1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com). Derived from the
4 DWARF 1 implementation written by Ron Guilmette (rfg@monkeys.com).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
26 /* The first part of this file deals with the DWARF 2 frame unwind
27 information, which is also used by the GCC efficient exception handling
28 mechanism. The second part, controlled only by an #ifdef
29 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
32 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
40 #include "hard-reg-set.h"
42 #include "insn-config.h"
48 /* #define NDEBUG 1 */
55 /* How to start an assembler comment. */
56 #ifndef ASM_COMMENT_START
57 #define ASM_COMMENT_START ";#"
60 typedef struct dw_cfi_struct *dw_cfi_ref;
61 typedef struct dw_fde_struct *dw_fde_ref;
62 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
64 /* Call frames are described using a sequence of Call Frame
65 Information instructions. The register number, offset
66 and address fields are provided as possible operands;
67 their use is selected by the opcode field. */
69 typedef union dw_cfi_oprnd_struct
71 unsigned long dw_cfi_reg_num;
72 long int dw_cfi_offset;
77 typedef struct dw_cfi_struct
79 dw_cfi_ref dw_cfi_next;
80 enum dwarf_call_frame_info dw_cfi_opc;
81 dw_cfi_oprnd dw_cfi_oprnd1;
82 dw_cfi_oprnd dw_cfi_oprnd2;
86 /* All call frame descriptions (FDE's) in the GCC generated DWARF
87 refer to a single Common Information Entry (CIE), defined at
88 the beginning of the .debug_frame section. This used of a single
89 CIE obviates the need to keep track of multiple CIE's
90 in the DWARF generation routines below. */
92 typedef struct dw_fde_struct
95 char *dw_fde_current_label;
97 dw_cfi_ref dw_fde_cfi;
101 /* Maximum size (in bytes) of an artificially generated label. */
102 #define MAX_ARTIFICIAL_LABEL_BYTES 30
104 /* Make sure we know the sizes of the various types dwarf can describe. These
105 are only defaults. If the sizes are different for your target, you should
106 override these values by defining the appropriate symbols in your tm.h
109 #ifndef CHAR_TYPE_SIZE
110 #define CHAR_TYPE_SIZE BITS_PER_UNIT
113 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
116 /* The size in bytes of a DWARF field indicating an offset or length
117 relative to a debug info section, specified to be 4 bytes in the DWARF-2
118 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
120 #ifndef DWARF_OFFSET_SIZE
121 #define DWARF_OFFSET_SIZE 4
124 #define DWARF_VERSION 2
126 /* Round SIZE up to the nearest BOUNDARY. */
127 #define DWARF_ROUND(SIZE,BOUNDARY) \
128 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
130 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
131 #ifdef STACK_GROWS_DOWNWARD
132 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
134 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
137 /* A pointer to the base of a table that contains frame description
138 information for each routine. */
139 static dw_fde_ref fde_table;
141 /* Number of elements currently allocated for fde_table. */
142 static unsigned fde_table_allocated;
144 /* Number of elements in fde_table currently in use. */
145 static unsigned fde_table_in_use;
147 /* Size (in elements) of increments by which we may expand the
149 #define FDE_TABLE_INCREMENT 256
151 /* A list of call frame insns for the CIE. */
152 static dw_cfi_ref cie_cfi_head;
154 /* The number of the current function definition for which debugging
155 information is being generated. These numbers range from 1 up to the
156 maximum number of function definitions contained within the current
157 compilation unit. These numbers are used to create unique label id's
158 unique to each function definition. */
159 static unsigned current_funcdef_number = 0;
161 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
162 attribute that accelerates the lookup of the FDE associated
163 with the subprogram. This variable holds the table index of the FDE
164 associated with the current function (body) definition. */
165 static unsigned current_funcdef_fde;
167 /* Forward declarations for functions defined in this file. */
169 static char *stripattributes PROTO((char *));
170 static char *dwarf_cfi_name PROTO((unsigned));
171 static dw_cfi_ref new_cfi PROTO((void));
172 static void add_cfi PROTO((dw_cfi_ref *, dw_cfi_ref));
173 static unsigned long size_of_uleb128 PROTO((unsigned long));
174 static unsigned long size_of_sleb128 PROTO((long));
175 static void output_uleb128 PROTO((unsigned long));
176 static void output_sleb128 PROTO((long));
177 char *dwarf2out_cfi_label PROTO((void));
178 static void add_fde_cfi PROTO((char *, dw_cfi_ref));
179 static void lookup_cfa_1 PROTO((dw_cfi_ref, unsigned long *,
181 static void lookup_cfa PROTO((unsigned long *, long *));
182 static void reg_save PROTO((char *, unsigned, unsigned,
184 static void initial_return_save PROTO((rtx));
185 static void output_cfi PROTO((dw_cfi_ref, dw_fde_ref));
186 static void output_call_frame_info PROTO((int));
187 static unsigned reg_number PROTO((rtx));
189 /* Definitions of defaults for assembler-dependent names of various
190 pseudo-ops and section names.
191 Theses may be overridden in the tm.h file (if necessary) for a particular
194 #ifndef UNALIGNED_SHORT_ASM_OP
195 #define UNALIGNED_SHORT_ASM_OP ".2byte"
197 #ifndef UNALIGNED_INT_ASM_OP
198 #define UNALIGNED_INT_ASM_OP ".4byte"
200 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
201 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
204 #define ASM_BYTE_OP ".byte"
207 #ifndef UNALIGNED_OFFSET_ASM_OP
208 #define UNALIGNED_OFFSET_ASM_OP \
209 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
212 #ifndef UNALIGNED_WORD_ASM_OP
213 #define UNALIGNED_WORD_ASM_OP \
214 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
217 /* Data and reference forms for relocatable data. */
218 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
219 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
221 /* Pseudo-op for defining a new section. */
222 #ifndef SECTION_ASM_OP
223 #define SECTION_ASM_OP ".section"
226 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
227 print the SECTION_ASM_OP and the section name. The default here works for
228 almost all svr4 assemblers, except for the sparc, where the section name
229 must be enclosed in double quotes. (See sparcv4.h). */
230 #ifndef SECTION_FORMAT
231 #ifdef PUSHSECTION_FORMAT
232 #define SECTION_FORMAT PUSHSECTION_FORMAT
234 #define SECTION_FORMAT "\t%s\t%s\n"
238 #ifndef FRAME_SECTION
239 #define FRAME_SECTION ".debug_frame"
241 #if !defined (EH_FRAME_SECTION) && defined (ASM_OUTPUT_SECTION_NAME)
242 #define EH_FRAME_SECTION ".eh_frame"
245 #ifndef FUNC_BEGIN_LABEL
246 #define FUNC_BEGIN_LABEL "LFB"
248 #ifndef FUNC_END_LABEL
249 #define FUNC_END_LABEL "LFE"
251 #define CIE_AFTER_SIZE_LABEL "LSCIE"
252 #define CIE_END_LABEL "LECIE"
253 #define FDE_AFTER_SIZE_LABEL "LSFDE"
254 #define FDE_END_LABEL "LEFDE"
256 /* Definitions of defaults for various types of primitive assembly language
257 output operations. These may be overridden from within the tm.h file,
258 but typically, that is unecessary. */
260 #ifndef ASM_OUTPUT_SECTION
261 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
262 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
265 #ifndef ASM_OUTPUT_DWARF_DELTA2
266 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
267 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
268 assemble_name (FILE, LABEL1); \
269 fprintf (FILE, "-"); \
270 assemble_name (FILE, LABEL2); \
274 #ifndef ASM_OUTPUT_DWARF_DELTA4
275 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
276 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
277 assemble_name (FILE, LABEL1); \
278 fprintf (FILE, "-"); \
279 assemble_name (FILE, LABEL2); \
283 #ifndef ASM_OUTPUT_DWARF_DELTA
284 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
285 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
286 assemble_name (FILE, LABEL1); \
287 fprintf (FILE, "-"); \
288 assemble_name (FILE, LABEL2); \
292 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
293 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
294 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
295 assemble_name (FILE, LABEL1); \
296 fprintf (FILE, "-"); \
297 assemble_name (FILE, LABEL2); \
301 #ifndef ASM_OUTPUT_DWARF_ADDR
302 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
303 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
304 assemble_name (FILE, LABEL); \
308 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
309 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
310 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
313 #ifndef ASM_OUTPUT_DWARF_OFFSET
314 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
315 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
316 assemble_name (FILE, LABEL); \
320 #ifndef ASM_OUTPUT_DWARF_DATA1
321 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
322 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
325 #ifndef ASM_OUTPUT_DWARF_DATA2
326 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
327 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
330 #ifndef ASM_OUTPUT_DWARF_DATA4
331 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
332 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
335 #ifndef ASM_OUTPUT_DWARF_DATA
336 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
337 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
338 (unsigned long) VALUE)
341 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
342 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
343 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
344 (unsigned long) VALUE)
347 #ifndef ASM_OUTPUT_DWARF_DATA8
348 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
350 if (WORDS_BIG_ENDIAN) \
352 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
353 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
357 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
358 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
363 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
364 newline is produced. When flag_verbose_asm is asserted, we add commnetary
365 at the end of the line, so we must avoid output of a newline here. */
366 #ifndef ASM_OUTPUT_DWARF_STRING
367 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
369 register int slen = strlen(P); \
370 register char *p = (P); \
372 fprintf (FILE, "\t.ascii \""); \
373 for (i = 0; i < slen; i++) \
375 register int c = p[i]; \
376 if (c == '\"' || c == '\\') \
378 if (c >= ' ' && c < 0177) \
382 fprintf (FILE, "\\%o", c); \
385 fprintf (FILE, "\\0\""); \
390 /* The DWARF 2 CFA column which tracks the return address. Normally this
391 is the column for PC, or the first column after all of the hard
393 #ifndef DWARF_FRAME_RETURN_COLUMN
395 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
397 #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER
401 /* The mapping from gcc register number to DWARF 2 CFA column number. By
402 default, we just provide columns for all registers. */
403 #ifndef DWARF_FRAME_REGNUM
404 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
407 /* The offset from the incoming value of %sp to the top of the stack frame
408 for the current function. */
409 #ifndef INCOMING_FRAME_SP_OFFSET
410 #define INCOMING_FRAME_SP_OFFSET 0
413 /* Return a pointer to a copy of the section string name S with all
414 attributes stripped off. */
420 char *stripped = xstrdup (s);
423 while (*p && *p != ',')
430 /* Return the register number described by a given RTL node. */
436 register unsigned regno = REGNO (rtl);
438 if (regno >= FIRST_PSEUDO_REGISTER)
440 warning ("internal regno botch: regno = %d\n", regno);
444 regno = DBX_REGISTER_NUMBER (regno);
448 /* Convert a DWARF call frame info. operation to its string name */
451 dwarf_cfi_name (cfi_opc)
452 register unsigned cfi_opc;
456 case DW_CFA_advance_loc:
457 return "DW_CFA_advance_loc";
459 return "DW_CFA_offset";
461 return "DW_CFA_restore";
465 return "DW_CFA_set_loc";
466 case DW_CFA_advance_loc1:
467 return "DW_CFA_advance_loc1";
468 case DW_CFA_advance_loc2:
469 return "DW_CFA_advance_loc2";
470 case DW_CFA_advance_loc4:
471 return "DW_CFA_advance_loc4";
472 case DW_CFA_offset_extended:
473 return "DW_CFA_offset_extended";
474 case DW_CFA_restore_extended:
475 return "DW_CFA_restore_extended";
476 case DW_CFA_undefined:
477 return "DW_CFA_undefined";
478 case DW_CFA_same_value:
479 return "DW_CFA_same_value";
480 case DW_CFA_register:
481 return "DW_CFA_register";
482 case DW_CFA_remember_state:
483 return "DW_CFA_remember_state";
484 case DW_CFA_restore_state:
485 return "DW_CFA_restore_state";
487 return "DW_CFA_def_cfa";
488 case DW_CFA_def_cfa_register:
489 return "DW_CFA_def_cfa_register";
490 case DW_CFA_def_cfa_offset:
491 return "DW_CFA_def_cfa_offset";
493 /* SGI/MIPS specific */
494 case DW_CFA_MIPS_advance_loc8:
495 return "DW_CFA_MIPS_advance_loc8";
498 case DW_CFA_GNU_window_save:
499 return "DW_CFA_GNU_window_save";
502 return "DW_CFA_<unknown>";
506 /* Return a pointer to a newly allocated Call Frame Instruction. */
508 static inline dw_cfi_ref
511 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
513 cfi->dw_cfi_next = NULL;
514 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
515 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
520 /* Add a Call Frame Instruction to list of instructions. */
523 add_cfi (list_head, cfi)
524 register dw_cfi_ref *list_head;
525 register dw_cfi_ref cfi;
527 register dw_cfi_ref *p;
529 /* Find the end of the chain. */
530 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
536 /* Generate a new label for the CFI info to refer to. */
539 dwarf2out_cfi_label ()
541 static char label[20];
542 static unsigned long label_num = 0;
544 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
545 ASM_OUTPUT_LABEL (asm_out_file, label);
550 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
551 or to the CIE if LABEL is NULL. */
554 add_fde_cfi (label, cfi)
555 register char *label;
556 register dw_cfi_ref cfi;
560 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
563 label = dwarf2out_cfi_label ();
565 if (fde->dw_fde_current_label == NULL
566 || strcmp (label, fde->dw_fde_current_label) != 0)
568 register dw_cfi_ref xcfi;
570 fde->dw_fde_current_label = label = xstrdup (label);
572 /* Set the location counter to the new label. */
574 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
575 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
576 add_cfi (&fde->dw_fde_cfi, xcfi);
579 add_cfi (&fde->dw_fde_cfi, cfi);
583 add_cfi (&cie_cfi_head, cfi);
586 /* Subroutine of lookup_cfa. */
589 lookup_cfa_1 (cfi, regp, offsetp)
590 register dw_cfi_ref cfi;
591 register unsigned long *regp;
592 register long *offsetp;
594 switch (cfi->dw_cfi_opc)
596 case DW_CFA_def_cfa_offset:
597 *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
599 case DW_CFA_def_cfa_register:
600 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
603 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
604 *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
609 /* Find the previous value for the CFA. */
612 lookup_cfa (regp, offsetp)
613 register unsigned long *regp;
614 register long *offsetp;
616 register dw_cfi_ref cfi;
618 *regp = (unsigned long) -1;
621 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
622 lookup_cfa_1 (cfi, regp, offsetp);
624 if (fde_table_in_use)
626 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
627 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
628 lookup_cfa_1 (cfi, regp, offsetp);
632 /* The current rule for calculating the DWARF2 canonical frame address. */
633 static unsigned long cfa_reg;
634 static long cfa_offset;
636 /* The register used for saving registers to the stack, and its offset
638 static unsigned cfa_store_reg;
639 static long cfa_store_offset;
641 /* Entry point to update the canonical frame address (CFA).
642 LABEL is passed to add_fde_cfi. The value of CFA is now to be
643 calculated from REG+OFFSET. */
646 dwarf2out_def_cfa (label, reg, offset)
647 register char *label;
648 register unsigned reg;
649 register long offset;
651 register dw_cfi_ref cfi;
652 unsigned long old_reg;
657 if (cfa_store_reg == reg)
658 cfa_store_offset = offset;
660 reg = DWARF_FRAME_REGNUM (reg);
661 lookup_cfa (&old_reg, &old_offset);
663 if (reg == old_reg && offset == old_offset)
670 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
671 cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
674 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
675 else if (offset == old_offset && old_reg != (unsigned long) -1)
677 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
678 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
684 cfi->dw_cfi_opc = DW_CFA_def_cfa;
685 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
686 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
689 add_fde_cfi (label, cfi);
692 /* Add the CFI for saving a register. REG is the CFA column number.
693 LABEL is passed to add_fde_cfi.
694 If SREG is -1, the register is saved at OFFSET from the CFA;
695 otherwise it is saved in SREG. */
698 reg_save (label, reg, sreg, offset)
699 register char * label;
700 register unsigned reg;
701 register unsigned sreg;
702 register long offset;
704 register dw_cfi_ref cfi = new_cfi ();
706 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
711 /* The register number won't fit in 6 bits, so we have to use
713 cfi->dw_cfi_opc = DW_CFA_offset_extended;
715 cfi->dw_cfi_opc = DW_CFA_offset;
717 offset /= DWARF_CIE_DATA_ALIGNMENT;
718 assert (offset >= 0);
719 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
723 cfi->dw_cfi_opc = DW_CFA_register;
724 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
727 add_fde_cfi (label, cfi);
730 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
731 This CFI tells the unwinder that it needs to restore the window registers
732 from the previous frame's window save area.
734 ??? Perhaps we should note in the CIE where windows are saved (instead of
735 assuming 0(cfa)) and what registers are in the window. */
738 dwarf2out_window_save (label)
739 register char * label;
741 register dw_cfi_ref cfi = new_cfi ();
742 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
743 add_fde_cfi (label, cfi);
746 /* Entry point for saving a register to the stack. REG is the GCC register
747 number. LABEL and OFFSET are passed to reg_save. */
750 dwarf2out_reg_save (label, reg, offset)
751 register char * label;
752 register unsigned reg;
753 register long offset;
755 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
758 /* Entry point for saving the return address in the stack.
759 LABEL and OFFSET are passed to reg_save. */
762 dwarf2out_return_save (label, offset)
763 register char * label;
764 register long offset;
766 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
769 /* Entry point for saving the return address in a register.
770 LABEL and SREG are passed to reg_save. */
773 dwarf2out_return_reg (label, sreg)
774 register char * label;
775 register unsigned sreg;
777 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
780 /* Record the initial position of the return address. RTL is
781 INCOMING_RETURN_ADDR_RTX. */
784 initial_return_save (rtl)
790 switch (GET_CODE (rtl))
793 /* RA is in a register. */
794 reg = reg_number (rtl);
797 /* RA is on the stack. */
799 switch (GET_CODE (rtl))
802 assert (REGNO (rtl) == STACK_POINTER_REGNUM);
806 assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
807 offset = INTVAL (XEXP (rtl, 1));
810 assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
811 offset = -INTVAL (XEXP (rtl, 1));
818 /* The return address is at some offset from any value we can
819 actually load. For instance, on the SPARC it is in %i7+8. Just
820 ignore the offset for now; it doesn't matter for unwinding frames. */
821 assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
822 initial_return_save (XEXP (rtl, 0));
828 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset);
831 /* Record call frame debugging information for INSN, which either
832 sets SP or FP (adjusting how we calculate the frame address) or saves a
833 register to the stack. If INSN is NULL_RTX, initialize our state. */
836 dwarf2out_frame_debug (insn)
843 /* A temporary register used in adjusting SP or setting up the store_reg. */
844 static unsigned cfa_temp_reg;
845 static long cfa_temp_value;
847 if (insn == NULL_RTX)
849 /* Set up state for generating call frame debug info. */
850 lookup_cfa (&cfa_reg, &cfa_offset);
851 assert (cfa_reg == DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
852 cfa_reg = STACK_POINTER_REGNUM;
853 cfa_store_reg = cfa_reg;
854 cfa_store_offset = cfa_offset;
860 label = dwarf2out_cfi_label ();
862 insn = PATTERN (insn);
863 assert (GET_CODE (insn) == SET);
865 src = SET_SRC (insn);
866 dest = SET_DEST (insn);
868 switch (GET_CODE (dest))
871 /* Update the CFA rule wrt SP or FP. Make sure src is
872 relative to the current CFA register. */
873 switch (GET_CODE (src))
875 /* Setting FP from SP. */
877 assert (cfa_reg == REGNO (src));
878 assert (REGNO (dest) == STACK_POINTER_REGNUM
879 || (frame_pointer_needed
880 && REGNO (dest) == HARD_FRAME_POINTER_REGNUM));
881 cfa_reg = REGNO (dest);
886 if (dest == stack_pointer_rtx)
889 switch (GET_CODE (XEXP (src, 1)))
892 offset = INTVAL (XEXP (src, 1));
895 assert (REGNO (XEXP (src, 1)) == cfa_temp_reg);
896 offset = cfa_temp_value;
902 if (GET_CODE (src) == PLUS)
904 if (cfa_reg == STACK_POINTER_REGNUM)
905 cfa_offset += offset;
906 if (cfa_store_reg == STACK_POINTER_REGNUM)
907 cfa_store_offset += offset;
908 assert (XEXP (src, 0) == stack_pointer_rtx);
912 /* Initializing the store base register. */
913 assert (GET_CODE (src) == PLUS);
914 assert (XEXP (src, 1) == stack_pointer_rtx);
915 assert (GET_CODE (XEXP (src, 0)) == REG
916 && REGNO (XEXP (src, 0)) == cfa_temp_reg);
917 assert (cfa_store_reg == STACK_POINTER_REGNUM);
918 cfa_store_reg = REGNO (dest);
919 cfa_store_offset -= cfa_temp_value;
924 cfa_temp_reg = REGNO (dest);
925 cfa_temp_value = INTVAL (src);
929 assert (GET_CODE (XEXP (src, 0)) == REG
930 && REGNO (XEXP (src, 0)) == cfa_temp_reg);
931 assert (REGNO (dest) == cfa_temp_reg);
932 assert (GET_CODE (XEXP (src, 1)) == CONST_INT);
933 cfa_temp_value |= INTVAL (XEXP (src, 1));
939 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
943 /* Saving a register to the stack. Make sure dest is relative to the
945 assert (GET_CODE (src) == REG);
946 switch (GET_CODE (XEXP (dest, 0)))
951 offset = GET_MODE_SIZE (GET_MODE (dest));
952 if (GET_CODE (src) == PRE_INC)
955 assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM);
956 assert (cfa_store_reg == STACK_POINTER_REGNUM);
957 cfa_store_offset += offset;
958 if (cfa_reg == STACK_POINTER_REGNUM)
959 cfa_offset = cfa_store_offset;
961 offset = -cfa_store_offset;
964 /* With an offset. */
967 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
968 if (GET_CODE (src) == MINUS)
971 assert (cfa_store_reg == REGNO (XEXP (XEXP (dest, 0), 0)));
972 offset -= cfa_store_offset;
978 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
979 dwarf2out_reg_save (label, REGNO (src), offset);
987 /* Return the size of an unsigned LEB128 quantity. */
989 static inline unsigned long
990 size_of_uleb128 (value)
991 register unsigned long value;
993 register unsigned long size = 0;
994 register unsigned byte;
998 byte = (value & 0x7f);
1007 /* Return the size of a signed LEB128 quantity. */
1009 static inline unsigned long
1010 size_of_sleb128 (value)
1011 register long value;
1013 register unsigned long size = 0;
1014 register unsigned byte;
1018 byte = (value & 0x7f);
1022 while (!(((value == 0) && ((byte & 0x40) == 0))
1023 || ((value == -1) && ((byte & 0x40) != 0))));
1028 /* Output an unsigned LEB128 quantity. */
1031 output_uleb128 (value)
1032 register unsigned long value;
1034 unsigned long save_value = value;
1036 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1039 register unsigned byte = (value & 0x7f);
1042 /* More bytes to follow. */
1045 fprintf (asm_out_file, "0x%x", byte);
1047 fprintf (asm_out_file, ",");
1051 if (flag_verbose_asm)
1052 fprintf (asm_out_file, "\t%s ULEB128 0x%x", ASM_COMMENT_START, save_value);
1055 /* Output an signed LEB128 quantity. */
1058 output_sleb128 (value)
1059 register long value;
1062 register unsigned byte;
1063 long save_value = value;
1065 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1068 byte = (value & 0x7f);
1069 /* arithmetic shift */
1071 more = !((((value == 0) && ((byte & 0x40) == 0))
1072 || ((value == -1) && ((byte & 0x40) != 0))));
1076 fprintf (asm_out_file, "0x%x", byte);
1078 fprintf (asm_out_file, ",");
1082 if (flag_verbose_asm)
1083 fprintf (asm_out_file, "\t%s SLEB128 %d", ASM_COMMENT_START, save_value);
1086 /* Output a Call Frame Information opcode and its operand(s). */
1089 output_cfi (cfi, fde)
1090 register dw_cfi_ref cfi;
1091 register dw_fde_ref fde;
1093 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1095 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1097 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1098 if (flag_verbose_asm)
1099 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%x",
1100 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1101 fputc ('\n', asm_out_file);
1104 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1106 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1108 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1109 if (flag_verbose_asm)
1110 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%x",
1111 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1113 fputc ('\n', asm_out_file);
1114 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1115 fputc ('\n', asm_out_file);
1117 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1119 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1121 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1122 if (flag_verbose_asm)
1123 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%x",
1124 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1126 fputc ('\n', asm_out_file);
1130 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1131 if (flag_verbose_asm)
1132 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1133 dwarf_cfi_name (cfi->dw_cfi_opc));
1135 fputc ('\n', asm_out_file);
1136 switch (cfi->dw_cfi_opc)
1138 case DW_CFA_set_loc:
1139 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1140 fputc ('\n', asm_out_file);
1142 case DW_CFA_advance_loc1:
1143 /* TODO: not currently implemented. */
1146 case DW_CFA_advance_loc2:
1147 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1148 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1149 fde->dw_fde_current_label);
1150 fputc ('\n', asm_out_file);
1151 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1153 case DW_CFA_advance_loc4:
1154 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1155 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1156 fde->dw_fde_current_label);
1157 fputc ('\n', asm_out_file);
1158 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1160 #ifdef MIPS_DEBUGGING_INFO
1161 case DW_CFA_MIPS_advance_loc8:
1162 /* TODO: not currently implemented. */
1166 case DW_CFA_offset_extended:
1167 case DW_CFA_def_cfa:
1168 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1169 fputc ('\n', asm_out_file);
1170 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1171 fputc ('\n', asm_out_file);
1173 case DW_CFA_restore_extended:
1174 case DW_CFA_undefined:
1175 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1176 fputc ('\n', asm_out_file);
1178 case DW_CFA_same_value:
1179 case DW_CFA_def_cfa_register:
1180 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1181 fputc ('\n', asm_out_file);
1183 case DW_CFA_register:
1184 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1185 fputc ('\n', asm_out_file);
1186 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1187 fputc ('\n', asm_out_file);
1189 case DW_CFA_def_cfa_offset:
1190 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1191 fputc ('\n', asm_out_file);
1193 case DW_CFA_GNU_window_save:
1201 /* Output the call frame information used to used to record information
1202 that relates to calculating the frame pointer, and records the
1203 location of saved registers. */
1206 output_call_frame_info (for_eh)
1209 register unsigned long i, j;
1210 register dw_fde_ref fde;
1211 register unsigned long fde_size;
1212 register dw_cfi_ref cfi;
1213 unsigned long fde_pad;
1214 char l1[20], l2[20];
1216 /* Do we want to include a pointer to the exception table? */
1217 int eh_ptr = for_eh && exception_table_p ();
1219 /* Only output the info if it will be interesting. */
1220 for (i = 0; i < fde_table_in_use; ++i)
1221 if (fde_table[i].dw_fde_cfi != NULL)
1223 if (i == fde_table_in_use)
1226 fputc ('\n', asm_out_file);
1229 #ifdef EH_FRAME_SECTION
1230 ASM_OUTPUT_SECTION_NAME (asm_out_file, NULL_TREE, EH_FRAME_SECTION, 0);
1234 assemble_label ("__FRAME_BEGIN__");
1237 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1239 /* Output the CIE. */
1240 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1241 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1242 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1243 if (flag_verbose_asm)
1244 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1247 fputc ('\n', asm_out_file);
1248 ASM_OUTPUT_LABEL (asm_out_file, l1);
1250 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1251 if (flag_verbose_asm)
1252 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1254 fputc ('\n', asm_out_file);
1255 if (DWARF_OFFSET_SIZE == 8)
1257 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1258 fputc ('\n', asm_out_file);
1261 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1262 if (flag_verbose_asm)
1263 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1265 fputc ('\n', asm_out_file);
1268 /* The "z" augmentation was defined by SGI; the FDE contains a pointer
1269 to the exception region info for the frame. */
1270 ASM_OUTPUT_DWARF_STRING (asm_out_file, "z");
1271 if (flag_verbose_asm)
1272 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1276 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1277 if (flag_verbose_asm)
1278 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1282 fputc ('\n', asm_out_file);
1284 if (flag_verbose_asm)
1285 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1287 fputc ('\n', asm_out_file);
1288 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1289 if (flag_verbose_asm)
1290 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1292 fputc ('\n', asm_out_file);
1293 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1294 if (flag_verbose_asm)
1295 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1297 fputc ('\n', asm_out_file);
1301 if (flag_verbose_asm)
1302 fprintf (asm_out_file, "\t%s CIE augmentation fields length",
1304 fputc ('\n', asm_out_file);
1307 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1308 output_cfi (cfi, NULL);
1310 /* Pad the CIE out to an address sized boundary. */
1311 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1312 ASM_OUTPUT_LABEL (asm_out_file, l2);
1314 /* Loop through all of the FDE's. */
1315 for (i = 0; i < fde_table_in_use; ++i)
1317 fde = &fde_table[i];
1318 if (fde->dw_fde_cfi == NULL)
1321 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2);
1322 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2);
1323 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1324 if (flag_verbose_asm)
1325 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1326 fputc ('\n', asm_out_file);
1327 ASM_OUTPUT_LABEL (asm_out_file, l1);
1330 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__FRAME_BEGIN__");
1332 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1333 if (flag_verbose_asm)
1334 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1336 fputc ('\n', asm_out_file);
1337 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1338 if (flag_verbose_asm)
1339 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1341 fputc ('\n', asm_out_file);
1342 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1343 fde->dw_fde_end, fde->dw_fde_begin);
1344 if (flag_verbose_asm)
1345 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1347 fputc ('\n', asm_out_file);
1350 output_uleb128 (PTR_SIZE);
1351 if (flag_verbose_asm)
1352 fprintf (asm_out_file, "\t%s FDE augmentation fields length",
1354 fputc ('\n', asm_out_file);
1356 /* For now, a pointer to the translation unit's info will do.
1357 ??? Eventually this should point to the function's info. */
1358 if (exception_table_p ())
1359 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1361 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
1363 if (flag_verbose_asm)
1364 fprintf (asm_out_file, "\t%s pointer to exception region info",
1366 fputc ('\n', asm_out_file);
1369 /* Loop through the Call Frame Instructions associated with
1371 fde->dw_fde_current_label = fde->dw_fde_begin;
1372 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1373 output_cfi (cfi, fde);
1375 /* Pad the FDE out to an address sized boundary. */
1376 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1377 ASM_OUTPUT_LABEL (asm_out_file, l2);
1379 #ifndef EH_FRAME_SECTION
1382 /* Emit terminating zero for table. */
1383 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
1384 fputc ('\n', asm_out_file);
1387 #ifdef MIPS_DEBUGGING_INFO
1388 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1389 get a value of 0. Putting .align 0 after the label fixes it. */
1390 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1394 /* Decide whether we want to emit frame unwind information for the current
1395 translation unit. */
1398 dwarf2out_do_frame ()
1400 return (write_symbols == DWARF2_DEBUG
1401 || (flag_exceptions && ! exceptions_via_longjmp));
1404 /* Output a marker (i.e. a label) for the beginning of a function, before
1408 dwarf2out_begin_prologue ()
1410 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1411 register dw_fde_ref fde;
1413 ++current_funcdef_number;
1415 function_section (current_function_decl);
1416 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1417 current_funcdef_number);
1418 ASM_OUTPUT_LABEL (asm_out_file, label);
1420 /* Expand the fde table if necessary. */
1421 if (fde_table_in_use == fde_table_allocated)
1423 fde_table_allocated += FDE_TABLE_INCREMENT;
1425 = (dw_fde_ref) xrealloc (fde_table,
1426 fde_table_allocated * sizeof (dw_fde_node));
1429 /* Record the FDE associated with this function. */
1430 current_funcdef_fde = fde_table_in_use;
1432 /* Add the new FDE at the end of the fde_table. */
1433 fde = &fde_table[fde_table_in_use++];
1434 fde->dw_fde_begin = xstrdup (label);
1435 fde->dw_fde_current_label = NULL;
1436 fde->dw_fde_end = NULL;
1437 fde->dw_fde_cfi = NULL;
1440 /* Output a marker (i.e. a label) for the absolute end of the generated code
1441 for a function definition. This gets called *after* the epilogue code has
1445 dwarf2out_end_epilogue ()
1448 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1450 /* Output a label to mark the endpoint of the code generated for this
1452 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1453 ASM_OUTPUT_LABEL (asm_out_file, label);
1454 fde = &fde_table[fde_table_in_use - 1];
1455 fde->dw_fde_end = xstrdup (label);
1459 dwarf2out_frame_init ()
1461 /* Allocate the initial hunk of the fde_table. */
1463 = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1464 bzero ((char *) fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1465 fde_table_allocated = FDE_TABLE_INCREMENT;
1466 fde_table_in_use = 0;
1468 /* Generate the CFA instructions common to all FDE's. Do it now for the
1469 sake of lookup_cfa. */
1471 #ifdef DWARF2_UNWIND_INFO
1472 /* On entry, the Canonical Frame Address is at SP. */
1473 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1474 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1479 dwarf2out_frame_finish ()
1481 /* Output call frame information. */
1482 #ifdef MIPS_DEBUGGING_INFO
1483 if (write_symbols == DWARF2_DEBUG)
1484 output_call_frame_info (0);
1485 if (flag_exceptions && ! exceptions_via_longjmp)
1486 output_call_frame_info (1);
1488 if (write_symbols == DWARF2_DEBUG
1489 || (flag_exceptions && ! exceptions_via_longjmp))
1490 output_call_frame_info (1);
1494 #endif /* .debug_frame support */
1496 /* And now, the support for symbolic debugging information. */
1497 #ifdef DWARF2_DEBUGGING_INFO
1499 extern char *getpwd ();
1501 /* NOTE: In the comments in this file, many references are made to
1502 "Debugging Information Entries". This term is abbreviated as `DIE'
1503 throughout the remainder of this file. */
1505 /* An internal representation of the DWARF output is built, and then
1506 walked to generate the DWARF debugging info. The walk of the internal
1507 representation is done after the entire program has been compiled.
1508 The types below are used to describe the internal representation. */
1510 /* Each DIE may have a series of attribute/value pairs. Values
1511 can take on several forms. The forms that are used in this
1512 implementation are listed below. */
1519 dw_val_class_unsigned_const,
1520 dw_val_class_long_long,
1523 dw_val_class_die_ref,
1524 dw_val_class_fde_ref,
1525 dw_val_class_lbl_id,
1526 dw_val_class_section_offset,
1531 /* Various DIE's use offsets relative to the beginning of the
1532 .debug_info section to refer to each other. */
1534 typedef long int dw_offset;
1536 /* Define typedefs here to avoid circular dependencies. */
1538 typedef struct die_struct *dw_die_ref;
1539 typedef struct dw_attr_struct *dw_attr_ref;
1540 typedef struct dw_val_struct *dw_val_ref;
1541 typedef struct dw_line_info_struct *dw_line_info_ref;
1542 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
1543 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1544 typedef struct pubname_struct *pubname_ref;
1545 typedef dw_die_ref *arange_ref;
1547 /* Describe a double word constant value. */
1549 typedef struct dw_long_long_struct
1556 /* Describe a floating point constant value. */
1558 typedef struct dw_fp_struct
1565 /* Each entry in the line_info_table maintains the file and
1566 line nuber associated with the label generated for that
1567 entry. The label gives the PC value associated with
1568 the line number entry. */
1570 typedef struct dw_line_info_struct
1572 unsigned long dw_file_num;
1573 unsigned long dw_line_num;
1577 /* Line information for functions in separate sections; each one gets its
1579 typedef struct dw_separate_line_info_struct
1581 unsigned long dw_file_num;
1582 unsigned long dw_line_num;
1583 unsigned long function;
1585 dw_separate_line_info_entry;
1587 /* The dw_val_node describes an attibute's value, as it is
1588 represented internally. */
1590 typedef struct dw_val_struct
1592 dw_val_class val_class;
1596 dw_loc_descr_ref val_loc;
1598 long unsigned val_unsigned;
1599 dw_long_long_const val_long_long;
1600 dw_float_const val_float;
1601 dw_die_ref val_die_ref;
1602 unsigned val_fde_index;
1606 unsigned char val_flag;
1612 /* Locations in memory are described using a sequence of stack machine
1615 typedef struct dw_loc_descr_struct
1617 dw_loc_descr_ref dw_loc_next;
1618 enum dwarf_location_atom dw_loc_opc;
1619 dw_val_node dw_loc_oprnd1;
1620 dw_val_node dw_loc_oprnd2;
1624 /* Each DIE attribute has a field specifying the attribute kind,
1625 a link to the next attribute in the chain, and an attribute value.
1626 Attributes are typically linked below the DIE they modify. */
1628 typedef struct dw_attr_struct
1630 enum dwarf_attribute dw_attr;
1631 dw_attr_ref dw_attr_next;
1632 dw_val_node dw_attr_val;
1636 /* The Debugging Information Entry (DIE) structure */
1638 typedef struct die_struct
1640 enum dwarf_tag die_tag;
1641 dw_attr_ref die_attr;
1642 dw_attr_ref die_attr_last;
1643 dw_die_ref die_parent;
1644 dw_die_ref die_child;
1645 dw_die_ref die_child_last;
1647 dw_offset die_offset;
1648 unsigned long die_abbrev;
1652 /* The pubname structure */
1654 typedef struct pubname_struct
1661 /* The limbo die list structure. */
1662 typedef struct limbo_die_struct
1665 struct limbo_die_struct *next;
1669 /* How to start an assembler comment. */
1670 #ifndef ASM_COMMENT_START
1671 #define ASM_COMMENT_START ";#"
1674 /* Define a macro which returns non-zero for a TYPE_DECL which was
1675 implicitly generated for a tagged type.
1677 Note that unlike the gcc front end (which generates a NULL named
1678 TYPE_DECL node for each complete tagged type, each array type, and
1679 each function type node created) the g++ front end generates a
1680 _named_ TYPE_DECL node for each tagged type node created.
1681 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
1682 generate a DW_TAG_typedef DIE for them. */
1684 #define TYPE_DECL_IS_STUB(decl) \
1685 (DECL_NAME (decl) == NULL_TREE \
1686 || (DECL_ARTIFICIAL (decl) \
1687 && is_tagged_type (TREE_TYPE (decl)) \
1688 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
1689 /* This is necessary for stub decls that \
1690 appear in nested inline functions. */ \
1691 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
1692 && (decl_ultimate_origin (decl) \
1693 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
1695 /* Information concerning the compilation unit's programming
1696 language, and compiler version. */
1698 extern int flag_traditional;
1699 extern char *version_string;
1700 extern char *language_string;
1702 /* Fixed size portion of the DWARF compilation unit header. */
1703 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
1705 /* Fixed size portion of debugging line information prolog. */
1706 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
1708 /* Fixed size portion of public names info. */
1709 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
1711 /* Fixed size portion of the address range info. */
1712 #define DWARF_ARANGES_HEADER_SIZE \
1713 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
1715 /* Define the architecture-dependent minimum instruction length (in bytes).
1716 In this implementation of DWARF, this field is used for information
1717 purposes only. Since GCC generates assembly language, we have
1718 no a priori knowledge of how many instruction bytes are generated
1719 for each source line, and therefore can use only the DW_LNE_set_address
1720 and DW_LNS_fixed_advance_pc line information commands. */
1722 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
1723 #define DWARF_LINE_MIN_INSTR_LENGTH 4
1726 /* Minimum line offset in a special line info. opcode.
1727 This value was chosen to give a reasonable range of values. */
1728 #define DWARF_LINE_BASE -10
1730 /* First special line opcde - leave room for the standard opcodes. */
1731 #define DWARF_LINE_OPCODE_BASE 10
1733 /* Range of line offsets in a special line info. opcode. */
1734 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
1736 /* Flag that indicates the initial value of the is_stmt_start flag.
1737 In the present implementation, we do not mark any lines as
1738 the beginning of a source statement, because that information
1739 is not made available by the GCC front-end. */
1740 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
1742 /* This location is used by calc_die_sizes() to keep track
1743 the offset of each DIE within the .debug_info section. */
1744 static unsigned long next_die_offset;
1746 /* Record the root of the DIE's built for the current compilation unit. */
1747 static dw_die_ref comp_unit_die;
1749 /* A list of DIEs with a NULL parent waiting to be relocated. */
1750 static limbo_die_node *limbo_die_list = 0;
1752 /* Pointer to an array of filenames referenced by this compilation unit. */
1753 static char **file_table;
1755 /* Total number of entries in the table (i.e. array) pointed to by
1756 `file_table'. This is the *total* and includes both used and unused
1758 static unsigned file_table_allocated;
1760 /* Number of entries in the file_table which are actually in use. */
1761 static unsigned file_table_in_use;
1763 /* Size (in elements) of increments by which we may expand the filename
1765 #define FILE_TABLE_INCREMENT 64
1767 /* Local pointer to the name of the main input file. Initialized in
1769 static char *primary_filename;
1771 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
1772 which their beginnings are encountered. We output Dwarf debugging info
1773 that refers to the beginnings and ends of the ranges of code for each
1774 lexical block. The labels themselves are generated in final.c, which
1775 assigns numbers to the blocks in the same way. */
1776 static unsigned next_block_number = 2;
1778 /* A pointer to the base of a table of references to DIE's that describe
1779 declarations. The table is indexed by DECL_UID() which is a unique
1780 number, indentifying each decl. */
1781 static dw_die_ref *decl_die_table;
1783 /* Number of elements currently allocated for the decl_die_table. */
1784 static unsigned decl_die_table_allocated;
1786 /* Number of elements in decl_die_table currently in use. */
1787 static unsigned decl_die_table_in_use;
1789 /* Size (in elements) of increments by which we may expand the
1791 #define DECL_DIE_TABLE_INCREMENT 256
1793 /* A pointer to the base of a table of references to declaration
1794 scopes. This table is a display which tracks the nesting
1795 of declaration scopes at the current scope and containing
1796 scopes. This table is used to find the proper place to
1797 define type declaration DIE's. */
1798 static tree *decl_scope_table;
1800 /* Number of elements currently allocated for the decl_scope_table. */
1801 static unsigned decl_scope_table_allocated;
1803 /* Current level of nesting of declataion scopes. */
1804 static unsigned decl_scope_depth;
1806 /* Size (in elements) of increments by which we may expand the
1807 decl_scope_table. */
1808 #define DECL_SCOPE_TABLE_INCREMENT 64
1810 /* A pointer to the base of a list of references to DIE's that
1811 are uniquely identified by their tag, presence/absence of
1812 children DIE's, and list of attribute/value pairs. */
1813 static dw_die_ref *abbrev_die_table;
1815 /* Number of elements currently allocated for abbrev_die_table. */
1816 static unsigned abbrev_die_table_allocated;
1818 /* Number of elements in type_die_table currently in use. */
1819 static unsigned abbrev_die_table_in_use;
1821 /* Size (in elements) of increments by which we may expand the
1822 abbrev_die_table. */
1823 #define ABBREV_DIE_TABLE_INCREMENT 256
1825 /* A pointer to the base of a table that contains line information
1826 for each source code line in .text in the compilation unit. */
1827 static dw_line_info_ref line_info_table;
1829 /* Number of elements currently allocated for line_info_table. */
1830 static unsigned line_info_table_allocated;
1832 /* Number of elements in separate_line_info_table currently in use. */
1833 static unsigned separate_line_info_table_in_use;
1835 /* A pointer to the base of a table that contains line information
1836 for each source code line outside of .text in the compilation unit. */
1837 static dw_separate_line_info_ref separate_line_info_table;
1839 /* Number of elements currently allocated for separate_line_info_table. */
1840 static unsigned separate_line_info_table_allocated;
1842 /* Number of elements in line_info_table currently in use. */
1843 static unsigned line_info_table_in_use;
1845 /* Size (in elements) of increments by which we may expand the
1847 #define LINE_INFO_TABLE_INCREMENT 1024
1849 /* A pointer to the base of a table that contains a list of publicly
1850 accessible names. */
1851 static pubname_ref pubname_table;
1853 /* Number of elements currently allocated for pubname_table. */
1854 static unsigned pubname_table_allocated;
1856 /* Number of elements in pubname_table currently in use. */
1857 static unsigned pubname_table_in_use;
1859 /* Size (in elements) of increments by which we may expand the
1861 #define PUBNAME_TABLE_INCREMENT 64
1863 /* A pointer to the base of a table that contains a list of publicly
1864 accessible names. */
1865 static arange_ref arange_table;
1867 /* Number of elements currently allocated for arange_table. */
1868 static unsigned arange_table_allocated;
1870 /* Number of elements in arange_table currently in use. */
1871 static unsigned arange_table_in_use;
1873 /* Size (in elements) of increments by which we may expand the
1875 #define ARANGE_TABLE_INCREMENT 64
1877 /* A pointer to the base of a list of pending types which we haven't
1878 generated DIEs for yet, but which we will have to come back to
1881 static tree *pending_types_list;
1883 /* Number of elements currently allocated for the pending_types_list. */
1884 static unsigned pending_types_allocated;
1886 /* Number of elements of pending_types_list currently in use. */
1887 static unsigned pending_types;
1889 /* Size (in elements) of increments by which we may expand the pending
1890 types list. Actually, a single hunk of space of this size should
1891 be enough for most typical programs. */
1892 #define PENDING_TYPES_INCREMENT 64
1894 /* Record whether the function being analyzed contains inlined functions. */
1895 static int current_function_has_inlines;
1896 static int comp_unit_has_inlines;
1898 /* A pointer to the ..._DECL node which we have most recently been working
1899 on. We keep this around just in case something about it looks screwy and
1900 we want to tell the user what the source coordinates for the actual
1902 static tree dwarf_last_decl;
1904 /* Forward declarations for functions defined in this file. */
1906 static void addr_const_to_string PROTO((char *, rtx));
1907 static char *addr_to_string PROTO((rtx));
1908 static int is_pseudo_reg PROTO((rtx));
1909 static tree type_main_variant PROTO((tree));
1910 static int is_tagged_type PROTO((tree));
1911 static char *dwarf_tag_name PROTO((unsigned));
1912 static char *dwarf_attr_name PROTO((unsigned));
1913 static char *dwarf_form_name PROTO((unsigned));
1914 static char *dwarf_stack_op_name PROTO((unsigned));
1915 static char *dwarf_type_encoding_name PROTO((unsigned));
1916 static tree decl_ultimate_origin PROTO((tree));
1917 static tree block_ultimate_origin PROTO((tree));
1918 static tree decl_class_context PROTO((tree));
1919 static void add_dwarf_attr PROTO((dw_die_ref, dw_attr_ref));
1920 static void add_AT_flag PROTO((dw_die_ref,
1921 enum dwarf_attribute,
1923 static void add_AT_int PROTO((dw_die_ref,
1924 enum dwarf_attribute, long));
1925 static void add_AT_unsigned PROTO((dw_die_ref,
1926 enum dwarf_attribute,
1928 static void add_AT_long_long PROTO((dw_die_ref,
1929 enum dwarf_attribute,
1930 unsigned long, unsigned long));
1931 static void add_AT_float PROTO((dw_die_ref,
1932 enum dwarf_attribute,
1934 static void add_AT_string PROTO((dw_die_ref,
1935 enum dwarf_attribute, char *));
1936 static void add_AT_die_ref PROTO((dw_die_ref,
1937 enum dwarf_attribute,
1939 static void add_AT_fde_ref PROTO((dw_die_ref,
1940 enum dwarf_attribute,
1942 static void add_AT_loc PROTO((dw_die_ref,
1943 enum dwarf_attribute,
1945 static void add_AT_addr PROTO((dw_die_ref,
1946 enum dwarf_attribute, char *));
1947 static void add_AT_lbl_id PROTO((dw_die_ref,
1948 enum dwarf_attribute, char *));
1949 static void add_AT_setion_offset PROTO((dw_die_ref,
1950 enum dwarf_attribute, char *));
1951 static int is_extern_subr_die PROTO((dw_die_ref));
1952 static dw_attr_ref get_AT PROTO((dw_die_ref,
1953 enum dwarf_attribute));
1954 static char *get_AT_low_pc PROTO((dw_die_ref));
1955 static char *get_AT_hi_pc PROTO((dw_die_ref));
1956 static char *get_AT_string PROTO((dw_die_ref,
1957 enum dwarf_attribute));
1958 static int get_AT_flag PROTO((dw_die_ref,
1959 enum dwarf_attribute));
1960 static unsigned get_AT_unsigned PROTO((dw_die_ref,
1961 enum dwarf_attribute));
1962 static int is_c_family PROTO((void));
1963 static int is_fortran PROTO((void));
1964 static void remove_AT PROTO((dw_die_ref,
1965 enum dwarf_attribute));
1966 static void remove_children PROTO((dw_die_ref));
1967 static void add_child_die PROTO((dw_die_ref, dw_die_ref));
1968 static dw_die_ref new_die PROTO((enum dwarf_tag, dw_die_ref));
1969 static dw_die_ref lookup_type_die PROTO((tree));
1970 static void equate_type_number_to_die PROTO((tree, dw_die_ref));
1971 static dw_die_ref lookup_decl_die PROTO((tree));
1972 static void equate_decl_number_to_die PROTO((tree, dw_die_ref));
1973 static dw_loc_descr_ref new_loc_descr PROTO((enum dwarf_location_atom,
1974 unsigned long, unsigned long));
1975 static void add_loc_descr PROTO((dw_loc_descr_ref *,
1977 static void print_spaces PROTO((FILE *));
1978 static void print_die PROTO((dw_die_ref, FILE *));
1979 static void print_dwarf_line_table PROTO((FILE *));
1980 static void add_sibling_atttributes PROTO((dw_die_ref));
1981 static void build_abbrev_table PROTO((dw_die_ref));
1982 static unsigned long size_of_string PROTO((char *));
1983 static unsigned long size_of_loc_descr PROTO((dw_loc_descr_ref));
1984 static unsigned long size_of_locs PROTO((dw_loc_descr_ref));
1985 static int constant_size PROTO((long unsigned));
1986 static unsigned long size_of_die PROTO((dw_die_ref));
1987 static void calc_die_sizes PROTO((dw_die_ref));
1988 static unsigned long size_of_prolog PROTO((void));
1989 static unsigned long size_of_line_info PROTO((void));
1990 static unsigned long size_of_pubnames PROTO((void));
1991 static unsigned long size_of_aranges PROTO((void));
1992 static enum dwarf_form value_format PROTO((dw_val_ref));
1993 static void output_value_format PROTO((dw_val_ref));
1994 static void output_abbrev_section PROTO((void));
1995 static void output_loc_operands PROTO((dw_loc_descr_ref));
1996 static unsigned long sibling_offset PROTO((dw_die_ref));
1997 static void output_die PROTO((dw_die_ref));
1998 static void output_compilation_unit_header PROTO((void));
1999 static char *dwarf2_name PROTO((tree, int));
2000 static void add_pubname PROTO((tree, dw_die_ref));
2001 static void output_pubnames PROTO((void));
2002 static void add_arrange PROTO((tree, dw_die_ref));
2003 static void output_arranges PROTO((void));
2004 static void output_line_info PROTO((void));
2005 static int is_body_block PROTO((tree));
2006 static dw_die_ref base_type_die PROTO((tree));
2007 static tree root_type PROTO((tree));
2008 static int is_base_type PROTO((tree));
2009 static dw_die_ref modified_type_die PROTO((tree, int, int, dw_die_ref));
2010 static int type_is_enum PROTO((tree));
2011 static dw_loc_descr_ref reg_loc_descr_ref PROTO((rtx));
2012 static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long));
2013 static int is_based_loc PROTO((rtx));
2014 static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx));
2015 static dw_loc_descr_ref loc_descriptor PROTO((rtx));
2016 static unsigned ceiling PROTO((unsigned, unsigned));
2017 static tree field_type PROTO((tree));
2018 static unsigned simple_type_align_in_bits PROTO((tree));
2019 static unsigned simple_type_size_in_bits PROTO((tree));
2020 static unsigned field_byte_offset PROTO((tree));
2021 static void add_AT_location_description PROTO((dw_die_ref,
2022 enum dwarf_attribute, rtx));
2023 static void add_data_member_location_attribute PROTO((dw_die_ref, tree));
2024 static void add_const_value_attribute PROTO((dw_die_ref, rtx));
2025 static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree));
2026 static void add_name_attribute PROTO((dw_die_ref, char *));
2027 static void add_bound_info PROTO((dw_die_ref,
2028 enum dwarf_attribute, tree));
2029 static void add_subscript_info PROTO((dw_die_ref, tree));
2030 static void add_byte_size_attribute PROTO((dw_die_ref, tree));
2031 static void add_bit_offset_attribute PROTO((dw_die_ref, tree));
2032 static void add_bit_size_attribute PROTO((dw_die_ref, tree));
2033 static void add_prototyped_attribute PROTO((dw_die_ref, tree));
2034 static void add_abstract_origin_attribute PROTO((dw_die_ref, tree));
2035 static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree));
2036 static void add_src_coords_attributes PROTO((dw_die_ref, tree));
2037 static void ad_name_and_src_coords_attributes PROTO((dw_die_ref, tree));
2038 static void push_decl_scope PROTO((tree));
2039 static dw_die_ref scope_die_for PROTO((tree, dw_die_ref));
2040 static void pop_decl_scope PROTO((void));
2041 static void add_type_attribute PROTO((dw_die_ref, tree, int, int,
2043 static char *type_tag PROTO((tree));
2044 static tree member_declared_type PROTO((tree));
2045 static char *decl_start_label PROTO((tree));
2046 static void gen_arrqay_type_die PROTO((tree, dw_die_ref));
2047 static void gen_set_type_die PROTO((tree, dw_die_ref));
2048 static void gen_entry_point_die PROTO((tree, dw_die_ref));
2049 static void pend_type PROTO((tree));
2050 static void output_pending_types_for_scope PROTO((dw_die_ref));
2051 static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref));
2052 static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref));
2053 static void gen_inlined_union_type_die PROTO((tree, dw_die_ref));
2054 static void gen_enumeration_type_die PROTO((tree, dw_die_ref));
2055 static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref));
2056 static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref));
2057 static void gen_formal_types_die PROTO((tree, dw_die_ref));
2058 static void gen_subprogram_die PROTO((tree, dw_die_ref));
2059 static void gen_variable_die PROTO((tree, dw_die_ref));
2060 static void gen_label_die PROTO((tree, dw_die_ref));
2061 static void gen_lexical_block_die PROTO((tree, dw_die_ref, int));
2062 static void gen_inlined_subprogram_die PROTO((tree, dw_die_ref, int));
2063 static void gen_field_die PROTO((tree, dw_die_ref));
2064 static void gen_ptr_to_mbr_type_die PROTO((tree, dw_die_ref));
2065 static void gen_compile_unit_die PROTO((char *));
2066 static void gen_string_type_die PROTO((tree, dw_die_ref));
2067 static void gen_inheritance_die PROTO((tree, dw_die_ref));
2068 static void gen_member_die PROTO((tree, dw_die_ref));
2069 static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref));
2070 static void gen_subroutine_type_die PROTO((tree, dw_die_ref));
2071 static void gen_typedef_die PROTO((tree, dw_die_ref));
2072 static void gen_type_die PROTO((tree, dw_die_ref));
2073 static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref));
2074 static void gen_block_die PROTO((tree, dw_die_ref, int));
2075 static void decls_for_scope PROTO((tree, dw_die_ref, int));
2076 static int is_redundant_typedef PROTO((tree));
2077 static void gen_decl_die PROTO((tree, dw_die_ref));
2078 static unsigned lookup_filename PROTO((char *));
2080 /* Section names used to hold DWARF debugging information. */
2081 #ifndef DEBUG_INFO_SECTION
2082 #define DEBUG_INFO_SECTION ".debug_info"
2084 #ifndef ABBREV_SECTION
2085 #define ABBREV_SECTION ".debug_abbrev"
2087 #ifndef ARANGES_SECTION
2088 #define ARANGES_SECTION ".debug_aranges"
2090 #ifndef DW_MACINFO_SECTION
2091 #define DW_MACINFO_SECTION ".debug_macinfo"
2093 #ifndef DEBUG_LINE_SECTION
2094 #define DEBUG_LINE_SECTION ".debug_line"
2097 #define LOC_SECTION ".debug_loc"
2099 #ifndef PUBNAMES_SECTION
2100 #define PUBNAMES_SECTION ".debug_pubnames"
2103 #define STR_SECTION ".debug_str"
2106 /* Standerd ELF section names for compiled code and data. */
2107 #ifndef TEXT_SECTION
2108 #define TEXT_SECTION ".text"
2110 #ifndef DATA_SECTION
2111 #define DATA_SECTION ".data"
2114 #define BSS_SECTION ".bss"
2118 /* Definitions of defaults for formats and names of various special
2119 (artificial) labels which may be generated within this file (when the -g
2120 options is used and DWARF_DEBUGGING_INFO is in effect.
2121 If necessary, these may be overridden from within the tm.h file, but
2122 typically, overriding these defaults is unnecessary. */
2124 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2126 #ifndef TEXT_END_LABEL
2127 #define TEXT_END_LABEL "Letext"
2129 #ifndef DATA_END_LABEL
2130 #define DATA_END_LABEL "Ledata"
2132 #ifndef BSS_END_LABEL
2133 #define BSS_END_LABEL "Lebss"
2135 #ifndef INSN_LABEL_FMT
2136 #define INSN_LABEL_FMT "LI%u_"
2138 #ifndef BLOCK_BEGIN_LABEL
2139 #define BLOCK_BEGIN_LABEL "LBB"
2141 #ifndef BLOCK_END_LABEL
2142 #define BLOCK_END_LABEL "LBE"
2144 #ifndef BODY_BEGIN_LABEL
2145 #define BODY_BEGIN_LABEL "Lbb"
2147 #ifndef BODY_END_LABEL
2148 #define BODY_END_LABEL "Lbe"
2150 #ifndef LINE_CODE_LABEL
2151 #define LINE_CODE_LABEL "LM"
2153 #ifndef SEPARATE_LINE_CODE_LABEL
2154 #define SEPARATE_LINE_CODE_LABEL "LSM"
2157 /* Convert a reference to the assembler name of a C-level name. This
2158 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
2159 a string rather than writing to a file. */
2160 #ifndef ASM_NAME_TO_STRING
2161 #define ASM_NAME_TO_STRING(STR, NAME) \
2163 if ((NAME)[0] == '*') \
2164 strcpy (STR, NAME+1); \
2166 strcpy (STR, NAME); \
2171 /* Convert an integer constant expression into assembler syntax. Addition
2172 and subtraction are the only arithmetic that may appear in these
2173 expressions. This is an adaptation of output_addr_const in final.c.
2174 Here, the target of the conversion is a string buffer. We can't use
2175 output_addr_const directly, because it writes to a file. */
2178 addr_const_to_string (str, x)
2187 switch (GET_CODE (x))
2197 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
2202 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2203 ASM_NAME_TO_STRING (buf2, buf1);
2208 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
2209 ASM_NAME_TO_STRING (buf2, buf1);
2214 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
2219 /* This used to output parentheses around the expression, but that does
2220 not work on the 386 (either ATT or BSD assembler). */
2221 addr_const_to_string (buf1, XEXP (x, 0));
2226 if (GET_MODE (x) == VOIDmode)
2228 /* We can use %d if the number is one word and positive. */
2229 if (CONST_DOUBLE_HIGH (x))
2230 sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
2231 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2232 else if (CONST_DOUBLE_LOW (x) < 0)
2233 sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
2235 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
2236 CONST_DOUBLE_LOW (x));
2240 /* We can't handle floating point constants; PRINT_OPERAND must
2242 output_operand_lossage ("floating constant misused");
2246 /* Some assemblers need integer constants to appear last (eg masm). */
2247 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2249 addr_const_to_string (buf1, XEXP (x, 1));
2251 if (INTVAL (XEXP (x, 0)) >= 0)
2254 addr_const_to_string (buf1, XEXP (x, 0));
2259 addr_const_to_string (buf1, XEXP (x, 0));
2261 if (INTVAL (XEXP (x, 1)) >= 0)
2264 addr_const_to_string (buf1, XEXP (x, 1));
2270 /* Avoid outputting things like x-x or x+5-x, since some assemblers
2271 can't handle that. */
2272 x = simplify_subtraction (x);
2273 if (GET_CODE (x) != MINUS)
2276 addr_const_to_string (buf1, XEXP (x, 0));
2279 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2280 && INTVAL (XEXP (x, 1)) < 0)
2282 strcat (str, ASM_OPEN_PAREN);
2283 addr_const_to_string (buf1, XEXP (x, 1));
2285 strcat (str, ASM_CLOSE_PAREN);
2289 addr_const_to_string (buf1, XEXP (x, 1));
2296 addr_const_to_string (buf1, XEXP (x, 0));
2301 output_operand_lossage ("invalid expression as operand");
2305 /* Convert an address constant to a string, and return a pointer to
2306 a copy of the result, located on the heap. */
2313 addr_const_to_string (buf, x);
2314 return xstrdup (buf);
2317 /* Test if rtl node points to a psuedo register. */
2323 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
2324 || ((GET_CODE (rtl) == SUBREG)
2325 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
2328 /* Return a reference to a type, with its const and volatile qualifiers
2332 type_main_variant (type)
2335 type = TYPE_MAIN_VARIANT (type);
2337 /* There really should be only one main variant among any group of variants
2338 of a given type (and all of the MAIN_VARIANT values for all members of
2339 the group should point to that one type) but sometimes the C front-end
2340 messes this up for array types, so we work around that bug here. */
2342 if (TREE_CODE (type) == ARRAY_TYPE)
2343 while (type != TYPE_MAIN_VARIANT (type))
2344 type = TYPE_MAIN_VARIANT (type);
2349 /* Return non-zero if the given type node represents a tagged type. */
2352 is_tagged_type (type)
2355 register enum tree_code code = TREE_CODE (type);
2357 return (code == RECORD_TYPE || code == UNION_TYPE
2358 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
2361 /* Convert a DIE tag into its string name. */
2364 dwarf_tag_name (tag)
2365 register unsigned tag;
2369 case DW_TAG_padding:
2370 return "DW_TAG_padding";
2371 case DW_TAG_array_type:
2372 return "DW_TAG_array_type";
2373 case DW_TAG_class_type:
2374 return "DW_TAG_class_type";
2375 case DW_TAG_entry_point:
2376 return "DW_TAG_entry_point";
2377 case DW_TAG_enumeration_type:
2378 return "DW_TAG_enumeration_type";
2379 case DW_TAG_formal_parameter:
2380 return "DW_TAG_formal_parameter";
2381 case DW_TAG_imported_declaration:
2382 return "DW_TAG_imported_declaration";
2384 return "DW_TAG_label";
2385 case DW_TAG_lexical_block:
2386 return "DW_TAG_lexical_block";
2388 return "DW_TAG_member";
2389 case DW_TAG_pointer_type:
2390 return "DW_TAG_pointer_type";
2391 case DW_TAG_reference_type:
2392 return "DW_TAG_reference_type";
2393 case DW_TAG_compile_unit:
2394 return "DW_TAG_compile_unit";
2395 case DW_TAG_string_type:
2396 return "DW_TAG_string_type";
2397 case DW_TAG_structure_type:
2398 return "DW_TAG_structure_type";
2399 case DW_TAG_subroutine_type:
2400 return "DW_TAG_subroutine_type";
2401 case DW_TAG_typedef:
2402 return "DW_TAG_typedef";
2403 case DW_TAG_union_type:
2404 return "DW_TAG_union_type";
2405 case DW_TAG_unspecified_parameters:
2406 return "DW_TAG_unspecified_parameters";
2407 case DW_TAG_variant:
2408 return "DW_TAG_variant";
2409 case DW_TAG_common_block:
2410 return "DW_TAG_common_block";
2411 case DW_TAG_common_inclusion:
2412 return "DW_TAG_common_inclusion";
2413 case DW_TAG_inheritance:
2414 return "DW_TAG_inheritance";
2415 case DW_TAG_inlined_subroutine:
2416 return "DW_TAG_inlined_subroutine";
2418 return "DW_TAG_module";
2419 case DW_TAG_ptr_to_member_type:
2420 return "DW_TAG_ptr_to_member_type";
2421 case DW_TAG_set_type:
2422 return "DW_TAG_set_type";
2423 case DW_TAG_subrange_type:
2424 return "DW_TAG_subrange_type";
2425 case DW_TAG_with_stmt:
2426 return "DW_TAG_with_stmt";
2427 case DW_TAG_access_declaration:
2428 return "DW_TAG_access_declaration";
2429 case DW_TAG_base_type:
2430 return "DW_TAG_base_type";
2431 case DW_TAG_catch_block:
2432 return "DW_TAG_catch_block";
2433 case DW_TAG_const_type:
2434 return "DW_TAG_const_type";
2435 case DW_TAG_constant:
2436 return "DW_TAG_constant";
2437 case DW_TAG_enumerator:
2438 return "DW_TAG_enumerator";
2439 case DW_TAG_file_type:
2440 return "DW_TAG_file_type";
2442 return "DW_TAG_friend";
2443 case DW_TAG_namelist:
2444 return "DW_TAG_namelist";
2445 case DW_TAG_namelist_item:
2446 return "DW_TAG_namelist_item";
2447 case DW_TAG_packed_type:
2448 return "DW_TAG_packed_type";
2449 case DW_TAG_subprogram:
2450 return "DW_TAG_subprogram";
2451 case DW_TAG_template_type_param:
2452 return "DW_TAG_template_type_param";
2453 case DW_TAG_template_value_param:
2454 return "DW_TAG_template_value_param";
2455 case DW_TAG_thrown_type:
2456 return "DW_TAG_thrown_type";
2457 case DW_TAG_try_block:
2458 return "DW_TAG_try_block";
2459 case DW_TAG_variant_part:
2460 return "DW_TAG_variant_part";
2461 case DW_TAG_variable:
2462 return "DW_TAG_variable";
2463 case DW_TAG_volatile_type:
2464 return "DW_TAG_volatile_type";
2465 case DW_TAG_MIPS_loop:
2466 return "DW_TAG_MIPS_loop";
2467 case DW_TAG_format_label:
2468 return "DW_TAG_format_label";
2469 case DW_TAG_function_template:
2470 return "DW_TAG_function_template";
2471 case DW_TAG_class_template:
2472 return "DW_TAG_class_template";
2474 return "DW_TAG_<unknown>";
2478 /* Convert a DWARF attribute code into its string name. */
2481 dwarf_attr_name (attr)
2482 register unsigned attr;
2487 return "DW_AT_sibling";
2488 case DW_AT_location:
2489 return "DW_AT_location";
2491 return "DW_AT_name";
2492 case DW_AT_ordering:
2493 return "DW_AT_ordering";
2494 case DW_AT_subscr_data:
2495 return "DW_AT_subscr_data";
2496 case DW_AT_byte_size:
2497 return "DW_AT_byte_size";
2498 case DW_AT_bit_offset:
2499 return "DW_AT_bit_offset";
2500 case DW_AT_bit_size:
2501 return "DW_AT_bit_size";
2502 case DW_AT_element_list:
2503 return "DW_AT_element_list";
2504 case DW_AT_stmt_list:
2505 return "DW_AT_stmt_list";
2507 return "DW_AT_low_pc";
2509 return "DW_AT_high_pc";
2510 case DW_AT_language:
2511 return "DW_AT_language";
2513 return "DW_AT_member";
2515 return "DW_AT_discr";
2516 case DW_AT_discr_value:
2517 return "DW_AT_discr_value";
2518 case DW_AT_visibility:
2519 return "DW_AT_visibility";
2521 return "DW_AT_import";
2522 case DW_AT_string_length:
2523 return "DW_AT_string_length";
2524 case DW_AT_common_reference:
2525 return "DW_AT_common_reference";
2526 case DW_AT_comp_dir:
2527 return "DW_AT_comp_dir";
2528 case DW_AT_const_value:
2529 return "DW_AT_const_value";
2530 case DW_AT_containing_type:
2531 return "DW_AT_containing_type";
2532 case DW_AT_default_value:
2533 return "DW_AT_default_value";
2535 return "DW_AT_inline";
2536 case DW_AT_is_optional:
2537 return "DW_AT_is_optional";
2538 case DW_AT_lower_bound:
2539 return "DW_AT_lower_bound";
2540 case DW_AT_producer:
2541 return "DW_AT_producer";
2542 case DW_AT_prototyped:
2543 return "DW_AT_prototyped";
2544 case DW_AT_return_addr:
2545 return "DW_AT_return_addr";
2546 case DW_AT_start_scope:
2547 return "DW_AT_start_scope";
2548 case DW_AT_stride_size:
2549 return "DW_AT_stride_size";
2550 case DW_AT_upper_bound:
2551 return "DW_AT_upper_bound";
2552 case DW_AT_abstract_origin:
2553 return "DW_AT_abstract_origin";
2554 case DW_AT_accessibility:
2555 return "DW_AT_accessibility";
2556 case DW_AT_address_class:
2557 return "DW_AT_address_class";
2558 case DW_AT_artificial:
2559 return "DW_AT_artificial";
2560 case DW_AT_base_types:
2561 return "DW_AT_base_types";
2562 case DW_AT_calling_convention:
2563 return "DW_AT_calling_convention";
2565 return "DW_AT_count";
2566 case DW_AT_data_member_location:
2567 return "DW_AT_data_member_location";
2568 case DW_AT_decl_column:
2569 return "DW_AT_decl_column";
2570 case DW_AT_decl_file:
2571 return "DW_AT_decl_file";
2572 case DW_AT_decl_line:
2573 return "DW_AT_decl_line";
2574 case DW_AT_declaration:
2575 return "DW_AT_declaration";
2576 case DW_AT_discr_list:
2577 return "DW_AT_discr_list";
2578 case DW_AT_encoding:
2579 return "DW_AT_encoding";
2580 case DW_AT_external:
2581 return "DW_AT_external";
2582 case DW_AT_frame_base:
2583 return "DW_AT_frame_base";
2585 return "DW_AT_friend";
2586 case DW_AT_identifier_case:
2587 return "DW_AT_identifier_case";
2588 case DW_AT_macro_info:
2589 return "DW_AT_macro_info";
2590 case DW_AT_namelist_items:
2591 return "DW_AT_namelist_items";
2592 case DW_AT_priority:
2593 return "DW_AT_priority";
2595 return "DW_AT_segment";
2596 case DW_AT_specification:
2597 return "DW_AT_specification";
2598 case DW_AT_static_link:
2599 return "DW_AT_static_link";
2601 return "DW_AT_type";
2602 case DW_AT_use_location:
2603 return "DW_AT_use_location";
2604 case DW_AT_variable_parameter:
2605 return "DW_AT_variable_parameter";
2606 case DW_AT_virtuality:
2607 return "DW_AT_virtuality";
2608 case DW_AT_vtable_elem_location:
2609 return "DW_AT_vtable_elem_location";
2611 case DW_AT_MIPS_fde:
2612 return "DW_AT_MIPS_fde";
2613 case DW_AT_MIPS_loop_begin:
2614 return "DW_AT_MIPS_loop_begin";
2615 case DW_AT_MIPS_tail_loop_begin:
2616 return "DW_AT_MIPS_tail_loop_begin";
2617 case DW_AT_MIPS_epilog_begin:
2618 return "DW_AT_MIPS_epilog_begin";
2619 case DW_AT_MIPS_loop_unroll_factor:
2620 return "DW_AT_MIPS_loop_unroll_factor";
2621 case DW_AT_MIPS_software_pipeline_depth:
2622 return "DW_AT_MIPS_software_pipeline_depth";
2623 case DW_AT_MIPS_linkage_name:
2624 return "DW_AT_MIPS_linkage_name";
2625 case DW_AT_MIPS_stride:
2626 return "DW_AT_MIPS_stride";
2627 case DW_AT_MIPS_abstract_name:
2628 return "DW_AT_MIPS_abstract_name";
2629 case DW_AT_MIPS_clone_origin:
2630 return "DW_AT_MIPS_clone_origin";
2631 case DW_AT_MIPS_has_inlines:
2632 return "DW_AT_MIPS_has_inlines";
2634 case DW_AT_sf_names:
2635 return "DW_AT_sf_names";
2636 case DW_AT_src_info:
2637 return "DW_AT_src_info";
2638 case DW_AT_mac_info:
2639 return "DW_AT_mac_info";
2640 case DW_AT_src_coords:
2641 return "DW_AT_src_coords";
2642 case DW_AT_body_begin:
2643 return "DW_AT_body_begin";
2644 case DW_AT_body_end:
2645 return "DW_AT_body_end";
2647 return "DW_AT_<unknown>";
2651 /* Convert a DWARF value form code into its string name. */
2654 dwarf_form_name (form)
2655 register unsigned form;
2660 return "DW_FORM_addr";
2661 case DW_FORM_block2:
2662 return "DW_FORM_block2";
2663 case DW_FORM_block4:
2664 return "DW_FORM_block4";
2666 return "DW_FORM_data2";
2668 return "DW_FORM_data4";
2670 return "DW_FORM_data8";
2671 case DW_FORM_string:
2672 return "DW_FORM_string";
2674 return "DW_FORM_block";
2675 case DW_FORM_block1:
2676 return "DW_FORM_block1";
2678 return "DW_FORM_data1";
2680 return "DW_FORM_flag";
2682 return "DW_FORM_sdata";
2684 return "DW_FORM_strp";
2686 return "DW_FORM_udata";
2687 case DW_FORM_ref_addr:
2688 return "DW_FORM_ref_addr";
2690 return "DW_FORM_ref1";
2692 return "DW_FORM_ref2";
2694 return "DW_FORM_ref4";
2696 return "DW_FORM_ref8";
2697 case DW_FORM_ref_udata:
2698 return "DW_FORM_ref_udata";
2699 case DW_FORM_indirect:
2700 return "DW_FORM_indirect";
2702 return "DW_FORM_<unknown>";
2706 /* Convert a DWARF stack opcode into its string name. */
2709 dwarf_stack_op_name (op)
2710 register unsigned op;
2715 return "DW_OP_addr";
2717 return "DW_OP_deref";
2719 return "DW_OP_const1u";
2721 return "DW_OP_const1s";
2723 return "DW_OP_const2u";
2725 return "DW_OP_const2s";
2727 return "DW_OP_const4u";
2729 return "DW_OP_const4s";
2731 return "DW_OP_const8u";
2733 return "DW_OP_const8s";
2735 return "DW_OP_constu";
2737 return "DW_OP_consts";
2741 return "DW_OP_drop";
2743 return "DW_OP_over";
2745 return "DW_OP_pick";
2747 return "DW_OP_swap";
2751 return "DW_OP_xderef";
2759 return "DW_OP_minus";
2771 return "DW_OP_plus";
2772 case DW_OP_plus_uconst:
2773 return "DW_OP_plus_uconst";
2779 return "DW_OP_shra";
2797 return "DW_OP_skip";
2799 return "DW_OP_lit0";
2801 return "DW_OP_lit1";
2803 return "DW_OP_lit2";
2805 return "DW_OP_lit3";
2807 return "DW_OP_lit4";
2809 return "DW_OP_lit5";
2811 return "DW_OP_lit6";
2813 return "DW_OP_lit7";
2815 return "DW_OP_lit8";
2817 return "DW_OP_lit9";
2819 return "DW_OP_lit10";
2821 return "DW_OP_lit11";
2823 return "DW_OP_lit12";
2825 return "DW_OP_lit13";
2827 return "DW_OP_lit14";
2829 return "DW_OP_lit15";
2831 return "DW_OP_lit16";
2833 return "DW_OP_lit17";
2835 return "DW_OP_lit18";
2837 return "DW_OP_lit19";
2839 return "DW_OP_lit20";
2841 return "DW_OP_lit21";
2843 return "DW_OP_lit22";
2845 return "DW_OP_lit23";
2847 return "DW_OP_lit24";
2849 return "DW_OP_lit25";
2851 return "DW_OP_lit26";
2853 return "DW_OP_lit27";
2855 return "DW_OP_lit28";
2857 return "DW_OP_lit29";
2859 return "DW_OP_lit30";
2861 return "DW_OP_lit31";
2863 return "DW_OP_reg0";
2865 return "DW_OP_reg1";
2867 return "DW_OP_reg2";
2869 return "DW_OP_reg3";
2871 return "DW_OP_reg4";
2873 return "DW_OP_reg5";
2875 return "DW_OP_reg6";
2877 return "DW_OP_reg7";
2879 return "DW_OP_reg8";
2881 return "DW_OP_reg9";
2883 return "DW_OP_reg10";
2885 return "DW_OP_reg11";
2887 return "DW_OP_reg12";
2889 return "DW_OP_reg13";
2891 return "DW_OP_reg14";
2893 return "DW_OP_reg15";
2895 return "DW_OP_reg16";
2897 return "DW_OP_reg17";
2899 return "DW_OP_reg18";
2901 return "DW_OP_reg19";
2903 return "DW_OP_reg20";
2905 return "DW_OP_reg21";
2907 return "DW_OP_reg22";
2909 return "DW_OP_reg23";
2911 return "DW_OP_reg24";
2913 return "DW_OP_reg25";
2915 return "DW_OP_reg26";
2917 return "DW_OP_reg27";
2919 return "DW_OP_reg28";
2921 return "DW_OP_reg29";
2923 return "DW_OP_reg30";
2925 return "DW_OP_reg31";
2927 return "DW_OP_breg0";
2929 return "DW_OP_breg1";
2931 return "DW_OP_breg2";
2933 return "DW_OP_breg3";
2935 return "DW_OP_breg4";
2937 return "DW_OP_breg5";
2939 return "DW_OP_breg6";
2941 return "DW_OP_breg7";
2943 return "DW_OP_breg8";
2945 return "DW_OP_breg9";
2947 return "DW_OP_breg10";
2949 return "DW_OP_breg11";
2951 return "DW_OP_breg12";
2953 return "DW_OP_breg13";
2955 return "DW_OP_breg14";
2957 return "DW_OP_breg15";
2959 return "DW_OP_breg16";
2961 return "DW_OP_breg17";
2963 return "DW_OP_breg18";
2965 return "DW_OP_breg19";
2967 return "DW_OP_breg20";
2969 return "DW_OP_breg21";
2971 return "DW_OP_breg22";
2973 return "DW_OP_breg23";
2975 return "DW_OP_breg24";
2977 return "DW_OP_breg25";
2979 return "DW_OP_breg26";
2981 return "DW_OP_breg27";
2983 return "DW_OP_breg28";
2985 return "DW_OP_breg29";
2987 return "DW_OP_breg30";
2989 return "DW_OP_breg31";
2991 return "DW_OP_regx";
2993 return "DW_OP_fbreg";
2995 return "DW_OP_bregx";
2997 return "DW_OP_piece";
2998 case DW_OP_deref_size:
2999 return "DW_OP_deref_size";
3000 case DW_OP_xderef_size:
3001 return "DW_OP_xderef_size";
3005 return "OP_<unknown>";
3009 /* Convert a DWARF type code into its string name. */
3012 dwarf_type_encoding_name (enc)
3013 register unsigned enc;
3017 case DW_ATE_address:
3018 return "DW_ATE_address";
3019 case DW_ATE_boolean:
3020 return "DW_ATE_boolean";
3021 case DW_ATE_complex_float:
3022 return "DW_ATE_complex_float";
3024 return "DW_ATE_float";
3026 return "DW_ATE_signed";
3027 case DW_ATE_signed_char:
3028 return "DW_ATE_signed_char";
3029 case DW_ATE_unsigned:
3030 return "DW_ATE_unsigned";
3031 case DW_ATE_unsigned_char:
3032 return "DW_ATE_unsigned_char";
3034 return "DW_ATE_<unknown>";
3038 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3039 instance of an inlined instance of a decl which is local to an inline
3040 function, so we have to trace all of the way back through the origin chain
3041 to find out what sort of node actually served as the original seed for the
3045 decl_ultimate_origin (decl)
3048 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
3050 if (immediate_origin == NULL_TREE)
3054 register tree ret_val;
3055 register tree lookahead = immediate_origin;
3059 ret_val = lookahead;
3060 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
3062 while (lookahead != NULL && lookahead != ret_val);
3068 /* Determine the "ultimate origin" of a block. The block may be an inlined
3069 instance of an inlined instance of a block which is local to an inline
3070 function, so we have to trace all of the way back through the origin chain
3071 to find out what sort of node actually served as the original seed for the
3075 block_ultimate_origin (block)
3076 register tree block;
3078 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3080 if (immediate_origin == NULL_TREE)
3084 register tree ret_val;
3085 register tree lookahead = immediate_origin;
3089 ret_val = lookahead;
3090 lookahead = (TREE_CODE (ret_val) == BLOCK)
3091 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3094 while (lookahead != NULL && lookahead != ret_val);
3100 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3101 of a virtual function may refer to a base class, so we check the 'this'
3105 decl_class_context (decl)
3108 tree context = NULL_TREE;
3110 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3111 context = DECL_CONTEXT (decl);
3113 context = TYPE_MAIN_VARIANT
3114 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3116 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
3117 context = NULL_TREE;
3122 /* Add an attribute/value pair to a DIE */
3125 add_dwarf_attr (die, attr)
3126 register dw_die_ref die;
3127 register dw_attr_ref attr;
3129 if (die != NULL && attr != NULL)
3131 if (die->die_attr == NULL)
3133 die->die_attr = attr;
3134 die->die_attr_last = attr;
3138 die->die_attr_last->dw_attr_next = attr;
3139 die->die_attr_last = attr;
3144 /* Add a flag value attribute to a DIE. */
3147 add_AT_flag (die, attr_kind, flag)
3148 register dw_die_ref die;
3149 register enum dwarf_attribute attr_kind;
3150 register unsigned flag;
3152 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3154 attr->dw_attr_next = NULL;
3155 attr->dw_attr = attr_kind;
3156 attr->dw_attr_val.val_class = dw_val_class_flag;
3157 attr->dw_attr_val.v.val_flag = flag;
3158 add_dwarf_attr (die, attr);
3161 /* Add a signed integer attribute value to a DIE. */
3164 add_AT_int (die, attr_kind, int_val)
3165 register dw_die_ref die;
3166 register enum dwarf_attribute attr_kind;
3167 register long int int_val;
3169 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3171 attr->dw_attr_next = NULL;
3172 attr->dw_attr = attr_kind;
3173 attr->dw_attr_val.val_class = dw_val_class_const;
3174 attr->dw_attr_val.v.val_int = int_val;
3175 add_dwarf_attr (die, attr);
3178 /* Add an unsigned integer attribute value to a DIE. */
3181 add_AT_unsigned (die, attr_kind, unsigned_val)
3182 register dw_die_ref die;
3183 register enum dwarf_attribute attr_kind;
3184 register unsigned long unsigned_val;
3186 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3188 attr->dw_attr_next = NULL;
3189 attr->dw_attr = attr_kind;
3190 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
3191 attr->dw_attr_val.v.val_unsigned = unsigned_val;
3192 add_dwarf_attr (die, attr);
3195 /* Add an unsigned double integer attribute value to a DIE. */
3198 add_AT_long_long (die, attr_kind, val_hi, val_low)
3199 register dw_die_ref die;
3200 register enum dwarf_attribute attr_kind;
3201 register unsigned long val_hi;
3202 register unsigned long val_low;
3204 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3206 attr->dw_attr_next = NULL;
3207 attr->dw_attr = attr_kind;
3208 attr->dw_attr_val.val_class = dw_val_class_long_long;
3209 attr->dw_attr_val.v.val_long_long.hi = val_hi;
3210 attr->dw_attr_val.v.val_long_long.low = val_low;
3211 add_dwarf_attr (die, attr);
3214 /* Add a floating point attribute value to a DIE and return it. */
3217 add_AT_float (die, attr_kind, length, array)
3218 register dw_die_ref die;
3219 register enum dwarf_attribute attr_kind;
3220 register unsigned length;
3221 register long *array;
3223 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3225 attr->dw_attr_next = NULL;
3226 attr->dw_attr = attr_kind;
3227 attr->dw_attr_val.val_class = dw_val_class_float;
3228 attr->dw_attr_val.v.val_float.length = length;
3229 attr->dw_attr_val.v.val_float.array = array;
3230 add_dwarf_attr (die, attr);
3233 /* Add a string attribute value to a DIE. */
3236 add_AT_string (die, attr_kind, str)
3237 register dw_die_ref die;
3238 register enum dwarf_attribute attr_kind;
3241 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3243 attr->dw_attr_next = NULL;
3244 attr->dw_attr = attr_kind;
3245 attr->dw_attr_val.val_class = dw_val_class_str;
3246 attr->dw_attr_val.v.val_str = xstrdup (str);
3247 add_dwarf_attr (die, attr);
3250 /* Add a DIE reference attribute value to a DIE. */
3253 add_AT_die_ref (die, attr_kind, targ_die)
3254 register dw_die_ref die;
3255 register enum dwarf_attribute attr_kind;
3256 register dw_die_ref targ_die;
3258 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3260 attr->dw_attr_next = NULL;
3261 attr->dw_attr = attr_kind;
3262 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3263 attr->dw_attr_val.v.val_die_ref = targ_die;
3264 add_dwarf_attr (die, attr);
3267 /* Add an FDE reference attribute value to a DIE. */
3270 add_AT_fde_ref (die, attr_kind, targ_fde)
3271 register dw_die_ref die;
3272 register enum dwarf_attribute attr_kind;
3273 register unsigned targ_fde;
3275 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3277 attr->dw_attr_next = NULL;
3278 attr->dw_attr = attr_kind;
3279 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
3280 attr->dw_attr_val.v.val_fde_index = targ_fde;
3281 add_dwarf_attr (die, attr);
3284 /* Add a location description attribute value to a DIE. */
3287 add_AT_loc (die, attr_kind, loc)
3288 register dw_die_ref die;
3289 register enum dwarf_attribute attr_kind;
3290 register dw_loc_descr_ref loc;
3292 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3294 attr->dw_attr_next = NULL;
3295 attr->dw_attr = attr_kind;
3296 attr->dw_attr_val.val_class = dw_val_class_loc;
3297 attr->dw_attr_val.v.val_loc = loc;
3298 add_dwarf_attr (die, attr);
3301 /* Add an address constant attribute value to a DIE. */
3304 add_AT_addr (die, attr_kind, addr)
3305 register dw_die_ref die;
3306 register enum dwarf_attribute attr_kind;
3309 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3311 attr->dw_attr_next = NULL;
3312 attr->dw_attr = attr_kind;
3313 attr->dw_attr_val.val_class = dw_val_class_addr;
3314 attr->dw_attr_val.v.val_addr = addr;
3315 add_dwarf_attr (die, attr);
3318 /* Add a label identifier attribute value to a DIE. */
3321 add_AT_lbl_id (die, attr_kind, lbl_id)
3322 register dw_die_ref die;
3323 register enum dwarf_attribute attr_kind;
3324 register char *lbl_id;
3326 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3328 attr->dw_attr_next = NULL;
3329 attr->dw_attr = attr_kind;
3330 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
3331 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
3332 add_dwarf_attr (die, attr);
3335 /* Add a section offset attribute value to a DIE. */
3338 add_AT_section_offset (die, attr_kind, section)
3339 register dw_die_ref die;
3340 register enum dwarf_attribute attr_kind;
3341 register char *section;
3343 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3345 attr->dw_attr_next = NULL;
3346 attr->dw_attr = attr_kind;
3347 attr->dw_attr_val.val_class = dw_val_class_section_offset;
3348 attr->dw_attr_val.v.val_section = section;
3349 add_dwarf_attr (die, attr);
3353 /* Test if die refers to an external subroutine. */
3356 is_extern_subr_die (die)
3357 register dw_die_ref die;
3359 register dw_attr_ref a;
3360 register int is_subr = FALSE;
3361 register int is_extern = FALSE;
3363 if (die != NULL && die->die_tag == DW_TAG_subprogram)
3366 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3368 if (a->dw_attr == DW_AT_external
3369 && a->dw_attr_val.val_class == dw_val_class_flag
3370 && a->dw_attr_val.v.val_flag != 0)
3378 return is_subr && is_extern;
3381 /* Get the attribute of type attr_kind. */
3383 static inline dw_attr_ref
3384 get_AT (die, attr_kind)
3385 register dw_die_ref die;
3386 register enum dwarf_attribute attr_kind;
3388 register dw_attr_ref a;
3389 register dw_die_ref spec = NULL;
3393 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3395 if (a->dw_attr == attr_kind)
3398 if (a->dw_attr == DW_AT_specification
3399 || a->dw_attr == DW_AT_abstract_origin)
3400 spec = a->dw_attr_val.v.val_die_ref;
3404 return get_AT (spec, attr_kind);
3410 /* Return the "low pc" attribute value, typically associated with
3411 a subprogram DIE. Return null if the "low pc" attribute is
3412 either not prsent, or if it cannot be represented as an
3413 assembler label identifier. */
3415 static inline char *
3417 register dw_die_ref die;
3419 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
3421 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3422 return a->dw_attr_val.v.val_lbl_id;
3427 /* Return the "high pc" attribute value, typically associated with
3428 a subprogram DIE. Return null if the "high pc" attribute is
3429 either not prsent, or if it cannot be represented as an
3430 assembler label identifier. */
3432 static inline char *
3434 register dw_die_ref die;
3436 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
3438 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3439 return a->dw_attr_val.v.val_lbl_id;
3444 /* Return the value of the string attribute designated by ATTR_KIND, or
3445 NULL if it is not present. */
3447 static inline char *
3448 get_AT_string (die, attr_kind)
3449 register dw_die_ref die;
3450 register enum dwarf_attribute attr_kind;
3452 register dw_attr_ref a = get_AT (die, attr_kind);
3454 if (a && a->dw_attr_val.val_class == dw_val_class_str)
3455 return a->dw_attr_val.v.val_str;
3460 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3461 if it is not present. */
3464 get_AT_flag (die, attr_kind)
3465 register dw_die_ref die;
3466 register enum dwarf_attribute attr_kind;
3468 register dw_attr_ref a = get_AT (die, attr_kind);
3470 if (a && a->dw_attr_val.val_class == dw_val_class_flag)
3471 return a->dw_attr_val.v.val_flag;
3476 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3477 if it is not present. */
3479 static inline unsigned
3480 get_AT_unsigned (die, attr_kind)
3481 register dw_die_ref die;
3482 register enum dwarf_attribute attr_kind;
3484 register dw_attr_ref a = get_AT (die, attr_kind);
3486 if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
3487 return a->dw_attr_val.v.val_unsigned;
3495 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3497 return (lang == DW_LANG_C || lang == DW_LANG_C89
3498 || lang == DW_LANG_C_plus_plus);
3504 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3506 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
3509 /* Remove the specified attribute if present. */
3512 remove_AT (die, attr_kind)
3513 register dw_die_ref die;
3514 register enum dwarf_attribute attr_kind;
3516 register dw_attr_ref a;
3517 register dw_attr_ref removed = NULL;;
3521 if (die->die_attr->dw_attr == attr_kind)
3523 removed = die->die_attr;
3524 if (die->die_attr_last == die->die_attr)
3525 die->die_attr_last = NULL;
3527 die->die_attr = die->die_attr->dw_attr_next;
3531 for (a = die->die_attr; a->dw_attr_next != NULL;
3532 a = a->dw_attr_next)
3533 if (a->dw_attr_next->dw_attr == attr_kind)
3535 removed = a->dw_attr_next;
3536 if (die->die_attr_last == a->dw_attr_next)
3537 die->die_attr_last = a;
3539 a->dw_attr_next = a->dw_attr_next->dw_attr_next;
3548 /* Discard the children of this DIE. */
3551 remove_children (die)
3552 register dw_die_ref die;
3554 register dw_die_ref child_die = die->die_child;
3556 die->die_child = NULL;
3557 die->die_child_last = NULL;
3559 while (child_die != NULL)
3561 register dw_die_ref tmp_die = child_die;
3562 register dw_attr_ref a;
3564 child_die = child_die->die_sib;
3566 for (a = tmp_die->die_attr; a != NULL; )
3568 register dw_attr_ref tmp_a = a;
3570 a = a->dw_attr_next;
3578 /* Add a child DIE below its parent. */
3581 add_child_die (die, child_die)
3582 register dw_die_ref die;
3583 register dw_die_ref child_die;
3585 if (die != NULL && child_die != NULL)
3587 assert (die != child_die);
3588 child_die->die_parent = die;
3589 child_die->die_sib = NULL;
3591 if (die->die_child == NULL)
3593 die->die_child = child_die;
3594 die->die_child_last = child_die;
3598 die->die_child_last->die_sib = child_die;
3599 die->die_child_last = child_die;
3604 /* Return a pointer to a newly created DIE node. */
3606 static inline dw_die_ref
3607 new_die (tag_value, parent_die)
3608 register enum dwarf_tag tag_value;
3609 register dw_die_ref parent_die;
3611 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
3613 die->die_tag = tag_value;
3614 die->die_abbrev = 0;
3615 die->die_offset = 0;
3616 die->die_child = NULL;
3617 die->die_parent = NULL;
3618 die->die_sib = NULL;
3619 die->die_child_last = NULL;
3620 die->die_attr = NULL;
3621 die->die_attr_last = NULL;
3623 if (parent_die != NULL)
3624 add_child_die (parent_die, die);
3627 limbo_die_node *limbo_node;
3629 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
3630 limbo_node->die = die;
3631 limbo_node->next = limbo_die_list;
3632 limbo_die_list = limbo_node;
3638 /* Return the DIE associated with the given type specifier. */
3640 static inline dw_die_ref
3641 lookup_type_die (type)
3644 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
3647 /* Equate a DIE to a given type specifier. */
3650 equate_type_number_to_die (type, type_die)
3652 register dw_die_ref type_die;
3654 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
3657 /* Return the DIE associated with a given declaration. */
3659 static inline dw_die_ref
3660 lookup_decl_die (decl)
3663 register unsigned decl_id = DECL_UID (decl);
3665 return (decl_id < decl_die_table_in_use
3666 ? decl_die_table[decl_id] : NULL);
3669 /* Equate a DIE to a particular declaration. */
3672 equate_decl_number_to_die (decl, decl_die)
3674 register dw_die_ref decl_die;
3676 register unsigned decl_id = DECL_UID (decl);
3677 register unsigned i;
3678 register unsigned num_allocated;
3680 if (decl_id >= decl_die_table_allocated)
3683 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
3684 / DECL_DIE_TABLE_INCREMENT)
3685 * DECL_DIE_TABLE_INCREMENT;
3688 = (dw_die_ref *) xrealloc (decl_die_table,
3689 sizeof (dw_die_ref) * num_allocated);
3691 bzero ((char *) &decl_die_table[decl_die_table_allocated],
3692 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
3693 decl_die_table_allocated = num_allocated;
3696 if (decl_id >= decl_die_table_in_use)
3697 decl_die_table_in_use = (decl_id + 1);
3699 decl_die_table[decl_id] = decl_die;
3702 /* Return a pointer to a newly allocated location description. Location
3703 descriptions are simple expression terms that can be strung
3704 together to form more complicated location (address) descriptions. */
3706 static inline dw_loc_descr_ref
3707 new_loc_descr (op, oprnd1, oprnd2)
3708 register enum dwarf_location_atom op;
3709 register unsigned long oprnd1;
3710 register unsigned long oprnd2;
3712 register dw_loc_descr_ref descr
3713 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
3715 descr->dw_loc_next = NULL;
3716 descr->dw_loc_opc = op;
3717 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3718 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3719 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3720 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3725 /* Add a location description term to a location description expression. */
3728 add_loc_descr (list_head, descr)
3729 register dw_loc_descr_ref *list_head;
3730 register dw_loc_descr_ref descr;
3732 register dw_loc_descr_ref *d;
3734 /* Find the end of the chain. */
3735 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3741 /* Keep track of the number of spaces used to indent the
3742 output of the debugging routines that print the structure of
3743 the DIE internal representation. */
3744 static int print_indent;
3746 /* Indent the line the number of spaces given by print_indent. */
3749 print_spaces (outfile)
3752 fprintf (outfile, "%*s", print_indent, "");
3755 /* Print the information assoaciated with a given DIE, and its children.
3756 This routine is a debugging aid only. */
3759 print_die (die, outfile)
3763 register dw_attr_ref a;
3764 register dw_die_ref c;
3766 print_spaces (outfile);
3767 fprintf (outfile, "DIE %4u: %s\n",
3768 die->die_offset, dwarf_tag_name (die->die_tag));
3769 print_spaces (outfile);
3770 fprintf (outfile, " abbrev id: %u", die->die_abbrev);
3771 fprintf (outfile, " offset: %u\n", die->die_offset);
3773 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3775 print_spaces (outfile);
3776 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
3778 switch (a->dw_attr_val.val_class)
3780 case dw_val_class_addr:
3781 fprintf (outfile, "address");
3783 case dw_val_class_loc:
3784 fprintf (outfile, "location descriptor");
3786 case dw_val_class_const:
3787 fprintf (outfile, "%d", a->dw_attr_val.v.val_int);
3789 case dw_val_class_unsigned_const:
3790 fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned);
3792 case dw_val_class_long_long:
3793 fprintf (outfile, "constant (%u,%u)",
3794 a->dw_attr_val.v.val_long_long.hi,
3795 a->dw_attr_val.v.val_long_long.low);
3797 case dw_val_class_float:
3798 fprintf (outfile, "floating-point constant");
3800 case dw_val_class_flag:
3801 fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
3803 case dw_val_class_die_ref:
3804 if (a->dw_attr_val.v.val_die_ref != NULL)
3805 fprintf (outfile, "die -> %u",
3806 a->dw_attr_val.v.val_die_ref->die_offset);
3808 fprintf (outfile, "die -> <null>");
3810 case dw_val_class_lbl_id:
3811 fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
3813 case dw_val_class_section_offset:
3814 fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section);
3816 case dw_val_class_str:
3817 if (a->dw_attr_val.v.val_str != NULL)
3818 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
3820 fprintf (outfile, "<null>");
3824 fprintf (outfile, "\n");
3827 if (die->die_child != NULL)
3830 for (c = die->die_child; c != NULL; c = c->die_sib)
3831 print_die (c, outfile);
3837 /* Print the contents of the source code line number correspondence table.
3838 This routine is a debugging aid only. */
3841 print_dwarf_line_table (outfile)
3844 register unsigned i;
3845 register dw_line_info_ref line_info;
3847 fprintf (outfile, "\n\nDWARF source line information\n");
3848 for (i = 1; i < line_info_table_in_use; ++i)
3850 line_info = &line_info_table[i];
3851 fprintf (outfile, "%5d: ", i);
3852 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
3853 fprintf (outfile, "%6d", line_info->dw_line_num);
3854 fprintf (outfile, "\n");
3857 fprintf (outfile, "\n\n");
3860 /* Print the information collected for a given DIE. */
3863 debug_dwarf_die (die)
3866 print_die (die, stderr);
3869 /* Print all DWARF information collected for the compilation unit.
3870 This routine is a debugging aid only. */
3876 print_die (comp_unit_die, stderr);
3877 print_dwarf_line_table (stderr);
3880 /* Traverse the DIE, and add a sibling attribute if it may have the
3881 effect of speeding up access to siblings. To save some space,
3882 avoid generating sibling attributes for DIE's without children. */
3885 add_sibling_attributes(die)
3886 register dw_die_ref die;
3888 register dw_die_ref c;
3889 register dw_attr_ref attr;
3890 if (die != comp_unit_die && die->die_child != NULL)
3892 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3893 attr->dw_attr_next = NULL;
3894 attr->dw_attr = DW_AT_sibling;
3895 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3896 attr->dw_attr_val.v.val_die_ref = die->die_sib;
3898 /* Add the sibling link to the front of the attribute list. */
3899 attr->dw_attr_next = die->die_attr;
3900 if (die->die_attr == NULL)
3901 die->die_attr_last = attr;
3903 die->die_attr = attr;
3906 for (c = die->die_child; c != NULL; c = c->die_sib)
3907 add_sibling_attributes (c);
3910 /* The format of each DIE (and its attribute value pairs)
3911 is encoded in an abbreviation table. This routine builds the
3912 abbreviation table and assigns a unique abbreviation id for
3913 each abbreviation entry. The children of each die are visited
3917 build_abbrev_table (die)
3918 register dw_die_ref die;
3920 register unsigned long abbrev_id;
3921 register unsigned long n_alloc;
3922 register dw_die_ref c;
3923 register dw_attr_ref d_attr, a_attr;
3924 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
3926 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
3928 if (abbrev->die_tag == die->die_tag)
3930 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
3932 a_attr = abbrev->die_attr;
3933 d_attr = die->die_attr;
3935 while (a_attr != NULL && d_attr != NULL)
3937 if ((a_attr->dw_attr != d_attr->dw_attr)
3938 || (value_format (&a_attr->dw_attr_val)
3939 != value_format (&d_attr->dw_attr_val)))
3942 a_attr = a_attr->dw_attr_next;
3943 d_attr = d_attr->dw_attr_next;
3946 if (a_attr == NULL && d_attr == NULL)
3952 if (abbrev_id >= abbrev_die_table_in_use)
3954 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
3956 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
3958 = (dw_die_ref *) xmalloc (abbrev_die_table,
3959 sizeof (dw_die_ref) * n_alloc);
3961 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
3962 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
3963 abbrev_die_table_allocated = n_alloc;
3966 ++abbrev_die_table_in_use;
3967 abbrev_die_table[abbrev_id] = die;
3970 die->die_abbrev = abbrev_id;
3971 for (c = die->die_child; c != NULL; c = c->die_sib)
3972 build_abbrev_table (c);
3975 /* Return the size of a string, including the null byte. */
3977 static unsigned long
3978 size_of_string (str)
3981 register unsigned long size = 0;
3982 register unsigned long slen = strlen (str);
3983 register unsigned long i;
3984 register unsigned c;
3986 for (i = 0; i < slen; ++i)
3995 /* Null terminator. */
4000 /* Return the size of a location descriptor. */
4002 static unsigned long
4003 size_of_loc_descr (loc)
4004 register dw_loc_descr_ref loc;
4006 register unsigned long size = 1;
4008 switch (loc->dw_loc_opc)
4030 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4033 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4038 case DW_OP_plus_uconst:
4039 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4077 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4080 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4083 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4086 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4087 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4090 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4092 case DW_OP_deref_size:
4093 case DW_OP_xderef_size:
4103 /* Return the size of a series of location descriptors. */
4105 static unsigned long
4107 register dw_loc_descr_ref loc;
4109 register unsigned long size = 0;
4111 for (; loc != NULL; loc = loc->dw_loc_next)
4112 size += size_of_loc_descr (loc);
4117 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4120 constant_size (value)
4121 long unsigned value;
4128 log = floor_log2 (value);
4131 log = 1 << (floor_log2 (log) + 1);
4136 /* Return the size of a DIE, as it is represented in the
4137 .debug_info section. */
4139 static unsigned long
4141 register dw_die_ref die;
4143 register unsigned long size = 0;
4144 register dw_attr_ref a;
4146 size += size_of_uleb128 (die->die_abbrev);
4147 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4149 switch (a->dw_attr_val.val_class)
4151 case dw_val_class_addr:
4154 case dw_val_class_loc:
4156 register unsigned long lsize
4157 = size_of_locs (a->dw_attr_val.v.val_loc);
4160 size += constant_size (lsize);
4164 case dw_val_class_const:
4167 case dw_val_class_unsigned_const:
4168 size += constant_size (a->dw_attr_val.v.val_unsigned);
4170 case dw_val_class_long_long:
4171 size += 1 + 8; /* block */
4173 case dw_val_class_float:
4174 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
4176 case dw_val_class_flag:
4179 case dw_val_class_die_ref:
4180 size += DWARF_OFFSET_SIZE;
4182 case dw_val_class_fde_ref:
4183 size += DWARF_OFFSET_SIZE;
4185 case dw_val_class_lbl_id:
4188 case dw_val_class_section_offset:
4189 size += DWARF_OFFSET_SIZE;
4191 case dw_val_class_str:
4192 size += size_of_string (a->dw_attr_val.v.val_str);
4202 /* Size the debgging information associted with a given DIE.
4203 Visits the DIE's children recursively. Updates the global
4204 variable next_die_offset, on each time through. Uses the
4205 current value of next_die_offset to updete the die_offset
4206 field in each DIE. */
4209 calc_die_sizes (die)
4212 register dw_die_ref c;
4213 die->die_offset = next_die_offset;
4214 next_die_offset += size_of_die (die);
4216 for (c = die->die_child; c != NULL; c = c->die_sib)
4219 if (die->die_child != NULL)
4220 /* Count the null byte used to terminate sibling lists. */
4221 next_die_offset += 1;
4224 /* Return the size of the line information prolog generated for the
4225 compilation unit. */
4227 static unsigned long
4228 size_of_line_prolog ()
4230 register unsigned long size;
4231 register unsigned long ft_index;
4233 size = DWARF_LINE_PROLOG_HEADER_SIZE;
4235 /* Count the size of the table giving number of args for each
4237 size += DWARF_LINE_OPCODE_BASE - 1;
4239 /* Include directory table is empty (at present). Count only the
4240 the null byte used to terminate the table. */
4243 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4245 /* File name entry. */
4246 size += size_of_string (file_table[ft_index]);
4248 /* Include directory index. */
4249 size += size_of_uleb128 (0);
4251 /* Modification time. */
4252 size += size_of_uleb128 (0);
4254 /* File length in bytes. */
4255 size += size_of_uleb128 (0);
4258 /* Count the file table terminator. */
4263 /* Return the size of the line information generated for this
4264 compilation unit. */
4266 static unsigned long
4267 size_of_line_info ()
4269 register unsigned long size;
4270 register unsigned long lt_index;
4271 register unsigned long current_line;
4272 register long line_offset;
4273 register long line_delta;
4274 register unsigned long current_file;
4275 register unsigned long function;
4276 unsigned long size_of_set_address;
4278 /* Size of a DW_LNE_set_address instruction. */
4279 size_of_set_address = 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
4281 /* Version number. */
4284 /* Prolog length specifier. */
4285 size += DWARF_OFFSET_SIZE;
4288 size += size_of_line_prolog ();
4290 /* Set address register instruction. */
4291 size += size_of_set_address;
4295 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
4297 register dw_line_info_ref line_info;
4299 /* Advance pc instruction. */
4300 /* ??? See the DW_LNS_advance_pc comment in output_line_info. */
4304 size += size_of_set_address;
4306 line_info = &line_info_table[lt_index];
4307 if (line_info->dw_file_num != current_file)
4309 /* Set file number instruction. */
4311 current_file = line_info->dw_file_num;
4312 size += size_of_uleb128 (current_file);
4315 if (line_info->dw_line_num != current_line)
4317 line_offset = line_info->dw_line_num - current_line;
4318 line_delta = line_offset - DWARF_LINE_BASE;
4319 current_line = line_info->dw_line_num;
4320 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4321 /* 1-byte special line number instruction. */
4325 /* Advance line instruction. */
4327 size += size_of_sleb128 (line_offset);
4328 /* Generate line entry instruction. */
4334 /* Advance pc instruction. */
4338 size += size_of_set_address;
4340 /* End of line number info. marker. */
4341 size += 1 + size_of_uleb128 (1) + 1;
4346 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
4348 register dw_separate_line_info_ref line_info
4349 = &separate_line_info_table[lt_index];
4350 if (function != line_info->function)
4352 function = line_info->function;
4353 /* Set address register instruction. */
4354 size += size_of_set_address;
4358 /* Advance pc instruction. */
4362 size += size_of_set_address;
4365 if (line_info->dw_file_num != current_file)
4367 /* Set file number instruction. */
4369 current_file = line_info->dw_file_num;
4370 size += size_of_uleb128 (current_file);
4373 if (line_info->dw_line_num != current_line)
4375 line_offset = line_info->dw_line_num - current_line;
4376 line_delta = line_offset - DWARF_LINE_BASE;
4377 current_line = line_info->dw_line_num;
4378 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4379 /* 1-byte special line number instruction. */
4383 /* Advance line instruction. */
4385 size += size_of_sleb128 (line_offset);
4387 /* Generate line entry instruction. */
4394 /* If we're done with a function, end its sequence. */
4395 if (lt_index == separate_line_info_table_in_use
4396 || separate_line_info_table[lt_index].function != function)
4401 /* Advance pc instruction. */
4405 size += size_of_set_address;
4407 /* End of line number info. marker. */
4408 size += 1 + size_of_uleb128 (1) + 1;
4415 /* Return the size of the .debug_pubnames table generated for the
4416 compilation unit. */
4418 static unsigned long
4421 register unsigned long size;
4422 register unsigned i;
4424 size = DWARF_PUBNAMES_HEADER_SIZE;
4425 for (i = 0; i < pubname_table_in_use; ++i)
4427 register pubname_ref p = &pubname_table[i];
4428 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
4431 size += DWARF_OFFSET_SIZE;
4435 /* Return the size of the information in the .debug_aranges seciton. */
4437 static unsigned long
4440 register unsigned long size;
4442 size = DWARF_ARANGES_HEADER_SIZE;
4444 /* Count the address/length pair for this compilation unit. */
4445 size += 2 * PTR_SIZE;
4446 size += 2 * PTR_SIZE * arange_table_in_use;
4448 /* Count the two zero words used to terminated the address range table. */
4449 size += 2 * PTR_SIZE;
4453 /* Select the encoding of an attribute value. */
4455 static enum dwarf_form
4459 switch (v->val_class)
4461 case dw_val_class_addr:
4462 return DW_FORM_addr;
4463 case dw_val_class_loc:
4464 switch (constant_size (size_of_locs (v->v.val_loc)))
4467 return DW_FORM_block1;
4469 return DW_FORM_block2;
4473 case dw_val_class_const:
4474 return DW_FORM_data4;
4475 case dw_val_class_unsigned_const:
4476 switch (constant_size (v->v.val_unsigned))
4479 return DW_FORM_data1;
4481 return DW_FORM_data2;
4483 return DW_FORM_data4;
4485 return DW_FORM_data8;
4489 case dw_val_class_long_long:
4490 return DW_FORM_block1;
4491 case dw_val_class_float:
4492 return DW_FORM_block1;
4493 case dw_val_class_flag:
4494 return DW_FORM_flag;
4495 case dw_val_class_die_ref:
4497 case dw_val_class_fde_ref:
4498 return DW_FORM_data;
4499 case dw_val_class_lbl_id:
4500 return DW_FORM_addr;
4501 case dw_val_class_section_offset:
4502 return DW_FORM_data;
4503 case dw_val_class_str:
4504 return DW_FORM_string;
4510 /* Output the encoding of an attribute value. */
4513 output_value_format (v)
4516 enum dwarf_form form = value_format (v);
4518 output_uleb128 (form);
4519 if (flag_verbose_asm)
4520 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
4522 fputc ('\n', asm_out_file);
4525 /* Output the .debug_abbrev section which defines the DIE abbreviation
4529 output_abbrev_section ()
4531 unsigned long abbrev_id;
4534 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4536 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4538 output_uleb128 (abbrev_id);
4539 if (flag_verbose_asm)
4540 fprintf (asm_out_file, " (abbrev code)");
4542 fputc ('\n', asm_out_file);
4543 output_uleb128 (abbrev->die_tag);
4544 if (flag_verbose_asm)
4545 fprintf (asm_out_file, " (TAG: %s)",
4546 dwarf_tag_name (abbrev->die_tag));
4548 fputc ('\n', asm_out_file);
4549 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
4550 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
4552 if (flag_verbose_asm)
4553 fprintf (asm_out_file, "\t%s %s",
4555 (abbrev->die_child != NULL
4556 ? "DW_children_yes" : "DW_children_no"));
4558 fputc ('\n', asm_out_file);
4560 for (a_attr = abbrev->die_attr; a_attr != NULL;
4561 a_attr = a_attr->dw_attr_next)
4563 output_uleb128 (a_attr->dw_attr);
4564 if (flag_verbose_asm)
4565 fprintf (asm_out_file, " (%s)",
4566 dwarf_attr_name (a_attr->dw_attr));
4568 fputc ('\n', asm_out_file);
4569 output_value_format (&a_attr->dw_attr_val);
4572 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
4576 /* Output location description stack opcode's operands (if any). */
4579 output_loc_operands (loc)
4580 register dw_loc_descr_ref loc;
4582 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
4583 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
4585 switch (loc->dw_loc_opc)
4588 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
4589 fputc ('\n', asm_out_file);
4593 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4594 fputc ('\n', asm_out_file);
4598 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4599 fputc ('\n', asm_out_file);
4603 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
4604 fputc ('\n', asm_out_file);
4609 fputc ('\n', asm_out_file);
4612 output_uleb128 (val1->v.val_unsigned);
4613 fputc ('\n', asm_out_file);
4616 output_sleb128 (val1->v.val_int);
4617 fputc ('\n', asm_out_file);
4620 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
4621 fputc ('\n', asm_out_file);
4623 case DW_OP_plus_uconst:
4624 output_uleb128 (val1->v.val_unsigned);
4625 fputc ('\n', asm_out_file);
4629 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4630 fputc ('\n', asm_out_file);
4664 output_sleb128 (val1->v.val_int);
4665 fputc ('\n', asm_out_file);
4668 output_uleb128 (val1->v.val_unsigned);
4669 fputc ('\n', asm_out_file);
4672 output_sleb128 (val1->v.val_int);
4673 fputc ('\n', asm_out_file);
4676 output_uleb128 (val1->v.val_unsigned);
4677 fputc ('\n', asm_out_file);
4678 output_sleb128 (val2->v.val_int);
4679 fputc ('\n', asm_out_file);
4682 output_uleb128 (val1->v.val_unsigned);
4683 fputc ('\n', asm_out_file);
4685 case DW_OP_deref_size:
4686 case DW_OP_xderef_size:
4687 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4688 fputc ('\n', asm_out_file);
4695 /* Compute the offset of a sibling. */
4697 static unsigned long
4698 sibling_offset (die)
4701 unsigned long offset;
4703 if (die->die_child_last == NULL)
4704 offset = die->die_offset + size_of_die (die);
4706 offset = sibling_offset (die->die_child_last) + 1;
4711 /* Output the DIE and its attributes. Called recursively to generate
4712 the definitions of each child DIE. */
4716 register dw_die_ref die;
4718 register dw_attr_ref a;
4719 register dw_die_ref c;
4720 register unsigned long ref_offset;
4721 register unsigned long size;
4722 register dw_loc_descr_ref loc;
4725 output_uleb128 (die->die_abbrev);
4726 if (flag_verbose_asm)
4727 fprintf (asm_out_file, " (DIE (0x%x) %s)",
4728 die->die_offset, dwarf_tag_name (die->die_tag));
4730 fputc ('\n', asm_out_file);
4732 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4734 switch (a->dw_attr_val.val_class)
4736 case dw_val_class_addr:
4737 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
4738 a->dw_attr_val.v.val_addr);
4741 case dw_val_class_loc:
4742 size = size_of_locs (a->dw_attr_val.v.val_loc);
4744 /* Output the block length for this list of location operations. */
4745 switch (constant_size (size))
4748 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
4751 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
4757 if (flag_verbose_asm)
4758 fprintf (asm_out_file, "\t%s %s",
4759 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
4761 fputc ('\n', asm_out_file);
4762 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
4763 loc = loc->dw_loc_next)
4765 /* Output the opcode. */
4766 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
4767 if (flag_verbose_asm)
4768 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
4769 dwarf_stack_op_name (loc->dw_loc_opc));
4771 fputc ('\n', asm_out_file);
4773 /* Output the operand(s) (if any). */
4774 output_loc_operands (loc);
4778 case dw_val_class_const:
4779 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
4782 case dw_val_class_unsigned_const:
4783 switch (constant_size (a->dw_attr_val.v.val_unsigned))
4786 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4787 a->dw_attr_val.v.val_unsigned);
4790 ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
4791 a->dw_attr_val.v.val_unsigned);
4794 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
4795 a->dw_attr_val.v.val_unsigned);
4798 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
4799 a->dw_attr_val.v.val_long_long.hi,
4800 a->dw_attr_val.v.val_long_long.low);
4807 case dw_val_class_long_long:
4808 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
4809 if (flag_verbose_asm)
4810 fprintf (asm_out_file, "\t%s %s",
4811 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
4813 fputc ('\n', asm_out_file);
4814 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
4815 a->dw_attr_val.v.val_long_long.hi,
4816 a->dw_attr_val.v.val_long_long.low);
4818 if (flag_verbose_asm)
4819 fprintf (asm_out_file,
4820 "\t%s long long constant", ASM_COMMENT_START);
4822 fputc ('\n', asm_out_file);
4825 case dw_val_class_float:
4826 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4827 a->dw_attr_val.v.val_float.length * 4);
4828 if (flag_verbose_asm)
4829 fprintf (asm_out_file, "\t%s %s",
4830 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
4832 fputc ('\n', asm_out_file);
4833 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
4835 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
4836 a->dw_attr_val.v.val_float.array[i]);
4837 if (flag_verbose_asm)
4838 fprintf (asm_out_file, "\t%s fp constant word %d",
4839 ASM_COMMENT_START, i);
4841 fputc ('\n', asm_out_file);
4845 case dw_val_class_flag:
4846 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
4849 case dw_val_class_die_ref:
4850 if (a->dw_attr_val.v.val_die_ref != NULL)
4851 ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
4852 else if (a->dw_attr == DW_AT_sibling)
4853 ref_offset = sibling_offset(die);
4857 ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
4860 case dw_val_class_fde_ref:
4863 ASM_GENERATE_INTERNAL_LABEL
4864 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
4865 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
4866 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
4870 case dw_val_class_lbl_id:
4871 ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
4874 case dw_val_class_section_offset:
4875 ASM_OUTPUT_DWARF_OFFSET (asm_out_file,
4877 (a->dw_attr_val.v.val_section));
4880 case dw_val_class_str:
4881 ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
4888 if (a->dw_attr_val.val_class != dw_val_class_loc
4889 && a->dw_attr_val.val_class != dw_val_class_long_long
4890 && a->dw_attr_val.val_class != dw_val_class_float)
4892 if (flag_verbose_asm)
4893 fprintf (asm_out_file, "\t%s %s",
4894 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
4896 fputc ('\n', asm_out_file);
4900 for (c = die->die_child; c != NULL; c = c->die_sib)
4903 if (die->die_child != NULL)
4905 /* Add null byte to terminate sibling list. */
4906 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4907 if (flag_verbose_asm)
4908 fprintf (asm_out_file, "\t%s end of children of DIE 0x%x",
4909 ASM_COMMENT_START, die->die_offset);
4911 fputc ('\n', asm_out_file);
4915 /* Output the compilation unit that appears at the beginning of the
4916 .debug_info section, and precedes the DIE descriptions. */
4919 output_compilation_unit_header ()
4921 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
4922 if (flag_verbose_asm)
4923 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
4926 fputc ('\n', asm_out_file);
4927 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4928 if (flag_verbose_asm)
4929 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
4931 fputc ('\n', asm_out_file);
4932 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION));
4933 if (flag_verbose_asm)
4934 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
4937 fputc ('\n', asm_out_file);
4938 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
4939 if (flag_verbose_asm)
4940 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
4942 fputc ('\n', asm_out_file);
4945 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
4946 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
4947 argument list, and maybe the scope. */
4950 dwarf2_name (decl, scope)
4954 return (*decl_printable_name) (decl, scope ? 1 : 0);
4957 /* Add a new entry to .debug_pubnames if appropriate. */
4960 add_pubname (decl, die)
4966 if (! TREE_PUBLIC (decl))
4969 if (pubname_table_in_use == pubname_table_allocated)
4971 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
4972 pubname_table = (pubname_ref) xrealloc
4973 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
4976 p = &pubname_table[pubname_table_in_use++];
4979 p->name = xstrdup (dwarf2_name (decl, 1));
4982 /* Output the public names table used to speed up access to externally
4983 visible names. For now, only generate entries for externally
4984 visible procedures. */
4989 register unsigned i;
4990 register unsigned long pubnames_length = size_of_pubnames ();
4992 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
4994 if (flag_verbose_asm)
4995 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
4998 fputc ('\n', asm_out_file);
4999 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5001 if (flag_verbose_asm)
5002 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5004 fputc ('\n', asm_out_file);
5005 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_INFO_SECTION));
5006 if (flag_verbose_asm)
5007 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5010 fputc ('\n', asm_out_file);
5011 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
5012 if (flag_verbose_asm)
5013 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
5015 fputc ('\n', asm_out_file);
5016 for (i = 0; i < pubname_table_in_use; ++i)
5018 register pubname_ref pub = &pubname_table[i];
5020 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
5021 if (flag_verbose_asm)
5022 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
5024 fputc ('\n', asm_out_file);
5026 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
5027 if (flag_verbose_asm)
5028 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
5030 fputc ('\n', asm_out_file);
5033 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
5034 fputc ('\n', asm_out_file);
5037 /* Add a new entry to .debug_aranges if appropriate. */
5040 add_arange (decl, die)
5044 if (! DECL_SECTION_NAME (decl))
5047 if (arange_table_in_use == arange_table_allocated)
5049 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5051 = (arange_ref) xrealloc (arange_table,
5052 arange_table_allocated * sizeof (dw_die_ref));
5055 arange_table[arange_table_in_use++] = die;
5058 /* Output the information that goes into the .debug_aranges table.
5059 Namely, define the beginning and ending address range of the
5060 text section generated for this compilation unit. */
5065 register unsigned i;
5066 register unsigned long aranges_length = size_of_aranges ();
5068 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
5069 if (flag_verbose_asm)
5070 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
5073 fputc ('\n', asm_out_file);
5074 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5075 if (flag_verbose_asm)
5076 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5078 fputc ('\n', asm_out_file);
5079 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_INFO_SECTION));
5080 if (flag_verbose_asm)
5081 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5084 fputc ('\n', asm_out_file);
5085 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5086 if (flag_verbose_asm)
5087 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
5089 fputc ('\n', asm_out_file);
5090 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5091 if (flag_verbose_asm)
5092 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
5095 fputc ('\n', asm_out_file);
5096 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
5098 fprintf (asm_out_file, ",0,0");
5100 if (flag_verbose_asm)
5101 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5102 ASM_COMMENT_START, 2 * PTR_SIZE);
5104 fputc ('\n', asm_out_file);
5105 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
5106 if (flag_verbose_asm)
5107 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5109 fputc ('\n', asm_out_file);
5110 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label, TEXT_SECTION);
5111 if (flag_verbose_asm)
5112 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5114 fputc ('\n', asm_out_file);
5115 for (i = 0; i < arange_table_in_use; ++i)
5117 dw_die_ref a = arange_table[i];
5119 if (a->die_tag == DW_TAG_subprogram)
5120 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a));
5123 char *name = get_AT_string (a, DW_AT_MIPS_linkage_name);
5125 name = get_AT_string (a, DW_AT_name);
5127 ASM_OUTPUT_DWARF_ADDR (asm_out_file, name);
5130 if (flag_verbose_asm)
5131 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5133 fputc ('\n', asm_out_file);
5134 if (a->die_tag == DW_TAG_subprogram)
5135 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a),
5138 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5139 get_AT_unsigned (a, DW_AT_byte_size));
5141 if (flag_verbose_asm)
5142 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5144 fputc ('\n', asm_out_file);
5147 /* Output the terminator words. */
5148 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5149 fputc ('\n', asm_out_file);
5150 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5151 fputc ('\n', asm_out_file);
5154 /* Output the source line number correspondence information. This
5155 information goes into the .debug_line section.
5157 If the format of this data changes, then the function size_of_line_info
5158 must also be adjusted the same way. */
5163 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5164 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5165 register unsigned opc;
5166 register unsigned n_op_args;
5167 register unsigned long ft_index;
5168 register unsigned long lt_index;
5169 register unsigned long current_line;
5170 register long line_offset;
5171 register long line_delta;
5172 register unsigned long current_file;
5173 register unsigned long function;
5175 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ());
5176 if (flag_verbose_asm)
5177 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5180 fputc ('\n', asm_out_file);
5181 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5182 if (flag_verbose_asm)
5183 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5185 fputc ('\n', asm_out_file);
5186 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
5187 if (flag_verbose_asm)
5188 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5190 fputc ('\n', asm_out_file);
5191 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
5192 if (flag_verbose_asm)
5193 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5196 fputc ('\n', asm_out_file);
5197 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
5198 if (flag_verbose_asm)
5199 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5202 fputc ('\n', asm_out_file);
5203 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
5204 if (flag_verbose_asm)
5205 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5208 fputc ('\n', asm_out_file);
5209 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
5210 if (flag_verbose_asm)
5211 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5214 fputc ('\n', asm_out_file);
5215 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5216 if (flag_verbose_asm)
5217 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5219 fputc ('\n', asm_out_file);
5220 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5224 case DW_LNS_advance_pc:
5225 case DW_LNS_advance_line:
5226 case DW_LNS_set_file:
5227 case DW_LNS_set_column:
5228 case DW_LNS_fixed_advance_pc:
5235 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5236 if (flag_verbose_asm)
5237 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5238 ASM_COMMENT_START, opc, n_op_args);
5239 fputc ('\n', asm_out_file);
5242 if (flag_verbose_asm)
5243 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5245 /* Include directory table is empty, at present */
5246 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5247 fputc ('\n', asm_out_file);
5248 if (flag_verbose_asm)
5249 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5251 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5253 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5254 if (flag_verbose_asm)
5255 fprintf (asm_out_file, "%s File Entry: 0x%x",
5256 ASM_COMMENT_START, ft_index);
5258 fputc ('\n', asm_out_file);
5260 /* Include directory index */
5262 fputc ('\n', asm_out_file);
5264 /* Modification time */
5266 fputc ('\n', asm_out_file);
5268 /* File length in bytes */
5270 fputc ('\n', asm_out_file);
5273 /* Terminate the file name table */
5274 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5275 fputc ('\n', asm_out_file);
5277 /* Set the address register to the first location in the text section */
5278 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5279 if (flag_verbose_asm)
5280 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5282 fputc ('\n', asm_out_file);
5283 output_uleb128 (1 + PTR_SIZE);
5284 fputc ('\n', asm_out_file);
5285 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5286 fputc ('\n', asm_out_file);
5287 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
5288 fputc ('\n', asm_out_file);
5290 /* Generate the line number to PC correspondence table, encoded as
5291 a series of state machine operations. */
5294 strcpy (prev_line_label, TEXT_SECTION);
5295 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5297 register dw_line_info_ref line_info;
5299 /* Emit debug info for the address of the current line, choosing
5300 the encoding that uses the least amount of space. */
5301 /* ??? Unfortunately, we have little choice here currently, and must
5302 always use the most general form. Gcc does not know the address
5303 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5304 dwarf2 aware assemblers at this time, so we can't use any special
5305 pseudo ops that would allow the assembler to optimally encode this for
5306 us. Many ports do have length attributes which will give an upper
5307 bound on the address range. We could perhaps use length attributes
5308 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5309 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5312 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5313 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5314 if (flag_verbose_asm)
5315 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5318 fputc ('\n', asm_out_file);
5319 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5320 fputc ('\n', asm_out_file);
5324 /* This can handle any delta. This takes 4+PTR_SIZE bytes. */
5325 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5326 if (flag_verbose_asm)
5327 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5329 fputc ('\n', asm_out_file);
5330 output_uleb128 (1 + PTR_SIZE);
5331 fputc ('\n', asm_out_file);
5332 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5333 fputc ('\n', asm_out_file);
5334 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5335 fputc ('\n', asm_out_file);
5337 strcpy (prev_line_label, line_label);
5339 /* Emit debug info for the source file of the current line, if
5340 different from the previous line. */
5341 line_info = &line_info_table[lt_index];
5342 if (line_info->dw_file_num != current_file)
5344 current_file = line_info->dw_file_num;
5345 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5346 if (flag_verbose_asm)
5347 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5349 fputc ('\n', asm_out_file);
5350 output_uleb128 (current_file);
5351 if (flag_verbose_asm)
5352 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5354 fputc ('\n', asm_out_file);
5357 /* Emit debug info for the current line number, choosing the encoding
5358 that uses the least amount of space. */
5359 line_offset = line_info->dw_line_num - current_line;
5360 line_delta = line_offset - DWARF_LINE_BASE;
5361 current_line = line_info->dw_line_num;
5362 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5364 /* This can handle deltas from -10 to 234, using the current
5365 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5367 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5368 DWARF_LINE_OPCODE_BASE + line_delta);
5369 if (flag_verbose_asm)
5370 fprintf (asm_out_file,
5371 "\t%s line %d", ASM_COMMENT_START, current_line);
5373 fputc ('\n', asm_out_file);
5377 /* This can handle any delta. This takes at least 4 bytes, depending
5378 on the value being encoded. */
5379 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5380 if (flag_verbose_asm)
5381 fprintf (asm_out_file, "\t%s advance to line %d",
5382 ASM_COMMENT_START, current_line);
5384 fputc ('\n', asm_out_file);
5385 output_sleb128 (line_offset);
5386 fputc ('\n', asm_out_file);
5387 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5388 fputc ('\n', asm_out_file);
5392 /* Emit debug info for the address of the end of the function. */
5395 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5396 if (flag_verbose_asm)
5397 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5400 fputc ('\n', asm_out_file);
5401 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
5402 fputc ('\n', asm_out_file);
5406 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5407 if (flag_verbose_asm)
5408 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5409 fputc ('\n', asm_out_file);
5410 output_uleb128 (1 + PTR_SIZE);
5411 fputc ('\n', asm_out_file);
5412 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5413 fputc ('\n', asm_out_file);
5414 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
5415 fputc ('\n', asm_out_file);
5418 /* Output the marker for the end of the line number info. */
5419 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5420 if (flag_verbose_asm)
5421 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
5423 fputc ('\n', asm_out_file);
5425 fputc ('\n', asm_out_file);
5426 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5427 fputc ('\n', asm_out_file);
5432 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5434 register dw_separate_line_info_ref line_info
5435 = &separate_line_info_table[lt_index];
5437 /* Emit debug info for the address of the current line. If this is
5438 a new function, or the first line of a function, then we need
5439 to handle it differently. */
5440 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
5442 if (function != line_info->function)
5444 function = line_info->function;
5446 /* Set the address register to the first line in the function */
5447 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5448 if (flag_verbose_asm)
5449 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5452 fputc ('\n', asm_out_file);
5453 output_uleb128 (1 + PTR_SIZE);
5454 fputc ('\n', asm_out_file);
5455 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5456 fputc ('\n', asm_out_file);
5457 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5458 fputc ('\n', asm_out_file);
5462 /* ??? See the DW_LNS_advance_pc comment above. */
5465 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5466 if (flag_verbose_asm)
5467 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5470 fputc ('\n', asm_out_file);
5471 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5473 fputc ('\n', asm_out_file);
5477 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5478 if (flag_verbose_asm)
5479 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5481 fputc ('\n', asm_out_file);
5482 output_uleb128 (1 + PTR_SIZE);
5483 fputc ('\n', asm_out_file);
5484 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5485 fputc ('\n', asm_out_file);
5486 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5487 fputc ('\n', asm_out_file);
5490 strcpy (prev_line_label, line_label);
5492 /* Emit debug info for the source file of the current line, if
5493 different from the previous line. */
5494 if (line_info->dw_file_num != current_file)
5496 current_file = line_info->dw_file_num;
5497 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5498 if (flag_verbose_asm)
5499 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5501 fputc ('\n', asm_out_file);
5502 output_uleb128 (current_file);
5503 if (flag_verbose_asm)
5504 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5506 fputc ('\n', asm_out_file);
5509 /* Emit debug info for the current line number, choosing the encoding
5510 that uses the least amount of space. */
5511 if (line_info->dw_line_num != current_line)
5513 line_offset = line_info->dw_line_num - current_line;
5514 line_delta = line_offset - DWARF_LINE_BASE;
5515 current_line = line_info->dw_line_num;
5516 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5518 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5519 DWARF_LINE_OPCODE_BASE + line_delta);
5520 if (flag_verbose_asm)
5521 fprintf (asm_out_file,
5522 "\t%s line %d", ASM_COMMENT_START, current_line);
5524 fputc ('\n', asm_out_file);
5528 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5529 if (flag_verbose_asm)
5530 fprintf (asm_out_file, "\t%s advance to line %d",
5531 ASM_COMMENT_START, current_line);
5533 fputc ('\n', asm_out_file);
5534 output_sleb128 (line_offset);
5535 fputc ('\n', asm_out_file);
5536 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5537 fputc ('\n', asm_out_file);
5543 /* If we're done with a function, end its sequence. */
5544 if (lt_index == separate_line_info_table_in_use
5545 || separate_line_info_table[lt_index].function != function)
5550 /* Emit debug info for the address of the end of the function. */
5551 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
5554 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5555 if (flag_verbose_asm)
5556 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5559 fputc ('\n', asm_out_file);
5560 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5562 fputc ('\n', asm_out_file);
5566 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5567 if (flag_verbose_asm)
5568 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5570 fputc ('\n', asm_out_file);
5571 output_uleb128 (1 + PTR_SIZE);
5572 fputc ('\n', asm_out_file);
5573 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5574 fputc ('\n', asm_out_file);
5575 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5576 fputc ('\n', asm_out_file);
5579 /* Output the marker for the end of this sequence. */
5580 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5581 if (flag_verbose_asm)
5582 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
5585 fputc ('\n', asm_out_file);
5587 fputc ('\n', asm_out_file);
5588 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5589 fputc ('\n', asm_out_file);
5594 /* Given a pointer to a BLOCK node return non-zero if (and only if) the node
5595 in question represents the outermost pair of curly braces (i.e. the "body
5596 block") of a function or method.
5598 For any BLOCK node representing a "body block" of a function or method, the
5599 BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
5600 represents the outermost (function) scope for the function or method (i.e.
5601 the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
5602 *that* node in turn will point to the relevant FUNCTION_DECL node. */
5605 is_body_block (stmt)
5608 if (TREE_CODE (stmt) == BLOCK)
5610 register tree parent = BLOCK_SUPERCONTEXT (stmt);
5612 if (TREE_CODE (parent) == BLOCK)
5614 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
5616 if (TREE_CODE (grandparent) == FUNCTION_DECL)
5624 /* Given a pointer to a tree node for some base type, return a pointer to
5625 a DIE that describes the given type.
5627 This routine must only be called for GCC type nodes that correspond to
5628 Dwarf base (fundamental) types. */
5631 base_type_die (type)
5634 register dw_die_ref base_type_result;
5635 register char *type_name;
5636 register enum dwarf_type encoding;
5637 register tree name = TYPE_NAME (type);
5639 if (TREE_CODE (type) == ERROR_MARK
5640 || TREE_CODE (type) == VOID_TYPE)
5643 if (TREE_CODE (name) == TYPE_DECL)
5644 name = DECL_NAME (name);
5645 type_name = IDENTIFIER_POINTER (name);
5647 switch (TREE_CODE (type))
5650 /* Carefully distinguish the C character types, without messing
5651 up if the language is not C. Note that we check only for the names
5652 that contain spaces; other names might occur by coincidence in other
5654 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
5655 && (type == char_type_node
5656 || ! strcmp (type_name, "signed char")
5657 || ! strcmp (type_name, "unsigned char"))))
5659 if (TREE_UNSIGNED (type))
5660 encoding = DW_ATE_unsigned;
5662 encoding = DW_ATE_signed;
5665 /* else fall through */
5668 /* GNU Pascal/Ada CHAR type. Not used in C. */
5669 if (TREE_UNSIGNED (type))
5670 encoding = DW_ATE_unsigned_char;
5672 encoding = DW_ATE_signed_char;
5676 encoding = DW_ATE_float;
5680 encoding = DW_ATE_complex_float;
5684 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
5685 encoding = DW_ATE_boolean;
5689 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
5692 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
5693 add_AT_string (base_type_result, DW_AT_name, type_name);
5694 add_AT_unsigned (base_type_result, DW_AT_byte_size,
5695 TYPE_PRECISION (type) / BITS_PER_UNIT);
5696 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
5698 return base_type_result;
5701 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
5702 the Dwarf "root" type for the given input type. The Dwarf "root" type of
5703 a given type is generally the same as the given type, except that if the
5704 given type is a pointer or reference type, then the root type of the given
5705 type is the root type of the "basis" type for the pointer or reference
5706 type. (This definition of the "root" type is recursive.) Also, the root
5707 type of a `const' qualified type or a `volatile' qualified type is the
5708 root type of the given type without the qualifiers. */
5714 if (TREE_CODE (type) == ERROR_MARK)
5715 return error_mark_node;
5717 switch (TREE_CODE (type))
5720 return error_mark_node;
5723 case REFERENCE_TYPE:
5724 return type_main_variant (root_type (TREE_TYPE (type)));
5727 return type_main_variant (type);
5731 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
5732 given input type is a Dwarf "fundamental" type. Otherwise return null. */
5738 switch (TREE_CODE (type))
5753 case QUAL_UNION_TYPE:
5758 case REFERENCE_TYPE:
5771 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
5772 entry that chains various modifiers in front of the given type. */
5775 modified_type_die (type, is_const_type, is_volatile_type, context_die)
5777 register int is_const_type;
5778 register int is_volatile_type;
5779 register dw_die_ref context_die;
5781 register enum tree_code code = TREE_CODE (type);
5782 register dw_die_ref mod_type_die = NULL;
5783 register dw_die_ref sub_die = NULL;
5784 register tree item_type = NULL;
5786 if (code != ERROR_MARK)
5788 type = build_type_variant (type, is_const_type, is_volatile_type);
5790 mod_type_die = lookup_type_die (type);
5792 return mod_type_die;
5794 /* Handle C typedef types. */
5795 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
5796 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
5798 tree dtype = TREE_TYPE (TYPE_NAME (type));
5801 /* For a named type, use the typedef. */
5802 gen_type_die (type, context_die);
5803 mod_type_die = lookup_type_die (type);
5806 else if (is_const_type < TYPE_READONLY (dtype)
5807 || is_volatile_type < TYPE_VOLATILE (dtype))
5808 /* cv-unqualified version of named type. Just use the unnamed
5809 type to which it refers. */
5811 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
5812 is_const_type, is_volatile_type,
5814 /* Else cv-qualified version of named type; fall through. */
5819 else if (is_const_type)
5821 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
5822 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
5824 else if (is_volatile_type)
5826 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
5827 sub_die = modified_type_die (type, 0, 0, context_die);
5829 else if (code == POINTER_TYPE)
5831 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
5832 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
5834 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
5836 item_type = TREE_TYPE (type);
5838 else if (code == REFERENCE_TYPE)
5840 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
5841 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
5843 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
5845 item_type = TREE_TYPE (type);
5847 else if (is_base_type (type))
5848 mod_type_die = base_type_die (type);
5851 gen_type_die (type, context_die);
5853 /* We have to get the type_main_variant here (and pass that to the
5854 `lookup_type_die' routine) because the ..._TYPE node we have
5855 might simply be a *copy* of some original type node (where the
5856 copy was created to help us keep track of typedef names) and
5857 that copy might have a different TYPE_UID from the original
5859 mod_type_die = lookup_type_die (type_main_variant (type));
5860 assert (mod_type_die != NULL);
5864 equate_type_number_to_die (type, mod_type_die);
5866 /* We must do this after the equate_type_number_to_die call, in case
5867 this is a recursive type. This ensures that the modified_type_die
5868 recursion will terminate even if the type is recursive. Recursive
5869 types are possible in Ada. */
5870 sub_die = modified_type_die (item_type,
5871 TYPE_READONLY (item_type),
5872 TYPE_VOLATILE (item_type),
5875 if (sub_die != NULL)
5876 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
5878 return mod_type_die;
5881 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
5882 an enumerated type. */
5888 return TREE_CODE (type) == ENUMERAL_TYPE;
5891 /* Return a location descriptor that designates a machine register. */
5893 static dw_loc_descr_ref
5894 reg_loc_descriptor (rtl)
5897 register dw_loc_descr_ref loc_result = NULL;
5898 register unsigned reg = reg_number (rtl);
5900 if (reg >= 0 && reg <= 31)
5901 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
5903 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
5908 /* Return a location descriptor that designates a base+offset location. */
5910 static dw_loc_descr_ref
5911 based_loc_descr (reg, offset)
5915 register dw_loc_descr_ref loc_result;
5916 /* For the "frame base", we use the frame pointer or stack pointer
5917 registers, since the RTL for local variables is relative to one of
5919 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
5920 ? HARD_FRAME_POINTER_REGNUM
5921 : STACK_POINTER_REGNUM);
5924 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
5925 else if (reg >= 0 && reg <= 31)
5926 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
5928 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
5933 /* Return true if this RTL expression describes a base+offset calculation. */
5939 return (GET_CODE (rtl) == PLUS
5940 && ((GET_CODE (XEXP (rtl, 0)) == REG
5941 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
5944 /* The following routine converts the RTL for a variable or parameter
5945 (resident in memory) into an equivalent Dwarf representation of a
5946 mechanism for getting the address of that same variable onto the top of a
5947 hypothetical "address evaluation" stack.
5949 When creating memory location descriptors, we are effectively transforming
5950 the RTL for a memory-resident object into its Dwarf postfix expression
5951 equivalent. This routine recursively descends an RTL tree, turning
5952 it into Dwarf postfix code as it goes. */
5954 static dw_loc_descr_ref
5955 mem_loc_descriptor (rtl)
5958 dw_loc_descr_ref mem_loc_result = NULL;
5959 /* Note that for a dynamically sized array, the location we will generate a
5960 description of here will be the lowest numbered location which is
5961 actually within the array. That's *not* necessarily the same as the
5962 zeroth element of the array. */
5964 switch (GET_CODE (rtl))
5967 /* The case of a subreg may arise when we have a local (register)
5968 variable or a formal (register) parameter which doesn't quite fill
5969 up an entire register. For now, just assume that it is
5970 legitimate to make the Dwarf info refer to the whole register which
5971 contains the given subreg. */
5972 rtl = XEXP (rtl, 0);
5974 /* ... fall through ... */
5977 /* Whenever a register number forms a part of the description of the
5978 method for calculating the (dynamic) address of a memory resident
5979 object, DWARF rules require the register number be referred to as
5980 a "base register". This distinction is not based in any way upon
5981 what category of register the hardware believes the given register
5982 belongs to. This is strictly DWARF terminology we're dealing with
5983 here. Note that in cases where the location of a memory-resident
5984 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
5985 OP_CONST (0)) the actual DWARF location descriptor that we generate
5986 may just be OP_BASEREG (basereg). This may look deceptively like
5987 the object in question was allocated to a register (rather than in
5988 memory) so DWARF consumers need to be aware of the subtle
5989 distinction between OP_REG and OP_BASEREG. */
5990 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
5994 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0));
5995 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6000 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6001 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6002 mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
6006 if (is_based_loc (rtl))
6007 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
6008 INTVAL (XEXP (rtl, 1)));
6011 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
6012 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
6013 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
6018 /* If a pseudo-reg is optimized away, it is possible for it to
6019 be replaced with a MEM containing a multiply. */
6020 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
6021 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
6022 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
6026 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6033 return mem_loc_result;
6036 /* Output a proper Dwarf location descriptor for a variable or parameter
6037 which is either allocated in a register or in a memory location. For a
6038 register, we just generate an OP_REG and the register number. For a
6039 memory location we provide a Dwarf postfix expression describing how to
6040 generate the (dynamic) address of the object onto the address stack. */
6042 static dw_loc_descr_ref
6043 loc_descriptor (rtl)
6046 dw_loc_descr_ref loc_result = NULL;
6047 switch (GET_CODE (rtl))
6050 /* The case of a subreg may arise when we have a local (register)
6051 variable or a formal (register) parameter which doesn't quite fill
6052 up an entire register. For now, just assume that it is
6053 legitimate to make the Dwarf info refer to the whole register which
6054 contains the given subreg. */
6055 rtl = XEXP (rtl, 0);
6057 /* ... fall through ... */
6060 loc_result = reg_loc_descriptor (rtl);
6064 loc_result = mem_loc_descriptor (XEXP (rtl, 0));
6074 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
6075 which is not less than the value itself. */
6077 static inline unsigned
6078 ceiling (value, boundary)
6079 register unsigned value;
6080 register unsigned boundary;
6082 return (((value + boundary - 1) / boundary) * boundary);
6085 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6086 pointer to the declared type for the relevant field variable, or return
6087 `integer_type_node' if the given node turns out to be an
6096 if (TREE_CODE (decl) == ERROR_MARK)
6097 return integer_type_node;
6099 type = DECL_BIT_FIELD_TYPE (decl);
6100 if (type == NULL_TREE)
6101 type = TREE_TYPE (decl);
6106 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6107 node, return the alignment in bits for the type, or else return
6108 BITS_PER_WORD if the node actually turns out to be an
6111 static inline unsigned
6112 simple_type_align_in_bits (type)
6115 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6118 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6119 node, return the size in bits for the type if it is a constant, or else
6120 return the alignment for the type if the type's size is not constant, or
6121 else return BITS_PER_WORD if the type actually turns out to be an
6124 static inline unsigned
6125 simple_type_size_in_bits (type)
6128 if (TREE_CODE (type) == ERROR_MARK)
6129 return BITS_PER_WORD;
6132 register tree type_size_tree = TYPE_SIZE (type);
6134 if (TREE_CODE (type_size_tree) != INTEGER_CST)
6135 return TYPE_ALIGN (type);
6137 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
6141 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6142 return the byte offset of the lowest addressed byte of the "containing
6143 object" for the given FIELD_DECL, or return 0 if we are unable to
6144 determine what that offset is, either because the argument turns out to
6145 be a pointer to an ERROR_MARK node, or because the offset is actually
6146 variable. (We can't handle the latter case just yet). */
6149 field_byte_offset (decl)
6152 register unsigned type_align_in_bytes;
6153 register unsigned type_align_in_bits;
6154 register unsigned type_size_in_bits;
6155 register unsigned object_offset_in_align_units;
6156 register unsigned object_offset_in_bits;
6157 register unsigned object_offset_in_bytes;
6159 register tree bitpos_tree;
6160 register tree field_size_tree;
6161 register unsigned bitpos_int;
6162 register unsigned deepest_bitpos;
6163 register unsigned field_size_in_bits;
6165 if (TREE_CODE (decl) == ERROR_MARK)
6168 if (TREE_CODE (decl) != FIELD_DECL)
6171 type = field_type (decl);
6173 bitpos_tree = DECL_FIELD_BITPOS (decl);
6174 field_size_tree = DECL_SIZE (decl);
6176 /* We cannot yet cope with fields whose positions or sizes are variable, so
6177 for now, when we see such things, we simply return 0. Someday, we may
6178 be able to handle such cases, but it will be damn difficult. */
6179 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6181 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6183 if (TREE_CODE (field_size_tree) != INTEGER_CST)
6186 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
6187 type_size_in_bits = simple_type_size_in_bits (type);
6188 type_align_in_bits = simple_type_align_in_bits (type);
6189 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6191 /* Note that the GCC front-end doesn't make any attempt to keep track of
6192 the starting bit offset (relative to the start of the containing
6193 structure type) of the hypothetical "containing object" for a bit-
6194 field. Thus, when computing the byte offset value for the start of the
6195 "containing object" of a bit-field, we must deduce this information on
6196 our own. This can be rather tricky to do in some cases. For example,
6197 handling the following structure type definition when compiling for an
6198 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6201 struct S { int field1; long long field2:31; };
6203 Fortunately, there is a simple rule-of-thumb which can be
6204 used in such cases. When compiling for an i386/i486, GCC will allocate
6205 8 bytes for the structure shown above. It decides to do this based upon
6206 one simple rule for bit-field allocation. Quite simply, GCC allocates
6207 each "containing object" for each bit-field at the first (i.e. lowest
6208 addressed) legitimate alignment boundary (based upon the required
6209 minimum alignment for the declared type of the field) which it can
6210 possibly use, subject to the condition that there is still enough
6211 available space remaining in the containing object (when allocated at
6212 the selected point) to fully accommodate all of the bits of the
6213 bit-field itself. This simple rule makes it obvious why GCC allocates
6214 8 bytes for each object of the structure type shown above. When looking
6215 for a place to allocate the "containing object" for `field2', the
6216 compiler simply tries to allocate a 64-bit "containing object" at each
6217 successive 32-bit boundary (starting at zero) until it finds a place to
6218 allocate that 64- bit field such that at least 31 contiguous (and
6219 previously unallocated) bits remain within that selected 64 bit field.
6220 (As it turns out, for the example above, the compiler finds that it is
6221 OK to allocate the "containing object" 64-bit field at bit-offset zero
6222 within the structure type.) Here we attempt to work backwards from the
6223 limited set of facts we're given, and we try to deduce from those facts,
6224 where GCC must have believed that the containing object started (within
6225 the structure type). The value we deduce is then used (by the callers of
6226 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6227 for fields (both bit-fields and, in the case of DW_AT_location, regular
6230 /* Figure out the bit-distance from the start of the structure to the
6231 "deepest" bit of the bit-field. */
6232 deepest_bitpos = bitpos_int + field_size_in_bits;
6234 /* This is the tricky part. Use some fancy footwork to deduce where the
6235 lowest addressed bit of the containing object must be. */
6236 object_offset_in_bits
6237 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6239 /* Compute the offset of the containing object in "alignment units". */
6240 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6242 /* Compute the offset of the containing object in bytes. */
6243 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6245 return object_offset_in_bytes;
6248 /* The following routines define various Dwarf attributes and any data
6249 associated with them. */
6251 /* Add a location description attribute value to a DIE.
6253 This emits location attributes suitable for whole variables and
6254 whole parameters. Note that the location attributes for struct fields are
6255 generated by the routine `data_member_location_attribute' below. */
6258 add_AT_location_description (die, attr_kind, rtl)
6260 enum dwarf_attribute attr_kind;
6263 /* Handle a special case. If we are about to output a location descriptor
6264 for a variable or parameter which has been optimized out of existence,
6265 don't do that. A variable which has been optimized out
6266 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6267 Currently, in some rare cases, variables can have DECL_RTL values which
6268 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6269 elsewhere in the compiler. We treat such cases as if the variable(s) in
6270 question had been optimized out of existence. */
6272 if (is_pseudo_reg (rtl)
6273 || (GET_CODE (rtl) == MEM
6274 && is_pseudo_reg (XEXP (rtl, 0))))
6277 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
6280 /* Attach the specialized form of location attribute used for data
6281 members of struct and union types. In the special case of a
6282 FIELD_DECL node which represents a bit-field, the "offset" part
6283 of this special location descriptor must indicate the distance
6284 in bytes from the lowest-addressed byte of the containing struct
6285 or union type to the lowest-addressed byte of the "containing
6286 object" for the bit-field. (See the `field_byte_offset' function
6287 above).. For any given bit-field, the "containing object" is a
6288 hypothetical object (of some integral or enum type) within which
6289 the given bit-field lives. The type of this hypothetical
6290 "containing object" is always the same as the declared type of
6291 the individual bit-field itself (for GCC anyway... the DWARF
6292 spec doesn't actually mandate this). Note that it is the size
6293 (in bytes) of the hypothetical "containing object" which will
6294 be given in the DW_AT_byte_size attribute for this bit-field.
6295 (See the `byte_size_attribute' function below.) It is also used
6296 when calculating the value of the DW_AT_bit_offset attribute.
6297 (See the `bit_offset_attribute' function below). */
6300 add_data_member_location_attribute (die, decl)
6301 register dw_die_ref die;
6304 register unsigned long offset;
6305 register dw_loc_descr_ref loc_descr;
6306 register enum dwarf_location_atom op;
6308 if (TREE_CODE (decl) == TREE_VEC)
6309 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
6311 offset = field_byte_offset (decl);
6313 /* The DWARF2 standard says that we should assume that the structure address
6314 is already on the stack, so we can specify a structure field address
6315 by using DW_OP_plus_uconst. */
6317 #ifdef MIPS_DEBUGGING_INFO
6318 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6319 correctly. It works only if we leave the offset on the stack. */
6322 op = DW_OP_plus_uconst;
6325 loc_descr = new_loc_descr (op, offset, 0);
6326 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6329 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6330 does not have a "location" either in memory or in a register. These
6331 things can arise in GNU C when a constant is passed as an actual parameter
6332 to an inlined function. They can also arise in C++ where declared
6333 constants do not necessarily get memory "homes". */
6336 add_const_value_attribute (die, rtl)
6337 register dw_die_ref die;
6340 switch (GET_CODE (rtl))
6343 /* Note that a CONST_INT rtx could represent either an integer or a
6344 floating-point constant. A CONST_INT is used whenever the constant
6345 will fit into a single word. In all such cases, the original mode
6346 of the constant value is wiped out, and the CONST_INT rtx is
6347 assigned VOIDmode. */
6348 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6352 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6353 floating-point constant. A CONST_DOUBLE is used whenever the
6354 constant requires more than one word in order to be adequately
6355 represented. We output CONST_DOUBLEs as blocks. */
6357 register enum machine_mode mode = GET_MODE (rtl);
6359 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6361 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6365 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6369 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6373 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6378 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6385 add_AT_float (die, DW_AT_const_value, length, array);
6388 add_AT_long_long (die, DW_AT_const_value,
6389 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6394 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6400 add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
6404 /* In cases where an inlined instance of an inline function is passed
6405 the address of an `auto' variable (which is local to the caller) we
6406 can get a situation where the DECL_RTL of the artificial local
6407 variable (for the inlining) which acts as a stand-in for the
6408 corresponding formal parameter (of the inline function) will look
6409 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6410 exactly a compile-time constant expression, but it isn't the address
6411 of the (artificial) local variable either. Rather, it represents the
6412 *value* which the artificial local variable always has during its
6413 lifetime. We currently have no way to represent such quasi-constant
6414 values in Dwarf, so for now we just punt and generate nothing. */
6418 /* No other kinds of rtx should be possible here. */
6424 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6425 data attribute for a variable or a parameter. We generate the
6426 DW_AT_const_value attribute only in those cases where the given variable
6427 or parameter does not have a true "location" either in memory or in a
6428 register. This can happen (for example) when a constant is passed as an
6429 actual argument in a call to an inline function. (It's possible that
6430 these things can crop up in other ways also.) Note that one type of
6431 constant value which can be passed into an inlined function is a constant
6432 pointer. This can happen for example if an actual argument in an inlined
6433 function call evaluates to a compile-time constant address. */
6436 add_location_or_const_value_attribute (die, decl)
6437 register dw_die_ref die;
6441 register tree declared_type;
6442 register tree passed_type;
6444 if (TREE_CODE (decl) == ERROR_MARK)
6447 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6450 /* Here we have to decide where we are going to say the parameter "lives"
6451 (as far as the debugger is concerned). We only have a couple of
6452 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6454 DECL_RTL normally indicates where the parameter lives during most of the
6455 activation of the function. If optimization is enabled however, this
6456 could be either NULL or else a pseudo-reg. Both of those cases indicate
6457 that the parameter doesn't really live anywhere (as far as the code
6458 generation parts of GCC are concerned) during most of the function's
6459 activation. That will happen (for example) if the parameter is never
6460 referenced within the function.
6462 We could just generate a location descriptor here for all non-NULL
6463 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6464 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6465 where DECL_RTL is NULL or is a pseudo-reg.
6467 Note however that we can only get away with using DECL_INCOMING_RTL as
6468 a backup substitute for DECL_RTL in certain limited cases. In cases
6469 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6470 we can be sure that the parameter was passed using the same type as it is
6471 declared to have within the function, and that its DECL_INCOMING_RTL
6472 points us to a place where a value of that type is passed.
6474 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6475 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6476 because in these cases DECL_INCOMING_RTL points us to a value of some
6477 type which is *different* from the type of the parameter itself. Thus,
6478 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6479 such cases, the debugger would end up (for example) trying to fetch a
6480 `float' from a place which actually contains the first part of a
6481 `double'. That would lead to really incorrect and confusing
6482 output at debug-time.
6484 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6485 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6486 are a couple of exceptions however. On little-endian machines we can
6487 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6488 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6489 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6490 when (on a little-endian machine) a non-prototyped function has a
6491 parameter declared to be of type `short' or `char'. In such cases,
6492 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6493 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6494 passed `int' value. If the debugger then uses that address to fetch
6495 a `short' or a `char' (on a little-endian machine) the result will be
6496 the correct data, so we allow for such exceptional cases below.
6498 Note that our goal here is to describe the place where the given formal
6499 parameter lives during most of the function's activation (i.e. between
6500 the end of the prologue and the start of the epilogue). We'll do that
6501 as best as we can. Note however that if the given formal parameter is
6502 modified sometime during the execution of the function, then a stack
6503 backtrace (at debug-time) will show the function as having been
6504 called with the *new* value rather than the value which was
6505 originally passed in. This happens rarely enough that it is not
6506 a major problem, but it *is* a problem, and I'd like to fix it.
6508 A future version of dwarf2out.c may generate two additional
6509 attributes for any given DW_TAG_formal_parameter DIE which will
6510 describe the "passed type" and the "passed location" for the
6511 given formal parameter in addition to the attributes we now
6512 generate to indicate the "declared type" and the "active
6513 location" for each parameter. This additional set of attributes
6514 could be used by debuggers for stack backtraces. Separately, note
6515 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6516 NULL also. This happens (for example) for inlined-instances of
6517 inline function formal parameters which are never referenced.
6518 This really shouldn't be happening. All PARM_DECL nodes should
6519 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6520 doesn't currently generate these values for inlined instances of
6521 inline function parameters, so when we see such cases, we are
6522 just SOL (shit-out-of-luck) for the time being (until integrate.c
6525 /* Use DECL_RTL as the "location" unless we find something better. */
6526 rtl = DECL_RTL (decl);
6528 if (TREE_CODE (decl) == PARM_DECL)
6530 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
6532 declared_type = type_main_variant (TREE_TYPE (decl));
6533 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
6535 /* This decl represents a formal parameter which was optimized out.
6536 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
6537 all* cases where (rtl == NULL_RTX) just below. */
6538 if (declared_type == passed_type)
6539 rtl = DECL_INCOMING_RTL (decl);
6540 else if (! BYTES_BIG_ENDIAN
6541 && TREE_CODE (declared_type) == INTEGER_TYPE
6542 && TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
6543 rtl = DECL_INCOMING_RTL (decl);
6547 if (rtl == NULL_RTX)
6550 rtl = eliminate_regs (rtl, 0, NULL_RTX, 0);
6551 #ifdef LEAF_REG_REMAP
6553 leaf_renumber_regs_insn (DECL_RTL (decl));
6556 switch (GET_CODE (rtl))
6565 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
6566 add_const_value_attribute (die, rtl);
6572 add_AT_location_description (die, DW_AT_location, rtl);
6580 /* Generate an DW_AT_name attribute given some string value to be included as
6581 the value of the attribute. */
6584 add_name_attribute (die, name_string)
6585 register dw_die_ref die;
6586 register char *name_string;
6588 if (name_string != NULL && *name_string != 0)
6589 add_AT_string (die, DW_AT_name, name_string);
6592 /* Given a tree node describing an array bound (either lower or upper) output
6593 a representation for that bound. */
6596 add_bound_info (subrange_die, bound_attr, bound)
6597 register dw_die_ref subrange_die;
6598 register enum dwarf_attribute bound_attr;
6599 register tree bound;
6601 register unsigned bound_value = 0;
6603 /* If this is an Ada unconstrained array type, then don't emit any debug
6604 info because the array bounds are unknown. They are parameterized when
6605 the type is instantiated. */
6606 if (contains_placeholder_p (bound))
6609 switch (TREE_CODE (bound))
6614 /* All fixed-bounds are represented by INTEGER_CST nodes. */
6616 bound_value = TREE_INT_CST_LOW (bound);
6617 if (bound_attr == DW_AT_lower_bound
6618 && ((is_c_family () && bound_value == 0)
6619 || (is_fortran () && bound_value == 1)))
6620 /* use the default */;
6622 add_AT_unsigned (subrange_die, bound_attr, bound_value);
6627 case NON_LVALUE_EXPR:
6628 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
6632 /* If optimization is turned on, the SAVE_EXPRs that describe how to
6633 access the upper bound values may be bogus. If they refer to a
6634 register, they may only describe how to get at these values at the
6635 points in the generated code right after they have just been
6636 computed. Worse yet, in the typical case, the upper bound values
6637 will not even *be* computed in the optimized code (though the
6638 number of elements will), so these SAVE_EXPRs are entirely
6639 bogus. In order to compensate for this fact, we check here to see
6640 if optimization is enabled, and if so, we don't add an attribute
6641 for the (unknown and unknowable) upper bound. This should not
6642 cause too much trouble for existing (stupid?) debuggers because
6643 they have to deal with empty upper bounds location descriptions
6644 anyway in order to be able to deal with incomplete array types.
6645 Of course an intelligent debugger (GDB?) should be able to
6646 comprehend that a missing upper bound specification in a array
6647 type used for a storage class `auto' local array variable
6648 indicates that the upper bound is both unknown (at compile- time)
6649 and unknowable (at run-time) due to optimization.
6651 We assume that a MEM rtx is safe because gcc wouldn't put the
6652 value there unless it was going to be used repeatedly in the
6653 function, i.e. for cleanups. */
6654 if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)
6656 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
6657 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
6658 add_AT_flag (decl_die, DW_AT_artificial, 1);
6659 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
6660 add_AT_location_description (decl_die, DW_AT_location,
6661 SAVE_EXPR_RTL (bound));
6662 add_AT_die_ref (subrange_die, bound_attr, decl_die);
6665 /* Else leave out the attribute. */
6670 /* ??? These types of bounds can be created by the Ada front end,
6671 and it isn't clear how to emit debug info for them. */
6679 /* Note that the block of subscript information for an array type also
6680 includes information about the element type of type given array type. */
6683 add_subscript_info (type_die, type)
6684 register dw_die_ref type_die;
6687 register unsigned dimension_number;
6688 register tree lower, upper;
6689 register dw_die_ref subrange_die;
6691 /* The GNU compilers represent multidimensional array types as sequences of
6692 one dimensional array types whose element types are themselves array
6693 types. Here we squish that down, so that each multidimensional array
6694 type gets only one array_type DIE in the Dwarf debugging info. The draft
6695 Dwarf specification say that we are allowed to do this kind of
6696 compression in C (because there is no difference between an array or
6697 arrays and a multidimensional array in C) but for other source languages
6698 (e.g. Ada) we probably shouldn't do this. */
6700 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
6701 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
6702 We work around this by disabling this feature. See also
6703 gen_array_type_die. */
6704 #ifndef MIPS_DEBUGGING_INFO
6705 for (dimension_number = 0;
6706 TREE_CODE (type) == ARRAY_TYPE;
6707 type = TREE_TYPE (type), dimension_number++)
6710 register tree domain = TYPE_DOMAIN (type);
6712 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
6713 and (in GNU C only) variable bounds. Handle all three forms
6715 subrange_die = new_die (DW_TAG_subrange_type, type_die);
6718 /* We have an array type with specified bounds. */
6719 lower = TYPE_MIN_VALUE (domain);
6720 upper = TYPE_MAX_VALUE (domain);
6722 /* define the index type. */
6723 if (TREE_TYPE (domain))
6725 /* ??? This is probably an Ada unnamed subrange type. Ignore the
6726 TREE_TYPE field. We can't emit debug info for this
6727 because it is an unnamed integral type. */
6728 if (TREE_CODE (domain) == INTEGER_TYPE
6729 && TYPE_NAME (domain) == NULL_TREE
6730 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
6731 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
6734 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
6738 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
6739 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
6742 /* We have an array type with an unspecified length. The DWARF-2
6743 spec does not say how to handle this; let's just leave out the
6747 #ifndef MIPS_DEBUGGING_INFO
6753 add_byte_size_attribute (die, tree_node)
6755 register tree tree_node;
6757 register unsigned size;
6759 switch (TREE_CODE (tree_node))
6767 case QUAL_UNION_TYPE:
6768 size = int_size_in_bytes (tree_node);
6771 /* For a data member of a struct or union, the DW_AT_byte_size is
6772 generally given as the number of bytes normally allocated for an
6773 object of the *declared* type of the member itself. This is true
6774 even for bit-fields. */
6775 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
6781 /* Note that `size' might be -1 when we get to this point. If it is, that
6782 indicates that the byte size of the entity in question is variable. We
6783 have no good way of expressing this fact in Dwarf at the present time,
6784 so just let the -1 pass on through. */
6786 add_AT_unsigned (die, DW_AT_byte_size, size);
6789 /* For a FIELD_DECL node which represents a bit-field, output an attribute
6790 which specifies the distance in bits from the highest order bit of the
6791 "containing object" for the bit-field to the highest order bit of the
6794 For any given bit-field, the "containing object" is a hypothetical
6795 object (of some integral or enum type) within which the given bit-field
6796 lives. The type of this hypothetical "containing object" is always the
6797 same as the declared type of the individual bit-field itself. The
6798 determination of the exact location of the "containing object" for a
6799 bit-field is rather complicated. It's handled by the
6800 `field_byte_offset' function (above).
6802 Note that it is the size (in bytes) of the hypothetical "containing object"
6803 which will be given in the DW_AT_byte_size attribute for this bit-field.
6804 (See `byte_size_attribute' above). */
6807 add_bit_offset_attribute (die, decl)
6808 register dw_die_ref die;
6811 register unsigned object_offset_in_bytes = field_byte_offset (decl);
6812 register tree type = DECL_BIT_FIELD_TYPE (decl);
6813 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
6814 register unsigned bitpos_int;
6815 register unsigned highest_order_object_bit_offset;
6816 register unsigned highest_order_field_bit_offset;
6817 register unsigned bit_offset;
6819 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
6820 assert (type); /* Must be a bit field. */
6822 /* We can't yet handle bit-fields whose offsets are variable, so if we
6823 encounter such things, just return without generating any attribute
6825 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6828 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6830 /* Note that the bit offset is always the distance (in bits) from the
6831 highest-order bit of the "containing object" to the highest-order bit of
6832 the bit-field itself. Since the "high-order end" of any object or field
6833 is different on big-endian and little-endian machines, the computation
6834 below must take account of these differences. */
6835 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
6836 highest_order_field_bit_offset = bitpos_int;
6838 if (! BYTES_BIG_ENDIAN)
6840 highest_order_field_bit_offset
6841 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
6843 highest_order_object_bit_offset += simple_type_size_in_bits (type);
6847 = (! BYTES_BIG_ENDIAN
6848 ? highest_order_object_bit_offset - highest_order_field_bit_offset
6849 : highest_order_field_bit_offset - highest_order_object_bit_offset);
6851 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
6854 /* For a FIELD_DECL node which represents a bit field, output an attribute
6855 which specifies the length in bits of the given field. */
6858 add_bit_size_attribute (die, decl)
6859 register dw_die_ref die;
6862 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
6863 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
6864 add_AT_unsigned (die, DW_AT_bit_size,
6865 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
6868 /* If the compiled language is ANSI C, then add a 'prototyped'
6869 attribute, if arg types are given for the parameters of a function. */
6872 add_prototyped_attribute (die, func_type)
6873 register dw_die_ref die;
6874 register tree func_type;
6876 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
6877 && TYPE_ARG_TYPES (func_type) != NULL)
6878 add_AT_flag (die, DW_AT_prototyped, 1);
6882 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
6883 by looking in either the type declaration or object declaration
6887 add_abstract_origin_attribute (die, origin)
6888 register dw_die_ref die;
6889 register tree origin;
6891 dw_die_ref origin_die = NULL;
6892 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
6893 origin_die = lookup_decl_die (origin);
6894 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
6895 origin_die = lookup_type_die (origin);
6897 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
6900 /* We do not currently support the pure_virtual attribute. */
6903 add_pure_or_virtual_attribute (die, func_decl)
6904 register dw_die_ref die;
6905 register tree func_decl;
6907 if (DECL_VINDEX (func_decl))
6909 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
6910 add_AT_loc (die, DW_AT_vtable_elem_location,
6911 new_loc_descr (DW_OP_constu,
6912 TREE_INT_CST_LOW (DECL_VINDEX (func_decl)),
6915 /* GNU extension: Record what type this method came from originally. */
6916 if (debug_info_level > DINFO_LEVEL_TERSE)
6917 add_AT_die_ref (die, DW_AT_containing_type,
6918 lookup_type_die (DECL_CONTEXT (func_decl)));
6922 /* Add source coordinate attributes for the given decl. */
6925 add_src_coords_attributes (die, decl)
6926 register dw_die_ref die;
6929 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
6931 add_AT_unsigned (die, DW_AT_decl_file, file_index);
6932 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
6935 /* Add an DW_AT_name attribute and source coordinate attribute for the
6936 given decl, but only if it actually has a name. */
6939 add_name_and_src_coords_attributes (die, decl)
6940 register dw_die_ref die;
6943 register tree decl_name;
6945 decl_name = DECL_NAME (decl);
6946 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
6948 add_name_attribute (die, dwarf2_name (decl, 0));
6949 add_src_coords_attributes (die, decl);
6950 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
6951 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
6952 add_AT_string (die, DW_AT_MIPS_linkage_name,
6953 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
6957 /* Push a new declaration scope. */
6960 push_decl_scope (scope)
6963 /* Make room in the decl_scope_table, if necessary. */
6964 if (decl_scope_table_allocated == decl_scope_depth)
6966 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
6968 = (tree *) xrealloc (decl_scope_table,
6969 decl_scope_table_allocated * sizeof (tree));
6972 decl_scope_table[decl_scope_depth++] = scope;
6975 /* Return the DIE for the scope the immediately contains this declaration. */
6978 scope_die_for (t, context_die)
6980 register dw_die_ref context_die;
6982 register dw_die_ref scope_die = NULL;
6983 register tree containing_scope;
6984 register unsigned long i;
6986 /* Walk back up the declaration tree looking for a place to define
6988 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
6989 containing_scope = TYPE_CONTEXT (t);
6990 else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t))
6991 containing_scope = decl_class_context (t);
6993 containing_scope = DECL_CONTEXT (t);
6995 /* Function-local tags and functions get stuck in limbo until they are
6996 fixed up by decls_for_scope. */
6997 if (context_die == NULL && containing_scope != NULL_TREE
6998 && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t)))
7001 if (containing_scope == NULL_TREE)
7002 scope_die = comp_unit_die;
7005 for (i = decl_scope_depth, scope_die = context_die;
7006 i > 0 && decl_scope_table[i - 1] != containing_scope;
7007 scope_die = scope_die->die_parent, --i)
7012 assert (scope_die == comp_unit_die);
7013 assert (TREE_CODE_CLASS (TREE_CODE (containing_scope)) == 't');
7014 if (debug_info_level > DINFO_LEVEL_TERSE)
7015 assert (TREE_ASM_WRITTEN (containing_scope));
7022 /* Pop a declaration scope. */
7026 assert (decl_scope_depth > 0);
7030 /* Many forms of DIEs require a "type description" attribute. This
7031 routine locates the proper "type descriptor" die for the type given
7032 by 'type', and adds an DW_AT_type attribute below the given die. */
7035 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
7036 register dw_die_ref object_die;
7038 register int decl_const;
7039 register int decl_volatile;
7040 register dw_die_ref context_die;
7042 register enum tree_code code = TREE_CODE (type);
7043 register dw_die_ref type_die = NULL;
7045 /* ??? If this type is an unnamed subrange type of an integral or
7046 floating-point type, use the inner type. This is because we have no
7047 support for unnamed types in base_type_die. This can happen if this is
7048 an Ada subrange type. Correct solution is emit a subrange type die. */
7049 if ((code == INTEGER_TYPE || code == REAL_TYPE)
7050 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
7051 type = TREE_TYPE (type), code = TREE_CODE (type);
7053 if (code == ERROR_MARK)
7056 /* Handle a special case. For functions whose return type is void, we
7057 generate *no* type attribute. (Note that no object may have type
7058 `void', so this only applies to function return types). */
7059 if (code == VOID_TYPE)
7062 type_die = modified_type_die (type,
7063 decl_const || TYPE_READONLY (type),
7064 decl_volatile || TYPE_VOLATILE (type),
7066 if (type_die != NULL)
7067 add_AT_die_ref (object_die, DW_AT_type, type_die);
7070 /* Given a tree pointer to a struct, class, union, or enum type node, return
7071 a pointer to the (string) tag name for the given type, or zero if the type
7072 was declared without a tag. */
7078 register char *name = 0;
7080 if (TYPE_NAME (type) != 0)
7082 register tree t = 0;
7084 /* Find the IDENTIFIER_NODE for the type name. */
7085 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7086 t = TYPE_NAME (type);
7088 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7089 a TYPE_DECL node, regardless of whether or not a `typedef' was
7091 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7092 && ! DECL_IGNORED_P (TYPE_NAME (type)))
7093 t = DECL_NAME (TYPE_NAME (type));
7095 /* Now get the name as a string, or invent one. */
7097 name = IDENTIFIER_POINTER (t);
7100 return (name == 0 || *name == '\0') ? 0 : name;
7103 /* Return the type associated with a data member, make a special check
7104 for bit field types. */
7107 member_declared_type (member)
7108 register tree member;
7110 return (DECL_BIT_FIELD_TYPE (member)
7111 ? DECL_BIT_FIELD_TYPE (member)
7112 : TREE_TYPE (member));
7115 /* Get the decl's label, as described by its RTL. This may be different
7116 from the DECL_NAME name used in the source file. */
7119 decl_start_label (decl)
7124 x = DECL_RTL (decl);
7125 if (GET_CODE (x) != MEM)
7129 if (GET_CODE (x) != SYMBOL_REF)
7132 fnname = XSTR (x, 0);
7136 /* These routines generate the internnal representation of the DIE's for
7137 the compilation unit. Debugging information is collected by walking
7138 the declaration trees passed in from dwarf2out_decl(). */
7141 gen_array_type_die (type, context_die)
7143 register dw_die_ref context_die;
7145 register dw_die_ref scope_die = scope_die_for (type, context_die);
7146 register dw_die_ref array_die;
7147 register tree element_type;
7149 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7150 the inner array type comes before the outer array type. Thus we must
7151 call gen_type_die before we call new_die. See below also. */
7152 #ifdef MIPS_DEBUGGING_INFO
7153 gen_type_die (TREE_TYPE (type), context_die);
7156 array_die = new_die (DW_TAG_array_type, scope_die);
7159 /* We default the array ordering. SDB will probably do
7160 the right things even if DW_AT_ordering is not present. It's not even
7161 an issue until we start to get into multidimensional arrays anyway. If
7162 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7163 then we'll have to put the DW_AT_ordering attribute back in. (But if
7164 and when we find out that we need to put these in, we will only do so
7165 for multidimensional arrays. */
7166 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
7169 #ifdef MIPS_DEBUGGING_INFO
7170 /* The SGI compilers handle arrays of unknown bound by setting
7171 AT_declaration and not emitting any subrange DIEs. */
7172 if (! TYPE_DOMAIN (type))
7173 add_AT_unsigned (array_die, DW_AT_declaration, 1);
7176 add_subscript_info (array_die, type);
7178 equate_type_number_to_die (type, array_die);
7180 /* Add representation of the type of the elements of this array type. */
7181 element_type = TREE_TYPE (type);
7183 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7184 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7185 We work around this by disabling this feature. See also
7186 add_subscript_info. */
7187 #ifndef MIPS_DEBUGGING_INFO
7188 while (TREE_CODE (element_type) == ARRAY_TYPE)
7189 element_type = TREE_TYPE (element_type);
7191 gen_type_die (element_type, context_die);
7194 add_type_attribute (array_die, element_type, 0, 0, context_die);
7198 gen_set_type_die (type, context_die)
7200 register dw_die_ref context_die;
7202 register dw_die_ref type_die
7203 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7205 equate_type_number_to_die (type, type_die);
7206 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7210 gen_entry_point_die (decl, context_die)
7212 register dw_die_ref context_die;
7214 register tree origin = decl_ultimate_origin (decl);
7215 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
7217 add_abstract_origin_attribute (decl_die, origin);
7220 add_name_and_src_coords_attributes (decl_die, decl);
7221 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
7225 if (DECL_ABSTRACT (decl))
7226 equate_decl_number_to_die (decl, decl_die);
7228 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
7231 /* Remember a type in the pending_types_list. */
7237 if (pending_types == pending_types_allocated)
7239 pending_types_allocated += PENDING_TYPES_INCREMENT;
7241 = (tree *) xrealloc (pending_types_list,
7242 sizeof (tree) * pending_types_allocated);
7245 pending_types_list[pending_types++] = type;
7248 /* Output any pending types (from the pending_types list) which we can output
7249 now (taking into account the scope that we are working on now).
7251 For each type output, remove the given type from the pending_types_list
7252 *before* we try to output it. */
7255 output_pending_types_for_scope (context_die)
7256 register dw_die_ref context_die;
7260 while (pending_types)
7263 type = pending_types_list[pending_types];
7264 gen_type_die (type, context_die);
7265 assert (TREE_ASM_WRITTEN (type));
7269 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7272 gen_inlined_enumeration_type_die (type, context_die)
7274 register dw_die_ref context_die;
7276 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
7277 scope_die_for (type, context_die));
7279 assert (TREE_ASM_WRITTEN (type));
7280 add_abstract_origin_attribute (type_die, type);
7283 /* Generate a DIE to represent an inlined instance of a structure type. */
7286 gen_inlined_structure_type_die (type, context_die)
7288 register dw_die_ref context_die;
7290 register dw_die_ref type_die = new_die (DW_TAG_structure_type,
7291 scope_die_for (type, context_die));
7293 assert (TREE_ASM_WRITTEN (type));
7294 add_abstract_origin_attribute (type_die, type);
7297 /* Generate a DIE to represent an inlined instance of a union type. */
7300 gen_inlined_union_type_die (type, context_die)
7302 register dw_die_ref context_die;
7304 register dw_die_ref type_die = new_die (DW_TAG_union_type,
7305 scope_die_for (type, context_die));
7307 assert (TREE_ASM_WRITTEN (type));
7308 add_abstract_origin_attribute (type_die, type);
7311 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7312 include all of the information about the enumeration values also. Each
7313 enumerated type name/value is listed as a child of the enumerated type
7317 gen_enumeration_type_die (type, context_die)
7319 register dw_die_ref context_die;
7321 register dw_die_ref type_die = lookup_type_die (type);
7323 if (type_die == NULL)
7325 type_die = new_die (DW_TAG_enumeration_type,
7326 scope_die_for (type, context_die));
7327 equate_type_number_to_die (type, type_die);
7328 add_name_attribute (type_die, type_tag (type));
7330 else if (! TYPE_SIZE (type))
7333 remove_AT (type_die, DW_AT_declaration);
7335 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7336 given enum type is incomplete, do not generate the DW_AT_byte_size
7337 attribute or the DW_AT_element_list attribute. */
7338 if (TYPE_SIZE (type))
7342 TREE_ASM_WRITTEN (type) = 1;
7343 add_byte_size_attribute (type_die, type);
7344 if (type_tag (type))
7345 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
7347 /* If the first reference to this type was as the return type of an
7348 inline function, then it may not have a parent. Fix this now. */
7349 if (type_die->die_parent == NULL)
7350 add_child_die (scope_die_for (type, context_die), type_die);
7352 for (link = TYPE_FIELDS (type);
7353 link != NULL; link = TREE_CHAIN (link))
7355 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
7357 add_name_attribute (enum_die,
7358 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
7359 add_AT_unsigned (enum_die, DW_AT_const_value,
7360 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
7364 add_AT_flag (type_die, DW_AT_declaration, 1);
7368 /* Generate a DIE to represent either a real live formal parameter decl or to
7369 represent just the type of some formal parameter position in some function
7372 Note that this routine is a bit unusual because its argument may be a
7373 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7374 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7375 node. If it's the former then this function is being called to output a
7376 DIE to represent a formal parameter object (or some inlining thereof). If
7377 it's the latter, then this function is only being called to output a
7378 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7379 argument type of some subprogram type. */
7382 gen_formal_parameter_die (node, context_die)
7384 register dw_die_ref context_die;
7386 register dw_die_ref parm_die
7387 = new_die (DW_TAG_formal_parameter, context_die);
7388 register tree origin;
7390 switch (TREE_CODE_CLASS (TREE_CODE (node)))
7393 origin = decl_ultimate_origin (node);
7395 add_abstract_origin_attribute (parm_die, origin);
7398 add_name_and_src_coords_attributes (parm_die, node);
7399 add_type_attribute (parm_die, TREE_TYPE (node),
7400 TREE_READONLY (node),
7401 TREE_THIS_VOLATILE (node),
7403 if (DECL_ARTIFICIAL (node))
7404 add_AT_flag (parm_die, DW_AT_artificial, 1);
7407 equate_decl_number_to_die (node, parm_die);
7408 if (! DECL_ABSTRACT (node))
7409 add_location_or_const_value_attribute (parm_die, node);
7414 /* We were called with some kind of a ..._TYPE node. */
7415 add_type_attribute (parm_die, node, 0, 0, context_die);
7425 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
7426 at the end of an (ANSI prototyped) formal parameters list. */
7429 gen_unspecified_parameters_die (decl_or_type, context_die)
7430 register tree decl_or_type;
7431 register dw_die_ref context_die;
7433 register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters,
7437 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
7438 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
7439 parameters as specified in some function type specification (except for
7440 those which appear as part of a function *definition*).
7442 Note we must be careful here to output all of the parameter DIEs before*
7443 we output any DIEs needed to represent the types of the formal parameters.
7444 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
7445 non-parameter DIE it sees ends the formal parameter list. */
7448 gen_formal_types_die (function_or_method_type, context_die)
7449 register tree function_or_method_type;
7450 register dw_die_ref context_die;
7453 register tree formal_type = NULL;
7454 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
7457 /* In the case where we are generating a formal types list for a C++
7458 non-static member function type, skip over the first thing on the
7459 TYPE_ARG_TYPES list because it only represents the type of the hidden
7460 `this pointer'. The debugger should be able to figure out (without
7461 being explicitly told) that this non-static member function type takes a
7462 `this pointer' and should be able to figure what the type of that hidden
7463 parameter is from the DW_AT_member attribute of the parent
7464 DW_TAG_subroutine_type DIE. */
7465 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
7466 first_parm_type = TREE_CHAIN (first_parm_type);
7469 /* Make our first pass over the list of formal parameter types and output a
7470 DW_TAG_formal_parameter DIE for each one. */
7471 for (link = first_parm_type; link; link = TREE_CHAIN (link))
7473 register dw_die_ref parm_die;
7475 formal_type = TREE_VALUE (link);
7476 if (formal_type == void_type_node)
7479 /* Output a (nameless) DIE to represent the formal parameter itself. */
7480 parm_die = gen_formal_parameter_die (formal_type, context_die);
7481 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
7482 && link == first_parm_type)
7483 add_AT_flag (parm_die, DW_AT_artificial, 1);
7486 /* If this function type has an ellipsis, add a
7487 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
7488 if (formal_type != void_type_node)
7489 gen_unspecified_parameters_die (function_or_method_type, context_die);
7491 /* Make our second (and final) pass over the list of formal parameter types
7492 and output DIEs to represent those types (as necessary). */
7493 for (link = TYPE_ARG_TYPES (function_or_method_type);
7495 link = TREE_CHAIN (link))
7497 formal_type = TREE_VALUE (link);
7498 if (formal_type == void_type_node)
7501 gen_type_die (formal_type, context_die);
7505 /* Generate a DIE to represent a declared function (either file-scope or
7509 gen_subprogram_die (decl, context_die)
7511 register dw_die_ref context_die;
7513 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
7514 register tree origin = decl_ultimate_origin (decl);
7515 register dw_die_ref subr_die;
7516 register dw_loc_descr_ref fp_loc = NULL;
7517 register rtx fp_reg;
7518 register tree fn_arg_types;
7519 register tree outer_scope;
7520 register dw_die_ref old_die = lookup_decl_die (decl);
7521 register int declaration
7522 = (current_function_decl != decl
7524 && (context_die->die_tag == DW_TAG_structure_type
7525 || context_die->die_tag == DW_TAG_union_type)));
7529 subr_die = new_die (DW_TAG_subprogram, context_die);
7530 add_abstract_origin_attribute (subr_die, origin);
7534 register unsigned file_index
7535 = lookup_filename (DECL_SOURCE_FILE (decl));
7537 assert (get_AT_flag (old_die, DW_AT_declaration) == 1);
7539 /* If the definition comes from the same place as the declaration,
7540 maybe use the old DIE. We always want the DIE for this function
7541 that has the *_pc attributes to be under comp_unit_die so the
7542 debugger can find it. For inlines, that is the concrete instance,
7543 so we can use the old DIE here. For non-inline methods, we want a
7544 specification DIE at toplevel, so we need a new DIE. For local
7545 class methods, this does not apply. */
7546 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
7547 || context_die == NULL)
7548 && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
7549 && (get_AT_unsigned (old_die, DW_AT_decl_line)
7550 == DECL_SOURCE_LINE (decl)))
7554 /* Clear out the declaration attribute and the parm types. */
7555 remove_AT (subr_die, DW_AT_declaration);
7556 remove_children (subr_die);
7560 subr_die = new_die (DW_TAG_subprogram, context_die);
7561 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
7562 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
7563 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
7564 if (get_AT_unsigned (old_die, DW_AT_decl_line)
7565 != DECL_SOURCE_LINE (decl))
7567 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7572 register dw_die_ref scope_die;
7574 if (DECL_CONTEXT (decl))
7575 scope_die = scope_die_for (decl, context_die);
7577 /* Don't put block extern declarations under comp_unit_die. */
7578 scope_die = context_die;
7580 subr_die = new_die (DW_TAG_subprogram, scope_die);
7582 if (TREE_PUBLIC (decl))
7583 add_AT_flag (subr_die, DW_AT_external, 1);
7585 add_name_and_src_coords_attributes (subr_die, decl);
7586 if (debug_info_level > DINFO_LEVEL_TERSE)
7588 register tree type = TREE_TYPE (decl);
7590 add_prototyped_attribute (subr_die, type);
7591 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
7594 add_pure_or_virtual_attribute (subr_die, decl);
7595 if (DECL_ARTIFICIAL (decl))
7596 add_AT_flag (subr_die, DW_AT_artificial, 1);
7597 if (TREE_PROTECTED (decl))
7598 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
7599 else if (TREE_PRIVATE (decl))
7600 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
7605 add_AT_flag (subr_die, DW_AT_declaration, 1);
7607 /* The first time we see a member function, it is in the context of
7608 the class to which it belongs. We make sure of this by emitting
7609 the class first. The next time is the definition, which is
7610 handled above. The two may come from the same source text. */
7611 if (DECL_CONTEXT (decl))
7612 equate_decl_number_to_die (decl, subr_die);
7614 else if (DECL_ABSTRACT (decl))
7616 if (DECL_DEFER_OUTPUT (decl))
7618 if (DECL_INLINE (decl))
7619 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
7621 add_AT_unsigned (subr_die, DW_AT_inline,
7622 DW_INL_declared_not_inlined);
7624 else if (DECL_INLINE (decl))
7625 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
7629 equate_decl_number_to_die (decl, subr_die);
7631 else if (!DECL_EXTERNAL (decl))
7633 if (origin == NULL_TREE)
7634 equate_decl_number_to_die (decl, subr_die);
7636 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
7637 current_funcdef_number);
7638 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
7639 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
7640 current_funcdef_number);
7641 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
7643 add_pubname (decl, subr_die);
7644 add_arange (decl, subr_die);
7646 #ifdef MIPS_DEBUGGING_INFO
7647 /* Add a reference to the FDE for this routine. */
7648 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
7651 /* Define the "frame base" location for this routine. We use the
7652 frame pointer or stack pointer registers, since the RTL for local
7653 variables is relative to one of them. */
7655 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
7656 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
7659 /* ??? This fails for nested inline functions, because context_display
7660 is not part of the state saved/restored for inline functions. */
7661 if (current_function_needs_context)
7662 add_AT_location_description (subr_die, DW_AT_static_link,
7663 lookup_static_chain (decl));
7667 /* Now output descriptions of the arguments for this function. This gets
7668 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
7669 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
7670 `...' at the end of the formal parameter list. In order to find out if
7671 there was a trailing ellipsis or not, we must instead look at the type
7672 associated with the FUNCTION_DECL. This will be a node of type
7673 FUNCTION_TYPE. If the chain of type nodes hanging off of this
7674 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
7675 an ellipsis at the end. */
7676 push_decl_scope (decl);
7678 /* In the case where we are describing a mere function declaration, all we
7679 need to do here (and all we *can* do here) is to describe the *types* of
7680 its formal parameters. */
7681 if (debug_info_level <= DINFO_LEVEL_TERSE)
7683 else if (declaration)
7684 gen_formal_types_die (TREE_TYPE (decl), subr_die);
7687 /* Generate DIEs to represent all known formal parameters */
7688 register tree arg_decls = DECL_ARGUMENTS (decl);
7691 /* When generating DIEs, generate the unspecified_parameters DIE
7692 instead if we come across the arg "__builtin_va_alist" */
7693 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
7694 if (TREE_CODE (parm) == PARM_DECL)
7696 if (DECL_NAME (parm)
7697 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
7698 "__builtin_va_alist"))
7699 gen_unspecified_parameters_die (parm, subr_die);
7701 gen_decl_die (parm, subr_die);
7704 /* Decide whether we need a unspecified_parameters DIE at the end.
7705 There are 2 more cases to do this for: 1) the ansi ... declaration -
7706 this is detectable when the end of the arg list is not a
7707 void_type_node 2) an unprototyped function declaration (not a
7708 definition). This just means that we have no info about the
7709 parameters at all. */
7710 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
7711 if (fn_arg_types != NULL)
7713 /* this is the prototyped case, check for ... */
7714 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
7715 gen_unspecified_parameters_die (decl, subr_die);
7717 else if (DECL_INITIAL (decl) == NULL_TREE)
7718 gen_unspecified_parameters_die (decl, subr_die);
7721 /* Output Dwarf info for all of the stuff within the body of the function
7722 (if it has one - it may be just a declaration). */
7723 outer_scope = DECL_INITIAL (decl);
7725 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
7726 node created to represent a function. This outermost BLOCK actually
7727 represents the outermost binding contour for the function, i.e. the
7728 contour in which the function's formal parameters and labels get
7729 declared. Curiously, it appears that the front end doesn't actually
7730 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
7731 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
7732 list for the function instead.) The BLOCK_VARS list for the
7733 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
7734 the function however, and we output DWARF info for those in
7735 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
7736 node representing the function's outermost pair of curly braces, and
7737 any blocks used for the base and member initializers of a C++
7738 constructor function. */
7739 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
7741 current_function_has_inlines = 0;
7742 decls_for_scope (outer_scope, subr_die, 0);
7744 #if 0 && defined (MIPS_DEBUGGING_INFO)
7745 if (current_function_has_inlines)
7747 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
7748 if (! comp_unit_has_inlines)
7750 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
7751 comp_unit_has_inlines = 1;
7760 /* Generate a DIE to represent a declared data object. */
7763 gen_variable_die (decl, context_die)
7765 register dw_die_ref context_die;
7767 register tree origin = decl_ultimate_origin (decl);
7768 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
7770 dw_die_ref old_die = lookup_decl_die (decl);
7772 = (DECL_EXTERNAL (decl)
7773 || current_function_decl != decl_function_context (decl)
7774 || context_die->die_tag == DW_TAG_structure_type
7775 || context_die->die_tag == DW_TAG_union_type);
7778 add_abstract_origin_attribute (var_die, origin);
7779 /* Loop unrolling can create multiple blocks that refer to the same
7780 static variable, so we must test for the DW_AT_declaration flag. */
7781 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
7782 copy decls and set the DECL_ABSTRACT flag on them instead of
7784 else if (old_die && TREE_STATIC (decl)
7785 && get_AT_flag (old_die, DW_AT_declaration) == 1)
7787 /* ??? This is an instantiation of a C++ class level static. */
7788 add_AT_die_ref (var_die, DW_AT_specification, old_die);
7789 if (DECL_NAME (decl))
7791 register unsigned file_index
7792 = lookup_filename (DECL_SOURCE_FILE (decl));
7794 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
7795 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
7797 if (get_AT_unsigned (old_die, DW_AT_decl_line)
7798 != DECL_SOURCE_LINE (decl))
7800 add_AT_unsigned (var_die, DW_AT_decl_line,
7801 DECL_SOURCE_LINE (decl));
7806 add_name_and_src_coords_attributes (var_die, decl);
7807 add_type_attribute (var_die, TREE_TYPE (decl),
7808 TREE_READONLY (decl),
7809 TREE_THIS_VOLATILE (decl), context_die);
7811 if (TREE_PUBLIC (decl))
7812 add_AT_flag (var_die, DW_AT_external, 1);
7814 if (DECL_ARTIFICIAL (decl))
7815 add_AT_flag (var_die, DW_AT_artificial, 1);
7817 if (TREE_PROTECTED (decl))
7818 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
7820 else if (TREE_PRIVATE (decl))
7821 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
7825 add_AT_flag (var_die, DW_AT_declaration, 1);
7827 if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl))
7828 equate_decl_number_to_die (decl, var_die);
7830 if (! declaration && ! DECL_ABSTRACT (decl))
7832 equate_decl_number_to_die (decl, var_die);
7833 add_location_or_const_value_attribute (var_die, decl);
7834 add_pubname (decl, var_die);
7838 /* Generate a DIE to represent a label identifier. */
7841 gen_label_die (decl, context_die)
7843 register dw_die_ref context_die;
7845 register tree origin = decl_ultimate_origin (decl);
7846 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
7848 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7849 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
7852 add_abstract_origin_attribute (lbl_die, origin);
7854 add_name_and_src_coords_attributes (lbl_die, decl);
7856 if (DECL_ABSTRACT (decl))
7857 equate_decl_number_to_die (decl, lbl_die);
7860 insn = DECL_RTL (decl);
7861 if (GET_CODE (insn) == CODE_LABEL)
7863 /* When optimization is enabled (via -O) some parts of the compiler
7864 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
7865 represent source-level labels which were explicitly declared by
7866 the user. This really shouldn't be happening though, so catch
7867 it if it ever does happen. */
7868 if (INSN_DELETED_P (insn))
7871 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
7872 ASM_GENERATE_INTERNAL_LABEL (label, label2,
7873 (unsigned) INSN_UID (insn));
7874 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
7879 /* Generate a DIE for a lexical block. */
7882 gen_lexical_block_die (stmt, context_die, depth)
7884 register dw_die_ref context_die;
7887 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
7888 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7890 if (! BLOCK_ABSTRACT (stmt))
7892 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
7894 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
7895 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
7896 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
7899 push_decl_scope (stmt);
7900 decls_for_scope (stmt, stmt_die, depth);
7904 /* Generate a DIE for an inlined subprogram. */
7907 gen_inlined_subroutine_die (stmt, context_die, depth)
7909 register dw_die_ref context_die;
7912 if (! BLOCK_ABSTRACT (stmt))
7914 register dw_die_ref subr_die
7915 = new_die (DW_TAG_inlined_subroutine, context_die);
7916 register tree decl = block_ultimate_origin (stmt);
7917 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7919 add_abstract_origin_attribute (subr_die, decl);
7920 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
7922 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
7923 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
7924 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
7925 push_decl_scope (decl);
7926 decls_for_scope (stmt, subr_die, depth);
7928 current_function_has_inlines = 1;
7932 /* Generate a DIE for a field in a record, or structure. */
7935 gen_field_die (decl, context_die)
7937 register dw_die_ref context_die;
7939 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
7941 add_name_and_src_coords_attributes (decl_die, decl);
7942 add_type_attribute (decl_die, member_declared_type (decl),
7943 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
7946 /* If this is a bit field... */
7947 if (DECL_BIT_FIELD_TYPE (decl))
7949 add_byte_size_attribute (decl_die, decl);
7950 add_bit_size_attribute (decl_die, decl);
7951 add_bit_offset_attribute (decl_die, decl);
7954 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
7955 add_data_member_location_attribute (decl_die, decl);
7957 if (DECL_ARTIFICIAL (decl))
7958 add_AT_flag (decl_die, DW_AT_artificial, 1);
7960 if (TREE_PROTECTED (decl))
7961 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
7963 else if (TREE_PRIVATE (decl))
7964 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
7968 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
7969 Use modified_type_die instead.
7970 We keep this code here just in case these types of DIEs may be needed to
7971 represent certain things in other languages (e.g. Pascal) someday. */
7973 gen_pointer_type_die (type, context_die)
7975 register dw_die_ref context_die;
7977 register dw_die_ref ptr_die
7978 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
7980 equate_type_number_to_die (type, ptr_die);
7981 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
7982 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7985 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
7986 Use modified_type_die instead.
7987 We keep this code here just in case these types of DIEs may be needed to
7988 represent certain things in other languages (e.g. Pascal) someday. */
7990 gen_reference_type_die (type, context_die)
7992 register dw_die_ref context_die;
7994 register dw_die_ref ref_die
7995 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
7997 equate_type_number_to_die (type, ref_die);
7998 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
7999 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8003 /* Generate a DIE for a pointer to a member type. */
8005 gen_ptr_to_mbr_type_die (type, context_die)
8007 register dw_die_ref context_die;
8009 register dw_die_ref ptr_die
8010 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8012 equate_type_number_to_die (type, ptr_die);
8013 add_AT_die_ref (ptr_die, DW_AT_containing_type,
8014 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
8015 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8018 /* Generate the DIE for the compilation unit. */
8021 gen_compile_unit_die (main_input_filename)
8022 register char *main_input_filename;
8025 char *wd = getpwd ();
8027 comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
8028 add_name_attribute (comp_unit_die, main_input_filename);
8031 add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
8033 sprintf (producer, "%s %s", language_string, version_string);
8035 #ifdef MIPS_DEBUGGING_INFO
8036 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8037 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8038 not appear in the producer string, the debugger reaches the conclusion
8039 that the object file is stripped and has no debugging information.
8040 To get the MIPS/SGI debugger to believe that there is debugging
8041 information in the object file, we add a -g to the producer string. */
8042 if (debug_info_level > DINFO_LEVEL_TERSE)
8043 strcat (producer, " -g");
8046 add_AT_string (comp_unit_die, DW_AT_producer, producer);
8048 if (strcmp (language_string, "GNU C++") == 0)
8049 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
8051 else if (strcmp (language_string, "GNU Ada") == 0)
8052 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
8054 else if (strcmp (language_string, "GNU F77") == 0)
8055 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77);
8057 else if (flag_traditional)
8058 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
8061 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
8063 #if 0 /* unimplemented */
8064 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
8065 add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
8069 /* Generate a DIE for a string type. */
8072 gen_string_type_die (type, context_die)
8074 register dw_die_ref context_die;
8076 register dw_die_ref type_die
8077 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
8079 equate_type_number_to_die (type, type_die);
8081 /* Fudge the string length attribute for now. */
8083 /* TODO: add string length info.
8084 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8085 bound_representation (upper_bound, 0, 'u'); */
8088 /* Generate the DIE for a base class. */
8091 gen_inheritance_die (binfo, context_die)
8092 register tree binfo;
8093 register dw_die_ref context_die;
8095 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
8097 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
8098 add_data_member_location_attribute (die, binfo);
8100 if (TREE_VIA_VIRTUAL (binfo))
8101 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8102 if (TREE_VIA_PUBLIC (binfo))
8103 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
8104 else if (TREE_VIA_PROTECTED (binfo))
8105 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
8108 /* Genearate a DIE for a class member. */
8111 gen_member_die (type, context_die)
8113 register dw_die_ref context_die;
8115 register tree member;
8117 /* If this is not an incomplete type, output descriptions of each of its
8118 members. Note that as we output the DIEs necessary to represent the
8119 members of this record or union type, we will also be trying to output
8120 DIEs to represent the *types* of those members. However the `type'
8121 function (above) will specifically avoid generating type DIEs for member
8122 types *within* the list of member DIEs for this (containing) type execpt
8123 for those types (of members) which are explicitly marked as also being
8124 members of this (containing) type themselves. The g++ front- end can
8125 force any given type to be treated as a member of some other
8126 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8127 to point to the TREE node representing the appropriate (containing)
8130 /* First output info about the base classes. */
8131 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
8133 register tree bases = TYPE_BINFO_BASETYPES (type);
8134 register int n_bases = TREE_VEC_LENGTH (bases);
8137 for (i = 0; i < n_bases; i++)
8138 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
8141 /* Now output info about the data members and type members. */
8142 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
8143 gen_decl_die (member, context_die);
8145 /* Now output info about the function members (if any). */
8146 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
8147 gen_decl_die (member, context_die);
8150 /* Generate a DIE for a structure or union type. */
8153 gen_struct_or_union_type_die (type, context_die)
8155 register dw_die_ref context_die;
8157 register dw_die_ref type_die = lookup_type_die (type);
8158 register dw_die_ref scope_die = 0;
8159 register int nested = 0;
8161 if (type_die && ! TYPE_SIZE (type))
8164 if (TYPE_CONTEXT (type) != NULL_TREE
8165 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't')
8168 scope_die = scope_die_for (type, context_die);
8170 if (! type_die || (nested && scope_die == comp_unit_die))
8171 /* First occurrence of type or toplevel definition of nested class. */
8173 register dw_die_ref old_die = type_die;
8175 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
8176 ? DW_TAG_structure_type : DW_TAG_union_type,
8178 equate_type_number_to_die (type, type_die);
8179 add_name_attribute (type_die, type_tag (type));
8181 add_AT_die_ref (type_die, DW_AT_specification, old_die);
8184 remove_AT (type_die, DW_AT_declaration);
8186 /* If we're not in the right context to be defining this type, defer to
8187 avoid tricky recursion. */
8188 if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die)
8190 add_AT_flag (type_die, DW_AT_declaration, 1);
8193 /* If this type has been completed, then give it a byte_size attribute and
8194 then give a list of members. */
8195 else if (TYPE_SIZE (type))
8197 /* Prevent infinite recursion in cases where the type of some member of
8198 this type is expressed in terms of this type itself. */
8199 TREE_ASM_WRITTEN (type) = 1;
8200 add_byte_size_attribute (type_die, type);
8201 if (type_tag (type))
8202 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8204 /* If the first reference to this type was as the return type of an
8205 inline function, then it may not have a parent. Fix this now. */
8206 if (type_die->die_parent == NULL)
8207 add_child_die (scope_die, type_die);
8209 push_decl_scope (type);
8210 gen_member_die (type, type_die);
8213 /* GNU extension: Record what type our vtable lives in. */
8214 if (TYPE_VFIELD (type))
8216 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
8218 gen_type_die (vtype, context_die);
8219 add_AT_die_ref (type_die, DW_AT_containing_type,
8220 lookup_type_die (vtype));
8224 add_AT_flag (type_die, DW_AT_declaration, 1);
8227 /* Generate a DIE for a subroutine _type_. */
8230 gen_subroutine_type_die (type, context_die)
8232 register dw_die_ref context_die;
8234 register tree return_type = TREE_TYPE (type);
8235 register dw_die_ref subr_die
8236 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
8238 equate_type_number_to_die (type, subr_die);
8239 add_prototyped_attribute (subr_die, type);
8240 add_type_attribute (subr_die, return_type, 0, 0, context_die);
8241 gen_formal_types_die (type, subr_die);
8244 /* Generate a DIE for a type definition */
8247 gen_typedef_die (decl, context_die)
8249 register dw_die_ref context_die;
8251 register dw_die_ref type_die;
8252 register tree origin;
8254 if (TREE_ASM_WRITTEN (decl))
8256 TREE_ASM_WRITTEN (decl) = 1;
8258 type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
8259 origin = decl_ultimate_origin (decl);
8261 add_abstract_origin_attribute (type_die, origin);
8265 add_name_and_src_coords_attributes (type_die, decl);
8266 if (DECL_ORIGINAL_TYPE (decl))
8268 type = DECL_ORIGINAL_TYPE (decl);
8269 equate_type_number_to_die (TREE_TYPE (decl), type_die);
8272 type = TREE_TYPE (decl);
8273 add_type_attribute (type_die, type, TREE_READONLY (decl),
8274 TREE_THIS_VOLATILE (decl), context_die);
8277 if (DECL_ABSTRACT (decl))
8278 equate_decl_number_to_die (decl, type_die);
8281 /* Generate a type description DIE. */
8284 gen_type_die (type, context_die)
8286 register dw_die_ref context_die;
8288 if (type == NULL_TREE || type == error_mark_node)
8291 /* We are going to output a DIE to represent the unqualified version of of
8292 this type (i.e. without any const or volatile qualifiers) so get the
8293 main variant (i.e. the unqualified version) of this type now. */
8294 type = type_main_variant (type);
8296 if (TREE_ASM_WRITTEN (type))
8299 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8300 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
8302 TREE_ASM_WRITTEN (type) = 1;
8303 gen_decl_die (TYPE_NAME (type), context_die);
8307 switch (TREE_CODE (type))
8313 case REFERENCE_TYPE:
8314 /* For these types, all that is required is that we output a DIE (or a
8315 set of DIEs) to represent the "basis" type. */
8316 gen_type_die (TREE_TYPE (type), context_die);
8320 /* This code is used for C++ pointer-to-data-member types.
8321 Output a description of the relevant class type. */
8322 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
8324 /* Output a description of the type of the object pointed to. */
8325 gen_type_die (TREE_TYPE (type), context_die);
8327 /* Now output a DIE to represent this pointer-to-data-member type
8329 gen_ptr_to_mbr_type_die (type, context_die);
8333 gen_type_die (TYPE_DOMAIN (type), context_die);
8334 gen_set_type_die (type, context_die);
8338 gen_type_die (TREE_TYPE (type), context_die);
8339 abort (); /* No way to represent these in Dwarf yet! */
8343 /* Force out return type (in case it wasn't forced out already). */
8344 gen_type_die (TREE_TYPE (type), context_die);
8345 gen_subroutine_type_die (type, context_die);
8349 /* Force out return type (in case it wasn't forced out already). */
8350 gen_type_die (TREE_TYPE (type), context_die);
8351 gen_subroutine_type_die (type, context_die);
8355 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
8357 gen_type_die (TREE_TYPE (type), context_die);
8358 gen_string_type_die (type, context_die);
8361 gen_array_type_die (type, context_die);
8367 case QUAL_UNION_TYPE:
8368 /* If this is a nested type whose containing class hasn't been
8369 written out yet, writing it out will cover this one, too. */
8370 if (TYPE_CONTEXT (type)
8371 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
8372 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8374 gen_type_die (TYPE_CONTEXT (type), context_die);
8376 if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8379 /* If that failed, attach ourselves to the stub. */
8380 push_decl_scope (TYPE_CONTEXT (type));
8381 context_die = lookup_type_die (TYPE_CONTEXT (type));
8384 if (TREE_CODE (type) == ENUMERAL_TYPE)
8385 gen_enumeration_type_die (type, context_die);
8387 gen_struct_or_union_type_die (type, context_die);
8389 if (TYPE_CONTEXT (type)
8390 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
8391 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8394 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
8395 it up if it is ever completed. gen_*_type_die will set it for us
8396 when appropriate. */
8405 /* No DIEs needed for fundamental types. */
8409 /* No Dwarf representation currently defined. */
8416 TREE_ASM_WRITTEN (type) = 1;
8419 /* Generate a DIE for a tagged type instantiation. */
8422 gen_tagged_type_instantiation_die (type, context_die)
8424 register dw_die_ref context_die;
8426 if (type == NULL_TREE || type == error_mark_node)
8429 /* We are going to output a DIE to represent the unqualified version of of
8430 this type (i.e. without any const or volatile qualifiers) so make sure
8431 that we have the main variant (i.e. the unqualified version) of this
8433 assert (type == type_main_variant (type));
8434 assert (TREE_ASM_WRITTEN (type));
8436 switch (TREE_CODE (type))
8442 gen_inlined_enumeration_type_die (type, context_die);
8446 gen_inlined_structure_type_die (type, context_die);
8450 case QUAL_UNION_TYPE:
8451 gen_inlined_union_type_die (type, context_die);
8459 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
8460 things which are local to the given block. */
8463 gen_block_die (stmt, context_die, depth)
8465 register dw_die_ref context_die;
8468 register int must_output_die = 0;
8469 register tree origin;
8471 register enum tree_code origin_code;
8473 /* Ignore blocks never really used to make RTL. */
8475 if (stmt == NULL_TREE || !TREE_USED (stmt))
8478 /* Determine the "ultimate origin" of this block. This block may be an
8479 inlined instance of an inlined instance of inline function, so we have
8480 to trace all of the way back through the origin chain to find out what
8481 sort of node actually served as the original seed for the creation of
8482 the current block. */
8483 origin = block_ultimate_origin (stmt);
8484 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
8486 /* Determine if we need to output any Dwarf DIEs at all to represent this
8488 if (origin_code == FUNCTION_DECL)
8489 /* The outer scopes for inlinings *must* always be represented. We
8490 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
8491 must_output_die = 1;
8494 /* In the case where the current block represents an inlining of the
8495 "body block" of an inline function, we must *NOT* output any DIE for
8496 this block because we have already output a DIE to represent the
8497 whole inlined function scope and the "body block" of any function
8498 doesn't really represent a different scope according to ANSI C
8499 rules. So we check here to make sure that this block does not
8500 represent a "body block inlining" before trying to set the
8501 `must_output_die' flag. */
8502 if (! is_body_block (origin ? origin : stmt))
8504 /* Determine if this block directly contains any "significant"
8505 local declarations which we will need to output DIEs for. */
8506 if (debug_info_level > DINFO_LEVEL_TERSE)
8507 /* We are not in terse mode so *any* local declaration counts
8508 as being a "significant" one. */
8509 must_output_die = (BLOCK_VARS (stmt) != NULL);
8511 /* We are in terse mode, so only local (nested) function
8512 definitions count as "significant" local declarations. */
8513 for (decl = BLOCK_VARS (stmt);
8514 decl != NULL; decl = TREE_CHAIN (decl))
8515 if (TREE_CODE (decl) == FUNCTION_DECL
8516 && DECL_INITIAL (decl))
8518 must_output_die = 1;
8524 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
8525 DIE for any block which contains no significant local declarations at
8526 all. Rather, in such cases we just call `decls_for_scope' so that any
8527 needed Dwarf info for any sub-blocks will get properly generated. Note
8528 that in terse mode, our definition of what constitutes a "significant"
8529 local declaration gets restricted to include only inlined function
8530 instances and local (nested) function definitions. */
8531 if (must_output_die)
8533 if (origin_code == FUNCTION_DECL)
8534 gen_inlined_subroutine_die (stmt, context_die, depth);
8536 gen_lexical_block_die (stmt, context_die, depth);
8539 decls_for_scope (stmt, context_die, depth);
8542 /* Generate all of the decls declared within a given scope and (recursively)
8543 all of it's sub-blocks. */
8546 decls_for_scope (stmt, context_die, depth)
8548 register dw_die_ref context_die;
8552 register tree subblocks;
8554 /* Ignore blocks never really used to make RTL. */
8555 if (stmt == NULL_TREE || ! TREE_USED (stmt))
8558 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
8559 next_block_number++;
8561 /* Output the DIEs to represent all of the data objects and typedefs
8562 declared directly within this block but not within any nested
8563 sub-blocks. Also, nested function and tag DIEs have been
8564 generated with a parent of NULL; fix that up now. */
8565 for (decl = BLOCK_VARS (stmt);
8566 decl != NULL; decl = TREE_CHAIN (decl))
8568 register dw_die_ref die;
8570 if (TREE_CODE (decl) == FUNCTION_DECL)
8571 die = lookup_decl_die (decl);
8572 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
8573 die = lookup_type_die (TREE_TYPE (decl));
8577 if (die != NULL && die->die_parent == NULL)
8578 add_child_die (context_die, die);
8580 gen_decl_die (decl, context_die);
8583 /* Output the DIEs to represent all sub-blocks (and the items declared
8584 therein) of this block. */
8585 for (subblocks = BLOCK_SUBBLOCKS (stmt);
8587 subblocks = BLOCK_CHAIN (subblocks))
8588 gen_block_die (subblocks, context_die, depth + 1);
8591 /* Is this a typedef we can avoid emitting? */
8594 is_redundant_typedef (decl)
8597 if (TYPE_DECL_IS_STUB (decl))
8600 if (DECL_ARTIFICIAL (decl)
8601 && DECL_CONTEXT (decl)
8602 && is_tagged_type (DECL_CONTEXT (decl))
8603 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
8604 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
8605 /* Also ignore the artificial member typedef for the class name. */
8611 /* Generate Dwarf debug information for a decl described by DECL. */
8614 gen_decl_die (decl, context_die)
8616 register dw_die_ref context_die;
8618 register tree origin;
8620 /* Make a note of the decl node we are going to be working on. We may need
8621 to give the user the source coordinates of where it appeared in case we
8622 notice (later on) that something about it looks screwy. */
8623 dwarf_last_decl = decl;
8625 if (TREE_CODE (decl) == ERROR_MARK)
8628 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
8629 ignore a function definition, since that would screw up our count of
8630 blocks, and that it turn will completely screw up the the labels we will
8631 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
8632 subsequent blocks). */
8633 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
8636 switch (TREE_CODE (decl))
8639 /* The individual enumerators of an enum type get output when we output
8640 the Dwarf representation of the relevant enum type itself. */
8644 /* Don't output any DIEs to represent mere function declarations,
8645 unless they are class members or explicit block externs. */
8646 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
8647 && (current_function_decl == NULL_TREE || ! DECL_ARTIFICIAL (decl)))
8650 if (debug_info_level > DINFO_LEVEL_TERSE)
8652 /* Before we describe the FUNCTION_DECL itself, make sure that we
8653 have described its return type. */
8654 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
8656 /* And its containing type. */
8657 origin = decl_class_context (decl);
8658 if (origin != NULL_TREE)
8659 gen_type_die (origin, context_die);
8661 /* And its virtual context. */
8662 if (DECL_VINDEX (decl) != NULL_TREE)
8663 gen_type_die (DECL_CONTEXT (decl), context_die);
8666 /* Now output a DIE to represent the function itself. */
8667 gen_subprogram_die (decl, context_die);
8671 /* If we are in terse mode, don't generate any DIEs to represent any
8673 if (debug_info_level <= DINFO_LEVEL_TERSE)
8676 /* In the special case of a TYPE_DECL node representing the
8677 declaration of some type tag, if the given TYPE_DECL is marked as
8678 having been instantiated from some other (original) TYPE_DECL node
8679 (e.g. one which was generated within the original definition of an
8680 inline function) we have to generate a special (abbreviated)
8681 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
8683 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
8685 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
8689 if (is_redundant_typedef (decl))
8690 gen_type_die (TREE_TYPE (decl), context_die);
8692 /* Output a DIE to represent the typedef itself. */
8693 gen_typedef_die (decl, context_die);
8697 if (debug_info_level >= DINFO_LEVEL_NORMAL)
8698 gen_label_die (decl, context_die);
8702 /* If we are in terse mode, don't generate any DIEs to represent any
8703 variable declarations or definitions. */
8704 if (debug_info_level <= DINFO_LEVEL_TERSE)
8707 /* Output any DIEs that are needed to specify the type of this data
8709 gen_type_die (TREE_TYPE (decl), context_die);
8711 /* And its containing type. */
8712 origin = decl_class_context (decl);
8713 if (origin != NULL_TREE)
8714 gen_type_die (origin, context_die);
8716 /* Now output the DIE to represent the data object itself. This gets
8717 complicated because of the possibility that the VAR_DECL really
8718 represents an inlined instance of a formal parameter for an inline
8720 origin = decl_ultimate_origin (decl);
8721 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
8722 gen_formal_parameter_die (decl, context_die);
8724 gen_variable_die (decl, context_die);
8728 /* Ignore the nameless fields that are used to skip bits, but
8729 handle C++ anonymous unions. */
8730 if (DECL_NAME (decl) != NULL_TREE
8731 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
8733 gen_type_die (member_declared_type (decl), context_die);
8734 gen_field_die (decl, context_die);
8739 gen_type_die (TREE_TYPE (decl), context_die);
8740 gen_formal_parameter_die (decl, context_die);
8748 /* Write the debugging output for DECL. */
8751 dwarf2out_decl (decl)
8754 register dw_die_ref context_die = comp_unit_die;
8756 if (TREE_CODE (decl) == ERROR_MARK)
8759 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
8760 hope that the node in question doesn't represent a function definition.
8761 If it does, then totally ignoring it is bound to screw up our count of
8762 blocks, and that it turn will completely screw up the the labels we will
8763 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
8764 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
8765 own sequence numbers with them!) */
8766 if (DECL_IGNORED_P (decl))
8768 if (TREE_CODE (decl) == FUNCTION_DECL
8769 && DECL_INITIAL (decl) != NULL)
8775 switch (TREE_CODE (decl))
8778 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
8779 builtin function. Explicit programmer-supplied declarations of
8780 these same functions should NOT be ignored however. */
8781 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
8784 /* What we would really like to do here is to filter out all mere
8785 file-scope declarations of file-scope functions which are never
8786 referenced later within this translation unit (and keep all of ones
8787 that *are* referenced later on) but we aren't clarvoiant, so we have
8788 no idea which functions will be referenced in the future (i.e. later
8789 on within the current translation unit). So here we just ignore all
8790 file-scope function declarations which are not also definitions. If
8791 and when the debugger needs to know something about these funcstion,
8792 it wil have to hunt around and find the DWARF information associated
8793 with the definition of the function. Note that we can't just check
8794 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
8795 definitions and which ones represent mere declarations. We have to
8796 check `DECL_INITIAL' instead. That's because the C front-end
8797 supports some weird semantics for "extern inline" function
8798 definitions. These can get inlined within the current translation
8799 unit (an thus, we need to generate DWARF info for their abstract
8800 instances so that the DWARF info for the concrete inlined instances
8801 can have something to refer to) but the compiler never generates any
8802 out-of-lines instances of such things (despite the fact that they
8803 *are* definitions). The important point is that the C front-end
8804 marks these "extern inline" functions as DECL_EXTERNAL, but we need
8805 to generate DWARF for them anyway. Note that the C++ front-end also
8806 plays some similar games for inline function definitions appearing
8807 within include files which also contain
8808 `#pragma interface' pragmas. */
8809 if (DECL_INITIAL (decl) == NULL_TREE)
8812 /* If we're a nested function, initially use a parent of NULL; if we're
8813 a plain function, this will be fixed up in decls_for_scope. If
8814 we're a method, it will be ignored, since we already have a DIE. */
8815 if (decl_function_context (decl))
8821 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
8822 declaration and if the declaration was never even referenced from
8823 within this entire compilation unit. We suppress these DIEs in
8824 order to save space in the .debug section (by eliminating entries
8825 which are probably useless). Note that we must not suppress
8826 block-local extern declarations (whether used or not) because that
8827 would screw-up the debugger's name lookup mechanism and cause it to
8828 miss things which really ought to be in scope at a given point. */
8829 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
8832 /* If we are in terse mode, don't generate any DIEs to represent any
8833 variable declarations or definitions. */
8834 if (debug_info_level <= DINFO_LEVEL_TERSE)
8839 /* Don't bother trying to generate any DIEs to represent any of the
8840 normal built-in types for the language we are compiling. */
8841 if (DECL_SOURCE_LINE (decl) == 0)
8843 /* OK, we need to generate one for `bool' so GDB knows what type
8844 comparisons have. */
8845 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
8846 == DW_LANG_C_plus_plus)
8847 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
8848 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
8853 /* If we are in terse mode, don't generate any DIEs for types. */
8854 if (debug_info_level <= DINFO_LEVEL_TERSE)
8857 /* If we're a function-scope tag, initially use a parent of NULL;
8858 this will be fixed up in decls_for_scope. */
8859 if (decl_function_context (decl))
8868 gen_decl_die (decl, context_die);
8869 output_pending_types_for_scope (comp_unit_die);
8872 /* Output a marker (i.e. a label) for the beginning of the generated code for
8876 dwarf2out_begin_block (blocknum)
8877 register unsigned blocknum;
8879 function_section (current_function_decl);
8880 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
8883 /* Output a marker (i.e. a label) for the end of the generated code for a
8887 dwarf2out_end_block (blocknum)
8888 register unsigned blocknum;
8890 function_section (current_function_decl);
8891 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
8894 /* Output a marker (i.e. a label) at a point in the assembly code which
8895 corresponds to a given source level label. */
8898 dwarf2out_label (insn)
8901 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8903 if (debug_info_level >= DINFO_LEVEL_NORMAL)
8905 function_section (current_function_decl);
8906 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
8907 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
8908 (unsigned) INSN_UID (insn));
8912 /* Lookup a filename (in the list of filenames that we know about here in
8913 dwarf2out.c) and return its "index". The index of each (known) filename is
8914 just a unique number which is associated with only that one filename.
8915 We need such numbers for the sake of generating labels
8916 (in the .debug_sfnames section) and references to those
8917 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
8918 If the filename given as an argument is not found in our current list,
8919 add it to the list and assign it the next available unique index number.
8920 In order to speed up searches, we remember the index of the filename
8921 was looked up last. This handles the majority of all searches. */
8924 lookup_filename (file_name)
8927 static unsigned last_file_lookup_index = 0;
8928 register unsigned i;
8930 /* Check to see if the file name that was searched on the previous call
8931 matches this file name. If so, return the index. */
8932 if (last_file_lookup_index != 0)
8933 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
8934 return last_file_lookup_index;
8936 /* Didn't match the previous lookup, search the table */
8937 for (i = 1; i < file_table_in_use; ++i)
8938 if (strcmp (file_name, file_table[i]) == 0)
8940 last_file_lookup_index = i;
8944 /* Prepare to add a new table entry by making sure there is enough space in
8945 the table to do so. If not, expand the current table. */
8946 if (file_table_in_use == file_table_allocated)
8948 file_table_allocated += FILE_TABLE_INCREMENT;
8950 = (char **) xrealloc (file_table,
8951 file_table_allocated * sizeof (char *));
8954 /* Add the new entry to the end of the filename table. */
8955 file_table[file_table_in_use] = xstrdup (file_name);
8956 last_file_lookup_index = file_table_in_use++;
8958 return last_file_lookup_index;
8961 /* Output a label to mark the beginning of a source code line entry
8962 and record information relating to this source line, in
8963 'line_info_table' for later output of the .debug_line section. */
8966 dwarf2out_line (filename, line)
8967 register char *filename;
8968 register unsigned line;
8970 if (debug_info_level >= DINFO_LEVEL_NORMAL)
8972 function_section (current_function_decl);
8974 if (DECL_SECTION_NAME (current_function_decl))
8976 register dw_separate_line_info_ref line_info;
8977 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
8978 separate_line_info_table_in_use);
8979 fputc ('\n', asm_out_file);
8981 /* expand the line info table if necessary */
8982 if (separate_line_info_table_in_use
8983 == separate_line_info_table_allocated)
8985 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
8986 separate_line_info_table
8987 = (dw_separate_line_info_ref)
8988 xrealloc (separate_line_info_table,
8989 separate_line_info_table_allocated
8990 * sizeof (dw_separate_line_info_entry));
8993 /* Add the new entry at the end of the line_info_table. */
8995 = &separate_line_info_table[separate_line_info_table_in_use++];
8996 line_info->dw_file_num = lookup_filename (filename);
8997 line_info->dw_line_num = line;
8998 line_info->function = current_funcdef_number;
9002 register dw_line_info_ref line_info;
9004 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
9005 line_info_table_in_use);
9006 fputc ('\n', asm_out_file);
9008 /* Expand the line info table if necessary. */
9009 if (line_info_table_in_use == line_info_table_allocated)
9011 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9013 = (dw_line_info_ref)
9014 xrealloc (line_info_table,
9015 (line_info_table_allocated
9016 * sizeof (dw_line_info_entry)));
9019 /* Add the new entry at the end of the line_info_table. */
9020 line_info = &line_info_table[line_info_table_in_use++];
9021 line_info->dw_file_num = lookup_filename (filename);
9022 line_info->dw_line_num = line;
9027 /* Record the beginning of a new source file, for later output
9028 of the .debug_macinfo section. At present, unimplemented. */
9031 dwarf2out_start_source_file (filename)
9032 register char *filename;
9036 /* Record the end of a source file, for later output
9037 of the .debug_macinfo section. At present, unimplemented. */
9040 dwarf2out_end_source_file ()
9044 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9045 the tail part of the directive line, i.e. the part which is past the
9046 initial whitespace, #, whitespace, directive-name, whitespace part. */
9049 dwarf2out_define (lineno, buffer)
9050 register unsigned lineno;
9051 register char *buffer;
9053 static int initialized = 0;
9056 dwarf2out_start_source_file (primary_filename);
9061 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9062 the tail part of the directive line, i.e. the part which is past the
9063 initial whitespace, #, whitespace, directive-name, whitespace part. */
9066 dwarf2out_undef (lineno, buffer)
9067 register unsigned lineno;
9068 register char *buffer;
9072 /* Set up for Dwarf output at the start of compilation. */
9075 dwarf2out_init (asm_out_file, main_input_filename)
9076 register FILE *asm_out_file;
9077 register char *main_input_filename;
9079 /* Remember the name of the primary input file. */
9080 primary_filename = main_input_filename;
9082 /* Allocate the initial hunk of the file_table. */
9083 file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *));
9084 bzero ((char *) file_table, FILE_TABLE_INCREMENT * sizeof (char *));
9085 file_table_allocated = FILE_TABLE_INCREMENT;
9087 /* Skip the first entry - file numbers begin at 1. */
9088 file_table_in_use = 1;
9090 /* Allocate the initial hunk of the decl_die_table. */
9092 = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
9093 bzero ((char *) decl_die_table,
9094 DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
9095 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
9096 decl_die_table_in_use = 0;
9098 /* Allocate the initial hunk of the decl_scope_table. */
9100 = (tree *) xmalloc (DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
9101 bzero ((char *) decl_scope_table,
9102 DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
9103 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
9104 decl_scope_depth = 0;
9106 /* Allocate the initial hunk of the abbrev_die_table. */
9108 = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT
9109 * sizeof (dw_die_ref));
9110 bzero ((char *) abbrev_die_table,
9111 ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
9112 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
9113 /* Zero-th entry is allocated, but unused */
9114 abbrev_die_table_in_use = 1;
9116 /* Allocate the initial hunk of the line_info_table. */
9118 = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT
9119 * sizeof (dw_line_info_entry));
9120 bzero ((char *) line_info_table,
9121 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
9122 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
9123 /* Zero-th entry is allocated, but unused */
9124 line_info_table_in_use = 1;
9126 /* Generate the initial DIE for the .debug section. Note that the (string)
9127 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9128 will (typically) be a relative pathname and that this pathname should be
9129 taken as being relative to the directory from which the compiler was
9130 invoked when the given (base) source file was compiled. */
9131 gen_compile_unit_die (main_input_filename);
9133 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
9135 /* Initialize the frame unwind information. Eventually this should be
9136 called from compile_file instead. */
9137 dwarf2out_frame_init ();
9140 /* Output stuff that dwarf requires at the end of every file,
9141 and generate the DWARF-2 debugging info. */
9146 limbo_die_node *node, *next_node;
9150 /* Traverse the limbo die list, and add parent/child links. The only
9151 dies without parents that should be here are concrete instances of
9152 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9153 For concrete instances, we can get the parent die from the abstract
9155 for (node = limbo_die_list; node; node = next_node)
9157 next_node = node->next;
9160 if (die->die_parent == NULL)
9162 a = get_AT (die, DW_AT_abstract_origin);
9164 add_child_die (a->dw_attr_val.v.val_die_ref->die_parent, die);
9165 else if (die == comp_unit_die)
9173 /* Traverse the DIE tree and add sibling attributes to those DIE's
9174 that have children. */
9175 add_sibling_attributes (comp_unit_die);
9177 /* Output a terminator label for the .text section. */
9178 fputc ('\n', asm_out_file);
9179 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9180 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
9183 /* Output a terminator label for the .data section. */
9184 fputc ('\n', asm_out_file);
9185 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
9186 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
9188 /* Output a terminator label for the .bss section. */
9189 fputc ('\n', asm_out_file);
9190 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
9191 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
9194 /* Output the frame unwind information. Eventually this should be called
9195 from compile_file instead. */
9196 dwarf2out_frame_finish ();
9198 /* Output the source line correspondence table. */
9199 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
9201 fputc ('\n', asm_out_file);
9202 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9203 output_line_info ();
9205 /* We can only use the low/high_pc attributes if all of the code
9207 if (separate_line_info_table_in_use == 0)
9209 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_SECTION);
9210 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
9213 add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, DEBUG_LINE_SECTION);
9216 /* Output the abbreviation table. */
9217 fputc ('\n', asm_out_file);
9218 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9219 build_abbrev_table (comp_unit_die);
9220 output_abbrev_section ();
9222 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9223 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9224 calc_die_sizes (comp_unit_die);
9226 /* Output debugging information. */
9227 fputc ('\n', asm_out_file);
9228 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9229 output_compilation_unit_header ();
9230 output_die (comp_unit_die);
9232 if (pubname_table_in_use)
9234 /* Output public names table. */
9235 fputc ('\n', asm_out_file);
9236 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
9240 if (fde_table_in_use)
9242 /* Output the address range information. */
9243 fputc ('\n', asm_out_file);
9244 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
9248 #endif /* DWARF2_DEBUGGING_INFO */