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. */
25 /* The first part of this file deals with the DWARF 2 frame unwind
26 information, which is also used by the GCC efficient exception handling
27 mechanism. The second part, controlled only by an #ifdef
28 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
31 #if defined (DWARF2_DEBUGGING_INFO) || defined (INCOMING_RETURN_ADDR_RTX)
39 #include "hard-reg-set.h"
41 #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
94 unsigned long dw_fde_offset;
96 char *dw_fde_current_label;
98 dw_cfi_ref dw_fde_cfi;
102 /* Maximum size (in bytes) of an artificially generated label. */
103 #define MAX_ARTIFICIAL_LABEL_BYTES 30
105 /* Make sure we know the sizes of the various types dwarf can describe. These
106 are only defaults. If the sizes are different for your target, you should
107 override these values by defining the appropriate symbols in your tm.h
110 #ifndef CHAR_TYPE_SIZE
111 #define CHAR_TYPE_SIZE BITS_PER_UNIT
114 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
117 /* The size in bytes of a DWARF field indicating an offset or length
118 relative to a debug info section, specified to be 4 bytes in the DWARF-2
119 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
121 #ifndef DWARF_OFFSET_SIZE
122 #define DWARF_OFFSET_SIZE 4
125 #define DWARF_VERSION 2
127 /* Round SIZE up to the nearest BOUNDARY. */
128 #define DWARF_ROUND(SIZE,BOUNDARY) \
129 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
131 /* Fixed size portion of the CIE (including the length field). */
132 #define DWARF_CIE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 5)
134 /* The un-padded size of the CIE. Initialized in calc_fde_sizes, used
135 in output_call_frame_info. */
136 static unsigned cie_size;
138 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
139 #ifdef STACK_GROWS_DOWNWARD
140 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
142 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
145 /* Fixed size portion of the FDE. */
146 #define DWARF_FDE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2 * PTR_SIZE)
148 /* This location is used by calc_fde_sizes() to keep track
149 the offset of each FDE within the .debug_frame section. */
150 static unsigned long next_fde_offset;
152 /* A pointer to the base of a table that contains frame description
153 information for each routine. */
154 static dw_fde_ref fde_table;
156 /* Number of elements currently allocated for fde_table. */
157 static unsigned fde_table_allocated;
159 /* Number of elements in fde_table currently in use. */
160 static unsigned fde_table_in_use;
162 /* Size (in elements) of increments by which we may expand the
164 #define FDE_TABLE_INCREMENT 256
166 /* A list of call frame insns for the CIE. */
167 static dw_cfi_ref cie_cfi_head;
169 /* The number of the current function definition for which debugging
170 information is being generated. These numbers range from 1 up to the
171 maximum number of function definitions contained within the current
172 compilation unit. These numbers are used to create unique label id's
173 unique to each function definition. */
174 static unsigned current_funcdef_number = 0;
176 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
177 attribute that accelerates the lookup of the FDE associated
178 with the subprogram. This variable holds the table index of the FDE
179 associated with the current function (body) definition. */
180 static unsigned current_funcdef_fde;
182 /* Forward declarations for functions defined in this file. */
184 static char *stripattributes PROTO((char *));
185 static char *dwarf_cfi_name PROTO((unsigned));
186 static dw_cfi_ref new_cfi PROTO((void));
187 static void add_cfi PROTO((dw_cfi_ref *, dw_cfi_ref));
188 static unsigned long size_of_uleb128 PROTO((unsigned long));
189 static unsigned long size_of_sleb128 PROTO((long));
190 static void output_uleb128 PROTO((unsigned long));
191 static void output_sleb128 PROTO((long));
192 static char *dwarf2out_cfi_label PROTO((void));
193 static void add_fde_cfi PROTO((char *, dw_cfi_ref));
194 static void lookup_cfa_1 PROTO((dw_cfi_ref, unsigned long *,
196 static void lookup_cfa PROTO((unsigned long *, long *));
197 static void reg_save PROTO((char *, unsigned, unsigned,
199 static void initial_return_save PROTO((rtx));
200 static unsigned long size_of_cfi PROTO((dw_cfi_ref));
201 static unsigned long size_of_fde PROTO((dw_fde_ref, unsigned long *));
202 static void calc_fde_sizes PROTO((void));
203 static void output_cfi PROTO((dw_cfi_ref, dw_fde_ref));
204 static void output_call_frame_info PROTO((int));
205 static unsigned reg_number PROTO((rtx));
207 /* Definitions of defaults for assembler-dependent names of various
208 pseudo-ops and section names.
209 Theses may be overridden in the tm.h file (if necessary) for a particular
212 #ifndef UNALIGNED_SHORT_ASM_OP
213 #define UNALIGNED_SHORT_ASM_OP ".2byte"
215 #ifndef UNALIGNED_INT_ASM_OP
216 #define UNALIGNED_INT_ASM_OP ".4byte"
218 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
219 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
222 #define ASM_BYTE_OP ".byte"
225 #ifndef UNALIGNED_OFFSET_ASM_OP
226 #define UNALIGNED_OFFSET_ASM_OP \
227 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
230 #ifndef UNALIGNED_WORD_ASM_OP
231 #define UNALIGNED_WORD_ASM_OP \
232 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
235 /* Data and reference forms for relocatable data. */
236 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
237 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
239 /* Pseudo-op for defining a new section. */
240 #ifndef SECTION_ASM_OP
241 #define SECTION_ASM_OP ".section"
244 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
245 print the SECTION_ASM_OP and the section name. The default here works for
246 almost all svr4 assemblers, except for the sparc, where the section name
247 must be enclosed in double quotes. (See sparcv4.h). */
248 #ifndef SECTION_FORMAT
249 #define SECTION_FORMAT "\t%s\t%s\n"
252 #ifndef FRAME_SECTION
253 #define FRAME_SECTION ".debug_frame"
255 #if !defined (EH_FRAME_SECTION) && defined (ASM_OUTPUT_SECTION_NAME)
256 #define EH_FRAME_SECTION ".eh_frame"
259 #ifndef FUNC_BEGIN_LABEL
260 #define FUNC_BEGIN_LABEL "LFB"
262 #ifndef FUNC_END_LABEL
263 #define FUNC_END_LABEL "LFE"
266 /* Definitions of defaults for various types of primitive assembly language
267 output operations. These may be overridden from within the tm.h file,
268 but typically, that is unecessary. */
270 #ifndef ASM_OUTPUT_SECTION
271 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
272 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
275 #ifndef ASM_OUTPUT_DWARF_DELTA2
276 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
277 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
278 assemble_name (FILE, LABEL1); \
279 fprintf (FILE, "-"); \
280 assemble_name (FILE, LABEL2); \
284 #ifndef ASM_OUTPUT_DWARF_DELTA4
285 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
286 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
287 assemble_name (FILE, LABEL1); \
288 fprintf (FILE, "-"); \
289 assemble_name (FILE, LABEL2); \
293 #ifndef ASM_OUTPUT_DWARF_DELTA
294 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
295 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
296 assemble_name (FILE, LABEL1); \
297 fprintf (FILE, "-"); \
298 assemble_name (FILE, LABEL2); \
302 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
303 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
304 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
305 assemble_name (FILE, LABEL1); \
306 fprintf (FILE, "-"); \
307 assemble_name (FILE, LABEL2); \
311 #ifndef ASM_OUTPUT_DWARF_ADDR
312 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
313 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
314 assemble_name (FILE, LABEL); \
318 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
319 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
320 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
323 #ifndef ASM_OUTPUT_DWARF_OFFSET
324 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
325 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
326 assemble_name (FILE, LABEL); \
330 #ifndef ASM_OUTPUT_DWARF_DATA1
331 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
332 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
335 #ifndef ASM_OUTPUT_DWARF_DATA2
336 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
337 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
340 #ifndef ASM_OUTPUT_DWARF_DATA4
341 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
342 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
345 #ifndef ASM_OUTPUT_DWARF_DATA
346 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
347 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
348 (unsigned long) VALUE)
351 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
352 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
353 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
354 (unsigned long) VALUE)
357 #ifndef ASM_OUTPUT_DWARF_DATA8
358 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
360 if (WORDS_BIG_ENDIAN) \
362 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
363 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
367 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
368 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
373 /* The DWARF 2 CFA column which tracks the return address. Normally this
374 is the column for PC, or the first column after all of the hard
376 #ifndef DWARF_FRAME_RETURN_COLUMN
378 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
380 #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER
384 /* The mapping from gcc register number to DWARF 2 CFA column number. By
385 default, we just provide columns for all registers. */
386 #ifndef DWARF_FRAME_REGNUM
387 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
390 /* Return a pointer to a copy of the section string name S with all
391 attributes stripped off. */
397 char *stripped = xstrdup (s);
400 while (*p && *p != ',')
407 /* Return the register number described by a given RTL node. */
413 register unsigned regno = REGNO (rtl);
415 if (regno >= FIRST_PSEUDO_REGISTER)
417 warning ("internal regno botch: regno = %d\n", regno);
421 regno = DBX_REGISTER_NUMBER (regno);
425 /* Convert a DWARF call frame info. operation to its string name */
428 dwarf_cfi_name (cfi_opc)
429 register unsigned cfi_opc;
433 case DW_CFA_advance_loc:
434 return "DW_CFA_advance_loc";
436 return "DW_CFA_offset";
438 return "DW_CFA_restore";
442 return "DW_CFA_set_loc";
443 case DW_CFA_advance_loc1:
444 return "DW_CFA_advance_loc1";
445 case DW_CFA_advance_loc2:
446 return "DW_CFA_advance_loc2";
447 case DW_CFA_advance_loc4:
448 return "DW_CFA_advance_loc4";
449 case DW_CFA_offset_extended:
450 return "DW_CFA_offset_extended";
451 case DW_CFA_restore_extended:
452 return "DW_CFA_restore_extended";
453 case DW_CFA_undefined:
454 return "DW_CFA_undefined";
455 case DW_CFA_same_value:
456 return "DW_CFA_same_value";
457 case DW_CFA_register:
458 return "DW_CFA_register";
459 case DW_CFA_remember_state:
460 return "DW_CFA_remember_state";
461 case DW_CFA_restore_state:
462 return "DW_CFA_restore_state";
464 return "DW_CFA_def_cfa";
465 case DW_CFA_def_cfa_register:
466 return "DW_CFA_def_cfa_register";
467 case DW_CFA_def_cfa_offset:
468 return "DW_CFA_def_cfa_offset";
469 /* SGI/MIPS specific */
470 case DW_CFA_MIPS_advance_loc8:
471 return "DW_CFA_MIPS_advance_loc8";
473 return "DW_CFA_<unknown>";
477 /* Return a pointer to a newly allocated Call Frame Instruction. */
479 static inline dw_cfi_ref
482 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
484 cfi->dw_cfi_next = NULL;
485 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
486 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
491 /* Add a Call Frame Instruction to list of instructions. */
494 add_cfi (list_head, cfi)
495 register dw_cfi_ref *list_head;
496 register dw_cfi_ref cfi;
498 register dw_cfi_ref *p;
500 /* Find the end of the chain. */
501 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
507 /* Generate a new label for the CFI info to refer to. */
510 dwarf2out_cfi_label ()
512 static char label[20];
513 static unsigned long label_num = 0;
515 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
516 ASM_OUTPUT_LABEL (asm_out_file, label);
521 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
522 or to the CIE if LABEL is NULL. */
525 add_fde_cfi (label, cfi)
526 register char *label;
527 register dw_cfi_ref cfi;
531 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
534 label = dwarf2out_cfi_label ();
536 if (fde->dw_fde_current_label == NULL
537 || strcmp (label, fde->dw_fde_current_label) != 0)
539 register dw_cfi_ref xcfi;
541 fde->dw_fde_current_label = label = xstrdup (label);
543 /* Set the location counter to the new label. */
545 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
546 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
547 add_cfi (&fde->dw_fde_cfi, xcfi);
550 add_cfi (&fde->dw_fde_cfi, cfi);
554 add_cfi (&cie_cfi_head, cfi);
557 /* Subroutine of lookup_cfa. */
560 lookup_cfa_1 (cfi, regp, offsetp)
561 register dw_cfi_ref cfi;
562 register unsigned long *regp;
563 register long *offsetp;
565 switch (cfi->dw_cfi_opc)
567 case DW_CFA_def_cfa_offset:
568 *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
570 case DW_CFA_def_cfa_register:
571 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
574 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
575 *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
580 /* Find the previous value for the CFA. */
583 lookup_cfa (regp, offsetp)
584 register unsigned long *regp;
585 register long *offsetp;
587 register dw_cfi_ref cfi;
589 *regp = (unsigned long) -1;
592 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
593 lookup_cfa_1 (cfi, regp, offsetp);
595 if (fde_table_in_use)
597 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
598 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
599 lookup_cfa_1 (cfi, regp, offsetp);
603 /* The current rule for calculating the DWARF2 canonical frame address. */
604 static unsigned cfa_reg;
605 static long cfa_offset;
607 /* The register used for saving registers to the stack, and its offset
609 static unsigned cfa_store_reg;
610 static long cfa_store_offset;
612 /* Entry point to update the canonical frame address (CFA).
613 LABEL is passed to add_fde_cfi. The value of CFA is now to be
614 calculated from REG+OFFSET. */
617 dwarf2out_def_cfa (label, reg, offset)
618 register char *label;
619 register unsigned reg;
620 register long offset;
622 register dw_cfi_ref cfi;
623 unsigned long old_reg;
628 if (cfa_store_reg == reg)
629 cfa_store_offset = offset;
631 reg = DWARF_FRAME_REGNUM (reg);
632 lookup_cfa (&old_reg, &old_offset);
634 if (reg == old_reg && offset == old_offset)
641 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
642 cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
645 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
646 else if (offset == old_offset && old_reg != (unsigned long) -1)
648 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
649 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
655 cfi->dw_cfi_opc = DW_CFA_def_cfa;
656 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
657 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
660 add_fde_cfi (label, cfi);
663 /* Add the CFI for saving a register. REG is the CFA column number.
664 LABEL is passed to add_fde_cfi.
665 If SREG is -1, the register is saved at OFFSET from the CFA;
666 otherwise it is saved in SREG. */
669 reg_save (label, reg, sreg, offset)
670 register char * label;
671 register unsigned reg;
672 register unsigned sreg;
673 register long offset;
675 register dw_cfi_ref cfi = new_cfi ();
677 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
682 /* The register number won't fit in 6 bits, so we have to use
684 cfi->dw_cfi_opc = DW_CFA_offset_extended;
686 cfi->dw_cfi_opc = DW_CFA_offset;
688 offset /= DWARF_CIE_DATA_ALIGNMENT;
689 assert (offset >= 0);
690 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
694 cfi->dw_cfi_opc = DW_CFA_register;
695 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
698 add_fde_cfi (label, cfi);
701 /* Entry point for saving a register. REG is the GCC register number.
702 LABEL and OFFSET are passed to reg_save. */
705 dwarf2out_reg_save (label, reg, offset)
706 register char * label;
707 register unsigned reg;
708 register long offset;
710 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
713 /* Record the initial position of the return address. RTL is
714 INCOMING_RETURN_ADDR_RTX. */
717 initial_return_save (rtl)
723 switch (GET_CODE (rtl))
726 /* RA is in a register. */
727 reg = reg_number (rtl);
730 /* RA is on the stack. */
732 switch (GET_CODE (rtl))
735 assert (REGNO (rtl) == STACK_POINTER_REGNUM);
739 assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
740 offset = INTVAL (XEXP (rtl, 1));
743 assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
744 offset = -INTVAL (XEXP (rtl, 1));
754 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset);
757 /* Record call frame debugging information for INSN, which either
758 sets SP or FP (adjusting how we calculate the frame address) or saves a
759 register to the stack. If INSN is NULL_RTX, initialize our state. */
762 dwarf2out_frame_debug (insn)
769 /* A temporary register used in adjusting SP or setting up the store_reg. */
770 static unsigned cfa_temp_reg;
771 static long cfa_temp_value;
773 if (insn == NULL_RTX)
775 /* Set up state for generating call frame debug info. */
776 cfa_reg = STACK_POINTER_REGNUM;
778 cfa_store_reg = STACK_POINTER_REGNUM;
779 cfa_store_offset = 0;
785 label = dwarf2out_cfi_label ();
787 insn = PATTERN (insn);
788 assert (GET_CODE (insn) == SET);
790 src = SET_SRC (insn);
791 dest = SET_DEST (insn);
793 switch (GET_CODE (dest))
796 /* Update the CFA rule wrt SP or FP. Make sure src is
797 relative to the current CFA register. */
798 switch (GET_CODE (src))
800 /* Setting FP from SP. */
802 assert (cfa_reg == REGNO (src));
803 assert (REGNO (dest) == STACK_POINTER_REGNUM
804 || (frame_pointer_needed
805 && REGNO (dest) == HARD_FRAME_POINTER_REGNUM));
806 cfa_reg = REGNO (dest);
811 if (dest == stack_pointer_rtx)
814 switch (GET_CODE (XEXP (src, 1)))
817 offset = INTVAL (XEXP (src, 1));
820 assert (REGNO (XEXP (src, 1)) == cfa_temp_reg);
821 offset = cfa_temp_value;
827 if (GET_CODE (src) == PLUS)
829 if (cfa_reg == STACK_POINTER_REGNUM)
830 cfa_offset += offset;
831 if (cfa_store_reg == STACK_POINTER_REGNUM)
832 cfa_store_offset += offset;
833 assert (XEXP (src, 0) == stack_pointer_rtx);
837 /* Initializing the store base register. */
838 assert (GET_CODE (src) == PLUS);
839 assert (XEXP (src, 1) == stack_pointer_rtx);
840 assert (GET_CODE (XEXP (src, 0)) == REG
841 && REGNO (XEXP (src, 0)) == cfa_temp_reg);
842 assert (cfa_store_reg == STACK_POINTER_REGNUM);
843 cfa_store_reg = REGNO (dest);
844 cfa_store_offset -= cfa_temp_value;
849 cfa_temp_reg = REGNO (dest);
850 cfa_temp_value = INTVAL (src);
856 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
860 /* Saving a register to the stack. Make sure dest is relative to the
862 assert (GET_CODE (src) == REG);
863 switch (GET_CODE (XEXP (dest, 0)))
868 offset = GET_MODE_SIZE (GET_MODE (dest));
869 if (GET_CODE (src) == PRE_INC)
872 assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM);
873 assert (cfa_store_reg == STACK_POINTER_REGNUM);
874 cfa_store_offset += offset;
875 if (cfa_reg == STACK_POINTER_REGNUM)
876 cfa_offset = cfa_store_offset;
878 offset = -cfa_store_offset;
881 /* With an offset. */
884 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
885 if (GET_CODE (src) == MINUS)
888 assert (cfa_store_reg == REGNO (XEXP (XEXP (dest, 0), 0)));
889 offset -= cfa_store_offset;
895 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
896 dwarf2out_reg_save (label, REGNO (src), offset);
904 /* Return the size of an unsigned LEB128 quantity. */
906 static inline unsigned long
907 size_of_uleb128 (value)
908 register unsigned long value;
910 register unsigned long size = 0;
911 register unsigned byte;
915 byte = (value & 0x7f);
924 /* Return the size of a signed LEB128 quantity. */
926 static inline unsigned long
927 size_of_sleb128 (value)
930 register unsigned long size = 0;
931 register unsigned byte;
935 byte = (value & 0x7f);
939 while (!(((value == 0) && ((byte & 0x40) == 0))
940 || ((value == -1) && ((byte & 0x40) != 0))));
945 /* Return the size of a Call Frame Instruction. */
951 register unsigned long size;
953 /* Count the 1-byte opcode */
955 switch (cfi->dw_cfi_opc)
958 size += size_of_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
963 case DW_CFA_advance_loc1:
966 case DW_CFA_advance_loc2:
969 case DW_CFA_advance_loc4:
972 #ifdef MIPS_DEBUGGING_INFO
973 case DW_CFA_MIPS_advance_loc8:
977 case DW_CFA_offset_extended:
979 size += size_of_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
980 size += size_of_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
982 case DW_CFA_restore_extended:
983 case DW_CFA_undefined:
984 size += size_of_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
986 case DW_CFA_same_value:
987 case DW_CFA_def_cfa_register:
988 size += size_of_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
990 case DW_CFA_register:
991 size += size_of_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
992 size += size_of_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
994 case DW_CFA_def_cfa_offset:
995 size += size_of_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1004 /* Return the size of an FDE sans the length word. */
1006 static inline unsigned long
1007 size_of_fde (fde, npad)
1009 unsigned long *npad;
1011 register dw_cfi_ref cfi;
1012 register unsigned long aligned_size;
1013 register unsigned long size;
1015 size = DWARF_FDE_HEADER_SIZE;
1016 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1017 size += size_of_cfi(cfi);
1019 /* Round the size up to a word boundary. */
1020 aligned_size = DWARF_ROUND (size, PTR_SIZE);
1021 *npad = aligned_size - size;
1022 return aligned_size;
1025 /* Calculate the size of the FDE table, and establish the offset
1026 of each FDE in the .debug_frame section. */
1031 register unsigned long i;
1032 register dw_fde_ref fde;
1033 register unsigned long fde_size;
1034 register dw_cfi_ref cfi;
1035 unsigned long fde_pad;
1037 cie_size = DWARF_CIE_HEADER_SIZE;
1038 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1039 cie_size += size_of_cfi (cfi);
1041 /* Initialize the beginning FDE offset. */
1042 next_fde_offset = DWARF_ROUND (cie_size, PTR_SIZE);
1044 for (i = 0; i < fde_table_in_use; ++i)
1046 fde = &fde_table[i];
1047 fde->dw_fde_offset = next_fde_offset;
1048 fde_size = size_of_fde (fde, &fde_pad);
1049 next_fde_offset += fde_size;
1053 /* Output an unsigned LEB128 quantity. */
1056 output_uleb128 (value)
1057 register unsigned long value;
1059 unsigned long save_value = value;
1061 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1064 register unsigned byte = (value & 0x7f);
1067 /* More bytes to follow. */
1070 fprintf (asm_out_file, "0x%x", byte);
1072 fprintf (asm_out_file, ",");
1076 if (flag_verbose_asm)
1077 fprintf (asm_out_file, "\t%s ULEB128 0x%x", ASM_COMMENT_START, save_value);
1080 /* Output an signed LEB128 quantity. */
1083 output_sleb128 (value)
1084 register long value;
1087 register unsigned byte;
1088 long save_value = value;
1090 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1093 byte = (value & 0x7f);
1094 /* arithmetic shift */
1096 more = !((((value == 0) && ((byte & 0x40) == 0))
1097 || ((value == -1) && ((byte & 0x40) != 0))));
1101 fprintf (asm_out_file, "0x%x", byte);
1103 fprintf (asm_out_file, ",");
1107 if (flag_verbose_asm)
1108 fprintf (asm_out_file, "\t%s SLEB128 %d", ASM_COMMENT_START, save_value);
1111 /* Output a Call Frame Information opcode and its operand(s). */
1114 output_cfi (cfi, fde)
1115 register dw_cfi_ref cfi;
1116 register dw_fde_ref fde;
1118 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1120 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1122 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1123 if (flag_verbose_asm)
1124 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%x",
1125 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1126 fputc ('\n', asm_out_file);
1129 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1131 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1133 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1134 if (flag_verbose_asm)
1135 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%x",
1136 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1138 fputc ('\n', asm_out_file);
1139 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1140 fputc ('\n', asm_out_file);
1142 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1144 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1146 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1147 if (flag_verbose_asm)
1148 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%x",
1149 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1151 fputc ('\n', asm_out_file);
1155 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1156 if (flag_verbose_asm)
1157 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1158 dwarf_cfi_name (cfi->dw_cfi_opc));
1160 fputc ('\n', asm_out_file);
1161 switch (cfi->dw_cfi_opc)
1163 case DW_CFA_set_loc:
1164 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1165 fputc ('\n', asm_out_file);
1167 case DW_CFA_advance_loc1:
1168 /* TODO: not currently implemented. */
1171 case DW_CFA_advance_loc2:
1172 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1173 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1174 fde->dw_fde_current_label);
1175 fputc ('\n', asm_out_file);
1176 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1178 case DW_CFA_advance_loc4:
1179 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1180 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1181 fde->dw_fde_current_label);
1182 fputc ('\n', asm_out_file);
1183 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1185 #ifdef MIPS_DEBUGGING_INFO
1186 case DW_CFA_MIPS_advance_loc8:
1187 /* TODO: not currently implemented. */
1191 case DW_CFA_offset_extended:
1192 case DW_CFA_def_cfa:
1193 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1194 fputc ('\n', asm_out_file);
1195 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1196 fputc ('\n', asm_out_file);
1198 case DW_CFA_restore_extended:
1199 case DW_CFA_undefined:
1200 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1201 fputc ('\n', asm_out_file);
1203 case DW_CFA_same_value:
1204 case DW_CFA_def_cfa_register:
1205 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1206 fputc ('\n', asm_out_file);
1208 case DW_CFA_register:
1209 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1210 fputc ('\n', asm_out_file);
1211 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1212 fputc ('\n', asm_out_file);
1214 case DW_CFA_def_cfa_offset:
1215 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1216 fputc ('\n', asm_out_file);
1224 /* Output the call frame information used to used to record information
1225 that relates to calculating the frame pointer, and records the
1226 location of saved registers. */
1229 output_call_frame_info (for_eh)
1232 register unsigned long i, j;
1233 register dw_fde_ref fde;
1234 register unsigned long fde_size;
1235 register dw_cfi_ref cfi;
1236 unsigned long fde_pad;
1238 /* Only output the info if it will be interesting. */
1239 for (i = 0; i < fde_table_in_use; ++i)
1240 if (fde_table[i].dw_fde_cfi != NULL)
1242 if (i == fde_table_in_use)
1245 /* (re-)initialize the beginning FDE offset. */
1246 next_fde_offset = DWARF_ROUND (cie_size, PTR_SIZE);
1248 fputc ('\n', asm_out_file);
1251 #ifdef EH_FRAME_SECTION
1252 ASM_OUTPUT_SECTION_NAME (asm_out_file, NULL_TREE, EH_FRAME_SECTION, 0);
1256 assemble_label ("__FRAME_BEGIN__");
1259 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1261 /* Output the CIE. */
1262 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_fde_offset - DWARF_OFFSET_SIZE);
1263 if (flag_verbose_asm)
1264 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1267 fputc ('\n', asm_out_file);
1268 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1269 if (flag_verbose_asm)
1270 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1272 fputc ('\n', asm_out_file);
1273 if (DWARF_OFFSET_SIZE == 8)
1275 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1276 fputc ('\n', asm_out_file);
1279 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1280 if (flag_verbose_asm)
1281 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1283 fputc ('\n', asm_out_file);
1284 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1285 if (flag_verbose_asm)
1286 fprintf (asm_out_file, "\t%s CIE Augmentation (none)", ASM_COMMENT_START);
1288 fputc ('\n', asm_out_file);
1290 if (flag_verbose_asm)
1291 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1293 fputc ('\n', asm_out_file);
1294 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1295 if (flag_verbose_asm)
1296 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1298 fputc ('\n', asm_out_file);
1299 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1300 if (flag_verbose_asm)
1301 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1303 fputc ('\n', asm_out_file);
1305 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1306 output_cfi (cfi, NULL);
1308 /* Pad the CIE out to an address sized boundary. */
1309 for (i = next_fde_offset - cie_size; i; --i)
1311 /* Pad out to a pointer size boundary */
1312 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
1313 if (flag_verbose_asm)
1314 fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)", ASM_COMMENT_START);
1316 fputc ('\n', asm_out_file);
1319 /* Loop through all of the FDE's. */
1320 for (i = 0; i < fde_table_in_use; ++i)
1322 fde = &fde_table[i];
1323 if (fde->dw_fde_cfi == NULL)
1326 fde_size = size_of_fde (fde, &fde_pad);
1327 ASM_OUTPUT_DWARF_DATA (asm_out_file, fde_size - DWARF_OFFSET_SIZE);
1328 if (flag_verbose_asm)
1329 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1331 fputc ('\n', asm_out_file);
1333 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__FRAME_BEGIN__");
1335 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1336 if (flag_verbose_asm)
1337 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1339 fputc ('\n', asm_out_file);
1340 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1341 if (flag_verbose_asm)
1342 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1344 fputc ('\n', asm_out_file);
1345 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1346 fde->dw_fde_end, fde->dw_fde_begin);
1347 if (flag_verbose_asm)
1348 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1350 fputc ('\n', asm_out_file);
1352 /* Loop through the Call Frame Instructions associated with
1354 fde->dw_fde_current_label = fde->dw_fde_begin;
1355 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1356 output_cfi (cfi, fde);
1358 /* Pad to a double word boundary. */
1359 for (j = 0; j < fde_pad; ++j)
1361 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
1362 if (flag_verbose_asm)
1363 fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)",
1366 fputc ('\n', asm_out_file);
1369 #ifndef EH_FRAME_SECTION
1372 /* Emit terminating zero for table. */
1373 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
1374 fputc ('\n', asm_out_file);
1379 /* Output a marker (i.e. a label) for the beginning of a function, before
1383 dwarf2out_begin_prologue ()
1385 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1386 register dw_fde_ref fde;
1388 ++current_funcdef_number;
1390 function_section (current_function_decl);
1391 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1392 current_funcdef_number);
1393 ASM_OUTPUT_LABEL (asm_out_file, label);
1395 /* Expand the fde table if necessary. */
1396 if (fde_table_in_use == fde_table_allocated)
1398 fde_table_allocated += FDE_TABLE_INCREMENT;
1400 = (dw_fde_ref) xrealloc (fde_table,
1401 fde_table_allocated * sizeof (dw_fde_node));
1404 /* Record the FDE associated with this function. */
1405 current_funcdef_fde = fde_table_in_use;
1407 /* Add the new FDE at the end of the fde_table. */
1408 fde = &fde_table[fde_table_in_use++];
1409 fde->dw_fde_begin = xstrdup (label);
1410 fde->dw_fde_current_label = NULL;
1411 fde->dw_fde_end = NULL;
1412 fde->dw_fde_cfi = NULL;
1415 /* Output a marker (i.e. a label) for the absolute end of the generated code
1416 for a function definition. This gets called *after* the epilogue code has
1420 dwarf2out_end_epilogue ()
1423 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1425 /* Output a label to mark the endpoint of the code generated for this
1427 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1428 ASM_OUTPUT_LABEL (asm_out_file, label);
1429 fde = &fde_table[fde_table_in_use - 1];
1430 fde->dw_fde_end = xstrdup (label);
1434 dwarf2out_frame_init ()
1436 /* Allocate the initial hunk of the fde_table. */
1438 = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1439 bzero ((char *) fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1440 fde_table_allocated = FDE_TABLE_INCREMENT;
1441 fde_table_in_use = 0;
1443 /* Generate the CFA instructions common to all FDE's. Do it now for the
1444 sake of lookup_cfa. */
1446 #ifdef INCOMING_RETURN_ADDR_RTX
1447 /* On entry, the Canonical Frame Address is at SP+0. */
1448 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, 0);
1449 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1454 dwarf2out_frame_finish ()
1456 /* calculate sizes/offsets for FDEs. */
1459 /* Output call frame information. */
1460 if (write_symbols == DWARF2_DEBUG)
1461 output_call_frame_info (0);
1462 if (flag_exceptions && ! exceptions_via_longjmp)
1463 output_call_frame_info (1);
1466 #endif /* .debug_frame support */
1468 /* And now, the support for symbolic debugging information. */
1469 #ifdef DWARF2_DEBUGGING_INFO
1471 extern char *getpwd ();
1473 /* NOTE: In the comments in this file, many references are made to
1474 "Debugging Information Entries". This term is abbreviated as `DIE'
1475 throughout the remainder of this file. */
1477 /* An internal representation of the DWARF output is built, and then
1478 walked to generate the DWARF debugging info. The walk of the internal
1479 representation is done after the entire program has been compiled.
1480 The types below are used to describe the internal representation. */
1482 /* Each DIE may have a series of attribute/value pairs. Values
1483 can take on several forms. The forms that are used in this
1484 implementation are listed below. */
1491 dw_val_class_unsigned_const,
1492 dw_val_class_long_long,
1495 dw_val_class_die_ref,
1496 dw_val_class_fde_ref,
1497 dw_val_class_lbl_id,
1498 dw_val_class_section_offset,
1503 /* Various DIE's use offsets relative to the beginning of the
1504 .debug_info section to refer to each other. */
1506 typedef long int dw_offset;
1508 /* Define typedefs here to avoid circular dependencies. */
1510 typedef struct die_struct *dw_die_ref;
1511 typedef struct dw_attr_struct *dw_attr_ref;
1512 typedef struct dw_val_struct *dw_val_ref;
1513 typedef struct dw_line_info_struct *dw_line_info_ref;
1514 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
1515 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1516 typedef struct pubname_struct *pubname_ref;
1517 typedef dw_die_ref *arange_ref;
1519 /* Describe a double word constant value. */
1521 typedef struct dw_long_long_struct
1528 /* Describe a floating point constant value. */
1530 typedef struct dw_fp_struct
1537 /* Each entry in the line_info_table maintains the file and
1538 line nuber associated with the label generated for that
1539 entry. The label gives the PC value associated with
1540 the line number entry. */
1542 typedef struct dw_line_info_struct
1544 unsigned long dw_file_num;
1545 unsigned long dw_line_num;
1549 /* Line information for functions in separate sections; each one gets its
1551 typedef struct dw_separate_line_info_struct
1553 unsigned long dw_file_num;
1554 unsigned long dw_line_num;
1555 unsigned long function;
1557 dw_separate_line_info_entry;
1559 /* The dw_val_node describes an attibute's value, as it is
1560 represented internally. */
1562 typedef struct dw_val_struct
1564 dw_val_class val_class;
1568 dw_loc_descr_ref val_loc;
1570 long unsigned val_unsigned;
1571 dw_long_long_const val_long_long;
1572 dw_float_const val_float;
1573 dw_die_ref val_die_ref;
1574 unsigned val_fde_index;
1578 unsigned char val_flag;
1584 /* Locations in memory are described using a sequence of stack machine
1587 typedef struct dw_loc_descr_struct
1589 dw_loc_descr_ref dw_loc_next;
1590 enum dwarf_location_atom dw_loc_opc;
1591 dw_val_node dw_loc_oprnd1;
1592 dw_val_node dw_loc_oprnd2;
1596 /* Each DIE attribute has a field specifying the attribute kind,
1597 a link to the next attribute in the chain, and an attribute value.
1598 Attributes are typically linked below the DIE they modify. */
1600 typedef struct dw_attr_struct
1602 enum dwarf_attribute dw_attr;
1603 dw_attr_ref dw_attr_next;
1604 dw_val_node dw_attr_val;
1608 /* The Debugging Information Entry (DIE) structure */
1610 typedef struct die_struct
1612 enum dwarf_tag die_tag;
1613 dw_attr_ref die_attr;
1614 dw_attr_ref die_attr_last;
1615 dw_die_ref die_parent;
1616 dw_die_ref die_child;
1617 dw_die_ref die_child_last;
1619 dw_offset die_offset;
1620 unsigned long die_abbrev;
1624 /* The pubname structure */
1626 typedef struct pubname_struct
1633 /* How to start an assembler comment. */
1634 #ifndef ASM_COMMENT_START
1635 #define ASM_COMMENT_START ";#"
1638 /* Define a macro which returns non-zero for a TYPE_DECL which was
1639 implicitly generated for a tagged type.
1641 Note that unlike the gcc front end (which generates a NULL named
1642 TYPE_DECL node for each complete tagged type, each array type, and
1643 each function type node created) the g++ front end generates a
1644 _named_ TYPE_DECL node for each tagged type node created.
1645 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
1646 generate a DW_TAG_typedef DIE for them. */
1648 #define TYPE_DECL_IS_STUB(decl) \
1649 (DECL_NAME (decl) == NULL_TREE \
1650 || (DECL_ARTIFICIAL (decl) \
1651 && is_tagged_type (TREE_TYPE (decl)) \
1652 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
1654 /* Information concerning the compilation unit's programming
1655 language, and compiler version. */
1657 extern int flag_traditional;
1658 extern char *version_string;
1659 extern char *language_string;
1661 /* Fixed size portion of the DWARF compilation unit header. */
1662 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
1664 /* Fixed size portion of debugging line information prolog. */
1665 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
1667 /* Fixed size portion of public names info. */
1668 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
1670 /* Fixed size portion of the address range info. */
1671 #define DWARF_ARANGES_HEADER_SIZE \
1672 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
1674 /* Define the architecture-dependent minimum instruction length (in bytes).
1675 In this implementation of DWARF, this field is used for information
1676 purposes only. Since GCC generates assembly language, we have
1677 no a priori knowledge of how many instruction bytes are generated
1678 for each source line, and therefore can use only the DW_LNE_set_address
1679 and DW_LNS_fixed_advance_pc line information commands. */
1681 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
1682 #define DWARF_LINE_MIN_INSTR_LENGTH 4
1685 /* Minimum line offset in a special line info. opcode.
1686 This value was chosen to give a reasonable range of values. */
1687 #define DWARF_LINE_BASE -10
1689 /* First special line opcde - leave room for the standard opcodes. */
1690 #define DWARF_LINE_OPCODE_BASE 10
1692 /* Range of line offsets in a special line info. opcode. */
1693 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
1695 /* Flag that indicates the initial value of the is_stmt_start flag.
1696 In the present implementation, we do not mark any lines as
1697 the beginning of a source statement, because that information
1698 is not made available by the GCC front-end. */
1699 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
1701 /* This location is used by calc_die_sizes() to keep track
1702 the offset of each DIE within the .debug_info section. */
1703 static unsigned long next_die_offset;
1705 /* Record the root of the DIE's built for the current compilation unit. */
1706 static dw_die_ref comp_unit_die;
1708 /* The number of DIEs with a NULL parent waiting to be relocated. */
1709 static int limbo_die_count;
1711 /* Pointer to an array of filenames referenced by this compilation unit. */
1712 static char **file_table;
1714 /* Total number of entries in the table (i.e. array) pointed to by
1715 `file_table'. This is the *total* and includes both used and unused
1717 static unsigned file_table_allocated;
1719 /* Number of entries in the file_table which are actually in use. */
1720 static unsigned file_table_in_use;
1722 /* Size (in elements) of increments by which we may expand the filename
1724 #define FILE_TABLE_INCREMENT 64
1726 /* Local pointer to the name of the main input file. Initialized in
1728 static char *primary_filename;
1730 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
1731 which their beginnings are encountered. We output Dwarf debugging info
1732 that refers to the beginnings and ends of the ranges of code for each
1733 lexical block. The labels themselves are generated in final.c, which
1734 assigns numbers to the blocks in the same way. */
1735 static unsigned next_block_number = 2;
1737 /* A pointer to the base of a table of references to DIE's that describe
1738 declarations. The table is indexed by DECL_UID() which is a unique
1739 number, indentifying each decl. */
1740 static dw_die_ref *decl_die_table;
1742 /* Number of elements currently allocated for the decl_die_table. */
1743 static unsigned decl_die_table_allocated;
1745 /* Number of elements in decl_die_table currently in use. */
1746 static unsigned decl_die_table_in_use;
1748 /* Size (in elements) of increments by which we may expand the
1750 #define DECL_DIE_TABLE_INCREMENT 256
1752 /* A pointer to the base of a table of references to declaration
1753 scopes. This table is a display which tracks the nesting
1754 of declaration scopes at the current scope and containing
1755 scopes. This table is used to find the proper place to
1756 define type declaration DIE's. */
1757 static tree *decl_scope_table;
1759 /* Number of elements currently allocated for the decl_scope_table. */
1760 static unsigned decl_scope_table_allocated;
1762 /* Current level of nesting of declataion scopes. */
1763 static unsigned decl_scope_depth;
1765 /* Size (in elements) of increments by which we may expand the
1766 decl_scope_table. */
1767 #define DECL_SCOPE_TABLE_INCREMENT 64
1769 /* A pointer to the base of a list of references to DIE's that
1770 are uniquely identified by their tag, presence/absence of
1771 children DIE's, and list of attribute/value pairs. */
1772 static dw_die_ref *abbrev_die_table;
1774 /* Number of elements currently allocated for abbrev_die_table. */
1775 static unsigned abbrev_die_table_allocated;
1777 /* Number of elements in type_die_table currently in use. */
1778 static unsigned abbrev_die_table_in_use;
1780 /* Size (in elements) of increments by which we may expand the
1781 abbrev_die_table. */
1782 #define ABBREV_DIE_TABLE_INCREMENT 256
1784 /* A pointer to the base of a table that contains line information
1785 for each source code line in .text in the compilation unit. */
1786 static dw_line_info_ref line_info_table;
1788 /* Number of elements currently allocated for line_info_table. */
1789 static unsigned line_info_table_allocated;
1791 /* Number of elements in separate_line_info_table currently in use. */
1792 static unsigned separate_line_info_table_in_use;
1794 /* A pointer to the base of a table that contains line information
1795 for each source code line outside of .text in the compilation unit. */
1796 static dw_separate_line_info_ref separate_line_info_table;
1798 /* Number of elements currently allocated for separate_line_info_table. */
1799 static unsigned separate_line_info_table_allocated;
1801 /* Number of elements in line_info_table currently in use. */
1802 static unsigned line_info_table_in_use;
1804 /* Size (in elements) of increments by which we may expand the
1806 #define LINE_INFO_TABLE_INCREMENT 1024
1808 /* A pointer to the base of a table that contains a list of publicly
1809 accessible names. */
1810 static pubname_ref pubname_table;
1812 /* Number of elements currently allocated for pubname_table. */
1813 static unsigned pubname_table_allocated;
1815 /* Number of elements in pubname_table currently in use. */
1816 static unsigned pubname_table_in_use;
1818 /* Size (in elements) of increments by which we may expand the
1820 #define PUBNAME_TABLE_INCREMENT 64
1822 /* A pointer to the base of a table that contains a list of publicly
1823 accessible names. */
1824 static arange_ref arange_table;
1826 /* Number of elements currently allocated for arange_table. */
1827 static unsigned arange_table_allocated;
1829 /* Number of elements in arange_table currently in use. */
1830 static unsigned arange_table_in_use;
1832 /* Size (in elements) of increments by which we may expand the
1834 #define ARANGE_TABLE_INCREMENT 64
1836 /* A pointer to the base of a list of pending types which we haven't
1837 generated DIEs for yet, but which we will have to come back to
1840 static tree *pending_types_list;
1842 /* Number of elements currently allocated for the pending_types_list. */
1843 static unsigned pending_types_allocated;
1845 /* Number of elements of pending_types_list currently in use. */
1846 static unsigned pending_types;
1848 /* Size (in elements) of increments by which we may expand the pending
1849 types list. Actually, a single hunk of space of this size should
1850 be enough for most typical programs. */
1851 #define PENDING_TYPES_INCREMENT 64
1853 /* Record whether the function being analyzed contains inlined functions. */
1854 static int current_function_has_inlines;
1855 static int comp_unit_has_inlines;
1857 /* A pointer to the ..._DECL node which we have most recently been working
1858 on. We keep this around just in case something about it looks screwy and
1859 we want to tell the user what the source coordinates for the actual
1861 static tree dwarf_last_decl;
1863 /* Forward declarations for functions defined in this file. */
1865 static void addr_const_to_string PROTO((char *, rtx));
1866 static char *addr_to_string PROTO((rtx));
1867 static int is_pseudo_reg PROTO((rtx));
1868 static tree type_main_variant PROTO((tree));
1869 static int is_tagged_type PROTO((tree));
1870 static char *dwarf_tag_name PROTO((unsigned));
1871 static char *dwarf_attr_name PROTO((unsigned));
1872 static char *dwarf_form_name PROTO((unsigned));
1873 static char *dwarf_stack_op_name PROTO((unsigned));
1874 static char *dwarf_type_encoding_name PROTO((unsigned));
1875 static tree decl_ultimate_origin PROTO((tree));
1876 static tree block_ultimate_origin PROTO((tree));
1877 static tree decl_class_context PROTO((tree));
1878 static void add_dwarf_attr PROTO((dw_die_ref, dw_attr_ref));
1879 static void add_AT_flag PROTO((dw_die_ref,
1880 enum dwarf_attribute,
1882 static void add_AT_int PROTO((dw_die_ref,
1883 enum dwarf_attribute, long));
1884 static void add_AT_unsigned PROTO((dw_die_ref,
1885 enum dwarf_attribute,
1887 static void add_AT_long_long PROTO((dw_die_ref,
1888 enum dwarf_attribute,
1889 unsigned long, unsigned long));
1890 static void add_AT_float PROTO((dw_die_ref,
1891 enum dwarf_attribute,
1893 static void add_AT_string PROTO((dw_die_ref,
1894 enum dwarf_attribute, char *));
1895 static void add_AT_die_ref PROTO((dw_die_ref,
1896 enum dwarf_attribute,
1898 static void add_AT_fde_ref PROTO((dw_die_ref,
1899 enum dwarf_attribute,
1901 static void add_AT_loc PROTO((dw_die_ref,
1902 enum dwarf_attribute,
1904 static void add_AT_addr PROTO((dw_die_ref,
1905 enum dwarf_attribute, char *));
1906 static void add_AT_lbl_id PROTO((dw_die_ref,
1907 enum dwarf_attribute, char *));
1908 static void add_AT_setion_offset PROTO((dw_die_ref,
1909 enum dwarf_attribute, char *));
1910 static int is_extern_subr_die PROTO((dw_die_ref));
1911 static dw_attr_ref get_AT PROTO((dw_die_ref,
1912 enum dwarf_attribute));
1913 static char *get_AT_low_pc PROTO((dw_die_ref));
1914 static char *get_AT_hi_pc PROTO((dw_die_ref));
1915 static char *get_AT_string PROTO((dw_die_ref,
1916 enum dwarf_attribute));
1917 static int get_AT_flag PROTO((dw_die_ref,
1918 enum dwarf_attribute));
1919 static unsigned get_AT_unsigned PROTO((dw_die_ref,
1920 enum dwarf_attribute));
1921 static int is_c_family PROTO((void));
1922 static int is_fortran PROTO((void));
1923 static void remove_AT PROTO((dw_die_ref,
1924 enum dwarf_attribute));
1925 static void remove_children PROTO((dw_die_ref));
1926 static void add_child_die PROTO((dw_die_ref, dw_die_ref));
1927 static dw_die_ref new_die PROTO((enum dwarf_tag, dw_die_ref));
1928 static dw_die_ref lookup_type_die PROTO((tree));
1929 static void equate_type_number_to_die PROTO((tree, dw_die_ref));
1930 static dw_die_ref lookup_decl_die PROTO((tree));
1931 static void equate_decl_number_to_die PROTO((tree, dw_die_ref));
1932 static dw_loc_descr_ref new_loc_descr PROTO((enum dwarf_location_atom,
1933 unsigned long, unsigned long));
1934 static void add_loc_descr PROTO((dw_loc_descr_ref *,
1936 static void print_spaces PROTO((FILE *));
1937 static void print_die PROTO((dw_die_ref, FILE *));
1938 static void print_dwarf_line_table PROTO((FILE *));
1939 static void add_sibling_atttributes PROTO((dw_die_ref));
1940 static void build_abbrev_table PROTO((dw_die_ref));
1941 static unsigned long size_of_string PROTO((char *));
1942 static unsigned long size_of_loc_descr PROTO((dw_loc_descr_ref));
1943 static unsigned long size_of_locs PROTO((dw_loc_descr_ref));
1944 static int constant_size PROTO((long unsigned));
1945 static unsigned long size_of_die PROTO((dw_die_ref));
1946 static void calc_die_sizes PROTO((dw_die_ref));
1947 static unsigned long size_of_prolog PROTO((void));
1948 static unsigned long size_of_line_info PROTO((void));
1949 static unsigned long size_of_pubnames PROTO((void));
1950 static unsigned long size_of_aranges PROTO((void));
1951 static enum dwarf_form value_format PROTO((dw_val_ref));
1952 static void output_value_format PROTO((dw_val_ref));
1953 static void output_abbrev_section PROTO((void));
1954 static void output_loc_operands PROTO((dw_loc_descr_ref));
1955 static unsigned long sibling_offset PROTO((dw_die_ref));
1956 static void output_die PROTO((dw_die_ref));
1957 static void output_compilation_unit_header PROTO((void));
1958 static char *dwarf2_name PROTO((tree, int));
1959 static void add_pubname PROTO((tree, dw_die_ref));
1960 static void output_pubnames PROTO((void));
1961 static void add_arrange PROTO((tree, dw_die_ref));
1962 static void output_arranges PROTO((void));
1963 static void output_line_info PROTO((void));
1964 static int is_body_block PROTO((tree));
1965 static dw_die_ref base_type_die PROTO((tree));
1966 static tree root_type PROTO((tree));
1967 static int is_base_type PROTO((tree));
1968 static dw_die_ref modified_type_die PROTO((tree, int, int, dw_die_ref));
1969 static int type_is_enum PROTO((tree));
1970 static dw_loc_descr_ref reg_loc_descr_ref PROTO((rtx));
1971 static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long));
1972 static int is_based_loc PROTO((rtx));
1973 static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx));
1974 static dw_loc_descr_ref loc_descriptor PROTO((rtx));
1975 static unsigned ceiling PROTO((unsigned, unsigned));
1976 static tree field_type PROTO((tree));
1977 static unsigned simple_type_align_in_bits PROTO((tree));
1978 static unsigned simple_type_size_in_bits PROTO((tree));
1979 static unsigned field_byte_offset PROTO((tree));
1980 static void add_location_attribute PROTO((dw_die_ref, rtx));
1981 static void add_data_member_location_attribute PROTO((dw_die_ref, tree));
1982 static void add_const_value_attribute PROTO((dw_die_ref, rtx));
1983 static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree));
1984 static void add_name_attribute PROTO((dw_die_ref, char *));
1985 static void add_bound_info PROTO((dw_die_ref,
1986 enum dwarf_attribute, tree));
1987 static void add_subscript_info PROTO((dw_die_ref, tree));
1988 static void add_byte_size_attribute PROTO((dw_die_ref, tree));
1989 static void add_bit_offset_attribute PROTO((dw_die_ref, tree));
1990 static void add_bit_size_attribute PROTO((dw_die_ref, tree));
1991 static void add_prototyped_attribute PROTO((dw_die_ref, tree));
1992 static void add_abstract_origin_attribute PROTO((dw_die_ref, tree));
1993 static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree));
1994 static void add_src_coords_attributes PROTO((dw_die_ref, tree));
1995 static void ad_name_and_src_coords_attributes PROTO((dw_die_ref, tree));
1996 static void push_decl_scope PROTO((tree));
1997 static dw_die_ref scope_die_for PROTO((tree, dw_die_ref));
1998 static void pop_decl_scope PROTO((void));
1999 static void add_type_attribute PROTO((dw_die_ref, tree, int, int,
2001 static char *type_tag PROTO((tree));
2002 static tree member_declared_type PROTO((tree));
2003 static char *decl_start_label PROTO((tree));
2004 static void gen_arrqay_type_die PROTO((tree, dw_die_ref));
2005 static void gen_set_type_die PROTO((tree, dw_die_ref));
2006 static void gen_entry_point_die PROTO((tree, dw_die_ref));
2007 static void pend_type PROTO((tree));
2008 static void output_pending_types_for_scope PROTO((dw_die_ref));
2009 static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref));
2010 static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref));
2011 static void gen_inlined_union_type_die PROTO((tree, dw_die_ref));
2012 static void gen_enumeration_type_die PROTO((tree, dw_die_ref));
2013 static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref));
2014 static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref));
2015 static void gen_formal_types_die PROTO((tree, dw_die_ref));
2016 static void gen_subprogram_die PROTO((tree, dw_die_ref));
2017 static void gen_variable_die PROTO((tree, dw_die_ref));
2018 static void gen_label_die PROTO((tree, dw_die_ref));
2019 static void gen_lexical_block_die PROTO((tree, dw_die_ref, int));
2020 static void gen_inlined_subprogram_die PROTO((tree, dw_die_ref, int));
2021 static void gen_field_die PROTO((tree, dw_die_ref));
2022 static void gen_ptr_to_mbr_type_die PROTO((tree, dw_die_ref));
2023 static void gen_compile_unit_die PROTO((char *));
2024 static void gen_string_type_die PROTO((tree, dw_die_ref));
2025 static void gen_inheritance_die PROTO((tree, dw_die_ref));
2026 static void gen_member_die PROTO((tree, dw_die_ref));
2027 static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref));
2028 static void gen_subroutine_type_die PROTO((tree, dw_die_ref));
2029 static void gen_typedef_die PROTO((tree, dw_die_ref));
2030 static void gen_type_die PROTO((tree, dw_die_ref));
2031 static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref));
2032 static void gen_block_die PROTO((tree, dw_die_ref, int));
2033 static void decls_for_scope PROTO((tree, dw_die_ref, int));
2034 static int is_redundant_typedef PROTO((tree));
2035 static void gen_decl_die PROTO((tree, dw_die_ref));
2036 static unsigned lookup_filename PROTO((char *));
2038 /* Section names used to hold DWARF debugging information. */
2039 #ifndef DEBUG_SECTION
2040 #define DEBUG_SECTION ".debug_info"
2042 #ifndef ABBREV_SECTION
2043 #define ABBREV_SECTION ".debug_abbrev"
2045 #ifndef ARANGES_SECTION
2046 #define ARANGES_SECTION ".debug_aranges"
2048 #ifndef DW_MACINFO_SECTION
2049 #define DW_MACINFO_SECTION ".debug_macinfo"
2051 #ifndef LINE_SECTION
2052 #define LINE_SECTION ".debug_line"
2055 #define LOC_SECTION ".debug_loc"
2057 #ifndef PUBNAMES_SECTION
2058 #define PUBNAMES_SECTION ".debug_pubnames"
2061 #define STR_SECTION ".debug_str"
2064 /* Standerd ELF section names for compiled code and data. */
2065 #ifndef TEXT_SECTION
2066 #define TEXT_SECTION ".text"
2068 #ifndef DATA_SECTION
2069 #define DATA_SECTION ".data"
2072 #define BSS_SECTION ".bss"
2076 /* Definitions of defaults for formats and names of various special
2077 (artificial) labels which may be generated within this file (when the -g
2078 options is used and DWARF_DEBUGGING_INFO is in effect.
2079 If necessary, these may be overridden from within the tm.h file, but
2080 typically, overriding these defaults is unnecessary. */
2082 char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2084 #ifndef TEXT_END_LABEL
2085 #define TEXT_END_LABEL "Letext"
2087 #ifndef DATA_END_LABEL
2088 #define DATA_END_LABEL "Ledata"
2090 #ifndef BSS_END_LABEL
2091 #define BSS_END_LABEL "Lebss"
2093 #ifndef INSN_LABEL_FMT
2094 #define INSN_LABEL_FMT "LI%u_"
2096 #ifndef BLOCK_BEGIN_LABEL
2097 #define BLOCK_BEGIN_LABEL "LBB"
2099 #ifndef BLOCK_END_LABEL
2100 #define BLOCK_END_LABEL "LBE"
2102 #ifndef BODY_BEGIN_LABEL
2103 #define BODY_BEGIN_LABEL "Lbb"
2105 #ifndef BODY_END_LABEL
2106 #define BODY_END_LABEL "Lbe"
2108 #ifndef LINE_CODE_LABEL
2109 #define LINE_CODE_LABEL "LM"
2111 #ifndef SEPARATE_LINE_CODE_LABEL
2112 #define SEPARATE_LINE_CODE_LABEL "LSM"
2115 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
2116 newline is produced. When flag_verbose_asm is asserted, we add commnetary
2117 at the end of the line, so we must avoid output of a newline here. */
2118 #ifndef ASM_OUTPUT_DWARF_STRING
2119 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
2121 register int slen = strlen(P); \
2122 register char *p = (P); \
2124 fprintf (FILE, "\t.ascii \""); \
2125 for (i = 0; i < slen; i++) \
2127 register int c = p[i]; \
2128 if (c == '\"' || c == '\\') \
2129 putc ('\\', FILE); \
2130 if (c >= ' ' && c < 0177) \
2134 fprintf (FILE, "\\%o", c); \
2137 fprintf (FILE, "\\0\""); \
2142 /* Convert a reference to the assembler name of a C-level name. This
2143 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
2144 a string rather than writing to a file. */
2145 #ifndef ASM_NAME_TO_STRING
2146 #define ASM_NAME_TO_STRING(STR, NAME) \
2148 if ((NAME)[0] == '*') \
2149 strcpy (STR, NAME+1); \
2151 strcpy (STR, NAME); \
2156 /* Convert an integer constant expression into assembler syntax. Addition
2157 and subtraction are the only arithmetic that may appear in these
2158 expressions. This is an adaptation of output_addr_const in final.c.
2159 Here, the target of the conversion is a string buffer. We can't use
2160 output_addr_const directly, because it writes to a file. */
2163 addr_const_to_string (str, x)
2172 switch (GET_CODE (x))
2182 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
2187 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2188 ASM_NAME_TO_STRING (buf2, buf1);
2193 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
2194 ASM_NAME_TO_STRING (buf2, buf1);
2199 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
2204 /* This used to output parentheses around the expression, but that does
2205 not work on the 386 (either ATT or BSD assembler). */
2206 addr_const_to_string (buf1, XEXP (x, 0));
2211 if (GET_MODE (x) == VOIDmode)
2213 /* We can use %d if the number is one word and positive. */
2214 if (CONST_DOUBLE_HIGH (x))
2215 sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
2216 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2217 else if (CONST_DOUBLE_LOW (x) < 0)
2218 sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
2220 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
2221 CONST_DOUBLE_LOW (x));
2225 /* We can't handle floating point constants; PRINT_OPERAND must
2227 output_operand_lossage ("floating constant misused");
2231 /* Some assemblers need integer constants to appear last (eg masm). */
2232 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2234 addr_const_to_string (buf1, XEXP (x, 1));
2236 if (INTVAL (XEXP (x, 0)) >= 0)
2239 addr_const_to_string (buf1, XEXP (x, 0));
2244 addr_const_to_string (buf1, XEXP (x, 0));
2246 if (INTVAL (XEXP (x, 1)) >= 0)
2249 addr_const_to_string (buf1, XEXP (x, 1));
2255 /* Avoid outputting things like x-x or x+5-x, since some assemblers
2256 can't handle that. */
2257 x = simplify_subtraction (x);
2258 if (GET_CODE (x) != MINUS)
2261 addr_const_to_string (buf1, XEXP (x, 0));
2264 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2265 && INTVAL (XEXP (x, 1)) < 0)
2267 strcat (str, ASM_OPEN_PAREN);
2268 addr_const_to_string (buf1, XEXP (x, 1));
2270 strcat (str, ASM_CLOSE_PAREN);
2274 addr_const_to_string (buf1, XEXP (x, 1));
2281 addr_const_to_string (buf1, XEXP (x, 0));
2286 output_operand_lossage ("invalid expression as operand");
2290 /* Convert an address constant to a string, and return a pointer to
2291 a copy of the result, located on the heap. */
2298 addr_const_to_string (buf, x);
2299 return xstrdup (buf);
2302 /* Test if rtl node points to a psuedo register. */
2308 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
2309 || ((GET_CODE (rtl) == SUBREG)
2310 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
2313 /* Return a reference to a type, with its const and volatile qualifiers
2317 type_main_variant (type)
2320 type = TYPE_MAIN_VARIANT (type);
2322 /* There really should be only one main variant among any group of variants
2323 of a given type (and all of the MAIN_VARIANT values for all members of
2324 the group should point to that one type) but sometimes the C front-end
2325 messes this up for array types, so we work around that bug here. */
2327 if (TREE_CODE (type) == ARRAY_TYPE)
2328 while (type != TYPE_MAIN_VARIANT (type))
2329 type = TYPE_MAIN_VARIANT (type);
2334 /* Return non-zero if the given type node represents a tagged type. */
2337 is_tagged_type (type)
2340 register enum tree_code code = TREE_CODE (type);
2342 return (code == RECORD_TYPE || code == UNION_TYPE
2343 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
2346 /* Convert a DIE tag into its string name. */
2349 dwarf_tag_name (tag)
2350 register unsigned tag;
2354 case DW_TAG_padding:
2355 return "DW_TAG_padding";
2356 case DW_TAG_array_type:
2357 return "DW_TAG_array_type";
2358 case DW_TAG_class_type:
2359 return "DW_TAG_class_type";
2360 case DW_TAG_entry_point:
2361 return "DW_TAG_entry_point";
2362 case DW_TAG_enumeration_type:
2363 return "DW_TAG_enumeration_type";
2364 case DW_TAG_formal_parameter:
2365 return "DW_TAG_formal_parameter";
2366 case DW_TAG_imported_declaration:
2367 return "DW_TAG_imported_declaration";
2369 return "DW_TAG_label";
2370 case DW_TAG_lexical_block:
2371 return "DW_TAG_lexical_block";
2373 return "DW_TAG_member";
2374 case DW_TAG_pointer_type:
2375 return "DW_TAG_pointer_type";
2376 case DW_TAG_reference_type:
2377 return "DW_TAG_reference_type";
2378 case DW_TAG_compile_unit:
2379 return "DW_TAG_compile_unit";
2380 case DW_TAG_string_type:
2381 return "DW_TAG_string_type";
2382 case DW_TAG_structure_type:
2383 return "DW_TAG_structure_type";
2384 case DW_TAG_subroutine_type:
2385 return "DW_TAG_subroutine_type";
2386 case DW_TAG_typedef:
2387 return "DW_TAG_typedef";
2388 case DW_TAG_union_type:
2389 return "DW_TAG_union_type";
2390 case DW_TAG_unspecified_parameters:
2391 return "DW_TAG_unspecified_parameters";
2392 case DW_TAG_variant:
2393 return "DW_TAG_variant";
2394 case DW_TAG_common_block:
2395 return "DW_TAG_common_block";
2396 case DW_TAG_common_inclusion:
2397 return "DW_TAG_common_inclusion";
2398 case DW_TAG_inheritance:
2399 return "DW_TAG_inheritance";
2400 case DW_TAG_inlined_subroutine:
2401 return "DW_TAG_inlined_subroutine";
2403 return "DW_TAG_module";
2404 case DW_TAG_ptr_to_member_type:
2405 return "DW_TAG_ptr_to_member_type";
2406 case DW_TAG_set_type:
2407 return "DW_TAG_set_type";
2408 case DW_TAG_subrange_type:
2409 return "DW_TAG_subrange_type";
2410 case DW_TAG_with_stmt:
2411 return "DW_TAG_with_stmt";
2412 case DW_TAG_access_declaration:
2413 return "DW_TAG_access_declaration";
2414 case DW_TAG_base_type:
2415 return "DW_TAG_base_type";
2416 case DW_TAG_catch_block:
2417 return "DW_TAG_catch_block";
2418 case DW_TAG_const_type:
2419 return "DW_TAG_const_type";
2420 case DW_TAG_constant:
2421 return "DW_TAG_constant";
2422 case DW_TAG_enumerator:
2423 return "DW_TAG_enumerator";
2424 case DW_TAG_file_type:
2425 return "DW_TAG_file_type";
2427 return "DW_TAG_friend";
2428 case DW_TAG_namelist:
2429 return "DW_TAG_namelist";
2430 case DW_TAG_namelist_item:
2431 return "DW_TAG_namelist_item";
2432 case DW_TAG_packed_type:
2433 return "DW_TAG_packed_type";
2434 case DW_TAG_subprogram:
2435 return "DW_TAG_subprogram";
2436 case DW_TAG_template_type_param:
2437 return "DW_TAG_template_type_param";
2438 case DW_TAG_template_value_param:
2439 return "DW_TAG_template_value_param";
2440 case DW_TAG_thrown_type:
2441 return "DW_TAG_thrown_type";
2442 case DW_TAG_try_block:
2443 return "DW_TAG_try_block";
2444 case DW_TAG_variant_part:
2445 return "DW_TAG_variant_part";
2446 case DW_TAG_variable:
2447 return "DW_TAG_variable";
2448 case DW_TAG_volatile_type:
2449 return "DW_TAG_volatile_type";
2450 case DW_TAG_MIPS_loop:
2451 return "DW_TAG_MIPS_loop";
2452 case DW_TAG_format_label:
2453 return "DW_TAG_format_label";
2454 case DW_TAG_function_template:
2455 return "DW_TAG_function_template";
2456 case DW_TAG_class_template:
2457 return "DW_TAG_class_template";
2459 return "DW_TAG_<unknown>";
2463 /* Convert a DWARF attribute code into its string name. */
2466 dwarf_attr_name (attr)
2467 register unsigned attr;
2472 return "DW_AT_sibling";
2473 case DW_AT_location:
2474 return "DW_AT_location";
2476 return "DW_AT_name";
2477 case DW_AT_ordering:
2478 return "DW_AT_ordering";
2479 case DW_AT_subscr_data:
2480 return "DW_AT_subscr_data";
2481 case DW_AT_byte_size:
2482 return "DW_AT_byte_size";
2483 case DW_AT_bit_offset:
2484 return "DW_AT_bit_offset";
2485 case DW_AT_bit_size:
2486 return "DW_AT_bit_size";
2487 case DW_AT_element_list:
2488 return "DW_AT_element_list";
2489 case DW_AT_stmt_list:
2490 return "DW_AT_stmt_list";
2492 return "DW_AT_low_pc";
2494 return "DW_AT_high_pc";
2495 case DW_AT_language:
2496 return "DW_AT_language";
2498 return "DW_AT_member";
2500 return "DW_AT_discr";
2501 case DW_AT_discr_value:
2502 return "DW_AT_discr_value";
2503 case DW_AT_visibility:
2504 return "DW_AT_visibility";
2506 return "DW_AT_import";
2507 case DW_AT_string_length:
2508 return "DW_AT_string_length";
2509 case DW_AT_common_reference:
2510 return "DW_AT_common_reference";
2511 case DW_AT_comp_dir:
2512 return "DW_AT_comp_dir";
2513 case DW_AT_const_value:
2514 return "DW_AT_const_value";
2515 case DW_AT_containing_type:
2516 return "DW_AT_containing_type";
2517 case DW_AT_default_value:
2518 return "DW_AT_default_value";
2520 return "DW_AT_inline";
2521 case DW_AT_is_optional:
2522 return "DW_AT_is_optional";
2523 case DW_AT_lower_bound:
2524 return "DW_AT_lower_bound";
2525 case DW_AT_producer:
2526 return "DW_AT_producer";
2527 case DW_AT_prototyped:
2528 return "DW_AT_prototyped";
2529 case DW_AT_return_addr:
2530 return "DW_AT_return_addr";
2531 case DW_AT_start_scope:
2532 return "DW_AT_start_scope";
2533 case DW_AT_stride_size:
2534 return "DW_AT_stride_size";
2535 case DW_AT_upper_bound:
2536 return "DW_AT_upper_bound";
2537 case DW_AT_abstract_origin:
2538 return "DW_AT_abstract_origin";
2539 case DW_AT_accessibility:
2540 return "DW_AT_accessibility";
2541 case DW_AT_address_class:
2542 return "DW_AT_address_class";
2543 case DW_AT_artificial:
2544 return "DW_AT_artificial";
2545 case DW_AT_base_types:
2546 return "DW_AT_base_types";
2547 case DW_AT_calling_convention:
2548 return "DW_AT_calling_convention";
2550 return "DW_AT_count";
2551 case DW_AT_data_member_location:
2552 return "DW_AT_data_member_location";
2553 case DW_AT_decl_column:
2554 return "DW_AT_decl_column";
2555 case DW_AT_decl_file:
2556 return "DW_AT_decl_file";
2557 case DW_AT_decl_line:
2558 return "DW_AT_decl_line";
2559 case DW_AT_declaration:
2560 return "DW_AT_declaration";
2561 case DW_AT_discr_list:
2562 return "DW_AT_discr_list";
2563 case DW_AT_encoding:
2564 return "DW_AT_encoding";
2565 case DW_AT_external:
2566 return "DW_AT_external";
2567 case DW_AT_frame_base:
2568 return "DW_AT_frame_base";
2570 return "DW_AT_friend";
2571 case DW_AT_identifier_case:
2572 return "DW_AT_identifier_case";
2573 case DW_AT_macro_info:
2574 return "DW_AT_macro_info";
2575 case DW_AT_namelist_items:
2576 return "DW_AT_namelist_items";
2577 case DW_AT_priority:
2578 return "DW_AT_priority";
2580 return "DW_AT_segment";
2581 case DW_AT_specification:
2582 return "DW_AT_specification";
2583 case DW_AT_static_link:
2584 return "DW_AT_static_link";
2586 return "DW_AT_type";
2587 case DW_AT_use_location:
2588 return "DW_AT_use_location";
2589 case DW_AT_variable_parameter:
2590 return "DW_AT_variable_parameter";
2591 case DW_AT_virtuality:
2592 return "DW_AT_virtuality";
2593 case DW_AT_vtable_elem_location:
2594 return "DW_AT_vtable_elem_location";
2596 case DW_AT_MIPS_fde:
2597 return "DW_AT_MIPS_fde";
2598 case DW_AT_MIPS_loop_begin:
2599 return "DW_AT_MIPS_loop_begin";
2600 case DW_AT_MIPS_tail_loop_begin:
2601 return "DW_AT_MIPS_tail_loop_begin";
2602 case DW_AT_MIPS_epilog_begin:
2603 return "DW_AT_MIPS_epilog_begin";
2604 case DW_AT_MIPS_loop_unroll_factor:
2605 return "DW_AT_MIPS_loop_unroll_factor";
2606 case DW_AT_MIPS_software_pipeline_depth:
2607 return "DW_AT_MIPS_software_pipeline_depth";
2608 case DW_AT_MIPS_linkage_name:
2609 return "DW_AT_MIPS_linkage_name";
2610 case DW_AT_MIPS_stride:
2611 return "DW_AT_MIPS_stride";
2612 case DW_AT_MIPS_abstract_name:
2613 return "DW_AT_MIPS_abstract_name";
2614 case DW_AT_MIPS_clone_origin:
2615 return "DW_AT_MIPS_clone_origin";
2616 case DW_AT_MIPS_has_inlines:
2617 return "DW_AT_MIPS_has_inlines";
2619 case DW_AT_sf_names:
2620 return "DW_AT_sf_names";
2621 case DW_AT_src_info:
2622 return "DW_AT_src_info";
2623 case DW_AT_mac_info:
2624 return "DW_AT_mac_info";
2625 case DW_AT_src_coords:
2626 return "DW_AT_src_coords";
2627 case DW_AT_body_begin:
2628 return "DW_AT_body_begin";
2629 case DW_AT_body_end:
2630 return "DW_AT_body_end";
2632 return "DW_AT_<unknown>";
2636 /* Convert a DWARF value form code into its string name. */
2639 dwarf_form_name (form)
2640 register unsigned form;
2645 return "DW_FORM_addr";
2646 case DW_FORM_block2:
2647 return "DW_FORM_block2";
2648 case DW_FORM_block4:
2649 return "DW_FORM_block4";
2651 return "DW_FORM_data2";
2653 return "DW_FORM_data4";
2655 return "DW_FORM_data8";
2656 case DW_FORM_string:
2657 return "DW_FORM_string";
2659 return "DW_FORM_block";
2660 case DW_FORM_block1:
2661 return "DW_FORM_block1";
2663 return "DW_FORM_data1";
2665 return "DW_FORM_flag";
2667 return "DW_FORM_sdata";
2669 return "DW_FORM_strp";
2671 return "DW_FORM_udata";
2672 case DW_FORM_ref_addr:
2673 return "DW_FORM_ref_addr";
2675 return "DW_FORM_ref1";
2677 return "DW_FORM_ref2";
2679 return "DW_FORM_ref4";
2681 return "DW_FORM_ref8";
2682 case DW_FORM_ref_udata:
2683 return "DW_FORM_ref_udata";
2684 case DW_FORM_indirect:
2685 return "DW_FORM_indirect";
2687 return "DW_FORM_<unknown>";
2691 /* Convert a DWARF stack opcode into its string name. */
2694 dwarf_stack_op_name (op)
2695 register unsigned op;
2700 return "DW_OP_addr";
2702 return "DW_OP_deref";
2704 return "DW_OP_const1u";
2706 return "DW_OP_const1s";
2708 return "DW_OP_const2u";
2710 return "DW_OP_const2s";
2712 return "DW_OP_const4u";
2714 return "DW_OP_const4s";
2716 return "DW_OP_const8u";
2718 return "DW_OP_const8s";
2720 return "DW_OP_constu";
2722 return "DW_OP_consts";
2726 return "DW_OP_drop";
2728 return "DW_OP_over";
2730 return "DW_OP_pick";
2732 return "DW_OP_swap";
2736 return "DW_OP_xderef";
2744 return "DW_OP_minus";
2756 return "DW_OP_plus";
2757 case DW_OP_plus_uconst:
2758 return "DW_OP_plus_uconst";
2764 return "DW_OP_shra";
2782 return "DW_OP_skip";
2784 return "DW_OP_lit0";
2786 return "DW_OP_lit1";
2788 return "DW_OP_lit2";
2790 return "DW_OP_lit3";
2792 return "DW_OP_lit4";
2794 return "DW_OP_lit5";
2796 return "DW_OP_lit6";
2798 return "DW_OP_lit7";
2800 return "DW_OP_lit8";
2802 return "DW_OP_lit9";
2804 return "DW_OP_lit10";
2806 return "DW_OP_lit11";
2808 return "DW_OP_lit12";
2810 return "DW_OP_lit13";
2812 return "DW_OP_lit14";
2814 return "DW_OP_lit15";
2816 return "DW_OP_lit16";
2818 return "DW_OP_lit17";
2820 return "DW_OP_lit18";
2822 return "DW_OP_lit19";
2824 return "DW_OP_lit20";
2826 return "DW_OP_lit21";
2828 return "DW_OP_lit22";
2830 return "DW_OP_lit23";
2832 return "DW_OP_lit24";
2834 return "DW_OP_lit25";
2836 return "DW_OP_lit26";
2838 return "DW_OP_lit27";
2840 return "DW_OP_lit28";
2842 return "DW_OP_lit29";
2844 return "DW_OP_lit30";
2846 return "DW_OP_lit31";
2848 return "DW_OP_reg0";
2850 return "DW_OP_reg1";
2852 return "DW_OP_reg2";
2854 return "DW_OP_reg3";
2856 return "DW_OP_reg4";
2858 return "DW_OP_reg5";
2860 return "DW_OP_reg6";
2862 return "DW_OP_reg7";
2864 return "DW_OP_reg8";
2866 return "DW_OP_reg9";
2868 return "DW_OP_reg10";
2870 return "DW_OP_reg11";
2872 return "DW_OP_reg12";
2874 return "DW_OP_reg13";
2876 return "DW_OP_reg14";
2878 return "DW_OP_reg15";
2880 return "DW_OP_reg16";
2882 return "DW_OP_reg17";
2884 return "DW_OP_reg18";
2886 return "DW_OP_reg19";
2888 return "DW_OP_reg20";
2890 return "DW_OP_reg21";
2892 return "DW_OP_reg22";
2894 return "DW_OP_reg23";
2896 return "DW_OP_reg24";
2898 return "DW_OP_reg25";
2900 return "DW_OP_reg26";
2902 return "DW_OP_reg27";
2904 return "DW_OP_reg28";
2906 return "DW_OP_reg29";
2908 return "DW_OP_reg30";
2910 return "DW_OP_reg31";
2912 return "DW_OP_breg0";
2914 return "DW_OP_breg1";
2916 return "DW_OP_breg2";
2918 return "DW_OP_breg3";
2920 return "DW_OP_breg4";
2922 return "DW_OP_breg5";
2924 return "DW_OP_breg6";
2926 return "DW_OP_breg7";
2928 return "DW_OP_breg8";
2930 return "DW_OP_breg9";
2932 return "DW_OP_breg10";
2934 return "DW_OP_breg11";
2936 return "DW_OP_breg12";
2938 return "DW_OP_breg13";
2940 return "DW_OP_breg14";
2942 return "DW_OP_breg15";
2944 return "DW_OP_breg16";
2946 return "DW_OP_breg17";
2948 return "DW_OP_breg18";
2950 return "DW_OP_breg19";
2952 return "DW_OP_breg20";
2954 return "DW_OP_breg21";
2956 return "DW_OP_breg22";
2958 return "DW_OP_breg23";
2960 return "DW_OP_breg24";
2962 return "DW_OP_breg25";
2964 return "DW_OP_breg26";
2966 return "DW_OP_breg27";
2968 return "DW_OP_breg28";
2970 return "DW_OP_breg29";
2972 return "DW_OP_breg30";
2974 return "DW_OP_breg31";
2976 return "DW_OP_regx";
2978 return "DW_OP_fbreg";
2980 return "DW_OP_bregx";
2982 return "DW_OP_piece";
2983 case DW_OP_deref_size:
2984 return "DW_OP_deref_size";
2985 case DW_OP_xderef_size:
2986 return "DW_OP_xderef_size";
2990 return "OP_<unknown>";
2994 /* Convert a DWARF type code into its string name. */
2997 dwarf_type_encoding_name (enc)
2998 register unsigned enc;
3002 case DW_ATE_address:
3003 return "DW_ATE_address";
3004 case DW_ATE_boolean:
3005 return "DW_ATE_boolean";
3006 case DW_ATE_complex_float:
3007 return "DW_ATE_complex_float";
3009 return "DW_ATE_float";
3011 return "DW_ATE_signed";
3012 case DW_ATE_signed_char:
3013 return "DW_ATE_signed_char";
3014 case DW_ATE_unsigned:
3015 return "DW_ATE_unsigned";
3016 case DW_ATE_unsigned_char:
3017 return "DW_ATE_unsigned_char";
3019 return "DW_ATE_<unknown>";
3023 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3024 instance of an inlined instance of a decl which is local to an inline
3025 function, so we have to trace all of the way back through the origin chain
3026 to find out what sort of node actually served as the original seed for the
3030 decl_ultimate_origin (decl)
3033 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
3035 if (immediate_origin == NULL_TREE)
3039 register tree ret_val;
3040 register tree lookahead = immediate_origin;
3044 ret_val = lookahead;
3045 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
3047 while (lookahead != NULL && lookahead != ret_val);
3053 /* Determine the "ultimate origin" of a block. The block may be an inlined
3054 instance of an inlined instance of a block which is local to an inline
3055 function, so we have to trace all of the way back through the origin chain
3056 to find out what sort of node actually served as the original seed for the
3060 block_ultimate_origin (block)
3061 register tree block;
3063 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3065 if (immediate_origin == NULL_TREE)
3069 register tree ret_val;
3070 register tree lookahead = immediate_origin;
3074 ret_val = lookahead;
3075 lookahead = (TREE_CODE (ret_val) == BLOCK)
3076 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3079 while (lookahead != NULL && lookahead != ret_val);
3085 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3086 of a virtual function may refer to a base class, so we check the 'this'
3090 decl_class_context (decl)
3093 tree context = NULL_TREE;
3095 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3096 context = DECL_CONTEXT (decl);
3098 context = TYPE_MAIN_VARIANT
3099 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3101 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
3102 context = NULL_TREE;
3107 /* Add an attribute/value pair to a DIE */
3110 add_dwarf_attr (die, attr)
3111 register dw_die_ref die;
3112 register dw_attr_ref attr;
3114 if (die != NULL && attr != NULL)
3116 if (die->die_attr == NULL)
3118 die->die_attr = attr;
3119 die->die_attr_last = attr;
3123 die->die_attr_last->dw_attr_next = attr;
3124 die->die_attr_last = attr;
3129 /* Add a flag value attribute to a DIE. */
3132 add_AT_flag (die, attr_kind, flag)
3133 register dw_die_ref die;
3134 register enum dwarf_attribute attr_kind;
3135 register unsigned flag;
3137 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3139 attr->dw_attr_next = NULL;
3140 attr->dw_attr = attr_kind;
3141 attr->dw_attr_val.val_class = dw_val_class_flag;
3142 attr->dw_attr_val.v.val_flag = flag;
3143 add_dwarf_attr (die, attr);
3146 /* Add a signed integer attribute value to a DIE. */
3149 add_AT_int (die, attr_kind, int_val)
3150 register dw_die_ref die;
3151 register enum dwarf_attribute attr_kind;
3152 register long int int_val;
3154 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3156 attr->dw_attr_next = NULL;
3157 attr->dw_attr = attr_kind;
3158 attr->dw_attr_val.val_class = dw_val_class_const;
3159 attr->dw_attr_val.v.val_int = int_val;
3160 add_dwarf_attr (die, attr);
3163 /* Add an unsigned integer attribute value to a DIE. */
3166 add_AT_unsigned (die, attr_kind, unsigned_val)
3167 register dw_die_ref die;
3168 register enum dwarf_attribute attr_kind;
3169 register unsigned long unsigned_val;
3171 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3173 attr->dw_attr_next = NULL;
3174 attr->dw_attr = attr_kind;
3175 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
3176 attr->dw_attr_val.v.val_unsigned = unsigned_val;
3177 add_dwarf_attr (die, attr);
3180 /* Add an unsigned double integer attribute value to a DIE. */
3183 add_AT_long_long (die, attr_kind, val_hi, val_low)
3184 register dw_die_ref die;
3185 register enum dwarf_attribute attr_kind;
3186 register unsigned long val_hi;
3187 register unsigned long val_low;
3189 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3191 attr->dw_attr_next = NULL;
3192 attr->dw_attr = attr_kind;
3193 attr->dw_attr_val.val_class = dw_val_class_long_long;
3194 attr->dw_attr_val.v.val_long_long.hi = val_hi;
3195 attr->dw_attr_val.v.val_long_long.low = val_low;
3196 add_dwarf_attr (die, attr);
3199 /* Add a floating point attribute value to a DIE and return it. */
3202 add_AT_float (die, attr_kind, length, array)
3203 register dw_die_ref die;
3204 register enum dwarf_attribute attr_kind;
3205 register unsigned length;
3206 register long *array;
3208 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3210 attr->dw_attr_next = NULL;
3211 attr->dw_attr = attr_kind;
3212 attr->dw_attr_val.val_class = dw_val_class_float;
3213 attr->dw_attr_val.v.val_float.length = length;
3214 attr->dw_attr_val.v.val_float.array = array;
3215 add_dwarf_attr (die, attr);
3218 /* Add a string attribute value to a DIE. */
3221 add_AT_string (die, attr_kind, str)
3222 register dw_die_ref die;
3223 register enum dwarf_attribute attr_kind;
3226 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3228 attr->dw_attr_next = NULL;
3229 attr->dw_attr = attr_kind;
3230 attr->dw_attr_val.val_class = dw_val_class_str;
3231 attr->dw_attr_val.v.val_str = xstrdup (str);
3232 add_dwarf_attr (die, attr);
3235 /* Add a DIE reference attribute value to a DIE. */
3238 add_AT_die_ref (die, attr_kind, targ_die)
3239 register dw_die_ref die;
3240 register enum dwarf_attribute attr_kind;
3241 register dw_die_ref targ_die;
3243 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3245 attr->dw_attr_next = NULL;
3246 attr->dw_attr = attr_kind;
3247 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3248 attr->dw_attr_val.v.val_die_ref = targ_die;
3249 add_dwarf_attr (die, attr);
3252 /* Add an FDE reference attribute value to a DIE. */
3255 add_AT_fde_ref (die, attr_kind, targ_fde)
3256 register dw_die_ref die;
3257 register enum dwarf_attribute attr_kind;
3258 register unsigned targ_fde;
3260 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3262 attr->dw_attr_next = NULL;
3263 attr->dw_attr = attr_kind;
3264 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
3265 attr->dw_attr_val.v.val_fde_index = targ_fde;
3266 add_dwarf_attr (die, attr);
3269 /* Add a location description attribute value to a DIE. */
3272 add_AT_loc (die, attr_kind, loc)
3273 register dw_die_ref die;
3274 register enum dwarf_attribute attr_kind;
3275 register dw_loc_descr_ref loc;
3277 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3279 attr->dw_attr_next = NULL;
3280 attr->dw_attr = attr_kind;
3281 attr->dw_attr_val.val_class = dw_val_class_loc;
3282 attr->dw_attr_val.v.val_loc = loc;
3283 add_dwarf_attr (die, attr);
3286 /* Add an address constant attribute value to a DIE. */
3289 add_AT_addr (die, attr_kind, addr)
3290 register dw_die_ref die;
3291 register enum dwarf_attribute attr_kind;
3294 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3296 attr->dw_attr_next = NULL;
3297 attr->dw_attr = attr_kind;
3298 attr->dw_attr_val.val_class = dw_val_class_addr;
3299 attr->dw_attr_val.v.val_addr = addr;
3300 add_dwarf_attr (die, attr);
3303 /* Add a label identifier attribute value to a DIE. */
3306 add_AT_lbl_id (die, attr_kind, lbl_id)
3307 register dw_die_ref die;
3308 register enum dwarf_attribute attr_kind;
3309 register char *lbl_id;
3311 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3313 attr->dw_attr_next = NULL;
3314 attr->dw_attr = attr_kind;
3315 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
3316 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
3317 add_dwarf_attr (die, attr);
3320 /* Add a section offset attribute value to a DIE. */
3323 add_AT_section_offset (die, attr_kind, section)
3324 register dw_die_ref die;
3325 register enum dwarf_attribute attr_kind;
3326 register char *section;
3328 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3330 attr->dw_attr_next = NULL;
3331 attr->dw_attr = attr_kind;
3332 attr->dw_attr_val.val_class = dw_val_class_section_offset;
3333 attr->dw_attr_val.v.val_section = section;
3334 add_dwarf_attr (die, attr);
3338 /* Test if die refers to an external subroutine. */
3341 is_extern_subr_die (die)
3342 register dw_die_ref die;
3344 register dw_attr_ref a;
3345 register int is_subr = FALSE;
3346 register int is_extern = FALSE;
3348 if (die != NULL && die->die_tag == DW_TAG_subprogram)
3351 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3353 if (a->dw_attr == DW_AT_external
3354 && a->dw_attr_val.val_class == dw_val_class_flag
3355 && a->dw_attr_val.v.val_flag != 0)
3363 return is_subr && is_extern;
3366 /* Get the attribute of type attr_kind. */
3368 static inline dw_attr_ref
3369 get_AT (die, attr_kind)
3370 register dw_die_ref die;
3371 register enum dwarf_attribute attr_kind;
3373 register dw_attr_ref a;
3374 register dw_die_ref spec = NULL;
3378 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3380 if (a->dw_attr == attr_kind)
3383 if (a->dw_attr == DW_AT_specification
3384 || a->dw_attr == DW_AT_abstract_origin)
3385 spec = a->dw_attr_val.v.val_die_ref;
3389 return get_AT (spec, attr_kind);
3395 /* Return the "low pc" attribute value, typically associated with
3396 a subprogram DIE. Return null if the "low pc" attribute is
3397 either not prsent, or if it cannot be represented as an
3398 assembler label identifier. */
3400 static inline char *
3402 register dw_die_ref die;
3404 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
3406 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3407 return a->dw_attr_val.v.val_lbl_id;
3412 /* Return the "high pc" attribute value, typically associated with
3413 a subprogram DIE. Return null if the "high pc" attribute is
3414 either not prsent, or if it cannot be represented as an
3415 assembler label identifier. */
3417 static inline char *
3419 register dw_die_ref die;
3421 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
3423 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3424 return a->dw_attr_val.v.val_lbl_id;
3429 /* Return the value of the string attribute designated by ATTR_KIND, or
3430 NULL if it is not present. */
3432 static inline char *
3433 get_AT_string (die, attr_kind)
3434 register dw_die_ref die;
3435 register enum dwarf_attribute attr_kind;
3437 register dw_attr_ref a = get_AT (die, attr_kind);
3439 if (a && a->dw_attr_val.val_class == dw_val_class_str)
3440 return a->dw_attr_val.v.val_str;
3445 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3446 if it is not present. */
3449 get_AT_flag (die, attr_kind)
3450 register dw_die_ref die;
3451 register enum dwarf_attribute attr_kind;
3453 register dw_attr_ref a = get_AT (die, attr_kind);
3455 if (a && a->dw_attr_val.val_class == dw_val_class_flag)
3456 return a->dw_attr_val.v.val_flag;
3461 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3462 if it is not present. */
3464 static inline unsigned
3465 get_AT_unsigned (die, attr_kind)
3466 register dw_die_ref die;
3467 register enum dwarf_attribute attr_kind;
3469 register dw_attr_ref a = get_AT (die, attr_kind);
3471 if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
3472 return a->dw_attr_val.v.val_unsigned;
3480 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3482 return (lang == DW_LANG_C || lang == DW_LANG_C89
3483 || lang == DW_LANG_C_plus_plus);
3489 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3491 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
3494 /* Remove the specified attribute if present. */
3497 remove_AT (die, attr_kind)
3498 register dw_die_ref die;
3499 register enum dwarf_attribute attr_kind;
3501 register dw_attr_ref a;
3502 register dw_attr_ref removed = NULL;;
3506 if (die->die_attr->dw_attr == attr_kind)
3508 removed = die->die_attr;
3509 if (die->die_attr_last == die->die_attr)
3510 die->die_attr_last = NULL;
3512 die->die_attr = die->die_attr->dw_attr_next;
3516 for (a = die->die_attr; a->dw_attr_next != NULL;
3517 a = a->dw_attr_next)
3518 if (a->dw_attr_next->dw_attr == attr_kind)
3520 removed = a->dw_attr_next;
3521 if (die->die_attr_last == a->dw_attr_next)
3522 die->die_attr_last = a;
3524 a->dw_attr_next = a->dw_attr_next->dw_attr_next;
3533 /* Discard the children of this DIE. */
3536 remove_children (die)
3537 register dw_die_ref die;
3539 register dw_die_ref child_die = die->die_child;
3541 die->die_child = NULL;
3542 die->die_child_last = NULL;
3544 while (child_die != NULL)
3546 register dw_die_ref tmp_die = child_die;
3547 register dw_attr_ref a;
3549 child_die = child_die->die_sib;
3551 for (a = tmp_die->die_attr; a != NULL; )
3553 register dw_attr_ref tmp_a = a;
3555 a = a->dw_attr_next;
3563 /* Add a child DIE below its parent. */
3566 add_child_die (die, child_die)
3567 register dw_die_ref die;
3568 register dw_die_ref child_die;
3570 if (die != NULL && child_die != NULL)
3572 assert (die != child_die);
3573 child_die->die_parent = die;
3574 child_die->die_sib = NULL;
3576 if (die->die_child == NULL)
3578 die->die_child = child_die;
3579 die->die_child_last = child_die;
3583 die->die_child_last->die_sib = child_die;
3584 die->die_child_last = child_die;
3589 /* Return a pointer to a newly created DIE node. */
3591 static inline dw_die_ref
3592 new_die (tag_value, parent_die)
3593 register enum dwarf_tag tag_value;
3594 register dw_die_ref parent_die;
3596 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
3598 die->die_tag = tag_value;
3599 die->die_abbrev = 0;
3600 die->die_offset = 0;
3601 die->die_child = NULL;
3602 die->die_parent = NULL;
3603 die->die_sib = NULL;
3604 die->die_child_last = NULL;
3605 die->die_attr = NULL;
3606 die->die_attr_last = NULL;
3608 if (parent_die != NULL)
3609 add_child_die (parent_die, die);
3616 /* Return the DIE associated with the given type specifier. */
3618 static inline dw_die_ref
3619 lookup_type_die (type)
3622 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
3625 /* Equate a DIE to a given type specifier. */
3628 equate_type_number_to_die (type, type_die)
3630 register dw_die_ref type_die;
3632 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
3635 /* Return the DIE associated with a given declaration. */
3637 static inline dw_die_ref
3638 lookup_decl_die (decl)
3641 register unsigned decl_id = DECL_UID (decl);
3643 return (decl_id < decl_die_table_in_use
3644 ? decl_die_table[decl_id] : NULL);
3647 /* Equate a DIE to a particular declaration. */
3650 equate_decl_number_to_die (decl, decl_die)
3652 register dw_die_ref decl_die;
3654 register unsigned decl_id = DECL_UID (decl);
3655 register unsigned i;
3656 register unsigned num_allocated;
3658 if (decl_id >= decl_die_table_allocated)
3661 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
3662 / DECL_DIE_TABLE_INCREMENT)
3663 * DECL_DIE_TABLE_INCREMENT;
3666 = (dw_die_ref *) xrealloc (decl_die_table,
3667 sizeof (dw_die_ref) * num_allocated);
3669 bzero ((char *) &decl_die_table[decl_die_table_allocated],
3670 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
3671 decl_die_table_allocated = num_allocated;
3674 if (decl_id >= decl_die_table_in_use)
3675 decl_die_table_in_use = (decl_id + 1);
3677 decl_die_table[decl_id] = decl_die;
3680 /* Return a pointer to a newly allocated location description. Location
3681 descriptions are simple expression terms that can be strung
3682 together to form more complicated location (address) descriptions. */
3684 static inline dw_loc_descr_ref
3685 new_loc_descr (op, oprnd1, oprnd2)
3686 register enum dwarf_location_atom op;
3687 register unsigned long oprnd1;
3688 register unsigned long oprnd2;
3690 register dw_loc_descr_ref descr
3691 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
3693 descr->dw_loc_next = NULL;
3694 descr->dw_loc_opc = op;
3695 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3696 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3697 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3698 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3703 /* Add a location description term to a location description expression. */
3706 add_loc_descr (list_head, descr)
3707 register dw_loc_descr_ref *list_head;
3708 register dw_loc_descr_ref descr;
3710 register dw_loc_descr_ref *d;
3712 /* Find the end of the chain. */
3713 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3719 /* Keep track of the number of spaces used to indent the
3720 output of the debugging routines that print the structure of
3721 the DIE internal representation. */
3722 static int print_indent;
3724 /* Indent the line the number of spaces given by print_indent. */
3727 print_spaces (outfile)
3730 fprintf (outfile, "%*s", print_indent, "");
3733 /* Print the information assoaciated with a given DIE, and its children.
3734 This routine is a debugging aid only. */
3737 print_die (die, outfile)
3741 register dw_attr_ref a;
3742 register dw_die_ref c;
3744 print_spaces (outfile);
3745 fprintf (outfile, "DIE %4u: %s\n",
3746 die->die_offset, dwarf_tag_name (die->die_tag));
3747 print_spaces (outfile);
3748 fprintf (outfile, " abbrev id: %u", die->die_abbrev);
3749 fprintf (outfile, " offset: %u\n", die->die_offset);
3751 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3753 print_spaces (outfile);
3754 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
3756 switch (a->dw_attr_val.val_class)
3758 case dw_val_class_addr:
3759 fprintf (outfile, "address");
3761 case dw_val_class_loc:
3762 fprintf (outfile, "location descriptor");
3764 case dw_val_class_const:
3765 fprintf (outfile, "%d", a->dw_attr_val.v.val_int);
3767 case dw_val_class_unsigned_const:
3768 fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned);
3770 case dw_val_class_long_long:
3771 fprintf (outfile, "constant (%u,%u)",
3772 a->dw_attr_val.v.val_long_long.hi,
3773 a->dw_attr_val.v.val_long_long.low);
3775 case dw_val_class_float:
3776 fprintf (outfile, "floating-point constant");
3778 case dw_val_class_flag:
3779 fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
3781 case dw_val_class_die_ref:
3782 if (a->dw_attr_val.v.val_die_ref != NULL)
3783 fprintf (outfile, "die -> %u",
3784 a->dw_attr_val.v.val_die_ref->die_offset);
3786 fprintf (outfile, "die -> <null>");
3788 case dw_val_class_lbl_id:
3789 fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
3791 case dw_val_class_section_offset:
3792 fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section);
3794 case dw_val_class_str:
3795 if (a->dw_attr_val.v.val_str != NULL)
3796 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
3798 fprintf (outfile, "<null>");
3802 fprintf (outfile, "\n");
3805 if (die->die_child != NULL)
3808 for (c = die->die_child; c != NULL; c = c->die_sib)
3809 print_die (c, outfile);
3815 /* Print the contents of the source code line number correspondence table.
3816 This routine is a debugging aid only. */
3819 print_dwarf_line_table (outfile)
3822 register unsigned i;
3823 register dw_line_info_ref line_info;
3825 fprintf (outfile, "\n\nDWARF source line information\n");
3826 for (i = 1; i < line_info_table_in_use; ++i)
3828 line_info = &line_info_table[i];
3829 fprintf (outfile, "%5d: ", i);
3830 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
3831 fprintf (outfile, "%6d", line_info->dw_line_num);
3832 fprintf (outfile, "\n");
3835 fprintf (outfile, "\n\n");
3838 /* Print the information collected for a given DIE. */
3841 debug_dwarf_die (die)
3844 print_die (die, stderr);
3847 /* Print all DWARF information collected for the compilation unit.
3848 This routine is a debugging aid only. */
3854 print_die (comp_unit_die, stderr);
3855 print_dwarf_line_table (stderr);
3858 /* Traverse the DIE, and add a sibling attribute if it may have the
3859 effect of speeding up access to siblings. To save some space,
3860 avoid generating sibling attributes for DIE's without children. */
3863 add_sibling_attributes(die)
3864 register dw_die_ref die;
3866 register dw_die_ref c;
3867 register dw_attr_ref attr;
3868 if (die != comp_unit_die && die->die_child != NULL)
3870 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3871 attr->dw_attr_next = NULL;
3872 attr->dw_attr = DW_AT_sibling;
3873 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3874 attr->dw_attr_val.v.val_die_ref = die->die_sib;
3876 /* Add the sibling link to the front of the attribute list. */
3877 attr->dw_attr_next = die->die_attr;
3878 if (die->die_attr == NULL)
3879 die->die_attr_last = attr;
3881 die->die_attr = attr;
3884 for (c = die->die_child; c != NULL; c = c->die_sib)
3885 add_sibling_attributes (c);
3888 /* The format of each DIE (and its attribute value pairs)
3889 is encoded in an abbreviation table. This routine builds the
3890 abbreviation table and assigns a unique abbreviation id for
3891 each abbreviation entry. The children of each die are visited
3895 build_abbrev_table (die)
3896 register dw_die_ref die;
3898 register unsigned long abbrev_id;
3899 register unsigned long n_alloc;
3900 register dw_die_ref c;
3901 register dw_attr_ref d_attr, a_attr;
3902 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
3904 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
3906 if (abbrev->die_tag == die->die_tag)
3908 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
3910 a_attr = abbrev->die_attr;
3911 d_attr = die->die_attr;
3913 while (a_attr != NULL && d_attr != NULL)
3915 if ((a_attr->dw_attr != d_attr->dw_attr)
3916 || (value_format (&a_attr->dw_attr_val)
3917 != value_format (&d_attr->dw_attr_val)))
3920 a_attr = a_attr->dw_attr_next;
3921 d_attr = d_attr->dw_attr_next;
3924 if (a_attr == NULL && d_attr == NULL)
3930 if (abbrev_id >= abbrev_die_table_in_use)
3932 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
3934 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
3936 = (dw_die_ref *) xmalloc (abbrev_die_table,
3937 sizeof (dw_die_ref) * n_alloc);
3939 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
3940 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
3941 abbrev_die_table_allocated = n_alloc;
3944 ++abbrev_die_table_in_use;
3945 abbrev_die_table[abbrev_id] = die;
3948 die->die_abbrev = abbrev_id;
3949 for (c = die->die_child; c != NULL; c = c->die_sib)
3950 build_abbrev_table (c);
3953 /* Return the size of a string, including the null byte. */
3955 static unsigned long
3956 size_of_string (str)
3959 register unsigned long size = 0;
3960 register unsigned long slen = strlen (str);
3961 register unsigned long i;
3962 register unsigned c;
3964 for (i = 0; i < slen; ++i)
3973 /* Null terminator. */
3978 /* Return the size of a location descriptor. */
3980 static unsigned long
3981 size_of_loc_descr (loc)
3982 register dw_loc_descr_ref loc;
3984 register unsigned long size = 1;
3986 switch (loc->dw_loc_opc)
4008 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4011 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4016 case DW_OP_plus_uconst:
4017 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4055 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4058 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4061 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4064 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4065 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4068 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4070 case DW_OP_deref_size:
4071 case DW_OP_xderef_size:
4081 /* Return the size of a series of location descriptors. */
4083 static unsigned long
4085 register dw_loc_descr_ref loc;
4087 register unsigned long size = 0;
4089 for (; loc != NULL; loc = loc->dw_loc_next)
4090 size += size_of_loc_descr (loc);
4095 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4098 constant_size (value)
4099 long unsigned value;
4106 log = floor_log2 (value);
4109 log = 1 << (floor_log2 (log) + 1);
4114 /* Return the size of a DIE, as it is represented in the
4115 .debug_info section. */
4117 static unsigned long
4119 register dw_die_ref die;
4121 register unsigned long size = 0;
4122 register dw_attr_ref a;
4124 size += size_of_uleb128 (die->die_abbrev);
4125 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4127 switch (a->dw_attr_val.val_class)
4129 case dw_val_class_addr:
4132 case dw_val_class_loc:
4134 register unsigned long lsize
4135 = size_of_locs (a->dw_attr_val.v.val_loc);
4138 size += constant_size (lsize);
4142 case dw_val_class_const:
4145 case dw_val_class_unsigned_const:
4146 size += constant_size (a->dw_attr_val.v.val_unsigned);
4148 case dw_val_class_long_long:
4149 size += 1 + 8; /* block */
4151 case dw_val_class_float:
4152 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
4154 case dw_val_class_flag:
4157 case dw_val_class_die_ref:
4158 size += DWARF_OFFSET_SIZE;
4160 case dw_val_class_fde_ref:
4161 size += DWARF_OFFSET_SIZE;
4163 case dw_val_class_lbl_id:
4166 case dw_val_class_section_offset:
4167 size += DWARF_OFFSET_SIZE;
4169 case dw_val_class_str:
4170 size += size_of_string (a->dw_attr_val.v.val_str);
4180 /* Size the debgging information associted with a given DIE.
4181 Visits the DIE's children recursively. Updates the global
4182 variable next_die_offset, on each time through. Uses the
4183 current value of next_die_offset to updete the die_offset
4184 field in each DIE. */
4187 calc_die_sizes (die)
4190 register dw_die_ref c;
4191 die->die_offset = next_die_offset;
4192 next_die_offset += size_of_die (die);
4194 for (c = die->die_child; c != NULL; c = c->die_sib)
4197 if (die->die_child != NULL)
4198 /* Count the null byte used to terminate sibling lists. */
4199 next_die_offset += 1;
4202 /* Return the size of the line information prolog generated for the
4203 compilation unit. */
4205 static unsigned long
4206 size_of_line_prolog ()
4208 register unsigned long size;
4209 register unsigned long ft_index;
4211 size = DWARF_LINE_PROLOG_HEADER_SIZE;
4213 /* Count the size of the table giving number of args for each
4215 size += DWARF_LINE_OPCODE_BASE - 1;
4217 /* Include directory table is empty (at present). Count only the
4218 the null byte used to terminate the table. */
4221 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4223 /* File name entry. */
4224 size += size_of_string (file_table[ft_index]);
4226 /* Include directory index. */
4227 size += size_of_uleb128 (0);
4229 /* Modification time. */
4230 size += size_of_uleb128 (0);
4232 /* File length in bytes. */
4233 size += size_of_uleb128 (0);
4236 /* Count the file table terminator. */
4241 /* Return the size of the line information generated for this
4242 compilation unit. */
4244 static unsigned long
4245 size_of_line_info ()
4247 register unsigned long size;
4248 register unsigned long lt_index;
4249 register unsigned long current_line;
4250 register long line_offset;
4251 register long line_delta;
4252 register unsigned long current_file;
4253 register unsigned long function;
4255 /* Version number. */
4258 /* Prolog length specifier. */
4259 size += DWARF_OFFSET_SIZE;
4262 size += size_of_line_prolog ();
4264 /* Set address register instruction. */
4265 size += 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
4269 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
4271 register dw_line_info_ref line_info;
4273 /* Advance pc instruction. */
4275 line_info = &line_info_table[lt_index];
4276 if (line_info->dw_file_num != current_file)
4278 /* Set file number instruction. */
4280 current_file = line_info->dw_file_num;
4281 size += size_of_uleb128 (current_file);
4284 if (line_info->dw_line_num != current_line)
4286 line_offset = line_info->dw_line_num - current_line;
4287 line_delta = line_offset - DWARF_LINE_BASE;
4288 current_line = line_info->dw_line_num;
4289 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4290 /* 1-byte special line number instruction. */
4294 /* Advance line instruction. */
4296 size += size_of_sleb128 (line_offset);
4297 /* Generate line entry instruction. */
4303 /* Advance pc instruction. */
4306 /* End of line number info. marker. */
4307 size += 1 + size_of_uleb128 (1) + 1;
4312 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
4314 register dw_separate_line_info_ref line_info
4315 = &separate_line_info_table[lt_index];
4316 if (function != line_info->function)
4318 function = line_info->function;
4319 /* Set address register instruction. */
4320 size += 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
4323 /* Advance pc instruction. */
4326 if (line_info->dw_file_num != current_file)
4328 /* Set file number instruction. */
4330 current_file = line_info->dw_file_num;
4331 size += size_of_uleb128 (current_file);
4334 if (line_info->dw_line_num != current_line)
4336 line_offset = line_info->dw_line_num - current_line;
4337 line_delta = line_offset - DWARF_LINE_BASE;
4338 current_line = line_info->dw_line_num;
4339 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4340 /* 1-byte special line number instruction. */
4344 /* Advance line instruction. */
4346 size += size_of_sleb128 (line_offset);
4348 /* Generate line entry instruction. */
4355 /* If we're done with a function, end its sequence. */
4356 if (lt_index == separate_line_info_table_in_use
4357 || separate_line_info_table[lt_index].function != function)
4362 /* Advance pc instruction. */
4365 /* End of line number info. marker. */
4366 size += 1 + size_of_uleb128 (1) + 1;
4373 /* Return the size of the .debug_pubnames table generated for the
4374 compilation unit. */
4376 static unsigned long
4379 register unsigned long size;
4380 register unsigned i;
4382 size = DWARF_PUBNAMES_HEADER_SIZE;
4383 for (i = 0; i < pubname_table_in_use; ++i)
4385 register pubname_ref p = &pubname_table[i];
4386 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
4389 size += DWARF_OFFSET_SIZE;
4393 /* Return the size of the information in the .debug_aranges seciton. */
4395 static unsigned long
4398 register unsigned long size;
4400 size = DWARF_ARANGES_HEADER_SIZE;
4402 /* Count the address/length pair for this compilation unit. */
4403 size += 2 * PTR_SIZE;
4404 size += 2 * PTR_SIZE * arange_table_in_use;
4406 /* Count the two zero words used to terminated the address range table. */
4407 size += 2 * PTR_SIZE;
4411 /* Select the encoding of an attribute value. */
4413 static enum dwarf_form
4417 switch (v->val_class)
4419 case dw_val_class_addr:
4420 return DW_FORM_addr;
4421 case dw_val_class_loc:
4422 switch (constant_size (size_of_locs (v->v.val_loc)))
4425 return DW_FORM_block1;
4427 return DW_FORM_block2;
4431 case dw_val_class_const:
4432 return DW_FORM_data4;
4433 case dw_val_class_unsigned_const:
4434 switch (constant_size (v->v.val_unsigned))
4437 return DW_FORM_data1;
4439 return DW_FORM_data2;
4441 return DW_FORM_data4;
4443 return DW_FORM_data8;
4447 case dw_val_class_long_long:
4448 return DW_FORM_block1;
4449 case dw_val_class_float:
4450 return DW_FORM_block1;
4451 case dw_val_class_flag:
4452 return DW_FORM_flag;
4453 case dw_val_class_die_ref:
4455 case dw_val_class_fde_ref:
4456 return DW_FORM_data;
4457 case dw_val_class_lbl_id:
4458 return DW_FORM_addr;
4459 case dw_val_class_section_offset:
4460 return DW_FORM_data;
4461 case dw_val_class_str:
4462 return DW_FORM_string;
4468 /* Output the encoding of an attribute value. */
4471 output_value_format (v)
4474 enum dwarf_form form = value_format (v);
4476 output_uleb128 (form);
4477 if (flag_verbose_asm)
4478 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
4480 fputc ('\n', asm_out_file);
4483 /* Output the .debug_abbrev section which defines the DIE abbreviation
4487 output_abbrev_section ()
4489 unsigned long abbrev_id;
4492 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4494 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4496 output_uleb128 (abbrev_id);
4497 if (flag_verbose_asm)
4498 fprintf (asm_out_file, " (abbrev code)");
4500 fputc ('\n', asm_out_file);
4501 output_uleb128 (abbrev->die_tag);
4502 if (flag_verbose_asm)
4503 fprintf (asm_out_file, " (TAG: %s)",
4504 dwarf_tag_name (abbrev->die_tag));
4506 fputc ('\n', asm_out_file);
4507 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
4508 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
4510 if (flag_verbose_asm)
4511 fprintf (asm_out_file, "\t%s %s",
4513 (abbrev->die_child != NULL
4514 ? "DW_children_yes" : "DW_children_no"));
4516 fputc ('\n', asm_out_file);
4518 for (a_attr = abbrev->die_attr; a_attr != NULL;
4519 a_attr = a_attr->dw_attr_next)
4521 output_uleb128 (a_attr->dw_attr);
4522 if (flag_verbose_asm)
4523 fprintf (asm_out_file, " (%s)",
4524 dwarf_attr_name (a_attr->dw_attr));
4526 fputc ('\n', asm_out_file);
4527 output_value_format (&a_attr->dw_attr_val);
4530 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
4534 /* Output location description stack opcode's operands (if any). */
4537 output_loc_operands (loc)
4538 register dw_loc_descr_ref loc;
4540 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
4541 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
4543 switch (loc->dw_loc_opc)
4546 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
4547 fputc ('\n', asm_out_file);
4551 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4552 fputc ('\n', asm_out_file);
4556 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4557 fputc ('\n', asm_out_file);
4561 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
4562 fputc ('\n', asm_out_file);
4567 fputc ('\n', asm_out_file);
4570 output_uleb128 (val1->v.val_unsigned);
4571 fputc ('\n', asm_out_file);
4574 output_sleb128 (val1->v.val_int);
4575 fputc ('\n', asm_out_file);
4578 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
4579 fputc ('\n', asm_out_file);
4581 case DW_OP_plus_uconst:
4582 output_uleb128 (val1->v.val_unsigned);
4583 fputc ('\n', asm_out_file);
4587 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4588 fputc ('\n', asm_out_file);
4622 output_sleb128 (val1->v.val_int);
4623 fputc ('\n', asm_out_file);
4626 output_uleb128 (val1->v.val_unsigned);
4627 fputc ('\n', asm_out_file);
4630 output_sleb128 (val1->v.val_int);
4631 fputc ('\n', asm_out_file);
4634 output_uleb128 (val1->v.val_unsigned);
4635 fputc ('\n', asm_out_file);
4636 output_sleb128 (val2->v.val_int);
4637 fputc ('\n', asm_out_file);
4640 output_uleb128 (val1->v.val_unsigned);
4641 fputc ('\n', asm_out_file);
4643 case DW_OP_deref_size:
4644 case DW_OP_xderef_size:
4645 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4646 fputc ('\n', asm_out_file);
4653 /* Compute the offset of a sibling. */
4655 static unsigned long
4656 sibling_offset (die)
4659 unsigned long offset;
4661 if (die->die_child_last == NULL)
4662 offset = die->die_offset + size_of_die (die);
4664 offset = sibling_offset (die->die_child_last) + 1;
4669 /* Output the DIE and its attributes. Called recursively to generate
4670 the definitions of each child DIE. */
4674 register dw_die_ref die;
4676 register dw_attr_ref a;
4677 register dw_die_ref c;
4678 register unsigned long ref_offset;
4679 register unsigned long size;
4680 register dw_loc_descr_ref loc;
4683 output_uleb128 (die->die_abbrev);
4684 if (flag_verbose_asm)
4685 fprintf (asm_out_file, " (DIE (0x%x) %s)",
4686 die->die_offset, dwarf_tag_name (die->die_tag));
4688 fputc ('\n', asm_out_file);
4690 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4692 switch (a->dw_attr_val.val_class)
4694 case dw_val_class_addr:
4695 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
4696 a->dw_attr_val.v.val_addr);
4699 case dw_val_class_loc:
4700 size = size_of_locs (a->dw_attr_val.v.val_loc);
4702 /* Output the block length for this list of location operations. */
4703 switch (constant_size (size))
4706 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
4709 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
4715 if (flag_verbose_asm)
4716 fprintf (asm_out_file, "\t%s %s",
4717 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
4719 fputc ('\n', asm_out_file);
4720 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
4721 loc = loc->dw_loc_next)
4723 /* Output the opcode. */
4724 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
4725 if (flag_verbose_asm)
4726 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
4727 dwarf_stack_op_name (loc->dw_loc_opc));
4729 fputc ('\n', asm_out_file);
4731 /* Output the operand(s) (if any). */
4732 output_loc_operands (loc);
4736 case dw_val_class_const:
4737 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
4740 case dw_val_class_unsigned_const:
4741 switch (constant_size (a->dw_attr_val.v.val_unsigned))
4744 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4745 a->dw_attr_val.v.val_unsigned);
4748 ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
4749 a->dw_attr_val.v.val_unsigned);
4752 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
4753 a->dw_attr_val.v.val_unsigned);
4756 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
4757 a->dw_attr_val.v.val_long_long.hi,
4758 a->dw_attr_val.v.val_long_long.low);
4765 case dw_val_class_long_long:
4766 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
4767 if (flag_verbose_asm)
4768 fprintf (asm_out_file, "\t%s %s",
4769 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
4771 fputc ('\n', asm_out_file);
4772 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
4773 a->dw_attr_val.v.val_long_long.hi,
4774 a->dw_attr_val.v.val_long_long.low);
4776 if (flag_verbose_asm)
4777 fprintf (asm_out_file,
4778 "\t%s long long constant", ASM_COMMENT_START);
4780 fputc ('\n', asm_out_file);
4783 case dw_val_class_float:
4784 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4785 a->dw_attr_val.v.val_float.length * 4);
4786 if (flag_verbose_asm)
4787 fprintf (asm_out_file, "\t%s %s",
4788 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
4790 fputc ('\n', asm_out_file);
4791 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
4793 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
4794 a->dw_attr_val.v.val_float.array[i]);
4795 if (flag_verbose_asm)
4796 fprintf (asm_out_file, "\t%s fp constant word %d",
4797 ASM_COMMENT_START, i);
4799 fputc ('\n', asm_out_file);
4803 case dw_val_class_flag:
4804 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
4807 case dw_val_class_die_ref:
4808 if (a->dw_attr_val.v.val_die_ref != NULL)
4809 ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
4810 else if (a->dw_attr == DW_AT_sibling)
4811 ref_offset = sibling_offset(die);
4815 ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
4818 case dw_val_class_fde_ref:
4819 ref_offset = fde_table[a->dw_attr_val.v.val_fde_index].dw_fde_offset;
4820 fprintf (asm_out_file, "\t%s\t%s+0x%x", UNALIGNED_OFFSET_ASM_OP,
4821 stripattributes (FRAME_SECTION), ref_offset);
4824 case dw_val_class_lbl_id:
4825 ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
4828 case dw_val_class_section_offset:
4829 ASM_OUTPUT_DWARF_OFFSET (asm_out_file,
4831 (a->dw_attr_val.v.val_section));
4834 case dw_val_class_str:
4835 ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
4842 if (a->dw_attr_val.val_class != dw_val_class_loc
4843 && a->dw_attr_val.val_class != dw_val_class_long_long
4844 && a->dw_attr_val.val_class != dw_val_class_float)
4846 if (flag_verbose_asm)
4847 fprintf (asm_out_file, "\t%s %s",
4848 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
4850 fputc ('\n', asm_out_file);
4854 for (c = die->die_child; c != NULL; c = c->die_sib)
4857 if (die->die_child != NULL)
4859 /* Add null byte to terminate sibling list. */
4860 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4861 if (flag_verbose_asm)
4862 fprintf (asm_out_file, "\t%s end of children of DIE 0x%x",
4863 ASM_COMMENT_START, die->die_offset);
4865 fputc ('\n', asm_out_file);
4869 /* Output the compilation unit that appears at the beginning of the
4870 .debug_info section, and precedes the DIE descriptions. */
4873 output_compilation_unit_header ()
4875 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
4876 if (flag_verbose_asm)
4877 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
4880 fputc ('\n', asm_out_file);
4881 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4882 if (flag_verbose_asm)
4883 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
4885 fputc ('\n', asm_out_file);
4886 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION));
4887 if (flag_verbose_asm)
4888 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
4891 fputc ('\n', asm_out_file);
4892 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
4893 if (flag_verbose_asm)
4894 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
4896 fputc ('\n', asm_out_file);
4899 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
4900 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
4901 argument list, and maybe the scope. */
4904 dwarf2_name (decl, scope)
4908 return (*decl_printable_name) (decl, scope ? 1 : 0);
4911 /* Add a new entry to .debug_pubnames if appropriate. */
4914 add_pubname (decl, die)
4920 if (! TREE_PUBLIC (decl))
4923 if (pubname_table_in_use == pubname_table_allocated)
4925 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
4926 pubname_table = (pubname_ref) xrealloc
4927 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
4930 p = &pubname_table[pubname_table_in_use++];
4933 p->name = xstrdup (dwarf2_name (decl, 1));
4936 /* Output the public names table used to speed up access to externally
4937 visible names. For now, only generate entries for externally
4938 visible procedures. */
4943 register unsigned i;
4944 register unsigned long pubnames_length = size_of_pubnames ();
4946 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
4948 if (flag_verbose_asm)
4949 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
4952 fputc ('\n', asm_out_file);
4953 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4955 if (flag_verbose_asm)
4956 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
4958 fputc ('\n', asm_out_file);
4959 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
4960 if (flag_verbose_asm)
4961 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
4964 fputc ('\n', asm_out_file);
4965 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
4966 if (flag_verbose_asm)
4967 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
4969 fputc ('\n', asm_out_file);
4970 for (i = 0; i < pubname_table_in_use; ++i)
4972 register pubname_ref pub = &pubname_table[i];
4974 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
4975 if (flag_verbose_asm)
4976 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
4978 fputc ('\n', asm_out_file);
4980 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
4981 if (flag_verbose_asm)
4982 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
4984 fputc ('\n', asm_out_file);
4987 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
4988 fputc ('\n', asm_out_file);
4991 /* Add a new entry to .debug_aranges if appropriate. */
4994 add_arange (decl, die)
4998 if (! DECL_SECTION_NAME (decl))
5001 if (arange_table_in_use == arange_table_allocated)
5003 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5005 = (arange_ref) xrealloc (arange_table,
5006 arange_table_allocated * sizeof (dw_die_ref));
5009 arange_table[arange_table_in_use++] = die;
5012 /* Output the information that goes into the .debug_aranges table.
5013 Namely, define the beginning and ending address range of the
5014 text section generated for this compilation unit. */
5019 register unsigned i;
5020 register unsigned long aranges_length = size_of_aranges ();
5022 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
5023 if (flag_verbose_asm)
5024 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
5027 fputc ('\n', asm_out_file);
5028 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5029 if (flag_verbose_asm)
5030 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5032 fputc ('\n', asm_out_file);
5033 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
5034 if (flag_verbose_asm)
5035 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5038 fputc ('\n', asm_out_file);
5039 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5040 if (flag_verbose_asm)
5041 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
5043 fputc ('\n', asm_out_file);
5044 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5045 if (flag_verbose_asm)
5046 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
5049 fputc ('\n', asm_out_file);
5050 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
5052 fprintf (asm_out_file, ",0,0");
5054 if (flag_verbose_asm)
5055 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5056 ASM_COMMENT_START, 2 * PTR_SIZE);
5058 fputc ('\n', asm_out_file);
5059 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
5060 if (flag_verbose_asm)
5061 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5063 fputc ('\n', asm_out_file);
5064 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label, TEXT_SECTION);
5065 if (flag_verbose_asm)
5066 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5068 fputc ('\n', asm_out_file);
5069 for (i = 0; i < arange_table_in_use; ++i)
5071 dw_die_ref a = arange_table[i];
5073 if (a->die_tag == DW_TAG_subprogram)
5074 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a));
5077 char *name = get_AT_string (a, DW_AT_MIPS_linkage_name);
5079 name = get_AT_string (a, DW_AT_name);
5081 ASM_OUTPUT_DWARF_ADDR (asm_out_file, name);
5084 if (flag_verbose_asm)
5085 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5087 fputc ('\n', asm_out_file);
5088 if (a->die_tag == DW_TAG_subprogram)
5089 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a),
5092 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5093 get_AT_unsigned (a, DW_AT_byte_size));
5095 if (flag_verbose_asm)
5096 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5098 fputc ('\n', asm_out_file);
5101 /* Output the terminator words. */
5102 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5103 fputc ('\n', asm_out_file);
5104 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5105 fputc ('\n', asm_out_file);
5108 /* Output the source line number correspondence information. This
5109 information goes into the .debug_line section. */
5114 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5115 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5116 register unsigned opc;
5117 register unsigned n_op_args;
5118 register unsigned long ft_index;
5119 register unsigned long lt_index;
5120 register unsigned long current_line;
5121 register long line_offset;
5122 register long line_delta;
5123 register unsigned long current_file;
5124 register unsigned long function;
5126 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ());
5127 if (flag_verbose_asm)
5128 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5131 fputc ('\n', asm_out_file);
5132 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5133 if (flag_verbose_asm)
5134 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5136 fputc ('\n', asm_out_file);
5137 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
5138 if (flag_verbose_asm)
5139 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5141 fputc ('\n', asm_out_file);
5142 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
5143 if (flag_verbose_asm)
5144 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5147 fputc ('\n', asm_out_file);
5148 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
5149 if (flag_verbose_asm)
5150 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5153 fputc ('\n', asm_out_file);
5154 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
5155 if (flag_verbose_asm)
5156 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5159 fputc ('\n', asm_out_file);
5160 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
5161 if (flag_verbose_asm)
5162 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5165 fputc ('\n', asm_out_file);
5166 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5167 if (flag_verbose_asm)
5168 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5170 fputc ('\n', asm_out_file);
5171 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5175 case DW_LNS_advance_pc:
5176 case DW_LNS_advance_line:
5177 case DW_LNS_set_file:
5178 case DW_LNS_set_column:
5179 case DW_LNS_fixed_advance_pc:
5186 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5187 if (flag_verbose_asm)
5188 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5189 ASM_COMMENT_START, opc, n_op_args);
5190 fputc ('\n', asm_out_file);
5193 if (flag_verbose_asm)
5194 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5196 /* Include directory table is empty, at present */
5197 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5198 fputc ('\n', asm_out_file);
5199 if (flag_verbose_asm)
5200 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5202 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5204 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5205 if (flag_verbose_asm)
5206 fprintf (asm_out_file, "%s File Entry: 0x%x",
5207 ASM_COMMENT_START, ft_index);
5209 fputc ('\n', asm_out_file);
5211 /* Include directory index */
5213 fputc ('\n', asm_out_file);
5215 /* Modification time */
5217 fputc ('\n', asm_out_file);
5219 /* File length in bytes */
5221 fputc ('\n', asm_out_file);
5224 /* Terminate the file name table */
5225 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5226 fputc ('\n', asm_out_file);
5228 /* Set the address register to the first location in the text section */
5229 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5230 if (flag_verbose_asm)
5231 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5233 fputc ('\n', asm_out_file);
5234 output_uleb128 (1 + PTR_SIZE);
5235 fputc ('\n', asm_out_file);
5236 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5237 fputc ('\n', asm_out_file);
5238 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
5239 fputc ('\n', asm_out_file);
5241 /* Generate the line number to PC correspondence table, encoded as
5242 a series of state machine operations. */
5245 strcpy (prev_line_label, TEXT_SECTION);
5246 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5248 register dw_line_info_ref line_info;
5250 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5251 if (flag_verbose_asm)
5252 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5255 fputc ('\n', asm_out_file);
5256 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5257 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5258 fputc ('\n', asm_out_file);
5259 line_info = &line_info_table[lt_index];
5260 if (line_info->dw_file_num != current_file)
5262 current_file = line_info->dw_file_num;
5263 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5264 if (flag_verbose_asm)
5265 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5267 fputc ('\n', asm_out_file);
5268 output_uleb128 (current_file);
5269 if (flag_verbose_asm)
5270 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5272 fputc ('\n', asm_out_file);
5275 line_offset = line_info->dw_line_num - current_line;
5276 line_delta = line_offset - DWARF_LINE_BASE;
5277 current_line = line_info->dw_line_num;
5278 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5280 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5281 DWARF_LINE_OPCODE_BASE + line_delta);
5282 if (flag_verbose_asm)
5283 fprintf (asm_out_file,
5284 "\t%s line %d", ASM_COMMENT_START, current_line);
5286 fputc ('\n', asm_out_file);
5290 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5291 if (flag_verbose_asm)
5292 fprintf (asm_out_file, "\t%s advance to line %d",
5293 ASM_COMMENT_START, current_line);
5295 fputc ('\n', asm_out_file);
5296 output_sleb128 (line_offset);
5297 fputc ('\n', asm_out_file);
5298 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5299 fputc ('\n', asm_out_file);
5302 strcpy (prev_line_label, line_label);
5305 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5306 if (flag_verbose_asm)
5307 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", ASM_COMMENT_START);
5309 fputc ('\n', asm_out_file);
5310 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
5311 fputc ('\n', asm_out_file);
5313 /* Output the marker for the end of the line number info. */
5314 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5315 if (flag_verbose_asm)
5316 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
5318 fputc ('\n', asm_out_file);
5320 fputc ('\n', asm_out_file);
5321 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5322 fputc ('\n', asm_out_file);
5327 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5329 register dw_separate_line_info_ref line_info
5330 = &separate_line_info_table[lt_index];
5332 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
5334 if (function != line_info->function)
5336 function = line_info->function;
5338 /* Set the address register to the first line in the function */
5339 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5340 if (flag_verbose_asm)
5341 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5344 fputc ('\n', asm_out_file);
5345 output_uleb128 (1 + PTR_SIZE);
5346 fputc ('\n', asm_out_file);
5347 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5348 fputc ('\n', asm_out_file);
5349 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5350 fputc ('\n', asm_out_file);
5354 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5355 if (flag_verbose_asm)
5356 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5359 fputc ('\n', asm_out_file);
5360 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5361 fputc ('\n', asm_out_file);
5364 if (line_info->dw_file_num != current_file)
5366 current_file = line_info->dw_file_num;
5367 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5368 if (flag_verbose_asm)
5369 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5371 fputc ('\n', asm_out_file);
5372 output_uleb128 (current_file);
5373 if (flag_verbose_asm)
5374 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5376 fputc ('\n', asm_out_file);
5379 if (line_info->dw_line_num != current_line)
5381 line_offset = line_info->dw_line_num - current_line;
5382 line_delta = line_offset - DWARF_LINE_BASE;
5383 current_line = line_info->dw_line_num;
5384 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5386 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5387 DWARF_LINE_OPCODE_BASE + line_delta);
5388 if (flag_verbose_asm)
5389 fprintf (asm_out_file,
5390 "\t%s line %d", ASM_COMMENT_START, current_line);
5392 fputc ('\n', asm_out_file);
5396 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5397 if (flag_verbose_asm)
5398 fprintf (asm_out_file, "\t%s advance to line %d",
5399 ASM_COMMENT_START, current_line);
5401 fputc ('\n', asm_out_file);
5402 output_sleb128 (line_offset);
5403 fputc ('\n', asm_out_file);
5404 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5405 fputc ('\n', asm_out_file);
5410 strcpy (prev_line_label, line_label);
5412 /* If we're done with a function, end its sequence. */
5413 if (lt_index == separate_line_info_table_in_use
5414 || separate_line_info_table[lt_index].function != function)
5418 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5419 if (flag_verbose_asm)
5420 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5423 fputc ('\n', asm_out_file);
5424 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
5425 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5426 fputc ('\n', asm_out_file);
5428 /* Output the marker for the end of this sequence. */
5429 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5430 if (flag_verbose_asm)
5431 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
5434 fputc ('\n', asm_out_file);
5436 fputc ('\n', asm_out_file);
5437 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5438 fputc ('\n', asm_out_file);
5443 /* Given a pointer to a BLOCK node return non-zero if (and only if) the node
5444 in question represents the outermost pair of curly braces (i.e. the "body
5445 block") of a function or method.
5447 For any BLOCK node representing a "body block" of a function or method, the
5448 BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
5449 represents the outermost (function) scope for the function or method (i.e.
5450 the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
5451 *that* node in turn will point to the relevant FUNCTION_DECL node. */
5454 is_body_block (stmt)
5457 if (TREE_CODE (stmt) == BLOCK)
5459 register tree parent = BLOCK_SUPERCONTEXT (stmt);
5461 if (TREE_CODE (parent) == BLOCK)
5463 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
5465 if (TREE_CODE (grandparent) == FUNCTION_DECL)
5473 /* Given a pointer to a tree node for some base type, return a pointer to
5474 a DIE that describes the given type.
5476 This routine must only be called for GCC type nodes that correspond to
5477 Dwarf base (fundamental) types. */
5480 base_type_die (type)
5483 register dw_die_ref base_type_result;
5484 register char *type_name;
5485 register enum dwarf_type encoding;
5486 register tree name = TYPE_NAME (type);
5488 if (TREE_CODE (type) == ERROR_MARK
5489 || TREE_CODE (type) == VOID_TYPE)
5492 if (TREE_CODE (name) == TYPE_DECL)
5493 name = DECL_NAME (name);
5494 type_name = IDENTIFIER_POINTER (name);
5496 switch (TREE_CODE (type))
5499 /* Carefully distinguish the C character types, without messing
5500 up if the language is not C. Note that we check only for the names
5501 that contain spaces; other names might occur by coincidence in other
5503 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
5504 && (type == char_type_node
5505 || ! strcmp (type_name, "signed char")
5506 || ! strcmp (type_name, "unsigned char"))))
5508 if (TREE_UNSIGNED (type))
5509 encoding = DW_ATE_unsigned;
5511 encoding = DW_ATE_signed;
5514 /* else fall through */
5517 /* GNU Pascal/Ada CHAR type. Not used in C. */
5518 if (TREE_UNSIGNED (type))
5519 encoding = DW_ATE_unsigned_char;
5521 encoding = DW_ATE_signed_char;
5525 encoding = DW_ATE_float;
5529 encoding = DW_ATE_complex_float;
5533 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
5534 encoding = DW_ATE_boolean;
5538 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
5541 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
5542 add_AT_string (base_type_result, DW_AT_name, type_name);
5543 add_AT_unsigned (base_type_result, DW_AT_byte_size,
5544 TYPE_PRECISION (type) / BITS_PER_UNIT);
5545 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
5547 return base_type_result;
5550 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
5551 the Dwarf "root" type for the given input type. The Dwarf "root" type of
5552 a given type is generally the same as the given type, except that if the
5553 given type is a pointer or reference type, then the root type of the given
5554 type is the root type of the "basis" type for the pointer or reference
5555 type. (This definition of the "root" type is recursive.) Also, the root
5556 type of a `const' qualified type or a `volatile' qualified type is the
5557 root type of the given type without the qualifiers. */
5563 if (TREE_CODE (type) == ERROR_MARK)
5564 return error_mark_node;
5566 switch (TREE_CODE (type))
5569 return error_mark_node;
5572 case REFERENCE_TYPE:
5573 return type_main_variant (root_type (TREE_TYPE (type)));
5576 return type_main_variant (type);
5580 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
5581 given input type is a Dwarf "fundamental" type. Otherwise return null. */
5587 switch (TREE_CODE (type))
5602 case QUAL_UNION_TYPE:
5607 case REFERENCE_TYPE:
5620 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
5621 entry that chains various modifiers in front of the given type. */
5624 modified_type_die (type, is_const_type, is_volatile_type, context_die)
5626 register int is_const_type;
5627 register int is_volatile_type;
5628 register dw_die_ref context_die;
5630 register enum tree_code code = TREE_CODE (type);
5631 register dw_die_ref mod_type_die = NULL;
5632 register dw_die_ref sub_die = NULL;
5633 register tree item_type = NULL;
5635 if (code != ERROR_MARK)
5637 type = build_type_variant (type, is_const_type, is_volatile_type);
5639 mod_type_die = lookup_type_die (type);
5641 return mod_type_die;
5643 /* Handle C typedef types. */
5644 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
5645 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
5647 tree dtype = TREE_TYPE (TYPE_NAME (type));
5650 /* For a named type, use the typedef. */
5651 gen_type_die (type, context_die);
5652 mod_type_die = lookup_type_die (type);
5655 else if (is_const_type < TYPE_READONLY (dtype)
5656 || is_volatile_type < TYPE_VOLATILE (dtype))
5657 /* cv-unqualified version of named type. Just use the unnamed
5658 type to which it refers. */
5660 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
5661 is_const_type, is_volatile_type,
5663 /* Else cv-qualified version of named type; fall through. */
5668 else if (is_const_type)
5670 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
5671 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
5673 else if (is_volatile_type)
5675 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
5676 sub_die = modified_type_die (type, 0, 0, context_die);
5678 else if (code == POINTER_TYPE)
5680 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
5681 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
5683 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
5685 item_type = TREE_TYPE (type);
5687 else if (code == REFERENCE_TYPE)
5689 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
5690 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
5692 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
5694 item_type = TREE_TYPE (type);
5696 else if (is_base_type (type))
5697 mod_type_die = base_type_die (type);
5700 gen_type_die (type, context_die);
5702 /* We have to get the type_main_variant here (and pass that to the
5703 `lookup_type_die' routine) because the ..._TYPE node we have
5704 might simply be a *copy* of some original type node (where the
5705 copy was created to help us keep track of typedef names) and
5706 that copy might have a different TYPE_UID from the original
5708 mod_type_die = lookup_type_die (type_main_variant (type));
5709 assert (mod_type_die != NULL);
5713 equate_type_number_to_die (type, mod_type_die);
5715 /* We must do this after the equate_type_number_to_die call, in case
5716 this is a recursive type. This ensures that the modified_type_die
5717 recursion will terminate even if the type is recursive. Recursive
5718 types are possible in Ada. */
5719 sub_die = modified_type_die (item_type,
5720 TYPE_READONLY (item_type),
5721 TYPE_VOLATILE (item_type),
5724 if (sub_die != NULL)
5725 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
5727 return mod_type_die;
5730 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
5731 an enumerated type. */
5737 return TREE_CODE (type) == ENUMERAL_TYPE;
5740 /* Return a location descriptor that designates a machine register. */
5742 static dw_loc_descr_ref
5743 reg_loc_descriptor (rtl)
5746 register dw_loc_descr_ref loc_result = NULL;
5747 register unsigned reg = reg_number (rtl);
5749 if (reg >= 0 && reg <= 31)
5750 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
5752 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
5757 /* Return a location descriptor that designates a base+offset location. */
5759 static dw_loc_descr_ref
5760 based_loc_descr (reg, offset)
5764 register dw_loc_descr_ref loc_result;
5765 /* For the "frame base", we use the frame pointer or stack pointer
5766 registers, since the RTL for local variables is relative to one of
5768 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
5769 ? HARD_FRAME_POINTER_REGNUM
5770 : STACK_POINTER_REGNUM);
5773 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
5774 else if (reg >= 0 && reg <= 31)
5775 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
5777 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
5782 /* Return true if this RTL expression describes a base+offset calculation. */
5788 return (GET_CODE (rtl) == PLUS
5789 && ((GET_CODE (XEXP (rtl, 0)) == REG
5790 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
5793 /* The following routine converts the RTL for a variable or parameter
5794 (resident in memory) into an equivalent Dwarf representation of a
5795 mechanism for getting the address of that same variable onto the top of a
5796 hypothetical "address evaluation" stack.
5798 When creating memory location descriptors, we are effectively transforming
5799 the RTL for a memory-resident object into its Dwarf postfix expression
5800 equivalent. This routine recursively descends an RTL tree, turning
5801 it into Dwarf postfix code as it goes. */
5803 static dw_loc_descr_ref
5804 mem_loc_descriptor (rtl)
5807 dw_loc_descr_ref mem_loc_result = NULL;
5808 /* Note that for a dynamically sized array, the location we will generate a
5809 description of here will be the lowest numbered location which is
5810 actually within the array. That's *not* necessarily the same as the
5811 zeroth element of the array. */
5813 switch (GET_CODE (rtl))
5816 /* The case of a subreg may arise when we have a local (register)
5817 variable or a formal (register) parameter which doesn't quite fill
5818 up an entire register. For now, just assume that it is
5819 legitimate to make the Dwarf info refer to the whole register which
5820 contains the given subreg. */
5821 rtl = XEXP (rtl, 0);
5823 /* ... fall through ... */
5826 /* Whenever a register number forms a part of the description of the
5827 method for calculating the (dynamic) address of a memory resident
5828 object, DWARF rules require the register number be referred to as
5829 a "base register". This distinction is not based in any way upon
5830 what category of register the hardware believes the given register
5831 belongs to. This is strictly DWARF terminology we're dealing with
5832 here. Note that in cases where the location of a memory-resident
5833 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
5834 OP_CONST (0)) the actual DWARF location descriptor that we generate
5835 may just be OP_BASEREG (basereg). This may look deceptively like
5836 the object in question was allocated to a register (rather than in
5837 memory) so DWARF consumers need to be aware of the subtle
5838 distinction between OP_REG and OP_BASEREG. */
5839 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
5843 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0));
5844 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
5849 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
5850 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
5851 mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
5855 if (is_based_loc (rtl))
5856 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
5857 INTVAL (XEXP (rtl, 1)));
5860 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
5861 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
5862 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
5867 /* If a pseudo-reg is optimized away, it is possible for it to
5868 be replaced with a MEM containing a multiply. */
5869 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
5870 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
5871 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
5875 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
5882 return mem_loc_result;
5885 /* Output a proper Dwarf location descriptor for a variable or parameter
5886 which is either allocated in a register or in a memory location. For a
5887 register, we just generate an OP_REG and the register number. For a
5888 memory location we provide a Dwarf postfix expression describing how to
5889 generate the (dynamic) address of the object onto the address stack. */
5891 static dw_loc_descr_ref
5892 loc_descriptor (rtl)
5895 dw_loc_descr_ref loc_result = NULL;
5896 switch (GET_CODE (rtl))
5899 /* The case of a subreg may arise when we have a local (register)
5900 variable or a formal (register) parameter which doesn't quite fill
5901 up an entire register. For now, just assume that it is
5902 legitimate to make the Dwarf info refer to the whole register which
5903 contains the given subreg. */
5904 rtl = XEXP (rtl, 0);
5906 /* ... fall through ... */
5909 loc_result = reg_loc_descriptor (rtl);
5913 loc_result = mem_loc_descriptor (XEXP (rtl, 0));
5923 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
5924 which is not less than the value itself. */
5926 static inline unsigned
5927 ceiling (value, boundary)
5928 register unsigned value;
5929 register unsigned boundary;
5931 return (((value + boundary - 1) / boundary) * boundary);
5934 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
5935 pointer to the declared type for the relevant field variable, or return
5936 `integer_type_node' if the given node turns out to be an
5945 if (TREE_CODE (decl) == ERROR_MARK)
5946 return integer_type_node;
5948 type = DECL_BIT_FIELD_TYPE (decl);
5949 if (type == NULL_TREE)
5950 type = TREE_TYPE (decl);
5955 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5956 node, return the alignment in bits for the type, or else return
5957 BITS_PER_WORD if the node actually turns out to be an
5960 static inline unsigned
5961 simple_type_align_in_bits (type)
5964 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
5967 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5968 node, return the size in bits for the type if it is a constant, or else
5969 return the alignment for the type if the type's size is not constant, or
5970 else return BITS_PER_WORD if the type actually turns out to be an
5973 static inline unsigned
5974 simple_type_size_in_bits (type)
5977 if (TREE_CODE (type) == ERROR_MARK)
5978 return BITS_PER_WORD;
5981 register tree type_size_tree = TYPE_SIZE (type);
5983 if (TREE_CODE (type_size_tree) != INTEGER_CST)
5984 return TYPE_ALIGN (type);
5986 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
5990 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
5991 return the byte offset of the lowest addressed byte of the "containing
5992 object" for the given FIELD_DECL, or return 0 if we are unable to
5993 determine what that offset is, either because the argument turns out to
5994 be a pointer to an ERROR_MARK node, or because the offset is actually
5995 variable. (We can't handle the latter case just yet). */
5998 field_byte_offset (decl)
6001 register unsigned type_align_in_bytes;
6002 register unsigned type_align_in_bits;
6003 register unsigned type_size_in_bits;
6004 register unsigned object_offset_in_align_units;
6005 register unsigned object_offset_in_bits;
6006 register unsigned object_offset_in_bytes;
6008 register tree bitpos_tree;
6009 register tree field_size_tree;
6010 register unsigned bitpos_int;
6011 register unsigned deepest_bitpos;
6012 register unsigned field_size_in_bits;
6014 if (TREE_CODE (decl) == ERROR_MARK)
6017 if (TREE_CODE (decl) != FIELD_DECL)
6020 type = field_type (decl);
6022 bitpos_tree = DECL_FIELD_BITPOS (decl);
6023 field_size_tree = DECL_SIZE (decl);
6025 /* We cannot yet cope with fields whose positions or sizes are variable, so
6026 for now, when we see such things, we simply return 0. Someday, we may
6027 be able to handle such cases, but it will be damn difficult. */
6028 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6030 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6032 if (TREE_CODE (field_size_tree) != INTEGER_CST)
6035 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
6036 type_size_in_bits = simple_type_size_in_bits (type);
6037 type_align_in_bits = simple_type_align_in_bits (type);
6038 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6040 /* Note that the GCC front-end doesn't make any attempt to keep track of
6041 the starting bit offset (relative to the start of the containing
6042 structure type) of the hypothetical "containing object" for a bit-
6043 field. Thus, when computing the byte offset value for the start of the
6044 "containing object" of a bit-field, we must deduce this information on
6045 our own. This can be rather tricky to do in some cases. For example,
6046 handling the following structure type definition when compiling for an
6047 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6050 struct S { int field1; long long field2:31; };
6052 Fortunately, there is a simple rule-of-thumb which can be
6053 used in such cases. When compiling for an i386/i486, GCC will allocate
6054 8 bytes for the structure shown above. It decides to do this based upon
6055 one simple rule for bit-field allocation. Quite simply, GCC allocates
6056 each "containing object" for each bit-field at the first (i.e. lowest
6057 addressed) legitimate alignment boundary (based upon the required
6058 minimum alignment for the declared type of the field) which it can
6059 possibly use, subject to the condition that there is still enough
6060 available space remaining in the containing object (when allocated at
6061 the selected point) to fully accommodate all of the bits of the
6062 bit-field itself. This simple rule makes it obvious why GCC allocates
6063 8 bytes for each object of the structure type shown above. When looking
6064 for a place to allocate the "containing object" for `field2', the
6065 compiler simply tries to allocate a 64-bit "containing object" at each
6066 successive 32-bit boundary (starting at zero) until it finds a place to
6067 allocate that 64- bit field such that at least 31 contiguous (and
6068 previously unallocated) bits remain within that selected 64 bit field.
6069 (As it turns out, for the example above, the compiler finds that it is
6070 OK to allocate the "containing object" 64-bit field at bit-offset zero
6071 within the structure type.) Here we attempt to work backwards from the
6072 limited set of facts we're given, and we try to deduce from those facts,
6073 where GCC must have believed that the containing object started (within
6074 the structure type). The value we deduce is then used (by the callers of
6075 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6076 for fields (both bit-fields and, in the case of DW_AT_location, regular
6079 /* Figure out the bit-distance from the start of the structure to the
6080 "deepest" bit of the bit-field. */
6081 deepest_bitpos = bitpos_int + field_size_in_bits;
6083 /* This is the tricky part. Use some fancy footwork to deduce where the
6084 lowest addressed bit of the containing object must be. */
6085 object_offset_in_bits
6086 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6088 /* Compute the offset of the containing object in "alignment units". */
6089 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6091 /* Compute the offset of the containing object in bytes. */
6092 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6094 return object_offset_in_bytes;
6097 /* The following routines define various Dwarf attributes and any data
6098 associated with them. */
6101 /* Output the form of location attributes suitable for whole variables and
6102 whole parameters. Note that the location attributes for struct fields are
6103 generated by the routine `data_member_location_attribute' below. */
6106 add_location_attribute (die, rtl)
6110 dw_loc_descr_ref loc_descr = NULL;
6112 /* Handle a special case. If we are about to output a location descriptor
6113 for a variable or parameter which has been optimized out of existence,
6114 don't do that. Instead we output a null location descriptor value as
6115 part of the location attribute. A variable which has been optimized out
6116 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6117 Currently, in some rare cases, variables can have DECL_RTL values which
6118 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6119 elsewhere in the compiler. We treat such cases as if the variable(s) in
6120 question had been optimized out of existence. Note that in all cases
6121 where we wish to express the fact that a variable has been optimized out
6122 of existence, we do not simply suppress the generation of the entire
6123 location attribute because the absence of a location attribute in
6124 certain kinds of DIEs is used to indicate something else entirely...
6125 i.e. that the DIE represents an object declaration, but not a
6126 definition. So sayeth the PLSIG. */
6128 if (!is_pseudo_reg (rtl)
6129 && (GET_CODE (rtl) != MEM
6130 || !is_pseudo_reg (XEXP (rtl, 0))))
6131 loc_descr = loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX, 0));
6133 #ifdef MIPS_DEBUGGING_INFO
6134 /* ??? SGI's dwarf reader is buggy, and will not accept a zero size
6135 location descriptor. Lets just use r0 for now to represent a
6136 variable that has been optimized away. */
6137 if (loc_descr == NULL)
6138 loc_descr = loc_descriptor (gen_rtx (REG, word_mode, 0));
6141 add_AT_loc (die, DW_AT_location, loc_descr);
6144 /* Attach the specialized form of location attribute used for data
6145 members of struct and union types. In the special case of a
6146 FIELD_DECL node which represents a bit-field, the "offset" part
6147 of this special location descriptor must indicate the distance
6148 in bytes from the lowest-addressed byte of the containing struct
6149 or union type to the lowest-addressed byte of the "containing
6150 object" for the bit-field. (See the `field_byte_offset' function
6151 above).. For any given bit-field, the "containing object" is a
6152 hypothetical object (of some integral or enum type) within which
6153 the given bit-field lives. The type of this hypothetical
6154 "containing object" is always the same as the declared type of
6155 the individual bit-field itself (for GCC anyway... the DWARF
6156 spec doesn't actually mandate this). Note that it is the size
6157 (in bytes) of the hypothetical "containing object" which will
6158 be given in the DW_AT_byte_size attribute for this bit-field.
6159 (See the `byte_size_attribute' function below.) It is also used
6160 when calculating the value of the DW_AT_bit_offset attribute.
6161 (See the `bit_offset_attribute' function below). */
6164 add_data_member_location_attribute (die, decl)
6165 register dw_die_ref die;
6168 register unsigned long offset;
6169 register dw_loc_descr_ref loc_descr;
6170 register enum dwarf_location_atom op;
6172 if (TREE_CODE (decl) == TREE_VEC)
6173 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
6175 offset = field_byte_offset (decl);
6177 /* The DWARF2 standard says that we should assume that the structure address
6178 is already on the stack, so we can specify a structure field address
6179 by using DW_OP_plus_uconst. */
6181 #ifdef MIPS_DEBUGGING_INFO
6182 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6183 correctly. It works only if we leave the offset on the stack. */
6186 op = DW_OP_plus_uconst;
6189 loc_descr = new_loc_descr (op, offset, 0);
6190 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6193 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6194 does not have a "location" either in memory or in a register. These
6195 things can arise in GNU C when a constant is passed as an actual parameter
6196 to an inlined function. They can also arise in C++ where declared
6197 constants do not necessarily get memory "homes". */
6200 add_const_value_attribute (die, rtl)
6201 register dw_die_ref die;
6204 switch (GET_CODE (rtl))
6207 /* Note that a CONST_INT rtx could represent either an integer or a
6208 floating-point constant. A CONST_INT is used whenever the constant
6209 will fit into a single word. In all such cases, the original mode
6210 of the constant value is wiped out, and the CONST_INT rtx is
6211 assigned VOIDmode. */
6212 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6216 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6217 floating-point constant. A CONST_DOUBLE is used whenever the
6218 constant requires more than one word in order to be adequately
6219 represented. We output CONST_DOUBLEs as blocks. */
6221 register enum machine_mode mode = GET_MODE (rtl);
6223 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6225 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6229 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6233 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6237 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6242 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6249 add_AT_float (die, DW_AT_const_value, length, array);
6252 add_AT_long_long (die, DW_AT_const_value,
6253 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6258 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6264 add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
6268 /* In cases where an inlined instance of an inline function is passed
6269 the address of an `auto' variable (which is local to the caller) we
6270 can get a situation where the DECL_RTL of the artificial local
6271 variable (for the inlining) which acts as a stand-in for the
6272 corresponding formal parameter (of the inline function) will look
6273 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6274 exactly a compile-time constant expression, but it isn't the address
6275 of the (artificial) local variable either. Rather, it represents the
6276 *value* which the artificial local variable always has during its
6277 lifetime. We currently have no way to represent such quasi-constant
6278 values in Dwarf, so for now we just punt and generate an
6279 DW_AT_const_value attribute with null address. */
6280 add_AT_addr (die, DW_AT_const_value, addr_to_string (const0_rtx));
6284 /* No other kinds of rtx should be possible here. */
6290 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6291 data attribute for a variable or a parameter. We generate the
6292 DW_AT_const_value attribute only in those cases where the given variable
6293 or parameter does not have a true "location" either in memory or in a
6294 register. This can happen (for example) when a constant is passed as an
6295 actual argument in a call to an inline function. (It's possible that
6296 these things can crop up in other ways also.) Note that one type of
6297 constant value which can be passed into an inlined function is a constant
6298 pointer. This can happen for example if an actual argument in an inlined
6299 function call evaluates to a compile-time constant address. */
6302 add_location_or_const_value_attribute (die, decl)
6303 register dw_die_ref die;
6307 register tree declared_type;
6308 register tree passed_type;
6310 if (TREE_CODE (decl) == ERROR_MARK)
6313 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6316 /* Here we have to decide where we are going to say the parameter "lives"
6317 (as far as the debugger is concerned). We only have a couple of
6318 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6320 DECL_RTL normally indicates where the parameter lives during most of the
6321 activation of the function. If optimization is enabled however, this
6322 could be either NULL or else a pseudo-reg. Both of those cases indicate
6323 that the parameter doesn't really live anywhere (as far as the code
6324 generation parts of GCC are concerned) during most of the function's
6325 activation. That will happen (for example) if the parameter is never
6326 referenced within the function.
6328 We could just generate a location descriptor here for all non-NULL
6329 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6330 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6331 where DECL_RTL is NULL or is a pseudo-reg.
6333 Note however that we can only get away with using DECL_INCOMING_RTL as
6334 a backup substitute for DECL_RTL in certain limited cases. In cases
6335 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6336 we can be sure that the parameter was passed using the same type as it is
6337 declared to have within the function, and that its DECL_INCOMING_RTL
6338 points us to a place where a value of that type is passed.
6340 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6341 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6342 because in these cases DECL_INCOMING_RTL points us to a value of some
6343 type which is *different* from the type of the parameter itself. Thus,
6344 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6345 such cases, the debugger would end up (for example) trying to fetch a
6346 `float' from a place which actually contains the first part of a
6347 `double'. That would lead to really incorrect and confusing
6348 output at debug-time.
6350 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6351 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6352 are a couple of exceptions however. On little-endian machines we can
6353 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6354 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6355 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6356 when (on a little-endian machine) a non-prototyped function has a
6357 parameter declared to be of type `short' or `char'. In such cases,
6358 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6359 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6360 passed `int' value. If the debugger then uses that address to fetch
6361 a `short' or a `char' (on a little-endian machine) the result will be
6362 the correct data, so we allow for such exceptional cases below.
6364 Note that our goal here is to describe the place where the given formal
6365 parameter lives during most of the function's activation (i.e. between
6366 the end of the prologue and the start of the epilogue). We'll do that
6367 as best as we can. Note however that if the given formal parameter is
6368 modified sometime during the execution of the function, then a stack
6369 backtrace (at debug-time) will show the function as having been
6370 called with the *new* value rather than the value which was
6371 originally passed in. This happens rarely enough that it is not
6372 a major problem, but it *is* a problem, and I'd like to fix it.
6374 A future version of dwarf2out.c may generate two additional
6375 attributes for any given DW_TAG_formal_parameter DIE which will
6376 describe the "passed type" and the "passed location" for the
6377 given formal parameter in addition to the attributes we now
6378 generate to indicate the "declared type" and the "active
6379 location" for each parameter. This additional set of attributes
6380 could be used by debuggers for stack backtraces. Separately, note
6381 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6382 NULL also. This happens (for example) for inlined-instances of
6383 inline function formal parameters which are never referenced.
6384 This really shouldn't be happening. All PARM_DECL nodes should
6385 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6386 doesn't currently generate these values for inlined instances of
6387 inline function parameters, so when we see such cases, we are
6388 just SOL (shit-out-of-luck) for the time being (until integrate.c
6391 /* Use DECL_RTL as the "location" unless we find something better. */
6392 rtl = DECL_RTL (decl);
6394 if (TREE_CODE (decl) == PARM_DECL)
6396 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
6398 declared_type = type_main_variant (TREE_TYPE (decl));
6399 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
6401 /* This decl represents a formal parameter which was optimized out.
6402 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
6403 all* cases where (rtl == NULL_RTX) just below. */
6404 if (declared_type == passed_type)
6405 rtl = DECL_INCOMING_RTL (decl);
6406 else if (! BYTES_BIG_ENDIAN
6407 && TREE_CODE (declared_type) == INTEGER_TYPE
6408 && TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
6409 rtl = DECL_INCOMING_RTL (decl);
6413 if (rtl == NULL_RTX)
6416 switch (GET_CODE (rtl))
6425 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
6426 add_const_value_attribute (die, rtl);
6432 add_location_attribute (die, rtl);
6440 /* Generate an DW_AT_name attribute given some string value to be included as
6441 the value of the attribute. */
6444 add_name_attribute (die, name_string)
6445 register dw_die_ref die;
6446 register char *name_string;
6448 if (name_string != NULL && *name_string != 0)
6449 add_AT_string (die, DW_AT_name, name_string);
6452 /* Given a tree node describing an array bound (either lower or upper) output
6453 a representation for that bound. */
6456 add_bound_info (subrange_die, bound_attr, bound)
6457 register dw_die_ref subrange_die;
6458 register enum dwarf_attribute bound_attr;
6459 register tree bound;
6461 register unsigned bound_value = 0;
6462 switch (TREE_CODE (bound))
6467 /* All fixed-bounds are represented by INTEGER_CST nodes. */
6469 bound_value = TREE_INT_CST_LOW (bound);
6470 if (bound_attr == DW_AT_lower_bound
6471 && ((is_c_family () && bound_value == 0)
6472 || (is_fortran () && bound_value == 1)))
6473 /* use the default */;
6475 add_AT_unsigned (subrange_die, bound_attr, bound_value);
6480 case NON_LVALUE_EXPR:
6481 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
6485 /* If optimization is turned on, the SAVE_EXPRs that describe how to
6486 access the upper bound values may be bogus. If they refer to a
6487 register, they may only describe how to get at these values at the
6488 points in the generated code right after they have just been
6489 computed. Worse yet, in the typical case, the upper bound values
6490 will not even *be* computed in the optimized code (though the
6491 number of elements will), so these SAVE_EXPRs are entirely
6492 bogus. In order to compensate for this fact, we check here to see
6493 if optimization is enabled, and if so, we don't add an attribute
6494 for the (unknown and unknowable) upper bound. This should not
6495 cause too much trouble for existing (stupid?) debuggers because
6496 they have to deal with empty upper bounds location descriptions
6497 anyway in order to be able to deal with incomplete array types.
6498 Of course an intelligent debugger (GDB?) should be able to
6499 comprehend that a missing upper bound specification in a array
6500 type used for a storage class `auto' local array variable
6501 indicates that the upper bound is both unknown (at compile- time)
6502 and unknowable (at run-time) due to optimization.
6504 We assume that a MEM rtx is safe because gcc wouldn't put the
6505 value there unless it was going to be used repeatedly in the
6506 function, i.e. for cleanups. */
6507 if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)
6509 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
6510 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
6511 add_AT_flag (decl_die, DW_AT_artificial, 1);
6512 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
6513 add_location_attribute (decl_die, SAVE_EXPR_RTL (bound));
6514 add_AT_die_ref (subrange_die, bound_attr, decl_die);
6517 /* Else leave out the attribute. */
6525 /* Note that the block of subscript information for an array type also
6526 includes information about the element type of type given array type. */
6529 add_subscript_info (type_die, type)
6530 register dw_die_ref type_die;
6533 register unsigned dimension_number;
6534 register tree lower, upper;
6535 register dw_die_ref subrange_die;
6537 /* The GNU compilers represent multidimensional array types as sequences of
6538 one dimensional array types whose element types are themselves array
6539 types. Here we squish that down, so that each multidimensional array
6540 type gets only one array_type DIE in the Dwarf debugging info. The draft
6541 Dwarf specification say that we are allowed to do this kind of
6542 compression in C (because there is no difference between an array or
6543 arrays and a multidimensional array in C) but for other source languages
6544 (e.g. Ada) we probably shouldn't do this. */
6546 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
6547 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
6548 We work around this by disabling this feature. See also
6549 gen_array_type_die. */
6550 #ifndef MIPS_DEBUGGING_INFO
6551 for (dimension_number = 0;
6552 TREE_CODE (type) == ARRAY_TYPE;
6553 type = TREE_TYPE (type), dimension_number++)
6556 register tree domain = TYPE_DOMAIN (type);
6558 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
6559 and (in GNU C only) variable bounds. Handle all three forms
6561 subrange_die = new_die (DW_TAG_subrange_type, type_die);
6564 /* We have an array type with specified bounds. */
6565 lower = TYPE_MIN_VALUE (domain);
6566 upper = TYPE_MAX_VALUE (domain);
6568 /* define the index type. */
6569 if (TREE_TYPE (domain))
6570 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
6573 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
6574 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
6577 /* We have an array type with an unspecified length. The DWARF-2
6578 spec does not say how to handle this; let's just leave out the
6582 #ifndef MIPS_DEBUGGING_INFO
6588 add_byte_size_attribute (die, tree_node)
6590 register tree tree_node;
6592 register unsigned size;
6594 switch (TREE_CODE (tree_node))
6602 case QUAL_UNION_TYPE:
6603 size = int_size_in_bytes (tree_node);
6606 /* For a data member of a struct or union, the DW_AT_byte_size is
6607 generally given as the number of bytes normally allocated for an
6608 object of the *declared* type of the member itself. This is true
6609 even for bit-fields. */
6610 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
6616 /* Note that `size' might be -1 when we get to this point. If it is, that
6617 indicates that the byte size of the entity in question is variable. We
6618 have no good way of expressing this fact in Dwarf at the present time,
6619 so just let the -1 pass on through. */
6621 add_AT_unsigned (die, DW_AT_byte_size, size);
6624 /* For a FIELD_DECL node which represents a bit-field, output an attribute
6625 which specifies the distance in bits from the highest order bit of the
6626 "containing object" for the bit-field to the highest order bit of the
6629 For any given bit-field, the "containing object" is a hypothetical
6630 object (of some integral or enum type) within which the given bit-field
6631 lives. The type of this hypothetical "containing object" is always the
6632 same as the declared type of the individual bit-field itself. The
6633 determination of the exact location of the "containing object" for a
6634 bit-field is rather complicated. It's handled by the
6635 `field_byte_offset' function (above).
6637 Note that it is the size (in bytes) of the hypothetical "containing object"
6638 which will be given in the DW_AT_byte_size attribute for this bit-field.
6639 (See `byte_size_attribute' above). */
6642 add_bit_offset_attribute (die, decl)
6643 register dw_die_ref die;
6646 register unsigned object_offset_in_bytes = field_byte_offset (decl);
6647 register tree type = DECL_BIT_FIELD_TYPE (decl);
6648 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
6649 register unsigned bitpos_int;
6650 register unsigned highest_order_object_bit_offset;
6651 register unsigned highest_order_field_bit_offset;
6652 register unsigned bit_offset;
6654 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
6655 assert (type); /* Must be a bit field. */
6657 /* We can't yet handle bit-fields whose offsets are variable, so if we
6658 encounter such things, just return without generating any attribute
6660 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6663 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6665 /* Note that the bit offset is always the distance (in bits) from the
6666 highest-order bit of the "containing object" to the highest-order bit of
6667 the bit-field itself. Since the "high-order end" of any object or field
6668 is different on big-endian and little-endian machines, the computation
6669 below must take account of these differences. */
6670 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
6671 highest_order_field_bit_offset = bitpos_int;
6673 if (! BYTES_BIG_ENDIAN)
6675 highest_order_field_bit_offset
6676 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
6678 highest_order_object_bit_offset += simple_type_size_in_bits (type);
6682 = (! BYTES_BIG_ENDIAN
6683 ? highest_order_object_bit_offset - highest_order_field_bit_offset
6684 : highest_order_field_bit_offset - highest_order_object_bit_offset);
6686 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
6689 /* For a FIELD_DECL node which represents a bit field, output an attribute
6690 which specifies the length in bits of the given field. */
6693 add_bit_size_attribute (die, decl)
6694 register dw_die_ref die;
6697 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
6698 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
6699 add_AT_unsigned (die, DW_AT_bit_size,
6700 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
6703 /* If the compiled language is ANSI C, then add a 'prototyped'
6704 attribute, if arg types are given for the parameters of a function. */
6707 add_prototyped_attribute (die, func_type)
6708 register dw_die_ref die;
6709 register tree func_type;
6711 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
6712 && TYPE_ARG_TYPES (func_type) != NULL)
6713 add_AT_flag (die, DW_AT_prototyped, 1);
6717 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
6718 by looking in either the type declaration or object declaration
6722 add_abstract_origin_attribute (die, origin)
6723 register dw_die_ref die;
6724 register tree origin;
6726 dw_die_ref origin_die = NULL;
6727 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
6728 origin_die = lookup_decl_die (origin);
6729 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
6730 origin_die = lookup_type_die (origin);
6732 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
6735 /* We do not currently support the pure_virtual attribute. */
6738 add_pure_or_virtual_attribute (die, func_decl)
6739 register dw_die_ref die;
6740 register tree func_decl;
6742 if (DECL_VINDEX (func_decl))
6744 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
6745 add_AT_loc (die, DW_AT_vtable_elem_location,
6746 new_loc_descr (DW_OP_constu,
6747 TREE_INT_CST_LOW (DECL_VINDEX (func_decl)),
6750 /* GNU extension: Record what type this method came from originally. */
6751 if (debug_info_level > DINFO_LEVEL_TERSE)
6752 add_AT_die_ref (die, DW_AT_containing_type,
6753 lookup_type_die (DECL_CONTEXT (func_decl)));
6757 /* Add source coordinate attributes for the given decl. */
6760 add_src_coords_attributes (die, decl)
6761 register dw_die_ref die;
6764 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
6766 add_AT_unsigned (die, DW_AT_decl_file, file_index);
6767 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
6770 /* Add an DW_AT_name attribute and source coordinate attribute for the
6771 given decl, but only if it actually has a name. */
6774 add_name_and_src_coords_attributes (die, decl)
6775 register dw_die_ref die;
6778 register tree decl_name;
6780 decl_name = DECL_NAME (decl);
6781 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
6783 add_name_attribute (die, dwarf2_name (decl, 0));
6784 add_src_coords_attributes (die, decl);
6785 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
6786 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
6787 add_AT_string (die, DW_AT_MIPS_linkage_name,
6788 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
6792 /* Push a new declaration scope. */
6795 push_decl_scope (scope)
6798 /* Make room in the decl_scope_table, if necessary. */
6799 if (decl_scope_table_allocated == decl_scope_depth)
6801 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
6803 = (tree *) xrealloc (decl_scope_table,
6804 decl_scope_table_allocated * sizeof (tree));
6807 decl_scope_table[decl_scope_depth++] = scope;
6810 /* Return the DIE for the scope the immediately contains this declaration. */
6813 scope_die_for (t, context_die)
6815 register dw_die_ref context_die;
6817 register dw_die_ref scope_die = NULL;
6818 register tree containing_scope;
6819 register unsigned long i;
6821 /* Function-local tags and functions get stuck in limbo until they are
6822 fixed up by decls_for_scope. */
6823 if (context_die == NULL
6824 && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t)))
6827 /* Walk back up the declaration tree looking for a place to define
6829 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
6830 containing_scope = TYPE_CONTEXT (t);
6831 else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t))
6832 containing_scope = decl_class_context (t);
6834 containing_scope = DECL_CONTEXT (t);
6836 if (containing_scope == NULL_TREE)
6837 scope_die = comp_unit_die;
6840 for (i = decl_scope_depth, scope_die = context_die;
6841 i > 0 && decl_scope_table[i - 1] != containing_scope;
6842 scope_die = scope_die->die_parent, --i)
6847 assert (scope_die == comp_unit_die);
6848 assert (TREE_CODE_CLASS (TREE_CODE (containing_scope)) == 't');
6849 if (debug_info_level > DINFO_LEVEL_TERSE)
6850 assert (TREE_ASM_WRITTEN (containing_scope));
6857 /* Pop a declaration scope. */
6861 assert (decl_scope_depth > 0);
6865 /* Many forms of DIEs require a "type description" attribute. This
6866 routine locates the proper "type descriptor" die for the type given
6867 by 'type', and adds an DW_AT_type attribute below the given die. */
6870 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
6871 register dw_die_ref object_die;
6873 register int decl_const;
6874 register int decl_volatile;
6875 register dw_die_ref context_die;
6877 register enum tree_code code = TREE_CODE (type);
6878 register dw_die_ref type_die = NULL;
6880 /* If this type is an unnamed subtype of an integral or floating-point
6881 type, use the inner type. */
6882 if ((code == INTEGER_TYPE || code == REAL_TYPE)
6883 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
6884 type = TREE_TYPE (type), code = TREE_CODE (type);
6886 if (code == ERROR_MARK)
6889 /* Handle a special case. For functions whose return type is void, we
6890 generate *no* type attribute. (Note that no object may have type
6891 `void', so this only applies to function return types). */
6892 if (code == VOID_TYPE)
6895 type_die = modified_type_die (type,
6896 decl_const || TYPE_READONLY (type),
6897 decl_volatile || TYPE_VOLATILE (type),
6899 if (type_die != NULL)
6900 add_AT_die_ref (object_die, DW_AT_type, type_die);
6903 /* Given a tree pointer to a struct, class, union, or enum type node, return
6904 a pointer to the (string) tag name for the given type, or zero if the type
6905 was declared without a tag. */
6911 register char *name = 0;
6913 if (TYPE_NAME (type) != 0)
6915 register tree t = 0;
6917 /* Find the IDENTIFIER_NODE for the type name. */
6918 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
6919 t = TYPE_NAME (type);
6921 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
6922 a TYPE_DECL node, regardless of whether or not a `typedef' was
6924 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6925 && ! DECL_IGNORED_P (TYPE_NAME (type)))
6926 t = DECL_NAME (TYPE_NAME (type));
6928 /* Now get the name as a string, or invent one. */
6930 name = IDENTIFIER_POINTER (t);
6933 return (name == 0 || *name == '\0') ? 0 : name;
6936 /* Return the type associated with a data member, make a special check
6937 for bit field types. */
6940 member_declared_type (member)
6941 register tree member;
6943 return (DECL_BIT_FIELD_TYPE (member)
6944 ? DECL_BIT_FIELD_TYPE (member)
6945 : TREE_TYPE (member));
6948 /* Get the decl's label, as described by its RTL. This may be different
6949 from the DECL_NAME name used in the source file. */
6952 decl_start_label (decl)
6957 x = DECL_RTL (decl);
6958 if (GET_CODE (x) != MEM)
6962 if (GET_CODE (x) != SYMBOL_REF)
6965 fnname = XSTR (x, 0);
6969 /* These routines generate the internnal representation of the DIE's for
6970 the compilation unit. Debugging information is collected by walking
6971 the declaration trees passed in from dwarf2out_decl(). */
6974 gen_array_type_die (type, context_die)
6976 register dw_die_ref context_die;
6978 register dw_die_ref scope_die = scope_die_for (type, context_die);
6979 register dw_die_ref array_die;
6980 register tree element_type;
6982 /* ??? The SGI dwarf reader fails for array of array of enum types unless
6983 the inner array type comes before the outer array type. Thus we must
6984 call gen_type_die before we call new_die. See below also. */
6985 #ifdef MIPS_DEBUGGING_INFO
6986 gen_type_die (TREE_TYPE (type), context_die);
6989 array_die = new_die (DW_TAG_array_type, scope_die);
6992 /* We default the array ordering. SDB will probably do
6993 the right things even if DW_AT_ordering is not present. It's not even
6994 an issue until we start to get into multidimensional arrays anyway. If
6995 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
6996 then we'll have to put the DW_AT_ordering attribute back in. (But if
6997 and when we find out that we need to put these in, we will only do so
6998 for multidimensional arrays. */
6999 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
7002 #ifdef MIPS_DEBUGGING_INFO
7003 /* The SGI compilers handle arrays of unknown bound by setting
7004 AT_declaration and not emitting any subrange DIEs. */
7005 if (! TYPE_DOMAIN (type))
7006 add_AT_unsigned (array_die, DW_AT_declaration, 1);
7009 add_subscript_info (array_die, type);
7011 equate_type_number_to_die (type, array_die);
7013 /* Add representation of the type of the elements of this array type. */
7014 element_type = TREE_TYPE (type);
7016 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7017 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7018 We work around this by disabling this feature. See also
7019 add_subscript_info. */
7020 #ifndef MIPS_DEBUGGING_INFO
7021 while (TREE_CODE (element_type) == ARRAY_TYPE)
7022 element_type = TREE_TYPE (element_type);
7024 gen_type_die (element_type, context_die);
7027 add_type_attribute (array_die, element_type, 0, 0, context_die);
7031 gen_set_type_die (type, context_die)
7033 register dw_die_ref context_die;
7035 register dw_die_ref type_die
7036 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7038 equate_type_number_to_die (type, type_die);
7039 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7043 gen_entry_point_die (decl, context_die)
7045 register dw_die_ref context_die;
7047 register tree origin = decl_ultimate_origin (decl);
7048 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
7050 add_abstract_origin_attribute (decl_die, origin);
7053 add_name_and_src_coords_attributes (decl_die, decl);
7054 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
7058 if (DECL_ABSTRACT (decl))
7059 equate_decl_number_to_die (decl, decl_die);
7061 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
7064 /* Remember a type in the pending_types_list. */
7070 if (pending_types == pending_types_allocated)
7072 pending_types_allocated += PENDING_TYPES_INCREMENT;
7074 = (tree *) xrealloc (pending_types_list,
7075 sizeof (tree) * pending_types_allocated);
7078 pending_types_list[pending_types++] = type;
7081 /* Output any pending types (from the pending_types list) which we can output
7082 now (taking into account the scope that we are working on now).
7084 For each type output, remove the given type from the pending_types_list
7085 *before* we try to output it. */
7088 output_pending_types_for_scope (context_die)
7089 register dw_die_ref context_die;
7093 while (pending_types)
7096 type = pending_types_list[pending_types];
7097 gen_type_die (type, context_die);
7098 assert (TREE_ASM_WRITTEN (type));
7102 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7105 gen_inlined_enumeration_type_die (type, context_die)
7107 register dw_die_ref context_die;
7109 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
7110 scope_die_for (type, context_die));
7112 assert (TREE_ASM_WRITTEN (type));
7113 add_abstract_origin_attribute (type_die, type);
7116 /* Generate a DIE to represent an inlined instance of a structure type. */
7119 gen_inlined_structure_type_die (type, context_die)
7121 register dw_die_ref context_die;
7123 register dw_die_ref type_die = new_die (DW_TAG_structure_type,
7124 scope_die_for (type, context_die));
7126 assert (TREE_ASM_WRITTEN (type));
7127 add_abstract_origin_attribute (type_die, type);
7130 /* Generate a DIE to represent an inlined instance of a union type. */
7133 gen_inlined_union_type_die (type, context_die)
7135 register dw_die_ref context_die;
7137 register dw_die_ref type_die = new_die (DW_TAG_union_type,
7138 scope_die_for (type, context_die));
7140 assert (TREE_ASM_WRITTEN (type));
7141 add_abstract_origin_attribute (type_die, type);
7144 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7145 include all of the information about the enumeration values also. Each
7146 enumerated type name/value is listed as a child of the enumerated type
7150 gen_enumeration_type_die (type, context_die)
7152 register dw_die_ref context_die;
7154 register dw_die_ref type_die = lookup_type_die (type);
7156 if (type_die == NULL)
7158 type_die = new_die (DW_TAG_enumeration_type,
7159 scope_die_for (type, context_die));
7160 equate_type_number_to_die (type, type_die);
7161 add_name_attribute (type_die, type_tag (type));
7163 else if (! TYPE_SIZE (type))
7166 remove_AT (type_die, DW_AT_declaration);
7168 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7169 given enum type is incomplete, do not generate the DW_AT_byte_size
7170 attribute or the DW_AT_element_list attribute. */
7171 if (TYPE_SIZE (type))
7175 TREE_ASM_WRITTEN (type) = 1;
7176 add_byte_size_attribute (type_die, type);
7177 if (type_tag (type))
7178 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
7180 for (link = TYPE_FIELDS (type);
7181 link != NULL; link = TREE_CHAIN (link))
7183 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
7185 add_name_attribute (enum_die,
7186 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
7187 add_AT_unsigned (enum_die, DW_AT_const_value,
7188 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
7192 add_AT_flag (type_die, DW_AT_declaration, 1);
7196 /* Generate a DIE to represent either a real live formal parameter decl or to
7197 represent just the type of some formal parameter position in some function
7200 Note that this routine is a bit unusual because its argument may be a
7201 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7202 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7203 node. If it's the former then this function is being called to output a
7204 DIE to represent a formal parameter object (or some inlining thereof). If
7205 it's the latter, then this function is only being called to output a
7206 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7207 argument type of some subprogram type. */
7210 gen_formal_parameter_die (node, context_die)
7212 register dw_die_ref context_die;
7214 register dw_die_ref parm_die
7215 = new_die (DW_TAG_formal_parameter, context_die);
7216 register tree origin;
7218 switch (TREE_CODE_CLASS (TREE_CODE (node)))
7221 origin = decl_ultimate_origin (node);
7223 add_abstract_origin_attribute (parm_die, origin);
7226 add_name_and_src_coords_attributes (parm_die, node);
7227 add_type_attribute (parm_die, TREE_TYPE (node),
7228 TREE_READONLY (node),
7229 TREE_THIS_VOLATILE (node),
7231 if (DECL_ARTIFICIAL (node))
7232 add_AT_flag (parm_die, DW_AT_artificial, 1);
7235 equate_decl_number_to_die (node, parm_die);
7236 if (! DECL_ABSTRACT (node))
7237 add_location_or_const_value_attribute (parm_die, node);
7242 /* We were called with some kind of a ..._TYPE node. */
7243 add_type_attribute (parm_die, node, 0, 0, context_die);
7253 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
7254 at the end of an (ANSI prototyped) formal parameters list. */
7257 gen_unspecified_parameters_die (decl_or_type, context_die)
7258 register tree decl_or_type;
7259 register dw_die_ref context_die;
7261 register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters,
7265 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
7266 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
7267 parameters as specified in some function type specification (except for
7268 those which appear as part of a function *definition*).
7270 Note we must be careful here to output all of the parameter DIEs before*
7271 we output any DIEs needed to represent the types of the formal parameters.
7272 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
7273 non-parameter DIE it sees ends the formal parameter list. */
7276 gen_formal_types_die (function_or_method_type, context_die)
7277 register tree function_or_method_type;
7278 register dw_die_ref context_die;
7281 register tree formal_type = NULL;
7282 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
7285 /* In the case where we are generating a formal types list for a C++
7286 non-static member function type, skip over the first thing on the
7287 TYPE_ARG_TYPES list because it only represents the type of the hidden
7288 `this pointer'. The debugger should be able to figure out (without
7289 being explicitly told) that this non-static member function type takes a
7290 `this pointer' and should be able to figure what the type of that hidden
7291 parameter is from the DW_AT_member attribute of the parent
7292 DW_TAG_subroutine_type DIE. */
7293 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
7294 first_parm_type = TREE_CHAIN (first_parm_type);
7297 /* Make our first pass over the list of formal parameter types and output a
7298 DW_TAG_formal_parameter DIE for each one. */
7299 for (link = first_parm_type; link; link = TREE_CHAIN (link))
7301 register dw_die_ref parm_die;
7303 formal_type = TREE_VALUE (link);
7304 if (formal_type == void_type_node)
7307 /* Output a (nameless) DIE to represent the formal parameter itself. */
7308 parm_die = gen_formal_parameter_die (formal_type, context_die);
7309 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
7310 && link == first_parm_type)
7311 add_AT_flag (parm_die, DW_AT_artificial, 1);
7314 /* If this function type has an ellipsis, add a
7315 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
7316 if (formal_type != void_type_node)
7317 gen_unspecified_parameters_die (function_or_method_type, context_die);
7319 /* Make our second (and final) pass over the list of formal parameter types
7320 and output DIEs to represent those types (as necessary). */
7321 for (link = TYPE_ARG_TYPES (function_or_method_type);
7323 link = TREE_CHAIN (link))
7325 formal_type = TREE_VALUE (link);
7326 if (formal_type == void_type_node)
7329 gen_type_die (formal_type, context_die);
7333 /* Generate a DIE to represent a declared function (either file-scope or
7337 gen_subprogram_die (decl, context_die)
7339 register dw_die_ref context_die;
7341 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
7342 register tree origin = decl_ultimate_origin (decl);
7343 register dw_die_ref subr_die;
7344 register dw_loc_descr_ref fp_loc = NULL;
7345 register rtx fp_reg;
7346 register tree fn_arg_types;
7347 register tree outer_scope;
7348 register dw_die_ref old_die = lookup_decl_die (decl);
7349 register int declaration
7350 = (current_function_decl != decl
7352 && (context_die->die_tag == DW_TAG_structure_type
7353 || context_die->die_tag == DW_TAG_union_type)));
7357 subr_die = new_die (DW_TAG_subprogram, context_die);
7358 add_abstract_origin_attribute (subr_die, origin);
7362 register unsigned file_index
7363 = lookup_filename (DECL_SOURCE_FILE (decl));
7365 assert (get_AT_flag (old_die, DW_AT_declaration) == 1);
7367 /* If the definition comes from the same place as the declaration,
7368 maybe use the old DIE. We always want the DIE for this function
7369 that has the *_pc attributes to be under comp_unit_die so the
7370 debugger can find it. For inlines, that is the concrete instance,
7371 so we can use the old DIE here. For non-inline methods, we want a
7372 specification DIE at toplevel, so we need a new DIE. For local
7373 class methods, this does not apply. */
7374 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
7375 || context_die == NULL)
7376 && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
7377 && (get_AT_unsigned (old_die, DW_AT_decl_line)
7378 == DECL_SOURCE_LINE (decl)))
7382 /* Clear out the declaration attribute and the parm types. */
7383 remove_AT (subr_die, DW_AT_declaration);
7384 remove_children (subr_die);
7388 subr_die = new_die (DW_TAG_subprogram, context_die);
7389 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
7390 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
7391 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
7392 if (get_AT_unsigned (old_die, DW_AT_decl_line)
7393 != DECL_SOURCE_LINE (decl))
7395 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7400 register dw_die_ref scope_die;
7402 if (DECL_CONTEXT (decl))
7403 scope_die = scope_die_for (decl, context_die);
7405 /* Don't put block extern declarations under comp_unit_die. */
7406 scope_die = context_die;
7408 subr_die = new_die (DW_TAG_subprogram, scope_die);
7410 if (TREE_PUBLIC (decl))
7411 add_AT_flag (subr_die, DW_AT_external, 1);
7413 add_name_and_src_coords_attributes (subr_die, decl);
7414 if (debug_info_level > DINFO_LEVEL_TERSE)
7416 register tree type = TREE_TYPE (decl);
7418 add_prototyped_attribute (subr_die, type);
7419 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
7422 add_pure_or_virtual_attribute (subr_die, decl);
7423 if (DECL_ARTIFICIAL (decl))
7424 add_AT_flag (subr_die, DW_AT_artificial, 1);
7425 if (TREE_PROTECTED (decl))
7426 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
7427 else if (TREE_PRIVATE (decl))
7428 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
7433 add_AT_flag (subr_die, DW_AT_declaration, 1);
7435 /* The first time we see a member function, it is in the context of
7436 the class to which it belongs. We make sure of this by emitting
7437 the class first. The next time is the definition, which is
7438 handled above. The two may come from the same source text. */
7439 if (decl_class_context (decl))
7440 equate_decl_number_to_die (decl, subr_die);
7442 else if (DECL_ABSTRACT (decl))
7444 if (DECL_DEFER_OUTPUT (decl))
7446 if (DECL_INLINE (decl))
7447 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
7449 add_AT_unsigned (subr_die, DW_AT_inline,
7450 DW_INL_declared_not_inlined);
7452 else if (DECL_INLINE (decl))
7453 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
7454 else if (declaration)
7455 /* Block extern declaration in an inline function. */
7456 add_AT_flag (subr_die, DW_AT_declaration, 1);
7460 equate_decl_number_to_die (decl, subr_die);
7462 else if (!DECL_EXTERNAL (decl))
7464 if (origin == NULL_TREE)
7465 equate_decl_number_to_die (decl, subr_die);
7467 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
7468 current_funcdef_number);
7469 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
7470 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
7471 current_funcdef_number);
7472 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
7474 add_pubname (decl, subr_die);
7475 add_arange (decl, subr_die);
7477 #ifdef MIPS_DEBUGGING_INFO
7478 /* Add a reference to the FDE for this routine. */
7479 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
7482 /* Define the "frame base" location for this routine. We use the
7483 frame pointer or stack pointer registers, since the RTL for local
7484 variables is relative to one of them. */
7486 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
7487 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
7489 if (current_function_needs_context)
7490 add_AT_loc (subr_die, DW_AT_static_link,
7491 loc_descriptor (lookup_static_chain (decl)));
7494 /* Now output descriptions of the arguments for this function. This gets
7495 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
7496 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
7497 `...' at the end of the formal parameter list. In order to find out if
7498 there was a trailing ellipsis or not, we must instead look at the type
7499 associated with the FUNCTION_DECL. This will be a node of type
7500 FUNCTION_TYPE. If the chain of type nodes hanging off of this
7501 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
7502 an ellipsis at the end. */
7503 push_decl_scope (decl);
7505 /* In the case where we are describing a mere function declaration, all we
7506 need to do here (and all we *can* do here) is to describe the *types* of
7507 its formal parameters. */
7508 if (debug_info_level <= DINFO_LEVEL_TERSE)
7510 else if (declaration)
7511 gen_formal_types_die (TREE_TYPE (decl), subr_die);
7514 /* Generate DIEs to represent all known formal parameters */
7515 register tree arg_decls = DECL_ARGUMENTS (decl);
7518 /* When generating DIEs, generate the unspecified_parameters DIE
7519 instead if we come across the arg "__builtin_va_alist" */
7520 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
7521 if (TREE_CODE (parm) == PARM_DECL)
7523 if (DECL_NAME (parm)
7524 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
7525 "__builtin_va_alist"))
7526 gen_unspecified_parameters_die (parm, subr_die);
7528 gen_decl_die (parm, subr_die);
7531 /* Decide whether we need a unspecified_parameters DIE at the end.
7532 There are 2 more cases to do this for: 1) the ansi ... declaration -
7533 this is detectable when the end of the arg list is not a
7534 void_type_node 2) an unprototyped function declaration (not a
7535 definition). This just means that we have no info about the
7536 parameters at all. */
7537 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
7538 if (fn_arg_types != NULL)
7540 /* this is the prototyped case, check for ... */
7541 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
7542 gen_unspecified_parameters_die (decl, subr_die);
7544 else if (DECL_INITIAL (decl) == NULL_TREE)
7545 gen_unspecified_parameters_die (decl, subr_die);
7548 /* Output Dwarf info for all of the stuff within the body of the function
7549 (if it has one - it may be just a declaration). */
7550 outer_scope = DECL_INITIAL (decl);
7552 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
7553 node created to represent a function. This outermost BLOCK actually
7554 represents the outermost binding contour for the function, i.e. the
7555 contour in which the function's formal parameters and labels get
7556 declared. Curiously, it appears that the front end doesn't actually
7557 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
7558 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
7559 list for the function instead.) The BLOCK_VARS list for the
7560 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
7561 the function however, and we output DWARF info for those in
7562 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
7563 node representing the function's outermost pair of curly braces, and
7564 any blocks used for the base and member initializers of a C++
7565 constructor function. */
7566 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
7568 current_function_has_inlines = 0;
7569 decls_for_scope (outer_scope, subr_die, 0);
7571 #if 0 && defined (MIPS_DEBUGGING_INFO)
7572 if (current_function_has_inlines)
7574 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
7575 if (! comp_unit_has_inlines)
7577 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
7578 comp_unit_has_inlines = 1;
7587 /* Generate a DIE to represent a declared data object. */
7590 gen_variable_die (decl, context_die)
7592 register dw_die_ref context_die;
7594 register tree origin = decl_ultimate_origin (decl);
7595 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
7597 dw_die_ref old_die = lookup_decl_die (decl);
7599 = (DECL_EXTERNAL (decl)
7600 || current_function_decl != decl_function_context (decl)
7601 || context_die->die_tag == DW_TAG_structure_type
7602 || context_die->die_tag == DW_TAG_union_type);
7605 add_abstract_origin_attribute (var_die, origin);
7606 /* Loop unrolling can create multiple blocks that refer to the same
7607 static variable, so we must test for the DW_AT_declaration flag. */
7608 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
7609 copy decls and set the DECL_ABSTRACT flag on them instead of
7611 else if (old_die && TREE_STATIC (decl)
7612 && get_AT_flag (old_die, DW_AT_declaration) == 1)
7614 /* ??? This is an instantiation of a C++ class level static. */
7615 add_AT_die_ref (var_die, DW_AT_specification, old_die);
7616 if (DECL_NAME (decl))
7618 register unsigned file_index
7619 = lookup_filename (DECL_SOURCE_FILE (decl));
7621 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
7622 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
7624 if (get_AT_unsigned (old_die, DW_AT_decl_line)
7625 != DECL_SOURCE_LINE (decl))
7627 add_AT_unsigned (var_die, DW_AT_decl_line,
7628 DECL_SOURCE_LINE (decl));
7633 add_name_and_src_coords_attributes (var_die, decl);
7634 add_type_attribute (var_die, TREE_TYPE (decl),
7635 TREE_READONLY (decl),
7636 TREE_THIS_VOLATILE (decl), context_die);
7638 if (TREE_PUBLIC (decl))
7639 add_AT_flag (var_die, DW_AT_external, 1);
7641 if (DECL_ARTIFICIAL (decl))
7642 add_AT_flag (var_die, DW_AT_artificial, 1);
7644 if (TREE_PROTECTED (decl))
7645 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
7647 else if (TREE_PRIVATE (decl))
7648 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
7652 add_AT_flag (var_die, DW_AT_declaration, 1);
7654 if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl))
7655 equate_decl_number_to_die (decl, var_die);
7657 if (! declaration && ! DECL_ABSTRACT (decl))
7659 equate_decl_number_to_die (decl, var_die);
7660 add_location_or_const_value_attribute (var_die, decl);
7661 add_pubname (decl, var_die);
7665 /* Generate a DIE to represent a label identifier. */
7668 gen_label_die (decl, context_die)
7670 register dw_die_ref context_die;
7672 register tree origin = decl_ultimate_origin (decl);
7673 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
7675 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7676 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
7679 add_abstract_origin_attribute (lbl_die, origin);
7681 add_name_and_src_coords_attributes (lbl_die, decl);
7683 if (DECL_ABSTRACT (decl))
7684 equate_decl_number_to_die (decl, lbl_die);
7687 insn = DECL_RTL (decl);
7688 if (GET_CODE (insn) == CODE_LABEL)
7690 /* When optimization is enabled (via -O) some parts of the compiler
7691 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
7692 represent source-level labels which were explicitly declared by
7693 the user. This really shouldn't be happening though, so catch
7694 it if it ever does happen. */
7695 if (INSN_DELETED_P (insn))
7698 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
7699 ASM_GENERATE_INTERNAL_LABEL (label, label2,
7700 (unsigned) INSN_UID (insn));
7701 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
7706 /* Generate a DIE for a lexical block. */
7709 gen_lexical_block_die (stmt, context_die, depth)
7711 register dw_die_ref context_die;
7714 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
7715 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7717 if (! BLOCK_ABSTRACT (stmt))
7719 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
7721 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
7722 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
7723 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
7726 push_decl_scope (stmt);
7727 decls_for_scope (stmt, stmt_die, depth);
7731 /* Generate a DIE for an inlined subprogram. */
7734 gen_inlined_subroutine_die (stmt, context_die, depth)
7736 register dw_die_ref context_die;
7739 if (! BLOCK_ABSTRACT (stmt))
7741 register dw_die_ref subr_die
7742 = new_die (DW_TAG_inlined_subroutine, context_die);
7743 register tree decl = block_ultimate_origin (stmt);
7744 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7746 add_abstract_origin_attribute (subr_die, decl);
7747 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
7749 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
7750 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
7751 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
7752 push_decl_scope (decl);
7753 decls_for_scope (stmt, subr_die, depth);
7755 current_function_has_inlines = 1;
7759 /* Generate a DIE for a field in a record, or structure. */
7762 gen_field_die (decl, context_die)
7764 register dw_die_ref context_die;
7766 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
7768 add_name_and_src_coords_attributes (decl_die, decl);
7769 add_type_attribute (decl_die, member_declared_type (decl),
7770 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
7773 /* If this is a bit field... */
7774 if (DECL_BIT_FIELD_TYPE (decl))
7776 add_byte_size_attribute (decl_die, decl);
7777 add_bit_size_attribute (decl_die, decl);
7778 add_bit_offset_attribute (decl_die, decl);
7781 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
7782 add_data_member_location_attribute (decl_die, decl);
7784 if (DECL_ARTIFICIAL (decl))
7785 add_AT_flag (decl_die, DW_AT_artificial, 1);
7787 if (TREE_PROTECTED (decl))
7788 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
7790 else if (TREE_PRIVATE (decl))
7791 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
7795 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
7796 Use modified_type_die instead.
7797 We keep this code here just in case these types of DIEs may be needed to
7798 represent certain things in other languages (e.g. Pascal) someday. */
7800 gen_pointer_type_die (type, context_die)
7802 register dw_die_ref context_die;
7804 register dw_die_ref ptr_die
7805 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
7807 equate_type_number_to_die (type, ptr_die);
7808 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
7809 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7812 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
7813 Use modified_type_die instead.
7814 We keep this code here just in case these types of DIEs may be needed to
7815 represent certain things in other languages (e.g. Pascal) someday. */
7817 gen_reference_type_die (type, context_die)
7819 register dw_die_ref context_die;
7821 register dw_die_ref ref_die
7822 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
7824 equate_type_number_to_die (type, ref_die);
7825 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
7826 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7830 /* Generate a DIE for a pointer to a member type. */
7832 gen_ptr_to_mbr_type_die (type, context_die)
7834 register dw_die_ref context_die;
7836 register dw_die_ref ptr_die
7837 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
7839 equate_type_number_to_die (type, ptr_die);
7840 add_AT_die_ref (ptr_die, DW_AT_containing_type,
7841 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
7842 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
7845 /* Generate the DIE for the compilation unit. */
7848 gen_compile_unit_die (main_input_filename)
7849 register char *main_input_filename;
7852 char *wd = getpwd ();
7854 comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
7855 add_name_attribute (comp_unit_die, main_input_filename);
7858 add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
7860 sprintf (producer, "%s %s", language_string, version_string);
7862 #ifdef MIPS_DEBUGGING_INFO
7863 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
7864 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
7865 not appear in the producer string, the debugger reaches the conclusion
7866 that the object file is stripped and has no debugging information.
7867 To get the MIPS/SGI debugger to believe that there is debugging
7868 information in the object file, we add a -g to the producer string. */
7869 if (debug_info_level > DINFO_LEVEL_TERSE)
7870 strcat (producer, " -g");
7873 add_AT_string (comp_unit_die, DW_AT_producer, producer);
7875 if (strcmp (language_string, "GNU C++") == 0)
7876 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
7878 else if (strcmp (language_string, "GNU Ada") == 0)
7879 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
7881 else if (strcmp (language_string, "GNU F77") == 0)
7882 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77);
7884 else if (flag_traditional)
7885 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
7888 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
7890 #if 0 /* unimplemented */
7891 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
7892 add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
7896 /* Generate a DIE for a string type. */
7899 gen_string_type_die (type, context_die)
7901 register dw_die_ref context_die;
7903 register dw_die_ref type_die
7904 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
7906 equate_type_number_to_die (type, type_die);
7908 /* Fudge the string length attribute for now. */
7910 /* TODO: add string length info.
7911 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
7912 bound_representation (upper_bound, 0, 'u'); */
7915 /* Generate the DIE for a base class. */
7918 gen_inheritance_die (binfo, context_die)
7919 register tree binfo;
7920 register dw_die_ref context_die;
7922 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
7924 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
7925 add_data_member_location_attribute (die, binfo);
7927 if (TREE_VIA_VIRTUAL (binfo))
7928 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7929 if (TREE_VIA_PUBLIC (binfo))
7930 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
7931 else if (TREE_VIA_PROTECTED (binfo))
7932 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
7935 /* Genearate a DIE for a class member. */
7938 gen_member_die (type, context_die)
7940 register dw_die_ref context_die;
7942 register tree member;
7944 /* If this is not an incomplete type, output descriptions of each of its
7945 members. Note that as we output the DIEs necessary to represent the
7946 members of this record or union type, we will also be trying to output
7947 DIEs to represent the *types* of those members. However the `type'
7948 function (above) will specifically avoid generating type DIEs for member
7949 types *within* the list of member DIEs for this (containing) type execpt
7950 for those types (of members) which are explicitly marked as also being
7951 members of this (containing) type themselves. The g++ front- end can
7952 force any given type to be treated as a member of some other
7953 (containing) type by setting the TYPE_CONTEXT of the given (member) type
7954 to point to the TREE node representing the appropriate (containing)
7957 /* First output info about the base classes. */
7958 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
7960 register tree bases = TYPE_BINFO_BASETYPES (type);
7961 register int n_bases = TREE_VEC_LENGTH (bases);
7964 for (i = 0; i < n_bases; i++)
7965 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
7968 /* Now output info about the data members and type members. */
7969 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
7970 gen_decl_die (member, context_die);
7972 /* Now output info about the function members (if any). */
7973 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
7974 gen_decl_die (member, context_die);
7977 /* Generate a DIE for a structure or union type. */
7980 gen_struct_or_union_type_die (type, context_die)
7982 register dw_die_ref context_die;
7984 register dw_die_ref type_die = lookup_type_die (type);
7985 register dw_die_ref scope_die = 0;
7986 register int nested = 0;
7988 if (type_die && ! TYPE_SIZE (type))
7991 if (TYPE_CONTEXT (type) != NULL_TREE
7992 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't')
7995 scope_die = scope_die_for (type, context_die);
7997 if (! type_die || (nested && scope_die == comp_unit_die))
7998 /* First occurrence of type or toplevel definition of nested class. */
8000 register dw_die_ref old_die = type_die;
8002 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
8003 ? DW_TAG_structure_type : DW_TAG_union_type,
8005 equate_type_number_to_die (type, type_die);
8006 add_name_attribute (type_die, type_tag (type));
8008 add_AT_die_ref (type_die, DW_AT_specification, old_die);
8011 remove_AT (type_die, DW_AT_declaration);
8013 /* If we're not in the right context to be defining this type, defer to
8014 avoid tricky recursion. */
8015 if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die)
8017 add_AT_flag (type_die, DW_AT_declaration, 1);
8020 /* If this type has been completed, then give it a byte_size attribute and
8021 then give a list of members. */
8022 else if (TYPE_SIZE (type))
8024 /* Prevent infinite recursion in cases where the type of some member of
8025 this type is expressed in terms of this type itself. */
8026 TREE_ASM_WRITTEN (type) = 1;
8027 add_byte_size_attribute (type_die, type);
8028 if (type_tag (type))
8029 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8031 push_decl_scope (type);
8032 gen_member_die (type, type_die);
8035 /* GNU extension: Record what type our vtable lives in. */
8036 if (TYPE_VFIELD (type))
8038 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
8040 gen_type_die (vtype, context_die);
8041 add_AT_die_ref (type_die, DW_AT_containing_type,
8042 lookup_type_die (vtype));
8046 add_AT_flag (type_die, DW_AT_declaration, 1);
8049 /* Generate a DIE for a subroutine _type_. */
8052 gen_subroutine_type_die (type, context_die)
8054 register dw_die_ref context_die;
8056 register tree return_type = TREE_TYPE (type);
8057 register dw_die_ref subr_die
8058 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
8060 equate_type_number_to_die (type, subr_die);
8061 add_prototyped_attribute (subr_die, type);
8062 add_type_attribute (subr_die, return_type, 0, 0, context_die);
8063 gen_formal_types_die (type, subr_die);
8066 /* Generate a DIE for a type definition */
8069 gen_typedef_die (decl, context_die)
8071 register dw_die_ref context_die;
8073 register dw_die_ref type_die;
8074 register tree origin;
8076 if (TREE_ASM_WRITTEN (decl))
8078 TREE_ASM_WRITTEN (decl) = 1;
8080 type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
8081 origin = decl_ultimate_origin (decl);
8083 add_abstract_origin_attribute (type_die, origin);
8087 add_name_and_src_coords_attributes (type_die, decl);
8088 if (DECL_ORIGINAL_TYPE (decl))
8090 type = DECL_ORIGINAL_TYPE (decl);
8091 equate_type_number_to_die (TREE_TYPE (decl), type_die);
8094 type = TREE_TYPE (decl);
8095 add_type_attribute (type_die, type, TREE_READONLY (decl),
8096 TREE_THIS_VOLATILE (decl), context_die);
8099 if (DECL_ABSTRACT (decl))
8100 equate_decl_number_to_die (decl, type_die);
8103 /* Generate a type description DIE. */
8106 gen_type_die (type, context_die)
8108 register dw_die_ref context_die;
8110 if (type == NULL_TREE || type == error_mark_node)
8113 /* We are going to output a DIE to represent the unqualified version of of
8114 this type (i.e. without any const or volatile qualifiers) so get the
8115 main variant (i.e. the unqualified version) of this type now. */
8116 type = type_main_variant (type);
8118 if (TREE_ASM_WRITTEN (type))
8121 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8122 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
8124 TREE_ASM_WRITTEN (type) = 1;
8125 gen_decl_die (TYPE_NAME (type), context_die);
8129 switch (TREE_CODE (type))
8135 case REFERENCE_TYPE:
8136 /* For these types, all that is required is that we output a DIE (or a
8137 set of DIEs) to represent the "basis" type. */
8138 gen_type_die (TREE_TYPE (type), context_die);
8142 /* This code is used for C++ pointer-to-data-member types.
8143 Output a description of the relevant class type. */
8144 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
8146 /* Output a description of the type of the object pointed to. */
8147 gen_type_die (TREE_TYPE (type), context_die);
8149 /* Now output a DIE to represent this pointer-to-data-member type
8151 gen_ptr_to_mbr_type_die (type, context_die);
8155 gen_type_die (TYPE_DOMAIN (type), context_die);
8156 gen_set_type_die (type, context_die);
8160 gen_type_die (TREE_TYPE (type), context_die);
8161 abort (); /* No way to represent these in Dwarf yet! */
8165 /* Force out return type (in case it wasn't forced out already). */
8166 gen_type_die (TREE_TYPE (type), context_die);
8167 gen_subroutine_type_die (type, context_die);
8171 /* Force out return type (in case it wasn't forced out already). */
8172 gen_type_die (TREE_TYPE (type), context_die);
8173 gen_subroutine_type_die (type, context_die);
8177 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
8179 gen_type_die (TREE_TYPE (type), context_die);
8180 gen_string_type_die (type, context_die);
8183 gen_array_type_die (type, context_die);
8189 case QUAL_UNION_TYPE:
8190 /* If this is a nested type whose containing class hasn't been
8191 written out yet, writing it out will cover this one, too. */
8192 if (TYPE_CONTEXT (type)
8193 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
8194 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8196 gen_type_die (TYPE_CONTEXT (type), context_die);
8198 if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8201 /* If that failed, attach ourselves to the stub. */
8202 push_decl_scope (TYPE_CONTEXT (type));
8203 context_die = lookup_type_die (TYPE_CONTEXT (type));
8206 if (TREE_CODE (type) == ENUMERAL_TYPE)
8207 gen_enumeration_type_die (type, context_die);
8209 gen_struct_or_union_type_die (type, context_die);
8211 if (TYPE_CONTEXT (type)
8212 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
8213 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8216 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
8217 it up if it is ever completed. gen_*_type_die will set it for us
8218 when appropriate. */
8227 /* No DIEs needed for fundamental types. */
8231 /* No Dwarf representation currently defined. */
8238 TREE_ASM_WRITTEN (type) = 1;
8241 /* Generate a DIE for a tagged type instantiation. */
8244 gen_tagged_type_instantiation_die (type, context_die)
8246 register dw_die_ref context_die;
8248 if (type == NULL_TREE || type == error_mark_node)
8251 /* We are going to output a DIE to represent the unqualified version of of
8252 this type (i.e. without any const or volatile qualifiers) so make sure
8253 that we have the main variant (i.e. the unqualified version) of this
8255 assert (type == type_main_variant (type));
8256 assert (TREE_ASM_WRITTEN (type));
8258 switch (TREE_CODE (type))
8264 gen_inlined_enumeration_type_die (type, context_die);
8268 gen_inlined_structure_type_die (type, context_die);
8272 case QUAL_UNION_TYPE:
8273 gen_inlined_union_type_die (type, context_die);
8281 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
8282 things which are local to the given block. */
8285 gen_block_die (stmt, context_die, depth)
8287 register dw_die_ref context_die;
8290 register int must_output_die = 0;
8291 register tree origin;
8293 register enum tree_code origin_code;
8295 /* Ignore blocks never really used to make RTL. */
8297 if (stmt == NULL_TREE || !TREE_USED (stmt))
8300 /* Determine the "ultimate origin" of this block. This block may be an
8301 inlined instance of an inlined instance of inline function, so we have
8302 to trace all of the way back through the origin chain to find out what
8303 sort of node actually served as the original seed for the creation of
8304 the current block. */
8305 origin = block_ultimate_origin (stmt);
8306 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
8308 /* Determine if we need to output any Dwarf DIEs at all to represent this
8310 if (origin_code == FUNCTION_DECL)
8311 /* The outer scopes for inlinings *must* always be represented. We
8312 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
8313 must_output_die = 1;
8316 /* In the case where the current block represents an inlining of the
8317 "body block" of an inline function, we must *NOT* output any DIE for
8318 this block because we have already output a DIE to represent the
8319 whole inlined function scope and the "body block" of any function
8320 doesn't really represent a different scope according to ANSI C
8321 rules. So we check here to make sure that this block does not
8322 represent a "body block inlining" before trying to set the
8323 `must_output_die' flag. */
8324 if (! is_body_block (origin ? origin : stmt))
8326 /* Determine if this block directly contains any "significant"
8327 local declarations which we will need to output DIEs for. */
8328 if (debug_info_level > DINFO_LEVEL_TERSE)
8329 /* We are not in terse mode so *any* local declaration counts
8330 as being a "significant" one. */
8331 must_output_die = (BLOCK_VARS (stmt) != NULL);
8333 /* We are in terse mode, so only local (nested) function
8334 definitions count as "significant" local declarations. */
8335 for (decl = BLOCK_VARS (stmt);
8336 decl != NULL; decl = TREE_CHAIN (decl))
8337 if (TREE_CODE (decl) == FUNCTION_DECL
8338 && DECL_INITIAL (decl))
8340 must_output_die = 1;
8346 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
8347 DIE for any block which contains no significant local declarations at
8348 all. Rather, in such cases we just call `decls_for_scope' so that any
8349 needed Dwarf info for any sub-blocks will get properly generated. Note
8350 that in terse mode, our definition of what constitutes a "significant"
8351 local declaration gets restricted to include only inlined function
8352 instances and local (nested) function definitions. */
8353 if (must_output_die)
8355 if (origin_code == FUNCTION_DECL)
8356 gen_inlined_subroutine_die (stmt, context_die, depth);
8358 gen_lexical_block_die (stmt, context_die, depth);
8361 decls_for_scope (stmt, context_die, depth);
8364 /* Generate all of the decls declared within a given scope and (recursively)
8365 all of it's sub-blocks. */
8368 decls_for_scope (stmt, context_die, depth)
8370 register dw_die_ref context_die;
8374 register tree subblocks;
8376 /* Ignore blocks never really used to make RTL. */
8377 if (stmt == NULL_TREE || ! TREE_USED (stmt))
8380 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
8381 next_block_number++;
8383 /* Output the DIEs to represent all of the data objects and typedefs
8384 declared directly within this block but not within any nested
8385 sub-blocks. Also, nested function and tag DIEs have been
8386 generated with a parent of NULL; fix that up now. */
8387 for (decl = BLOCK_VARS (stmt);
8388 decl != NULL; decl = TREE_CHAIN (decl))
8390 register dw_die_ref die;
8392 if (TREE_CODE (decl) == FUNCTION_DECL)
8393 die = lookup_decl_die (decl);
8394 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
8395 die = lookup_type_die (TREE_TYPE (decl));
8399 if (die != NULL && die->die_parent == NULL)
8401 add_child_die (context_die, die);
8405 gen_decl_die (decl, context_die);
8408 /* Output the DIEs to represent all sub-blocks (and the items declared
8409 therein) of this block. */
8410 for (subblocks = BLOCK_SUBBLOCKS (stmt);
8412 subblocks = BLOCK_CHAIN (subblocks))
8413 gen_block_die (subblocks, context_die, depth + 1);
8416 /* Is this a typedef we can avoid emitting? */
8419 is_redundant_typedef (decl)
8422 if (TYPE_DECL_IS_STUB (decl))
8425 if (DECL_ARTIFICIAL (decl)
8426 && DECL_CONTEXT (decl)
8427 && is_tagged_type (DECL_CONTEXT (decl))
8428 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
8429 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
8430 /* Also ignore the artificial member typedef for the class name. */
8436 /* Generate Dwarf debug information for a decl described by DECL. */
8439 gen_decl_die (decl, context_die)
8441 register dw_die_ref context_die;
8443 register tree origin;
8445 /* Make a note of the decl node we are going to be working on. We may need
8446 to give the user the source coordinates of where it appeared in case we
8447 notice (later on) that something about it looks screwy. */
8448 dwarf_last_decl = decl;
8450 if (TREE_CODE (decl) == ERROR_MARK)
8453 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
8454 ignore a function definition, since that would screw up our count of
8455 blocks, and that it turn will completely screw up the the labels we will
8456 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
8457 subsequent blocks). */
8458 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
8461 switch (TREE_CODE (decl))
8464 /* The individual enumerators of an enum type get output when we output
8465 the Dwarf representation of the relevant enum type itself. */
8469 /* Don't output any DIEs to represent mere function declarations,
8470 unless they are class members or explicit block externs. */
8471 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
8472 && (current_function_decl == NULL_TREE || ! DECL_ARTIFICIAL (decl)))
8475 if (debug_info_level > DINFO_LEVEL_TERSE)
8477 /* Before we describe the FUNCTION_DECL itself, make sure that we
8478 have described its return type. */
8479 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
8481 /* And its containing type. */
8482 origin = decl_class_context (decl);
8483 if (origin != NULL_TREE)
8484 gen_type_die (origin, context_die);
8486 /* And its virtual context. */
8487 if (DECL_VINDEX (decl) != NULL_TREE)
8488 gen_type_die (DECL_CONTEXT (decl), context_die);
8491 /* Now output a DIE to represent the function itself. */
8492 gen_subprogram_die (decl, context_die);
8496 /* If we are in terse mode, don't generate any DIEs to represent any
8498 if (debug_info_level <= DINFO_LEVEL_TERSE)
8501 /* In the special case of a TYPE_DECL node representing the
8502 declaration of some type tag, if the given TYPE_DECL is marked as
8503 having been instantiated from some other (original) TYPE_DECL node
8504 (e.g. one which was generated within the original definition of an
8505 inline function) we have to generate a special (abbreviated)
8506 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration-type
8508 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
8510 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
8514 if (is_redundant_typedef (decl))
8515 gen_type_die (TREE_TYPE (decl), context_die);
8517 /* Output a DIE to represent the typedef itself. */
8518 gen_typedef_die (decl, context_die);
8522 if (debug_info_level >= DINFO_LEVEL_NORMAL)
8523 gen_label_die (decl, context_die);
8527 /* If we are in terse mode, don't generate any DIEs to represent any
8528 variable declarations or definitions. */
8529 if (debug_info_level <= DINFO_LEVEL_TERSE)
8532 /* Output any DIEs that are needed to specify the type of this data
8534 gen_type_die (TREE_TYPE (decl), context_die);
8536 /* And its containing type. */
8537 origin = decl_class_context (decl);
8538 if (origin != NULL_TREE)
8539 gen_type_die (origin, context_die);
8541 /* Now output the DIE to represent the data object itself. This gets
8542 complicated because of the possibility that the VAR_DECL really
8543 represents an inlined instance of a formal parameter for an inline
8545 origin = decl_ultimate_origin (decl);
8546 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
8547 gen_formal_parameter_die (decl, context_die);
8549 gen_variable_die (decl, context_die);
8553 /* Ignore the nameless fields that are used to skip bits, but
8554 handle C++ anonymous unions. */
8555 if (DECL_NAME (decl) != NULL_TREE
8556 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
8558 gen_type_die (member_declared_type (decl), context_die);
8559 gen_field_die (decl, context_die);
8564 gen_type_die (TREE_TYPE (decl), context_die);
8565 gen_formal_parameter_die (decl, context_die);
8573 /* Write the debugging output for DECL. */
8576 dwarf2out_decl (decl)
8579 register dw_die_ref context_die = comp_unit_die;
8581 if (TREE_CODE (decl) == ERROR_MARK)
8584 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
8585 hope that the node in question doesn't represent a function definition.
8586 If it does, then totally ignoring it is bound to screw up our count of
8587 blocks, and that it turn will completely screw up the the labels we will
8588 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
8589 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
8590 own sequence numbers with them!) */
8591 if (DECL_IGNORED_P (decl))
8593 if (TREE_CODE (decl) == FUNCTION_DECL
8594 && DECL_INITIAL (decl) != NULL)
8600 switch (TREE_CODE (decl))
8603 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
8604 builtin function. Explicit programmer-supplied declarations of
8605 these same functions should NOT be ignored however. */
8606 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
8609 /* What we would really like to do here is to filter out all mere
8610 file-scope declarations of file-scope functions which are never
8611 referenced later within this translation unit (and keep all of ones
8612 that *are* referenced later on) but we aren't clarvoiant, so we have
8613 no idea which functions will be referenced in the future (i.e. later
8614 on within the current translation unit). So here we just ignore all
8615 file-scope function declarations which are not also definitions. If
8616 and when the debugger needs to know something about these funcstion,
8617 it wil have to hunt around and find the DWARF information associated
8618 with the definition of the function. Note that we can't just check
8619 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
8620 definitions and which ones represent mere declarations. We have to
8621 check `DECL_INITIAL' instead. That's because the C front-end
8622 supports some weird semantics for "extern inline" function
8623 definitions. These can get inlined within the current translation
8624 unit (an thus, we need to generate DWARF info for their abstract
8625 instances so that the DWARF info for the concrete inlined instances
8626 can have something to refer to) but the compiler never generates any
8627 out-of-lines instances of such things (despite the fact that they
8628 *are* definitions). The important point is that the C front-end
8629 marks these "extern inline" functions as DECL_EXTERNAL, but we need
8630 to generate DWARF for them anyway. Note that the C++ front-end also
8631 plays some similar games for inline function definitions appearing
8632 within include files which also contain
8633 `#pragma interface' pragmas. */
8634 if (DECL_INITIAL (decl) == NULL_TREE)
8637 /* If we're a nested function, initially use a parent of NULL; if we're
8638 a plain function, this will be fixed up in decls_for_scope. If
8639 we're a method, it will be ignored, since we already have a DIE. */
8640 if (decl_function_context (decl))
8646 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
8647 declaration and if the declaration was never even referenced from
8648 within this entire compilation unit. We suppress these DIEs in
8649 order to save space in the .debug section (by eliminating entries
8650 which are probably useless). Note that we must not suppress
8651 block-local extern declarations (whether used or not) because that
8652 would screw-up the debugger's name lookup mechanism and cause it to
8653 miss things which really ought to be in scope at a given point. */
8654 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
8657 /* If we are in terse mode, don't generate any DIEs to represent any
8658 variable declarations or definitions. */
8659 if (debug_info_level <= DINFO_LEVEL_TERSE)
8664 /* Don't bother trying to generate any DIEs to represent any of the
8665 normal built-in types for the language we are compiling. */
8666 if (DECL_SOURCE_LINE (decl) == 0)
8668 /* OK, we need to generate one for `bool' so GDB knows what type
8669 comparisons have. */
8670 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
8671 == DW_LANG_C_plus_plus)
8672 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
8673 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
8678 /* If we are in terse mode, don't generate any DIEs for types. */
8679 if (debug_info_level <= DINFO_LEVEL_TERSE)
8682 /* If we're a function-scope tag, initially use a parent of NULL;
8683 this will be fixed up in decls_for_scope. */
8684 if (decl_function_context (decl))
8693 gen_decl_die (decl, context_die);
8694 output_pending_types_for_scope (comp_unit_die);
8697 /* Output a marker (i.e. a label) for the beginning of the generated code for
8701 dwarf2out_begin_block (blocknum)
8702 register unsigned blocknum;
8704 function_section (current_function_decl);
8705 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
8708 /* Output a marker (i.e. a label) for the end of the generated code for a
8712 dwarf2out_end_block (blocknum)
8713 register unsigned blocknum;
8715 function_section (current_function_decl);
8716 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
8719 /* Output a marker (i.e. a label) at a point in the assembly code which
8720 corresponds to a given source level label. */
8723 dwarf2out_label (insn)
8726 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8728 if (debug_info_level >= DINFO_LEVEL_NORMAL)
8730 function_section (current_function_decl);
8731 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
8732 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
8733 (unsigned) INSN_UID (insn));
8737 /* Lookup a filename (in the list of filenames that we know about here in
8738 dwarf2out.c) and return its "index". The index of each (known) filename is
8739 just a unique number which is associated with only that one filename.
8740 We need such numbers for the sake of generating labels
8741 (in the .debug_sfnames section) and references to those
8742 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
8743 If the filename given as an argument is not found in our current list,
8744 add it to the list and assign it the next available unique index number.
8745 In order to speed up searches, we remember the index of the filename
8746 was looked up last. This handles the majority of all searches. */
8749 lookup_filename (file_name)
8752 static unsigned last_file_lookup_index = 0;
8753 register unsigned i;
8755 /* Check to see if the file name that was searched on the previous call
8756 matches this file name. If so, return the index. */
8757 if (last_file_lookup_index != 0)
8758 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
8759 return last_file_lookup_index;
8761 /* Didn't match the previous lookup, search the table */
8762 for (i = 1; i < file_table_in_use; ++i)
8763 if (strcmp (file_name, file_table[i]) == 0)
8765 last_file_lookup_index = i;
8769 /* Prepare to add a new table entry by making sure there is enough space in
8770 the table to do so. If not, expand the current table. */
8771 if (file_table_in_use == file_table_allocated)
8773 file_table_allocated += FILE_TABLE_INCREMENT;
8775 = (char **) xrealloc (file_table,
8776 file_table_allocated * sizeof (char *));
8779 /* Add the new entry to the end of the filename table. */
8780 file_table[file_table_in_use] = xstrdup (file_name);
8781 last_file_lookup_index = file_table_in_use++;
8783 return last_file_lookup_index;
8786 /* Output a label to mark the beginning of a source code line entry
8787 and record information relating to this source line, in
8788 'line_info_table' for later output of the .debug_line section. */
8791 dwarf2out_line (filename, line)
8792 register char *filename;
8793 register unsigned line;
8795 if (debug_info_level >= DINFO_LEVEL_NORMAL)
8797 function_section (current_function_decl);
8799 if (DECL_SECTION_NAME (current_function_decl))
8801 register dw_separate_line_info_ref line_info;
8802 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
8803 separate_line_info_table_in_use);
8804 fputc ('\n', asm_out_file);
8806 /* expand the line info table if necessary */
8807 if (separate_line_info_table_in_use
8808 == separate_line_info_table_allocated)
8810 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
8811 separate_line_info_table
8812 = (dw_separate_line_info_ref)
8813 xrealloc (separate_line_info_table,
8814 separate_line_info_table_allocated
8815 * sizeof (dw_separate_line_info_entry));
8818 /* Add the new entry at the end of the line_info_table. */
8820 = &separate_line_info_table[separate_line_info_table_in_use++];
8821 line_info->dw_file_num = lookup_filename (filename);
8822 line_info->dw_line_num = line;
8823 line_info->function = current_funcdef_number;
8827 register dw_line_info_ref line_info;
8829 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
8830 line_info_table_in_use);
8831 fputc ('\n', asm_out_file);
8833 /* Expand the line info table if necessary. */
8834 if (line_info_table_in_use == line_info_table_allocated)
8836 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
8838 = (dw_line_info_ref)
8839 xrealloc (line_info_table,
8840 (line_info_table_allocated
8841 * sizeof (dw_line_info_entry)));
8844 /* Add the new entry at the end of the line_info_table. */
8845 line_info = &line_info_table[line_info_table_in_use++];
8846 line_info->dw_file_num = lookup_filename (filename);
8847 line_info->dw_line_num = line;
8852 /* Record the beginning of a new source file, for later output
8853 of the .debug_macinfo section. At present, unimplemented. */
8856 dwarf2out_start_source_file (filename)
8857 register char *filename;
8861 /* Record the end of a source file, for later output
8862 of the .debug_macinfo section. At present, unimplemented. */
8865 dwarf2out_end_source_file ()
8869 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
8870 the tail part of the directive line, i.e. the part which is past the
8871 initial whitespace, #, whitespace, directive-name, whitespace part. */
8874 dwarf2out_define (lineno, buffer)
8875 register unsigned lineno;
8876 register char *buffer;
8878 static int initialized = 0;
8881 dwarf2out_start_source_file (primary_filename);
8886 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
8887 the tail part of the directive line, i.e. the part which is past the
8888 initial whitespace, #, whitespace, directive-name, whitespace part. */
8891 dwarf2out_undef (lineno, buffer)
8892 register unsigned lineno;
8893 register char *buffer;
8897 /* Set up for Dwarf output at the start of compilation. */
8900 dwarf2out_init (asm_out_file, main_input_filename)
8901 register FILE *asm_out_file;
8902 register char *main_input_filename;
8904 /* Remember the name of the primary input file. */
8905 primary_filename = main_input_filename;
8907 /* Allocate the initial hunk of the file_table. */
8908 file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *));
8909 bzero ((char *) file_table, FILE_TABLE_INCREMENT * sizeof (char *));
8910 file_table_allocated = FILE_TABLE_INCREMENT;
8912 /* Skip the first entry - file numbers begin at 1. */
8913 file_table_in_use = 1;
8915 /* Allocate the initial hunk of the decl_die_table. */
8917 = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8918 bzero ((char *) decl_die_table,
8919 DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8920 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
8921 decl_die_table_in_use = 0;
8923 /* Allocate the initial hunk of the decl_scope_table. */
8925 = (tree *) xmalloc (DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
8926 bzero ((char *) decl_scope_table,
8927 DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
8928 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
8929 decl_scope_depth = 0;
8931 /* Allocate the initial hunk of the abbrev_die_table. */
8933 = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT
8934 * sizeof (dw_die_ref));
8935 bzero ((char *) abbrev_die_table,
8936 ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8937 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
8938 /* Zero-th entry is allocated, but unused */
8939 abbrev_die_table_in_use = 1;
8941 /* Allocate the initial hunk of the line_info_table. */
8943 = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT
8944 * sizeof (dw_line_info_entry));
8945 bzero ((char *) line_info_table,
8946 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
8947 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
8948 /* Zero-th entry is allocated, but unused */
8949 line_info_table_in_use = 1;
8951 /* Generate the initial DIE for the .debug section. Note that the (string)
8952 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
8953 will (typically) be a relative pathname and that this pathname should be
8954 taken as being relative to the directory from which the compiler was
8955 invoked when the given (base) source file was compiled. */
8956 gen_compile_unit_die (main_input_filename);
8958 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
8960 /* Initialize the frame unwind information. Eventually this should be
8961 called from compile_file instead. */
8962 dwarf2out_frame_init ();
8965 /* Output stuff that dwarf requires at the end of every file,
8966 and generate the DWARF-2 debugging info. */
8971 /* Traverse the DIE tree and add sibling attributes to those DIE's
8972 that have children. */
8973 add_sibling_attributes (comp_unit_die);
8975 /* Output a terminator label for the .text section. */
8976 fputc ('\n', asm_out_file);
8977 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
8978 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
8981 /* Output a terminator label for the .data section. */
8982 fputc ('\n', asm_out_file);
8983 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
8984 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
8986 /* Output a terminator label for the .bss section. */
8987 fputc ('\n', asm_out_file);
8988 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
8989 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
8992 /* Output the frame unwind information. Eventually this should be called
8993 from compile_file instead. */
8994 dwarf2out_frame_finish ();
8996 /* Output the source line correspondence table. */
8997 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
8999 fputc ('\n', asm_out_file);
9000 ASM_OUTPUT_SECTION (asm_out_file, LINE_SECTION);
9001 output_line_info ();
9003 /* We can only use the low/high_pc attributes if all of the code
9005 if (separate_line_info_table_in_use == 0)
9007 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_SECTION);
9008 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
9011 add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, LINE_SECTION);
9014 /* Output the abbreviation table. */
9015 fputc ('\n', asm_out_file);
9016 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9017 build_abbrev_table (comp_unit_die);
9018 output_abbrev_section ();
9020 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9021 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9022 calc_die_sizes (comp_unit_die);
9024 /* Output debugging information. */
9025 fputc ('\n', asm_out_file);
9026 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_SECTION);
9027 output_compilation_unit_header ();
9028 output_die (comp_unit_die);
9030 if (pubname_table_in_use)
9032 /* Output public names table. */
9033 fputc ('\n', asm_out_file);
9034 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
9038 if (fde_table_in_use)
9040 /* Output the address range information. */
9041 fputc ('\n', asm_out_file);
9042 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
9046 /* The only DIE we should have with a parent of NULL is comp_unit_die. */
9047 assert (limbo_die_count == 1);
9049 #endif /* DWARF2_DEBUGGING_INFO */