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);
946 dwarf2out_emit_cfi (dw_cfi_ref cfi)
948 if (dwarf2out_do_cfi_asm ())
949 output_cfi_directive (cfi);
952 /* Output CFIs from VEC, up to index UPTO, to bring current FDE to the
953 same state as after executing CFIs in CFI chain. DO_CFI_ASM is
954 true if .cfi_* directives shall be emitted, false otherwise. If it
955 is false, FDE and FOR_EH are the other arguments to pass to
959 output_cfis (cfi_vec vec, int upto, bool do_cfi_asm,
960 dw_fde_ref fde, bool for_eh)
963 struct dw_cfi_struct cfi_buf;
965 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
966 VEC(dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
967 unsigned int len, idx;
969 for (ix = 0; ix < upto + 1; ix++)
971 dw_cfi_ref cfi = ix < upto ? VEC_index (dw_cfi_ref, vec, ix) : NULL;
972 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
974 case DW_CFA_advance_loc:
975 case DW_CFA_advance_loc1:
976 case DW_CFA_advance_loc2:
977 case DW_CFA_advance_loc4:
978 case DW_CFA_MIPS_advance_loc8:
980 /* All advances should be ignored. */
982 case DW_CFA_remember_state:
984 dw_cfi_ref args_size = cfi_args_size;
986 /* Skip everything between .cfi_remember_state and
987 .cfi_restore_state. */
992 for (; ix < upto; ix++)
994 cfi2 = VEC_index (dw_cfi_ref, vec, ix);
995 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
997 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
1000 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
1003 cfi_args_size = args_size;
1006 case DW_CFA_GNU_args_size:
1007 cfi_args_size = cfi;
1009 case DW_CFA_GNU_window_save:
1012 case DW_CFA_offset_extended:
1013 case DW_CFA_offset_extended_sf:
1014 case DW_CFA_restore:
1015 case DW_CFA_restore_extended:
1016 case DW_CFA_undefined:
1017 case DW_CFA_same_value:
1018 case DW_CFA_register:
1019 case DW_CFA_val_offset:
1020 case DW_CFA_val_offset_sf:
1021 case DW_CFA_expression:
1022 case DW_CFA_val_expression:
1023 case DW_CFA_GNU_negative_offset_extended:
1024 if (VEC_length (dw_cfi_ref, regs)
1025 <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
1026 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
1027 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
1028 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1031 case DW_CFA_def_cfa:
1032 case DW_CFA_def_cfa_sf:
1033 case DW_CFA_def_cfa_expression:
1035 cfi_cfa_offset = cfi;
1037 case DW_CFA_def_cfa_register:
1040 case DW_CFA_def_cfa_offset:
1041 case DW_CFA_def_cfa_offset_sf:
1042 cfi_cfa_offset = cfi;
1045 gcc_assert (cfi == NULL);
1047 len = VEC_length (dw_cfi_ref, regs);
1048 for (idx = 0; idx < len; idx++)
1050 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
1052 && cfi2->dw_cfi_opc != DW_CFA_restore
1053 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
1056 output_cfi_directive (cfi2);
1058 output_cfi (cfi2, fde, for_eh);
1061 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
1063 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
1065 switch (cfi_cfa_offset->dw_cfi_opc)
1067 case DW_CFA_def_cfa_offset:
1068 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
1069 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
1071 case DW_CFA_def_cfa_offset_sf:
1072 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
1073 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
1075 case DW_CFA_def_cfa:
1076 case DW_CFA_def_cfa_sf:
1077 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
1078 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
1085 else if (cfi_cfa_offset)
1086 cfi_cfa = cfi_cfa_offset;
1090 output_cfi_directive (cfi_cfa);
1092 output_cfi (cfi_cfa, fde, for_eh);
1095 cfi_cfa_offset = NULL;
1097 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
1100 output_cfi_directive (cfi_args_size);
1102 output_cfi (cfi_args_size, fde, for_eh);
1104 cfi_args_size = NULL;
1107 VEC_free (dw_cfi_ref, heap, regs);
1110 else if (do_cfi_asm)
1111 output_cfi_directive (cfi);
1113 output_cfi (cfi, fde, for_eh);
1121 /* Like output_cfis, but emit all CFIs in the vector. */
1123 output_all_cfis (cfi_vec vec, bool do_cfi_asm,
1124 dw_fde_ref fde, bool for_eh)
1126 output_cfis (vec, VEC_length (dw_cfi_ref, vec), do_cfi_asm, fde, for_eh);
1129 /* Output one FDE. */
1132 output_fde (dw_fde_ref fde, bool for_eh, bool second,
1133 char *section_start_label, int fde_encoding, char *augmentation,
1134 bool any_lsda_needed, int lsda_encoding)
1137 const char *begin, *end;
1138 static unsigned int j;
1139 char l1[20], l2[20];
1142 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
1144 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
1146 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
1147 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
1148 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
1149 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
1150 " indicating 64-bit DWARF extension");
1151 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1153 ASM_OUTPUT_LABEL (asm_out_file, l1);
1156 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
1158 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
1159 debug_frame_section, "FDE CIE offset");
1161 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
1162 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
1166 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
1167 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
1168 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
1169 "FDE initial location");
1170 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1171 end, begin, "FDE address range");
1175 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
1176 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
1179 if (augmentation[0])
1181 if (any_lsda_needed)
1183 int size = size_of_encoded_value (lsda_encoding);
1185 if (lsda_encoding == DW_EH_PE_aligned)
1187 int offset = ( 4 /* Length */
1188 + 4 /* CIE offset */
1189 + 2 * size_of_encoded_value (fde_encoding)
1190 + 1 /* Augmentation size */ );
1191 int pad = -offset & (PTR_SIZE - 1);
1194 gcc_assert (size_of_uleb128 (size) == 1);
1197 dw2_asm_output_data_uleb128 (size, "Augmentation size");
1199 if (fde->uses_eh_lsda)
1201 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
1202 fde->funcdef_number);
1203 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
1204 gen_rtx_SYMBOL_REF (Pmode, l1),
1206 "Language Specific Data Area");
1210 if (lsda_encoding == DW_EH_PE_aligned)
1211 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1212 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
1213 "Language Specific Data Area (none)");
1217 dw2_asm_output_data_uleb128 (0, "Augmentation size");
1220 /* Loop through the Call Frame Instructions associated with
1222 fde->dw_fde_current_label = begin;
1223 if (fde->dw_fde_second_begin == NULL)
1224 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
1225 output_cfi (cfi, fde, for_eh);
1228 if (fde->dw_fde_switch_cfi_index > 0)
1229 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
1231 if (ix == fde->dw_fde_switch_cfi_index)
1233 output_cfi (cfi, fde, for_eh);
1239 int until = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
1241 if (fde->dw_fde_switch_cfi_index > 0)
1243 from = fde->dw_fde_switch_cfi_index;
1244 output_cfis (fde->dw_fde_cfi, from, false, fde, for_eh);
1246 for (i = from; i < until; i++)
1247 output_cfi (VEC_index (dw_cfi_ref, fde->dw_fde_cfi, i),
1251 /* If we are to emit a ref/link from function bodies to their frame tables,
1252 do it now. This is typically performed to make sure that tables
1253 associated with functions are dragged with them and not discarded in
1254 garbage collecting links. We need to do this on a per function basis to
1255 cope with -ffunction-sections. */
1257 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
1258 /* Switch to the function section, emit the ref to the tables, and
1259 switch *back* into the table section. */
1260 switch_to_section (function_section (fde->decl));
1261 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
1262 switch_to_frame_table_section (for_eh, true);
1265 /* Pad the FDE out to an address sized boundary. */
1266 ASM_OUTPUT_ALIGN (asm_out_file,
1267 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1268 ASM_OUTPUT_LABEL (asm_out_file, l2);
1273 /* Return true if frame description entry FDE is needed for EH. */
1276 fde_needed_for_eh_p (dw_fde_ref fde)
1278 if (flag_asynchronous_unwind_tables)
1281 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
1284 if (fde->uses_eh_lsda)
1287 /* If exceptions are enabled, we have collected nothrow info. */
1288 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
1294 /* Output the call frame information used to record information
1295 that relates to calculating the frame pointer, and records the
1296 location of saved registers. */
1299 output_call_frame_info (int for_eh)
1304 char l1[20], l2[20], section_start_label[20];
1305 bool any_lsda_needed = false;
1306 char augmentation[6];
1307 int augmentation_size;
1308 int fde_encoding = DW_EH_PE_absptr;
1309 int per_encoding = DW_EH_PE_absptr;
1310 int lsda_encoding = DW_EH_PE_absptr;
1312 rtx personality = NULL;
1315 /* Don't emit a CIE if there won't be any FDEs. */
1316 if (fde_table_in_use == 0)
1319 /* Nothing to do if the assembler's doing it all. */
1320 if (dwarf2out_do_cfi_asm ())
1323 /* If we don't have any functions we'll want to unwind out of, don't emit
1324 any EH unwind information. If we make FDEs linkonce, we may have to
1325 emit an empty label for an FDE that wouldn't otherwise be emitted. We
1326 want to avoid having an FDE kept around when the function it refers to
1327 is discarded. Example where this matters: a primary function template
1328 in C++ requires EH information, an explicit specialization doesn't. */
1331 bool any_eh_needed = false;
1333 for (i = 0; i < fde_table_in_use; i++)
1334 if (fde_table[i].uses_eh_lsda)
1335 any_eh_needed = any_lsda_needed = true;
1336 else if (fde_needed_for_eh_p (&fde_table[i]))
1337 any_eh_needed = true;
1338 else if (TARGET_USES_WEAK_UNWIND_INFO)
1339 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
1346 /* We're going to be generating comments, so turn on app. */
1350 /* Switch to the proper frame section, first time. */
1351 switch_to_frame_table_section (for_eh, false);
1353 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1354 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1356 /* Output the CIE. */
1357 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1358 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1359 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
1360 dw2_asm_output_data (4, 0xffffffff,
1361 "Initial length escape value indicating 64-bit DWARF extension");
1362 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1363 "Length of Common Information Entry");
1364 ASM_OUTPUT_LABEL (asm_out_file, l1);
1366 /* Now that the CIE pointer is PC-relative for EH,
1367 use 0 to identify the CIE. */
1368 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1369 (for_eh ? 0 : DWARF_CIE_ID),
1370 "CIE Identifier Tag");
1372 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
1373 use CIE version 1, unless that would produce incorrect results
1374 due to overflowing the return register column. */
1375 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
1377 if (return_reg >= 256 || dwarf_version > 2)
1379 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
1381 augmentation[0] = 0;
1382 augmentation_size = 0;
1384 personality = current_unit_personality;
1390 z Indicates that a uleb128 is present to size the
1391 augmentation section.
1392 L Indicates the encoding (and thus presence) of
1393 an LSDA pointer in the FDE augmentation.
1394 R Indicates a non-default pointer encoding for
1396 P Indicates the presence of an encoding + language
1397 personality routine in the CIE augmentation. */
1399 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1400 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1401 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1403 p = augmentation + 1;
1407 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1408 assemble_external_libcall (personality);
1410 if (any_lsda_needed)
1413 augmentation_size += 1;
1415 if (fde_encoding != DW_EH_PE_absptr)
1418 augmentation_size += 1;
1420 if (p > augmentation + 1)
1422 augmentation[0] = 'z';
1426 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1427 if (personality && per_encoding == DW_EH_PE_aligned)
1429 int offset = ( 4 /* Length */
1431 + 1 /* CIE version */
1432 + strlen (augmentation) + 1 /* Augmentation */
1433 + size_of_uleb128 (1) /* Code alignment */
1434 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1436 + 1 /* Augmentation size */
1437 + 1 /* Personality encoding */ );
1438 int pad = -offset & (PTR_SIZE - 1);
1440 augmentation_size += pad;
1442 /* Augmentations should be small, so there's scarce need to
1443 iterate for a solution. Die if we exceed one uleb128 byte. */
1444 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
1448 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1449 if (dw_cie_version >= 4)
1451 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
1452 dw2_asm_output_data (1, 0, "CIE Segment Size");
1454 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1455 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1456 "CIE Data Alignment Factor");
1458 if (dw_cie_version == 1)
1459 dw2_asm_output_data (1, return_reg, "CIE RA Column");
1461 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
1463 if (augmentation[0])
1465 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1468 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1469 eh_data_format_name (per_encoding));
1470 dw2_asm_output_encoded_addr_rtx (per_encoding,
1475 if (any_lsda_needed)
1476 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1477 eh_data_format_name (lsda_encoding));
1479 if (fde_encoding != DW_EH_PE_absptr)
1480 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1481 eh_data_format_name (fde_encoding));
1484 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, i, cfi)
1485 output_cfi (cfi, NULL, for_eh);
1487 /* Pad the CIE out to an address sized boundary. */
1488 ASM_OUTPUT_ALIGN (asm_out_file,
1489 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1490 ASM_OUTPUT_LABEL (asm_out_file, l2);
1492 /* Loop through all of the FDE's. */
1493 for (i = 0; i < fde_table_in_use; i++)
1496 fde = &fde_table[i];
1498 /* Don't emit EH unwind info for leaf functions that don't need it. */
1499 if (for_eh && !fde_needed_for_eh_p (fde))
1502 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
1503 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
1504 augmentation, any_lsda_needed, lsda_encoding);
1507 if (for_eh && targetm.terminate_dw2_eh_frame_info)
1508 dw2_asm_output_data (4, 0, "End of Table");
1509 #ifdef MIPS_DEBUGGING_INFO
1510 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1511 get a value of 0. Putting .align 0 after the label fixes it. */
1512 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1515 /* Turn off app to make assembly quicker. */
1520 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
1523 dwarf2out_do_cfi_startproc (bool second)
1527 rtx personality = get_personality_function (current_function_decl);
1529 fprintf (asm_out_file, "\t.cfi_startproc\n");
1533 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1536 /* ??? The GAS support isn't entirely consistent. We have to
1537 handle indirect support ourselves, but PC-relative is done
1538 in the assembler. Further, the assembler can't handle any
1539 of the weirder relocation types. */
1540 if (enc & DW_EH_PE_indirect)
1541 ref = dw2_force_const_mem (ref, true);
1543 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
1544 output_addr_const (asm_out_file, ref);
1545 fputc ('\n', asm_out_file);
1548 if (crtl->uses_eh_lsda)
1552 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1553 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
1554 current_function_funcdef_no);
1555 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
1556 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
1558 if (enc & DW_EH_PE_indirect)
1559 ref = dw2_force_const_mem (ref, true);
1561 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
1562 output_addr_const (asm_out_file, ref);
1563 fputc ('\n', asm_out_file);
1567 /* Output a marker (i.e. a label) for the beginning of a function, before
1571 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
1572 const char *file ATTRIBUTE_UNUSED)
1574 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1580 current_function_func_begin_label = NULL;
1582 do_frame = dwarf2out_do_frame ();
1584 /* ??? current_function_func_begin_label is also used by except.c for
1585 call-site information. We must emit this label if it might be used. */
1587 && (!flag_exceptions
1588 || targetm_common.except_unwind_info (&global_options) != UI_TARGET))
1591 fnsec = function_section (current_function_decl);
1592 switch_to_section (fnsec);
1593 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1594 current_function_funcdef_no);
1595 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
1596 current_function_funcdef_no);
1597 dup_label = xstrdup (label);
1598 current_function_func_begin_label = dup_label;
1600 /* We can elide the fde allocation if we're not emitting debug info. */
1604 /* Expand the fde table if necessary. */
1605 if (fde_table_in_use == fde_table_allocated)
1607 fde_table_allocated += FDE_TABLE_INCREMENT;
1608 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
1609 memset (fde_table + fde_table_in_use, 0,
1610 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1613 /* Record the FDE associated with this function. */
1614 current_funcdef_fde = fde_table_in_use;
1616 /* Add the new FDE at the end of the fde_table. */
1617 fde = &fde_table[fde_table_in_use++];
1618 fde->decl = current_function_decl;
1619 fde->dw_fde_begin = dup_label;
1620 fde->dw_fde_end = NULL;
1621 fde->dw_fde_current_label = dup_label;
1622 fde->dw_fde_second_begin = NULL;
1623 fde->dw_fde_second_end = NULL;
1624 fde->dw_fde_vms_end_prologue = NULL;
1625 fde->dw_fde_vms_begin_epilogue = NULL;
1626 fde->dw_fde_cfi = VEC_alloc (dw_cfi_ref, gc, 20);
1627 fde->dw_fde_switch_cfi_index = 0;
1628 fde->funcdef_number = current_function_funcdef_no;
1629 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
1630 fde->uses_eh_lsda = crtl->uses_eh_lsda;
1631 fde->nothrow = crtl->nothrow;
1632 fde->drap_reg = INVALID_REGNUM;
1633 fde->vdrap_reg = INVALID_REGNUM;
1634 fde->in_std_section = (fnsec == text_section
1635 || (cold_text_section && fnsec == cold_text_section));
1636 fde->second_in_std_section = 0;
1638 dwarf2cfi_function_init ();
1640 /* We only want to output line number information for the genuine dwarf2
1641 prologue case, not the eh frame case. */
1642 #ifdef DWARF2_DEBUGGING_INFO
1644 dwarf2out_source_line (line, file, 0, true);
1647 if (dwarf2out_do_cfi_asm ())
1648 dwarf2out_do_cfi_startproc (false);
1651 rtx personality = get_personality_function (current_function_decl);
1652 if (!current_unit_personality)
1653 current_unit_personality = personality;
1655 /* We cannot keep a current personality per function as without CFI
1656 asm, at the point where we emit the CFI data, there is no current
1657 function anymore. */
1658 if (personality && current_unit_personality != personality)
1659 sorry ("multiple EH personalities are supported only with assemblers "
1660 "supporting .cfi_personality directive");
1664 /* Output a marker (i.e. a label) for the end of the generated code
1665 for a function prologue. This gets called *after* the prologue code has
1669 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
1670 const char *file ATTRIBUTE_UNUSED)
1673 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1675 /* Output a label to mark the endpoint of the code generated for this
1677 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
1678 current_function_funcdef_no);
1679 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
1680 current_function_funcdef_no);
1681 fde = &fde_table[fde_table_in_use - 1];
1682 fde->dw_fde_vms_end_prologue = xstrdup (label);
1685 /* Output a marker (i.e. a label) for the beginning of the generated code
1686 for a function epilogue. This gets called *before* the prologue code has
1690 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1691 const char *file ATTRIBUTE_UNUSED)
1694 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1696 fde = &fde_table[fde_table_in_use - 1];
1697 if (fde->dw_fde_vms_begin_epilogue)
1700 /* Output a label to mark the endpoint of the code generated for this
1702 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
1703 current_function_funcdef_no);
1704 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
1705 current_function_funcdef_no);
1706 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
1709 /* Output a marker (i.e. a label) for the absolute end of the generated code
1710 for a function definition. This gets called *after* the epilogue code has
1714 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1715 const char *file ATTRIBUTE_UNUSED)
1718 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1720 last_var_location_insn = NULL_RTX;
1722 if (dwarf2out_do_cfi_asm ())
1723 fprintf (asm_out_file, "\t.cfi_endproc\n");
1725 /* Output a label to mark the endpoint of the code generated for this
1727 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1728 current_function_funcdef_no);
1729 ASM_OUTPUT_LABEL (asm_out_file, label);
1730 fde = current_fde ();
1731 gcc_assert (fde != NULL);
1732 if (fde->dw_fde_second_begin == NULL)
1733 fde->dw_fde_end = xstrdup (label);
1737 dwarf2out_frame_init (void)
1739 /* Allocate the initial hunk of the fde_table. */
1740 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
1741 fde_table_allocated = FDE_TABLE_INCREMENT;
1742 fde_table_in_use = 0;
1744 dwarf2cfi_frame_init ();
1748 dwarf2out_frame_finish (void)
1750 /* Output call frame information. */
1751 if (targetm.debug_unwind_info () == UI_DWARF2)
1752 output_call_frame_info (0);
1754 /* Output another copy for the unwinder. */
1755 if ((flag_unwind_tables || flag_exceptions)
1756 && targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
1757 output_call_frame_info (1);
1760 /* Note that the current function section is being used for code. */
1763 dwarf2out_note_section_used (void)
1765 section *sec = current_function_section ();
1766 if (sec == text_section)
1767 text_section_used = true;
1768 else if (sec == cold_text_section)
1769 cold_text_section_used = true;
1772 static void var_location_switch_text_section (void);
1773 static void set_cur_line_info_table (section *);
1776 dwarf2out_switch_text_section (void)
1779 dw_fde_ref fde = current_fde ();
1781 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
1783 if (!in_cold_section_p)
1785 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
1786 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
1787 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
1791 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
1792 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
1793 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
1795 have_multiple_function_sections = true;
1797 /* There is no need to mark used sections when not debugging. */
1798 if (cold_text_section != NULL)
1799 dwarf2out_note_section_used ();
1801 if (dwarf2out_do_cfi_asm ())
1802 fprintf (asm_out_file, "\t.cfi_endproc\n");
1804 /* Now do the real section switch. */
1805 sect = current_function_section ();
1806 switch_to_section (sect);
1808 fde->second_in_std_section
1809 = (sect == text_section
1810 || (cold_text_section && sect == cold_text_section));
1812 if (dwarf2out_do_cfi_asm ())
1814 dwarf2out_do_cfi_startproc (true);
1815 /* As this is a different FDE, insert all current CFI instructions
1817 output_all_cfis (fde->dw_fde_cfi, true, fde, true);
1819 fde->dw_fde_switch_cfi_index = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
1820 var_location_switch_text_section ();
1822 set_cur_line_info_table (sect);
1825 /* And now, the subset of the debugging information support code necessary
1826 for emitting location expressions. */
1828 /* Data about a single source file. */
1829 struct GTY(()) dwarf_file_data {
1830 const char * filename;
1834 typedef struct GTY(()) deferred_locations_struct
1838 } deferred_locations;
1840 DEF_VEC_O(deferred_locations);
1841 DEF_VEC_ALLOC_O(deferred_locations,gc);
1843 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
1845 DEF_VEC_P(dw_die_ref);
1846 DEF_VEC_ALLOC_P(dw_die_ref,heap);
1848 /* Location lists are ranges + location descriptions for that range,
1849 so you can track variables that are in different places over
1850 their entire life. */
1851 typedef struct GTY(()) dw_loc_list_struct {
1852 dw_loc_list_ref dw_loc_next;
1853 const char *begin; /* Label for begin address of range */
1854 const char *end; /* Label for end address of range */
1855 char *ll_symbol; /* Label for beginning of location list.
1856 Only on head of list */
1857 const char *section; /* Section this loclist is relative to */
1858 dw_loc_descr_ref expr;
1860 /* True if all addresses in this and subsequent lists are known to be
1863 /* True if this list has been replaced by dw_loc_next. */
1866 /* True if the range should be emitted even if begin and end
1871 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
1873 /* Convert a DWARF stack opcode into its string name. */
1876 dwarf_stack_op_name (unsigned int op)
1881 return "DW_OP_addr";
1883 return "DW_OP_deref";
1885 return "DW_OP_const1u";
1887 return "DW_OP_const1s";
1889 return "DW_OP_const2u";
1891 return "DW_OP_const2s";
1893 return "DW_OP_const4u";
1895 return "DW_OP_const4s";
1897 return "DW_OP_const8u";
1899 return "DW_OP_const8s";
1901 return "DW_OP_constu";
1903 return "DW_OP_consts";
1907 return "DW_OP_drop";
1909 return "DW_OP_over";
1911 return "DW_OP_pick";
1913 return "DW_OP_swap";
1917 return "DW_OP_xderef";
1925 return "DW_OP_minus";
1937 return "DW_OP_plus";
1938 case DW_OP_plus_uconst:
1939 return "DW_OP_plus_uconst";
1945 return "DW_OP_shra";
1963 return "DW_OP_skip";
1965 return "DW_OP_lit0";
1967 return "DW_OP_lit1";
1969 return "DW_OP_lit2";
1971 return "DW_OP_lit3";
1973 return "DW_OP_lit4";
1975 return "DW_OP_lit5";
1977 return "DW_OP_lit6";
1979 return "DW_OP_lit7";
1981 return "DW_OP_lit8";
1983 return "DW_OP_lit9";
1985 return "DW_OP_lit10";
1987 return "DW_OP_lit11";
1989 return "DW_OP_lit12";
1991 return "DW_OP_lit13";
1993 return "DW_OP_lit14";
1995 return "DW_OP_lit15";
1997 return "DW_OP_lit16";
1999 return "DW_OP_lit17";
2001 return "DW_OP_lit18";
2003 return "DW_OP_lit19";
2005 return "DW_OP_lit20";
2007 return "DW_OP_lit21";
2009 return "DW_OP_lit22";
2011 return "DW_OP_lit23";
2013 return "DW_OP_lit24";
2015 return "DW_OP_lit25";
2017 return "DW_OP_lit26";
2019 return "DW_OP_lit27";
2021 return "DW_OP_lit28";
2023 return "DW_OP_lit29";
2025 return "DW_OP_lit30";
2027 return "DW_OP_lit31";
2029 return "DW_OP_reg0";
2031 return "DW_OP_reg1";
2033 return "DW_OP_reg2";
2035 return "DW_OP_reg3";
2037 return "DW_OP_reg4";
2039 return "DW_OP_reg5";
2041 return "DW_OP_reg6";
2043 return "DW_OP_reg7";
2045 return "DW_OP_reg8";
2047 return "DW_OP_reg9";
2049 return "DW_OP_reg10";
2051 return "DW_OP_reg11";
2053 return "DW_OP_reg12";
2055 return "DW_OP_reg13";
2057 return "DW_OP_reg14";
2059 return "DW_OP_reg15";
2061 return "DW_OP_reg16";
2063 return "DW_OP_reg17";
2065 return "DW_OP_reg18";
2067 return "DW_OP_reg19";
2069 return "DW_OP_reg20";
2071 return "DW_OP_reg21";
2073 return "DW_OP_reg22";
2075 return "DW_OP_reg23";
2077 return "DW_OP_reg24";
2079 return "DW_OP_reg25";
2081 return "DW_OP_reg26";
2083 return "DW_OP_reg27";
2085 return "DW_OP_reg28";
2087 return "DW_OP_reg29";
2089 return "DW_OP_reg30";
2091 return "DW_OP_reg31";
2093 return "DW_OP_breg0";
2095 return "DW_OP_breg1";
2097 return "DW_OP_breg2";
2099 return "DW_OP_breg3";
2101 return "DW_OP_breg4";
2103 return "DW_OP_breg5";
2105 return "DW_OP_breg6";
2107 return "DW_OP_breg7";
2109 return "DW_OP_breg8";
2111 return "DW_OP_breg9";
2113 return "DW_OP_breg10";
2115 return "DW_OP_breg11";
2117 return "DW_OP_breg12";
2119 return "DW_OP_breg13";
2121 return "DW_OP_breg14";
2123 return "DW_OP_breg15";
2125 return "DW_OP_breg16";
2127 return "DW_OP_breg17";
2129 return "DW_OP_breg18";
2131 return "DW_OP_breg19";
2133 return "DW_OP_breg20";
2135 return "DW_OP_breg21";
2137 return "DW_OP_breg22";
2139 return "DW_OP_breg23";
2141 return "DW_OP_breg24";
2143 return "DW_OP_breg25";
2145 return "DW_OP_breg26";
2147 return "DW_OP_breg27";
2149 return "DW_OP_breg28";
2151 return "DW_OP_breg29";
2153 return "DW_OP_breg30";
2155 return "DW_OP_breg31";
2157 return "DW_OP_regx";
2159 return "DW_OP_fbreg";
2161 return "DW_OP_bregx";
2163 return "DW_OP_piece";
2164 case DW_OP_deref_size:
2165 return "DW_OP_deref_size";
2166 case DW_OP_xderef_size:
2167 return "DW_OP_xderef_size";
2171 case DW_OP_push_object_address:
2172 return "DW_OP_push_object_address";
2174 return "DW_OP_call2";
2176 return "DW_OP_call4";
2177 case DW_OP_call_ref:
2178 return "DW_OP_call_ref";
2179 case DW_OP_implicit_value:
2180 return "DW_OP_implicit_value";
2181 case DW_OP_stack_value:
2182 return "DW_OP_stack_value";
2183 case DW_OP_form_tls_address:
2184 return "DW_OP_form_tls_address";
2185 case DW_OP_call_frame_cfa:
2186 return "DW_OP_call_frame_cfa";
2187 case DW_OP_bit_piece:
2188 return "DW_OP_bit_piece";
2190 case DW_OP_GNU_push_tls_address:
2191 return "DW_OP_GNU_push_tls_address";
2192 case DW_OP_GNU_uninit:
2193 return "DW_OP_GNU_uninit";
2194 case DW_OP_GNU_encoded_addr:
2195 return "DW_OP_GNU_encoded_addr";
2196 case DW_OP_GNU_implicit_pointer:
2197 return "DW_OP_GNU_implicit_pointer";
2198 case DW_OP_GNU_entry_value:
2199 return "DW_OP_GNU_entry_value";
2200 case DW_OP_GNU_const_type:
2201 return "DW_OP_GNU_const_type";
2202 case DW_OP_GNU_regval_type:
2203 return "DW_OP_GNU_regval_type";
2204 case DW_OP_GNU_deref_type:
2205 return "DW_OP_GNU_deref_type";
2206 case DW_OP_GNU_convert:
2207 return "DW_OP_GNU_convert";
2208 case DW_OP_GNU_reinterpret:
2209 return "DW_OP_GNU_reinterpret";
2210 case DW_OP_GNU_parameter_ref:
2211 return "DW_OP_GNU_parameter_ref";
2214 return "OP_<unknown>";
2218 /* Return a pointer to a newly allocated location description. Location
2219 descriptions are simple expression terms that can be strung
2220 together to form more complicated location (address) descriptions. */
2222 static inline dw_loc_descr_ref
2223 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
2224 unsigned HOST_WIDE_INT oprnd2)
2226 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
2228 descr->dw_loc_opc = op;
2229 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2230 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2231 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2232 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2237 /* Return a pointer to a newly allocated location description for
2240 static inline dw_loc_descr_ref
2241 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
2244 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
2247 return new_loc_descr (DW_OP_bregx, reg, offset);
2250 /* Add a location description term to a location description expression. */
2253 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
2255 dw_loc_descr_ref *d;
2257 /* Find the end of the chain. */
2258 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2264 /* Add a constant OFFSET to a location expression. */
2267 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
2269 dw_loc_descr_ref loc;
2272 gcc_assert (*list_head != NULL);
2277 /* Find the end of the chain. */
2278 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
2282 if (loc->dw_loc_opc == DW_OP_fbreg
2283 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
2284 p = &loc->dw_loc_oprnd1.v.val_int;
2285 else if (loc->dw_loc_opc == DW_OP_bregx)
2286 p = &loc->dw_loc_oprnd2.v.val_int;
2288 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
2289 offset. Don't optimize if an signed integer overflow would happen. */
2291 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
2292 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
2295 else if (offset > 0)
2296 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
2300 loc->dw_loc_next = int_loc_descriptor (-offset);
2301 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
2305 /* Add a constant OFFSET to a location list. */
2308 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
2311 for (d = list_head; d != NULL; d = d->dw_loc_next)
2312 loc_descr_plus_const (&d->expr, offset);
2315 #define DWARF_REF_SIZE \
2316 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
2318 static unsigned long size_of_locs (dw_loc_descr_ref);
2319 static unsigned long int get_base_type_offset (dw_die_ref);
2321 /* Return the size of a location descriptor. */
2323 static unsigned long
2324 size_of_loc_descr (dw_loc_descr_ref loc)
2326 unsigned long size = 1;
2328 switch (loc->dw_loc_opc)
2331 size += DWARF2_ADDR_SIZE;
2350 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2353 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2358 case DW_OP_plus_uconst:
2359 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2397 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2400 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2403 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2406 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2407 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2410 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2412 case DW_OP_bit_piece:
2413 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2414 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
2416 case DW_OP_deref_size:
2417 case DW_OP_xderef_size:
2426 case DW_OP_call_ref:
2427 size += DWARF_REF_SIZE;
2429 case DW_OP_implicit_value:
2430 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
2431 + loc->dw_loc_oprnd1.v.val_unsigned;
2433 case DW_OP_GNU_implicit_pointer:
2434 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2436 case DW_OP_GNU_entry_value:
2438 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
2439 size += size_of_uleb128 (op_size) + op_size;
2442 case DW_OP_GNU_const_type:
2445 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
2446 size += size_of_uleb128 (o) + 1;
2447 switch (loc->dw_loc_oprnd2.val_class)
2449 case dw_val_class_vec:
2450 size += loc->dw_loc_oprnd2.v.val_vec.length
2451 * loc->dw_loc_oprnd2.v.val_vec.elt_size;
2453 case dw_val_class_const:
2454 size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
2456 case dw_val_class_const_double:
2457 size += 2 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
2464 case DW_OP_GNU_regval_type:
2467 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
2468 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
2469 + size_of_uleb128 (o);
2472 case DW_OP_GNU_deref_type:
2475 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
2476 size += 1 + size_of_uleb128 (o);
2479 case DW_OP_GNU_convert:
2480 case DW_OP_GNU_reinterpret:
2481 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2482 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2486 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
2487 size += size_of_uleb128 (o);
2490 case DW_OP_GNU_parameter_ref:
2500 /* Return the size of a series of location descriptors. */
2502 static unsigned long
2503 size_of_locs (dw_loc_descr_ref loc)
2508 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
2509 field, to avoid writing to a PCH file. */
2510 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
2512 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
2514 size += size_of_loc_descr (l);
2519 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
2521 l->dw_loc_addr = size;
2522 size += size_of_loc_descr (l);
2528 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
2529 static void get_ref_die_offset_label (char *, dw_die_ref);
2530 static unsigned long int get_ref_die_offset (dw_die_ref);
2531 static void output_loc_sequence (dw_loc_descr_ref, int);
2533 /* Output location description stack opcode's operands (if any).
2534 The for_eh_or_skip parameter controls whether register numbers are
2535 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2536 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2537 info). This should be suppressed for the cases that have not been converted
2538 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2541 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
2543 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2544 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2546 switch (loc->dw_loc_opc)
2548 #ifdef DWARF2_DEBUGGING_INFO
2551 dw2_asm_output_data (2, val1->v.val_int, NULL);
2556 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
2557 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
2559 fputc ('\n', asm_out_file);
2564 dw2_asm_output_data (4, val1->v.val_int, NULL);
2569 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
2570 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
2572 fputc ('\n', asm_out_file);
2577 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2578 dw2_asm_output_data (8, val1->v.val_int, NULL);
2585 gcc_assert (val1->val_class == dw_val_class_loc);
2586 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2588 dw2_asm_output_data (2, offset, NULL);
2591 case DW_OP_implicit_value:
2592 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2593 switch (val2->val_class)
2595 case dw_val_class_const:
2596 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
2598 case dw_val_class_vec:
2600 unsigned int elt_size = val2->v.val_vec.elt_size;
2601 unsigned int len = val2->v.val_vec.length;
2605 if (elt_size > sizeof (HOST_WIDE_INT))
2610 for (i = 0, p = val2->v.val_vec.array;
2613 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2614 "fp or vector constant word %u", i);
2617 case dw_val_class_const_double:
2619 unsigned HOST_WIDE_INT first, second;
2621 if (WORDS_BIG_ENDIAN)
2623 first = val2->v.val_double.high;
2624 second = val2->v.val_double.low;
2628 first = val2->v.val_double.low;
2629 second = val2->v.val_double.high;
2631 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2633 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2637 case dw_val_class_addr:
2638 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
2639 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
2654 case DW_OP_implicit_value:
2655 /* We currently don't make any attempt to make sure these are
2656 aligned properly like we do for the main unwind info, so
2657 don't support emitting things larger than a byte if we're
2658 only doing unwinding. */
2663 dw2_asm_output_data (1, val1->v.val_int, NULL);
2666 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2669 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2672 dw2_asm_output_data (1, val1->v.val_int, NULL);
2674 case DW_OP_plus_uconst:
2675 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2709 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2713 unsigned r = val1->v.val_unsigned;
2714 if (for_eh_or_skip >= 0)
2715 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2716 gcc_assert (size_of_uleb128 (r)
2717 == size_of_uleb128 (val1->v.val_unsigned));
2718 dw2_asm_output_data_uleb128 (r, NULL);
2722 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2726 unsigned r = val1->v.val_unsigned;
2727 if (for_eh_or_skip >= 0)
2728 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2729 gcc_assert (size_of_uleb128 (r)
2730 == size_of_uleb128 (val1->v.val_unsigned));
2731 dw2_asm_output_data_uleb128 (r, NULL);
2732 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2736 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2738 case DW_OP_bit_piece:
2739 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2740 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
2742 case DW_OP_deref_size:
2743 case DW_OP_xderef_size:
2744 dw2_asm_output_data (1, val1->v.val_int, NULL);
2750 if (targetm.asm_out.output_dwarf_dtprel)
2752 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
2755 fputc ('\n', asm_out_file);
2762 #ifdef DWARF2_DEBUGGING_INFO
2763 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2770 case DW_OP_GNU_implicit_pointer:
2772 char label[MAX_ARTIFICIAL_LABEL_BYTES
2773 + HOST_BITS_PER_WIDE_INT / 2 + 2];
2774 gcc_assert (val1->val_class == dw_val_class_die_ref);
2775 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
2776 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
2777 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2781 case DW_OP_GNU_entry_value:
2782 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
2783 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
2786 case DW_OP_GNU_const_type:
2788 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
2790 dw2_asm_output_data_uleb128 (o, NULL);
2791 switch (val2->val_class)
2793 case dw_val_class_const:
2794 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2795 dw2_asm_output_data (1, l, NULL);
2796 dw2_asm_output_data (l, val2->v.val_int, NULL);
2798 case dw_val_class_vec:
2800 unsigned int elt_size = val2->v.val_vec.elt_size;
2801 unsigned int len = val2->v.val_vec.length;
2806 dw2_asm_output_data (1, l, NULL);
2807 if (elt_size > sizeof (HOST_WIDE_INT))
2812 for (i = 0, p = val2->v.val_vec.array;
2815 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2816 "fp or vector constant word %u", i);
2819 case dw_val_class_const_double:
2821 unsigned HOST_WIDE_INT first, second;
2822 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2824 dw2_asm_output_data (1, 2 * l, NULL);
2825 if (WORDS_BIG_ENDIAN)
2827 first = val2->v.val_double.high;
2828 second = val2->v.val_double.low;
2832 first = val2->v.val_double.low;
2833 second = val2->v.val_double.high;
2835 dw2_asm_output_data (l, first, NULL);
2836 dw2_asm_output_data (l, second, NULL);
2844 case DW_OP_GNU_regval_type:
2846 unsigned r = val1->v.val_unsigned;
2847 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2849 if (for_eh_or_skip >= 0)
2851 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2852 gcc_assert (size_of_uleb128 (r)
2853 == size_of_uleb128 (val1->v.val_unsigned));
2855 dw2_asm_output_data_uleb128 (r, NULL);
2856 dw2_asm_output_data_uleb128 (o, NULL);
2859 case DW_OP_GNU_deref_type:
2861 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2863 dw2_asm_output_data (1, val1->v.val_int, NULL);
2864 dw2_asm_output_data_uleb128 (o, NULL);
2867 case DW_OP_GNU_convert:
2868 case DW_OP_GNU_reinterpret:
2869 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2870 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2873 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
2875 dw2_asm_output_data_uleb128 (o, NULL);
2879 case DW_OP_GNU_parameter_ref:
2882 gcc_assert (val1->val_class == dw_val_class_die_ref);
2883 o = get_ref_die_offset (val1->v.val_die_ref.die);
2884 dw2_asm_output_data (4, o, NULL);
2889 /* Other codes have no operands. */
2894 /* Output a sequence of location operations.
2895 The for_eh_or_skip parameter controls whether register numbers are
2896 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2897 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2898 info). This should be suppressed for the cases that have not been converted
2899 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2902 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
2904 for (; loc != NULL; loc = loc->dw_loc_next)
2906 enum dwarf_location_atom opc = loc->dw_loc_opc;
2907 /* Output the opcode. */
2908 if (for_eh_or_skip >= 0
2909 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2911 unsigned r = (opc - DW_OP_breg0);
2912 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2913 gcc_assert (r <= 31);
2914 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2916 else if (for_eh_or_skip >= 0
2917 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2919 unsigned r = (opc - DW_OP_reg0);
2920 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2921 gcc_assert (r <= 31);
2922 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2925 dw2_asm_output_data (1, opc,
2926 "%s", dwarf_stack_op_name (opc));
2928 /* Output the operand(s) (if any). */
2929 output_loc_operands (loc, for_eh_or_skip);
2933 /* Output location description stack opcode's operands (if any).
2934 The output is single bytes on a line, suitable for .cfi_escape. */
2937 output_loc_operands_raw (dw_loc_descr_ref loc)
2939 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2940 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2942 switch (loc->dw_loc_opc)
2945 case DW_OP_implicit_value:
2946 /* We cannot output addresses in .cfi_escape, only bytes. */
2952 case DW_OP_deref_size:
2953 case DW_OP_xderef_size:
2954 fputc (',', asm_out_file);
2955 dw2_asm_output_data_raw (1, val1->v.val_int);
2960 fputc (',', asm_out_file);
2961 dw2_asm_output_data_raw (2, val1->v.val_int);
2966 fputc (',', asm_out_file);
2967 dw2_asm_output_data_raw (4, val1->v.val_int);
2972 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2973 fputc (',', asm_out_file);
2974 dw2_asm_output_data_raw (8, val1->v.val_int);
2982 gcc_assert (val1->val_class == dw_val_class_loc);
2983 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2985 fputc (',', asm_out_file);
2986 dw2_asm_output_data_raw (2, offset);
2992 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2993 gcc_assert (size_of_uleb128 (r)
2994 == size_of_uleb128 (val1->v.val_unsigned));
2995 fputc (',', asm_out_file);
2996 dw2_asm_output_data_uleb128_raw (r);
3001 case DW_OP_plus_uconst:
3003 fputc (',', asm_out_file);
3004 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
3007 case DW_OP_bit_piece:
3008 fputc (',', asm_out_file);
3009 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
3010 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
3047 fputc (',', asm_out_file);
3048 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
3053 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
3054 gcc_assert (size_of_uleb128 (r)
3055 == size_of_uleb128 (val1->v.val_unsigned));
3056 fputc (',', asm_out_file);
3057 dw2_asm_output_data_uleb128_raw (r);
3058 fputc (',', asm_out_file);
3059 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
3063 case DW_OP_GNU_implicit_pointer:
3064 case DW_OP_GNU_entry_value:
3065 case DW_OP_GNU_const_type:
3066 case DW_OP_GNU_regval_type:
3067 case DW_OP_GNU_deref_type:
3068 case DW_OP_GNU_convert:
3069 case DW_OP_GNU_reinterpret:
3070 case DW_OP_GNU_parameter_ref:
3075 /* Other codes have no operands. */
3081 output_loc_sequence_raw (dw_loc_descr_ref loc)
3085 enum dwarf_location_atom opc = loc->dw_loc_opc;
3086 /* Output the opcode. */
3087 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
3089 unsigned r = (opc - DW_OP_breg0);
3090 r = DWARF2_FRAME_REG_OUT (r, 1);
3091 gcc_assert (r <= 31);
3092 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
3094 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
3096 unsigned r = (opc - DW_OP_reg0);
3097 r = DWARF2_FRAME_REG_OUT (r, 1);
3098 gcc_assert (r <= 31);
3099 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
3101 /* Output the opcode. */
3102 fprintf (asm_out_file, "%#x", opc);
3103 output_loc_operands_raw (loc);
3105 if (!loc->dw_loc_next)
3107 loc = loc->dw_loc_next;
3109 fputc (',', asm_out_file);
3113 /* This routine will generate the correct assembly data for a location
3114 description based on a cfi entry with a complex address. */
3117 output_cfa_loc (dw_cfi_ref cfi, int for_eh)
3119 dw_loc_descr_ref loc;
3122 if (cfi->dw_cfi_opc == DW_CFA_expression)
3125 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3126 dw2_asm_output_data (1, r, NULL);
3127 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
3130 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3132 /* Output the size of the block. */
3133 size = size_of_locs (loc);
3134 dw2_asm_output_data_uleb128 (size, NULL);
3136 /* Now output the operations themselves. */
3137 output_loc_sequence (loc, for_eh);
3140 /* Similar, but used for .cfi_escape. */
3143 output_cfa_loc_raw (dw_cfi_ref cfi)
3145 dw_loc_descr_ref loc;
3148 if (cfi->dw_cfi_opc == DW_CFA_expression)
3151 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3152 fprintf (asm_out_file, "%#x,", r);
3153 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
3156 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3158 /* Output the size of the block. */
3159 size = size_of_locs (loc);
3160 dw2_asm_output_data_uleb128_raw (size);
3161 fputc (',', asm_out_file);
3163 /* Now output the operations themselves. */
3164 output_loc_sequence_raw (loc);
3167 /* This function builds a dwarf location descriptor sequence from a
3168 dw_cfa_location, adding the given OFFSET to the result of the
3171 struct dw_loc_descr_struct *
3172 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
3174 struct dw_loc_descr_struct *head, *tmp;
3176 offset += cfa->offset;
3180 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
3181 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3182 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3183 add_loc_descr (&head, tmp);
3186 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
3187 add_loc_descr (&head, tmp);
3191 head = new_reg_loc_descr (cfa->reg, offset);
3196 /* This function builds a dwarf location descriptor sequence for
3197 the address at OFFSET from the CFA when stack is aligned to
3200 struct dw_loc_descr_struct *
3201 build_cfa_aligned_loc (dw_cfa_location *cfa,
3202 HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
3204 struct dw_loc_descr_struct *head;
3205 unsigned int dwarf_fp
3206 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
3208 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
3209 if (cfa->reg == HARD_FRAME_POINTER_REGNUM && cfa->indirect == 0)
3211 head = new_reg_loc_descr (dwarf_fp, 0);
3212 add_loc_descr (&head, int_loc_descriptor (alignment));
3213 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
3214 loc_descr_plus_const (&head, offset);
3217 head = new_reg_loc_descr (dwarf_fp, offset);
3221 /* And now, the support for symbolic debugging information. */
3223 /* .debug_str support. */
3224 static int output_indirect_string (void **, void *);
3226 static void dwarf2out_init (const char *);
3227 static void dwarf2out_finish (const char *);
3228 static void dwarf2out_assembly_start (void);
3229 static void dwarf2out_define (unsigned int, const char *);
3230 static void dwarf2out_undef (unsigned int, const char *);
3231 static void dwarf2out_start_source_file (unsigned, const char *);
3232 static void dwarf2out_end_source_file (unsigned);
3233 static void dwarf2out_function_decl (tree);
3234 static void dwarf2out_begin_block (unsigned, unsigned);
3235 static void dwarf2out_end_block (unsigned, unsigned);
3236 static bool dwarf2out_ignore_block (const_tree);
3237 static void dwarf2out_global_decl (tree);
3238 static void dwarf2out_type_decl (tree, int);
3239 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
3240 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
3242 static void dwarf2out_abstract_function (tree);
3243 static void dwarf2out_var_location (rtx);
3244 static void dwarf2out_begin_function (tree);
3245 static void dwarf2out_set_name (tree, tree);
3247 /* The debug hooks structure. */
3249 const struct gcc_debug_hooks dwarf2_debug_hooks =
3253 dwarf2out_assembly_start,
3256 dwarf2out_start_source_file,
3257 dwarf2out_end_source_file,
3258 dwarf2out_begin_block,
3259 dwarf2out_end_block,
3260 dwarf2out_ignore_block,
3261 dwarf2out_source_line,
3262 dwarf2out_begin_prologue,
3263 #if VMS_DEBUGGING_INFO
3264 dwarf2out_vms_end_prologue,
3265 dwarf2out_vms_begin_epilogue,
3267 debug_nothing_int_charstar,
3268 debug_nothing_int_charstar,
3270 dwarf2out_end_epilogue,
3271 dwarf2out_begin_function,
3272 debug_nothing_int, /* end_function */
3273 dwarf2out_function_decl, /* function_decl */
3274 dwarf2out_global_decl,
3275 dwarf2out_type_decl, /* type_decl */
3276 dwarf2out_imported_module_or_decl,
3277 debug_nothing_tree, /* deferred_inline_function */
3278 /* The DWARF 2 backend tries to reduce debugging bloat by not
3279 emitting the abstract description of inline functions until
3280 something tries to reference them. */
3281 dwarf2out_abstract_function, /* outlining_inline_function */
3282 debug_nothing_rtx, /* label */
3283 debug_nothing_int, /* handle_pch */
3284 dwarf2out_var_location,
3285 dwarf2out_switch_text_section,
3287 1, /* start_end_main_source_file */
3288 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
3291 /* NOTE: In the comments in this file, many references are made to
3292 "Debugging Information Entries". This term is abbreviated as `DIE'
3293 throughout the remainder of this file. */
3295 /* An internal representation of the DWARF output is built, and then
3296 walked to generate the DWARF debugging info. The walk of the internal
3297 representation is done after the entire program has been compiled.
3298 The types below are used to describe the internal representation. */
3300 /* Whether to put type DIEs into their own section .debug_types instead
3301 of making them part of the .debug_info section. Only supported for
3302 Dwarf V4 or higher and the user didn't disable them through
3303 -fno-debug-types-section. It is more efficient to put them in a
3304 separate comdat sections since the linker will then be able to
3305 remove duplicates. But not all tools support .debug_types sections
3308 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
3310 /* Various DIE's use offsets relative to the beginning of the
3311 .debug_info section to refer to each other. */
3313 typedef long int dw_offset;
3315 /* Define typedefs here to avoid circular dependencies. */
3317 typedef struct dw_attr_struct *dw_attr_ref;
3318 typedef struct dw_line_info_struct *dw_line_info_ref;
3319 typedef struct pubname_struct *pubname_ref;
3320 typedef struct dw_ranges_struct *dw_ranges_ref;
3321 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
3322 typedef struct comdat_type_struct *comdat_type_node_ref;
3324 /* The entries in the line_info table more-or-less mirror the opcodes
3325 that are used in the real dwarf line table. Arrays of these entries
3326 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
3329 enum dw_line_info_opcode {
3330 /* Emit DW_LNE_set_address; the operand is the label index. */
3333 /* Emit a row to the matrix with the given line. This may be done
3334 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
3338 /* Emit a DW_LNS_set_file. */
3341 /* Emit a DW_LNS_set_column. */
3344 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
3347 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
3348 LI_set_prologue_end,
3349 LI_set_epilogue_begin,
3351 /* Emit a DW_LNE_set_discriminator. */
3352 LI_set_discriminator
3355 typedef struct GTY(()) dw_line_info_struct {
3356 enum dw_line_info_opcode opcode;
3358 } dw_line_info_entry;
3360 DEF_VEC_O(dw_line_info_entry);
3361 DEF_VEC_ALLOC_O(dw_line_info_entry, gc);
3363 typedef struct GTY(()) dw_line_info_table_struct {
3364 /* The label that marks the end of this section. */
3365 const char *end_label;
3367 /* The values for the last row of the matrix, as collected in the table.
3368 These are used to minimize the changes to the next row. */
3369 unsigned int file_num;
3370 unsigned int line_num;
3371 unsigned int column_num;
3376 VEC(dw_line_info_entry, gc) *entries;
3377 } dw_line_info_table;
3379 typedef dw_line_info_table *dw_line_info_table_p;
3381 DEF_VEC_P(dw_line_info_table_p);
3382 DEF_VEC_ALLOC_P(dw_line_info_table_p, gc);
3384 /* Each DIE attribute has a field specifying the attribute kind,
3385 a link to the next attribute in the chain, and an attribute value.
3386 Attributes are typically linked below the DIE they modify. */
3388 typedef struct GTY(()) dw_attr_struct {
3389 enum dwarf_attribute dw_attr;
3390 dw_val_node dw_attr_val;
3394 DEF_VEC_O(dw_attr_node);
3395 DEF_VEC_ALLOC_O(dw_attr_node,gc);
3397 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
3398 The children of each node form a circular list linked by
3399 die_sib. die_child points to the node *before* the "first" child node. */
3401 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
3402 union die_symbol_or_type_node
3404 char * GTY ((tag ("0"))) die_symbol;
3405 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
3407 GTY ((desc ("use_debug_types"))) die_id;
3408 VEC(dw_attr_node,gc) * die_attr;
3409 dw_die_ref die_parent;
3410 dw_die_ref die_child;
3412 dw_die_ref die_definition; /* ref from a specification to its definition */
3413 dw_offset die_offset;
3414 unsigned long die_abbrev;
3416 /* Die is used and must not be pruned as unused. */
3417 int die_perennial_p;
3418 unsigned int decl_id;
3419 enum dwarf_tag die_tag;
3423 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3424 #define FOR_EACH_CHILD(die, c, expr) do { \
3425 c = die->die_child; \
3429 } while (c != die->die_child); \
3432 /* The pubname structure */
3434 typedef struct GTY(()) pubname_struct {
3440 DEF_VEC_O(pubname_entry);
3441 DEF_VEC_ALLOC_O(pubname_entry, gc);
3443 struct GTY(()) dw_ranges_struct {
3444 /* If this is positive, it's a block number, otherwise it's a
3445 bitwise-negated index into dw_ranges_by_label. */
3449 /* A structure to hold a macinfo entry. */
3451 typedef struct GTY(()) macinfo_struct {
3452 unsigned HOST_WIDE_INT code;
3453 unsigned HOST_WIDE_INT lineno;
3458 DEF_VEC_O(macinfo_entry);
3459 DEF_VEC_ALLOC_O(macinfo_entry, gc);
3461 struct GTY(()) dw_ranges_by_label_struct {
3466 /* The comdat type node structure. */
3467 typedef struct GTY(()) comdat_type_struct
3469 dw_die_ref root_die;
3470 dw_die_ref type_die;
3471 char signature[DWARF_TYPE_SIGNATURE_SIZE];
3472 struct comdat_type_struct *next;
3476 /* The limbo die list structure. */
3477 typedef struct GTY(()) limbo_die_struct {
3480 struct limbo_die_struct *next;
3484 typedef struct skeleton_chain_struct
3488 struct skeleton_chain_struct *parent;
3490 skeleton_chain_node;
3492 /* How to start an assembler comment. */
3493 #ifndef ASM_COMMENT_START
3494 #define ASM_COMMENT_START ";#"
3497 /* Define a macro which returns nonzero for a TYPE_DECL which was
3498 implicitly generated for a type.
3500 Note that, unlike the C front-end (which generates a NULL named
3501 TYPE_DECL node for each complete tagged type, each array type,
3502 and each function type node created) the C++ front-end generates
3503 a _named_ TYPE_DECL node for each tagged type node created.
3504 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3505 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
3506 front-end, but for each type, tagged or not. */
3508 #define TYPE_DECL_IS_STUB(decl) \
3509 (DECL_NAME (decl) == NULL_TREE \
3510 || (DECL_ARTIFICIAL (decl) \
3511 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3512 /* This is necessary for stub decls that \
3513 appear in nested inline functions. */ \
3514 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3515 && (decl_ultimate_origin (decl) \
3516 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3518 /* Information concerning the compilation unit's programming
3519 language, and compiler version. */
3521 /* Fixed size portion of the DWARF compilation unit header. */
3522 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3523 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3525 /* Fixed size portion of the DWARF comdat type unit header. */
3526 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
3527 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
3528 + DWARF_OFFSET_SIZE)
3530 /* Fixed size portion of public names info. */
3531 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3533 /* Fixed size portion of the address range info. */
3534 #define DWARF_ARANGES_HEADER_SIZE \
3535 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3536 DWARF2_ADDR_SIZE * 2) \
3537 - DWARF_INITIAL_LENGTH_SIZE)
3539 /* Size of padding portion in the address range info. It must be
3540 aligned to twice the pointer size. */
3541 #define DWARF_ARANGES_PAD_SIZE \
3542 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3543 DWARF2_ADDR_SIZE * 2) \
3544 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3546 /* Use assembler line directives if available. */
3547 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3548 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3549 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3551 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3555 /* Minimum line offset in a special line info. opcode.
3556 This value was chosen to give a reasonable range of values. */
3557 #define DWARF_LINE_BASE -10
3559 /* First special line opcode - leave room for the standard opcodes. */
3560 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
3562 /* Range of line offsets in a special line info. opcode. */
3563 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3565 /* Flag that indicates the initial value of the is_stmt_start flag.
3566 In the present implementation, we do not mark any lines as
3567 the beginning of a source statement, because that information
3568 is not made available by the GCC front-end. */
3569 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3571 /* Maximum number of operations per instruction bundle. */
3572 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
3573 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
3576 /* This location is used by calc_die_sizes() to keep track
3577 the offset of each DIE within the .debug_info section. */
3578 static unsigned long next_die_offset;
3580 /* Record the root of the DIE's built for the current compilation unit. */
3581 static GTY(()) dw_die_ref single_comp_unit_die;
3583 /* A list of type DIEs that have been separated into comdat sections. */
3584 static GTY(()) comdat_type_node *comdat_type_list;
3586 /* A list of DIEs with a NULL parent waiting to be relocated. */
3587 static GTY(()) limbo_die_node *limbo_die_list;
3589 /* A list of DIEs for which we may have to generate
3590 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
3591 static GTY(()) limbo_die_node *deferred_asm_name;
3593 /* Filenames referenced by this compilation unit. */
3594 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
3596 /* A hash table of references to DIE's that describe declarations.
3597 The key is a DECL_UID() which is a unique number identifying each decl. */
3598 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
3600 /* A hash table of references to DIE's that describe COMMON blocks.
3601 The key is DECL_UID() ^ die_parent. */
3602 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
3604 typedef struct GTY(()) die_arg_entry_struct {
3609 DEF_VEC_O(die_arg_entry);
3610 DEF_VEC_ALLOC_O(die_arg_entry,gc);
3612 /* Node of the variable location list. */
3613 struct GTY ((chain_next ("%h.next"))) var_loc_node {
3614 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3615 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3616 in mode of the EXPR_LIST node and first EXPR_LIST operand
3617 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3618 location or NULL for padding. For larger bitsizes,
3619 mode is 0 and first operand is a CONCAT with bitsize
3620 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3621 NULL as second operand. */
3623 const char * GTY (()) label;
3624 struct var_loc_node * GTY (()) next;
3627 /* Variable location list. */
3628 struct GTY (()) var_loc_list_def {
3629 struct var_loc_node * GTY (()) first;
3631 /* Pointer to the last but one or last element of the
3632 chained list. If the list is empty, both first and
3633 last are NULL, if the list contains just one node
3634 or the last node certainly is not redundant, it points
3635 to the last node, otherwise points to the last but one.
3636 Do not mark it for GC because it is marked through the chain. */
3637 struct var_loc_node * GTY ((skip ("%h"))) last;
3639 /* Pointer to the last element before section switch,
3640 if NULL, either sections weren't switched or first
3641 is after section switch. */
3642 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
3644 /* DECL_UID of the variable decl. */
3645 unsigned int decl_id;
3647 typedef struct var_loc_list_def var_loc_list;
3649 /* Call argument location list. */
3650 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
3651 rtx GTY (()) call_arg_loc_note;
3652 const char * GTY (()) label;
3653 tree GTY (()) block;
3655 rtx GTY (()) symbol_ref;
3656 struct call_arg_loc_node * GTY (()) next;
3660 /* Table of decl location linked lists. */
3661 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
3663 /* Head and tail of call_arg_loc chain. */
3664 static GTY (()) struct call_arg_loc_node *call_arg_locations;
3665 static struct call_arg_loc_node *call_arg_loc_last;
3667 /* Number of call sites in the current function. */
3668 static int call_site_count = -1;
3669 /* Number of tail call sites in the current function. */
3670 static int tail_call_site_count = -1;
3672 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
3674 static VEC (dw_die_ref, heap) *block_map;
3676 /* A cached location list. */
3677 struct GTY (()) cached_dw_loc_list_def {
3678 /* The DECL_UID of the decl that this entry describes. */
3679 unsigned int decl_id;
3681 /* The cached location list. */
3682 dw_loc_list_ref loc_list;
3684 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
3686 /* Table of cached location lists. */
3687 static GTY ((param_is (cached_dw_loc_list))) htab_t cached_dw_loc_list_table;
3689 /* A pointer to the base of a list of references to DIE's that
3690 are uniquely identified by their tag, presence/absence of
3691 children DIE's, and list of attribute/value pairs. */
3692 static GTY((length ("abbrev_die_table_allocated")))
3693 dw_die_ref *abbrev_die_table;
3695 /* Number of elements currently allocated for abbrev_die_table. */
3696 static GTY(()) unsigned abbrev_die_table_allocated;
3698 /* Number of elements in type_die_table currently in use. */
3699 static GTY(()) unsigned abbrev_die_table_in_use;
3701 /* Size (in elements) of increments by which we may expand the
3702 abbrev_die_table. */
3703 #define ABBREV_DIE_TABLE_INCREMENT 256
3705 /* A global counter for generating labels for line number data. */
3706 static unsigned int line_info_label_num;
3708 /* The current table to which we should emit line number information
3709 for the current function. This will be set up at the beginning of
3710 assembly for the function. */
3711 static dw_line_info_table *cur_line_info_table;
3713 /* The two default tables of line number info. */
3714 static GTY(()) dw_line_info_table *text_section_line_info;
3715 static GTY(()) dw_line_info_table *cold_text_section_line_info;
3717 /* The set of all non-default tables of line number info. */
3718 static GTY(()) VEC (dw_line_info_table_p, gc) *separate_line_info;
3720 /* A flag to tell pubnames/types export if there is an info section to
3722 static bool info_section_emitted;
3724 /* A pointer to the base of a table that contains a list of publicly
3725 accessible names. */
3726 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
3728 /* A pointer to the base of a table that contains a list of publicly
3729 accessible types. */
3730 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
3732 /* A pointer to the base of a table that contains a list of macro
3733 defines/undefines (and file start/end markers). */
3734 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
3736 /* Array of dies for which we should generate .debug_ranges info. */
3737 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3739 /* Number of elements currently allocated for ranges_table. */
3740 static GTY(()) unsigned ranges_table_allocated;
3742 /* Number of elements in ranges_table currently in use. */
3743 static GTY(()) unsigned ranges_table_in_use;
3745 /* Array of pairs of labels referenced in ranges_table. */
3746 static GTY ((length ("ranges_by_label_allocated")))
3747 dw_ranges_by_label_ref ranges_by_label;
3749 /* Number of elements currently allocated for ranges_by_label. */
3750 static GTY(()) unsigned ranges_by_label_allocated;
3752 /* Number of elements in ranges_by_label currently in use. */
3753 static GTY(()) unsigned ranges_by_label_in_use;
3755 /* Size (in elements) of increments by which we may expand the
3757 #define RANGES_TABLE_INCREMENT 64
3759 /* Whether we have location lists that need outputting */
3760 static GTY(()) bool have_location_lists;
3762 /* Unique label counter. */
3763 static GTY(()) unsigned int loclabel_num;
3765 /* Unique label counter for point-of-call tables. */
3766 static GTY(()) unsigned int poc_label_num;
3768 /* Record whether the function being analyzed contains inlined functions. */
3769 static int current_function_has_inlines;
3771 /* The last file entry emitted by maybe_emit_file(). */
3772 static GTY(()) struct dwarf_file_data * last_emitted_file;
3774 /* Number of internal labels generated by gen_internal_sym(). */
3775 static GTY(()) int label_num;
3777 /* Cached result of previous call to lookup_filename. */
3778 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
3780 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
3782 /* Instances of generic types for which we need to generate debug
3783 info that describe their generic parameters and arguments. That
3784 generation needs to happen once all types are properly laid out so
3785 we do it at the end of compilation. */
3786 static GTY(()) VEC(tree,gc) *generic_type_instances;
3788 /* Offset from the "steady-state frame pointer" to the frame base,
3789 within the current function. */
3790 static HOST_WIDE_INT frame_pointer_fb_offset;
3791 static bool frame_pointer_fb_offset_valid;
3793 static VEC (dw_die_ref, heap) *base_types;
3795 /* Forward declarations for functions defined in this file. */
3797 static int is_pseudo_reg (const_rtx);
3798 static tree type_main_variant (tree);
3799 static int is_tagged_type (const_tree);
3800 static const char *dwarf_tag_name (unsigned);
3801 static const char *dwarf_attr_name (unsigned);
3802 static const char *dwarf_form_name (unsigned);
3803 static tree decl_ultimate_origin (const_tree);
3804 static tree decl_class_context (tree);
3805 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3806 static inline enum dw_val_class AT_class (dw_attr_ref);
3807 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3808 static inline unsigned AT_flag (dw_attr_ref);
3809 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3810 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
3811 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3812 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
3813 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
3814 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
3815 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3816 unsigned int, unsigned char *);
3817 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
3818 static hashval_t debug_str_do_hash (const void *);
3819 static int debug_str_eq (const void *, const void *);
3820 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3821 static inline const char *AT_string (dw_attr_ref);
3822 static enum dwarf_form AT_string_form (dw_attr_ref);
3823 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3824 static void add_AT_specification (dw_die_ref, dw_die_ref);
3825 static inline dw_die_ref AT_ref (dw_attr_ref);
3826 static inline int AT_ref_external (dw_attr_ref);
3827 static inline void set_AT_ref_external (dw_attr_ref, int);
3828 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3829 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3830 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3831 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3833 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3834 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3835 static inline rtx AT_addr (dw_attr_ref);
3836 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3837 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
3838 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
3839 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
3840 unsigned HOST_WIDE_INT);
3841 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3843 static inline const char *AT_lbl (dw_attr_ref);
3844 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3845 static const char *get_AT_low_pc (dw_die_ref);
3846 static const char *get_AT_hi_pc (dw_die_ref);
3847 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3848 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3849 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3850 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3851 static bool is_cxx (void);
3852 static bool is_fortran (void);
3853 static bool is_ada (void);
3854 static void remove_AT (dw_die_ref, enum dwarf_attribute);
3855 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3856 static void add_child_die (dw_die_ref, dw_die_ref);
3857 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3858 static dw_die_ref lookup_type_die (tree);
3859 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
3860 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
3861 static void equate_type_number_to_die (tree, dw_die_ref);
3862 static hashval_t decl_die_table_hash (const void *);
3863 static int decl_die_table_eq (const void *, const void *);
3864 static dw_die_ref lookup_decl_die (tree);
3865 static hashval_t common_block_die_table_hash (const void *);
3866 static int common_block_die_table_eq (const void *, const void *);
3867 static hashval_t decl_loc_table_hash (const void *);
3868 static int decl_loc_table_eq (const void *, const void *);
3869 static var_loc_list *lookup_decl_loc (const_tree);
3870 static void equate_decl_number_to_die (tree, dw_die_ref);
3871 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
3872 static void print_spaces (FILE *);
3873 static void print_die (dw_die_ref, FILE *);
3874 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3875 static dw_die_ref pop_compile_unit (dw_die_ref);
3876 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3877 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3878 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3879 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
3880 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
3881 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
3882 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
3883 struct md5_ctx *, int *);
3884 struct checksum_attributes;
3885 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
3886 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
3887 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
3888 static void generate_type_signature (dw_die_ref, comdat_type_node *);
3889 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3890 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
3891 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3892 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3893 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3894 static void compute_section_prefix (dw_die_ref);
3895 static int is_type_die (dw_die_ref);
3896 static int is_comdat_die (dw_die_ref);
3897 static int is_symbol_die (dw_die_ref);
3898 static void assign_symbol_names (dw_die_ref);
3899 static void break_out_includes (dw_die_ref);
3900 static int is_declaration_die (dw_die_ref);
3901 static int should_move_die_to_comdat (dw_die_ref);
3902 static dw_die_ref clone_as_declaration (dw_die_ref);
3903 static dw_die_ref clone_die (dw_die_ref);
3904 static dw_die_ref clone_tree (dw_die_ref);
3905 static void copy_declaration_context (dw_die_ref, dw_die_ref);
3906 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
3907 static void generate_skeleton_bottom_up (skeleton_chain_node *);
3908 static dw_die_ref generate_skeleton (dw_die_ref);
3909 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
3911 static void break_out_comdat_types (dw_die_ref);
3912 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
3913 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
3914 static void copy_decls_for_unworthy_types (dw_die_ref);
3916 static hashval_t htab_cu_hash (const void *);
3917 static int htab_cu_eq (const void *, const void *);
3918 static void htab_cu_del (void *);
3919 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
3920 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
3921 static void add_sibling_attributes (dw_die_ref);
3922 static void build_abbrev_table (dw_die_ref);
3923 static void output_location_lists (dw_die_ref);
3924 static int constant_size (unsigned HOST_WIDE_INT);
3925 static unsigned long size_of_die (dw_die_ref);
3926 static void calc_die_sizes (dw_die_ref);
3927 static void calc_base_type_die_sizes (void);
3928 static void mark_dies (dw_die_ref);
3929 static void unmark_dies (dw_die_ref);
3930 static void unmark_all_dies (dw_die_ref);
3931 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
3932 static unsigned long size_of_aranges (void);
3933 static enum dwarf_form value_format (dw_attr_ref);
3934 static void output_value_format (dw_attr_ref);
3935 static void output_abbrev_section (void);
3936 static void output_die_symbol (dw_die_ref);
3937 static void output_die (dw_die_ref);
3938 static void output_compilation_unit_header (void);
3939 static void output_comp_unit (dw_die_ref, int);
3940 static void output_comdat_type_unit (comdat_type_node *);
3941 static const char *dwarf2_name (tree, int);
3942 static void add_pubname (tree, dw_die_ref);
3943 static void add_pubname_string (const char *, dw_die_ref);
3944 static void add_pubtype (tree, dw_die_ref);
3945 static void output_pubnames (VEC (pubname_entry,gc) *);
3946 static void output_aranges (unsigned long);
3947 static unsigned int add_ranges_num (int);
3948 static unsigned int add_ranges (const_tree);
3949 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
3951 static void output_ranges (void);
3952 static dw_line_info_table *new_line_info_table (void);
3953 static void output_line_info (void);
3954 static void output_file_names (void);
3955 static dw_die_ref base_type_die (tree);
3956 static int is_base_type (tree);
3957 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
3958 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
3959 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
3960 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
3961 static int type_is_enum (const_tree);
3962 static unsigned int dbx_reg_number (const_rtx);
3963 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
3964 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
3965 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
3966 enum var_init_status);
3967 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
3968 enum var_init_status);
3969 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
3970 enum var_init_status);
3971 static int is_based_loc (const_rtx);
3972 static int resolve_one_addr (rtx *, void *);
3973 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
3974 enum var_init_status);
3975 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
3976 enum var_init_status);
3977 static dw_loc_list_ref loc_list_from_tree (tree, int);
3978 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
3979 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3980 static tree field_type (const_tree);
3981 static unsigned int simple_type_align_in_bits (const_tree);
3982 static unsigned int simple_decl_align_in_bits (const_tree);
3983 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
3984 static HOST_WIDE_INT field_byte_offset (const_tree);
3985 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3987 static void add_data_member_location_attribute (dw_die_ref, tree);
3988 static bool add_const_value_attribute (dw_die_ref, rtx);
3989 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
3990 static void insert_double (double_int, unsigned char *);
3991 static void insert_float (const_rtx, unsigned char *);
3992 static rtx rtl_for_decl_location (tree);
3993 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
3994 enum dwarf_attribute);
3995 static bool tree_add_const_value_attribute (dw_die_ref, tree);
3996 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
3997 static void add_name_attribute (dw_die_ref, const char *);
3998 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
3999 static void add_comp_dir_attribute (dw_die_ref);
4000 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
4001 static void add_subscript_info (dw_die_ref, tree, bool);
4002 static void add_byte_size_attribute (dw_die_ref, tree);
4003 static void add_bit_offset_attribute (dw_die_ref, tree);
4004 static void add_bit_size_attribute (dw_die_ref, tree);
4005 static void add_prototyped_attribute (dw_die_ref, tree);
4006 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
4007 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
4008 static void add_src_coords_attributes (dw_die_ref, tree);
4009 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
4010 static void push_decl_scope (tree);
4011 static void pop_decl_scope (void);
4012 static dw_die_ref scope_die_for (tree, dw_die_ref);
4013 static inline int local_scope_p (dw_die_ref);
4014 static inline int class_scope_p (dw_die_ref);
4015 static inline int class_or_namespace_scope_p (dw_die_ref);
4016 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
4017 static void add_calling_convention_attribute (dw_die_ref, tree);
4018 static const char *type_tag (const_tree);
4019 static tree member_declared_type (const_tree);
4021 static const char *decl_start_label (tree);
4023 static void gen_array_type_die (tree, dw_die_ref);
4024 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
4026 static void gen_entry_point_die (tree, dw_die_ref);
4028 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
4029 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
4030 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
4031 static void gen_unspecified_parameters_die (tree, dw_die_ref);
4032 static void gen_formal_types_die (tree, dw_die_ref);
4033 static void gen_subprogram_die (tree, dw_die_ref);
4034 static void gen_variable_die (tree, tree, dw_die_ref);
4035 static void gen_const_die (tree, dw_die_ref);
4036 static void gen_label_die (tree, dw_die_ref);
4037 static void gen_lexical_block_die (tree, dw_die_ref, int);
4038 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
4039 static void gen_field_die (tree, dw_die_ref);
4040 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
4041 static dw_die_ref gen_compile_unit_die (const char *);
4042 static void gen_inheritance_die (tree, tree, dw_die_ref);
4043 static void gen_member_die (tree, dw_die_ref);
4044 static void gen_struct_or_union_type_die (tree, dw_die_ref,
4045 enum debug_info_usage);
4046 static void gen_subroutine_type_die (tree, dw_die_ref);
4047 static void gen_typedef_die (tree, dw_die_ref);
4048 static void gen_type_die (tree, dw_die_ref);
4049 static void gen_block_die (tree, dw_die_ref, int);
4050 static void decls_for_scope (tree, dw_die_ref, int);
4051 static inline int is_redundant_typedef (const_tree);
4052 static bool is_naming_typedef_decl (const_tree);
4053 static inline dw_die_ref get_context_die (tree);
4054 static void gen_namespace_die (tree, dw_die_ref);
4055 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
4056 static dw_die_ref force_decl_die (tree);
4057 static dw_die_ref force_type_die (tree);
4058 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
4059 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
4060 static struct dwarf_file_data * lookup_filename (const char *);
4061 static void retry_incomplete_types (void);
4062 static void gen_type_die_for_member (tree, tree, dw_die_ref);
4063 static void gen_generic_params_dies (tree);
4064 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
4065 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
4066 static void splice_child_die (dw_die_ref, dw_die_ref);
4067 static int file_info_cmp (const void *, const void *);
4068 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
4069 const char *, const char *);
4070 static void output_loc_list (dw_loc_list_ref);
4071 static char *gen_internal_sym (const char *);
4073 static void prune_unmark_dies (dw_die_ref);
4074 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
4075 static void prune_unused_types_mark (dw_die_ref, int);
4076 static void prune_unused_types_walk (dw_die_ref);
4077 static void prune_unused_types_walk_attribs (dw_die_ref);
4078 static void prune_unused_types_prune (dw_die_ref);
4079 static void prune_unused_types (void);
4080 static int maybe_emit_file (struct dwarf_file_data *fd);
4081 static inline const char *AT_vms_delta1 (dw_attr_ref);
4082 static inline const char *AT_vms_delta2 (dw_attr_ref);
4083 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
4084 const char *, const char *);
4085 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
4086 static void gen_remaining_tmpl_value_param_die_attribute (void);
4087 static bool generic_type_p (tree);
4088 static void schedule_generic_params_dies_gen (tree t);
4089 static void gen_scheduled_generic_parms_dies (void);
4091 /* Section names used to hold DWARF debugging information. */
4092 #ifndef DEBUG_INFO_SECTION
4093 #define DEBUG_INFO_SECTION ".debug_info"
4095 #ifndef DEBUG_ABBREV_SECTION
4096 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4098 #ifndef DEBUG_ARANGES_SECTION
4099 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4101 #ifndef DEBUG_MACINFO_SECTION
4102 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4104 #ifndef DEBUG_LINE_SECTION
4105 #define DEBUG_LINE_SECTION ".debug_line"
4107 #ifndef DEBUG_LOC_SECTION
4108 #define DEBUG_LOC_SECTION ".debug_loc"
4110 #ifndef DEBUG_PUBNAMES_SECTION
4111 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4113 #ifndef DEBUG_PUBTYPES_SECTION
4114 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
4116 #ifndef DEBUG_STR_SECTION
4117 #define DEBUG_STR_SECTION ".debug_str"
4119 #ifndef DEBUG_RANGES_SECTION
4120 #define DEBUG_RANGES_SECTION ".debug_ranges"
4123 /* Standard ELF section names for compiled code and data. */
4124 #ifndef TEXT_SECTION_NAME
4125 #define TEXT_SECTION_NAME ".text"
4128 /* Section flags for .debug_str section. */
4129 #define DEBUG_STR_SECTION_FLAGS \
4130 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
4131 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4134 /* Labels we insert at beginning sections we can reference instead of
4135 the section names themselves. */
4137 #ifndef TEXT_SECTION_LABEL
4138 #define TEXT_SECTION_LABEL "Ltext"
4140 #ifndef COLD_TEXT_SECTION_LABEL
4141 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4143 #ifndef DEBUG_LINE_SECTION_LABEL
4144 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4146 #ifndef DEBUG_INFO_SECTION_LABEL
4147 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4149 #ifndef DEBUG_ABBREV_SECTION_LABEL
4150 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4152 #ifndef DEBUG_LOC_SECTION_LABEL
4153 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4155 #ifndef DEBUG_RANGES_SECTION_LABEL
4156 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4158 #ifndef DEBUG_MACINFO_SECTION_LABEL
4159 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4163 /* Definitions of defaults for formats and names of various special
4164 (artificial) labels which may be generated within this file (when the -g
4165 options is used and DWARF2_DEBUGGING_INFO is in effect.
4166 If necessary, these may be overridden from within the tm.h file, but
4167 typically, overriding these defaults is unnecessary. */
4169 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4170 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4171 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4172 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4173 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4174 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4175 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4176 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4177 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4178 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4180 #ifndef TEXT_END_LABEL
4181 #define TEXT_END_LABEL "Letext"
4183 #ifndef COLD_END_LABEL
4184 #define COLD_END_LABEL "Letext_cold"
4186 #ifndef BLOCK_BEGIN_LABEL
4187 #define BLOCK_BEGIN_LABEL "LBB"
4189 #ifndef BLOCK_END_LABEL
4190 #define BLOCK_END_LABEL "LBE"
4192 #ifndef LINE_CODE_LABEL
4193 #define LINE_CODE_LABEL "LM"
4197 /* Return the root of the DIE's built for the current compilation unit. */
4199 comp_unit_die (void)
4201 if (!single_comp_unit_die)
4202 single_comp_unit_die = gen_compile_unit_die (NULL);
4203 return single_comp_unit_die;
4206 /* We allow a language front-end to designate a function that is to be
4207 called to "demangle" any name before it is put into a DIE. */
4209 static const char *(*demangle_name_func) (const char *);
4212 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4214 demangle_name_func = func;
4217 /* Test if rtl node points to a pseudo register. */
4220 is_pseudo_reg (const_rtx rtl)
4222 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4223 || (GET_CODE (rtl) == SUBREG
4224 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4227 /* Return a reference to a type, with its const and volatile qualifiers
4231 type_main_variant (tree type)
4233 type = TYPE_MAIN_VARIANT (type);
4235 /* ??? There really should be only one main variant among any group of
4236 variants of a given type (and all of the MAIN_VARIANT values for all
4237 members of the group should point to that one type) but sometimes the C
4238 front-end messes this up for array types, so we work around that bug
4240 if (TREE_CODE (type) == ARRAY_TYPE)
4241 while (type != TYPE_MAIN_VARIANT (type))
4242 type = TYPE_MAIN_VARIANT (type);
4247 /* Return nonzero if the given type node represents a tagged type. */
4250 is_tagged_type (const_tree type)
4252 enum tree_code code = TREE_CODE (type);
4254 return (code == RECORD_TYPE || code == UNION_TYPE
4255 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4258 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
4261 get_ref_die_offset_label (char *label, dw_die_ref ref)
4263 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
4266 /* Return die_offset of a DIE reference to a base type. */
4268 static unsigned long int
4269 get_base_type_offset (dw_die_ref ref)
4271 if (ref->die_offset)
4272 return ref->die_offset;
4273 if (comp_unit_die ()->die_abbrev)
4275 calc_base_type_die_sizes ();
4276 gcc_assert (ref->die_offset);
4278 return ref->die_offset;
4281 /* Return die_offset of a DIE reference other than base type. */
4283 static unsigned long int
4284 get_ref_die_offset (dw_die_ref ref)
4286 gcc_assert (ref->die_offset);
4287 return ref->die_offset;
4290 /* Convert a DIE tag into its string name. */
4293 dwarf_tag_name (unsigned int tag)
4297 case DW_TAG_padding:
4298 return "DW_TAG_padding";
4299 case DW_TAG_array_type:
4300 return "DW_TAG_array_type";
4301 case DW_TAG_class_type:
4302 return "DW_TAG_class_type";
4303 case DW_TAG_entry_point:
4304 return "DW_TAG_entry_point";
4305 case DW_TAG_enumeration_type:
4306 return "DW_TAG_enumeration_type";
4307 case DW_TAG_formal_parameter:
4308 return "DW_TAG_formal_parameter";
4309 case DW_TAG_imported_declaration:
4310 return "DW_TAG_imported_declaration";
4312 return "DW_TAG_label";
4313 case DW_TAG_lexical_block:
4314 return "DW_TAG_lexical_block";
4316 return "DW_TAG_member";
4317 case DW_TAG_pointer_type:
4318 return "DW_TAG_pointer_type";
4319 case DW_TAG_reference_type:
4320 return "DW_TAG_reference_type";
4321 case DW_TAG_compile_unit:
4322 return "DW_TAG_compile_unit";
4323 case DW_TAG_string_type:
4324 return "DW_TAG_string_type";
4325 case DW_TAG_structure_type:
4326 return "DW_TAG_structure_type";
4327 case DW_TAG_subroutine_type:
4328 return "DW_TAG_subroutine_type";
4329 case DW_TAG_typedef:
4330 return "DW_TAG_typedef";
4331 case DW_TAG_union_type:
4332 return "DW_TAG_union_type";
4333 case DW_TAG_unspecified_parameters:
4334 return "DW_TAG_unspecified_parameters";
4335 case DW_TAG_variant:
4336 return "DW_TAG_variant";
4337 case DW_TAG_common_block:
4338 return "DW_TAG_common_block";
4339 case DW_TAG_common_inclusion:
4340 return "DW_TAG_common_inclusion";
4341 case DW_TAG_inheritance:
4342 return "DW_TAG_inheritance";
4343 case DW_TAG_inlined_subroutine:
4344 return "DW_TAG_inlined_subroutine";
4346 return "DW_TAG_module";
4347 case DW_TAG_ptr_to_member_type:
4348 return "DW_TAG_ptr_to_member_type";
4349 case DW_TAG_set_type:
4350 return "DW_TAG_set_type";
4351 case DW_TAG_subrange_type:
4352 return "DW_TAG_subrange_type";
4353 case DW_TAG_with_stmt:
4354 return "DW_TAG_with_stmt";
4355 case DW_TAG_access_declaration:
4356 return "DW_TAG_access_declaration";
4357 case DW_TAG_base_type:
4358 return "DW_TAG_base_type";
4359 case DW_TAG_catch_block:
4360 return "DW_TAG_catch_block";
4361 case DW_TAG_const_type:
4362 return "DW_TAG_const_type";
4363 case DW_TAG_constant:
4364 return "DW_TAG_constant";
4365 case DW_TAG_enumerator:
4366 return "DW_TAG_enumerator";
4367 case DW_TAG_file_type:
4368 return "DW_TAG_file_type";
4370 return "DW_TAG_friend";
4371 case DW_TAG_namelist:
4372 return "DW_TAG_namelist";
4373 case DW_TAG_namelist_item:
4374 return "DW_TAG_namelist_item";
4375 case DW_TAG_packed_type:
4376 return "DW_TAG_packed_type";
4377 case DW_TAG_subprogram:
4378 return "DW_TAG_subprogram";
4379 case DW_TAG_template_type_param:
4380 return "DW_TAG_template_type_param";
4381 case DW_TAG_template_value_param:
4382 return "DW_TAG_template_value_param";
4383 case DW_TAG_thrown_type:
4384 return "DW_TAG_thrown_type";
4385 case DW_TAG_try_block:
4386 return "DW_TAG_try_block";
4387 case DW_TAG_variant_part:
4388 return "DW_TAG_variant_part";
4389 case DW_TAG_variable:
4390 return "DW_TAG_variable";
4391 case DW_TAG_volatile_type:
4392 return "DW_TAG_volatile_type";
4393 case DW_TAG_dwarf_procedure:
4394 return "DW_TAG_dwarf_procedure";
4395 case DW_TAG_restrict_type:
4396 return "DW_TAG_restrict_type";
4397 case DW_TAG_interface_type:
4398 return "DW_TAG_interface_type";
4399 case DW_TAG_namespace:
4400 return "DW_TAG_namespace";
4401 case DW_TAG_imported_module:
4402 return "DW_TAG_imported_module";
4403 case DW_TAG_unspecified_type:
4404 return "DW_TAG_unspecified_type";
4405 case DW_TAG_partial_unit:
4406 return "DW_TAG_partial_unit";
4407 case DW_TAG_imported_unit:
4408 return "DW_TAG_imported_unit";
4409 case DW_TAG_condition:
4410 return "DW_TAG_condition";
4411 case DW_TAG_shared_type:
4412 return "DW_TAG_shared_type";
4413 case DW_TAG_type_unit:
4414 return "DW_TAG_type_unit";
4415 case DW_TAG_rvalue_reference_type:
4416 return "DW_TAG_rvalue_reference_type";
4417 case DW_TAG_template_alias:
4418 return "DW_TAG_template_alias";
4419 case DW_TAG_GNU_template_parameter_pack:
4420 return "DW_TAG_GNU_template_parameter_pack";
4421 case DW_TAG_GNU_formal_parameter_pack:
4422 return "DW_TAG_GNU_formal_parameter_pack";
4423 case DW_TAG_MIPS_loop:
4424 return "DW_TAG_MIPS_loop";
4425 case DW_TAG_format_label:
4426 return "DW_TAG_format_label";
4427 case DW_TAG_function_template:
4428 return "DW_TAG_function_template";
4429 case DW_TAG_class_template:
4430 return "DW_TAG_class_template";
4431 case DW_TAG_GNU_BINCL:
4432 return "DW_TAG_GNU_BINCL";
4433 case DW_TAG_GNU_EINCL:
4434 return "DW_TAG_GNU_EINCL";
4435 case DW_TAG_GNU_template_template_param:
4436 return "DW_TAG_GNU_template_template_param";
4437 case DW_TAG_GNU_call_site:
4438 return "DW_TAG_GNU_call_site";
4439 case DW_TAG_GNU_call_site_parameter:
4440 return "DW_TAG_GNU_call_site_parameter";
4442 return "DW_TAG_<unknown>";
4446 /* Convert a DWARF attribute code into its string name. */
4449 dwarf_attr_name (unsigned int attr)
4454 return "DW_AT_sibling";
4455 case DW_AT_location:
4456 return "DW_AT_location";
4458 return "DW_AT_name";
4459 case DW_AT_ordering:
4460 return "DW_AT_ordering";
4461 case DW_AT_subscr_data:
4462 return "DW_AT_subscr_data";
4463 case DW_AT_byte_size:
4464 return "DW_AT_byte_size";
4465 case DW_AT_bit_offset:
4466 return "DW_AT_bit_offset";
4467 case DW_AT_bit_size:
4468 return "DW_AT_bit_size";
4469 case DW_AT_element_list:
4470 return "DW_AT_element_list";
4471 case DW_AT_stmt_list:
4472 return "DW_AT_stmt_list";
4474 return "DW_AT_low_pc";
4476 return "DW_AT_high_pc";
4477 case DW_AT_language:
4478 return "DW_AT_language";
4480 return "DW_AT_member";
4482 return "DW_AT_discr";
4483 case DW_AT_discr_value:
4484 return "DW_AT_discr_value";
4485 case DW_AT_visibility:
4486 return "DW_AT_visibility";
4488 return "DW_AT_import";
4489 case DW_AT_string_length:
4490 return "DW_AT_string_length";
4491 case DW_AT_common_reference:
4492 return "DW_AT_common_reference";
4493 case DW_AT_comp_dir:
4494 return "DW_AT_comp_dir";
4495 case DW_AT_const_value:
4496 return "DW_AT_const_value";
4497 case DW_AT_containing_type:
4498 return "DW_AT_containing_type";
4499 case DW_AT_default_value:
4500 return "DW_AT_default_value";
4502 return "DW_AT_inline";
4503 case DW_AT_is_optional:
4504 return "DW_AT_is_optional";
4505 case DW_AT_lower_bound:
4506 return "DW_AT_lower_bound";
4507 case DW_AT_producer:
4508 return "DW_AT_producer";
4509 case DW_AT_prototyped:
4510 return "DW_AT_prototyped";
4511 case DW_AT_return_addr:
4512 return "DW_AT_return_addr";
4513 case DW_AT_start_scope:
4514 return "DW_AT_start_scope";
4515 case DW_AT_bit_stride:
4516 return "DW_AT_bit_stride";
4517 case DW_AT_upper_bound:
4518 return "DW_AT_upper_bound";
4519 case DW_AT_abstract_origin:
4520 return "DW_AT_abstract_origin";
4521 case DW_AT_accessibility:
4522 return "DW_AT_accessibility";
4523 case DW_AT_address_class:
4524 return "DW_AT_address_class";
4525 case DW_AT_artificial:
4526 return "DW_AT_artificial";
4527 case DW_AT_base_types:
4528 return "DW_AT_base_types";
4529 case DW_AT_calling_convention:
4530 return "DW_AT_calling_convention";
4532 return "DW_AT_count";
4533 case DW_AT_data_member_location:
4534 return "DW_AT_data_member_location";
4535 case DW_AT_decl_column:
4536 return "DW_AT_decl_column";
4537 case DW_AT_decl_file:
4538 return "DW_AT_decl_file";
4539 case DW_AT_decl_line:
4540 return "DW_AT_decl_line";
4541 case DW_AT_declaration:
4542 return "DW_AT_declaration";
4543 case DW_AT_discr_list:
4544 return "DW_AT_discr_list";
4545 case DW_AT_encoding:
4546 return "DW_AT_encoding";
4547 case DW_AT_external:
4548 return "DW_AT_external";
4549 case DW_AT_explicit:
4550 return "DW_AT_explicit";
4551 case DW_AT_frame_base:
4552 return "DW_AT_frame_base";
4554 return "DW_AT_friend";
4555 case DW_AT_identifier_case:
4556 return "DW_AT_identifier_case";
4557 case DW_AT_macro_info:
4558 return "DW_AT_macro_info";
4559 case DW_AT_namelist_items:
4560 return "DW_AT_namelist_items";
4561 case DW_AT_priority:
4562 return "DW_AT_priority";
4564 return "DW_AT_segment";
4565 case DW_AT_specification:
4566 return "DW_AT_specification";
4567 case DW_AT_static_link:
4568 return "DW_AT_static_link";
4570 return "DW_AT_type";
4571 case DW_AT_use_location:
4572 return "DW_AT_use_location";
4573 case DW_AT_variable_parameter:
4574 return "DW_AT_variable_parameter";
4575 case DW_AT_virtuality:
4576 return "DW_AT_virtuality";
4577 case DW_AT_vtable_elem_location:
4578 return "DW_AT_vtable_elem_location";
4580 case DW_AT_allocated:
4581 return "DW_AT_allocated";
4582 case DW_AT_associated:
4583 return "DW_AT_associated";
4584 case DW_AT_data_location:
4585 return "DW_AT_data_location";
4586 case DW_AT_byte_stride:
4587 return "DW_AT_byte_stride";
4588 case DW_AT_entry_pc:
4589 return "DW_AT_entry_pc";
4590 case DW_AT_use_UTF8:
4591 return "DW_AT_use_UTF8";
4592 case DW_AT_extension:
4593 return "DW_AT_extension";
4595 return "DW_AT_ranges";
4596 case DW_AT_trampoline:
4597 return "DW_AT_trampoline";
4598 case DW_AT_call_column:
4599 return "DW_AT_call_column";
4600 case DW_AT_call_file:
4601 return "DW_AT_call_file";
4602 case DW_AT_call_line:
4603 return "DW_AT_call_line";
4604 case DW_AT_object_pointer:
4605 return "DW_AT_object_pointer";
4607 case DW_AT_signature:
4608 return "DW_AT_signature";
4609 case DW_AT_main_subprogram:
4610 return "DW_AT_main_subprogram";
4611 case DW_AT_data_bit_offset:
4612 return "DW_AT_data_bit_offset";
4613 case DW_AT_const_expr:
4614 return "DW_AT_const_expr";
4615 case DW_AT_enum_class:
4616 return "DW_AT_enum_class";
4617 case DW_AT_linkage_name:
4618 return "DW_AT_linkage_name";
4620 case DW_AT_MIPS_fde:
4621 return "DW_AT_MIPS_fde";
4622 case DW_AT_MIPS_loop_begin:
4623 return "DW_AT_MIPS_loop_begin";
4624 case DW_AT_MIPS_tail_loop_begin:
4625 return "DW_AT_MIPS_tail_loop_begin";
4626 case DW_AT_MIPS_epilog_begin:
4627 return "DW_AT_MIPS_epilog_begin";
4628 #if VMS_DEBUGGING_INFO
4629 case DW_AT_HP_prologue:
4630 return "DW_AT_HP_prologue";
4632 case DW_AT_MIPS_loop_unroll_factor:
4633 return "DW_AT_MIPS_loop_unroll_factor";
4635 case DW_AT_MIPS_software_pipeline_depth:
4636 return "DW_AT_MIPS_software_pipeline_depth";
4637 case DW_AT_MIPS_linkage_name:
4638 return "DW_AT_MIPS_linkage_name";
4639 #if VMS_DEBUGGING_INFO
4640 case DW_AT_HP_epilogue:
4641 return "DW_AT_HP_epilogue";
4643 case DW_AT_MIPS_stride:
4644 return "DW_AT_MIPS_stride";
4646 case DW_AT_MIPS_abstract_name:
4647 return "DW_AT_MIPS_abstract_name";
4648 case DW_AT_MIPS_clone_origin:
4649 return "DW_AT_MIPS_clone_origin";
4650 case DW_AT_MIPS_has_inlines:
4651 return "DW_AT_MIPS_has_inlines";
4653 case DW_AT_sf_names:
4654 return "DW_AT_sf_names";
4655 case DW_AT_src_info:
4656 return "DW_AT_src_info";
4657 case DW_AT_mac_info:
4658 return "DW_AT_mac_info";
4659 case DW_AT_src_coords:
4660 return "DW_AT_src_coords";
4661 case DW_AT_body_begin:
4662 return "DW_AT_body_begin";
4663 case DW_AT_body_end:
4664 return "DW_AT_body_end";
4666 case DW_AT_GNU_vector:
4667 return "DW_AT_GNU_vector";
4668 case DW_AT_GNU_guarded_by:
4669 return "DW_AT_GNU_guarded_by";
4670 case DW_AT_GNU_pt_guarded_by:
4671 return "DW_AT_GNU_pt_guarded_by";
4672 case DW_AT_GNU_guarded:
4673 return "DW_AT_GNU_guarded";
4674 case DW_AT_GNU_pt_guarded:
4675 return "DW_AT_GNU_pt_guarded";
4676 case DW_AT_GNU_locks_excluded:
4677 return "DW_AT_GNU_locks_excluded";
4678 case DW_AT_GNU_exclusive_locks_required:
4679 return "DW_AT_GNU_exclusive_locks_required";
4680 case DW_AT_GNU_shared_locks_required:
4681 return "DW_AT_GNU_shared_locks_required";
4682 case DW_AT_GNU_odr_signature:
4683 return "DW_AT_GNU_odr_signature";
4684 case DW_AT_GNU_template_name:
4685 return "DW_AT_GNU_template_name";
4686 case DW_AT_GNU_call_site_value:
4687 return "DW_AT_GNU_call_site_value";
4688 case DW_AT_GNU_call_site_data_value:
4689 return "DW_AT_GNU_call_site_data_value";
4690 case DW_AT_GNU_call_site_target:
4691 return "DW_AT_GNU_call_site_target";
4692 case DW_AT_GNU_call_site_target_clobbered:
4693 return "DW_AT_GNU_call_site_target_clobbered";
4694 case DW_AT_GNU_tail_call:
4695 return "DW_AT_GNU_tail_call";
4696 case DW_AT_GNU_all_tail_call_sites:
4697 return "DW_AT_GNU_all_tail_call_sites";
4698 case DW_AT_GNU_all_call_sites:
4699 return "DW_AT_GNU_all_call_sites";
4700 case DW_AT_GNU_all_source_call_sites:
4701 return "DW_AT_GNU_all_source_call_sites";
4703 case DW_AT_GNAT_descriptive_type:
4704 return "DW_AT_GNAT_descriptive_type";
4706 case DW_AT_VMS_rtnbeg_pd_address:
4707 return "DW_AT_VMS_rtnbeg_pd_address";
4710 return "DW_AT_<unknown>";
4714 /* Convert a DWARF value form code into its string name. */
4717 dwarf_form_name (unsigned int form)
4722 return "DW_FORM_addr";
4723 case DW_FORM_block2:
4724 return "DW_FORM_block2";
4725 case DW_FORM_block4:
4726 return "DW_FORM_block4";
4728 return "DW_FORM_data2";
4730 return "DW_FORM_data4";
4732 return "DW_FORM_data8";
4733 case DW_FORM_string:
4734 return "DW_FORM_string";
4736 return "DW_FORM_block";
4737 case DW_FORM_block1:
4738 return "DW_FORM_block1";
4740 return "DW_FORM_data1";
4742 return "DW_FORM_flag";
4744 return "DW_FORM_sdata";
4746 return "DW_FORM_strp";
4748 return "DW_FORM_udata";
4749 case DW_FORM_ref_addr:
4750 return "DW_FORM_ref_addr";
4752 return "DW_FORM_ref1";
4754 return "DW_FORM_ref2";
4756 return "DW_FORM_ref4";
4758 return "DW_FORM_ref8";
4759 case DW_FORM_ref_udata:
4760 return "DW_FORM_ref_udata";
4761 case DW_FORM_indirect:
4762 return "DW_FORM_indirect";
4763 case DW_FORM_sec_offset:
4764 return "DW_FORM_sec_offset";
4765 case DW_FORM_exprloc:
4766 return "DW_FORM_exprloc";
4767 case DW_FORM_flag_present:
4768 return "DW_FORM_flag_present";
4769 case DW_FORM_ref_sig8:
4770 return "DW_FORM_ref_sig8";
4772 return "DW_FORM_<unknown>";
4776 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4777 instance of an inlined instance of a decl which is local to an inline
4778 function, so we have to trace all of the way back through the origin chain
4779 to find out what sort of node actually served as the original seed for the
4783 decl_ultimate_origin (const_tree decl)
4785 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4788 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4789 nodes in the function to point to themselves; ignore that if
4790 we're trying to output the abstract instance of this function. */
4791 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4794 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4795 most distant ancestor, this should never happen. */
4796 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4798 return DECL_ABSTRACT_ORIGIN (decl);
4801 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4802 of a virtual function may refer to a base class, so we check the 'this'
4806 decl_class_context (tree decl)
4808 tree context = NULL_TREE;
4810 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4811 context = DECL_CONTEXT (decl);
4813 context = TYPE_MAIN_VARIANT
4814 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4816 if (context && !TYPE_P (context))
4817 context = NULL_TREE;
4822 /* Add an attribute/value pair to a DIE. */
4825 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4827 /* Maybe this should be an assert? */
4831 if (die->die_attr == NULL)
4832 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
4833 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
4836 static inline enum dw_val_class
4837 AT_class (dw_attr_ref a)
4839 return a->dw_attr_val.val_class;
4842 /* Add a flag value attribute to a DIE. */
4845 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4849 attr.dw_attr = attr_kind;
4850 attr.dw_attr_val.val_class = dw_val_class_flag;
4851 attr.dw_attr_val.v.val_flag = flag;
4852 add_dwarf_attr (die, &attr);
4855 static inline unsigned
4856 AT_flag (dw_attr_ref a)
4858 gcc_assert (a && AT_class (a) == dw_val_class_flag);
4859 return a->dw_attr_val.v.val_flag;
4862 /* Add a signed integer attribute value to a DIE. */
4865 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4869 attr.dw_attr = attr_kind;
4870 attr.dw_attr_val.val_class = dw_val_class_const;
4871 attr.dw_attr_val.v.val_int = int_val;
4872 add_dwarf_attr (die, &attr);
4875 static inline HOST_WIDE_INT
4876 AT_int (dw_attr_ref a)
4878 gcc_assert (a && AT_class (a) == dw_val_class_const);
4879 return a->dw_attr_val.v.val_int;
4882 /* Add an unsigned integer attribute value to a DIE. */
4885 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4886 unsigned HOST_WIDE_INT unsigned_val)
4890 attr.dw_attr = attr_kind;
4891 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
4892 attr.dw_attr_val.v.val_unsigned = unsigned_val;
4893 add_dwarf_attr (die, &attr);
4896 static inline unsigned HOST_WIDE_INT
4897 AT_unsigned (dw_attr_ref a)
4899 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
4900 return a->dw_attr_val.v.val_unsigned;
4903 /* Add an unsigned double integer attribute value to a DIE. */
4906 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
4907 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
4911 attr.dw_attr = attr_kind;
4912 attr.dw_attr_val.val_class = dw_val_class_const_double;
4913 attr.dw_attr_val.v.val_double.high = high;
4914 attr.dw_attr_val.v.val_double.low = low;
4915 add_dwarf_attr (die, &attr);
4918 /* Add a floating point attribute value to a DIE and return it. */
4921 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
4922 unsigned int length, unsigned int elt_size, unsigned char *array)
4926 attr.dw_attr = attr_kind;
4927 attr.dw_attr_val.val_class = dw_val_class_vec;
4928 attr.dw_attr_val.v.val_vec.length = length;
4929 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
4930 attr.dw_attr_val.v.val_vec.array = array;
4931 add_dwarf_attr (die, &attr);
4934 /* Add an 8-byte data attribute value to a DIE. */
4937 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
4938 unsigned char data8[8])
4942 attr.dw_attr = attr_kind;
4943 attr.dw_attr_val.val_class = dw_val_class_data8;
4944 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
4945 add_dwarf_attr (die, &attr);
4948 /* Hash and equality functions for debug_str_hash. */
4951 debug_str_do_hash (const void *x)
4953 return htab_hash_string (((const struct indirect_string_node *)x)->str);
4957 debug_str_eq (const void *x1, const void *x2)
4959 return strcmp ((((const struct indirect_string_node *)x1)->str),
4960 (const char *)x2) == 0;
4963 /* Add STR to the indirect string hash table. */
4965 static struct indirect_string_node *
4966 find_AT_string (const char *str)
4968 struct indirect_string_node *node;
4971 if (! debug_str_hash)
4972 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
4973 debug_str_eq, NULL);
4975 slot = htab_find_slot_with_hash (debug_str_hash, str,
4976 htab_hash_string (str), INSERT);
4979 node = ggc_alloc_cleared_indirect_string_node ();
4980 node->str = ggc_strdup (str);
4984 node = (struct indirect_string_node *) *slot;
4990 /* Add a string attribute value to a DIE. */
4993 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4996 struct indirect_string_node *node;
4998 node = find_AT_string (str);
5000 attr.dw_attr = attr_kind;
5001 attr.dw_attr_val.val_class = dw_val_class_str;
5002 attr.dw_attr_val.v.val_str = node;
5003 add_dwarf_attr (die, &attr);
5006 static inline const char *
5007 AT_string (dw_attr_ref a)
5009 gcc_assert (a && AT_class (a) == dw_val_class_str);
5010 return a->dw_attr_val.v.val_str->str;
5013 /* Find out whether a string should be output inline in DIE
5014 or out-of-line in .debug_str section. */
5016 static enum dwarf_form
5017 AT_string_form (dw_attr_ref a)
5019 struct indirect_string_node *node;
5023 gcc_assert (a && AT_class (a) == dw_val_class_str);
5025 node = a->dw_attr_val.v.val_str;
5029 len = strlen (node->str) + 1;
5031 /* If the string is shorter or equal to the size of the reference, it is
5032 always better to put it inline. */
5033 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
5034 return node->form = DW_FORM_string;
5036 /* If we cannot expect the linker to merge strings in .debug_str
5037 section, only put it into .debug_str if it is worth even in this
5039 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
5040 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
5041 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
5042 return node->form = DW_FORM_string;
5044 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
5045 ++dw2_string_counter;
5046 node->label = xstrdup (label);
5048 return node->form = DW_FORM_strp;
5051 /* Add a DIE reference attribute value to a DIE. */
5054 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
5058 #ifdef ENABLE_CHECKING
5059 gcc_assert (targ_die != NULL);
5061 /* With LTO we can end up trying to reference something we didn't create
5062 a DIE for. Avoid crashing later on a NULL referenced DIE. */
5063 if (targ_die == NULL)
5067 attr.dw_attr = attr_kind;
5068 attr.dw_attr_val.val_class = dw_val_class_die_ref;
5069 attr.dw_attr_val.v.val_die_ref.die = targ_die;
5070 attr.dw_attr_val.v.val_die_ref.external = 0;
5071 add_dwarf_attr (die, &attr);
5074 /* Add an AT_specification attribute to a DIE, and also make the back
5075 pointer from the specification to the definition. */
5078 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
5080 add_AT_die_ref (die, DW_AT_specification, targ_die);
5081 gcc_assert (!targ_die->die_definition);
5082 targ_die->die_definition = die;
5085 static inline dw_die_ref
5086 AT_ref (dw_attr_ref a)
5088 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5089 return a->dw_attr_val.v.val_die_ref.die;
5093 AT_ref_external (dw_attr_ref a)
5095 if (a && AT_class (a) == dw_val_class_die_ref)
5096 return a->dw_attr_val.v.val_die_ref.external;
5102 set_AT_ref_external (dw_attr_ref a, int i)
5104 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5105 a->dw_attr_val.v.val_die_ref.external = i;
5108 /* Add an FDE reference attribute value to a DIE. */
5111 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
5115 attr.dw_attr = attr_kind;
5116 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
5117 attr.dw_attr_val.v.val_fde_index = targ_fde;
5118 add_dwarf_attr (die, &attr);
5121 /* Add a location description attribute value to a DIE. */
5124 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
5128 attr.dw_attr = attr_kind;
5129 attr.dw_attr_val.val_class = dw_val_class_loc;
5130 attr.dw_attr_val.v.val_loc = loc;
5131 add_dwarf_attr (die, &attr);
5134 static inline dw_loc_descr_ref
5135 AT_loc (dw_attr_ref a)
5137 gcc_assert (a && AT_class (a) == dw_val_class_loc);
5138 return a->dw_attr_val.v.val_loc;
5142 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
5146 attr.dw_attr = attr_kind;
5147 attr.dw_attr_val.val_class = dw_val_class_loc_list;
5148 attr.dw_attr_val.v.val_loc_list = loc_list;
5149 add_dwarf_attr (die, &attr);
5150 have_location_lists = true;
5153 static inline dw_loc_list_ref
5154 AT_loc_list (dw_attr_ref a)
5156 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5157 return a->dw_attr_val.v.val_loc_list;
5160 static inline dw_loc_list_ref *
5161 AT_loc_list_ptr (dw_attr_ref a)
5163 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5164 return &a->dw_attr_val.v.val_loc_list;
5167 /* Add an address constant attribute value to a DIE. */
5170 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
5174 attr.dw_attr = attr_kind;
5175 attr.dw_attr_val.val_class = dw_val_class_addr;
5176 attr.dw_attr_val.v.val_addr = addr;
5177 add_dwarf_attr (die, &attr);
5180 /* Get the RTX from to an address DIE attribute. */
5183 AT_addr (dw_attr_ref a)
5185 gcc_assert (a && AT_class (a) == dw_val_class_addr);
5186 return a->dw_attr_val.v.val_addr;
5189 /* Add a file attribute value to a DIE. */
5192 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
5193 struct dwarf_file_data *fd)
5197 attr.dw_attr = attr_kind;
5198 attr.dw_attr_val.val_class = dw_val_class_file;
5199 attr.dw_attr_val.v.val_file = fd;
5200 add_dwarf_attr (die, &attr);
5203 /* Get the dwarf_file_data from a file DIE attribute. */
5205 static inline struct dwarf_file_data *
5206 AT_file (dw_attr_ref a)
5208 gcc_assert (a && AT_class (a) == dw_val_class_file);
5209 return a->dw_attr_val.v.val_file;
5212 /* Add a vms delta attribute value to a DIE. */
5215 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
5216 const char *lbl1, const char *lbl2)
5220 attr.dw_attr = attr_kind;
5221 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
5222 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
5223 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
5224 add_dwarf_attr (die, &attr);
5227 /* Add a label identifier attribute value to a DIE. */
5230 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
5234 attr.dw_attr = attr_kind;
5235 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
5236 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
5237 add_dwarf_attr (die, &attr);
5240 /* Add a section offset attribute value to a DIE, an offset into the
5241 debug_line section. */
5244 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5249 attr.dw_attr = attr_kind;
5250 attr.dw_attr_val.val_class = dw_val_class_lineptr;
5251 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5252 add_dwarf_attr (die, &attr);
5255 /* Add a section offset attribute value to a DIE, an offset into the
5256 debug_macinfo section. */
5259 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5264 attr.dw_attr = attr_kind;
5265 attr.dw_attr_val.val_class = dw_val_class_macptr;
5266 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5267 add_dwarf_attr (die, &attr);
5270 /* Add an offset attribute value to a DIE. */
5273 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
5274 unsigned HOST_WIDE_INT offset)
5278 attr.dw_attr = attr_kind;
5279 attr.dw_attr_val.val_class = dw_val_class_offset;
5280 attr.dw_attr_val.v.val_offset = offset;
5281 add_dwarf_attr (die, &attr);
5284 /* Add an range_list attribute value to a DIE. */
5287 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5288 long unsigned int offset)
5292 attr.dw_attr = attr_kind;
5293 attr.dw_attr_val.val_class = dw_val_class_range_list;
5294 attr.dw_attr_val.v.val_offset = offset;
5295 add_dwarf_attr (die, &attr);
5298 /* Return the start label of a delta attribute. */
5300 static inline const char *
5301 AT_vms_delta1 (dw_attr_ref a)
5303 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
5304 return a->dw_attr_val.v.val_vms_delta.lbl1;
5307 /* Return the end label of a delta attribute. */
5309 static inline const char *
5310 AT_vms_delta2 (dw_attr_ref a)
5312 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
5313 return a->dw_attr_val.v.val_vms_delta.lbl2;
5316 static inline const char *
5317 AT_lbl (dw_attr_ref a)
5319 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5320 || AT_class (a) == dw_val_class_lineptr
5321 || AT_class (a) == dw_val_class_macptr));
5322 return a->dw_attr_val.v.val_lbl_id;
5325 /* Get the attribute of type attr_kind. */
5328 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5332 dw_die_ref spec = NULL;
5337 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
5338 if (a->dw_attr == attr_kind)
5340 else if (a->dw_attr == DW_AT_specification
5341 || a->dw_attr == DW_AT_abstract_origin)
5345 return get_AT (spec, attr_kind);
5350 /* Return the "low pc" attribute value, typically associated with a subprogram
5351 DIE. Return null if the "low pc" attribute is either not present, or if it
5352 cannot be represented as an assembler label identifier. */
5354 static inline const char *
5355 get_AT_low_pc (dw_die_ref die)
5357 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
5359 return a ? AT_lbl (a) : NULL;
5362 /* Return the "high pc" attribute value, typically associated with a subprogram
5363 DIE. Return null if the "high pc" attribute is either not present, or if it
5364 cannot be represented as an assembler label identifier. */
5366 static inline const char *
5367 get_AT_hi_pc (dw_die_ref die)
5369 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
5371 return a ? AT_lbl (a) : NULL;
5374 /* Return the value of the string attribute designated by ATTR_KIND, or
5375 NULL if it is not present. */
5377 static inline const char *
5378 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5380 dw_attr_ref a = get_AT (die, attr_kind);
5382 return a ? AT_string (a) : NULL;
5385 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5386 if it is not present. */
5389 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5391 dw_attr_ref a = get_AT (die, attr_kind);
5393 return a ? AT_flag (a) : 0;
5396 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5397 if it is not present. */
5399 static inline unsigned
5400 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5402 dw_attr_ref a = get_AT (die, attr_kind);
5404 return a ? AT_unsigned (a) : 0;
5407 static inline dw_die_ref
5408 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5410 dw_attr_ref a = get_AT (die, attr_kind);
5412 return a ? AT_ref (a) : NULL;
5415 static inline struct dwarf_file_data *
5416 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
5418 dw_attr_ref a = get_AT (die, attr_kind);
5420 return a ? AT_file (a) : NULL;
5423 /* Return TRUE if the language is C++. */
5428 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5430 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
5433 /* Return TRUE if the language is Fortran. */
5438 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5440 return (lang == DW_LANG_Fortran77
5441 || lang == DW_LANG_Fortran90
5442 || lang == DW_LANG_Fortran95);
5445 /* Return TRUE if the language is Ada. */
5450 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5452 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
5455 /* Remove the specified attribute if present. */
5458 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5466 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
5467 if (a->dw_attr == attr_kind)
5469 if (AT_class (a) == dw_val_class_str)
5470 if (a->dw_attr_val.v.val_str->refcount)
5471 a->dw_attr_val.v.val_str->refcount--;
5473 /* VEC_ordered_remove should help reduce the number of abbrevs
5475 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
5480 /* Remove CHILD from its parent. PREV must have the property that
5481 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5484 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
5486 gcc_assert (child->die_parent == prev->die_parent);
5487 gcc_assert (prev->die_sib == child);
5490 gcc_assert (child->die_parent->die_child == child);
5494 prev->die_sib = child->die_sib;
5495 if (child->die_parent->die_child == child)
5496 child->die_parent->die_child = prev;
5499 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
5500 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
5503 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
5505 dw_die_ref parent = old_child->die_parent;
5507 gcc_assert (parent == prev->die_parent);
5508 gcc_assert (prev->die_sib == old_child);
5510 new_child->die_parent = parent;
5511 if (prev == old_child)
5513 gcc_assert (parent->die_child == old_child);
5514 new_child->die_sib = new_child;
5518 prev->die_sib = new_child;
5519 new_child->die_sib = old_child->die_sib;
5521 if (old_child->die_parent->die_child == old_child)
5522 old_child->die_parent->die_child = new_child;
5525 /* Move all children from OLD_PARENT to NEW_PARENT. */
5528 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
5531 new_parent->die_child = old_parent->die_child;
5532 old_parent->die_child = NULL;
5533 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
5536 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5540 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5546 dw_die_ref prev = c;
5548 while (c->die_tag == tag)
5550 remove_child_with_prev (c, prev);
5551 /* Might have removed every child. */
5552 if (c == c->die_sib)
5556 } while (c != die->die_child);
5559 /* Add a CHILD_DIE as the last child of DIE. */
5562 add_child_die (dw_die_ref die, dw_die_ref child_die)
5564 /* FIXME this should probably be an assert. */
5565 if (! die || ! child_die)
5567 gcc_assert (die != child_die);
5569 child_die->die_parent = die;
5572 child_die->die_sib = die->die_child->die_sib;
5573 die->die_child->die_sib = child_die;
5576 child_die->die_sib = child_die;
5577 die->die_child = child_die;
5580 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5581 is the specification, to the end of PARENT's list of children.
5582 This is done by removing and re-adding it. */
5585 splice_child_die (dw_die_ref parent, dw_die_ref child)
5589 /* We want the declaration DIE from inside the class, not the
5590 specification DIE at toplevel. */
5591 if (child->die_parent != parent)
5593 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5599 gcc_assert (child->die_parent == parent
5600 || (child->die_parent
5601 == get_AT_ref (parent, DW_AT_specification)));
5603 for (p = child->die_parent->die_child; ; p = p->die_sib)
5604 if (p->die_sib == child)
5606 remove_child_with_prev (child, p);
5610 add_child_die (parent, child);
5613 /* Return a pointer to a newly created DIE node. */
5615 static inline dw_die_ref
5616 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5618 dw_die_ref die = ggc_alloc_cleared_die_node ();
5620 die->die_tag = tag_value;
5622 if (parent_die != NULL)
5623 add_child_die (parent_die, die);
5626 limbo_die_node *limbo_node;
5628 limbo_node = ggc_alloc_cleared_limbo_die_node ();
5629 limbo_node->die = die;
5630 limbo_node->created_for = t;
5631 limbo_node->next = limbo_die_list;
5632 limbo_die_list = limbo_node;
5638 /* Return the DIE associated with the given type specifier. */
5640 static inline dw_die_ref
5641 lookup_type_die (tree type)
5643 return TYPE_SYMTAB_DIE (type);
5646 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5647 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5648 anonymous type instead the one of the naming typedef. */
5650 static inline dw_die_ref
5651 strip_naming_typedef (tree type, dw_die_ref type_die)
5654 && TREE_CODE (type) == RECORD_TYPE
5656 && type_die->die_tag == DW_TAG_typedef
5657 && is_naming_typedef_decl (TYPE_NAME (type)))
5658 type_die = get_AT_ref (type_die, DW_AT_type);
5662 /* Like lookup_type_die, but if type is an anonymous type named by a
5663 typedef[1], return the DIE of the anonymous type instead the one of
5664 the naming typedef. This is because in gen_typedef_die, we did
5665 equate the anonymous struct named by the typedef with the DIE of
5666 the naming typedef. So by default, lookup_type_die on an anonymous
5667 struct yields the DIE of the naming typedef.
5669 [1]: Read the comment of is_naming_typedef_decl to learn about what
5670 a naming typedef is. */
5672 static inline dw_die_ref
5673 lookup_type_die_strip_naming_typedef (tree type)
5675 dw_die_ref die = lookup_type_die (type);
5676 return strip_naming_typedef (type, die);
5679 /* Equate a DIE to a given type specifier. */
5682 equate_type_number_to_die (tree type, dw_die_ref type_die)
5684 TYPE_SYMTAB_DIE (type) = type_die;
5687 /* Returns a hash value for X (which really is a die_struct). */
5690 decl_die_table_hash (const void *x)
5692 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
5695 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5698 decl_die_table_eq (const void *x, const void *y)
5700 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
5703 /* Return the DIE associated with a given declaration. */
5705 static inline dw_die_ref
5706 lookup_decl_die (tree decl)
5708 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5711 /* Returns a hash value for X (which really is a var_loc_list). */
5714 decl_loc_table_hash (const void *x)
5716 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5719 /* Return nonzero if decl_id of var_loc_list X is the same as
5723 decl_loc_table_eq (const void *x, const void *y)
5725 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
5728 /* Return the var_loc list associated with a given declaration. */
5730 static inline var_loc_list *
5731 lookup_decl_loc (const_tree decl)
5733 if (!decl_loc_table)
5735 return (var_loc_list *)
5736 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5739 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5742 cached_dw_loc_list_table_hash (const void *x)
5744 return (hashval_t) ((const cached_dw_loc_list *) x)->decl_id;
5747 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5751 cached_dw_loc_list_table_eq (const void *x, const void *y)
5753 return (((const cached_dw_loc_list *) x)->decl_id
5754 == DECL_UID ((const_tree) y));
5757 /* Equate a DIE to a particular declaration. */
5760 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5762 unsigned int decl_id = DECL_UID (decl);
5765 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5767 decl_die->decl_id = decl_id;
5770 /* Return how many bits covers PIECE EXPR_LIST. */
5773 decl_piece_bitsize (rtx piece)
5775 int ret = (int) GET_MODE (piece);
5778 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
5779 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
5780 return INTVAL (XEXP (XEXP (piece, 0), 0));
5783 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5786 decl_piece_varloc_ptr (rtx piece)
5788 if ((int) GET_MODE (piece))
5789 return &XEXP (piece, 0);
5791 return &XEXP (XEXP (piece, 0), 1);
5794 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5795 Next is the chain of following piece nodes. */
5798 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
5800 if (bitsize <= (int) MAX_MACHINE_MODE)
5801 return alloc_EXPR_LIST (bitsize, loc_note, next);
5803 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
5808 /* Return rtx that should be stored into loc field for
5809 LOC_NOTE and BITPOS/BITSIZE. */
5812 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
5813 HOST_WIDE_INT bitsize)
5817 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
5819 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
5824 /* This function either modifies location piece list *DEST in
5825 place (if SRC and INNER is NULL), or copies location piece list
5826 *SRC to *DEST while modifying it. Location BITPOS is modified
5827 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5828 not copied and if needed some padding around it is added.
5829 When modifying in place, DEST should point to EXPR_LIST where
5830 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5831 to the start of the whole list and INNER points to the EXPR_LIST
5832 where earlier pieces cover PIECE_BITPOS bits. */
5835 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
5836 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
5837 HOST_WIDE_INT bitsize, rtx loc_note)
5840 bool copy = inner != NULL;
5844 /* First copy all nodes preceeding the current bitpos. */
5845 while (src != inner)
5847 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5848 decl_piece_bitsize (*src), NULL_RTX);
5849 dest = &XEXP (*dest, 1);
5850 src = &XEXP (*src, 1);
5853 /* Add padding if needed. */
5854 if (bitpos != piece_bitpos)
5856 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
5857 copy ? NULL_RTX : *dest);
5858 dest = &XEXP (*dest, 1);
5860 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
5863 /* A piece with correct bitpos and bitsize already exist,
5864 just update the location for it and return. */
5865 *decl_piece_varloc_ptr (*dest) = loc_note;
5868 /* Add the piece that changed. */
5869 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
5870 dest = &XEXP (*dest, 1);
5871 /* Skip over pieces that overlap it. */
5872 diff = bitpos - piece_bitpos + bitsize;
5875 while (diff > 0 && *src)
5878 diff -= decl_piece_bitsize (piece);
5880 src = &XEXP (piece, 1);
5883 *src = XEXP (piece, 1);
5884 free_EXPR_LIST_node (piece);
5887 /* Add padding if needed. */
5888 if (diff < 0 && *src)
5892 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
5893 dest = &XEXP (*dest, 1);
5897 /* Finally copy all nodes following it. */
5900 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5901 decl_piece_bitsize (*src), NULL_RTX);
5902 dest = &XEXP (*dest, 1);
5903 src = &XEXP (*src, 1);
5907 /* Add a variable location node to the linked list for DECL. */
5909 static struct var_loc_node *
5910 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
5912 unsigned int decl_id;
5915 struct var_loc_node *loc = NULL;
5916 HOST_WIDE_INT bitsize = -1, bitpos = -1;
5918 if (DECL_DEBUG_EXPR_IS_FROM (decl))
5920 tree realdecl = DECL_DEBUG_EXPR (decl);
5921 if (realdecl && handled_component_p (realdecl))
5923 HOST_WIDE_INT maxsize;
5926 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
5927 if (!DECL_P (innerdecl)
5928 || DECL_IGNORED_P (innerdecl)
5929 || TREE_STATIC (innerdecl)
5931 || bitpos + bitsize > 256
5932 || bitsize != maxsize)
5938 decl_id = DECL_UID (decl);
5939 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5942 temp = ggc_alloc_cleared_var_loc_list ();
5943 temp->decl_id = decl_id;
5947 temp = (var_loc_list *) *slot;
5949 /* For PARM_DECLs try to keep around the original incoming value,
5950 even if that means we'll emit a zero-range .debug_loc entry. */
5952 && temp->first == temp->last
5953 && TREE_CODE (decl) == PARM_DECL
5954 && GET_CODE (temp->first->loc) == NOTE
5955 && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
5956 && DECL_INCOMING_RTL (decl)
5957 && NOTE_VAR_LOCATION_LOC (temp->first->loc)
5958 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
5959 == GET_CODE (DECL_INCOMING_RTL (decl))
5960 && prev_real_insn (temp->first->loc) == NULL_RTX
5962 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
5963 NOTE_VAR_LOCATION_LOC (loc_note))
5964 || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
5965 != NOTE_VAR_LOCATION_STATUS (loc_note))))
5967 loc = ggc_alloc_cleared_var_loc_node ();
5968 temp->first->next = loc;
5970 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5972 else if (temp->last)
5974 struct var_loc_node *last = temp->last, *unused = NULL;
5975 rtx *piece_loc = NULL, last_loc_note;
5976 int piece_bitpos = 0;
5980 gcc_assert (last->next == NULL);
5982 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
5984 piece_loc = &last->loc;
5987 int cur_bitsize = decl_piece_bitsize (*piece_loc);
5988 if (piece_bitpos + cur_bitsize > bitpos)
5990 piece_bitpos += cur_bitsize;
5991 piece_loc = &XEXP (*piece_loc, 1);
5995 /* TEMP->LAST here is either pointer to the last but one or
5996 last element in the chained list, LAST is pointer to the
5998 if (label && strcmp (last->label, label) == 0)
6000 /* For SRA optimized variables if there weren't any real
6001 insns since last note, just modify the last node. */
6002 if (piece_loc != NULL)
6004 adjust_piece_list (piece_loc, NULL, NULL,
6005 bitpos, piece_bitpos, bitsize, loc_note);
6008 /* If the last note doesn't cover any instructions, remove it. */
6009 if (temp->last != last)
6011 temp->last->next = NULL;
6014 gcc_assert (strcmp (last->label, label) != 0);
6018 gcc_assert (temp->first == temp->last
6019 || (temp->first->next == temp->last
6020 && TREE_CODE (decl) == PARM_DECL));
6021 memset (temp->last, '\0', sizeof (*temp->last));
6022 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
6026 if (bitsize == -1 && NOTE_P (last->loc))
6027 last_loc_note = last->loc;
6028 else if (piece_loc != NULL
6029 && *piece_loc != NULL_RTX
6030 && piece_bitpos == bitpos
6031 && decl_piece_bitsize (*piece_loc) == bitsize)
6032 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
6034 last_loc_note = NULL_RTX;
6035 /* If the current location is the same as the end of the list,
6036 and either both or neither of the locations is uninitialized,
6037 we have nothing to do. */
6038 if (last_loc_note == NULL_RTX
6039 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
6040 NOTE_VAR_LOCATION_LOC (loc_note)))
6041 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
6042 != NOTE_VAR_LOCATION_STATUS (loc_note))
6043 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
6044 == VAR_INIT_STATUS_UNINITIALIZED)
6045 || (NOTE_VAR_LOCATION_STATUS (loc_note)
6046 == VAR_INIT_STATUS_UNINITIALIZED))))
6048 /* Add LOC to the end of list and update LAST. If the last
6049 element of the list has been removed above, reuse its
6050 memory for the new node, otherwise allocate a new one. */
6054 memset (loc, '\0', sizeof (*loc));
6057 loc = ggc_alloc_cleared_var_loc_node ();
6058 if (bitsize == -1 || piece_loc == NULL)
6059 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
6061 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
6062 bitpos, piece_bitpos, bitsize, loc_note);
6064 /* Ensure TEMP->LAST will point either to the new last but one
6065 element of the chain, or to the last element in it. */
6066 if (last != temp->last)
6074 loc = ggc_alloc_cleared_var_loc_node ();
6077 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
6082 /* Keep track of the number of spaces used to indent the
6083 output of the debugging routines that print the structure of
6084 the DIE internal representation. */
6085 static int print_indent;
6087 /* Indent the line the number of spaces given by print_indent. */
6090 print_spaces (FILE *outfile)
6092 fprintf (outfile, "%*s", print_indent, "");
6095 /* Print a type signature in hex. */
6098 print_signature (FILE *outfile, char *sig)
6102 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
6103 fprintf (outfile, "%02x", sig[i] & 0xff);
6106 /* Print the information associated with a given DIE, and its children.
6107 This routine is a debugging aid only. */
6110 print_die (dw_die_ref die, FILE *outfile)
6116 print_spaces (outfile);
6117 fprintf (outfile, "DIE %4ld: %s (%p)\n",
6118 die->die_offset, dwarf_tag_name (die->die_tag),
6120 print_spaces (outfile);
6121 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
6122 fprintf (outfile, " offset: %ld", die->die_offset);
6123 fprintf (outfile, " mark: %d\n", die->die_mark);
6125 if (use_debug_types && die->die_id.die_type_node)
6127 print_spaces (outfile);
6128 fprintf (outfile, " signature: ");
6129 print_signature (outfile, die->die_id.die_type_node->signature);
6130 fprintf (outfile, "\n");
6133 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6135 print_spaces (outfile);
6136 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
6138 switch (AT_class (a))
6140 case dw_val_class_addr:
6141 fprintf (outfile, "address");
6143 case dw_val_class_offset:
6144 fprintf (outfile, "offset");
6146 case dw_val_class_loc:
6147 fprintf (outfile, "location descriptor");
6149 case dw_val_class_loc_list:
6150 fprintf (outfile, "location list -> label:%s",
6151 AT_loc_list (a)->ll_symbol);
6153 case dw_val_class_range_list:
6154 fprintf (outfile, "range list");
6156 case dw_val_class_const:
6157 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
6159 case dw_val_class_unsigned_const:
6160 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
6162 case dw_val_class_const_double:
6163 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
6164 HOST_WIDE_INT_PRINT_UNSIGNED")",
6165 a->dw_attr_val.v.val_double.high,
6166 a->dw_attr_val.v.val_double.low);
6168 case dw_val_class_vec:
6169 fprintf (outfile, "floating-point or vector constant");
6171 case dw_val_class_flag:
6172 fprintf (outfile, "%u", AT_flag (a));
6174 case dw_val_class_die_ref:
6175 if (AT_ref (a) != NULL)
6177 if (use_debug_types && AT_ref (a)->die_id.die_type_node)
6179 fprintf (outfile, "die -> signature: ");
6180 print_signature (outfile,
6181 AT_ref (a)->die_id.die_type_node->signature);
6183 else if (! use_debug_types && AT_ref (a)->die_id.die_symbol)
6184 fprintf (outfile, "die -> label: %s",
6185 AT_ref (a)->die_id.die_symbol);
6187 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
6188 fprintf (outfile, " (%p)", (void *) AT_ref (a));
6191 fprintf (outfile, "die -> <null>");
6193 case dw_val_class_vms_delta:
6194 fprintf (outfile, "delta: @slotcount(%s-%s)",
6195 AT_vms_delta2 (a), AT_vms_delta1 (a));
6197 case dw_val_class_lbl_id:
6198 case dw_val_class_lineptr:
6199 case dw_val_class_macptr:
6200 fprintf (outfile, "label: %s", AT_lbl (a));
6202 case dw_val_class_str:
6203 if (AT_string (a) != NULL)
6204 fprintf (outfile, "\"%s\"", AT_string (a));
6206 fprintf (outfile, "<null>");
6208 case dw_val_class_file:
6209 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
6210 AT_file (a)->emitted_number);
6212 case dw_val_class_data8:
6216 for (i = 0; i < 8; i++)
6217 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
6224 fprintf (outfile, "\n");
6227 if (die->die_child != NULL)
6230 FOR_EACH_CHILD (die, c, print_die (c, outfile));
6233 if (print_indent == 0)
6234 fprintf (outfile, "\n");
6237 /* Print the information collected for a given DIE. */
6240 debug_dwarf_die (dw_die_ref die)
6242 print_die (die, stderr);
6245 /* Print all DWARF information collected for the compilation unit.
6246 This routine is a debugging aid only. */
6252 print_die (comp_unit_die (), stderr);
6255 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6256 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6257 DIE that marks the start of the DIEs for this include file. */
6260 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
6262 const char *filename = get_AT_string (bincl_die, DW_AT_name);
6263 dw_die_ref new_unit = gen_compile_unit_die (filename);
6265 new_unit->die_sib = old_unit;
6269 /* Close an include-file CU and reopen the enclosing one. */
6272 pop_compile_unit (dw_die_ref old_unit)
6274 dw_die_ref new_unit = old_unit->die_sib;
6276 old_unit->die_sib = NULL;
6280 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6281 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6283 /* Calculate the checksum of a location expression. */
6286 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
6290 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
6292 CHECKSUM (loc->dw_loc_oprnd1);
6293 CHECKSUM (loc->dw_loc_oprnd2);
6296 /* Calculate the checksum of an attribute. */
6299 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
6301 dw_loc_descr_ref loc;
6304 CHECKSUM (at->dw_attr);
6306 /* We don't care that this was compiled with a different compiler
6307 snapshot; if the output is the same, that's what matters. */
6308 if (at->dw_attr == DW_AT_producer)
6311 switch (AT_class (at))
6313 case dw_val_class_const:
6314 CHECKSUM (at->dw_attr_val.v.val_int);
6316 case dw_val_class_unsigned_const:
6317 CHECKSUM (at->dw_attr_val.v.val_unsigned);
6319 case dw_val_class_const_double:
6320 CHECKSUM (at->dw_attr_val.v.val_double);
6322 case dw_val_class_vec:
6323 CHECKSUM (at->dw_attr_val.v.val_vec);
6325 case dw_val_class_flag:
6326 CHECKSUM (at->dw_attr_val.v.val_flag);
6328 case dw_val_class_str:
6329 CHECKSUM_STRING (AT_string (at));
6332 case dw_val_class_addr:
6334 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6335 CHECKSUM_STRING (XSTR (r, 0));
6338 case dw_val_class_offset:
6339 CHECKSUM (at->dw_attr_val.v.val_offset);
6342 case dw_val_class_loc:
6343 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6344 loc_checksum (loc, ctx);
6347 case dw_val_class_die_ref:
6348 die_checksum (AT_ref (at), ctx, mark);
6351 case dw_val_class_fde_ref:
6352 case dw_val_class_vms_delta:
6353 case dw_val_class_lbl_id:
6354 case dw_val_class_lineptr:
6355 case dw_val_class_macptr:
6358 case dw_val_class_file:
6359 CHECKSUM_STRING (AT_file (at)->filename);
6362 case dw_val_class_data8:
6363 CHECKSUM (at->dw_attr_val.v.val_data8);
6371 /* Calculate the checksum of a DIE. */
6374 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6380 /* To avoid infinite recursion. */
6383 CHECKSUM (die->die_mark);
6386 die->die_mark = ++(*mark);
6388 CHECKSUM (die->die_tag);
6390 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6391 attr_checksum (a, ctx, mark);
6393 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
6397 #undef CHECKSUM_STRING
6399 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
6400 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6401 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
6402 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
6403 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
6404 #define CHECKSUM_ATTR(FOO) \
6405 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
6407 /* Calculate the checksum of a number in signed LEB128 format. */
6410 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
6417 byte = (value & 0x7f);
6419 more = !((value == 0 && (byte & 0x40) == 0)
6420 || (value == -1 && (byte & 0x40) != 0));
6429 /* Calculate the checksum of a number in unsigned LEB128 format. */
6432 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
6436 unsigned char byte = (value & 0x7f);
6439 /* More bytes to follow. */
6447 /* Checksum the context of the DIE. This adds the names of any
6448 surrounding namespaces or structures to the checksum. */
6451 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
6455 int tag = die->die_tag;
6457 if (tag != DW_TAG_namespace
6458 && tag != DW_TAG_structure_type
6459 && tag != DW_TAG_class_type)
6462 name = get_AT_string (die, DW_AT_name);
6464 spec = get_AT_ref (die, DW_AT_specification);
6468 if (die->die_parent != NULL)
6469 checksum_die_context (die->die_parent, ctx);
6471 CHECKSUM_ULEB128 ('C');
6472 CHECKSUM_ULEB128 (tag);
6474 CHECKSUM_STRING (name);
6477 /* Calculate the checksum of a location expression. */
6480 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
6482 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6483 were emitted as a DW_FORM_sdata instead of a location expression. */
6484 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
6486 CHECKSUM_ULEB128 (DW_FORM_sdata);
6487 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
6491 /* Otherwise, just checksum the raw location expression. */
6494 CHECKSUM_ULEB128 (loc->dw_loc_opc);
6495 CHECKSUM (loc->dw_loc_oprnd1);
6496 CHECKSUM (loc->dw_loc_oprnd2);
6497 loc = loc->dw_loc_next;
6501 /* Calculate the checksum of an attribute. */
6504 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
6505 struct md5_ctx *ctx, int *mark)
6507 dw_loc_descr_ref loc;
6510 if (AT_class (at) == dw_val_class_die_ref)
6512 dw_die_ref target_die = AT_ref (at);
6514 /* For pointer and reference types, we checksum only the (qualified)
6515 name of the target type (if there is a name). For friend entries,
6516 we checksum only the (qualified) name of the target type or function.
6517 This allows the checksum to remain the same whether the target type
6518 is complete or not. */
6519 if ((at->dw_attr == DW_AT_type
6520 && (tag == DW_TAG_pointer_type
6521 || tag == DW_TAG_reference_type
6522 || tag == DW_TAG_rvalue_reference_type
6523 || tag == DW_TAG_ptr_to_member_type))
6524 || (at->dw_attr == DW_AT_friend
6525 && tag == DW_TAG_friend))
6527 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
6529 if (name_attr != NULL)
6531 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
6535 CHECKSUM_ULEB128 ('N');
6536 CHECKSUM_ULEB128 (at->dw_attr);
6537 if (decl->die_parent != NULL)
6538 checksum_die_context (decl->die_parent, ctx);
6539 CHECKSUM_ULEB128 ('E');
6540 CHECKSUM_STRING (AT_string (name_attr));
6545 /* For all other references to another DIE, we check to see if the
6546 target DIE has already been visited. If it has, we emit a
6547 backward reference; if not, we descend recursively. */
6548 if (target_die->die_mark > 0)
6550 CHECKSUM_ULEB128 ('R');
6551 CHECKSUM_ULEB128 (at->dw_attr);
6552 CHECKSUM_ULEB128 (target_die->die_mark);
6556 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
6560 target_die->die_mark = ++(*mark);
6561 CHECKSUM_ULEB128 ('T');
6562 CHECKSUM_ULEB128 (at->dw_attr);
6563 if (decl->die_parent != NULL)
6564 checksum_die_context (decl->die_parent, ctx);
6565 die_checksum_ordered (target_die, ctx, mark);
6570 CHECKSUM_ULEB128 ('A');
6571 CHECKSUM_ULEB128 (at->dw_attr);
6573 switch (AT_class (at))
6575 case dw_val_class_const:
6576 CHECKSUM_ULEB128 (DW_FORM_sdata);
6577 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
6580 case dw_val_class_unsigned_const:
6581 CHECKSUM_ULEB128 (DW_FORM_sdata);
6582 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
6585 case dw_val_class_const_double:
6586 CHECKSUM_ULEB128 (DW_FORM_block);
6587 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
6588 CHECKSUM (at->dw_attr_val.v.val_double);
6591 case dw_val_class_vec:
6592 CHECKSUM_ULEB128 (DW_FORM_block);
6593 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
6594 CHECKSUM (at->dw_attr_val.v.val_vec);
6597 case dw_val_class_flag:
6598 CHECKSUM_ULEB128 (DW_FORM_flag);
6599 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
6602 case dw_val_class_str:
6603 CHECKSUM_ULEB128 (DW_FORM_string);
6604 CHECKSUM_STRING (AT_string (at));
6607 case dw_val_class_addr:
6609 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6610 CHECKSUM_ULEB128 (DW_FORM_string);
6611 CHECKSUM_STRING (XSTR (r, 0));
6614 case dw_val_class_offset:
6615 CHECKSUM_ULEB128 (DW_FORM_sdata);
6616 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
6619 case dw_val_class_loc:
6620 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6621 loc_checksum_ordered (loc, ctx);
6624 case dw_val_class_fde_ref:
6625 case dw_val_class_lbl_id:
6626 case dw_val_class_lineptr:
6627 case dw_val_class_macptr:
6630 case dw_val_class_file:
6631 CHECKSUM_ULEB128 (DW_FORM_string);
6632 CHECKSUM_STRING (AT_file (at)->filename);
6635 case dw_val_class_data8:
6636 CHECKSUM (at->dw_attr_val.v.val_data8);
6644 struct checksum_attributes
6646 dw_attr_ref at_name;
6647 dw_attr_ref at_type;
6648 dw_attr_ref at_friend;
6649 dw_attr_ref at_accessibility;
6650 dw_attr_ref at_address_class;
6651 dw_attr_ref at_allocated;
6652 dw_attr_ref at_artificial;
6653 dw_attr_ref at_associated;
6654 dw_attr_ref at_binary_scale;
6655 dw_attr_ref at_bit_offset;
6656 dw_attr_ref at_bit_size;
6657 dw_attr_ref at_bit_stride;
6658 dw_attr_ref at_byte_size;
6659 dw_attr_ref at_byte_stride;
6660 dw_attr_ref at_const_value;
6661 dw_attr_ref at_containing_type;
6662 dw_attr_ref at_count;
6663 dw_attr_ref at_data_location;
6664 dw_attr_ref at_data_member_location;
6665 dw_attr_ref at_decimal_scale;
6666 dw_attr_ref at_decimal_sign;
6667 dw_attr_ref at_default_value;
6668 dw_attr_ref at_digit_count;
6669 dw_attr_ref at_discr;
6670 dw_attr_ref at_discr_list;
6671 dw_attr_ref at_discr_value;
6672 dw_attr_ref at_encoding;
6673 dw_attr_ref at_endianity;
6674 dw_attr_ref at_explicit;
6675 dw_attr_ref at_is_optional;
6676 dw_attr_ref at_location;
6677 dw_attr_ref at_lower_bound;
6678 dw_attr_ref at_mutable;
6679 dw_attr_ref at_ordering;
6680 dw_attr_ref at_picture_string;
6681 dw_attr_ref at_prototyped;
6682 dw_attr_ref at_small;
6683 dw_attr_ref at_segment;
6684 dw_attr_ref at_string_length;
6685 dw_attr_ref at_threads_scaled;
6686 dw_attr_ref at_upper_bound;
6687 dw_attr_ref at_use_location;
6688 dw_attr_ref at_use_UTF8;
6689 dw_attr_ref at_variable_parameter;
6690 dw_attr_ref at_virtuality;
6691 dw_attr_ref at_visibility;
6692 dw_attr_ref at_vtable_elem_location;
6695 /* Collect the attributes that we will want to use for the checksum. */
6698 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
6703 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6714 attrs->at_friend = a;
6716 case DW_AT_accessibility:
6717 attrs->at_accessibility = a;
6719 case DW_AT_address_class:
6720 attrs->at_address_class = a;
6722 case DW_AT_allocated:
6723 attrs->at_allocated = a;
6725 case DW_AT_artificial:
6726 attrs->at_artificial = a;
6728 case DW_AT_associated:
6729 attrs->at_associated = a;
6731 case DW_AT_binary_scale:
6732 attrs->at_binary_scale = a;
6734 case DW_AT_bit_offset:
6735 attrs->at_bit_offset = a;
6737 case DW_AT_bit_size:
6738 attrs->at_bit_size = a;
6740 case DW_AT_bit_stride:
6741 attrs->at_bit_stride = a;
6743 case DW_AT_byte_size:
6744 attrs->at_byte_size = a;
6746 case DW_AT_byte_stride:
6747 attrs->at_byte_stride = a;
6749 case DW_AT_const_value:
6750 attrs->at_const_value = a;
6752 case DW_AT_containing_type:
6753 attrs->at_containing_type = a;
6756 attrs->at_count = a;
6758 case DW_AT_data_location:
6759 attrs->at_data_location = a;
6761 case DW_AT_data_member_location:
6762 attrs->at_data_member_location = a;
6764 case DW_AT_decimal_scale:
6765 attrs->at_decimal_scale = a;
6767 case DW_AT_decimal_sign:
6768 attrs->at_decimal_sign = a;
6770 case DW_AT_default_value:
6771 attrs->at_default_value = a;
6773 case DW_AT_digit_count:
6774 attrs->at_digit_count = a;
6777 attrs->at_discr = a;
6779 case DW_AT_discr_list:
6780 attrs->at_discr_list = a;
6782 case DW_AT_discr_value:
6783 attrs->at_discr_value = a;
6785 case DW_AT_encoding:
6786 attrs->at_encoding = a;
6788 case DW_AT_endianity:
6789 attrs->at_endianity = a;
6791 case DW_AT_explicit:
6792 attrs->at_explicit = a;
6794 case DW_AT_is_optional:
6795 attrs->at_is_optional = a;
6797 case DW_AT_location:
6798 attrs->at_location = a;
6800 case DW_AT_lower_bound:
6801 attrs->at_lower_bound = a;
6804 attrs->at_mutable = a;
6806 case DW_AT_ordering:
6807 attrs->at_ordering = a;
6809 case DW_AT_picture_string:
6810 attrs->at_picture_string = a;
6812 case DW_AT_prototyped:
6813 attrs->at_prototyped = a;
6816 attrs->at_small = a;
6819 attrs->at_segment = a;
6821 case DW_AT_string_length:
6822 attrs->at_string_length = a;
6824 case DW_AT_threads_scaled:
6825 attrs->at_threads_scaled = a;
6827 case DW_AT_upper_bound:
6828 attrs->at_upper_bound = a;
6830 case DW_AT_use_location:
6831 attrs->at_use_location = a;
6833 case DW_AT_use_UTF8:
6834 attrs->at_use_UTF8 = a;
6836 case DW_AT_variable_parameter:
6837 attrs->at_variable_parameter = a;
6839 case DW_AT_virtuality:
6840 attrs->at_virtuality = a;
6842 case DW_AT_visibility:
6843 attrs->at_visibility = a;
6845 case DW_AT_vtable_elem_location:
6846 attrs->at_vtable_elem_location = a;
6854 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6857 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6861 struct checksum_attributes attrs;
6863 CHECKSUM_ULEB128 ('D');
6864 CHECKSUM_ULEB128 (die->die_tag);
6866 memset (&attrs, 0, sizeof (attrs));
6868 decl = get_AT_ref (die, DW_AT_specification);
6870 collect_checksum_attributes (&attrs, decl);
6871 collect_checksum_attributes (&attrs, die);
6873 CHECKSUM_ATTR (attrs.at_name);
6874 CHECKSUM_ATTR (attrs.at_accessibility);
6875 CHECKSUM_ATTR (attrs.at_address_class);
6876 CHECKSUM_ATTR (attrs.at_allocated);
6877 CHECKSUM_ATTR (attrs.at_artificial);
6878 CHECKSUM_ATTR (attrs.at_associated);
6879 CHECKSUM_ATTR (attrs.at_binary_scale);
6880 CHECKSUM_ATTR (attrs.at_bit_offset);
6881 CHECKSUM_ATTR (attrs.at_bit_size);
6882 CHECKSUM_ATTR (attrs.at_bit_stride);
6883 CHECKSUM_ATTR (attrs.at_byte_size);
6884 CHECKSUM_ATTR (attrs.at_byte_stride);
6885 CHECKSUM_ATTR (attrs.at_const_value);
6886 CHECKSUM_ATTR (attrs.at_containing_type);
6887 CHECKSUM_ATTR (attrs.at_count);
6888 CHECKSUM_ATTR (attrs.at_data_location);
6889 CHECKSUM_ATTR (attrs.at_data_member_location);
6890 CHECKSUM_ATTR (attrs.at_decimal_scale);
6891 CHECKSUM_ATTR (attrs.at_decimal_sign);
6892 CHECKSUM_ATTR (attrs.at_default_value);
6893 CHECKSUM_ATTR (attrs.at_digit_count);
6894 CHECKSUM_ATTR (attrs.at_discr);
6895 CHECKSUM_ATTR (attrs.at_discr_list);
6896 CHECKSUM_ATTR (attrs.at_discr_value);
6897 CHECKSUM_ATTR (attrs.at_encoding);
6898 CHECKSUM_ATTR (attrs.at_endianity);
6899 CHECKSUM_ATTR (attrs.at_explicit);
6900 CHECKSUM_ATTR (attrs.at_is_optional);
6901 CHECKSUM_ATTR (attrs.at_location);
6902 CHECKSUM_ATTR (attrs.at_lower_bound);
6903 CHECKSUM_ATTR (attrs.at_mutable);
6904 CHECKSUM_ATTR (attrs.at_ordering);
6905 CHECKSUM_ATTR (attrs.at_picture_string);
6906 CHECKSUM_ATTR (attrs.at_prototyped);
6907 CHECKSUM_ATTR (attrs.at_small);
6908 CHECKSUM_ATTR (attrs.at_segment);
6909 CHECKSUM_ATTR (attrs.at_string_length);
6910 CHECKSUM_ATTR (attrs.at_threads_scaled);
6911 CHECKSUM_ATTR (attrs.at_upper_bound);
6912 CHECKSUM_ATTR (attrs.at_use_location);
6913 CHECKSUM_ATTR (attrs.at_use_UTF8);
6914 CHECKSUM_ATTR (attrs.at_variable_parameter);
6915 CHECKSUM_ATTR (attrs.at_virtuality);
6916 CHECKSUM_ATTR (attrs.at_visibility);
6917 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
6918 CHECKSUM_ATTR (attrs.at_type);
6919 CHECKSUM_ATTR (attrs.at_friend);
6921 /* Checksum the child DIEs, except for nested types and member functions. */
6924 dw_attr_ref name_attr;
6927 name_attr = get_AT (c, DW_AT_name);
6928 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
6929 && name_attr != NULL)
6931 CHECKSUM_ULEB128 ('S');
6932 CHECKSUM_ULEB128 (c->die_tag);
6933 CHECKSUM_STRING (AT_string (name_attr));
6937 /* Mark this DIE so it gets processed when unmarking. */
6938 if (c->die_mark == 0)
6940 die_checksum_ordered (c, ctx, mark);
6942 } while (c != die->die_child);
6944 CHECKSUM_ULEB128 (0);
6948 #undef CHECKSUM_STRING
6949 #undef CHECKSUM_ATTR
6950 #undef CHECKSUM_LEB128
6951 #undef CHECKSUM_ULEB128
6953 /* Generate the type signature for DIE. This is computed by generating an
6954 MD5 checksum over the DIE's tag, its relevant attributes, and its
6955 children. Attributes that are references to other DIEs are processed
6956 by recursion, using the MARK field to prevent infinite recursion.
6957 If the DIE is nested inside a namespace or another type, we also
6958 need to include that context in the signature. The lower 64 bits
6959 of the resulting MD5 checksum comprise the signature. */
6962 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
6966 unsigned char checksum[16];
6970 name = get_AT_string (die, DW_AT_name);
6971 decl = get_AT_ref (die, DW_AT_specification);
6973 /* First, compute a signature for just the type name (and its surrounding
6974 context, if any. This is stored in the type unit DIE for link-time
6975 ODR (one-definition rule) checking. */
6977 if (is_cxx() && name != NULL)
6979 md5_init_ctx (&ctx);
6981 /* Checksum the names of surrounding namespaces and structures. */
6982 if (decl != NULL && decl->die_parent != NULL)
6983 checksum_die_context (decl->die_parent, &ctx);
6985 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
6986 md5_process_bytes (name, strlen (name) + 1, &ctx);
6987 md5_finish_ctx (&ctx, checksum);
6989 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
6992 /* Next, compute the complete type signature. */
6994 md5_init_ctx (&ctx);
6996 die->die_mark = mark;
6998 /* Checksum the names of surrounding namespaces and structures. */
6999 if (decl != NULL && decl->die_parent != NULL)
7000 checksum_die_context (decl->die_parent, &ctx);
7002 /* Checksum the DIE and its children. */
7003 die_checksum_ordered (die, &ctx, &mark);
7004 unmark_all_dies (die);
7005 md5_finish_ctx (&ctx, checksum);
7007 /* Store the signature in the type node and link the type DIE and the
7008 type node together. */
7009 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
7010 DWARF_TYPE_SIGNATURE_SIZE);
7011 die->die_id.die_type_node = type_node;
7012 type_node->type_die = die;
7014 /* If the DIE is a specification, link its declaration to the type node
7017 decl->die_id.die_type_node = type_node;
7020 /* Do the location expressions look same? */
7022 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
7024 return loc1->dw_loc_opc == loc2->dw_loc_opc
7025 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
7026 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
7029 /* Do the values look the same? */
7031 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
7033 dw_loc_descr_ref loc1, loc2;
7036 if (v1->val_class != v2->val_class)
7039 switch (v1->val_class)
7041 case dw_val_class_const:
7042 return v1->v.val_int == v2->v.val_int;
7043 case dw_val_class_unsigned_const:
7044 return v1->v.val_unsigned == v2->v.val_unsigned;
7045 case dw_val_class_const_double:
7046 return v1->v.val_double.high == v2->v.val_double.high
7047 && v1->v.val_double.low == v2->v.val_double.low;
7048 case dw_val_class_vec:
7049 if (v1->v.val_vec.length != v2->v.val_vec.length
7050 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
7052 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
7053 v1->v.val_vec.length * v1->v.val_vec.elt_size))
7056 case dw_val_class_flag:
7057 return v1->v.val_flag == v2->v.val_flag;
7058 case dw_val_class_str:
7059 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
7061 case dw_val_class_addr:
7062 r1 = v1->v.val_addr;
7063 r2 = v2->v.val_addr;
7064 if (GET_CODE (r1) != GET_CODE (r2))
7066 return !rtx_equal_p (r1, r2);
7068 case dw_val_class_offset:
7069 return v1->v.val_offset == v2->v.val_offset;
7071 case dw_val_class_loc:
7072 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
7074 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
7075 if (!same_loc_p (loc1, loc2, mark))
7077 return !loc1 && !loc2;
7079 case dw_val_class_die_ref:
7080 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
7082 case dw_val_class_fde_ref:
7083 case dw_val_class_vms_delta:
7084 case dw_val_class_lbl_id:
7085 case dw_val_class_lineptr:
7086 case dw_val_class_macptr:
7089 case dw_val_class_file:
7090 return v1->v.val_file == v2->v.val_file;
7092 case dw_val_class_data8:
7093 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
7100 /* Do the attributes look the same? */
7103 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
7105 if (at1->dw_attr != at2->dw_attr)
7108 /* We don't care that this was compiled with a different compiler
7109 snapshot; if the output is the same, that's what matters. */
7110 if (at1->dw_attr == DW_AT_producer)
7113 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7116 /* Do the dies look the same? */
7119 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7125 /* To avoid infinite recursion. */
7127 return die1->die_mark == die2->die_mark;
7128 die1->die_mark = die2->die_mark = ++(*mark);
7130 if (die1->die_tag != die2->die_tag)
7133 if (VEC_length (dw_attr_node, die1->die_attr)
7134 != VEC_length (dw_attr_node, die2->die_attr))
7137 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
7138 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
7141 c1 = die1->die_child;
7142 c2 = die2->die_child;
7151 if (!same_die_p (c1, c2, mark))
7155 if (c1 == die1->die_child)
7157 if (c2 == die2->die_child)
7167 /* Do the dies look the same? Wrapper around same_die_p. */
7170 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
7173 int ret = same_die_p (die1, die2, &mark);
7175 unmark_all_dies (die1);
7176 unmark_all_dies (die2);
7181 /* The prefix to attach to symbols on DIEs in the current comdat debug
7183 static char *comdat_symbol_id;
7185 /* The index of the current symbol within the current comdat CU. */
7186 static unsigned int comdat_symbol_number;
7188 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7189 children, and set comdat_symbol_id accordingly. */
7192 compute_section_prefix (dw_die_ref unit_die)
7194 const char *die_name = get_AT_string (unit_die, DW_AT_name);
7195 const char *base = die_name ? lbasename (die_name) : "anonymous";
7196 char *name = XALLOCAVEC (char, strlen (base) + 64);
7199 unsigned char checksum[16];
7202 /* Compute the checksum of the DIE, then append part of it as hex digits to
7203 the name filename of the unit. */
7205 md5_init_ctx (&ctx);
7207 die_checksum (unit_die, &ctx, &mark);
7208 unmark_all_dies (unit_die);
7209 md5_finish_ctx (&ctx, checksum);
7211 sprintf (name, "%s.", base);
7212 clean_symbol_name (name);
7214 p = name + strlen (name);
7215 for (i = 0; i < 4; i++)
7217 sprintf (p, "%.2x", checksum[i]);
7221 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
7222 comdat_symbol_number = 0;
7225 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7228 is_type_die (dw_die_ref die)
7230 switch (die->die_tag)
7232 case DW_TAG_array_type:
7233 case DW_TAG_class_type:
7234 case DW_TAG_interface_type:
7235 case DW_TAG_enumeration_type:
7236 case DW_TAG_pointer_type:
7237 case DW_TAG_reference_type:
7238 case DW_TAG_rvalue_reference_type:
7239 case DW_TAG_string_type:
7240 case DW_TAG_structure_type:
7241 case DW_TAG_subroutine_type:
7242 case DW_TAG_union_type:
7243 case DW_TAG_ptr_to_member_type:
7244 case DW_TAG_set_type:
7245 case DW_TAG_subrange_type:
7246 case DW_TAG_base_type:
7247 case DW_TAG_const_type:
7248 case DW_TAG_file_type:
7249 case DW_TAG_packed_type:
7250 case DW_TAG_volatile_type:
7251 case DW_TAG_typedef:
7258 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7259 Basically, we want to choose the bits that are likely to be shared between
7260 compilations (types) and leave out the bits that are specific to individual
7261 compilations (functions). */
7264 is_comdat_die (dw_die_ref c)
7266 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7267 we do for stabs. The advantage is a greater likelihood of sharing between
7268 objects that don't include headers in the same order (and therefore would
7269 put the base types in a different comdat). jason 8/28/00 */
7271 if (c->die_tag == DW_TAG_base_type)
7274 if (c->die_tag == DW_TAG_pointer_type
7275 || c->die_tag == DW_TAG_reference_type
7276 || c->die_tag == DW_TAG_rvalue_reference_type
7277 || c->die_tag == DW_TAG_const_type
7278 || c->die_tag == DW_TAG_volatile_type)
7280 dw_die_ref t = get_AT_ref (c, DW_AT_type);
7282 return t ? is_comdat_die (t) : 0;
7285 return is_type_die (c);
7288 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7289 compilation unit. */
7292 is_symbol_die (dw_die_ref c)
7294 return (is_type_die (c)
7295 || is_declaration_die (c)
7296 || c->die_tag == DW_TAG_namespace
7297 || c->die_tag == DW_TAG_module);
7300 /* Returns true iff C is a compile-unit DIE. */
7303 is_cu_die (dw_die_ref c)
7305 return c && c->die_tag == DW_TAG_compile_unit;
7309 gen_internal_sym (const char *prefix)
7313 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
7314 return xstrdup (buf);
7317 /* Assign symbols to all worthy DIEs under DIE. */
7320 assign_symbol_names (dw_die_ref die)
7324 if (is_symbol_die (die))
7326 if (comdat_symbol_id)
7328 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
7330 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
7331 comdat_symbol_id, comdat_symbol_number++);
7332 die->die_id.die_symbol = xstrdup (p);
7335 die->die_id.die_symbol = gen_internal_sym ("LDIE");
7338 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
7341 struct cu_hash_table_entry
7344 unsigned min_comdat_num, max_comdat_num;
7345 struct cu_hash_table_entry *next;
7348 /* Routines to manipulate hash table of CUs. */
7350 htab_cu_hash (const void *of)
7352 const struct cu_hash_table_entry *const entry =
7353 (const struct cu_hash_table_entry *) of;
7355 return htab_hash_string (entry->cu->die_id.die_symbol);
7359 htab_cu_eq (const void *of1, const void *of2)
7361 const struct cu_hash_table_entry *const entry1 =
7362 (const struct cu_hash_table_entry *) of1;
7363 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7365 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
7369 htab_cu_del (void *what)
7371 struct cu_hash_table_entry *next,
7372 *entry = (struct cu_hash_table_entry *) what;
7382 /* Check whether we have already seen this CU and set up SYM_NUM
7385 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
7387 struct cu_hash_table_entry dummy;
7388 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
7390 dummy.max_comdat_num = 0;
7392 slot = (struct cu_hash_table_entry **)
7393 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
7397 for (; entry; last = entry, entry = entry->next)
7399 if (same_die_p_wrap (cu, entry->cu))
7405 *sym_num = entry->min_comdat_num;
7409 entry = XCNEW (struct cu_hash_table_entry);
7411 entry->min_comdat_num = *sym_num = last->max_comdat_num;
7412 entry->next = *slot;
7418 /* Record SYM_NUM to record of CU in HTABLE. */
7420 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
7422 struct cu_hash_table_entry **slot, *entry;
7424 slot = (struct cu_hash_table_entry **)
7425 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
7429 entry->max_comdat_num = sym_num;
7432 /* Traverse the DIE (which is always comp_unit_die), and set up
7433 additional compilation units for each of the include files we see
7434 bracketed by BINCL/EINCL. */
7437 break_out_includes (dw_die_ref die)
7440 dw_die_ref unit = NULL;
7441 limbo_die_node *node, **pnode;
7442 htab_t cu_hash_table;
7446 dw_die_ref prev = c;
7448 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
7449 || (unit && is_comdat_die (c)))
7451 dw_die_ref next = c->die_sib;
7453 /* This DIE is for a secondary CU; remove it from the main one. */
7454 remove_child_with_prev (c, prev);
7456 if (c->die_tag == DW_TAG_GNU_BINCL)
7457 unit = push_new_compile_unit (unit, c);
7458 else if (c->die_tag == DW_TAG_GNU_EINCL)
7459 unit = pop_compile_unit (unit);
7461 add_child_die (unit, c);
7463 if (c == die->die_child)
7466 } while (c != die->die_child);
7469 /* We can only use this in debugging, since the frontend doesn't check
7470 to make sure that we leave every include file we enter. */
7474 assign_symbol_names (die);
7475 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
7476 for (node = limbo_die_list, pnode = &limbo_die_list;
7482 compute_section_prefix (node->die);
7483 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
7484 &comdat_symbol_number);
7485 assign_symbol_names (node->die);
7487 *pnode = node->next;
7490 pnode = &node->next;
7491 record_comdat_symbol_number (node->die, cu_hash_table,
7492 comdat_symbol_number);
7495 htab_delete (cu_hash_table);
7498 /* Return non-zero if this DIE is a declaration. */
7501 is_declaration_die (dw_die_ref die)
7506 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7507 if (a->dw_attr == DW_AT_declaration)
7513 /* Return non-zero if this DIE is nested inside a subprogram. */
7516 is_nested_in_subprogram (dw_die_ref die)
7518 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
7522 return local_scope_p (decl);
7525 /* Return non-zero if this DIE contains a defining declaration of a
7529 contains_subprogram_definition (dw_die_ref die)
7533 if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
7535 FOR_EACH_CHILD (die, c, if (contains_subprogram_definition(c)) return 1);
7539 /* Return non-zero if this is a type DIE that should be moved to a
7540 COMDAT .debug_types section. */
7543 should_move_die_to_comdat (dw_die_ref die)
7545 switch (die->die_tag)
7547 case DW_TAG_class_type:
7548 case DW_TAG_structure_type:
7549 case DW_TAG_enumeration_type:
7550 case DW_TAG_union_type:
7551 /* Don't move declarations, inlined instances, or types nested in a
7553 if (is_declaration_die (die)
7554 || get_AT (die, DW_AT_abstract_origin)
7555 || is_nested_in_subprogram (die))
7557 /* A type definition should never contain a subprogram definition. */
7558 gcc_assert (!contains_subprogram_definition (die));
7560 case DW_TAG_array_type:
7561 case DW_TAG_interface_type:
7562 case DW_TAG_pointer_type:
7563 case DW_TAG_reference_type:
7564 case DW_TAG_rvalue_reference_type:
7565 case DW_TAG_string_type:
7566 case DW_TAG_subroutine_type:
7567 case DW_TAG_ptr_to_member_type:
7568 case DW_TAG_set_type:
7569 case DW_TAG_subrange_type:
7570 case DW_TAG_base_type:
7571 case DW_TAG_const_type:
7572 case DW_TAG_file_type:
7573 case DW_TAG_packed_type:
7574 case DW_TAG_volatile_type:
7575 case DW_TAG_typedef:
7581 /* Make a clone of DIE. */
7584 clone_die (dw_die_ref die)
7590 clone = ggc_alloc_cleared_die_node ();
7591 clone->die_tag = die->die_tag;
7593 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7594 add_dwarf_attr (clone, a);
7599 /* Make a clone of the tree rooted at DIE. */
7602 clone_tree (dw_die_ref die)
7605 dw_die_ref clone = clone_die (die);
7607 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
7612 /* Make a clone of DIE as a declaration. */
7615 clone_as_declaration (dw_die_ref die)
7622 /* If the DIE is already a declaration, just clone it. */
7623 if (is_declaration_die (die))
7624 return clone_die (die);
7626 /* If the DIE is a specification, just clone its declaration DIE. */
7627 decl = get_AT_ref (die, DW_AT_specification);
7629 return clone_die (decl);
7631 clone = ggc_alloc_cleared_die_node ();
7632 clone->die_tag = die->die_tag;
7634 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7636 /* We don't want to copy over all attributes.
7637 For example we don't want DW_AT_byte_size because otherwise we will no
7638 longer have a declaration and GDB will treat it as a definition. */
7642 case DW_AT_artificial:
7643 case DW_AT_containing_type:
7644 case DW_AT_external:
7647 case DW_AT_virtuality:
7648 case DW_AT_linkage_name:
7649 case DW_AT_MIPS_linkage_name:
7650 add_dwarf_attr (clone, a);
7652 case DW_AT_byte_size:
7658 if (die->die_id.die_type_node)
7659 add_AT_die_ref (clone, DW_AT_signature, die);
7661 add_AT_flag (clone, DW_AT_declaration, 1);
7665 /* Copy the declaration context to the new compile unit DIE. This includes
7666 any surrounding namespace or type declarations. If the DIE has an
7667 AT_specification attribute, it also includes attributes and children
7668 attached to the specification. */
7671 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
7674 dw_die_ref new_decl;
7676 decl = get_AT_ref (die, DW_AT_specification);
7685 /* Copy the type node pointer from the new DIE to the original
7686 declaration DIE so we can forward references later. */
7687 decl->die_id.die_type_node = die->die_id.die_type_node;
7689 remove_AT (die, DW_AT_specification);
7691 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
7693 if (a->dw_attr != DW_AT_name
7694 && a->dw_attr != DW_AT_declaration
7695 && a->dw_attr != DW_AT_external)
7696 add_dwarf_attr (die, a);
7699 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
7702 if (decl->die_parent != NULL
7703 && decl->die_parent->die_tag != DW_TAG_compile_unit
7704 && decl->die_parent->die_tag != DW_TAG_type_unit)
7706 new_decl = copy_ancestor_tree (unit, decl, NULL);
7707 if (new_decl != NULL)
7709 remove_AT (new_decl, DW_AT_signature);
7710 add_AT_specification (die, new_decl);
7715 /* Generate the skeleton ancestor tree for the given NODE, then clone
7716 the DIE and add the clone into the tree. */
7719 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
7721 if (node->new_die != NULL)
7724 node->new_die = clone_as_declaration (node->old_die);
7726 if (node->parent != NULL)
7728 generate_skeleton_ancestor_tree (node->parent);
7729 add_child_die (node->parent->new_die, node->new_die);
7733 /* Generate a skeleton tree of DIEs containing any declarations that are
7734 found in the original tree. We traverse the tree looking for declaration
7735 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7738 generate_skeleton_bottom_up (skeleton_chain_node *parent)
7740 skeleton_chain_node node;
7743 dw_die_ref prev = NULL;
7744 dw_die_ref next = NULL;
7746 node.parent = parent;
7748 first = c = parent->old_die->die_child;
7752 if (prev == NULL || prev->die_sib == c)
7755 next = (c == first ? NULL : c->die_sib);
7757 node.new_die = NULL;
7758 if (is_declaration_die (c))
7760 /* Clone the existing DIE, move the original to the skeleton
7761 tree (which is in the main CU), and put the clone, with
7762 all the original's children, where the original came from. */
7763 dw_die_ref clone = clone_die (c);
7764 move_all_children (c, clone);
7766 replace_child (c, clone, prev);
7767 generate_skeleton_ancestor_tree (parent);
7768 add_child_die (parent->new_die, c);
7772 generate_skeleton_bottom_up (&node);
7773 } while (next != NULL);
7776 /* Wrapper function for generate_skeleton_bottom_up. */
7779 generate_skeleton (dw_die_ref die)
7781 skeleton_chain_node node;
7784 node.new_die = NULL;
7787 /* If this type definition is nested inside another type,
7788 always leave at least a declaration in its place. */
7789 if (die->die_parent != NULL && is_type_die (die->die_parent))
7790 node.new_die = clone_as_declaration (die);
7792 generate_skeleton_bottom_up (&node);
7793 return node.new_die;
7796 /* Remove the DIE from its parent, possibly replacing it with a cloned
7797 declaration. The original DIE will be moved to a new compile unit
7798 so that existing references to it follow it to the new location. If
7799 any of the original DIE's descendants is a declaration, we need to
7800 replace the original DIE with a skeleton tree and move the
7801 declarations back into the skeleton tree. */
7804 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
7806 dw_die_ref skeleton;
7808 skeleton = generate_skeleton (child);
7809 if (skeleton == NULL)
7810 remove_child_with_prev (child, prev);
7813 skeleton->die_id.die_type_node = child->die_id.die_type_node;
7814 replace_child (child, skeleton, prev);
7820 /* Traverse the DIE and set up additional .debug_types sections for each
7821 type worthy of being placed in a COMDAT section. */
7824 break_out_comdat_types (dw_die_ref die)
7828 dw_die_ref prev = NULL;
7829 dw_die_ref next = NULL;
7830 dw_die_ref unit = NULL;
7832 first = c = die->die_child;
7836 if (prev == NULL || prev->die_sib == c)
7839 next = (c == first ? NULL : c->die_sib);
7840 if (should_move_die_to_comdat (c))
7842 dw_die_ref replacement;
7843 comdat_type_node_ref type_node;
7845 /* Create a new type unit DIE as the root for the new tree, and
7846 add it to the list of comdat types. */
7847 unit = new_die (DW_TAG_type_unit, NULL, NULL);
7848 add_AT_unsigned (unit, DW_AT_language,
7849 get_AT_unsigned (comp_unit_die (), DW_AT_language));
7850 type_node = ggc_alloc_cleared_comdat_type_node ();
7851 type_node->root_die = unit;
7852 type_node->next = comdat_type_list;
7853 comdat_type_list = type_node;
7855 /* Generate the type signature. */
7856 generate_type_signature (c, type_node);
7858 /* Copy the declaration context, attributes, and children of the
7859 declaration into the new compile unit DIE. */
7860 copy_declaration_context (unit, c);
7862 /* Remove this DIE from the main CU. */
7863 replacement = remove_child_or_replace_with_skeleton (c, prev);
7865 /* Break out nested types into their own type units. */
7866 break_out_comdat_types (c);
7868 /* Add the DIE to the new compunit. */
7869 add_child_die (unit, c);
7871 if (replacement != NULL)
7874 else if (c->die_tag == DW_TAG_namespace
7875 || c->die_tag == DW_TAG_class_type
7876 || c->die_tag == DW_TAG_structure_type
7877 || c->die_tag == DW_TAG_union_type)
7879 /* Look for nested types that can be broken out. */
7880 break_out_comdat_types (c);
7882 } while (next != NULL);
7885 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7887 struct decl_table_entry
7893 /* Routines to manipulate hash table of copied declarations. */
7896 htab_decl_hash (const void *of)
7898 const struct decl_table_entry *const entry =
7899 (const struct decl_table_entry *) of;
7901 return htab_hash_pointer (entry->orig);
7905 htab_decl_eq (const void *of1, const void *of2)
7907 const struct decl_table_entry *const entry1 =
7908 (const struct decl_table_entry *) of1;
7909 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7911 return entry1->orig == entry2;
7915 htab_decl_del (void *what)
7917 struct decl_table_entry *entry = (struct decl_table_entry *) what;
7922 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7923 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7924 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7925 to check if the ancestor has already been copied into UNIT. */
7928 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
7930 dw_die_ref parent = die->die_parent;
7931 dw_die_ref new_parent = unit;
7934 struct decl_table_entry *entry = NULL;
7938 /* Check if the entry has already been copied to UNIT. */
7939 slot = htab_find_slot_with_hash (decl_table, die,
7940 htab_hash_pointer (die), INSERT);
7941 if (*slot != HTAB_EMPTY_ENTRY)
7943 entry = (struct decl_table_entry *) *slot;
7947 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7948 entry = XCNEW (struct decl_table_entry);
7956 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
7959 if (parent->die_tag != DW_TAG_compile_unit
7960 && parent->die_tag != DW_TAG_type_unit)
7961 new_parent = copy_ancestor_tree (unit, parent, decl_table);
7964 copy = clone_as_declaration (die);
7965 add_child_die (new_parent, copy);
7967 if (decl_table != NULL)
7969 /* Record the pointer to the copy. */
7976 /* Walk the DIE and its children, looking for references to incomplete
7977 or trivial types that are unmarked (i.e., that are not in the current
7981 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
7987 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7989 if (AT_class (a) == dw_val_class_die_ref)
7991 dw_die_ref targ = AT_ref (a);
7992 comdat_type_node_ref type_node = targ->die_id.die_type_node;
7994 struct decl_table_entry *entry;
7996 if (targ->die_mark != 0 || type_node != NULL)
7999 slot = htab_find_slot_with_hash (decl_table, targ,
8000 htab_hash_pointer (targ), INSERT);
8002 if (*slot != HTAB_EMPTY_ENTRY)
8004 /* TARG has already been copied, so we just need to
8005 modify the reference to point to the copy. */
8006 entry = (struct decl_table_entry *) *slot;
8007 a->dw_attr_val.v.val_die_ref.die = entry->copy;
8011 dw_die_ref parent = unit;
8012 dw_die_ref copy = clone_tree (targ);
8014 /* Make sure the cloned tree is marked as part of the
8018 /* Record in DECL_TABLE that TARG has been copied.
8019 Need to do this now, before the recursive call,
8020 because DECL_TABLE may be expanded and SLOT
8021 would no longer be a valid pointer. */
8022 entry = XCNEW (struct decl_table_entry);
8027 /* If TARG has surrounding context, copy its ancestor tree
8028 into the new type unit. */
8029 if (targ->die_parent != NULL
8030 && targ->die_parent->die_tag != DW_TAG_compile_unit
8031 && targ->die_parent->die_tag != DW_TAG_type_unit)
8032 parent = copy_ancestor_tree (unit, targ->die_parent,
8035 add_child_die (parent, copy);
8036 a->dw_attr_val.v.val_die_ref.die = copy;
8038 /* Make sure the newly-copied DIE is walked. If it was
8039 installed in a previously-added context, it won't
8040 get visited otherwise. */
8043 /* Find the highest point of the newly-added tree,
8044 mark each node along the way, and walk from there. */
8045 parent->die_mark = 1;
8046 while (parent->die_parent
8047 && parent->die_parent->die_mark == 0)
8049 parent = parent->die_parent;
8050 parent->die_mark = 1;
8052 copy_decls_walk (unit, parent, decl_table);
8058 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
8061 /* Copy declarations for "unworthy" types into the new comdat section.
8062 Incomplete types, modified types, and certain other types aren't broken
8063 out into comdat sections of their own, so they don't have a signature,
8064 and we need to copy the declaration into the same section so that we
8065 don't have an external reference. */
8068 copy_decls_for_unworthy_types (dw_die_ref unit)
8073 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
8074 copy_decls_walk (unit, unit, decl_table);
8075 htab_delete (decl_table);
8079 /* Traverse the DIE and add a sibling attribute if it may have the
8080 effect of speeding up access to siblings. To save some space,
8081 avoid generating sibling attributes for DIE's without children. */
8084 add_sibling_attributes (dw_die_ref die)
8088 if (! die->die_child)
8091 if (die->die_parent && die != die->die_parent->die_child)
8092 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
8094 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
8097 /* Output all location lists for the DIE and its children. */
8100 output_location_lists (dw_die_ref die)
8106 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8107 if (AT_class (a) == dw_val_class_loc_list)
8108 output_loc_list (AT_loc_list (a));
8110 FOR_EACH_CHILD (die, c, output_location_lists (c));
8113 /* The format of each DIE (and its attribute value pairs) is encoded in an
8114 abbreviation table. This routine builds the abbreviation table and assigns
8115 a unique abbreviation id for each abbreviation entry. The children of each
8116 die are visited recursively. */
8119 build_abbrev_table (dw_die_ref die)
8121 unsigned long abbrev_id;
8122 unsigned int n_alloc;
8127 /* Scan the DIE references, and mark as external any that refer to
8128 DIEs from other CUs (i.e. those which are not marked). */
8129 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8130 if (AT_class (a) == dw_val_class_die_ref
8131 && AT_ref (a)->die_mark == 0)
8133 gcc_assert (use_debug_types || AT_ref (a)->die_id.die_symbol);
8134 set_AT_ref_external (a, 1);
8137 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8139 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8140 dw_attr_ref die_a, abbrev_a;
8144 if (abbrev->die_tag != die->die_tag)
8146 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
8149 if (VEC_length (dw_attr_node, abbrev->die_attr)
8150 != VEC_length (dw_attr_node, die->die_attr))
8153 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
8155 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
8156 if ((abbrev_a->dw_attr != die_a->dw_attr)
8157 || (value_format (abbrev_a) != value_format (die_a)))
8167 if (abbrev_id >= abbrev_die_table_in_use)
8169 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
8171 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
8172 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
8175 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
8176 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
8177 abbrev_die_table_allocated = n_alloc;
8180 ++abbrev_die_table_in_use;
8181 abbrev_die_table[abbrev_id] = die;
8184 die->die_abbrev = abbrev_id;
8185 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
8188 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8191 constant_size (unsigned HOST_WIDE_INT value)
8198 log = floor_log2 (value);
8201 log = 1 << (floor_log2 (log) + 1);
8206 /* Return the size of a DIE as it is represented in the
8207 .debug_info section. */
8209 static unsigned long
8210 size_of_die (dw_die_ref die)
8212 unsigned long size = 0;
8216 size += size_of_uleb128 (die->die_abbrev);
8217 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8219 switch (AT_class (a))
8221 case dw_val_class_addr:
8222 size += DWARF2_ADDR_SIZE;
8224 case dw_val_class_offset:
8225 size += DWARF_OFFSET_SIZE;
8227 case dw_val_class_loc:
8229 unsigned long lsize = size_of_locs (AT_loc (a));
8232 if (dwarf_version >= 4)
8233 size += size_of_uleb128 (lsize);
8235 size += constant_size (lsize);
8239 case dw_val_class_loc_list:
8240 size += DWARF_OFFSET_SIZE;
8242 case dw_val_class_range_list:
8243 size += DWARF_OFFSET_SIZE;
8245 case dw_val_class_const:
8246 size += size_of_sleb128 (AT_int (a));
8248 case dw_val_class_unsigned_const:
8249 size += constant_size (AT_unsigned (a));
8251 case dw_val_class_const_double:
8252 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
8253 if (HOST_BITS_PER_WIDE_INT >= 64)
8256 case dw_val_class_vec:
8257 size += constant_size (a->dw_attr_val.v.val_vec.length
8258 * a->dw_attr_val.v.val_vec.elt_size)
8259 + a->dw_attr_val.v.val_vec.length
8260 * a->dw_attr_val.v.val_vec.elt_size; /* block */
8262 case dw_val_class_flag:
8263 if (dwarf_version >= 4)
8264 /* Currently all add_AT_flag calls pass in 1 as last argument,
8265 so DW_FORM_flag_present can be used. If that ever changes,
8266 we'll need to use DW_FORM_flag and have some optimization
8267 in build_abbrev_table that will change those to
8268 DW_FORM_flag_present if it is set to 1 in all DIEs using
8269 the same abbrev entry. */
8270 gcc_assert (a->dw_attr_val.v.val_flag == 1);
8274 case dw_val_class_die_ref:
8275 if (AT_ref_external (a))
8277 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
8278 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
8279 is sized by target address length, whereas in DWARF3
8280 it's always sized as an offset. */
8281 if (use_debug_types)
8282 size += DWARF_TYPE_SIGNATURE_SIZE;
8283 else if (dwarf_version == 2)
8284 size += DWARF2_ADDR_SIZE;
8286 size += DWARF_OFFSET_SIZE;
8289 size += DWARF_OFFSET_SIZE;
8291 case dw_val_class_fde_ref:
8292 size += DWARF_OFFSET_SIZE;
8294 case dw_val_class_lbl_id:
8295 size += DWARF2_ADDR_SIZE;
8297 case dw_val_class_lineptr:
8298 case dw_val_class_macptr:
8299 size += DWARF_OFFSET_SIZE;
8301 case dw_val_class_str:
8302 if (AT_string_form (a) == DW_FORM_strp)
8303 size += DWARF_OFFSET_SIZE;
8305 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
8307 case dw_val_class_file:
8308 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
8310 case dw_val_class_data8:
8313 case dw_val_class_vms_delta:
8314 size += DWARF_OFFSET_SIZE;
8324 /* Size the debugging information associated with a given DIE. Visits the
8325 DIE's children recursively. Updates the global variable next_die_offset, on
8326 each time through. Uses the current value of next_die_offset to update the
8327 die_offset field in each DIE. */
8330 calc_die_sizes (dw_die_ref die)
8334 gcc_assert (die->die_offset == 0
8335 || (unsigned long int) die->die_offset == next_die_offset);
8336 die->die_offset = next_die_offset;
8337 next_die_offset += size_of_die (die);
8339 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
8341 if (die->die_child != NULL)
8342 /* Count the null byte used to terminate sibling lists. */
8343 next_die_offset += 1;
8346 /* Size just the base type children at the start of the CU.
8347 This is needed because build_abbrev needs to size locs
8348 and sizing of type based stack ops needs to know die_offset
8349 values for the base types. */
8352 calc_base_type_die_sizes (void)
8354 unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8356 dw_die_ref base_type;
8357 #if ENABLE_ASSERT_CHECKING
8358 dw_die_ref prev = comp_unit_die ()->die_child;
8361 die_offset += size_of_die (comp_unit_die ());
8362 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
8364 #if ENABLE_ASSERT_CHECKING
8365 gcc_assert (base_type->die_offset == 0
8366 && prev->die_sib == base_type
8367 && base_type->die_child == NULL
8368 && base_type->die_abbrev);
8371 base_type->die_offset = die_offset;
8372 die_offset += size_of_die (base_type);
8376 /* Set the marks for a die and its children. We do this so
8377 that we know whether or not a reference needs to use FORM_ref_addr; only
8378 DIEs in the same CU will be marked. We used to clear out the offset
8379 and use that as the flag, but ran into ordering problems. */
8382 mark_dies (dw_die_ref die)
8386 gcc_assert (!die->die_mark);
8389 FOR_EACH_CHILD (die, c, mark_dies (c));
8392 /* Clear the marks for a die and its children. */
8395 unmark_dies (dw_die_ref die)
8399 if (! use_debug_types)
8400 gcc_assert (die->die_mark);
8403 FOR_EACH_CHILD (die, c, unmark_dies (c));
8406 /* Clear the marks for a die, its children and referred dies. */
8409 unmark_all_dies (dw_die_ref die)
8419 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
8421 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8422 if (AT_class (a) == dw_val_class_die_ref)
8423 unmark_all_dies (AT_ref (a));
8426 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8427 generated for the compilation unit. */
8429 static unsigned long
8430 size_of_pubnames (VEC (pubname_entry, gc) * names)
8436 size = DWARF_PUBNAMES_HEADER_SIZE;
8437 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
8438 if (names != pubtype_table
8439 || p->die->die_offset != 0
8440 || !flag_eliminate_unused_debug_types)
8441 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
8443 size += DWARF_OFFSET_SIZE;
8447 /* Return the size of the information in the .debug_aranges section. */
8449 static unsigned long
8450 size_of_aranges (void)
8454 size = DWARF_ARANGES_HEADER_SIZE;
8456 /* Count the address/length pair for this compilation unit. */
8457 if (text_section_used)
8458 size += 2 * DWARF2_ADDR_SIZE;
8459 if (cold_text_section_used)
8460 size += 2 * DWARF2_ADDR_SIZE;
8461 if (have_multiple_function_sections)
8463 unsigned fde_idx = 0;
8465 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
8467 dw_fde_ref fde = &fde_table[fde_idx];
8469 if (!fde->in_std_section)
8470 size += 2 * DWARF2_ADDR_SIZE;
8471 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
8472 size += 2 * DWARF2_ADDR_SIZE;
8476 /* Count the two zero words used to terminated the address range table. */
8477 size += 2 * DWARF2_ADDR_SIZE;
8481 /* Select the encoding of an attribute value. */
8483 static enum dwarf_form
8484 value_format (dw_attr_ref a)
8486 switch (a->dw_attr_val.val_class)
8488 case dw_val_class_addr:
8489 /* Only very few attributes allow DW_FORM_addr. */
8494 case DW_AT_entry_pc:
8495 case DW_AT_trampoline:
8496 return DW_FORM_addr;
8500 switch (DWARF2_ADDR_SIZE)
8503 return DW_FORM_data1;
8505 return DW_FORM_data2;
8507 return DW_FORM_data4;
8509 return DW_FORM_data8;
8513 case dw_val_class_range_list:
8514 case dw_val_class_loc_list:
8515 if (dwarf_version >= 4)
8516 return DW_FORM_sec_offset;
8518 case dw_val_class_vms_delta:
8519 case dw_val_class_offset:
8520 switch (DWARF_OFFSET_SIZE)
8523 return DW_FORM_data4;
8525 return DW_FORM_data8;
8529 case dw_val_class_loc:
8530 if (dwarf_version >= 4)
8531 return DW_FORM_exprloc;
8532 switch (constant_size (size_of_locs (AT_loc (a))))
8535 return DW_FORM_block1;
8537 return DW_FORM_block2;
8541 case dw_val_class_const:
8542 return DW_FORM_sdata;
8543 case dw_val_class_unsigned_const:
8544 switch (constant_size (AT_unsigned (a)))
8547 return DW_FORM_data1;
8549 return DW_FORM_data2;
8551 return DW_FORM_data4;
8553 return DW_FORM_data8;
8557 case dw_val_class_const_double:
8558 switch (HOST_BITS_PER_WIDE_INT)
8561 return DW_FORM_data2;
8563 return DW_FORM_data4;
8565 return DW_FORM_data8;
8568 return DW_FORM_block1;
8570 case dw_val_class_vec:
8571 switch (constant_size (a->dw_attr_val.v.val_vec.length
8572 * a->dw_attr_val.v.val_vec.elt_size))
8575 return DW_FORM_block1;
8577 return DW_FORM_block2;
8579 return DW_FORM_block4;
8583 case dw_val_class_flag:
8584 if (dwarf_version >= 4)
8586 /* Currently all add_AT_flag calls pass in 1 as last argument,
8587 so DW_FORM_flag_present can be used. If that ever changes,
8588 we'll need to use DW_FORM_flag and have some optimization
8589 in build_abbrev_table that will change those to
8590 DW_FORM_flag_present if it is set to 1 in all DIEs using
8591 the same abbrev entry. */
8592 gcc_assert (a->dw_attr_val.v.val_flag == 1);
8593 return DW_FORM_flag_present;
8595 return DW_FORM_flag;
8596 case dw_val_class_die_ref:
8597 if (AT_ref_external (a))
8598 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
8601 case dw_val_class_fde_ref:
8602 return DW_FORM_data;
8603 case dw_val_class_lbl_id:
8604 return DW_FORM_addr;
8605 case dw_val_class_lineptr:
8606 case dw_val_class_macptr:
8607 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
8608 case dw_val_class_str:
8609 return AT_string_form (a);
8610 case dw_val_class_file:
8611 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
8614 return DW_FORM_data1;
8616 return DW_FORM_data2;
8618 return DW_FORM_data4;
8623 case dw_val_class_data8:
8624 return DW_FORM_data8;
8631 /* Output the encoding of an attribute value. */
8634 output_value_format (dw_attr_ref a)
8636 enum dwarf_form form = value_format (a);
8638 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
8641 /* Output the .debug_abbrev section which defines the DIE abbreviation
8645 output_abbrev_section (void)
8647 unsigned long abbrev_id;
8649 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8651 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8655 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
8656 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
8657 dwarf_tag_name (abbrev->die_tag));
8659 if (abbrev->die_child != NULL)
8660 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
8662 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
8664 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
8667 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
8668 dwarf_attr_name (a_attr->dw_attr));
8669 output_value_format (a_attr);
8672 dw2_asm_output_data (1, 0, NULL);
8673 dw2_asm_output_data (1, 0, NULL);
8676 /* Terminate the table. */
8677 dw2_asm_output_data (1, 0, NULL);
8680 /* Output a symbol we can use to refer to this DIE from another CU. */
8683 output_die_symbol (dw_die_ref die)
8685 char *sym = die->die_id.die_symbol;
8690 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8691 /* We make these global, not weak; if the target doesn't support
8692 .linkonce, it doesn't support combining the sections, so debugging
8694 targetm.asm_out.globalize_label (asm_out_file, sym);
8696 ASM_OUTPUT_LABEL (asm_out_file, sym);
8699 /* Return a new location list, given the begin and end range, and the
8702 static inline dw_loc_list_ref
8703 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8704 const char *section)
8706 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
8708 retlist->begin = begin;
8710 retlist->expr = expr;
8711 retlist->section = section;
8716 /* Generate a new internal symbol for this location list node, if it
8717 hasn't got one yet. */
8720 gen_llsym (dw_loc_list_ref list)
8722 gcc_assert (!list->ll_symbol);
8723 list->ll_symbol = gen_internal_sym ("LLST");
8726 /* Output the location list given to us. */
8729 output_loc_list (dw_loc_list_ref list_head)
8731 dw_loc_list_ref curr = list_head;
8733 if (list_head->emitted)
8735 list_head->emitted = true;
8737 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8739 /* Walk the location list, and output each range + expression. */
8740 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8743 /* Don't output an entry that starts and ends at the same address. */
8744 if (strcmp (curr->begin, curr->end) == 0 && !curr->force)
8746 if (!have_multiple_function_sections)
8748 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8749 "Location list begin address (%s)",
8750 list_head->ll_symbol);
8751 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8752 "Location list end address (%s)",
8753 list_head->ll_symbol);
8757 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8758 "Location list begin address (%s)",
8759 list_head->ll_symbol);
8760 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8761 "Location list end address (%s)",
8762 list_head->ll_symbol);
8764 size = size_of_locs (curr->expr);
8766 /* Output the block length for this list of location operations. */
8767 gcc_assert (size <= 0xffff);
8768 dw2_asm_output_data (2, size, "%s", "Location expression size");
8770 output_loc_sequence (curr->expr, -1);
8773 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8774 "Location list terminator begin (%s)",
8775 list_head->ll_symbol);
8776 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8777 "Location list terminator end (%s)",
8778 list_head->ll_symbol);
8781 /* Output a type signature. */
8784 output_signature (const char *sig, const char *name)
8788 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8789 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
8792 /* Output the DIE and its attributes. Called recursively to generate
8793 the definitions of each child DIE. */
8796 output_die (dw_die_ref die)
8803 /* If someone in another CU might refer to us, set up a symbol for
8804 them to point to. */
8805 if (! use_debug_types && die->die_id.die_symbol)
8806 output_die_symbol (die);
8808 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
8809 (unsigned long)die->die_offset,
8810 dwarf_tag_name (die->die_tag));
8812 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8814 const char *name = dwarf_attr_name (a->dw_attr);
8816 switch (AT_class (a))
8818 case dw_val_class_addr:
8819 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8822 case dw_val_class_offset:
8823 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8827 case dw_val_class_range_list:
8829 char *p = strchr (ranges_section_label, '\0');
8831 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8832 a->dw_attr_val.v.val_offset);
8833 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8834 debug_ranges_section, "%s", name);
8839 case dw_val_class_loc:
8840 size = size_of_locs (AT_loc (a));
8842 /* Output the block length for this list of location operations. */
8843 if (dwarf_version >= 4)
8844 dw2_asm_output_data_uleb128 (size, "%s", name);
8846 dw2_asm_output_data (constant_size (size), size, "%s", name);
8848 output_loc_sequence (AT_loc (a), -1);
8851 case dw_val_class_const:
8852 /* ??? It would be slightly more efficient to use a scheme like is
8853 used for unsigned constants below, but gdb 4.x does not sign
8854 extend. Gdb 5.x does sign extend. */
8855 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8858 case dw_val_class_unsigned_const:
8859 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8860 AT_unsigned (a), "%s", name);
8863 case dw_val_class_const_double:
8865 unsigned HOST_WIDE_INT first, second;
8867 if (HOST_BITS_PER_WIDE_INT >= 64)
8868 dw2_asm_output_data (1,
8869 2 * HOST_BITS_PER_WIDE_INT
8870 / HOST_BITS_PER_CHAR,
8873 if (WORDS_BIG_ENDIAN)
8875 first = a->dw_attr_val.v.val_double.high;
8876 second = a->dw_attr_val.v.val_double.low;
8880 first = a->dw_attr_val.v.val_double.low;
8881 second = a->dw_attr_val.v.val_double.high;
8884 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8886 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8891 case dw_val_class_vec:
8893 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8894 unsigned int len = a->dw_attr_val.v.val_vec.length;
8898 dw2_asm_output_data (constant_size (len * elt_size),
8899 len * elt_size, "%s", name);
8900 if (elt_size > sizeof (HOST_WIDE_INT))
8905 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8908 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8909 "fp or vector constant word %u", i);
8913 case dw_val_class_flag:
8914 if (dwarf_version >= 4)
8916 /* Currently all add_AT_flag calls pass in 1 as last argument,
8917 so DW_FORM_flag_present can be used. If that ever changes,
8918 we'll need to use DW_FORM_flag and have some optimization
8919 in build_abbrev_table that will change those to
8920 DW_FORM_flag_present if it is set to 1 in all DIEs using
8921 the same abbrev entry. */
8922 gcc_assert (AT_flag (a) == 1);
8924 fprintf (asm_out_file, "\t\t\t%s %s\n",
8925 ASM_COMMENT_START, name);
8928 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8931 case dw_val_class_loc_list:
8933 char *sym = AT_loc_list (a)->ll_symbol;
8936 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8941 case dw_val_class_die_ref:
8942 if (AT_ref_external (a))
8944 if (use_debug_types)
8946 comdat_type_node_ref type_node =
8947 AT_ref (a)->die_id.die_type_node;
8949 gcc_assert (type_node);
8950 output_signature (type_node->signature, name);
8954 char *sym = AT_ref (a)->die_id.die_symbol;
8958 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8959 length, whereas in DWARF3 it's always sized as an
8961 if (dwarf_version == 2)
8962 size = DWARF2_ADDR_SIZE;
8964 size = DWARF_OFFSET_SIZE;
8965 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
8971 gcc_assert (AT_ref (a)->die_offset);
8972 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8977 case dw_val_class_fde_ref:
8981 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8982 a->dw_attr_val.v.val_fde_index * 2);
8983 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8988 case dw_val_class_vms_delta:
8989 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
8990 AT_vms_delta2 (a), AT_vms_delta1 (a),
8994 case dw_val_class_lbl_id:
8995 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8998 case dw_val_class_lineptr:
8999 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9000 debug_line_section, "%s", name);
9003 case dw_val_class_macptr:
9004 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9005 debug_macinfo_section, "%s", name);
9008 case dw_val_class_str:
9009 if (AT_string_form (a) == DW_FORM_strp)
9010 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
9011 a->dw_attr_val.v.val_str->label,
9013 "%s: \"%s\"", name, AT_string (a));
9015 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
9018 case dw_val_class_file:
9020 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
9022 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
9023 a->dw_attr_val.v.val_file->filename);
9027 case dw_val_class_data8:
9031 for (i = 0; i < 8; i++)
9032 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
9033 i == 0 ? "%s" : NULL, name);
9042 FOR_EACH_CHILD (die, c, output_die (c));
9044 /* Add null byte to terminate sibling list. */
9045 if (die->die_child != NULL)
9046 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
9047 (unsigned long) die->die_offset);
9050 /* Output the compilation unit that appears at the beginning of the
9051 .debug_info section, and precedes the DIE descriptions. */
9054 output_compilation_unit_header (void)
9056 int ver = dwarf_version;
9058 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9059 dw2_asm_output_data (4, 0xffffffff,
9060 "Initial length escape value indicating 64-bit DWARF extension");
9061 dw2_asm_output_data (DWARF_OFFSET_SIZE,
9062 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
9063 "Length of Compilation Unit Info");
9064 dw2_asm_output_data (2, ver, "DWARF version number");
9065 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
9066 debug_abbrev_section,
9067 "Offset Into Abbrev. Section");
9068 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
9071 /* Output the compilation unit DIE and its children. */
9074 output_comp_unit (dw_die_ref die, int output_if_empty)
9076 const char *secname;
9079 /* Unless we are outputting main CU, we may throw away empty ones. */
9080 if (!output_if_empty && die->die_child == NULL)
9083 /* Even if there are no children of this DIE, we must output the information
9084 about the compilation unit. Otherwise, on an empty translation unit, we
9085 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9086 will then complain when examining the file. First mark all the DIEs in
9087 this CU so we know which get local refs. */
9090 build_abbrev_table (die);
9092 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9093 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9094 calc_die_sizes (die);
9096 oldsym = die->die_id.die_symbol;
9099 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
9101 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
9103 die->die_id.die_symbol = NULL;
9104 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
9108 switch_to_section (debug_info_section);
9109 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
9110 info_section_emitted = true;
9113 /* Output debugging information. */
9114 output_compilation_unit_header ();
9117 /* Leave the marks on the main CU, so we can check them in
9122 die->die_id.die_symbol = oldsym;
9126 /* Output a comdat type unit DIE and its children. */
9129 output_comdat_type_unit (comdat_type_node *node)
9131 const char *secname;
9134 #if defined (OBJECT_FORMAT_ELF)
9138 /* First mark all the DIEs in this CU so we know which get local refs. */
9139 mark_dies (node->root_die);
9141 build_abbrev_table (node->root_die);
9143 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9144 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
9145 calc_die_sizes (node->root_die);
9147 #if defined (OBJECT_FORMAT_ELF)
9148 secname = ".debug_types";
9149 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
9150 sprintf (tmp, "wt.");
9151 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
9152 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
9153 comdat_key = get_identifier (tmp);
9154 targetm.asm_out.named_section (secname,
9155 SECTION_DEBUG | SECTION_LINKONCE,
9158 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
9159 sprintf (tmp, ".gnu.linkonce.wt.");
9160 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
9161 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
9163 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
9166 /* Output debugging information. */
9167 output_compilation_unit_header ();
9168 output_signature (node->signature, "Type Signature");
9169 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
9170 "Offset to Type DIE");
9171 output_die (node->root_die);
9173 unmark_dies (node->root_die);
9176 /* Return the DWARF2/3 pubname associated with a decl. */
9179 dwarf2_name (tree decl, int scope)
9181 if (DECL_NAMELESS (decl))
9183 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
9186 /* Add a new entry to .debug_pubnames if appropriate. */
9189 add_pubname_string (const char *str, dw_die_ref die)
9191 if (targetm.want_debug_pub_sections)
9196 e.name = xstrdup (str);
9197 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
9202 add_pubname (tree decl, dw_die_ref die)
9204 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
9206 const char *name = dwarf2_name (decl, 1);
9208 add_pubname_string (name, die);
9212 /* Add a new entry to .debug_pubtypes if appropriate. */
9215 add_pubtype (tree decl, dw_die_ref die)
9219 if (!targetm.want_debug_pub_sections)
9223 if ((TREE_PUBLIC (decl)
9224 || is_cu_die (die->die_parent))
9225 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
9230 if (TYPE_NAME (decl))
9232 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
9233 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
9234 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
9235 && DECL_NAME (TYPE_NAME (decl)))
9236 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
9238 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
9243 e.name = dwarf2_name (decl, 1);
9245 e.name = xstrdup (e.name);
9248 /* If we don't have a name for the type, there's no point in adding
9250 if (e.name && e.name[0] != '\0')
9251 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
9255 /* Output the public names table used to speed up access to externally
9256 visible names; or the public types table used to find type definitions. */
9259 output_pubnames (VEC (pubname_entry, gc) * names)
9262 unsigned long pubnames_length = size_of_pubnames (names);
9265 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9266 dw2_asm_output_data (4, 0xffffffff,
9267 "Initial length escape value indicating 64-bit DWARF extension");
9268 if (names == pubname_table)
9269 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
9270 "Length of Public Names Info");
9272 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
9273 "Length of Public Type Names Info");
9274 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
9275 dw2_asm_output_data (2, 2, "DWARF Version");
9276 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9278 "Offset of Compilation Unit Info");
9279 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
9280 "Compilation Unit Length");
9282 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
9284 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9285 if (names == pubname_table)
9286 gcc_assert (pub->die->die_mark);
9288 if (names != pubtype_table
9289 || pub->die->die_offset != 0
9290 || !flag_eliminate_unused_debug_types)
9292 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
9295 dw2_asm_output_nstring (pub->name, -1, "external name");
9299 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
9302 /* Output the information that goes into the .debug_aranges table.
9303 Namely, define the beginning and ending address range of the
9304 text section generated for this compilation unit. */
9307 output_aranges (unsigned long aranges_length)
9311 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9312 dw2_asm_output_data (4, 0xffffffff,
9313 "Initial length escape value indicating 64-bit DWARF extension");
9314 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
9315 "Length of Address Ranges Info");
9316 /* Version number for aranges is still 2, even in DWARF3. */
9317 dw2_asm_output_data (2, 2, "DWARF Version");
9318 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9320 "Offset of Compilation Unit Info");
9321 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
9322 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9324 /* We need to align to twice the pointer size here. */
9325 if (DWARF_ARANGES_PAD_SIZE)
9327 /* Pad using a 2 byte words so that padding is correct for any
9329 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9330 2 * DWARF2_ADDR_SIZE);
9331 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
9332 dw2_asm_output_data (2, 0, NULL);
9335 /* It is necessary not to output these entries if the sections were
9336 not used; if the sections were not used, the length will be 0 and
9337 the address may end up as 0 if the section is discarded by ld
9338 --gc-sections, leaving an invalid (0, 0) entry that can be
9339 confused with the terminator. */
9340 if (text_section_used)
9342 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
9343 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
9344 text_section_label, "Length");
9346 if (cold_text_section_used)
9348 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
9350 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
9351 cold_text_section_label, "Length");
9354 if (have_multiple_function_sections)
9356 unsigned fde_idx = 0;
9358 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
9360 dw_fde_ref fde = &fde_table[fde_idx];
9362 if (!fde->in_std_section)
9364 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
9366 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
9367 fde->dw_fde_begin, "Length");
9369 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
9371 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
9373 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
9374 fde->dw_fde_second_begin, "Length");
9379 /* Output the terminator words. */
9380 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9381 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9384 /* Add a new entry to .debug_ranges. Return the offset at which it
9388 add_ranges_num (int num)
9390 unsigned int in_use = ranges_table_in_use;
9392 if (in_use == ranges_table_allocated)
9394 ranges_table_allocated += RANGES_TABLE_INCREMENT;
9395 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
9396 ranges_table_allocated);
9397 memset (ranges_table + ranges_table_in_use, 0,
9398 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
9401 ranges_table[in_use].num = num;
9402 ranges_table_in_use = in_use + 1;
9404 return in_use * 2 * DWARF2_ADDR_SIZE;
9407 /* Add a new entry to .debug_ranges corresponding to a block, or a
9408 range terminator if BLOCK is NULL. */
9411 add_ranges (const_tree block)
9413 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
9416 /* Add a new entry to .debug_ranges corresponding to a pair of
9420 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
9423 unsigned int in_use = ranges_by_label_in_use;
9424 unsigned int offset;
9426 if (in_use == ranges_by_label_allocated)
9428 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
9429 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
9431 ranges_by_label_allocated);
9432 memset (ranges_by_label + ranges_by_label_in_use, 0,
9433 RANGES_TABLE_INCREMENT
9434 * sizeof (struct dw_ranges_by_label_struct));
9437 ranges_by_label[in_use].begin = begin;
9438 ranges_by_label[in_use].end = end;
9439 ranges_by_label_in_use = in_use + 1;
9441 offset = add_ranges_num (-(int)in_use - 1);
9444 add_AT_range_list (die, DW_AT_ranges, offset);
9450 output_ranges (void)
9453 static const char *const start_fmt = "Offset %#x";
9454 const char *fmt = start_fmt;
9456 for (i = 0; i < ranges_table_in_use; i++)
9458 int block_num = ranges_table[i].num;
9462 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
9463 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
9465 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
9466 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
9468 /* If all code is in the text section, then the compilation
9469 unit base address defaults to DW_AT_low_pc, which is the
9470 base of the text section. */
9471 if (!have_multiple_function_sections)
9473 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
9475 fmt, i * 2 * DWARF2_ADDR_SIZE);
9476 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
9477 text_section_label, NULL);
9480 /* Otherwise, the compilation unit base address is zero,
9481 which allows us to use absolute addresses, and not worry
9482 about whether the target supports cross-section
9486 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
9487 fmt, i * 2 * DWARF2_ADDR_SIZE);
9488 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
9494 /* Negative block_num stands for an index into ranges_by_label. */
9495 else if (block_num < 0)
9497 int lab_idx = - block_num - 1;
9499 if (!have_multiple_function_sections)
9503 /* If we ever use add_ranges_by_labels () for a single
9504 function section, all we have to do is to take out
9506 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9507 ranges_by_label[lab_idx].begin,
9509 fmt, i * 2 * DWARF2_ADDR_SIZE);
9510 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9511 ranges_by_label[lab_idx].end,
9512 text_section_label, NULL);
9517 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9518 ranges_by_label[lab_idx].begin,
9519 fmt, i * 2 * DWARF2_ADDR_SIZE);
9520 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9521 ranges_by_label[lab_idx].end,
9527 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9528 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9534 /* Data structure containing information about input files. */
9537 const char *path; /* Complete file name. */
9538 const char *fname; /* File name part. */
9539 int length; /* Length of entire string. */
9540 struct dwarf_file_data * file_idx; /* Index in input file table. */
9541 int dir_idx; /* Index in directory table. */
9544 /* Data structure containing information about directories with source
9548 const char *path; /* Path including directory name. */
9549 int length; /* Path length. */
9550 int prefix; /* Index of directory entry which is a prefix. */
9551 int count; /* Number of files in this directory. */
9552 int dir_idx; /* Index of directory used as base. */
9555 /* Callback function for file_info comparison. We sort by looking at
9556 the directories in the path. */
9559 file_info_cmp (const void *p1, const void *p2)
9561 const struct file_info *const s1 = (const struct file_info *) p1;
9562 const struct file_info *const s2 = (const struct file_info *) p2;
9563 const unsigned char *cp1;
9564 const unsigned char *cp2;
9566 /* Take care of file names without directories. We need to make sure that
9567 we return consistent values to qsort since some will get confused if
9568 we return the same value when identical operands are passed in opposite
9569 orders. So if neither has a directory, return 0 and otherwise return
9570 1 or -1 depending on which one has the directory. */
9571 if ((s1->path == s1->fname || s2->path == s2->fname))
9572 return (s2->path == s2->fname) - (s1->path == s1->fname);
9574 cp1 = (const unsigned char *) s1->path;
9575 cp2 = (const unsigned char *) s2->path;
9581 /* Reached the end of the first path? If so, handle like above. */
9582 if ((cp1 == (const unsigned char *) s1->fname)
9583 || (cp2 == (const unsigned char *) s2->fname))
9584 return ((cp2 == (const unsigned char *) s2->fname)
9585 - (cp1 == (const unsigned char *) s1->fname));
9587 /* Character of current path component the same? */
9588 else if (*cp1 != *cp2)
9593 struct file_name_acquire_data
9595 struct file_info *files;
9600 /* Traversal function for the hash table. */
9603 file_name_acquire (void ** slot, void *data)
9605 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
9606 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
9607 struct file_info *fi;
9610 gcc_assert (fnad->max_files >= d->emitted_number);
9612 if (! d->emitted_number)
9615 gcc_assert (fnad->max_files != fnad->used_files);
9617 fi = fnad->files + fnad->used_files++;
9619 /* Skip all leading "./". */
9621 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
9624 /* Create a new array entry. */
9626 fi->length = strlen (f);
9629 /* Search for the file name part. */
9630 f = strrchr (f, DIR_SEPARATOR);
9631 #if defined (DIR_SEPARATOR_2)
9633 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
9637 if (f == NULL || f < g)
9643 fi->fname = f == NULL ? fi->path : f + 1;
9647 /* Output the directory table and the file name table. We try to minimize
9648 the total amount of memory needed. A heuristic is used to avoid large
9649 slowdowns with many input files. */
9652 output_file_names (void)
9654 struct file_name_acquire_data fnad;
9656 struct file_info *files;
9657 struct dir_info *dirs;
9665 if (!last_emitted_file)
9667 dw2_asm_output_data (1, 0, "End directory table");
9668 dw2_asm_output_data (1, 0, "End file name table");
9672 numfiles = last_emitted_file->emitted_number;
9674 /* Allocate the various arrays we need. */
9675 files = XALLOCAVEC (struct file_info, numfiles);
9676 dirs = XALLOCAVEC (struct dir_info, numfiles);
9679 fnad.used_files = 0;
9680 fnad.max_files = numfiles;
9681 htab_traverse (file_table, file_name_acquire, &fnad);
9682 gcc_assert (fnad.used_files == fnad.max_files);
9684 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
9686 /* Find all the different directories used. */
9687 dirs[0].path = files[0].path;
9688 dirs[0].length = files[0].fname - files[0].path;
9689 dirs[0].prefix = -1;
9691 dirs[0].dir_idx = 0;
9692 files[0].dir_idx = 0;
9695 for (i = 1; i < numfiles; i++)
9696 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
9697 && memcmp (dirs[ndirs - 1].path, files[i].path,
9698 dirs[ndirs - 1].length) == 0)
9700 /* Same directory as last entry. */
9701 files[i].dir_idx = ndirs - 1;
9702 ++dirs[ndirs - 1].count;
9708 /* This is a new directory. */
9709 dirs[ndirs].path = files[i].path;
9710 dirs[ndirs].length = files[i].fname - files[i].path;
9711 dirs[ndirs].count = 1;
9712 dirs[ndirs].dir_idx = ndirs;
9713 files[i].dir_idx = ndirs;
9715 /* Search for a prefix. */
9716 dirs[ndirs].prefix = -1;
9717 for (j = 0; j < ndirs; j++)
9718 if (dirs[j].length < dirs[ndirs].length
9719 && dirs[j].length > 1
9720 && (dirs[ndirs].prefix == -1
9721 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
9722 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
9723 dirs[ndirs].prefix = j;
9728 /* Now to the actual work. We have to find a subset of the directories which
9729 allow expressing the file name using references to the directory table
9730 with the least amount of characters. We do not do an exhaustive search
9731 where we would have to check out every combination of every single
9732 possible prefix. Instead we use a heuristic which provides nearly optimal
9733 results in most cases and never is much off. */
9734 saved = XALLOCAVEC (int, ndirs);
9735 savehere = XALLOCAVEC (int, ndirs);
9737 memset (saved, '\0', ndirs * sizeof (saved[0]));
9738 for (i = 0; i < ndirs; i++)
9743 /* We can always save some space for the current directory. But this
9744 does not mean it will be enough to justify adding the directory. */
9745 savehere[i] = dirs[i].length;
9746 total = (savehere[i] - saved[i]) * dirs[i].count;
9748 for (j = i + 1; j < ndirs; j++)
9751 if (saved[j] < dirs[i].length)
9753 /* Determine whether the dirs[i] path is a prefix of the
9758 while (k != -1 && k != (int) i)
9763 /* Yes it is. We can possibly save some memory by
9764 writing the filenames in dirs[j] relative to
9766 savehere[j] = dirs[i].length;
9767 total += (savehere[j] - saved[j]) * dirs[j].count;
9772 /* Check whether we can save enough to justify adding the dirs[i]
9774 if (total > dirs[i].length + 1)
9776 /* It's worthwhile adding. */
9777 for (j = i; j < ndirs; j++)
9778 if (savehere[j] > 0)
9780 /* Remember how much we saved for this directory so far. */
9781 saved[j] = savehere[j];
9783 /* Remember the prefix directory. */
9784 dirs[j].dir_idx = i;
9789 /* Emit the directory name table. */
9790 idx_offset = dirs[0].length > 0 ? 1 : 0;
9791 for (i = 1 - idx_offset; i < ndirs; i++)
9792 dw2_asm_output_nstring (dirs[i].path,
9794 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
9795 "Directory Entry: %#x", i + idx_offset);
9797 dw2_asm_output_data (1, 0, "End directory table");
9799 /* We have to emit them in the order of emitted_number since that's
9800 used in the debug info generation. To do this efficiently we
9801 generate a back-mapping of the indices first. */
9802 backmap = XALLOCAVEC (int, numfiles);
9803 for (i = 0; i < numfiles; i++)
9804 backmap[files[i].file_idx->emitted_number - 1] = i;
9806 /* Now write all the file names. */
9807 for (i = 0; i < numfiles; i++)
9809 int file_idx = backmap[i];
9810 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
9812 #ifdef VMS_DEBUGGING_INFO
9813 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9815 /* Setting these fields can lead to debugger miscomparisons,
9816 but VMS Debug requires them to be set correctly. */
9821 int maxfilelen = strlen (files[file_idx].path)
9822 + dirs[dir_idx].length
9823 + MAX_VMS_VERSION_LEN + 1;
9824 char *filebuf = XALLOCAVEC (char, maxfilelen);
9826 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
9827 snprintf (filebuf, maxfilelen, "%s;%d",
9828 files[file_idx].path + dirs[dir_idx].length, ver);
9830 dw2_asm_output_nstring
9831 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
9833 /* Include directory index. */
9834 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9836 /* Modification time. */
9837 dw2_asm_output_data_uleb128
9838 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
9842 /* File length in bytes. */
9843 dw2_asm_output_data_uleb128
9844 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
9848 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
9849 "File Entry: %#x", (unsigned) i + 1);
9851 /* Include directory index. */
9852 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9854 /* Modification time. */
9855 dw2_asm_output_data_uleb128 (0, NULL);
9857 /* File length in bytes. */
9858 dw2_asm_output_data_uleb128 (0, NULL);
9859 #endif /* VMS_DEBUGGING_INFO */
9862 dw2_asm_output_data (1, 0, "End file name table");
9866 /* Output one line number table into the .debug_line section. */
9869 output_one_line_info_table (dw_line_info_table *table)
9871 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9872 unsigned int current_line = 1;
9873 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
9874 dw_line_info_entry *ent;
9877 FOR_EACH_VEC_ELT (dw_line_info_entry, table->entries, i, ent)
9879 switch (ent->opcode)
9881 case LI_set_address:
9882 /* ??? Unfortunately, we have little choice here currently, and
9883 must always use the most general form. GCC does not know the
9884 address delta itself, so we can't use DW_LNS_advance_pc. Many
9885 ports do have length attributes which will give an upper bound
9886 on the address range. We could perhaps use length attributes
9887 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9888 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
9890 /* This can handle any delta. This takes
9891 4+DWARF2_ADDR_SIZE bytes. */
9892 dw2_asm_output_data (1, 0, "set address %s", line_label);
9893 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9894 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9895 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9899 if (ent->val == current_line)
9901 /* We still need to start a new row, so output a copy insn. */
9902 dw2_asm_output_data (1, DW_LNS_copy,
9903 "copy line %u", current_line);
9907 int line_offset = ent->val - current_line;
9908 int line_delta = line_offset - DWARF_LINE_BASE;
9910 current_line = ent->val;
9911 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9913 /* This can handle deltas from -10 to 234, using the current
9914 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9915 This takes 1 byte. */
9916 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9917 "line %u", current_line);
9921 /* This can handle any delta. This takes at least 4 bytes,
9922 depending on the value being encoded. */
9923 dw2_asm_output_data (1, DW_LNS_advance_line,
9924 "advance to line %u", current_line);
9925 dw2_asm_output_data_sleb128 (line_offset, NULL);
9926 dw2_asm_output_data (1, DW_LNS_copy, NULL);
9932 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
9933 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
9937 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
9938 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
9941 case LI_negate_stmt:
9942 current_is_stmt = !current_is_stmt;
9943 dw2_asm_output_data (1, DW_LNS_negate_stmt,
9944 "is_stmt %d", current_is_stmt);
9947 case LI_set_prologue_end:
9948 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
9949 "set prologue end");
9952 case LI_set_epilogue_begin:
9953 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
9954 "set epilogue begin");
9957 case LI_set_discriminator:
9958 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
9959 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
9960 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
9961 dw2_asm_output_data_uleb128 (ent->val, NULL);
9966 /* Emit debug info for the address of the end of the table. */
9967 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
9968 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9969 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9970 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
9972 dw2_asm_output_data (1, 0, "end sequence");
9973 dw2_asm_output_data_uleb128 (1, NULL);
9974 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9977 /* Output the source line number correspondence information. This
9978 information goes into the .debug_line section. */
9981 output_line_info (void)
9983 char l1[20], l2[20], p1[20], p2[20];
9984 int ver = dwarf_version;
9985 bool saw_one = false;
9988 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9989 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9990 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9991 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9993 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9994 dw2_asm_output_data (4, 0xffffffff,
9995 "Initial length escape value indicating 64-bit DWARF extension");
9996 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9997 "Length of Source Line Info");
9998 ASM_OUTPUT_LABEL (asm_out_file, l1);
10000 dw2_asm_output_data (2, ver, "DWARF Version");
10001 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
10002 ASM_OUTPUT_LABEL (asm_out_file, p1);
10004 /* Define the architecture-dependent minimum instruction length (in bytes).
10005 In this implementation of DWARF, this field is used for information
10006 purposes only. Since GCC generates assembly language, we have no
10007 a priori knowledge of how many instruction bytes are generated for each
10008 source line, and therefore can use only the DW_LNE_set_address and
10009 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10010 this as '1', which is "correct enough" for all architectures,
10011 and don't let the target override. */
10012 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10015 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
10016 "Maximum Operations Per Instruction");
10017 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
10018 "Default is_stmt_start flag");
10019 dw2_asm_output_data (1, DWARF_LINE_BASE,
10020 "Line Base Value (Special Opcodes)");
10021 dw2_asm_output_data (1, DWARF_LINE_RANGE,
10022 "Line Range Value (Special Opcodes)");
10023 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
10024 "Special Opcode Base");
10026 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
10031 case DW_LNS_advance_pc:
10032 case DW_LNS_advance_line:
10033 case DW_LNS_set_file:
10034 case DW_LNS_set_column:
10035 case DW_LNS_fixed_advance_pc:
10036 case DW_LNS_set_isa:
10044 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
10048 /* Write out the information about the files we use. */
10049 output_file_names ();
10050 ASM_OUTPUT_LABEL (asm_out_file, p2);
10052 if (separate_line_info)
10054 dw_line_info_table *table;
10057 FOR_EACH_VEC_ELT (dw_line_info_table_p, separate_line_info, i, table)
10060 output_one_line_info_table (table);
10064 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
10066 output_one_line_info_table (cold_text_section_line_info);
10070 /* ??? Some Darwin linkers crash on a .debug_line section with no
10071 sequences. Further, merely a DW_LNE_end_sequence entry is not
10072 sufficient -- the address column must also be initialized.
10073 Make sure to output at least one set_address/end_sequence pair,
10074 choosing .text since that section is always present. */
10075 if (text_section_line_info->in_use || !saw_one)
10076 output_one_line_info_table (text_section_line_info);
10078 /* Output the marker for the end of the line number info. */
10079 ASM_OUTPUT_LABEL (asm_out_file, l2);
10082 /* Given a pointer to a tree node for some base type, return a pointer to
10083 a DIE that describes the given type.
10085 This routine must only be called for GCC type nodes that correspond to
10086 Dwarf base (fundamental) types. */
10089 base_type_die (tree type)
10091 dw_die_ref base_type_result;
10092 enum dwarf_type encoding;
10094 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
10097 /* If this is a subtype that should not be emitted as a subrange type,
10098 use the base type. See subrange_type_for_debug_p. */
10099 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
10100 type = TREE_TYPE (type);
10102 switch (TREE_CODE (type))
10105 if ((dwarf_version >= 4 || !dwarf_strict)
10106 && TYPE_NAME (type)
10107 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10108 && DECL_IS_BUILTIN (TYPE_NAME (type))
10109 && DECL_NAME (TYPE_NAME (type)))
10111 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
10112 if (strcmp (name, "char16_t") == 0
10113 || strcmp (name, "char32_t") == 0)
10115 encoding = DW_ATE_UTF;
10119 if (TYPE_STRING_FLAG (type))
10121 if (TYPE_UNSIGNED (type))
10122 encoding = DW_ATE_unsigned_char;
10124 encoding = DW_ATE_signed_char;
10126 else if (TYPE_UNSIGNED (type))
10127 encoding = DW_ATE_unsigned;
10129 encoding = DW_ATE_signed;
10133 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
10135 if (dwarf_version >= 3 || !dwarf_strict)
10136 encoding = DW_ATE_decimal_float;
10138 encoding = DW_ATE_lo_user;
10141 encoding = DW_ATE_float;
10144 case FIXED_POINT_TYPE:
10145 if (!(dwarf_version >= 3 || !dwarf_strict))
10146 encoding = DW_ATE_lo_user;
10147 else if (TYPE_UNSIGNED (type))
10148 encoding = DW_ATE_unsigned_fixed;
10150 encoding = DW_ATE_signed_fixed;
10153 /* Dwarf2 doesn't know anything about complex ints, so use
10154 a user defined type for it. */
10156 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
10157 encoding = DW_ATE_complex_float;
10159 encoding = DW_ATE_lo_user;
10163 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10164 encoding = DW_ATE_boolean;
10168 /* No other TREE_CODEs are Dwarf fundamental types. */
10169 gcc_unreachable ();
10172 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
10174 add_AT_unsigned (base_type_result, DW_AT_byte_size,
10175 int_size_in_bytes (type));
10176 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
10178 return base_type_result;
10181 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10182 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10185 is_base_type (tree type)
10187 switch (TREE_CODE (type))
10193 case FIXED_POINT_TYPE:
10201 case QUAL_UNION_TYPE:
10202 case ENUMERAL_TYPE:
10203 case FUNCTION_TYPE:
10206 case REFERENCE_TYPE:
10214 gcc_unreachable ();
10220 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10221 node, return the size in bits for the type if it is a constant, or else
10222 return the alignment for the type if the type's size is not constant, or
10223 else return BITS_PER_WORD if the type actually turns out to be an
10224 ERROR_MARK node. */
10226 static inline unsigned HOST_WIDE_INT
10227 simple_type_size_in_bits (const_tree type)
10229 if (TREE_CODE (type) == ERROR_MARK)
10230 return BITS_PER_WORD;
10231 else if (TYPE_SIZE (type) == NULL_TREE)
10233 else if (host_integerp (TYPE_SIZE (type), 1))
10234 return tree_low_cst (TYPE_SIZE (type), 1);
10236 return TYPE_ALIGN (type);
10239 /* Similarly, but return a double_int instead of UHWI. */
10241 static inline double_int
10242 double_int_type_size_in_bits (const_tree type)
10244 if (TREE_CODE (type) == ERROR_MARK)
10245 return uhwi_to_double_int (BITS_PER_WORD);
10246 else if (TYPE_SIZE (type) == NULL_TREE)
10247 return double_int_zero;
10248 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
10249 return tree_to_double_int (TYPE_SIZE (type));
10251 return uhwi_to_double_int (TYPE_ALIGN (type));
10254 /* Given a pointer to a tree node for a subrange type, return a pointer
10255 to a DIE that describes the given type. */
10258 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
10260 dw_die_ref subrange_die;
10261 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
10263 if (context_die == NULL)
10264 context_die = comp_unit_die ();
10266 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
10268 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
10270 /* The size of the subrange type and its base type do not match,
10271 so we need to generate a size attribute for the subrange type. */
10272 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
10276 add_bound_info (subrange_die, DW_AT_lower_bound, low);
10278 add_bound_info (subrange_die, DW_AT_upper_bound, high);
10280 return subrange_die;
10283 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10284 entry that chains various modifiers in front of the given type. */
10287 modified_type_die (tree type, int is_const_type, int is_volatile_type,
10288 dw_die_ref context_die)
10290 enum tree_code code = TREE_CODE (type);
10291 dw_die_ref mod_type_die;
10292 dw_die_ref sub_die = NULL;
10293 tree item_type = NULL;
10294 tree qualified_type;
10295 tree name, low, high;
10297 if (code == ERROR_MARK)
10300 /* See if we already have the appropriately qualified variant of
10303 = get_qualified_type (type,
10304 ((is_const_type ? TYPE_QUAL_CONST : 0)
10305 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
10307 if (qualified_type == sizetype
10308 && TYPE_NAME (qualified_type)
10309 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
10311 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
10313 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
10314 && TYPE_PRECISION (t)
10315 == TYPE_PRECISION (qualified_type)
10316 && TYPE_UNSIGNED (t)
10317 == TYPE_UNSIGNED (qualified_type));
10318 qualified_type = t;
10321 /* If we do, then we can just use its DIE, if it exists. */
10322 if (qualified_type)
10324 mod_type_die = lookup_type_die (qualified_type);
10326 return mod_type_die;
10329 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
10331 /* Handle C typedef types. */
10332 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
10333 && !DECL_ARTIFICIAL (name))
10335 tree dtype = TREE_TYPE (name);
10337 if (qualified_type == dtype)
10339 /* For a named type, use the typedef. */
10340 gen_type_die (qualified_type, context_die);
10341 return lookup_type_die (qualified_type);
10343 else if (is_const_type < TYPE_READONLY (dtype)
10344 || is_volatile_type < TYPE_VOLATILE (dtype)
10345 || (is_const_type <= TYPE_READONLY (dtype)
10346 && is_volatile_type <= TYPE_VOLATILE (dtype)
10347 && DECL_ORIGINAL_TYPE (name) != type))
10348 /* cv-unqualified version of named type. Just use the unnamed
10349 type to which it refers. */
10350 return modified_type_die (DECL_ORIGINAL_TYPE (name),
10351 is_const_type, is_volatile_type,
10353 /* Else cv-qualified version of named type; fall through. */
10357 /* If both is_const_type and is_volatile_type, prefer the path
10358 which leads to a qualified type. */
10359 && (!is_volatile_type
10360 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
10361 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
10363 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
10364 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
10366 else if (is_volatile_type)
10368 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
10369 sub_die = modified_type_die (type, is_const_type, 0, context_die);
10371 else if (code == POINTER_TYPE)
10373 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
10374 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10375 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10376 item_type = TREE_TYPE (type);
10377 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
10378 add_AT_unsigned (mod_type_die, DW_AT_address_class,
10379 TYPE_ADDR_SPACE (item_type));
10381 else if (code == REFERENCE_TYPE)
10383 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
10384 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
10387 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
10388 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10389 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10390 item_type = TREE_TYPE (type);
10391 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
10392 add_AT_unsigned (mod_type_die, DW_AT_address_class,
10393 TYPE_ADDR_SPACE (item_type));
10395 else if (code == INTEGER_TYPE
10396 && TREE_TYPE (type) != NULL_TREE
10397 && subrange_type_for_debug_p (type, &low, &high))
10399 mod_type_die = subrange_type_die (type, low, high, context_die);
10400 item_type = TREE_TYPE (type);
10402 else if (is_base_type (type))
10403 mod_type_die = base_type_die (type);
10406 gen_type_die (type, context_die);
10408 /* We have to get the type_main_variant here (and pass that to the
10409 `lookup_type_die' routine) because the ..._TYPE node we have
10410 might simply be a *copy* of some original type node (where the
10411 copy was created to help us keep track of typedef names) and
10412 that copy might have a different TYPE_UID from the original
10414 if (TREE_CODE (type) != VECTOR_TYPE)
10415 return lookup_type_die (type_main_variant (type));
10417 /* Vectors have the debugging information in the type,
10418 not the main variant. */
10419 return lookup_type_die (type);
10422 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10423 don't output a DW_TAG_typedef, since there isn't one in the
10424 user's program; just attach a DW_AT_name to the type.
10425 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10426 if the base type already has the same name. */
10428 && ((TREE_CODE (name) != TYPE_DECL
10429 && (qualified_type == TYPE_MAIN_VARIANT (type)
10430 || (!is_const_type && !is_volatile_type)))
10431 || (TREE_CODE (name) == TYPE_DECL
10432 && TREE_TYPE (name) == qualified_type
10433 && DECL_NAME (name))))
10435 if (TREE_CODE (name) == TYPE_DECL)
10436 /* Could just call add_name_and_src_coords_attributes here,
10437 but since this is a builtin type it doesn't have any
10438 useful source coordinates anyway. */
10439 name = DECL_NAME (name);
10440 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
10441 add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
10442 if (TYPE_ARTIFICIAL (type))
10443 add_AT_flag (mod_type_die, DW_AT_artificial, 1);
10445 /* This probably indicates a bug. */
10446 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
10447 add_name_attribute (mod_type_die, "__unknown__");
10449 if (qualified_type)
10450 equate_type_number_to_die (qualified_type, mod_type_die);
10453 /* We must do this after the equate_type_number_to_die call, in case
10454 this is a recursive type. This ensures that the modified_type_die
10455 recursion will terminate even if the type is recursive. Recursive
10456 types are possible in Ada. */
10457 sub_die = modified_type_die (item_type,
10458 TYPE_READONLY (item_type),
10459 TYPE_VOLATILE (item_type),
10462 if (sub_die != NULL)
10463 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
10465 return mod_type_die;
10468 /* Generate DIEs for the generic parameters of T.
10469 T must be either a generic type or a generic function.
10470 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10473 gen_generic_params_dies (tree t)
10477 dw_die_ref die = NULL;
10479 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
10483 die = lookup_type_die (t);
10484 else if (DECL_P (t))
10485 die = lookup_decl_die (t);
10489 parms = lang_hooks.get_innermost_generic_parms (t);
10491 /* T has no generic parameter. It means T is neither a generic type
10492 or function. End of story. */
10495 parms_num = TREE_VEC_LENGTH (parms);
10496 args = lang_hooks.get_innermost_generic_args (t);
10497 for (i = 0; i < parms_num; i++)
10499 tree parm, arg, arg_pack_elems;
10501 parm = TREE_VEC_ELT (parms, i);
10502 arg = TREE_VEC_ELT (args, i);
10503 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
10504 gcc_assert (parm && TREE_VALUE (parm) && arg);
10506 if (parm && TREE_VALUE (parm) && arg)
10508 /* If PARM represents a template parameter pack,
10509 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10510 by DW_TAG_template_*_parameter DIEs for the argument
10511 pack elements of ARG. Note that ARG would then be
10512 an argument pack. */
10513 if (arg_pack_elems)
10514 template_parameter_pack_die (TREE_VALUE (parm),
10518 generic_parameter_die (TREE_VALUE (parm), arg,
10519 true /* Emit DW_AT_name */, die);
10524 /* Create and return a DIE for PARM which should be
10525 the representation of a generic type parameter.
10526 For instance, in the C++ front end, PARM would be a template parameter.
10527 ARG is the argument to PARM.
10528 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10530 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10531 as a child node. */
10534 generic_parameter_die (tree parm, tree arg,
10536 dw_die_ref parent_die)
10538 dw_die_ref tmpl_die = NULL;
10539 const char *name = NULL;
10541 if (!parm || !DECL_NAME (parm) || !arg)
10544 /* We support non-type generic parameters and arguments,
10545 type generic parameters and arguments, as well as
10546 generic generic parameters (a.k.a. template template parameters in C++)
10548 if (TREE_CODE (parm) == PARM_DECL)
10549 /* PARM is a nontype generic parameter */
10550 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
10551 else if (TREE_CODE (parm) == TYPE_DECL)
10552 /* PARM is a type generic parameter. */
10553 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
10554 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10555 /* PARM is a generic generic parameter.
10556 Its DIE is a GNU extension. It shall have a
10557 DW_AT_name attribute to represent the name of the template template
10558 parameter, and a DW_AT_GNU_template_name attribute to represent the
10559 name of the template template argument. */
10560 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
10563 gcc_unreachable ();
10569 /* If PARM is a generic parameter pack, it means we are
10570 emitting debug info for a template argument pack element.
10571 In other terms, ARG is a template argument pack element.
10572 In that case, we don't emit any DW_AT_name attribute for
10576 name = IDENTIFIER_POINTER (DECL_NAME (parm));
10578 add_AT_string (tmpl_die, DW_AT_name, name);
10581 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10583 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10584 TMPL_DIE should have a child DW_AT_type attribute that is set
10585 to the type of the argument to PARM, which is ARG.
10586 If PARM is a type generic parameter, TMPL_DIE should have a
10587 child DW_AT_type that is set to ARG. */
10588 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
10589 add_type_attribute (tmpl_die, tmpl_type, 0,
10590 TREE_THIS_VOLATILE (tmpl_type),
10595 /* So TMPL_DIE is a DIE representing a
10596 a generic generic template parameter, a.k.a template template
10597 parameter in C++ and arg is a template. */
10599 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10600 to the name of the argument. */
10601 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
10603 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
10606 if (TREE_CODE (parm) == PARM_DECL)
10607 /* So PARM is a non-type generic parameter.
10608 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10609 attribute of TMPL_DIE which value represents the value
10611 We must be careful here:
10612 The value of ARG might reference some function decls.
10613 We might currently be emitting debug info for a generic
10614 type and types are emitted before function decls, we don't
10615 know if the function decls referenced by ARG will actually be
10616 emitted after cgraph computations.
10617 So must defer the generation of the DW_AT_const_value to
10618 after cgraph is ready. */
10619 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
10625 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10626 PARM_PACK must be a template parameter pack. The returned DIE
10627 will be child DIE of PARENT_DIE. */
10630 template_parameter_pack_die (tree parm_pack,
10631 tree parm_pack_args,
10632 dw_die_ref parent_die)
10637 gcc_assert (parent_die && parm_pack);
10639 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
10640 add_name_and_src_coords_attributes (die, parm_pack);
10641 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
10642 generic_parameter_die (parm_pack,
10643 TREE_VEC_ELT (parm_pack_args, j),
10644 false /* Don't emit DW_AT_name */,
10649 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10650 an enumerated type. */
10653 type_is_enum (const_tree type)
10655 return TREE_CODE (type) == ENUMERAL_TYPE;
10658 /* Return the DBX register number described by a given RTL node. */
10660 static unsigned int
10661 dbx_reg_number (const_rtx rtl)
10663 unsigned regno = REGNO (rtl);
10665 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
10667 #ifdef LEAF_REG_REMAP
10668 if (current_function_uses_only_leaf_regs)
10670 int leaf_reg = LEAF_REG_REMAP (regno);
10671 if (leaf_reg != -1)
10672 regno = (unsigned) leaf_reg;
10676 return DBX_REGISTER_NUMBER (regno);
10679 /* Optionally add a DW_OP_piece term to a location description expression.
10680 DW_OP_piece is only added if the location description expression already
10681 doesn't end with DW_OP_piece. */
10684 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
10686 dw_loc_descr_ref loc;
10688 if (*list_head != NULL)
10690 /* Find the end of the chain. */
10691 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
10694 if (loc->dw_loc_opc != DW_OP_piece)
10695 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
10699 /* Return a location descriptor that designates a machine register or
10700 zero if there is none. */
10702 static dw_loc_descr_ref
10703 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
10707 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
10710 /* We only use "frame base" when we're sure we're talking about the
10711 post-prologue local stack frame. We do this by *not* running
10712 register elimination until this point, and recognizing the special
10713 argument pointer and soft frame pointer rtx's.
10714 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10715 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
10716 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
10718 dw_loc_descr_ref result = NULL;
10720 if (dwarf_version >= 4 || !dwarf_strict)
10722 result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
10725 add_loc_descr (&result,
10726 new_loc_descr (DW_OP_stack_value, 0, 0));
10731 regs = targetm.dwarf_register_span (rtl);
10733 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
10734 return multiple_reg_loc_descriptor (rtl, regs, initialized);
10736 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
10739 /* Return a location descriptor that designates a machine register for
10740 a given hard register number. */
10742 static dw_loc_descr_ref
10743 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
10745 dw_loc_descr_ref reg_loc_descr;
10749 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
10751 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
10753 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10754 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10756 return reg_loc_descr;
10759 /* Given an RTL of a register, return a location descriptor that
10760 designates a value that spans more than one register. */
10762 static dw_loc_descr_ref
10763 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
10764 enum var_init_status initialized)
10766 int nregs, size, i;
10768 dw_loc_descr_ref loc_result = NULL;
10771 #ifdef LEAF_REG_REMAP
10772 if (current_function_uses_only_leaf_regs)
10774 int leaf_reg = LEAF_REG_REMAP (reg);
10775 if (leaf_reg != -1)
10776 reg = (unsigned) leaf_reg;
10779 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
10780 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
10782 /* Simple, contiguous registers. */
10783 if (regs == NULL_RTX)
10785 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
10790 dw_loc_descr_ref t;
10792 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
10793 VAR_INIT_STATUS_INITIALIZED);
10794 add_loc_descr (&loc_result, t);
10795 add_loc_descr_op_piece (&loc_result, size);
10801 /* Now onto stupid register sets in non contiguous locations. */
10803 gcc_assert (GET_CODE (regs) == PARALLEL);
10805 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10808 for (i = 0; i < XVECLEN (regs, 0); ++i)
10810 dw_loc_descr_ref t;
10812 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
10813 VAR_INIT_STATUS_INITIALIZED);
10814 add_loc_descr (&loc_result, t);
10815 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10816 add_loc_descr_op_piece (&loc_result, size);
10819 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10820 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10824 /* Return a location descriptor that designates a constant. */
10826 static dw_loc_descr_ref
10827 int_loc_descriptor (HOST_WIDE_INT i)
10829 enum dwarf_location_atom op;
10831 /* Pick the smallest representation of a constant, rather than just
10832 defaulting to the LEB encoding. */
10836 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
10837 else if (i <= 0xff)
10838 op = DW_OP_const1u;
10839 else if (i <= 0xffff)
10840 op = DW_OP_const2u;
10841 else if (HOST_BITS_PER_WIDE_INT == 32
10842 || i <= 0xffffffff)
10843 op = DW_OP_const4u;
10850 op = DW_OP_const1s;
10851 else if (i >= -0x8000)
10852 op = DW_OP_const2s;
10853 else if (HOST_BITS_PER_WIDE_INT == 32
10854 || i >= -0x80000000)
10855 op = DW_OP_const4s;
10860 return new_loc_descr (op, i, 0);
10863 /* Return loc description representing "address" of integer value.
10864 This can appear only as toplevel expression. */
10866 static dw_loc_descr_ref
10867 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
10870 dw_loc_descr_ref loc_result = NULL;
10872 if (!(dwarf_version >= 4 || !dwarf_strict))
10879 else if (i <= 0xff)
10881 else if (i <= 0xffff)
10883 else if (HOST_BITS_PER_WIDE_INT == 32
10884 || i <= 0xffffffff)
10887 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
10893 else if (i >= -0x8000)
10895 else if (HOST_BITS_PER_WIDE_INT == 32
10896 || i >= -0x80000000)
10899 litsize = 1 + size_of_sleb128 (i);
10901 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10902 is more compact. For DW_OP_stack_value we need:
10903 litsize + 1 (DW_OP_stack_value)
10904 and for DW_OP_implicit_value:
10905 1 (DW_OP_implicit_value) + 1 (length) + size. */
10906 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
10908 loc_result = int_loc_descriptor (i);
10909 add_loc_descr (&loc_result,
10910 new_loc_descr (DW_OP_stack_value, 0, 0));
10914 loc_result = new_loc_descr (DW_OP_implicit_value,
10916 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
10917 loc_result->dw_loc_oprnd2.v.val_int = i;
10921 /* Return a location descriptor that designates a base+offset location. */
10923 static dw_loc_descr_ref
10924 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
10925 enum var_init_status initialized)
10927 unsigned int regno;
10928 dw_loc_descr_ref result;
10929 dw_fde_ref fde = current_fde ();
10931 /* We only use "frame base" when we're sure we're talking about the
10932 post-prologue local stack frame. We do this by *not* running
10933 register elimination until this point, and recognizing the special
10934 argument pointer and soft frame pointer rtx's. */
10935 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
10937 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10941 if (GET_CODE (elim) == PLUS)
10943 offset += INTVAL (XEXP (elim, 1));
10944 elim = XEXP (elim, 0);
10946 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10947 && (elim == hard_frame_pointer_rtx
10948 || elim == stack_pointer_rtx))
10949 || elim == (frame_pointer_needed
10950 ? hard_frame_pointer_rtx
10951 : stack_pointer_rtx));
10953 /* If drap register is used to align stack, use frame
10954 pointer + offset to access stack variables. If stack
10955 is aligned without drap, use stack pointer + offset to
10956 access stack variables. */
10957 if (crtl->stack_realign_tried
10958 && reg == frame_pointer_rtx)
10961 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
10962 ? HARD_FRAME_POINTER_REGNUM
10964 return new_reg_loc_descr (base_reg, offset);
10967 gcc_assert (frame_pointer_fb_offset_valid);
10968 offset += frame_pointer_fb_offset;
10969 return new_loc_descr (DW_OP_fbreg, offset, 0);
10974 && (fde->drap_reg == REGNO (reg)
10975 || fde->vdrap_reg == REGNO (reg)))
10977 /* Use cfa+offset to represent the location of arguments passed
10978 on the stack when drap is used to align stack.
10979 Only do this when not optimizing, for optimized code var-tracking
10980 is supposed to track where the arguments live and the register
10981 used as vdrap or drap in some spot might be used for something
10982 else in other part of the routine. */
10983 return new_loc_descr (DW_OP_fbreg, offset, 0);
10986 regno = dbx_reg_number (reg);
10988 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
10991 result = new_loc_descr (DW_OP_bregx, regno, offset);
10993 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10994 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10999 /* Return true if this RTL expression describes a base+offset calculation. */
11002 is_based_loc (const_rtx rtl)
11004 return (GET_CODE (rtl) == PLUS
11005 && ((REG_P (XEXP (rtl, 0))
11006 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
11007 && CONST_INT_P (XEXP (rtl, 1)))));
11010 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11013 static dw_loc_descr_ref
11014 tls_mem_loc_descriptor (rtx mem)
11017 dw_loc_descr_ref loc_result;
11019 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
11022 base = get_base_address (MEM_EXPR (mem));
11024 || TREE_CODE (base) != VAR_DECL
11025 || !DECL_THREAD_LOCAL_P (base))
11028 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
11029 if (loc_result == NULL)
11032 if (INTVAL (MEM_OFFSET (mem)))
11033 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
11038 /* Output debug info about reason why we failed to expand expression as dwarf
11042 expansion_failed (tree expr, rtx rtl, char const *reason)
11044 if (dump_file && (dump_flags & TDF_DETAILS))
11046 fprintf (dump_file, "Failed to expand as dwarf: ");
11048 print_generic_expr (dump_file, expr, dump_flags);
11051 fprintf (dump_file, "\n");
11052 print_rtl (dump_file, rtl);
11054 fprintf (dump_file, "\nReason: %s\n", reason);
11058 /* Helper function for const_ok_for_output, called either directly
11059 or via for_each_rtx. */
11062 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
11066 if (GET_CODE (rtl) == UNSPEC)
11068 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11069 we can't express it in the debug info. */
11070 #ifdef ENABLE_CHECKING
11071 /* Don't complain about TLS UNSPECs, those are just too hard to
11073 if (XVECLEN (rtl, 0) != 1
11074 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
11075 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
11076 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
11077 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
11078 inform (current_function_decl
11079 ? DECL_SOURCE_LOCATION (current_function_decl)
11080 : UNKNOWN_LOCATION,
11081 #if NUM_UNSPEC_VALUES > 0
11082 "non-delegitimized UNSPEC %s (%d) found in variable location",
11083 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
11084 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
11087 "non-delegitimized UNSPEC %d found in variable location",
11091 expansion_failed (NULL_TREE, rtl,
11092 "UNSPEC hasn't been delegitimized.\n");
11096 if (GET_CODE (rtl) != SYMBOL_REF)
11099 if (CONSTANT_POOL_ADDRESS_P (rtl))
11102 get_pool_constant_mark (rtl, &marked);
11103 /* If all references to this pool constant were optimized away,
11104 it was not output and thus we can't represent it. */
11107 expansion_failed (NULL_TREE, rtl,
11108 "Constant was removed from constant pool.\n");
11113 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11116 /* Avoid references to external symbols in debug info, on several targets
11117 the linker might even refuse to link when linking a shared library,
11118 and in many other cases the relocations for .debug_info/.debug_loc are
11119 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11120 to be defined within the same shared library or executable are fine. */
11121 if (SYMBOL_REF_EXTERNAL_P (rtl))
11123 tree decl = SYMBOL_REF_DECL (rtl);
11125 if (decl == NULL || !targetm.binds_local_p (decl))
11127 expansion_failed (NULL_TREE, rtl,
11128 "Symbol not defined in current TU.\n");
11136 /* Return true if constant RTL can be emitted in DW_OP_addr or
11137 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11138 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11141 const_ok_for_output (rtx rtl)
11143 if (GET_CODE (rtl) == SYMBOL_REF)
11144 return const_ok_for_output_1 (&rtl, NULL) == 0;
11146 if (GET_CODE (rtl) == CONST)
11147 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
11152 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11153 if possible, NULL otherwise. */
11156 base_type_for_mode (enum machine_mode mode, bool unsignedp)
11158 dw_die_ref type_die;
11159 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
11163 switch (TREE_CODE (type))
11171 type_die = lookup_type_die (type);
11173 type_die = modified_type_die (type, false, false, comp_unit_die ());
11174 if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
11179 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11180 type matching MODE, or, if MODE is narrower than or as wide as
11181 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11184 static dw_loc_descr_ref
11185 convert_descriptor_to_mode (enum machine_mode mode, dw_loc_descr_ref op)
11187 enum machine_mode outer_mode = mode;
11188 dw_die_ref type_die;
11189 dw_loc_descr_ref cvt;
11191 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
11193 add_loc_descr (&op, new_loc_descr (DW_OP_GNU_convert, 0, 0));
11196 type_die = base_type_for_mode (outer_mode, 1);
11197 if (type_die == NULL)
11199 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11200 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11201 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11202 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11203 add_loc_descr (&op, cvt);
11207 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11209 static dw_loc_descr_ref
11210 compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
11211 dw_loc_descr_ref op1)
11213 dw_loc_descr_ref ret = op0;
11214 add_loc_descr (&ret, op1);
11215 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
11216 if (STORE_FLAG_VALUE != 1)
11218 add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
11219 add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
11224 /* Return location descriptor for signed comparison OP RTL. */
11226 static dw_loc_descr_ref
11227 scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
11228 enum machine_mode mem_mode)
11230 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
11231 dw_loc_descr_ref op0, op1;
11234 if (op_mode == VOIDmode)
11235 op_mode = GET_MODE (XEXP (rtl, 1));
11236 if (op_mode == VOIDmode)
11240 && (GET_MODE_CLASS (op_mode) != MODE_INT
11241 || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
11244 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
11245 VAR_INIT_STATUS_INITIALIZED);
11246 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
11247 VAR_INIT_STATUS_INITIALIZED);
11249 if (op0 == NULL || op1 == NULL)
11252 if (GET_MODE_CLASS (op_mode) != MODE_INT
11253 || GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
11254 return compare_loc_descriptor (op, op0, op1);
11256 if (GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
11258 dw_die_ref type_die = base_type_for_mode (op_mode, 0);
11259 dw_loc_descr_ref cvt;
11261 if (type_die == NULL)
11263 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11264 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11265 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11266 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11267 add_loc_descr (&op0, cvt);
11268 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11269 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11270 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11271 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11272 add_loc_descr (&op1, cvt);
11273 return compare_loc_descriptor (op, op0, op1);
11276 shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
11277 /* For eq/ne, if the operands are known to be zero-extended,
11278 there is no need to do the fancy shifting up. */
11279 if (op == DW_OP_eq || op == DW_OP_ne)
11281 dw_loc_descr_ref last0, last1;
11282 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
11284 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
11286 /* deref_size zero extends, and for constants we can check
11287 whether they are zero extended or not. */
11288 if (((last0->dw_loc_opc == DW_OP_deref_size
11289 && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
11290 || (CONST_INT_P (XEXP (rtl, 0))
11291 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
11292 == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
11293 && ((last1->dw_loc_opc == DW_OP_deref_size
11294 && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
11295 || (CONST_INT_P (XEXP (rtl, 1))
11296 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
11297 == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
11298 return compare_loc_descriptor (op, op0, op1);
11300 add_loc_descr (&op0, int_loc_descriptor (shift));
11301 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
11302 if (CONST_INT_P (XEXP (rtl, 1)))
11303 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
11306 add_loc_descr (&op1, int_loc_descriptor (shift));
11307 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
11309 return compare_loc_descriptor (op, op0, op1);
11312 /* Return location descriptor for unsigned comparison OP RTL. */
11314 static dw_loc_descr_ref
11315 ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
11316 enum machine_mode mem_mode)
11318 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
11319 dw_loc_descr_ref op0, op1;
11321 if (op_mode == VOIDmode)
11322 op_mode = GET_MODE (XEXP (rtl, 1));
11323 if (op_mode == VOIDmode)
11325 if (GET_MODE_CLASS (op_mode) != MODE_INT)
11328 if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
11331 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
11332 VAR_INIT_STATUS_INITIALIZED);
11333 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
11334 VAR_INIT_STATUS_INITIALIZED);
11336 if (op0 == NULL || op1 == NULL)
11339 if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
11341 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
11342 dw_loc_descr_ref last0, last1;
11343 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
11345 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
11347 if (CONST_INT_P (XEXP (rtl, 0)))
11348 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
11349 /* deref_size zero extends, so no need to mask it again. */
11350 else if (last0->dw_loc_opc != DW_OP_deref_size
11351 || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
11353 add_loc_descr (&op0, int_loc_descriptor (mask));
11354 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
11356 if (CONST_INT_P (XEXP (rtl, 1)))
11357 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
11358 /* deref_size zero extends, so no need to mask it again. */
11359 else if (last1->dw_loc_opc != DW_OP_deref_size
11360 || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
11362 add_loc_descr (&op1, int_loc_descriptor (mask));
11363 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
11366 else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
11368 HOST_WIDE_INT bias = 1;
11369 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
11370 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11371 if (CONST_INT_P (XEXP (rtl, 1)))
11372 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
11373 + INTVAL (XEXP (rtl, 1)));
11375 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
11378 return compare_loc_descriptor (op, op0, op1);
11381 /* Return location descriptor for {U,S}{MIN,MAX}. */
11383 static dw_loc_descr_ref
11384 minmax_loc_descriptor (rtx rtl, enum machine_mode mode,
11385 enum machine_mode mem_mode)
11387 enum dwarf_location_atom op;
11388 dw_loc_descr_ref op0, op1, ret;
11389 dw_loc_descr_ref bra_node, drop_node;
11392 && (GET_MODE_CLASS (mode) != MODE_INT
11393 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
11396 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11397 VAR_INIT_STATUS_INITIALIZED);
11398 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11399 VAR_INIT_STATUS_INITIALIZED);
11401 if (op0 == NULL || op1 == NULL)
11404 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
11405 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
11406 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
11407 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
11409 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
11411 HOST_WIDE_INT mask = GET_MODE_MASK (mode);
11412 add_loc_descr (&op0, int_loc_descriptor (mask));
11413 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
11414 add_loc_descr (&op1, int_loc_descriptor (mask));
11415 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
11417 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
11419 HOST_WIDE_INT bias = 1;
11420 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
11421 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11422 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11425 else if (GET_MODE_CLASS (mode) == MODE_INT
11426 && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
11428 int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode)) * BITS_PER_UNIT;
11429 add_loc_descr (&op0, int_loc_descriptor (shift));
11430 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
11431 add_loc_descr (&op1, int_loc_descriptor (shift));
11432 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
11434 else if (GET_MODE_CLASS (mode) == MODE_INT
11435 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11437 dw_die_ref type_die = base_type_for_mode (mode, 0);
11438 dw_loc_descr_ref cvt;
11439 if (type_die == NULL)
11441 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11442 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11443 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11444 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11445 add_loc_descr (&op0, cvt);
11446 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11447 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11448 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11449 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11450 add_loc_descr (&op1, cvt);
11453 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
11458 add_loc_descr (&ret, op1);
11459 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
11460 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
11461 add_loc_descr (&ret, bra_node);
11462 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11463 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
11464 add_loc_descr (&ret, drop_node);
11465 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11466 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
11467 if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
11468 && GET_MODE_CLASS (mode) == MODE_INT
11469 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11470 ret = convert_descriptor_to_mode (mode, ret);
11474 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11475 but after converting arguments to type_die, afterwards
11476 convert back to unsigned. */
11478 static dw_loc_descr_ref
11479 typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
11480 enum machine_mode mode, enum machine_mode mem_mode)
11482 dw_loc_descr_ref cvt, op0, op1;
11484 if (type_die == NULL)
11486 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11487 VAR_INIT_STATUS_INITIALIZED);
11488 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11489 VAR_INIT_STATUS_INITIALIZED);
11490 if (op0 == NULL || op1 == NULL)
11492 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11493 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11494 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11495 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11496 add_loc_descr (&op0, cvt);
11497 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11498 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11499 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11500 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11501 add_loc_descr (&op1, cvt);
11502 add_loc_descr (&op0, op1);
11503 add_loc_descr (&op0, new_loc_descr (op, 0, 0));
11504 return convert_descriptor_to_mode (mode, op0);
11507 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11508 const0 is DW_OP_lit0 or corresponding typed constant,
11509 const1 is DW_OP_lit1 or corresponding typed constant
11510 and constMSB is constant with just the MSB bit set
11512 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11513 L1: const0 DW_OP_swap
11514 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11515 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11520 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11521 L1: const0 DW_OP_swap
11522 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11523 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11528 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11529 L1: const1 DW_OP_swap
11530 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11531 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11535 static dw_loc_descr_ref
11536 clz_loc_descriptor (rtx rtl, enum machine_mode mode,
11537 enum machine_mode mem_mode)
11539 dw_loc_descr_ref op0, ret, tmp;
11540 HOST_WIDE_INT valv;
11541 dw_loc_descr_ref l1jump, l1label;
11542 dw_loc_descr_ref l2jump, l2label;
11543 dw_loc_descr_ref l3jump, l3label;
11544 dw_loc_descr_ref l4jump, l4label;
11547 if (GET_MODE_CLASS (mode) != MODE_INT
11548 || GET_MODE (XEXP (rtl, 0)) != mode
11549 || (GET_CODE (rtl) == CLZ
11550 && GET_MODE_BITSIZE (mode) > 2 * HOST_BITS_PER_WIDE_INT))
11553 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11554 VAR_INIT_STATUS_INITIALIZED);
11558 if (GET_CODE (rtl) == CLZ)
11560 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
11561 valv = GET_MODE_BITSIZE (mode);
11563 else if (GET_CODE (rtl) == FFS)
11565 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
11566 valv = GET_MODE_BITSIZE (mode);
11567 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11568 l1jump = new_loc_descr (DW_OP_bra, 0, 0);
11569 add_loc_descr (&ret, l1jump);
11570 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
11571 tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
11572 VAR_INIT_STATUS_INITIALIZED);
11575 add_loc_descr (&ret, tmp);
11576 l4jump = new_loc_descr (DW_OP_skip, 0, 0);
11577 add_loc_descr (&ret, l4jump);
11578 l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
11579 ? const1_rtx : const0_rtx,
11581 VAR_INIT_STATUS_INITIALIZED);
11582 if (l1label == NULL)
11584 add_loc_descr (&ret, l1label);
11585 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11586 l2label = new_loc_descr (DW_OP_dup, 0, 0);
11587 add_loc_descr (&ret, l2label);
11588 if (GET_CODE (rtl) != CLZ)
11590 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
11591 msb = GEN_INT ((unsigned HOST_WIDE_INT) 1
11592 << (GET_MODE_BITSIZE (mode) - 1));
11594 msb = immed_double_const (0, (unsigned HOST_WIDE_INT) 1
11595 << (GET_MODE_BITSIZE (mode)
11596 - HOST_BITS_PER_WIDE_INT - 1), mode);
11597 if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
11598 tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
11599 ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
11600 ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
11602 tmp = mem_loc_descriptor (msb, mode, mem_mode,
11603 VAR_INIT_STATUS_INITIALIZED);
11606 add_loc_descr (&ret, tmp);
11607 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11608 l3jump = new_loc_descr (DW_OP_bra, 0, 0);
11609 add_loc_descr (&ret, l3jump);
11610 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11611 VAR_INIT_STATUS_INITIALIZED);
11614 add_loc_descr (&ret, tmp);
11615 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
11616 ? DW_OP_shl : DW_OP_shr, 0, 0));
11617 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11618 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
11619 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11620 l2jump = new_loc_descr (DW_OP_skip, 0, 0);
11621 add_loc_descr (&ret, l2jump);
11622 l3label = new_loc_descr (DW_OP_drop, 0, 0);
11623 add_loc_descr (&ret, l3label);
11624 l4label = new_loc_descr (DW_OP_nop, 0, 0);
11625 add_loc_descr (&ret, l4label);
11626 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11627 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11628 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11629 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11630 l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11631 l3jump->dw_loc_oprnd1.v.val_loc = l3label;
11632 l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11633 l4jump->dw_loc_oprnd1.v.val_loc = l4label;
11637 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11638 const1 is DW_OP_lit1 or corresponding typed constant):
11640 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11641 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11645 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11646 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11649 static dw_loc_descr_ref
11650 popcount_loc_descriptor (rtx rtl, enum machine_mode mode,
11651 enum machine_mode mem_mode)
11653 dw_loc_descr_ref op0, ret, tmp;
11654 dw_loc_descr_ref l1jump, l1label;
11655 dw_loc_descr_ref l2jump, l2label;
11657 if (GET_MODE_CLASS (mode) != MODE_INT
11658 || GET_MODE (XEXP (rtl, 0)) != mode)
11661 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11662 VAR_INIT_STATUS_INITIALIZED);
11666 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11667 VAR_INIT_STATUS_INITIALIZED);
11670 add_loc_descr (&ret, tmp);
11671 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11672 l1label = new_loc_descr (DW_OP_dup, 0, 0);
11673 add_loc_descr (&ret, l1label);
11674 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
11675 add_loc_descr (&ret, l2jump);
11676 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11677 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
11678 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11679 VAR_INIT_STATUS_INITIALIZED);
11682 add_loc_descr (&ret, tmp);
11683 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11684 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
11685 ? DW_OP_plus : DW_OP_xor, 0, 0));
11686 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11687 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11688 VAR_INIT_STATUS_INITIALIZED);
11689 add_loc_descr (&ret, tmp);
11690 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11691 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
11692 add_loc_descr (&ret, l1jump);
11693 l2label = new_loc_descr (DW_OP_drop, 0, 0);
11694 add_loc_descr (&ret, l2label);
11695 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11696 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11697 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11698 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11702 /* BSWAP (constS is initial shift count, either 56 or 24):
11704 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11705 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11706 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11707 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11708 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11710 static dw_loc_descr_ref
11711 bswap_loc_descriptor (rtx rtl, enum machine_mode mode,
11712 enum machine_mode mem_mode)
11714 dw_loc_descr_ref op0, ret, tmp;
11715 dw_loc_descr_ref l1jump, l1label;
11716 dw_loc_descr_ref l2jump, l2label;
11718 if (GET_MODE_CLASS (mode) != MODE_INT
11719 || BITS_PER_UNIT != 8
11720 || (GET_MODE_BITSIZE (mode) != 32
11721 && GET_MODE_BITSIZE (mode) != 64))
11724 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11725 VAR_INIT_STATUS_INITIALIZED);
11730 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
11732 VAR_INIT_STATUS_INITIALIZED);
11735 add_loc_descr (&ret, tmp);
11736 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11737 VAR_INIT_STATUS_INITIALIZED);
11740 add_loc_descr (&ret, tmp);
11741 l1label = new_loc_descr (DW_OP_pick, 2, 0);
11742 add_loc_descr (&ret, l1label);
11743 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
11745 VAR_INIT_STATUS_INITIALIZED);
11746 add_loc_descr (&ret, tmp);
11747 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
11748 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
11749 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11750 tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
11751 VAR_INIT_STATUS_INITIALIZED);
11754 add_loc_descr (&ret, tmp);
11755 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11756 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
11757 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11758 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
11759 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11760 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11761 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11762 VAR_INIT_STATUS_INITIALIZED);
11763 add_loc_descr (&ret, tmp);
11764 add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
11765 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
11766 add_loc_descr (&ret, l2jump);
11767 tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
11768 VAR_INIT_STATUS_INITIALIZED);
11769 add_loc_descr (&ret, tmp);
11770 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
11771 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11772 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
11773 add_loc_descr (&ret, l1jump);
11774 l2label = new_loc_descr (DW_OP_drop, 0, 0);
11775 add_loc_descr (&ret, l2label);
11776 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11777 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
11778 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11779 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11780 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11781 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11785 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11786 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11787 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11788 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11790 ROTATERT is similar:
11791 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11792 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11793 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11795 static dw_loc_descr_ref
11796 rotate_loc_descriptor (rtx rtl, enum machine_mode mode,
11797 enum machine_mode mem_mode)
11799 rtx rtlop1 = XEXP (rtl, 1);
11800 dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
11803 if (GET_MODE_CLASS (mode) != MODE_INT)
11806 if (GET_MODE (rtlop1) != VOIDmode
11807 && GET_MODE_BITSIZE (GET_MODE (rtlop1)) < GET_MODE_BITSIZE (mode))
11808 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
11809 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11810 VAR_INIT_STATUS_INITIALIZED);
11811 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
11812 VAR_INIT_STATUS_INITIALIZED);
11813 if (op0 == NULL || op1 == NULL)
11815 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
11816 for (i = 0; i < 2; i++)
11818 if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
11819 mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
11821 VAR_INIT_STATUS_INITIALIZED);
11822 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
11823 mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
11825 : HOST_BITS_PER_WIDE_INT == 64
11826 ? DW_OP_const8u : DW_OP_constu,
11827 GET_MODE_MASK (mode), 0);
11830 if (mask[i] == NULL)
11832 add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
11835 add_loc_descr (&ret, op1);
11836 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
11837 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
11838 if (GET_CODE (rtl) == ROTATERT)
11840 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11841 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
11842 GET_MODE_BITSIZE (mode), 0));
11844 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11845 if (mask[0] != NULL)
11846 add_loc_descr (&ret, mask[0]);
11847 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
11848 if (mask[1] != NULL)
11850 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11851 add_loc_descr (&ret, mask[1]);
11852 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11854 if (GET_CODE (rtl) == ROTATE)
11856 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11857 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
11858 GET_MODE_BITSIZE (mode), 0));
11860 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11861 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
11865 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11866 for DEBUG_PARAMETER_REF RTL. */
11868 static dw_loc_descr_ref
11869 parameter_ref_descriptor (rtx rtl)
11871 dw_loc_descr_ref ret;
11876 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
11877 ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
11878 ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
11881 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11882 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
11883 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
11887 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
11888 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
11893 /* Helper function to get mode of MEM's address. */
11896 get_address_mode (rtx mem)
11898 enum machine_mode mode = GET_MODE (XEXP (mem, 0));
11899 if (mode != VOIDmode)
11901 return targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
11904 /* The following routine converts the RTL for a variable or parameter
11905 (resident in memory) into an equivalent Dwarf representation of a
11906 mechanism for getting the address of that same variable onto the top of a
11907 hypothetical "address evaluation" stack.
11909 When creating memory location descriptors, we are effectively transforming
11910 the RTL for a memory-resident object into its Dwarf postfix expression
11911 equivalent. This routine recursively descends an RTL tree, turning
11912 it into Dwarf postfix code as it goes.
11914 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11916 MEM_MODE is the mode of the memory reference, needed to handle some
11917 autoincrement addressing modes.
11919 Return 0 if we can't represent the location. */
11922 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
11923 enum machine_mode mem_mode,
11924 enum var_init_status initialized)
11926 dw_loc_descr_ref mem_loc_result = NULL;
11927 enum dwarf_location_atom op;
11928 dw_loc_descr_ref op0, op1;
11930 if (mode == VOIDmode)
11931 mode = GET_MODE (rtl);
11933 /* Note that for a dynamically sized array, the location we will generate a
11934 description of here will be the lowest numbered location which is
11935 actually within the array. That's *not* necessarily the same as the
11936 zeroth element of the array. */
11938 rtl = targetm.delegitimize_address (rtl);
11940 if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
11943 switch (GET_CODE (rtl))
11948 return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
11951 /* The case of a subreg may arise when we have a local (register)
11952 variable or a formal (register) parameter which doesn't quite fill
11953 up an entire register. For now, just assume that it is
11954 legitimate to make the Dwarf info refer to the whole register which
11955 contains the given subreg. */
11956 if (!subreg_lowpart_p (rtl))
11958 if (GET_MODE_CLASS (mode) == MODE_INT
11959 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) == MODE_INT
11960 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11961 #ifdef POINTERS_EXTEND_UNSIGNED
11962 || (mode == Pmode && mem_mode != VOIDmode)
11965 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))) <= DWARF2_ADDR_SIZE)
11967 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
11968 GET_MODE (SUBREG_REG (rtl)),
11969 mem_mode, initialized);
11974 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
11976 if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl)))
11977 && (GET_MODE_CLASS (mode) != MODE_INT
11978 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) != MODE_INT))
11982 dw_die_ref type_die;
11983 dw_loc_descr_ref cvt;
11985 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
11986 GET_MODE (SUBREG_REG (rtl)),
11987 mem_mode, initialized);
11988 if (mem_loc_result == NULL)
11990 type_die = base_type_for_mode (mode,
11991 GET_MODE_CLASS (mode) == MODE_INT);
11992 if (type_die == NULL)
11994 mem_loc_result = NULL;
11997 if (GET_MODE_SIZE (mode)
11998 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
11999 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12001 cvt = new_loc_descr (DW_OP_GNU_reinterpret, 0, 0);
12002 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12003 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12004 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12005 add_loc_descr (&mem_loc_result, cvt);
12010 if (GET_MODE_CLASS (mode) != MODE_INT
12011 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
12012 #ifdef POINTERS_EXTEND_UNSIGNED
12013 && (mode != Pmode || mem_mode == VOIDmode)
12017 dw_die_ref type_die;
12021 if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
12023 type_die = base_type_for_mode (mode,
12024 GET_MODE_CLASS (mode) == MODE_INT);
12025 if (type_die == NULL)
12027 mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
12028 dbx_reg_number (rtl), 0);
12029 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
12030 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
12031 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
12034 /* Whenever a register number forms a part of the description of the
12035 method for calculating the (dynamic) address of a memory resident
12036 object, DWARF rules require the register number be referred to as
12037 a "base register". This distinction is not based in any way upon
12038 what category of register the hardware believes the given register
12039 belongs to. This is strictly DWARF terminology we're dealing with
12040 here. Note that in cases where the location of a memory-resident
12041 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12042 OP_CONST (0)) the actual DWARF location descriptor that we generate
12043 may just be OP_BASEREG (basereg). This may look deceptively like
12044 the object in question was allocated to a register (rather than in
12045 memory) so DWARF consumers need to be aware of the subtle
12046 distinction between OP_REG and OP_BASEREG. */
12047 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
12048 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
12049 else if (stack_realign_drap
12051 && crtl->args.internal_arg_pointer == rtl
12052 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
12054 /* If RTL is internal_arg_pointer, which has been optimized
12055 out, use DRAP instead. */
12056 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
12057 VAR_INIT_STATUS_INITIALIZED);
12063 if (GET_MODE_CLASS (mode) != MODE_INT)
12065 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12066 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12069 else if (GET_CODE (rtl) == ZERO_EXTEND
12070 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12071 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
12072 < HOST_BITS_PER_WIDE_INT
12073 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12074 to expand zero extend as two shifts instead of
12076 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= 4)
12078 enum machine_mode imode = GET_MODE (XEXP (rtl, 0));
12079 mem_loc_result = op0;
12080 add_loc_descr (&mem_loc_result,
12081 int_loc_descriptor (GET_MODE_MASK (imode)));
12082 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
12084 else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
12086 int shift = DWARF2_ADDR_SIZE
12087 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
12088 shift *= BITS_PER_UNIT;
12089 if (GET_CODE (rtl) == SIGN_EXTEND)
12093 mem_loc_result = op0;
12094 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
12095 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
12096 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
12097 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12099 else if (!dwarf_strict)
12101 dw_die_ref type_die1, type_die2;
12102 dw_loc_descr_ref cvt;
12104 type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
12105 GET_CODE (rtl) == ZERO_EXTEND);
12106 if (type_die1 == NULL)
12108 type_die2 = base_type_for_mode (mode, 1);
12109 if (type_die2 == NULL)
12111 mem_loc_result = op0;
12112 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12113 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12114 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
12115 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12116 add_loc_descr (&mem_loc_result, cvt);
12117 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12118 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12119 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
12120 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12121 add_loc_descr (&mem_loc_result, cvt);
12126 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
12127 get_address_mode (rtl), mode,
12128 VAR_INIT_STATUS_INITIALIZED);
12129 if (mem_loc_result == NULL)
12130 mem_loc_result = tls_mem_loc_descriptor (rtl);
12131 if (mem_loc_result != 0)
12133 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
12134 || GET_MODE_CLASS (mode) != MODE_INT)
12136 dw_die_ref type_die;
12137 dw_loc_descr_ref deref;
12142 = base_type_for_mode (mode, GET_MODE_CLASS (mode) == MODE_INT);
12143 if (type_die == NULL)
12145 deref = new_loc_descr (DW_OP_GNU_deref_type,
12146 GET_MODE_SIZE (mode), 0);
12147 deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
12148 deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
12149 deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
12150 add_loc_descr (&mem_loc_result, deref);
12152 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
12153 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
12155 add_loc_descr (&mem_loc_result,
12156 new_loc_descr (DW_OP_deref_size,
12157 GET_MODE_SIZE (mode), 0));
12161 rtx new_rtl = avoid_constant_pool_reference (rtl);
12162 if (new_rtl != rtl)
12163 return mem_loc_descriptor (new_rtl, mode, mem_mode, initialized);
12168 return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
12171 /* Some ports can transform a symbol ref into a label ref, because
12172 the symbol ref is too far away and has to be dumped into a constant
12176 if (GET_MODE_CLASS (mode) != MODE_INT
12177 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
12178 #ifdef POINTERS_EXTEND_UNSIGNED
12179 && (mode != Pmode || mem_mode == VOIDmode)
12183 if (GET_CODE (rtl) == SYMBOL_REF
12184 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
12186 dw_loc_descr_ref temp;
12188 /* If this is not defined, we have no way to emit the data. */
12189 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
12192 /* We used to emit DW_OP_addr here, but that's wrong, since
12193 DW_OP_addr should be relocated by the debug info consumer,
12194 while DW_OP_GNU_push_tls_address operand should not. */
12195 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
12196 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
12197 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
12198 temp->dw_loc_oprnd1.v.val_addr = rtl;
12199 temp->dtprel = true;
12201 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
12202 add_loc_descr (&mem_loc_result, temp);
12207 if (!const_ok_for_output (rtl))
12211 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
12212 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
12213 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
12214 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
12220 case DEBUG_IMPLICIT_PTR:
12221 expansion_failed (NULL_TREE, rtl,
12222 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12228 if (REG_P (ENTRY_VALUE_EXP (rtl)))
12230 if (GET_MODE_CLASS (mode) != MODE_INT
12231 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
12232 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
12233 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12236 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
12237 VAR_INIT_STATUS_INITIALIZED);
12239 else if (MEM_P (ENTRY_VALUE_EXP (rtl))
12240 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
12242 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
12243 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12244 if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
12248 gcc_unreachable ();
12251 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
12252 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
12253 mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
12256 case DEBUG_PARAMETER_REF:
12257 mem_loc_result = parameter_ref_descriptor (rtl);
12261 /* Extract the PLUS expression nested inside and fall into
12262 PLUS code below. */
12263 rtl = XEXP (rtl, 1);
12268 /* Turn these into a PLUS expression and fall into the PLUS code
12270 rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
12271 GEN_INT (GET_CODE (rtl) == PRE_INC
12272 ? GET_MODE_UNIT_SIZE (mem_mode)
12273 : -GET_MODE_UNIT_SIZE (mem_mode)));
12275 /* ... fall through ... */
12279 if (is_based_loc (rtl)
12280 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12281 && GET_MODE_CLASS (mode) == MODE_INT)
12282 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
12283 INTVAL (XEXP (rtl, 1)),
12284 VAR_INIT_STATUS_INITIALIZED);
12287 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12288 VAR_INIT_STATUS_INITIALIZED);
12289 if (mem_loc_result == 0)
12292 if (CONST_INT_P (XEXP (rtl, 1))
12293 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
12294 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
12297 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12298 VAR_INIT_STATUS_INITIALIZED);
12301 add_loc_descr (&mem_loc_result, op1);
12302 add_loc_descr (&mem_loc_result,
12303 new_loc_descr (DW_OP_plus, 0, 0));
12308 /* If a pseudo-reg is optimized away, it is possible for it to
12309 be replaced with a MEM containing a multiply or shift. */
12320 && GET_MODE_CLASS (mode) == MODE_INT
12321 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
12323 mem_loc_result = typed_binop (DW_OP_div, rtl,
12324 base_type_for_mode (mode, 0),
12348 if (GET_MODE_CLASS (mode) != MODE_INT)
12350 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12351 VAR_INIT_STATUS_INITIALIZED);
12353 rtx rtlop1 = XEXP (rtl, 1);
12354 if (GET_MODE (rtlop1) != VOIDmode
12355 && GET_MODE_BITSIZE (GET_MODE (rtlop1))
12356 < GET_MODE_BITSIZE (mode))
12357 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
12358 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
12359 VAR_INIT_STATUS_INITIALIZED);
12362 if (op0 == 0 || op1 == 0)
12365 mem_loc_result = op0;
12366 add_loc_descr (&mem_loc_result, op1);
12367 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12383 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12384 VAR_INIT_STATUS_INITIALIZED);
12385 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12386 VAR_INIT_STATUS_INITIALIZED);
12388 if (op0 == 0 || op1 == 0)
12391 mem_loc_result = op0;
12392 add_loc_descr (&mem_loc_result, op1);
12393 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12397 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE && !dwarf_strict)
12399 mem_loc_result = typed_binop (DW_OP_mod, rtl,
12400 base_type_for_mode (mode, 0),
12405 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12406 VAR_INIT_STATUS_INITIALIZED);
12407 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12408 VAR_INIT_STATUS_INITIALIZED);
12410 if (op0 == 0 || op1 == 0)
12413 mem_loc_result = op0;
12414 add_loc_descr (&mem_loc_result, op1);
12415 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
12416 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
12417 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
12418 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
12419 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
12423 if (!dwarf_strict && GET_MODE_CLASS (mode) == MODE_INT)
12425 if (GET_MODE_CLASS (mode) > DWARF2_ADDR_SIZE)
12430 mem_loc_result = typed_binop (DW_OP_div, rtl,
12431 base_type_for_mode (mode, 1),
12449 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12450 VAR_INIT_STATUS_INITIALIZED);
12455 mem_loc_result = op0;
12456 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12460 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12461 #ifdef POINTERS_EXTEND_UNSIGNED
12463 && mem_mode != VOIDmode
12464 && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
12468 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
12472 && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
12473 || GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT))
12475 dw_die_ref type_die = base_type_for_mode (mode, 1);
12476 if (type_die == NULL)
12478 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
12480 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12481 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12482 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
12483 if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
12484 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
12487 mem_loc_result->dw_loc_oprnd2.val_class
12488 = dw_val_class_const_double;
12489 mem_loc_result->dw_loc_oprnd2.v.val_double
12490 = shwi_to_double_int (INTVAL (rtl));
12498 dw_die_ref type_die;
12500 /* Note that a CONST_DOUBLE rtx could represent either an integer
12501 or a floating-point constant. A CONST_DOUBLE is used whenever
12502 the constant requires more than one word in order to be
12503 adequately represented. We output CONST_DOUBLEs as blocks. */
12504 if (mode == VOIDmode
12505 || (GET_MODE (rtl) == VOIDmode
12506 && GET_MODE_BITSIZE (mode) != 2 * HOST_BITS_PER_WIDE_INT))
12508 type_die = base_type_for_mode (mode,
12509 GET_MODE_CLASS (mode) == MODE_INT);
12510 if (type_die == NULL)
12512 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
12513 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12514 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12515 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
12516 if (SCALAR_FLOAT_MODE_P (mode))
12518 unsigned int length = GET_MODE_SIZE (mode);
12519 unsigned char *array
12520 = (unsigned char*) ggc_alloc_atomic (length);
12522 insert_float (rtl, array);
12523 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12524 mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
12525 mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
12526 mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12530 mem_loc_result->dw_loc_oprnd2.val_class
12531 = dw_val_class_const_double;
12532 mem_loc_result->dw_loc_oprnd2.v.val_double
12533 = rtx_to_double_int (rtl);
12539 mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
12543 mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
12547 mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
12551 mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
12555 mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
12559 mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
12563 mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
12567 mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
12571 mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
12575 mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
12580 if (GET_MODE_CLASS (mode) != MODE_INT)
12585 mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
12590 if (CONST_INT_P (XEXP (rtl, 1))
12591 && CONST_INT_P (XEXP (rtl, 2))
12592 && ((unsigned) INTVAL (XEXP (rtl, 1))
12593 + (unsigned) INTVAL (XEXP (rtl, 2))
12594 <= GET_MODE_BITSIZE (mode))
12595 && GET_MODE_CLASS (mode) == MODE_INT
12596 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12597 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
12600 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12601 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12604 if (GET_CODE (rtl) == SIGN_EXTRACT)
12608 mem_loc_result = op0;
12609 size = INTVAL (XEXP (rtl, 1));
12610 shift = INTVAL (XEXP (rtl, 2));
12611 if (BITS_BIG_ENDIAN)
12612 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
12614 if (shift + size != (int) DWARF2_ADDR_SIZE)
12616 add_loc_descr (&mem_loc_result,
12617 int_loc_descriptor (DWARF2_ADDR_SIZE
12619 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
12621 if (size != (int) DWARF2_ADDR_SIZE)
12623 add_loc_descr (&mem_loc_result,
12624 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
12625 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12632 dw_loc_descr_ref op2, bra_node, drop_node;
12633 op0 = mem_loc_descriptor (XEXP (rtl, 0),
12634 GET_MODE (XEXP (rtl, 0)) == VOIDmode
12635 ? word_mode : GET_MODE (XEXP (rtl, 0)),
12636 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12637 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12638 VAR_INIT_STATUS_INITIALIZED);
12639 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
12640 VAR_INIT_STATUS_INITIALIZED);
12641 if (op0 == NULL || op1 == NULL || op2 == NULL)
12644 mem_loc_result = op1;
12645 add_loc_descr (&mem_loc_result, op2);
12646 add_loc_descr (&mem_loc_result, op0);
12647 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
12648 add_loc_descr (&mem_loc_result, bra_node);
12649 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
12650 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
12651 add_loc_descr (&mem_loc_result, drop_node);
12652 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12653 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
12658 case FLOAT_TRUNCATE:
12660 case UNSIGNED_FLOAT:
12665 dw_die_ref type_die;
12666 dw_loc_descr_ref cvt;
12668 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12669 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12672 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
12673 && (GET_CODE (rtl) == FLOAT
12674 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
12675 <= DWARF2_ADDR_SIZE))
12677 type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
12678 GET_CODE (rtl) == UNSIGNED_FLOAT);
12679 if (type_die == NULL)
12681 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12682 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12683 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12684 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12685 add_loc_descr (&op0, cvt);
12687 type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
12688 if (type_die == NULL)
12690 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12691 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12692 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12693 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12694 add_loc_descr (&op0, cvt);
12695 if (GET_MODE_CLASS (mode) == MODE_INT
12696 && (GET_CODE (rtl) == FIX
12697 || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
12699 op0 = convert_descriptor_to_mode (mode, op0);
12703 mem_loc_result = op0;
12710 mem_loc_result = clz_loc_descriptor (rtl, mode, mem_mode);
12715 mem_loc_result = popcount_loc_descriptor (rtl, mode, mem_mode);
12719 mem_loc_result = bswap_loc_descriptor (rtl, mode, mem_mode);
12724 mem_loc_result = rotate_loc_descriptor (rtl, mode, mem_mode);
12729 /* In theory, we could implement the above. */
12730 /* DWARF cannot represent the unsigned compare operations
12755 case FRACT_CONVERT:
12756 case UNSIGNED_FRACT_CONVERT:
12758 case UNSIGNED_SAT_FRACT:
12764 case VEC_DUPLICATE:
12768 case STRICT_LOW_PART:
12772 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12773 can't express it in the debug info. This can happen e.g. with some
12778 resolve_one_addr (&rtl, NULL);
12782 #ifdef ENABLE_CHECKING
12783 print_rtl (stderr, rtl);
12784 gcc_unreachable ();
12790 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
12791 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12793 return mem_loc_result;
12796 /* Return a descriptor that describes the concatenation of two locations.
12797 This is typically a complex variable. */
12799 static dw_loc_descr_ref
12800 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
12802 dw_loc_descr_ref cc_loc_result = NULL;
12803 dw_loc_descr_ref x0_ref
12804 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12805 dw_loc_descr_ref x1_ref
12806 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12808 if (x0_ref == 0 || x1_ref == 0)
12811 cc_loc_result = x0_ref;
12812 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
12814 add_loc_descr (&cc_loc_result, x1_ref);
12815 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
12817 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
12818 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12820 return cc_loc_result;
12823 /* Return a descriptor that describes the concatenation of N
12826 static dw_loc_descr_ref
12827 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
12830 dw_loc_descr_ref cc_loc_result = NULL;
12831 unsigned int n = XVECLEN (concatn, 0);
12833 for (i = 0; i < n; ++i)
12835 dw_loc_descr_ref ref;
12836 rtx x = XVECEXP (concatn, 0, i);
12838 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12842 add_loc_descr (&cc_loc_result, ref);
12843 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
12846 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
12847 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12849 return cc_loc_result;
12852 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12853 for DEBUG_IMPLICIT_PTR RTL. */
12855 static dw_loc_descr_ref
12856 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
12858 dw_loc_descr_ref ret;
12863 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
12864 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
12865 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
12866 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
12867 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
12868 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
12871 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12872 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
12873 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
12877 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
12878 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
12883 /* Output a proper Dwarf location descriptor for a variable or parameter
12884 which is either allocated in a register or in a memory location. For a
12885 register, we just generate an OP_REG and the register number. For a
12886 memory location we provide a Dwarf postfix expression describing how to
12887 generate the (dynamic) address of the object onto the address stack.
12889 MODE is mode of the decl if this loc_descriptor is going to be used in
12890 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12891 allowed, VOIDmode otherwise.
12893 If we don't know how to describe it, return 0. */
12895 static dw_loc_descr_ref
12896 loc_descriptor (rtx rtl, enum machine_mode mode,
12897 enum var_init_status initialized)
12899 dw_loc_descr_ref loc_result = NULL;
12901 switch (GET_CODE (rtl))
12904 /* The case of a subreg may arise when we have a local (register)
12905 variable or a formal (register) parameter which doesn't quite fill
12906 up an entire register. For now, just assume that it is
12907 legitimate to make the Dwarf info refer to the whole register which
12908 contains the given subreg. */
12909 if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
12910 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
12916 loc_result = reg_loc_descriptor (rtl, initialized);
12920 loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
12921 GET_MODE (rtl), initialized);
12922 if (loc_result == NULL)
12923 loc_result = tls_mem_loc_descriptor (rtl);
12924 if (loc_result == NULL)
12926 rtx new_rtl = avoid_constant_pool_reference (rtl);
12927 if (new_rtl != rtl)
12928 loc_result = loc_descriptor (new_rtl, mode, initialized);
12933 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
12938 loc_result = concatn_loc_descriptor (rtl, initialized);
12943 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
12945 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
12946 if (GET_CODE (loc) == EXPR_LIST)
12947 loc = XEXP (loc, 0);
12948 loc_result = loc_descriptor (loc, mode, initialized);
12952 rtl = XEXP (rtl, 1);
12957 rtvec par_elems = XVEC (rtl, 0);
12958 int num_elem = GET_NUM_ELEM (par_elems);
12959 enum machine_mode mode;
12962 /* Create the first one, so we have something to add to. */
12963 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
12964 VOIDmode, initialized);
12965 if (loc_result == NULL)
12967 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
12968 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
12969 for (i = 1; i < num_elem; i++)
12971 dw_loc_descr_ref temp;
12973 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
12974 VOIDmode, initialized);
12977 add_loc_descr (&loc_result, temp);
12978 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
12979 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
12985 if (mode != VOIDmode && mode != BLKmode)
12986 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
12991 if (mode == VOIDmode)
12992 mode = GET_MODE (rtl);
12994 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
12996 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
12998 /* Note that a CONST_DOUBLE rtx could represent either an integer
12999 or a floating-point constant. A CONST_DOUBLE is used whenever
13000 the constant requires more than one word in order to be
13001 adequately represented. We output CONST_DOUBLEs as blocks. */
13002 loc_result = new_loc_descr (DW_OP_implicit_value,
13003 GET_MODE_SIZE (mode), 0);
13004 if (SCALAR_FLOAT_MODE_P (mode))
13006 unsigned int length = GET_MODE_SIZE (mode);
13007 unsigned char *array
13008 = (unsigned char*) ggc_alloc_atomic (length);
13010 insert_float (rtl, array);
13011 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
13012 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
13013 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
13014 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
13018 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
13019 loc_result->dw_loc_oprnd2.v.val_double
13020 = rtx_to_double_int (rtl);
13026 if (mode == VOIDmode)
13027 mode = GET_MODE (rtl);
13029 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
13031 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
13032 unsigned int length = CONST_VECTOR_NUNITS (rtl);
13033 unsigned char *array = (unsigned char *)
13034 ggc_alloc_atomic (length * elt_size);
13038 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
13039 switch (GET_MODE_CLASS (mode))
13041 case MODE_VECTOR_INT:
13042 for (i = 0, p = array; i < length; i++, p += elt_size)
13044 rtx elt = CONST_VECTOR_ELT (rtl, i);
13045 double_int val = rtx_to_double_int (elt);
13047 if (elt_size <= sizeof (HOST_WIDE_INT))
13048 insert_int (double_int_to_shwi (val), elt_size, p);
13051 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
13052 insert_double (val, p);
13057 case MODE_VECTOR_FLOAT:
13058 for (i = 0, p = array; i < length; i++, p += elt_size)
13060 rtx elt = CONST_VECTOR_ELT (rtl, i);
13061 insert_float (elt, p);
13066 gcc_unreachable ();
13069 loc_result = new_loc_descr (DW_OP_implicit_value,
13070 length * elt_size, 0);
13071 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
13072 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
13073 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
13074 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
13079 if (mode == VOIDmode
13080 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
13081 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
13082 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
13084 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
13089 if (!const_ok_for_output (rtl))
13092 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
13093 && (dwarf_version >= 4 || !dwarf_strict))
13095 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
13096 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
13097 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
13098 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
13099 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
13103 case DEBUG_IMPLICIT_PTR:
13104 loc_result = implicit_ptr_descriptor (rtl, 0);
13108 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
13109 && CONST_INT_P (XEXP (rtl, 1)))
13112 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
13118 if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
13119 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
13120 && dwarf_version >= 4)
13121 || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
13123 /* Value expression. */
13124 loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
13126 add_loc_descr (&loc_result,
13127 new_loc_descr (DW_OP_stack_value, 0, 0));
13135 /* We need to figure out what section we should use as the base for the
13136 address ranges where a given location is valid.
13137 1. If this particular DECL has a section associated with it, use that.
13138 2. If this function has a section associated with it, use that.
13139 3. Otherwise, use the text section.
13140 XXX: If you split a variable across multiple sections, we won't notice. */
13142 static const char *
13143 secname_for_decl (const_tree decl)
13145 const char *secname;
13147 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
13149 tree sectree = DECL_SECTION_NAME (decl);
13150 secname = TREE_STRING_POINTER (sectree);
13152 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
13154 tree sectree = DECL_SECTION_NAME (current_function_decl);
13155 secname = TREE_STRING_POINTER (sectree);
13157 else if (cfun && in_cold_section_p)
13158 secname = crtl->subsections.cold_section_label;
13160 secname = text_section_label;
13165 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13168 decl_by_reference_p (tree decl)
13170 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
13171 || TREE_CODE (decl) == VAR_DECL)
13172 && DECL_BY_REFERENCE (decl));
13175 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13178 static dw_loc_descr_ref
13179 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
13180 enum var_init_status initialized)
13182 int have_address = 0;
13183 dw_loc_descr_ref descr;
13184 enum machine_mode mode;
13186 if (want_address != 2)
13188 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
13190 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
13192 varloc = PAT_VAR_LOCATION_LOC (varloc);
13193 if (GET_CODE (varloc) == EXPR_LIST)
13194 varloc = XEXP (varloc, 0);
13195 mode = GET_MODE (varloc);
13196 if (MEM_P (varloc))
13198 rtx addr = XEXP (varloc, 0);
13199 descr = mem_loc_descriptor (addr, get_address_mode (varloc),
13200 mode, initialized);
13205 rtx x = avoid_constant_pool_reference (varloc);
13207 descr = mem_loc_descriptor (x, mode, VOIDmode,
13212 descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
13219 if (GET_CODE (varloc) == VAR_LOCATION)
13220 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
13222 mode = DECL_MODE (loc);
13223 descr = loc_descriptor (varloc, mode, initialized);
13230 if (want_address == 2 && !have_address
13231 && (dwarf_version >= 4 || !dwarf_strict))
13233 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
13235 expansion_failed (loc, NULL_RTX,
13236 "DWARF address size mismatch");
13239 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
13242 /* Show if we can't fill the request for an address. */
13243 if (want_address && !have_address)
13245 expansion_failed (loc, NULL_RTX,
13246 "Want address and only have value");
13250 /* If we've got an address and don't want one, dereference. */
13251 if (!want_address && have_address)
13253 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
13254 enum dwarf_location_atom op;
13256 if (size > DWARF2_ADDR_SIZE || size == -1)
13258 expansion_failed (loc, NULL_RTX,
13259 "DWARF address size mismatch");
13262 else if (size == DWARF2_ADDR_SIZE)
13265 op = DW_OP_deref_size;
13267 add_loc_descr (&descr, new_loc_descr (op, size, 0));
13273 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13274 if it is not possible. */
13276 static dw_loc_descr_ref
13277 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
13279 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
13280 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
13281 else if (dwarf_version >= 3 || !dwarf_strict)
13282 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
13287 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13288 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13290 static dw_loc_descr_ref
13291 dw_sra_loc_expr (tree decl, rtx loc)
13294 unsigned int padsize = 0;
13295 dw_loc_descr_ref descr, *descr_tail;
13296 unsigned HOST_WIDE_INT decl_size;
13298 enum var_init_status initialized;
13300 if (DECL_SIZE (decl) == NULL
13301 || !host_integerp (DECL_SIZE (decl), 1))
13304 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
13306 descr_tail = &descr;
13308 for (p = loc; p; p = XEXP (p, 1))
13310 unsigned int bitsize = decl_piece_bitsize (p);
13311 rtx loc_note = *decl_piece_varloc_ptr (p);
13312 dw_loc_descr_ref cur_descr;
13313 dw_loc_descr_ref *tail, last = NULL;
13314 unsigned int opsize = 0;
13316 if (loc_note == NULL_RTX
13317 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
13319 padsize += bitsize;
13322 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
13323 varloc = NOTE_VAR_LOCATION (loc_note);
13324 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
13325 if (cur_descr == NULL)
13327 padsize += bitsize;
13331 /* Check that cur_descr either doesn't use
13332 DW_OP_*piece operations, or their sum is equal
13333 to bitsize. Otherwise we can't embed it. */
13334 for (tail = &cur_descr; *tail != NULL;
13335 tail = &(*tail)->dw_loc_next)
13336 if ((*tail)->dw_loc_opc == DW_OP_piece)
13338 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
13342 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
13344 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
13348 if (last != NULL && opsize != bitsize)
13350 padsize += bitsize;
13354 /* If there is a hole, add DW_OP_*piece after empty DWARF
13355 expression, which means that those bits are optimized out. */
13358 if (padsize > decl_size)
13360 decl_size -= padsize;
13361 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
13362 if (*descr_tail == NULL)
13364 descr_tail = &(*descr_tail)->dw_loc_next;
13367 *descr_tail = cur_descr;
13369 if (bitsize > decl_size)
13371 decl_size -= bitsize;
13374 HOST_WIDE_INT offset = 0;
13375 if (GET_CODE (varloc) == VAR_LOCATION
13376 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
13378 varloc = PAT_VAR_LOCATION_LOC (varloc);
13379 if (GET_CODE (varloc) == EXPR_LIST)
13380 varloc = XEXP (varloc, 0);
13384 if (GET_CODE (varloc) == CONST
13385 || GET_CODE (varloc) == SIGN_EXTEND
13386 || GET_CODE (varloc) == ZERO_EXTEND)
13387 varloc = XEXP (varloc, 0);
13388 else if (GET_CODE (varloc) == SUBREG)
13389 varloc = SUBREG_REG (varloc);
13394 /* DW_OP_bit_size offset should be zero for register
13395 or implicit location descriptions and empty location
13396 descriptions, but for memory addresses needs big endian
13398 if (MEM_P (varloc))
13400 unsigned HOST_WIDE_INT memsize
13401 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
13402 if (memsize != bitsize)
13404 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
13405 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
13407 if (memsize < bitsize)
13409 if (BITS_BIG_ENDIAN)
13410 offset = memsize - bitsize;
13414 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
13415 if (*descr_tail == NULL)
13417 descr_tail = &(*descr_tail)->dw_loc_next;
13421 /* If there were any non-empty expressions, add padding till the end of
13423 if (descr != NULL && decl_size != 0)
13425 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
13426 if (*descr_tail == NULL)
13432 /* Return the dwarf representation of the location list LOC_LIST of
13433 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13436 static dw_loc_list_ref
13437 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
13439 const char *endname, *secname;
13441 enum var_init_status initialized;
13442 struct var_loc_node *node;
13443 dw_loc_descr_ref descr;
13444 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
13445 dw_loc_list_ref list = NULL;
13446 dw_loc_list_ref *listp = &list;
13448 /* Now that we know what section we are using for a base,
13449 actually construct the list of locations.
13450 The first location information is what is passed to the
13451 function that creates the location list, and the remaining
13452 locations just get added on to that list.
13453 Note that we only know the start address for a location
13454 (IE location changes), so to build the range, we use
13455 the range [current location start, next location start].
13456 This means we have to special case the last node, and generate
13457 a range of [last location start, end of function label]. */
13459 secname = secname_for_decl (decl);
13461 for (node = loc_list->first; node; node = node->next)
13462 if (GET_CODE (node->loc) == EXPR_LIST
13463 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
13465 if (GET_CODE (node->loc) == EXPR_LIST)
13467 /* This requires DW_OP_{,bit_}piece, which is not usable
13468 inside DWARF expressions. */
13469 if (want_address != 2)
13471 descr = dw_sra_loc_expr (decl, node->loc);
13477 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
13478 varloc = NOTE_VAR_LOCATION (node->loc);
13479 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
13483 bool range_across_switch = false;
13484 /* If section switch happens in between node->label
13485 and node->next->label (or end of function) and
13486 we can't emit it as a single entry list,
13487 emit two ranges, first one ending at the end
13488 of first partition and second one starting at the
13489 beginning of second partition. */
13490 if (node == loc_list->last_before_switch
13491 && (node != loc_list->first || loc_list->first->next)
13492 && current_function_decl)
13494 endname = current_fde ()->dw_fde_end;
13495 range_across_switch = true;
13497 /* The variable has a location between NODE->LABEL and
13498 NODE->NEXT->LABEL. */
13499 else if (node->next)
13500 endname = node->next->label;
13501 /* If the variable has a location at the last label
13502 it keeps its location until the end of function. */
13503 else if (!current_function_decl)
13504 endname = text_end_label;
13507 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
13508 current_function_funcdef_no);
13509 endname = ggc_strdup (label_id);
13512 *listp = new_loc_list (descr, node->label, endname, secname);
13513 if (TREE_CODE (decl) == PARM_DECL
13514 && node == loc_list->first
13515 && GET_CODE (node->loc) == NOTE
13516 && strcmp (node->label, endname) == 0)
13517 (*listp)->force = true;
13518 listp = &(*listp)->dw_loc_next;
13520 if (range_across_switch)
13522 if (GET_CODE (node->loc) == EXPR_LIST)
13523 descr = dw_sra_loc_expr (decl, node->loc);
13526 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
13527 varloc = NOTE_VAR_LOCATION (node->loc);
13528 descr = dw_loc_list_1 (decl, varloc, want_address,
13531 gcc_assert (descr);
13532 /* The variable has a location between NODE->LABEL and
13533 NODE->NEXT->LABEL. */
13535 endname = node->next->label;
13537 endname = current_fde ()->dw_fde_second_end;
13538 *listp = new_loc_list (descr,
13539 current_fde ()->dw_fde_second_begin,
13541 listp = &(*listp)->dw_loc_next;
13546 /* Try to avoid the overhead of a location list emitting a location
13547 expression instead, but only if we didn't have more than one
13548 location entry in the first place. If some entries were not
13549 representable, we don't want to pretend a single entry that was
13550 applies to the entire scope in which the variable is
13552 if (list && loc_list->first->next)
13558 /* Return if the loc_list has only single element and thus can be represented
13559 as location description. */
13562 single_element_loc_list_p (dw_loc_list_ref list)
13564 gcc_assert (!list->dw_loc_next || list->ll_symbol);
13565 return !list->ll_symbol;
13568 /* To each location in list LIST add loc descr REF. */
13571 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
13573 dw_loc_descr_ref copy;
13574 add_loc_descr (&list->expr, ref);
13575 list = list->dw_loc_next;
13578 copy = ggc_alloc_dw_loc_descr_node ();
13579 memcpy (copy, ref, sizeof (dw_loc_descr_node));
13580 add_loc_descr (&list->expr, copy);
13581 while (copy->dw_loc_next)
13583 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
13584 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
13585 copy->dw_loc_next = new_copy;
13588 list = list->dw_loc_next;
13592 /* Given two lists RET and LIST
13593 produce location list that is result of adding expression in LIST
13594 to expression in RET on each possition in program.
13595 Might be destructive on both RET and LIST.
13597 TODO: We handle only simple cases of RET or LIST having at most one
13598 element. General case would inolve sorting the lists in program order
13599 and merging them that will need some additional work.
13600 Adding that will improve quality of debug info especially for SRA-ed
13604 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
13613 if (!list->dw_loc_next)
13615 add_loc_descr_to_each (*ret, list->expr);
13618 if (!(*ret)->dw_loc_next)
13620 add_loc_descr_to_each (list, (*ret)->expr);
13624 expansion_failed (NULL_TREE, NULL_RTX,
13625 "Don't know how to merge two non-trivial"
13626 " location lists.\n");
13631 /* LOC is constant expression. Try a luck, look it up in constant
13632 pool and return its loc_descr of its address. */
13634 static dw_loc_descr_ref
13635 cst_pool_loc_descr (tree loc)
13637 /* Get an RTL for this, if something has been emitted. */
13638 rtx rtl = lookup_constant_def (loc);
13640 if (!rtl || !MEM_P (rtl))
13645 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
13647 /* TODO: We might get more coverage if we was actually delaying expansion
13648 of all expressions till end of compilation when constant pools are fully
13650 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
13652 expansion_failed (loc, NULL_RTX,
13653 "CST value in contant pool but not marked.");
13656 return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
13657 GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
13660 /* Return dw_loc_list representing address of addr_expr LOC
13661 by looking for innder INDIRECT_REF expression and turing it
13662 into simple arithmetics. */
13664 static dw_loc_list_ref
13665 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
13668 HOST_WIDE_INT bitsize, bitpos, bytepos;
13669 enum machine_mode mode;
13671 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
13672 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
13674 obj = get_inner_reference (TREE_OPERAND (loc, 0),
13675 &bitsize, &bitpos, &offset, &mode,
13676 &unsignedp, &volatilep, false);
13678 if (bitpos % BITS_PER_UNIT)
13680 expansion_failed (loc, NULL_RTX, "bitfield access");
13683 if (!INDIRECT_REF_P (obj))
13685 expansion_failed (obj,
13686 NULL_RTX, "no indirect ref in inner refrence");
13689 if (!offset && !bitpos)
13690 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
13692 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
13693 && (dwarf_version >= 4 || !dwarf_strict))
13695 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
13700 /* Variable offset. */
13701 list_ret1 = loc_list_from_tree (offset, 0);
13702 if (list_ret1 == 0)
13704 add_loc_list (&list_ret, list_ret1);
13707 add_loc_descr_to_each (list_ret,
13708 new_loc_descr (DW_OP_plus, 0, 0));
13710 bytepos = bitpos / BITS_PER_UNIT;
13712 add_loc_descr_to_each (list_ret,
13713 new_loc_descr (DW_OP_plus_uconst,
13715 else if (bytepos < 0)
13716 loc_list_plus_const (list_ret, bytepos);
13717 add_loc_descr_to_each (list_ret,
13718 new_loc_descr (DW_OP_stack_value, 0, 0));
13724 /* Generate Dwarf location list representing LOC.
13725 If WANT_ADDRESS is false, expression computing LOC will be computed
13726 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13727 if WANT_ADDRESS is 2, expression computing address useable in location
13728 will be returned (i.e. DW_OP_reg can be used
13729 to refer to register values). */
13731 static dw_loc_list_ref
13732 loc_list_from_tree (tree loc, int want_address)
13734 dw_loc_descr_ref ret = NULL, ret1 = NULL;
13735 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
13736 int have_address = 0;
13737 enum dwarf_location_atom op;
13739 /* ??? Most of the time we do not take proper care for sign/zero
13740 extending the values properly. Hopefully this won't be a real
13743 switch (TREE_CODE (loc))
13746 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
13749 case PLACEHOLDER_EXPR:
13750 /* This case involves extracting fields from an object to determine the
13751 position of other fields. We don't try to encode this here. The
13752 only user of this is Ada, which encodes the needed information using
13753 the names of types. */
13754 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
13758 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
13759 /* There are no opcodes for these operations. */
13762 case PREINCREMENT_EXPR:
13763 case PREDECREMENT_EXPR:
13764 case POSTINCREMENT_EXPR:
13765 case POSTDECREMENT_EXPR:
13766 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
13767 /* There are no opcodes for these operations. */
13771 /* If we already want an address, see if there is INDIRECT_REF inside
13772 e.g. for &this->field. */
13775 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
13776 (loc, want_address == 2);
13779 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
13780 && (ret = cst_pool_loc_descr (loc)))
13783 /* Otherwise, process the argument and look for the address. */
13784 if (!list_ret && !ret)
13785 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
13789 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
13795 if (DECL_THREAD_LOCAL_P (loc))
13798 enum dwarf_location_atom first_op;
13799 enum dwarf_location_atom second_op;
13800 bool dtprel = false;
13802 if (targetm.have_tls)
13804 /* If this is not defined, we have no way to emit the
13806 if (!targetm.asm_out.output_dwarf_dtprel)
13809 /* The way DW_OP_GNU_push_tls_address is specified, we
13810 can only look up addresses of objects in the current
13811 module. We used DW_OP_addr as first op, but that's
13812 wrong, because DW_OP_addr is relocated by the debug
13813 info consumer, while DW_OP_GNU_push_tls_address
13814 operand shouldn't be. */
13815 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
13817 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
13819 second_op = DW_OP_GNU_push_tls_address;
13823 if (!targetm.emutls.debug_form_tls_address
13824 || !(dwarf_version >= 3 || !dwarf_strict))
13826 /* We stuffed the control variable into the DECL_VALUE_EXPR
13827 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13828 no longer appear in gimple code. We used the control
13829 variable in specific so that we could pick it up here. */
13830 loc = DECL_VALUE_EXPR (loc);
13831 first_op = DW_OP_addr;
13832 second_op = DW_OP_form_tls_address;
13835 rtl = rtl_for_decl_location (loc);
13836 if (rtl == NULL_RTX)
13841 rtl = XEXP (rtl, 0);
13842 if (! CONSTANT_P (rtl))
13845 ret = new_loc_descr (first_op, 0, 0);
13846 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
13847 ret->dw_loc_oprnd1.v.val_addr = rtl;
13848 ret->dtprel = dtprel;
13850 ret1 = new_loc_descr (second_op, 0, 0);
13851 add_loc_descr (&ret, ret1);
13860 if (DECL_HAS_VALUE_EXPR_P (loc))
13861 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
13865 case FUNCTION_DECL:
13868 var_loc_list *loc_list = lookup_decl_loc (loc);
13870 if (loc_list && loc_list->first)
13872 list_ret = dw_loc_list (loc_list, loc, want_address);
13873 have_address = want_address != 0;
13876 rtl = rtl_for_decl_location (loc);
13877 if (rtl == NULL_RTX)
13879 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
13882 else if (CONST_INT_P (rtl))
13884 HOST_WIDE_INT val = INTVAL (rtl);
13885 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13886 val &= GET_MODE_MASK (DECL_MODE (loc));
13887 ret = int_loc_descriptor (val);
13889 else if (GET_CODE (rtl) == CONST_STRING)
13891 expansion_failed (loc, NULL_RTX, "CONST_STRING");
13894 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
13896 ret = new_loc_descr (DW_OP_addr, 0, 0);
13897 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
13898 ret->dw_loc_oprnd1.v.val_addr = rtl;
13902 enum machine_mode mode, mem_mode;
13904 /* Certain constructs can only be represented at top-level. */
13905 if (want_address == 2)
13907 ret = loc_descriptor (rtl, VOIDmode,
13908 VAR_INIT_STATUS_INITIALIZED);
13913 mode = GET_MODE (rtl);
13914 mem_mode = VOIDmode;
13918 mode = get_address_mode (rtl);
13919 rtl = XEXP (rtl, 0);
13922 ret = mem_loc_descriptor (rtl, mode, mem_mode,
13923 VAR_INIT_STATUS_INITIALIZED);
13926 expansion_failed (loc, rtl,
13927 "failed to produce loc descriptor for rtl");
13934 if (!integer_zerop (TREE_OPERAND (loc, 1)))
13938 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13942 case COMPOUND_EXPR:
13943 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
13946 case VIEW_CONVERT_EXPR:
13949 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
13951 case COMPONENT_REF:
13952 case BIT_FIELD_REF:
13954 case ARRAY_RANGE_REF:
13955 case REALPART_EXPR:
13956 case IMAGPART_EXPR:
13959 HOST_WIDE_INT bitsize, bitpos, bytepos;
13960 enum machine_mode mode;
13962 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
13964 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
13965 &unsignedp, &volatilep, false);
13967 gcc_assert (obj != loc);
13969 list_ret = loc_list_from_tree (obj,
13971 && !bitpos && !offset ? 2 : 1);
13972 /* TODO: We can extract value of the small expression via shifting even
13973 for nonzero bitpos. */
13976 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
13978 expansion_failed (loc, NULL_RTX,
13979 "bitfield access");
13983 if (offset != NULL_TREE)
13985 /* Variable offset. */
13986 list_ret1 = loc_list_from_tree (offset, 0);
13987 if (list_ret1 == 0)
13989 add_loc_list (&list_ret, list_ret1);
13992 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
13995 bytepos = bitpos / BITS_PER_UNIT;
13997 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
13998 else if (bytepos < 0)
13999 loc_list_plus_const (list_ret, bytepos);
14006 if ((want_address || !host_integerp (loc, 0))
14007 && (ret = cst_pool_loc_descr (loc)))
14009 else if (want_address == 2
14010 && host_integerp (loc, 0)
14011 && (ret = address_of_int_loc_descriptor
14012 (int_size_in_bytes (TREE_TYPE (loc)),
14013 tree_low_cst (loc, 0))))
14015 else if (host_integerp (loc, 0))
14016 ret = int_loc_descriptor (tree_low_cst (loc, 0));
14019 expansion_failed (loc, NULL_RTX,
14020 "Integer operand is not host integer");
14029 if ((ret = cst_pool_loc_descr (loc)))
14032 /* We can construct small constants here using int_loc_descriptor. */
14033 expansion_failed (loc, NULL_RTX,
14034 "constructor or constant not in constant pool");
14037 case TRUTH_AND_EXPR:
14038 case TRUTH_ANDIF_EXPR:
14043 case TRUTH_XOR_EXPR:
14048 case TRUTH_OR_EXPR:
14049 case TRUTH_ORIF_EXPR:
14054 case FLOOR_DIV_EXPR:
14055 case CEIL_DIV_EXPR:
14056 case ROUND_DIV_EXPR:
14057 case TRUNC_DIV_EXPR:
14058 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
14067 case FLOOR_MOD_EXPR:
14068 case CEIL_MOD_EXPR:
14069 case ROUND_MOD_EXPR:
14070 case TRUNC_MOD_EXPR:
14071 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
14076 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
14077 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
14078 if (list_ret == 0 || list_ret1 == 0)
14081 add_loc_list (&list_ret, list_ret1);
14084 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
14085 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
14086 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
14087 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
14088 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
14100 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
14103 case POINTER_PLUS_EXPR:
14105 if (host_integerp (TREE_OPERAND (loc, 1), 0))
14107 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
14111 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
14119 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14126 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14133 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14140 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14155 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
14156 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
14157 if (list_ret == 0 || list_ret1 == 0)
14160 add_loc_list (&list_ret, list_ret1);
14163 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
14166 case TRUTH_NOT_EXPR:
14180 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
14184 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
14190 const enum tree_code code =
14191 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
14193 loc = build3 (COND_EXPR, TREE_TYPE (loc),
14194 build2 (code, integer_type_node,
14195 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
14196 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
14199 /* ... fall through ... */
14203 dw_loc_descr_ref lhs
14204 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
14205 dw_loc_list_ref rhs
14206 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
14207 dw_loc_descr_ref bra_node, jump_node, tmp;
14209 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
14210 if (list_ret == 0 || lhs == 0 || rhs == 0)
14213 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14214 add_loc_descr_to_each (list_ret, bra_node);
14216 add_loc_list (&list_ret, rhs);
14217 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
14218 add_loc_descr_to_each (list_ret, jump_node);
14220 add_loc_descr_to_each (list_ret, lhs);
14221 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14222 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
14224 /* ??? Need a node to point the skip at. Use a nop. */
14225 tmp = new_loc_descr (DW_OP_nop, 0, 0);
14226 add_loc_descr_to_each (list_ret, tmp);
14227 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14228 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
14232 case FIX_TRUNC_EXPR:
14236 /* Leave front-end specific codes as simply unknown. This comes
14237 up, for instance, with the C STMT_EXPR. */
14238 if ((unsigned int) TREE_CODE (loc)
14239 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
14241 expansion_failed (loc, NULL_RTX,
14242 "language specific tree node");
14246 #ifdef ENABLE_CHECKING
14247 /* Otherwise this is a generic code; we should just lists all of
14248 these explicitly. We forgot one. */
14249 gcc_unreachable ();
14251 /* In a release build, we want to degrade gracefully: better to
14252 generate incomplete debugging information than to crash. */
14257 if (!ret && !list_ret)
14260 if (want_address == 2 && !have_address
14261 && (dwarf_version >= 4 || !dwarf_strict))
14263 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
14265 expansion_failed (loc, NULL_RTX,
14266 "DWARF address size mismatch");
14270 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
14272 add_loc_descr_to_each (list_ret,
14273 new_loc_descr (DW_OP_stack_value, 0, 0));
14276 /* Show if we can't fill the request for an address. */
14277 if (want_address && !have_address)
14279 expansion_failed (loc, NULL_RTX,
14280 "Want address and only have value");
14284 gcc_assert (!ret || !list_ret);
14286 /* If we've got an address and don't want one, dereference. */
14287 if (!want_address && have_address)
14289 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
14291 if (size > DWARF2_ADDR_SIZE || size == -1)
14293 expansion_failed (loc, NULL_RTX,
14294 "DWARF address size mismatch");
14297 else if (size == DWARF2_ADDR_SIZE)
14300 op = DW_OP_deref_size;
14303 add_loc_descr (&ret, new_loc_descr (op, size, 0));
14305 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
14308 list_ret = new_loc_list (ret, NULL, NULL, NULL);
14313 /* Same as above but return only single location expression. */
14314 static dw_loc_descr_ref
14315 loc_descriptor_from_tree (tree loc, int want_address)
14317 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
14320 if (ret->dw_loc_next)
14322 expansion_failed (loc, NULL_RTX,
14323 "Location list where only loc descriptor needed");
14329 /* Given a value, round it up to the lowest multiple of `boundary'
14330 which is not less than the value itself. */
14332 static inline HOST_WIDE_INT
14333 ceiling (HOST_WIDE_INT value, unsigned int boundary)
14335 return (((value + boundary - 1) / boundary) * boundary);
14338 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14339 pointer to the declared type for the relevant field variable, or return
14340 `integer_type_node' if the given node turns out to be an
14341 ERROR_MARK node. */
14344 field_type (const_tree decl)
14348 if (TREE_CODE (decl) == ERROR_MARK)
14349 return integer_type_node;
14351 type = DECL_BIT_FIELD_TYPE (decl);
14352 if (type == NULL_TREE)
14353 type = TREE_TYPE (decl);
14358 /* Given a pointer to a tree node, return the alignment in bits for
14359 it, or else return BITS_PER_WORD if the node actually turns out to
14360 be an ERROR_MARK node. */
14362 static inline unsigned
14363 simple_type_align_in_bits (const_tree type)
14365 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
14368 static inline unsigned
14369 simple_decl_align_in_bits (const_tree decl)
14371 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
14374 /* Return the result of rounding T up to ALIGN. */
14376 static inline double_int
14377 round_up_to_align (double_int t, unsigned int align)
14379 double_int alignd = uhwi_to_double_int (align);
14380 t = double_int_add (t, alignd);
14381 t = double_int_add (t, double_int_minus_one);
14382 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
14383 t = double_int_mul (t, alignd);
14387 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14388 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14389 or return 0 if we are unable to determine what that offset is, either
14390 because the argument turns out to be a pointer to an ERROR_MARK node, or
14391 because the offset is actually variable. (We can't handle the latter case
14394 static HOST_WIDE_INT
14395 field_byte_offset (const_tree decl)
14397 double_int object_offset_in_bits;
14398 double_int object_offset_in_bytes;
14399 double_int bitpos_int;
14401 if (TREE_CODE (decl) == ERROR_MARK)
14404 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
14406 /* We cannot yet cope with fields whose positions are variable, so
14407 for now, when we see such things, we simply return 0. Someday, we may
14408 be able to handle such cases, but it will be damn difficult. */
14409 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
14412 bitpos_int = tree_to_double_int (bit_position (decl));
14414 #ifdef PCC_BITFIELD_TYPE_MATTERS
14415 if (PCC_BITFIELD_TYPE_MATTERS)
14418 tree field_size_tree;
14419 double_int deepest_bitpos;
14420 double_int field_size_in_bits;
14421 unsigned int type_align_in_bits;
14422 unsigned int decl_align_in_bits;
14423 double_int type_size_in_bits;
14425 type = field_type (decl);
14426 type_size_in_bits = double_int_type_size_in_bits (type);
14427 type_align_in_bits = simple_type_align_in_bits (type);
14429 field_size_tree = DECL_SIZE (decl);
14431 /* The size could be unspecified if there was an error, or for
14432 a flexible array member. */
14433 if (!field_size_tree)
14434 field_size_tree = bitsize_zero_node;
14436 /* If the size of the field is not constant, use the type size. */
14437 if (TREE_CODE (field_size_tree) == INTEGER_CST)
14438 field_size_in_bits = tree_to_double_int (field_size_tree);
14440 field_size_in_bits = type_size_in_bits;
14442 decl_align_in_bits = simple_decl_align_in_bits (decl);
14444 /* The GCC front-end doesn't make any attempt to keep track of the
14445 starting bit offset (relative to the start of the containing
14446 structure type) of the hypothetical "containing object" for a
14447 bit-field. Thus, when computing the byte offset value for the
14448 start of the "containing object" of a bit-field, we must deduce
14449 this information on our own. This can be rather tricky to do in
14450 some cases. For example, handling the following structure type
14451 definition when compiling for an i386/i486 target (which only
14452 aligns long long's to 32-bit boundaries) can be very tricky:
14454 struct S { int field1; long long field2:31; };
14456 Fortunately, there is a simple rule-of-thumb which can be used
14457 in such cases. When compiling for an i386/i486, GCC will
14458 allocate 8 bytes for the structure shown above. It decides to
14459 do this based upon one simple rule for bit-field allocation.
14460 GCC allocates each "containing object" for each bit-field at
14461 the first (i.e. lowest addressed) legitimate alignment boundary
14462 (based upon the required minimum alignment for the declared
14463 type of the field) which it can possibly use, subject to the
14464 condition that there is still enough available space remaining
14465 in the containing object (when allocated at the selected point)
14466 to fully accommodate all of the bits of the bit-field itself.
14468 This simple rule makes it obvious why GCC allocates 8 bytes for
14469 each object of the structure type shown above. When looking
14470 for a place to allocate the "containing object" for `field2',
14471 the compiler simply tries to allocate a 64-bit "containing
14472 object" at each successive 32-bit boundary (starting at zero)
14473 until it finds a place to allocate that 64- bit field such that
14474 at least 31 contiguous (and previously unallocated) bits remain
14475 within that selected 64 bit field. (As it turns out, for the
14476 example above, the compiler finds it is OK to allocate the
14477 "containing object" 64-bit field at bit-offset zero within the
14480 Here we attempt to work backwards from the limited set of facts
14481 we're given, and we try to deduce from those facts, where GCC
14482 must have believed that the containing object started (within
14483 the structure type). The value we deduce is then used (by the
14484 callers of this routine) to generate DW_AT_location and
14485 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14486 the case of DW_AT_location, regular fields as well). */
14488 /* Figure out the bit-distance from the start of the structure to
14489 the "deepest" bit of the bit-field. */
14490 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
14492 /* This is the tricky part. Use some fancy footwork to deduce
14493 where the lowest addressed bit of the containing object must
14495 object_offset_in_bits
14496 = double_int_sub (deepest_bitpos, type_size_in_bits);
14498 /* Round up to type_align by default. This works best for
14500 object_offset_in_bits
14501 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
14503 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
14505 object_offset_in_bits
14506 = double_int_sub (deepest_bitpos, type_size_in_bits);
14508 /* Round up to decl_align instead. */
14509 object_offset_in_bits
14510 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
14514 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14515 object_offset_in_bits = bitpos_int;
14517 object_offset_in_bytes
14518 = double_int_div (object_offset_in_bits,
14519 uhwi_to_double_int (BITS_PER_UNIT), true,
14521 return double_int_to_shwi (object_offset_in_bytes);
14524 /* The following routines define various Dwarf attributes and any data
14525 associated with them. */
14527 /* Add a location description attribute value to a DIE.
14529 This emits location attributes suitable for whole variables and
14530 whole parameters. Note that the location attributes for struct fields are
14531 generated by the routine `data_member_location_attribute' below. */
14534 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
14535 dw_loc_list_ref descr)
14539 if (single_element_loc_list_p (descr))
14540 add_AT_loc (die, attr_kind, descr->expr);
14542 add_AT_loc_list (die, attr_kind, descr);
14545 /* Add DW_AT_accessibility attribute to DIE if needed. */
14548 add_accessibility_attribute (dw_die_ref die, tree decl)
14550 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14551 children, otherwise the default is DW_ACCESS_public. In DWARF2
14552 the default has always been DW_ACCESS_public. */
14553 if (TREE_PROTECTED (decl))
14554 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
14555 else if (TREE_PRIVATE (decl))
14557 if (dwarf_version == 2
14558 || die->die_parent == NULL
14559 || die->die_parent->die_tag != DW_TAG_class_type)
14560 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
14562 else if (dwarf_version > 2
14564 && die->die_parent->die_tag == DW_TAG_class_type)
14565 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
14568 /* Attach the specialized form of location attribute used for data members of
14569 struct and union types. In the special case of a FIELD_DECL node which
14570 represents a bit-field, the "offset" part of this special location
14571 descriptor must indicate the distance in bytes from the lowest-addressed
14572 byte of the containing struct or union type to the lowest-addressed byte of
14573 the "containing object" for the bit-field. (See the `field_byte_offset'
14576 For any given bit-field, the "containing object" is a hypothetical object
14577 (of some integral or enum type) within which the given bit-field lives. The
14578 type of this hypothetical "containing object" is always the same as the
14579 declared type of the individual bit-field itself (for GCC anyway... the
14580 DWARF spec doesn't actually mandate this). Note that it is the size (in
14581 bytes) of the hypothetical "containing object" which will be given in the
14582 DW_AT_byte_size attribute for this bit-field. (See the
14583 `byte_size_attribute' function below.) It is also used when calculating the
14584 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14585 function below.) */
14588 add_data_member_location_attribute (dw_die_ref die, tree decl)
14590 HOST_WIDE_INT offset;
14591 dw_loc_descr_ref loc_descr = 0;
14593 if (TREE_CODE (decl) == TREE_BINFO)
14595 /* We're working on the TAG_inheritance for a base class. */
14596 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
14598 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14599 aren't at a fixed offset from all (sub)objects of the same
14600 type. We need to extract the appropriate offset from our
14601 vtable. The following dwarf expression means
14603 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14605 This is specific to the V3 ABI, of course. */
14607 dw_loc_descr_ref tmp;
14609 /* Make a copy of the object address. */
14610 tmp = new_loc_descr (DW_OP_dup, 0, 0);
14611 add_loc_descr (&loc_descr, tmp);
14613 /* Extract the vtable address. */
14614 tmp = new_loc_descr (DW_OP_deref, 0, 0);
14615 add_loc_descr (&loc_descr, tmp);
14617 /* Calculate the address of the offset. */
14618 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
14619 gcc_assert (offset < 0);
14621 tmp = int_loc_descriptor (-offset);
14622 add_loc_descr (&loc_descr, tmp);
14623 tmp = new_loc_descr (DW_OP_minus, 0, 0);
14624 add_loc_descr (&loc_descr, tmp);
14626 /* Extract the offset. */
14627 tmp = new_loc_descr (DW_OP_deref, 0, 0);
14628 add_loc_descr (&loc_descr, tmp);
14630 /* Add it to the object address. */
14631 tmp = new_loc_descr (DW_OP_plus, 0, 0);
14632 add_loc_descr (&loc_descr, tmp);
14635 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
14638 offset = field_byte_offset (decl);
14642 if (dwarf_version > 2)
14644 /* Don't need to output a location expression, just the constant. */
14646 add_AT_int (die, DW_AT_data_member_location, offset);
14648 add_AT_unsigned (die, DW_AT_data_member_location, offset);
14653 enum dwarf_location_atom op;
14655 /* The DWARF2 standard says that we should assume that the structure
14656 address is already on the stack, so we can specify a structure
14657 field address by using DW_OP_plus_uconst. */
14659 #ifdef MIPS_DEBUGGING_INFO
14660 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
14661 operator correctly. It works only if we leave the offset on the
14665 op = DW_OP_plus_uconst;
14668 loc_descr = new_loc_descr (op, offset, 0);
14672 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
14675 /* Writes integer values to dw_vec_const array. */
14678 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
14682 *dest++ = val & 0xff;
14688 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14690 static HOST_WIDE_INT
14691 extract_int (const unsigned char *src, unsigned int size)
14693 HOST_WIDE_INT val = 0;
14699 val |= *--src & 0xff;
14705 /* Writes double_int values to dw_vec_const array. */
14708 insert_double (double_int val, unsigned char *dest)
14710 unsigned char *p0 = dest;
14711 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
14713 if (WORDS_BIG_ENDIAN)
14719 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
14720 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
14723 /* Writes floating point values to dw_vec_const array. */
14726 insert_float (const_rtx rtl, unsigned char *array)
14728 REAL_VALUE_TYPE rv;
14732 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
14733 real_to_target (val, &rv, GET_MODE (rtl));
14735 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14736 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
14738 insert_int (val[i], 4, array);
14743 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14744 does not have a "location" either in memory or in a register. These
14745 things can arise in GNU C when a constant is passed as an actual parameter
14746 to an inlined function. They can also arise in C++ where declared
14747 constants do not necessarily get memory "homes". */
14750 add_const_value_attribute (dw_die_ref die, rtx rtl)
14752 switch (GET_CODE (rtl))
14756 HOST_WIDE_INT val = INTVAL (rtl);
14759 add_AT_int (die, DW_AT_const_value, val);
14761 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
14766 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14767 floating-point constant. A CONST_DOUBLE is used whenever the
14768 constant requires more than one word in order to be adequately
14771 enum machine_mode mode = GET_MODE (rtl);
14773 if (SCALAR_FLOAT_MODE_P (mode))
14775 unsigned int length = GET_MODE_SIZE (mode);
14776 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
14778 insert_float (rtl, array);
14779 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
14782 add_AT_double (die, DW_AT_const_value,
14783 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
14789 enum machine_mode mode = GET_MODE (rtl);
14790 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
14791 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14792 unsigned char *array = (unsigned char *) ggc_alloc_atomic
14793 (length * elt_size);
14797 switch (GET_MODE_CLASS (mode))
14799 case MODE_VECTOR_INT:
14800 for (i = 0, p = array; i < length; i++, p += elt_size)
14802 rtx elt = CONST_VECTOR_ELT (rtl, i);
14803 double_int val = rtx_to_double_int (elt);
14805 if (elt_size <= sizeof (HOST_WIDE_INT))
14806 insert_int (double_int_to_shwi (val), elt_size, p);
14809 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14810 insert_double (val, p);
14815 case MODE_VECTOR_FLOAT:
14816 for (i = 0, p = array; i < length; i++, p += elt_size)
14818 rtx elt = CONST_VECTOR_ELT (rtl, i);
14819 insert_float (elt, p);
14824 gcc_unreachable ();
14827 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
14832 if (dwarf_version >= 4 || !dwarf_strict)
14834 dw_loc_descr_ref loc_result;
14835 resolve_one_addr (&rtl, NULL);
14837 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14838 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14839 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14840 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14841 add_AT_loc (die, DW_AT_location, loc_result);
14842 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14848 if (CONSTANT_P (XEXP (rtl, 0)))
14849 return add_const_value_attribute (die, XEXP (rtl, 0));
14852 if (!const_ok_for_output (rtl))
14855 if (dwarf_version >= 4 || !dwarf_strict)
14860 /* In cases where an inlined instance of an inline function is passed
14861 the address of an `auto' variable (which is local to the caller) we
14862 can get a situation where the DECL_RTL of the artificial local
14863 variable (for the inlining) which acts as a stand-in for the
14864 corresponding formal parameter (of the inline function) will look
14865 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14866 exactly a compile-time constant expression, but it isn't the address
14867 of the (artificial) local variable either. Rather, it represents the
14868 *value* which the artificial local variable always has during its
14869 lifetime. We currently have no way to represent such quasi-constant
14870 values in Dwarf, so for now we just punt and generate nothing. */
14878 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
14879 && MEM_READONLY_P (rtl)
14880 && GET_MODE (rtl) == BLKmode)
14882 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
14888 /* No other kinds of rtx should be possible here. */
14889 gcc_unreachable ();
14894 /* Determine whether the evaluation of EXPR references any variables
14895 or functions which aren't otherwise used (and therefore may not be
14898 reference_to_unused (tree * tp, int * walk_subtrees,
14899 void * data ATTRIBUTE_UNUSED)
14901 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
14902 *walk_subtrees = 0;
14904 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
14905 && ! TREE_ASM_WRITTEN (*tp))
14907 /* ??? The C++ FE emits debug information for using decls, so
14908 putting gcc_unreachable here falls over. See PR31899. For now
14909 be conservative. */
14910 else if (!cgraph_global_info_ready
14911 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
14913 else if (TREE_CODE (*tp) == VAR_DECL)
14915 struct varpool_node *node = varpool_get_node (*tp);
14916 if (!node || !node->needed)
14919 else if (TREE_CODE (*tp) == FUNCTION_DECL
14920 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
14922 /* The call graph machinery must have finished analyzing,
14923 optimizing and gimplifying the CU by now.
14924 So if *TP has no call graph node associated
14925 to it, it means *TP will not be emitted. */
14926 if (!cgraph_get_node (*tp))
14929 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
14935 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14936 for use in a later add_const_value_attribute call. */
14939 rtl_for_decl_init (tree init, tree type)
14941 rtx rtl = NULL_RTX;
14945 /* If a variable is initialized with a string constant without embedded
14946 zeros, build CONST_STRING. */
14947 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
14949 tree enttype = TREE_TYPE (type);
14950 tree domain = TYPE_DOMAIN (type);
14951 enum machine_mode mode = TYPE_MODE (enttype);
14953 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
14955 && integer_zerop (TYPE_MIN_VALUE (domain))
14956 && compare_tree_int (TYPE_MAX_VALUE (domain),
14957 TREE_STRING_LENGTH (init) - 1) == 0
14958 && ((size_t) TREE_STRING_LENGTH (init)
14959 == strlen (TREE_STRING_POINTER (init)) + 1))
14961 rtl = gen_rtx_CONST_STRING (VOIDmode,
14962 ggc_strdup (TREE_STRING_POINTER (init)));
14963 rtl = gen_rtx_MEM (BLKmode, rtl);
14964 MEM_READONLY_P (rtl) = 1;
14967 /* Other aggregates, and complex values, could be represented using
14969 else if (AGGREGATE_TYPE_P (type)
14970 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
14971 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
14972 || TREE_CODE (type) == COMPLEX_TYPE)
14974 /* Vectors only work if their mode is supported by the target.
14975 FIXME: generic vectors ought to work too. */
14976 else if (TREE_CODE (type) == VECTOR_TYPE
14977 && !VECTOR_MODE_P (TYPE_MODE (type)))
14979 /* If the initializer is something that we know will expand into an
14980 immediate RTL constant, expand it now. We must be careful not to
14981 reference variables which won't be output. */
14982 else if (initializer_constant_valid_p (init, type)
14983 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
14985 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14987 if (TREE_CODE (type) == VECTOR_TYPE)
14988 switch (TREE_CODE (init))
14993 if (TREE_CONSTANT (init))
14995 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
14996 bool constant_p = true;
14998 unsigned HOST_WIDE_INT ix;
15000 /* Even when ctor is constant, it might contain non-*_CST
15001 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15002 belong into VECTOR_CST nodes. */
15003 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
15004 if (!CONSTANT_CLASS_P (value))
15006 constant_p = false;
15012 init = build_vector_from_ctor (type, elts);
15022 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
15024 /* If expand_expr returns a MEM, it wasn't immediate. */
15025 gcc_assert (!rtl || !MEM_P (rtl));
15031 /* Generate RTL for the variable DECL to represent its location. */
15034 rtl_for_decl_location (tree decl)
15038 /* Here we have to decide where we are going to say the parameter "lives"
15039 (as far as the debugger is concerned). We only have a couple of
15040 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15042 DECL_RTL normally indicates where the parameter lives during most of the
15043 activation of the function. If optimization is enabled however, this
15044 could be either NULL or else a pseudo-reg. Both of those cases indicate
15045 that the parameter doesn't really live anywhere (as far as the code
15046 generation parts of GCC are concerned) during most of the function's
15047 activation. That will happen (for example) if the parameter is never
15048 referenced within the function.
15050 We could just generate a location descriptor here for all non-NULL
15051 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15052 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15053 where DECL_RTL is NULL or is a pseudo-reg.
15055 Note however that we can only get away with using DECL_INCOMING_RTL as
15056 a backup substitute for DECL_RTL in certain limited cases. In cases
15057 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15058 we can be sure that the parameter was passed using the same type as it is
15059 declared to have within the function, and that its DECL_INCOMING_RTL
15060 points us to a place where a value of that type is passed.
15062 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15063 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15064 because in these cases DECL_INCOMING_RTL points us to a value of some
15065 type which is *different* from the type of the parameter itself. Thus,
15066 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15067 such cases, the debugger would end up (for example) trying to fetch a
15068 `float' from a place which actually contains the first part of a
15069 `double'. That would lead to really incorrect and confusing
15070 output at debug-time.
15072 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15073 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15074 are a couple of exceptions however. On little-endian machines we can
15075 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15076 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15077 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15078 when (on a little-endian machine) a non-prototyped function has a
15079 parameter declared to be of type `short' or `char'. In such cases,
15080 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15081 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15082 passed `int' value. If the debugger then uses that address to fetch
15083 a `short' or a `char' (on a little-endian machine) the result will be
15084 the correct data, so we allow for such exceptional cases below.
15086 Note that our goal here is to describe the place where the given formal
15087 parameter lives during most of the function's activation (i.e. between the
15088 end of the prologue and the start of the epilogue). We'll do that as best
15089 as we can. Note however that if the given formal parameter is modified
15090 sometime during the execution of the function, then a stack backtrace (at
15091 debug-time) will show the function as having been called with the *new*
15092 value rather than the value which was originally passed in. This happens
15093 rarely enough that it is not a major problem, but it *is* a problem, and
15094 I'd like to fix it.
15096 A future version of dwarf2out.c may generate two additional attributes for
15097 any given DW_TAG_formal_parameter DIE which will describe the "passed
15098 type" and the "passed location" for the given formal parameter in addition
15099 to the attributes we now generate to indicate the "declared type" and the
15100 "active location" for each parameter. This additional set of attributes
15101 could be used by debuggers for stack backtraces. Separately, note that
15102 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15103 This happens (for example) for inlined-instances of inline function formal
15104 parameters which are never referenced. This really shouldn't be
15105 happening. All PARM_DECL nodes should get valid non-NULL
15106 DECL_INCOMING_RTL values. FIXME. */
15108 /* Use DECL_RTL as the "location" unless we find something better. */
15109 rtl = DECL_RTL_IF_SET (decl);
15111 /* When generating abstract instances, ignore everything except
15112 constants, symbols living in memory, and symbols living in
15113 fixed registers. */
15114 if (! reload_completed)
15117 && (CONSTANT_P (rtl)
15119 && CONSTANT_P (XEXP (rtl, 0)))
15121 && TREE_CODE (decl) == VAR_DECL
15122 && TREE_STATIC (decl))))
15124 rtl = targetm.delegitimize_address (rtl);
15129 else if (TREE_CODE (decl) == PARM_DECL)
15131 if (rtl == NULL_RTX
15132 || is_pseudo_reg (rtl)
15134 && is_pseudo_reg (XEXP (rtl, 0))
15135 && DECL_INCOMING_RTL (decl)
15136 && MEM_P (DECL_INCOMING_RTL (decl))
15137 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
15139 tree declared_type = TREE_TYPE (decl);
15140 tree passed_type = DECL_ARG_TYPE (decl);
15141 enum machine_mode dmode = TYPE_MODE (declared_type);
15142 enum machine_mode pmode = TYPE_MODE (passed_type);
15144 /* This decl represents a formal parameter which was optimized out.
15145 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15146 all cases where (rtl == NULL_RTX) just below. */
15147 if (dmode == pmode)
15148 rtl = DECL_INCOMING_RTL (decl);
15149 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
15150 && SCALAR_INT_MODE_P (dmode)
15151 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
15152 && DECL_INCOMING_RTL (decl))
15154 rtx inc = DECL_INCOMING_RTL (decl);
15157 else if (MEM_P (inc))
15159 if (BYTES_BIG_ENDIAN)
15160 rtl = adjust_address_nv (inc, dmode,
15161 GET_MODE_SIZE (pmode)
15162 - GET_MODE_SIZE (dmode));
15169 /* If the parm was passed in registers, but lives on the stack, then
15170 make a big endian correction if the mode of the type of the
15171 parameter is not the same as the mode of the rtl. */
15172 /* ??? This is the same series of checks that are made in dbxout.c before
15173 we reach the big endian correction code there. It isn't clear if all
15174 of these checks are necessary here, but keeping them all is the safe
15176 else if (MEM_P (rtl)
15177 && XEXP (rtl, 0) != const0_rtx
15178 && ! CONSTANT_P (XEXP (rtl, 0))
15179 /* Not passed in memory. */
15180 && !MEM_P (DECL_INCOMING_RTL (decl))
15181 /* Not passed by invisible reference. */
15182 && (!REG_P (XEXP (rtl, 0))
15183 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
15184 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
15185 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15186 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
15189 /* Big endian correction check. */
15190 && BYTES_BIG_ENDIAN
15191 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
15192 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
15195 int offset = (UNITS_PER_WORD
15196 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
15198 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
15199 plus_constant (XEXP (rtl, 0), offset));
15202 else if (TREE_CODE (decl) == VAR_DECL
15205 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
15206 && BYTES_BIG_ENDIAN)
15208 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
15209 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
15211 /* If a variable is declared "register" yet is smaller than
15212 a register, then if we store the variable to memory, it
15213 looks like we're storing a register-sized value, when in
15214 fact we are not. We need to adjust the offset of the
15215 storage location to reflect the actual value's bytes,
15216 else gdb will not be able to display it. */
15218 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
15219 plus_constant (XEXP (rtl, 0), rsize-dsize));
15222 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15223 and will have been substituted directly into all expressions that use it.
15224 C does not have such a concept, but C++ and other languages do. */
15225 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
15226 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
15229 rtl = targetm.delegitimize_address (rtl);
15231 /* If we don't look past the constant pool, we risk emitting a
15232 reference to a constant pool entry that isn't referenced from
15233 code, and thus is not emitted. */
15235 rtl = avoid_constant_pool_reference (rtl);
15237 /* Try harder to get a rtl. If this symbol ends up not being emitted
15238 in the current CU, resolve_addr will remove the expression referencing
15240 if (rtl == NULL_RTX
15241 && TREE_CODE (decl) == VAR_DECL
15242 && !DECL_EXTERNAL (decl)
15243 && TREE_STATIC (decl)
15244 && DECL_NAME (decl)
15245 && !DECL_HARD_REGISTER (decl)
15246 && DECL_MODE (decl) != VOIDmode)
15248 rtl = make_decl_rtl_for_debug (decl);
15250 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
15251 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
15258 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15259 returned. If so, the decl for the COMMON block is returned, and the
15260 value is the offset into the common block for the symbol. */
15263 fortran_common (tree decl, HOST_WIDE_INT *value)
15265 tree val_expr, cvar;
15266 enum machine_mode mode;
15267 HOST_WIDE_INT bitsize, bitpos;
15269 int volatilep = 0, unsignedp = 0;
15271 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15272 it does not have a value (the offset into the common area), or if it
15273 is thread local (as opposed to global) then it isn't common, and shouldn't
15274 be handled as such. */
15275 if (TREE_CODE (decl) != VAR_DECL
15276 || !TREE_STATIC (decl)
15277 || !DECL_HAS_VALUE_EXPR_P (decl)
15281 val_expr = DECL_VALUE_EXPR (decl);
15282 if (TREE_CODE (val_expr) != COMPONENT_REF)
15285 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
15286 &mode, &unsignedp, &volatilep, true);
15288 if (cvar == NULL_TREE
15289 || TREE_CODE (cvar) != VAR_DECL
15290 || DECL_ARTIFICIAL (cvar)
15291 || !TREE_PUBLIC (cvar))
15295 if (offset != NULL)
15297 if (!host_integerp (offset, 0))
15299 *value = tree_low_cst (offset, 0);
15302 *value += bitpos / BITS_PER_UNIT;
15307 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15308 data attribute for a variable or a parameter. We generate the
15309 DW_AT_const_value attribute only in those cases where the given variable
15310 or parameter does not have a true "location" either in memory or in a
15311 register. This can happen (for example) when a constant is passed as an
15312 actual argument in a call to an inline function. (It's possible that
15313 these things can crop up in other ways also.) Note that one type of
15314 constant value which can be passed into an inlined function is a constant
15315 pointer. This can happen for example if an actual argument in an inlined
15316 function call evaluates to a compile-time constant address.
15318 CACHE_P is true if it is worth caching the location list for DECL,
15319 so that future calls can reuse it rather than regenerate it from scratch.
15320 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15321 since we will need to refer to them each time the function is inlined. */
15324 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
15325 enum dwarf_attribute attr)
15328 dw_loc_list_ref list;
15329 var_loc_list *loc_list;
15330 cached_dw_loc_list *cache;
15333 if (TREE_CODE (decl) == ERROR_MARK)
15336 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
15337 || TREE_CODE (decl) == RESULT_DECL);
15339 /* Try to get some constant RTL for this decl, and use that as the value of
15342 rtl = rtl_for_decl_location (decl);
15343 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
15344 && add_const_value_attribute (die, rtl))
15347 /* See if we have single element location list that is equivalent to
15348 a constant value. That way we are better to use add_const_value_attribute
15349 rather than expanding constant value equivalent. */
15350 loc_list = lookup_decl_loc (decl);
15353 && loc_list->first->next == NULL
15354 && NOTE_P (loc_list->first->loc)
15355 && NOTE_VAR_LOCATION (loc_list->first->loc)
15356 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
15358 struct var_loc_node *node;
15360 node = loc_list->first;
15361 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
15362 if (GET_CODE (rtl) == EXPR_LIST)
15363 rtl = XEXP (rtl, 0);
15364 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
15365 && add_const_value_attribute (die, rtl))
15368 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15369 list several times. See if we've already cached the contents. */
15371 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
15375 cache = (cached_dw_loc_list *)
15376 htab_find_with_hash (cached_dw_loc_list_table, decl, DECL_UID (decl));
15378 list = cache->loc_list;
15382 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
15383 /* It is usually worth caching this result if the decl is from
15384 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15385 if (cache_p && list && list->dw_loc_next)
15387 slot = htab_find_slot_with_hash (cached_dw_loc_list_table, decl,
15388 DECL_UID (decl), INSERT);
15389 cache = ggc_alloc_cleared_cached_dw_loc_list ();
15390 cache->decl_id = DECL_UID (decl);
15391 cache->loc_list = list;
15397 add_AT_location_description (die, attr, list);
15400 /* None of that worked, so it must not really have a location;
15401 try adding a constant value attribute from the DECL_INITIAL. */
15402 return tree_add_const_value_attribute_for_decl (die, decl);
15405 /* Add VARIABLE and DIE into deferred locations list. */
15408 defer_location (tree variable, dw_die_ref die)
15410 deferred_locations entry;
15411 entry.variable = variable;
15413 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
15416 /* Helper function for tree_add_const_value_attribute. Natively encode
15417 initializer INIT into an array. Return true if successful. */
15420 native_encode_initializer (tree init, unsigned char *array, int size)
15424 if (init == NULL_TREE)
15428 switch (TREE_CODE (init))
15431 type = TREE_TYPE (init);
15432 if (TREE_CODE (type) == ARRAY_TYPE)
15434 tree enttype = TREE_TYPE (type);
15435 enum machine_mode mode = TYPE_MODE (enttype);
15437 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
15439 if (int_size_in_bytes (type) != size)
15441 if (size > TREE_STRING_LENGTH (init))
15443 memcpy (array, TREE_STRING_POINTER (init),
15444 TREE_STRING_LENGTH (init));
15445 memset (array + TREE_STRING_LENGTH (init),
15446 '\0', size - TREE_STRING_LENGTH (init));
15449 memcpy (array, TREE_STRING_POINTER (init), size);
15454 type = TREE_TYPE (init);
15455 if (int_size_in_bytes (type) != size)
15457 if (TREE_CODE (type) == ARRAY_TYPE)
15459 HOST_WIDE_INT min_index;
15460 unsigned HOST_WIDE_INT cnt;
15461 int curpos = 0, fieldsize;
15462 constructor_elt *ce;
15464 if (TYPE_DOMAIN (type) == NULL_TREE
15465 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
15468 fieldsize = int_size_in_bytes (TREE_TYPE (type));
15469 if (fieldsize <= 0)
15472 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
15473 memset (array, '\0', size);
15474 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
15476 tree val = ce->value;
15477 tree index = ce->index;
15479 if (index && TREE_CODE (index) == RANGE_EXPR)
15480 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
15483 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
15488 if (!native_encode_initializer (val, array + pos, fieldsize))
15491 curpos = pos + fieldsize;
15492 if (index && TREE_CODE (index) == RANGE_EXPR)
15494 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
15495 - tree_low_cst (TREE_OPERAND (index, 0), 0);
15496 while (count-- > 0)
15499 memcpy (array + curpos, array + pos, fieldsize);
15500 curpos += fieldsize;
15503 gcc_assert (curpos <= size);
15507 else if (TREE_CODE (type) == RECORD_TYPE
15508 || TREE_CODE (type) == UNION_TYPE)
15510 tree field = NULL_TREE;
15511 unsigned HOST_WIDE_INT cnt;
15512 constructor_elt *ce;
15514 if (int_size_in_bytes (type) != size)
15517 if (TREE_CODE (type) == RECORD_TYPE)
15518 field = TYPE_FIELDS (type);
15520 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
15522 tree val = ce->value;
15523 int pos, fieldsize;
15525 if (ce->index != 0)
15531 if (field == NULL_TREE || DECL_BIT_FIELD (field))
15534 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
15535 && TYPE_DOMAIN (TREE_TYPE (field))
15536 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
15538 else if (DECL_SIZE_UNIT (field) == NULL_TREE
15539 || !host_integerp (DECL_SIZE_UNIT (field), 0))
15541 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
15542 pos = int_byte_position (field);
15543 gcc_assert (pos + fieldsize <= size);
15545 && !native_encode_initializer (val, array + pos, fieldsize))
15551 case VIEW_CONVERT_EXPR:
15552 case NON_LVALUE_EXPR:
15553 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
15555 return native_encode_expr (init, array, size) == size;
15559 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15560 attribute is the const value T. */
15563 tree_add_const_value_attribute (dw_die_ref die, tree t)
15566 tree type = TREE_TYPE (t);
15569 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
15573 gcc_assert (!DECL_P (init));
15575 rtl = rtl_for_decl_init (init, type);
15577 return add_const_value_attribute (die, rtl);
15578 /* If the host and target are sane, try harder. */
15579 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
15580 && initializer_constant_valid_p (init, type))
15582 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
15583 if (size > 0 && (int) size == size)
15585 unsigned char *array = (unsigned char *)
15586 ggc_alloc_cleared_atomic (size);
15588 if (native_encode_initializer (init, array, size))
15590 add_AT_vec (die, DW_AT_const_value, size, 1, array);
15598 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15599 attribute is the const value of T, where T is an integral constant
15600 variable with static storage duration
15601 (so it can't be a PARM_DECL or a RESULT_DECL). */
15604 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
15608 || (TREE_CODE (decl) != VAR_DECL
15609 && TREE_CODE (decl) != CONST_DECL)
15610 || (TREE_CODE (decl) == VAR_DECL
15611 && !TREE_STATIC (decl)))
15614 if (TREE_READONLY (decl)
15615 && ! TREE_THIS_VOLATILE (decl)
15616 && DECL_INITIAL (decl))
15621 /* Don't add DW_AT_const_value if abstract origin already has one. */
15622 if (get_AT (var_die, DW_AT_const_value))
15625 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
15628 /* Convert the CFI instructions for the current function into a
15629 location list. This is used for DW_AT_frame_base when we targeting
15630 a dwarf2 consumer that does not support the dwarf3
15631 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15634 static dw_loc_list_ref
15635 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
15639 dw_loc_list_ref list, *list_tail;
15641 dw_cfa_location last_cfa, next_cfa;
15642 const char *start_label, *last_label, *section;
15643 dw_cfa_location remember;
15645 fde = current_fde ();
15646 gcc_assert (fde != NULL);
15648 section = secname_for_decl (current_function_decl);
15652 memset (&next_cfa, 0, sizeof (next_cfa));
15653 next_cfa.reg = INVALID_REGNUM;
15654 remember = next_cfa;
15656 start_label = fde->dw_fde_begin;
15658 /* ??? Bald assumption that the CIE opcode list does not contain
15659 advance opcodes. */
15660 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
15661 lookup_cfa_1 (cfi, &next_cfa, &remember);
15663 last_cfa = next_cfa;
15664 last_label = start_label;
15666 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
15668 /* If the first partition contained no CFI adjustments, the
15669 CIE opcodes apply to the whole first partition. */
15670 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15671 fde->dw_fde_begin, fde->dw_fde_end, section);
15672 list_tail =&(*list_tail)->dw_loc_next;
15673 start_label = last_label = fde->dw_fde_second_begin;
15676 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
15678 switch (cfi->dw_cfi_opc)
15680 case DW_CFA_set_loc:
15681 case DW_CFA_advance_loc1:
15682 case DW_CFA_advance_loc2:
15683 case DW_CFA_advance_loc4:
15684 if (!cfa_equal_p (&last_cfa, &next_cfa))
15686 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15687 start_label, last_label, section);
15689 list_tail = &(*list_tail)->dw_loc_next;
15690 last_cfa = next_cfa;
15691 start_label = last_label;
15693 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
15696 case DW_CFA_advance_loc:
15697 /* The encoding is complex enough that we should never emit this. */
15698 gcc_unreachable ();
15701 lookup_cfa_1 (cfi, &next_cfa, &remember);
15704 if (ix + 1 == fde->dw_fde_switch_cfi_index)
15706 if (!cfa_equal_p (&last_cfa, &next_cfa))
15708 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15709 start_label, last_label, section);
15711 list_tail = &(*list_tail)->dw_loc_next;
15712 last_cfa = next_cfa;
15713 start_label = last_label;
15715 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15716 start_label, fde->dw_fde_end, section);
15717 list_tail = &(*list_tail)->dw_loc_next;
15718 start_label = last_label = fde->dw_fde_second_begin;
15722 if (!cfa_equal_p (&last_cfa, &next_cfa))
15724 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15725 start_label, last_label, section);
15726 list_tail = &(*list_tail)->dw_loc_next;
15727 start_label = last_label;
15730 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
15732 fde->dw_fde_second_begin
15733 ? fde->dw_fde_second_end : fde->dw_fde_end,
15736 if (list && list->dw_loc_next)
15742 /* Compute a displacement from the "steady-state frame pointer" to the
15743 frame base (often the same as the CFA), and store it in
15744 frame_pointer_fb_offset. OFFSET is added to the displacement
15745 before the latter is negated. */
15748 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
15752 #ifdef FRAME_POINTER_CFA_OFFSET
15753 reg = frame_pointer_rtx;
15754 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
15756 reg = arg_pointer_rtx;
15757 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
15760 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
15761 if (GET_CODE (elim) == PLUS)
15763 offset += INTVAL (XEXP (elim, 1));
15764 elim = XEXP (elim, 0);
15767 frame_pointer_fb_offset = -offset;
15769 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15770 in which to eliminate. This is because it's stack pointer isn't
15771 directly accessible as a register within the ISA. To work around
15772 this, assume that while we cannot provide a proper value for
15773 frame_pointer_fb_offset, we won't need one either. */
15774 frame_pointer_fb_offset_valid
15775 = ((SUPPORTS_STACK_ALIGNMENT
15776 && (elim == hard_frame_pointer_rtx
15777 || elim == stack_pointer_rtx))
15778 || elim == (frame_pointer_needed
15779 ? hard_frame_pointer_rtx
15780 : stack_pointer_rtx));
15783 /* Generate a DW_AT_name attribute given some string value to be included as
15784 the value of the attribute. */
15787 add_name_attribute (dw_die_ref die, const char *name_string)
15789 if (name_string != NULL && *name_string != 0)
15791 if (demangle_name_func)
15792 name_string = (*demangle_name_func) (name_string);
15794 add_AT_string (die, DW_AT_name, name_string);
15798 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15799 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15800 of TYPE accordingly.
15802 ??? This is a temporary measure until after we're able to generate
15803 regular DWARF for the complex Ada type system. */
15806 add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
15807 dw_die_ref context_die)
15810 dw_die_ref dtype_die;
15812 if (!lang_hooks.types.descriptive_type)
15815 dtype = lang_hooks.types.descriptive_type (type);
15819 dtype_die = lookup_type_die (dtype);
15822 gen_type_die (dtype, context_die);
15823 dtype_die = lookup_type_die (dtype);
15824 gcc_assert (dtype_die);
15827 add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
15830 /* Generate a DW_AT_comp_dir attribute for DIE. */
15833 add_comp_dir_attribute (dw_die_ref die)
15835 const char *wd = get_src_pwd ();
15841 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
15845 wdlen = strlen (wd);
15846 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
15848 wd1 [wdlen] = DIR_SEPARATOR;
15849 wd1 [wdlen + 1] = 0;
15853 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
15856 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15860 lower_bound_default (void)
15862 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
15867 case DW_LANG_C_plus_plus:
15869 case DW_LANG_ObjC_plus_plus:
15872 case DW_LANG_Fortran77:
15873 case DW_LANG_Fortran90:
15874 case DW_LANG_Fortran95:
15878 case DW_LANG_Python:
15879 return dwarf_version >= 4 ? 0 : -1;
15880 case DW_LANG_Ada95:
15881 case DW_LANG_Ada83:
15882 case DW_LANG_Cobol74:
15883 case DW_LANG_Cobol85:
15884 case DW_LANG_Pascal83:
15885 case DW_LANG_Modula2:
15887 return dwarf_version >= 4 ? 1 : -1;
15893 /* Given a tree node describing an array bound (either lower or upper) output
15894 a representation for that bound. */
15897 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
15899 switch (TREE_CODE (bound))
15904 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15907 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
15910 /* Use the default if possible. */
15911 if (bound_attr == DW_AT_lower_bound
15912 && host_integerp (bound, 0)
15913 && (dflt = lower_bound_default ()) != -1
15914 && tree_low_cst (bound, 0) == dflt)
15917 /* Otherwise represent the bound as an unsigned value with the
15918 precision of its type. The precision and signedness of the
15919 type will be necessary to re-interpret it unambiguously. */
15920 else if (prec < HOST_BITS_PER_WIDE_INT)
15922 unsigned HOST_WIDE_INT mask
15923 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
15924 add_AT_unsigned (subrange_die, bound_attr,
15925 TREE_INT_CST_LOW (bound) & mask);
15927 else if (prec == HOST_BITS_PER_WIDE_INT
15928 || TREE_INT_CST_HIGH (bound) == 0)
15929 add_AT_unsigned (subrange_die, bound_attr,
15930 TREE_INT_CST_LOW (bound));
15932 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
15933 TREE_INT_CST_LOW (bound));
15938 case VIEW_CONVERT_EXPR:
15939 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
15949 dw_die_ref decl_die = lookup_decl_die (bound);
15951 /* ??? Can this happen, or should the variable have been bound
15952 first? Probably it can, since I imagine that we try to create
15953 the types of parameters in the order in which they exist in
15954 the list, and won't have created a forward reference to a
15955 later parameter. */
15956 if (decl_die != NULL)
15958 add_AT_die_ref (subrange_die, bound_attr, decl_die);
15966 /* Otherwise try to create a stack operation procedure to
15967 evaluate the value of the array bound. */
15969 dw_die_ref ctx, decl_die;
15970 dw_loc_list_ref list;
15972 list = loc_list_from_tree (bound, 2);
15973 if (list == NULL || single_element_loc_list_p (list))
15975 /* If DW_AT_*bound is not a reference nor constant, it is
15976 a DWARF expression rather than location description.
15977 For that loc_list_from_tree (bound, 0) is needed.
15978 If that fails to give a single element list,
15979 fall back to outputting this as a reference anyway. */
15980 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
15981 if (list2 && single_element_loc_list_p (list2))
15983 add_AT_loc (subrange_die, bound_attr, list2->expr);
15990 if (current_function_decl == 0)
15991 ctx = comp_unit_die ();
15993 ctx = lookup_decl_die (current_function_decl);
15995 decl_die = new_die (DW_TAG_variable, ctx, bound);
15996 add_AT_flag (decl_die, DW_AT_artificial, 1);
15997 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
15998 add_AT_location_description (decl_die, DW_AT_location, list);
15999 add_AT_die_ref (subrange_die, bound_attr, decl_die);
16005 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16006 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16007 Note that the block of subscript information for an array type also
16008 includes information about the element type of the given array type. */
16011 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
16013 unsigned dimension_number;
16015 dw_die_ref subrange_die;
16017 for (dimension_number = 0;
16018 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
16019 type = TREE_TYPE (type), dimension_number++)
16021 tree domain = TYPE_DOMAIN (type);
16023 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
16026 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16027 and (in GNU C only) variable bounds. Handle all three forms
16029 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
16032 /* We have an array type with specified bounds. */
16033 lower = TYPE_MIN_VALUE (domain);
16034 upper = TYPE_MAX_VALUE (domain);
16036 /* Define the index type. */
16037 if (TREE_TYPE (domain))
16039 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16040 TREE_TYPE field. We can't emit debug info for this
16041 because it is an unnamed integral type. */
16042 if (TREE_CODE (domain) == INTEGER_TYPE
16043 && TYPE_NAME (domain) == NULL_TREE
16044 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
16045 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
16048 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
16052 /* ??? If upper is NULL, the array has unspecified length,
16053 but it does have a lower bound. This happens with Fortran
16055 Since the debugger is definitely going to need to know N
16056 to produce useful results, go ahead and output the lower
16057 bound solo, and hope the debugger can cope. */
16059 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
16061 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
16064 /* Otherwise we have an array type with an unspecified length. The
16065 DWARF-2 spec does not say how to handle this; let's just leave out the
16071 add_byte_size_attribute (dw_die_ref die, tree tree_node)
16075 switch (TREE_CODE (tree_node))
16080 case ENUMERAL_TYPE:
16083 case QUAL_UNION_TYPE:
16084 size = int_size_in_bytes (tree_node);
16087 /* For a data member of a struct or union, the DW_AT_byte_size is
16088 generally given as the number of bytes normally allocated for an
16089 object of the *declared* type of the member itself. This is true
16090 even for bit-fields. */
16091 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
16094 gcc_unreachable ();
16097 /* Note that `size' might be -1 when we get to this point. If it is, that
16098 indicates that the byte size of the entity in question is variable. We
16099 have no good way of expressing this fact in Dwarf at the present time,
16100 so just let the -1 pass on through. */
16101 add_AT_unsigned (die, DW_AT_byte_size, size);
16104 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16105 which specifies the distance in bits from the highest order bit of the
16106 "containing object" for the bit-field to the highest order bit of the
16109 For any given bit-field, the "containing object" is a hypothetical object
16110 (of some integral or enum type) within which the given bit-field lives. The
16111 type of this hypothetical "containing object" is always the same as the
16112 declared type of the individual bit-field itself. The determination of the
16113 exact location of the "containing object" for a bit-field is rather
16114 complicated. It's handled by the `field_byte_offset' function (above).
16116 Note that it is the size (in bytes) of the hypothetical "containing object"
16117 which will be given in the DW_AT_byte_size attribute for this bit-field.
16118 (See `byte_size_attribute' above). */
16121 add_bit_offset_attribute (dw_die_ref die, tree decl)
16123 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
16124 tree type = DECL_BIT_FIELD_TYPE (decl);
16125 HOST_WIDE_INT bitpos_int;
16126 HOST_WIDE_INT highest_order_object_bit_offset;
16127 HOST_WIDE_INT highest_order_field_bit_offset;
16128 HOST_WIDE_INT bit_offset;
16130 /* Must be a field and a bit field. */
16131 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
16133 /* We can't yet handle bit-fields whose offsets are variable, so if we
16134 encounter such things, just return without generating any attribute
16135 whatsoever. Likewise for variable or too large size. */
16136 if (! host_integerp (bit_position (decl), 0)
16137 || ! host_integerp (DECL_SIZE (decl), 1))
16140 bitpos_int = int_bit_position (decl);
16142 /* Note that the bit offset is always the distance (in bits) from the
16143 highest-order bit of the "containing object" to the highest-order bit of
16144 the bit-field itself. Since the "high-order end" of any object or field
16145 is different on big-endian and little-endian machines, the computation
16146 below must take account of these differences. */
16147 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
16148 highest_order_field_bit_offset = bitpos_int;
16150 if (! BYTES_BIG_ENDIAN)
16152 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
16153 highest_order_object_bit_offset += simple_type_size_in_bits (type);
16157 = (! BYTES_BIG_ENDIAN
16158 ? highest_order_object_bit_offset - highest_order_field_bit_offset
16159 : highest_order_field_bit_offset - highest_order_object_bit_offset);
16161 if (bit_offset < 0)
16162 add_AT_int (die, DW_AT_bit_offset, bit_offset);
16164 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
16167 /* For a FIELD_DECL node which represents a bit field, output an attribute
16168 which specifies the length in bits of the given field. */
16171 add_bit_size_attribute (dw_die_ref die, tree decl)
16173 /* Must be a field and a bit field. */
16174 gcc_assert (TREE_CODE (decl) == FIELD_DECL
16175 && DECL_BIT_FIELD_TYPE (decl));
16177 if (host_integerp (DECL_SIZE (decl), 1))
16178 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
16181 /* If the compiled language is ANSI C, then add a 'prototyped'
16182 attribute, if arg types are given for the parameters of a function. */
16185 add_prototyped_attribute (dw_die_ref die, tree func_type)
16187 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
16188 && prototype_p (func_type))
16189 add_AT_flag (die, DW_AT_prototyped, 1);
16192 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16193 by looking in either the type declaration or object declaration
16196 static inline dw_die_ref
16197 add_abstract_origin_attribute (dw_die_ref die, tree origin)
16199 dw_die_ref origin_die = NULL;
16201 if (TREE_CODE (origin) != FUNCTION_DECL)
16203 /* We may have gotten separated from the block for the inlined
16204 function, if we're in an exception handler or some such; make
16205 sure that the abstract function has been written out.
16207 Doing this for nested functions is wrong, however; functions are
16208 distinct units, and our context might not even be inline. */
16212 fn = TYPE_STUB_DECL (fn);
16214 fn = decl_function_context (fn);
16216 dwarf2out_abstract_function (fn);
16219 if (DECL_P (origin))
16220 origin_die = lookup_decl_die (origin);
16221 else if (TYPE_P (origin))
16222 origin_die = lookup_type_die (origin);
16224 /* XXX: Functions that are never lowered don't always have correct block
16225 trees (in the case of java, they simply have no block tree, in some other
16226 languages). For these functions, there is nothing we can really do to
16227 output correct debug info for inlined functions in all cases. Rather
16228 than die, we'll just produce deficient debug info now, in that we will
16229 have variables without a proper abstract origin. In the future, when all
16230 functions are lowered, we should re-add a gcc_assert (origin_die)
16234 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
16238 /* We do not currently support the pure_virtual attribute. */
16241 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
16243 if (DECL_VINDEX (func_decl))
16245 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
16247 if (host_integerp (DECL_VINDEX (func_decl), 0))
16248 add_AT_loc (die, DW_AT_vtable_elem_location,
16249 new_loc_descr (DW_OP_constu,
16250 tree_low_cst (DECL_VINDEX (func_decl), 0),
16253 /* GNU extension: Record what type this method came from originally. */
16254 if (debug_info_level > DINFO_LEVEL_TERSE
16255 && DECL_CONTEXT (func_decl))
16256 add_AT_die_ref (die, DW_AT_containing_type,
16257 lookup_type_die (DECL_CONTEXT (func_decl)));
16261 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16262 given decl. This used to be a vendor extension until after DWARF 4
16263 standardized it. */
16266 add_linkage_attr (dw_die_ref die, tree decl)
16268 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
16270 /* Mimic what assemble_name_raw does with a leading '*'. */
16271 if (name[0] == '*')
16274 if (dwarf_version >= 4)
16275 add_AT_string (die, DW_AT_linkage_name, name);
16277 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
16280 /* Add source coordinate attributes for the given decl. */
16283 add_src_coords_attributes (dw_die_ref die, tree decl)
16285 expanded_location s;
16287 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
16289 s = expand_location (DECL_SOURCE_LOCATION (decl));
16290 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
16291 add_AT_unsigned (die, DW_AT_decl_line, s.line);
16294 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16297 add_linkage_name (dw_die_ref die, tree decl)
16299 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
16300 && TREE_PUBLIC (decl)
16301 && !DECL_ABSTRACT (decl)
16302 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
16303 && die->die_tag != DW_TAG_member)
16305 /* Defer until we have an assembler name set. */
16306 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
16308 limbo_die_node *asm_name;
16310 asm_name = ggc_alloc_cleared_limbo_die_node ();
16311 asm_name->die = die;
16312 asm_name->created_for = decl;
16313 asm_name->next = deferred_asm_name;
16314 deferred_asm_name = asm_name;
16316 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
16317 add_linkage_attr (die, decl);
16321 /* Add a DW_AT_name attribute and source coordinate attribute for the
16322 given decl, but only if it actually has a name. */
16325 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
16329 decl_name = DECL_NAME (decl);
16330 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
16332 const char *name = dwarf2_name (decl, 0);
16334 add_name_attribute (die, name);
16335 if (! DECL_ARTIFICIAL (decl))
16336 add_src_coords_attributes (die, decl);
16338 add_linkage_name (die, decl);
16341 #ifdef VMS_DEBUGGING_INFO
16342 /* Get the function's name, as described by its RTL. This may be different
16343 from the DECL_NAME name used in the source file. */
16344 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
16346 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
16347 XEXP (DECL_RTL (decl), 0));
16348 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
16350 #endif /* VMS_DEBUGGING_INFO */
16353 #ifdef VMS_DEBUGGING_INFO
16354 /* Output the debug main pointer die for VMS */
16357 dwarf2out_vms_debug_main_pointer (void)
16359 char label[MAX_ARTIFICIAL_LABEL_BYTES];
16362 /* Allocate the VMS debug main subprogram die. */
16363 die = ggc_alloc_cleared_die_node ();
16364 die->die_tag = DW_TAG_subprogram;
16365 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
16366 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
16367 current_function_funcdef_no);
16368 add_AT_lbl_id (die, DW_AT_entry_pc, label);
16370 /* Make it the first child of comp_unit_die (). */
16371 die->die_parent = comp_unit_die ();
16372 if (comp_unit_die ()->die_child)
16374 die->die_sib = comp_unit_die ()->die_child->die_sib;
16375 comp_unit_die ()->die_child->die_sib = die;
16379 die->die_sib = die;
16380 comp_unit_die ()->die_child = die;
16383 #endif /* VMS_DEBUGGING_INFO */
16385 /* Push a new declaration scope. */
16388 push_decl_scope (tree scope)
16390 VEC_safe_push (tree, gc, decl_scope_table, scope);
16393 /* Pop a declaration scope. */
16396 pop_decl_scope (void)
16398 VEC_pop (tree, decl_scope_table);
16401 /* Return the DIE for the scope that immediately contains this type.
16402 Non-named types get global scope. Named types nested in other
16403 types get their containing scope if it's open, or global scope
16404 otherwise. All other types (i.e. function-local named types) get
16405 the current active scope. */
16408 scope_die_for (tree t, dw_die_ref context_die)
16410 dw_die_ref scope_die = NULL;
16411 tree containing_scope;
16414 /* Non-types always go in the current scope. */
16415 gcc_assert (TYPE_P (t));
16417 containing_scope = TYPE_CONTEXT (t);
16419 /* Use the containing namespace if it was passed in (for a declaration). */
16420 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
16422 if (context_die == lookup_decl_die (containing_scope))
16425 containing_scope = NULL_TREE;
16428 /* Ignore function type "scopes" from the C frontend. They mean that
16429 a tagged type is local to a parmlist of a function declarator, but
16430 that isn't useful to DWARF. */
16431 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
16432 containing_scope = NULL_TREE;
16434 if (SCOPE_FILE_SCOPE_P (containing_scope))
16435 scope_die = comp_unit_die ();
16436 else if (TYPE_P (containing_scope))
16438 /* For types, we can just look up the appropriate DIE. But
16439 first we check to see if we're in the middle of emitting it
16440 so we know where the new DIE should go. */
16441 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
16442 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
16447 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
16448 || TREE_ASM_WRITTEN (containing_scope));
16449 /*We are not in the middle of emitting the type
16450 CONTAINING_SCOPE. Let's see if it's emitted already. */
16451 scope_die = lookup_type_die (containing_scope);
16453 /* If none of the current dies are suitable, we get file scope. */
16454 if (scope_die == NULL)
16455 scope_die = comp_unit_die ();
16458 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
16461 scope_die = context_die;
16466 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16469 local_scope_p (dw_die_ref context_die)
16471 for (; context_die; context_die = context_die->die_parent)
16472 if (context_die->die_tag == DW_TAG_inlined_subroutine
16473 || context_die->die_tag == DW_TAG_subprogram)
16479 /* Returns nonzero if CONTEXT_DIE is a class. */
16482 class_scope_p (dw_die_ref context_die)
16484 return (context_die
16485 && (context_die->die_tag == DW_TAG_structure_type
16486 || context_die->die_tag == DW_TAG_class_type
16487 || context_die->die_tag == DW_TAG_interface_type
16488 || context_die->die_tag == DW_TAG_union_type));
16491 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16492 whether or not to treat a DIE in this context as a declaration. */
16495 class_or_namespace_scope_p (dw_die_ref context_die)
16497 return (class_scope_p (context_die)
16498 || (context_die && context_die->die_tag == DW_TAG_namespace));
16501 /* Many forms of DIEs require a "type description" attribute. This
16502 routine locates the proper "type descriptor" die for the type given
16503 by 'type', and adds a DW_AT_type attribute below the given die. */
16506 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
16507 int decl_volatile, dw_die_ref context_die)
16509 enum tree_code code = TREE_CODE (type);
16510 dw_die_ref type_die = NULL;
16512 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16513 or fixed-point type, use the inner type. This is because we have no
16514 support for unnamed types in base_type_die. This can happen if this is
16515 an Ada subrange type. Correct solution is emit a subrange type die. */
16516 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
16517 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
16518 type = TREE_TYPE (type), code = TREE_CODE (type);
16520 if (code == ERROR_MARK
16521 /* Handle a special case. For functions whose return type is void, we
16522 generate *no* type attribute. (Note that no object may have type
16523 `void', so this only applies to function return types). */
16524 || code == VOID_TYPE)
16527 type_die = modified_type_die (type,
16528 decl_const || TYPE_READONLY (type),
16529 decl_volatile || TYPE_VOLATILE (type),
16532 if (type_die != NULL)
16533 add_AT_die_ref (object_die, DW_AT_type, type_die);
16536 /* Given an object die, add the calling convention attribute for the
16537 function call type. */
16539 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
16541 enum dwarf_calling_convention value = DW_CC_normal;
16543 value = ((enum dwarf_calling_convention)
16544 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
16547 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
16549 /* DWARF 2 doesn't provide a way to identify a program's source-level
16550 entry point. DW_AT_calling_convention attributes are only meant
16551 to describe functions' calling conventions. However, lacking a
16552 better way to signal the Fortran main program, we used this for
16553 a long time, following existing custom. Now, DWARF 4 has
16554 DW_AT_main_subprogram, which we add below, but some tools still
16555 rely on the old way, which we thus keep. */
16556 value = DW_CC_program;
16558 if (dwarf_version >= 4 || !dwarf_strict)
16559 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
16562 /* Only add the attribute if the backend requests it, and
16563 is not DW_CC_normal. */
16564 if (value && (value != DW_CC_normal))
16565 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
16568 /* Given a tree pointer to a struct, class, union, or enum type node, return
16569 a pointer to the (string) tag name for the given type, or zero if the type
16570 was declared without a tag. */
16572 static const char *
16573 type_tag (const_tree type)
16575 const char *name = 0;
16577 if (TYPE_NAME (type) != 0)
16581 /* Find the IDENTIFIER_NODE for the type name. */
16582 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
16583 && !TYPE_NAMELESS (type))
16584 t = TYPE_NAME (type);
16586 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16587 a TYPE_DECL node, regardless of whether or not a `typedef' was
16589 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
16590 && ! DECL_IGNORED_P (TYPE_NAME (type)))
16592 /* We want to be extra verbose. Don't call dwarf_name if
16593 DECL_NAME isn't set. The default hook for decl_printable_name
16594 doesn't like that, and in this context it's correct to return
16595 0, instead of "<anonymous>" or the like. */
16596 if (DECL_NAME (TYPE_NAME (type))
16597 && !DECL_NAMELESS (TYPE_NAME (type)))
16598 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
16601 /* Now get the name as a string, or invent one. */
16602 if (!name && t != 0)
16603 name = IDENTIFIER_POINTER (t);
16606 return (name == 0 || *name == '\0') ? 0 : name;
16609 /* Return the type associated with a data member, make a special check
16610 for bit field types. */
16613 member_declared_type (const_tree member)
16615 return (DECL_BIT_FIELD_TYPE (member)
16616 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
16619 /* Get the decl's label, as described by its RTL. This may be different
16620 from the DECL_NAME name used in the source file. */
16623 static const char *
16624 decl_start_label (tree decl)
16627 const char *fnname;
16629 x = DECL_RTL (decl);
16630 gcc_assert (MEM_P (x));
16633 gcc_assert (GET_CODE (x) == SYMBOL_REF);
16635 fnname = XSTR (x, 0);
16640 /* These routines generate the internal representation of the DIE's for
16641 the compilation unit. Debugging information is collected by walking
16642 the declaration trees passed in from dwarf2out_decl(). */
16645 gen_array_type_die (tree type, dw_die_ref context_die)
16647 dw_die_ref scope_die = scope_die_for (type, context_die);
16648 dw_die_ref array_die;
16650 /* GNU compilers represent multidimensional array types as sequences of one
16651 dimensional array types whose element types are themselves array types.
16652 We sometimes squish that down to a single array_type DIE with multiple
16653 subscripts in the Dwarf debugging info. The draft Dwarf specification
16654 say that we are allowed to do this kind of compression in C, because
16655 there is no difference between an array of arrays and a multidimensional
16656 array. We don't do this for Ada to remain as close as possible to the
16657 actual representation, which is especially important against the language
16658 flexibilty wrt arrays of variable size. */
16660 bool collapse_nested_arrays = !is_ada ();
16663 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16664 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16665 if (TYPE_STRING_FLAG (type)
16666 && TREE_CODE (type) == ARRAY_TYPE
16668 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
16670 HOST_WIDE_INT size;
16672 array_die = new_die (DW_TAG_string_type, scope_die, type);
16673 add_name_attribute (array_die, type_tag (type));
16674 equate_type_number_to_die (type, array_die);
16675 size = int_size_in_bytes (type);
16677 add_AT_unsigned (array_die, DW_AT_byte_size, size);
16678 else if (TYPE_DOMAIN (type) != NULL_TREE
16679 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
16680 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
16682 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
16683 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
16685 size = int_size_in_bytes (TREE_TYPE (szdecl));
16686 if (loc && size > 0)
16688 add_AT_location_description (array_die, DW_AT_string_length, loc);
16689 if (size != DWARF2_ADDR_SIZE)
16690 add_AT_unsigned (array_die, DW_AT_byte_size, size);
16696 /* ??? The SGI dwarf reader fails for array of array of enum types
16697 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
16698 array type comes before the outer array type. We thus call gen_type_die
16699 before we new_die and must prevent nested array types collapsing for this
16702 #ifdef MIPS_DEBUGGING_INFO
16703 gen_type_die (TREE_TYPE (type), context_die);
16704 collapse_nested_arrays = false;
16707 array_die = new_die (DW_TAG_array_type, scope_die, type);
16708 add_name_attribute (array_die, type_tag (type));
16709 add_gnat_descriptive_type_attribute (array_die, type, context_die);
16710 if (TYPE_ARTIFICIAL (type))
16711 add_AT_flag (array_die, DW_AT_artificial, 1);
16712 equate_type_number_to_die (type, array_die);
16714 if (TREE_CODE (type) == VECTOR_TYPE)
16715 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
16717 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16719 && TREE_CODE (type) == ARRAY_TYPE
16720 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
16721 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
16722 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
16725 /* We default the array ordering. SDB will probably do
16726 the right things even if DW_AT_ordering is not present. It's not even
16727 an issue until we start to get into multidimensional arrays anyway. If
16728 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16729 then we'll have to put the DW_AT_ordering attribute back in. (But if
16730 and when we find out that we need to put these in, we will only do so
16731 for multidimensional arrays. */
16732 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
16735 #ifdef MIPS_DEBUGGING_INFO
16736 /* The SGI compilers handle arrays of unknown bound by setting
16737 AT_declaration and not emitting any subrange DIEs. */
16738 if (TREE_CODE (type) == ARRAY_TYPE
16739 && ! TYPE_DOMAIN (type))
16740 add_AT_flag (array_die, DW_AT_declaration, 1);
16743 if (TREE_CODE (type) == VECTOR_TYPE)
16745 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16746 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
16747 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
16748 add_bound_info (subrange_die, DW_AT_upper_bound,
16749 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
16752 add_subscript_info (array_die, type, collapse_nested_arrays);
16754 /* Add representation of the type of the elements of this array type and
16755 emit the corresponding DIE if we haven't done it already. */
16756 element_type = TREE_TYPE (type);
16757 if (collapse_nested_arrays)
16758 while (TREE_CODE (element_type) == ARRAY_TYPE)
16760 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
16762 element_type = TREE_TYPE (element_type);
16765 #ifndef MIPS_DEBUGGING_INFO
16766 gen_type_die (element_type, context_die);
16769 add_type_attribute (array_die, element_type, 0, 0, context_die);
16771 if (get_AT (array_die, DW_AT_name))
16772 add_pubtype (type, array_die);
16775 static dw_loc_descr_ref
16776 descr_info_loc (tree val, tree base_decl)
16778 HOST_WIDE_INT size;
16779 dw_loc_descr_ref loc, loc2;
16780 enum dwarf_location_atom op;
16782 if (val == base_decl)
16783 return new_loc_descr (DW_OP_push_object_address, 0, 0);
16785 switch (TREE_CODE (val))
16788 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16790 return loc_descriptor_from_tree (val, 0);
16792 if (host_integerp (val, 0))
16793 return int_loc_descriptor (tree_low_cst (val, 0));
16796 size = int_size_in_bytes (TREE_TYPE (val));
16799 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16802 if (size == DWARF2_ADDR_SIZE)
16803 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
16805 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
16807 case POINTER_PLUS_EXPR:
16809 if (host_integerp (TREE_OPERAND (val, 1), 1)
16810 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
16813 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16816 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
16822 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16825 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
16828 add_loc_descr (&loc, loc2);
16829 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
16851 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
16852 tree val, tree base_decl)
16854 dw_loc_descr_ref loc;
16856 if (host_integerp (val, 0))
16858 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
16862 loc = descr_info_loc (val, base_decl);
16866 add_AT_loc (die, attr, loc);
16869 /* This routine generates DIE for array with hidden descriptor, details
16870 are filled into *info by a langhook. */
16873 gen_descr_array_type_die (tree type, struct array_descr_info *info,
16874 dw_die_ref context_die)
16876 dw_die_ref scope_die = scope_die_for (type, context_die);
16877 dw_die_ref array_die;
16880 array_die = new_die (DW_TAG_array_type, scope_die, type);
16881 add_name_attribute (array_die, type_tag (type));
16882 equate_type_number_to_die (type, array_die);
16884 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16886 && info->ndimensions >= 2)
16887 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
16889 if (info->data_location)
16890 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
16892 if (info->associated)
16893 add_descr_info_field (array_die, DW_AT_associated, info->associated,
16895 if (info->allocated)
16896 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
16899 for (dim = 0; dim < info->ndimensions; dim++)
16901 dw_die_ref subrange_die
16902 = new_die (DW_TAG_subrange_type, array_die, NULL);
16904 if (info->dimen[dim].lower_bound)
16906 /* If it is the default value, omit it. */
16909 if (host_integerp (info->dimen[dim].lower_bound, 0)
16910 && (dflt = lower_bound_default ()) != -1
16911 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
16914 add_descr_info_field (subrange_die, DW_AT_lower_bound,
16915 info->dimen[dim].lower_bound,
16918 if (info->dimen[dim].upper_bound)
16919 add_descr_info_field (subrange_die, DW_AT_upper_bound,
16920 info->dimen[dim].upper_bound,
16922 if (info->dimen[dim].stride)
16923 add_descr_info_field (subrange_die, DW_AT_byte_stride,
16924 info->dimen[dim].stride,
16928 gen_type_die (info->element_type, context_die);
16929 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
16931 if (get_AT (array_die, DW_AT_name))
16932 add_pubtype (type, array_die);
16937 gen_entry_point_die (tree decl, dw_die_ref context_die)
16939 tree origin = decl_ultimate_origin (decl);
16940 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
16942 if (origin != NULL)
16943 add_abstract_origin_attribute (decl_die, origin);
16946 add_name_and_src_coords_attributes (decl_die, decl);
16947 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
16948 0, 0, context_die);
16951 if (DECL_ABSTRACT (decl))
16952 equate_decl_number_to_die (decl, decl_die);
16954 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
16958 /* Walk through the list of incomplete types again, trying once more to
16959 emit full debugging info for them. */
16962 retry_incomplete_types (void)
16966 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
16967 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
16968 DINFO_USAGE_DIR_USE))
16969 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
16972 /* Determine what tag to use for a record type. */
16974 static enum dwarf_tag
16975 record_type_tag (tree type)
16977 if (! lang_hooks.types.classify_record)
16978 return DW_TAG_structure_type;
16980 switch (lang_hooks.types.classify_record (type))
16982 case RECORD_IS_STRUCT:
16983 return DW_TAG_structure_type;
16985 case RECORD_IS_CLASS:
16986 return DW_TAG_class_type;
16988 case RECORD_IS_INTERFACE:
16989 if (dwarf_version >= 3 || !dwarf_strict)
16990 return DW_TAG_interface_type;
16991 return DW_TAG_structure_type;
16994 gcc_unreachable ();
16998 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16999 include all of the information about the enumeration values also. Each
17000 enumerated type name/value is listed as a child of the enumerated type
17004 gen_enumeration_type_die (tree type, dw_die_ref context_die)
17006 dw_die_ref type_die = lookup_type_die (type);
17008 if (type_die == NULL)
17010 type_die = new_die (DW_TAG_enumeration_type,
17011 scope_die_for (type, context_die), type);
17012 equate_type_number_to_die (type, type_die);
17013 add_name_attribute (type_die, type_tag (type));
17014 add_gnat_descriptive_type_attribute (type_die, type, context_die);
17015 if (TYPE_ARTIFICIAL (type))
17016 add_AT_flag (type_die, DW_AT_artificial, 1);
17017 if (dwarf_version >= 4 || !dwarf_strict)
17019 if (ENUM_IS_SCOPED (type))
17020 add_AT_flag (type_die, DW_AT_enum_class, 1);
17021 if (ENUM_IS_OPAQUE (type))
17022 add_AT_flag (type_die, DW_AT_declaration, 1);
17025 else if (! TYPE_SIZE (type))
17028 remove_AT (type_die, DW_AT_declaration);
17030 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17031 given enum type is incomplete, do not generate the DW_AT_byte_size
17032 attribute or the DW_AT_element_list attribute. */
17033 if (TYPE_SIZE (type))
17037 TREE_ASM_WRITTEN (type) = 1;
17038 add_byte_size_attribute (type_die, type);
17039 if (TYPE_STUB_DECL (type) != NULL_TREE)
17041 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
17042 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
17045 /* If the first reference to this type was as the return type of an
17046 inline function, then it may not have a parent. Fix this now. */
17047 if (type_die->die_parent == NULL)
17048 add_child_die (scope_die_for (type, context_die), type_die);
17050 for (link = TYPE_VALUES (type);
17051 link != NULL; link = TREE_CHAIN (link))
17053 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
17054 tree value = TREE_VALUE (link);
17056 add_name_attribute (enum_die,
17057 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
17059 if (TREE_CODE (value) == CONST_DECL)
17060 value = DECL_INITIAL (value);
17062 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
17063 /* DWARF2 does not provide a way of indicating whether or
17064 not enumeration constants are signed or unsigned. GDB
17065 always assumes the values are signed, so we output all
17066 values as if they were signed. That means that
17067 enumeration constants with very large unsigned values
17068 will appear to have negative values in the debugger. */
17069 add_AT_int (enum_die, DW_AT_const_value,
17070 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
17074 add_AT_flag (type_die, DW_AT_declaration, 1);
17076 if (get_AT (type_die, DW_AT_name))
17077 add_pubtype (type, type_die);
17082 /* Generate a DIE to represent either a real live formal parameter decl or to
17083 represent just the type of some formal parameter position in some function
17086 Note that this routine is a bit unusual because its argument may be a
17087 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17088 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17089 node. If it's the former then this function is being called to output a
17090 DIE to represent a formal parameter object (or some inlining thereof). If
17091 it's the latter, then this function is only being called to output a
17092 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17093 argument type of some subprogram type.
17094 If EMIT_NAME_P is true, name and source coordinate attributes
17098 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
17099 dw_die_ref context_die)
17101 tree node_or_origin = node ? node : origin;
17102 tree ultimate_origin;
17103 dw_die_ref parm_die
17104 = new_die (DW_TAG_formal_parameter, context_die, node);
17106 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
17108 case tcc_declaration:
17109 ultimate_origin = decl_ultimate_origin (node_or_origin);
17110 if (node || ultimate_origin)
17111 origin = ultimate_origin;
17112 if (origin != NULL)
17113 add_abstract_origin_attribute (parm_die, origin);
17114 else if (emit_name_p)
17115 add_name_and_src_coords_attributes (parm_die, node);
17117 || (! DECL_ABSTRACT (node_or_origin)
17118 && variably_modified_type_p (TREE_TYPE (node_or_origin),
17119 decl_function_context
17120 (node_or_origin))))
17122 tree type = TREE_TYPE (node_or_origin);
17123 if (decl_by_reference_p (node_or_origin))
17124 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
17127 add_type_attribute (parm_die, type,
17128 TREE_READONLY (node_or_origin),
17129 TREE_THIS_VOLATILE (node_or_origin),
17132 if (origin == NULL && DECL_ARTIFICIAL (node))
17133 add_AT_flag (parm_die, DW_AT_artificial, 1);
17135 if (node && node != origin)
17136 equate_decl_number_to_die (node, parm_die);
17137 if (! DECL_ABSTRACT (node_or_origin))
17138 add_location_or_const_value_attribute (parm_die, node_or_origin,
17139 node == NULL, DW_AT_location);
17144 /* We were called with some kind of a ..._TYPE node. */
17145 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
17149 gcc_unreachable ();
17155 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17156 children DW_TAG_formal_parameter DIEs representing the arguments of the
17159 PARM_PACK must be a function parameter pack.
17160 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17161 must point to the subsequent arguments of the function PACK_ARG belongs to.
17162 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17163 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17164 following the last one for which a DIE was generated. */
17167 gen_formal_parameter_pack_die (tree parm_pack,
17169 dw_die_ref subr_die,
17173 dw_die_ref parm_pack_die;
17175 gcc_assert (parm_pack
17176 && lang_hooks.function_parameter_pack_p (parm_pack)
17179 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
17180 add_src_coords_attributes (parm_pack_die, parm_pack);
17182 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
17184 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
17187 gen_formal_parameter_die (arg, NULL,
17188 false /* Don't emit name attribute. */,
17193 return parm_pack_die;
17196 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17197 at the end of an (ANSI prototyped) formal parameters list. */
17200 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
17202 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
17205 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17206 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17207 parameters as specified in some function type specification (except for
17208 those which appear as part of a function *definition*). */
17211 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
17214 tree formal_type = NULL;
17215 tree first_parm_type;
17218 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
17220 arg = DECL_ARGUMENTS (function_or_method_type);
17221 function_or_method_type = TREE_TYPE (function_or_method_type);
17226 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
17228 /* Make our first pass over the list of formal parameter types and output a
17229 DW_TAG_formal_parameter DIE for each one. */
17230 for (link = first_parm_type; link; )
17232 dw_die_ref parm_die;
17234 formal_type = TREE_VALUE (link);
17235 if (formal_type == void_type_node)
17238 /* Output a (nameless) DIE to represent the formal parameter itself. */
17239 parm_die = gen_formal_parameter_die (formal_type, NULL,
17240 true /* Emit name attribute. */,
17242 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
17243 && link == first_parm_type)
17245 add_AT_flag (parm_die, DW_AT_artificial, 1);
17246 if (dwarf_version >= 3 || !dwarf_strict)
17247 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
17249 else if (arg && DECL_ARTIFICIAL (arg))
17250 add_AT_flag (parm_die, DW_AT_artificial, 1);
17252 link = TREE_CHAIN (link);
17254 arg = DECL_CHAIN (arg);
17257 /* If this function type has an ellipsis, add a
17258 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17259 if (formal_type != void_type_node)
17260 gen_unspecified_parameters_die (function_or_method_type, context_die);
17262 /* Make our second (and final) pass over the list of formal parameter types
17263 and output DIEs to represent those types (as necessary). */
17264 for (link = TYPE_ARG_TYPES (function_or_method_type);
17265 link && TREE_VALUE (link);
17266 link = TREE_CHAIN (link))
17267 gen_type_die (TREE_VALUE (link), context_die);
17270 /* We want to generate the DIE for TYPE so that we can generate the
17271 die for MEMBER, which has been defined; we will need to refer back
17272 to the member declaration nested within TYPE. If we're trying to
17273 generate minimal debug info for TYPE, processing TYPE won't do the
17274 trick; we need to attach the member declaration by hand. */
17277 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
17279 gen_type_die (type, context_die);
17281 /* If we're trying to avoid duplicate debug info, we may not have
17282 emitted the member decl for this function. Emit it now. */
17283 if (TYPE_STUB_DECL (type)
17284 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
17285 && ! lookup_decl_die (member))
17287 dw_die_ref type_die;
17288 gcc_assert (!decl_ultimate_origin (member));
17290 push_decl_scope (type);
17291 type_die = lookup_type_die_strip_naming_typedef (type);
17292 if (TREE_CODE (member) == FUNCTION_DECL)
17293 gen_subprogram_die (member, type_die);
17294 else if (TREE_CODE (member) == FIELD_DECL)
17296 /* Ignore the nameless fields that are used to skip bits but handle
17297 C++ anonymous unions and structs. */
17298 if (DECL_NAME (member) != NULL_TREE
17299 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
17300 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
17302 gen_type_die (member_declared_type (member), type_die);
17303 gen_field_die (member, type_die);
17307 gen_variable_die (member, NULL_TREE, type_die);
17313 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17314 may later generate inlined and/or out-of-line instances of. */
17317 dwarf2out_abstract_function (tree decl)
17319 dw_die_ref old_die;
17323 htab_t old_decl_loc_table;
17324 htab_t old_cached_dw_loc_list_table;
17325 int old_call_site_count, old_tail_call_site_count;
17326 struct call_arg_loc_node *old_call_arg_locations;
17328 /* Make sure we have the actual abstract inline, not a clone. */
17329 decl = DECL_ORIGIN (decl);
17331 old_die = lookup_decl_die (decl);
17332 if (old_die && get_AT (old_die, DW_AT_inline))
17333 /* We've already generated the abstract instance. */
17336 /* We can be called while recursively when seeing block defining inlined subroutine
17337 DIE. Be sure to not clobber the outer location table nor use it or we would
17338 get locations in abstract instantces. */
17339 old_decl_loc_table = decl_loc_table;
17340 decl_loc_table = NULL;
17341 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
17342 cached_dw_loc_list_table = NULL;
17343 old_call_arg_locations = call_arg_locations;
17344 call_arg_locations = NULL;
17345 old_call_site_count = call_site_count;
17346 call_site_count = -1;
17347 old_tail_call_site_count = tail_call_site_count;
17348 tail_call_site_count = -1;
17350 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17351 we don't get confused by DECL_ABSTRACT. */
17352 if (debug_info_level > DINFO_LEVEL_TERSE)
17354 context = decl_class_context (decl);
17356 gen_type_die_for_member
17357 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
17360 /* Pretend we've just finished compiling this function. */
17361 save_fn = current_function_decl;
17362 current_function_decl = decl;
17363 push_cfun (DECL_STRUCT_FUNCTION (decl));
17365 was_abstract = DECL_ABSTRACT (decl);
17366 set_decl_abstract_flags (decl, 1);
17367 dwarf2out_decl (decl);
17368 if (! was_abstract)
17369 set_decl_abstract_flags (decl, 0);
17371 current_function_decl = save_fn;
17372 decl_loc_table = old_decl_loc_table;
17373 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
17374 call_arg_locations = old_call_arg_locations;
17375 call_site_count = old_call_site_count;
17376 tail_call_site_count = old_tail_call_site_count;
17380 /* Helper function of premark_used_types() which gets called through
17383 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17384 marked as unused by prune_unused_types. */
17387 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
17392 type = (tree) *slot;
17393 die = lookup_type_die (type);
17395 die->die_perennial_p = 1;
17399 /* Helper function of premark_types_used_by_global_vars which gets called
17400 through htab_traverse.
17402 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17403 marked as unused by prune_unused_types. The DIE of the type is marked
17404 only if the global variable using the type will actually be emitted. */
17407 premark_types_used_by_global_vars_helper (void **slot,
17408 void *data ATTRIBUTE_UNUSED)
17410 struct types_used_by_vars_entry *entry;
17413 entry = (struct types_used_by_vars_entry *) *slot;
17414 gcc_assert (entry->type != NULL
17415 && entry->var_decl != NULL);
17416 die = lookup_type_die (entry->type);
17419 /* Ask cgraph if the global variable really is to be emitted.
17420 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17421 struct varpool_node *node = varpool_get_node (entry->var_decl);
17422 if (node && node->needed)
17424 die->die_perennial_p = 1;
17425 /* Keep the parent DIEs as well. */
17426 while ((die = die->die_parent) && die->die_perennial_p == 0)
17427 die->die_perennial_p = 1;
17433 /* Mark all members of used_types_hash as perennial. */
17436 premark_used_types (void)
17438 if (cfun && cfun->used_types_hash)
17439 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
17442 /* Mark all members of types_used_by_vars_entry as perennial. */
17445 premark_types_used_by_global_vars (void)
17447 if (types_used_by_vars_hash)
17448 htab_traverse (types_used_by_vars_hash,
17449 premark_types_used_by_global_vars_helper, NULL);
17452 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17453 for CA_LOC call arg loc node. */
17456 gen_call_site_die (tree decl, dw_die_ref subr_die,
17457 struct call_arg_loc_node *ca_loc)
17459 dw_die_ref stmt_die = NULL, die;
17460 tree block = ca_loc->block;
17463 && block != DECL_INITIAL (decl)
17464 && TREE_CODE (block) == BLOCK)
17466 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
17467 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
17470 block = BLOCK_SUPERCONTEXT (block);
17472 if (stmt_die == NULL)
17473 stmt_die = subr_die;
17474 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
17475 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
17476 if (ca_loc->tail_call_p)
17477 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
17478 if (ca_loc->symbol_ref)
17480 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
17482 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
17484 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
17489 /* Generate a DIE to represent a declared function (either file-scope or
17493 gen_subprogram_die (tree decl, dw_die_ref context_die)
17495 tree origin = decl_ultimate_origin (decl);
17496 dw_die_ref subr_die;
17498 dw_die_ref old_die = lookup_decl_die (decl);
17499 int declaration = (current_function_decl != decl
17500 || class_or_namespace_scope_p (context_die));
17502 premark_used_types ();
17504 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17505 started to generate the abstract instance of an inline, decided to output
17506 its containing class, and proceeded to emit the declaration of the inline
17507 from the member list for the class. If so, DECLARATION takes priority;
17508 we'll get back to the abstract instance when done with the class. */
17510 /* The class-scope declaration DIE must be the primary DIE. */
17511 if (origin && declaration && class_or_namespace_scope_p (context_die))
17514 gcc_assert (!old_die);
17517 /* Now that the C++ front end lazily declares artificial member fns, we
17518 might need to retrofit the declaration into its class. */
17519 if (!declaration && !origin && !old_die
17520 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
17521 && !class_or_namespace_scope_p (context_die)
17522 && debug_info_level > DINFO_LEVEL_TERSE)
17523 old_die = force_decl_die (decl);
17525 if (origin != NULL)
17527 gcc_assert (!declaration || local_scope_p (context_die));
17529 /* Fixup die_parent for the abstract instance of a nested
17530 inline function. */
17531 if (old_die && old_die->die_parent == NULL)
17532 add_child_die (context_die, old_die);
17534 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17535 add_abstract_origin_attribute (subr_die, origin);
17536 /* This is where the actual code for a cloned function is.
17537 Let's emit linkage name attribute for it. This helps
17538 debuggers to e.g, set breakpoints into
17539 constructors/destructors when the user asks "break
17541 add_linkage_name (subr_die, decl);
17545 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
17546 struct dwarf_file_data * file_index = lookup_filename (s.file);
17548 if (!get_AT_flag (old_die, DW_AT_declaration)
17549 /* We can have a normal definition following an inline one in the
17550 case of redefinition of GNU C extern inlines.
17551 It seems reasonable to use AT_specification in this case. */
17552 && !get_AT (old_die, DW_AT_inline))
17554 /* Detect and ignore this case, where we are trying to output
17555 something we have already output. */
17559 /* If the definition comes from the same place as the declaration,
17560 maybe use the old DIE. We always want the DIE for this function
17561 that has the *_pc attributes to be under comp_unit_die so the
17562 debugger can find it. We also need to do this for abstract
17563 instances of inlines, since the spec requires the out-of-line copy
17564 to have the same parent. For local class methods, this doesn't
17565 apply; we just use the old DIE. */
17566 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
17567 && (DECL_ARTIFICIAL (decl)
17568 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
17569 && (get_AT_unsigned (old_die, DW_AT_decl_line)
17570 == (unsigned) s.line))))
17572 subr_die = old_die;
17574 /* Clear out the declaration attribute and the formal parameters.
17575 Do not remove all children, because it is possible that this
17576 declaration die was forced using force_decl_die(). In such
17577 cases die that forced declaration die (e.g. TAG_imported_module)
17578 is one of the children that we do not want to remove. */
17579 remove_AT (subr_die, DW_AT_declaration);
17580 remove_AT (subr_die, DW_AT_object_pointer);
17581 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
17585 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17586 add_AT_specification (subr_die, old_die);
17587 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
17588 add_AT_file (subr_die, DW_AT_decl_file, file_index);
17589 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
17590 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
17595 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17597 if (TREE_PUBLIC (decl))
17598 add_AT_flag (subr_die, DW_AT_external, 1);
17600 add_name_and_src_coords_attributes (subr_die, decl);
17601 if (debug_info_level > DINFO_LEVEL_TERSE)
17603 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
17604 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
17605 0, 0, context_die);
17608 add_pure_or_virtual_attribute (subr_die, decl);
17609 if (DECL_ARTIFICIAL (decl))
17610 add_AT_flag (subr_die, DW_AT_artificial, 1);
17612 add_accessibility_attribute (subr_die, decl);
17617 if (!old_die || !get_AT (old_die, DW_AT_inline))
17619 add_AT_flag (subr_die, DW_AT_declaration, 1);
17621 /* If this is an explicit function declaration then generate
17622 a DW_AT_explicit attribute. */
17623 if (lang_hooks.decls.function_decl_explicit_p (decl)
17624 && (dwarf_version >= 3 || !dwarf_strict))
17625 add_AT_flag (subr_die, DW_AT_explicit, 1);
17627 /* The first time we see a member function, it is in the context of
17628 the class to which it belongs. We make sure of this by emitting
17629 the class first. The next time is the definition, which is
17630 handled above. The two may come from the same source text.
17632 Note that force_decl_die() forces function declaration die. It is
17633 later reused to represent definition. */
17634 equate_decl_number_to_die (decl, subr_die);
17637 else if (DECL_ABSTRACT (decl))
17639 if (DECL_DECLARED_INLINE_P (decl))
17641 if (cgraph_function_possibly_inlined_p (decl))
17642 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
17644 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
17648 if (cgraph_function_possibly_inlined_p (decl))
17649 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
17651 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
17654 if (DECL_DECLARED_INLINE_P (decl)
17655 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
17656 add_AT_flag (subr_die, DW_AT_artificial, 1);
17658 equate_decl_number_to_die (decl, subr_die);
17660 else if (!DECL_EXTERNAL (decl))
17662 HOST_WIDE_INT cfa_fb_offset;
17664 if (!old_die || !get_AT (old_die, DW_AT_inline))
17665 equate_decl_number_to_die (decl, subr_die);
17667 if (!flag_reorder_blocks_and_partition)
17669 dw_fde_ref fde = &fde_table[current_funcdef_fde];
17670 if (fde->dw_fde_begin)
17672 /* We have already generated the labels. */
17673 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
17674 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
17678 /* Create start/end labels and add the range. */
17679 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
17680 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
17681 current_function_funcdef_no);
17682 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
17683 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
17684 current_function_funcdef_no);
17685 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
17688 #if VMS_DEBUGGING_INFO
17689 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17690 Section 2.3 Prologue and Epilogue Attributes:
17691 When a breakpoint is set on entry to a function, it is generally
17692 desirable for execution to be suspended, not on the very first
17693 instruction of the function, but rather at a point after the
17694 function's frame has been set up, after any language defined local
17695 declaration processing has been completed, and before execution of
17696 the first statement of the function begins. Debuggers generally
17697 cannot properly determine where this point is. Similarly for a
17698 breakpoint set on exit from a function. The prologue and epilogue
17699 attributes allow a compiler to communicate the location(s) to use. */
17702 if (fde->dw_fde_vms_end_prologue)
17703 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
17704 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
17706 if (fde->dw_fde_vms_begin_epilogue)
17707 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
17708 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
17712 add_pubname (decl, subr_die);
17715 { /* Generate pubnames entries for the split function code
17717 dw_fde_ref fde = &fde_table[current_funcdef_fde];
17719 if (fde->dw_fde_second_begin)
17721 if (dwarf_version >= 3 || !dwarf_strict)
17723 /* We should use ranges for non-contiguous code section
17724 addresses. Use the actual code range for the initial
17725 section, since the HOT/COLD labels might precede an
17726 alignment offset. */
17727 bool range_list_added = false;
17728 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
17729 fde->dw_fde_end, &range_list_added);
17730 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
17731 fde->dw_fde_second_end,
17732 &range_list_added);
17733 add_pubname (decl, subr_die);
17734 if (range_list_added)
17739 /* There is no real support in DW2 for this .. so we make
17740 a work-around. First, emit the pub name for the segment
17741 containing the function label. Then make and emit a
17742 simplified subprogram DIE for the second segment with the
17743 name pre-fixed by __hot/cold_sect_of_. We use the same
17744 linkage name for the second die so that gdb will find both
17745 sections when given "b foo". */
17746 const char *name = NULL;
17747 tree decl_name = DECL_NAME (decl);
17748 dw_die_ref seg_die;
17750 /* Do the 'primary' section. */
17751 add_AT_lbl_id (subr_die, DW_AT_low_pc,
17752 fde->dw_fde_begin);
17753 add_AT_lbl_id (subr_die, DW_AT_high_pc,
17756 add_pubname (decl, subr_die);
17758 /* Build a minimal DIE for the secondary section. */
17759 seg_die = new_die (DW_TAG_subprogram,
17760 subr_die->die_parent, decl);
17762 if (TREE_PUBLIC (decl))
17763 add_AT_flag (seg_die, DW_AT_external, 1);
17765 if (decl_name != NULL
17766 && IDENTIFIER_POINTER (decl_name) != NULL)
17768 name = dwarf2_name (decl, 1);
17769 if (! DECL_ARTIFICIAL (decl))
17770 add_src_coords_attributes (seg_die, decl);
17772 add_linkage_name (seg_die, decl);
17774 gcc_assert (name != NULL);
17775 add_pure_or_virtual_attribute (seg_die, decl);
17776 if (DECL_ARTIFICIAL (decl))
17777 add_AT_flag (seg_die, DW_AT_artificial, 1);
17779 name = concat ("__second_sect_of_", name, NULL);
17780 add_AT_lbl_id (seg_die, DW_AT_low_pc,
17781 fde->dw_fde_second_begin);
17782 add_AT_lbl_id (seg_die, DW_AT_high_pc,
17783 fde->dw_fde_second_end);
17784 add_name_attribute (seg_die, name);
17785 add_pubname_string (name, seg_die);
17790 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
17791 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
17792 add_pubname (decl, subr_die);
17796 #ifdef MIPS_DEBUGGING_INFO
17797 /* Add a reference to the FDE for this routine. */
17798 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
17801 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
17803 /* We define the "frame base" as the function's CFA. This is more
17804 convenient for several reasons: (1) It's stable across the prologue
17805 and epilogue, which makes it better than just a frame pointer,
17806 (2) With dwarf3, there exists a one-byte encoding that allows us
17807 to reference the .debug_frame data by proxy, but failing that,
17808 (3) We can at least reuse the code inspection and interpretation
17809 code that determines the CFA position at various points in the
17811 if (dwarf_version >= 3)
17813 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
17814 add_AT_loc (subr_die, DW_AT_frame_base, op);
17818 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
17819 if (list->dw_loc_next)
17820 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
17822 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
17825 /* Compute a displacement from the "steady-state frame pointer" to
17826 the CFA. The former is what all stack slots and argument slots
17827 will reference in the rtl; the later is what we've told the
17828 debugger about. We'll need to adjust all frame_base references
17829 by this displacement. */
17830 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
17832 if (cfun->static_chain_decl)
17833 add_AT_location_description (subr_die, DW_AT_static_link,
17834 loc_list_from_tree (cfun->static_chain_decl, 2));
17837 /* Generate child dies for template paramaters. */
17838 if (debug_info_level > DINFO_LEVEL_TERSE)
17839 gen_generic_params_dies (decl);
17841 /* Now output descriptions of the arguments for this function. This gets
17842 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17843 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17844 `...' at the end of the formal parameter list. In order to find out if
17845 there was a trailing ellipsis or not, we must instead look at the type
17846 associated with the FUNCTION_DECL. This will be a node of type
17847 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17848 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17849 an ellipsis at the end. */
17851 /* In the case where we are describing a mere function declaration, all we
17852 need to do here (and all we *can* do here) is to describe the *types* of
17853 its formal parameters. */
17854 if (debug_info_level <= DINFO_LEVEL_TERSE)
17856 else if (declaration)
17857 gen_formal_types_die (decl, subr_die);
17860 /* Generate DIEs to represent all known formal parameters. */
17861 tree parm = DECL_ARGUMENTS (decl);
17862 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
17863 tree generic_decl_parm = generic_decl
17864 ? DECL_ARGUMENTS (generic_decl)
17867 /* Now we want to walk the list of parameters of the function and
17868 emit their relevant DIEs.
17870 We consider the case of DECL being an instance of a generic function
17871 as well as it being a normal function.
17873 If DECL is an instance of a generic function we walk the
17874 parameters of the generic function declaration _and_ the parameters of
17875 DECL itself. This is useful because we want to emit specific DIEs for
17876 function parameter packs and those are declared as part of the
17877 generic function declaration. In that particular case,
17878 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17879 That DIE has children DIEs representing the set of arguments
17880 of the pack. Note that the set of pack arguments can be empty.
17881 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17884 Otherwise, we just consider the parameters of DECL. */
17885 while (generic_decl_parm || parm)
17887 if (generic_decl_parm
17888 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
17889 gen_formal_parameter_pack_die (generic_decl_parm,
17894 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
17896 if (parm == DECL_ARGUMENTS (decl)
17897 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
17899 && (dwarf_version >= 3 || !dwarf_strict))
17900 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
17902 parm = DECL_CHAIN (parm);
17905 if (generic_decl_parm)
17906 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
17909 /* Decide whether we need an unspecified_parameters DIE at the end.
17910 There are 2 more cases to do this for: 1) the ansi ... declaration -
17911 this is detectable when the end of the arg list is not a
17912 void_type_node 2) an unprototyped function declaration (not a
17913 definition). This just means that we have no info about the
17914 parameters at all. */
17915 if (prototype_p (TREE_TYPE (decl)))
17917 /* This is the prototyped case, check for.... */
17918 if (stdarg_p (TREE_TYPE (decl)))
17919 gen_unspecified_parameters_die (decl, subr_die);
17921 else if (DECL_INITIAL (decl) == NULL_TREE)
17922 gen_unspecified_parameters_die (decl, subr_die);
17925 /* Output Dwarf info for all of the stuff within the body of the function
17926 (if it has one - it may be just a declaration). */
17927 outer_scope = DECL_INITIAL (decl);
17929 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17930 a function. This BLOCK actually represents the outermost binding contour
17931 for the function, i.e. the contour in which the function's formal
17932 parameters and labels get declared. Curiously, it appears that the front
17933 end doesn't actually put the PARM_DECL nodes for the current function onto
17934 the BLOCK_VARS list for this outer scope, but are strung off of the
17935 DECL_ARGUMENTS list for the function instead.
17937 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17938 the LABEL_DECL nodes for the function however, and we output DWARF info
17939 for those in decls_for_scope. Just within the `outer_scope' there will be
17940 a BLOCK node representing the function's outermost pair of curly braces,
17941 and any blocks used for the base and member initializers of a C++
17942 constructor function. */
17943 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
17945 int call_site_note_count = 0;
17946 int tail_call_site_note_count = 0;
17948 /* Emit a DW_TAG_variable DIE for a named return value. */
17949 if (DECL_NAME (DECL_RESULT (decl)))
17950 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
17952 current_function_has_inlines = 0;
17953 decls_for_scope (outer_scope, subr_die, 0);
17955 if (call_arg_locations && !dwarf_strict)
17957 struct call_arg_loc_node *ca_loc;
17958 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
17960 dw_die_ref die = NULL;
17961 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
17964 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
17965 arg; arg = next_arg)
17967 dw_loc_descr_ref reg, val;
17968 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
17969 dw_die_ref cdie, tdie = NULL;
17971 next_arg = XEXP (arg, 1);
17972 if (REG_P (XEXP (XEXP (arg, 0), 0))
17974 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
17975 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
17976 && REGNO (XEXP (XEXP (arg, 0), 0))
17977 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
17978 next_arg = XEXP (next_arg, 1);
17979 if (mode == VOIDmode)
17981 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
17982 if (mode == VOIDmode)
17983 mode = GET_MODE (XEXP (arg, 0));
17985 if (mode == VOIDmode || mode == BLKmode)
17987 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
17989 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
17990 tloc = XEXP (XEXP (arg, 0), 1);
17993 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
17994 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
17996 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
17997 tlocc = XEXP (XEXP (arg, 0), 1);
18001 if (REG_P (XEXP (XEXP (arg, 0), 0)))
18002 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
18003 VAR_INIT_STATUS_INITIALIZED);
18004 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
18006 rtx mem = XEXP (XEXP (arg, 0), 0);
18007 reg = mem_loc_descriptor (XEXP (mem, 0),
18008 get_address_mode (mem),
18010 VAR_INIT_STATUS_INITIALIZED);
18012 else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
18013 == DEBUG_PARAMETER_REF)
18016 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
18017 tdie = lookup_decl_die (tdecl);
18024 && GET_CODE (XEXP (XEXP (arg, 0), 0))
18025 != DEBUG_PARAMETER_REF)
18027 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
18029 VAR_INIT_STATUS_INITIALIZED);
18033 die = gen_call_site_die (decl, subr_die, ca_loc);
18034 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
18037 add_AT_loc (cdie, DW_AT_location, reg);
18038 else if (tdie != NULL)
18039 add_AT_die_ref (cdie, DW_AT_abstract_origin, tdie);
18040 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
18041 if (next_arg != XEXP (arg, 1))
18043 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
18044 if (mode == VOIDmode)
18045 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
18046 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
18049 VAR_INIT_STATUS_INITIALIZED);
18051 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
18055 && (ca_loc->symbol_ref || tloc))
18056 die = gen_call_site_die (decl, subr_die, ca_loc);
18057 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
18059 dw_loc_descr_ref tval = NULL;
18061 if (tloc != NULL_RTX)
18062 tval = mem_loc_descriptor (tloc,
18063 GET_MODE (tloc) == VOIDmode
18064 ? Pmode : GET_MODE (tloc),
18066 VAR_INIT_STATUS_INITIALIZED);
18068 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
18069 else if (tlocc != NULL_RTX)
18071 tval = mem_loc_descriptor (tlocc,
18072 GET_MODE (tlocc) == VOIDmode
18073 ? Pmode : GET_MODE (tlocc),
18075 VAR_INIT_STATUS_INITIALIZED);
18077 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
18083 call_site_note_count++;
18084 if (ca_loc->tail_call_p)
18085 tail_call_site_note_count++;
18089 call_arg_locations = NULL;
18090 call_arg_loc_last = NULL;
18091 if (tail_call_site_count >= 0
18092 && tail_call_site_count == tail_call_site_note_count
18095 if (call_site_count >= 0
18096 && call_site_count == call_site_note_count)
18097 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
18099 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
18101 call_site_count = -1;
18102 tail_call_site_count = -1;
18104 /* Add the calling convention attribute if requested. */
18105 add_calling_convention_attribute (subr_die, decl);
18109 /* Returns a hash value for X (which really is a die_struct). */
18112 common_block_die_table_hash (const void *x)
18114 const_dw_die_ref d = (const_dw_die_ref) x;
18115 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
18118 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18119 as decl_id and die_parent of die_struct Y. */
18122 common_block_die_table_eq (const void *x, const void *y)
18124 const_dw_die_ref d = (const_dw_die_ref) x;
18125 const_dw_die_ref e = (const_dw_die_ref) y;
18126 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
18129 /* Generate a DIE to represent a declared data object.
18130 Either DECL or ORIGIN must be non-null. */
18133 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
18137 tree decl_or_origin = decl ? decl : origin;
18138 tree ultimate_origin;
18139 dw_die_ref var_die;
18140 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
18141 dw_die_ref origin_die;
18142 bool declaration = (DECL_EXTERNAL (decl_or_origin)
18143 || class_or_namespace_scope_p (context_die));
18144 bool specialization_p = false;
18146 ultimate_origin = decl_ultimate_origin (decl_or_origin);
18147 if (decl || ultimate_origin)
18148 origin = ultimate_origin;
18149 com_decl = fortran_common (decl_or_origin, &off);
18151 /* Symbol in common gets emitted as a child of the common block, in the form
18152 of a data member. */
18155 dw_die_ref com_die;
18156 dw_loc_list_ref loc;
18157 die_node com_die_arg;
18159 var_die = lookup_decl_die (decl_or_origin);
18162 if (get_AT (var_die, DW_AT_location) == NULL)
18164 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
18169 /* Optimize the common case. */
18170 if (single_element_loc_list_p (loc)
18171 && loc->expr->dw_loc_opc == DW_OP_addr
18172 && loc->expr->dw_loc_next == NULL
18173 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
18175 loc->expr->dw_loc_oprnd1.v.val_addr
18176 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
18178 loc_list_plus_const (loc, off);
18180 add_AT_location_description (var_die, DW_AT_location, loc);
18181 remove_AT (var_die, DW_AT_declaration);
18187 if (common_block_die_table == NULL)
18188 common_block_die_table
18189 = htab_create_ggc (10, common_block_die_table_hash,
18190 common_block_die_table_eq, NULL);
18192 com_die_arg.decl_id = DECL_UID (com_decl);
18193 com_die_arg.die_parent = context_die;
18194 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
18195 loc = loc_list_from_tree (com_decl, 2);
18196 if (com_die == NULL)
18199 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
18202 com_die = new_die (DW_TAG_common_block, context_die, decl);
18203 add_name_and_src_coords_attributes (com_die, com_decl);
18206 add_AT_location_description (com_die, DW_AT_location, loc);
18207 /* Avoid sharing the same loc descriptor between
18208 DW_TAG_common_block and DW_TAG_variable. */
18209 loc = loc_list_from_tree (com_decl, 2);
18211 else if (DECL_EXTERNAL (decl))
18212 add_AT_flag (com_die, DW_AT_declaration, 1);
18213 add_pubname_string (cnam, com_die); /* ??? needed? */
18214 com_die->decl_id = DECL_UID (com_decl);
18215 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
18216 *slot = (void *) com_die;
18218 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
18220 add_AT_location_description (com_die, DW_AT_location, loc);
18221 loc = loc_list_from_tree (com_decl, 2);
18222 remove_AT (com_die, DW_AT_declaration);
18224 var_die = new_die (DW_TAG_variable, com_die, decl);
18225 add_name_and_src_coords_attributes (var_die, decl);
18226 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
18227 TREE_THIS_VOLATILE (decl), context_die);
18228 add_AT_flag (var_die, DW_AT_external, 1);
18233 /* Optimize the common case. */
18234 if (single_element_loc_list_p (loc)
18235 && loc->expr->dw_loc_opc == DW_OP_addr
18236 && loc->expr->dw_loc_next == NULL
18237 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
18238 loc->expr->dw_loc_oprnd1.v.val_addr
18239 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
18241 loc_list_plus_const (loc, off);
18243 add_AT_location_description (var_die, DW_AT_location, loc);
18245 else if (DECL_EXTERNAL (decl))
18246 add_AT_flag (var_die, DW_AT_declaration, 1);
18247 equate_decl_number_to_die (decl, var_die);
18251 /* If the compiler emitted a definition for the DECL declaration
18252 and if we already emitted a DIE for it, don't emit a second
18253 DIE for it again. Allow re-declarations of DECLs that are
18254 inside functions, though. */
18255 if (old_die && declaration && !local_scope_p (context_die))
18258 /* For static data members, the declaration in the class is supposed
18259 to have DW_TAG_member tag; the specification should still be
18260 DW_TAG_variable referencing the DW_TAG_member DIE. */
18261 if (declaration && class_scope_p (context_die))
18262 var_die = new_die (DW_TAG_member, context_die, decl);
18264 var_die = new_die (DW_TAG_variable, context_die, decl);
18267 if (origin != NULL)
18268 origin_die = add_abstract_origin_attribute (var_die, origin);
18270 /* Loop unrolling can create multiple blocks that refer to the same
18271 static variable, so we must test for the DW_AT_declaration flag.
18273 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18274 copy decls and set the DECL_ABSTRACT flag on them instead of
18277 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18279 ??? The declare_in_namespace support causes us to get two DIEs for one
18280 variable, both of which are declarations. We want to avoid considering
18281 one to be a specification, so we must test that this DIE is not a
18283 else if (old_die && TREE_STATIC (decl) && ! declaration
18284 && get_AT_flag (old_die, DW_AT_declaration) == 1)
18286 /* This is a definition of a C++ class level static. */
18287 add_AT_specification (var_die, old_die);
18288 specialization_p = true;
18289 if (DECL_NAME (decl))
18291 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
18292 struct dwarf_file_data * file_index = lookup_filename (s.file);
18294 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
18295 add_AT_file (var_die, DW_AT_decl_file, file_index);
18297 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
18298 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
18300 if (old_die->die_tag == DW_TAG_member)
18301 add_linkage_name (var_die, decl);
18305 add_name_and_src_coords_attributes (var_die, decl);
18307 if ((origin == NULL && !specialization_p)
18309 && !DECL_ABSTRACT (decl_or_origin)
18310 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
18311 decl_function_context
18312 (decl_or_origin))))
18314 tree type = TREE_TYPE (decl_or_origin);
18316 if (decl_by_reference_p (decl_or_origin))
18317 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
18319 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
18320 TREE_THIS_VOLATILE (decl_or_origin), context_die);
18323 if (origin == NULL && !specialization_p)
18325 if (TREE_PUBLIC (decl))
18326 add_AT_flag (var_die, DW_AT_external, 1);
18328 if (DECL_ARTIFICIAL (decl))
18329 add_AT_flag (var_die, DW_AT_artificial, 1);
18331 add_accessibility_attribute (var_die, decl);
18335 add_AT_flag (var_die, DW_AT_declaration, 1);
18337 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
18338 equate_decl_number_to_die (decl, var_die);
18341 && (! DECL_ABSTRACT (decl_or_origin)
18342 /* Local static vars are shared between all clones/inlines,
18343 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18345 || (TREE_CODE (decl_or_origin) == VAR_DECL
18346 && TREE_STATIC (decl_or_origin)
18347 && DECL_RTL_SET_P (decl_or_origin)))
18348 /* When abstract origin already has DW_AT_location attribute, no need
18349 to add it again. */
18350 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
18352 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
18353 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
18354 defer_location (decl_or_origin, var_die);
18356 add_location_or_const_value_attribute (var_die, decl_or_origin,
18357 decl == NULL, DW_AT_location);
18358 add_pubname (decl_or_origin, var_die);
18361 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
18364 /* Generate a DIE to represent a named constant. */
18367 gen_const_die (tree decl, dw_die_ref context_die)
18369 dw_die_ref const_die;
18370 tree type = TREE_TYPE (decl);
18372 const_die = new_die (DW_TAG_constant, context_die, decl);
18373 add_name_and_src_coords_attributes (const_die, decl);
18374 add_type_attribute (const_die, type, 1, 0, context_die);
18375 if (TREE_PUBLIC (decl))
18376 add_AT_flag (const_die, DW_AT_external, 1);
18377 if (DECL_ARTIFICIAL (decl))
18378 add_AT_flag (const_die, DW_AT_artificial, 1);
18379 tree_add_const_value_attribute_for_decl (const_die, decl);
18382 /* Generate a DIE to represent a label identifier. */
18385 gen_label_die (tree decl, dw_die_ref context_die)
18387 tree origin = decl_ultimate_origin (decl);
18388 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
18390 char label[MAX_ARTIFICIAL_LABEL_BYTES];
18392 if (origin != NULL)
18393 add_abstract_origin_attribute (lbl_die, origin);
18395 add_name_and_src_coords_attributes (lbl_die, decl);
18397 if (DECL_ABSTRACT (decl))
18398 equate_decl_number_to_die (decl, lbl_die);
18401 insn = DECL_RTL_IF_SET (decl);
18403 /* Deleted labels are programmer specified labels which have been
18404 eliminated because of various optimizations. We still emit them
18405 here so that it is possible to put breakpoints on them. */
18409 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
18411 /* When optimization is enabled (via -O) some parts of the compiler
18412 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18413 represent source-level labels which were explicitly declared by
18414 the user. This really shouldn't be happening though, so catch
18415 it if it ever does happen. */
18416 gcc_assert (!INSN_DELETED_P (insn));
18418 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
18419 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
18424 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18425 attributes to the DIE for a block STMT, to describe where the inlined
18426 function was called from. This is similar to add_src_coords_attributes. */
18429 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
18431 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
18433 if (dwarf_version >= 3 || !dwarf_strict)
18435 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
18436 add_AT_unsigned (die, DW_AT_call_line, s.line);
18441 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18442 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18445 add_high_low_attributes (tree stmt, dw_die_ref die)
18447 char label[MAX_ARTIFICIAL_LABEL_BYTES];
18449 if (BLOCK_FRAGMENT_CHAIN (stmt)
18450 && (dwarf_version >= 3 || !dwarf_strict))
18454 if (inlined_function_outer_scope_p (stmt))
18456 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
18457 BLOCK_NUMBER (stmt));
18458 add_AT_lbl_id (die, DW_AT_entry_pc, label);
18461 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
18463 chain = BLOCK_FRAGMENT_CHAIN (stmt);
18466 add_ranges (chain);
18467 chain = BLOCK_FRAGMENT_CHAIN (chain);
18474 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
18475 BLOCK_NUMBER (stmt));
18476 add_AT_lbl_id (die, DW_AT_low_pc, label);
18477 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
18478 BLOCK_NUMBER (stmt));
18479 add_AT_lbl_id (die, DW_AT_high_pc, label);
18483 /* Generate a DIE for a lexical block. */
18486 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
18488 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
18490 if (call_arg_locations)
18492 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
18493 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
18494 BLOCK_NUMBER (stmt) + 1);
18495 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
18498 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
18499 add_high_low_attributes (stmt, stmt_die);
18501 decls_for_scope (stmt, stmt_die, depth);
18504 /* Generate a DIE for an inlined subprogram. */
18507 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
18511 /* The instance of function that is effectively being inlined shall not
18513 gcc_assert (! BLOCK_ABSTRACT (stmt));
18515 decl = block_ultimate_origin (stmt);
18517 /* Emit info for the abstract instance first, if we haven't yet. We
18518 must emit this even if the block is abstract, otherwise when we
18519 emit the block below (or elsewhere), we may end up trying to emit
18520 a die whose origin die hasn't been emitted, and crashing. */
18521 dwarf2out_abstract_function (decl);
18523 if (! BLOCK_ABSTRACT (stmt))
18525 dw_die_ref subr_die
18526 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
18528 if (call_arg_locations)
18530 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
18531 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
18532 BLOCK_NUMBER (stmt) + 1);
18533 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
18535 add_abstract_origin_attribute (subr_die, decl);
18536 if (TREE_ASM_WRITTEN (stmt))
18537 add_high_low_attributes (stmt, subr_die);
18538 add_call_src_coords_attributes (stmt, subr_die);
18540 decls_for_scope (stmt, subr_die, depth);
18541 current_function_has_inlines = 1;
18545 /* Generate a DIE for a field in a record, or structure. */
18548 gen_field_die (tree decl, dw_die_ref context_die)
18550 dw_die_ref decl_die;
18552 if (TREE_TYPE (decl) == error_mark_node)
18555 decl_die = new_die (DW_TAG_member, context_die, decl);
18556 add_name_and_src_coords_attributes (decl_die, decl);
18557 add_type_attribute (decl_die, member_declared_type (decl),
18558 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
18561 if (DECL_BIT_FIELD_TYPE (decl))
18563 add_byte_size_attribute (decl_die, decl);
18564 add_bit_size_attribute (decl_die, decl);
18565 add_bit_offset_attribute (decl_die, decl);
18568 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
18569 add_data_member_location_attribute (decl_die, decl);
18571 if (DECL_ARTIFICIAL (decl))
18572 add_AT_flag (decl_die, DW_AT_artificial, 1);
18574 add_accessibility_attribute (decl_die, decl);
18576 /* Equate decl number to die, so that we can look up this decl later on. */
18577 equate_decl_number_to_die (decl, decl_die);
18581 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18582 Use modified_type_die instead.
18583 We keep this code here just in case these types of DIEs may be needed to
18584 represent certain things in other languages (e.g. Pascal) someday. */
18587 gen_pointer_type_die (tree type, dw_die_ref context_die)
18590 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
18592 equate_type_number_to_die (type, ptr_die);
18593 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
18594 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
18597 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18598 Use modified_type_die instead.
18599 We keep this code here just in case these types of DIEs may be needed to
18600 represent certain things in other languages (e.g. Pascal) someday. */
18603 gen_reference_type_die (tree type, dw_die_ref context_die)
18605 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
18607 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
18608 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
18610 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
18612 equate_type_number_to_die (type, ref_die);
18613 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
18614 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
18618 /* Generate a DIE for a pointer to a member type. */
18621 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
18624 = new_die (DW_TAG_ptr_to_member_type,
18625 scope_die_for (type, context_die), type);
18627 equate_type_number_to_die (type, ptr_die);
18628 add_AT_die_ref (ptr_die, DW_AT_containing_type,
18629 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
18630 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
18633 /* Generate the DIE for the compilation unit. */
18636 gen_compile_unit_die (const char *filename)
18639 char producer[250];
18640 const char *language_string = lang_hooks.name;
18643 die = new_die (DW_TAG_compile_unit, NULL, NULL);
18647 add_name_attribute (die, filename);
18648 /* Don't add cwd for <built-in>. */
18649 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
18650 add_comp_dir_attribute (die);
18653 sprintf (producer, "%s %s", language_string, version_string);
18655 #ifdef MIPS_DEBUGGING_INFO
18656 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
18657 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
18658 not appear in the producer string, the debugger reaches the conclusion
18659 that the object file is stripped and has no debugging information.
18660 To get the MIPS/SGI debugger to believe that there is debugging
18661 information in the object file, we add a -g to the producer string. */
18662 if (debug_info_level > DINFO_LEVEL_TERSE)
18663 strcat (producer, " -g");
18666 add_AT_string (die, DW_AT_producer, producer);
18668 /* If our producer is LTO try to figure out a common language to use
18669 from the global list of translation units. */
18670 if (strcmp (language_string, "GNU GIMPLE") == 0)
18674 const char *common_lang = NULL;
18676 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
18678 if (!TRANSLATION_UNIT_LANGUAGE (t))
18681 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
18682 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
18684 else if (strncmp (common_lang, "GNU C", 5) == 0
18685 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
18686 /* Mixing C and C++ is ok, use C++ in that case. */
18687 common_lang = "GNU C++";
18690 /* Fall back to C. */
18691 common_lang = NULL;
18697 language_string = common_lang;
18700 language = DW_LANG_C89;
18701 if (strcmp (language_string, "GNU C++") == 0)
18702 language = DW_LANG_C_plus_plus;
18703 else if (strcmp (language_string, "GNU F77") == 0)
18704 language = DW_LANG_Fortran77;
18705 else if (strcmp (language_string, "GNU Pascal") == 0)
18706 language = DW_LANG_Pascal83;
18707 else if (dwarf_version >= 3 || !dwarf_strict)
18709 if (strcmp (language_string, "GNU Ada") == 0)
18710 language = DW_LANG_Ada95;
18711 else if (strcmp (language_string, "GNU Fortran") == 0)
18712 language = DW_LANG_Fortran95;
18713 else if (strcmp (language_string, "GNU Java") == 0)
18714 language = DW_LANG_Java;
18715 else if (strcmp (language_string, "GNU Objective-C") == 0)
18716 language = DW_LANG_ObjC;
18717 else if (strcmp (language_string, "GNU Objective-C++") == 0)
18718 language = DW_LANG_ObjC_plus_plus;
18721 add_AT_unsigned (die, DW_AT_language, language);
18725 case DW_LANG_Fortran77:
18726 case DW_LANG_Fortran90:
18727 case DW_LANG_Fortran95:
18728 /* Fortran has case insensitive identifiers and the front-end
18729 lowercases everything. */
18730 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
18733 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18739 /* Generate the DIE for a base class. */
18742 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
18744 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
18746 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
18747 add_data_member_location_attribute (die, binfo);
18749 if (BINFO_VIRTUAL_P (binfo))
18750 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
18752 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18753 children, otherwise the default is DW_ACCESS_public. In DWARF2
18754 the default has always been DW_ACCESS_private. */
18755 if (access == access_public_node)
18757 if (dwarf_version == 2
18758 || context_die->die_tag == DW_TAG_class_type)
18759 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
18761 else if (access == access_protected_node)
18762 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
18763 else if (dwarf_version > 2
18764 && context_die->die_tag != DW_TAG_class_type)
18765 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
18768 /* Generate a DIE for a class member. */
18771 gen_member_die (tree type, dw_die_ref context_die)
18774 tree binfo = TYPE_BINFO (type);
18777 /* If this is not an incomplete type, output descriptions of each of its
18778 members. Note that as we output the DIEs necessary to represent the
18779 members of this record or union type, we will also be trying to output
18780 DIEs to represent the *types* of those members. However the `type'
18781 function (above) will specifically avoid generating type DIEs for member
18782 types *within* the list of member DIEs for this (containing) type except
18783 for those types (of members) which are explicitly marked as also being
18784 members of this (containing) type themselves. The g++ front- end can
18785 force any given type to be treated as a member of some other (containing)
18786 type by setting the TYPE_CONTEXT of the given (member) type to point to
18787 the TREE node representing the appropriate (containing) type. */
18789 /* First output info about the base classes. */
18792 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
18796 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
18797 gen_inheritance_die (base,
18798 (accesses ? VEC_index (tree, accesses, i)
18799 : access_public_node), context_die);
18802 /* Now output info about the data members and type members. */
18803 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
18805 /* If we thought we were generating minimal debug info for TYPE
18806 and then changed our minds, some of the member declarations
18807 may have already been defined. Don't define them again, but
18808 do put them in the right order. */
18810 child = lookup_decl_die (member);
18812 splice_child_die (context_die, child);
18814 gen_decl_die (member, NULL, context_die);
18817 /* Now output info about the function members (if any). */
18818 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
18820 /* Don't include clones in the member list. */
18821 if (DECL_ABSTRACT_ORIGIN (member))
18824 child = lookup_decl_die (member);
18826 splice_child_die (context_die, child);
18828 gen_decl_die (member, NULL, context_die);
18832 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
18833 is set, we pretend that the type was never defined, so we only get the
18834 member DIEs needed by later specification DIEs. */
18837 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
18838 enum debug_info_usage usage)
18840 dw_die_ref type_die = lookup_type_die (type);
18841 dw_die_ref scope_die = 0;
18843 int complete = (TYPE_SIZE (type)
18844 && (! TYPE_STUB_DECL (type)
18845 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
18846 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
18847 complete = complete && should_emit_struct_debug (type, usage);
18849 if (type_die && ! complete)
18852 if (TYPE_CONTEXT (type) != NULL_TREE
18853 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
18854 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
18857 scope_die = scope_die_for (type, context_die);
18859 if (! type_die || (nested && is_cu_die (scope_die)))
18860 /* First occurrence of type or toplevel definition of nested class. */
18862 dw_die_ref old_die = type_die;
18864 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
18865 ? record_type_tag (type) : DW_TAG_union_type,
18867 equate_type_number_to_die (type, type_die);
18869 add_AT_specification (type_die, old_die);
18872 add_name_attribute (type_die, type_tag (type));
18873 add_gnat_descriptive_type_attribute (type_die, type, context_die);
18874 if (TYPE_ARTIFICIAL (type))
18875 add_AT_flag (type_die, DW_AT_artificial, 1);
18879 remove_AT (type_die, DW_AT_declaration);
18881 /* Generate child dies for template paramaters. */
18882 if (debug_info_level > DINFO_LEVEL_TERSE
18883 && COMPLETE_TYPE_P (type))
18884 schedule_generic_params_dies_gen (type);
18886 /* If this type has been completed, then give it a byte_size attribute and
18887 then give a list of members. */
18888 if (complete && !ns_decl)
18890 /* Prevent infinite recursion in cases where the type of some member of
18891 this type is expressed in terms of this type itself. */
18892 TREE_ASM_WRITTEN (type) = 1;
18893 add_byte_size_attribute (type_die, type);
18894 if (TYPE_STUB_DECL (type) != NULL_TREE)
18896 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18897 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18900 /* If the first reference to this type was as the return type of an
18901 inline function, then it may not have a parent. Fix this now. */
18902 if (type_die->die_parent == NULL)
18903 add_child_die (scope_die, type_die);
18905 push_decl_scope (type);
18906 gen_member_die (type, type_die);
18909 /* GNU extension: Record what type our vtable lives in. */
18910 if (TYPE_VFIELD (type))
18912 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
18914 gen_type_die (vtype, context_die);
18915 add_AT_die_ref (type_die, DW_AT_containing_type,
18916 lookup_type_die (vtype));
18921 add_AT_flag (type_die, DW_AT_declaration, 1);
18923 /* We don't need to do this for function-local types. */
18924 if (TYPE_STUB_DECL (type)
18925 && ! decl_function_context (TYPE_STUB_DECL (type)))
18926 VEC_safe_push (tree, gc, incomplete_types, type);
18929 if (get_AT (type_die, DW_AT_name))
18930 add_pubtype (type, type_die);
18933 /* Generate a DIE for a subroutine _type_. */
18936 gen_subroutine_type_die (tree type, dw_die_ref context_die)
18938 tree return_type = TREE_TYPE (type);
18939 dw_die_ref subr_die
18940 = new_die (DW_TAG_subroutine_type,
18941 scope_die_for (type, context_die), type);
18943 equate_type_number_to_die (type, subr_die);
18944 add_prototyped_attribute (subr_die, type);
18945 add_type_attribute (subr_die, return_type, 0, 0, context_die);
18946 gen_formal_types_die (type, subr_die);
18948 if (get_AT (subr_die, DW_AT_name))
18949 add_pubtype (type, subr_die);
18952 /* Generate a DIE for a type definition. */
18955 gen_typedef_die (tree decl, dw_die_ref context_die)
18957 dw_die_ref type_die;
18960 if (TREE_ASM_WRITTEN (decl))
18963 TREE_ASM_WRITTEN (decl) = 1;
18964 type_die = new_die (DW_TAG_typedef, context_die, decl);
18965 origin = decl_ultimate_origin (decl);
18966 if (origin != NULL)
18967 add_abstract_origin_attribute (type_die, origin);
18972 add_name_and_src_coords_attributes (type_die, decl);
18973 if (DECL_ORIGINAL_TYPE (decl))
18975 type = DECL_ORIGINAL_TYPE (decl);
18977 gcc_assert (type != TREE_TYPE (decl));
18978 equate_type_number_to_die (TREE_TYPE (decl), type_die);
18982 type = TREE_TYPE (decl);
18984 if (is_naming_typedef_decl (TYPE_NAME (type)))
18986 /* Here, we are in the case of decl being a typedef naming
18987 an anonymous type, e.g:
18988 typedef struct {...} foo;
18989 In that case TREE_TYPE (decl) is not a typedef variant
18990 type and TYPE_NAME of the anonymous type is set to the
18991 TYPE_DECL of the typedef. This construct is emitted by
18994 TYPE is the anonymous struct named by the typedef
18995 DECL. As we need the DW_AT_type attribute of the
18996 DW_TAG_typedef to point to the DIE of TYPE, let's
18997 generate that DIE right away. add_type_attribute
18998 called below will then pick (via lookup_type_die) that
18999 anonymous struct DIE. */
19000 if (!TREE_ASM_WRITTEN (type))
19001 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
19003 /* This is a GNU Extension. We are adding a
19004 DW_AT_linkage_name attribute to the DIE of the
19005 anonymous struct TYPE. The value of that attribute
19006 is the name of the typedef decl naming the anonymous
19007 struct. This greatly eases the work of consumers of
19008 this debug info. */
19009 add_linkage_attr (lookup_type_die (type), decl);
19013 add_type_attribute (type_die, type, TREE_READONLY (decl),
19014 TREE_THIS_VOLATILE (decl), context_die);
19016 if (is_naming_typedef_decl (decl))
19017 /* We want that all subsequent calls to lookup_type_die with
19018 TYPE in argument yield the DW_TAG_typedef we have just
19020 equate_type_number_to_die (type, type_die);
19022 add_accessibility_attribute (type_die, decl);
19025 if (DECL_ABSTRACT (decl))
19026 equate_decl_number_to_die (decl, type_die);
19028 if (get_AT (type_die, DW_AT_name))
19029 add_pubtype (decl, type_die);
19032 /* Generate a DIE for a struct, class, enum or union type. */
19035 gen_tagged_type_die (tree type,
19036 dw_die_ref context_die,
19037 enum debug_info_usage usage)
19041 if (type == NULL_TREE
19042 || !is_tagged_type (type))
19045 /* If this is a nested type whose containing class hasn't been written
19046 out yet, writing it out will cover this one, too. This does not apply
19047 to instantiations of member class templates; they need to be added to
19048 the containing class as they are generated. FIXME: This hurts the
19049 idea of combining type decls from multiple TUs, since we can't predict
19050 what set of template instantiations we'll get. */
19051 if (TYPE_CONTEXT (type)
19052 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
19053 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
19055 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
19057 if (TREE_ASM_WRITTEN (type))
19060 /* If that failed, attach ourselves to the stub. */
19061 push_decl_scope (TYPE_CONTEXT (type));
19062 context_die = lookup_type_die (TYPE_CONTEXT (type));
19065 else if (TYPE_CONTEXT (type) != NULL_TREE
19066 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
19068 /* If this type is local to a function that hasn't been written
19069 out yet, use a NULL context for now; it will be fixed up in
19070 decls_for_scope. */
19071 context_die = lookup_decl_die (TYPE_CONTEXT (type));
19072 /* A declaration DIE doesn't count; nested types need to go in the
19074 if (context_die && is_declaration_die (context_die))
19075 context_die = NULL;
19080 context_die = declare_in_namespace (type, context_die);
19084 if (TREE_CODE (type) == ENUMERAL_TYPE)
19086 /* This might have been written out by the call to
19087 declare_in_namespace. */
19088 if (!TREE_ASM_WRITTEN (type))
19089 gen_enumeration_type_die (type, context_die);
19092 gen_struct_or_union_type_die (type, context_die, usage);
19097 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19098 it up if it is ever completed. gen_*_type_die will set it for us
19099 when appropriate. */
19102 /* Generate a type description DIE. */
19105 gen_type_die_with_usage (tree type, dw_die_ref context_die,
19106 enum debug_info_usage usage)
19108 struct array_descr_info info;
19110 if (type == NULL_TREE || type == error_mark_node)
19113 if (TYPE_NAME (type) != NULL_TREE
19114 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
19115 && is_redundant_typedef (TYPE_NAME (type))
19116 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
19117 /* The DECL of this type is a typedef we don't want to emit debug
19118 info for but we want debug info for its underlying typedef.
19119 This can happen for e.g, the injected-class-name of a C++
19121 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
19123 /* If TYPE is a typedef type variant, let's generate debug info
19124 for the parent typedef which TYPE is a type of. */
19125 if (typedef_variant_p (type))
19127 if (TREE_ASM_WRITTEN (type))
19130 /* Prevent broken recursion; we can't hand off to the same type. */
19131 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
19133 /* Use the DIE of the containing namespace as the parent DIE of
19134 the type description DIE we want to generate. */
19135 if (DECL_CONTEXT (TYPE_NAME (type))
19136 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
19137 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
19139 TREE_ASM_WRITTEN (type) = 1;
19141 gen_decl_die (TYPE_NAME (type), NULL, context_die);
19145 /* If type is an anonymous tagged type named by a typedef, let's
19146 generate debug info for the typedef. */
19147 if (is_naming_typedef_decl (TYPE_NAME (type)))
19149 /* Use the DIE of the containing namespace as the parent DIE of
19150 the type description DIE we want to generate. */
19151 if (DECL_CONTEXT (TYPE_NAME (type))
19152 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
19153 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
19155 gen_decl_die (TYPE_NAME (type), NULL, context_die);
19159 /* If this is an array type with hidden descriptor, handle it first. */
19160 if (!TREE_ASM_WRITTEN (type)
19161 && lang_hooks.types.get_array_descr_info
19162 && lang_hooks.types.get_array_descr_info (type, &info)
19163 && (dwarf_version >= 3 || !dwarf_strict))
19165 gen_descr_array_type_die (type, &info, context_die);
19166 TREE_ASM_WRITTEN (type) = 1;
19170 /* We are going to output a DIE to represent the unqualified version
19171 of this type (i.e. without any const or volatile qualifiers) so
19172 get the main variant (i.e. the unqualified version) of this type
19173 now. (Vectors are special because the debugging info is in the
19174 cloned type itself). */
19175 if (TREE_CODE (type) != VECTOR_TYPE)
19176 type = type_main_variant (type);
19178 if (TREE_ASM_WRITTEN (type))
19181 switch (TREE_CODE (type))
19187 case REFERENCE_TYPE:
19188 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19189 ensures that the gen_type_die recursion will terminate even if the
19190 type is recursive. Recursive types are possible in Ada. */
19191 /* ??? We could perhaps do this for all types before the switch
19193 TREE_ASM_WRITTEN (type) = 1;
19195 /* For these types, all that is required is that we output a DIE (or a
19196 set of DIEs) to represent the "basis" type. */
19197 gen_type_die_with_usage (TREE_TYPE (type), context_die,
19198 DINFO_USAGE_IND_USE);
19202 /* This code is used for C++ pointer-to-data-member types.
19203 Output a description of the relevant class type. */
19204 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
19205 DINFO_USAGE_IND_USE);
19207 /* Output a description of the type of the object pointed to. */
19208 gen_type_die_with_usage (TREE_TYPE (type), context_die,
19209 DINFO_USAGE_IND_USE);
19211 /* Now output a DIE to represent this pointer-to-data-member type
19213 gen_ptr_to_mbr_type_die (type, context_die);
19216 case FUNCTION_TYPE:
19217 /* Force out return type (in case it wasn't forced out already). */
19218 gen_type_die_with_usage (TREE_TYPE (type), context_die,
19219 DINFO_USAGE_DIR_USE);
19220 gen_subroutine_type_die (type, context_die);
19224 /* Force out return type (in case it wasn't forced out already). */
19225 gen_type_die_with_usage (TREE_TYPE (type), context_die,
19226 DINFO_USAGE_DIR_USE);
19227 gen_subroutine_type_die (type, context_die);
19231 gen_array_type_die (type, context_die);
19235 gen_array_type_die (type, context_die);
19238 case ENUMERAL_TYPE:
19241 case QUAL_UNION_TYPE:
19242 gen_tagged_type_die (type, context_die, usage);
19248 case FIXED_POINT_TYPE:
19251 /* No DIEs needed for fundamental types. */
19256 /* Just use DW_TAG_unspecified_type. */
19258 dw_die_ref type_die = lookup_type_die (type);
19259 if (type_die == NULL)
19261 tree name = TYPE_NAME (type);
19262 if (TREE_CODE (name) == TYPE_DECL)
19263 name = DECL_NAME (name);
19264 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
19265 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
19266 equate_type_number_to_die (type, type_die);
19272 gcc_unreachable ();
19275 TREE_ASM_WRITTEN (type) = 1;
19279 gen_type_die (tree type, dw_die_ref context_die)
19281 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
19284 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19285 things which are local to the given block. */
19288 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
19290 int must_output_die = 0;
19293 /* Ignore blocks that are NULL. */
19294 if (stmt == NULL_TREE)
19297 inlined_func = inlined_function_outer_scope_p (stmt);
19299 /* If the block is one fragment of a non-contiguous block, do not
19300 process the variables, since they will have been done by the
19301 origin block. Do process subblocks. */
19302 if (BLOCK_FRAGMENT_ORIGIN (stmt))
19306 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
19307 gen_block_die (sub, context_die, depth + 1);
19312 /* Determine if we need to output any Dwarf DIEs at all to represent this
19315 /* The outer scopes for inlinings *must* always be represented. We
19316 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19317 must_output_die = 1;
19320 /* Determine if this block directly contains any "significant"
19321 local declarations which we will need to output DIEs for. */
19322 if (debug_info_level > DINFO_LEVEL_TERSE)
19323 /* We are not in terse mode so *any* local declaration counts
19324 as being a "significant" one. */
19325 must_output_die = ((BLOCK_VARS (stmt) != NULL
19326 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
19327 && (TREE_USED (stmt)
19328 || TREE_ASM_WRITTEN (stmt)
19329 || BLOCK_ABSTRACT (stmt)));
19330 else if ((TREE_USED (stmt)
19331 || TREE_ASM_WRITTEN (stmt)
19332 || BLOCK_ABSTRACT (stmt))
19333 && !dwarf2out_ignore_block (stmt))
19334 must_output_die = 1;
19337 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19338 DIE for any block which contains no significant local declarations at
19339 all. Rather, in such cases we just call `decls_for_scope' so that any
19340 needed Dwarf info for any sub-blocks will get properly generated. Note
19341 that in terse mode, our definition of what constitutes a "significant"
19342 local declaration gets restricted to include only inlined function
19343 instances and local (nested) function definitions. */
19344 if (must_output_die)
19348 /* If STMT block is abstract, that means we have been called
19349 indirectly from dwarf2out_abstract_function.
19350 That function rightfully marks the descendent blocks (of
19351 the abstract function it is dealing with) as being abstract,
19352 precisely to prevent us from emitting any
19353 DW_TAG_inlined_subroutine DIE as a descendent
19354 of an abstract function instance. So in that case, we should
19355 not call gen_inlined_subroutine_die.
19357 Later though, when cgraph asks dwarf2out to emit info
19358 for the concrete instance of the function decl into which
19359 the concrete instance of STMT got inlined, the later will lead
19360 to the generation of a DW_TAG_inlined_subroutine DIE. */
19361 if (! BLOCK_ABSTRACT (stmt))
19362 gen_inlined_subroutine_die (stmt, context_die, depth);
19365 gen_lexical_block_die (stmt, context_die, depth);
19368 decls_for_scope (stmt, context_die, depth);
19371 /* Process variable DECL (or variable with origin ORIGIN) within
19372 block STMT and add it to CONTEXT_DIE. */
19374 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
19377 tree decl_or_origin = decl ? decl : origin;
19379 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
19380 die = lookup_decl_die (decl_or_origin);
19381 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
19382 && TYPE_DECL_IS_STUB (decl_or_origin))
19383 die = lookup_type_die (TREE_TYPE (decl_or_origin));
19387 if (die != NULL && die->die_parent == NULL)
19388 add_child_die (context_die, die);
19389 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
19390 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
19391 stmt, context_die);
19393 gen_decl_die (decl, origin, context_die);
19396 /* Generate all of the decls declared within a given scope and (recursively)
19397 all of its sub-blocks. */
19400 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
19406 /* Ignore NULL blocks. */
19407 if (stmt == NULL_TREE)
19410 /* Output the DIEs to represent all of the data objects and typedefs
19411 declared directly within this block but not within any nested
19412 sub-blocks. Also, nested function and tag DIEs have been
19413 generated with a parent of NULL; fix that up now. */
19414 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
19415 process_scope_var (stmt, decl, NULL_TREE, context_die);
19416 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
19417 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
19420 /* If we're at -g1, we're not interested in subblocks. */
19421 if (debug_info_level <= DINFO_LEVEL_TERSE)
19424 /* Output the DIEs to represent all sub-blocks (and the items declared
19425 therein) of this block. */
19426 for (subblocks = BLOCK_SUBBLOCKS (stmt);
19428 subblocks = BLOCK_CHAIN (subblocks))
19429 gen_block_die (subblocks, context_die, depth + 1);
19432 /* Is this a typedef we can avoid emitting? */
19435 is_redundant_typedef (const_tree decl)
19437 if (TYPE_DECL_IS_STUB (decl))
19440 if (DECL_ARTIFICIAL (decl)
19441 && DECL_CONTEXT (decl)
19442 && is_tagged_type (DECL_CONTEXT (decl))
19443 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
19444 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
19445 /* Also ignore the artificial member typedef for the class name. */
19451 /* Return TRUE if TYPE is a typedef that names a type for linkage
19452 purposes. This kind of typedefs is produced by the C++ FE for
19455 typedef struct {...} foo;
19457 In that case, there is no typedef variant type produced for foo.
19458 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19462 is_naming_typedef_decl (const_tree decl)
19464 if (decl == NULL_TREE
19465 || TREE_CODE (decl) != TYPE_DECL
19466 || !is_tagged_type (TREE_TYPE (decl))
19467 || DECL_IS_BUILTIN (decl)
19468 || is_redundant_typedef (decl)
19469 /* It looks like Ada produces TYPE_DECLs that are very similar
19470 to C++ naming typedefs but that have different
19471 semantics. Let's be specific to c++ for now. */
19475 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
19476 && TYPE_NAME (TREE_TYPE (decl)) == decl
19477 && (TYPE_STUB_DECL (TREE_TYPE (decl))
19478 != TYPE_NAME (TREE_TYPE (decl))));
19481 /* Returns the DIE for a context. */
19483 static inline dw_die_ref
19484 get_context_die (tree context)
19488 /* Find die that represents this context. */
19489 if (TYPE_P (context))
19491 context = TYPE_MAIN_VARIANT (context);
19492 return strip_naming_typedef (context, force_type_die (context));
19495 return force_decl_die (context);
19497 return comp_unit_die ();
19500 /* Returns the DIE for decl. A DIE will always be returned. */
19503 force_decl_die (tree decl)
19505 dw_die_ref decl_die;
19506 unsigned saved_external_flag;
19507 tree save_fn = NULL_TREE;
19508 decl_die = lookup_decl_die (decl);
19511 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
19513 decl_die = lookup_decl_die (decl);
19517 switch (TREE_CODE (decl))
19519 case FUNCTION_DECL:
19520 /* Clear current_function_decl, so that gen_subprogram_die thinks
19521 that this is a declaration. At this point, we just want to force
19522 declaration die. */
19523 save_fn = current_function_decl;
19524 current_function_decl = NULL_TREE;
19525 gen_subprogram_die (decl, context_die);
19526 current_function_decl = save_fn;
19530 /* Set external flag to force declaration die. Restore it after
19531 gen_decl_die() call. */
19532 saved_external_flag = DECL_EXTERNAL (decl);
19533 DECL_EXTERNAL (decl) = 1;
19534 gen_decl_die (decl, NULL, context_die);
19535 DECL_EXTERNAL (decl) = saved_external_flag;
19538 case NAMESPACE_DECL:
19539 if (dwarf_version >= 3 || !dwarf_strict)
19540 dwarf2out_decl (decl);
19542 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19543 decl_die = comp_unit_die ();
19546 case TRANSLATION_UNIT_DECL:
19547 decl_die = comp_unit_die ();
19551 gcc_unreachable ();
19554 /* We should be able to find the DIE now. */
19556 decl_die = lookup_decl_die (decl);
19557 gcc_assert (decl_die);
19563 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19564 always returned. */
19567 force_type_die (tree type)
19569 dw_die_ref type_die;
19571 type_die = lookup_type_die (type);
19574 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
19576 type_die = modified_type_die (type, TYPE_READONLY (type),
19577 TYPE_VOLATILE (type), context_die);
19578 gcc_assert (type_die);
19583 /* Force out any required namespaces to be able to output DECL,
19584 and return the new context_die for it, if it's changed. */
19587 setup_namespace_context (tree thing, dw_die_ref context_die)
19589 tree context = (DECL_P (thing)
19590 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
19591 if (context && TREE_CODE (context) == NAMESPACE_DECL)
19592 /* Force out the namespace. */
19593 context_die = force_decl_die (context);
19595 return context_die;
19598 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19599 type) within its namespace, if appropriate.
19601 For compatibility with older debuggers, namespace DIEs only contain
19602 declarations; all definitions are emitted at CU scope. */
19605 declare_in_namespace (tree thing, dw_die_ref context_die)
19607 dw_die_ref ns_context;
19609 if (debug_info_level <= DINFO_LEVEL_TERSE)
19610 return context_die;
19612 /* If this decl is from an inlined function, then don't try to emit it in its
19613 namespace, as we will get confused. It would have already been emitted
19614 when the abstract instance of the inline function was emitted anyways. */
19615 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
19616 return context_die;
19618 ns_context = setup_namespace_context (thing, context_die);
19620 if (ns_context != context_die)
19624 if (DECL_P (thing))
19625 gen_decl_die (thing, NULL, ns_context);
19627 gen_type_die (thing, ns_context);
19629 return context_die;
19632 /* Generate a DIE for a namespace or namespace alias. */
19635 gen_namespace_die (tree decl, dw_die_ref context_die)
19637 dw_die_ref namespace_die;
19639 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19640 they are an alias of. */
19641 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
19643 /* Output a real namespace or module. */
19644 context_die = setup_namespace_context (decl, comp_unit_die ());
19645 namespace_die = new_die (is_fortran ()
19646 ? DW_TAG_module : DW_TAG_namespace,
19647 context_die, decl);
19648 /* For Fortran modules defined in different CU don't add src coords. */
19649 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
19651 const char *name = dwarf2_name (decl, 0);
19653 add_name_attribute (namespace_die, name);
19656 add_name_and_src_coords_attributes (namespace_die, decl);
19657 if (DECL_EXTERNAL (decl))
19658 add_AT_flag (namespace_die, DW_AT_declaration, 1);
19659 equate_decl_number_to_die (decl, namespace_die);
19663 /* Output a namespace alias. */
19665 /* Force out the namespace we are an alias of, if necessary. */
19666 dw_die_ref origin_die
19667 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
19669 if (DECL_FILE_SCOPE_P (decl)
19670 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
19671 context_die = setup_namespace_context (decl, comp_unit_die ());
19672 /* Now create the namespace alias DIE. */
19673 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
19674 add_name_and_src_coords_attributes (namespace_die, decl);
19675 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
19676 equate_decl_number_to_die (decl, namespace_die);
19680 /* Generate Dwarf debug information for a decl described by DECL.
19681 The return value is currently only meaningful for PARM_DECLs,
19682 for all other decls it returns NULL. */
19685 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
19687 tree decl_or_origin = decl ? decl : origin;
19688 tree class_origin = NULL, ultimate_origin;
19690 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
19693 switch (TREE_CODE (decl_or_origin))
19699 if (!is_fortran () && !is_ada ())
19701 /* The individual enumerators of an enum type get output when we output
19702 the Dwarf representation of the relevant enum type itself. */
19706 /* Emit its type. */
19707 gen_type_die (TREE_TYPE (decl), context_die);
19709 /* And its containing namespace. */
19710 context_die = declare_in_namespace (decl, context_die);
19712 gen_const_die (decl, context_die);
19715 case FUNCTION_DECL:
19716 /* Don't output any DIEs to represent mere function declarations,
19717 unless they are class members or explicit block externs. */
19718 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
19719 && DECL_FILE_SCOPE_P (decl_or_origin)
19720 && (current_function_decl == NULL_TREE
19721 || DECL_ARTIFICIAL (decl_or_origin)))
19726 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19727 on local redeclarations of global functions. That seems broken. */
19728 if (current_function_decl != decl)
19729 /* This is only a declaration. */;
19732 /* If we're emitting a clone, emit info for the abstract instance. */
19733 if (origin || DECL_ORIGIN (decl) != decl)
19734 dwarf2out_abstract_function (origin
19735 ? DECL_ORIGIN (origin)
19736 : DECL_ABSTRACT_ORIGIN (decl));
19738 /* If we're emitting an out-of-line copy of an inline function,
19739 emit info for the abstract instance and set up to refer to it. */
19740 else if (cgraph_function_possibly_inlined_p (decl)
19741 && ! DECL_ABSTRACT (decl)
19742 && ! class_or_namespace_scope_p (context_die)
19743 /* dwarf2out_abstract_function won't emit a die if this is just
19744 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19745 that case, because that works only if we have a die. */
19746 && DECL_INITIAL (decl) != NULL_TREE)
19748 dwarf2out_abstract_function (decl);
19749 set_decl_origin_self (decl);
19752 /* Otherwise we're emitting the primary DIE for this decl. */
19753 else if (debug_info_level > DINFO_LEVEL_TERSE)
19755 /* Before we describe the FUNCTION_DECL itself, make sure that we
19756 have its containing type. */
19758 origin = decl_class_context (decl);
19759 if (origin != NULL_TREE)
19760 gen_type_die (origin, context_die);
19762 /* And its return type. */
19763 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
19765 /* And its virtual context. */
19766 if (DECL_VINDEX (decl) != NULL_TREE)
19767 gen_type_die (DECL_CONTEXT (decl), context_die);
19769 /* Make sure we have a member DIE for decl. */
19770 if (origin != NULL_TREE)
19771 gen_type_die_for_member (origin, decl, context_die);
19773 /* And its containing namespace. */
19774 context_die = declare_in_namespace (decl, context_die);
19777 /* Now output a DIE to represent the function itself. */
19779 gen_subprogram_die (decl, context_die);
19783 /* If we are in terse mode, don't generate any DIEs to represent any
19784 actual typedefs. */
19785 if (debug_info_level <= DINFO_LEVEL_TERSE)
19788 /* In the special case of a TYPE_DECL node representing the declaration
19789 of some type tag, if the given TYPE_DECL is marked as having been
19790 instantiated from some other (original) TYPE_DECL node (e.g. one which
19791 was generated within the original definition of an inline function) we
19792 used to generate a special (abbreviated) DW_TAG_structure_type,
19793 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
19794 should be actually referencing those DIEs, as variable DIEs with that
19795 type would be emitted already in the abstract origin, so it was always
19796 removed during unused type prunning. Don't add anything in this
19798 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
19801 if (is_redundant_typedef (decl))
19802 gen_type_die (TREE_TYPE (decl), context_die);
19804 /* Output a DIE to represent the typedef itself. */
19805 gen_typedef_die (decl, context_die);
19809 if (debug_info_level >= DINFO_LEVEL_NORMAL)
19810 gen_label_die (decl, context_die);
19815 /* If we are in terse mode, don't generate any DIEs to represent any
19816 variable declarations or definitions. */
19817 if (debug_info_level <= DINFO_LEVEL_TERSE)
19820 /* Output any DIEs that are needed to specify the type of this data
19822 if (decl_by_reference_p (decl_or_origin))
19823 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
19825 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
19827 /* And its containing type. */
19828 class_origin = decl_class_context (decl_or_origin);
19829 if (class_origin != NULL_TREE)
19830 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
19832 /* And its containing namespace. */
19833 context_die = declare_in_namespace (decl_or_origin, context_die);
19835 /* Now output the DIE to represent the data object itself. This gets
19836 complicated because of the possibility that the VAR_DECL really
19837 represents an inlined instance of a formal parameter for an inline
19839 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19840 if (ultimate_origin != NULL_TREE
19841 && TREE_CODE (ultimate_origin) == PARM_DECL)
19842 gen_formal_parameter_die (decl, origin,
19843 true /* Emit name attribute. */,
19846 gen_variable_die (decl, origin, context_die);
19850 /* Ignore the nameless fields that are used to skip bits but handle C++
19851 anonymous unions and structs. */
19852 if (DECL_NAME (decl) != NULL_TREE
19853 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
19854 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
19856 gen_type_die (member_declared_type (decl), context_die);
19857 gen_field_die (decl, context_die);
19862 if (DECL_BY_REFERENCE (decl_or_origin))
19863 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
19865 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
19866 return gen_formal_parameter_die (decl, origin,
19867 true /* Emit name attribute. */,
19870 case NAMESPACE_DECL:
19871 case IMPORTED_DECL:
19872 if (dwarf_version >= 3 || !dwarf_strict)
19873 gen_namespace_die (decl, context_die);
19877 /* Probably some frontend-internal decl. Assume we don't care. */
19878 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
19885 /* Output debug information for global decl DECL. Called from toplev.c after
19886 compilation proper has finished. */
19889 dwarf2out_global_decl (tree decl)
19891 /* Output DWARF2 information for file-scope tentative data object
19892 declarations, file-scope (extern) function declarations (which
19893 had no corresponding body) and file-scope tagged type declarations
19894 and definitions which have not yet been forced out. */
19895 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
19896 dwarf2out_decl (decl);
19899 /* Output debug information for type decl DECL. Called from toplev.c
19900 and from language front ends (to record built-in types). */
19902 dwarf2out_type_decl (tree decl, int local)
19905 dwarf2out_decl (decl);
19908 /* Output debug information for imported module or decl DECL.
19909 NAME is non-NULL name in the lexical block if the decl has been renamed.
19910 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
19911 that DECL belongs to.
19912 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
19914 dwarf2out_imported_module_or_decl_1 (tree decl,
19916 tree lexical_block,
19917 dw_die_ref lexical_block_die)
19919 expanded_location xloc;
19920 dw_die_ref imported_die = NULL;
19921 dw_die_ref at_import_die;
19923 if (TREE_CODE (decl) == IMPORTED_DECL)
19925 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
19926 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
19930 xloc = expand_location (input_location);
19932 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
19934 at_import_die = force_type_die (TREE_TYPE (decl));
19935 /* For namespace N { typedef void T; } using N::T; base_type_die
19936 returns NULL, but DW_TAG_imported_declaration requires
19937 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
19938 if (!at_import_die)
19940 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
19941 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
19942 at_import_die = lookup_type_die (TREE_TYPE (decl));
19943 gcc_assert (at_import_die);
19948 at_import_die = lookup_decl_die (decl);
19949 if (!at_import_die)
19951 /* If we're trying to avoid duplicate debug info, we may not have
19952 emitted the member decl for this field. Emit it now. */
19953 if (TREE_CODE (decl) == FIELD_DECL)
19955 tree type = DECL_CONTEXT (decl);
19957 if (TYPE_CONTEXT (type)
19958 && TYPE_P (TYPE_CONTEXT (type))
19959 && !should_emit_struct_debug (TYPE_CONTEXT (type),
19960 DINFO_USAGE_DIR_USE))
19962 gen_type_die_for_member (type, decl,
19963 get_context_die (TYPE_CONTEXT (type)));
19965 at_import_die = force_decl_die (decl);
19969 if (TREE_CODE (decl) == NAMESPACE_DECL)
19971 if (dwarf_version >= 3 || !dwarf_strict)
19972 imported_die = new_die (DW_TAG_imported_module,
19979 imported_die = new_die (DW_TAG_imported_declaration,
19983 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
19984 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
19986 add_AT_string (imported_die, DW_AT_name,
19987 IDENTIFIER_POINTER (name));
19988 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
19991 /* Output debug information for imported module or decl DECL.
19992 NAME is non-NULL name in context if the decl has been renamed.
19993 CHILD is true if decl is one of the renamed decls as part of
19994 importing whole module. */
19997 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
20000 /* dw_die_ref at_import_die; */
20001 dw_die_ref scope_die;
20003 if (debug_info_level <= DINFO_LEVEL_TERSE)
20008 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20009 We need decl DIE for reference and scope die. First, get DIE for the decl
20012 /* Get the scope die for decl context. Use comp_unit_die for global module
20013 or decl. If die is not found for non globals, force new die. */
20015 && TYPE_P (context)
20016 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
20019 if (!(dwarf_version >= 3 || !dwarf_strict))
20022 scope_die = get_context_die (context);
20026 gcc_assert (scope_die->die_child);
20027 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
20028 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
20029 scope_die = scope_die->die_child;
20032 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20033 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
20037 /* Write the debugging output for DECL. */
20040 dwarf2out_decl (tree decl)
20042 dw_die_ref context_die = comp_unit_die ();
20044 switch (TREE_CODE (decl))
20049 case FUNCTION_DECL:
20050 /* What we would really like to do here is to filter out all mere
20051 file-scope declarations of file-scope functions which are never
20052 referenced later within this translation unit (and keep all of ones
20053 that *are* referenced later on) but we aren't clairvoyant, so we have
20054 no idea which functions will be referenced in the future (i.e. later
20055 on within the current translation unit). So here we just ignore all
20056 file-scope function declarations which are not also definitions. If
20057 and when the debugger needs to know something about these functions,
20058 it will have to hunt around and find the DWARF information associated
20059 with the definition of the function.
20061 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20062 nodes represent definitions and which ones represent mere
20063 declarations. We have to check DECL_INITIAL instead. That's because
20064 the C front-end supports some weird semantics for "extern inline"
20065 function definitions. These can get inlined within the current
20066 translation unit (and thus, we need to generate Dwarf info for their
20067 abstract instances so that the Dwarf info for the concrete inlined
20068 instances can have something to refer to) but the compiler never
20069 generates any out-of-lines instances of such things (despite the fact
20070 that they *are* definitions).
20072 The important point is that the C front-end marks these "extern
20073 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20074 them anyway. Note that the C++ front-end also plays some similar games
20075 for inline function definitions appearing within include files which
20076 also contain `#pragma interface' pragmas. */
20077 if (DECL_INITIAL (decl) == NULL_TREE)
20080 /* If we're a nested function, initially use a parent of NULL; if we're
20081 a plain function, this will be fixed up in decls_for_scope. If
20082 we're a method, it will be ignored, since we already have a DIE. */
20083 if (decl_function_context (decl)
20084 /* But if we're in terse mode, we don't care about scope. */
20085 && debug_info_level > DINFO_LEVEL_TERSE)
20086 context_die = NULL;
20090 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20091 declaration and if the declaration was never even referenced from
20092 within this entire compilation unit. We suppress these DIEs in
20093 order to save space in the .debug section (by eliminating entries
20094 which are probably useless). Note that we must not suppress
20095 block-local extern declarations (whether used or not) because that
20096 would screw-up the debugger's name lookup mechanism and cause it to
20097 miss things which really ought to be in scope at a given point. */
20098 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
20101 /* For local statics lookup proper context die. */
20102 if (TREE_STATIC (decl) && decl_function_context (decl))
20103 context_die = lookup_decl_die (DECL_CONTEXT (decl));
20105 /* If we are in terse mode, don't generate any DIEs to represent any
20106 variable declarations or definitions. */
20107 if (debug_info_level <= DINFO_LEVEL_TERSE)
20112 if (debug_info_level <= DINFO_LEVEL_TERSE)
20114 if (!is_fortran () && !is_ada ())
20116 if (TREE_STATIC (decl) && decl_function_context (decl))
20117 context_die = lookup_decl_die (DECL_CONTEXT (decl));
20120 case NAMESPACE_DECL:
20121 case IMPORTED_DECL:
20122 if (debug_info_level <= DINFO_LEVEL_TERSE)
20124 if (lookup_decl_die (decl) != NULL)
20129 /* Don't emit stubs for types unless they are needed by other DIEs. */
20130 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
20133 /* Don't bother trying to generate any DIEs to represent any of the
20134 normal built-in types for the language we are compiling. */
20135 if (DECL_IS_BUILTIN (decl))
20138 /* If we are in terse mode, don't generate any DIEs for types. */
20139 if (debug_info_level <= DINFO_LEVEL_TERSE)
20142 /* If we're a function-scope tag, initially use a parent of NULL;
20143 this will be fixed up in decls_for_scope. */
20144 if (decl_function_context (decl))
20145 context_die = NULL;
20153 gen_decl_die (decl, NULL, context_die);
20156 /* Write the debugging output for DECL. */
20159 dwarf2out_function_decl (tree decl)
20161 dwarf2out_decl (decl);
20162 call_arg_locations = NULL;
20163 call_arg_loc_last = NULL;
20164 call_site_count = -1;
20165 tail_call_site_count = -1;
20166 VEC_free (dw_die_ref, heap, block_map);
20167 htab_empty (decl_loc_table);
20168 htab_empty (cached_dw_loc_list_table);
20171 /* Output a marker (i.e. a label) for the beginning of the generated code for
20172 a lexical block. */
20175 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
20176 unsigned int blocknum)
20178 switch_to_section (current_function_section ());
20179 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
20182 /* Output a marker (i.e. a label) for the end of the generated code for a
20186 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
20188 switch_to_section (current_function_section ());
20189 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
20192 /* Returns nonzero if it is appropriate not to emit any debugging
20193 information for BLOCK, because it doesn't contain any instructions.
20195 Don't allow this for blocks with nested functions or local classes
20196 as we would end up with orphans, and in the presence of scheduling
20197 we may end up calling them anyway. */
20200 dwarf2out_ignore_block (const_tree block)
20205 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
20206 if (TREE_CODE (decl) == FUNCTION_DECL
20207 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
20209 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
20211 decl = BLOCK_NONLOCALIZED_VAR (block, i);
20212 if (TREE_CODE (decl) == FUNCTION_DECL
20213 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
20220 /* Hash table routines for file_hash. */
20223 file_table_eq (const void *p1_p, const void *p2_p)
20225 const struct dwarf_file_data *const p1 =
20226 (const struct dwarf_file_data *) p1_p;
20227 const char *const p2 = (const char *) p2_p;
20228 return filename_cmp (p1->filename, p2) == 0;
20232 file_table_hash (const void *p_p)
20234 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
20235 return htab_hash_string (p->filename);
20238 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20239 dwarf2out.c) and return its "index". The index of each (known) filename is
20240 just a unique number which is associated with only that one filename. We
20241 need such numbers for the sake of generating labels (in the .debug_sfnames
20242 section) and references to those files numbers (in the .debug_srcinfo
20243 and.debug_macinfo sections). If the filename given as an argument is not
20244 found in our current list, add it to the list and assign it the next
20245 available unique index number. In order to speed up searches, we remember
20246 the index of the filename was looked up last. This handles the majority of
20249 static struct dwarf_file_data *
20250 lookup_filename (const char *file_name)
20253 struct dwarf_file_data * created;
20255 /* Check to see if the file name that was searched on the previous
20256 call matches this file name. If so, return the index. */
20257 if (file_table_last_lookup
20258 && (file_name == file_table_last_lookup->filename
20259 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
20260 return file_table_last_lookup;
20262 /* Didn't match the previous lookup, search the table. */
20263 slot = htab_find_slot_with_hash (file_table, file_name,
20264 htab_hash_string (file_name), INSERT);
20266 return (struct dwarf_file_data *) *slot;
20268 created = ggc_alloc_dwarf_file_data ();
20269 created->filename = file_name;
20270 created->emitted_number = 0;
20275 /* If the assembler will construct the file table, then translate the compiler
20276 internal file table number into the assembler file table number, and emit
20277 a .file directive if we haven't already emitted one yet. The file table
20278 numbers are different because we prune debug info for unused variables and
20279 types, which may include filenames. */
20282 maybe_emit_file (struct dwarf_file_data * fd)
20284 if (! fd->emitted_number)
20286 if (last_emitted_file)
20287 fd->emitted_number = last_emitted_file->emitted_number + 1;
20289 fd->emitted_number = 1;
20290 last_emitted_file = fd;
20292 if (DWARF2_ASM_LINE_DEBUG_INFO)
20294 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
20295 output_quoted_string (asm_out_file,
20296 remap_debug_filename (fd->filename));
20297 fputc ('\n', asm_out_file);
20301 return fd->emitted_number;
20304 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20305 That generation should happen after function debug info has been
20306 generated. The value of the attribute is the constant value of ARG. */
20309 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
20311 die_arg_entry entry;
20316 if (!tmpl_value_parm_die_table)
20317 tmpl_value_parm_die_table
20318 = VEC_alloc (die_arg_entry, gc, 32);
20322 VEC_safe_push (die_arg_entry, gc,
20323 tmpl_value_parm_die_table,
20327 /* Return TRUE if T is an instance of generic type, FALSE
20331 generic_type_p (tree t)
20333 if (t == NULL_TREE || !TYPE_P (t))
20335 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
20338 /* Schedule the generation of the generic parameter dies for the
20339 instance of generic type T. The proper generation itself is later
20340 done by gen_scheduled_generic_parms_dies. */
20343 schedule_generic_params_dies_gen (tree t)
20345 if (!generic_type_p (t))
20348 if (generic_type_instances == NULL)
20349 generic_type_instances = VEC_alloc (tree, gc, 256);
20351 VEC_safe_push (tree, gc, generic_type_instances, t);
20354 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20355 by append_entry_to_tmpl_value_parm_die_table. This function must
20356 be called after function DIEs have been generated. */
20359 gen_remaining_tmpl_value_param_die_attribute (void)
20361 if (tmpl_value_parm_die_table)
20366 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
20367 tree_add_const_value_attribute (e->die, e->arg);
20371 /* Generate generic parameters DIEs for instances of generic types
20372 that have been previously scheduled by
20373 schedule_generic_params_dies_gen. This function must be called
20374 after all the types of the CU have been laid out. */
20377 gen_scheduled_generic_parms_dies (void)
20382 if (generic_type_instances == NULL)
20385 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
20386 gen_generic_params_dies (t);
20390 /* Replace DW_AT_name for the decl with name. */
20393 dwarf2out_set_name (tree decl, tree name)
20399 die = TYPE_SYMTAB_DIE (decl);
20403 dname = dwarf2_name (name, 0);
20407 attr = get_AT (die, DW_AT_name);
20410 struct indirect_string_node *node;
20412 node = find_AT_string (dname);
20413 /* replace the string. */
20414 attr->dw_attr_val.v.val_str = node;
20418 add_name_attribute (die, dname);
20421 /* Called by the final INSN scan whenever we see a var location. We
20422 use it to drop labels in the right places, and throw the location in
20423 our lookup table. */
20426 dwarf2out_var_location (rtx loc_note)
20428 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
20429 struct var_loc_node *newloc;
20431 static const char *last_label;
20432 static const char *last_postcall_label;
20433 static bool last_in_cold_section_p;
20437 if (!NOTE_P (loc_note))
20439 if (CALL_P (loc_note))
20442 if (SIBLING_CALL_P (loc_note))
20443 tail_call_site_count++;
20448 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
20449 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
20452 next_real = next_real_insn (loc_note);
20454 /* If there are no instructions which would be affected by this note,
20455 don't do anything. */
20457 && next_real == NULL_RTX
20458 && !NOTE_DURING_CALL_P (loc_note))
20461 if (next_real == NULL_RTX)
20462 next_real = get_last_insn ();
20464 /* If there were any real insns between note we processed last time
20465 and this note (or if it is the first note), clear
20466 last_{,postcall_}label so that they are not reused this time. */
20467 if (last_var_location_insn == NULL_RTX
20468 || last_var_location_insn != next_real
20469 || last_in_cold_section_p != in_cold_section_p)
20472 last_postcall_label = NULL;
20477 decl = NOTE_VAR_LOCATION_DECL (loc_note);
20478 newloc = add_var_loc_to_decl (decl, loc_note,
20479 NOTE_DURING_CALL_P (loc_note)
20480 ? last_postcall_label : last_label);
20481 if (newloc == NULL)
20490 /* If there were no real insns between note we processed last time
20491 and this note, use the label we emitted last time. Otherwise
20492 create a new label and emit it. */
20493 if (last_label == NULL)
20495 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
20496 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
20498 last_label = ggc_strdup (loclabel);
20503 struct call_arg_loc_node *ca_loc
20504 = ggc_alloc_cleared_call_arg_loc_node ();
20505 rtx prev = prev_real_insn (loc_note), x;
20506 ca_loc->call_arg_loc_note = loc_note;
20507 ca_loc->next = NULL;
20508 ca_loc->label = last_label;
20511 || (NONJUMP_INSN_P (prev)
20512 && GET_CODE (PATTERN (prev)) == SEQUENCE
20513 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
20514 if (!CALL_P (prev))
20515 prev = XVECEXP (PATTERN (prev), 0, 0);
20516 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
20517 x = PATTERN (prev);
20518 if (GET_CODE (x) == PARALLEL)
20519 x = XVECEXP (x, 0, 0);
20520 if (GET_CODE (x) == SET)
20522 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
20524 x = XEXP (XEXP (x, 0), 0);
20525 if (GET_CODE (x) == SYMBOL_REF
20526 && SYMBOL_REF_DECL (x)
20527 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
20528 ca_loc->symbol_ref = x;
20530 ca_loc->block = insn_scope (prev);
20531 if (call_arg_locations)
20532 call_arg_loc_last->next = ca_loc;
20534 call_arg_locations = ca_loc;
20535 call_arg_loc_last = ca_loc;
20537 else if (!NOTE_DURING_CALL_P (loc_note))
20538 newloc->label = last_label;
20541 if (!last_postcall_label)
20543 sprintf (loclabel, "%s-1", last_label);
20544 last_postcall_label = ggc_strdup (loclabel);
20546 newloc->label = last_postcall_label;
20549 last_var_location_insn = next_real;
20550 last_in_cold_section_p = in_cold_section_p;
20553 /* Note in one location list that text section has changed. */
20556 var_location_switch_text_section_1 (void **slot, void *data ATTRIBUTE_UNUSED)
20558 var_loc_list *list = (var_loc_list *) *slot;
20560 list->last_before_switch
20561 = list->last->next ? list->last->next : list->last;
20565 /* Note in all location lists that text section has changed. */
20568 var_location_switch_text_section (void)
20570 if (decl_loc_table == NULL)
20573 htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
20576 /* Create a new line number table. */
20578 static dw_line_info_table *
20579 new_line_info_table (void)
20581 dw_line_info_table *table;
20583 table = ggc_alloc_cleared_dw_line_info_table_struct ();
20584 table->file_num = 1;
20585 table->line_num = 1;
20586 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
20591 /* Lookup the "current" table into which we emit line info, so
20592 that we don't have to do it for every source line. */
20595 set_cur_line_info_table (section *sec)
20597 dw_line_info_table *table;
20599 if (sec == text_section)
20600 table = text_section_line_info;
20601 else if (sec == cold_text_section)
20603 table = cold_text_section_line_info;
20606 cold_text_section_line_info = table = new_line_info_table ();
20607 table->end_label = cold_end_label;
20612 const char *end_label;
20614 if (flag_reorder_blocks_and_partition)
20616 if (in_cold_section_p)
20617 end_label = crtl->subsections.cold_section_end_label;
20619 end_label = crtl->subsections.hot_section_end_label;
20623 char label[MAX_ARTIFICIAL_LABEL_BYTES];
20624 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
20625 current_function_funcdef_no);
20626 end_label = ggc_strdup (label);
20629 table = new_line_info_table ();
20630 table->end_label = end_label;
20632 VEC_safe_push (dw_line_info_table_p, gc, separate_line_info, table);
20635 cur_line_info_table = table;
20639 /* We need to reset the locations at the beginning of each
20640 function. We can't do this in the end_function hook, because the
20641 declarations that use the locations won't have been output when
20642 that hook is called. Also compute have_multiple_function_sections here. */
20645 dwarf2out_begin_function (tree fun)
20647 section *sec = function_section (fun);
20649 if (sec != text_section)
20650 have_multiple_function_sections = true;
20652 if (flag_reorder_blocks_and_partition && !cold_text_section)
20654 gcc_assert (current_function_decl == fun);
20655 cold_text_section = unlikely_text_section ();
20656 switch_to_section (cold_text_section);
20657 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
20658 switch_to_section (sec);
20661 dwarf2out_note_section_used ();
20662 call_site_count = 0;
20663 tail_call_site_count = 0;
20665 set_cur_line_info_table (sec);
20668 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20671 push_dw_line_info_entry (dw_line_info_table *table,
20672 enum dw_line_info_opcode opcode, unsigned int val)
20674 dw_line_info_entry e;
20677 VEC_safe_push (dw_line_info_entry, gc, table->entries, &e);
20680 /* Output a label to mark the beginning of a source code line entry
20681 and record information relating to this source line, in
20682 'line_info_table' for later output of the .debug_line section. */
20683 /* ??? The discriminator parameter ought to be unsigned. */
20686 dwarf2out_source_line (unsigned int line, const char *filename,
20687 int discriminator, bool is_stmt)
20689 unsigned int file_num;
20690 dw_line_info_table *table;
20692 if (debug_info_level < DINFO_LEVEL_NORMAL || line == 0)
20695 /* The discriminator column was added in dwarf4. Simplify the below
20696 by simply removing it if we're not supposed to output it. */
20697 if (dwarf_version < 4 && dwarf_strict)
20700 table = cur_line_info_table;
20701 file_num = maybe_emit_file (lookup_filename (filename));
20703 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20704 the debugger has used the second (possibly duplicate) line number
20705 at the beginning of the function to mark the end of the prologue.
20706 We could eliminate any other duplicates within the function. For
20707 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20708 that second line number entry. */
20709 /* Recall that this end-of-prologue indication is *not* the same thing
20710 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20711 to which the hook corresponds, follows the last insn that was
20712 emitted by gen_prologue. What we need is to preceed the first insn
20713 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20714 insn that corresponds to something the user wrote. These may be
20715 very different locations once scheduling is enabled. */
20717 if (0 && file_num == table->file_num
20718 && line == table->line_num
20719 && discriminator == table->discrim_num
20720 && is_stmt == table->is_stmt)
20723 switch_to_section (current_function_section ());
20725 /* If requested, emit something human-readable. */
20726 if (flag_debug_asm)
20727 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
20729 if (DWARF2_ASM_LINE_DEBUG_INFO)
20731 /* Emit the .loc directive understood by GNU as. */
20732 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
20733 if (is_stmt != table->is_stmt)
20734 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
20735 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
20736 fprintf (asm_out_file, " discriminator %d", discriminator);
20737 fputc ('\n', asm_out_file);
20741 unsigned int label_num = ++line_info_label_num;
20743 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
20745 push_dw_line_info_entry (table, LI_set_address, label_num);
20746 if (file_num != table->file_num)
20747 push_dw_line_info_entry (table, LI_set_file, file_num);
20748 if (discriminator != table->discrim_num)
20749 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
20750 if (is_stmt != table->is_stmt)
20751 push_dw_line_info_entry (table, LI_negate_stmt, 0);
20752 push_dw_line_info_entry (table, LI_set_line, line);
20755 table->file_num = file_num;
20756 table->line_num = line;
20757 table->discrim_num = discriminator;
20758 table->is_stmt = is_stmt;
20759 table->in_use = true;
20762 /* Record the beginning of a new source file. */
20765 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
20767 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
20769 /* Record the beginning of the file for break_out_includes. */
20770 dw_die_ref bincl_die;
20772 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
20773 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
20776 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20779 e.code = DW_MACINFO_start_file;
20781 e.info = xstrdup (filename);
20782 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20786 /* Record the end of a source file. */
20789 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
20791 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
20792 /* Record the end of the file for break_out_includes. */
20793 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
20795 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20798 e.code = DW_MACINFO_end_file;
20801 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20805 /* Called from debug_define in toplev.c. The `buffer' parameter contains
20806 the tail part of the directive line, i.e. the part which is past the
20807 initial whitespace, #, whitespace, directive-name, whitespace part. */
20810 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
20811 const char *buffer ATTRIBUTE_UNUSED)
20813 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20816 e.code = DW_MACINFO_define;
20818 e.info = xstrdup (buffer);;
20819 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20823 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
20824 the tail part of the directive line, i.e. the part which is past the
20825 initial whitespace, #, whitespace, directive-name, whitespace part. */
20828 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
20829 const char *buffer ATTRIBUTE_UNUSED)
20831 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20834 e.code = DW_MACINFO_undef;
20836 e.info = xstrdup (buffer);;
20837 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20842 output_macinfo (void)
20845 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
20846 macinfo_entry *ref;
20851 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
20855 case DW_MACINFO_start_file:
20857 int file_num = maybe_emit_file (lookup_filename (ref->info));
20858 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
20859 dw2_asm_output_data_uleb128
20860 (ref->lineno, "Included from line number %lu",
20861 (unsigned long)ref->lineno);
20862 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
20865 case DW_MACINFO_end_file:
20866 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
20868 case DW_MACINFO_define:
20869 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
20870 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
20871 (unsigned long)ref->lineno);
20872 dw2_asm_output_nstring (ref->info, -1, "The macro");
20874 case DW_MACINFO_undef:
20875 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
20876 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
20877 (unsigned long)ref->lineno);
20878 dw2_asm_output_nstring (ref->info, -1, "The macro");
20881 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
20882 ASM_COMMENT_START, (unsigned long)ref->code);
20888 /* Set up for Dwarf output at the start of compilation. */
20891 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
20893 /* Allocate the file_table. */
20894 file_table = htab_create_ggc (50, file_table_hash,
20895 file_table_eq, NULL);
20897 /* Allocate the decl_die_table. */
20898 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
20899 decl_die_table_eq, NULL);
20901 /* Allocate the decl_loc_table. */
20902 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
20903 decl_loc_table_eq, NULL);
20905 /* Allocate the cached_dw_loc_list_table. */
20906 cached_dw_loc_list_table
20907 = htab_create_ggc (10, cached_dw_loc_list_table_hash,
20908 cached_dw_loc_list_table_eq, NULL);
20910 /* Allocate the initial hunk of the decl_scope_table. */
20911 decl_scope_table = VEC_alloc (tree, gc, 256);
20913 /* Allocate the initial hunk of the abbrev_die_table. */
20914 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
20915 (ABBREV_DIE_TABLE_INCREMENT);
20916 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
20917 /* Zero-th entry is allocated, but unused. */
20918 abbrev_die_table_in_use = 1;
20920 /* Allocate the pubtypes and pubnames vectors. */
20921 pubname_table = VEC_alloc (pubname_entry, gc, 32);
20922 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
20924 incomplete_types = VEC_alloc (tree, gc, 64);
20926 used_rtx_array = VEC_alloc (rtx, gc, 32);
20928 debug_info_section = get_section (DEBUG_INFO_SECTION,
20929 SECTION_DEBUG, NULL);
20930 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
20931 SECTION_DEBUG, NULL);
20932 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
20933 SECTION_DEBUG, NULL);
20934 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
20935 SECTION_DEBUG, NULL);
20936 debug_line_section = get_section (DEBUG_LINE_SECTION,
20937 SECTION_DEBUG, NULL);
20938 debug_loc_section = get_section (DEBUG_LOC_SECTION,
20939 SECTION_DEBUG, NULL);
20940 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
20941 SECTION_DEBUG, NULL);
20942 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
20943 SECTION_DEBUG, NULL);
20944 debug_str_section = get_section (DEBUG_STR_SECTION,
20945 DEBUG_STR_SECTION_FLAGS, NULL);
20946 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
20947 SECTION_DEBUG, NULL);
20948 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
20949 SECTION_DEBUG, NULL);
20951 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
20952 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
20953 DEBUG_ABBREV_SECTION_LABEL, 0);
20954 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
20955 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
20956 COLD_TEXT_SECTION_LABEL, 0);
20957 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
20959 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
20960 DEBUG_INFO_SECTION_LABEL, 0);
20961 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
20962 DEBUG_LINE_SECTION_LABEL, 0);
20963 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
20964 DEBUG_RANGES_SECTION_LABEL, 0);
20965 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
20966 DEBUG_MACINFO_SECTION_LABEL, 0);
20968 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20969 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
20971 switch_to_section (text_section);
20972 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
20974 /* Make sure the line number table for .text always exists. */
20975 text_section_line_info = new_line_info_table ();
20976 text_section_line_info->end_label = text_end_label;
20979 /* Called before cgraph_optimize starts outputtting functions, variables
20980 and toplevel asms into assembly. */
20983 dwarf2out_assembly_start (void)
20985 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
20986 && dwarf2out_do_cfi_asm ()
20987 && (!(flag_unwind_tables || flag_exceptions)
20988 || targetm_common.except_unwind_info (&global_options) != UI_DWARF2))
20989 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
20992 /* A helper function for dwarf2out_finish called through
20993 htab_traverse. Emit one queued .debug_str string. */
20996 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
20998 struct indirect_string_node *node = (struct indirect_string_node *) *h;
21000 if (node->form == DW_FORM_strp)
21002 switch_to_section (debug_str_section);
21003 ASM_OUTPUT_LABEL (asm_out_file, node->label);
21004 assemble_string (node->str, strlen (node->str) + 1);
21010 #if ENABLE_ASSERT_CHECKING
21011 /* Verify that all marks are clear. */
21014 verify_marks_clear (dw_die_ref die)
21018 gcc_assert (! die->die_mark);
21019 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
21021 #endif /* ENABLE_ASSERT_CHECKING */
21023 /* Clear the marks for a die and its children.
21024 Be cool if the mark isn't set. */
21027 prune_unmark_dies (dw_die_ref die)
21033 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
21036 /* Given DIE that we're marking as used, find any other dies
21037 it references as attributes and mark them as used. */
21040 prune_unused_types_walk_attribs (dw_die_ref die)
21045 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21047 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
21049 /* A reference to another DIE.
21050 Make sure that it will get emitted.
21051 If it was broken out into a comdat group, don't follow it. */
21052 if (! use_debug_types
21053 || a->dw_attr == DW_AT_specification
21054 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
21055 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
21057 /* Set the string's refcount to 0 so that prune_unused_types_mark
21058 accounts properly for it. */
21059 if (AT_class (a) == dw_val_class_str)
21060 a->dw_attr_val.v.val_str->refcount = 0;
21064 /* Mark the generic parameters and arguments children DIEs of DIE. */
21067 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
21071 if (die == NULL || die->die_child == NULL)
21073 c = die->die_child;
21076 switch (c->die_tag)
21078 case DW_TAG_template_type_param:
21079 case DW_TAG_template_value_param:
21080 case DW_TAG_GNU_template_template_param:
21081 case DW_TAG_GNU_template_parameter_pack:
21082 prune_unused_types_mark (c, 1);
21088 } while (c && c != die->die_child);
21091 /* Mark DIE as being used. If DOKIDS is true, then walk down
21092 to DIE's children. */
21095 prune_unused_types_mark (dw_die_ref die, int dokids)
21099 if (die->die_mark == 0)
21101 /* We haven't done this node yet. Mark it as used. */
21103 /* If this is the DIE of a generic type instantiation,
21104 mark the children DIEs that describe its generic parms and
21106 prune_unused_types_mark_generic_parms_dies (die);
21108 /* We also have to mark its parents as used.
21109 (But we don't want to mark our parents' kids due to this.) */
21110 if (die->die_parent)
21111 prune_unused_types_mark (die->die_parent, 0);
21113 /* Mark any referenced nodes. */
21114 prune_unused_types_walk_attribs (die);
21116 /* If this node is a specification,
21117 also mark the definition, if it exists. */
21118 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
21119 prune_unused_types_mark (die->die_definition, 1);
21122 if (dokids && die->die_mark != 2)
21124 /* We need to walk the children, but haven't done so yet.
21125 Remember that we've walked the kids. */
21128 /* If this is an array type, we need to make sure our
21129 kids get marked, even if they're types. If we're
21130 breaking out types into comdat sections, do this
21131 for all type definitions. */
21132 if (die->die_tag == DW_TAG_array_type
21133 || (use_debug_types
21134 && is_type_die (die) && ! is_declaration_die (die)))
21135 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
21137 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
21141 /* For local classes, look if any static member functions were emitted
21142 and if so, mark them. */
21145 prune_unused_types_walk_local_classes (dw_die_ref die)
21149 if (die->die_mark == 2)
21152 switch (die->die_tag)
21154 case DW_TAG_structure_type:
21155 case DW_TAG_union_type:
21156 case DW_TAG_class_type:
21159 case DW_TAG_subprogram:
21160 if (!get_AT_flag (die, DW_AT_declaration)
21161 || die->die_definition != NULL)
21162 prune_unused_types_mark (die, 1);
21169 /* Mark children. */
21170 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
21173 /* Walk the tree DIE and mark types that we actually use. */
21176 prune_unused_types_walk (dw_die_ref die)
21180 /* Don't do anything if this node is already marked and
21181 children have been marked as well. */
21182 if (die->die_mark == 2)
21185 switch (die->die_tag)
21187 case DW_TAG_structure_type:
21188 case DW_TAG_union_type:
21189 case DW_TAG_class_type:
21190 if (die->die_perennial_p)
21193 for (c = die->die_parent; c; c = c->die_parent)
21194 if (c->die_tag == DW_TAG_subprogram)
21197 /* Finding used static member functions inside of classes
21198 is needed just for local classes, because for other classes
21199 static member function DIEs with DW_AT_specification
21200 are emitted outside of the DW_TAG_*_type. If we ever change
21201 it, we'd need to call this even for non-local classes. */
21203 prune_unused_types_walk_local_classes (die);
21205 /* It's a type node --- don't mark it. */
21208 case DW_TAG_const_type:
21209 case DW_TAG_packed_type:
21210 case DW_TAG_pointer_type:
21211 case DW_TAG_reference_type:
21212 case DW_TAG_rvalue_reference_type:
21213 case DW_TAG_volatile_type:
21214 case DW_TAG_typedef:
21215 case DW_TAG_array_type:
21216 case DW_TAG_interface_type:
21217 case DW_TAG_friend:
21218 case DW_TAG_variant_part:
21219 case DW_TAG_enumeration_type:
21220 case DW_TAG_subroutine_type:
21221 case DW_TAG_string_type:
21222 case DW_TAG_set_type:
21223 case DW_TAG_subrange_type:
21224 case DW_TAG_ptr_to_member_type:
21225 case DW_TAG_file_type:
21226 if (die->die_perennial_p)
21229 /* It's a type node --- don't mark it. */
21233 /* Mark everything else. */
21237 if (die->die_mark == 0)
21241 /* Now, mark any dies referenced from here. */
21242 prune_unused_types_walk_attribs (die);
21247 /* Mark children. */
21248 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
21251 /* Increment the string counts on strings referred to from DIE's
21255 prune_unused_types_update_strings (dw_die_ref die)
21260 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21261 if (AT_class (a) == dw_val_class_str)
21263 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
21265 /* Avoid unnecessarily putting strings that are used less than
21266 twice in the hash table. */
21268 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
21271 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
21272 htab_hash_string (s->str),
21274 gcc_assert (*slot == NULL);
21280 /* Remove from the tree DIE any dies that aren't marked. */
21283 prune_unused_types_prune (dw_die_ref die)
21287 gcc_assert (die->die_mark);
21288 prune_unused_types_update_strings (die);
21290 if (! die->die_child)
21293 c = die->die_child;
21295 dw_die_ref prev = c;
21296 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
21297 if (c == die->die_child)
21299 /* No marked children between 'prev' and the end of the list. */
21301 /* No marked children at all. */
21302 die->die_child = NULL;
21305 prev->die_sib = c->die_sib;
21306 die->die_child = prev;
21311 if (c != prev->die_sib)
21313 prune_unused_types_prune (c);
21314 } while (c != die->die_child);
21317 /* Remove dies representing declarations that we never use. */
21320 prune_unused_types (void)
21323 limbo_die_node *node;
21324 comdat_type_node *ctnode;
21326 dw_die_ref base_type;
21328 #if ENABLE_ASSERT_CHECKING
21329 /* All the marks should already be clear. */
21330 verify_marks_clear (comp_unit_die ());
21331 for (node = limbo_die_list; node; node = node->next)
21332 verify_marks_clear (node->die);
21333 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21334 verify_marks_clear (ctnode->root_die);
21335 #endif /* ENABLE_ASSERT_CHECKING */
21337 /* Mark types that are used in global variables. */
21338 premark_types_used_by_global_vars ();
21340 /* Set the mark on nodes that are actually used. */
21341 prune_unused_types_walk (comp_unit_die ());
21342 for (node = limbo_die_list; node; node = node->next)
21343 prune_unused_types_walk (node->die);
21344 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21346 prune_unused_types_walk (ctnode->root_die);
21347 prune_unused_types_mark (ctnode->type_die, 1);
21350 /* Also set the mark on nodes referenced from the
21352 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
21353 prune_unused_types_mark (pub->die, 1);
21354 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
21355 prune_unused_types_mark (base_type, 1);
21357 if (debug_str_hash)
21358 htab_empty (debug_str_hash);
21359 prune_unused_types_prune (comp_unit_die ());
21360 for (node = limbo_die_list; node; node = node->next)
21361 prune_unused_types_prune (node->die);
21362 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21363 prune_unused_types_prune (ctnode->root_die);
21365 /* Leave the marks clear. */
21366 prune_unmark_dies (comp_unit_die ());
21367 for (node = limbo_die_list; node; node = node->next)
21368 prune_unmark_dies (node->die);
21369 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21370 prune_unmark_dies (ctnode->root_die);
21373 /* Set the parameter to true if there are any relative pathnames in
21376 file_table_relative_p (void ** slot, void *param)
21378 bool *p = (bool *) param;
21379 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
21380 if (!IS_ABSOLUTE_PATH (d->filename))
21388 /* Routines to manipulate hash table of comdat type units. */
21391 htab_ct_hash (const void *of)
21394 const comdat_type_node *const type_node = (const comdat_type_node *) of;
21396 memcpy (&h, type_node->signature, sizeof (h));
21401 htab_ct_eq (const void *of1, const void *of2)
21403 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
21404 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
21406 return (! memcmp (type_node_1->signature, type_node_2->signature,
21407 DWARF_TYPE_SIGNATURE_SIZE));
21410 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
21411 to the location it would have been added, should we know its
21412 DECL_ASSEMBLER_NAME when we added other attributes. This will
21413 probably improve compactness of debug info, removing equivalent
21414 abbrevs, and hide any differences caused by deferring the
21415 computation of the assembler name, triggered by e.g. PCH. */
21418 move_linkage_attr (dw_die_ref die)
21420 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
21421 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
21423 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
21424 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
21428 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
21430 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
21434 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
21436 VEC_pop (dw_attr_node, die->die_attr);
21437 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
21441 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
21442 referenced from typed stack ops and count how often they are used. */
21445 mark_base_types (dw_loc_descr_ref loc)
21447 dw_die_ref base_type = NULL;
21449 for (; loc; loc = loc->dw_loc_next)
21451 switch (loc->dw_loc_opc)
21453 case DW_OP_GNU_regval_type:
21454 case DW_OP_GNU_deref_type:
21455 base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
21457 case DW_OP_GNU_convert:
21458 case DW_OP_GNU_reinterpret:
21459 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
21462 case DW_OP_GNU_const_type:
21463 base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
21465 case DW_OP_GNU_entry_value:
21466 mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
21471 gcc_assert (base_type->die_parent == comp_unit_die ());
21472 if (base_type->die_mark)
21473 base_type->die_mark++;
21476 VEC_safe_push (dw_die_ref, heap, base_types, base_type);
21477 base_type->die_mark = 1;
21482 /* Comparison function for sorting marked base types. */
21485 base_type_cmp (const void *x, const void *y)
21487 dw_die_ref dx = *(const dw_die_ref *) x;
21488 dw_die_ref dy = *(const dw_die_ref *) y;
21489 unsigned int byte_size1, byte_size2;
21490 unsigned int encoding1, encoding2;
21491 if (dx->die_mark > dy->die_mark)
21493 if (dx->die_mark < dy->die_mark)
21495 byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
21496 byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
21497 if (byte_size1 < byte_size2)
21499 if (byte_size1 > byte_size2)
21501 encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
21502 encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
21503 if (encoding1 < encoding2)
21505 if (encoding1 > encoding2)
21510 /* Move base types marked by mark_base_types as early as possible
21511 in the CU, sorted by decreasing usage count both to make the
21512 uleb128 references as small as possible and to make sure they
21513 will have die_offset already computed by calc_die_sizes when
21514 sizes of typed stack loc ops is computed. */
21517 move_marked_base_types (void)
21520 dw_die_ref base_type, die, c;
21522 if (VEC_empty (dw_die_ref, base_types))
21525 /* Sort by decreasing usage count, they will be added again in that
21527 VEC_qsort (dw_die_ref, base_types, base_type_cmp);
21528 die = comp_unit_die ();
21529 c = die->die_child;
21532 dw_die_ref prev = c;
21534 while (c->die_mark)
21536 remove_child_with_prev (c, prev);
21537 /* As base types got marked, there must be at least
21538 one node other than DW_TAG_base_type. */
21539 gcc_assert (c != c->die_sib);
21543 while (c != die->die_child);
21544 gcc_assert (die->die_child);
21545 c = die->die_child;
21546 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
21548 base_type->die_mark = 0;
21549 base_type->die_sib = c->die_sib;
21550 c->die_sib = base_type;
21555 /* Helper function for resolve_addr, attempt to resolve
21556 one CONST_STRING, return non-zero if not successful. Similarly verify that
21557 SYMBOL_REFs refer to variables emitted in the current CU. */
21560 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
21564 if (GET_CODE (rtl) == CONST_STRING)
21566 size_t len = strlen (XSTR (rtl, 0)) + 1;
21567 tree t = build_string (len, XSTR (rtl, 0));
21568 tree tlen = size_int (len - 1);
21570 = build_array_type (char_type_node, build_index_type (tlen));
21571 rtl = lookup_constant_def (t);
21572 if (!rtl || !MEM_P (rtl))
21574 rtl = XEXP (rtl, 0);
21575 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
21580 if (GET_CODE (rtl) == SYMBOL_REF
21581 && SYMBOL_REF_DECL (rtl))
21583 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
21585 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
21588 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
21592 if (GET_CODE (rtl) == CONST
21593 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
21599 /* Helper function for resolve_addr, handle one location
21600 expression, return false if at least one CONST_STRING or SYMBOL_REF in
21601 the location list couldn't be resolved. */
21604 resolve_addr_in_expr (dw_loc_descr_ref loc)
21606 dw_loc_descr_ref keep = NULL;
21607 for (; loc; loc = loc->dw_loc_next)
21608 switch (loc->dw_loc_opc)
21611 if (resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
21614 case DW_OP_const4u:
21615 case DW_OP_const8u:
21617 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
21620 case DW_OP_implicit_value:
21621 if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
21622 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL))
21625 case DW_OP_GNU_implicit_pointer:
21626 case DW_OP_GNU_parameter_ref:
21627 if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
21630 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
21633 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
21634 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
21635 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
21638 case DW_OP_GNU_const_type:
21639 case DW_OP_GNU_regval_type:
21640 case DW_OP_GNU_deref_type:
21641 case DW_OP_GNU_convert:
21642 case DW_OP_GNU_reinterpret:
21643 while (loc->dw_loc_next
21644 && loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert)
21646 dw_die_ref base1, base2;
21647 unsigned enc1, enc2, size1, size2;
21648 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
21649 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
21650 base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
21651 else if (loc->dw_loc_oprnd1.val_class
21652 == dw_val_class_unsigned_const)
21655 base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
21656 if (loc->dw_loc_next->dw_loc_oprnd1.val_class
21657 == dw_val_class_unsigned_const)
21659 base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
21660 gcc_assert (base1->die_tag == DW_TAG_base_type
21661 && base2->die_tag == DW_TAG_base_type);
21662 enc1 = get_AT_unsigned (base1, DW_AT_encoding);
21663 enc2 = get_AT_unsigned (base2, DW_AT_encoding);
21664 size1 = get_AT_unsigned (base1, DW_AT_byte_size);
21665 size2 = get_AT_unsigned (base2, DW_AT_byte_size);
21667 && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
21668 && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
21672 /* Optimize away next DW_OP_GNU_convert after
21673 adjusting LOC's base type die reference. */
21674 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
21675 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
21676 loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
21678 loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
21679 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
21682 /* Don't change integer DW_OP_GNU_convert after e.g. floating
21683 point typed stack entry. */
21684 else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
21685 keep = loc->dw_loc_next;
21695 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
21696 an address in .rodata section if the string literal is emitted there,
21697 or remove the containing location list or replace DW_AT_const_value
21698 with DW_AT_location and empty location expression, if it isn't found
21699 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
21700 to something that has been emitted in the current CU. */
21703 resolve_addr (dw_die_ref die)
21707 dw_loc_list_ref *curr, *start, loc;
21710 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21711 switch (AT_class (a))
21713 case dw_val_class_loc_list:
21714 start = curr = AT_loc_list_ptr (a);
21717 /* The same list can be referenced more than once. See if we have
21718 already recorded the result from a previous pass. */
21720 *curr = loc->dw_loc_next;
21721 else if (!loc->resolved_addr)
21723 /* As things stand, we do not expect or allow one die to
21724 reference a suffix of another die's location list chain.
21725 References must be identical or completely separate.
21726 There is therefore no need to cache the result of this
21727 pass on any list other than the first; doing so
21728 would lead to unnecessary writes. */
21731 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
21732 if (!resolve_addr_in_expr ((*curr)->expr))
21734 dw_loc_list_ref next = (*curr)->dw_loc_next;
21735 if (next && (*curr)->ll_symbol)
21737 gcc_assert (!next->ll_symbol);
21738 next->ll_symbol = (*curr)->ll_symbol;
21744 mark_base_types ((*curr)->expr);
21745 curr = &(*curr)->dw_loc_next;
21749 loc->resolved_addr = 1;
21753 loc->dw_loc_next = *start;
21758 remove_AT (die, a->dw_attr);
21762 case dw_val_class_loc:
21763 if (!resolve_addr_in_expr (AT_loc (a)))
21765 remove_AT (die, a->dw_attr);
21769 mark_base_types (AT_loc (a));
21771 case dw_val_class_addr:
21772 if (a->dw_attr == DW_AT_const_value
21773 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
21775 remove_AT (die, a->dw_attr);
21778 if (die->die_tag == DW_TAG_GNU_call_site
21779 && a->dw_attr == DW_AT_abstract_origin)
21781 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
21782 dw_die_ref tdie = lookup_decl_die (tdecl);
21784 && DECL_EXTERNAL (tdecl)
21785 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE)
21787 force_decl_die (tdecl);
21788 tdie = lookup_decl_die (tdecl);
21792 a->dw_attr_val.val_class = dw_val_class_die_ref;
21793 a->dw_attr_val.v.val_die_ref.die = tdie;
21794 a->dw_attr_val.v.val_die_ref.external = 0;
21798 remove_AT (die, a->dw_attr);
21807 FOR_EACH_CHILD (die, c, resolve_addr (c));
21810 /* Helper routines for optimize_location_lists.
21811 This pass tries to share identical local lists in .debug_loc
21814 /* Iteratively hash operands of LOC opcode. */
21816 static inline hashval_t
21817 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
21819 dw_val_ref val1 = &loc->dw_loc_oprnd1;
21820 dw_val_ref val2 = &loc->dw_loc_oprnd2;
21822 switch (loc->dw_loc_opc)
21824 case DW_OP_const4u:
21825 case DW_OP_const8u:
21829 case DW_OP_const1u:
21830 case DW_OP_const1s:
21831 case DW_OP_const2u:
21832 case DW_OP_const2s:
21833 case DW_OP_const4s:
21834 case DW_OP_const8s:
21838 case DW_OP_plus_uconst:
21874 case DW_OP_deref_size:
21875 case DW_OP_xderef_size:
21876 hash = iterative_hash_object (val1->v.val_int, hash);
21883 gcc_assert (val1->val_class == dw_val_class_loc);
21884 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
21885 hash = iterative_hash_object (offset, hash);
21888 case DW_OP_implicit_value:
21889 hash = iterative_hash_object (val1->v.val_unsigned, hash);
21890 switch (val2->val_class)
21892 case dw_val_class_const:
21893 hash = iterative_hash_object (val2->v.val_int, hash);
21895 case dw_val_class_vec:
21897 unsigned int elt_size = val2->v.val_vec.elt_size;
21898 unsigned int len = val2->v.val_vec.length;
21900 hash = iterative_hash_object (elt_size, hash);
21901 hash = iterative_hash_object (len, hash);
21902 hash = iterative_hash (val2->v.val_vec.array,
21903 len * elt_size, hash);
21906 case dw_val_class_const_double:
21907 hash = iterative_hash_object (val2->v.val_double.low, hash);
21908 hash = iterative_hash_object (val2->v.val_double.high, hash);
21910 case dw_val_class_addr:
21911 hash = iterative_hash_rtx (val2->v.val_addr, hash);
21914 gcc_unreachable ();
21918 case DW_OP_bit_piece:
21919 hash = iterative_hash_object (val1->v.val_int, hash);
21920 hash = iterative_hash_object (val2->v.val_int, hash);
21926 unsigned char dtprel = 0xd1;
21927 hash = iterative_hash_object (dtprel, hash);
21929 hash = iterative_hash_rtx (val1->v.val_addr, hash);
21931 case DW_OP_GNU_implicit_pointer:
21932 hash = iterative_hash_object (val2->v.val_int, hash);
21934 case DW_OP_GNU_entry_value:
21935 hash = hash_loc_operands (val1->v.val_loc, hash);
21937 case DW_OP_GNU_regval_type:
21938 case DW_OP_GNU_deref_type:
21940 unsigned int byte_size
21941 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
21942 unsigned int encoding
21943 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
21944 hash = iterative_hash_object (val1->v.val_int, hash);
21945 hash = iterative_hash_object (byte_size, hash);
21946 hash = iterative_hash_object (encoding, hash);
21949 case DW_OP_GNU_convert:
21950 case DW_OP_GNU_reinterpret:
21951 if (val1->val_class == dw_val_class_unsigned_const)
21953 hash = iterative_hash_object (val1->v.val_unsigned, hash);
21957 case DW_OP_GNU_const_type:
21959 unsigned int byte_size
21960 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
21961 unsigned int encoding
21962 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
21963 hash = iterative_hash_object (byte_size, hash);
21964 hash = iterative_hash_object (encoding, hash);
21965 if (loc->dw_loc_opc != DW_OP_GNU_const_type)
21967 hash = iterative_hash_object (val2->val_class, hash);
21968 switch (val2->val_class)
21970 case dw_val_class_const:
21971 hash = iterative_hash_object (val2->v.val_int, hash);
21973 case dw_val_class_vec:
21975 unsigned int elt_size = val2->v.val_vec.elt_size;
21976 unsigned int len = val2->v.val_vec.length;
21978 hash = iterative_hash_object (elt_size, hash);
21979 hash = iterative_hash_object (len, hash);
21980 hash = iterative_hash (val2->v.val_vec.array,
21981 len * elt_size, hash);
21984 case dw_val_class_const_double:
21985 hash = iterative_hash_object (val2->v.val_double.low, hash);
21986 hash = iterative_hash_object (val2->v.val_double.high, hash);
21989 gcc_unreachable ();
21995 /* Other codes have no operands. */
22001 /* Iteratively hash the whole DWARF location expression LOC. */
22003 static inline hashval_t
22004 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
22006 dw_loc_descr_ref l;
22007 bool sizes_computed = false;
22008 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
22009 size_of_locs (loc);
22011 for (l = loc; l != NULL; l = l->dw_loc_next)
22013 enum dwarf_location_atom opc = l->dw_loc_opc;
22014 hash = iterative_hash_object (opc, hash);
22015 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
22017 size_of_locs (loc);
22018 sizes_computed = true;
22020 hash = hash_loc_operands (l, hash);
22025 /* Compute hash of the whole location list LIST_HEAD. */
22028 hash_loc_list (dw_loc_list_ref list_head)
22030 dw_loc_list_ref curr = list_head;
22031 hashval_t hash = 0;
22033 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
22035 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
22036 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
22038 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
22040 hash = hash_locs (curr->expr, hash);
22042 list_head->hash = hash;
22045 /* Return true if X and Y opcodes have the same operands. */
22048 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
22050 dw_val_ref valx1 = &x->dw_loc_oprnd1;
22051 dw_val_ref valx2 = &x->dw_loc_oprnd2;
22052 dw_val_ref valy1 = &y->dw_loc_oprnd1;
22053 dw_val_ref valy2 = &y->dw_loc_oprnd2;
22055 switch (x->dw_loc_opc)
22057 case DW_OP_const4u:
22058 case DW_OP_const8u:
22062 case DW_OP_const1u:
22063 case DW_OP_const1s:
22064 case DW_OP_const2u:
22065 case DW_OP_const2s:
22066 case DW_OP_const4s:
22067 case DW_OP_const8s:
22071 case DW_OP_plus_uconst:
22107 case DW_OP_deref_size:
22108 case DW_OP_xderef_size:
22109 return valx1->v.val_int == valy1->v.val_int;
22112 gcc_assert (valx1->val_class == dw_val_class_loc
22113 && valy1->val_class == dw_val_class_loc
22114 && x->dw_loc_addr == y->dw_loc_addr);
22115 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
22116 case DW_OP_implicit_value:
22117 if (valx1->v.val_unsigned != valy1->v.val_unsigned
22118 || valx2->val_class != valy2->val_class)
22120 switch (valx2->val_class)
22122 case dw_val_class_const:
22123 return valx2->v.val_int == valy2->v.val_int;
22124 case dw_val_class_vec:
22125 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
22126 && valx2->v.val_vec.length == valy2->v.val_vec.length
22127 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
22128 valx2->v.val_vec.elt_size
22129 * valx2->v.val_vec.length) == 0;
22130 case dw_val_class_const_double:
22131 return valx2->v.val_double.low == valy2->v.val_double.low
22132 && valx2->v.val_double.high == valy2->v.val_double.high;
22133 case dw_val_class_addr:
22134 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
22136 gcc_unreachable ();
22139 case DW_OP_bit_piece:
22140 return valx1->v.val_int == valy1->v.val_int
22141 && valx2->v.val_int == valy2->v.val_int;
22144 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
22145 case DW_OP_GNU_implicit_pointer:
22146 return valx1->val_class == dw_val_class_die_ref
22147 && valx1->val_class == valy1->val_class
22148 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
22149 && valx2->v.val_int == valy2->v.val_int;
22150 case DW_OP_GNU_entry_value:
22151 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
22152 case DW_OP_GNU_const_type:
22153 if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
22154 || valx2->val_class != valy2->val_class)
22156 switch (valx2->val_class)
22158 case dw_val_class_const:
22159 return valx2->v.val_int == valy2->v.val_int;
22160 case dw_val_class_vec:
22161 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
22162 && valx2->v.val_vec.length == valy2->v.val_vec.length
22163 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
22164 valx2->v.val_vec.elt_size
22165 * valx2->v.val_vec.length) == 0;
22166 case dw_val_class_const_double:
22167 return valx2->v.val_double.low == valy2->v.val_double.low
22168 && valx2->v.val_double.high == valy2->v.val_double.high;
22170 gcc_unreachable ();
22172 case DW_OP_GNU_regval_type:
22173 case DW_OP_GNU_deref_type:
22174 return valx1->v.val_int == valy1->v.val_int
22175 && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
22176 case DW_OP_GNU_convert:
22177 case DW_OP_GNU_reinterpret:
22178 if (valx1->val_class != valy1->val_class)
22180 if (valx1->val_class == dw_val_class_unsigned_const)
22181 return valx1->v.val_unsigned == valy1->v.val_unsigned;
22182 return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
22183 case DW_OP_GNU_parameter_ref:
22184 return valx1->val_class == dw_val_class_die_ref
22185 && valx1->val_class == valy1->val_class
22186 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
22188 /* Other codes have no operands. */
22193 /* Return true if DWARF location expressions X and Y are the same. */
22196 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
22198 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
22199 if (x->dw_loc_opc != y->dw_loc_opc
22200 || x->dtprel != y->dtprel
22201 || !compare_loc_operands (x, y))
22203 return x == NULL && y == NULL;
22206 /* Return precomputed hash of location list X. */
22209 loc_list_hash (const void *x)
22211 return ((const struct dw_loc_list_struct *) x)->hash;
22214 /* Return 1 if location lists X and Y are the same. */
22217 loc_list_eq (const void *x, const void *y)
22219 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
22220 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
22223 if (a->hash != b->hash)
22225 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
22226 if (strcmp (a->begin, b->begin) != 0
22227 || strcmp (a->end, b->end) != 0
22228 || (a->section == NULL) != (b->section == NULL)
22229 || (a->section && strcmp (a->section, b->section) != 0)
22230 || !compare_locs (a->expr, b->expr))
22232 return a == NULL && b == NULL;
22235 /* Recursively optimize location lists referenced from DIE
22236 children and share them whenever possible. */
22239 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
22246 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22247 if (AT_class (a) == dw_val_class_loc_list)
22249 dw_loc_list_ref list = AT_loc_list (a);
22250 /* TODO: perform some optimizations here, before hashing
22251 it and storing into the hash table. */
22252 hash_loc_list (list);
22253 slot = htab_find_slot_with_hash (htab, list, list->hash,
22256 *slot = (void *) list;
22258 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
22261 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
22264 /* Optimize location lists referenced from DIE
22265 children and share them whenever possible. */
22268 optimize_location_lists (dw_die_ref die)
22270 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
22271 optimize_location_lists_1 (die, htab);
22272 htab_delete (htab);
22275 /* Output stuff that dwarf requires at the end of every file,
22276 and generate the DWARF-2 debugging info. */
22279 dwarf2out_finish (const char *filename)
22281 limbo_die_node *node, *next_node;
22282 comdat_type_node *ctnode;
22283 htab_t comdat_type_table;
22286 gen_scheduled_generic_parms_dies ();
22287 gen_remaining_tmpl_value_param_die_attribute ();
22289 /* Add the name for the main input file now. We delayed this from
22290 dwarf2out_init to avoid complications with PCH. */
22291 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
22292 if (!IS_ABSOLUTE_PATH (filename))
22293 add_comp_dir_attribute (comp_unit_die ());
22294 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
22297 htab_traverse (file_table, file_table_relative_p, &p);
22299 add_comp_dir_attribute (comp_unit_die ());
22302 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
22304 add_location_or_const_value_attribute (
22305 VEC_index (deferred_locations, deferred_locations_list, i)->die,
22306 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
22311 /* Traverse the limbo die list, and add parent/child links. The only
22312 dies without parents that should be here are concrete instances of
22313 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22314 For concrete instances, we can get the parent die from the abstract
22316 for (node = limbo_die_list; node; node = next_node)
22318 dw_die_ref die = node->die;
22319 next_node = node->next;
22321 if (die->die_parent == NULL)
22323 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
22325 if (origin && origin->die_parent)
22326 add_child_die (origin->die_parent, die);
22327 else if (is_cu_die (die))
22329 else if (seen_error ())
22330 /* It's OK to be confused by errors in the input. */
22331 add_child_die (comp_unit_die (), die);
22334 /* In certain situations, the lexical block containing a
22335 nested function can be optimized away, which results
22336 in the nested function die being orphaned. Likewise
22337 with the return type of that nested function. Force
22338 this to be a child of the containing function.
22340 It may happen that even the containing function got fully
22341 inlined and optimized out. In that case we are lost and
22342 assign the empty child. This should not be big issue as
22343 the function is likely unreachable too. */
22344 tree context = NULL_TREE;
22346 gcc_assert (node->created_for);
22348 if (DECL_P (node->created_for))
22349 context = DECL_CONTEXT (node->created_for);
22350 else if (TYPE_P (node->created_for))
22351 context = TYPE_CONTEXT (node->created_for);
22353 gcc_assert (context
22354 && (TREE_CODE (context) == FUNCTION_DECL
22355 || TREE_CODE (context) == NAMESPACE_DECL));
22357 origin = lookup_decl_die (context);
22359 add_child_die (origin, die);
22361 add_child_die (comp_unit_die (), die);
22366 limbo_die_list = NULL;
22368 #if ENABLE_ASSERT_CHECKING
22370 dw_die_ref die = comp_unit_die (), c;
22371 FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
22374 resolve_addr (comp_unit_die ());
22375 move_marked_base_types ();
22377 for (node = deferred_asm_name; node; node = node->next)
22379 tree decl = node->created_for;
22380 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
22382 add_linkage_attr (node->die, decl);
22383 move_linkage_attr (node->die);
22387 deferred_asm_name = NULL;
22389 /* Walk through the list of incomplete types again, trying once more to
22390 emit full debugging info for them. */
22391 retry_incomplete_types ();
22393 if (flag_eliminate_unused_debug_types)
22394 prune_unused_types ();
22396 /* Generate separate CUs for each of the include files we've seen.
22397 They will go into limbo_die_list. */
22398 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
22399 break_out_includes (comp_unit_die ());
22401 /* Generate separate COMDAT sections for type DIEs. */
22402 if (use_debug_types)
22404 break_out_comdat_types (comp_unit_die ());
22406 /* Each new type_unit DIE was added to the limbo die list when created.
22407 Since these have all been added to comdat_type_list, clear the
22409 limbo_die_list = NULL;
22411 /* For each new comdat type unit, copy declarations for incomplete
22412 types to make the new unit self-contained (i.e., no direct
22413 references to the main compile unit). */
22414 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22415 copy_decls_for_unworthy_types (ctnode->root_die);
22416 copy_decls_for_unworthy_types (comp_unit_die ());
22418 /* In the process of copying declarations from one unit to another,
22419 we may have left some declarations behind that are no longer
22420 referenced. Prune them. */
22421 prune_unused_types ();
22424 /* Traverse the DIE's and add add sibling attributes to those DIE's
22425 that have children. */
22426 add_sibling_attributes (comp_unit_die ());
22427 for (node = limbo_die_list; node; node = node->next)
22428 add_sibling_attributes (node->die);
22429 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22430 add_sibling_attributes (ctnode->root_die);
22432 /* Output a terminator label for the .text section. */
22433 switch_to_section (text_section);
22434 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
22435 if (cold_text_section)
22437 switch_to_section (cold_text_section);
22438 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
22441 /* We can only use the low/high_pc attributes if all of the code was
22443 if (!have_multiple_function_sections
22444 || (dwarf_version < 3 && dwarf_strict))
22446 /* Don't add if the CU has no associated code. */
22447 if (text_section_used)
22449 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
22450 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
22455 unsigned fde_idx = 0;
22456 bool range_list_added = false;
22458 if (text_section_used)
22459 add_ranges_by_labels (comp_unit_die (), text_section_label,
22460 text_end_label, &range_list_added);
22461 if (cold_text_section_used)
22462 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
22463 cold_end_label, &range_list_added);
22465 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
22467 dw_fde_ref fde = &fde_table[fde_idx];
22469 if (!fde->in_std_section)
22470 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
22471 fde->dw_fde_end, &range_list_added);
22472 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
22473 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_second_begin,
22474 fde->dw_fde_second_end, &range_list_added);
22477 if (range_list_added)
22479 /* We need to give .debug_loc and .debug_ranges an appropriate
22480 "base address". Use zero so that these addresses become
22481 absolute. Historically, we've emitted the unexpected
22482 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22483 Emit both to give time for other tools to adapt. */
22484 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
22485 if (! dwarf_strict && dwarf_version < 4)
22486 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
22492 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22493 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
22494 debug_line_section_label);
22496 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22497 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
22499 if (have_location_lists)
22500 optimize_location_lists (comp_unit_die ());
22502 /* Output all of the compilation units. We put the main one last so that
22503 the offsets are available to output_pubnames. */
22504 for (node = limbo_die_list; node; node = node->next)
22505 output_comp_unit (node->die, 0);
22507 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
22508 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22510 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
22512 /* Don't output duplicate types. */
22513 if (*slot != HTAB_EMPTY_ENTRY)
22516 /* Add a pointer to the line table for the main compilation unit
22517 so that the debugger can make sense of DW_AT_decl_file
22519 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22520 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
22521 debug_line_section_label);
22523 output_comdat_type_unit (ctnode);
22526 htab_delete (comdat_type_table);
22528 /* Output the main compilation unit if non-empty or if .debug_macinfo
22529 will be emitted. */
22530 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
22532 /* Output the abbreviation table. */
22533 if (abbrev_die_table_in_use != 1)
22535 switch_to_section (debug_abbrev_section);
22536 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
22537 output_abbrev_section ();
22540 /* Output location list section if necessary. */
22541 if (have_location_lists)
22543 /* Output the location lists info. */
22544 switch_to_section (debug_loc_section);
22545 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
22546 DEBUG_LOC_SECTION_LABEL, 0);
22547 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
22548 output_location_lists (comp_unit_die ());
22551 /* Output public names table if necessary. */
22552 if (!VEC_empty (pubname_entry, pubname_table))
22554 gcc_assert (info_section_emitted);
22555 switch_to_section (debug_pubnames_section);
22556 output_pubnames (pubname_table);
22559 /* Output public types table if necessary. */
22560 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22561 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22562 simply won't look for the section. */
22563 if (!VEC_empty (pubname_entry, pubtype_table))
22565 bool empty = false;
22567 if (flag_eliminate_unused_debug_types)
22569 /* The pubtypes table might be emptied by pruning unused items. */
22573 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
22574 if (p->die->die_offset != 0)
22582 gcc_assert (info_section_emitted);
22583 switch_to_section (debug_pubtypes_section);
22584 output_pubnames (pubtype_table);
22588 /* Output the address range information if a CU (.debug_info section)
22589 was emitted. We output an empty table even if we had no functions
22590 to put in it. This because the consumer has no way to tell the
22591 difference between an empty table that we omitted and failure to
22592 generate a table that would have contained data. */
22593 if (info_section_emitted)
22595 unsigned long aranges_length = size_of_aranges ();
22597 switch_to_section (debug_aranges_section);
22598 output_aranges (aranges_length);
22601 /* Output ranges section if necessary. */
22602 if (ranges_table_in_use)
22604 switch_to_section (debug_ranges_section);
22605 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
22609 /* Output the source line correspondence table. We must do this
22610 even if there is no line information. Otherwise, on an empty
22611 translation unit, we will generate a present, but empty,
22612 .debug_info section. IRIX 6.5 `nm' will then complain when
22613 examining the file. This is done late so that any filenames
22614 used by the debug_info section are marked as 'used'. */
22615 switch_to_section (debug_line_section);
22616 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
22617 if (! DWARF2_ASM_LINE_DEBUG_INFO)
22618 output_line_info ();
22620 /* Have to end the macro section. */
22621 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22623 switch_to_section (debug_macinfo_section);
22624 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
22625 if (!VEC_empty (macinfo_entry, macinfo_table))
22627 dw2_asm_output_data (1, 0, "End compilation unit");
22630 /* If we emitted any DW_FORM_strp form attribute, output the string
22632 if (debug_str_hash)
22633 htab_traverse (debug_str_hash, output_indirect_string, NULL);
22636 #include "gt-dwarf2out.h"