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"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
84 #include "diagnostic.h"
85 #include "tree-pretty-print.h"
88 #include "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 HOST_WIDE_INT stack_realignment;
309 unsigned funcdef_number;
310 /* Dynamic realign argument pointer register. */
311 unsigned int drap_reg;
312 /* Virtual dynamic realign argument pointer register. */
313 unsigned int vdrap_reg;
314 /* These 3 flags are copied from rtl_data in function.h. */
315 unsigned all_throwers_are_sibcalls : 1;
316 unsigned uses_eh_lsda : 1;
317 unsigned nothrow : 1;
318 /* Whether we did stack realign in this call frame. */
319 unsigned stack_realign : 1;
320 /* Whether dynamic realign argument pointer register has been saved. */
321 unsigned drap_reg_saved: 1;
322 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
323 unsigned in_std_section : 1;
324 /* True iff dw_fde_unlikely_section_label is in text_section or
325 cold_text_section. */
326 unsigned cold_in_std_section : 1;
327 /* True iff switched sections. */
328 unsigned dw_fde_switched_sections : 1;
329 /* True iff switching from cold to hot section. */
330 unsigned dw_fde_switched_cold_to_hot : 1;
334 /* Maximum size (in bytes) of an artificially generated label. */
335 #define MAX_ARTIFICIAL_LABEL_BYTES 30
337 /* The size of addresses as they appear in the Dwarf 2 data.
338 Some architectures use word addresses to refer to code locations,
339 but Dwarf 2 info always uses byte addresses. On such machines,
340 Dwarf 2 addresses need to be larger than the architecture's
342 #ifndef DWARF2_ADDR_SIZE
343 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
346 /* The size in bytes of a DWARF field indicating an offset or length
347 relative to a debug info section, specified to be 4 bytes in the
348 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
351 #ifndef DWARF_OFFSET_SIZE
352 #define DWARF_OFFSET_SIZE 4
355 /* The size in bytes of a DWARF 4 type signature. */
357 #ifndef DWARF_TYPE_SIGNATURE_SIZE
358 #define DWARF_TYPE_SIGNATURE_SIZE 8
361 /* According to the (draft) DWARF 3 specification, the initial length
362 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
363 bytes are 0xffffffff, followed by the length stored in the next 8
366 However, the SGI/MIPS ABI uses an initial length which is equal to
367 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
369 #ifndef DWARF_INITIAL_LENGTH_SIZE
370 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
373 /* Round SIZE up to the nearest BOUNDARY. */
374 #define DWARF_ROUND(SIZE,BOUNDARY) \
375 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
377 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
378 #ifndef DWARF_CIE_DATA_ALIGNMENT
379 #ifdef STACK_GROWS_DOWNWARD
380 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
382 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
386 /* CIE identifier. */
387 #if HOST_BITS_PER_WIDE_INT >= 64
388 #define DWARF_CIE_ID \
389 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
391 #define DWARF_CIE_ID DW_CIE_ID
394 /* A pointer to the base of a table that contains frame description
395 information for each routine. */
396 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
398 /* Number of elements currently allocated for fde_table. */
399 static GTY(()) unsigned fde_table_allocated;
401 /* Number of elements in fde_table currently in use. */
402 static GTY(()) unsigned fde_table_in_use;
404 /* Size (in elements) of increments by which we may expand the
406 #define FDE_TABLE_INCREMENT 256
408 /* Get the current fde_table entry we should use. */
410 static inline dw_fde_ref
413 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
416 /* A list of call frame insns for the CIE. */
417 static GTY(()) dw_cfi_ref cie_cfi_head;
419 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
420 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
421 attribute that accelerates the lookup of the FDE associated
422 with the subprogram. This variable holds the table index of the FDE
423 associated with the current function (body) definition. */
424 static unsigned current_funcdef_fde;
427 struct GTY(()) indirect_string_node {
429 unsigned int refcount;
430 enum dwarf_form form;
434 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
436 /* True if the compilation unit has location entries that reference
438 static GTY(()) bool debug_str_hash_forced = false;
440 static GTY(()) int dw2_string_counter;
441 static GTY(()) unsigned long dwarf2out_cfi_label_num;
443 /* True if the compilation unit places functions in more than one section. */
444 static GTY(()) bool have_multiple_function_sections = false;
446 /* Whether the default text and cold text sections have been used at all. */
448 static GTY(()) bool text_section_used = false;
449 static GTY(()) bool cold_text_section_used = false;
451 /* The default cold text section. */
452 static GTY(()) section *cold_text_section;
454 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
456 /* Forward declarations for functions defined in this file. */
458 static char *stripattributes (const char *);
459 static const char *dwarf_cfi_name (unsigned);
460 static dw_cfi_ref new_cfi (void);
461 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
462 static void add_fde_cfi (const char *, dw_cfi_ref);
463 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
464 static void lookup_cfa (dw_cfa_location *);
465 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
466 #ifdef DWARF2_UNWIND_INFO
467 static void initial_return_save (rtx);
469 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
471 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
472 static void output_cfi_directive (dw_cfi_ref);
473 static void output_call_frame_info (int);
474 static void dwarf2out_note_section_used (void);
475 static void flush_queued_reg_saves (void);
476 static bool clobbers_queued_reg_save (const_rtx);
477 static void dwarf2out_frame_debug_expr (rtx, const char *);
479 /* Support for complex CFA locations. */
480 static void output_cfa_loc (dw_cfi_ref);
481 static void output_cfa_loc_raw (dw_cfi_ref);
482 static void get_cfa_from_loc_descr (dw_cfa_location *,
483 struct dw_loc_descr_struct *);
484 static struct dw_loc_descr_struct *build_cfa_loc
485 (dw_cfa_location *, HOST_WIDE_INT);
486 static struct dw_loc_descr_struct *build_cfa_aligned_loc
487 (HOST_WIDE_INT, HOST_WIDE_INT);
488 static void def_cfa_1 (const char *, dw_cfa_location *);
490 /* How to start an assembler comment. */
491 #ifndef ASM_COMMENT_START
492 #define ASM_COMMENT_START ";#"
495 /* Data and reference forms for relocatable data. */
496 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
497 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
499 #ifndef DEBUG_FRAME_SECTION
500 #define DEBUG_FRAME_SECTION ".debug_frame"
503 #ifndef FUNC_BEGIN_LABEL
504 #define FUNC_BEGIN_LABEL "LFB"
507 #ifndef FUNC_END_LABEL
508 #define FUNC_END_LABEL "LFE"
511 #ifndef FRAME_BEGIN_LABEL
512 #define FRAME_BEGIN_LABEL "Lframe"
514 #define CIE_AFTER_SIZE_LABEL "LSCIE"
515 #define CIE_END_LABEL "LECIE"
516 #define FDE_LABEL "LSFDE"
517 #define FDE_AFTER_SIZE_LABEL "LASFDE"
518 #define FDE_END_LABEL "LEFDE"
519 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
520 #define LINE_NUMBER_END_LABEL "LELT"
521 #define LN_PROLOG_AS_LABEL "LASLTP"
522 #define LN_PROLOG_END_LABEL "LELTP"
523 #define DIE_LABEL_PREFIX "DW"
525 /* The DWARF 2 CFA column which tracks the return address. Normally this
526 is the column for PC, or the first column after all of the hard
528 #ifndef DWARF_FRAME_RETURN_COLUMN
530 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
532 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
536 /* The mapping from gcc register number to DWARF 2 CFA column number. By
537 default, we just provide columns for all registers. */
538 #ifndef DWARF_FRAME_REGNUM
539 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
542 /* Hook used by __throw. */
545 expand_builtin_dwarf_sp_column (void)
547 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
548 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
551 /* Return a pointer to a copy of the section string name S with all
552 attributes stripped off, and an asterisk prepended (for assemble_name). */
555 stripattributes (const char *s)
557 char *stripped = XNEWVEC (char, strlen (s) + 2);
562 while (*s && *s != ',')
569 /* MEM is a memory reference for the register size table, each element of
570 which has mode MODE. Initialize column C as a return address column. */
573 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
575 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
576 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
577 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
580 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
582 static inline HOST_WIDE_INT
583 div_data_align (HOST_WIDE_INT off)
585 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
586 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
590 /* Return true if we need a signed version of a given opcode
591 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
594 need_data_align_sf_opcode (HOST_WIDE_INT off)
596 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
599 /* Generate code to initialize the register size table. */
602 expand_builtin_init_dwarf_reg_sizes (tree address)
605 enum machine_mode mode = TYPE_MODE (char_type_node);
606 rtx addr = expand_normal (address);
607 rtx mem = gen_rtx_MEM (BLKmode, addr);
608 bool wrote_return_column = false;
610 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
612 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
614 if (rnum < DWARF_FRAME_REGISTERS)
616 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
617 enum machine_mode save_mode = reg_raw_mode[i];
620 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
621 save_mode = choose_hard_reg_mode (i, 1, true);
622 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
624 if (save_mode == VOIDmode)
626 wrote_return_column = true;
628 size = GET_MODE_SIZE (save_mode);
632 emit_move_insn (adjust_address (mem, mode, offset),
633 gen_int_mode (size, mode));
637 if (!wrote_return_column)
638 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
640 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
641 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
644 targetm.init_dwarf_reg_sizes_extra (address);
647 /* Convert a DWARF call frame info. operation to its string name */
650 dwarf_cfi_name (unsigned int cfi_opc)
654 case DW_CFA_advance_loc:
655 return "DW_CFA_advance_loc";
657 return "DW_CFA_offset";
659 return "DW_CFA_restore";
663 return "DW_CFA_set_loc";
664 case DW_CFA_advance_loc1:
665 return "DW_CFA_advance_loc1";
666 case DW_CFA_advance_loc2:
667 return "DW_CFA_advance_loc2";
668 case DW_CFA_advance_loc4:
669 return "DW_CFA_advance_loc4";
670 case DW_CFA_offset_extended:
671 return "DW_CFA_offset_extended";
672 case DW_CFA_restore_extended:
673 return "DW_CFA_restore_extended";
674 case DW_CFA_undefined:
675 return "DW_CFA_undefined";
676 case DW_CFA_same_value:
677 return "DW_CFA_same_value";
678 case DW_CFA_register:
679 return "DW_CFA_register";
680 case DW_CFA_remember_state:
681 return "DW_CFA_remember_state";
682 case DW_CFA_restore_state:
683 return "DW_CFA_restore_state";
685 return "DW_CFA_def_cfa";
686 case DW_CFA_def_cfa_register:
687 return "DW_CFA_def_cfa_register";
688 case DW_CFA_def_cfa_offset:
689 return "DW_CFA_def_cfa_offset";
692 case DW_CFA_def_cfa_expression:
693 return "DW_CFA_def_cfa_expression";
694 case DW_CFA_expression:
695 return "DW_CFA_expression";
696 case DW_CFA_offset_extended_sf:
697 return "DW_CFA_offset_extended_sf";
698 case DW_CFA_def_cfa_sf:
699 return "DW_CFA_def_cfa_sf";
700 case DW_CFA_def_cfa_offset_sf:
701 return "DW_CFA_def_cfa_offset_sf";
703 /* SGI/MIPS specific */
704 case DW_CFA_MIPS_advance_loc8:
705 return "DW_CFA_MIPS_advance_loc8";
708 case DW_CFA_GNU_window_save:
709 return "DW_CFA_GNU_window_save";
710 case DW_CFA_GNU_args_size:
711 return "DW_CFA_GNU_args_size";
712 case DW_CFA_GNU_negative_offset_extended:
713 return "DW_CFA_GNU_negative_offset_extended";
716 return "DW_CFA_<unknown>";
720 /* Return a pointer to a newly allocated Call Frame Instruction. */
722 static inline dw_cfi_ref
725 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
727 cfi->dw_cfi_next = NULL;
728 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
729 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
734 /* Add a Call Frame Instruction to list of instructions. */
737 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
740 dw_fde_ref fde = current_fde ();
742 /* When DRAP is used, CFA is defined with an expression. Redefine
743 CFA may lead to a different CFA value. */
744 /* ??? Of course, this heuristic fails when we're annotating epilogues,
745 because of course we'll always want to redefine the CFA back to the
746 stack pointer on the way out. Where should we move this check? */
747 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
748 switch (cfi->dw_cfi_opc)
750 case DW_CFA_def_cfa_register:
751 case DW_CFA_def_cfa_offset:
752 case DW_CFA_def_cfa_offset_sf:
754 case DW_CFA_def_cfa_sf:
761 /* Find the end of the chain. */
762 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
768 /* Generate a new label for the CFI info to refer to. FORCE is true
769 if a label needs to be output even when using .cfi_* directives. */
772 dwarf2out_cfi_label (bool force)
774 static char label[20];
776 if (!force && dwarf2out_do_cfi_asm ())
778 /* In this case, we will be emitting the asm directive instead of
779 the label, so just return a placeholder to keep the rest of the
781 strcpy (label, "<do not output>");
785 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
786 ASM_OUTPUT_LABEL (asm_out_file, label);
792 /* True if remember_state should be emitted before following CFI directive. */
793 static bool emit_cfa_remember;
795 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
796 or to the CIE if LABEL is NULL. */
799 add_fde_cfi (const char *label, dw_cfi_ref cfi)
801 dw_cfi_ref *list_head;
803 if (emit_cfa_remember)
805 dw_cfi_ref cfi_remember;
807 /* Emit the state save. */
808 emit_cfa_remember = false;
809 cfi_remember = new_cfi ();
810 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
811 add_fde_cfi (label, cfi_remember);
814 list_head = &cie_cfi_head;
816 if (dwarf2out_do_cfi_asm ())
820 dw_fde_ref fde = current_fde ();
822 gcc_assert (fde != NULL);
824 /* We still have to add the cfi to the list so that lookup_cfa
825 works later on. When -g2 and above we even need to force
826 emitting of CFI labels and add to list a DW_CFA_set_loc for
827 convert_cfa_to_fb_loc_list purposes. If we're generating
828 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
829 convert_cfa_to_fb_loc_list. */
830 if (dwarf_version == 2
831 && debug_info_level > DINFO_LEVEL_TERSE
832 && (write_symbols == DWARF2_DEBUG
833 || write_symbols == VMS_AND_DWARF2_DEBUG))
835 switch (cfi->dw_cfi_opc)
837 case DW_CFA_def_cfa_offset:
838 case DW_CFA_def_cfa_offset_sf:
839 case DW_CFA_def_cfa_register:
841 case DW_CFA_def_cfa_sf:
842 case DW_CFA_def_cfa_expression:
843 case DW_CFA_restore_state:
844 if (*label == 0 || strcmp (label, "<do not output>") == 0)
845 label = dwarf2out_cfi_label (true);
847 if (fde->dw_fde_current_label == NULL
848 || strcmp (label, fde->dw_fde_current_label) != 0)
852 label = xstrdup (label);
854 /* Set the location counter to the new label. */
856 /* It doesn't metter whether DW_CFA_set_loc
857 or DW_CFA_advance_loc4 is added here, those aren't
858 emitted into assembly, only looked up by
859 convert_cfa_to_fb_loc_list. */
860 xcfi->dw_cfi_opc = DW_CFA_set_loc;
861 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
862 add_cfi (&fde->dw_fde_cfi, xcfi);
863 fde->dw_fde_current_label = label;
871 output_cfi_directive (cfi);
873 list_head = &fde->dw_fde_cfi;
875 /* ??? If this is a CFI for the CIE, we don't emit. This
876 assumes that the standard CIE contents that the assembler
877 uses matches the standard CIE contents that the compiler
878 uses. This is probably a bad assumption. I'm not quite
879 sure how to address this for now. */
883 dw_fde_ref fde = current_fde ();
885 gcc_assert (fde != NULL);
888 label = dwarf2out_cfi_label (false);
890 if (fde->dw_fde_current_label == NULL
891 || strcmp (label, fde->dw_fde_current_label) != 0)
895 label = xstrdup (label);
897 /* Set the location counter to the new label. */
899 /* If we have a current label, advance from there, otherwise
900 set the location directly using set_loc. */
901 xcfi->dw_cfi_opc = fde->dw_fde_current_label
902 ? DW_CFA_advance_loc4
904 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
905 add_cfi (&fde->dw_fde_cfi, xcfi);
907 fde->dw_fde_current_label = label;
910 list_head = &fde->dw_fde_cfi;
913 add_cfi (list_head, cfi);
916 /* Subroutine of lookup_cfa. */
919 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
921 switch (cfi->dw_cfi_opc)
923 case DW_CFA_def_cfa_offset:
924 case DW_CFA_def_cfa_offset_sf:
925 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
927 case DW_CFA_def_cfa_register:
928 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
931 case DW_CFA_def_cfa_sf:
932 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
933 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
935 case DW_CFA_def_cfa_expression:
936 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
939 case DW_CFA_remember_state:
940 gcc_assert (!remember->in_use);
942 remember->in_use = 1;
944 case DW_CFA_restore_state:
945 gcc_assert (remember->in_use);
947 remember->in_use = 0;
955 /* Find the previous value for the CFA. */
958 lookup_cfa (dw_cfa_location *loc)
962 dw_cfa_location remember;
964 memset (loc, 0, sizeof (*loc));
965 loc->reg = INVALID_REGNUM;
968 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
969 lookup_cfa_1 (cfi, loc, &remember);
971 fde = current_fde ();
973 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
974 lookup_cfa_1 (cfi, loc, &remember);
977 /* The current rule for calculating the DWARF2 canonical frame address. */
978 static dw_cfa_location cfa;
980 /* The register used for saving registers to the stack, and its offset
982 static dw_cfa_location cfa_store;
984 /* The current save location around an epilogue. */
985 static dw_cfa_location cfa_remember;
987 /* The running total of the size of arguments pushed onto the stack. */
988 static HOST_WIDE_INT args_size;
990 /* The last args_size we actually output. */
991 static HOST_WIDE_INT old_args_size;
993 /* Entry point to update the canonical frame address (CFA).
994 LABEL is passed to add_fde_cfi. The value of CFA is now to be
995 calculated from REG+OFFSET. */
998 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1000 dw_cfa_location loc;
1002 loc.base_offset = 0;
1004 loc.offset = offset;
1005 def_cfa_1 (label, &loc);
1008 /* Determine if two dw_cfa_location structures define the same data. */
1011 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1013 return (loc1->reg == loc2->reg
1014 && loc1->offset == loc2->offset
1015 && loc1->indirect == loc2->indirect
1016 && (loc1->indirect == 0
1017 || loc1->base_offset == loc2->base_offset));
1020 /* This routine does the actual work. The CFA is now calculated from
1021 the dw_cfa_location structure. */
1024 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1027 dw_cfa_location old_cfa, loc;
1032 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1033 cfa_store.offset = loc.offset;
1035 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1036 lookup_cfa (&old_cfa);
1038 /* If nothing changed, no need to issue any call frame instructions. */
1039 if (cfa_equal_p (&loc, &old_cfa))
1044 if (loc.reg == old_cfa.reg && !loc.indirect && !old_cfa.indirect)
1046 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1047 the CFA register did not change but the offset did. The data
1048 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1049 in the assembler via the .cfi_def_cfa_offset directive. */
1051 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1053 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1054 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1057 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1058 else if (loc.offset == old_cfa.offset
1059 && old_cfa.reg != INVALID_REGNUM
1061 && !old_cfa.indirect)
1063 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1064 indicating the CFA register has changed to <register> but the
1065 offset has not changed. */
1066 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1067 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1071 else if (loc.indirect == 0)
1073 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1074 indicating the CFA register has changed to <register> with
1075 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1076 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1079 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1081 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1082 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1083 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1087 /* Construct a DW_CFA_def_cfa_expression instruction to
1088 calculate the CFA using a full location expression since no
1089 register-offset pair is available. */
1090 struct dw_loc_descr_struct *loc_list;
1092 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1093 loc_list = build_cfa_loc (&loc, 0);
1094 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1097 add_fde_cfi (label, cfi);
1100 /* Add the CFI for saving a register. REG is the CFA column number.
1101 LABEL is passed to add_fde_cfi.
1102 If SREG is -1, the register is saved at OFFSET from the CFA;
1103 otherwise it is saved in SREG. */
1106 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1108 dw_cfi_ref cfi = new_cfi ();
1109 dw_fde_ref fde = current_fde ();
1111 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1113 /* When stack is aligned, store REG using DW_CFA_expression with
1116 && fde->stack_realign
1117 && sreg == INVALID_REGNUM)
1119 cfi->dw_cfi_opc = DW_CFA_expression;
1120 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1121 cfi->dw_cfi_oprnd2.dw_cfi_loc
1122 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1124 else if (sreg == INVALID_REGNUM)
1126 if (need_data_align_sf_opcode (offset))
1127 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1128 else if (reg & ~0x3f)
1129 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1131 cfi->dw_cfi_opc = DW_CFA_offset;
1132 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1134 else if (sreg == reg)
1135 cfi->dw_cfi_opc = DW_CFA_same_value;
1138 cfi->dw_cfi_opc = DW_CFA_register;
1139 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1142 add_fde_cfi (label, cfi);
1145 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1146 This CFI tells the unwinder that it needs to restore the window registers
1147 from the previous frame's window save area.
1149 ??? Perhaps we should note in the CIE where windows are saved (instead of
1150 assuming 0(cfa)) and what registers are in the window. */
1153 dwarf2out_window_save (const char *label)
1155 dw_cfi_ref cfi = new_cfi ();
1157 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1158 add_fde_cfi (label, cfi);
1161 /* Entry point for saving a register to the stack. REG is the GCC register
1162 number. LABEL and OFFSET are passed to reg_save. */
1165 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1167 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1170 /* Entry point for saving the return address in the stack.
1171 LABEL and OFFSET are passed to reg_save. */
1174 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1176 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1179 /* Entry point for saving the return address in a register.
1180 LABEL and SREG are passed to reg_save. */
1183 dwarf2out_return_reg (const char *label, unsigned int sreg)
1185 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1188 #ifdef DWARF2_UNWIND_INFO
1189 /* Record the initial position of the return address. RTL is
1190 INCOMING_RETURN_ADDR_RTX. */
1193 initial_return_save (rtx rtl)
1195 unsigned int reg = INVALID_REGNUM;
1196 HOST_WIDE_INT offset = 0;
1198 switch (GET_CODE (rtl))
1201 /* RA is in a register. */
1202 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1206 /* RA is on the stack. */
1207 rtl = XEXP (rtl, 0);
1208 switch (GET_CODE (rtl))
1211 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1216 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1217 offset = INTVAL (XEXP (rtl, 1));
1221 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1222 offset = -INTVAL (XEXP (rtl, 1));
1232 /* The return address is at some offset from any value we can
1233 actually load. For instance, on the SPARC it is in %i7+8. Just
1234 ignore the offset for now; it doesn't matter for unwinding frames. */
1235 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1236 initial_return_save (XEXP (rtl, 0));
1243 if (reg != DWARF_FRAME_RETURN_COLUMN)
1244 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1248 /* Given a SET, calculate the amount of stack adjustment it
1251 static HOST_WIDE_INT
1252 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1253 HOST_WIDE_INT cur_offset)
1255 const_rtx src = SET_SRC (pattern);
1256 const_rtx dest = SET_DEST (pattern);
1257 HOST_WIDE_INT offset = 0;
1260 if (dest == stack_pointer_rtx)
1262 code = GET_CODE (src);
1264 /* Assume (set (reg sp) (reg whatever)) sets args_size
1266 if (code == REG && src != stack_pointer_rtx)
1268 offset = -cur_args_size;
1269 #ifndef STACK_GROWS_DOWNWARD
1272 return offset - cur_offset;
1275 if (! (code == PLUS || code == MINUS)
1276 || XEXP (src, 0) != stack_pointer_rtx
1277 || !CONST_INT_P (XEXP (src, 1)))
1280 /* (set (reg sp) (plus (reg sp) (const_int))) */
1281 offset = INTVAL (XEXP (src, 1));
1287 if (MEM_P (src) && !MEM_P (dest))
1291 /* (set (mem (pre_dec (reg sp))) (foo)) */
1292 src = XEXP (dest, 0);
1293 code = GET_CODE (src);
1299 if (XEXP (src, 0) == stack_pointer_rtx)
1301 rtx val = XEXP (XEXP (src, 1), 1);
1302 /* We handle only adjustments by constant amount. */
1303 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1304 && CONST_INT_P (val));
1305 offset = -INTVAL (val);
1312 if (XEXP (src, 0) == stack_pointer_rtx)
1314 offset = GET_MODE_SIZE (GET_MODE (dest));
1321 if (XEXP (src, 0) == stack_pointer_rtx)
1323 offset = -GET_MODE_SIZE (GET_MODE (dest));
1338 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1339 indexed by INSN_UID. */
1341 static HOST_WIDE_INT *barrier_args_size;
1343 /* Helper function for compute_barrier_args_size. Handle one insn. */
1345 static HOST_WIDE_INT
1346 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1347 VEC (rtx, heap) **next)
1349 HOST_WIDE_INT offset = 0;
1352 if (! RTX_FRAME_RELATED_P (insn))
1354 if (prologue_epilogue_contains (insn))
1356 else if (GET_CODE (PATTERN (insn)) == SET)
1357 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1358 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1359 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1361 /* There may be stack adjustments inside compound insns. Search
1363 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1364 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1365 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1366 cur_args_size, offset);
1371 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1375 expr = XEXP (expr, 0);
1376 if (GET_CODE (expr) == PARALLEL
1377 || GET_CODE (expr) == SEQUENCE)
1378 for (i = 1; i < XVECLEN (expr, 0); i++)
1380 rtx elem = XVECEXP (expr, 0, i);
1382 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1383 offset += stack_adjust_offset (elem, cur_args_size, offset);
1388 #ifndef STACK_GROWS_DOWNWARD
1392 cur_args_size += offset;
1393 if (cur_args_size < 0)
1398 rtx dest = JUMP_LABEL (insn);
1402 if (barrier_args_size [INSN_UID (dest)] < 0)
1404 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1405 VEC_safe_push (rtx, heap, *next, dest);
1410 return cur_args_size;
1413 /* Walk the whole function and compute args_size on BARRIERs. */
1416 compute_barrier_args_size (void)
1418 int max_uid = get_max_uid (), i;
1420 VEC (rtx, heap) *worklist, *next, *tmp;
1422 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1423 for (i = 0; i < max_uid; i++)
1424 barrier_args_size[i] = -1;
1426 worklist = VEC_alloc (rtx, heap, 20);
1427 next = VEC_alloc (rtx, heap, 20);
1428 insn = get_insns ();
1429 barrier_args_size[INSN_UID (insn)] = 0;
1430 VEC_quick_push (rtx, worklist, insn);
1433 while (!VEC_empty (rtx, worklist))
1435 rtx prev, body, first_insn;
1436 HOST_WIDE_INT cur_args_size;
1438 first_insn = insn = VEC_pop (rtx, worklist);
1439 cur_args_size = barrier_args_size[INSN_UID (insn)];
1440 prev = prev_nonnote_insn (insn);
1441 if (prev && BARRIER_P (prev))
1442 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1444 for (; insn; insn = NEXT_INSN (insn))
1446 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1448 if (BARRIER_P (insn))
1453 if (insn == first_insn)
1455 else if (barrier_args_size[INSN_UID (insn)] < 0)
1457 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1462 /* The insns starting with this label have been
1463 already scanned or are in the worklist. */
1468 body = PATTERN (insn);
1469 if (GET_CODE (body) == SEQUENCE)
1471 HOST_WIDE_INT dest_args_size = cur_args_size;
1472 for (i = 1; i < XVECLEN (body, 0); i++)
1473 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1474 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1476 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1477 dest_args_size, &next);
1480 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1481 cur_args_size, &next);
1483 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1484 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1485 dest_args_size, &next);
1488 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1489 cur_args_size, &next);
1493 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1497 if (VEC_empty (rtx, next))
1500 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1504 VEC_truncate (rtx, next, 0);
1507 VEC_free (rtx, heap, worklist);
1508 VEC_free (rtx, heap, next);
1511 /* Add a CFI to update the running total of the size of arguments
1512 pushed onto the stack. */
1515 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1519 if (size == old_args_size)
1522 old_args_size = size;
1525 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1526 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1527 add_fde_cfi (label, cfi);
1530 /* Record a stack adjustment of OFFSET bytes. */
1533 dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
1535 if (cfa.reg == STACK_POINTER_REGNUM)
1536 cfa.offset += offset;
1538 if (cfa_store.reg == STACK_POINTER_REGNUM)
1539 cfa_store.offset += offset;
1541 if (ACCUMULATE_OUTGOING_ARGS)
1544 #ifndef STACK_GROWS_DOWNWARD
1548 args_size += offset;
1552 def_cfa_1 (label, &cfa);
1553 if (flag_asynchronous_unwind_tables)
1554 dwarf2out_args_size (label, args_size);
1557 /* Check INSN to see if it looks like a push or a stack adjustment, and
1558 make a note of it if it does. EH uses this information to find out
1559 how much extra space it needs to pop off the stack. */
1562 dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
1564 HOST_WIDE_INT offset;
1568 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1569 with this function. Proper support would require all frame-related
1570 insns to be marked, and to be able to handle saving state around
1571 epilogues textually in the middle of the function. */
1572 if (prologue_epilogue_contains (insn))
1575 /* If INSN is an instruction from target of an annulled branch, the
1576 effects are for the target only and so current argument size
1577 shouldn't change at all. */
1579 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1580 && INSN_FROM_TARGET_P (insn))
1583 /* If only calls can throw, and we have a frame pointer,
1584 save up adjustments until we see the CALL_INSN. */
1585 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1587 if (CALL_P (insn) && !after_p)
1589 /* Extract the size of the args from the CALL rtx itself. */
1590 insn = PATTERN (insn);
1591 if (GET_CODE (insn) == PARALLEL)
1592 insn = XVECEXP (insn, 0, 0);
1593 if (GET_CODE (insn) == SET)
1594 insn = SET_SRC (insn);
1595 gcc_assert (GET_CODE (insn) == CALL);
1596 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1601 if (CALL_P (insn) && !after_p)
1603 if (!flag_asynchronous_unwind_tables)
1604 dwarf2out_args_size ("", args_size);
1607 else if (BARRIER_P (insn))
1609 /* Don't call compute_barrier_args_size () if the only
1610 BARRIER is at the end of function. */
1611 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1612 compute_barrier_args_size ();
1613 if (barrier_args_size == NULL)
1617 offset = barrier_args_size[INSN_UID (insn)];
1622 offset -= args_size;
1623 #ifndef STACK_GROWS_DOWNWARD
1627 else if (GET_CODE (PATTERN (insn)) == SET)
1628 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1629 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1630 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1632 /* There may be stack adjustments inside compound insns. Search
1634 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1635 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1636 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1645 label = dwarf2out_cfi_label (false);
1646 dwarf2out_stack_adjust (offset, label);
1651 /* We delay emitting a register save until either (a) we reach the end
1652 of the prologue or (b) the register is clobbered. This clusters
1653 register saves so that there are fewer pc advances. */
1655 struct GTY(()) queued_reg_save {
1656 struct queued_reg_save *next;
1658 HOST_WIDE_INT cfa_offset;
1662 static GTY(()) struct queued_reg_save *queued_reg_saves;
1664 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1665 struct GTY(()) reg_saved_in_data {
1670 /* A list of registers saved in other registers.
1671 The list intentionally has a small maximum capacity of 4; if your
1672 port needs more than that, you might consider implementing a
1673 more efficient data structure. */
1674 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1675 static GTY(()) size_t num_regs_saved_in_regs;
1677 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1678 static const char *last_reg_save_label;
1680 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1681 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1684 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1686 struct queued_reg_save *q;
1688 /* Duplicates waste space, but it's also necessary to remove them
1689 for correctness, since the queue gets output in reverse
1691 for (q = queued_reg_saves; q != NULL; q = q->next)
1692 if (REGNO (q->reg) == REGNO (reg))
1697 q = GGC_NEW (struct queued_reg_save);
1698 q->next = queued_reg_saves;
1699 queued_reg_saves = q;
1703 q->cfa_offset = offset;
1704 q->saved_reg = sreg;
1706 last_reg_save_label = label;
1709 /* Output all the entries in QUEUED_REG_SAVES. */
1712 flush_queued_reg_saves (void)
1714 struct queued_reg_save *q;
1716 for (q = queued_reg_saves; q; q = q->next)
1719 unsigned int reg, sreg;
1721 for (i = 0; i < num_regs_saved_in_regs; i++)
1722 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1724 if (q->saved_reg && i == num_regs_saved_in_regs)
1726 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1727 num_regs_saved_in_regs++;
1729 if (i != num_regs_saved_in_regs)
1731 regs_saved_in_regs[i].orig_reg = q->reg;
1732 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1735 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1737 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1739 sreg = INVALID_REGNUM;
1740 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1743 queued_reg_saves = NULL;
1744 last_reg_save_label = NULL;
1747 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1748 location for? Or, does it clobber a register which we've previously
1749 said that some other register is saved in, and for which we now
1750 have a new location for? */
1753 clobbers_queued_reg_save (const_rtx insn)
1755 struct queued_reg_save *q;
1757 for (q = queued_reg_saves; q; q = q->next)
1760 if (modified_in_p (q->reg, insn))
1762 for (i = 0; i < num_regs_saved_in_regs; i++)
1763 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1764 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1771 /* Entry point for saving the first register into the second. */
1774 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1777 unsigned int regno, sregno;
1779 for (i = 0; i < num_regs_saved_in_regs; i++)
1780 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1782 if (i == num_regs_saved_in_regs)
1784 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1785 num_regs_saved_in_regs++;
1787 regs_saved_in_regs[i].orig_reg = reg;
1788 regs_saved_in_regs[i].saved_in_reg = sreg;
1790 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1791 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1792 reg_save (label, regno, sregno, 0);
1795 /* What register, if any, is currently saved in REG? */
1798 reg_saved_in (rtx reg)
1800 unsigned int regn = REGNO (reg);
1802 struct queued_reg_save *q;
1804 for (q = queued_reg_saves; q; q = q->next)
1805 if (q->saved_reg && regn == REGNO (q->saved_reg))
1808 for (i = 0; i < num_regs_saved_in_regs; i++)
1809 if (regs_saved_in_regs[i].saved_in_reg
1810 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1811 return regs_saved_in_regs[i].orig_reg;
1817 /* A temporary register holding an integral value used in adjusting SP
1818 or setting up the store_reg. The "offset" field holds the integer
1819 value, not an offset. */
1820 static dw_cfa_location cfa_temp;
1822 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1825 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1827 memset (&cfa, 0, sizeof (cfa));
1829 switch (GET_CODE (pat))
1832 cfa.reg = REGNO (XEXP (pat, 0));
1833 cfa.offset = INTVAL (XEXP (pat, 1));
1837 cfa.reg = REGNO (pat);
1841 /* Recurse and define an expression. */
1845 def_cfa_1 (label, &cfa);
1848 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1851 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1855 gcc_assert (GET_CODE (pat) == SET);
1856 dest = XEXP (pat, 0);
1857 src = XEXP (pat, 1);
1859 switch (GET_CODE (src))
1862 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1863 cfa.offset -= INTVAL (XEXP (src, 1));
1873 cfa.reg = REGNO (dest);
1874 gcc_assert (cfa.indirect == 0);
1876 def_cfa_1 (label, &cfa);
1879 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1882 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1884 HOST_WIDE_INT offset;
1885 rtx src, addr, span;
1887 src = XEXP (set, 1);
1888 addr = XEXP (set, 0);
1889 gcc_assert (MEM_P (addr));
1890 addr = XEXP (addr, 0);
1892 /* As documented, only consider extremely simple addresses. */
1893 switch (GET_CODE (addr))
1896 gcc_assert (REGNO (addr) == cfa.reg);
1897 offset = -cfa.offset;
1900 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1901 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1907 span = targetm.dwarf_register_span (src);
1909 /* ??? We'd like to use queue_reg_save, but we need to come up with
1910 a different flushing heuristic for epilogues. */
1912 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
1915 /* We have a PARALLEL describing where the contents of SRC live.
1916 Queue register saves for each piece of the PARALLEL. */
1919 HOST_WIDE_INT span_offset = offset;
1921 gcc_assert (GET_CODE (span) == PARALLEL);
1923 limit = XVECLEN (span, 0);
1924 for (par_index = 0; par_index < limit; par_index++)
1926 rtx elem = XVECEXP (span, 0, par_index);
1928 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
1929 INVALID_REGNUM, span_offset);
1930 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1935 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1938 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
1941 unsigned sregno, dregno;
1943 src = XEXP (set, 1);
1944 dest = XEXP (set, 0);
1947 sregno = DWARF_FRAME_RETURN_COLUMN;
1949 sregno = DWARF_FRAME_REGNUM (REGNO (src));
1951 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
1953 /* ??? We'd like to use queue_reg_save, but we need to come up with
1954 a different flushing heuristic for epilogues. */
1955 reg_save (label, sregno, dregno, 0);
1958 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1961 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
1963 dw_cfi_ref cfi = new_cfi ();
1964 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
1966 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
1967 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
1969 add_fde_cfi (label, cfi);
1972 /* Record call frame debugging information for an expression EXPR,
1973 which either sets SP or FP (adjusting how we calculate the frame
1974 address) or saves a register to the stack or another register.
1975 LABEL indicates the address of EXPR.
1977 This function encodes a state machine mapping rtxes to actions on
1978 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1979 users need not read the source code.
1981 The High-Level Picture
1983 Changes in the register we use to calculate the CFA: Currently we
1984 assume that if you copy the CFA register into another register, we
1985 should take the other one as the new CFA register; this seems to
1986 work pretty well. If it's wrong for some target, it's simple
1987 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1989 Changes in the register we use for saving registers to the stack:
1990 This is usually SP, but not always. Again, we deduce that if you
1991 copy SP into another register (and SP is not the CFA register),
1992 then the new register is the one we will be using for register
1993 saves. This also seems to work.
1995 Register saves: There's not much guesswork about this one; if
1996 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1997 register save, and the register used to calculate the destination
1998 had better be the one we think we're using for this purpose.
1999 It's also assumed that a copy from a call-saved register to another
2000 register is saving that register if RTX_FRAME_RELATED_P is set on
2001 that instruction. If the copy is from a call-saved register to
2002 the *same* register, that means that the register is now the same
2003 value as in the caller.
2005 Except: If the register being saved is the CFA register, and the
2006 offset is nonzero, we are saving the CFA, so we assume we have to
2007 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2008 the intent is to save the value of SP from the previous frame.
2010 In addition, if a register has previously been saved to a different
2013 Invariants / Summaries of Rules
2015 cfa current rule for calculating the CFA. It usually
2016 consists of a register and an offset.
2017 cfa_store register used by prologue code to save things to the stack
2018 cfa_store.offset is the offset from the value of
2019 cfa_store.reg to the actual CFA
2020 cfa_temp register holding an integral value. cfa_temp.offset
2021 stores the value, which will be used to adjust the
2022 stack pointer. cfa_temp is also used like cfa_store,
2023 to track stores to the stack via fp or a temp reg.
2025 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2026 with cfa.reg as the first operand changes the cfa.reg and its
2027 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2030 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2031 expression yielding a constant. This sets cfa_temp.reg
2032 and cfa_temp.offset.
2034 Rule 5: Create a new register cfa_store used to save items to the
2037 Rules 10-14: Save a register to the stack. Define offset as the
2038 difference of the original location and cfa_store's
2039 location (or cfa_temp's location if cfa_temp is used).
2041 Rules 16-20: If AND operation happens on sp in prologue, we assume
2042 stack is realigned. We will use a group of DW_OP_XXX
2043 expressions to represent the location of the stored
2044 register instead of CFA+offset.
2048 "{a,b}" indicates a choice of a xor b.
2049 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2052 (set <reg1> <reg2>:cfa.reg)
2053 effects: cfa.reg = <reg1>
2054 cfa.offset unchanged
2055 cfa_temp.reg = <reg1>
2056 cfa_temp.offset = cfa.offset
2059 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2060 {<const_int>,<reg>:cfa_temp.reg}))
2061 effects: cfa.reg = sp if fp used
2062 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2063 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2064 if cfa_store.reg==sp
2067 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2068 effects: cfa.reg = fp
2069 cfa_offset += +/- <const_int>
2072 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2073 constraints: <reg1> != fp
2075 effects: cfa.reg = <reg1>
2076 cfa_temp.reg = <reg1>
2077 cfa_temp.offset = cfa.offset
2080 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2081 constraints: <reg1> != fp
2083 effects: cfa_store.reg = <reg1>
2084 cfa_store.offset = cfa.offset - cfa_temp.offset
2087 (set <reg> <const_int>)
2088 effects: cfa_temp.reg = <reg>
2089 cfa_temp.offset = <const_int>
2092 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2093 effects: cfa_temp.reg = <reg1>
2094 cfa_temp.offset |= <const_int>
2097 (set <reg> (high <exp>))
2101 (set <reg> (lo_sum <exp> <const_int>))
2102 effects: cfa_temp.reg = <reg>
2103 cfa_temp.offset = <const_int>
2106 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2107 effects: cfa_store.offset -= <const_int>
2108 cfa.offset = cfa_store.offset if cfa.reg == sp
2110 cfa.base_offset = -cfa_store.offset
2113 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2114 effects: cfa_store.offset += -/+ mode_size(mem)
2115 cfa.offset = cfa_store.offset if cfa.reg == sp
2117 cfa.base_offset = -cfa_store.offset
2120 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2123 effects: cfa.reg = <reg1>
2124 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2127 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2128 effects: cfa.reg = <reg1>
2129 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2132 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2133 effects: cfa.reg = <reg1>
2134 cfa.base_offset = -cfa_temp.offset
2135 cfa_temp.offset -= mode_size(mem)
2138 (set <reg> {unspec, unspec_volatile})
2139 effects: target-dependent
2142 (set sp (and: sp <const_int>))
2143 constraints: cfa_store.reg == sp
2144 effects: current_fde.stack_realign = 1
2145 cfa_store.offset = 0
2146 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2149 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2150 effects: cfa_store.offset += -/+ mode_size(mem)
2153 (set (mem ({pre_inc, pre_dec} sp)) fp)
2154 constraints: fde->stack_realign == 1
2155 effects: cfa_store.offset = 0
2156 cfa.reg != HARD_FRAME_POINTER_REGNUM
2159 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2160 constraints: fde->stack_realign == 1
2162 && cfa.indirect == 0
2163 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2164 effects: Use DW_CFA_def_cfa_expression to define cfa
2165 cfa.reg == fde->drap_reg */
2168 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2170 rtx src, dest, span;
2171 HOST_WIDE_INT offset;
2174 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2175 the PARALLEL independently. The first element is always processed if
2176 it is a SET. This is for backward compatibility. Other elements
2177 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2178 flag is set in them. */
2179 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2182 int limit = XVECLEN (expr, 0);
2185 /* PARALLELs have strict read-modify-write semantics, so we
2186 ought to evaluate every rvalue before changing any lvalue.
2187 It's cumbersome to do that in general, but there's an
2188 easy approximation that is enough for all current users:
2189 handle register saves before register assignments. */
2190 if (GET_CODE (expr) == PARALLEL)
2191 for (par_index = 0; par_index < limit; par_index++)
2193 elem = XVECEXP (expr, 0, par_index);
2194 if (GET_CODE (elem) == SET
2195 && MEM_P (SET_DEST (elem))
2196 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2197 dwarf2out_frame_debug_expr (elem, label);
2200 for (par_index = 0; par_index < limit; par_index++)
2202 elem = XVECEXP (expr, 0, par_index);
2203 if (GET_CODE (elem) == SET
2204 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2205 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2206 dwarf2out_frame_debug_expr (elem, label);
2207 else if (GET_CODE (elem) == SET
2209 && !RTX_FRAME_RELATED_P (elem))
2211 /* Stack adjustment combining might combine some post-prologue
2212 stack adjustment into a prologue stack adjustment. */
2213 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2216 dwarf2out_stack_adjust (offset, label);
2222 gcc_assert (GET_CODE (expr) == SET);
2224 src = SET_SRC (expr);
2225 dest = SET_DEST (expr);
2229 rtx rsi = reg_saved_in (src);
2234 fde = current_fde ();
2236 switch (GET_CODE (dest))
2239 switch (GET_CODE (src))
2241 /* Setting FP from SP. */
2243 if (cfa.reg == (unsigned) REGNO (src))
2246 /* Update the CFA rule wrt SP or FP. Make sure src is
2247 relative to the current CFA register.
2249 We used to require that dest be either SP or FP, but the
2250 ARM copies SP to a temporary register, and from there to
2251 FP. So we just rely on the backends to only set
2252 RTX_FRAME_RELATED_P on appropriate insns. */
2253 cfa.reg = REGNO (dest);
2254 cfa_temp.reg = cfa.reg;
2255 cfa_temp.offset = cfa.offset;
2259 /* Saving a register in a register. */
2260 gcc_assert (!fixed_regs [REGNO (dest)]
2261 /* For the SPARC and its register window. */
2262 || (DWARF_FRAME_REGNUM (REGNO (src))
2263 == DWARF_FRAME_RETURN_COLUMN));
2265 /* After stack is aligned, we can only save SP in FP
2266 if drap register is used. In this case, we have
2267 to restore stack pointer with the CFA value and we
2268 don't generate this DWARF information. */
2270 && fde->stack_realign
2271 && REGNO (src) == STACK_POINTER_REGNUM)
2272 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2273 && fde->drap_reg != INVALID_REGNUM
2274 && cfa.reg != REGNO (src));
2276 queue_reg_save (label, src, dest, 0);
2283 if (dest == stack_pointer_rtx)
2287 switch (GET_CODE (XEXP (src, 1)))
2290 offset = INTVAL (XEXP (src, 1));
2293 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2295 offset = cfa_temp.offset;
2301 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2303 /* Restoring SP from FP in the epilogue. */
2304 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2305 cfa.reg = STACK_POINTER_REGNUM;
2307 else if (GET_CODE (src) == LO_SUM)
2308 /* Assume we've set the source reg of the LO_SUM from sp. */
2311 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2313 if (GET_CODE (src) != MINUS)
2315 if (cfa.reg == STACK_POINTER_REGNUM)
2316 cfa.offset += offset;
2317 if (cfa_store.reg == STACK_POINTER_REGNUM)
2318 cfa_store.offset += offset;
2320 else if (dest == hard_frame_pointer_rtx)
2323 /* Either setting the FP from an offset of the SP,
2324 or adjusting the FP */
2325 gcc_assert (frame_pointer_needed);
2327 gcc_assert (REG_P (XEXP (src, 0))
2328 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2329 && CONST_INT_P (XEXP (src, 1)));
2330 offset = INTVAL (XEXP (src, 1));
2331 if (GET_CODE (src) != MINUS)
2333 cfa.offset += offset;
2334 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2338 gcc_assert (GET_CODE (src) != MINUS);
2341 if (REG_P (XEXP (src, 0))
2342 && REGNO (XEXP (src, 0)) == cfa.reg
2343 && CONST_INT_P (XEXP (src, 1)))
2345 /* Setting a temporary CFA register that will be copied
2346 into the FP later on. */
2347 offset = - INTVAL (XEXP (src, 1));
2348 cfa.offset += offset;
2349 cfa.reg = REGNO (dest);
2350 /* Or used to save regs to the stack. */
2351 cfa_temp.reg = cfa.reg;
2352 cfa_temp.offset = cfa.offset;
2356 else if (REG_P (XEXP (src, 0))
2357 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2358 && XEXP (src, 1) == stack_pointer_rtx)
2360 /* Setting a scratch register that we will use instead
2361 of SP for saving registers to the stack. */
2362 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2363 cfa_store.reg = REGNO (dest);
2364 cfa_store.offset = cfa.offset - cfa_temp.offset;
2368 else if (GET_CODE (src) == LO_SUM
2369 && CONST_INT_P (XEXP (src, 1)))
2371 cfa_temp.reg = REGNO (dest);
2372 cfa_temp.offset = INTVAL (XEXP (src, 1));
2381 cfa_temp.reg = REGNO (dest);
2382 cfa_temp.offset = INTVAL (src);
2387 gcc_assert (REG_P (XEXP (src, 0))
2388 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2389 && CONST_INT_P (XEXP (src, 1)));
2391 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2392 cfa_temp.reg = REGNO (dest);
2393 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2396 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2397 which will fill in all of the bits. */
2404 case UNSPEC_VOLATILE:
2405 gcc_assert (targetm.dwarf_handle_frame_unspec);
2406 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2411 /* If this AND operation happens on stack pointer in prologue,
2412 we assume the stack is realigned and we extract the
2414 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2416 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2417 fde->stack_realign = 1;
2418 fde->stack_realignment = INTVAL (XEXP (src, 1));
2419 cfa_store.offset = 0;
2421 if (cfa.reg != STACK_POINTER_REGNUM
2422 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2423 fde->drap_reg = cfa.reg;
2431 def_cfa_1 (label, &cfa);
2436 /* Saving a register to the stack. Make sure dest is relative to the
2438 switch (GET_CODE (XEXP (dest, 0)))
2443 /* We can't handle variable size modifications. */
2444 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2446 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2448 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2449 && cfa_store.reg == STACK_POINTER_REGNUM);
2451 cfa_store.offset += offset;
2452 if (cfa.reg == STACK_POINTER_REGNUM)
2453 cfa.offset = cfa_store.offset;
2455 offset = -cfa_store.offset;
2461 offset = GET_MODE_SIZE (GET_MODE (dest));
2462 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2465 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2466 == STACK_POINTER_REGNUM)
2467 && cfa_store.reg == STACK_POINTER_REGNUM);
2469 cfa_store.offset += offset;
2471 /* Rule 18: If stack is aligned, we will use FP as a
2472 reference to represent the address of the stored
2475 && fde->stack_realign
2476 && src == hard_frame_pointer_rtx)
2478 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2479 cfa_store.offset = 0;
2482 if (cfa.reg == STACK_POINTER_REGNUM)
2483 cfa.offset = cfa_store.offset;
2485 offset = -cfa_store.offset;
2489 /* With an offset. */
2496 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2497 && REG_P (XEXP (XEXP (dest, 0), 0)));
2498 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2499 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2502 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2504 if (cfa_store.reg == (unsigned) regno)
2505 offset -= cfa_store.offset;
2508 gcc_assert (cfa_temp.reg == (unsigned) regno);
2509 offset -= cfa_temp.offset;
2515 /* Without an offset. */
2518 int regno = REGNO (XEXP (dest, 0));
2520 if (cfa_store.reg == (unsigned) regno)
2521 offset = -cfa_store.offset;
2524 gcc_assert (cfa_temp.reg == (unsigned) regno);
2525 offset = -cfa_temp.offset;
2532 gcc_assert (cfa_temp.reg
2533 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2534 offset = -cfa_temp.offset;
2535 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2543 /* If the source operand of this MEM operation is not a
2544 register, basically the source is return address. Here
2545 we only care how much stack grew and we don't save it. */
2549 if (REGNO (src) != STACK_POINTER_REGNUM
2550 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2551 && (unsigned) REGNO (src) == cfa.reg)
2553 /* We're storing the current CFA reg into the stack. */
2555 if (cfa.offset == 0)
2558 /* If stack is aligned, putting CFA reg into stack means
2559 we can no longer use reg + offset to represent CFA.
2560 Here we use DW_CFA_def_cfa_expression instead. The
2561 result of this expression equals to the original CFA
2564 && fde->stack_realign
2565 && cfa.indirect == 0
2566 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2568 dw_cfa_location cfa_exp;
2570 gcc_assert (fde->drap_reg == cfa.reg);
2572 cfa_exp.indirect = 1;
2573 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2574 cfa_exp.base_offset = offset;
2577 fde->drap_reg_saved = 1;
2579 def_cfa_1 (label, &cfa_exp);
2583 /* If the source register is exactly the CFA, assume
2584 we're saving SP like any other register; this happens
2586 def_cfa_1 (label, &cfa);
2587 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2592 /* Otherwise, we'll need to look in the stack to
2593 calculate the CFA. */
2594 rtx x = XEXP (dest, 0);
2598 gcc_assert (REG_P (x));
2600 cfa.reg = REGNO (x);
2601 cfa.base_offset = offset;
2603 def_cfa_1 (label, &cfa);
2608 def_cfa_1 (label, &cfa);
2610 span = targetm.dwarf_register_span (src);
2613 queue_reg_save (label, src, NULL_RTX, offset);
2616 /* We have a PARALLEL describing where the contents of SRC
2617 live. Queue register saves for each piece of the
2621 HOST_WIDE_INT span_offset = offset;
2623 gcc_assert (GET_CODE (span) == PARALLEL);
2625 limit = XVECLEN (span, 0);
2626 for (par_index = 0; par_index < limit; par_index++)
2628 rtx elem = XVECEXP (span, 0, par_index);
2630 queue_reg_save (label, elem, NULL_RTX, span_offset);
2631 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2642 /* Record call frame debugging information for INSN, which either
2643 sets SP or FP (adjusting how we calculate the frame address) or saves a
2644 register to the stack. If INSN is NULL_RTX, initialize our state.
2646 If AFTER_P is false, we're being called before the insn is emitted,
2647 otherwise after. Call instructions get invoked twice. */
2650 dwarf2out_frame_debug (rtx insn, bool after_p)
2654 bool handled_one = false;
2656 if (insn == NULL_RTX)
2660 /* Flush any queued register saves. */
2661 flush_queued_reg_saves ();
2663 /* Set up state for generating call frame debug info. */
2666 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2668 cfa.reg = STACK_POINTER_REGNUM;
2671 cfa_temp.offset = 0;
2673 for (i = 0; i < num_regs_saved_in_regs; i++)
2675 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2676 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2678 num_regs_saved_in_regs = 0;
2680 if (barrier_args_size)
2682 XDELETEVEC (barrier_args_size);
2683 barrier_args_size = NULL;
2688 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2689 flush_queued_reg_saves ();
2691 if (!RTX_FRAME_RELATED_P (insn))
2693 /* ??? This should be done unconditionally since stack adjustments
2694 matter if the stack pointer is not the CFA register anymore but
2695 is still used to save registers. */
2696 if (!ACCUMULATE_OUTGOING_ARGS)
2697 dwarf2out_notice_stack_adjust (insn, after_p);
2701 label = dwarf2out_cfi_label (false);
2703 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2704 switch (REG_NOTE_KIND (note))
2706 case REG_FRAME_RELATED_EXPR:
2707 insn = XEXP (note, 0);
2710 case REG_CFA_DEF_CFA:
2711 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2715 case REG_CFA_ADJUST_CFA:
2720 if (GET_CODE (n) == PARALLEL)
2721 n = XVECEXP (n, 0, 0);
2723 dwarf2out_frame_debug_adjust_cfa (n, label);
2727 case REG_CFA_OFFSET:
2730 n = single_set (insn);
2731 dwarf2out_frame_debug_cfa_offset (n, label);
2735 case REG_CFA_REGISTER:
2740 if (GET_CODE (n) == PARALLEL)
2741 n = XVECEXP (n, 0, 0);
2743 dwarf2out_frame_debug_cfa_register (n, label);
2747 case REG_CFA_RESTORE:
2752 if (GET_CODE (n) == PARALLEL)
2753 n = XVECEXP (n, 0, 0);
2756 dwarf2out_frame_debug_cfa_restore (n, label);
2760 case REG_CFA_SET_VDRAP:
2764 dw_fde_ref fde = current_fde ();
2767 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2769 fde->vdrap_reg = REGNO (n);
2781 insn = PATTERN (insn);
2783 dwarf2out_frame_debug_expr (insn, label);
2786 /* Determine if we need to save and restore CFI information around this
2787 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2788 we do need to save/restore, then emit the save now, and insert a
2789 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2792 dwarf2out_begin_epilogue (rtx insn)
2794 bool saw_frp = false;
2797 /* Scan forward to the return insn, noticing if there are possible
2798 frame related insns. */
2799 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2804 /* Look for both regular and sibcalls to end the block. */
2805 if (returnjump_p (i))
2807 if (CALL_P (i) && SIBLING_CALL_P (i))
2810 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2813 rtx seq = PATTERN (i);
2815 if (returnjump_p (XVECEXP (seq, 0, 0)))
2817 if (CALL_P (XVECEXP (seq, 0, 0))
2818 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2821 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2822 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2826 if (RTX_FRAME_RELATED_P (i))
2830 /* If the port doesn't emit epilogue unwind info, we don't need a
2831 save/restore pair. */
2835 /* Otherwise, search forward to see if the return insn was the last
2836 basic block of the function. If so, we don't need save/restore. */
2837 gcc_assert (i != NULL);
2838 i = next_real_insn (i);
2842 /* Insert the restore before that next real insn in the stream, and before
2843 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2844 properly nested. This should be after any label or alignment. This
2845 will be pushed into the CFI stream by the function below. */
2848 rtx p = PREV_INSN (i);
2851 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
2855 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
2857 emit_cfa_remember = true;
2859 /* And emulate the state save. */
2860 gcc_assert (!cfa_remember.in_use);
2862 cfa_remember.in_use = 1;
2865 /* A "subroutine" of dwarf2out_begin_epilogue. Emit the restore required. */
2868 dwarf2out_frame_debug_restore_state (void)
2870 dw_cfi_ref cfi = new_cfi ();
2871 const char *label = dwarf2out_cfi_label (false);
2873 cfi->dw_cfi_opc = DW_CFA_restore_state;
2874 add_fde_cfi (label, cfi);
2876 gcc_assert (cfa_remember.in_use);
2878 cfa_remember.in_use = 0;
2883 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2884 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2885 (enum dwarf_call_frame_info cfi);
2887 static enum dw_cfi_oprnd_type
2888 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2893 case DW_CFA_GNU_window_save:
2894 case DW_CFA_remember_state:
2895 case DW_CFA_restore_state:
2896 return dw_cfi_oprnd_unused;
2898 case DW_CFA_set_loc:
2899 case DW_CFA_advance_loc1:
2900 case DW_CFA_advance_loc2:
2901 case DW_CFA_advance_loc4:
2902 case DW_CFA_MIPS_advance_loc8:
2903 return dw_cfi_oprnd_addr;
2906 case DW_CFA_offset_extended:
2907 case DW_CFA_def_cfa:
2908 case DW_CFA_offset_extended_sf:
2909 case DW_CFA_def_cfa_sf:
2910 case DW_CFA_restore:
2911 case DW_CFA_restore_extended:
2912 case DW_CFA_undefined:
2913 case DW_CFA_same_value:
2914 case DW_CFA_def_cfa_register:
2915 case DW_CFA_register:
2916 case DW_CFA_expression:
2917 return dw_cfi_oprnd_reg_num;
2919 case DW_CFA_def_cfa_offset:
2920 case DW_CFA_GNU_args_size:
2921 case DW_CFA_def_cfa_offset_sf:
2922 return dw_cfi_oprnd_offset;
2924 case DW_CFA_def_cfa_expression:
2925 return dw_cfi_oprnd_loc;
2932 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2933 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2934 (enum dwarf_call_frame_info cfi);
2936 static enum dw_cfi_oprnd_type
2937 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2941 case DW_CFA_def_cfa:
2942 case DW_CFA_def_cfa_sf:
2944 case DW_CFA_offset_extended_sf:
2945 case DW_CFA_offset_extended:
2946 return dw_cfi_oprnd_offset;
2948 case DW_CFA_register:
2949 return dw_cfi_oprnd_reg_num;
2951 case DW_CFA_expression:
2952 return dw_cfi_oprnd_loc;
2955 return dw_cfi_oprnd_unused;
2959 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2961 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
2962 switch to the data section instead, and write out a synthetic start label
2963 for collect2 the first time around. */
2966 switch_to_eh_frame_section (bool back)
2970 #ifdef EH_FRAME_SECTION_NAME
2971 if (eh_frame_section == 0)
2975 if (EH_TABLES_CAN_BE_READ_ONLY)
2981 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2983 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2985 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2987 flags = ((! flag_pic
2988 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2989 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2990 && (per_encoding & 0x70) != DW_EH_PE_absptr
2991 && (per_encoding & 0x70) != DW_EH_PE_aligned
2992 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2993 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2994 ? 0 : SECTION_WRITE);
2997 flags = SECTION_WRITE;
2998 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3002 if (eh_frame_section)
3003 switch_to_section (eh_frame_section);
3006 /* We have no special eh_frame section. Put the information in
3007 the data section and emit special labels to guide collect2. */
3008 switch_to_section (data_section);
3012 label = get_file_function_name ("F");
3013 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3014 targetm.asm_out.globalize_label (asm_out_file,
3015 IDENTIFIER_POINTER (label));
3016 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3021 /* Switch [BACK] to the eh or debug frame table section, depending on
3025 switch_to_frame_table_section (int for_eh, bool back)
3028 switch_to_eh_frame_section (back);
3031 if (!debug_frame_section)
3032 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3033 SECTION_DEBUG, NULL);
3034 switch_to_section (debug_frame_section);
3038 /* Output a Call Frame Information opcode and its operand(s). */
3041 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3046 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3047 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3048 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3049 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3050 ((unsigned HOST_WIDE_INT)
3051 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3052 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3054 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3055 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3056 "DW_CFA_offset, column %#lx", r);
3057 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3058 dw2_asm_output_data_uleb128 (off, NULL);
3060 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3062 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3063 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3064 "DW_CFA_restore, column %#lx", r);
3068 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3069 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3071 switch (cfi->dw_cfi_opc)
3073 case DW_CFA_set_loc:
3075 dw2_asm_output_encoded_addr_rtx (
3076 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3077 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3080 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3081 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3082 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3085 case DW_CFA_advance_loc1:
3086 dw2_asm_output_delta (1, 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_loc2:
3092 dw2_asm_output_delta (2, 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_advance_loc4:
3098 dw2_asm_output_delta (4, 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_MIPS_advance_loc8:
3104 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3105 fde->dw_fde_current_label, NULL);
3106 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3109 case DW_CFA_offset_extended:
3110 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3111 dw2_asm_output_data_uleb128 (r, NULL);
3112 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3113 dw2_asm_output_data_uleb128 (off, NULL);
3116 case DW_CFA_def_cfa:
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 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3122 case DW_CFA_offset_extended_sf:
3123 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3124 dw2_asm_output_data_uleb128 (r, NULL);
3125 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3126 dw2_asm_output_data_sleb128 (off, NULL);
3129 case DW_CFA_def_cfa_sf:
3130 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3131 dw2_asm_output_data_uleb128 (r, NULL);
3132 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3133 dw2_asm_output_data_sleb128 (off, NULL);
3136 case DW_CFA_restore_extended:
3137 case DW_CFA_undefined:
3138 case DW_CFA_same_value:
3139 case DW_CFA_def_cfa_register:
3140 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3141 dw2_asm_output_data_uleb128 (r, NULL);
3144 case DW_CFA_register:
3145 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3146 dw2_asm_output_data_uleb128 (r, NULL);
3147 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3148 dw2_asm_output_data_uleb128 (r, NULL);
3151 case DW_CFA_def_cfa_offset:
3152 case DW_CFA_GNU_args_size:
3153 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3156 case DW_CFA_def_cfa_offset_sf:
3157 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3158 dw2_asm_output_data_sleb128 (off, NULL);
3161 case DW_CFA_GNU_window_save:
3164 case DW_CFA_def_cfa_expression:
3165 case DW_CFA_expression:
3166 output_cfa_loc (cfi);
3169 case DW_CFA_GNU_negative_offset_extended:
3170 /* Obsoleted by DW_CFA_offset_extended_sf. */
3179 /* Similar, but do it via assembler directives instead. */
3182 output_cfi_directive (dw_cfi_ref cfi)
3184 unsigned long r, r2;
3186 switch (cfi->dw_cfi_opc)
3188 case DW_CFA_advance_loc:
3189 case DW_CFA_advance_loc1:
3190 case DW_CFA_advance_loc2:
3191 case DW_CFA_advance_loc4:
3192 case DW_CFA_MIPS_advance_loc8:
3193 case DW_CFA_set_loc:
3194 /* Should only be created by add_fde_cfi in a code path not
3195 followed when emitting via directives. The assembler is
3196 going to take care of this for us. */
3200 case DW_CFA_offset_extended:
3201 case DW_CFA_offset_extended_sf:
3202 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3203 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3204 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3207 case DW_CFA_restore:
3208 case DW_CFA_restore_extended:
3209 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3210 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3213 case DW_CFA_undefined:
3214 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3215 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3218 case DW_CFA_same_value:
3219 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3220 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3223 case DW_CFA_def_cfa:
3224 case DW_CFA_def_cfa_sf:
3225 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3226 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3227 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3230 case DW_CFA_def_cfa_register:
3231 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3232 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3235 case DW_CFA_register:
3236 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3237 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3238 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3241 case DW_CFA_def_cfa_offset:
3242 case DW_CFA_def_cfa_offset_sf:
3243 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3244 HOST_WIDE_INT_PRINT_DEC"\n",
3245 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3248 case DW_CFA_remember_state:
3249 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3251 case DW_CFA_restore_state:
3252 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3255 case DW_CFA_GNU_args_size:
3256 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3257 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3259 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3260 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3261 fputc ('\n', asm_out_file);
3264 case DW_CFA_GNU_window_save:
3265 fprintf (asm_out_file, "\t.cfi_window_save\n");
3268 case DW_CFA_def_cfa_expression:
3269 case DW_CFA_expression:
3270 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3271 output_cfa_loc_raw (cfi);
3272 fputc ('\n', asm_out_file);
3280 DEF_VEC_P (dw_cfi_ref);
3281 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3283 /* Output CFIs to bring current FDE to the same state as after executing
3284 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3285 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3286 other arguments to pass to output_cfi. */
3289 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3291 struct dw_cfi_struct cfi_buf;
3293 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3294 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3295 unsigned int len, idx;
3297 for (;; cfi = cfi->dw_cfi_next)
3298 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3300 case DW_CFA_advance_loc:
3301 case DW_CFA_advance_loc1:
3302 case DW_CFA_advance_loc2:
3303 case DW_CFA_advance_loc4:
3304 case DW_CFA_MIPS_advance_loc8:
3305 case DW_CFA_set_loc:
3306 /* All advances should be ignored. */
3308 case DW_CFA_remember_state:
3310 dw_cfi_ref args_size = cfi_args_size;
3312 /* Skip everything between .cfi_remember_state and
3313 .cfi_restore_state. */
3314 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3315 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3317 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3320 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3327 cfi_args_size = args_size;
3331 case DW_CFA_GNU_args_size:
3332 cfi_args_size = cfi;
3334 case DW_CFA_GNU_window_save:
3337 case DW_CFA_offset_extended:
3338 case DW_CFA_offset_extended_sf:
3339 case DW_CFA_restore:
3340 case DW_CFA_restore_extended:
3341 case DW_CFA_undefined:
3342 case DW_CFA_same_value:
3343 case DW_CFA_register:
3344 case DW_CFA_val_offset:
3345 case DW_CFA_val_offset_sf:
3346 case DW_CFA_expression:
3347 case DW_CFA_val_expression:
3348 case DW_CFA_GNU_negative_offset_extended:
3349 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3350 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3351 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3352 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3354 case DW_CFA_def_cfa:
3355 case DW_CFA_def_cfa_sf:
3356 case DW_CFA_def_cfa_expression:
3358 cfi_cfa_offset = cfi;
3360 case DW_CFA_def_cfa_register:
3363 case DW_CFA_def_cfa_offset:
3364 case DW_CFA_def_cfa_offset_sf:
3365 cfi_cfa_offset = cfi;
3368 gcc_assert (cfi == NULL);
3370 len = VEC_length (dw_cfi_ref, regs);
3371 for (idx = 0; idx < len; idx++)
3373 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3375 && cfi2->dw_cfi_opc != DW_CFA_restore
3376 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3379 output_cfi_directive (cfi2);
3381 output_cfi (cfi2, fde, for_eh);
3384 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3386 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3388 switch (cfi_cfa_offset->dw_cfi_opc)
3390 case DW_CFA_def_cfa_offset:
3391 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3392 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3394 case DW_CFA_def_cfa_offset_sf:
3395 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3396 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3398 case DW_CFA_def_cfa:
3399 case DW_CFA_def_cfa_sf:
3400 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3401 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3408 else if (cfi_cfa_offset)
3409 cfi_cfa = cfi_cfa_offset;
3413 output_cfi_directive (cfi_cfa);
3415 output_cfi (cfi_cfa, fde, for_eh);
3418 cfi_cfa_offset = NULL;
3420 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3423 output_cfi_directive (cfi_args_size);
3425 output_cfi (cfi_args_size, fde, for_eh);
3427 cfi_args_size = NULL;
3430 VEC_free (dw_cfi_ref, heap, regs);
3433 else if (do_cfi_asm)
3434 output_cfi_directive (cfi);
3436 output_cfi (cfi, fde, for_eh);
3443 /* Output one FDE. */
3446 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3447 char *section_start_label, int fde_encoding, char *augmentation,
3448 bool any_lsda_needed, int lsda_encoding)
3450 const char *begin, *end;
3451 static unsigned int j;
3452 char l1[20], l2[20];
3455 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh,
3457 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3459 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3460 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3461 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3462 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3463 " indicating 64-bit DWARF extension");
3464 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3466 ASM_OUTPUT_LABEL (asm_out_file, l1);
3469 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3471 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3472 debug_frame_section, "FDE CIE offset");
3474 if (!fde->dw_fde_switched_sections)
3476 begin = fde->dw_fde_begin;
3477 end = fde->dw_fde_end;
3481 /* For the first section, prefer dw_fde_begin over
3482 dw_fde_{hot,cold}_section_label, as the latter
3483 might be separated from the real start of the
3484 function by alignment padding. */
3486 begin = fde->dw_fde_begin;
3487 else if (fde->dw_fde_switched_cold_to_hot)
3488 begin = fde->dw_fde_hot_section_label;
3490 begin = fde->dw_fde_unlikely_section_label;
3491 if (second ^ fde->dw_fde_switched_cold_to_hot)
3492 end = fde->dw_fde_unlikely_section_end_label;
3494 end = fde->dw_fde_hot_section_end_label;
3499 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3500 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3501 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3502 "FDE initial location");
3503 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3504 end, begin, "FDE address range");
3508 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3509 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3512 if (augmentation[0])
3514 if (any_lsda_needed)
3516 int size = size_of_encoded_value (lsda_encoding);
3518 if (lsda_encoding == DW_EH_PE_aligned)
3520 int offset = ( 4 /* Length */
3521 + 4 /* CIE offset */
3522 + 2 * size_of_encoded_value (fde_encoding)
3523 + 1 /* Augmentation size */ );
3524 int pad = -offset & (PTR_SIZE - 1);
3527 gcc_assert (size_of_uleb128 (size) == 1);
3530 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3532 if (fde->uses_eh_lsda)
3534 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3535 fde->funcdef_number);
3536 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3537 gen_rtx_SYMBOL_REF (Pmode, l1),
3539 "Language Specific Data Area");
3543 if (lsda_encoding == DW_EH_PE_aligned)
3544 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3545 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3546 "Language Specific Data Area (none)");
3550 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3553 /* Loop through the Call Frame Instructions associated with
3555 fde->dw_fde_current_label = begin;
3556 if (!fde->dw_fde_switched_sections)
3557 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3558 output_cfi (cfi, fde, for_eh);
3561 if (fde->dw_fde_switch_cfi)
3562 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3564 output_cfi (cfi, fde, for_eh);
3565 if (cfi == fde->dw_fde_switch_cfi)
3571 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3573 if (fde->dw_fde_switch_cfi)
3575 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3576 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3577 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3578 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3580 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3581 output_cfi (cfi, fde, for_eh);
3584 /* If we are to emit a ref/link from function bodies to their frame tables,
3585 do it now. This is typically performed to make sure that tables
3586 associated with functions are dragged with them and not discarded in
3587 garbage collecting links. We need to do this on a per function basis to
3588 cope with -ffunction-sections. */
3590 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3591 /* Switch to the function section, emit the ref to the tables, and
3592 switch *back* into the table section. */
3593 switch_to_section (function_section (fde->decl));
3594 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3595 switch_to_frame_table_section (for_eh, true);
3598 /* Pad the FDE out to an address sized boundary. */
3599 ASM_OUTPUT_ALIGN (asm_out_file,
3600 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3601 ASM_OUTPUT_LABEL (asm_out_file, l2);
3606 /* Return true if frame description entry FDE is needed for EH. */
3609 fde_needed_for_eh_p (dw_fde_ref fde)
3611 if (flag_asynchronous_unwind_tables)
3614 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3617 if (fde->uses_eh_lsda)
3620 /* If exceptions are enabled, we have collected nothrow info. */
3621 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3627 /* Output the call frame information used to record information
3628 that relates to calculating the frame pointer, and records the
3629 location of saved registers. */
3632 output_call_frame_info (int for_eh)
3637 char l1[20], l2[20], section_start_label[20];
3638 bool any_lsda_needed = false;
3639 char augmentation[6];
3640 int augmentation_size;
3641 int fde_encoding = DW_EH_PE_absptr;
3642 int per_encoding = DW_EH_PE_absptr;
3643 int lsda_encoding = DW_EH_PE_absptr;
3645 rtx personality = NULL;
3648 /* Don't emit a CIE if there won't be any FDEs. */
3649 if (fde_table_in_use == 0)
3652 /* Nothing to do if the assembler's doing it all. */
3653 if (dwarf2out_do_cfi_asm ())
3656 /* If we don't have any functions we'll want to unwind out of, don't emit
3657 any EH unwind information. If we make FDEs linkonce, we may have to
3658 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3659 want to avoid having an FDE kept around when the function it refers to
3660 is discarded. Example where this matters: a primary function template
3661 in C++ requires EH information, an explicit specialization doesn't. */
3664 bool any_eh_needed = false;
3666 for (i = 0; i < fde_table_in_use; i++)
3667 if (fde_table[i].uses_eh_lsda)
3668 any_eh_needed = any_lsda_needed = true;
3669 else if (fde_needed_for_eh_p (&fde_table[i]))
3670 any_eh_needed = true;
3671 else if (TARGET_USES_WEAK_UNWIND_INFO)
3672 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl, 1, 1);
3678 /* We're going to be generating comments, so turn on app. */
3682 /* Switch to the proper frame section, first time. */
3683 switch_to_frame_table_section (for_eh, false);
3685 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3686 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3688 /* Output the CIE. */
3689 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3690 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3691 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3692 dw2_asm_output_data (4, 0xffffffff,
3693 "Initial length escape value indicating 64-bit DWARF extension");
3694 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3695 "Length of Common Information Entry");
3696 ASM_OUTPUT_LABEL (asm_out_file, l1);
3698 /* Now that the CIE pointer is PC-relative for EH,
3699 use 0 to identify the CIE. */
3700 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3701 (for_eh ? 0 : DWARF_CIE_ID),
3702 "CIE Identifier Tag");
3704 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3705 use CIE version 1, unless that would produce incorrect results
3706 due to overflowing the return register column. */
3707 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3709 if (return_reg >= 256 || dwarf_version > 2)
3711 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3713 augmentation[0] = 0;
3714 augmentation_size = 0;
3716 personality = current_unit_personality;
3722 z Indicates that a uleb128 is present to size the
3723 augmentation section.
3724 L Indicates the encoding (and thus presence) of
3725 an LSDA pointer in the FDE augmentation.
3726 R Indicates a non-default pointer encoding for
3728 P Indicates the presence of an encoding + language
3729 personality routine in the CIE augmentation. */
3731 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3732 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3733 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3735 p = augmentation + 1;
3739 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3740 assemble_external_libcall (personality);
3742 if (any_lsda_needed)
3745 augmentation_size += 1;
3747 if (fde_encoding != DW_EH_PE_absptr)
3750 augmentation_size += 1;
3752 if (p > augmentation + 1)
3754 augmentation[0] = 'z';
3758 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3759 if (personality && per_encoding == DW_EH_PE_aligned)
3761 int offset = ( 4 /* Length */
3763 + 1 /* CIE version */
3764 + strlen (augmentation) + 1 /* Augmentation */
3765 + size_of_uleb128 (1) /* Code alignment */
3766 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3768 + 1 /* Augmentation size */
3769 + 1 /* Personality encoding */ );
3770 int pad = -offset & (PTR_SIZE - 1);
3772 augmentation_size += pad;
3774 /* Augmentations should be small, so there's scarce need to
3775 iterate for a solution. Die if we exceed one uleb128 byte. */
3776 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3780 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3781 if (dw_cie_version >= 4)
3783 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3784 dw2_asm_output_data (1, 0, "CIE Segment Size");
3786 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3787 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3788 "CIE Data Alignment Factor");
3790 if (dw_cie_version == 1)
3791 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3793 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3795 if (augmentation[0])
3797 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3800 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3801 eh_data_format_name (per_encoding));
3802 dw2_asm_output_encoded_addr_rtx (per_encoding,
3807 if (any_lsda_needed)
3808 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3809 eh_data_format_name (lsda_encoding));
3811 if (fde_encoding != DW_EH_PE_absptr)
3812 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3813 eh_data_format_name (fde_encoding));
3816 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3817 output_cfi (cfi, NULL, for_eh);
3819 /* Pad the CIE out to an address sized boundary. */
3820 ASM_OUTPUT_ALIGN (asm_out_file,
3821 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3822 ASM_OUTPUT_LABEL (asm_out_file, l2);
3824 /* Loop through all of the FDE's. */
3825 for (i = 0; i < fde_table_in_use; i++)
3828 fde = &fde_table[i];
3830 /* Don't emit EH unwind info for leaf functions that don't need it. */
3831 if (for_eh && !fde_needed_for_eh_p (fde))
3834 for (k = 0; k < (fde->dw_fde_switched_sections ? 2 : 1); k++)
3835 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3836 augmentation, any_lsda_needed, lsda_encoding);
3839 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3840 dw2_asm_output_data (4, 0, "End of Table");
3841 #ifdef MIPS_DEBUGGING_INFO
3842 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3843 get a value of 0. Putting .align 0 after the label fixes it. */
3844 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3847 /* Turn off app to make assembly quicker. */
3852 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
3855 dwarf2out_do_cfi_startproc (bool second)
3859 rtx personality = get_personality_function (current_function_decl);
3861 fprintf (asm_out_file, "\t.cfi_startproc\n");
3865 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3868 /* ??? The GAS support isn't entirely consistent. We have to
3869 handle indirect support ourselves, but PC-relative is done
3870 in the assembler. Further, the assembler can't handle any
3871 of the weirder relocation types. */
3872 if (enc & DW_EH_PE_indirect)
3873 ref = dw2_force_const_mem (ref, true);
3875 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
3876 output_addr_const (asm_out_file, ref);
3877 fputc ('\n', asm_out_file);
3880 if (crtl->uses_eh_lsda)
3884 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3885 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
3886 current_function_funcdef_no);
3887 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
3888 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
3890 if (enc & DW_EH_PE_indirect)
3891 ref = dw2_force_const_mem (ref, true);
3893 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
3894 output_addr_const (asm_out_file, ref);
3895 fputc ('\n', asm_out_file);
3899 /* Output a marker (i.e. a label) for the beginning of a function, before
3903 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
3904 const char *file ATTRIBUTE_UNUSED)
3906 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3911 current_function_func_begin_label = NULL;
3913 #ifdef TARGET_UNWIND_INFO
3914 /* ??? current_function_func_begin_label is also used by except.c
3915 for call-site information. We must emit this label if it might
3917 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3918 && ! dwarf2out_do_frame ())
3921 if (! dwarf2out_do_frame ())
3925 fnsec = function_section (current_function_decl);
3926 switch_to_section (fnsec);
3927 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3928 current_function_funcdef_no);
3929 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3930 current_function_funcdef_no);
3931 dup_label = xstrdup (label);
3932 current_function_func_begin_label = dup_label;
3934 #ifdef TARGET_UNWIND_INFO
3935 /* We can elide the fde allocation if we're not emitting debug info. */
3936 if (! dwarf2out_do_frame ())
3940 /* Expand the fde table if necessary. */
3941 if (fde_table_in_use == fde_table_allocated)
3943 fde_table_allocated += FDE_TABLE_INCREMENT;
3944 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
3945 memset (fde_table + fde_table_in_use, 0,
3946 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
3949 /* Record the FDE associated with this function. */
3950 current_funcdef_fde = fde_table_in_use;
3952 /* Add the new FDE at the end of the fde_table. */
3953 fde = &fde_table[fde_table_in_use++];
3954 fde->decl = current_function_decl;
3955 fde->dw_fde_begin = dup_label;
3956 fde->dw_fde_current_label = dup_label;
3957 fde->dw_fde_hot_section_label = NULL;
3958 fde->dw_fde_hot_section_end_label = NULL;
3959 fde->dw_fde_unlikely_section_label = NULL;
3960 fde->dw_fde_unlikely_section_end_label = NULL;
3961 fde->dw_fde_switched_sections = 0;
3962 fde->dw_fde_switched_cold_to_hot = 0;
3963 fde->dw_fde_end = NULL;
3964 fde->dw_fde_cfi = NULL;
3965 fde->dw_fde_switch_cfi = NULL;
3966 fde->funcdef_number = current_function_funcdef_no;
3967 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
3968 fde->uses_eh_lsda = crtl->uses_eh_lsda;
3969 fde->nothrow = crtl->nothrow;
3970 fde->drap_reg = INVALID_REGNUM;
3971 fde->vdrap_reg = INVALID_REGNUM;
3972 if (flag_reorder_blocks_and_partition)
3974 section *unlikelysec;
3975 if (first_function_block_is_cold)
3976 fde->in_std_section = 1;
3979 = (fnsec == text_section
3980 || (cold_text_section && fnsec == cold_text_section));
3981 unlikelysec = unlikely_text_section ();
3982 fde->cold_in_std_section
3983 = (unlikelysec == text_section
3984 || (cold_text_section && unlikelysec == cold_text_section));
3989 = (fnsec == text_section
3990 || (cold_text_section && fnsec == cold_text_section));
3991 fde->cold_in_std_section = 0;
3994 args_size = old_args_size = 0;
3996 /* We only want to output line number information for the genuine dwarf2
3997 prologue case, not the eh frame case. */
3998 #ifdef DWARF2_DEBUGGING_INFO
4000 dwarf2out_source_line (line, file, 0, true);
4003 if (dwarf2out_do_cfi_asm ())
4004 dwarf2out_do_cfi_startproc (false);
4007 rtx personality = get_personality_function (current_function_decl);
4008 if (!current_unit_personality)
4009 current_unit_personality = personality;
4011 /* We cannot keep a current personality per function as without CFI
4012 asm, at the point where we emit the CFI data, there is no current
4013 function anymore. */
4014 if (personality && current_unit_personality != personality)
4015 sorry ("multiple EH personalities are supported only with assemblers "
4016 "supporting .cfi_personality directive");
4020 /* Output a marker (i.e. a label) for the absolute end of the generated code
4021 for a function definition. This gets called *after* the epilogue code has
4025 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4026 const char *file ATTRIBUTE_UNUSED)
4029 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4031 #ifdef DWARF2_DEBUGGING_INFO
4032 last_var_location_insn = NULL_RTX;
4035 if (dwarf2out_do_cfi_asm ())
4036 fprintf (asm_out_file, "\t.cfi_endproc\n");
4038 /* Output a label to mark the endpoint of the code generated for this
4040 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4041 current_function_funcdef_no);
4042 ASM_OUTPUT_LABEL (asm_out_file, label);
4043 fde = current_fde ();
4044 gcc_assert (fde != NULL);
4045 fde->dw_fde_end = xstrdup (label);
4049 dwarf2out_frame_init (void)
4051 /* Allocate the initial hunk of the fde_table. */
4052 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
4053 fde_table_allocated = FDE_TABLE_INCREMENT;
4054 fde_table_in_use = 0;
4056 /* Generate the CFA instructions common to all FDE's. Do it now for the
4057 sake of lookup_cfa. */
4059 /* On entry, the Canonical Frame Address is at SP. */
4060 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4062 #ifdef DWARF2_UNWIND_INFO
4063 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
4064 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4069 dwarf2out_frame_finish (void)
4071 /* Output call frame information. */
4072 if (DWARF2_FRAME_INFO)
4073 output_call_frame_info (0);
4075 #ifndef TARGET_UNWIND_INFO
4076 /* Output another copy for the unwinder. */
4077 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
4078 output_call_frame_info (1);
4082 /* Note that the current function section is being used for code. */
4085 dwarf2out_note_section_used (void)
4087 section *sec = current_function_section ();
4088 if (sec == text_section)
4089 text_section_used = true;
4090 else if (sec == cold_text_section)
4091 cold_text_section_used = true;
4095 dwarf2out_switch_text_section (void)
4097 dw_fde_ref fde = current_fde ();
4099 gcc_assert (cfun && fde && !fde->dw_fde_switched_sections);
4101 fde->dw_fde_switched_sections = 1;
4102 fde->dw_fde_switched_cold_to_hot = !in_cold_section_p;
4104 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
4105 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
4106 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
4107 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
4108 have_multiple_function_sections = true;
4110 /* Reset the current label on switching text sections, so that we
4111 don't attempt to advance_loc4 between labels in different sections. */
4112 fde->dw_fde_current_label = NULL;
4114 /* There is no need to mark used sections when not debugging. */
4115 if (cold_text_section != NULL)
4116 dwarf2out_note_section_used ();
4118 if (dwarf2out_do_cfi_asm ())
4119 fprintf (asm_out_file, "\t.cfi_endproc\n");
4121 /* Now do the real section switch. */
4122 switch_to_section (current_function_section ());
4124 if (dwarf2out_do_cfi_asm ())
4126 dwarf2out_do_cfi_startproc (true);
4127 /* As this is a different FDE, insert all current CFI instructions
4129 output_cfis (fde->dw_fde_cfi, true, fde, true);
4133 dw_cfi_ref cfi = fde->dw_fde_cfi;
4135 cfi = fde->dw_fde_cfi;
4137 while (cfi->dw_cfi_next != NULL)
4138 cfi = cfi->dw_cfi_next;
4139 fde->dw_fde_switch_cfi = cfi;
4144 /* And now, the subset of the debugging information support code necessary
4145 for emitting location expressions. */
4147 /* Data about a single source file. */
4148 struct GTY(()) dwarf_file_data {
4149 const char * filename;
4153 typedef struct dw_val_struct *dw_val_ref;
4154 typedef struct die_struct *dw_die_ref;
4155 typedef const struct die_struct *const_dw_die_ref;
4156 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4157 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4159 typedef struct GTY(()) deferred_locations_struct
4163 } deferred_locations;
4165 DEF_VEC_O(deferred_locations);
4166 DEF_VEC_ALLOC_O(deferred_locations,gc);
4168 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4170 DEF_VEC_P(dw_die_ref);
4171 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4173 /* Each DIE may have a series of attribute/value pairs. Values
4174 can take on several forms. The forms that are used in this
4175 implementation are listed below. */
4180 dw_val_class_offset,
4182 dw_val_class_loc_list,
4183 dw_val_class_range_list,
4185 dw_val_class_unsigned_const,
4186 dw_val_class_const_double,
4189 dw_val_class_die_ref,
4190 dw_val_class_fde_ref,
4191 dw_val_class_lbl_id,
4192 dw_val_class_lineptr,
4194 dw_val_class_macptr,
4199 /* Describe a floating point constant value, or a vector constant value. */
4201 typedef struct GTY(()) dw_vec_struct {
4202 unsigned char * GTY((length ("%h.length"))) array;