1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* TODO: Emit .debug_line header even when there are no functions, since
25 the file numbers are used by .debug_info. Alternately, leave
26 out locations for types and decls.
27 Avoid talking about ctors and op= for PODs.
28 Factor out common prologue sequences into multiple CIEs. */
30 /* The first part of this file deals with the DWARF 2 frame unwind
31 information, which is also used by the GCC efficient exception handling
32 mechanism. The second part, controlled only by an #ifdef
33 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 /* DWARF2 Abbreviation Glossary:
38 CFA = Canonical Frame Address
39 a fixed address on the stack which identifies a call frame.
40 We define it to be the value of SP just before the call insn.
41 The CFA register and offset, which may change during the course
42 of the function, are used to calculate its value at runtime.
44 CFI = Call Frame Instruction
45 an instruction for the DWARF2 abstract machine
47 CIE = Common Information Entry
48 information describing information common to one or more FDEs
50 DIE = Debugging Information Entry
52 FDE = Frame Description Entry
53 information describing the stack call frame, in particular,
54 how to restore registers
56 DW_CFA_... = DWARF2 CFA call frame instruction
57 DW_TAG_... = DWARF2 DIE tag */
61 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
85 #include "diagnostic.h"
88 #include "langhooks.h"
93 #ifdef DWARF2_DEBUGGING_INFO
94 static void dwarf2out_source_line (unsigned int, const char *);
97 #ifndef DWARF2_FRAME_INFO
98 # ifdef DWARF2_DEBUGGING_INFO
99 # define DWARF2_FRAME_INFO \
100 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
102 # define DWARF2_FRAME_INFO 0
106 /* Map register numbers held in the call frame info that gcc has
107 collected using DWARF_FRAME_REGNUM to those that should be output in
108 .debug_frame and .eh_frame. */
109 #ifndef DWARF2_FRAME_REG_OUT
110 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
113 /* Decide whether we want to emit frame unwind information for the current
117 dwarf2out_do_frame (void)
119 /* We want to emit correct CFA location expressions or lists, so we
120 have to return true if we're going to output debug info, even if
121 we're not going to output frame or unwind info. */
122 return (write_symbols == DWARF2_DEBUG
123 || write_symbols == VMS_AND_DWARF2_DEBUG
125 #ifdef DWARF2_UNWIND_INFO
126 || (DWARF2_UNWIND_INFO
127 && (flag_unwind_tables
128 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
133 /* The size of the target's pointer type. */
135 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
138 /* Array of RTXes referenced by the debugging information, which therefore
139 must be kept around forever. */
140 static GTY(()) VEC(rtx,gc) *used_rtx_array;
142 /* A pointer to the base of a list of incomplete types which might be
143 completed at some later time. incomplete_types_list needs to be a
144 VEC(tree,gc) because we want to tell the garbage collector about
146 static GTY(()) VEC(tree,gc) *incomplete_types;
148 /* A pointer to the base of a table of references to declaration
149 scopes. This table is a display which tracks the nesting
150 of declaration scopes at the current scope and containing
151 scopes. This table is used to find the proper place to
152 define type declaration DIE's. */
153 static GTY(()) VEC(tree,gc) *decl_scope_table;
155 /* Pointers to various DWARF2 sections. */
156 static GTY(()) section *debug_info_section;
157 static GTY(()) section *debug_abbrev_section;
158 static GTY(()) section *debug_aranges_section;
159 static GTY(()) section *debug_macinfo_section;
160 static GTY(()) section *debug_line_section;
161 static GTY(()) section *debug_loc_section;
162 static GTY(()) section *debug_pubnames_section;
163 static GTY(()) section *debug_pubtypes_section;
164 static GTY(()) section *debug_str_section;
165 static GTY(()) section *debug_ranges_section;
166 static GTY(()) section *debug_frame_section;
168 /* How to start an assembler comment. */
169 #ifndef ASM_COMMENT_START
170 #define ASM_COMMENT_START ";#"
173 typedef struct dw_cfi_struct *dw_cfi_ref;
174 typedef struct dw_fde_struct *dw_fde_ref;
175 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
177 /* Call frames are described using a sequence of Call Frame
178 Information instructions. The register number, offset
179 and address fields are provided as possible operands;
180 their use is selected by the opcode field. */
182 enum dw_cfi_oprnd_type {
184 dw_cfi_oprnd_reg_num,
190 typedef union dw_cfi_oprnd_struct GTY(())
192 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
193 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
194 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
195 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
199 typedef struct dw_cfi_struct GTY(())
201 dw_cfi_ref dw_cfi_next;
202 enum dwarf_call_frame_info dw_cfi_opc;
203 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
205 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
210 /* This is how we define the location of the CFA. We use to handle it
211 as REG + OFFSET all the time, but now it can be more complex.
212 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
213 Instead of passing around REG and OFFSET, we pass a copy
214 of this structure. */
215 typedef struct cfa_loc GTY(())
217 HOST_WIDE_INT offset;
218 HOST_WIDE_INT base_offset;
220 int indirect; /* 1 if CFA is accessed via a dereference. */
223 /* All call frame descriptions (FDE's) in the GCC generated DWARF
224 refer to a single Common Information Entry (CIE), defined at
225 the beginning of the .debug_frame section. This use of a single
226 CIE obviates the need to keep track of multiple CIE's
227 in the DWARF generation routines below. */
229 typedef struct dw_fde_struct GTY(())
232 const char *dw_fde_begin;
233 const char *dw_fde_current_label;
234 const char *dw_fde_end;
235 const char *dw_fde_hot_section_label;
236 const char *dw_fde_hot_section_end_label;
237 const char *dw_fde_unlikely_section_label;
238 const char *dw_fde_unlikely_section_end_label;
239 bool dw_fde_switched_sections;
240 dw_cfi_ref dw_fde_cfi;
241 unsigned funcdef_number;
242 unsigned all_throwers_are_sibcalls : 1;
243 unsigned nothrow : 1;
244 unsigned uses_eh_lsda : 1;
248 /* Maximum size (in bytes) of an artificially generated label. */
249 #define MAX_ARTIFICIAL_LABEL_BYTES 30
251 /* The size of addresses as they appear in the Dwarf 2 data.
252 Some architectures use word addresses to refer to code locations,
253 but Dwarf 2 info always uses byte addresses. On such machines,
254 Dwarf 2 addresses need to be larger than the architecture's
256 #ifndef DWARF2_ADDR_SIZE
257 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
260 /* The size in bytes of a DWARF field indicating an offset or length
261 relative to a debug info section, specified to be 4 bytes in the
262 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
265 #ifndef DWARF_OFFSET_SIZE
266 #define DWARF_OFFSET_SIZE 4
269 /* According to the (draft) DWARF 3 specification, the initial length
270 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
271 bytes are 0xffffffff, followed by the length stored in the next 8
274 However, the SGI/MIPS ABI uses an initial length which is equal to
275 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
277 #ifndef DWARF_INITIAL_LENGTH_SIZE
278 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
281 #define DWARF_VERSION 2
283 /* Round SIZE up to the nearest BOUNDARY. */
284 #define DWARF_ROUND(SIZE,BOUNDARY) \
285 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
287 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
288 #ifndef DWARF_CIE_DATA_ALIGNMENT
289 #ifdef STACK_GROWS_DOWNWARD
290 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
292 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
296 /* CIE identifier. */
297 #if HOST_BITS_PER_WIDE_INT >= 64
298 #define DWARF_CIE_ID \
299 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
301 #define DWARF_CIE_ID DW_CIE_ID
304 /* A pointer to the base of a table that contains frame description
305 information for each routine. */
306 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
308 /* Number of elements currently allocated for fde_table. */
309 static GTY(()) unsigned fde_table_allocated;
311 /* Number of elements in fde_table currently in use. */
312 static GTY(()) unsigned fde_table_in_use;
314 /* Size (in elements) of increments by which we may expand the
316 #define FDE_TABLE_INCREMENT 256
318 /* A list of call frame insns for the CIE. */
319 static GTY(()) dw_cfi_ref cie_cfi_head;
321 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
322 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
323 attribute that accelerates the lookup of the FDE associated
324 with the subprogram. This variable holds the table index of the FDE
325 associated with the current function (body) definition. */
326 static unsigned current_funcdef_fde;
329 struct indirect_string_node GTY(())
332 unsigned int refcount;
337 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
339 static GTY(()) int dw2_string_counter;
340 static GTY(()) unsigned long dwarf2out_cfi_label_num;
342 /* True if the compilation unit places functions in more than one section. */
343 static GTY(()) bool have_multiple_function_sections = false;
345 /* Whether the default text and cold text sections have been used at all. */
347 static GTY(()) bool text_section_used = false;
348 static GTY(()) bool cold_text_section_used = false;
350 /* The default cold text section. */
351 static GTY(()) section *cold_text_section;
353 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
355 /* Forward declarations for functions defined in this file. */
357 static char *stripattributes (const char *);
358 static const char *dwarf_cfi_name (unsigned);
359 static dw_cfi_ref new_cfi (void);
360 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
361 static void add_fde_cfi (const char *, dw_cfi_ref);
362 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
363 static void lookup_cfa (dw_cfa_location *);
364 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
365 #ifdef DWARF2_UNWIND_INFO
366 static void initial_return_save (rtx);
368 static HOST_WIDE_INT stack_adjust_offset (const_rtx);
369 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
370 static void output_call_frame_info (int);
371 static void dwarf2out_note_section_used (void);
372 static void dwarf2out_stack_adjust (rtx, bool);
373 static void flush_queued_reg_saves (void);
374 static bool clobbers_queued_reg_save (const_rtx);
375 static void dwarf2out_frame_debug_expr (rtx, const char *);
377 /* Support for complex CFA locations. */
378 static void output_cfa_loc (dw_cfi_ref);
379 static void get_cfa_from_loc_descr (dw_cfa_location *,
380 struct dw_loc_descr_struct *);
381 static struct dw_loc_descr_struct *build_cfa_loc
382 (dw_cfa_location *, HOST_WIDE_INT);
383 static void def_cfa_1 (const char *, dw_cfa_location *);
385 /* How to start an assembler comment. */
386 #ifndef ASM_COMMENT_START
387 #define ASM_COMMENT_START ";#"
390 /* Data and reference forms for relocatable data. */
391 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
392 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
394 #ifndef DEBUG_FRAME_SECTION
395 #define DEBUG_FRAME_SECTION ".debug_frame"
398 #ifndef FUNC_BEGIN_LABEL
399 #define FUNC_BEGIN_LABEL "LFB"
402 #ifndef FUNC_END_LABEL
403 #define FUNC_END_LABEL "LFE"
406 #ifndef FRAME_BEGIN_LABEL
407 #define FRAME_BEGIN_LABEL "Lframe"
409 #define CIE_AFTER_SIZE_LABEL "LSCIE"
410 #define CIE_END_LABEL "LECIE"
411 #define FDE_LABEL "LSFDE"
412 #define FDE_AFTER_SIZE_LABEL "LASFDE"
413 #define FDE_END_LABEL "LEFDE"
414 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
415 #define LINE_NUMBER_END_LABEL "LELT"
416 #define LN_PROLOG_AS_LABEL "LASLTP"
417 #define LN_PROLOG_END_LABEL "LELTP"
418 #define DIE_LABEL_PREFIX "DW"
420 /* The DWARF 2 CFA column which tracks the return address. Normally this
421 is the column for PC, or the first column after all of the hard
423 #ifndef DWARF_FRAME_RETURN_COLUMN
425 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
427 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
431 /* The mapping from gcc register number to DWARF 2 CFA column number. By
432 default, we just provide columns for all registers. */
433 #ifndef DWARF_FRAME_REGNUM
434 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
437 /* Hook used by __throw. */
440 expand_builtin_dwarf_sp_column (void)
442 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
443 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
446 /* Return a pointer to a copy of the section string name S with all
447 attributes stripped off, and an asterisk prepended (for assemble_name). */
450 stripattributes (const char *s)
452 char *stripped = XNEWVEC (char, strlen (s) + 2);
457 while (*s && *s != ',')
464 /* MEM is a memory reference for the register size table, each element of
465 which has mode MODE. Initialize column C as a return address column. */
468 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
470 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
471 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
472 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
475 /* Generate code to initialize the register size table. */
478 expand_builtin_init_dwarf_reg_sizes (tree address)
481 enum machine_mode mode = TYPE_MODE (char_type_node);
482 rtx addr = expand_normal (address);
483 rtx mem = gen_rtx_MEM (BLKmode, addr);
484 bool wrote_return_column = false;
486 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
488 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
490 if (rnum < DWARF_FRAME_REGISTERS)
492 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
493 enum machine_mode save_mode = reg_raw_mode[i];
496 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
497 save_mode = choose_hard_reg_mode (i, 1, true);
498 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
500 if (save_mode == VOIDmode)
502 wrote_return_column = true;
504 size = GET_MODE_SIZE (save_mode);
508 emit_move_insn (adjust_address (mem, mode, offset),
509 gen_int_mode (size, mode));
513 if (!wrote_return_column)
514 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
516 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
517 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
520 targetm.init_dwarf_reg_sizes_extra (address);
523 /* Convert a DWARF call frame info. operation to its string name */
526 dwarf_cfi_name (unsigned int cfi_opc)
530 case DW_CFA_advance_loc:
531 return "DW_CFA_advance_loc";
533 return "DW_CFA_offset";
535 return "DW_CFA_restore";
539 return "DW_CFA_set_loc";
540 case DW_CFA_advance_loc1:
541 return "DW_CFA_advance_loc1";
542 case DW_CFA_advance_loc2:
543 return "DW_CFA_advance_loc2";
544 case DW_CFA_advance_loc4:
545 return "DW_CFA_advance_loc4";
546 case DW_CFA_offset_extended:
547 return "DW_CFA_offset_extended";
548 case DW_CFA_restore_extended:
549 return "DW_CFA_restore_extended";
550 case DW_CFA_undefined:
551 return "DW_CFA_undefined";
552 case DW_CFA_same_value:
553 return "DW_CFA_same_value";
554 case DW_CFA_register:
555 return "DW_CFA_register";
556 case DW_CFA_remember_state:
557 return "DW_CFA_remember_state";
558 case DW_CFA_restore_state:
559 return "DW_CFA_restore_state";
561 return "DW_CFA_def_cfa";
562 case DW_CFA_def_cfa_register:
563 return "DW_CFA_def_cfa_register";
564 case DW_CFA_def_cfa_offset:
565 return "DW_CFA_def_cfa_offset";
568 case DW_CFA_def_cfa_expression:
569 return "DW_CFA_def_cfa_expression";
570 case DW_CFA_expression:
571 return "DW_CFA_expression";
572 case DW_CFA_offset_extended_sf:
573 return "DW_CFA_offset_extended_sf";
574 case DW_CFA_def_cfa_sf:
575 return "DW_CFA_def_cfa_sf";
576 case DW_CFA_def_cfa_offset_sf:
577 return "DW_CFA_def_cfa_offset_sf";
579 /* SGI/MIPS specific */
580 case DW_CFA_MIPS_advance_loc8:
581 return "DW_CFA_MIPS_advance_loc8";
584 case DW_CFA_GNU_window_save:
585 return "DW_CFA_GNU_window_save";
586 case DW_CFA_GNU_args_size:
587 return "DW_CFA_GNU_args_size";
588 case DW_CFA_GNU_negative_offset_extended:
589 return "DW_CFA_GNU_negative_offset_extended";
592 return "DW_CFA_<unknown>";
596 /* Return a pointer to a newly allocated Call Frame Instruction. */
598 static inline dw_cfi_ref
601 dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node));
603 cfi->dw_cfi_next = NULL;
604 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
605 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
610 /* Add a Call Frame Instruction to list of instructions. */
613 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
617 /* Find the end of the chain. */
618 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
624 /* Generate a new label for the CFI info to refer to. */
627 dwarf2out_cfi_label (void)
629 static char label[20];
631 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
632 ASM_OUTPUT_LABEL (asm_out_file, label);
636 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
637 or to the CIE if LABEL is NULL. */
640 add_fde_cfi (const char *label, dw_cfi_ref cfi)
644 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
647 label = dwarf2out_cfi_label ();
649 if (fde->dw_fde_current_label == NULL
650 || strcmp (label, fde->dw_fde_current_label) != 0)
654 label = xstrdup (label);
656 /* Set the location counter to the new label. */
658 /* If we have a current label, advance from there, otherwise
659 set the location directly using set_loc. */
660 xcfi->dw_cfi_opc = fde->dw_fde_current_label
661 ? DW_CFA_advance_loc4
663 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
664 add_cfi (&fde->dw_fde_cfi, xcfi);
666 fde->dw_fde_current_label = label;
669 add_cfi (&fde->dw_fde_cfi, cfi);
673 add_cfi (&cie_cfi_head, cfi);
676 /* Subroutine of lookup_cfa. */
679 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
681 switch (cfi->dw_cfi_opc)
683 case DW_CFA_def_cfa_offset:
684 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
686 case DW_CFA_def_cfa_offset_sf:
688 = cfi->dw_cfi_oprnd1.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
690 case DW_CFA_def_cfa_register:
691 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
694 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
695 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
697 case DW_CFA_def_cfa_sf:
698 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
700 = cfi->dw_cfi_oprnd2.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
702 case DW_CFA_def_cfa_expression:
703 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
710 /* Find the previous value for the CFA. */
713 lookup_cfa (dw_cfa_location *loc)
717 loc->reg = INVALID_REGNUM;
720 loc->base_offset = 0;
722 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
723 lookup_cfa_1 (cfi, loc);
725 if (fde_table_in_use)
727 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
728 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
729 lookup_cfa_1 (cfi, loc);
733 /* The current rule for calculating the DWARF2 canonical frame address. */
734 static dw_cfa_location cfa;
736 /* The register used for saving registers to the stack, and its offset
738 static dw_cfa_location cfa_store;
740 /* The running total of the size of arguments pushed onto the stack. */
741 static HOST_WIDE_INT args_size;
743 /* The last args_size we actually output. */
744 static HOST_WIDE_INT old_args_size;
746 /* Entry point to update the canonical frame address (CFA).
747 LABEL is passed to add_fde_cfi. The value of CFA is now to be
748 calculated from REG+OFFSET. */
751 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
758 def_cfa_1 (label, &loc);
761 /* Determine if two dw_cfa_location structures define the same data. */
764 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
766 return (loc1->reg == loc2->reg
767 && loc1->offset == loc2->offset
768 && loc1->indirect == loc2->indirect
769 && (loc1->indirect == 0
770 || loc1->base_offset == loc2->base_offset));
773 /* This routine does the actual work. The CFA is now calculated from
774 the dw_cfa_location structure. */
777 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
780 dw_cfa_location old_cfa, loc;
785 if (cfa_store.reg == loc.reg && loc.indirect == 0)
786 cfa_store.offset = loc.offset;
788 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
789 lookup_cfa (&old_cfa);
791 /* If nothing changed, no need to issue any call frame instructions. */
792 if (cfa_equal_p (&loc, &old_cfa))
797 if (loc.reg == old_cfa.reg && !loc.indirect)
799 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
800 the CFA register did not change but the offset did. */
803 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
804 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
806 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
807 cfi->dw_cfi_oprnd1.dw_cfi_offset = f_offset;
811 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
812 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
816 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
817 else if (loc.offset == old_cfa.offset
818 && old_cfa.reg != INVALID_REGNUM
821 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
822 indicating the CFA register has changed to <register> but the
823 offset has not changed. */
824 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
825 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
829 else if (loc.indirect == 0)
831 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
832 indicating the CFA register has changed to <register> with
833 the specified offset. */
836 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
837 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
839 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
840 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
841 cfi->dw_cfi_oprnd2.dw_cfi_offset = f_offset;
845 cfi->dw_cfi_opc = DW_CFA_def_cfa;
846 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
847 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
852 /* Construct a DW_CFA_def_cfa_expression instruction to
853 calculate the CFA using a full location expression since no
854 register-offset pair is available. */
855 struct dw_loc_descr_struct *loc_list;
857 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
858 loc_list = build_cfa_loc (&loc, 0);
859 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
862 add_fde_cfi (label, cfi);
865 /* Add the CFI for saving a register. REG is the CFA column number.
866 LABEL is passed to add_fde_cfi.
867 If SREG is -1, the register is saved at OFFSET from the CFA;
868 otherwise it is saved in SREG. */
871 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
873 dw_cfi_ref cfi = new_cfi ();
875 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
877 if (sreg == INVALID_REGNUM)
880 /* The register number won't fit in 6 bits, so we have to use
882 cfi->dw_cfi_opc = DW_CFA_offset_extended;
884 cfi->dw_cfi_opc = DW_CFA_offset;
886 #ifdef ENABLE_CHECKING
888 /* If we get an offset that is not a multiple of
889 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
890 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
892 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
894 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
897 offset /= DWARF_CIE_DATA_ALIGNMENT;
899 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
901 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
903 else if (sreg == reg)
904 cfi->dw_cfi_opc = DW_CFA_same_value;
907 cfi->dw_cfi_opc = DW_CFA_register;
908 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
911 add_fde_cfi (label, cfi);
914 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
915 This CFI tells the unwinder that it needs to restore the window registers
916 from the previous frame's window save area.
918 ??? Perhaps we should note in the CIE where windows are saved (instead of
919 assuming 0(cfa)) and what registers are in the window. */
922 dwarf2out_window_save (const char *label)
924 dw_cfi_ref cfi = new_cfi ();
926 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
927 add_fde_cfi (label, cfi);
930 /* Add a CFI to update the running total of the size of arguments
931 pushed onto the stack. */
934 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
938 if (size == old_args_size)
941 old_args_size = size;
944 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
945 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
946 add_fde_cfi (label, cfi);
949 /* Entry point for saving a register to the stack. REG is the GCC register
950 number. LABEL and OFFSET are passed to reg_save. */
953 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
955 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
958 /* Entry point for saving the return address in the stack.
959 LABEL and OFFSET are passed to reg_save. */
962 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
964 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
967 /* Entry point for saving the return address in a register.
968 LABEL and SREG are passed to reg_save. */
971 dwarf2out_return_reg (const char *label, unsigned int sreg)
973 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
976 #ifdef DWARF2_UNWIND_INFO
977 /* Record the initial position of the return address. RTL is
978 INCOMING_RETURN_ADDR_RTX. */
981 initial_return_save (rtx rtl)
983 unsigned int reg = INVALID_REGNUM;
984 HOST_WIDE_INT offset = 0;
986 switch (GET_CODE (rtl))
989 /* RA is in a register. */
990 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
994 /* RA is on the stack. */
996 switch (GET_CODE (rtl))
999 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1004 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1005 offset = INTVAL (XEXP (rtl, 1));
1009 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1010 offset = -INTVAL (XEXP (rtl, 1));
1020 /* The return address is at some offset from any value we can
1021 actually load. For instance, on the SPARC it is in %i7+8. Just
1022 ignore the offset for now; it doesn't matter for unwinding frames. */
1023 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1024 initial_return_save (XEXP (rtl, 0));
1031 if (reg != DWARF_FRAME_RETURN_COLUMN)
1032 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1036 /* Given a SET, calculate the amount of stack adjustment it
1039 static HOST_WIDE_INT
1040 stack_adjust_offset (const_rtx pattern)
1042 const_rtx src = SET_SRC (pattern);
1043 const_rtx dest = SET_DEST (pattern);
1044 HOST_WIDE_INT offset = 0;
1047 if (dest == stack_pointer_rtx)
1049 /* (set (reg sp) (plus (reg sp) (const_int))) */
1050 code = GET_CODE (src);
1051 if (! (code == PLUS || code == MINUS)
1052 || XEXP (src, 0) != stack_pointer_rtx
1053 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1056 offset = INTVAL (XEXP (src, 1));
1060 else if (MEM_P (dest))
1062 /* (set (mem (pre_dec (reg sp))) (foo)) */
1063 src = XEXP (dest, 0);
1064 code = GET_CODE (src);
1070 if (XEXP (src, 0) == stack_pointer_rtx)
1072 rtx val = XEXP (XEXP (src, 1), 1);
1073 /* We handle only adjustments by constant amount. */
1074 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1075 && GET_CODE (val) == CONST_INT);
1076 offset = -INTVAL (val);
1083 if (XEXP (src, 0) == stack_pointer_rtx)
1085 offset = GET_MODE_SIZE (GET_MODE (dest));
1092 if (XEXP (src, 0) == stack_pointer_rtx)
1094 offset = -GET_MODE_SIZE (GET_MODE (dest));
1109 /* Check INSN to see if it looks like a push or a stack adjustment, and
1110 make a note of it if it does. EH uses this information to find out how
1111 much extra space it needs to pop off the stack. */
1114 dwarf2out_stack_adjust (rtx insn, bool after_p)
1116 HOST_WIDE_INT offset;
1120 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1121 with this function. Proper support would require all frame-related
1122 insns to be marked, and to be able to handle saving state around
1123 epilogues textually in the middle of the function. */
1124 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1127 /* If only calls can throw, and we have a frame pointer,
1128 save up adjustments until we see the CALL_INSN. */
1129 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1131 if (CALL_P (insn) && !after_p)
1133 /* Extract the size of the args from the CALL rtx itself. */
1134 insn = PATTERN (insn);
1135 if (GET_CODE (insn) == PARALLEL)
1136 insn = XVECEXP (insn, 0, 0);
1137 if (GET_CODE (insn) == SET)
1138 insn = SET_SRC (insn);
1139 gcc_assert (GET_CODE (insn) == CALL);
1140 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1145 if (CALL_P (insn) && !after_p)
1147 if (!flag_asynchronous_unwind_tables)
1148 dwarf2out_args_size ("", args_size);
1151 else if (BARRIER_P (insn))
1153 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1154 the compiler will have already emitted a stack adjustment, but
1155 doesn't bother for calls to noreturn functions. */
1156 #ifdef STACK_GROWS_DOWNWARD
1157 offset = -args_size;
1162 else if (GET_CODE (PATTERN (insn)) == SET)
1163 offset = stack_adjust_offset (PATTERN (insn));
1164 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1165 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1167 /* There may be stack adjustments inside compound insns. Search
1169 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1170 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1171 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1179 if (cfa.reg == STACK_POINTER_REGNUM)
1180 cfa.offset += offset;
1182 #ifndef STACK_GROWS_DOWNWARD
1186 args_size += offset;
1190 label = dwarf2out_cfi_label ();
1191 def_cfa_1 (label, &cfa);
1192 if (flag_asynchronous_unwind_tables)
1193 dwarf2out_args_size (label, args_size);
1198 /* We delay emitting a register save until either (a) we reach the end
1199 of the prologue or (b) the register is clobbered. This clusters
1200 register saves so that there are fewer pc advances. */
1202 struct queued_reg_save GTY(())
1204 struct queued_reg_save *next;
1206 HOST_WIDE_INT cfa_offset;
1210 static GTY(()) struct queued_reg_save *queued_reg_saves;
1212 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1213 struct reg_saved_in_data GTY(()) {
1218 /* A list of registers saved in other registers.
1219 The list intentionally has a small maximum capacity of 4; if your
1220 port needs more than that, you might consider implementing a
1221 more efficient data structure. */
1222 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1223 static GTY(()) size_t num_regs_saved_in_regs;
1225 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1226 static const char *last_reg_save_label;
1228 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1229 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1232 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1234 struct queued_reg_save *q;
1236 /* Duplicates waste space, but it's also necessary to remove them
1237 for correctness, since the queue gets output in reverse
1239 for (q = queued_reg_saves; q != NULL; q = q->next)
1240 if (REGNO (q->reg) == REGNO (reg))
1245 q = ggc_alloc (sizeof (*q));
1246 q->next = queued_reg_saves;
1247 queued_reg_saves = q;
1251 q->cfa_offset = offset;
1252 q->saved_reg = sreg;
1254 last_reg_save_label = label;
1257 /* Output all the entries in QUEUED_REG_SAVES. */
1260 flush_queued_reg_saves (void)
1262 struct queued_reg_save *q;
1264 for (q = queued_reg_saves; q; q = q->next)
1267 unsigned int reg, sreg;
1269 for (i = 0; i < num_regs_saved_in_regs; i++)
1270 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1272 if (q->saved_reg && i == num_regs_saved_in_regs)
1274 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1275 num_regs_saved_in_regs++;
1277 if (i != num_regs_saved_in_regs)
1279 regs_saved_in_regs[i].orig_reg = q->reg;
1280 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1283 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1285 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1287 sreg = INVALID_REGNUM;
1288 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1291 queued_reg_saves = NULL;
1292 last_reg_save_label = NULL;
1295 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1296 location for? Or, does it clobber a register which we've previously
1297 said that some other register is saved in, and for which we now
1298 have a new location for? */
1301 clobbers_queued_reg_save (const_rtx insn)
1303 struct queued_reg_save *q;
1305 for (q = queued_reg_saves; q; q = q->next)
1308 if (modified_in_p (q->reg, insn))
1310 for (i = 0; i < num_regs_saved_in_regs; i++)
1311 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1312 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1319 /* Entry point for saving the first register into the second. */
1322 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1325 unsigned int regno, sregno;
1327 for (i = 0; i < num_regs_saved_in_regs; i++)
1328 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1330 if (i == num_regs_saved_in_regs)
1332 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1333 num_regs_saved_in_regs++;
1335 regs_saved_in_regs[i].orig_reg = reg;
1336 regs_saved_in_regs[i].saved_in_reg = sreg;
1338 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1339 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1340 reg_save (label, regno, sregno, 0);
1343 /* What register, if any, is currently saved in REG? */
1346 reg_saved_in (rtx reg)
1348 unsigned int regn = REGNO (reg);
1350 struct queued_reg_save *q;
1352 for (q = queued_reg_saves; q; q = q->next)
1353 if (q->saved_reg && regn == REGNO (q->saved_reg))
1356 for (i = 0; i < num_regs_saved_in_regs; i++)
1357 if (regs_saved_in_regs[i].saved_in_reg
1358 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1359 return regs_saved_in_regs[i].orig_reg;
1365 /* A temporary register holding an integral value used in adjusting SP
1366 or setting up the store_reg. The "offset" field holds the integer
1367 value, not an offset. */
1368 static dw_cfa_location cfa_temp;
1370 /* Record call frame debugging information for an expression EXPR,
1371 which either sets SP or FP (adjusting how we calculate the frame
1372 address) or saves a register to the stack or another register.
1373 LABEL indicates the address of EXPR.
1375 This function encodes a state machine mapping rtxes to actions on
1376 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1377 users need not read the source code.
1379 The High-Level Picture
1381 Changes in the register we use to calculate the CFA: Currently we
1382 assume that if you copy the CFA register into another register, we
1383 should take the other one as the new CFA register; this seems to
1384 work pretty well. If it's wrong for some target, it's simple
1385 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1387 Changes in the register we use for saving registers to the stack:
1388 This is usually SP, but not always. Again, we deduce that if you
1389 copy SP into another register (and SP is not the CFA register),
1390 then the new register is the one we will be using for register
1391 saves. This also seems to work.
1393 Register saves: There's not much guesswork about this one; if
1394 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1395 register save, and the register used to calculate the destination
1396 had better be the one we think we're using for this purpose.
1397 It's also assumed that a copy from a call-saved register to another
1398 register is saving that register if RTX_FRAME_RELATED_P is set on
1399 that instruction. If the copy is from a call-saved register to
1400 the *same* register, that means that the register is now the same
1401 value as in the caller.
1403 Except: If the register being saved is the CFA register, and the
1404 offset is nonzero, we are saving the CFA, so we assume we have to
1405 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1406 the intent is to save the value of SP from the previous frame.
1408 In addition, if a register has previously been saved to a different
1411 Invariants / Summaries of Rules
1413 cfa current rule for calculating the CFA. It usually
1414 consists of a register and an offset.
1415 cfa_store register used by prologue code to save things to the stack
1416 cfa_store.offset is the offset from the value of
1417 cfa_store.reg to the actual CFA
1418 cfa_temp register holding an integral value. cfa_temp.offset
1419 stores the value, which will be used to adjust the
1420 stack pointer. cfa_temp is also used like cfa_store,
1421 to track stores to the stack via fp or a temp reg.
1423 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1424 with cfa.reg as the first operand changes the cfa.reg and its
1425 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1428 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1429 expression yielding a constant. This sets cfa_temp.reg
1430 and cfa_temp.offset.
1432 Rule 5: Create a new register cfa_store used to save items to the
1435 Rules 10-14: Save a register to the stack. Define offset as the
1436 difference of the original location and cfa_store's
1437 location (or cfa_temp's location if cfa_temp is used).
1441 "{a,b}" indicates a choice of a xor b.
1442 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1445 (set <reg1> <reg2>:cfa.reg)
1446 effects: cfa.reg = <reg1>
1447 cfa.offset unchanged
1448 cfa_temp.reg = <reg1>
1449 cfa_temp.offset = cfa.offset
1452 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1453 {<const_int>,<reg>:cfa_temp.reg}))
1454 effects: cfa.reg = sp if fp used
1455 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1456 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1457 if cfa_store.reg==sp
1460 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1461 effects: cfa.reg = fp
1462 cfa_offset += +/- <const_int>
1465 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1466 constraints: <reg1> != fp
1468 effects: cfa.reg = <reg1>
1469 cfa_temp.reg = <reg1>
1470 cfa_temp.offset = cfa.offset
1473 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1474 constraints: <reg1> != fp
1476 effects: cfa_store.reg = <reg1>
1477 cfa_store.offset = cfa.offset - cfa_temp.offset
1480 (set <reg> <const_int>)
1481 effects: cfa_temp.reg = <reg>
1482 cfa_temp.offset = <const_int>
1485 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1486 effects: cfa_temp.reg = <reg1>
1487 cfa_temp.offset |= <const_int>
1490 (set <reg> (high <exp>))
1494 (set <reg> (lo_sum <exp> <const_int>))
1495 effects: cfa_temp.reg = <reg>
1496 cfa_temp.offset = <const_int>
1499 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1500 effects: cfa_store.offset -= <const_int>
1501 cfa.offset = cfa_store.offset if cfa.reg == sp
1503 cfa.base_offset = -cfa_store.offset
1506 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1507 effects: cfa_store.offset += -/+ mode_size(mem)
1508 cfa.offset = cfa_store.offset if cfa.reg == sp
1510 cfa.base_offset = -cfa_store.offset
1513 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1516 effects: cfa.reg = <reg1>
1517 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1520 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1521 effects: cfa.reg = <reg1>
1522 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1525 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1526 effects: cfa.reg = <reg1>
1527 cfa.base_offset = -cfa_temp.offset
1528 cfa_temp.offset -= mode_size(mem)
1531 (set <reg> {unspec, unspec_volatile})
1532 effects: target-dependent */
1535 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1538 HOST_WIDE_INT offset;
1540 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1541 the PARALLEL independently. The first element is always processed if
1542 it is a SET. This is for backward compatibility. Other elements
1543 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1544 flag is set in them. */
1545 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1548 int limit = XVECLEN (expr, 0);
1551 /* PARALLELs have strict read-modify-write semantics, so we
1552 ought to evaluate every rvalue before changing any lvalue.
1553 It's cumbersome to do that in general, but there's an
1554 easy approximation that is enough for all current users:
1555 handle register saves before register assignments. */
1556 if (GET_CODE (expr) == PARALLEL)
1557 for (par_index = 0; par_index < limit; par_index++)
1559 elem = XVECEXP (expr, 0, par_index);
1560 if (GET_CODE (elem) == SET
1561 && MEM_P (SET_DEST (elem))
1562 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1563 dwarf2out_frame_debug_expr (elem, label);
1566 for (par_index = 0; par_index < limit; par_index++)
1568 elem = XVECEXP (expr, 0, par_index);
1569 if (GET_CODE (elem) == SET
1570 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
1571 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1572 dwarf2out_frame_debug_expr (elem, label);
1577 gcc_assert (GET_CODE (expr) == SET);
1579 src = SET_SRC (expr);
1580 dest = SET_DEST (expr);
1584 rtx rsi = reg_saved_in (src);
1589 switch (GET_CODE (dest))
1592 switch (GET_CODE (src))
1594 /* Setting FP from SP. */
1596 if (cfa.reg == (unsigned) REGNO (src))
1599 /* Update the CFA rule wrt SP or FP. Make sure src is
1600 relative to the current CFA register.
1602 We used to require that dest be either SP or FP, but the
1603 ARM copies SP to a temporary register, and from there to
1604 FP. So we just rely on the backends to only set
1605 RTX_FRAME_RELATED_P on appropriate insns. */
1606 cfa.reg = REGNO (dest);
1607 cfa_temp.reg = cfa.reg;
1608 cfa_temp.offset = cfa.offset;
1612 /* Saving a register in a register. */
1613 gcc_assert (!fixed_regs [REGNO (dest)]
1614 /* For the SPARC and its register window. */
1615 || (DWARF_FRAME_REGNUM (REGNO (src))
1616 == DWARF_FRAME_RETURN_COLUMN));
1617 queue_reg_save (label, src, dest, 0);
1624 if (dest == stack_pointer_rtx)
1628 switch (GET_CODE (XEXP (src, 1)))
1631 offset = INTVAL (XEXP (src, 1));
1634 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1636 offset = cfa_temp.offset;
1642 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1644 /* Restoring SP from FP in the epilogue. */
1645 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1646 cfa.reg = STACK_POINTER_REGNUM;
1648 else if (GET_CODE (src) == LO_SUM)
1649 /* Assume we've set the source reg of the LO_SUM from sp. */
1652 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1654 if (GET_CODE (src) != MINUS)
1656 if (cfa.reg == STACK_POINTER_REGNUM)
1657 cfa.offset += offset;
1658 if (cfa_store.reg == STACK_POINTER_REGNUM)
1659 cfa_store.offset += offset;
1661 else if (dest == hard_frame_pointer_rtx)
1664 /* Either setting the FP from an offset of the SP,
1665 or adjusting the FP */
1666 gcc_assert (frame_pointer_needed);
1668 gcc_assert (REG_P (XEXP (src, 0))
1669 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1670 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1671 offset = INTVAL (XEXP (src, 1));
1672 if (GET_CODE (src) != MINUS)
1674 cfa.offset += offset;
1675 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1679 gcc_assert (GET_CODE (src) != MINUS);
1682 if (REG_P (XEXP (src, 0))
1683 && REGNO (XEXP (src, 0)) == cfa.reg
1684 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1686 /* Setting a temporary CFA register that will be copied
1687 into the FP later on. */
1688 offset = - INTVAL (XEXP (src, 1));
1689 cfa.offset += offset;
1690 cfa.reg = REGNO (dest);
1691 /* Or used to save regs to the stack. */
1692 cfa_temp.reg = cfa.reg;
1693 cfa_temp.offset = cfa.offset;
1697 else if (REG_P (XEXP (src, 0))
1698 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1699 && XEXP (src, 1) == stack_pointer_rtx)
1701 /* Setting a scratch register that we will use instead
1702 of SP for saving registers to the stack. */
1703 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
1704 cfa_store.reg = REGNO (dest);
1705 cfa_store.offset = cfa.offset - cfa_temp.offset;
1709 else if (GET_CODE (src) == LO_SUM
1710 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1712 cfa_temp.reg = REGNO (dest);
1713 cfa_temp.offset = INTVAL (XEXP (src, 1));
1722 cfa_temp.reg = REGNO (dest);
1723 cfa_temp.offset = INTVAL (src);
1728 gcc_assert (REG_P (XEXP (src, 0))
1729 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
1730 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1732 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1733 cfa_temp.reg = REGNO (dest);
1734 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1737 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1738 which will fill in all of the bits. */
1745 case UNSPEC_VOLATILE:
1746 gcc_assert (targetm.dwarf_handle_frame_unspec);
1747 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
1754 def_cfa_1 (label, &cfa);
1758 gcc_assert (REG_P (src));
1760 /* Saving a register to the stack. Make sure dest is relative to the
1762 switch (GET_CODE (XEXP (dest, 0)))
1767 /* We can't handle variable size modifications. */
1768 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
1770 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1772 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1773 && cfa_store.reg == STACK_POINTER_REGNUM);
1775 cfa_store.offset += offset;
1776 if (cfa.reg == STACK_POINTER_REGNUM)
1777 cfa.offset = cfa_store.offset;
1779 offset = -cfa_store.offset;
1785 offset = GET_MODE_SIZE (GET_MODE (dest));
1786 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1789 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1790 && cfa_store.reg == STACK_POINTER_REGNUM);
1792 cfa_store.offset += offset;
1793 if (cfa.reg == STACK_POINTER_REGNUM)
1794 cfa.offset = cfa_store.offset;
1796 offset = -cfa_store.offset;
1800 /* With an offset. */
1807 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
1808 && REG_P (XEXP (XEXP (dest, 0), 0)));
1809 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1810 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1813 regno = REGNO (XEXP (XEXP (dest, 0), 0));
1815 if (cfa_store.reg == (unsigned) regno)
1816 offset -= cfa_store.offset;
1819 gcc_assert (cfa_temp.reg == (unsigned) regno);
1820 offset -= cfa_temp.offset;
1826 /* Without an offset. */
1829 int regno = REGNO (XEXP (dest, 0));
1831 if (cfa_store.reg == (unsigned) regno)
1832 offset = -cfa_store.offset;
1835 gcc_assert (cfa_temp.reg == (unsigned) regno);
1836 offset = -cfa_temp.offset;
1843 gcc_assert (cfa_temp.reg
1844 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
1845 offset = -cfa_temp.offset;
1846 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1853 if (REGNO (src) != STACK_POINTER_REGNUM
1854 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1855 && (unsigned) REGNO (src) == cfa.reg)
1857 /* We're storing the current CFA reg into the stack. */
1859 if (cfa.offset == 0)
1861 /* If the source register is exactly the CFA, assume
1862 we're saving SP like any other register; this happens
1864 def_cfa_1 (label, &cfa);
1865 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
1870 /* Otherwise, we'll need to look in the stack to
1871 calculate the CFA. */
1872 rtx x = XEXP (dest, 0);
1876 gcc_assert (REG_P (x));
1878 cfa.reg = REGNO (x);
1879 cfa.base_offset = offset;
1881 def_cfa_1 (label, &cfa);
1886 def_cfa_1 (label, &cfa);
1887 queue_reg_save (label, src, NULL_RTX, offset);
1895 /* Record call frame debugging information for INSN, which either
1896 sets SP or FP (adjusting how we calculate the frame address) or saves a
1897 register to the stack. If INSN is NULL_RTX, initialize our state.
1899 If AFTER_P is false, we're being called before the insn is emitted,
1900 otherwise after. Call instructions get invoked twice. */
1903 dwarf2out_frame_debug (rtx insn, bool after_p)
1908 if (insn == NULL_RTX)
1912 /* Flush any queued register saves. */
1913 flush_queued_reg_saves ();
1915 /* Set up state for generating call frame debug info. */
1918 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1920 cfa.reg = STACK_POINTER_REGNUM;
1923 cfa_temp.offset = 0;
1925 for (i = 0; i < num_regs_saved_in_regs; i++)
1927 regs_saved_in_regs[i].orig_reg = NULL_RTX;
1928 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
1930 num_regs_saved_in_regs = 0;
1934 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
1935 flush_queued_reg_saves ();
1937 if (! RTX_FRAME_RELATED_P (insn))
1939 if (!ACCUMULATE_OUTGOING_ARGS)
1940 dwarf2out_stack_adjust (insn, after_p);
1944 label = dwarf2out_cfi_label ();
1945 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1947 insn = XEXP (src, 0);
1949 insn = PATTERN (insn);
1951 dwarf2out_frame_debug_expr (insn, label);
1956 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1957 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1958 (enum dwarf_call_frame_info cfi);
1960 static enum dw_cfi_oprnd_type
1961 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1966 case DW_CFA_GNU_window_save:
1967 return dw_cfi_oprnd_unused;
1969 case DW_CFA_set_loc:
1970 case DW_CFA_advance_loc1:
1971 case DW_CFA_advance_loc2:
1972 case DW_CFA_advance_loc4:
1973 case DW_CFA_MIPS_advance_loc8:
1974 return dw_cfi_oprnd_addr;
1977 case DW_CFA_offset_extended:
1978 case DW_CFA_def_cfa:
1979 case DW_CFA_offset_extended_sf:
1980 case DW_CFA_def_cfa_sf:
1981 case DW_CFA_restore_extended:
1982 case DW_CFA_undefined:
1983 case DW_CFA_same_value:
1984 case DW_CFA_def_cfa_register:
1985 case DW_CFA_register:
1986 return dw_cfi_oprnd_reg_num;
1988 case DW_CFA_def_cfa_offset:
1989 case DW_CFA_GNU_args_size:
1990 case DW_CFA_def_cfa_offset_sf:
1991 return dw_cfi_oprnd_offset;
1993 case DW_CFA_def_cfa_expression:
1994 case DW_CFA_expression:
1995 return dw_cfi_oprnd_loc;
2002 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2003 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2004 (enum dwarf_call_frame_info cfi);
2006 static enum dw_cfi_oprnd_type
2007 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2011 case DW_CFA_def_cfa:
2012 case DW_CFA_def_cfa_sf:
2014 case DW_CFA_offset_extended_sf:
2015 case DW_CFA_offset_extended:
2016 return dw_cfi_oprnd_offset;
2018 case DW_CFA_register:
2019 return dw_cfi_oprnd_reg_num;
2022 return dw_cfi_oprnd_unused;
2026 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2028 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2029 switch to the data section instead, and write out a synthetic label
2033 switch_to_eh_frame_section (void)
2037 #ifdef EH_FRAME_SECTION_NAME
2038 if (eh_frame_section == 0)
2042 if (EH_TABLES_CAN_BE_READ_ONLY)
2048 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2050 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2052 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2054 flags = ((! flag_pic
2055 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2056 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2057 && (per_encoding & 0x70) != DW_EH_PE_absptr
2058 && (per_encoding & 0x70) != DW_EH_PE_aligned
2059 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2060 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2061 ? 0 : SECTION_WRITE);
2064 flags = SECTION_WRITE;
2065 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2069 if (eh_frame_section)
2070 switch_to_section (eh_frame_section);
2073 /* We have no special eh_frame section. Put the information in
2074 the data section and emit special labels to guide collect2. */
2075 switch_to_section (data_section);
2076 label = get_file_function_name ("F");
2077 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2078 targetm.asm_out.globalize_label (asm_out_file,
2079 IDENTIFIER_POINTER (label));
2080 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2084 /* Output a Call Frame Information opcode and its operand(s). */
2087 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2090 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2091 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2092 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2093 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2094 cfi->dw_cfi_oprnd1.dw_cfi_offset);
2095 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2097 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2098 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2099 "DW_CFA_offset, column 0x%lx", r);
2100 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2102 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2104 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2105 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2106 "DW_CFA_restore, column 0x%lx", r);
2110 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2111 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2113 switch (cfi->dw_cfi_opc)
2115 case DW_CFA_set_loc:
2117 dw2_asm_output_encoded_addr_rtx (
2118 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2119 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2122 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2123 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2124 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2127 case DW_CFA_advance_loc1:
2128 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2129 fde->dw_fde_current_label, NULL);
2130 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2133 case DW_CFA_advance_loc2:
2134 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2135 fde->dw_fde_current_label, NULL);
2136 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2139 case DW_CFA_advance_loc4:
2140 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2141 fde->dw_fde_current_label, NULL);
2142 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2145 case DW_CFA_MIPS_advance_loc8:
2146 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2147 fde->dw_fde_current_label, NULL);
2148 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2151 case DW_CFA_offset_extended:
2152 case DW_CFA_def_cfa:
2153 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2154 dw2_asm_output_data_uleb128 (r, NULL);
2155 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2158 case DW_CFA_offset_extended_sf:
2159 case DW_CFA_def_cfa_sf:
2160 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2161 dw2_asm_output_data_uleb128 (r, NULL);
2162 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2165 case DW_CFA_restore_extended:
2166 case DW_CFA_undefined:
2167 case DW_CFA_same_value:
2168 case DW_CFA_def_cfa_register:
2169 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2170 dw2_asm_output_data_uleb128 (r, NULL);
2173 case DW_CFA_register:
2174 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2175 dw2_asm_output_data_uleb128 (r, NULL);
2176 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2177 dw2_asm_output_data_uleb128 (r, NULL);
2180 case DW_CFA_def_cfa_offset:
2181 case DW_CFA_GNU_args_size:
2182 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2185 case DW_CFA_def_cfa_offset_sf:
2186 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2189 case DW_CFA_GNU_window_save:
2192 case DW_CFA_def_cfa_expression:
2193 case DW_CFA_expression:
2194 output_cfa_loc (cfi);
2197 case DW_CFA_GNU_negative_offset_extended:
2198 /* Obsoleted by DW_CFA_offset_extended_sf. */
2207 /* Output the call frame information used to record information
2208 that relates to calculating the frame pointer, and records the
2209 location of saved registers. */
2212 output_call_frame_info (int for_eh)
2217 char l1[20], l2[20], section_start_label[20];
2218 bool any_lsda_needed = false;
2219 char augmentation[6];
2220 int augmentation_size;
2221 int fde_encoding = DW_EH_PE_absptr;
2222 int per_encoding = DW_EH_PE_absptr;
2223 int lsda_encoding = DW_EH_PE_absptr;
2226 /* Don't emit a CIE if there won't be any FDEs. */
2227 if (fde_table_in_use == 0)
2230 /* If we make FDEs linkonce, we may have to emit an empty label for
2231 an FDE that wouldn't otherwise be emitted. We want to avoid
2232 having an FDE kept around when the function it refers to is
2233 discarded. Example where this matters: a primary function
2234 template in C++ requires EH information, but an explicit
2235 specialization doesn't. */
2236 if (TARGET_USES_WEAK_UNWIND_INFO
2237 && ! flag_asynchronous_unwind_tables
2240 for (i = 0; i < fde_table_in_use; i++)
2241 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2242 && !fde_table[i].uses_eh_lsda
2243 && ! DECL_WEAK (fde_table[i].decl))
2244 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2245 for_eh, /* empty */ 1);
2247 /* If we don't have any functions we'll want to unwind out of, don't
2248 emit any EH unwind information. Note that if exceptions aren't
2249 enabled, we won't have collected nothrow information, and if we
2250 asked for asynchronous tables, we always want this info. */
2253 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2255 for (i = 0; i < fde_table_in_use; i++)
2256 if (fde_table[i].uses_eh_lsda)
2257 any_eh_needed = any_lsda_needed = true;
2258 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2259 any_eh_needed = true;
2260 else if (! fde_table[i].nothrow
2261 && ! fde_table[i].all_throwers_are_sibcalls)
2262 any_eh_needed = true;
2264 if (! any_eh_needed)
2268 /* We're going to be generating comments, so turn on app. */
2273 switch_to_eh_frame_section ();
2276 if (!debug_frame_section)
2277 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
2278 SECTION_DEBUG, NULL);
2279 switch_to_section (debug_frame_section);
2282 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2283 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2285 /* Output the CIE. */
2286 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2287 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2288 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2289 dw2_asm_output_data (4, 0xffffffff,
2290 "Initial length escape value indicating 64-bit DWARF extension");
2291 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2292 "Length of Common Information Entry");
2293 ASM_OUTPUT_LABEL (asm_out_file, l1);
2295 /* Now that the CIE pointer is PC-relative for EH,
2296 use 0 to identify the CIE. */
2297 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2298 (for_eh ? 0 : DWARF_CIE_ID),
2299 "CIE Identifier Tag");
2301 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2303 augmentation[0] = 0;
2304 augmentation_size = 0;
2310 z Indicates that a uleb128 is present to size the
2311 augmentation section.
2312 L Indicates the encoding (and thus presence) of
2313 an LSDA pointer in the FDE augmentation.
2314 R Indicates a non-default pointer encoding for
2316 P Indicates the presence of an encoding + language
2317 personality routine in the CIE augmentation. */
2319 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2320 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2321 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2323 p = augmentation + 1;
2324 if (eh_personality_libfunc)
2327 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2328 assemble_external_libcall (eh_personality_libfunc);
2330 if (any_lsda_needed)
2333 augmentation_size += 1;
2335 if (fde_encoding != DW_EH_PE_absptr)
2338 augmentation_size += 1;
2340 if (p > augmentation + 1)
2342 augmentation[0] = 'z';
2346 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2347 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2349 int offset = ( 4 /* Length */
2351 + 1 /* CIE version */
2352 + strlen (augmentation) + 1 /* Augmentation */
2353 + size_of_uleb128 (1) /* Code alignment */
2354 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2356 + 1 /* Augmentation size */
2357 + 1 /* Personality encoding */ );
2358 int pad = -offset & (PTR_SIZE - 1);
2360 augmentation_size += pad;
2362 /* Augmentations should be small, so there's scarce need to
2363 iterate for a solution. Die if we exceed one uleb128 byte. */
2364 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2368 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2369 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2370 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2371 "CIE Data Alignment Factor");
2373 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2374 if (DW_CIE_VERSION == 1)
2375 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2377 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2379 if (augmentation[0])
2381 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2382 if (eh_personality_libfunc)
2384 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2385 eh_data_format_name (per_encoding));
2386 dw2_asm_output_encoded_addr_rtx (per_encoding,
2387 eh_personality_libfunc,
2391 if (any_lsda_needed)
2392 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2393 eh_data_format_name (lsda_encoding));
2395 if (fde_encoding != DW_EH_PE_absptr)
2396 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2397 eh_data_format_name (fde_encoding));
2400 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2401 output_cfi (cfi, NULL, for_eh);
2403 /* Pad the CIE out to an address sized boundary. */
2404 ASM_OUTPUT_ALIGN (asm_out_file,
2405 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2406 ASM_OUTPUT_LABEL (asm_out_file, l2);
2408 /* Loop through all of the FDE's. */
2409 for (i = 0; i < fde_table_in_use; i++)
2411 fde = &fde_table[i];
2413 /* Don't emit EH unwind info for leaf functions that don't need it. */
2414 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2415 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2416 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2417 && !fde->uses_eh_lsda)
2420 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2421 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2422 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2423 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2424 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2425 dw2_asm_output_data (4, 0xffffffff,
2426 "Initial length escape value indicating 64-bit DWARF extension");
2427 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2429 ASM_OUTPUT_LABEL (asm_out_file, l1);
2432 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2434 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2435 debug_frame_section, "FDE CIE offset");
2439 if (fde->dw_fde_switched_sections)
2441 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2442 fde->dw_fde_unlikely_section_label);
2443 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2444 fde->dw_fde_hot_section_label);
2445 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2446 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2447 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
2448 "FDE initial location");
2449 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2450 fde->dw_fde_hot_section_end_label,
2451 fde->dw_fde_hot_section_label,
2452 "FDE address range");
2453 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
2454 "FDE initial location");
2455 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2456 fde->dw_fde_unlikely_section_end_label,
2457 fde->dw_fde_unlikely_section_label,
2458 "FDE address range");
2462 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2463 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2464 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2467 "FDE initial location");
2468 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2469 fde->dw_fde_end, fde->dw_fde_begin,
2470 "FDE address range");
2475 if (fde->dw_fde_switched_sections)
2477 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2478 fde->dw_fde_hot_section_label,
2479 "FDE initial location");
2480 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2481 fde->dw_fde_hot_section_end_label,
2482 fde->dw_fde_hot_section_label,
2483 "FDE address range");
2484 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2485 fde->dw_fde_unlikely_section_label,
2486 "FDE initial location");
2487 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2488 fde->dw_fde_unlikely_section_end_label,
2489 fde->dw_fde_unlikely_section_label,
2490 "FDE address range");
2494 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2495 "FDE initial location");
2496 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2497 fde->dw_fde_end, fde->dw_fde_begin,
2498 "FDE address range");
2502 if (augmentation[0])
2504 if (any_lsda_needed)
2506 int size = size_of_encoded_value (lsda_encoding);
2508 if (lsda_encoding == DW_EH_PE_aligned)
2510 int offset = ( 4 /* Length */
2511 + 4 /* CIE offset */
2512 + 2 * size_of_encoded_value (fde_encoding)
2513 + 1 /* Augmentation size */ );
2514 int pad = -offset & (PTR_SIZE - 1);
2517 gcc_assert (size_of_uleb128 (size) == 1);
2520 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2522 if (fde->uses_eh_lsda)
2524 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2525 fde->funcdef_number);
2526 dw2_asm_output_encoded_addr_rtx (
2527 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2528 false, "Language Specific Data Area");
2532 if (lsda_encoding == DW_EH_PE_aligned)
2533 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2535 (size_of_encoded_value (lsda_encoding), 0,
2536 "Language Specific Data Area (none)");
2540 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2543 /* Loop through the Call Frame Instructions associated with
2545 fde->dw_fde_current_label = fde->dw_fde_begin;
2546 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2547 output_cfi (cfi, fde, for_eh);
2549 /* Pad the FDE out to an address sized boundary. */
2550 ASM_OUTPUT_ALIGN (asm_out_file,
2551 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2552 ASM_OUTPUT_LABEL (asm_out_file, l2);
2555 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2556 dw2_asm_output_data (4, 0, "End of Table");
2557 #ifdef MIPS_DEBUGGING_INFO
2558 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2559 get a value of 0. Putting .align 0 after the label fixes it. */
2560 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2563 /* Turn off app to make assembly quicker. */
2568 /* Output a marker (i.e. a label) for the beginning of a function, before
2572 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2573 const char *file ATTRIBUTE_UNUSED)
2575 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2579 current_function_func_begin_label = NULL;
2581 #ifdef TARGET_UNWIND_INFO
2582 /* ??? current_function_func_begin_label is also used by except.c
2583 for call-site information. We must emit this label if it might
2585 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2586 && ! dwarf2out_do_frame ())
2589 if (! dwarf2out_do_frame ())
2593 switch_to_section (function_section (current_function_decl));
2594 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2595 current_function_funcdef_no);
2596 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2597 current_function_funcdef_no);
2598 dup_label = xstrdup (label);
2599 current_function_func_begin_label = dup_label;
2601 #ifdef TARGET_UNWIND_INFO
2602 /* We can elide the fde allocation if we're not emitting debug info. */
2603 if (! dwarf2out_do_frame ())
2607 /* Expand the fde table if necessary. */
2608 if (fde_table_in_use == fde_table_allocated)
2610 fde_table_allocated += FDE_TABLE_INCREMENT;
2611 fde_table = ggc_realloc (fde_table,
2612 fde_table_allocated * sizeof (dw_fde_node));
2613 memset (fde_table + fde_table_in_use, 0,
2614 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2617 /* Record the FDE associated with this function. */
2618 current_funcdef_fde = fde_table_in_use;
2620 /* Add the new FDE at the end of the fde_table. */
2621 fde = &fde_table[fde_table_in_use++];
2622 fde->decl = current_function_decl;
2623 fde->dw_fde_begin = dup_label;
2624 fde->dw_fde_current_label = dup_label;
2625 fde->dw_fde_hot_section_label = NULL;
2626 fde->dw_fde_hot_section_end_label = NULL;
2627 fde->dw_fde_unlikely_section_label = NULL;
2628 fde->dw_fde_unlikely_section_end_label = NULL;
2629 fde->dw_fde_switched_sections = false;
2630 fde->dw_fde_end = NULL;
2631 fde->dw_fde_cfi = NULL;
2632 fde->funcdef_number = current_function_funcdef_no;
2633 fde->nothrow = TREE_NOTHROW (current_function_decl);
2634 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2635 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2637 args_size = old_args_size = 0;
2639 /* We only want to output line number information for the genuine dwarf2
2640 prologue case, not the eh frame case. */
2641 #ifdef DWARF2_DEBUGGING_INFO
2643 dwarf2out_source_line (line, file);
2647 /* Output a marker (i.e. a label) for the absolute end of the generated code
2648 for a function definition. This gets called *after* the epilogue code has
2652 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2653 const char *file ATTRIBUTE_UNUSED)
2656 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2658 /* Output a label to mark the endpoint of the code generated for this
2660 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2661 current_function_funcdef_no);
2662 ASM_OUTPUT_LABEL (asm_out_file, label);
2663 fde = &fde_table[fde_table_in_use - 1];
2664 fde->dw_fde_end = xstrdup (label);
2668 dwarf2out_frame_init (void)
2670 /* Allocate the initial hunk of the fde_table. */
2671 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2672 fde_table_allocated = FDE_TABLE_INCREMENT;
2673 fde_table_in_use = 0;
2675 /* Generate the CFA instructions common to all FDE's. Do it now for the
2676 sake of lookup_cfa. */
2678 /* On entry, the Canonical Frame Address is at SP. */
2679 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2681 #ifdef DWARF2_UNWIND_INFO
2682 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
2683 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2688 dwarf2out_frame_finish (void)
2690 /* Output call frame information. */
2691 if (DWARF2_FRAME_INFO)
2692 output_call_frame_info (0);
2694 #ifndef TARGET_UNWIND_INFO
2695 /* Output another copy for the unwinder. */
2696 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2697 output_call_frame_info (1);
2701 /* Note that the current function section is being used for code. */
2704 dwarf2out_note_section_used (void)
2706 section *sec = current_function_section ();
2707 if (sec == text_section)
2708 text_section_used = true;
2709 else if (sec == cold_text_section)
2710 cold_text_section_used = true;
2714 dwarf2out_switch_text_section (void)
2720 fde = &fde_table[fde_table_in_use - 1];
2721 fde->dw_fde_switched_sections = true;
2722 fde->dw_fde_hot_section_label = cfun->hot_section_label;
2723 fde->dw_fde_hot_section_end_label = cfun->hot_section_end_label;
2724 fde->dw_fde_unlikely_section_label = cfun->cold_section_label;
2725 fde->dw_fde_unlikely_section_end_label = cfun->cold_section_end_label;
2726 have_multiple_function_sections = true;
2728 /* Reset the current label on switching text sections, so that we
2729 don't attempt to advance_loc4 between labels in different sections. */
2730 fde->dw_fde_current_label = NULL;
2732 dwarf2out_note_section_used ();
2736 /* And now, the subset of the debugging information support code necessary
2737 for emitting location expressions. */
2739 /* Data about a single source file. */
2740 struct dwarf_file_data GTY(())
2742 const char * filename;
2746 /* We need some way to distinguish DW_OP_addr with a direct symbol
2747 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2748 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2751 typedef struct dw_val_struct *dw_val_ref;
2752 typedef struct die_struct *dw_die_ref;
2753 typedef const struct die_struct *const_dw_die_ref;
2754 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2755 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2757 /* Each DIE may have a series of attribute/value pairs. Values
2758 can take on several forms. The forms that are used in this
2759 implementation are listed below. */
2764 dw_val_class_offset,
2766 dw_val_class_loc_list,
2767 dw_val_class_range_list,
2769 dw_val_class_unsigned_const,
2770 dw_val_class_long_long,
2773 dw_val_class_die_ref,
2774 dw_val_class_fde_ref,
2775 dw_val_class_lbl_id,
2776 dw_val_class_lineptr,
2778 dw_val_class_macptr,
2782 /* Describe a double word constant value. */
2783 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2785 typedef struct dw_long_long_struct GTY(())
2792 /* Describe a floating point constant value, or a vector constant value. */
2794 typedef struct dw_vec_struct GTY(())
2796 unsigned char * GTY((length ("%h.length"))) array;
2802 /* The dw_val_node describes an attribute's value, as it is
2803 represented internally. */
2805 typedef struct dw_val_struct GTY(())
2807 enum dw_val_class val_class;
2808 union dw_val_struct_union
2810 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2811 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2812 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2813 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2814 HOST_WIDE_INT GTY ((default)) val_int;
2815 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2816 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2817 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2818 struct dw_val_die_union
2822 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2823 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2824 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2825 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2826 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2827 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
2829 GTY ((desc ("%1.val_class"))) v;
2833 /* Locations in memory are described using a sequence of stack machine
2836 typedef struct dw_loc_descr_struct GTY(())
2838 dw_loc_descr_ref dw_loc_next;
2839 enum dwarf_location_atom dw_loc_opc;
2840 dw_val_node dw_loc_oprnd1;
2841 dw_val_node dw_loc_oprnd2;
2846 /* Location lists are ranges + location descriptions for that range,
2847 so you can track variables that are in different places over
2848 their entire life. */
2849 typedef struct dw_loc_list_struct GTY(())
2851 dw_loc_list_ref dw_loc_next;
2852 const char *begin; /* Label for begin address of range */
2853 const char *end; /* Label for end address of range */
2854 char *ll_symbol; /* Label for beginning of location list.
2855 Only on head of list */
2856 const char *section; /* Section this loclist is relative to */
2857 dw_loc_descr_ref expr;
2860 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2862 static const char *dwarf_stack_op_name (unsigned);
2863 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2864 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2865 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2866 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2867 static unsigned long size_of_locs (dw_loc_descr_ref);
2868 static void output_loc_operands (dw_loc_descr_ref);
2869 static void output_loc_sequence (dw_loc_descr_ref);
2871 /* Convert a DWARF stack opcode into its string name. */
2874 dwarf_stack_op_name (unsigned int op)
2879 case INTERNAL_DW_OP_tls_addr:
2880 return "DW_OP_addr";
2882 return "DW_OP_deref";
2884 return "DW_OP_const1u";
2886 return "DW_OP_const1s";
2888 return "DW_OP_const2u";
2890 return "DW_OP_const2s";
2892 return "DW_OP_const4u";
2894 return "DW_OP_const4s";
2896 return "DW_OP_const8u";
2898 return "DW_OP_const8s";
2900 return "DW_OP_constu";
2902 return "DW_OP_consts";
2906 return "DW_OP_drop";
2908 return "DW_OP_over";
2910 return "DW_OP_pick";
2912 return "DW_OP_swap";
2916 return "DW_OP_xderef";
2924 return "DW_OP_minus";
2936 return "DW_OP_plus";
2937 case DW_OP_plus_uconst:
2938 return "DW_OP_plus_uconst";
2944 return "DW_OP_shra";
2962 return "DW_OP_skip";
2964 return "DW_OP_lit0";
2966 return "DW_OP_lit1";
2968 return "DW_OP_lit2";
2970 return "DW_OP_lit3";
2972 return "DW_OP_lit4";
2974 return "DW_OP_lit5";
2976 return "DW_OP_lit6";
2978 return "DW_OP_lit7";
2980 return "DW_OP_lit8";
2982 return "DW_OP_lit9";
2984 return "DW_OP_lit10";
2986 return "DW_OP_lit11";
2988 return "DW_OP_lit12";
2990 return "DW_OP_lit13";
2992 return "DW_OP_lit14";
2994 return "DW_OP_lit15";
2996 return "DW_OP_lit16";
2998 return "DW_OP_lit17";
3000 return "DW_OP_lit18";
3002 return "DW_OP_lit19";
3004 return "DW_OP_lit20";
3006 return "DW_OP_lit21";
3008 return "DW_OP_lit22";
3010 return "DW_OP_lit23";
3012 return "DW_OP_lit24";
3014 return "DW_OP_lit25";
3016 return "DW_OP_lit26";
3018 return "DW_OP_lit27";
3020 return "DW_OP_lit28";
3022 return "DW_OP_lit29";
3024 return "DW_OP_lit30";
3026 return "DW_OP_lit31";
3028 return "DW_OP_reg0";
3030 return "DW_OP_reg1";
3032 return "DW_OP_reg2";
3034 return "DW_OP_reg3";
3036 return "DW_OP_reg4";
3038 return "DW_OP_reg5";
3040 return "DW_OP_reg6";
3042 return "DW_OP_reg7";
3044 return "DW_OP_reg8";
3046 return "DW_OP_reg9";
3048 return "DW_OP_reg10";
3050 return "DW_OP_reg11";
3052 return "DW_OP_reg12";
3054 return "DW_OP_reg13";
3056 return "DW_OP_reg14";
3058 return "DW_OP_reg15";
3060 return "DW_OP_reg16";
3062 return "DW_OP_reg17";
3064 return "DW_OP_reg18";
3066 return "DW_OP_reg19";
3068 return "DW_OP_reg20";
3070 return "DW_OP_reg21";
3072 return "DW_OP_reg22";
3074 return "DW_OP_reg23";
3076 return "DW_OP_reg24";
3078 return "DW_OP_reg25";
3080 return "DW_OP_reg26";
3082 return "DW_OP_reg27";
3084 return "DW_OP_reg28";
3086 return "DW_OP_reg29";
3088 return "DW_OP_reg30";
3090 return "DW_OP_reg31";
3092 return "DW_OP_breg0";
3094 return "DW_OP_breg1";
3096 return "DW_OP_breg2";
3098 return "DW_OP_breg3";
3100 return "DW_OP_breg4";
3102 return "DW_OP_breg5";
3104 return "DW_OP_breg6";
3106 return "DW_OP_breg7";
3108 return "DW_OP_breg8";
3110 return "DW_OP_breg9";
3112 return "DW_OP_breg10";
3114 return "DW_OP_breg11";
3116 return "DW_OP_breg12";
3118 return "DW_OP_breg13";
3120 return "DW_OP_breg14";
3122 return "DW_OP_breg15";
3124 return "DW_OP_breg16";
3126 return "DW_OP_breg17";
3128 return "DW_OP_breg18";
3130 return "DW_OP_breg19";
3132 return "DW_OP_breg20";
3134 return "DW_OP_breg21";
3136 return "DW_OP_breg22";
3138 return "DW_OP_breg23";
3140 return "DW_OP_breg24";
3142 return "DW_OP_breg25";
3144 return "DW_OP_breg26";
3146 return "DW_OP_breg27";
3148 return "DW_OP_breg28";
3150 return "DW_OP_breg29";
3152 return "DW_OP_breg30";
3154 return "DW_OP_breg31";
3156 return "DW_OP_regx";
3158 return "DW_OP_fbreg";
3160 return "DW_OP_bregx";
3162 return "DW_OP_piece";
3163 case DW_OP_deref_size:
3164 return "DW_OP_deref_size";
3165 case DW_OP_xderef_size:
3166 return "DW_OP_xderef_size";
3169 case DW_OP_push_object_address:
3170 return "DW_OP_push_object_address";
3172 return "DW_OP_call2";
3174 return "DW_OP_call4";
3175 case DW_OP_call_ref:
3176 return "DW_OP_call_ref";
3177 case DW_OP_GNU_push_tls_address:
3178 return "DW_OP_GNU_push_tls_address";
3179 case DW_OP_GNU_uninit:
3180 return "DW_OP_GNU_uninit";
3182 return "OP_<unknown>";
3186 /* Return a pointer to a newly allocated location description. Location
3187 descriptions are simple expression terms that can be strung
3188 together to form more complicated location (address) descriptions. */
3190 static inline dw_loc_descr_ref
3191 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3192 unsigned HOST_WIDE_INT oprnd2)
3194 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
3196 descr->dw_loc_opc = op;
3197 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3198 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3199 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3200 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3205 /* Add a location description term to a location description expression. */
3208 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3210 dw_loc_descr_ref *d;
3212 /* Find the end of the chain. */
3213 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3219 /* Return the size of a location descriptor. */
3221 static unsigned long
3222 size_of_loc_descr (dw_loc_descr_ref loc)
3224 unsigned long size = 1;
3226 switch (loc->dw_loc_opc)
3229 case INTERNAL_DW_OP_tls_addr:
3230 size += DWARF2_ADDR_SIZE;
3249 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3252 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3257 case DW_OP_plus_uconst:
3258 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3296 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3299 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3302 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3305 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3306 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3309 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3311 case DW_OP_deref_size:
3312 case DW_OP_xderef_size:
3321 case DW_OP_call_ref:
3322 size += DWARF2_ADDR_SIZE;
3331 /* Return the size of a series of location descriptors. */
3333 static unsigned long
3334 size_of_locs (dw_loc_descr_ref loc)
3339 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3340 field, to avoid writing to a PCH file. */
3341 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3343 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
3345 size += size_of_loc_descr (l);
3350 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3352 l->dw_loc_addr = size;
3353 size += size_of_loc_descr (l);
3359 /* Output location description stack opcode's operands (if any). */
3362 output_loc_operands (dw_loc_descr_ref loc)
3364 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3365 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3367 switch (loc->dw_loc_opc)
3369 #ifdef DWARF2_DEBUGGING_INFO
3371 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3375 dw2_asm_output_data (2, val1->v.val_int, NULL);
3379 dw2_asm_output_data (4, val1->v.val_int, NULL);
3383 gcc_assert (HOST_BITS_PER_LONG >= 64);
3384 dw2_asm_output_data (8, val1->v.val_int, NULL);
3391 gcc_assert (val1->val_class == dw_val_class_loc);
3392 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3394 dw2_asm_output_data (2, offset, NULL);
3407 /* We currently don't make any attempt to make sure these are
3408 aligned properly like we do for the main unwind info, so
3409 don't support emitting things larger than a byte if we're
3410 only doing unwinding. */
3415 dw2_asm_output_data (1, val1->v.val_int, NULL);
3418 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3421 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3424 dw2_asm_output_data (1, val1->v.val_int, NULL);
3426 case DW_OP_plus_uconst:
3427 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3461 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3464 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3467 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3470 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3471 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3474 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3476 case DW_OP_deref_size:
3477 case DW_OP_xderef_size:
3478 dw2_asm_output_data (1, val1->v.val_int, NULL);
3481 case INTERNAL_DW_OP_tls_addr:
3482 if (targetm.asm_out.output_dwarf_dtprel)
3484 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
3487 fputc ('\n', asm_out_file);
3494 /* Other codes have no operands. */
3499 /* Output a sequence of location operations. */
3502 output_loc_sequence (dw_loc_descr_ref loc)
3504 for (; loc != NULL; loc = loc->dw_loc_next)
3506 /* Output the opcode. */
3507 dw2_asm_output_data (1, loc->dw_loc_opc,
3508 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3510 /* Output the operand(s) (if any). */
3511 output_loc_operands (loc);
3515 /* This routine will generate the correct assembly data for a location
3516 description based on a cfi entry with a complex address. */
3519 output_cfa_loc (dw_cfi_ref cfi)
3521 dw_loc_descr_ref loc;
3524 /* Output the size of the block. */
3525 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3526 size = size_of_locs (loc);
3527 dw2_asm_output_data_uleb128 (size, NULL);
3529 /* Now output the operations themselves. */
3530 output_loc_sequence (loc);
3533 /* This function builds a dwarf location descriptor sequence from a
3534 dw_cfa_location, adding the given OFFSET to the result of the
3537 static struct dw_loc_descr_struct *
3538 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
3540 struct dw_loc_descr_struct *head, *tmp;
3542 offset += cfa->offset;
3546 if (cfa->base_offset)
3549 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3551 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3553 else if (cfa->reg <= 31)
3554 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3556 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3558 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3559 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3560 add_loc_descr (&head, tmp);
3563 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
3564 add_loc_descr (&head, tmp);
3571 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3573 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3574 else if (cfa->reg <= 31)
3575 head = new_loc_descr (DW_OP_breg0 + cfa->reg, offset, 0);
3577 head = new_loc_descr (DW_OP_bregx, cfa->reg, offset);
3583 /* This function fills in aa dw_cfa_location structure from a dwarf location
3584 descriptor sequence. */
3587 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3589 struct dw_loc_descr_struct *ptr;
3591 cfa->base_offset = 0;
3595 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3597 enum dwarf_location_atom op = ptr->dw_loc_opc;
3633 cfa->reg = op - DW_OP_reg0;
3636 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3670 cfa->reg = op - DW_OP_breg0;
3671 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3674 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3675 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3680 case DW_OP_plus_uconst:
3681 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3684 internal_error ("DW_LOC_OP %s not implemented",
3685 dwarf_stack_op_name (ptr->dw_loc_opc));
3689 #endif /* .debug_frame support */
3691 /* And now, the support for symbolic debugging information. */
3692 #ifdef DWARF2_DEBUGGING_INFO
3694 /* .debug_str support. */
3695 static int output_indirect_string (void **, void *);
3697 static void dwarf2out_init (const char *);
3698 static void dwarf2out_finish (const char *);
3699 static void dwarf2out_define (unsigned int, const char *);
3700 static void dwarf2out_undef (unsigned int, const char *);
3701 static void dwarf2out_start_source_file (unsigned, const char *);
3702 static void dwarf2out_end_source_file (unsigned);
3703 static void dwarf2out_begin_block (unsigned, unsigned);
3704 static void dwarf2out_end_block (unsigned, unsigned);
3705 static bool dwarf2out_ignore_block (const_tree);
3706 static void dwarf2out_global_decl (tree);
3707 static void dwarf2out_type_decl (tree, int);
3708 static void dwarf2out_imported_module_or_decl (tree, tree);
3709 static void dwarf2out_abstract_function (tree);
3710 static void dwarf2out_var_location (rtx);
3711 static void dwarf2out_begin_function (tree);
3713 /* The debug hooks structure. */
3715 const struct gcc_debug_hooks dwarf2_debug_hooks =
3721 dwarf2out_start_source_file,
3722 dwarf2out_end_source_file,
3723 dwarf2out_begin_block,
3724 dwarf2out_end_block,
3725 dwarf2out_ignore_block,
3726 dwarf2out_source_line,
3727 dwarf2out_begin_prologue,
3728 debug_nothing_int_charstar, /* end_prologue */
3729 dwarf2out_end_epilogue,
3730 dwarf2out_begin_function,
3731 debug_nothing_int, /* end_function */
3732 dwarf2out_decl, /* function_decl */
3733 dwarf2out_global_decl,
3734 dwarf2out_type_decl, /* type_decl */
3735 dwarf2out_imported_module_or_decl,
3736 debug_nothing_tree, /* deferred_inline_function */
3737 /* The DWARF 2 backend tries to reduce debugging bloat by not
3738 emitting the abstract description of inline functions until
3739 something tries to reference them. */
3740 dwarf2out_abstract_function, /* outlining_inline_function */
3741 debug_nothing_rtx, /* label */
3742 debug_nothing_int, /* handle_pch */
3743 dwarf2out_var_location,
3744 dwarf2out_switch_text_section,
3745 1 /* start_end_main_source_file */
3749 /* NOTE: In the comments in this file, many references are made to
3750 "Debugging Information Entries". This term is abbreviated as `DIE'
3751 throughout the remainder of this file. */
3753 /* An internal representation of the DWARF output is built, and then
3754 walked to generate the DWARF debugging info. The walk of the internal
3755 representation is done after the entire program has been compiled.
3756 The types below are used to describe the internal representation. */
3758 /* Various DIE's use offsets relative to the beginning of the
3759 .debug_info section to refer to each other. */
3761 typedef long int dw_offset;
3763 /* Define typedefs here to avoid circular dependencies. */
3765 typedef struct dw_attr_struct *dw_attr_ref;
3766 typedef struct dw_line_info_struct *dw_line_info_ref;
3767 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3768 typedef struct pubname_struct *pubname_ref;
3769 typedef struct dw_ranges_struct *dw_ranges_ref;
3770 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
3772 /* Each entry in the line_info_table maintains the file and
3773 line number associated with the label generated for that
3774 entry. The label gives the PC value associated with
3775 the line number entry. */
3777 typedef struct dw_line_info_struct GTY(())
3779 unsigned long dw_file_num;
3780 unsigned long dw_line_num;
3784 /* Line information for functions in separate sections; each one gets its
3786 typedef struct dw_separate_line_info_struct GTY(())
3788 unsigned long dw_file_num;
3789 unsigned long dw_line_num;
3790 unsigned long function;
3792 dw_separate_line_info_entry;
3794 /* Each DIE attribute has a field specifying the attribute kind,
3795 a link to the next attribute in the chain, and an attribute value.
3796 Attributes are typically linked below the DIE they modify. */
3798 typedef struct dw_attr_struct GTY(())
3800 enum dwarf_attribute dw_attr;
3801 dw_val_node dw_attr_val;
3805 DEF_VEC_O(dw_attr_node);
3806 DEF_VEC_ALLOC_O(dw_attr_node,gc);
3808 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
3809 The children of each node form a circular list linked by
3810 die_sib. die_child points to the node *before* the "first" child node. */
3812 typedef struct die_struct GTY(())
3814 enum dwarf_tag die_tag;
3816 VEC(dw_attr_node,gc) * die_attr;
3817 dw_die_ref die_parent;
3818 dw_die_ref die_child;
3820 dw_die_ref die_definition; /* ref from a specification to its definition */
3821 dw_offset die_offset;
3822 unsigned long die_abbrev;
3824 /* Die is used and must not be pruned as unused. */
3825 int die_perennial_p;
3826 unsigned int decl_id;
3830 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3831 #define FOR_EACH_CHILD(die, c, expr) do { \
3832 c = die->die_child; \
3836 } while (c != die->die_child); \
3839 /* The pubname structure */
3841 typedef struct pubname_struct GTY(())
3848 DEF_VEC_O(pubname_entry);
3849 DEF_VEC_ALLOC_O(pubname_entry, gc);
3851 struct dw_ranges_struct GTY(())
3853 /* If this is positive, it's a block number, otherwise it's a
3854 bitwise-negated index into dw_ranges_by_label. */
3858 struct dw_ranges_by_label_struct GTY(())
3864 /* The limbo die list structure. */
3865 typedef struct limbo_die_struct GTY(())
3869 struct limbo_die_struct *next;
3873 /* How to start an assembler comment. */
3874 #ifndef ASM_COMMENT_START
3875 #define ASM_COMMENT_START ";#"
3878 /* Define a macro which returns nonzero for a TYPE_DECL which was
3879 implicitly generated for a tagged type.
3881 Note that unlike the gcc front end (which generates a NULL named
3882 TYPE_DECL node for each complete tagged type, each array type, and
3883 each function type node created) the g++ front end generates a
3884 _named_ TYPE_DECL node for each tagged type node created.
3885 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3886 generate a DW_TAG_typedef DIE for them. */
3888 #define TYPE_DECL_IS_STUB(decl) \
3889 (DECL_NAME (decl) == NULL_TREE \
3890 || (DECL_ARTIFICIAL (decl) \
3891 && is_tagged_type (TREE_TYPE (decl)) \
3892 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3893 /* This is necessary for stub decls that \
3894 appear in nested inline functions. */ \
3895 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3896 && (decl_ultimate_origin (decl) \
3897 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3899 /* Information concerning the compilation unit's programming
3900 language, and compiler version. */
3902 /* Fixed size portion of the DWARF compilation unit header. */
3903 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3904 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3906 /* Fixed size portion of public names info. */
3907 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3909 /* Fixed size portion of the address range info. */
3910 #define DWARF_ARANGES_HEADER_SIZE \
3911 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3912 DWARF2_ADDR_SIZE * 2) \
3913 - DWARF_INITIAL_LENGTH_SIZE)
3915 /* Size of padding portion in the address range info. It must be
3916 aligned to twice the pointer size. */
3917 #define DWARF_ARANGES_PAD_SIZE \
3918 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3919 DWARF2_ADDR_SIZE * 2) \
3920 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3922 /* Use assembler line directives if available. */
3923 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3924 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3925 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3927 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3931 /* Minimum line offset in a special line info. opcode.
3932 This value was chosen to give a reasonable range of values. */
3933 #define DWARF_LINE_BASE -10
3935 /* First special line opcode - leave room for the standard opcodes. */
3936 #define DWARF_LINE_OPCODE_BASE 10
3938 /* Range of line offsets in a special line info. opcode. */
3939 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3941 /* Flag that indicates the initial value of the is_stmt_start flag.
3942 In the present implementation, we do not mark any lines as
3943 the beginning of a source statement, because that information
3944 is not made available by the GCC front-end. */
3945 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3947 #ifdef DWARF2_DEBUGGING_INFO
3948 /* This location is used by calc_die_sizes() to keep track
3949 the offset of each DIE within the .debug_info section. */
3950 static unsigned long next_die_offset;
3953 /* Record the root of the DIE's built for the current compilation unit. */
3954 static GTY(()) dw_die_ref comp_unit_die;
3956 /* A list of DIEs with a NULL parent waiting to be relocated. */
3957 static GTY(()) limbo_die_node *limbo_die_list;
3959 /* Filenames referenced by this compilation unit. */
3960 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
3962 /* A hash table of references to DIE's that describe declarations.
3963 The key is a DECL_UID() which is a unique number identifying each decl. */
3964 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
3966 /* Node of the variable location list. */
3967 struct var_loc_node GTY ((chain_next ("%h.next")))
3969 rtx GTY (()) var_loc_note;
3970 const char * GTY (()) label;
3971 const char * GTY (()) section_label;
3972 struct var_loc_node * GTY (()) next;
3975 /* Variable location list. */
3976 struct var_loc_list_def GTY (())
3978 struct var_loc_node * GTY (()) first;
3980 /* Do not mark the last element of the chained list because
3981 it is marked through the chain. */
3982 struct var_loc_node * GTY ((skip ("%h"))) last;
3984 /* DECL_UID of the variable decl. */
3985 unsigned int decl_id;
3987 typedef struct var_loc_list_def var_loc_list;
3990 /* Table of decl location linked lists. */
3991 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
3993 /* A pointer to the base of a list of references to DIE's that
3994 are uniquely identified by their tag, presence/absence of
3995 children DIE's, and list of attribute/value pairs. */
3996 static GTY((length ("abbrev_die_table_allocated")))
3997 dw_die_ref *abbrev_die_table;
3999 /* Number of elements currently allocated for abbrev_die_table. */
4000 static GTY(()) unsigned abbrev_die_table_allocated;
4002 /* Number of elements in type_die_table currently in use. */
4003 static GTY(()) unsigned abbrev_die_table_in_use;
4005 /* Size (in elements) of increments by which we may expand the
4006 abbrev_die_table. */
4007 #define ABBREV_DIE_TABLE_INCREMENT 256
4009 /* A pointer to the base of a table that contains line information
4010 for each source code line in .text in the compilation unit. */
4011 static GTY((length ("line_info_table_allocated")))
4012 dw_line_info_ref line_info_table;
4014 /* Number of elements currently allocated for line_info_table. */
4015 static GTY(()) unsigned line_info_table_allocated;
4017 /* Number of elements in line_info_table currently in use. */
4018 static GTY(()) unsigned line_info_table_in_use;
4020 /* A pointer to the base of a table that contains line information
4021 for each source code line outside of .text in the compilation unit. */
4022 static GTY ((length ("separate_line_info_table_allocated")))
4023 dw_separate_line_info_ref separate_line_info_table;
4025 /* Number of elements currently allocated for separate_line_info_table. */
4026 static GTY(()) unsigned separate_line_info_table_allocated;
4028 /* Number of elements in separate_line_info_table currently in use. */
4029 static GTY(()) unsigned separate_line_info_table_in_use;
4031 /* Size (in elements) of increments by which we may expand the
4033 #define LINE_INFO_TABLE_INCREMENT 1024
4035 /* A pointer to the base of a table that contains a list of publicly
4036 accessible names. */
4037 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
4039 /* A pointer to the base of a table that contains a list of publicly
4040 accessible types. */
4041 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
4043 /* Array of dies for which we should generate .debug_arange info. */
4044 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
4046 /* Number of elements currently allocated for arange_table. */
4047 static GTY(()) unsigned arange_table_allocated;
4049 /* Number of elements in arange_table currently in use. */
4050 static GTY(()) unsigned arange_table_in_use;
4052 /* Size (in elements) of increments by which we may expand the
4054 #define ARANGE_TABLE_INCREMENT 64
4056 /* Array of dies for which we should generate .debug_ranges info. */
4057 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
4059 /* Number of elements currently allocated for ranges_table. */
4060 static GTY(()) unsigned ranges_table_allocated;
4062 /* Number of elements in ranges_table currently in use. */
4063 static GTY(()) unsigned ranges_table_in_use;
4065 /* Array of pairs of labels referenced in ranges_table. */
4066 static GTY ((length ("ranges_by_label_allocated")))
4067 dw_ranges_by_label_ref ranges_by_label;
4069 /* Number of elements currently allocated for ranges_by_label. */
4070 static GTY(()) unsigned ranges_by_label_allocated;
4072 /* Number of elements in ranges_by_label currently in use. */
4073 static GTY(()) unsigned ranges_by_label_in_use;
4075 /* Size (in elements) of increments by which we may expand the
4077 #define RANGES_TABLE_INCREMENT 64
4079 /* Whether we have location lists that need outputting */
4080 static GTY(()) bool have_location_lists;
4082 /* Unique label counter. */
4083 static GTY(()) unsigned int loclabel_num;
4085 #ifdef DWARF2_DEBUGGING_INFO
4086 /* Record whether the function being analyzed contains inlined functions. */
4087 static int current_function_has_inlines;
4089 #if 0 && defined (MIPS_DEBUGGING_INFO)
4090 static int comp_unit_has_inlines;
4093 /* The last file entry emitted by maybe_emit_file(). */
4094 static GTY(()) struct dwarf_file_data * last_emitted_file;
4096 /* Number of internal labels generated by gen_internal_sym(). */
4097 static GTY(()) int label_num;
4099 /* Cached result of previous call to lookup_filename. */
4100 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
4102 #ifdef DWARF2_DEBUGGING_INFO
4104 /* Offset from the "steady-state frame pointer" to the frame base,
4105 within the current function. */
4106 static HOST_WIDE_INT frame_pointer_fb_offset;
4108 /* Forward declarations for functions defined in this file. */
4110 static int is_pseudo_reg (const_rtx);
4111 static tree type_main_variant (tree);
4112 static int is_tagged_type (const_tree);
4113 static const char *dwarf_tag_name (unsigned);
4114 static const char *dwarf_attr_name (unsigned);
4115 static const char *dwarf_form_name (unsigned);
4116 static tree decl_ultimate_origin (const_tree);
4117 static tree block_ultimate_origin (const_tree);
4118 static tree decl_class_context (tree);
4119 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
4120 static inline enum dw_val_class AT_class (dw_attr_ref);
4121 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
4122 static inline unsigned AT_flag (dw_attr_ref);
4123 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
4124 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
4125 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
4126 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
4127 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
4129 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
4130 unsigned int, unsigned char *);
4131 static hashval_t debug_str_do_hash (const void *);
4132 static int debug_str_eq (const void *, const void *);
4133 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
4134 static inline const char *AT_string (dw_attr_ref);
4135 static int AT_string_form (dw_attr_ref);
4136 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
4137 static void add_AT_specification (dw_die_ref, dw_die_ref);
4138 static inline dw_die_ref AT_ref (dw_attr_ref);
4139 static inline int AT_ref_external (dw_attr_ref);
4140 static inline void set_AT_ref_external (dw_attr_ref, int);
4141 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
4142 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
4143 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
4144 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
4146 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
4147 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
4148 static inline rtx AT_addr (dw_attr_ref);
4149 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
4150 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
4151 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
4152 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
4153 unsigned HOST_WIDE_INT);
4154 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
4156 static inline const char *AT_lbl (dw_attr_ref);
4157 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
4158 static const char *get_AT_low_pc (dw_die_ref);
4159 static const char *get_AT_hi_pc (dw_die_ref);
4160 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
4161 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
4162 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
4163 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
4164 static bool is_c_family (void);
4165 static bool is_cxx (void);
4166 static bool is_java (void);
4167 static bool is_fortran (void);
4168 static bool is_ada (void);
4169 static void remove_AT (dw_die_ref, enum dwarf_attribute);
4170 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
4171 static void add_child_die (dw_die_ref, dw_die_ref);
4172 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
4173 static dw_die_ref lookup_type_die (tree);
4174 static void equate_type_number_to_die (tree, dw_die_ref);
4175 static hashval_t decl_die_table_hash (const void *);
4176 static int decl_die_table_eq (const void *, const void *);
4177 static dw_die_ref lookup_decl_die (tree);
4178 static hashval_t decl_loc_table_hash (const void *);
4179 static int decl_loc_table_eq (const void *, const void *);
4180 static var_loc_list *lookup_decl_loc (const_tree);
4181 static void equate_decl_number_to_die (tree, dw_die_ref);
4182 static void add_var_loc_to_decl (tree, struct var_loc_node *);
4183 static void print_spaces (FILE *);
4184 static void print_die (dw_die_ref, FILE *);
4185 static void print_dwarf_line_table (FILE *);
4186 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
4187 static dw_die_ref pop_compile_unit (dw_die_ref);
4188 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
4189 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
4190 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
4191 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
4192 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
4193 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
4194 static int same_die_p (dw_die_ref, dw_die_ref, int *);
4195 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
4196 static void compute_section_prefix (dw_die_ref);
4197 static int is_type_die (dw_die_ref);
4198 static int is_comdat_die (dw_die_ref);
4199 static int is_symbol_die (dw_die_ref);
4200 static void assign_symbol_names (dw_die_ref);
4201 static void break_out_includes (dw_die_ref);
4202 static hashval_t htab_cu_hash (const void *);
4203 static int htab_cu_eq (const void *, const void *);
4204 static void htab_cu_del (void *);
4205 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
4206 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
4207 static void add_sibling_attributes (dw_die_ref);
4208 static void build_abbrev_table (dw_die_ref);
4209 static void output_location_lists (dw_die_ref);
4210 static int constant_size (long unsigned);
4211 static unsigned long size_of_die (dw_die_ref);
4212 static void calc_die_sizes (dw_die_ref);
4213 static void mark_dies (dw_die_ref);
4214 static void unmark_dies (dw_die_ref);
4215 static void unmark_all_dies (dw_die_ref);
4216 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
4217 static unsigned long size_of_aranges (void);
4218 static enum dwarf_form value_format (dw_attr_ref);
4219 static void output_value_format (dw_attr_ref);
4220 static void output_abbrev_section (void);
4221 static void output_die_symbol (dw_die_ref);
4222 static void output_die (dw_die_ref);
4223 static void output_compilation_unit_header (void);
4224 static void output_comp_unit (dw_die_ref, int);
4225 static const char *dwarf2_name (tree, int);
4226 static void add_pubname (tree, dw_die_ref);
4227 static void add_pubtype (tree, dw_die_ref);
4228 static void output_pubnames (VEC (pubname_entry,gc) *);
4229 static void add_arange (tree, dw_die_ref);
4230 static void output_aranges (void);
4231 static unsigned int add_ranges_num (int);
4232 static unsigned int add_ranges (const_tree);
4233 static unsigned int add_ranges_by_labels (const char *, const char *);
4234 static void output_ranges (void);
4235 static void output_line_info (void);
4236 static void output_file_names (void);
4237 static dw_die_ref base_type_die (tree);
4238 static int is_base_type (tree);
4239 static bool is_subrange_type (const_tree);
4240 static dw_die_ref subrange_type_die (tree, dw_die_ref);
4241 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
4242 static int type_is_enum (const_tree);
4243 static unsigned int dbx_reg_number (const_rtx);
4244 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
4245 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
4246 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
4247 enum var_init_status);