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 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* TODO: Emit .debug_line header even when there are no functions, since
25 the file numbers are used by .debug_info. Alternately, leave
26 out locations for types and decls.
27 Avoid talking about ctors and op= for PODs.
28 Factor out common prologue sequences into multiple CIEs. */
30 /* The first part of this file deals with the DWARF 2 frame unwind
31 information, which is also used by the GCC efficient exception handling
32 mechanism. The second part, controlled only by an #ifdef
33 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 /* DWARF2 Abbreviation Glossary:
38 CFA = Canonical Frame Address
39 a fixed address on the stack which identifies a call frame.
40 We define it to be the value of SP just before the call insn.
41 The CFA register and offset, which may change during the course
42 of the function, are used to calculate its value at runtime.
44 CFI = Call Frame Instruction
45 an instruction for the DWARF2 abstract machine
47 CIE = Common Information Entry
48 information describing information common to one or more FDEs
50 DIE = Debugging Information Entry
52 FDE = Frame Description Entry
53 information describing the stack call frame, in particular,
54 how to restore registers
56 DW_CFA_... = DWARF2 CFA call frame instruction
57 DW_TAG_... = DWARF2 DIE tag */
61 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
85 #include "diagnostic.h"
88 #include "langhooks.h"
93 #ifdef DWARF2_DEBUGGING_INFO
94 static void dwarf2out_source_line (unsigned int, const char *);
97 #ifndef DWARF2_FRAME_INFO
98 # ifdef DWARF2_DEBUGGING_INFO
99 # define DWARF2_FRAME_INFO \
100 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
102 # define DWARF2_FRAME_INFO 0
106 /* Map register numbers held in the call frame info that gcc has
107 collected using DWARF_FRAME_REGNUM to those that should be output in
108 .debug_frame and .eh_frame. */
109 #ifndef DWARF2_FRAME_REG_OUT
110 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
113 /* Decide whether we want to emit frame unwind information for the current
117 dwarf2out_do_frame (void)
119 /* We want to emit correct CFA location expressions or lists, so we
120 have to return true if we're going to output debug info, even if
121 we're not going to output frame or unwind info. */
122 return (write_symbols == DWARF2_DEBUG
123 || write_symbols == VMS_AND_DWARF2_DEBUG
125 #ifdef DWARF2_UNWIND_INFO
126 || (DWARF2_UNWIND_INFO
127 && (flag_unwind_tables
128 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
133 /* The size of the target's pointer type. */
135 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
138 /* Array of RTXes referenced by the debugging information, which therefore
139 must be kept around forever. */
140 static GTY(()) VEC(rtx,gc) *used_rtx_array;
142 /* A pointer to the base of a list of incomplete types which might be
143 completed at some later time. incomplete_types_list needs to be a
144 VEC(tree,gc) because we want to tell the garbage collector about
146 static GTY(()) VEC(tree,gc) *incomplete_types;
148 /* A pointer to the base of a table of references to declaration
149 scopes. This table is a display which tracks the nesting
150 of declaration scopes at the current scope and containing
151 scopes. This table is used to find the proper place to
152 define type declaration DIE's. */
153 static GTY(()) VEC(tree,gc) *decl_scope_table;
155 /* Pointers to various DWARF2 sections. */
156 static GTY(()) section *debug_info_section;
157 static GTY(()) section *debug_abbrev_section;
158 static GTY(()) section *debug_aranges_section;
159 static GTY(()) section *debug_macinfo_section;
160 static GTY(()) section *debug_line_section;
161 static GTY(()) section *debug_loc_section;
162 static GTY(()) section *debug_pubnames_section;
163 static GTY(()) section *debug_pubtypes_section;
164 static GTY(()) section *debug_str_section;
165 static GTY(()) section *debug_ranges_section;
166 static GTY(()) section *debug_frame_section;
168 /* How to start an assembler comment. */
169 #ifndef ASM_COMMENT_START
170 #define ASM_COMMENT_START ";#"
173 typedef struct dw_cfi_struct *dw_cfi_ref;
174 typedef struct dw_fde_struct *dw_fde_ref;
175 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
177 /* Call frames are described using a sequence of Call Frame
178 Information instructions. The register number, offset
179 and address fields are provided as possible operands;
180 their use is selected by the opcode field. */
182 enum dw_cfi_oprnd_type {
184 dw_cfi_oprnd_reg_num,
190 typedef union dw_cfi_oprnd_struct GTY(())
192 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
193 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
194 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
195 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
199 typedef struct dw_cfi_struct GTY(())
201 dw_cfi_ref dw_cfi_next;
202 enum dwarf_call_frame_info dw_cfi_opc;
203 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
205 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
210 /* This is how we define the location of the CFA. We use to handle it
211 as REG + OFFSET all the time, but now it can be more complex.
212 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
213 Instead of passing around REG and OFFSET, we pass a copy
214 of this structure. */
215 typedef struct cfa_loc GTY(())
217 HOST_WIDE_INT offset;
218 HOST_WIDE_INT base_offset;
220 int indirect; /* 1 if CFA is accessed via a dereference. */
223 /* All call frame descriptions (FDE's) in the GCC generated DWARF
224 refer to a single Common Information Entry (CIE), defined at
225 the beginning of the .debug_frame section. This use of a single
226 CIE obviates the need to keep track of multiple CIE's
227 in the DWARF generation routines below. */
229 typedef struct dw_fde_struct GTY(())
232 const char *dw_fde_begin;
233 const char *dw_fde_current_label;
234 const char *dw_fde_end;
235 const char *dw_fde_hot_section_label;
236 const char *dw_fde_hot_section_end_label;
237 const char *dw_fde_unlikely_section_label;
238 const char *dw_fde_unlikely_section_end_label;
239 bool dw_fde_switched_sections;
240 dw_cfi_ref dw_fde_cfi;
241 unsigned funcdef_number;
242 unsigned all_throwers_are_sibcalls : 1;
243 unsigned nothrow : 1;
244 unsigned uses_eh_lsda : 1;
248 /* Maximum size (in bytes) of an artificially generated label. */
249 #define MAX_ARTIFICIAL_LABEL_BYTES 30
251 /* The size of addresses as they appear in the Dwarf 2 data.
252 Some architectures use word addresses to refer to code locations,
253 but Dwarf 2 info always uses byte addresses. On such machines,
254 Dwarf 2 addresses need to be larger than the architecture's
256 #ifndef DWARF2_ADDR_SIZE
257 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
260 /* The size in bytes of a DWARF field indicating an offset or length
261 relative to a debug info section, specified to be 4 bytes in the
262 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
265 #ifndef DWARF_OFFSET_SIZE
266 #define DWARF_OFFSET_SIZE 4
269 /* According to the (draft) DWARF 3 specification, the initial length
270 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
271 bytes are 0xffffffff, followed by the length stored in the next 8
274 However, the SGI/MIPS ABI uses an initial length which is equal to
275 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
277 #ifndef DWARF_INITIAL_LENGTH_SIZE
278 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
281 #define DWARF_VERSION 2
283 /* Round SIZE up to the nearest BOUNDARY. */
284 #define DWARF_ROUND(SIZE,BOUNDARY) \
285 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
287 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
288 #ifndef DWARF_CIE_DATA_ALIGNMENT
289 #ifdef STACK_GROWS_DOWNWARD
290 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
292 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
296 /* CIE identifier. */
297 #if HOST_BITS_PER_WIDE_INT >= 64
298 #define DWARF_CIE_ID \
299 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
301 #define DWARF_CIE_ID DW_CIE_ID
304 /* A pointer to the base of a table that contains frame description
305 information for each routine. */
306 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
308 /* Number of elements currently allocated for fde_table. */
309 static GTY(()) unsigned fde_table_allocated;
311 /* Number of elements in fde_table currently in use. */
312 static GTY(()) unsigned fde_table_in_use;
314 /* Size (in elements) of increments by which we may expand the
316 #define FDE_TABLE_INCREMENT 256
318 /* A list of call frame insns for the CIE. */
319 static GTY(()) dw_cfi_ref cie_cfi_head;
321 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
322 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
323 attribute that accelerates the lookup of the FDE associated
324 with the subprogram. This variable holds the table index of the FDE
325 associated with the current function (body) definition. */
326 static unsigned current_funcdef_fde;
329 struct indirect_string_node GTY(())
332 unsigned int refcount;
337 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
339 static GTY(()) int dw2_string_counter;
340 static GTY(()) unsigned long dwarf2out_cfi_label_num;
342 /* True if the compilation unit places functions in more than one section. */
343 static GTY(()) bool have_multiple_function_sections = false;
345 /* Whether the default text and cold text sections have been used at all. */
347 static GTY(()) bool text_section_used = false;
348 static GTY(()) bool cold_text_section_used = false;
350 /* The default cold text section. */
351 static GTY(()) section *cold_text_section;
353 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
355 /* Forward declarations for functions defined in this file. */
357 static char *stripattributes (const char *);
358 static const char *dwarf_cfi_name (unsigned);
359 static dw_cfi_ref new_cfi (void);
360 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
361 static void add_fde_cfi (const char *, dw_cfi_ref);
362 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
363 static void lookup_cfa (dw_cfa_location *);
364 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
365 #ifdef DWARF2_UNWIND_INFO
366 static void initial_return_save (rtx);
368 static HOST_WIDE_INT stack_adjust_offset (const_rtx);
369 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
370 static void output_call_frame_info (int);
371 static void dwarf2out_note_section_used (void);
372 static void dwarf2out_stack_adjust (rtx, bool);
373 static void flush_queued_reg_saves (void);
374 static bool clobbers_queued_reg_save (const_rtx);
375 static void dwarf2out_frame_debug_expr (rtx, const char *);
377 /* Support for complex CFA locations. */
378 static void output_cfa_loc (dw_cfi_ref);
379 static void get_cfa_from_loc_descr (dw_cfa_location *,
380 struct dw_loc_descr_struct *);
381 static struct dw_loc_descr_struct *build_cfa_loc
382 (dw_cfa_location *, HOST_WIDE_INT);
383 static void def_cfa_1 (const char *, dw_cfa_location *);
385 /* How to start an assembler comment. */
386 #ifndef ASM_COMMENT_START
387 #define ASM_COMMENT_START ";#"
390 /* Data and reference forms for relocatable data. */
391 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
392 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
394 #ifndef DEBUG_FRAME_SECTION
395 #define DEBUG_FRAME_SECTION ".debug_frame"
398 #ifndef FUNC_BEGIN_LABEL
399 #define FUNC_BEGIN_LABEL "LFB"
402 #ifndef FUNC_END_LABEL
403 #define FUNC_END_LABEL "LFE"
406 #ifndef FRAME_BEGIN_LABEL
407 #define FRAME_BEGIN_LABEL "Lframe"
409 #define CIE_AFTER_SIZE_LABEL "LSCIE"
410 #define CIE_END_LABEL "LECIE"
411 #define FDE_LABEL "LSFDE"
412 #define FDE_AFTER_SIZE_LABEL "LASFDE"
413 #define FDE_END_LABEL "LEFDE"
414 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
415 #define LINE_NUMBER_END_LABEL "LELT"
416 #define LN_PROLOG_AS_LABEL "LASLTP"
417 #define LN_PROLOG_END_LABEL "LELTP"
418 #define DIE_LABEL_PREFIX "DW"
420 /* The DWARF 2 CFA column which tracks the return address. Normally this
421 is the column for PC, or the first column after all of the hard
423 #ifndef DWARF_FRAME_RETURN_COLUMN
425 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
427 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
431 /* The mapping from gcc register number to DWARF 2 CFA column number. By
432 default, we just provide columns for all registers. */
433 #ifndef DWARF_FRAME_REGNUM
434 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
437 /* Hook used by __throw. */
440 expand_builtin_dwarf_sp_column (void)
442 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
443 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
446 /* Return a pointer to a copy of the section string name S with all
447 attributes stripped off, and an asterisk prepended (for assemble_name). */
450 stripattributes (const char *s)
452 char *stripped = XNEWVEC (char, strlen (s) + 2);
457 while (*s && *s != ',')
464 /* MEM is a memory reference for the register size table, each element of
465 which has mode MODE. Initialize column C as a return address column. */
468 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
470 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
471 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
472 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
475 /* Generate code to initialize the register size table. */
478 expand_builtin_init_dwarf_reg_sizes (tree address)
481 enum machine_mode mode = TYPE_MODE (char_type_node);
482 rtx addr = expand_normal (address);
483 rtx mem = gen_rtx_MEM (BLKmode, addr);
484 bool wrote_return_column = false;
486 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
488 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
490 if (rnum < DWARF_FRAME_REGISTERS)
492 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
493 enum machine_mode save_mode = reg_raw_mode[i];
496 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
497 save_mode = choose_hard_reg_mode (i, 1, true);
498 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
500 if (save_mode == VOIDmode)
502 wrote_return_column = true;
504 size = GET_MODE_SIZE (save_mode);
508 emit_move_insn (adjust_address (mem, mode, offset),
509 gen_int_mode (size, mode));
513 if (!wrote_return_column)
514 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
516 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
517 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
520 targetm.init_dwarf_reg_sizes_extra (address);
523 /* Convert a DWARF call frame info. operation to its string name */
526 dwarf_cfi_name (unsigned int cfi_opc)
530 case DW_CFA_advance_loc:
531 return "DW_CFA_advance_loc";
533 return "DW_CFA_offset";
535 return "DW_CFA_restore";
539 return "DW_CFA_set_loc";
540 case DW_CFA_advance_loc1:
541 return "DW_CFA_advance_loc1";
542 case DW_CFA_advance_loc2:
543 return "DW_CFA_advance_loc2";
544 case DW_CFA_advance_loc4:
545 return "DW_CFA_advance_loc4";
546 case DW_CFA_offset_extended:
547 return "DW_CFA_offset_extended";
548 case DW_CFA_restore_extended:
549 return "DW_CFA_restore_extended";
550 case DW_CFA_undefined:
551 return "DW_CFA_undefined";
552 case DW_CFA_same_value:
553 return "DW_CFA_same_value";
554 case DW_CFA_register:
555 return "DW_CFA_register";
556 case DW_CFA_remember_state:
557 return "DW_CFA_remember_state";
558 case DW_CFA_restore_state:
559 return "DW_CFA_restore_state";
561 return "DW_CFA_def_cfa";
562 case DW_CFA_def_cfa_register:
563 return "DW_CFA_def_cfa_register";
564 case DW_CFA_def_cfa_offset:
565 return "DW_CFA_def_cfa_offset";
568 case DW_CFA_def_cfa_expression:
569 return "DW_CFA_def_cfa_expression";
570 case DW_CFA_expression:
571 return "DW_CFA_expression";
572 case DW_CFA_offset_extended_sf:
573 return "DW_CFA_offset_extended_sf";
574 case DW_CFA_def_cfa_sf:
575 return "DW_CFA_def_cfa_sf";
576 case DW_CFA_def_cfa_offset_sf:
577 return "DW_CFA_def_cfa_offset_sf";
579 /* SGI/MIPS specific */
580 case DW_CFA_MIPS_advance_loc8:
581 return "DW_CFA_MIPS_advance_loc8";
584 case DW_CFA_GNU_window_save:
585 return "DW_CFA_GNU_window_save";
586 case DW_CFA_GNU_args_size:
587 return "DW_CFA_GNU_args_size";
588 case DW_CFA_GNU_negative_offset_extended:
589 return "DW_CFA_GNU_negative_offset_extended";
592 return "DW_CFA_<unknown>";
596 /* Return a pointer to a newly allocated Call Frame Instruction. */
598 static inline dw_cfi_ref
601 dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node));
603 cfi->dw_cfi_next = NULL;
604 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
605 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
610 /* Add a Call Frame Instruction to list of instructions. */
613 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
617 /* Find the end of the chain. */
618 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
624 /* Generate a new label for the CFI info to refer to. */
627 dwarf2out_cfi_label (void)
629 static char label[20];
631 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
632 ASM_OUTPUT_LABEL (asm_out_file, label);
636 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
637 or to the CIE if LABEL is NULL. */
640 add_fde_cfi (const char *label, dw_cfi_ref cfi)
644 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
647 label = dwarf2out_cfi_label ();
649 if (fde->dw_fde_current_label == NULL
650 || strcmp (label, fde->dw_fde_current_label) != 0)
654 label = xstrdup (label);
656 /* Set the location counter to the new label. */
658 /* If we have a current label, advance from there, otherwise
659 set the location directly using set_loc. */
660 xcfi->dw_cfi_opc = fde->dw_fde_current_label
661 ? DW_CFA_advance_loc4
663 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
664 add_cfi (&fde->dw_fde_cfi, xcfi);
666 fde->dw_fde_current_label = label;
669 add_cfi (&fde->dw_fde_cfi, cfi);
673 add_cfi (&cie_cfi_head, cfi);
676 /* Subroutine of lookup_cfa. */
679 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
681 switch (cfi->dw_cfi_opc)
683 case DW_CFA_def_cfa_offset:
684 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
686 case DW_CFA_def_cfa_offset_sf:
688 = cfi->dw_cfi_oprnd1.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
690 case DW_CFA_def_cfa_register:
691 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
694 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
695 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
697 case DW_CFA_def_cfa_sf:
698 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
700 = cfi->dw_cfi_oprnd2.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
702 case DW_CFA_def_cfa_expression:
703 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
710 /* Find the previous value for the CFA. */
713 lookup_cfa (dw_cfa_location *loc)
717 loc->reg = INVALID_REGNUM;
720 loc->base_offset = 0;
722 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
723 lookup_cfa_1 (cfi, loc);
725 if (fde_table_in_use)
727 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
728 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
729 lookup_cfa_1 (cfi, loc);
733 /* The current rule for calculating the DWARF2 canonical frame address. */
734 static dw_cfa_location cfa;
736 /* The register used for saving registers to the stack, and its offset
738 static dw_cfa_location cfa_store;
740 /* The running total of the size of arguments pushed onto the stack. */
741 static HOST_WIDE_INT args_size;
743 /* The last args_size we actually output. */
744 static HOST_WIDE_INT old_args_size;
746 /* Entry point to update the canonical frame address (CFA).
747 LABEL is passed to add_fde_cfi. The value of CFA is now to be
748 calculated from REG+OFFSET. */
751 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
758 def_cfa_1 (label, &loc);
761 /* Determine if two dw_cfa_location structures define the same data. */
764 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
766 return (loc1->reg == loc2->reg
767 && loc1->offset == loc2->offset
768 && loc1->indirect == loc2->indirect
769 && (loc1->indirect == 0
770 || loc1->base_offset == loc2->base_offset));
773 /* This routine does the actual work. The CFA is now calculated from
774 the dw_cfa_location structure. */
777 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
780 dw_cfa_location old_cfa, loc;
785 if (cfa_store.reg == loc.reg && loc.indirect == 0)
786 cfa_store.offset = loc.offset;
788 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
789 lookup_cfa (&old_cfa);
791 /* If nothing changed, no need to issue any call frame instructions. */
792 if (cfa_equal_p (&loc, &old_cfa))
797 if (loc.reg == old_cfa.reg && !loc.indirect)
799 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
800 the CFA register did not change but the offset did. */
803 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
804 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
806 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
807 cfi->dw_cfi_oprnd1.dw_cfi_offset = f_offset;
811 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
812 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
816 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
817 else if (loc.offset == old_cfa.offset
818 && old_cfa.reg != INVALID_REGNUM
821 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
822 indicating the CFA register has changed to <register> but the
823 offset has not changed. */
824 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
825 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
829 else if (loc.indirect == 0)
831 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
832 indicating the CFA register has changed to <register> with
833 the specified offset. */
836 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
837 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
839 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
840 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
841 cfi->dw_cfi_oprnd2.dw_cfi_offset = f_offset;
845 cfi->dw_cfi_opc = DW_CFA_def_cfa;
846 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
847 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
852 /* Construct a DW_CFA_def_cfa_expression instruction to
853 calculate the CFA using a full location expression since no
854 register-offset pair is available. */
855 struct dw_loc_descr_struct *loc_list;
857 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
858 loc_list = build_cfa_loc (&loc, 0);
859 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
862 add_fde_cfi (label, cfi);
865 /* Add the CFI for saving a register. REG is the CFA column number.
866 LABEL is passed to add_fde_cfi.
867 If SREG is -1, the register is saved at OFFSET from the CFA;
868 otherwise it is saved in SREG. */
871 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
873 dw_cfi_ref cfi = new_cfi ();
875 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
877 if (sreg == INVALID_REGNUM)
880 /* The register number won't fit in 6 bits, so we have to use
882 cfi->dw_cfi_opc = DW_CFA_offset_extended;
884 cfi->dw_cfi_opc = DW_CFA_offset;
886 #ifdef ENABLE_CHECKING
888 /* If we get an offset that is not a multiple of
889 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
890 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
892 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
894 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
897 offset /= DWARF_CIE_DATA_ALIGNMENT;
899 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
901 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
903 else if (sreg == reg)
904 cfi->dw_cfi_opc = DW_CFA_same_value;
907 cfi->dw_cfi_opc = DW_CFA_register;
908 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
911 add_fde_cfi (label, cfi);
914 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
915 This CFI tells the unwinder that it needs to restore the window registers
916 from the previous frame's window save area.
918 ??? Perhaps we should note in the CIE where windows are saved (instead of
919 assuming 0(cfa)) and what registers are in the window. */
922 dwarf2out_window_save (const char *label)
924 dw_cfi_ref cfi = new_cfi ();
926 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
927 add_fde_cfi (label, cfi);
930 /* Add a CFI to update the running total of the size of arguments
931 pushed onto the stack. */
934 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
938 if (size == old_args_size)
941 old_args_size = size;
944 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
945 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
946 add_fde_cfi (label, cfi);
949 /* Entry point for saving a register to the stack. REG is the GCC register
950 number. LABEL and OFFSET are passed to reg_save. */
953 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
955 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
958 /* Entry point for saving the return address in the stack.
959 LABEL and OFFSET are passed to reg_save. */
962 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
964 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
967 /* Entry point for saving the return address in a register.
968 LABEL and SREG are passed to reg_save. */
971 dwarf2out_return_reg (const char *label, unsigned int sreg)
973 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
976 #ifdef DWARF2_UNWIND_INFO
977 /* Record the initial position of the return address. RTL is
978 INCOMING_RETURN_ADDR_RTX. */
981 initial_return_save (rtx rtl)
983 unsigned int reg = INVALID_REGNUM;
984 HOST_WIDE_INT offset = 0;
986 switch (GET_CODE (rtl))
989 /* RA is in a register. */
990 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
994 /* RA is on the stack. */
996 switch (GET_CODE (rtl))
999 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1004 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1005 offset = INTVAL (XEXP (rtl, 1));
1009 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1010 offset = -INTVAL (XEXP (rtl, 1));
1020 /* The return address is at some offset from any value we can
1021 actually load. For instance, on the SPARC it is in %i7+8. Just
1022 ignore the offset for now; it doesn't matter for unwinding frames. */
1023 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1024 initial_return_save (XEXP (rtl, 0));
1031 if (reg != DWARF_FRAME_RETURN_COLUMN)
1032 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1036 /* Given a SET, calculate the amount of stack adjustment it
1039 static HOST_WIDE_INT
1040 stack_adjust_offset (const_rtx pattern)
1042 const_rtx src = SET_SRC (pattern);
1043 const_rtx dest = SET_DEST (pattern);
1044 HOST_WIDE_INT offset = 0;
1047 if (dest == stack_pointer_rtx)
1049 /* (set (reg sp) (plus (reg sp) (const_int))) */
1050 code = GET_CODE (src);
1051 if (! (code == PLUS || code == MINUS)
1052 || XEXP (src, 0) != stack_pointer_rtx
1053 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1056 offset = INTVAL (XEXP (src, 1));
1060 else if (MEM_P (dest))
1062 /* (set (mem (pre_dec (reg sp))) (foo)) */
1063 src = XEXP (dest, 0);
1064 code = GET_CODE (src);
1070 if (XEXP (src, 0) == stack_pointer_rtx)
1072 rtx val = XEXP (XEXP (src, 1), 1);
1073 /* We handle only adjustments by constant amount. */
1074 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1075 && GET_CODE (val) == CONST_INT);
1076 offset = -INTVAL (val);
1083 if (XEXP (src, 0) == stack_pointer_rtx)
1085 offset = GET_MODE_SIZE (GET_MODE (dest));
1092 if (XEXP (src, 0) == stack_pointer_rtx)
1094 offset = -GET_MODE_SIZE (GET_MODE (dest));
1109 /* Check INSN to see if it looks like a push or a stack adjustment, and
1110 make a note of it if it does. EH uses this information to find out how
1111 much extra space it needs to pop off the stack. */
1114 dwarf2out_stack_adjust (rtx insn, bool after_p)
1116 HOST_WIDE_INT offset;
1120 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1121 with this function. Proper support would require all frame-related
1122 insns to be marked, and to be able to handle saving state around
1123 epilogues textually in the middle of the function. */
1124 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1127 /* If only calls can throw, and we have a frame pointer,
1128 save up adjustments until we see the CALL_INSN. */
1129 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1131 if (CALL_P (insn) && !after_p)
1133 /* Extract the size of the args from the CALL rtx itself. */
1134 insn = PATTERN (insn);
1135 if (GET_CODE (insn) == PARALLEL)
1136 insn = XVECEXP (insn, 0, 0);
1137 if (GET_CODE (insn) == SET)
1138 insn = SET_SRC (insn);
1139 gcc_assert (GET_CODE (insn) == CALL);
1140 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1145 if (CALL_P (insn) && !after_p)
1147 if (!flag_asynchronous_unwind_tables)
1148 dwarf2out_args_size ("", args_size);
1151 else if (BARRIER_P (insn))
1153 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1154 the compiler will have already emitted a stack adjustment, but
1155 doesn't bother for calls to noreturn functions. */
1156 #ifdef STACK_GROWS_DOWNWARD
1157 offset = -args_size;
1162 else if (GET_CODE (PATTERN (insn)) == SET)
1163 offset = stack_adjust_offset (PATTERN (insn));
1164 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1165 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1167 /* There may be stack adjustments inside compound insns. Search
1169 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1170 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1171 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1179 if (cfa.reg == STACK_POINTER_REGNUM)
1180 cfa.offset += offset;
1182 #ifndef STACK_GROWS_DOWNWARD
1186 args_size += offset;
1190 label = dwarf2out_cfi_label ();
1191 def_cfa_1 (label, &cfa);
1192 if (flag_asynchronous_unwind_tables)
1193 dwarf2out_args_size (label, args_size);
1198 /* We delay emitting a register save until either (a) we reach the end
1199 of the prologue or (b) the register is clobbered. This clusters
1200 register saves so that there are fewer pc advances. */
1202 struct queued_reg_save GTY(())
1204 struct queued_reg_save *next;
1206 HOST_WIDE_INT cfa_offset;
1210 static GTY(()) struct queued_reg_save *queued_reg_saves;
1212 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1213 struct reg_saved_in_data GTY(()) {
1218 /* A list of registers saved in other registers.
1219 The list intentionally has a small maximum capacity of 4; if your
1220 port needs more than that, you might consider implementing a
1221 more efficient data structure. */
1222 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1223 static GTY(()) size_t num_regs_saved_in_regs;
1225 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1226 static const char *last_reg_save_label;
1228 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1229 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1232 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1234 struct queued_reg_save *q;
1236 /* Duplicates waste space, but it's also necessary to remove them
1237 for correctness, since the queue gets output in reverse
1239 for (q = queued_reg_saves; q != NULL; q = q->next)
1240 if (REGNO (q->reg) == REGNO (reg))
1245 q = ggc_alloc (sizeof (*q));
1246 q->next = queued_reg_saves;
1247 queued_reg_saves = q;
1251 q->cfa_offset = offset;
1252 q->saved_reg = sreg;
1254 last_reg_save_label = label;
1257 /* Output all the entries in QUEUED_REG_SAVES. */
1260 flush_queued_reg_saves (void)
1262 struct queued_reg_save *q;
1264 for (q = queued_reg_saves; q; q = q->next)
1267 unsigned int reg, sreg;
1269 for (i = 0; i < num_regs_saved_in_regs; i++)
1270 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1272 if (q->saved_reg && i == num_regs_saved_in_regs)
1274 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1275 num_regs_saved_in_regs++;
1277 if (i != num_regs_saved_in_regs)
1279 regs_saved_in_regs[i].orig_reg = q->reg;
1280 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1283 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1285 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1287 sreg = INVALID_REGNUM;
1288 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1291 queued_reg_saves = NULL;
1292 last_reg_save_label = NULL;
1295 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1296 location for? Or, does it clobber a register which we've previously
1297 said that some other register is saved in, and for which we now
1298 have a new location for? */
1301 clobbers_queued_reg_save (const_rtx insn)
1303 struct queued_reg_save *q;
1305 for (q = queued_reg_saves; q; q = q->next)
1308 if (modified_in_p (q->reg, insn))
1310 for (i = 0; i < num_regs_saved_in_regs; i++)
1311 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1312 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1319 /* Entry point for saving the first register into the second. */
1322 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1325 unsigned int regno, sregno;
1327 for (i = 0; i < num_regs_saved_in_regs; i++)
1328 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1330 if (i == num_regs_saved_in_regs)
1332 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1333 num_regs_saved_in_regs++;
1335 regs_saved_in_regs[i].orig_reg = reg;
1336 regs_saved_in_regs[i].saved_in_reg = sreg;
1338 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1339 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1340 reg_save (label, regno, sregno, 0);
1343 /* What register, if any, is currently saved in REG? */
1346 reg_saved_in (rtx reg)
1348 unsigned int regn = REGNO (reg);
1350 struct queued_reg_save *q;
1352 for (q = queued_reg_saves; q; q = q->next)
1353 if (q->saved_reg && regn == REGNO (q->saved_reg))
1356 for (i = 0; i < num_regs_saved_in_regs; i++)
1357 if (regs_saved_in_regs[i].saved_in_reg
1358 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1359 return regs_saved_in_regs[i].orig_reg;
1365 /* A temporary register holding an integral value used in adjusting SP
1366 or setting up the store_reg. The "offset" field holds the integer
1367 value, not an offset. */
1368 static dw_cfa_location cfa_temp;
1370 /* Record call frame debugging information for an expression EXPR,
1371 which either sets SP or FP (adjusting how we calculate the frame
1372 address) or saves a register to the stack or another register.
1373 LABEL indicates the address of EXPR.
1375 This function encodes a state machine mapping rtxes to actions on
1376 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1377 users need not read the source code.
1379 The High-Level Picture
1381 Changes in the register we use to calculate the CFA: Currently we
1382 assume that if you copy the CFA register into another register, we
1383 should take the other one as the new CFA register; this seems to
1384 work pretty well. If it's wrong for some target, it's simple
1385 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1387 Changes in the register we use for saving registers to the stack:
1388 This is usually SP, but not always. Again, we deduce that if you
1389 copy SP into another register (and SP is not the CFA register),
1390 then the new register is the one we will be using for register
1391 saves. This also seems to work.
1393 Register saves: There's not much guesswork about this one; if
1394 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1395 register save, and the register used to calculate the destination
1396 had better be the one we think we're using for this purpose.
1397 It's also assumed that a copy from a call-saved register to another
1398 register is saving that register if RTX_FRAME_RELATED_P is set on
1399 that instruction. If the copy is from a call-saved register to
1400 the *same* register, that means that the register is now the same
1401 value as in the caller.
1403 Except: If the register being saved is the CFA register, and the
1404 offset is nonzero, we are saving the CFA, so we assume we have to
1405 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1406 the intent is to save the value of SP from the previous frame.
1408 In addition, if a register has previously been saved to a different
1411 Invariants / Summaries of Rules
1413 cfa current rule for calculating the CFA. It usually
1414 consists of a register and an offset.
1415 cfa_store register used by prologue code to save things to the stack
1416 cfa_store.offset is the offset from the value of
1417 cfa_store.reg to the actual CFA
1418 cfa_temp register holding an integral value. cfa_temp.offset
1419 stores the value, which will be used to adjust the
1420 stack pointer. cfa_temp is also used like cfa_store,
1421 to track stores to the stack via fp or a temp reg.
1423 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1424 with cfa.reg as the first operand changes the cfa.reg and its
1425 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1428 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1429 expression yielding a constant. This sets cfa_temp.reg
1430 and cfa_temp.offset.
1432 Rule 5: Create a new register cfa_store used to save items to the
1435 Rules 10-14: Save a register to the stack. Define offset as the
1436 difference of the original location and cfa_store's
1437 location (or cfa_temp's location if cfa_temp is used).
1441 "{a,b}" indicates a choice of a xor b.
1442 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1445 (set <reg1> <reg2>:cfa.reg)
1446 effects: cfa.reg = <reg1>
1447 cfa.offset unchanged
1448 cfa_temp.reg = <reg1>
1449 cfa_temp.offset = cfa.offset
1452 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1453 {<const_int>,<reg>:cfa_temp.reg}))
1454 effects: cfa.reg = sp if fp used
1455 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1456 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1457 if cfa_store.reg==sp
1460 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1461 effects: cfa.reg = fp
1462 cfa_offset += +/- <const_int>
1465 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1466 constraints: <reg1> != fp
1468 effects: cfa.reg = <reg1>
1469 cfa_temp.reg = <reg1>
1470 cfa_temp.offset = cfa.offset
1473 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1474 constraints: <reg1> != fp
1476 effects: cfa_store.reg = <reg1>
1477 cfa_store.offset = cfa.offset - cfa_temp.offset
1480 (set <reg> <const_int>)
1481 effects: cfa_temp.reg = <reg>
1482 cfa_temp.offset = <const_int>
1485 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1486 effects: cfa_temp.reg = <reg1>
1487 cfa_temp.offset |= <const_int>
1490 (set <reg> (high <exp>))
1494 (set <reg> (lo_sum <exp> <const_int>))
1495 effects: cfa_temp.reg = <reg>
1496 cfa_temp.offset = <const_int>
1499 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1500 effects: cfa_store.offset -= <const_int>
1501 cfa.offset = cfa_store.offset if cfa.reg == sp
1503 cfa.base_offset = -cfa_store.offset
1506 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1507 effects: cfa_store.offset += -/+ mode_size(mem)
1508 cfa.offset = cfa_store.offset if cfa.reg == sp
1510 cfa.base_offset = -cfa_store.offset
1513 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1516 effects: cfa.reg = <reg1>
1517 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1520 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1521 effects: cfa.reg = <reg1>
1522 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1525 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1526 effects: cfa.reg = <reg1>
1527 cfa.base_offset = -cfa_temp.offset
1528 cfa_temp.offset -= mode_size(mem)
1531 (set <reg> {unspec, unspec_volatile})
1532 effects: target-dependent */
1535 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1538 HOST_WIDE_INT offset;
1540 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1541 the PARALLEL independently. The first element is always processed if
1542 it is a SET. This is for backward compatibility. Other elements
1543 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1544 flag is set in them. */
1545 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1548 int limit = XVECLEN (expr, 0);
1551 /* PARALLELs have strict read-modify-write semantics, so we
1552 ought to evaluate every rvalue before changing any lvalue.
1553 It's cumbersome to do that in general, but there's an
1554 easy approximation that is enough for all current users:
1555 handle register saves before register assignments. */
1556 if (GET_CODE (expr) == PARALLEL)
1557 for (par_index = 0; par_index < limit; par_index++)
1559 elem = XVECEXP (expr, 0, par_index);
1560 if (GET_CODE (elem) == SET
1561 && MEM_P (SET_DEST (elem))
1562 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1563 dwarf2out_frame_debug_expr (elem, label);
1566 for (par_index = 0; par_index < limit; par_index++)
1568 elem = XVECEXP (expr, 0, par_index);
1569 if (GET_CODE (elem) == SET
1570 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
1571 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1572 dwarf2out_frame_debug_expr (elem, label);
1577 gcc_assert (GET_CODE (expr) == SET);
1579 src = SET_SRC (expr);
1580 dest = SET_DEST (expr);
1584 rtx rsi = reg_saved_in (src);
1589 switch (GET_CODE (dest))
1592 switch (GET_CODE (src))
1594 /* Setting FP from SP. */
1596 if (cfa.reg == (unsigned) REGNO (src))
1599 /* Update the CFA rule wrt SP or FP. Make sure src is
1600 relative to the current CFA register.
1602 We used to require that dest be either SP or FP, but the
1603 ARM copies SP to a temporary register, and from there to
1604 FP. So we just rely on the backends to only set
1605 RTX_FRAME_RELATED_P on appropriate insns. */
1606 cfa.reg = REGNO (dest);
1607 cfa_temp.reg = cfa.reg;
1608 cfa_temp.offset = cfa.offset;
1612 /* Saving a register in a register. */
1613 gcc_assert (!fixed_regs [REGNO (dest)]
1614 /* For the SPARC and its register window. */
1615 || (DWARF_FRAME_REGNUM (REGNO (src))
1616 == DWARF_FRAME_RETURN_COLUMN));
1617 queue_reg_save (label, src, dest, 0);
1624 if (dest == stack_pointer_rtx)
1628 switch (GET_CODE (XEXP (src, 1)))
1631 offset = INTVAL (XEXP (src, 1));
1634 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1636 offset = cfa_temp.offset;
1642 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1644 /* Restoring SP from FP in the epilogue. */
1645 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1646 cfa.reg = STACK_POINTER_REGNUM;
1648 else if (GET_CODE (src) == LO_SUM)
1649 /* Assume we've set the source reg of the LO_SUM from sp. */
1652 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1654 if (GET_CODE (src) != MINUS)
1656 if (cfa.reg == STACK_POINTER_REGNUM)
1657 cfa.offset += offset;
1658 if (cfa_store.reg == STACK_POINTER_REGNUM)
1659 cfa_store.offset += offset;
1661 else if (dest == hard_frame_pointer_rtx)
1664 /* Either setting the FP from an offset of the SP,
1665 or adjusting the FP */
1666 gcc_assert (frame_pointer_needed);
1668 gcc_assert (REG_P (XEXP (src, 0))
1669 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1670 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1671 offset = INTVAL (XEXP (src, 1));
1672 if (GET_CODE (src) != MINUS)
1674 cfa.offset += offset;
1675 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1679 gcc_assert (GET_CODE (src) != MINUS);
1682 if (REG_P (XEXP (src, 0))
1683 && REGNO (XEXP (src, 0)) == cfa.reg
1684 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1686 /* Setting a temporary CFA register that will be copied
1687 into the FP later on. */
1688 offset = - INTVAL (XEXP (src, 1));
1689 cfa.offset += offset;
1690 cfa.reg = REGNO (dest);
1691 /* Or used to save regs to the stack. */
1692 cfa_temp.reg = cfa.reg;
1693 cfa_temp.offset = cfa.offset;
1697 else if (REG_P (XEXP (src, 0))
1698 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1699 && XEXP (src, 1) == stack_pointer_rtx)
1701 /* Setting a scratch register that we will use instead
1702 of SP for saving registers to the stack. */
1703 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
1704 cfa_store.reg = REGNO (dest);
1705 cfa_store.offset = cfa.offset - cfa_temp.offset;
1709 else if (GET_CODE (src) == LO_SUM
1710 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1712 cfa_temp.reg = REGNO (dest);
1713 cfa_temp.offset = INTVAL (XEXP (src, 1));
1722 cfa_temp.reg = REGNO (dest);
1723 cfa_temp.offset = INTVAL (src);
1728 gcc_assert (REG_P (XEXP (src, 0))
1729 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
1730 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1732 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1733 cfa_temp.reg = REGNO (dest);
1734 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1737 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1738 which will fill in all of the bits. */
1745 case UNSPEC_VOLATILE:
1746 gcc_assert (targetm.dwarf_handle_frame_unspec);
1747 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
1754 def_cfa_1 (label, &cfa);
1758 gcc_assert (REG_P (src));
1760 /* Saving a register to the stack. Make sure dest is relative to the
1762 switch (GET_CODE (XEXP (dest, 0)))
1767 /* We can't handle variable size modifications. */
1768 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
1770 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1772 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1773 && cfa_store.reg == STACK_POINTER_REGNUM);
1775 cfa_store.offset += offset;
1776 if (cfa.reg == STACK_POINTER_REGNUM)
1777 cfa.offset = cfa_store.offset;
1779 offset = -cfa_store.offset;
1785 offset = GET_MODE_SIZE (GET_MODE (dest));
1786 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1789 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1790 && cfa_store.reg == STACK_POINTER_REGNUM);
1792 cfa_store.offset += offset;
1793 if (cfa.reg == STACK_POINTER_REGNUM)
1794 cfa.offset = cfa_store.offset;
1796 offset = -cfa_store.offset;
1800 /* With an offset. */
1807 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
1808 && REG_P (XEXP (XEXP (dest, 0), 0)));
1809 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1810 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1813 regno = REGNO (XEXP (XEXP (dest, 0), 0));
1815 if (cfa_store.reg == (unsigned) regno)
1816 offset -= cfa_store.offset;
1819 gcc_assert (cfa_temp.reg == (unsigned) regno);
1820 offset -= cfa_temp.offset;
1826 /* Without an offset. */
1829 int regno = REGNO (XEXP (dest, 0));
1831 if (cfa_store.reg == (unsigned) regno)
1832 offset = -cfa_store.offset;
1835 gcc_assert (cfa_temp.reg == (unsigned) regno);
1836 offset = -cfa_temp.offset;
1843 gcc_assert (cfa_temp.reg
1844 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
1845 offset = -cfa_temp.offset;
1846 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1853 if (REGNO (src) != STACK_POINTER_REGNUM
1854 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1855 && (unsigned) REGNO (src) == cfa.reg)
1857 /* We're storing the current CFA reg into the stack. */
1859 if (cfa.offset == 0)
1861 /* If the source register is exactly the CFA, assume
1862 we're saving SP like any other register; this happens
1864 def_cfa_1 (label, &cfa);
1865 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
1870 /* Otherwise, we'll need to look in the stack to
1871 calculate the CFA. */
1872 rtx x = XEXP (dest, 0);
1876 gcc_assert (REG_P (x));
1878 cfa.reg = REGNO (x);
1879 cfa.base_offset = offset;
1881 def_cfa_1 (label, &cfa);
1886 def_cfa_1 (label, &cfa);
1887 queue_reg_save (label, src, NULL_RTX, offset);
1895 /* Record call frame debugging information for INSN, which either
1896 sets SP or FP (adjusting how we calculate the frame address) or saves a
1897 register to the stack. If INSN is NULL_RTX, initialize our state.
1899 If AFTER_P is false, we're being called before the insn is emitted,
1900 otherwise after. Call instructions get invoked twice. */
1903 dwarf2out_frame_debug (rtx insn, bool after_p)
1908 if (insn == NULL_RTX)
1912 /* Flush any queued register saves. */
1913 flush_queued_reg_saves ();
1915 /* Set up state for generating call frame debug info. */
1918 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1920 cfa.reg = STACK_POINTER_REGNUM;
1923 cfa_temp.offset = 0;
1925 for (i = 0; i < num_regs_saved_in_regs; i++)
1927 regs_saved_in_regs[i].orig_reg = NULL_RTX;
1928 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
1930 num_regs_saved_in_regs = 0;
1934 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
1935 flush_queued_reg_saves ();
1937 if (! RTX_FRAME_RELATED_P (insn))
1939 if (!ACCUMULATE_OUTGOING_ARGS)
1940 dwarf2out_stack_adjust (insn, after_p);
1944 label = dwarf2out_cfi_label ();
1945 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1947 insn = XEXP (src, 0);
1949 insn = PATTERN (insn);
1951 dwarf2out_frame_debug_expr (insn, label);
1956 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1957 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1958 (enum dwarf_call_frame_info cfi);
1960 static enum dw_cfi_oprnd_type
1961 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1966 case DW_CFA_GNU_window_save:
1967 return dw_cfi_oprnd_unused;
1969 case DW_CFA_set_loc:
1970 case DW_CFA_advance_loc1:
1971 case DW_CFA_advance_loc2:
1972 case DW_CFA_advance_loc4:
1973 case DW_CFA_MIPS_advance_loc8:
1974 return dw_cfi_oprnd_addr;
1977 case DW_CFA_offset_extended:
1978 case DW_CFA_def_cfa:
1979 case DW_CFA_offset_extended_sf:
1980 case DW_CFA_def_cfa_sf:
1981 case DW_CFA_restore_extended:
1982 case DW_CFA_undefined:
1983 case DW_CFA_same_value:
1984 case DW_CFA_def_cfa_register:
1985 case DW_CFA_register:
1986 return dw_cfi_oprnd_reg_num;
1988 case DW_CFA_def_cfa_offset:
1989 case DW_CFA_GNU_args_size:
1990 case DW_CFA_def_cfa_offset_sf:
1991 return dw_cfi_oprnd_offset;
1993 case DW_CFA_def_cfa_expression:
1994 case DW_CFA_expression:
1995 return dw_cfi_oprnd_loc;
2002 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2003 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2004 (enum dwarf_call_frame_info cfi);
2006 static enum dw_cfi_oprnd_type
2007 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2011 case DW_CFA_def_cfa:
2012 case DW_CFA_def_cfa_sf:
2014 case DW_CFA_offset_extended_sf:
2015 case DW_CFA_offset_extended:
2016 return dw_cfi_oprnd_offset;
2018 case DW_CFA_register:
2019 return dw_cfi_oprnd_reg_num;
2022 return dw_cfi_oprnd_unused;
2026 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2028 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2029 switch to the data section instead, and write out a synthetic label
2033 switch_to_eh_frame_section (void)
2037 #ifdef EH_FRAME_SECTION_NAME
2038 if (eh_frame_section == 0)
2042 if (EH_TABLES_CAN_BE_READ_ONLY)
2048 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2050 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2052 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2054 flags = ((! flag_pic
2055 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2056 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2057 && (per_encoding & 0x70) != DW_EH_PE_absptr
2058 && (per_encoding & 0x70) != DW_EH_PE_aligned
2059 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2060 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2061 ? 0 : SECTION_WRITE);
2064 flags = SECTION_WRITE;
2065 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2069 if (eh_frame_section)
2070 switch_to_section (eh_frame_section);
2073 /* We have no special eh_frame section. Put the information in
2074 the data section and emit special labels to guide collect2. */
2075 switch_to_section (data_section);
2076 label = get_file_function_name ("F");
2077 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2078 targetm.asm_out.globalize_label (asm_out_file,
2079 IDENTIFIER_POINTER (label));
2080 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2084 /* Output a Call Frame Information opcode and its operand(s). */
2087 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2090 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2091 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2092 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2093 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2094 cfi->dw_cfi_oprnd1.dw_cfi_offset);
2095 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2097 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2098 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2099 "DW_CFA_offset, column 0x%lx", r);
2100 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2102 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2104 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2105 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2106 "DW_CFA_restore, column 0x%lx", r);
2110 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2111 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2113 switch (cfi->dw_cfi_opc)
2115 case DW_CFA_set_loc:
2117 dw2_asm_output_encoded_addr_rtx (
2118 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2119 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2122 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2123 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2124 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2127 case DW_CFA_advance_loc1:
2128 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2129 fde->dw_fde_current_label, NULL);
2130 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2133 case DW_CFA_advance_loc2:
2134 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2135 fde->dw_fde_current_label, NULL);
2136 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2139 case DW_CFA_advance_loc4:
2140 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2141 fde->dw_fde_current_label, NULL);
2142 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2145 case DW_CFA_MIPS_advance_loc8:
2146 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2147 fde->dw_fde_current_label, NULL);
2148 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2151 case DW_CFA_offset_extended:
2152 case DW_CFA_def_cfa:
2153 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2154 dw2_asm_output_data_uleb128 (r, NULL);
2155 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2158 case DW_CFA_offset_extended_sf:
2159 case DW_CFA_def_cfa_sf:
2160 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2161 dw2_asm_output_data_uleb128 (r, NULL);
2162 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2165 case DW_CFA_restore_extended:
2166 case DW_CFA_undefined:
2167 case DW_CFA_same_value:
2168 case DW_CFA_def_cfa_register:
2169 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2170 dw2_asm_output_data_uleb128 (r, NULL);
2173 case DW_CFA_register:
2174 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2175 dw2_asm_output_data_uleb128 (r, NULL);
2176 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2177 dw2_asm_output_data_uleb128 (r, NULL);
2180 case DW_CFA_def_cfa_offset:
2181 case DW_CFA_GNU_args_size:
2182 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2185 case DW_CFA_def_cfa_offset_sf:
2186 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2189 case DW_CFA_GNU_window_save:
2192 case DW_CFA_def_cfa_expression:
2193 case DW_CFA_expression:
2194 output_cfa_loc (cfi);
2197 case DW_CFA_GNU_negative_offset_extended:
2198 /* Obsoleted by DW_CFA_offset_extended_sf. */
2207 /* Output the call frame information used to record information
2208 that relates to calculating the frame pointer, and records the
2209 location of saved registers. */
2212 output_call_frame_info (int for_eh)
2217 char l1[20], l2[20], section_start_label[20];
2218 bool any_lsda_needed = false;
2219 char augmentation[6];
2220 int augmentation_size;
2221 int fde_encoding = DW_EH_PE_absptr;
2222 int per_encoding = DW_EH_PE_absptr;
2223 int lsda_encoding = DW_EH_PE_absptr;
2226 /* Don't emit a CIE if there won't be any FDEs. */
2227 if (fde_table_in_use == 0)
2230 /* If we make FDEs linkonce, we may have to emit an empty label for
2231 an FDE that wouldn't otherwise be emitted. We want to avoid
2232 having an FDE kept around when the function it refers to is
2233 discarded. Example where this matters: a primary function
2234 template in C++ requires EH information, but an explicit
2235 specialization doesn't. */
2236 if (TARGET_USES_WEAK_UNWIND_INFO
2237 && ! flag_asynchronous_unwind_tables
2240 for (i = 0; i < fde_table_in_use; i++)
2241 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2242 && !fde_table[i].uses_eh_lsda
2243 && ! DECL_WEAK (fde_table[i].decl))
2244 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2245 for_eh, /* empty */ 1);
2247 /* If we don't have any functions we'll want to unwind out of, don't
2248 emit any EH unwind information. Note that if exceptions aren't
2249 enabled, we won't have collected nothrow information, and if we
2250 asked for asynchronous tables, we always want this info. */
2253 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2255 for (i = 0; i < fde_table_in_use; i++)
2256 if (fde_table[i].uses_eh_lsda)
2257 any_eh_needed = any_lsda_needed = true;
2258 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2259 any_eh_needed = true;
2260 else if (! fde_table[i].nothrow
2261 && ! fde_table[i].all_throwers_are_sibcalls)
2262 any_eh_needed = true;
2264 if (! any_eh_needed)
2268 /* We're going to be generating comments, so turn on app. */
2273 switch_to_eh_frame_section ();
2276 if (!debug_frame_section)
2277 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
2278 SECTION_DEBUG, NULL);
2279 switch_to_section (debug_frame_section);
2282 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2283 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2285 /* Output the CIE. */
2286 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2287 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2288 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2289 dw2_asm_output_data (4, 0xffffffff,
2290 "Initial length escape value indicating 64-bit DWARF extension");
2291 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2292 "Length of Common Information Entry");
2293 ASM_OUTPUT_LABEL (asm_out_file, l1);
2295 /* Now that the CIE pointer is PC-relative for EH,
2296 use 0 to identify the CIE. */
2297 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2298 (for_eh ? 0 : DWARF_CIE_ID),
2299 "CIE Identifier Tag");
2301 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2303 augmentation[0] = 0;
2304 augmentation_size = 0;
2310 z Indicates that a uleb128 is present to size the
2311 augmentation section.
2312 L Indicates the encoding (and thus presence) of
2313 an LSDA pointer in the FDE augmentation.
2314 R Indicates a non-default pointer encoding for
2316 P Indicates the presence of an encoding + language
2317 personality routine in the CIE augmentation. */
2319 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2320 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2321 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2323 p = augmentation + 1;
2324 if (eh_personality_libfunc)
2327 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2328 assemble_external_libcall (eh_personality_libfunc);
2330 if (any_lsda_needed)
2333 augmentation_size += 1;
2335 if (fde_encoding != DW_EH_PE_absptr)
2338 augmentation_size += 1;
2340 if (p > augmentation + 1)
2342 augmentation[0] = 'z';
2346 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2347 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2349 int offset = ( 4 /* Length */
2351 + 1 /* CIE version */
2352 + strlen (augmentation) + 1 /* Augmentation */
2353 + size_of_uleb128 (1) /* Code alignment */
2354 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2356 + 1 /* Augmentation size */
2357 + 1 /* Personality encoding */ );
2358 int pad = -offset & (PTR_SIZE - 1);
2360 augmentation_size += pad;
2362 /* Augmentations should be small, so there's scarce need to
2363 iterate for a solution. Die if we exceed one uleb128 byte. */
2364 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2368 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2369 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2370 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2371 "CIE Data Alignment Factor");
2373 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2374 if (DW_CIE_VERSION == 1)
2375 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2377 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2379 if (augmentation[0])
2381 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2382 if (eh_personality_libfunc)
2384 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2385 eh_data_format_name (per_encoding));
2386 dw2_asm_output_encoded_addr_rtx (per_encoding,
2387 eh_personality_libfunc,
2391 if (any_lsda_needed)
2392 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2393 eh_data_format_name (lsda_encoding));
2395 if (fde_encoding != DW_EH_PE_absptr)
2396 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2397 eh_data_format_name (fde_encoding));
2400 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2401 output_cfi (cfi, NULL, for_eh);
2403 /* Pad the CIE out to an address sized boundary. */
2404 ASM_OUTPUT_ALIGN (asm_out_file,
2405 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2406 ASM_OUTPUT_LABEL (asm_out_file, l2);
2408 /* Loop through all of the FDE's. */
2409 for (i = 0; i < fde_table_in_use; i++)
2411 fde = &fde_table[i];
2413 /* Don't emit EH unwind info for leaf functions that don't need it. */
2414 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2415 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2416 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2417 && !fde->uses_eh_lsda)
2420 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2421 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2422 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2423 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2424 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2425 dw2_asm_output_data (4, 0xffffffff,
2426 "Initial length escape value indicating 64-bit DWARF extension");
2427 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2429 ASM_OUTPUT_LABEL (asm_out_file, l1);
2432 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2434 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2435 debug_frame_section, "FDE CIE offset");
2439 if (fde->dw_fde_switched_sections)
2441 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2442 fde->dw_fde_unlikely_section_label);
2443 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2444 fde->dw_fde_hot_section_label);
2445 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2446 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2447 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
2448 "FDE initial location");
2449 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2450 fde->dw_fde_hot_section_end_label,
2451 fde->dw_fde_hot_section_label,
2452 "FDE address range");
2453 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
2454 "FDE initial location");
2455 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2456 fde->dw_fde_unlikely_section_end_label,
2457 fde->dw_fde_unlikely_section_label,
2458 "FDE address range");
2462 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2463 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2464 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2467 "FDE initial location");
2468 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2469 fde->dw_fde_end, fde->dw_fde_begin,
2470 "FDE address range");
2475 if (fde->dw_fde_switched_sections)
2477 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2478 fde->dw_fde_hot_section_label,
2479 "FDE initial location");
2480 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2481 fde->dw_fde_hot_section_end_label,
2482 fde->dw_fde_hot_section_label,
2483 "FDE address range");
2484 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2485 fde->dw_fde_unlikely_section_label,
2486 "FDE initial location");
2487 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2488 fde->dw_fde_unlikely_section_end_label,
2489 fde->dw_fde_unlikely_section_label,
2490 "FDE address range");
2494 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2495 "FDE initial location");
2496 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2497 fde->dw_fde_end, fde->dw_fde_begin,
2498 "FDE address range");
2502 if (augmentation[0])
2504 if (any_lsda_needed)
2506 int size = size_of_encoded_value (lsda_encoding);
2508 if (lsda_encoding == DW_EH_PE_aligned)
2510 int offset = ( 4 /* Length */
2511 + 4 /* CIE offset */
2512 + 2 * size_of_encoded_value (fde_encoding)
2513 + 1 /* Augmentation size */ );
2514 int pad = -offset & (PTR_SIZE - 1);
2517 gcc_assert (size_of_uleb128 (size) == 1);
2520 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2522 if (fde->uses_eh_lsda)
2524 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2525 fde->funcdef_number);
2526 dw2_asm_output_encoded_addr_rtx (
2527 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2528 false, "Language Specific Data Area");
2532 if (lsda_encoding == DW_EH_PE_aligned)
2533 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2535 (size_of_encoded_value (lsda_encoding), 0,
2536 "Language Specific Data Area (none)");
2540 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2543 /* Loop through the Call Frame Instructions associated with
2545 fde->dw_fde_current_label = fde->dw_fde_begin;
2546 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2547 output_cfi (cfi, fde, for_eh);
2549 /* Pad the FDE out to an address sized boundary. */
2550 ASM_OUTPUT_ALIGN (asm_out_file,
2551 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2552 ASM_OUTPUT_LABEL (asm_out_file, l2);
2555 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2556 dw2_asm_output_data (4, 0, "End of Table");
2557 #ifdef MIPS_DEBUGGING_INFO
2558 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2559 get a value of 0. Putting .align 0 after the label fixes it. */
2560 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2563 /* Turn off app to make assembly quicker. */
2568 /* Output a marker (i.e. a label) for the beginning of a function, before
2572 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2573 const char *file ATTRIBUTE_UNUSED)
2575 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2579 current_function_func_begin_label = NULL;
2581 #ifdef TARGET_UNWIND_INFO
2582 /* ??? current_function_func_begin_label is also used by except.c
2583 for call-site information. We must emit this label if it might
2585 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2586 && ! dwarf2out_do_frame ())
2589 if (! dwarf2out_do_frame ())
2593 switch_to_section (function_section (current_function_decl));
2594 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2595 current_function_funcdef_no);
2596 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2597 current_function_funcdef_no);
2598 dup_label = xstrdup (label);
2599 current_function_func_begin_label = dup_label;
2601 #ifdef TARGET_UNWIND_INFO
2602 /* We can elide the fde allocation if we're not emitting debug info. */
2603 if (! dwarf2out_do_frame ())
2607 /* Expand the fde table if necessary. */
2608 if (fde_table_in_use == fde_table_allocated)
2610 fde_table_allocated += FDE_TABLE_INCREMENT;
2611 fde_table = ggc_realloc (fde_table,
2612 fde_table_allocated * sizeof (dw_fde_node));
2613 memset (fde_table + fde_table_in_use, 0,
2614 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2617 /* Record the FDE associated with this function. */
2618 current_funcdef_fde = fde_table_in_use;
2620 /* Add the new FDE at the end of the fde_table. */
2621 fde = &fde_table[fde_table_in_use++];
2622 fde->decl = current_function_decl;
2623 fde->dw_fde_begin = dup_label;
2624 fde->dw_fde_current_label = dup_label;
2625 fde->dw_fde_hot_section_label = NULL;
2626 fde->dw_fde_hot_section_end_label = NULL;
2627 fde->dw_fde_unlikely_section_label = NULL;
2628 fde->dw_fde_unlikely_section_end_label = NULL;
2629 fde->dw_fde_switched_sections = false;
2630 fde->dw_fde_end = NULL;
2631 fde->dw_fde_cfi = NULL;
2632 fde->funcdef_number = current_function_funcdef_no;
2633 fde->nothrow = TREE_NOTHROW (current_function_decl);
2634 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2635 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2637 args_size = old_args_size = 0;
2639 /* We only want to output line number information for the genuine dwarf2
2640 prologue case, not the eh frame case. */
2641 #ifdef DWARF2_DEBUGGING_INFO
2643 dwarf2out_source_line (line, file);
2647 /* Output a marker (i.e. a label) for the absolute end of the generated code
2648 for a function definition. This gets called *after* the epilogue code has
2652 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2653 const char *file ATTRIBUTE_UNUSED)
2656 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2658 /* Output a label to mark the endpoint of the code generated for this
2660 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2661 current_function_funcdef_no);
2662 ASM_OUTPUT_LABEL (asm_out_file, label);
2663 fde = &fde_table[fde_table_in_use - 1];
2664 fde->dw_fde_end = xstrdup (label);
2668 dwarf2out_frame_init (void)
2670 /* Allocate the initial hunk of the fde_table. */
2671 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2672 fde_table_allocated = FDE_TABLE_INCREMENT;
2673 fde_table_in_use = 0;
2675 /* Generate the CFA instructions common to all FDE's. Do it now for the
2676 sake of lookup_cfa. */
2678 /* On entry, the Canonical Frame Address is at SP. */
2679 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2681 #ifdef DWARF2_UNWIND_INFO
2682 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
2683 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2688 dwarf2out_frame_finish (void)
2690 /* Output call frame information. */
2691 if (DWARF2_FRAME_INFO)
2692 output_call_frame_info (0);
2694 #ifndef TARGET_UNWIND_INFO
2695 /* Output another copy for the unwinder. */
2696 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2697 output_call_frame_info (1);
2701 /* Note that the current function section is being used for code. */
2704 dwarf2out_note_section_used (void)
2706 section *sec = current_function_section ();
2707 if (sec == text_section)
2708 text_section_used = true;
2709 else if (sec == cold_text_section)
2710 cold_text_section_used = true;
2714 dwarf2out_switch_text_section (void)
2720 fde = &fde_table[fde_table_in_use - 1];
2721 fde->dw_fde_switched_sections = true;
2722 fde->dw_fde_hot_section_label = cfun->hot_section_label;
2723 fde->dw_fde_hot_section_end_label = cfun->hot_section_end_label;
2724 fde->dw_fde_unlikely_section_label = cfun->cold_section_label;
2725 fde->dw_fde_unlikely_section_end_label = cfun->cold_section_end_label;
2726 have_multiple_function_sections = true;
2728 /* Reset the current label on switching text sections, so that we
2729 don't attempt to advance_loc4 between labels in different sections. */
2730 fde->dw_fde_current_label = NULL;
2732 /* There is no need to mark used sections when not debugging. */
2733 if (cold_text_section != NULL)
2734 dwarf2out_note_section_used ();
2738 /* And now, the subset of the debugging information support code necessary
2739 for emitting location expressions. */
2741 /* Data about a single source file. */
2742 struct dwarf_file_data GTY(())
2744 const char * filename;
2748 /* We need some way to distinguish DW_OP_addr with a direct symbol
2749 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2750 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2753 typedef struct dw_val_struct *dw_val_ref;
2754 typedef struct die_struct *dw_die_ref;
2755 typedef const struct die_struct *const_dw_die_ref;
2756 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2757 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2759 /* Each DIE may have a series of attribute/value pairs. Values
2760 can take on several forms. The forms that are used in this
2761 implementation are listed below. */
2766 dw_val_class_offset,
2768 dw_val_class_loc_list,
2769 dw_val_class_range_list,
2771 dw_val_class_unsigned_const,
2772 dw_val_class_long_long,
2775 dw_val_class_die_ref,
2776 dw_val_class_fde_ref,
2777 dw_val_class_lbl_id,
2778 dw_val_class_lineptr,
2780 dw_val_class_macptr,
2784 /* Describe a double word constant value. */
2785 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2787 typedef struct dw_long_long_struct GTY(())
2794 /* Describe a floating point constant value, or a vector constant value. */
2796 typedef struct dw_vec_struct GTY(())
2798 unsigned char * GTY((length ("%h.length"))) array;
2804 /* The dw_val_node describes an attribute's value, as it is
2805 represented internally. */
2807 typedef struct dw_val_struct GTY(())
2809 enum dw_val_class val_class;
2810 union dw_val_struct_union
2812 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2813 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2814 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2815 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2816 HOST_WIDE_INT GTY ((default)) val_int;
2817 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2818 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2819 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2820 struct dw_val_die_union
2824 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2825 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2826 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2827 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2828 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2829 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
2831 GTY ((desc ("%1.val_class"))) v;
2835 /* Locations in memory are described using a sequence of stack machine
2838 typedef struct dw_loc_descr_struct GTY(())
2840 dw_loc_descr_ref dw_loc_next;
2841 enum dwarf_location_atom dw_loc_opc;
2842 dw_val_node dw_loc_oprnd1;
2843 dw_val_node dw_loc_oprnd2;
2848 /* Location lists are ranges + location descriptions for that range,
2849 so you can track variables that are in different places over
2850 their entire life. */
2851 typedef struct dw_loc_list_struct GTY(())
2853 dw_loc_list_ref dw_loc_next;
2854 const char *begin; /* Label for begin address of range */
2855 const char *end; /* Label for end address of range */
2856 char *ll_symbol; /* Label for beginning of location list.
2857 Only on head of list */
2858 const char *section; /* Section this loclist is relative to */
2859 dw_loc_descr_ref expr;
2862 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2864 static const char *dwarf_stack_op_name (unsigned);
2865 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2866 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2867 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2868 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2869 static unsigned long size_of_locs (dw_loc_descr_ref);
2870 static void output_loc_operands (dw_loc_descr_ref);
2871 static void output_loc_sequence (dw_loc_descr_ref);
2873 /* Convert a DWARF stack opcode into its string name. */
2876 dwarf_stack_op_name (unsigned int op)
2881 case INTERNAL_DW_OP_tls_addr:
2882 return "DW_OP_addr";
2884 return "DW_OP_deref";
2886 return "DW_OP_const1u";
2888 return "DW_OP_const1s";
2890 return "DW_OP_const2u";
2892 return "DW_OP_const2s";
2894 return "DW_OP_const4u";
2896 return "DW_OP_const4s";
2898 return "DW_OP_const8u";
2900 return "DW_OP_const8s";
2902 return "DW_OP_constu";
2904 return "DW_OP_consts";
2908 return "DW_OP_drop";
2910 return "DW_OP_over";
2912 return "DW_OP_pick";
2914 return "DW_OP_swap";
2918 return "DW_OP_xderef";
2926 return "DW_OP_minus";
2938 return "DW_OP_plus";
2939 case DW_OP_plus_uconst:
2940 return "DW_OP_plus_uconst";
2946 return "DW_OP_shra";
2964 return "DW_OP_skip";
2966 return "DW_OP_lit0";
2968 return "DW_OP_lit1";
2970 return "DW_OP_lit2";
2972 return "DW_OP_lit3";
2974 return "DW_OP_lit4";
2976 return "DW_OP_lit5";
2978 return "DW_OP_lit6";
2980 return "DW_OP_lit7";
2982 return "DW_OP_lit8";
2984 return "DW_OP_lit9";
2986 return "DW_OP_lit10";
2988 return "DW_OP_lit11";
2990 return "DW_OP_lit12";
2992 return "DW_OP_lit13";
2994 return "DW_OP_lit14";
2996 return "DW_OP_lit15";
2998 return "DW_OP_lit16";
3000 return "DW_OP_lit17";
3002 return "DW_OP_lit18";
3004 return "DW_OP_lit19";
3006 return "DW_OP_lit20";
3008 return "DW_OP_lit21";
3010 return "DW_OP_lit22";
3012 return "DW_OP_lit23";
3014 return "DW_OP_lit24";
3016 return "DW_OP_lit25";
3018 return "DW_OP_lit26";
3020 return "DW_OP_lit27";
3022 return "DW_OP_lit28";
3024 return "DW_OP_lit29";
3026 return "DW_OP_lit30";
3028 return "DW_OP_lit31";
3030 return "DW_OP_reg0";
3032 return "DW_OP_reg1";
3034 return "DW_OP_reg2";
3036 return "DW_OP_reg3";
3038 return "DW_OP_reg4";
3040 return "DW_OP_reg5";
3042 return "DW_OP_reg6";
3044 return "DW_OP_reg7";
3046 return "DW_OP_reg8";
3048 return "DW_OP_reg9";
3050 return "DW_OP_reg10";
3052 return "DW_OP_reg11";
3054 return "DW_OP_reg12";
3056 return "DW_OP_reg13";
3058 return "DW_OP_reg14";
3060 return "DW_OP_reg15";
3062 return "DW_OP_reg16";
3064 return "DW_OP_reg17";
3066 return "DW_OP_reg18";
3068 return "DW_OP_reg19";
3070 return "DW_OP_reg20";
3072 return "DW_OP_reg21";
3074 return "DW_OP_reg22";
3076 return "DW_OP_reg23";
3078 return "DW_OP_reg24";
3080 return "DW_OP_reg25";
3082 return "DW_OP_reg26";
3084 return "DW_OP_reg27";
3086 return "DW_OP_reg28";
3088 return "DW_OP_reg29";
3090 return "DW_OP_reg30";
3092 return "DW_OP_reg31";
3094 return "DW_OP_breg0";
3096 return "DW_OP_breg1";
3098 return "DW_OP_breg2";
3100 return "DW_OP_breg3";
3102 return "DW_OP_breg4";
3104 return "DW_OP_breg5";
3106 return "DW_OP_breg6";
3108 return "DW_OP_breg7";
3110 return "DW_OP_breg8";
3112 return "DW_OP_breg9";
3114 return "DW_OP_breg10";
3116 return "DW_OP_breg11";
3118 return "DW_OP_breg12";
3120 return "DW_OP_breg13";
3122 return "DW_OP_breg14";
3124 return "DW_OP_breg15";
3126 return "DW_OP_breg16";
3128 return "DW_OP_breg17";
3130 return "DW_OP_breg18";
3132 return "DW_OP_breg19";
3134 return "DW_OP_breg20";
3136 return "DW_OP_breg21";
3138 return "DW_OP_breg22";
3140 return "DW_OP_breg23";
3142 return "DW_OP_breg24";
3144 return "DW_OP_breg25";
3146 return "DW_OP_breg26";
3148 return "DW_OP_breg27";
3150 return "DW_OP_breg28";
3152 return "DW_OP_breg29";
3154 return "DW_OP_breg30";
3156 return "DW_OP_breg31";
3158 return "DW_OP_regx";
3160 return "DW_OP_fbreg";
3162 return "DW_OP_bregx";
3164 return "DW_OP_piece";
3165 case DW_OP_deref_size:
3166 return "DW_OP_deref_size";
3167 case DW_OP_xderef_size:
3168 return "DW_OP_xderef_size";
3171 case DW_OP_push_object_address:
3172 return "DW_OP_push_object_address";
3174 return "DW_OP_call2";
3176 return "DW_OP_call4";
3177 case DW_OP_call_ref:
3178 return "DW_OP_call_ref";
3179 case DW_OP_GNU_push_tls_address:
3180 return "DW_OP_GNU_push_tls_address";
3181 case DW_OP_GNU_uninit:
3182 return "DW_OP_GNU_uninit";
3184 return "OP_<unknown>";
3188 /* Return a pointer to a newly allocated location description. Location
3189 descriptions are simple expression terms that can be strung
3190 together to form more complicated location (address) descriptions. */
3192 static inline dw_loc_descr_ref
3193 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3194 unsigned HOST_WIDE_INT oprnd2)
3196 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
3198 descr->dw_loc_opc = op;
3199 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3200 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3201 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3202 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3207 /* Add a location description term to a location description expression. */
3210 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3212 dw_loc_descr_ref *d;
3214 /* Find the end of the chain. */
3215 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3221 /* Return the size of a location descriptor. */
3223 static unsigned long
3224 size_of_loc_descr (dw_loc_descr_ref loc)
3226 unsigned long size = 1;
3228 switch (loc->dw_loc_opc)
3231 case INTERNAL_DW_OP_tls_addr:
3232 size += DWARF2_ADDR_SIZE;
3251 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3254 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3259 case DW_OP_plus_uconst:
3260 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3298 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3301 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3304 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3307 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3308 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3311 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3313 case DW_OP_deref_size:
3314 case DW_OP_xderef_size:
3323 case DW_OP_call_ref:
3324 size += DWARF2_ADDR_SIZE;
3333 /* Return the size of a series of location descriptors. */
3335 static unsigned long
3336 size_of_locs (dw_loc_descr_ref loc)
3341 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3342 field, to avoid writing to a PCH file. */
3343 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3345 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
3347 size += size_of_loc_descr (l);
3352 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3354 l->dw_loc_addr = size;
3355 size += size_of_loc_descr (l);
3361 /* Output location description stack opcode's operands (if any). */
3364 output_loc_operands (dw_loc_descr_ref loc)
3366 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3367 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3369 switch (loc->dw_loc_opc)
3371 #ifdef DWARF2_DEBUGGING_INFO
3373 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3377 dw2_asm_output_data (2, val1->v.val_int, NULL);
3381 dw2_asm_output_data (4, val1->v.val_int, NULL);
3385 gcc_assert (HOST_BITS_PER_LONG >= 64);
3386 dw2_asm_output_data (8, val1->v.val_int, NULL);
3393 gcc_assert (val1->val_class == dw_val_class_loc);
3394 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3396 dw2_asm_output_data (2, offset, NULL);
3409 /* We currently don't make any attempt to make sure these are
3410 aligned properly like we do for the main unwind info, so
3411 don't support emitting things larger than a byte if we're
3412 only doing unwinding. */
3417 dw2_asm_output_data (1, val1->v.val_int, NULL);
3420 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3423 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3426 dw2_asm_output_data (1, val1->v.val_int, NULL);
3428 case DW_OP_plus_uconst:
3429 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3463 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3466 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3469 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3472 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3473 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3476 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3478 case DW_OP_deref_size:
3479 case DW_OP_xderef_size:
3480 dw2_asm_output_data (1, val1->v.val_int, NULL);
3483 case INTERNAL_DW_OP_tls_addr:
3484 if (targetm.asm_out.output_dwarf_dtprel)
3486 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
3489 fputc ('\n', asm_out_file);
3496 /* Other codes have no operands. */
3501 /* Output a sequence of location operations. */
3504 output_loc_sequence (dw_loc_descr_ref loc)
3506 for (; loc != NULL; loc = loc->dw_loc_next)
3508 /* Output the opcode. */
3509 dw2_asm_output_data (1, loc->dw_loc_opc,
3510 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3512 /* Output the operand(s) (if any). */
3513 output_loc_operands (loc);
3517 /* This routine will generate the correct assembly data for a location
3518 description based on a cfi entry with a complex address. */
3521 output_cfa_loc (dw_cfi_ref cfi)
3523 dw_loc_descr_ref loc;
3526 /* Output the size of the block. */
3527 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3528 size = size_of_locs (loc);
3529 dw2_asm_output_data_uleb128 (size, NULL);
3531 /* Now output the operations themselves. */
3532 output_loc_sequence (loc);
3535 /* This function builds a dwarf location descriptor sequence from a
3536 dw_cfa_location, adding the given OFFSET to the result of the
3539 static struct dw_loc_descr_struct *
3540 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
3542 struct dw_loc_descr_struct *head, *tmp;
3544 offset += cfa->offset;
3548 if (cfa->base_offset)
3551 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3553 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3555 else if (cfa->reg <= 31)
3556 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3558 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3560 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3561 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3562 add_loc_descr (&head, tmp);
3565 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
3566 add_loc_descr (&head, tmp);
3573 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3575 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3576 else if (cfa->reg <= 31)
3577 head = new_loc_descr (DW_OP_breg0 + cfa->reg, offset, 0);
3579 head = new_loc_descr (DW_OP_bregx, cfa->reg, offset);
3585 /* This function fills in aa dw_cfa_location structure from a dwarf location
3586 descriptor sequence. */
3589 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3591 struct dw_loc_descr_struct *ptr;
3593 cfa->base_offset = 0;
3597 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)