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 typedef struct dw_cfi_struct *dw_cfi_ref;
56 typedef struct dw_fde_struct *dw_fde_ref;
57 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
59 /* Call frames are described using a sequence of Call Frame
60 Information instructions. The register number, offset
61 and address fields are provided as possible operands;
62 their use is selected by the opcode field. */
64 typedef union dw_cfi_oprnd_struct
66 unsigned long dw_cfi_reg_num;
67 long int dw_cfi_offset;
72 typedef struct dw_cfi_struct
74 dw_cfi_ref dw_cfi_next;
75 enum dwarf_call_frame_info dw_cfi_opc;
76 dw_cfi_oprnd dw_cfi_oprnd1;
77 dw_cfi_oprnd dw_cfi_oprnd2;
81 /* All call frame descriptions (FDE's) in the GCC generated DWARF
82 refer to a single Common Information Entry (CIE), defined at
83 the beginning of the .debug_frame section. This used of a single
84 CIE obviates the need to keep track of multiple CIE's
85 in the DWARF generation routines below. */
87 typedef struct dw_fde_struct
89 unsigned long dw_fde_offset;
91 char *dw_fde_current_label;
93 dw_cfi_ref dw_fde_cfi;
97 /* Maximum size (in bytes) of an artificially generated label. */
98 #define MAX_ARTIFICIAL_LABEL_BYTES 30
100 /* Make sure we know the sizes of the various types dwarf can describe. These
101 are only defaults. If the sizes are different for your target, you should
102 override these values by defining the appropriate symbols in your tm.h
105 #ifndef CHAR_TYPE_SIZE
106 #define CHAR_TYPE_SIZE BITS_PER_UNIT
109 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
112 /* The size in bytes of a DWARF field indicating an offset or length
113 relative to a debug info section, specified to be 4 bytes in the DWARF-2
114 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
116 #ifndef DWARF_OFFSET_SIZE
117 #define DWARF_OFFSET_SIZE 4
120 #define DWARF_VERSION 2
122 /* Round SIZE up to the nearest BOUNDARY. */
123 #define DWARF_ROUND(SIZE,BOUNDARY) \
124 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
126 /* Fixed size portion of the CIE (including the length field). */
127 #define DWARF_CIE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 5)
129 /* The un-padded size of the CIE. Initialized in calc_fde_sizes, used
130 in output_call_frame_info. */
131 static unsigned cie_size;
133 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
134 #ifdef STACK_GROWS_DOWNWARD
135 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
137 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
140 /* Fixed size portion of the FDE. */
141 #define DWARF_FDE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2 * PTR_SIZE)
143 /* This location is used by calc_fde_sizes() to keep track
144 the offset of each FDE within the .debug_frame section. */
145 static unsigned long next_fde_offset;
147 /* A pointer to the base of a table that contains frame description
148 information for each routine. */
149 static dw_fde_ref fde_table;
151 /* Number of elements currently allocated for fde_table. */
152 static unsigned fde_table_allocated;
154 /* Number of elements in fde_table currently in use. */
155 static unsigned fde_table_in_use;
157 /* Size (in elements) of increments by which we may expand the
159 #define FDE_TABLE_INCREMENT 256
161 /* A list of call frame insns for the CIE. */
162 static dw_cfi_ref cie_cfi_head;
164 /* The number of the current function definition for which debugging
165 information is being generated. These numbers range from 1 up to the
166 maximum number of function definitions contained within the current
167 compilation unit. These numbers are used to create unique label id's
168 unique to each function definition. */
169 static unsigned current_funcdef_number = 0;
171 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
172 attribute that accelerates the lookup of the FDE associated
173 with the subprogram. This variable holds the table index of the FDE
174 associated with the current function (body) definition. */
175 static unsigned current_funcdef_fde;
177 /* Forward declarations for functions defined in this file. */
179 static char *stripattributes PROTO((char *));
180 static char *dwarf_cfi_name PROTO((unsigned));
181 static dw_cfi_ref new_cfi PROTO((void));
182 static void add_cfi PROTO((dw_cfi_ref *, dw_cfi_ref));
183 static unsigned long size_of_uleb128 PROTO((unsigned long));
184 static unsigned long size_of_sleb128 PROTO((long));
185 static void output_uleb128 PROTO((unsigned long));
186 static void output_sleb128 PROTO((long));
187 static char *dwarf2out_cfi_label PROTO((void));
188 static void add_fde_cfi PROTO((char *, dw_cfi_ref));
189 static void lookup_cfa_1 PROTO((dw_cfi_ref, unsigned long *,
191 static void lookup_cfa PROTO((unsigned long *, long *));
192 static void reg_save PROTO((char *, unsigned, unsigned,
194 static void initial_return_save PROTO((rtx));
195 static unsigned long size_of_cfi PROTO((dw_cfi_ref));
196 static unsigned long size_of_fde PROTO((dw_fde_ref, unsigned long *));
197 static void calc_fde_sizes PROTO((void));
198 static void output_cfi PROTO((dw_cfi_ref, dw_fde_ref));
199 static void output_call_frame_info PROTO((int));
200 static unsigned reg_number PROTO((rtx));
202 /* Definitions of defaults for assembler-dependent names of various
203 pseudo-ops and section names.
204 Theses may be overridden in the tm.h file (if necessary) for a particular
207 #ifndef UNALIGNED_SHORT_ASM_OP
208 #define UNALIGNED_SHORT_ASM_OP ".2byte"
210 #ifndef UNALIGNED_INT_ASM_OP
211 #define UNALIGNED_INT_ASM_OP ".4byte"
213 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
214 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
217 #define ASM_BYTE_OP ".byte"
220 #ifndef UNALIGNED_OFFSET_ASM_OP
221 #define UNALIGNED_OFFSET_ASM_OP \
222 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
225 #ifndef UNALIGNED_WORD_ASM_OP
226 #define UNALIGNED_WORD_ASM_OP \
227 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
230 /* Data and reference forms for relocatable data. */
231 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
232 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
234 /* Pseudo-op for defining a new section. */
235 #ifndef SECTION_ASM_OP
236 #define SECTION_ASM_OP ".section"
239 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
240 print the SECTION_ASM_OP and the section name. The default here works for
241 almost all svr4 assemblers, except for the sparc, where the section name
242 must be enclosed in double quotes. (See sparcv4.h). */
243 #ifndef SECTION_FORMAT
244 #define SECTION_FORMAT "\t%s\t%s\n"
247 #ifndef FRAME_SECTION
248 #define FRAME_SECTION ".debug_frame"
250 #if !defined (EH_FRAME_SECTION) && defined (ASM_OUTPUT_SECTION_NAME)
251 #define EH_FRAME_SECTION ".eh_frame"
254 #ifndef FUNC_BEGIN_LABEL
255 #define FUNC_BEGIN_LABEL "LFB"
257 #ifndef FUNC_END_LABEL
258 #define FUNC_END_LABEL "LFE"
261 /* Definitions of defaults for various types of primitive assembly language
262 output operations. These may be overridden from within the tm.h file,
263 but typically, that is unecessary. */
265 #ifndef ASM_OUTPUT_SECTION
266 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
267 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
270 #ifndef ASM_OUTPUT_DWARF_DELTA2
271 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
272 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
273 assemble_name (FILE, LABEL1); \
274 fprintf (FILE, "-"); \
275 assemble_name (FILE, LABEL2); \
279 #ifndef ASM_OUTPUT_DWARF_DELTA4
280 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
281 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
282 assemble_name (FILE, LABEL1); \
283 fprintf (FILE, "-"); \
284 assemble_name (FILE, LABEL2); \
288 #ifndef ASM_OUTPUT_DWARF_DELTA
289 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
290 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
291 assemble_name (FILE, LABEL1); \
292 fprintf (FILE, "-"); \
293 assemble_name (FILE, LABEL2); \
297 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
298 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
299 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
300 assemble_name (FILE, LABEL1); \
301 fprintf (FILE, "-"); \
302 assemble_name (FILE, LABEL2); \
306 #ifndef ASM_OUTPUT_DWARF_ADDR
307 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
308 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
309 assemble_name (FILE, LABEL); \
313 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
314 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
315 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
318 #ifndef ASM_OUTPUT_DWARF_OFFSET
319 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
320 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
321 assemble_name (FILE, LABEL); \
325 #ifndef ASM_OUTPUT_DWARF_DATA1
326 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
327 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
330 #ifndef ASM_OUTPUT_DWARF_DATA2
331 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
332 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
335 #ifndef ASM_OUTPUT_DWARF_DATA4
336 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
337 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
340 #ifndef ASM_OUTPUT_DWARF_DATA
341 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
342 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
343 (unsigned long) VALUE)
346 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
347 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
348 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
349 (unsigned long) VALUE)
352 #ifndef ASM_OUTPUT_DWARF_DATA8
353 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
355 if (WORDS_BIG_ENDIAN) \
357 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
358 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
362 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
363 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
368 /* The DWARF 2 CFA column which tracks the return address. Normally this
369 is the column for PC, or the first column after all of the hard
371 #ifndef DWARF_FRAME_RETURN_COLUMN
373 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
375 #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER
379 /* The mapping from gcc register number to DWARF 2 CFA column number. By
380 default, we just provide columns for all registers. */
381 #ifndef DWARF_FRAME_REGNUM
382 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
385 /* Return a pointer to a copy of the section string name S with all
386 attributes stripped off. */
392 char *stripped = xstrdup (s);
395 while (*p && *p != ',')
402 /* Return the register number described by a given RTL node. */
408 register unsigned regno = REGNO (rtl);
410 if (regno >= FIRST_PSEUDO_REGISTER)
412 warning ("internal regno botch: regno = %d\n", regno);
416 regno = DBX_REGISTER_NUMBER (regno);
420 /* Convert a DWARF call frame info. operation to its string name */
423 dwarf_cfi_name (cfi_opc)
424 register unsigned cfi_opc;
428 case DW_CFA_advance_loc:
429 return "DW_CFA_advance_loc";
431 return "DW_CFA_offset";
433 return "DW_CFA_restore";
437 return "DW_CFA_set_loc";
438 case DW_CFA_advance_loc1:
439 return "DW_CFA_advance_loc1";
440 case DW_CFA_advance_loc2:
441 return "DW_CFA_advance_loc2";
442 case DW_CFA_advance_loc4:
443 return "DW_CFA_advance_loc4";
444 case DW_CFA_offset_extended:
445 return "DW_CFA_offset_extended";
446 case DW_CFA_restore_extended:
447 return "DW_CFA_restore_extended";
448 case DW_CFA_undefined:
449 return "DW_CFA_undefined";
450 case DW_CFA_same_value:
451 return "DW_CFA_same_value";
452 case DW_CFA_register:
453 return "DW_CFA_register";
454 case DW_CFA_remember_state:
455 return "DW_CFA_remember_state";
456 case DW_CFA_restore_state:
457 return "DW_CFA_restore_state";
459 return "DW_CFA_def_cfa";
460 case DW_CFA_def_cfa_register:
461 return "DW_CFA_def_cfa_register";
462 case DW_CFA_def_cfa_offset:
463 return "DW_CFA_def_cfa_offset";
464 /* SGI/MIPS specific */
465 case DW_CFA_MIPS_advance_loc8:
466 return "DW_CFA_MIPS_advance_loc8";
468 return "DW_CFA_<unknown>";
472 /* Return a pointer to a newly allocated Call Frame Instruction. */
474 static inline dw_cfi_ref
477 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
479 cfi->dw_cfi_next = NULL;
480 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
481 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
486 /* Add a Call Frame Instruction to list of instructions. */
489 add_cfi (list_head, cfi)
490 register dw_cfi_ref *list_head;
491 register dw_cfi_ref cfi;
493 register dw_cfi_ref *p;
495 /* Find the end of the chain. */
496 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
502 /* Generate a new label for the CFI info to refer to. */
505 dwarf2out_cfi_label ()
507 static char label[20];
508 static unsigned long label_num = 0;
510 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
511 ASM_OUTPUT_LABEL (asm_out_file, label);
516 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
517 or to the CIE if LABEL is NULL. */
520 add_fde_cfi (label, cfi)
521 register char *label;
522 register dw_cfi_ref cfi;
526 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
529 label = dwarf2out_cfi_label ();
531 if (fde->dw_fde_current_label == NULL
532 || strcmp (label, fde->dw_fde_current_label) != 0)
534 register dw_cfi_ref xcfi;
536 fde->dw_fde_current_label = label = xstrdup (label);
538 /* Set the location counter to the new label. */
540 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
541 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
542 add_cfi (&fde->dw_fde_cfi, xcfi);
545 add_cfi (&fde->dw_fde_cfi, cfi);
549 add_cfi (&cie_cfi_head, cfi);
552 /* Subroutine of lookup_cfa. */
555 lookup_cfa_1 (cfi, regp, offsetp)
556 register dw_cfi_ref cfi;
557 register unsigned long *regp;
558 register long *offsetp;
560 switch (cfi->dw_cfi_opc)
562 case DW_CFA_def_cfa_offset:
563 *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
565 case DW_CFA_def_cfa_register:
566 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
569 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
570 *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
575 /* Find the previous value for the CFA. */
578 lookup_cfa (regp, offsetp)
579 register unsigned long *regp;
580 register long *offsetp;
582 register dw_cfi_ref cfi;
584 *regp = (unsigned long) -1;
587 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
588 lookup_cfa_1 (cfi, regp, offsetp);
590 if (fde_table_in_use)
592 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
593 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
594 lookup_cfa_1 (cfi, regp, offsetp);
598 /* The current rule for calculating the DWARF2 canonical frame address. */
599 static unsigned cfa_reg;
600 static long cfa_offset;
602 /* The register used for saving registers to the stack, and its offset
604 static unsigned cfa_store_reg;
605 static long cfa_store_offset;
607 /* Entry point to update the canonical frame address (CFA).
608 LABEL is passed to add_fde_cfi. The value of CFA is now to be
609 calculated from REG+OFFSET. */
612 dwarf2out_def_cfa (label, reg, offset)
613 register char *label;
614 register unsigned reg;
615 register long offset;
617 register dw_cfi_ref cfi;
618 unsigned long old_reg;
621 reg = DWARF_FRAME_REGNUM (reg);
622 lookup_cfa (&old_reg, &old_offset);
624 if (reg == old_reg && offset == old_offset)
631 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
632 cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
635 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
636 else if (offset == old_offset && old_reg != (unsigned long) -1)
638 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
639 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
645 cfi->dw_cfi_opc = DW_CFA_def_cfa;
646 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
647 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
650 add_fde_cfi (label, cfi);
654 if (cfa_store_reg == reg)
655 cfa_store_offset = offset;
658 /* Add the CFI for saving a register. REG is the CFA column number.
659 LABEL is passed to add_fde_cfi.
660 If SREG is -1, the register is saved at OFFSET from the CFA;
661 otherwise it is saved in SREG. */
664 reg_save (label, reg, sreg, offset)
665 register char * label;
666 register unsigned reg;
667 register unsigned sreg;
668 register long offset;
670 register dw_cfi_ref cfi = new_cfi ();
672 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
677 /* The register number won't fit in 6 bits, so we have to use
679 cfi->dw_cfi_opc = DW_CFA_offset_extended;
681 cfi->dw_cfi_opc = DW_CFA_offset;
683 offset /= DWARF_CIE_DATA_ALIGNMENT;
684 assert (offset >= 0);
685 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
689 cfi->dw_cfi_opc = DW_CFA_register;
690 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
693 add_fde_cfi (label, cfi);
696 /* Entry point for saving a register. REG is the GCC register number.
697 LABEL and OFFSET are passed to reg_save. */
700 dwarf2out_reg_save (label, reg, offset)
701 register char * label;
702 register unsigned reg;
703 register long offset;
705 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
708 /* Record the initial position of the return address. RTL is
709 INCOMING_RETURN_ADDR_RTX. */
712 initial_return_save (rtl)
718 switch (GET_CODE (rtl))
721 /* RA is in a register. */
722 reg = reg_number (rtl);
725 /* RA is on the stack. */
727 switch (GET_CODE (rtl))
730 assert (REGNO (rtl) == STACK_POINTER_REGNUM);
734 assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
735 offset = INTVAL (XEXP (rtl, 1));
738 assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
739 offset = -INTVAL (XEXP (rtl, 1));
749 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset);
752 /* Record call frame debugging information for INSN, which either
753 sets SP or FP (adjusting how we calculate the frame address) or saves a
754 register to the stack. If INSN is NULL_RTX, initialize our state. */
757 dwarf2out_frame_debug (insn)
764 /* A temporary register used in adjusting SP or setting up the store_reg. */
765 static unsigned cfa_temp_reg;
766 static long cfa_temp_value;
768 if (insn == NULL_RTX)
770 /* Set up state for generating call frame debug info. */
771 cfa_reg = STACK_POINTER_REGNUM;
773 cfa_store_reg = STACK_POINTER_REGNUM;
774 cfa_store_offset = 0;
780 label = dwarf2out_cfi_label ();
782 insn = PATTERN (insn);
783 assert (GET_CODE (insn) == SET);
785 src = SET_SRC (insn);
786 dest = SET_DEST (insn);
788 switch (GET_CODE (dest))
791 /* Update the CFA rule wrt SP or FP. Make sure src is
792 relative to the current CFA register. */
793 switch (GET_CODE (src))
795 /* Setting FP from SP. */
797 assert (cfa_reg == REGNO (src));
798 assert (REGNO (dest) == STACK_POINTER_REGNUM
799 || (frame_pointer_needed
800 && REGNO (dest) == HARD_FRAME_POINTER_REGNUM));
801 cfa_reg = REGNO (dest);
806 if (dest == stack_pointer_rtx)
809 switch (GET_CODE (XEXP (src, 1)))
812 offset = INTVAL (XEXP (src, 1));
815 assert (REGNO (XEXP (src, 1)) == cfa_temp_reg);
816 offset = cfa_temp_value;
822 if (GET_CODE (src) == PLUS)
824 if (cfa_reg == STACK_POINTER_REGNUM)
825 cfa_offset += offset;
826 if (cfa_store_reg == STACK_POINTER_REGNUM)
827 cfa_store_offset += offset;
828 assert (XEXP (src, 0) == stack_pointer_rtx);
832 /* Initializing the store base register. */
833 assert (GET_CODE (src) == PLUS);
834 assert (XEXP (src, 1) == stack_pointer_rtx);
835 assert (GET_CODE (XEXP (src, 0)) == REG
836 && REGNO (XEXP (src, 0)) == cfa_temp_reg);
837 assert (cfa_store_reg == STACK_POINTER_REGNUM);
838 cfa_store_reg = REGNO (dest);
839 cfa_store_offset -= cfa_temp_value;
844 cfa_temp_reg = REGNO (dest);
845 cfa_temp_value = INTVAL (src);
851 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
855 /* Saving a register to the stack. Make sure dest is relative to the
857 assert (GET_CODE (src) == REG);
858 switch (GET_CODE (XEXP (dest, 0)))
863 offset = GET_MODE_SIZE (GET_MODE (dest));
864 if (GET_CODE (src) == PRE_INC)
867 assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM);
868 assert (cfa_store_reg == STACK_POINTER_REGNUM);
869 cfa_store_offset += offset;
870 if (cfa_reg == STACK_POINTER_REGNUM)
871 cfa_offset = cfa_store_offset;
873 offset = -cfa_store_offset;
876 /* With an offset. */
879 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
880 if (GET_CODE (src) == MINUS)
883 assert (cfa_store_reg == REGNO (XEXP (XEXP (dest, 0), 0)));
884 offset -= cfa_store_offset;
890 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
891 dwarf2out_reg_save (label, REGNO (src), offset);
899 /* Return the size of an unsigned LEB128 quantity. */
901 static inline unsigned long
902 size_of_uleb128 (value)
903 register unsigned long value;
905 register unsigned long size = 0;
906 register unsigned byte;
910 byte = (value & 0x7f);
919 /* Return the size of a signed LEB128 quantity. */
921 static inline unsigned long
922 size_of_sleb128 (value)
925 register unsigned long size = 0;
926 register unsigned byte;
930 byte = (value & 0x7f);
934 while (!(((value == 0) && ((byte & 0x40) == 0))
935 || ((value == -1) && ((byte & 0x40) != 0))));
940 /* Return the size of a Call Frame Instruction. */
946 register unsigned long size;
948 /* Count the 1-byte opcode */
950 switch (cfi->dw_cfi_opc)
953 size += size_of_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
958 case DW_CFA_advance_loc1:
961 case DW_CFA_advance_loc2:
964 case DW_CFA_advance_loc4:
967 #ifdef MIPS_DEBUGGING_INFO
968 case DW_CFA_MIPS_advance_loc8:
972 case DW_CFA_offset_extended:
974 size += size_of_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
975 size += size_of_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
977 case DW_CFA_restore_extended:
978 case DW_CFA_undefined:
979 size += size_of_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
981 case DW_CFA_same_value:
982 case DW_CFA_def_cfa_register:
983 size += size_of_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
985 case DW_CFA_register:
986 size += size_of_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
987 size += size_of_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
989 case DW_CFA_def_cfa_offset:
990 size += size_of_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
999 /* Return the size of an FDE sans the length word. */
1001 static inline unsigned long
1002 size_of_fde (fde, npad)
1004 unsigned long *npad;
1006 register dw_cfi_ref cfi;
1007 register unsigned long aligned_size;
1008 register unsigned long size;
1010 size = DWARF_FDE_HEADER_SIZE;
1011 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1012 size += size_of_cfi(cfi);
1014 /* Round the size up to a word boundary. */
1015 aligned_size = DWARF_ROUND (size, PTR_SIZE);
1016 *npad = aligned_size - size;
1017 return aligned_size;
1020 /* Calculate the size of the FDE table, and establish the offset
1021 of each FDE in the .debug_frame section. */
1026 register unsigned long i;
1027 register dw_fde_ref fde;
1028 register unsigned long fde_size;
1029 register dw_cfi_ref cfi;
1030 unsigned long fde_pad;
1032 cie_size = DWARF_CIE_HEADER_SIZE;
1033 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1034 cie_size += size_of_cfi (cfi);
1036 /* Initialize the beginning FDE offset. */
1037 next_fde_offset = DWARF_ROUND (cie_size, PTR_SIZE);
1039 for (i = 0; i < fde_table_in_use; ++i)
1041 fde = &fde_table[i];
1042 fde->dw_fde_offset = next_fde_offset;
1043 fde_size = size_of_fde (fde, &fde_pad);
1044 next_fde_offset += fde_size;
1048 /* Output an unsigned LEB128 quantity. */
1051 output_uleb128 (value)
1052 register unsigned long value;
1054 unsigned long save_value = value;
1056 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1059 register unsigned byte = (value & 0x7f);
1062 /* More bytes to follow. */
1065 fprintf (asm_out_file, "0x%x", byte);
1067 fprintf (asm_out_file, ",");
1071 if (flag_verbose_asm)
1072 fprintf (asm_out_file, "\t%s ULEB128 0x%x", ASM_COMMENT_START, save_value);
1075 /* Output an signed LEB128 quantity. */
1078 output_sleb128 (value)
1079 register long value;
1082 register unsigned byte;
1083 long save_value = value;
1085 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1088 byte = (value & 0x7f);
1089 /* arithmetic shift */
1091 more = !((((value == 0) && ((byte & 0x40) == 0))
1092 || ((value == -1) && ((byte & 0x40) != 0))));
1096 fprintf (asm_out_file, "0x%x", byte);
1098 fprintf (asm_out_file, ",");
1102 if (flag_verbose_asm)
1103 fprintf (asm_out_file, "\t%s SLEB128 %d", ASM_COMMENT_START, save_value);
1106 /* Output a Call Frame Information opcode and its operand(s). */
1109 output_cfi (cfi, fde)
1110 register dw_cfi_ref cfi;
1111 register dw_fde_ref fde;
1113 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1115 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1117 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1118 if (flag_verbose_asm)
1119 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%x",
1120 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1121 fputc ('\n', asm_out_file);
1124 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1126 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1128 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1129 if (flag_verbose_asm)
1130 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%x",
1131 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1133 fputc ('\n', asm_out_file);
1134 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1135 fputc ('\n', asm_out_file);
1137 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1139 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1141 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1142 if (flag_verbose_asm)
1143 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%x",
1144 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1146 fputc ('\n', asm_out_file);
1150 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1151 if (flag_verbose_asm)
1152 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1153 dwarf_cfi_name (cfi->dw_cfi_opc));
1155 fputc ('\n', asm_out_file);
1156 switch (cfi->dw_cfi_opc)
1158 case DW_CFA_set_loc:
1159 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1160 fputc ('\n', asm_out_file);
1162 case DW_CFA_advance_loc1:
1163 /* TODO: not currently implemented. */
1166 case DW_CFA_advance_loc2:
1167 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1168 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1169 fde->dw_fde_current_label);
1170 fputc ('\n', asm_out_file);
1171 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1173 case DW_CFA_advance_loc4:
1174 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1175 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1176 fde->dw_fde_current_label);
1177 fputc ('\n', asm_out_file);
1178 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1180 #ifdef MIPS_DEBUGGING_INFO
1181 case DW_CFA_MIPS_advance_loc8:
1182 /* TODO: not currently implemented. */
1186 case DW_CFA_offset_extended:
1187 case DW_CFA_def_cfa:
1188 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1189 fputc ('\n', asm_out_file);
1190 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1191 fputc ('\n', asm_out_file);
1193 case DW_CFA_restore_extended:
1194 case DW_CFA_undefined:
1195 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1196 fputc ('\n', asm_out_file);
1198 case DW_CFA_same_value:
1199 case DW_CFA_def_cfa_register:
1200 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1201 fputc ('\n', asm_out_file);
1203 case DW_CFA_register:
1204 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1205 fputc ('\n', asm_out_file);
1206 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1207 fputc ('\n', asm_out_file);
1209 case DW_CFA_def_cfa_offset:
1210 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1211 fputc ('\n', asm_out_file);
1219 /* Output the call frame information used to used to record information
1220 that relates to calculating the frame pointer, and records the
1221 location of saved registers. */
1224 output_call_frame_info (for_eh)
1227 register unsigned long i, j;
1228 register dw_fde_ref fde;
1229 register unsigned long fde_size;
1230 register dw_cfi_ref cfi;
1231 unsigned long fde_pad;
1233 /* Only output the info if it will be interesting. */
1234 for (i = 0; i < fde_table_in_use; ++i)
1235 if (fde_table[i].dw_fde_cfi != NULL)
1237 if (i == fde_table_in_use)
1240 /* (re-)initialize the beginning FDE offset. */
1241 next_fde_offset = DWARF_ROUND (cie_size, PTR_SIZE);
1243 fputc ('\n', asm_out_file);
1246 #ifdef EH_FRAME_SECTION
1247 ASM_OUTPUT_SECTION_NAME (asm_out_file, NULL_TREE, EH_FRAME_SECTION, 0);
1251 assemble_label ("__FRAME_BEGIN__");
1254 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1256 /* Output the CIE. */
1257 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_fde_offset - DWARF_OFFSET_SIZE);
1258 if (flag_verbose_asm)
1259 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1262 fputc ('\n', asm_out_file);
1263 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1264 if (flag_verbose_asm)
1265 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1267 fputc ('\n', asm_out_file);
1268 if (DWARF_OFFSET_SIZE == 8)
1270 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1271 fputc ('\n', asm_out_file);
1274 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1275 if (flag_verbose_asm)
1276 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1278 fputc ('\n', asm_out_file);
1279 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1280 if (flag_verbose_asm)
1281 fprintf (asm_out_file, "\t%s CIE Augmentation (none)", ASM_COMMENT_START);
1283 fputc ('\n', asm_out_file);
1285 if (flag_verbose_asm)
1286 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1288 fputc ('\n', asm_out_file);
1289 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1290 if (flag_verbose_asm)
1291 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1293 fputc ('\n', asm_out_file);
1294 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1295 if (flag_verbose_asm)
1296 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1298 fputc ('\n', asm_out_file);
1300 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1301 output_cfi (cfi, NULL);
1303 /* Pad the CIE out to an address sized boundary. */
1304 for (i = next_fde_offset - cie_size; i; --i)
1306 /* Pad out to a pointer size boundary */
1307 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
1308 if (flag_verbose_asm)
1309 fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)", ASM_COMMENT_START);
1311 fputc ('\n', asm_out_file);
1314 /* Loop through all of the FDE's. */
1315 for (i = 0; i < fde_table_in_use; ++i)
1317 fde = &fde_table[i];
1318 if (fde->dw_fde_cfi == NULL)
1321 fde_size = size_of_fde (fde, &fde_pad);
1322 ASM_OUTPUT_DWARF_DATA (asm_out_file, fde_size - DWARF_OFFSET_SIZE);
1323 if (flag_verbose_asm)
1324 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1326 fputc ('\n', asm_out_file);
1328 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__FRAME_BEGIN__");
1330 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1331 if (flag_verbose_asm)
1332 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1334 fputc ('\n', asm_out_file);
1335 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1336 if (flag_verbose_asm)
1337 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1339 fputc ('\n', asm_out_file);
1340 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1341 fde->dw_fde_end, fde->dw_fde_begin);
1342 if (flag_verbose_asm)
1343 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1345 fputc ('\n', asm_out_file);
1347 /* Loop through the Call Frame Instructions associated with
1349 fde->dw_fde_current_label = fde->dw_fde_begin;
1350 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1351 output_cfi (cfi, fde);
1353 /* Pad to a double word boundary. */
1354 for (j = 0; j < fde_pad; ++j)
1356 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
1357 if (flag_verbose_asm)
1358 fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)",
1361 fputc ('\n', asm_out_file);
1364 #ifndef EH_FRAME_SECTION
1367 /* Emit terminating zero for table. */
1368 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
1369 fputc ('\n', asm_out_file);
1374 /* Output a marker (i.e. a label) for the beginning of a function, before
1378 dwarf2out_begin_prologue ()
1380 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1381 register dw_fde_ref fde;
1383 ++current_funcdef_number;
1385 function_section (current_function_decl);
1386 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1387 current_funcdef_number);
1388 ASM_OUTPUT_LABEL (asm_out_file, label);
1390 /* Expand the fde table if necessary. */
1391 if (fde_table_in_use == fde_table_allocated)
1393 fde_table_allocated += FDE_TABLE_INCREMENT;
1395 = (dw_fde_ref) xrealloc (fde_table,
1396 fde_table_allocated * sizeof (dw_fde_node));
1399 /* Record the FDE associated with this function. */
1400 current_funcdef_fde = fde_table_in_use;
1402 /* Add the new FDE at the end of the fde_table. */
1403 fde = &fde_table[fde_table_in_use++];
1404 fde->dw_fde_begin = xstrdup (label);
1405 fde->dw_fde_current_label = NULL;
1406 fde->dw_fde_end = NULL;
1407 fde->dw_fde_cfi = NULL;
1410 /* Output a marker (i.e. a label) for the absolute end of the generated code
1411 for a function definition. This gets called *after* the epilogue code has
1415 dwarf2out_end_epilogue ()
1418 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1420 /* Output a label to mark the endpoint of the code generated for this
1422 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1423 ASM_OUTPUT_LABEL (asm_out_file, label);
1424 fde = &fde_table[fde_table_in_use - 1];
1425 fde->dw_fde_end = xstrdup (label);
1429 dwarf2out_frame_init ()
1431 /* Allocate the initial hunk of the fde_table. */
1433 = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1434 bzero ((char *) fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1435 fde_table_allocated = FDE_TABLE_INCREMENT;
1436 fde_table_in_use = 0;
1438 /* Generate the CFA instructions common to all FDE's. Do it now for the
1439 sake of lookup_cfa. */
1441 #ifdef INCOMING_RETURN_ADDR_RTX
1442 /* On entry, the Canonical Frame Address is at SP+0. */
1443 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, 0);
1444 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1449 dwarf2out_frame_finish ()
1451 /* calculate sizes/offsets for FDEs. */
1454 /* Output call frame information. */
1455 if (write_symbols == DWARF2_DEBUG)
1456 output_call_frame_info (0);
1457 if (flag_exceptions && ! exceptions_via_longjmp)
1458 output_call_frame_info (1);
1461 #endif /* .debug_frame support */
1463 /* And now, the support for symbolic debugging information. */
1464 #ifdef DWARF2_DEBUGGING_INFO
1466 extern char *getpwd ();
1468 /* NOTE: In the comments in this file, many references are made to
1469 "Debugging Information Entries". This term is abbreviated as `DIE'
1470 throughout the remainder of this file. */
1472 /* An internal representation of the DWARF output is built, and then
1473 walked to generate the DWARF debugging info. The walk of the internal
1474 representation is done after the entire program has been compiled.
1475 The types below are used to describe the internal representation. */
1477 /* Each DIE may have a series of attribute/value pairs. Values
1478 can take on several forms. The forms that are used in this
1479 implementation are listed below. */
1486 dw_val_class_unsigned_const,
1487 dw_val_class_long_long,
1490 dw_val_class_die_ref,
1491 dw_val_class_fde_ref,
1492 dw_val_class_lbl_id,
1493 dw_val_class_section_offset,
1498 /* Various DIE's use offsets relative to the beginning of the
1499 .debug_info section to refer to each other. */
1501 typedef long int dw_offset;
1503 /* Define typedefs here to avoid circular dependencies. */
1505 typedef struct die_struct *dw_die_ref;
1506 typedef struct dw_attr_struct *dw_attr_ref;
1507 typedef struct dw_val_struct *dw_val_ref;
1508 typedef struct dw_line_info_struct *dw_line_info_ref;
1509 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
1510 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1511 typedef struct pubname_struct *pubname_ref;
1512 typedef dw_die_ref *arange_ref;
1514 /* Describe a double word constant value. */
1516 typedef struct dw_long_long_struct
1523 /* Describe a floating point constant value. */
1525 typedef struct dw_fp_struct
1532 /* Each entry in the line_info_table maintains the file and
1533 line nuber associated with the label generated for that
1534 entry. The label gives the PC value associated with
1535 the line number entry. */
1537 typedef struct dw_line_info_struct
1539 unsigned long dw_file_num;
1540 unsigned long dw_line_num;
1544 /* Line information for functions in separate sections; each one gets its
1546 typedef struct dw_separate_line_info_struct
1548 unsigned long dw_file_num;
1549 unsigned long dw_line_num;
1550 unsigned long function;
1552 dw_separate_line_info_entry;
1554 /* The dw_val_node describes an attibute's value, as it is
1555 represented internally. */
1557 typedef struct dw_val_struct
1559 dw_val_class val_class;
1563 dw_loc_descr_ref val_loc;
1565 long unsigned val_unsigned;
1566 dw_long_long_const val_long_long;
1567 dw_float_const val_float;
1568 dw_die_ref val_die_ref;
1569 unsigned val_fde_index;
1573 unsigned char val_flag;
1579 /* Locations in memory are described using a sequence of stack machine
1582 typedef struct dw_loc_descr_struct
1584 dw_loc_descr_ref dw_loc_next;
1585 enum dwarf_location_atom dw_loc_opc;
1586 dw_val_node dw_loc_oprnd1;
1587 dw_val_node dw_loc_oprnd2;
1591 /* Each DIE attribute has a field specifying the attribute kind,
1592 a link to the next attribute in the chain, and an attribute value.
1593 Attributes are typically linked below the DIE they modify. */
1595 typedef struct dw_attr_struct
1597 enum dwarf_attribute dw_attr;
1598 dw_attr_ref dw_attr_next;
1599 dw_val_node dw_attr_val;
1603 /* The Debugging Information Entry (DIE) structure */
1605 typedef struct die_struct
1607 enum dwarf_tag die_tag;
1608 dw_attr_ref die_attr;
1609 dw_attr_ref die_attr_last;
1610 dw_die_ref die_parent;
1611 dw_die_ref die_child;
1612 dw_die_ref die_child_last;
1614 dw_offset die_offset;
1615 unsigned long die_abbrev;
1619 /* The pubname structure */
1621 typedef struct pubname_struct
1628 /* How to start an assembler comment. */
1629 #ifndef ASM_COMMENT_START
1630 #define ASM_COMMENT_START ";#"
1633 /* Define a macro which returns non-zero for a TYPE_DECL which was
1634 implicitly generated for a tagged type.
1636 Note that unlike the gcc front end (which generates a NULL named
1637 TYPE_DECL node for each complete tagged type, each array type, and
1638 each function type node created) the g++ front end generates a
1639 _named_ TYPE_DECL node for each tagged type node created.
1640 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
1641 generate a DW_TAG_typedef DIE for them. */
1643 #define TYPE_DECL_IS_STUB(decl) \
1644 (DECL_NAME (decl) == NULL_TREE \
1645 || (DECL_ARTIFICIAL (decl) \
1646 && is_tagged_type (TREE_TYPE (decl)) \
1647 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
1649 /* Information concerning the compilation unit's programming
1650 language, and compiler version. */
1652 extern int flag_traditional;
1653 extern char *version_string;
1654 extern char *language_string;
1656 /* Fixed size portion of the DWARF compilation unit header. */
1657 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
1659 /* Fixed size portion of debugging line information prolog. */
1660 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
1662 /* Fixed size portion of public names info. */
1663 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
1665 /* Fixed size portion of the address range info. */
1666 #define DWARF_ARANGES_HEADER_SIZE \
1667 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
1669 /* Define the architecture-dependent minimum instruction length (in bytes).
1670 In this implementation of DWARF, this field is used for information
1671 purposes only. Since GCC generates assembly language, we have
1672 no a priori knowledge of how many instruction bytes are generated
1673 for each source line, and therefore can use only the DW_LNE_set_address
1674 and DW_LNS_fixed_advance_pc line information commands. */
1676 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
1677 #define DWARF_LINE_MIN_INSTR_LENGTH 4
1680 /* Minimum line offset in a special line info. opcode.
1681 This value was chosen to give a reasonable range of values. */
1682 #define DWARF_LINE_BASE -10
1684 /* First special line opcde - leave room for the standard opcodes. */
1685 #define DWARF_LINE_OPCODE_BASE 10
1687 /* Range of line offsets in a special line info. opcode. */
1688 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
1690 /* Flag that indicates the initial value of the is_stmt_start flag.
1691 In the present implementation, we do not mark any lines as
1692 the beginning of a source statement, because that information
1693 is not made available by the GCC front-end. */
1694 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
1696 /* This location is used by calc_die_sizes() to keep track
1697 the offset of each DIE within the .debug_info section. */
1698 static unsigned long next_die_offset;
1700 /* Record the root of the DIE's built for the current compilation unit. */
1701 static dw_die_ref comp_unit_die;
1703 /* The number of DIEs with a NULL parent waiting to be relocated. */
1704 static int limbo_die_count;
1706 /* Pointer to an array of filenames referenced by this compilation unit. */
1707 static char **file_table;
1709 /* Total number of entries in the table (i.e. array) pointed to by
1710 `file_table'. This is the *total* and includes both used and unused
1712 static unsigned file_table_allocated;
1714 /* Number of entries in the file_table which are actually in use. */
1715 static unsigned file_table_in_use;
1717 /* Size (in elements) of increments by which we may expand the filename
1719 #define FILE_TABLE_INCREMENT 64
1721 /* Local pointer to the name of the main input file. Initialized in
1723 static char *primary_filename;
1725 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
1726 which their beginnings are encountered. We output Dwarf debugging info
1727 that refers to the beginnings and ends of the ranges of code for each
1728 lexical block. The labels themselves are generated in final.c, which
1729 assigns numbers to the blocks in the same way. */
1730 static unsigned next_block_number = 2;
1732 /* A pointer to the base of a table of references to DIE's that describe
1733 declarations. The table is indexed by DECL_UID() which is a unique
1734 number, indentifying each decl. */
1735 static dw_die_ref *decl_die_table;
1737 /* Number of elements currently allocated for the decl_die_table. */
1738 static unsigned decl_die_table_allocated;
1740 /* Number of elements in decl_die_table currently in use. */
1741 static unsigned decl_die_table_in_use;
1743 /* Size (in elements) of increments by which we may expand the
1745 #define DECL_DIE_TABLE_INCREMENT 256
1747 /* A pointer to the base of a table of references to declaration
1748 scopes. This table is a display which tracks the nesting
1749 of declaration scopes at the current scope and containing
1750 scopes. This table is used to find the proper place to
1751 define type declaration DIE's. */
1752 static tree *decl_scope_table;
1754 /* Number of elements currently allocated for the decl_scope_table. */
1755 static unsigned decl_scope_table_allocated;
1757 /* Current level of nesting of declataion scopes. */
1758 static unsigned decl_scope_depth;
1760 /* Size (in elements) of increments by which we may expand the
1761 decl_scope_table. */
1762 #define DECL_SCOPE_TABLE_INCREMENT 64
1764 /* A pointer to the base of a list of references to DIE's that
1765 are uniquely identified by their tag, presence/absence of
1766 children DIE's, and list of attribute/value pairs. */
1767 static dw_die_ref *abbrev_die_table;
1769 /* Number of elements currently allocated for abbrev_die_table. */
1770 static unsigned abbrev_die_table_allocated;
1772 /* Number of elements in type_die_table currently in use. */
1773 static unsigned abbrev_die_table_in_use;
1775 /* Size (in elements) of increments by which we may expand the
1776 abbrev_die_table. */
1777 #define ABBREV_DIE_TABLE_INCREMENT 256
1779 /* A pointer to the base of a table that contains line information
1780 for each source code line in .text in the compilation unit. */
1781 static dw_line_info_ref line_info_table;
1783 /* Number of elements currently allocated for line_info_table. */
1784 static unsigned line_info_table_allocated;
1786 /* Number of elements in separate_line_info_table currently in use. */
1787 static unsigned separate_line_info_table_in_use;
1789 /* A pointer to the base of a table that contains line information
1790 for each source code line outside of .text in the compilation unit. */
1791 static dw_separate_line_info_ref separate_line_info_table;
1793 /* Number of elements currently allocated for separate_line_info_table. */
1794 static unsigned separate_line_info_table_allocated;
1796 /* Number of elements in line_info_table currently in use. */
1797 static unsigned line_info_table_in_use;
1799 /* Size (in elements) of increments by which we may expand the
1801 #define LINE_INFO_TABLE_INCREMENT 1024
1803 /* A pointer to the base of a table that contains a list of publicly
1804 accessible names. */
1805 static pubname_ref pubname_table;
1807 /* Number of elements currently allocated for pubname_table. */
1808 static unsigned pubname_table_allocated;
1810 /* Number of elements in pubname_table currently in use. */
1811 static unsigned pubname_table_in_use;
1813 /* Size (in elements) of increments by which we may expand the
1815 #define PUBNAME_TABLE_INCREMENT 64
1817 /* A pointer to the base of a table that contains a list of publicly
1818 accessible names. */
1819 static arange_ref arange_table;
1821 /* Number of elements currently allocated for arange_table. */
1822 static unsigned arange_table_allocated;
1824 /* Number of elements in arange_table currently in use. */
1825 static unsigned arange_table_in_use;
1827 /* Size (in elements) of increments by which we may expand the
1829 #define ARANGE_TABLE_INCREMENT 64
1831 /* A pointer to the base of a list of pending types which we haven't
1832 generated DIEs for yet, but which we will have to come back to
1835 static tree *pending_types_list;
1837 /* Number of elements currently allocated for the pending_types_list. */
1838 static unsigned pending_types_allocated;
1840 /* Number of elements of pending_types_list currently in use. */
1841 static unsigned pending_types;
1843 /* Size (in elements) of increments by which we may expand the pending
1844 types list. Actually, a single hunk of space of this size should
1845 be enough for most typical programs. */
1846 #define PENDING_TYPES_INCREMENT 64
1848 /* Record whether the function being analyzed contains inlined functions. */
1849 static int current_function_has_inlines;
1850 static int comp_unit_has_inlines;
1852 /* A pointer to the ..._DECL node which we have most recently been working
1853 on. We keep this around just in case something about it looks screwy and
1854 we want to tell the user what the source coordinates for the actual
1856 static tree dwarf_last_decl;
1858 /* Forward declarations for functions defined in this file. */
1860 static void addr_const_to_string PROTO((char *, rtx));
1861 static char *addr_to_string PROTO((rtx));
1862 static int is_pseudo_reg PROTO((rtx));
1863 static tree type_main_variant PROTO((tree));
1864 static int is_tagged_type PROTO((tree));
1865 static char *dwarf_tag_name PROTO((unsigned));
1866 static char *dwarf_attr_name PROTO((unsigned));
1867 static char *dwarf_form_name PROTO((unsigned));
1868 static char *dwarf_stack_op_name PROTO((unsigned));
1869 static char *dwarf_type_encoding_name PROTO((unsigned));
1870 static tree decl_ultimate_origin PROTO((tree));
1871 static tree block_ultimate_origin PROTO((tree));
1872 static tree decl_class_context PROTO((tree));
1873 static void add_dwarf_attr PROTO((dw_die_ref, dw_attr_ref));
1874 static void add_AT_flag PROTO((dw_die_ref,
1875 enum dwarf_attribute,
1877 static void add_AT_int PROTO((dw_die_ref,
1878 enum dwarf_attribute, long));
1879 static void add_AT_unsigned PROTO((dw_die_ref,
1880 enum dwarf_attribute,
1882 static void add_AT_long_long PROTO((dw_die_ref,
1883 enum dwarf_attribute,
1884 unsigned long, unsigned long));
1885 static void add_AT_float PROTO((dw_die_ref,
1886 enum dwarf_attribute,
1888 static void add_AT_string PROTO((dw_die_ref,
1889 enum dwarf_attribute, char *));
1890 static void add_AT_die_ref PROTO((dw_die_ref,
1891 enum dwarf_attribute,
1893 static void add_AT_fde_ref PROTO((dw_die_ref,
1894 enum dwarf_attribute,
1896 static void add_AT_loc PROTO((dw_die_ref,
1897 enum dwarf_attribute,
1899 static void add_AT_addr PROTO((dw_die_ref,
1900 enum dwarf_attribute, char *));
1901 static void add_AT_lbl_id PROTO((dw_die_ref,
1902 enum dwarf_attribute, char *));
1903 static void add_AT_setion_offset PROTO((dw_die_ref,
1904 enum dwarf_attribute, char *));
1905 static int is_extern_subr_die PROTO((dw_die_ref));
1906 static dw_attr_ref get_AT PROTO((dw_die_ref,
1907 enum dwarf_attribute));
1908 static char *get_AT_low_pc PROTO((dw_die_ref));
1909 static char *get_AT_hi_pc PROTO((dw_die_ref));
1910 static char *get_AT_string PROTO((dw_die_ref,
1911 enum dwarf_attribute));
1912 static int get_AT_flag PROTO((dw_die_ref,
1913 enum dwarf_attribute));
1914 static unsigned get_AT_unsigned PROTO((dw_die_ref,
1915 enum dwarf_attribute));
1916 static int is_c_family PROTO((void));
1917 static int is_fortran PROTO((void));
1918 static void remove_AT PROTO((dw_die_ref,
1919 enum dwarf_attribute));
1920 static void remove_children PROTO((dw_die_ref));
1921 static void add_child_die PROTO((dw_die_ref, dw_die_ref));
1922 static dw_die_ref new_die PROTO((enum dwarf_tag, dw_die_ref));
1923 static dw_die_ref lookup_type_die PROTO((tree));
1924 static void equate_type_number_to_die PROTO((tree, dw_die_ref));
1925 static dw_die_ref lookup_decl_die PROTO((tree));
1926 static void equate_decl_number_to_die PROTO((tree, dw_die_ref));
1927 static dw_loc_descr_ref new_loc_descr PROTO((enum dwarf_location_atom,
1928 unsigned long, unsigned long));
1929 static void add_loc_descr PROTO((dw_loc_descr_ref *,
1931 static void print_spaces PROTO((FILE *));
1932 static void print_die PROTO((dw_die_ref, FILE *));
1933 static void print_dwarf_line_table PROTO((FILE *));
1934 static void add_sibling_atttributes PROTO((dw_die_ref));
1935 static void build_abbrev_table PROTO((dw_die_ref));
1936 static unsigned long size_of_string PROTO((char *));
1937 static unsigned long size_of_loc_descr PROTO((dw_loc_descr_ref));
1938 static unsigned long size_of_locs PROTO((dw_loc_descr_ref));
1939 static int constant_size PROTO((long unsigned));
1940 static unsigned long size_of_die PROTO((dw_die_ref));
1941 static void calc_die_sizes PROTO((dw_die_ref));
1942 static unsigned long size_of_prolog PROTO((void));
1943 static unsigned long size_of_line_info PROTO((void));
1944 static unsigned long size_of_pubnames PROTO((void));
1945 static unsigned long size_of_aranges PROTO((void));
1946 static enum dwarf_form value_format PROTO((dw_val_ref));
1947 static void output_value_format PROTO((dw_val_ref));
1948 static void output_abbrev_section PROTO((void));
1949 static void output_loc_operands PROTO((dw_loc_descr_ref));
1950 static unsigned long sibling_offset PROTO((dw_die_ref));
1951 static void output_die PROTO((dw_die_ref));
1952 static void output_compilation_unit_header PROTO((void));
1953 static char *dwarf2_name PROTO((tree, int));
1954 static void add_pubname PROTO((tree, dw_die_ref));
1955 static void output_pubnames PROTO((void));
1956 static void add_arrange PROTO((tree, dw_die_ref));
1957 static void output_arranges PROTO((void));
1958 static void output_line_info PROTO((void));
1959 static int is_body_block PROTO((tree));
1960 static dw_die_ref base_type_die PROTO((tree));
1961 static tree root_type PROTO((tree));
1962 static int is_base_type PROTO((tree));
1963 static dw_die_ref modified_type_die PROTO((tree, int, int, dw_die_ref));
1964 static int type_is_enum PROTO((tree));
1965 static dw_loc_descr_ref reg_loc_descr_ref PROTO((rtx));
1966 static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long));
1967 static int is_based_loc PROTO((rtx));
1968 static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx));
1969 static dw_loc_descr_ref loc_descriptor PROTO((rtx));
1970 static unsigned ceiling PROTO((unsigned, unsigned));
1971 static tree field_type PROTO((tree));
1972 static unsigned simple_type_align_in_bits PROTO((tree));
1973 static unsigned simple_type_size_in_bits PROTO((tree));
1974 static unsigned field_byte_offset PROTO((tree));
1975 static void add_location_attribute PROTO((dw_die_ref, rtx));
1976 static void add_data_member_location_attribute PROTO((dw_die_ref, tree));
1977 static void add_const_value_attribute PROTO((dw_die_ref, rtx));
1978 static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree));
1979 static void add_name_attribute PROTO((dw_die_ref, char *));
1980 static void add_bound_info PROTO((dw_die_ref,
1981 enum dwarf_attribute, tree));
1982 static void add_subscript_info PROTO((dw_die_ref, tree));
1983 static void add_byte_size_attribute PROTO((dw_die_ref, tree));
1984 static void add_bit_offset_attribute PROTO((dw_die_ref, tree));
1985 static void add_bit_size_attribute PROTO((dw_die_ref, tree));
1986 static void add_prototyped_attribute PROTO((dw_die_ref, tree));
1987 static void add_abstract_origin_attribute PROTO((dw_die_ref, tree));
1988 static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree));
1989 static void add_src_coords_attributes PROTO((dw_die_ref, tree));
1990 static void ad_name_and_src_coords_attributes PROTO((dw_die_ref, tree));
1991 static void push_decl_scope PROTO((tree));
1992 static dw_die_ref scope_die_for PROTO((tree, dw_die_ref));
1993 static void pop_decl_scope PROTO((void));
1994 static void add_type_attribute PROTO((dw_die_ref, tree, int, int,
1996 static char *type_tag PROTO((tree));
1997 static tree member_declared_type PROTO((tree));
1998 static char *decl_start_label PROTO((tree));
1999 static void gen_arrqay_type_die PROTO((tree, dw_die_ref));
2000 static void gen_set_type_die PROTO((tree, dw_die_ref));
2001 static void gen_entry_point_die PROTO((tree, dw_die_ref));
2002 static void pend_type PROTO((tree));
2003 static void output_pending_types_for_scope PROTO((dw_die_ref));
2004 static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref));
2005 static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref));
2006 static void gen_inlined_union_type_die PROTO((tree, dw_die_ref));
2007 static void gen_enumeration_type_die PROTO((tree, dw_die_ref));
2008 static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref));
2009 static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref));
2010 static void gen_formal_types_die PROTO((tree, dw_die_ref));
2011 static void gen_subprogram_die PROTO((tree, dw_die_ref));
2012 static void gen_variable_die PROTO((tree, dw_die_ref));
2013 static void gen_label_die PROTO((tree, dw_die_ref));
2014 static void gen_lexical_block_die PROTO((tree, dw_die_ref, int));
2015 static void gen_inlined_subprogram_die PROTO((tree, dw_die_ref, int));
2016 static void gen_field_die PROTO((tree, dw_die_ref));
2017 static void gen_ptr_to_mbr_type_die PROTO((tree, dw_die_ref));
2018 static void gen_compile_unit_die PROTO((char *));
2019 static void gen_string_type_die PROTO((tree, dw_die_ref));
2020 static void gen_inheritance_die PROTO((tree, dw_die_ref));
2021 static void gen_member_die PROTO((tree, dw_die_ref));
2022 static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref));
2023 static void gen_subroutine_type_die PROTO((tree, dw_die_ref));
2024 static void gen_typedef_die PROTO((tree, dw_die_ref));
2025 static void gen_type_die PROTO((tree, dw_die_ref));
2026 static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref));
2027 static void gen_block_die PROTO((tree, dw_die_ref, int));
2028 static void decls_for_scope PROTO((tree, dw_die_ref, int));
2029 static int is_redundant_typedef PROTO((tree));
2030 static void gen_decl_die PROTO((tree, dw_die_ref));
2031 static unsigned lookup_filename PROTO((char *));
2033 /* Section names used to hold DWARF debugging information. */
2034 #ifndef DEBUG_SECTION
2035 #define DEBUG_SECTION ".debug_info"
2037 #ifndef ABBREV_SECTION
2038 #define ABBREV_SECTION ".debug_abbrev"
2040 #ifndef ARANGES_SECTION
2041 #define ARANGES_SECTION ".debug_aranges"
2043 #ifndef DW_MACINFO_SECTION
2044 #define DW_MACINFO_SECTION ".debug_macinfo"
2046 #ifndef LINE_SECTION
2047 #define LINE_SECTION ".debug_line"
2050 #define LOC_SECTION ".debug_loc"
2052 #ifndef PUBNAMES_SECTION
2053 #define PUBNAMES_SECTION ".debug_pubnames"
2056 #define STR_SECTION ".debug_str"
2059 /* Standerd ELF section names for compiled code and data. */
2060 #ifndef TEXT_SECTION
2061 #define TEXT_SECTION ".text"
2063 #ifndef DATA_SECTION
2064 #define DATA_SECTION ".data"
2067 #define BSS_SECTION ".bss"
2071 /* Definitions of defaults for formats and names of various special
2072 (artificial) labels which may be generated within this file (when the -g
2073 options is used and DWARF_DEBUGGING_INFO is in effect.
2074 If necessary, these may be overridden from within the tm.h file, but
2075 typically, overriding these defaults is unnecessary. */
2077 char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2079 #ifndef TEXT_END_LABEL
2080 #define TEXT_END_LABEL "Letext"
2082 #ifndef DATA_END_LABEL
2083 #define DATA_END_LABEL "Ledata"
2085 #ifndef BSS_END_LABEL
2086 #define BSS_END_LABEL "Lebss"
2088 #ifndef INSN_LABEL_FMT
2089 #define INSN_LABEL_FMT "LI%u_"
2091 #ifndef BLOCK_BEGIN_LABEL
2092 #define BLOCK_BEGIN_LABEL "LBB"
2094 #ifndef BLOCK_END_LABEL
2095 #define BLOCK_END_LABEL "LBE"
2097 #ifndef BODY_BEGIN_LABEL
2098 #define BODY_BEGIN_LABEL "Lbb"
2100 #ifndef BODY_END_LABEL
2101 #define BODY_END_LABEL "Lbe"
2103 #ifndef LINE_CODE_LABEL
2104 #define LINE_CODE_LABEL "LM"
2106 #ifndef SEPARATE_LINE_CODE_LABEL
2107 #define SEPARATE_LINE_CODE_LABEL "LSM"
2110 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
2111 newline is produced. When flag_verbose_asm is asserted, we add commnetary
2112 at the end of the line, so we must avoid output of a newline here. */
2113 #ifndef ASM_OUTPUT_DWARF_STRING
2114 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
2116 register int slen = strlen(P); \
2117 register char *p = (P); \
2119 fprintf (FILE, "\t.ascii \""); \
2120 for (i = 0; i < slen; i++) \
2122 register int c = p[i]; \
2123 if (c == '\"' || c == '\\') \
2124 putc ('\\', FILE); \
2125 if (c >= ' ' && c < 0177) \
2129 fprintf (FILE, "\\%o", c); \
2132 fprintf (FILE, "\\0\""); \
2137 /* Convert a reference to the assembler name of a C-level name. This
2138 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
2139 a string rather than writing to a file. */
2140 #ifndef ASM_NAME_TO_STRING
2141 #define ASM_NAME_TO_STRING(STR, NAME) \
2143 if ((NAME)[0] == '*') \
2144 strcpy (STR, NAME+1); \
2146 strcpy (STR, NAME); \
2151 /* Convert an integer constant expression into assembler syntax. Addition
2152 and subtraction are the only arithmetic that may appear in these
2153 expressions. This is an adaptation of output_addr_const in final.c.
2154 Here, the target of the conversion is a string buffer. We can't use
2155 output_addr_const directly, because it writes to a file. */
2158 addr_const_to_string (str, x)
2167 switch (GET_CODE (x))
2177 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
2182 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2183 ASM_NAME_TO_STRING (buf2, buf1);
2188 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
2189 ASM_NAME_TO_STRING (buf2, buf1);
2194 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
2199 /* This used to output parentheses around the expression, but that does
2200 not work on the 386 (either ATT or BSD assembler). */
2201 addr_const_to_string (buf1, XEXP (x, 0));
2206 if (GET_MODE (x) == VOIDmode)
2208 /* We can use %d if the number is one word and positive. */
2209 if (CONST_DOUBLE_HIGH (x))
2210 sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
2211 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2212 else if (CONST_DOUBLE_LOW (x) < 0)
2213 sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
2215 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
2216 CONST_DOUBLE_LOW (x));
2220 /* We can't handle floating point constants; PRINT_OPERAND must
2222 output_operand_lossage ("floating constant misused");
2226 /* Some assemblers need integer constants to appear last (eg masm). */
2227 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2229 addr_const_to_string (buf1, XEXP (x, 1));
2231 if (INTVAL (XEXP (x, 0)) >= 0)
2234 addr_const_to_string (buf1, XEXP (x, 0));
2239 addr_const_to_string (buf1, XEXP (x, 0));
2241 if (INTVAL (XEXP (x, 1)) >= 0)
2244 addr_const_to_string (buf1, XEXP (x, 1));
2250 /* Avoid outputting things like x-x or x+5-x, since some assemblers
2251 can't handle that. */
2252 x = simplify_subtraction (x);
2253 if (GET_CODE (x) != MINUS)
2256 addr_const_to_string (buf1, XEXP (x, 0));
2259 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2260 && INTVAL (XEXP (x, 1)) < 0)
2262 strcat (str, ASM_OPEN_PAREN);
2263 addr_const_to_string (buf1, XEXP (x, 1));
2265 strcat (str, ASM_CLOSE_PAREN);
2269 addr_const_to_string (buf1, XEXP (x, 1));
2276 addr_const_to_string (buf1, XEXP (x, 0));
2281 output_operand_lossage ("invalid expression as operand");
2285 /* Convert an address constant to a string, and return a pointer to
2286 a copy of the result, located on the heap. */
2293 addr_const_to_string (buf, x);
2294 return xstrdup (buf);
2297 /* Test if rtl node points to a psuedo register. */
2303 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
2304 || ((GET_CODE (rtl) == SUBREG)
2305 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
2308 /* Return a reference to a type, with its const and volatile qualifiers
2312 type_main_variant (type)
2315 type = TYPE_MAIN_VARIANT (type);
2317 /* There really should be only one main variant among any group of variants
2318 of a given type (and all of the MAIN_VARIANT values for all members of
2319 the group should point to that one type) but sometimes the C front-end
2320 messes this up for array types, so we work around that bug here. */
2322 if (TREE_CODE (type) == ARRAY_TYPE)
2323 while (type != TYPE_MAIN_VARIANT (type))
2324 type = TYPE_MAIN_VARIANT (type);
2329 /* Return non-zero if the given type node represents a tagged type. */
2332 is_tagged_type (type)
2335 register enum tree_code code = TREE_CODE (type);
2337 return (code == RECORD_TYPE || code == UNION_TYPE
2338 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
2341 /* Convert a DIE tag into its string name. */
2344 dwarf_tag_name (tag)
2345 register unsigned tag;
2349 case DW_TAG_padding:
2350 return "DW_TAG_padding";
2351 case DW_TAG_array_type:
2352 return "DW_TAG_array_type";
2353 case DW_TAG_class_type:
2354 return "DW_TAG_class_type";
2355 case DW_TAG_entry_point:
2356 return "DW_TAG_entry_point";
2357 case DW_TAG_enumeration_type:
2358 return "DW_TAG_enumeration_type";
2359 case DW_TAG_formal_parameter:
2360 return "DW_TAG_formal_parameter";
2361 case DW_TAG_imported_declaration:
2362 return "DW_TAG_imported_declaration";
2364 return "DW_TAG_label";
2365 case DW_TAG_lexical_block:
2366 return "DW_TAG_lexical_block";
2368 return "DW_TAG_member";
2369 case DW_TAG_pointer_type:
2370 return "DW_TAG_pointer_type";
2371 case DW_TAG_reference_type:
2372 return "DW_TAG_reference_type";
2373 case DW_TAG_compile_unit:
2374 return "DW_TAG_compile_unit";
2375 case DW_TAG_string_type:
2376 return "DW_TAG_string_type";
2377 case DW_TAG_structure_type:
2378 return "DW_TAG_structure_type";
2379 case DW_TAG_subroutine_type:
2380 return "DW_TAG_subroutine_type";
2381 case DW_TAG_typedef:
2382 return "DW_TAG_typedef";
2383 case DW_TAG_union_type:
2384 return "DW_TAG_union_type";
2385 case DW_TAG_unspecified_parameters:
2386 return "DW_TAG_unspecified_parameters";
2387 case DW_TAG_variant:
2388 return "DW_TAG_variant";
2389 case DW_TAG_common_block:
2390 return "DW_TAG_common_block";
2391 case DW_TAG_common_inclusion:
2392 return "DW_TAG_common_inclusion";
2393 case DW_TAG_inheritance:
2394 return "DW_TAG_inheritance";
2395 case DW_TAG_inlined_subroutine:
2396 return "DW_TAG_inlined_subroutine";
2398 return "DW_TAG_module";
2399 case DW_TAG_ptr_to_member_type:
2400 return "DW_TAG_ptr_to_member_type";
2401 case DW_TAG_set_type:
2402 return "DW_TAG_set_type";
2403 case DW_TAG_subrange_type:
2404 return "DW_TAG_subrange_type";
2405 case DW_TAG_with_stmt:
2406 return "DW_TAG_with_stmt";
2407 case DW_TAG_access_declaration:
2408 return "DW_TAG_access_declaration";
2409 case DW_TAG_base_type:
2410 return "DW_TAG_base_type";
2411 case DW_TAG_catch_block:
2412 return "DW_TAG_catch_block";
2413 case DW_TAG_const_type:
2414 return "DW_TAG_const_type";
2415 case DW_TAG_constant:
2416 return "DW_TAG_constant";
2417 case DW_TAG_enumerator:
2418 return "DW_TAG_enumerator";
2419 case DW_TAG_file_type:
2420 return "DW_TAG_file_type";
2422 return "DW_TAG_friend";
2423 case DW_TAG_namelist:
2424 return "DW_TAG_namelist";
2425 case DW_TAG_namelist_item:
2426 return "DW_TAG_namelist_item";
2427 case DW_TAG_packed_type:
2428 return "DW_TAG_packed_type";
2429 case DW_TAG_subprogram:
2430 return "DW_TAG_subprogram";
2431 case DW_TAG_template_type_param:
2432 return "DW_TAG_template_type_param";
2433 case DW_TAG_template_value_param:
2434 return "DW_TAG_template_value_param";
2435 case DW_TAG_thrown_type:
2436 return "DW_TAG_thrown_type";
2437 case DW_TAG_try_block:
2438 return "DW_TAG_try_block";
2439 case DW_TAG_variant_part:
2440 return "DW_TAG_variant_part";
2441 case DW_TAG_variable:
2442 return "DW_TAG_variable";
2443 case DW_TAG_volatile_type:
2444 return "DW_TAG_volatile_type";
2445 case DW_TAG_MIPS_loop:
2446 return "DW_TAG_MIPS_loop";
2447 case DW_TAG_format_label:
2448 return "DW_TAG_format_label";
2449 case DW_TAG_function_template:
2450 return "DW_TAG_function_template";
2451 case DW_TAG_class_template:
2452 return "DW_TAG_class_template";
2454 return "DW_TAG_<unknown>";
2458 /* Convert a DWARF attribute code into its string name. */
2461 dwarf_attr_name (attr)
2462 register unsigned attr;
2467 return "DW_AT_sibling";
2468 case DW_AT_location:
2469 return "DW_AT_location";
2471 return "DW_AT_name";
2472 case DW_AT_ordering:
2473 return "DW_AT_ordering";
2474 case DW_AT_subscr_data:
2475 return "DW_AT_subscr_data";
2476 case DW_AT_byte_size:
2477 return "DW_AT_byte_size";
2478 case DW_AT_bit_offset:
2479 return "DW_AT_bit_offset";
2480 case DW_AT_bit_size:
2481 return "DW_AT_bit_size";
2482 case DW_AT_element_list:
2483 return "DW_AT_element_list";
2484 case DW_AT_stmt_list:
2485 return "DW_AT_stmt_list";
2487 return "DW_AT_low_pc";
2489 return "DW_AT_high_pc";
2490 case DW_AT_language:
2491 return "DW_AT_language";
2493 return "DW_AT_member";
2495 return "DW_AT_discr";
2496 case DW_AT_discr_value:
2497 return "DW_AT_discr_value";
2498 case DW_AT_visibility:
2499 return "DW_AT_visibility";
2501 return "DW_AT_import";
2502 case DW_AT_string_length:
2503 return "DW_AT_string_length";
2504 case DW_AT_common_reference:
2505 return "DW_AT_common_reference";
2506 case DW_AT_comp_dir:
2507 return "DW_AT_comp_dir";
2508 case DW_AT_const_value:
2509 return "DW_AT_const_value";
2510 case DW_AT_containing_type:
2511 return "DW_AT_containing_type";
2512 case DW_AT_default_value:
2513 return "DW_AT_default_value";
2515 return "DW_AT_inline";
2516 case DW_AT_is_optional:
2517 return "DW_AT_is_optional";
2518 case DW_AT_lower_bound:
2519 return "DW_AT_lower_bound";
2520 case DW_AT_producer:
2521 return "DW_AT_producer";
2522 case DW_AT_prototyped:
2523 return "DW_AT_prototyped";
2524 case DW_AT_return_addr:
2525 return "DW_AT_return_addr";
2526 case DW_AT_start_scope:
2527 return "DW_AT_start_scope";
2528 case DW_AT_stride_size:
2529 return "DW_AT_stride_size";
2530 case DW_AT_upper_bound:
2531 return "DW_AT_upper_bound";
2532 case DW_AT_abstract_origin:
2533 return "DW_AT_abstract_origin";
2534 case DW_AT_accessibility:
2535 return "DW_AT_accessibility";
2536 case DW_AT_address_class:
2537 return "DW_AT_address_class";
2538 case DW_AT_artificial:
2539 return "DW_AT_artificial";
2540 case DW_AT_base_types:
2541 return "DW_AT_base_types";
2542 case DW_AT_calling_convention:
2543 return "DW_AT_calling_convention";
2545 return "DW_AT_count";
2546 case DW_AT_data_member_location:
2547 return "DW_AT_data_member_location";
2548 case DW_AT_decl_column:
2549 return "DW_AT_decl_column";
2550 case DW_AT_decl_file:
2551 return "DW_AT_decl_file";
2552 case DW_AT_decl_line:
2553 return "DW_AT_decl_line";
2554 case DW_AT_declaration:
2555 return "DW_AT_declaration";
2556 case DW_AT_discr_list:
2557 return "DW_AT_discr_list";
2558 case DW_AT_encoding:
2559 return "DW_AT_encoding";
2560 case DW_AT_external:
2561 return "DW_AT_external";
2562 case DW_AT_frame_base:
2563 return "DW_AT_frame_base";
2565 return "DW_AT_friend";
2566 case DW_AT_identifier_case:
2567 return "DW_AT_identifier_case";
2568 case DW_AT_macro_info:
2569 return "DW_AT_macro_info";
2570 case DW_AT_namelist_items:
2571 return "DW_AT_namelist_items";
2572 case DW_AT_priority:
2573 return "DW_AT_priority";
2575 return "DW_AT_segment";
2576 case DW_AT_specification:
2577 return "DW_AT_specification";
2578 case DW_AT_static_link:
2579 return "DW_AT_static_link";
2581 return "DW_AT_type";
2582 case DW_AT_use_location:
2583 return "DW_AT_use_location";
2584 case DW_AT_variable_parameter:
2585 return "DW_AT_variable_parameter";
2586 case DW_AT_virtuality:
2587 return "DW_AT_virtuality";
2588 case DW_AT_vtable_elem_location:
2589 return "DW_AT_vtable_elem_location";
2591 case DW_AT_MIPS_fde:
2592 return "DW_AT_MIPS_fde";
2593 case DW_AT_MIPS_loop_begin:
2594 return "DW_AT_MIPS_loop_begin";
2595 case DW_AT_MIPS_tail_loop_begin:
2596 return "DW_AT_MIPS_tail_loop_begin";
2597 case DW_AT_MIPS_epilog_begin:
2598 return "DW_AT_MIPS_epilog_begin";
2599 case DW_AT_MIPS_loop_unroll_factor:
2600 return "DW_AT_MIPS_loop_unroll_factor";
2601 case DW_AT_MIPS_software_pipeline_depth:
2602 return "DW_AT_MIPS_software_pipeline_depth";
2603 case DW_AT_MIPS_linkage_name:
2604 return "DW_AT_MIPS_linkage_name";
2605 case DW_AT_MIPS_stride:
2606 return "DW_AT_MIPS_stride";
2607 case DW_AT_MIPS_abstract_name:
2608 return "DW_AT_MIPS_abstract_name";
2609 case DW_AT_MIPS_clone_origin:
2610 return "DW_AT_MIPS_clone_origin";
2611 case DW_AT_MIPS_has_inlines:
2612 return "DW_AT_MIPS_has_inlines";
2614 case DW_AT_sf_names:
2615 return "DW_AT_sf_names";
2616 case DW_AT_src_info:
2617 return "DW_AT_src_info";
2618 case DW_AT_mac_info:
2619 return "DW_AT_mac_info";
2620 case DW_AT_src_coords:
2621 return "DW_AT_src_coords";
2622 case DW_AT_body_begin:
2623 return "DW_AT_body_begin";
2624 case DW_AT_body_end:
2625 return "DW_AT_body_end";
2627 return "DW_AT_<unknown>";
2631 /* Convert a DWARF value form code into its string name. */
2634 dwarf_form_name (form)
2635 register unsigned form;
2640 return "DW_FORM_addr";
2641 case DW_FORM_block2:
2642 return "DW_FORM_block2";
2643 case DW_FORM_block4:
2644 return "DW_FORM_block4";
2646 return "DW_FORM_data2";
2648 return "DW_FORM_data4";
2650 return "DW_FORM_data8";
2651 case DW_FORM_string:
2652 return "DW_FORM_string";
2654 return "DW_FORM_block";
2655 case DW_FORM_block1:
2656 return "DW_FORM_block1";
2658 return "DW_FORM_data1";
2660 return "DW_FORM_flag";
2662 return "DW_FORM_sdata";
2664 return "DW_FORM_strp";
2666 return "DW_FORM_udata";
2667 case DW_FORM_ref_addr:
2668 return "DW_FORM_ref_addr";
2670 return "DW_FORM_ref1";
2672 return "DW_FORM_ref2";
2674 return "DW_FORM_ref4";
2676 return "DW_FORM_ref8";
2677 case DW_FORM_ref_udata:
2678 return "DW_FORM_ref_udata";
2679 case DW_FORM_indirect:
2680 return "DW_FORM_indirect";
2682 return "DW_FORM_<unknown>";
2686 /* Convert a DWARF stack opcode into its string name. */
2689 dwarf_stack_op_name (op)
2690 register unsigned op;
2695 return "DW_OP_addr";
2697 return "DW_OP_deref";
2699 return "DW_OP_const1u";
2701 return "DW_OP_const1s";
2703 return "DW_OP_const2u";
2705 return "DW_OP_const2s";
2707 return "DW_OP_const4u";
2709 return "DW_OP_const4s";
2711 return "DW_OP_const8u";
2713 return "DW_OP_const8s";
2715 return "DW_OP_constu";
2717 return "DW_OP_consts";
2721 return "DW_OP_drop";
2723 return "DW_OP_over";
2725 return "DW_OP_pick";
2727 return "DW_OP_swap";
2731 return "DW_OP_xderef";
2739 return "DW_OP_minus";
2751 return "DW_OP_plus";
2752 case DW_OP_plus_uconst:
2753 return "DW_OP_plus_uconst";
2759 return "DW_OP_shra";
2777 return "DW_OP_skip";
2779 return "DW_OP_lit0";
2781 return "DW_OP_lit1";
2783 return "DW_OP_lit2";
2785 return "DW_OP_lit3";
2787 return "DW_OP_lit4";
2789 return "DW_OP_lit5";
2791 return "DW_OP_lit6";
2793 return "DW_OP_lit7";
2795 return "DW_OP_lit8";
2797 return "DW_OP_lit9";
2799 return "DW_OP_lit10";
2801 return "DW_OP_lit11";
2803 return "DW_OP_lit12";
2805 return "DW_OP_lit13";
2807 return "DW_OP_lit14";
2809 return "DW_OP_lit15";
2811 return "DW_OP_lit16";
2813 return "DW_OP_lit17";
2815 return "DW_OP_lit18";
2817 return "DW_OP_lit19";
2819 return "DW_OP_lit20";
2821 return "DW_OP_lit21";
2823 return "DW_OP_lit22";
2825 return "DW_OP_lit23";
2827 return "DW_OP_lit24";
2829 return "DW_OP_lit25";
2831 return "DW_OP_lit26";
2833 return "DW_OP_lit27";
2835 return "DW_OP_lit28";
2837 return "DW_OP_lit29";
2839 return "DW_OP_lit30";
2841 return "DW_OP_lit31";
2843 return "DW_OP_reg0";
2845 return "DW_OP_reg1";
2847 return "DW_OP_reg2";
2849 return "DW_OP_reg3";
2851 return "DW_OP_reg4";
2853 return "DW_OP_reg5";
2855 return "DW_OP_reg6";
2857 return "DW_OP_reg7";
2859 return "DW_OP_reg8";
2861 return "DW_OP_reg9";
2863 return "DW_OP_reg10";
2865 return "DW_OP_reg11";
2867 return "DW_OP_reg12";
2869 return "DW_OP_reg13";
2871 return "DW_OP_reg14";
2873 return "DW_OP_reg15";
2875 return "DW_OP_reg16";
2877 return "DW_OP_reg17";
2879 return "DW_OP_reg18";
2881 return "DW_OP_reg19";
2883 return "DW_OP_reg20";
2885 return "DW_OP_reg21";
2887 return "DW_OP_reg22";
2889 return "DW_OP_reg23";
2891 return "DW_OP_reg24";
2893 return "DW_OP_reg25";
2895 return "DW_OP_reg26";
2897 return "DW_OP_reg27";
2899 return "DW_OP_reg28";
2901 return "DW_OP_reg29";
2903 return "DW_OP_reg30";
2905 return "DW_OP_reg31";
2907 return "DW_OP_breg0";
2909 return "DW_OP_breg1";
2911 return "DW_OP_breg2";
2913 return "DW_OP_breg3";
2915 return "DW_OP_breg4";
2917 return "DW_OP_breg5";
2919 return "DW_OP_breg6";
2921 return "DW_OP_breg7";
2923 return "DW_OP_breg8";
2925 return "DW_OP_breg9";
2927 return "DW_OP_breg10";
2929 return "DW_OP_breg11";
2931 return "DW_OP_breg12";
2933 return "DW_OP_breg13";
2935 return "DW_OP_breg14";
2937 return "DW_OP_breg15";
2939 return "DW_OP_breg16";
2941 return "DW_OP_breg17";
2943 return "DW_OP_breg18";
2945 return "DW_OP_breg19";
2947 return "DW_OP_breg20";
2949 return "DW_OP_breg21";
2951 return "DW_OP_breg22";
2953 return "DW_OP_breg23";
2955 return "DW_OP_breg24";
2957 return "DW_OP_breg25";
2959 return "DW_OP_breg26";
2961 return "DW_OP_breg27";
2963 return "DW_OP_breg28";
2965 return "DW_OP_breg29";
2967 return "DW_OP_breg30";
2969 return "DW_OP_breg31";
2971 return "DW_OP_regx";
2973 return "DW_OP_fbreg";
2975 return "DW_OP_bregx";
2977 return "DW_OP_piece";
2978 case DW_OP_deref_size:
2979 return "DW_OP_deref_size";
2980 case DW_OP_xderef_size:
2981 return "DW_OP_xderef_size";
2985 return "OP_<unknown>";
2989 /* Convert a DWARF type code into its string name. */
2992 dwarf_type_encoding_name (enc)
2993 register unsigned enc;
2997 case DW_ATE_address:
2998 return "DW_ATE_address";
2999 case DW_ATE_boolean:
3000 return "DW_ATE_boolean";
3001 case DW_ATE_complex_float:
3002 return "DW_ATE_complex_float";
3004 return "DW_ATE_float";
3006 return "DW_ATE_signed";
3007 case DW_ATE_signed_char:
3008 return "DW_ATE_signed_char";
3009 case DW_ATE_unsigned:
3010 return "DW_ATE_unsigned";
3011 case DW_ATE_unsigned_char:
3012 return "DW_ATE_unsigned_char";
3014 return "DW_ATE_<unknown>";
3018 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3019 instance of an inlined instance of a decl which is local to an inline
3020 function, so we have to trace all of the way back through the origin chain
3021 to find out what sort of node actually served as the original seed for the
3025 decl_ultimate_origin (decl)
3028 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
3030 if (immediate_origin == NULL_TREE)
3034 register tree ret_val;
3035 register tree lookahead = immediate_origin;
3039 ret_val = lookahead;
3040 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
3042 while (lookahead != NULL && lookahead != ret_val);
3048 /* Determine the "ultimate origin" of a block. The block may be an inlined
3049 instance of an inlined instance of a block which is local to an inline
3050 function, so we have to trace all of the way back through the origin chain
3051 to find out what sort of node actually served as the original seed for the
3055 block_ultimate_origin (block)
3056 register tree block;
3058 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3060 if (immediate_origin == NULL_TREE)
3064 register tree ret_val;
3065 register tree lookahead = immediate_origin;
3069 ret_val = lookahead;
3070 lookahead = (TREE_CODE (ret_val) == BLOCK)
3071 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3074 while (lookahead != NULL && lookahead != ret_val);
3080 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3081 of a virtual function may refer to a base class, so we check the 'this'
3085 decl_class_context (decl)
3088 tree context = NULL_TREE;
3090 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3091 context = DECL_CONTEXT (decl);
3093 context = TYPE_MAIN_VARIANT
3094 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3096 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
3097 context = NULL_TREE;
3102 /* Add an attribute/value pair to a DIE */
3105 add_dwarf_attr (die, attr)
3106 register dw_die_ref die;
3107 register dw_attr_ref attr;
3109 if (die != NULL && attr != NULL)
3111 if (die->die_attr == NULL)
3113 die->die_attr = attr;
3114 die->die_attr_last = attr;
3118 die->die_attr_last->dw_attr_next = attr;
3119 die->die_attr_last = attr;
3124 /* Add a flag value attribute to a DIE. */
3127 add_AT_flag (die, attr_kind, flag)
3128 register dw_die_ref die;
3129 register enum dwarf_attribute attr_kind;
3130 register unsigned flag;
3132 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3134 attr->dw_attr_next = NULL;
3135 attr->dw_attr = attr_kind;
3136 attr->dw_attr_val.val_class = dw_val_class_flag;
3137 attr->dw_attr_val.v.val_flag = flag;
3138 add_dwarf_attr (die, attr);
3141 /* Add a signed integer attribute value to a DIE. */
3144 add_AT_int (die, attr_kind, int_val)
3145 register dw_die_ref die;
3146 register enum dwarf_attribute attr_kind;
3147 register long int int_val;
3149 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3151 attr->dw_attr_next = NULL;
3152 attr->dw_attr = attr_kind;
3153 attr->dw_attr_val.val_class = dw_val_class_const;
3154 attr->dw_attr_val.v.val_int = int_val;
3155 add_dwarf_attr (die, attr);
3158 /* Add an unsigned integer attribute value to a DIE. */
3161 add_AT_unsigned (die, attr_kind, unsigned_val)
3162 register dw_die_ref die;
3163 register enum dwarf_attribute attr_kind;
3164 register unsigned long unsigned_val;
3166 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3168 attr->dw_attr_next = NULL;
3169 attr->dw_attr = attr_kind;
3170 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
3171 attr->dw_attr_val.v.val_unsigned = unsigned_val;
3172 add_dwarf_attr (die, attr);
3175 /* Add an unsigned double integer attribute value to a DIE. */
3178 add_AT_long_long (die, attr_kind, val_hi, val_low)
3179 register dw_die_ref die;
3180 register enum dwarf_attribute attr_kind;
3181 register unsigned long val_hi;
3182 register unsigned long val_low;
3184 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3186 attr->dw_attr_next = NULL;
3187 attr->dw_attr = attr_kind;
3188 attr->dw_attr_val.val_class = dw_val_class_long_long;
3189 attr->dw_attr_val.v.val_long_long.hi = val_hi;
3190 attr->dw_attr_val.v.val_long_long.low = val_low;
3191 add_dwarf_attr (die, attr);
3194 /* Add a floating point attribute value to a DIE and return it. */
3197 add_AT_float (die, attr_kind, length, array)
3198 register dw_die_ref die;
3199 register enum dwarf_attribute attr_kind;
3200 register unsigned length;
3201 register long *array;
3203 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3205 attr->dw_attr_next = NULL;
3206 attr->dw_attr = attr_kind;
3207 attr->dw_attr_val.val_class = dw_val_class_float;
3208 attr->dw_attr_val.v.val_float.length = length;
3209 attr->dw_attr_val.v.val_float.array = array;
3210 add_dwarf_attr (die, attr);
3213 /* Add a string attribute value to a DIE. */
3216 add_AT_string (die, attr_kind, str)
3217 register dw_die_ref die;
3218 register enum dwarf_attribute attr_kind;
3221 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3223 attr->dw_attr_next = NULL;
3224 attr->dw_attr = attr_kind;
3225 attr->dw_attr_val.val_class = dw_val_class_str;
3226 attr->dw_attr_val.v.val_str = xstrdup (str);
3227 add_dwarf_attr (die, attr);
3230 /* Add a DIE reference attribute value to a DIE. */
3233 add_AT_die_ref (die, attr_kind, targ_die)
3234 register dw_die_ref die;
3235 register enum dwarf_attribute attr_kind;
3236 register dw_die_ref targ_die;
3238 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3240 attr->dw_attr_next = NULL;
3241 attr->dw_attr = attr_kind;
3242 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3243 attr->dw_attr_val.v.val_die_ref = targ_die;
3244 add_dwarf_attr (die, attr);
3247 /* Add an FDE reference attribute value to a DIE. */
3250 add_AT_fde_ref (die, attr_kind, targ_fde)
3251 register dw_die_ref die;
3252 register enum dwarf_attribute attr_kind;
3253 register unsigned targ_fde;
3255 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3257 attr->dw_attr_next = NULL;
3258 attr->dw_attr = attr_kind;
3259 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
3260 attr->dw_attr_val.v.val_fde_index = targ_fde;
3261 add_dwarf_attr (die, attr);
3264 /* Add a location description attribute value to a DIE. */
3267 add_AT_loc (die, attr_kind, loc)
3268 register dw_die_ref die;
3269 register enum dwarf_attribute attr_kind;
3270 register dw_loc_descr_ref loc;
3272 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3274 attr->dw_attr_next = NULL;
3275 attr->dw_attr = attr_kind;
3276 attr->dw_attr_val.val_class = dw_val_class_loc;
3277 attr->dw_attr_val.v.val_loc = loc;
3278 add_dwarf_attr (die, attr);
3281 /* Add an address constant attribute value to a DIE. */
3284 add_AT_addr (die, attr_kind, addr)
3285 register dw_die_ref die;
3286 register enum dwarf_attribute attr_kind;
3289 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3291 attr->dw_attr_next = NULL;
3292 attr->dw_attr = attr_kind;
3293 attr->dw_attr_val.val_class = dw_val_class_addr;
3294 attr->dw_attr_val.v.val_addr = addr;
3295 add_dwarf_attr (die, attr);
3298 /* Add a label identifier attribute value to a DIE. */
3301 add_AT_lbl_id (die, attr_kind, lbl_id)
3302 register dw_die_ref die;
3303 register enum dwarf_attribute attr_kind;
3304 register char *lbl_id;
3306 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3308 attr->dw_attr_next = NULL;
3309 attr->dw_attr = attr_kind;
3310 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
3311 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
3312 add_dwarf_attr (die, attr);
3315 /* Add a section offset attribute value to a DIE. */
3318 add_AT_section_offset (die, attr_kind, section)
3319 register dw_die_ref die;
3320 register enum dwarf_attribute attr_kind;
3321 register char *section;
3323 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3325 attr->dw_attr_next = NULL;
3326 attr->dw_attr = attr_kind;
3327 attr->dw_attr_val.val_class = dw_val_class_section_offset;
3328 attr->dw_attr_val.v.val_section = section;
3329 add_dwarf_attr (die, attr);
3333 /* Test if die refers to an external subroutine. */
3336 is_extern_subr_die (die)
3337 register dw_die_ref die;
3339 register dw_attr_ref a;
3340 register int is_subr = FALSE;
3341 register int is_extern = FALSE;
3343 if (die != NULL && die->die_tag == DW_TAG_subprogram)
3346 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3348 if (a->dw_attr == DW_AT_external
3349 && a->dw_attr_val.val_class == dw_val_class_flag
3350 && a->dw_attr_val.v.val_flag != 0)
3358 return is_subr && is_extern;
3361 /* Get the attribute of type attr_kind. */
3363 static inline dw_attr_ref
3364 get_AT (die, attr_kind)
3365 register dw_die_ref die;
3366 register enum dwarf_attribute attr_kind;
3368 register dw_attr_ref a;
3369 register dw_die_ref spec = NULL;
3373 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3375 if (a->dw_attr == attr_kind)
3378 if (a->dw_attr == DW_AT_specification
3379 || a->dw_attr == DW_AT_abstract_origin)
3380 spec = a->dw_attr_val.v.val_die_ref;
3384 return get_AT (spec, attr_kind);
3390 /* Return the "low pc" attribute value, typically associated with
3391 a subprogram DIE. Return null if the "low pc" attribute is
3392 either not prsent, or if it cannot be represented as an
3393 assembler label identifier. */
3395 static inline char *
3397 register dw_die_ref die;
3399 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
3401 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3402 return a->dw_attr_val.v.val_lbl_id;
3407 /* Return the "high pc" attribute value, typically associated with
3408 a subprogram DIE. Return null if the "high pc" attribute is
3409 either not prsent, or if it cannot be represented as an
3410 assembler label identifier. */
3412 static inline char *
3414 register dw_die_ref die;
3416 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
3418 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3419 return a->dw_attr_val.v.val_lbl_id;
3424 /* Return the value of the string attribute designated by ATTR_KIND, or
3425 NULL if it is not present. */
3427 static inline char *
3428 get_AT_string (die, attr_kind)
3429 register dw_die_ref die;
3430 register enum dwarf_attribute attr_kind;
3432 register dw_attr_ref a = get_AT (die, attr_kind);
3434 if (a && a->dw_attr_val.val_class == dw_val_class_str)
3435 return a->dw_attr_val.v.val_str;
3440 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3441 if it is not present. */
3444 get_AT_flag (die, attr_kind)
3445 register dw_die_ref die;
3446 register enum dwarf_attribute attr_kind;
3448 register dw_attr_ref a = get_AT (die, attr_kind);
3450 if (a && a->dw_attr_val.val_class == dw_val_class_flag)
3451 return a->dw_attr_val.v.val_flag;
3456 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3457 if it is not present. */
3459 static inline unsigned
3460 get_AT_unsigned (die, attr_kind)
3461 register dw_die_ref die;
3462 register enum dwarf_attribute attr_kind;
3464 register dw_attr_ref a = get_AT (die, attr_kind);
3466 if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
3467 return a->dw_attr_val.v.val_unsigned;
3475 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3477 return (lang == DW_LANG_C || lang == DW_LANG_C89
3478 || lang == DW_LANG_C_plus_plus);
3484 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3486 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
3489 /* Remove the specified attribute if present. */
3492 remove_AT (die, attr_kind)
3493 register dw_die_ref die;
3494 register enum dwarf_attribute attr_kind;
3496 register dw_attr_ref a;
3497 register dw_attr_ref removed = NULL;;
3501 if (die->die_attr->dw_attr == attr_kind)
3503 removed = die->die_attr;
3504 if (die->die_attr_last == die->die_attr)
3505 die->die_attr_last = NULL;
3507 die->die_attr = die->die_attr->dw_attr_next;
3511 for (a = die->die_attr; a->dw_attr_next != NULL;
3512 a = a->dw_attr_next)
3513 if (a->dw_attr_next->dw_attr == attr_kind)
3515 removed = a->dw_attr_next;
3516 if (die->die_attr_last == a->dw_attr_next)
3517 die->die_attr_last = a;
3519 a->dw_attr_next = a->dw_attr_next->dw_attr_next;
3528 /* Discard the children of this DIE. */
3531 remove_children (die)
3532 register dw_die_ref die;
3534 register dw_die_ref child_die = die->die_child;
3536 die->die_child = NULL;
3537 die->die_child_last = NULL;
3539 while (child_die != NULL)
3541 register dw_die_ref tmp_die = child_die;
3542 register dw_attr_ref a;
3544 child_die = child_die->die_sib;
3546 for (a = tmp_die->die_attr; a != NULL; )
3548 register dw_attr_ref tmp_a = a;
3550 a = a->dw_attr_next;
3558 /* Add a child DIE below its parent. */
3561 add_child_die (die, child_die)
3562 register dw_die_ref die;
3563 register dw_die_ref child_die;
3565 if (die != NULL && child_die != NULL)
3567 assert (die != child_die);
3568 child_die->die_parent = die;
3569 child_die->die_sib = NULL;
3571 if (die->die_child == NULL)
3573 die->die_child = child_die;
3574 die->die_child_last = child_die;
3578 die->die_child_last->die_sib = child_die;
3579 die->die_child_last = child_die;
3584 /* Return a pointer to a newly created DIE node. */
3586 static inline dw_die_ref
3587 new_die (tag_value, parent_die)
3588 register enum dwarf_tag tag_value;
3589 register dw_die_ref parent_die;
3591 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
3593 die->die_tag = tag_value;
3594 die->die_abbrev = 0;
3595 die->die_offset = 0;
3596 die->die_child = NULL;
3597 die->die_parent = NULL;
3598 die->die_sib = NULL;
3599 die->die_child_last = NULL;
3600 die->die_attr = NULL;
3601 die->die_attr_last = NULL;
3603 if (parent_die != NULL)
3604 add_child_die (parent_die, die);
3611 /* Return the DIE associated with the given type specifier. */
3613 static inline dw_die_ref
3614 lookup_type_die (type)
3617 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
3620 /* Equate a DIE to a given type specifier. */
3623 equate_type_number_to_die (type, type_die)
3625 register dw_die_ref type_die;
3627 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
3630 /* Return the DIE associated with a given declaration. */
3632 static inline dw_die_ref
3633 lookup_decl_die (decl)
3636 register unsigned decl_id = DECL_UID (decl);
3638 return (decl_id < decl_die_table_in_use
3639 ? decl_die_table[decl_id] : NULL);
3642 /* Equate a DIE to a particular declaration. */
3645 equate_decl_number_to_die (decl, decl_die)
3647 register dw_die_ref decl_die;
3649 register unsigned decl_id = DECL_UID (decl);
3650 register unsigned i;
3651 register unsigned num_allocated;
3653 if (decl_id >= decl_die_table_allocated)
3656 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
3657 / DECL_DIE_TABLE_INCREMENT)
3658 * DECL_DIE_TABLE_INCREMENT;
3661 = (dw_die_ref *) xrealloc (decl_die_table,
3662 sizeof (dw_die_ref) * num_allocated);
3664 bzero ((char *) &decl_die_table[decl_die_table_allocated],
3665 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
3666 decl_die_table_allocated = num_allocated;
3669 if (decl_id >= decl_die_table_in_use)
3670 decl_die_table_in_use = (decl_id + 1);
3672 decl_die_table[decl_id] = decl_die;
3675 /* Return a pointer to a newly allocated location description. Location
3676 descriptions are simple expression terms that can be strung
3677 together to form more complicated location (address) descriptions. */
3679 static inline dw_loc_descr_ref
3680 new_loc_descr (op, oprnd1, oprnd2)
3681 register enum dwarf_location_atom op;
3682 register unsigned long oprnd1;
3683 register unsigned long oprnd2;
3685 register dw_loc_descr_ref descr
3686 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
3688 descr->dw_loc_next = NULL;
3689 descr->dw_loc_opc = op;
3690 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3691 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3692 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3693 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3698 /* Add a location description term to a location description expression. */
3701 add_loc_descr (list_head, descr)
3702 register dw_loc_descr_ref *list_head;
3703 register dw_loc_descr_ref descr;
3705 register dw_loc_descr_ref *d;
3707 /* Find the end of the chain. */
3708 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3714 /* Keep track of the number of spaces used to indent the
3715 output of the debugging routines that print the structure of
3716 the DIE internal representation. */
3717 static int print_indent;
3719 /* Indent the line the number of spaces given by print_indent. */
3722 print_spaces (outfile)
3725 fprintf (outfile, "%*s", print_indent, "");
3728 /* Print the information assoaciated with a given DIE, and its children.
3729 This routine is a debugging aid only. */
3732 print_die (die, outfile)
3736 register dw_attr_ref a;
3737 register dw_die_ref c;
3739 print_spaces (outfile);
3740 fprintf (outfile, "DIE %4u: %s\n",
3741 die->die_offset, dwarf_tag_name (die->die_tag));
3742 print_spaces (outfile);
3743 fprintf (outfile, " abbrev id: %u", die->die_abbrev);
3744 fprintf (outfile, " offset: %u\n", die->die_offset);
3746 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3748 print_spaces (outfile);
3749 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
3751 switch (a->dw_attr_val.val_class)
3753 case dw_val_class_addr:
3754 fprintf (outfile, "address");
3756 case dw_val_class_loc:
3757 fprintf (outfile, "location descriptor");
3759 case dw_val_class_const:
3760 fprintf (outfile, "%d", a->dw_attr_val.v.val_int);
3762 case dw_val_class_unsigned_const:
3763 fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned);
3765 case dw_val_class_long_long:
3766 fprintf (outfile, "constant (%u,%u)",
3767 a->dw_attr_val.v.val_long_long.hi,
3768 a->dw_attr_val.v.val_long_long.low);
3770 case dw_val_class_float:
3771 fprintf (outfile, "floating-point constant");
3773 case dw_val_class_flag:
3774 fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
3776 case dw_val_class_die_ref:
3777 if (a->dw_attr_val.v.val_die_ref != NULL)
3778 fprintf (outfile, "die -> %u",
3779 a->dw_attr_val.v.val_die_ref->die_offset);
3781 fprintf (outfile, "die -> <null>");
3783 case dw_val_class_lbl_id:
3784 fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
3786 case dw_val_class_section_offset:
3787 fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section);
3789 case dw_val_class_str:
3790 if (a->dw_attr_val.v.val_str != NULL)
3791 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
3793 fprintf (outfile, "<null>");
3797 fprintf (outfile, "\n");
3800 if (die->die_child != NULL)
3803 for (c = die->die_child; c != NULL; c = c->die_sib)
3804 print_die (c, outfile);
3810 /* Print the contents of the source code line number correspondence table.
3811 This routine is a debugging aid only. */
3814 print_dwarf_line_table (outfile)
3817 register unsigned i;
3818 register dw_line_info_ref line_info;
3820 fprintf (outfile, "\n\nDWARF source line information\n");
3821 for (i = 1; i < line_info_table_in_use; ++i)
3823 line_info = &line_info_table[i];
3824 fprintf (outfile, "%5d: ", i);
3825 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
3826 fprintf (outfile, "%6d", line_info->dw_line_num);
3827 fprintf (outfile, "\n");
3830 fprintf (outfile, "\n\n");
3833 /* Print the information collected for a given DIE. */
3836 debug_dwarf_die (die)
3839 print_die (die, stderr);
3842 /* Print all DWARF information collected for the compilation unit.
3843 This routine is a debugging aid only. */
3849 print_die (comp_unit_die, stderr);
3850 print_dwarf_line_table (stderr);
3853 /* Traverse the DIE, and add a sibling attribute if it may have the
3854 effect of speeding up access to siblings. To save some space,
3855 avoid generating sibling attributes for DIE's without children. */
3858 add_sibling_attributes(die)
3859 register dw_die_ref die;
3861 register dw_die_ref c;
3862 register dw_attr_ref attr;
3863 if (die != comp_unit_die && die->die_child != NULL)
3865 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3866 attr->dw_attr_next = NULL;
3867 attr->dw_attr = DW_AT_sibling;
3868 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3869 attr->dw_attr_val.v.val_die_ref = die->die_sib;
3871 /* Add the sibling link to the front of the attribute list. */
3872 attr->dw_attr_next = die->die_attr;
3873 if (die->die_attr == NULL)
3874 die->die_attr_last = attr;
3876 die->die_attr = attr;
3879 for (c = die->die_child; c != NULL; c = c->die_sib)
3880 add_sibling_attributes (c);
3883 /* The format of each DIE (and its attribute value pairs)
3884 is encoded in an abbreviation table. This routine builds the
3885 abbreviation table and assigns a unique abbreviation id for
3886 each abbreviation entry. The children of each die are visited
3890 build_abbrev_table (die)
3891 register dw_die_ref die;
3893 register unsigned long abbrev_id;
3894 register unsigned long n_alloc;
3895 register dw_die_ref c;
3896 register dw_attr_ref d_attr, a_attr;
3897 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
3899 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
3901 if (abbrev->die_tag == die->die_tag)
3903 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
3905 a_attr = abbrev->die_attr;
3906 d_attr = die->die_attr;
3908 while (a_attr != NULL && d_attr != NULL)
3910 if ((a_attr->dw_attr != d_attr->dw_attr)
3911 || (value_format (&a_attr->dw_attr_val)
3912 != value_format (&d_attr->dw_attr_val)))
3915 a_attr = a_attr->dw_attr_next;
3916 d_attr = d_attr->dw_attr_next;
3919 if (a_attr == NULL && d_attr == NULL)
3925 if (abbrev_id >= abbrev_die_table_in_use)
3927 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
3929 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
3931 = (dw_die_ref *) xmalloc (abbrev_die_table,
3932 sizeof (dw_die_ref) * n_alloc);
3934 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
3935 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
3936 abbrev_die_table_allocated = n_alloc;
3939 ++abbrev_die_table_in_use;
3940 abbrev_die_table[abbrev_id] = die;
3943 die->die_abbrev = abbrev_id;
3944 for (c = die->die_child; c != NULL; c = c->die_sib)
3945 build_abbrev_table (c);
3948 /* Return the size of a string, including the null byte. */
3950 static unsigned long
3951 size_of_string (str)
3954 register unsigned long size = 0;
3955 register unsigned long slen = strlen (str);
3956 register unsigned long i;
3957 register unsigned c;
3959 for (i = 0; i < slen; ++i)
3968 /* Null terminator. */
3973 /* Return the size of a location descriptor. */
3975 static unsigned long
3976 size_of_loc_descr (loc)
3977 register dw_loc_descr_ref loc;
3979 register unsigned long size = 1;
3981 switch (loc->dw_loc_opc)
4003 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4006 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4011 case DW_OP_plus_uconst:
4012 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4050 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4053 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4056 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4059 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4060 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4063 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4065 case DW_OP_deref_size:
4066 case DW_OP_xderef_size:
4076 /* Return the size of a series of location descriptors. */
4078 static unsigned long
4080 register dw_loc_descr_ref loc;
4082 register unsigned long size = 0;
4084 for (; loc != NULL; loc = loc->dw_loc_next)
4085 size += size_of_loc_descr (loc);
4090 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4093 constant_size (value)
4094 long unsigned value;
4101 log = floor_log2 (value);
4104 log = 1 << (floor_log2 (log) + 1);
4109 /* Return the size of a DIE, as it is represented in the
4110 .debug_info section. */
4112 static unsigned long
4114 register dw_die_ref die;
4116 register unsigned long size = 0;
4117 register dw_attr_ref a;
4119 size += size_of_uleb128 (die->die_abbrev);
4120 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4122 switch (a->dw_attr_val.val_class)
4124 case dw_val_class_addr:
4127 case dw_val_class_loc:
4129 register unsigned long lsize
4130 = size_of_locs (a->dw_attr_val.v.val_loc);
4133 size += constant_size (lsize);
4137 case dw_val_class_const:
4140 case dw_val_class_unsigned_const:
4141 size += constant_size (a->dw_attr_val.v.val_unsigned);
4143 case dw_val_class_long_long:
4144 size += 1 + 8; /* block */
4146 case dw_val_class_float:
4147 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
4149 case dw_val_class_flag:
4152 case dw_val_class_die_ref:
4153 size += DWARF_OFFSET_SIZE;
4155 case dw_val_class_fde_ref:
4156 size += DWARF_OFFSET_SIZE;
4158 case dw_val_class_lbl_id:
4161 case dw_val_class_section_offset:
4162 size += DWARF_OFFSET_SIZE;
4164 case dw_val_class_str:
4165 size += size_of_string (a->dw_attr_val.v.val_str);
4175 /* Size the debgging information associted with a given DIE.
4176 Visits the DIE's children recursively. Updates the global
4177 variable next_die_offset, on each time through. Uses the
4178 current value of next_die_offset to updete the die_offset
4179 field in each DIE. */
4182 calc_die_sizes (die)
4185 register dw_die_ref c;
4186 die->die_offset = next_die_offset;
4187 next_die_offset += size_of_die (die);
4189 for (c = die->die_child; c != NULL; c = c->die_sib)
4192 if (die->die_child != NULL)
4193 /* Count the null byte used to terminate sibling lists. */
4194 next_die_offset += 1;
4197 /* Return the size of the line information prolog generated for the
4198 compilation unit. */
4200 static unsigned long
4201 size_of_line_prolog ()
4203 register unsigned long size;
4204 register unsigned long ft_index;
4206 size = DWARF_LINE_PROLOG_HEADER_SIZE;
4208 /* Count the size of the table giving number of args for each
4210 size += DWARF_LINE_OPCODE_BASE - 1;
4212 /* Include directory table is empty (at present). Count only the
4213 the null byte used to terminate the table. */
4216 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4218 /* File name entry. */
4219 size += size_of_string (file_table[ft_index]);
4221 /* Include directory index. */
4222 size += size_of_uleb128 (0);
4224 /* Modification time. */
4225 size += size_of_uleb128 (0);
4227 /* File length in bytes. */
4228 size += size_of_uleb128 (0);
4231 /* Count the file table terminator. */
4236 /* Return the size of the line information generated for this
4237 compilation unit. */
4239 static unsigned long
4240 size_of_line_info ()
4242 register unsigned long size;
4243 register unsigned long lt_index;
4244 register unsigned long current_line;
4245 register long line_offset;
4246 register long line_delta;
4247 register unsigned long current_file;
4248 register unsigned long function;
4250 /* Version number. */
4253 /* Prolog length specifier. */
4254 size += DWARF_OFFSET_SIZE;
4257 size += size_of_line_prolog ();
4259 /* Set address register instruction. */
4260 size += 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
4264 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
4266 register dw_line_info_ref line_info;
4268 /* Advance pc instruction. */
4270 line_info = &line_info_table[lt_index];
4271 if (line_info->dw_file_num != current_file)
4273 /* Set file number instruction. */
4275 current_file = line_info->dw_file_num;
4276 size += size_of_uleb128 (current_file);
4279 if (line_info->dw_line_num != current_line)
4281 line_offset = line_info->dw_line_num - current_line;
4282 line_delta = line_offset - DWARF_LINE_BASE;
4283 current_line = line_info->dw_line_num;
4284 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4285 /* 1-byte special line number instruction. */
4289 /* Advance line instruction. */
4291 size += size_of_sleb128 (line_offset);
4292 /* Generate line entry instruction. */
4298 /* Advance pc instruction. */
4301 /* End of line number info. marker. */
4302 size += 1 + size_of_uleb128 (1) + 1;
4307 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
4309 register dw_separate_line_info_ref line_info
4310 = &separate_line_info_table[lt_index];
4311 if (function != line_info->function)
4313 function = line_info->function;
4314 /* Set address register instruction. */
4315 size += 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
4318 /* Advance pc instruction. */
4321 if (line_info->dw_file_num != current_file)
4323 /* Set file number instruction. */
4325 current_file = line_info->dw_file_num;
4326 size += size_of_uleb128 (current_file);
4329 if (line_info->dw_line_num != current_line)
4331 line_offset = line_info->dw_line_num - current_line;
4332 line_delta = line_offset - DWARF_LINE_BASE;
4333 current_line = line_info->dw_line_num;
4334 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4335 /* 1-byte special line number instruction. */
4339 /* Advance line instruction. */
4341 size += size_of_sleb128 (line_offset);
4343 /* Generate line entry instruction. */
4350 /* If we're done with a function, end its sequence. */
4351 if (lt_index == separate_line_info_table_in_use
4352 || separate_line_info_table[lt_index].function != function)
4357 /* Advance pc instruction. */
4360 /* End of line number info. marker. */
4361 size += 1 + size_of_uleb128 (1) + 1;
4368 /* Return the size of the .debug_pubnames table generated for the
4369 compilation unit. */
4371 static unsigned long
4374 register unsigned long size;
4375 register unsigned i;
4377 size = DWARF_PUBNAMES_HEADER_SIZE;
4378 for (i = 0; i < pubname_table_in_use; ++i)
4380 register pubname_ref p = &pubname_table[i];
4381 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
4384 size += DWARF_OFFSET_SIZE;
4388 /* Return the size of the information in the .debug_aranges seciton. */
4390 static unsigned long
4393 register unsigned long size;
4395 size = DWARF_ARANGES_HEADER_SIZE;
4397 /* Count the address/length pair for this compilation unit. */
4398 size += 2 * PTR_SIZE;
4399 size += 2 * PTR_SIZE * arange_table_in_use;
4401 /* Count the two zero words used to terminated the address range table. */
4402 size += 2 * PTR_SIZE;
4406 /* Select the encoding of an attribute value. */
4408 static enum dwarf_form
4412 switch (v->val_class)
4414 case dw_val_class_addr:
4415 return DW_FORM_addr;
4416 case dw_val_class_loc:
4417 switch (constant_size (size_of_locs (v->v.val_loc)))
4420 return DW_FORM_block1;
4422 return DW_FORM_block2;
4426 case dw_val_class_const:
4427 return DW_FORM_data4;
4428 case dw_val_class_unsigned_const:
4429 switch (constant_size (v->v.val_unsigned))
4432 return DW_FORM_data1;
4434 return DW_FORM_data2;
4436 return DW_FORM_data4;
4438 return DW_FORM_data8;
4442 case dw_val_class_long_long:
4443 return DW_FORM_block1;
4444 case dw_val_class_float:
4445 return DW_FORM_block1;
4446 case dw_val_class_flag:
4447 return DW_FORM_flag;
4448 case dw_val_class_die_ref:
4450 case dw_val_class_fde_ref:
4451 return DW_FORM_data;
4452 case dw_val_class_lbl_id:
4453 return DW_FORM_addr;
4454 case dw_val_class_section_offset:
4455 return DW_FORM_data;
4456 case dw_val_class_str:
4457 return DW_FORM_string;
4463 /* Output the encoding of an attribute value. */
4466 output_value_format (v)
4469 enum dwarf_form form = value_format (v);
4471 output_uleb128 (form);
4472 if (flag_verbose_asm)
4473 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
4475 fputc ('\n', asm_out_file);
4478 /* Output the .debug_abbrev section which defines the DIE abbreviation
4482 output_abbrev_section ()
4484 unsigned long abbrev_id;
4487 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4489 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4491 output_uleb128 (abbrev_id);
4492 if (flag_verbose_asm)
4493 fprintf (asm_out_file, " (abbrev code)");
4495 fputc ('\n', asm_out_file);
4496 output_uleb128 (abbrev->die_tag);
4497 if (flag_verbose_asm)
4498 fprintf (asm_out_file, " (TAG: %s)",
4499 dwarf_tag_name (abbrev->die_tag));
4501 fputc ('\n', asm_out_file);
4502 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
4503 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
4505 if (flag_verbose_asm)
4506 fprintf (asm_out_file, "\t%s %s",
4508 (abbrev->die_child != NULL
4509 ? "DW_children_yes" : "DW_children_no"));
4511 fputc ('\n', asm_out_file);
4513 for (a_attr = abbrev->die_attr; a_attr != NULL;
4514 a_attr = a_attr->dw_attr_next)
4516 output_uleb128 (a_attr->dw_attr);
4517 if (flag_verbose_asm)
4518 fprintf (asm_out_file, " (%s)",
4519 dwarf_attr_name (a_attr->dw_attr));
4521 fputc ('\n', asm_out_file);
4522 output_value_format (&a_attr->dw_attr_val);
4525 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
4529 /* Output location description stack opcode's operands (if any). */
4532 output_loc_operands (loc)
4533 register dw_loc_descr_ref loc;
4535 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
4536 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
4538 switch (loc->dw_loc_opc)
4541 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
4542 fputc ('\n', asm_out_file);
4546 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4547 fputc ('\n', asm_out_file);
4551 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4552 fputc ('\n', asm_out_file);
4556 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
4557 fputc ('\n', asm_out_file);
4562 fputc ('\n', asm_out_file);
4565 output_uleb128 (val1->v.val_unsigned);
4566 fputc ('\n', asm_out_file);
4569 output_sleb128 (val1->v.val_int);
4570 fputc ('\n', asm_out_file);
4573 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
4574 fputc ('\n', asm_out_file);
4576 case DW_OP_plus_uconst:
4577 output_uleb128 (val1->v.val_unsigned);
4578 fputc ('\n', asm_out_file);
4582 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4583 fputc ('\n', asm_out_file);
4617 output_sleb128 (val1->v.val_int);
4618 fputc ('\n', asm_out_file);
4621 output_uleb128 (val1->v.val_unsigned);
4622 fputc ('\n', asm_out_file);
4625 output_sleb128 (val1->v.val_int);
4626 fputc ('\n', asm_out_file);
4629 output_uleb128 (val1->v.val_unsigned);
4630 fputc ('\n', asm_out_file);
4631 output_sleb128 (val2->v.val_int);
4632 fputc ('\n', asm_out_file);
4635 output_uleb128 (val1->v.val_unsigned);
4636 fputc ('\n', asm_out_file);
4638 case DW_OP_deref_size:
4639 case DW_OP_xderef_size:
4640 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4641 fputc ('\n', asm_out_file);
4648 /* Compute the offset of a sibling. */
4650 static unsigned long
4651 sibling_offset (die)
4654 unsigned long offset;
4656 if (die->die_child_last == NULL)
4657 offset = die->die_offset + size_of_die (die);
4659 offset = sibling_offset (die->die_child_last) + 1;
4664 /* Output the DIE and its attributes. Called recursively to generate
4665 the definitions of each child DIE. */
4669 register dw_die_ref die;
4671 register dw_attr_ref a;
4672 register dw_die_ref c;
4673 register unsigned long ref_offset;
4674 register unsigned long size;
4675 register dw_loc_descr_ref loc;
4678 output_uleb128 (die->die_abbrev);
4679 if (flag_verbose_asm)
4680 fprintf (asm_out_file, " (DIE (0x%x) %s)",
4681 die->die_offset, dwarf_tag_name (die->die_tag));
4683 fputc ('\n', asm_out_file);
4685 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4687 switch (a->dw_attr_val.val_class)
4689 case dw_val_class_addr:
4690 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
4691 a->dw_attr_val.v.val_addr);
4694 case dw_val_class_loc:
4695 size = size_of_locs (a->dw_attr_val.v.val_loc);
4697 /* Output the block length for this list of location operations. */
4698 switch (constant_size (size))
4701 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
4704 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
4710 if (flag_verbose_asm)
4711 fprintf (asm_out_file, "\t%s %s",
4712 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
4714 fputc ('\n', asm_out_file);
4715 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
4716 loc = loc->dw_loc_next)
4718 /* Output the opcode. */
4719 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
4720 if (flag_verbose_asm)
4721 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
4722 dwarf_stack_op_name (loc->dw_loc_opc));
4724 fputc ('\n', asm_out_file);
4726 /* Output the operand(s) (if any). */
4727 output_loc_operands (loc);
4731 case dw_val_class_const:
4732 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
4735 case dw_val_class_unsigned_const:
4736 switch (constant_size (a->dw_attr_val.v.val_unsigned))
4739 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4740 a->dw_attr_val.v.val_unsigned);
4743 ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
4744 a->dw_attr_val.v.val_unsigned);
4747 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
4748 a->dw_attr_val.v.val_unsigned);
4751 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
4752 a->dw_attr_val.v.val_long_long.hi,
4753 a->dw_attr_val.v.val_long_long.low);
4760 case dw_val_class_long_long:
4761 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
4762 if (flag_verbose_asm)
4763 fprintf (asm_out_file, "\t%s %s",
4764 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
4766 fputc ('\n', asm_out_file);
4767 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
4768 a->dw_attr_val.v.val_long_long.hi,
4769 a->dw_attr_val.v.val_long_long.low);
4771 if (flag_verbose_asm)
4772 fprintf (asm_out_file,
4773 "\t%s long long constant", ASM_COMMENT_START);
4775 fputc ('\n', asm_out_file);
4778 case dw_val_class_float:
4779 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4780 a->dw_attr_val.v.val_float.length * 4);
4781 if (flag_verbose_asm)
4782 fprintf (asm_out_file, "\t%s %s",
4783 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
4785 fputc ('\n', asm_out_file);
4786 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
4788 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
4789 a->dw_attr_val.v.val_float.array[i]);
4790 if (flag_verbose_asm)
4791 fprintf (asm_out_file, "\t%s fp constant word %d",
4792 ASM_COMMENT_START, i);
4794 fputc ('\n', asm_out_file);
4798 case dw_val_class_flag:
4799 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
4802 case dw_val_class_die_ref:
4803 if (a->dw_attr_val.v.val_die_ref != NULL)
4804 ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
4805 else if (a->dw_attr == DW_AT_sibling)
4806 ref_offset = sibling_offset(die);
4810 ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
4813 case dw_val_class_fde_ref:
4814 ref_offset = fde_table[a->dw_attr_val.v.val_fde_index].dw_fde_offset;
4815 fprintf (asm_out_file, "\t%s\t%s+0x%x", UNALIGNED_OFFSET_ASM_OP,
4816 stripattributes (FRAME_SECTION), ref_offset);
4819 case dw_val_class_lbl_id:
4820 ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
4823 case dw_val_class_section_offset:
4824 ASM_OUTPUT_DWARF_OFFSET (asm_out_file,
4826 (a->dw_attr_val.v.val_section));
4829 case dw_val_class_str:
4830 ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
4837 if (a->dw_attr_val.val_class != dw_val_class_loc
4838 && a->dw_attr_val.val_class != dw_val_class_long_long
4839 && a->dw_attr_val.val_class != dw_val_class_float)
4841 if (flag_verbose_asm)
4842 fprintf (asm_out_file, "\t%s %s",
4843 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
4845 fputc ('\n', asm_out_file);
4849 for (c = die->die_child; c != NULL; c = c->die_sib)
4852 if (die->die_child != NULL)
4854 /* Add null byte to terminate sibling list. */
4855 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4856 if (flag_verbose_asm)
4857 fprintf (asm_out_file, "\t%s end of children of DIE 0x%x",
4858 ASM_COMMENT_START, die->die_offset);
4860 fputc ('\n', asm_out_file);
4864 /* Output the compilation unit that appears at the beginning of the
4865 .debug_info section, and precedes the DIE descriptions. */
4868 output_compilation_unit_header ()
4870 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
4871 if (flag_verbose_asm)
4872 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
4875 fputc ('\n', asm_out_file);
4876 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4877 if (flag_verbose_asm)
4878 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
4880 fputc ('\n', asm_out_file);
4881 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION));
4882 if (flag_verbose_asm)
4883 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
4886 fputc ('\n', asm_out_file);
4887 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
4888 if (flag_verbose_asm)
4889 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
4891 fputc ('\n', asm_out_file);
4894 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
4895 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
4896 argument list, and maybe the scope. */
4899 dwarf2_name (decl, scope)
4903 return (*decl_printable_name) (decl, scope ? 1 : 0);
4906 /* Add a new entry to .debug_pubnames if appropriate. */
4909 add_pubname (decl, die)
4915 if (! TREE_PUBLIC (decl))
4918 if (pubname_table_in_use == pubname_table_allocated)
4920 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
4921 pubname_table = (pubname_ref) xrealloc
4922 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
4925 p = &pubname_table[pubname_table_in_use++];
4928 p->name = xstrdup (dwarf2_name (decl, 1));
4931 /* Output the public names table used to speed up access to externally
4932 visible names. For now, only generate entries for externally
4933 visible procedures. */
4938 register unsigned i;
4939 register unsigned long pubnames_length = size_of_pubnames ();
4941 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
4943 if (flag_verbose_asm)
4944 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
4947 fputc ('\n', asm_out_file);
4948 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4950 if (flag_verbose_asm)
4951 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
4953 fputc ('\n', asm_out_file);
4954 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
4955 if (flag_verbose_asm)
4956 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
4959 fputc ('\n', asm_out_file);
4960 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
4961 if (flag_verbose_asm)
4962 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
4964 fputc ('\n', asm_out_file);
4965 for (i = 0; i < pubname_table_in_use; ++i)
4967 register pubname_ref pub = &pubname_table[i];
4969 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
4970 if (flag_verbose_asm)
4971 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
4973 fputc ('\n', asm_out_file);
4975 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
4976 if (flag_verbose_asm)
4977 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
4979 fputc ('\n', asm_out_file);
4982 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
4983 fputc ('\n', asm_out_file);
4986 /* Add a new entry to .debug_aranges if appropriate. */
4989 add_arange (decl, die)
4993 if (! DECL_SECTION_NAME (decl))
4996 if (arange_table_in_use == arange_table_allocated)
4998 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5000 = (arange_ref) xrealloc (arange_table,
5001 arange_table_allocated * sizeof (dw_die_ref));
5004 arange_table[arange_table_in_use++] = die;
5007 /* Output the information that goes into the .debug_aranges table.
5008 Namely, define the beginning and ending address range of the
5009 text section generated for this compilation unit. */
5014 register unsigned i;
5015 register unsigned long aranges_length = size_of_aranges ();
5017 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
5018 if (flag_verbose_asm)
5019 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
5022 fputc ('\n', asm_out_file);
5023 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5024 if (flag_verbose_asm)
5025 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5027 fputc ('\n', asm_out_file);
5028 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
5029 if (flag_verbose_asm)
5030 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5033 fputc ('\n', asm_out_file);
5034 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5035 if (flag_verbose_asm)
5036 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
5038 fputc ('\n', asm_out_file);
5039 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5040 if (flag_verbose_asm)
5041 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
5044 fputc ('\n', asm_out_file);
5045 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
5047 fprintf (asm_out_file, ",0,0");
5049 if (flag_verbose_asm)
5050 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5051 ASM_COMMENT_START, 2 * PTR_SIZE);
5053 fputc ('\n', asm_out_file);
5054 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
5055 if (flag_verbose_asm)
5056 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5058 fputc ('\n', asm_out_file);
5059 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label, TEXT_SECTION);
5060 if (flag_verbose_asm)
5061 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5063 fputc ('\n', asm_out_file);
5064 for (i = 0; i < arange_table_in_use; ++i)
5066 dw_die_ref a = arange_table[i];
5068 if (a->die_tag == DW_TAG_subprogram)
5069 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a));
5072 char *name = get_AT_string (a, DW_AT_MIPS_linkage_name);
5074 name = get_AT_string (a, DW_AT_name);
5076 ASM_OUTPUT_DWARF_ADDR (asm_out_file, name);
5079 if (flag_verbose_asm)
5080 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5082 fputc ('\n', asm_out_file);
5083 if (a->die_tag == DW_TAG_subprogram)
5084 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a),
5087 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5088 get_AT_unsigned (a, DW_AT_byte_size));
5090 if (flag_verbose_asm)
5091 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5093 fputc ('\n', asm_out_file);
5096 /* Output the terminator words. */
5097 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5098 fputc ('\n', asm_out_file);
5099 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5100 fputc ('\n', asm_out_file);
5103 /* Output the source line number correspondence information. This
5104 information goes into the .debug_line section. */
5109 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5110 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5111 register unsigned opc;
5112 register unsigned n_op_args;
5113 register unsigned long ft_index;
5114 register unsigned long lt_index;
5115 register unsigned long current_line;
5116 register long line_offset;
5117 register long line_delta;
5118 register unsigned long current_file;
5119 register unsigned long function;
5121 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ());
5122 if (flag_verbose_asm)
5123 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5126 fputc ('\n', asm_out_file);
5127 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5128 if (flag_verbose_asm)
5129 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5131 fputc ('\n', asm_out_file);
5132 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
5133 if (flag_verbose_asm)
5134 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5136 fputc ('\n', asm_out_file);
5137 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
5138 if (flag_verbose_asm)
5139 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5142 fputc ('\n', asm_out_file);
5143 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
5144 if (flag_verbose_asm)
5145 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5148 fputc ('\n', asm_out_file);
5149 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
5150 if (flag_verbose_asm)
5151 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5154 fputc ('\n', asm_out_file);
5155 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
5156 if (flag_verbose_asm)
5157 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5160 fputc ('\n', asm_out_file);
5161 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5162 if (flag_verbose_asm)
5163 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5165 fputc ('\n', asm_out_file);
5166 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5170 case DW_LNS_advance_pc:
5171 case DW_LNS_advance_line:
5172 case DW_LNS_set_file:
5173 case DW_LNS_set_column:
5174 case DW_LNS_fixed_advance_pc:
5181 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5182 if (flag_verbose_asm)
5183 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5184 ASM_COMMENT_START, opc, n_op_args);
5185 fputc ('\n', asm_out_file);
5188 if (flag_verbose_asm)
5189 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5191 /* Include directory table is empty, at present */
5192 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5193 fputc ('\n', asm_out_file);
5194 if (flag_verbose_asm)
5195 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5197 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5199 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5200 if (flag_verbose_asm)
5201 fprintf (asm_out_file, "%s File Entry: 0x%x",
5202 ASM_COMMENT_START, ft_index);
5204 fputc ('\n', asm_out_file);
5206 /* Include directory index */
5208 fputc ('\n', asm_out_file);
5210 /* Modification time */
5212 fputc ('\n', asm_out_file);
5214 /* File length in bytes */
5216 fputc ('\n', asm_out_file);
5219 /* Terminate the file name table */
5220 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5221 fputc ('\n', asm_out_file);
5223 /* Set the address register to the first location in the text section */
5224 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5225 if (flag_verbose_asm)
5226 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5228 fputc ('\n', asm_out_file);
5229 output_uleb128 (1 + PTR_SIZE);
5230 fputc ('\n', asm_out_file);
5231 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5232 fputc ('\n', asm_out_file);
5233 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
5234 fputc ('\n', asm_out_file);
5236 /* Generate the line number to PC correspondence table, encoded as
5237 a series of state machine operations. */
5240 strcpy (prev_line_label, TEXT_SECTION);
5241 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5243 register dw_line_info_ref line_info;
5245 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5246 if (flag_verbose_asm)
5247 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5250 fputc ('\n', asm_out_file);
5251 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5252 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5253 fputc ('\n', asm_out_file);
5254 line_info = &line_info_table[lt_index];
5255 if (line_info->dw_file_num != current_file)
5257 current_file = line_info->dw_file_num;
5258 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5259 if (flag_verbose_asm)
5260 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5262 fputc ('\n', asm_out_file);
5263 output_uleb128 (current_file);
5264 if (flag_verbose_asm)
5265 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5267 fputc ('\n', asm_out_file);
5270 line_offset = line_info->dw_line_num - current_line;
5271 line_delta = line_offset - DWARF_LINE_BASE;
5272 current_line = line_info->dw_line_num;
5273 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5275 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5276 DWARF_LINE_OPCODE_BASE + line_delta);
5277 if (flag_verbose_asm)
5278 fprintf (asm_out_file,
5279 "\t%s line %d", ASM_COMMENT_START, current_line);
5281 fputc ('\n', asm_out_file);
5285 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5286 if (flag_verbose_asm)
5287 fprintf (asm_out_file, "\t%s advance to line %d",
5288 ASM_COMMENT_START, current_line);
5290 fputc ('\n', asm_out_file);
5291 output_sleb128 (line_offset);
5292 fputc ('\n', asm_out_file);
5293 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5294 fputc ('\n', asm_out_file);
5297 strcpy (prev_line_label, line_label);
5300 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5301 if (flag_verbose_asm)
5302 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", ASM_COMMENT_START);
5304 fputc ('\n', asm_out_file);
5305 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
5306 fputc ('\n', asm_out_file);
5308 /* Output the marker for the end of the line number info. */
5309 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5310 if (flag_verbose_asm)
5311 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
5313 fputc ('\n', asm_out_file);
5315 fputc ('\n', asm_out_file);
5316 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5317 fputc ('\n', asm_out_file);
5322 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5324 register dw_separate_line_info_ref line_info
5325 = &separate_line_info_table[lt_index];
5327 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
5329 if (function != line_info->function)
5331 function = line_info->function;
5333 /* Set the address register to the first line in the function */
5334 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5335 if (flag_verbose_asm)
5336 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5339 fputc ('\n', asm_out_file);
5340 output_uleb128 (1 + PTR_SIZE);
5341 fputc ('\n', asm_out_file);
5342 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5343 fputc ('\n', asm_out_file);
5344 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5345 fputc ('\n', asm_out_file);
5349 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5350 if (flag_verbose_asm)
5351 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5354 fputc ('\n', asm_out_file);
5355 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5356 fputc ('\n', asm_out_file);
5359 if (line_info->dw_file_num != current_file)
5361 current_file = line_info->dw_file_num;
5362 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5363 if (flag_verbose_asm)
5364 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5366 fputc ('\n', asm_out_file);
5367 output_uleb128 (current_file);
5368 if (flag_verbose_asm)
5369 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5371 fputc ('\n', asm_out_file);
5374 if (line_info->dw_line_num != current_line)
5376 line_offset = line_info->dw_line_num - current_line;
5377 line_delta = line_offset - DWARF_LINE_BASE;
5378 current_line = line_info->dw_line_num;
5379 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5381 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5382 DWARF_LINE_OPCODE_BASE + line_delta);
5383 if (flag_verbose_asm)
5384 fprintf (asm_out_file,
5385 "\t%s line %d", ASM_COMMENT_START, current_line);
5387 fputc ('\n', asm_out_file);
5391 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5392 if (flag_verbose_asm)
5393 fprintf (asm_out_file, "\t%s advance to line %d",
5394 ASM_COMMENT_START, current_line);
5396 fputc ('\n', asm_out_file);
5397 output_sleb128 (line_offset);
5398 fputc ('\n', asm_out_file);
5399 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5400 fputc ('\n', asm_out_file);
5405 strcpy (prev_line_label, line_label);
5407 /* If we're done with a function, end its sequence. */
5408 if (lt_index == separate_line_info_table_in_use
5409 || separate_line_info_table[lt_index].function != function)
5413 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5414 if (flag_verbose_asm)
5415 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5418 fputc ('\n', asm_out_file);
5419 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
5420 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5421 fputc ('\n', asm_out_file);
5423 /* Output the marker for the end of this sequence. */
5424 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5425 if (flag_verbose_asm)
5426 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
5429 fputc ('\n', asm_out_file);
5431 fputc ('\n', asm_out_file);
5432 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5433 fputc ('\n', asm_out_file);
5438 /* Given a pointer to a BLOCK node return non-zero if (and only if) the node
5439 in question represents the outermost pair of curly braces (i.e. the "body
5440 block") of a function or method.
5442 For any BLOCK node representing a "body block" of a function or method, the
5443 BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
5444 represents the outermost (function) scope for the function or method (i.e.
5445 the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
5446 *that* node in turn will point to the relevant FUNCTION_DECL node. */
5449 is_body_block (stmt)
5452 if (TREE_CODE (stmt) == BLOCK)
5454 register tree parent = BLOCK_SUPERCONTEXT (stmt);
5456 if (TREE_CODE (parent) == BLOCK)
5458 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
5460 if (TREE_CODE (grandparent) == FUNCTION_DECL)
5468 /* Given a pointer to a tree node for some base type, return a pointer to
5469 a DIE that describes the given type.
5471 This routine must only be called for GCC type nodes that correspond to
5472 Dwarf base (fundamental) types. */
5475 base_type_die (type)
5478 register dw_die_ref base_type_result;
5479 register char *type_name;
5480 register enum dwarf_type encoding;
5481 register tree name = TYPE_NAME (type);
5483 if (TREE_CODE (type) == ERROR_MARK
5484 || TREE_CODE (type) == VOID_TYPE)
5487 if (TREE_CODE (name) == TYPE_DECL)
5488 name = DECL_NAME (name);
5489 type_name = IDENTIFIER_POINTER (name);
5491 switch (TREE_CODE (type))
5494 /* Carefully distinguish the C character types, without messing
5495 up if the language is not C. Note that we check only for the names
5496 that contain spaces; other names might occur by coincidence in other
5498 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
5499 && (type == char_type_node
5500 || ! strcmp (type_name, "signed char")
5501 || ! strcmp (type_name, "unsigned char"))))
5503 if (TREE_UNSIGNED (type))
5504 encoding = DW_ATE_unsigned;
5506 encoding = DW_ATE_signed;
5509 /* else fall through */
5512 /* GNU Pascal/Ada CHAR type. Not used in C. */
5513 if (TREE_UNSIGNED (type))
5514 encoding = DW_ATE_unsigned_char;
5516 encoding = DW_ATE_signed_char;
5520 encoding = DW_ATE_float;
5524 encoding = DW_ATE_complex_float;
5528 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
5529 encoding = DW_ATE_boolean;
5533 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
5536 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
5537 add_AT_string (base_type_result, DW_AT_name, type_name);
5538 add_AT_unsigned (base_type_result, DW_AT_byte_size,
5539 TYPE_PRECISION (type) / BITS_PER_UNIT);
5540 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
5542 return base_type_result;
5545 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
5546 the Dwarf "root" type for the given input type. The Dwarf "root" type of
5547 a given type is generally the same as the given type, except that if the
5548 given type is a pointer or reference type, then the root type of the given
5549 type is the root type of the "basis" type for the pointer or reference
5550 type. (This definition of the "root" type is recursive.) Also, the root
5551 type of a `const' qualified type or a `volatile' qualified type is the
5552 root type of the given type without the qualifiers. */
5558 if (TREE_CODE (type) == ERROR_MARK)
5559 return error_mark_node;
5561 switch (TREE_CODE (type))
5564 return error_mark_node;
5567 case REFERENCE_TYPE:
5568 return type_main_variant (root_type (TREE_TYPE (type)));
5571 return type_main_variant (type);
5575 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
5576 given input type is a Dwarf "fundamental" type. Otherwise return null. */
5582 switch (TREE_CODE (type))
5597 case QUAL_UNION_TYPE:
5602 case REFERENCE_TYPE:
5615 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
5616 entry that chains various modifiers in front of the given type. */
5619 modified_type_die (type, is_const_type, is_volatile_type, context_die)
5621 register int is_const_type;
5622 register int is_volatile_type;
5623 register dw_die_ref context_die;
5625 register enum tree_code code = TREE_CODE (type);
5626 register dw_die_ref mod_type_die = NULL;
5627 register dw_die_ref sub_die = NULL;
5628 register tree item_type = NULL;
5630 if (code != ERROR_MARK)
5632 type = build_type_variant (type, is_const_type, is_volatile_type);
5634 mod_type_die = lookup_type_die (type);
5636 return mod_type_die;
5638 /* Handle C typedef types. */
5639 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
5640 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
5642 tree dtype = TREE_TYPE (TYPE_NAME (type));
5645 /* For a named type, use the typedef. */
5646 gen_type_die (type, context_die);
5647 mod_type_die = lookup_type_die (type);
5650 else if (is_const_type < TYPE_READONLY (dtype)
5651 || is_volatile_type < TYPE_VOLATILE (dtype))
5652 /* cv-unqualified version of named type. Just use the unnamed
5653 type to which it refers. */
5655 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
5656 is_const_type, is_volatile_type,
5658 /* Else cv-qualified version of named type; fall through. */
5663 else if (is_const_type)
5665 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
5666 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
5668 else if (is_volatile_type)
5670 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
5671 sub_die = modified_type_die (type, 0, 0, context_die);
5673 else if (code == POINTER_TYPE)
5675 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
5676 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
5678 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
5680 item_type = TREE_TYPE (type);
5682 else if (code == REFERENCE_TYPE)
5684 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
5685 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
5687 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
5689 item_type = TREE_TYPE (type);
5691 else if (is_base_type (type))
5692 mod_type_die = base_type_die (type);
5695 gen_type_die (type, context_die);
5697 /* We have to get the type_main_variant here (and pass that to the
5698 `lookup_type_die' routine) because the ..._TYPE node we have
5699 might simply be a *copy* of some original type node (where the
5700 copy was created to help us keep track of typedef names) and
5701 that copy might have a different TYPE_UID from the original
5703 mod_type_die = lookup_type_die (type_main_variant (type));
5704 assert (mod_type_die != NULL);
5708 equate_type_number_to_die (type, mod_type_die);
5710 /* We must do this after the equate_type_number_to_die call, in case
5711 this is a recursive type. This ensures that the modified_type_die
5712 recursion will terminate even if the type is recursive. Recursive
5713 types are possible in Ada. */
5714 sub_die = modified_type_die (item_type,
5715 TYPE_READONLY (item_type),
5716 TYPE_VOLATILE (item_type),
5719 if (sub_die != NULL)
5720 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
5722 return mod_type_die;
5725 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
5726 an enumerated type. */
5732 return TREE_CODE (type) == ENUMERAL_TYPE;
5735 /* Return a location descriptor that designates a machine register. */
5737 static dw_loc_descr_ref
5738 reg_loc_descriptor (rtl)
5741 register dw_loc_descr_ref loc_result = NULL;
5742 register unsigned reg = reg_number (rtl);
5744 if (reg >= 0 && reg <= 31)
5745 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
5747 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
5752 /* Return a location descriptor that designates a base+offset location. */
5754 static dw_loc_descr_ref
5755 based_loc_descr (reg, offset)
5759 register dw_loc_descr_ref loc_result;
5760 /* For the "frame base", we use the frame pointer or stack pointer
5761 registers, since the RTL for local variables is relative to one of
5763 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
5764 ? HARD_FRAME_POINTER_REGNUM
5765 : STACK_POINTER_REGNUM);
5768 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
5769 else if (reg >= 0 && reg <= 31)
5770 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
5772 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
5777 /* Return true if this RTL expression describes a base+offset calculation. */
5783 return (GET_CODE (rtl) == PLUS
5784 && ((GET_CODE (XEXP (rtl, 0)) == REG
5785 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
5788 /* The following routine converts the RTL for a variable or parameter
5789 (resident in memory) into an equivalent Dwarf representation of a
5790 mechanism for getting the address of that same variable onto the top of a
5791 hypothetical "address evaluation" stack.
5793 When creating memory location descriptors, we are effectively transforming
5794 the RTL for a memory-resident object into its Dwarf postfix expression
5795 equivalent. This routine recursively descends an RTL tree, turning
5796 it into Dwarf postfix code as it goes. */
5798 static dw_loc_descr_ref
5799 mem_loc_descriptor (rtl)
5802 dw_loc_descr_ref mem_loc_result = NULL;
5803 /* Note that for a dynamically sized array, the location we will generate a
5804 description of here will be the lowest numbered location which is
5805 actually within the array. That's *not* necessarily the same as the
5806 zeroth element of the array. */
5808 switch (GET_CODE (rtl))
5811 /* The case of a subreg may arise when we have a local (register)
5812 variable or a formal (register) parameter which doesn't quite fill
5813 up an entire register. For now, just assume that it is
5814 legitimate to make the Dwarf info refer to the whole register which
5815 contains the given subreg. */
5816 rtl = XEXP (rtl, 0);
5818 /* ... fall through ... */
5821 /* Whenever a register number forms a part of the description of the
5822 method for calculating the (dynamic) address of a memory resident
5823 object, DWARF rules require the register number be referred to as
5824 a "base register". This distinction is not based in any way upon
5825 what category of register the hardware believes the given register
5826 belongs to. This is strictly DWARF terminology we're dealing with
5827 here. Note that in cases where the location of a memory-resident
5828 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
5829 OP_CONST (0)) the actual DWARF location descriptor that we generate
5830 may just be OP_BASEREG (basereg). This may look deceptively like
5831 the object in question was allocated to a register (rather than in
5832 memory) so DWARF consumers need to be aware of the subtle
5833 distinction between OP_REG and OP_BASEREG. */
5834 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
5838 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0));
5839 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
5844 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
5845 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
5846 mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
5850 if (is_based_loc (rtl))
5851 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
5852 INTVAL (XEXP (rtl, 1)));
5855 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
5856 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
5857 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
5862 /* If a pseudo-reg is optimized away, it is possible for it to
5863 be replaced with a MEM containing a multiply. */
5864 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
5865 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
5866 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
5870 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
5877 return mem_loc_result;
5880 /* Output a proper Dwarf location descriptor for a variable or parameter
5881 which is either allocated in a register or in a memory location. For a
5882 register, we just generate an OP_REG and the register number. For a
5883 memory location we provide a Dwarf postfix expression describing how to
5884 generate the (dynamic) address of the object onto the address stack. */
5886 static dw_loc_descr_ref
5887 loc_descriptor (rtl)
5890 dw_loc_descr_ref loc_result = NULL;
5891 switch (GET_CODE (rtl))
5894 /* The case of a subreg may arise when we have a local (register)
5895 variable or a formal (register) parameter which doesn't quite fill
5896 up an entire register. For now, just assume that it is
5897 legitimate to make the Dwarf info refer to the whole register which
5898 contains the given subreg. */
5899 rtl = XEXP (rtl, 0);
5901 /* ... fall through ... */
5904 loc_result = reg_loc_descriptor (rtl);
5908 loc_result = mem_loc_descriptor (XEXP (rtl, 0));
5918 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
5919 which is not less than the value itself. */
5921 static inline unsigned
5922 ceiling (value, boundary)
5923 register unsigned value;
5924 register unsigned boundary;
5926 return (((value + boundary - 1) / boundary) * boundary);
5929 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
5930 pointer to the declared type for the relevant field variable, or return
5931 `integer_type_node' if the given node turns out to be an
5940 if (TREE_CODE (decl) == ERROR_MARK)
5941 return integer_type_node;
5943 type = DECL_BIT_FIELD_TYPE (decl);
5944 if (type == NULL_TREE)
5945 type = TREE_TYPE (decl);
5950 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5951 node, return the alignment in bits for the type, or else return
5952 BITS_PER_WORD if the node actually turns out to be an
5955 static inline unsigned
5956 simple_type_align_in_bits (type)
5959 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
5962 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5963 node, return the size in bits for the type if it is a constant, or else
5964 return the alignment for the type if the type's size is not constant, or
5965 else return BITS_PER_WORD if the type actually turns out to be an
5968 static inline unsigned
5969 simple_type_size_in_bits (type)
5972 if (TREE_CODE (type) == ERROR_MARK)
5973 return BITS_PER_WORD;
5976 register tree type_size_tree = TYPE_SIZE (type);
5978 if (TREE_CODE (type_size_tree) != INTEGER_CST)
5979 return TYPE_ALIGN (type);
5981 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
5985 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
5986 return the byte offset of the lowest addressed byte of the "containing
5987 object" for the given FIELD_DECL, or return 0 if we are unable to
5988 determine what that offset is, either because the argument turns out to
5989 be a pointer to an ERROR_MARK node, or because the offset is actually
5990 variable. (We can't handle the latter case just yet). */
5993 field_byte_offset (decl)
5996 register unsigned type_align_in_bytes;
5997 register unsigned type_align_in_bits;
5998 register unsigned type_size_in_bits;
5999 register unsigned object_offset_in_align_units;
6000 register unsigned object_offset_in_bits;
6001 register unsigned object_offset_in_bytes;
6003 register tree bitpos_tree;
6004 register tree field_size_tree;
6005 register unsigned bitpos_int;
6006 register unsigned deepest_bitpos;
6007 register unsigned field_size_in_bits;
6009 if (TREE_CODE (decl) == ERROR_MARK)
6012 if (TREE_CODE (decl) != FIELD_DECL)
6015 type = field_type (decl);
6017 bitpos_tree = DECL_FIELD_BITPOS (decl);
6018 field_size_tree = DECL_SIZE (decl);
6020 /* We cannot yet cope with fields whose positions or sizes are variable, so
6021 for now, when we see such things, we simply return 0. Someday, we may
6022 be able to handle such cases, but it will be damn difficult. */
6023 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6025 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6027 if (TREE_CODE (field_size_tree) != INTEGER_CST)
6030 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
6031 type_size_in_bits = simple_type_size_in_bits (type);
6032 type_align_in_bits = simple_type_align_in_bits (type);
6033 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6035 /* Note that the GCC front-end doesn't make any attempt to keep track of
6036 the starting bit offset (relative to the start of the containing
6037 structure type) of the hypothetical "containing object" for a bit-
6038 field. Thus, when computing the byte offset value for the start of the
6039 "containing object" of a bit-field, we must deduce this information on
6040 our own. This can be rather tricky to do in some cases. For example,
6041 handling the following structure type definition when compiling for an
6042 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6045 struct S { int field1; long long field2:31; };
6047 Fortunately, there is a simple rule-of-thumb which can be
6048 used in such cases. When compiling for an i386/i486, GCC will allocate
6049 8 bytes for the structure shown above. It decides to do this based upon
6050 one simple rule for bit-field allocation. Quite simply, GCC allocates
6051 each "containing object" for each bit-field at the first (i.e. lowest
6052 addressed) legitimate alignment boundary (based upon the required
6053 minimum alignment for the declared type of the field) which it can
6054 possibly use, subject to the condition that there is still enough
6055 available space remaining in the containing object (when allocated at
6056 the selected point) to fully accommodate all of the bits of the
6057 bit-field itself. This simple rule makes it obvious why GCC allocates
6058 8 bytes for each object of the structure type shown above. When looking
6059 for a place to allocate the "containing object" for `field2', the
6060 compiler simply tries to allocate a 64-bit "containing object" at each
6061 successive 32-bit boundary (starting at zero) until it finds a place to
6062 allocate that 64- bit field such that at least 31 contiguous (and
6063 previously unallocated) bits remain within that selected 64 bit field.
6064 (As it turns out, for the example above, the compiler finds that it is
6065 OK to allocate the "containing object" 64-bit field at bit-offset zero
6066 within the structure type.) Here we attempt to work backwards from the
6067 limited set of facts we're given, and we try to deduce from those facts,
6068 where GCC must have believed that the containing object started (within
6069 the structure type). The value we deduce is then used (by the callers of
6070 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6071 for fields (both bit-fields and, in the case of DW_AT_location, regular
6074 /* Figure out the bit-distance from the start of the structure to the
6075 "deepest" bit of the bit-field. */
6076 deepest_bitpos = bitpos_int + field_size_in_bits;
6078 /* This is the tricky part. Use some fancy footwork to deduce where the
6079 lowest addressed bit of the containing object must be. */
6080 object_offset_in_bits
6081 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6083 /* Compute the offset of the containing object in "alignment units". */
6084 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6086 /* Compute the offset of the containing object in bytes. */
6087 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6089 return object_offset_in_bytes;
6092 /* The following routines define various Dwarf attributes and any data
6093 associated with them. */
6096 /* Output the form of location attributes suitable for whole variables and
6097 whole parameters. Note that the location attributes for struct fields are
6098 generated by the routine `data_member_location_attribute' below. */
6101 add_location_attribute (die, rtl)
6105 dw_loc_descr_ref loc_descr = NULL;
6107 /* Handle a special case. If we are about to output a location descriptor
6108 for a variable or parameter which has been optimized out of existence,
6109 don't do that. Instead we output a null location descriptor value as
6110 part of the location attribute. A variable which has been optimized out
6111 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6112 Currently, in some rare cases, variables can have DECL_RTL values which
6113 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6114 elsewhere in the compiler. We treat such cases as if the variable(s) in
6115 question had been optimized out of existence. Note that in all cases
6116 where we wish to express the fact that a variable has been optimized out
6117 of existence, we do not simply suppress the generation of the entire
6118 location attribute because the absence of a location attribute in
6119 certain kinds of DIEs is used to indicate something else entirely...
6120 i.e. that the DIE represents an object declaration, but not a
6121 definition. So sayeth the PLSIG. */
6123 if (!is_pseudo_reg (rtl)
6124 && (GET_CODE (rtl) != MEM
6125 || !is_pseudo_reg (XEXP (rtl, 0))))
6126 loc_descr = loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX, 0));
6128 #ifdef MIPS_DEBUGGING_INFO
6129 /* ??? SGI's dwarf reader is buggy, and will not accept a zero size
6130 location descriptor. Lets just use r0 for now to represent a
6131 variable that has been optimized away. */
6132 if (loc_descr == NULL)
6133 loc_descr = loc_descriptor (gen_rtx (REG, word_mode, 0));
6136 add_AT_loc (die, DW_AT_location, loc_descr);
6139 /* Attach the specialized form of location attribute used for data
6140 members of struct and union types. In the special case of a
6141 FIELD_DECL node which represents a bit-field, the "offset" part
6142 of this special location descriptor must indicate the distance
6143 in bytes from the lowest-addressed byte of the containing struct
6144 or union type to the lowest-addressed byte of the "containing
6145 object" for the bit-field. (See the `field_byte_offset' function
6146 above).. For any given bit-field, the "containing object" is a
6147 hypothetical object (of some integral or enum type) within which
6148 the given bit-field lives. The type of this hypothetical
6149 "containing object" is always the same as the declared type of
6150 the individual bit-field itself (for GCC anyway... the DWARF
6151 spec doesn't actually mandate this). Note that it is the size
6152 (in bytes) of the hypothetical "containing object" which will
6153 be given in the DW_AT_byte_size attribute for this bit-field.
6154 (See the `byte_size_attribute' function below.) It is also used
6155 when calculating the value of the DW_AT_bit_offset attribute.
6156 (See the `bit_offset_attribute' function below). */
6159 add_data_member_location_attribute (die, decl)
6160 register dw_die_ref die;
6163 register unsigned long offset;
6164 register dw_loc_descr_ref loc_descr;
6165 register enum dwarf_location_atom op;
6167 if (TREE_CODE (decl) == TREE_VEC)
6168 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
6170 offset = field_byte_offset (decl);
6172 /* The DWARF2 standard says that we should assume that the structure address
6173 is already on the stack, so we can specify a structure field address
6174 by using DW_OP_plus_uconst. */
6176 #ifdef MIPS_DEBUGGING_INFO
6177 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6178 correctly. It works only if we leave the offset on the stack. */
6181 op = DW_OP_plus_uconst;
6184 loc_descr = new_loc_descr (op, offset, 0);
6185 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6188 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6189 does not have a "location" either in memory or in a register. These
6190 things can arise in GNU C when a constant is passed as an actual parameter
6191 to an inlined function. They can also arise in C++ where declared
6192 constants do not necessarily get memory "homes". */
6195 add_const_value_attribute (die, rtl)
6196 register dw_die_ref die;
6199 switch (GET_CODE (rtl))
6202 /* Note that a CONST_INT rtx could represent either an integer or a
6203 floating-point constant. A CONST_INT is used whenever the constant
6204 will fit into a single word. In all such cases, the original mode
6205 of the constant value is wiped out, and the CONST_INT rtx is
6206 assigned VOIDmode. */
6207 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6211 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6212 floating-point constant. A CONST_DOUBLE is used whenever the
6213 constant requires more than one word in order to be adequately
6214 represented. We output CONST_DOUBLEs as blocks. */
6216 register enum machine_mode mode = GET_MODE (rtl);
6218 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6220 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6224 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6228 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6232 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6237 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6244 add_AT_float (die, DW_AT_const_value, length, array);
6247 add_AT_long_long (die, DW_AT_const_value,
6248 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6253 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6259 add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
6263 /* In cases where an inlined instance of an inline function is passed
6264 the address of an `auto' variable (which is local to the caller) we
6265 can get a situation where the DECL_RTL of the artificial local
6266 variable (for the inlining) which acts as a stand-in for the
6267 corresponding formal parameter (of the inline function) will look
6268 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6269 exactly a compile-time constant expression, but it isn't the address
6270 of the (artificial) local variable either. Rather, it represents the
6271 *value* which the artificial local variable always has during its
6272 lifetime. We currently have no way to represent such quasi-constant
6273 values in Dwarf, so for now we just punt and generate an
6274 DW_AT_const_value attribute with null address. */
6275 add_AT_addr (die, DW_AT_const_value, addr_to_string (const0_rtx));
6279 /* No other kinds of rtx should be possible here. */
6285 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6286 data attribute for a variable or a parameter. We generate the
6287 DW_AT_const_value attribute only in those cases where the given variable
6288 or parameter does not have a true "location" either in memory or in a
6289 register. This can happen (for example) when a constant is passed as an
6290 actual argument in a call to an inline function. (It's possible that
6291 these things can crop up in other ways also.) Note that one type of
6292 constant value which can be passed into an inlined function is a constant
6293 pointer. This can happen for example if an actual argument in an inlined
6294 function call evaluates to a compile-time constant address. */
6297 add_location_or_const_value_attribute (die, decl)
6298 register dw_die_ref die;
6302 register tree declared_type;
6303 register tree passed_type;
6305 if (TREE_CODE (decl) == ERROR_MARK)
6308 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6311 /* Here we have to decide where we are going to say the parameter "lives"
6312 (as far as the debugger is concerned). We only have a couple of
6313 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6315 DECL_RTL normally indicates where the parameter lives during most of the
6316 activation of the function. If optimization is enabled however, this
6317 could be either NULL or else a pseudo-reg. Both of those cases indicate
6318 that the parameter doesn't really live anywhere (as far as the code
6319 generation parts of GCC are concerned) during most of the function's
6320 activation. That will happen (for example) if the parameter is never
6321 referenced within the function.
6323 We could just generate a location descriptor here for all non-NULL
6324 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6325 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6326 where DECL_RTL is NULL or is a pseudo-reg.
6328 Note however that we can only get away with using DECL_INCOMING_RTL as
6329 a backup substitute for DECL_RTL in certain limited cases. In cases
6330 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6331 we can be sure that the parameter was passed using the same type as it is
6332 declared to have within the function, and that its DECL_INCOMING_RTL
6333 points us to a place where a value of that type is passed.
6335 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6336 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6337 because in these cases DECL_INCOMING_RTL points us to a value of some
6338 type which is *different* from the type of the parameter itself. Thus,
6339 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6340 such cases, the debugger would end up (for example) trying to fetch a
6341 `float' from a place which actually contains the first part of a
6342 `double'. That would lead to really incorrect and confusing
6343 output at debug-time.
6345 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6346 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6347 are a couple of exceptions however. On little-endian machines we can
6348 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6349 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6350 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6351 when (on a little-endian machine) a non-prototyped function has a
6352 parameter declared to be of type `short' or `char'. In such cases,
6353 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6354 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6355 passed `int' value. If the debugger then uses that address to fetch
6356 a `short' or a `char' (on a little-endian machine) the result will be
6357 the correct data, so we allow for such exceptional cases below.
6359 Note that our goal here is to describe the place where the given formal
6360 parameter lives during most of the function's activation (i.e. between
6361 the end of the prologue and the start of the epilogue). We'll do that
6362 as best as we can. Note however that if the given formal parameter is
6363 modified sometime during the execution of the function, then a stack
6364 backtrace (at debug-time) will show the function as having been
6365 called with the *new* value rather than the value which was
6366 originally passed in. This happens rarely enough that it is not
6367 a major problem, but it *is* a problem, and I'd like to fix it.
6369 A future version of dwarf2out.c may generate two additional
6370 attributes for any given DW_TAG_formal_parameter DIE which will
6371 describe the "passed type" and the "passed location" for the
6372 given formal parameter in addition to the attributes we now
6373 generate to indicate the "declared type" and the "active
6374 location" for each parameter. This additional set of attributes
6375 could be used by debuggers for stack backtraces. Separately, note
6376 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6377 NULL also. This happens (for example) for inlined-instances of
6378 inline function formal parameters which are never referenced.
6379 This really shouldn't be happening. All PARM_DECL nodes should
6380 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6381 doesn't currently generate these values for inlined instances of
6382 inline function parameters, so when we see such cases, we are
6383 just SOL (shit-out-of-luck) for the time being (until integrate.c
6386 /* Use DECL_RTL as the "location" unless we find something better. */
6387 rtl = DECL_RTL (decl);
6389 if (TREE_CODE (decl) == PARM_DECL)
6391 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
6393 declared_type = type_main_variant (TREE_TYPE (decl));
6394 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
6396 /* This decl represents a formal parameter which was optimized out.
6397 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
6398 all* cases where (rtl == NULL_RTX) just below. */
6399 if (declared_type == passed_type)
6400 rtl = DECL_INCOMING_RTL (decl);
6401 else if (! BYTES_BIG_ENDIAN
6402 && TREE_CODE (declared_type) == INTEGER_TYPE
6403 && TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
6404 rtl = DECL_INCOMING_RTL (decl);
6408 if (rtl == NULL_RTX)
6411 switch (GET_CODE (rtl))
6420 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
6421 add_const_value_attribute (die, rtl);
6427 add_location_attribute (die, rtl);
6435 /* Generate an DW_AT_name attribute given some string value to be included as
6436 the value of the attribute. */
6439 add_name_attribute (die, name_string)
6440 register dw_die_ref die;
6441 register char *name_string;
6443 if (name_string != NULL && *name_string != 0)
6444 add_AT_string (die, DW_AT_name, name_string);
6447 /* Given a tree node describing an array bound (either lower or upper) output
6448 a representation for that bound. */
6451 add_bound_info (subrange_die, bound_attr, bound)
6452 register dw_die_ref subrange_die;
6453 register enum dwarf_attribute bound_attr;
6454 register tree bound;
6456 register unsigned bound_value = 0;
6457 switch (TREE_CODE (bound))
6462 /* All fixed-bounds are represented by INTEGER_CST nodes. */
6464 bound_value = TREE_INT_CST_LOW (bound);
6465 if (bound_attr == DW_AT_lower_bound
6466 && ((is_c_family () && bound_value == 0)
6467 || (is_fortran () && bound_value == 1)))
6468 /* use the default */;
6470 add_AT_unsigned (subrange_die, bound_attr, bound_value);
6475 case NON_LVALUE_EXPR:
6476 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
6480 /* If optimization is turned on, the SAVE_EXPRs that describe how to
6481 access the upper bound values may be bogus. If they refer to a
6482 register, they may only describe how to get at these values at the
6483 points in the generated code right after they have just been
6484 computed. Worse yet, in the typical case, the upper bound values
6485 will not even *be* computed in the optimized code (though the
6486 number of elements will), so these SAVE_EXPRs are entirely
6487 bogus. In order to compensate for this fact, we check here to see
6488 if optimization is enabled, and if so, we don't add an attribute
6489 for the (unknown and unknowable) upper bound. This should not
6490 cause too much trouble for existing (stupid?) debuggers because
6491 they have to deal with empty upper bounds location descriptions
6492 anyway in order to be able to deal with incomplete array types.
6493 Of course an intelligent debugger (GDB?) should be able to
6494 comprehend that a missing upper bound specification in a array
6495 type used for a storage class `auto' local array variable
6496 indicates that the upper bound is both unknown (at compile- time)
6497 and unknowable (at run-time) due to optimization.
6499 We assume that a MEM rtx is safe because gcc wouldn't put the
6500 value there unless it was going to be used repeatedly in the
6501 function, i.e. for cleanups. */
6502 if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)
6504 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
6505 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
6506 add_AT_flag (decl_die, DW_AT_artificial, 1);
6507 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
6508 add_location_attribute (decl_die, SAVE_EXPR_RTL (bound));
6509 add_AT_die_ref (subrange_die, bound_attr, decl_die);
6512 /* Else leave out the attribute. */
6520 /* Note that the block of subscript information for an array type also
6521 includes information about the element type of type given array type. */
6524 add_subscript_info (type_die, type)
6525 register dw_die_ref type_die;
6528 register unsigned dimension_number;
6529 register tree lower, upper;
6530 register dw_die_ref subrange_die;
6532 /* The GNU compilers represent multidimensional array types as sequences of
6533 one dimensional array types whose element types are themselves array
6534 types. Here we squish that down, so that each multidimensional array
6535 type gets only one array_type DIE in the Dwarf debugging info. The draft
6536 Dwarf specification say that we are allowed to do this kind of
6537 compression in C (because there is no difference between an array or
6538 arrays and a multidimensional array in C) but for other source languages
6539 (e.g. Ada) we probably shouldn't do this. */
6541 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
6542 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
6543 We work around this by disabling this feature. See also
6544 gen_array_type_die. */
6545 #ifndef MIPS_DEBUGGING_INFO
6546 for (dimension_number = 0;
6547 TREE_CODE (type) == ARRAY_TYPE;
6548 type = TREE_TYPE (type), dimension_number++)
6551 register tree domain = TYPE_DOMAIN (type);
6553 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
6554 and (in GNU C only) variable bounds. Handle all three forms
6556 subrange_die = new_die (DW_TAG_subrange_type, type_die);
6559 /* We have an array type with specified bounds. */
6560 lower = TYPE_MIN_VALUE (domain);
6561 upper = TYPE_MAX_VALUE (domain);
6563 /* define the index type. */
6564 if (TREE_TYPE (domain))
6565 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
6568 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
6569 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
6572 /* We have an array type with an unspecified length. The DWARF-2
6573 spec does not say how to handle this; let's just leave out the
6577 #ifndef MIPS_DEBUGGING_INFO
6583 add_byte_size_attribute (die, tree_node)
6585 register tree tree_node;
6587 register unsigned size;
6589 switch (TREE_CODE (tree_node))
6597 case QUAL_UNION_TYPE:
6598 size = int_size_in_bytes (tree_node);
6601 /* For a data member of a struct or union, the DW_AT_byte_size is
6602 generally given as the number of bytes normally allocated for an
6603 object of the *declared* type of the member itself. This is true
6604 even for bit-fields. */
6605 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
6611 /* Note that `size' might be -1 when we get to this point. If it is, that
6612 indicates that the byte size of the entity in question is variable. We
6613 have no good way of expressing this fact in Dwarf at the present time,
6614 so just let the -1 pass on through. */
6616 add_AT_unsigned (die, DW_AT_byte_size, size);
6619 /* For a FIELD_DECL node which represents a bit-field, output an attribute
6620 which specifies the distance in bits from the highest order bit of the
6621 "containing object" for the bit-field to the highest order bit of the
6624 For any given bit-field, the "containing object" is a hypothetical
6625 object (of some integral or enum type) within which the given bit-field
6626 lives. The type of this hypothetical "containing object" is always the
6627 same as the declared type of the individual bit-field itself. The
6628 determination of the exact location of the "containing object" for a
6629 bit-field is rather complicated. It's handled by the
6630 `field_byte_offset' function (above).
6632 Note that it is the size (in bytes) of the hypothetical "containing object"
6633 which will be given in the DW_AT_byte_size attribute for this bit-field.
6634 (See `byte_size_attribute' above). */
6637 add_bit_offset_attribute (die, decl)
6638 register dw_die_ref die;
6641 register unsigned object_offset_in_bytes = field_byte_offset (decl);
6642 register tree type = DECL_BIT_FIELD_TYPE (decl);
6643 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
6644 register unsigned bitpos_int;
6645 register unsigned highest_order_object_bit_offset;
6646 register unsigned highest_order_field_bit_offset;
6647 register unsigned bit_offset;
6649 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
6650 assert (type); /* Must be a bit field. */
6652 /* We can't yet handle bit-fields whose offsets are variable, so if we
6653 encounter such things, just return without generating any attribute
6655 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6658 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6660 /* Note that the bit offset is always the distance (in bits) from the
6661 highest-order bit of the "containing object" to the highest-order bit of
6662 the bit-field itself. Since the "high-order end" of any object or field
6663 is different on big-endian and little-endian machines, the computation
6664 below must take account of these differences. */
6665 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
6666 highest_order_field_bit_offset = bitpos_int;
6668 if (! BYTES_BIG_ENDIAN)
6670 highest_order_field_bit_offset
6671 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
6673 highest_order_object_bit_offset += simple_type_size_in_bits (type);
6677 = (! BYTES_BIG_ENDIAN
6678 ? highest_order_object_bit_offset - highest_order_field_bit_offset
6679 : highest_order_field_bit_offset - highest_order_object_bit_offset);
6681 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
6684 /* For a FIELD_DECL node which represents a bit field, output an attribute
6685 which specifies the length in bits of the given field. */
6688 add_bit_size_attribute (die, decl)
6689 register dw_die_ref die;
6692 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
6693 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
6694 add_AT_unsigned (die, DW_AT_bit_size,
6695 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
6698 /* If the compiled language is ANSI C, then add a 'prototyped'
6699 attribute, if arg types are given for the parameters of a function. */
6702 add_prototyped_attribute (die, func_type)
6703 register dw_die_ref die;
6704 register tree func_type;
6706 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
6707 && TYPE_ARG_TYPES (func_type) != NULL)
6708 add_AT_flag (die, DW_AT_prototyped, 1);
6712 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
6713 by looking in either the type declaration or object declaration
6717 add_abstract_origin_attribute (die, origin)
6718 register dw_die_ref die;
6719 register tree origin;
6721 dw_die_ref origin_die = NULL;
6722 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
6723 origin_die = lookup_decl_die (origin);
6724 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
6725 origin_die = lookup_type_die (origin);
6727 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
6730 /* We do not currently support the pure_virtual attribute. */
6733 add_pure_or_virtual_attribute (die, func_decl)
6734 register dw_die_ref die;
6735 register tree func_decl;
6737 if (DECL_VINDEX (func_decl))
6739 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
6740 add_AT_loc (die, DW_AT_vtable_elem_location,
6741 new_loc_descr (DW_OP_constu,
6742 TREE_INT_CST_LOW (DECL_VINDEX (func_decl)),
6745 /* GNU extension: Record what type this method came from originally. */
6746 if (debug_info_level > DINFO_LEVEL_TERSE)
6747 add_AT_die_ref (die, DW_AT_containing_type,
6748 lookup_type_die (DECL_CONTEXT (func_decl)));
6752 /* Add source coordinate attributes for the given decl. */
6755 add_src_coords_attributes (die, decl)
6756 register dw_die_ref die;
6759 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
6761 add_AT_unsigned (die, DW_AT_decl_file, file_index);
6762 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
6765 /* Add an DW_AT_name attribute and source coordinate attribute for the
6766 given decl, but only if it actually has a name. */
6769 add_name_and_src_coords_attributes (die, decl)
6770 register dw_die_ref die;
6773 register tree decl_name;
6775 decl_name = DECL_NAME (decl);
6776 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
6778 add_name_attribute (die, dwarf2_name (decl, 0));
6779 add_src_coords_attributes (die, decl);
6780 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
6781 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
6782 add_AT_string (die, DW_AT_MIPS_linkage_name,
6783 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
6787 /* Push a new declaration scope. */
6790 push_decl_scope (scope)
6793 /* Make room in the decl_scope_table, if necessary. */
6794 if (decl_scope_table_allocated == decl_scope_depth)
6796 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
6798 = (tree *) xrealloc (decl_scope_table,
6799 decl_scope_table_allocated * sizeof (tree));
6802 decl_scope_table[decl_scope_depth++] = scope;
6805 /* Return the DIE for the scope the immediately contains this declaration. */
6808 scope_die_for (t, context_die)
6810 register dw_die_ref context_die;
6812 register dw_die_ref scope_die = NULL;
6813 register tree containing_scope;
6814 register unsigned long i;
6816 /* Function-local tags and functions get stuck in limbo until they are
6817 fixed up by decls_for_scope. */
6818 if (context_die == NULL
6819 && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t)))
6822 /* Walk back up the declaration tree looking for a place to define
6824 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
6825 containing_scope = TYPE_CONTEXT (t);
6826 else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t))
6827 containing_scope = decl_class_context (t);
6829 containing_scope = DECL_CONTEXT (t);
6831 if (containing_scope == NULL_TREE)
6832 scope_die = comp_unit_die;
6835 for (i = decl_scope_depth, scope_die = context_die;
6836 i > 0 && decl_scope_table[i - 1] != containing_scope;
6837 scope_die = scope_die->die_parent, --i)
6842 assert (scope_die == comp_unit_die);
6843 assert (TREE_CODE_CLASS (TREE_CODE (containing_scope)) == 't');
6844 if (debug_info_level > DINFO_LEVEL_TERSE)
6845 assert (TREE_ASM_WRITTEN (containing_scope));
6852 /* Pop a declaration scope. */
6856 assert (decl_scope_depth > 0);
6860 /* Many forms of DIEs require a "type description" attribute. This
6861 routine locates the proper "type descriptor" die for the type given
6862 by 'type', and adds an DW_AT_type attribute below the given die. */
6865 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
6866 register dw_die_ref object_die;
6868 register int decl_const;
6869 register int decl_volatile;
6870 register dw_die_ref context_die;
6872 register enum tree_code code = TREE_CODE (type);
6873 register dw_die_ref type_die = NULL;
6875 /* If this type is an unnamed subtype of an integral or floating-point
6876 type, use the inner type. */
6877 if ((code == INTEGER_TYPE || code == REAL_TYPE)
6878 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
6879 type = TREE_TYPE (type), code = TREE_CODE (type);
6881 if (code == ERROR_MARK)
6884 /* Handle a special case. For functions whose return type is void, we
6885 generate *no* type attribute. (Note that no object may have type
6886 `void', so this only applies to function return types). */
6887 if (code == VOID_TYPE)
6890 type_die = modified_type_die (type,
6891 decl_const || TYPE_READONLY (type),
6892 decl_volatile || TYPE_VOLATILE (type),
6894 if (type_die != NULL)
6895 add_AT_die_ref (object_die, DW_AT_type, type_die);
6898 /* Given a tree pointer to a struct, class, union, or enum type node, return
6899 a pointer to the (string) tag name for the given type, or zero if the type
6900 was declared without a tag. */
6906 register char *name = 0;
6908 if (TYPE_NAME (type) != 0)
6910 register tree t = 0;
6912 /* Find the IDENTIFIER_NODE for the type name. */
6913 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
6914 t = TYPE_NAME (type);
6916 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
6917 a TYPE_DECL node, regardless of whether or not a `typedef' was
6919 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6920 && ! DECL_IGNORED_P (TYPE_NAME (type)))
6921 t = DECL_NAME (TYPE_NAME (type));
6923 /* Now get the name as a string, or invent one. */
6925 name = IDENTIFIER_POINTER (t);
6928 return (name == 0 || *name == '\0') ? 0 : name;
6931 /* Return the type associated with a data member, make a special check
6932 for bit field types. */
6935 member_declared_type (member)
6936 register tree member;
6938 return (DECL_BIT_FIELD_TYPE (member)
6939 ? DECL_BIT_FIELD_TYPE (member)
6940 : TREE_TYPE (member));
6943 /* Get the decl's label, as described by its RTL. This may be different
6944 from the DECL_NAME name used in the source file. */
6947 decl_start_label (decl)
6952 x = DECL_RTL (decl);
6953 if (GET_CODE (x) != MEM)
6957 if (GET_CODE (x) != SYMBOL_REF)
6960 fnname = XSTR (x, 0);
6964 /* These routines generate the internnal representation of the DIE's for
6965 the compilation unit. Debugging information is collected by walking
6966 the declaration trees passed in from dwarf2out_decl(). */
6969 gen_array_type_die (type, context_die)
6971 register dw_die_ref context_die;
6973 register dw_die_ref scope_die = scope_die_for (type, context_die);
6974 register dw_die_ref array_die;
6975 register tree element_type;
6977 /* ??? The SGI dwarf reader fails for array of array of enum types unless
6978 the inner array type comes before the outer array type. Thus we must
6979 call gen_type_die before we call new_die. See below also. */
6980 #ifdef MIPS_DEBUGGING_INFO
6981 gen_type_die (TREE_TYPE (type), context_die);
6984 array_die = new_die (DW_TAG_array_type, scope_die);
6987 /* We default the array ordering. SDB will probably do
6988 the right things even if DW_AT_ordering is not present. It's not even
6989 an issue until we start to get into multidimensional arrays anyway. If
6990 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
6991 then we'll have to put the DW_AT_ordering attribute back in. (But if
6992 and when we find out that we need to put these in, we will only do so
6993 for multidimensional arrays. */
6994 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
6997 #ifdef MIPS_DEBUGGING_INFO
6998 /* The SGI compilers handle arrays of unknown bound by setting
6999 AT_declaration and not emitting any subrange DIEs. */
7000 if (! TYPE_DOMAIN (type))
7001 add_AT_unsigned (array_die, DW_AT_declaration, 1);
7004 add_subscript_info (array_die, type);
7006 equate_type_number_to_die (type, array_die);
7008 /* Add representation of the type of the elements of this array type. */
7009 element_type = TREE_TYPE (type);
7011 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7012 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7013 We work around this by disabling this feature. See also
7014 add_subscript_info. */
7015 #ifndef MIPS_DEBUGGING_INFO
7016 while (TREE_CODE (element_type) == ARRAY_TYPE)
7017 element_type = TREE_TYPE (element_type);
7019 gen_type_die (element_type, context_die);
7022 add_type_attribute (array_die, element_type, 0, 0, context_die);
7026 gen_set_type_die (type, context_die)
7028 register dw_die_ref context_die;
7030 register dw_die_ref type_die
7031 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7033 equate_type_number_to_die (type, type_die);
7034 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7038 gen_entry_point_die (decl, context_die)
7040 register dw_die_ref context_die;
7042 register tree origin = decl_ultimate_origin (decl);
7043 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
7045 add_abstract_origin_attribute (decl_die, origin);
7048 add_name_and_src_coords_attributes (decl_die, decl);
7049 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
7053 if (DECL_ABSTRACT (decl))
7054 equate_decl_number_to_die (decl, decl_die);
7056 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
7059 /* Remember a type in the pending_types_list. */
7065 if (pending_types == pending_types_allocated)
7067 pending_types_allocated += PENDING_TYPES_INCREMENT;
7069 = (tree *) xrealloc (pending_types_list,
7070 sizeof (tree) * pending_types_allocated);
7073 pending_types_list[pending_types++] = type;
7076 /* Output any pending types (from the pending_types list) which we can output
7077 now (taking into account the scope that we are working on now).
7079 For each type output, remove the given type from the pending_types_list
7080 *before* we try to output it. */
7083 output_pending_types_for_scope (context_die)
7084 register dw_die_ref context_die;
7088 while (pending_types)
7091 type = pending_types_list[pending_types];
7092 gen_type_die (type, context_die);
7093 assert (TREE_ASM_WRITTEN (type));
7097 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7100 gen_inlined_enumeration_type_die (type, context_die)
7102 register dw_die_ref context_die;
7104 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
7105 scope_die_for (type, context_die));
7107 assert (TREE_ASM_WRITTEN (type));
7108 add_abstract_origin_attribute (type_die, type);
7111 /* Generate a DIE to represent an inlined instance of a structure type. */
7114 gen_inlined_structure_type_die (type, context_die)
7116 register dw_die_ref context_die;
7118 register dw_die_ref type_die = new_die (DW_TAG_structure_type,
7119 scope_die_for (type, context_die));
7121 assert (TREE_ASM_WRITTEN (type));
7122 add_abstract_origin_attribute (type_die, type);
7125 /* Generate a DIE to represent an inlined instance of a union type. */
7128 gen_inlined_union_type_die (type, context_die)
7130 register dw_die_ref context_die;
7132 register dw_die_ref type_die = new_die (DW_TAG_union_type,
7133 scope_die_for (type, context_die));
7135 assert (TREE_ASM_WRITTEN (type));
7136 add_abstract_origin_attribute (type_die, type);
7139 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7140 include all of the information about the enumeration values also. Each
7141 enumerated type name/value is listed as a child of the enumerated type
7145 gen_enumeration_type_die (type, context_die)
7147 register dw_die_ref context_die;
7149 register dw_die_ref type_die = lookup_type_die (type);
7151 if (type_die == NULL)
7153 type_die = new_die (DW_TAG_enumeration_type,
7154 scope_die_for (type, context_die));
7155 equate_type_number_to_die (type, type_die);
7156 add_name_attribute (type_die, type_tag (type));
7158 else if (! TYPE_SIZE (type))
7161 remove_AT (type_die, DW_AT_declaration);
7163 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7164 given enum type is incomplete, do not generate the DW_AT_byte_size
7165 attribute or the DW_AT_element_list attribute. */
7166 if (TYPE_SIZE (type))
7170 TREE_ASM_WRITTEN (type) = 1;
7171 add_byte_size_attribute (type_die, type);
7172 if (type_tag (type))
7173 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
7175 for (link = TYPE_FIELDS (type);
7176 link != NULL; link = TREE_CHAIN (link))
7178 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
7180 add_name_attribute (enum_die,
7181 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
7182 add_AT_unsigned (enum_die, DW_AT_const_value,
7183 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
7187 add_AT_flag (type_die, DW_AT_declaration, 1);
7191 /* Generate a DIE to represent either a real live formal parameter decl or to
7192 represent just the type of some formal parameter position in some function
7195 Note that this routine is a bit unusual because its argument may be a
7196 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7197 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7198 node. If it's the former then this function is being called to output a
7199 DIE to represent a formal parameter object (or some inlining thereof). If
7200 it's the latter, then this function is only being called to output a
7201 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7202 argument type of some subprogram type. */
7205 gen_formal_parameter_die (node, context_die)
7207 register dw_die_ref context_die;
7209 register dw_die_ref parm_die
7210 = new_die (DW_TAG_formal_parameter, context_die);
7211 register tree origin;
7213 switch (TREE_CODE_CLASS (TREE_CODE (node)))
7216 origin = decl_ultimate_origin (node);
7218 add_abstract_origin_attribute (parm_die, origin);
7221 add_name_and_src_coords_attributes (parm_die, node);
7222 add_type_attribute (parm_die, TREE_TYPE (node),
7223 TREE_READONLY (node),
7224 TREE_THIS_VOLATILE (node),
7226 if (DECL_ARTIFICIAL (node))
7227 add_AT_flag (parm_die, DW_AT_artificial, 1);
7230 equate_decl_number_to_die (node, parm_die);
7231 if (! DECL_ABSTRACT (node))
7232 add_location_or_const_value_attribute (parm_die, node);
7237 /* We were called with some kind of a ..._TYPE node. */
7238 add_type_attribute (parm_die, node, 0, 0, context_die);
7248 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
7249 at the end of an (ANSI prototyped) formal parameters list. */
7252 gen_unspecified_parameters_die (decl_or_type, context_die)
7253 register tree decl_or_type;
7254 register dw_die_ref context_die;
7256 register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters,
7260 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
7261 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
7262 parameters as specified in some function type specification (except for
7263 those which appear as part of a function *definition*).
7265 Note we must be careful here to output all of the parameter DIEs before*
7266 we output any DIEs needed to represent the types of the formal parameters.
7267 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
7268 non-parameter DIE it sees ends the formal parameter list. */
7271 gen_formal_types_die (function_or_method_type, context_die)
7272 register tree function_or_method_type;
7273 register dw_die_ref context_die;
7276 register tree formal_type = NULL;
7277 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
7280 /* In the case where we are generating a formal types list for a C++
7281 non-static member function type, skip over the first thing on the
7282 TYPE_ARG_TYPES list because it only represents the type of the hidden
7283 `this pointer'. The debugger should be able to figure out (without
7284 being explicitly told) that this non-static member function type takes a
7285 `this pointer' and should be able to figure what the type of that hidden
7286 parameter is from the DW_AT_member attribute of the parent
7287 DW_TAG_subroutine_type DIE. */
7288 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
7289 first_parm_type = TREE_CHAIN (first_parm_type);
7292 /* Make our first pass over the list of formal parameter types and output a
7293 DW_TAG_formal_parameter DIE for each one. */
7294 for (link = first_parm_type; link; link = TREE_CHAIN (link))
7296 register dw_die_ref parm_die;
7298 formal_type = TREE_VALUE (link);
7299 if (formal_type == void_type_node)
7302 /* Output a (nameless) DIE to represent the formal parameter itself. */
7303 parm_die = gen_formal_parameter_die (formal_type, context_die);
7304 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
7305 && link == first_parm_type)
7306 add_AT_flag (parm_die, DW_AT_artificial, 1);
7309 /* If this function type has an ellipsis, add a
7310 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
7311 if (formal_type != void_type_node)
7312 gen_unspecified_parameters_die (function_or_method_type, context_die);
7314 /* Make our second (and final) pass over the list of formal parameter types
7315 and output DIEs to represent those types (as necessary). */
7316 for (link = TYPE_ARG_TYPES (function_or_method_type);
7318 link = TREE_CHAIN (link))
7320 formal_type = TREE_VALUE (link);
7321 if (formal_type == void_type_node)
7324 gen_type_die (formal_type, context_die);
7328 /* Generate a DIE to represent a declared function (either file-scope or
7332 gen_subprogram_die (decl, context_die)
7334 register dw_die_ref context_die;
7336 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
7337 register tree origin = decl_ultimate_origin (decl);
7338 register dw_die_ref subr_die;
7339 register dw_loc_descr_ref fp_loc = NULL;
7340 register rtx fp_reg;
7341 register tree fn_arg_types;
7342 register tree outer_scope;
7343 register dw_die_ref old_die = lookup_decl_die (decl);
7344 register int declaration
7345 = (current_function_decl != decl
7347 && (context_die->die_tag == DW_TAG_structure_type
7348 || context_die->die_tag == DW_TAG_union_type)));
7352 subr_die = new_die (DW_TAG_subprogram, context_die);
7353 add_abstract_origin_attribute (subr_die, origin);
7357 register unsigned file_index
7358 = lookup_filename (DECL_SOURCE_FILE (decl));
7360 assert (get_AT_flag (old_die, DW_AT_declaration) == 1);
7362 /* If the definition comes from the same place as the declaration,
7363 maybe use the old DIE. We always want the DIE for this function
7364 that has the *_pc attributes to be under comp_unit_die so the
7365 debugger can find it. For inlines, that is the concrete instance,
7366 so we can use the old DIE here. For non-inline methods, we want a
7367 specification DIE at toplevel, so we need a new DIE. For local
7368 class methods, this does not apply. */
7369 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
7370 || context_die == NULL)
7371 && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
7372 && (get_AT_unsigned (old_die, DW_AT_decl_line)
7373 == DECL_SOURCE_LINE (decl)))
7377 /* Clear out the declaration attribute and the parm types. */
7378 remove_AT (subr_die, DW_AT_declaration);
7379 remove_children (subr_die);
7383 subr_die = new_die (DW_TAG_subprogram, context_die);
7384 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
7385 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
7386 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
7387 if (get_AT_unsigned (old_die, DW_AT_decl_line)
7388 != DECL_SOURCE_LINE (decl))
7390 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7395 register dw_die_ref scope_die;
7397 if (DECL_CONTEXT (decl))
7398 scope_die = scope_die_for (decl, context_die);
7400 /* Don't put block extern declarations under comp_unit_die. */
7401 scope_die = context_die;
7403 subr_die = new_die (DW_TAG_subprogram, scope_die);
7405 if (TREE_PUBLIC (decl))
7406 add_AT_flag (subr_die, DW_AT_external, 1);
7408 add_name_and_src_coords_attributes (subr_die, decl);
7409 if (debug_info_level > DINFO_LEVEL_TERSE)
7411 register tree type = TREE_TYPE (decl);
7413 add_prototyped_attribute (subr_die, type);
7414 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
7417 add_pure_or_virtual_attribute (subr_die, decl);
7418 if (DECL_ARTIFICIAL (decl))
7419 add_AT_flag (subr_die, DW_AT_artificial, 1);
7420 if (TREE_PROTECTED (decl))
7421 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
7422 else if (TREE_PRIVATE (decl))
7423 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
7428 add_AT_flag (subr_die, DW_AT_declaration, 1);
7430 /* The first time we see a member function, it is in the context of
7431 the class to which it belongs. We make sure of this by emitting
7432 the class first. The next time is the definition, which is
7433 handled above. The two may come from the same source text. */
7434 if (decl_class_context (decl))
7435 equate_decl_number_to_die (decl, subr_die);
7437 else if (DECL_ABSTRACT (decl))
7439 if (DECL_DEFER_OUTPUT (decl))
7441 if (DECL_INLINE (decl))
7442 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
7444 add_AT_unsigned (subr_die, DW_AT_inline,
7445 DW_INL_declared_not_inlined);
7447 else if (DECL_INLINE (decl))
7448 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
7449 else if (declaration)
7450 /* Block extern declaration in an inline function. */
7451 add_AT_flag (subr_die, DW_AT_declaration, 1);
7455 equate_decl_number_to_die (decl, subr_die);
7457 else if (!DECL_EXTERNAL (decl))
7459 if (origin == NULL_TREE)
7460 equate_decl_number_to_die (decl, subr_die);
7462 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
7463 current_funcdef_number);
7464 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
7465 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
7466 current_funcdef_number);
7467 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
7469 add_pubname (decl, subr_die);
7470 add_arange (decl, subr_die);
7472 #ifdef MIPS_DEBUGGING_INFO
7473 /* Add a reference to the FDE for this routine. */
7474 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
7477 /* Define the "frame base" location for this routine. We use the
7478 frame pointer or stack pointer registers, since the RTL for local
7479 variables is relative to one of them. */
7481 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
7482 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
7484 if (current_function_needs_context)
7485 add_AT_loc (subr_die, DW_AT_static_link,
7486 loc_descriptor (lookup_static_chain (decl)));
7489 /* Now output descriptions of the arguments for this function. This gets
7490 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
7491 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
7492 `...' at the end of the formal parameter list. In order to find out if
7493 there was a trailing ellipsis or not, we must instead look at the type
7494 associated with the FUNCTION_DECL. This will be a node of type
7495 FUNCTION_TYPE. If the chain of type nodes hanging off of this
7496 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
7497 an ellipsis at the end. */
7498 push_decl_scope (decl);
7500 /* In the case where we are describing a mere function declaration, all we
7501 need to do here (and all we *can* do here) is to describe the *types* of
7502 its formal parameters. */
7503 if (debug_info_level <= DINFO_LEVEL_TERSE)
7505 else if (declaration)
7506 gen_formal_types_die (TREE_TYPE (decl), subr_die);
7509 /* Generate DIEs to represent all known formal parameters */
7510 register tree arg_decls = DECL_ARGUMENTS (decl);
7513 /* When generating DIEs, generate the unspecified_parameters DIE
7514 instead if we come across the arg "__builtin_va_alist" */
7515 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
7516 if (TREE_CODE (parm) == PARM_DECL)
7518 if (DECL_NAME (parm)
7519 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
7520 "__builtin_va_alist"))
7521 gen_unspecified_parameters_die (parm, subr_die);
7523 gen_decl_die (parm, subr_die);
7526 /* Decide whether we need a unspecified_parameters DIE at the end.
7527 There are 2 more cases to do this for: 1) the ansi ... declaration -
7528 this is detectable when the end of the arg list is not a
7529 void_type_node 2) an unprototyped function declaration (not a
7530 definition). This just means that we have no info about the
7531 parameters at all. */
7532 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
7533 if (fn_arg_types != NULL)
7535 /* this is the prototyped case, check for ... */
7536 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
7537 gen_unspecified_parameters_die (decl, subr_die);
7539 else if (DECL_INITIAL (decl) == NULL_TREE)
7540 gen_unspecified_parameters_die (decl, subr_die);
7543 /* Output Dwarf info for all of the stuff within the body of the function
7544 (if it has one - it may be just a declaration). */
7545 outer_scope = DECL_INITIAL (decl);
7547 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
7548 node created to represent a function. This outermost BLOCK actually
7549 represents the outermost binding contour for the function, i.e. the
7550 contour in which the function's formal parameters and labels get
7551 declared. Curiously, it appears that the front end doesn't actually
7552 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
7553 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
7554 list for the function instead.) The BLOCK_VARS list for the
7555 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
7556 the function however, and we output DWARF info for those in
7557 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
7558 node representing the function's outermost pair of curly braces, and
7559 any blocks used for the base and member initializers of a C++
7560 constructor function. */
7561 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
7563 current_function_has_inlines = 0;
7564 decls_for_scope (outer_scope, subr_die, 0);
7566 #if 0 && defined (MIPS_DEBUGGING_INFO)
7567 if (current_function_has_inlines)
7569 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
7570 if (! comp_unit_has_inlines)
7572 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
7573 comp_unit_has_inlines = 1;
7582 /* Generate a DIE to represent a declared data object. */
7585 gen_variable_die (decl, context_die)
7587 register dw_die_ref context_die;
7589 register tree origin = decl_ultimate_origin (decl);
7590 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
7592 dw_die_ref old_die = lookup_decl_die (decl);
7594 = (DECL_EXTERNAL (decl)
7595 || current_function_decl != decl_function_context (decl)
7596 || context_die->die_tag == DW_TAG_structure_type
7597 || context_die->die_tag == DW_TAG_union_type);
7600 add_abstract_origin_attribute (var_die, origin);
7601 /* Loop unrolling can create multiple blocks that refer to the same
7602 static variable, so we must test for the DW_AT_declaration flag. */
7603 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
7604 copy decls and set the DECL_ABSTRACT flag on them instead of
7606 else if (old_die && TREE_STATIC (decl)
7607 && get_AT_flag (old_die, DW_AT_declaration) == 1)
7609 /* ??? This is an instantiation of a C++ class level static. */
7610 add_AT_die_ref (var_die, DW_AT_specification, old_die);
7611 if (DECL_NAME (decl))
7613 register unsigned file_index
7614 = lookup_filename (DECL_SOURCE_FILE (decl));
7616 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
7617 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
7619 if (get_AT_unsigned (old_die, DW_AT_decl_line)
7620 != DECL_SOURCE_LINE (decl))
7622 add_AT_unsigned (var_die, DW_AT_decl_line,
7623 DECL_SOURCE_LINE (decl));
7628 add_name_and_src_coords_attributes (var_die, decl);
7629 add_type_attribute (var_die, TREE_TYPE (decl),
7630 TREE_READONLY (decl),
7631 TREE_THIS_VOLATILE (decl), context_die);
7633 if (TREE_PUBLIC (decl))
7634 add_AT_flag (var_die, DW_AT_external, 1);
7636 if (DECL_ARTIFICIAL (decl))
7637 add_AT_flag (var_die, DW_AT_artificial, 1);
7639 if (TREE_PROTECTED (decl))
7640 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
7642 else if (TREE_PRIVATE (decl))
7643 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
7647 add_AT_flag (var_die, DW_AT_declaration, 1);
7649 if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl))
7650 equate_decl_number_to_die (decl, var_die);
7652 if (! declaration && ! DECL_ABSTRACT (decl))
7654 equate_decl_number_to_die (decl, var_die);
7655 add_location_or_const_value_attribute (var_die, decl);
7656 add_pubname (decl, var_die);
7660 /* Generate a DIE to represent a label identifier. */
7663 gen_label_die (decl, context_die)
7665 register dw_die_ref context_die;
7667 register tree origin = decl_ultimate_origin (decl);
7668 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
7670 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7671 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
7674 add_abstract_origin_attribute (lbl_die, origin);
7676 add_name_and_src_coords_attributes (lbl_die, decl);
7678 if (DECL_ABSTRACT (decl))
7679 equate_decl_number_to_die (decl, lbl_die);
7682 insn = DECL_RTL (decl);
7683 if (GET_CODE (insn) == CODE_LABEL)
7685 /* When optimization is enabled (via -O) some parts of the compiler
7686 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
7687 represent source-level labels which were explicitly declared by
7688 the user. This really shouldn't be happening though, so catch
7689 it if it ever does happen. */
7690 if (INSN_DELETED_P (insn))
7693 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
7694 ASM_GENERATE_INTERNAL_LABEL (label, label2,
7695 (unsigned) INSN_UID (insn));
7696 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
7701 /* Generate a DIE for a lexical block. */
7704 gen_lexical_block_die (stmt, context_die, depth)
7706 register dw_die_ref context_die;
7709 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
7710 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7712 if (! BLOCK_ABSTRACT (stmt))
7714 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
7716 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
7717 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
7718 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
7721 push_decl_scope (stmt);
7722 decls_for_scope (stmt, stmt_die, depth);
7726 /* Generate a DIE for an inlined subprogram. */
7729 gen_inlined_subroutine_die (stmt, context_die, depth)
7731 register dw_die_ref context_die;
7734 if (! BLOCK_ABSTRACT (stmt))
7736 register dw_die_ref subr_die
7737 = new_die (DW_TAG_inlined_subroutine, context_die);
7738 register tree decl = block_ultimate_origin (stmt);
7739 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7741 add_abstract_origin_attribute (subr_die, decl);
7742 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
7744 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
7745 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
7746 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
7747 push_decl_scope (decl);
7748 decls_for_scope (stmt, subr_die, depth);
7750 current_function_has_inlines = 1;
7754 /* Generate a DIE for a field in a record, or structure. */
7757 gen_field_die (decl, context_die)
7759 register dw_die_ref context_die;
7761 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
7763 add_name_and_src_coords_attributes (decl_die, decl);
7764 add_type_attribute (decl_die, member_declared_type (decl),
7765 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
7768 /* If this is a bit field... */
7769 if (DECL_BIT_FIELD_TYPE (decl))
7771 add_byte_size_attribute (decl_die, decl);
7772 add_bit_size_attribute (decl_die, decl);
7773 add_bit_offset_attribute (decl_die, decl);
7776 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
7777 add_data_member_location_attribute (decl_die, decl);
7779 if (DECL_ARTIFICIAL (decl))
7780 add_AT_flag (decl_die, DW_AT_artificial, 1);
7782 if (TREE_PROTECTED (decl))
7783 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
7785 else if (TREE_PRIVATE (decl))
7786 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
7790 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
7791 Use modified_type_die instead.
7792 We keep this code here just in case these types of DIEs may be needed to
7793 represent certain things in other languages (e.g. Pascal) someday. */
7795 gen_pointer_type_die (type, context_die)
7797 register dw_die_ref context_die;
7799 register dw_die_ref ptr_die
7800 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
7802 equate_type_number_to_die (type, ptr_die);
7803 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
7804 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7807 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
7808 Use modified_type_die instead.
7809 We keep this code here just in case these types of DIEs may be needed to
7810 represent certain things in other languages (e.g. Pascal) someday. */
7812 gen_reference_type_die (type, context_die)
7814 register dw_die_ref context_die;
7816 register dw_die_ref ref_die
7817 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
7819 equate_type_number_to_die (type, ref_die);
7820 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
7821 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7825 /* Generate a DIE for a pointer to a member type. */
7827 gen_ptr_to_mbr_type_die (type, context_die)
7829 register dw_die_ref context_die;
7831 register dw_die_ref ptr_die
7832 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
7834 equate_type_number_to_die (type, ptr_die);
7835 add_AT_die_ref (ptr_die, DW_AT_containing_type,
7836 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
7837 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
7840 /* Generate the DIE for the compilation unit. */
7843 gen_compile_unit_die (main_input_filename)
7844 register char *main_input_filename;
7847 char *wd = getpwd ();
7849 comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
7850 add_name_attribute (comp_unit_die, main_input_filename);
7853 add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
7855 sprintf (producer, "%s %s", language_string, version_string);
7857 #ifdef MIPS_DEBUGGING_INFO
7858 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
7859 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
7860 not appear in the producer string, the debugger reaches the conclusion
7861 that the object file is stripped and has no debugging information.
7862 To get the MIPS/SGI debugger to believe that there is debugging
7863 information in the object file, we add a -g to the producer string. */
7864 if (debug_info_level > DINFO_LEVEL_TERSE)
7865 strcat (producer, " -g");
7868 add_AT_string (comp_unit_die, DW_AT_producer, producer);
7870 if (strcmp (language_string, "GNU C++") == 0)
7871 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
7873 else if (strcmp (language_string, "GNU Ada") == 0)
7874 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
7876 else if (strcmp (language_string, "GNU F77") == 0)
7877 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77);
7879 else if (flag_traditional)
7880 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
7883 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
7885 #if 0 /* unimplemented */
7886 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
7887 add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
7891 /* Generate a DIE for a string type. */
7894 gen_string_type_die (type, context_die)
7896 register dw_die_ref context_die;
7898 register dw_die_ref type_die
7899 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
7901 equate_type_number_to_die (type, type_die);
7903 /* Fudge the string length attribute for now. */
7905 /* TODO: add string length info.
7906 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
7907 bound_representation (upper_bound, 0, 'u'); */
7910 /* Generate the DIE for a base class. */
7913 gen_inheritance_die (binfo, context_die)
7914 register tree binfo;
7915 register dw_die_ref context_die;
7917 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
7919 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
7920 add_data_member_location_attribute (die, binfo);
7922 if (TREE_VIA_VIRTUAL (binfo))
7923 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7924 if (TREE_VIA_PUBLIC (binfo))
7925 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
7926 else if (TREE_VIA_PROTECTED (binfo))
7927 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
7930 /* Genearate a DIE for a class member. */
7933 gen_member_die (type, context_die)
7935 register dw_die_ref context_die;
7937 register tree member;
7939 /* If this is not an incomplete type, output descriptions of each of its
7940 members. Note that as we output the DIEs necessary to represent the
7941 members of this record or union type, we will also be trying to output
7942 DIEs to represent the *types* of those members. However the `type'
7943 function (above) will specifically avoid generating type DIEs for member
7944 types *within* the list of member DIEs for this (containing) type execpt
7945 for those types (of members) which are explicitly marked as also being
7946 members of this (containing) type themselves. The g++ front- end can
7947 force any given type to be treated as a member of some other
7948 (containing) type by setting the TYPE_CONTEXT of the given (member) type
7949 to point to the TREE node representing the appropriate (containing)
7952 /* First output info about the base classes. */
7953 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
7955 register tree bases = TYPE_BINFO_BASETYPES (type);
7956 register int n_bases = TREE_VEC_LENGTH (bases);
7959 for (i = 0; i < n_bases; i++)
7960 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
7963 /* Now output info about the data members and type members. */
7964 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
7965 gen_decl_die (member, context_die);
7967 /* Now output info about the function members (if any). */
7968 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
7969 gen_decl_die (member, context_die);
7972 /* Generate a DIE for a structure or union type. */
7975 gen_struct_or_union_type_die (type, context_die)
7977 register dw_die_ref context_die;
7979 register dw_die_ref type_die = lookup_type_die (type);
7980 register dw_die_ref scope_die = 0;
7981 register int nested = 0;
7983 if (type_die && ! TYPE_SIZE (type))
7986 if (TYPE_CONTEXT (type) != NULL_TREE
7987 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't')
7990 scope_die = scope_die_for (type, context_die);
7992 if (! type_die || (nested && scope_die == comp_unit_die))
7993 /* First occurrence of type or toplevel definition of nested class. */
7995 register dw_die_ref old_die = type_die;
7997 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
7998 ? DW_TAG_structure_type : DW_TAG_union_type,
8000 equate_type_number_to_die (type, type_die);
8001 add_name_attribute (type_die, type_tag (type));
8003 add_AT_die_ref (type_die, DW_AT_specification, old_die);
8006 remove_AT (type_die, DW_AT_declaration);
8008 /* If we're not in the right context to be defining this type, defer to
8009 avoid tricky recursion. */
8010 if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die)
8012 add_AT_flag (type_die, DW_AT_declaration, 1);
8015 /* If this type has been completed, then give it a byte_size attribute and
8016 then give a list of members. */
8017 else if (TYPE_SIZE (type))
8019 /* Prevent infinite recursion in cases where the type of some member of
8020 this type is expressed in terms of this type itself. */
8021 TREE_ASM_WRITTEN (type) = 1;
8022 add_byte_size_attribute (type_die, type);
8023 if (type_tag (type))
8024 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8026 push_decl_scope (type);
8027 gen_member_die (type, type_die);
8030 /* GNU extension: Record what type our vtable lives in. */
8031 if (TYPE_VFIELD (type))
8033 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
8035 gen_type_die (vtype, context_die);
8036 add_AT_die_ref (type_die, DW_AT_containing_type,
8037 lookup_type_die (vtype));
8041 add_AT_flag (type_die, DW_AT_declaration, 1);
8044 /* Generate a DIE for a subroutine _type_. */
8047 gen_subroutine_type_die (type, context_die)
8049 register dw_die_ref context_die;
8051 register tree return_type = TREE_TYPE (type);
8052 register dw_die_ref subr_die
8053 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
8055 equate_type_number_to_die (type, subr_die);
8056 add_prototyped_attribute (subr_die, type);
8057 add_type_attribute (subr_die, return_type, 0, 0, context_die);
8058 gen_formal_types_die (type, subr_die);
8061 /* Generate a DIE for a type definition */
8064 gen_typedef_die (decl, context_die)
8066 register dw_die_ref context_die;
8068 register dw_die_ref type_die;
8069 register tree origin;
8071 if (TREE_ASM_WRITTEN (decl))
8073 TREE_ASM_WRITTEN (decl) = 1;
8075 type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
8076 origin = decl_ultimate_origin (decl);
8078 add_abstract_origin_attribute (type_die, origin);
8082 add_name_and_src_coords_attributes (type_die, decl);
8083 if (DECL_ORIGINAL_TYPE (decl))
8085 type = DECL_ORIGINAL_TYPE (decl);
8086 equate_type_number_to_die (TREE_TYPE (decl), type_die);
8089 type = TREE_TYPE (decl);
8090 add_type_attribute (type_die, type, TREE_READONLY (decl),
8091 TREE_THIS_VOLATILE (decl), context_die);
8094 if (DECL_ABSTRACT (decl))
8095 equate_decl_number_to_die (decl, type_die);
8098 /* Generate a type description DIE. */
8101 gen_type_die (type, context_die)
8103 register dw_die_ref context_die;
8105 if (type == NULL_TREE || type == error_mark_node)
8108 /* We are going to output a DIE to represent the unqualified version of of
8109 this type (i.e. without any const or volatile qualifiers) so get the
8110 main variant (i.e. the unqualified version) of this type now. */
8111 type = type_main_variant (type);
8113 if (TREE_ASM_WRITTEN (type))
8116 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8117 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
8119 TREE_ASM_WRITTEN (type) = 1;
8120 gen_decl_die (TYPE_NAME (type), context_die);
8124 switch (TREE_CODE (type))
8130 case REFERENCE_TYPE:
8131 /* For these types, all that is required is that we output a DIE (or a
8132 set of DIEs) to represent the "basis" type. */
8133 gen_type_die (TREE_TYPE (type), context_die);
8137 /* This code is used for C++ pointer-to-data-member types.
8138 Output a description of the relevant class type. */
8139 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
8141 /* Output a description of the type of the object pointed to. */
8142 gen_type_die (TREE_TYPE (type), context_die);
8144 /* Now output a DIE to represent this pointer-to-data-member type
8146 gen_ptr_to_mbr_type_die (type, context_die);
8150 gen_type_die (TYPE_DOMAIN (type), context_die);
8151 gen_set_type_die (type, context_die);
8155 gen_type_die (TREE_TYPE (type), context_die);
8156 abort (); /* No way to represent these in Dwarf yet! */
8160 /* Force out return type (in case it wasn't forced out already). */
8161 gen_type_die (TREE_TYPE (type), context_die);
8162 gen_subroutine_type_die (type, context_die);
8166 /* Force out return type (in case it wasn't forced out already). */
8167 gen_type_die (TREE_TYPE (type), context_die);
8168 gen_subroutine_type_die (type, context_die);
8172 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
8174 gen_type_die (TREE_TYPE (type), context_die);
8175 gen_string_type_die (type, context_die);
8178 gen_array_type_die (type, context_die);
8184 case QUAL_UNION_TYPE:
8185 /* If this is a nested type whose containing class hasn't been
8186 written out yet, writing it out will cover this one, too. */
8187 if (TYPE_CONTEXT (type)
8188 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
8189 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8191 gen_type_die (TYPE_CONTEXT (type), context_die);
8193 if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8196 /* If that failed, attach ourselves to the stub. */
8197 push_decl_scope (TYPE_CONTEXT (type));
8198 context_die = lookup_type_die (TYPE_CONTEXT (type));
8201 if (TREE_CODE (type) == ENUMERAL_TYPE)
8202 gen_enumeration_type_die (type, context_die);
8204 gen_struct_or_union_type_die (type, context_die);
8206 if (TYPE_CONTEXT (type)
8207 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
8208 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8211 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
8212 it up if it is ever completed. gen_*_type_die will set it for us
8213 when appropriate. */
8222 /* No DIEs needed for fundamental types. */
8226 /* No Dwarf representation currently defined. */
8233 TREE_ASM_WRITTEN (type) = 1;
8236 /* Generate a DIE for a tagged type instantiation. */
8239 gen_tagged_type_instantiation_die (type, context_die)
8241 register dw_die_ref context_die;
8243 if (type == NULL_TREE || type == error_mark_node)
8246 /* We are going to output a DIE to represent the unqualified version of of
8247 this type (i.e. without any const or volatile qualifiers) so make sure
8248 that we have the main variant (i.e. the unqualified version) of this
8250 assert (type == type_main_variant (type));
8251 assert (TREE_ASM_WRITTEN (type));
8253 switch (TREE_CODE (type))
8259 gen_inlined_enumeration_type_die (type, context_die);
8263 gen_inlined_structure_type_die (type, context_die);
8267 case QUAL_UNION_TYPE:
8268 gen_inlined_union_type_die (type, context_die);
8276 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
8277 things which are local to the given block. */
8280 gen_block_die (stmt, context_die, depth)
8282 register dw_die_ref context_die;
8285 register int must_output_die = 0;
8286 register tree origin;
8288 register enum tree_code origin_code;
8290 /* Ignore blocks never really used to make RTL. */
8292 if (stmt == NULL_TREE || !TREE_USED (stmt))
8295 /* Determine the "ultimate origin" of this block. This block may be an
8296 inlined instance of an inlined instance of inline function, so we have
8297 to trace all of the way back through the origin chain to find out what
8298 sort of node actually served as the original seed for the creation of
8299 the current block. */
8300 origin = block_ultimate_origin (stmt);
8301 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
8303 /* Determine if we need to output any Dwarf DIEs at all to represent this
8305 if (origin_code == FUNCTION_DECL)
8306 /* The outer scopes for inlinings *must* always be represented. We
8307 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
8308 must_output_die = 1;
8311 /* In the case where the current block represents an inlining of the
8312 "body block" of an inline function, we must *NOT* output any DIE for
8313 this block because we have already output a DIE to represent the
8314 whole inlined function scope and the "body block" of any function
8315 doesn't really represent a different scope according to ANSI C
8316 rules. So we check here to make sure that this block does not
8317 represent a "body block inlining" before trying to set the
8318 `must_output_die' flag. */
8319 if (! is_body_block (origin ? origin : stmt))
8321 /* Determine if this block directly contains any "significant"
8322 local declarations which we will need to output DIEs for. */
8323 if (debug_info_level > DINFO_LEVEL_TERSE)
8324 /* We are not in terse mode so *any* local declaration counts
8325 as being a "significant" one. */
8326 must_output_die = (BLOCK_VARS (stmt) != NULL);
8328 /* We are in terse mode, so only local (nested) function
8329 definitions count as "significant" local declarations. */
8330 for (decl = BLOCK_VARS (stmt);
8331 decl != NULL; decl = TREE_CHAIN (decl))
8332 if (TREE_CODE (decl) == FUNCTION_DECL
8333 && DECL_INITIAL (decl))
8335 must_output_die = 1;
8341 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
8342 DIE for any block which contains no significant local declarations at
8343 all. Rather, in such cases we just call `decls_for_scope' so that any
8344 needed Dwarf info for any sub-blocks will get properly generated. Note
8345 that in terse mode, our definition of what constitutes a "significant"
8346 local declaration gets restricted to include only inlined function
8347 instances and local (nested) function definitions. */
8348 if (must_output_die)
8350 if (origin_code == FUNCTION_DECL)
8351 gen_inlined_subroutine_die (stmt, context_die, depth);
8353 gen_lexical_block_die (stmt, context_die, depth);
8356 decls_for_scope (stmt, context_die, depth);
8359 /* Generate all of the decls declared within a given scope and (recursively)
8360 all of it's sub-blocks. */
8363 decls_for_scope (stmt, context_die, depth)
8365 register dw_die_ref context_die;
8369 register tree subblocks;
8371 /* Ignore blocks never really used to make RTL. */
8372 if (stmt == NULL_TREE || ! TREE_USED (stmt))
8375 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
8376 next_block_number++;
8378 /* Output the DIEs to represent all of the data objects and typedefs
8379 declared directly within this block but not within any nested
8380 sub-blocks. Also, nested function and tag DIEs have been
8381 generated with a parent of NULL; fix that up now. */
8382 for (decl = BLOCK_VARS (stmt);
8383 decl != NULL; decl = TREE_CHAIN (decl))
8385 register dw_die_ref die;
8387 if (TREE_CODE (decl) == FUNCTION_DECL)
8388 die = lookup_decl_die (decl);
8389 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
8390 die = lookup_type_die (TREE_TYPE (decl));
8394 if (die != NULL && die->die_parent == NULL)
8396 add_child_die (context_die, die);
8400 gen_decl_die (decl, context_die);
8403 /* Output the DIEs to represent all sub-blocks (and the items declared
8404 therein) of this block. */
8405 for (subblocks = BLOCK_SUBBLOCKS (stmt);
8407 subblocks = BLOCK_CHAIN (subblocks))
8408 gen_block_die (subblocks, context_die, depth + 1);
8411 /* Is this a typedef we can avoid emitting? */
8414 is_redundant_typedef (decl)
8417 if (TYPE_DECL_IS_STUB (decl))
8420 if (DECL_ARTIFICIAL (decl)
8421 && DECL_CONTEXT (decl)
8422 && is_tagged_type (DECL_CONTEXT (decl))
8423 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
8424 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
8425 /* Also ignore the artificial member typedef for the class name. */
8431 /* Generate Dwarf debug information for a decl described by DECL. */
8434 gen_decl_die (decl, context_die)
8436 register dw_die_ref context_die;
8438 register tree origin;
8440 /* Make a note of the decl node we are going to be working on. We may need
8441 to give the user the source coordinates of where it appeared in case we
8442 notice (later on) that something about it looks screwy. */
8443 dwarf_last_decl = decl;
8445 if (TREE_CODE (decl) == ERROR_MARK)
8448 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
8449 ignore a function definition, since that would screw up our count of
8450 blocks, and that it turn will completely screw up the the labels we will
8451 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
8452 subsequent blocks). */
8453 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
8456 switch (TREE_CODE (decl))
8459 /* The individual enumerators of an enum type get output when we output
8460 the Dwarf representation of the relevant enum type itself. */
8464 /* Don't output any DIEs to represent mere function declarations,
8465 unless they are class members or explicit block externs. */
8466 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
8467 && (current_function_decl == NULL_TREE || ! DECL_ARTIFICIAL (decl)))
8470 if (debug_info_level > DINFO_LEVEL_TERSE)
8472 /* Before we describe the FUNCTION_DECL itself, make sure that we
8473 have described its return type. */
8474 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
8476 /* And its containing type. */
8477 origin = decl_class_context (decl);
8478 if (origin != NULL_TREE)
8479 gen_type_die (origin, context_die);
8481 /* And its virtual context. */
8482 if (DECL_VINDEX (decl) != NULL_TREE)
8483 gen_type_die (DECL_CONTEXT (decl), context_die);
8486 /* Now output a DIE to represent the function itself. */
8487 gen_subprogram_die (decl, context_die);
8491 /* If we are in terse mode, don't generate any DIEs to represent any
8493 if (debug_info_level <= DINFO_LEVEL_TERSE)
8496 /* In the special case of a TYPE_DECL node representing the
8497 declaration of some type tag, if the given TYPE_DECL is marked as
8498 having been instantiated from some other (original) TYPE_DECL node
8499 (e.g. one which was generated within the original definition of an
8500 inline function) we have to generate a special (abbreviated)
8501 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration-type
8503 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
8505 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
8509 if (is_redundant_typedef (decl))
8510 gen_type_die (TREE_TYPE (decl), context_die);
8512 /* Output a DIE to represent the typedef itself. */
8513 gen_typedef_die (decl, context_die);
8517 if (debug_info_level >= DINFO_LEVEL_NORMAL)
8518 gen_label_die (decl, context_die);
8522 /* If we are in terse mode, don't generate any DIEs to represent any
8523 variable declarations or definitions. */
8524 if (debug_info_level <= DINFO_LEVEL_TERSE)
8527 /* Output any DIEs that are needed to specify the type of this data
8529 gen_type_die (TREE_TYPE (decl), context_die);
8531 /* And its containing type. */
8532 origin = decl_class_context (decl);
8533 if (origin != NULL_TREE)
8534 gen_type_die (origin, context_die);
8536 /* Now output the DIE to represent the data object itself. This gets
8537 complicated because of the possibility that the VAR_DECL really
8538 represents an inlined instance of a formal parameter for an inline
8540 origin = decl_ultimate_origin (decl);
8541 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
8542 gen_formal_parameter_die (decl, context_die);
8544 gen_variable_die (decl, context_die);
8548 /* Ignore the nameless fields that are used to skip bits, but
8549 handle C++ anonymous unions. */
8550 if (DECL_NAME (decl) != NULL_TREE
8551 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
8553 gen_type_die (member_declared_type (decl), context_die);
8554 gen_field_die (decl, context_die);
8559 gen_type_die (TREE_TYPE (decl), context_die);
8560 gen_formal_parameter_die (decl, context_die);
8568 /* Write the debugging output for DECL. */
8571 dwarf2out_decl (decl)
8574 register dw_die_ref context_die = comp_unit_die;
8576 if (TREE_CODE (decl) == ERROR_MARK)
8579 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
8580 hope that the node in question doesn't represent a function definition.
8581 If it does, then totally ignoring it is bound to screw up our count of
8582 blocks, and that it turn will completely screw up the the labels we will
8583 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
8584 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
8585 own sequence numbers with them!) */
8586 if (DECL_IGNORED_P (decl))
8588 if (TREE_CODE (decl) == FUNCTION_DECL
8589 && DECL_INITIAL (decl) != NULL)
8595 switch (TREE_CODE (decl))
8598 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
8599 builtin function. Explicit programmer-supplied declarations of
8600 these same functions should NOT be ignored however. */
8601 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
8604 /* What we would really like to do here is to filter out all mere
8605 file-scope declarations of file-scope functions which are never
8606 referenced later within this translation unit (and keep all of ones
8607 that *are* referenced later on) but we aren't clarvoiant, so we have
8608 no idea which functions will be referenced in the future (i.e. later
8609 on within the current translation unit). So here we just ignore all
8610 file-scope function declarations which are not also definitions. If
8611 and when the debugger needs to know something about these funcstion,
8612 it wil have to hunt around and find the DWARF information associated
8613 with the definition of the function. Note that we can't just check
8614 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
8615 definitions and which ones represent mere declarations. We have to
8616 check `DECL_INITIAL' instead. That's because the C front-end
8617 supports some weird semantics for "extern inline" function
8618 definitions. These can get inlined within the current translation
8619 unit (an thus, we need to generate DWARF info for their abstract
8620 instances so that the DWARF info for the concrete inlined instances
8621 can have something to refer to) but the compiler never generates any
8622 out-of-lines instances of such things (despite the fact that they
8623 *are* definitions). The important point is that the C front-end
8624 marks these "extern inline" functions as DECL_EXTERNAL, but we need
8625 to generate DWARF for them anyway. Note that the C++ front-end also
8626 plays some similar games for inline function definitions appearing
8627 within include files which also contain
8628 `#pragma interface' pragmas. */
8629 if (DECL_INITIAL (decl) == NULL_TREE)
8632 /* If we're a nested function, initially use a parent of NULL; if we're
8633 a plain function, this will be fixed up in decls_for_scope. If
8634 we're a method, it will be ignored, since we already have a DIE. */
8635 if (decl_function_context (decl))
8641 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
8642 declaration and if the declaration was never even referenced from
8643 within this entire compilation unit. We suppress these DIEs in
8644 order to save space in the .debug section (by eliminating entries
8645 which are probably useless). Note that we must not suppress
8646 block-local extern declarations (whether used or not) because that
8647 would screw-up the debugger's name lookup mechanism and cause it to
8648 miss things which really ought to be in scope at a given point. */
8649 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
8652 /* If we are in terse mode, don't generate any DIEs to represent any
8653 variable declarations or definitions. */
8654 if (debug_info_level <= DINFO_LEVEL_TERSE)
8659 /* Don't bother trying to generate any DIEs to represent any of the
8660 normal built-in types for the language we are compiling. */
8661 if (DECL_SOURCE_LINE (decl) == 0)
8663 /* OK, we need to generate one for `bool' so GDB knows what type
8664 comparisons have. */
8665 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
8666 == DW_LANG_C_plus_plus)
8667 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
8668 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
8673 /* If we are in terse mode, don't generate any DIEs for types. */
8674 if (debug_info_level <= DINFO_LEVEL_TERSE)
8677 /* If we're a function-scope tag, initially use a parent of NULL;
8678 this will be fixed up in decls_for_scope. */
8679 if (decl_function_context (decl))
8688 gen_decl_die (decl, context_die);
8689 output_pending_types_for_scope (comp_unit_die);
8692 /* Output a marker (i.e. a label) for the beginning of the generated code for
8696 dwarf2out_begin_block (blocknum)
8697 register unsigned blocknum;
8699 function_section (current_function_decl);
8700 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
8703 /* Output a marker (i.e. a label) for the end of the generated code for a
8707 dwarf2out_end_block (blocknum)
8708 register unsigned blocknum;
8710 function_section (current_function_decl);
8711 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
8714 /* Output a marker (i.e. a label) at a point in the assembly code which
8715 corresponds to a given source level label. */
8718 dwarf2out_label (insn)
8721 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8723 if (debug_info_level >= DINFO_LEVEL_NORMAL)
8725 function_section (current_function_decl);
8726 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
8727 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
8728 (unsigned) INSN_UID (insn));
8732 /* Lookup a filename (in the list of filenames that we know about here in
8733 dwarf2out.c) and return its "index". The index of each (known) filename is
8734 just a unique number which is associated with only that one filename.
8735 We need such numbers for the sake of generating labels
8736 (in the .debug_sfnames section) and references to those
8737 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
8738 If the filename given as an argument is not found in our current list,
8739 add it to the list and assign it the next available unique index number.
8740 In order to speed up searches, we remember the index of the filename
8741 was looked up last. This handles the majority of all searches. */
8744 lookup_filename (file_name)
8747 static unsigned last_file_lookup_index = 0;
8748 register unsigned i;
8750 /* Check to see if the file name that was searched on the previous call
8751 matches this file name. If so, return the index. */
8752 if (last_file_lookup_index != 0)
8753 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
8754 return last_file_lookup_index;
8756 /* Didn't match the previous lookup, search the table */
8757 for (i = 1; i < file_table_in_use; ++i)
8758 if (strcmp (file_name, file_table[i]) == 0)
8760 last_file_lookup_index = i;
8764 /* Prepare to add a new table entry by making sure there is enough space in
8765 the table to do so. If not, expand the current table. */
8766 if (file_table_in_use == file_table_allocated)
8768 file_table_allocated += FILE_TABLE_INCREMENT;
8770 = (char **) xrealloc (file_table,
8771 file_table_allocated * sizeof (char *));
8774 /* Add the new entry to the end of the filename table. */
8775 file_table[file_table_in_use] = xstrdup (file_name);
8776 last_file_lookup_index = file_table_in_use++;
8778 return last_file_lookup_index;
8781 /* Output a label to mark the beginning of a source code line entry
8782 and record information relating to this source line, in
8783 'line_info_table' for later output of the .debug_line section. */
8786 dwarf2out_line (filename, line)
8787 register char *filename;
8788 register unsigned line;
8790 if (debug_info_level >= DINFO_LEVEL_NORMAL)
8792 function_section (current_function_decl);
8794 if (DECL_SECTION_NAME (current_function_decl))
8796 register dw_separate_line_info_ref line_info;
8797 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
8798 separate_line_info_table_in_use);
8799 fputc ('\n', asm_out_file);
8801 /* expand the line info table if necessary */
8802 if (separate_line_info_table_in_use
8803 == separate_line_info_table_allocated)
8805 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
8806 separate_line_info_table
8807 = (dw_separate_line_info_ref)
8808 xrealloc (separate_line_info_table,
8809 separate_line_info_table_allocated
8810 * sizeof (dw_separate_line_info_entry));
8813 /* Add the new entry at the end of the line_info_table. */
8815 = &separate_line_info_table[separate_line_info_table_in_use++];
8816 line_info->dw_file_num = lookup_filename (filename);
8817 line_info->dw_line_num = line;
8818 line_info->function = current_funcdef_number;
8822 register dw_line_info_ref line_info;
8824 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
8825 line_info_table_in_use);
8826 fputc ('\n', asm_out_file);
8828 /* Expand the line info table if necessary. */
8829 if (line_info_table_in_use == line_info_table_allocated)
8831 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
8833 = (dw_line_info_ref)
8834 xrealloc (line_info_table,
8835 (line_info_table_allocated
8836 * sizeof (dw_line_info_entry)));
8839 /* Add the new entry at the end of the line_info_table. */
8840 line_info = &line_info_table[line_info_table_in_use++];
8841 line_info->dw_file_num = lookup_filename (filename);
8842 line_info->dw_line_num = line;
8847 /* Record the beginning of a new source file, for later output
8848 of the .debug_macinfo section. At present, unimplemented. */
8851 dwarf2out_start_source_file (filename)
8852 register char *filename;
8856 /* Record the end of a source file, for later output
8857 of the .debug_macinfo section. At present, unimplemented. */
8860 dwarf2out_end_source_file ()
8864 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
8865 the tail part of the directive line, i.e. the part which is past the
8866 initial whitespace, #, whitespace, directive-name, whitespace part. */
8869 dwarf2out_define (lineno, buffer)
8870 register unsigned lineno;
8871 register char *buffer;
8873 static int initialized = 0;
8876 dwarf2out_start_source_file (primary_filename);
8881 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
8882 the tail part of the directive line, i.e. the part which is past the
8883 initial whitespace, #, whitespace, directive-name, whitespace part. */
8886 dwarf2out_undef (lineno, buffer)
8887 register unsigned lineno;
8888 register char *buffer;
8892 /* Set up for Dwarf output at the start of compilation. */
8895 dwarf2out_init (asm_out_file, main_input_filename)
8896 register FILE *asm_out_file;
8897 register char *main_input_filename;
8899 /* Remember the name of the primary input file. */
8900 primary_filename = main_input_filename;
8902 /* Allocate the initial hunk of the file_table. */
8903 file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *));
8904 bzero ((char *) file_table, FILE_TABLE_INCREMENT * sizeof (char *));
8905 file_table_allocated = FILE_TABLE_INCREMENT;
8907 /* Skip the first entry - file numbers begin at 1. */
8908 file_table_in_use = 1;
8910 /* Allocate the initial hunk of the decl_die_table. */
8912 = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8913 bzero ((char *) decl_die_table,
8914 DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8915 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
8916 decl_die_table_in_use = 0;
8918 /* Allocate the initial hunk of the decl_scope_table. */
8920 = (tree *) xmalloc (DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
8921 bzero ((char *) decl_scope_table,
8922 DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
8923 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
8924 decl_scope_depth = 0;
8926 /* Allocate the initial hunk of the abbrev_die_table. */
8928 = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT
8929 * sizeof (dw_die_ref));
8930 bzero ((char *) abbrev_die_table,
8931 ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8932 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
8933 /* Zero-th entry is allocated, but unused */
8934 abbrev_die_table_in_use = 1;
8936 /* Allocate the initial hunk of the line_info_table. */
8938 = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT
8939 * sizeof (dw_line_info_entry));
8940 bzero ((char *) line_info_table,
8941 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
8942 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
8943 /* Zero-th entry is allocated, but unused */
8944 line_info_table_in_use = 1;
8946 /* Generate the initial DIE for the .debug section. Note that the (string)
8947 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
8948 will (typically) be a relative pathname and that this pathname should be
8949 taken as being relative to the directory from which the compiler was
8950 invoked when the given (base) source file was compiled. */
8951 gen_compile_unit_die (main_input_filename);
8953 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
8955 /* Initialize the frame unwind information. Eventually this should be
8956 called from compile_file instead. */
8957 dwarf2out_frame_init ();
8960 /* Output stuff that dwarf requires at the end of every file,
8961 and generate the DWARF-2 debugging info. */
8966 /* Traverse the DIE tree and add sibling attributes to those DIE's
8967 that have children. */
8968 add_sibling_attributes (comp_unit_die);
8970 /* Output a terminator label for the .text section. */
8971 fputc ('\n', asm_out_file);
8972 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
8973 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
8976 /* Output a terminator label for the .data section. */
8977 fputc ('\n', asm_out_file);
8978 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
8979 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
8981 /* Output a terminator label for the .bss section. */
8982 fputc ('\n', asm_out_file);
8983 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
8984 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
8987 /* Output the frame unwind information. Eventually this should be called
8988 from compile_file instead. */
8989 dwarf2out_frame_finish ();
8991 /* Output the source line correspondence table. */
8992 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
8994 fputc ('\n', asm_out_file);
8995 ASM_OUTPUT_SECTION (asm_out_file, LINE_SECTION);
8996 output_line_info ();
8998 /* We can only use the low/high_pc attributes if all of the code
9000 if (separate_line_info_table_in_use == 0)
9002 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_SECTION);
9003 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
9006 add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, LINE_SECTION);
9009 /* Output the abbreviation table. */
9010 fputc ('\n', asm_out_file);
9011 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9012 build_abbrev_table (comp_unit_die);
9013 output_abbrev_section ();
9015 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9016 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9017 calc_die_sizes (comp_unit_die);
9019 /* Output debugging information. */
9020 fputc ('\n', asm_out_file);
9021 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_SECTION);
9022 output_compilation_unit_header ();
9023 output_die (comp_unit_die);
9025 if (pubname_table_in_use)
9027 /* Output public names table. */
9028 fputc ('\n', asm_out_file);
9029 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
9033 if (fde_table_in_use)
9035 /* Output the address range information. */
9036 fputc ('\n', asm_out_file);
9037 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
9041 /* The only DIE we should have with a parent of NULL is comp_unit_die. */
9042 assert (limbo_die_count == 1);
9044 #endif /* DWARF2_DEBUGGING_INFO */