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 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
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
39 #include "coretypes.h"
46 #include "hard-reg-set.h"
48 #include "insn-config.h"
56 #include "dwarf2out.h"
57 #include "dwarf2asm.h"
63 #include "diagnostic.h"
66 #include "langhooks.h"
71 #ifdef DWARF2_DEBUGGING_INFO
72 static void dwarf2out_source_line (unsigned int, const char *);
75 /* DWARF2 Abbreviation Glossary:
76 CFA = Canonical Frame Address
77 a fixed address on the stack which identifies a call frame.
78 We define it to be the value of SP just before the call insn.
79 The CFA register and offset, which may change during the course
80 of the function, are used to calculate its value at runtime.
81 CFI = Call Frame Instruction
82 an instruction for the DWARF2 abstract machine
83 CIE = Common Information Entry
84 information describing information common to one or more FDEs
85 DIE = Debugging Information Entry
86 FDE = Frame Description Entry
87 information describing the stack call frame, in particular,
88 how to restore registers
90 DW_CFA_... = DWARF2 CFA call frame instruction
91 DW_TAG_... = DWARF2 DIE tag */
93 #ifndef DWARF2_FRAME_INFO
94 # ifdef DWARF2_DEBUGGING_INFO
95 # define DWARF2_FRAME_INFO \
96 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
98 # define DWARF2_FRAME_INFO 0
102 /* Map register numbers held in the call frame info that gcc has
103 collected using DWARF_FRAME_REGNUM to those that should be output in
104 .debug_frame and .eh_frame. */
105 #ifndef DWARF2_FRAME_REG_OUT
106 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
109 /* Decide whether we want to emit frame unwind information for the current
113 dwarf2out_do_frame (void)
115 /* We want to emit correct CFA location expressions or lists, so we
116 have to return true if we're going to output debug info, even if
117 we're not going to output frame or unwind info. */
118 return (write_symbols == DWARF2_DEBUG
119 || write_symbols == VMS_AND_DWARF2_DEBUG
121 #ifdef DWARF2_UNWIND_INFO
122 || (DWARF2_UNWIND_INFO
123 && (flag_unwind_tables
124 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
129 /* The size of the target's pointer type. */
131 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
134 /* Array of RTXes referenced by the debugging information, which therefore
135 must be kept around forever. */
136 static GTY(()) VEC(rtx,gc) *used_rtx_array;
138 /* A pointer to the base of a list of incomplete types which might be
139 completed at some later time. incomplete_types_list needs to be a
140 VEC(tree,gc) because we want to tell the garbage collector about
142 static GTY(()) VEC(tree,gc) *incomplete_types;
144 /* A pointer to the base of a table of references to declaration
145 scopes. This table is a display which tracks the nesting
146 of declaration scopes at the current scope and containing
147 scopes. This table is used to find the proper place to
148 define type declaration DIE's. */
149 static GTY(()) VEC(tree,gc) *decl_scope_table;
151 /* Pointers to various DWARF2 sections. */
152 static GTY(()) section *debug_info_section;
153 static GTY(()) section *debug_abbrev_section;
154 static GTY(()) section *debug_aranges_section;
155 static GTY(()) section *debug_macinfo_section;
156 static GTY(()) section *debug_line_section;
157 static GTY(()) section *debug_loc_section;
158 static GTY(()) section *debug_pubnames_section;
159 static GTY(()) section *debug_pubtypes_section;
160 static GTY(()) section *debug_str_section;
161 static GTY(()) section *debug_ranges_section;
162 static GTY(()) section *debug_frame_section;
164 /* How to start an assembler comment. */
165 #ifndef ASM_COMMENT_START
166 #define ASM_COMMENT_START ";#"
169 typedef struct dw_cfi_struct *dw_cfi_ref;
170 typedef struct dw_fde_struct *dw_fde_ref;
171 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
173 /* Call frames are described using a sequence of Call Frame
174 Information instructions. The register number, offset
175 and address fields are provided as possible operands;
176 their use is selected by the opcode field. */
178 enum dw_cfi_oprnd_type {
180 dw_cfi_oprnd_reg_num,
186 typedef union dw_cfi_oprnd_struct GTY(())
188 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
189 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
190 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
191 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
195 typedef struct dw_cfi_struct GTY(())
197 dw_cfi_ref dw_cfi_next;
198 enum dwarf_call_frame_info dw_cfi_opc;
199 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
201 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
206 /* This is how we define the location of the CFA. We use to handle it
207 as REG + OFFSET all the time, but now it can be more complex.
208 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
209 Instead of passing around REG and OFFSET, we pass a copy
210 of this structure. */
211 typedef struct cfa_loc GTY(())
213 HOST_WIDE_INT offset;
214 HOST_WIDE_INT base_offset;
216 int indirect; /* 1 if CFA is accessed via a dereference. */
219 /* All call frame descriptions (FDE's) in the GCC generated DWARF
220 refer to a single Common Information Entry (CIE), defined at
221 the beginning of the .debug_frame section. This use of a single
222 CIE obviates the need to keep track of multiple CIE's
223 in the DWARF generation routines below. */
225 typedef struct dw_fde_struct GTY(())
228 const char *dw_fde_begin;
229 const char *dw_fde_current_label;
230 const char *dw_fde_end;
231 const char *dw_fde_hot_section_label;
232 const char *dw_fde_hot_section_end_label;
233 const char *dw_fde_unlikely_section_label;
234 const char *dw_fde_unlikely_section_end_label;
235 bool dw_fde_switched_sections;
236 dw_cfi_ref dw_fde_cfi;
237 unsigned funcdef_number;
238 unsigned all_throwers_are_sibcalls : 1;
239 unsigned nothrow : 1;
240 unsigned uses_eh_lsda : 1;
244 /* Maximum size (in bytes) of an artificially generated label. */
245 #define MAX_ARTIFICIAL_LABEL_BYTES 30
247 /* The size of addresses as they appear in the Dwarf 2 data.
248 Some architectures use word addresses to refer to code locations,
249 but Dwarf 2 info always uses byte addresses. On such machines,
250 Dwarf 2 addresses need to be larger than the architecture's
252 #ifndef DWARF2_ADDR_SIZE
253 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
256 /* The size in bytes of a DWARF field indicating an offset or length
257 relative to a debug info section, specified to be 4 bytes in the
258 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
261 #ifndef DWARF_OFFSET_SIZE
262 #define DWARF_OFFSET_SIZE 4
265 /* According to the (draft) DWARF 3 specification, the initial length
266 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
267 bytes are 0xffffffff, followed by the length stored in the next 8
270 However, the SGI/MIPS ABI uses an initial length which is equal to
271 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
273 #ifndef DWARF_INITIAL_LENGTH_SIZE
274 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
277 #define DWARF_VERSION 2
279 /* Round SIZE up to the nearest BOUNDARY. */
280 #define DWARF_ROUND(SIZE,BOUNDARY) \
281 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
283 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
284 #ifndef DWARF_CIE_DATA_ALIGNMENT
285 #ifdef STACK_GROWS_DOWNWARD
286 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
288 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
292 /* CIE identifier. */
293 #if HOST_BITS_PER_WIDE_INT >= 64
294 #define DWARF_CIE_ID \
295 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
297 #define DWARF_CIE_ID DW_CIE_ID
300 /* A pointer to the base of a table that contains frame description
301 information for each routine. */
302 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
304 /* Number of elements currently allocated for fde_table. */
305 static GTY(()) unsigned fde_table_allocated;
307 /* Number of elements in fde_table currently in use. */
308 static GTY(()) unsigned fde_table_in_use;
310 /* Size (in elements) of increments by which we may expand the
312 #define FDE_TABLE_INCREMENT 256
314 /* A list of call frame insns for the CIE. */
315 static GTY(()) dw_cfi_ref cie_cfi_head;
317 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
318 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
319 attribute that accelerates the lookup of the FDE associated
320 with the subprogram. This variable holds the table index of the FDE
321 associated with the current function (body) definition. */
322 static unsigned current_funcdef_fde;
325 struct indirect_string_node GTY(())
328 unsigned int refcount;
333 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
335 static GTY(()) int dw2_string_counter;
336 static GTY(()) unsigned long dwarf2out_cfi_label_num;
338 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
340 /* Forward declarations for functions defined in this file. */
342 static char *stripattributes (const char *);
343 static const char *dwarf_cfi_name (unsigned);
344 static dw_cfi_ref new_cfi (void);
345 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
346 static void add_fde_cfi (const char *, dw_cfi_ref);
347 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
348 static void lookup_cfa (dw_cfa_location *);
349 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
350 static void initial_return_save (rtx);
351 static HOST_WIDE_INT stack_adjust_offset (rtx);
352 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
353 static void output_call_frame_info (int);
354 static void dwarf2out_stack_adjust (rtx, bool);
355 static void flush_queued_reg_saves (void);
356 static bool clobbers_queued_reg_save (rtx);
357 static void dwarf2out_frame_debug_expr (rtx, const char *);
359 /* Support for complex CFA locations. */
360 static void output_cfa_loc (dw_cfi_ref);
361 static void get_cfa_from_loc_descr (dw_cfa_location *,
362 struct dw_loc_descr_struct *);
363 static struct dw_loc_descr_struct *build_cfa_loc
364 (dw_cfa_location *, HOST_WIDE_INT);
365 static void def_cfa_1 (const char *, dw_cfa_location *);
367 /* How to start an assembler comment. */
368 #ifndef ASM_COMMENT_START
369 #define ASM_COMMENT_START ";#"
372 /* Data and reference forms for relocatable data. */
373 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
374 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
376 #ifndef DEBUG_FRAME_SECTION
377 #define DEBUG_FRAME_SECTION ".debug_frame"
380 #ifndef FUNC_BEGIN_LABEL
381 #define FUNC_BEGIN_LABEL "LFB"
384 #ifndef FUNC_END_LABEL
385 #define FUNC_END_LABEL "LFE"
388 #ifndef FRAME_BEGIN_LABEL
389 #define FRAME_BEGIN_LABEL "Lframe"
391 #define CIE_AFTER_SIZE_LABEL "LSCIE"
392 #define CIE_END_LABEL "LECIE"
393 #define FDE_LABEL "LSFDE"
394 #define FDE_AFTER_SIZE_LABEL "LASFDE"
395 #define FDE_END_LABEL "LEFDE"
396 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
397 #define LINE_NUMBER_END_LABEL "LELT"
398 #define LN_PROLOG_AS_LABEL "LASLTP"
399 #define LN_PROLOG_END_LABEL "LELTP"
400 #define DIE_LABEL_PREFIX "DW"
402 /* The DWARF 2 CFA column which tracks the return address. Normally this
403 is the column for PC, or the first column after all of the hard
405 #ifndef DWARF_FRAME_RETURN_COLUMN
407 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
409 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
413 /* The mapping from gcc register number to DWARF 2 CFA column number. By
414 default, we just provide columns for all registers. */
415 #ifndef DWARF_FRAME_REGNUM
416 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
419 /* Hook used by __throw. */
422 expand_builtin_dwarf_sp_column (void)
424 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
425 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
428 /* Return a pointer to a copy of the section string name S with all
429 attributes stripped off, and an asterisk prepended (for assemble_name). */
432 stripattributes (const char *s)
434 char *stripped = XNEWVEC (char, strlen (s) + 2);
439 while (*s && *s != ',')
446 /* MEM is a memory reference for the register size table, each element of
447 which has mode MODE. Initialize column C as a return address column. */
450 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
452 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
453 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
454 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
457 /* Generate code to initialize the register size table. */
460 expand_builtin_init_dwarf_reg_sizes (tree address)
463 enum machine_mode mode = TYPE_MODE (char_type_node);
464 rtx addr = expand_normal (address);
465 rtx mem = gen_rtx_MEM (BLKmode, addr);
466 bool wrote_return_column = false;
468 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
470 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
472 if (rnum < DWARF_FRAME_REGISTERS)
474 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
475 enum machine_mode save_mode = reg_raw_mode[i];
478 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
479 save_mode = choose_hard_reg_mode (i, 1, true);
480 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
482 if (save_mode == VOIDmode)
484 wrote_return_column = true;
486 size = GET_MODE_SIZE (save_mode);
490 emit_move_insn (adjust_address (mem, mode, offset),
491 gen_int_mode (size, mode));
495 if (!wrote_return_column)
496 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
498 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
499 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
502 targetm.init_dwarf_reg_sizes_extra (address);
505 /* Convert a DWARF call frame info. operation to its string name */
508 dwarf_cfi_name (unsigned int cfi_opc)
512 case DW_CFA_advance_loc:
513 return "DW_CFA_advance_loc";
515 return "DW_CFA_offset";
517 return "DW_CFA_restore";
521 return "DW_CFA_set_loc";
522 case DW_CFA_advance_loc1:
523 return "DW_CFA_advance_loc1";
524 case DW_CFA_advance_loc2:
525 return "DW_CFA_advance_loc2";
526 case DW_CFA_advance_loc4:
527 return "DW_CFA_advance_loc4";
528 case DW_CFA_offset_extended:
529 return "DW_CFA_offset_extended";
530 case DW_CFA_restore_extended:
531 return "DW_CFA_restore_extended";
532 case DW_CFA_undefined:
533 return "DW_CFA_undefined";
534 case DW_CFA_same_value:
535 return "DW_CFA_same_value";
536 case DW_CFA_register:
537 return "DW_CFA_register";
538 case DW_CFA_remember_state:
539 return "DW_CFA_remember_state";
540 case DW_CFA_restore_state:
541 return "DW_CFA_restore_state";
543 return "DW_CFA_def_cfa";
544 case DW_CFA_def_cfa_register:
545 return "DW_CFA_def_cfa_register";
546 case DW_CFA_def_cfa_offset:
547 return "DW_CFA_def_cfa_offset";
550 case DW_CFA_def_cfa_expression:
551 return "DW_CFA_def_cfa_expression";
552 case DW_CFA_expression:
553 return "DW_CFA_expression";
554 case DW_CFA_offset_extended_sf:
555 return "DW_CFA_offset_extended_sf";
556 case DW_CFA_def_cfa_sf:
557 return "DW_CFA_def_cfa_sf";
558 case DW_CFA_def_cfa_offset_sf:
559 return "DW_CFA_def_cfa_offset_sf";
561 /* SGI/MIPS specific */
562 case DW_CFA_MIPS_advance_loc8:
563 return "DW_CFA_MIPS_advance_loc8";
566 case DW_CFA_GNU_window_save:
567 return "DW_CFA_GNU_window_save";
568 case DW_CFA_GNU_args_size:
569 return "DW_CFA_GNU_args_size";
570 case DW_CFA_GNU_negative_offset_extended:
571 return "DW_CFA_GNU_negative_offset_extended";
574 return "DW_CFA_<unknown>";
578 /* Return a pointer to a newly allocated Call Frame Instruction. */
580 static inline dw_cfi_ref
583 dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node));
585 cfi->dw_cfi_next = NULL;
586 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
587 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
592 /* Add a Call Frame Instruction to list of instructions. */
595 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
599 /* Find the end of the chain. */
600 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
606 /* Generate a new label for the CFI info to refer to. */
609 dwarf2out_cfi_label (void)
611 static char label[20];
613 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
614 ASM_OUTPUT_LABEL (asm_out_file, label);
618 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
619 or to the CIE if LABEL is NULL. */
622 add_fde_cfi (const char *label, dw_cfi_ref cfi)
626 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
629 label = dwarf2out_cfi_label ();
631 if (fde->dw_fde_current_label == NULL
632 || strcmp (label, fde->dw_fde_current_label) != 0)
636 label = xstrdup (label);
638 /* Set the location counter to the new label. */
640 /* If we have a current label, advance from there, otherwise
641 set the location directly using set_loc. */
642 xcfi->dw_cfi_opc = fde->dw_fde_current_label
643 ? DW_CFA_advance_loc4
645 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
646 add_cfi (&fde->dw_fde_cfi, xcfi);
648 fde->dw_fde_current_label = label;
651 add_cfi (&fde->dw_fde_cfi, cfi);
655 add_cfi (&cie_cfi_head, cfi);
658 /* Subroutine of lookup_cfa. */
661 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
663 switch (cfi->dw_cfi_opc)
665 case DW_CFA_def_cfa_offset:
666 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
668 case DW_CFA_def_cfa_offset_sf:
670 = cfi->dw_cfi_oprnd1.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
672 case DW_CFA_def_cfa_register:
673 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
676 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
677 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
679 case DW_CFA_def_cfa_sf:
680 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
682 = cfi->dw_cfi_oprnd2.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
684 case DW_CFA_def_cfa_expression:
685 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
692 /* Find the previous value for the CFA. */
695 lookup_cfa (dw_cfa_location *loc)
699 loc->reg = INVALID_REGNUM;
702 loc->base_offset = 0;
704 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
705 lookup_cfa_1 (cfi, loc);
707 if (fde_table_in_use)
709 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
710 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
711 lookup_cfa_1 (cfi, loc);
715 /* The current rule for calculating the DWARF2 canonical frame address. */
716 static dw_cfa_location cfa;
718 /* The register used for saving registers to the stack, and its offset
720 static dw_cfa_location cfa_store;
722 /* The running total of the size of arguments pushed onto the stack. */
723 static HOST_WIDE_INT args_size;
725 /* The last args_size we actually output. */
726 static HOST_WIDE_INT old_args_size;
728 /* Entry point to update the canonical frame address (CFA).
729 LABEL is passed to add_fde_cfi. The value of CFA is now to be
730 calculated from REG+OFFSET. */
733 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
740 def_cfa_1 (label, &loc);
743 /* Determine if two dw_cfa_location structures define the same data. */
746 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
748 return (loc1->reg == loc2->reg
749 && loc1->offset == loc2->offset
750 && loc1->indirect == loc2->indirect
751 && (loc1->indirect == 0
752 || loc1->base_offset == loc2->base_offset));
755 /* This routine does the actual work. The CFA is now calculated from
756 the dw_cfa_location structure. */
759 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
762 dw_cfa_location old_cfa, loc;
767 if (cfa_store.reg == loc.reg && loc.indirect == 0)
768 cfa_store.offset = loc.offset;
770 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
771 lookup_cfa (&old_cfa);
773 /* If nothing changed, no need to issue any call frame instructions. */
774 if (cfa_equal_p (&loc, &old_cfa))
779 if (loc.reg == old_cfa.reg && !loc.indirect)
781 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
782 the CFA register did not change but the offset did. */
785 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
786 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
788 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
789 cfi->dw_cfi_oprnd1.dw_cfi_offset = f_offset;
793 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
794 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
798 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
799 else if (loc.offset == old_cfa.offset
800 && old_cfa.reg != INVALID_REGNUM
803 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
804 indicating the CFA register has changed to <register> but the
805 offset has not changed. */
806 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
807 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
811 else if (loc.indirect == 0)
813 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
814 indicating the CFA register has changed to <register> with
815 the specified offset. */
818 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
819 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
821 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
822 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
823 cfi->dw_cfi_oprnd2.dw_cfi_offset = f_offset;
827 cfi->dw_cfi_opc = DW_CFA_def_cfa;
828 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
829 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
834 /* Construct a DW_CFA_def_cfa_expression instruction to
835 calculate the CFA using a full location expression since no
836 register-offset pair is available. */
837 struct dw_loc_descr_struct *loc_list;
839 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
840 loc_list = build_cfa_loc (&loc, 0);
841 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
844 add_fde_cfi (label, cfi);
847 /* Add the CFI for saving a register. REG is the CFA column number.
848 LABEL is passed to add_fde_cfi.
849 If SREG is -1, the register is saved at OFFSET from the CFA;
850 otherwise it is saved in SREG. */
853 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
855 dw_cfi_ref cfi = new_cfi ();
857 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
859 if (sreg == INVALID_REGNUM)
862 /* The register number won't fit in 6 bits, so we have to use
864 cfi->dw_cfi_opc = DW_CFA_offset_extended;
866 cfi->dw_cfi_opc = DW_CFA_offset;
868 #ifdef ENABLE_CHECKING
870 /* If we get an offset that is not a multiple of
871 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
872 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
874 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
876 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
879 offset /= DWARF_CIE_DATA_ALIGNMENT;
881 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
883 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
885 else if (sreg == reg)
886 cfi->dw_cfi_opc = DW_CFA_same_value;
889 cfi->dw_cfi_opc = DW_CFA_register;
890 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
893 add_fde_cfi (label, cfi);
896 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
897 This CFI tells the unwinder that it needs to restore the window registers
898 from the previous frame's window save area.
900 ??? Perhaps we should note in the CIE where windows are saved (instead of
901 assuming 0(cfa)) and what registers are in the window. */
904 dwarf2out_window_save (const char *label)
906 dw_cfi_ref cfi = new_cfi ();
908 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
909 add_fde_cfi (label, cfi);
912 /* Add a CFI to update the running total of the size of arguments
913 pushed onto the stack. */
916 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
920 if (size == old_args_size)
923 old_args_size = size;
926 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
927 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
928 add_fde_cfi (label, cfi);
931 /* Entry point for saving a register to the stack. REG is the GCC register
932 number. LABEL and OFFSET are passed to reg_save. */
935 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
937 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
940 /* Entry point for saving the return address in the stack.
941 LABEL and OFFSET are passed to reg_save. */
944 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
946 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
949 /* Entry point for saving the return address in a register.
950 LABEL and SREG are passed to reg_save. */
953 dwarf2out_return_reg (const char *label, unsigned int sreg)
955 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
958 /* Record the initial position of the return address. RTL is
959 INCOMING_RETURN_ADDR_RTX. */
962 initial_return_save (rtx rtl)
964 unsigned int reg = INVALID_REGNUM;
965 HOST_WIDE_INT offset = 0;
967 switch (GET_CODE (rtl))
970 /* RA is in a register. */
971 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
975 /* RA is on the stack. */
977 switch (GET_CODE (rtl))
980 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
985 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
986 offset = INTVAL (XEXP (rtl, 1));
990 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
991 offset = -INTVAL (XEXP (rtl, 1));
1001 /* The return address is at some offset from any value we can
1002 actually load. For instance, on the SPARC it is in %i7+8. Just
1003 ignore the offset for now; it doesn't matter for unwinding frames. */
1004 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1005 initial_return_save (XEXP (rtl, 0));
1012 if (reg != DWARF_FRAME_RETURN_COLUMN)
1013 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1016 /* Given a SET, calculate the amount of stack adjustment it
1019 static HOST_WIDE_INT
1020 stack_adjust_offset (rtx pattern)
1022 rtx src = SET_SRC (pattern);
1023 rtx dest = SET_DEST (pattern);
1024 HOST_WIDE_INT offset = 0;
1027 if (dest == stack_pointer_rtx)
1029 /* (set (reg sp) (plus (reg sp) (const_int))) */
1030 code = GET_CODE (src);
1031 if (! (code == PLUS || code == MINUS)
1032 || XEXP (src, 0) != stack_pointer_rtx
1033 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1036 offset = INTVAL (XEXP (src, 1));
1040 else if (MEM_P (dest))
1042 /* (set (mem (pre_dec (reg sp))) (foo)) */
1043 src = XEXP (dest, 0);
1044 code = GET_CODE (src);
1050 if (XEXP (src, 0) == stack_pointer_rtx)
1052 rtx val = XEXP (XEXP (src, 1), 1);
1053 /* We handle only adjustments by constant amount. */
1054 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1055 && GET_CODE (val) == CONST_INT);
1056 offset = -INTVAL (val);
1063 if (XEXP (src, 0) == stack_pointer_rtx)
1065 offset = GET_MODE_SIZE (GET_MODE (dest));
1072 if (XEXP (src, 0) == stack_pointer_rtx)
1074 offset = -GET_MODE_SIZE (GET_MODE (dest));
1089 /* Check INSN to see if it looks like a push or a stack adjustment, and
1090 make a note of it if it does. EH uses this information to find out how
1091 much extra space it needs to pop off the stack. */
1094 dwarf2out_stack_adjust (rtx insn, bool after_p)
1096 HOST_WIDE_INT offset;
1100 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1101 with this function. Proper support would require all frame-related
1102 insns to be marked, and to be able to handle saving state around
1103 epilogues textually in the middle of the function. */
1104 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1107 /* If only calls can throw, and we have a frame pointer,
1108 save up adjustments until we see the CALL_INSN. */
1109 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1111 if (CALL_P (insn) && !after_p)
1113 /* Extract the size of the args from the CALL rtx itself. */
1114 insn = PATTERN (insn);
1115 if (GET_CODE (insn) == PARALLEL)
1116 insn = XVECEXP (insn, 0, 0);
1117 if (GET_CODE (insn) == SET)
1118 insn = SET_SRC (insn);
1119 gcc_assert (GET_CODE (insn) == CALL);
1120 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1125 if (CALL_P (insn) && !after_p)
1127 if (!flag_asynchronous_unwind_tables)
1128 dwarf2out_args_size ("", args_size);
1131 else if (BARRIER_P (insn))
1133 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1134 the compiler will have already emitted a stack adjustment, but
1135 doesn't bother for calls to noreturn functions. */
1136 #ifdef STACK_GROWS_DOWNWARD
1137 offset = -args_size;
1142 else if (GET_CODE (PATTERN (insn)) == SET)
1143 offset = stack_adjust_offset (PATTERN (insn));
1144 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1145 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1147 /* There may be stack adjustments inside compound insns. Search
1149 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1150 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1151 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1159 if (cfa.reg == STACK_POINTER_REGNUM)
1160 cfa.offset += offset;
1162 #ifndef STACK_GROWS_DOWNWARD
1166 args_size += offset;
1170 label = dwarf2out_cfi_label ();
1171 def_cfa_1 (label, &cfa);
1172 if (flag_asynchronous_unwind_tables)
1173 dwarf2out_args_size (label, args_size);
1178 /* We delay emitting a register save until either (a) we reach the end
1179 of the prologue or (b) the register is clobbered. This clusters
1180 register saves so that there are fewer pc advances. */
1182 struct queued_reg_save GTY(())
1184 struct queued_reg_save *next;
1186 HOST_WIDE_INT cfa_offset;
1190 static GTY(()) struct queued_reg_save *queued_reg_saves;
1192 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1193 struct reg_saved_in_data GTY(()) {
1198 /* A list of registers saved in other registers.
1199 The list intentionally has a small maximum capacity of 4; if your
1200 port needs more than that, you might consider implementing a
1201 more efficient data structure. */
1202 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1203 static GTY(()) size_t num_regs_saved_in_regs;
1205 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1206 static const char *last_reg_save_label;
1208 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1209 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1212 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1214 struct queued_reg_save *q;
1216 /* Duplicates waste space, but it's also necessary to remove them
1217 for correctness, since the queue gets output in reverse
1219 for (q = queued_reg_saves; q != NULL; q = q->next)
1220 if (REGNO (q->reg) == REGNO (reg))
1225 q = ggc_alloc (sizeof (*q));
1226 q->next = queued_reg_saves;
1227 queued_reg_saves = q;
1231 q->cfa_offset = offset;
1232 q->saved_reg = sreg;
1234 last_reg_save_label = label;
1237 /* Output all the entries in QUEUED_REG_SAVES. */
1240 flush_queued_reg_saves (void)
1242 struct queued_reg_save *q;
1244 for (q = queued_reg_saves; q; q = q->next)
1247 unsigned int reg, sreg;
1249 for (i = 0; i < num_regs_saved_in_regs; i++)
1250 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1252 if (q->saved_reg && i == num_regs_saved_in_regs)
1254 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1255 num_regs_saved_in_regs++;
1257 if (i != num_regs_saved_in_regs)
1259 regs_saved_in_regs[i].orig_reg = q->reg;
1260 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1263 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1265 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1267 sreg = INVALID_REGNUM;
1268 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1271 queued_reg_saves = NULL;
1272 last_reg_save_label = NULL;
1275 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1276 location for? Or, does it clobber a register which we've previously
1277 said that some other register is saved in, and for which we now
1278 have a new location for? */
1281 clobbers_queued_reg_save (rtx insn)
1283 struct queued_reg_save *q;
1285 for (q = queued_reg_saves; q; q = q->next)
1288 if (modified_in_p (q->reg, insn))
1290 for (i = 0; i < num_regs_saved_in_regs; i++)
1291 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1292 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1299 /* Entry point for saving the first register into the second. */
1302 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1305 unsigned int regno, sregno;
1307 for (i = 0; i < num_regs_saved_in_regs; i++)
1308 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1310 if (i == num_regs_saved_in_regs)
1312 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1313 num_regs_saved_in_regs++;
1315 regs_saved_in_regs[i].orig_reg = reg;
1316 regs_saved_in_regs[i].saved_in_reg = sreg;
1318 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1319 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1320 reg_save (label, regno, sregno, 0);
1323 /* What register, if any, is currently saved in REG? */
1326 reg_saved_in (rtx reg)
1328 unsigned int regn = REGNO (reg);
1330 struct queued_reg_save *q;
1332 for (q = queued_reg_saves; q; q = q->next)
1333 if (q->saved_reg && regn == REGNO (q->saved_reg))
1336 for (i = 0; i < num_regs_saved_in_regs; i++)
1337 if (regs_saved_in_regs[i].saved_in_reg
1338 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1339 return regs_saved_in_regs[i].orig_reg;
1345 /* A temporary register holding an integral value used in adjusting SP
1346 or setting up the store_reg. The "offset" field holds the integer
1347 value, not an offset. */
1348 static dw_cfa_location cfa_temp;
1350 /* Record call frame debugging information for an expression EXPR,
1351 which either sets SP or FP (adjusting how we calculate the frame
1352 address) or saves a register to the stack or another register.
1353 LABEL indicates the address of EXPR.
1355 This function encodes a state machine mapping rtxes to actions on
1356 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1357 users need not read the source code.
1359 The High-Level Picture
1361 Changes in the register we use to calculate the CFA: Currently we
1362 assume that if you copy the CFA register into another register, we
1363 should take the other one as the new CFA register; this seems to
1364 work pretty well. If it's wrong for some target, it's simple
1365 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1367 Changes in the register we use for saving registers to the stack:
1368 This is usually SP, but not always. Again, we deduce that if you
1369 copy SP into another register (and SP is not the CFA register),
1370 then the new register is the one we will be using for register
1371 saves. This also seems to work.
1373 Register saves: There's not much guesswork about this one; if
1374 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1375 register save, and the register used to calculate the destination
1376 had better be the one we think we're using for this purpose.
1377 It's also assumed that a copy from a call-saved register to another
1378 register is saving that register if RTX_FRAME_RELATED_P is set on
1379 that instruction. If the copy is from a call-saved register to
1380 the *same* register, that means that the register is now the same
1381 value as in the caller.
1383 Except: If the register being saved is the CFA register, and the
1384 offset is nonzero, we are saving the CFA, so we assume we have to
1385 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1386 the intent is to save the value of SP from the previous frame.
1388 In addition, if a register has previously been saved to a different
1391 Invariants / Summaries of Rules
1393 cfa current rule for calculating the CFA. It usually
1394 consists of a register and an offset.
1395 cfa_store register used by prologue code to save things to the stack
1396 cfa_store.offset is the offset from the value of
1397 cfa_store.reg to the actual CFA
1398 cfa_temp register holding an integral value. cfa_temp.offset
1399 stores the value, which will be used to adjust the
1400 stack pointer. cfa_temp is also used like cfa_store,
1401 to track stores to the stack via fp or a temp reg.
1403 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1404 with cfa.reg as the first operand changes the cfa.reg and its
1405 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1408 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1409 expression yielding a constant. This sets cfa_temp.reg
1410 and cfa_temp.offset.
1412 Rule 5: Create a new register cfa_store used to save items to the
1415 Rules 10-14: Save a register to the stack. Define offset as the
1416 difference of the original location and cfa_store's
1417 location (or cfa_temp's location if cfa_temp is used).
1421 "{a,b}" indicates a choice of a xor b.
1422 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1425 (set <reg1> <reg2>:cfa.reg)
1426 effects: cfa.reg = <reg1>
1427 cfa.offset unchanged
1428 cfa_temp.reg = <reg1>
1429 cfa_temp.offset = cfa.offset
1432 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1433 {<const_int>,<reg>:cfa_temp.reg}))
1434 effects: cfa.reg = sp if fp used
1435 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1436 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1437 if cfa_store.reg==sp
1440 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1441 effects: cfa.reg = fp
1442 cfa_offset += +/- <const_int>
1445 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1446 constraints: <reg1> != fp
1448 effects: cfa.reg = <reg1>
1449 cfa_temp.reg = <reg1>
1450 cfa_temp.offset = cfa.offset
1453 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1454 constraints: <reg1> != fp
1456 effects: cfa_store.reg = <reg1>
1457 cfa_store.offset = cfa.offset - cfa_temp.offset
1460 (set <reg> <const_int>)
1461 effects: cfa_temp.reg = <reg>
1462 cfa_temp.offset = <const_int>
1465 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1466 effects: cfa_temp.reg = <reg1>
1467 cfa_temp.offset |= <const_int>
1470 (set <reg> (high <exp>))
1474 (set <reg> (lo_sum <exp> <const_int>))
1475 effects: cfa_temp.reg = <reg>
1476 cfa_temp.offset = <const_int>
1479 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1480 effects: cfa_store.offset -= <const_int>
1481 cfa.offset = cfa_store.offset if cfa.reg == sp
1483 cfa.base_offset = -cfa_store.offset
1486 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1487 effects: cfa_store.offset += -/+ mode_size(mem)
1488 cfa.offset = cfa_store.offset if cfa.reg == sp
1490 cfa.base_offset = -cfa_store.offset
1493 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1496 effects: cfa.reg = <reg1>
1497 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1500 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1501 effects: cfa.reg = <reg1>
1502 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1505 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1506 effects: cfa.reg = <reg1>
1507 cfa.base_offset = -cfa_temp.offset
1508 cfa_temp.offset -= mode_size(mem)
1511 (set <reg> {unspec, unspec_volatile})
1512 effects: target-dependent */
1515 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1518 HOST_WIDE_INT offset;
1520 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1521 the PARALLEL independently. The first element is always processed if
1522 it is a SET. This is for backward compatibility. Other elements
1523 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1524 flag is set in them. */
1525 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1528 int limit = XVECLEN (expr, 0);
1531 /* PARALLELs have strict read-modify-write semantics, so we
1532 ought to evaluate every rvalue before changing any lvalue.
1533 It's cumbersome to do that in general, but there's an
1534 easy approximation that is enough for all current users:
1535 handle register saves before register assignments. */
1536 if (GET_CODE (expr) == PARALLEL)
1537 for (par_index = 0; par_index < limit; par_index++)
1539 elem = XVECEXP (expr, 0, par_index);
1540 if (GET_CODE (elem) == SET
1541 && MEM_P (SET_DEST (elem))
1542 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1543 dwarf2out_frame_debug_expr (elem, label);
1546 for (par_index = 0; par_index < limit; par_index++)
1548 elem = XVECEXP (expr, 0, par_index);
1549 if (GET_CODE (elem) == SET
1550 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
1551 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1552 dwarf2out_frame_debug_expr (elem, label);
1557 gcc_assert (GET_CODE (expr) == SET);
1559 src = SET_SRC (expr);
1560 dest = SET_DEST (expr);
1564 rtx rsi = reg_saved_in (src);
1569 switch (GET_CODE (dest))
1572 switch (GET_CODE (src))
1574 /* Setting FP from SP. */
1576 if (cfa.reg == (unsigned) REGNO (src))
1579 /* Update the CFA rule wrt SP or FP. Make sure src is
1580 relative to the current CFA register.
1582 We used to require that dest be either SP or FP, but the
1583 ARM copies SP to a temporary register, and from there to
1584 FP. So we just rely on the backends to only set
1585 RTX_FRAME_RELATED_P on appropriate insns. */
1586 cfa.reg = REGNO (dest);
1587 cfa_temp.reg = cfa.reg;
1588 cfa_temp.offset = cfa.offset;
1592 /* Saving a register in a register. */
1593 gcc_assert (!fixed_regs [REGNO (dest)]
1594 /* For the SPARC and its register window. */
1595 || (DWARF_FRAME_REGNUM (REGNO (src))
1596 == DWARF_FRAME_RETURN_COLUMN));
1597 queue_reg_save (label, src, dest, 0);
1604 if (dest == stack_pointer_rtx)
1608 switch (GET_CODE (XEXP (src, 1)))
1611 offset = INTVAL (XEXP (src, 1));
1614 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1616 offset = cfa_temp.offset;
1622 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1624 /* Restoring SP from FP in the epilogue. */
1625 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1626 cfa.reg = STACK_POINTER_REGNUM;
1628 else if (GET_CODE (src) == LO_SUM)
1629 /* Assume we've set the source reg of the LO_SUM from sp. */
1632 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1634 if (GET_CODE (src) != MINUS)
1636 if (cfa.reg == STACK_POINTER_REGNUM)
1637 cfa.offset += offset;
1638 if (cfa_store.reg == STACK_POINTER_REGNUM)
1639 cfa_store.offset += offset;
1641 else if (dest == hard_frame_pointer_rtx)
1644 /* Either setting the FP from an offset of the SP,
1645 or adjusting the FP */
1646 gcc_assert (frame_pointer_needed);
1648 gcc_assert (REG_P (XEXP (src, 0))
1649 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1650 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1651 offset = INTVAL (XEXP (src, 1));
1652 if (GET_CODE (src) != MINUS)
1654 cfa.offset += offset;
1655 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1659 gcc_assert (GET_CODE (src) != MINUS);
1662 if (REG_P (XEXP (src, 0))
1663 && REGNO (XEXP (src, 0)) == cfa.reg
1664 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1666 /* Setting a temporary CFA register that will be copied
1667 into the FP later on. */
1668 offset = - INTVAL (XEXP (src, 1));
1669 cfa.offset += offset;
1670 cfa.reg = REGNO (dest);
1671 /* Or used to save regs to the stack. */
1672 cfa_temp.reg = cfa.reg;
1673 cfa_temp.offset = cfa.offset;
1677 else if (REG_P (XEXP (src, 0))
1678 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1679 && XEXP (src, 1) == stack_pointer_rtx)
1681 /* Setting a scratch register that we will use instead
1682 of SP for saving registers to the stack. */
1683 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
1684 cfa_store.reg = REGNO (dest);
1685 cfa_store.offset = cfa.offset - cfa_temp.offset;
1689 else if (GET_CODE (src) == LO_SUM
1690 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1692 cfa_temp.reg = REGNO (dest);
1693 cfa_temp.offset = INTVAL (XEXP (src, 1));
1702 cfa_temp.reg = REGNO (dest);
1703 cfa_temp.offset = INTVAL (src);
1708 gcc_assert (REG_P (XEXP (src, 0))
1709 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
1710 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1712 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1713 cfa_temp.reg = REGNO (dest);
1714 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1717 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1718 which will fill in all of the bits. */
1725 case UNSPEC_VOLATILE:
1726 gcc_assert (targetm.dwarf_handle_frame_unspec);
1727 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
1734 def_cfa_1 (label, &cfa);
1738 gcc_assert (REG_P (src));
1740 /* Saving a register to the stack. Make sure dest is relative to the
1742 switch (GET_CODE (XEXP (dest, 0)))
1747 /* We can't handle variable size modifications. */
1748 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
1750 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1752 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1753 && cfa_store.reg == STACK_POINTER_REGNUM);
1755 cfa_store.offset += offset;
1756 if (cfa.reg == STACK_POINTER_REGNUM)
1757 cfa.offset = cfa_store.offset;
1759 offset = -cfa_store.offset;
1765 offset = GET_MODE_SIZE (GET_MODE (dest));
1766 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1769 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1770 && cfa_store.reg == STACK_POINTER_REGNUM);
1772 cfa_store.offset += offset;
1773 if (cfa.reg == STACK_POINTER_REGNUM)
1774 cfa.offset = cfa_store.offset;
1776 offset = -cfa_store.offset;
1780 /* With an offset. */
1787 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
1788 && REG_P (XEXP (XEXP (dest, 0), 0)));
1789 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1790 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1793 regno = REGNO (XEXP (XEXP (dest, 0), 0));
1795 if (cfa_store.reg == (unsigned) regno)
1796 offset -= cfa_store.offset;
1799 gcc_assert (cfa_temp.reg == (unsigned) regno);
1800 offset -= cfa_temp.offset;
1806 /* Without an offset. */
1809 int regno = REGNO (XEXP (dest, 0));
1811 if (cfa_store.reg == (unsigned) regno)
1812 offset = -cfa_store.offset;
1815 gcc_assert (cfa_temp.reg == (unsigned) regno);
1816 offset = -cfa_temp.offset;
1823 gcc_assert (cfa_temp.reg
1824 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
1825 offset = -cfa_temp.offset;
1826 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1833 if (REGNO (src) != STACK_POINTER_REGNUM
1834 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1835 && (unsigned) REGNO (src) == cfa.reg)
1837 /* We're storing the current CFA reg into the stack. */
1839 if (cfa.offset == 0)
1841 /* If the source register is exactly the CFA, assume
1842 we're saving SP like any other register; this happens
1844 def_cfa_1 (label, &cfa);
1845 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
1850 /* Otherwise, we'll need to look in the stack to
1851 calculate the CFA. */
1852 rtx x = XEXP (dest, 0);
1856 gcc_assert (REG_P (x));
1858 cfa.reg = REGNO (x);
1859 cfa.base_offset = offset;
1861 def_cfa_1 (label, &cfa);
1866 def_cfa_1 (label, &cfa);
1867 queue_reg_save (label, src, NULL_RTX, offset);
1875 /* Record call frame debugging information for INSN, which either
1876 sets SP or FP (adjusting how we calculate the frame address) or saves a
1877 register to the stack. If INSN is NULL_RTX, initialize our state.
1879 If AFTER_P is false, we're being called before the insn is emitted,
1880 otherwise after. Call instructions get invoked twice. */
1883 dwarf2out_frame_debug (rtx insn, bool after_p)
1888 if (insn == NULL_RTX)
1892 /* Flush any queued register saves. */
1893 flush_queued_reg_saves ();
1895 /* Set up state for generating call frame debug info. */
1898 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1900 cfa.reg = STACK_POINTER_REGNUM;
1903 cfa_temp.offset = 0;
1905 for (i = 0; i < num_regs_saved_in_regs; i++)
1907 regs_saved_in_regs[i].orig_reg = NULL_RTX;
1908 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
1910 num_regs_saved_in_regs = 0;
1914 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
1915 flush_queued_reg_saves ();
1917 if (! RTX_FRAME_RELATED_P (insn))
1919 if (!ACCUMULATE_OUTGOING_ARGS)
1920 dwarf2out_stack_adjust (insn, after_p);
1924 label = dwarf2out_cfi_label ();
1925 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1927 insn = XEXP (src, 0);
1929 insn = PATTERN (insn);
1931 dwarf2out_frame_debug_expr (insn, label);
1936 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1937 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1938 (enum dwarf_call_frame_info cfi);
1940 static enum dw_cfi_oprnd_type
1941 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1946 case DW_CFA_GNU_window_save:
1947 return dw_cfi_oprnd_unused;
1949 case DW_CFA_set_loc:
1950 case DW_CFA_advance_loc1:
1951 case DW_CFA_advance_loc2:
1952 case DW_CFA_advance_loc4:
1953 case DW_CFA_MIPS_advance_loc8:
1954 return dw_cfi_oprnd_addr;
1957 case DW_CFA_offset_extended:
1958 case DW_CFA_def_cfa:
1959 case DW_CFA_offset_extended_sf:
1960 case DW_CFA_def_cfa_sf:
1961 case DW_CFA_restore_extended:
1962 case DW_CFA_undefined:
1963 case DW_CFA_same_value:
1964 case DW_CFA_def_cfa_register:
1965 case DW_CFA_register:
1966 return dw_cfi_oprnd_reg_num;
1968 case DW_CFA_def_cfa_offset:
1969 case DW_CFA_GNU_args_size:
1970 case DW_CFA_def_cfa_offset_sf:
1971 return dw_cfi_oprnd_offset;
1973 case DW_CFA_def_cfa_expression:
1974 case DW_CFA_expression:
1975 return dw_cfi_oprnd_loc;
1982 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1983 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1984 (enum dwarf_call_frame_info cfi);
1986 static enum dw_cfi_oprnd_type
1987 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1991 case DW_CFA_def_cfa:
1992 case DW_CFA_def_cfa_sf:
1994 case DW_CFA_offset_extended_sf:
1995 case DW_CFA_offset_extended:
1996 return dw_cfi_oprnd_offset;
1998 case DW_CFA_register:
1999 return dw_cfi_oprnd_reg_num;
2002 return dw_cfi_oprnd_unused;
2006 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2008 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2009 switch to the data section instead, and write out a synthetic label
2013 switch_to_eh_frame_section (void)
2017 #ifdef EH_FRAME_SECTION_NAME
2018 if (eh_frame_section == 0)
2022 if (EH_TABLES_CAN_BE_READ_ONLY)
2028 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2030 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2032 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2034 flags = ((! flag_pic
2035 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2036 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2037 && (per_encoding & 0x70) != DW_EH_PE_absptr
2038 && (per_encoding & 0x70) != DW_EH_PE_aligned
2039 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2040 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2041 ? 0 : SECTION_WRITE);
2044 flags = SECTION_WRITE;
2045 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2049 if (eh_frame_section)
2050 switch_to_section (eh_frame_section);
2053 /* We have no special eh_frame section. Put the information in
2054 the data section and emit special labels to guide collect2. */
2055 switch_to_section (data_section);
2056 label = get_file_function_name ("F");
2057 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2058 targetm.asm_out.globalize_label (asm_out_file,
2059 IDENTIFIER_POINTER (label));
2060 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2064 /* Output a Call Frame Information opcode and its operand(s). */
2067 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2070 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2071 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2072 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2073 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2074 cfi->dw_cfi_oprnd1.dw_cfi_offset);
2075 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2077 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2078 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2079 "DW_CFA_offset, column 0x%lx", r);
2080 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2082 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2084 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2085 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2086 "DW_CFA_restore, column 0x%lx", r);
2090 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2091 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2093 switch (cfi->dw_cfi_opc)
2095 case DW_CFA_set_loc:
2097 dw2_asm_output_encoded_addr_rtx (
2098 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2099 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2102 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2103 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2104 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2107 case DW_CFA_advance_loc1:
2108 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2109 fde->dw_fde_current_label, NULL);
2110 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2113 case DW_CFA_advance_loc2:
2114 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2115 fde->dw_fde_current_label, NULL);
2116 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2119 case DW_CFA_advance_loc4:
2120 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2121 fde->dw_fde_current_label, NULL);
2122 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2125 case DW_CFA_MIPS_advance_loc8:
2126 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2127 fde->dw_fde_current_label, NULL);
2128 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2131 case DW_CFA_offset_extended:
2132 case DW_CFA_def_cfa:
2133 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2134 dw2_asm_output_data_uleb128 (r, NULL);
2135 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2138 case DW_CFA_offset_extended_sf:
2139 case DW_CFA_def_cfa_sf:
2140 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2141 dw2_asm_output_data_uleb128 (r, NULL);
2142 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2145 case DW_CFA_restore_extended:
2146 case DW_CFA_undefined:
2147 case DW_CFA_same_value:
2148 case DW_CFA_def_cfa_register:
2149 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2150 dw2_asm_output_data_uleb128 (r, NULL);
2153 case DW_CFA_register:
2154 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2155 dw2_asm_output_data_uleb128 (r, NULL);
2156 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2157 dw2_asm_output_data_uleb128 (r, NULL);
2160 case DW_CFA_def_cfa_offset:
2161 case DW_CFA_GNU_args_size:
2162 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2165 case DW_CFA_def_cfa_offset_sf:
2166 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2169 case DW_CFA_GNU_window_save:
2172 case DW_CFA_def_cfa_expression:
2173 case DW_CFA_expression:
2174 output_cfa_loc (cfi);
2177 case DW_CFA_GNU_negative_offset_extended:
2178 /* Obsoleted by DW_CFA_offset_extended_sf. */
2187 /* Output the call frame information used to record information
2188 that relates to calculating the frame pointer, and records the
2189 location of saved registers. */
2192 output_call_frame_info (int for_eh)
2197 char l1[20], l2[20], section_start_label[20];
2198 bool any_lsda_needed = false;
2199 char augmentation[6];
2200 int augmentation_size;
2201 int fde_encoding = DW_EH_PE_absptr;
2202 int per_encoding = DW_EH_PE_absptr;
2203 int lsda_encoding = DW_EH_PE_absptr;
2206 /* Don't emit a CIE if there won't be any FDEs. */
2207 if (fde_table_in_use == 0)
2210 /* If we make FDEs linkonce, we may have to emit an empty label for
2211 an FDE that wouldn't otherwise be emitted. We want to avoid
2212 having an FDE kept around when the function it refers to is
2213 discarded. Example where this matters: a primary function
2214 template in C++ requires EH information, but an explicit
2215 specialization doesn't. */
2216 if (TARGET_USES_WEAK_UNWIND_INFO
2217 && ! flag_asynchronous_unwind_tables
2219 for (i = 0; i < fde_table_in_use; i++)
2220 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2221 && !fde_table[i].uses_eh_lsda
2222 && ! DECL_WEAK (fde_table[i].decl))
2223 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2224 for_eh, /* empty */ 1);
2226 /* If we don't have any functions we'll want to unwind out of, don't
2227 emit any EH unwind information. Note that if exceptions aren't
2228 enabled, we won't have collected nothrow information, and if we
2229 asked for asynchronous tables, we always want this info. */
2232 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2234 for (i = 0; i < fde_table_in_use; i++)
2235 if (fde_table[i].uses_eh_lsda)
2236 any_eh_needed = any_lsda_needed = true;
2237 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2238 any_eh_needed = true;
2239 else if (! fde_table[i].nothrow
2240 && ! fde_table[i].all_throwers_are_sibcalls)
2241 any_eh_needed = true;
2243 if (! any_eh_needed)
2247 /* We're going to be generating comments, so turn on app. */
2252 switch_to_eh_frame_section ();
2255 if (!debug_frame_section)
2256 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
2257 SECTION_DEBUG, NULL);
2258 switch_to_section (debug_frame_section);
2261 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2262 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2264 /* Output the CIE. */
2265 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2266 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2267 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2268 dw2_asm_output_data (4, 0xffffffff,
2269 "Initial length escape value indicating 64-bit DWARF extension");
2270 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2271 "Length of Common Information Entry");
2272 ASM_OUTPUT_LABEL (asm_out_file, l1);
2274 /* Now that the CIE pointer is PC-relative for EH,
2275 use 0 to identify the CIE. */
2276 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2277 (for_eh ? 0 : DWARF_CIE_ID),
2278 "CIE Identifier Tag");
2280 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2282 augmentation[0] = 0;
2283 augmentation_size = 0;
2289 z Indicates that a uleb128 is present to size the
2290 augmentation section.
2291 L Indicates the encoding (and thus presence) of
2292 an LSDA pointer in the FDE augmentation.
2293 R Indicates a non-default pointer encoding for
2295 P Indicates the presence of an encoding + language
2296 personality routine in the CIE augmentation. */
2298 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2299 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2300 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2302 p = augmentation + 1;
2303 if (eh_personality_libfunc)
2306 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2307 assemble_external_libcall (eh_personality_libfunc);
2309 if (any_lsda_needed)
2312 augmentation_size += 1;
2314 if (fde_encoding != DW_EH_PE_absptr)
2317 augmentation_size += 1;
2319 if (p > augmentation + 1)
2321 augmentation[0] = 'z';
2325 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2326 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2328 int offset = ( 4 /* Length */
2330 + 1 /* CIE version */
2331 + strlen (augmentation) + 1 /* Augmentation */
2332 + size_of_uleb128 (1) /* Code alignment */
2333 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2335 + 1 /* Augmentation size */
2336 + 1 /* Personality encoding */ );
2337 int pad = -offset & (PTR_SIZE - 1);
2339 augmentation_size += pad;
2341 /* Augmentations should be small, so there's scarce need to
2342 iterate for a solution. Die if we exceed one uleb128 byte. */
2343 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2347 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2348 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2349 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2350 "CIE Data Alignment Factor");
2352 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2353 if (DW_CIE_VERSION == 1)
2354 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2356 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2358 if (augmentation[0])
2360 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2361 if (eh_personality_libfunc)
2363 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2364 eh_data_format_name (per_encoding));
2365 dw2_asm_output_encoded_addr_rtx (per_encoding,
2366 eh_personality_libfunc,
2370 if (any_lsda_needed)
2371 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2372 eh_data_format_name (lsda_encoding));
2374 if (fde_encoding != DW_EH_PE_absptr)
2375 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2376 eh_data_format_name (fde_encoding));
2379 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2380 output_cfi (cfi, NULL, for_eh);
2382 /* Pad the CIE out to an address sized boundary. */
2383 ASM_OUTPUT_ALIGN (asm_out_file,
2384 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2385 ASM_OUTPUT_LABEL (asm_out_file, l2);
2387 /* Loop through all of the FDE's. */
2388 for (i = 0; i < fde_table_in_use; i++)
2390 fde = &fde_table[i];
2392 /* Don't emit EH unwind info for leaf functions that don't need it. */
2393 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2394 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2395 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2396 && !fde->uses_eh_lsda)
2399 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2400 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2401 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2402 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2403 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2404 dw2_asm_output_data (4, 0xffffffff,
2405 "Initial length escape value indicating 64-bit DWARF extension");
2406 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2408 ASM_OUTPUT_LABEL (asm_out_file, l1);
2411 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2413 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2414 debug_frame_section, "FDE CIE offset");
2418 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2419 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2420 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2423 "FDE initial location");
2424 if (fde->dw_fde_switched_sections)
2426 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2427 fde->dw_fde_unlikely_section_label);
2428 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2429 fde->dw_fde_hot_section_label);
2430 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2431 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2432 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
2433 "FDE initial location");
2434 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2435 fde->dw_fde_hot_section_end_label,
2436 fde->dw_fde_hot_section_label,
2437 "FDE address range");
2438 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
2439 "FDE initial location");
2440 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2441 fde->dw_fde_unlikely_section_end_label,
2442 fde->dw_fde_unlikely_section_label,
2443 "FDE address range");
2446 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2447 fde->dw_fde_end, fde->dw_fde_begin,
2448 "FDE address range");
2452 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2453 "FDE initial location");
2454 if (fde->dw_fde_switched_sections)
2456 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2457 fde->dw_fde_hot_section_label,
2458 "FDE initial location");
2459 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2460 fde->dw_fde_hot_section_end_label,
2461 fde->dw_fde_hot_section_label,
2462 "FDE address range");
2463 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2464 fde->dw_fde_unlikely_section_label,
2465 "FDE initial location");
2466 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2467 fde->dw_fde_unlikely_section_end_label,
2468 fde->dw_fde_unlikely_section_label,
2469 "FDE address range");
2472 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2473 fde->dw_fde_end, fde->dw_fde_begin,
2474 "FDE address range");
2477 if (augmentation[0])
2479 if (any_lsda_needed)
2481 int size = size_of_encoded_value (lsda_encoding);
2483 if (lsda_encoding == DW_EH_PE_aligned)
2485 int offset = ( 4 /* Length */
2486 + 4 /* CIE offset */
2487 + 2 * size_of_encoded_value (fde_encoding)
2488 + 1 /* Augmentation size */ );
2489 int pad = -offset & (PTR_SIZE - 1);
2492 gcc_assert (size_of_uleb128 (size) == 1);
2495 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2497 if (fde->uses_eh_lsda)
2499 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2500 fde->funcdef_number);
2501 dw2_asm_output_encoded_addr_rtx (
2502 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2503 false, "Language Specific Data Area");
2507 if (lsda_encoding == DW_EH_PE_aligned)
2508 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2510 (size_of_encoded_value (lsda_encoding), 0,
2511 "Language Specific Data Area (none)");
2515 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2518 /* Loop through the Call Frame Instructions associated with
2520 fde->dw_fde_current_label = fde->dw_fde_begin;
2521 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2522 output_cfi (cfi, fde, for_eh);
2524 /* Pad the FDE out to an address sized boundary. */
2525 ASM_OUTPUT_ALIGN (asm_out_file,
2526 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2527 ASM_OUTPUT_LABEL (asm_out_file, l2);
2530 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2531 dw2_asm_output_data (4, 0, "End of Table");
2532 #ifdef MIPS_DEBUGGING_INFO
2533 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2534 get a value of 0. Putting .align 0 after the label fixes it. */
2535 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2538 /* Turn off app to make assembly quicker. */
2543 /* Output a marker (i.e. a label) for the beginning of a function, before
2547 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2548 const char *file ATTRIBUTE_UNUSED)
2550 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2554 current_function_func_begin_label = NULL;
2556 #ifdef TARGET_UNWIND_INFO
2557 /* ??? current_function_func_begin_label is also used by except.c
2558 for call-site information. We must emit this label if it might
2560 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2561 && ! dwarf2out_do_frame ())
2564 if (! dwarf2out_do_frame ())
2568 switch_to_section (function_section (current_function_decl));
2569 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2570 current_function_funcdef_no);
2571 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2572 current_function_funcdef_no);
2573 dup_label = xstrdup (label);
2574 current_function_func_begin_label = dup_label;
2576 #ifdef TARGET_UNWIND_INFO
2577 /* We can elide the fde allocation if we're not emitting debug info. */
2578 if (! dwarf2out_do_frame ())
2582 /* Expand the fde table if necessary. */
2583 if (fde_table_in_use == fde_table_allocated)
2585 fde_table_allocated += FDE_TABLE_INCREMENT;
2586 fde_table = ggc_realloc (fde_table,
2587 fde_table_allocated * sizeof (dw_fde_node));
2588 memset (fde_table + fde_table_in_use, 0,
2589 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2592 /* Record the FDE associated with this function. */
2593 current_funcdef_fde = fde_table_in_use;
2595 /* Add the new FDE at the end of the fde_table. */
2596 fde = &fde_table[fde_table_in_use++];
2597 fde->decl = current_function_decl;
2598 fde->dw_fde_begin = dup_label;
2599 fde->dw_fde_current_label = dup_label;
2600 fde->dw_fde_hot_section_label = NULL;
2601 fde->dw_fde_hot_section_end_label = NULL;
2602 fde->dw_fde_unlikely_section_label = NULL;
2603 fde->dw_fde_unlikely_section_end_label = NULL;
2604 fde->dw_fde_switched_sections = false;
2605 fde->dw_fde_end = NULL;
2606 fde->dw_fde_cfi = NULL;
2607 fde->funcdef_number = current_function_funcdef_no;
2608 fde->nothrow = TREE_NOTHROW (current_function_decl);
2609 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2610 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2612 args_size = old_args_size = 0;
2614 /* We only want to output line number information for the genuine dwarf2
2615 prologue case, not the eh frame case. */
2616 #ifdef DWARF2_DEBUGGING_INFO
2618 dwarf2out_source_line (line, file);
2622 /* Output a marker (i.e. a label) for the absolute end of the generated code
2623 for a function definition. This gets called *after* the epilogue code has
2627 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2628 const char *file ATTRIBUTE_UNUSED)
2631 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2633 /* Output a label to mark the endpoint of the code generated for this
2635 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2636 current_function_funcdef_no);
2637 ASM_OUTPUT_LABEL (asm_out_file, label);
2638 fde = &fde_table[fde_table_in_use - 1];
2639 fde->dw_fde_end = xstrdup (label);
2643 dwarf2out_frame_init (void)
2645 /* Allocate the initial hunk of the fde_table. */
2646 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2647 fde_table_allocated = FDE_TABLE_INCREMENT;
2648 fde_table_in_use = 0;
2650 /* Generate the CFA instructions common to all FDE's. Do it now for the
2651 sake of lookup_cfa. */
2653 /* On entry, the Canonical Frame Address is at SP. */
2654 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2656 #ifdef DWARF2_UNWIND_INFO
2657 if (DWARF2_UNWIND_INFO)
2658 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2663 dwarf2out_frame_finish (void)
2665 /* Output call frame information. */
2666 if (DWARF2_FRAME_INFO)
2667 output_call_frame_info (0);
2669 #ifndef TARGET_UNWIND_INFO
2670 /* Output another copy for the unwinder. */
2671 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2672 output_call_frame_info (1);
2677 /* And now, the subset of the debugging information support code necessary
2678 for emitting location expressions. */
2680 /* Data about a single source file. */
2681 struct dwarf_file_data GTY(())
2683 const char * filename;
2687 /* We need some way to distinguish DW_OP_addr with a direct symbol
2688 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2689 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2692 typedef struct dw_val_struct *dw_val_ref;
2693 typedef struct die_struct *dw_die_ref;
2694 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2695 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2697 /* Each DIE may have a series of attribute/value pairs. Values
2698 can take on several forms. The forms that are used in this
2699 implementation are listed below. */
2704 dw_val_class_offset,
2706 dw_val_class_loc_list,
2707 dw_val_class_range_list,
2709 dw_val_class_unsigned_const,
2710 dw_val_class_long_long,
2713 dw_val_class_die_ref,
2714 dw_val_class_fde_ref,
2715 dw_val_class_lbl_id,
2716 dw_val_class_lineptr,
2718 dw_val_class_macptr,
2722 /* Describe a double word constant value. */
2723 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2725 typedef struct dw_long_long_struct GTY(())
2732 /* Describe a floating point constant value, or a vector constant value. */
2734 typedef struct dw_vec_struct GTY(())
2736 unsigned char * GTY((length ("%h.length"))) array;
2742 /* The dw_val_node describes an attribute's value, as it is
2743 represented internally. */
2745 typedef struct dw_val_struct GTY(())
2747 enum dw_val_class val_class;
2748 union dw_val_struct_union
2750 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2751 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2752 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2753 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2754 HOST_WIDE_INT GTY ((default)) val_int;
2755 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2756 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2757 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2758 struct dw_val_die_union
2762 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2763 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2764 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2765 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2766 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2767 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
2769 GTY ((desc ("%1.val_class"))) v;
2773 /* Locations in memory are described using a sequence of stack machine
2776 typedef struct dw_loc_descr_struct GTY(())
2778 dw_loc_descr_ref dw_loc_next;
2779 enum dwarf_location_atom dw_loc_opc;
2780 dw_val_node dw_loc_oprnd1;
2781 dw_val_node dw_loc_oprnd2;
2786 /* Location lists are ranges + location descriptions for that range,
2787 so you can track variables that are in different places over
2788 their entire life. */
2789 typedef struct dw_loc_list_struct GTY(())
2791 dw_loc_list_ref dw_loc_next;
2792 const char *begin; /* Label for begin address of range */
2793 const char *end; /* Label for end address of range */
2794 char *ll_symbol; /* Label for beginning of location list.
2795 Only on head of list */
2796 const char *section; /* Section this loclist is relative to */
2797 dw_loc_descr_ref expr;
2800 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2802 static const char *dwarf_stack_op_name (unsigned);
2803 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2804 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2805 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2806 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2807 static unsigned long size_of_locs (dw_loc_descr_ref);
2808 static void output_loc_operands (dw_loc_descr_ref);
2809 static void output_loc_sequence (dw_loc_descr_ref);
2811 /* Convert a DWARF stack opcode into its string name. */
2814 dwarf_stack_op_name (unsigned int op)
2819 case INTERNAL_DW_OP_tls_addr:
2820 return "DW_OP_addr";
2822 return "DW_OP_deref";
2824 return "DW_OP_const1u";
2826 return "DW_OP_const1s";
2828 return "DW_OP_const2u";
2830 return "DW_OP_const2s";
2832 return "DW_OP_const4u";
2834 return "DW_OP_const4s";
2836 return "DW_OP_const8u";
2838 return "DW_OP_const8s";
2840 return "DW_OP_constu";
2842 return "DW_OP_consts";
2846 return "DW_OP_drop";
2848 return "DW_OP_over";
2850 return "DW_OP_pick";
2852 return "DW_OP_swap";
2856 return "DW_OP_xderef";
2864 return "DW_OP_minus";
2876 return "DW_OP_plus";
2877 case DW_OP_plus_uconst:
2878 return "DW_OP_plus_uconst";
2884 return "DW_OP_shra";
2902 return "DW_OP_skip";
2904 return "DW_OP_lit0";
2906 return "DW_OP_lit1";
2908 return "DW_OP_lit2";
2910 return "DW_OP_lit3";
2912 return "DW_OP_lit4";
2914 return "DW_OP_lit5";
2916 return "DW_OP_lit6";
2918 return "DW_OP_lit7";
2920 return "DW_OP_lit8";
2922 return "DW_OP_lit9";
2924 return "DW_OP_lit10";
2926 return "DW_OP_lit11";
2928 return "DW_OP_lit12";
2930 return "DW_OP_lit13";
2932 return "DW_OP_lit14";
2934 return "DW_OP_lit15";
2936 return "DW_OP_lit16";
2938 return "DW_OP_lit17";
2940 return "DW_OP_lit18";
2942 return "DW_OP_lit19";
2944 return "DW_OP_lit20";
2946 return "DW_OP_lit21";
2948 return "DW_OP_lit22";
2950 return "DW_OP_lit23";
2952 return "DW_OP_lit24";
2954 return "DW_OP_lit25";
2956 return "DW_OP_lit26";
2958 return "DW_OP_lit27";
2960 return "DW_OP_lit28";
2962 return "DW_OP_lit29";
2964 return "DW_OP_lit30";
2966 return "DW_OP_lit31";
2968 return "DW_OP_reg0";
2970 return "DW_OP_reg1";
2972 return "DW_OP_reg2";
2974 return "DW_OP_reg3";
2976 return "DW_OP_reg4";
2978 return "DW_OP_reg5";
2980 return "DW_OP_reg6";
2982 return "DW_OP_reg7";
2984 return "DW_OP_reg8";
2986 return "DW_OP_reg9";
2988 return "DW_OP_reg10";
2990 return "DW_OP_reg11";
2992 return "DW_OP_reg12";
2994 return "DW_OP_reg13";
2996 return "DW_OP_reg14";
2998 return "DW_OP_reg15";
3000 return "DW_OP_reg16";
3002 return "DW_OP_reg17";
3004 return "DW_OP_reg18";
3006 return "DW_OP_reg19";
3008 return "DW_OP_reg20";
3010 return "DW_OP_reg21";
3012 return "DW_OP_reg22";
3014 return "DW_OP_reg23";
3016 return "DW_OP_reg24";
3018 return "DW_OP_reg25";
3020 return "DW_OP_reg26";
3022 return "DW_OP_reg27";
3024 return "DW_OP_reg28";
3026 return "DW_OP_reg29";
3028 return "DW_OP_reg30";
3030 return "DW_OP_reg31";
3032 return "DW_OP_breg0";
3034 return "DW_OP_breg1";
3036 return "DW_OP_breg2";
3038 return "DW_OP_breg3";
3040 return "DW_OP_breg4";
3042 return "DW_OP_breg5";
3044 return "DW_OP_breg6";
3046 return "DW_OP_breg7";
3048 return "DW_OP_breg8";
3050 return "DW_OP_breg9";
3052 return "DW_OP_breg10";
3054 return "DW_OP_breg11";
3056 return "DW_OP_breg12";
3058 return "DW_OP_breg13";
3060 return "DW_OP_breg14";
3062 return "DW_OP_breg15";
3064 return "DW_OP_breg16";
3066 return "DW_OP_breg17";
3068 return "DW_OP_breg18";
3070 return "DW_OP_breg19";
3072 return "DW_OP_breg20";
3074 return "DW_OP_breg21";
3076 return "DW_OP_breg22";
3078 return "DW_OP_breg23";
3080 return "DW_OP_breg24";
3082 return "DW_OP_breg25";
3084 return "DW_OP_breg26";
3086 return "DW_OP_breg27";
3088 return "DW_OP_breg28";
3090 return "DW_OP_breg29";
3092 return "DW_OP_breg30";
3094 return "DW_OP_breg31";
3096 return "DW_OP_regx";
3098 return "DW_OP_fbreg";
3100 return "DW_OP_bregx";
3102 return "DW_OP_piece";
3103 case DW_OP_deref_size:
3104 return "DW_OP_deref_size";
3105 case DW_OP_xderef_size:
3106 return "DW_OP_xderef_size";
3109 case DW_OP_push_object_address:
3110 return "DW_OP_push_object_address";
3112 return "DW_OP_call2";
3114 return "DW_OP_call4";
3115 case DW_OP_call_ref:
3116 return "DW_OP_call_ref";
3117 case DW_OP_GNU_push_tls_address:
3118 return "DW_OP_GNU_push_tls_address";
3120 return "OP_<unknown>";
3124 /* Return a pointer to a newly allocated location description. Location
3125 descriptions are simple expression terms that can be strung
3126 together to form more complicated location (address) descriptions. */
3128 static inline dw_loc_descr_ref
3129 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3130 unsigned HOST_WIDE_INT oprnd2)
3132 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
3134 descr->dw_loc_opc = op;
3135 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3136 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3137 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3138 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3143 /* Add a location description term to a location description expression. */
3146 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3148 dw_loc_descr_ref *d;
3150 /* Find the end of the chain. */
3151 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3157 /* Return the size of a location descriptor. */
3159 static unsigned long
3160 size_of_loc_descr (dw_loc_descr_ref loc)
3162 unsigned long size = 1;
3164 switch (loc->dw_loc_opc)
3167 case INTERNAL_DW_OP_tls_addr:
3168 size += DWARF2_ADDR_SIZE;
3187 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3190 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3195 case DW_OP_plus_uconst:
3196 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3234 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3237 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3240 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3243 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3244 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3247 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3249 case DW_OP_deref_size:
3250 case DW_OP_xderef_size:
3259 case DW_OP_call_ref:
3260 size += DWARF2_ADDR_SIZE;
3269 /* Return the size of a series of location descriptors. */
3271 static unsigned long
3272 size_of_locs (dw_loc_descr_ref loc)
3277 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3278 field, to avoid writing to a PCH file. */
3279 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3281 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
3283 size += size_of_loc_descr (l);
3288 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3290 l->dw_loc_addr = size;
3291 size += size_of_loc_descr (l);
3297 /* Output location description stack opcode's operands (if any). */
3300 output_loc_operands (dw_loc_descr_ref loc)
3302 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3303 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3305 switch (loc->dw_loc_opc)
3307 #ifdef DWARF2_DEBUGGING_INFO
3309 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3313 dw2_asm_output_data (2, val1->v.val_int, NULL);
3317 dw2_asm_output_data (4, val1->v.val_int, NULL);
3321 gcc_assert (HOST_BITS_PER_LONG >= 64);
3322 dw2_asm_output_data (8, val1->v.val_int, NULL);
3329 gcc_assert (val1->val_class == dw_val_class_loc);
3330 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3332 dw2_asm_output_data (2, offset, NULL);
3345 /* We currently don't make any attempt to make sure these are
3346 aligned properly like we do for the main unwind info, so
3347 don't support emitting things larger than a byte if we're
3348 only doing unwinding. */
3353 dw2_asm_output_data (1, val1->v.val_int, NULL);
3356 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3359 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3362 dw2_asm_output_data (1, val1->v.val_int, NULL);
3364 case DW_OP_plus_uconst:
3365 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3399 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3402 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3405 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3408 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3409 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3412 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3414 case DW_OP_deref_size:
3415 case DW_OP_xderef_size:
3416 dw2_asm_output_data (1, val1->v.val_int, NULL);
3419 case INTERNAL_DW_OP_tls_addr:
3420 if (targetm.asm_out.output_dwarf_dtprel)
3422 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
3425 fputc ('\n', asm_out_file);
3432 /* Other codes have no operands. */
3437 /* Output a sequence of location operations. */
3440 output_loc_sequence (dw_loc_descr_ref loc)
3442 for (; loc != NULL; loc = loc->dw_loc_next)
3444 /* Output the opcode. */
3445 dw2_asm_output_data (1, loc->dw_loc_opc,
3446 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3448 /* Output the operand(s) (if any). */
3449 output_loc_operands (loc);
3453 /* This routine will generate the correct assembly data for a location
3454 description based on a cfi entry with a complex address. */
3457 output_cfa_loc (dw_cfi_ref cfi)
3459 dw_loc_descr_ref loc;
3462 /* Output the size of the block. */
3463 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3464 size = size_of_locs (loc);
3465 dw2_asm_output_data_uleb128 (size, NULL);
3467 /* Now output the operations themselves. */
3468 output_loc_sequence (loc);
3471 /* This function builds a dwarf location descriptor sequence from a
3472 dw_cfa_location, adding the given OFFSET to the result of the
3475 static struct dw_loc_descr_struct *
3476 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
3478 struct dw_loc_descr_struct *head, *tmp;
3480 offset += cfa->offset;
3484 if (cfa->base_offset)
3487 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3489 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3491 else if (cfa->reg <= 31)
3492 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3494 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3496 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3497 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3498 add_loc_descr (&head, tmp);
3501 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
3502 add_loc_descr (&head, tmp);
3509 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3511 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3512 else if (cfa->reg <= 31)
3513 head = new_loc_descr (DW_OP_breg0 + cfa->reg, offset, 0);
3515 head = new_loc_descr (DW_OP_bregx, cfa->reg, offset);
3521 /* This function fills in aa dw_cfa_location structure from a dwarf location
3522 descriptor sequence. */
3525 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3527 struct dw_loc_descr_struct *ptr;
3529 cfa->base_offset = 0;
3533 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3535 enum dwarf_location_atom op = ptr->dw_loc_opc;
3571 cfa->reg = op - DW_OP_reg0;
3574 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;