1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003 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"
68 #ifdef DWARF2_DEBUGGING_INFO
69 static void dwarf2out_source_line (unsigned int, const char *);
72 /* DWARF2 Abbreviation Glossary:
73 CFA = Canonical Frame Address
74 a fixed address on the stack which identifies a call frame.
75 We define it to be the value of SP just before the call insn.
76 The CFA register and offset, which may change during the course
77 of the function, are used to calculate its value at runtime.
78 CFI = Call Frame Instruction
79 an instruction for the DWARF2 abstract machine
80 CIE = Common Information Entry
81 information describing information common to one or more FDEs
82 DIE = Debugging Information Entry
83 FDE = Frame Description Entry
84 information describing the stack call frame, in particular,
85 how to restore registers
87 DW_CFA_... = DWARF2 CFA call frame instruction
88 DW_TAG_... = DWARF2 DIE tag */
90 /* Decide whether we want to emit frame unwind information for the current
94 dwarf2out_do_frame (void)
96 return (write_symbols == DWARF2_DEBUG
97 || write_symbols == VMS_AND_DWARF2_DEBUG
98 #ifdef DWARF2_FRAME_INFO
101 #ifdef DWARF2_UNWIND_INFO
102 || flag_unwind_tables
103 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
108 /* The size of the target's pointer type. */
110 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
113 /* Default version of targetm.eh_frame_section. Note this must appear
114 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
118 default_eh_frame_section (void)
120 #ifdef EH_FRAME_SECTION_NAME
121 #ifdef HAVE_LD_RO_RW_SECTION_MIXING
122 int fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
123 int per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
124 int lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
128 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
129 && (fde_encoding & 0x70) != DW_EH_PE_aligned
130 && (per_encoding & 0x70) != DW_EH_PE_absptr
131 && (per_encoding & 0x70) != DW_EH_PE_aligned
132 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
133 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
135 named_section_flags (EH_FRAME_SECTION_NAME, flags);
137 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
140 tree label = get_file_function_name ('F');
143 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
144 (*targetm.asm_out.globalize_label) (asm_out_file, IDENTIFIER_POINTER (label));
145 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
149 /* Array of RTXes referenced by the debugging information, which therefore
150 must be kept around forever. */
151 static GTY(()) varray_type used_rtx_varray;
153 /* A pointer to the base of a list of incomplete types which might be
154 completed at some later time. incomplete_types_list needs to be a VARRAY
155 because we want to tell the garbage collector about it. */
156 static GTY(()) varray_type incomplete_types;
158 /* A pointer to the base of a table of references to declaration
159 scopes. This table is a display which tracks the nesting
160 of declaration scopes at the current scope and containing
161 scopes. This table is used to find the proper place to
162 define type declaration DIE's. */
163 static GTY(()) varray_type decl_scope_table;
165 /* How to start an assembler comment. */
166 #ifndef ASM_COMMENT_START
167 #define ASM_COMMENT_START ";#"
170 typedef struct dw_cfi_struct *dw_cfi_ref;
171 typedef struct dw_fde_struct *dw_fde_ref;
172 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
174 /* Call frames are described using a sequence of Call Frame
175 Information instructions. The register number, offset
176 and address fields are provided as possible operands;
177 their use is selected by the opcode field. */
179 enum dw_cfi_oprnd_type {
181 dw_cfi_oprnd_reg_num,
187 typedef union dw_cfi_oprnd_struct GTY(())
189 unsigned long GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
190 long int GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
191 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
192 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
196 typedef struct dw_cfi_struct GTY(())
198 dw_cfi_ref dw_cfi_next;
199 enum dwarf_call_frame_info dw_cfi_opc;
200 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
202 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
207 /* This is how we define the location of the CFA. We use to handle it
208 as REG + OFFSET all the time, but now it can be more complex.
209 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
210 Instead of passing around REG and OFFSET, we pass a copy
211 of this structure. */
212 typedef struct cfa_loc GTY(())
217 int indirect; /* 1 if CFA is accessed via a dereference. */
220 /* All call frame descriptions (FDE's) in the GCC generated DWARF
221 refer to a single Common Information Entry (CIE), defined at
222 the beginning of the .debug_frame section. This use of a single
223 CIE obviates the need to keep track of multiple CIE's
224 in the DWARF generation routines below. */
226 typedef struct dw_fde_struct GTY(())
228 const char *dw_fde_begin;
229 const char *dw_fde_current_label;
230 const char *dw_fde_end;
231 dw_cfi_ref dw_fde_cfi;
232 unsigned funcdef_number;
233 unsigned all_throwers_are_sibcalls : 1;
234 unsigned nothrow : 1;
235 unsigned uses_eh_lsda : 1;
239 /* Maximum size (in bytes) of an artificially generated label. */
240 #define MAX_ARTIFICIAL_LABEL_BYTES 30
242 /* The size of addresses as they appear in the Dwarf 2 data.
243 Some architectures use word addresses to refer to code locations,
244 but Dwarf 2 info always uses byte addresses. On such machines,
245 Dwarf 2 addresses need to be larger than the architecture's
247 #ifndef DWARF2_ADDR_SIZE
248 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
251 /* The size in bytes of a DWARF field indicating an offset or length
252 relative to a debug info section, specified to be 4 bytes in the
253 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
256 #ifndef DWARF_OFFSET_SIZE
257 #define DWARF_OFFSET_SIZE 4
260 /* According to the (draft) DWARF 3 specification, the initial length
261 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
262 bytes are 0xffffffff, followed by the length stored in the next 8
265 However, the SGI/MIPS ABI uses an initial length which is equal to
266 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
268 #ifndef DWARF_INITIAL_LENGTH_SIZE
269 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
272 #define DWARF_VERSION 2
274 /* Round SIZE up to the nearest BOUNDARY. */
275 #define DWARF_ROUND(SIZE,BOUNDARY) \
276 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
278 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
279 #ifndef DWARF_CIE_DATA_ALIGNMENT
280 #ifdef STACK_GROWS_DOWNWARD
281 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
283 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
287 /* A pointer to the base of a table that contains frame description
288 information for each routine. */
289 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
291 /* Number of elements currently allocated for fde_table. */
292 static GTY(()) unsigned fde_table_allocated;
294 /* Number of elements in fde_table currently in use. */
295 static GTY(()) unsigned fde_table_in_use;
297 /* Size (in elements) of increments by which we may expand the
299 #define FDE_TABLE_INCREMENT 256
301 /* A list of call frame insns for the CIE. */
302 static GTY(()) dw_cfi_ref cie_cfi_head;
304 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
305 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
306 attribute that accelerates the lookup of the FDE associated
307 with the subprogram. This variable holds the table index of the FDE
308 associated with the current function (body) definition. */
309 static unsigned current_funcdef_fde;
312 struct indirect_string_node GTY(())
315 unsigned int refcount;
320 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
322 static GTY(()) int dw2_string_counter;
323 static GTY(()) unsigned long dwarf2out_cfi_label_num;
325 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
327 /* Forward declarations for functions defined in this file. */
329 static char *stripattributes (const char *);
330 static const char *dwarf_cfi_name (unsigned);
331 static dw_cfi_ref new_cfi (void);
332 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
333 static void add_fde_cfi (const char *, dw_cfi_ref);
334 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
335 static void lookup_cfa (dw_cfa_location *);
336 static void reg_save (const char *, unsigned, unsigned, long);
337 static void initial_return_save (rtx);
338 static long stack_adjust_offset (rtx);
339 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
340 static void output_call_frame_info (int);
341 static void dwarf2out_stack_adjust (rtx);
342 static void queue_reg_save (const char *, rtx, long);
343 static void flush_queued_reg_saves (void);
344 static bool clobbers_queued_reg_save (rtx);
345 static void dwarf2out_frame_debug_expr (rtx, const char *);
347 /* Support for complex CFA locations. */
348 static void output_cfa_loc (dw_cfi_ref);
349 static void get_cfa_from_loc_descr (dw_cfa_location *,
350 struct dw_loc_descr_struct *);
351 static struct dw_loc_descr_struct *build_cfa_loc
353 static void def_cfa_1 (const char *, dw_cfa_location *);
355 /* How to start an assembler comment. */
356 #ifndef ASM_COMMENT_START
357 #define ASM_COMMENT_START ";#"
360 /* Data and reference forms for relocatable data. */
361 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
362 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
364 #ifndef DEBUG_FRAME_SECTION
365 #define DEBUG_FRAME_SECTION ".debug_frame"
368 #ifndef FUNC_BEGIN_LABEL
369 #define FUNC_BEGIN_LABEL "LFB"
372 #ifndef FUNC_END_LABEL
373 #define FUNC_END_LABEL "LFE"
376 #define FRAME_BEGIN_LABEL "Lframe"
377 #define CIE_AFTER_SIZE_LABEL "LSCIE"
378 #define CIE_END_LABEL "LECIE"
379 #define FDE_LABEL "LSFDE"
380 #define FDE_AFTER_SIZE_LABEL "LASFDE"
381 #define FDE_END_LABEL "LEFDE"
382 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
383 #define LINE_NUMBER_END_LABEL "LELT"
384 #define LN_PROLOG_AS_LABEL "LASLTP"
385 #define LN_PROLOG_END_LABEL "LELTP"
386 #define DIE_LABEL_PREFIX "DW"
388 /* The DWARF 2 CFA column which tracks the return address. Normally this
389 is the column for PC, or the first column after all of the hard
391 #ifndef DWARF_FRAME_RETURN_COLUMN
393 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
395 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
399 /* The mapping from gcc register number to DWARF 2 CFA column number. By
400 default, we just provide columns for all registers. */
401 #ifndef DWARF_FRAME_REGNUM
402 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
405 /* The offset from the incoming value of %sp to the top of the stack frame
406 for the current function. */
407 #ifndef INCOMING_FRAME_SP_OFFSET
408 #define INCOMING_FRAME_SP_OFFSET 0
411 /* Hook used by __throw. */
414 expand_builtin_dwarf_sp_column (void)
416 return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
419 /* Return a pointer to a copy of the section string name S with all
420 attributes stripped off, and an asterisk prepended (for assemble_name). */
423 stripattributes (const char *s)
425 char *stripped = xmalloc (strlen (s) + 2);
430 while (*s && *s != ',')
437 /* Generate code to initialize the register size table. */
440 expand_builtin_init_dwarf_reg_sizes (tree address)
443 enum machine_mode mode = TYPE_MODE (char_type_node);
444 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
445 rtx mem = gen_rtx_MEM (BLKmode, addr);
447 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
448 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
450 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
451 enum machine_mode save_mode = reg_raw_mode[i];
454 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
455 save_mode = choose_hard_reg_mode (i, 1, true);
456 size = GET_MODE_SIZE (save_mode);
460 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
464 /* Convert a DWARF call frame info. operation to its string name */
467 dwarf_cfi_name (unsigned int cfi_opc)
471 case DW_CFA_advance_loc:
472 return "DW_CFA_advance_loc";
474 return "DW_CFA_offset";
476 return "DW_CFA_restore";
480 return "DW_CFA_set_loc";
481 case DW_CFA_advance_loc1:
482 return "DW_CFA_advance_loc1";
483 case DW_CFA_advance_loc2:
484 return "DW_CFA_advance_loc2";
485 case DW_CFA_advance_loc4:
486 return "DW_CFA_advance_loc4";
487 case DW_CFA_offset_extended:
488 return "DW_CFA_offset_extended";
489 case DW_CFA_restore_extended:
490 return "DW_CFA_restore_extended";
491 case DW_CFA_undefined:
492 return "DW_CFA_undefined";
493 case DW_CFA_same_value:
494 return "DW_CFA_same_value";
495 case DW_CFA_register:
496 return "DW_CFA_register";
497 case DW_CFA_remember_state:
498 return "DW_CFA_remember_state";
499 case DW_CFA_restore_state:
500 return "DW_CFA_restore_state";
502 return "DW_CFA_def_cfa";
503 case DW_CFA_def_cfa_register:
504 return "DW_CFA_def_cfa_register";
505 case DW_CFA_def_cfa_offset:
506 return "DW_CFA_def_cfa_offset";
509 case DW_CFA_def_cfa_expression:
510 return "DW_CFA_def_cfa_expression";
511 case DW_CFA_expression:
512 return "DW_CFA_expression";
513 case DW_CFA_offset_extended_sf:
514 return "DW_CFA_offset_extended_sf";
515 case DW_CFA_def_cfa_sf:
516 return "DW_CFA_def_cfa_sf";
517 case DW_CFA_def_cfa_offset_sf:
518 return "DW_CFA_def_cfa_offset_sf";
520 /* SGI/MIPS specific */
521 case DW_CFA_MIPS_advance_loc8:
522 return "DW_CFA_MIPS_advance_loc8";
525 case DW_CFA_GNU_window_save:
526 return "DW_CFA_GNU_window_save";
527 case DW_CFA_GNU_args_size:
528 return "DW_CFA_GNU_args_size";
529 case DW_CFA_GNU_negative_offset_extended:
530 return "DW_CFA_GNU_negative_offset_extended";
533 return "DW_CFA_<unknown>";
537 /* Return a pointer to a newly allocated Call Frame Instruction. */
539 static inline dw_cfi_ref
542 dw_cfi_ref cfi = (dw_cfi_ref) ggc_alloc (sizeof (dw_cfi_node));
544 cfi->dw_cfi_next = NULL;
545 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
546 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
551 /* Add a Call Frame Instruction to list of instructions. */
554 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
558 /* Find the end of the chain. */
559 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
565 /* Generate a new label for the CFI info to refer to. */
568 dwarf2out_cfi_label (void)
570 static char label[20];
572 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
573 ASM_OUTPUT_LABEL (asm_out_file, label);
577 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
578 or to the CIE if LABEL is NULL. */
581 add_fde_cfi (const char *label, dw_cfi_ref cfi)
585 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
588 label = dwarf2out_cfi_label ();
590 if (fde->dw_fde_current_label == NULL
591 || strcmp (label, fde->dw_fde_current_label) != 0)
595 fde->dw_fde_current_label = label = xstrdup (label);
597 /* Set the location counter to the new label. */
599 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
600 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
601 add_cfi (&fde->dw_fde_cfi, xcfi);
604 add_cfi (&fde->dw_fde_cfi, cfi);
608 add_cfi (&cie_cfi_head, cfi);
611 /* Subroutine of lookup_cfa. */
614 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
616 switch (cfi->dw_cfi_opc)
618 case DW_CFA_def_cfa_offset:
619 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
621 case DW_CFA_def_cfa_register:
622 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
625 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
626 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
628 case DW_CFA_def_cfa_expression:
629 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
636 /* Find the previous value for the CFA. */
639 lookup_cfa (dw_cfa_location *loc)
643 loc->reg = (unsigned long) -1;
646 loc->base_offset = 0;
648 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
649 lookup_cfa_1 (cfi, loc);
651 if (fde_table_in_use)
653 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
654 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
655 lookup_cfa_1 (cfi, loc);
659 /* The current rule for calculating the DWARF2 canonical frame address. */
660 static dw_cfa_location cfa;
662 /* The register used for saving registers to the stack, and its offset
664 static dw_cfa_location cfa_store;
666 /* The running total of the size of arguments pushed onto the stack. */
667 static long args_size;
669 /* The last args_size we actually output. */
670 static long old_args_size;
672 /* Entry point to update the canonical frame address (CFA).
673 LABEL is passed to add_fde_cfi. The value of CFA is now to be
674 calculated from REG+OFFSET. */
677 dwarf2out_def_cfa (const char *label, unsigned int reg, long int offset)
684 def_cfa_1 (label, &loc);
687 /* This routine does the actual work. The CFA is now calculated from
688 the dw_cfa_location structure. */
691 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
694 dw_cfa_location old_cfa, loc;
699 if (cfa_store.reg == loc.reg && loc.indirect == 0)
700 cfa_store.offset = loc.offset;
702 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
703 lookup_cfa (&old_cfa);
705 /* If nothing changed, no need to issue any call frame instructions. */
706 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
707 && loc.indirect == old_cfa.indirect
708 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
713 if (loc.reg == old_cfa.reg && !loc.indirect)
715 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
716 indicating the CFA register did not change but the offset
718 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
719 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
722 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
723 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
726 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
727 indicating the CFA register has changed to <register> but the
728 offset has not changed. */
729 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
730 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
734 else if (loc.indirect == 0)
736 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
737 indicating the CFA register has changed to <register> with
738 the specified offset. */
739 cfi->dw_cfi_opc = DW_CFA_def_cfa;
740 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
741 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
745 /* Construct a DW_CFA_def_cfa_expression instruction to
746 calculate the CFA using a full location expression since no
747 register-offset pair is available. */
748 struct dw_loc_descr_struct *loc_list;
750 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
751 loc_list = build_cfa_loc (&loc);
752 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
755 add_fde_cfi (label, cfi);
758 /* Add the CFI for saving a register. REG is the CFA column number.
759 LABEL is passed to add_fde_cfi.
760 If SREG is -1, the register is saved at OFFSET from the CFA;
761 otherwise it is saved in SREG. */
764 reg_save (const char *label, unsigned int reg, unsigned int sreg, long int offset)
766 dw_cfi_ref cfi = new_cfi ();
768 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
770 /* The following comparison is correct. -1 is used to indicate that
771 the value isn't a register number. */
772 if (sreg == (unsigned int) -1)
775 /* The register number won't fit in 6 bits, so we have to use
777 cfi->dw_cfi_opc = DW_CFA_offset_extended;
779 cfi->dw_cfi_opc = DW_CFA_offset;
781 #ifdef ENABLE_CHECKING
783 /* If we get an offset that is not a multiple of
784 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
785 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
787 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
789 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
793 offset /= DWARF_CIE_DATA_ALIGNMENT;
795 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
797 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
799 else if (sreg == reg)
800 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
804 cfi->dw_cfi_opc = DW_CFA_register;
805 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
808 add_fde_cfi (label, cfi);
811 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
812 This CFI tells the unwinder that it needs to restore the window registers
813 from the previous frame's window save area.
815 ??? Perhaps we should note in the CIE where windows are saved (instead of
816 assuming 0(cfa)) and what registers are in the window. */
819 dwarf2out_window_save (const char *label)
821 dw_cfi_ref cfi = new_cfi ();
823 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
824 add_fde_cfi (label, cfi);
827 /* Add a CFI to update the running total of the size of arguments
828 pushed onto the stack. */
831 dwarf2out_args_size (const char *label, long int size)
835 if (size == old_args_size)
838 old_args_size = size;
841 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
842 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
843 add_fde_cfi (label, cfi);
846 /* Entry point for saving a register to the stack. REG is the GCC register
847 number. LABEL and OFFSET are passed to reg_save. */
850 dwarf2out_reg_save (const char *label, unsigned int reg, long int offset)
852 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
855 /* Entry point for saving the return address in the stack.
856 LABEL and OFFSET are passed to reg_save. */
859 dwarf2out_return_save (const char *label, long int offset)
861 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
864 /* Entry point for saving the return address in a register.
865 LABEL and SREG are passed to reg_save. */
868 dwarf2out_return_reg (const char *label, unsigned int sreg)
870 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
873 /* Record the initial position of the return address. RTL is
874 INCOMING_RETURN_ADDR_RTX. */
877 initial_return_save (rtx rtl)
879 unsigned int reg = (unsigned int) -1;
880 HOST_WIDE_INT offset = 0;
882 switch (GET_CODE (rtl))
885 /* RA is in a register. */
886 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
890 /* RA is on the stack. */
892 switch (GET_CODE (rtl))
895 if (REGNO (rtl) != STACK_POINTER_REGNUM)
901 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
903 offset = INTVAL (XEXP (rtl, 1));
907 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
909 offset = -INTVAL (XEXP (rtl, 1));
919 /* The return address is at some offset from any value we can
920 actually load. For instance, on the SPARC it is in %i7+8. Just
921 ignore the offset for now; it doesn't matter for unwinding frames. */
922 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
924 initial_return_save (XEXP (rtl, 0));
931 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
934 /* Given a SET, calculate the amount of stack adjustment it
938 stack_adjust_offset (rtx pattern)
940 rtx src = SET_SRC (pattern);
941 rtx dest = SET_DEST (pattern);
942 HOST_WIDE_INT offset = 0;
945 if (dest == stack_pointer_rtx)
947 /* (set (reg sp) (plus (reg sp) (const_int))) */
948 code = GET_CODE (src);
949 if (! (code == PLUS || code == MINUS)
950 || XEXP (src, 0) != stack_pointer_rtx
951 || GET_CODE (XEXP (src, 1)) != CONST_INT)
954 offset = INTVAL (XEXP (src, 1));
958 else if (GET_CODE (dest) == MEM)
960 /* (set (mem (pre_dec (reg sp))) (foo)) */
961 src = XEXP (dest, 0);
962 code = GET_CODE (src);
968 if (XEXP (src, 0) == stack_pointer_rtx)
970 rtx val = XEXP (XEXP (src, 1), 1);
971 /* We handle only adjustments by constant amount. */
972 if (GET_CODE (XEXP (src, 1)) != PLUS ||
973 GET_CODE (val) != CONST_INT)
975 offset = -INTVAL (val);
982 if (XEXP (src, 0) == stack_pointer_rtx)
984 offset = GET_MODE_SIZE (GET_MODE (dest));
991 if (XEXP (src, 0) == stack_pointer_rtx)
993 offset = -GET_MODE_SIZE (GET_MODE (dest));
1008 /* Check INSN to see if it looks like a push or a stack adjustment, and
1009 make a note of it if it does. EH uses this information to find out how
1010 much extra space it needs to pop off the stack. */
1013 dwarf2out_stack_adjust (rtx insn)
1015 HOST_WIDE_INT offset;
1019 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
1021 /* Extract the size of the args from the CALL rtx itself. */
1022 insn = PATTERN (insn);
1023 if (GET_CODE (insn) == PARALLEL)
1024 insn = XVECEXP (insn, 0, 0);
1025 if (GET_CODE (insn) == SET)
1026 insn = SET_SRC (insn);
1027 if (GET_CODE (insn) != CALL)
1030 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1034 /* If only calls can throw, and we have a frame pointer,
1035 save up adjustments until we see the CALL_INSN. */
1036 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1039 if (GET_CODE (insn) == BARRIER)
1041 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1042 the compiler will have already emitted a stack adjustment, but
1043 doesn't bother for calls to noreturn functions. */
1044 #ifdef STACK_GROWS_DOWNWARD
1045 offset = -args_size;
1050 else if (GET_CODE (PATTERN (insn)) == SET)
1051 offset = stack_adjust_offset (PATTERN (insn));
1052 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1053 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1055 /* There may be stack adjustments inside compound insns. Search
1057 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1058 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1059 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1067 if (cfa.reg == STACK_POINTER_REGNUM)
1068 cfa.offset += offset;
1070 #ifndef STACK_GROWS_DOWNWARD
1074 args_size += offset;
1078 label = dwarf2out_cfi_label ();
1079 def_cfa_1 (label, &cfa);
1080 dwarf2out_args_size (label, args_size);
1085 /* We delay emitting a register save until either (a) we reach the end
1086 of the prologue or (b) the register is clobbered. This clusters
1087 register saves so that there are fewer pc advances. */
1089 struct queued_reg_save GTY(())
1091 struct queued_reg_save *next;
1096 static GTY(()) struct queued_reg_save *queued_reg_saves;
1098 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1099 static const char *last_reg_save_label;
1102 queue_reg_save (const char *label, rtx reg, long int offset)
1104 struct queued_reg_save *q = ggc_alloc (sizeof (*q));
1106 q->next = queued_reg_saves;
1108 q->cfa_offset = offset;
1109 queued_reg_saves = q;
1111 last_reg_save_label = label;
1115 flush_queued_reg_saves (void)
1117 struct queued_reg_save *q, *next;
1119 for (q = queued_reg_saves; q; q = next)
1121 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1125 queued_reg_saves = NULL;
1126 last_reg_save_label = NULL;
1130 clobbers_queued_reg_save (rtx insn)
1132 struct queued_reg_save *q;
1134 for (q = queued_reg_saves; q; q = q->next)
1135 if (modified_in_p (q->reg, insn))
1142 /* A temporary register holding an integral value used in adjusting SP
1143 or setting up the store_reg. The "offset" field holds the integer
1144 value, not an offset. */
1145 static dw_cfa_location cfa_temp;
1147 /* Record call frame debugging information for an expression EXPR,
1148 which either sets SP or FP (adjusting how we calculate the frame
1149 address) or saves a register to the stack. LABEL indicates the
1152 This function encodes a state machine mapping rtxes to actions on
1153 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1154 users need not read the source code.
1156 The High-Level Picture
1158 Changes in the register we use to calculate the CFA: Currently we
1159 assume that if you copy the CFA register into another register, we
1160 should take the other one as the new CFA register; this seems to
1161 work pretty well. If it's wrong for some target, it's simple
1162 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1164 Changes in the register we use for saving registers to the stack:
1165 This is usually SP, but not always. Again, we deduce that if you
1166 copy SP into another register (and SP is not the CFA register),
1167 then the new register is the one we will be using for register
1168 saves. This also seems to work.
1170 Register saves: There's not much guesswork about this one; if
1171 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1172 register save, and the register used to calculate the destination
1173 had better be the one we think we're using for this purpose.
1175 Except: If the register being saved is the CFA register, and the
1176 offset is nonzero, we are saving the CFA, so we assume we have to
1177 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1178 the intent is to save the value of SP from the previous frame.
1180 Invariants / Summaries of Rules
1182 cfa current rule for calculating the CFA. It usually
1183 consists of a register and an offset.
1184 cfa_store register used by prologue code to save things to the stack
1185 cfa_store.offset is the offset from the value of
1186 cfa_store.reg to the actual CFA
1187 cfa_temp register holding an integral value. cfa_temp.offset
1188 stores the value, which will be used to adjust the
1189 stack pointer. cfa_temp is also used like cfa_store,
1190 to track stores to the stack via fp or a temp reg.
1192 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1193 with cfa.reg as the first operand changes the cfa.reg and its
1194 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1197 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1198 expression yielding a constant. This sets cfa_temp.reg
1199 and cfa_temp.offset.
1201 Rule 5: Create a new register cfa_store used to save items to the
1204 Rules 10-14: Save a register to the stack. Define offset as the
1205 difference of the original location and cfa_store's
1206 location (or cfa_temp's location if cfa_temp is used).
1210 "{a,b}" indicates a choice of a xor b.
1211 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1214 (set <reg1> <reg2>:cfa.reg)
1215 effects: cfa.reg = <reg1>
1216 cfa.offset unchanged
1217 cfa_temp.reg = <reg1>
1218 cfa_temp.offset = cfa.offset
1221 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1222 {<const_int>,<reg>:cfa_temp.reg}))
1223 effects: cfa.reg = sp if fp used
1224 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1225 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1226 if cfa_store.reg==sp
1229 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1230 effects: cfa.reg = fp
1231 cfa_offset += +/- <const_int>
1234 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1235 constraints: <reg1> != fp
1237 effects: cfa.reg = <reg1>
1238 cfa_temp.reg = <reg1>
1239 cfa_temp.offset = cfa.offset
1242 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1243 constraints: <reg1> != fp
1245 effects: cfa_store.reg = <reg1>
1246 cfa_store.offset = cfa.offset - cfa_temp.offset
1249 (set <reg> <const_int>)
1250 effects: cfa_temp.reg = <reg>
1251 cfa_temp.offset = <const_int>
1254 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1255 effects: cfa_temp.reg = <reg1>
1256 cfa_temp.offset |= <const_int>
1259 (set <reg> (high <exp>))
1263 (set <reg> (lo_sum <exp> <const_int>))
1264 effects: cfa_temp.reg = <reg>
1265 cfa_temp.offset = <const_int>
1268 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1269 effects: cfa_store.offset -= <const_int>
1270 cfa.offset = cfa_store.offset if cfa.reg == sp
1272 cfa.base_offset = -cfa_store.offset
1275 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1276 effects: cfa_store.offset += -/+ mode_size(mem)
1277 cfa.offset = cfa_store.offset if cfa.reg == sp
1279 cfa.base_offset = -cfa_store.offset
1282 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1285 effects: cfa.reg = <reg1>
1286 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1289 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1290 effects: cfa.reg = <reg1>
1291 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1294 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1295 effects: cfa.reg = <reg1>
1296 cfa.base_offset = -cfa_temp.offset
1297 cfa_temp.offset -= mode_size(mem) */
1300 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1303 HOST_WIDE_INT offset;
1305 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1306 the PARALLEL independently. The first element is always processed if
1307 it is a SET. This is for backward compatibility. Other elements
1308 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1309 flag is set in them. */
1310 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1313 int limit = XVECLEN (expr, 0);
1315 for (par_index = 0; par_index < limit; par_index++)
1316 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1317 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1319 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1324 if (GET_CODE (expr) != SET)
1327 src = SET_SRC (expr);
1328 dest = SET_DEST (expr);
1330 switch (GET_CODE (dest))
1334 /* Update the CFA rule wrt SP or FP. Make sure src is
1335 relative to the current CFA register. */
1336 switch (GET_CODE (src))
1338 /* Setting FP from SP. */
1340 if (cfa.reg == (unsigned) REGNO (src))
1346 /* We used to require that dest be either SP or FP, but the
1347 ARM copies SP to a temporary register, and from there to
1348 FP. So we just rely on the backends to only set
1349 RTX_FRAME_RELATED_P on appropriate insns. */
1350 cfa.reg = REGNO (dest);
1351 cfa_temp.reg = cfa.reg;
1352 cfa_temp.offset = cfa.offset;
1358 if (dest == stack_pointer_rtx)
1362 switch (GET_CODE (XEXP (src, 1)))
1365 offset = INTVAL (XEXP (src, 1));
1368 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1370 offset = cfa_temp.offset;
1376 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1378 /* Restoring SP from FP in the epilogue. */
1379 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1381 cfa.reg = STACK_POINTER_REGNUM;
1383 else if (GET_CODE (src) == LO_SUM)
1384 /* Assume we've set the source reg of the LO_SUM from sp. */
1386 else if (XEXP (src, 0) != stack_pointer_rtx)
1389 if (GET_CODE (src) != MINUS)
1391 if (cfa.reg == STACK_POINTER_REGNUM)
1392 cfa.offset += offset;
1393 if (cfa_store.reg == STACK_POINTER_REGNUM)
1394 cfa_store.offset += offset;
1396 else if (dest == hard_frame_pointer_rtx)
1399 /* Either setting the FP from an offset of the SP,
1400 or adjusting the FP */
1401 if (! frame_pointer_needed)
1404 if (GET_CODE (XEXP (src, 0)) == REG
1405 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1406 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1408 offset = INTVAL (XEXP (src, 1));
1409 if (GET_CODE (src) != MINUS)
1411 cfa.offset += offset;
1412 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1419 if (GET_CODE (src) == MINUS)
1423 if (GET_CODE (XEXP (src, 0)) == REG
1424 && REGNO (XEXP (src, 0)) == cfa.reg
1425 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1427 /* Setting a temporary CFA register that will be copied
1428 into the FP later on. */
1429 offset = - INTVAL (XEXP (src, 1));
1430 cfa.offset += offset;
1431 cfa.reg = REGNO (dest);
1432 /* Or used to save regs to the stack. */
1433 cfa_temp.reg = cfa.reg;
1434 cfa_temp.offset = cfa.offset;
1438 else if (GET_CODE (XEXP (src, 0)) == REG
1439 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1440 && XEXP (src, 1) == stack_pointer_rtx)
1442 /* Setting a scratch register that we will use instead
1443 of SP for saving registers to the stack. */
1444 if (cfa.reg != STACK_POINTER_REGNUM)
1446 cfa_store.reg = REGNO (dest);
1447 cfa_store.offset = cfa.offset - cfa_temp.offset;
1451 else if (GET_CODE (src) == LO_SUM
1452 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1454 cfa_temp.reg = REGNO (dest);
1455 cfa_temp.offset = INTVAL (XEXP (src, 1));
1464 cfa_temp.reg = REGNO (dest);
1465 cfa_temp.offset = INTVAL (src);
1470 if (GET_CODE (XEXP (src, 0)) != REG
1471 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1472 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1475 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1476 cfa_temp.reg = REGNO (dest);
1477 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1480 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1481 which will fill in all of the bits. */
1490 def_cfa_1 (label, &cfa);
1494 if (GET_CODE (src) != REG)
1497 /* Saving a register to the stack. Make sure dest is relative to the
1499 switch (GET_CODE (XEXP (dest, 0)))
1504 /* We can't handle variable size modifications. */
1505 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1507 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1509 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1510 || cfa_store.reg != STACK_POINTER_REGNUM)
1513 cfa_store.offset += offset;
1514 if (cfa.reg == STACK_POINTER_REGNUM)
1515 cfa.offset = cfa_store.offset;
1517 offset = -cfa_store.offset;
1523 offset = GET_MODE_SIZE (GET_MODE (dest));
1524 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1527 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1528 || cfa_store.reg != STACK_POINTER_REGNUM)
1531 cfa_store.offset += offset;
1532 if (cfa.reg == STACK_POINTER_REGNUM)
1533 cfa.offset = cfa_store.offset;
1535 offset = -cfa_store.offset;
1539 /* With an offset. */
1543 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1545 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1546 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1549 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1550 offset -= cfa_store.offset;
1551 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1552 offset -= cfa_temp.offset;
1558 /* Without an offset. */
1560 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1561 offset = -cfa_store.offset;
1562 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1563 offset = -cfa_temp.offset;
1570 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1572 offset = -cfa_temp.offset;
1573 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1580 if (REGNO (src) != STACK_POINTER_REGNUM
1581 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1582 && (unsigned) REGNO (src) == cfa.reg)
1584 /* We're storing the current CFA reg into the stack. */
1586 if (cfa.offset == 0)
1588 /* If the source register is exactly the CFA, assume
1589 we're saving SP like any other register; this happens
1591 def_cfa_1 (label, &cfa);
1592 queue_reg_save (label, stack_pointer_rtx, offset);
1597 /* Otherwise, we'll need to look in the stack to
1598 calculate the CFA. */
1599 rtx x = XEXP (dest, 0);
1601 if (GET_CODE (x) != REG)
1603 if (GET_CODE (x) != REG)
1606 cfa.reg = REGNO (x);
1607 cfa.base_offset = offset;
1609 def_cfa_1 (label, &cfa);
1614 def_cfa_1 (label, &cfa);
1615 queue_reg_save (label, src, offset);
1623 /* Record call frame debugging information for INSN, which either
1624 sets SP or FP (adjusting how we calculate the frame address) or saves a
1625 register to the stack. If INSN is NULL_RTX, initialize our state. */
1628 dwarf2out_frame_debug (rtx insn)
1633 if (insn == NULL_RTX)
1635 /* Flush any queued register saves. */
1636 flush_queued_reg_saves ();
1638 /* Set up state for generating call frame debug info. */
1640 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1643 cfa.reg = STACK_POINTER_REGNUM;
1646 cfa_temp.offset = 0;
1650 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1651 flush_queued_reg_saves ();
1653 if (! RTX_FRAME_RELATED_P (insn))
1655 if (!ACCUMULATE_OUTGOING_ARGS)
1656 dwarf2out_stack_adjust (insn);
1661 label = dwarf2out_cfi_label ();
1662 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1664 insn = XEXP (src, 0);
1666 insn = PATTERN (insn);
1668 dwarf2out_frame_debug_expr (insn, label);
1673 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1674 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1675 (enum dwarf_call_frame_info cfi);
1677 static enum dw_cfi_oprnd_type
1678 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1683 case DW_CFA_GNU_window_save:
1684 return dw_cfi_oprnd_unused;
1686 case DW_CFA_set_loc:
1687 case DW_CFA_advance_loc1:
1688 case DW_CFA_advance_loc2:
1689 case DW_CFA_advance_loc4:
1690 case DW_CFA_MIPS_advance_loc8:
1691 return dw_cfi_oprnd_addr;
1694 case DW_CFA_offset_extended:
1695 case DW_CFA_def_cfa:
1696 case DW_CFA_offset_extended_sf:
1697 case DW_CFA_def_cfa_sf:
1698 case DW_CFA_restore_extended:
1699 case DW_CFA_undefined:
1700 case DW_CFA_same_value:
1701 case DW_CFA_def_cfa_register:
1702 case DW_CFA_register:
1703 return dw_cfi_oprnd_reg_num;
1705 case DW_CFA_def_cfa_offset:
1706 case DW_CFA_GNU_args_size:
1707 case DW_CFA_def_cfa_offset_sf:
1708 return dw_cfi_oprnd_offset;
1710 case DW_CFA_def_cfa_expression:
1711 case DW_CFA_expression:
1712 return dw_cfi_oprnd_loc;
1719 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1720 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1721 (enum dwarf_call_frame_info cfi);
1723 static enum dw_cfi_oprnd_type
1724 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1728 case DW_CFA_def_cfa:
1729 case DW_CFA_def_cfa_sf:
1731 case DW_CFA_offset_extended_sf:
1732 case DW_CFA_offset_extended:
1733 return dw_cfi_oprnd_offset;
1735 case DW_CFA_register:
1736 return dw_cfi_oprnd_reg_num;
1739 return dw_cfi_oprnd_unused;
1743 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1745 /* Output a Call Frame Information opcode and its operand(s). */
1748 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
1750 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1751 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1752 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1753 "DW_CFA_advance_loc 0x%lx",
1754 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1755 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1757 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1758 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1759 "DW_CFA_offset, column 0x%lx",
1760 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1761 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1763 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1764 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1765 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1766 "DW_CFA_restore, column 0x%lx",
1767 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1770 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1771 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1773 switch (cfi->dw_cfi_opc)
1775 case DW_CFA_set_loc:
1777 dw2_asm_output_encoded_addr_rtx (
1778 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1779 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1782 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1783 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1786 case DW_CFA_advance_loc1:
1787 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1788 fde->dw_fde_current_label, NULL);
1789 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1792 case DW_CFA_advance_loc2:
1793 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1794 fde->dw_fde_current_label, NULL);
1795 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1798 case DW_CFA_advance_loc4:
1799 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1800 fde->dw_fde_current_label, NULL);
1801 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1804 case DW_CFA_MIPS_advance_loc8:
1805 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1806 fde->dw_fde_current_label, NULL);
1807 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1810 case DW_CFA_offset_extended:
1811 case DW_CFA_def_cfa:
1812 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1814 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1817 case DW_CFA_offset_extended_sf:
1818 case DW_CFA_def_cfa_sf:
1819 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1821 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1824 case DW_CFA_restore_extended:
1825 case DW_CFA_undefined:
1826 case DW_CFA_same_value:
1827 case DW_CFA_def_cfa_register:
1828 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1832 case DW_CFA_register:
1833 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1835 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
1839 case DW_CFA_def_cfa_offset:
1840 case DW_CFA_GNU_args_size:
1841 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1844 case DW_CFA_def_cfa_offset_sf:
1845 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1848 case DW_CFA_GNU_window_save:
1851 case DW_CFA_def_cfa_expression:
1852 case DW_CFA_expression:
1853 output_cfa_loc (cfi);
1856 case DW_CFA_GNU_negative_offset_extended:
1857 /* Obsoleted by DW_CFA_offset_extended_sf. */
1866 /* Output the call frame information used to used to record information
1867 that relates to calculating the frame pointer, and records the
1868 location of saved registers. */
1871 output_call_frame_info (int for_eh)
1876 char l1[20], l2[20], section_start_label[20];
1877 bool any_lsda_needed = false;
1878 char augmentation[6];
1879 int augmentation_size;
1880 int fde_encoding = DW_EH_PE_absptr;
1881 int per_encoding = DW_EH_PE_absptr;
1882 int lsda_encoding = DW_EH_PE_absptr;
1884 /* Don't emit a CIE if there won't be any FDEs. */
1885 if (fde_table_in_use == 0)
1888 /* If we don't have any functions we'll want to unwind out of, don't
1889 emit any EH unwind information. Note that if exceptions aren't
1890 enabled, we won't have collected nothrow information, and if we
1891 asked for asynchronous tables, we always want this info. */
1894 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
1896 for (i = 0; i < fde_table_in_use; i++)
1897 if (fde_table[i].uses_eh_lsda)
1898 any_eh_needed = any_lsda_needed = true;
1899 else if (! fde_table[i].nothrow
1900 && ! fde_table[i].all_throwers_are_sibcalls)
1901 any_eh_needed = true;
1903 if (! any_eh_needed)
1907 /* We're going to be generating comments, so turn on app. */
1912 (*targetm.asm_out.eh_frame_section) ();
1914 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1916 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1917 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1919 /* Output the CIE. */
1920 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1921 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1922 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1923 "Length of Common Information Entry");
1924 ASM_OUTPUT_LABEL (asm_out_file, l1);
1926 /* Now that the CIE pointer is PC-relative for EH,
1927 use 0 to identify the CIE. */
1928 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1929 (for_eh ? 0 : DW_CIE_ID),
1930 "CIE Identifier Tag");
1932 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1934 augmentation[0] = 0;
1935 augmentation_size = 0;
1941 z Indicates that a uleb128 is present to size the
1942 augmentation section.
1943 L Indicates the encoding (and thus presence) of
1944 an LSDA pointer in the FDE augmentation.
1945 R Indicates a non-default pointer encoding for
1947 P Indicates the presence of an encoding + language
1948 personality routine in the CIE augmentation. */
1950 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1951 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1952 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1954 p = augmentation + 1;
1955 if (eh_personality_libfunc)
1958 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1960 if (any_lsda_needed)
1963 augmentation_size += 1;
1965 if (fde_encoding != DW_EH_PE_absptr)
1968 augmentation_size += 1;
1970 if (p > augmentation + 1)
1972 augmentation[0] = 'z';
1976 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1977 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1979 int offset = ( 4 /* Length */
1981 + 1 /* CIE version */
1982 + strlen (augmentation) + 1 /* Augmentation */
1983 + size_of_uleb128 (1) /* Code alignment */
1984 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1986 + 1 /* Augmentation size */
1987 + 1 /* Personality encoding */ );
1988 int pad = -offset & (PTR_SIZE - 1);
1990 augmentation_size += pad;
1992 /* Augmentations should be small, so there's scarce need to
1993 iterate for a solution. Die if we exceed one uleb128 byte. */
1994 if (size_of_uleb128 (augmentation_size) != 1)
1999 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2000 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2001 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2002 "CIE Data Alignment Factor");
2003 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
2005 if (augmentation[0])
2007 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2008 if (eh_personality_libfunc)
2010 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2011 eh_data_format_name (per_encoding));
2012 dw2_asm_output_encoded_addr_rtx (per_encoding,
2013 eh_personality_libfunc, NULL);
2016 if (any_lsda_needed)
2017 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2018 eh_data_format_name (lsda_encoding));
2020 if (fde_encoding != DW_EH_PE_absptr)
2021 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2022 eh_data_format_name (fde_encoding));
2025 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2026 output_cfi (cfi, NULL, for_eh);
2028 /* Pad the CIE out to an address sized boundary. */
2029 ASM_OUTPUT_ALIGN (asm_out_file,
2030 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2031 ASM_OUTPUT_LABEL (asm_out_file, l2);
2033 /* Loop through all of the FDE's. */
2034 for (i = 0; i < fde_table_in_use; i++)
2036 fde = &fde_table[i];
2038 /* Don't emit EH unwind info for leaf functions that don't need it. */
2039 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2040 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2041 && !fde->uses_eh_lsda)
2044 (*targetm.asm_out.internal_label) (asm_out_file, FDE_LABEL, for_eh + i * 2);
2045 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2046 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2047 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2049 ASM_OUTPUT_LABEL (asm_out_file, l1);
2052 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2054 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2059 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2060 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
2061 "FDE initial location");
2062 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2063 fde->dw_fde_end, fde->dw_fde_begin,
2064 "FDE address range");
2068 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2069 "FDE initial location");
2070 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2071 fde->dw_fde_end, fde->dw_fde_begin,
2072 "FDE address range");
2075 if (augmentation[0])
2077 if (any_lsda_needed)
2079 int size = size_of_encoded_value (lsda_encoding);
2081 if (lsda_encoding == DW_EH_PE_aligned)
2083 int offset = ( 4 /* Length */
2084 + 4 /* CIE offset */
2085 + 2 * size_of_encoded_value (fde_encoding)
2086 + 1 /* Augmentation size */ );
2087 int pad = -offset & (PTR_SIZE - 1);
2090 if (size_of_uleb128 (size) != 1)
2094 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2096 if (fde->uses_eh_lsda)
2098 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2099 fde->funcdef_number);
2100 dw2_asm_output_encoded_addr_rtx (
2101 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2102 "Language Specific Data Area");
2106 if (lsda_encoding == DW_EH_PE_aligned)
2107 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2109 (size_of_encoded_value (lsda_encoding), 0,
2110 "Language Specific Data Area (none)");
2114 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2117 /* Loop through the Call Frame Instructions associated with
2119 fde->dw_fde_current_label = fde->dw_fde_begin;
2120 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2121 output_cfi (cfi, fde, for_eh);
2123 /* Pad the FDE out to an address sized boundary. */
2124 ASM_OUTPUT_ALIGN (asm_out_file,
2125 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2126 ASM_OUTPUT_LABEL (asm_out_file, l2);
2129 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2130 dw2_asm_output_data (4, 0, "End of Table");
2131 #ifdef MIPS_DEBUGGING_INFO
2132 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2133 get a value of 0. Putting .align 0 after the label fixes it. */
2134 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2137 /* Turn off app to make assembly quicker. */
2142 /* Output a marker (i.e. a label) for the beginning of a function, before
2146 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2147 const char *file ATTRIBUTE_UNUSED)
2149 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2152 current_function_func_begin_label = 0;
2154 #ifdef IA64_UNWIND_INFO
2155 /* ??? current_function_func_begin_label is also used by except.c
2156 for call-site information. We must emit this label if it might
2158 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2159 && ! dwarf2out_do_frame ())
2162 if (! dwarf2out_do_frame ())
2166 function_section (current_function_decl);
2167 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2168 current_function_funcdef_no);
2169 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2170 current_function_funcdef_no);
2171 current_function_func_begin_label = get_identifier (label);
2173 #ifdef IA64_UNWIND_INFO
2174 /* We can elide the fde allocation if we're not emitting debug info. */
2175 if (! dwarf2out_do_frame ())
2179 /* Expand the fde table if necessary. */
2180 if (fde_table_in_use == fde_table_allocated)
2182 fde_table_allocated += FDE_TABLE_INCREMENT;
2183 fde_table = ggc_realloc (fde_table,
2184 fde_table_allocated * sizeof (dw_fde_node));
2185 memset (fde_table + fde_table_in_use, 0,
2186 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2189 /* Record the FDE associated with this function. */
2190 current_funcdef_fde = fde_table_in_use;
2192 /* Add the new FDE at the end of the fde_table. */
2193 fde = &fde_table[fde_table_in_use++];
2194 fde->dw_fde_begin = xstrdup (label);
2195 fde->dw_fde_current_label = NULL;
2196 fde->dw_fde_end = NULL;
2197 fde->dw_fde_cfi = NULL;
2198 fde->funcdef_number = current_function_funcdef_no;
2199 fde->nothrow = current_function_nothrow;
2200 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2201 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2203 args_size = old_args_size = 0;
2205 /* We only want to output line number information for the genuine dwarf2
2206 prologue case, not the eh frame case. */
2207 #ifdef DWARF2_DEBUGGING_INFO
2209 dwarf2out_source_line (line, file);
2213 /* Output a marker (i.e. a label) for the absolute end of the generated code
2214 for a function definition. This gets called *after* the epilogue code has
2218 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2219 const char *file ATTRIBUTE_UNUSED)
2222 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2224 /* Output a label to mark the endpoint of the code generated for this
2226 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2227 current_function_funcdef_no);
2228 ASM_OUTPUT_LABEL (asm_out_file, label);
2229 fde = &fde_table[fde_table_in_use - 1];
2230 fde->dw_fde_end = xstrdup (label);
2234 dwarf2out_frame_init (void)
2236 /* Allocate the initial hunk of the fde_table. */
2237 fde_table = (dw_fde_ref) ggc_alloc_cleared (FDE_TABLE_INCREMENT
2238 * sizeof (dw_fde_node));
2239 fde_table_allocated = FDE_TABLE_INCREMENT;
2240 fde_table_in_use = 0;
2242 /* Generate the CFA instructions common to all FDE's. Do it now for the
2243 sake of lookup_cfa. */
2245 #ifdef DWARF2_UNWIND_INFO
2246 /* On entry, the Canonical Frame Address is at SP. */
2247 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2248 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2253 dwarf2out_frame_finish (void)
2255 /* Output call frame information. */
2256 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2257 output_call_frame_info (0);
2259 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2260 output_call_frame_info (1);
2264 /* And now, the subset of the debugging information support code necessary
2265 for emitting location expressions. */
2267 /* We need some way to distinguish DW_OP_addr with a direct symbol
2268 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2269 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2272 typedef struct dw_val_struct *dw_val_ref;
2273 typedef struct die_struct *dw_die_ref;
2274 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2275 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2277 /* Each DIE may have a series of attribute/value pairs. Values
2278 can take on several forms. The forms that are used in this
2279 implementation are listed below. */
2284 dw_val_class_offset,
2286 dw_val_class_loc_list,
2287 dw_val_class_range_list,
2289 dw_val_class_unsigned_const,
2290 dw_val_class_long_long,
2293 dw_val_class_die_ref,
2294 dw_val_class_fde_ref,
2295 dw_val_class_lbl_id,
2296 dw_val_class_lbl_offset,
2300 /* Describe a double word constant value. */
2301 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2303 typedef struct dw_long_long_struct GTY(())
2310 /* Describe a floating point constant value. */
2312 typedef struct dw_fp_struct GTY(())
2314 long * GTY((length ("%h.length"))) array;
2319 /* The dw_val_node describes an attribute's value, as it is
2320 represented internally. */
2322 typedef struct dw_val_struct GTY(())
2324 enum dw_val_class val_class;
2325 union dw_val_struct_union
2327 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2328 long unsigned GTY ((tag ("dw_val_class_offset"))) val_offset;
2329 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2330 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2331 long int GTY ((default (""))) val_int;
2332 long unsigned GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2333 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2334 dw_float_const GTY ((tag ("dw_val_class_float"))) val_float;
2335 struct dw_val_die_union
2339 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2340 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2341 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2342 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2343 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2345 GTY ((desc ("%1.val_class"))) v;
2349 /* Locations in memory are described using a sequence of stack machine
2352 typedef struct dw_loc_descr_struct GTY(())
2354 dw_loc_descr_ref dw_loc_next;
2355 enum dwarf_location_atom dw_loc_opc;
2356 dw_val_node dw_loc_oprnd1;
2357 dw_val_node dw_loc_oprnd2;
2362 /* Location lists are ranges + location descriptions for that range,
2363 so you can track variables that are in different places over
2364 their entire life. */
2365 typedef struct dw_loc_list_struct GTY(())
2367 dw_loc_list_ref dw_loc_next;
2368 const char *begin; /* Label for begin address of range */
2369 const char *end; /* Label for end address of range */
2370 char *ll_symbol; /* Label for beginning of location list.
2371 Only on head of list */
2372 const char *section; /* Section this loclist is relative to */
2373 dw_loc_descr_ref expr;
2376 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2378 static const char *dwarf_stack_op_name (unsigned);
2379 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2380 unsigned long, unsigned long);
2381 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2382 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2383 static unsigned long size_of_locs (dw_loc_descr_ref);
2384 static void output_loc_operands (dw_loc_descr_ref);
2385 static void output_loc_sequence (dw_loc_descr_ref);
2387 /* Convert a DWARF stack opcode into its string name. */
2390 dwarf_stack_op_name (unsigned int op)
2395 case INTERNAL_DW_OP_tls_addr:
2396 return "DW_OP_addr";
2398 return "DW_OP_deref";
2400 return "DW_OP_const1u";
2402 return "DW_OP_const1s";
2404 return "DW_OP_const2u";
2406 return "DW_OP_const2s";
2408 return "DW_OP_const4u";
2410 return "DW_OP_const4s";
2412 return "DW_OP_const8u";
2414 return "DW_OP_const8s";
2416 return "DW_OP_constu";
2418 return "DW_OP_consts";
2422 return "DW_OP_drop";
2424 return "DW_OP_over";
2426 return "DW_OP_pick";
2428 return "DW_OP_swap";
2432 return "DW_OP_xderef";
2440 return "DW_OP_minus";
2452 return "DW_OP_plus";
2453 case DW_OP_plus_uconst:
2454 return "DW_OP_plus_uconst";
2460 return "DW_OP_shra";
2478 return "DW_OP_skip";
2480 return "DW_OP_lit0";
2482 return "DW_OP_lit1";
2484 return "DW_OP_lit2";
2486 return "DW_OP_lit3";
2488 return "DW_OP_lit4";
2490 return "DW_OP_lit5";
2492 return "DW_OP_lit6";
2494 return "DW_OP_lit7";
2496 return "DW_OP_lit8";
2498 return "DW_OP_lit9";
2500 return "DW_OP_lit10";
2502 return "DW_OP_lit11";
2504 return "DW_OP_lit12";
2506 return "DW_OP_lit13";
2508 return "DW_OP_lit14";
2510 return "DW_OP_lit15";
2512 return "DW_OP_lit16";
2514 return "DW_OP_lit17";
2516 return "DW_OP_lit18";
2518 return "DW_OP_lit19";
2520 return "DW_OP_lit20";
2522 return "DW_OP_lit21";
2524 return "DW_OP_lit22";
2526 return "DW_OP_lit23";
2528 return "DW_OP_lit24";
2530 return "DW_OP_lit25";
2532 return "DW_OP_lit26";
2534 return "DW_OP_lit27";
2536 return "DW_OP_lit28";
2538 return "DW_OP_lit29";
2540 return "DW_OP_lit30";
2542 return "DW_OP_lit31";
2544 return "DW_OP_reg0";
2546 return "DW_OP_reg1";
2548 return "DW_OP_reg2";
2550 return "DW_OP_reg3";
2552 return "DW_OP_reg4";
2554 return "DW_OP_reg5";
2556 return "DW_OP_reg6";
2558 return "DW_OP_reg7";
2560 return "DW_OP_reg8";
2562 return "DW_OP_reg9";
2564 return "DW_OP_reg10";
2566 return "DW_OP_reg11";
2568 return "DW_OP_reg12";
2570 return "DW_OP_reg13";
2572 return "DW_OP_reg14";
2574 return "DW_OP_reg15";
2576 return "DW_OP_reg16";
2578 return "DW_OP_reg17";
2580 return "DW_OP_reg18";
2582 return "DW_OP_reg19";
2584 return "DW_OP_reg20";
2586 return "DW_OP_reg21";
2588 return "DW_OP_reg22";
2590 return "DW_OP_reg23";
2592 return "DW_OP_reg24";
2594 return "DW_OP_reg25";
2596 return "DW_OP_reg26";
2598 return "DW_OP_reg27";
2600 return "DW_OP_reg28";
2602 return "DW_OP_reg29";
2604 return "DW_OP_reg30";
2606 return "DW_OP_reg31";
2608 return "DW_OP_breg0";
2610 return "DW_OP_breg1";
2612 return "DW_OP_breg2";
2614 return "DW_OP_breg3";
2616 return "DW_OP_breg4";
2618 return "DW_OP_breg5";
2620 return "DW_OP_breg6";
2622 return "DW_OP_breg7";
2624 return "DW_OP_breg8";
2626 return "DW_OP_breg9";
2628 return "DW_OP_breg10";
2630 return "DW_OP_breg11";
2632 return "DW_OP_breg12";
2634 return "DW_OP_breg13";
2636 return "DW_OP_breg14";
2638 return "DW_OP_breg15";
2640 return "DW_OP_breg16";
2642 return "DW_OP_breg17";
2644 return "DW_OP_breg18";
2646 return "DW_OP_breg19";
2648 return "DW_OP_breg20";
2650 return "DW_OP_breg21";
2652 return "DW_OP_breg22";
2654 return "DW_OP_breg23";
2656 return "DW_OP_breg24";
2658 return "DW_OP_breg25";
2660 return "DW_OP_breg26";
2662 return "DW_OP_breg27";
2664 return "DW_OP_breg28";
2666 return "DW_OP_breg29";
2668 return "DW_OP_breg30";
2670 return "DW_OP_breg31";
2672 return "DW_OP_regx";
2674 return "DW_OP_fbreg";
2676 return "DW_OP_bregx";
2678 return "DW_OP_piece";
2679 case DW_OP_deref_size:
2680 return "DW_OP_deref_size";
2681 case DW_OP_xderef_size:
2682 return "DW_OP_xderef_size";
2685 case DW_OP_push_object_address:
2686 return "DW_OP_push_object_address";
2688 return "DW_OP_call2";
2690 return "DW_OP_call4";
2691 case DW_OP_call_ref:
2692 return "DW_OP_call_ref";
2693 case DW_OP_GNU_push_tls_address:
2694 return "DW_OP_GNU_push_tls_address";
2696 return "OP_<unknown>";
2700 /* Return a pointer to a newly allocated location description. Location
2701 descriptions are simple expression terms that can be strung
2702 together to form more complicated location (address) descriptions. */
2704 static inline dw_loc_descr_ref
2705 new_loc_descr (enum dwarf_location_atom op, long unsigned int oprnd1,
2706 long unsigned int oprnd2)
2708 dw_loc_descr_ref descr
2709 = (dw_loc_descr_ref) ggc_alloc_cleared (sizeof (dw_loc_descr_node));
2711 descr->dw_loc_opc = op;
2712 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2713 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2714 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2715 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2721 /* Add a location description term to a location description expression. */
2724 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
2726 dw_loc_descr_ref *d;
2728 /* Find the end of the chain. */
2729 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2735 /* Return the size of a location descriptor. */
2737 static unsigned long
2738 size_of_loc_descr (dw_loc_descr_ref loc)
2740 unsigned long size = 1;
2742 switch (loc->dw_loc_opc)
2745 case INTERNAL_DW_OP_tls_addr:
2746 size += DWARF2_ADDR_SIZE;
2765 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2768 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2773 case DW_OP_plus_uconst:
2774 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2812 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2815 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2818 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2821 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2822 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2825 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2827 case DW_OP_deref_size:
2828 case DW_OP_xderef_size:
2837 case DW_OP_call_ref:
2838 size += DWARF2_ADDR_SIZE;
2847 /* Return the size of a series of location descriptors. */
2849 static unsigned long
2850 size_of_locs (dw_loc_descr_ref loc)
2854 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2856 loc->dw_loc_addr = size;
2857 size += size_of_loc_descr (loc);
2863 /* Output location description stack opcode's operands (if any). */
2866 output_loc_operands (dw_loc_descr_ref loc)
2868 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2869 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2871 switch (loc->dw_loc_opc)
2873 #ifdef DWARF2_DEBUGGING_INFO
2875 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2879 dw2_asm_output_data (2, val1->v.val_int, NULL);
2883 dw2_asm_output_data (4, val1->v.val_int, NULL);
2887 if (HOST_BITS_PER_LONG < 64)
2889 dw2_asm_output_data (8, val1->v.val_int, NULL);
2896 if (val1->val_class == dw_val_class_loc)
2897 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2901 dw2_asm_output_data (2, offset, NULL);
2914 /* We currently don't make any attempt to make sure these are
2915 aligned properly like we do for the main unwind info, so
2916 don't support emitting things larger than a byte if we're
2917 only doing unwinding. */
2922 dw2_asm_output_data (1, val1->v.val_int, NULL);
2925 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2928 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2931 dw2_asm_output_data (1, val1->v.val_int, NULL);
2933 case DW_OP_plus_uconst:
2934 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2968 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2971 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2974 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2977 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2978 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2981 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2983 case DW_OP_deref_size:
2984 case DW_OP_xderef_size:
2985 dw2_asm_output_data (1, val1->v.val_int, NULL);
2988 case INTERNAL_DW_OP_tls_addr:
2989 #ifdef ASM_OUTPUT_DWARF_DTPREL
2990 ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE,
2992 fputc ('\n', asm_out_file);
2999 /* Other codes have no operands. */
3004 /* Output a sequence of location operations. */
3007 output_loc_sequence (dw_loc_descr_ref loc)
3009 for (; loc != NULL; loc = loc->dw_loc_next)
3011 /* Output the opcode. */
3012 dw2_asm_output_data (1, loc->dw_loc_opc,
3013 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3015 /* Output the operand(s) (if any). */
3016 output_loc_operands (loc);
3020 /* This routine will generate the correct assembly data for a location
3021 description based on a cfi entry with a complex address. */
3024 output_cfa_loc (dw_cfi_ref cfi)
3026 dw_loc_descr_ref loc;
3029 /* Output the size of the block. */
3030 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3031 size = size_of_locs (loc);
3032 dw2_asm_output_data_uleb128 (size, NULL);
3034 /* Now output the operations themselves. */
3035 output_loc_sequence (loc);
3038 /* This function builds a dwarf location descriptor sequence from
3039 a dw_cfa_location. */
3041 static struct dw_loc_descr_struct *
3042 build_cfa_loc (dw_cfa_location *cfa)
3044 struct dw_loc_descr_struct *head, *tmp;
3046 if (cfa->indirect == 0)
3049 if (cfa->base_offset)
3052 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3054 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3056 else if (cfa->reg <= 31)
3057 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3059 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3061 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3062 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3063 add_loc_descr (&head, tmp);
3064 if (cfa->offset != 0)
3066 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3067 add_loc_descr (&head, tmp);
3073 /* This function fills in aa dw_cfa_location structure from a dwarf location
3074 descriptor sequence. */
3077 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3079 struct dw_loc_descr_struct *ptr;
3081 cfa->base_offset = 0;
3085 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3087 enum dwarf_location_atom op = ptr->dw_loc_opc;
3123 cfa->reg = op - DW_OP_reg0;
3126 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3160 cfa->reg = op - DW_OP_breg0;
3161 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3164 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3165 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3170 case DW_OP_plus_uconst:
3171 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3174 internal_error ("DW_LOC_OP %s not implemented\n",
3175 dwarf_stack_op_name (ptr->dw_loc_opc));
3179 #endif /* .debug_frame support */
3181 /* And now, the support for symbolic debugging information. */
3182 #ifdef DWARF2_DEBUGGING_INFO
3184 /* .debug_str support. */
3185 static int output_indirect_string (void **, void *);
3187 static void dwarf2out_init (const char *);
3188 static void dwarf2out_finish (const char *);
3189 static void dwarf2out_define (unsigned int, const char *);
3190 static void dwarf2out_undef (unsigned int, const char *);
3191 static void dwarf2out_start_source_file (unsigned, const char *);
3192 static void dwarf2out_end_source_file (unsigned);
3193 static void dwarf2out_begin_block (unsigned, unsigned);
3194 static void dwarf2out_end_block (unsigned, unsigned);
3195 static bool dwarf2out_ignore_block (tree);
3196 static void dwarf2out_global_decl (tree);
3197 static void dwarf2out_abstract_function (tree);
3199 /* The debug hooks structure. */
3201 const struct gcc_debug_hooks dwarf2_debug_hooks =
3207 dwarf2out_start_source_file,
3208 dwarf2out_end_source_file,
3209 dwarf2out_begin_block,
3210 dwarf2out_end_block,
3211 dwarf2out_ignore_block,
3212 dwarf2out_source_line,
3213 dwarf2out_begin_prologue,
3214 debug_nothing_int_charstar, /* end_prologue */
3215 dwarf2out_end_epilogue,
3216 debug_nothing_tree, /* begin_function */
3217 debug_nothing_int, /* end_function */
3218 dwarf2out_decl, /* function_decl */
3219 dwarf2out_global_decl,
3220 debug_nothing_tree, /* deferred_inline_function */
3221 /* The DWARF 2 backend tries to reduce debugging bloat by not
3222 emitting the abstract description of inline functions until
3223 something tries to reference them. */
3224 dwarf2out_abstract_function, /* outlining_inline_function */
3225 debug_nothing_rtx, /* label */
3226 debug_nothing_int /* handle_pch */
3230 /* NOTE: In the comments in this file, many references are made to
3231 "Debugging Information Entries". This term is abbreviated as `DIE'
3232 throughout the remainder of this file. */
3234 /* An internal representation of the DWARF output is built, and then
3235 walked to generate the DWARF debugging info. The walk of the internal
3236 representation is done after the entire program has been compiled.
3237 The types below are used to describe the internal representation. */
3239 /* Various DIE's use offsets relative to the beginning of the
3240 .debug_info section to refer to each other. */
3242 typedef long int dw_offset;
3244 /* Define typedefs here to avoid circular dependencies. */
3246 typedef struct dw_attr_struct *dw_attr_ref;
3247 typedef struct dw_line_info_struct *dw_line_info_ref;
3248 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3249 typedef struct pubname_struct *pubname_ref;
3250 typedef struct dw_ranges_struct *dw_ranges_ref;
3252 /* Each entry in the line_info_table maintains the file and
3253 line number associated with the label generated for that
3254 entry. The label gives the PC value associated with
3255 the line number entry. */
3257 typedef struct dw_line_info_struct GTY(())
3259 unsigned long dw_file_num;
3260 unsigned long dw_line_num;
3264 /* Line information for functions in separate sections; each one gets its
3266 typedef struct dw_separate_line_info_struct GTY(())
3268 unsigned long dw_file_num;
3269 unsigned long dw_line_num;
3270 unsigned long function;
3272 dw_separate_line_info_entry;
3274 /* Each DIE attribute has a field specifying the attribute kind,
3275 a link to the next attribute in the chain, and an attribute value.
3276 Attributes are typically linked below the DIE they modify. */
3278 typedef struct dw_attr_struct GTY(())
3280 enum dwarf_attribute dw_attr;
3281 dw_attr_ref dw_attr_next;
3282 dw_val_node dw_attr_val;
3286 /* The Debugging Information Entry (DIE) structure */
3288 typedef struct die_struct GTY(())
3290 enum dwarf_tag die_tag;
3292 dw_attr_ref die_attr;
3293 dw_die_ref die_parent;
3294 dw_die_ref die_child;
3296 dw_offset die_offset;
3297 unsigned long die_abbrev;
3302 /* The pubname structure */
3304 typedef struct pubname_struct GTY(())
3311 struct dw_ranges_struct GTY(())
3316 /* The limbo die list structure. */
3317 typedef struct limbo_die_struct GTY(())
3321 struct limbo_die_struct *next;
3325 /* How to start an assembler comment. */
3326 #ifndef ASM_COMMENT_START
3327 #define ASM_COMMENT_START ";#"
3330 /* Define a macro which returns nonzero for a TYPE_DECL which was
3331 implicitly generated for a tagged type.
3333 Note that unlike the gcc front end (which generates a NULL named
3334 TYPE_DECL node for each complete tagged type, each array type, and
3335 each function type node created) the g++ front end generates a
3336 _named_ TYPE_DECL node for each tagged type node created.
3337 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3338 generate a DW_TAG_typedef DIE for them. */
3340 #define TYPE_DECL_IS_STUB(decl) \
3341 (DECL_NAME (decl) == NULL_TREE \
3342 || (DECL_ARTIFICIAL (decl) \
3343 && is_tagged_type (TREE_TYPE (decl)) \
3344 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3345 /* This is necessary for stub decls that \
3346 appear in nested inline functions. */ \
3347 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3348 && (decl_ultimate_origin (decl) \
3349 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3351 /* Information concerning the compilation unit's programming
3352 language, and compiler version. */
3354 /* Fixed size portion of the DWARF compilation unit header. */
3355 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3356 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3358 /* Fixed size portion of public names info. */
3359 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3361 /* Fixed size portion of the address range info. */
3362 #define DWARF_ARANGES_HEADER_SIZE \
3363 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3364 DWARF2_ADDR_SIZE * 2) \
3365 - DWARF_INITIAL_LENGTH_SIZE)
3367 /* Size of padding portion in the address range info. It must be
3368 aligned to twice the pointer size. */
3369 #define DWARF_ARANGES_PAD_SIZE \
3370 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3371 DWARF2_ADDR_SIZE * 2) \
3372 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3374 /* Use assembler line directives if available. */
3375 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3376 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3377 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3379 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3383 /* Minimum line offset in a special line info. opcode.
3384 This value was chosen to give a reasonable range of values. */
3385 #define DWARF_LINE_BASE -10
3387 /* First special line opcode - leave room for the standard opcodes. */
3388 #define DWARF_LINE_OPCODE_BASE 10
3390 /* Range of line offsets in a special line info. opcode. */
3391 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3393 /* Flag that indicates the initial value of the is_stmt_start flag.
3394 In the present implementation, we do not mark any lines as
3395 the beginning of a source statement, because that information
3396 is not made available by the GCC front-end. */
3397 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3399 #ifdef DWARF2_DEBUGGING_INFO
3400 /* This location is used by calc_die_sizes() to keep track
3401 the offset of each DIE within the .debug_info section. */
3402 static unsigned long next_die_offset;
3405 /* Record the root of the DIE's built for the current compilation unit. */
3406 static GTY(()) dw_die_ref comp_unit_die;
3408 #ifdef DWARF2_DEBUGGING_INFO
3409 /* We need special handling in dwarf2out_start_source_file if it is
3411 static int is_main_source;
3414 /* A list of DIEs with a NULL parent waiting to be relocated. */
3415 static GTY(()) limbo_die_node *limbo_die_list;
3417 /* Filenames referenced by this compilation unit. */
3418 static GTY(()) varray_type file_table;
3419 static GTY(()) varray_type file_table_emitted;
3420 static GTY(()) size_t file_table_last_lookup_index;
3422 /* A pointer to the base of a table of references to DIE's that describe
3423 declarations. The table is indexed by DECL_UID() which is a unique
3424 number identifying each decl. */
3425 static GTY((length ("decl_die_table_allocated"))) dw_die_ref *decl_die_table;
3427 /* Number of elements currently allocated for the decl_die_table. */
3428 static GTY(()) unsigned decl_die_table_allocated;
3430 /* Number of elements in decl_die_table currently in use. */
3431 static GTY(()) unsigned decl_die_table_in_use;
3433 /* Size (in elements) of increments by which we may expand the
3435 #define DECL_DIE_TABLE_INCREMENT 256
3437 /* A pointer to the base of a list of references to DIE's that
3438 are uniquely identified by their tag, presence/absence of
3439 children DIE's, and list of attribute/value pairs. */
3440 static GTY((length ("abbrev_die_table_allocated")))
3441 dw_die_ref *abbrev_die_table;
3443 /* Number of elements currently allocated for abbrev_die_table. */
3444 static GTY(()) unsigned abbrev_die_table_allocated;
3446 /* Number of elements in type_die_table currently in use. */
3447 static GTY(()) unsigned abbrev_die_table_in_use;
3449 /* Size (in elements) of increments by which we may expand the
3450 abbrev_die_table. */
3451 #define ABBREV_DIE_TABLE_INCREMENT 256
3453 /* A pointer to the base of a table that contains line information
3454 for each source code line in .text in the compilation unit. */
3455 static GTY((length ("line_info_table_allocated")))
3456 dw_line_info_ref line_info_table;
3458 /* Number of elements currently allocated for line_info_table. */
3459 static GTY(()) unsigned line_info_table_allocated;
3461 /* Number of elements in line_info_table currently in use. */
3462 static GTY(()) unsigned line_info_table_in_use;
3464 /* A pointer to the base of a table that contains line information
3465 for each source code line outside of .text in the compilation unit. */
3466 static GTY ((length ("separate_line_info_table_allocated")))
3467 dw_separate_line_info_ref separate_line_info_table;
3469 /* Number of elements currently allocated for separate_line_info_table. */
3470 static GTY(()) unsigned separate_line_info_table_allocated;
3472 /* Number of elements in separate_line_info_table currently in use. */
3473 static GTY(()) unsigned separate_line_info_table_in_use;
3475 /* Size (in elements) of increments by which we may expand the
3477 #define LINE_INFO_TABLE_INCREMENT 1024
3479 /* A pointer to the base of a table that contains a list of publicly
3480 accessible names. */
3481 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table;
3483 /* Number of elements currently allocated for pubname_table. */
3484 static GTY(()) unsigned pubname_table_allocated;
3486 /* Number of elements in pubname_table currently in use. */
3487 static GTY(()) unsigned pubname_table_in_use;
3489 /* Size (in elements) of increments by which we may expand the
3491 #define PUBNAME_TABLE_INCREMENT 64
3493 /* Array of dies for which we should generate .debug_arange info. */
3494 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
3496 /* Number of elements currently allocated for arange_table. */
3497 static GTY(()) unsigned arange_table_allocated;
3499 /* Number of elements in arange_table currently in use. */
3500 static GTY(()) unsigned arange_table_in_use;
3502 /* Size (in elements) of increments by which we may expand the
3504 #define ARANGE_TABLE_INCREMENT 64
3506 /* Array of dies for which we should generate .debug_ranges info. */
3507 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3509 /* Number of elements currently allocated for ranges_table. */
3510 static GTY(()) unsigned ranges_table_allocated;
3512 /* Number of elements in ranges_table currently in use. */
3513 static GTY(()) unsigned ranges_table_in_use;
3515 /* Size (in elements) of increments by which we may expand the
3517 #define RANGES_TABLE_INCREMENT 64
3519 /* Whether we have location lists that need outputting */
3520 static GTY(()) unsigned have_location_lists;
3522 #ifdef DWARF2_DEBUGGING_INFO
3523 /* Record whether the function being analyzed contains inlined functions. */
3524 static int current_function_has_inlines;
3526 #if 0 && defined (MIPS_DEBUGGING_INFO)
3527 static int comp_unit_has_inlines;
3530 /* Number of file tables emitted in maybe_emit_file(). */
3531 static GTY(()) int emitcount = 0;
3533 /* Number of internal labels generated by gen_internal_sym(). */
3534 static GTY(()) int label_num;
3536 #ifdef DWARF2_DEBUGGING_INFO
3538 /* Forward declarations for functions defined in this file. */
3540 static int is_pseudo_reg (rtx);
3541 static tree type_main_variant (tree);
3542 static int is_tagged_type (tree);
3543 static const char *dwarf_tag_name (unsigned);
3544 static const char *dwarf_attr_name (unsigned);
3545 static const char *dwarf_form_name (unsigned);
3547 static const char *dwarf_type_encoding_name (unsigned);
3549 static tree decl_ultimate_origin (tree);
3550 static tree block_ultimate_origin (tree);
3551 static tree decl_class_context (tree);
3552 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3553 static inline enum dw_val_class AT_class (dw_attr_ref);
3554 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3555 static inline unsigned AT_flag (dw_attr_ref);
3556 static void add_AT_int (dw_die_ref, enum dwarf_attribute, long);
3557 static inline long int AT_int (dw_attr_ref);
3558 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned long);
3559 static inline unsigned long AT_unsigned (dw_attr_ref);
3560 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
3562 static void add_AT_float (dw_die_ref, enum dwarf_attribute, unsigned, long *);
3563 static hashval_t debug_str_do_hash (const void *);
3564 static int debug_str_eq (const void *, const void *);
3565 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3566 static inline const char *AT_string (dw_attr_ref);
3567 static int AT_string_form (dw_attr_ref);
3568 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3569 static inline dw_die_ref AT_ref (dw_attr_ref);
3570 static inline int AT_ref_external (dw_attr_ref);
3571 static inline void set_AT_ref_external (dw_attr_ref, int);
3572 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3573 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3574 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3575 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3577 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3578 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3579 static inline rtx AT_addr (dw_attr_ref);
3580 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3581 static void add_AT_lbl_offset (dw_die_ref, enum dwarf_attribute, const char *);
3582 static void add_AT_offset (dw_die_ref, enum dwarf_attribute, unsigned long);
3583 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3585 static inline const char *AT_lbl (dw_attr_ref);
3586 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3587 static const char *get_AT_low_pc (dw_die_ref);
3588 static const char *get_AT_hi_pc (dw_die_ref);
3589 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3590 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3591 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3592 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3593 static bool is_c_family (void);
3594 static bool is_cxx (void);
3595 static bool is_java (void);
3596 static bool is_fortran (void);
3597 static bool is_ada (void);
3598 static void remove_AT (dw_die_ref, enum dwarf_attribute);
3599 static inline void free_die (dw_die_ref);
3600 static void remove_children (dw_die_ref);
3601 static void add_child_die (dw_die_ref, dw_die_ref);
3602 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3603 static dw_die_ref lookup_type_die (tree);
3604 static void equate_type_number_to_die (tree, dw_die_ref);
3605 static dw_die_ref lookup_decl_die (tree);
3606 static void equate_decl_number_to_die (tree, dw_die_ref);
3607 static void print_spaces (FILE *);
3608 static void print_die (dw_die_ref, FILE *);
3609 static void print_dwarf_line_table (FILE *);
3610 static void reverse_die_lists (dw_die_ref);
3611 static void reverse_all_dies (dw_die_ref);
3612 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3613 static dw_die_ref pop_compile_unit (dw_die_ref);
3614 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3615 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3616 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3617 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3618 static int same_dw_val_p (dw_val_node *, dw_val_node *, int *);
3619 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3620 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3621 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3622 static void compute_section_prefix (dw_die_ref);
3623 static int is_type_die (dw_die_ref);
3624 static int is_comdat_die (dw_die_ref);
3625 static int is_symbol_die (dw_die_ref);
3626 static void assign_symbol_names (dw_die_ref);
3627 static void break_out_includes (dw_die_ref);
3628 static hashval_t htab_cu_hash (const void *);
3629 static int htab_cu_eq (const void *, const void *);
3630 static void htab_cu_del (void *);
3631 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
3632 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
3633 static void add_sibling_attributes (dw_die_ref);
3634 static void build_abbrev_table (dw_di