1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 93, 95-98, 1999 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com).
4 Derived from DWARF 1 implementation of 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, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
24 /* The first part of this file deals with the DWARF 2 frame unwind
25 information, which is also used by the GCC efficient exception handling
26 mechanism. The second part, controlled only by an #ifdef
27 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 #include "hard-reg-set.h"
38 #include "insn-config.h"
44 #include "dwarf2out.h"
46 #include "dyn-string.h"
48 /* We cannot use <assert.h> in GCC source, since that would include
49 GCC's assert.h, which may not be compatible with the host compiler. */
54 # define assert(e) do { if (! (e)) abort (); } while (0)
57 /* Decide whether we want to emit frame unwind information for the current
63 return (write_symbols == DWARF2_DEBUG
64 #ifdef DWARF2_FRAME_INFO
67 #ifdef DWARF2_UNWIND_INFO
68 || (flag_exceptions && ! exceptions_via_longjmp)
73 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
75 /* How to start an assembler comment. */
76 #ifndef ASM_COMMENT_START
77 #define ASM_COMMENT_START ";#"
80 typedef struct dw_cfi_struct *dw_cfi_ref;
81 typedef struct dw_fde_struct *dw_fde_ref;
82 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
84 /* Call frames are described using a sequence of Call Frame
85 Information instructions. The register number, offset
86 and address fields are provided as possible operands;
87 their use is selected by the opcode field. */
89 typedef union dw_cfi_oprnd_struct
91 unsigned long dw_cfi_reg_num;
92 long int dw_cfi_offset;
97 typedef struct dw_cfi_struct
99 dw_cfi_ref dw_cfi_next;
100 enum dwarf_call_frame_info dw_cfi_opc;
101 dw_cfi_oprnd dw_cfi_oprnd1;
102 dw_cfi_oprnd dw_cfi_oprnd2;
106 /* All call frame descriptions (FDE's) in the GCC generated DWARF
107 refer to a single Common Information Entry (CIE), defined at
108 the beginning of the .debug_frame section. This used of a single
109 CIE obviates the need to keep track of multiple CIE's
110 in the DWARF generation routines below. */
112 typedef struct dw_fde_struct
115 char *dw_fde_current_label;
117 dw_cfi_ref dw_fde_cfi;
121 /* Maximum size (in bytes) of an artificially generated label. */
122 #define MAX_ARTIFICIAL_LABEL_BYTES 30
124 /* Make sure we know the sizes of the various types dwarf can describe. These
125 are only defaults. If the sizes are different for your target, you should
126 override these values by defining the appropriate symbols in your tm.h
129 #ifndef CHAR_TYPE_SIZE
130 #define CHAR_TYPE_SIZE BITS_PER_UNIT
133 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
136 /* The size in bytes of a DWARF field indicating an offset or length
137 relative to a debug info section, specified to be 4 bytes in the DWARF-2
138 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
140 #ifndef DWARF_OFFSET_SIZE
141 #define DWARF_OFFSET_SIZE 4
144 #define DWARF_VERSION 2
146 /* Round SIZE up to the nearest BOUNDARY. */
147 #define DWARF_ROUND(SIZE,BOUNDARY) \
148 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
150 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
151 #ifdef STACK_GROWS_DOWNWARD
152 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
154 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
157 /* A pointer to the base of a table that contains frame description
158 information for each routine. */
159 static dw_fde_ref fde_table;
161 /* Number of elements currently allocated for fde_table. */
162 static unsigned fde_table_allocated;
164 /* Number of elements in fde_table currently in use. */
165 static unsigned fde_table_in_use;
167 /* Size (in elements) of increments by which we may expand the
169 #define FDE_TABLE_INCREMENT 256
171 /* A list of call frame insns for the CIE. */
172 static dw_cfi_ref cie_cfi_head;
174 /* The number of the current function definition for which debugging
175 information is being generated. These numbers range from 1 up to the
176 maximum number of function definitions contained within the current
177 compilation unit. These numbers are used to create unique label id's
178 unique to each function definition. */
179 static unsigned current_funcdef_number = 0;
181 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
182 attribute that accelerates the lookup of the FDE associated
183 with the subprogram. This variable holds the table index of the FDE
184 associated with the current function (body) definition. */
185 static unsigned current_funcdef_fde;
187 /* Forward declarations for functions defined in this file. */
189 static char *stripattributes PROTO((const char *));
190 static const char *dwarf_cfi_name PROTO((unsigned));
191 static dw_cfi_ref new_cfi PROTO((void));
192 static void add_cfi PROTO((dw_cfi_ref *, dw_cfi_ref));
193 static unsigned long size_of_uleb128 PROTO((unsigned long));
194 static unsigned long size_of_sleb128 PROTO((long));
195 static void output_uleb128 PROTO((unsigned long));
196 static void output_sleb128 PROTO((long));
197 static void add_fde_cfi PROTO((char *, dw_cfi_ref));
198 static void lookup_cfa_1 PROTO((dw_cfi_ref, unsigned long *,
200 static void lookup_cfa PROTO((unsigned long *, long *));
201 static void reg_save PROTO((char *, unsigned, unsigned,
203 static void initial_return_save PROTO((rtx));
204 static void output_cfi PROTO((dw_cfi_ref, dw_fde_ref));
205 static void output_call_frame_info PROTO((int));
206 static unsigned reg_number PROTO((rtx));
207 static void dwarf2out_stack_adjust PROTO((rtx));
208 static void dwarf2out_frame_debug_expr PROTO((rtx, char *));
210 /* Definitions of defaults for assembler-dependent names of various
211 pseudo-ops and section names.
212 Theses may be overridden in the tm.h file (if necessary) for a particular
215 #ifdef OBJECT_FORMAT_ELF
216 #ifndef UNALIGNED_SHORT_ASM_OP
217 #define UNALIGNED_SHORT_ASM_OP ".2byte"
219 #ifndef UNALIGNED_INT_ASM_OP
220 #define UNALIGNED_INT_ASM_OP ".4byte"
222 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
223 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
225 #endif /* OBJECT_FORMAT_ELF */
228 #define ASM_BYTE_OP ".byte"
231 /* Data and reference forms for relocatable data. */
232 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
233 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
235 /* Pseudo-op for defining a new section. */
236 #ifndef SECTION_ASM_OP
237 #define SECTION_ASM_OP ".section"
240 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
241 print the SECTION_ASM_OP and the section name. The default here works for
242 almost all svr4 assemblers, except for the sparc, where the section name
243 must be enclosed in double quotes. (See sparcv4.h). */
244 #ifndef SECTION_FORMAT
245 #ifdef PUSHSECTION_FORMAT
246 #define SECTION_FORMAT PUSHSECTION_FORMAT
248 #define SECTION_FORMAT "\t%s\t%s\n"
252 #ifndef FRAME_SECTION
253 #define FRAME_SECTION ".debug_frame"
256 #ifndef FUNC_BEGIN_LABEL
257 #define FUNC_BEGIN_LABEL "LFB"
259 #ifndef FUNC_END_LABEL
260 #define FUNC_END_LABEL "LFE"
262 #define CIE_AFTER_SIZE_LABEL "LSCIE"
263 #define CIE_END_LABEL "LECIE"
264 #define CIE_LENGTH_LABEL "LLCIE"
265 #define FDE_AFTER_SIZE_LABEL "LSFDE"
266 #define FDE_END_LABEL "LEFDE"
267 #define FDE_LENGTH_LABEL "LLFDE"
269 /* Definitions of defaults for various types of primitive assembly language
270 output operations. These may be overridden from within the tm.h file,
271 but typically, that is unnecessary. */
273 #ifndef ASM_OUTPUT_SECTION
274 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
275 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
278 #ifndef ASM_OUTPUT_DWARF_DATA1
279 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
280 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
283 #ifndef ASM_OUTPUT_DWARF_DELTA1
284 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
285 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
286 assemble_name (FILE, LABEL1); \
287 fprintf (FILE, "-"); \
288 assemble_name (FILE, LABEL2); \
292 #ifdef UNALIGNED_INT_ASM_OP
294 #ifndef UNALIGNED_OFFSET_ASM_OP
295 #define UNALIGNED_OFFSET_ASM_OP \
296 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
299 #ifndef UNALIGNED_WORD_ASM_OP
300 #define UNALIGNED_WORD_ASM_OP \
301 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
304 #ifndef ASM_OUTPUT_DWARF_DELTA2
305 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
306 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
307 assemble_name (FILE, LABEL1); \
308 fprintf (FILE, "-"); \
309 assemble_name (FILE, LABEL2); \
313 #ifndef ASM_OUTPUT_DWARF_DELTA4
314 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
315 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
316 assemble_name (FILE, LABEL1); \
317 fprintf (FILE, "-"); \
318 assemble_name (FILE, LABEL2); \
322 #ifndef ASM_OUTPUT_DWARF_DELTA
323 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
324 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
325 assemble_name (FILE, LABEL1); \
326 fprintf (FILE, "-"); \
327 assemble_name (FILE, LABEL2); \
331 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
332 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
333 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
334 assemble_name (FILE, LABEL1); \
335 fprintf (FILE, "-"); \
336 assemble_name (FILE, LABEL2); \
340 #ifndef ASM_OUTPUT_DWARF_ADDR
341 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
342 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
343 assemble_name (FILE, LABEL); \
347 /* ??? This macro takes an RTX in dwarfout.c and a string in dwarf2out.c.
348 We resolve the conflict by creating a new macro ASM_OUTPUT_DWARF2_ADDR_CONST
349 for ports that want to support both DWARF1 and DWARF2. This needs a better
350 solution. See also the comments in sparc/sp64-elf.h. */
351 #ifdef ASM_OUTPUT_DWARF2_ADDR_CONST
352 #undef ASM_OUTPUT_DWARF_ADDR_CONST
353 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
354 ASM_OUTPUT_DWARF2_ADDR_CONST (FILE, ADDR)
357 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
358 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
359 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
362 #ifndef ASM_OUTPUT_DWARF_OFFSET4
363 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
364 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
365 assemble_name (FILE, LABEL); \
369 #ifndef ASM_OUTPUT_DWARF_OFFSET
370 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
371 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
372 assemble_name (FILE, LABEL); \
376 #ifndef ASM_OUTPUT_DWARF_DATA2
377 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
378 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
381 #ifndef ASM_OUTPUT_DWARF_DATA4
382 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
383 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
386 #ifndef ASM_OUTPUT_DWARF_DATA
387 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
388 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
389 (unsigned long) (VALUE))
392 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
393 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
394 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
395 (unsigned long) (VALUE))
398 #ifndef ASM_OUTPUT_DWARF_DATA8
399 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
401 if (WORDS_BIG_ENDIAN) \
403 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
404 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
408 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
409 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
414 #else /* UNALIGNED_INT_ASM_OP */
416 /* We don't have unaligned support, let's hope the normal output works for
419 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
420 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), PTR_SIZE, 1)
422 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
423 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
425 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
426 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
428 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
429 assemble_integer (gen_rtx_MINUS (HImode, \
430 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
431 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
434 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
435 assemble_integer (gen_rtx_MINUS (SImode, \
436 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
437 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
440 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
441 assemble_integer (gen_rtx_MINUS (Pmode, \
442 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
443 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
446 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
447 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
449 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
450 assemble_integer (GEN_INT (VALUE), 4, 1)
452 #endif /* UNALIGNED_INT_ASM_OP */
455 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
456 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
458 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
459 assemble_name (FILE, SY); \
461 assemble_name (FILE, HI); \
463 assemble_name (FILE, LO); \
466 #endif /* SET_ASM_OP */
468 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
469 newline is produced. When flag_debug_asm is asserted, we add commentary
470 at the end of the line, so we must avoid output of a newline here. */
471 #ifndef ASM_OUTPUT_DWARF_STRING
472 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
474 register int slen = strlen(P); \
475 register const char *p = (P); \
477 fprintf (FILE, "\t.ascii \""); \
478 for (i = 0; i < slen; i++) \
480 register int c = p[i]; \
481 if (c == '\"' || c == '\\') \
487 fprintf (FILE, "\\%o", c); \
490 fprintf (FILE, "\\0\""); \
495 /* The DWARF 2 CFA column which tracks the return address. Normally this
496 is the column for PC, or the first column after all of the hard
498 #ifndef DWARF_FRAME_RETURN_COLUMN
500 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
502 #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER
506 /* The mapping from gcc register number to DWARF 2 CFA column number. By
507 default, we just provide columns for all registers. */
508 #ifndef DWARF_FRAME_REGNUM
509 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
512 /* Hook used by __throw. */
515 expand_builtin_dwarf_fp_regnum ()
517 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
520 /* The offset from the incoming value of %sp to the top of the stack frame
521 for the current function. */
522 #ifndef INCOMING_FRAME_SP_OFFSET
523 #define INCOMING_FRAME_SP_OFFSET 0
526 /* Return a pointer to a copy of the section string name S with all
527 attributes stripped off, and an asterisk prepended (for assemble_name). */
533 char *stripped = xmalloc (strlen (s) + 2);
538 while (*s && *s != ',')
545 /* Return the register number described by a given RTL node. */
551 register unsigned regno = REGNO (rtl);
553 if (regno >= FIRST_PSEUDO_REGISTER)
555 warning ("internal regno botch: regno = %d\n", regno);
559 regno = DBX_REGISTER_NUMBER (regno);
563 /* Generate code to initialize the register size table. */
566 expand_builtin_init_dwarf_reg_sizes (address)
570 enum machine_mode mode = TYPE_MODE (char_type_node);
571 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
572 rtx mem = gen_rtx_MEM (mode, addr);
574 for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
576 int offset = i * GET_MODE_SIZE (mode);
577 int size = GET_MODE_SIZE (reg_raw_mode[i]);
579 emit_move_insn (change_address (mem, mode,
580 plus_constant (addr, offset)),
585 /* Convert a DWARF call frame info. operation to its string name */
588 dwarf_cfi_name (cfi_opc)
589 register unsigned cfi_opc;
593 case DW_CFA_advance_loc:
594 return "DW_CFA_advance_loc";
596 return "DW_CFA_offset";
598 return "DW_CFA_restore";
602 return "DW_CFA_set_loc";
603 case DW_CFA_advance_loc1:
604 return "DW_CFA_advance_loc1";
605 case DW_CFA_advance_loc2:
606 return "DW_CFA_advance_loc2";
607 case DW_CFA_advance_loc4:
608 return "DW_CFA_advance_loc4";
609 case DW_CFA_offset_extended:
610 return "DW_CFA_offset_extended";
611 case DW_CFA_restore_extended:
612 return "DW_CFA_restore_extended";
613 case DW_CFA_undefined:
614 return "DW_CFA_undefined";
615 case DW_CFA_same_value:
616 return "DW_CFA_same_value";
617 case DW_CFA_register:
618 return "DW_CFA_register";
619 case DW_CFA_remember_state:
620 return "DW_CFA_remember_state";
621 case DW_CFA_restore_state:
622 return "DW_CFA_restore_state";
624 return "DW_CFA_def_cfa";
625 case DW_CFA_def_cfa_register:
626 return "DW_CFA_def_cfa_register";
627 case DW_CFA_def_cfa_offset:
628 return "DW_CFA_def_cfa_offset";
630 /* SGI/MIPS specific */
631 case DW_CFA_MIPS_advance_loc8:
632 return "DW_CFA_MIPS_advance_loc8";
635 case DW_CFA_GNU_window_save:
636 return "DW_CFA_GNU_window_save";
637 case DW_CFA_GNU_args_size:
638 return "DW_CFA_GNU_args_size";
641 return "DW_CFA_<unknown>";
645 /* Return a pointer to a newly allocated Call Frame Instruction. */
647 static inline dw_cfi_ref
650 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
652 cfi->dw_cfi_next = NULL;
653 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
654 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
659 /* Add a Call Frame Instruction to list of instructions. */
662 add_cfi (list_head, cfi)
663 register dw_cfi_ref *list_head;
664 register dw_cfi_ref cfi;
666 register dw_cfi_ref *p;
668 /* Find the end of the chain. */
669 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
675 /* Generate a new label for the CFI info to refer to. */
678 dwarf2out_cfi_label ()
680 static char label[20];
681 static unsigned long label_num = 0;
683 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
684 ASM_OUTPUT_LABEL (asm_out_file, label);
689 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
690 or to the CIE if LABEL is NULL. */
693 add_fde_cfi (label, cfi)
694 register char *label;
695 register dw_cfi_ref cfi;
699 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
702 label = dwarf2out_cfi_label ();
704 if (fde->dw_fde_current_label == NULL
705 || strcmp (label, fde->dw_fde_current_label) != 0)
707 register dw_cfi_ref xcfi;
709 fde->dw_fde_current_label = label = xstrdup (label);
711 /* Set the location counter to the new label. */
713 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
714 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
715 add_cfi (&fde->dw_fde_cfi, xcfi);
718 add_cfi (&fde->dw_fde_cfi, cfi);
722 add_cfi (&cie_cfi_head, cfi);
725 /* Subroutine of lookup_cfa. */
728 lookup_cfa_1 (cfi, regp, offsetp)
729 register dw_cfi_ref cfi;
730 register unsigned long *regp;
731 register long *offsetp;
733 switch (cfi->dw_cfi_opc)
735 case DW_CFA_def_cfa_offset:
736 *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
738 case DW_CFA_def_cfa_register:
739 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
742 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
743 *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
750 /* Find the previous value for the CFA. */
753 lookup_cfa (regp, offsetp)
754 register unsigned long *regp;
755 register long *offsetp;
757 register dw_cfi_ref cfi;
759 *regp = (unsigned long) -1;
762 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
763 lookup_cfa_1 (cfi, regp, offsetp);
765 if (fde_table_in_use)
767 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
768 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
769 lookup_cfa_1 (cfi, regp, offsetp);
773 /* The current rule for calculating the DWARF2 canonical frame address. */
774 static unsigned long cfa_reg;
775 static long cfa_offset;
777 /* The register used for saving registers to the stack, and its offset
779 static unsigned cfa_store_reg;
780 static long cfa_store_offset;
782 /* The running total of the size of arguments pushed onto the stack. */
783 static long args_size;
785 /* The last args_size we actually output. */
786 static long old_args_size;
788 /* Entry point to update the canonical frame address (CFA).
789 LABEL is passed to add_fde_cfi. The value of CFA is now to be
790 calculated from REG+OFFSET. */
793 dwarf2out_def_cfa (label, reg, offset)
794 register char *label;
795 register unsigned reg;
796 register long offset;
798 register dw_cfi_ref cfi;
799 unsigned long old_reg;
804 if (cfa_store_reg == reg)
805 cfa_store_offset = offset;
807 reg = DWARF_FRAME_REGNUM (reg);
808 lookup_cfa (&old_reg, &old_offset);
810 if (reg == old_reg && offset == old_offset)
817 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
818 cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
821 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
822 else if (offset == old_offset && old_reg != (unsigned long) -1)
824 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
825 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
831 cfi->dw_cfi_opc = DW_CFA_def_cfa;
832 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
833 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
836 add_fde_cfi (label, cfi);
839 /* Add the CFI for saving a register. REG is the CFA column number.
840 LABEL is passed to add_fde_cfi.
841 If SREG is -1, the register is saved at OFFSET from the CFA;
842 otherwise it is saved in SREG. */
845 reg_save (label, reg, sreg, offset)
846 register char * label;
847 register unsigned reg;
848 register unsigned sreg;
849 register long offset;
851 register dw_cfi_ref cfi = new_cfi ();
853 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
855 /* The following comparison is correct. -1 is used to indicate that
856 the value isn't a register number. */
857 if (sreg == (unsigned int) -1)
860 /* The register number won't fit in 6 bits, so we have to use
862 cfi->dw_cfi_opc = DW_CFA_offset_extended;
864 cfi->dw_cfi_opc = DW_CFA_offset;
866 offset /= DWARF_CIE_DATA_ALIGNMENT;
869 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
873 cfi->dw_cfi_opc = DW_CFA_register;
874 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
877 add_fde_cfi (label, cfi);
880 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
881 This CFI tells the unwinder that it needs to restore the window registers
882 from the previous frame's window save area.
884 ??? Perhaps we should note in the CIE where windows are saved (instead of
885 assuming 0(cfa)) and what registers are in the window. */
888 dwarf2out_window_save (label)
889 register char * label;
891 register dw_cfi_ref cfi = new_cfi ();
892 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
893 add_fde_cfi (label, cfi);
896 /* Add a CFI to update the running total of the size of arguments
897 pushed onto the stack. */
900 dwarf2out_args_size (label, size)
904 register dw_cfi_ref cfi;
906 if (size == old_args_size)
908 old_args_size = size;
911 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
912 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
913 add_fde_cfi (label, cfi);
916 /* Entry point for saving a register to the stack. REG is the GCC register
917 number. LABEL and OFFSET are passed to reg_save. */
920 dwarf2out_reg_save (label, reg, offset)
921 register char * label;
922 register unsigned reg;
923 register long offset;
925 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
928 /* Entry point for saving the return address in the stack.
929 LABEL and OFFSET are passed to reg_save. */
932 dwarf2out_return_save (label, offset)
933 register char * label;
934 register long offset;
936 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
939 /* Entry point for saving the return address in a register.
940 LABEL and SREG are passed to reg_save. */
943 dwarf2out_return_reg (label, sreg)
944 register char * label;
945 register unsigned sreg;
947 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
950 /* Record the initial position of the return address. RTL is
951 INCOMING_RETURN_ADDR_RTX. */
954 initial_return_save (rtl)
957 unsigned int reg = (unsigned int) -1;
960 switch (GET_CODE (rtl))
963 /* RA is in a register. */
964 reg = reg_number (rtl);
967 /* RA is on the stack. */
969 switch (GET_CODE (rtl))
972 if (REGNO (rtl) != STACK_POINTER_REGNUM)
977 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
979 offset = INTVAL (XEXP (rtl, 1));
982 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
984 offset = -INTVAL (XEXP (rtl, 1));
991 /* The return address is at some offset from any value we can
992 actually load. For instance, on the SPARC it is in %i7+8. Just
993 ignore the offset for now; it doesn't matter for unwinding frames. */
994 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
996 initial_return_save (XEXP (rtl, 0));
1002 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset);
1005 /* Check INSN to see if it looks like a push or a stack adjustment, and
1006 make a note of it if it does. EH uses this information to find out how
1007 much extra space it needs to pop off the stack. */
1010 dwarf2out_stack_adjust (insn)
1016 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1018 /* Extract the size of the args from the CALL rtx itself. */
1020 insn = PATTERN (insn);
1021 if (GET_CODE (insn) == PARALLEL)
1022 insn = XVECEXP (insn, 0, 0);
1023 if (GET_CODE (insn) == SET)
1024 insn = SET_SRC (insn);
1025 assert (GET_CODE (insn) == CALL);
1026 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1030 /* If only calls can throw, and we have a frame pointer,
1031 save up adjustments until we see the CALL_INSN. */
1032 else if (! asynchronous_exceptions
1033 && cfa_reg != STACK_POINTER_REGNUM)
1036 if (GET_CODE (insn) == BARRIER)
1038 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1039 the compiler will have already emitted a stack adjustment, but
1040 doesn't bother for calls to noreturn functions. */
1041 #ifdef STACK_GROWS_DOWNWARD
1042 offset = -args_size;
1047 else if (GET_CODE (PATTERN (insn)) == SET)
1052 insn = PATTERN (insn);
1053 src = SET_SRC (insn);
1054 dest = SET_DEST (insn);
1056 if (dest == stack_pointer_rtx)
1058 /* (set (reg sp) (plus (reg sp) (const_int))) */
1059 code = GET_CODE (src);
1060 if (! (code == PLUS || code == MINUS)
1061 || XEXP (src, 0) != stack_pointer_rtx
1062 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1065 offset = INTVAL (XEXP (src, 1));
1067 else if (GET_CODE (dest) == MEM)
1069 /* (set (mem (pre_dec (reg sp))) (foo)) */
1070 src = XEXP (dest, 0);
1071 code = GET_CODE (src);
1073 if (! (code == PRE_DEC || code == PRE_INC)
1074 || XEXP (src, 0) != stack_pointer_rtx)
1077 offset = GET_MODE_SIZE (GET_MODE (dest));
1082 if (code == PLUS || code == PRE_INC)
1091 if (cfa_reg == STACK_POINTER_REGNUM)
1092 cfa_offset += offset;
1094 #ifndef STACK_GROWS_DOWNWARD
1097 args_size += offset;
1101 label = dwarf2out_cfi_label ();
1102 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1103 dwarf2out_args_size (label, args_size);
1106 /* A temporary register used in adjusting SP or setting up the store_reg. */
1107 static unsigned cfa_temp_reg;
1109 /* A temporary value used in adjusting SP or setting up the store_reg. */
1110 static long cfa_temp_value;
1112 /* Record call frame debugging information for an expression, which either
1113 sets SP or FP (adjusting how we calculate the frame address) or saves a
1114 register to the stack. */
1117 dwarf2out_frame_debug_expr (expr, label)
1124 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1125 the PARALLEL independantly. The first element is always processed if
1126 it is a SET. This is for backward compatability. Other elements
1127 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1128 flag is set in them. */
1130 if (GET_CODE (expr) == PARALLEL)
1133 int limit = XVECLEN (expr, 0);
1135 for (par_index = 0; par_index < limit; par_index++)
1137 rtx x = XVECEXP (expr, 0, par_index);
1139 if (GET_CODE (x) == SET &&
1140 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1141 dwarf2out_frame_debug_expr (x, label);
1146 if (GET_CODE (expr) != SET)
1149 src = SET_SRC (expr);
1150 dest = SET_DEST (expr);
1152 switch (GET_CODE (dest))
1155 /* Update the CFA rule wrt SP or FP. Make sure src is
1156 relative to the current CFA register. */
1157 switch (GET_CODE (src))
1159 /* Setting FP from SP. */
1161 if (cfa_reg != (unsigned) REGNO (src))
1163 if (REGNO (dest) != STACK_POINTER_REGNUM
1164 && !(frame_pointer_needed
1165 && REGNO (dest) == HARD_FRAME_POINTER_REGNUM))
1167 cfa_reg = REGNO (dest);
1172 if (dest == stack_pointer_rtx)
1175 switch (GET_CODE (XEXP (src, 1)))
1178 offset = INTVAL (XEXP (src, 1));
1181 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1183 offset = cfa_temp_value;
1189 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1191 /* Restoring SP from FP in the epilogue. */
1192 if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1194 cfa_reg = STACK_POINTER_REGNUM;
1196 else if (XEXP (src, 0) != stack_pointer_rtx)
1199 if (GET_CODE (src) == PLUS)
1201 if (cfa_reg == STACK_POINTER_REGNUM)
1202 cfa_offset += offset;
1203 if (cfa_store_reg == STACK_POINTER_REGNUM)
1204 cfa_store_offset += offset;
1206 else if (dest == hard_frame_pointer_rtx)
1208 /* Either setting the FP from an offset of the SP,
1209 or adjusting the FP */
1210 if (! frame_pointer_needed
1211 || REGNO (dest) != HARD_FRAME_POINTER_REGNUM)
1214 if (XEXP (src, 0) == stack_pointer_rtx
1215 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1217 if (cfa_reg != STACK_POINTER_REGNUM)
1219 offset = INTVAL (XEXP (src, 1));
1220 if (GET_CODE (src) == PLUS)
1222 cfa_offset += offset;
1223 cfa_reg = HARD_FRAME_POINTER_REGNUM;
1225 else if (XEXP (src, 0) == hard_frame_pointer_rtx
1226 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1228 if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1230 offset = INTVAL (XEXP (src, 1));
1231 if (GET_CODE (src) == PLUS)
1233 cfa_offset += offset;
1241 if (GET_CODE (src) != PLUS
1242 || XEXP (src, 1) != stack_pointer_rtx)
1244 if (GET_CODE (XEXP (src, 0)) != REG
1245 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1247 if (cfa_reg != STACK_POINTER_REGNUM)
1249 cfa_store_reg = REGNO (dest);
1250 cfa_store_offset = cfa_offset - cfa_temp_value;
1255 cfa_temp_reg = REGNO (dest);
1256 cfa_temp_value = INTVAL (src);
1260 if (GET_CODE (XEXP (src, 0)) != REG
1261 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1262 || (unsigned) REGNO (dest) != cfa_temp_reg
1263 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1265 cfa_temp_value |= INTVAL (XEXP (src, 1));
1271 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1275 /* Saving a register to the stack. Make sure dest is relative to the
1277 if (GET_CODE (src) != REG)
1279 switch (GET_CODE (XEXP (dest, 0)))
1284 offset = GET_MODE_SIZE (GET_MODE (dest));
1285 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1288 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1289 || cfa_store_reg != STACK_POINTER_REGNUM)
1291 cfa_store_offset += offset;
1292 if (cfa_reg == STACK_POINTER_REGNUM)
1293 cfa_offset = cfa_store_offset;
1295 offset = -cfa_store_offset;
1298 /* With an offset. */
1301 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1302 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1305 if (cfa_store_reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1307 offset -= cfa_store_offset;
1310 /* Without an offset. */
1312 if (cfa_store_reg != (unsigned) REGNO (XEXP (dest, 0)))
1314 offset = -cfa_store_offset;
1320 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1321 dwarf2out_reg_save (label, REGNO (src), offset);
1330 /* Record call frame debugging information for INSN, which either
1331 sets SP or FP (adjusting how we calculate the frame address) or saves a
1332 register to the stack. If INSN is NULL_RTX, initialize our state. */
1335 dwarf2out_frame_debug (insn)
1341 if (insn == NULL_RTX)
1343 /* Set up state for generating call frame debug info. */
1344 lookup_cfa (&cfa_reg, &cfa_offset);
1345 if (cfa_reg != DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1347 cfa_reg = STACK_POINTER_REGNUM;
1348 cfa_store_reg = cfa_reg;
1349 cfa_store_offset = cfa_offset;
1355 if (! RTX_FRAME_RELATED_P (insn))
1357 dwarf2out_stack_adjust (insn);
1361 label = dwarf2out_cfi_label ();
1363 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1365 insn = XEXP (src, 0);
1367 insn = PATTERN (insn);
1369 dwarf2out_frame_debug_expr (insn, label);
1372 /* Return the size of an unsigned LEB128 quantity. */
1374 static inline unsigned long
1375 size_of_uleb128 (value)
1376 register unsigned long value;
1378 register unsigned long size = 0;
1379 register unsigned byte;
1383 byte = (value & 0x7f);
1392 /* Return the size of a signed LEB128 quantity. */
1394 static inline unsigned long
1395 size_of_sleb128 (value)
1396 register long value;
1398 register unsigned long size = 0;
1399 register unsigned byte;
1403 byte = (value & 0x7f);
1407 while (!(((value == 0) && ((byte & 0x40) == 0))
1408 || ((value == -1) && ((byte & 0x40) != 0))));
1413 /* Output an unsigned LEB128 quantity. */
1416 output_uleb128 (value)
1417 register unsigned long value;
1419 unsigned long save_value = value;
1421 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1424 register unsigned byte = (value & 0x7f);
1427 /* More bytes to follow. */
1430 fprintf (asm_out_file, "0x%x", byte);
1432 fprintf (asm_out_file, ",");
1437 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1440 /* Output an signed LEB128 quantity. */
1443 output_sleb128 (value)
1444 register long value;
1447 register unsigned byte;
1448 long save_value = value;
1450 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1453 byte = (value & 0x7f);
1454 /* arithmetic shift */
1456 more = !((((value == 0) && ((byte & 0x40) == 0))
1457 || ((value == -1) && ((byte & 0x40) != 0))));
1461 fprintf (asm_out_file, "0x%x", byte);
1463 fprintf (asm_out_file, ",");
1468 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1471 /* Output a Call Frame Information opcode and its operand(s). */
1474 output_cfi (cfi, fde)
1475 register dw_cfi_ref cfi;
1476 register dw_fde_ref fde;
1478 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1480 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1482 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1484 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1485 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1486 fputc ('\n', asm_out_file);
1489 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1491 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1493 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1495 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1496 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1498 fputc ('\n', asm_out_file);
1499 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1500 fputc ('\n', asm_out_file);
1502 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1504 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1506 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1508 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1509 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1511 fputc ('\n', asm_out_file);
1515 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1517 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1518 dwarf_cfi_name (cfi->dw_cfi_opc));
1520 fputc ('\n', asm_out_file);
1521 switch (cfi->dw_cfi_opc)
1523 case DW_CFA_set_loc:
1524 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1525 fputc ('\n', asm_out_file);
1527 case DW_CFA_advance_loc1:
1528 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1529 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1530 fde->dw_fde_current_label);
1531 fputc ('\n', asm_out_file);
1532 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1534 case DW_CFA_advance_loc2:
1535 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1536 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1537 fde->dw_fde_current_label);
1538 fputc ('\n', asm_out_file);
1539 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1541 case DW_CFA_advance_loc4:
1542 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1543 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1544 fde->dw_fde_current_label);
1545 fputc ('\n', asm_out_file);
1546 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1548 #ifdef MIPS_DEBUGGING_INFO
1549 case DW_CFA_MIPS_advance_loc8:
1550 /* TODO: not currently implemented. */
1554 case DW_CFA_offset_extended:
1555 case DW_CFA_def_cfa:
1556 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1557 fputc ('\n', asm_out_file);
1558 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1559 fputc ('\n', asm_out_file);
1561 case DW_CFA_restore_extended:
1562 case DW_CFA_undefined:
1563 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1564 fputc ('\n', asm_out_file);
1566 case DW_CFA_same_value:
1567 case DW_CFA_def_cfa_register:
1568 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1569 fputc ('\n', asm_out_file);
1571 case DW_CFA_register:
1572 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1573 fputc ('\n', asm_out_file);
1574 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1575 fputc ('\n', asm_out_file);
1577 case DW_CFA_def_cfa_offset:
1578 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1579 fputc ('\n', asm_out_file);
1581 case DW_CFA_GNU_window_save:
1583 case DW_CFA_GNU_args_size:
1584 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1585 fputc ('\n', asm_out_file);
1593 /* Output the call frame information used to used to record information
1594 that relates to calculating the frame pointer, and records the
1595 location of saved registers. */
1598 output_call_frame_info (for_eh)
1601 register unsigned long i;
1602 register dw_fde_ref fde;
1603 register dw_cfi_ref cfi;
1604 char l1[20], l2[20];
1605 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1609 /* Do we want to include a pointer to the exception table? */
1610 int eh_ptr = for_eh && exception_table_p ();
1612 fputc ('\n', asm_out_file);
1614 /* We're going to be generating comments, so turn on app. */
1620 #ifdef EH_FRAME_SECTION
1621 EH_FRAME_SECTION ();
1623 tree label = get_file_function_name ('F');
1625 force_data_section ();
1626 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1627 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1628 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1630 assemble_label ("__FRAME_BEGIN__");
1633 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1635 /* Output the CIE. */
1636 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1637 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1638 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1639 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1641 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1643 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1646 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1648 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1651 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1654 fputc ('\n', asm_out_file);
1655 ASM_OUTPUT_LABEL (asm_out_file, l1);
1658 /* Now that the CIE pointer is PC-relative for EH,
1659 use 0 to identify the CIE. */
1660 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1662 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1665 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1667 fputc ('\n', asm_out_file);
1668 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1670 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1671 fputc ('\n', asm_out_file);
1674 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1676 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1678 fputc ('\n', asm_out_file);
1681 /* The CIE contains a pointer to the exception region info for the
1682 frame. Make the augmentation string three bytes (including the
1683 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1684 can't handle unaligned relocs. */
1687 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1688 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1692 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1694 fputc ('\n', asm_out_file);
1696 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1698 fprintf (asm_out_file, "\t%s pointer to exception region info",
1703 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1705 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1709 fputc ('\n', asm_out_file);
1712 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1714 fputc ('\n', asm_out_file);
1715 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1717 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1719 fputc ('\n', asm_out_file);
1720 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1722 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1724 fputc ('\n', asm_out_file);
1726 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1727 output_cfi (cfi, NULL);
1729 /* Pad the CIE out to an address sized boundary. */
1730 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1731 ASM_OUTPUT_LABEL (asm_out_file, l2);
1732 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1733 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1735 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1736 fputc ('\n', asm_out_file);
1739 /* Loop through all of the FDE's. */
1740 for (i = 0; i < fde_table_in_use; ++i)
1742 fde = &fde_table[i];
1744 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2);
1745 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2);
1746 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1747 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2);
1749 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1751 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1754 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1756 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1759 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1760 fputc ('\n', asm_out_file);
1761 ASM_OUTPUT_LABEL (asm_out_file, l1);
1763 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1764 emits a target dependent sized offset when for_eh is not true.
1765 This inconsistency may confuse gdb. The only case where we need a
1766 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1767 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1768 though in order to be compatible with the dwarf_fde struct in frame.c.
1769 If the for_eh case is changed, then the struct in frame.c has
1770 to be adjusted appropriately. */
1772 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1774 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1776 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1778 fputc ('\n', asm_out_file);
1779 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1781 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1783 fputc ('\n', asm_out_file);
1784 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1785 fde->dw_fde_end, fde->dw_fde_begin);
1787 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1789 fputc ('\n', asm_out_file);
1791 /* Loop through the Call Frame Instructions associated with
1793 fde->dw_fde_current_label = fde->dw_fde_begin;
1794 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1795 output_cfi (cfi, fde);
1797 /* Pad the FDE out to an address sized boundary. */
1798 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1799 ASM_OUTPUT_LABEL (asm_out_file, l2);
1800 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1801 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1803 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1804 fputc ('\n', asm_out_file);
1807 #ifndef EH_FRAME_SECTION
1810 /* Emit terminating zero for table. */
1811 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1812 fputc ('\n', asm_out_file);
1815 #ifdef MIPS_DEBUGGING_INFO
1816 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1817 get a value of 0. Putting .align 0 after the label fixes it. */
1818 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1821 /* Turn off app to make assembly quicker. */
1826 /* Output a marker (i.e. a label) for the beginning of a function, before
1830 dwarf2out_begin_prologue ()
1832 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1833 register dw_fde_ref fde;
1835 ++current_funcdef_number;
1837 function_section (current_function_decl);
1838 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1839 current_funcdef_number);
1840 ASM_OUTPUT_LABEL (asm_out_file, label);
1842 /* Expand the fde table if necessary. */
1843 if (fde_table_in_use == fde_table_allocated)
1845 fde_table_allocated += FDE_TABLE_INCREMENT;
1847 = (dw_fde_ref) xrealloc (fde_table,
1848 fde_table_allocated * sizeof (dw_fde_node));
1851 /* Record the FDE associated with this function. */
1852 current_funcdef_fde = fde_table_in_use;
1854 /* Add the new FDE at the end of the fde_table. */
1855 fde = &fde_table[fde_table_in_use++];
1856 fde->dw_fde_begin = xstrdup (label);
1857 fde->dw_fde_current_label = NULL;
1858 fde->dw_fde_end = NULL;
1859 fde->dw_fde_cfi = NULL;
1861 args_size = old_args_size = 0;
1864 /* Output a marker (i.e. a label) for the absolute end of the generated code
1865 for a function definition. This gets called *after* the epilogue code has
1869 dwarf2out_end_epilogue ()
1872 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1874 /* Output a label to mark the endpoint of the code generated for this
1876 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1877 ASM_OUTPUT_LABEL (asm_out_file, label);
1878 fde = &fde_table[fde_table_in_use - 1];
1879 fde->dw_fde_end = xstrdup (label);
1883 dwarf2out_frame_init ()
1885 /* Allocate the initial hunk of the fde_table. */
1886 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
1887 fde_table_allocated = FDE_TABLE_INCREMENT;
1888 fde_table_in_use = 0;
1890 /* Generate the CFA instructions common to all FDE's. Do it now for the
1891 sake of lookup_cfa. */
1893 #ifdef DWARF2_UNWIND_INFO
1894 /* On entry, the Canonical Frame Address is at SP. */
1895 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1896 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1901 dwarf2out_frame_finish ()
1903 /* Output call frame information. */
1904 #ifdef MIPS_DEBUGGING_INFO
1905 if (write_symbols == DWARF2_DEBUG)
1906 output_call_frame_info (0);
1907 if (flag_exceptions && ! exceptions_via_longjmp)
1908 output_call_frame_info (1);
1910 if (write_symbols == DWARF2_DEBUG
1911 || (flag_exceptions && ! exceptions_via_longjmp))
1912 output_call_frame_info (1);
1916 #endif /* .debug_frame support */
1918 /* And now, the support for symbolic debugging information. */
1919 #ifdef DWARF2_DEBUGGING_INFO
1921 /* NOTE: In the comments in this file, many references are made to
1922 "Debugging Information Entries". This term is abbreviated as `DIE'
1923 throughout the remainder of this file. */
1925 /* An internal representation of the DWARF output is built, and then
1926 walked to generate the DWARF debugging info. The walk of the internal
1927 representation is done after the entire program has been compiled.
1928 The types below are used to describe the internal representation. */
1930 /* Each DIE may have a series of attribute/value pairs. Values
1931 can take on several forms. The forms that are used in this
1932 implementation are listed below. */
1939 dw_val_class_unsigned_const,
1940 dw_val_class_long_long,
1943 dw_val_class_die_ref,
1944 dw_val_class_fde_ref,
1945 dw_val_class_lbl_id,
1946 dw_val_class_lbl_offset,
1951 /* Various DIE's use offsets relative to the beginning of the
1952 .debug_info section to refer to each other. */
1954 typedef long int dw_offset;
1956 /* Define typedefs here to avoid circular dependencies. */
1958 typedef struct die_struct *dw_die_ref;
1959 typedef struct dw_attr_struct *dw_attr_ref;
1960 typedef struct dw_val_struct *dw_val_ref;
1961 typedef struct dw_line_info_struct *dw_line_info_ref;
1962 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
1963 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1964 typedef struct pubname_struct *pubname_ref;
1965 typedef dw_die_ref *arange_ref;
1967 /* Describe a double word constant value. */
1969 typedef struct dw_long_long_struct
1976 /* Describe a floating point constant value. */
1978 typedef struct dw_fp_struct
1985 /* Each entry in the line_info_table maintains the file and
1986 line number associated with the label generated for that
1987 entry. The label gives the PC value associated with
1988 the line number entry. */
1990 typedef struct dw_line_info_struct
1992 unsigned long dw_file_num;
1993 unsigned long dw_line_num;
1997 /* Line information for functions in separate sections; each one gets its
1999 typedef struct dw_separate_line_info_struct
2001 unsigned long dw_file_num;
2002 unsigned long dw_line_num;
2003 unsigned long function;
2005 dw_separate_line_info_entry;
2007 /* The dw_val_node describes an attribute's value, as it is
2008 represented internally. */
2010 typedef struct dw_val_struct
2012 dw_val_class val_class;
2016 dw_loc_descr_ref val_loc;
2018 long unsigned val_unsigned;
2019 dw_long_long_const val_long_long;
2020 dw_float_const val_float;
2021 dw_die_ref val_die_ref;
2022 unsigned val_fde_index;
2025 unsigned char val_flag;
2031 /* Locations in memory are described using a sequence of stack machine
2034 typedef struct dw_loc_descr_struct
2036 dw_loc_descr_ref dw_loc_next;
2037 enum dwarf_location_atom dw_loc_opc;
2038 dw_val_node dw_loc_oprnd1;
2039 dw_val_node dw_loc_oprnd2;
2043 /* Each DIE attribute has a field specifying the attribute kind,
2044 a link to the next attribute in the chain, and an attribute value.
2045 Attributes are typically linked below the DIE they modify. */
2047 typedef struct dw_attr_struct
2049 enum dwarf_attribute dw_attr;
2050 dw_attr_ref dw_attr_next;
2051 dw_val_node dw_attr_val;
2055 /* The Debugging Information Entry (DIE) structure */
2057 typedef struct die_struct
2059 enum dwarf_tag die_tag;
2060 dw_attr_ref die_attr;
2061 dw_attr_ref die_attr_last;
2062 dw_die_ref die_parent;
2063 dw_die_ref die_child;
2064 dw_die_ref die_child_last;
2066 dw_offset die_offset;
2067 unsigned long die_abbrev;
2071 /* The pubname structure */
2073 typedef struct pubname_struct
2080 /* The limbo die list structure. */
2081 typedef struct limbo_die_struct
2084 struct limbo_die_struct *next;
2088 /* How to start an assembler comment. */
2089 #ifndef ASM_COMMENT_START
2090 #define ASM_COMMENT_START ";#"
2093 /* Define a macro which returns non-zero for a TYPE_DECL which was
2094 implicitly generated for a tagged type.
2096 Note that unlike the gcc front end (which generates a NULL named
2097 TYPE_DECL node for each complete tagged type, each array type, and
2098 each function type node created) the g++ front end generates a
2099 _named_ TYPE_DECL node for each tagged type node created.
2100 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2101 generate a DW_TAG_typedef DIE for them. */
2103 #define TYPE_DECL_IS_STUB(decl) \
2104 (DECL_NAME (decl) == NULL_TREE \
2105 || (DECL_ARTIFICIAL (decl) \
2106 && is_tagged_type (TREE_TYPE (decl)) \
2107 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2108 /* This is necessary for stub decls that \
2109 appear in nested inline functions. */ \
2110 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2111 && (decl_ultimate_origin (decl) \
2112 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2114 /* Information concerning the compilation unit's programming
2115 language, and compiler version. */
2117 extern int flag_traditional;
2118 extern char *version_string;
2120 /* Fixed size portion of the DWARF compilation unit header. */
2121 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2123 /* Fixed size portion of debugging line information prolog. */
2124 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2126 /* Fixed size portion of public names info. */
2127 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2129 /* Fixed size portion of the address range info. */
2130 #define DWARF_ARANGES_HEADER_SIZE \
2131 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
2133 /* The default is to have gcc emit the line number tables. */
2134 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2135 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2138 /* Define the architecture-dependent minimum instruction length (in bytes).
2139 In this implementation of DWARF, this field is used for information
2140 purposes only. Since GCC generates assembly language, we have
2141 no a priori knowledge of how many instruction bytes are generated
2142 for each source line, and therefore can use only the DW_LNE_set_address
2143 and DW_LNS_fixed_advance_pc line information commands. */
2145 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2146 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2149 /* Minimum line offset in a special line info. opcode.
2150 This value was chosen to give a reasonable range of values. */
2151 #define DWARF_LINE_BASE -10
2153 /* First special line opcde - leave room for the standard opcodes. */
2154 #define DWARF_LINE_OPCODE_BASE 10
2156 /* Range of line offsets in a special line info. opcode. */
2157 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2159 /* Flag that indicates the initial value of the is_stmt_start flag.
2160 In the present implementation, we do not mark any lines as
2161 the beginning of a source statement, because that information
2162 is not made available by the GCC front-end. */
2163 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2165 /* This location is used by calc_die_sizes() to keep track
2166 the offset of each DIE within the .debug_info section. */
2167 static unsigned long next_die_offset;
2169 /* Record the root of the DIE's built for the current compilation unit. */
2170 static dw_die_ref comp_unit_die;
2172 /* A list of DIEs with a NULL parent waiting to be relocated. */
2173 static limbo_die_node *limbo_die_list = 0;
2175 /* Pointer to an array of filenames referenced by this compilation unit. */
2176 static char **file_table;
2178 /* Total number of entries in the table (i.e. array) pointed to by
2179 `file_table'. This is the *total* and includes both used and unused
2181 static unsigned file_table_allocated;
2183 /* Number of entries in the file_table which are actually in use. */
2184 static unsigned file_table_in_use;
2186 /* Size (in elements) of increments by which we may expand the filename
2188 #define FILE_TABLE_INCREMENT 64
2190 /* Local pointer to the name of the main input file. Initialized in
2192 static char *primary_filename;
2194 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
2195 which their beginnings are encountered. We output Dwarf debugging info
2196 that refers to the beginnings and ends of the ranges of code for each
2197 lexical block. The labels themselves are generated in final.c, which
2198 assigns numbers to the blocks in the same way. */
2199 static unsigned next_block_number = 2;
2201 /* A pointer to the base of a table of references to DIE's that describe
2202 declarations. The table is indexed by DECL_UID() which is a unique
2203 number identifying each decl. */
2204 static dw_die_ref *decl_die_table;
2206 /* Number of elements currently allocated for the decl_die_table. */
2207 static unsigned decl_die_table_allocated;
2209 /* Number of elements in decl_die_table currently in use. */
2210 static unsigned decl_die_table_in_use;
2212 /* Size (in elements) of increments by which we may expand the
2214 #define DECL_DIE_TABLE_INCREMENT 256
2216 /* Structure used for the decl_scope table. scope is the current declaration
2217 scope, and previous is the entry that is the parent of this scope. This
2218 is usually but not always the immediately preceeding entry. */
2220 typedef struct decl_scope_struct
2227 /* A pointer to the base of a table of references to declaration
2228 scopes. This table is a display which tracks the nesting
2229 of declaration scopes at the current scope and containing
2230 scopes. This table is used to find the proper place to
2231 define type declaration DIE's. */
2232 static decl_scope_node *decl_scope_table;
2234 /* Number of elements currently allocated for the decl_scope_table. */
2235 static int decl_scope_table_allocated;
2237 /* Current level of nesting of declaration scopes. */
2238 static int decl_scope_depth;
2240 /* Size (in elements) of increments by which we may expand the
2241 decl_scope_table. */
2242 #define DECL_SCOPE_TABLE_INCREMENT 64
2244 /* A pointer to the base of a list of references to DIE's that
2245 are uniquely identified by their tag, presence/absence of
2246 children DIE's, and list of attribute/value pairs. */
2247 static dw_die_ref *abbrev_die_table;
2249 /* Number of elements currently allocated for abbrev_die_table. */
2250 static unsigned abbrev_die_table_allocated;
2252 /* Number of elements in type_die_table currently in use. */
2253 static unsigned abbrev_die_table_in_use;
2255 /* Size (in elements) of increments by which we may expand the
2256 abbrev_die_table. */
2257 #define ABBREV_DIE_TABLE_INCREMENT 256
2259 /* A pointer to the base of a table that contains line information
2260 for each source code line in .text in the compilation unit. */
2261 static dw_line_info_ref line_info_table;
2263 /* Number of elements currently allocated for line_info_table. */
2264 static unsigned line_info_table_allocated;
2266 /* Number of elements in separate_line_info_table currently in use. */
2267 static unsigned separate_line_info_table_in_use;
2269 /* A pointer to the base of a table that contains line information
2270 for each source code line outside of .text in the compilation unit. */
2271 static dw_separate_line_info_ref separate_line_info_table;
2273 /* Number of elements currently allocated for separate_line_info_table. */
2274 static unsigned separate_line_info_table_allocated;
2276 /* Number of elements in line_info_table currently in use. */
2277 static unsigned line_info_table_in_use;
2279 /* Size (in elements) of increments by which we may expand the
2281 #define LINE_INFO_TABLE_INCREMENT 1024
2283 /* A pointer to the base of a table that contains a list of publicly
2284 accessible names. */
2285 static pubname_ref pubname_table;
2287 /* Number of elements currently allocated for pubname_table. */
2288 static unsigned pubname_table_allocated;
2290 /* Number of elements in pubname_table currently in use. */
2291 static unsigned pubname_table_in_use;
2293 /* Size (in elements) of increments by which we may expand the
2295 #define PUBNAME_TABLE_INCREMENT 64
2297 /* A pointer to the base of a table that contains a list of publicly
2298 accessible names. */
2299 static arange_ref arange_table;
2301 /* Number of elements currently allocated for arange_table. */
2302 static unsigned arange_table_allocated;
2304 /* Number of elements in arange_table currently in use. */
2305 static unsigned arange_table_in_use;
2307 /* Size (in elements) of increments by which we may expand the
2309 #define ARANGE_TABLE_INCREMENT 64
2311 /* A pointer to the base of a list of pending types which we haven't
2312 generated DIEs for yet, but which we will have to come back to
2315 static tree *pending_types_list;
2317 /* Number of elements currently allocated for the pending_types_list. */
2318 static unsigned pending_types_allocated;
2320 /* Number of elements of pending_types_list currently in use. */
2321 static unsigned pending_types;
2323 /* Size (in elements) of increments by which we may expand the pending
2324 types list. Actually, a single hunk of space of this size should
2325 be enough for most typical programs. */
2326 #define PENDING_TYPES_INCREMENT 64
2328 /* A pointer to the base of a list of incomplete types which might be
2329 completed at some later time. */
2331 static tree *incomplete_types_list;
2333 /* Number of elements currently allocated for the incomplete_types_list. */
2334 static unsigned incomplete_types_allocated;
2336 /* Number of elements of incomplete_types_list currently in use. */
2337 static unsigned incomplete_types;
2339 /* Size (in elements) of increments by which we may expand the incomplete
2340 types list. Actually, a single hunk of space of this size should
2341 be enough for most typical programs. */
2342 #define INCOMPLETE_TYPES_INCREMENT 64
2344 /* Record whether the function being analyzed contains inlined functions. */
2345 static int current_function_has_inlines;
2346 #if 0 && defined (MIPS_DEBUGGING_INFO)
2347 static int comp_unit_has_inlines;
2350 /* A pointer to the ..._DECL node which we have most recently been working
2351 on. We keep this around just in case something about it looks screwy and
2352 we want to tell the user what the source coordinates for the actual
2354 static tree dwarf_last_decl;
2356 /* Forward declarations for functions defined in this file. */
2358 static void addr_const_to_string PROTO((dyn_string_t, rtx));
2359 static char *addr_to_string PROTO((rtx));
2360 static int is_pseudo_reg PROTO((rtx));
2361 static tree type_main_variant PROTO((tree));
2362 static int is_tagged_type PROTO((tree));
2363 static const char *dwarf_tag_name PROTO((unsigned));
2364 static const char *dwarf_attr_name PROTO((unsigned));
2365 static const char *dwarf_form_name PROTO((unsigned));
2366 static const char *dwarf_stack_op_name PROTO((unsigned));
2368 static const char *dwarf_type_encoding_name PROTO((unsigned));
2370 static tree decl_ultimate_origin PROTO((tree));
2371 static tree block_ultimate_origin PROTO((tree));
2372 static tree decl_class_context PROTO((tree));
2373 static void add_dwarf_attr PROTO((dw_die_ref, dw_attr_ref));
2374 static void add_AT_flag PROTO((dw_die_ref,
2375 enum dwarf_attribute,
2377 static void add_AT_int PROTO((dw_die_ref,
2378 enum dwarf_attribute, long));
2379 static void add_AT_unsigned PROTO((dw_die_ref,
2380 enum dwarf_attribute,
2382 static void add_AT_long_long PROTO((dw_die_ref,
2383 enum dwarf_attribute,
2384 unsigned long, unsigned long));
2385 static void add_AT_float PROTO((dw_die_ref,
2386 enum dwarf_attribute,
2388 static void add_AT_string PROTO((dw_die_ref,
2389 enum dwarf_attribute,
2391 static void add_AT_die_ref PROTO((dw_die_ref,
2392 enum dwarf_attribute,
2394 static void add_AT_fde_ref PROTO((dw_die_ref,
2395 enum dwarf_attribute,
2397 static void add_AT_loc PROTO((dw_die_ref,
2398 enum dwarf_attribute,
2400 static void add_AT_addr PROTO((dw_die_ref,
2401 enum dwarf_attribute, char *));
2402 static void add_AT_lbl_id PROTO((dw_die_ref,
2403 enum dwarf_attribute, char *));
2404 static void add_AT_lbl_offset PROTO((dw_die_ref,
2405 enum dwarf_attribute, char *));
2406 static int is_extern_subr_die PROTO((dw_die_ref));
2407 static dw_attr_ref get_AT PROTO((dw_die_ref,
2408 enum dwarf_attribute));
2409 static char *get_AT_low_pc PROTO((dw_die_ref));
2410 static char *get_AT_hi_pc PROTO((dw_die_ref));
2411 static char *get_AT_string PROTO((dw_die_ref,
2412 enum dwarf_attribute));
2413 static int get_AT_flag PROTO((dw_die_ref,
2414 enum dwarf_attribute));
2415 static unsigned get_AT_unsigned PROTO((dw_die_ref,
2416 enum dwarf_attribute));
2417 static int is_c_family PROTO((void));
2418 static int is_fortran PROTO((void));
2419 static void remove_AT PROTO((dw_die_ref,
2420 enum dwarf_attribute));
2421 static void remove_children PROTO((dw_die_ref));
2422 static void add_child_die PROTO((dw_die_ref, dw_die_ref));
2423 static dw_die_ref new_die PROTO((enum dwarf_tag, dw_die_ref));
2424 static dw_die_ref lookup_type_die PROTO((tree));
2425 static void equate_type_number_to_die PROTO((tree, dw_die_ref));
2426 static dw_die_ref lookup_decl_die PROTO((tree));
2427 static void equate_decl_number_to_die PROTO((tree, dw_die_ref));
2428 static dw_loc_descr_ref new_loc_descr PROTO((enum dwarf_location_atom,
2429 unsigned long, unsigned long));
2430 static void add_loc_descr PROTO((dw_loc_descr_ref *,
2432 static void print_spaces PROTO((FILE *));
2433 static void print_die PROTO((dw_die_ref, FILE *));
2434 static void print_dwarf_line_table PROTO((FILE *));
2435 static void add_sibling_attributes PROTO((dw_die_ref));
2436 static void build_abbrev_table PROTO((dw_die_ref));
2437 static unsigned long size_of_string PROTO((char *));
2438 static unsigned long size_of_loc_descr PROTO((dw_loc_descr_ref));
2439 static unsigned long size_of_locs PROTO((dw_loc_descr_ref));
2440 static int constant_size PROTO((long unsigned));
2441 static unsigned long size_of_die PROTO((dw_die_ref));
2442 static void calc_die_sizes PROTO((dw_die_ref));
2443 static unsigned long size_of_line_prolog PROTO((void));
2444 static unsigned long size_of_line_info PROTO((void));
2445 static unsigned long size_of_pubnames PROTO((void));
2446 static unsigned long size_of_aranges PROTO((void));
2447 static enum dwarf_form value_format PROTO((dw_val_ref));
2448 static void output_value_format PROTO((dw_val_ref));
2449 static void output_abbrev_section PROTO((void));
2450 static void output_loc_operands PROTO((dw_loc_descr_ref));
2451 static unsigned long sibling_offset PROTO((dw_die_ref));
2452 static void output_die PROTO((dw_die_ref));
2453 static void output_compilation_unit_header PROTO((void));
2454 static const char *dwarf2_name PROTO((tree, int));
2455 static void add_pubname PROTO((tree, dw_die_ref));
2456 static void output_pubnames PROTO((void));
2457 static void add_arange PROTO((tree, dw_die_ref));
2458 static void output_aranges PROTO((void));
2459 static void output_line_info PROTO((void));
2460 static int is_body_block PROTO((tree));
2461 static dw_die_ref base_type_die PROTO((tree));
2462 static tree root_type PROTO((tree));
2463 static int is_base_type PROTO((tree));
2464 static dw_die_ref modified_type_die PROTO((tree, int, int, dw_die_ref));
2465 static int type_is_enum PROTO((tree));
2466 static dw_loc_descr_ref reg_loc_descriptor PROTO((rtx));
2467 static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long));
2468 static int is_based_loc PROTO((rtx));
2469 static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx, enum machine_mode mode));
2470 static dw_loc_descr_ref concat_loc_descriptor PROTO((rtx, rtx));
2471 static dw_loc_descr_ref loc_descriptor PROTO((rtx));
2472 static unsigned ceiling PROTO((unsigned, unsigned));
2473 static tree field_type PROTO((tree));
2474 static unsigned simple_type_align_in_bits PROTO((tree));
2475 static unsigned simple_type_size_in_bits PROTO((tree));
2476 static unsigned field_byte_offset PROTO((tree));
2477 static void add_AT_location_description PROTO((dw_die_ref,
2478 enum dwarf_attribute, rtx));
2479 static void add_data_member_location_attribute PROTO((dw_die_ref, tree));
2480 static void add_const_value_attribute PROTO((dw_die_ref, rtx));
2481 static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree));
2482 static void add_name_attribute PROTO((dw_die_ref, const char *));
2483 static void add_bound_info PROTO((dw_die_ref,
2484 enum dwarf_attribute, tree));
2485 static void add_subscript_info PROTO((dw_die_ref, tree));
2486 static void add_byte_size_attribute PROTO((dw_die_ref, tree));
2487 static void add_bit_offset_attribute PROTO((dw_die_ref, tree));
2488 static void add_bit_size_attribute PROTO((dw_die_ref, tree));
2489 static void add_prototyped_attribute PROTO((dw_die_ref, tree));
2490 static void add_abstract_origin_attribute PROTO((dw_die_ref, tree));
2491 static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree));
2492 static void add_src_coords_attributes PROTO((dw_die_ref, tree));
2493 static void add_name_and_src_coords_attributes PROTO((dw_die_ref, tree));
2494 static void push_decl_scope PROTO((tree));
2495 static dw_die_ref scope_die_for PROTO((tree, dw_die_ref));
2496 static void pop_decl_scope PROTO((void));
2497 static void add_type_attribute PROTO((dw_die_ref, tree, int, int,
2499 static char *type_tag PROTO((tree));
2500 static tree member_declared_type PROTO((tree));
2502 static char *decl_start_label PROTO((tree));
2504 static void gen_array_type_die PROTO((tree, dw_die_ref));
2505 static void gen_set_type_die PROTO((tree, dw_die_ref));
2507 static void gen_entry_point_die PROTO((tree, dw_die_ref));
2509 static void pend_type PROTO((tree));
2510 static void output_pending_types_for_scope PROTO((dw_die_ref));
2511 static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref));
2512 static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref));
2513 static void gen_inlined_union_type_die PROTO((tree, dw_die_ref));
2514 static void gen_enumeration_type_die PROTO((tree, dw_die_ref));
2515 static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref));
2516 static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref));
2517 static void gen_formal_types_die PROTO((tree, dw_die_ref));
2518 static void gen_subprogram_die PROTO((tree, dw_die_ref));
2519 static void gen_variable_die PROTO((tree, dw_die_ref));
2520 static void gen_label_die PROTO((tree, dw_die_ref));
2521 static void gen_lexical_block_die PROTO((tree, dw_die_ref, int));
2522 static void gen_inlined_subroutine_die PROTO((tree, dw_die_ref, int));
2523 static void gen_field_die PROTO((tree, dw_die_ref));
2524 static void gen_ptr_to_mbr_type_die PROTO((tree, dw_die_ref));
2525 static void gen_compile_unit_die PROTO((char *));
2526 static void gen_string_type_die PROTO((tree, dw_die_ref));
2527 static void gen_inheritance_die PROTO((tree, dw_die_ref));
2528 static void gen_member_die PROTO((tree, dw_die_ref));
2529 static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref));
2530 static void gen_subroutine_type_die PROTO((tree, dw_die_ref));
2531 static void gen_typedef_die PROTO((tree, dw_die_ref));
2532 static void gen_type_die PROTO((tree, dw_die_ref));
2533 static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref));
2534 static void gen_block_die PROTO((tree, dw_die_ref, int));
2535 static void decls_for_scope PROTO((tree, dw_die_ref, int));
2536 static int is_redundant_typedef PROTO((tree));
2537 static void gen_decl_die PROTO((tree, dw_die_ref));
2538 static unsigned lookup_filename PROTO((const char *));
2539 static void add_incomplete_type PROTO((tree));
2540 static void retry_incomplete_types PROTO((void));
2542 /* Section names used to hold DWARF debugging information. */
2543 #ifndef DEBUG_INFO_SECTION
2544 #define DEBUG_INFO_SECTION ".debug_info"
2546 #ifndef ABBREV_SECTION
2547 #define ABBREV_SECTION ".debug_abbrev"
2549 #ifndef ARANGES_SECTION
2550 #define ARANGES_SECTION ".debug_aranges"
2552 #ifndef DW_MACINFO_SECTION
2553 #define DW_MACINFO_SECTION ".debug_macinfo"
2555 #ifndef DEBUG_LINE_SECTION
2556 #define DEBUG_LINE_SECTION ".debug_line"
2559 #define LOC_SECTION ".debug_loc"
2561 #ifndef PUBNAMES_SECTION
2562 #define PUBNAMES_SECTION ".debug_pubnames"
2565 #define STR_SECTION ".debug_str"
2568 /* Standard ELF section names for compiled code and data. */
2569 #ifndef TEXT_SECTION
2570 #define TEXT_SECTION ".text"
2572 #ifndef DATA_SECTION
2573 #define DATA_SECTION ".data"
2576 #define BSS_SECTION ".bss"
2579 /* Labels we insert at beginning sections we can reference instead of
2580 the section names themselves. */
2582 #ifndef TEXT_SECTION_LABEL
2583 #define TEXT_SECTION_LABEL "Ltext"
2585 #ifndef DEBUG_LINE_SECTION_LABEL
2586 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
2588 #ifndef DEBUG_INFO_SECTION_LABEL
2589 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
2591 #ifndef ABBREV_SECTION_LABEL
2592 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
2596 /* Definitions of defaults for formats and names of various special
2597 (artificial) labels which may be generated within this file (when the -g
2598 options is used and DWARF_DEBUGGING_INFO is in effect.
2599 If necessary, these may be overridden from within the tm.h file, but
2600 typically, overriding these defaults is unnecessary. */
2602 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2603 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2604 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2605 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2606 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2608 #ifndef TEXT_END_LABEL
2609 #define TEXT_END_LABEL "Letext"
2611 #ifndef DATA_END_LABEL
2612 #define DATA_END_LABEL "Ledata"
2614 #ifndef BSS_END_LABEL
2615 #define BSS_END_LABEL "Lebss"
2617 #ifndef INSN_LABEL_FMT
2618 #define INSN_LABEL_FMT "LI%u_"
2620 #ifndef BLOCK_BEGIN_LABEL
2621 #define BLOCK_BEGIN_LABEL "LBB"
2623 #ifndef BLOCK_END_LABEL
2624 #define BLOCK_END_LABEL "LBE"
2626 #ifndef BODY_BEGIN_LABEL
2627 #define BODY_BEGIN_LABEL "Lbb"
2629 #ifndef BODY_END_LABEL
2630 #define BODY_END_LABEL "Lbe"
2632 #ifndef LINE_CODE_LABEL
2633 #define LINE_CODE_LABEL "LM"
2635 #ifndef SEPARATE_LINE_CODE_LABEL
2636 #define SEPARATE_LINE_CODE_LABEL "LSM"
2639 /* Convert a reference to the assembler name of a C-level name. This
2640 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
2641 a string rather than writing to a file. */
2642 #ifndef ASM_NAME_TO_STRING
2643 #define ASM_NAME_TO_STRING(STR, NAME) \
2645 if ((NAME)[0] == '*') \
2646 dyn_string_append (STR, NAME + 1); \
2649 const char *newstr; \
2650 STRIP_NAME_ENCODING (newstr, NAME); \
2651 dyn_string_append (STR, user_label_prefix); \
2652 dyn_string_append (STR, newstr); \
2658 /* Convert an integer constant expression into assembler syntax. Addition
2659 and subtraction are the only arithmetic that may appear in these
2660 expressions. This is an adaptation of output_addr_const in final.c.
2661 Here, the target of the conversion is a string buffer. We can't use
2662 output_addr_const directly, because it writes to a file. */
2665 addr_const_to_string (str, x)
2672 switch (GET_CODE (x))
2676 dyn_string_append (str, ",");
2682 ASM_NAME_TO_STRING (str, XSTR (x, 0));
2686 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2687 ASM_NAME_TO_STRING (str, buf1);
2691 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
2692 ASM_NAME_TO_STRING (str, buf1);
2696 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
2697 dyn_string_append (str, buf1);
2701 /* This used to output parentheses around the expression, but that does
2702 not work on the 386 (either ATT or BSD assembler). */
2703 addr_const_to_string (str, XEXP (x, 0));
2707 if (GET_MODE (x) == VOIDmode)
2709 /* We can use %d if the number is one word and positive. */
2710 if (CONST_DOUBLE_HIGH (x))
2711 sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
2712 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2713 else if (CONST_DOUBLE_LOW (x) < 0)
2714 sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
2716 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
2717 CONST_DOUBLE_LOW (x));
2718 dyn_string_append (str, buf1);
2721 /* We can't handle floating point constants; PRINT_OPERAND must
2723 output_operand_lossage ("floating constant misused");
2727 /* Some assemblers need integer constants to appear last (eg masm). */
2728 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2730 addr_const_to_string (str, XEXP (x, 1));
2731 if (INTVAL (XEXP (x, 0)) >= 0)
2732 dyn_string_append (str, "+");
2734 addr_const_to_string (str, XEXP (x, 0));
2738 addr_const_to_string (str, XEXP (x, 0));
2739 if (INTVAL (XEXP (x, 1)) >= 0)
2740 dyn_string_append (str, "+");
2742 addr_const_to_string (str, XEXP (x, 1));
2747 /* Avoid outputting things like x-x or x+5-x, since some assemblers
2748 can't handle that. */
2749 x = simplify_subtraction (x);
2750 if (GET_CODE (x) != MINUS)
2753 addr_const_to_string (str, XEXP (x, 0));
2754 dyn_string_append (str, "-");
2755 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2756 && INTVAL (XEXP (x, 1)) < 0)
2758 dyn_string_append (str, ASM_OPEN_PAREN);
2759 addr_const_to_string (str, XEXP (x, 1));
2760 dyn_string_append (str, ASM_CLOSE_PAREN);
2763 addr_const_to_string (str, XEXP (x, 1));
2768 addr_const_to_string (str, XEXP (x, 0));
2772 output_operand_lossage ("invalid expression as operand");
2776 /* Convert an address constant to a string, and return a pointer to
2777 a copy of the result, located on the heap. */
2783 dyn_string_t ds = dyn_string_new (256);
2786 addr_const_to_string (ds, x);
2788 /* Return the dynamically allocated string, but free the
2789 dyn_string_t itself. */
2795 /* Test if rtl node points to a pseudo register. */
2801 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
2802 || ((GET_CODE (rtl) == SUBREG)
2803 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
2806 /* Return a reference to a type, with its const and volatile qualifiers
2810 type_main_variant (type)
2813 type = TYPE_MAIN_VARIANT (type);
2815 /* There really should be only one main variant among any group of variants
2816 of a given type (and all of the MAIN_VARIANT values for all members of
2817 the group should point to that one type) but sometimes the C front-end
2818 messes this up for array types, so we work around that bug here. */
2820 if (TREE_CODE (type) == ARRAY_TYPE)
2821 while (type != TYPE_MAIN_VARIANT (type))
2822 type = TYPE_MAIN_VARIANT (type);
2827 /* Return non-zero if the given type node represents a tagged type. */
2830 is_tagged_type (type)
2833 register enum tree_code code = TREE_CODE (type);
2835 return (code == RECORD_TYPE || code == UNION_TYPE
2836 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
2839 /* Convert a DIE tag into its string name. */
2842 dwarf_tag_name (tag)
2843 register unsigned tag;
2847 case DW_TAG_padding:
2848 return "DW_TAG_padding";
2849 case DW_TAG_array_type:
2850 return "DW_TAG_array_type";
2851 case DW_TAG_class_type:
2852 return "DW_TAG_class_type";
2853 case DW_TAG_entry_point:
2854 return "DW_TAG_entry_point";
2855 case DW_TAG_enumeration_type:
2856 return "DW_TAG_enumeration_type";
2857 case DW_TAG_formal_parameter:
2858 return "DW_TAG_formal_parameter";
2859 case DW_TAG_imported_declaration:
2860 return "DW_TAG_imported_declaration";
2862 return "DW_TAG_label";
2863 case DW_TAG_lexical_block:
2864 return "DW_TAG_lexical_block";
2866 return "DW_TAG_member";
2867 case DW_TAG_pointer_type:
2868 return "DW_TAG_pointer_type";
2869 case DW_TAG_reference_type:
2870 return "DW_TAG_reference_type";
2871 case DW_TAG_compile_unit:
2872 return "DW_TAG_compile_unit";
2873 case DW_TAG_string_type:
2874 return "DW_TAG_string_type";
2875 case DW_TAG_structure_type:
2876 return "DW_TAG_structure_type";
2877 case DW_TAG_subroutine_type:
2878 return "DW_TAG_subroutine_type";
2879 case DW_TAG_typedef:
2880 return "DW_TAG_typedef";
2881 case DW_TAG_union_type:
2882 return "DW_TAG_union_type";
2883 case DW_TAG_unspecified_parameters:
2884 return "DW_TAG_unspecified_parameters";
2885 case DW_TAG_variant:
2886 return "DW_TAG_variant";
2887 case DW_TAG_common_block:
2888 return "DW_TAG_common_block";
2889 case DW_TAG_common_inclusion:
2890 return "DW_TAG_common_inclusion";
2891 case DW_TAG_inheritance:
2892 return "DW_TAG_inheritance";
2893 case DW_TAG_inlined_subroutine:
2894 return "DW_TAG_inlined_subroutine";
2896 return "DW_TAG_module";
2897 case DW_TAG_ptr_to_member_type:
2898 return "DW_TAG_ptr_to_member_type";
2899 case DW_TAG_set_type:
2900 return "DW_TAG_set_type";
2901 case DW_TAG_subrange_type:
2902 return "DW_TAG_subrange_type";
2903 case DW_TAG_with_stmt:
2904 return "DW_TAG_with_stmt";
2905 case DW_TAG_access_declaration:
2906 return "DW_TAG_access_declaration";
2907 case DW_TAG_base_type:
2908 return "DW_TAG_base_type";
2909 case DW_TAG_catch_block:
2910 return "DW_TAG_catch_block";
2911 case DW_TAG_const_type:
2912 return "DW_TAG_const_type";
2913 case DW_TAG_constant:
2914 return "DW_TAG_constant";
2915 case DW_TAG_enumerator:
2916 return "DW_TAG_enumerator";
2917 case DW_TAG_file_type:
2918 return "DW_TAG_file_type";
2920 return "DW_TAG_friend";
2921 case DW_TAG_namelist:
2922 return "DW_TAG_namelist";
2923 case DW_TAG_namelist_item:
2924 return "DW_TAG_namelist_item";
2925 case DW_TAG_packed_type:
2926 return "DW_TAG_packed_type";
2927 case DW_TAG_subprogram:
2928 return "DW_TAG_subprogram";
2929 case DW_TAG_template_type_param:
2930 return "DW_TAG_template_type_param";
2931 case DW_TAG_template_value_param:
2932 return "DW_TAG_template_value_param";
2933 case DW_TAG_thrown_type:
2934 return "DW_TAG_thrown_type";
2935 case DW_TAG_try_block:
2936 return "DW_TAG_try_block";
2937 case DW_TAG_variant_part:
2938 return "DW_TAG_variant_part";
2939 case DW_TAG_variable:
2940 return "DW_TAG_variable";
2941 case DW_TAG_volatile_type:
2942 return "DW_TAG_volatile_type";
2943 case DW_TAG_MIPS_loop:
2944 return "DW_TAG_MIPS_loop";
2945 case DW_TAG_format_label:
2946 return "DW_TAG_format_label";
2947 case DW_TAG_function_template:
2948 return "DW_TAG_function_template";
2949 case DW_TAG_class_template:
2950 return "DW_TAG_class_template";
2952 return "DW_TAG_<unknown>";
2956 /* Convert a DWARF attribute code into its string name. */
2959 dwarf_attr_name (attr)
2960 register unsigned attr;
2965 return "DW_AT_sibling";
2966 case DW_AT_location:
2967 return "DW_AT_location";
2969 return "DW_AT_name";
2970 case DW_AT_ordering:
2971 return "DW_AT_ordering";
2972 case DW_AT_subscr_data:
2973 return "DW_AT_subscr_data";
2974 case DW_AT_byte_size:
2975 return "DW_AT_byte_size";
2976 case DW_AT_bit_offset:
2977 return "DW_AT_bit_offset";
2978 case DW_AT_bit_size:
2979 return "DW_AT_bit_size";
2980 case DW_AT_element_list:
2981 return "DW_AT_element_list";
2982 case DW_AT_stmt_list:
2983 return "DW_AT_stmt_list";
2985 return "DW_AT_low_pc";
2987 return "DW_AT_high_pc";
2988 case DW_AT_language:
2989 return "DW_AT_language";
2991 return "DW_AT_member";
2993 return "DW_AT_discr";
2994 case DW_AT_discr_value:
2995 return "DW_AT_discr_value";
2996 case DW_AT_visibility:
2997 return "DW_AT_visibility";
2999 return "DW_AT_import";
3000 case DW_AT_string_length:
3001 return "DW_AT_string_length";
3002 case DW_AT_common_reference:
3003 return "DW_AT_common_reference";
3004 case DW_AT_comp_dir:
3005 return "DW_AT_comp_dir";
3006 case DW_AT_const_value:
3007 return "DW_AT_const_value";
3008 case DW_AT_containing_type:
3009 return "DW_AT_containing_type";
3010 case DW_AT_default_value:
3011 return "DW_AT_default_value";
3013 return "DW_AT_inline";
3014 case DW_AT_is_optional:
3015 return "DW_AT_is_optional";
3016 case DW_AT_lower_bound:
3017 return "DW_AT_lower_bound";
3018 case DW_AT_producer:
3019 return "DW_AT_producer";
3020 case DW_AT_prototyped:
3021 return "DW_AT_prototyped";
3022 case DW_AT_return_addr:
3023 return "DW_AT_return_addr";
3024 case DW_AT_start_scope:
3025 return "DW_AT_start_scope";
3026 case DW_AT_stride_size:
3027 return "DW_AT_stride_size";
3028 case DW_AT_upper_bound:
3029 return "DW_AT_upper_bound";
3030 case DW_AT_abstract_origin:
3031 return "DW_AT_abstract_origin";
3032 case DW_AT_accessibility:
3033 return "DW_AT_accessibility";
3034 case DW_AT_address_class:
3035 return "DW_AT_address_class";
3036 case DW_AT_artificial:
3037 return "DW_AT_artificial";
3038 case DW_AT_base_types:
3039 return "DW_AT_base_types";
3040 case DW_AT_calling_convention:
3041 return "DW_AT_calling_convention";
3043 return "DW_AT_count";
3044 case DW_AT_data_member_location:
3045 return "DW_AT_data_member_location";
3046 case DW_AT_decl_column:
3047 return "DW_AT_decl_column";
3048 case DW_AT_decl_file:
3049 return "DW_AT_decl_file";
3050 case DW_AT_decl_line:
3051 return "DW_AT_decl_line";
3052 case DW_AT_declaration:
3053 return "DW_AT_declaration";
3054 case DW_AT_discr_list:
3055 return "DW_AT_discr_list";
3056 case DW_AT_encoding:
3057 return "DW_AT_encoding";
3058 case DW_AT_external:
3059 return "DW_AT_external";
3060 case DW_AT_frame_base:
3061 return "DW_AT_frame_base";
3063 return "DW_AT_friend";
3064 case DW_AT_identifier_case:
3065 return "DW_AT_identifier_case";
3066 case DW_AT_macro_info:
3067 return "DW_AT_macro_info";
3068 case DW_AT_namelist_items:
3069 return "DW_AT_namelist_items";
3070 case DW_AT_priority:
3071 return "DW_AT_priority";
3073 return "DW_AT_segment";
3074 case DW_AT_specification:
3075 return "DW_AT_specification";
3076 case DW_AT_static_link:
3077 return "DW_AT_static_link";
3079 return "DW_AT_type";
3080 case DW_AT_use_location:
3081 return "DW_AT_use_location";
3082 case DW_AT_variable_parameter:
3083 return "DW_AT_variable_parameter";
3084 case DW_AT_virtuality:
3085 return "DW_AT_virtuality";
3086 case DW_AT_vtable_elem_location:
3087 return "DW_AT_vtable_elem_location";
3089 case DW_AT_MIPS_fde:
3090 return "DW_AT_MIPS_fde";
3091 case DW_AT_MIPS_loop_begin:
3092 return "DW_AT_MIPS_loop_begin";
3093 case DW_AT_MIPS_tail_loop_begin:
3094 return "DW_AT_MIPS_tail_loop_begin";
3095 case DW_AT_MIPS_epilog_begin:
3096 return "DW_AT_MIPS_epilog_begin";
3097 case DW_AT_MIPS_loop_unroll_factor:
3098 return "DW_AT_MIPS_loop_unroll_factor";
3099 case DW_AT_MIPS_software_pipeline_depth:
3100 return "DW_AT_MIPS_software_pipeline_depth";
3101 case DW_AT_MIPS_linkage_name:
3102 return "DW_AT_MIPS_linkage_name";
3103 case DW_AT_MIPS_stride:
3104 return "DW_AT_MIPS_stride";
3105 case DW_AT_MIPS_abstract_name:
3106 return "DW_AT_MIPS_abstract_name";
3107 case DW_AT_MIPS_clone_origin:
3108 return "DW_AT_MIPS_clone_origin";
3109 case DW_AT_MIPS_has_inlines:
3110 return "DW_AT_MIPS_has_inlines";
3112 case DW_AT_sf_names:
3113 return "DW_AT_sf_names";
3114 case DW_AT_src_info:
3115 return "DW_AT_src_info";
3116 case DW_AT_mac_info:
3117 return "DW_AT_mac_info";
3118 case DW_AT_src_coords:
3119 return "DW_AT_src_coords";
3120 case DW_AT_body_begin:
3121 return "DW_AT_body_begin";
3122 case DW_AT_body_end:
3123 return "DW_AT_body_end";
3125 return "DW_AT_<unknown>";
3129 /* Convert a DWARF value form code into its string name. */
3132 dwarf_form_name (form)
3133 register unsigned form;
3138 return "DW_FORM_addr";
3139 case DW_FORM_block2:
3140 return "DW_FORM_block2";
3141 case DW_FORM_block4:
3142 return "DW_FORM_block4";
3144 return "DW_FORM_data2";
3146 return "DW_FORM_data4";
3148 return "DW_FORM_data8";
3149 case DW_FORM_string:
3150 return "DW_FORM_string";
3152 return "DW_FORM_block";
3153 case DW_FORM_block1:
3154 return "DW_FORM_block1";
3156 return "DW_FORM_data1";
3158 return "DW_FORM_flag";
3160 return "DW_FORM_sdata";
3162 return "DW_FORM_strp";
3164 return "DW_FORM_udata";
3165 case DW_FORM_ref_addr:
3166 return "DW_FORM_ref_addr";
3168 return "DW_FORM_ref1";
3170 return "DW_FORM_ref2";
3172 return "DW_FORM_ref4";
3174 return "DW_FORM_ref8";
3175 case DW_FORM_ref_udata:
3176 return "DW_FORM_ref_udata";
3177 case DW_FORM_indirect:
3178 return "DW_FORM_indirect";
3180 return "DW_FORM_<unknown>";
3184 /* Convert a DWARF stack opcode into its string name. */
3187 dwarf_stack_op_name (op)
3188 register unsigned op;
3193 return "DW_OP_addr";
3195 return "DW_OP_deref";
3197 return "DW_OP_const1u";
3199 return "DW_OP_const1s";
3201 return "DW_OP_const2u";
3203 return "DW_OP_const2s";
3205 return "DW_OP_const4u";
3207 return "DW_OP_const4s";
3209 return "DW_OP_const8u";
3211 return "DW_OP_const8s";
3213 return "DW_OP_constu";
3215 return "DW_OP_consts";
3219 return "DW_OP_drop";
3221 return "DW_OP_over";
3223 return "DW_OP_pick";
3225 return "DW_OP_swap";
3229 return "DW_OP_xderef";
3237 return "DW_OP_minus";
3249 return "DW_OP_plus";
3250 case DW_OP_plus_uconst:
3251 return "DW_OP_plus_uconst";
3257 return "DW_OP_shra";
3275 return "DW_OP_skip";
3277 return "DW_OP_lit0";
3279 return "DW_OP_lit1";
3281 return "DW_OP_lit2";
3283 return "DW_OP_lit3";
3285 return "DW_OP_lit4";
3287 return "DW_OP_lit5";
3289 return "DW_OP_lit6";
3291 return "DW_OP_lit7";
3293 return "DW_OP_lit8";
3295 return "DW_OP_lit9";
3297 return "DW_OP_lit10";
3299 return "DW_OP_lit11";
3301 return "DW_OP_lit12";
3303 return "DW_OP_lit13";
3305 return "DW_OP_lit14";
3307 return "DW_OP_lit15";
3309 return "DW_OP_lit16";
3311 return "DW_OP_lit17";
3313 return "DW_OP_lit18";
3315 return "DW_OP_lit19";
3317 return "DW_OP_lit20";
3319 return "DW_OP_lit21";
3321 return "DW_OP_lit22";
3323 return "DW_OP_lit23";
3325 return "DW_OP_lit24";
3327 return "DW_OP_lit25";
3329 return "DW_OP_lit26";
3331 return "DW_OP_lit27";
3333 return "DW_OP_lit28";
3335 return "DW_OP_lit29";
3337 return "DW_OP_lit30";
3339 return "DW_OP_lit31";
3341 return "DW_OP_reg0";
3343 return "DW_OP_reg1";
3345 return "DW_OP_reg2";
3347 return "DW_OP_reg3";
3349 return "DW_OP_reg4";
3351 return "DW_OP_reg5";
3353 return "DW_OP_reg6";
3355 return "DW_OP_reg7";
3357 return "DW_OP_reg8";
3359 return "DW_OP_reg9";
3361 return "DW_OP_reg10";
3363 return "DW_OP_reg11";
3365 return "DW_OP_reg12";
3367 return "DW_OP_reg13";
3369 return "DW_OP_reg14";
3371 return "DW_OP_reg15";
3373 return "DW_OP_reg16";
3375 return "DW_OP_reg17";
3377 return "DW_OP_reg18";
3379 return "DW_OP_reg19";
3381 return "DW_OP_reg20";
3383 return "DW_OP_reg21";
3385 return "DW_OP_reg22";
3387 return "DW_OP_reg23";
3389 return "DW_OP_reg24";
3391 return "DW_OP_reg25";
3393 return "DW_OP_reg26";
3395 return "DW_OP_reg27";
3397 return "DW_OP_reg28";
3399 return "DW_OP_reg29";
3401 return "DW_OP_reg30";
3403 return "DW_OP_reg31";
3405 return "DW_OP_breg0";
3407 return "DW_OP_breg1";
3409 return "DW_OP_breg2";
3411 return "DW_OP_breg3";
3413 return "DW_OP_breg4";
3415 return "DW_OP_breg5";
3417 return "DW_OP_breg6";
3419 return "DW_OP_breg7";
3421 return "DW_OP_breg8";
3423 return "DW_OP_breg9";
3425 return "DW_OP_breg10";
3427 return "DW_OP_breg11";
3429 return "DW_OP_breg12";
3431 return "DW_OP_breg13";
3433 return "DW_OP_breg14";
3435 return "DW_OP_breg15";
3437 return "DW_OP_breg16";
3439 return "DW_OP_breg17";
3441 return "DW_OP_breg18";
3443 return "DW_OP_breg19";
3445 return "DW_OP_breg20";
3447 return "DW_OP_breg21";
3449 return "DW_OP_breg22";
3451 return "DW_OP_breg23";
3453 return "DW_OP_breg24";
3455 return "DW_OP_breg25";
3457 return "DW_OP_breg26";
3459 return "DW_OP_breg27";
3461 return "DW_OP_breg28";
3463 return "DW_OP_breg29";
3465 return "DW_OP_breg30";
3467 return "DW_OP_breg31";
3469 return "DW_OP_regx";
3471 return "DW_OP_fbreg";
3473 return "DW_OP_bregx";
3475 return "DW_OP_piece";
3476 case DW_OP_deref_size:
3477 return "DW_OP_deref_size";
3478 case DW_OP_xderef_size:
3479 return "DW_OP_xderef_size";
3483 return "OP_<unknown>";
3487 /* Convert a DWARF type code into its string name. */
3491 dwarf_type_encoding_name (enc)
3492 register unsigned enc;
3496 case DW_ATE_address:
3497 return "DW_ATE_address";
3498 case DW_ATE_boolean:
3499 return "DW_ATE_boolean";
3500 case DW_ATE_complex_float:
3501 return "DW_ATE_complex_float";
3503 return "DW_ATE_float";
3505 return "DW_ATE_signed";
3506 case DW_ATE_signed_char:
3507 return "DW_ATE_signed_char";
3508 case DW_ATE_unsigned:
3509 return "DW_ATE_unsigned";
3510 case DW_ATE_unsigned_char:
3511 return "DW_ATE_unsigned_char";
3513 return "DW_ATE_<unknown>";
3518 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3519 instance of an inlined instance of a decl which is local to an inline
3520 function, so we have to trace all of the way back through the origin chain
3521 to find out what sort of node actually served as the original seed for the
3525 decl_ultimate_origin (decl)
3528 #ifdef ENABLE_CHECKING
3529 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
3530 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3531 most distant ancestor, this should never happen. */
3535 return DECL_ABSTRACT_ORIGIN (decl);
3538 /* Determine the "ultimate origin" of a block. The block may be an inlined
3539 instance of an inlined instance of a block which is local to an inline
3540 function, so we have to trace all of the way back through the origin chain
3541 to find out what sort of node actually served as the original seed for the
3545 block_ultimate_origin (block)
3546 register tree block;
3548 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3550 if (immediate_origin == NULL_TREE)
3554 register tree ret_val;
3555 register tree lookahead = immediate_origin;
3559 ret_val = lookahead;
3560 lookahead = (TREE_CODE (ret_val) == BLOCK)
3561 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3564 while (lookahead != NULL && lookahead != ret_val);
3570 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3571 of a virtual function may refer to a base class, so we check the 'this'
3575 decl_class_context (decl)
3578 tree context = NULL_TREE;
3580 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3581 context = DECL_CONTEXT (decl);
3583 context = TYPE_MAIN_VARIANT
3584 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3586 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
3587 context = NULL_TREE;
3592 /* Add an attribute/value pair to a DIE */
3595 add_dwarf_attr (die, attr)
3596 register dw_die_ref die;
3597 register dw_attr_ref attr;
3599 if (die != NULL && attr != NULL)
3601 if (die->die_attr == NULL)
3603 die->die_attr = attr;
3604 die->die_attr_last = attr;
3608 die->die_attr_last->dw_attr_next = attr;
3609 die->die_attr_last = attr;
3614 /* Add a flag value attribute to a DIE. */
3617 add_AT_flag (die, attr_kind, flag)
3618 register dw_die_ref die;
3619 register enum dwarf_attribute attr_kind;
3620 register unsigned flag;
3622 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3624 attr->dw_attr_next = NULL;
3625 attr->dw_attr = attr_kind;
3626 attr->dw_attr_val.val_class = dw_val_class_flag;
3627 attr->dw_attr_val.v.val_flag = flag;
3628 add_dwarf_attr (die, attr);
3631 /* Add a signed integer attribute value to a DIE. */
3634 add_AT_int (die, attr_kind, int_val)
3635 register dw_die_ref die;
3636 register enum dwarf_attribute attr_kind;
3637 register long int int_val;
3639 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3641 attr->dw_attr_next = NULL;
3642 attr->dw_attr = attr_kind;
3643 attr->dw_attr_val.val_class = dw_val_class_const;
3644 attr->dw_attr_val.v.val_int = int_val;
3645 add_dwarf_attr (die, attr);
3648 /* Add an unsigned integer attribute value to a DIE. */
3651 add_AT_unsigned (die, attr_kind, unsigned_val)
3652 register dw_die_ref die;
3653 register enum dwarf_attribute attr_kind;
3654 register unsigned long unsigned_val;
3656 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3658 attr->dw_attr_next = NULL;
3659 attr->dw_attr = attr_kind;
3660 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
3661 attr->dw_attr_val.v.val_unsigned = unsigned_val;
3662 add_dwarf_attr (die, attr);
3665 /* Add an unsigned double integer attribute value to a DIE. */
3668 add_AT_long_long (die, attr_kind, val_hi, val_low)
3669 register dw_die_ref die;
3670 register enum dwarf_attribute attr_kind;
3671 register unsigned long val_hi;
3672 register unsigned long val_low;
3674 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3676 attr->dw_attr_next = NULL;
3677 attr->dw_attr = attr_kind;
3678 attr->dw_attr_val.val_class = dw_val_class_long_long;
3679 attr->dw_attr_val.v.val_long_long.hi = val_hi;
3680 attr->dw_attr_val.v.val_long_long.low = val_low;
3681 add_dwarf_attr (die, attr);
3684 /* Add a floating point attribute value to a DIE and return it. */
3687 add_AT_float (die, attr_kind, length, array)
3688 register dw_die_ref die;
3689 register enum dwarf_attribute attr_kind;
3690 register unsigned length;
3691 register long *array;
3693 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3695 attr->dw_attr_next = NULL;
3696 attr->dw_attr = attr_kind;
3697 attr->dw_attr_val.val_class = dw_val_class_float;
3698 attr->dw_attr_val.v.val_float.length = length;
3699 attr->dw_attr_val.v.val_float.array = array;
3700 add_dwarf_attr (die, attr);
3703 /* Add a string attribute value to a DIE. */
3706 add_AT_string (die, attr_kind, str)
3707 register dw_die_ref die;
3708 register enum dwarf_attribute attr_kind;
3709 register const char *str;
3711 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3713 attr->dw_attr_next = NULL;
3714 attr->dw_attr = attr_kind;
3715 attr->dw_attr_val.val_class = dw_val_class_str;
3716 attr->dw_attr_val.v.val_str = xstrdup (str);
3717 add_dwarf_attr (die, attr);
3720 /* Add a DIE reference attribute value to a DIE. */
3723 add_AT_die_ref (die, attr_kind, targ_die)
3724 register dw_die_ref die;
3725 register enum dwarf_attribute attr_kind;
3726 register dw_die_ref targ_die;
3728 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3730 attr->dw_attr_next = NULL;
3731 attr->dw_attr = attr_kind;
3732 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3733 attr->dw_attr_val.v.val_die_ref = targ_die;
3734 add_dwarf_attr (die, attr);
3737 /* Add an FDE reference attribute value to a DIE. */
3740 add_AT_fde_ref (die, attr_kind, targ_fde)
3741 register dw_die_ref die;
3742 register enum dwarf_attribute attr_kind;
3743 register unsigned targ_fde;
3745 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3747 attr->dw_attr_next = NULL;
3748 attr->dw_attr = attr_kind;
3749 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
3750 attr->dw_attr_val.v.val_fde_index = targ_fde;
3751 add_dwarf_attr (die, attr);
3754 /* Add a location description attribute value to a DIE. */
3757 add_AT_loc (die, attr_kind, loc)
3758 register dw_die_ref die;
3759 register enum dwarf_attribute attr_kind;
3760 register dw_loc_descr_ref loc;
3762 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3764 attr->dw_attr_next = NULL;
3765 attr->dw_attr = attr_kind;
3766 attr->dw_attr_val.val_class = dw_val_class_loc;
3767 attr->dw_attr_val.v.val_loc = loc;
3768 add_dwarf_attr (die, attr);
3771 /* Add an address constant attribute value to a DIE. */
3774 add_AT_addr (die, attr_kind, addr)
3775 register dw_die_ref die;
3776 register enum dwarf_attribute attr_kind;
3779 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3781 attr->dw_attr_next = NULL;
3782 attr->dw_attr = attr_kind;
3783 attr->dw_attr_val.val_class = dw_val_class_addr;
3784 attr->dw_attr_val.v.val_addr = addr;
3785 add_dwarf_attr (die, attr);
3788 /* Add a label identifier attribute value to a DIE. */
3791 add_AT_lbl_id (die, attr_kind, lbl_id)
3792 register dw_die_ref die;
3793 register enum dwarf_attribute attr_kind;
3794 register char *lbl_id;
3796 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3798 attr->dw_attr_next = NULL;
3799 attr->dw_attr = attr_kind;
3800 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
3801 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
3802 add_dwarf_attr (die, attr);
3805 /* Add a section offset attribute value to a DIE. */
3808 add_AT_lbl_offset (die, attr_kind, label)
3809 register dw_die_ref die;
3810 register enum dwarf_attribute attr_kind;
3811 register char *label;
3813 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3815 attr->dw_attr_next = NULL;
3816 attr->dw_attr = attr_kind;
3817 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
3818 attr->dw_attr_val.v.val_lbl_id = label;
3819 add_dwarf_attr (die, attr);
3823 /* Test if die refers to an external subroutine. */
3826 is_extern_subr_die (die)
3827 register dw_die_ref die;
3829 register dw_attr_ref a;
3830 register int is_subr = FALSE;
3831 register int is_extern = FALSE;
3833 if (die != NULL && die->die_tag == DW_TAG_subprogram)
3836 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3838 if (a->dw_attr == DW_AT_external
3839 && a->dw_attr_val.val_class == dw_val_class_flag
3840 && a->dw_attr_val.v.val_flag != 0)
3848 return is_subr && is_extern;
3851 /* Get the attribute of type attr_kind. */
3853 static inline dw_attr_ref
3854 get_AT (die, attr_kind)
3855 register dw_die_ref die;
3856 register enum dwarf_attribute attr_kind;
3858 register dw_attr_ref a;
3859 register dw_die_ref spec = NULL;
3863 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3865 if (a->dw_attr == attr_kind)
3868 if (a->dw_attr == DW_AT_specification
3869 || a->dw_attr == DW_AT_abstract_origin)
3870 spec = a->dw_attr_val.v.val_die_ref;
3874 return get_AT (spec, attr_kind);
3880 /* Return the "low pc" attribute value, typically associated with
3881 a subprogram DIE. Return null if the "low pc" attribute is
3882 either not prsent, or if it cannot be represented as an
3883 assembler label identifier. */
3885 static inline char *
3887 register dw_die_ref die;
3889 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
3891 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3892 return a->dw_attr_val.v.val_lbl_id;
3897 /* Return the "high pc" attribute value, typically associated with
3898 a subprogram DIE. Return null if the "high pc" attribute is
3899 either not prsent, or if it cannot be represented as an
3900 assembler label identifier. */
3902 static inline char *
3904 register dw_die_ref die;
3906 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
3908 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3909 return a->dw_attr_val.v.val_lbl_id;
3914 /* Return the value of the string attribute designated by ATTR_KIND, or
3915 NULL if it is not present. */
3917 static inline char *
3918 get_AT_string (die, attr_kind)
3919 register dw_die_ref die;
3920 register enum dwarf_attribute attr_kind;
3922 register dw_attr_ref a = get_AT (die, attr_kind);
3924 if (a && a->dw_attr_val.val_class == dw_val_class_str)
3925 return a->dw_attr_val.v.val_str;
3930 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3931 if it is not present. */
3934 get_AT_flag (die, attr_kind)
3935 register dw_die_ref die;
3936 register enum dwarf_attribute attr_kind;
3938 register dw_attr_ref a = get_AT (die, attr_kind);
3940 if (a && a->dw_attr_val.val_class == dw_val_class_flag)
3941 return a->dw_attr_val.v.val_flag;
3946 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3947 if it is not present. */
3949 static inline unsigned
3950 get_AT_unsigned (die, attr_kind)
3951 register dw_die_ref die;
3952 register enum dwarf_attribute attr_kind;
3954 register dw_attr_ref a = get_AT (die, attr_kind);
3956 if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
3957 return a->dw_attr_val.v.val_unsigned;
3965 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3967 return (lang == DW_LANG_C || lang == DW_LANG_C89
3968 || lang == DW_LANG_C_plus_plus);
3974 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3976 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
3979 /* Remove the specified attribute if present. */
3982 remove_AT (die, attr_kind)
3983 register dw_die_ref die;
3984 register enum dwarf_attribute attr_kind;
3986 register dw_attr_ref a;
3987 register dw_attr_ref removed = NULL;
3991 if (die->die_attr->dw_attr == attr_kind)
3993 removed = die->die_attr;
3994 if (die->die_attr_last == die->die_attr)
3995 die->die_attr_last = NULL;
3997 die->die_attr = die->die_attr->dw_attr_next;
4001 for (a = die->die_attr; a->dw_attr_next != NULL;
4002 a = a->dw_attr_next)
4003 if (a->dw_attr_next->dw_attr == attr_kind)
4005 removed = a->dw_attr_next;
4006 if (die->die_attr_last == a->dw_attr_next)
4007 die->die_attr_last = a;
4009 a->dw_attr_next = a->dw_attr_next->dw_attr_next;
4018 /* Discard the children of this DIE. */
4021 remove_children (die)
4022 register dw_die_ref die;
4024 register dw_die_ref child_die = die->die_child;
4026 die->die_child = NULL;
4027 die->die_child_last = NULL;
4029 while (child_die != NULL)
4031 register dw_die_ref tmp_die = child_die;
4032 register dw_attr_ref a;
4034 child_die = child_die->die_sib;
4036 for (a = tmp_die->die_attr; a != NULL; )
4038 register dw_attr_ref tmp_a = a;
4040 a = a->dw_attr_next;
4048 /* Add a child DIE below its parent. */
4051 add_child_die (die, child_die)
4052 register dw_die_ref die;
4053 register dw_die_ref child_die;
4055 if (die != NULL && child_die != NULL)
4057 if (die == child_die)
4059 child_die->die_parent = die;
4060 child_die->die_sib = NULL;
4062 if (die->die_child == NULL)
4064 die->die_child = child_die;
4065 die->die_child_last = child_die;
4069 die->die_child_last->die_sib = child_die;
4070 die->die_child_last = child_die;
4075 /* Return a pointer to a newly created DIE node. */
4077 static inline dw_die_ref
4078 new_die (tag_value, parent_die)
4079 register enum dwarf_tag tag_value;
4080 register dw_die_ref parent_die;
4082 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4084 die->die_tag = tag_value;
4085 die->die_abbrev = 0;
4086 die->die_offset = 0;
4087 die->die_child = NULL;
4088 die->die_parent = NULL;
4089 die->die_sib = NULL;
4090 die->die_child_last = NULL;
4091 die->die_attr = NULL;
4092 die->die_attr_last = NULL;
4094 if (parent_die != NULL)
4095 add_child_die (parent_die, die);
4098 limbo_die_node *limbo_node;
4100 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4101 limbo_node->die = die;
4102 limbo_node->next = limbo_die_list;
4103 limbo_die_list = limbo_node;
4109 /* Return the DIE associated with the given type specifier. */
4111 static inline dw_die_ref
4112 lookup_type_die (type)
4115 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4118 /* Equate a DIE to a given type specifier. */
4121 equate_type_number_to_die (type, type_die)
4123 register dw_die_ref type_die;
4125 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4128 /* Return the DIE associated with a given declaration. */
4130 static inline dw_die_ref
4131 lookup_decl_die (decl)
4134 register unsigned decl_id = DECL_UID (decl);
4136 return (decl_id < decl_die_table_in_use
4137 ? decl_die_table[decl_id] : NULL);
4140 /* Equate a DIE to a particular declaration. */
4143 equate_decl_number_to_die (decl, decl_die)
4145 register dw_die_ref decl_die;
4147 register unsigned decl_id = DECL_UID (decl);
4148 register unsigned num_allocated;
4150 if (decl_id >= decl_die_table_allocated)
4153 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4154 / DECL_DIE_TABLE_INCREMENT)
4155 * DECL_DIE_TABLE_INCREMENT;
4158 = (dw_die_ref *) xrealloc (decl_die_table,
4159 sizeof (dw_die_ref) * num_allocated);
4161 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4162 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4163 decl_die_table_allocated = num_allocated;
4166 if (decl_id >= decl_die_table_in_use)
4167 decl_die_table_in_use = (decl_id + 1);
4169 decl_die_table[decl_id] = decl_die;
4172 /* Return a pointer to a newly allocated location description. Location
4173 descriptions are simple expression terms that can be strung
4174 together to form more complicated location (address) descriptions. */
4176 static inline dw_loc_descr_ref
4177 new_loc_descr (op, oprnd1, oprnd2)
4178 register enum dwarf_location_atom op;
4179 register unsigned long oprnd1;
4180 register unsigned long oprnd2;
4182 register dw_loc_descr_ref descr
4183 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
4185 descr->dw_loc_next = NULL;
4186 descr->dw_loc_opc = op;
4187 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4188 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4189 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4190 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4195 /* Add a location description term to a location description expression. */
4198 add_loc_descr (list_head, descr)
4199 register dw_loc_descr_ref *list_head;
4200 register dw_loc_descr_ref descr;
4202 register dw_loc_descr_ref *d;
4204 /* Find the end of the chain. */
4205 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4211 /* Keep track of the number of spaces used to indent the
4212 output of the debugging routines that print the structure of
4213 the DIE internal representation. */
4214 static int print_indent;
4216 /* Indent the line the number of spaces given by print_indent. */
4219 print_spaces (outfile)
4222 fprintf (outfile, "%*s", print_indent, "");
4225 /* Print the information associated with a given DIE, and its children.
4226 This routine is a debugging aid only. */
4229 print_die (die, outfile)
4233 register dw_attr_ref a;
4234 register dw_die_ref c;
4236 print_spaces (outfile);
4237 fprintf (outfile, "DIE %4lu: %s\n",
4238 die->die_offset, dwarf_tag_name (die->die_tag));
4239 print_spaces (outfile);
4240 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4241 fprintf (outfile, " offset: %lu\n", die->die_offset);
4243 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4245 print_spaces (outfile);
4246 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4248 switch (a->dw_attr_val.val_class)
4250 case dw_val_class_addr:
4251 fprintf (outfile, "address");
4253 case dw_val_class_loc:
4254 fprintf (outfile, "location descriptor");
4256 case dw_val_class_const:
4257 fprintf (outfile, "%ld", a->dw_attr_val.v.val_int);
4259 case dw_val_class_unsigned_const:
4260 fprintf (outfile, "%lu", a->dw_attr_val.v.val_unsigned);
4262 case dw_val_class_long_long:
4263 fprintf (outfile, "constant (%lu,%lu)",
4264 a->dw_attr_val.v.val_long_long.hi,
4265 a->dw_attr_val.v.val_long_long.low);
4267 case dw_val_class_float:
4268 fprintf (outfile, "floating-point constant");
4270 case dw_val_class_flag:
4271 fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
4273 case dw_val_class_die_ref:
4274 if (a->dw_attr_val.v.val_die_ref != NULL)
4275 fprintf (outfile, "die -> %lu",
4276 a->dw_attr_val.v.val_die_ref->die_offset);
4278 fprintf (outfile, "die -> <null>");
4280 case dw_val_class_lbl_id:
4281 case dw_val_class_lbl_offset:
4282 fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
4284 case dw_val_class_str:
4285 if (a->dw_attr_val.v.val_str != NULL)
4286 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
4288 fprintf (outfile, "<null>");
4294 fprintf (outfile, "\n");
4297 if (die->die_child != NULL)
4300 for (c = die->die_child; c != NULL; c = c->die_sib)
4301 print_die (c, outfile);
4307 /* Print the contents of the source code line number correspondence table.
4308 This routine is a debugging aid only. */
4311 print_dwarf_line_table (outfile)
4314 register unsigned i;
4315 register dw_line_info_ref line_info;
4317 fprintf (outfile, "\n\nDWARF source line information\n");
4318 for (i = 1; i < line_info_table_in_use; ++i)
4320 line_info = &line_info_table[i];
4321 fprintf (outfile, "%5d: ", i);
4322 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4323 fprintf (outfile, "%6ld", line_info->dw_line_num);
4324 fprintf (outfile, "\n");
4327 fprintf (outfile, "\n\n");
4330 /* Print the information collected for a given DIE. */
4333 debug_dwarf_die (die)
4336 print_die (die, stderr);
4339 /* Print all DWARF information collected for the compilation unit.
4340 This routine is a debugging aid only. */
4346 print_die (comp_unit_die, stderr);
4347 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4348 print_dwarf_line_table (stderr);
4351 /* Traverse the DIE, and add a sibling attribute if it may have the
4352 effect of speeding up access to siblings. To save some space,
4353 avoid generating sibling attributes for DIE's without children. */
4356 add_sibling_attributes(die)
4357 register dw_die_ref die;
4359 register dw_die_ref c;
4360 register dw_attr_ref attr;
4361 if (die != comp_unit_die && die->die_child != NULL)
4363 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4364 attr->dw_attr_next = NULL;
4365 attr->dw_attr = DW_AT_sibling;
4366 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4367 attr->dw_attr_val.v.val_die_ref = die->die_sib;
4369 /* Add the sibling link to the front of the attribute list. */
4370 attr->dw_attr_next = die->die_attr;
4371 if (die->die_attr == NULL)
4372 die->die_attr_last = attr;
4374 die->die_attr = attr;
4377 for (c = die->die_child; c != NULL; c = c->die_sib)
4378 add_sibling_attributes (c);
4381 /* The format of each DIE (and its attribute value pairs)
4382 is encoded in an abbreviation table. This routine builds the
4383 abbreviation table and assigns a unique abbreviation id for
4384 each abbreviation entry. The children of each die are visited
4388 build_abbrev_table (die)
4389 register dw_die_ref die;
4391 register unsigned long abbrev_id;
4392 register unsigned long n_alloc;
4393 register dw_die_ref c;
4394 register dw_attr_ref d_attr, a_attr;
4395 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4397 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4399 if (abbrev->die_tag == die->die_tag)
4401 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
4403 a_attr = abbrev->die_attr;
4404 d_attr = die->die_attr;
4406 while (a_attr != NULL && d_attr != NULL)
4408 if ((a_attr->dw_attr != d_attr->dw_attr)
4409 || (value_format (&a_attr->dw_attr_val)
4410 != value_format (&d_attr->dw_attr_val)))
4413 a_attr = a_attr->dw_attr_next;
4414 d_attr = d_attr->dw_attr_next;
4417 if (a_attr == NULL && d_attr == NULL)
4423 if (abbrev_id >= abbrev_die_table_in_use)
4425 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
4427 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
4429 = (dw_die_ref *) xrealloc (abbrev_die_table,
4430 sizeof (dw_die_ref) * n_alloc);
4432 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
4433 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
4434 abbrev_die_table_allocated = n_alloc;
4437 ++abbrev_die_table_in_use;
4438 abbrev_die_table[abbrev_id] = die;
4441 die->die_abbrev = abbrev_id;
4442 for (c = die->die_child; c != NULL; c = c->die_sib)
4443 build_abbrev_table (c);
4446 /* Return the size of a string, including the null byte.
4448 This used to treat backslashes as escapes, and hence they were not included
4449 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
4450 which treats a backslash as a backslash, escaping it if necessary, and hence
4451 we must include them in the count. */
4453 static unsigned long
4454 size_of_string (str)
4457 return strlen (str) + 1;
4460 /* Return the size of a location descriptor. */
4462 static unsigned long
4463 size_of_loc_descr (loc)
4464 register dw_loc_descr_ref loc;
4466 register unsigned long size = 1;
4468 switch (loc->dw_loc_opc)
4490 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4493 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4498 case DW_OP_plus_uconst:
4499 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4537 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4540 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4543 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4546 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4547 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4550 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4552 case DW_OP_deref_size:
4553 case DW_OP_xderef_size:
4563 /* Return the size of a series of location descriptors. */
4565 static unsigned long
4567 register dw_loc_descr_ref loc;
4569 register unsigned long size = 0;
4571 for (; loc != NULL; loc = loc->dw_loc_next)
4572 size += size_of_loc_descr (loc);
4577 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4580 constant_size (value)
4581 long unsigned value;
4588 log = floor_log2 (value);
4591 log = 1 << (floor_log2 (log) + 1);
4596 /* Return the size of a DIE, as it is represented in the
4597 .debug_info section. */
4599 static unsigned long
4601 register dw_die_ref die;
4603 register unsigned long size = 0;
4604 register dw_attr_ref a;
4606 size += size_of_uleb128 (die->die_abbrev);
4607 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4609 switch (a->dw_attr_val.val_class)
4611 case dw_val_class_addr:
4614 case dw_val_class_loc:
4616 register unsigned long lsize
4617 = size_of_locs (a->dw_attr_val.v.val_loc);
4620 size += constant_size (lsize);
4624 case dw_val_class_const:
4627 case dw_val_class_unsigned_const:
4628 size += constant_size (a->dw_attr_val.v.val_unsigned);
4630 case dw_val_class_long_long:
4631 size += 1 + 8; /* block */
4633 case dw_val_class_float:
4634 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
4636 case dw_val_class_flag:
4639 case dw_val_class_die_ref:
4640 size += DWARF_OFFSET_SIZE;
4642 case dw_val_class_fde_ref:
4643 size += DWARF_OFFSET_SIZE;
4645 case dw_val_class_lbl_id:
4648 case dw_val_class_lbl_offset:
4649 size += DWARF_OFFSET_SIZE;
4651 case dw_val_class_str:
4652 size += size_of_string (a->dw_attr_val.v.val_str);
4662 /* Size the debugging information associated with a given DIE.
4663 Visits the DIE's children recursively. Updates the global
4664 variable next_die_offset, on each time through. Uses the
4665 current value of next_die_offset to update the die_offset
4666 field in each DIE. */
4669 calc_die_sizes (die)
4672 register dw_die_ref c;
4673 die->die_offset = next_die_offset;
4674 next_die_offset += size_of_die (die);
4676 for (c = die->die_child; c != NULL; c = c->die_sib)
4679 if (die->die_child != NULL)
4680 /* Count the null byte used to terminate sibling lists. */
4681 next_die_offset += 1;
4684 /* Return the size of the line information prolog generated for the
4685 compilation unit. */
4687 static unsigned long
4688 size_of_line_prolog ()
4690 register unsigned long size;
4691 register unsigned long ft_index;
4693 size = DWARF_LINE_PROLOG_HEADER_SIZE;
4695 /* Count the size of the table giving number of args for each
4697 size += DWARF_LINE_OPCODE_BASE - 1;
4699 /* Include directory table is empty (at present). Count only the
4700 null byte used to terminate the table. */
4703 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4705 /* File name entry. */
4706 size += size_of_string (file_table[ft_index]);
4708 /* Include directory index. */
4709 size += size_of_uleb128 (0);
4711 /* Modification time. */
4712 size += size_of_uleb128 (0);
4714 /* File length in bytes. */
4715 size += size_of_uleb128 (0);
4718 /* Count the file table terminator. */
4723 /* Return the size of the line information generated for this
4724 compilation unit. */
4726 static unsigned long
4727 size_of_line_info ()
4729 register unsigned long size;
4730 register unsigned long lt_index;
4731 register unsigned long current_line;
4732 register long line_offset;
4733 register long line_delta;
4734 register unsigned long current_file;
4735 register unsigned long function;
4736 unsigned long size_of_set_address;
4738 /* Size of a DW_LNE_set_address instruction. */
4739 size_of_set_address = 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
4741 /* Version number. */
4744 /* Prolog length specifier. */
4745 size += DWARF_OFFSET_SIZE;
4748 size += size_of_line_prolog ();
4752 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
4754 register dw_line_info_ref line_info = &line_info_table[lt_index];
4756 if (line_info->dw_line_num == current_line
4757 && line_info->dw_file_num == current_file)
4760 /* Advance pc instruction. */
4761 /* ??? See the DW_LNS_advance_pc comment in output_line_info. */
4765 size += size_of_set_address;
4767 if (line_info->dw_file_num != current_file)
4769 /* Set file number instruction. */
4771 current_file = line_info->dw_file_num;
4772 size += size_of_uleb128 (current_file);
4775 if (line_info->dw_line_num != current_line)
4777 line_offset = line_info->dw_line_num - current_line;
4778 line_delta = line_offset - DWARF_LINE_BASE;
4779 current_line = line_info->dw_line_num;
4780 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4781 /* 1-byte special line number instruction. */
4785 /* Advance line instruction. */
4787 size += size_of_sleb128 (line_offset);
4788 /* Generate line entry instruction. */
4794 /* Advance pc instruction. */
4798 size += size_of_set_address;
4800 /* End of line number info. marker. */
4801 size += 1 + size_of_uleb128 (1) + 1;
4806 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
4808 register dw_separate_line_info_ref line_info
4809 = &separate_line_info_table[lt_index];
4811 if (line_info->dw_line_num == current_line
4812 && line_info->dw_file_num == current_file
4813 && line_info->function == function)
4816 if (function != line_info->function)
4818 function = line_info->function;
4819 /* Set address register instruction. */
4820 size += size_of_set_address;
4824 /* Advance pc instruction. */
4828 size += size_of_set_address;
4831 if (line_info->dw_file_num != current_file)
4833 /* Set file number instruction. */
4835 current_file = line_info->dw_file_num;
4836 size += size_of_uleb128 (current_file);
4839 if (line_info->dw_line_num != current_line)
4841 line_offset = line_info->dw_line_num - current_line;
4842 line_delta = line_offset - DWARF_LINE_BASE;
4843 current_line = line_info->dw_line_num;
4844 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4845 /* 1-byte special line number instruction. */
4849 /* Advance line instruction. */
4851 size += size_of_sleb128 (line_offset);
4853 /* Generate line entry instruction. */
4861 /* If we're done with a function, end its sequence. */
4862 if (lt_index == separate_line_info_table_in_use
4863 || separate_line_info_table[lt_index].function != function)
4868 /* Advance pc instruction. */
4872 size += size_of_set_address;
4874 /* End of line number info. marker. */
4875 size += 1 + size_of_uleb128 (1) + 1;
4882 /* Return the size of the .debug_pubnames table generated for the
4883 compilation unit. */
4885 static unsigned long
4888 register unsigned long size;
4889 register unsigned i;
4891 size = DWARF_PUBNAMES_HEADER_SIZE;
4892 for (i = 0; i < pubname_table_in_use; ++i)
4894 register pubname_ref p = &pubname_table[i];
4895 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
4898 size += DWARF_OFFSET_SIZE;
4902 /* Return the size of the information in the .debug_aranges section. */
4904 static unsigned long
4907 register unsigned long size;
4909 size = DWARF_ARANGES_HEADER_SIZE;
4911 /* Count the address/length pair for this compilation unit. */
4912 size += 2 * PTR_SIZE;
4913 size += 2 * PTR_SIZE * arange_table_in_use;
4915 /* Count the two zero words used to terminated the address range table. */
4916 size += 2 * PTR_SIZE;
4920 /* Select the encoding of an attribute value. */
4922 static enum dwarf_form
4926 switch (v->val_class)
4928 case dw_val_class_addr:
4929 return DW_FORM_addr;
4930 case dw_val_class_loc:
4931 switch (constant_size (size_of_locs (v->v.val_loc)))
4934 return DW_FORM_block1;
4936 return DW_FORM_block2;
4940 case dw_val_class_const:
4941 return DW_FORM_data4;
4942 case dw_val_class_unsigned_const:
4943 switch (constant_size (v->v.val_unsigned))
4946 return DW_FORM_data1;
4948 return DW_FORM_data2;
4950 return DW_FORM_data4;
4952 return DW_FORM_data8;
4956 case dw_val_class_long_long:
4957 return DW_FORM_block1;
4958 case dw_val_class_float:
4959 return DW_FORM_block1;
4960 case dw_val_class_flag:
4961 return DW_FORM_flag;
4962 case dw_val_class_die_ref:
4964 case dw_val_class_fde_ref:
4965 return DW_FORM_data;
4966 case dw_val_class_lbl_id:
4967 return DW_FORM_addr;
4968 case dw_val_class_lbl_offset:
4969 return DW_FORM_data;
4970 case dw_val_class_str:
4971 return DW_FORM_string;
4977 /* Output the encoding of an attribute value. */
4980 output_value_format (v)
4983 enum dwarf_form form = value_format (v);
4985 output_uleb128 (form);
4987 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
4989 fputc ('\n', asm_out_file);
4992 /* Output the .debug_abbrev section which defines the DIE abbreviation
4996 output_abbrev_section ()
4998 unsigned long abbrev_id;
5001 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5003 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5005 output_uleb128 (abbrev_id);
5007 fprintf (asm_out_file, " (abbrev code)");
5009 fputc ('\n', asm_out_file);
5010 output_uleb128 (abbrev->die_tag);
5012 fprintf (asm_out_file, " (TAG: %s)",
5013 dwarf_tag_name (abbrev->die_tag));
5015 fputc ('\n', asm_out_file);
5016 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
5017 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
5020 fprintf (asm_out_file, "\t%s %s",
5022 (abbrev->die_child != NULL
5023 ? "DW_children_yes" : "DW_children_no"));
5025 fputc ('\n', asm_out_file);
5027 for (a_attr = abbrev->die_attr; a_attr != NULL;
5028 a_attr = a_attr->dw_attr_next)
5030 output_uleb128 (a_attr->dw_attr);
5032 fprintf (asm_out_file, " (%s)",
5033 dwarf_attr_name (a_attr->dw_attr));
5035 fputc ('\n', asm_out_file);
5036 output_value_format (&a_attr->dw_attr_val);
5039 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
5042 /* Terminate the table. */
5043 fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP);
5046 /* Output location description stack opcode's operands (if any). */
5049 output_loc_operands (loc)
5050 register dw_loc_descr_ref loc;
5052 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
5053 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
5055 switch (loc->dw_loc_opc)
5058 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
5059 fputc ('\n', asm_out_file);
5063 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
5064 fputc ('\n', asm_out_file);
5068 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
5069 fputc ('\n', asm_out_file);
5073 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
5074 fputc ('\n', asm_out_file);
5079 fputc ('\n', asm_out_file);
5082 output_uleb128 (val1->v.val_unsigned);
5083 fputc ('\n', asm_out_file);
5086 output_sleb128 (val1->v.val_int);
5087 fputc ('\n', asm_out_file);
5090 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
5091 fputc ('\n', asm_out_file);
5093 case DW_OP_plus_uconst:
5094 output_uleb128 (val1->v.val_unsigned);
5095 fputc ('\n', asm_out_file);
5099 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
5100 fputc ('\n', asm_out_file);
5134 output_sleb128 (val1->v.val_int);
5135 fputc ('\n', asm_out_file);
5138 output_uleb128 (val1->v.val_unsigned);
5139 fputc ('\n', asm_out_file);
5142 output_sleb128 (val1->v.val_int);
5143 fputc ('\n', asm_out_file);
5146 output_uleb128 (val1->v.val_unsigned);
5147 fputc ('\n', asm_out_file);
5148 output_sleb128 (val2->v.val_int);
5149 fputc ('\n', asm_out_file);
5152 output_uleb128 (val1->v.val_unsigned);
5153 fputc ('\n', asm_out_file);
5155 case DW_OP_deref_size:
5156 case DW_OP_xderef_size:
5157 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
5158 fputc ('\n', asm_out_file);
5165 /* Compute the offset of a sibling. */
5167 static unsigned long
5168 sibling_offset (die)
5171 unsigned long offset;
5173 if (die->die_child_last == NULL)
5174 offset = die->die_offset + size_of_die (die);
5176 offset = sibling_offset (die->die_child_last) + 1;
5181 /* Output the DIE and its attributes. Called recursively to generate
5182 the definitions of each child DIE. */
5186 register dw_die_ref die;
5188 register dw_attr_ref a;
5189 register dw_die_ref c;
5190 register unsigned long ref_offset;
5191 register unsigned long size;
5192 register dw_loc_descr_ref loc;
5194 output_uleb128 (die->die_abbrev);
5196 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5197 die->die_offset, dwarf_tag_name (die->die_tag));
5199 fputc ('\n', asm_out_file);
5201 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5203 switch (a->dw_attr_val.val_class)
5205 case dw_val_class_addr:
5206 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
5207 a->dw_attr_val.v.val_addr);
5210 case dw_val_class_loc:
5211 size = size_of_locs (a->dw_attr_val.v.val_loc);
5213 /* Output the block length for this list of location operations. */
5214 switch (constant_size (size))
5217 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5220 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5227 fprintf (asm_out_file, "\t%s %s",
5228 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5230 fputc ('\n', asm_out_file);
5231 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
5232 loc = loc->dw_loc_next)
5234 /* Output the opcode. */
5235 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
5237 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
5238 dwarf_stack_op_name (loc->dw_loc_opc));
5240 fputc ('\n', asm_out_file);
5242 /* Output the operand(s) (if any). */
5243 output_loc_operands (loc);
5247 case dw_val_class_const:
5248 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
5251 case dw_val_class_unsigned_const:
5252 switch (constant_size (a->dw_attr_val.v.val_unsigned))
5255 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5256 a->dw_attr_val.v.val_unsigned);
5259 ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
5260 a->dw_attr_val.v.val_unsigned);
5263 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5264 a->dw_attr_val.v.val_unsigned);
5267 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5268 a->dw_attr_val.v.val_long_long.hi,
5269 a->dw_attr_val.v.val_long_long.low);
5276 case dw_val_class_long_long:
5277 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5279 fprintf (asm_out_file, "\t%s %s",
5280 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5282 fputc ('\n', asm_out_file);
5283 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5284 a->dw_attr_val.v.val_long_long.hi,
5285 a->dw_attr_val.v.val_long_long.low);
5288 fprintf (asm_out_file,
5289 "\t%s long long constant", ASM_COMMENT_START);
5291 fputc ('\n', asm_out_file);
5294 case dw_val_class_float:
5296 register unsigned int i;
5297 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5298 a->dw_attr_val.v.val_float.length * 4);
5300 fprintf (asm_out_file, "\t%s %s",
5301 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5303 fputc ('\n', asm_out_file);
5304 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5306 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5307 a->dw_attr_val.v.val_float.array[i]);
5309 fprintf (asm_out_file, "\t%s fp constant word %u",
5310 ASM_COMMENT_START, i);
5312 fputc ('\n', asm_out_file);
5317 case dw_val_class_flag:
5318 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
5321 case dw_val_class_die_ref:
5322 if (a->dw_attr_val.v.val_die_ref != NULL)
5323 ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
5324 else if (a->dw_attr == DW_AT_sibling)
5325 ref_offset = sibling_offset(die);
5329 ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
5332 case dw_val_class_fde_ref:
5335 ASM_GENERATE_INTERNAL_LABEL
5336 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5337 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5338 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5342 case dw_val_class_lbl_id:
5343 ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
5346 case dw_val_class_lbl_offset:
5347 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, a->dw_attr_val.v.val_lbl_id);
5350 case dw_val_class_str:
5352 ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
5354 ASM_OUTPUT_ASCII (asm_out_file,
5355 a->dw_attr_val.v.val_str,
5356 (int) strlen (a->dw_attr_val.v.val_str) + 1);
5363 if (a->dw_attr_val.val_class != dw_val_class_loc
5364 && a->dw_attr_val.val_class != dw_val_class_long_long
5365 && a->dw_attr_val.val_class != dw_val_class_float)
5368 fprintf (asm_out_file, "\t%s %s",
5369 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5371 fputc ('\n', asm_out_file);
5375 for (c = die->die_child; c != NULL; c = c->die_sib)
5378 if (die->die_child != NULL)
5380 /* Add null byte to terminate sibling list. */
5381 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5383 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
5384 ASM_COMMENT_START, die->die_offset);
5386 fputc ('\n', asm_out_file);
5390 /* Output the compilation unit that appears at the beginning of the
5391 .debug_info section, and precedes the DIE descriptions. */
5394 output_compilation_unit_header ()
5396 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
5398 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
5401 fputc ('\n', asm_out_file);
5402 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5404 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
5406 fputc ('\n', asm_out_file);
5407 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
5409 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
5412 fputc ('\n', asm_out_file);
5413 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5415 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
5417 fputc ('\n', asm_out_file);
5420 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5421 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5422 argument list, and maybe the scope. */
5425 dwarf2_name (decl, scope)
5429 return (*decl_printable_name) (decl, scope ? 1 : 0);
5432 /* Add a new entry to .debug_pubnames if appropriate. */
5435 add_pubname (decl, die)
5441 if (! TREE_PUBLIC (decl))
5444 if (pubname_table_in_use == pubname_table_allocated)
5446 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5447 pubname_table = (pubname_ref) xrealloc
5448 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5451 p = &pubname_table[pubname_table_in_use++];
5454 p->name = xstrdup (dwarf2_name (decl, 1));
5457 /* Output the public names table used to speed up access to externally
5458 visible names. For now, only generate entries for externally
5459 visible procedures. */
5464 register unsigned i;
5465 register unsigned long pubnames_length = size_of_pubnames ();
5467 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
5470 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
5473 fputc ('\n', asm_out_file);
5474 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5477 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5479 fputc ('\n', asm_out_file);
5480 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5482 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5485 fputc ('\n', asm_out_file);
5486 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
5488 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
5490 fputc ('\n', asm_out_file);
5491 for (i = 0; i < pubname_table_in_use; ++i)
5493 register pubname_ref pub = &pubname_table[i];
5495 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
5497 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
5499 fputc ('\n', asm_out_file);
5503 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
5504 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
5508 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
5509 (int) strlen (pub->name) + 1);
5512 fputc ('\n', asm_out_file);
5515 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
5516 fputc ('\n', asm_out_file);
5519 /* Add a new entry to .debug_aranges if appropriate. */
5522 add_arange (decl, die)
5526 if (! DECL_SECTION_NAME (decl))
5529 if (arange_table_in_use == arange_table_allocated)
5531 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5533 = (arange_ref) xrealloc (arange_table,
5534 arange_table_allocated * sizeof (dw_die_ref));
5537 arange_table[arange_table_in_use++] = die;
5540 /* Output the information that goes into the .debug_aranges table.
5541 Namely, define the beginning and ending address range of the
5542 text section generated for this compilation unit. */
5547 register unsigned i;
5548 register unsigned long aranges_length = size_of_aranges ();
5550 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
5552 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
5555 fputc ('\n', asm_out_file);
5556 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5558 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5560 fputc ('\n', asm_out_file);
5561 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5563 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5566 fputc ('\n', asm_out_file);
5567 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5569 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
5571 fputc ('\n', asm_out_file);
5572 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5574 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
5577 fputc ('\n', asm_out_file);
5578 /* We need to align to twice the pointer size here.
5579 If DWARF_OFFSET_SIZE == 4, then we have emitted 12 bytes, and need 4
5580 bytes of padding to align for either 4 or 8 byte pointers. */
5581 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5582 /* If DWARF_OFFSET_SIZE == 8, then we have emitted 20 bytes, and need 12
5583 bytes of padding to align for 8 byte pointers. We have already emitted
5584 4 bytes of padding, so emit 8 more here. */
5585 if (DWARF_OFFSET_SIZE == 8)
5586 fprintf (asm_out_file, ",0,0");
5589 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5590 ASM_COMMENT_START, 2 * PTR_SIZE);
5592 fputc ('\n', asm_out_file);
5593 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
5595 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5597 fputc ('\n', asm_out_file);
5598 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
5599 text_section_label);
5601 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5603 fputc ('\n', asm_out_file);
5604 for (i = 0; i < arange_table_in_use; ++i)
5606 dw_die_ref die = arange_table[i];
5608 if (die->die_tag == DW_TAG_subprogram)
5609 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
5612 /* A static variable; extract the symbol from DW_AT_location.
5613 Note that this code isn't currently hit, as we only emit
5614 aranges for functions (jason 9/23/99). */
5616 dw_attr_ref a = get_AT (die, DW_AT_location);
5617 dw_loc_descr_ref loc;
5618 if (! a || a->dw_attr_val.val_class != dw_val_class_loc)
5621 loc = a->dw_attr_val.v.val_loc;
5622 if (loc->dw_loc_opc != DW_OP_addr)
5625 ASM_OUTPUT_DWARF_ADDR (asm_out_file, loc->dw_loc_oprnd1.v.val_addr);
5629 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5631 fputc ('\n', asm_out_file);
5632 if (die->die_tag == DW_TAG_subprogram)
5633 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
5634 get_AT_low_pc (die));
5636 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5637 get_AT_unsigned (die, DW_AT_byte_size));
5640 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5642 fputc ('\n', asm_out_file);
5645 /* Output the terminator words. */
5646 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5647 fputc ('\n', asm_out_file);
5648 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5649 fputc ('\n', asm_out_file);
5652 /* Output the source line number correspondence information. This
5653 information goes into the .debug_line section.
5655 If the format of this data changes, then the function size_of_line_info
5656 must also be adjusted the same way. */
5661 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5662 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5663 register unsigned opc;
5664 register unsigned n_op_args;
5665 register unsigned long ft_index;
5666 register unsigned long lt_index;
5667 register unsigned long current_line;
5668 register long line_offset;
5669 register long line_delta;
5670 register unsigned long current_file;
5671 register unsigned long function;
5673 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ());
5675 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5678 fputc ('\n', asm_out_file);
5679 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5681 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5683 fputc ('\n', asm_out_file);
5684 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
5686 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5688 fputc ('\n', asm_out_file);
5689 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
5691 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5694 fputc ('\n', asm_out_file);
5695 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
5697 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5700 fputc ('\n', asm_out_file);
5701 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
5703 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5706 fputc ('\n', asm_out_file);
5707 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
5709 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5712 fputc ('\n', asm_out_file);
5713 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5715 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5717 fputc ('\n', asm_out_file);
5718 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5722 case DW_LNS_advance_pc:
5723 case DW_LNS_advance_line:
5724 case DW_LNS_set_file:
5725 case DW_LNS_set_column:
5726 case DW_LNS_fixed_advance_pc:
5733 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5735 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5736 ASM_COMMENT_START, opc, n_op_args);
5737 fputc ('\n', asm_out_file);
5741 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5743 /* Include directory table is empty, at present */
5744 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5745 fputc ('\n', asm_out_file);
5747 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5749 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5753 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5754 fprintf (asm_out_file, "%s File Entry: 0x%lx",
5755 ASM_COMMENT_START, ft_index);
5759 ASM_OUTPUT_ASCII (asm_out_file,
5760 file_table[ft_index],
5761 (int) strlen (file_table[ft_index]) + 1);
5764 fputc ('\n', asm_out_file);
5766 /* Include directory index */
5768 fputc ('\n', asm_out_file);
5770 /* Modification time */
5772 fputc ('\n', asm_out_file);
5774 /* File length in bytes */
5776 fputc ('\n', asm_out_file);
5779 /* Terminate the file name table */
5780 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5781 fputc ('\n', asm_out_file);
5783 /* We used to set the address register to the first location in the text
5784 section here, but that didn't accomplish anything since we already
5785 have a line note for the opening brace of the first function. */
5787 /* Generate the line number to PC correspondence table, encoded as
5788 a series of state machine operations. */
5791 strcpy (prev_line_label, text_section_label);
5792 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5794 register dw_line_info_ref line_info = &line_info_table[lt_index];
5796 /* Don't emit anything for redundant notes. Just updating the
5797 address doesn't accomplish anything, because we already assume
5798 that anything after the last address is this line. */
5799 if (line_info->dw_line_num == current_line
5800 && line_info->dw_file_num == current_file)
5803 /* Emit debug info for the address of the current line, choosing
5804 the encoding that uses the least amount of space. */
5805 /* ??? Unfortunately, we have little choice here currently, and must
5806 always use the most general form. Gcc does not know the address
5807 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5808 dwarf2 aware assemblers at this time, so we can't use any special
5809 pseudo ops that would allow the assembler to optimally encode this for
5810 us. Many ports do have length attributes which will give an upper
5811 bound on the address range. We could perhaps use length attributes
5812 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5813 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5816 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5817 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5819 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5822 fputc ('\n', asm_out_file);
5823 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5824 fputc ('\n', asm_out_file);
5828 /* This can handle any delta. This takes 4+PTR_SIZE bytes. */
5829 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5831 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5833 fputc ('\n', asm_out_file);
5834 output_uleb128 (1 + PTR_SIZE);
5835 fputc ('\n', asm_out_file);
5836 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5837 fputc ('\n', asm_out_file);
5838 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5839 fputc ('\n', asm_out_file);
5841 strcpy (prev_line_label, line_label);
5843 /* Emit debug info for the source file of the current line, if
5844 different from the previous line. */
5845 if (line_info->dw_file_num != current_file)
5847 current_file = line_info->dw_file_num;
5848 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5850 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5852 fputc ('\n', asm_out_file);
5853 output_uleb128 (current_file);
5855 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5857 fputc ('\n', asm_out_file);
5860 /* Emit debug info for the current line number, choosing the encoding
5861 that uses the least amount of space. */
5862 if (line_info->dw_line_num != current_line)
5864 line_offset = line_info->dw_line_num - current_line;
5865 line_delta = line_offset - DWARF_LINE_BASE;
5866 current_line = line_info->dw_line_num;
5867 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5869 /* This can handle deltas from -10 to 234, using the current
5870 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5872 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5873 DWARF_LINE_OPCODE_BASE + line_delta);
5875 fprintf (asm_out_file,
5876 "\t%s line %ld", ASM_COMMENT_START, current_line);
5878 fputc ('\n', asm_out_file);
5882 /* This can handle any delta. This takes at least 4 bytes,
5883 depending on the value being encoded. */
5884 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5886 fprintf (asm_out_file, "\t%s advance to line %ld",
5887 ASM_COMMENT_START, current_line);
5889 fputc ('\n', asm_out_file);
5890 output_sleb128 (line_offset);
5891 fputc ('\n', asm_out_file);
5892 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5894 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5895 fputc ('\n', asm_out_file);
5900 /* We still need to start a new row, so output a copy insn. */
5901 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5903 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5904 fputc ('\n', asm_out_file);
5908 /* Emit debug info for the address of the end of the function. */
5911 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5913 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5916 fputc ('\n', asm_out_file);
5917 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
5918 fputc ('\n', asm_out_file);
5922 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5924 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5925 fputc ('\n', asm_out_file);
5926 output_uleb128 (1 + PTR_SIZE);
5927 fputc ('\n', asm_out_file);
5928 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5929 fputc ('\n', asm_out_file);
5930 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
5931 fputc ('\n', asm_out_file);
5934 /* Output the marker for the end of the line number info. */
5935 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5937 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
5939 fputc ('\n', asm_out_file);
5941 fputc ('\n', asm_out_file);
5942 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5943 fputc ('\n', asm_out_file);
5948 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5950 register dw_separate_line_info_ref line_info
5951 = &separate_line_info_table[lt_index];
5953 /* Don't emit anything for redundant notes. */
5954 if (line_info->dw_line_num == current_line
5955 && line_info->dw_file_num == current_file
5956 && line_info->function == function)
5959 /* Emit debug info for the address of the current line. If this is
5960 a new function, or the first line of a function, then we need
5961 to handle it differently. */
5962 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
5964 if (function != line_info->function)
5966 function = line_info->function;
5968 /* Set the address register to the first line in the function */
5969 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5971 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5974 fputc ('\n', asm_out_file);
5975 output_uleb128 (1 + PTR_SIZE);
5976 fputc ('\n', asm_out_file);
5977 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5978 fputc ('\n', asm_out_file);
5979 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5980 fputc ('\n', asm_out_file);
5984 /* ??? See the DW_LNS_advance_pc comment above. */
5987 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5989 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5992 fputc ('\n', asm_out_file);
5993 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5995 fputc ('\n', asm_out_file);
5999 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6001 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6003 fputc ('\n', asm_out_file);
6004 output_uleb128 (1 + PTR_SIZE);
6005 fputc ('\n', asm_out_file);
6006 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6007 fputc ('\n', asm_out_file);
6008 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6009 fputc ('\n', asm_out_file);
6012 strcpy (prev_line_label, line_label);
6014 /* Emit debug info for the source file of the current line, if
6015 different from the previous line. */
6016 if (line_info->dw_file_num != current_file)
6018 current_file = line_info->dw_file_num;
6019 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6021 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6023 fputc ('\n', asm_out_file);
6024 output_uleb128 (current_file);
6026 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
6028 fputc ('\n', asm_out_file);
6031 /* Emit debug info for the current line number, choosing the encoding
6032 that uses the least amount of space. */
6033 if (line_info->dw_line_num != current_line)
6035 line_offset = line_info->dw_line_num - current_line;
6036 line_delta = line_offset - DWARF_LINE_BASE;
6037 current_line = line_info->dw_line_num;
6038 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6040 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6041 DWARF_LINE_OPCODE_BASE + line_delta);
6043 fprintf (asm_out_file,
6044 "\t%s line %ld", ASM_COMMENT_START, current_line);
6046 fputc ('\n', asm_out_file);
6050 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6052 fprintf (asm_out_file, "\t%s advance to line %ld",
6053 ASM_COMMENT_START, current_line);
6055 fputc ('\n', asm_out_file);
6056 output_sleb128 (line_offset);
6057 fputc ('\n', asm_out_file);
6058 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6060 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6061 fputc ('\n', asm_out_file);
6066 /* We still need to start a new row, so output a copy insn. */
6067 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6069 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6070 fputc ('\n', asm_out_file);
6076 /* If we're done with a function, end its sequence. */
6077 if (lt_index == separate_line_info_table_in_use
6078 || separate_line_info_table[lt_index].function != function)
6083 /* Emit debug info for the address of the end of the function. */
6084 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6087 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6089 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6092 fputc ('\n', asm_out_file);
6093 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6095 fputc ('\n', asm_out_file);
6099 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6101 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6103 fputc ('\n', asm_out_file);
6104 output_uleb128 (1 + PTR_SIZE);
6105 fputc ('\n', asm_out_file);
6106 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6107 fputc ('\n', asm_out_file);
6108 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6109 fputc ('\n', asm_out_file);
6112 /* Output the marker for the end of this sequence. */
6113 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6115 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
6118 fputc ('\n', asm_out_file);
6120 fputc ('\n', asm_out_file);
6121 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6122 fputc ('\n', asm_out_file);
6127 /* Given a pointer to a BLOCK node return non-zero if (and only if) the node
6128 in question represents the outermost pair of curly braces (i.e. the "body
6129 block") of a function or method.
6131 For any BLOCK node representing a "body block" of a function or method, the
6132 BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
6133 represents the outermost (function) scope for the function or method (i.e.
6134 the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
6135 *that* node in turn will point to the relevant FUNCTION_DECL node. */
6138 is_body_block (stmt)
6141 if (TREE_CODE (stmt) == BLOCK)
6143 register tree parent = BLOCK_SUPERCONTEXT (stmt);
6145 if (TREE_CODE (parent) == BLOCK)
6147 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
6149 if (TREE_CODE (grandparent) == FUNCTION_DECL)
6157 /* Given a pointer to a tree node for some base type, return a pointer to
6158 a DIE that describes the given type.
6160 This routine must only be called for GCC type nodes that correspond to
6161 Dwarf base (fundamental) types. */
6164 base_type_die (type)
6167 register dw_die_ref base_type_result;
6168 register const char *type_name;
6169 register enum dwarf_type encoding;
6170 register tree name = TYPE_NAME (type);
6172 if (TREE_CODE (type) == ERROR_MARK
6173 || TREE_CODE (type) == VOID_TYPE)
6178 if (TREE_CODE (name) == TYPE_DECL)
6179 name = DECL_NAME (name);
6181 type_name = IDENTIFIER_POINTER (name);
6184 type_name = "__unknown__";
6186 switch (TREE_CODE (type))
6189 /* Carefully distinguish the C character types, without messing
6190 up if the language is not C. Note that we check only for the names
6191 that contain spaces; other names might occur by coincidence in other
6193 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6194 && (type == char_type_node
6195 || ! strcmp (type_name, "signed char")
6196 || ! strcmp (type_name, "unsigned char"))))
6198 if (TREE_UNSIGNED (type))
6199 encoding = DW_ATE_unsigned;
6201 encoding = DW_ATE_signed;
6204 /* else fall through */
6207 /* GNU Pascal/Ada CHAR type. Not used in C. */
6208 if (TREE_UNSIGNED (type))
6209 encoding = DW_ATE_unsigned_char;
6211 encoding = DW_ATE_signed_char;
6215 encoding = DW_ATE_float;
6218 /* Dwarf2 doesn't know anything about complex ints, so use
6219 a user defined type for it. */
6221 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6222 encoding = DW_ATE_complex_float;
6224 encoding = DW_ATE_lo_user;
6228 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6229 encoding = DW_ATE_boolean;
6233 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6236 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6237 add_AT_string (base_type_result, DW_AT_name, type_name);
6238 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6239 int_size_in_bytes (type));
6240 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6242 return base_type_result;
6245 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6246 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6247 a given type is generally the same as the given type, except that if the
6248 given type is a pointer or reference type, then the root type of the given
6249 type is the root type of the "basis" type for the pointer or reference
6250 type. (This definition of the "root" type is recursive.) Also, the root
6251 type of a `const' qualified type or a `volatile' qualified type is the
6252 root type of the given type without the qualifiers. */
6258 if (TREE_CODE (type) == ERROR_MARK)
6259 return error_mark_node;
6261 switch (TREE_CODE (type))
6264 return error_mark_node;
6267 case REFERENCE_TYPE:
6268 return type_main_variant (root_type (TREE_TYPE (type)));
6271 return type_main_variant (type);
6275 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6276 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6282 switch (TREE_CODE (type))
6297 case QUAL_UNION_TYPE:
6302 case REFERENCE_TYPE:
6315 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6316 entry that chains various modifiers in front of the given type. */
6319 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6321 register int is_const_type;
6322 register int is_volatile_type;
6323 register dw_die_ref context_die;
6325 register enum tree_code code = TREE_CODE (type);
6326 register dw_die_ref mod_type_die = NULL;
6327 register dw_die_ref sub_die = NULL;
6328 register tree item_type = NULL;
6330 if (code != ERROR_MARK)
6332 type = build_type_variant (type, is_const_type, is_volatile_type);
6334 mod_type_die = lookup_type_die (type);
6336 return mod_type_die;
6338 /* Handle C typedef types. */
6339 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6340 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6342 tree dtype = TREE_TYPE (TYPE_NAME (type));
6345 /* For a named type, use the typedef. */
6346 gen_type_die (type, context_die);
6347 mod_type_die = lookup_type_die (type);
6350 else if (is_const_type < TYPE_READONLY (dtype)
6351 || is_volatile_type < TYPE_VOLATILE (dtype))
6352 /* cv-unqualified version of named type. Just use the unnamed
6353 type to which it refers. */
6355 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6356 is_const_type, is_volatile_type,
6358 /* Else cv-qualified version of named type; fall through. */
6363 else if (is_const_type)
6365 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6366 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6368 else if (is_volatile_type)
6370 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6371 sub_die = modified_type_die (type, 0, 0, context_die);
6373 else if (code == POINTER_TYPE)
6375 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6376 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6378 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6380 item_type = TREE_TYPE (type);
6382 else if (code == REFERENCE_TYPE)
6384 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6385 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6387 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6389 item_type = TREE_TYPE (type);
6391 else if (is_base_type (type))
6392 mod_type_die = base_type_die (type);
6395 gen_type_die (type, context_die);
6397 /* We have to get the type_main_variant here (and pass that to the
6398 `lookup_type_die' routine) because the ..._TYPE node we have
6399 might simply be a *copy* of some original type node (where the
6400 copy was created to help us keep track of typedef names) and
6401 that copy might have a different TYPE_UID from the original
6403 mod_type_die = lookup_type_die (type_main_variant (type));
6404 if (mod_type_die == NULL)
6409 equate_type_number_to_die (type, mod_type_die);
6411 /* We must do this after the equate_type_number_to_die call, in case
6412 this is a recursive type. This ensures that the modified_type_die
6413 recursion will terminate even if the type is recursive. Recursive
6414 types are possible in Ada. */
6415 sub_die = modified_type_die (item_type,
6416 TYPE_READONLY (item_type),
6417 TYPE_VOLATILE (item_type),
6420 if (sub_die != NULL)
6421 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6423 return mod_type_die;
6426 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6427 an enumerated type. */
6433 return TREE_CODE (type) == ENUMERAL_TYPE;
6436 /* Return a location descriptor that designates a machine register. */
6438 static dw_loc_descr_ref
6439 reg_loc_descriptor (rtl)
6442 register dw_loc_descr_ref loc_result = NULL;
6443 register unsigned reg = reg_number (rtl);
6446 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6448 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6453 /* Return a location descriptor that designates a base+offset location. */
6455 static dw_loc_descr_ref
6456 based_loc_descr (reg, offset)
6460 register dw_loc_descr_ref loc_result;
6461 /* For the "frame base", we use the frame pointer or stack pointer
6462 registers, since the RTL for local variables is relative to one of
6464 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6465 ? HARD_FRAME_POINTER_REGNUM
6466 : STACK_POINTER_REGNUM);
6469 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
6471 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
6473 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
6478 /* Return true if this RTL expression describes a base+offset calculation. */
6484 return (GET_CODE (rtl) == PLUS
6485 && ((GET_CODE (XEXP (rtl, 0)) == REG
6486 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
6489 /* The following routine converts the RTL for a variable or parameter
6490 (resident in memory) into an equivalent Dwarf representation of a
6491 mechanism for getting the address of that same variable onto the top of a
6492 hypothetical "address evaluation" stack.
6494 When creating memory location descriptors, we are effectively transforming
6495 the RTL for a memory-resident object into its Dwarf postfix expression
6496 equivalent. This routine recursively descends an RTL tree, turning
6497 it into Dwarf postfix code as it goes.
6499 MODE is the mode of the memory reference, needed to handle some
6500 autoincrement addressing modes. */
6502 static dw_loc_descr_ref
6503 mem_loc_descriptor (rtl, mode)
6505 enum machine_mode mode;
6507 dw_loc_descr_ref mem_loc_result = NULL;
6508 /* Note that for a dynamically sized array, the location we will generate a
6509 description of here will be the lowest numbered location which is
6510 actually within the array. That's *not* necessarily the same as the
6511 zeroth element of the array. */
6513 switch (GET_CODE (rtl))
6517 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
6518 just fall into the SUBREG code. */
6520 /* ... fall through ... */
6523 /* The case of a subreg may arise when we have a local (register)
6524 variable or a formal (register) parameter which doesn't quite fill
6525 up an entire register. For now, just assume that it is
6526 legitimate to make the Dwarf info refer to the whole register which
6527 contains the given subreg. */
6528 rtl = XEXP (rtl, 0);
6530 /* ... fall through ... */
6533 /* Whenever a register number forms a part of the description of the
6534 method for calculating the (dynamic) address of a memory resident
6535 object, DWARF rules require the register number be referred to as
6536 a "base register". This distinction is not based in any way upon
6537 what category of register the hardware believes the given register
6538 belongs to. This is strictly DWARF terminology we're dealing with
6539 here. Note that in cases where the location of a memory-resident
6540 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6541 OP_CONST (0)) the actual DWARF location descriptor that we generate
6542 may just be OP_BASEREG (basereg). This may look deceptively like
6543 the object in question was allocated to a register (rather than in
6544 memory) so DWARF consumers need to be aware of the subtle
6545 distinction between OP_REG and OP_BASEREG. */
6546 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
6550 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
6551 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6555 /* Some ports can transform a symbol ref into a label ref, because
6556 the symbol ref is too far away and has to be dumped into a constant
6560 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6561 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6562 mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
6567 /* Turn these into a PLUS expression and fall into the PLUS code
6569 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
6570 GEN_INT (GET_CODE (rtl) == PRE_INC
6571 ? GET_MODE_UNIT_SIZE (mode)
6572 : - GET_MODE_UNIT_SIZE (mode)));
6574 /* ... fall through ... */
6577 if (is_based_loc (rtl))
6578 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
6579 INTVAL (XEXP (rtl, 1)));
6582 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0),
6584 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1),
6586 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
6591 /* If a pseudo-reg is optimized away, it is possible for it to
6592 be replaced with a MEM containing a multiply. */
6593 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode));
6594 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode));
6595 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
6599 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6606 return mem_loc_result;
6609 /* Return a descriptor that describes the concatenation of two locations.
6610 This is typically a complex variable. */
6612 static dw_loc_descr_ref
6613 concat_loc_descriptor (x0, x1)
6614 register rtx x0, x1;
6616 dw_loc_descr_ref cc_loc_result = NULL;
6618 if (!is_pseudo_reg (x0)
6619 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
6620 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
6621 add_loc_descr (&cc_loc_result,
6622 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
6624 if (!is_pseudo_reg (x1)
6625 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
6626 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
6627 add_loc_descr (&cc_loc_result,
6628 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
6630 return cc_loc_result;
6633 /* Output a proper Dwarf location descriptor for a variable or parameter
6634 which is either allocated in a register or in a memory location. For a
6635 register, we just generate an OP_REG and the register number. For a
6636 memory location we provide a Dwarf postfix expression describing how to
6637 generate the (dynamic) address of the object onto the address stack. */
6639 static dw_loc_descr_ref
6640 loc_descriptor (rtl)
6643 dw_loc_descr_ref loc_result = NULL;
6644 switch (GET_CODE (rtl))
6647 /* The case of a subreg may arise when we have a local (register)
6648 variable or a formal (register) parameter which doesn't quite fill
6649 up an entire register. For now, just assume that it is
6650 legitimate to make the Dwarf info refer to the whole register which
6651 contains the given subreg. */
6652 rtl = XEXP (rtl, 0);
6654 /* ... fall through ... */
6657 loc_result = reg_loc_descriptor (rtl);
6661 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
6665 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
6675 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
6676 which is not less than the value itself. */
6678 static inline unsigned
6679 ceiling (value, boundary)
6680 register unsigned value;
6681 register unsigned boundary;
6683 return (((value + boundary - 1) / boundary) * boundary);
6686 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6687 pointer to the declared type for the relevant field variable, or return
6688 `integer_type_node' if the given node turns out to be an
6697 if (TREE_CODE (decl) == ERROR_MARK)
6698 return integer_type_node;
6700 type = DECL_BIT_FIELD_TYPE (decl);
6701 if (type == NULL_TREE)
6702 type = TREE_TYPE (decl);
6707 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6708 node, return the alignment in bits for the type, or else return
6709 BITS_PER_WORD if the node actually turns out to be an
6712 static inline unsigned
6713 simple_type_align_in_bits (type)
6716 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6719 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6720 node, return the size in bits for the type if it is a constant, or else
6721 return the alignment for the type if the type's size is not constant, or
6722 else return BITS_PER_WORD if the type actually turns out to be an
6725 static inline unsigned
6726 simple_type_size_in_bits (type)
6729 if (TREE_CODE (type) == ERROR_MARK)
6730 return BITS_PER_WORD;
6733 register tree type_size_tree = TYPE_SIZE (type);
6735 if (TREE_CODE (type_size_tree) != INTEGER_CST)
6736 return TYPE_ALIGN (type);
6738 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
6742 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6743 return the byte offset of the lowest addressed byte of the "containing
6744 object" for the given FIELD_DECL, or return 0 if we are unable to
6745 determine what that offset is, either because the argument turns out to
6746 be a pointer to an ERROR_MARK node, or because the offset is actually
6747 variable. (We can't handle the latter case just yet). */
6750 field_byte_offset (decl)
6753 register unsigned type_align_in_bytes;
6754 register unsigned type_align_in_bits;
6755 register unsigned type_size_in_bits;
6756 register unsigned object_offset_in_align_units;
6757 register unsigned object_offset_in_bits;
6758 register unsigned object_offset_in_bytes;
6760 register tree bitpos_tree;
6761 register tree field_size_tree;
6762 register unsigned bitpos_int;
6763 register unsigned deepest_bitpos;
6764 register unsigned field_size_in_bits;
6766 if (TREE_CODE (decl) == ERROR_MARK)
6769 if (TREE_CODE (decl) != FIELD_DECL)
6772 type = field_type (decl);
6774 bitpos_tree = DECL_FIELD_BITPOS (decl);
6775 field_size_tree = DECL_SIZE (decl);
6777 /* We cannot yet cope with fields whose positions or sizes are variable, so
6778 for now, when we see such things, we simply return 0. Someday, we may
6779 be able to handle such cases, but it will be damn difficult. */
6780 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6782 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6784 if (TREE_CODE (field_size_tree) != INTEGER_CST)
6787 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
6788 type_size_in_bits = simple_type_size_in_bits (type);
6789 type_align_in_bits = simple_type_align_in_bits (type);
6790 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6792 /* Note that the GCC front-end doesn't make any attempt to keep track of
6793 the starting bit offset (relative to the start of the containing
6794 structure type) of the hypothetical "containing object" for a bit-
6795 field. Thus, when computing the byte offset value for the start of the
6796 "containing object" of a bit-field, we must deduce this information on
6797 our own. This can be rather tricky to do in some cases. For example,
6798 handling the following structure type definition when compiling for an
6799 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6802 struct S { int field1; long long field2:31; };
6804 Fortunately, there is a simple rule-of-thumb which can be
6805 used in such cases. When compiling for an i386/i486, GCC will allocate
6806 8 bytes for the structure shown above. It decides to do this based upon
6807 one simple rule for bit-field allocation. Quite simply, GCC allocates
6808 each "containing object" for each bit-field at the first (i.e. lowest
6809 addressed) legitimate alignment boundary (based upon the required
6810 minimum alignment for the declared type of the field) which it can
6811 possibly use, subject to the condition that there is still enough
6812 available space remaining in the containing object (when allocated at
6813 the selected point) to fully accommodate all of the bits of the
6814 bit-field itself. This simple rule makes it obvious why GCC allocates
6815 8 bytes for each object of the structure type shown above. When looking
6816 for a place to allocate the "containing object" for `field2', the
6817 compiler simply tries to allocate a 64-bit "containing object" at each
6818 successive 32-bit boundary (starting at zero) until it finds a place to
6819 allocate that 64- bit field such that at least 31 contiguous (and
6820 previously unallocated) bits remain within that selected 64 bit field.
6821 (As it turns out, for the example above, the compiler finds that it is
6822 OK to allocate the "containing object" 64-bit field at bit-offset zero
6823 within the structure type.) Here we attempt to work backwards from the
6824 limited set of facts we're given, and we try to deduce from those facts,
6825 where GCC must have believed that the containing object started (within
6826 the structure type). The value we deduce is then used (by the callers of
6827 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6828 for fields (both bit-fields and, in the case of DW_AT_location, regular
6831 /* Figure out the bit-distance from the start of the structure to the
6832 "deepest" bit of the bit-field. */
6833 deepest_bitpos = bitpos_int + field_size_in_bits;
6835 /* This is the tricky part. Use some fancy footwork to deduce where the
6836 lowest addressed bit of the containing object must be. */
6837 object_offset_in_bits
6838 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6840 /* Compute the offset of the containing object in "alignment units". */
6841 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6843 /* Compute the offset of the containing object in bytes. */
6844 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6846 return object_offset_in_bytes;
6849 /* The following routines define various Dwarf attributes and any data
6850 associated with them. */
6852 /* Add a location description attribute value to a DIE.
6854 This emits location attributes suitable for whole variables and
6855 whole parameters. Note that the location attributes for struct fields are
6856 generated by the routine `data_member_location_attribute' below. */
6859 add_AT_location_description (die, attr_kind, rtl)
6861 enum dwarf_attribute attr_kind;
6864 /* Handle a special case. If we are about to output a location descriptor
6865 for a variable or parameter which has been optimized out of existence,
6866 don't do that. A variable which has been optimized out
6867 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6868 Currently, in some rare cases, variables can have DECL_RTL values which
6869 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6870 elsewhere in the compiler. We treat such cases as if the variable(s) in
6871 question had been optimized out of existence. */
6873 if (is_pseudo_reg (rtl)
6874 || (GET_CODE (rtl) == MEM
6875 && is_pseudo_reg (XEXP (rtl, 0)))
6876 || (GET_CODE (rtl) == CONCAT
6877 && is_pseudo_reg (XEXP (rtl, 0))
6878 && is_pseudo_reg (XEXP (rtl, 1))))
6881 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
6884 /* Attach the specialized form of location attribute used for data
6885 members of struct and union types. In the special case of a
6886 FIELD_DECL node which represents a bit-field, the "offset" part
6887 of this special location descriptor must indicate the distance
6888 in bytes from the lowest-addressed byte of the containing struct
6889 or union type to the lowest-addressed byte of the "containing
6890 object" for the bit-field. (See the `field_byte_offset' function
6891 above).. For any given bit-field, the "containing object" is a
6892 hypothetical object (of some integral or enum type) within which
6893 the given bit-field lives. The type of this hypothetical
6894 "containing object" is always the same as the declared type of
6895 the individual bit-field itself (for GCC anyway... the DWARF
6896 spec doesn't actually mandate this). Note that it is the size
6897 (in bytes) of the hypothetical "containing object" which will
6898 be given in the DW_AT_byte_size attribute for this bit-field.
6899 (See the `byte_size_attribute' function below.) It is also used
6900 when calculating the value of the DW_AT_bit_offset attribute.
6901 (See the `bit_offset_attribute' function below). */
6904 add_data_member_location_attribute (die, decl)
6905 register dw_die_ref die;
6908 register unsigned long offset;
6909 register dw_loc_descr_ref loc_descr;
6910 register enum dwarf_location_atom op;
6912 if (TREE_CODE (decl) == TREE_VEC)
6913 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
6915 offset = field_byte_offset (decl);
6917 /* The DWARF2 standard says that we should assume that the structure address
6918 is already on the stack, so we can specify a structure field address
6919 by using DW_OP_plus_uconst. */
6921 #ifdef MIPS_DEBUGGING_INFO
6922 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6923 correctly. It works only if we leave the offset on the stack. */
6926 op = DW_OP_plus_uconst;
6929 loc_descr = new_loc_descr (op, offset, 0);
6930 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6933 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6934 does not have a "location" either in memory or in a register. These
6935 things can arise in GNU C when a constant is passed as an actual parameter
6936 to an inlined function. They can also arise in C++ where declared
6937 constants do not necessarily get memory "homes". */
6940 add_const_value_attribute (die, rtl)
6941 register dw_die_ref die;
6944 switch (GET_CODE (rtl))
6947 /* Note that a CONST_INT rtx could represent either an integer or a
6948 floating-point constant. A CONST_INT is used whenever the constant
6949 will fit into a single word. In all such cases, the original mode
6950 of the constant value is wiped out, and the CONST_INT rtx is
6951 assigned VOIDmode. */
6952 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6956 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6957 floating-point constant. A CONST_DOUBLE is used whenever the
6958 constant requires more than one word in order to be adequately
6959 represented. We output CONST_DOUBLEs as blocks. */
6961 register enum machine_mode mode = GET_MODE (rtl);
6963 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6965 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6969 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6973 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6977 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6982 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6989 add_AT_float (die, DW_AT_const_value, length, array);
6992 add_AT_long_long (die, DW_AT_const_value,
6993 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6998 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
7004 add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
7008 /* In cases where an inlined instance of an inline function is passed
7009 the address of an `auto' variable (which is local to the caller) we
7010 can get a situation where the DECL_RTL of the artificial local
7011 variable (for the inlining) which acts as a stand-in for the
7012 corresponding formal parameter (of the inline function) will look
7013 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
7014 exactly a compile-time constant expression, but it isn't the address
7015 of the (artificial) local variable either. Rather, it represents the
7016 *value* which the artificial local variable always has during its
7017 lifetime. We currently have no way to represent such quasi-constant
7018 values in Dwarf, so for now we just punt and generate nothing. */
7022 /* No other kinds of rtx should be possible here. */
7028 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
7029 data attribute for a variable or a parameter. We generate the
7030 DW_AT_const_value attribute only in those cases where the given variable
7031 or parameter does not have a true "location" either in memory or in a
7032 register. This can happen (for example) when a constant is passed as an
7033 actual argument in a call to an inline function. (It's possible that
7034 these things can crop up in other ways also.) Note that one type of
7035 constant value which can be passed into an inlined function is a constant
7036 pointer. This can happen for example if an actual argument in an inlined
7037 function call evaluates to a compile-time constant address. */
7040 add_location_or_const_value_attribute (die, decl)
7041 register dw_die_ref die;
7045 register tree declared_type;
7046 register tree passed_type;
7048 if (TREE_CODE (decl) == ERROR_MARK)
7051 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
7054 /* Here we have to decide where we are going to say the parameter "lives"
7055 (as far as the debugger is concerned). We only have a couple of
7056 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
7058 DECL_RTL normally indicates where the parameter lives during most of the
7059 activation of the function. If optimization is enabled however, this
7060 could be either NULL or else a pseudo-reg. Both of those cases indicate
7061 that the parameter doesn't really live anywhere (as far as the code
7062 generation parts of GCC are concerned) during most of the function's
7063 activation. That will happen (for example) if the parameter is never
7064 referenced within the function.
7066 We could just generate a location descriptor here for all non-NULL
7067 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
7068 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
7069 where DECL_RTL is NULL or is a pseudo-reg.
7071 Note however that we can only get away with using DECL_INCOMING_RTL as
7072 a backup substitute for DECL_RTL in certain limited cases. In cases
7073 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
7074 we can be sure that the parameter was passed using the same type as it is
7075 declared to have within the function, and that its DECL_INCOMING_RTL
7076 points us to a place where a value of that type is passed.
7078 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
7079 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
7080 because in these cases DECL_INCOMING_RTL points us to a value of some
7081 type which is *different* from the type of the parameter itself. Thus,
7082 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
7083 such cases, the debugger would end up (for example) trying to fetch a
7084 `float' from a place which actually contains the first part of a
7085 `double'. That would lead to really incorrect and confusing
7086 output at debug-time.
7088 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
7089 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
7090 are a couple of exceptions however. On little-endian machines we can
7091 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
7092 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
7093 an integral type that is smaller than TREE_TYPE (decl). These cases arise
7094 when (on a little-endian machine) a non-prototyped function has a
7095 parameter declared to be of type `short' or `char'. In such cases,
7096 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
7097 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
7098 passed `int' value. If the debugger then uses that address to fetch
7099 a `short' or a `char' (on a little-endian machine) the result will be
7100 the correct data, so we allow for such exceptional cases below.
7102 Note that our goal here is to describe the place where the given formal
7103 parameter lives during most of the function's activation (i.e. between
7104 the end of the prologue and the start of the epilogue). We'll do that
7105 as best as we can. Note however that if the given formal parameter is
7106 modified sometime during the execution of the function, then a stack
7107 backtrace (at debug-time) will show the function as having been
7108 called with the *new* value rather than the value which was
7109 originally passed in. This happens rarely enough that it is not
7110 a major problem, but it *is* a problem, and I'd like to fix it.
7112 A future version of dwarf2out.c may generate two additional
7113 attributes for any given DW_TAG_formal_parameter DIE which will
7114 describe the "passed type" and the "passed location" for the
7115 given formal parameter in addition to the attributes we now
7116 generate to indicate the "declared type" and the "active
7117 location" for each parameter. This additional set of attributes
7118 could be used by debuggers for stack backtraces. Separately, note
7119 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
7120 NULL also. This happens (for example) for inlined-instances of
7121 inline function formal parameters which are never referenced.
7122 This really shouldn't be happening. All PARM_DECL nodes should
7123 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
7124 doesn't currently generate these values for inlined instances of
7125 inline function parameters, so when we see such cases, we are
7126 just out-of-luck for the time being (until integrate.c
7129 /* Use DECL_RTL as the "location" unless we find something better. */
7130 rtl = DECL_RTL (decl);
7132 if (TREE_CODE (decl) == PARM_DECL)
7134 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
7136 declared_type = type_main_variant (TREE_TYPE (decl));
7137 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
7139 /* This decl represents a formal parameter which was optimized out.
7140 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
7141 all* cases where (rtl == NULL_RTX) just below. */
7142 if (declared_type == passed_type)
7143 rtl = DECL_INCOMING_RTL (decl);
7144 else if (! BYTES_BIG_ENDIAN
7145 && TREE_CODE (declared_type) == INTEGER_TYPE
7146 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
7147 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
7148 rtl = DECL_INCOMING_RTL (decl);
7151 /* If the parm was passed in registers, but lives on the stack, then
7152 make a big endian correction if the mode of the type of the
7153 parameter is not the same as the mode of the rtl. */
7154 /* ??? This is the same series of checks that are made in dbxout.c before
7155 we reach the big endian correction code there. It isn't clear if all
7156 of these checks are necessary here, but keeping them all is the safe
7158 else if (GET_CODE (rtl) == MEM
7159 && XEXP (rtl, 0) != const0_rtx
7160 && ! CONSTANT_P (XEXP (rtl, 0))
7161 /* Not passed in memory. */
7162 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
7163 /* Not passed by invisible reference. */
7164 && (GET_CODE (XEXP (rtl, 0)) != REG
7165 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
7166 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
7167 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
7168 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
7171 /* Big endian correction check. */
7173 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
7174 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
7177 int offset = (UNITS_PER_WORD
7178 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
7179 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
7180 plus_constant (XEXP (rtl, 0), offset));
7184 if (rtl == NULL_RTX)
7187 rtl = eliminate_regs (rtl, 0, NULL_RTX);
7188 #ifdef LEAF_REG_REMAP
7189 if (current_function_uses_only_leaf_regs)
7190 leaf_renumber_regs_insn (rtl);
7193 switch (GET_CODE (rtl))
7196 /* The address of a variable that was optimized away; don't emit
7207 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7208 add_const_value_attribute (die, rtl);
7215 add_AT_location_description (die, DW_AT_location, rtl);
7223 /* Generate an DW_AT_name attribute given some string value to be included as
7224 the value of the attribute. */
7227 add_name_attribute (die, name_string)
7228 register dw_die_ref die;
7229 register const char *name_string;
7231 if (name_string != NULL && *name_string != 0)
7232 add_AT_string (die, DW_AT_name, name_string);
7235 /* Given a tree node describing an array bound (either lower or upper) output
7236 a representation for that bound. */
7239 add_bound_info (subrange_die, bound_attr, bound)
7240 register dw_die_ref subrange_die;
7241 register enum dwarf_attribute bound_attr;
7242 register tree bound;
7244 register unsigned bound_value = 0;
7246 /* If this is an Ada unconstrained array type, then don't emit any debug
7247 info because the array bounds are unknown. They are parameterized when
7248 the type is instantiated. */
7249 if (contains_placeholder_p (bound))
7252 switch (TREE_CODE (bound))
7257 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7259 bound_value = TREE_INT_CST_LOW (bound);
7260 if (bound_attr == DW_AT_lower_bound
7261 && ((is_c_family () && bound_value == 0)
7262 || (is_fortran () && bound_value == 1)))
7263 /* use the default */;
7265 add_AT_unsigned (subrange_die, bound_attr, bound_value);
7270 case NON_LVALUE_EXPR:
7271 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7275 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7276 access the upper bound values may be bogus. If they refer to a
7277 register, they may only describe how to get at these values at the
7278 points in the generated code right after they have just been
7279 computed. Worse yet, in the typical case, the upper bound values
7280 will not even *be* computed in the optimized code (though the
7281 number of elements will), so these SAVE_EXPRs are entirely
7282 bogus. In order to compensate for this fact, we check here to see
7283 if optimization is enabled, and if so, we don't add an attribute
7284 for the (unknown and unknowable) upper bound. This should not
7285 cause too much trouble for existing (stupid?) debuggers because
7286 they have to deal with empty upper bounds location descriptions
7287 anyway in order to be able to deal with incomplete array types.
7288 Of course an intelligent debugger (GDB?) should be able to
7289 comprehend that a missing upper bound specification in a array
7290 type used for a storage class `auto' local array variable
7291 indicates that the upper bound is both unknown (at compile- time)
7292 and unknowable (at run-time) due to optimization.
7294 We assume that a MEM rtx is safe because gcc wouldn't put the
7295 value there unless it was going to be used repeatedly in the
7296 function, i.e. for cleanups. */
7297 if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)
7299 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7300 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7301 register rtx loc = SAVE_EXPR_RTL (bound);
7303 /* If the RTL for the SAVE_EXPR is memory, handle the case where
7304 it references an outer function's frame. */
7306 if (GET_CODE (loc) == MEM)
7308 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
7310 if (XEXP (loc, 0) != new_addr)
7311 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
7314 add_AT_flag (decl_die, DW_AT_artificial, 1);
7315 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
7316 add_AT_location_description (decl_die, DW_AT_location, loc);
7317 add_AT_die_ref (subrange_die, bound_attr, decl_die);
7320 /* Else leave out the attribute. */
7326 /* ??? These types of bounds can be created by the Ada front end,
7327 and it isn't clear how to emit debug info for them. */
7335 /* Note that the block of subscript information for an array type also
7336 includes information about the element type of type given array type. */
7339 add_subscript_info (type_die, type)
7340 register dw_die_ref type_die;
7343 #ifndef MIPS_DEBUGGING_INFO
7344 register unsigned dimension_number;
7346 register tree lower, upper;
7347 register dw_die_ref subrange_die;
7349 /* The GNU compilers represent multidimensional array types as sequences of
7350 one dimensional array types whose element types are themselves array
7351 types. Here we squish that down, so that each multidimensional array
7352 type gets only one array_type DIE in the Dwarf debugging info. The draft
7353 Dwarf specification say that we are allowed to do this kind of
7354 compression in C (because there is no difference between an array or
7355 arrays and a multidimensional array in C) but for other source languages
7356 (e.g. Ada) we probably shouldn't do this. */
7358 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7359 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7360 We work around this by disabling this feature. See also
7361 gen_array_type_die. */
7362 #ifndef MIPS_DEBUGGING_INFO
7363 for (dimension_number = 0;
7364 TREE_CODE (type) == ARRAY_TYPE;
7365 type = TREE_TYPE (type), dimension_number++)
7368 register tree domain = TYPE_DOMAIN (type);
7370 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7371 and (in GNU C only) variable bounds. Handle all three forms
7373 subrange_die = new_die (DW_TAG_subrange_type, type_die);
7376 /* We have an array type with specified bounds. */
7377 lower = TYPE_MIN_VALUE (domain);
7378 upper = TYPE_MAX_VALUE (domain);
7380 /* define the index type. */
7381 if (TREE_TYPE (domain))
7383 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7384 TREE_TYPE field. We can't emit debug info for this
7385 because it is an unnamed integral type. */
7386 if (TREE_CODE (domain) == INTEGER_TYPE
7387 && TYPE_NAME (domain) == NULL_TREE
7388 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
7389 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
7392 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
7396 /* ??? If upper is NULL, the array has unspecified length,
7397 but it does have a lower bound. This happens with Fortran
7399 Since the debugger is definitely going to need to know N
7400 to produce useful results, go ahead and output the lower
7401 bound solo, and hope the debugger can cope. */
7403 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
7405 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
7408 /* We have an array type with an unspecified length. The DWARF-2
7409 spec does not say how to handle this; let's just leave out the
7414 #ifndef MIPS_DEBUGGING_INFO
7420 add_byte_size_attribute (die, tree_node)
7422 register tree tree_node;
7424 register unsigned size;
7426 switch (TREE_CODE (tree_node))
7434 case QUAL_UNION_TYPE:
7435 size = int_size_in_bytes (tree_node);
7438 /* For a data member of a struct or union, the DW_AT_byte_size is
7439 generally given as the number of bytes normally allocated for an
7440 object of the *declared* type of the member itself. This is true
7441 even for bit-fields. */
7442 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
7448 /* Note that `size' might be -1 when we get to this point. If it is, that
7449 indicates that the byte size of the entity in question is variable. We
7450 have no good way of expressing this fact in Dwarf at the present time,
7451 so just let the -1 pass on through. */
7453 add_AT_unsigned (die, DW_AT_byte_size, size);
7456 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7457 which specifies the distance in bits from the highest order bit of the
7458 "containing object" for the bit-field to the highest order bit of the
7461 For any given bit-field, the "containing object" is a hypothetical
7462 object (of some integral or enum type) within which the given bit-field
7463 lives. The type of this hypothetical "containing object" is always the
7464 same as the declared type of the individual bit-field itself. The
7465 determination of the exact location of the "containing object" for a
7466 bit-field is rather complicated. It's handled by the
7467 `field_byte_offset' function (above).
7469 Note that it is the size (in bytes) of the hypothetical "containing object"
7470 which will be given in the DW_AT_byte_size attribute for this bit-field.
7471 (See `byte_size_attribute' above). */
7474 add_bit_offset_attribute (die, decl)
7475 register dw_die_ref die;
7478 register unsigned object_offset_in_bytes = field_byte_offset (decl);
7479 register tree type = DECL_BIT_FIELD_TYPE (decl);
7480 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
7481 register unsigned bitpos_int;
7482 register unsigned highest_order_object_bit_offset;
7483 register unsigned highest_order_field_bit_offset;
7484 register unsigned bit_offset;
7486 /* Must be a field and a bit field. */
7488 || TREE_CODE (decl) != FIELD_DECL)
7491 /* We can't yet handle bit-fields whose offsets are variable, so if we
7492 encounter such things, just return without generating any attribute
7494 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
7497 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
7499 /* Note that the bit offset is always the distance (in bits) from the
7500 highest-order bit of the "containing object" to the highest-order bit of
7501 the bit-field itself. Since the "high-order end" of any object or field
7502 is different on big-endian and little-endian machines, the computation
7503 below must take account of these differences. */
7504 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
7505 highest_order_field_bit_offset = bitpos_int;
7507 if (! BYTES_BIG_ENDIAN)
7509 highest_order_field_bit_offset
7510 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
7512 highest_order_object_bit_offset += simple_type_size_in_bits (type);
7516 = (! BYTES_BIG_ENDIAN
7517 ? highest_order_object_bit_offset - highest_order_field_bit_offset
7518 : highest_order_field_bit_offset - highest_order_object_bit_offset);
7520 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
7523 /* For a FIELD_DECL node which represents a bit field, output an attribute
7524 which specifies the length in bits of the given field. */
7527 add_bit_size_attribute (die, decl)
7528 register dw_die_ref die;
7531 /* Must be a field and a bit field. */
7532 if (TREE_CODE (decl) != FIELD_DECL
7533 || ! DECL_BIT_FIELD_TYPE (decl))
7535 add_AT_unsigned (die, DW_AT_bit_size,
7536 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
7539 /* If the compiled language is ANSI C, then add a 'prototyped'
7540 attribute, if arg types are given for the parameters of a function. */
7543 add_prototyped_attribute (die, func_type)
7544 register dw_die_ref die;
7545 register tree func_type;
7547 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
7548 && TYPE_ARG_TYPES (func_type) != NULL)
7549 add_AT_flag (die, DW_AT_prototyped, 1);
7553 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7554 by looking in either the type declaration or object declaration
7558 add_abstract_origin_attribute (die, origin)
7559 register dw_die_ref die;
7560 register tree origin;
7562 dw_die_ref origin_die = NULL;
7564 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
7565 origin_die = lookup_decl_die (origin);
7566 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
7567 origin_die = lookup_type_die (origin);
7569 if (origin_die == NULL)
7572 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
7575 /* We do not currently support the pure_virtual attribute. */
7578 add_pure_or_virtual_attribute (die, func_decl)
7579 register dw_die_ref die;
7580 register tree func_decl;
7582 if (DECL_VINDEX (func_decl))
7584 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7585 add_AT_loc (die, DW_AT_vtable_elem_location,
7586 new_loc_descr (DW_OP_constu,
7587 TREE_INT_CST_LOW (DECL_VINDEX (func_decl)),
7590 /* GNU extension: Record what type this method came from originally. */
7591 if (debug_info_level > DINFO_LEVEL_TERSE)
7592 add_AT_die_ref (die, DW_AT_containing_type,
7593 lookup_type_die (DECL_CONTEXT (func_decl)));
7597 /* Add source coordinate attributes for the given decl. */
7600 add_src_coords_attributes (die, decl)
7601 register dw_die_ref die;
7604 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
7606 add_AT_unsigned (die, DW_AT_decl_file, file_index);
7607 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7610 /* Add an DW_AT_name attribute and source coordinate attribute for the
7611 given decl, but only if it actually has a name. */
7614 add_name_and_src_coords_attributes (die, decl)
7615 register dw_die_ref die;
7618 register tree decl_name;
7620 decl_name = DECL_NAME (decl);
7621 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
7623 add_name_attribute (die, dwarf2_name (decl, 0));
7624 add_src_coords_attributes (die, decl);
7626 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
7627 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
7628 add_AT_string (die, DW_AT_MIPS_linkage_name,
7629 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
7633 /* Push a new declaration scope. */
7636 push_decl_scope (scope)
7639 tree containing_scope;
7642 /* Make room in the decl_scope_table, if necessary. */
7643 if (decl_scope_table_allocated == decl_scope_depth)
7645 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
7647 = (decl_scope_node *) xrealloc (decl_scope_table,
7648 (decl_scope_table_allocated
7649 * sizeof (decl_scope_node)));
7652 decl_scope_table[decl_scope_depth].scope = scope;
7654 /* Sometimes, while recursively emitting subtypes within a class type,
7655 we end up recuring on a subtype at a higher level then the current
7656 subtype. In such a case, we need to search the decl_scope_table to
7657 find the parent of this subtype. */
7659 if (AGGREGATE_TYPE_P (scope))
7660 containing_scope = TYPE_CONTEXT (scope);
7662 containing_scope = NULL_TREE;
7664 /* The normal case. */
7665 if (decl_scope_depth == 0
7666 || containing_scope == NULL_TREE
7667 /* Ignore namespaces for the moment. */
7668 || TREE_CODE (containing_scope) == NAMESPACE_DECL
7669 || containing_scope == decl_scope_table[decl_scope_depth - 1].scope)
7670 decl_scope_table[decl_scope_depth].previous = decl_scope_depth - 1;
7673 /* We need to search for the containing_scope. */
7674 for (i = 0; i < decl_scope_depth; i++)
7675 if (decl_scope_table[i].scope == containing_scope)
7678 if (i == decl_scope_depth)
7681 decl_scope_table[decl_scope_depth].previous = i;
7687 /* Return the DIE for the scope that immediately contains this declaration. */
7690 scope_die_for (t, context_die)
7692 register dw_die_ref context_die;
7694 register dw_die_ref scope_die = NULL;
7695 register tree containing_scope;
7698 /* Walk back up the declaration tree looking for a place to define
7700 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
7701 containing_scope = TYPE_CONTEXT (t);
7702 else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t))
7703 containing_scope = decl_class_context (t);
7705 containing_scope = DECL_CONTEXT (t);
7707 /* Ignore namespaces for the moment. */
7708 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
7709 containing_scope = NULL_TREE;
7711 /* Ignore function type "scopes" from the C frontend. They mean that
7712 a tagged type is local to a parmlist of a function declarator, but
7713 that isn't useful to DWARF. */
7714 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
7715 containing_scope = NULL_TREE;
7717 /* Function-local tags and functions get stuck in limbo until they are
7718 fixed up by decls_for_scope. */
7719 if (context_die == NULL && containing_scope != NULL_TREE
7720 && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t)))
7723 if (containing_scope == NULL_TREE)
7724 scope_die = comp_unit_die;
7727 for (i = decl_scope_depth - 1, scope_die = context_die;
7728 i >= 0 && decl_scope_table[i].scope != containing_scope;
7729 (scope_die = scope_die->die_parent,
7730 i = decl_scope_table[i].previous))
7733 /* ??? Integrate_decl_tree does not handle BLOCK_TYPE_TAGS, nor
7734 does it try to handle types defined by TYPE_DECLs. Such types
7735 thus have an incorrect TYPE_CONTEXT, which points to the block
7736 they were originally defined in, instead of the current block
7737 created by function inlining. We try to detect that here and
7740 if (i < 0 && scope_die == comp_unit_die
7741 && TREE_CODE (containing_scope) == BLOCK
7742 && is_tagged_type (t)
7743 && (block_ultimate_origin (decl_scope_table[decl_scope_depth - 1].scope)
7744 == containing_scope))
7746 scope_die = context_die;
7747 /* Since the checks below are no longer applicable. */
7753 if (TREE_CODE_CLASS (TREE_CODE (containing_scope)) != 't')
7755 if (debug_info_level > DINFO_LEVEL_TERSE
7756 && !TREE_ASM_WRITTEN (containing_scope))
7759 /* If none of the current dies are suitable, we get file scope. */
7760 scope_die = comp_unit_die;
7767 /* Pop a declaration scope. */
7771 if (decl_scope_depth <= 0)
7776 /* Many forms of DIEs require a "type description" attribute. This
7777 routine locates the proper "type descriptor" die for the type given
7778 by 'type', and adds an DW_AT_type attribute below the given die. */
7781 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
7782 register dw_die_ref object_die;
7784 register int decl_const;
7785 register int decl_volatile;
7786 register dw_die_ref context_die;
7788 register enum tree_code code = TREE_CODE (type);
7789 register dw_die_ref type_die = NULL;
7791 /* ??? If this type is an unnamed subrange type of an integral or
7792 floating-point type, use the inner type. This is because we have no
7793 support for unnamed types in base_type_die. This can happen if this is
7794 an Ada subrange type. Correct solution is emit a subrange type die. */
7795 if ((code == INTEGER_TYPE || code == REAL_TYPE)
7796 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
7797 type = TREE_TYPE (type), code = TREE_CODE (type);
7799 if (code == ERROR_MARK)
7802 /* Handle a special case. For functions whose return type is void, we
7803 generate *no* type attribute. (Note that no object may have type
7804 `void', so this only applies to function return types). */
7805 if (code == VOID_TYPE)
7808 type_die = modified_type_die (type,
7809 decl_const || TYPE_READONLY (type),
7810 decl_volatile || TYPE_VOLATILE (type),
7812 if (type_die != NULL)
7813 add_AT_die_ref (object_die, DW_AT_type, type_die);
7816 /* Given a tree pointer to a struct, class, union, or enum type node, return
7817 a pointer to the (string) tag name for the given type, or zero if the type
7818 was declared without a tag. */
7824 register char *name = 0;
7826 if (TYPE_NAME (type) != 0)
7828 register tree t = 0;
7830 /* Find the IDENTIFIER_NODE for the type name. */
7831 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7832 t = TYPE_NAME (type);
7834 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7835 a TYPE_DECL node, regardless of whether or not a `typedef' was
7837 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7838 && ! DECL_IGNORED_P (TYPE_NAME (type)))
7839 t = DECL_NAME (TYPE_NAME (type));
7841 /* Now get the name as a string, or invent one. */
7843 name = IDENTIFIER_POINTER (t);
7846 return (name == 0 || *name == '\0') ? 0 : name;
7849 /* Return the type associated with a data member, make a special check
7850 for bit field types. */
7853 member_declared_type (member)
7854 register tree member;
7856 return (DECL_BIT_FIELD_TYPE (member)
7857 ? DECL_BIT_FIELD_TYPE (member)
7858 : TREE_TYPE (member));
7861 /* Get the decl's label, as described by its RTL. This may be different
7862 from the DECL_NAME name used in the source file. */
7866 decl_start_label (decl)
7871 x = DECL_RTL (decl);
7872 if (GET_CODE (x) != MEM)
7876 if (GET_CODE (x) != SYMBOL_REF)
7879 fnname = XSTR (x, 0);
7884 /* These routines generate the internal representation of the DIE's for
7885 the compilation unit. Debugging information is collected by walking
7886 the declaration trees passed in from dwarf2out_decl(). */
7889 gen_array_type_die (type, context_die)
7891 register dw_die_ref context_die;
7893 register dw_die_ref scope_die = scope_die_for (type, context_die);
7894 register dw_die_ref array_die;
7895 register tree element_type;
7897 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7898 the inner array type comes before the outer array type. Thus we must
7899 call gen_type_die before we call new_die. See below also. */
7900 #ifdef MIPS_DEBUGGING_INFO
7901 gen_type_die (TREE_TYPE (type), context_die);
7904 array_die = new_die (DW_TAG_array_type, scope_die);
7907 /* We default the array ordering. SDB will probably do
7908 the right things even if DW_AT_ordering is not present. It's not even
7909 an issue until we start to get into multidimensional arrays anyway. If
7910 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7911 then we'll have to put the DW_AT_ordering attribute back in. (But if
7912 and when we find out that we need to put these in, we will only do so
7913 for multidimensional arrays. */
7914 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
7917 #ifdef MIPS_DEBUGGING_INFO
7918 /* The SGI compilers handle arrays of unknown bound by setting
7919 AT_declaration and not emitting any subrange DIEs. */
7920 if (! TYPE_DOMAIN (type))
7921 add_AT_unsigned (array_die, DW_AT_declaration, 1);
7924 add_subscript_info (array_die, type);
7926 equate_type_number_to_die (type, array_die);
7928 /* Add representation of the type of the elements of this array type. */
7929 element_type = TREE_TYPE (type);
7931 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7932 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7933 We work around this by disabling this feature. See also
7934 add_subscript_info. */
7935 #ifndef MIPS_DEBUGGING_INFO
7936 while (TREE_CODE (element_type) == ARRAY_TYPE)
7937 element_type = TREE_TYPE (element_type);
7939 gen_type_die (element_type, context_die);
7942 add_type_attribute (array_die, element_type, 0, 0, context_die);
7946 gen_set_type_die (type, context_die)
7948 register dw_die_ref context_die;
7950 register dw_die_ref type_die
7951 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7953 equate_type_number_to_die (type, type_die);
7954 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7959 gen_entry_point_die (decl, context_die)
7961 register dw_die_ref context_die;
7963 register tree origin = decl_ultimate_origin (decl);
7964 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
7966 add_abstract_origin_attribute (decl_die, origin);
7969 add_name_and_src_coords_attributes (decl_die, decl);
7970 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
7974 if (DECL_ABSTRACT (decl))
7975 equate_decl_number_to_die (decl, decl_die);
7977 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
7981 /* Remember a type in the pending_types_list. */
7987 if (pending_types == pending_types_allocated)
7989 pending_types_allocated += PENDING_TYPES_INCREMENT;
7991 = (tree *) xrealloc (pending_types_list,
7992 sizeof (tree) * pending_types_allocated);
7995 pending_types_list[pending_types++] = type;
7998 /* Output any pending types (from the pending_types list) which we can output
7999 now (taking into account the scope that we are working on now).
8001 For each type output, remove the given type from the pending_types_list
8002 *before* we try to output it. */
8005 output_pending_types_for_scope (context_die)
8006 register dw_die_ref context_die;
8010 while (pending_types)
8013 type = pending_types_list[pending_types];
8014 gen_type_die (type, context_die);
8015 if (!TREE_ASM_WRITTEN (type))
8020 /* Remember a type in the incomplete_types_list. */
8023 add_incomplete_type (type)
8026 if (incomplete_types == incomplete_types_allocated)
8028 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
8029 incomplete_types_list
8030 = (tree *) xrealloc (incomplete_types_list,
8031 sizeof (tree) * incomplete_types_allocated);
8034 incomplete_types_list[incomplete_types++] = type;
8037 /* Walk through the list of incomplete types again, trying once more to
8038 emit full debugging info for them. */
8041 retry_incomplete_types ()
8045 while (incomplete_types)
8048 type = incomplete_types_list[incomplete_types];
8049 gen_type_die (type, comp_unit_die);
8053 /* Generate a DIE to represent an inlined instance of an enumeration type. */
8056 gen_inlined_enumeration_type_die (type, context_die)
8058 register dw_die_ref context_die;
8060 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
8061 scope_die_for (type, context_die));
8062 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8063 be incomplete and such types are not marked. */
8064 add_abstract_origin_attribute (type_die, type);
8067 /* Generate a DIE to represent an inlined instance of a structure type. */
8070 gen_inlined_structure_type_die (type, context_die)
8072 register dw_die_ref context_die;
8074 register dw_die_ref type_die = new_die (DW_TAG_structure_type,
8075 scope_die_for (type, context_die));
8076 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8077 be incomplete and such types are not marked. */
8078 add_abstract_origin_attribute (type_die, type);
8081 /* Generate a DIE to represent an inlined instance of a union type. */
8084 gen_inlined_union_type_die (type, context_die)
8086 register dw_die_ref context_die;
8088 register dw_die_ref type_die = new_die (DW_TAG_union_type,
8089 scope_die_for (type, context_die));
8090 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8091 be incomplete and such types are not marked. */
8092 add_abstract_origin_attribute (type_die, type);
8095 /* Generate a DIE to represent an enumeration type. Note that these DIEs
8096 include all of the information about the enumeration values also. Each
8097 enumerated type name/value is listed as a child of the enumerated type
8101 gen_enumeration_type_die (type, context_die)
8103 register dw_die_ref context_die;
8105 register dw_die_ref type_die = lookup_type_die (type);
8107 if (type_die == NULL)
8109 type_die = new_die (DW_TAG_enumeration_type,
8110 scope_die_for (type, context_die));
8111 equate_type_number_to_die (type, type_die);
8112 add_name_attribute (type_die, type_tag (type));
8114 else if (! TYPE_SIZE (type))
8117 remove_AT (type_die, DW_AT_declaration);
8119 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
8120 given enum type is incomplete, do not generate the DW_AT_byte_size
8121 attribute or the DW_AT_element_list attribute. */
8122 if (TYPE_SIZE (type))
8126 TREE_ASM_WRITTEN (type) = 1;
8127 add_byte_size_attribute (type_die, type);
8128 if (TYPE_STUB_DECL (type) != NULL_TREE)
8129 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8131 /* If the first reference to this type was as the return type of an
8132 inline function, then it may not have a parent. Fix this now. */
8133 if (type_die->die_parent == NULL)
8134 add_child_die (scope_die_for (type, context_die), type_die);
8136 for (link = TYPE_FIELDS (type);
8137 link != NULL; link = TREE_CHAIN (link))
8139 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
8141 add_name_attribute (enum_die,
8142 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
8143 add_AT_unsigned (enum_die, DW_AT_const_value,
8144 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
8148 add_AT_flag (type_die, DW_AT_declaration, 1);
8152 /* Generate a DIE to represent either a real live formal parameter decl or to
8153 represent just the type of some formal parameter position in some function
8156 Note that this routine is a bit unusual because its argument may be a
8157 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
8158 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
8159 node. If it's the former then this function is being called to output a
8160 DIE to represent a formal parameter object (or some inlining thereof). If
8161 it's the latter, then this function is only being called to output a
8162 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
8163 argument type of some subprogram type. */
8166 gen_formal_parameter_die (node, context_die)
8168 register dw_die_ref context_die;
8170 register dw_die_ref parm_die
8171 = new_die (DW_TAG_formal_parameter, context_die);
8172 register tree origin;
8174 switch (TREE_CODE_CLASS (TREE_CODE (node)))
8177 origin = decl_ultimate_origin (node);
8179 add_abstract_origin_attribute (parm_die, origin);
8182 add_name_and_src_coords_attributes (parm_die, node);
8183 add_type_attribute (parm_die, TREE_TYPE (node),
8184 TREE_READONLY (node),
8185 TREE_THIS_VOLATILE (node),
8187 if (DECL_ARTIFICIAL (node))
8188 add_AT_flag (parm_die, DW_AT_artificial, 1);
8191 equate_decl_number_to_die (node, parm_die);
8192 if (! DECL_ABSTRACT (node))
8193 add_location_or_const_value_attribute (parm_die, node);
8198 /* We were called with some kind of a ..._TYPE node. */
8199 add_type_attribute (parm_die, node, 0, 0, context_die);
8209 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
8210 at the end of an (ANSI prototyped) formal parameters list. */
8213 gen_unspecified_parameters_die (decl_or_type, context_die)
8214 register tree decl_or_type ATTRIBUTE_UNUSED;
8215 register dw_die_ref context_die;
8217 new_die (DW_TAG_unspecified_parameters, context_die);
8220 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
8221 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
8222 parameters as specified in some function type specification (except for
8223 those which appear as part of a function *definition*).
8225 Note we must be careful here to output all of the parameter DIEs before*
8226 we output any DIEs needed to represent the types of the formal parameters.
8227 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
8228 non-parameter DIE it sees ends the formal parameter list. */
8231 gen_formal_types_die (function_or_method_type, context_die)
8232 register tree function_or_method_type;
8233 register dw_die_ref context_die;
8236 register tree formal_type = NULL;
8237 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
8240 /* In the case where we are generating a formal types list for a C++
8241 non-static member function type, skip over the first thing on the
8242 TYPE_ARG_TYPES list because it only represents the type of the hidden
8243 `this pointer'. The debugger should be able to figure out (without
8244 being explicitly told) that this non-static member function type takes a
8245 `this pointer' and should be able to figure what the type of that hidden
8246 parameter is from the DW_AT_member attribute of the parent
8247 DW_TAG_subroutine_type DIE. */
8248 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
8249 first_parm_type = TREE_CHAIN (first_parm_type);
8252 /* Make our first pass over the list of formal parameter types and output a
8253 DW_TAG_formal_parameter DIE for each one. */
8254 for (link = first_parm_type; link; link = TREE_CHAIN (link))
8256 register dw_die_ref parm_die;
8258 formal_type = TREE_VALUE (link);
8259 if (formal_type == void_type_node)
8262 /* Output a (nameless) DIE to represent the formal parameter itself. */
8263 parm_die = gen_formal_parameter_die (formal_type, context_die);
8264 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8265 && link == first_parm_type)
8266 add_AT_flag (parm_die, DW_AT_artificial, 1);
8269 /* If this function type has an ellipsis, add a
8270 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8271 if (formal_type != void_type_node)
8272 gen_unspecified_parameters_die (function_or_method_type, context_die);
8274 /* Make our second (and final) pass over the list of formal parameter types
8275 and output DIEs to represent those types (as necessary). */
8276 for (link = TYPE_ARG_TYPES (function_or_method_type);
8278 link = TREE_CHAIN (link))
8280 formal_type = TREE_VALUE (link);
8281 if (formal_type == void_type_node)
8284 gen_type_die (formal_type, context_die);
8288 /* Generate a DIE to represent a declared function (either file-scope or
8292 gen_subprogram_die (decl, context_die)
8294 register dw_die_ref context_die;
8296 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
8297 register tree origin = decl_ultimate_origin (decl);
8298 register dw_die_ref subr_die;
8299 register rtx fp_reg;
8300 register tree fn_arg_types;
8301 register tree outer_scope;
8302 register dw_die_ref old_die = lookup_decl_die (decl);
8303 register int declaration
8304 = (current_function_decl != decl
8306 && (context_die->die_tag == DW_TAG_structure_type
8307 || context_die->die_tag == DW_TAG_union_type)));
8311 subr_die = new_die (DW_TAG_subprogram, context_die);
8312 add_abstract_origin_attribute (subr_die, origin);
8314 else if (old_die && DECL_ABSTRACT (decl)
8315 && get_AT_unsigned (old_die, DW_AT_inline))
8317 /* This must be a redefinition of an extern inline function.
8318 We can just reuse the old die here. */
8321 /* Clear out the inlined attribute and parm types. */
8322 remove_AT (subr_die, DW_AT_inline);
8323 remove_children (subr_die);
8327 register unsigned file_index
8328 = lookup_filename (DECL_SOURCE_FILE (decl));
8330 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
8332 /* ??? This can happen if there is a bug in the program, for
8333 instance, if it has duplicate function definitions. Ideally,
8334 we should detect this case and ignore it. For now, if we have
8335 already reported an error, any error at all, then assume that
8336 we got here because of a input error, not a dwarf2 bug. */
8342 /* If the definition comes from the same place as the declaration,
8343 maybe use the old DIE. We always want the DIE for this function
8344 that has the *_pc attributes to be under comp_unit_die so the
8345 debugger can find it. For inlines, that is the concrete instance,
8346 so we can use the old DIE here. For non-inline methods, we want a
8347 specification DIE at toplevel, so we need a new DIE. For local
8348 class methods, this does not apply. */
8349 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
8350 || context_die == NULL)
8351 && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
8352 && (get_AT_unsigned (old_die, DW_AT_decl_line)
8353 == (unsigned)DECL_SOURCE_LINE (decl)))
8357 /* Clear out the declaration attribute and the parm types. */
8358 remove_AT (subr_die, DW_AT_declaration);
8359 remove_children (subr_die);
8363 subr_die = new_die (DW_TAG_subprogram, context_die);
8364 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
8365 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8366 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
8367 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8368 != (unsigned)DECL_SOURCE_LINE (decl))
8370 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8375 register dw_die_ref scope_die;
8377 if (DECL_CONTEXT (decl))
8378 scope_die = scope_die_for (decl, context_die);
8380 /* Don't put block extern declarations under comp_unit_die. */
8381 scope_die = context_die;
8383 subr_die = new_die (DW_TAG_subprogram, scope_die);
8385 if (TREE_PUBLIC (decl))
8386 add_AT_flag (subr_die, DW_AT_external, 1);
8388 add_name_and_src_coords_attributes (subr_die, decl);
8389 if (debug_info_level > DINFO_LEVEL_TERSE)
8391 register tree type = TREE_TYPE (decl);
8393 add_prototyped_attribute (subr_die, type);
8394 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
8397 add_pure_or_virtual_attribute (subr_die, decl);
8398 if (DECL_ARTIFICIAL (decl))
8399 add_AT_flag (subr_die, DW_AT_artificial, 1);
8400 if (TREE_PROTECTED (decl))
8401 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
8402 else if (TREE_PRIVATE (decl))
8403 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
8408 add_AT_flag (subr_die, DW_AT_declaration, 1);
8410 /* The first time we see a member function, it is in the context of
8411 the class to which it belongs. We make sure of this by emitting
8412 the class first. The next time is the definition, which is
8413 handled above. The two may come from the same source text. */
8414 if (DECL_CONTEXT (decl))
8415 equate_decl_number_to_die (decl, subr_die);
8417 else if (DECL_ABSTRACT (decl))
8419 /* ??? Checking DECL_DEFER_OUTPUT is correct for static inline functions,
8420 but not for extern inline functions. We can't get this completely
8421 correct because information about whether the function was declared
8422 inline is not saved anywhere. */
8423 if (DECL_DEFER_OUTPUT (decl))
8425 if (DECL_INLINE (decl))
8426 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
8428 add_AT_unsigned (subr_die, DW_AT_inline,
8429 DW_INL_declared_not_inlined);
8431 else if (DECL_INLINE (decl))
8432 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
8436 equate_decl_number_to_die (decl, subr_die);
8438 else if (!DECL_EXTERNAL (decl))
8440 if (origin == NULL_TREE)
8441 equate_decl_number_to_die (decl, subr_die);
8443 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
8444 current_funcdef_number);
8445 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
8446 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
8447 current_funcdef_number);
8448 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
8450 add_pubname (decl, subr_die);
8451 add_arange (decl, subr_die);
8453 #ifdef MIPS_DEBUGGING_INFO
8454 /* Add a reference to the FDE for this routine. */
8455 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
8458 /* Define the "frame base" location for this routine. We use the
8459 frame pointer or stack pointer registers, since the RTL for local
8460 variables is relative to one of them. */
8462 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
8463 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
8466 /* ??? This fails for nested inline functions, because context_display
8467 is not part of the state saved/restored for inline functions. */
8468 if (current_function_needs_context)
8469 add_AT_location_description (subr_die, DW_AT_static_link,
8470 lookup_static_chain (decl));
8474 /* Now output descriptions of the arguments for this function. This gets
8475 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8476 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8477 `...' at the end of the formal parameter list. In order to find out if
8478 there was a trailing ellipsis or not, we must instead look at the type
8479 associated with the FUNCTION_DECL. This will be a node of type
8480 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8481 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8482 an ellipsis at the end. */
8483 push_decl_scope (decl);
8485 /* In the case where we are describing a mere function declaration, all we
8486 need to do here (and all we *can* do here) is to describe the *types* of
8487 its formal parameters. */
8488 if (debug_info_level <= DINFO_LEVEL_TERSE)
8490 else if (declaration)
8491 gen_formal_types_die (TREE_TYPE (decl), subr_die);
8494 /* Generate DIEs to represent all known formal parameters */
8495 register tree arg_decls = DECL_ARGUMENTS (decl);
8498 /* When generating DIEs, generate the unspecified_parameters DIE
8499 instead if we come across the arg "__builtin_va_alist" */
8500 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
8501 if (TREE_CODE (parm) == PARM_DECL)
8503 if (DECL_NAME (parm)
8504 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
8505 "__builtin_va_alist"))
8506 gen_unspecified_parameters_die (parm, subr_die);
8508 gen_decl_die (parm, subr_die);
8511 /* Decide whether we need a unspecified_parameters DIE at the end.
8512 There are 2 more cases to do this for: 1) the ansi ... declaration -
8513 this is detectable when the end of the arg list is not a
8514 void_type_node 2) an unprototyped function declaration (not a
8515 definition). This just means that we have no info about the
8516 parameters at all. */
8517 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
8518 if (fn_arg_types != NULL)
8520 /* this is the prototyped case, check for ... */
8521 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
8522 gen_unspecified_parameters_die (decl, subr_die);
8524 else if (DECL_INITIAL (decl) == NULL_TREE)
8525 gen_unspecified_parameters_die (decl, subr_die);
8528 /* Output Dwarf info for all of the stuff within the body of the function
8529 (if it has one - it may be just a declaration). */
8530 outer_scope = DECL_INITIAL (decl);
8532 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8533 node created to represent a function. This outermost BLOCK actually
8534 represents the outermost binding contour for the function, i.e. the
8535 contour in which the function's formal parameters and labels get
8536 declared. Curiously, it appears that the front end doesn't actually
8537 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8538 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8539 list for the function instead.) The BLOCK_VARS list for the
8540 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8541 the function however, and we output DWARF info for those in
8542 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8543 node representing the function's outermost pair of curly braces, and
8544 any blocks used for the base and member initializers of a C++
8545 constructor function. */
8546 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
8548 current_function_has_inlines = 0;
8549 decls_for_scope (outer_scope, subr_die, 0);
8551 #if 0 && defined (MIPS_DEBUGGING_INFO)
8552 if (current_function_has_inlines)
8554 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
8555 if (! comp_unit_has_inlines)
8557 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
8558 comp_unit_has_inlines = 1;
8567 /* Generate a DIE to represent a declared data object. */
8570 gen_variable_die (decl, context_die)
8572 register dw_die_ref context_die;
8574 register tree origin = decl_ultimate_origin (decl);
8575 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
8577 dw_die_ref old_die = lookup_decl_die (decl);
8579 = (DECL_EXTERNAL (decl)
8580 || current_function_decl != decl_function_context (decl)
8581 || context_die->die_tag == DW_TAG_structure_type
8582 || context_die->die_tag == DW_TAG_union_type);
8585 add_abstract_origin_attribute (var_die, origin);
8586 /* Loop unrolling can create multiple blocks that refer to the same
8587 static variable, so we must test for the DW_AT_declaration flag. */
8588 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8589 copy decls and set the DECL_ABSTRACT flag on them instead of
8591 else if (old_die && TREE_STATIC (decl)
8592 && get_AT_flag (old_die, DW_AT_declaration) == 1)
8594 /* This is a definition of a C++ class level static. */
8595 add_AT_die_ref (var_die, DW_AT_specification, old_die);
8596 if (DECL_NAME (decl))
8598 register unsigned file_index
8599 = lookup_filename (DECL_SOURCE_FILE (decl));
8601 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8602 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
8604 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8605 != (unsigned)DECL_SOURCE_LINE (decl))
8607 add_AT_unsigned (var_die, DW_AT_decl_line,
8608 DECL_SOURCE_LINE (decl));
8613 add_name_and_src_coords_attributes (var_die, decl);
8614 add_type_attribute (var_die, TREE_TYPE (decl),
8615 TREE_READONLY (decl),
8616 TREE_THIS_VOLATILE (decl), context_die);
8618 if (TREE_PUBLIC (decl))
8619 add_AT_flag (var_die, DW_AT_external, 1);
8621 if (DECL_ARTIFICIAL (decl))
8622 add_AT_flag (var_die, DW_AT_artificial, 1);
8624 if (TREE_PROTECTED (decl))
8625 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
8627 else if (TREE_PRIVATE (decl))
8628 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
8632 add_AT_flag (var_die, DW_AT_declaration, 1);
8634 if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl))
8635 equate_decl_number_to_die (decl, var_die);
8637 if (! declaration && ! DECL_ABSTRACT (decl))
8639 equate_decl_number_to_die (decl, var_die);
8640 add_location_or_const_value_attribute (var_die, decl);
8641 add_pubname (decl, var_die);
8645 /* Generate a DIE to represent a label identifier. */
8648 gen_label_die (decl, context_die)
8650 register dw_die_ref context_die;
8652 register tree origin = decl_ultimate_origin (decl);
8653 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
8655 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8656 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
8659 add_abstract_origin_attribute (lbl_die, origin);
8661 add_name_and_src_coords_attributes (lbl_die, decl);
8663 if (DECL_ABSTRACT (decl))
8664 equate_decl_number_to_die (decl, lbl_die);
8667 insn = DECL_RTL (decl);
8669 /* Deleted labels are programmer specified labels which have been
8670 eliminated because of various optimisations. We still emit them
8671 here so that it is possible to put breakpoints on them. */
8672 if (GET_CODE (insn) == CODE_LABEL
8673 || ((GET_CODE (insn) == NOTE
8674 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
8676 /* When optimization is enabled (via -O) some parts of the compiler
8677 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8678 represent source-level labels which were explicitly declared by
8679 the user. This really shouldn't be happening though, so catch
8680 it if it ever does happen. */
8681 if (INSN_DELETED_P (insn))
8684 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
8685 ASM_GENERATE_INTERNAL_LABEL (label, label2,
8686 (unsigned) INSN_UID (insn));
8687 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
8692 /* Generate a DIE for a lexical block. */
8695 gen_lexical_block_die (stmt, context_die, depth)
8697 register dw_die_ref context_die;
8700 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
8701 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8703 if (! BLOCK_ABSTRACT (stmt))
8705 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8707 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
8708 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
8709 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
8712 push_decl_scope (stmt);
8713 decls_for_scope (stmt, stmt_die, depth);
8717 /* Generate a DIE for an inlined subprogram. */
8720 gen_inlined_subroutine_die (stmt, context_die, depth)
8722 register dw_die_ref context_die;
8725 if (! BLOCK_ABSTRACT (stmt))
8727 register dw_die_ref subr_die
8728 = new_die (DW_TAG_inlined_subroutine, context_die);
8729 register tree decl = block_ultimate_origin (stmt);
8730 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8732 add_abstract_origin_attribute (subr_die, decl);
8733 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8735 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
8736 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
8737 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
8738 push_decl_scope (decl);
8739 decls_for_scope (stmt, subr_die, depth);
8741 current_function_has_inlines = 1;
8745 /* Generate a DIE for a field in a record, or structure. */
8748 gen_field_die (decl, context_die)
8750 register dw_die_ref context_die;
8752 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
8754 add_name_and_src_coords_attributes (decl_die, decl);
8755 add_type_attribute (decl_die, member_declared_type (decl),
8756 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
8759 /* If this is a bit field... */
8760 if (DECL_BIT_FIELD_TYPE (decl))
8762 add_byte_size_attribute (decl_die, decl);
8763 add_bit_size_attribute (decl_die, decl);
8764 add_bit_offset_attribute (decl_die, decl);
8767 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
8768 add_data_member_location_attribute (decl_die, decl);
8770 if (DECL_ARTIFICIAL (decl))
8771 add_AT_flag (decl_die, DW_AT_artificial, 1);
8773 if (TREE_PROTECTED (decl))
8774 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
8776 else if (TREE_PRIVATE (decl))
8777 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
8781 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8782 Use modified_type_die instead.
8783 We keep this code here just in case these types of DIEs may be needed to
8784 represent certain things in other languages (e.g. Pascal) someday. */
8786 gen_pointer_type_die (type, context_die)
8788 register dw_die_ref context_die;
8790 register dw_die_ref ptr_die
8791 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
8793 equate_type_number_to_die (type, ptr_die);
8794 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8795 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8798 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8799 Use modified_type_die instead.
8800 We keep this code here just in case these types of DIEs may be needed to
8801 represent certain things in other languages (e.g. Pascal) someday. */
8803 gen_reference_type_die (type, context_die)
8805 register dw_die_ref context_die;
8807 register dw_die_ref ref_die
8808 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
8810 equate_type_number_to_die (type, ref_die);
8811 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
8812 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8816 /* Generate a DIE for a pointer to a member type. */
8818 gen_ptr_to_mbr_type_die (type, context_die)
8820 register dw_die_ref context_die;
8822 register dw_die_ref ptr_die
8823 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8825 equate_type_number_to_die (type, ptr_die);
8826 add_AT_die_ref (ptr_die, DW_AT_containing_type,
8827 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
8828 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8831 /* Generate the DIE for the compilation unit. */
8834 gen_compile_unit_die (main_input_filename)
8835 register char *main_input_filename;
8838 char *wd = getpwd ();
8840 comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
8841 add_name_attribute (comp_unit_die, main_input_filename);
8844 add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
8846 sprintf (producer, "%s %s", language_string, version_string);
8848 #ifdef MIPS_DEBUGGING_INFO
8849 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8850 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8851 not appear in the producer string, the debugger reaches the conclusion
8852 that the object file is stripped and has no debugging information.
8853 To get the MIPS/SGI debugger to believe that there is debugging
8854 information in the object file, we add a -g to the producer string. */
8855 if (debug_info_level > DINFO_LEVEL_TERSE)
8856 strcat (producer, " -g");
8859 add_AT_string (comp_unit_die, DW_AT_producer, producer);
8861 if (strcmp (language_string, "GNU C++") == 0)
8862 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
8864 else if (strcmp (language_string, "GNU Ada") == 0)
8865 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
8867 else if (strcmp (language_string, "GNU F77") == 0)
8868 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77);
8870 else if (strcmp (language_string, "GNU Pascal") == 0)
8871 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Pascal83);
8873 else if (flag_traditional)
8874 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
8877 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
8879 #if 0 /* unimplemented */
8880 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
8881 add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
8885 /* Generate a DIE for a string type. */
8888 gen_string_type_die (type, context_die)
8890 register dw_die_ref context_die;
8892 register dw_die_ref type_die
8893 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
8895 equate_type_number_to_die (type, type_die);
8897 /* Fudge the string length attribute for now. */
8899 /* TODO: add string length info.
8900 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8901 bound_representation (upper_bound, 0, 'u'); */
8904 /* Generate the DIE for a base class. */
8907 gen_inheritance_die (binfo, context_die)
8908 register tree binfo;
8909 register dw_die_ref context_die;
8911 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
8913 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
8914 add_data_member_location_attribute (die, binfo);
8916 if (TREE_VIA_VIRTUAL (binfo))
8917 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8918 if (TREE_VIA_PUBLIC (binfo))
8919 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
8920 else if (TREE_VIA_PROTECTED (binfo))
8921 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
8924 /* Generate a DIE for a class member. */
8927 gen_member_die (type, context_die)
8929 register dw_die_ref context_die;
8931 register tree member;
8933 /* If this is not an incomplete type, output descriptions of each of its
8934 members. Note that as we output the DIEs necessary to represent the
8935 members of this record or union type, we will also be trying to output
8936 DIEs to represent the *types* of those members. However the `type'
8937 function (above) will specifically avoid generating type DIEs for member
8938 types *within* the list of member DIEs for this (containing) type execpt
8939 for those types (of members) which are explicitly marked as also being
8940 members of this (containing) type themselves. The g++ front- end can
8941 force any given type to be treated as a member of some other
8942 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8943 to point to the TREE node representing the appropriate (containing)
8946 /* First output info about the base classes. */
8947 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
8949 register tree bases = TYPE_BINFO_BASETYPES (type);
8950 register int n_bases = TREE_VEC_LENGTH (bases);
8953 for (i = 0; i < n_bases; i++)
8954 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
8957 /* Now output info about the data members and type members. */
8958 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
8959 gen_decl_die (member, context_die);
8961 /* Now output info about the function members (if any). */
8962 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
8963 gen_decl_die (member, context_die);
8966 /* Generate a DIE for a structure or union type. */
8969 gen_struct_or_union_type_die (type, context_die)
8971 register dw_die_ref context_die;
8973 register dw_die_ref type_die = lookup_type_die (type);
8974 register dw_die_ref scope_die = 0;
8975 register int nested = 0;
8977 if (type_die && ! TYPE_SIZE (type))
8980 if (TYPE_CONTEXT (type) != NULL_TREE
8981 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
8984 scope_die = scope_die_for (type, context_die);
8986 if (! type_die || (nested && scope_die == comp_unit_die))
8987 /* First occurrence of type or toplevel definition of nested class. */
8989 register dw_die_ref old_die = type_die;
8991 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
8992 ? DW_TAG_structure_type : DW_TAG_union_type,
8994 equate_type_number_to_die (type, type_die);
8995 add_name_attribute (type_die, type_tag (type));
8997 add_AT_die_ref (type_die, DW_AT_specification, old_die);
9000 remove_AT (type_die, DW_AT_declaration);
9002 /* If we're not in the right context to be defining this type, defer to
9003 avoid tricky recursion. */
9004 if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die)
9006 add_AT_flag (type_die, DW_AT_declaration, 1);
9009 /* If this type has been completed, then give it a byte_size attribute and
9010 then give a list of members. */
9011 else if (TYPE_SIZE (type))
9013 /* Prevent infinite recursion in cases where the type of some member of
9014 this type is expressed in terms of this type itself. */
9015 TREE_ASM_WRITTEN (type) = 1;
9016 add_byte_size_attribute (type_die, type);
9017 if (TYPE_STUB_DECL (type) != NULL_TREE)
9018 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9020 /* If the first reference to this type was as the return type of an
9021 inline function, then it may not have a parent. Fix this now. */
9022 if (type_die->die_parent == NULL)
9023 add_child_die (scope_die, type_die);
9025 push_decl_scope (type);
9026 gen_member_die (type, type_die);
9029 /* GNU extension: Record what type our vtable lives in. */
9030 if (TYPE_VFIELD (type))
9032 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
9034 gen_type_die (vtype, context_die);
9035 add_AT_die_ref (type_die, DW_AT_containing_type,
9036 lookup_type_die (vtype));
9041 add_AT_flag (type_die, DW_AT_declaration, 1);
9043 /* We can't do this for function-local types, and we don't need to. */
9044 if (TREE_PERMANENT (type))
9045 add_incomplete_type (type);
9049 /* Generate a DIE for a subroutine _type_. */
9052 gen_subroutine_type_die (type, context_die)
9054 register dw_die_ref context_die;
9056 register tree return_type = TREE_TYPE (type);
9057 register dw_die_ref subr_die
9058 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
9060 equate_type_number_to_die (type, subr_die);
9061 add_prototyped_attribute (subr_die, type);
9062 add_type_attribute (subr_die, return_type, 0, 0, context_die);
9063 gen_formal_types_die (type, subr_die);
9066 /* Generate a DIE for a type definition */
9069 gen_typedef_die (decl, context_die)
9071 register dw_die_ref context_die;
9073 register dw_die_ref type_die;
9074 register tree origin;
9076 if (TREE_ASM_WRITTEN (decl))
9078 TREE_ASM_WRITTEN (decl) = 1;
9080 type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
9081 origin = decl_ultimate_origin (decl);
9083 add_abstract_origin_attribute (type_die, origin);
9087 add_name_and_src_coords_attributes (type_die, decl);
9088 if (DECL_ORIGINAL_TYPE (decl))
9090 type = DECL_ORIGINAL_TYPE (decl);
9091 equate_type_number_to_die (TREE_TYPE (decl), type_die);
9094 type = TREE_TYPE (decl);
9095 add_type_attribute (type_die, type, TREE_READONLY (decl),
9096 TREE_THIS_VOLATILE (decl), context_die);
9099 if (DECL_ABSTRACT (decl))
9100 equate_decl_number_to_die (decl, type_die);
9103 /* Generate a type description DIE. */
9106 gen_type_die (type, context_die)
9108 register dw_die_ref context_die;
9110 if (type == NULL_TREE || type == error_mark_node)
9113 /* We are going to output a DIE to represent the unqualified version of
9114 this type (i.e. without any const or volatile qualifiers) so get the
9115 main variant (i.e. the unqualified version) of this type now. */
9116 type = type_main_variant (type);
9118 if (TREE_ASM_WRITTEN (type))
9121 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9122 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
9124 TREE_ASM_WRITTEN (type) = 1;
9125 gen_decl_die (TYPE_NAME (type), context_die);
9129 switch (TREE_CODE (type))
9135 case REFERENCE_TYPE:
9136 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
9137 ensures that the gen_type_die recursion will terminate even if the
9138 type is recursive. Recursive types are possible in Ada. */
9139 /* ??? We could perhaps do this for all types before the switch
9141 TREE_ASM_WRITTEN (type) = 1;
9143 /* For these types, all that is required is that we output a DIE (or a
9144 set of DIEs) to represent the "basis" type. */
9145 gen_type_die (TREE_TYPE (type), context_die);
9149 /* This code is used for C++ pointer-to-data-member types.
9150 Output a description of the relevant class type. */
9151 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
9153 /* Output a description of the type of the object pointed to. */
9154 gen_type_die (TREE_TYPE (type), context_die);
9156 /* Now output a DIE to represent this pointer-to-data-member type
9158 gen_ptr_to_mbr_type_die (type, context_die);
9162 gen_type_die (TYPE_DOMAIN (type), context_die);
9163 gen_set_type_die (type, context_die);
9167 gen_type_die (TREE_TYPE (type), context_die);
9168 abort (); /* No way to represent these in Dwarf yet! */
9172 /* Force out return type (in case it wasn't forced out already). */
9173 gen_type_die (TREE_TYPE (type), context_die);
9174 gen_subroutine_type_die (type, context_die);
9178 /* Force out return type (in case it wasn't forced out already). */
9179 gen_type_die (TREE_TYPE (type), context_die);
9180 gen_subroutine_type_die (type, context_die);
9184 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
9186 gen_type_die (TREE_TYPE (type), context_die);
9187 gen_string_type_die (type, context_die);
9190 gen_array_type_die (type, context_die);
9196 case QUAL_UNION_TYPE:
9197 /* If this is a nested type whose containing class hasn't been
9198 written out yet, writing it out will cover this one, too. */
9199 if (TYPE_CONTEXT (type)
9200 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9201 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9203 gen_type_die (TYPE_CONTEXT (type), context_die);
9205 if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9208 /* If that failed, attach ourselves to the stub. */
9209 push_decl_scope (TYPE_CONTEXT (type));
9210 context_die = lookup_type_die (TYPE_CONTEXT (type));
9213 if (TREE_CODE (type) == ENUMERAL_TYPE)
9214 gen_enumeration_type_die (type, context_die);
9216 gen_struct_or_union_type_die (type, context_die);
9218 if (TYPE_CONTEXT (type)
9219 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9220 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9223 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9224 it up if it is ever completed. gen_*_type_die will set it for us
9225 when appropriate. */
9234 /* No DIEs needed for fundamental types. */
9238 /* No Dwarf representation currently defined. */
9245 TREE_ASM_WRITTEN (type) = 1;
9248 /* Generate a DIE for a tagged type instantiation. */
9251 gen_tagged_type_instantiation_die (type, context_die)
9253 register dw_die_ref context_die;
9255 if (type == NULL_TREE || type == error_mark_node)
9258 /* We are going to output a DIE to represent the unqualified version of
9259 this type (i.e. without any const or volatile qualifiers) so make sure
9260 that we have the main variant (i.e. the unqualified version) of this
9262 if (type != type_main_variant (type))
9265 /* Do not check TREE_ASM_WRITTEN(type) as it may not be set if this is
9266 an instance of an unresolved type. */
9268 switch (TREE_CODE (type))
9274 gen_inlined_enumeration_type_die (type, context_die);
9278 gen_inlined_structure_type_die (type, context_die);
9282 case QUAL_UNION_TYPE:
9283 gen_inlined_union_type_die (type, context_die);
9291 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
9292 things which are local to the given block. */
9295 gen_block_die (stmt, context_die, depth)
9297 register dw_die_ref context_die;
9300 register int must_output_die = 0;
9301 register tree origin;
9303 register enum tree_code origin_code;
9305 /* Ignore blocks never really used to make RTL. */
9307 if (stmt == NULL_TREE || !TREE_USED (stmt))
9310 /* Determine the "ultimate origin" of this block. This block may be an
9311 inlined instance of an inlined instance of inline function, so we have
9312 to trace all of the way back through the origin chain to find out what
9313 sort of node actually served as the original seed for the creation of
9314 the current block. */
9315 origin = block_ultimate_origin (stmt);
9316 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
9318 /* Determine if we need to output any Dwarf DIEs at all to represent this
9320 if (origin_code == FUNCTION_DECL)
9321 /* The outer scopes for inlinings *must* always be represented. We
9322 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9323 must_output_die = 1;
9326 /* In the case where the current block represents an inlining of the
9327 "body block" of an inline function, we must *NOT* output any DIE for
9328 this block because we have already output a DIE to represent the
9329 whole inlined function scope and the "body block" of any function
9330 doesn't really represent a different scope according to ANSI C
9331 rules. So we check here to make sure that this block does not
9332 represent a "body block inlining" before trying to set the
9333 `must_output_die' flag. */
9334 if (! is_body_block (origin ? origin : stmt))
9336 /* Determine if this block directly contains any "significant"
9337 local declarations which we will need to output DIEs for. */
9338 if (debug_info_level > DINFO_LEVEL_TERSE)
9339 /* We are not in terse mode so *any* local declaration counts
9340 as being a "significant" one. */
9341 must_output_die = (BLOCK_VARS (stmt) != NULL);
9343 /* We are in terse mode, so only local (nested) function
9344 definitions count as "significant" local declarations. */
9345 for (decl = BLOCK_VARS (stmt);
9346 decl != NULL; decl = TREE_CHAIN (decl))
9347 if (TREE_CODE (decl) == FUNCTION_DECL
9348 && DECL_INITIAL (decl))
9350 must_output_die = 1;
9356 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9357 DIE for any block which contains no significant local declarations at
9358 all. Rather, in such cases we just call `decls_for_scope' so that any
9359 needed Dwarf info for any sub-blocks will get properly generated. Note
9360 that in terse mode, our definition of what constitutes a "significant"
9361 local declaration gets restricted to include only inlined function
9362 instances and local (nested) function definitions. */
9363 if (must_output_die)
9365 if (origin_code == FUNCTION_DECL)
9366 gen_inlined_subroutine_die (stmt, context_die, depth);
9368 gen_lexical_block_die (stmt, context_die, depth);
9371 decls_for_scope (stmt, context_die, depth);
9374 /* Generate all of the decls declared within a given scope and (recursively)
9375 all of its sub-blocks. */
9378 decls_for_scope (stmt, context_die, depth)
9380 register dw_die_ref context_die;
9384 register tree subblocks;
9386 /* Ignore blocks never really used to make RTL. */
9387 if (stmt == NULL_TREE || ! TREE_USED (stmt))
9390 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
9391 next_block_number++;
9393 /* Output the DIEs to represent all of the data objects and typedefs
9394 declared directly within this block but not within any nested
9395 sub-blocks. Also, nested function and tag DIEs have been
9396 generated with a parent of NULL; fix that up now. */
9397 for (decl = BLOCK_VARS (stmt);
9398 decl != NULL; decl = TREE_CHAIN (decl))
9400 register dw_die_ref die;
9402 if (TREE_CODE (decl) == FUNCTION_DECL)
9403 die = lookup_decl_die (decl);
9404 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9405 die = lookup_type_die (TREE_TYPE (decl));
9409 if (die != NULL && die->die_parent == NULL)
9410 add_child_die (context_die, die);
9412 gen_decl_die (decl, context_die);
9415 /* Output the DIEs to represent all sub-blocks (and the items declared
9416 therein) of this block. */
9417 for (subblocks = BLOCK_SUBBLOCKS (stmt);
9419 subblocks = BLOCK_CHAIN (subblocks))
9420 gen_block_die (subblocks, context_die, depth + 1);
9423 /* Is this a typedef we can avoid emitting? */
9426 is_redundant_typedef (decl)
9429 if (TYPE_DECL_IS_STUB (decl))
9432 if (DECL_ARTIFICIAL (decl)
9433 && DECL_CONTEXT (decl)
9434 && is_tagged_type (DECL_CONTEXT (decl))
9435 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
9436 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
9437 /* Also ignore the artificial member typedef for the class name. */
9443 /* Generate Dwarf debug information for a decl described by DECL. */
9446 gen_decl_die (decl, context_die)
9448 register dw_die_ref context_die;
9450 register tree origin;
9452 /* Make a note of the decl node we are going to be working on. We may need
9453 to give the user the source coordinates of where it appeared in case we
9454 notice (later on) that something about it looks screwy. */
9455 dwarf_last_decl = decl;
9457 if (TREE_CODE (decl) == ERROR_MARK)
9460 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
9461 ignore a function definition, since that would screw up our count of
9462 blocks, and that in turn will completely screw up the labels we will
9463 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9464 subsequent blocks). */
9465 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
9468 switch (TREE_CODE (decl))
9471 /* The individual enumerators of an enum type get output when we output
9472 the Dwarf representation of the relevant enum type itself. */
9476 /* Don't output any DIEs to represent mere function declarations,
9477 unless they are class members or explicit block externs. */
9478 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
9479 && (current_function_decl == NULL_TREE || ! DECL_ARTIFICIAL (decl)))
9482 if (debug_info_level > DINFO_LEVEL_TERSE)
9484 /* Before we describe the FUNCTION_DECL itself, make sure that we
9485 have described its return type. */
9486 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
9488 /* And its containing type. */
9489 origin = decl_class_context (decl);
9490 if (origin != NULL_TREE)
9491 gen_type_die (origin, context_die);
9493 /* And its virtual context. */
9494 if (DECL_VINDEX (decl) != NULL_TREE)
9495 gen_type_die (DECL_CONTEXT (decl), context_die);
9498 /* Now output a DIE to represent the function itself. */
9499 gen_subprogram_die (decl, context_die);
9503 /* If we are in terse mode, don't generate any DIEs to represent any
9505 if (debug_info_level <= DINFO_LEVEL_TERSE)
9508 /* In the special case of a TYPE_DECL node representing the
9509 declaration of some type tag, if the given TYPE_DECL is marked as
9510 having been instantiated from some other (original) TYPE_DECL node
9511 (e.g. one which was generated within the original definition of an
9512 inline function) we have to generate a special (abbreviated)
9513 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9515 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
9517 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
9521 if (is_redundant_typedef (decl))
9522 gen_type_die (TREE_TYPE (decl), context_die);
9524 /* Output a DIE to represent the typedef itself. */
9525 gen_typedef_die (decl, context_die);
9529 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9530 gen_label_die (decl, context_die);
9534 /* If we are in terse mode, don't generate any DIEs to represent any
9535 variable declarations or definitions. */
9536 if (debug_info_level <= DINFO_LEVEL_TERSE)
9539 /* Output any DIEs that are needed to specify the type of this data
9541 gen_type_die (TREE_TYPE (decl), context_die);
9543 /* And its containing type. */
9544 origin = decl_class_context (decl);
9545 if (origin != NULL_TREE)
9546 gen_type_die (origin, context_die);
9548 /* Now output the DIE to represent the data object itself. This gets
9549 complicated because of the possibility that the VAR_DECL really
9550 represents an inlined instance of a formal parameter for an inline
9552 origin = decl_ultimate_origin (decl);
9553 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
9554 gen_formal_parameter_die (decl, context_die);
9556 gen_variable_die (decl, context_die);
9560 /* Ignore the nameless fields that are used to skip bits, but
9561 handle C++ anonymous unions. */
9562 if (DECL_NAME (decl) != NULL_TREE
9563 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
9565 gen_type_die (member_declared_type (decl), context_die);
9566 gen_field_die (decl, context_die);
9571 gen_type_die (TREE_TYPE (decl), context_die);
9572 gen_formal_parameter_die (decl, context_die);
9580 /* Write the debugging output for DECL. */
9583 dwarf2out_decl (decl)
9586 register dw_die_ref context_die = comp_unit_die;
9588 if (TREE_CODE (decl) == ERROR_MARK)
9591 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
9592 hope that the node in question doesn't represent a function definition.
9593 If it does, then totally ignoring it is bound to screw up our count of
9594 blocks, and that in turn will completely screw up the labels we will
9595 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9596 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
9597 own sequence numbers with them!) */
9598 if (DECL_IGNORED_P (decl))
9600 if (TREE_CODE (decl) == FUNCTION_DECL
9601 && DECL_INITIAL (decl) != NULL)
9607 switch (TREE_CODE (decl))
9610 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9611 builtin function. Explicit programmer-supplied declarations of
9612 these same functions should NOT be ignored however. */
9613 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
9616 /* What we would really like to do here is to filter out all mere
9617 file-scope declarations of file-scope functions which are never
9618 referenced later within this translation unit (and keep all of ones
9619 that *are* referenced later on) but we aren't clairvoyant, so we have
9620 no idea which functions will be referenced in the future (i.e. later
9621 on within the current translation unit). So here we just ignore all
9622 file-scope function declarations which are not also definitions. If
9623 and when the debugger needs to know something about these functions,
9624 it will have to hunt around and find the DWARF information associated
9625 with the definition of the function. Note that we can't just check
9626 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9627 definitions and which ones represent mere declarations. We have to
9628 check `DECL_INITIAL' instead. That's because the C front-end
9629 supports some weird semantics for "extern inline" function
9630 definitions. These can get inlined within the current translation
9631 unit (an thus, we need to generate DWARF info for their abstract
9632 instances so that the DWARF info for the concrete inlined instances
9633 can have something to refer to) but the compiler never generates any
9634 out-of-lines instances of such things (despite the fact that they
9635 *are* definitions). The important point is that the C front-end
9636 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9637 to generate DWARF for them anyway. Note that the C++ front-end also
9638 plays some similar games for inline function definitions appearing
9639 within include files which also contain
9640 `#pragma interface' pragmas. */
9641 if (DECL_INITIAL (decl) == NULL_TREE)
9644 /* If we're a nested function, initially use a parent of NULL; if we're
9645 a plain function, this will be fixed up in decls_for_scope. If
9646 we're a method, it will be ignored, since we already have a DIE. */
9647 if (decl_function_context (decl))
9653 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9654 declaration and if the declaration was never even referenced from
9655 within this entire compilation unit. We suppress these DIEs in
9656 order to save space in the .debug section (by eliminating entries
9657 which are probably useless). Note that we must not suppress
9658 block-local extern declarations (whether used or not) because that
9659 would screw-up the debugger's name lookup mechanism and cause it to
9660 miss things which really ought to be in scope at a given point. */
9661 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
9664 /* If we are in terse mode, don't generate any DIEs to represent any
9665 variable declarations or definitions. */
9666 if (debug_info_level <= DINFO_LEVEL_TERSE)
9671 /* Don't bother trying to generate any DIEs to represent any of the
9672 normal built-in types for the language we are compiling. */
9673 if (DECL_SOURCE_LINE (decl) == 0)
9675 /* OK, we need to generate one for `bool' so GDB knows what type
9676 comparisons have. */
9677 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
9678 == DW_LANG_C_plus_plus)
9679 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
9680 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
9685 /* If we are in terse mode, don't generate any DIEs for types. */
9686 if (debug_info_level <= DINFO_LEVEL_TERSE)
9689 /* If we're a function-scope tag, initially use a parent of NULL;
9690 this will be fixed up in decls_for_scope. */
9691 if (decl_function_context (decl))
9700 gen_decl_die (decl, context_die);
9701 output_pending_types_for_scope (comp_unit_die);
9704 /* Output a marker (i.e. a label) for the beginning of the generated code for
9708 dwarf2out_begin_block (blocknum)
9709 register unsigned blocknum;
9711 function_section (current_function_decl);
9712 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
9715 /* Output a marker (i.e. a label) for the end of the generated code for a
9719 dwarf2out_end_block (blocknum)
9720 register unsigned blocknum;
9722 function_section (current_function_decl);
9723 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
9726 /* Output a marker (i.e. a label) at a point in the assembly code which
9727 corresponds to a given source level label. */
9730 dwarf2out_label (insn)
9733 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9735 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9737 function_section (current_function_decl);
9738 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
9739 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
9740 (unsigned) INSN_UID (insn));
9744 /* Lookup a filename (in the list of filenames that we know about here in
9745 dwarf2out.c) and return its "index". The index of each (known) filename is
9746 just a unique number which is associated with only that one filename.
9747 We need such numbers for the sake of generating labels
9748 (in the .debug_sfnames section) and references to those
9749 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9750 If the filename given as an argument is not found in our current list,
9751 add it to the list and assign it the next available unique index number.
9752 In order to speed up searches, we remember the index of the filename
9753 was looked up last. This handles the majority of all searches. */
9756 lookup_filename (file_name)
9757 const char *file_name;
9759 static unsigned last_file_lookup_index = 0;
9760 register unsigned i;
9762 /* Check to see if the file name that was searched on the previous call
9763 matches this file name. If so, return the index. */
9764 if (last_file_lookup_index != 0)
9765 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
9766 return last_file_lookup_index;
9768 /* Didn't match the previous lookup, search the table */
9769 for (i = 1; i < file_table_in_use; ++i)
9770 if (strcmp (file_name, file_table[i]) == 0)
9772 last_file_lookup_index = i;
9776 /* Prepare to add a new table entry by making sure there is enough space in
9777 the table to do so. If not, expand the current table. */
9778 if (file_table_in_use == file_table_allocated)
9780 file_table_allocated += FILE_TABLE_INCREMENT;
9782 = (char **) xrealloc (file_table,
9783 file_table_allocated * sizeof (char *));
9786 /* Add the new entry to the end of the filename table. */
9787 file_table[file_table_in_use] = xstrdup (file_name);
9788 last_file_lookup_index = file_table_in_use++;
9790 return last_file_lookup_index;
9793 /* Output a label to mark the beginning of a source code line entry
9794 and record information relating to this source line, in
9795 'line_info_table' for later output of the .debug_line section. */
9798 dwarf2out_line (filename, line)
9799 register const char *filename;
9800 register unsigned line;
9802 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9804 function_section (current_function_decl);
9806 if (DWARF2_ASM_LINE_DEBUG_INFO)
9808 static const char *lastfile;
9810 /* Emit the .file and .loc directives understood by GNU as. */
9811 if (lastfile == 0 || strcmp (filename, lastfile))
9813 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
9814 lastfile = filename;
9817 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
9819 /* Indicate that line number info exists. */
9820 ++line_info_table_in_use;
9822 /* Indicate that multiple line number tables exist. */
9823 if (DECL_SECTION_NAME (current_function_decl))
9824 ++separate_line_info_table_in_use;
9826 else if (DECL_SECTION_NAME (current_function_decl))
9828 register dw_separate_line_info_ref line_info;
9829 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
9830 separate_line_info_table_in_use);
9832 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9833 fputc ('\n', asm_out_file);
9835 /* expand the line info table if necessary */
9836 if (separate_line_info_table_in_use
9837 == separate_line_info_table_allocated)
9839 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9840 separate_line_info_table
9841 = (dw_separate_line_info_ref)
9842 xrealloc (separate_line_info_table,
9843 separate_line_info_table_allocated
9844 * sizeof (dw_separate_line_info_entry));
9847 /* Add the new entry at the end of the line_info_table. */
9849 = &separate_line_info_table[separate_line_info_table_in_use++];
9850 line_info->dw_file_num = lookup_filename (filename);
9851 line_info->dw_line_num = line;
9852 line_info->function = current_funcdef_number;
9856 register dw_line_info_ref line_info;
9858 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
9859 line_info_table_in_use);
9861 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9862 fputc ('\n', asm_out_file);
9864 /* Expand the line info table if necessary. */
9865 if (line_info_table_in_use == line_info_table_allocated)
9867 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9869 = (dw_line_info_ref)
9870 xrealloc (line_info_table,
9871 (line_info_table_allocated
9872 * sizeof (dw_line_info_entry)));
9875 /* Add the new entry at the end of the line_info_table. */
9876 line_info = &line_info_table[line_info_table_in_use++];
9877 line_info->dw_file_num = lookup_filename (filename);
9878 line_info->dw_line_num = line;
9883 /* Record the beginning of a new source file, for later output
9884 of the .debug_macinfo section. At present, unimplemented. */
9887 dwarf2out_start_source_file (filename)
9888 register const char *filename ATTRIBUTE_UNUSED;
9892 /* Record the end of a source file, for later output
9893 of the .debug_macinfo section. At present, unimplemented. */
9896 dwarf2out_end_source_file ()
9900 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9901 the tail part of the directive line, i.e. the part which is past the
9902 initial whitespace, #, whitespace, directive-name, whitespace part. */
9905 dwarf2out_define (lineno, buffer)
9906 register unsigned lineno ATTRIBUTE_UNUSED;
9907 register const char *buffer ATTRIBUTE_UNUSED;
9909 static int initialized = 0;
9912 dwarf2out_start_source_file (primary_filename);
9917 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9918 the tail part of the directive line, i.e. the part which is past the
9919 initial whitespace, #, whitespace, directive-name, whitespace part. */
9922 dwarf2out_undef (lineno, buffer)
9923 register unsigned lineno ATTRIBUTE_UNUSED;
9924 register const char *buffer ATTRIBUTE_UNUSED;
9928 /* Set up for Dwarf output at the start of compilation. */
9931 dwarf2out_init (asm_out_file, main_input_filename)
9932 register FILE *asm_out_file;
9933 register char *main_input_filename;
9935 /* Remember the name of the primary input file. */
9936 primary_filename = main_input_filename;
9938 /* Allocate the initial hunk of the file_table. */
9939 file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
9940 file_table_allocated = FILE_TABLE_INCREMENT;
9942 /* Skip the first entry - file numbers begin at 1. */
9943 file_table_in_use = 1;
9945 /* Allocate the initial hunk of the decl_die_table. */
9947 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
9948 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
9949 decl_die_table_in_use = 0;
9951 /* Allocate the initial hunk of the decl_scope_table. */
9953 = (decl_scope_node *) xcalloc (DECL_SCOPE_TABLE_INCREMENT,
9954 sizeof (decl_scope_node));
9955 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
9956 decl_scope_depth = 0;
9958 /* Allocate the initial hunk of the abbrev_die_table. */
9960 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
9961 sizeof (dw_die_ref));
9962 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
9963 /* Zero-th entry is allocated, but unused */
9964 abbrev_die_table_in_use = 1;
9966 /* Allocate the initial hunk of the line_info_table. */
9968 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
9969 sizeof (dw_line_info_entry));
9970 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
9971 /* Zero-th entry is allocated, but unused */
9972 line_info_table_in_use = 1;
9974 /* Generate the initial DIE for the .debug section. Note that the (string)
9975 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9976 will (typically) be a relative pathname and that this pathname should be
9977 taken as being relative to the directory from which the compiler was
9978 invoked when the given (base) source file was compiled. */
9979 gen_compile_unit_die (main_input_filename);
9981 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
9982 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
9983 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9984 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
9986 strcpy (text_section_label, stripattributes (TEXT_SECTION));
9987 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
9988 DEBUG_INFO_SECTION_LABEL, 0);
9989 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
9990 DEBUG_LINE_SECTION_LABEL, 0);
9992 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9993 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
9994 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9995 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9996 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
9997 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9998 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
9999 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
10000 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
10003 /* Output stuff that dwarf requires at the end of every file,
10004 and generate the DWARF-2 debugging info. */
10007 dwarf2out_finish ()
10009 limbo_die_node *node, *next_node;
10013 /* Traverse the limbo die list, and add parent/child links. The only
10014 dies without parents that should be here are concrete instances of
10015 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
10016 For concrete instances, we can get the parent die from the abstract
10018 for (node = limbo_die_list; node; node = next_node)
10020 next_node = node->next;
10023 if (die->die_parent == NULL)
10025 a = get_AT (die, DW_AT_abstract_origin);
10027 add_child_die (a->dw_attr_val.v.val_die_ref->die_parent, die);
10028 else if (die == comp_unit_die)
10036 /* Walk through the list of incomplete types again, trying once more to
10037 emit full debugging info for them. */
10038 retry_incomplete_types ();
10040 /* Traverse the DIE tree and add sibling attributes to those DIE's
10041 that have children. */
10042 add_sibling_attributes (comp_unit_die);
10044 /* Output a terminator label for the .text section. */
10045 fputc ('\n', asm_out_file);
10046 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
10047 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
10050 /* Output a terminator label for the .data section. */
10051 fputc ('\n', asm_out_file);
10052 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
10053 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
10055 /* Output a terminator label for the .bss section. */
10056 fputc ('\n', asm_out_file);
10057 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
10058 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
10061 /* Output the source line correspondence table. */
10062 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
10064 if (! DWARF2_ASM_LINE_DEBUG_INFO)
10066 fputc ('\n', asm_out_file);
10067 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
10068 output_line_info ();
10071 /* We can only use the low/high_pc attributes if all of the code
10073 if (separate_line_info_table_in_use == 0)
10075 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
10076 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
10079 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
10080 debug_line_section_label);
10083 /* Output the abbreviation table. */
10084 fputc ('\n', asm_out_file);
10085 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
10086 build_abbrev_table (comp_unit_die);
10087 output_abbrev_section ();
10089 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10090 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
10091 calc_die_sizes (comp_unit_die);
10093 /* Output debugging information. */
10094 fputc ('\n', asm_out_file);
10095 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
10096 output_compilation_unit_header ();
10097 output_die (comp_unit_die);
10099 if (pubname_table_in_use)
10101 /* Output public names table. */
10102 fputc ('\n', asm_out_file);
10103 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
10104 output_pubnames ();
10107 /* We only put functions in the arange table, so don't write it out if
10108 we don't have any. */
10109 if (fde_table_in_use)
10111 /* Output the address range information. */
10112 fputc ('\n', asm_out_file);
10113 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
10117 #endif /* DWARF2_DEBUGGING_INFO */