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 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* TODO: Emit .debug_line header even when there are no functions, since
25 the file numbers are used by .debug_info. Alternately, leave
26 out locations for types and decls.
27 Avoid talking about ctors and op= for PODs.
28 Factor out common prologue sequences into multiple CIEs. */
30 /* The first part of this file deals with the DWARF 2 frame unwind
31 information, which is also used by the GCC efficient exception handling
32 mechanism. The second part, controlled only by an #ifdef
33 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 /* DWARF2 Abbreviation Glossary:
38 CFA = Canonical Frame Address
39 a fixed address on the stack which identifies a call frame.
40 We define it to be the value of SP just before the call insn.
41 The CFA register and offset, which may change during the course
42 of the function, are used to calculate its value at runtime.
44 CFI = Call Frame Instruction
45 an instruction for the DWARF2 abstract machine
47 CIE = Common Information Entry
48 information describing information common to one or more FDEs
50 DIE = Debugging Information Entry
52 FDE = Frame Description Entry
53 information describing the stack call frame, in particular,
54 how to restore registers
56 DW_CFA_... = DWARF2 CFA call frame instruction
57 DW_TAG_... = DWARF2 DIE tag */
61 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
85 #include "diagnostic.h"
88 #include "langhooks.h"
93 #include "tree-pass.h"
95 #ifdef DWARF2_DEBUGGING_INFO
96 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
98 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 #ifndef DWARF2_FRAME_INFO
118 # ifdef DWARF2_DEBUGGING_INFO
119 # define DWARF2_FRAME_INFO \
120 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
122 # define DWARF2_FRAME_INFO 0
126 /* Map register numbers held in the call frame info that gcc has
127 collected using DWARF_FRAME_REGNUM to those that should be output in
128 .debug_frame and .eh_frame. */
129 #ifndef DWARF2_FRAME_REG_OUT
130 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
133 /* Save the result of dwarf2out_do_frame across PCH. */
134 static GTY(()) bool saved_do_cfi_asm = 0;
136 /* Decide whether we want to emit frame unwind information for the current
140 dwarf2out_do_frame (void)
142 /* We want to emit correct CFA location expressions or lists, so we
143 have to return true if we're going to output debug info, even if
144 we're not going to output frame or unwind info. */
145 return (write_symbols == DWARF2_DEBUG
146 || write_symbols == VMS_AND_DWARF2_DEBUG
147 || DWARF2_FRAME_INFO || saved_do_cfi_asm
148 #ifdef DWARF2_UNWIND_INFO
149 || (DWARF2_UNWIND_INFO
150 && (flag_unwind_tables
151 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
156 /* Decide whether to emit frame unwind via assembler directives. */
159 dwarf2out_do_cfi_asm (void)
163 #ifdef MIPS_DEBUGGING_INFO
166 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
168 if (saved_do_cfi_asm)
170 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
173 /* Make sure the personality encoding is one the assembler can support.
174 In particular, aligned addresses can't be handled. */
175 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
176 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
178 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
179 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
182 saved_do_cfi_asm = true;
186 /* The size of the target's pointer type. */
188 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
191 /* Array of RTXes referenced by the debugging information, which therefore
192 must be kept around forever. */
193 static GTY(()) VEC(rtx,gc) *used_rtx_array;
195 /* A pointer to the base of a list of incomplete types which might be
196 completed at some later time. incomplete_types_list needs to be a
197 VEC(tree,gc) because we want to tell the garbage collector about
199 static GTY(()) VEC(tree,gc) *incomplete_types;
201 /* A pointer to the base of a table of references to declaration
202 scopes. This table is a display which tracks the nesting
203 of declaration scopes at the current scope and containing
204 scopes. This table is used to find the proper place to
205 define type declaration DIE's. */
206 static GTY(()) VEC(tree,gc) *decl_scope_table;
208 /* Pointers to various DWARF2 sections. */
209 static GTY(()) section *debug_info_section;
210 static GTY(()) section *debug_abbrev_section;
211 static GTY(()) section *debug_aranges_section;
212 static GTY(()) section *debug_macinfo_section;
213 static GTY(()) section *debug_line_section;
214 static GTY(()) section *debug_loc_section;
215 static GTY(()) section *debug_pubnames_section;
216 static GTY(()) section *debug_pubtypes_section;
217 static GTY(()) section *debug_str_section;
218 static GTY(()) section *debug_ranges_section;
219 static GTY(()) section *debug_frame_section;
221 /* Personality decl of current unit. Used only when assembler does not support
223 static GTY(()) rtx current_unit_personality;
225 /* How to start an assembler comment. */
226 #ifndef ASM_COMMENT_START
227 #define ASM_COMMENT_START ";#"
230 typedef struct dw_cfi_struct *dw_cfi_ref;
231 typedef struct dw_fde_struct *dw_fde_ref;
232 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
234 /* Call frames are described using a sequence of Call Frame
235 Information instructions. The register number, offset
236 and address fields are provided as possible operands;
237 their use is selected by the opcode field. */
239 enum dw_cfi_oprnd_type {
241 dw_cfi_oprnd_reg_num,
247 typedef union GTY(()) dw_cfi_oprnd_struct {
248 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
249 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
250 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
251 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
255 typedef struct GTY(()) dw_cfi_struct {
256 dw_cfi_ref dw_cfi_next;
257 enum dwarf_call_frame_info dw_cfi_opc;
258 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
260 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
265 /* This is how we define the location of the CFA. We use to handle it
266 as REG + OFFSET all the time, but now it can be more complex.
267 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
268 Instead of passing around REG and OFFSET, we pass a copy
269 of this structure. */
270 typedef struct GTY(()) cfa_loc {
271 HOST_WIDE_INT offset;
272 HOST_WIDE_INT base_offset;
274 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
275 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
278 /* All call frame descriptions (FDE's) in the GCC generated DWARF
279 refer to a single Common Information Entry (CIE), defined at
280 the beginning of the .debug_frame section. This use of a single
281 CIE obviates the need to keep track of multiple CIE's
282 in the DWARF generation routines below. */
284 typedef struct GTY(()) dw_fde_struct {
286 const char *dw_fde_begin;
287 const char *dw_fde_current_label;
288 const char *dw_fde_end;
289 const char *dw_fde_hot_section_label;
290 const char *dw_fde_hot_section_end_label;
291 const char *dw_fde_unlikely_section_label;
292 const char *dw_fde_unlikely_section_end_label;
293 dw_cfi_ref dw_fde_cfi;
294 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
295 unsigned funcdef_number;
296 HOST_WIDE_INT stack_realignment;
297 /* Dynamic realign argument pointer register. */
298 unsigned int drap_reg;
299 /* Virtual dynamic realign argument pointer register. */
300 unsigned int vdrap_reg;
301 unsigned all_throwers_are_sibcalls : 1;
302 unsigned nothrow : 1;
303 unsigned uses_eh_lsda : 1;
304 /* Whether we did stack realign in this call frame. */
305 unsigned stack_realign : 1;
306 /* Whether dynamic realign argument pointer register has been saved. */
307 unsigned drap_reg_saved: 1;
308 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
309 unsigned in_std_section : 1;
310 /* True iff dw_fde_unlikely_section_label is in text_section or
311 cold_text_section. */
312 unsigned cold_in_std_section : 1;
313 /* True iff switched sections. */
314 unsigned dw_fde_switched_sections : 1;
315 /* True iff switching from cold to hot section. */
316 unsigned dw_fde_switched_cold_to_hot : 1;
320 /* Maximum size (in bytes) of an artificially generated label. */
321 #define MAX_ARTIFICIAL_LABEL_BYTES 30
323 /* The size of addresses as they appear in the Dwarf 2 data.
324 Some architectures use word addresses to refer to code locations,
325 but Dwarf 2 info always uses byte addresses. On such machines,
326 Dwarf 2 addresses need to be larger than the architecture's
328 #ifndef DWARF2_ADDR_SIZE
329 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
332 /* The size in bytes of a DWARF field indicating an offset or length
333 relative to a debug info section, specified to be 4 bytes in the
334 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
337 #ifndef DWARF_OFFSET_SIZE
338 #define DWARF_OFFSET_SIZE 4
341 /* According to the (draft) DWARF 3 specification, the initial length
342 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
343 bytes are 0xffffffff, followed by the length stored in the next 8
346 However, the SGI/MIPS ABI uses an initial length which is equal to
347 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
349 #ifndef DWARF_INITIAL_LENGTH_SIZE
350 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
353 /* Round SIZE up to the nearest BOUNDARY. */
354 #define DWARF_ROUND(SIZE,BOUNDARY) \
355 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
357 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
358 #ifndef DWARF_CIE_DATA_ALIGNMENT
359 #ifdef STACK_GROWS_DOWNWARD
360 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
362 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
366 /* CIE identifier. */
367 #if HOST_BITS_PER_WIDE_INT >= 64
368 #define DWARF_CIE_ID \
369 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
371 #define DWARF_CIE_ID DW_CIE_ID
374 /* A pointer to the base of a table that contains frame description
375 information for each routine. */
376 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
378 /* Number of elements currently allocated for fde_table. */
379 static GTY(()) unsigned fde_table_allocated;
381 /* Number of elements in fde_table currently in use. */
382 static GTY(()) unsigned fde_table_in_use;
384 /* Size (in elements) of increments by which we may expand the
386 #define FDE_TABLE_INCREMENT 256
388 /* Get the current fde_table entry we should use. */
390 static inline dw_fde_ref
393 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
396 /* A list of call frame insns for the CIE. */
397 static GTY(()) dw_cfi_ref cie_cfi_head;
399 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
400 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
401 attribute that accelerates the lookup of the FDE associated
402 with the subprogram. This variable holds the table index of the FDE
403 associated with the current function (body) definition. */
404 static unsigned current_funcdef_fde;
407 struct GTY(()) indirect_string_node {
409 unsigned int refcount;
410 enum dwarf_form form;
414 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
416 /* True if the compilation unit has location entries that reference
418 static GTY(()) bool debug_str_hash_forced = false;
420 static GTY(()) int dw2_string_counter;
421 static GTY(()) unsigned long dwarf2out_cfi_label_num;
423 /* True if the compilation unit places functions in more than one section. */
424 static GTY(()) bool have_multiple_function_sections = false;
426 /* Whether the default text and cold text sections have been used at all. */
428 static GTY(()) bool text_section_used = false;
429 static GTY(()) bool cold_text_section_used = false;
431 /* The default cold text section. */
432 static GTY(()) section *cold_text_section;
434 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
436 /* Forward declarations for functions defined in this file. */
438 static char *stripattributes (const char *);
439 static const char *dwarf_cfi_name (unsigned);
440 static dw_cfi_ref new_cfi (void);
441 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
442 static void add_fde_cfi (const char *, dw_cfi_ref);
443 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
444 static void lookup_cfa (dw_cfa_location *);
445 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
446 #ifdef DWARF2_UNWIND_INFO
447 static void initial_return_save (rtx);
449 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
451 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
452 static void output_cfi_directive (dw_cfi_ref);
453 static void output_call_frame_info (int);
454 static void dwarf2out_note_section_used (void);
455 static void dwarf2out_stack_adjust (rtx, bool);
456 static void dwarf2out_args_size_adjust (HOST_WIDE_INT, const char *);
457 static void flush_queued_reg_saves (void);
458 static bool clobbers_queued_reg_save (const_rtx);
459 static void dwarf2out_frame_debug_expr (rtx, const char *);
461 /* Support for complex CFA locations. */
462 static void output_cfa_loc (dw_cfi_ref);
463 static void output_cfa_loc_raw (dw_cfi_ref);
464 static void get_cfa_from_loc_descr (dw_cfa_location *,
465 struct dw_loc_descr_struct *);
466 static struct dw_loc_descr_struct *build_cfa_loc
467 (dw_cfa_location *, HOST_WIDE_INT);
468 static struct dw_loc_descr_struct *build_cfa_aligned_loc
469 (HOST_WIDE_INT, HOST_WIDE_INT);
470 static void def_cfa_1 (const char *, dw_cfa_location *);
472 /* How to start an assembler comment. */
473 #ifndef ASM_COMMENT_START
474 #define ASM_COMMENT_START ";#"
477 /* Data and reference forms for relocatable data. */
478 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
479 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
481 #ifndef DEBUG_FRAME_SECTION
482 #define DEBUG_FRAME_SECTION ".debug_frame"
485 #ifndef FUNC_BEGIN_LABEL
486 #define FUNC_BEGIN_LABEL "LFB"
489 #ifndef FUNC_END_LABEL
490 #define FUNC_END_LABEL "LFE"
493 #ifndef FRAME_BEGIN_LABEL
494 #define FRAME_BEGIN_LABEL "Lframe"
496 #define CIE_AFTER_SIZE_LABEL "LSCIE"
497 #define CIE_END_LABEL "LECIE"
498 #define FDE_LABEL "LSFDE"
499 #define FDE_AFTER_SIZE_LABEL "LASFDE"
500 #define FDE_END_LABEL "LEFDE"
501 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
502 #define LINE_NUMBER_END_LABEL "LELT"
503 #define LN_PROLOG_AS_LABEL "LASLTP"
504 #define LN_PROLOG_END_LABEL "LELTP"
505 #define DIE_LABEL_PREFIX "DW"
507 /* The DWARF 2 CFA column which tracks the return address. Normally this
508 is the column for PC, or the first column after all of the hard
510 #ifndef DWARF_FRAME_RETURN_COLUMN
512 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
514 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
518 /* The mapping from gcc register number to DWARF 2 CFA column number. By
519 default, we just provide columns for all registers. */
520 #ifndef DWARF_FRAME_REGNUM
521 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
524 /* Hook used by __throw. */
527 expand_builtin_dwarf_sp_column (void)
529 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
530 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
533 /* Return a pointer to a copy of the section string name S with all
534 attributes stripped off, and an asterisk prepended (for assemble_name). */
537 stripattributes (const char *s)
539 char *stripped = XNEWVEC (char, strlen (s) + 2);
544 while (*s && *s != ',')
551 /* MEM is a memory reference for the register size table, each element of
552 which has mode MODE. Initialize column C as a return address column. */
555 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
557 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
558 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
559 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
562 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
564 static inline HOST_WIDE_INT
565 div_data_align (HOST_WIDE_INT off)
567 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
568 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
572 /* Return true if we need a signed version of a given opcode
573 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
576 need_data_align_sf_opcode (HOST_WIDE_INT off)
578 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
581 /* Generate code to initialize the register size table. */
584 expand_builtin_init_dwarf_reg_sizes (tree address)
587 enum machine_mode mode = TYPE_MODE (char_type_node);
588 rtx addr = expand_normal (address);
589 rtx mem = gen_rtx_MEM (BLKmode, addr);
590 bool wrote_return_column = false;
592 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
594 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
596 if (rnum < DWARF_FRAME_REGISTERS)
598 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
599 enum machine_mode save_mode = reg_raw_mode[i];
602 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
603 save_mode = choose_hard_reg_mode (i, 1, true);
604 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
606 if (save_mode == VOIDmode)
608 wrote_return_column = true;
610 size = GET_MODE_SIZE (save_mode);
614 emit_move_insn (adjust_address (mem, mode, offset),
615 gen_int_mode (size, mode));
619 if (!wrote_return_column)
620 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
622 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
623 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
626 targetm.init_dwarf_reg_sizes_extra (address);
629 /* Convert a DWARF call frame info. operation to its string name */
632 dwarf_cfi_name (unsigned int cfi_opc)
636 case DW_CFA_advance_loc:
637 return "DW_CFA_advance_loc";
639 return "DW_CFA_offset";
641 return "DW_CFA_restore";
645 return "DW_CFA_set_loc";
646 case DW_CFA_advance_loc1:
647 return "DW_CFA_advance_loc1";
648 case DW_CFA_advance_loc2:
649 return "DW_CFA_advance_loc2";
650 case DW_CFA_advance_loc4:
651 return "DW_CFA_advance_loc4";
652 case DW_CFA_offset_extended:
653 return "DW_CFA_offset_extended";
654 case DW_CFA_restore_extended:
655 return "DW_CFA_restore_extended";
656 case DW_CFA_undefined:
657 return "DW_CFA_undefined";
658 case DW_CFA_same_value:
659 return "DW_CFA_same_value";
660 case DW_CFA_register:
661 return "DW_CFA_register";
662 case DW_CFA_remember_state:
663 return "DW_CFA_remember_state";
664 case DW_CFA_restore_state:
665 return "DW_CFA_restore_state";
667 return "DW_CFA_def_cfa";
668 case DW_CFA_def_cfa_register:
669 return "DW_CFA_def_cfa_register";
670 case DW_CFA_def_cfa_offset:
671 return "DW_CFA_def_cfa_offset";
674 case DW_CFA_def_cfa_expression:
675 return "DW_CFA_def_cfa_expression";
676 case DW_CFA_expression:
677 return "DW_CFA_expression";
678 case DW_CFA_offset_extended_sf:
679 return "DW_CFA_offset_extended_sf";
680 case DW_CFA_def_cfa_sf:
681 return "DW_CFA_def_cfa_sf";
682 case DW_CFA_def_cfa_offset_sf:
683 return "DW_CFA_def_cfa_offset_sf";
685 /* SGI/MIPS specific */
686 case DW_CFA_MIPS_advance_loc8:
687 return "DW_CFA_MIPS_advance_loc8";
690 case DW_CFA_GNU_window_save:
691 return "DW_CFA_GNU_window_save";
692 case DW_CFA_GNU_args_size:
693 return "DW_CFA_GNU_args_size";
694 case DW_CFA_GNU_negative_offset_extended:
695 return "DW_CFA_GNU_negative_offset_extended";
698 return "DW_CFA_<unknown>";
702 /* Return a pointer to a newly allocated Call Frame Instruction. */
704 static inline dw_cfi_ref
707 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
709 cfi->dw_cfi_next = NULL;
710 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
711 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
716 /* Add a Call Frame Instruction to list of instructions. */
719 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
722 dw_fde_ref fde = current_fde ();
724 /* When DRAP is used, CFA is defined with an expression. Redefine
725 CFA may lead to a different CFA value. */
726 /* ??? Of course, this heuristic fails when we're annotating epilogues,
727 because of course we'll always want to redefine the CFA back to the
728 stack pointer on the way out. Where should we move this check? */
729 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
730 switch (cfi->dw_cfi_opc)
732 case DW_CFA_def_cfa_register:
733 case DW_CFA_def_cfa_offset:
734 case DW_CFA_def_cfa_offset_sf:
736 case DW_CFA_def_cfa_sf:
743 /* Find the end of the chain. */
744 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
750 /* Generate a new label for the CFI info to refer to. FORCE is true
751 if a label needs to be output even when using .cfi_* directives. */
754 dwarf2out_cfi_label (bool force)
756 static char label[20];
758 if (!force && dwarf2out_do_cfi_asm ())
760 /* In this case, we will be emitting the asm directive instead of
761 the label, so just return a placeholder to keep the rest of the
763 strcpy (label, "<do not output>");
767 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
768 ASM_OUTPUT_LABEL (asm_out_file, label);
774 /* True if remember_state should be emitted before following CFI directive. */
775 static bool emit_cfa_remember;
777 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
778 or to the CIE if LABEL is NULL. */
781 add_fde_cfi (const char *label, dw_cfi_ref cfi)
783 dw_cfi_ref *list_head;
785 if (emit_cfa_remember)
787 dw_cfi_ref cfi_remember;
789 /* Emit the state save. */
790 emit_cfa_remember = false;
791 cfi_remember = new_cfi ();
792 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
793 add_fde_cfi (label, cfi_remember);
796 list_head = &cie_cfi_head;
798 if (dwarf2out_do_cfi_asm ())
802 dw_fde_ref fde = current_fde ();
804 gcc_assert (fde != NULL);
806 /* We still have to add the cfi to the list so that lookup_cfa
807 works later on. When -g2 and above we even need to force
808 emitting of CFI labels and add to list a DW_CFA_set_loc for
809 convert_cfa_to_fb_loc_list purposes. If we're generating
810 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
811 convert_cfa_to_fb_loc_list. */
812 if (dwarf_version == 2
813 && debug_info_level > DINFO_LEVEL_TERSE
814 && (write_symbols == DWARF2_DEBUG
815 || write_symbols == VMS_AND_DWARF2_DEBUG))
817 switch (cfi->dw_cfi_opc)
819 case DW_CFA_def_cfa_offset:
820 case DW_CFA_def_cfa_offset_sf:
821 case DW_CFA_def_cfa_register:
823 case DW_CFA_def_cfa_sf:
824 case DW_CFA_def_cfa_expression:
825 case DW_CFA_restore_state:
826 if (*label == 0 || strcmp (label, "<do not output>") == 0)
827 label = dwarf2out_cfi_label (true);
829 if (fde->dw_fde_current_label == NULL
830 || strcmp (label, fde->dw_fde_current_label) != 0)
834 label = xstrdup (label);
836 /* Set the location counter to the new label. */
838 /* It doesn't metter whether DW_CFA_set_loc
839 or DW_CFA_advance_loc4 is added here, those aren't
840 emitted into assembly, only looked up by
841 convert_cfa_to_fb_loc_list. */
842 xcfi->dw_cfi_opc = DW_CFA_set_loc;
843 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
844 add_cfi (&fde->dw_fde_cfi, xcfi);
845 fde->dw_fde_current_label = label;
853 output_cfi_directive (cfi);
855 list_head = &fde->dw_fde_cfi;
857 /* ??? If this is a CFI for the CIE, we don't emit. This
858 assumes that the standard CIE contents that the assembler
859 uses matches the standard CIE contents that the compiler
860 uses. This is probably a bad assumption. I'm not quite
861 sure how to address this for now. */
865 dw_fde_ref fde = current_fde ();
867 gcc_assert (fde != NULL);
870 label = dwarf2out_cfi_label (false);
872 if (fde->dw_fde_current_label == NULL
873 || strcmp (label, fde->dw_fde_current_label) != 0)
877 label = xstrdup (label);
879 /* Set the location counter to the new label. */
881 /* If we have a current label, advance from there, otherwise
882 set the location directly using set_loc. */
883 xcfi->dw_cfi_opc = fde->dw_fde_current_label
884 ? DW_CFA_advance_loc4
886 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
887 add_cfi (&fde->dw_fde_cfi, xcfi);
889 fde->dw_fde_current_label = label;
892 list_head = &fde->dw_fde_cfi;
895 add_cfi (list_head, cfi);
898 /* Subroutine of lookup_cfa. */
901 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
903 switch (cfi->dw_cfi_opc)
905 case DW_CFA_def_cfa_offset:
906 case DW_CFA_def_cfa_offset_sf:
907 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
909 case DW_CFA_def_cfa_register:
910 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
913 case DW_CFA_def_cfa_sf:
914 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
915 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
917 case DW_CFA_def_cfa_expression:
918 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
921 case DW_CFA_remember_state:
922 gcc_assert (!remember->in_use);
924 remember->in_use = 1;
926 case DW_CFA_restore_state:
927 gcc_assert (remember->in_use);
929 remember->in_use = 0;
937 /* Find the previous value for the CFA. */
940 lookup_cfa (dw_cfa_location *loc)
944 dw_cfa_location remember;
946 memset (loc, 0, sizeof (*loc));
947 loc->reg = INVALID_REGNUM;
950 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
951 lookup_cfa_1 (cfi, loc, &remember);
953 fde = current_fde ();
955 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
956 lookup_cfa_1 (cfi, loc, &remember);
959 /* The current rule for calculating the DWARF2 canonical frame address. */
960 static dw_cfa_location cfa;
962 /* The register used for saving registers to the stack, and its offset
964 static dw_cfa_location cfa_store;
966 /* The current save location around an epilogue. */
967 static dw_cfa_location cfa_remember;
969 /* The running total of the size of arguments pushed onto the stack. */
970 static HOST_WIDE_INT args_size;
972 /* The last args_size we actually output. */
973 static HOST_WIDE_INT old_args_size;
975 /* Entry point to update the canonical frame address (CFA).
976 LABEL is passed to add_fde_cfi. The value of CFA is now to be
977 calculated from REG+OFFSET. */
980 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
987 def_cfa_1 (label, &loc);
990 /* Determine if two dw_cfa_location structures define the same data. */
993 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
995 return (loc1->reg == loc2->reg
996 && loc1->offset == loc2->offset
997 && loc1->indirect == loc2->indirect
998 && (loc1->indirect == 0
999 || loc1->base_offset == loc2->base_offset));
1002 /* This routine does the actual work. The CFA is now calculated from
1003 the dw_cfa_location structure. */
1006 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1009 dw_cfa_location old_cfa, loc;
1014 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1015 cfa_store.offset = loc.offset;
1017 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1018 lookup_cfa (&old_cfa);
1020 /* If nothing changed, no need to issue any call frame instructions. */
1021 if (cfa_equal_p (&loc, &old_cfa))
1026 if (loc.reg == old_cfa.reg && !loc.indirect)
1028 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1029 the CFA register did not change but the offset did. The data
1030 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1031 in the assembler via the .cfi_def_cfa_offset directive. */
1033 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1035 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1036 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1039 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1040 else if (loc.offset == old_cfa.offset
1041 && old_cfa.reg != INVALID_REGNUM
1044 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1045 indicating the CFA register has changed to <register> but the
1046 offset has not changed. */
1047 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1048 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1052 else if (loc.indirect == 0)
1054 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1055 indicating the CFA register has changed to <register> with
1056 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1057 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1060 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1062 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1063 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1064 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1068 /* Construct a DW_CFA_def_cfa_expression instruction to
1069 calculate the CFA using a full location expression since no
1070 register-offset pair is available. */
1071 struct dw_loc_descr_struct *loc_list;
1073 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1074 loc_list = build_cfa_loc (&loc, 0);
1075 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1078 add_fde_cfi (label, cfi);
1081 /* Add the CFI for saving a register. REG is the CFA column number.
1082 LABEL is passed to add_fde_cfi.
1083 If SREG is -1, the register is saved at OFFSET from the CFA;
1084 otherwise it is saved in SREG. */
1087 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1089 dw_cfi_ref cfi = new_cfi ();
1090 dw_fde_ref fde = current_fde ();
1092 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1094 /* When stack is aligned, store REG using DW_CFA_expression with
1097 && fde->stack_realign
1098 && sreg == INVALID_REGNUM)
1100 cfi->dw_cfi_opc = DW_CFA_expression;
1101 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = reg;
1102 cfi->dw_cfi_oprnd1.dw_cfi_loc
1103 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1105 else if (sreg == INVALID_REGNUM)
1107 if (need_data_align_sf_opcode (offset))
1108 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1109 else if (reg & ~0x3f)
1110 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1112 cfi->dw_cfi_opc = DW_CFA_offset;
1113 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1115 else if (sreg == reg)
1116 cfi->dw_cfi_opc = DW_CFA_same_value;
1119 cfi->dw_cfi_opc = DW_CFA_register;
1120 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1123 add_fde_cfi (label, cfi);
1126 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1127 This CFI tells the unwinder that it needs to restore the window registers
1128 from the previous frame's window save area.
1130 ??? Perhaps we should note in the CIE where windows are saved (instead of
1131 assuming 0(cfa)) and what registers are in the window. */
1134 dwarf2out_window_save (const char *label)
1136 dw_cfi_ref cfi = new_cfi ();
1138 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1139 add_fde_cfi (label, cfi);
1142 /* Add a CFI to update the running total of the size of arguments
1143 pushed onto the stack. */
1146 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1150 if (size == old_args_size)
1153 old_args_size = size;
1156 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1157 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1158 add_fde_cfi (label, cfi);
1161 /* Entry point for saving a register to the stack. REG is the GCC register
1162 number. LABEL and OFFSET are passed to reg_save. */
1165 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1167 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1170 /* Entry point for saving the return address in the stack.
1171 LABEL and OFFSET are passed to reg_save. */
1174 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1176 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1179 /* Entry point for saving the return address in a register.
1180 LABEL and SREG are passed to reg_save. */
1183 dwarf2out_return_reg (const char *label, unsigned int sreg)
1185 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1188 #ifdef DWARF2_UNWIND_INFO
1189 /* Record the initial position of the return address. RTL is
1190 INCOMING_RETURN_ADDR_RTX. */
1193 initial_return_save (rtx rtl)
1195 unsigned int reg = INVALID_REGNUM;
1196 HOST_WIDE_INT offset = 0;
1198 switch (GET_CODE (rtl))
1201 /* RA is in a register. */
1202 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1206 /* RA is on the stack. */
1207 rtl = XEXP (rtl, 0);
1208 switch (GET_CODE (rtl))
1211 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1216 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1217 offset = INTVAL (XEXP (rtl, 1));
1221 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1222 offset = -INTVAL (XEXP (rtl, 1));
1232 /* The return address is at some offset from any value we can
1233 actually load. For instance, on the SPARC it is in %i7+8. Just
1234 ignore the offset for now; it doesn't matter for unwinding frames. */
1235 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1236 initial_return_save (XEXP (rtl, 0));
1243 if (reg != DWARF_FRAME_RETURN_COLUMN)
1244 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1248 /* Given a SET, calculate the amount of stack adjustment it
1251 static HOST_WIDE_INT
1252 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1253 HOST_WIDE_INT cur_offset)
1255 const_rtx src = SET_SRC (pattern);
1256 const_rtx dest = SET_DEST (pattern);
1257 HOST_WIDE_INT offset = 0;
1260 if (dest == stack_pointer_rtx)
1262 code = GET_CODE (src);
1264 /* Assume (set (reg sp) (reg whatever)) sets args_size
1266 if (code == REG && src != stack_pointer_rtx)
1268 offset = -cur_args_size;
1269 #ifndef STACK_GROWS_DOWNWARD
1272 return offset - cur_offset;
1275 if (! (code == PLUS || code == MINUS)
1276 || XEXP (src, 0) != stack_pointer_rtx
1277 || !CONST_INT_P (XEXP (src, 1)))
1280 /* (set (reg sp) (plus (reg sp) (const_int))) */
1281 offset = INTVAL (XEXP (src, 1));
1287 if (MEM_P (src) && !MEM_P (dest))
1291 /* (set (mem (pre_dec (reg sp))) (foo)) */
1292 src = XEXP (dest, 0);
1293 code = GET_CODE (src);
1299 if (XEXP (src, 0) == stack_pointer_rtx)
1301 rtx val = XEXP (XEXP (src, 1), 1);
1302 /* We handle only adjustments by constant amount. */
1303 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1304 && CONST_INT_P (val));
1305 offset = -INTVAL (val);
1312 if (XEXP (src, 0) == stack_pointer_rtx)
1314 offset = GET_MODE_SIZE (GET_MODE (dest));
1321 if (XEXP (src, 0) == stack_pointer_rtx)
1323 offset = -GET_MODE_SIZE (GET_MODE (dest));
1338 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1339 indexed by INSN_UID. */
1341 static HOST_WIDE_INT *barrier_args_size;
1343 /* Helper function for compute_barrier_args_size. Handle one insn. */
1345 static HOST_WIDE_INT
1346 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1347 VEC (rtx, heap) **next)
1349 HOST_WIDE_INT offset = 0;
1352 if (! RTX_FRAME_RELATED_P (insn))
1354 if (prologue_epilogue_contains (insn))
1356 else if (GET_CODE (PATTERN (insn)) == SET)
1357 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1358 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1359 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1361 /* There may be stack adjustments inside compound insns. Search
1363 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1364 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1365 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1366 cur_args_size, offset);
1371 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1375 expr = XEXP (expr, 0);
1376 if (GET_CODE (expr) == PARALLEL
1377 || GET_CODE (expr) == SEQUENCE)
1378 for (i = 1; i < XVECLEN (expr, 0); i++)
1380 rtx elem = XVECEXP (expr, 0, i);
1382 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1383 offset += stack_adjust_offset (elem, cur_args_size, offset);
1388 #ifndef STACK_GROWS_DOWNWARD
1392 cur_args_size += offset;
1393 if (cur_args_size < 0)
1398 rtx dest = JUMP_LABEL (insn);
1402 if (barrier_args_size [INSN_UID (dest)] < 0)
1404 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1405 VEC_safe_push (rtx, heap, *next, dest);
1410 return cur_args_size;
1413 /* Walk the whole function and compute args_size on BARRIERs. */
1416 compute_barrier_args_size (void)
1418 int max_uid = get_max_uid (), i;
1420 VEC (rtx, heap) *worklist, *next, *tmp;
1422 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1423 for (i = 0; i < max_uid; i++)
1424 barrier_args_size[i] = -1;
1426 worklist = VEC_alloc (rtx, heap, 20);
1427 next = VEC_alloc (rtx, heap, 20);
1428 insn = get_insns ();
1429 barrier_args_size[INSN_UID (insn)] = 0;
1430 VEC_quick_push (rtx, worklist, insn);
1433 while (!VEC_empty (rtx, worklist))
1435 rtx prev, body, first_insn;
1436 HOST_WIDE_INT cur_args_size;
1438 first_insn = insn = VEC_pop (rtx, worklist);
1439 cur_args_size = barrier_args_size[INSN_UID (insn)];
1440 prev = prev_nonnote_insn (insn);
1441 if (prev && BARRIER_P (prev))
1442 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1444 for (; insn; insn = NEXT_INSN (insn))
1446 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1448 if (BARRIER_P (insn))
1453 if (insn == first_insn)
1455 else if (barrier_args_size[INSN_UID (insn)] < 0)
1457 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1462 /* The insns starting with this label have been
1463 already scanned or are in the worklist. */
1468 body = PATTERN (insn);
1469 if (GET_CODE (body) == SEQUENCE)
1471 HOST_WIDE_INT dest_args_size = cur_args_size;
1472 for (i = 1; i < XVECLEN (body, 0); i++)
1473 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1474 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1476 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1477 dest_args_size, &next);
1480 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1481 cur_args_size, &next);
1483 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1484 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1485 dest_args_size, &next);
1488 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1489 cur_args_size, &next);
1493 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1497 if (VEC_empty (rtx, next))
1500 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1504 VEC_truncate (rtx, next, 0);
1507 VEC_free (rtx, heap, worklist);
1508 VEC_free (rtx, heap, next);
1512 /* Check INSN to see if it looks like a push or a stack adjustment, and
1513 make a note of it if it does. EH uses this information to find out how
1514 much extra space it needs to pop off the stack. */
1517 dwarf2out_stack_adjust (rtx insn, bool after_p)
1519 HOST_WIDE_INT offset;
1523 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1524 with this function. Proper support would require all frame-related
1525 insns to be marked, and to be able to handle saving state around
1526 epilogues textually in the middle of the function. */
1527 if (prologue_epilogue_contains (insn))
1530 /* If INSN is an instruction from target of an annulled branch, the
1531 effects are for the target only and so current argument size
1532 shouldn't change at all. */
1534 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1535 && INSN_FROM_TARGET_P (insn))
1538 /* If only calls can throw, and we have a frame pointer,
1539 save up adjustments until we see the CALL_INSN. */
1540 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1542 if (CALL_P (insn) && !after_p)
1544 /* Extract the size of the args from the CALL rtx itself. */
1545 insn = PATTERN (insn);
1546 if (GET_CODE (insn) == PARALLEL)
1547 insn = XVECEXP (insn, 0, 0);
1548 if (GET_CODE (insn) == SET)
1549 insn = SET_SRC (insn);
1550 gcc_assert (GET_CODE (insn) == CALL);
1551 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1556 if (CALL_P (insn) && !after_p)
1558 if (!flag_asynchronous_unwind_tables)
1559 dwarf2out_args_size ("", args_size);
1562 else if (BARRIER_P (insn))
1564 /* Don't call compute_barrier_args_size () if the only
1565 BARRIER is at the end of function. */
1566 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1567 compute_barrier_args_size ();
1568 if (barrier_args_size == NULL)
1572 offset = barrier_args_size[INSN_UID (insn)];
1577 offset -= args_size;
1578 #ifndef STACK_GROWS_DOWNWARD
1582 else if (GET_CODE (PATTERN (insn)) == SET)
1583 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1584 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1585 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1587 /* There may be stack adjustments inside compound insns. Search
1589 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1590 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1591 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1600 label = dwarf2out_cfi_label (false);
1601 dwarf2out_args_size_adjust (offset, label);
1604 /* Adjust args_size based on stack adjustment OFFSET. */
1607 dwarf2out_args_size_adjust (HOST_WIDE_INT offset, const char *label)
1609 if (cfa.reg == STACK_POINTER_REGNUM)
1610 cfa.offset += offset;
1612 if (cfa_store.reg == STACK_POINTER_REGNUM)
1613 cfa_store.offset += offset;
1615 #ifndef STACK_GROWS_DOWNWARD
1619 args_size += offset;
1623 def_cfa_1 (label, &cfa);
1624 if (flag_asynchronous_unwind_tables)
1625 dwarf2out_args_size (label, args_size);
1630 /* We delay emitting a register save until either (a) we reach the end
1631 of the prologue or (b) the register is clobbered. This clusters
1632 register saves so that there are fewer pc advances. */
1634 struct GTY(()) queued_reg_save {
1635 struct queued_reg_save *next;
1637 HOST_WIDE_INT cfa_offset;
1641 static GTY(()) struct queued_reg_save *queued_reg_saves;
1643 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1644 struct GTY(()) reg_saved_in_data {
1649 /* A list of registers saved in other registers.
1650 The list intentionally has a small maximum capacity of 4; if your
1651 port needs more than that, you might consider implementing a
1652 more efficient data structure. */
1653 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1654 static GTY(()) size_t num_regs_saved_in_regs;
1656 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1657 static const char *last_reg_save_label;
1659 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1660 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1663 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1665 struct queued_reg_save *q;
1667 /* Duplicates waste space, but it's also necessary to remove them
1668 for correctness, since the queue gets output in reverse
1670 for (q = queued_reg_saves; q != NULL; q = q->next)
1671 if (REGNO (q->reg) == REGNO (reg))
1676 q = GGC_NEW (struct queued_reg_save);
1677 q->next = queued_reg_saves;
1678 queued_reg_saves = q;
1682 q->cfa_offset = offset;
1683 q->saved_reg = sreg;
1685 last_reg_save_label = label;
1688 /* Output all the entries in QUEUED_REG_SAVES. */
1691 flush_queued_reg_saves (void)
1693 struct queued_reg_save *q;
1695 for (q = queued_reg_saves; q; q = q->next)
1698 unsigned int reg, sreg;
1700 for (i = 0; i < num_regs_saved_in_regs; i++)
1701 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1703 if (q->saved_reg && i == num_regs_saved_in_regs)
1705 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1706 num_regs_saved_in_regs++;
1708 if (i != num_regs_saved_in_regs)
1710 regs_saved_in_regs[i].orig_reg = q->reg;
1711 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1714 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1716 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1718 sreg = INVALID_REGNUM;
1719 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1722 queued_reg_saves = NULL;
1723 last_reg_save_label = NULL;
1726 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1727 location for? Or, does it clobber a register which we've previously
1728 said that some other register is saved in, and for which we now
1729 have a new location for? */
1732 clobbers_queued_reg_save (const_rtx insn)
1734 struct queued_reg_save *q;
1736 for (q = queued_reg_saves; q; q = q->next)
1739 if (modified_in_p (q->reg, insn))
1741 for (i = 0; i < num_regs_saved_in_regs; i++)
1742 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1743 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1750 /* Entry point for saving the first register into the second. */
1753 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1756 unsigned int regno, sregno;
1758 for (i = 0; i < num_regs_saved_in_regs; i++)
1759 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1761 if (i == num_regs_saved_in_regs)
1763 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1764 num_regs_saved_in_regs++;
1766 regs_saved_in_regs[i].orig_reg = reg;
1767 regs_saved_in_regs[i].saved_in_reg = sreg;
1769 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1770 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1771 reg_save (label, regno, sregno, 0);
1774 /* What register, if any, is currently saved in REG? */
1777 reg_saved_in (rtx reg)
1779 unsigned int regn = REGNO (reg);
1781 struct queued_reg_save *q;
1783 for (q = queued_reg_saves; q; q = q->next)
1784 if (q->saved_reg && regn == REGNO (q->saved_reg))
1787 for (i = 0; i < num_regs_saved_in_regs; i++)
1788 if (regs_saved_in_regs[i].saved_in_reg
1789 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1790 return regs_saved_in_regs[i].orig_reg;
1796 /* A temporary register holding an integral value used in adjusting SP
1797 or setting up the store_reg. The "offset" field holds the integer
1798 value, not an offset. */
1799 static dw_cfa_location cfa_temp;
1801 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1804 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1806 memset (&cfa, 0, sizeof (cfa));
1808 switch (GET_CODE (pat))
1811 cfa.reg = REGNO (XEXP (pat, 0));
1812 cfa.offset = INTVAL (XEXP (pat, 1));
1816 cfa.reg = REGNO (pat);
1820 /* Recurse and define an expression. */
1824 def_cfa_1 (label, &cfa);
1827 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1830 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1834 gcc_assert (GET_CODE (pat) == SET);
1835 dest = XEXP (pat, 0);
1836 src = XEXP (pat, 1);
1838 switch (GET_CODE (src))
1841 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1842 cfa.offset -= INTVAL (XEXP (src, 1));
1852 cfa.reg = REGNO (dest);
1853 gcc_assert (cfa.indirect == 0);
1855 def_cfa_1 (label, &cfa);
1858 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1861 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1863 HOST_WIDE_INT offset;
1864 rtx src, addr, span;
1866 src = XEXP (set, 1);
1867 addr = XEXP (set, 0);
1868 gcc_assert (MEM_P (addr));
1869 addr = XEXP (addr, 0);
1871 /* As documented, only consider extremely simple addresses. */
1872 switch (GET_CODE (addr))
1875 gcc_assert (REGNO (addr) == cfa.reg);
1876 offset = -cfa.offset;
1879 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1880 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1886 span = targetm.dwarf_register_span (src);
1888 /* ??? We'd like to use queue_reg_save, but we need to come up with
1889 a different flushing heuristic for epilogues. */
1891 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
1894 /* We have a PARALLEL describing where the contents of SRC live.
1895 Queue register saves for each piece of the PARALLEL. */
1898 HOST_WIDE_INT span_offset = offset;
1900 gcc_assert (GET_CODE (span) == PARALLEL);
1902 limit = XVECLEN (span, 0);
1903 for (par_index = 0; par_index < limit; par_index++)
1905 rtx elem = XVECEXP (span, 0, par_index);
1907 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
1908 INVALID_REGNUM, span_offset);
1909 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1914 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1917 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
1920 unsigned sregno, dregno;
1922 src = XEXP (set, 1);
1923 dest = XEXP (set, 0);
1926 sregno = DWARF_FRAME_RETURN_COLUMN;
1928 sregno = DWARF_FRAME_REGNUM (REGNO (src));
1930 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
1932 /* ??? We'd like to use queue_reg_save, but we need to come up with
1933 a different flushing heuristic for epilogues. */
1934 reg_save (label, sregno, dregno, 0);
1937 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1940 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
1942 dw_cfi_ref cfi = new_cfi ();
1943 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
1945 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
1946 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
1948 add_fde_cfi (label, cfi);
1951 /* Record call frame debugging information for an expression EXPR,
1952 which either sets SP or FP (adjusting how we calculate the frame
1953 address) or saves a register to the stack or another register.
1954 LABEL indicates the address of EXPR.
1956 This function encodes a state machine mapping rtxes to actions on
1957 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1958 users need not read the source code.
1960 The High-Level Picture
1962 Changes in the register we use to calculate the CFA: Currently we
1963 assume that if you copy the CFA register into another register, we
1964 should take the other one as the new CFA register; this seems to
1965 work pretty well. If it's wrong for some target, it's simple
1966 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1968 Changes in the register we use for saving registers to the stack:
1969 This is usually SP, but not always. Again, we deduce that if you
1970 copy SP into another register (and SP is not the CFA register),
1971 then the new register is the one we will be using for register
1972 saves. This also seems to work.
1974 Register saves: There's not much guesswork about this one; if
1975 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1976 register save, and the register used to calculate the destination
1977 had better be the one we think we're using for this purpose.
1978 It's also assumed that a copy from a call-saved register to another
1979 register is saving that register if RTX_FRAME_RELATED_P is set on
1980 that instruction. If the copy is from a call-saved register to
1981 the *same* register, that means that the register is now the same
1982 value as in the caller.
1984 Except: If the register being saved is the CFA register, and the
1985 offset is nonzero, we are saving the CFA, so we assume we have to
1986 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1987 the intent is to save the value of SP from the previous frame.
1989 In addition, if a register has previously been saved to a different
1992 Invariants / Summaries of Rules
1994 cfa current rule for calculating the CFA. It usually
1995 consists of a register and an offset.
1996 cfa_store register used by prologue code to save things to the stack
1997 cfa_store.offset is the offset from the value of
1998 cfa_store.reg to the actual CFA
1999 cfa_temp register holding an integral value. cfa_temp.offset
2000 stores the value, which will be used to adjust the
2001 stack pointer. cfa_temp is also used like cfa_store,
2002 to track stores to the stack via fp or a temp reg.
2004 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2005 with cfa.reg as the first operand changes the cfa.reg and its
2006 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2009 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2010 expression yielding a constant. This sets cfa_temp.reg
2011 and cfa_temp.offset.
2013 Rule 5: Create a new register cfa_store used to save items to the
2016 Rules 10-14: Save a register to the stack. Define offset as the
2017 difference of the original location and cfa_store's
2018 location (or cfa_temp's location if cfa_temp is used).
2020 Rules 16-20: If AND operation happens on sp in prologue, we assume
2021 stack is realigned. We will use a group of DW_OP_XXX
2022 expressions to represent the location of the stored
2023 register instead of CFA+offset.
2027 "{a,b}" indicates a choice of a xor b.
2028 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2031 (set <reg1> <reg2>:cfa.reg)
2032 effects: cfa.reg = <reg1>
2033 cfa.offset unchanged
2034 cfa_temp.reg = <reg1>
2035 cfa_temp.offset = cfa.offset
2038 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2039 {<const_int>,<reg>:cfa_temp.reg}))
2040 effects: cfa.reg = sp if fp used
2041 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2042 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2043 if cfa_store.reg==sp
2046 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2047 effects: cfa.reg = fp
2048 cfa_offset += +/- <const_int>
2051 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2052 constraints: <reg1> != fp
2054 effects: cfa.reg = <reg1>
2055 cfa_temp.reg = <reg1>
2056 cfa_temp.offset = cfa.offset
2059 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2060 constraints: <reg1> != fp
2062 effects: cfa_store.reg = <reg1>
2063 cfa_store.offset = cfa.offset - cfa_temp.offset
2066 (set <reg> <const_int>)
2067 effects: cfa_temp.reg = <reg>
2068 cfa_temp.offset = <const_int>
2071 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2072 effects: cfa_temp.reg = <reg1>
2073 cfa_temp.offset |= <const_int>
2076 (set <reg> (high <exp>))
2080 (set <reg> (lo_sum <exp> <const_int>))
2081 effects: cfa_temp.reg = <reg>
2082 cfa_temp.offset = <const_int>
2085 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2086 effects: cfa_store.offset -= <const_int>
2087 cfa.offset = cfa_store.offset if cfa.reg == sp
2089 cfa.base_offset = -cfa_store.offset
2092 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2093 effects: cfa_store.offset += -/+ mode_size(mem)
2094 cfa.offset = cfa_store.offset if cfa.reg == sp
2096 cfa.base_offset = -cfa_store.offset
2099 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2102 effects: cfa.reg = <reg1>
2103 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2106 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2107 effects: cfa.reg = <reg1>
2108 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2111 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2112 effects: cfa.reg = <reg1>
2113 cfa.base_offset = -cfa_temp.offset
2114 cfa_temp.offset -= mode_size(mem)
2117 (set <reg> {unspec, unspec_volatile})
2118 effects: target-dependent
2121 (set sp (and: sp <const_int>))
2122 constraints: cfa_store.reg == sp
2123 effects: current_fde.stack_realign = 1
2124 cfa_store.offset = 0
2125 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2128 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2129 effects: cfa_store.offset += -/+ mode_size(mem)
2132 (set (mem ({pre_inc, pre_dec} sp)) fp)
2133 constraints: fde->stack_realign == 1
2134 effects: cfa_store.offset = 0
2135 cfa.reg != HARD_FRAME_POINTER_REGNUM
2138 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2139 constraints: fde->stack_realign == 1
2141 && cfa.indirect == 0
2142 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2143 effects: Use DW_CFA_def_cfa_expression to define cfa
2144 cfa.reg == fde->drap_reg
2147 (set reg fde->drap_reg)
2148 constraints: fde->vdrap_reg == INVALID_REGNUM
2149 effects: fde->vdrap_reg = reg.
2150 (set mem fde->drap_reg)
2151 constraints: fde->drap_reg_saved == 1
2155 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2157 rtx src, dest, span;
2158 HOST_WIDE_INT offset;
2161 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2162 the PARALLEL independently. The first element is always processed if
2163 it is a SET. This is for backward compatibility. Other elements
2164 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2165 flag is set in them. */
2166 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2169 int limit = XVECLEN (expr, 0);
2172 /* PARALLELs have strict read-modify-write semantics, so we
2173 ought to evaluate every rvalue before changing any lvalue.
2174 It's cumbersome to do that in general, but there's an
2175 easy approximation that is enough for all current users:
2176 handle register saves before register assignments. */
2177 if (GET_CODE (expr) == PARALLEL)
2178 for (par_index = 0; par_index < limit; par_index++)
2180 elem = XVECEXP (expr, 0, par_index);
2181 if (GET_CODE (elem) == SET
2182 && MEM_P (SET_DEST (elem))
2183 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2184 dwarf2out_frame_debug_expr (elem, label);
2187 for (par_index = 0; par_index < limit; par_index++)
2189 elem = XVECEXP (expr, 0, par_index);
2190 if (GET_CODE (elem) == SET
2191 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2192 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2193 dwarf2out_frame_debug_expr (elem, label);
2194 else if (GET_CODE (elem) == SET
2196 && !RTX_FRAME_RELATED_P (elem))
2198 /* Stack adjustment combining might combine some post-prologue
2199 stack adjustment into a prologue stack adjustment. */
2200 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2203 dwarf2out_args_size_adjust (offset, label);
2209 gcc_assert (GET_CODE (expr) == SET);
2211 src = SET_SRC (expr);
2212 dest = SET_DEST (expr);
2216 rtx rsi = reg_saved_in (src);
2221 fde = current_fde ();
2225 && fde->drap_reg == REGNO (src)
2226 && (fde->drap_reg_saved
2230 /* If we are saving dynamic realign argument pointer to a
2231 register, the destination is virtual dynamic realign
2232 argument pointer. It may be used to access argument. */
2235 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2236 fde->vdrap_reg = REGNO (dest);
2241 switch (GET_CODE (dest))
2244 switch (GET_CODE (src))
2246 /* Setting FP from SP. */
2248 if (cfa.reg == (unsigned) REGNO (src))
2251 /* Update the CFA rule wrt SP or FP. Make sure src is
2252 relative to the current CFA register.
2254 We used to require that dest be either SP or FP, but the
2255 ARM copies SP to a temporary register, and from there to
2256 FP. So we just rely on the backends to only set
2257 RTX_FRAME_RELATED_P on appropriate insns. */
2258 cfa.reg = REGNO (dest);
2259 cfa_temp.reg = cfa.reg;
2260 cfa_temp.offset = cfa.offset;
2264 /* Saving a register in a register. */
2265 gcc_assert (!fixed_regs [REGNO (dest)]
2266 /* For the SPARC and its register window. */
2267 || (DWARF_FRAME_REGNUM (REGNO (src))
2268 == DWARF_FRAME_RETURN_COLUMN));
2270 /* After stack is aligned, we can only save SP in FP
2271 if drap register is used. In this case, we have
2272 to restore stack pointer with the CFA value and we
2273 don't generate this DWARF information. */
2275 && fde->stack_realign
2276 && REGNO (src) == STACK_POINTER_REGNUM)
2277 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2278 && fde->drap_reg != INVALID_REGNUM
2279 && cfa.reg != REGNO (src));
2281 queue_reg_save (label, src, dest, 0);
2288 if (dest == stack_pointer_rtx)
2292 switch (GET_CODE (XEXP (src, 1)))
2295 offset = INTVAL (XEXP (src, 1));
2298 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2300 offset = cfa_temp.offset;
2306 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2308 /* Restoring SP from FP in the epilogue. */
2309 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2310 cfa.reg = STACK_POINTER_REGNUM;
2312 else if (GET_CODE (src) == LO_SUM)
2313 /* Assume we've set the source reg of the LO_SUM from sp. */
2316 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2318 if (GET_CODE (src) != MINUS)
2320 if (cfa.reg == STACK_POINTER_REGNUM)
2321 cfa.offset += offset;
2322 if (cfa_store.reg == STACK_POINTER_REGNUM)
2323 cfa_store.offset += offset;
2325 else if (dest == hard_frame_pointer_rtx)
2328 /* Either setting the FP from an offset of the SP,
2329 or adjusting the FP */
2330 gcc_assert (frame_pointer_needed);
2332 gcc_assert (REG_P (XEXP (src, 0))
2333 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2334 && CONST_INT_P (XEXP (src, 1)));
2335 offset = INTVAL (XEXP (src, 1));
2336 if (GET_CODE (src) != MINUS)
2338 cfa.offset += offset;
2339 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2343 gcc_assert (GET_CODE (src) != MINUS);
2346 if (REG_P (XEXP (src, 0))
2347 && REGNO (XEXP (src, 0)) == cfa.reg
2348 && CONST_INT_P (XEXP (src, 1)))
2350 /* Setting a temporary CFA register that will be copied
2351 into the FP later on. */
2352 offset = - INTVAL (XEXP (src, 1));
2353 cfa.offset += offset;
2354 cfa.reg = REGNO (dest);
2355 /* Or used to save regs to the stack. */
2356 cfa_temp.reg = cfa.reg;
2357 cfa_temp.offset = cfa.offset;
2361 else if (REG_P (XEXP (src, 0))
2362 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2363 && XEXP (src, 1) == stack_pointer_rtx)
2365 /* Setting a scratch register that we will use instead
2366 of SP for saving registers to the stack. */
2367 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2368 cfa_store.reg = REGNO (dest);
2369 cfa_store.offset = cfa.offset - cfa_temp.offset;
2373 else if (GET_CODE (src) == LO_SUM
2374 && CONST_INT_P (XEXP (src, 1)))
2376 cfa_temp.reg = REGNO (dest);
2377 cfa_temp.offset = INTVAL (XEXP (src, 1));
2386 cfa_temp.reg = REGNO (dest);
2387 cfa_temp.offset = INTVAL (src);
2392 gcc_assert (REG_P (XEXP (src, 0))
2393 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2394 && CONST_INT_P (XEXP (src, 1)));
2396 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2397 cfa_temp.reg = REGNO (dest);
2398 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2401 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2402 which will fill in all of the bits. */
2409 case UNSPEC_VOLATILE:
2410 gcc_assert (targetm.dwarf_handle_frame_unspec);
2411 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2416 /* If this AND operation happens on stack pointer in prologue,
2417 we assume the stack is realigned and we extract the
2419 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2421 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2422 fde->stack_realign = 1;
2423 fde->stack_realignment = INTVAL (XEXP (src, 1));
2424 cfa_store.offset = 0;
2426 if (cfa.reg != STACK_POINTER_REGNUM
2427 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2428 fde->drap_reg = cfa.reg;
2436 def_cfa_1 (label, &cfa);
2441 /* Saving a register to the stack. Make sure dest is relative to the
2443 switch (GET_CODE (XEXP (dest, 0)))
2448 /* We can't handle variable size modifications. */
2449 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2451 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2453 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2454 && cfa_store.reg == STACK_POINTER_REGNUM);
2456 cfa_store.offset += offset;
2457 if (cfa.reg == STACK_POINTER_REGNUM)
2458 cfa.offset = cfa_store.offset;
2460 offset = -cfa_store.offset;
2466 offset = GET_MODE_SIZE (GET_MODE (dest));
2467 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2470 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2471 == STACK_POINTER_REGNUM)
2472 && cfa_store.reg == STACK_POINTER_REGNUM);
2474 cfa_store.offset += offset;
2476 /* Rule 18: If stack is aligned, we will use FP as a
2477 reference to represent the address of the stored
2480 && fde->stack_realign
2481 && src == hard_frame_pointer_rtx)
2483 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2484 cfa_store.offset = 0;
2487 if (cfa.reg == STACK_POINTER_REGNUM)
2488 cfa.offset = cfa_store.offset;
2490 offset = -cfa_store.offset;
2494 /* With an offset. */
2501 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2502 && REG_P (XEXP (XEXP (dest, 0), 0)));
2503 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2504 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2507 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2509 if (cfa_store.reg == (unsigned) regno)
2510 offset -= cfa_store.offset;
2513 gcc_assert (cfa_temp.reg == (unsigned) regno);
2514 offset -= cfa_temp.offset;
2520 /* Without an offset. */
2523 int regno = REGNO (XEXP (dest, 0));
2525 if (cfa_store.reg == (unsigned) regno)
2526 offset = -cfa_store.offset;
2529 gcc_assert (cfa_temp.reg == (unsigned) regno);
2530 offset = -cfa_temp.offset;
2537 gcc_assert (cfa_temp.reg
2538 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2539 offset = -cfa_temp.offset;
2540 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2548 /* If the source operand of this MEM operation is not a
2549 register, basically the source is return address. Here
2550 we only care how much stack grew and we don't save it. */
2554 if (REGNO (src) != STACK_POINTER_REGNUM
2555 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2556 && (unsigned) REGNO (src) == cfa.reg)
2558 /* We're storing the current CFA reg into the stack. */
2560 if (cfa.offset == 0)
2563 /* If stack is aligned, putting CFA reg into stack means
2564 we can no longer use reg + offset to represent CFA.
2565 Here we use DW_CFA_def_cfa_expression instead. The
2566 result of this expression equals to the original CFA
2569 && fde->stack_realign
2570 && cfa.indirect == 0
2571 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2573 dw_cfa_location cfa_exp;
2575 gcc_assert (fde->drap_reg == cfa.reg);
2577 cfa_exp.indirect = 1;
2578 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2579 cfa_exp.base_offset = offset;
2582 fde->drap_reg_saved = 1;
2584 def_cfa_1 (label, &cfa_exp);
2588 /* If the source register is exactly the CFA, assume
2589 we're saving SP like any other register; this happens
2591 def_cfa_1 (label, &cfa);
2592 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2597 /* Otherwise, we'll need to look in the stack to
2598 calculate the CFA. */
2599 rtx x = XEXP (dest, 0);
2603 gcc_assert (REG_P (x));
2605 cfa.reg = REGNO (x);
2606 cfa.base_offset = offset;
2608 def_cfa_1 (label, &cfa);
2613 def_cfa_1 (label, &cfa);
2615 span = targetm.dwarf_register_span (src);
2618 queue_reg_save (label, src, NULL_RTX, offset);
2621 /* We have a PARALLEL describing where the contents of SRC
2622 live. Queue register saves for each piece of the
2626 HOST_WIDE_INT span_offset = offset;
2628 gcc_assert (GET_CODE (span) == PARALLEL);
2630 limit = XVECLEN (span, 0);
2631 for (par_index = 0; par_index < limit; par_index++)
2633 rtx elem = XVECEXP (span, 0, par_index);
2635 queue_reg_save (label, elem, NULL_RTX, span_offset);
2636 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2647 /* Record call frame debugging information for INSN, which either
2648 sets SP or FP (adjusting how we calculate the frame address) or saves a
2649 register to the stack. If INSN is NULL_RTX, initialize our state.
2651 If AFTER_P is false, we're being called before the insn is emitted,
2652 otherwise after. Call instructions get invoked twice. */
2655 dwarf2out_frame_debug (rtx insn, bool after_p)
2659 bool handled_one = false;
2661 if (insn == NULL_RTX)
2665 /* Flush any queued register saves. */
2666 flush_queued_reg_saves ();
2668 /* Set up state for generating call frame debug info. */
2671 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2673 cfa.reg = STACK_POINTER_REGNUM;
2676 cfa_temp.offset = 0;
2678 for (i = 0; i < num_regs_saved_in_regs; i++)
2680 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2681 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2683 num_regs_saved_in_regs = 0;
2685 if (barrier_args_size)
2687 XDELETEVEC (barrier_args_size);
2688 barrier_args_size = NULL;
2693 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2694 flush_queued_reg_saves ();
2696 if (! RTX_FRAME_RELATED_P (insn))
2698 if (!ACCUMULATE_OUTGOING_ARGS)
2699 dwarf2out_stack_adjust (insn, after_p);
2703 label = dwarf2out_cfi_label (false);
2705 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2706 switch (REG_NOTE_KIND (note))
2708 case REG_FRAME_RELATED_EXPR:
2709 insn = XEXP (note, 0);
2712 case REG_CFA_DEF_CFA:
2713 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2717 case REG_CFA_ADJUST_CFA:
2722 if (GET_CODE (n) == PARALLEL)
2723 n = XVECEXP (n, 0, 0);
2725 dwarf2out_frame_debug_adjust_cfa (n, label);
2729 case REG_CFA_OFFSET:
2732 n = single_set (insn);
2733 dwarf2out_frame_debug_cfa_offset (n, label);
2737 case REG_CFA_REGISTER:
2742 if (GET_CODE (n) == PARALLEL)
2743 n = XVECEXP (n, 0, 0);
2745 dwarf2out_frame_debug_cfa_register (n, label);
2749 case REG_CFA_RESTORE:
2754 if (GET_CODE (n) == PARALLEL)
2755 n = XVECEXP (n, 0, 0);
2758 dwarf2out_frame_debug_cfa_restore (n, label);
2768 insn = PATTERN (insn);
2770 dwarf2out_frame_debug_expr (insn, label);
2773 /* Determine if we need to save and restore CFI information around this
2774 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2775 we do need to save/restore, then emit the save now, and insert a
2776 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2779 dwarf2out_begin_epilogue (rtx insn)
2781 bool saw_frp = false;
2784 /* Scan forward to the return insn, noticing if there are possible
2785 frame related insns. */
2786 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2791 /* Look for both regular and sibcalls to end the block. */
2792 if (returnjump_p (i))
2794 if (CALL_P (i) && SIBLING_CALL_P (i))
2797 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2800 rtx seq = PATTERN (i);
2802 if (returnjump_p (XVECEXP (seq, 0, 0)))
2804 if (CALL_P (XVECEXP (seq, 0, 0))
2805 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2808 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2809 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2813 if (RTX_FRAME_RELATED_P (i))
2817 /* If the port doesn't emit epilogue unwind info, we don't need a
2818 save/restore pair. */
2822 /* Otherwise, search forward to see if the return insn was the last
2823 basic block of the function. If so, we don't need save/restore. */
2824 gcc_assert (i != NULL);
2825 i = next_real_insn (i);
2829 /* Insert the restore before that next real insn in the stream, and before
2830 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2831 properly nested. This should be after any label or alignment. This
2832 will be pushed into the CFI stream by the function below. */
2835 rtx p = PREV_INSN (i);
2838 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
2842 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
2844 emit_cfa_remember = true;
2846 /* And emulate the state save. */
2847 gcc_assert (!cfa_remember.in_use);
2849 cfa_remember.in_use = 1;
2852 /* A "subroutine" of dwarf2out_begin_epilogue. Emit the restore required. */
2855 dwarf2out_frame_debug_restore_state (void)
2857 dw_cfi_ref cfi = new_cfi ();
2858 const char *label = dwarf2out_cfi_label (false);
2860 cfi->dw_cfi_opc = DW_CFA_restore_state;
2861 add_fde_cfi (label, cfi);
2863 gcc_assert (cfa_remember.in_use);
2865 cfa_remember.in_use = 0;
2870 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2871 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2872 (enum dwarf_call_frame_info cfi);
2874 static enum dw_cfi_oprnd_type
2875 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2880 case DW_CFA_GNU_window_save:
2881 case DW_CFA_remember_state:
2882 case DW_CFA_restore_state:
2883 return dw_cfi_oprnd_unused;
2885 case DW_CFA_set_loc:
2886 case DW_CFA_advance_loc1:
2887 case DW_CFA_advance_loc2:
2888 case DW_CFA_advance_loc4:
2889 case DW_CFA_MIPS_advance_loc8:
2890 return dw_cfi_oprnd_addr;
2893 case DW_CFA_offset_extended:
2894 case DW_CFA_def_cfa:
2895 case DW_CFA_offset_extended_sf:
2896 case DW_CFA_def_cfa_sf:
2897 case DW_CFA_restore:
2898 case DW_CFA_restore_extended:
2899 case DW_CFA_undefined:
2900 case DW_CFA_same_value:
2901 case DW_CFA_def_cfa_register:
2902 case DW_CFA_register:
2903 return dw_cfi_oprnd_reg_num;
2905 case DW_CFA_def_cfa_offset:
2906 case DW_CFA_GNU_args_size:
2907 case DW_CFA_def_cfa_offset_sf:
2908 return dw_cfi_oprnd_offset;
2910 case DW_CFA_def_cfa_expression:
2911 case DW_CFA_expression:
2912 return dw_cfi_oprnd_loc;
2919 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2920 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2921 (enum dwarf_call_frame_info cfi);
2923 static enum dw_cfi_oprnd_type
2924 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2928 case DW_CFA_def_cfa:
2929 case DW_CFA_def_cfa_sf:
2931 case DW_CFA_offset_extended_sf:
2932 case DW_CFA_offset_extended:
2933 return dw_cfi_oprnd_offset;
2935 case DW_CFA_register:
2936 return dw_cfi_oprnd_reg_num;
2939 return dw_cfi_oprnd_unused;
2943 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2945 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
2946 switch to the data section instead, and write out a synthetic start label
2947 for collect2 the first time around. */
2950 switch_to_eh_frame_section (bool back)
2954 #ifdef EH_FRAME_SECTION_NAME
2955 if (eh_frame_section == 0)
2959 if (EH_TABLES_CAN_BE_READ_ONLY)
2965 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2967 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2969 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2971 flags = ((! flag_pic
2972 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2973 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2974 && (per_encoding & 0x70) != DW_EH_PE_absptr
2975 && (per_encoding & 0x70) != DW_EH_PE_aligned
2976 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2977 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2978 ? 0 : SECTION_WRITE);
2981 flags = SECTION_WRITE;
2982 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2986 if (eh_frame_section)
2987 switch_to_section (eh_frame_section);
2990 /* We have no special eh_frame section. Put the information in
2991 the data section and emit special labels to guide collect2. */
2992 switch_to_section (data_section);
2996 label = get_file_function_name ("F");
2997 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2998 targetm.asm_out.globalize_label (asm_out_file,
2999 IDENTIFIER_POINTER (label));
3000 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3005 /* Switch [BACK] to the eh or debug frame table section, depending on
3009 switch_to_frame_table_section (int for_eh, bool back)
3012 switch_to_eh_frame_section (back);
3015 if (!debug_frame_section)
3016 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3017 SECTION_DEBUG, NULL);
3018 switch_to_section (debug_frame_section);
3022 /* Output a Call Frame Information opcode and its operand(s). */
3025 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3030 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3031 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3032 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3033 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3034 ((unsigned HOST_WIDE_INT)
3035 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3036 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3038 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3039 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3040 "DW_CFA_offset, column 0x%lx", r);
3041 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3042 dw2_asm_output_data_uleb128 (off, NULL);
3044 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3046 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3047 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3048 "DW_CFA_restore, column 0x%lx", r);
3052 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3053 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3055 switch (cfi->dw_cfi_opc)
3057 case DW_CFA_set_loc:
3059 dw2_asm_output_encoded_addr_rtx (
3060 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3061 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3064 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3065 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3066 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3069 case DW_CFA_advance_loc1:
3070 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3071 fde->dw_fde_current_label, NULL);
3072 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3075 case DW_CFA_advance_loc2:
3076 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3077 fde->dw_fde_current_label, NULL);
3078 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3081 case DW_CFA_advance_loc4:
3082 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3083 fde->dw_fde_current_label, NULL);
3084 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3087 case DW_CFA_MIPS_advance_loc8:
3088 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3089 fde->dw_fde_current_label, NULL);
3090 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3093 case DW_CFA_offset_extended:
3094 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3095 dw2_asm_output_data_uleb128 (r, NULL);
3096 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3097 dw2_asm_output_data_uleb128 (off, NULL);
3100 case DW_CFA_def_cfa:
3101 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3102 dw2_asm_output_data_uleb128 (r, NULL);
3103 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3106 case DW_CFA_offset_extended_sf:
3107 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3108 dw2_asm_output_data_uleb128 (r, NULL);
3109 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3110 dw2_asm_output_data_sleb128 (off, NULL);
3113 case DW_CFA_def_cfa_sf:
3114 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3115 dw2_asm_output_data_uleb128 (r, NULL);
3116 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3117 dw2_asm_output_data_sleb128 (off, NULL);
3120 case DW_CFA_restore_extended:
3121 case DW_CFA_undefined:
3122 case DW_CFA_same_value:
3123 case DW_CFA_def_cfa_register:
3124 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3125 dw2_asm_output_data_uleb128 (r, NULL);
3128 case DW_CFA_register:
3129 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3130 dw2_asm_output_data_uleb128 (r, NULL);
3131 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3132 dw2_asm_output_data_uleb128 (r, NULL);
3135 case DW_CFA_def_cfa_offset:
3136 case DW_CFA_GNU_args_size:
3137 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3140 case DW_CFA_def_cfa_offset_sf:
3141 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3142 dw2_asm_output_data_sleb128 (off, NULL);
3145 case DW_CFA_GNU_window_save:
3148 case DW_CFA_def_cfa_expression:
3149 case DW_CFA_expression:
3150 output_cfa_loc (cfi);
3153 case DW_CFA_GNU_negative_offset_extended:
3154 /* Obsoleted by DW_CFA_offset_extended_sf. */
3163 /* Similar, but do it via assembler directives instead. */
3166 output_cfi_directive (dw_cfi_ref cfi)
3168 unsigned long r, r2;
3170 switch (cfi->dw_cfi_opc)
3172 case DW_CFA_advance_loc:
3173 case DW_CFA_advance_loc1:
3174 case DW_CFA_advance_loc2:
3175 case DW_CFA_advance_loc4:
3176 case DW_CFA_MIPS_advance_loc8:
3177 case DW_CFA_set_loc:
3178 /* Should only be created by add_fde_cfi in a code path not
3179 followed when emitting via directives. The assembler is
3180 going to take care of this for us. */
3184 case DW_CFA_offset_extended:
3185 case DW_CFA_offset_extended_sf:
3186 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3187 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3188 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3191 case DW_CFA_restore:
3192 case DW_CFA_restore_extended:
3193 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3194 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3197 case DW_CFA_undefined:
3198 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3199 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3202 case DW_CFA_same_value:
3203 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3204 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3207 case DW_CFA_def_cfa:
3208 case DW_CFA_def_cfa_sf:
3209 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3210 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3211 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3214 case DW_CFA_def_cfa_register:
3215 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3216 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3219 case DW_CFA_register:
3220 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3221 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3222 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3225 case DW_CFA_def_cfa_offset:
3226 case DW_CFA_def_cfa_offset_sf:
3227 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3228 HOST_WIDE_INT_PRINT_DEC"\n",
3229 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3232 case DW_CFA_remember_state:
3233 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3235 case DW_CFA_restore_state:
3236 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3239 case DW_CFA_GNU_args_size:
3240 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size);
3241 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3243 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3244 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3245 fputc ('\n', asm_out_file);
3248 case DW_CFA_GNU_window_save:
3249 fprintf (asm_out_file, "\t.cfi_window_save\n");
3252 case DW_CFA_def_cfa_expression:
3253 case DW_CFA_expression:
3254 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", cfi->dw_cfi_opc);
3255 output_cfa_loc_raw (cfi);
3256 fputc ('\n', asm_out_file);
3264 DEF_VEC_P (dw_cfi_ref);
3265 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3267 /* Output CFIs to bring current FDE to the same state as after executing
3268 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3269 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3270 other arguments to pass to output_cfi. */
3273 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3275 struct dw_cfi_struct cfi_buf;
3277 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3278 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3279 unsigned int len, idx;
3281 for (;; cfi = cfi->dw_cfi_next)
3282 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3284 case DW_CFA_advance_loc:
3285 case DW_CFA_advance_loc1:
3286 case DW_CFA_advance_loc2:
3287 case DW_CFA_advance_loc4:
3288 case DW_CFA_MIPS_advance_loc8:
3289 case DW_CFA_set_loc:
3290 /* All advances should be ignored. */
3292 case DW_CFA_remember_state:
3294 dw_cfi_ref args_size = cfi_args_size;
3296 /* Skip everything between .cfi_remember_state and
3297 .cfi_restore_state. */
3298 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3299 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3301 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3304 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3311 cfi_args_size = args_size;
3315 case DW_CFA_GNU_args_size:
3316 cfi_args_size = cfi;
3318 case DW_CFA_GNU_window_save:
3321 case DW_CFA_offset_extended:
3322 case DW_CFA_offset_extended_sf:
3323 case DW_CFA_restore:
3324 case DW_CFA_restore_extended:
3325 case DW_CFA_undefined:
3326 case DW_CFA_same_value:
3327 case DW_CFA_register:
3328 case DW_CFA_val_offset:
3329 case DW_CFA_val_offset_sf:
3330 case DW_CFA_expression:
3331 case DW_CFA_val_expression:
3332 case DW_CFA_GNU_negative_offset_extended:
3333 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3334 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3335 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3336 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3338 case DW_CFA_def_cfa:
3339 case DW_CFA_def_cfa_sf:
3340 case DW_CFA_def_cfa_expression:
3342 cfi_cfa_offset = cfi;
3344 case DW_CFA_def_cfa_register:
3347 case DW_CFA_def_cfa_offset:
3348 case DW_CFA_def_cfa_offset_sf:
3349 cfi_cfa_offset = cfi;
3352 gcc_assert (cfi == NULL);
3354 len = VEC_length (dw_cfi_ref, regs);
3355 for (idx = 0; idx < len; idx++)
3357 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3359 && cfi2->dw_cfi_opc != DW_CFA_restore
3360 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3363 output_cfi_directive (cfi2);
3365 output_cfi (cfi2, fde, for_eh);
3368 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3370 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3372 switch (cfi_cfa_offset->dw_cfi_opc)
3374 case DW_CFA_def_cfa_offset:
3375 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3376 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3378 case DW_CFA_def_cfa_offset_sf:
3379 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3380 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3382 case DW_CFA_def_cfa:
3383 case DW_CFA_def_cfa_sf:
3384 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3385 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3392 else if (cfi_cfa_offset)
3393 cfi_cfa = cfi_cfa_offset;
3397 output_cfi_directive (cfi_cfa);
3399 output_cfi (cfi_cfa, fde, for_eh);
3402 cfi_cfa_offset = NULL;
3404 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3407 output_cfi_directive (cfi_args_size);
3409 output_cfi (cfi_args_size, fde, for_eh);
3411 cfi_args_size = NULL;
3414 VEC_free (dw_cfi_ref, heap, regs);
3417 else if (do_cfi_asm)
3418 output_cfi_directive (cfi);
3420 output_cfi (cfi, fde, for_eh);
3427 /* Output one FDE. */
3430 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3431 char *section_start_label, int fde_encoding, char *augmentation,
3432 bool any_lsda_needed, int lsda_encoding)
3434 const char *begin, *end;
3435 static unsigned int j;
3436 char l1[20], l2[20];
3439 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh,
3441 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3443 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3444 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3445 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3446 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3447 " indicating 64-bit DWARF extension");
3448 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3450 ASM_OUTPUT_LABEL (asm_out_file, l1);
3453 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3455 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3456 debug_frame_section, "FDE CIE offset");
3458 if (!fde->dw_fde_switched_sections)
3460 begin = fde->dw_fde_begin;
3461 end = fde->dw_fde_end;
3465 /* For the first section, prefer dw_fde_begin over
3466 dw_fde_{hot,cold}_section_label, as the latter
3467 might be separated from the real start of the
3468 function by alignment padding. */
3470 begin = fde->dw_fde_begin;
3471 else if (fde->dw_fde_switched_cold_to_hot)
3472 begin = fde->dw_fde_hot_section_label;
3474 begin = fde->dw_fde_unlikely_section_label;
3475 if (second ^ fde->dw_fde_switched_cold_to_hot)
3476 end = fde->dw_fde_unlikely_section_end_label;
3478 end = fde->dw_fde_hot_section_end_label;
3483 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3484 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3485 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3486 "FDE initial location");
3487 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3488 end, begin, "FDE address range");
3492 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3493 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3496 if (augmentation[0])
3498 if (any_lsda_needed)
3500 int size = size_of_encoded_value (lsda_encoding);
3502 if (lsda_encoding == DW_EH_PE_aligned)
3504 int offset = ( 4 /* Length */
3505 + 4 /* CIE offset */
3506 + 2 * size_of_encoded_value (fde_encoding)
3507 + 1 /* Augmentation size */ );
3508 int pad = -offset & (PTR_SIZE - 1);
3511 gcc_assert (size_of_uleb128 (size) == 1);
3514 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3516 if (fde->uses_eh_lsda)
3518 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3519 fde->funcdef_number);
3520 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3521 gen_rtx_SYMBOL_REF (Pmode, l1),
3523 "Language Specific Data Area");
3527 if (lsda_encoding == DW_EH_PE_aligned)
3528 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3529 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3530 "Language Specific Data Area (none)");
3534 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3537 /* Loop through the Call Frame Instructions associated with
3539 fde->dw_fde_current_label = begin;
3540 if (!fde->dw_fde_switched_sections)
3541 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3542 output_cfi (cfi, fde, for_eh);
3545 if (fde->dw_fde_switch_cfi)
3546 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3548 output_cfi (cfi, fde, for_eh);
3549 if (cfi == fde->dw_fde_switch_cfi)
3555 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3557 if (fde->dw_fde_switch_cfi)
3559 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3560 fde->dw_fde_switch_cfi->dw_cfi_next = NUL