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 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE)
184 #ifdef TARGET_UNWIND_INFO
187 if (USING_SJLJ_EXCEPTIONS || (!flag_unwind_tables && !flag_exceptions))
192 saved_do_cfi_asm = true;
196 /* The size of the target's pointer type. */
198 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
201 /* Array of RTXes referenced by the debugging information, which therefore
202 must be kept around forever. */
203 static GTY(()) VEC(rtx,gc) *used_rtx_array;
205 /* A pointer to the base of a list of incomplete types which might be
206 completed at some later time. incomplete_types_list needs to be a
207 VEC(tree,gc) because we want to tell the garbage collector about
209 static GTY(()) VEC(tree,gc) *incomplete_types;
211 /* A pointer to the base of a table of references to declaration
212 scopes. This table is a display which tracks the nesting
213 of declaration scopes at the current scope and containing
214 scopes. This table is used to find the proper place to
215 define type declaration DIE's. */
216 static GTY(()) VEC(tree,gc) *decl_scope_table;
218 /* Pointers to various DWARF2 sections. */
219 static GTY(()) section *debug_info_section;
220 static GTY(()) section *debug_abbrev_section;
221 static GTY(()) section *debug_aranges_section;
222 static GTY(()) section *debug_macinfo_section;
223 static GTY(()) section *debug_line_section;
224 static GTY(()) section *debug_loc_section;
225 static GTY(()) section *debug_pubnames_section;
226 static GTY(()) section *debug_pubtypes_section;
227 static GTY(()) section *debug_str_section;
228 static GTY(()) section *debug_ranges_section;
229 static GTY(()) section *debug_frame_section;
231 /* Personality decl of current unit. Used only when assembler does not support
233 static GTY(()) rtx current_unit_personality;
235 /* How to start an assembler comment. */
236 #ifndef ASM_COMMENT_START
237 #define ASM_COMMENT_START ";#"
240 typedef struct dw_cfi_struct *dw_cfi_ref;
241 typedef struct dw_fde_struct *dw_fde_ref;
242 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
244 /* Call frames are described using a sequence of Call Frame
245 Information instructions. The register number, offset
246 and address fields are provided as possible operands;
247 their use is selected by the opcode field. */
249 enum dw_cfi_oprnd_type {
251 dw_cfi_oprnd_reg_num,
257 typedef union GTY(()) dw_cfi_oprnd_struct {
258 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
259 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
260 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
261 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
265 typedef struct GTY(()) dw_cfi_struct {
266 dw_cfi_ref dw_cfi_next;
267 enum dwarf_call_frame_info dw_cfi_opc;
268 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
270 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
275 /* This is how we define the location of the CFA. We use to handle it
276 as REG + OFFSET all the time, but now it can be more complex.
277 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
278 Instead of passing around REG and OFFSET, we pass a copy
279 of this structure. */
280 typedef struct GTY(()) cfa_loc {
281 HOST_WIDE_INT offset;
282 HOST_WIDE_INT base_offset;
284 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
285 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
288 /* All call frame descriptions (FDE's) in the GCC generated DWARF
289 refer to a single Common Information Entry (CIE), defined at
290 the beginning of the .debug_frame section. This use of a single
291 CIE obviates the need to keep track of multiple CIE's
292 in the DWARF generation routines below. */
294 typedef struct GTY(()) dw_fde_struct {
296 const char *dw_fde_begin;
297 const char *dw_fde_current_label;
298 const char *dw_fde_end;
299 const char *dw_fde_hot_section_label;
300 const char *dw_fde_hot_section_end_label;
301 const char *dw_fde_unlikely_section_label;
302 const char *dw_fde_unlikely_section_end_label;
303 dw_cfi_ref dw_fde_cfi;
304 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
305 unsigned funcdef_number;
306 HOST_WIDE_INT stack_realignment;
307 /* Dynamic realign argument pointer register. */
308 unsigned int drap_reg;
309 /* Virtual dynamic realign argument pointer register. */
310 unsigned int vdrap_reg;
311 unsigned all_throwers_are_sibcalls : 1;
312 unsigned nothrow : 1;
313 unsigned uses_eh_lsda : 1;
314 /* Whether we did stack realign in this call frame. */
315 unsigned stack_realign : 1;
316 /* Whether dynamic realign argument pointer register has been saved. */
317 unsigned drap_reg_saved: 1;
318 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
319 unsigned in_std_section : 1;
320 /* True iff dw_fde_unlikely_section_label is in text_section or
321 cold_text_section. */
322 unsigned cold_in_std_section : 1;
323 /* True iff switched sections. */
324 unsigned dw_fde_switched_sections : 1;
325 /* True iff switching from cold to hot section. */
326 unsigned dw_fde_switched_cold_to_hot : 1;
330 /* Maximum size (in bytes) of an artificially generated label. */
331 #define MAX_ARTIFICIAL_LABEL_BYTES 30
333 /* The size of addresses as they appear in the Dwarf 2 data.
334 Some architectures use word addresses to refer to code locations,
335 but Dwarf 2 info always uses byte addresses. On such machines,
336 Dwarf 2 addresses need to be larger than the architecture's
338 #ifndef DWARF2_ADDR_SIZE
339 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
342 /* The size in bytes of a DWARF field indicating an offset or length
343 relative to a debug info section, specified to be 4 bytes in the
344 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
347 #ifndef DWARF_OFFSET_SIZE
348 #define DWARF_OFFSET_SIZE 4
351 /* According to the (draft) DWARF 3 specification, the initial length
352 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
353 bytes are 0xffffffff, followed by the length stored in the next 8
356 However, the SGI/MIPS ABI uses an initial length which is equal to
357 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
359 #ifndef DWARF_INITIAL_LENGTH_SIZE
360 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
363 /* Round SIZE up to the nearest BOUNDARY. */
364 #define DWARF_ROUND(SIZE,BOUNDARY) \
365 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
367 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
368 #ifndef DWARF_CIE_DATA_ALIGNMENT
369 #ifdef STACK_GROWS_DOWNWARD
370 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
372 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
376 /* CIE identifier. */
377 #if HOST_BITS_PER_WIDE_INT >= 64
378 #define DWARF_CIE_ID \
379 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
381 #define DWARF_CIE_ID DW_CIE_ID
384 /* A pointer to the base of a table that contains frame description
385 information for each routine. */
386 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
388 /* Number of elements currently allocated for fde_table. */
389 static GTY(()) unsigned fde_table_allocated;
391 /* Number of elements in fde_table currently in use. */
392 static GTY(()) unsigned fde_table_in_use;
394 /* Size (in elements) of increments by which we may expand the
396 #define FDE_TABLE_INCREMENT 256
398 /* Get the current fde_table entry we should use. */
400 static inline dw_fde_ref
403 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
406 /* A list of call frame insns for the CIE. */
407 static GTY(()) dw_cfi_ref cie_cfi_head;
409 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
410 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
411 attribute that accelerates the lookup of the FDE associated
412 with the subprogram. This variable holds the table index of the FDE
413 associated with the current function (body) definition. */
414 static unsigned current_funcdef_fde;
417 struct GTY(()) indirect_string_node {
419 unsigned int refcount;
420 enum dwarf_form form;
424 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
426 /* True if the compilation unit has location entries that reference
428 static GTY(()) bool debug_str_hash_forced = false;
430 static GTY(()) int dw2_string_counter;
431 static GTY(()) unsigned long dwarf2out_cfi_label_num;
433 /* True if the compilation unit places functions in more than one section. */
434 static GTY(()) bool have_multiple_function_sections = false;
436 /* Whether the default text and cold text sections have been used at all. */
438 static GTY(()) bool text_section_used = false;
439 static GTY(()) bool cold_text_section_used = false;
441 /* The default cold text section. */
442 static GTY(()) section *cold_text_section;
444 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
446 /* Forward declarations for functions defined in this file. */
448 static char *stripattributes (const char *);
449 static const char *dwarf_cfi_name (unsigned);
450 static dw_cfi_ref new_cfi (void);
451 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
452 static void add_fde_cfi (const char *, dw_cfi_ref);
453 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
454 static void lookup_cfa (dw_cfa_location *);
455 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
456 #ifdef DWARF2_UNWIND_INFO
457 static void initial_return_save (rtx);
459 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
461 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
462 static void output_cfi_directive (dw_cfi_ref);
463 static void output_call_frame_info (int);
464 static void dwarf2out_note_section_used (void);
465 static void dwarf2out_stack_adjust (rtx, bool);
466 static void dwarf2out_args_size_adjust (HOST_WIDE_INT, const char *);
467 static void flush_queued_reg_saves (void);
468 static bool clobbers_queued_reg_save (const_rtx);
469 static void dwarf2out_frame_debug_expr (rtx, const char *);
471 /* Support for complex CFA locations. */
472 static void output_cfa_loc (dw_cfi_ref);
473 static void output_cfa_loc_raw (dw_cfi_ref);
474 static void get_cfa_from_loc_descr (dw_cfa_location *,
475 struct dw_loc_descr_struct *);
476 static struct dw_loc_descr_struct *build_cfa_loc
477 (dw_cfa_location *, HOST_WIDE_INT);
478 static struct dw_loc_descr_struct *build_cfa_aligned_loc
479 (HOST_WIDE_INT, HOST_WIDE_INT);
480 static void def_cfa_1 (const char *, dw_cfa_location *);
482 /* How to start an assembler comment. */
483 #ifndef ASM_COMMENT_START
484 #define ASM_COMMENT_START ";#"
487 /* Data and reference forms for relocatable data. */
488 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
489 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
491 #ifndef DEBUG_FRAME_SECTION
492 #define DEBUG_FRAME_SECTION ".debug_frame"
495 #ifndef FUNC_BEGIN_LABEL
496 #define FUNC_BEGIN_LABEL "LFB"
499 #ifndef FUNC_END_LABEL
500 #define FUNC_END_LABEL "LFE"
503 #ifndef FRAME_BEGIN_LABEL
504 #define FRAME_BEGIN_LABEL "Lframe"
506 #define CIE_AFTER_SIZE_LABEL "LSCIE"
507 #define CIE_END_LABEL "LECIE"
508 #define FDE_LABEL "LSFDE"
509 #define FDE_AFTER_SIZE_LABEL "LASFDE"
510 #define FDE_END_LABEL "LEFDE"
511 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
512 #define LINE_NUMBER_END_LABEL "LELT"
513 #define LN_PROLOG_AS_LABEL "LASLTP"
514 #define LN_PROLOG_END_LABEL "LELTP"
515 #define DIE_LABEL_PREFIX "DW"
517 /* The DWARF 2 CFA column which tracks the return address. Normally this
518 is the column for PC, or the first column after all of the hard
520 #ifndef DWARF_FRAME_RETURN_COLUMN
522 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
524 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
528 /* The mapping from gcc register number to DWARF 2 CFA column number. By
529 default, we just provide columns for all registers. */
530 #ifndef DWARF_FRAME_REGNUM
531 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
534 /* Hook used by __throw. */
537 expand_builtin_dwarf_sp_column (void)
539 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
540 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
543 /* Return a pointer to a copy of the section string name S with all
544 attributes stripped off, and an asterisk prepended (for assemble_name). */
547 stripattributes (const char *s)
549 char *stripped = XNEWVEC (char, strlen (s) + 2);
554 while (*s && *s != ',')
561 /* MEM is a memory reference for the register size table, each element of
562 which has mode MODE. Initialize column C as a return address column. */
565 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
567 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
568 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
569 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
572 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
574 static inline HOST_WIDE_INT
575 div_data_align (HOST_WIDE_INT off)
577 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
578 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
582 /* Return true if we need a signed version of a given opcode
583 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
586 need_data_align_sf_opcode (HOST_WIDE_INT off)
588 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
591 /* Generate code to initialize the register size table. */
594 expand_builtin_init_dwarf_reg_sizes (tree address)
597 enum machine_mode mode = TYPE_MODE (char_type_node);
598 rtx addr = expand_normal (address);
599 rtx mem = gen_rtx_MEM (BLKmode, addr);
600 bool wrote_return_column = false;
602 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
604 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
606 if (rnum < DWARF_FRAME_REGISTERS)
608 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
609 enum machine_mode save_mode = reg_raw_mode[i];
612 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
613 save_mode = choose_hard_reg_mode (i, 1, true);
614 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
616 if (save_mode == VOIDmode)
618 wrote_return_column = true;
620 size = GET_MODE_SIZE (save_mode);
624 emit_move_insn (adjust_address (mem, mode, offset),
625 gen_int_mode (size, mode));
629 if (!wrote_return_column)
630 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
632 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
633 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
636 targetm.init_dwarf_reg_sizes_extra (address);
639 /* Convert a DWARF call frame info. operation to its string name */
642 dwarf_cfi_name (unsigned int cfi_opc)
646 case DW_CFA_advance_loc:
647 return "DW_CFA_advance_loc";
649 return "DW_CFA_offset";
651 return "DW_CFA_restore";
655 return "DW_CFA_set_loc";
656 case DW_CFA_advance_loc1:
657 return "DW_CFA_advance_loc1";
658 case DW_CFA_advance_loc2:
659 return "DW_CFA_advance_loc2";
660 case DW_CFA_advance_loc4:
661 return "DW_CFA_advance_loc4";
662 case DW_CFA_offset_extended:
663 return "DW_CFA_offset_extended";
664 case DW_CFA_restore_extended:
665 return "DW_CFA_restore_extended";
666 case DW_CFA_undefined:
667 return "DW_CFA_undefined";
668 case DW_CFA_same_value:
669 return "DW_CFA_same_value";
670 case DW_CFA_register:
671 return "DW_CFA_register";
672 case DW_CFA_remember_state:
673 return "DW_CFA_remember_state";
674 case DW_CFA_restore_state:
675 return "DW_CFA_restore_state";
677 return "DW_CFA_def_cfa";
678 case DW_CFA_def_cfa_register:
679 return "DW_CFA_def_cfa_register";
680 case DW_CFA_def_cfa_offset:
681 return "DW_CFA_def_cfa_offset";
684 case DW_CFA_def_cfa_expression:
685 return "DW_CFA_def_cfa_expression";
686 case DW_CFA_expression:
687 return "DW_CFA_expression";
688 case DW_CFA_offset_extended_sf:
689 return "DW_CFA_offset_extended_sf";
690 case DW_CFA_def_cfa_sf:
691 return "DW_CFA_def_cfa_sf";
692 case DW_CFA_def_cfa_offset_sf:
693 return "DW_CFA_def_cfa_offset_sf";
695 /* SGI/MIPS specific */
696 case DW_CFA_MIPS_advance_loc8:
697 return "DW_CFA_MIPS_advance_loc8";
700 case DW_CFA_GNU_window_save:
701 return "DW_CFA_GNU_window_save";
702 case DW_CFA_GNU_args_size:
703 return "DW_CFA_GNU_args_size";
704 case DW_CFA_GNU_negative_offset_extended:
705 return "DW_CFA_GNU_negative_offset_extended";
708 return "DW_CFA_<unknown>";
712 /* Return a pointer to a newly allocated Call Frame Instruction. */
714 static inline dw_cfi_ref
717 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
719 cfi->dw_cfi_next = NULL;
720 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
721 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
726 /* Add a Call Frame Instruction to list of instructions. */
729 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
732 dw_fde_ref fde = current_fde ();
734 /* When DRAP is used, CFA is defined with an expression. Redefine
735 CFA may lead to a different CFA value. */
736 /* ??? Of course, this heuristic fails when we're annotating epilogues,
737 because of course we'll always want to redefine the CFA back to the
738 stack pointer on the way out. Where should we move this check? */
739 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
740 switch (cfi->dw_cfi_opc)
742 case DW_CFA_def_cfa_register:
743 case DW_CFA_def_cfa_offset:
744 case DW_CFA_def_cfa_offset_sf:
746 case DW_CFA_def_cfa_sf:
753 /* Find the end of the chain. */
754 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
760 /* Generate a new label for the CFI info to refer to. FORCE is true
761 if a label needs to be output even when using .cfi_* directives. */
764 dwarf2out_cfi_label (bool force)
766 static char label[20];
768 if (!force && dwarf2out_do_cfi_asm ())
770 /* In this case, we will be emitting the asm directive instead of
771 the label, so just return a placeholder to keep the rest of the
773 strcpy (label, "<do not output>");
777 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
778 ASM_OUTPUT_LABEL (asm_out_file, label);
784 /* True if remember_state should be emitted before following CFI directive. */
785 static bool emit_cfa_remember;
787 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
788 or to the CIE if LABEL is NULL. */
791 add_fde_cfi (const char *label, dw_cfi_ref cfi)
793 dw_cfi_ref *list_head;
795 if (emit_cfa_remember)
797 dw_cfi_ref cfi_remember;
799 /* Emit the state save. */
800 emit_cfa_remember = false;
801 cfi_remember = new_cfi ();
802 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
803 add_fde_cfi (label, cfi_remember);
806 list_head = &cie_cfi_head;
808 if (dwarf2out_do_cfi_asm ())
812 dw_fde_ref fde = current_fde ();
814 gcc_assert (fde != NULL);
816 /* We still have to add the cfi to the list so that lookup_cfa
817 works later on. When -g2 and above we even need to force
818 emitting of CFI labels and add to list a DW_CFA_set_loc for
819 convert_cfa_to_fb_loc_list purposes. If we're generating
820 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
821 convert_cfa_to_fb_loc_list. */
822 if (dwarf_version == 2
823 && debug_info_level > DINFO_LEVEL_TERSE
824 && (write_symbols == DWARF2_DEBUG
825 || write_symbols == VMS_AND_DWARF2_DEBUG))
827 switch (cfi->dw_cfi_opc)
829 case DW_CFA_def_cfa_offset:
830 case DW_CFA_def_cfa_offset_sf:
831 case DW_CFA_def_cfa_register:
833 case DW_CFA_def_cfa_sf:
834 case DW_CFA_def_cfa_expression:
835 case DW_CFA_restore_state:
836 if (*label == 0 || strcmp (label, "<do not output>") == 0)
837 label = dwarf2out_cfi_label (true);
839 if (fde->dw_fde_current_label == NULL
840 || strcmp (label, fde->dw_fde_current_label) != 0)
844 label = xstrdup (label);
846 /* Set the location counter to the new label. */
848 /* It doesn't metter whether DW_CFA_set_loc
849 or DW_CFA_advance_loc4 is added here, those aren't
850 emitted into assembly, only looked up by
851 convert_cfa_to_fb_loc_list. */
852 xcfi->dw_cfi_opc = DW_CFA_set_loc;
853 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
854 add_cfi (&fde->dw_fde_cfi, xcfi);
855 fde->dw_fde_current_label = label;
863 output_cfi_directive (cfi);
865 list_head = &fde->dw_fde_cfi;
867 /* ??? If this is a CFI for the CIE, we don't emit. This
868 assumes that the standard CIE contents that the assembler
869 uses matches the standard CIE contents that the compiler
870 uses. This is probably a bad assumption. I'm not quite
871 sure how to address this for now. */
875 dw_fde_ref fde = current_fde ();
877 gcc_assert (fde != NULL);
880 label = dwarf2out_cfi_label (false);
882 if (fde->dw_fde_current_label == NULL
883 || strcmp (label, fde->dw_fde_current_label) != 0)
887 label = xstrdup (label);
889 /* Set the location counter to the new label. */
891 /* If we have a current label, advance from there, otherwise
892 set the location directly using set_loc. */
893 xcfi->dw_cfi_opc = fde->dw_fde_current_label
894 ? DW_CFA_advance_loc4
896 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
897 add_cfi (&fde->dw_fde_cfi, xcfi);
899 fde->dw_fde_current_label = label;
902 list_head = &fde->dw_fde_cfi;
905 add_cfi (list_head, cfi);
908 /* Subroutine of lookup_cfa. */
911 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
913 switch (cfi->dw_cfi_opc)
915 case DW_CFA_def_cfa_offset:
916 case DW_CFA_def_cfa_offset_sf:
917 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
919 case DW_CFA_def_cfa_register:
920 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
923 case DW_CFA_def_cfa_sf:
924 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
925 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
927 case DW_CFA_def_cfa_expression:
928 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
931 case DW_CFA_remember_state:
932 gcc_assert (!remember->in_use);
934 remember->in_use = 1;
936 case DW_CFA_restore_state:
937 gcc_assert (remember->in_use);
939 remember->in_use = 0;
947 /* Find the previous value for the CFA. */
950 lookup_cfa (dw_cfa_location *loc)
954 dw_cfa_location remember;
956 memset (loc, 0, sizeof (*loc));
957 loc->reg = INVALID_REGNUM;
960 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
961 lookup_cfa_1 (cfi, loc, &remember);
963 fde = current_fde ();
965 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
966 lookup_cfa_1 (cfi, loc, &remember);
969 /* The current rule for calculating the DWARF2 canonical frame address. */
970 static dw_cfa_location cfa;
972 /* The register used for saving registers to the stack, and its offset
974 static dw_cfa_location cfa_store;
976 /* The current save location around an epilogue. */
977 static dw_cfa_location cfa_remember;
979 /* The running total of the size of arguments pushed onto the stack. */
980 static HOST_WIDE_INT args_size;
982 /* The last args_size we actually output. */
983 static HOST_WIDE_INT old_args_size;
985 /* Entry point to update the canonical frame address (CFA).
986 LABEL is passed to add_fde_cfi. The value of CFA is now to be
987 calculated from REG+OFFSET. */
990 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
997 def_cfa_1 (label, &loc);
1000 /* Determine if two dw_cfa_location structures define the same data. */
1003 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1005 return (loc1->reg == loc2->reg
1006 && loc1->offset == loc2->offset
1007 && loc1->indirect == loc2->indirect
1008 && (loc1->indirect == 0
1009 || loc1->base_offset == loc2->base_offset));
1012 /* This routine does the actual work. The CFA is now calculated from
1013 the dw_cfa_location structure. */
1016 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1019 dw_cfa_location old_cfa, loc;
1024 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1025 cfa_store.offset = loc.offset;
1027 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1028 lookup_cfa (&old_cfa);
1030 /* If nothing changed, no need to issue any call frame instructions. */
1031 if (cfa_equal_p (&loc, &old_cfa))
1036 if (loc.reg == old_cfa.reg && !loc.indirect)
1038 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1039 the CFA register did not change but the offset did. The data
1040 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1041 in the assembler via the .cfi_def_cfa_offset directive. */
1043 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1045 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1046 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1049 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1050 else if (loc.offset == old_cfa.offset
1051 && old_cfa.reg != INVALID_REGNUM
1054 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1055 indicating the CFA register has changed to <register> but the
1056 offset has not changed. */
1057 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1058 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1062 else if (loc.indirect == 0)
1064 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1065 indicating the CFA register has changed to <register> with
1066 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1067 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1070 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1072 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1073 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1074 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1078 /* Construct a DW_CFA_def_cfa_expression instruction to
1079 calculate the CFA using a full location expression since no
1080 register-offset pair is available. */
1081 struct dw_loc_descr_struct *loc_list;
1083 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1084 loc_list = build_cfa_loc (&loc, 0);
1085 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1088 add_fde_cfi (label, cfi);
1091 /* Add the CFI for saving a register. REG is the CFA column number.
1092 LABEL is passed to add_fde_cfi.
1093 If SREG is -1, the register is saved at OFFSET from the CFA;
1094 otherwise it is saved in SREG. */
1097 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1099 dw_cfi_ref cfi = new_cfi ();
1100 dw_fde_ref fde = current_fde ();
1102 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1104 /* When stack is aligned, store REG using DW_CFA_expression with
1107 && fde->stack_realign
1108 && sreg == INVALID_REGNUM)
1110 cfi->dw_cfi_opc = DW_CFA_expression;
1111 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = reg;
1112 cfi->dw_cfi_oprnd1.dw_cfi_loc
1113 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1115 else if (sreg == INVALID_REGNUM)
1117 if (need_data_align_sf_opcode (offset))
1118 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1119 else if (reg & ~0x3f)
1120 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1122 cfi->dw_cfi_opc = DW_CFA_offset;
1123 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1125 else if (sreg == reg)
1126 cfi->dw_cfi_opc = DW_CFA_same_value;
1129 cfi->dw_cfi_opc = DW_CFA_register;
1130 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1133 add_fde_cfi (label, cfi);
1136 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1137 This CFI tells the unwinder that it needs to restore the window registers
1138 from the previous frame's window save area.
1140 ??? Perhaps we should note in the CIE where windows are saved (instead of
1141 assuming 0(cfa)) and what registers are in the window. */
1144 dwarf2out_window_save (const char *label)
1146 dw_cfi_ref cfi = new_cfi ();
1148 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1149 add_fde_cfi (label, cfi);
1152 /* Add a CFI to update the running total of the size of arguments
1153 pushed onto the stack. */
1156 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1160 if (size == old_args_size)
1163 old_args_size = size;
1166 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1167 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1168 add_fde_cfi (label, cfi);
1171 /* Entry point for saving a register to the stack. REG is the GCC register
1172 number. LABEL and OFFSET are passed to reg_save. */
1175 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1177 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1180 /* Entry point for saving the return address in the stack.
1181 LABEL and OFFSET are passed to reg_save. */
1184 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1186 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1189 /* Entry point for saving the return address in a register.
1190 LABEL and SREG are passed to reg_save. */
1193 dwarf2out_return_reg (const char *label, unsigned int sreg)
1195 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1198 #ifdef DWARF2_UNWIND_INFO
1199 /* Record the initial position of the return address. RTL is
1200 INCOMING_RETURN_ADDR_RTX. */
1203 initial_return_save (rtx rtl)
1205 unsigned int reg = INVALID_REGNUM;
1206 HOST_WIDE_INT offset = 0;
1208 switch (GET_CODE (rtl))
1211 /* RA is in a register. */
1212 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1216 /* RA is on the stack. */
1217 rtl = XEXP (rtl, 0);
1218 switch (GET_CODE (rtl))
1221 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1226 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1227 offset = INTVAL (XEXP (rtl, 1));
1231 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1232 offset = -INTVAL (XEXP (rtl, 1));
1242 /* The return address is at some offset from any value we can
1243 actually load. For instance, on the SPARC it is in %i7+8. Just
1244 ignore the offset for now; it doesn't matter for unwinding frames. */
1245 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1246 initial_return_save (XEXP (rtl, 0));
1253 if (reg != DWARF_FRAME_RETURN_COLUMN)
1254 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1258 /* Given a SET, calculate the amount of stack adjustment it
1261 static HOST_WIDE_INT
1262 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1263 HOST_WIDE_INT cur_offset)
1265 const_rtx src = SET_SRC (pattern);
1266 const_rtx dest = SET_DEST (pattern);
1267 HOST_WIDE_INT offset = 0;
1270 if (dest == stack_pointer_rtx)
1272 code = GET_CODE (src);
1274 /* Assume (set (reg sp) (reg whatever)) sets args_size
1276 if (code == REG && src != stack_pointer_rtx)
1278 offset = -cur_args_size;
1279 #ifndef STACK_GROWS_DOWNWARD
1282 return offset - cur_offset;
1285 if (! (code == PLUS || code == MINUS)
1286 || XEXP (src, 0) != stack_pointer_rtx
1287 || !CONST_INT_P (XEXP (src, 1)))
1290 /* (set (reg sp) (plus (reg sp) (const_int))) */
1291 offset = INTVAL (XEXP (src, 1));
1297 if (MEM_P (src) && !MEM_P (dest))
1301 /* (set (mem (pre_dec (reg sp))) (foo)) */
1302 src = XEXP (dest, 0);
1303 code = GET_CODE (src);
1309 if (XEXP (src, 0) == stack_pointer_rtx)
1311 rtx val = XEXP (XEXP (src, 1), 1);
1312 /* We handle only adjustments by constant amount. */
1313 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1314 && CONST_INT_P (val));
1315 offset = -INTVAL (val);
1322 if (XEXP (src, 0) == stack_pointer_rtx)
1324 offset = GET_MODE_SIZE (GET_MODE (dest));
1331 if (XEXP (src, 0) == stack_pointer_rtx)
1333 offset = -GET_MODE_SIZE (GET_MODE (dest));
1348 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1349 indexed by INSN_UID. */
1351 static HOST_WIDE_INT *barrier_args_size;
1353 /* Helper function for compute_barrier_args_size. Handle one insn. */
1355 static HOST_WIDE_INT
1356 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1357 VEC (rtx, heap) **next)
1359 HOST_WIDE_INT offset = 0;
1362 if (! RTX_FRAME_RELATED_P (insn))
1364 if (prologue_epilogue_contains (insn))
1366 else if (GET_CODE (PATTERN (insn)) == SET)
1367 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1368 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1369 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1371 /* There may be stack adjustments inside compound insns. Search
1373 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1374 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1375 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1376 cur_args_size, offset);
1381 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1385 expr = XEXP (expr, 0);
1386 if (GET_CODE (expr) == PARALLEL
1387 || GET_CODE (expr) == SEQUENCE)
1388 for (i = 1; i < XVECLEN (expr, 0); i++)
1390 rtx elem = XVECEXP (expr, 0, i);
1392 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1393 offset += stack_adjust_offset (elem, cur_args_size, offset);
1398 #ifndef STACK_GROWS_DOWNWARD
1402 cur_args_size += offset;
1403 if (cur_args_size < 0)
1408 rtx dest = JUMP_LABEL (insn);
1412 if (barrier_args_size [INSN_UID (dest)] < 0)
1414 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1415 VEC_safe_push (rtx, heap, *next, dest);
1420 return cur_args_size;
1423 /* Walk the whole function and compute args_size on BARRIERs. */
1426 compute_barrier_args_size (void)
1428 int max_uid = get_max_uid (), i;
1430 VEC (rtx, heap) *worklist, *next, *tmp;
1432 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1433 for (i = 0; i < max_uid; i++)
1434 barrier_args_size[i] = -1;
1436 worklist = VEC_alloc (rtx, heap, 20);
1437 next = VEC_alloc (rtx, heap, 20);
1438 insn = get_insns ();
1439 barrier_args_size[INSN_UID (insn)] = 0;
1440 VEC_quick_push (rtx, worklist, insn);
1443 while (!VEC_empty (rtx, worklist))
1445 rtx prev, body, first_insn;
1446 HOST_WIDE_INT cur_args_size;
1448 first_insn = insn = VEC_pop (rtx, worklist);
1449 cur_args_size = barrier_args_size[INSN_UID (insn)];
1450 prev = prev_nonnote_insn (insn);
1451 if (prev && BARRIER_P (prev))
1452 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1454 for (; insn; insn = NEXT_INSN (insn))
1456 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1458 if (BARRIER_P (insn))
1463 if (insn == first_insn)
1465 else if (barrier_args_size[INSN_UID (insn)] < 0)
1467 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1472 /* The insns starting with this label have been
1473 already scanned or are in the worklist. */
1478 body = PATTERN (insn);
1479 if (GET_CODE (body) == SEQUENCE)
1481 HOST_WIDE_INT dest_args_size = cur_args_size;
1482 for (i = 1; i < XVECLEN (body, 0); i++)
1483 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1484 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1486 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1487 dest_args_size, &next);
1490 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1491 cur_args_size, &next);
1493 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1494 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1495 dest_args_size, &next);
1498 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1499 cur_args_size, &next);
1503 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1507 if (VEC_empty (rtx, next))
1510 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1514 VEC_truncate (rtx, next, 0);
1517 VEC_free (rtx, heap, worklist);
1518 VEC_free (rtx, heap, next);
1522 /* Check INSN to see if it looks like a push or a stack adjustment, and
1523 make a note of it if it does. EH uses this information to find out how
1524 much extra space it needs to pop off the stack. */
1527 dwarf2out_stack_adjust (rtx insn, bool after_p)
1529 HOST_WIDE_INT offset;
1533 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1534 with this function. Proper support would require all frame-related
1535 insns to be marked, and to be able to handle saving state around
1536 epilogues textually in the middle of the function. */
1537 if (prologue_epilogue_contains (insn))
1540 /* If INSN is an instruction from target of an annulled branch, the
1541 effects are for the target only and so current argument size
1542 shouldn't change at all. */
1544 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1545 && INSN_FROM_TARGET_P (insn))
1548 /* If only calls can throw, and we have a frame pointer,
1549 save up adjustments until we see the CALL_INSN. */
1550 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1552 if (CALL_P (insn) && !after_p)
1554 /* Extract the size of the args from the CALL rtx itself. */
1555 insn = PATTERN (insn);
1556 if (GET_CODE (insn) == PARALLEL)
1557 insn = XVECEXP (insn, 0, 0);
1558 if (GET_CODE (insn) == SET)
1559 insn = SET_SRC (insn);
1560 gcc_assert (GET_CODE (insn) == CALL);
1561 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1566 if (CALL_P (insn) && !after_p)
1568 if (!flag_asynchronous_unwind_tables)
1569 dwarf2out_args_size ("", args_size);
1572 else if (BARRIER_P (insn))
1574 /* Don't call compute_barrier_args_size () if the only
1575 BARRIER is at the end of function. */
1576 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1577 compute_barrier_args_size ();
1578 if (barrier_args_size == NULL)
1582 offset = barrier_args_size[INSN_UID (insn)];
1587 offset -= args_size;
1588 #ifndef STACK_GROWS_DOWNWARD
1592 else if (GET_CODE (PATTERN (insn)) == SET)
1593 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1594 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1595 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1597 /* There may be stack adjustments inside compound insns. Search
1599 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1600 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1601 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1610 label = dwarf2out_cfi_label (false);
1611 dwarf2out_args_size_adjust (offset, label);
1614 /* Adjust args_size based on stack adjustment OFFSET. */
1617 dwarf2out_args_size_adjust (HOST_WIDE_INT offset, const char *label)
1619 if (cfa.reg == STACK_POINTER_REGNUM)
1620 cfa.offset += offset;
1622 if (cfa_store.reg == STACK_POINTER_REGNUM)
1623 cfa_store.offset += offset;
1625 #ifndef STACK_GROWS_DOWNWARD
1629 args_size += offset;
1633 def_cfa_1 (label, &cfa);
1634 if (flag_asynchronous_unwind_tables)
1635 dwarf2out_args_size (label, args_size);
1640 /* We delay emitting a register save until either (a) we reach the end
1641 of the prologue or (b) the register is clobbered. This clusters
1642 register saves so that there are fewer pc advances. */
1644 struct GTY(()) queued_reg_save {
1645 struct queued_reg_save *next;
1647 HOST_WIDE_INT cfa_offset;
1651 static GTY(()) struct queued_reg_save *queued_reg_saves;
1653 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1654 struct GTY(()) reg_saved_in_data {
1659 /* A list of registers saved in other registers.
1660 The list intentionally has a small maximum capacity of 4; if your
1661 port needs more than that, you might consider implementing a
1662 more efficient data structure. */
1663 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1664 static GTY(()) size_t num_regs_saved_in_regs;
1666 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1667 static const char *last_reg_save_label;
1669 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1670 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1673 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1675 struct queued_reg_save *q;
1677 /* Duplicates waste space, but it's also necessary to remove them
1678 for correctness, since the queue gets output in reverse
1680 for (q = queued_reg_saves; q != NULL; q = q->next)
1681 if (REGNO (q->reg) == REGNO (reg))
1686 q = GGC_NEW (struct queued_reg_save);
1687 q->next = queued_reg_saves;
1688 queued_reg_saves = q;
1692 q->cfa_offset = offset;
1693 q->saved_reg = sreg;
1695 last_reg_save_label = label;
1698 /* Output all the entries in QUEUED_REG_SAVES. */
1701 flush_queued_reg_saves (void)
1703 struct queued_reg_save *q;
1705 for (q = queued_reg_saves; q; q = q->next)
1708 unsigned int reg, sreg;
1710 for (i = 0; i < num_regs_saved_in_regs; i++)
1711 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1713 if (q->saved_reg && i == num_regs_saved_in_regs)
1715 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1716 num_regs_saved_in_regs++;
1718 if (i != num_regs_saved_in_regs)
1720 regs_saved_in_regs[i].orig_reg = q->reg;
1721 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1724 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1726 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1728 sreg = INVALID_REGNUM;
1729 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1732 queued_reg_saves = NULL;
1733 last_reg_save_label = NULL;
1736 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1737 location for? Or, does it clobber a register which we've previously
1738 said that some other register is saved in, and for which we now
1739 have a new location for? */
1742 clobbers_queued_reg_save (const_rtx insn)
1744 struct queued_reg_save *q;
1746 for (q = queued_reg_saves; q; q = q->next)
1749 if (modified_in_p (q->reg, insn))
1751 for (i = 0; i < num_regs_saved_in_regs; i++)
1752 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1753 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1760 /* Entry point for saving the first register into the second. */
1763 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1766 unsigned int regno, sregno;
1768 for (i = 0; i < num_regs_saved_in_regs; i++)
1769 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1771 if (i == num_regs_saved_in_regs)
1773 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1774 num_regs_saved_in_regs++;
1776 regs_saved_in_regs[i].orig_reg = reg;
1777 regs_saved_in_regs[i].saved_in_reg = sreg;
1779 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1780 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1781 reg_save (label, regno, sregno, 0);
1784 /* What register, if any, is currently saved in REG? */
1787 reg_saved_in (rtx reg)
1789 unsigned int regn = REGNO (reg);
1791 struct queued_reg_save *q;
1793 for (q = queued_reg_saves; q; q = q->next)
1794 if (q->saved_reg && regn == REGNO (q->saved_reg))
1797 for (i = 0; i < num_regs_saved_in_regs; i++)
1798 if (regs_saved_in_regs[i].saved_in_reg
1799 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1800 return regs_saved_in_regs[i].orig_reg;
1806 /* A temporary register holding an integral value used in adjusting SP
1807 or setting up the store_reg. The "offset" field holds the integer
1808 value, not an offset. */
1809 static dw_cfa_location cfa_temp;
1811 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1814 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1816 memset (&cfa, 0, sizeof (cfa));
1818 switch (GET_CODE (pat))
1821 cfa.reg = REGNO (XEXP (pat, 0));
1822 cfa.offset = INTVAL (XEXP (pat, 1));
1826 cfa.reg = REGNO (pat);
1830 /* Recurse and define an expression. */
1834 def_cfa_1 (label, &cfa);
1837 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1840 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1844 gcc_assert (GET_CODE (pat) == SET);
1845 dest = XEXP (pat, 0);
1846 src = XEXP (pat, 1);
1848 switch (GET_CODE (src))
1851 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1852 cfa.offset -= INTVAL (XEXP (src, 1));
1862 cfa.reg = REGNO (dest);
1863 gcc_assert (cfa.indirect == 0);
1865 def_cfa_1 (label, &cfa);
1868 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1871 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1873 HOST_WIDE_INT offset;
1874 rtx src, addr, span;
1876 src = XEXP (set, 1);
1877 addr = XEXP (set, 0);
1878 gcc_assert (MEM_P (addr));
1879 addr = XEXP (addr, 0);
1881 /* As documented, only consider extremely simple addresses. */
1882 switch (GET_CODE (addr))
1885 gcc_assert (REGNO (addr) == cfa.reg);
1886 offset = -cfa.offset;
1889 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1890 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1896 span = targetm.dwarf_register_span (src);
1898 /* ??? We'd like to use queue_reg_save, but we need to come up with
1899 a different flushing heuristic for epilogues. */
1901 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
1904 /* We have a PARALLEL describing where the contents of SRC live.
1905 Queue register saves for each piece of the PARALLEL. */
1908 HOST_WIDE_INT span_offset = offset;
1910 gcc_assert (GET_CODE (span) == PARALLEL);
1912 limit = XVECLEN (span, 0);
1913 for (par_index = 0; par_index < limit; par_index++)
1915 rtx elem = XVECEXP (span, 0, par_index);
1917 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
1918 INVALID_REGNUM, span_offset);
1919 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1924 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1927 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
1930 unsigned sregno, dregno;
1932 src = XEXP (set, 1);
1933 dest = XEXP (set, 0);
1936 sregno = DWARF_FRAME_RETURN_COLUMN;
1938 sregno = DWARF_FRAME_REGNUM (REGNO (src));
1940 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
1942 /* ??? We'd like to use queue_reg_save, but we need to come up with
1943 a different flushing heuristic for epilogues. */
1944 reg_save (label, sregno, dregno, 0);
1947 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1950 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
1952 dw_cfi_ref cfi = new_cfi ();
1953 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
1955 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
1956 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
1958 add_fde_cfi (label, cfi);
1961 /* Record call frame debugging information for an expression EXPR,
1962 which either sets SP or FP (adjusting how we calculate the frame
1963 address) or saves a register to the stack or another register.
1964 LABEL indicates the address of EXPR.
1966 This function encodes a state machine mapping rtxes to actions on
1967 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1968 users need not read the source code.
1970 The High-Level Picture
1972 Changes in the register we use to calculate the CFA: Currently we
1973 assume that if you copy the CFA register into another register, we
1974 should take the other one as the new CFA register; this seems to
1975 work pretty well. If it's wrong for some target, it's simple
1976 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1978 Changes in the register we use for saving registers to the stack:
1979 This is usually SP, but not always. Again, we deduce that if you
1980 copy SP into another register (and SP is not the CFA register),
1981 then the new register is the one we will be using for register
1982 saves. This also seems to work.
1984 Register saves: There's not much guesswork about this one; if
1985 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1986 register save, and the register used to calculate the destination
1987 had better be the one we think we're using for this purpose.
1988 It's also assumed that a copy from a call-saved register to another
1989 register is saving that register if RTX_FRAME_RELATED_P is set on
1990 that instruction. If the copy is from a call-saved register to
1991 the *same* register, that means that the register is now the same
1992 value as in the caller.
1994 Except: If the register being saved is the CFA register, and the
1995 offset is nonzero, we are saving the CFA, so we assume we have to
1996 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1997 the intent is to save the value of SP from the previous frame.
1999 In addition, if a register has previously been saved to a different
2002 Invariants / Summaries of Rules
2004 cfa current rule for calculating the CFA. It usually
2005 consists of a register and an offset.
2006 cfa_store register used by prologue code to save things to the stack
2007 cfa_store.offset is the offset from the value of
2008 cfa_store.reg to the actual CFA
2009 cfa_temp register holding an integral value. cfa_temp.offset
2010 stores the value, which will be used to adjust the
2011 stack pointer. cfa_temp is also used like cfa_store,
2012 to track stores to the stack via fp or a temp reg.
2014 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2015 with cfa.reg as the first operand changes the cfa.reg and its
2016 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2019 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2020 expression yielding a constant. This sets cfa_temp.reg
2021 and cfa_temp.offset.
2023 Rule 5: Create a new register cfa_store used to save items to the
2026 Rules 10-14: Save a register to the stack. Define offset as the
2027 difference of the original location and cfa_store's
2028 location (or cfa_temp's location if cfa_temp is used).
2030 Rules 16-20: If AND operation happens on sp in prologue, we assume
2031 stack is realigned. We will use a group of DW_OP_XXX
2032 expressions to represent the location of the stored
2033 register instead of CFA+offset.
2037 "{a,b}" indicates a choice of a xor b.
2038 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2041 (set <reg1> <reg2>:cfa.reg)
2042 effects: cfa.reg = <reg1>
2043 cfa.offset unchanged
2044 cfa_temp.reg = <reg1>
2045 cfa_temp.offset = cfa.offset
2048 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2049 {<const_int>,<reg>:cfa_temp.reg}))
2050 effects: cfa.reg = sp if fp used
2051 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2052 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2053 if cfa_store.reg==sp
2056 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2057 effects: cfa.reg = fp
2058 cfa_offset += +/- <const_int>
2061 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2062 constraints: <reg1> != fp
2064 effects: cfa.reg = <reg1>
2065 cfa_temp.reg = <reg1>
2066 cfa_temp.offset = cfa.offset
2069 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2070 constraints: <reg1> != fp
2072 effects: cfa_store.reg = <reg1>
2073 cfa_store.offset = cfa.offset - cfa_temp.offset
2076 (set <reg> <const_int>)
2077 effects: cfa_temp.reg = <reg>
2078 cfa_temp.offset = <const_int>
2081 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2082 effects: cfa_temp.reg = <reg1>
2083 cfa_temp.offset |= <const_int>
2086 (set <reg> (high <exp>))
2090 (set <reg> (lo_sum <exp> <const_int>))
2091 effects: cfa_temp.reg = <reg>
2092 cfa_temp.offset = <const_int>
2095 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2096 effects: cfa_store.offset -= <const_int>
2097 cfa.offset = cfa_store.offset if cfa.reg == sp
2099 cfa.base_offset = -cfa_store.offset
2102 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2103 effects: cfa_store.offset += -/+ mode_size(mem)
2104 cfa.offset = cfa_store.offset if cfa.reg == sp
2106 cfa.base_offset = -cfa_store.offset
2109 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2112 effects: cfa.reg = <reg1>
2113 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2116 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2117 effects: cfa.reg = <reg1>
2118 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2121 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2122 effects: cfa.reg = <reg1>
2123 cfa.base_offset = -cfa_temp.offset
2124 cfa_temp.offset -= mode_size(mem)
2127 (set <reg> {unspec, unspec_volatile})
2128 effects: target-dependent
2131 (set sp (and: sp <const_int>))
2132 constraints: cfa_store.reg == sp
2133 effects: current_fde.stack_realign = 1
2134 cfa_store.offset = 0
2135 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2138 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2139 effects: cfa_store.offset += -/+ mode_size(mem)
2142 (set (mem ({pre_inc, pre_dec} sp)) fp)
2143 constraints: fde->stack_realign == 1
2144 effects: cfa_store.offset = 0
2145 cfa.reg != HARD_FRAME_POINTER_REGNUM
2148 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2149 constraints: fde->stack_realign == 1
2151 && cfa.indirect == 0
2152 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2153 effects: Use DW_CFA_def_cfa_expression to define cfa
2154 cfa.reg == fde->drap_reg
2157 (set reg fde->drap_reg)
2158 constraints: fde->vdrap_reg == INVALID_REGNUM
2159 effects: fde->vdrap_reg = reg.
2160 (set mem fde->drap_reg)
2161 constraints: fde->drap_reg_saved == 1
2165 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2167 rtx src, dest, span;
2168 HOST_WIDE_INT offset;
2171 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2172 the PARALLEL independently. The first element is always processed if
2173 it is a SET. This is for backward compatibility. Other elements
2174 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2175 flag is set in them. */
2176 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2179 int limit = XVECLEN (expr, 0);
2182 /* PARALLELs have strict read-modify-write semantics, so we
2183 ought to evaluate every rvalue before changing any lvalue.
2184 It's cumbersome to do that in general, but there's an
2185 easy approximation that is enough for all current users:
2186 handle register saves before register assignments. */
2187 if (GET_CODE (expr) == PARALLEL)
2188 for (par_index = 0; par_index < limit; par_index++)
2190 elem = XVECEXP (expr, 0, par_index);
2191 if (GET_CODE (elem) == SET
2192 && MEM_P (SET_DEST (elem))
2193 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2194 dwarf2out_frame_debug_expr (elem, label);
2197 for (par_index = 0; par_index < limit; par_index++)
2199 elem = XVECEXP (expr, 0, par_index);
2200 if (GET_CODE (elem) == SET
2201 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2202 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2203 dwarf2out_frame_debug_expr (elem, label);
2204 else if (GET_CODE (elem) == SET
2206 && !RTX_FRAME_RELATED_P (elem))
2208 /* Stack adjustment combining might combine some post-prologue
2209 stack adjustment into a prologue stack adjustment. */
2210 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2213 dwarf2out_args_size_adjust (offset, label);
2219 gcc_assert (GET_CODE (expr) == SET);
2221 src = SET_SRC (expr);
2222 dest = SET_DEST (expr);
2226 rtx rsi = reg_saved_in (src);
2231 fde = current_fde ();
2235 && fde->drap_reg == REGNO (src)
2236 && (fde->drap_reg_saved
2240 /* If we are saving dynamic realign argument pointer to a
2241 register, the destination is virtual dynamic realign
2242 argument pointer. It may be used to access argument. */
2245 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2246 fde->vdrap_reg = REGNO (dest);
2251 switch (GET_CODE (dest))
2254 switch (GET_CODE (src))
2256 /* Setting FP from SP. */
2258 if (cfa.reg == (unsigned) REGNO (src))
2261 /* Update the CFA rule wrt SP or FP. Make sure src is
2262 relative to the current CFA register.
2264 We used to require that dest be either SP or FP, but the
2265 ARM copies SP to a temporary register, and from there to
2266 FP. So we just rely on the backends to only set
2267 RTX_FRAME_RELATED_P on appropriate insns. */
2268 cfa.reg = REGNO (dest);
2269 cfa_temp.reg = cfa.reg;
2270 cfa_temp.offset = cfa.offset;
2274 /* Saving a register in a register. */
2275 gcc_assert (!fixed_regs [REGNO (dest)]
2276 /* For the SPARC and its register window. */
2277 || (DWARF_FRAME_REGNUM (REGNO (src))
2278 == DWARF_FRAME_RETURN_COLUMN));
2280 /* After stack is aligned, we can only save SP in FP
2281 if drap register is used. In this case, we have
2282 to restore stack pointer with the CFA value and we
2283 don't generate this DWARF information. */
2285 && fde->stack_realign
2286 && REGNO (src) == STACK_POINTER_REGNUM)
2287 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2288 && fde->drap_reg != INVALID_REGNUM
2289 && cfa.reg != REGNO (src));
2291 queue_reg_save (label, src, dest, 0);
2298 if (dest == stack_pointer_rtx)
2302 switch (GET_CODE (XEXP (src, 1)))
2305 offset = INTVAL (XEXP (src, 1));
2308 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2310 offset = cfa_temp.offset;
2316 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2318 /* Restoring SP from FP in the epilogue. */
2319 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2320 cfa.reg = STACK_POINTER_REGNUM;
2322 else if (GET_CODE (src) == LO_SUM)
2323 /* Assume we've set the source reg of the LO_SUM from sp. */
2326 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2328 if (GET_CODE (src) != MINUS)
2330 if (cfa.reg == STACK_POINTER_REGNUM)
2331 cfa.offset += offset;
2332 if (cfa_store.reg == STACK_POINTER_REGNUM)
2333 cfa_store.offset += offset;
2335 else if (dest == hard_frame_pointer_rtx)
2338 /* Either setting the FP from an offset of the SP,
2339 or adjusting the FP */
2340 gcc_assert (frame_pointer_needed);
2342 gcc_assert (REG_P (XEXP (src, 0))
2343 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2344 && CONST_INT_P (XEXP (src, 1)));
2345 offset = INTVAL (XEXP (src, 1));
2346 if (GET_CODE (src) != MINUS)
2348 cfa.offset += offset;
2349 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2353 gcc_assert (GET_CODE (src) != MINUS);
2356 if (REG_P (XEXP (src, 0))
2357 && REGNO (XEXP (src, 0)) == cfa.reg
2358 && CONST_INT_P (XEXP (src, 1)))
2360 /* Setting a temporary CFA register that will be copied
2361 into the FP later on. */
2362 offset = - INTVAL (XEXP (src, 1));
2363 cfa.offset += offset;
2364 cfa.reg = REGNO (dest);
2365 /* Or used to save regs to the stack. */
2366 cfa_temp.reg = cfa.reg;
2367 cfa_temp.offset = cfa.offset;
2371 else if (REG_P (XEXP (src, 0))
2372 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2373 && XEXP (src, 1) == stack_pointer_rtx)
2375 /* Setting a scratch register that we will use instead
2376 of SP for saving registers to the stack. */
2377 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2378 cfa_store.reg = REGNO (dest);
2379 cfa_store.offset = cfa.offset - cfa_temp.offset;
2383 else if (GET_CODE (src) == LO_SUM
2384 && CONST_INT_P (XEXP (src, 1)))
2386 cfa_temp.reg = REGNO (dest);
2387 cfa_temp.offset = INTVAL (XEXP (src, 1));
2396 cfa_temp.reg = REGNO (dest);
2397 cfa_temp.offset = INTVAL (src);
2402 gcc_assert (REG_P (XEXP (src, 0))
2403 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2404 && CONST_INT_P (XEXP (src, 1)));
2406 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2407 cfa_temp.reg = REGNO (dest);
2408 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2411 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2412 which will fill in all of the bits. */
2419 case UNSPEC_VOLATILE:
2420 gcc_assert (targetm.dwarf_handle_frame_unspec);
2421 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2426 /* If this AND operation happens on stack pointer in prologue,
2427 we assume the stack is realigned and we extract the
2429 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2431 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2432 fde->stack_realign = 1;
2433 fde->stack_realignment = INTVAL (XEXP (src, 1));
2434 cfa_store.offset = 0;
2436 if (cfa.reg != STACK_POINTER_REGNUM
2437 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2438 fde->drap_reg = cfa.reg;
2446 def_cfa_1 (label, &cfa);
2451 /* Saving a register to the stack. Make sure dest is relative to the
2453 switch (GET_CODE (XEXP (dest, 0)))
2458 /* We can't handle variable size modifications. */
2459 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2461 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2463 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2464 && cfa_store.reg == STACK_POINTER_REGNUM);
2466 cfa_store.offset += offset;
2467 if (cfa.reg == STACK_POINTER_REGNUM)
2468 cfa.offset = cfa_store.offset;
2470 offset = -cfa_store.offset;
2476 offset = GET_MODE_SIZE (GET_MODE (dest));
2477 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2480 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2481 == STACK_POINTER_REGNUM)
2482 && cfa_store.reg == STACK_POINTER_REGNUM);
2484 cfa_store.offset += offset;
2486 /* Rule 18: If stack is aligned, we will use FP as a
2487 reference to represent the address of the stored
2490 && fde->stack_realign
2491 && src == hard_frame_pointer_rtx)
2493 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2494 cfa_store.offset = 0;
2497 if (cfa.reg == STACK_POINTER_REGNUM)
2498 cfa.offset = cfa_store.offset;
2500 offset = -cfa_store.offset;
2504 /* With an offset. */
2511 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2512 && REG_P (XEXP (XEXP (dest, 0), 0)));
2513 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2514 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2517 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2519 if (cfa_store.reg == (unsigned) regno)
2520 offset -= cfa_store.offset;
2523 gcc_assert (cfa_temp.reg == (unsigned) regno);
2524 offset -= cfa_temp.offset;
2530 /* Without an offset. */
2533 int regno = REGNO (XEXP (dest, 0));
2535 if (cfa_store.reg == (unsigned) regno)
2536 offset = -cfa_store.offset;
2539 gcc_assert (cfa_temp.reg == (unsigned) regno);
2540 offset = -cfa_temp.offset;
2547 gcc_assert (cfa_temp.reg
2548 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2549 offset = -cfa_temp.offset;
2550 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2558 /* If the source operand of this MEM operation is not a
2559 register, basically the source is return address. Here
2560 we only care how much stack grew and we don't save it. */
2564 if (REGNO (src) != STACK_POINTER_REGNUM
2565 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2566 && (unsigned) REGNO (src) == cfa.reg)
2568 /* We're storing the current CFA reg into the stack. */
2570 if (cfa.offset == 0)
2573 /* If stack is aligned, putting CFA reg into stack means
2574 we can no longer use reg + offset to represent CFA.
2575 Here we use DW_CFA_def_cfa_expression instead. The
2576 result of this expression equals to the original CFA
2579 && fde->stack_realign
2580 && cfa.indirect == 0
2581 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2583 dw_cfa_location cfa_exp;
2585 gcc_assert (fde->drap_reg == cfa.reg);
2587 cfa_exp.indirect = 1;
2588 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2589 cfa_exp.base_offset = offset;
2592 fde->drap_reg_saved = 1;
2594 def_cfa_1 (label, &cfa_exp);
2598 /* If the source register is exactly the CFA, assume
2599 we're saving SP like any other register; this happens
2601 def_cfa_1 (label, &cfa);
2602 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2607 /* Otherwise, we'll need to look in the stack to
2608 calculate the CFA. */
2609 rtx x = XEXP (dest, 0);
2613 gcc_assert (REG_P (x));
2615 cfa.reg = REGNO (x);
2616 cfa.base_offset = offset;
2618 def_cfa_1 (label, &cfa);
2623 def_cfa_1 (label, &cfa);
2625 span = targetm.dwarf_register_span (src);
2628 queue_reg_save (label, src, NULL_RTX, offset);
2631 /* We have a PARALLEL describing where the contents of SRC
2632 live. Queue register saves for each piece of the
2636 HOST_WIDE_INT span_offset = offset;
2638 gcc_assert (GET_CODE (span) == PARALLEL);
2640 limit = XVECLEN (span, 0);
2641 for (par_index = 0; par_index < limit; par_index++)
2643 rtx elem = XVECEXP (span, 0, par_index);
2645 queue_reg_save (label, elem, NULL_RTX, span_offset);
2646 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2657 /* Record call frame debugging information for INSN, which either
2658 sets SP or FP (adjusting how we calculate the frame address) or saves a
2659 register to the stack. If INSN is NULL_RTX, initialize our state.
2661 If AFTER_P is false, we're being called before the insn is emitted,
2662 otherwise after. Call instructions get invoked twice. */
2665 dwarf2out_frame_debug (rtx insn, bool after_p)
2669 bool handled_one = false;
2671 if (insn == NULL_RTX)
2675 /* Flush any queued register saves. */
2676 flush_queued_reg_saves ();
2678 /* Set up state for generating call frame debug info. */
2681 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2683 cfa.reg = STACK_POINTER_REGNUM;
2686 cfa_temp.offset = 0;
2688 for (i = 0; i < num_regs_saved_in_regs; i++)
2690 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2691 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2693 num_regs_saved_in_regs = 0;
2695 if (barrier_args_size)
2697 XDELETEVEC (barrier_args_size);
2698 barrier_args_size = NULL;
2703 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2704 flush_queued_reg_saves ();
2706 if (! RTX_FRAME_RELATED_P (insn))
2708 if (!ACCUMULATE_OUTGOING_ARGS)
2709 dwarf2out_stack_adjust (insn, after_p);
2713 label = dwarf2out_cfi_label (false);
2715 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2716 switch (REG_NOTE_KIND (note))
2718 case REG_FRAME_RELATED_EXPR:
2719 insn = XEXP (note, 0);
2722 case REG_CFA_DEF_CFA:
2723 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2727 case REG_CFA_ADJUST_CFA:
2732 if (GET_CODE (n) == PARALLEL)
2733 n = XVECEXP (n, 0, 0);
2735 dwarf2out_frame_debug_adjust_cfa (n, label);
2739 case REG_CFA_OFFSET:
2742 n = single_set (insn);
2743 dwarf2out_frame_debug_cfa_offset (n, label);
2747 case REG_CFA_REGISTER:
2752 if (GET_CODE (n) == PARALLEL)
2753 n = XVECEXP (n, 0, 0);
2755 dwarf2out_frame_debug_cfa_register (n, label);
2759 case REG_CFA_RESTORE:
2764 if (GET_CODE (n) == PARALLEL)
2765 n = XVECEXP (n, 0, 0);
2768 dwarf2out_frame_debug_cfa_restore (n, label);
2778 insn = PATTERN (insn);
2780 dwarf2out_frame_debug_expr (insn, label);
2783 /* Determine if we need to save and restore CFI information around this
2784 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2785 we do need to save/restore, then emit the save now, and insert a
2786 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2789 dwarf2out_begin_epilogue (rtx insn)
2791 bool saw_frp = false;
2794 /* Scan forward to the return insn, noticing if there are possible
2795 frame related insns. */
2796 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2801 /* Look for both regular and sibcalls to end the block. */
2802 if (returnjump_p (i))
2804 if (CALL_P (i) && SIBLING_CALL_P (i))
2807 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2810 rtx seq = PATTERN (i);
2812 if (returnjump_p (XVECEXP (seq, 0, 0)))
2814 if (CALL_P (XVECEXP (seq, 0, 0))
2815 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2818 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2819 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2823 if (RTX_FRAME_RELATED_P (i))
2827 /* If the port doesn't emit epilogue unwind info, we don't need a
2828 save/restore pair. */
2832 /* Otherwise, search forward to see if the return insn was the last
2833 basic block of the function. If so, we don't need save/restore. */
2834 gcc_assert (i != NULL);
2835 i = next_real_insn (i);
2839 /* Insert the restore before that next real insn in the stream, and before
2840 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2841 properly nested. This should be after any label or alignment. This
2842 will be pushed into the CFI stream by the function below. */
2845 rtx p = PREV_INSN (i);
2848 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
2852 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
2854 emit_cfa_remember = true;
2856 /* And emulate the state save. */
2857 gcc_assert (!cfa_remember.in_use);
2859 cfa_remember.in_use = 1;
2862 /* A "subroutine" of dwarf2out_begin_epilogue. Emit the restore required. */
2865 dwarf2out_frame_debug_restore_state (void)
2867 dw_cfi_ref cfi = new_cfi ();
2868 const char *label = dwarf2out_cfi_label (false);
2870 cfi->dw_cfi_opc = DW_CFA_restore_state;
2871 add_fde_cfi (label, cfi);
2873 gcc_assert (cfa_remember.in_use);
2875 cfa_remember.in_use = 0;
2880 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2881 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2882 (enum dwarf_call_frame_info cfi);
2884 static enum dw_cfi_oprnd_type
2885 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2890 case DW_CFA_GNU_window_save:
2891 case DW_CFA_remember_state:
2892 case DW_CFA_restore_state:
2893 return dw_cfi_oprnd_unused;
2895 case DW_CFA_set_loc:
2896 case DW_CFA_advance_loc1:
2897 case DW_CFA_advance_loc2:
2898 case DW_CFA_advance_loc4:
2899 case DW_CFA_MIPS_advance_loc8:
2900 return dw_cfi_oprnd_addr;
2903 case DW_CFA_offset_extended:
2904 case DW_CFA_def_cfa:
2905 case DW_CFA_offset_extended_sf:
2906 case DW_CFA_def_cfa_sf:
2907 case DW_CFA_restore:
2908 case DW_CFA_restore_extended:
2909 case DW_CFA_undefined:
2910 case DW_CFA_same_value:
2911 case DW_CFA_def_cfa_register:
2912 case DW_CFA_register:
2913 return dw_cfi_oprnd_reg_num;
2915 case DW_CFA_def_cfa_offset:
2916 case DW_CFA_GNU_args_size:
2917 case DW_CFA_def_cfa_offset_sf:
2918 return dw_cfi_oprnd_offset;
2920 case DW_CFA_def_cfa_expression:
2921 case DW_CFA_expression:
2922 return dw_cfi_oprnd_loc;
2929 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2930 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2931 (enum dwarf_call_frame_info cfi);
2933 static enum dw_cfi_oprnd_type
2934 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2938 case DW_CFA_def_cfa:
2939 case DW_CFA_def_cfa_sf:
2941 case DW_CFA_offset_extended_sf:
2942 case DW_CFA_offset_extended:
2943 return dw_cfi_oprnd_offset;
2945 case DW_CFA_register:
2946 return dw_cfi_oprnd_reg_num;
2949 return dw_cfi_oprnd_unused;
2953 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2955 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
2956 switch to the data section instead, and write out a synthetic start label
2957 for collect2 the first time around. */
2960 switch_to_eh_frame_section (bool back)
2964 #ifdef EH_FRAME_SECTION_NAME
2965 if (eh_frame_section == 0)
2969 if (EH_TABLES_CAN_BE_READ_ONLY)
2975 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2977 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2979 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2981 flags = ((! flag_pic
2982 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2983 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2984 && (per_encoding & 0x70) != DW_EH_PE_absptr
2985 && (per_encoding & 0x70) != DW_EH_PE_aligned
2986 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2987 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2988 ? 0 : SECTION_WRITE);
2991 flags = SECTION_WRITE;
2992 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2996 if (eh_frame_section)
2997 switch_to_section (eh_frame_section);
3000 /* We have no special eh_frame section. Put the information in
3001 the data section and emit special labels to guide collect2. */
3002 switch_to_section (data_section);
3006 label = get_file_function_name ("F");
3007 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3008 targetm.asm_out.globalize_label (asm_out_file,
3009 IDENTIFIER_POINTER (label));
3010 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3015 /* Switch [BACK] to the eh or debug frame table section, depending on
3019 switch_to_frame_table_section (int for_eh, bool back)
3022 switch_to_eh_frame_section (back);
3025 if (!debug_frame_section)
3026 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3027 SECTION_DEBUG, NULL);
3028 switch_to_section (debug_frame_section);
3032 /* Output a Call Frame Information opcode and its operand(s). */
3035 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3040 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3041 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3042 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3043 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3044 ((unsigned HOST_WIDE_INT)
3045 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3046 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3048 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3049 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3050 "DW_CFA_offset, column 0x%lx", r);
3051 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3052 dw2_asm_output_data_uleb128 (off, NULL);
3054 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3056 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3057 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3058 "DW_CFA_restore, column 0x%lx", r);
3062 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3063 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3065 switch (cfi->dw_cfi_opc)
3067 case DW_CFA_set_loc:
3069 dw2_asm_output_encoded_addr_rtx (
3070 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3071 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3074 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3075 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3076 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3079 case DW_CFA_advance_loc1:
3080 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3081 fde->dw_fde_current_label, NULL);
3082 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3085 case DW_CFA_advance_loc2:
3086 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3087 fde->dw_fde_current_label, NULL);
3088 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3091 case DW_CFA_advance_loc4:
3092 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3093 fde->dw_fde_current_label, NULL);
3094 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3097 case DW_CFA_MIPS_advance_loc8:
3098 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3099 fde->dw_fde_current_label, NULL);
3100 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3103 case DW_CFA_offset_extended:
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_uleb128 (off, NULL);
3110 case DW_CFA_def_cfa:
3111 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3112 dw2_asm_output_data_uleb128 (r, NULL);
3113 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3116 case DW_CFA_offset_extended_sf:
3117 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3118 dw2_asm_output_data_uleb128 (r, NULL);
3119 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3120 dw2_asm_output_data_sleb128 (off, NULL);
3123 case DW_CFA_def_cfa_sf:
3124 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3125 dw2_asm_output_data_uleb128 (r, NULL);
3126 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3127 dw2_asm_output_data_sleb128 (off, NULL);
3130 case DW_CFA_restore_extended:
3131 case DW_CFA_undefined:
3132 case DW_CFA_same_value:
3133 case DW_CFA_def_cfa_register:
3134 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3135 dw2_asm_output_data_uleb128 (r, NULL);
3138 case DW_CFA_register:
3139 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3140 dw2_asm_output_data_uleb128 (r, NULL);
3141 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3142 dw2_asm_output_data_uleb128 (r, NULL);
3145 case DW_CFA_def_cfa_offset:
3146 case DW_CFA_GNU_args_size:
3147 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3150 case DW_CFA_def_cfa_offset_sf:
3151 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3152 dw2_asm_output_data_sleb128 (off, NULL);
3155 case DW_CFA_GNU_window_save:
3158 case DW_CFA_def_cfa_expression:
3159 case DW_CFA_expression:
3160 output_cfa_loc (cfi);
3163 case DW_CFA_GNU_negative_offset_extended:
3164 /* Obsoleted by DW_CFA_offset_extended_sf. */
3173 /* Similar, but do it via assembler directives instead. */
3176 output_cfi_directive (dw_cfi_ref cfi)
3178 unsigned long r, r2;
3180 switch (cfi->dw_cfi_opc)
3182 case DW_CFA_advance_loc:
3183 case DW_CFA_advance_loc1:
3184 case DW_CFA_advance_loc2:
3185 case DW_CFA_advance_loc4:
3186 case DW_CFA_MIPS_advance_loc8:
3187 case DW_CFA_set_loc:
3188 /* Should only be created by add_fde_cfi in a code path not
3189 followed when emitting via directives. The assembler is
3190 going to take care of this for us. */
3194 case DW_CFA_offset_extended:
3195 case DW_CFA_offset_extended_sf:
3196 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3197 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3198 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3201 case DW_CFA_restore:
3202 case DW_CFA_restore_extended:
3203 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3204 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3207 case DW_CFA_undefined:
3208 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3209 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3212 case DW_CFA_same_value:
3213 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3214 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3217 case DW_CFA_def_cfa:
3218 case DW_CFA_def_cfa_sf:
3219 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3220 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3221 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3224 case DW_CFA_def_cfa_register:
3225 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3226 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3229 case DW_CFA_register:
3230 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3231 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3232 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3235 case DW_CFA_def_cfa_offset:
3236 case DW_CFA_def_cfa_offset_sf:
3237 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3238 HOST_WIDE_INT_PRINT_DEC"\n",
3239 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3242 case DW_CFA_remember_state:
3243 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3245 case DW_CFA_restore_state:
3246 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3249 case DW_CFA_GNU_args_size:
3250 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size);
3251 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3253 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3254 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3255 fputc ('\n', asm_out_file);
3258 case DW_CFA_GNU_window_save:
3259 fprintf (asm_out_file, "\t.cfi_window_save\n");
3262 case DW_CFA_def_cfa_expression:
3263 case DW_CFA_expression:
3264 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", cfi->dw_cfi_opc);
3265 output_cfa_loc_raw (cfi);
3266 fputc ('\n', asm_out_file);
3274 DEF_VEC_P (dw_cfi_ref);
3275 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3277 /* Output CFIs to bring current FDE to the same state as after executing
3278 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3279 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3280 other arguments to pass to output_cfi. */
3283 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3285 struct dw_cfi_struct cfi_buf;
3287 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3288 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3289 unsigned int len, idx;
3291 for (;; cfi = cfi->dw_cfi_next)
3292 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3294 case DW_CFA_advance_loc:
3295 case DW_CFA_advance_loc1:
3296 case DW_CFA_advance_loc2:
3297 case DW_CFA_advance_loc4:
3298 case DW_CFA_MIPS_advance_loc8:
3299 case DW_CFA_set_loc:
3300 /* All advances should be ignored. */
3302 case DW_CFA_remember_state:
3304 dw_cfi_ref args_size = cfi_args_size;
3306 /* Skip everything between .cfi_remember_state and
3307 .cfi_restore_state. */
3308 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3309 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3311 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3314 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3321 cfi_args_size = args_size;
3325 case DW_CFA_GNU_args_size:
3326 cfi_args_size = cfi;
3328 case DW_CFA_GNU_window_save:
3331 case DW_CFA_offset_extended:
3332 case DW_CFA_offset_extended_sf:
3333 case DW_CFA_restore:
3334 case DW_CFA_restore_extended:
3335 case DW_CFA_undefined:
3336 case DW_CFA_same_value:
3337 case DW_CFA_register:
3338 case DW_CFA_val_offset:
3339 case DW_CFA_val_offset_sf:
3340 case DW_CFA_expression:
3341 case DW_CFA_val_expression:
3342 case DW_CFA_GNU_negative_offset_extended:
3343 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3344 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3345 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3346 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3348 case DW_CFA_def_cfa:
3349 case DW_CFA_def_cfa_sf:
3350 case DW_CFA_def_cfa_expression:
3352 cfi_cfa_offset = cfi;
3354 case DW_CFA_def_cfa_register:
3357 case DW_CFA_def_cfa_offset:
3358 case DW_CFA_def_cfa_offset_sf:
3359 cfi_cfa_offset = cfi;
3362 gcc_assert (cfi == NULL);
3364 len = VEC_length (dw_cfi_ref, regs);
3365 for (idx = 0; idx < len; idx++)
3367 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3369 && cfi2->dw_cfi_opc != DW_CFA_restore
3370 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3373 output_cfi_directive (cfi2);
3375 output_cfi (cfi2, fde, for_eh);
3378 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3380 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3382 switch (cfi_cfa_offset->dw_cfi_opc)
3384 case DW_CFA_def_cfa_offset:
3385 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3386 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3388 case DW_CFA_def_cfa_offset_sf:
3389 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3390 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3392 case DW_CFA_def_cfa:
3393 case DW_CFA_def_cfa_sf:
3394 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3395 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3402 else if (cfi_cfa_offset)
3403 cfi_cfa = cfi_cfa_offset;
3407 output_cfi_directive (cfi_cfa);
3409 output_cfi (cfi_cfa, fde, for_eh);
3412 cfi_cfa_offset = NULL;
3414 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3417 output_cfi_directive (cfi_args_size);
3419 output_cfi (cfi_args_size, fde, for_eh);
3421 cfi_args_size = NULL;
3424 VEC_free (dw_cfi_ref, heap, regs);
3427 else if (do_cfi_asm)
3428 output_cfi_directive (cfi);
3430 output_cfi (cfi, fde, for_eh);
3437 /* Output one FDE. */
3440 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3441 char *section_start_label, int fde_encoding, char *augmentation,
3442 bool any_lsda_needed, int lsda_encoding)
3444 const char *begin, *end;
3445 static unsigned int j;
3446 char l1[20], l2[20];
3449 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh,
3451 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3453 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3454 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3455 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3456 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3457 " indicating 64-bit DWARF extension");
3458 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3460 ASM_OUTPUT_LABEL (asm_out_file, l1);
3463 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3465 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3466 debug_frame_section, "FDE CIE offset");
3468 if (!fde->dw_fde_switched_sections)
3470 begin = fde->dw_fde_begin;
3471 end = fde->dw_fde_end;
3475 /* For the first section, prefer dw_fde_begin over
3476 dw_fde_{hot,cold}_section_label, as the latter
3477 might be separated from the real start of the
3478 function by alignment padding. */
3480 begin = fde->dw_fde_begin;
3481 else if (fde->dw_fde_switched_cold_to_hot)
3482 begin = fde->dw_fde_hot_section_label;
3484 begin = fde->dw_fde_unlikely_section_label;
3485 if (second ^ fde->dw_fde_switched_cold_to_hot)
3486 end = fde->dw_fde_unlikely_section_end_label;
3488 end = fde->dw_fde_hot_section_end_label;
3493 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3494 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3495 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3496 "FDE initial location");
3497 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3498 end, begin, "FDE address range");
3502 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3503 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3506 if (augmentation[0])
3508 if (any_lsda_needed)
3510 int size = size_of_encoded_value (lsda_encoding);
3512 if (lsda_encoding == DW_EH_PE_aligned)
3514 int offset = ( 4 /* Length */
3515 + 4 /* CIE offset */
3516 + 2 * size_of_encoded_value (fde_encoding)
3517 + 1 /* Augmentation size */ );
3518 int pad = -offset & (PTR_SIZE - 1);
3521 gcc_assert (size_of_uleb128 (size) == 1);
3524 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3526 if (fde->uses_eh_lsda)
3528 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3529 fde->funcdef_number);
3530 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3531 gen_rtx_SYMBOL_REF (Pmode, l1),
3533 "Language Specific Data Area");
3537 if (lsda_encoding == DW_EH_PE_aligned)
3538 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3539 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3540 "Language Specific Data Area (none)");
3544 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3547 /* Loop through the Call Frame Instructions associated with
3549 fde->dw_fde_current_label = begin;
3550 if (!fde->dw_fde_switched_sections)
3551 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3552 output_cfi (cfi, fde, for_eh);
3555 if (fde->dw_fde_switch_cfi)
3556 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3558 output_cfi (cfi, fde, for_eh);
3559 if (cfi == fde->dw_fde_switch_cfi)