1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
62 #include "coretypes.h"
69 #include "hard-reg-set.h"
71 #include "insn-config.h"
79 #include "dwarf2out.h"
80 #include "dwarf2asm.h"
85 #include "diagnostic.h"
88 #include "langhooks.h"
93 #include "tree-pass.h"
94 #include "tree-flow.h"
96 #ifdef DWARF2_DEBUGGING_INFO
97 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
99 static rtx last_var_location_insn;
102 #ifdef VMS_DEBUGGING_INFO
103 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
105 /* Define this macro to be a nonzero value if the directory specifications
106 which are output in the debug info should end with a separator. */
107 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
108 /* Define this macro to evaluate to a nonzero value if GCC should refrain
109 from generating indirect strings in DWARF2 debug information, for instance
110 if your target is stuck with an old version of GDB that is unable to
111 process them properly or uses VMS Debug. */
112 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
114 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
115 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
118 #ifndef DWARF2_FRAME_INFO
119 # ifdef DWARF2_DEBUGGING_INFO
120 # define DWARF2_FRAME_INFO \
121 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
123 # define DWARF2_FRAME_INFO 0
127 /* Map register numbers held in the call frame info that gcc has
128 collected using DWARF_FRAME_REGNUM to those that should be output in
129 .debug_frame and .eh_frame. */
130 #ifndef DWARF2_FRAME_REG_OUT
131 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
134 /* Save the result of dwarf2out_do_frame across PCH. */
135 static GTY(()) bool saved_do_cfi_asm = 0;
137 /* Decide whether we want to emit frame unwind information for the current
141 dwarf2out_do_frame (void)
143 /* We want to emit correct CFA location expressions or lists, so we
144 have to return true if we're going to output debug info, even if
145 we're not going to output frame or unwind info. */
146 return (write_symbols == DWARF2_DEBUG
147 || write_symbols == VMS_AND_DWARF2_DEBUG
148 || DWARF2_FRAME_INFO || saved_do_cfi_asm
149 #ifdef DWARF2_UNWIND_INFO
150 || (DWARF2_UNWIND_INFO
151 && (flag_unwind_tables
152 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
157 /* Decide whether to emit frame unwind via assembler directives. */
160 dwarf2out_do_cfi_asm (void)
164 #ifdef MIPS_DEBUGGING_INFO
167 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
169 if (saved_do_cfi_asm)
171 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
174 /* Make sure the personality encoding is one the assembler can support.
175 In particular, aligned addresses can't be handled. */
176 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
177 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
179 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
180 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
183 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE)
185 #ifdef TARGET_UNWIND_INFO
188 if (USING_SJLJ_EXCEPTIONS || (!flag_unwind_tables && !flag_exceptions))
193 saved_do_cfi_asm = true;
197 /* The size of the target's pointer type. */
199 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
202 /* Array of RTXes referenced by the debugging information, which therefore
203 must be kept around forever. */
204 static GTY(()) VEC(rtx,gc) *used_rtx_array;
206 /* A pointer to the base of a list of incomplete types which might be
207 completed at some later time. incomplete_types_list needs to be a
208 VEC(tree,gc) because we want to tell the garbage collector about
210 static GTY(()) VEC(tree,gc) *incomplete_types;
212 /* A pointer to the base of a table of references to declaration
213 scopes. This table is a display which tracks the nesting
214 of declaration scopes at the current scope and containing
215 scopes. This table is used to find the proper place to
216 define type declaration DIE's. */
217 static GTY(()) VEC(tree,gc) *decl_scope_table;
219 /* Pointers to various DWARF2 sections. */
220 static GTY(()) section *debug_info_section;
221 static GTY(()) section *debug_abbrev_section;
222 static GTY(()) section *debug_aranges_section;
223 static GTY(()) section *debug_macinfo_section;
224 static GTY(()) section *debug_line_section;
225 static GTY(()) section *debug_loc_section;
226 static GTY(()) section *debug_pubnames_section;
227 static GTY(()) section *debug_pubtypes_section;
228 static GTY(()) section *debug_dcall_section;
229 static GTY(()) section *debug_vcall_section;
230 static GTY(()) section *debug_str_section;
231 static GTY(()) section *debug_ranges_section;
232 static GTY(()) section *debug_frame_section;
234 /* Personality decl of current unit. Used only when assembler does not support
236 static GTY(()) rtx current_unit_personality;
238 /* How to start an assembler comment. */
239 #ifndef ASM_COMMENT_START
240 #define ASM_COMMENT_START ";#"
243 typedef struct dw_cfi_struct *dw_cfi_ref;
244 typedef struct dw_fde_struct *dw_fde_ref;
245 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
247 /* Call frames are described using a sequence of Call Frame
248 Information instructions. The register number, offset
249 and address fields are provided as possible operands;
250 their use is selected by the opcode field. */
252 enum dw_cfi_oprnd_type {
254 dw_cfi_oprnd_reg_num,
260 typedef union GTY(()) dw_cfi_oprnd_struct {
261 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
262 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
263 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
264 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
268 typedef struct GTY(()) dw_cfi_struct {
269 dw_cfi_ref dw_cfi_next;
270 enum dwarf_call_frame_info dw_cfi_opc;
271 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
273 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
278 /* This is how we define the location of the CFA. We use to handle it
279 as REG + OFFSET all the time, but now it can be more complex.
280 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
281 Instead of passing around REG and OFFSET, we pass a copy
282 of this structure. */
283 typedef struct GTY(()) cfa_loc {
284 HOST_WIDE_INT offset;
285 HOST_WIDE_INT base_offset;
287 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
288 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
291 /* All call frame descriptions (FDE's) in the GCC generated DWARF
292 refer to a single Common Information Entry (CIE), defined at
293 the beginning of the .debug_frame section. This use of a single
294 CIE obviates the need to keep track of multiple CIE's
295 in the DWARF generation routines below. */
297 typedef struct GTY(()) dw_fde_struct {
299 const char *dw_fde_begin;
300 const char *dw_fde_current_label;
301 const char *dw_fde_end;
302 const char *dw_fde_hot_section_label;
303 const char *dw_fde_hot_section_end_label;
304 const char *dw_fde_unlikely_section_label;
305 const char *dw_fde_unlikely_section_end_label;
306 dw_cfi_ref dw_fde_cfi;
307 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
308 unsigned funcdef_number;
309 HOST_WIDE_INT stack_realignment;
310 /* Dynamic realign argument pointer register. */
311 unsigned int drap_reg;
312 /* Virtual dynamic realign argument pointer register. */
313 unsigned int vdrap_reg;
314 unsigned all_throwers_are_sibcalls : 1;
315 unsigned nothrow : 1;
316 unsigned uses_eh_lsda : 1;
317 /* Whether we did stack realign in this call frame. */
318 unsigned stack_realign : 1;
319 /* Whether dynamic realign argument pointer register has been saved. */
320 unsigned drap_reg_saved: 1;
321 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
322 unsigned in_std_section : 1;
323 /* True iff dw_fde_unlikely_section_label is in text_section or
324 cold_text_section. */
325 unsigned cold_in_std_section : 1;
326 /* True iff switched sections. */
327 unsigned dw_fde_switched_sections : 1;
328 /* True iff switching from cold to hot section. */
329 unsigned dw_fde_switched_cold_to_hot : 1;
333 /* Maximum size (in bytes) of an artificially generated label. */
334 #define MAX_ARTIFICIAL_LABEL_BYTES 30
336 /* The size of addresses as they appear in the Dwarf 2 data.
337 Some architectures use word addresses to refer to code locations,
338 but Dwarf 2 info always uses byte addresses. On such machines,
339 Dwarf 2 addresses need to be larger than the architecture's
341 #ifndef DWARF2_ADDR_SIZE
342 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
345 /* The size in bytes of a DWARF field indicating an offset or length
346 relative to a debug info section, specified to be 4 bytes in the
347 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
350 #ifndef DWARF_OFFSET_SIZE
351 #define DWARF_OFFSET_SIZE 4
354 /* The size in bytes of a DWARF 4 type signature. */
356 #ifndef DWARF_TYPE_SIGNATURE_SIZE
357 #define DWARF_TYPE_SIGNATURE_SIZE 8
360 /* According to the (draft) DWARF 3 specification, the initial length
361 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
362 bytes are 0xffffffff, followed by the length stored in the next 8
365 However, the SGI/MIPS ABI uses an initial length which is equal to
366 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
368 #ifndef DWARF_INITIAL_LENGTH_SIZE
369 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
372 /* Round SIZE up to the nearest BOUNDARY. */
373 #define DWARF_ROUND(SIZE,BOUNDARY) \
374 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
376 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
377 #ifndef DWARF_CIE_DATA_ALIGNMENT
378 #ifdef STACK_GROWS_DOWNWARD
379 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
381 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
385 /* CIE identifier. */
386 #if HOST_BITS_PER_WIDE_INT >= 64
387 #define DWARF_CIE_ID \
388 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
390 #define DWARF_CIE_ID DW_CIE_ID
393 /* A pointer to the base of a table that contains frame description
394 information for each routine. */
395 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
397 /* Number of elements currently allocated for fde_table. */
398 static GTY(()) unsigned fde_table_allocated;
400 /* Number of elements in fde_table currently in use. */
401 static GTY(()) unsigned fde_table_in_use;
403 /* Size (in elements) of increments by which we may expand the
405 #define FDE_TABLE_INCREMENT 256
407 /* Get the current fde_table entry we should use. */
409 static inline dw_fde_ref
412 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
415 /* A list of call frame insns for the CIE. */
416 static GTY(()) dw_cfi_ref cie_cfi_head;
418 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
419 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
420 attribute that accelerates the lookup of the FDE associated
421 with the subprogram. This variable holds the table index of the FDE
422 associated with the current function (body) definition. */
423 static unsigned current_funcdef_fde;
426 struct GTY(()) indirect_string_node {
428 unsigned int refcount;
429 enum dwarf_form form;
433 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
435 /* True if the compilation unit has location entries that reference
437 static GTY(()) bool debug_str_hash_forced = false;
439 static GTY(()) int dw2_string_counter;
440 static GTY(()) unsigned long dwarf2out_cfi_label_num;
442 /* True if the compilation unit places functions in more than one section. */
443 static GTY(()) bool have_multiple_function_sections = false;
445 /* Whether the default text and cold text sections have been used at all. */
447 static GTY(()) bool text_section_used = false;
448 static GTY(()) bool cold_text_section_used = false;
450 /* The default cold text section. */
451 static GTY(()) section *cold_text_section;
453 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
455 /* Forward declarations for functions defined in this file. */
457 static char *stripattributes (const char *);
458 static const char *dwarf_cfi_name (unsigned);
459 static dw_cfi_ref new_cfi (void);
460 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
461 static void add_fde_cfi (const char *, dw_cfi_ref);
462 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
463 static void lookup_cfa (dw_cfa_location *);
464 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
465 #ifdef DWARF2_UNWIND_INFO
466 static void initial_return_save (rtx);
468 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
470 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
471 static void output_cfi_directive (dw_cfi_ref);
472 static void output_call_frame_info (int);
473 static void dwarf2out_note_section_used (void);
474 static void flush_queued_reg_saves (void);
475 static bool clobbers_queued_reg_save (const_rtx);
476 static void dwarf2out_frame_debug_expr (rtx, const char *);
478 /* Support for complex CFA locations. */
479 static void output_cfa_loc (dw_cfi_ref);
480 static void output_cfa_loc_raw (dw_cfi_ref);
481 static void get_cfa_from_loc_descr (dw_cfa_location *,
482 struct dw_loc_descr_struct *);
483 static struct dw_loc_descr_struct *build_cfa_loc
484 (dw_cfa_location *, HOST_WIDE_INT);
485 static struct dw_loc_descr_struct *build_cfa_aligned_loc
486 (HOST_WIDE_INT, HOST_WIDE_INT);
487 static void def_cfa_1 (const char *, dw_cfa_location *);
489 /* How to start an assembler comment. */
490 #ifndef ASM_COMMENT_START
491 #define ASM_COMMENT_START ";#"
494 /* Data and reference forms for relocatable data. */
495 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
496 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
498 #ifndef DEBUG_FRAME_SECTION
499 #define DEBUG_FRAME_SECTION ".debug_frame"
502 #ifndef FUNC_BEGIN_LABEL
503 #define FUNC_BEGIN_LABEL "LFB"
506 #ifndef FUNC_END_LABEL
507 #define FUNC_END_LABEL "LFE"
510 #ifndef FRAME_BEGIN_LABEL
511 #define FRAME_BEGIN_LABEL "Lframe"
513 #define CIE_AFTER_SIZE_LABEL "LSCIE"
514 #define CIE_END_LABEL "LECIE"
515 #define FDE_LABEL "LSFDE"
516 #define FDE_AFTER_SIZE_LABEL "LASFDE"
517 #define FDE_END_LABEL "LEFDE"
518 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
519 #define LINE_NUMBER_END_LABEL "LELT"
520 #define LN_PROLOG_AS_LABEL "LASLTP"
521 #define LN_PROLOG_END_LABEL "LELTP"
522 #define DIE_LABEL_PREFIX "DW"
524 /* The DWARF 2 CFA column which tracks the return address. Normally this
525 is the column for PC, or the first column after all of the hard
527 #ifndef DWARF_FRAME_RETURN_COLUMN
529 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
531 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
535 /* The mapping from gcc register number to DWARF 2 CFA column number. By
536 default, we just provide columns for all registers. */
537 #ifndef DWARF_FRAME_REGNUM
538 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
541 /* Hook used by __throw. */
544 expand_builtin_dwarf_sp_column (void)
546 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
547 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
550 /* Return a pointer to a copy of the section string name S with all
551 attributes stripped off, and an asterisk prepended (for assemble_name). */
554 stripattributes (const char *s)
556 char *stripped = XNEWVEC (char, strlen (s) + 2);
561 while (*s && *s != ',')
568 /* MEM is a memory reference for the register size table, each element of
569 which has mode MODE. Initialize column C as a return address column. */
572 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
574 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
575 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
576 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
579 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
581 static inline HOST_WIDE_INT
582 div_data_align (HOST_WIDE_INT off)
584 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
585 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
589 /* Return true if we need a signed version of a given opcode
590 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
593 need_data_align_sf_opcode (HOST_WIDE_INT off)
595 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
598 /* Generate code to initialize the register size table. */
601 expand_builtin_init_dwarf_reg_sizes (tree address)
604 enum machine_mode mode = TYPE_MODE (char_type_node);
605 rtx addr = expand_normal (address);
606 rtx mem = gen_rtx_MEM (BLKmode, addr);
607 bool wrote_return_column = false;
609 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
611 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
613 if (rnum < DWARF_FRAME_REGISTERS)
615 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
616 enum machine_mode save_mode = reg_raw_mode[i];
619 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
620 save_mode = choose_hard_reg_mode (i, 1, true);
621 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
623 if (save_mode == VOIDmode)
625 wrote_return_column = true;
627 size = GET_MODE_SIZE (save_mode);
631 emit_move_insn (adjust_address (mem, mode, offset),
632 gen_int_mode (size, mode));
636 if (!wrote_return_column)
637 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
639 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
640 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
643 targetm.init_dwarf_reg_sizes_extra (address);
646 /* Convert a DWARF call frame info. operation to its string name */
649 dwarf_cfi_name (unsigned int cfi_opc)
653 case DW_CFA_advance_loc:
654 return "DW_CFA_advance_loc";
656 return "DW_CFA_offset";
658 return "DW_CFA_restore";
662 return "DW_CFA_set_loc";
663 case DW_CFA_advance_loc1:
664 return "DW_CFA_advance_loc1";
665 case DW_CFA_advance_loc2:
666 return "DW_CFA_advance_loc2";
667 case DW_CFA_advance_loc4:
668 return "DW_CFA_advance_loc4";
669 case DW_CFA_offset_extended:
670 return "DW_CFA_offset_extended";
671 case DW_CFA_restore_extended:
672 return "DW_CFA_restore_extended";
673 case DW_CFA_undefined:
674 return "DW_CFA_undefined";
675 case DW_CFA_same_value:
676 return "DW_CFA_same_value";
677 case DW_CFA_register:
678 return "DW_CFA_register";
679 case DW_CFA_remember_state:
680 return "DW_CFA_remember_state";
681 case DW_CFA_restore_state:
682 return "DW_CFA_restore_state";
684 return "DW_CFA_def_cfa";
685 case DW_CFA_def_cfa_register:
686 return "DW_CFA_def_cfa_register";
687 case DW_CFA_def_cfa_offset:
688 return "DW_CFA_def_cfa_offset";
691 case DW_CFA_def_cfa_expression:
692 return "DW_CFA_def_cfa_expression";
693 case DW_CFA_expression:
694 return "DW_CFA_expression";
695 case DW_CFA_offset_extended_sf:
696 return "DW_CFA_offset_extended_sf";
697 case DW_CFA_def_cfa_sf:
698 return "DW_CFA_def_cfa_sf";
699 case DW_CFA_def_cfa_offset_sf:
700 return "DW_CFA_def_cfa_offset_sf";
702 /* SGI/MIPS specific */
703 case DW_CFA_MIPS_advance_loc8:
704 return "DW_CFA_MIPS_advance_loc8";
707 case DW_CFA_GNU_window_save:
708 return "DW_CFA_GNU_window_save";
709 case DW_CFA_GNU_args_size:
710 return "DW_CFA_GNU_args_size";
711 case DW_CFA_GNU_negative_offset_extended:
712 return "DW_CFA_GNU_negative_offset_extended";
715 return "DW_CFA_<unknown>";
719 /* Return a pointer to a newly allocated Call Frame Instruction. */
721 static inline dw_cfi_ref
724 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
726 cfi->dw_cfi_next = NULL;
727 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
728 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
733 /* Add a Call Frame Instruction to list of instructions. */
736 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
739 dw_fde_ref fde = current_fde ();
741 /* When DRAP is used, CFA is defined with an expression. Redefine
742 CFA may lead to a different CFA value. */
743 /* ??? Of course, this heuristic fails when we're annotating epilogues,
744 because of course we'll always want to redefine the CFA back to the
745 stack pointer on the way out. Where should we move this check? */
746 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
747 switch (cfi->dw_cfi_opc)
749 case DW_CFA_def_cfa_register:
750 case DW_CFA_def_cfa_offset:
751 case DW_CFA_def_cfa_offset_sf:
753 case DW_CFA_def_cfa_sf:
760 /* Find the end of the chain. */
761 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
767 /* Generate a new label for the CFI info to refer to. FORCE is true
768 if a label needs to be output even when using .cfi_* directives. */
771 dwarf2out_cfi_label (bool force)
773 static char label[20];
775 if (!force && dwarf2out_do_cfi_asm ())
777 /* In this case, we will be emitting the asm directive instead of
778 the label, so just return a placeholder to keep the rest of the
780 strcpy (label, "<do not output>");
784 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
785 ASM_OUTPUT_LABEL (asm_out_file, label);
791 /* True if remember_state should be emitted before following CFI directive. */
792 static bool emit_cfa_remember;
794 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
795 or to the CIE if LABEL is NULL. */
798 add_fde_cfi (const char *label, dw_cfi_ref cfi)
800 dw_cfi_ref *list_head;
802 if (emit_cfa_remember)
804 dw_cfi_ref cfi_remember;
806 /* Emit the state save. */
807 emit_cfa_remember = false;
808 cfi_remember = new_cfi ();
809 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
810 add_fde_cfi (label, cfi_remember);
813 list_head = &cie_cfi_head;
815 if (dwarf2out_do_cfi_asm ())
819 dw_fde_ref fde = current_fde ();
821 gcc_assert (fde != NULL);
823 /* We still have to add the cfi to the list so that lookup_cfa
824 works later on. When -g2 and above we even need to force
825 emitting of CFI labels and add to list a DW_CFA_set_loc for
826 convert_cfa_to_fb_loc_list purposes. If we're generating
827 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
828 convert_cfa_to_fb_loc_list. */
829 if (dwarf_version == 2
830 && debug_info_level > DINFO_LEVEL_TERSE
831 && (write_symbols == DWARF2_DEBUG
832 || write_symbols == VMS_AND_DWARF2_DEBUG))
834 switch (cfi->dw_cfi_opc)
836 case DW_CFA_def_cfa_offset:
837 case DW_CFA_def_cfa_offset_sf:
838 case DW_CFA_def_cfa_register:
840 case DW_CFA_def_cfa_sf:
841 case DW_CFA_def_cfa_expression:
842 case DW_CFA_restore_state:
843 if (*label == 0 || strcmp (label, "<do not output>") == 0)
844 label = dwarf2out_cfi_label (true);
846 if (fde->dw_fde_current_label == NULL
847 || strcmp (label, fde->dw_fde_current_label) != 0)
851 label = xstrdup (label);
853 /* Set the location counter to the new label. */
855 /* It doesn't metter whether DW_CFA_set_loc
856 or DW_CFA_advance_loc4 is added here, those aren't
857 emitted into assembly, only looked up by
858 convert_cfa_to_fb_loc_list. */
859 xcfi->dw_cfi_opc = DW_CFA_set_loc;
860 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
861 add_cfi (&fde->dw_fde_cfi, xcfi);
862 fde->dw_fde_current_label = label;
870 output_cfi_directive (cfi);
872 list_head = &fde->dw_fde_cfi;
874 /* ??? If this is a CFI for the CIE, we don't emit. This
875 assumes that the standard CIE contents that the assembler
876 uses matches the standard CIE contents that the compiler
877 uses. This is probably a bad assumption. I'm not quite
878 sure how to address this for now. */
882 dw_fde_ref fde = current_fde ();
884 gcc_assert (fde != NULL);
887 label = dwarf2out_cfi_label (false);
889 if (fde->dw_fde_current_label == NULL
890 || strcmp (label, fde->dw_fde_current_label) != 0)
894 label = xstrdup (label);
896 /* Set the location counter to the new label. */
898 /* If we have a current label, advance from there, otherwise
899 set the location directly using set_loc. */
900 xcfi->dw_cfi_opc = fde->dw_fde_current_label
901 ? DW_CFA_advance_loc4
903 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
904 add_cfi (&fde->dw_fde_cfi, xcfi);
906 fde->dw_fde_current_label = label;
909 list_head = &fde->dw_fde_cfi;
912 add_cfi (list_head, cfi);
915 /* Subroutine of lookup_cfa. */
918 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
920 switch (cfi->dw_cfi_opc)
922 case DW_CFA_def_cfa_offset:
923 case DW_CFA_def_cfa_offset_sf:
924 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
926 case DW_CFA_def_cfa_register:
927 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
930 case DW_CFA_def_cfa_sf:
931 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
932 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
934 case DW_CFA_def_cfa_expression:
935 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
938 case DW_CFA_remember_state:
939 gcc_assert (!remember->in_use);
941 remember->in_use = 1;
943 case DW_CFA_restore_state:
944 gcc_assert (remember->in_use);
946 remember->in_use = 0;
954 /* Find the previous value for the CFA. */
957 lookup_cfa (dw_cfa_location *loc)
961 dw_cfa_location remember;
963 memset (loc, 0, sizeof (*loc));
964 loc->reg = INVALID_REGNUM;
967 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
968 lookup_cfa_1 (cfi, loc, &remember);
970 fde = current_fde ();
972 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
973 lookup_cfa_1 (cfi, loc, &remember);
976 /* The current rule for calculating the DWARF2 canonical frame address. */
977 static dw_cfa_location cfa;
979 /* The register used for saving registers to the stack, and its offset
981 static dw_cfa_location cfa_store;
983 /* The current save location around an epilogue. */
984 static dw_cfa_location cfa_remember;
986 /* The running total of the size of arguments pushed onto the stack. */
987 static HOST_WIDE_INT args_size;
989 /* The last args_size we actually output. */
990 static HOST_WIDE_INT old_args_size;
992 /* Entry point to update the canonical frame address (CFA).
993 LABEL is passed to add_fde_cfi. The value of CFA is now to be
994 calculated from REG+OFFSET. */
997 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1001 loc.base_offset = 0;
1003 loc.offset = offset;
1004 def_cfa_1 (label, &loc);
1007 /* Determine if two dw_cfa_location structures define the same data. */
1010 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1012 return (loc1->reg == loc2->reg
1013 && loc1->offset == loc2->offset
1014 && loc1->indirect == loc2->indirect
1015 && (loc1->indirect == 0
1016 || loc1->base_offset == loc2->base_offset));
1019 /* This routine does the actual work. The CFA is now calculated from
1020 the dw_cfa_location structure. */
1023 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1026 dw_cfa_location old_cfa, loc;
1031 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1032 cfa_store.offset = loc.offset;
1034 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1035 lookup_cfa (&old_cfa);
1037 /* If nothing changed, no need to issue any call frame instructions. */
1038 if (cfa_equal_p (&loc, &old_cfa))
1043 if (loc.reg == old_cfa.reg && !loc.indirect && !old_cfa.indirect)
1045 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1046 the CFA register did not change but the offset did. The data
1047 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1048 in the assembler via the .cfi_def_cfa_offset directive. */
1050 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1052 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1053 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1056 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1057 else if (loc.offset == old_cfa.offset
1058 && old_cfa.reg != INVALID_REGNUM
1060 && !old_cfa.indirect)
1062 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1063 indicating the CFA register has changed to <register> but the
1064 offset has not changed. */
1065 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1066 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1070 else if (loc.indirect == 0)
1072 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1073 indicating the CFA register has changed to <register> with
1074 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1075 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1078 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1080 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1081 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1082 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1086 /* Construct a DW_CFA_def_cfa_expression instruction to
1087 calculate the CFA using a full location expression since no
1088 register-offset pair is available. */
1089 struct dw_loc_descr_struct *loc_list;
1091 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1092 loc_list = build_cfa_loc (&loc, 0);
1093 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1096 add_fde_cfi (label, cfi);
1099 /* Add the CFI for saving a register. REG is the CFA column number.
1100 LABEL is passed to add_fde_cfi.
1101 If SREG is -1, the register is saved at OFFSET from the CFA;
1102 otherwise it is saved in SREG. */
1105 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1107 dw_cfi_ref cfi = new_cfi ();
1108 dw_fde_ref fde = current_fde ();
1110 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1112 /* When stack is aligned, store REG using DW_CFA_expression with
1115 && fde->stack_realign
1116 && sreg == INVALID_REGNUM)
1118 cfi->dw_cfi_opc = DW_CFA_expression;
1119 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1120 cfi->dw_cfi_oprnd2.dw_cfi_loc
1121 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1123 else if (sreg == INVALID_REGNUM)
1125 if (need_data_align_sf_opcode (offset))
1126 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1127 else if (reg & ~0x3f)
1128 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1130 cfi->dw_cfi_opc = DW_CFA_offset;
1131 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1133 else if (sreg == reg)
1134 cfi->dw_cfi_opc = DW_CFA_same_value;
1137 cfi->dw_cfi_opc = DW_CFA_register;
1138 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1141 add_fde_cfi (label, cfi);
1144 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1145 This CFI tells the unwinder that it needs to restore the window registers
1146 from the previous frame's window save area.
1148 ??? Perhaps we should note in the CIE where windows are saved (instead of
1149 assuming 0(cfa)) and what registers are in the window. */
1152 dwarf2out_window_save (const char *label)
1154 dw_cfi_ref cfi = new_cfi ();
1156 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1157 add_fde_cfi (label, cfi);
1160 /* Entry point for saving a register to the stack. REG is the GCC register
1161 number. LABEL and OFFSET are passed to reg_save. */
1164 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1166 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1169 /* Entry point for saving the return address in the stack.
1170 LABEL and OFFSET are passed to reg_save. */
1173 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1175 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1178 /* Entry point for saving the return address in a register.
1179 LABEL and SREG are passed to reg_save. */
1182 dwarf2out_return_reg (const char *label, unsigned int sreg)
1184 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1187 #ifdef DWARF2_UNWIND_INFO
1188 /* Record the initial position of the return address. RTL is
1189 INCOMING_RETURN_ADDR_RTX. */
1192 initial_return_save (rtx rtl)
1194 unsigned int reg = INVALID_REGNUM;
1195 HOST_WIDE_INT offset = 0;
1197 switch (GET_CODE (rtl))
1200 /* RA is in a register. */
1201 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1205 /* RA is on the stack. */
1206 rtl = XEXP (rtl, 0);
1207 switch (GET_CODE (rtl))
1210 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1215 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1216 offset = INTVAL (XEXP (rtl, 1));
1220 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1221 offset = -INTVAL (XEXP (rtl, 1));
1231 /* The return address is at some offset from any value we can
1232 actually load. For instance, on the SPARC it is in %i7+8. Just
1233 ignore the offset for now; it doesn't matter for unwinding frames. */
1234 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1235 initial_return_save (XEXP (rtl, 0));
1242 if (reg != DWARF_FRAME_RETURN_COLUMN)
1243 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1247 /* Given a SET, calculate the amount of stack adjustment it
1250 static HOST_WIDE_INT
1251 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1252 HOST_WIDE_INT cur_offset)
1254 const_rtx src = SET_SRC (pattern);
1255 const_rtx dest = SET_DEST (pattern);
1256 HOST_WIDE_INT offset = 0;
1259 if (dest == stack_pointer_rtx)
1261 code = GET_CODE (src);
1263 /* Assume (set (reg sp) (reg whatever)) sets args_size
1265 if (code == REG && src != stack_pointer_rtx)
1267 offset = -cur_args_size;
1268 #ifndef STACK_GROWS_DOWNWARD
1271 return offset - cur_offset;
1274 if (! (code == PLUS || code == MINUS)
1275 || XEXP (src, 0) != stack_pointer_rtx
1276 || !CONST_INT_P (XEXP (src, 1)))
1279 /* (set (reg sp) (plus (reg sp) (const_int))) */
1280 offset = INTVAL (XEXP (src, 1));
1286 if (MEM_P (src) && !MEM_P (dest))
1290 /* (set (mem (pre_dec (reg sp))) (foo)) */
1291 src = XEXP (dest, 0);
1292 code = GET_CODE (src);
1298 if (XEXP (src, 0) == stack_pointer_rtx)
1300 rtx val = XEXP (XEXP (src, 1), 1);
1301 /* We handle only adjustments by constant amount. */
1302 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1303 && CONST_INT_P (val));
1304 offset = -INTVAL (val);
1311 if (XEXP (src, 0) == stack_pointer_rtx)
1313 offset = GET_MODE_SIZE (GET_MODE (dest));
1320 if (XEXP (src, 0) == stack_pointer_rtx)
1322 offset = -GET_MODE_SIZE (GET_MODE (dest));
1337 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1338 indexed by INSN_UID. */
1340 static HOST_WIDE_INT *barrier_args_size;
1342 /* Helper function for compute_barrier_args_size. Handle one insn. */
1344 static HOST_WIDE_INT
1345 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1346 VEC (rtx, heap) **next)
1348 HOST_WIDE_INT offset = 0;
1351 if (! RTX_FRAME_RELATED_P (insn))
1353 if (prologue_epilogue_contains (insn))
1355 else if (GET_CODE (PATTERN (insn)) == SET)
1356 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1357 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1358 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1360 /* There may be stack adjustments inside compound insns. Search
1362 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1363 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1364 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1365 cur_args_size, offset);
1370 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1374 expr = XEXP (expr, 0);
1375 if (GET_CODE (expr) == PARALLEL
1376 || GET_CODE (expr) == SEQUENCE)
1377 for (i = 1; i < XVECLEN (expr, 0); i++)
1379 rtx elem = XVECEXP (expr, 0, i);
1381 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1382 offset += stack_adjust_offset (elem, cur_args_size, offset);
1387 #ifndef STACK_GROWS_DOWNWARD
1391 cur_args_size += offset;
1392 if (cur_args_size < 0)
1397 rtx dest = JUMP_LABEL (insn);
1401 if (barrier_args_size [INSN_UID (dest)] < 0)
1403 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1404 VEC_safe_push (rtx, heap, *next, dest);
1409 return cur_args_size;
1412 /* Walk the whole function and compute args_size on BARRIERs. */
1415 compute_barrier_args_size (void)
1417 int max_uid = get_max_uid (), i;
1419 VEC (rtx, heap) *worklist, *next, *tmp;
1421 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1422 for (i = 0; i < max_uid; i++)
1423 barrier_args_size[i] = -1;
1425 worklist = VEC_alloc (rtx, heap, 20);
1426 next = VEC_alloc (rtx, heap, 20);
1427 insn = get_insns ();
1428 barrier_args_size[INSN_UID (insn)] = 0;
1429 VEC_quick_push (rtx, worklist, insn);
1432 while (!VEC_empty (rtx, worklist))
1434 rtx prev, body, first_insn;
1435 HOST_WIDE_INT cur_args_size;
1437 first_insn = insn = VEC_pop (rtx, worklist);
1438 cur_args_size = barrier_args_size[INSN_UID (insn)];
1439 prev = prev_nonnote_insn (insn);
1440 if (prev && BARRIER_P (prev))
1441 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1443 for (; insn; insn = NEXT_INSN (insn))
1445 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1447 if (BARRIER_P (insn))
1452 if (insn == first_insn)
1454 else if (barrier_args_size[INSN_UID (insn)] < 0)
1456 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1461 /* The insns starting with this label have been
1462 already scanned or are in the worklist. */
1467 body = PATTERN (insn);
1468 if (GET_CODE (body) == SEQUENCE)
1470 HOST_WIDE_INT dest_args_size = cur_args_size;
1471 for (i = 1; i < XVECLEN (body, 0); i++)
1472 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1473 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1475 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1476 dest_args_size, &next);
1479 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1480 cur_args_size, &next);
1482 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1483 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1484 dest_args_size, &next);
1487 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1488 cur_args_size, &next);
1492 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1496 if (VEC_empty (rtx, next))
1499 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1503 VEC_truncate (rtx, next, 0);
1506 VEC_free (rtx, heap, worklist);
1507 VEC_free (rtx, heap, next);
1510 /* Add a CFI to update the running total of the size of arguments
1511 pushed onto the stack. */
1514 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1518 if (size == old_args_size)
1521 old_args_size = size;
1524 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1525 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1526 add_fde_cfi (label, cfi);
1529 /* Record a stack adjustment of OFFSET bytes. */
1532 dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
1534 if (cfa.reg == STACK_POINTER_REGNUM)
1535 cfa.offset += offset;
1537 if (cfa_store.reg == STACK_POINTER_REGNUM)
1538 cfa_store.offset += offset;
1540 if (ACCUMULATE_OUTGOING_ARGS)
1543 #ifndef STACK_GROWS_DOWNWARD
1547 args_size += offset;
1551 def_cfa_1 (label, &cfa);
1552 if (flag_asynchronous_unwind_tables)
1553 dwarf2out_args_size (label, args_size);
1556 /* Check INSN to see if it looks like a push or a stack adjustment, and
1557 make a note of it if it does. EH uses this information to find out
1558 how much extra space it needs to pop off the stack. */
1561 dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
1563 HOST_WIDE_INT offset;
1567 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1568 with this function. Proper support would require all frame-related
1569 insns to be marked, and to be able to handle saving state around
1570 epilogues textually in the middle of the function. */
1571 if (prologue_epilogue_contains (insn))
1574 /* If INSN is an instruction from target of an annulled branch, the
1575 effects are for the target only and so current argument size
1576 shouldn't change at all. */
1578 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1579 && INSN_FROM_TARGET_P (insn))
1582 /* If only calls can throw, and we have a frame pointer,
1583 save up adjustments until we see the CALL_INSN. */
1584 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1586 if (CALL_P (insn) && !after_p)
1588 /* Extract the size of the args from the CALL rtx itself. */
1589 insn = PATTERN (insn);
1590 if (GET_CODE (insn) == PARALLEL)
1591 insn = XVECEXP (insn, 0, 0);
1592 if (GET_CODE (insn) == SET)
1593 insn = SET_SRC (insn);
1594 gcc_assert (GET_CODE (insn) == CALL);
1595 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1600 if (CALL_P (insn) && !after_p)
1602 if (!flag_asynchronous_unwind_tables)
1603 dwarf2out_args_size ("", args_size);
1606 else if (BARRIER_P (insn))
1608 /* Don't call compute_barrier_args_size () if the only
1609 BARRIER is at the end of function. */
1610 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1611 compute_barrier_args_size ();
1612 if (barrier_args_size == NULL)
1616 offset = barrier_args_size[INSN_UID (insn)];
1621 offset -= args_size;
1622 #ifndef STACK_GROWS_DOWNWARD
1626 else if (GET_CODE (PATTERN (insn)) == SET)
1627 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1628 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1629 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1631 /* There may be stack adjustments inside compound insns. Search
1633 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1634 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1635 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1644 label = dwarf2out_cfi_label (false);
1645 dwarf2out_stack_adjust (offset, label);
1650 /* We delay emitting a register save until either (a) we reach the end
1651 of the prologue or (b) the register is clobbered. This clusters
1652 register saves so that there are fewer pc advances. */
1654 struct GTY(()) queued_reg_save {
1655 struct queued_reg_save *next;
1657 HOST_WIDE_INT cfa_offset;
1661 static GTY(()) struct queued_reg_save *queued_reg_saves;
1663 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1664 struct GTY(()) reg_saved_in_data {
1669 /* A list of registers saved in other registers.
1670 The list intentionally has a small maximum capacity of 4; if your
1671 port needs more than that, you might consider implementing a
1672 more efficient data structure. */
1673 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1674 static GTY(()) size_t num_regs_saved_in_regs;
1676 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1677 static const char *last_reg_save_label;
1679 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1680 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1683 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1685 struct queued_reg_save *q;
1687 /* Duplicates waste space, but it's also necessary to remove them
1688 for correctness, since the queue gets output in reverse
1690 for (q = queued_reg_saves; q != NULL; q = q->next)
1691 if (REGNO (q->reg) == REGNO (reg))
1696 q = GGC_NEW (struct queued_reg_save);
1697 q->next = queued_reg_saves;
1698 queued_reg_saves = q;
1702 q->cfa_offset = offset;
1703 q->saved_reg = sreg;
1705 last_reg_save_label = label;
1708 /* Output all the entries in QUEUED_REG_SAVES. */
1711 flush_queued_reg_saves (void)
1713 struct queued_reg_save *q;
1715 for (q = queued_reg_saves; q; q = q->next)
1718 unsigned int reg, sreg;
1720 for (i = 0; i < num_regs_saved_in_regs; i++)
1721 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1723 if (q->saved_reg && i == num_regs_saved_in_regs)
1725 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1726 num_regs_saved_in_regs++;
1728 if (i != num_regs_saved_in_regs)
1730 regs_saved_in_regs[i].orig_reg = q->reg;
1731 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1734 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1736 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1738 sreg = INVALID_REGNUM;
1739 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1742 queued_reg_saves = NULL;
1743 last_reg_save_label = NULL;
1746 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1747 location for? Or, does it clobber a register which we've previously
1748 said that some other register is saved in, and for which we now
1749 have a new location for? */
1752 clobbers_queued_reg_save (const_rtx insn)
1754 struct queued_reg_save *q;
1756 for (q = queued_reg_saves; q; q = q->next)
1759 if (modified_in_p (q->reg, insn))
1761 for (i = 0; i < num_regs_saved_in_regs; i++)
1762 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1763 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1770 /* Entry point for saving the first register into the second. */
1773 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1776 unsigned int regno, sregno;
1778 for (i = 0; i < num_regs_saved_in_regs; i++)
1779 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1781 if (i == num_regs_saved_in_regs)
1783 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1784 num_regs_saved_in_regs++;
1786 regs_saved_in_regs[i].orig_reg = reg;
1787 regs_saved_in_regs[i].saved_in_reg = sreg;
1789 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1790 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1791 reg_save (label, regno, sregno, 0);
1794 /* What register, if any, is currently saved in REG? */
1797 reg_saved_in (rtx reg)
1799 unsigned int regn = REGNO (reg);
1801 struct queued_reg_save *q;
1803 for (q = queued_reg_saves; q; q = q->next)
1804 if (q->saved_reg && regn == REGNO (q->saved_reg))
1807 for (i = 0; i < num_regs_saved_in_regs; i++)
1808 if (regs_saved_in_regs[i].saved_in_reg
1809 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1810 return regs_saved_in_regs[i].orig_reg;
1816 /* A temporary register holding an integral value used in adjusting SP
1817 or setting up the store_reg. The "offset" field holds the integer
1818 value, not an offset. */
1819 static dw_cfa_location cfa_temp;
1821 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1824 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1826 memset (&cfa, 0, sizeof (cfa));
1828 switch (GET_CODE (pat))
1831 cfa.reg = REGNO (XEXP (pat, 0));
1832 cfa.offset = INTVAL (XEXP (pat, 1));
1836 cfa.reg = REGNO (pat);
1840 /* Recurse and define an expression. */
1844 def_cfa_1 (label, &cfa);
1847 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1850 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1854 gcc_assert (GET_CODE (pat) == SET);
1855 dest = XEXP (pat, 0);
1856 src = XEXP (pat, 1);
1858 switch (GET_CODE (src))
1861 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1862 cfa.offset -= INTVAL (XEXP (src, 1));
1872 cfa.reg = REGNO (dest);
1873 gcc_assert (cfa.indirect == 0);
1875 def_cfa_1 (label, &cfa);
1878 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1881 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1883 HOST_WIDE_INT offset;
1884 rtx src, addr, span;
1886 src = XEXP (set, 1);
1887 addr = XEXP (set, 0);
1888 gcc_assert (MEM_P (addr));
1889 addr = XEXP (addr, 0);
1891 /* As documented, only consider extremely simple addresses. */
1892 switch (GET_CODE (addr))
1895 gcc_assert (REGNO (addr) == cfa.reg);
1896 offset = -cfa.offset;
1899 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1900 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1906 span = targetm.dwarf_register_span (src);
1908 /* ??? We'd like to use queue_reg_save, but we need to come up with
1909 a different flushing heuristic for epilogues. */
1911 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
1914 /* We have a PARALLEL describing where the contents of SRC live.
1915 Queue register saves for each piece of the PARALLEL. */
1918 HOST_WIDE_INT span_offset = offset;
1920 gcc_assert (GET_CODE (span) == PARALLEL);
1922 limit = XVECLEN (span, 0);
1923 for (par_index = 0; par_index < limit; par_index++)
1925 rtx elem = XVECEXP (span, 0, par_index);
1927 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
1928 INVALID_REGNUM, span_offset);
1929 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1934 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1937 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
1940 unsigned sregno, dregno;
1942 src = XEXP (set, 1);
1943 dest = XEXP (set, 0);
1946 sregno = DWARF_FRAME_RETURN_COLUMN;
1948 sregno = DWARF_FRAME_REGNUM (REGNO (src));
1950 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
1952 /* ??? We'd like to use queue_reg_save, but we need to come up with
1953 a different flushing heuristic for epilogues. */
1954 reg_save (label, sregno, dregno, 0);
1957 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1960 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
1962 dw_cfi_ref cfi = new_cfi ();
1963 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
1965 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
1966 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
1968 add_fde_cfi (label, cfi);
1971 /* Record call frame debugging information for an expression EXPR,
1972 which either sets SP or FP (adjusting how we calculate the frame
1973 address) or saves a register to the stack or another register.
1974 LABEL indicates the address of EXPR.
1976 This function encodes a state machine mapping rtxes to actions on
1977 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1978 users need not read the source code.
1980 The High-Level Picture
1982 Changes in the register we use to calculate the CFA: Currently we
1983 assume that if you copy the CFA register into another register, we
1984 should take the other one as the new CFA register; this seems to
1985 work pretty well. If it's wrong for some target, it's simple
1986 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1988 Changes in the register we use for saving registers to the stack:
1989 This is usually SP, but not always. Again, we deduce that if you
1990 copy SP into another register (and SP is not the CFA register),
1991 then the new register is the one we will be using for register
1992 saves. This also seems to work.
1994 Register saves: There's not much guesswork about this one; if
1995 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1996 register save, and the register used to calculate the destination
1997 had better be the one we think we're using for this purpose.
1998 It's also assumed that a copy from a call-saved register to another
1999 register is saving that register if RTX_FRAME_RELATED_P is set on
2000 that instruction. If the copy is from a call-saved register to
2001 the *same* register, that means that the register is now the same
2002 value as in the caller.
2004 Except: If the register being saved is the CFA register, and the
2005 offset is nonzero, we are saving the CFA, so we assume we have to
2006 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2007 the intent is to save the value of SP from the previous frame.
2009 In addition, if a register has previously been saved to a different
2012 Invariants / Summaries of Rules
2014 cfa current rule for calculating the CFA. It usually
2015 consists of a register and an offset.
2016 cfa_store register used by prologue code to save things to the stack
2017 cfa_store.offset is the offset from the value of
2018 cfa_store.reg to the actual CFA
2019 cfa_temp register holding an integral value. cfa_temp.offset
2020 stores the value, which will be used to adjust the
2021 stack pointer. cfa_temp is also used like cfa_store,
2022 to track stores to the stack via fp or a temp reg.
2024 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2025 with cfa.reg as the first operand changes the cfa.reg and its
2026 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2029 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2030 expression yielding a constant. This sets cfa_temp.reg
2031 and cfa_temp.offset.
2033 Rule 5: Create a new register cfa_store used to save items to the
2036 Rules 10-14: Save a register to the stack. Define offset as the
2037 difference of the original location and cfa_store's
2038 location (or cfa_temp's location if cfa_temp is used).
2040 Rules 16-20: If AND operation happens on sp in prologue, we assume
2041 stack is realigned. We will use a group of DW_OP_XXX
2042 expressions to represent the location of the stored
2043 register instead of CFA+offset.
2047 "{a,b}" indicates a choice of a xor b.
2048 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2051 (set <reg1> <reg2>:cfa.reg)
2052 effects: cfa.reg = <reg1>
2053 cfa.offset unchanged
2054 cfa_temp.reg = <reg1>
2055 cfa_temp.offset = cfa.offset
2058 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2059 {<const_int>,<reg>:cfa_temp.reg}))
2060 effects: cfa.reg = sp if fp used
2061 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2062 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2063 if cfa_store.reg==sp
2066 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2067 effects: cfa.reg = fp
2068 cfa_offset += +/- <const_int>
2071 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2072 constraints: <reg1> != fp
2074 effects: cfa.reg = <reg1>
2075 cfa_temp.reg = <reg1>
2076 cfa_temp.offset = cfa.offset
2079 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2080 constraints: <reg1> != fp
2082 effects: cfa_store.reg = <reg1>
2083 cfa_store.offset = cfa.offset - cfa_temp.offset
2086 (set <reg> <const_int>)
2087 effects: cfa_temp.reg = <reg>
2088 cfa_temp.offset = <const_int>
2091 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2092 effects: cfa_temp.reg = <reg1>
2093 cfa_temp.offset |= <const_int>
2096 (set <reg> (high <exp>))
2100 (set <reg> (lo_sum <exp> <const_int>))
2101 effects: cfa_temp.reg = <reg>
2102 cfa_temp.offset = <const_int>
2105 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2106 effects: cfa_store.offset -= <const_int>
2107 cfa.offset = cfa_store.offset if cfa.reg == sp
2109 cfa.base_offset = -cfa_store.offset
2112 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2113 effects: cfa_store.offset += -/+ mode_size(mem)
2114 cfa.offset = cfa_store.offset if cfa.reg == sp
2116 cfa.base_offset = -cfa_store.offset
2119 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2122 effects: cfa.reg = <reg1>
2123 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2126 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2127 effects: cfa.reg = <reg1>
2128 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2131 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2132 effects: cfa.reg = <reg1>
2133 cfa.base_offset = -cfa_temp.offset
2134 cfa_temp.offset -= mode_size(mem)
2137 (set <reg> {unspec, unspec_volatile})
2138 effects: target-dependent
2141 (set sp (and: sp <const_int>))
2142 constraints: cfa_store.reg == sp
2143 effects: current_fde.stack_realign = 1
2144 cfa_store.offset = 0
2145 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2148 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2149 effects: cfa_store.offset += -/+ mode_size(mem)
2152 (set (mem ({pre_inc, pre_dec} sp)) fp)
2153 constraints: fde->stack_realign == 1
2154 effects: cfa_store.offset = 0
2155 cfa.reg != HARD_FRAME_POINTER_REGNUM
2158 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2159 constraints: fde->stack_realign == 1
2161 && cfa.indirect == 0
2162 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2163 effects: Use DW_CFA_def_cfa_expression to define cfa
2164 cfa.reg == fde->drap_reg */
2167 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2169 rtx src, dest, span;
2170 HOST_WIDE_INT offset;
2173 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2174 the PARALLEL independently. The first element is always processed if
2175 it is a SET. This is for backward compatibility. Other elements
2176 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2177 flag is set in them. */
2178 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2181 int limit = XVECLEN (expr, 0);
2184 /* PARALLELs have strict read-modify-write semantics, so we
2185 ought to evaluate every rvalue before changing any lvalue.
2186 It's cumbersome to do that in general, but there's an
2187 easy approximation that is enough for all current users:
2188 handle register saves before register assignments. */
2189 if (GET_CODE (expr) == PARALLEL)
2190 for (par_index = 0; par_index < limit; par_index++)
2192 elem = XVECEXP (expr, 0, par_index);
2193 if (GET_CODE (elem) == SET
2194 && MEM_P (SET_DEST (elem))
2195 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2196 dwarf2out_frame_debug_expr (elem, label);
2199 for (par_index = 0; par_index < limit; par_index++)
2201 elem = XVECEXP (expr, 0, par_index);
2202 if (GET_CODE (elem) == SET
2203 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2204 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2205 dwarf2out_frame_debug_expr (elem, label);
2206 else if (GET_CODE (elem) == SET
2208 && !RTX_FRAME_RELATED_P (elem))
2210 /* Stack adjustment combining might combine some post-prologue
2211 stack adjustment into a prologue stack adjustment. */
2212 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2215 dwarf2out_stack_adjust (offset, label);
2221 gcc_assert (GET_CODE (expr) == SET);
2223 src = SET_SRC (expr);
2224 dest = SET_DEST (expr);
2228 rtx rsi = reg_saved_in (src);
2233 fde = current_fde ();
2235 switch (GET_CODE (dest))
2238 switch (GET_CODE (src))
2240 /* Setting FP from SP. */
2242 if (cfa.reg == (unsigned) REGNO (src))
2245 /* Update the CFA rule wrt SP or FP. Make sure src is
2246 relative to the current CFA register.
2248 We used to require that dest be either SP or FP, but the
2249 ARM copies SP to a temporary register, and from there to
2250 FP. So we just rely on the backends to only set
2251 RTX_FRAME_RELATED_P on appropriate insns. */
2252 cfa.reg = REGNO (dest);
2253 cfa_temp.reg = cfa.reg;
2254 cfa_temp.offset = cfa.offset;
2258 /* Saving a register in a register. */
2259 gcc_assert (!fixed_regs [REGNO (dest)]
2260 /* For the SPARC and its register window. */
2261 || (DWARF_FRAME_REGNUM (REGNO (src))
2262 == DWARF_FRAME_RETURN_COLUMN));
2264 /* After stack is aligned, we can only save SP in FP
2265 if drap register is used. In this case, we have
2266 to restore stack pointer with the CFA value and we
2267 don't generate this DWARF information. */
2269 && fde->stack_realign
2270 && REGNO (src) == STACK_POINTER_REGNUM)
2271 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2272 && fde->drap_reg != INVALID_REGNUM
2273 && cfa.reg != REGNO (src));
2275 queue_reg_save (label, src, dest, 0);
2282 if (dest == stack_pointer_rtx)
2286 switch (GET_CODE (XEXP (src, 1)))
2289 offset = INTVAL (XEXP (src, 1));
2292 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2294 offset = cfa_temp.offset;
2300 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2302 /* Restoring SP from FP in the epilogue. */
2303 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2304 cfa.reg = STACK_POINTER_REGNUM;
2306 else if (GET_CODE (src) == LO_SUM)
2307 /* Assume we've set the source reg of the LO_SUM from sp. */
2310 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2312 if (GET_CODE (src) != MINUS)
2314 if (cfa.reg == STACK_POINTER_REGNUM)
2315 cfa.offset += offset;
2316 if (cfa_store.reg == STACK_POINTER_REGNUM)
2317 cfa_store.offset += offset;
2319 else if (dest == hard_frame_pointer_rtx)
2322 /* Either setting the FP from an offset of the SP,
2323 or adjusting the FP */
2324 gcc_assert (frame_pointer_needed);
2326 gcc_assert (REG_P (XEXP (src, 0))
2327 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2328 && CONST_INT_P (XEXP (src, 1)));
2329 offset = INTVAL (XEXP (src, 1));
2330 if (GET_CODE (src) != MINUS)
2332 cfa.offset += offset;
2333 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2337 gcc_assert (GET_CODE (src) != MINUS);
2340 if (REG_P (XEXP (src, 0))
2341 && REGNO (XEXP (src, 0)) == cfa.reg
2342 && CONST_INT_P (XEXP (src, 1)))
2344 /* Setting a temporary CFA register that will be copied
2345 into the FP later on. */
2346 offset = - INTVAL (XEXP (src, 1));
2347 cfa.offset += offset;
2348 cfa.reg = REGNO (dest);
2349 /* Or used to save regs to the stack. */
2350 cfa_temp.reg = cfa.reg;
2351 cfa_temp.offset = cfa.offset;
2355 else if (REG_P (XEXP (src, 0))
2356 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2357 && XEXP (src, 1) == stack_pointer_rtx)
2359 /* Setting a scratch register that we will use instead
2360 of SP for saving registers to the stack. */
2361 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2362 cfa_store.reg = REGNO (dest);
2363 cfa_store.offset = cfa.offset - cfa_temp.offset;
2367 else if (GET_CODE (src) == LO_SUM
2368 && CONST_INT_P (XEXP (src, 1)))
2370 cfa_temp.reg = REGNO (dest);
2371 cfa_temp.offset = INTVAL (XEXP (src, 1));
2380 cfa_temp.reg = REGNO (dest);
2381 cfa_temp.offset = INTVAL (src);
2386 gcc_assert (REG_P (XEXP (src, 0))
2387 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2388 && CONST_INT_P (XEXP (src, 1)));
2390 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2391 cfa_temp.reg = REGNO (dest);
2392 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2395 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2396 which will fill in all of the bits. */
2403 case UNSPEC_VOLATILE:
2404 gcc_assert (targetm.dwarf_handle_frame_unspec);
2405 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2410 /* If this AND operation happens on stack pointer in prologue,
2411 we assume the stack is realigned and we extract the
2413 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2415 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2416 fde->stack_realign = 1;
2417 fde->stack_realignment = INTVAL (XEXP (src, 1));
2418 cfa_store.offset = 0;
2420 if (cfa.reg != STACK_POINTER_REGNUM
2421 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2422 fde->drap_reg = cfa.reg;
2430 def_cfa_1 (label, &cfa);
2435 /* Saving a register to the stack. Make sure dest is relative to the
2437 switch (GET_CODE (XEXP (dest, 0)))
2442 /* We can't handle variable size modifications. */
2443 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2445 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2447 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2448 && cfa_store.reg == STACK_POINTER_REGNUM);
2450 cfa_store.offset += offset;
2451 if (cfa.reg == STACK_POINTER_REGNUM)
2452 cfa.offset = cfa_store.offset;
2454 offset = -cfa_store.offset;
2460 offset = GET_MODE_SIZE (GET_MODE (dest));
2461 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2464 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2465 == STACK_POINTER_REGNUM)
2466 && cfa_store.reg == STACK_POINTER_REGNUM);
2468 cfa_store.offset += offset;
2470 /* Rule 18: If stack is aligned, we will use FP as a
2471 reference to represent the address of the stored
2474 && fde->stack_realign
2475 && src == hard_frame_pointer_rtx)
2477 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2478 cfa_store.offset = 0;
2481 if (cfa.reg == STACK_POINTER_REGNUM)
2482 cfa.offset = cfa_store.offset;
2484 offset = -cfa_store.offset;
2488 /* With an offset. */
2495 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2496 && REG_P (XEXP (XEXP (dest, 0), 0)));
2497 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2498 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2501 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2503 if (cfa_store.reg == (unsigned) regno)
2504 offset -= cfa_store.offset;
2507 gcc_assert (cfa_temp.reg == (unsigned) regno);
2508 offset -= cfa_temp.offset;
2514 /* Without an offset. */
2517 int regno = REGNO (XEXP (dest, 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;
2531 gcc_assert (cfa_temp.reg
2532 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2533 offset = -cfa_temp.offset;
2534 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2542 /* If the source operand of this MEM operation is not a
2543 register, basically the source is return address. Here
2544 we only care how much stack grew and we don't save it. */
2548 if (REGNO (src) != STACK_POINTER_REGNUM
2549 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2550 && (unsigned) REGNO (src) == cfa.reg)
2552 /* We're storing the current CFA reg into the stack. */
2554 if (cfa.offset == 0)
2557 /* If stack is aligned, putting CFA reg into stack means
2558 we can no longer use reg + offset to represent CFA.
2559 Here we use DW_CFA_def_cfa_expression instead. The
2560 result of this expression equals to the original CFA
2563 && fde->stack_realign
2564 && cfa.indirect == 0
2565 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2567 dw_cfa_location cfa_exp;
2569 gcc_assert (fde->drap_reg == cfa.reg);
2571 cfa_exp.indirect = 1;
2572 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2573 cfa_exp.base_offset = offset;
2576 fde->drap_reg_saved = 1;
2578 def_cfa_1 (label, &cfa_exp);
2582 /* If the source register is exactly the CFA, assume
2583 we're saving SP like any other register; this happens
2585 def_cfa_1 (label, &cfa);
2586 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2591 /* Otherwise, we'll need to look in the stack to
2592 calculate the CFA. */
2593 rtx x = XEXP (dest, 0);
2597 gcc_assert (REG_P (x));
2599 cfa.reg = REGNO (x);
2600 cfa.base_offset = offset;
2602 def_cfa_1 (label, &cfa);
2607 def_cfa_1 (label, &cfa);
2609 span = targetm.dwarf_register_span (src);
2612 queue_reg_save (label, src, NULL_RTX, offset);
2615 /* We have a PARALLEL describing where the contents of SRC
2616 live. Queue register saves for each piece of the
2620 HOST_WIDE_INT span_offset = offset;
2622 gcc_assert (GET_CODE (span) == PARALLEL);
2624 limit = XVECLEN (span, 0);
2625 for (par_index = 0; par_index < limit; par_index++)
2627 rtx elem = XVECEXP (span, 0, par_index);
2629 queue_reg_save (label, elem, NULL_RTX, span_offset);
2630 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2641 /* Record call frame debugging information for INSN, which either
2642 sets SP or FP (adjusting how we calculate the frame address) or saves a
2643 register to the stack. If INSN is NULL_RTX, initialize our state.
2645 If AFTER_P is false, we're being called before the insn is emitted,
2646 otherwise after. Call instructions get invoked twice. */
2649 dwarf2out_frame_debug (rtx insn, bool after_p)
2653 bool handled_one = false;
2655 if (insn == NULL_RTX)
2659 /* Flush any queued register saves. */
2660 flush_queued_reg_saves ();
2662 /* Set up state for generating call frame debug info. */
2665 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2667 cfa.reg = STACK_POINTER_REGNUM;
2670 cfa_temp.offset = 0;
2672 for (i = 0; i < num_regs_saved_in_regs; i++)
2674 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2675 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2677 num_regs_saved_in_regs = 0;
2679 if (barrier_args_size)
2681 XDELETEVEC (barrier_args_size);
2682 barrier_args_size = NULL;
2687 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2688 flush_queued_reg_saves ();
2690 if (!RTX_FRAME_RELATED_P (insn))
2692 /* ??? This should be done unconditionally since stack adjustments
2693 matter if the stack pointer is not the CFA register anymore but
2694 is still used to save registers. */
2695 if (!ACCUMULATE_OUTGOING_ARGS)
2696 dwarf2out_notice_stack_adjust (insn, after_p);
2700 label = dwarf2out_cfi_label (false);
2702 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2703 switch (REG_NOTE_KIND (note))
2705 case REG_FRAME_RELATED_EXPR:
2706 insn = XEXP (note, 0);
2709 case REG_CFA_DEF_CFA:
2710 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2714 case REG_CFA_ADJUST_CFA:
2719 if (GET_CODE (n) == PARALLEL)
2720 n = XVECEXP (n, 0, 0);
2722 dwarf2out_frame_debug_adjust_cfa (n, label);
2726 case REG_CFA_OFFSET:
2729 n = single_set (insn);
2730 dwarf2out_frame_debug_cfa_offset (n, label);
2734 case REG_CFA_REGISTER:
2739 if (GET_CODE (n) == PARALLEL)
2740 n = XVECEXP (n, 0, 0);
2742 dwarf2out_frame_debug_cfa_register (n, label);
2746 case REG_CFA_RESTORE:
2751 if (GET_CODE (n) == PARALLEL)
2752 n = XVECEXP (n, 0, 0);
2755 dwarf2out_frame_debug_cfa_restore (n, label);
2759 case REG_CFA_SET_VDRAP:
2763 dw_fde_ref fde = current_fde ();
2766 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2768 fde->vdrap_reg = REGNO (n);
2780 insn = PATTERN (insn);
2782 dwarf2out_frame_debug_expr (insn, label);
2785 /* Determine if we need to save and restore CFI information around this
2786 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2787 we do need to save/restore, then emit the save now, and insert a
2788 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2791 dwarf2out_begin_epilogue (rtx insn)
2793 bool saw_frp = false;
2796 /* Scan forward to the return insn, noticing if there are possible
2797 frame related insns. */
2798 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2803 /* Look for both regular and sibcalls to end the block. */
2804 if (returnjump_p (i))
2806 if (CALL_P (i) && SIBLING_CALL_P (i))
2809 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2812 rtx seq = PATTERN (i);
2814 if (returnjump_p (XVECEXP (seq, 0, 0)))
2816 if (CALL_P (XVECEXP (seq, 0, 0))
2817 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2820 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2821 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2825 if (RTX_FRAME_RELATED_P (i))
2829 /* If the port doesn't emit epilogue unwind info, we don't need a
2830 save/restore pair. */
2834 /* Otherwise, search forward to see if the return insn was the last
2835 basic block of the function. If so, we don't need save/restore. */
2836 gcc_assert (i != NULL);
2837 i = next_real_insn (i);
2841 /* Insert the restore before that next real insn in the stream, and before
2842 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2843 properly nested. This should be after any label or alignment. This
2844 will be pushed into the CFI stream by the function below. */
2847 rtx p = PREV_INSN (i);
2850 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
2854 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
2856 emit_cfa_remember = true;
2858 /* And emulate the state save. */
2859 gcc_assert (!cfa_remember.in_use);
2861 cfa_remember.in_use = 1;
2864 /* A "subroutine" of dwarf2out_begin_epilogue. Emit the restore required. */
2867 dwarf2out_frame_debug_restore_state (void)
2869 dw_cfi_ref cfi = new_cfi ();
2870 const char *label = dwarf2out_cfi_label (false);
2872 cfi->dw_cfi_opc = DW_CFA_restore_state;
2873 add_fde_cfi (label, cfi);
2875 gcc_assert (cfa_remember.in_use);
2877 cfa_remember.in_use = 0;
2882 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2883 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2884 (enum dwarf_call_frame_info cfi);
2886 static enum dw_cfi_oprnd_type
2887 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2892 case DW_CFA_GNU_window_save:
2893 case DW_CFA_remember_state:
2894 case DW_CFA_restore_state:
2895 return dw_cfi_oprnd_unused;
2897 case DW_CFA_set_loc:
2898 case DW_CFA_advance_loc1:
2899 case DW_CFA_advance_loc2:
2900 case DW_CFA_advance_loc4:
2901 case DW_CFA_MIPS_advance_loc8:
2902 return dw_cfi_oprnd_addr;
2905 case DW_CFA_offset_extended:
2906 case DW_CFA_def_cfa:
2907 case DW_CFA_offset_extended_sf:
2908 case DW_CFA_def_cfa_sf:
2909 case DW_CFA_restore:
2910 case DW_CFA_restore_extended:
2911 case DW_CFA_undefined:
2912 case DW_CFA_same_value:
2913 case DW_CFA_def_cfa_register:
2914 case DW_CFA_register:
2915 case DW_CFA_expression:
2916 return dw_cfi_oprnd_reg_num;
2918 case DW_CFA_def_cfa_offset:
2919 case DW_CFA_GNU_args_size:
2920 case DW_CFA_def_cfa_offset_sf:
2921 return dw_cfi_oprnd_offset;
2923 case DW_CFA_def_cfa_expression:
2924 return dw_cfi_oprnd_loc;
2931 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2932 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2933 (enum dwarf_call_frame_info cfi);
2935 static enum dw_cfi_oprnd_type
2936 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2940 case DW_CFA_def_cfa:
2941 case DW_CFA_def_cfa_sf:
2943 case DW_CFA_offset_extended_sf:
2944 case DW_CFA_offset_extended:
2945 return dw_cfi_oprnd_offset;
2947 case DW_CFA_register:
2948 return dw_cfi_oprnd_reg_num;
2950 case DW_CFA_expression:
2951 return dw_cfi_oprnd_loc;
2954 return dw_cfi_oprnd_unused;
2958 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2960 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
2961 switch to the data section instead, and write out a synthetic start label
2962 for collect2 the first time around. */
2965 switch_to_eh_frame_section (bool back)
2969 #ifdef EH_FRAME_SECTION_NAME
2970 if (eh_frame_section == 0)
2974 if (EH_TABLES_CAN_BE_READ_ONLY)
2980 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2982 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2984 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2986 flags = ((! flag_pic
2987 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2988 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2989 && (per_encoding & 0x70) != DW_EH_PE_absptr
2990 && (per_encoding & 0x70) != DW_EH_PE_aligned
2991 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2992 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2993 ? 0 : SECTION_WRITE);
2996 flags = SECTION_WRITE;
2997 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3001 if (eh_frame_section)
3002 switch_to_section (eh_frame_section);
3005 /* We have no special eh_frame section. Put the information in
3006 the data section and emit special labels to guide collect2. */
3007 switch_to_section (data_section);
3011 label = get_file_function_name ("F");
3012 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3013 targetm.asm_out.globalize_label (asm_out_file,
3014 IDENTIFIER_POINTER (label));
3015 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3020 /* Switch [BACK] to the eh or debug frame table section, depending on
3024 switch_to_frame_table_section (int for_eh, bool back)
3027 switch_to_eh_frame_section (back);
3030 if (!debug_frame_section)
3031 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3032 SECTION_DEBUG, NULL);
3033 switch_to_section (debug_frame_section);
3037 /* Output a Call Frame Information opcode and its operand(s). */
3040 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3045 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3046 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3047 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3048 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3049 ((unsigned HOST_WIDE_INT)
3050 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3051 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3053 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3054 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3055 "DW_CFA_offset, column %#lx", r);
3056 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3057 dw2_asm_output_data_uleb128 (off, NULL);
3059 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3061 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3062 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3063 "DW_CFA_restore, column %#lx", r);
3067 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3068 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3070 switch (cfi->dw_cfi_opc)
3072 case DW_CFA_set_loc:
3074 dw2_asm_output_encoded_addr_rtx (
3075 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3076 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3079 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3080 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3081 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3084 case DW_CFA_advance_loc1:
3085 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3086 fde->dw_fde_current_label, NULL);
3087 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3090 case DW_CFA_advance_loc2:
3091 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3092 fde->dw_fde_current_label, NULL);
3093 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3096 case DW_CFA_advance_loc4:
3097 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3098 fde->dw_fde_current_label, NULL);
3099 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3102 case DW_CFA_MIPS_advance_loc8:
3103 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3104 fde->dw_fde_current_label, NULL);
3105 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3108 case DW_CFA_offset_extended:
3109 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3110 dw2_asm_output_data_uleb128 (r, NULL);
3111 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3112 dw2_asm_output_data_uleb128 (off, NULL);
3115 case DW_CFA_def_cfa:
3116 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3117 dw2_asm_output_data_uleb128 (r, NULL);
3118 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3121 case DW_CFA_offset_extended_sf:
3122 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3123 dw2_asm_output_data_uleb128 (r, NULL);
3124 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3125 dw2_asm_output_data_sleb128 (off, NULL);
3128 case DW_CFA_def_cfa_sf:
3129 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3130 dw2_asm_output_data_uleb128 (r, NULL);
3131 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3132 dw2_asm_output_data_sleb128 (off, NULL);
3135 case DW_CFA_restore_extended:
3136 case DW_CFA_undefined:
3137 case DW_CFA_same_value:
3138 case DW_CFA_def_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);
3143 case DW_CFA_register:
3144 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3145 dw2_asm_output_data_uleb128 (r, NULL);
3146 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3147 dw2_asm_output_data_uleb128 (r, NULL);
3150 case DW_CFA_def_cfa_offset:
3151 case DW_CFA_GNU_args_size:
3152 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3155 case DW_CFA_def_cfa_offset_sf:
3156 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3157 dw2_asm_output_data_sleb128 (off, NULL);
3160 case DW_CFA_GNU_window_save:
3163 case DW_CFA_def_cfa_expression:
3164 case DW_CFA_expression:
3165 output_cfa_loc (cfi);
3168 case DW_CFA_GNU_negative_offset_extended:
3169 /* Obsoleted by DW_CFA_offset_extended_sf. */
3178 /* Similar, but do it via assembler directives instead. */
3181 output_cfi_directive (dw_cfi_ref cfi)
3183 unsigned long r, r2;
3185 switch (cfi->dw_cfi_opc)
3187 case DW_CFA_advance_loc:
3188 case DW_CFA_advance_loc1:
3189 case DW_CFA_advance_loc2:
3190 case DW_CFA_advance_loc4:
3191 case DW_CFA_MIPS_advance_loc8:
3192 case DW_CFA_set_loc:
3193 /* Should only be created by add_fde_cfi in a code path not
3194 followed when emitting via directives. The assembler is
3195 going to take care of this for us. */
3199 case DW_CFA_offset_extended:
3200 case DW_CFA_offset_extended_sf:
3201 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3202 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3203 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3206 case DW_CFA_restore:
3207 case DW_CFA_restore_extended:
3208 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3209 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3212 case DW_CFA_undefined:
3213 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3214 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3217 case DW_CFA_same_value:
3218 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3219 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3222 case DW_CFA_def_cfa:
3223 case DW_CFA_def_cfa_sf:
3224 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3225 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3226 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3229 case DW_CFA_def_cfa_register:
3230 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3231 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3234 case DW_CFA_register:
3235 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3236 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3237 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3240 case DW_CFA_def_cfa_offset:
3241 case DW_CFA_def_cfa_offset_sf:
3242 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3243 HOST_WIDE_INT_PRINT_DEC"\n",
3244 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3247 case DW_CFA_remember_state:
3248 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3250 case DW_CFA_restore_state:
3251 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3254 case DW_CFA_GNU_args_size:
3255 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3256 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3258 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3259 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3260 fputc ('\n', asm_out_file);
3263 case DW_CFA_GNU_window_save:
3264 fprintf (asm_out_file, "\t.cfi_window_save\n");
3267 case DW_CFA_def_cfa_expression:
3268 case DW_CFA_expression:
3269 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3270 output_cfa_loc_raw (cfi);
3271 fputc ('\n', asm_out_file);
3279 DEF_VEC_P (dw_cfi_ref);
3280 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3282 /* Output CFIs to bring current FDE to the same state as after executing
3283 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3284 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3285 other arguments to pass to output_cfi. */
3288 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3290 struct dw_cfi_struct cfi_buf;
3292 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3293 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3294 unsigned int len, idx;
3296 for (;; cfi = cfi->dw_cfi_next)
3297 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3299 case DW_CFA_advance_loc:
3300 case DW_CFA_advance_loc1:
3301 case DW_CFA_advance_loc2:
3302 case DW_CFA_advance_loc4:
3303 case DW_CFA_MIPS_advance_loc8:
3304 case DW_CFA_set_loc:
3305 /* All advances should be ignored. */
3307 case DW_CFA_remember_state:
3309 dw_cfi_ref args_size = cfi_args_size;
3311 /* Skip everything between .cfi_remember_state and
3312 .cfi_restore_state. */
3313 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3314 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3316 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3319 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3326 cfi_args_size = args_size;
3330 case DW_CFA_GNU_args_size:
3331 cfi_args_size = cfi;
3333 case DW_CFA_GNU_window_save:
3336 case DW_CFA_offset_extended:
3337 case DW_CFA_offset_extended_sf:
3338 case DW_CFA_restore:
3339 case DW_CFA_restore_extended:
3340 case DW_CFA_undefined:
3341 case DW_CFA_same_value:
3342 case DW_CFA_register:
3343 case DW_CFA_val_offset:
3344 case DW_CFA_val_offset_sf:
3345 case DW_CFA_expression:
3346 case DW_CFA_val_expression:
3347 case DW_CFA_GNU_negative_offset_extended:
3348 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3349 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3350 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3351 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3353 case DW_CFA_def_cfa:
3354 case DW_CFA_def_cfa_sf:
3355 case DW_CFA_def_cfa_expression:
3357 cfi_cfa_offset = cfi;
3359 case DW_CFA_def_cfa_register:
3362 case DW_CFA_def_cfa_offset:
3363 case DW_CFA_def_cfa_offset_sf:
3364 cfi_cfa_offset = cfi;
3367 gcc_assert (cfi == NULL);
3369 len = VEC_length (dw_cfi_ref, regs);
3370 for (idx = 0; idx < len; idx++)
3372 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3374 && cfi2->dw_cfi_opc != DW_CFA_restore
3375 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3378 output_cfi_directive (cfi2);
3380 output_cfi (cfi2, fde, for_eh);
3383 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3385 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3387 switch (cfi_cfa_offset->dw_cfi_opc)
3389 case DW_CFA_def_cfa_offset:
3390 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3391 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3393 case DW_CFA_def_cfa_offset_sf:
3394 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3395 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3397 case DW_CFA_def_cfa:
3398 case DW_CFA_def_cfa_sf:
3399 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3400 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3407 else if (cfi_cfa_offset)
3408 cfi_cfa = cfi_cfa_offset;
3412 output_cfi_directive (cfi_cfa);
3414 output_cfi (cfi_cfa, fde, for_eh);
3417 cfi_cfa_offset = NULL;
3419 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3422 output_cfi_directive (cfi_args_size);
3424 output_cfi (cfi_args_size, fde, for_eh);
3426 cfi_args_size = NULL;
3429 VEC_free (dw_cfi_ref, heap, regs);
3432 else if (do_cfi_asm)
3433 output_cfi_directive (cfi);
3435 output_cfi (cfi, fde, for_eh);
3442 /* Output one FDE. */
3445 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3446 char *section_start_label, int fde_encoding, char *augmentation,
3447 bool any_lsda_needed, int lsda_encoding)
3449 const char *begin, *end;
3450 static unsigned int j;
3451 char l1[20], l2[20];
3454 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh,
3456 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3458 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3459 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3460 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3461 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3462 " indicating 64-bit DWARF extension");
3463 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3465 ASM_OUTPUT_LABEL (asm_out_file, l1);
3468 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3470 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3471 debug_frame_section, "FDE CIE offset");
3473 if (!fde->dw_fde_switched_sections)
3475 begin = fde->dw_fde_begin;
3476 end = fde->dw_fde_end;
3480 /* For the first section, prefer dw_fde_begin over
3481 dw_fde_{hot,cold}_section_label, as the latter
3482 might be separated from the real start of the
3483 function by alignment padding. */
3485 begin = fde->dw_fde_begin;
3486 else if (fde->dw_fde_switched_cold_to_hot)
3487 begin = fde->dw_fde_hot_section_label;
3489 begin = fde->dw_fde_unlikely_section_label;
3490 if (second ^ fde->dw_fde_switched_cold_to_hot)
3491 end = fde->dw_fde_unlikely_section_end_label;
3493 end = fde->dw_fde_hot_section_end_label;
3498 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3499 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3500 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3501 "FDE initial location");
3502 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3503 end, begin, "FDE address range");
3507 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3508 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3511 if (augmentation[0])
3513 if (any_lsda_needed)
3515 int size = size_of_encoded_value (lsda_encoding);
3517 if (lsda_encoding == DW_EH_PE_aligned)
3519 int offset = ( 4 /* Length */
3520 + 4 /* CIE offset */
3521 + 2 * size_of_encoded_value (fde_encoding)
3522 + 1 /* Augmentation size */ );
3523 int pad = -offset & (PTR_SIZE - 1);
3526 gcc_assert (size_of_uleb128 (size) == 1);
3529 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3531 if (fde->uses_eh_lsda)
3533 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3534 fde->funcdef_number);
3535 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3536 gen_rtx_SYMBOL_REF (Pmode, l1),
3538 "Language Specific Data Area");
3542 if (lsda_encoding == DW_EH_PE_aligned)
3543 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3544 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3545 "Language Specific Data Area (none)");
3549 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3552 /* Loop through the Call Frame Instructions associated with
3554 fde->dw_fde_current_label = begin;
3555 if (!fde->dw_fde_switched_sections)
3556 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3557 output_cfi (cfi, fde, for_eh);
3560 if (fde->dw_fde_switch_cfi)