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 #ifdef DWARF2_DEBUGGING_INFO
94 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
96 static rtx last_var_location_insn;
99 #ifdef VMS_DEBUGGING_INFO
100 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
102 /* Define this macro to be a nonzero value if the directory specifications
103 which are output in the debug info should end with a separator. */
104 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
105 /* Define this macro to evaluate to a nonzero value if GCC should refrain
106 from generating indirect strings in DWARF2 debug information, for instance
107 if your target is stuck with an old version of GDB that is unable to
108 process them properly or uses VMS Debug. */
109 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
111 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
112 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
115 #ifndef DWARF2_FRAME_INFO
116 # ifdef DWARF2_DEBUGGING_INFO
117 # define DWARF2_FRAME_INFO \
118 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
120 # define DWARF2_FRAME_INFO 0
124 /* Map register numbers held in the call frame info that gcc has
125 collected using DWARF_FRAME_REGNUM to those that should be output in
126 .debug_frame and .eh_frame. */
127 #ifndef DWARF2_FRAME_REG_OUT
128 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
131 /* Save the result of dwarf2out_do_frame across PCH. */
132 static GTY(()) bool saved_do_cfi_asm = 0;
134 /* Decide whether we want to emit frame unwind information for the current
138 dwarf2out_do_frame (void)
140 /* We want to emit correct CFA location expressions or lists, so we
141 have to return true if we're going to output debug info, even if
142 we're not going to output frame or unwind info. */
143 return (write_symbols == DWARF2_DEBUG
144 || write_symbols == VMS_AND_DWARF2_DEBUG
145 || DWARF2_FRAME_INFO || saved_do_cfi_asm
146 #ifdef DWARF2_UNWIND_INFO
147 || (DWARF2_UNWIND_INFO
148 && (flag_unwind_tables
149 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
154 /* Decide whether to emit frame unwind via assembler directives. */
157 dwarf2out_do_cfi_asm (void)
161 #ifdef MIPS_DEBUGGING_INFO
164 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
166 if (saved_do_cfi_asm || !eh_personality_libfunc)
168 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
171 /* Make sure the personality encoding is one the assembler can support.
172 In particular, aligned addresses can't be handled. */
173 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
174 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
176 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
177 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
180 saved_do_cfi_asm = true;
184 /* The size of the target's pointer type. */
186 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
189 /* Array of RTXes referenced by the debugging information, which therefore
190 must be kept around forever. */
191 static GTY(()) VEC(rtx,gc) *used_rtx_array;
193 /* A pointer to the base of a list of incomplete types which might be
194 completed at some later time. incomplete_types_list needs to be a
195 VEC(tree,gc) because we want to tell the garbage collector about
197 static GTY(()) VEC(tree,gc) *incomplete_types;
199 /* A pointer to the base of a table of references to declaration
200 scopes. This table is a display which tracks the nesting
201 of declaration scopes at the current scope and containing
202 scopes. This table is used to find the proper place to
203 define type declaration DIE's. */
204 static GTY(()) VEC(tree,gc) *decl_scope_table;
206 /* Pointers to various DWARF2 sections. */
207 static GTY(()) section *debug_info_section;
208 static GTY(()) section *debug_abbrev_section;
209 static GTY(()) section *debug_aranges_section;
210 static GTY(()) section *debug_macinfo_section;
211 static GTY(()) section *debug_line_section;
212 static GTY(()) section *debug_loc_section;
213 static GTY(()) section *debug_pubnames_section;
214 static GTY(()) section *debug_pubtypes_section;
215 static GTY(()) section *debug_str_section;
216 static GTY(()) section *debug_ranges_section;
217 static GTY(()) section *debug_frame_section;
219 /* How to start an assembler comment. */
220 #ifndef ASM_COMMENT_START
221 #define ASM_COMMENT_START ";#"
224 typedef struct dw_cfi_struct *dw_cfi_ref;
225 typedef struct dw_fde_struct *dw_fde_ref;
226 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
228 /* Call frames are described using a sequence of Call Frame
229 Information instructions. The register number, offset
230 and address fields are provided as possible operands;
231 their use is selected by the opcode field. */
233 enum dw_cfi_oprnd_type {
235 dw_cfi_oprnd_reg_num,
241 typedef union GTY(()) dw_cfi_oprnd_struct {
242 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
243 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
244 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
245 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
249 typedef struct GTY(()) dw_cfi_struct {
250 dw_cfi_ref dw_cfi_next;
251 enum dwarf_call_frame_info dw_cfi_opc;
252 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
254 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
259 /* This is how we define the location of the CFA. We use to handle it
260 as REG + OFFSET all the time, but now it can be more complex.
261 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
262 Instead of passing around REG and OFFSET, we pass a copy
263 of this structure. */
264 typedef struct GTY(()) cfa_loc {
265 HOST_WIDE_INT offset;
266 HOST_WIDE_INT base_offset;
268 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
269 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
272 /* All call frame descriptions (FDE's) in the GCC generated DWARF
273 refer to a single Common Information Entry (CIE), defined at
274 the beginning of the .debug_frame section. This use of a single
275 CIE obviates the need to keep track of multiple CIE's
276 in the DWARF generation routines below. */
278 typedef struct GTY(()) dw_fde_struct {
280 const char *dw_fde_begin;
281 const char *dw_fde_current_label;
282 const char *dw_fde_end;
283 const char *dw_fde_hot_section_label;
284 const char *dw_fde_hot_section_end_label;
285 const char *dw_fde_unlikely_section_label;
286 const char *dw_fde_unlikely_section_end_label;
287 dw_cfi_ref dw_fde_cfi;
288 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
289 unsigned funcdef_number;
290 HOST_WIDE_INT stack_realignment;
291 /* Dynamic realign argument pointer register. */
292 unsigned int drap_reg;
293 /* Virtual dynamic realign argument pointer register. */
294 unsigned int vdrap_reg;
295 unsigned all_throwers_are_sibcalls : 1;
296 unsigned nothrow : 1;
297 unsigned uses_eh_lsda : 1;
298 /* Whether we did stack realign in this call frame. */
299 unsigned stack_realign : 1;
300 /* Whether dynamic realign argument pointer register has been saved. */
301 unsigned drap_reg_saved: 1;
302 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
303 unsigned in_std_section : 1;
304 /* True iff dw_fde_unlikely_section_label is in text_section or
305 cold_text_section. */
306 unsigned cold_in_std_section : 1;
307 /* True iff switched sections. */
308 unsigned dw_fde_switched_sections : 1;
309 /* True iff switching from cold to hot section. */
310 unsigned dw_fde_switched_cold_to_hot : 1;
314 /* Maximum size (in bytes) of an artificially generated label. */
315 #define MAX_ARTIFICIAL_LABEL_BYTES 30
317 /* The size of addresses as they appear in the Dwarf 2 data.
318 Some architectures use word addresses to refer to code locations,
319 but Dwarf 2 info always uses byte addresses. On such machines,
320 Dwarf 2 addresses need to be larger than the architecture's
322 #ifndef DWARF2_ADDR_SIZE
323 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
326 /* The size in bytes of a DWARF field indicating an offset or length
327 relative to a debug info section, specified to be 4 bytes in the
328 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
331 #ifndef DWARF_OFFSET_SIZE
332 #define DWARF_OFFSET_SIZE 4
335 /* According to the (draft) DWARF 3 specification, the initial length
336 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
337 bytes are 0xffffffff, followed by the length stored in the next 8
340 However, the SGI/MIPS ABI uses an initial length which is equal to
341 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
343 #ifndef DWARF_INITIAL_LENGTH_SIZE
344 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
347 /* Round SIZE up to the nearest BOUNDARY. */
348 #define DWARF_ROUND(SIZE,BOUNDARY) \
349 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
351 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
352 #ifndef DWARF_CIE_DATA_ALIGNMENT
353 #ifdef STACK_GROWS_DOWNWARD
354 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
356 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
360 /* CIE identifier. */
361 #if HOST_BITS_PER_WIDE_INT >= 64
362 #define DWARF_CIE_ID \
363 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
365 #define DWARF_CIE_ID DW_CIE_ID
368 /* A pointer to the base of a table that contains frame description
369 information for each routine. */
370 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
372 /* Number of elements currently allocated for fde_table. */
373 static GTY(()) unsigned fde_table_allocated;
375 /* Number of elements in fde_table currently in use. */
376 static GTY(()) unsigned fde_table_in_use;
378 /* Size (in elements) of increments by which we may expand the
380 #define FDE_TABLE_INCREMENT 256
382 /* Get the current fde_table entry we should use. */
384 static inline dw_fde_ref
387 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
390 /* A list of call frame insns for the CIE. */
391 static GTY(()) dw_cfi_ref cie_cfi_head;
393 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
394 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
395 attribute that accelerates the lookup of the FDE associated
396 with the subprogram. This variable holds the table index of the FDE
397 associated with the current function (body) definition. */
398 static unsigned current_funcdef_fde;
401 struct GTY(()) indirect_string_node {
403 unsigned int refcount;
404 enum dwarf_form form;
408 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
410 static GTY(()) int dw2_string_counter;
411 static GTY(()) unsigned long dwarf2out_cfi_label_num;
413 /* True if the compilation unit places functions in more than one section. */
414 static GTY(()) bool have_multiple_function_sections = false;
416 /* Whether the default text and cold text sections have been used at all. */
418 static GTY(()) bool text_section_used = false;
419 static GTY(()) bool cold_text_section_used = false;
421 /* The default cold text section. */
422 static GTY(()) section *cold_text_section;
424 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
426 /* Forward declarations for functions defined in this file. */
428 static char *stripattributes (const char *);
429 static const char *dwarf_cfi_name (unsigned);
430 static dw_cfi_ref new_cfi (void);
431 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
432 static void add_fde_cfi (const char *, dw_cfi_ref);
433 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
434 static void lookup_cfa (dw_cfa_location *);
435 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
436 #ifdef DWARF2_UNWIND_INFO
437 static void initial_return_save (rtx);
439 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
441 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
442 static void output_cfi_directive (dw_cfi_ref);
443 static void output_call_frame_info (int);
444 static void dwarf2out_note_section_used (void);
445 static void dwarf2out_stack_adjust (rtx, bool);
446 static void dwarf2out_args_size_adjust (HOST_WIDE_INT, const char *);
447 static void flush_queued_reg_saves (void);
448 static bool clobbers_queued_reg_save (const_rtx);
449 static void dwarf2out_frame_debug_expr (rtx, const char *);
451 /* Support for complex CFA locations. */
452 static void output_cfa_loc (dw_cfi_ref);
453 static void output_cfa_loc_raw (dw_cfi_ref);
454 static void get_cfa_from_loc_descr (dw_cfa_location *,
455 struct dw_loc_descr_struct *);
456 static struct dw_loc_descr_struct *build_cfa_loc
457 (dw_cfa_location *, HOST_WIDE_INT);
458 static struct dw_loc_descr_struct *build_cfa_aligned_loc
459 (HOST_WIDE_INT, HOST_WIDE_INT);
460 static void def_cfa_1 (const char *, dw_cfa_location *);
462 /* How to start an assembler comment. */
463 #ifndef ASM_COMMENT_START
464 #define ASM_COMMENT_START ";#"
467 /* Data and reference forms for relocatable data. */
468 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
469 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
471 #ifndef DEBUG_FRAME_SECTION
472 #define DEBUG_FRAME_SECTION ".debug_frame"
475 #ifndef FUNC_BEGIN_LABEL
476 #define FUNC_BEGIN_LABEL "LFB"
479 #ifndef FUNC_END_LABEL
480 #define FUNC_END_LABEL "LFE"
483 #ifndef FRAME_BEGIN_LABEL
484 #define FRAME_BEGIN_LABEL "Lframe"
486 #define CIE_AFTER_SIZE_LABEL "LSCIE"
487 #define CIE_END_LABEL "LECIE"
488 #define FDE_LABEL "LSFDE"
489 #define FDE_AFTER_SIZE_LABEL "LASFDE"
490 #define FDE_END_LABEL "LEFDE"
491 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
492 #define LINE_NUMBER_END_LABEL "LELT"
493 #define LN_PROLOG_AS_LABEL "LASLTP"
494 #define LN_PROLOG_END_LABEL "LELTP"
495 #define DIE_LABEL_PREFIX "DW"
497 /* The DWARF 2 CFA column which tracks the return address. Normally this
498 is the column for PC, or the first column after all of the hard
500 #ifndef DWARF_FRAME_RETURN_COLUMN
502 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
504 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
508 /* The mapping from gcc register number to DWARF 2 CFA column number. By
509 default, we just provide columns for all registers. */
510 #ifndef DWARF_FRAME_REGNUM
511 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
514 /* Hook used by __throw. */
517 expand_builtin_dwarf_sp_column (void)
519 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
520 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
523 /* Return a pointer to a copy of the section string name S with all
524 attributes stripped off, and an asterisk prepended (for assemble_name). */
527 stripattributes (const char *s)
529 char *stripped = XNEWVEC (char, strlen (s) + 2);
534 while (*s && *s != ',')
541 /* MEM is a memory reference for the register size table, each element of
542 which has mode MODE. Initialize column C as a return address column. */
545 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
547 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
548 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
549 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
552 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
554 static inline HOST_WIDE_INT
555 div_data_align (HOST_WIDE_INT off)
557 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
558 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
562 /* Return true if we need a signed version of a given opcode
563 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
566 need_data_align_sf_opcode (HOST_WIDE_INT off)
568 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
571 /* Generate code to initialize the register size table. */
574 expand_builtin_init_dwarf_reg_sizes (tree address)
577 enum machine_mode mode = TYPE_MODE (char_type_node);
578 rtx addr = expand_normal (address);
579 rtx mem = gen_rtx_MEM (BLKmode, addr);
580 bool wrote_return_column = false;
582 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
584 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
586 if (rnum < DWARF_FRAME_REGISTERS)
588 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
589 enum machine_mode save_mode = reg_raw_mode[i];
592 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
593 save_mode = choose_hard_reg_mode (i, 1, true);
594 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
596 if (save_mode == VOIDmode)
598 wrote_return_column = true;
600 size = GET_MODE_SIZE (save_mode);
604 emit_move_insn (adjust_address (mem, mode, offset),
605 gen_int_mode (size, mode));
609 if (!wrote_return_column)
610 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
612 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
613 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
616 targetm.init_dwarf_reg_sizes_extra (address);
619 /* Convert a DWARF call frame info. operation to its string name */
622 dwarf_cfi_name (unsigned int cfi_opc)
626 case DW_CFA_advance_loc:
627 return "DW_CFA_advance_loc";
629 return "DW_CFA_offset";
631 return "DW_CFA_restore";
635 return "DW_CFA_set_loc";
636 case DW_CFA_advance_loc1:
637 return "DW_CFA_advance_loc1";
638 case DW_CFA_advance_loc2:
639 return "DW_CFA_advance_loc2";
640 case DW_CFA_advance_loc4:
641 return "DW_CFA_advance_loc4";
642 case DW_CFA_offset_extended:
643 return "DW_CFA_offset_extended";
644 case DW_CFA_restore_extended:
645 return "DW_CFA_restore_extended";
646 case DW_CFA_undefined:
647 return "DW_CFA_undefined";
648 case DW_CFA_same_value:
649 return "DW_CFA_same_value";
650 case DW_CFA_register:
651 return "DW_CFA_register";
652 case DW_CFA_remember_state:
653 return "DW_CFA_remember_state";
654 case DW_CFA_restore_state:
655 return "DW_CFA_restore_state";
657 return "DW_CFA_def_cfa";
658 case DW_CFA_def_cfa_register:
659 return "DW_CFA_def_cfa_register";
660 case DW_CFA_def_cfa_offset:
661 return "DW_CFA_def_cfa_offset";
664 case DW_CFA_def_cfa_expression:
665 return "DW_CFA_def_cfa_expression";
666 case DW_CFA_expression:
667 return "DW_CFA_expression";
668 case DW_CFA_offset_extended_sf:
669 return "DW_CFA_offset_extended_sf";
670 case DW_CFA_def_cfa_sf:
671 return "DW_CFA_def_cfa_sf";
672 case DW_CFA_def_cfa_offset_sf:
673 return "DW_CFA_def_cfa_offset_sf";
675 /* SGI/MIPS specific */
676 case DW_CFA_MIPS_advance_loc8:
677 return "DW_CFA_MIPS_advance_loc8";
680 case DW_CFA_GNU_window_save:
681 return "DW_CFA_GNU_window_save";
682 case DW_CFA_GNU_args_size:
683 return "DW_CFA_GNU_args_size";
684 case DW_CFA_GNU_negative_offset_extended:
685 return "DW_CFA_GNU_negative_offset_extended";
688 return "DW_CFA_<unknown>";
692 /* Return a pointer to a newly allocated Call Frame Instruction. */
694 static inline dw_cfi_ref
697 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
699 cfi->dw_cfi_next = NULL;
700 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
701 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
706 /* Add a Call Frame Instruction to list of instructions. */
709 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
712 dw_fde_ref fde = current_fde ();
714 /* When DRAP is used, CFA is defined with an expression. Redefine
715 CFA may lead to a different CFA value. */
716 /* ??? Of course, this heuristic fails when we're annotating epilogues,
717 because of course we'll always want to redefine the CFA back to the
718 stack pointer on the way out. Where should we move this check? */
719 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
720 switch (cfi->dw_cfi_opc)
722 case DW_CFA_def_cfa_register:
723 case DW_CFA_def_cfa_offset:
724 case DW_CFA_def_cfa_offset_sf:
726 case DW_CFA_def_cfa_sf:
733 /* Find the end of the chain. */
734 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
740 /* Generate a new label for the CFI info to refer to. FORCE is true
741 if a label needs to be output even when using .cfi_* directives. */
744 dwarf2out_cfi_label (bool force)
746 static char label[20];
748 if (!force && dwarf2out_do_cfi_asm ())
750 /* In this case, we will be emitting the asm directive instead of
751 the label, so just return a placeholder to keep the rest of the
753 strcpy (label, "<do not output>");
757 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
758 ASM_OUTPUT_LABEL (asm_out_file, label);
764 /* True if remember_state should be emitted before following CFI directive. */
765 static bool emit_cfa_remember;
767 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
768 or to the CIE if LABEL is NULL. */
771 add_fde_cfi (const char *label, dw_cfi_ref cfi)
773 dw_cfi_ref *list_head;
775 if (emit_cfa_remember)
777 dw_cfi_ref cfi_remember;
779 /* Emit the state save. */
780 emit_cfa_remember = false;
781 cfi_remember = new_cfi ();
782 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
783 add_fde_cfi (label, cfi_remember);
786 list_head = &cie_cfi_head;
788 if (dwarf2out_do_cfi_asm ())
792 dw_fde_ref fde = current_fde ();
794 gcc_assert (fde != NULL);
796 /* We still have to add the cfi to the list so that lookup_cfa
797 works later on. When -g2 and above we even need to force
798 emitting of CFI labels and add to list a DW_CFA_set_loc for
799 convert_cfa_to_fb_loc_list purposes. If we're generating
800 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
801 convert_cfa_to_fb_loc_list. */
802 if (dwarf_version == 2
803 && debug_info_level > DINFO_LEVEL_TERSE
804 && (write_symbols == DWARF2_DEBUG
805 || write_symbols == VMS_AND_DWARF2_DEBUG))
807 switch (cfi->dw_cfi_opc)
809 case DW_CFA_def_cfa_offset:
810 case DW_CFA_def_cfa_offset_sf:
811 case DW_CFA_def_cfa_register:
813 case DW_CFA_def_cfa_sf:
814 case DW_CFA_def_cfa_expression:
815 case DW_CFA_restore_state:
816 if (*label == 0 || strcmp (label, "<do not output>") == 0)
817 label = dwarf2out_cfi_label (true);
819 if (fde->dw_fde_current_label == NULL
820 || strcmp (label, fde->dw_fde_current_label) != 0)
824 label = xstrdup (label);
826 /* Set the location counter to the new label. */
828 /* It doesn't metter whether DW_CFA_set_loc
829 or DW_CFA_advance_loc4 is added here, those aren't
830 emitted into assembly, only looked up by
831 convert_cfa_to_fb_loc_list. */
832 xcfi->dw_cfi_opc = DW_CFA_set_loc;
833 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
834 add_cfi (&fde->dw_fde_cfi, xcfi);
835 fde->dw_fde_current_label = label;
843 output_cfi_directive (cfi);
845 list_head = &fde->dw_fde_cfi;
847 /* ??? If this is a CFI for the CIE, we don't emit. This
848 assumes that the standard CIE contents that the assembler
849 uses matches the standard CIE contents that the compiler
850 uses. This is probably a bad assumption. I'm not quite
851 sure how to address this for now. */
855 dw_fde_ref fde = current_fde ();
857 gcc_assert (fde != NULL);
860 label = dwarf2out_cfi_label (false);
862 if (fde->dw_fde_current_label == NULL
863 || strcmp (label, fde->dw_fde_current_label) != 0)
867 label = xstrdup (label);
869 /* Set the location counter to the new label. */
871 /* If we have a current label, advance from there, otherwise
872 set the location directly using set_loc. */
873 xcfi->dw_cfi_opc = fde->dw_fde_current_label
874 ? DW_CFA_advance_loc4
876 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
877 add_cfi (&fde->dw_fde_cfi, xcfi);
879 fde->dw_fde_current_label = label;
882 list_head = &fde->dw_fde_cfi;
885 add_cfi (list_head, cfi);
888 /* Subroutine of lookup_cfa. */
891 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
893 switch (cfi->dw_cfi_opc)
895 case DW_CFA_def_cfa_offset:
896 case DW_CFA_def_cfa_offset_sf:
897 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
899 case DW_CFA_def_cfa_register:
900 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
903 case DW_CFA_def_cfa_sf:
904 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
905 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
907 case DW_CFA_def_cfa_expression:
908 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
911 case DW_CFA_remember_state:
912 gcc_assert (!remember->in_use);
914 remember->in_use = 1;
916 case DW_CFA_restore_state:
917 gcc_assert (remember->in_use);
919 remember->in_use = 0;
927 /* Find the previous value for the CFA. */
930 lookup_cfa (dw_cfa_location *loc)
934 dw_cfa_location remember;
936 memset (loc, 0, sizeof (*loc));
937 loc->reg = INVALID_REGNUM;
940 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
941 lookup_cfa_1 (cfi, loc, &remember);
943 fde = current_fde ();
945 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
946 lookup_cfa_1 (cfi, loc, &remember);
949 /* The current rule for calculating the DWARF2 canonical frame address. */
950 static dw_cfa_location cfa;
952 /* The register used for saving registers to the stack, and its offset
954 static dw_cfa_location cfa_store;
956 /* The current save location around an epilogue. */
957 static dw_cfa_location cfa_remember;
959 /* The running total of the size of arguments pushed onto the stack. */
960 static HOST_WIDE_INT args_size;
962 /* The last args_size we actually output. */
963 static HOST_WIDE_INT old_args_size;
965 /* Entry point to update the canonical frame address (CFA).
966 LABEL is passed to add_fde_cfi. The value of CFA is now to be
967 calculated from REG+OFFSET. */
970 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
977 def_cfa_1 (label, &loc);
980 /* Determine if two dw_cfa_location structures define the same data. */
983 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
985 return (loc1->reg == loc2->reg
986 && loc1->offset == loc2->offset
987 && loc1->indirect == loc2->indirect
988 && (loc1->indirect == 0
989 || loc1->base_offset == loc2->base_offset));
992 /* This routine does the actual work. The CFA is now calculated from
993 the dw_cfa_location structure. */
996 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
999 dw_cfa_location old_cfa, loc;
1004 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1005 cfa_store.offset = loc.offset;
1007 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1008 lookup_cfa (&old_cfa);
1010 /* If nothing changed, no need to issue any call frame instructions. */
1011 if (cfa_equal_p (&loc, &old_cfa))
1016 if (loc.reg == old_cfa.reg && !loc.indirect)
1018 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1019 the CFA register did not change but the offset did. The data
1020 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1021 in the assembler via the .cfi_def_cfa_offset directive. */
1023 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1025 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1026 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1029 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1030 else if (loc.offset == old_cfa.offset
1031 && old_cfa.reg != INVALID_REGNUM
1034 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1035 indicating the CFA register has changed to <register> but the
1036 offset has not changed. */
1037 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1038 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1042 else if (loc.indirect == 0)
1044 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1045 indicating the CFA register has changed to <register> with
1046 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1047 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1050 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1052 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1053 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1054 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1058 /* Construct a DW_CFA_def_cfa_expression instruction to
1059 calculate the CFA using a full location expression since no
1060 register-offset pair is available. */
1061 struct dw_loc_descr_struct *loc_list;
1063 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1064 loc_list = build_cfa_loc (&loc, 0);
1065 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1068 add_fde_cfi (label, cfi);
1071 /* Add the CFI for saving a register. REG is the CFA column number.
1072 LABEL is passed to add_fde_cfi.
1073 If SREG is -1, the register is saved at OFFSET from the CFA;
1074 otherwise it is saved in SREG. */
1077 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1079 dw_cfi_ref cfi = new_cfi ();
1080 dw_fde_ref fde = current_fde ();
1082 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1084 /* When stack is aligned, store REG using DW_CFA_expression with
1087 && fde->stack_realign
1088 && sreg == INVALID_REGNUM)
1090 cfi->dw_cfi_opc = DW_CFA_expression;
1091 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = reg;
1092 cfi->dw_cfi_oprnd1.dw_cfi_loc
1093 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1095 else if (sreg == INVALID_REGNUM)
1097 if (need_data_align_sf_opcode (offset))
1098 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1099 else if (reg & ~0x3f)
1100 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1102 cfi->dw_cfi_opc = DW_CFA_offset;
1103 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1105 else if (sreg == reg)
1106 cfi->dw_cfi_opc = DW_CFA_same_value;
1109 cfi->dw_cfi_opc = DW_CFA_register;
1110 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1113 add_fde_cfi (label, cfi);
1116 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1117 This CFI tells the unwinder that it needs to restore the window registers
1118 from the previous frame's window save area.
1120 ??? Perhaps we should note in the CIE where windows are saved (instead of
1121 assuming 0(cfa)) and what registers are in the window. */
1124 dwarf2out_window_save (const char *label)
1126 dw_cfi_ref cfi = new_cfi ();
1128 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1129 add_fde_cfi (label, cfi);
1132 /* Add a CFI to update the running total of the size of arguments
1133 pushed onto the stack. */
1136 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1140 if (size == old_args_size)
1143 old_args_size = size;
1146 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1147 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1148 add_fde_cfi (label, cfi);
1151 /* Entry point for saving a register to the stack. REG is the GCC register
1152 number. LABEL and OFFSET are passed to reg_save. */
1155 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1157 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1160 /* Entry point for saving the return address in the stack.
1161 LABEL and OFFSET are passed to reg_save. */
1164 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1166 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1169 /* Entry point for saving the return address in a register.
1170 LABEL and SREG are passed to reg_save. */
1173 dwarf2out_return_reg (const char *label, unsigned int sreg)
1175 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1178 #ifdef DWARF2_UNWIND_INFO
1179 /* Record the initial position of the return address. RTL is
1180 INCOMING_RETURN_ADDR_RTX. */
1183 initial_return_save (rtx rtl)
1185 unsigned int reg = INVALID_REGNUM;
1186 HOST_WIDE_INT offset = 0;
1188 switch (GET_CODE (rtl))
1191 /* RA is in a register. */
1192 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1196 /* RA is on the stack. */
1197 rtl = XEXP (rtl, 0);
1198 switch (GET_CODE (rtl))
1201 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1206 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1207 offset = INTVAL (XEXP (rtl, 1));
1211 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1212 offset = -INTVAL (XEXP (rtl, 1));
1222 /* The return address is at some offset from any value we can
1223 actually load. For instance, on the SPARC it is in %i7+8. Just
1224 ignore the offset for now; it doesn't matter for unwinding frames. */
1225 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1226 initial_return_save (XEXP (rtl, 0));
1233 if (reg != DWARF_FRAME_RETURN_COLUMN)
1234 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1238 /* Given a SET, calculate the amount of stack adjustment it
1241 static HOST_WIDE_INT
1242 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1243 HOST_WIDE_INT cur_offset)
1245 const_rtx src = SET_SRC (pattern);
1246 const_rtx dest = SET_DEST (pattern);
1247 HOST_WIDE_INT offset = 0;
1250 if (dest == stack_pointer_rtx)
1252 code = GET_CODE (src);
1254 /* Assume (set (reg sp) (reg whatever)) sets args_size
1256 if (code == REG && src != stack_pointer_rtx)
1258 offset = -cur_args_size;
1259 #ifndef STACK_GROWS_DOWNWARD
1262 return offset - cur_offset;
1265 if (! (code == PLUS || code == MINUS)
1266 || XEXP (src, 0) != stack_pointer_rtx
1267 || !CONST_INT_P (XEXP (src, 1)))
1270 /* (set (reg sp) (plus (reg sp) (const_int))) */
1271 offset = INTVAL (XEXP (src, 1));
1277 if (MEM_P (src) && !MEM_P (dest))
1281 /* (set (mem (pre_dec (reg sp))) (foo)) */
1282 src = XEXP (dest, 0);
1283 code = GET_CODE (src);
1289 if (XEXP (src, 0) == stack_pointer_rtx)
1291 rtx val = XEXP (XEXP (src, 1), 1);
1292 /* We handle only adjustments by constant amount. */
1293 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1294 && CONST_INT_P (val));
1295 offset = -INTVAL (val);
1302 if (XEXP (src, 0) == stack_pointer_rtx)
1304 offset = GET_MODE_SIZE (GET_MODE (dest));
1311 if (XEXP (src, 0) == stack_pointer_rtx)
1313 offset = -GET_MODE_SIZE (GET_MODE (dest));
1328 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1329 indexed by INSN_UID. */
1331 static HOST_WIDE_INT *barrier_args_size;
1333 /* Helper function for compute_barrier_args_size. Handle one insn. */
1335 static HOST_WIDE_INT
1336 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1337 VEC (rtx, heap) **next)
1339 HOST_WIDE_INT offset = 0;
1342 if (! RTX_FRAME_RELATED_P (insn))
1344 if (prologue_epilogue_contains (insn))
1346 else if (GET_CODE (PATTERN (insn)) == SET)
1347 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1348 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1349 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1351 /* There may be stack adjustments inside compound insns. Search
1353 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1354 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1355 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1356 cur_args_size, offset);
1361 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1365 expr = XEXP (expr, 0);
1366 if (GET_CODE (expr) == PARALLEL
1367 || GET_CODE (expr) == SEQUENCE)
1368 for (i = 1; i < XVECLEN (expr, 0); i++)
1370 rtx elem = XVECEXP (expr, 0, i);
1372 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1373 offset += stack_adjust_offset (elem, cur_args_size, offset);
1378 #ifndef STACK_GROWS_DOWNWARD
1382 cur_args_size += offset;
1383 if (cur_args_size < 0)
1388 rtx dest = JUMP_LABEL (insn);
1392 if (barrier_args_size [INSN_UID (dest)] < 0)
1394 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1395 VEC_safe_push (rtx, heap, *next, dest);
1400 return cur_args_size;
1403 /* Walk the whole function and compute args_size on BARRIERs. */
1406 compute_barrier_args_size (void)
1408 int max_uid = get_max_uid (), i;
1410 VEC (rtx, heap) *worklist, *next, *tmp;
1412 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1413 for (i = 0; i < max_uid; i++)
1414 barrier_args_size[i] = -1;
1416 worklist = VEC_alloc (rtx, heap, 20);
1417 next = VEC_alloc (rtx, heap, 20);
1418 insn = get_insns ();
1419 barrier_args_size[INSN_UID (insn)] = 0;
1420 VEC_quick_push (rtx, worklist, insn);
1423 while (!VEC_empty (rtx, worklist))
1425 rtx prev, body, first_insn;
1426 HOST_WIDE_INT cur_args_size;
1428 first_insn = insn = VEC_pop (rtx, worklist);
1429 cur_args_size = barrier_args_size[INSN_UID (insn)];
1430 prev = prev_nonnote_insn (insn);
1431 if (prev && BARRIER_P (prev))
1432 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1434 for (; insn; insn = NEXT_INSN (insn))
1436 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1438 if (BARRIER_P (insn))
1443 if (insn == first_insn)
1445 else if (barrier_args_size[INSN_UID (insn)] < 0)
1447 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1452 /* The insns starting with this label have been
1453 already scanned or are in the worklist. */
1458 body = PATTERN (insn);
1459 if (GET_CODE (body) == SEQUENCE)
1461 HOST_WIDE_INT dest_args_size = cur_args_size;
1462 for (i = 1; i < XVECLEN (body, 0); i++)
1463 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1464 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1466 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1467 dest_args_size, &next);
1470 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1471 cur_args_size, &next);
1473 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1474 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1475 dest_args_size, &next);
1478 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1479 cur_args_size, &next);
1483 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1487 if (VEC_empty (rtx, next))
1490 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1494 VEC_truncate (rtx, next, 0);
1497 VEC_free (rtx, heap, worklist);
1498 VEC_free (rtx, heap, next);
1502 /* Check INSN to see if it looks like a push or a stack adjustment, and
1503 make a note of it if it does. EH uses this information to find out how
1504 much extra space it needs to pop off the stack. */
1507 dwarf2out_stack_adjust (rtx insn, bool after_p)
1509 HOST_WIDE_INT offset;
1513 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1514 with this function. Proper support would require all frame-related
1515 insns to be marked, and to be able to handle saving state around
1516 epilogues textually in the middle of the function. */
1517 if (prologue_epilogue_contains (insn))
1520 /* If INSN is an instruction from target of an annulled branch, the
1521 effects are for the target only and so current argument size
1522 shouldn't change at all. */
1524 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1525 && INSN_FROM_TARGET_P (insn))
1528 /* If only calls can throw, and we have a frame pointer,
1529 save up adjustments until we see the CALL_INSN. */
1530 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1532 if (CALL_P (insn) && !after_p)
1534 /* Extract the size of the args from the CALL rtx itself. */
1535 insn = PATTERN (insn);
1536 if (GET_CODE (insn) == PARALLEL)
1537 insn = XVECEXP (insn, 0, 0);
1538 if (GET_CODE (insn) == SET)
1539 insn = SET_SRC (insn);
1540 gcc_assert (GET_CODE (insn) == CALL);
1541 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1546 if (CALL_P (insn) && !after_p)
1548 if (!flag_asynchronous_unwind_tables)
1549 dwarf2out_args_size ("", args_size);
1552 else if (BARRIER_P (insn))
1554 /* Don't call compute_barrier_args_size () if the only
1555 BARRIER is at the end of function. */
1556 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1557 compute_barrier_args_size ();
1558 if (barrier_args_size == NULL)
1562 offset = barrier_args_size[INSN_UID (insn)];
1567 offset -= args_size;
1568 #ifndef STACK_GROWS_DOWNWARD
1572 else if (GET_CODE (PATTERN (insn)) == SET)
1573 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1574 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1575 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1577 /* There may be stack adjustments inside compound insns. Search
1579 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1580 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1581 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1590 label = dwarf2out_cfi_label (false);
1591 dwarf2out_args_size_adjust (offset, label);
1594 /* Adjust args_size based on stack adjustment OFFSET. */
1597 dwarf2out_args_size_adjust (HOST_WIDE_INT offset, const char *label)
1599 if (cfa.reg == STACK_POINTER_REGNUM)
1600 cfa.offset += offset;
1602 if (cfa_store.reg == STACK_POINTER_REGNUM)
1603 cfa_store.offset += offset;
1605 #ifndef STACK_GROWS_DOWNWARD
1609 args_size += offset;
1613 def_cfa_1 (label, &cfa);
1614 if (flag_asynchronous_unwind_tables)
1615 dwarf2out_args_size (label, args_size);
1620 /* We delay emitting a register save until either (a) we reach the end
1621 of the prologue or (b) the register is clobbered. This clusters
1622 register saves so that there are fewer pc advances. */
1624 struct GTY(()) queued_reg_save {
1625 struct queued_reg_save *next;
1627 HOST_WIDE_INT cfa_offset;
1631 static GTY(()) struct queued_reg_save *queued_reg_saves;
1633 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1634 struct GTY(()) reg_saved_in_data {
1639 /* A list of registers saved in other registers.
1640 The list intentionally has a small maximum capacity of 4; if your
1641 port needs more than that, you might consider implementing a
1642 more efficient data structure. */
1643 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1644 static GTY(()) size_t num_regs_saved_in_regs;
1646 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1647 static const char *last_reg_save_label;
1649 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1650 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1653 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1655 struct queued_reg_save *q;
1657 /* Duplicates waste space, but it's also necessary to remove them
1658 for correctness, since the queue gets output in reverse
1660 for (q = queued_reg_saves; q != NULL; q = q->next)
1661 if (REGNO (q->reg) == REGNO (reg))
1666 q = GGC_NEW (struct queued_reg_save);
1667 q->next = queued_reg_saves;
1668 queued_reg_saves = q;
1672 q->cfa_offset = offset;
1673 q->saved_reg = sreg;
1675 last_reg_save_label = label;
1678 /* Output all the entries in QUEUED_REG_SAVES. */
1681 flush_queued_reg_saves (void)
1683 struct queued_reg_save *q;
1685 for (q = queued_reg_saves; q; q = q->next)
1688 unsigned int reg, sreg;
1690 for (i = 0; i < num_regs_saved_in_regs; i++)
1691 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1693 if (q->saved_reg && i == num_regs_saved_in_regs)
1695 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1696 num_regs_saved_in_regs++;
1698 if (i != num_regs_saved_in_regs)
1700 regs_saved_in_regs[i].orig_reg = q->reg;
1701 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1704 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1706 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1708 sreg = INVALID_REGNUM;
1709 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1712 queued_reg_saves = NULL;
1713 last_reg_save_label = NULL;
1716 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1717 location for? Or, does it clobber a register which we've previously
1718 said that some other register is saved in, and for which we now
1719 have a new location for? */
1722 clobbers_queued_reg_save (const_rtx insn)
1724 struct queued_reg_save *q;
1726 for (q = queued_reg_saves; q; q = q->next)
1729 if (modified_in_p (q->reg, insn))
1731 for (i = 0; i < num_regs_saved_in_regs; i++)
1732 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1733 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1740 /* Entry point for saving the first register into the second. */
1743 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1746 unsigned int regno, sregno;
1748 for (i = 0; i < num_regs_saved_in_regs; i++)
1749 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1751 if (i == num_regs_saved_in_regs)
1753 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1754 num_regs_saved_in_regs++;
1756 regs_saved_in_regs[i].orig_reg = reg;
1757 regs_saved_in_regs[i].saved_in_reg = sreg;
1759 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1760 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1761 reg_save (label, regno, sregno, 0);
1764 /* What register, if any, is currently saved in REG? */
1767 reg_saved_in (rtx reg)
1769 unsigned int regn = REGNO (reg);
1771 struct queued_reg_save *q;
1773 for (q = queued_reg_saves; q; q = q->next)
1774 if (q->saved_reg && regn == REGNO (q->saved_reg))
1777 for (i = 0; i < num_regs_saved_in_regs; i++)
1778 if (regs_saved_in_regs[i].saved_in_reg
1779 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1780 return regs_saved_in_regs[i].orig_reg;
1786 /* A temporary register holding an integral value used in adjusting SP
1787 or setting up the store_reg. The "offset" field holds the integer
1788 value, not an offset. */
1789 static dw_cfa_location cfa_temp;
1791 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1794 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1796 memset (&cfa, 0, sizeof (cfa));
1798 switch (GET_CODE (pat))
1801 cfa.reg = REGNO (XEXP (pat, 0));
1802 cfa.offset = INTVAL (XEXP (pat, 1));
1806 cfa.reg = REGNO (pat);
1810 /* Recurse and define an expression. */
1814 def_cfa_1 (label, &cfa);
1817 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1820 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1824 gcc_assert (GET_CODE (pat) == SET);
1825 dest = XEXP (pat, 0);
1826 src = XEXP (pat, 1);
1828 switch (GET_CODE (src))
1831 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1832 cfa.offset -= INTVAL (XEXP (src, 1));
1842 cfa.reg = REGNO (dest);
1843 gcc_assert (cfa.indirect == 0);
1845 def_cfa_1 (label, &cfa);
1848 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1851 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1853 HOST_WIDE_INT offset;
1854 rtx src, addr, span;
1856 src = XEXP (set, 1);
1857 addr = XEXP (set, 0);
1858 gcc_assert (MEM_P (addr));
1859 addr = XEXP (addr, 0);
1861 /* As documented, only consider extremely simple addresses. */
1862 switch (GET_CODE (addr))
1865 gcc_assert (REGNO (addr) == cfa.reg);
1866 offset = -cfa.offset;
1869 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1870 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1876 span = targetm.dwarf_register_span (src);
1878 /* ??? We'd like to use queue_reg_save, but we need to come up with
1879 a different flushing heuristic for epilogues. */
1881 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
1884 /* We have a PARALLEL describing where the contents of SRC live.
1885 Queue register saves for each piece of the PARALLEL. */
1888 HOST_WIDE_INT span_offset = offset;
1890 gcc_assert (GET_CODE (span) == PARALLEL);
1892 limit = XVECLEN (span, 0);
1893 for (par_index = 0; par_index < limit; par_index++)
1895 rtx elem = XVECEXP (span, 0, par_index);
1897 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
1898 INVALID_REGNUM, span_offset);
1899 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1904 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1907 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
1910 unsigned sregno, dregno;
1912 src = XEXP (set, 1);
1913 dest = XEXP (set, 0);
1916 sregno = DWARF_FRAME_RETURN_COLUMN;
1918 sregno = DWARF_FRAME_REGNUM (REGNO (src));
1920 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
1922 /* ??? We'd like to use queue_reg_save, but we need to come up with
1923 a different flushing heuristic for epilogues. */
1924 reg_save (label, sregno, dregno, 0);
1927 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1930 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
1932 dw_cfi_ref cfi = new_cfi ();
1933 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
1935 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
1936 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
1938 add_fde_cfi (label, cfi);
1941 /* Record call frame debugging information for an expression EXPR,
1942 which either sets SP or FP (adjusting how we calculate the frame
1943 address) or saves a register to the stack or another register.
1944 LABEL indicates the address of EXPR.
1946 This function encodes a state machine mapping rtxes to actions on
1947 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1948 users need not read the source code.
1950 The High-Level Picture
1952 Changes in the register we use to calculate the CFA: Currently we
1953 assume that if you copy the CFA register into another register, we
1954 should take the other one as the new CFA register; this seems to
1955 work pretty well. If it's wrong for some target, it's simple
1956 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1958 Changes in the register we use for saving registers to the stack:
1959 This is usually SP, but not always. Again, we deduce that if you
1960 copy SP into another register (and SP is not the CFA register),
1961 then the new register is the one we will be using for register
1962 saves. This also seems to work.
1964 Register saves: There's not much guesswork about this one; if
1965 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1966 register save, and the register used to calculate the destination
1967 had better be the one we think we're using for this purpose.
1968 It's also assumed that a copy from a call-saved register to another
1969 register is saving that register if RTX_FRAME_RELATED_P is set on
1970 that instruction. If the copy is from a call-saved register to
1971 the *same* register, that means that the register is now the same
1972 value as in the caller.
1974 Except: If the register being saved is the CFA register, and the
1975 offset is nonzero, we are saving the CFA, so we assume we have to
1976 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1977 the intent is to save the value of SP from the previous frame.
1979 In addition, if a register has previously been saved to a different
1982 Invariants / Summaries of Rules
1984 cfa current rule for calculating the CFA. It usually
1985 consists of a register and an offset.
1986 cfa_store register used by prologue code to save things to the stack
1987 cfa_store.offset is the offset from the value of
1988 cfa_store.reg to the actual CFA
1989 cfa_temp register holding an integral value. cfa_temp.offset
1990 stores the value, which will be used to adjust the
1991 stack pointer. cfa_temp is also used like cfa_store,
1992 to track stores to the stack via fp or a temp reg.
1994 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1995 with cfa.reg as the first operand changes the cfa.reg and its
1996 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1999 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2000 expression yielding a constant. This sets cfa_temp.reg
2001 and cfa_temp.offset.
2003 Rule 5: Create a new register cfa_store used to save items to the
2006 Rules 10-14: Save a register to the stack. Define offset as the
2007 difference of the original location and cfa_store's
2008 location (or cfa_temp's location if cfa_temp is used).
2010 Rules 16-20: If AND operation happens on sp in prologue, we assume
2011 stack is realigned. We will use a group of DW_OP_XXX
2012 expressions to represent the location of the stored
2013 register instead of CFA+offset.
2017 "{a,b}" indicates a choice of a xor b.
2018 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2021 (set <reg1> <reg2>:cfa.reg)
2022 effects: cfa.reg = <reg1>
2023 cfa.offset unchanged
2024 cfa_temp.reg = <reg1>
2025 cfa_temp.offset = cfa.offset
2028 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2029 {<const_int>,<reg>:cfa_temp.reg}))
2030 effects: cfa.reg = sp if fp used
2031 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2032 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2033 if cfa_store.reg==sp
2036 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2037 effects: cfa.reg = fp
2038 cfa_offset += +/- <const_int>
2041 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2042 constraints: <reg1> != fp
2044 effects: cfa.reg = <reg1>
2045 cfa_temp.reg = <reg1>
2046 cfa_temp.offset = cfa.offset
2049 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2050 constraints: <reg1> != fp
2052 effects: cfa_store.reg = <reg1>
2053 cfa_store.offset = cfa.offset - cfa_temp.offset
2056 (set <reg> <const_int>)
2057 effects: cfa_temp.reg = <reg>
2058 cfa_temp.offset = <const_int>
2061 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2062 effects: cfa_temp.reg = <reg1>
2063 cfa_temp.offset |= <const_int>
2066 (set <reg> (high <exp>))
2070 (set <reg> (lo_sum <exp> <const_int>))
2071 effects: cfa_temp.reg = <reg>
2072 cfa_temp.offset = <const_int>
2075 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2076 effects: cfa_store.offset -= <const_int>
2077 cfa.offset = cfa_store.offset if cfa.reg == sp
2079 cfa.base_offset = -cfa_store.offset
2082 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2083 effects: cfa_store.offset += -/+ mode_size(mem)
2084 cfa.offset = cfa_store.offset if cfa.reg == sp
2086 cfa.base_offset = -cfa_store.offset
2089 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2092 effects: cfa.reg = <reg1>
2093 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2096 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2097 effects: cfa.reg = <reg1>
2098 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2101 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2102 effects: cfa.reg = <reg1>
2103 cfa.base_offset = -cfa_temp.offset
2104 cfa_temp.offset -= mode_size(mem)
2107 (set <reg> {unspec, unspec_volatile})
2108 effects: target-dependent
2111 (set sp (and: sp <const_int>))
2112 constraints: cfa_store.reg == sp
2113 effects: current_fde.stack_realign = 1
2114 cfa_store.offset = 0
2115 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2118 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2119 effects: cfa_store.offset += -/+ mode_size(mem)
2122 (set (mem ({pre_inc, pre_dec} sp)) fp)
2123 constraints: fde->stack_realign == 1
2124 effects: cfa_store.offset = 0
2125 cfa.reg != HARD_FRAME_POINTER_REGNUM
2128 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2129 constraints: fde->stack_realign == 1
2131 && cfa.indirect == 0
2132 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2133 effects: Use DW_CFA_def_cfa_expression to define cfa
2134 cfa.reg == fde->drap_reg
2137 (set reg fde->drap_reg)
2138 constraints: fde->vdrap_reg == INVALID_REGNUM
2139 effects: fde->vdrap_reg = reg.
2140 (set mem fde->drap_reg)
2141 constraints: fde->drap_reg_saved == 1
2145 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2147 rtx src, dest, span;
2148 HOST_WIDE_INT offset;
2151 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2152 the PARALLEL independently. The first element is always processed if
2153 it is a SET. This is for backward compatibility. Other elements
2154 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2155 flag is set in them. */
2156 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2159 int limit = XVECLEN (expr, 0);
2162 /* PARALLELs have strict read-modify-write semantics, so we
2163 ought to evaluate every rvalue before changing any lvalue.
2164 It's cumbersome to do that in general, but there's an
2165 easy approximation that is enough for all current users:
2166 handle register saves before register assignments. */
2167 if (GET_CODE (expr) == PARALLEL)
2168 for (par_index = 0; par_index < limit; par_index++)
2170 elem = XVECEXP (expr, 0, par_index);
2171 if (GET_CODE (elem) == SET
2172 && MEM_P (SET_DEST (elem))
2173 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2174 dwarf2out_frame_debug_expr (elem, label);
2177 for (par_index = 0; par_index < limit; par_index++)
2179 elem = XVECEXP (expr, 0, par_index);
2180 if (GET_CODE (elem) == SET
2181 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2182 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2183 dwarf2out_frame_debug_expr (elem, label);
2184 else if (GET_CODE (elem) == SET
2186 && !RTX_FRAME_RELATED_P (elem))
2188 /* Stack adjustment combining might combine some post-prologue
2189 stack adjustment into a prologue stack adjustment. */
2190 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2193 dwarf2out_args_size_adjust (offset, label);
2199 gcc_assert (GET_CODE (expr) == SET);
2201 src = SET_SRC (expr);
2202 dest = SET_DEST (expr);
2206 rtx rsi = reg_saved_in (src);
2211 fde = current_fde ();
2215 && fde->drap_reg == REGNO (src)
2216 && (fde->drap_reg_saved
2220 /* If we are saving dynamic realign argument pointer to a
2221 register, the destination is virtual dynamic realign
2222 argument pointer. It may be used to access argument. */
2225 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2226 fde->vdrap_reg = REGNO (dest);
2231 switch (GET_CODE (dest))
2234 switch (GET_CODE (src))
2236 /* Setting FP from SP. */
2238 if (cfa.reg == (unsigned) REGNO (src))
2241 /* Update the CFA rule wrt SP or FP. Make sure src is
2242 relative to the current CFA register.
2244 We used to require that dest be either SP or FP, but the
2245 ARM copies SP to a temporary register, and from there to
2246 FP. So we just rely on the backends to only set
2247 RTX_FRAME_RELATED_P on appropriate insns. */
2248 cfa.reg = REGNO (dest);
2249 cfa_temp.reg = cfa.reg;
2250 cfa_temp.offset = cfa.offset;
2254 /* Saving a register in a register. */
2255 gcc_assert (!fixed_regs [REGNO (dest)]
2256 /* For the SPARC and its register window. */
2257 || (DWARF_FRAME_REGNUM (REGNO (src))
2258 == DWARF_FRAME_RETURN_COLUMN));
2260 /* After stack is aligned, we can only save SP in FP
2261 if drap register is used. In this case, we have
2262 to restore stack pointer with the CFA value and we
2263 don't generate this DWARF information. */
2265 && fde->stack_realign
2266 && REGNO (src) == STACK_POINTER_REGNUM)
2267 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2268 && fde->drap_reg != INVALID_REGNUM
2269 && cfa.reg != REGNO (src));
2271 queue_reg_save (label, src, dest, 0);
2278 if (dest == stack_pointer_rtx)
2282 switch (GET_CODE (XEXP (src, 1)))
2285 offset = INTVAL (XEXP (src, 1));
2288 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2290 offset = cfa_temp.offset;
2296 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2298 /* Restoring SP from FP in the epilogue. */
2299 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2300 cfa.reg = STACK_POINTER_REGNUM;
2302 else if (GET_CODE (src) == LO_SUM)
2303 /* Assume we've set the source reg of the LO_SUM from sp. */
2306 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2308 if (GET_CODE (src) != MINUS)
2310 if (cfa.reg == STACK_POINTER_REGNUM)
2311 cfa.offset += offset;
2312 if (cfa_store.reg == STACK_POINTER_REGNUM)
2313 cfa_store.offset += offset;
2315 else if (dest == hard_frame_pointer_rtx)
2318 /* Either setting the FP from an offset of the SP,
2319 or adjusting the FP */
2320 gcc_assert (frame_pointer_needed);
2322 gcc_assert (REG_P (XEXP (src, 0))
2323 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2324 && CONST_INT_P (XEXP (src, 1)));
2325 offset = INTVAL (XEXP (src, 1));
2326 if (GET_CODE (src) != MINUS)
2328 cfa.offset += offset;
2329 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2333 gcc_assert (GET_CODE (src) != MINUS);
2336 if (REG_P (XEXP (src, 0))
2337 && REGNO (XEXP (src, 0)) == cfa.reg
2338 && CONST_INT_P (XEXP (src, 1)))
2340 /* Setting a temporary CFA register that will be copied
2341 into the FP later on. */
2342 offset = - INTVAL (XEXP (src, 1));
2343 cfa.offset += offset;
2344 cfa.reg = REGNO (dest);
2345 /* Or used to save regs to the stack. */
2346 cfa_temp.reg = cfa.reg;
2347 cfa_temp.offset = cfa.offset;
2351 else if (REG_P (XEXP (src, 0))
2352 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2353 && XEXP (src, 1) == stack_pointer_rtx)
2355 /* Setting a scratch register that we will use instead
2356 of SP for saving registers to the stack. */
2357 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2358 cfa_store.reg = REGNO (dest);
2359 cfa_store.offset = cfa.offset - cfa_temp.offset;
2363 else if (GET_CODE (src) == LO_SUM
2364 && CONST_INT_P (XEXP (src, 1)))
2366 cfa_temp.reg = REGNO (dest);
2367 cfa_temp.offset = INTVAL (XEXP (src, 1));
2376 cfa_temp.reg = REGNO (dest);
2377 cfa_temp.offset = INTVAL (src);
2382 gcc_assert (REG_P (XEXP (src, 0))
2383 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2384 && CONST_INT_P (XEXP (src, 1)));
2386 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2387 cfa_temp.reg = REGNO (dest);
2388 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2391 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2392 which will fill in all of the bits. */
2399 case UNSPEC_VOLATILE:
2400 gcc_assert (targetm.dwarf_handle_frame_unspec);
2401 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2406 /* If this AND operation happens on stack pointer in prologue,
2407 we assume the stack is realigned and we extract the
2409 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2411 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2412 fde->stack_realign = 1;
2413 fde->stack_realignment = INTVAL (XEXP (src, 1));
2414 cfa_store.offset = 0;
2416 if (cfa.reg != STACK_POINTER_REGNUM
2417 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2418 fde->drap_reg = cfa.reg;
2426 def_cfa_1 (label, &cfa);
2431 /* Saving a register to the stack. Make sure dest is relative to the
2433 switch (GET_CODE (XEXP (dest, 0)))
2438 /* We can't handle variable size modifications. */
2439 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2441 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2443 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2444 && cfa_store.reg == STACK_POINTER_REGNUM);
2446 cfa_store.offset += offset;
2447 if (cfa.reg == STACK_POINTER_REGNUM)
2448 cfa.offset = cfa_store.offset;
2450 offset = -cfa_store.offset;
2456 offset = GET_MODE_SIZE (GET_MODE (dest));
2457 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2460 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2461 == STACK_POINTER_REGNUM)
2462 && cfa_store.reg == STACK_POINTER_REGNUM);
2464 cfa_store.offset += offset;
2466 /* Rule 18: If stack is aligned, we will use FP as a
2467 reference to represent the address of the stored
2470 && fde->stack_realign
2471 && src == hard_frame_pointer_rtx)
2473 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2474 cfa_store.offset = 0;
2477 if (cfa.reg == STACK_POINTER_REGNUM)
2478 cfa.offset = cfa_store.offset;
2480 offset = -cfa_store.offset;
2484 /* With an offset. */
2491 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2492 && REG_P (XEXP (XEXP (dest, 0), 0)));
2493 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2494 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2497 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2499 if (cfa_store.reg == (unsigned) regno)
2500 offset -= cfa_store.offset;
2503 gcc_assert (cfa_temp.reg == (unsigned) regno);
2504 offset -= cfa_temp.offset;
2510 /* Without an offset. */
2513 int regno = REGNO (XEXP (dest, 0));
2515 if (cfa_store.reg == (unsigned) regno)
2516 offset = -cfa_store.offset;
2519 gcc_assert (cfa_temp.reg == (unsigned) regno);
2520 offset = -cfa_temp.offset;
2527 gcc_assert (cfa_temp.reg
2528 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2529 offset = -cfa_temp.offset;
2530 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2538 /* If the source operand of this MEM operation is not a
2539 register, basically the source is return address. Here
2540 we only care how much stack grew and we don't save it. */
2544 if (REGNO (src) != STACK_POINTER_REGNUM
2545 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2546 && (unsigned) REGNO (src) == cfa.reg)
2548 /* We're storing the current CFA reg into the stack. */
2550 if (cfa.offset == 0)
2553 /* If stack is aligned, putting CFA reg into stack means
2554 we can no longer use reg + offset to represent CFA.
2555 Here we use DW_CFA_def_cfa_expression instead. The
2556 result of this expression equals to the original CFA
2559 && fde->stack_realign
2560 && cfa.indirect == 0
2561 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2563 dw_cfa_location cfa_exp;
2565 gcc_assert (fde->drap_reg == cfa.reg);
2567 cfa_exp.indirect = 1;
2568 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2569 cfa_exp.base_offset = offset;
2572 fde->drap_reg_saved = 1;
2574 def_cfa_1 (label, &cfa_exp);
2578 /* If the source register is exactly the CFA, assume
2579 we're saving SP like any other register; this happens
2581 def_cfa_1 (label, &cfa);
2582 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2587 /* Otherwise, we'll need to look in the stack to
2588 calculate the CFA. */
2589 rtx x = XEXP (dest, 0);
2593 gcc_assert (REG_P (x));
2595 cfa.reg = REGNO (x);
2596 cfa.base_offset = offset;
2598 def_cfa_1 (label, &cfa);
2603 def_cfa_1 (label, &cfa);
2605 span = targetm.dwarf_register_span (src);
2608 queue_reg_save (label, src, NULL_RTX, offset);
2611 /* We have a PARALLEL describing where the contents of SRC
2612 live. Queue register saves for each piece of the
2616 HOST_WIDE_INT span_offset = offset;
2618 gcc_assert (GET_CODE (span) == PARALLEL);
2620 limit = XVECLEN (span, 0);
2621 for (par_index = 0; par_index < limit; par_index++)
2623 rtx elem = XVECEXP (span, 0, par_index);
2625 queue_reg_save (label, elem, NULL_RTX, span_offset);
2626 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2637 /* Record call frame debugging information for INSN, which either
2638 sets SP or FP (adjusting how we calculate the frame address) or saves a
2639 register to the stack. If INSN is NULL_RTX, initialize our state.
2641 If AFTER_P is false, we're being called before the insn is emitted,
2642 otherwise after. Call instructions get invoked twice. */
2645 dwarf2out_frame_debug (rtx insn, bool after_p)
2649 bool handled_one = false;
2651 if (insn == NULL_RTX)
2655 /* Flush any queued register saves. */
2656 flush_queued_reg_saves ();
2658 /* Set up state for generating call frame debug info. */
2661 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2663 cfa.reg = STACK_POINTER_REGNUM;
2666 cfa_temp.offset = 0;
2668 for (i = 0; i < num_regs_saved_in_regs; i++)
2670 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2671 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2673 num_regs_saved_in_regs = 0;
2675 if (barrier_args_size)
2677 XDELETEVEC (barrier_args_size);
2678 barrier_args_size = NULL;
2683 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2684 flush_queued_reg_saves ();
2686 if (! RTX_FRAME_RELATED_P (insn))
2688 if (!ACCUMULATE_OUTGOING_ARGS)
2689 dwarf2out_stack_adjust (insn, after_p);
2693 label = dwarf2out_cfi_label (false);
2695 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2696 switch (REG_NOTE_KIND (note))
2698 case REG_FRAME_RELATED_EXPR:
2699 insn = XEXP (note, 0);
2702 case REG_CFA_DEF_CFA:
2703 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2707 case REG_CFA_ADJUST_CFA:
2712 if (GET_CODE (n) == PARALLEL)
2713 n = XVECEXP (n, 0, 0);
2715 dwarf2out_frame_debug_adjust_cfa (n, label);
2719 case REG_CFA_OFFSET:
2722 n = single_set (insn);
2723 dwarf2out_frame_debug_cfa_offset (n, label);
2727 case REG_CFA_REGISTER:
2732 if (GET_CODE (n) == PARALLEL)
2733 n = XVECEXP (n, 0, 0);
2735 dwarf2out_frame_debug_cfa_register (n, label);
2739 case REG_CFA_RESTORE:
2744 if (GET_CODE (n) == PARALLEL)
2745 n = XVECEXP (n, 0, 0);
2748 dwarf2out_frame_debug_cfa_restore (n, label);
2758 insn = PATTERN (insn);
2760 dwarf2out_frame_debug_expr (insn, label);
2763 /* Determine if we need to save and restore CFI information around this
2764 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2765 we do need to save/restore, then emit the save now, and insert a
2766 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2769 dwarf2out_begin_epilogue (rtx insn)
2771 bool saw_frp = false;
2774 /* Scan forward to the return insn, noticing if there are possible
2775 frame related insns. */
2776 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2781 /* Look for both regular and sibcalls to end the block. */
2782 if (returnjump_p (i))
2784 if (CALL_P (i) && SIBLING_CALL_P (i))
2787 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2790 rtx seq = PATTERN (i);
2792 if (returnjump_p (XVECEXP (seq, 0, 0)))
2794 if (CALL_P (XVECEXP (seq, 0, 0))
2795 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2798 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2799 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2803 if (RTX_FRAME_RELATED_P (i))
2807 /* If the port doesn't emit epilogue unwind info, we don't need a
2808 save/restore pair. */
2812 /* Otherwise, search forward to see if the return insn was the last
2813 basic block of the function. If so, we don't need save/restore. */
2814 gcc_assert (i != NULL);
2815 i = next_real_insn (i);
2819 /* Insert the restore before that next real insn in the stream, and before
2820 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2821 properly nested. This should be after any label or alignment. This
2822 will be pushed into the CFI stream by the function below. */
2825 rtx p = PREV_INSN (i);
2828 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
2832 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
2834 emit_cfa_remember = true;
2836 /* And emulate the state save. */
2837 gcc_assert (!cfa_remember.in_use);
2839 cfa_remember.in_use = 1;
2842 /* A "subroutine" of dwarf2out_begin_epilogue. Emit the restore required. */
2845 dwarf2out_frame_debug_restore_state (void)
2847 dw_cfi_ref cfi = new_cfi ();
2848 const char *label = dwarf2out_cfi_label (false);
2850 cfi->dw_cfi_opc = DW_CFA_restore_state;
2851 add_fde_cfi (label, cfi);
2853 gcc_assert (cfa_remember.in_use);
2855 cfa_remember.in_use = 0;
2860 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2861 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2862 (enum dwarf_call_frame_info cfi);
2864 static enum dw_cfi_oprnd_type
2865 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2870 case DW_CFA_GNU_window_save:
2871 case DW_CFA_remember_state:
2872 case DW_CFA_restore_state:
2873 return dw_cfi_oprnd_unused;
2875 case DW_CFA_set_loc:
2876 case DW_CFA_advance_loc1:
2877 case DW_CFA_advance_loc2:
2878 case DW_CFA_advance_loc4:
2879 case DW_CFA_MIPS_advance_loc8:
2880 return dw_cfi_oprnd_addr;
2883 case DW_CFA_offset_extended:
2884 case DW_CFA_def_cfa:
2885 case DW_CFA_offset_extended_sf:
2886 case DW_CFA_def_cfa_sf:
2887 case DW_CFA_restore:
2888 case DW_CFA_restore_extended:
2889 case DW_CFA_undefined:
2890 case DW_CFA_same_value:
2891 case DW_CFA_def_cfa_register:
2892 case DW_CFA_register:
2893 return dw_cfi_oprnd_reg_num;
2895 case DW_CFA_def_cfa_offset:
2896 case DW_CFA_GNU_args_size:
2897 case DW_CFA_def_cfa_offset_sf:
2898 return dw_cfi_oprnd_offset;
2900 case DW_CFA_def_cfa_expression:
2901 case DW_CFA_expression:
2902 return dw_cfi_oprnd_loc;
2909 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2910 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2911 (enum dwarf_call_frame_info cfi);
2913 static enum dw_cfi_oprnd_type
2914 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2918 case DW_CFA_def_cfa:
2919 case DW_CFA_def_cfa_sf:
2921 case DW_CFA_offset_extended_sf:
2922 case DW_CFA_offset_extended:
2923 return dw_cfi_oprnd_offset;
2925 case DW_CFA_register:
2926 return dw_cfi_oprnd_reg_num;
2929 return dw_cfi_oprnd_unused;
2933 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2935 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
2936 switch to the data section instead, and write out a synthetic start label
2937 for collect2 the first time around. */
2940 switch_to_eh_frame_section (bool back)
2944 #ifdef EH_FRAME_SECTION_NAME
2945 if (eh_frame_section == 0)
2949 if (EH_TABLES_CAN_BE_READ_ONLY)
2955 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2957 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2959 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2961 flags = ((! flag_pic
2962 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2963 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2964 && (per_encoding & 0x70) != DW_EH_PE_absptr
2965 && (per_encoding & 0x70) != DW_EH_PE_aligned
2966 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2967 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2968 ? 0 : SECTION_WRITE);
2971 flags = SECTION_WRITE;
2972 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2976 if (eh_frame_section)
2977 switch_to_section (eh_frame_section);
2980 /* We have no special eh_frame section. Put the information in
2981 the data section and emit special labels to guide collect2. */
2982 switch_to_section (data_section);
2986 label = get_file_function_name ("F");
2987 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2988 targetm.asm_out.globalize_label (asm_out_file,
2989 IDENTIFIER_POINTER (label));
2990 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2995 /* Switch [BACK] to the eh or debug frame table section, depending on
2999 switch_to_frame_table_section (int for_eh, bool back)
3002 switch_to_eh_frame_section (back);
3005 if (!debug_frame_section)
3006 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3007 SECTION_DEBUG, NULL);
3008 switch_to_section (debug_frame_section);
3012 /* Output a Call Frame Information opcode and its operand(s). */
3015 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3020 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3021 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3022 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3023 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3024 ((unsigned HOST_WIDE_INT)
3025 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3026 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3028 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3029 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3030 "DW_CFA_offset, column 0x%lx", r);
3031 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3032 dw2_asm_output_data_uleb128 (off, NULL);
3034 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3036 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3037 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3038 "DW_CFA_restore, column 0x%lx", r);
3042 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3043 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3045 switch (cfi->dw_cfi_opc)
3047 case DW_CFA_set_loc:
3049 dw2_asm_output_encoded_addr_rtx (
3050 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3051 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3054 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3055 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3056 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3059 case DW_CFA_advance_loc1:
3060 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3061 fde->dw_fde_current_label, NULL);
3062 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3065 case DW_CFA_advance_loc2:
3066 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3067 fde->dw_fde_current_label, NULL);
3068 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3071 case DW_CFA_advance_loc4:
3072 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3073 fde->dw_fde_current_label, NULL);
3074 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3077 case DW_CFA_MIPS_advance_loc8:
3078 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3079 fde->dw_fde_current_label, NULL);
3080 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3083 case DW_CFA_offset_extended:
3084 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3085 dw2_asm_output_data_uleb128 (r, NULL);
3086 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3087 dw2_asm_output_data_uleb128 (off, NULL);
3090 case DW_CFA_def_cfa:
3091 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3092 dw2_asm_output_data_uleb128 (r, NULL);
3093 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3096 case DW_CFA_offset_extended_sf:
3097 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3098 dw2_asm_output_data_uleb128 (r, NULL);
3099 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3100 dw2_asm_output_data_sleb128 (off, NULL);
3103 case DW_CFA_def_cfa_sf:
3104 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3105 dw2_asm_output_data_uleb128 (r, NULL);
3106 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3107 dw2_asm_output_data_sleb128 (off, NULL);
3110 case DW_CFA_restore_extended:
3111 case DW_CFA_undefined:
3112 case DW_CFA_same_value:
3113 case DW_CFA_def_cfa_register:
3114 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3115 dw2_asm_output_data_uleb128 (r, NULL);
3118 case DW_CFA_register:
3119 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3120 dw2_asm_output_data_uleb128 (r, NULL);
3121 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3122 dw2_asm_output_data_uleb128 (r, NULL);
3125 case DW_CFA_def_cfa_offset:
3126 case DW_CFA_GNU_args_size:
3127 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3130 case DW_CFA_def_cfa_offset_sf:
3131 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3132 dw2_asm_output_data_sleb128 (off, NULL);
3135 case DW_CFA_GNU_window_save:
3138 case DW_CFA_def_cfa_expression:
3139 case DW_CFA_expression:
3140 output_cfa_loc (cfi);
3143 case DW_CFA_GNU_negative_offset_extended:
3144 /* Obsoleted by DW_CFA_offset_extended_sf. */
3153 /* Similar, but do it via assembler directives instead. */
3156 output_cfi_directive (dw_cfi_ref cfi)
3158 unsigned long r, r2;
3160 switch (cfi->dw_cfi_opc)
3162 case DW_CFA_advance_loc:
3163 case DW_CFA_advance_loc1:
3164 case DW_CFA_advance_loc2:
3165 case DW_CFA_advance_loc4:
3166 case DW_CFA_MIPS_advance_loc8:
3167 case DW_CFA_set_loc:
3168 /* Should only be created by add_fde_cfi in a code path not
3169 followed when emitting via directives. The assembler is
3170 going to take care of this for us. */
3174 case DW_CFA_offset_extended:
3175 case DW_CFA_offset_extended_sf:
3176 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3177 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3178 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3181 case DW_CFA_restore:
3182 case DW_CFA_restore_extended:
3183 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3184 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3187 case DW_CFA_undefined:
3188 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3189 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3192 case DW_CFA_same_value:
3193 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3194 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3197 case DW_CFA_def_cfa:
3198 case DW_CFA_def_cfa_sf:
3199 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3200 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3201 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3204 case DW_CFA_def_cfa_register:
3205 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3206 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3209 case DW_CFA_register:
3210 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3211 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3212 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3215 case DW_CFA_def_cfa_offset:
3216 case DW_CFA_def_cfa_offset_sf:
3217 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3218 HOST_WIDE_INT_PRINT_DEC"\n",
3219 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3222 case DW_CFA_remember_state:
3223 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3225 case DW_CFA_restore_state:
3226 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3229 case DW_CFA_GNU_args_size:
3230 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size);
3231 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3233 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3234 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3235 fputc ('\n', asm_out_file);
3238 case DW_CFA_GNU_window_save:
3239 fprintf (asm_out_file, "\t.cfi_window_save\n");
3242 case DW_CFA_def_cfa_expression:
3243 case DW_CFA_expression:
3244 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", cfi->dw_cfi_opc);
3245 output_cfa_loc_raw (cfi);
3246 fputc ('\n', asm_out_file);
3254 DEF_VEC_P (dw_cfi_ref);
3255 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3257 /* Output CFIs to bring current FDE to the same state as after executing
3258 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3259 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3260 other arguments to pass to output_cfi. */
3263 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3265 struct dw_cfi_struct cfi_buf;
3267 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3268 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3269 unsigned int len, idx;
3271 for (;; cfi = cfi->dw_cfi_next)
3272 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3274 case DW_CFA_advance_loc:
3275 case DW_CFA_advance_loc1:
3276 case DW_CFA_advance_loc2:
3277 case DW_CFA_advance_loc4:
3278 case DW_CFA_MIPS_advance_loc8:
3279 case DW_CFA_set_loc:
3280 /* All advances should be ignored. */
3282 case DW_CFA_remember_state:
3284 dw_cfi_ref args_size = cfi_args_size;
3286 /* Skip everything between .cfi_remember_state and
3287 .cfi_restore_state. */
3288 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3289 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3291 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3294 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3301 cfi_args_size = args_size;
3305 case DW_CFA_GNU_args_size:
3306 cfi_args_size = cfi;
3308 case DW_CFA_GNU_window_save:
3311 case DW_CFA_offset_extended:
3312 case DW_CFA_offset_extended_sf:
3313 case DW_CFA_restore:
3314 case DW_CFA_restore_extended:
3315 case DW_CFA_undefined:
3316 case DW_CFA_same_value:
3317 case DW_CFA_register:
3318 case DW_CFA_val_offset:
3319 case DW_CFA_val_offset_sf:
3320 case DW_CFA_expression:
3321 case DW_CFA_val_expression:
3322 case DW_CFA_GNU_negative_offset_extended:
3323 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3324 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3325 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3326 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3328 case DW_CFA_def_cfa:
3329 case DW_CFA_def_cfa_sf:
3330 case DW_CFA_def_cfa_expression:
3332 cfi_cfa_offset = cfi;
3334 case DW_CFA_def_cfa_register:
3337 case DW_CFA_def_cfa_offset:
3338 case DW_CFA_def_cfa_offset_sf:
3339 cfi_cfa_offset = cfi;
3342 gcc_assert (cfi == NULL);
3344 len = VEC_length (dw_cfi_ref, regs);
3345 for (idx = 0; idx < len; idx++)
3347 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3349 && cfi2->dw_cfi_opc != DW_CFA_restore
3350 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3353 output_cfi_directive (cfi2);
3355 output_cfi (cfi2, fde, for_eh);
3358 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3360 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3362 switch (cfi_cfa_offset->dw_cfi_opc)
3364 case DW_CFA_def_cfa_offset:
3365 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3366 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3368 case DW_CFA_def_cfa_offset_sf:
3369 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3370 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3372 case DW_CFA_def_cfa:
3373 case DW_CFA_def_cfa_sf:
3374 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3375 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3382 else if (cfi_cfa_offset)
3383 cfi_cfa = cfi_cfa_offset;
3387 output_cfi_directive (cfi_cfa);
3389 output_cfi (cfi_cfa, fde, for_eh);
3392 cfi_cfa_offset = NULL;
3394 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3397 output_cfi_directive (cfi_args_size);
3399 output_cfi (cfi_args_size, fde, for_eh);
3401 cfi_args_size = NULL;
3404 VEC_free (dw_cfi_ref, heap, regs);
3407 else if (do_cfi_asm)
3408 output_cfi_directive (cfi);
3410 output_cfi (cfi, fde, for_eh);
3417 /* Output one FDE. */
3420 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3421 char *section_start_label, int fde_encoding, char *augmentation,
3422 bool any_lsda_needed, int lsda_encoding)
3424 const char *begin, *end;
3425 static unsigned int j;
3426 char l1[20], l2[20];
3429 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh,
3431 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3433 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3434 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3435 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3436 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3437 " indicating 64-bit DWARF extension");
3438 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3440 ASM_OUTPUT_LABEL (asm_out_file, l1);
3443 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3445 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3446 debug_frame_section, "FDE CIE offset");
3448 if (!fde->dw_fde_switched_sections)
3450 begin = fde->dw_fde_begin;
3451 end = fde->dw_fde_end;
3455 /* For the first section, prefer dw_fde_begin over
3456 dw_fde_{hot,cold}_section_label, as the latter
3457 might be separated from the real start of the
3458 function by alignment padding. */
3460 begin = fde->dw_fde_begin;
3461 else if (fde->dw_fde_switched_cold_to_hot)
3462 begin = fde->dw_fde_hot_section_label;
3464 begin = fde->dw_fde_unlikely_section_label;
3465 if (second ^ fde->dw_fde_switched_cold_to_hot)
3466 end = fde->dw_fde_unlikely_section_end_label;
3468 end = fde->dw_fde_hot_section_end_label;
3473 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3474 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3475 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3476 "FDE initial location");
3477 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3478 end, begin, "FDE address range");
3482 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3483 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3486 if (augmentation[0])
3488 if (any_lsda_needed)
3490 int size = size_of_encoded_value (lsda_encoding);
3492 if (lsda_encoding == DW_EH_PE_aligned)
3494 int offset = ( 4 /* Length */
3495 + 4 /* CIE offset */
3496 + 2 * size_of_encoded_value (fde_encoding)
3497 + 1 /* Augmentation size */ );
3498 int pad = -offset & (PTR_SIZE - 1);
3501 gcc_assert (size_of_uleb128 (size) == 1);
3504 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3506 if (fde->uses_eh_lsda)
3508 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3509 fde->funcdef_number);
3510 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3511 gen_rtx_SYMBOL_REF (Pmode, l1),
3513 "Language Specific Data Area");
3517 if (lsda_encoding == DW_EH_PE_aligned)
3518 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3519 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3520 "Language Specific Data Area (none)");
3524 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3527 /* Loop through the Call Frame Instructions associated with
3529 fde->dw_fde_current_label = begin;
3530 if (!fde->dw_fde_switched_sections)
3531 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3532 output_cfi (cfi, fde, for_eh);
3535 if (fde->dw_fde_switch_cfi)
3536 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3538 output_cfi (cfi, fde, for_eh);
3539 if (cfi == fde->dw_fde_switch_cfi)
3545 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3547 if (fde->dw_fde_switch_cfi)
3549 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3550 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3551 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3552 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3554 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3555 output_cfi (cfi, fde, for_eh);
3558 /* If we are to emit a ref/link from function bodies to their frame tables,