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 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 /* Decide whether we want to emit frame unwind information for the current
97 dwarf2out_do_frame (void)
99 return (write_symbols == DWARF2_DEBUG
100 || write_symbols == VMS_AND_DWARF2_DEBUG
101 #ifdef DWARF2_FRAME_INFO
104 #ifdef DWARF2_UNWIND_INFO
105 || flag_unwind_tables
106 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
111 /* The size of the target's pointer type. */
113 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
116 /* Various versions of targetm.eh_frame_section. Note these must appear
117 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro guards. */
119 /* Version of targetm.eh_frame_section for systems with named sections. */
121 named_section_eh_frame_section (void)
123 #ifdef EH_FRAME_SECTION_NAME
126 if (EH_TABLES_CAN_BE_READ_ONLY)
132 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
133 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
134 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
136 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
137 && (fde_encoding & 0x70) != DW_EH_PE_aligned
138 && (per_encoding & 0x70) != DW_EH_PE_absptr
139 && (per_encoding & 0x70) != DW_EH_PE_aligned
140 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
141 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
145 flags = SECTION_WRITE;
146 named_section_flags (EH_FRAME_SECTION_NAME, flags);
150 /* Version of targetm.eh_frame_section for systems using collect2. */
152 collect2_eh_frame_section (void)
154 tree label = get_file_function_name ('F');
157 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
158 targetm.asm_out.globalize_label (asm_out_file, IDENTIFIER_POINTER (label));
159 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
162 /* Default version of targetm.eh_frame_section. */
164 default_eh_frame_section (void)
166 #ifdef EH_FRAME_SECTION_NAME
167 named_section_eh_frame_section ();
169 collect2_eh_frame_section ();
174 DEF_VEC_ALLOC_P(rtx,gc);
176 /* Array of RTXes referenced by the debugging information, which therefore
177 must be kept around forever. */
178 static GTY(()) VEC(rtx,gc) *used_rtx_array;
180 /* A pointer to the base of a list of incomplete types which might be
181 completed at some later time. incomplete_types_list needs to be a
182 VEC(tree,gc) because we want to tell the garbage collector about
184 static GTY(()) VEC(tree,gc) *incomplete_types;
186 /* A pointer to the base of a table of references to declaration
187 scopes. This table is a display which tracks the nesting
188 of declaration scopes at the current scope and containing
189 scopes. This table is used to find the proper place to
190 define type declaration DIE's. */
191 static GTY(()) VEC(tree,gc) *decl_scope_table;
193 /* How to start an assembler comment. */
194 #ifndef ASM_COMMENT_START
195 #define ASM_COMMENT_START ";#"
198 typedef struct dw_cfi_struct *dw_cfi_ref;
199 typedef struct dw_fde_struct *dw_fde_ref;
200 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
202 /* Call frames are described using a sequence of Call Frame
203 Information instructions. The register number, offset
204 and address fields are provided as possible operands;
205 their use is selected by the opcode field. */
207 enum dw_cfi_oprnd_type {
209 dw_cfi_oprnd_reg_num,
215 typedef union dw_cfi_oprnd_struct GTY(())
217 unsigned long GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
218 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
219 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
220 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
224 typedef struct dw_cfi_struct GTY(())
226 dw_cfi_ref dw_cfi_next;
227 enum dwarf_call_frame_info dw_cfi_opc;
228 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
230 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
235 /* This is how we define the location of the CFA. We use to handle it
236 as REG + OFFSET all the time, but now it can be more complex.
237 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
238 Instead of passing around REG and OFFSET, we pass a copy
239 of this structure. */
240 typedef struct cfa_loc GTY(())
243 HOST_WIDE_INT offset;
244 HOST_WIDE_INT base_offset;
245 int indirect; /* 1 if CFA is accessed via a dereference. */
248 /* All call frame descriptions (FDE's) in the GCC generated DWARF
249 refer to a single Common Information Entry (CIE), defined at
250 the beginning of the .debug_frame section. This use of a single
251 CIE obviates the need to keep track of multiple CIE's
252 in the DWARF generation routines below. */
254 typedef struct dw_fde_struct GTY(())
257 const char *dw_fde_begin;
258 const char *dw_fde_current_label;
259 const char *dw_fde_end;
260 const char *dw_fde_hot_section_label;
261 const char *dw_fde_hot_section_end_label;
262 const char *dw_fde_unlikely_section_label;
263 const char *dw_fde_unlikely_section_end_label;
264 bool dw_fde_switched_sections;
265 dw_cfi_ref dw_fde_cfi;
266 unsigned funcdef_number;
267 unsigned all_throwers_are_sibcalls : 1;
268 unsigned nothrow : 1;
269 unsigned uses_eh_lsda : 1;
273 /* Maximum size (in bytes) of an artificially generated label. */
274 #define MAX_ARTIFICIAL_LABEL_BYTES 30
276 /* The size of addresses as they appear in the Dwarf 2 data.
277 Some architectures use word addresses to refer to code locations,
278 but Dwarf 2 info always uses byte addresses. On such machines,
279 Dwarf 2 addresses need to be larger than the architecture's
281 #ifndef DWARF2_ADDR_SIZE
282 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
285 /* The size in bytes of a DWARF field indicating an offset or length
286 relative to a debug info section, specified to be 4 bytes in the
287 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
290 #ifndef DWARF_OFFSET_SIZE
291 #define DWARF_OFFSET_SIZE 4
294 /* According to the (draft) DWARF 3 specification, the initial length
295 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
296 bytes are 0xffffffff, followed by the length stored in the next 8
299 However, the SGI/MIPS ABI uses an initial length which is equal to
300 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
302 #ifndef DWARF_INITIAL_LENGTH_SIZE
303 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
306 #define DWARF_VERSION 2
308 /* Round SIZE up to the nearest BOUNDARY. */
309 #define DWARF_ROUND(SIZE,BOUNDARY) \
310 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
312 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
313 #ifndef DWARF_CIE_DATA_ALIGNMENT
314 #ifdef STACK_GROWS_DOWNWARD
315 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
317 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
321 /* A pointer to the base of a table that contains frame description
322 information for each routine. */
323 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
325 /* Number of elements currently allocated for fde_table. */
326 static GTY(()) unsigned fde_table_allocated;
328 /* Number of elements in fde_table currently in use. */
329 static GTY(()) unsigned fde_table_in_use;
331 /* Size (in elements) of increments by which we may expand the
333 #define FDE_TABLE_INCREMENT 256
335 /* A list of call frame insns for the CIE. */
336 static GTY(()) dw_cfi_ref cie_cfi_head;
338 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
339 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
340 attribute that accelerates the lookup of the FDE associated
341 with the subprogram. This variable holds the table index of the FDE
342 associated with the current function (body) definition. */
343 static unsigned current_funcdef_fde;
346 struct indirect_string_node GTY(())
349 unsigned int refcount;
354 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
356 static GTY(()) int dw2_string_counter;
357 static GTY(()) unsigned long dwarf2out_cfi_label_num;
359 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
361 /* Forward declarations for functions defined in this file. */
363 static char *stripattributes (const char *);
364 static const char *dwarf_cfi_name (unsigned);
365 static dw_cfi_ref new_cfi (void);
366 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
367 static void add_fde_cfi (const char *, dw_cfi_ref);
368 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
369 static void lookup_cfa (dw_cfa_location *);
370 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
371 static void initial_return_save (rtx);
372 static HOST_WIDE_INT stack_adjust_offset (rtx);
373 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
374 static void output_call_frame_info (int);
375 static void dwarf2out_stack_adjust (rtx, bool);
376 static void flush_queued_reg_saves (void);
377 static bool clobbers_queued_reg_save (rtx);
378 static void dwarf2out_frame_debug_expr (rtx, const char *);
380 /* Support for complex CFA locations. */
381 static void output_cfa_loc (dw_cfi_ref);
382 static void get_cfa_from_loc_descr (dw_cfa_location *,
383 struct dw_loc_descr_struct *);
384 static struct dw_loc_descr_struct *build_cfa_loc
386 static void def_cfa_1 (const char *, dw_cfa_location *);
388 /* How to start an assembler comment. */
389 #ifndef ASM_COMMENT_START
390 #define ASM_COMMENT_START ";#"
393 /* Data and reference forms for relocatable data. */
394 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
395 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
397 #ifndef DEBUG_FRAME_SECTION
398 #define DEBUG_FRAME_SECTION ".debug_frame"
401 #ifndef FUNC_BEGIN_LABEL
402 #define FUNC_BEGIN_LABEL "LFB"
405 #ifndef FUNC_END_LABEL
406 #define FUNC_END_LABEL "LFE"
409 #ifndef FRAME_BEGIN_LABEL
410 #define FRAME_BEGIN_LABEL "Lframe"
412 #define CIE_AFTER_SIZE_LABEL "LSCIE"
413 #define CIE_END_LABEL "LECIE"
414 #define FDE_LABEL "LSFDE"
415 #define FDE_AFTER_SIZE_LABEL "LASFDE"
416 #define FDE_END_LABEL "LEFDE"
417 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
418 #define LINE_NUMBER_END_LABEL "LELT"
419 #define LN_PROLOG_AS_LABEL "LASLTP"
420 #define LN_PROLOG_END_LABEL "LELTP"
421 #define DIE_LABEL_PREFIX "DW"
423 /* The DWARF 2 CFA column which tracks the return address. Normally this
424 is the column for PC, or the first column after all of the hard
426 #ifndef DWARF_FRAME_RETURN_COLUMN
428 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
430 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
434 /* The mapping from gcc register number to DWARF 2 CFA column number. By
435 default, we just provide columns for all registers. */
436 #ifndef DWARF_FRAME_REGNUM
437 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
440 /* The offset from the incoming value of %sp to the top of the stack frame
441 for the current function. */
442 #ifndef INCOMING_FRAME_SP_OFFSET
443 #define INCOMING_FRAME_SP_OFFSET 0
446 /* Hook used by __throw. */
449 expand_builtin_dwarf_sp_column (void)
451 return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
454 /* Return a pointer to a copy of the section string name S with all
455 attributes stripped off, and an asterisk prepended (for assemble_name). */
458 stripattributes (const char *s)
460 char *stripped = xmalloc (strlen (s) + 2);
465 while (*s && *s != ',')
472 /* Generate code to initialize the register size table. */
475 expand_builtin_init_dwarf_reg_sizes (tree address)
478 enum machine_mode mode = TYPE_MODE (char_type_node);
479 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
480 rtx mem = gen_rtx_MEM (BLKmode, addr);
481 bool wrote_return_column = false;
483 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
484 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
486 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
487 enum machine_mode save_mode = reg_raw_mode[i];
490 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
491 save_mode = choose_hard_reg_mode (i, 1, true);
492 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
494 if (save_mode == VOIDmode)
496 wrote_return_column = true;
498 size = GET_MODE_SIZE (save_mode);
502 emit_move_insn (adjust_address (mem, mode, offset),
503 gen_int_mode (size, mode));
506 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
507 gcc_assert (wrote_return_column);
508 i = DWARF_ALT_FRAME_RETURN_COLUMN;
509 wrote_return_column = false;
511 i = DWARF_FRAME_RETURN_COLUMN;
514 if (! wrote_return_column)
516 enum machine_mode save_mode = Pmode;
517 HOST_WIDE_INT offset = i * GET_MODE_SIZE (mode);
518 HOST_WIDE_INT size = GET_MODE_SIZE (save_mode);
519 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
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 fde->dw_fde_current_label = label = xstrdup (label);
656 /* Set the location counter to the new label. */
658 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
659 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
660 add_cfi (&fde->dw_fde_cfi, xcfi);
663 add_cfi (&fde->dw_fde_cfi, cfi);
667 add_cfi (&cie_cfi_head, cfi);
670 /* Subroutine of lookup_cfa. */
673 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
675 switch (cfi->dw_cfi_opc)
677 case DW_CFA_def_cfa_offset:
678 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
680 case DW_CFA_def_cfa_register:
681 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
684 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
685 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
687 case DW_CFA_def_cfa_expression:
688 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
695 /* Find the previous value for the CFA. */
698 lookup_cfa (dw_cfa_location *loc)
702 loc->reg = (unsigned long) -1;
705 loc->base_offset = 0;
707 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
708 lookup_cfa_1 (cfi, loc);
710 if (fde_table_in_use)
712 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
713 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
714 lookup_cfa_1 (cfi, loc);
718 /* The current rule for calculating the DWARF2 canonical frame address. */
719 static dw_cfa_location cfa;
721 /* The register used for saving registers to the stack, and its offset
723 static dw_cfa_location cfa_store;
725 /* The running total of the size of arguments pushed onto the stack. */
726 static HOST_WIDE_INT args_size;
728 /* The last args_size we actually output. */
729 static HOST_WIDE_INT old_args_size;
731 /* Entry point to update the canonical frame address (CFA).
732 LABEL is passed to add_fde_cfi. The value of CFA is now to be
733 calculated from REG+OFFSET. */
736 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
743 def_cfa_1 (label, &loc);
746 /* This routine does the actual work. The CFA is now calculated from
747 the dw_cfa_location structure. */
750 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
753 dw_cfa_location old_cfa, loc;
758 if (cfa_store.reg == loc.reg && loc.indirect == 0)
759 cfa_store.offset = loc.offset;
761 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
762 lookup_cfa (&old_cfa);
764 /* If nothing changed, no need to issue any call frame instructions. */
765 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
766 && loc.indirect == old_cfa.indirect
767 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
772 if (loc.reg == old_cfa.reg && !loc.indirect)
774 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
775 indicating the CFA register did not change but the offset
777 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
778 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
781 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
782 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
785 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
786 indicating the CFA register has changed to <register> but the
787 offset has not changed. */
788 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
789 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
793 else if (loc.indirect == 0)
795 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
796 indicating the CFA register has changed to <register> with
797 the specified offset. */
798 cfi->dw_cfi_opc = DW_CFA_def_cfa;
799 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
800 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
804 /* Construct a DW_CFA_def_cfa_expression instruction to
805 calculate the CFA using a full location expression since no
806 register-offset pair is available. */
807 struct dw_loc_descr_struct *loc_list;
809 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
810 loc_list = build_cfa_loc (&loc);
811 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
814 add_fde_cfi (label, cfi);
817 /* Add the CFI for saving a register. REG is the CFA column number.
818 LABEL is passed to add_fde_cfi.
819 If SREG is -1, the register is saved at OFFSET from the CFA;
820 otherwise it is saved in SREG. */
823 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
825 dw_cfi_ref cfi = new_cfi ();
827 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
829 if (sreg == INVALID_REGNUM)
832 /* The register number won't fit in 6 bits, so we have to use
834 cfi->dw_cfi_opc = DW_CFA_offset_extended;
836 cfi->dw_cfi_opc = DW_CFA_offset;
838 #ifdef ENABLE_CHECKING
840 /* If we get an offset that is not a multiple of
841 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
842 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
844 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
846 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
849 offset /= DWARF_CIE_DATA_ALIGNMENT;
851 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
853 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
855 else if (sreg == reg)
856 cfi->dw_cfi_opc = DW_CFA_same_value;
859 cfi->dw_cfi_opc = DW_CFA_register;
860 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
863 add_fde_cfi (label, cfi);
866 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
867 This CFI tells the unwinder that it needs to restore the window registers
868 from the previous frame's window save area.
870 ??? Perhaps we should note in the CIE where windows are saved (instead of
871 assuming 0(cfa)) and what registers are in the window. */
874 dwarf2out_window_save (const char *label)
876 dw_cfi_ref cfi = new_cfi ();
878 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
879 add_fde_cfi (label, cfi);
882 /* Add a CFI to update the running total of the size of arguments
883 pushed onto the stack. */
886 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
890 if (size == old_args_size)
893 old_args_size = size;
896 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
897 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
898 add_fde_cfi (label, cfi);
901 /* Entry point for saving a register to the stack. REG is the GCC register
902 number. LABEL and OFFSET are passed to reg_save. */
905 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
907 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
910 /* Entry point for saving the return address in the stack.
911 LABEL and OFFSET are passed to reg_save. */
914 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
916 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
919 /* Entry point for saving the return address in a register.
920 LABEL and SREG are passed to reg_save. */
923 dwarf2out_return_reg (const char *label, unsigned int sreg)
925 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
928 /* Record the initial position of the return address. RTL is
929 INCOMING_RETURN_ADDR_RTX. */
932 initial_return_save (rtx rtl)
934 unsigned int reg = INVALID_REGNUM;
935 HOST_WIDE_INT offset = 0;
937 switch (GET_CODE (rtl))
940 /* RA is in a register. */
941 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
945 /* RA is on the stack. */
947 switch (GET_CODE (rtl))
950 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
955 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
956 offset = INTVAL (XEXP (rtl, 1));
960 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
961 offset = -INTVAL (XEXP (rtl, 1));
971 /* The return address is at some offset from any value we can
972 actually load. For instance, on the SPARC it is in %i7+8. Just
973 ignore the offset for now; it doesn't matter for unwinding frames. */
974 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
975 initial_return_save (XEXP (rtl, 0));
982 if (reg != DWARF_FRAME_RETURN_COLUMN)
983 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
986 /* Given a SET, calculate the amount of stack adjustment it
990 stack_adjust_offset (rtx pattern)
992 rtx src = SET_SRC (pattern);
993 rtx dest = SET_DEST (pattern);
994 HOST_WIDE_INT offset = 0;
997 if (dest == stack_pointer_rtx)
999 /* (set (reg sp) (plus (reg sp) (const_int))) */
1000 code = GET_CODE (src);
1001 if (! (code == PLUS || code == MINUS)
1002 || XEXP (src, 0) != stack_pointer_rtx
1003 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1006 offset = INTVAL (XEXP (src, 1));
1010 else if (MEM_P (dest))
1012 /* (set (mem (pre_dec (reg sp))) (foo)) */
1013 src = XEXP (dest, 0);
1014 code = GET_CODE (src);
1020 if (XEXP (src, 0) == stack_pointer_rtx)
1022 rtx val = XEXP (XEXP (src, 1), 1);
1023 /* We handle only adjustments by constant amount. */
1024 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1025 && GET_CODE (val) == CONST_INT);
1026 offset = -INTVAL (val);
1033 if (XEXP (src, 0) == stack_pointer_rtx)
1035 offset = GET_MODE_SIZE (GET_MODE (dest));
1042 if (XEXP (src, 0) == stack_pointer_rtx)
1044 offset = -GET_MODE_SIZE (GET_MODE (dest));
1059 /* Check INSN to see if it looks like a push or a stack adjustment, and
1060 make a note of it if it does. EH uses this information to find out how
1061 much extra space it needs to pop off the stack. */
1064 dwarf2out_stack_adjust (rtx insn, bool after_p)
1066 HOST_WIDE_INT offset;
1070 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1071 with this function. Proper support would require all frame-related
1072 insns to be marked, and to be able to handle saving state around
1073 epilogues textually in the middle of the function. */
1074 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1077 /* If only calls can throw, and we have a frame pointer,
1078 save up adjustments until we see the CALL_INSN. */
1079 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1081 if (CALL_P (insn) && !after_p)
1083 /* Extract the size of the args from the CALL rtx itself. */
1084 insn = PATTERN (insn);
1085 if (GET_CODE (insn) == PARALLEL)
1086 insn = XVECEXP (insn, 0, 0);
1087 if (GET_CODE (insn) == SET)
1088 insn = SET_SRC (insn);
1089 gcc_assert (GET_CODE (insn) == CALL);
1090 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1095 if (CALL_P (insn) && !after_p)
1097 if (!flag_asynchronous_unwind_tables)
1098 dwarf2out_args_size ("", args_size);
1101 else if (BARRIER_P (insn))
1103 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1104 the compiler will have already emitted a stack adjustment, but
1105 doesn't bother for calls to noreturn functions. */
1106 #ifdef STACK_GROWS_DOWNWARD
1107 offset = -args_size;
1112 else if (GET_CODE (PATTERN (insn)) == SET)
1113 offset = stack_adjust_offset (PATTERN (insn));
1114 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1115 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1117 /* There may be stack adjustments inside compound insns. Search
1119 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1120 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1121 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1129 if (cfa.reg == STACK_POINTER_REGNUM)
1130 cfa.offset += offset;
1132 #ifndef STACK_GROWS_DOWNWARD
1136 args_size += offset;
1140 label = dwarf2out_cfi_label ();
1141 def_cfa_1 (label, &cfa);
1142 if (flag_asynchronous_unwind_tables)
1143 dwarf2out_args_size (label, args_size);
1148 /* We delay emitting a register save until either (a) we reach the end
1149 of the prologue or (b) the register is clobbered. This clusters
1150 register saves so that there are fewer pc advances. */
1152 struct queued_reg_save GTY(())
1154 struct queued_reg_save *next;
1156 HOST_WIDE_INT cfa_offset;
1160 static GTY(()) struct queued_reg_save *queued_reg_saves;
1162 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1163 struct reg_saved_in_data GTY(()) {
1168 /* A list of registers saved in other registers.
1169 The list intentionally has a small maximum capacity of 4; if your
1170 port needs more than that, you might consider implementing a
1171 more efficient data structure. */
1172 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1173 static GTY(()) size_t num_regs_saved_in_regs;
1175 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1176 static const char *last_reg_save_label;
1178 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1179 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1182 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1184 struct queued_reg_save *q;
1186 /* Duplicates waste space, but it's also necessary to remove them
1187 for correctness, since the queue gets output in reverse
1189 for (q = queued_reg_saves; q != NULL; q = q->next)
1190 if (REGNO (q->reg) == REGNO (reg))
1195 q = ggc_alloc (sizeof (*q));
1196 q->next = queued_reg_saves;
1197 queued_reg_saves = q;
1201 q->cfa_offset = offset;
1202 q->saved_reg = sreg;
1204 last_reg_save_label = label;
1207 /* Output all the entries in QUEUED_REG_SAVES. */
1210 flush_queued_reg_saves (void)
1212 struct queued_reg_save *q;
1214 for (q = queued_reg_saves; q; q = q->next)
1217 unsigned int reg, sreg;
1219 for (i = 0; i < num_regs_saved_in_regs; i++)
1220 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1222 if (q->saved_reg && i == num_regs_saved_in_regs)
1224 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1225 num_regs_saved_in_regs++;
1227 if (i != num_regs_saved_in_regs)
1229 regs_saved_in_regs[i].orig_reg = q->reg;
1230 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1233 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1235 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1237 sreg = INVALID_REGNUM;
1238 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1241 queued_reg_saves = NULL;
1242 last_reg_save_label = NULL;
1245 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1246 location for? Or, does it clobber a register which we've previously
1247 said that some other register is saved in, and for which we now
1248 have a new location for? */
1251 clobbers_queued_reg_save (rtx insn)
1253 struct queued_reg_save *q;
1255 for (q = queued_reg_saves; q; q = q->next)
1258 if (modified_in_p (q->reg, insn))
1260 for (i = 0; i < num_regs_saved_in_regs; i++)
1261 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1262 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1269 /* What register, if any, is currently saved in REG? */
1272 reg_saved_in (rtx reg)
1274 unsigned int regn = REGNO (reg);
1276 struct queued_reg_save *q;
1278 for (q = queued_reg_saves; q; q = q->next)
1279 if (q->saved_reg && regn == REGNO (q->saved_reg))
1282 for (i = 0; i < num_regs_saved_in_regs; i++)
1283 if (regs_saved_in_regs[i].saved_in_reg
1284 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1285 return regs_saved_in_regs[i].orig_reg;
1291 /* A temporary register holding an integral value used in adjusting SP
1292 or setting up the store_reg. The "offset" field holds the integer
1293 value, not an offset. */
1294 static dw_cfa_location cfa_temp;
1296 /* Record call frame debugging information for an expression EXPR,
1297 which either sets SP or FP (adjusting how we calculate the frame
1298 address) or saves a register to the stack or another register.
1299 LABEL indicates the address of EXPR.
1301 This function encodes a state machine mapping rtxes to actions on
1302 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1303 users need not read the source code.
1305 The High-Level Picture
1307 Changes in the register we use to calculate the CFA: Currently we
1308 assume that if you copy the CFA register into another register, we
1309 should take the other one as the new CFA register; this seems to
1310 work pretty well. If it's wrong for some target, it's simple
1311 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1313 Changes in the register we use for saving registers to the stack:
1314 This is usually SP, but not always. Again, we deduce that if you
1315 copy SP into another register (and SP is not the CFA register),
1316 then the new register is the one we will be using for register
1317 saves. This also seems to work.
1319 Register saves: There's not much guesswork about this one; if
1320 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1321 register save, and the register used to calculate the destination
1322 had better be the one we think we're using for this purpose.
1323 It's also assumed that a copy from a call-saved register to another
1324 register is saving that register if RTX_FRAME_RELATED_P is set on
1325 that instruction. If the copy is from a call-saved register to
1326 the *same* register, that means that the register is now the same
1327 value as in the caller.
1329 Except: If the register being saved is the CFA register, and the
1330 offset is nonzero, we are saving the CFA, so we assume we have to
1331 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1332 the intent is to save the value of SP from the previous frame.
1334 In addition, if a register has previously been saved to a different
1337 Invariants / Summaries of Rules
1339 cfa current rule for calculating the CFA. It usually
1340 consists of a register and an offset.
1341 cfa_store register used by prologue code to save things to the stack
1342 cfa_store.offset is the offset from the value of
1343 cfa_store.reg to the actual CFA
1344 cfa_temp register holding an integral value. cfa_temp.offset
1345 stores the value, which will be used to adjust the
1346 stack pointer. cfa_temp is also used like cfa_store,
1347 to track stores to the stack via fp or a temp reg.
1349 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1350 with cfa.reg as the first operand changes the cfa.reg and its
1351 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1354 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1355 expression yielding a constant. This sets cfa_temp.reg
1356 and cfa_temp.offset.
1358 Rule 5: Create a new register cfa_store used to save items to the
1361 Rules 10-14: Save a register to the stack. Define offset as the
1362 difference of the original location and cfa_store's
1363 location (or cfa_temp's location if cfa_temp is used).
1367 "{a,b}" indicates a choice of a xor b.
1368 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1371 (set <reg1> <reg2>:cfa.reg)
1372 effects: cfa.reg = <reg1>
1373 cfa.offset unchanged
1374 cfa_temp.reg = <reg1>
1375 cfa_temp.offset = cfa.offset
1378 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1379 {<const_int>,<reg>:cfa_temp.reg}))
1380 effects: cfa.reg = sp if fp used
1381 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1382 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1383 if cfa_store.reg==sp
1386 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1387 effects: cfa.reg = fp
1388 cfa_offset += +/- <const_int>
1391 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1392 constraints: <reg1> != fp
1394 effects: cfa.reg = <reg1>
1395 cfa_temp.reg = <reg1>
1396 cfa_temp.offset = cfa.offset
1399 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1400 constraints: <reg1> != fp
1402 effects: cfa_store.reg = <reg1>
1403 cfa_store.offset = cfa.offset - cfa_temp.offset
1406 (set <reg> <const_int>)
1407 effects: cfa_temp.reg = <reg>
1408 cfa_temp.offset = <const_int>
1411 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1412 effects: cfa_temp.reg = <reg1>
1413 cfa_temp.offset |= <const_int>
1416 (set <reg> (high <exp>))
1420 (set <reg> (lo_sum <exp> <const_int>))
1421 effects: cfa_temp.reg = <reg>
1422 cfa_temp.offset = <const_int>
1425 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1426 effects: cfa_store.offset -= <const_int>
1427 cfa.offset = cfa_store.offset if cfa.reg == sp
1429 cfa.base_offset = -cfa_store.offset
1432 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1433 effects: cfa_store.offset += -/+ mode_size(mem)
1434 cfa.offset = cfa_store.offset if cfa.reg == sp
1436 cfa.base_offset = -cfa_store.offset
1439 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1442 effects: cfa.reg = <reg1>
1443 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1446 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1447 effects: cfa.reg = <reg1>
1448 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1451 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1452 effects: cfa.reg = <reg1>
1453 cfa.base_offset = -cfa_temp.offset
1454 cfa_temp.offset -= mode_size(mem)
1457 Â (set <reg> {unspec, unspec_volatile})
1458 Â effects: target-dependent */
1461 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1464 HOST_WIDE_INT offset;
1466 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1467 the PARALLEL independently. The first element is always processed if
1468 it is a SET. This is for backward compatibility. Other elements
1469 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1470 flag is set in them. */
1471 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1474 int limit = XVECLEN (expr, 0);
1476 for (par_index = 0; par_index < limit; par_index++)
1477 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1478 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1480 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1485 gcc_assert (GET_CODE (expr) == SET);
1487 src = SET_SRC (expr);
1488 dest = SET_DEST (expr);
1492 rtx rsi = reg_saved_in (src);
1497 switch (GET_CODE (dest))
1500 switch (GET_CODE (src))
1502 /* Setting FP from SP. */
1504 if (cfa.reg == (unsigned) REGNO (src))
1507 /* Update the CFA rule wrt SP or FP. Make sure src is
1508 relative to the current CFA register.
1510 We used to require that dest be either SP or FP, but the
1511 ARM copies SP to a temporary register, and from there to
1512 FP. So we just rely on the backends to only set
1513 RTX_FRAME_RELATED_P on appropriate insns. */
1514 cfa.reg = REGNO (dest);
1515 cfa_temp.reg = cfa.reg;
1516 cfa_temp.offset = cfa.offset;
1520 /* Saving a register in a register. */
1521 gcc_assert (call_used_regs [REGNO (dest)]
1522 && (!fixed_regs [REGNO (dest)]
1523 /* For the SPARC and its register window. */
1524 || DWARF_FRAME_REGNUM (REGNO (src))
1525 == DWARF_FRAME_RETURN_COLUMN));
1526 queue_reg_save (label, src, dest, 0);
1533 if (dest == stack_pointer_rtx)
1537 switch (GET_CODE (XEXP (src, 1)))
1540 offset = INTVAL (XEXP (src, 1));
1543 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1545 offset = cfa_temp.offset;
1551 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1553 /* Restoring SP from FP in the epilogue. */
1554 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1555 cfa.reg = STACK_POINTER_REGNUM;
1557 else if (GET_CODE (src) == LO_SUM)
1558 /* Assume we've set the source reg of the LO_SUM from sp. */
1561 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1563 if (GET_CODE (src) != MINUS)
1565 if (cfa.reg == STACK_POINTER_REGNUM)
1566 cfa.offset += offset;
1567 if (cfa_store.reg == STACK_POINTER_REGNUM)
1568 cfa_store.offset += offset;
1570 else if (dest == hard_frame_pointer_rtx)
1573 /* Either setting the FP from an offset of the SP,
1574 or adjusting the FP */
1575 gcc_assert (frame_pointer_needed);
1577 gcc_assert (REG_P (XEXP (src, 0))
1578 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1579 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1580 offset = INTVAL (XEXP (src, 1));
1581 if (GET_CODE (src) != MINUS)
1583 cfa.offset += offset;
1584 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1588 gcc_assert (GET_CODE (src) != MINUS);
1591 if (REG_P (XEXP (src, 0))
1592 && REGNO (XEXP (src, 0)) == cfa.reg
1593 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1595 /* Setting a temporary CFA register that will be copied
1596 into the FP later on. */
1597 offset = - INTVAL (XEXP (src, 1));
1598 cfa.offset += offset;
1599 cfa.reg = REGNO (dest);
1600 /* Or used to save regs to the stack. */
1601 cfa_temp.reg = cfa.reg;
1602 cfa_temp.offset = cfa.offset;
1606 else if (REG_P (XEXP (src, 0))
1607 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1608 && XEXP (src, 1) == stack_pointer_rtx)
1610 /* Setting a scratch register that we will use instead
1611 of SP for saving registers to the stack. */
1612 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
1613 cfa_store.reg = REGNO (dest);
1614 cfa_store.offset = cfa.offset - cfa_temp.offset;
1618 else if (GET_CODE (src) == LO_SUM
1619 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1621 cfa_temp.reg = REGNO (dest);
1622 cfa_temp.offset = INTVAL (XEXP (src, 1));
1631 cfa_temp.reg = REGNO (dest);
1632 cfa_temp.offset = INTVAL (src);
1637 gcc_assert (REG_P (XEXP (src, 0))
1638 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
1639 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1641 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1642 cfa_temp.reg = REGNO (dest);
1643 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1646 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1647 which will fill in all of the bits. */
1654 case UNSPEC_VOLATILE:
1655 gcc_assert (targetm.dwarf_handle_frame_unspec);
1656 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
1663 def_cfa_1 (label, &cfa);
1667 gcc_assert (REG_P (src));
1669 /* Saving a register to the stack. Make sure dest is relative to the
1671 switch (GET_CODE (XEXP (dest, 0)))
1676 /* We can't handle variable size modifications. */
1677 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
1679 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1681 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1682 && cfa_store.reg == STACK_POINTER_REGNUM);
1684 cfa_store.offset += offset;
1685 if (cfa.reg == STACK_POINTER_REGNUM)
1686 cfa.offset = cfa_store.offset;
1688 offset = -cfa_store.offset;
1694 offset = GET_MODE_SIZE (GET_MODE (dest));
1695 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1698 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1699 && cfa_store.reg == STACK_POINTER_REGNUM);
1701 cfa_store.offset += offset;
1702 if (cfa.reg == STACK_POINTER_REGNUM)
1703 cfa.offset = cfa_store.offset;
1705 offset = -cfa_store.offset;
1709 /* With an offset. */
1716 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT);
1717 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1718 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1721 regno = REGNO (XEXP (XEXP (dest, 0), 0));
1723 if (cfa_store.reg == (unsigned) regno)
1724 offset -= cfa_store.offset;
1727 gcc_assert (cfa_temp.reg == (unsigned) regno);
1728 offset -= cfa_temp.offset;
1734 /* Without an offset. */
1737 int regno = REGNO (XEXP (dest, 0));
1739 if (cfa_store.reg == (unsigned) regno)
1740 offset = -cfa_store.offset;
1743 gcc_assert (cfa_temp.reg == (unsigned) regno);
1744 offset = -cfa_temp.offset;
1751 gcc_assert (cfa_temp.reg
1752 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
1753 offset = -cfa_temp.offset;
1754 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1761 if (REGNO (src) != STACK_POINTER_REGNUM
1762 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1763 && (unsigned) REGNO (src) == cfa.reg)
1765 /* We're storing the current CFA reg into the stack. */
1767 if (cfa.offset == 0)
1769 /* If the source register is exactly the CFA, assume
1770 we're saving SP like any other register; this happens
1772 def_cfa_1 (label, &cfa);
1773 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
1778 /* Otherwise, we'll need to look in the stack to
1779 calculate the CFA. */
1780 rtx x = XEXP (dest, 0);
1784 gcc_assert (REG_P (x));
1786 cfa.reg = REGNO (x);
1787 cfa.base_offset = offset;
1789 def_cfa_1 (label, &cfa);
1794 def_cfa_1 (label, &cfa);
1795 queue_reg_save (label, src, NULL_RTX, offset);
1803 /* Record call frame debugging information for INSN, which either
1804 sets SP or FP (adjusting how we calculate the frame address) or saves a
1805 register to the stack. If INSN is NULL_RTX, initialize our state.
1807 If AFTER_P is false, we're being called before the insn is emitted,
1808 otherwise after. Call instructions get invoked twice. */
1811 dwarf2out_frame_debug (rtx insn, bool after_p)
1816 if (insn == NULL_RTX)
1820 /* Flush any queued register saves. */
1821 flush_queued_reg_saves ();
1823 /* Set up state for generating call frame debug info. */
1826 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1828 cfa.reg = STACK_POINTER_REGNUM;
1831 cfa_temp.offset = 0;
1833 for (i = 0; i < num_regs_saved_in_regs; i++)
1835 regs_saved_in_regs[i].orig_reg = NULL_RTX;
1836 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
1838 num_regs_saved_in_regs = 0;
1842 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
1843 flush_queued_reg_saves ();
1845 if (! RTX_FRAME_RELATED_P (insn))
1847 if (!ACCUMULATE_OUTGOING_ARGS)
1848 dwarf2out_stack_adjust (insn, after_p);
1852 label = dwarf2out_cfi_label ();
1853 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1855 insn = XEXP (src, 0);
1857 insn = PATTERN (insn);
1859 dwarf2out_frame_debug_expr (insn, label);
1864 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1865 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1866 (enum dwarf_call_frame_info cfi);
1868 static enum dw_cfi_oprnd_type
1869 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1874 case DW_CFA_GNU_window_save:
1875 return dw_cfi_oprnd_unused;
1877 case DW_CFA_set_loc:
1878 case DW_CFA_advance_loc1:
1879 case DW_CFA_advance_loc2:
1880 case DW_CFA_advance_loc4:
1881 case DW_CFA_MIPS_advance_loc8:
1882 return dw_cfi_oprnd_addr;
1885 case DW_CFA_offset_extended:
1886 case DW_CFA_def_cfa:
1887 case DW_CFA_offset_extended_sf:
1888 case DW_CFA_def_cfa_sf:
1889 case DW_CFA_restore_extended:
1890 case DW_CFA_undefined:
1891 case DW_CFA_same_value:
1892 case DW_CFA_def_cfa_register:
1893 case DW_CFA_register:
1894 return dw_cfi_oprnd_reg_num;
1896 case DW_CFA_def_cfa_offset:
1897 case DW_CFA_GNU_args_size:
1898 case DW_CFA_def_cfa_offset_sf:
1899 return dw_cfi_oprnd_offset;
1901 case DW_CFA_def_cfa_expression:
1902 case DW_CFA_expression:
1903 return dw_cfi_oprnd_loc;
1910 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1911 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1912 (enum dwarf_call_frame_info cfi);
1914 static enum dw_cfi_oprnd_type
1915 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1919 case DW_CFA_def_cfa:
1920 case DW_CFA_def_cfa_sf:
1922 case DW_CFA_offset_extended_sf:
1923 case DW_CFA_offset_extended:
1924 return dw_cfi_oprnd_offset;
1926 case DW_CFA_register:
1927 return dw_cfi_oprnd_reg_num;
1930 return dw_cfi_oprnd_unused;
1934 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1936 /* Map register numbers held in the call frame info that gcc has
1937 collected using DWARF_FRAME_REGNUM to those that should be output in
1938 .debug_frame and .eh_frame. */
1939 #ifndef DWARF2_FRAME_REG_OUT
1940 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
1943 /* Output a Call Frame Information opcode and its operand(s). */
1946 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
1949 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1950 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1951 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1952 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
1953 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1954 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1956 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1957 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
1958 "DW_CFA_offset, column 0x%lx", r);
1959 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1961 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1963 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1964 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
1965 "DW_CFA_restore, column 0x%lx", r);
1969 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1970 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1972 switch (cfi->dw_cfi_opc)
1974 case DW_CFA_set_loc:
1976 dw2_asm_output_encoded_addr_rtx (
1977 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1978 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1981 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1982 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1985 case DW_CFA_advance_loc1:
1986 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1987 fde->dw_fde_current_label, NULL);
1988 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1991 case DW_CFA_advance_loc2:
1992 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1993 fde->dw_fde_current_label, NULL);
1994 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1997 case DW_CFA_advance_loc4:
1998 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1999 fde->dw_fde_current_label, NULL);
2000 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2003 case DW_CFA_MIPS_advance_loc8:
2004 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2005 fde->dw_fde_current_label, NULL);
2006 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2009 case DW_CFA_offset_extended:
2010 case DW_CFA_def_cfa:
2011 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2012 dw2_asm_output_data_uleb128 (r, NULL);
2013 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2016 case DW_CFA_offset_extended_sf:
2017 case DW_CFA_def_cfa_sf:
2018 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2019 dw2_asm_output_data_uleb128 (r, NULL);
2020 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2023 case DW_CFA_restore_extended:
2024 case DW_CFA_undefined:
2025 case DW_CFA_same_value:
2026 case DW_CFA_def_cfa_register:
2027 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2028 dw2_asm_output_data_uleb128 (r, NULL);
2031 case DW_CFA_register:
2032 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2033 dw2_asm_output_data_uleb128 (r, NULL);
2034 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2035 dw2_asm_output_data_uleb128 (r, NULL);
2038 case DW_CFA_def_cfa_offset:
2039 case DW_CFA_GNU_args_size:
2040 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2043 case DW_CFA_def_cfa_offset_sf:
2044 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2047 case DW_CFA_GNU_window_save:
2050 case DW_CFA_def_cfa_expression:
2051 case DW_CFA_expression:
2052 output_cfa_loc (cfi);
2055 case DW_CFA_GNU_negative_offset_extended:
2056 /* Obsoleted by DW_CFA_offset_extended_sf. */
2065 /* Output the call frame information used to record information
2066 that relates to calculating the frame pointer, and records the
2067 location of saved registers. */
2070 output_call_frame_info (int for_eh)
2075 char l1[20], l2[20], section_start_label[20];
2076 bool any_lsda_needed = false;
2077 char augmentation[6];
2078 int augmentation_size;
2079 int fde_encoding = DW_EH_PE_absptr;
2080 int per_encoding = DW_EH_PE_absptr;
2081 int lsda_encoding = DW_EH_PE_absptr;
2084 /* Don't emit a CIE if there won't be any FDEs. */
2085 if (fde_table_in_use == 0)
2088 /* If we make FDEs linkonce, we may have to emit an empty label for
2089 an FDE that wouldn't otherwise be emitted. We want to avoid
2090 having an FDE kept around when the function it refers to is
2091 discarded. Example where this matters: a primary function
2092 template in C++ requires EH information, but an explicit
2093 specialization doesn't. */
2094 if (TARGET_USES_WEAK_UNWIND_INFO
2095 && ! flag_asynchronous_unwind_tables
2097 for (i = 0; i < fde_table_in_use; i++)
2098 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2099 && !fde_table[i].uses_eh_lsda
2100 && ! DECL_WEAK (fde_table[i].decl))
2101 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2102 for_eh, /* empty */ 1);
2104 /* If we don't have any functions we'll want to unwind out of, don't
2105 emit any EH unwind information. Note that if exceptions aren't
2106 enabled, we won't have collected nothrow information, and if we
2107 asked for asynchronous tables, we always want this info. */
2110 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2112 for (i = 0; i < fde_table_in_use; i++)
2113 if (fde_table[i].uses_eh_lsda)
2114 any_eh_needed = any_lsda_needed = true;
2115 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2116 any_eh_needed = true;
2117 else if (! fde_table[i].nothrow
2118 && ! fde_table[i].all_throwers_are_sibcalls)
2119 any_eh_needed = true;
2121 if (! any_eh_needed)
2125 /* We're going to be generating comments, so turn on app. */
2130 targetm.asm_out.eh_frame_section ();
2132 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
2134 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2135 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2137 /* Output the CIE. */
2138 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2139 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2140 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2141 "Length of Common Information Entry");
2142 ASM_OUTPUT_LABEL (asm_out_file, l1);
2144 /* Now that the CIE pointer is PC-relative for EH,
2145 use 0 to identify the CIE. */
2146 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2147 (for_eh ? 0 : DW_CIE_ID),
2148 "CIE Identifier Tag");
2150 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2152 augmentation[0] = 0;
2153 augmentation_size = 0;
2159 z Indicates that a uleb128 is present to size the
2160 augmentation section.
2161 L Indicates the encoding (and thus presence) of
2162 an LSDA pointer in the FDE augmentation.
2163 R Indicates a non-default pointer encoding for
2165 P Indicates the presence of an encoding + language
2166 personality routine in the CIE augmentation. */
2168 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2169 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2170 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2172 p = augmentation + 1;
2173 if (eh_personality_libfunc)
2176 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2178 if (any_lsda_needed)
2181 augmentation_size += 1;
2183 if (fde_encoding != DW_EH_PE_absptr)
2186 augmentation_size += 1;
2188 if (p > augmentation + 1)
2190 augmentation[0] = 'z';
2194 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2195 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2197 int offset = ( 4 /* Length */
2199 + 1 /* CIE version */
2200 + strlen (augmentation) + 1 /* Augmentation */
2201 + size_of_uleb128 (1) /* Code alignment */
2202 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2204 + 1 /* Augmentation size */
2205 + 1 /* Personality encoding */ );
2206 int pad = -offset & (PTR_SIZE - 1);
2208 augmentation_size += pad;
2210 /* Augmentations should be small, so there's scarce need to
2211 iterate for a solution. Die if we exceed one uleb128 byte. */
2212 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2216 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2217 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2218 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2219 "CIE Data Alignment Factor");
2221 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2222 if (DW_CIE_VERSION == 1)
2223 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2225 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2227 if (augmentation[0])
2229 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2230 if (eh_personality_libfunc)
2232 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2233 eh_data_format_name (per_encoding));
2234 dw2_asm_output_encoded_addr_rtx (per_encoding,
2235 eh_personality_libfunc, NULL);
2238 if (any_lsda_needed)
2239 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2240 eh_data_format_name (lsda_encoding));
2242 if (fde_encoding != DW_EH_PE_absptr)
2243 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2244 eh_data_format_name (fde_encoding));
2247 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2248 output_cfi (cfi, NULL, for_eh);
2250 /* Pad the CIE out to an address sized boundary. */
2251 ASM_OUTPUT_ALIGN (asm_out_file,
2252 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2253 ASM_OUTPUT_LABEL (asm_out_file, l2);
2255 /* Loop through all of the FDE's. */
2256 for (i = 0; i < fde_table_in_use; i++)
2258 fde = &fde_table[i];
2260 /* Don't emit EH unwind info for leaf functions that don't need it. */
2261 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2262 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2263 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2264 && !fde->uses_eh_lsda)
2267 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2268 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2269 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2270 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2271 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2273 ASM_OUTPUT_LABEL (asm_out_file, l1);
2276 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2278 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2283 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2284 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2285 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2287 "FDE initial location");
2288 if (fde->dw_fde_switched_sections)
2290 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2291 fde->dw_fde_unlikely_section_label);
2292 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2293 fde->dw_fde_hot_section_label);
2294 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2295 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2296 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3,
2297 "FDE initial location");
2298 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2299 fde->dw_fde_hot_section_end_label,
2300 fde->dw_fde_hot_section_label,
2301 "FDE address range");
2302 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2,
2303 "FDE initial location");
2304 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2305 fde->dw_fde_unlikely_section_end_label,
2306 fde->dw_fde_unlikely_section_label,
2307 "FDE address range");
2310 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2311 fde->dw_fde_end, fde->dw_fde_begin,
2312 "FDE address range");
2316 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2317 "FDE initial location");
2318 if (fde->dw_fde_switched_sections)
2320 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2321 fde->dw_fde_hot_section_label,
2322 "FDE initial location");
2323 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2324 fde->dw_fde_hot_section_end_label,
2325 fde->dw_fde_hot_section_label,
2326 "FDE address range");
2327 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2328 fde->dw_fde_unlikely_section_label,
2329 "FDE initial location");
2330 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2331 fde->dw_fde_unlikely_section_end_label,
2332 fde->dw_fde_unlikely_section_label,
2333 "FDE address range");
2336 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2337 fde->dw_fde_end, fde->dw_fde_begin,
2338 "FDE address range");
2341 if (augmentation[0])
2343 if (any_lsda_needed)
2345 int size = size_of_encoded_value (lsda_encoding);
2347 if (lsda_encoding == DW_EH_PE_aligned)
2349 int offset = ( 4 /* Length */
2350 + 4 /* CIE offset */
2351 + 2 * size_of_encoded_value (fde_encoding)
2352 + 1 /* Augmentation size */ );
2353 int pad = -offset & (PTR_SIZE - 1);
2356 gcc_assert (size_of_uleb128 (size) == 1);
2359 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2361 if (fde->uses_eh_lsda)
2363 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2364 fde->funcdef_number);
2365 dw2_asm_output_encoded_addr_rtx (
2366 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2367 "Language Specific Data Area");
2371 if (lsda_encoding == DW_EH_PE_aligned)
2372 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2374 (size_of_encoded_value (lsda_encoding), 0,
2375 "Language Specific Data Area (none)");
2379 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2382 /* Loop through the Call Frame Instructions associated with
2384 fde->dw_fde_current_label = fde->dw_fde_begin;
2385 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2386 output_cfi (cfi, fde, for_eh);
2388 /* Pad the FDE out to an address sized boundary. */
2389 ASM_OUTPUT_ALIGN (asm_out_file,
2390 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2391 ASM_OUTPUT_LABEL (asm_out_file, l2);
2394 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2395 dw2_asm_output_data (4, 0, "End of Table");
2396 #ifdef MIPS_DEBUGGING_INFO
2397 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2398 get a value of 0. Putting .align 0 after the label fixes it. */
2399 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2402 /* Turn off app to make assembly quicker. */
2407 /* Output a marker (i.e. a label) for the beginning of a function, before
2411 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2412 const char *file ATTRIBUTE_UNUSED)
2414 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2418 current_function_func_begin_label = NULL;
2420 #ifdef TARGET_UNWIND_INFO
2421 /* ??? current_function_func_begin_label is also used by except.c
2422 for call-site information. We must emit this label if it might
2424 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2425 && ! dwarf2out_do_frame ())
2428 if (! dwarf2out_do_frame ())
2432 function_section (current_function_decl);
2433 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2434 current_function_funcdef_no);
2435 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2436 current_function_funcdef_no);
2437 dup_label = xstrdup (label);
2438 current_function_func_begin_label = dup_label;
2440 #ifdef TARGET_UNWIND_INFO
2441 /* We can elide the fde allocation if we're not emitting debug info. */
2442 if (! dwarf2out_do_frame ())
2446 /* Expand the fde table if necessary. */
2447 if (fde_table_in_use == fde_table_allocated)
2449 fde_table_allocated += FDE_TABLE_INCREMENT;
2450 fde_table = ggc_realloc (fde_table,
2451 fde_table_allocated * sizeof (dw_fde_node));
2452 memset (fde_table + fde_table_in_use, 0,
2453 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2456 /* Record the FDE associated with this function. */
2457 current_funcdef_fde = fde_table_in_use;
2459 /* Add the new FDE at the end of the fde_table. */
2460 fde = &fde_table[fde_table_in_use++];
2461 fde->decl = current_function_decl;
2462 fde->dw_fde_begin = dup_label;
2463 fde->dw_fde_current_label = NULL;
2464 fde->dw_fde_hot_section_label = NULL;
2465 fde->dw_fde_hot_section_end_label = NULL;
2466 fde->dw_fde_unlikely_section_label = NULL;
2467 fde->dw_fde_unlikely_section_end_label = NULL;
2468 fde->dw_fde_switched_sections = false;
2469 fde->dw_fde_end = NULL;
2470 fde->dw_fde_cfi = NULL;
2471 fde->funcdef_number = current_function_funcdef_no;
2472 fde->nothrow = TREE_NOTHROW (current_function_decl);
2473 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2474 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2476 args_size = old_args_size = 0;
2478 /* We only want to output line number information for the genuine dwarf2
2479 prologue case, not the eh frame case. */
2480 #ifdef DWARF2_DEBUGGING_INFO
2482 dwarf2out_source_line (line, file);
2486 /* Output a marker (i.e. a label) for the absolute end of the generated code
2487 for a function definition. This gets called *after* the epilogue code has
2491 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2492 const char *file ATTRIBUTE_UNUSED)
2495 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2497 /* Output a label to mark the endpoint of the code generated for this
2499 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2500 current_function_funcdef_no);
2501 ASM_OUTPUT_LABEL (asm_out_file, label);
2502 fde = &fde_table[fde_table_in_use - 1];
2503 fde->dw_fde_end = xstrdup (label);
2507 dwarf2out_frame_init (void)
2509 /* Allocate the initial hunk of the fde_table. */
2510 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2511 fde_table_allocated = FDE_TABLE_INCREMENT;
2512 fde_table_in_use = 0;
2514 /* Generate the CFA instructions common to all FDE's. Do it now for the
2515 sake of lookup_cfa. */
2517 #ifdef DWARF2_UNWIND_INFO
2518 /* On entry, the Canonical Frame Address is at SP. */
2519 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2520 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2525 dwarf2out_frame_finish (void)
2527 /* Output call frame information. */
2528 if (write_symbols == DWARF2_DEBUG
2529 || write_symbols == VMS_AND_DWARF2_DEBUG
2530 #ifdef DWARF2_FRAME_INFO
2531 || DWARF2_FRAME_INFO
2534 output_call_frame_info (0);
2536 #ifndef TARGET_UNWIND_INFO
2537 /* Output another copy for the unwinder. */
2538 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2539 output_call_frame_info (1);
2544 /* And now, the subset of the debugging information support code necessary
2545 for emitting location expressions. */
2547 /* We need some way to distinguish DW_OP_addr with a direct symbol
2548 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2549 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2552 typedef struct dw_val_struct *dw_val_ref;
2553 typedef struct die_struct *dw_die_ref;
2554 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2555 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2557 /* Each DIE may have a series of attribute/value pairs. Values
2558 can take on several forms. The forms that are used in this
2559 implementation are listed below. */
2564 dw_val_class_offset,
2566 dw_val_class_loc_list,
2567 dw_val_class_range_list,
2569 dw_val_class_unsigned_const,
2570 dw_val_class_long_long,
2573 dw_val_class_die_ref,
2574 dw_val_class_fde_ref,
2575 dw_val_class_lbl_id,
2576 dw_val_class_lbl_offset,
2580 /* Describe a double word constant value. */
2581 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2583 typedef struct dw_long_long_struct GTY(())
2590 /* Describe a floating point constant value, or a vector constant value. */
2592 typedef struct dw_vec_struct GTY(())
2594 unsigned char * GTY((length ("%h.length"))) array;
2600 /* The dw_val_node describes an attribute's value, as it is
2601 represented internally. */
2603 typedef struct dw_val_struct GTY(())
2605 enum dw_val_class val_class;
2606 union dw_val_struct_union
2608 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2609 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2610 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2611 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2612 HOST_WIDE_INT GTY ((default)) val_int;
2613 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2614 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2615 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2616 struct dw_val_die_union
2620 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2621 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2622 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2623 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2624 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2626 GTY ((desc ("%1.val_class"))) v;
2630 /* Locations in memory are described using a sequence of stack machine
2633 typedef struct dw_loc_descr_struct GTY(())
2635 dw_loc_descr_ref dw_loc_next;
2636 enum dwarf_location_atom dw_loc_opc;
2637 dw_val_node dw_loc_oprnd1;
2638 dw_val_node dw_loc_oprnd2;
2643 /* Location lists are ranges + location descriptions for that range,
2644 so you can track variables that are in different places over
2645 their entire life. */
2646 typedef struct dw_loc_list_struct GTY(())
2648 dw_loc_list_ref dw_loc_next;
2649 const char *begin; /* Label for begin address of range */
2650 const char *end; /* Label for end address of range */
2651 char *ll_symbol; /* Label for beginning of location list.
2652 Only on head of list */
2653 const char *section; /* Section this loclist is relative to */
2654 dw_loc_descr_ref expr;
2657 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2659 static const char *dwarf_stack_op_name (unsigned);
2660 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2661 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2662 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2663 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2664 static unsigned long size_of_locs (dw_loc_descr_ref);
2665 static void output_loc_operands (dw_loc_descr_ref);
2666 static void output_loc_sequence (dw_loc_descr_ref);
2668 /* Convert a DWARF stack opcode into its string name. */
2671 dwarf_stack_op_name (unsigned int op)
2676 case INTERNAL_DW_OP_tls_addr:
2677 return "DW_OP_addr";
2679 return "DW_OP_deref";
2681 return "DW_OP_const1u";
2683 return "DW_OP_const1s";
2685 return "DW_OP_const2u";
2687 return "DW_OP_const2s";
2689 return "DW_OP_const4u";
2691 return "DW_OP_const4s";
2693 return "DW_OP_const8u";
2695 return "DW_OP_const8s";
2697 return "DW_OP_constu";
2699 return "DW_OP_consts";
2703 return "DW_OP_drop";
2705 return "DW_OP_over";
2707 return "DW_OP_pick";
2709 return "DW_OP_swap";
2713 return "DW_OP_xderef";
2721 return "DW_OP_minus";
2733 return "DW_OP_plus";
2734 case DW_OP_plus_uconst:
2735 return "DW_OP_plus_uconst";
2741 return "DW_OP_shra";
2759 return "DW_OP_skip";
2761 return "DW_OP_lit0";
2763 return "DW_OP_lit1";
2765 return "DW_OP_lit2";
2767 return "DW_OP_lit3";
2769 return "DW_OP_lit4";
2771 return "DW_OP_lit5";
2773 return "DW_OP_lit6";
2775 return "DW_OP_lit7";
2777 return "DW_OP_lit8";
2779 return "DW_OP_lit9";
2781 return "DW_OP_lit10";
2783 return "DW_OP_lit11";
2785 return "DW_OP_lit12";
2787 return "DW_OP_lit13";
2789 return "DW_OP_lit14";
2791 return "DW_OP_lit15";
2793 return "DW_OP_lit16";
2795 return "DW_OP_lit17";
2797 return "DW_OP_lit18";
2799 return "DW_OP_lit19";
2801 return "DW_OP_lit20";
2803 return "DW_OP_lit21";
2805 return "DW_OP_lit22";
2807 return "DW_OP_lit23";
2809 return "DW_OP_lit24";
2811 return "DW_OP_lit25";
2813 return "DW_OP_lit26";
2815 return "DW_OP_lit27";
2817 return "DW_OP_lit28";
2819 return "DW_OP_lit29";
2821 return "DW_OP_lit30";
2823 return "DW_OP_lit31";
2825 return "DW_OP_reg0";
2827 return "DW_OP_reg1";
2829 return "DW_OP_reg2";
2831 return "DW_OP_reg3";
2833 return "DW_OP_reg4";
2835 return "DW_OP_reg5";
2837 return "DW_OP_reg6";
2839 return "DW_OP_reg7";
2841 return "DW_OP_reg8";
2843 return "DW_OP_reg9";
2845 return "DW_OP_reg10";
2847 return "DW_OP_reg11";
2849 return "DW_OP_reg12";
2851 return "DW_OP_reg13";
2853 return "DW_OP_reg14";
2855 return "DW_OP_reg15";
2857 return "DW_OP_reg16";
2859 return "DW_OP_reg17";
2861 return "DW_OP_reg18";
2863 return "DW_OP_reg19";
2865 return "DW_OP_reg20";
2867 return "DW_OP_reg21";
2869 return "DW_OP_reg22";
2871 return "DW_OP_reg23";
2873 return "DW_OP_reg24";
2875 return "DW_OP_reg25";
2877 return "DW_OP_reg26";
2879 return "DW_OP_reg27";
2881 return "DW_OP_reg28";
2883 return "DW_OP_reg29";
2885 return "DW_OP_reg30";
2887 return "DW_OP_reg31";
2889 return "DW_OP_breg0";
2891 return "DW_OP_breg1";
2893 return "DW_OP_breg2";
2895 return "DW_OP_breg3";
2897 return "DW_OP_breg4";
2899 return "DW_OP_breg5";
2901 return "DW_OP_breg6";
2903 return "DW_OP_breg7";
2905 return "DW_OP_breg8";
2907 return "DW_OP_breg9";
2909 return "DW_OP_breg10";
2911 return "DW_OP_breg11";
2913 return "DW_OP_breg12";
2915 return "DW_OP_breg13";
2917 return "DW_OP_breg14";
2919 return "DW_OP_breg15";
2921 return "DW_OP_breg16";
2923 return "DW_OP_breg17";
2925 return "DW_OP_breg18";
2927 return "DW_OP_breg19";
2929 return "DW_OP_breg20";
2931 return "DW_OP_breg21";
2933 return "DW_OP_breg22";
2935 return "DW_OP_breg23";
2937 return "DW_OP_breg24";
2939 return "DW_OP_breg25";
2941 return "DW_OP_breg26";
2943 return "DW_OP_breg27";
2945 return "DW_OP_breg28";
2947 return "DW_OP_breg29";
2949 return "DW_OP_breg30";
2951 return "DW_OP_breg31";
2953 return "DW_OP_regx";
2955 return "DW_OP_fbreg";
2957 return "DW_OP_bregx";
2959 return "DW_OP_piece";
2960 case DW_OP_deref_size:
2961 return "DW_OP_deref_size";
2962 case DW_OP_xderef_size:
2963 return "DW_OP_xderef_size";
2966 case DW_OP_push_object_address:
2967 return "DW_OP_push_object_address";
2969 return "DW_OP_call2";
2971 return "DW_OP_call4";
2972 case DW_OP_call_ref:
2973 return "DW_OP_call_ref";
2974 case DW_OP_GNU_push_tls_address:
2975 return "DW_OP_GNU_push_tls_address";
2977 return "OP_<unknown>";
2981 /* Return a pointer to a newly allocated location description. Location
2982 descriptions are simple expression terms that can be strung
2983 together to form more complicated location (address) descriptions. */
2985 static inline dw_loc_descr_ref
2986 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
2987 unsigned HOST_WIDE_INT oprnd2)
2989 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
2991 descr->dw_loc_opc = op;
2992 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2993 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2994 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2995 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3000 /* Add a location description term to a location description expression. */
3003 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3005 dw_loc_descr_ref *d;
3007 /* Find the end of the chain. */
3008 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3014 /* Return the size of a location descriptor. */
3016 static unsigned long
3017 size_of_loc_descr (dw_loc_descr_ref loc)
3019 unsigned long size = 1;
3021 switch (loc->dw_loc_opc)
3024 case INTERNAL_DW_OP_tls_addr:
3025 size += DWARF2_ADDR_SIZE;
3044 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3047 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3052 case DW_OP_plus_uconst:
3053 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3091 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3094 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3097 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3100 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3101 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3104 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3106 case DW_OP_deref_size:
3107 case DW_OP_xderef_size:
3116 case DW_OP_call_ref:
3117 size += DWARF2_ADDR_SIZE;
3126 /* Return the size of a series of location descriptors. */
3128 static unsigned long
3129 size_of_locs (dw_loc_descr_ref loc)
3133 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
3135 loc->dw_loc_addr = size;
3136 size += size_of_loc_descr (loc);
3142 /* Output location description stack opcode's operands (if any). */
3145 output_loc_operands (dw_loc_descr_ref loc)
3147 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3148 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3150 switch (loc->dw_loc_opc)
3152 #ifdef DWARF2_DEBUGGING_INFO
3154 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3158 dw2_asm_output_data (2, val1->v.val_int, NULL);
3162 dw2_asm_output_data (4, val1->v.val_int, NULL);
3166 gcc_assert (HOST_BITS_PER_LONG >= 64);
3167 dw2_asm_output_data (8, val1->v.val_int, NULL);
3174 gcc_assert (val1->val_class == dw_val_class_loc);
3175 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3177 dw2_asm_output_data (2, offset, NULL);
3190 /* We currently don't make any attempt to make sure these are
3191 aligned properly like we do for the main unwind info, so
3192 don't support emitting things larger than a byte if we're
3193 only doing unwinding. */
3198 dw2_asm_output_data (1, val1->v.val_int, NULL);
3201 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3204 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3207 dw2_asm_output_data (1, val1->v.val_int, NULL);
3209 case DW_OP_plus_uconst:
3210 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3244 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3247 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3250 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3253 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3254 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3257 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3259 case DW_OP_deref_size:
3260 case DW_OP_xderef_size:
3261 dw2_asm_output_data (1, val1->v.val_int, NULL);
3264 case INTERNAL_DW_OP_tls_addr:
3265 if (targetm.asm_out.output_dwarf_dtprel)
3267 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
3270 fputc ('\n', asm_out_file);
3277 /* Other codes have no operands. */
3282 /* Output a sequence of location operations. */
3285 output_loc_sequence (dw_loc_descr_ref loc)
3287 for (; loc != NULL; loc = loc->dw_loc_next)
3289 /* Output the opcode. */
3290 dw2_asm_output_data (1, loc->dw_loc_opc,
3291 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3293 /* Output the operand(s) (if any). */
3294 output_loc_operands (loc);
3298 /* This routine will generate the correct assembly data for a location
3299 description based on a cfi entry with a complex address. */
3302 output_cfa_loc (dw_cfi_ref cfi)
3304 dw_loc_descr_ref loc;
3307 /* Output the size of the block. */
3308 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3309 size = size_of_locs (loc);
3310 dw2_asm_output_data_uleb128 (size, NULL);
3312 /* Now output the operations themselves. */
3313 output_loc_sequence (loc);
3316 /* This function builds a dwarf location descriptor sequence from
3317 a dw_cfa_location. */
3319 static struct dw_loc_descr_struct *
3320 build_cfa_loc (dw_cfa_location *cfa)
3322 struct dw_loc_descr_struct *head, *tmp;
3324 gcc_assert (cfa->indirect);
3326 if (cfa->base_offset)
3329 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3331 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3333 else if (cfa->reg <= 31)
3334 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3336 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3338 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3339 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3340 add_loc_descr (&head, tmp);
3341 if (cfa->offset != 0)
3343 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3344 add_loc_descr (&head, tmp);
3350 /* This function fills in aa dw_cfa_location structure from a dwarf location
3351 descriptor sequence. */
3354 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3356 struct dw_loc_descr_struct *ptr;
3358 cfa->base_offset = 0;
3362 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3364 enum dwarf_location_atom op = ptr->dw_loc_opc;
3400 cfa->reg = op - DW_OP_reg0;
3403 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3437 cfa->reg = op - DW_OP_breg0;
3438 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3441 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3442 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3447 case DW_OP_plus_uconst:
3448 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3451 internal_error ("DW_LOC_OP %s not implemented",
3452 dwarf_stack_op_name (ptr->dw_loc_opc));
3456 #endif /* .debug_frame support */
3458 /* And now, the support for symbolic debugging information. */
3459 #ifdef DWARF2_DEBUGGING_INFO
3461 /* .debug_str support. */
3462 static int output_indirect_string (void **, void *);
3464 static void dwarf2out_init (const char *);
3465 static void dwarf2out_finish (const char *);
3466 static void dwarf2out_define (unsigned int, const char *);
3467 static void dwarf2out_undef (unsigned int, const char *);
3468 static void dwarf2out_start_source_file (unsigned, const char *);
3469 static void dwarf2out_end_source_file (unsigned);
3470 static void dwarf2out_begin_block (unsigned, unsigned);
3471 static void dwarf2out_end_block (unsigned, unsigned);
3472 static bool dwarf2out_ignore_block (tree);
3473 static void dwarf2out_global_decl (tree);
3474 static void dwarf2out_type_decl (tree, int);
3475 static void dwarf2out_imported_module_or_decl (tree, tree);
3476 static void dwarf2out_abstract_function (tree);
3477 static void dwarf2out_var_location (rtx);
3478 static void dwarf2out_begin_function (tree);
3479 static void dwarf2out_switch_text_section (void);
3481 /* The debug hooks structure. */
3483 const struct gcc_debug_hooks dwarf2_debug_hooks =
3489 dwarf2out_start_source_file,
3490 dwarf2out_end_source_file,
3491 dwarf2out_begin_block,
3492 dwarf2out_end_block,
3493 dwarf2out_ignore_block,
3494 dwarf2out_source_line,
3495 dwarf2out_begin_prologue,
3496 debug_nothing_int_charstar, /* end_prologue */
3497 dwarf2out_end_epilogue,
3498 dwarf2out_begin_function,
3499 debug_nothing_int, /* end_function */
3500 dwarf2out_decl, /* function_decl */
3501 dwarf2out_global_decl,
3502 dwarf2out_type_decl, /* type_decl */
3503 dwarf2out_imported_module_or_decl,
3504 debug_nothing_tree, /* deferred_inline_function */
3505 /* The DWARF 2 backend tries to reduce debugging bloat by not
3506 emitting the abstract description of inline functions until
3507 something tries to reference them. */
3508 dwarf2out_abstract_function, /* outlining_inline_function */
3509 debug_nothing_rtx, /* label */
3510 debug_nothing_int, /* handle_pch */
3511 dwarf2out_var_location,
3512 dwarf2out_switch_text_section,
3513 1 /* start_end_main_source_file */
3517 /* NOTE: In the comments in this file, many references are made to
3518 "Debugging Information Entries". This term is abbreviated as `DIE'
3519 throughout the remainder of this file. */
3521 /* An internal representation of the DWARF output is built, and then
3522 walked to generate the DWARF debugging info. The walk of the internal
3523 representation is done after the entire program has been compiled.
3524 The types below are used to describe the internal representation. */
3526 /* Various DIE's use offsets relative to the beginning of the
3527 .debug_info section to refer to each other. */
3529 typedef long int dw_offset;
3531 /* Define typedefs here to avoid circular dependencies. */
3533 typedef struct dw_attr_struct *dw_attr_ref;
3534 typedef struct dw_line_info_struct *dw_line_info_ref;
3535 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3536 typedef struct pubname_struct *pubname_ref;
3537 typedef struct dw_ranges_struct *dw_ranges_ref;
3539 /* Each entry in the line_info_table maintains the file and
3540 line number associated with the label generated for that
3541 entry. The label gives the PC value associated with
3542 the line number entry. */
3544 typedef struct dw_line_info_struct GTY(())
3546 unsigned long dw_file_num;
3547 unsigned long dw_line_num;
3551 /* Line information for functions in separate sections; each one gets its
3553 typedef struct dw_separate_line_info_struct GTY(())
3555 unsigned long dw_file_num;
3556 unsigned long dw_line_num;
3557 unsigned long function;
3559 dw_separate_line_info_entry;
3561 /* Each DIE attribute has a field specifying the attribute kind,
3562 a link to the next attribute in the chain, and an attribute value.
3563 Attributes are typically linked below the DIE they modify. */
3565 typedef struct dw_attr_struct GTY(())
3567 enum dwarf_attribute dw_attr;
3568 dw_attr_ref dw_attr_next;
3569 dw_val_node dw_attr_val;
3573 /* The Debugging Information Entry (DIE) structure */
3575 typedef struct die_struct GTY(())
3577 enum dwarf_tag die_tag;
3579 dw_attr_ref die_attr;
3580 dw_die_ref die_parent;
3581 dw_die_ref die_child;
3583 dw_die_ref die_definition; /* ref from a specification to its definition */
3584 dw_offset die_offset;
3585 unsigned long die_abbrev;
3587 unsigned int decl_id;
3591 /* The pubname structure */
3593 typedef struct pubname_struct GTY(())
3600 struct dw_ranges_struct GTY(())
3605 /* The limbo die list structure. */
3606 typedef struct limbo_die_struct GTY(())
3610 struct limbo_die_struct *next;
3614 /* How to start an assembler comment. */
3615 #ifndef ASM_COMMENT_START
3616 #define ASM_COMMENT_START ";#"