1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
39 #include "coretypes.h"
45 #include "hard-reg-set.h"
47 #include "insn-config.h"
55 #include "dwarf2out.h"
56 #include "dwarf2asm.h"
62 #include "diagnostic.h"
65 #include "langhooks.h"
68 #ifdef DWARF2_DEBUGGING_INFO
69 static void dwarf2out_source_line (unsigned int, const char *);
72 /* DWARF2 Abbreviation Glossary:
73 CFA = Canonical Frame Address
74 a fixed address on the stack which identifies a call frame.
75 We define it to be the value of SP just before the call insn.
76 The CFA register and offset, which may change during the course
77 of the function, are used to calculate its value at runtime.
78 CFI = Call Frame Instruction
79 an instruction for the DWARF2 abstract machine
80 CIE = Common Information Entry
81 information describing information common to one or more FDEs
82 DIE = Debugging Information Entry
83 FDE = Frame Description Entry
84 information describing the stack call frame, in particular,
85 how to restore registers
87 DW_CFA_... = DWARF2 CFA call frame instruction
88 DW_TAG_... = DWARF2 DIE tag */
90 /* Decide whether we want to emit frame unwind information for the current
94 dwarf2out_do_frame (void)
96 return (write_symbols == DWARF2_DEBUG
97 || write_symbols == VMS_AND_DWARF2_DEBUG
98 #ifdef DWARF2_FRAME_INFO
101 #ifdef DWARF2_UNWIND_INFO
102 || flag_unwind_tables
103 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
108 /* The size of the target's pointer type. */
110 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
113 /* Default version of targetm.eh_frame_section. Note this must appear
114 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
118 default_eh_frame_section (void)
120 #ifdef EH_FRAME_SECTION_NAME
121 #ifdef HAVE_LD_RO_RW_SECTION_MIXING
122 int fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
123 int per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
124 int lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
128 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
129 && (fde_encoding & 0x70) != DW_EH_PE_aligned
130 && (per_encoding & 0x70) != DW_EH_PE_absptr
131 && (per_encoding & 0x70) != DW_EH_PE_aligned
132 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
133 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
135 named_section_flags (EH_FRAME_SECTION_NAME, flags);
137 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
140 tree label = get_file_function_name ('F');
143 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
144 (*targetm.asm_out.globalize_label) (asm_out_file, IDENTIFIER_POINTER (label));
145 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
149 /* Array of RTXes referenced by the debugging information, which therefore
150 must be kept around forever. */
151 static GTY(()) varray_type used_rtx_varray;
153 /* A pointer to the base of a list of incomplete types which might be
154 completed at some later time. incomplete_types_list needs to be a VARRAY
155 because we want to tell the garbage collector about it. */
156 static GTY(()) varray_type incomplete_types;
158 /* A pointer to the base of a table of references to declaration
159 scopes. This table is a display which tracks the nesting
160 of declaration scopes at the current scope and containing
161 scopes. This table is used to find the proper place to
162 define type declaration DIE's. */
163 static GTY(()) varray_type decl_scope_table;
165 /* How to start an assembler comment. */
166 #ifndef ASM_COMMENT_START
167 #define ASM_COMMENT_START ";#"
170 typedef struct dw_cfi_struct *dw_cfi_ref;
171 typedef struct dw_fde_struct *dw_fde_ref;
172 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
174 /* Call frames are described using a sequence of Call Frame
175 Information instructions. The register number, offset
176 and address fields are provided as possible operands;
177 their use is selected by the opcode field. */
179 enum dw_cfi_oprnd_type {
181 dw_cfi_oprnd_reg_num,
187 typedef union dw_cfi_oprnd_struct GTY(())
189 unsigned long GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
190 long int GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
191 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
192 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
196 typedef struct dw_cfi_struct GTY(())
198 dw_cfi_ref dw_cfi_next;
199 enum dwarf_call_frame_info dw_cfi_opc;
200 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
202 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
207 /* This is how we define the location of the CFA. We use to handle it
208 as REG + OFFSET all the time, but now it can be more complex.
209 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
210 Instead of passing around REG and OFFSET, we pass a copy
211 of this structure. */
212 typedef struct cfa_loc GTY(())
217 int indirect; /* 1 if CFA is accessed via a dereference. */
220 /* All call frame descriptions (FDE's) in the GCC generated DWARF
221 refer to a single Common Information Entry (CIE), defined at
222 the beginning of the .debug_frame section. This use of a single
223 CIE obviates the need to keep track of multiple CIE's
224 in the DWARF generation routines below. */
226 typedef struct dw_fde_struct GTY(())
228 const char *dw_fde_begin;
229 const char *dw_fde_current_label;
230 const char *dw_fde_end;
231 dw_cfi_ref dw_fde_cfi;
232 unsigned funcdef_number;
233 unsigned all_throwers_are_sibcalls : 1;
234 unsigned nothrow : 1;
235 unsigned uses_eh_lsda : 1;
239 /* Maximum size (in bytes) of an artificially generated label. */
240 #define MAX_ARTIFICIAL_LABEL_BYTES 30
242 /* The size of addresses as they appear in the Dwarf 2 data.
243 Some architectures use word addresses to refer to code locations,
244 but Dwarf 2 info always uses byte addresses. On such machines,
245 Dwarf 2 addresses need to be larger than the architecture's
247 #ifndef DWARF2_ADDR_SIZE
248 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
251 /* The size in bytes of a DWARF field indicating an offset or length
252 relative to a debug info section, specified to be 4 bytes in the
253 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
256 #ifndef DWARF_OFFSET_SIZE
257 #define DWARF_OFFSET_SIZE 4
260 /* According to the (draft) DWARF 3 specification, the initial length
261 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
262 bytes are 0xffffffff, followed by the length stored in the next 8
265 However, the SGI/MIPS ABI uses an initial length which is equal to
266 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
268 #ifndef DWARF_INITIAL_LENGTH_SIZE
269 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
272 #define DWARF_VERSION 2
274 /* Round SIZE up to the nearest BOUNDARY. */
275 #define DWARF_ROUND(SIZE,BOUNDARY) \
276 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
278 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
279 #ifndef DWARF_CIE_DATA_ALIGNMENT
280 #ifdef STACK_GROWS_DOWNWARD
281 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
283 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
287 /* A pointer to the base of a table that contains frame description
288 information for each routine. */
289 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
291 /* Number of elements currently allocated for fde_table. */
292 static GTY(()) unsigned fde_table_allocated;
294 /* Number of elements in fde_table currently in use. */
295 static GTY(()) unsigned fde_table_in_use;
297 /* Size (in elements) of increments by which we may expand the
299 #define FDE_TABLE_INCREMENT 256
301 /* A list of call frame insns for the CIE. */
302 static GTY(()) dw_cfi_ref cie_cfi_head;
304 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
305 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
306 attribute that accelerates the lookup of the FDE associated
307 with the subprogram. This variable holds the table index of the FDE
308 associated with the current function (body) definition. */
309 static unsigned current_funcdef_fde;
312 struct indirect_string_node GTY(())
315 unsigned int refcount;
320 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
322 static GTY(()) int dw2_string_counter;
323 static GTY(()) unsigned long dwarf2out_cfi_label_num;
325 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
327 /* Forward declarations for functions defined in this file. */
329 static char *stripattributes (const char *);
330 static const char *dwarf_cfi_name (unsigned);
331 static dw_cfi_ref new_cfi (void);
332 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
333 static void add_fde_cfi (const char *, dw_cfi_ref);
334 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
335 static void lookup_cfa (dw_cfa_location *);
336 static void reg_save (const char *, unsigned, unsigned, long);
337 static void initial_return_save (rtx);
338 static long stack_adjust_offset (rtx);
339 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
340 static void output_call_frame_info (int);
341 static void dwarf2out_stack_adjust (rtx);
342 static void queue_reg_save (const char *, rtx, long);
343 static void flush_queued_reg_saves (void);
344 static bool clobbers_queued_reg_save (rtx);
345 static void dwarf2out_frame_debug_expr (rtx, const char *);
347 /* Support for complex CFA locations. */
348 static void output_cfa_loc (dw_cfi_ref);
349 static void get_cfa_from_loc_descr (dw_cfa_location *,
350 struct dw_loc_descr_struct *);
351 static struct dw_loc_descr_struct *build_cfa_loc
353 static void def_cfa_1 (const char *, dw_cfa_location *);
355 /* How to start an assembler comment. */
356 #ifndef ASM_COMMENT_START
357 #define ASM_COMMENT_START ";#"
360 /* Data and reference forms for relocatable data. */
361 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
362 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
364 #ifndef DEBUG_FRAME_SECTION
365 #define DEBUG_FRAME_SECTION ".debug_frame"
368 #ifndef FUNC_BEGIN_LABEL
369 #define FUNC_BEGIN_LABEL "LFB"
372 #ifndef FUNC_END_LABEL
373 #define FUNC_END_LABEL "LFE"
376 #define FRAME_BEGIN_LABEL "Lframe"
377 #define CIE_AFTER_SIZE_LABEL "LSCIE"
378 #define CIE_END_LABEL "LECIE"
379 #define FDE_LABEL "LSFDE"
380 #define FDE_AFTER_SIZE_LABEL "LASFDE"
381 #define FDE_END_LABEL "LEFDE"
382 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
383 #define LINE_NUMBER_END_LABEL "LELT"
384 #define LN_PROLOG_AS_LABEL "LASLTP"
385 #define LN_PROLOG_END_LABEL "LELTP"
386 #define DIE_LABEL_PREFIX "DW"
388 /* The DWARF 2 CFA column which tracks the return address. Normally this
389 is the column for PC, or the first column after all of the hard
391 #ifndef DWARF_FRAME_RETURN_COLUMN
393 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
395 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
399 /* The mapping from gcc register number to DWARF 2 CFA column number. By
400 default, we just provide columns for all registers. */
401 #ifndef DWARF_FRAME_REGNUM
402 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
405 /* The offset from the incoming value of %sp to the top of the stack frame
406 for the current function. */
407 #ifndef INCOMING_FRAME_SP_OFFSET
408 #define INCOMING_FRAME_SP_OFFSET 0
411 /* Hook used by __throw. */
414 expand_builtin_dwarf_sp_column (void)
416 return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
419 /* Return a pointer to a copy of the section string name S with all
420 attributes stripped off, and an asterisk prepended (for assemble_name). */
423 stripattributes (const char *s)
425 char *stripped = xmalloc (strlen (s) + 2);
430 while (*s && *s != ',')
437 /* Generate code to initialize the register size table. */
440 expand_builtin_init_dwarf_reg_sizes (tree address)
443 enum machine_mode mode = TYPE_MODE (char_type_node);
444 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
445 rtx mem = gen_rtx_MEM (BLKmode, addr);
447 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
448 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
450 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
451 HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]);
456 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
460 /* Convert a DWARF call frame info. operation to its string name */
463 dwarf_cfi_name (unsigned int cfi_opc)
467 case DW_CFA_advance_loc:
468 return "DW_CFA_advance_loc";
470 return "DW_CFA_offset";
472 return "DW_CFA_restore";
476 return "DW_CFA_set_loc";
477 case DW_CFA_advance_loc1:
478 return "DW_CFA_advance_loc1";
479 case DW_CFA_advance_loc2:
480 return "DW_CFA_advance_loc2";
481 case DW_CFA_advance_loc4:
482 return "DW_CFA_advance_loc4";
483 case DW_CFA_offset_extended:
484 return "DW_CFA_offset_extended";
485 case DW_CFA_restore_extended:
486 return "DW_CFA_restore_extended";
487 case DW_CFA_undefined:
488 return "DW_CFA_undefined";
489 case DW_CFA_same_value:
490 return "DW_CFA_same_value";
491 case DW_CFA_register:
492 return "DW_CFA_register";
493 case DW_CFA_remember_state:
494 return "DW_CFA_remember_state";
495 case DW_CFA_restore_state:
496 return "DW_CFA_restore_state";
498 return "DW_CFA_def_cfa";
499 case DW_CFA_def_cfa_register:
500 return "DW_CFA_def_cfa_register";
501 case DW_CFA_def_cfa_offset:
502 return "DW_CFA_def_cfa_offset";
505 case DW_CFA_def_cfa_expression:
506 return "DW_CFA_def_cfa_expression";
507 case DW_CFA_expression:
508 return "DW_CFA_expression";
509 case DW_CFA_offset_extended_sf:
510 return "DW_CFA_offset_extended_sf";
511 case DW_CFA_def_cfa_sf:
512 return "DW_CFA_def_cfa_sf";
513 case DW_CFA_def_cfa_offset_sf:
514 return "DW_CFA_def_cfa_offset_sf";
516 /* SGI/MIPS specific */
517 case DW_CFA_MIPS_advance_loc8:
518 return "DW_CFA_MIPS_advance_loc8";
521 case DW_CFA_GNU_window_save:
522 return "DW_CFA_GNU_window_save";
523 case DW_CFA_GNU_args_size:
524 return "DW_CFA_GNU_args_size";
525 case DW_CFA_GNU_negative_offset_extended:
526 return "DW_CFA_GNU_negative_offset_extended";
529 return "DW_CFA_<unknown>";
533 /* Return a pointer to a newly allocated Call Frame Instruction. */
535 static inline dw_cfi_ref
538 dw_cfi_ref cfi = (dw_cfi_ref) ggc_alloc (sizeof (dw_cfi_node));
540 cfi->dw_cfi_next = NULL;
541 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
542 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
547 /* Add a Call Frame Instruction to list of instructions. */
550 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
554 /* Find the end of the chain. */
555 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
561 /* Generate a new label for the CFI info to refer to. */
564 dwarf2out_cfi_label (void)
566 static char label[20];
568 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
569 ASM_OUTPUT_LABEL (asm_out_file, label);
573 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
574 or to the CIE if LABEL is NULL. */
577 add_fde_cfi (const char *label, dw_cfi_ref cfi)
581 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
584 label = dwarf2out_cfi_label ();
586 if (fde->dw_fde_current_label == NULL
587 || strcmp (label, fde->dw_fde_current_label) != 0)
591 fde->dw_fde_current_label = label = xstrdup (label);
593 /* Set the location counter to the new label. */
595 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
596 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
597 add_cfi (&fde->dw_fde_cfi, xcfi);
600 add_cfi (&fde->dw_fde_cfi, cfi);
604 add_cfi (&cie_cfi_head, cfi);
607 /* Subroutine of lookup_cfa. */
610 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
612 switch (cfi->dw_cfi_opc)
614 case DW_CFA_def_cfa_offset:
615 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
617 case DW_CFA_def_cfa_register:
618 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
621 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
622 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
624 case DW_CFA_def_cfa_expression:
625 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
632 /* Find the previous value for the CFA. */
635 lookup_cfa (dw_cfa_location *loc)
639 loc->reg = (unsigned long) -1;
642 loc->base_offset = 0;
644 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
645 lookup_cfa_1 (cfi, loc);
647 if (fde_table_in_use)
649 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
650 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
651 lookup_cfa_1 (cfi, loc);
655 /* The current rule for calculating the DWARF2 canonical frame address. */
656 static dw_cfa_location cfa;
658 /* The register used for saving registers to the stack, and its offset
660 static dw_cfa_location cfa_store;
662 /* The running total of the size of arguments pushed onto the stack. */
663 static long args_size;
665 /* The last args_size we actually output. */
666 static long old_args_size;
668 /* Entry point to update the canonical frame address (CFA).
669 LABEL is passed to add_fde_cfi. The value of CFA is now to be
670 calculated from REG+OFFSET. */
673 dwarf2out_def_cfa (const char *label, unsigned int reg, long int offset)
680 def_cfa_1 (label, &loc);
683 /* This routine does the actual work. The CFA is now calculated from
684 the dw_cfa_location structure. */
687 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
690 dw_cfa_location old_cfa, loc;
695 if (cfa_store.reg == loc.reg && loc.indirect == 0)
696 cfa_store.offset = loc.offset;
698 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
699 lookup_cfa (&old_cfa);
701 /* If nothing changed, no need to issue any call frame instructions. */
702 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
703 && loc.indirect == old_cfa.indirect
704 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
709 if (loc.reg == old_cfa.reg && !loc.indirect)
711 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
712 indicating the CFA register did not change but the offset
714 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
715 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
718 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
719 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
722 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
723 indicating the CFA register has changed to <register> but the
724 offset has not changed. */
725 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
726 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
730 else if (loc.indirect == 0)
732 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
733 indicating the CFA register has changed to <register> with
734 the specified offset. */
735 cfi->dw_cfi_opc = DW_CFA_def_cfa;
736 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
737 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
741 /* Construct a DW_CFA_def_cfa_expression instruction to
742 calculate the CFA using a full location expression since no
743 register-offset pair is available. */
744 struct dw_loc_descr_struct *loc_list;
746 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
747 loc_list = build_cfa_loc (&loc);
748 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
751 add_fde_cfi (label, cfi);
754 /* Add the CFI for saving a register. REG is the CFA column number.
755 LABEL is passed to add_fde_cfi.
756 If SREG is -1, the register is saved at OFFSET from the CFA;
757 otherwise it is saved in SREG. */
760 reg_save (const char *label, unsigned int reg, unsigned int sreg, long int offset)
762 dw_cfi_ref cfi = new_cfi ();
764 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
766 /* The following comparison is correct. -1 is used to indicate that
767 the value isn't a register number. */
768 if (sreg == (unsigned int) -1)
771 /* The register number won't fit in 6 bits, so we have to use
773 cfi->dw_cfi_opc = DW_CFA_offset_extended;
775 cfi->dw_cfi_opc = DW_CFA_offset;
777 #ifdef ENABLE_CHECKING
779 /* If we get an offset that is not a multiple of
780 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
781 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
783 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
785 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
789 offset /= DWARF_CIE_DATA_ALIGNMENT;
791 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
793 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
795 else if (sreg == reg)
796 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
800 cfi->dw_cfi_opc = DW_CFA_register;
801 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
804 add_fde_cfi (label, cfi);
807 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
808 This CFI tells the unwinder that it needs to restore the window registers
809 from the previous frame's window save area.
811 ??? Perhaps we should note in the CIE where windows are saved (instead of
812 assuming 0(cfa)) and what registers are in the window. */
815 dwarf2out_window_save (const char *label)
817 dw_cfi_ref cfi = new_cfi ();
819 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
820 add_fde_cfi (label, cfi);
823 /* Add a CFI to update the running total of the size of arguments
824 pushed onto the stack. */
827 dwarf2out_args_size (const char *label, long int size)
831 if (size == old_args_size)
834 old_args_size = size;
837 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
838 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
839 add_fde_cfi (label, cfi);
842 /* Entry point for saving a register to the stack. REG is the GCC register
843 number. LABEL and OFFSET are passed to reg_save. */
846 dwarf2out_reg_save (const char *label, unsigned int reg, long int offset)
848 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
851 /* Entry point for saving the return address in the stack.
852 LABEL and OFFSET are passed to reg_save. */
855 dwarf2out_return_save (const char *label, long int offset)
857 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
860 /* Entry point for saving the return address in a register.
861 LABEL and SREG are passed to reg_save. */
864 dwarf2out_return_reg (const char *label, unsigned int sreg)
866 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
869 /* Record the initial position of the return address. RTL is
870 INCOMING_RETURN_ADDR_RTX. */
873 initial_return_save (rtx rtl)
875 unsigned int reg = (unsigned int) -1;
876 HOST_WIDE_INT offset = 0;
878 switch (GET_CODE (rtl))
881 /* RA is in a register. */
882 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
886 /* RA is on the stack. */
888 switch (GET_CODE (rtl))
891 if (REGNO (rtl) != STACK_POINTER_REGNUM)
897 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
899 offset = INTVAL (XEXP (rtl, 1));
903 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
905 offset = -INTVAL (XEXP (rtl, 1));
915 /* The return address is at some offset from any value we can
916 actually load. For instance, on the SPARC it is in %i7+8. Just
917 ignore the offset for now; it doesn't matter for unwinding frames. */
918 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
920 initial_return_save (XEXP (rtl, 0));
927 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
930 /* Given a SET, calculate the amount of stack adjustment it
934 stack_adjust_offset (rtx pattern)
936 rtx src = SET_SRC (pattern);
937 rtx dest = SET_DEST (pattern);
938 HOST_WIDE_INT offset = 0;
941 if (dest == stack_pointer_rtx)
943 /* (set (reg sp) (plus (reg sp) (const_int))) */
944 code = GET_CODE (src);
945 if (! (code == PLUS || code == MINUS)
946 || XEXP (src, 0) != stack_pointer_rtx
947 || GET_CODE (XEXP (src, 1)) != CONST_INT)
950 offset = INTVAL (XEXP (src, 1));
954 else if (GET_CODE (dest) == MEM)
956 /* (set (mem (pre_dec (reg sp))) (foo)) */
957 src = XEXP (dest, 0);
958 code = GET_CODE (src);
964 if (XEXP (src, 0) == stack_pointer_rtx)
966 rtx val = XEXP (XEXP (src, 1), 1);
967 /* We handle only adjustments by constant amount. */
968 if (GET_CODE (XEXP (src, 1)) != PLUS ||
969 GET_CODE (val) != CONST_INT)
971 offset = -INTVAL (val);
978 if (XEXP (src, 0) == stack_pointer_rtx)
980 offset = GET_MODE_SIZE (GET_MODE (dest));
987 if (XEXP (src, 0) == stack_pointer_rtx)
989 offset = -GET_MODE_SIZE (GET_MODE (dest));
1004 /* Check INSN to see if it looks like a push or a stack adjustment, and
1005 make a note of it if it does. EH uses this information to find out how
1006 much extra space it needs to pop off the stack. */
1009 dwarf2out_stack_adjust (rtx insn)
1011 HOST_WIDE_INT offset;
1015 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
1017 /* Extract the size of the args from the CALL rtx itself. */
1018 insn = PATTERN (insn);
1019 if (GET_CODE (insn) == PARALLEL)
1020 insn = XVECEXP (insn, 0, 0);
1021 if (GET_CODE (insn) == SET)
1022 insn = SET_SRC (insn);
1023 if (GET_CODE (insn) != CALL)
1026 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1030 /* If only calls can throw, and we have a frame pointer,
1031 save up adjustments until we see the CALL_INSN. */
1032 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1035 if (GET_CODE (insn) == BARRIER)
1037 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1038 the compiler will have already emitted a stack adjustment, but
1039 doesn't bother for calls to noreturn functions. */
1040 #ifdef STACK_GROWS_DOWNWARD
1041 offset = -args_size;
1046 else if (GET_CODE (PATTERN (insn)) == SET)
1047 offset = stack_adjust_offset (PATTERN (insn));
1048 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1049 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1051 /* There may be stack adjustments inside compound insns. Search
1053 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1054 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1055 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1063 if (cfa.reg == STACK_POINTER_REGNUM)
1064 cfa.offset += offset;
1066 #ifndef STACK_GROWS_DOWNWARD
1070 args_size += offset;
1074 label = dwarf2out_cfi_label ();
1075 def_cfa_1 (label, &cfa);
1076 dwarf2out_args_size (label, args_size);
1081 /* We delay emitting a register save until either (a) we reach the end
1082 of the prologue or (b) the register is clobbered. This clusters
1083 register saves so that there are fewer pc advances. */
1085 struct queued_reg_save GTY(())
1087 struct queued_reg_save *next;
1092 static GTY(()) struct queued_reg_save *queued_reg_saves;
1094 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1095 static const char *last_reg_save_label;
1098 queue_reg_save (const char *label, rtx reg, long int offset)
1100 struct queued_reg_save *q = ggc_alloc (sizeof (*q));
1102 q->next = queued_reg_saves;
1104 q->cfa_offset = offset;
1105 queued_reg_saves = q;
1107 last_reg_save_label = label;
1111 flush_queued_reg_saves (void)
1113 struct queued_reg_save *q, *next;
1115 for (q = queued_reg_saves; q; q = next)
1117 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1121 queued_reg_saves = NULL;
1122 last_reg_save_label = NULL;
1126 clobbers_queued_reg_save (rtx insn)
1128 struct queued_reg_save *q;
1130 for (q = queued_reg_saves; q; q = q->next)
1131 if (modified_in_p (q->reg, insn))
1138 /* A temporary register holding an integral value used in adjusting SP
1139 or setting up the store_reg. The "offset" field holds the integer
1140 value, not an offset. */
1141 static dw_cfa_location cfa_temp;
1143 /* Record call frame debugging information for an expression EXPR,
1144 which either sets SP or FP (adjusting how we calculate the frame
1145 address) or saves a register to the stack. LABEL indicates the
1148 This function encodes a state machine mapping rtxes to actions on
1149 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1150 users need not read the source code.
1152 The High-Level Picture
1154 Changes in the register we use to calculate the CFA: Currently we
1155 assume that if you copy the CFA register into another register, we
1156 should take the other one as the new CFA register; this seems to
1157 work pretty well. If it's wrong for some target, it's simple
1158 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1160 Changes in the register we use for saving registers to the stack:
1161 This is usually SP, but not always. Again, we deduce that if you
1162 copy SP into another register (and SP is not the CFA register),
1163 then the new register is the one we will be using for register
1164 saves. This also seems to work.
1166 Register saves: There's not much guesswork about this one; if
1167 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1168 register save, and the register used to calculate the destination
1169 had better be the one we think we're using for this purpose.
1171 Except: If the register being saved is the CFA register, and the
1172 offset is nonzero, we are saving the CFA, so we assume we have to
1173 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1174 the intent is to save the value of SP from the previous frame.
1176 Invariants / Summaries of Rules
1178 cfa current rule for calculating the CFA. It usually
1179 consists of a register and an offset.
1180 cfa_store register used by prologue code to save things to the stack
1181 cfa_store.offset is the offset from the value of
1182 cfa_store.reg to the actual CFA
1183 cfa_temp register holding an integral value. cfa_temp.offset
1184 stores the value, which will be used to adjust the
1185 stack pointer. cfa_temp is also used like cfa_store,
1186 to track stores to the stack via fp or a temp reg.
1188 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1189 with cfa.reg as the first operand changes the cfa.reg and its
1190 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1193 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1194 expression yielding a constant. This sets cfa_temp.reg
1195 and cfa_temp.offset.
1197 Rule 5: Create a new register cfa_store used to save items to the
1200 Rules 10-14: Save a register to the stack. Define offset as the
1201 difference of the original location and cfa_store's
1202 location (or cfa_temp's location if cfa_temp is used).
1206 "{a,b}" indicates a choice of a xor b.
1207 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1210 (set <reg1> <reg2>:cfa.reg)
1211 effects: cfa.reg = <reg1>
1212 cfa.offset unchanged
1213 cfa_temp.reg = <reg1>
1214 cfa_temp.offset = cfa.offset
1217 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1218 {<const_int>,<reg>:cfa_temp.reg}))
1219 effects: cfa.reg = sp if fp used
1220 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1221 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1222 if cfa_store.reg==sp
1225 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1226 effects: cfa.reg = fp
1227 cfa_offset += +/- <const_int>
1230 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1231 constraints: <reg1> != fp
1233 effects: cfa.reg = <reg1>
1234 cfa_temp.reg = <reg1>
1235 cfa_temp.offset = cfa.offset
1238 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1239 constraints: <reg1> != fp
1241 effects: cfa_store.reg = <reg1>
1242 cfa_store.offset = cfa.offset - cfa_temp.offset
1245 (set <reg> <const_int>)
1246 effects: cfa_temp.reg = <reg>
1247 cfa_temp.offset = <const_int>
1250 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1251 effects: cfa_temp.reg = <reg1>
1252 cfa_temp.offset |= <const_int>
1255 (set <reg> (high <exp>))
1259 (set <reg> (lo_sum <exp> <const_int>))
1260 effects: cfa_temp.reg = <reg>
1261 cfa_temp.offset = <const_int>
1264 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1265 effects: cfa_store.offset -= <const_int>
1266 cfa.offset = cfa_store.offset if cfa.reg == sp
1268 cfa.base_offset = -cfa_store.offset
1271 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1272 effects: cfa_store.offset += -/+ mode_size(mem)
1273 cfa.offset = cfa_store.offset if cfa.reg == sp
1275 cfa.base_offset = -cfa_store.offset
1278 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1281 effects: cfa.reg = <reg1>
1282 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1285 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1286 effects: cfa.reg = <reg1>
1287 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1290 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1291 effects: cfa.reg = <reg1>
1292 cfa.base_offset = -cfa_temp.offset
1293 cfa_temp.offset -= mode_size(mem) */
1296 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1299 HOST_WIDE_INT offset;
1301 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1302 the PARALLEL independently. The first element is always processed if
1303 it is a SET. This is for backward compatibility. Other elements
1304 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1305 flag is set in them. */
1306 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1309 int limit = XVECLEN (expr, 0);
1311 for (par_index = 0; par_index < limit; par_index++)
1312 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1313 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1315 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1320 if (GET_CODE (expr) != SET)
1323 src = SET_SRC (expr);
1324 dest = SET_DEST (expr);
1326 switch (GET_CODE (dest))
1330 /* Update the CFA rule wrt SP or FP. Make sure src is
1331 relative to the current CFA register. */
1332 switch (GET_CODE (src))
1334 /* Setting FP from SP. */
1336 if (cfa.reg == (unsigned) REGNO (src))
1342 /* We used to require that dest be either SP or FP, but the
1343 ARM copies SP to a temporary register, and from there to
1344 FP. So we just rely on the backends to only set
1345 RTX_FRAME_RELATED_P on appropriate insns. */
1346 cfa.reg = REGNO (dest);
1347 cfa_temp.reg = cfa.reg;
1348 cfa_temp.offset = cfa.offset;
1354 if (dest == stack_pointer_rtx)
1358 switch (GET_CODE (XEXP (src, 1)))
1361 offset = INTVAL (XEXP (src, 1));
1364 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1366 offset = cfa_temp.offset;
1372 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1374 /* Restoring SP from FP in the epilogue. */
1375 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1377 cfa.reg = STACK_POINTER_REGNUM;
1379 else if (GET_CODE (src) == LO_SUM)
1380 /* Assume we've set the source reg of the LO_SUM from sp. */
1382 else if (XEXP (src, 0) != stack_pointer_rtx)
1385 if (GET_CODE (src) != MINUS)
1387 if (cfa.reg == STACK_POINTER_REGNUM)
1388 cfa.offset += offset;
1389 if (cfa_store.reg == STACK_POINTER_REGNUM)
1390 cfa_store.offset += offset;
1392 else if (dest == hard_frame_pointer_rtx)
1395 /* Either setting the FP from an offset of the SP,
1396 or adjusting the FP */
1397 if (! frame_pointer_needed)
1400 if (GET_CODE (XEXP (src, 0)) == REG
1401 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1402 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1404 offset = INTVAL (XEXP (src, 1));
1405 if (GET_CODE (src) != MINUS)
1407 cfa.offset += offset;
1408 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1415 if (GET_CODE (src) == MINUS)
1419 if (GET_CODE (XEXP (src, 0)) == REG
1420 && REGNO (XEXP (src, 0)) == cfa.reg
1421 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1423 /* Setting a temporary CFA register that will be copied
1424 into the FP later on. */
1425 offset = - INTVAL (XEXP (src, 1));
1426 cfa.offset += offset;
1427 cfa.reg = REGNO (dest);
1428 /* Or used to save regs to the stack. */
1429 cfa_temp.reg = cfa.reg;
1430 cfa_temp.offset = cfa.offset;
1434 else if (GET_CODE (XEXP (src, 0)) == REG
1435 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1436 && XEXP (src, 1) == stack_pointer_rtx)
1438 /* Setting a scratch register that we will use instead
1439 of SP for saving registers to the stack. */
1440 if (cfa.reg != STACK_POINTER_REGNUM)
1442 cfa_store.reg = REGNO (dest);
1443 cfa_store.offset = cfa.offset - cfa_temp.offset;
1447 else if (GET_CODE (src) == LO_SUM
1448 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1450 cfa_temp.reg = REGNO (dest);
1451 cfa_temp.offset = INTVAL (XEXP (src, 1));
1460 cfa_temp.reg = REGNO (dest);
1461 cfa_temp.offset = INTVAL (src);
1466 if (GET_CODE (XEXP (src, 0)) != REG
1467 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1468 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1471 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1472 cfa_temp.reg = REGNO (dest);
1473 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1476 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1477 which will fill in all of the bits. */
1486 def_cfa_1 (label, &cfa);
1490 if (GET_CODE (src) != REG)
1493 /* Saving a register to the stack. Make sure dest is relative to the
1495 switch (GET_CODE (XEXP (dest, 0)))
1500 /* We can't handle variable size modifications. */
1501 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1503 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1505 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1506 || cfa_store.reg != STACK_POINTER_REGNUM)
1509 cfa_store.offset += offset;
1510 if (cfa.reg == STACK_POINTER_REGNUM)
1511 cfa.offset = cfa_store.offset;
1513 offset = -cfa_store.offset;
1519 offset = GET_MODE_SIZE (GET_MODE (dest));
1520 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1523 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1524 || cfa_store.reg != STACK_POINTER_REGNUM)
1527 cfa_store.offset += offset;
1528 if (cfa.reg == STACK_POINTER_REGNUM)
1529 cfa.offset = cfa_store.offset;
1531 offset = -cfa_store.offset;
1535 /* With an offset. */
1539 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1541 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1542 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1545 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1546 offset -= cfa_store.offset;
1547 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1548 offset -= cfa_temp.offset;
1554 /* Without an offset. */
1556 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1557 offset = -cfa_store.offset;
1558 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1559 offset = -cfa_temp.offset;
1566 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1568 offset = -cfa_temp.offset;
1569 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1576 if (REGNO (src) != STACK_POINTER_REGNUM
1577 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1578 && (unsigned) REGNO (src) == cfa.reg)
1580 /* We're storing the current CFA reg into the stack. */
1582 if (cfa.offset == 0)
1584 /* If the source register is exactly the CFA, assume
1585 we're saving SP like any other register; this happens
1587 def_cfa_1 (label, &cfa);
1588 queue_reg_save (label, stack_pointer_rtx, offset);
1593 /* Otherwise, we'll need to look in the stack to
1594 calculate the CFA. */
1595 rtx x = XEXP (dest, 0);
1597 if (GET_CODE (x) != REG)
1599 if (GET_CODE (x) != REG)
1602 cfa.reg = REGNO (x);
1603 cfa.base_offset = offset;
1605 def_cfa_1 (label, &cfa);
1610 def_cfa_1 (label, &cfa);
1611 queue_reg_save (label, src, offset);
1619 /* Record call frame debugging information for INSN, which either
1620 sets SP or FP (adjusting how we calculate the frame address) or saves a
1621 register to the stack. If INSN is NULL_RTX, initialize our state. */
1624 dwarf2out_frame_debug (rtx insn)
1629 if (insn == NULL_RTX)
1631 /* Flush any queued register saves. */
1632 flush_queued_reg_saves ();
1634 /* Set up state for generating call frame debug info. */
1636 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1639 cfa.reg = STACK_POINTER_REGNUM;
1642 cfa_temp.offset = 0;
1646 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1647 flush_queued_reg_saves ();
1649 if (! RTX_FRAME_RELATED_P (insn))
1651 if (!ACCUMULATE_OUTGOING_ARGS)
1652 dwarf2out_stack_adjust (insn);
1657 label = dwarf2out_cfi_label ();
1658 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1660 insn = XEXP (src, 0);
1662 insn = PATTERN (insn);
1664 dwarf2out_frame_debug_expr (insn, label);
1669 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1670 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1671 (enum dwarf_call_frame_info cfi);
1673 static enum dw_cfi_oprnd_type
1674 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1679 case DW_CFA_GNU_window_save:
1680 return dw_cfi_oprnd_unused;
1682 case DW_CFA_set_loc:
1683 case DW_CFA_advance_loc1:
1684 case DW_CFA_advance_loc2:
1685 case DW_CFA_advance_loc4:
1686 case DW_CFA_MIPS_advance_loc8:
1687 return dw_cfi_oprnd_addr;
1690 case DW_CFA_offset_extended:
1691 case DW_CFA_def_cfa:
1692 case DW_CFA_offset_extended_sf:
1693 case DW_CFA_def_cfa_sf:
1694 case DW_CFA_restore_extended:
1695 case DW_CFA_undefined:
1696 case DW_CFA_same_value:
1697 case DW_CFA_def_cfa_register:
1698 case DW_CFA_register:
1699 return dw_cfi_oprnd_reg_num;
1701 case DW_CFA_def_cfa_offset:
1702 case DW_CFA_GNU_args_size:
1703 case DW_CFA_def_cfa_offset_sf:
1704 return dw_cfi_oprnd_offset;
1706 case DW_CFA_def_cfa_expression:
1707 case DW_CFA_expression:
1708 return dw_cfi_oprnd_loc;
1715 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1716 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1717 (enum dwarf_call_frame_info cfi);
1719 static enum dw_cfi_oprnd_type
1720 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1724 case DW_CFA_def_cfa:
1725 case DW_CFA_def_cfa_sf:
1727 case DW_CFA_offset_extended_sf:
1728 case DW_CFA_offset_extended:
1729 return dw_cfi_oprnd_offset;
1731 case DW_CFA_register:
1732 return dw_cfi_oprnd_reg_num;
1735 return dw_cfi_oprnd_unused;
1739 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1741 /* Output a Call Frame Information opcode and its operand(s). */
1744 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
1746 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1747 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1748 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1749 "DW_CFA_advance_loc 0x%lx",
1750 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1751 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1753 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1754 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1755 "DW_CFA_offset, column 0x%lx",
1756 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1757 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1759 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1760 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1761 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1762 "DW_CFA_restore, column 0x%lx",
1763 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1766 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1767 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1769 switch (cfi->dw_cfi_opc)
1771 case DW_CFA_set_loc:
1773 dw2_asm_output_encoded_addr_rtx (
1774 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1775 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1778 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1779 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1782 case DW_CFA_advance_loc1:
1783 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1784 fde->dw_fde_current_label, NULL);
1785 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1788 case DW_CFA_advance_loc2:
1789 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1790 fde->dw_fde_current_label, NULL);
1791 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1794 case DW_CFA_advance_loc4:
1795 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1796 fde->dw_fde_current_label, NULL);
1797 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1800 case DW_CFA_MIPS_advance_loc8:
1801 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1802 fde->dw_fde_current_label, NULL);
1803 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1806 case DW_CFA_offset_extended:
1807 case DW_CFA_def_cfa:
1808 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1810 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1813 case DW_CFA_offset_extended_sf:
1814 case DW_CFA_def_cfa_sf:
1815 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1817 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1820 case DW_CFA_restore_extended:
1821 case DW_CFA_undefined:
1822 case DW_CFA_same_value:
1823 case DW_CFA_def_cfa_register:
1824 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1828 case DW_CFA_register:
1829 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1831 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
1835 case DW_CFA_def_cfa_offset:
1836 case DW_CFA_GNU_args_size:
1837 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1840 case DW_CFA_def_cfa_offset_sf:
1841 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1844 case DW_CFA_GNU_window_save:
1847 case DW_CFA_def_cfa_expression:
1848 case DW_CFA_expression:
1849 output_cfa_loc (cfi);
1852 case DW_CFA_GNU_negative_offset_extended:
1853 /* Obsoleted by DW_CFA_offset_extended_sf. */
1862 /* Output the call frame information used to used to record information
1863 that relates to calculating the frame pointer, and records the
1864 location of saved registers. */
1867 output_call_frame_info (int for_eh)
1872 char l1[20], l2[20], section_start_label[20];
1873 bool any_lsda_needed = false;
1874 char augmentation[6];
1875 int augmentation_size;
1876 int fde_encoding = DW_EH_PE_absptr;
1877 int per_encoding = DW_EH_PE_absptr;
1878 int lsda_encoding = DW_EH_PE_absptr;
1880 /* Don't emit a CIE if there won't be any FDEs. */
1881 if (fde_table_in_use == 0)
1884 /* If we don't have any functions we'll want to unwind out of, don't
1885 emit any EH unwind information. Note that if exceptions aren't
1886 enabled, we won't have collected nothrow information, and if we
1887 asked for asynchronous tables, we always want this info. */
1890 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
1892 for (i = 0; i < fde_table_in_use; i++)
1893 if (fde_table[i].uses_eh_lsda)
1894 any_eh_needed = any_lsda_needed = true;
1895 else if (! fde_table[i].nothrow
1896 && ! fde_table[i].all_throwers_are_sibcalls)
1897 any_eh_needed = true;
1899 if (! any_eh_needed)
1903 /* We're going to be generating comments, so turn on app. */
1908 (*targetm.asm_out.eh_frame_section) ();
1910 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1912 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1913 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1915 /* Output the CIE. */
1916 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1917 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1918 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1919 "Length of Common Information Entry");
1920 ASM_OUTPUT_LABEL (asm_out_file, l1);
1922 /* Now that the CIE pointer is PC-relative for EH,
1923 use 0 to identify the CIE. */
1924 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1925 (for_eh ? 0 : DW_CIE_ID),
1926 "CIE Identifier Tag");
1928 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1930 augmentation[0] = 0;
1931 augmentation_size = 0;
1937 z Indicates that a uleb128 is present to size the
1938 augmentation section.
1939 L Indicates the encoding (and thus presence) of
1940 an LSDA pointer in the FDE augmentation.
1941 R Indicates a non-default pointer encoding for
1943 P Indicates the presence of an encoding + language
1944 personality routine in the CIE augmentation. */
1946 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1947 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1948 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1950 p = augmentation + 1;
1951 if (eh_personality_libfunc)
1954 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1956 if (any_lsda_needed)
1959 augmentation_size += 1;
1961 if (fde_encoding != DW_EH_PE_absptr)
1964 augmentation_size += 1;
1966 if (p > augmentation + 1)
1968 augmentation[0] = 'z';
1972 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1973 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1975 int offset = ( 4 /* Length */
1977 + 1 /* CIE version */
1978 + strlen (augmentation) + 1 /* Augmentation */
1979 + size_of_uleb128 (1) /* Code alignment */
1980 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1982 + 1 /* Augmentation size */
1983 + 1 /* Personality encoding */ );
1984 int pad = -offset & (PTR_SIZE - 1);
1986 augmentation_size += pad;
1988 /* Augmentations should be small, so there's scarce need to
1989 iterate for a solution. Die if we exceed one uleb128 byte. */
1990 if (size_of_uleb128 (augmentation_size) != 1)
1995 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1996 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1997 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1998 "CIE Data Alignment Factor");
1999 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
2001 if (augmentation[0])
2003 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2004 if (eh_personality_libfunc)
2006 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2007 eh_data_format_name (per_encoding));
2008 dw2_asm_output_encoded_addr_rtx (per_encoding,
2009 eh_personality_libfunc, NULL);
2012 if (any_lsda_needed)
2013 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2014 eh_data_format_name (lsda_encoding));
2016 if (fde_encoding != DW_EH_PE_absptr)
2017 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2018 eh_data_format_name (fde_encoding));
2021 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2022 output_cfi (cfi, NULL, for_eh);
2024 /* Pad the CIE out to an address sized boundary. */
2025 ASM_OUTPUT_ALIGN (asm_out_file,
2026 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2027 ASM_OUTPUT_LABEL (asm_out_file, l2);
2029 /* Loop through all of the FDE's. */
2030 for (i = 0; i < fde_table_in_use; i++)
2032 fde = &fde_table[i];
2034 /* Don't emit EH unwind info for leaf functions that don't need it. */
2035 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2036 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2037 && !fde->uses_eh_lsda)
2040 (*targetm.asm_out.internal_label) (asm_out_file, FDE_LABEL, for_eh + i * 2);
2041 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2042 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2043 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2045 ASM_OUTPUT_LABEL (asm_out_file, l1);
2048 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2050 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2055 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2056 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
2057 "FDE initial location");
2058 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2059 fde->dw_fde_end, fde->dw_fde_begin,
2060 "FDE address range");
2064 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2065 "FDE initial location");
2066 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2067 fde->dw_fde_end, fde->dw_fde_begin,
2068 "FDE address range");
2071 if (augmentation[0])
2073 if (any_lsda_needed)
2075 int size = size_of_encoded_value (lsda_encoding);
2077 if (lsda_encoding == DW_EH_PE_aligned)
2079 int offset = ( 4 /* Length */
2080 + 4 /* CIE offset */
2081 + 2 * size_of_encoded_value (fde_encoding)
2082 + 1 /* Augmentation size */ );
2083 int pad = -offset & (PTR_SIZE - 1);
2086 if (size_of_uleb128 (size) != 1)
2090 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2092 if (fde->uses_eh_lsda)
2094 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2095 fde->funcdef_number);
2096 dw2_asm_output_encoded_addr_rtx (
2097 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2098 "Language Specific Data Area");
2102 if (lsda_encoding == DW_EH_PE_aligned)
2103 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2105 (size_of_encoded_value (lsda_encoding), 0,
2106 "Language Specific Data Area (none)");
2110 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2113 /* Loop through the Call Frame Instructions associated with
2115 fde->dw_fde_current_label = fde->dw_fde_begin;
2116 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2117 output_cfi (cfi, fde, for_eh);
2119 /* Pad the FDE out to an address sized boundary. */
2120 ASM_OUTPUT_ALIGN (asm_out_file,
2121 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2122 ASM_OUTPUT_LABEL (asm_out_file, l2);
2125 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2126 dw2_asm_output_data (4, 0, "End of Table");
2127 #ifdef MIPS_DEBUGGING_INFO
2128 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2129 get a value of 0. Putting .align 0 after the label fixes it. */
2130 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2133 /* Turn off app to make assembly quicker. */
2138 /* Output a marker (i.e. a label) for the beginning of a function, before
2142 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2143 const char *file ATTRIBUTE_UNUSED)
2145 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2148 current_function_func_begin_label = 0;
2150 #ifdef IA64_UNWIND_INFO
2151 /* ??? current_function_func_begin_label is also used by except.c
2152 for call-site information. We must emit this label if it might
2154 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2155 && ! dwarf2out_do_frame ())
2158 if (! dwarf2out_do_frame ())
2162 function_section (current_function_decl);
2163 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2164 current_function_funcdef_no);
2165 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2166 current_function_funcdef_no);
2167 current_function_func_begin_label = get_identifier (label);
2169 #ifdef IA64_UNWIND_INFO
2170 /* We can elide the fde allocation if we're not emitting debug info. */
2171 if (! dwarf2out_do_frame ())
2175 /* Expand the fde table if necessary. */
2176 if (fde_table_in_use == fde_table_allocated)
2178 fde_table_allocated += FDE_TABLE_INCREMENT;
2179 fde_table = ggc_realloc (fde_table,
2180 fde_table_allocated * sizeof (dw_fde_node));
2181 memset (fde_table + fde_table_in_use, 0,
2182 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2185 /* Record the FDE associated with this function. */
2186 current_funcdef_fde = fde_table_in_use;
2188 /* Add the new FDE at the end of the fde_table. */
2189 fde = &fde_table[fde_table_in_use++];
2190 fde->dw_fde_begin = xstrdup (label);
2191 fde->dw_fde_current_label = NULL;
2192 fde->dw_fde_end = NULL;
2193 fde->dw_fde_cfi = NULL;
2194 fde->funcdef_number = current_function_funcdef_no;
2195 fde->nothrow = current_function_nothrow;
2196 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2197 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2199 args_size = old_args_size = 0;
2201 /* We only want to output line number information for the genuine dwarf2
2202 prologue case, not the eh frame case. */
2203 #ifdef DWARF2_DEBUGGING_INFO
2205 dwarf2out_source_line (line, file);
2209 /* Output a marker (i.e. a label) for the absolute end of the generated code
2210 for a function definition. This gets called *after* the epilogue code has
2214 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2215 const char *file ATTRIBUTE_UNUSED)
2218 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2220 /* Output a label to mark the endpoint of the code generated for this
2222 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2223 current_function_funcdef_no);
2224 ASM_OUTPUT_LABEL (asm_out_file, label);
2225 fde = &fde_table[fde_table_in_use - 1];
2226 fde->dw_fde_end = xstrdup (label);
2230 dwarf2out_frame_init (void)
2232 /* Allocate the initial hunk of the fde_table. */
2233 fde_table = (dw_fde_ref) ggc_alloc_cleared (FDE_TABLE_INCREMENT
2234 * sizeof (dw_fde_node));
2235 fde_table_allocated = FDE_TABLE_INCREMENT;
2236 fde_table_in_use = 0;
2238 /* Generate the CFA instructions common to all FDE's. Do it now for the
2239 sake of lookup_cfa. */
2241 #ifdef DWARF2_UNWIND_INFO
2242 /* On entry, the Canonical Frame Address is at SP. */
2243 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2244 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2249 dwarf2out_frame_finish (void)
2251 /* Output call frame information. */
2252 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2253 output_call_frame_info (0);
2255 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2256 output_call_frame_info (1);
2260 /* And now, the subset of the debugging information support code necessary
2261 for emitting location expressions. */
2263 /* We need some way to distinguish DW_OP_addr with a direct symbol
2264 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2265 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2268 typedef struct dw_val_struct *dw_val_ref;
2269 typedef struct die_struct *dw_die_ref;
2270 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2271 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2273 /* Each DIE may have a series of attribute/value pairs. Values
2274 can take on several forms. The forms that are used in this
2275 implementation are listed below. */
2280 dw_val_class_offset,
2282 dw_val_class_loc_list,
2283 dw_val_class_range_list,
2285 dw_val_class_unsigned_const,
2286 dw_val_class_long_long,
2289 dw_val_class_die_ref,
2290 dw_val_class_fde_ref,
2291 dw_val_class_lbl_id,
2292 dw_val_class_lbl_offset,
2296 /* Describe a double word constant value. */
2297 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2299 typedef struct dw_long_long_struct GTY(())
2306 /* Describe a floating point constant value. */
2308 typedef struct dw_fp_struct GTY(())
2310 long * GTY((length ("%h.length"))) array;
2315 /* The dw_val_node describes an attribute's value, as it is
2316 represented internally. */
2318 typedef struct dw_val_struct GTY(())
2320 enum dw_val_class val_class;
2321 union dw_val_struct_union
2323 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2324 long unsigned GTY ((tag ("dw_val_class_offset"))) val_offset;
2325 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2326 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2327 long int GTY ((default (""))) val_int;
2328 long unsigned GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2329 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2330 dw_float_const GTY ((tag ("dw_val_class_float"))) val_float;
2331 struct dw_val_die_union
2335 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2336 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2337 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2338 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2339 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2341 GTY ((desc ("%1.val_class"))) v;
2345 /* Locations in memory are described using a sequence of stack machine
2348 typedef struct dw_loc_descr_struct GTY(())
2350 dw_loc_descr_ref dw_loc_next;
2351 enum dwarf_location_atom dw_loc_opc;
2352 dw_val_node dw_loc_oprnd1;
2353 dw_val_node dw_loc_oprnd2;
2358 /* Location lists are ranges + location descriptions for that range,
2359 so you can track variables that are in different places over
2360 their entire life. */
2361 typedef struct dw_loc_list_struct GTY(())
2363 dw_loc_list_ref dw_loc_next;
2364 const char *begin; /* Label for begin address of range */
2365 const char *end; /* Label for end address of range */
2366 char *ll_symbol; /* Label for beginning of location list.
2367 Only on head of list */
2368 const char *section; /* Section this loclist is relative to */
2369 dw_loc_descr_ref expr;
2372 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2374 static const char *dwarf_stack_op_name (unsigned);
2375 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2376 unsigned long, unsigned long);
2377 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2378 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2379 static unsigned long size_of_locs (dw_loc_descr_ref);
2380 static void output_loc_operands (dw_loc_descr_ref);
2381 static void output_loc_sequence (dw_loc_descr_ref);
2383 /* Convert a DWARF stack opcode into its string name. */
2386 dwarf_stack_op_name (unsigned int op)
2391 case INTERNAL_DW_OP_tls_addr:
2392 return "DW_OP_addr";
2394 return "DW_OP_deref";
2396 return "DW_OP_const1u";
2398 return "DW_OP_const1s";
2400 return "DW_OP_const2u";
2402 return "DW_OP_const2s";
2404 return "DW_OP_const4u";
2406 return "DW_OP_const4s";
2408 return "DW_OP_const8u";
2410 return "DW_OP_const8s";
2412 return "DW_OP_constu";
2414 return "DW_OP_consts";
2418 return "DW_OP_drop";
2420 return "DW_OP_over";
2422 return "DW_OP_pick";
2424 return "DW_OP_swap";
2428 return "DW_OP_xderef";
2436 return "DW_OP_minus";
2448 return "DW_OP_plus";
2449 case DW_OP_plus_uconst:
2450 return "DW_OP_plus_uconst";
2456 return "DW_OP_shra";
2474 return "DW_OP_skip";
2476 return "DW_OP_lit0";
2478 return "DW_OP_lit1";
2480 return "DW_OP_lit2";
2482 return "DW_OP_lit3";
2484 return "DW_OP_lit4";
2486 return "DW_OP_lit5";
2488 return "DW_OP_lit6";
2490 return "DW_OP_lit7";
2492 return "DW_OP_lit8";
2494 return "DW_OP_lit9";
2496 return "DW_OP_lit10";
2498 return "DW_OP_lit11";
2500 return "DW_OP_lit12";
2502 return "DW_OP_lit13";
2504 return "DW_OP_lit14";
2506 return "DW_OP_lit15";
2508 return "DW_OP_lit16";
2510 return "DW_OP_lit17";
2512 return "DW_OP_lit18";
2514 return "DW_OP_lit19";
2516 return "DW_OP_lit20";
2518 return "DW_OP_lit21";
2520 return "DW_OP_lit22";
2522 return "DW_OP_lit23";
2524 return "DW_OP_lit24";
2526 return "DW_OP_lit25";
2528 return "DW_OP_lit26";
2530 return "DW_OP_lit27";
2532 return "DW_OP_lit28";
2534 return "DW_OP_lit29";
2536 return "DW_OP_lit30";
2538 return "DW_OP_lit31";
2540 return "DW_OP_reg0";
2542 return "DW_OP_reg1";
2544 return "DW_OP_reg2";
2546 return "DW_OP_reg3";
2548 return "DW_OP_reg4";
2550 return "DW_OP_reg5";
2552 return "DW_OP_reg6";
2554 return "DW_OP_reg7";
2556 return "DW_OP_reg8";
2558 return "DW_OP_reg9";
2560 return "DW_OP_reg10";
2562 return "DW_OP_reg11";
2564 return "DW_OP_reg12";
2566 return "DW_OP_reg13";
2568 return "DW_OP_reg14";
2570 return "DW_OP_reg15";
2572 return "DW_OP_reg16";
2574 return "DW_OP_reg17";
2576 return "DW_OP_reg18";
2578 return "DW_OP_reg19";
2580 return "DW_OP_reg20";
2582 return "DW_OP_reg21";
2584 return "DW_OP_reg22";
2586 return "DW_OP_reg23";
2588 return "DW_OP_reg24";
2590 return "DW_OP_reg25";
2592 return "DW_OP_reg26";
2594 return "DW_OP_reg27";
2596 return "DW_OP_reg28";
2598 return "DW_OP_reg29";
2600 return "DW_OP_reg30";
2602 return "DW_OP_reg31";
2604 return "DW_OP_breg0";
2606 return "DW_OP_breg1";
2608 return "DW_OP_breg2";
2610 return "DW_OP_breg3";
2612 return "DW_OP_breg4";
2614 return "DW_OP_breg5";
2616 return "DW_OP_breg6";
2618 return "DW_OP_breg7";
2620 return "DW_OP_breg8";
2622 return "DW_OP_breg9";
2624 return "DW_OP_breg10";
2626 return "DW_OP_breg11";
2628 return "DW_OP_breg12";
2630 return "DW_OP_breg13";
2632 return "DW_OP_breg14";
2634 return "DW_OP_breg15";
2636 return "DW_OP_breg16";
2638 return "DW_OP_breg17";
2640 return "DW_OP_breg18";
2642 return "DW_OP_breg19";
2644 return "DW_OP_breg20";
2646 return "DW_OP_breg21";
2648 return "DW_OP_breg22";
2650 return "DW_OP_breg23";
2652 return "DW_OP_breg24";
2654 return "DW_OP_breg25";
2656 return "DW_OP_breg26";
2658 return "DW_OP_breg27";
2660 return "DW_OP_breg28";
2662 return "DW_OP_breg29";
2664 return "DW_OP_breg30";
2666 return "DW_OP_breg31";
2668 return "DW_OP_regx";
2670 return "DW_OP_fbreg";
2672 return "DW_OP_bregx";
2674 return "DW_OP_piece";
2675 case DW_OP_deref_size:
2676 return "DW_OP_deref_size";
2677 case DW_OP_xderef_size:
2678 return "DW_OP_xderef_size";
2681 case DW_OP_push_object_address:
2682 return "DW_OP_push_object_address";
2684 return "DW_OP_call2";
2686 return "DW_OP_call4";
2687 case DW_OP_call_ref:
2688 return "DW_OP_call_ref";
2689 case DW_OP_GNU_push_tls_address:
2690 return "DW_OP_GNU_push_tls_address";
2692 return "OP_<unknown>";
2696 /* Return a pointer to a newly allocated location description. Location
2697 descriptions are simple expression terms that can be strung
2698 together to form more complicated location (address) descriptions. */
2700 static inline dw_loc_descr_ref
2701 new_loc_descr (enum dwarf_location_atom op, long unsigned int oprnd1,
2702 long unsigned int oprnd2)
2704 dw_loc_descr_ref descr
2705 = (dw_loc_descr_ref) ggc_alloc_cleared (sizeof (dw_loc_descr_node));
2707 descr->dw_loc_opc = op;
2708 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2709 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2710 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2711 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2717 /* Add a location description term to a location description expression. */
2720 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
2722 dw_loc_descr_ref *d;
2724 /* Find the end of the chain. */
2725 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2731 /* Return the size of a location descriptor. */
2733 static unsigned long
2734 size_of_loc_descr (dw_loc_descr_ref loc)
2736 unsigned long size = 1;
2738 switch (loc->dw_loc_opc)
2741 case INTERNAL_DW_OP_tls_addr:
2742 size += DWARF2_ADDR_SIZE;
2761 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2764 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2769 case DW_OP_plus_uconst:
2770 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2808 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2811 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2814 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2817 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2818 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2821 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2823 case DW_OP_deref_size:
2824 case DW_OP_xderef_size:
2833 case DW_OP_call_ref:
2834 size += DWARF2_ADDR_SIZE;
2843 /* Return the size of a series of location descriptors. */
2845 static unsigned long
2846 size_of_locs (dw_loc_descr_ref loc)
2850 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2852 loc->dw_loc_addr = size;
2853 size += size_of_loc_descr (loc);
2859 /* Output location description stack opcode's operands (if any). */
2862 output_loc_operands (dw_loc_descr_ref loc)
2864 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2865 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2867 switch (loc->dw_loc_opc)
2869 #ifdef DWARF2_DEBUGGING_INFO
2871 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2875 dw2_asm_output_data (2, val1->v.val_int, NULL);
2879 dw2_asm_output_data (4, val1->v.val_int, NULL);
2883 if (HOST_BITS_PER_LONG < 64)
2885 dw2_asm_output_data (8, val1->v.val_int, NULL);
2892 if (val1->val_class == dw_val_class_loc)
2893 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2897 dw2_asm_output_data (2, offset, NULL);
2910 /* We currently don't make any attempt to make sure these are
2911 aligned properly like we do for the main unwind info, so
2912 don't support emitting things larger than a byte if we're
2913 only doing unwinding. */
2918 dw2_asm_output_data (1, val1->v.val_int, NULL);
2921 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2924 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2927 dw2_asm_output_data (1, val1->v.val_int, NULL);
2929 case DW_OP_plus_uconst:
2930 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2964 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2967 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2970 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2973 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2974 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2977 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2979 case DW_OP_deref_size:
2980 case DW_OP_xderef_size:
2981 dw2_asm_output_data (1, val1->v.val_int, NULL);
2984 case INTERNAL_DW_OP_tls_addr:
2985 #ifdef ASM_OUTPUT_DWARF_DTPREL
2986 ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE,
2988 fputc ('\n', asm_out_file);
2995 /* Other codes have no operands. */
3000 /* Output a sequence of location operations. */
3003 output_loc_sequence (dw_loc_descr_ref loc)
3005 for (; loc != NULL; loc = loc->dw_loc_next)
3007 /* Output the opcode. */
3008 dw2_asm_output_data (1, loc->dw_loc_opc,
3009 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3011 /* Output the operand(s) (if any). */
3012 output_loc_operands (loc);
3016 /* This routine will generate the correct assembly data for a location
3017 description based on a cfi entry with a complex address. */
3020 output_cfa_loc (dw_cfi_ref cfi)
3022 dw_loc_descr_ref loc;
3025 /* Output the size of the block. */
3026 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3027 size = size_of_locs (loc);
3028 dw2_asm_output_data_uleb128 (size, NULL);
3030 /* Now output the operations themselves. */
3031 output_loc_sequence (loc);
3034 /* This function builds a dwarf location descriptor sequence from
3035 a dw_cfa_location. */
3037 static struct dw_loc_descr_struct *
3038 build_cfa_loc (dw_cfa_location *cfa)
3040 struct dw_loc_descr_struct *head, *tmp;
3042 if (cfa->indirect == 0)
3045 if (cfa->base_offset)
3048 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3050 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3052 else if (cfa->reg <= 31)
3053 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3055 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3057 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3058 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3059 add_loc_descr (&head, tmp);
3060 if (cfa->offset != 0)
3062 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3063 add_loc_descr (&head, tmp);
3069 /* This function fills in aa dw_cfa_location structure from a dwarf location
3070 descriptor sequence. */
3073 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3075 struct dw_loc_descr_struct *ptr;
3077 cfa->base_offset = 0;
3081 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3083 enum dwarf_location_atom op = ptr->dw_loc_opc;
3119 cfa->reg = op - DW_OP_reg0;
3122 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3156 cfa->reg = op - DW_OP_breg0;
3157 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3160 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3161 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3166 case DW_OP_plus_uconst:
3167 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3170 internal_error ("DW_LOC_OP %s not implemented\n",
3171 dwarf_stack_op_name (ptr->dw_loc_opc));
3175 #endif /* .debug_frame support */
3177 /* And now, the support for symbolic debugging information. */
3178 #ifdef DWARF2_DEBUGGING_INFO
3180 /* .debug_str support. */
3181 static int output_indirect_string (void **, void *);
3183 static void dwarf2out_init (const char *);
3184 static void dwarf2out_finish (const char *);
3185 static void dwarf2out_define (unsigned int, const char *);
3186 static void dwarf2out_undef (unsigned int, const char *);
3187 static void dwarf2out_start_source_file (unsigned, const char *);
3188 static void dwarf2out_end_source_file (unsigned);
3189 static void dwarf2out_begin_block (unsigned, unsigned);
3190 static void dwarf2out_end_block (unsigned, unsigned);
3191 static bool dwarf2out_ignore_block (tree);
3192 static void dwarf2out_global_decl (tree);
3193 static void dwarf2out_abstract_function (tree);
3195 /* The debug hooks structure. */
3197 const struct gcc_debug_hooks dwarf2_debug_hooks =
3203 dwarf2out_start_source_file,
3204 dwarf2out_end_source_file,
3205 dwarf2out_begin_block,
3206 dwarf2out_end_block,
3207 dwarf2out_ignore_block,
3208 dwarf2out_source_line,
3209 dwarf2out_begin_prologue,
3210 debug_nothing_int_charstar, /* end_prologue */
3211 dwarf2out_end_epilogue,
3212 debug_nothing_tree, /* begin_function */
3213 debug_nothing_int, /* end_function */
3214 dwarf2out_decl, /* function_decl */
3215 dwarf2out_global_decl,
3216 debug_nothing_tree, /* deferred_inline_function */
3217 /* The DWARF 2 backend tries to reduce debugging bloat by not
3218 emitting the abstract description of inline functions until
3219 something tries to reference them. */
3220 dwarf2out_abstract_function, /* outlining_inline_function */
3221 debug_nothing_rtx, /* label */
3222 debug_nothing_int /* handle_pch */
3226 /* NOTE: In the comments in this file, many references are made to
3227 "Debugging Information Entries". This term is abbreviated as `DIE'
3228 throughout the remainder of this file. */
3230 /* An internal representation of the DWARF output is built, and then
3231 walked to generate the DWARF debugging info. The walk of the internal
3232 representation is done after the entire program has been compiled.
3233 The types below are used to describe the internal representation. */
3235 /* Various DIE's use offsets relative to the beginning of the
3236 .debug_info section to refer to each other. */
3238 typedef long int dw_offset;
3240 /* Define typedefs here to avoid circular dependencies. */
3242 typedef struct dw_attr_struct *dw_attr_ref;
3243 typedef struct dw_line_info_struct *dw_line_info_ref;
3244 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3245 typedef struct pubname_struct *pubname_ref;
3246 typedef struct dw_ranges_struct *dw_ranges_ref;
3248 /* Each entry in the line_info_table maintains the file and
3249 line number associated with the label generated for that
3250 entry. The label gives the PC value associated with
3251 the line number entry. */
3253 typedef struct dw_line_info_struct GTY(())
3255 unsigned long dw_file_num;
3256 unsigned long dw_line_num;
3260 /* Line information for functions in separate sections; each one gets its
3262 typedef struct dw_separate_line_info_struct GTY(())
3264 unsigned long dw_file_num;
3265 unsigned long dw_line_num;
3266 unsigned long function;
3268 dw_separate_line_info_entry;
3270 /* Each DIE attribute has a field specifying the attribute kind,
3271 a link to the next attribute in the chain, and an attribute value.
3272 Attributes are typically linked below the DIE they modify. */
3274 typedef struct dw_attr_struct GTY(())
3276 enum dwarf_attribute dw_attr;
3277 dw_attr_ref dw_attr_next;
3278 dw_val_node dw_attr_val;
3282 /* The Debugging Information Entry (DIE) structure */
3284 typedef struct die_struct GTY(())
3286 enum dwarf_tag die_tag;
3288 dw_attr_ref die_attr;
3289 dw_die_ref die_parent;
3290 dw_die_ref die_child;
3292 dw_offset die_offset;
3293 unsigned long die_abbrev;
3298 /* The pubname structure */
3300 typedef struct pubname_struct GTY(())
3307 struct dw_ranges_struct GTY(())
3312 /* The limbo die list structure. */
3313 typedef struct limbo_die_struct GTY(())
3317 struct limbo_die_struct *next;
3321 /* How to start an assembler comment. */
3322 #ifndef ASM_COMMENT_START
3323 #define ASM_COMMENT_START ";#"
3326 /* Define a macro which returns nonzero for a TYPE_DECL which was
3327 implicitly generated for a tagged type.
3329 Note that unlike the gcc front end (which generates a NULL named
3330 TYPE_DECL node for each complete tagged type, each array type, and
3331 each function type node created) the g++ front end generates a
3332 _named_ TYPE_DECL node for each tagged type node created.
3333 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3334 generate a DW_TAG_typedef DIE for them. */
3336 #define TYPE_DECL_IS_STUB(decl) \
3337 (DECL_NAME (decl) == NULL_TREE \
3338 || (DECL_ARTIFICIAL (decl) \
3339 && is_tagged_type (TREE_TYPE (decl)) \
3340 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3341 /* This is necessary for stub decls that \
3342 appear in nested inline functions. */ \
3343 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3344 && (decl_ultimate_origin (decl) \
3345 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3347 /* Information concerning the compilation unit's programming
3348 language, and compiler version. */
3350 /* Fixed size portion of the DWARF compilation unit header. */
3351 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3352 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3354 /* Fixed size portion of public names info. */
3355 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3357 /* Fixed size portion of the address range info. */
3358 #define DWARF_ARANGES_HEADER_SIZE \
3359 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3360 DWARF2_ADDR_SIZE * 2) \
3361 - DWARF_INITIAL_LENGTH_SIZE)
3363 /* Size of padding portion in the address range info. It must be
3364 aligned to twice the pointer size. */
3365 #define DWARF_ARANGES_PAD_SIZE \
3366 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3367 DWARF2_ADDR_SIZE * 2) \
3368 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3370 /* Use assembler line directives if available. */
3371 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3372 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3373 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3375 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3379 /* Minimum line offset in a special line info. opcode.
3380 This value was chosen to give a reasonable range of values. */
3381 #define DWARF_LINE_BASE -10
3383 /* First special line opcode - leave room for the standard opcodes. */
3384 #define DWARF_LINE_OPCODE_BASE 10
3386 /* Range of line offsets in a special line info. opcode. */
3387 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3389 /* Flag that indicates the initial value of the is_stmt_start flag.
3390 In the present implementation, we do not mark any lines as
3391 the beginning of a source statement, because that information
3392 is not made available by the GCC front-end. */
3393 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3395 #ifdef DWARF2_DEBUGGING_INFO
3396 /* This location is used by calc_die_sizes() to keep track
3397 the offset of each DIE within the .debug_info section. */
3398 static unsigned long next_die_offset;
3401 /* Record the root of the DIE's built for the current compilation unit. */
3402 static GTY(()) dw_die_ref comp_unit_die;
3404 #ifdef DWARF2_DEBUGGING_INFO
3405 /* We need special handling in dwarf2out_start_source_file if it is
3407 static int is_main_source;
3410 /* A list of DIEs with a NULL parent waiting to be relocated. */
3411 static GTY(()) limbo_die_node *limbo_die_list;
3413 /* Filenames referenced by this compilation unit. */
3414 static GTY(()) varray_type file_table;
3415 static GTY(()) varray_type file_table_emitted;
3416 static GTY(()) size_t file_table_last_lookup_index;
3418 /* A pointer to the base of a table of references to DIE's that describe
3419 declarations. The table is indexed by DECL_UID() which is a unique
3420 number identifying each decl. */
3421 static GTY((length ("decl_die_table_allocated"))) dw_die_ref *decl_die_table;
3423 /* Number of elements currently allocated for the decl_die_table. */
3424 static GTY(()) unsigned decl_die_table_allocated;
3426 /* Number of elements in decl_die_table currently in use. */
3427 static GTY(()) unsigned decl_die_table_in_use;
3429 /* Size (in elements) of increments by which we may expand the
3431 #define DECL_DIE_TABLE_INCREMENT 256
3433 /* A pointer to the base of a list of references to DIE's that
3434 are uniquely identified by their tag, presence/absence of
3435 children DIE's, and list of attribute/value pairs. */
3436 static GTY((length ("abbrev_die_table_allocated")))
3437 dw_die_ref *abbrev_die_table;
3439 /* Number of elements currently allocated for abbrev_die_table. */
3440 static GTY(()) unsigned abbrev_die_table_allocated;
3442 /* Number of elements in type_die_table currently in use. */
3443 static GTY(()) unsigned abbrev_die_table_in_use;
3445 /* Size (in elements) of increments by which we may expand the
3446 abbrev_die_table. */
3447 #define ABBREV_DIE_TABLE_INCREMENT 256
3449 /* A pointer to the base of a table that contains line information
3450 for each source code line in .text in the compilation unit. */
3451 static GTY((length ("line_info_table_allocated")))
3452 dw_line_info_ref line_info_table;
3454 /* Number of elements currently allocated for line_info_table. */
3455 static GTY(()) unsigned line_info_table_allocated;
3457 /* Number of elements in line_info_table currently in use. */
3458 static GTY(()) unsigned line_info_table_in_use;
3460 /* A pointer to the base of a table that contains line information
3461 for each source code line outside of .text in the compilation unit. */
3462 static GTY ((length ("separate_line_info_table_allocated")))
3463 dw_separate_line_info_ref separate_line_info_table;
3465 /* Number of elements currently allocated for separate_line_info_table. */
3466 static GTY(()) unsigned separate_line_info_table_allocated;
3468 /* Number of elements in separate_line_info_table currently in use. */
3469 static GTY(()) unsigned separate_line_info_table_in_use;
3471 /* Size (in elements) of increments by which we may expand the
3473 #define LINE_INFO_TABLE_INCREMENT 1024
3475 /* A pointer to the base of a table that contains a list of publicly
3476 accessible names. */
3477 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table;
3479 /* Number of elements currently allocated for pubname_table. */
3480 static GTY(()) unsigned pubname_table_allocated;
3482 /* Number of elements in pubname_table currently in use. */
3483 static GTY(()) unsigned pubname_table_in_use;
3485 /* Size (in elements) of increments by which we may expand the
3487 #define PUBNAME_TABLE_INCREMENT 64
3489 /* Array of dies for which we should generate .debug_arange info. */
3490 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
3492 /* Number of elements currently allocated for arange_table. */
3493 static GTY(()) unsigned arange_table_allocated;
3495 /* Number of elements in arange_table currently in use. */
3496 static GTY(()) unsigned arange_table_in_use;
3498 /* Size (in elements) of increments by which we may expand the
3500 #define ARANGE_TABLE_INCREMENT 64
3502 /* Array of dies for which we should generate .debug_ranges info. */
3503 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3505 /* Number of elements currently allocated for ranges_table. */
3506 static GTY(()) unsigned ranges_table_allocated;
3508 /* Number of elements in ranges_table currently in use. */
3509 static GTY(()) unsigned ranges_table_in_use;
3511 /* Size (in elements) of increments by which we may expand the
3513 #define RANGES_TABLE_INCREMENT 64
3515 /* Whether we have location lists that need outputting */
3516 static GTY(()) unsigned have_location_lists;
3518 #ifdef DWARF2_DEBUGGING_INFO
3519 /* Record whether the function being analyzed contains inlined functions. */
3520 static int current_function_has_inlines;
3522 #if 0 && defined (MIPS_DEBUGGING_INFO)
3523 static int comp_unit_has_inlines;
3526 /* Number of file tables emitted in maybe_emit_file(). */
3527 static GTY(()) int emitcount = 0;
3529 /* Number of internal labels generated by gen_internal_sym(). */
3530 static GTY(()) int label_num;
3532 #ifdef DWARF2_DEBUGGING_INFO
3534 /* Forward declarations for functions defined in this file. */
3536 static int is_pseudo_reg (rtx);
3537 static tree type_main_variant (tree);
3538 static int is_tagged_type (tree);
3539 static const char *dwarf_tag_name (unsigned);
3540 static const char *dwarf_attr_name (unsigned);
3541 static const char *dwarf_form_name (unsigned);
3543 static const char *dwarf_type_encoding_name (unsigned);
3545 static tree decl_ultimate_origin (tree);
3546 static tree block_ultimate_origin (tree);
3547 static tree decl_class_context (tree);
3548 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3549 static inline enum dw_val_class AT_class (dw_attr_ref);
3550 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3551 static inline unsigned AT_flag (dw_attr_ref);
3552 static void add_AT_int (dw_die_ref, enum dwarf_attribute, long);
3553 static inline long int AT_int (dw_attr_ref);
3554 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned long);
3555 static inline unsigned long AT_unsigned (dw_attr_ref);
3556 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
3558 static void add_AT_float (dw_die_ref, enum dwarf_attribute, unsigned, long *);
3559 static hashval_t debug_str_do_hash (const void *);
3560 static int debug_str_eq (const void *, const void *);
3561 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3562 static inline const char *AT_string (dw_attr_ref);
3563 static int AT_string_form (dw_attr_ref);
3564 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3565 static inline dw_die_ref AT_ref (dw_attr_ref);
3566 static inline int AT_ref_external (dw_attr_ref);
3567 static inline void set_AT_ref_external (dw_attr_ref, int);
3568 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3569 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3570 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3571 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3573 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3574 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3575 static inline rtx AT_addr (dw_attr_ref);
3576 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3577 static void add_AT_lbl_offset (dw_die_ref, enum dwarf_attribute, const char *);
3578 static void add_AT_offset (dw_die_ref, enum dwarf_attribute, unsigned long);
3579 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3581 static inline const char *AT_lbl (dw_attr_ref);
3582 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3583 static const char *get_AT_low_pc (dw_die_ref);
3584 static const char *get_AT_hi_pc (dw_die_ref);
3585 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3586 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3587 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3588 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3589 static bool is_c_family (void);
3590 static bool is_cxx (void);
3591 static bool is_java (void);
3592 static bool is_fortran (void);
3593 static bool is_ada (void);
3594 static void remove_AT (dw_die_ref, enum dwarf_attribute);
3595 static inline void free_die (dw_die_ref);
3596 static void remove_children (dw_die_ref);
3597 static void add_child_die (dw_die_ref, dw_die_ref);
3598 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3599 static dw_die_ref lookup_type_die (tree);
3600 static void equate_type_number_to_die (tree, dw_die_ref);
3601 static dw_die_ref lookup_decl_die (tree);
3602 static void equate_decl_number_to_die (tree, dw_die_ref);
3603 static void print_spaces (FILE *);
3604 static void print_die (dw_die_ref, FILE *);
3605 static void print_dwarf_line_table (FILE *);
3606 static void reverse_die_lists (dw_die_ref);
3607 static void reverse_all_dies (dw_die_ref);
3608 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3609 static dw_die_ref pop_compile_unit (dw_die_ref);
3610 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3611 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3612 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3613 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3614 static int same_dw_val_p (dw_val_node *, dw_val_node *, int *);
3615 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3616 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3617 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3618 static void compute_section_prefix (dw_die_ref);
3619 static int is_type_die (dw_die_ref);
3620 static int is_comdat_die (dw_die_ref);
3621 static int is_symbol_die (dw_die_ref);
3622 static void assign_symbol_names (dw_die_ref);
3623 static void break_out_includes (dw_die_ref);
3624 static hashval_t htab_cu_hash (const void *);
3625 static int htab_cu_eq (const void *, const void *);
3626 static void htab_cu_del (void *);
3627 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
3628 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
3629 static void add_sibling_attributes (dw_die_ref);
3630 static void build_abbrev_table (dw_die_ref);
3631 static void output_location_lists (dw_die_ref);
3632 static int constant_size (long unsigned);
3633 static unsigned long size_of_die (dw_die_ref);
3634 static void calc_die_sizes (dw_die_ref);
3635 static void mark_dies (dw_die_ref);
3636 static void unmark_dies (dw_die_ref);
3637 static void unmark_all_dies (dw_die_ref);
3638 static unsigned long size_of_pubnames (void);
3639 static unsigned long size_of_aranges (void);
3640 static enum dwarf_form value_format (dw_attr_ref);
3641 static void output_value_format (dw_attr_ref);
3642 static void output_abbrev_section (void);
3643 static void output_die_symbol (dw_die_ref);
3644 static void output_die (dw_die_ref);
3645 static void output_compilation_unit_header (void);
3646 static void output_comp_unit (dw_die_ref, int);
3647 static const char *dwarf2_name (tree, int);
3648 static void add_pubname (tree, dw_die_ref);
3649 static void output_pubnames (void);
3650 static void add_arange (tree, dw_die_ref);
3651 static void output_aranges (void);
3652 static unsigned int add_ranges (tree);
3653 static void output_ranges (void);
3654 static void output_line_info (void);
3655 static void output_file_names (void);
3656 static dw_die_ref base_type_die (tree);
3657 static tree root_type (tree);
3658 static int is_base_type (tree);
3659 static bool is_ada_subrange_type (tree);
3660 static dw_die_ref subrange_type_die (tree);
3661 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
3662 static int type_is_enum (tree);
3663 static unsigned int reg_number (rtx);
3664 static dw_loc_descr_ref reg_loc_descriptor (rtx);
3665 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int);
3666 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx);
3667 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3668 static dw_loc_descr_ref based_loc_descr (unsigned, long);
3669 static int is_based_loc (rtx);
3670 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode);
3671 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx);
3672 static dw_loc_descr_ref loc_descriptor (rtx);
3673 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
3674 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3675 static tree field_type (tree);
3676 static unsigned int simple_type_align_in_bits (tree);
3677 static unsigned int simple_decl_align_in_bits (tree);
3678 static unsigned HOST_WIDE_INT simple_type_size_in_bits (tree);
3679 static HOST_WIDE_INT field_byte_offset (tree);
3680 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3682 static void add_data_member_location_attribute (dw_die_ref, tree);
3683 static void add_const_value_attribute (dw_die_ref, rtx);
3684 static rtx rtl_for_decl_location (tree);
3685 static void add_location_or_const_value_attribute (dw_die_ref, tree);
3686 static void tree_add_const_value_attribute (dw_die_ref, tree);
3687 static void add_name_attribute (dw_die_ref, const char *);
3688 static void add_comp_dir_attribute (dw_die_ref);
3689 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
3690 static void add_subscript_info (dw_die_ref, tree);
3691 static void add_byte_size_attribute (dw_die_ref, tree);
3692 static void add_bit_offset_attribute (dw_die_ref, tree);
3693 static void add_bit_size_attribute (dw_die_ref, tree);
3694 static void add_prototyped_attribute (dw_die_ref, tree);
3695 static void add_abstract_origin_attribute (dw_die_ref, tree);
3696 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3697 static void add_src_coords_attributes (dw_die_ref, tree);
3698 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
3699 static void push_decl_scope (tree);
3700 static void pop_decl_scope (void);
3701 static dw_die_ref scope_die_for (tree, dw_die_ref);
3702 static inline int local_scope_p (dw_die_ref);
3703 static inline int class_scope_p (dw_die_ref);
3704 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
3705 static const char *type_tag (tree);
3706 static tree member_declared_type (tree);
3708 static const char *decl_start_label (tree);
3710 static void gen_array_type_die (tree, dw_die_ref);
3711 static void gen_set_type_die (tree, dw_die_ref);
3713 static void gen_entry_point_die (tree, dw_die_ref);
3715 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
3716 static void gen_inlined_structure_type_die (tree, dw_die_ref);
3717 static void gen_inlined_union_type_die (tree, dw_die_ref);
3718 static void gen_enumeration_type_die (tree, dw_die_ref);
3719 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
3720 static void gen_unspecified_parameters_die (tree, dw_die_ref);
3721 static void gen_formal_types_die (tree, dw_die_ref);
3722 static void gen_subprogram_die (tree, dw_die_ref);
3723 static void gen_variable_die (tree, dw_die_ref);
3724 static void gen_label_die (tree, dw_die_ref);
3725 static void gen_lexical_block_die (tree, dw_die_ref, int);
3726 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
3727 static void gen_field_die (tree, dw_die_ref);
3728 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3729 static dw_die_ref gen_compile_unit_die (const char *);
3730 static void gen_string_type_die (tree, dw_die_ref);
3731 static void gen_inheritance_die (tree, tree, dw_die_ref);
3732 static void gen_member_die (tree, dw_die_ref);
3733 static void gen_struct_or_union_type_die (tree, dw_die_ref);
3734 static void gen_subroutine_type_die (tree, dw_die_ref);
3735 static void gen_typedef_die (tree, dw_die_ref);
3736 static void gen_type_die (tree, dw_die_ref);
3737 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
3738 static void gen_block_die (tree, dw_die_ref, int);
3739 static void decls_for_scope (tree, dw_die_ref, int);
3740 static int is_redundant_typedef (tree);
3741 static void gen_decl_die (tree, dw_die_ref);
3742 static unsigned lookup_filename (const char *);
3743 static void init_file_table (void);
3744 static void retry_incomplete_types (void);
3745 static void gen_type_die_for_member (tree, tree, dw_die_ref);
3746 static void splice_child_die (dw_die_ref, dw_die_ref);
3747 static int file_info_cmp (const void *, const void *);
3748 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
3749 const char *, const char *, unsigned);
3750 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
3751 const char *, const char *,
3753 static void output_loc_list (dw_loc_list_ref);
3754 static char *gen_internal_sym (const char *);
3756 static void prune_unmark_dies (dw_die_ref);
3757 static void prune_unused_types_mark (dw_die_ref, int);
3758 static void prune_unused_types_walk (dw_die_ref);
3759 static void prune_unused_types_walk_attribs (dw_die_ref);
3760 static void prune_unused_types_prune (dw_die_ref);
3761 static void prune_unused_types (void);
3762 static int maybe_emit_file (int);
3764 /* Section names used to hold DWARF debugging information. */
3765 #ifndef DEBUG_INFO_SECTION
3766 #define DEBUG_INFO_SECTION ".debug_info"
3768 #ifndef DEBUG_ABBREV_SECTION
3769 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3771 #ifndef DEBUG_ARANGES_SECTION
3772 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3774 #ifndef DEBUG_MACINFO_SECTION
3775 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3777 #ifndef DEBUG_LINE_SECTION
3778 #define DEBUG_LINE_SECTION ".debug_line"
3780 #ifndef DEBUG_LOC_SECTION
3781 #define DEBUG_LOC_SECTION ".debug_loc"
3783 #ifndef DEBUG_PUBNAMES_SECTION
3784 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3786 #ifndef DEBUG_STR_SECTION
3787 #define DEBUG_STR_SECTION ".debug_str"
3789 #ifndef DEBUG_RANGES_SECTION
3790 #define DEBUG_RANGES_SECTION ".debug_ranges"
3793 /* Standard ELF section names for compiled code and data. */
3794 #ifndef TEXT_SECTION_NAME
3795 #define TEXT_SECTION_NAME ".text"
3798 /* Section flags for .debug_str section. */
3799 #ifdef HAVE_GAS_SHF_MERGE
3800 #define DEBUG_STR_SECTION_FLAGS \
3801 (flag_merge_constants \
3802 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3805 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3808 /* Labels we insert at beginning sections we can reference instead of
3809 the section names themselves. */
3811 #ifndef TEXT_SECTION_LABEL
3812 #define TEXT_SECTION_LABEL "Ltext"
3814 #ifndef DEBUG_LINE_SECTION_LABEL
3815 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3817 #ifndef DEBUG_INFO_SECTION_LABEL
3818 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3820 #ifndef DEBUG_ABBREV_SECTION_LABEL
3821 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3823 #ifndef DEBUG_LOC_SECTION_LABEL
3824 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3826 #ifndef DEBUG_RANGES_SECTION_LABEL
3827 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3829 #ifndef DEBUG_MACINFO_SECTION_LABEL
3830 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3833 /* Definitions of defaults for formats and names of various special
3834 (artificial) labels which may be generated within this file (when the -g
3835 options is used and DWARF_DEBUGGING_INFO is in effect.
3836 If necessary, these may be overridden from within the tm.h file, but
3837 typically, overriding these defaults is unnecessary. */
3839 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3840 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3841 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3842 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3843 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3844 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3845 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3846 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3848 #ifndef TEXT_END_LABEL
3849 #define TEXT_END_LABEL "Letext"
3851 #ifndef BLOCK_BEGIN_LABEL
3852 #define BLOCK_BEGIN_LABEL "LBB"
3854 #ifndef BLOCK_END_LABEL
3855 #define BLOCK_END_LABEL "LBE"
3857 #ifndef LINE_CODE_LABEL
3858 #define LINE_CODE_LABEL "LM"
3860 #ifndef SEPARATE_LINE_CODE_LABEL
3861 #define SEPARATE_LINE_CODE_LABEL "LSM"
3864 /* We allow a language front-end to designate a function that is to be
3865 called to "demangle" any name before it it put into a DIE. */
3867 static const char *(*demangle_name_func) (const char *);
3870 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
3872 demangle_name_func = func;
3875 /* Test if rtl node points to a pseudo register. */
3878 is_pseudo_reg (rtx rtl)
3880 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3881 || (GET_CODE (rtl) == SUBREG
3882 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3885 /* Return a reference to a type, with its const and volatile qualifiers
3889 type_main_variant (tree type)
3891 type = TYPE_MAIN_VARIANT (type);
3893 /* ??? There really should be only one main variant among any group of
3894 variants of a given type (and all of the MAIN_VARIANT values for all
3895 members of the group should point to that one type) but sometimes the C
3896 front-end messes this up for array types, so we work around that bug
3898 if (TREE_CODE (type) == ARRAY_TYPE)
3899 while (type != TYPE_MAIN_VARIANT (type))
3900 type = TYPE_MAIN_VARIANT (type);
3905 /* Return nonzero if the given type node represents a tagged type. */
3908 is_tagged_type (tree type)
3910 enum tree_code code = TREE_CODE (type);
3912 return (code == RECORD_TYPE || code == UNION_TYPE
3913 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3916 /* Convert a DIE tag into its string name. */
3919 dwarf_tag_name (unsigned int tag)
3923 case DW_TAG_padding:
3924 return "DW_TAG_padding";
3925 case DW_TAG_array_type:
3926 return "DW_TAG_array_type";
3927 case DW_TAG_class_type:
3928 return "DW_TAG_class_type";
3929 case DW_TAG_entry_point:
3930 return "DW_TAG_entry_point";
3931 case DW_TAG_enumeration_type:
3932 return "DW_TAG_enumeration_type";
3933 case DW_TAG_formal_parameter:
3934 return "DW_TAG_formal_parameter";
3935 case DW_TAG_imported_declaration:
3936 return "DW_TAG_imported_declaration";
3938 return "DW_TAG_label";
3939 case DW_TAG_lexical_block:
3940 return "DW_TAG_lexical_block";
3942 return "DW_TAG_member";
3943 case DW_TAG_pointer_type:
3944 return "DW_TAG_pointer_type";
3945 case DW_TAG_reference_type:
3946 return "DW_TAG_reference_type";
3947 case DW_TAG_compile_unit:
3948 return "DW_TAG_compile_unit";
3949 case DW_TAG_string_type:
3950 return "DW_TAG_string_type";
3951 case DW_TAG_structure_type:
3952 return "DW_TAG_structure_type";
3953 case DW_TAG_subroutine_type:
3954 return "DW_TAG_subroutine_type";
3955 case DW_TAG_typedef:
3956 return "DW_TAG_typedef";
3957 case DW_TAG_union_type:
3958 return "DW_TAG_union_type";
3959 case DW_TAG_unspecified_parameters:
3960 return "DW_TAG_unspecified_parameters";
3961 case DW_TAG_variant:
3962 return "DW_TAG_variant";
3963 case DW_TAG_common_block:
3964 return "DW_TAG_common_block";
3965 case DW_TAG_common_inclusion:
3966 return "DW_TAG_common_inclusion";
3967 case DW_TAG_inheritance:
3968 return "DW_TAG_inheritance";
3969 case DW_TAG_inlined_subroutine:
3970 return "DW_TAG_inlined_subroutine";
3972 return "DW_TAG_module";
3973 case DW_TAG_ptr_to_member_type:
3974 return "DW_TAG_ptr_to_member_type";
3975 case DW_TAG_set_type:
3976 return "DW_TAG_set_type";
3977 case DW_TAG_subrange_type:
3978 return "DW_TAG_subrange_type";
3979 case DW_TAG_with_stmt:
3980 return "DW_TAG_with_stmt";
3981 case DW_TAG_access_declaration:
3982 return "DW_TAG_access_declaration";
3983 case DW_TAG_base_type:
3984 return "DW_TAG_base_type";
3985 case DW_TAG_catch_block:
3986 return "DW_TAG_catch_block";
3987 case DW_TAG_const_type:
3988 return "DW_TAG_const_type";
3989 case DW_TAG_constant:
3990 return "DW_TAG_constant";
3991 case DW_TAG_enumerator:
3992 return "DW_TAG_enumerator";
3993 case DW_TAG_file_type:
3994 return "DW_TAG_file_type";
3996 return "DW_TAG_friend";
3997 case DW_TAG_namelist:
3998 return "DW_TAG_namelist";
3999 case DW_TAG_namelist_item:
4000 return "DW_TAG_namelist_item";
4001 case DW_TAG_packed_type:
4002 return "DW_TAG_packed_type";
4003 case DW_TAG_subprogram:
4004 return "DW_TAG_subprogram";
4005 case DW_TAG_template_type_param:
4006 return "DW_TAG_template_type_param";
4007 case DW_TAG_template_value_param:
4008 return "DW_TAG_template_value_param";
4009 case DW_TAG_thrown_type:
4010 return "DW_TAG_thrown_type";
4011 case DW_TAG_try_block:
4012 return "DW_TAG_try_block";
4013 case DW_TAG_variant_part:
4014 return "DW_TAG_variant_part";
4015 case DW_TAG_variable:
4016 return "DW_TAG_variable";
4017 case DW_TAG_volatile_type:
4018 return "DW_TAG_volatile_type";
4019 case DW_TAG_MIPS_loop:
4020 return "DW_TAG_MIPS_loop";
4021 case DW_TAG_format_label:
4022 return "DW_TAG_format_label";
4023 case DW_TAG_function_template:
4024 return "DW_TAG_function_template";
4025 case DW_TAG_class_template:
4026 return "DW_TAG_class_template";
4027 case DW_TAG_GNU_BINCL:
4028 return "DW_TAG_GNU_BINCL";
4029 case DW_TAG_GNU_EINCL:
4030 return "DW_TAG_GNU_EINCL";
4032 return "DW_TAG_<unknown>";
4036 /* Convert a DWARF attribute code into its string name. */
4039 dwarf_attr_name (unsigned int attr)
4044 return "DW_AT_sibling";
4045 case DW_AT_location:
4046 return "DW_AT_location";
4048 return "DW_AT_name";
4049 case DW_AT_ordering:
4050 return "DW_AT_ordering";
4051 case DW_AT_subscr_data:
4052 return "DW_AT_subscr_data";
4053 case DW_AT_byte_size:
4054 return "DW_AT_byte_size";
4055 case DW_AT_bit_offset:
4056 return "DW_AT_bit_offset";
4057 case DW_AT_bit_size:
4058 return "DW_AT_bit_size";
4059 case DW_AT_element_list:
4060 return "DW_AT_element_list";
4061 case DW_AT_stmt_list:
4062 return "DW_AT_stmt_list";
4064 return "DW_AT_low_pc";
4066 return "DW_AT_high_pc";
4067 case DW_AT_language:
4068 return "DW_AT_language";
4070 return "DW_AT_member";
4072 return "DW_AT_discr";
4073 case DW_AT_discr_value:
4074 return "DW_AT_discr_value";
4075 case DW_AT_visibility:
4076 return "DW_AT_visibility";
4078 return "DW_AT_import";
4079 case DW_AT_string_length:
4080 return "DW_AT_string_length";
4081 case DW_AT_common_reference:
4082 return "DW_AT_common_reference";
4083 case DW_AT_comp_dir:
4084 return "DW_AT_comp_dir";
4085 case DW_AT_const_value:
4086 return "DW_AT_const_value";
4087 case DW_AT_containing_type:
4088 return "DW_AT_containing_type";
4089 case DW_AT_default_value:
4090 return "DW_AT_default_value";
4092 return "DW_AT_inline";
4093 case DW_AT_is_optional:
4094 return "DW_AT_is_optional";
4095 case DW_AT_lower_bound:
4096 return "DW_AT_lower_bound";
4097 case DW_AT_producer:
4098 return "DW_AT_producer";
4099 case DW_AT_prototyped:
4100 return "DW_AT_prototyped";
4101 case DW_AT_return_addr:
4102 return "DW_AT_return_addr";
4103 case DW_AT_start_scope:
4104 return "DW_AT_start_scope";
4105 case DW_AT_stride_size:
4106 return "DW_AT_stride_size";
4107 case DW_AT_upper_bound:
4108 return "DW_AT_upper_bound";
4109 case DW_AT_abstract_origin:
4110 return "DW_AT_abstract_origin";
4111 case DW_AT_accessibility:
4112 return "DW_AT_accessibility";
4113 case DW_AT_address_class:
4114 return "DW_AT_address_class";
4115 case DW_AT_artificial:
4116 return "DW_AT_artificial";
4117 case DW_AT_base_types:
4118 return "DW_AT_base_types";
4119 case DW_AT_calling_convention:
4120 return "DW_AT_calling_convention";
4122 return "DW_AT_count";
4123 case DW_AT_data_member_location:
4124 return "DW_AT_data_member_location";
4125 case DW_AT_decl_column:
4126 return "DW_AT_decl_column";
4127 case DW_AT_decl_file:
4128 return "DW_AT_decl_file";
4129 case DW_AT_decl_line:
4130 return "DW_AT_decl_line";
4131 case DW_AT_declaration:
4132 return "DW_AT_declaration";
4133 case DW_AT_discr_list:
4134 return "DW_AT_discr_list";
4135 case DW_AT_encoding:
4136 return "DW_AT_encoding";
4137 case DW_AT_external:
4138 return "DW_AT_external";
4139 case DW_AT_frame_base:
4140 return "DW_AT_frame_base";
4142 return "DW_AT_friend";
4143 case DW_AT_identifier_case:
4144 return "DW_AT_identifier_case";
4145 case DW_AT_macro_info:
4146 return "DW_AT_macro_info";
4147 case DW_AT_namelist_items:
4148 return "DW_AT_namelist_items";
4149 case DW_AT_priority:
4150 return "DW_AT_priority";
4152 return "DW_AT_segment";
4153 case DW_AT_specification:
4154 return "DW_AT_specification";
4155 case DW_AT_static_link:
4156 return "DW_AT_static_link";
4158 return "DW_AT_type";
4159 case DW_AT_use_location:
4160 return "DW_AT_use_location";
4161 case DW_AT_variable_parameter:
4162 return "DW_AT_variable_parameter";
4163 case DW_AT_virtuality:
4164 return "DW_AT_virtuality";
4165 case DW_AT_vtable_elem_location:
4166 return "DW_AT_vtable_elem_location";
4168 case DW_AT_allocated:
4169 return "DW_AT_allocated";
4170 case DW_AT_associated:
4171 return "DW_AT_associated";
4172 case DW_AT_data_location:
4173 return "DW_AT_data_location";
4175 return "DW_AT_stride";
4176 case DW_AT_entry_pc:
4177 return "DW_AT_entry_pc";
4178 case DW_AT_use_UTF8:
4179 return "DW_AT_use_UTF8";
4180 case DW_AT_extension:
4181 return "DW_AT_extension";
4183 return "DW_AT_ranges";
4184 case DW_AT_trampoline:
4185 return "DW_AT_trampoline";
4186 case DW_AT_call_column:
4187 return "DW_AT_call_column";
4188 case DW_AT_call_file:
4189 return "DW_AT_call_file";
4190 case DW_AT_call_line:
4191 return "DW_AT_call_line";
4193 case DW_AT_MIPS_fde:
4194 return "DW_AT_MIPS_fde";
4195 case DW_AT_MIPS_loop_begin:
4196 return "DW_AT_MIPS_loop_begin";
4197 case DW_AT_MIPS_tail_loop_begin:
4198 return "DW_AT_MIPS_tail_loop_begin";
4199 case DW_AT_MIPS_epilog_begin:
4200 return "DW_AT_MIPS_epilog_begin";
4201 case DW_AT_MIPS_loop_unroll_factor:
4202 return "DW_AT_MIPS_loop_unroll_factor";
4203 case DW_AT_MIPS_software_pipeline_depth:
4204 return "DW_AT_MIPS_software_pipeline_depth";
4205 case DW_AT_MIPS_linkage_name:
4206 return "DW_AT_MIPS_linkage_name";
4207 case DW_AT_MIPS_stride:
4208 return "DW_AT_MIPS_stride";
4209 case DW_AT_MIPS_abstract_name:
4210 return "DW_AT_MIPS_abstract_name";
4211 case DW_AT_MIPS_clone_origin:
4212 return "DW_AT_MIPS_clone_origin";
4213 case DW_AT_MIPS_has_inlines:
4214 return "DW_AT_MIPS_has_inlines";
4216 case DW_AT_sf_names:
4217 return "DW_AT_sf_names";
4218 case DW_AT_src_info:
4219 return "DW_AT_src_info";
4220 case DW_AT_mac_info:
4221 return "DW_AT_mac_info";
4222 case DW_AT_src_coords:
4223 return "DW_AT_src_coords";
4224 case DW_AT_body_begin:
4225 return "DW_AT_body_begin";
4226 case DW_AT_body_end:
4227 return "DW_AT_body_end";
4228 case DW_AT_GNU_vector:
4229 return "DW_AT_GNU_vector";
4231 case DW_AT_VMS_rtnbeg_pd_address:
4232 return "DW_AT_VMS_rtnbeg_pd_address";
4235 return "DW_AT_<unknown>";
4239 /* Convert a DWARF value form code into its string name. */
4242 dwarf_form_name (unsigned int form)
4247 return "DW_FORM_addr";
4248 case DW_FORM_block2:
4249 return "DW_FORM_block2";
4250 case DW_FORM_block4:
4251 return "DW_FORM_block4";
4253 return "DW_FORM_data2";
4255 return "DW_FORM_data4";
4257 return "DW_FORM_data8";
4258 case DW_FORM_string:
4259 return "DW_FORM_string";
4261 return "DW_FORM_block";
4262 case DW_FORM_block1:
4263 return "DW_FORM_block1";
4265 return "DW_FORM_data1";
4267 return "DW_FORM_flag";
4269 return "DW_FORM_sdata";
4271 return "DW_FORM_strp";
4273 return "DW_FORM_udata";
4274 case DW_FORM_ref_addr:
4275 return "DW_FORM_ref_addr";
4277 return "DW_FORM_ref1";
4279 return "DW_FORM_ref2";
4281 return "DW_FORM_ref4";
4283 return "DW_FORM_ref8";
4284 case DW_FORM_ref_udata:
4285 return "DW_FORM_ref_udata";
4286 case DW_FORM_indirect:
4287 return "DW_FORM_indirect";
4289 return "DW_FORM_<unknown>";
4293 /* Convert a DWARF type code into its string name. */
4297 dwarf_type_encoding_name (unsigned enc)
4301 case DW_ATE_address:
4302 return "DW_ATE_address";
4303 case DW_ATE_boolean:
4304 return "DW_ATE_boolean";
4305 case DW_ATE_complex_float:
4306 return "DW_ATE_complex_float";
4308 return "DW_ATE_float";
4310 return "DW_ATE_signed";