1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000
3 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 GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* TODO: Implement .debug_str handling, and share entries somehow.
26 Eliminate duplicates by putting common info in a separate section
27 to be collected by the linker and referring to it with
29 Emit .debug_line header even when there are no functions, since
30 the file numbers are used by .debug_info. Alternately, leave
31 out locations for types and decls.
32 Avoid talking about ctors and op= for PODs.
33 Factor out common prologue sequences into multiple CIEs. */
35 /* The first part of this file deals with the DWARF 2 frame unwind
36 information, which is also used by the GCC efficient exception handling
37 mechanism. The second part, controlled only by an #ifdef
38 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
47 #include "hard-reg-set.h"
49 #include "insn-config.h"
55 #include "dwarf2out.h"
61 /* We cannot use <assert.h> in GCC source, since that would include
62 GCC's assert.h, which may not be compatible with the host compiler. */
67 # define assert(e) do { if (! (e)) abort (); } while (0)
70 /* Decide whether we want to emit frame unwind information for the current
76 return (write_symbols == DWARF2_DEBUG
77 #ifdef DWARF2_FRAME_INFO
80 #ifdef DWARF2_UNWIND_INFO
82 || (flag_exceptions && ! exceptions_via_longjmp)
87 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
89 /* How to start an assembler comment. */
90 #ifndef ASM_COMMENT_START
91 #define ASM_COMMENT_START ";#"
94 typedef struct dw_cfi_struct *dw_cfi_ref;
95 typedef struct dw_fde_struct *dw_fde_ref;
96 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
98 /* Call frames are described using a sequence of Call Frame
99 Information instructions. The register number, offset
100 and address fields are provided as possible operands;
101 their use is selected by the opcode field. */
103 typedef union dw_cfi_oprnd_struct
105 unsigned long dw_cfi_reg_num;
106 long int dw_cfi_offset;
107 const char *dw_cfi_addr;
111 typedef struct dw_cfi_struct
113 dw_cfi_ref dw_cfi_next;
114 enum dwarf_call_frame_info dw_cfi_opc;
115 dw_cfi_oprnd dw_cfi_oprnd1;
116 dw_cfi_oprnd dw_cfi_oprnd2;
120 /* All call frame descriptions (FDE's) in the GCC generated DWARF
121 refer to a single Common Information Entry (CIE), defined at
122 the beginning of the .debug_frame section. This used of a single
123 CIE obviates the need to keep track of multiple CIE's
124 in the DWARF generation routines below. */
126 typedef struct dw_fde_struct
128 const char *dw_fde_begin;
129 const char *dw_fde_current_label;
130 const char *dw_fde_end;
131 dw_cfi_ref dw_fde_cfi;
136 /* Maximum size (in bytes) of an artificially generated label. */
137 #define MAX_ARTIFICIAL_LABEL_BYTES 30
139 /* Make sure we know the sizes of the various types dwarf can describe. These
140 are only defaults. If the sizes are different for your target, you should
141 override these values by defining the appropriate symbols in your tm.h
144 #ifndef CHAR_TYPE_SIZE
145 #define CHAR_TYPE_SIZE BITS_PER_UNIT
148 /* The size of the target's pointer type. */
150 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
153 /* The size of addresses as they appear in the Dwarf 2 data.
154 Some architectures use word addresses to refer to code locations,
155 but Dwarf 2 info always uses byte addresses. On such machines,
156 Dwarf 2 addresses need to be larger than the architecture's
158 #ifndef DWARF2_ADDR_SIZE
159 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
162 /* The size in bytes of a DWARF field indicating an offset or length
163 relative to a debug info section, specified to be 4 bytes in the
164 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
167 #ifndef DWARF_OFFSET_SIZE
168 #define DWARF_OFFSET_SIZE 4
171 #define DWARF_VERSION 2
173 /* Round SIZE up to the nearest BOUNDARY. */
174 #define DWARF_ROUND(SIZE,BOUNDARY) \
175 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
177 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
178 #ifdef STACK_GROWS_DOWNWARD
179 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
181 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
184 /* A pointer to the base of a table that contains frame description
185 information for each routine. */
186 static dw_fde_ref fde_table;
188 /* Number of elements currently allocated for fde_table. */
189 static unsigned fde_table_allocated;
191 /* Number of elements in fde_table currently in use. */
192 static unsigned fde_table_in_use;
194 /* Size (in elements) of increments by which we may expand the
196 #define FDE_TABLE_INCREMENT 256
198 /* A list of call frame insns for the CIE. */
199 static dw_cfi_ref cie_cfi_head;
201 /* The number of the current function definition for which debugging
202 information is being generated. These numbers range from 1 up to the
203 maximum number of function definitions contained within the current
204 compilation unit. These numbers are used to create unique label id's
205 unique to each function definition. */
206 static unsigned current_funcdef_number = 0;
208 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
209 attribute that accelerates the lookup of the FDE associated
210 with the subprogram. This variable holds the table index of the FDE
211 associated with the current function (body) definition. */
212 static unsigned current_funcdef_fde;
214 /* Forward declarations for functions defined in this file. */
216 static char *stripattributes PARAMS ((const char *));
217 static const char *dwarf_cfi_name PARAMS ((unsigned));
218 static dw_cfi_ref new_cfi PARAMS ((void));
219 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
220 static unsigned long size_of_uleb128 PARAMS ((unsigned long));
221 static unsigned long size_of_sleb128 PARAMS ((long));
222 static void output_uleb128 PARAMS ((unsigned long));
223 static void output_sleb128 PARAMS ((long));
224 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
225 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, unsigned long *,
227 static void lookup_cfa PARAMS ((unsigned long *, long *));
228 static void reg_save PARAMS ((const char *, unsigned,
230 static void initial_return_save PARAMS ((rtx));
231 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
232 static void output_call_frame_info PARAMS ((int));
233 static unsigned int reg_number PARAMS ((rtx));
234 static void dwarf2out_stack_adjust PARAMS ((rtx));
235 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
237 /* Definitions of defaults for assembler-dependent names of various
238 pseudo-ops and section names.
239 Theses may be overridden in the tm.h file (if necessary) for a particular
242 #ifdef OBJECT_FORMAT_ELF
243 #ifndef UNALIGNED_SHORT_ASM_OP
244 #define UNALIGNED_SHORT_ASM_OP ".2byte"
246 #ifndef UNALIGNED_INT_ASM_OP
247 #define UNALIGNED_INT_ASM_OP ".4byte"
249 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
250 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
252 #endif /* OBJECT_FORMAT_ELF */
255 #define ASM_BYTE_OP ".byte"
258 /* Data and reference forms for relocatable data. */
259 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
260 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
262 /* Pseudo-op for defining a new section. */
263 #ifndef SECTION_ASM_OP
264 #define SECTION_ASM_OP ".section"
267 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
268 print the SECTION_ASM_OP and the section name. The default here works for
269 almost all svr4 assemblers, except for the sparc, where the section name
270 must be enclosed in double quotes. (See sparcv4.h). */
271 #ifndef SECTION_FORMAT
272 #ifdef PUSHSECTION_FORMAT
273 #define SECTION_FORMAT PUSHSECTION_FORMAT
275 #define SECTION_FORMAT "\t%s\t%s\n"
279 #ifndef FRAME_SECTION
280 #define FRAME_SECTION ".debug_frame"
283 #ifndef FUNC_BEGIN_LABEL
284 #define FUNC_BEGIN_LABEL "LFB"
286 #ifndef FUNC_END_LABEL
287 #define FUNC_END_LABEL "LFE"
289 #define CIE_AFTER_SIZE_LABEL "LSCIE"
290 #define CIE_END_LABEL "LECIE"
291 #define CIE_LENGTH_LABEL "LLCIE"
292 #define FDE_AFTER_SIZE_LABEL "LSFDE"
293 #define FDE_END_LABEL "LEFDE"
294 #define FDE_LENGTH_LABEL "LLFDE"
296 /* Definitions of defaults for various types of primitive assembly language
297 output operations. These may be overridden from within the tm.h file,
298 but typically, that is unnecessary. */
300 #ifndef ASM_OUTPUT_SECTION
301 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
302 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
305 #ifndef ASM_OUTPUT_DWARF_DATA1
306 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
307 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
310 #ifndef ASM_OUTPUT_DWARF_DELTA1
311 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
312 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
313 assemble_name (FILE, LABEL1); \
314 fprintf (FILE, "-"); \
315 assemble_name (FILE, LABEL2); \
319 #ifdef UNALIGNED_INT_ASM_OP
321 #ifndef UNALIGNED_OFFSET_ASM_OP
322 #define UNALIGNED_OFFSET_ASM_OP \
323 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
326 #ifndef UNALIGNED_WORD_ASM_OP
327 #define UNALIGNED_WORD_ASM_OP \
328 ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \
329 : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \
330 : UNALIGNED_INT_ASM_OP)
333 #ifndef ASM_OUTPUT_DWARF_DELTA2
334 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
335 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
336 assemble_name (FILE, LABEL1); \
337 fprintf (FILE, "-"); \
338 assemble_name (FILE, LABEL2); \
342 #ifndef ASM_OUTPUT_DWARF_DELTA4
343 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
344 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
345 assemble_name (FILE, LABEL1); \
346 fprintf (FILE, "-"); \
347 assemble_name (FILE, LABEL2); \
351 #ifndef ASM_OUTPUT_DWARF_DELTA
352 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
353 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
354 assemble_name (FILE, LABEL1); \
355 fprintf (FILE, "-"); \
356 assemble_name (FILE, LABEL2); \
360 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
361 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
362 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
363 assemble_name (FILE, LABEL1); \
364 fprintf (FILE, "-"); \
365 assemble_name (FILE, LABEL2); \
369 #ifndef ASM_OUTPUT_DWARF_ADDR
370 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
371 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
372 assemble_name (FILE, LABEL); \
376 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
377 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
379 fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
380 output_addr_const ((FILE), (RTX)); \
384 #ifndef ASM_OUTPUT_DWARF_OFFSET4
385 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
386 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
387 assemble_name (FILE, LABEL); \
391 #ifndef ASM_OUTPUT_DWARF_OFFSET
392 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
393 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
394 assemble_name (FILE, LABEL); \
398 #ifndef ASM_OUTPUT_DWARF_DATA2
399 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
400 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
403 #ifndef ASM_OUTPUT_DWARF_DATA4
404 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
405 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
408 #ifndef ASM_OUTPUT_DWARF_DATA
409 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
410 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
411 (unsigned long) (VALUE))
414 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
415 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
416 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
417 (unsigned long) (VALUE))
420 #ifndef ASM_OUTPUT_DWARF_DATA8
421 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
423 if (WORDS_BIG_ENDIAN) \
425 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
426 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
430 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
431 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
436 #else /* UNALIGNED_INT_ASM_OP */
438 /* We don't have unaligned support, let's hope the normal output works for
441 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
442 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1)
444 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
445 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
447 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
448 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
450 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
451 assemble_integer (gen_rtx_MINUS (HImode, \
452 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
453 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
456 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
457 assemble_integer (gen_rtx_MINUS (SImode, \
458 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
459 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
462 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
463 assemble_integer (gen_rtx_MINUS (Pmode, \
464 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
465 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
468 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
469 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
471 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
472 assemble_integer (GEN_INT (VALUE), 4, 1)
474 #endif /* UNALIGNED_INT_ASM_OP */
477 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
478 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
480 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
481 assemble_name (FILE, SY); \
483 assemble_name (FILE, HI); \
485 assemble_name (FILE, LO); \
488 #endif /* SET_ASM_OP */
490 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
491 newline is produced. When flag_debug_asm is asserted, we add commentary
492 at the end of the line, so we must avoid output of a newline here. */
493 #ifndef ASM_OUTPUT_DWARF_STRING
494 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
496 register int slen = strlen(P); \
497 register const char *p = (P); \
499 fprintf (FILE, "\t.ascii \""); \
500 for (i = 0; i < slen; i++) \
502 register int c = p[i]; \
503 if (c == '\"' || c == '\\') \
509 fprintf (FILE, "\\%o", c); \
512 fprintf (FILE, "\\0\""); \
517 /* The DWARF 2 CFA column which tracks the return address. Normally this
518 is the column for PC, or the first column after all of the hard
520 #ifndef DWARF_FRAME_RETURN_COLUMN
522 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
524 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
528 /* The mapping from gcc register number to DWARF 2 CFA column number. By
529 default, we just provide columns for all registers. */
530 #ifndef DWARF_FRAME_REGNUM
531 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
534 /* Hook used by __throw. */
537 expand_builtin_dwarf_fp_regnum ()
539 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
542 /* The offset from the incoming value of %sp to the top of the stack frame
543 for the current function. */
544 #ifndef INCOMING_FRAME_SP_OFFSET
545 #define INCOMING_FRAME_SP_OFFSET 0
548 /* Return a pointer to a copy of the section string name S with all
549 attributes stripped off, and an asterisk prepended (for assemble_name). */
555 char *stripped = xmalloc (strlen (s) + 2);
560 while (*s && *s != ',')
567 /* Return the register number described by a given RTL node. */
573 register unsigned regno = REGNO (rtl);
575 if (regno >= FIRST_PSEUDO_REGISTER)
577 warning ("internal regno botch: regno = %d\n", regno);
581 regno = DBX_REGISTER_NUMBER (regno);
585 /* Generate code to initialize the register size table. */
588 expand_builtin_init_dwarf_reg_sizes (address)
592 enum machine_mode mode = TYPE_MODE (char_type_node);
593 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
594 rtx mem = gen_rtx_MEM (mode, addr);
596 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
598 int offset = i * GET_MODE_SIZE (mode);
599 int size = GET_MODE_SIZE (reg_raw_mode[i]);
601 emit_move_insn (change_address (mem, mode,
602 plus_constant (addr, offset)),
607 /* Convert a DWARF call frame info. operation to its string name */
610 dwarf_cfi_name (cfi_opc)
611 register unsigned cfi_opc;
615 case DW_CFA_advance_loc:
616 return "DW_CFA_advance_loc";
618 return "DW_CFA_offset";
620 return "DW_CFA_restore";
624 return "DW_CFA_set_loc";
625 case DW_CFA_advance_loc1:
626 return "DW_CFA_advance_loc1";
627 case DW_CFA_advance_loc2:
628 return "DW_CFA_advance_loc2";
629 case DW_CFA_advance_loc4:
630 return "DW_CFA_advance_loc4";
631 case DW_CFA_offset_extended:
632 return "DW_CFA_offset_extended";
633 case DW_CFA_restore_extended:
634 return "DW_CFA_restore_extended";
635 case DW_CFA_undefined:
636 return "DW_CFA_undefined";
637 case DW_CFA_same_value:
638 return "DW_CFA_same_value";
639 case DW_CFA_register:
640 return "DW_CFA_register";
641 case DW_CFA_remember_state:
642 return "DW_CFA_remember_state";
643 case DW_CFA_restore_state:
644 return "DW_CFA_restore_state";
646 return "DW_CFA_def_cfa";
647 case DW_CFA_def_cfa_register:
648 return "DW_CFA_def_cfa_register";
649 case DW_CFA_def_cfa_offset:
650 return "DW_CFA_def_cfa_offset";
652 /* SGI/MIPS specific */
653 case DW_CFA_MIPS_advance_loc8:
654 return "DW_CFA_MIPS_advance_loc8";
657 case DW_CFA_GNU_window_save:
658 return "DW_CFA_GNU_window_save";
659 case DW_CFA_GNU_args_size:
660 return "DW_CFA_GNU_args_size";
661 case DW_CFA_GNU_negative_offset_extended:
662 return "DW_CFA_GNU_negative_offset_extended";
665 return "DW_CFA_<unknown>";
669 /* Return a pointer to a newly allocated Call Frame Instruction. */
671 static inline dw_cfi_ref
674 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
676 cfi->dw_cfi_next = NULL;
677 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
678 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
683 /* Add a Call Frame Instruction to list of instructions. */
686 add_cfi (list_head, cfi)
687 register dw_cfi_ref *list_head;
688 register dw_cfi_ref cfi;
690 register dw_cfi_ref *p;
692 /* Find the end of the chain. */
693 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
699 /* Generate a new label for the CFI info to refer to. */
702 dwarf2out_cfi_label ()
704 static char label[20];
705 static unsigned long label_num = 0;
707 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
708 ASM_OUTPUT_LABEL (asm_out_file, label);
713 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
714 or to the CIE if LABEL is NULL. */
717 add_fde_cfi (label, cfi)
718 register const char *label;
719 register dw_cfi_ref cfi;
723 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
726 label = dwarf2out_cfi_label ();
728 if (fde->dw_fde_current_label == NULL
729 || strcmp (label, fde->dw_fde_current_label) != 0)
731 register dw_cfi_ref xcfi;
733 fde->dw_fde_current_label = label = xstrdup (label);
735 /* Set the location counter to the new label. */
737 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
738 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
739 add_cfi (&fde->dw_fde_cfi, xcfi);
742 add_cfi (&fde->dw_fde_cfi, cfi);
746 add_cfi (&cie_cfi_head, cfi);
749 /* Subroutine of lookup_cfa. */
752 lookup_cfa_1 (cfi, regp, offsetp)
753 register dw_cfi_ref cfi;
754 register unsigned long *regp;
755 register long *offsetp;
757 switch (cfi->dw_cfi_opc)
759 case DW_CFA_def_cfa_offset:
760 *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
762 case DW_CFA_def_cfa_register:
763 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
766 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
767 *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
774 /* Find the previous value for the CFA. */
777 lookup_cfa (regp, offsetp)
778 register unsigned long *regp;
779 register long *offsetp;
781 register dw_cfi_ref cfi;
783 *regp = (unsigned long) -1;
786 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
787 lookup_cfa_1 (cfi, regp, offsetp);
789 if (fde_table_in_use)
791 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
792 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
793 lookup_cfa_1 (cfi, regp, offsetp);
797 /* The current rule for calculating the DWARF2 canonical frame address. */
798 static unsigned long cfa_reg;
799 static long cfa_offset;
801 /* The register used for saving registers to the stack, and its offset
803 static unsigned cfa_store_reg;
804 static long cfa_store_offset;
806 /* The running total of the size of arguments pushed onto the stack. */
807 static long args_size;
809 /* The last args_size we actually output. */
810 static long old_args_size;
812 /* Entry point to update the canonical frame address (CFA).
813 LABEL is passed to add_fde_cfi. The value of CFA is now to be
814 calculated from REG+OFFSET. */
817 dwarf2out_def_cfa (label, reg, offset)
818 register const char *label;
819 register unsigned reg;
820 register long offset;
822 register dw_cfi_ref cfi;
823 unsigned long old_reg;
828 if (cfa_store_reg == reg)
829 cfa_store_offset = offset;
831 reg = DWARF_FRAME_REGNUM (reg);
832 lookup_cfa (&old_reg, &old_offset);
834 if (reg == old_reg && offset == old_offset)
841 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
842 cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
845 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
846 else if (offset == old_offset && old_reg != (unsigned long) -1)
848 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
849 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
855 cfi->dw_cfi_opc = DW_CFA_def_cfa;
856 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
857 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
860 add_fde_cfi (label, cfi);
863 /* Add the CFI for saving a register. REG is the CFA column number.
864 LABEL is passed to add_fde_cfi.
865 If SREG is -1, the register is saved at OFFSET from the CFA;
866 otherwise it is saved in SREG. */
869 reg_save (label, reg, sreg, offset)
870 register const char *label;
871 register unsigned reg;
872 register unsigned sreg;
873 register long offset;
875 register dw_cfi_ref cfi = new_cfi ();
877 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
879 /* The following comparison is correct. -1 is used to indicate that
880 the value isn't a register number. */
881 if (sreg == (unsigned int) -1)
884 /* The register number won't fit in 6 bits, so we have to use
886 cfi->dw_cfi_opc = DW_CFA_offset_extended;
888 cfi->dw_cfi_opc = DW_CFA_offset;
890 offset /= DWARF_CIE_DATA_ALIGNMENT;
893 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
896 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
898 else if (sreg == reg)
899 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
903 cfi->dw_cfi_opc = DW_CFA_register;
904 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
907 add_fde_cfi (label, cfi);
910 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
911 This CFI tells the unwinder that it needs to restore the window registers
912 from the previous frame's window save area.
914 ??? Perhaps we should note in the CIE where windows are saved (instead of
915 assuming 0(cfa)) and what registers are in the window. */
918 dwarf2out_window_save (label)
919 register const char *label;
921 register dw_cfi_ref cfi = new_cfi ();
922 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
923 add_fde_cfi (label, cfi);
926 /* Add a CFI to update the running total of the size of arguments
927 pushed onto the stack. */
930 dwarf2out_args_size (label, size)
934 register dw_cfi_ref cfi;
936 if (size == old_args_size)
938 old_args_size = size;
941 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
942 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
943 add_fde_cfi (label, cfi);
946 /* Entry point for saving a register to the stack. REG is the GCC register
947 number. LABEL and OFFSET are passed to reg_save. */
950 dwarf2out_reg_save (label, reg, offset)
951 register const char *label;
952 register unsigned reg;
953 register long offset;
955 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
958 /* Entry point for saving the return address in the stack.
959 LABEL and OFFSET are passed to reg_save. */
962 dwarf2out_return_save (label, offset)
963 register const char *label;
964 register long offset;
966 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
969 /* Entry point for saving the return address in a register.
970 LABEL and SREG are passed to reg_save. */
973 dwarf2out_return_reg (label, sreg)
974 register const char *label;
975 register unsigned sreg;
977 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
980 /* Record the initial position of the return address. RTL is
981 INCOMING_RETURN_ADDR_RTX. */
984 initial_return_save (rtl)
987 unsigned int reg = (unsigned int) -1;
990 switch (GET_CODE (rtl))
993 /* RA is in a register. */
994 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
997 /* RA is on the stack. */
999 switch (GET_CODE (rtl))
1002 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1007 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1009 offset = INTVAL (XEXP (rtl, 1));
1012 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1014 offset = -INTVAL (XEXP (rtl, 1));
1021 /* The return address is at some offset from any value we can
1022 actually load. For instance, on the SPARC it is in %i7+8. Just
1023 ignore the offset for now; it doesn't matter for unwinding frames. */
1024 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1026 initial_return_save (XEXP (rtl, 0));
1032 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset);
1035 /* Check INSN to see if it looks like a push or a stack adjustment, and
1036 make a note of it if it does. EH uses this information to find out how
1037 much extra space it needs to pop off the stack. */
1040 dwarf2out_stack_adjust (insn)
1046 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1048 /* Extract the size of the args from the CALL rtx itself. */
1050 insn = PATTERN (insn);
1051 if (GET_CODE (insn) == PARALLEL)
1052 insn = XVECEXP (insn, 0, 0);
1053 if (GET_CODE (insn) == SET)
1054 insn = SET_SRC (insn);
1055 assert (GET_CODE (insn) == CALL);
1056 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1060 /* If only calls can throw, and we have a frame pointer,
1061 save up adjustments until we see the CALL_INSN. */
1062 else if (! asynchronous_exceptions
1063 && cfa_reg != STACK_POINTER_REGNUM)
1066 if (GET_CODE (insn) == BARRIER)
1068 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1069 the compiler will have already emitted a stack adjustment, but
1070 doesn't bother for calls to noreturn functions. */
1071 #ifdef STACK_GROWS_DOWNWARD
1072 offset = -args_size;
1077 else if (GET_CODE (PATTERN (insn)) == SET)
1082 insn = PATTERN (insn);
1083 src = SET_SRC (insn);
1084 dest = SET_DEST (insn);
1086 if (dest == stack_pointer_rtx)
1088 /* (set (reg sp) (plus (reg sp) (const_int))) */
1089 code = GET_CODE (src);
1090 if (! (code == PLUS || code == MINUS)
1091 || XEXP (src, 0) != stack_pointer_rtx
1092 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1095 offset = INTVAL (XEXP (src, 1));
1097 else if (GET_CODE (dest) == MEM)
1099 /* (set (mem (pre_dec (reg sp))) (foo)) */
1100 src = XEXP (dest, 0);
1101 code = GET_CODE (src);
1103 if (! (code == PRE_DEC || code == PRE_INC)
1104 || XEXP (src, 0) != stack_pointer_rtx)
1107 offset = GET_MODE_SIZE (GET_MODE (dest));
1112 if (code == PLUS || code == PRE_INC)
1121 if (cfa_reg == STACK_POINTER_REGNUM)
1122 cfa_offset += offset;
1124 #ifndef STACK_GROWS_DOWNWARD
1127 args_size += offset;
1131 label = dwarf2out_cfi_label ();
1132 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1133 dwarf2out_args_size (label, args_size);
1136 /* A temporary register used in adjusting SP or setting up the store_reg. */
1137 static unsigned cfa_temp_reg;
1139 /* A temporary value used in adjusting SP or setting up the store_reg. */
1140 static long cfa_temp_value;
1142 /* Record call frame debugging information for an expression, which either
1143 sets SP or FP (adjusting how we calculate the frame address) or saves a
1144 register to the stack. */
1147 dwarf2out_frame_debug_expr (expr, label)
1154 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1155 the PARALLEL independantly. The first element is always processed if
1156 it is a SET. This is for backward compatability. Other elements
1157 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1158 flag is set in them. */
1160 if (GET_CODE (expr) == PARALLEL)
1163 int limit = XVECLEN (expr, 0);
1165 for (par_index = 0; par_index < limit; par_index++)
1167 rtx x = XVECEXP (expr, 0, par_index);
1169 if (GET_CODE (x) == SET &&
1170 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1171 dwarf2out_frame_debug_expr (x, label);
1176 if (GET_CODE (expr) != SET)
1179 src = SET_SRC (expr);
1180 dest = SET_DEST (expr);
1182 switch (GET_CODE (dest))
1185 /* Update the CFA rule wrt SP or FP. Make sure src is
1186 relative to the current CFA register. */
1187 switch (GET_CODE (src))
1189 /* Setting FP from SP. */
1191 if (cfa_reg != (unsigned) REGNO (src))
1194 /* We used to require that dest be either SP or FP, but the
1195 ARM copies SP to a temporary register, and from there to
1196 FP. So we just rely on the backends to only set
1197 RTX_FRAME_RELATED_P on appropriate insns. */
1198 cfa_reg = REGNO (dest);
1203 if (dest == stack_pointer_rtx)
1206 switch (GET_CODE (XEXP (src, 1)))
1209 offset = INTVAL (XEXP (src, 1));
1212 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1214 offset = cfa_temp_value;
1220 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1222 /* Restoring SP from FP in the epilogue. */
1223 if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1225 cfa_reg = STACK_POINTER_REGNUM;
1227 else if (XEXP (src, 0) != stack_pointer_rtx)
1230 if (GET_CODE (src) == PLUS)
1232 if (cfa_reg == STACK_POINTER_REGNUM)
1233 cfa_offset += offset;
1234 if (cfa_store_reg == STACK_POINTER_REGNUM)
1235 cfa_store_offset += offset;
1237 else if (dest == hard_frame_pointer_rtx)
1239 /* Either setting the FP from an offset of the SP,
1240 or adjusting the FP */
1241 if (! frame_pointer_needed)
1244 if (GET_CODE (XEXP (src, 0)) == REG
1245 && (unsigned) REGNO (XEXP (src, 0)) == cfa_reg
1246 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1248 offset = INTVAL (XEXP (src, 1));
1249 if (GET_CODE (src) == PLUS)
1251 cfa_offset += offset;
1252 cfa_reg = HARD_FRAME_POINTER_REGNUM;
1259 if (GET_CODE (src) != PLUS
1260 || XEXP (src, 1) != stack_pointer_rtx)
1262 if (GET_CODE (XEXP (src, 0)) != REG
1263 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1265 if (cfa_reg != STACK_POINTER_REGNUM)
1267 cfa_store_reg = REGNO (dest);
1268 cfa_store_offset = cfa_offset - cfa_temp_value;
1273 cfa_temp_reg = REGNO (dest);
1274 cfa_temp_value = INTVAL (src);
1278 if (GET_CODE (XEXP (src, 0)) != REG
1279 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1280 || (unsigned) REGNO (dest) != cfa_temp_reg
1281 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1283 cfa_temp_value |= INTVAL (XEXP (src, 1));
1289 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1293 /* Saving a register to the stack. Make sure dest is relative to the
1295 if (GET_CODE (src) != REG)
1297 switch (GET_CODE (XEXP (dest, 0)))
1302 offset = GET_MODE_SIZE (GET_MODE (dest));
1303 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1306 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1307 || cfa_store_reg != STACK_POINTER_REGNUM)
1309 cfa_store_offset += offset;
1310 if (cfa_reg == STACK_POINTER_REGNUM)
1311 cfa_offset = cfa_store_offset;
1313 offset = -cfa_store_offset;
1316 /* With an offset. */
1319 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1320 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1323 if (cfa_store_reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1325 offset -= cfa_store_offset;
1328 /* Without an offset. */
1330 if (cfa_store_reg != REGNO (XEXP (dest, 0)))
1332 offset = -cfa_store_offset;
1338 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1339 dwarf2out_reg_save (label, REGNO (src), offset);
1348 /* Record call frame debugging information for INSN, which either
1349 sets SP or FP (adjusting how we calculate the frame address) or saves a
1350 register to the stack. If INSN is NULL_RTX, initialize our state. */
1353 dwarf2out_frame_debug (insn)
1359 if (insn == NULL_RTX)
1361 /* Set up state for generating call frame debug info. */
1362 lookup_cfa (&cfa_reg, &cfa_offset);
1363 if (cfa_reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1365 cfa_reg = STACK_POINTER_REGNUM;
1366 cfa_store_reg = cfa_reg;
1367 cfa_store_offset = cfa_offset;
1373 if (! RTX_FRAME_RELATED_P (insn))
1375 dwarf2out_stack_adjust (insn);
1379 label = dwarf2out_cfi_label ();
1381 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1383 insn = XEXP (src, 0);
1385 insn = PATTERN (insn);
1387 dwarf2out_frame_debug_expr (insn, label);
1390 /* Return the size of an unsigned LEB128 quantity. */
1392 static inline unsigned long
1393 size_of_uleb128 (value)
1394 register unsigned long value;
1396 register unsigned long size = 0;
1397 register unsigned byte;
1401 byte = (value & 0x7f);
1410 /* Return the size of a signed LEB128 quantity. */
1412 static inline unsigned long
1413 size_of_sleb128 (value)
1414 register long value;
1416 register unsigned long size = 0;
1417 register unsigned byte;
1421 byte = (value & 0x7f);
1425 while (!(((value == 0) && ((byte & 0x40) == 0))
1426 || ((value == -1) && ((byte & 0x40) != 0))));
1431 /* Output an unsigned LEB128 quantity. */
1434 output_uleb128 (value)
1435 register unsigned long value;
1437 unsigned long save_value = value;
1439 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1442 register unsigned byte = (value & 0x7f);
1445 /* More bytes to follow. */
1448 fprintf (asm_out_file, "0x%x", byte);
1450 fprintf (asm_out_file, ",");
1455 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1458 /* Output an signed LEB128 quantity. */
1461 output_sleb128 (value)
1462 register long value;
1465 register unsigned byte;
1466 long save_value = value;
1468 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1471 byte = (value & 0x7f);
1472 /* arithmetic shift */
1474 more = !((((value == 0) && ((byte & 0x40) == 0))
1475 || ((value == -1) && ((byte & 0x40) != 0))));
1479 fprintf (asm_out_file, "0x%x", byte);
1481 fprintf (asm_out_file, ",");
1486 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1489 /* Output a Call Frame Information opcode and its operand(s). */
1492 output_cfi (cfi, fde)
1493 register dw_cfi_ref cfi;
1494 register dw_fde_ref fde;
1496 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1498 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1500 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1502 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1503 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1504 fputc ('\n', asm_out_file);
1507 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1509 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1511 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1513 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1514 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1516 fputc ('\n', asm_out_file);
1517 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1518 fputc ('\n', asm_out_file);
1520 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1522 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1524 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1526 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1527 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1529 fputc ('\n', asm_out_file);
1533 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1535 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1536 dwarf_cfi_name (cfi->dw_cfi_opc));
1538 fputc ('\n', asm_out_file);
1539 switch (cfi->dw_cfi_opc)
1541 case DW_CFA_set_loc:
1542 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1543 fputc ('\n', asm_out_file);
1545 case DW_CFA_advance_loc1:
1546 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1547 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1548 fde->dw_fde_current_label);
1549 fputc ('\n', asm_out_file);
1550 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1552 case DW_CFA_advance_loc2:
1553 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1554 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1555 fde->dw_fde_current_label);
1556 fputc ('\n', asm_out_file);
1557 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1559 case DW_CFA_advance_loc4:
1560 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1561 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1562 fde->dw_fde_current_label);
1563 fputc ('\n', asm_out_file);
1564 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1566 #ifdef MIPS_DEBUGGING_INFO
1567 case DW_CFA_MIPS_advance_loc8:
1568 /* TODO: not currently implemented. */
1572 case DW_CFA_offset_extended:
1573 case DW_CFA_GNU_negative_offset_extended:
1574 case DW_CFA_def_cfa:
1575 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1576 fputc ('\n', asm_out_file);
1577 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1578 fputc ('\n', asm_out_file);
1580 case DW_CFA_restore_extended:
1581 case DW_CFA_undefined:
1582 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1583 fputc ('\n', asm_out_file);
1585 case DW_CFA_same_value:
1586 case DW_CFA_def_cfa_register:
1587 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1588 fputc ('\n', asm_out_file);
1590 case DW_CFA_register:
1591 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1592 fputc ('\n', asm_out_file);
1593 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1594 fputc ('\n', asm_out_file);
1596 case DW_CFA_def_cfa_offset:
1597 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1598 fputc ('\n', asm_out_file);
1600 case DW_CFA_GNU_window_save:
1602 case DW_CFA_GNU_args_size:
1603 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1604 fputc ('\n', asm_out_file);
1612 /* Output the call frame information used to used to record information
1613 that relates to calculating the frame pointer, and records the
1614 location of saved registers. */
1617 output_call_frame_info (for_eh)
1620 register unsigned long i;
1621 register dw_fde_ref fde;
1622 register dw_cfi_ref cfi;
1623 char l1[20], l2[20];
1624 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1628 /* Do we want to include a pointer to the exception table? */
1629 int eh_ptr = for_eh && exception_table_p ();
1631 /* If we don't have any functions we'll want to unwind out of, don't
1632 emit any EH unwind information. */
1635 for (i = 0; i < fde_table_in_use; ++i)
1636 if (! fde_table[i].nothrow)
1642 fputc ('\n', asm_out_file);
1644 /* We're going to be generating comments, so turn on app. */
1650 #ifdef EH_FRAME_SECTION
1651 EH_FRAME_SECTION ();
1653 tree label = get_file_function_name ('F');
1655 force_data_section ();
1656 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1657 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1658 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1660 assemble_label ("__FRAME_BEGIN__");
1663 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1665 /* Output the CIE. */
1666 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1667 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1668 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1669 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1671 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1673 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1676 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1678 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1681 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1684 fputc ('\n', asm_out_file);
1685 ASM_OUTPUT_LABEL (asm_out_file, l1);
1688 /* Now that the CIE pointer is PC-relative for EH,
1689 use 0 to identify the CIE. */
1690 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1692 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1695 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1697 fputc ('\n', asm_out_file);
1698 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1700 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1701 fputc ('\n', asm_out_file);
1704 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1706 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1708 fputc ('\n', asm_out_file);
1711 /* The CIE contains a pointer to the exception region info for the
1712 frame. Make the augmentation string three bytes (including the
1713 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1714 can't handle unaligned relocs. */
1717 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1718 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1722 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1724 fputc ('\n', asm_out_file);
1726 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1728 fprintf (asm_out_file, "\t%s pointer to exception region info",
1733 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1735 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1739 fputc ('\n', asm_out_file);
1742 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1744 fputc ('\n', asm_out_file);
1745 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1747 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1749 fputc ('\n', asm_out_file);
1750 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1752 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1754 fputc ('\n', asm_out_file);
1756 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1757 output_cfi (cfi, NULL);
1759 /* Pad the CIE out to an address sized boundary. */
1760 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1761 ASM_OUTPUT_LABEL (asm_out_file, l2);
1762 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1763 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1765 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1766 fputc ('\n', asm_out_file);
1769 /* Loop through all of the FDE's. */
1770 for (i = 0; i < fde_table_in_use; ++i)
1772 fde = &fde_table[i];
1774 /* Don't emit EH unwind info for leaf functions. */
1775 if (for_eh && fde->nothrow)
1778 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2);
1779 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2);
1780 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1781 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2);
1783 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1785 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1788 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1790 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1793 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1794 fputc ('\n', asm_out_file);
1795 ASM_OUTPUT_LABEL (asm_out_file, l1);
1797 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1798 emits a target dependent sized offset when for_eh is not true.
1799 This inconsistency may confuse gdb. The only case where we need a
1800 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1801 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1802 though in order to be compatible with the dwarf_fde struct in frame.c.
1803 If the for_eh case is changed, then the struct in frame.c has
1804 to be adjusted appropriately. */
1806 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1808 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1810 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1812 fputc ('\n', asm_out_file);
1813 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1815 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1817 fputc ('\n', asm_out_file);
1818 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1819 fde->dw_fde_end, fde->dw_fde_begin);
1821 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1823 fputc ('\n', asm_out_file);
1825 /* Loop through the Call Frame Instructions associated with
1827 fde->dw_fde_current_label = fde->dw_fde_begin;
1828 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1829 output_cfi (cfi, fde);
1831 /* Pad the FDE out to an address sized boundary. */
1832 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1833 ASM_OUTPUT_LABEL (asm_out_file, l2);
1834 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1835 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1837 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1838 fputc ('\n', asm_out_file);
1841 #ifndef EH_FRAME_SECTION
1844 /* Emit terminating zero for table. */
1845 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1846 fputc ('\n', asm_out_file);
1849 #ifdef MIPS_DEBUGGING_INFO
1850 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1851 get a value of 0. Putting .align 0 after the label fixes it. */
1852 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1855 /* Turn off app to make assembly quicker. */
1860 /* Output a marker (i.e. a label) for the beginning of a function, before
1864 dwarf2out_begin_prologue ()
1866 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1867 register dw_fde_ref fde;
1869 ++current_funcdef_number;
1871 function_section (current_function_decl);
1872 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1873 current_funcdef_number);
1874 ASM_OUTPUT_LABEL (asm_out_file, label);
1875 current_function_func_begin_label = get_identifier (label);
1877 /* Expand the fde table if necessary. */
1878 if (fde_table_in_use == fde_table_allocated)
1880 fde_table_allocated += FDE_TABLE_INCREMENT;
1882 = (dw_fde_ref) xrealloc (fde_table,
1883 fde_table_allocated * sizeof (dw_fde_node));
1886 /* Record the FDE associated with this function. */
1887 current_funcdef_fde = fde_table_in_use;
1889 /* Add the new FDE at the end of the fde_table. */
1890 fde = &fde_table[fde_table_in_use++];
1891 fde->dw_fde_begin = xstrdup (label);
1892 fde->dw_fde_current_label = NULL;
1893 fde->dw_fde_end = NULL;
1894 fde->dw_fde_cfi = NULL;
1895 fde->nothrow = current_function_nothrow;
1897 args_size = old_args_size = 0;
1900 /* Output a marker (i.e. a label) for the absolute end of the generated code
1901 for a function definition. This gets called *after* the epilogue code has
1905 dwarf2out_end_epilogue ()
1908 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1910 /* Output a label to mark the endpoint of the code generated for this
1912 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1913 ASM_OUTPUT_LABEL (asm_out_file, label);
1914 fde = &fde_table[fde_table_in_use - 1];
1915 fde->dw_fde_end = xstrdup (label);
1919 dwarf2out_frame_init ()
1921 /* Allocate the initial hunk of the fde_table. */
1922 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
1923 fde_table_allocated = FDE_TABLE_INCREMENT;
1924 fde_table_in_use = 0;
1926 /* Generate the CFA instructions common to all FDE's. Do it now for the
1927 sake of lookup_cfa. */
1929 #ifdef DWARF2_UNWIND_INFO
1930 /* On entry, the Canonical Frame Address is at SP. */
1931 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1932 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1937 dwarf2out_frame_finish ()
1939 /* Output call frame information. */
1940 #ifdef MIPS_DEBUGGING_INFO
1941 if (write_symbols == DWARF2_DEBUG)
1942 output_call_frame_info (0);
1943 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1944 output_call_frame_info (1);
1946 if (write_symbols == DWARF2_DEBUG
1947 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1948 output_call_frame_info (1);
1952 #endif /* .debug_frame support */
1954 /* And now, the support for symbolic debugging information. */
1955 #ifdef DWARF2_DEBUGGING_INFO
1957 /* NOTE: In the comments in this file, many references are made to
1958 "Debugging Information Entries". This term is abbreviated as `DIE'
1959 throughout the remainder of this file. */
1961 /* An internal representation of the DWARF output is built, and then
1962 walked to generate the DWARF debugging info. The walk of the internal
1963 representation is done after the entire program has been compiled.
1964 The types below are used to describe the internal representation. */
1966 /* Each DIE may have a series of attribute/value pairs. Values
1967 can take on several forms. The forms that are used in this
1968 implementation are listed below. */
1975 dw_val_class_unsigned_const,
1976 dw_val_class_long_long,
1979 dw_val_class_die_ref,
1980 dw_val_class_fde_ref,
1981 dw_val_class_lbl_id,
1982 dw_val_class_lbl_offset,
1987 /* Various DIE's use offsets relative to the beginning of the
1988 .debug_info section to refer to each other. */
1990 typedef long int dw_offset;
1992 /* Define typedefs here to avoid circular dependencies. */
1994 typedef struct die_struct *dw_die_ref;
1995 typedef struct dw_attr_struct *dw_attr_ref;
1996 typedef struct dw_val_struct *dw_val_ref;
1997 typedef struct dw_line_info_struct *dw_line_info_ref;
1998 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
1999 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2000 typedef struct pubname_struct *pubname_ref;
2001 typedef dw_die_ref *arange_ref;
2003 /* Describe a double word constant value. */
2005 typedef struct dw_long_long_struct
2012 /* Describe a floating point constant value. */
2014 typedef struct dw_fp_struct
2021 /* Each entry in the line_info_table maintains the file and
2022 line number associated with the label generated for that
2023 entry. The label gives the PC value associated with
2024 the line number entry. */
2026 typedef struct dw_line_info_struct
2028 unsigned long dw_file_num;
2029 unsigned long dw_line_num;
2033 /* Line information for functions in separate sections; each one gets its
2035 typedef struct dw_separate_line_info_struct
2037 unsigned long dw_file_num;
2038 unsigned long dw_line_num;
2039 unsigned long function;
2041 dw_separate_line_info_entry;
2043 /* The dw_val_node describes an attribute's value, as it is
2044 represented internally. */
2046 typedef struct dw_val_struct
2048 dw_val_class val_class;
2052 dw_loc_descr_ref val_loc;
2054 long unsigned val_unsigned;
2055 dw_long_long_const val_long_long;
2056 dw_float_const val_float;
2057 dw_die_ref val_die_ref;
2058 unsigned val_fde_index;
2061 unsigned char val_flag;
2067 /* Locations in memory are described using a sequence of stack machine
2070 typedef struct dw_loc_descr_struct
2072 dw_loc_descr_ref dw_loc_next;
2073 enum dwarf_location_atom dw_loc_opc;
2074 dw_val_node dw_loc_oprnd1;
2075 dw_val_node dw_loc_oprnd2;
2079 /* Each DIE attribute has a field specifying the attribute kind,
2080 a link to the next attribute in the chain, and an attribute value.
2081 Attributes are typically linked below the DIE they modify. */
2083 typedef struct dw_attr_struct
2085 enum dwarf_attribute dw_attr;
2086 dw_attr_ref dw_attr_next;
2087 dw_val_node dw_attr_val;
2091 /* The Debugging Information Entry (DIE) structure */
2093 typedef struct die_struct
2095 enum dwarf_tag die_tag;
2096 dw_attr_ref die_attr;
2097 dw_die_ref die_parent;
2098 dw_die_ref die_child;
2100 dw_offset die_offset;
2101 unsigned long die_abbrev;
2105 /* The pubname structure */
2107 typedef struct pubname_struct
2114 /* The limbo die list structure. */
2115 typedef struct limbo_die_struct
2118 struct limbo_die_struct *next;
2122 /* How to start an assembler comment. */
2123 #ifndef ASM_COMMENT_START
2124 #define ASM_COMMENT_START ";#"
2127 /* Define a macro which returns non-zero for a TYPE_DECL which was
2128 implicitly generated for a tagged type.
2130 Note that unlike the gcc front end (which generates a NULL named
2131 TYPE_DECL node for each complete tagged type, each array type, and
2132 each function type node created) the g++ front end generates a
2133 _named_ TYPE_DECL node for each tagged type node created.
2134 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2135 generate a DW_TAG_typedef DIE for them. */
2137 #define TYPE_DECL_IS_STUB(decl) \
2138 (DECL_NAME (decl) == NULL_TREE \
2139 || (DECL_ARTIFICIAL (decl) \
2140 && is_tagged_type (TREE_TYPE (decl)) \
2141 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2142 /* This is necessary for stub decls that \
2143 appear in nested inline functions. */ \
2144 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2145 && (decl_ultimate_origin (decl) \
2146 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2148 /* Information concerning the compilation unit's programming
2149 language, and compiler version. */
2151 extern int flag_traditional;
2153 /* Fixed size portion of the DWARF compilation unit header. */
2154 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2156 /* Fixed size portion of debugging line information prolog. */
2157 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2159 /* Fixed size portion of public names info. */
2160 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2162 /* Fixed size portion of the address range info. */
2163 #define DWARF_ARANGES_HEADER_SIZE \
2164 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
2165 - DWARF_OFFSET_SIZE)
2167 /* Size of padding portion in the address range info. It must be
2168 aligned to twice the pointer size. */
2169 #define DWARF_ARANGES_PAD_SIZE \
2170 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
2171 - (2 * DWARF_OFFSET_SIZE + 4))
2173 /* The default is to have gcc emit the line number tables. */
2174 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2175 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2178 /* Define the architecture-dependent minimum instruction length (in bytes).
2179 In this implementation of DWARF, this field is used for information
2180 purposes only. Since GCC generates assembly language, we have
2181 no a priori knowledge of how many instruction bytes are generated
2182 for each source line, and therefore can use only the DW_LNE_set_address
2183 and DW_LNS_fixed_advance_pc line information commands. */
2185 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2186 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2189 /* Minimum line offset in a special line info. opcode.
2190 This value was chosen to give a reasonable range of values. */
2191 #define DWARF_LINE_BASE -10
2193 /* First special line opcde - leave room for the standard opcodes. */
2194 #define DWARF_LINE_OPCODE_BASE 10
2196 /* Range of line offsets in a special line info. opcode. */
2197 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2199 /* Flag that indicates the initial value of the is_stmt_start flag.
2200 In the present implementation, we do not mark any lines as
2201 the beginning of a source statement, because that information
2202 is not made available by the GCC front-end. */
2203 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2205 /* This location is used by calc_die_sizes() to keep track
2206 the offset of each DIE within the .debug_info section. */
2207 static unsigned long next_die_offset;
2209 /* Record the root of the DIE's built for the current compilation unit. */
2210 static dw_die_ref comp_unit_die;
2212 /* A list of DIEs with a NULL parent waiting to be relocated. */
2213 static limbo_die_node *limbo_die_list = 0;
2215 /* Pointer to an array of filenames referenced by this compilation unit. */
2216 static char **file_table;
2218 /* Total number of entries in the table (i.e. array) pointed to by
2219 `file_table'. This is the *total* and includes both used and unused
2221 static unsigned file_table_allocated;
2223 /* Number of entries in the file_table which are actually in use. */
2224 static unsigned file_table_in_use;
2226 /* Size (in elements) of increments by which we may expand the filename
2228 #define FILE_TABLE_INCREMENT 64
2230 /* Local pointer to the name of the main input file. Initialized in
2232 static const char *primary_filename;
2234 /* A pointer to the base of a table of references to DIE's that describe
2235 declarations. The table is indexed by DECL_UID() which is a unique
2236 number identifying each decl. */
2237 static dw_die_ref *decl_die_table;
2239 /* Number of elements currently allocated for the decl_die_table. */
2240 static unsigned decl_die_table_allocated;
2242 /* Number of elements in decl_die_table currently in use. */
2243 static unsigned decl_die_table_in_use;
2245 /* Size (in elements) of increments by which we may expand the
2247 #define DECL_DIE_TABLE_INCREMENT 256
2249 /* A pointer to the base of a table of references to declaration
2250 scopes. This table is a display which tracks the nesting
2251 of declaration scopes at the current scope and containing
2252 scopes. This table is used to find the proper place to
2253 define type declaration DIE's. */
2254 static tree *decl_scope_table;
2256 /* Number of elements currently allocated for the decl_scope_table. */
2257 static int decl_scope_table_allocated;
2259 /* Current level of nesting of declaration scopes. */
2260 static int decl_scope_depth;
2262 /* Size (in elements) of increments by which we may expand the
2263 decl_scope_table. */
2264 #define DECL_SCOPE_TABLE_INCREMENT 64
2266 /* A pointer to the base of a list of references to DIE's that
2267 are uniquely identified by their tag, presence/absence of
2268 children DIE's, and list of attribute/value pairs. */
2269 static dw_die_ref *abbrev_die_table;
2271 /* Number of elements currently allocated for abbrev_die_table. */
2272 static unsigned abbrev_die_table_allocated;
2274 /* Number of elements in type_die_table currently in use. */
2275 static unsigned abbrev_die_table_in_use;
2277 /* Size (in elements) of increments by which we may expand the
2278 abbrev_die_table. */
2279 #define ABBREV_DIE_TABLE_INCREMENT 256
2281 /* A pointer to the base of a table that contains line information
2282 for each source code line in .text in the compilation unit. */
2283 static dw_line_info_ref line_info_table;
2285 /* Number of elements currently allocated for line_info_table. */
2286 static unsigned line_info_table_allocated;
2288 /* Number of elements in separate_line_info_table currently in use. */
2289 static unsigned separate_line_info_table_in_use;
2291 /* A pointer to the base of a table that contains line information
2292 for each source code line outside of .text in the compilation unit. */
2293 static dw_separate_line_info_ref separate_line_info_table;
2295 /* Number of elements currently allocated for separate_line_info_table. */
2296 static unsigned separate_line_info_table_allocated;
2298 /* Number of elements in line_info_table currently in use. */
2299 static unsigned line_info_table_in_use;
2301 /* Size (in elements) of increments by which we may expand the
2303 #define LINE_INFO_TABLE_INCREMENT 1024
2305 /* A pointer to the base of a table that contains a list of publicly
2306 accessible names. */
2307 static pubname_ref pubname_table;
2309 /* Number of elements currently allocated for pubname_table. */
2310 static unsigned pubname_table_allocated;
2312 /* Number of elements in pubname_table currently in use. */
2313 static unsigned pubname_table_in_use;
2315 /* Size (in elements) of increments by which we may expand the
2317 #define PUBNAME_TABLE_INCREMENT 64
2319 /* A pointer to the base of a table that contains a list of publicly
2320 accessible names. */
2321 static arange_ref arange_table;
2323 /* Number of elements currently allocated for arange_table. */
2324 static unsigned arange_table_allocated;
2326 /* Number of elements in arange_table currently in use. */
2327 static unsigned arange_table_in_use;
2329 /* Size (in elements) of increments by which we may expand the
2331 #define ARANGE_TABLE_INCREMENT 64
2333 /* A pointer to the base of a list of incomplete types which might be
2334 completed at some later time. */
2336 static tree *incomplete_types_list;
2338 /* Number of elements currently allocated for the incomplete_types_list. */
2339 static unsigned incomplete_types_allocated;
2341 /* Number of elements of incomplete_types_list currently in use. */
2342 static unsigned incomplete_types;
2344 /* Size (in elements) of increments by which we may expand the incomplete
2345 types list. Actually, a single hunk of space of this size should
2346 be enough for most typical programs. */
2347 #define INCOMPLETE_TYPES_INCREMENT 64
2349 /* Record whether the function being analyzed contains inlined functions. */
2350 static int current_function_has_inlines;
2351 #if 0 && defined (MIPS_DEBUGGING_INFO)
2352 static int comp_unit_has_inlines;
2355 /* Array of RTXes referenced by the debugging information, which therefore
2356 must be kept around forever. We do this rather than perform GC on
2357 the dwarf info because almost all of the dwarf info lives forever, and
2358 it's easier to support non-GC frontends this way. */
2359 static varray_type used_rtx_varray;
2361 /* Forward declarations for functions defined in this file. */
2363 static int is_pseudo_reg PARAMS ((rtx));
2364 static tree type_main_variant PARAMS ((tree));
2365 static int is_tagged_type PARAMS ((tree));
2366 static const char *dwarf_tag_name PARAMS ((unsigned));
2367 static const char *dwarf_attr_name PARAMS ((unsigned));
2368 static const char *dwarf_form_name PARAMS ((unsigned));
2369 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2371 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
2373 static tree decl_ultimate_origin PARAMS ((tree));
2374 static tree block_ultimate_origin PARAMS ((tree));
2375 static tree decl_class_context PARAMS ((tree));
2376 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
2377 static void add_AT_flag PARAMS ((dw_die_ref,
2378 enum dwarf_attribute,
2380 static void add_AT_int PARAMS ((dw_die_ref,
2381 enum dwarf_attribute, long));
2382 static void add_AT_unsigned PARAMS ((dw_die_ref,
2383 enum dwarf_attribute,
2385 static void add_AT_long_long PARAMS ((dw_die_ref,
2386 enum dwarf_attribute,
2389 static void add_AT_float PARAMS ((dw_die_ref,
2390 enum dwarf_attribute,
2392 static void add_AT_string PARAMS ((dw_die_ref,
2393 enum dwarf_attribute,
2395 static void add_AT_die_ref PARAMS ((dw_die_ref,
2396 enum dwarf_attribute,
2398 static void add_AT_fde_ref PARAMS ((dw_die_ref,
2399 enum dwarf_attribute,
2401 static void add_AT_loc PARAMS ((dw_die_ref,
2402 enum dwarf_attribute,
2404 static void add_AT_addr PARAMS ((dw_die_ref,
2405 enum dwarf_attribute,
2407 static void add_AT_lbl_id PARAMS ((dw_die_ref,
2408 enum dwarf_attribute,
2410 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
2411 enum dwarf_attribute,
2413 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
2414 enum dwarf_attribute));
2415 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
2416 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
2417 static const char *get_AT_string PARAMS ((dw_die_ref,
2418 enum dwarf_attribute));
2419 static int get_AT_flag PARAMS ((dw_die_ref,
2420 enum dwarf_attribute));
2421 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
2422 enum dwarf_attribute));
2423 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
2424 enum dwarf_attribute));
2425 static int is_c_family PARAMS ((void));
2426 static int is_fortran PARAMS ((void));
2427 static void remove_AT PARAMS ((dw_die_ref,
2428 enum dwarf_attribute));
2429 static void remove_children PARAMS ((dw_die_ref));
2430 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
2431 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
2432 static dw_die_ref lookup_type_die PARAMS ((tree));
2433 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
2434 static dw_die_ref lookup_decl_die PARAMS ((tree));
2435 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
2436 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2439 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2441 static void print_spaces PARAMS ((FILE *));
2442 static void print_die PARAMS ((dw_die_ref, FILE *));
2443 static void print_dwarf_line_table PARAMS ((FILE *));
2444 static void add_sibling_attributes PARAMS ((dw_die_ref));
2445 static void build_abbrev_table PARAMS ((dw_die_ref));
2446 static unsigned long size_of_string PARAMS ((const char *));
2447 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2448 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2449 static int constant_size PARAMS ((long unsigned));
2450 static unsigned long size_of_die PARAMS ((dw_die_ref));
2451 static void calc_die_sizes PARAMS ((dw_die_ref));
2452 static unsigned long size_of_line_prolog PARAMS ((void));
2453 static unsigned long size_of_pubnames PARAMS ((void));
2454 static unsigned long size_of_aranges PARAMS ((void));
2455 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
2456 static void output_value_format PARAMS ((dw_attr_ref));
2457 static void output_abbrev_section PARAMS ((void));
2458 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2459 static void output_die PARAMS ((dw_die_ref));
2460 static void output_compilation_unit_header PARAMS ((void));
2461 static const char *dwarf2_name PARAMS ((tree, int));
2462 static void add_pubname PARAMS ((tree, dw_die_ref));
2463 static void output_pubnames PARAMS ((void));
2464 static void add_arange PARAMS ((tree, dw_die_ref));
2465 static void output_aranges PARAMS ((void));
2466 static void output_line_info PARAMS ((void));
2467 static dw_die_ref base_type_die PARAMS ((tree));
2468 static tree root_type PARAMS ((tree));
2469 static int is_base_type PARAMS ((tree));
2470 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
2471 static int type_is_enum PARAMS ((tree));
2472 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
2473 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
2474 static int is_based_loc PARAMS ((rtx));
2475 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
2476 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
2477 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
2478 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
2479 static tree field_type PARAMS ((tree));
2480 static unsigned int simple_type_align_in_bits PARAMS ((tree));
2481 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
2482 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
2483 static void add_AT_location_description PARAMS ((dw_die_ref,
2484 enum dwarf_attribute, rtx));
2485 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
2486 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
2487 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
2488 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
2489 static void add_bound_info PARAMS ((dw_die_ref,
2490 enum dwarf_attribute, tree));
2491 static void add_subscript_info PARAMS ((dw_die_ref, tree));
2492 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
2493 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
2494 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
2495 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
2496 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
2497 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
2498 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
2499 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
2500 static void push_decl_scope PARAMS ((tree));
2501 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
2502 static void pop_decl_scope PARAMS ((void));
2503 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
2505 static const char *type_tag PARAMS ((tree));
2506 static tree member_declared_type PARAMS ((tree));
2508 static const char *decl_start_label PARAMS ((tree));
2510 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
2511 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
2513 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
2515 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
2516 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
2517 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
2518 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
2519 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
2520 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
2521 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
2522 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
2523 static void gen_variable_die PARAMS ((tree, dw_die_ref));
2524 static void gen_label_die PARAMS ((tree, dw_die_ref));
2525 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
2526 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
2527 static void gen_field_die PARAMS ((tree, dw_die_ref));
2528 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
2529 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
2530 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
2531 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
2532 static void gen_member_die PARAMS ((tree, dw_die_ref));
2533 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
2534 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
2535 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
2536 static void gen_type_die PARAMS ((tree, dw_die_ref));
2537 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
2538 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
2539 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
2540 static int is_redundant_typedef PARAMS ((tree));
2541 static void gen_decl_die PARAMS ((tree, dw_die_ref));
2542 static unsigned lookup_filename PARAMS ((const char *));
2543 static void add_incomplete_type PARAMS ((tree));
2544 static void retry_incomplete_types PARAMS ((void));
2545 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
2546 static void gen_abstract_function PARAMS ((tree));
2547 static rtx save_rtx PARAMS ((rtx));
2548 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
2549 static void reverse_die_lists PARAMS ((dw_die_ref));
2551 /* Section names used to hold DWARF debugging information. */
2552 #ifndef DEBUG_INFO_SECTION
2553 #define DEBUG_INFO_SECTION ".debug_info"
2555 #ifndef ABBREV_SECTION
2556 #define ABBREV_SECTION ".debug_abbrev"
2558 #ifndef ARANGES_SECTION
2559 #define ARANGES_SECTION ".debug_aranges"
2561 #ifndef DW_MACINFO_SECTION
2562 #define DW_MACINFO_SECTION ".debug_macinfo"
2564 #ifndef DEBUG_LINE_SECTION
2565 #define DEBUG_LINE_SECTION ".debug_line"
2568 #define LOC_SECTION ".debug_loc"
2570 #ifndef PUBNAMES_SECTION
2571 #define PUBNAMES_SECTION ".debug_pubnames"
2574 #define STR_SECTION ".debug_str"
2577 /* Standard ELF section names for compiled code and data. */
2578 #ifndef TEXT_SECTION
2579 #define TEXT_SECTION ".text"
2581 #ifndef DATA_SECTION
2582 #define DATA_SECTION ".data"
2585 #define BSS_SECTION ".bss"
2588 /* Labels we insert at beginning sections we can reference instead of
2589 the section names themselves. */
2591 #ifndef TEXT_SECTION_LABEL
2592 #define TEXT_SECTION_LABEL "Ltext"
2594 #ifndef DEBUG_LINE_SECTION_LABEL
2595 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
2597 #ifndef DEBUG_INFO_SECTION_LABEL
2598 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
2600 #ifndef ABBREV_SECTION_LABEL
2601 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
2605 /* Definitions of defaults for formats and names of various special
2606 (artificial) labels which may be generated within this file (when the -g
2607 options is used and DWARF_DEBUGGING_INFO is in effect.
2608 If necessary, these may be overridden from within the tm.h file, but
2609 typically, overriding these defaults is unnecessary. */
2611 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2612 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2613 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2614 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2615 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2617 #ifndef TEXT_END_LABEL
2618 #define TEXT_END_LABEL "Letext"
2620 #ifndef DATA_END_LABEL
2621 #define DATA_END_LABEL "Ledata"
2623 #ifndef BSS_END_LABEL
2624 #define BSS_END_LABEL "Lebss"
2626 #ifndef INSN_LABEL_FMT
2627 #define INSN_LABEL_FMT "LI%u_"
2629 #ifndef BLOCK_BEGIN_LABEL
2630 #define BLOCK_BEGIN_LABEL "LBB"
2632 #ifndef BLOCK_END_LABEL
2633 #define BLOCK_END_LABEL "LBE"
2635 #ifndef BODY_BEGIN_LABEL
2636 #define BODY_BEGIN_LABEL "Lbb"
2638 #ifndef BODY_END_LABEL
2639 #define BODY_END_LABEL "Lbe"
2641 #ifndef LINE_CODE_LABEL
2642 #define LINE_CODE_LABEL "LM"
2644 #ifndef SEPARATE_LINE_CODE_LABEL
2645 #define SEPARATE_LINE_CODE_LABEL "LSM"
2648 /* We allow a language front-end to designate a function that is to be
2649 called to "demangle" any name before it it put into a DIE. */
2651 static const char *(*demangle_name_func) PARAMS ((const char *));
2654 dwarf2out_set_demangle_name_func (func)
2655 const char *(*func) PARAMS ((const char *));
2657 demangle_name_func = func;
2660 /* Return an rtx like ORIG which lives forever. If we're doing GC,
2661 that means adding it to used_rtx_varray. If not, that means making
2662 a copy on the permanent_obstack. */
2669 VARRAY_PUSH_RTX (used_rtx_varray, orig);
2672 push_obstacks_nochange ();
2673 end_temporary_allocation ();
2674 orig = copy_rtx (orig);
2681 /* Test if rtl node points to a pseudo register. */
2687 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
2688 || (GET_CODE (rtl) == SUBREG
2689 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
2692 /* Return a reference to a type, with its const and volatile qualifiers
2696 type_main_variant (type)
2699 type = TYPE_MAIN_VARIANT (type);
2701 /* There really should be only one main variant among any group of variants
2702 of a given type (and all of the MAIN_VARIANT values for all members of
2703 the group should point to that one type) but sometimes the C front-end
2704 messes this up for array types, so we work around that bug here. */
2706 if (TREE_CODE (type) == ARRAY_TYPE)
2707 while (type != TYPE_MAIN_VARIANT (type))
2708 type = TYPE_MAIN_VARIANT (type);
2713 /* Return non-zero if the given type node represents a tagged type. */
2716 is_tagged_type (type)
2719 register enum tree_code code = TREE_CODE (type);
2721 return (code == RECORD_TYPE || code == UNION_TYPE
2722 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
2725 /* Convert a DIE tag into its string name. */
2728 dwarf_tag_name (tag)
2729 register unsigned tag;
2733 case DW_TAG_padding:
2734 return "DW_TAG_padding";
2735 case DW_TAG_array_type:
2736 return "DW_TAG_array_type";
2737 case DW_TAG_class_type:
2738 return "DW_TAG_class_type";
2739 case DW_TAG_entry_point:
2740 return "DW_TAG_entry_point";
2741 case DW_TAG_enumeration_type:
2742 return "DW_TAG_enumeration_type";
2743 case DW_TAG_formal_parameter:
2744 return "DW_TAG_formal_parameter";
2745 case DW_TAG_imported_declaration:
2746 return "DW_TAG_imported_declaration";
2748 return "DW_TAG_label";
2749 case DW_TAG_lexical_block:
2750 return "DW_TAG_lexical_block";
2752 return "DW_TAG_member";
2753 case DW_TAG_pointer_type:
2754 return "DW_TAG_pointer_type";
2755 case DW_TAG_reference_type:
2756 return "DW_TAG_reference_type";
2757 case DW_TAG_compile_unit:
2758 return "DW_TAG_compile_unit";
2759 case DW_TAG_string_type:
2760 return "DW_TAG_string_type";
2761 case DW_TAG_structure_type:
2762 return "DW_TAG_structure_type";
2763 case DW_TAG_subroutine_type:
2764 return "DW_TAG_subroutine_type";
2765 case DW_TAG_typedef:
2766 return "DW_TAG_typedef";
2767 case DW_TAG_union_type:
2768 return "DW_TAG_union_type";
2769 case DW_TAG_unspecified_parameters:
2770 return "DW_TAG_unspecified_parameters";
2771 case DW_TAG_variant:
2772 return "DW_TAG_variant";
2773 case DW_TAG_common_block:
2774 return "DW_TAG_common_block";
2775 case DW_TAG_common_inclusion:
2776 return "DW_TAG_common_inclusion";
2777 case DW_TAG_inheritance:
2778 return "DW_TAG_inheritance";
2779 case DW_TAG_inlined_subroutine:
2780 return "DW_TAG_inlined_subroutine";
2782 return "DW_TAG_module";
2783 case DW_TAG_ptr_to_member_type:
2784 return "DW_TAG_ptr_to_member_type";
2785 case DW_TAG_set_type:
2786 return "DW_TAG_set_type";
2787 case DW_TAG_subrange_type:
2788 return "DW_TAG_subrange_type";
2789 case DW_TAG_with_stmt:
2790 return "DW_TAG_with_stmt";
2791 case DW_TAG_access_declaration:
2792 return "DW_TAG_access_declaration";
2793 case DW_TAG_base_type:
2794 return "DW_TAG_base_type";
2795 case DW_TAG_catch_block:
2796 return "DW_TAG_catch_block";
2797 case DW_TAG_const_type:
2798 return "DW_TAG_const_type";
2799 case DW_TAG_constant:
2800 return "DW_TAG_constant";
2801 case DW_TAG_enumerator:
2802 return "DW_TAG_enumerator";
2803 case DW_TAG_file_type:
2804 return "DW_TAG_file_type";
2806 return "DW_TAG_friend";
2807 case DW_TAG_namelist:
2808 return "DW_TAG_namelist";
2809 case DW_TAG_namelist_item:
2810 return "DW_TAG_namelist_item";
2811 case DW_TAG_packed_type:
2812 return "DW_TAG_packed_type";
2813 case DW_TAG_subprogram:
2814 return "DW_TAG_subprogram";
2815 case DW_TAG_template_type_param:
2816 return "DW_TAG_template_type_param";
2817 case DW_TAG_template_value_param:
2818 return "DW_TAG_template_value_param";
2819 case DW_TAG_thrown_type:
2820 return "DW_TAG_thrown_type";
2821 case DW_TAG_try_block:
2822 return "DW_TAG_try_block";
2823 case DW_TAG_variant_part:
2824 return "DW_TAG_variant_part";
2825 case DW_TAG_variable:
2826 return "DW_TAG_variable";
2827 case DW_TAG_volatile_type:
2828 return "DW_TAG_volatile_type";
2829 case DW_TAG_MIPS_loop:
2830 return "DW_TAG_MIPS_loop";
2831 case DW_TAG_format_label:
2832 return "DW_TAG_format_label";
2833 case DW_TAG_function_template:
2834 return "DW_TAG_function_template";
2835 case DW_TAG_class_template:
2836 return "DW_TAG_class_template";
2838 return "DW_TAG_<unknown>";
2842 /* Convert a DWARF attribute code into its string name. */
2845 dwarf_attr_name (attr)
2846 register unsigned attr;
2851 return "DW_AT_sibling";
2852 case DW_AT_location:
2853 return "DW_AT_location";
2855 return "DW_AT_name";
2856 case DW_AT_ordering:
2857 return "DW_AT_ordering";
2858 case DW_AT_subscr_data:
2859 return "DW_AT_subscr_data";
2860 case DW_AT_byte_size:
2861 return "DW_AT_byte_size";
2862 case DW_AT_bit_offset:
2863 return "DW_AT_bit_offset";
2864 case DW_AT_bit_size:
2865 return "DW_AT_bit_size";
2866 case DW_AT_element_list:
2867 return "DW_AT_element_list";
2868 case DW_AT_stmt_list:
2869 return "DW_AT_stmt_list";
2871 return "DW_AT_low_pc";
2873 return "DW_AT_high_pc";
2874 case DW_AT_language:
2875 return "DW_AT_language";
2877 return "DW_AT_member";
2879 return "DW_AT_discr";
2880 case DW_AT_discr_value:
2881 return "DW_AT_discr_value";
2882 case DW_AT_visibility:
2883 return "DW_AT_visibility";
2885 return "DW_AT_import";
2886 case DW_AT_string_length:
2887 return "DW_AT_string_length";
2888 case DW_AT_common_reference:
2889 return "DW_AT_common_reference";
2890 case DW_AT_comp_dir:
2891 return "DW_AT_comp_dir";
2892 case DW_AT_const_value:
2893 return "DW_AT_const_value";
2894 case DW_AT_containing_type:
2895 return "DW_AT_containing_type";
2896 case DW_AT_default_value:
2897 return "DW_AT_default_value";
2899 return "DW_AT_inline";
2900 case DW_AT_is_optional:
2901 return "DW_AT_is_optional";
2902 case DW_AT_lower_bound:
2903 return "DW_AT_lower_bound";
2904 case DW_AT_producer:
2905 return "DW_AT_producer";
2906 case DW_AT_prototyped:
2907 return "DW_AT_prototyped";
2908 case DW_AT_return_addr:
2909 return "DW_AT_return_addr";
2910 case DW_AT_start_scope:
2911 return "DW_AT_start_scope";
2912 case DW_AT_stride_size:
2913 return "DW_AT_stride_size";
2914 case DW_AT_upper_bound:
2915 return "DW_AT_upper_bound";
2916 case DW_AT_abstract_origin:
2917 return "DW_AT_abstract_origin";
2918 case DW_AT_accessibility:
2919 return "DW_AT_accessibility";
2920 case DW_AT_address_class:
2921 return "DW_AT_address_class";
2922 case DW_AT_artificial:
2923 return "DW_AT_artificial";
2924 case DW_AT_base_types:
2925 return "DW_AT_base_types";
2926 case DW_AT_calling_convention:
2927 return "DW_AT_calling_convention";
2929 return "DW_AT_count";
2930 case DW_AT_data_member_location:
2931 return "DW_AT_data_member_location";
2932 case DW_AT_decl_column:
2933 return "DW_AT_decl_column";
2934 case DW_AT_decl_file:
2935 return "DW_AT_decl_file";
2936 case DW_AT_decl_line:
2937 return "DW_AT_decl_line";
2938 case DW_AT_declaration:
2939 return "DW_AT_declaration";
2940 case DW_AT_discr_list:
2941 return "DW_AT_discr_list";
2942 case DW_AT_encoding:
2943 return "DW_AT_encoding";
2944 case DW_AT_external:
2945 return "DW_AT_external";
2946 case DW_AT_frame_base:
2947 return "DW_AT_frame_base";
2949 return "DW_AT_friend";
2950 case DW_AT_identifier_case:
2951 return "DW_AT_identifier_case";
2952 case DW_AT_macro_info:
2953 return "DW_AT_macro_info";
2954 case DW_AT_namelist_items:
2955 return "DW_AT_namelist_items";
2956 case DW_AT_priority:
2957 return "DW_AT_priority";
2959 return "DW_AT_segment";
2960 case DW_AT_specification:
2961 return "DW_AT_specification";
2962 case DW_AT_static_link:
2963 return "DW_AT_static_link";
2965 return "DW_AT_type";
2966 case DW_AT_use_location:
2967 return "DW_AT_use_location";
2968 case DW_AT_variable_parameter:
2969 return "DW_AT_variable_parameter";
2970 case DW_AT_virtuality:
2971 return "DW_AT_virtuality";
2972 case DW_AT_vtable_elem_location:
2973 return "DW_AT_vtable_elem_location";
2975 case DW_AT_MIPS_fde:
2976 return "DW_AT_MIPS_fde";
2977 case DW_AT_MIPS_loop_begin:
2978 return "DW_AT_MIPS_loop_begin";
2979 case DW_AT_MIPS_tail_loop_begin:
2980 return "DW_AT_MIPS_tail_loop_begin";
2981 case DW_AT_MIPS_epilog_begin:
2982 return "DW_AT_MIPS_epilog_begin";
2983 case DW_AT_MIPS_loop_unroll_factor:
2984 return "DW_AT_MIPS_loop_unroll_factor";
2985 case DW_AT_MIPS_software_pipeline_depth:
2986 return "DW_AT_MIPS_software_pipeline_depth";
2987 case DW_AT_MIPS_linkage_name:
2988 return "DW_AT_MIPS_linkage_name";
2989 case DW_AT_MIPS_stride:
2990 return "DW_AT_MIPS_stride";
2991 case DW_AT_MIPS_abstract_name:
2992 return "DW_AT_MIPS_abstract_name";
2993 case DW_AT_MIPS_clone_origin:
2994 return "DW_AT_MIPS_clone_origin";
2995 case DW_AT_MIPS_has_inlines:
2996 return "DW_AT_MIPS_has_inlines";
2998 case DW_AT_sf_names:
2999 return "DW_AT_sf_names";
3000 case DW_AT_src_info:
3001 return "DW_AT_src_info";
3002 case DW_AT_mac_info:
3003 return "DW_AT_mac_info";
3004 case DW_AT_src_coords:
3005 return "DW_AT_src_coords";
3006 case DW_AT_body_begin:
3007 return "DW_AT_body_begin";
3008 case DW_AT_body_end:
3009 return "DW_AT_body_end";
3011 return "DW_AT_<unknown>";
3015 /* Convert a DWARF value form code into its string name. */
3018 dwarf_form_name (form)
3019 register unsigned form;
3024 return "DW_FORM_addr";
3025 case DW_FORM_block2:
3026 return "DW_FORM_block2";
3027 case DW_FORM_block4:
3028 return "DW_FORM_block4";
3030 return "DW_FORM_data2";
3032 return "DW_FORM_data4";
3034 return "DW_FORM_data8";
3035 case DW_FORM_string:
3036 return "DW_FORM_string";
3038 return "DW_FORM_block";
3039 case DW_FORM_block1:
3040 return "DW_FORM_block1";
3042 return "DW_FORM_data1";
3044 return "DW_FORM_flag";
3046 return "DW_FORM_sdata";
3048 return "DW_FORM_strp";
3050 return "DW_FORM_udata";
3051 case DW_FORM_ref_addr:
3052 return "DW_FORM_ref_addr";
3054 return "DW_FORM_ref1";
3056 return "DW_FORM_ref2";
3058 return "DW_FORM_ref4";
3060 return "DW_FORM_ref8";
3061 case DW_FORM_ref_udata:
3062 return "DW_FORM_ref_udata";
3063 case DW_FORM_indirect:
3064 return "DW_FORM_indirect";
3066 return "DW_FORM_<unknown>";
3070 /* Convert a DWARF stack opcode into its string name. */
3073 dwarf_stack_op_name (op)
3074 register unsigned op;
3079 return "DW_OP_addr";
3081 return "DW_OP_deref";
3083 return "DW_OP_const1u";
3085 return "DW_OP_const1s";
3087 return "DW_OP_const2u";
3089 return "DW_OP_const2s";
3091 return "DW_OP_const4u";
3093 return "DW_OP_const4s";
3095 return "DW_OP_const8u";
3097 return "DW_OP_const8s";
3099 return "DW_OP_constu";
3101 return "DW_OP_consts";
3105 return "DW_OP_drop";
3107 return "DW_OP_over";
3109 return "DW_OP_pick";
3111 return "DW_OP_swap";
3115 return "DW_OP_xderef";
3123 return "DW_OP_minus";
3135 return "DW_OP_plus";
3136 case DW_OP_plus_uconst:
3137 return "DW_OP_plus_uconst";
3143 return "DW_OP_shra";
3161 return "DW_OP_skip";
3163 return "DW_OP_lit0";
3165 return "DW_OP_lit1";
3167 return "DW_OP_lit2";
3169 return "DW_OP_lit3";
3171 return "DW_OP_lit4";
3173 return "DW_OP_lit5";
3175 return "DW_OP_lit6";
3177 return "DW_OP_lit7";
3179 return "DW_OP_lit8";
3181 return "DW_OP_lit9";
3183 return "DW_OP_lit10";
3185 return "DW_OP_lit11";
3187 return "DW_OP_lit12";
3189 return "DW_OP_lit13";
3191 return "DW_OP_lit14";
3193 return "DW_OP_lit15";
3195 return "DW_OP_lit16";
3197 return "DW_OP_lit17";
3199 return "DW_OP_lit18";
3201 return "DW_OP_lit19";
3203 return "DW_OP_lit20";
3205 return "DW_OP_lit21";
3207 return "DW_OP_lit22";
3209 return "DW_OP_lit23";
3211 return "DW_OP_lit24";
3213 return "DW_OP_lit25";
3215 return "DW_OP_lit26";
3217 return "DW_OP_lit27";
3219 return "DW_OP_lit28";
3221 return "DW_OP_lit29";
3223 return "DW_OP_lit30";
3225 return "DW_OP_lit31";
3227 return "DW_OP_reg0";
3229 return "DW_OP_reg1";
3231 return "DW_OP_reg2";
3233 return "DW_OP_reg3";
3235 return "DW_OP_reg4";
3237 return "DW_OP_reg5";
3239 return "DW_OP_reg6";
3241 return "DW_OP_reg7";
3243 return "DW_OP_reg8";
3245 return "DW_OP_reg9";
3247 return "DW_OP_reg10";
3249 return "DW_OP_reg11";
3251 return "DW_OP_reg12";
3253 return "DW_OP_reg13";
3255 return "DW_OP_reg14";
3257 return "DW_OP_reg15";
3259 return "DW_OP_reg16";
3261 return "DW_OP_reg17";
3263 return "DW_OP_reg18";
3265 return "DW_OP_reg19";
3267 return "DW_OP_reg20";
3269 return "DW_OP_reg21";
3271 return "DW_OP_reg22";
3273 return "DW_OP_reg23";
3275 return "DW_OP_reg24";
3277 return "DW_OP_reg25";
3279 return "DW_OP_reg26";
3281 return "DW_OP_reg27";
3283 return "DW_OP_reg28";
3285 return "DW_OP_reg29";
3287 return "DW_OP_reg30";
3289 return "DW_OP_reg31";
3291 return "DW_OP_breg0";
3293 return "DW_OP_breg1";
3295 return "DW_OP_breg2";
3297 return "DW_OP_breg3";
3299 return "DW_OP_breg4";
3301 return "DW_OP_breg5";
3303 return "DW_OP_breg6";
3305 return "DW_OP_breg7";
3307 return "DW_OP_breg8";
3309 return "DW_OP_breg9";
3311 return "DW_OP_breg10";
3313 return "DW_OP_breg11";
3315 return "DW_OP_breg12";
3317 return "DW_OP_breg13";
3319 return "DW_OP_breg14";
3321 return "DW_OP_breg15";
3323 return "DW_OP_breg16";
3325 return "DW_OP_breg17";
3327 return "DW_OP_breg18";
3329 return "DW_OP_breg19";
3331 return "DW_OP_breg20";
3333 return "DW_OP_breg21";
3335 return "DW_OP_breg22";
3337 return "DW_OP_breg23";
3339 return "DW_OP_breg24";
3341 return "DW_OP_breg25";
3343 return "DW_OP_breg26";
3345 return "DW_OP_breg27";
3347 return "DW_OP_breg28";
3349 return "DW_OP_breg29";
3351 return "DW_OP_breg30";
3353 return "DW_OP_breg31";
3355 return "DW_OP_regx";
3357 return "DW_OP_fbreg";
3359 return "DW_OP_bregx";
3361 return "DW_OP_piece";
3362 case DW_OP_deref_size:
3363 return "DW_OP_deref_size";
3364 case DW_OP_xderef_size:
3365 return "DW_OP_xderef_size";
3369 return "OP_<unknown>";
3373 /* Convert a DWARF type code into its string name. */
3377 dwarf_type_encoding_name (enc)
3378 register unsigned enc;
3382 case DW_ATE_address:
3383 return "DW_ATE_address";
3384 case DW_ATE_boolean:
3385 return "DW_ATE_boolean";
3386 case DW_ATE_complex_float:
3387 return "DW_ATE_complex_float";
3389 return "DW_ATE_float";
3391 return "DW_ATE_signed";
3392 case DW_ATE_signed_char:
3393 return "DW_ATE_signed_char";
3394 case DW_ATE_unsigned:
3395 return "DW_ATE_unsigned";
3396 case DW_ATE_unsigned_char:
3397 return "DW_ATE_unsigned_char";
3399 return "DW_ATE_<unknown>";
3404 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3405 instance of an inlined instance of a decl which is local to an inline
3406 function, so we have to trace all of the way back through the origin chain
3407 to find out what sort of node actually served as the original seed for the
3411 decl_ultimate_origin (decl)
3414 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3415 nodes in the function to point to themselves; ignore that if
3416 we're trying to output the abstract instance of this function. */
3417 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
3420 #ifdef ENABLE_CHECKING
3421 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
3422 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3423 most distant ancestor, this should never happen. */
3427 return DECL_ABSTRACT_ORIGIN (decl);
3430 /* Determine the "ultimate origin" of a block. The block may be an inlined
3431 instance of an inlined instance of a block which is local to an inline
3432 function, so we have to trace all of the way back through the origin chain
3433 to find out what sort of node actually served as the original seed for the
3437 block_ultimate_origin (block)
3438 register tree block;
3440 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3442 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
3443 nodes in the function to point to themselves; ignore that if
3444 we're trying to output the abstract instance of this function. */
3445 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
3448 if (immediate_origin == NULL_TREE)
3452 register tree ret_val;
3453 register tree lookahead = immediate_origin;
3457 ret_val = lookahead;
3458 lookahead = (TREE_CODE (ret_val) == BLOCK)
3459 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3462 while (lookahead != NULL && lookahead != ret_val);
3468 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3469 of a virtual function may refer to a base class, so we check the 'this'
3473 decl_class_context (decl)
3476 tree context = NULL_TREE;
3478 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3479 context = DECL_CONTEXT (decl);
3481 context = TYPE_MAIN_VARIANT
3482 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3484 if (context && !TYPE_P (context))
3485 context = NULL_TREE;
3490 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
3491 addition order, and correct that in add_sibling_attributes. */
3494 add_dwarf_attr (die, attr)
3495 register dw_die_ref die;
3496 register dw_attr_ref attr;
3498 if (die != NULL && attr != NULL)
3500 attr->dw_attr_next = die->die_attr;
3501 die->die_attr = attr;
3505 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
3506 static inline dw_val_class
3510 return a->dw_attr_val.val_class;
3513 /* Add a flag value attribute to a DIE. */
3516 add_AT_flag (die, attr_kind, flag)
3517 register dw_die_ref die;
3518 register enum dwarf_attribute attr_kind;
3519 register unsigned flag;
3521 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3523 attr->dw_attr_next = NULL;
3524 attr->dw_attr = attr_kind;
3525 attr->dw_attr_val.val_class = dw_val_class_flag;
3526 attr->dw_attr_val.v.val_flag = flag;
3527 add_dwarf_attr (die, attr);
3530 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
3531 static inline unsigned
3533 register dw_attr_ref a;
3535 if (a && AT_class (a) == dw_val_class_flag)
3536 return a->dw_attr_val.v.val_flag;
3541 /* Add a signed integer attribute value to a DIE. */
3544 add_AT_int (die, attr_kind, int_val)
3545 register dw_die_ref die;
3546 register enum dwarf_attribute attr_kind;
3547 register long int int_val;
3549 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3551 attr->dw_attr_next = NULL;
3552 attr->dw_attr = attr_kind;
3553 attr->dw_attr_val.val_class = dw_val_class_const;
3554 attr->dw_attr_val.v.val_int = int_val;
3555 add_dwarf_attr (die, attr);
3558 static inline long int AT_int PARAMS ((dw_attr_ref));
3559 static inline long int
3561 register dw_attr_ref a;
3563 if (a && AT_class (a) == dw_val_class_const)
3564 return a->dw_attr_val.v.val_int;
3569 /* Add an unsigned integer attribute value to a DIE. */
3572 add_AT_unsigned (die, attr_kind, unsigned_val)
3573 register dw_die_ref die;
3574 register enum dwarf_attribute attr_kind;
3575 register unsigned long unsigned_val;
3577 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3579 attr->dw_attr_next = NULL;
3580 attr->dw_attr = attr_kind;
3581 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
3582 attr->dw_attr_val.v.val_unsigned = unsigned_val;
3583 add_dwarf_attr (die, attr);
3586 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
3587 static inline unsigned long
3589 register dw_attr_ref a;
3591 if (a && AT_class (a) == dw_val_class_unsigned_const)
3592 return a->dw_attr_val.v.val_unsigned;
3597 /* Add an unsigned double integer attribute value to a DIE. */
3600 add_AT_long_long (die, attr_kind, val_hi, val_low)
3601 register dw_die_ref die;
3602 register enum dwarf_attribute attr_kind;
3603 register unsigned long val_hi;
3604 register unsigned long val_low;
3606 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3608 attr->dw_attr_next = NULL;
3609 attr->dw_attr = attr_kind;
3610 attr->dw_attr_val.val_class = dw_val_class_long_long;
3611 attr->dw_attr_val.v.val_long_long.hi = val_hi;
3612 attr->dw_attr_val.v.val_long_long.low = val_low;
3613 add_dwarf_attr (die, attr);
3616 /* Add a floating point attribute value to a DIE and return it. */
3619 add_AT_float (die, attr_kind, length, array)
3620 register dw_die_ref die;
3621 register enum dwarf_attribute attr_kind;
3622 register unsigned length;
3623 register long *array;
3625 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3627 attr->dw_attr_next = NULL;
3628 attr->dw_attr = attr_kind;
3629 attr->dw_attr_val.val_class = dw_val_class_float;
3630 attr->dw_attr_val.v.val_float.length = length;
3631 attr->dw_attr_val.v.val_float.array = array;
3632 add_dwarf_attr (die, attr);
3635 /* Add a string attribute value to a DIE. */
3638 add_AT_string (die, attr_kind, str)
3639 register dw_die_ref die;
3640 register enum dwarf_attribute attr_kind;
3641 register const char *str;
3643 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3645 attr->dw_attr_next = NULL;
3646 attr->dw_attr = attr_kind;
3647 attr->dw_attr_val.val_class = dw_val_class_str;
3648 attr->dw_attr_val.v.val_str = xstrdup (str);
3649 add_dwarf_attr (die, attr);
3652 static inline const char *AT_string PARAMS ((dw_attr_ref));
3653 static inline const char *
3655 register dw_attr_ref a;
3657 if (a && AT_class (a) == dw_val_class_str)
3658 return a->dw_attr_val.v.val_str;
3663 /* Add a DIE reference attribute value to a DIE. */
3666 add_AT_die_ref (die, attr_kind, targ_die)
3667 register dw_die_ref die;
3668 register enum dwarf_attribute attr_kind;
3669 register dw_die_ref targ_die;
3671 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3673 attr->dw_attr_next = NULL;
3674 attr->dw_attr = attr_kind;
3675 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3676 attr->dw_attr_val.v.val_die_ref = targ_die;
3677 add_dwarf_attr (die, attr);
3680 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
3681 static inline dw_die_ref
3683 register dw_attr_ref a;
3685 if (a && AT_class (a) == dw_val_class_die_ref)
3686 return a->dw_attr_val.v.val_die_ref;
3691 /* Add an FDE reference attribute value to a DIE. */
3694 add_AT_fde_ref (die, attr_kind, targ_fde)
3695 register dw_die_ref die;
3696 register enum dwarf_attribute attr_kind;
3697 register unsigned targ_fde;
3699 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3701 attr->dw_attr_next = NULL;
3702 attr->dw_attr = attr_kind;
3703 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
3704 attr->dw_attr_val.v.val_fde_index = targ_fde;
3705 add_dwarf_attr (die, attr);
3708 /* Add a location description attribute value to a DIE. */
3711 add_AT_loc (die, attr_kind, loc)
3712 register dw_die_ref die;
3713 register enum dwarf_attribute attr_kind;
3714 register dw_loc_descr_ref loc;
3716 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3718 attr->dw_attr_next = NULL;
3719 attr->dw_attr = attr_kind;
3720 attr->dw_attr_val.val_class = dw_val_class_loc;
3721 attr->dw_attr_val.v.val_loc = loc;
3722 add_dwarf_attr (die, attr);
3725 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
3726 static inline dw_loc_descr_ref
3728 register dw_attr_ref a;
3730 if (a && AT_class (a) == dw_val_class_loc)
3731 return a->dw_attr_val.v.val_loc;
3736 /* Add an address constant attribute value to a DIE. */
3739 add_AT_addr (die, attr_kind, addr)
3740 register dw_die_ref die;
3741 register enum dwarf_attribute attr_kind;
3744 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3746 attr->dw_attr_next = NULL;
3747 attr->dw_attr = attr_kind;
3748 attr->dw_attr_val.val_class = dw_val_class_addr;
3749 attr->dw_attr_val.v.val_addr = addr;
3750 add_dwarf_attr (die, attr);
3753 static inline rtx AT_addr PARAMS ((dw_attr_ref));
3756 register dw_attr_ref a;
3758 if (a && AT_class (a) == dw_val_class_addr)
3759 return a->dw_attr_val.v.val_addr;
3764 /* Add a label identifier attribute value to a DIE. */
3767 add_AT_lbl_id (die, attr_kind, lbl_id)
3768 register dw_die_ref die;
3769 register enum dwarf_attribute attr_kind;
3770 register const char *lbl_id;
3772 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3774 attr->dw_attr_next = NULL;
3775 attr->dw_attr = attr_kind;
3776 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
3777 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
3778 add_dwarf_attr (die, attr);
3781 /* Add a section offset attribute value to a DIE. */
3784 add_AT_lbl_offset (die, attr_kind, label)
3785 register dw_die_ref die;
3786 register enum dwarf_attribute attr_kind;
3787 register const char *label;
3789 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3791 attr->dw_attr_next = NULL;
3792 attr->dw_attr = attr_kind;
3793 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
3794 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
3795 add_dwarf_attr (die, attr);
3799 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
3800 static inline const char *
3802 register dw_attr_ref a;
3804 if (a && (AT_class (a) == dw_val_class_lbl_id
3805 || AT_class (a) == dw_val_class_lbl_offset))
3806 return a->dw_attr_val.v.val_lbl_id;
3811 /* Get the attribute of type attr_kind. */
3813 static inline dw_attr_ref
3814 get_AT (die, attr_kind)
3815 register dw_die_ref die;
3816 register enum dwarf_attribute attr_kind;
3818 register dw_attr_ref a;
3819 register dw_die_ref spec = NULL;
3823 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3825 if (a->dw_attr == attr_kind)
3828 if (a->dw_attr == DW_AT_specification
3829 || a->dw_attr == DW_AT_abstract_origin)
3834 return get_AT (spec, attr_kind);
3840 /* Return the "low pc" attribute value, typically associated with
3841 a subprogram DIE. Return null if the "low pc" attribute is
3842 either not prsent, or if it cannot be represented as an
3843 assembler label identifier. */
3845 static inline const char *
3847 register dw_die_ref die;
3849 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
3853 /* Return the "high pc" attribute value, typically associated with
3854 a subprogram DIE. Return null if the "high pc" attribute is
3855 either not prsent, or if it cannot be represented as an
3856 assembler label identifier. */
3858 static inline const char *
3860 register dw_die_ref die;
3862 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
3866 /* Return the value of the string attribute designated by ATTR_KIND, or
3867 NULL if it is not present. */
3869 static inline const char *
3870 get_AT_string (die, attr_kind)
3871 register dw_die_ref die;
3872 register enum dwarf_attribute attr_kind;
3874 register dw_attr_ref a = get_AT (die, attr_kind);
3875 return AT_string (a);
3878 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3879 if it is not present. */
3882 get_AT_flag (die, attr_kind)
3883 register dw_die_ref die;
3884 register enum dwarf_attribute attr_kind;
3886 register dw_attr_ref a = get_AT (die, attr_kind);
3890 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3891 if it is not present. */
3893 static inline unsigned
3894 get_AT_unsigned (die, attr_kind)
3895 register dw_die_ref die;
3896 register enum dwarf_attribute attr_kind;
3898 register dw_attr_ref a = get_AT (die, attr_kind);
3899 return AT_unsigned (a);
3902 static inline dw_die_ref
3903 get_AT_ref (die, attr_kind)
3905 register enum dwarf_attribute attr_kind;
3907 register dw_attr_ref a = get_AT (die, attr_kind);
3914 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3916 return (lang == DW_LANG_C || lang == DW_LANG_C89
3917 || lang == DW_LANG_C_plus_plus);
3923 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3925 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
3928 /* Free up the memory used by A. */
3930 static inline void free_AT PARAMS ((dw_attr_ref));
3935 switch (AT_class (a))
3937 case dw_val_class_str:
3938 case dw_val_class_lbl_id:
3939 case dw_val_class_lbl_offset:
3940 free (a->dw_attr_val.v.val_str);
3950 /* Remove the specified attribute if present. */
3953 remove_AT (die, attr_kind)
3954 register dw_die_ref die;
3955 register enum dwarf_attribute attr_kind;
3957 register dw_attr_ref *p;
3958 register dw_attr_ref removed = NULL;
3962 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
3963 if ((*p)->dw_attr == attr_kind)
3966 *p = (*p)->dw_attr_next;
3975 /* Free up the memory used by DIE. */
3977 static inline void free_die PARAMS ((dw_die_ref));
3982 remove_children (die);
3986 /* Discard the children of this DIE. */
3989 remove_children (die)
3990 register dw_die_ref die;
3992 register dw_die_ref child_die = die->die_child;
3994 die->die_child = NULL;
3996 while (child_die != NULL)
3998 register dw_die_ref tmp_die = child_die;
3999 register dw_attr_ref a;
4001 child_die = child_die->die_sib;
4003 for (a = tmp_die->die_attr; a != NULL; )
4005 register dw_attr_ref tmp_a = a;
4007 a = a->dw_attr_next;
4015 /* Add a child DIE below its parent. We build the lists up in reverse
4016 addition order, and correct that in add_sibling_attributes. */
4019 add_child_die (die, child_die)
4020 register dw_die_ref die;
4021 register dw_die_ref child_die;
4023 if (die != NULL && child_die != NULL)
4025 if (die == child_die)
4027 child_die->die_parent = die;
4028 child_die->die_sib = die->die_child;
4029 die->die_child = child_die;
4033 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4034 is the specification, to the front of PARENT's list of children. */
4037 splice_child_die (parent, child)
4038 dw_die_ref parent, child;
4042 /* We want the declaration DIE from inside the class, not the
4043 specification DIE at toplevel. */
4044 if (child->die_parent != parent)
4046 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4051 if (child->die_parent != parent
4052 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4055 for (p = &(parent->die_child); *p; p = &((*p)->die_sib))
4058 *p = child->die_sib;
4062 child->die_sib = parent->die_child;
4063 parent->die_child = child;
4066 /* Return a pointer to a newly created DIE node. */
4068 static inline dw_die_ref
4069 new_die (tag_value, parent_die)
4070 register enum dwarf_tag tag_value;
4071 register dw_die_ref parent_die;
4073 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4075 die->die_tag = tag_value;
4076 die->die_abbrev = 0;
4077 die->die_offset = 0;
4078 die->die_child = NULL;
4079 die->die_parent = NULL;
4080 die->die_sib = NULL;
4081 die->die_attr = NULL;
4083 if (parent_die != NULL)
4084 add_child_die (parent_die, die);
4087 limbo_die_node *limbo_node;
4089 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4090 limbo_node->die = die;
4091 limbo_node->next = limbo_die_list;
4092 limbo_die_list = limbo_node;
4098 /* Return the DIE associated with the given type specifier. */
4100 static inline dw_die_ref
4101 lookup_type_die (type)
4104 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4107 /* Equate a DIE to a given type specifier. */
4110 equate_type_number_to_die (type, type_die)
4112 register dw_die_ref type_die;
4114 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4117 /* Return the DIE associated with a given declaration. */
4119 static inline dw_die_ref
4120 lookup_decl_die (decl)
4123 register unsigned decl_id = DECL_UID (decl);
4125 return (decl_id < decl_die_table_in_use
4126 ? decl_die_table[decl_id] : NULL);
4129 /* Equate a DIE to a particular declaration. */
4132 equate_decl_number_to_die (decl, decl_die)
4134 register dw_die_ref decl_die;
4136 register unsigned decl_id = DECL_UID (decl);
4137 register unsigned num_allocated;
4139 if (decl_id >= decl_die_table_allocated)
4142 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4143 / DECL_DIE_TABLE_INCREMENT)
4144 * DECL_DIE_TABLE_INCREMENT;
4147 = (dw_die_ref *) xrealloc (decl_die_table,
4148 sizeof (dw_die_ref) * num_allocated);
4150 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4151 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4152 decl_die_table_allocated = num_allocated;
4155 if (decl_id >= decl_die_table_in_use)
4156 decl_die_table_in_use = (decl_id + 1);
4158 decl_die_table[decl_id] = decl_die;
4161 /* Return a pointer to a newly allocated location description. Location
4162 descriptions are simple expression terms that can be strung
4163 together to form more complicated location (address) descriptions. */
4165 static inline dw_loc_descr_ref
4166 new_loc_descr (op, oprnd1, oprnd2)
4167 register enum dwarf_location_atom op;
4168 register unsigned long oprnd1;
4169 register unsigned long oprnd2;
4171 register dw_loc_descr_ref descr
4172 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
4174 descr->dw_loc_next = NULL;
4175 descr->dw_loc_opc = op;
4176 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4177 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4178 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4179 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4184 /* Add a location description term to a location description expression. */
4187 add_loc_descr (list_head, descr)
4188 register dw_loc_descr_ref *list_head;
4189 register dw_loc_descr_ref descr;
4191 register dw_loc_descr_ref *d;
4193 /* Find the end of the chain. */
4194 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4200 /* Keep track of the number of spaces used to indent the
4201 output of the debugging routines that print the structure of
4202 the DIE internal representation. */
4203 static int print_indent;
4205 /* Indent the line the number of spaces given by print_indent. */
4208 print_spaces (outfile)
4211 fprintf (outfile, "%*s", print_indent, "");
4214 /* Print the information associated with a given DIE, and its children.
4215 This routine is a debugging aid only. */
4218 print_die (die, outfile)
4222 register dw_attr_ref a;
4223 register dw_die_ref c;
4225 print_spaces (outfile);
4226 fprintf (outfile, "DIE %4lu: %s\n",
4227 die->die_offset, dwarf_tag_name (die->die_tag));
4228 print_spaces (outfile);
4229 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4230 fprintf (outfile, " offset: %lu\n", die->die_offset);
4232 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4234 print_spaces (outfile);
4235 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4237 switch (AT_class (a))
4239 case dw_val_class_addr:
4240 fprintf (outfile, "address");
4242 case dw_val_class_loc:
4243 fprintf (outfile, "location descriptor");
4245 case dw_val_class_const:
4246 fprintf (outfile, "%ld", AT_int (a));
4248 case dw_val_class_unsigned_const:
4249 fprintf (outfile, "%lu", AT_unsigned (a));
4251 case dw_val_class_long_long:
4252 fprintf (outfile, "constant (%lu,%lu)",
4253 a->dw_attr_val.v.val_long_long.hi,
4254 a->dw_attr_val.v.val_long_long.low);
4256 case dw_val_class_float:
4257 fprintf (outfile, "floating-point constant");
4259 case dw_val_class_flag:
4260 fprintf (outfile, "%u", AT_flag (a));
4262 case dw_val_class_die_ref:
4263 if (AT_ref (a) != NULL)
4264 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4266 fprintf (outfile, "die -> <null>");
4268 case dw_val_class_lbl_id:
4269 case dw_val_class_lbl_offset:
4270 fprintf (outfile, "label: %s", AT_lbl (a));
4272 case dw_val_class_str:
4273 if (AT_string (a) != NULL)
4274 fprintf (outfile, "\"%s\"", AT_string (a));
4276 fprintf (outfile, "<null>");
4282 fprintf (outfile, "\n");
4285 if (die->die_child != NULL)
4288 for (c = die->die_child; c != NULL; c = c->die_sib)
4289 print_die (c, outfile);
4295 /* Print the contents of the source code line number correspondence table.
4296 This routine is a debugging aid only. */
4299 print_dwarf_line_table (outfile)
4302 register unsigned i;
4303 register dw_line_info_ref line_info;
4305 fprintf (outfile, "\n\nDWARF source line information\n");
4306 for (i = 1; i < line_info_table_in_use; ++i)
4308 line_info = &line_info_table[i];
4309 fprintf (outfile, "%5d: ", i);
4310 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4311 fprintf (outfile, "%6ld", line_info->dw_line_num);
4312 fprintf (outfile, "\n");
4315 fprintf (outfile, "\n\n");
4318 /* Print the information collected for a given DIE. */
4321 debug_dwarf_die (die)
4324 print_die (die, stderr);
4327 /* Print all DWARF information collected for the compilation unit.
4328 This routine is a debugging aid only. */
4334 print_die (comp_unit_die, stderr);
4335 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4336 print_dwarf_line_table (stderr);
4339 /* We build up the lists of children and attributes by pushing new ones
4340 onto the beginning of the list. Reverse the lists for DIE so that
4341 they are in order of addition. */
4344 reverse_die_lists (die)
4345 register dw_die_ref die;
4347 register dw_die_ref c, cp, cn;
4348 register dw_attr_ref a, ap, an;
4350 for (a = die->die_attr, ap = 0; a; a = an)
4352 an = a->dw_attr_next;
4353 a->dw_attr_next = ap;
4358 for (c = die->die_child, cp = 0; c; c = cn)
4364 die->die_child = cp;
4367 /* Traverse the DIE, reverse its lists of attributes and children, and
4368 add a sibling attribute if it may have the effect of speeding up
4369 access to siblings. To save some space, avoid generating sibling
4370 attributes for DIE's without children. */
4373 add_sibling_attributes (die)
4374 register dw_die_ref die;
4376 register dw_die_ref c;
4378 reverse_die_lists (die);
4380 if (die != comp_unit_die && die->die_sib && die->die_child != NULL)
4381 /* Add the sibling link to the front of the attribute list. */
4382 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
4384 for (c = die->die_child; c != NULL; c = c->die_sib)
4385 add_sibling_attributes (c);
4388 /* The format of each DIE (and its attribute value pairs)
4389 is encoded in an abbreviation table. This routine builds the
4390 abbreviation table and assigns a unique abbreviation id for
4391 each abbreviation entry. The children of each die are visited
4395 build_abbrev_table (die)
4396 register dw_die_ref die;
4398 register unsigned long abbrev_id;
4399 register unsigned long n_alloc;
4400 register dw_die_ref c;
4401 register dw_attr_ref d_attr, a_attr;
4402 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4404 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4406 if (abbrev->die_tag == die->die_tag)
4408 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
4410 a_attr = abbrev->die_attr;
4411 d_attr = die->die_attr;
4413 while (a_attr != NULL && d_attr != NULL)
4415 if ((a_attr->dw_attr != d_attr->dw_attr)
4416 || (value_format (a_attr) != value_format (d_attr)))
4419 a_attr = a_attr->dw_attr_next;
4420 d_attr = d_attr->dw_attr_next;
4423 if (a_attr == NULL && d_attr == NULL)
4429 if (abbrev_id >= abbrev_die_table_in_use)
4431 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
4433 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
4435 = (dw_die_ref *) xrealloc (abbrev_die_table,
4436 sizeof (dw_die_ref) * n_alloc);
4438 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
4439 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
4440 abbrev_die_table_allocated = n_alloc;
4443 ++abbrev_die_table_in_use;
4444 abbrev_die_table[abbrev_id] = die;
4447 die->die_abbrev = abbrev_id;
4448 for (c = die->die_child; c != NULL; c = c->die_sib)
4449 build_abbrev_table (c);
4452 /* Return the size of a string, including the null byte.
4454 This used to treat backslashes as escapes, and hence they were not included
4455 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
4456 which treats a backslash as a backslash, escaping it if necessary, and hence
4457 we must include them in the count. */
4459 static unsigned long
4460 size_of_string (str)
4461 register const char *str;
4463 return strlen (str) + 1;
4466 /* Return the size of a location descriptor. */
4468 static unsigned long
4469 size_of_loc_descr (loc)
4470 register dw_loc_descr_ref loc;
4472 register unsigned long size = 1;
4474 switch (loc->dw_loc_opc)
4477 size += DWARF2_ADDR_SIZE;
4496 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4499 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4504 case DW_OP_plus_uconst:
4505 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4543 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4546 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4549 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4552 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4553 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4556 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4558 case DW_OP_deref_size:
4559 case DW_OP_xderef_size:
4569 /* Return the size of a series of location descriptors. */
4571 static unsigned long
4573 register dw_loc_descr_ref loc;
4575 register unsigned long size = 0;
4577 for (; loc != NULL; loc = loc->dw_loc_next)
4578 size += size_of_loc_descr (loc);
4583 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4586 constant_size (value)
4587 long unsigned value;
4594 log = floor_log2 (value);
4597 log = 1 << (floor_log2 (log) + 1);
4602 /* Return the size of a DIE, as it is represented in the
4603 .debug_info section. */
4605 static unsigned long
4607 register dw_die_ref die;
4609 register unsigned long size = 0;
4610 register dw_attr_ref a;
4612 size += size_of_uleb128 (die->die_abbrev);
4613 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4615 switch (AT_class (a))
4617 case dw_val_class_addr:
4618 size += DWARF2_ADDR_SIZE;
4620 case dw_val_class_loc:
4622 register unsigned long lsize = size_of_locs (AT_loc (a));
4625 size += constant_size (lsize);
4629 case dw_val_class_const:
4632 case dw_val_class_unsigned_const:
4633 size += constant_size (AT_unsigned (a));
4635 case dw_val_class_long_long:
4636 size += 1 + 8; /* block */
4638 case dw_val_class_float:
4639 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
4641 case dw_val_class_flag:
4644 case dw_val_class_die_ref:
4645 size += DWARF_OFFSET_SIZE;
4647 case dw_val_class_fde_ref:
4648 size += DWARF_OFFSET_SIZE;
4650 case dw_val_class_lbl_id:
4651 size += DWARF2_ADDR_SIZE;
4653 case dw_val_class_lbl_offset:
4654 size += DWARF_OFFSET_SIZE;
4656 case dw_val_class_str:
4657 size += size_of_string (AT_string (a));
4667 /* Size the debugging information associated with a given DIE.
4668 Visits the DIE's children recursively. Updates the global
4669 variable next_die_offset, on each time through. Uses the
4670 current value of next_die_offset to update the die_offset
4671 field in each DIE. */
4674 calc_die_sizes (die)
4677 register dw_die_ref c;
4678 die->die_offset = next_die_offset;
4679 next_die_offset += size_of_die (die);
4681 for (c = die->die_child; c != NULL; c = c->die_sib)
4684 if (die->die_child != NULL)
4685 /* Count the null byte used to terminate sibling lists. */
4686 next_die_offset += 1;
4689 /* Return the size of the line information prolog generated for the
4690 compilation unit. */
4692 static unsigned long
4693 size_of_line_prolog ()
4695 register unsigned long size;
4696 register unsigned long ft_index;
4698 size = DWARF_LINE_PROLOG_HEADER_SIZE;
4700 /* Count the size of the table giving number of args for each
4702 size += DWARF_LINE_OPCODE_BASE - 1;
4704 /* Include directory table is empty (at present). Count only the
4705 null byte used to terminate the table. */
4708 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4710 /* File name entry. */
4711 size += size_of_string (file_table[ft_index]);
4713 /* Include directory index. */
4714 size += size_of_uleb128 (0);
4716 /* Modification time. */
4717 size += size_of_uleb128 (0);
4719 /* File length in bytes. */
4720 size += size_of_uleb128 (0);
4723 /* Count the file table terminator. */
4728 /* Return the size of the .debug_pubnames table generated for the
4729 compilation unit. */
4731 static unsigned long
4734 register unsigned long size;
4735 register unsigned i;
4737 size = DWARF_PUBNAMES_HEADER_SIZE;
4738 for (i = 0; i < pubname_table_in_use; ++i)
4740 register pubname_ref p = &pubname_table[i];
4741 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
4744 size += DWARF_OFFSET_SIZE;
4748 /* Return the size of the information in the .debug_aranges section. */
4750 static unsigned long
4753 register unsigned long size;
4755 size = DWARF_ARANGES_HEADER_SIZE;
4757 /* Count the address/length pair for this compilation unit. */
4758 size += 2 * DWARF2_ADDR_SIZE;
4759 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
4761 /* Count the two zero words used to terminated the address range table. */
4762 size += 2 * DWARF2_ADDR_SIZE;
4766 /* Select the encoding of an attribute value. */
4768 static enum dwarf_form
4772 switch (a->dw_attr_val.val_class)
4774 case dw_val_class_addr:
4775 return DW_FORM_addr;
4776 case dw_val_class_loc:
4777 switch (constant_size (size_of_locs (AT_loc (a))))
4780 return DW_FORM_block1;
4782 return DW_FORM_block2;
4786 case dw_val_class_const:
4787 return DW_FORM_data4;
4788 case dw_val_class_unsigned_const:
4789 switch (constant_size (AT_unsigned (a)))
4792 return DW_FORM_data1;
4794 return DW_FORM_data2;
4796 return DW_FORM_data4;
4798 return DW_FORM_data8;
4802 case dw_val_class_long_long:
4803 return DW_FORM_block1;
4804 case dw_val_class_float:
4805 return DW_FORM_block1;
4806 case dw_val_class_flag:
4807 return DW_FORM_flag;
4808 case dw_val_class_die_ref:
4810 case dw_val_class_fde_ref:
4811 return DW_FORM_data;
4812 case dw_val_class_lbl_id:
4813 return DW_FORM_addr;
4814 case dw_val_class_lbl_offset:
4815 return DW_FORM_data;
4816 case dw_val_class_str:
4817 return DW_FORM_string;
4823 /* Output the encoding of an attribute value. */
4826 output_value_format (a)
4829 enum dwarf_form form = value_format (a);
4831 output_uleb128 (form);
4833 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
4835 fputc ('\n', asm_out_file);
4838 /* Output the .debug_abbrev section which defines the DIE abbreviation
4842 output_abbrev_section ()
4844 unsigned long abbrev_id;
4847 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4849 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4851 output_uleb128 (abbrev_id);
4853 fprintf (asm_out_file, " (abbrev code)");
4855 fputc ('\n', asm_out_file);
4856 output_uleb128 (abbrev->die_tag);
4858 fprintf (asm_out_file, " (TAG: %s)",
4859 dwarf_tag_name (abbrev->die_tag));
4861 fputc ('\n', asm_out_file);
4862 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
4863 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
4866 fprintf (asm_out_file, "\t%s %s",
4868 (abbrev->die_child != NULL
4869 ? "DW_children_yes" : "DW_children_no"));
4871 fputc ('\n', asm_out_file);
4873 for (a_attr = abbrev->die_attr; a_attr != NULL;
4874 a_attr = a_attr->dw_attr_next)
4876 output_uleb128 (a_attr->dw_attr);
4878 fprintf (asm_out_file, " (%s)",
4879 dwarf_attr_name (a_attr->dw_attr));
4881 fputc ('\n', asm_out_file);
4882 output_value_format (a_attr);
4885 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
4888 /* Terminate the table. */
4889 fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP);
4892 /* Output location description stack opcode's operands (if any). */
4895 output_loc_operands (loc)
4896 register dw_loc_descr_ref loc;
4898 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
4899 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
4901 switch (loc->dw_loc_opc)
4904 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
4905 fputc ('\n', asm_out_file);
4909 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4910 fputc ('\n', asm_out_file);
4914 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4915 fputc ('\n', asm_out_file);
4919 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
4920 fputc ('\n', asm_out_file);
4925 fputc ('\n', asm_out_file);
4928 output_uleb128 (val1->v.val_unsigned);
4929 fputc ('\n', asm_out_file);
4932 output_sleb128 (val1->v.val_int);
4933 fputc ('\n', asm_out_file);
4936 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
4937 fputc ('\n', asm_out_file);
4939 case DW_OP_plus_uconst:
4940 output_uleb128 (val1->v.val_unsigned);
4941 fputc ('\n', asm_out_file);
4945 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4946 fputc ('\n', asm_out_file);
4980 output_sleb128 (val1->v.val_int);
4981 fputc ('\n', asm_out_file);
4984 output_uleb128 (val1->v.val_unsigned);
4985 fputc ('\n', asm_out_file);
4988 output_sleb128 (val1->v.val_int);
4989 fputc ('\n', asm_out_file);
4992 output_uleb128 (val1->v.val_unsigned);
4993 fputc ('\n', asm_out_file);
4994 output_sleb128 (val2->v.val_int);
4995 fputc ('\n', asm_out_file);
4998 output_uleb128 (val1->v.val_unsigned);
4999 fputc ('\n', asm_out_file);
5001 case DW_OP_deref_size:
5002 case DW_OP_xderef_size:
5003 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
5004 fputc ('\n', asm_out_file);
5011 /* Output the DIE and its attributes. Called recursively to generate
5012 the definitions of each child DIE. */
5016 register dw_die_ref die;
5018 register dw_attr_ref a;
5019 register dw_die_ref c;
5020 register unsigned long size;
5021 register dw_loc_descr_ref loc;
5023 output_uleb128 (die->die_abbrev);
5025 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5026 die->die_offset, dwarf_tag_name (die->die_tag));
5028 fputc ('\n', asm_out_file);
5030 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5032 switch (AT_class (a))
5034 case dw_val_class_addr:
5035 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
5038 case dw_val_class_loc:
5039 size = size_of_locs (AT_loc (a));
5041 /* Output the block length for this list of location operations. */
5042 switch (constant_size (size))
5045 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5048 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5055 fprintf (asm_out_file, "\t%s %s",
5056 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5058 fputc ('\n', asm_out_file);
5059 for (loc = AT_loc (a); loc != NULL; loc = loc->dw_loc_next)
5061 /* Output the opcode. */
5062 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
5064 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
5065 dwarf_stack_op_name (loc->dw_loc_opc));
5067 fputc ('\n', asm_out_file);
5069 /* Output the operand(s) (if any). */
5070 output_loc_operands (loc);
5074 case dw_val_class_const:
5075 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_int (a));
5078 case dw_val_class_unsigned_const:
5079 switch (constant_size (AT_unsigned (a)))
5082 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
5085 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
5088 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
5091 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5092 a->dw_attr_val.v.val_long_long.hi,
5093 a->dw_attr_val.v.val_long_long.low);
5100 case dw_val_class_long_long:
5101 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5103 fprintf (asm_out_file, "\t%s %s",
5104 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5106 fputc ('\n', asm_out_file);
5107 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5108 a->dw_attr_val.v.val_long_long.hi,
5109 a->dw_attr_val.v.val_long_long.low);
5112 fprintf (asm_out_file,
5113 "\t%s long long constant", ASM_COMMENT_START);
5115 fputc ('\n', asm_out_file);
5118 case dw_val_class_float:
5120 register unsigned int i;
5121 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5122 a->dw_attr_val.v.val_float.length * 4);
5124 fprintf (asm_out_file, "\t%s %s",
5125 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5127 fputc ('\n', asm_out_file);
5128 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5130 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5131 a->dw_attr_val.v.val_float.array[i]);
5133 fprintf (asm_out_file, "\t%s fp constant word %u",
5134 ASM_COMMENT_START, i);
5136 fputc ('\n', asm_out_file);
5141 case dw_val_class_flag:
5142 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
5145 case dw_val_class_die_ref:
5146 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
5149 case dw_val_class_fde_ref:
5152 ASM_GENERATE_INTERNAL_LABEL
5153 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5154 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5155 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5159 case dw_val_class_lbl_id:
5160 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
5163 case dw_val_class_lbl_offset:
5164 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
5167 case dw_val_class_str:
5169 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
5171 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
5172 (int) strlen (AT_string (a)) + 1);
5179 if (AT_class (a) != dw_val_class_loc
5180 && AT_class (a) != dw_val_class_long_long
5181 && AT_class (a) != dw_val_class_float)
5184 fprintf (asm_out_file, "\t%s %s",
5185 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5187 fputc ('\n', asm_out_file);
5191 for (c = die->die_child; c != NULL; c = c->die_sib)
5194 if (die->die_child != NULL)
5196 /* Add null byte to terminate sibling list. */
5197 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5199 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
5200 ASM_COMMENT_START, die->die_offset);
5202 fputc ('\n', asm_out_file);
5206 /* Output the compilation unit that appears at the beginning of the
5207 .debug_info section, and precedes the DIE descriptions. */
5210 output_compilation_unit_header ()
5212 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
5214 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
5217 fputc ('\n', asm_out_file);
5218 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5220 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
5222 fputc ('\n', asm_out_file);
5223 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
5225 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
5228 fputc ('\n', asm_out_file);
5229 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
5231 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
5233 fputc ('\n', asm_out_file);
5236 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5237 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5238 argument list, and maybe the scope. */
5241 dwarf2_name (decl, scope)
5245 return (*decl_printable_name) (decl, scope ? 1 : 0);
5248 /* Add a new entry to .debug_pubnames if appropriate. */
5251 add_pubname (decl, die)
5257 if (! TREE_PUBLIC (decl))
5260 if (pubname_table_in_use == pubname_table_allocated)
5262 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5263 pubname_table = (pubname_ref) xrealloc
5264 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5267 p = &pubname_table[pubname_table_in_use++];
5270 p->name = xstrdup (dwarf2_name (decl, 1));
5273 /* Output the public names table used to speed up access to externally
5274 visible names. For now, only generate entries for externally
5275 visible procedures. */
5280 register unsigned i;
5281 register unsigned long pubnames_length = size_of_pubnames ();
5283 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
5286 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
5289 fputc ('\n', asm_out_file);
5290 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5293 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5295 fputc ('\n', asm_out_file);
5296 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5298 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5301 fputc ('\n', asm_out_file);
5302 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
5304 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
5306 fputc ('\n', asm_out_file);
5307 for (i = 0; i < pubname_table_in_use; ++i)
5309 register pubname_ref pub = &pubname_table[i];
5311 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
5313 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
5315 fputc ('\n', asm_out_file);
5319 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
5320 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
5324 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
5325 (int) strlen (pub->name) + 1);
5328 fputc ('\n', asm_out_file);
5331 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
5332 fputc ('\n', asm_out_file);
5335 /* Add a new entry to .debug_aranges if appropriate. */
5338 add_arange (decl, die)
5342 if (! DECL_SECTION_NAME (decl))
5345 if (arange_table_in_use == arange_table_allocated)
5347 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5349 = (arange_ref) xrealloc (arange_table,
5350 arange_table_allocated * sizeof (dw_die_ref));
5353 arange_table[arange_table_in_use++] = die;
5356 /* Output the information that goes into the .debug_aranges table.
5357 Namely, define the beginning and ending address range of the
5358 text section generated for this compilation unit. */
5363 register unsigned i;
5364 register unsigned long aranges_length = size_of_aranges ();
5366 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
5368 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
5371 fputc ('\n', asm_out_file);
5372 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5374 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5376 fputc ('\n', asm_out_file);
5377 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5379 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5382 fputc ('\n', asm_out_file);
5383 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
5385 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
5387 fputc ('\n', asm_out_file);
5388 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5390 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
5393 fputc ('\n', asm_out_file);
5395 /* We need to align to twice the pointer size here. */
5396 if (DWARF_ARANGES_PAD_SIZE)
5398 /* Pad using a 2 bytes word so that padding is correct
5399 for any pointer size. */
5400 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
5401 for (i = 2; i < DWARF_ARANGES_PAD_SIZE; i += 2)
5402 fprintf (asm_out_file, ",0");
5404 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5405 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
5408 fputc ('\n', asm_out_file);
5409 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
5411 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5413 fputc ('\n', asm_out_file);
5414 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
5415 text_section_label);
5417 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5419 fputc ('\n', asm_out_file);
5420 for (i = 0; i < arange_table_in_use; ++i)
5422 dw_die_ref die = arange_table[i];
5424 if (die->die_tag == DW_TAG_subprogram)
5425 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
5428 /* A static variable; extract the symbol from DW_AT_location.
5429 Note that this code isn't currently hit, as we only emit
5430 aranges for functions (jason 9/23/99). */
5432 dw_attr_ref a = get_AT (die, DW_AT_location);
5433 dw_loc_descr_ref loc;
5434 if (! a || AT_class (a) != dw_val_class_loc)
5438 if (loc->dw_loc_opc != DW_OP_addr)
5441 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
5442 loc->dw_loc_oprnd1.v.val_addr);
5446 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5448 fputc ('\n', asm_out_file);
5449 if (die->die_tag == DW_TAG_subprogram)
5450 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
5451 get_AT_low_pc (die));
5453 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5454 get_AT_unsigned (die, DW_AT_byte_size));
5457 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5459 fputc ('\n', asm_out_file);
5462 /* Output the terminator words. */
5463 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5464 fputc ('\n', asm_out_file);
5465 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5466 fputc ('\n', asm_out_file);
5469 /* Output the source line number correspondence information. This
5470 information goes into the .debug_line section. */
5475 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5476 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5477 register unsigned opc;
5478 register unsigned n_op_args;
5479 register unsigned long ft_index;
5480 register unsigned long lt_index;
5481 register unsigned long current_line;
5482 register long line_offset;
5483 register long line_delta;
5484 register unsigned long current_file;
5485 register unsigned long function;
5487 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
5489 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5492 fputc ('\n', asm_out_file);
5493 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
5494 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5496 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5498 fputc ('\n', asm_out_file);
5499 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
5501 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5503 fputc ('\n', asm_out_file);
5504 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
5506 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5509 fputc ('\n', asm_out_file);
5510 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
5512 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5515 fputc ('\n', asm_out_file);
5516 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
5518 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5521 fputc ('\n', asm_out_file);
5522 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
5524 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5527 fputc ('\n', asm_out_file);
5528 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5530 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5532 fputc ('\n', asm_out_file);
5533 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5537 case DW_LNS_advance_pc:
5538 case DW_LNS_advance_line:
5539 case DW_LNS_set_file:
5540 case DW_LNS_set_column:
5541 case DW_LNS_fixed_advance_pc:
5548 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5550 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5551 ASM_COMMENT_START, opc, n_op_args);
5552 fputc ('\n', asm_out_file);
5556 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5558 /* Include directory table is empty, at present */
5559 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5560 fputc ('\n', asm_out_file);
5562 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5564 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5568 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5569 fprintf (asm_out_file, "%s File Entry: 0x%lx",
5570 ASM_COMMENT_START, ft_index);
5574 ASM_OUTPUT_ASCII (asm_out_file,
5575 file_table[ft_index],
5576 (int) strlen (file_table[ft_index]) + 1);
5579 fputc ('\n', asm_out_file);
5581 /* Include directory index */
5583 fputc ('\n', asm_out_file);
5585 /* Modification time */
5587 fputc ('\n', asm_out_file);
5589 /* File length in bytes */
5591 fputc ('\n', asm_out_file);
5594 /* Terminate the file name table */
5595 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5596 fputc ('\n', asm_out_file);
5598 /* We used to set the address register to the first location in the text
5599 section here, but that didn't accomplish anything since we already
5600 have a line note for the opening brace of the first function. */
5602 /* Generate the line number to PC correspondence table, encoded as
5603 a series of state machine operations. */
5606 strcpy (prev_line_label, text_section_label);
5607 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5609 register dw_line_info_ref line_info = &line_info_table[lt_index];
5612 /* Disable this optimization for now; GDB wants to see two line notes
5613 at the beginning of a function so it can find the end of the
5616 /* Don't emit anything for redundant notes. Just updating the
5617 address doesn't accomplish anything, because we already assume
5618 that anything after the last address is this line. */
5619 if (line_info->dw_line_num == current_line
5620 && line_info->dw_file_num == current_file)
5624 /* Emit debug info for the address of the current line, choosing
5625 the encoding that uses the least amount of space. */
5626 /* ??? Unfortunately, we have little choice here currently, and must
5627 always use the most general form. Gcc does not know the address
5628 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5629 dwarf2 aware assemblers at this time, so we can't use any special
5630 pseudo ops that would allow the assembler to optimally encode this for
5631 us. Many ports do have length attributes which will give an upper
5632 bound on the address range. We could perhaps use length attributes
5633 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5634 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5637 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5638 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5640 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5643 fputc ('\n', asm_out_file);
5644 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5645 fputc ('\n', asm_out_file);
5649 /* This can handle any delta. This takes
5650 4+DWARF2_ADDR_SIZE bytes. */
5651 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5653 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5655 fputc ('\n', asm_out_file);
5656 output_uleb128 (1 + DWARF2_ADDR_SIZE);
5657 fputc ('\n', asm_out_file);
5658 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5659 fputc ('\n', asm_out_file);
5660 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5661 fputc ('\n', asm_out_file);
5663 strcpy (prev_line_label, line_label);
5665 /* Emit debug info for the source file of the current line, if
5666 different from the previous line. */
5667 if (line_info->dw_file_num != current_file)
5669 current_file = line_info->dw_file_num;
5670 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5672 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5674 fputc ('\n', asm_out_file);
5675 output_uleb128 (current_file);
5677 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5679 fputc ('\n', asm_out_file);
5682 /* Emit debug info for the current line number, choosing the encoding
5683 that uses the least amount of space. */
5684 if (line_info->dw_line_num != current_line)
5686 line_offset = line_info->dw_line_num - current_line;
5687 line_delta = line_offset - DWARF_LINE_BASE;
5688 current_line = line_info->dw_line_num;
5689 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5691 /* This can handle deltas from -10 to 234, using the current
5692 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5694 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5695 DWARF_LINE_OPCODE_BASE + line_delta);
5697 fprintf (asm_out_file,
5698 "\t%s line %ld", ASM_COMMENT_START, current_line);
5700 fputc ('\n', asm_out_file);
5704 /* This can handle any delta. This takes at least 4 bytes,
5705 depending on the value being encoded. */
5706 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5708 fprintf (asm_out_file, "\t%s advance to line %ld",
5709 ASM_COMMENT_START, current_line);
5711 fputc ('\n', asm_out_file);
5712 output_sleb128 (line_offset);
5713 fputc ('\n', asm_out_file);
5714 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5716 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5717 fputc ('\n', asm_out_file);
5722 /* We still need to start a new row, so output a copy insn. */
5723 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5725 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5726 fputc ('\n', asm_out_file);
5730 /* Emit debug info for the address of the end of the function. */
5733 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5735 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5738 fputc ('\n', asm_out_file);
5739 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
5740 fputc ('\n', asm_out_file);
5744 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5746 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5747 fputc ('\n', asm_out_file);
5748 output_uleb128 (1 + DWARF2_ADDR_SIZE);
5749 fputc ('\n', asm_out_file);
5750 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5751 fputc ('\n', asm_out_file);
5752 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
5753 fputc ('\n', asm_out_file);
5756 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5758 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
5760 fputc ('\n', asm_out_file);
5762 fputc ('\n', asm_out_file);
5763 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5764 fputc ('\n', asm_out_file);
5769 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5771 register dw_separate_line_info_ref line_info
5772 = &separate_line_info_table[lt_index];
5775 /* Don't emit anything for redundant notes. */
5776 if (line_info->dw_line_num == current_line
5777 && line_info->dw_file_num == current_file
5778 && line_info->function == function)
5782 /* Emit debug info for the address of the current line. If this is
5783 a new function, or the first line of a function, then we need
5784 to handle it differently. */
5785 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
5787 if (function != line_info->function)
5789 function = line_info->function;
5791 /* Set the address register to the first line in the function */
5792 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5794 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5797 fputc ('\n', asm_out_file);
5798 output_uleb128 (1 + DWARF2_ADDR_SIZE);
5799 fputc ('\n', asm_out_file);
5800 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5801 fputc ('\n', asm_out_file);
5802 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5803 fputc ('\n', asm_out_file);
5807 /* ??? See the DW_LNS_advance_pc comment above. */
5810 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5812 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5815 fputc ('\n', asm_out_file);
5816 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5818 fputc ('\n', asm_out_file);
5822 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5824 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5826 fputc ('\n', asm_out_file);
5827 output_uleb128 (1 + DWARF2_ADDR_SIZE);
5828 fputc ('\n', asm_out_file);
5829 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5830 fputc ('\n', asm_out_file);
5831 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5832 fputc ('\n', asm_out_file);
5835 strcpy (prev_line_label, line_label);
5837 /* Emit debug info for the source file of the current line, if
5838 different from the previous line. */
5839 if (line_info->dw_file_num != current_file)
5841 current_file = line_info->dw_file_num;
5842 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5844 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5846 fputc ('\n', asm_out_file);
5847 output_uleb128 (current_file);
5849 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5851 fputc ('\n', asm_out_file);
5854 /* Emit debug info for the current line number, choosing the encoding
5855 that uses the least amount of space. */
5856 if (line_info->dw_line_num != current_line)
5858 line_offset = line_info->dw_line_num - current_line;
5859 line_delta = line_offset - DWARF_LINE_BASE;
5860 current_line = line_info->dw_line_num;
5861 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5863 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5864 DWARF_LINE_OPCODE_BASE + line_delta);
5866 fprintf (asm_out_file,
5867 "\t%s line %ld", ASM_COMMENT_START, current_line);
5869 fputc ('\n', asm_out_file);
5873 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5875 fprintf (asm_out_file, "\t%s advance to line %ld",
5876 ASM_COMMENT_START, current_line);
5878 fputc ('\n', asm_out_file);
5879 output_sleb128 (line_offset);
5880 fputc ('\n', asm_out_file);
5881 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5883 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5884 fputc ('\n', asm_out_file);
5889 /* We still need to start a new row, so output a copy insn. */
5890 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5892 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5893 fputc ('\n', asm_out_file);
5901 /* If we're done with a function, end its sequence. */
5902 if (lt_index == separate_line_info_table_in_use
5903 || separate_line_info_table[lt_index].function != function)
5908 /* Emit debug info for the address of the end of the function. */
5909 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
5912 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5914 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5917 fputc ('\n', asm_out_file);
5918 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5920 fputc ('\n', asm_out_file);
5924 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5926 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5928 fputc ('\n', asm_out_file);
5929 output_uleb128 (1 + DWARF2_ADDR_SIZE);
5930 fputc ('\n', asm_out_file);
5931 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5932 fputc ('\n', asm_out_file);
5933 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5934 fputc ('\n', asm_out_file);
5937 /* Output the marker for the end of this sequence. */
5938 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5940 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
5943 fputc ('\n', asm_out_file);
5945 fputc ('\n', asm_out_file);
5946 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5947 fputc ('\n', asm_out_file);
5951 /* Output the marker for the end of the line number info. */
5952 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
5955 /* Given a pointer to a tree node for some base type, return a pointer to
5956 a DIE that describes the given type.
5958 This routine must only be called for GCC type nodes that correspond to
5959 Dwarf base (fundamental) types. */
5962 base_type_die (type)
5965 register dw_die_ref base_type_result;
5966 register const char *type_name;
5967 register enum dwarf_type encoding;
5968 register tree name = TYPE_NAME (type);
5970 if (TREE_CODE (type) == ERROR_MARK
5971 || TREE_CODE (type) == VOID_TYPE)
5976 if (TREE_CODE (name) == TYPE_DECL)
5977 name = DECL_NAME (name);
5979 type_name = IDENTIFIER_POINTER (name);
5982 type_name = "__unknown__";
5984 switch (TREE_CODE (type))
5987 /* Carefully distinguish the C character types, without messing
5988 up if the language is not C. Note that we check only for the names
5989 that contain spaces; other names might occur by coincidence in other
5991 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
5992 && (type == char_type_node
5993 || ! strcmp (type_name, "signed char")
5994 || ! strcmp (type_name, "unsigned char"))))
5996 if (TREE_UNSIGNED (type))
5997 encoding = DW_ATE_unsigned;
5999 encoding = DW_ATE_signed;
6002 /* else fall through */
6005 /* GNU Pascal/Ada CHAR type. Not used in C. */
6006 if (TREE_UNSIGNED (type))
6007 encoding = DW_ATE_unsigned_char;
6009 encoding = DW_ATE_signed_char;
6013 encoding = DW_ATE_float;
6016 /* Dwarf2 doesn't know anything about complex ints, so use
6017 a user defined type for it. */
6019 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6020 encoding = DW_ATE_complex_float;
6022 encoding = DW_ATE_lo_user;
6026 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6027 encoding = DW_ATE_boolean;
6031 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6034 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6035 if (demangle_name_func)
6036 type_name = (*demangle_name_func) (type_name);
6038 add_AT_string (base_type_result, DW_AT_name, type_name);
6039 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6040 int_size_in_bytes (type));
6041 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6043 return base_type_result;
6046 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6047 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6048 a given type is generally the same as the given type, except that if the
6049 given type is a pointer or reference type, then the root type of the given
6050 type is the root type of the "basis" type for the pointer or reference
6051 type. (This definition of the "root" type is recursive.) Also, the root
6052 type of a `const' qualified type or a `volatile' qualified type is the
6053 root type of the given type without the qualifiers. */
6059 if (TREE_CODE (type) == ERROR_MARK)
6060 return error_mark_node;
6062 switch (TREE_CODE (type))
6065 return error_mark_node;
6068 case REFERENCE_TYPE:
6069 return type_main_variant (root_type (TREE_TYPE (type)));
6072 return type_main_variant (type);
6076 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6077 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6083 switch (TREE_CODE (type))
6098 case QUAL_UNION_TYPE:
6103 case REFERENCE_TYPE:
6116 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6117 entry that chains various modifiers in front of the given type. */
6120 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6122 register int is_const_type;
6123 register int is_volatile_type;
6124 register dw_die_ref context_die;
6126 register enum tree_code code = TREE_CODE (type);
6127 register dw_die_ref mod_type_die = NULL;
6128 register dw_die_ref sub_die = NULL;
6129 register tree item_type = NULL;
6131 if (code != ERROR_MARK)
6133 type = build_type_variant (type, is_const_type, is_volatile_type);
6135 mod_type_die = lookup_type_die (type);
6137 return mod_type_die;
6139 /* Handle C typedef types. */
6140 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6141 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6143 tree dtype = TREE_TYPE (TYPE_NAME (type));
6146 /* For a named type, use the typedef. */
6147 gen_type_die (type, context_die);
6148 mod_type_die = lookup_type_die (type);
6151 else if (is_const_type < TYPE_READONLY (dtype)
6152 || is_volatile_type < TYPE_VOLATILE (dtype))
6153 /* cv-unqualified version of named type. Just use the unnamed
6154 type to which it refers. */
6156 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6157 is_const_type, is_volatile_type,
6159 /* Else cv-qualified version of named type; fall through. */
6164 else if (is_const_type)
6166 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6167 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6169 else if (is_volatile_type)
6171 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6172 sub_die = modified_type_die (type, 0, 0, context_die);
6174 else if (code == POINTER_TYPE)
6176 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6177 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6179 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6181 item_type = TREE_TYPE (type);
6183 else if (code == REFERENCE_TYPE)
6185 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6186 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6188 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6190 item_type = TREE_TYPE (type);
6192 else if (is_base_type (type))
6193 mod_type_die = base_type_die (type);
6196 gen_type_die (type, context_die);
6198 /* We have to get the type_main_variant here (and pass that to the
6199 `lookup_type_die' routine) because the ..._TYPE node we have
6200 might simply be a *copy* of some original type node (where the
6201 copy was created to help us keep track of typedef names) and
6202 that copy might have a different TYPE_UID from the original
6204 mod_type_die = lookup_type_die (type_main_variant (type));
6205 if (mod_type_die == NULL)
6210 equate_type_number_to_die (type, mod_type_die);
6212 /* We must do this after the equate_type_number_to_die call, in case
6213 this is a recursive type. This ensures that the modified_type_die
6214 recursion will terminate even if the type is recursive. Recursive
6215 types are possible in Ada. */
6216 sub_die = modified_type_die (item_type,
6217 TYPE_READONLY (item_type),
6218 TYPE_VOLATILE (item_type),
6221 if (sub_die != NULL)
6222 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6224 return mod_type_die;
6227 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6228 an enumerated type. */
6234 return TREE_CODE (type) == ENUMERAL_TYPE;
6237 /* Return a location descriptor that designates a machine register. */
6239 static dw_loc_descr_ref
6240 reg_loc_descriptor (rtl)
6243 register dw_loc_descr_ref loc_result = NULL;
6244 register unsigned reg = reg_number (rtl);
6247 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6249 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6254 /* Return a location descriptor that designates a base+offset location. */
6256 static dw_loc_descr_ref
6257 based_loc_descr (reg, offset)
6261 register dw_loc_descr_ref loc_result;
6262 /* For the "frame base", we use the frame pointer or stack pointer
6263 registers, since the RTL for local variables is relative to one of
6265 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6266 ? HARD_FRAME_POINTER_REGNUM
6267 : STACK_POINTER_REGNUM);
6270 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
6272 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
6274 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
6279 /* Return true if this RTL expression describes a base+offset calculation. */
6285 return (GET_CODE (rtl) == PLUS
6286 && ((GET_CODE (XEXP (rtl, 0)) == REG
6287 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
6290 /* The following routine converts the RTL for a variable or parameter
6291 (resident in memory) into an equivalent Dwarf representation of a
6292 mechanism for getting the address of that same variable onto the top of a
6293 hypothetical "address evaluation" stack.
6295 When creating memory location descriptors, we are effectively transforming
6296 the RTL for a memory-resident object into its Dwarf postfix expression
6297 equivalent. This routine recursively descends an RTL tree, turning
6298 it into Dwarf postfix code as it goes.
6300 MODE is the mode of the memory reference, needed to handle some
6301 autoincrement addressing modes. */
6303 static dw_loc_descr_ref
6304 mem_loc_descriptor (rtl, mode)
6306 enum machine_mode mode;
6308 dw_loc_descr_ref mem_loc_result = NULL;
6309 /* Note that for a dynamically sized array, the location we will generate a
6310 description of here will be the lowest numbered location which is
6311 actually within the array. That's *not* necessarily the same as the
6312 zeroth element of the array. */
6314 #ifdef ASM_SIMPLIFY_DWARF_ADDR
6315 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
6318 switch (GET_CODE (rtl))
6322 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
6323 just fall into the SUBREG code. */
6325 /* ... fall through ... */
6328 /* The case of a subreg may arise when we have a local (register)
6329 variable or a formal (register) parameter which doesn't quite fill
6330 up an entire register. For now, just assume that it is
6331 legitimate to make the Dwarf info refer to the whole register which
6332 contains the given subreg. */
6333 rtl = XEXP (rtl, 0);
6335 /* ... fall through ... */
6338 /* Whenever a register number forms a part of the description of the
6339 method for calculating the (dynamic) address of a memory resident
6340 object, DWARF rules require the register number be referred to as
6341 a "base register". This distinction is not based in any way upon
6342 what category of register the hardware believes the given register
6343 belongs to. This is strictly DWARF terminology we're dealing with
6344 here. Note that in cases where the location of a memory-resident
6345 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6346 OP_CONST (0)) the actual DWARF location descriptor that we generate
6347 may just be OP_BASEREG (basereg). This may look deceptively like
6348 the object in question was allocated to a register (rather than in
6349 memory) so DWARF consumers need to be aware of the subtle
6350 distinction between OP_REG and OP_BASEREG. */
6351 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
6355 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
6356 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6360 /* Some ports can transform a symbol ref into a label ref, because
6361 the symbol ref is too far away and has to be dumped into a constant
6365 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6366 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6367 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
6372 /* Turn these into a PLUS expression and fall into the PLUS code
6374 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
6375 GEN_INT (GET_CODE (rtl) == PRE_INC
6376 ? GET_MODE_UNIT_SIZE (mode)
6377 : - GET_MODE_UNIT_SIZE (mode)));
6379 /* ... fall through ... */
6382 if (is_based_loc (rtl))
6383 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
6384 INTVAL (XEXP (rtl, 1)));
6387 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0),
6389 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1),
6391 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
6396 /* If a pseudo-reg is optimized away, it is possible for it to
6397 be replaced with a MEM containing a multiply. */
6398 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode));
6399 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode));
6400 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
6404 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6411 return mem_loc_result;
6414 /* Return a descriptor that describes the concatenation of two locations.
6415 This is typically a complex variable. */
6417 static dw_loc_descr_ref
6418 concat_loc_descriptor (x0, x1)
6419 register rtx x0, x1;
6421 dw_loc_descr_ref cc_loc_result = NULL;
6423 if (!is_pseudo_reg (x0)
6424 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
6425 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
6426 add_loc_descr (&cc_loc_result,
6427 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
6429 if (!is_pseudo_reg (x1)
6430 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
6431 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
6432 add_loc_descr (&cc_loc_result,
6433 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
6435 return cc_loc_result;
6438 /* Output a proper Dwarf location descriptor for a variable or parameter
6439 which is either allocated in a register or in a memory location. For a
6440 register, we just generate an OP_REG and the register number. For a
6441 memory location we provide a Dwarf postfix expression describing how to
6442 generate the (dynamic) address of the object onto the address stack. */
6444 static dw_loc_descr_ref
6445 loc_descriptor (rtl)
6448 dw_loc_descr_ref loc_result = NULL;
6449 switch (GET_CODE (rtl))
6452 /* The case of a subreg may arise when we have a local (register)
6453 variable or a formal (register) parameter which doesn't quite fill
6454 up an entire register. For now, just assume that it is
6455 legitimate to make the Dwarf info refer to the whole register which
6456 contains the given subreg. */
6457 rtl = XEXP (rtl, 0);
6459 /* ... fall through ... */
6462 loc_result = reg_loc_descriptor (rtl);
6466 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
6470 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
6480 /* Given a value, round it up to the lowest multiple of `boundary'
6481 which is not less than the value itself. */
6483 static inline HOST_WIDE_INT
6484 ceiling (value, boundary)
6485 HOST_WIDE_INT value;
6486 unsigned int boundary;
6488 return (((value + boundary - 1) / boundary) * boundary);
6491 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6492 pointer to the declared type for the relevant field variable, or return
6493 `integer_type_node' if the given node turns out to be an
6502 if (TREE_CODE (decl) == ERROR_MARK)
6503 return integer_type_node;
6505 type = DECL_BIT_FIELD_TYPE (decl);
6506 if (type == NULL_TREE)
6507 type = TREE_TYPE (decl);
6512 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6513 node, return the alignment in bits for the type, or else return
6514 BITS_PER_WORD if the node actually turns out to be an
6517 static inline unsigned
6518 simple_type_align_in_bits (type)
6521 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6524 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6525 node, return the size in bits for the type if it is a constant, or else
6526 return the alignment for the type if the type's size is not constant, or
6527 else return BITS_PER_WORD if the type actually turns out to be an
6530 static inline unsigned HOST_WIDE_INT
6531 simple_type_size_in_bits (type)
6534 if (TREE_CODE (type) == ERROR_MARK)
6535 return BITS_PER_WORD;
6538 register tree type_size_tree = TYPE_SIZE (type);
6540 if (! host_integerp (type_size_tree, 1))
6541 return TYPE_ALIGN (type);
6543 return tree_low_cst (type_size_tree, 1);
6547 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6548 return the byte offset of the lowest addressed byte of the "containing
6549 object" for the given FIELD_DECL, or return 0 if we are unable to
6550 determine what that offset is, either because the argument turns out to
6551 be a pointer to an ERROR_MARK node, or because the offset is actually
6552 variable. (We can't handle the latter case just yet). */
6554 static HOST_WIDE_INT
6555 field_byte_offset (decl)
6558 unsigned int type_align_in_bytes;
6559 unsigned int type_align_in_bits;
6560 unsigned HOST_WIDE_INT type_size_in_bits;
6561 HOST_WIDE_INT object_offset_in_align_units;
6562 HOST_WIDE_INT object_offset_in_bits;
6563 HOST_WIDE_INT object_offset_in_bytes;
6565 tree field_size_tree;
6566 HOST_WIDE_INT bitpos_int;
6567 HOST_WIDE_INT deepest_bitpos;
6568 unsigned HOST_WIDE_INT field_size_in_bits;
6570 if (TREE_CODE (decl) == ERROR_MARK)
6573 if (TREE_CODE (decl) != FIELD_DECL)
6576 type = field_type (decl);
6577 field_size_tree = DECL_SIZE (decl);
6579 /* If there was an error, the size could be zero. */
6580 if (! field_size_tree)
6588 /* We cannot yet cope with fields whose positions are variable, so
6589 for now, when we see such things, we simply return 0. Someday, we may
6590 be able to handle such cases, but it will be damn difficult. */
6591 if (! host_integerp (bit_position (decl), 0))
6594 bitpos_int = int_bit_position (decl);
6596 /* If we don't know the size of the field, pretend it's a full word. */
6597 if (host_integerp (field_size_tree, 1))
6598 field_size_in_bits = tree_low_cst (field_size_tree, 1);
6600 field_size_in_bits = BITS_PER_WORD;
6602 type_size_in_bits = simple_type_size_in_bits (type);
6603 type_align_in_bits = simple_type_align_in_bits (type);
6604 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6606 /* Note that the GCC front-end doesn't make any attempt to keep track of
6607 the starting bit offset (relative to the start of the containing
6608 structure type) of the hypothetical "containing object" for a bit-
6609 field. Thus, when computing the byte offset value for the start of the
6610 "containing object" of a bit-field, we must deduce this information on
6611 our own. This can be rather tricky to do in some cases. For example,
6612 handling the following structure type definition when compiling for an
6613 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6616 struct S { int field1; long long field2:31; };
6618 Fortunately, there is a simple rule-of-thumb which can be
6619 used in such cases. When compiling for an i386/i486, GCC will allocate
6620 8 bytes for the structure shown above. It decides to do this based upon
6621 one simple rule for bit-field allocation. Quite simply, GCC allocates
6622 each "containing object" for each bit-field at the first (i.e. lowest
6623 addressed) legitimate alignment boundary (based upon the required
6624 minimum alignment for the declared type of the field) which it can
6625 possibly use, subject to the condition that there is still enough
6626 available space remaining in the containing object (when allocated at
6627 the selected point) to fully accommodate all of the bits of the
6628 bit-field itself. This simple rule makes it obvious why GCC allocates
6629 8 bytes for each object of the structure type shown above. When looking
6630 for a place to allocate the "containing object" for `field2', the
6631 compiler simply tries to allocate a 64-bit "containing object" at each
6632 successive 32-bit boundary (starting at zero) until it finds a place to
6633 allocate that 64- bit field such that at least 31 contiguous (and
6634 previously unallocated) bits remain within that selected 64 bit field.
6635 (As it turns out, for the example above, the compiler finds that it is
6636 OK to allocate the "containing object" 64-bit field at bit-offset zero
6637 within the structure type.) Here we attempt to work backwards from the
6638 limited set of facts we're given, and we try to deduce from those facts,
6639 where GCC must have believed that the containing object started (within
6640 the structure type). The value we deduce is then used (by the callers of
6641 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6642 for fields (both bit-fields and, in the case of DW_AT_location, regular
6645 /* Figure out the bit-distance from the start of the structure to the
6646 "deepest" bit of the bit-field. */
6647 deepest_bitpos = bitpos_int + field_size_in_bits;
6649 /* This is the tricky part. Use some fancy footwork to deduce where the
6650 lowest addressed bit of the containing object must be. */
6651 object_offset_in_bits
6652 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6654 /* Compute the offset of the containing object in "alignment units". */
6655 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6657 /* Compute the offset of the containing object in bytes. */
6658 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6660 return object_offset_in_bytes;
6663 /* The following routines define various Dwarf attributes and any data
6664 associated with them. */
6666 /* Add a location description attribute value to a DIE.
6668 This emits location attributes suitable for whole variables and
6669 whole parameters. Note that the location attributes for struct fields are
6670 generated by the routine `data_member_location_attribute' below. */
6673 add_AT_location_description (die, attr_kind, rtl)
6675 enum dwarf_attribute attr_kind;
6678 /* Handle a special case. If we are about to output a location descriptor
6679 for a variable or parameter which has been optimized out of existence,
6680 don't do that. A variable which has been optimized out
6681 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6682 Currently, in some rare cases, variables can have DECL_RTL values which
6683 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6684 elsewhere in the compiler. We treat such cases as if the variable(s) in
6685 question had been optimized out of existence. */
6687 if (is_pseudo_reg (rtl)
6688 || (GET_CODE (rtl) == MEM
6689 && is_pseudo_reg (XEXP (rtl, 0)))
6690 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
6691 references the internal argument pointer (a pseudo) in a function
6692 where all references to the internal argument pointer were
6693 eliminated via the optimizers. */
6694 || (GET_CODE (rtl) == MEM
6695 && GET_CODE (XEXP (rtl, 0)) == PLUS
6696 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
6697 || (GET_CODE (rtl) == CONCAT
6698 && is_pseudo_reg (XEXP (rtl, 0))
6699 && is_pseudo_reg (XEXP (rtl, 1))))
6702 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
6705 /* Attach the specialized form of location attribute used for data
6706 members of struct and union types. In the special case of a
6707 FIELD_DECL node which represents a bit-field, the "offset" part
6708 of this special location descriptor must indicate the distance
6709 in bytes from the lowest-addressed byte of the containing struct
6710 or union type to the lowest-addressed byte of the "containing
6711 object" for the bit-field. (See the `field_byte_offset' function
6712 above).. For any given bit-field, the "containing object" is a
6713 hypothetical object (of some integral or enum type) within which
6714 the given bit-field lives. The type of this hypothetical
6715 "containing object" is always the same as the declared type of
6716 the individual bit-field itself (for GCC anyway... the DWARF
6717 spec doesn't actually mandate this). Note that it is the size
6718 (in bytes) of the hypothetical "containing object" which will
6719 be given in the DW_AT_byte_size attribute for this bit-field.
6720 (See the `byte_size_attribute' function below.) It is also used
6721 when calculating the value of the DW_AT_bit_offset attribute.
6722 (See the `bit_offset_attribute' function below). */
6725 add_data_member_location_attribute (die, decl)
6726 register dw_die_ref die;
6729 register unsigned long offset;
6730 register dw_loc_descr_ref loc_descr;
6731 register enum dwarf_location_atom op;
6733 if (TREE_CODE (decl) == TREE_VEC)
6734 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
6736 offset = field_byte_offset (decl);
6738 /* The DWARF2 standard says that we should assume that the structure address
6739 is already on the stack, so we can specify a structure field address
6740 by using DW_OP_plus_uconst. */
6742 #ifdef MIPS_DEBUGGING_INFO
6743 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6744 correctly. It works only if we leave the offset on the stack. */
6747 op = DW_OP_plus_uconst;
6750 loc_descr = new_loc_descr (op, offset, 0);
6751 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6754 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6755 does not have a "location" either in memory or in a register. These
6756 things can arise in GNU C when a constant is passed as an actual parameter
6757 to an inlined function. They can also arise in C++ where declared
6758 constants do not necessarily get memory "homes". */
6761 add_const_value_attribute (die, rtl)
6762 register dw_die_ref die;
6765 switch (GET_CODE (rtl))
6768 /* Note that a CONST_INT rtx could represent either an integer or a
6769 floating-point constant. A CONST_INT is used whenever the constant
6770 will fit into a single word. In all such cases, the original mode
6771 of the constant value is wiped out, and the CONST_INT rtx is
6772 assigned VOIDmode. */
6773 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6777 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6778 floating-point constant. A CONST_DOUBLE is used whenever the
6779 constant requires more than one word in order to be adequately
6780 represented. We output CONST_DOUBLEs as blocks. */
6782 register enum machine_mode mode = GET_MODE (rtl);
6784 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6786 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6790 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6794 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6798 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6803 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6810 add_AT_float (die, DW_AT_const_value, length, array);
6813 add_AT_long_long (die, DW_AT_const_value,
6814 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6819 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6825 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
6829 /* In cases where an inlined instance of an inline function is passed
6830 the address of an `auto' variable (which is local to the caller) we
6831 can get a situation where the DECL_RTL of the artificial local
6832 variable (for the inlining) which acts as a stand-in for the
6833 corresponding formal parameter (of the inline function) will look
6834 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6835 exactly a compile-time constant expression, but it isn't the address
6836 of the (artificial) local variable either. Rather, it represents the
6837 *value* which the artificial local variable always has during its
6838 lifetime. We currently have no way to represent such quasi-constant
6839 values in Dwarf, so for now we just punt and generate nothing. */
6843 /* No other kinds of rtx should be possible here. */
6849 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6850 data attribute for a variable or a parameter. We generate the
6851 DW_AT_const_value attribute only in those cases where the given variable
6852 or parameter does not have a true "location" either in memory or in a
6853 register. This can happen (for example) when a constant is passed as an
6854 actual argument in a call to an inline function. (It's possible that
6855 these things can crop up in other ways also.) Note that one type of
6856 constant value which can be passed into an inlined function is a constant
6857 pointer. This can happen for example if an actual argument in an inlined
6858 function call evaluates to a compile-time constant address. */
6861 add_location_or_const_value_attribute (die, decl)
6862 register dw_die_ref die;
6866 register tree declared_type;
6867 register tree passed_type;
6869 if (TREE_CODE (decl) == ERROR_MARK)
6872 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6875 /* Here we have to decide where we are going to say the parameter "lives"
6876 (as far as the debugger is concerned). We only have a couple of
6877 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6879 DECL_RTL normally indicates where the parameter lives during most of the
6880 activation of the function. If optimization is enabled however, this
6881 could be either NULL or else a pseudo-reg. Both of those cases indicate
6882 that the parameter doesn't really live anywhere (as far as the code
6883 generation parts of GCC are concerned) during most of the function's
6884 activation. That will happen (for example) if the parameter is never
6885 referenced within the function.
6887 We could just generate a location descriptor here for all non-NULL
6888 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6889 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6890 where DECL_RTL is NULL or is a pseudo-reg.
6892 Note however that we can only get away with using DECL_INCOMING_RTL as
6893 a backup substitute for DECL_RTL in certain limited cases. In cases
6894 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6895 we can be sure that the parameter was passed using the same type as it is
6896 declared to have within the function, and that its DECL_INCOMING_RTL
6897 points us to a place where a value of that type is passed.
6899 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6900 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6901 because in these cases DECL_INCOMING_RTL points us to a value of some
6902 type which is *different* from the type of the parameter itself. Thus,
6903 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6904 such cases, the debugger would end up (for example) trying to fetch a
6905 `float' from a place which actually contains the first part of a
6906 `double'. That would lead to really incorrect and confusing
6907 output at debug-time.
6909 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6910 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6911 are a couple of exceptions however. On little-endian machines we can
6912 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6913 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6914 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6915 when (on a little-endian machine) a non-prototyped function has a
6916 parameter declared to be of type `short' or `char'. In such cases,
6917 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6918 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6919 passed `int' value. If the debugger then uses that address to fetch
6920 a `short' or a `char' (on a little-endian machine) the result will be
6921 the correct data, so we allow for such exceptional cases below.
6923 Note that our goal here is to describe the place where the given formal
6924 parameter lives during most of the function's activation (i.e. between
6925 the end of the prologue and the start of the epilogue). We'll do that
6926 as best as we can. Note however that if the given formal parameter is
6927 modified sometime during the execution of the function, then a stack
6928 backtrace (at debug-time) will show the function as having been
6929 called with the *new* value rather than the value which was
6930 originally passed in. This happens rarely enough that it is not
6931 a major problem, but it *is* a problem, and I'd like to fix it.
6933 A future version of dwarf2out.c may generate two additional
6934 attributes for any given DW_TAG_formal_parameter DIE which will
6935 describe the "passed type" and the "passed location" for the
6936 given formal parameter in addition to the attributes we now
6937 generate to indicate the "declared type" and the "active
6938 location" for each parameter. This additional set of attributes
6939 could be used by debuggers for stack backtraces. Separately, note
6940 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6941 NULL also. This happens (for example) for inlined-instances of
6942 inline function formal parameters which are never referenced.
6943 This really shouldn't be happening. All PARM_DECL nodes should
6944 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6945 doesn't currently generate these values for inlined instances of
6946 inline function parameters, so when we see such cases, we are
6947 just out-of-luck for the time being (until integrate.c
6950 /* Use DECL_RTL as the "location" unless we find something better. */
6951 rtl = DECL_RTL (decl);
6953 if (TREE_CODE (decl) == PARM_DECL)
6955 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
6957 declared_type = type_main_variant (TREE_TYPE (decl));
6958 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
6960 /* This decl represents a formal parameter which was optimized out.
6961 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
6962 all* cases where (rtl == NULL_RTX) just below. */
6963 if (declared_type == passed_type)
6964 rtl = DECL_INCOMING_RTL (decl);
6965 else if (! BYTES_BIG_ENDIAN
6966 && TREE_CODE (declared_type) == INTEGER_TYPE
6967 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
6968 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
6969 rtl = DECL_INCOMING_RTL (decl);
6972 /* If the parm was passed in registers, but lives on the stack, then
6973 make a big endian correction if the mode of the type of the
6974 parameter is not the same as the mode of the rtl. */
6975 /* ??? This is the same series of checks that are made in dbxout.c before
6976 we reach the big endian correction code there. It isn't clear if all
6977 of these checks are necessary here, but keeping them all is the safe
6979 else if (GET_CODE (rtl) == MEM
6980 && XEXP (rtl, 0) != const0_rtx
6981 && ! CONSTANT_P (XEXP (rtl, 0))
6982 /* Not passed in memory. */
6983 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
6984 /* Not passed by invisible reference. */
6985 && (GET_CODE (XEXP (rtl, 0)) != REG
6986 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
6987 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
6988 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
6989 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
6992 /* Big endian correction check. */
6994 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
6995 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
6998 int offset = (UNITS_PER_WORD
6999 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
7000 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
7001 plus_constant (XEXP (rtl, 0), offset));
7005 if (rtl == NULL_RTX)
7008 rtl = eliminate_regs (rtl, 0, NULL_RTX);
7009 #ifdef LEAF_REG_REMAP
7010 if (current_function_uses_only_leaf_regs)
7011 leaf_renumber_regs_insn (rtl);
7014 switch (GET_CODE (rtl))
7017 /* The address of a variable that was optimized away; don't emit
7028 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7029 add_const_value_attribute (die, rtl);
7036 add_AT_location_description (die, DW_AT_location, rtl);
7044 /* Generate an DW_AT_name attribute given some string value to be included as
7045 the value of the attribute. */
7048 add_name_attribute (die, name_string)
7049 register dw_die_ref die;
7050 register const char *name_string;
7052 if (name_string != NULL && *name_string != 0)
7054 if (demangle_name_func)
7055 name_string = (*demangle_name_func) (name_string);
7057 add_AT_string (die, DW_AT_name, name_string);
7061 /* Given a tree node describing an array bound (either lower or upper) output
7062 a representation for that bound. */
7065 add_bound_info (subrange_die, bound_attr, bound)
7066 register dw_die_ref subrange_die;
7067 register enum dwarf_attribute bound_attr;
7068 register tree bound;
7070 /* If this is an Ada unconstrained array type, then don't emit any debug
7071 info because the array bounds are unknown. They are parameterized when
7072 the type is instantiated. */
7073 if (contains_placeholder_p (bound))
7076 switch (TREE_CODE (bound))
7081 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7083 if (! host_integerp (bound, 0)
7084 || (bound_attr == DW_AT_lower_bound
7085 && ((is_c_family () && integer_zerop (bound))
7086 || (is_fortran () && integer_onep (bound)))))
7087 /* use the default */
7090 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
7095 case NON_LVALUE_EXPR:
7096 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7100 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7101 access the upper bound values may be bogus. If they refer to a
7102 register, they may only describe how to get at these values at the
7103 points in the generated code right after they have just been
7104 computed. Worse yet, in the typical case, the upper bound values
7105 will not even *be* computed in the optimized code (though the
7106 number of elements will), so these SAVE_EXPRs are entirely
7107 bogus. In order to compensate for this fact, we check here to see
7108 if optimization is enabled, and if so, we don't add an attribute
7109 for the (unknown and unknowable) upper bound. This should not
7110 cause too much trouble for existing (stupid?) debuggers because
7111 they have to deal with empty upper bounds location descriptions
7112 anyway in order to be able to deal with incomplete array types.
7113 Of course an intelligent debugger (GDB?) should be able to
7114 comprehend that a missing upper bound specification in a array
7115 type used for a storage class `auto' local array variable
7116 indicates that the upper bound is both unknown (at compile- time)
7117 and unknowable (at run-time) due to optimization.
7119 We assume that a MEM rtx is safe because gcc wouldn't put the
7120 value there unless it was going to be used repeatedly in the
7121 function, i.e. for cleanups. */
7122 if (! optimize || (SAVE_EXPR_RTL (bound)
7123 && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
7125 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7126 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7127 register rtx loc = SAVE_EXPR_RTL (bound);
7129 /* If the RTL for the SAVE_EXPR is memory, handle the case where
7130 it references an outer function's frame. */
7132 if (GET_CODE (loc) == MEM)
7134 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
7136 if (XEXP (loc, 0) != new_addr)
7137 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
7140 add_AT_flag (decl_die, DW_AT_artificial, 1);
7141 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
7142 add_AT_location_description (decl_die, DW_AT_location, loc);
7143 add_AT_die_ref (subrange_die, bound_attr, decl_die);
7146 /* Else leave out the attribute. */
7152 /* ??? These types of bounds can be created by the Ada front end,
7153 and it isn't clear how to emit debug info for them. */
7161 /* Note that the block of subscript information for an array type also
7162 includes information about the element type of type given array type. */
7165 add_subscript_info (type_die, type)
7166 register dw_die_ref type_die;
7169 #ifndef MIPS_DEBUGGING_INFO
7170 register unsigned dimension_number;
7172 register tree lower, upper;
7173 register dw_die_ref subrange_die;
7175 /* The GNU compilers represent multidimensional array types as sequences of
7176 one dimensional array types whose element types are themselves array
7177 types. Here we squish that down, so that each multidimensional array
7178 type gets only one array_type DIE in the Dwarf debugging info. The draft
7179 Dwarf specification say that we are allowed to do this kind of
7180 compression in C (because there is no difference between an array or
7181 arrays and a multidimensional array in C) but for other source languages
7182 (e.g. Ada) we probably shouldn't do this. */
7184 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7185 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7186 We work around this by disabling this feature. See also
7187 gen_array_type_die. */
7188 #ifndef MIPS_DEBUGGING_INFO
7189 for (dimension_number = 0;
7190 TREE_CODE (type) == ARRAY_TYPE;
7191 type = TREE_TYPE (type), dimension_number++)
7194 register tree domain = TYPE_DOMAIN (type);
7196 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7197 and (in GNU C only) variable bounds. Handle all three forms
7199 subrange_die = new_die (DW_TAG_subrange_type, type_die);
7202 /* We have an array type with specified bounds. */
7203 lower = TYPE_MIN_VALUE (domain);
7204 upper = TYPE_MAX_VALUE (domain);
7206 /* define the index type. */
7207 if (TREE_TYPE (domain))
7209 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7210 TREE_TYPE field. We can't emit debug info for this
7211 because it is an unnamed integral type. */
7212 if (TREE_CODE (domain) == INTEGER_TYPE
7213 && TYPE_NAME (domain) == NULL_TREE
7214 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
7215 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
7218 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
7222 /* ??? If upper is NULL, the array has unspecified length,
7223 but it does have a lower bound. This happens with Fortran
7225 Since the debugger is definitely going to need to know N
7226 to produce useful results, go ahead and output the lower
7227 bound solo, and hope the debugger can cope. */
7229 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
7231 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
7234 /* We have an array type with an unspecified length. The DWARF-2
7235 spec does not say how to handle this; let's just leave out the
7240 #ifndef MIPS_DEBUGGING_INFO
7246 add_byte_size_attribute (die, tree_node)
7248 register tree tree_node;
7250 register unsigned size;
7252 switch (TREE_CODE (tree_node))
7260 case QUAL_UNION_TYPE:
7261 size = int_size_in_bytes (tree_node);
7264 /* For a data member of a struct or union, the DW_AT_byte_size is
7265 generally given as the number of bytes normally allocated for an
7266 object of the *declared* type of the member itself. This is true
7267 even for bit-fields. */
7268 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
7274 /* Note that `size' might be -1 when we get to this point. If it is, that
7275 indicates that the byte size of the entity in question is variable. We
7276 have no good way of expressing this fact in Dwarf at the present time,
7277 so just let the -1 pass on through. */
7279 add_AT_unsigned (die, DW_AT_byte_size, size);
7282 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7283 which specifies the distance in bits from the highest order bit of the
7284 "containing object" for the bit-field to the highest order bit of the
7287 For any given bit-field, the "containing object" is a hypothetical
7288 object (of some integral or enum type) within which the given bit-field
7289 lives. The type of this hypothetical "containing object" is always the
7290 same as the declared type of the individual bit-field itself. The
7291 determination of the exact location of the "containing object" for a
7292 bit-field is rather complicated. It's handled by the
7293 `field_byte_offset' function (above).
7295 Note that it is the size (in bytes) of the hypothetical "containing object"
7296 which will be given in the DW_AT_byte_size attribute for this bit-field.
7297 (See `byte_size_attribute' above). */
7300 add_bit_offset_attribute (die, decl)
7301 register dw_die_ref die;
7304 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
7305 tree type = DECL_BIT_FIELD_TYPE (decl);
7306 HOST_WIDE_INT bitpos_int;
7307 HOST_WIDE_INT highest_order_object_bit_offset;
7308 HOST_WIDE_INT highest_order_field_bit_offset;
7309 HOST_WIDE_INT unsigned bit_offset;
7311 /* Must be a field and a bit field. */
7313 || TREE_CODE (decl) != FIELD_DECL)
7316 /* We can't yet handle bit-fields whose offsets are variable, so if we
7317 encounter such things, just return without generating any attribute
7318 whatsoever. Likewise for variable or too large size. */
7319 if (! host_integerp (bit_position (decl), 0)
7320 || ! host_integerp (DECL_SIZE (decl), 1))
7323 bitpos_int = int_bit_position (decl);
7325 /* Note that the bit offset is always the distance (in bits) from the
7326 highest-order bit of the "containing object" to the highest-order bit of
7327 the bit-field itself. Since the "high-order end" of any object or field
7328 is different on big-endian and little-endian machines, the computation
7329 below must take account of these differences. */
7330 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
7331 highest_order_field_bit_offset = bitpos_int;
7333 if (! BYTES_BIG_ENDIAN)
7335 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
7336 highest_order_object_bit_offset += simple_type_size_in_bits (type);
7340 = (! BYTES_BIG_ENDIAN
7341 ? highest_order_object_bit_offset - highest_order_field_bit_offset
7342 : highest_order_field_bit_offset - highest_order_object_bit_offset);
7344 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
7347 /* For a FIELD_DECL node which represents a bit field, output an attribute
7348 which specifies the length in bits of the given field. */
7351 add_bit_size_attribute (die, decl)
7352 register dw_die_ref die;
7355 /* Must be a field and a bit field. */
7356 if (TREE_CODE (decl) != FIELD_DECL
7357 || ! DECL_BIT_FIELD_TYPE (decl))
7360 if (host_integerp (DECL_SIZE (decl), 1))
7361 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
7364 /* If the compiled language is ANSI C, then add a 'prototyped'
7365 attribute, if arg types are given for the parameters of a function. */
7368 add_prototyped_attribute (die, func_type)
7369 register dw_die_ref die;
7370 register tree func_type;
7372 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
7373 && TYPE_ARG_TYPES (func_type) != NULL)
7374 add_AT_flag (die, DW_AT_prototyped, 1);
7378 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7379 by looking in either the type declaration or object declaration
7383 add_abstract_origin_attribute (die, origin)
7384 register dw_die_ref die;
7385 register tree origin;
7387 dw_die_ref origin_die = NULL;
7389 if (TREE_CODE (origin) != FUNCTION_DECL)
7391 /* We may have gotten separated from the block for the inlined
7392 function, if we're in an exception handler or some such; make
7393 sure that the abstract function has been written out.
7395 Doing this for nested functions is wrong, however; functions are
7396 distinct units, and our context might not even be inline. */
7399 fn = TYPE_STUB_DECL (fn);
7400 fn = decl_function_context (fn);
7402 gen_abstract_function (fn);
7405 if (DECL_P (origin))
7406 origin_die = lookup_decl_die (origin);
7407 else if (TYPE_P (origin))
7408 origin_die = lookup_type_die (origin);
7410 if (origin_die == NULL)
7413 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
7416 /* We do not currently support the pure_virtual attribute. */
7419 add_pure_or_virtual_attribute (die, func_decl)
7420 register dw_die_ref die;
7421 register tree func_decl;
7423 if (DECL_VINDEX (func_decl))
7425 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7427 if (host_integerp (DECL_VINDEX (func_decl), 0))
7428 add_AT_loc (die, DW_AT_vtable_elem_location,
7429 new_loc_descr (DW_OP_constu,
7430 tree_low_cst (DECL_VINDEX (func_decl), 0),
7433 /* GNU extension: Record what type this method came from originally. */
7434 if (debug_info_level > DINFO_LEVEL_TERSE)
7435 add_AT_die_ref (die, DW_AT_containing_type,
7436 lookup_type_die (DECL_CONTEXT (func_decl)));
7440 /* Add source coordinate attributes for the given decl. */
7443 add_src_coords_attributes (die, decl)
7444 register dw_die_ref die;
7447 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
7449 add_AT_unsigned (die, DW_AT_decl_file, file_index);
7450 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7453 /* Add an DW_AT_name attribute and source coordinate attribute for the
7454 given decl, but only if it actually has a name. */
7457 add_name_and_src_coords_attributes (die, decl)
7458 register dw_die_ref die;
7461 register tree decl_name;
7463 decl_name = DECL_NAME (decl);
7464 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
7466 add_name_attribute (die, dwarf2_name (decl, 0));
7467 if (! DECL_ARTIFICIAL (decl))
7468 add_src_coords_attributes (die, decl);
7470 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
7471 && TREE_PUBLIC (decl)
7472 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
7473 add_AT_string (die, DW_AT_MIPS_linkage_name,
7474 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
7478 /* Push a new declaration scope. */
7481 push_decl_scope (scope)
7484 /* Make room in the decl_scope_table, if necessary. */
7485 if (decl_scope_table_allocated == decl_scope_depth)
7487 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
7489 = (tree *) xrealloc (decl_scope_table,
7490 decl_scope_table_allocated * sizeof (tree));
7493 decl_scope_table[decl_scope_depth] = scope;
7497 /* Pop a declaration scope. */
7501 if (decl_scope_depth <= 0)
7506 /* Return the DIE for the scope that immediately contains this type.
7507 Non-named types get global scope. Named types nested in other
7508 types get their containing scope if it's open, or global scope
7509 otherwise. All other types (i.e. function-local named types) get
7510 the current active scope. */
7513 scope_die_for (t, context_die)
7515 register dw_die_ref context_die;
7517 register dw_die_ref scope_die = NULL;
7518 register tree containing_scope;
7521 /* Non-types always go in the current scope. */
7525 containing_scope = TYPE_CONTEXT (t);
7527 /* Ignore namespaces for the moment. */
7528 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
7529 containing_scope = NULL_TREE;
7531 /* Ignore function type "scopes" from the C frontend. They mean that
7532 a tagged type is local to a parmlist of a function declarator, but
7533 that isn't useful to DWARF. */
7534 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
7535 containing_scope = NULL_TREE;
7537 if (containing_scope == NULL_TREE)
7538 scope_die = comp_unit_die;
7539 else if (TYPE_P (containing_scope))
7541 /* For types, we can just look up the appropriate DIE. But
7542 first we check to see if we're in the middle of emitting it
7543 so we know where the new DIE should go. */
7545 for (i = decl_scope_depth - 1; i >= 0; --i)
7546 if (decl_scope_table[i] == containing_scope)
7551 if (debug_info_level > DINFO_LEVEL_TERSE
7552 && !TREE_ASM_WRITTEN (containing_scope))
7555 /* If none of the current dies are suitable, we get file scope. */
7556 scope_die = comp_unit_die;
7559 scope_die = lookup_type_die (containing_scope);
7562 scope_die = context_die;
7567 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
7569 static inline int local_scope_p PARAMS ((dw_die_ref));
7571 local_scope_p (context_die)
7572 dw_die_ref context_die;
7574 for (; context_die; context_die = context_die->die_parent)
7575 if (context_die->die_tag == DW_TAG_inlined_subroutine
7576 || context_die->die_tag == DW_TAG_subprogram)
7581 /* Returns nonzero iff CONTEXT_DIE is a class. */
7583 static inline int class_scope_p PARAMS ((dw_die_ref));
7585 class_scope_p (context_die)
7586 dw_die_ref context_die;
7589 && (context_die->die_tag == DW_TAG_structure_type
7590 || context_die->die_tag == DW_TAG_union_type));
7593 /* Many forms of DIEs require a "type description" attribute. This
7594 routine locates the proper "type descriptor" die for the type given
7595 by 'type', and adds an DW_AT_type attribute below the given die. */
7598 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
7599 register dw_die_ref object_die;
7601 register int decl_const;
7602 register int decl_volatile;
7603 register dw_die_ref context_die;
7605 register enum tree_code code = TREE_CODE (type);
7606 register dw_die_ref type_die = NULL;
7608 /* ??? If this type is an unnamed subrange type of an integral or
7609 floating-point type, use the inner type. This is because we have no
7610 support for unnamed types in base_type_die. This can happen if this is
7611 an Ada subrange type. Correct solution is emit a subrange type die. */
7612 if ((code == INTEGER_TYPE || code == REAL_TYPE)
7613 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
7614 type = TREE_TYPE (type), code = TREE_CODE (type);
7616 if (code == ERROR_MARK)
7619 /* Handle a special case. For functions whose return type is void, we
7620 generate *no* type attribute. (Note that no object may have type
7621 `void', so this only applies to function return types). */
7622 if (code == VOID_TYPE)
7625 type_die = modified_type_die (type,
7626 decl_const || TYPE_READONLY (type),
7627 decl_volatile || TYPE_VOLATILE (type),
7629 if (type_die != NULL)
7630 add_AT_die_ref (object_die, DW_AT_type, type_die);
7633 /* Given a tree pointer to a struct, class, union, or enum type node, return
7634 a pointer to the (string) tag name for the given type, or zero if the type
7635 was declared without a tag. */
7641 register const char *name = 0;
7643 if (TYPE_NAME (type) != 0)
7645 register tree t = 0;
7647 /* Find the IDENTIFIER_NODE for the type name. */
7648 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7649 t = TYPE_NAME (type);
7651 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7652 a TYPE_DECL node, regardless of whether or not a `typedef' was
7654 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7655 && ! DECL_IGNORED_P (TYPE_NAME (type)))
7656 t = DECL_NAME (TYPE_NAME (type));
7658 /* Now get the name as a string, or invent one. */
7660 name = IDENTIFIER_POINTER (t);
7663 return (name == 0 || *name == '\0') ? 0 : name;
7666 /* Return the type associated with a data member, make a special check
7667 for bit field types. */
7670 member_declared_type (member)
7671 register tree member;
7673 return (DECL_BIT_FIELD_TYPE (member)
7674 ? DECL_BIT_FIELD_TYPE (member)
7675 : TREE_TYPE (member));
7678 /* Get the decl's label, as described by its RTL. This may be different
7679 from the DECL_NAME name used in the source file. */
7683 decl_start_label (decl)
7688 x = DECL_RTL (decl);
7689 if (GET_CODE (x) != MEM)
7693 if (GET_CODE (x) != SYMBOL_REF)
7696 fnname = XSTR (x, 0);
7701 /* These routines generate the internal representation of the DIE's for
7702 the compilation unit. Debugging information is collected by walking
7703 the declaration trees passed in from dwarf2out_decl(). */
7706 gen_array_type_die (type, context_die)
7708 register dw_die_ref context_die;
7710 register dw_die_ref scope_die = scope_die_for (type, context_die);
7711 register dw_die_ref array_die;
7712 register tree element_type;
7714 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7715 the inner array type comes before the outer array type. Thus we must
7716 call gen_type_die before we call new_die. See below also. */
7717 #ifdef MIPS_DEBUGGING_INFO
7718 gen_type_die (TREE_TYPE (type), context_die);
7721 array_die = new_die (DW_TAG_array_type, scope_die);
7724 /* We default the array ordering. SDB will probably do
7725 the right things even if DW_AT_ordering is not present. It's not even
7726 an issue until we start to get into multidimensional arrays anyway. If
7727 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7728 then we'll have to put the DW_AT_ordering attribute back in. (But if
7729 and when we find out that we need to put these in, we will only do so
7730 for multidimensional arrays. */
7731 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
7734 #ifdef MIPS_DEBUGGING_INFO
7735 /* The SGI compilers handle arrays of unknown bound by setting
7736 AT_declaration and not emitting any subrange DIEs. */
7737 if (! TYPE_DOMAIN (type))
7738 add_AT_unsigned (array_die, DW_AT_declaration, 1);
7741 add_subscript_info (array_die, type);
7743 add_name_attribute (array_die, type_tag (type));
7744 equate_type_number_to_die (type, array_die);
7746 /* Add representation of the type of the elements of this array type. */
7747 element_type = TREE_TYPE (type);
7749 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7750 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7751 We work around this by disabling this feature. See also
7752 add_subscript_info. */
7753 #ifndef MIPS_DEBUGGING_INFO
7754 while (TREE_CODE (element_type) == ARRAY_TYPE)
7755 element_type = TREE_TYPE (element_type);
7757 gen_type_die (element_type, context_die);
7760 add_type_attribute (array_die, element_type, 0, 0, context_die);
7764 gen_set_type_die (type, context_die)
7766 register dw_die_ref context_die;
7768 register dw_die_ref type_die
7769 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7771 equate_type_number_to_die (type, type_die);
7772 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7777 gen_entry_point_die (decl, context_die)
7779 register dw_die_ref context_die;
7781 register tree origin = decl_ultimate_origin (decl);
7782 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
7784 add_abstract_origin_attribute (decl_die, origin);
7787 add_name_and_src_coords_attributes (decl_die, decl);
7788 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
7792 if (DECL_ABSTRACT (decl))
7793 equate_decl_number_to_die (decl, decl_die);
7795 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
7799 /* Remember a type in the incomplete_types_list. */
7802 add_incomplete_type (type)
7805 if (incomplete_types == incomplete_types_allocated)
7807 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
7808 incomplete_types_list
7809 = (tree *) xrealloc (incomplete_types_list,
7810 sizeof (tree) * incomplete_types_allocated);
7813 incomplete_types_list[incomplete_types++] = type;
7816 /* Walk through the list of incomplete types again, trying once more to
7817 emit full debugging info for them. */
7820 retry_incomplete_types ()
7824 while (incomplete_types)
7827 type = incomplete_types_list[incomplete_types];
7828 gen_type_die (type, comp_unit_die);
7832 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7835 gen_inlined_enumeration_type_die (type, context_die)
7837 register dw_die_ref context_die;
7839 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
7841 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7842 be incomplete and such types are not marked. */
7843 add_abstract_origin_attribute (type_die, type);
7846 /* Generate a DIE to represent an inlined instance of a structure type. */
7849 gen_inlined_structure_type_die (type, context_die)
7851 register dw_die_ref context_die;
7853 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
7855 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7856 be incomplete and such types are not marked. */
7857 add_abstract_origin_attribute (type_die, type);
7860 /* Generate a DIE to represent an inlined instance of a union type. */
7863 gen_inlined_union_type_die (type, context_die)
7865 register dw_die_ref context_die;
7867 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
7869 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7870 be incomplete and such types are not marked. */
7871 add_abstract_origin_attribute (type_die, type);
7874 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7875 include all of the information about the enumeration values also. Each
7876 enumerated type name/value is listed as a child of the enumerated type
7880 gen_enumeration_type_die (type, context_die)
7882 register dw_die_ref context_die;
7884 register dw_die_ref type_die = lookup_type_die (type);
7886 if (type_die == NULL)
7888 type_die = new_die (DW_TAG_enumeration_type,
7889 scope_die_for (type, context_die));
7890 equate_type_number_to_die (type, type_die);
7891 add_name_attribute (type_die, type_tag (type));
7893 else if (! TYPE_SIZE (type))
7896 remove_AT (type_die, DW_AT_declaration);
7898 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7899 given enum type is incomplete, do not generate the DW_AT_byte_size
7900 attribute or the DW_AT_element_list attribute. */
7901 if (TYPE_SIZE (type))
7905 TREE_ASM_WRITTEN (type) = 1;
7906 add_byte_size_attribute (type_die, type);
7907 if (TYPE_STUB_DECL (type) != NULL_TREE)
7908 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
7910 /* If the first reference to this type was as the return type of an
7911 inline function, then it may not have a parent. Fix this now. */
7912 if (type_die->die_parent == NULL)
7913 add_child_die (scope_die_for (type, context_die), type_die);
7915 for (link = TYPE_FIELDS (type);
7916 link != NULL; link = TREE_CHAIN (link))
7918 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
7920 add_name_attribute (enum_die,
7921 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
7923 if (host_integerp (TREE_VALUE (link), 0))
7925 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
7926 add_AT_int (enum_die, DW_AT_const_value,
7927 tree_low_cst (TREE_VALUE (link), 0));
7929 add_AT_unsigned (enum_die, DW_AT_const_value,
7930 tree_low_cst (TREE_VALUE (link), 0));
7935 add_AT_flag (type_die, DW_AT_declaration, 1);
7939 /* Generate a DIE to represent either a real live formal parameter decl or to
7940 represent just the type of some formal parameter position in some function
7943 Note that this routine is a bit unusual because its argument may be a
7944 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7945 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7946 node. If it's the former then this function is being called to output a
7947 DIE to represent a formal parameter object (or some inlining thereof). If
7948 it's the latter, then this function is only being called to output a
7949 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7950 argument type of some subprogram type. */
7953 gen_formal_parameter_die (node, context_die)
7955 register dw_die_ref context_die;
7957 register dw_die_ref parm_die
7958 = new_die (DW_TAG_formal_parameter, context_die);
7959 register tree origin;
7961 switch (TREE_CODE_CLASS (TREE_CODE (node)))
7964 origin = decl_ultimate_origin (node);
7966 add_abstract_origin_attribute (parm_die, origin);
7969 add_name_and_src_coords_attributes (parm_die, node);
7970 add_type_attribute (parm_die, TREE_TYPE (node),
7971 TREE_READONLY (node),
7972 TREE_THIS_VOLATILE (node),
7974 if (DECL_ARTIFICIAL (node))
7975 add_AT_flag (parm_die, DW_AT_artificial, 1);
7978 equate_decl_number_to_die (node, parm_die);
7979 if (! DECL_ABSTRACT (node))
7980 add_location_or_const_value_attribute (parm_die, node);
7985 /* We were called with some kind of a ..._TYPE node. */
7986 add_type_attribute (parm_die, node, 0, 0, context_die);
7996 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
7997 at the end of an (ANSI prototyped) formal parameters list. */
8000 gen_unspecified_parameters_die (decl_or_type, context_die)
8001 register tree decl_or_type ATTRIBUTE_UNUSED;
8002 register dw_die_ref context_die;
8004 new_die (DW_TAG_unspecified_parameters, context_die);
8007 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
8008 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
8009 parameters as specified in some function type specification (except for
8010 those which appear as part of a function *definition*). */
8013 gen_formal_types_die (function_or_method_type, context_die)
8014 register tree function_or_method_type;
8015 register dw_die_ref context_die;
8018 register tree formal_type = NULL;
8019 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
8022 /* In the case where we are generating a formal types list for a C++
8023 non-static member function type, skip over the first thing on the
8024 TYPE_ARG_TYPES list because it only represents the type of the hidden
8025 `this pointer'. The debugger should be able to figure out (without
8026 being explicitly told) that this non-static member function type takes a
8027 `this pointer' and should be able to figure what the type of that hidden
8028 parameter is from the DW_AT_member attribute of the parent
8029 DW_TAG_subroutine_type DIE. */
8030 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
8031 first_parm_type = TREE_CHAIN (first_parm_type);
8034 /* Make our first pass over the list of formal parameter types and output a
8035 DW_TAG_formal_parameter DIE for each one. */
8036 for (link = first_parm_type; link; link = TREE_CHAIN (link))
8038 register dw_die_ref parm_die;
8040 formal_type = TREE_VALUE (link);
8041 if (formal_type == void_type_node)
8044 /* Output a (nameless) DIE to represent the formal parameter itself. */
8045 parm_die = gen_formal_parameter_die (formal_type, context_die);
8046 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8047 && link == first_parm_type)
8048 add_AT_flag (parm_die, DW_AT_artificial, 1);
8051 /* If this function type has an ellipsis, add a
8052 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8053 if (formal_type != void_type_node)
8054 gen_unspecified_parameters_die (function_or_method_type, context_die);
8056 /* Make our second (and final) pass over the list of formal parameter types
8057 and output DIEs to represent those types (as necessary). */
8058 for (link = TYPE_ARG_TYPES (function_or_method_type);
8060 link = TREE_CHAIN (link))
8062 formal_type = TREE_VALUE (link);
8063 if (formal_type == void_type_node)
8066 gen_type_die (formal_type, context_die);
8070 /* We want to generate the DIE for TYPE so that we can generate the
8071 die for MEMBER, which has been defined; we will need to refer back
8072 to the member declaration nested within TYPE. If we're trying to
8073 generate minimal debug info for TYPE, processing TYPE won't do the
8074 trick; we need to attach the member declaration by hand. */
8077 gen_type_die_for_member (type, member, context_die)
8079 dw_die_ref context_die;
8081 gen_type_die (type, context_die);
8083 /* If we're trying to avoid duplicate debug info, we may not have
8084 emitted the member decl for this function. Emit it now. */
8085 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
8086 && ! lookup_decl_die (member))
8088 if (decl_ultimate_origin (member))
8091 push_decl_scope (type);
8092 if (TREE_CODE (member) == FUNCTION_DECL)
8093 gen_subprogram_die (member, lookup_type_die (type));
8095 gen_variable_die (member, lookup_type_die (type));
8100 /* Generate the DWARF2 info for the "abstract" instance
8101 of a function which we may later generate inlined and/or
8102 out-of-line instances of. */
8105 gen_abstract_function (decl)
8108 register dw_die_ref old_die = lookup_decl_die (decl);
8111 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
8112 /* We've already generated the abstract instance. */
8115 save_fn = current_function_decl;
8116 current_function_decl = decl;
8118 set_decl_abstract_flags (decl, 1);
8119 dwarf2out_decl (decl);
8120 set_decl_abstract_flags (decl, 0);
8122 current_function_decl = save_fn;
8125 /* Generate a DIE to represent a declared function (either file-scope or
8129 gen_subprogram_die (decl, context_die)
8131 register dw_die_ref context_die;
8133 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
8134 register tree origin = decl_ultimate_origin (decl);
8135 register dw_die_ref subr_die;
8136 register rtx fp_reg;
8137 register tree fn_arg_types;
8138 register tree outer_scope;
8139 register dw_die_ref old_die = lookup_decl_die (decl);
8140 register int declaration = (current_function_decl != decl
8141 || class_scope_p (context_die));
8143 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
8144 be true, if we started to generate the abstract instance of an inline,
8145 decided to output its containing class, and proceeded to emit the
8146 declaration of the inline from the member list for the class. In that
8147 case, `declaration' takes priority; we'll get back to the abstract
8148 instance when we're done with the class. */
8150 /* The class-scope declaration DIE must be the primary DIE. */
8151 if (origin && declaration && class_scope_p (context_die))
8160 if (declaration && ! local_scope_p (context_die))
8163 /* Fixup die_parent for the abstract instance of a nested
8165 if (old_die && old_die->die_parent == NULL)
8166 add_child_die (context_die, old_die);
8168 subr_die = new_die (DW_TAG_subprogram, context_die);
8169 add_abstract_origin_attribute (subr_die, origin);
8171 else if (old_die && DECL_ABSTRACT (decl)
8172 && get_AT_unsigned (old_die, DW_AT_inline))
8174 /* This must be a redefinition of an extern inline function.
8175 We can just reuse the old die here. */
8178 /* Clear out the inlined attribute and parm types. */
8179 remove_AT (subr_die, DW_AT_inline);
8180 remove_children (subr_die);
8184 register unsigned file_index
8185 = lookup_filename (DECL_SOURCE_FILE (decl));
8187 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
8189 /* ??? This can happen if there is a bug in the program, for
8190 instance, if it has duplicate function definitions. Ideally,
8191 we should detect this case and ignore it. For now, if we have
8192 already reported an error, any error at all, then assume that
8193 we got here because of a input error, not a dwarf2 bug. */
8199 /* If the definition comes from the same place as the declaration,
8200 maybe use the old DIE. We always want the DIE for this function
8201 that has the *_pc attributes to be under comp_unit_die so the
8202 debugger can find it. For inlines, that is the concrete instance,
8203 so we can use the old DIE here. For non-inline methods, we want a
8204 specification DIE at toplevel, so we need a new DIE. For local
8205 class methods, this doesn't apply; we just use the old DIE. */
8206 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
8207 || context_die == NULL)
8208 && (DECL_ARTIFICIAL (decl)
8209 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
8210 && (get_AT_unsigned (old_die, DW_AT_decl_line)
8211 == (unsigned)DECL_SOURCE_LINE (decl)))))
8215 /* Clear out the declaration attribute and the parm types. */
8216 remove_AT (subr_die, DW_AT_declaration);
8217 remove_children (subr_die);
8221 subr_die = new_die (DW_TAG_subprogram, context_die);
8222 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
8223 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8224 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
8225 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8226 != (unsigned)DECL_SOURCE_LINE (decl))
8228 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8233 subr_die = new_die (DW_TAG_subprogram, context_die);
8235 if (TREE_PUBLIC (decl))
8236 add_AT_flag (subr_die, DW_AT_external, 1);
8238 add_name_and_src_coords_attributes (subr_die, decl);
8239 if (debug_info_level > DINFO_LEVEL_TERSE)
8241 register tree type = TREE_TYPE (decl);
8243 add_prototyped_attribute (subr_die, type);
8244 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
8247 add_pure_or_virtual_attribute (subr_die, decl);
8248 if (DECL_ARTIFICIAL (decl))
8249 add_AT_flag (subr_die, DW_AT_artificial, 1);
8250 if (TREE_PROTECTED (decl))
8251 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
8252 else if (TREE_PRIVATE (decl))
8253 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
8259 add_AT_flag (subr_die, DW_AT_declaration, 1);
8261 /* The first time we see a member function, it is in the context of
8262 the class to which it belongs. We make sure of this by emitting
8263 the class first. The next time is the definition, which is
8264 handled above. The two may come from the same source text. */
8265 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
8266 equate_decl_number_to_die (decl, subr_die);
8268 else if (DECL_ABSTRACT (decl))
8270 if (DECL_INLINE (decl) && !flag_no_inline)
8272 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
8273 inline functions, but not for extern inline functions.
8274 We can't get this completely correct because information
8275 about whether the function was declared inline is not
8277 if (DECL_DEFER_OUTPUT (decl))
8278 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
8280 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
8283 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
8285 equate_decl_number_to_die (decl, subr_die);
8287 else if (!DECL_EXTERNAL (decl))
8289 if (origin == NULL_TREE)
8290 equate_decl_number_to_die (decl, subr_die);
8292 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
8293 current_funcdef_number);
8294 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
8295 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
8296 current_funcdef_number);
8297 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
8299 add_pubname (decl, subr_die);
8300 add_arange (decl, subr_die);
8302 #ifdef MIPS_DEBUGGING_INFO
8303 /* Add a reference to the FDE for this routine. */
8304 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
8307 /* Define the "frame base" location for this routine. We use the
8308 frame pointer or stack pointer registers, since the RTL for local
8309 variables is relative to one of them. */
8311 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
8312 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
8315 /* ??? This fails for nested inline functions, because context_display
8316 is not part of the state saved/restored for inline functions. */
8317 if (current_function_needs_context)
8318 add_AT_location_description (subr_die, DW_AT_static_link,
8319 lookup_static_chain (decl));
8323 /* Now output descriptions of the arguments for this function. This gets
8324 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8325 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8326 `...' at the end of the formal parameter list. In order to find out if
8327 there was a trailing ellipsis or not, we must instead look at the type
8328 associated with the FUNCTION_DECL. This will be a node of type
8329 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8330 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8331 an ellipsis at the end. */
8333 /* In the case where we are describing a mere function declaration, all we
8334 need to do here (and all we *can* do here) is to describe the *types* of
8335 its formal parameters. */
8336 if (debug_info_level <= DINFO_LEVEL_TERSE)
8338 else if (declaration)
8339 gen_formal_types_die (TREE_TYPE (decl), subr_die);
8342 /* Generate DIEs to represent all known formal parameters */
8343 register tree arg_decls = DECL_ARGUMENTS (decl);
8346 /* When generating DIEs, generate the unspecified_parameters DIE
8347 instead if we come across the arg "__builtin_va_alist" */
8348 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
8349 if (TREE_CODE (parm) == PARM_DECL)
8351 if (DECL_NAME (parm)
8352 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
8353 "__builtin_va_alist"))
8354 gen_unspecified_parameters_die (parm, subr_die);
8356 gen_decl_die (parm, subr_die);
8359 /* Decide whether we need a unspecified_parameters DIE at the end.
8360 There are 2 more cases to do this for: 1) the ansi ... declaration -
8361 this is detectable when the end of the arg list is not a
8362 void_type_node 2) an unprototyped function declaration (not a
8363 definition). This just means that we have no info about the
8364 parameters at all. */
8365 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
8366 if (fn_arg_types != NULL)
8368 /* this is the prototyped case, check for ... */
8369 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
8370 gen_unspecified_parameters_die (decl, subr_die);
8372 else if (DECL_INITIAL (decl) == NULL_TREE)
8373 gen_unspecified_parameters_die (decl, subr_die);
8376 /* Output Dwarf info for all of the stuff within the body of the function
8377 (if it has one - it may be just a declaration). */
8378 outer_scope = DECL_INITIAL (decl);
8380 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8381 node created to represent a function. This outermost BLOCK actually
8382 represents the outermost binding contour for the function, i.e. the
8383 contour in which the function's formal parameters and labels get
8384 declared. Curiously, it appears that the front end doesn't actually
8385 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8386 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8387 list for the function instead.) The BLOCK_VARS list for the
8388 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8389 the function however, and we output DWARF info for those in
8390 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8391 node representing the function's outermost pair of curly braces, and
8392 any blocks used for the base and member initializers of a C++
8393 constructor function. */
8394 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
8396 current_function_has_inlines = 0;
8397 decls_for_scope (outer_scope, subr_die, 0);
8399 #if 0 && defined (MIPS_DEBUGGING_INFO)
8400 if (current_function_has_inlines)
8402 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
8403 if (! comp_unit_has_inlines)
8405 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
8406 comp_unit_has_inlines = 1;
8413 /* Generate a DIE to represent a declared data object. */
8416 gen_variable_die (decl, context_die)
8418 register dw_die_ref context_die;
8420 register tree origin = decl_ultimate_origin (decl);
8421 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
8423 dw_die_ref old_die = lookup_decl_die (decl);
8424 int declaration = (DECL_EXTERNAL (decl)
8425 || class_scope_p (context_die));
8428 add_abstract_origin_attribute (var_die, origin);
8429 /* Loop unrolling can create multiple blocks that refer to the same
8430 static variable, so we must test for the DW_AT_declaration flag. */
8431 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8432 copy decls and set the DECL_ABSTRACT flag on them instead of
8434 else if (old_die && TREE_STATIC (decl)
8435 && get_AT_flag (old_die, DW_AT_declaration) == 1)
8437 /* This is a definition of a C++ class level static. */
8438 add_AT_die_ref (var_die, DW_AT_specification, old_die);
8439 if (DECL_NAME (decl))
8441 register unsigned file_index
8442 = lookup_filename (DECL_SOURCE_FILE (decl));
8444 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8445 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
8447 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8448 != (unsigned)DECL_SOURCE_LINE (decl))
8450 add_AT_unsigned (var_die, DW_AT_decl_line,
8451 DECL_SOURCE_LINE (decl));
8456 add_name_and_src_coords_attributes (var_die, decl);
8457 add_type_attribute (var_die, TREE_TYPE (decl),
8458 TREE_READONLY (decl),
8459 TREE_THIS_VOLATILE (decl), context_die);
8461 if (TREE_PUBLIC (decl))
8462 add_AT_flag (var_die, DW_AT_external, 1);
8464 if (DECL_ARTIFICIAL (decl))
8465 add_AT_flag (var_die, DW_AT_artificial, 1);
8467 if (TREE_PROTECTED (decl))
8468 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
8470 else if (TREE_PRIVATE (decl))
8471 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
8475 add_AT_flag (var_die, DW_AT_declaration, 1);
8477 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
8478 equate_decl_number_to_die (decl, var_die);
8480 if (! declaration && ! DECL_ABSTRACT (decl))
8482 add_location_or_const_value_attribute (var_die, decl);
8483 add_pubname (decl, var_die);
8487 /* Generate a DIE to represent a label identifier. */
8490 gen_label_die (decl, context_die)
8492 register dw_die_ref context_die;
8494 register tree origin = decl_ultimate_origin (decl);
8495 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
8497 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8498 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
8501 add_abstract_origin_attribute (lbl_die, origin);
8503 add_name_and_src_coords_attributes (lbl_die, decl);
8505 if (DECL_ABSTRACT (decl))
8506 equate_decl_number_to_die (decl, lbl_die);
8509 insn = DECL_RTL (decl);
8511 /* Deleted labels are programmer specified labels which have been
8512 eliminated because of various optimisations. We still emit them
8513 here so that it is possible to put breakpoints on them. */
8514 if (GET_CODE (insn) == CODE_LABEL
8515 || ((GET_CODE (insn) == NOTE
8516 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
8518 /* When optimization is enabled (via -O) some parts of the compiler
8519 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8520 represent source-level labels which were explicitly declared by
8521 the user. This really shouldn't be happening though, so catch
8522 it if it ever does happen. */
8523 if (INSN_DELETED_P (insn))
8526 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
8527 ASM_GENERATE_INTERNAL_LABEL (label, label2,
8528 (unsigned) INSN_UID (insn));
8529 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
8534 /* Generate a DIE for a lexical block. */
8537 gen_lexical_block_die (stmt, context_die, depth)
8539 register dw_die_ref context_die;
8542 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
8543 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8545 if (! BLOCK_ABSTRACT (stmt))
8547 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8548 BLOCK_NUMBER (stmt));
8549 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
8550 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
8551 BLOCK_NUMBER (stmt));
8552 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
8555 decls_for_scope (stmt, stmt_die, depth);
8558 /* Generate a DIE for an inlined subprogram. */
8561 gen_inlined_subroutine_die (stmt, context_die, depth)
8563 register dw_die_ref context_die;
8566 if (! BLOCK_ABSTRACT (stmt))
8568 register dw_die_ref subr_die
8569 = new_die (DW_TAG_inlined_subroutine, context_die);
8570 register tree decl = block_ultimate_origin (stmt);
8571 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8573 /* Emit info for the abstract instance first, if we haven't yet. */
8574 gen_abstract_function (decl);
8576 add_abstract_origin_attribute (subr_die, decl);
8577 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8578 BLOCK_NUMBER (stmt));
8579 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
8580 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
8581 BLOCK_NUMBER (stmt));
8582 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
8583 decls_for_scope (stmt, subr_die, depth);
8584 current_function_has_inlines = 1;
8588 /* Generate a DIE for a field in a record, or structure. */
8591 gen_field_die (decl, context_die)
8593 register dw_die_ref context_die;
8595 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
8597 add_name_and_src_coords_attributes (decl_die, decl);
8598 add_type_attribute (decl_die, member_declared_type (decl),
8599 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
8602 /* If this is a bit field... */
8603 if (DECL_BIT_FIELD_TYPE (decl))
8605 add_byte_size_attribute (decl_die, decl);
8606 add_bit_size_attribute (decl_die, decl);
8607 add_bit_offset_attribute (decl_die, decl);
8610 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
8611 add_data_member_location_attribute (decl_die, decl);
8613 if (DECL_ARTIFICIAL (decl))
8614 add_AT_flag (decl_die, DW_AT_artificial, 1);
8616 if (TREE_PROTECTED (decl))
8617 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
8619 else if (TREE_PRIVATE (decl))
8620 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
8624 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8625 Use modified_type_die instead.
8626 We keep this code here just in case these types of DIEs may be needed to
8627 represent certain things in other languages (e.g. Pascal) someday. */
8629 gen_pointer_type_die (type, context_die)
8631 register dw_die_ref context_die;
8633 register dw_die_ref ptr_die
8634 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
8636 equate_type_number_to_die (type, ptr_die);
8637 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8638 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8641 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8642 Use modified_type_die instead.
8643 We keep this code here just in case these types of DIEs may be needed to
8644 represent certain things in other languages (e.g. Pascal) someday. */
8646 gen_reference_type_die (type, context_die)
8648 register dw_die_ref context_die;
8650 register dw_die_ref ref_die
8651 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
8653 equate_type_number_to_die (type, ref_die);
8654 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
8655 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8659 /* Generate a DIE for a pointer to a member type. */
8661 gen_ptr_to_mbr_type_die (type, context_die)
8663 register dw_die_ref context_die;
8665 register dw_die_ref ptr_die
8666 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8668 equate_type_number_to_die (type, ptr_die);
8669 add_AT_die_ref (ptr_die, DW_AT_containing_type,
8670 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
8671 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8674 /* Generate the DIE for the compilation unit. */
8677 gen_compile_unit_die (filename)
8678 register const char *filename;
8680 register dw_die_ref die;
8682 const char *wd = getpwd ();
8685 die = new_die (DW_TAG_compile_unit, NULL);
8686 add_name_attribute (die, filename);
8688 if (wd != NULL && filename[0] != DIR_SEPARATOR)
8689 add_AT_string (die, DW_AT_comp_dir, wd);
8691 sprintf (producer, "%s %s", language_string, version_string);
8693 #ifdef MIPS_DEBUGGING_INFO
8694 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8695 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8696 not appear in the producer string, the debugger reaches the conclusion
8697 that the object file is stripped and has no debugging information.
8698 To get the MIPS/SGI debugger to believe that there is debugging
8699 information in the object file, we add a -g to the producer string. */
8700 if (debug_info_level > DINFO_LEVEL_TERSE)
8701 strcat (producer, " -g");
8704 add_AT_string (die, DW_AT_producer, producer);
8706 if (strcmp (language_string, "GNU C++") == 0)
8707 language = DW_LANG_C_plus_plus;
8708 else if (strcmp (language_string, "GNU Ada") == 0)
8709 language = DW_LANG_Ada83;
8710 else if (strcmp (language_string, "GNU F77") == 0)
8711 language = DW_LANG_Fortran77;
8712 else if (strcmp (language_string, "GNU Pascal") == 0)
8713 language = DW_LANG_Pascal83;
8714 else if (flag_traditional)
8715 language = DW_LANG_C;
8717 language = DW_LANG_C89;
8719 add_AT_unsigned (die, DW_AT_language, language);
8724 /* Generate a DIE for a string type. */
8727 gen_string_type_die (type, context_die)
8729 register dw_die_ref context_die;
8731 register dw_die_ref type_die
8732 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
8734 equate_type_number_to_die (type, type_die);
8736 /* Fudge the string length attribute for now. */
8738 /* TODO: add string length info.
8739 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8740 bound_representation (upper_bound, 0, 'u'); */
8743 /* Generate the DIE for a base class. */
8746 gen_inheritance_die (binfo, context_die)
8747 register tree binfo;
8748 register dw_die_ref context_die;
8750 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
8752 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
8753 add_data_member_location_attribute (die, binfo);
8755 if (TREE_VIA_VIRTUAL (binfo))
8756 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8757 if (TREE_VIA_PUBLIC (binfo))
8758 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
8759 else if (TREE_VIA_PROTECTED (binfo))
8760 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
8763 /* Generate a DIE for a class member. */
8766 gen_member_die (type, context_die)
8768 register dw_die_ref context_die;
8770 register tree member;
8773 /* If this is not an incomplete type, output descriptions of each of its
8774 members. Note that as we output the DIEs necessary to represent the
8775 members of this record or union type, we will also be trying to output
8776 DIEs to represent the *types* of those members. However the `type'
8777 function (above) will specifically avoid generating type DIEs for member
8778 types *within* the list of member DIEs for this (containing) type execpt
8779 for those types (of members) which are explicitly marked as also being
8780 members of this (containing) type themselves. The g++ front- end can
8781 force any given type to be treated as a member of some other
8782 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8783 to point to the TREE node representing the appropriate (containing)
8786 /* First output info about the base classes. */
8787 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
8789 register tree bases = TYPE_BINFO_BASETYPES (type);
8790 register int n_bases = TREE_VEC_LENGTH (bases);
8793 for (i = 0; i < n_bases; i++)
8794 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
8797 /* Now output info about the data members and type members. */
8798 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
8800 /* If we thought we were generating minimal debug info for TYPE
8801 and then changed our minds, some of the member declarations
8802 may have already been defined. Don't define them again, but
8803 do put them in the right order. */
8805 child = lookup_decl_die (member);
8807 splice_child_die (context_die, child);
8809 gen_decl_die (member, context_die);
8812 /* Now output info about the function members (if any). */
8813 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
8815 child = lookup_decl_die (member);
8817 splice_child_die (context_die, child);
8819 gen_decl_die (member, context_die);
8823 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
8824 is set, we pretend that the type was never defined, so we only get the
8825 member DIEs needed by later specification DIEs. */
8828 gen_struct_or_union_type_die (type, context_die)
8830 register dw_die_ref context_die;
8832 register dw_die_ref type_die = lookup_type_die (type);
8833 register dw_die_ref scope_die = 0;
8834 register int nested = 0;
8835 int complete = (TYPE_SIZE (type)
8836 && (! TYPE_STUB_DECL (type)
8837 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
8839 if (type_die && ! complete)
8842 if (TYPE_CONTEXT (type) != NULL_TREE
8843 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
8846 scope_die = scope_die_for (type, context_die);
8848 if (! type_die || (nested && scope_die == comp_unit_die))
8849 /* First occurrence of type or toplevel definition of nested class. */
8851 register dw_die_ref old_die = type_die;
8853 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
8854 ? DW_TAG_structure_type : DW_TAG_union_type,
8856 equate_type_number_to_die (type, type_die);
8857 add_name_attribute (type_die, type_tag (type));
8859 add_AT_die_ref (type_die, DW_AT_specification, old_die);
8862 remove_AT (type_die, DW_AT_declaration);
8864 /* If this type has been completed, then give it a byte_size attribute and
8865 then give a list of members. */
8868 /* Prevent infinite recursion in cases where the type of some member of
8869 this type is expressed in terms of this type itself. */
8870 TREE_ASM_WRITTEN (type) = 1;
8871 add_byte_size_attribute (type_die, type);
8872 if (TYPE_STUB_DECL (type) != NULL_TREE)
8873 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8875 /* If the first reference to this type was as the return type of an
8876 inline function, then it may not have a parent. Fix this now. */
8877 if (type_die->die_parent == NULL)
8878 add_child_die (scope_die, type_die);
8880 push_decl_scope (type);
8881 gen_member_die (type, type_die);
8884 /* GNU extension: Record what type our vtable lives in. */
8885 if (TYPE_VFIELD (type))
8887 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
8889 gen_type_die (vtype, context_die);
8890 add_AT_die_ref (type_die, DW_AT_containing_type,
8891 lookup_type_die (vtype));
8896 add_AT_flag (type_die, DW_AT_declaration, 1);
8898 /* We don't need to do this for function-local types. */
8899 if (! decl_function_context (TYPE_STUB_DECL (type)))
8900 add_incomplete_type (type);
8904 /* Generate a DIE for a subroutine _type_. */
8907 gen_subroutine_type_die (type, context_die)
8909 register dw_die_ref context_die;
8911 register tree return_type = TREE_TYPE (type);
8912 register dw_die_ref subr_die
8913 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
8915 equate_type_number_to_die (type, subr_die);
8916 add_prototyped_attribute (subr_die, type);
8917 add_type_attribute (subr_die, return_type, 0, 0, context_die);
8918 gen_formal_types_die (type, subr_die);
8921 /* Generate a DIE for a type definition */
8924 gen_typedef_die (decl, context_die)
8926 register dw_die_ref context_die;
8928 register dw_die_ref type_die;
8929 register tree origin;
8931 if (TREE_ASM_WRITTEN (decl))
8933 TREE_ASM_WRITTEN (decl) = 1;
8935 type_die = new_die (DW_TAG_typedef, context_die);
8936 origin = decl_ultimate_origin (decl);
8938 add_abstract_origin_attribute (type_die, origin);
8942 add_name_and_src_coords_attributes (type_die, decl);
8943 if (DECL_ORIGINAL_TYPE (decl))
8945 type = DECL_ORIGINAL_TYPE (decl);
8946 equate_type_number_to_die (TREE_TYPE (decl), type_die);
8949 type = TREE_TYPE (decl);
8950 add_type_attribute (type_die, type, TREE_READONLY (decl),
8951 TREE_THIS_VOLATILE (decl), context_die);
8954 if (DECL_ABSTRACT (decl))
8955 equate_decl_number_to_die (decl, type_die);
8958 /* Generate a type description DIE. */
8961 gen_type_die (type, context_die)
8963 register dw_die_ref context_die;
8967 if (type == NULL_TREE || type == error_mark_node)
8970 /* We are going to output a DIE to represent the unqualified version of
8971 this type (i.e. without any const or volatile qualifiers) so get the
8972 main variant (i.e. the unqualified version) of this type now. */
8973 type = type_main_variant (type);
8975 if (TREE_ASM_WRITTEN (type))
8978 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8979 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
8981 TREE_ASM_WRITTEN (type) = 1;
8982 gen_decl_die (TYPE_NAME (type), context_die);
8986 switch (TREE_CODE (type))
8992 case REFERENCE_TYPE:
8993 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
8994 ensures that the gen_type_die recursion will terminate even if the
8995 type is recursive. Recursive types are possible in Ada. */
8996 /* ??? We could perhaps do this for all types before the switch
8998 TREE_ASM_WRITTEN (type) = 1;
9000 /* For these types, all that is required is that we output a DIE (or a
9001 set of DIEs) to represent the "basis" type. */
9002 gen_type_die (TREE_TYPE (type), context_die);
9006 /* This code is used for C++ pointer-to-data-member types.
9007 Output a description of the relevant class type. */
9008 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
9010 /* Output a description of the type of the object pointed to. */
9011 gen_type_die (TREE_TYPE (type), context_die);
9013 /* Now output a DIE to represent this pointer-to-data-member type
9015 gen_ptr_to_mbr_type_die (type, context_die);
9019 gen_type_die (TYPE_DOMAIN (type), context_die);
9020 gen_set_type_die (type, context_die);
9024 gen_type_die (TREE_TYPE (type), context_die);
9025 abort (); /* No way to represent these in Dwarf yet! */
9029 /* Force out return type (in case it wasn't forced out already). */
9030 gen_type_die (TREE_TYPE (type), context_die);
9031 gen_subroutine_type_die (type, context_die);
9035 /* Force out return type (in case it wasn't forced out already). */
9036 gen_type_die (TREE_TYPE (type), context_die);
9037 gen_subroutine_type_die (type, context_die);
9041 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
9043 gen_type_die (TREE_TYPE (type), context_die);
9044 gen_string_type_die (type, context_die);
9047 gen_array_type_die (type, context_die);
9053 case QUAL_UNION_TYPE:
9054 /* If this is a nested type whose containing class hasn't been
9055 written out yet, writing it out will cover this one, too.
9056 This does not apply to instantiations of member class templates;
9057 they need to be added to the containing class as they are
9058 generated. FIXME: This hurts the idea of combining type decls
9059 from multiple TUs, since we can't predict what set of template
9060 instantiations we'll get. */
9061 if (TYPE_CONTEXT (type)
9062 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9063 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9065 gen_type_die (TYPE_CONTEXT (type), context_die);
9067 if (TREE_ASM_WRITTEN (type))
9070 /* If that failed, attach ourselves to the stub. */
9071 push_decl_scope (TYPE_CONTEXT (type));
9072 context_die = lookup_type_die (TYPE_CONTEXT (type));
9078 if (TREE_CODE (type) == ENUMERAL_TYPE)
9079 gen_enumeration_type_die (type, context_die);
9081 gen_struct_or_union_type_die (type, context_die);
9086 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9087 it up if it is ever completed. gen_*_type_die will set it for us
9088 when appropriate. */
9097 /* No DIEs needed for fundamental types. */
9101 /* No Dwarf representation currently defined. */
9108 TREE_ASM_WRITTEN (type) = 1;
9111 /* Generate a DIE for a tagged type instantiation. */
9114 gen_tagged_type_instantiation_die (type, context_die)
9116 register dw_die_ref context_die;
9118 if (type == NULL_TREE || type == error_mark_node)
9121 /* We are going to output a DIE to represent the unqualified version of
9122 this type (i.e. without any const or volatile qualifiers) so make sure
9123 that we have the main variant (i.e. the unqualified version) of this
9125 if (type != type_main_variant (type))
9128 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
9129 an instance of an unresolved type. */
9131 switch (TREE_CODE (type))
9137 gen_inlined_enumeration_type_die (type, context_die);
9141 gen_inlined_structure_type_die (type, context_die);
9145 case QUAL_UNION_TYPE:
9146 gen_inlined_union_type_die (type, context_die);
9154 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
9155 things which are local to the given block. */
9158 gen_block_die (stmt, context_die, depth)
9160 register dw_die_ref context_die;
9163 register int must_output_die = 0;
9164 register tree origin;
9166 register enum tree_code origin_code;
9168 /* Ignore blocks never really used to make RTL. */
9170 if (stmt == NULL_TREE || !TREE_USED (stmt)
9171 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
9174 /* Determine the "ultimate origin" of this block. This block may be an
9175 inlined instance of an inlined instance of inline function, so we have
9176 to trace all of the way back through the origin chain to find out what
9177 sort of node actually served as the original seed for the creation of
9178 the current block. */
9179 origin = block_ultimate_origin (stmt);
9180 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
9182 /* Determine if we need to output any Dwarf DIEs at all to represent this
9184 if (origin_code == FUNCTION_DECL)
9185 /* The outer scopes for inlinings *must* always be represented. We
9186 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9187 must_output_die = 1;
9190 /* In the case where the current block represents an inlining of the
9191 "body block" of an inline function, we must *NOT* output any DIE for
9192 this block because we have already output a DIE to represent the
9193 whole inlined function scope and the "body block" of any function
9194 doesn't really represent a different scope according to ANSI C
9195 rules. So we check here to make sure that this block does not
9196 represent a "body block inlining" before trying to set the
9197 `must_output_die' flag. */
9198 if (! is_body_block (origin ? origin : stmt))
9200 /* Determine if this block directly contains any "significant"
9201 local declarations which we will need to output DIEs for. */
9202 if (debug_info_level > DINFO_LEVEL_TERSE)
9203 /* We are not in terse mode so *any* local declaration counts
9204 as being a "significant" one. */
9205 must_output_die = (BLOCK_VARS (stmt) != NULL);
9207 /* We are in terse mode, so only local (nested) function
9208 definitions count as "significant" local declarations. */
9209 for (decl = BLOCK_VARS (stmt);
9210 decl != NULL; decl = TREE_CHAIN (decl))
9211 if (TREE_CODE (decl) == FUNCTION_DECL
9212 && DECL_INITIAL (decl))
9214 must_output_die = 1;
9220 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9221 DIE for any block which contains no significant local declarations at
9222 all. Rather, in such cases we just call `decls_for_scope' so that any
9223 needed Dwarf info for any sub-blocks will get properly generated. Note
9224 that in terse mode, our definition of what constitutes a "significant"
9225 local declaration gets restricted to include only inlined function
9226 instances and local (nested) function definitions. */
9227 if (must_output_die)
9229 if (origin_code == FUNCTION_DECL)
9230 gen_inlined_subroutine_die (stmt, context_die, depth);
9232 gen_lexical_block_die (stmt, context_die, depth);
9235 decls_for_scope (stmt, context_die, depth);
9238 /* Generate all of the decls declared within a given scope and (recursively)
9239 all of its sub-blocks. */
9242 decls_for_scope (stmt, context_die, depth)
9244 register dw_die_ref context_die;
9248 register tree subblocks;
9250 /* Ignore blocks never really used to make RTL. */
9251 if (stmt == NULL_TREE || ! TREE_USED (stmt))
9254 /* Output the DIEs to represent all of the data objects and typedefs
9255 declared directly within this block but not within any nested
9256 sub-blocks. Also, nested function and tag DIEs have been
9257 generated with a parent of NULL; fix that up now. */
9258 for (decl = BLOCK_VARS (stmt);
9259 decl != NULL; decl = TREE_CHAIN (decl))
9261 register dw_die_ref die;
9263 if (TREE_CODE (decl) == FUNCTION_DECL)
9264 die = lookup_decl_die (decl);
9265 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9266 die = lookup_type_die (TREE_TYPE (decl));
9270 if (die != NULL && die->die_parent == NULL)
9271 add_child_die (context_die, die);
9273 gen_decl_die (decl, context_die);
9276 /* Output the DIEs to represent all sub-blocks (and the items declared
9277 therein) of this block. */
9278 for (subblocks = BLOCK_SUBBLOCKS (stmt);
9280 subblocks = BLOCK_CHAIN (subblocks))
9281 gen_block_die (subblocks, context_die, depth + 1);
9284 /* Is this a typedef we can avoid emitting? */
9287 is_redundant_typedef (decl)
9290 if (TYPE_DECL_IS_STUB (decl))
9293 if (DECL_ARTIFICIAL (decl)
9294 && DECL_CONTEXT (decl)
9295 && is_tagged_type (DECL_CONTEXT (decl))
9296 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
9297 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
9298 /* Also ignore the artificial member typedef for the class name. */
9304 /* Generate Dwarf debug information for a decl described by DECL. */
9307 gen_decl_die (decl, context_die)
9309 register dw_die_ref context_die;
9311 register tree origin;
9313 if (TREE_CODE (decl) == ERROR_MARK)
9316 /* If this ..._DECL node is marked to be ignored, then ignore it. */
9317 if (DECL_IGNORED_P (decl))
9320 switch (TREE_CODE (decl))
9323 /* The individual enumerators of an enum type get output when we output
9324 the Dwarf representation of the relevant enum type itself. */
9328 /* Don't output any DIEs to represent mere function declarations,
9329 unless they are class members or explicit block externs. */
9330 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
9331 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
9334 /* If we're emitting an out-of-line copy of an inline function,
9335 emit info for the abstract instance and set up to refer to it. */
9336 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
9337 && ! class_scope_p (context_die))
9339 gen_abstract_function (decl);
9340 set_decl_origin_self (decl);
9343 if (debug_info_level > DINFO_LEVEL_TERSE)
9345 /* Before we describe the FUNCTION_DECL itself, make sure that we
9346 have described its return type. */
9347 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
9349 /* And its virtual context. */
9350 if (DECL_VINDEX (decl) != NULL_TREE)
9351 gen_type_die (DECL_CONTEXT (decl), context_die);
9353 /* And its containing type. */
9354 origin = decl_class_context (decl);
9355 if (origin != NULL_TREE)
9356 gen_type_die_for_member (origin, decl, context_die);
9359 /* Now output a DIE to represent the function itself. */
9360 gen_subprogram_die (decl, context_die);
9364 /* If we are in terse mode, don't generate any DIEs to represent any
9366 if (debug_info_level <= DINFO_LEVEL_TERSE)
9369 /* In the special case of a TYPE_DECL node representing the
9370 declaration of some type tag, if the given TYPE_DECL is marked as
9371 having been instantiated from some other (original) TYPE_DECL node
9372 (e.g. one which was generated within the original definition of an
9373 inline function) we have to generate a special (abbreviated)
9374 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9376 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
9378 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
9382 if (is_redundant_typedef (decl))
9383 gen_type_die (TREE_TYPE (decl), context_die);
9385 /* Output a DIE to represent the typedef itself. */
9386 gen_typedef_die (decl, context_die);
9390 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9391 gen_label_die (decl, context_die);
9395 /* If we are in terse mode, don't generate any DIEs to represent any
9396 variable declarations or definitions. */
9397 if (debug_info_level <= DINFO_LEVEL_TERSE)
9400 /* Output any DIEs that are needed to specify the type of this data
9402 gen_type_die (TREE_TYPE (decl), context_die);
9404 /* And its containing type. */
9405 origin = decl_class_context (decl);
9406 if (origin != NULL_TREE)
9407 gen_type_die_for_member (origin, decl, context_die);
9409 /* Now output the DIE to represent the data object itself. This gets
9410 complicated because of the possibility that the VAR_DECL really
9411 represents an inlined instance of a formal parameter for an inline
9413 origin = decl_ultimate_origin (decl);
9414 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
9415 gen_formal_parameter_die (decl, context_die);
9417 gen_variable_die (decl, context_die);
9421 /* Ignore the nameless fields that are used to skip bits, but
9422 handle C++ anonymous unions. */
9423 if (DECL_NAME (decl) != NULL_TREE
9424 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
9426 gen_type_die (member_declared_type (decl), context_die);
9427 gen_field_die (decl, context_die);
9432 gen_type_die (TREE_TYPE (decl), context_die);
9433 gen_formal_parameter_die (decl, context_die);
9436 case NAMESPACE_DECL:
9437 /* Ignore for now. */
9445 /* Add Ada "use" clause information for SGI Workshop debugger. */
9448 dwarf2out_add_library_unit_info (filename, context_list)
9449 const char *filename;
9450 const char *context_list;
9452 unsigned int file_index;
9454 if (filename != NULL)
9456 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
9457 tree context_list_decl
9458 = build_decl (LABEL_DECL, get_identifier (context_list),
9461 TREE_PUBLIC (context_list_decl) = TRUE;
9462 add_name_attribute (unit_die, context_list);
9463 file_index = lookup_filename (filename);
9464 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
9465 add_pubname (context_list_decl, unit_die);
9469 /* Write the debugging output for DECL. */
9472 dwarf2out_decl (decl)
9475 register dw_die_ref context_die = comp_unit_die;
9477 if (TREE_CODE (decl) == ERROR_MARK)
9480 /* If this ..._DECL node is marked to be ignored, then ignore it. */
9481 if (DECL_IGNORED_P (decl))
9484 switch (TREE_CODE (decl))
9487 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9488 builtin function. Explicit programmer-supplied declarations of
9489 these same functions should NOT be ignored however. */
9490 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
9493 /* What we would really like to do here is to filter out all mere
9494 file-scope declarations of file-scope functions which are never
9495 referenced later within this translation unit (and keep all of ones
9496 that *are* referenced later on) but we aren't clairvoyant, so we have
9497 no idea which functions will be referenced in the future (i.e. later
9498 on within the current translation unit). So here we just ignore all
9499 file-scope function declarations which are not also definitions. If
9500 and when the debugger needs to know something about these functions,
9501 it will have to hunt around and find the DWARF information associated
9502 with the definition of the function. Note that we can't just check
9503 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9504 definitions and which ones represent mere declarations. We have to
9505 check `DECL_INITIAL' instead. That's because the C front-end
9506 supports some weird semantics for "extern inline" function
9507 definitions. These can get inlined within the current translation
9508 unit (an thus, we need to generate DWARF info for their abstract
9509 instances so that the DWARF info for the concrete inlined instances
9510 can have something to refer to) but the compiler never generates any
9511 out-of-lines instances of such things (despite the fact that they
9512 *are* definitions). The important point is that the C front-end
9513 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9514 to generate DWARF for them anyway. Note that the C++ front-end also
9515 plays some similar games for inline function definitions appearing
9516 within include files which also contain
9517 `#pragma interface' pragmas. */
9518 if (DECL_INITIAL (decl) == NULL_TREE)
9521 /* If we're a nested function, initially use a parent of NULL; if we're
9522 a plain function, this will be fixed up in decls_for_scope. If
9523 we're a method, it will be ignored, since we already have a DIE. */
9524 if (decl_function_context (decl))
9530 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9531 declaration and if the declaration was never even referenced from
9532 within this entire compilation unit. We suppress these DIEs in
9533 order to save space in the .debug section (by eliminating entries
9534 which are probably useless). Note that we must not suppress
9535 block-local extern declarations (whether used or not) because that
9536 would screw-up the debugger's name lookup mechanism and cause it to
9537 miss things which really ought to be in scope at a given point. */
9538 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
9541 /* If we are in terse mode, don't generate any DIEs to represent any
9542 variable declarations or definitions. */
9543 if (debug_info_level <= DINFO_LEVEL_TERSE)
9548 /* Don't emit stubs for types unless they are needed by other DIEs. */
9549 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
9552 /* Don't bother trying to generate any DIEs to represent any of the
9553 normal built-in types for the language we are compiling. */
9554 if (DECL_SOURCE_LINE (decl) == 0)
9556 /* OK, we need to generate one for `bool' so GDB knows what type
9557 comparisons have. */
9558 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
9559 == DW_LANG_C_plus_plus)
9560 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
9561 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
9566 /* If we are in terse mode, don't generate any DIEs for types. */
9567 if (debug_info_level <= DINFO_LEVEL_TERSE)
9570 /* If we're a function-scope tag, initially use a parent of NULL;
9571 this will be fixed up in decls_for_scope. */
9572 if (decl_function_context (decl))
9581 gen_decl_die (decl, context_die);
9584 /* Output a marker (i.e. a label) for the beginning of the generated code for
9588 dwarf2out_begin_block (blocknum)
9589 register unsigned blocknum;
9591 function_section (current_function_decl);
9592 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
9595 /* Output a marker (i.e. a label) for the end of the generated code for a
9599 dwarf2out_end_block (blocknum)
9600 register unsigned blocknum;
9602 function_section (current_function_decl);
9603 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
9606 /* Returns nonzero if it is appropriate not to emit any debugging
9607 information for BLOCK, because it doesn't contain any instructions.
9609 Don't allow this for blocks with nested functions or local classes
9610 as we would end up with orphans, and in the presence of scheduling
9611 we may end up calling them anyway. */
9614 dwarf2out_ignore_block (block)
9618 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
9619 if (TREE_CODE (decl) == FUNCTION_DECL
9620 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
9625 /* Output a marker (i.e. a label) at a point in the assembly code which
9626 corresponds to a given source level label. */
9629 dwarf2out_label (insn)
9632 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9634 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9636 function_section (current_function_decl);
9637 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
9638 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
9639 (unsigned) INSN_UID (insn));
9643 /* Lookup a filename (in the list of filenames that we know about here in
9644 dwarf2out.c) and return its "index". The index of each (known) filename is
9645 just a unique number which is associated with only that one filename.
9646 We need such numbers for the sake of generating labels
9647 (in the .debug_sfnames section) and references to those
9648 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9649 If the filename given as an argument is not found in our current list,
9650 add it to the list and assign it the next available unique index number.
9651 In order to speed up searches, we remember the index of the filename
9652 was looked up last. This handles the majority of all searches. */
9655 lookup_filename (file_name)
9656 const char *file_name;
9658 static unsigned last_file_lookup_index = 0;
9659 register unsigned i;
9661 /* Check to see if the file name that was searched on the previous call
9662 matches this file name. If so, return the index. */
9663 if (last_file_lookup_index != 0)
9664 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
9665 return last_file_lookup_index;
9667 /* Didn't match the previous lookup, search the table */
9668 for (i = 1; i < file_table_in_use; ++i)
9669 if (strcmp (file_name, file_table[i]) == 0)
9671 last_file_lookup_index = i;
9675 /* Prepare to add a new table entry by making sure there is enough space in
9676 the table to do so. If not, expand the current table. */
9677 if (file_table_in_use == file_table_allocated)
9679 file_table_allocated += FILE_TABLE_INCREMENT;
9681 = (char **) xrealloc (file_table,
9682 file_table_allocated * sizeof (char *));
9685 /* Add the new entry to the end of the filename table. */
9686 file_table[file_table_in_use] = xstrdup (file_name);
9687 last_file_lookup_index = file_table_in_use++;
9689 return last_file_lookup_index;
9692 /* Output a label to mark the beginning of a source code line entry
9693 and record information relating to this source line, in
9694 'line_info_table' for later output of the .debug_line section. */
9697 dwarf2out_line (filename, line)
9698 register const char *filename;
9699 register unsigned line;
9701 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9703 function_section (current_function_decl);
9705 if (DWARF2_ASM_LINE_DEBUG_INFO)
9707 static const char *lastfile;
9709 /* Emit the .file and .loc directives understood by GNU as. */
9710 if (lastfile == 0 || strcmp (filename, lastfile))
9713 ggc_add_string_root ((char **) &lastfile, 1);
9715 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
9716 lastfile = filename;
9719 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
9721 /* Indicate that line number info exists. */
9722 ++line_info_table_in_use;
9724 /* Indicate that multiple line number tables exist. */
9725 if (DECL_SECTION_NAME (current_function_decl))
9726 ++separate_line_info_table_in_use;
9728 else if (DECL_SECTION_NAME (current_function_decl))
9730 register dw_separate_line_info_ref line_info;
9731 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
9732 separate_line_info_table_in_use);
9734 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9735 fputc ('\n', asm_out_file);
9737 /* expand the line info table if necessary */
9738 if (separate_line_info_table_in_use
9739 == separate_line_info_table_allocated)
9741 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9742 separate_line_info_table
9743 = (dw_separate_line_info_ref)
9744 xrealloc (separate_line_info_table,
9745 separate_line_info_table_allocated
9746 * sizeof (dw_separate_line_info_entry));
9749 /* Add the new entry at the end of the line_info_table. */
9751 = &separate_line_info_table[separate_line_info_table_in_use++];
9752 line_info->dw_file_num = lookup_filename (filename);
9753 line_info->dw_line_num = line;
9754 line_info->function = current_funcdef_number;
9758 register dw_line_info_ref line_info;
9760 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
9761 line_info_table_in_use);
9763 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9764 fputc ('\n', asm_out_file);
9766 /* Expand the line info table if necessary. */
9767 if (line_info_table_in_use == line_info_table_allocated)
9769 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9771 = (dw_line_info_ref)
9772 xrealloc (line_info_table,
9773 (line_info_table_allocated
9774 * sizeof (dw_line_info_entry)));
9777 /* Add the new entry at the end of the line_info_table. */
9778 line_info = &line_info_table[line_info_table_in_use++];
9779 line_info->dw_file_num = lookup_filename (filename);
9780 line_info->dw_line_num = line;
9785 /* Record the beginning of a new source file, for later output
9786 of the .debug_macinfo section. At present, unimplemented. */
9789 dwarf2out_start_source_file (filename)
9790 register const char *filename ATTRIBUTE_UNUSED;
9794 /* Record the end of a source file, for later output
9795 of the .debug_macinfo section. At present, unimplemented. */
9798 dwarf2out_end_source_file ()
9802 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9803 the tail part of the directive line, i.e. the part which is past the
9804 initial whitespace, #, whitespace, directive-name, whitespace part. */
9807 dwarf2out_define (lineno, buffer)
9808 register unsigned lineno ATTRIBUTE_UNUSED;
9809 register const char *buffer ATTRIBUTE_UNUSED;
9811 static int initialized = 0;
9814 dwarf2out_start_source_file (primary_filename);
9819 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9820 the tail part of the directive line, i.e. the part which is past the
9821 initial whitespace, #, whitespace, directive-name, whitespace part. */
9824 dwarf2out_undef (lineno, buffer)
9825 register unsigned lineno ATTRIBUTE_UNUSED;
9826 register const char *buffer ATTRIBUTE_UNUSED;
9830 /* Set up for Dwarf output at the start of compilation. */
9833 dwarf2out_init (asm_out_file, main_input_filename)
9834 register FILE *asm_out_file;
9835 register const char *main_input_filename;
9837 /* Remember the name of the primary input file. */
9838 primary_filename = main_input_filename;
9840 /* Allocate the initial hunk of the file_table. */
9841 file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
9842 file_table_allocated = FILE_TABLE_INCREMENT;
9844 /* Skip the first entry - file numbers begin at 1. */
9845 file_table_in_use = 1;
9847 /* Allocate the initial hunk of the decl_die_table. */
9849 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
9850 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
9851 decl_die_table_in_use = 0;
9853 /* Allocate the initial hunk of the decl_scope_table. */
9855 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
9856 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
9857 decl_scope_depth = 0;
9859 /* Allocate the initial hunk of the abbrev_die_table. */
9861 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
9862 sizeof (dw_die_ref));
9863 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
9864 /* Zero-th entry is allocated, but unused */
9865 abbrev_die_table_in_use = 1;
9867 /* Allocate the initial hunk of the line_info_table. */
9869 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
9870 sizeof (dw_line_info_entry));
9871 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
9872 /* Zero-th entry is allocated, but unused */
9873 line_info_table_in_use = 1;
9875 /* Generate the initial DIE for the .debug section. Note that the (string)
9876 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9877 will (typically) be a relative pathname and that this pathname should be
9878 taken as being relative to the directory from which the compiler was
9879 invoked when the given (base) source file was compiled. */
9880 comp_unit_die = gen_compile_unit_die (main_input_filename);
9884 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
9885 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
9888 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
9889 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
9890 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9891 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
9893 strcpy (text_section_label, stripattributes (TEXT_SECTION));
9894 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
9895 DEBUG_INFO_SECTION_LABEL, 0);
9896 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
9897 DEBUG_LINE_SECTION_LABEL, 0);
9899 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9900 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
9901 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9903 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9904 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
9906 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9907 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
9908 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9909 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
9912 /* Output stuff that dwarf requires at the end of every file,
9913 and generate the DWARF-2 debugging info. */
9918 limbo_die_node *node, *next_node;
9921 /* Traverse the limbo die list, and add parent/child links. The only
9922 dies without parents that should be here are concrete instances of
9923 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9924 For concrete instances, we can get the parent die from the abstract
9926 for (node = limbo_die_list; node; node = next_node)
9928 next_node = node->next;
9931 if (die->die_parent == NULL)
9933 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
9935 add_child_die (origin->die_parent, die);
9936 else if (die == comp_unit_die)
9943 limbo_die_list = NULL;
9945 /* Walk through the list of incomplete types again, trying once more to
9946 emit full debugging info for them. */
9947 retry_incomplete_types ();
9949 /* Traverse the DIE's, reverse their lists of attributes and children,
9950 and add add sibling attributes to those DIE's that have children. */
9951 add_sibling_attributes (comp_unit_die);
9953 /* Output a terminator label for the .text section. */
9954 fputc ('\n', asm_out_file);
9955 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9956 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
9959 /* Output a terminator label for the .data section. */
9960 fputc ('\n', asm_out_file);
9961 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
9962 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
9964 /* Output a terminator label for the .bss section. */
9965 fputc ('\n', asm_out_file);
9966 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
9967 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
9970 /* Output the source line correspondence table. */
9971 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
9973 if (! DWARF2_ASM_LINE_DEBUG_INFO)
9975 fputc ('\n', asm_out_file);
9976 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9977 output_line_info ();
9980 /* We can only use the low/high_pc attributes if all of the code
9982 if (separate_line_info_table_in_use == 0)
9984 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
9985 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
9988 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
9989 debug_line_section_label);
9992 #if 0 /* unimplemented */
9993 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
9994 add_AT_unsigned (die, DW_AT_macro_info, 0);
9997 /* Output the abbreviation table. */
9998 fputc ('\n', asm_out_file);
9999 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
10000 build_abbrev_table (comp_unit_die);
10001 output_abbrev_section ();
10003 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10004 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
10005 calc_die_sizes (comp_unit_die);
10007 /* Output debugging information. */
10008 fputc ('\n', asm_out_file);
10009 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
10010 output_compilation_unit_header ();
10011 output_die (comp_unit_die);
10013 if (pubname_table_in_use)
10015 /* Output public names table. */
10016 fputc ('\n', asm_out_file);
10017 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
10018 output_pubnames ();
10021 /* We only put functions in the arange table, so don't write it out if
10022 we don't have any. */
10023 if (fde_table_in_use)
10025 /* Output the address range information. */
10026 fputc ('\n', asm_out_file);
10027 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
10031 #endif /* DWARF2_DEBUGGING_INFO */