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(())
242 HOST_WIDE_INT offset;
243 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 /* Hook used by __throw. */
443 expand_builtin_dwarf_sp_column (void)
445 return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
448 /* Return a pointer to a copy of the section string name S with all
449 attributes stripped off, and an asterisk prepended (for assemble_name). */
452 stripattributes (const char *s)
454 char *stripped = xmalloc (strlen (s) + 2);
459 while (*s && *s != ',')
466 /* Generate code to initialize the register size table. */
469 expand_builtin_init_dwarf_reg_sizes (tree address)
472 enum machine_mode mode = TYPE_MODE (char_type_node);
473 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
474 rtx mem = gen_rtx_MEM (BLKmode, addr);
475 bool wrote_return_column = false;
477 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
478 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
480 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
481 enum machine_mode save_mode = reg_raw_mode[i];
484 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
485 save_mode = choose_hard_reg_mode (i, 1, true);
486 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
488 if (save_mode == VOIDmode)
490 wrote_return_column = true;
492 size = GET_MODE_SIZE (save_mode);
496 emit_move_insn (adjust_address (mem, mode, offset),
497 gen_int_mode (size, mode));
500 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
501 gcc_assert (wrote_return_column);
502 i = DWARF_ALT_FRAME_RETURN_COLUMN;
503 wrote_return_column = false;
505 i = DWARF_FRAME_RETURN_COLUMN;
508 if (! wrote_return_column)
510 enum machine_mode save_mode = Pmode;
511 HOST_WIDE_INT offset = i * GET_MODE_SIZE (mode);
512 HOST_WIDE_INT size = GET_MODE_SIZE (save_mode);
513 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
517 /* Convert a DWARF call frame info. operation to its string name */
520 dwarf_cfi_name (unsigned int cfi_opc)
524 case DW_CFA_advance_loc:
525 return "DW_CFA_advance_loc";
527 return "DW_CFA_offset";
529 return "DW_CFA_restore";
533 return "DW_CFA_set_loc";
534 case DW_CFA_advance_loc1:
535 return "DW_CFA_advance_loc1";
536 case DW_CFA_advance_loc2:
537 return "DW_CFA_advance_loc2";
538 case DW_CFA_advance_loc4:
539 return "DW_CFA_advance_loc4";
540 case DW_CFA_offset_extended:
541 return "DW_CFA_offset_extended";
542 case DW_CFA_restore_extended:
543 return "DW_CFA_restore_extended";
544 case DW_CFA_undefined:
545 return "DW_CFA_undefined";
546 case DW_CFA_same_value:
547 return "DW_CFA_same_value";
548 case DW_CFA_register:
549 return "DW_CFA_register";
550 case DW_CFA_remember_state:
551 return "DW_CFA_remember_state";
552 case DW_CFA_restore_state:
553 return "DW_CFA_restore_state";
555 return "DW_CFA_def_cfa";
556 case DW_CFA_def_cfa_register:
557 return "DW_CFA_def_cfa_register";
558 case DW_CFA_def_cfa_offset:
559 return "DW_CFA_def_cfa_offset";
562 case DW_CFA_def_cfa_expression:
563 return "DW_CFA_def_cfa_expression";
564 case DW_CFA_expression:
565 return "DW_CFA_expression";
566 case DW_CFA_offset_extended_sf:
567 return "DW_CFA_offset_extended_sf";
568 case DW_CFA_def_cfa_sf:
569 return "DW_CFA_def_cfa_sf";
570 case DW_CFA_def_cfa_offset_sf:
571 return "DW_CFA_def_cfa_offset_sf";
573 /* SGI/MIPS specific */
574 case DW_CFA_MIPS_advance_loc8:
575 return "DW_CFA_MIPS_advance_loc8";
578 case DW_CFA_GNU_window_save:
579 return "DW_CFA_GNU_window_save";
580 case DW_CFA_GNU_args_size:
581 return "DW_CFA_GNU_args_size";
582 case DW_CFA_GNU_negative_offset_extended:
583 return "DW_CFA_GNU_negative_offset_extended";
586 return "DW_CFA_<unknown>";
590 /* Return a pointer to a newly allocated Call Frame Instruction. */
592 static inline dw_cfi_ref
595 dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node));
597 cfi->dw_cfi_next = NULL;
598 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
599 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
604 /* Add a Call Frame Instruction to list of instructions. */
607 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
611 /* Find the end of the chain. */
612 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
618 /* Generate a new label for the CFI info to refer to. */
621 dwarf2out_cfi_label (void)
623 static char label[20];
625 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
626 ASM_OUTPUT_LABEL (asm_out_file, label);
630 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
631 or to the CIE if LABEL is NULL. */
634 add_fde_cfi (const char *label, dw_cfi_ref cfi)
638 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
641 label = dwarf2out_cfi_label ();
643 if (fde->dw_fde_current_label == NULL
644 || strcmp (label, fde->dw_fde_current_label) != 0)
648 fde->dw_fde_current_label = label = xstrdup (label);
650 /* Set the location counter to the new label. */
652 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
653 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
654 add_cfi (&fde->dw_fde_cfi, xcfi);
657 add_cfi (&fde->dw_fde_cfi, cfi);
661 add_cfi (&cie_cfi_head, cfi);
664 /* Subroutine of lookup_cfa. */
667 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
669 switch (cfi->dw_cfi_opc)
671 case DW_CFA_def_cfa_offset:
672 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
674 case DW_CFA_def_cfa_register:
675 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
678 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
679 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
681 case DW_CFA_def_cfa_expression:
682 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
689 /* Find the previous value for the CFA. */
692 lookup_cfa (dw_cfa_location *loc)
696 loc->reg = INVALID_REGNUM;
699 loc->base_offset = 0;
701 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
702 lookup_cfa_1 (cfi, loc);
704 if (fde_table_in_use)
706 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
707 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
708 lookup_cfa_1 (cfi, loc);
712 /* The current rule for calculating the DWARF2 canonical frame address. */
713 static dw_cfa_location cfa;
715 /* The register used for saving registers to the stack, and its offset
717 static dw_cfa_location cfa_store;
719 /* The running total of the size of arguments pushed onto the stack. */
720 static HOST_WIDE_INT args_size;
722 /* The last args_size we actually output. */
723 static HOST_WIDE_INT old_args_size;
725 /* Entry point to update the canonical frame address (CFA).
726 LABEL is passed to add_fde_cfi. The value of CFA is now to be
727 calculated from REG+OFFSET. */
730 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
737 def_cfa_1 (label, &loc);
740 /* Determine if two dw_cfa_location structures define the same data. */
743 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
745 return (loc1->reg == loc2->reg
746 && loc1->offset == loc2->offset
747 && loc1->indirect == loc2->indirect
748 && (loc1->indirect == 0
749 || loc1->base_offset == loc2->base_offset));
752 /* This routine does the actual work. The CFA is now calculated from
753 the dw_cfa_location structure. */
756 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
759 dw_cfa_location old_cfa, loc;
764 if (cfa_store.reg == loc.reg && loc.indirect == 0)
765 cfa_store.offset = loc.offset;
767 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
768 lookup_cfa (&old_cfa);
770 /* If nothing changed, no need to issue any call frame instructions. */
771 if (cfa_equal_p (&loc, &old_cfa))
776 if (loc.reg == old_cfa.reg && !loc.indirect)
778 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
779 indicating the CFA register did not change but the offset
781 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
782 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
785 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
786 else if (loc.offset == old_cfa.offset
787 && old_cfa.reg != INVALID_REGNUM
790 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
791 indicating the CFA register has changed to <register> but the
792 offset has not changed. */
793 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
794 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
798 else if (loc.indirect == 0)
800 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
801 indicating the CFA register has changed to <register> with
802 the specified offset. */
803 cfi->dw_cfi_opc = DW_CFA_def_cfa;
804 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
805 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
809 /* Construct a DW_CFA_def_cfa_expression instruction to
810 calculate the CFA using a full location expression since no
811 register-offset pair is available. */
812 struct dw_loc_descr_struct *loc_list;
814 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
815 loc_list = build_cfa_loc (&loc);
816 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
819 add_fde_cfi (label, cfi);
822 /* Add the CFI for saving a register. REG is the CFA column number.
823 LABEL is passed to add_fde_cfi.
824 If SREG is -1, the register is saved at OFFSET from the CFA;
825 otherwise it is saved in SREG. */
828 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
830 dw_cfi_ref cfi = new_cfi ();
832 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
834 if (sreg == INVALID_REGNUM)
837 /* The register number won't fit in 6 bits, so we have to use
839 cfi->dw_cfi_opc = DW_CFA_offset_extended;
841 cfi->dw_cfi_opc = DW_CFA_offset;
843 #ifdef ENABLE_CHECKING
845 /* If we get an offset that is not a multiple of
846 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
847 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
849 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
851 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
854 offset /= DWARF_CIE_DATA_ALIGNMENT;
856 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
858 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
860 else if (sreg == reg)
861 cfi->dw_cfi_opc = DW_CFA_same_value;
864 cfi->dw_cfi_opc = DW_CFA_register;
865 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
868 add_fde_cfi (label, cfi);
871 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
872 This CFI tells the unwinder that it needs to restore the window registers
873 from the previous frame's window save area.
875 ??? Perhaps we should note in the CIE where windows are saved (instead of
876 assuming 0(cfa)) and what registers are in the window. */
879 dwarf2out_window_save (const char *label)
881 dw_cfi_ref cfi = new_cfi ();
883 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
884 add_fde_cfi (label, cfi);
887 /* Add a CFI to update the running total of the size of arguments
888 pushed onto the stack. */
891 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
895 if (size == old_args_size)
898 old_args_size = size;
901 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
902 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
903 add_fde_cfi (label, cfi);
906 /* Entry point for saving a register to the stack. REG is the GCC register
907 number. LABEL and OFFSET are passed to reg_save. */
910 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
912 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
915 /* Entry point for saving the return address in the stack.
916 LABEL and OFFSET are passed to reg_save. */
919 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
921 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
924 /* Entry point for saving the return address in a register.
925 LABEL and SREG are passed to reg_save. */
928 dwarf2out_return_reg (const char *label, unsigned int sreg)
930 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
933 /* Record the initial position of the return address. RTL is
934 INCOMING_RETURN_ADDR_RTX. */
937 initial_return_save (rtx rtl)
939 unsigned int reg = INVALID_REGNUM;
940 HOST_WIDE_INT offset = 0;
942 switch (GET_CODE (rtl))
945 /* RA is in a register. */
946 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
950 /* RA is on the stack. */
952 switch (GET_CODE (rtl))
955 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
960 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
961 offset = INTVAL (XEXP (rtl, 1));
965 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
966 offset = -INTVAL (XEXP (rtl, 1));
976 /* The return address is at some offset from any value we can
977 actually load. For instance, on the SPARC it is in %i7+8. Just
978 ignore the offset for now; it doesn't matter for unwinding frames. */
979 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
980 initial_return_save (XEXP (rtl, 0));
987 if (reg != DWARF_FRAME_RETURN_COLUMN)
988 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
991 /* Given a SET, calculate the amount of stack adjustment it
995 stack_adjust_offset (rtx pattern)
997 rtx src = SET_SRC (pattern);
998 rtx dest = SET_DEST (pattern);
999 HOST_WIDE_INT offset = 0;
1002 if (dest == stack_pointer_rtx)
1004 /* (set (reg sp) (plus (reg sp) (const_int))) */
1005 code = GET_CODE (src);
1006 if (! (code == PLUS || code == MINUS)
1007 || XEXP (src, 0) != stack_pointer_rtx
1008 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1011 offset = INTVAL (XEXP (src, 1));
1015 else if (MEM_P (dest))
1017 /* (set (mem (pre_dec (reg sp))) (foo)) */
1018 src = XEXP (dest, 0);
1019 code = GET_CODE (src);
1025 if (XEXP (src, 0) == stack_pointer_rtx)
1027 rtx val = XEXP (XEXP (src, 1), 1);
1028 /* We handle only adjustments by constant amount. */
1029 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1030 && GET_CODE (val) == CONST_INT);
1031 offset = -INTVAL (val);
1038 if (XEXP (src, 0) == stack_pointer_rtx)
1040 offset = GET_MODE_SIZE (GET_MODE (dest));
1047 if (XEXP (src, 0) == stack_pointer_rtx)
1049 offset = -GET_MODE_SIZE (GET_MODE (dest));
1064 /* Check INSN to see if it looks like a push or a stack adjustment, and
1065 make a note of it if it does. EH uses this information to find out how
1066 much extra space it needs to pop off the stack. */
1069 dwarf2out_stack_adjust (rtx insn, bool after_p)
1071 HOST_WIDE_INT offset;
1075 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1076 with this function. Proper support would require all frame-related
1077 insns to be marked, and to be able to handle saving state around
1078 epilogues textually in the middle of the function. */
1079 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1082 /* If only calls can throw, and we have a frame pointer,
1083 save up adjustments until we see the CALL_INSN. */
1084 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1086 if (CALL_P (insn) && !after_p)
1088 /* Extract the size of the args from the CALL rtx itself. */
1089 insn = PATTERN (insn);
1090 if (GET_CODE (insn) == PARALLEL)
1091 insn = XVECEXP (insn, 0, 0);
1092 if (GET_CODE (insn) == SET)
1093 insn = SET_SRC (insn);
1094 gcc_assert (GET_CODE (insn) == CALL);
1095 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1100 if (CALL_P (insn) && !after_p)
1102 if (!flag_asynchronous_unwind_tables)
1103 dwarf2out_args_size ("", args_size);
1106 else if (BARRIER_P (insn))
1108 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1109 the compiler will have already emitted a stack adjustment, but
1110 doesn't bother for calls to noreturn functions. */
1111 #ifdef STACK_GROWS_DOWNWARD
1112 offset = -args_size;
1117 else if (GET_CODE (PATTERN (insn)) == SET)
1118 offset = stack_adjust_offset (PATTERN (insn));
1119 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1120 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1122 /* There may be stack adjustments inside compound insns. Search
1124 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1125 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1126 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1134 if (cfa.reg == STACK_POINTER_REGNUM)
1135 cfa.offset += offset;
1137 #ifndef STACK_GROWS_DOWNWARD
1141 args_size += offset;
1145 label = dwarf2out_cfi_label ();
1146 def_cfa_1 (label, &cfa);
1147 if (flag_asynchronous_unwind_tables)
1148 dwarf2out_args_size (label, args_size);
1153 /* We delay emitting a register save until either (a) we reach the end
1154 of the prologue or (b) the register is clobbered. This clusters
1155 register saves so that there are fewer pc advances. */
1157 struct queued_reg_save GTY(())
1159 struct queued_reg_save *next;
1161 HOST_WIDE_INT cfa_offset;
1165 static GTY(()) struct queued_reg_save *queued_reg_saves;
1167 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1168 struct reg_saved_in_data GTY(()) {
1173 /* A list of registers saved in other registers.
1174 The list intentionally has a small maximum capacity of 4; if your
1175 port needs more than that, you might consider implementing a
1176 more efficient data structure. */
1177 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1178 static GTY(()) size_t num_regs_saved_in_regs;
1180 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1181 static const char *last_reg_save_label;
1183 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1184 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1187 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1189 struct queued_reg_save *q;
1191 /* Duplicates waste space, but it's also necessary to remove them
1192 for correctness, since the queue gets output in reverse
1194 for (q = queued_reg_saves; q != NULL; q = q->next)
1195 if (REGNO (q->reg) == REGNO (reg))
1200 q = ggc_alloc (sizeof (*q));
1201 q->next = queued_reg_saves;
1202 queued_reg_saves = q;
1206 q->cfa_offset = offset;
1207 q->saved_reg = sreg;
1209 last_reg_save_label = label;
1212 /* Output all the entries in QUEUED_REG_SAVES. */
1215 flush_queued_reg_saves (void)
1217 struct queued_reg_save *q;
1219 for (q = queued_reg_saves; q; q = q->next)
1222 unsigned int reg, sreg;
1224 for (i = 0; i < num_regs_saved_in_regs; i++)
1225 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1227 if (q->saved_reg && i == num_regs_saved_in_regs)
1229 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1230 num_regs_saved_in_regs++;
1232 if (i != num_regs_saved_in_regs)
1234 regs_saved_in_regs[i].orig_reg = q->reg;
1235 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1238 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1240 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1242 sreg = INVALID_REGNUM;
1243 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1246 queued_reg_saves = NULL;
1247 last_reg_save_label = NULL;
1250 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1251 location for? Or, does it clobber a register which we've previously
1252 said that some other register is saved in, and for which we now
1253 have a new location for? */
1256 clobbers_queued_reg_save (rtx insn)
1258 struct queued_reg_save *q;
1260 for (q = queued_reg_saves; q; q = q->next)
1263 if (modified_in_p (q->reg, insn))
1265 for (i = 0; i < num_regs_saved_in_regs; i++)
1266 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1267 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1274 /* Entry point for saving the first register into the second. */
1277 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1280 unsigned int regno, sregno;
1282 for (i = 0; i < num_regs_saved_in_regs; i++)
1283 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1285 if (i == num_regs_saved_in_regs)
1287 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1288 num_regs_saved_in_regs++;
1290 regs_saved_in_regs[i].orig_reg = reg;
1291 regs_saved_in_regs[i].saved_in_reg = sreg;
1293 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1294 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1295 reg_save (label, regno, sregno, 0);
1298 /* What register, if any, is currently saved in REG? */
1301 reg_saved_in (rtx reg)
1303 unsigned int regn = REGNO (reg);
1305 struct queued_reg_save *q;
1307 for (q = queued_reg_saves; q; q = q->next)
1308 if (q->saved_reg && regn == REGNO (q->saved_reg))
1311 for (i = 0; i < num_regs_saved_in_regs; i++)
1312 if (regs_saved_in_regs[i].saved_in_reg
1313 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1314 return regs_saved_in_regs[i].orig_reg;
1320 /* A temporary register holding an integral value used in adjusting SP
1321 or setting up the store_reg. The "offset" field holds the integer
1322 value, not an offset. */
1323 static dw_cfa_location cfa_temp;
1325 /* Record call frame debugging information for an expression EXPR,
1326 which either sets SP or FP (adjusting how we calculate the frame
1327 address) or saves a register to the stack or another register.
1328 LABEL indicates the address of EXPR.
1330 This function encodes a state machine mapping rtxes to actions on
1331 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1332 users need not read the source code.
1334 The High-Level Picture
1336 Changes in the register we use to calculate the CFA: Currently we
1337 assume that if you copy the CFA register into another register, we
1338 should take the other one as the new CFA register; this seems to
1339 work pretty well. If it's wrong for some target, it's simple
1340 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1342 Changes in the register we use for saving registers to the stack:
1343 This is usually SP, but not always. Again, we deduce that if you
1344 copy SP into another register (and SP is not the CFA register),
1345 then the new register is the one we will be using for register
1346 saves. This also seems to work.
1348 Register saves: There's not much guesswork about this one; if
1349 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1350 register save, and the register used to calculate the destination
1351 had better be the one we think we're using for this purpose.
1352 It's also assumed that a copy from a call-saved register to another
1353 register is saving that register if RTX_FRAME_RELATED_P is set on
1354 that instruction. If the copy is from a call-saved register to
1355 the *same* register, that means that the register is now the same
1356 value as in the caller.
1358 Except: If the register being saved is the CFA register, and the
1359 offset is nonzero, we are saving the CFA, so we assume we have to
1360 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1361 the intent is to save the value of SP from the previous frame.
1363 In addition, if a register has previously been saved to a different
1366 Invariants / Summaries of Rules
1368 cfa current rule for calculating the CFA. It usually
1369 consists of a register and an offset.
1370 cfa_store register used by prologue code to save things to the stack
1371 cfa_store.offset is the offset from the value of
1372 cfa_store.reg to the actual CFA
1373 cfa_temp register holding an integral value. cfa_temp.offset
1374 stores the value, which will be used to adjust the
1375 stack pointer. cfa_temp is also used like cfa_store,
1376 to track stores to the stack via fp or a temp reg.
1378 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1379 with cfa.reg as the first operand changes the cfa.reg and its
1380 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1383 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1384 expression yielding a constant. This sets cfa_temp.reg
1385 and cfa_temp.offset.
1387 Rule 5: Create a new register cfa_store used to save items to the
1390 Rules 10-14: Save a register to the stack. Define offset as the
1391 difference of the original location and cfa_store's
1392 location (or cfa_temp's location if cfa_temp is used).
1396 "{a,b}" indicates a choice of a xor b.
1397 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1400 (set <reg1> <reg2>:cfa.reg)
1401 effects: cfa.reg = <reg1>
1402 cfa.offset unchanged
1403 cfa_temp.reg = <reg1>
1404 cfa_temp.offset = cfa.offset
1407 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1408 {<const_int>,<reg>:cfa_temp.reg}))
1409 effects: cfa.reg = sp if fp used
1410 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1411 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1412 if cfa_store.reg==sp
1415 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1416 effects: cfa.reg = fp
1417 cfa_offset += +/- <const_int>
1420 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1421 constraints: <reg1> != fp
1423 effects: cfa.reg = <reg1>
1424 cfa_temp.reg = <reg1>
1425 cfa_temp.offset = cfa.offset
1428 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1429 constraints: <reg1> != fp
1431 effects: cfa_store.reg = <reg1>
1432 cfa_store.offset = cfa.offset - cfa_temp.offset
1435 (set <reg> <const_int>)
1436 effects: cfa_temp.reg = <reg>
1437 cfa_temp.offset = <const_int>
1440 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1441 effects: cfa_temp.reg = <reg1>
1442 cfa_temp.offset |= <const_int>
1445 (set <reg> (high <exp>))
1449 (set <reg> (lo_sum <exp> <const_int>))
1450 effects: cfa_temp.reg = <reg>
1451 cfa_temp.offset = <const_int>
1454 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1455 effects: cfa_store.offset -= <const_int>
1456 cfa.offset = cfa_store.offset if cfa.reg == sp
1458 cfa.base_offset = -cfa_store.offset
1461 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1462 effects: cfa_store.offset += -/+ mode_size(mem)
1463 cfa.offset = cfa_store.offset if cfa.reg == sp
1465 cfa.base_offset = -cfa_store.offset
1468 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1471 effects: cfa.reg = <reg1>
1472 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1475 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1476 effects: cfa.reg = <reg1>
1477 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1480 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1481 effects: cfa.reg = <reg1>
1482 cfa.base_offset = -cfa_temp.offset
1483 cfa_temp.offset -= mode_size(mem)
1486 Â (set <reg> {unspec, unspec_volatile})
1487 Â effects: target-dependent */
1490 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1493 HOST_WIDE_INT offset;
1495 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1496 the PARALLEL independently. The first element is always processed if
1497 it is a SET. This is for backward compatibility. Other elements
1498 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1499 flag is set in them. */
1500 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1503 int limit = XVECLEN (expr, 0);
1505 for (par_index = 0; par_index < limit; par_index++)
1506 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1507 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1509 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1514 gcc_assert (GET_CODE (expr) == SET);
1516 src = SET_SRC (expr);
1517 dest = SET_DEST (expr);
1521 rtx rsi = reg_saved_in (src);
1526 switch (GET_CODE (dest))
1529 switch (GET_CODE (src))
1531 /* Setting FP from SP. */
1533 if (cfa.reg == (unsigned) REGNO (src))
1536 /* Update the CFA rule wrt SP or FP. Make sure src is
1537 relative to the current CFA register.
1539 We used to require that dest be either SP or FP, but the
1540 ARM copies SP to a temporary register, and from there to
1541 FP. So we just rely on the backends to only set
1542 RTX_FRAME_RELATED_P on appropriate insns. */
1543 cfa.reg = REGNO (dest);
1544 cfa_temp.reg = cfa.reg;
1545 cfa_temp.offset = cfa.offset;
1549 /* Saving a register in a register. */
1550 gcc_assert (call_used_regs [REGNO (dest)]
1551 && (!fixed_regs [REGNO (dest)]
1552 /* For the SPARC and its register window. */
1553 || DWARF_FRAME_REGNUM (REGNO (src))
1554 == DWARF_FRAME_RETURN_COLUMN));
1555 queue_reg_save (label, src, dest, 0);
1562 if (dest == stack_pointer_rtx)
1566 switch (GET_CODE (XEXP (src, 1)))
1569 offset = INTVAL (XEXP (src, 1));
1572 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1574 offset = cfa_temp.offset;
1580 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1582 /* Restoring SP from FP in the epilogue. */
1583 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1584 cfa.reg = STACK_POINTER_REGNUM;
1586 else if (GET_CODE (src) == LO_SUM)
1587 /* Assume we've set the source reg of the LO_SUM from sp. */
1590 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1592 if (GET_CODE (src) != MINUS)
1594 if (cfa.reg == STACK_POINTER_REGNUM)
1595 cfa.offset += offset;
1596 if (cfa_store.reg == STACK_POINTER_REGNUM)
1597 cfa_store.offset += offset;
1599 else if (dest == hard_frame_pointer_rtx)
1602 /* Either setting the FP from an offset of the SP,
1603 or adjusting the FP */
1604 gcc_assert (frame_pointer_needed);
1606 gcc_assert (REG_P (XEXP (src, 0))
1607 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1608 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1609 offset = INTVAL (XEXP (src, 1));
1610 if (GET_CODE (src) != MINUS)
1612 cfa.offset += offset;
1613 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1617 gcc_assert (GET_CODE (src) != MINUS);
1620 if (REG_P (XEXP (src, 0))
1621 && REGNO (XEXP (src, 0)) == cfa.reg
1622 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1624 /* Setting a temporary CFA register that will be copied
1625 into the FP later on. */
1626 offset = - INTVAL (XEXP (src, 1));
1627 cfa.offset += offset;
1628 cfa.reg = REGNO (dest);
1629 /* Or used to save regs to the stack. */
1630 cfa_temp.reg = cfa.reg;
1631 cfa_temp.offset = cfa.offset;
1635 else if (REG_P (XEXP (src, 0))
1636 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1637 && XEXP (src, 1) == stack_pointer_rtx)
1639 /* Setting a scratch register that we will use instead
1640 of SP for saving registers to the stack. */
1641 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
1642 cfa_store.reg = REGNO (dest);
1643 cfa_store.offset = cfa.offset - cfa_temp.offset;
1647 else if (GET_CODE (src) == LO_SUM
1648 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1650 cfa_temp.reg = REGNO (dest);
1651 cfa_temp.offset = INTVAL (XEXP (src, 1));
1660 cfa_temp.reg = REGNO (dest);
1661 cfa_temp.offset = INTVAL (src);
1666 gcc_assert (REG_P (XEXP (src, 0))
1667 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
1668 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1670 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1671 cfa_temp.reg = REGNO (dest);
1672 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1675 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1676 which will fill in all of the bits. */
1683 case UNSPEC_VOLATILE:
1684 gcc_assert (targetm.dwarf_handle_frame_unspec);
1685 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
1692 def_cfa_1 (label, &cfa);
1696 gcc_assert (REG_P (src));
1698 /* Saving a register to the stack. Make sure dest is relative to the
1700 switch (GET_CODE (XEXP (dest, 0)))
1705 /* We can't handle variable size modifications. */
1706 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
1708 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1710 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1711 && cfa_store.reg == STACK_POINTER_REGNUM);
1713 cfa_store.offset += offset;
1714 if (cfa.reg == STACK_POINTER_REGNUM)
1715 cfa.offset = cfa_store.offset;
1717 offset = -cfa_store.offset;
1723 offset = GET_MODE_SIZE (GET_MODE (dest));
1724 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1727 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1728 && cfa_store.reg == STACK_POINTER_REGNUM);
1730 cfa_store.offset += offset;
1731 if (cfa.reg == STACK_POINTER_REGNUM)
1732 cfa.offset = cfa_store.offset;
1734 offset = -cfa_store.offset;
1738 /* With an offset. */
1745 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT);
1746 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1747 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1750 regno = REGNO (XEXP (XEXP (dest, 0), 0));
1752 if (cfa_store.reg == (unsigned) regno)
1753 offset -= cfa_store.offset;
1756 gcc_assert (cfa_temp.reg == (unsigned) regno);
1757 offset -= cfa_temp.offset;
1763 /* Without an offset. */
1766 int regno = REGNO (XEXP (dest, 0));
1768 if (cfa_store.reg == (unsigned) regno)
1769 offset = -cfa_store.offset;
1772 gcc_assert (cfa_temp.reg == (unsigned) regno);
1773 offset = -cfa_temp.offset;
1780 gcc_assert (cfa_temp.reg
1781 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
1782 offset = -cfa_temp.offset;
1783 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1790 if (REGNO (src) != STACK_POINTER_REGNUM
1791 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1792 && (unsigned) REGNO (src) == cfa.reg)
1794 /* We're storing the current CFA reg into the stack. */
1796 if (cfa.offset == 0)
1798 /* If the source register is exactly the CFA, assume
1799 we're saving SP like any other register; this happens
1801 def_cfa_1 (label, &cfa);
1802 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
1807 /* Otherwise, we'll need to look in the stack to
1808 calculate the CFA. */
1809 rtx x = XEXP (dest, 0);
1813 gcc_assert (REG_P (x));
1815 cfa.reg = REGNO (x);
1816 cfa.base_offset = offset;
1818 def_cfa_1 (label, &cfa);
1823 def_cfa_1 (label, &cfa);
1824 queue_reg_save (label, src, NULL_RTX, offset);
1832 /* Record call frame debugging information for INSN, which either
1833 sets SP or FP (adjusting how we calculate the frame address) or saves a
1834 register to the stack. If INSN is NULL_RTX, initialize our state.
1836 If AFTER_P is false, we're being called before the insn is emitted,
1837 otherwise after. Call instructions get invoked twice. */
1840 dwarf2out_frame_debug (rtx insn, bool after_p)
1845 if (insn == NULL_RTX)
1849 /* Flush any queued register saves. */
1850 flush_queued_reg_saves ();
1852 /* Set up state for generating call frame debug info. */
1855 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1857 cfa.reg = STACK_POINTER_REGNUM;
1860 cfa_temp.offset = 0;
1862 for (i = 0; i < num_regs_saved_in_regs; i++)
1864 regs_saved_in_regs[i].orig_reg = NULL_RTX;
1865 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
1867 num_regs_saved_in_regs = 0;
1871 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
1872 flush_queued_reg_saves ();
1874 if (! RTX_FRAME_RELATED_P (insn))
1876 if (!ACCUMULATE_OUTGOING_ARGS)
1877 dwarf2out_stack_adjust (insn, after_p);
1881 label = dwarf2out_cfi_label ();
1882 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1884 insn = XEXP (src, 0);
1886 insn = PATTERN (insn);
1888 dwarf2out_frame_debug_expr (insn, label);
1893 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1894 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1895 (enum dwarf_call_frame_info cfi);
1897 static enum dw_cfi_oprnd_type
1898 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1903 case DW_CFA_GNU_window_save:
1904 return dw_cfi_oprnd_unused;
1906 case DW_CFA_set_loc:
1907 case DW_CFA_advance_loc1:
1908 case DW_CFA_advance_loc2:
1909 case DW_CFA_advance_loc4:
1910 case DW_CFA_MIPS_advance_loc8:
1911 return dw_cfi_oprnd_addr;
1914 case DW_CFA_offset_extended:
1915 case DW_CFA_def_cfa:
1916 case DW_CFA_offset_extended_sf:
1917 case DW_CFA_def_cfa_sf:
1918 case DW_CFA_restore_extended:
1919 case DW_CFA_undefined:
1920 case DW_CFA_same_value:
1921 case DW_CFA_def_cfa_register:
1922 case DW_CFA_register:
1923 return dw_cfi_oprnd_reg_num;
1925 case DW_CFA_def_cfa_offset:
1926 case DW_CFA_GNU_args_size:
1927 case DW_CFA_def_cfa_offset_sf:
1928 return dw_cfi_oprnd_offset;
1930 case DW_CFA_def_cfa_expression:
1931 case DW_CFA_expression:
1932 return dw_cfi_oprnd_loc;
1939 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1940 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1941 (enum dwarf_call_frame_info cfi);
1943 static enum dw_cfi_oprnd_type
1944 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1948 case DW_CFA_def_cfa:
1949 case DW_CFA_def_cfa_sf:
1951 case DW_CFA_offset_extended_sf:
1952 case DW_CFA_offset_extended:
1953 return dw_cfi_oprnd_offset;
1955 case DW_CFA_register:
1956 return dw_cfi_oprnd_reg_num;
1959 return dw_cfi_oprnd_unused;
1963 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1965 /* Map register numbers held in the call frame info that gcc has
1966 collected using DWARF_FRAME_REGNUM to those that should be output in
1967 .debug_frame and .eh_frame. */
1968 #ifndef DWARF2_FRAME_REG_OUT
1969 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
1972 /* Output a Call Frame Information opcode and its operand(s). */
1975 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
1978 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1979 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1980 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1981 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
1982 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1983 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1985 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1986 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
1987 "DW_CFA_offset, column 0x%lx", r);
1988 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1990 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1992 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1993 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
1994 "DW_CFA_restore, column 0x%lx", r);
1998 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1999 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2001 switch (cfi->dw_cfi_opc)
2003 case DW_CFA_set_loc:
2005 dw2_asm_output_encoded_addr_rtx (
2006 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2007 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2010 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2011 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2014 case DW_CFA_advance_loc1:
2015 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2016 fde->dw_fde_current_label, NULL);
2017 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2020 case DW_CFA_advance_loc2:
2021 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2022 fde->dw_fde_current_label, NULL);
2023 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2026 case DW_CFA_advance_loc4:
2027 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2028 fde->dw_fde_current_label, NULL);
2029 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2032 case DW_CFA_MIPS_advance_loc8:
2033 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2034 fde->dw_fde_current_label, NULL);
2035 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2038 case DW_CFA_offset_extended:
2039 case DW_CFA_def_cfa:
2040 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2041 dw2_asm_output_data_uleb128 (r, NULL);
2042 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2045 case DW_CFA_offset_extended_sf:
2046 case DW_CFA_def_cfa_sf:
2047 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2048 dw2_asm_output_data_uleb128 (r, NULL);
2049 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2052 case DW_CFA_restore_extended:
2053 case DW_CFA_undefined:
2054 case DW_CFA_same_value:
2055 case DW_CFA_def_cfa_register:
2056 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2057 dw2_asm_output_data_uleb128 (r, NULL);
2060 case DW_CFA_register:
2061 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2062 dw2_asm_output_data_uleb128 (r, NULL);
2063 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2064 dw2_asm_output_data_uleb128 (r, NULL);
2067 case DW_CFA_def_cfa_offset:
2068 case DW_CFA_GNU_args_size:
2069 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2072 case DW_CFA_def_cfa_offset_sf:
2073 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2076 case DW_CFA_GNU_window_save:
2079 case DW_CFA_def_cfa_expression:
2080 case DW_CFA_expression:
2081 output_cfa_loc (cfi);
2084 case DW_CFA_GNU_negative_offset_extended:
2085 /* Obsoleted by DW_CFA_offset_extended_sf. */
2094 /* Output the call frame information used to record information
2095 that relates to calculating the frame pointer, and records the
2096 location of saved registers. */
2099 output_call_frame_info (int for_eh)
2104 char l1[20], l2[20], section_start_label[20];
2105 bool any_lsda_needed = false;
2106 char augmentation[6];
2107 int augmentation_size;
2108 int fde_encoding = DW_EH_PE_absptr;
2109 int per_encoding = DW_EH_PE_absptr;
2110 int lsda_encoding = DW_EH_PE_absptr;
2113 /* Don't emit a CIE if there won't be any FDEs. */
2114 if (fde_table_in_use == 0)
2117 /* If we make FDEs linkonce, we may have to emit an empty label for
2118 an FDE that wouldn't otherwise be emitted. We want to avoid
2119 having an FDE kept around when the function it refers to is
2120 discarded. Example where this matters: a primary function
2121 template in C++ requires EH information, but an explicit
2122 specialization doesn't. */
2123 if (TARGET_USES_WEAK_UNWIND_INFO
2124 && ! flag_asynchronous_unwind_tables
2126 for (i = 0; i < fde_table_in_use; i++)
2127 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2128 && !fde_table[i].uses_eh_lsda
2129 && ! DECL_WEAK (fde_table[i].decl))
2130 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2131 for_eh, /* empty */ 1);
2133 /* If we don't have any functions we'll want to unwind out of, don't
2134 emit any EH unwind information. Note that if exceptions aren't
2135 enabled, we won't have collected nothrow information, and if we
2136 asked for asynchronous tables, we always want this info. */
2139 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2141 for (i = 0; i < fde_table_in_use; i++)
2142 if (fde_table[i].uses_eh_lsda)
2143 any_eh_needed = any_lsda_needed = true;
2144 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2145 any_eh_needed = true;
2146 else if (! fde_table[i].nothrow
2147 && ! fde_table[i].all_throwers_are_sibcalls)
2148 any_eh_needed = true;
2150 if (! any_eh_needed)
2154 /* We're going to be generating comments, so turn on app. */
2159 targetm.asm_out.eh_frame_section ();
2161 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
2163 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2164 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2166 /* Output the CIE. */
2167 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2168 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2169 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2170 "Length of Common Information Entry");
2171 ASM_OUTPUT_LABEL (asm_out_file, l1);
2173 /* Now that the CIE pointer is PC-relative for EH,
2174 use 0 to identify the CIE. */
2175 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2176 (for_eh ? 0 : DW_CIE_ID),
2177 "CIE Identifier Tag");
2179 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2181 augmentation[0] = 0;
2182 augmentation_size = 0;
2188 z Indicates that a uleb128 is present to size the
2189 augmentation section.
2190 L Indicates the encoding (and thus presence) of
2191 an LSDA pointer in the FDE augmentation.
2192 R Indicates a non-default pointer encoding for
2194 P Indicates the presence of an encoding + language
2195 personality routine in the CIE augmentation. */
2197 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2198 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2199 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2201 p = augmentation + 1;
2202 if (eh_personality_libfunc)
2205 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2207 if (any_lsda_needed)
2210 augmentation_size += 1;
2212 if (fde_encoding != DW_EH_PE_absptr)
2215 augmentation_size += 1;
2217 if (p > augmentation + 1)
2219 augmentation[0] = 'z';
2223 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2224 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2226 int offset = ( 4 /* Length */
2228 + 1 /* CIE version */
2229 + strlen (augmentation) + 1 /* Augmentation */
2230 + size_of_uleb128 (1) /* Code alignment */
2231 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2233 + 1 /* Augmentation size */
2234 + 1 /* Personality encoding */ );
2235 int pad = -offset & (PTR_SIZE - 1);
2237 augmentation_size += pad;
2239 /* Augmentations should be small, so there's scarce need to
2240 iterate for a solution. Die if we exceed one uleb128 byte. */
2241 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2245 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2246 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2247 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2248 "CIE Data Alignment Factor");
2250 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2251 if (DW_CIE_VERSION == 1)
2252 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2254 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2256 if (augmentation[0])
2258 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2259 if (eh_personality_libfunc)
2261 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2262 eh_data_format_name (per_encoding));
2263 dw2_asm_output_encoded_addr_rtx (per_encoding,
2264 eh_personality_libfunc,
2268 if (any_lsda_needed)
2269 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2270 eh_data_format_name (lsda_encoding));
2272 if (fde_encoding != DW_EH_PE_absptr)
2273 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2274 eh_data_format_name (fde_encoding));
2277 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2278 output_cfi (cfi, NULL, for_eh);
2280 /* Pad the CIE out to an address sized boundary. */
2281 ASM_OUTPUT_ALIGN (asm_out_file,
2282 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2283 ASM_OUTPUT_LABEL (asm_out_file, l2);
2285 /* Loop through all of the FDE's. */
2286 for (i = 0; i < fde_table_in_use; i++)
2288 fde = &fde_table[i];
2290 /* Don't emit EH unwind info for leaf functions that don't need it. */
2291 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2292 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2293 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2294 && !fde->uses_eh_lsda)
2297 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2298 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2299 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2300 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2301 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2303 ASM_OUTPUT_LABEL (asm_out_file, l1);
2306 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2308 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2313 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2314 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2315 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2318 "FDE initial location");
2319 if (fde->dw_fde_switched_sections)
2321 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2322 fde->dw_fde_unlikely_section_label);
2323 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2324 fde->dw_fde_hot_section_label);
2325 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2326 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2327 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
2328 "FDE initial location");
2329 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2330 fde->dw_fde_hot_section_end_label,
2331 fde->dw_fde_hot_section_label,
2332 "FDE address range");
2333 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
2334 "FDE initial location");
2335 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2336 fde->dw_fde_unlikely_section_end_label,
2337 fde->dw_fde_unlikely_section_label,
2338 "FDE address range");
2341 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2342 fde->dw_fde_end, fde->dw_fde_begin,
2343 "FDE address range");
2347 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2348 "FDE initial location");
2349 if (fde->dw_fde_switched_sections)
2351 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2352 fde->dw_fde_hot_section_label,
2353 "FDE initial location");
2354 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2355 fde->dw_fde_hot_section_end_label,
2356 fde->dw_fde_hot_section_label,
2357 "FDE address range");
2358 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2359 fde->dw_fde_unlikely_section_label,
2360 "FDE initial location");
2361 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2362 fde->dw_fde_unlikely_section_end_label,
2363 fde->dw_fde_unlikely_section_label,
2364 "FDE address range");
2367 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2368 fde->dw_fde_end, fde->dw_fde_begin,
2369 "FDE address range");
2372 if (augmentation[0])
2374 if (any_lsda_needed)
2376 int size = size_of_encoded_value (lsda_encoding);
2378 if (lsda_encoding == DW_EH_PE_aligned)
2380 int offset = ( 4 /* Length */
2381 + 4 /* CIE offset */
2382 + 2 * size_of_encoded_value (fde_encoding)
2383 + 1 /* Augmentation size */ );
2384 int pad = -offset & (PTR_SIZE - 1);
2387 gcc_assert (size_of_uleb128 (size) == 1);
2390 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2392 if (fde->uses_eh_lsda)
2394 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2395 fde->funcdef_number);
2396 dw2_asm_output_encoded_addr_rtx (
2397 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2398 false, "Language Specific Data Area");
2402 if (lsda_encoding == DW_EH_PE_aligned)
2403 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2405 (size_of_encoded_value (lsda_encoding), 0,
2406 "Language Specific Data Area (none)");
2410 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2413 /* Loop through the Call Frame Instructions associated with
2415 fde->dw_fde_current_label = fde->dw_fde_begin;
2416 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2417 output_cfi (cfi, fde, for_eh);
2419 /* Pad the FDE out to an address sized boundary. */
2420 ASM_OUTPUT_ALIGN (asm_out_file,
2421 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2422 ASM_OUTPUT_LABEL (asm_out_file, l2);
2425 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2426 dw2_asm_output_data (4, 0, "End of Table");
2427 #ifdef MIPS_DEBUGGING_INFO
2428 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2429 get a value of 0. Putting .align 0 after the label fixes it. */
2430 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2433 /* Turn off app to make assembly quicker. */
2438 /* Output a marker (i.e. a label) for the beginning of a function, before
2442 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2443 const char *file ATTRIBUTE_UNUSED)
2445 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2449 current_function_func_begin_label = NULL;
2451 #ifdef TARGET_UNWIND_INFO
2452 /* ??? current_function_func_begin_label is also used by except.c
2453 for call-site information. We must emit this label if it might
2455 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2456 && ! dwarf2out_do_frame ())
2459 if (! dwarf2out_do_frame ())
2463 function_section (current_function_decl);
2464 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2465 current_function_funcdef_no);
2466 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2467 current_function_funcdef_no);
2468 dup_label = xstrdup (label);
2469 current_function_func_begin_label = dup_label;
2471 #ifdef TARGET_UNWIND_INFO
2472 /* We can elide the fde allocation if we're not emitting debug info. */
2473 if (! dwarf2out_do_frame ())
2477 /* Expand the fde table if necessary. */
2478 if (fde_table_in_use == fde_table_allocated)
2480 fde_table_allocated += FDE_TABLE_INCREMENT;
2481 fde_table = ggc_realloc (fde_table,
2482 fde_table_allocated * sizeof (dw_fde_node));
2483 memset (fde_table + fde_table_in_use, 0,
2484 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2487 /* Record the FDE associated with this function. */
2488 current_funcdef_fde = fde_table_in_use;
2490 /* Add the new FDE at the end of the fde_table. */
2491 fde = &fde_table[fde_table_in_use++];
2492 fde->decl = current_function_decl;
2493 fde->dw_fde_begin = dup_label;
2494 fde->dw_fde_current_label = NULL;
2495 fde->dw_fde_hot_section_label = NULL;
2496 fde->dw_fde_hot_section_end_label = NULL;
2497 fde->dw_fde_unlikely_section_label = NULL;
2498 fde->dw_fde_unlikely_section_end_label = NULL;
2499 fde->dw_fde_switched_sections = false;
2500 fde->dw_fde_end = NULL;
2501 fde->dw_fde_cfi = NULL;
2502 fde->funcdef_number = current_function_funcdef_no;
2503 fde->nothrow = TREE_NOTHROW (current_function_decl);
2504 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2505 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2507 args_size = old_args_size = 0;
2509 /* We only want to output line number information for the genuine dwarf2
2510 prologue case, not the eh frame case. */
2511 #ifdef DWARF2_DEBUGGING_INFO
2513 dwarf2out_source_line (line, file);
2517 /* Output a marker (i.e. a label) for the absolute end of the generated code
2518 for a function definition. This gets called *after* the epilogue code has
2522 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2523 const char *file ATTRIBUTE_UNUSED)
2526 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2528 /* Output a label to mark the endpoint of the code generated for this
2530 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2531 current_function_funcdef_no);
2532 ASM_OUTPUT_LABEL (asm_out_file, label);
2533 fde = &fde_table[fde_table_in_use - 1];
2534 fde->dw_fde_end = xstrdup (label);
2538 dwarf2out_frame_init (void)
2540 /* Allocate the initial hunk of the fde_table. */
2541 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2542 fde_table_allocated = FDE_TABLE_INCREMENT;
2543 fde_table_in_use = 0;
2545 /* Generate the CFA instructions common to all FDE's. Do it now for the
2546 sake of lookup_cfa. */
2548 #ifdef DWARF2_UNWIND_INFO
2549 /* On entry, the Canonical Frame Address is at SP. */
2550 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2551 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2556 dwarf2out_frame_finish (void)
2558 /* Output call frame information. */
2559 if (write_symbols == DWARF2_DEBUG
2560 || write_symbols == VMS_AND_DWARF2_DEBUG
2561 #ifdef DWARF2_FRAME_INFO
2562 || DWARF2_FRAME_INFO
2565 output_call_frame_info (0);
2567 #ifndef TARGET_UNWIND_INFO
2568 /* Output another copy for the unwinder. */
2569 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2570 output_call_frame_info (1);
2575 /* And now, the subset of the debugging information support code necessary
2576 for emitting location expressions. */
2578 /* We need some way to distinguish DW_OP_addr with a direct symbol
2579 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2580 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2583 typedef struct dw_val_struct *dw_val_ref;
2584 typedef struct die_struct *dw_die_ref;
2585 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2586 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2588 /* Each DIE may have a series of attribute/value pairs. Values
2589 can take on several forms. The forms that are used in this
2590 implementation are listed below. */
2595 dw_val_class_offset,
2597 dw_val_class_loc_list,
2598 dw_val_class_range_list,
2600 dw_val_class_unsigned_const,
2601 dw_val_class_long_long,
2604 dw_val_class_die_ref,
2605 dw_val_class_fde_ref,
2606 dw_val_class_lbl_id,
2607 dw_val_class_lbl_offset,
2611 /* Describe a double word constant value. */
2612 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2614 typedef struct dw_long_long_struct GTY(())
2621 /* Describe a floating point constant value, or a vector constant value. */
2623 typedef struct dw_vec_struct GTY(())
2625 unsigned char * GTY((length ("%h.length"))) array;
2631 /* The dw_val_node describes an attribute's value, as it is
2632 represented internally. */
2634 typedef struct dw_val_struct GTY(())
2636 enum dw_val_class val_class;
2637 union dw_val_struct_union
2639 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2640 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2641 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2642 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2643 HOST_WIDE_INT GTY ((default)) val_int;
2644 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2645 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2646 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2647 struct dw_val_die_union
2651 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2652 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2653 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2654 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2655 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2657 GTY ((desc ("%1.val_class"))) v;
2661 /* Locations in memory are described using a sequence of stack machine
2664 typedef struct dw_loc_descr_struct GTY(())
2666 dw_loc_descr_ref dw_loc_next;
2667 enum dwarf_location_atom dw_loc_opc;
2668 dw_val_node dw_loc_oprnd1;
2669 dw_val_node dw_loc_oprnd2;
2674 /* Location lists are ranges + location descriptions for that range,
2675 so you can track variables that are in different places over
2676 their entire life. */
2677 typedef struct dw_loc_list_struct GTY(())
2679 dw_loc_list_ref dw_loc_next;
2680 const char *begin; /* Label for begin address of range */
2681 const char *end; /* Label for end address of range */
2682 char *ll_symbol; /* Label for beginning of location list.
2683 Only on head of list */
2684 const char *section; /* Section this loclist is relative to */
2685 dw_loc_descr_ref expr;
2688 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2690 static const char *dwarf_stack_op_name (unsigned);
2691 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2692 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2693 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2694 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2695 static unsigned long size_of_locs (dw_loc_descr_ref);
2696 static void output_loc_operands (dw_loc_descr_ref);
2697 static void output_loc_sequence (dw_loc_descr_ref);
2699 /* Convert a DWARF stack opcode into its string name. */
2702 dwarf_stack_op_name (unsigned int op)
2707 case INTERNAL_DW_OP_tls_addr:
2708 return "DW_OP_addr";
2710 return "DW_OP_deref";
2712 return "DW_OP_const1u";
2714 return "DW_OP_const1s";
2716 return "DW_OP_const2u";
2718 return "DW_OP_const2s";
2720 return "DW_OP_const4u";
2722 return "DW_OP_const4s";
2724 return "DW_OP_const8u";
2726 return "DW_OP_const8s";
2728 return "DW_OP_constu";
2730 return "DW_OP_consts";
2734 return "DW_OP_drop";
2736 return "DW_OP_over";
2738 return "DW_OP_pick";
2740 return "DW_OP_swap";
2744 return "DW_OP_xderef";
2752 return "DW_OP_minus";
2764 return "DW_OP_plus";
2765 case DW_OP_plus_uconst:
2766 return "DW_OP_plus_uconst";
2772 return "DW_OP_shra";
2790 return "DW_OP_skip";
2792 return "DW_OP_lit0";
2794 return "DW_OP_lit1";
2796 return "DW_OP_lit2";
2798 return "DW_OP_lit3";
2800 return "DW_OP_lit4";
2802 return "DW_OP_lit5";
2804 return "DW_OP_lit6";
2806 return "DW_OP_lit7";
2808 return "DW_OP_lit8";
2810 return "DW_OP_lit9";
2812 return "DW_OP_lit10";
2814 return "DW_OP_lit11";
2816 return "DW_OP_lit12";
2818 return "DW_OP_lit13";
2820 return "DW_OP_lit14";
2822 return "DW_OP_lit15";
2824 return "DW_OP_lit16";
2826 return "DW_OP_lit17";
2828 return "DW_OP_lit18";
2830 return "DW_OP_lit19";
2832 return "DW_OP_lit20";
2834 return "DW_OP_lit21";
2836 return "DW_OP_lit22";
2838 return "DW_OP_lit23";
2840 return "DW_OP_lit24";
2842 return "DW_OP_lit25";
2844 return "DW_OP_lit26";
2846 return "DW_OP_lit27";
2848 return "DW_OP_lit28";
2850 return "DW_OP_lit29";
2852 return "DW_OP_lit30";
2854 return "DW_OP_lit31";
2856 return "DW_OP_reg0";
2858 return "DW_OP_reg1";
2860 return "DW_OP_reg2";
2862 return "DW_OP_reg3";
2864 return "DW_OP_reg4";
2866 return "DW_OP_reg5";
2868 return "DW_OP_reg6";
2870 return "DW_OP_reg7";
2872 return "DW_OP_reg8";
2874 return "DW_OP_reg9";
2876 return "DW_OP_reg10";
2878 return "DW_OP_reg11";
2880 return "DW_OP_reg12";
2882 return "DW_OP_reg13";
2884 return "DW_OP_reg14";
2886 return "DW_OP_reg15";
2888 return "DW_OP_reg16";
2890 return "DW_OP_reg17";
2892 return "DW_OP_reg18";
2894 return "DW_OP_reg19";
2896 return "DW_OP_reg20";
2898 return "DW_OP_reg21";
2900 return "DW_OP_reg22";
2902 return "DW_OP_reg23";
2904 return "DW_OP_reg24";
2906 return "DW_OP_reg25";
2908 return "DW_OP_reg26";
2910 return "DW_OP_reg27";
2912 return "DW_OP_reg28";
2914 return "DW_OP_reg29";
2916 return "DW_OP_reg30";
2918 return "DW_OP_reg31";
2920 return "DW_OP_breg0";
2922 return "DW_OP_breg1";
2924 return "DW_OP_breg2";
2926 return "DW_OP_breg3";
2928 return "DW_OP_breg4";
2930 return "DW_OP_breg5";
2932 return "DW_OP_breg6";
2934 return "DW_OP_breg7";
2936 return "DW_OP_breg8";
2938 return "DW_OP_breg9";
2940 return "DW_OP_breg10";
2942 return "DW_OP_breg11";
2944 return "DW_OP_breg12";
2946 return "DW_OP_breg13";
2948 return "DW_OP_breg14";
2950 return "DW_OP_breg15";
2952 return "DW_OP_breg16";
2954 return "DW_OP_breg17";
2956 return "DW_OP_breg18";
2958 return "DW_OP_breg19";
2960 return "DW_OP_breg20";
2962 return "DW_OP_breg21";
2964 return "DW_OP_breg22";
2966 return "DW_OP_breg23";
2968 return "DW_OP_breg24";
2970 return "DW_OP_breg25";
2972 return "DW_OP_breg26";
2974 return "DW_OP_breg27";
2976 return "DW_OP_breg28";
2978 return "DW_OP_breg29";
2980 return "DW_OP_breg30";
2982 return "DW_OP_breg31";
2984 return "DW_OP_regx";
2986 return "DW_OP_fbreg";
2988 return "DW_OP_bregx";
2990 return "DW_OP_piece";
2991 case DW_OP_deref_size:
2992 return "DW_OP_deref_size";
2993 case DW_OP_xderef_size:
2994 return "DW_OP_xderef_size";
2997 case DW_OP_push_object_address:
2998 return "DW_OP_push_object_address";
3000 return "DW_OP_call2";
3002 return "DW_OP_call4";
3003 case DW_OP_call_ref:
3004 return "DW_OP_call_ref";
3005 case DW_OP_GNU_push_tls_address:
3006 return "DW_OP_GNU_push_tls_address";
3008 return "OP_<unknown>";
3012 /* Return a pointer to a newly allocated location description. Location
3013 descriptions are simple expression terms that can be strung
3014 together to form more complicated location (address) descriptions. */
3016 static inline dw_loc_descr_ref
3017 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3018 unsigned HOST_WIDE_INT oprnd2)
3020 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
3022 descr->dw_loc_opc = op;
3023 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3024 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3025 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3026 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3031 /* Add a location description term to a location description expression. */
3034 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3036 dw_loc_descr_ref *d;
3038 /* Find the end of the chain. */
3039 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3045 /* Return the size of a location descriptor. */
3047 static unsigned long
3048 size_of_loc_descr (dw_loc_descr_ref loc)
3050 unsigned long size = 1;
3052 switch (loc->dw_loc_opc)
3055 case INTERNAL_DW_OP_tls_addr:
3056 size += DWARF2_ADDR_SIZE;
3075 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3078 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3083 case DW_OP_plus_uconst:
3084 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3122 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3125 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3128 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3131 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3132 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3135 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3137 case DW_OP_deref_size:
3138 case DW_OP_xderef_size:
3147 case DW_OP_call_ref:
3148 size += DWARF2_ADDR_SIZE;
3157 /* Return the size of a series of location descriptors. */
3159 static unsigned long
3160 size_of_locs (dw_loc_descr_ref loc)
3164 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
3166 loc->dw_loc_addr = size;
3167 size += size_of_loc_descr (loc);
3173 /* Output location description stack opcode's operands (if any). */
3176 output_loc_operands (dw_loc_descr_ref loc)
3178 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3179 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3181 switch (loc->dw_loc_opc)
3183 #ifdef DWARF2_DEBUGGING_INFO
3185 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3189 dw2_asm_output_data (2, val1->v.val_int, NULL);
3193 dw2_asm_output_data (4, val1->v.val_int, NULL);
3197 gcc_assert (HOST_BITS_PER_LONG >= 64);
3198 dw2_asm_output_data (8, val1->v.val_int, NULL);
3205 gcc_assert (val1->val_class == dw_val_class_loc);
3206 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3208 dw2_asm_output_data (2, offset, NULL);
3221 /* We currently don't make any attempt to make sure these are
3222 aligned properly like we do for the main unwind info, so
3223 don't support emitting things larger than a byte if we're
3224 only doing unwinding. */
3229 dw2_asm_output_data (1, val1->v.val_int, NULL);
3232 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3235 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3238 dw2_asm_output_data (1, val1->v.val_int, NULL);
3240 case DW_OP_plus_uconst:
3241 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3275 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3278 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3281 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3284 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3285 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3288 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3290 case DW_OP_deref_size:
3291 case DW_OP_xderef_size:
3292 dw2_asm_output_data (1, val1->v.val_int, NULL);
3295 case INTERNAL_DW_OP_tls_addr:
3296 if (targetm.asm_out.output_dwarf_dtprel)
3298 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
3301 fputc ('\n', asm_out_file);
3308 /* Other codes have no operands. */
3313 /* Output a sequence of location operations. */
3316 output_loc_sequence (dw_loc_descr_ref loc)
3318 for (; loc != NULL; loc = loc->dw_loc_next)
3320 /* Output the opcode. */
3321 dw2_asm_output_data (1, loc->dw_loc_opc,
3322 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3324 /* Output the operand(s) (if any). */
3325 output_loc_operands (loc);
3329 /* This routine will generate the correct assembly data for a location
3330 description based on a cfi entry with a complex address. */
3333 output_cfa_loc (dw_cfi_ref cfi)
3335 dw_loc_descr_ref loc;
3338 /* Output the size of the block. */
3339 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3340 size = size_of_locs (loc);
3341 dw2_asm_output_data_uleb128 (size, NULL);
3343 /* Now output the operations themselves. */
3344 output_loc_sequence (loc);
3347 /* This function builds a dwarf location descriptor sequence from
3348 a dw_cfa_location. */
3350 static struct dw_loc_descr_struct *
3351 build_cfa_loc (dw_cfa_location *cfa)
3353 struct dw_loc_descr_struct *head, *tmp;
3357 if (cfa->base_offset)
3360 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3362 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3364 else if (cfa->reg <= 31)
3365 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3367 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3369 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3370 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3371 add_loc_descr (&head, tmp);
3372 if (cfa->offset != 0)
3374 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3375 add_loc_descr (&head, tmp);
3380 if (cfa->offset == 0)
3382 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3384 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3385 else if (cfa->reg <= 31)
3386 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->offset, 0);
3388 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->offset);
3394 /* This function fills in aa dw_cfa_location structure from a dwarf location
3395 descriptor sequence. */
3398 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3400 struct dw_loc_descr_struct *ptr;
3402 cfa->base_offset = 0;
3406 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3408 enum dwarf_location_atom op = ptr->dw_loc_opc;
3444 cfa->reg = op - DW_OP_reg0;
3447 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3481 cfa->reg = op - DW_OP_breg0;
3482 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3485 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3486 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3491 case DW_OP_plus_uconst:
3492 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3495 internal_error ("DW_LOC_OP %s not implemented",
3496 dwarf_stack_op_name (ptr->dw_loc_opc));
3500 #endif /* .debug_frame support */
3502 /* And now, the support for symbolic debugging information. */
3503 #ifdef DWARF2_DEBUGGING_INFO
3505 /* .debug_str support. */
3506 static int output_indirect_string (void **, void *);
3508 static void dwarf2out_init (const char *);
3509 static void dwarf2out_finish (const char *);
3510 static void dwarf2out_define (unsigned int, const char *);
3511 static void dwarf2out_undef (unsigned int, const char *);
3512 static void dwarf2out_start_source_file (unsigned, const char *);
3513 static void dwarf2out_end_source_file (unsigned);
3514 static void dwarf2out_begin_block (unsigned, unsigned);
3515 static void dwarf2out_end_block (unsigned, unsigned);
3516 static bool dwarf2out_ignore_block (tree);
3517 static void dwarf2out_global_decl (tree);
3518 static void dwarf2out_type_decl (tree, int);
3519 static void dwarf2out_imported_module_or_decl (tree, tree);
3520 static void dwarf2out_abstract_function (tree);
3521 static void dwarf2out_var_location (rtx);
3522 static void dwarf2out_begin_function (tree);
3523 static void dwarf2out_switch_text_section (void);
3525 /* The debug hooks structure. */
3527 const struct gcc_debug_hooks dwarf2_debug_hooks =
3533 dwarf2out_start_source_file,
3534 dwarf2out_end_source_file,
3535 dwarf2out_begin_block,
3536 dwarf2out_end_block,
3537 dwarf2out_ignore_block,
3538 dwarf2out_source_line,
3539 dwarf2out_begin_prologue,
3540 debug_nothing_int_charstar, /* end_prologue */
3541 dwarf2out_end_epilogue,
3542 dwarf2out_begin_function,
3543 debug_nothing_int, /* end_function */
3544 dwarf2out_decl, /* function_decl */
3545 dwarf2out_global_decl,
3546 dwarf2out_type_decl, /* type_decl */
3547 dwarf2out_imported_module_or_decl,
3548 debug_nothing_tree, /* deferred_inline_function */
3549 /* The DWARF 2 backend tries to reduce debugging bloat by not
3550 emitting the abstract description of inline functions until
3551 something tries to reference them. */
3552 dwarf2out_abstract_function, /* outlining_inline_function */
3553 debug_nothing_rtx, /* label */
3554 debug_nothing_int, /* handle_pch */
3555 dwarf2out_var_location,
3556 dwarf2out_switch_text_section,
3557 1 /* start_end_main_source_file */
3561 /* NOTE: In the comments in this file, many references are made to
3562 "Debugging Information Entries". This term is abbreviated as `DIE'
3563 throughout the remainder of this file. */
3565 /* An internal representation of the DWARF output is built, and then
3566 walked to generate the DWARF debugging info. The walk of the internal
3567 representation is done after the entire program has been compiled.
3568 The types below are used to describe the internal representation. */
3570 /* Various DIE's use offsets relative to the beginning of the
3571 .debug_info section to refer to each other. */
3573 typedef long int dw_offset;
3575 /* Define typedefs here to avoid circular dependencies. */
3577 typedef struct dw_attr_struct *dw_attr_ref;
3578 typedef struct dw_line_info_struct *dw_line_info_ref;
3579 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3580 typedef struct pubname_struct *pubname_ref;
3581 typedef struct dw_ranges_struct *dw_ranges_ref;
3583 /* Each entry in the line_info_table maintains the file and
3584 line number associated with the label generated for that
3585 entry. The label gives the PC value associated with
3586 the line number entry. */
3588 typedef struct dw_line_info_struct GTY(())
3590 unsigned long dw_file_num;
3591 unsigned long dw_line_num;
3595 /* Line information for functions in separate sections; each one gets its
3597 typedef struct dw_separate_line_info_struct GTY(())
3599 unsigned long dw_file_num;
3600 unsigned long dw_line_num;
3601 unsigned long function;
3603 dw_separate_line_info_entry;
3605 /* Each DIE attribute has a field specifying the attribute kind,
3606 a link to the next attribute in the chain, and an attribute value.
3607 Attributes are typically linked below the DIE they modify. */
3609 typedef struct dw_attr_struct GTY(())