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 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, 59 Temple Place - Suite 330, 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"
45 #include "hard-reg-set.h"
47 #include "insn-config.h"
55 #include "dwarf2out.h"
56 #include "dwarf2asm.h"
62 #include "diagnostic.h"
65 #include "langhooks.h"
70 #ifdef DWARF2_DEBUGGING_INFO
71 static void dwarf2out_source_line (unsigned int, const char *);
74 /* DWARF2 Abbreviation Glossary:
75 CFA = Canonical Frame Address
76 a fixed address on the stack which identifies a call frame.
77 We define it to be the value of SP just before the call insn.
78 The CFA register and offset, which may change during the course
79 of the function, are used to calculate its value at runtime.
80 CFI = Call Frame Instruction
81 an instruction for the DWARF2 abstract machine
82 CIE = Common Information Entry
83 information describing information common to one or more FDEs
84 DIE = Debugging Information Entry
85 FDE = Frame Description Entry
86 information describing the stack call frame, in particular,
87 how to restore registers
89 DW_CFA_... = DWARF2 CFA call frame instruction
90 DW_TAG_... = DWARF2 DIE tag */
92 /* Decide whether we want to emit frame unwind information for the current
96 dwarf2out_do_frame (void)
98 return (write_symbols == DWARF2_DEBUG
99 || write_symbols == VMS_AND_DWARF2_DEBUG
100 #ifdef DWARF2_FRAME_INFO
103 #ifdef DWARF2_UNWIND_INFO
104 || flag_unwind_tables
105 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
110 /* The size of the target's pointer type. */
112 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
115 /* Various versions of targetm.eh_frame_section. Note these must appear
116 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro guards. */
118 /* Version of targetm.eh_frame_section for systems with named sections. */
120 named_section_eh_frame_section (void)
122 #ifdef EH_FRAME_SECTION_NAME
123 #ifdef HAVE_LD_RO_RW_SECTION_MIXING
124 int fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
125 int per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
126 int lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
130 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
131 && (fde_encoding & 0x70) != DW_EH_PE_aligned
132 && (per_encoding & 0x70) != DW_EH_PE_absptr
133 && (per_encoding & 0x70) != DW_EH_PE_aligned
134 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
135 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
137 named_section_flags (EH_FRAME_SECTION_NAME, flags);
139 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
144 /* Version of targetm.eh_frame_section for systems using collect2. */
146 collect2_eh_frame_section (void)
148 tree label = get_file_function_name ('F');
151 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
152 targetm.asm_out.globalize_label (asm_out_file, IDENTIFIER_POINTER (label));
153 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
156 /* Default version of targetm.eh_frame_section. */
158 default_eh_frame_section (void)
160 #ifdef EH_FRAME_SECTION_NAME
161 named_section_eh_frame_section ();
163 collect2_eh_frame_section ();
167 /* Array of RTXes referenced by the debugging information, which therefore
168 must be kept around forever. */
169 static GTY(()) varray_type used_rtx_varray;
171 /* A pointer to the base of a list of incomplete types which might be
172 completed at some later time. incomplete_types_list needs to be a VARRAY
173 because we want to tell the garbage collector about it. */
174 static GTY(()) varray_type incomplete_types;
176 /* A pointer to the base of a table of references to declaration
177 scopes. This table is a display which tracks the nesting
178 of declaration scopes at the current scope and containing
179 scopes. This table is used to find the proper place to
180 define type declaration DIE's. */
181 static GTY(()) varray_type decl_scope_table;
183 /* How to start an assembler comment. */
184 #ifndef ASM_COMMENT_START
185 #define ASM_COMMENT_START ";#"
188 typedef struct dw_cfi_struct *dw_cfi_ref;
189 typedef struct dw_fde_struct *dw_fde_ref;
190 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
192 /* Call frames are described using a sequence of Call Frame
193 Information instructions. The register number, offset
194 and address fields are provided as possible operands;
195 their use is selected by the opcode field. */
197 enum dw_cfi_oprnd_type {
199 dw_cfi_oprnd_reg_num,
205 typedef union dw_cfi_oprnd_struct GTY(())
207 unsigned long GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
208 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
209 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
210 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
214 typedef struct dw_cfi_struct GTY(())
216 dw_cfi_ref dw_cfi_next;
217 enum dwarf_call_frame_info dw_cfi_opc;
218 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
220 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
225 /* This is how we define the location of the CFA. We use to handle it
226 as REG + OFFSET all the time, but now it can be more complex.
227 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
228 Instead of passing around REG and OFFSET, we pass a copy
229 of this structure. */
230 typedef struct cfa_loc GTY(())
233 HOST_WIDE_INT offset;
234 HOST_WIDE_INT base_offset;
235 int indirect; /* 1 if CFA is accessed via a dereference. */
238 /* All call frame descriptions (FDE's) in the GCC generated DWARF
239 refer to a single Common Information Entry (CIE), defined at
240 the beginning of the .debug_frame section. This use of a single
241 CIE obviates the need to keep track of multiple CIE's
242 in the DWARF generation routines below. */
244 typedef struct dw_fde_struct GTY(())
247 const char *dw_fde_begin;
248 const char *dw_fde_current_label;
249 const char *dw_fde_end;
250 dw_cfi_ref dw_fde_cfi;
251 unsigned funcdef_number;
252 unsigned all_throwers_are_sibcalls : 1;
253 unsigned nothrow : 1;
254 unsigned uses_eh_lsda : 1;
258 /* Maximum size (in bytes) of an artificially generated label. */
259 #define MAX_ARTIFICIAL_LABEL_BYTES 30
261 /* The size of addresses as they appear in the Dwarf 2 data.
262 Some architectures use word addresses to refer to code locations,
263 but Dwarf 2 info always uses byte addresses. On such machines,
264 Dwarf 2 addresses need to be larger than the architecture's
266 #ifndef DWARF2_ADDR_SIZE
267 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
270 /* The size in bytes of a DWARF field indicating an offset or length
271 relative to a debug info section, specified to be 4 bytes in the
272 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
275 #ifndef DWARF_OFFSET_SIZE
276 #define DWARF_OFFSET_SIZE 4
279 /* According to the (draft) DWARF 3 specification, the initial length
280 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
281 bytes are 0xffffffff, followed by the length stored in the next 8
284 However, the SGI/MIPS ABI uses an initial length which is equal to
285 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
287 #ifndef DWARF_INITIAL_LENGTH_SIZE
288 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
291 #define DWARF_VERSION 2
293 /* Round SIZE up to the nearest BOUNDARY. */
294 #define DWARF_ROUND(SIZE,BOUNDARY) \
295 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
297 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
298 #ifndef DWARF_CIE_DATA_ALIGNMENT
299 #ifdef STACK_GROWS_DOWNWARD
300 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
302 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
306 /* A pointer to the base of a table that contains frame description
307 information for each routine. */
308 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
310 /* Number of elements currently allocated for fde_table. */
311 static GTY(()) unsigned fde_table_allocated;
313 /* Number of elements in fde_table currently in use. */
314 static GTY(()) unsigned fde_table_in_use;
316 /* Size (in elements) of increments by which we may expand the
318 #define FDE_TABLE_INCREMENT 256
320 /* A list of call frame insns for the CIE. */
321 static GTY(()) dw_cfi_ref cie_cfi_head;
323 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
324 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
325 attribute that accelerates the lookup of the FDE associated
326 with the subprogram. This variable holds the table index of the FDE
327 associated with the current function (body) definition. */
328 static unsigned current_funcdef_fde;
331 struct indirect_string_node GTY(())
334 unsigned int refcount;
339 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
341 static GTY(()) int dw2_string_counter;
342 static GTY(()) unsigned long dwarf2out_cfi_label_num;
344 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
346 /* Forward declarations for functions defined in this file. */
348 static char *stripattributes (const char *);
349 static const char *dwarf_cfi_name (unsigned);
350 static dw_cfi_ref new_cfi (void);
351 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
352 static void add_fde_cfi (const char *, dw_cfi_ref);
353 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
354 static void lookup_cfa (dw_cfa_location *);
355 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
356 static void initial_return_save (rtx);
357 static HOST_WIDE_INT stack_adjust_offset (rtx);
358 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
359 static void output_call_frame_info (int);
360 static void dwarf2out_stack_adjust (rtx);
361 static void queue_reg_save (const char *, rtx, HOST_WIDE_INT);
362 static void flush_queued_reg_saves (void);
363 static bool clobbers_queued_reg_save (rtx);
364 static void dwarf2out_frame_debug_expr (rtx, const char *);
366 /* Support for complex CFA locations. */
367 static void output_cfa_loc (dw_cfi_ref);
368 static void get_cfa_from_loc_descr (dw_cfa_location *,
369 struct dw_loc_descr_struct *);
370 static struct dw_loc_descr_struct *build_cfa_loc
372 static void def_cfa_1 (const char *, dw_cfa_location *);
374 /* How to start an assembler comment. */
375 #ifndef ASM_COMMENT_START
376 #define ASM_COMMENT_START ";#"
379 /* Data and reference forms for relocatable data. */
380 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
381 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
383 #ifndef DEBUG_FRAME_SECTION
384 #define DEBUG_FRAME_SECTION ".debug_frame"
387 #ifndef FUNC_BEGIN_LABEL
388 #define FUNC_BEGIN_LABEL "LFB"
391 #ifndef FUNC_END_LABEL
392 #define FUNC_END_LABEL "LFE"
395 #ifndef FRAME_BEGIN_LABEL
396 #define FRAME_BEGIN_LABEL "Lframe"
398 #define CIE_AFTER_SIZE_LABEL "LSCIE"
399 #define CIE_END_LABEL "LECIE"
400 #define FDE_LABEL "LSFDE"
401 #define FDE_AFTER_SIZE_LABEL "LASFDE"
402 #define FDE_END_LABEL "LEFDE"
403 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
404 #define LINE_NUMBER_END_LABEL "LELT"
405 #define LN_PROLOG_AS_LABEL "LASLTP"
406 #define LN_PROLOG_END_LABEL "LELTP"
407 #define DIE_LABEL_PREFIX "DW"
409 /* The DWARF 2 CFA column which tracks the return address. Normally this
410 is the column for PC, or the first column after all of the hard
412 #ifndef DWARF_FRAME_RETURN_COLUMN
414 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
416 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
420 /* The mapping from gcc register number to DWARF 2 CFA column number. By
421 default, we just provide columns for all registers. */
422 #ifndef DWARF_FRAME_REGNUM
423 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
426 /* The offset from the incoming value of %sp to the top of the stack frame
427 for the current function. */
428 #ifndef INCOMING_FRAME_SP_OFFSET
429 #define INCOMING_FRAME_SP_OFFSET 0
432 /* Hook used by __throw. */
435 expand_builtin_dwarf_sp_column (void)
437 return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
440 /* Return a pointer to a copy of the section string name S with all
441 attributes stripped off, and an asterisk prepended (for assemble_name). */
444 stripattributes (const char *s)
446 char *stripped = xmalloc (strlen (s) + 2);
451 while (*s && *s != ',')
458 /* Generate code to initialize the register size table. */
461 expand_builtin_init_dwarf_reg_sizes (tree address)
464 enum machine_mode mode = TYPE_MODE (char_type_node);
465 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
466 rtx mem = gen_rtx_MEM (BLKmode, addr);
467 bool wrote_return_column = false;
469 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
470 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
472 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
473 enum machine_mode save_mode = reg_raw_mode[i];
476 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
477 save_mode = choose_hard_reg_mode (i, 1, true);
478 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
480 if (save_mode == VOIDmode)
482 wrote_return_column = true;
484 size = GET_MODE_SIZE (save_mode);
488 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
491 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
492 if (! wrote_return_column)
494 i = DWARF_ALT_FRAME_RETURN_COLUMN;
495 wrote_return_column = false;
497 i = DWARF_FRAME_RETURN_COLUMN;
500 if (! wrote_return_column)
502 enum machine_mode save_mode = Pmode;
503 HOST_WIDE_INT offset = i * GET_MODE_SIZE (mode);
504 HOST_WIDE_INT size = GET_MODE_SIZE (save_mode);
505 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
509 /* Convert a DWARF call frame info. operation to its string name */
512 dwarf_cfi_name (unsigned int cfi_opc)
516 case DW_CFA_advance_loc:
517 return "DW_CFA_advance_loc";
519 return "DW_CFA_offset";
521 return "DW_CFA_restore";
525 return "DW_CFA_set_loc";
526 case DW_CFA_advance_loc1:
527 return "DW_CFA_advance_loc1";
528 case DW_CFA_advance_loc2:
529 return "DW_CFA_advance_loc2";
530 case DW_CFA_advance_loc4:
531 return "DW_CFA_advance_loc4";
532 case DW_CFA_offset_extended:
533 return "DW_CFA_offset_extended";
534 case DW_CFA_restore_extended:
535 return "DW_CFA_restore_extended";
536 case DW_CFA_undefined:
537 return "DW_CFA_undefined";
538 case DW_CFA_same_value:
539 return "DW_CFA_same_value";
540 case DW_CFA_register:
541 return "DW_CFA_register";
542 case DW_CFA_remember_state:
543 return "DW_CFA_remember_state";
544 case DW_CFA_restore_state:
545 return "DW_CFA_restore_state";
547 return "DW_CFA_def_cfa";
548 case DW_CFA_def_cfa_register:
549 return "DW_CFA_def_cfa_register";
550 case DW_CFA_def_cfa_offset:
551 return "DW_CFA_def_cfa_offset";
554 case DW_CFA_def_cfa_expression:
555 return "DW_CFA_def_cfa_expression";
556 case DW_CFA_expression:
557 return "DW_CFA_expression";
558 case DW_CFA_offset_extended_sf:
559 return "DW_CFA_offset_extended_sf";
560 case DW_CFA_def_cfa_sf:
561 return "DW_CFA_def_cfa_sf";
562 case DW_CFA_def_cfa_offset_sf:
563 return "DW_CFA_def_cfa_offset_sf";
565 /* SGI/MIPS specific */
566 case DW_CFA_MIPS_advance_loc8:
567 return "DW_CFA_MIPS_advance_loc8";
570 case DW_CFA_GNU_window_save:
571 return "DW_CFA_GNU_window_save";
572 case DW_CFA_GNU_args_size:
573 return "DW_CFA_GNU_args_size";
574 case DW_CFA_GNU_negative_offset_extended:
575 return "DW_CFA_GNU_negative_offset_extended";
578 return "DW_CFA_<unknown>";
582 /* Return a pointer to a newly allocated Call Frame Instruction. */
584 static inline dw_cfi_ref
587 dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node));
589 cfi->dw_cfi_next = NULL;
590 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
591 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
596 /* Add a Call Frame Instruction to list of instructions. */
599 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
603 /* Find the end of the chain. */
604 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
610 /* Generate a new label for the CFI info to refer to. */
613 dwarf2out_cfi_label (void)
615 static char label[20];
617 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
618 ASM_OUTPUT_LABEL (asm_out_file, label);
622 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
623 or to the CIE if LABEL is NULL. */
626 add_fde_cfi (const char *label, dw_cfi_ref cfi)
630 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
633 label = dwarf2out_cfi_label ();
635 if (fde->dw_fde_current_label == NULL
636 || strcmp (label, fde->dw_fde_current_label) != 0)
640 fde->dw_fde_current_label = label = xstrdup (label);
642 /* Set the location counter to the new label. */
644 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
645 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
646 add_cfi (&fde->dw_fde_cfi, xcfi);
649 add_cfi (&fde->dw_fde_cfi, cfi);
653 add_cfi (&cie_cfi_head, cfi);
656 /* Subroutine of lookup_cfa. */
659 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
661 switch (cfi->dw_cfi_opc)
663 case DW_CFA_def_cfa_offset:
664 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
666 case DW_CFA_def_cfa_register:
667 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
670 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
671 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
673 case DW_CFA_def_cfa_expression:
674 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
681 /* Find the previous value for the CFA. */
684 lookup_cfa (dw_cfa_location *loc)
688 loc->reg = (unsigned long) -1;
691 loc->base_offset = 0;
693 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
694 lookup_cfa_1 (cfi, loc);
696 if (fde_table_in_use)
698 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
699 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
700 lookup_cfa_1 (cfi, loc);
704 /* The current rule for calculating the DWARF2 canonical frame address. */
705 static dw_cfa_location cfa;
707 /* The register used for saving registers to the stack, and its offset
709 static dw_cfa_location cfa_store;
711 /* The running total of the size of arguments pushed onto the stack. */
712 static HOST_WIDE_INT args_size;
714 /* The last args_size we actually output. */
715 static HOST_WIDE_INT old_args_size;
717 /* Entry point to update the canonical frame address (CFA).
718 LABEL is passed to add_fde_cfi. The value of CFA is now to be
719 calculated from REG+OFFSET. */
722 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
729 def_cfa_1 (label, &loc);
732 /* This routine does the actual work. The CFA is now calculated from
733 the dw_cfa_location structure. */
736 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
739 dw_cfa_location old_cfa, loc;
744 if (cfa_store.reg == loc.reg && loc.indirect == 0)
745 cfa_store.offset = loc.offset;
747 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
748 lookup_cfa (&old_cfa);
750 /* If nothing changed, no need to issue any call frame instructions. */
751 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
752 && loc.indirect == old_cfa.indirect
753 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
758 if (loc.reg == old_cfa.reg && !loc.indirect)
760 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
761 indicating the CFA register did not change but the offset
763 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
764 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
767 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
768 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
771 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
772 indicating the CFA register has changed to <register> but the
773 offset has not changed. */
774 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
775 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
779 else if (loc.indirect == 0)
781 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
782 indicating the CFA register has changed to <register> with
783 the specified offset. */
784 cfi->dw_cfi_opc = DW_CFA_def_cfa;
785 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
786 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
790 /* Construct a DW_CFA_def_cfa_expression instruction to
791 calculate the CFA using a full location expression since no
792 register-offset pair is available. */
793 struct dw_loc_descr_struct *loc_list;
795 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
796 loc_list = build_cfa_loc (&loc);
797 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
800 add_fde_cfi (label, cfi);
803 /* Add the CFI for saving a register. REG is the CFA column number.
804 LABEL is passed to add_fde_cfi.
805 If SREG is -1, the register is saved at OFFSET from the CFA;
806 otherwise it is saved in SREG. */
809 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
811 dw_cfi_ref cfi = new_cfi ();
813 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
815 /* The following comparison is correct. -1 is used to indicate that
816 the value isn't a register number. */
817 if (sreg == (unsigned int) -1)
820 /* The register number won't fit in 6 bits, so we have to use
822 cfi->dw_cfi_opc = DW_CFA_offset_extended;
824 cfi->dw_cfi_opc = DW_CFA_offset;
826 #ifdef ENABLE_CHECKING
828 /* If we get an offset that is not a multiple of
829 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
830 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
832 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
834 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
838 offset /= DWARF_CIE_DATA_ALIGNMENT;
840 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
842 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
844 else if (sreg == reg)
845 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
849 cfi->dw_cfi_opc = DW_CFA_register;
850 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
853 add_fde_cfi (label, cfi);
856 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
857 This CFI tells the unwinder that it needs to restore the window registers
858 from the previous frame's window save area.
860 ??? Perhaps we should note in the CIE where windows are saved (instead of
861 assuming 0(cfa)) and what registers are in the window. */
864 dwarf2out_window_save (const char *label)
866 dw_cfi_ref cfi = new_cfi ();
868 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
869 add_fde_cfi (label, cfi);
872 /* Add a CFI to update the running total of the size of arguments
873 pushed onto the stack. */
876 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
880 if (size == old_args_size)
883 old_args_size = size;
886 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
887 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
888 add_fde_cfi (label, cfi);
891 /* Entry point for saving a register to the stack. REG is the GCC register
892 number. LABEL and OFFSET are passed to reg_save. */
895 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
897 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
900 /* Entry point for saving the return address in the stack.
901 LABEL and OFFSET are passed to reg_save. */
904 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
906 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
909 /* Entry point for saving the return address in a register.
910 LABEL and SREG are passed to reg_save. */
913 dwarf2out_return_reg (const char *label, unsigned int sreg)
915 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
918 /* Record the initial position of the return address. RTL is
919 INCOMING_RETURN_ADDR_RTX. */
922 initial_return_save (rtx rtl)
924 unsigned int reg = (unsigned int) -1;
925 HOST_WIDE_INT offset = 0;
927 switch (GET_CODE (rtl))
930 /* RA is in a register. */
931 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
935 /* RA is on the stack. */
937 switch (GET_CODE (rtl))
940 if (REGNO (rtl) != STACK_POINTER_REGNUM)
946 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
948 offset = INTVAL (XEXP (rtl, 1));
952 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
954 offset = -INTVAL (XEXP (rtl, 1));
964 /* The return address is at some offset from any value we can
965 actually load. For instance, on the SPARC it is in %i7+8. Just
966 ignore the offset for now; it doesn't matter for unwinding frames. */
967 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
969 initial_return_save (XEXP (rtl, 0));
976 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
979 /* Given a SET, calculate the amount of stack adjustment it
983 stack_adjust_offset (rtx pattern)
985 rtx src = SET_SRC (pattern);
986 rtx dest = SET_DEST (pattern);
987 HOST_WIDE_INT offset = 0;
990 if (dest == stack_pointer_rtx)
992 /* (set (reg sp) (plus (reg sp) (const_int))) */
993 code = GET_CODE (src);
994 if (! (code == PLUS || code == MINUS)
995 || XEXP (src, 0) != stack_pointer_rtx
996 || GET_CODE (XEXP (src, 1)) != CONST_INT)
999 offset = INTVAL (XEXP (src, 1));
1003 else if (GET_CODE (dest) == MEM)
1005 /* (set (mem (pre_dec (reg sp))) (foo)) */
1006 src = XEXP (dest, 0);
1007 code = GET_CODE (src);
1013 if (XEXP (src, 0) == stack_pointer_rtx)
1015 rtx val = XEXP (XEXP (src, 1), 1);
1016 /* We handle only adjustments by constant amount. */
1017 if (GET_CODE (XEXP (src, 1)) != PLUS ||
1018 GET_CODE (val) != CONST_INT)
1020 offset = -INTVAL (val);
1027 if (XEXP (src, 0) == stack_pointer_rtx)
1029 offset = GET_MODE_SIZE (GET_MODE (dest));
1036 if (XEXP (src, 0) == stack_pointer_rtx)
1038 offset = -GET_MODE_SIZE (GET_MODE (dest));
1053 /* Check INSN to see if it looks like a push or a stack adjustment, and
1054 make a note of it if it does. EH uses this information to find out how
1055 much extra space it needs to pop off the stack. */
1058 dwarf2out_stack_adjust (rtx insn)
1060 HOST_WIDE_INT offset;
1064 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1065 with this function. Proper support would require all frame-related
1066 insns to be marked, and to be able to handle saving state around
1067 epilogues textually in the middle of the function. */
1068 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1071 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
1073 /* Extract the size of the args from the CALL rtx itself. */
1074 insn = PATTERN (insn);
1075 if (GET_CODE (insn) == PARALLEL)
1076 insn = XVECEXP (insn, 0, 0);
1077 if (GET_CODE (insn) == SET)
1078 insn = SET_SRC (insn);
1079 if (GET_CODE (insn) != CALL)
1082 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1086 /* If only calls can throw, and we have a frame pointer,
1087 save up adjustments until we see the CALL_INSN. */
1088 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1091 if (GET_CODE (insn) == BARRIER)
1093 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1094 the compiler will have already emitted a stack adjustment, but
1095 doesn't bother for calls to noreturn functions. */
1096 #ifdef STACK_GROWS_DOWNWARD
1097 offset = -args_size;
1102 else if (GET_CODE (PATTERN (insn)) == SET)
1103 offset = stack_adjust_offset (PATTERN (insn));
1104 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1105 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1107 /* There may be stack adjustments inside compound insns. Search
1109 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1110 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1111 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1119 if (cfa.reg == STACK_POINTER_REGNUM)
1120 cfa.offset += offset;
1122 #ifndef STACK_GROWS_DOWNWARD
1126 args_size += offset;
1130 label = dwarf2out_cfi_label ();
1131 def_cfa_1 (label, &cfa);
1132 dwarf2out_args_size (label, args_size);
1137 /* We delay emitting a register save until either (a) we reach the end
1138 of the prologue or (b) the register is clobbered. This clusters
1139 register saves so that there are fewer pc advances. */
1141 struct queued_reg_save GTY(())
1143 struct queued_reg_save *next;
1145 HOST_WIDE_INT cfa_offset;
1148 static GTY(()) struct queued_reg_save *queued_reg_saves;
1150 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1151 static const char *last_reg_save_label;
1154 queue_reg_save (const char *label, rtx reg, HOST_WIDE_INT offset)
1156 struct queued_reg_save *q = ggc_alloc (sizeof (*q));
1158 q->next = queued_reg_saves;
1160 q->cfa_offset = offset;
1161 queued_reg_saves = q;
1163 last_reg_save_label = label;
1167 flush_queued_reg_saves (void)
1169 struct queued_reg_save *q, *next;
1171 for (q = queued_reg_saves; q; q = next)
1173 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1177 queued_reg_saves = NULL;
1178 last_reg_save_label = NULL;
1182 clobbers_queued_reg_save (rtx insn)
1184 struct queued_reg_save *q;
1186 for (q = queued_reg_saves; q; q = q->next)
1187 if (modified_in_p (q->reg, insn))
1194 /* A temporary register holding an integral value used in adjusting SP
1195 or setting up the store_reg. The "offset" field holds the integer
1196 value, not an offset. */
1197 static dw_cfa_location cfa_temp;
1199 /* Record call frame debugging information for an expression EXPR,
1200 which either sets SP or FP (adjusting how we calculate the frame
1201 address) or saves a register to the stack. LABEL indicates the
1204 This function encodes a state machine mapping rtxes to actions on
1205 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1206 users need not read the source code.
1208 The High-Level Picture
1210 Changes in the register we use to calculate the CFA: Currently we
1211 assume that if you copy the CFA register into another register, we
1212 should take the other one as the new CFA register; this seems to
1213 work pretty well. If it's wrong for some target, it's simple
1214 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1216 Changes in the register we use for saving registers to the stack:
1217 This is usually SP, but not always. Again, we deduce that if you
1218 copy SP into another register (and SP is not the CFA register),
1219 then the new register is the one we will be using for register
1220 saves. This also seems to work.
1222 Register saves: There's not much guesswork about this one; if
1223 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1224 register save, and the register used to calculate the destination
1225 had better be the one we think we're using for this purpose.
1227 Except: If the register being saved is the CFA register, and the
1228 offset is nonzero, we are saving the CFA, so we assume we have to
1229 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1230 the intent is to save the value of SP from the previous frame.
1232 Invariants / Summaries of Rules
1234 cfa current rule for calculating the CFA. It usually
1235 consists of a register and an offset.
1236 cfa_store register used by prologue code to save things to the stack
1237 cfa_store.offset is the offset from the value of
1238 cfa_store.reg to the actual CFA
1239 cfa_temp register holding an integral value. cfa_temp.offset
1240 stores the value, which will be used to adjust the
1241 stack pointer. cfa_temp is also used like cfa_store,
1242 to track stores to the stack via fp or a temp reg.
1244 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1245 with cfa.reg as the first operand changes the cfa.reg and its
1246 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1249 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1250 expression yielding a constant. This sets cfa_temp.reg
1251 and cfa_temp.offset.
1253 Rule 5: Create a new register cfa_store used to save items to the
1256 Rules 10-14: Save a register to the stack. Define offset as the
1257 difference of the original location and cfa_store's
1258 location (or cfa_temp's location if cfa_temp is used).
1262 "{a,b}" indicates a choice of a xor b.
1263 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1266 (set <reg1> <reg2>:cfa.reg)
1267 effects: cfa.reg = <reg1>
1268 cfa.offset unchanged
1269 cfa_temp.reg = <reg1>
1270 cfa_temp.offset = cfa.offset
1273 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1274 {<const_int>,<reg>:cfa_temp.reg}))
1275 effects: cfa.reg = sp if fp used
1276 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1277 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1278 if cfa_store.reg==sp
1281 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1282 effects: cfa.reg = fp
1283 cfa_offset += +/- <const_int>
1286 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1287 constraints: <reg1> != fp
1289 effects: cfa.reg = <reg1>
1290 cfa_temp.reg = <reg1>
1291 cfa_temp.offset = cfa.offset
1294 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1295 constraints: <reg1> != fp
1297 effects: cfa_store.reg = <reg1>
1298 cfa_store.offset = cfa.offset - cfa_temp.offset
1301 (set <reg> <const_int>)
1302 effects: cfa_temp.reg = <reg>
1303 cfa_temp.offset = <const_int>
1306 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1307 effects: cfa_temp.reg = <reg1>
1308 cfa_temp.offset |= <const_int>
1311 (set <reg> (high <exp>))
1315 (set <reg> (lo_sum <exp> <const_int>))
1316 effects: cfa_temp.reg = <reg>
1317 cfa_temp.offset = <const_int>
1320 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1321 effects: cfa_store.offset -= <const_int>
1322 cfa.offset = cfa_store.offset if cfa.reg == sp
1324 cfa.base_offset = -cfa_store.offset
1327 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1328 effects: cfa_store.offset += -/+ mode_size(mem)
1329 cfa.offset = cfa_store.offset if cfa.reg == sp
1331 cfa.base_offset = -cfa_store.offset
1334 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1337 effects: cfa.reg = <reg1>
1338 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1341 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1342 effects: cfa.reg = <reg1>
1343 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1346 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1347 effects: cfa.reg = <reg1>
1348 cfa.base_offset = -cfa_temp.offset
1349 cfa_temp.offset -= mode_size(mem) */
1352 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1355 HOST_WIDE_INT offset;
1357 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1358 the PARALLEL independently. The first element is always processed if
1359 it is a SET. This is for backward compatibility. Other elements
1360 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1361 flag is set in them. */
1362 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1365 int limit = XVECLEN (expr, 0);
1367 for (par_index = 0; par_index < limit; par_index++)
1368 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1369 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1371 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1376 if (GET_CODE (expr) != SET)
1379 src = SET_SRC (expr);
1380 dest = SET_DEST (expr);
1382 switch (GET_CODE (dest))
1386 /* Update the CFA rule wrt SP or FP. Make sure src is
1387 relative to the current CFA register. */
1388 switch (GET_CODE (src))
1390 /* Setting FP from SP. */
1392 if (cfa.reg == (unsigned) REGNO (src))
1398 /* We used to require that dest be either SP or FP, but the
1399 ARM copies SP to a temporary register, and from there to
1400 FP. So we just rely on the backends to only set
1401 RTX_FRAME_RELATED_P on appropriate insns. */
1402 cfa.reg = REGNO (dest);
1403 cfa_temp.reg = cfa.reg;
1404 cfa_temp.offset = cfa.offset;
1410 if (dest == stack_pointer_rtx)
1414 switch (GET_CODE (XEXP (src, 1)))
1417 offset = INTVAL (XEXP (src, 1));
1420 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1422 offset = cfa_temp.offset;
1428 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1430 /* Restoring SP from FP in the epilogue. */
1431 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1433 cfa.reg = STACK_POINTER_REGNUM;
1435 else if (GET_CODE (src) == LO_SUM)
1436 /* Assume we've set the source reg of the LO_SUM from sp. */
1438 else if (XEXP (src, 0) != stack_pointer_rtx)
1441 if (GET_CODE (src) != MINUS)
1443 if (cfa.reg == STACK_POINTER_REGNUM)
1444 cfa.offset += offset;
1445 if (cfa_store.reg == STACK_POINTER_REGNUM)
1446 cfa_store.offset += offset;
1448 else if (dest == hard_frame_pointer_rtx)
1451 /* Either setting the FP from an offset of the SP,
1452 or adjusting the FP */
1453 if (! frame_pointer_needed)
1456 if (GET_CODE (XEXP (src, 0)) == REG
1457 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1458 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1460 offset = INTVAL (XEXP (src, 1));
1461 if (GET_CODE (src) != MINUS)
1463 cfa.offset += offset;
1464 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1471 if (GET_CODE (src) == MINUS)
1475 if (GET_CODE (XEXP (src, 0)) == REG
1476 && REGNO (XEXP (src, 0)) == cfa.reg
1477 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1479 /* Setting a temporary CFA register that will be copied
1480 into the FP later on. */
1481 offset = - INTVAL (XEXP (src, 1));
1482 cfa.offset += offset;
1483 cfa.reg = REGNO (dest);
1484 /* Or used to save regs to the stack. */
1485 cfa_temp.reg = cfa.reg;
1486 cfa_temp.offset = cfa.offset;
1490 else if (GET_CODE (XEXP (src, 0)) == REG
1491 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1492 && XEXP (src, 1) == stack_pointer_rtx)
1494 /* Setting a scratch register that we will use instead
1495 of SP for saving registers to the stack. */
1496 if (cfa.reg != STACK_POINTER_REGNUM)
1498 cfa_store.reg = REGNO (dest);
1499 cfa_store.offset = cfa.offset - cfa_temp.offset;
1503 else if (GET_CODE (src) == LO_SUM
1504 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1506 cfa_temp.reg = REGNO (dest);
1507 cfa_temp.offset = INTVAL (XEXP (src, 1));
1516 cfa_temp.reg = REGNO (dest);
1517 cfa_temp.offset = INTVAL (src);
1522 if (GET_CODE (XEXP (src, 0)) != REG
1523 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1524 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1527 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1528 cfa_temp.reg = REGNO (dest);
1529 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1532 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1533 which will fill in all of the bits. */
1542 def_cfa_1 (label, &cfa);
1546 if (GET_CODE (src) != REG)
1549 /* Saving a register to the stack. Make sure dest is relative to the
1551 switch (GET_CODE (XEXP (dest, 0)))
1556 /* We can't handle variable size modifications. */
1557 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1559 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1561 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1562 || cfa_store.reg != STACK_POINTER_REGNUM)
1565 cfa_store.offset += offset;
1566 if (cfa.reg == STACK_POINTER_REGNUM)
1567 cfa.offset = cfa_store.offset;
1569 offset = -cfa_store.offset;
1575 offset = GET_MODE_SIZE (GET_MODE (dest));
1576 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1579 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1580 || cfa_store.reg != STACK_POINTER_REGNUM)
1583 cfa_store.offset += offset;
1584 if (cfa.reg == STACK_POINTER_REGNUM)
1585 cfa.offset = cfa_store.offset;
1587 offset = -cfa_store.offset;
1591 /* With an offset. */
1595 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1597 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1598 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1601 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1602 offset -= cfa_store.offset;
1603 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1604 offset -= cfa_temp.offset;
1610 /* Without an offset. */
1612 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1613 offset = -cfa_store.offset;
1614 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1615 offset = -cfa_temp.offset;
1622 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1624 offset = -cfa_temp.offset;
1625 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1632 if (REGNO (src) != STACK_POINTER_REGNUM
1633 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1634 && (unsigned) REGNO (src) == cfa.reg)
1636 /* We're storing the current CFA reg into the stack. */
1638 if (cfa.offset == 0)
1640 /* If the source register is exactly the CFA, assume
1641 we're saving SP like any other register; this happens
1643 def_cfa_1 (label, &cfa);
1644 queue_reg_save (label, stack_pointer_rtx, offset);
1649 /* Otherwise, we'll need to look in the stack to
1650 calculate the CFA. */
1651 rtx x = XEXP (dest, 0);
1653 if (GET_CODE (x) != REG)
1655 if (GET_CODE (x) != REG)
1658 cfa.reg = REGNO (x);
1659 cfa.base_offset = offset;
1661 def_cfa_1 (label, &cfa);
1666 def_cfa_1 (label, &cfa);
1667 queue_reg_save (label, src, offset);
1675 /* Record call frame debugging information for INSN, which either
1676 sets SP or FP (adjusting how we calculate the frame address) or saves a
1677 register to the stack. If INSN is NULL_RTX, initialize our state. */
1680 dwarf2out_frame_debug (rtx insn)
1685 if (insn == NULL_RTX)
1687 /* Flush any queued register saves. */
1688 flush_queued_reg_saves ();
1690 /* Set up state for generating call frame debug info. */
1692 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1695 cfa.reg = STACK_POINTER_REGNUM;
1698 cfa_temp.offset = 0;
1702 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1703 flush_queued_reg_saves ();
1705 if (! RTX_FRAME_RELATED_P (insn))
1707 if (!ACCUMULATE_OUTGOING_ARGS)
1708 dwarf2out_stack_adjust (insn);
1713 label = dwarf2out_cfi_label ();
1714 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1716 insn = XEXP (src, 0);
1718 insn = PATTERN (insn);
1720 dwarf2out_frame_debug_expr (insn, label);
1725 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1726 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1727 (enum dwarf_call_frame_info cfi);
1729 static enum dw_cfi_oprnd_type
1730 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1735 case DW_CFA_GNU_window_save:
1736 return dw_cfi_oprnd_unused;
1738 case DW_CFA_set_loc:
1739 case DW_CFA_advance_loc1:
1740 case DW_CFA_advance_loc2:
1741 case DW_CFA_advance_loc4:
1742 case DW_CFA_MIPS_advance_loc8:
1743 return dw_cfi_oprnd_addr;
1746 case DW_CFA_offset_extended:
1747 case DW_CFA_def_cfa:
1748 case DW_CFA_offset_extended_sf:
1749 case DW_CFA_def_cfa_sf:
1750 case DW_CFA_restore_extended:
1751 case DW_CFA_undefined:
1752 case DW_CFA_same_value:
1753 case DW_CFA_def_cfa_register:
1754 case DW_CFA_register:
1755 return dw_cfi_oprnd_reg_num;
1757 case DW_CFA_def_cfa_offset:
1758 case DW_CFA_GNU_args_size:
1759 case DW_CFA_def_cfa_offset_sf:
1760 return dw_cfi_oprnd_offset;
1762 case DW_CFA_def_cfa_expression:
1763 case DW_CFA_expression:
1764 return dw_cfi_oprnd_loc;
1771 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1772 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1773 (enum dwarf_call_frame_info cfi);
1775 static enum dw_cfi_oprnd_type
1776 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1780 case DW_CFA_def_cfa:
1781 case DW_CFA_def_cfa_sf:
1783 case DW_CFA_offset_extended_sf:
1784 case DW_CFA_offset_extended:
1785 return dw_cfi_oprnd_offset;
1787 case DW_CFA_register:
1788 return dw_cfi_oprnd_reg_num;
1791 return dw_cfi_oprnd_unused;
1795 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1797 /* Map register numbers held in the call frame info that gcc has
1798 collected using DWARF_FRAME_REGNUM to those that should be output in
1799 .debug_frame and .eh_frame. */
1800 #ifndef DWARF2_FRAME_REG_OUT
1801 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
1804 /* Output a Call Frame Information opcode and its operand(s). */
1807 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
1810 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1811 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1812 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1813 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
1814 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1815 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1817 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1818 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
1819 "DW_CFA_offset, column 0x%lx", r);
1820 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1822 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1824 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1825 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
1826 "DW_CFA_restore, column 0x%lx", r);
1830 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1831 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1833 switch (cfi->dw_cfi_opc)
1835 case DW_CFA_set_loc:
1837 dw2_asm_output_encoded_addr_rtx (
1838 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1839 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1842 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1843 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1846 case DW_CFA_advance_loc1:
1847 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1848 fde->dw_fde_current_label, NULL);
1849 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1852 case DW_CFA_advance_loc2:
1853 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1854 fde->dw_fde_current_label, NULL);
1855 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1858 case DW_CFA_advance_loc4:
1859 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1860 fde->dw_fde_current_label, NULL);
1861 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1864 case DW_CFA_MIPS_advance_loc8:
1865 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1866 fde->dw_fde_current_label, NULL);
1867 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1870 case DW_CFA_offset_extended:
1871 case DW_CFA_def_cfa:
1872 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1873 dw2_asm_output_data_uleb128 (r, NULL);
1874 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1877 case DW_CFA_offset_extended_sf:
1878 case DW_CFA_def_cfa_sf:
1879 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1880 dw2_asm_output_data_uleb128 (r, NULL);
1881 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1884 case DW_CFA_restore_extended:
1885 case DW_CFA_undefined:
1886 case DW_CFA_same_value:
1887 case DW_CFA_def_cfa_register:
1888 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1889 dw2_asm_output_data_uleb128 (r, NULL);
1892 case DW_CFA_register:
1893 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1894 dw2_asm_output_data_uleb128 (r, NULL);
1895 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
1896 dw2_asm_output_data_uleb128 (r, NULL);
1899 case DW_CFA_def_cfa_offset:
1900 case DW_CFA_GNU_args_size:
1901 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1904 case DW_CFA_def_cfa_offset_sf:
1905 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1908 case DW_CFA_GNU_window_save:
1911 case DW_CFA_def_cfa_expression:
1912 case DW_CFA_expression:
1913 output_cfa_loc (cfi);
1916 case DW_CFA_GNU_negative_offset_extended:
1917 /* Obsoleted by DW_CFA_offset_extended_sf. */
1926 /* Output the call frame information used to record information
1927 that relates to calculating the frame pointer, and records the
1928 location of saved registers. */
1931 output_call_frame_info (int for_eh)
1936 char l1[20], l2[20], section_start_label[20];
1937 bool any_lsda_needed = false;
1938 char augmentation[6];
1939 int augmentation_size;
1940 int fde_encoding = DW_EH_PE_absptr;
1941 int per_encoding = DW_EH_PE_absptr;
1942 int lsda_encoding = DW_EH_PE_absptr;
1944 /* Don't emit a CIE if there won't be any FDEs. */
1945 if (fde_table_in_use == 0)
1948 /* If we make FDEs linkonce, we may have to emit an empty label for
1949 an FDE that wouldn't otherwise be emitted. We want to avoid
1950 having an FDE kept around when the function it refers to is
1951 discarded. (Example where this matters: a primary function
1952 template in C++ requires EH information, but an explicit
1953 specialization doesn't. */
1954 if (TARGET_USES_WEAK_UNWIND_INFO
1955 && ! flag_asynchronous_unwind_tables
1957 for (i = 0; i < fde_table_in_use; i++)
1958 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
1959 && !fde_table[i].uses_eh_lsda
1960 && ! DECL_ONE_ONLY (fde_table[i].decl))
1961 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
1964 /* If we don't have any functions we'll want to unwind out of, don't
1965 emit any EH unwind information. Note that if exceptions aren't
1966 enabled, we won't have collected nothrow information, and if we
1967 asked for asynchronous tables, we always want this info. */
1970 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
1972 for (i = 0; i < fde_table_in_use; i++)
1973 if (fde_table[i].uses_eh_lsda)
1974 any_eh_needed = any_lsda_needed = true;
1975 else if (TARGET_USES_WEAK_UNWIND_INFO
1976 && DECL_ONE_ONLY (fde_table[i].decl))
1978 else if (! fde_table[i].nothrow
1979 && ! fde_table[i].all_throwers_are_sibcalls)
1980 any_eh_needed = true;
1982 if (! any_eh_needed)
1986 /* We're going to be generating comments, so turn on app. */
1991 targetm.asm_out.eh_frame_section ();
1993 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1995 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1996 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1998 /* Output the CIE. */
1999 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2000 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2001 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2002 "Length of Common Information Entry");
2003 ASM_OUTPUT_LABEL (asm_out_file, l1);
2005 /* Now that the CIE pointer is PC-relative for EH,
2006 use 0 to identify the CIE. */
2007 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2008 (for_eh ? 0 : DW_CIE_ID),
2009 "CIE Identifier Tag");
2011 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2013 augmentation[0] = 0;
2014 augmentation_size = 0;
2020 z Indicates that a uleb128 is present to size the
2021 augmentation section.
2022 L Indicates the encoding (and thus presence) of
2023 an LSDA pointer in the FDE augmentation.
2024 R Indicates a non-default pointer encoding for
2026 P Indicates the presence of an encoding + language
2027 personality routine in the CIE augmentation. */
2029 fde_encoding = TARGET_USES_WEAK_UNWIND_INFO
2030 ? ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1)
2031 : ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2032 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2033 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2035 p = augmentation + 1;
2036 if (eh_personality_libfunc)
2039 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2041 if (any_lsda_needed)
2044 augmentation_size += 1;
2046 if (fde_encoding != DW_EH_PE_absptr)
2049 augmentation_size += 1;
2051 if (p > augmentation + 1)
2053 augmentation[0] = 'z';
2057 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2058 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2060 int offset = ( 4 /* Length */
2062 + 1 /* CIE version */
2063 + strlen (augmentation) + 1 /* Augmentation */
2064 + size_of_uleb128 (1) /* Code alignment */
2065 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2067 + 1 /* Augmentation size */
2068 + 1 /* Personality encoding */ );
2069 int pad = -offset & (PTR_SIZE - 1);
2071 augmentation_size += pad;
2073 /* Augmentations should be small, so there's scarce need to
2074 iterate for a solution. Die if we exceed one uleb128 byte. */
2075 if (size_of_uleb128 (augmentation_size) != 1)
2080 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2081 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2082 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2083 "CIE Data Alignment Factor");
2084 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
2086 if (augmentation[0])
2088 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2089 if (eh_personality_libfunc)
2091 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2092 eh_data_format_name (per_encoding));
2093 dw2_asm_output_encoded_addr_rtx (per_encoding,
2094 eh_personality_libfunc, NULL);
2097 if (any_lsda_needed)
2098 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2099 eh_data_format_name (lsda_encoding));
2101 if (fde_encoding != DW_EH_PE_absptr)
2102 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2103 eh_data_format_name (fde_encoding));
2106 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2107 output_cfi (cfi, NULL, for_eh);
2109 /* Pad the CIE out to an address sized boundary. */
2110 ASM_OUTPUT_ALIGN (asm_out_file,
2111 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2112 ASM_OUTPUT_LABEL (asm_out_file, l2);
2114 /* Loop through all of the FDE's. */
2115 for (i = 0; i < fde_table_in_use; i++)
2117 fde = &fde_table[i];
2119 /* Don't emit EH unwind info for leaf functions that don't need it. */
2120 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2121 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2122 && (! TARGET_USES_WEAK_UNWIND_INFO || ! DECL_ONE_ONLY (fde->decl))
2123 && !fde->uses_eh_lsda)
2126 targetm.asm_out.unwind_label (asm_out_file, fde->decl, /* empty */ 0);
2127 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2128 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2129 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2130 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2132 ASM_OUTPUT_LABEL (asm_out_file, l1);
2135 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2137 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2142 if (TARGET_USES_WEAK_UNWIND_INFO
2143 && DECL_ONE_ONLY (fde->decl))
2144 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2145 gen_rtx_SYMBOL_REF (Pmode, IDENTIFIER_POINTER
2146 (DECL_ASSEMBLER_NAME (fde->decl))),
2147 "FDE initial location");
2149 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2150 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
2151 "FDE initial location");
2152 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2153 fde->dw_fde_end, fde->dw_fde_begin,
2154 "FDE address range");
2158 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2159 "FDE initial location");
2160 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2161 fde->dw_fde_end, fde->dw_fde_begin,
2162 "FDE address range");
2165 if (augmentation[0])
2167 if (any_lsda_needed)
2169 int size = size_of_encoded_value (lsda_encoding);
2171 if (lsda_encoding == DW_EH_PE_aligned)
2173 int offset = ( 4 /* Length */
2174 + 4 /* CIE offset */
2175 + 2 * size_of_encoded_value (fde_encoding)
2176 + 1 /* Augmentation size */ );
2177 int pad = -offset & (PTR_SIZE - 1);
2180 if (size_of_uleb128 (size) != 1)
2184 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2186 if (fde->uses_eh_lsda)
2188 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2189 fde->funcdef_number);
2190 dw2_asm_output_encoded_addr_rtx (
2191 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2192 "Language Specific Data Area");
2196 if (lsda_encoding == DW_EH_PE_aligned)
2197 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2199 (size_of_encoded_value (lsda_encoding), 0,
2200 "Language Specific Data Area (none)");
2204 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2207 /* Loop through the Call Frame Instructions associated with
2209 fde->dw_fde_current_label = fde->dw_fde_begin;
2210 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2211 output_cfi (cfi, fde, for_eh);
2213 /* Pad the FDE out to an address sized boundary. */
2214 ASM_OUTPUT_ALIGN (asm_out_file,
2215 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2216 ASM_OUTPUT_LABEL (asm_out_file, l2);
2219 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2220 dw2_asm_output_data (4, 0, "End of Table");
2221 #ifdef MIPS_DEBUGGING_INFO
2222 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2223 get a value of 0. Putting .align 0 after the label fixes it. */
2224 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2227 /* Turn off app to make assembly quicker. */
2232 /* Output a marker (i.e. a label) for the beginning of a function, before
2236 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2237 const char *file ATTRIBUTE_UNUSED)
2239 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2242 current_function_func_begin_label = 0;
2244 #ifdef IA64_UNWIND_INFO
2245 /* ??? current_function_func_begin_label is also used by except.c
2246 for call-site information. We must emit this label if it might
2248 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2249 && ! dwarf2out_do_frame ())
2252 if (! dwarf2out_do_frame ())
2256 function_section (current_function_decl);
2257 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2258 current_function_funcdef_no);
2259 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2260 current_function_funcdef_no);
2261 current_function_func_begin_label = get_identifier (label);
2263 #ifdef IA64_UNWIND_INFO
2264 /* We can elide the fde allocation if we're not emitting debug info. */
2265 if (! dwarf2out_do_frame ())
2269 /* Expand the fde table if necessary. */
2270 if (fde_table_in_use == fde_table_allocated)
2272 fde_table_allocated += FDE_TABLE_INCREMENT;
2273 fde_table = ggc_realloc (fde_table,
2274 fde_table_allocated * sizeof (dw_fde_node));
2275 memset (fde_table + fde_table_in_use, 0,
2276 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2279 /* Record the FDE associated with this function. */
2280 current_funcdef_fde = fde_table_in_use;
2282 /* Add the new FDE at the end of the fde_table. */
2283 fde = &fde_table[fde_table_in_use++];
2284 fde->decl = current_function_decl;
2285 fde->dw_fde_begin = xstrdup (label);
2286 fde->dw_fde_current_label = NULL;
2287 fde->dw_fde_end = NULL;
2288 fde->dw_fde_cfi = NULL;
2289 fde->funcdef_number = current_function_funcdef_no;
2290 fde->nothrow = current_function_nothrow;
2291 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2292 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2294 args_size = old_args_size = 0;
2296 /* We only want to output line number information for the genuine dwarf2
2297 prologue case, not the eh frame case. */
2298 #ifdef DWARF2_DEBUGGING_INFO
2300 dwarf2out_source_line (line, file);
2304 /* Output a marker (i.e. a label) for the absolute end of the generated code
2305 for a function definition. This gets called *after* the epilogue code has
2309 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2310 const char *file ATTRIBUTE_UNUSED)
2313 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2315 /* Output a label to mark the endpoint of the code generated for this
2317 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2318 current_function_funcdef_no);
2319 ASM_OUTPUT_LABEL (asm_out_file, label);
2320 fde = &fde_table[fde_table_in_use - 1];
2321 fde->dw_fde_end = xstrdup (label);
2325 dwarf2out_frame_init (void)
2327 /* Allocate the initial hunk of the fde_table. */
2328 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2329 fde_table_allocated = FDE_TABLE_INCREMENT;
2330 fde_table_in_use = 0;
2332 /* Generate the CFA instructions common to all FDE's. Do it now for the
2333 sake of lookup_cfa. */
2335 #ifdef DWARF2_UNWIND_INFO
2336 /* On entry, the Canonical Frame Address is at SP. */
2337 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2338 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2343 dwarf2out_frame_finish (void)
2345 /* Output call frame information. */
2346 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2347 output_call_frame_info (0);
2349 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2350 output_call_frame_info (1);
2354 /* And now, the subset of the debugging information support code necessary
2355 for emitting location expressions. */
2357 /* We need some way to distinguish DW_OP_addr with a direct symbol
2358 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2359 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2362 typedef struct dw_val_struct *dw_val_ref;
2363 typedef struct die_struct *dw_die_ref;
2364 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2365 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2367 /* Each DIE may have a series of attribute/value pairs. Values
2368 can take on several forms. The forms that are used in this
2369 implementation are listed below. */
2374 dw_val_class_offset,
2376 dw_val_class_loc_list,
2377 dw_val_class_range_list,
2379 dw_val_class_unsigned_const,
2380 dw_val_class_long_long,
2383 dw_val_class_die_ref,
2384 dw_val_class_fde_ref,
2385 dw_val_class_lbl_id,
2386 dw_val_class_lbl_offset,
2390 /* Describe a double word constant value. */
2391 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2393 typedef struct dw_long_long_struct GTY(())
2400 /* Describe a floating point constant value, or a vector constant value. */
2402 typedef struct dw_vec_struct GTY(())
2404 unsigned char * GTY((length ("%h.length"))) array;
2410 /* The dw_val_node describes an attribute's value, as it is
2411 represented internally. */
2413 typedef struct dw_val_struct GTY(())
2415 enum dw_val_class val_class;
2416 union dw_val_struct_union
2418 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2419 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2420 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2421 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2422 HOST_WIDE_INT GTY ((default (""))) val_int;
2423 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2424 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2425 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2426 struct dw_val_die_union
2430 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2431 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2432 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2433 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2434 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2436 GTY ((desc ("%1.val_class"))) v;
2440 /* Locations in memory are described using a sequence of stack machine
2443 typedef struct dw_loc_descr_struct GTY(())
2445 dw_loc_descr_ref dw_loc_next;
2446 enum dwarf_location_atom dw_loc_opc;
2447 dw_val_node dw_loc_oprnd1;
2448 dw_val_node dw_loc_oprnd2;
2453 /* Location lists are ranges + location descriptions for that range,
2454 so you can track variables that are in different places over
2455 their entire life. */
2456 typedef struct dw_loc_list_struct GTY(())
2458 dw_loc_list_ref dw_loc_next;
2459 const char *begin; /* Label for begin address of range */
2460 const char *end; /* Label for end address of range */
2461 char *ll_symbol; /* Label for beginning of location list.
2462 Only on head of list */
2463 const char *section; /* Section this loclist is relative to */
2464 dw_loc_descr_ref expr;
2467 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2469 static const char *dwarf_stack_op_name (unsigned);
2470 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2471 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2472 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2473 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2474 static unsigned long size_of_locs (dw_loc_descr_ref);
2475 static void output_loc_operands (dw_loc_descr_ref);
2476 static void output_loc_sequence (dw_loc_descr_ref);
2478 /* Convert a DWARF stack opcode into its string name. */
2481 dwarf_stack_op_name (unsigned int op)
2486 case INTERNAL_DW_OP_tls_addr:
2487 return "DW_OP_addr";
2489 return "DW_OP_deref";
2491 return "DW_OP_const1u";
2493 return "DW_OP_const1s";
2495 return "DW_OP_const2u";
2497 return "DW_OP_const2s";
2499 return "DW_OP_const4u";
2501 return "DW_OP_const4s";
2503 return "DW_OP_const8u";
2505 return "DW_OP_const8s";
2507 return "DW_OP_constu";
2509 return "DW_OP_consts";
2513 return "DW_OP_drop";
2515 return "DW_OP_over";
2517 return "DW_OP_pick";
2519 return "DW_OP_swap";
2523 return "DW_OP_xderef";
2531 return "DW_OP_minus";
2543 return "DW_OP_plus";
2544 case DW_OP_plus_uconst:
2545 return "DW_OP_plus_uconst";
2551 return "DW_OP_shra";
2569 return "DW_OP_skip";
2571 return "DW_OP_lit0";
2573 return "DW_OP_lit1";
2575 return "DW_OP_lit2";
2577 return "DW_OP_lit3";
2579 return "DW_OP_lit4";
2581 return "DW_OP_lit5";
2583 return "DW_OP_lit6";
2585 return "DW_OP_lit7";
2587 return "DW_OP_lit8";
2589 return "DW_OP_lit9";
2591 return "DW_OP_lit10";
2593 return "DW_OP_lit11";
2595 return "DW_OP_lit12";
2597 return "DW_OP_lit13";
2599 return "DW_OP_lit14";
2601 return "DW_OP_lit15";
2603 return "DW_OP_lit16";
2605 return "DW_OP_lit17";
2607 return "DW_OP_lit18";
2609 return "DW_OP_lit19";
2611 return "DW_OP_lit20";
2613 return "DW_OP_lit21";
2615 return "DW_OP_lit22";
2617 return "DW_OP_lit23";
2619 return "DW_OP_lit24";
2621 return "DW_OP_lit25";
2623 return "DW_OP_lit26";
2625 return "DW_OP_lit27";
2627 return "DW_OP_lit28";
2629 return "DW_OP_lit29";
2631 return "DW_OP_lit30";
2633 return "DW_OP_lit31";
2635 return "DW_OP_reg0";
2637 return "DW_OP_reg1";
2639 return "DW_OP_reg2";
2641 return "DW_OP_reg3";
2643 return "DW_OP_reg4";
2645 return "DW_OP_reg5";
2647 return "DW_OP_reg6";
2649 return "DW_OP_reg7";
2651 return "DW_OP_reg8";
2653 return "DW_OP_reg9";
2655 return "DW_OP_reg10";
2657 return "DW_OP_reg11";
2659 return "DW_OP_reg12";
2661 return "DW_OP_reg13";
2663 return "DW_OP_reg14";
2665 return "DW_OP_reg15";
2667 return "DW_OP_reg16";
2669 return "DW_OP_reg17";
2671 return "DW_OP_reg18";
2673 return "DW_OP_reg19";
2675 return "DW_OP_reg20";
2677 return "DW_OP_reg21";
2679 return "DW_OP_reg22";
2681 return "DW_OP_reg23";
2683 return "DW_OP_reg24";
2685 return "DW_OP_reg25";
2687 return "DW_OP_reg26";
2689 return "DW_OP_reg27";
2691 return "DW_OP_reg28";
2693 return "DW_OP_reg29";
2695 return "DW_OP_reg30";
2697 return "DW_OP_reg31";
2699 return "DW_OP_breg0";
2701 return "DW_OP_breg1";
2703 return "DW_OP_breg2";
2705 return "DW_OP_breg3";
2707 return "DW_OP_breg4";
2709 return "DW_OP_breg5";
2711 return "DW_OP_breg6";
2713 return "DW_OP_breg7";
2715 return "DW_OP_breg8";
2717 return "DW_OP_breg9";
2719 return "DW_OP_breg10";
2721 return "DW_OP_breg11";
2723 return "DW_OP_breg12";
2725 return "DW_OP_breg13";
2727 return "DW_OP_breg14";
2729 return "DW_OP_breg15";
2731 return "DW_OP_breg16";
2733 return "DW_OP_breg17";
2735 return "DW_OP_breg18";
2737 return "DW_OP_breg19";
2739 return "DW_OP_breg20";
2741 return "DW_OP_breg21";
2743 return "DW_OP_breg22";
2745 return "DW_OP_breg23";
2747 return "DW_OP_breg24";
2749 return "DW_OP_breg25";
2751 return "DW_OP_breg26";
2753 return "DW_OP_breg27";
2755 return "DW_OP_breg28";
2757 return "DW_OP_breg29";
2759 return "DW_OP_breg30";
2761 return "DW_OP_breg31";
2763 return "DW_OP_regx";
2765 return "DW_OP_fbreg";
2767 return "DW_OP_bregx";
2769 return "DW_OP_piece";
2770 case DW_OP_deref_size:
2771 return "DW_OP_deref_size";
2772 case DW_OP_xderef_size:
2773 return "DW_OP_xderef_size";
2776 case DW_OP_push_object_address:
2777 return "DW_OP_push_object_address";
2779 return "DW_OP_call2";
2781 return "DW_OP_call4";
2782 case DW_OP_call_ref:
2783 return "DW_OP_call_ref";
2784 case DW_OP_GNU_push_tls_address:
2785 return "DW_OP_GNU_push_tls_address";
2787 return "OP_<unknown>";
2791 /* Return a pointer to a newly allocated location description. Location
2792 descriptions are simple expression terms that can be strung
2793 together to form more complicated location (address) descriptions. */
2795 static inline dw_loc_descr_ref
2796 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
2797 unsigned HOST_WIDE_INT oprnd2)
2799 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
2801 descr->dw_loc_opc = op;
2802 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2803 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2804 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2805 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2811 /* Add a location description term to a location description expression. */
2814 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
2816 dw_loc_descr_ref *d;
2818 /* Find the end of the chain. */
2819 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2825 /* Return the size of a location descriptor. */
2827 static unsigned long
2828 size_of_loc_descr (dw_loc_descr_ref loc)
2830 unsigned long size = 1;
2832 switch (loc->dw_loc_opc)
2835 case INTERNAL_DW_OP_tls_addr:
2836 size += DWARF2_ADDR_SIZE;
2855 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2858 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2863 case DW_OP_plus_uconst:
2864 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2902 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2905 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2908 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2911 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2912 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2915 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2917 case DW_OP_deref_size:
2918 case DW_OP_xderef_size:
2927 case DW_OP_call_ref:
2928 size += DWARF2_ADDR_SIZE;
2937 /* Return the size of a series of location descriptors. */
2939 static unsigned long
2940 size_of_locs (dw_loc_descr_ref loc)
2944 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2946 loc->dw_loc_addr = size;
2947 size += size_of_loc_descr (loc);
2953 /* Output location description stack opcode's operands (if any). */
2956 output_loc_operands (dw_loc_descr_ref loc)
2958 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2959 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2961 switch (loc->dw_loc_opc)
2963 #ifdef DWARF2_DEBUGGING_INFO
2965 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2969 dw2_asm_output_data (2, val1->v.val_int, NULL);
2973 dw2_asm_output_data (4, val1->v.val_int, NULL);
2977 if (HOST_BITS_PER_LONG < 64)
2979 dw2_asm_output_data (8, val1->v.val_int, NULL);
2986 if (val1->val_class == dw_val_class_loc)
2987 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2991 dw2_asm_output_data (2, offset, NULL);
3004 /* We currently don't make any attempt to make sure these are
3005 aligned properly like we do for the main unwind info, so
3006 don't support emitting things larger than a byte if we're
3007 only doing unwinding. */
3012 dw2_asm_output_data (1, val1->v.val_int, NULL);
3015 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3018 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3021 dw2_asm_output_data (1, val1->v.val_int, NULL);
3023 case DW_OP_plus_uconst:
3024 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3058 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3061 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3064 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3067 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3068 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3071 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3073 case DW_OP_deref_size:
3074 case DW_OP_xderef_size:
3075 dw2_asm_output_data (1, val1->v.val_int, NULL);
3078 case INTERNAL_DW_OP_tls_addr:
3079 #ifdef ASM_OUTPUT_DWARF_DTPREL
3080 ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE,
3082 fputc ('\n', asm_out_file);
3089 /* Other codes have no operands. */
3094 /* Output a sequence of location operations. */
3097 output_loc_sequence (dw_loc_descr_ref loc)
3099 for (; loc != NULL; loc = loc->dw_loc_next)
3101 /* Output the opcode. */
3102 dw2_asm_output_data (1, loc->dw_loc_opc,
3103 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3105 /* Output the operand(s) (if any). */
3106 output_loc_operands (loc);
3110 /* This routine will generate the correct assembly data for a location
3111 description based on a cfi entry with a complex address. */
3114 output_cfa_loc (dw_cfi_ref cfi)
3116 dw_loc_descr_ref loc;
3119 /* Output the size of the block. */
3120 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3121 size = size_of_locs (loc);
3122 dw2_asm_output_data_uleb128 (size, NULL);
3124 /* Now output the operations themselves. */
3125 output_loc_sequence (loc);
3128 /* This function builds a dwarf location descriptor sequence from
3129 a dw_cfa_location. */
3131 static struct dw_loc_descr_struct *
3132 build_cfa_loc (dw_cfa_location *cfa)
3134 struct dw_loc_descr_struct *head, *tmp;
3136 if (cfa->indirect == 0)
3139 if (cfa->base_offset)
3142 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3144 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3146 else if (cfa->reg <= 31)
3147 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3149 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3151 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3152 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3153 add_loc_descr (&head, tmp);
3154 if (cfa->offset != 0)
3156 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3157 add_loc_descr (&head, tmp);
3163 /* This function fills in aa dw_cfa_location structure from a dwarf location
3164 descriptor sequence. */
3167 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3169 struct dw_loc_descr_struct *ptr;
3171 cfa->base_offset = 0;
3175 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3177 enum dwarf_location_atom op = ptr->dw_loc_opc;
3213 cfa->reg = op - DW_OP_reg0;
3216 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3250 cfa->reg = op - DW_OP_breg0;
3251 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3254 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3255 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3260 case DW_OP_plus_uconst:
3261 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3264 internal_error ("DW_LOC_OP %s not implemented\n",
3265 dwarf_stack_op_name (ptr->dw_loc_opc));
3269 #endif /* .debug_frame support */
3271 /* And now, the support for symbolic debugging information. */
3272 #ifdef DWARF2_DEBUGGING_INFO
3274 /* .debug_str support. */
3275 static int output_indirect_string (void **, void *);
3277 static void dwarf2out_init (const char *);
3278 static void dwarf2out_finish (const char *);
3279 static void dwarf2out_define (unsigned int, const char *);
3280 static void dwarf2out_undef (unsigned int, const char *);
3281 static void dwarf2out_start_source_file (unsigned, const char *);
3282 static void dwarf2out_end_source_file (unsigned);
3283 static void dwarf2out_begin_block (unsigned, unsigned);
3284 static void dwarf2out_end_block (unsigned, unsigned);
3285 static bool dwarf2out_ignore_block (tree);
3286 static void dwarf2out_global_decl (tree);
3287 static void dwarf2out_type_decl (tree, int);
3288 static void dwarf2out_imported_module_or_decl (tree, tree);
3289 static void dwarf2out_abstract_function (tree);
3290 static void dwarf2out_var_location (rtx);
3291 static void dwarf2out_begin_function (tree);
3293 /* The debug hooks structure. */
3295 const struct gcc_debug_hooks dwarf2_debug_hooks =
3301 dwarf2out_start_source_file,
3302 dwarf2out_end_source_file,
3303 dwarf2out_begin_block,
3304 dwarf2out_end_block,
3305 dwarf2out_ignore_block,
3306 dwarf2out_source_line,
3307 dwarf2out_begin_prologue,
3308 debug_nothing_int_charstar, /* end_prologue */
3309 dwarf2out_end_epilogue,
3310 dwarf2out_begin_function,
3311 debug_nothing_int, /* end_function */
3312 dwarf2out_decl, /* function_decl */
3313 dwarf2out_global_decl,
3314 dwarf2out_type_decl, /* type_decl */
3315 dwarf2out_imported_module_or_decl,
3316 debug_nothing_tree, /* deferred_inline_function */
3317 /* The DWARF 2 backend tries to reduce debugging bloat by not
3318 emitting the abstract description of inline functions until
3319 something tries to reference them. */
3320 dwarf2out_abstract_function, /* outlining_inline_function */
3321 debug_nothing_rtx, /* label */
3322 debug_nothing_int, /* handle_pch */
3323 dwarf2out_var_location
3327 /* NOTE: In the comments in this file, many references are made to
3328 "Debugging Information Entries". This term is abbreviated as `DIE'
3329 throughout the remainder of this file. */
3331 /* An internal representation of the DWARF output is built, and then
3332 walked to generate the DWARF debugging info. The walk of the internal
3333 representation is done after the entire program has been compiled.
3334 The types below are used to describe the internal representation. */
3336 /* Various DIE's use offsets relative to the beginning of the
3337 .debug_info section to refer to each other. */
3339 typedef long int dw_offset;
3341 /* Define typedefs here to avoid circular dependencies. */
3343 typedef struct dw_attr_struct *dw_attr_ref;
3344 typedef struct dw_line_info_struct *dw_line_info_ref;
3345 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3346 typedef struct pubname_struct *pubname_ref;
3347 typedef struct dw_ranges_struct *dw_ranges_ref;
3349 /* Each entry in the line_info_table maintains the file and
3350 line number associated with the label generated for that
3351 entry. The label gives the PC value associated with
3352 the line number entry. */
3354 typedef struct dw_line_info_struct GTY(())
3356 unsigned long dw_file_num;
3357 unsigned long dw_line_num;
3361 /* Line information for functions in separate sections; each one gets its
3363 typedef struct dw_separate_line_info_struct GTY(())
3365 unsigned long dw_file_num;
3366 unsigned long dw_line_num;
3367 unsigned long function;
3369 dw_separate_line_info_entry;
3371 /* Each DIE attribute has a field specifying the attribute kind,
3372 a link to the next attribute in the chain, and an attribute value.
3373 Attributes are typically linked below the DIE they modify. */
3375 typedef struct dw_attr_struct GTY(())
3377 enum dwarf_attribute dw_attr;
3378 dw_attr_ref dw_attr_next;
3379 dw_val_node dw_attr_val;
3383 /* The Debugging Information Entry (DIE) structure */
3385 typedef struct die_struct GTY(())
3387 enum dwarf_tag die_tag;
3389 dw_attr_ref die_attr;
3390 dw_die_ref die_parent;
3391 dw_die_ref die_child;
3393 dw_die_ref die_definition; /* ref from a specification to its definition */
3394 dw_offset die_offset;
3395 unsigned long die_abbrev;
3397 unsigned int decl_id;
3401 /* The pubname structure */
3403 typedef struct pubname_struct GTY(())
3410 struct dw_ranges_struct GTY(())
3415 /* The limbo die list structure. */
3416 typedef struct limbo_die_struct GTY(())
3420 struct limbo_die_struct *next;
3424 /* How to start an assembler comment. */
3425 #ifndef ASM_COMMENT_START
3426 #define ASM_COMMENT_START ";#"
3429 /* Define a macro which returns nonzero for a TYPE_DECL which was
3430 implicitly generated for a tagged type.
3432 Note that unlike the gcc front end (which generates a NULL named
3433 TYPE_DECL node for each complete tagged type, each array type, and
3434 each function type node created) the g++ front end generates a
3435 _named_ TYPE_DECL node for each tagged type node created.
3436 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3437 generate a DW_TAG_typedef DIE for them. */
3439 #define TYPE_DECL_IS_STUB(decl) \
3440 (DECL_NAME (decl) == NULL_TREE \
3441 || (DECL_ARTIFICIAL (decl) \
3442 && is_tagged_type (TREE_TYPE (decl)) \
3443 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3444 /* This is necessary for stub decls that \
3445 appear in nested inline functions. */ \
3446 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3447 && (decl_ultimate_origin (decl) \
3448 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3450 /* Information concerning the compilation unit's programming
3451 language, and compiler version. */
3453 /* Fixed size portion of the DWARF compilation unit header. */
3454 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3455 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3457 /* Fixed size portion of public names info. */
3458 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3460 /* Fixed size portion of the address range info. */
3461 #define DWARF_ARANGES_HEADER_SIZE \
3462 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3463 DWARF2_ADDR_SIZE * 2) \
3464 - DWARF_INITIAL_LENGTH_SIZE)
3466 /* Size of padding portion in the address range info. It must be
3467 aligned to twice the pointer size. */
3468 #define DWARF_ARANGES_PAD_SIZE \
3469 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3470 DWARF2_ADDR_SIZE * 2) \
3471 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3473 /* Use assembler line directives if available. */
3474 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3475 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3476 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3478 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3482 /* Minimum line offset in a special line info. opcode.
3483 This value was chosen to give a reasonable range of values. */
3484 #define DWARF_LINE_BASE -10
3486 /* First special line opcode - leave room for the standard opcodes. */
3487 #define DWARF_LINE_OPCODE_BASE 10
3489 /* Range of line offsets in a special line info. opcode. */
3490 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3492 /* Flag that indicates the initial value of the is_stmt_start flag.
3493 In the present implementation, we do not mark any lines as
3494 the beginning of a source statement, because that information
3495 is not made available by the GCC front-end. */
3496 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3498 #ifdef DWARF2_DEBUGGING_INFO
3499 /* This location is used by calc_die_sizes() to keep track
3500 the offset of each DIE within the .debug_info section. */
3501 static unsigned long next_die_offset;
3504 /* Record the root of the DIE's built for the current compilation unit. */
3505 static GTY(()) dw_die_ref comp_unit_die;
3507 /* A list of DIEs with a NULL parent waiting to be relocated. */
3508 static GTY(()) limbo_die_node *limbo_die_list;
3510 /* Filenames referenced by this compilation unit. */
3511 static GTY(()) varray_type file_table;
3512 static GTY(()) varray_type file_table_emitted;
3513 static GTY(()) size_t file_table_last_lookup_index;
3515 /* A hash table of references to DIE's that describe declarations.
3516 The key is a DECL_UID() which is a unique number identifying each decl. */
3517 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
3519 /* Node of the variable location list. */
3520 struct var_loc_node GTY ((chain_next ("%h.next")))
3522 rtx GTY (()) var_loc_note;
3523 const char * GTY (()) label;
3524 struct var_loc_node * GTY (()) next;
3527 /* Variable location list. */
3528 struct var_loc_list_def GTY (())
3530 struct var_loc_node * GTY (()) first;
3532 /* Do not mark the last element of the chained list because
3533 it is marked through the chain. */
3534 struct var_loc_node * GTY ((skip ("%h"))) last;
3536 /* DECL_UID of the variable decl. */
3537 unsigned int decl_id;
3539 typedef struct var_loc_list_def var_loc_list;
3542 /* Table of decl location linked lists. */
3543 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
3545 /* A pointer to the base of a list of references to DIE's that
3546 are uniquely identified by their tag, presence/absence of
3547 children DIE's, and list of attribute/value pairs. */
3548 static GTY((length ("abbrev_die_table_allocated")))
3549 dw_die_ref *abbrev_die_table;
3551 /* Number of elements currently allocated for abbrev_die_table. */
3552 static GTY(()) unsigned abbrev_die_table_allocated;
3554 /* Number of elements in type_die_table currently in use. */
3555 static GTY(()) unsigned abbrev_die_table_in_use;
3557 /* Size (in elements) of increments by which we may expand the
3558 abbrev_die_table. */
3559 #define ABBREV_DIE_TABLE_INCREMENT 256
3561 /* A pointer to the base of a table that contains line information
3562 for each source code line in .text in the compilation unit. */
3563 static GTY((length ("line_info_table_allocated")))
3564 dw_line_info_ref line_info_table;
3566 /* Number of elements currently allocated for line_info_table. */
3567 static GTY(()) unsigned line_info_table_allocated;
3569 /* Number of elements in line_info_table currently in use. */
3570 static GTY(()) unsigned line_info_table_in_use;
3572 /* A pointer to the base of a table that contains line information
3573 for each source code line outside of .text in the compilation unit. */
3574 static GTY ((length ("separate_line_info_table_allocated")))
3575 dw_separate_line_info_ref separate_line_info_table;
3577 /* Number of elements currently allocated for separate_line_info_table. */
3578 static GTY(()) unsigned separate_line_info_table_allocated;
3580 /* Number of elements in separate_line_info_table currently in use. */
3581 static GTY(()) unsigned separate_line_info_table_in_use;
3583 /* Size (in elements) of increments by which we may expand the
3585 #define LINE_INFO_TABLE_INCREMENT 1024
3587 /* A pointer to the base of a table that contains a list of publicly
3588 accessible names. */
3589 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table;
3591 /* Number of elements currently allocated for pubname_table. */
3592 static GTY(()) unsigned pubname_table_allocated;
3594 /* Number of elements in pubname_table currently in use. */
3595 static GTY(()) unsigned pubname_table_in_use;
3597 /* Size (in elements) of increments by which we may expand the
3599 #define PUBNAME_TABLE_INCREMENT 64
3601 /* Array of dies for which we should generate .debug_arange info. */
3602 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
3604 /* Number of elements currently allocated for arange_table. */
3605 static GTY(()) unsigned arange_table_allocated;
3607 /* Number of elements in arange_table currently in use. */
3608 static GTY(()) unsigned arange_table_in_use;
3610 /* Size (in elements) of increments by which we may expand the
3612 #define ARANGE_TABLE_INCREMENT 64
3614 /* Array of dies for which we should generate .debug_ranges info. */
3615 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3617 /* Number of elements currently allocated for ranges_table. */
3618 static GTY(()) unsigned ranges_table_allocated;
3620 /* Number of elements in ranges_table currently in use. */
3621 static GTY(()) unsigned ranges_table_in_use;
3623 /* Size (in elements) of increments by which we may expand the
3625 #define RANGES_TABLE_INCREMENT 64
3627 /* Whether we have location lists that need outputting */
3628 static GTY(()) unsigned have_location_lists;
3630 /* Unique label counter. */
3631 static GTY(()) unsigned int loclabel_num;
3633 #ifdef DWARF2_DEBUGGING_INFO
3634 /* Record whether the function being analyzed contains inlined functions. */
3635 static int current_function_has_inlines;
3637 #if 0 && defined (MIPS_DEBUGGING_INFO)