1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* TODO: Implement .debug_str handling, and share entries somehow.
26 Eliminate duplicates by putting common info in a separate section
27 to be collected by the linker and referring to it with
29 Emit .debug_line header even when there are no functions, since
30 the file numbers are used by .debug_info. Alternately, leave
31 out locations for types and decls.
32 Avoid talking about ctors and op= for PODs.
33 Factor out common prologue sequences into multiple CIEs. */
35 /* The first part of this file deals with the DWARF 2 frame unwind
36 information, which is also used by the GCC efficient exception handling
37 mechanism. The second part, controlled only by an #ifdef
38 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
47 #include "hard-reg-set.h"
49 #include "insn-config.h"
55 #include "dwarf2out.h"
61 /* Decide whether we want to emit frame unwind information for the current
67 return (write_symbols == DWARF2_DEBUG
68 #ifdef DWARF2_FRAME_INFO
71 #ifdef DWARF2_UNWIND_INFO
73 || (flag_exceptions && ! exceptions_via_longjmp)
78 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
80 /* How to start an assembler comment. */
81 #ifndef ASM_COMMENT_START
82 #define ASM_COMMENT_START ";#"
85 typedef struct dw_cfi_struct *dw_cfi_ref;
86 typedef struct dw_fde_struct *dw_fde_ref;
87 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
89 /* Call frames are described using a sequence of Call Frame
90 Information instructions. The register number, offset
91 and address fields are provided as possible operands;
92 their use is selected by the opcode field. */
94 typedef union dw_cfi_oprnd_struct
96 unsigned long dw_cfi_reg_num;
97 long int dw_cfi_offset;
98 const char *dw_cfi_addr;
99 struct dw_loc_descr_struct *dw_cfi_loc;
103 typedef struct dw_cfi_struct
105 dw_cfi_ref dw_cfi_next;
106 enum dwarf_call_frame_info dw_cfi_opc;
107 dw_cfi_oprnd dw_cfi_oprnd1;
108 dw_cfi_oprnd dw_cfi_oprnd2;
112 /* This is how we define the location of the CFA. We use to handle it
113 as REG + OFFSET all the time, but now it can be more complex.
114 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
115 Instead of passing around REG and OFFSET, we pass a copy
116 of this structure. */
117 typedef struct cfa_loc
122 int indirect; /* 1 if CFA is accessed via a dereference. */
125 /* All call frame descriptions (FDE's) in the GCC generated DWARF
126 refer to a single Common Information Entry (CIE), defined at
127 the beginning of the .debug_frame section. This used of a single
128 CIE obviates the need to keep track of multiple CIE's
129 in the DWARF generation routines below. */
131 typedef struct dw_fde_struct
133 const char *dw_fde_begin;
134 const char *dw_fde_current_label;
135 const char *dw_fde_end;
136 dw_cfi_ref dw_fde_cfi;
141 /* Maximum size (in bytes) of an artificially generated label. */
142 #define MAX_ARTIFICIAL_LABEL_BYTES 30
144 /* Make sure we know the sizes of the various types dwarf can describe. These
145 are only defaults. If the sizes are different for your target, you should
146 override these values by defining the appropriate symbols in your tm.h
149 #ifndef CHAR_TYPE_SIZE
150 #define CHAR_TYPE_SIZE BITS_PER_UNIT
153 /* The size of the target's pointer type. */
155 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
158 /* The size of addresses as they appear in the Dwarf 2 data.
159 Some architectures use word addresses to refer to code locations,
160 but Dwarf 2 info always uses byte addresses. On such machines,
161 Dwarf 2 addresses need to be larger than the architecture's
163 #ifndef DWARF2_ADDR_SIZE
164 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
167 /* The size in bytes of a DWARF field indicating an offset or length
168 relative to a debug info section, specified to be 4 bytes in the
169 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
172 #ifndef DWARF_OFFSET_SIZE
173 #define DWARF_OFFSET_SIZE 4
176 #define DWARF_VERSION 2
178 /* Round SIZE up to the nearest BOUNDARY. */
179 #define DWARF_ROUND(SIZE,BOUNDARY) \
180 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
182 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
183 #ifdef STACK_GROWS_DOWNWARD
184 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
186 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
189 /* A pointer to the base of a table that contains frame description
190 information for each routine. */
191 static dw_fde_ref fde_table;
193 /* Number of elements currently allocated for fde_table. */
194 static unsigned fde_table_allocated;
196 /* Number of elements in fde_table currently in use. */
197 static unsigned fde_table_in_use;
199 /* Size (in elements) of increments by which we may expand the
201 #define FDE_TABLE_INCREMENT 256
203 /* A list of call frame insns for the CIE. */
204 static dw_cfi_ref cie_cfi_head;
206 /* The number of the current function definition for which debugging
207 information is being generated. These numbers range from 1 up to the
208 maximum number of function definitions contained within the current
209 compilation unit. These numbers are used to create unique label id's
210 unique to each function definition. */
211 static unsigned current_funcdef_number = 0;
213 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
214 attribute that accelerates the lookup of the FDE associated
215 with the subprogram. This variable holds the table index of the FDE
216 associated with the current function (body) definition. */
217 static unsigned current_funcdef_fde;
219 /* Forward declarations for functions defined in this file. */
221 static char *stripattributes PARAMS ((const char *));
222 static const char *dwarf_cfi_name PARAMS ((unsigned));
223 static dw_cfi_ref new_cfi PARAMS ((void));
224 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
225 static unsigned long size_of_uleb128 PARAMS ((unsigned long));
226 static unsigned long size_of_sleb128 PARAMS ((long));
227 static void output_uleb128 PARAMS ((unsigned long));
228 static void output_sleb128 PARAMS ((long));
229 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
230 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
231 static void lookup_cfa PARAMS ((dw_cfa_location *));
232 static void reg_save PARAMS ((const char *, unsigned,
234 static void initial_return_save PARAMS ((rtx));
235 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
236 static void output_call_frame_info PARAMS ((int));
237 static void dwarf2out_stack_adjust PARAMS ((rtx));
238 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
240 /* Support for complex CFA locations. */
241 static void output_cfa_loc PARAMS ((dw_cfi_ref));
242 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
243 struct dw_loc_descr_struct *));
244 static struct dw_loc_descr_struct *build_cfa_loc
245 PARAMS ((dw_cfa_location *));
246 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
248 /* Definitions of defaults for assembler-dependent names of various
249 pseudo-ops and section names.
250 Theses may be overridden in the tm.h file (if necessary) for a particular
253 #ifdef OBJECT_FORMAT_ELF
254 #ifndef UNALIGNED_SHORT_ASM_OP
255 #define UNALIGNED_SHORT_ASM_OP ".2byte"
257 #ifndef UNALIGNED_INT_ASM_OP
258 #define UNALIGNED_INT_ASM_OP ".4byte"
260 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
261 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
263 #endif /* OBJECT_FORMAT_ELF */
266 #define ASM_BYTE_OP ".byte"
269 /* Data and reference forms for relocatable data. */
270 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
271 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
273 /* Pseudo-op for defining a new section. */
274 #ifndef SECTION_ASM_OP
275 #define SECTION_ASM_OP ".section"
278 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
279 print the SECTION_ASM_OP and the section name. The default here works for
280 almost all svr4 assemblers, except for the sparc, where the section name
281 must be enclosed in double quotes. (See sparcv4.h). */
282 #ifndef SECTION_FORMAT
283 #ifdef PUSHSECTION_FORMAT
284 #define SECTION_FORMAT PUSHSECTION_FORMAT
286 #define SECTION_FORMAT "\t%s\t%s\n"
290 #ifndef FRAME_SECTION
291 #define FRAME_SECTION ".debug_frame"
294 #ifndef FUNC_BEGIN_LABEL
295 #define FUNC_BEGIN_LABEL "LFB"
297 #ifndef FUNC_END_LABEL
298 #define FUNC_END_LABEL "LFE"
300 #define CIE_AFTER_SIZE_LABEL "LSCIE"
301 #define CIE_END_LABEL "LECIE"
302 #define CIE_LENGTH_LABEL "LLCIE"
303 #define FDE_AFTER_SIZE_LABEL "LSFDE"
304 #define FDE_END_LABEL "LEFDE"
305 #define FDE_LENGTH_LABEL "LLFDE"
307 /* Definitions of defaults for various types of primitive assembly language
308 output operations. These may be overridden from within the tm.h file,
309 but typically, that is unnecessary. */
311 #ifndef ASM_OUTPUT_SECTION
312 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
313 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
316 #ifndef ASM_OUTPUT_DWARF_DATA1
317 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
318 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
321 #ifndef ASM_OUTPUT_DWARF_DELTA1
322 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
323 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
324 assemble_name (FILE, LABEL1); \
325 fprintf (FILE, "-"); \
326 assemble_name (FILE, LABEL2); \
330 #ifdef UNALIGNED_INT_ASM_OP
332 #ifndef UNALIGNED_OFFSET_ASM_OP
333 #define UNALIGNED_OFFSET_ASM_OP \
334 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
337 #ifndef UNALIGNED_WORD_ASM_OP
338 #define UNALIGNED_WORD_ASM_OP \
339 ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \
340 : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \
341 : UNALIGNED_INT_ASM_OP)
344 #ifndef ASM_OUTPUT_DWARF_DELTA2
345 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
346 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
347 assemble_name (FILE, LABEL1); \
348 fprintf (FILE, "-"); \
349 assemble_name (FILE, LABEL2); \
353 #ifndef ASM_OUTPUT_DWARF_DELTA4
354 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
355 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
356 assemble_name (FILE, LABEL1); \
357 fprintf (FILE, "-"); \
358 assemble_name (FILE, LABEL2); \
362 #ifndef ASM_OUTPUT_DWARF_DELTA
363 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
364 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
365 assemble_name (FILE, LABEL1); \
366 fprintf (FILE, "-"); \
367 assemble_name (FILE, LABEL2); \
371 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
372 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
373 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
374 assemble_name (FILE, LABEL1); \
375 fprintf (FILE, "-"); \
376 assemble_name (FILE, LABEL2); \
380 #ifndef ASM_OUTPUT_DWARF_ADDR
381 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
382 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
383 assemble_name (FILE, LABEL); \
387 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
388 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
390 fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
391 output_addr_const ((FILE), (RTX)); \
395 #ifndef ASM_OUTPUT_DWARF_OFFSET4
396 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
397 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
398 assemble_name (FILE, LABEL); \
402 #ifndef ASM_OUTPUT_DWARF_OFFSET
403 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
404 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
405 assemble_name (FILE, LABEL); \
409 #ifndef ASM_OUTPUT_DWARF_DATA2
410 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
411 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
414 #ifndef ASM_OUTPUT_DWARF_DATA4
415 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
416 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
419 #ifndef ASM_OUTPUT_DWARF_DATA8
420 #define ASM_OUTPUT_DWARF_DATA8(FILE,VALUE) \
421 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_DOUBLE_INT_ASM_OP, \
422 (unsigned long) (VALUE))
425 #ifndef ASM_OUTPUT_DWARF_DATA
426 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
427 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
428 (unsigned long) (VALUE))
431 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
432 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
433 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
434 (unsigned long) (VALUE))
437 #ifndef ASM_OUTPUT_DWARF_CONST_DOUBLE
438 #define ASM_OUTPUT_DWARF_CONST_DOUBLE(FILE,HIGH_VALUE,LOW_VALUE) \
440 if (WORDS_BIG_ENDIAN) \
442 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
443 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
447 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
448 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
453 #else /* UNALIGNED_INT_ASM_OP */
455 /* We don't have unaligned support, let's hope the normal output works for
456 .debug_frame. But we know it won't work for .debug_info. */
458 #ifdef DWARF2_DEBUGGING_INFO
459 #error DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP.
462 #ifndef ASM_OUTPUT_DWARF_ADDR
463 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
464 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1)
467 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
468 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) ASM_OUTPUT_DWARF_ADDR (FILE,RTX)
471 #ifndef ASM_OUTPUT_DWARF_OFFSET4
472 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
473 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
476 #ifndef ASM_OUTPUT_DWARF_OFFSET
477 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
478 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
481 #ifndef ASM_OUTPUT_DWARF_DELTA2
482 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
483 assemble_integer (gen_rtx_MINUS (HImode, \
484 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
485 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
489 #ifndef ASM_OUTPUT_DWARF_DELTA4
490 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
491 assemble_integer (gen_rtx_MINUS (SImode, \
492 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
493 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
497 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
498 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
499 assemble_integer (gen_rtx_MINUS (Pmode, \
500 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
501 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
505 #ifndef ASM_OUTPUT_DWARF_DELTA
506 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
507 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
510 #ifndef ASM_OUTPUT_DWARF_DATA2
511 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
512 assemble_integer (GEN_INT (VALUE), 2, 1)
515 #ifndef ASM_OUTPUT_DWARF_DATA4
516 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
517 assemble_integer (GEN_INT (VALUE), 4, 1)
520 #endif /* UNALIGNED_INT_ASM_OP */
523 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
524 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
526 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
527 assemble_name (FILE, SY); \
529 assemble_name (FILE, HI); \
531 assemble_name (FILE, LO); \
534 #endif /* SET_ASM_OP */
536 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
537 newline is produced. When flag_debug_asm is asserted, we add commentary
538 at the end of the line, so we must avoid output of a newline here. */
539 #ifndef ASM_OUTPUT_DWARF_STRING
540 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
542 register int slen = strlen(P); \
543 register const char *p = (P); \
545 fprintf (FILE, "\t.ascii \""); \
546 for (i = 0; i < slen; i++) \
548 register int c = p[i]; \
549 if (c == '\"' || c == '\\') \
555 fprintf (FILE, "\\%o", c); \
558 fprintf (FILE, "\\0\""); \
563 /* The DWARF 2 CFA column which tracks the return address. Normally this
564 is the column for PC, or the first column after all of the hard
566 #ifndef DWARF_FRAME_RETURN_COLUMN
568 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
570 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
574 /* The mapping from gcc register number to DWARF 2 CFA column number. By
575 default, we just provide columns for all registers. */
576 #ifndef DWARF_FRAME_REGNUM
577 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
580 /* Hook used by __throw. */
583 expand_builtin_dwarf_fp_regnum ()
585 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
588 /* The offset from the incoming value of %sp to the top of the stack frame
589 for the current function. */
590 #ifndef INCOMING_FRAME_SP_OFFSET
591 #define INCOMING_FRAME_SP_OFFSET 0
594 /* Return a pointer to a copy of the section string name S with all
595 attributes stripped off, and an asterisk prepended (for assemble_name). */
601 char *stripped = xmalloc (strlen (s) + 2);
606 while (*s && *s != ',')
613 /* Generate code to initialize the register size table. */
616 expand_builtin_init_dwarf_reg_sizes (address)
620 enum machine_mode mode = TYPE_MODE (char_type_node);
621 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
622 rtx mem = gen_rtx_MEM (mode, addr);
624 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
626 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
627 int size = GET_MODE_SIZE (reg_raw_mode[i]);
632 emit_move_insn (change_address (mem, mode,
633 plus_constant (addr, offset)),
638 /* Convert a DWARF call frame info. operation to its string name */
641 dwarf_cfi_name (cfi_opc)
642 register unsigned cfi_opc;
646 case DW_CFA_advance_loc:
647 return "DW_CFA_advance_loc";
649 return "DW_CFA_offset";
651 return "DW_CFA_restore";
655 return "DW_CFA_set_loc";
656 case DW_CFA_advance_loc1:
657 return "DW_CFA_advance_loc1";
658 case DW_CFA_advance_loc2:
659 return "DW_CFA_advance_loc2";
660 case DW_CFA_advance_loc4:
661 return "DW_CFA_advance_loc4";
662 case DW_CFA_offset_extended:
663 return "DW_CFA_offset_extended";
664 case DW_CFA_restore_extended:
665 return "DW_CFA_restore_extended";
666 case DW_CFA_undefined:
667 return "DW_CFA_undefined";
668 case DW_CFA_same_value:
669 return "DW_CFA_same_value";
670 case DW_CFA_register:
671 return "DW_CFA_register";
672 case DW_CFA_remember_state:
673 return "DW_CFA_remember_state";
674 case DW_CFA_restore_state:
675 return "DW_CFA_restore_state";
677 return "DW_CFA_def_cfa";
678 case DW_CFA_def_cfa_register:
679 return "DW_CFA_def_cfa_register";
680 case DW_CFA_def_cfa_offset:
681 return "DW_CFA_def_cfa_offset";
682 case DW_CFA_def_cfa_expression:
683 return "DW_CFA_def_cfa_expression";
685 /* SGI/MIPS specific */
686 case DW_CFA_MIPS_advance_loc8:
687 return "DW_CFA_MIPS_advance_loc8";
690 case DW_CFA_GNU_window_save:
691 return "DW_CFA_GNU_window_save";
692 case DW_CFA_GNU_args_size:
693 return "DW_CFA_GNU_args_size";
694 case DW_CFA_GNU_negative_offset_extended:
695 return "DW_CFA_GNU_negative_offset_extended";
698 return "DW_CFA_<unknown>";
702 /* Return a pointer to a newly allocated Call Frame Instruction. */
704 static inline dw_cfi_ref
707 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
709 cfi->dw_cfi_next = NULL;
710 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
711 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
716 /* Add a Call Frame Instruction to list of instructions. */
719 add_cfi (list_head, cfi)
720 register dw_cfi_ref *list_head;
721 register dw_cfi_ref cfi;
723 register dw_cfi_ref *p;
725 /* Find the end of the chain. */
726 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
732 /* Generate a new label for the CFI info to refer to. */
735 dwarf2out_cfi_label ()
737 static char label[20];
738 static unsigned long label_num = 0;
740 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
741 ASM_OUTPUT_LABEL (asm_out_file, label);
746 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
747 or to the CIE if LABEL is NULL. */
750 add_fde_cfi (label, cfi)
751 register const char *label;
752 register dw_cfi_ref cfi;
756 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
759 label = dwarf2out_cfi_label ();
761 if (fde->dw_fde_current_label == NULL
762 || strcmp (label, fde->dw_fde_current_label) != 0)
764 register dw_cfi_ref xcfi;
766 fde->dw_fde_current_label = label = xstrdup (label);
768 /* Set the location counter to the new label. */
770 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
771 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
772 add_cfi (&fde->dw_fde_cfi, xcfi);
775 add_cfi (&fde->dw_fde_cfi, cfi);
779 add_cfi (&cie_cfi_head, cfi);
782 /* Subroutine of lookup_cfa. */
785 lookup_cfa_1 (cfi, loc)
786 register dw_cfi_ref cfi;
787 register dw_cfa_location *loc;
789 switch (cfi->dw_cfi_opc)
791 case DW_CFA_def_cfa_offset:
792 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
794 case DW_CFA_def_cfa_register:
795 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
798 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
799 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
801 case DW_CFA_def_cfa_expression:
802 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
809 /* Find the previous value for the CFA. */
813 register dw_cfa_location *loc;
815 register dw_cfi_ref cfi;
817 loc->reg = (unsigned long) -1;
820 loc->base_offset = 0;
822 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
823 lookup_cfa_1 (cfi, loc);
825 if (fde_table_in_use)
827 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
828 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
829 lookup_cfa_1 (cfi, loc);
833 /* The current rule for calculating the DWARF2 canonical frame address. */
836 /* The register used for saving registers to the stack, and its offset
838 dw_cfa_location cfa_store;
840 /* The running total of the size of arguments pushed onto the stack. */
841 static long args_size;
843 /* The last args_size we actually output. */
844 static long old_args_size;
846 /* Entry point to update the canonical frame address (CFA).
847 LABEL is passed to add_fde_cfi. The value of CFA is now to be
848 calculated from REG+OFFSET. */
851 dwarf2out_def_cfa (label, reg, offset)
852 register const char *label;
861 def_cfa_1 (label, &loc);
864 /* This routine does the actual work. The CFA is now calculated from
865 the dw_cfa_location structure. */
867 def_cfa_1 (label, loc_p)
868 register const char *label;
869 dw_cfa_location *loc_p;
871 register dw_cfi_ref cfi;
872 dw_cfa_location old_cfa, loc;
877 if (cfa_store.reg == loc.reg && loc.indirect == 0)
878 cfa_store.offset = loc.offset;
880 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
881 lookup_cfa (&old_cfa);
883 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
884 loc.indirect == old_cfa.indirect)
886 if (loc.indirect == 0
887 || loc.base_offset == old_cfa.base_offset)
893 if (loc.reg == old_cfa.reg && !loc.indirect)
895 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
896 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
899 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
900 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
903 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
904 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
908 else if (loc.indirect == 0)
910 cfi->dw_cfi_opc = DW_CFA_def_cfa;
911 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
912 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
916 struct dw_loc_descr_struct * loc_list;
917 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
918 loc_list = build_cfa_loc (&loc);
919 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
922 add_fde_cfi (label, cfi);
925 /* Add the CFI for saving a register. REG is the CFA column number.
926 LABEL is passed to add_fde_cfi.
927 If SREG is -1, the register is saved at OFFSET from the CFA;
928 otherwise it is saved in SREG. */
931 reg_save (label, reg, sreg, offset)
932 register const char *label;
933 register unsigned reg;
934 register unsigned sreg;
935 register long offset;
937 register dw_cfi_ref cfi = new_cfi ();
939 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
941 /* The following comparison is correct. -1 is used to indicate that
942 the value isn't a register number. */
943 if (sreg == (unsigned int) -1)
946 /* The register number won't fit in 6 bits, so we have to use
948 cfi->dw_cfi_opc = DW_CFA_offset_extended;
950 cfi->dw_cfi_opc = DW_CFA_offset;
952 offset /= DWARF_CIE_DATA_ALIGNMENT;
955 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
958 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
960 else if (sreg == reg)
961 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
965 cfi->dw_cfi_opc = DW_CFA_register;
966 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
969 add_fde_cfi (label, cfi);
972 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
973 This CFI tells the unwinder that it needs to restore the window registers
974 from the previous frame's window save area.
976 ??? Perhaps we should note in the CIE where windows are saved (instead of
977 assuming 0(cfa)) and what registers are in the window. */
980 dwarf2out_window_save (label)
981 register const char *label;
983 register dw_cfi_ref cfi = new_cfi ();
984 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
985 add_fde_cfi (label, cfi);
988 /* Add a CFI to update the running total of the size of arguments
989 pushed onto the stack. */
992 dwarf2out_args_size (label, size)
996 register dw_cfi_ref cfi;
998 if (size == old_args_size)
1000 old_args_size = size;
1003 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1004 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1005 add_fde_cfi (label, cfi);
1008 /* Entry point for saving a register to the stack. REG is the GCC register
1009 number. LABEL and OFFSET are passed to reg_save. */
1012 dwarf2out_reg_save (label, reg, offset)
1013 register const char *label;
1014 register unsigned reg;
1015 register long offset;
1017 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
1020 /* Entry point for saving the return address in the stack.
1021 LABEL and OFFSET are passed to reg_save. */
1024 dwarf2out_return_save (label, offset)
1025 register const char *label;
1026 register long offset;
1028 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
1031 /* Entry point for saving the return address in a register.
1032 LABEL and SREG are passed to reg_save. */
1035 dwarf2out_return_reg (label, sreg)
1036 register const char *label;
1037 register unsigned sreg;
1039 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
1042 /* Record the initial position of the return address. RTL is
1043 INCOMING_RETURN_ADDR_RTX. */
1046 initial_return_save (rtl)
1049 unsigned int reg = (unsigned int) -1;
1052 switch (GET_CODE (rtl))
1055 /* RA is in a register. */
1056 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1059 /* RA is on the stack. */
1060 rtl = XEXP (rtl, 0);
1061 switch (GET_CODE (rtl))
1064 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1069 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1071 offset = INTVAL (XEXP (rtl, 1));
1074 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1076 offset = -INTVAL (XEXP (rtl, 1));
1083 /* The return address is at some offset from any value we can
1084 actually load. For instance, on the SPARC it is in %i7+8. Just
1085 ignore the offset for now; it doesn't matter for unwinding frames. */
1086 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1088 initial_return_save (XEXP (rtl, 0));
1094 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1097 /* Check INSN to see if it looks like a push or a stack adjustment, and
1098 make a note of it if it does. EH uses this information to find out how
1099 much extra space it needs to pop off the stack. */
1102 dwarf2out_stack_adjust (insn)
1108 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1110 /* Extract the size of the args from the CALL rtx itself. */
1112 insn = PATTERN (insn);
1113 if (GET_CODE (insn) == PARALLEL)
1114 insn = XVECEXP (insn, 0, 0);
1115 if (GET_CODE (insn) == SET)
1116 insn = SET_SRC (insn);
1117 if (GET_CODE (insn) != CALL)
1119 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1123 /* If only calls can throw, and we have a frame pointer,
1124 save up adjustments until we see the CALL_INSN. */
1125 else if (! asynchronous_exceptions
1126 && cfa.reg != STACK_POINTER_REGNUM)
1129 if (GET_CODE (insn) == BARRIER)
1131 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1132 the compiler will have already emitted a stack adjustment, but
1133 doesn't bother for calls to noreturn functions. */
1134 #ifdef STACK_GROWS_DOWNWARD
1135 offset = -args_size;
1140 else if (GET_CODE (PATTERN (insn)) == SET)
1145 insn = PATTERN (insn);
1146 src = SET_SRC (insn);
1147 dest = SET_DEST (insn);
1149 if (dest == stack_pointer_rtx)
1151 /* (set (reg sp) (plus (reg sp) (const_int))) */
1152 code = GET_CODE (src);
1153 if (! (code == PLUS || code == MINUS)
1154 || XEXP (src, 0) != stack_pointer_rtx
1155 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1158 offset = INTVAL (XEXP (src, 1));
1160 else if (GET_CODE (dest) == MEM)
1162 /* (set (mem (pre_dec (reg sp))) (foo)) */
1163 src = XEXP (dest, 0);
1164 code = GET_CODE (src);
1166 if (! (code == PRE_DEC || code == PRE_INC)
1167 || XEXP (src, 0) != stack_pointer_rtx)
1170 offset = GET_MODE_SIZE (GET_MODE (dest));
1175 if (code == PLUS || code == PRE_INC)
1184 if (cfa.reg == STACK_POINTER_REGNUM)
1185 cfa.offset += offset;
1187 #ifndef STACK_GROWS_DOWNWARD
1190 args_size += offset;
1194 label = dwarf2out_cfi_label ();
1195 def_cfa_1 (label, &cfa);
1196 dwarf2out_args_size (label, args_size);
1199 /* A temporary register used in adjusting SP or setting up the store_reg. */
1200 static unsigned cfa_temp_reg;
1202 /* A temporary value used in adjusting SP or setting up the store_reg. */
1203 static long cfa_temp_value;
1205 /* Record call frame debugging information for an expression, which either
1206 sets SP or FP (adjusting how we calculate the frame address) or saves a
1207 register to the stack. */
1210 dwarf2out_frame_debug_expr (expr, label)
1217 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1218 the PARALLEL independently. The first element is always processed if
1219 it is a SET. This is for backward compatability. Other elements
1220 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1221 flag is set in them. */
1223 if (GET_CODE (expr) == PARALLEL
1224 || GET_CODE (expr) == SEQUENCE)
1227 int limit = XVECLEN (expr, 0);
1229 for (par_index = 0; par_index < limit; par_index++)
1231 rtx x = XVECEXP (expr, 0, par_index);
1233 if (GET_CODE (x) == SET &&
1234 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1235 dwarf2out_frame_debug_expr (x, label);
1240 if (GET_CODE (expr) != SET)
1243 src = SET_SRC (expr);
1244 dest = SET_DEST (expr);
1246 switch (GET_CODE (dest))
1249 /* Update the CFA rule wrt SP or FP. Make sure src is
1250 relative to the current CFA register. */
1251 switch (GET_CODE (src))
1253 /* Setting FP from SP. */
1255 if (cfa.reg == (unsigned) REGNO (src))
1260 /* We used to require that dest be either SP or FP, but the
1261 ARM copies SP to a temporary register, and from there to
1262 FP. So we just rely on the backends to only set
1263 RTX_FRAME_RELATED_P on appropriate insns. */
1264 cfa.reg = REGNO (dest);
1269 if (dest == stack_pointer_rtx)
1272 switch (GET_CODE (XEXP (src, 1)))
1275 offset = INTVAL (XEXP (src, 1));
1278 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1280 offset = cfa_temp_value;
1286 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1288 /* Restoring SP from FP in the epilogue. */
1289 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1291 cfa.reg = STACK_POINTER_REGNUM;
1293 else if (XEXP (src, 0) != stack_pointer_rtx)
1296 if (GET_CODE (src) == PLUS)
1298 if (cfa.reg == STACK_POINTER_REGNUM)
1299 cfa.offset += offset;
1300 if (cfa_store.reg == STACK_POINTER_REGNUM)
1301 cfa_store.offset += offset;
1303 else if (dest == hard_frame_pointer_rtx)
1305 /* Either setting the FP from an offset of the SP,
1306 or adjusting the FP */
1307 if (! frame_pointer_needed)
1310 if (GET_CODE (XEXP (src, 0)) == REG
1311 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1312 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1314 offset = INTVAL (XEXP (src, 1));
1315 if (GET_CODE (src) == PLUS)
1317 cfa.offset += offset;
1318 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1325 if (GET_CODE (src) != PLUS
1326 || XEXP (src, 1) != stack_pointer_rtx)
1328 if (GET_CODE (XEXP (src, 0)) != REG
1329 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1331 if (cfa.reg != STACK_POINTER_REGNUM)
1333 cfa_store.reg = REGNO (dest);
1334 cfa_store.offset = cfa.offset - cfa_temp_value;
1339 cfa_temp_reg = REGNO (dest);
1340 cfa_temp_value = INTVAL (src);
1344 if (GET_CODE (XEXP (src, 0)) != REG
1345 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1346 || (unsigned) REGNO (dest) != cfa_temp_reg
1347 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1349 cfa_temp_value |= INTVAL (XEXP (src, 1));
1355 def_cfa_1 (label, &cfa);
1358 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1359 will fill in all of the bits. */
1364 cfa_temp_reg = REGNO (dest);
1365 cfa_temp_value = INTVAL (XEXP (src, 1));
1369 if (GET_CODE (src) != REG)
1372 /* Saving a register to the stack. Make sure dest is relative to the
1374 switch (GET_CODE (XEXP (dest, 0)))
1379 offset = GET_MODE_SIZE (GET_MODE (dest));
1380 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1383 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1384 || cfa_store.reg != STACK_POINTER_REGNUM)
1386 cfa_store.offset += offset;
1387 if (cfa.reg == STACK_POINTER_REGNUM)
1388 cfa.offset = cfa_store.offset;
1390 offset = -cfa_store.offset;
1393 /* With an offset. */
1396 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1397 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1400 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1402 offset -= cfa_store.offset;
1405 /* Without an offset. */
1407 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1409 offset = -cfa_store.offset;
1416 if (REGNO (src) != STACK_POINTER_REGNUM
1417 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1418 && (unsigned) REGNO (src) == cfa.reg)
1420 /* We're storing the current CFA reg into the stack. */
1422 if (cfa.offset == 0)
1424 /* If the source register is exactly the CFA, assume
1425 we're saving SP like any other register; this happens
1428 def_cfa_1 (label, &cfa);
1429 dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset);
1434 /* Otherwise, we'll need to look in the stack to
1435 calculate the CFA. */
1437 rtx x = XEXP (dest, 0);
1438 if (GET_CODE (x) != REG)
1440 if (GET_CODE (x) != REG)
1442 cfa.reg = (unsigned) REGNO (x);
1443 cfa.base_offset = offset;
1445 def_cfa_1 (label, &cfa);
1450 def_cfa_1 (label, &cfa);
1451 dwarf2out_reg_save (label, REGNO (src), offset);
1460 /* Record call frame debugging information for INSN, which either
1461 sets SP or FP (adjusting how we calculate the frame address) or saves a
1462 register to the stack. If INSN is NULL_RTX, initialize our state. */
1465 dwarf2out_frame_debug (insn)
1471 if (insn == NULL_RTX)
1473 /* Set up state for generating call frame debug info. */
1475 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1477 cfa.reg = STACK_POINTER_REGNUM;
1484 if (! RTX_FRAME_RELATED_P (insn))
1486 dwarf2out_stack_adjust (insn);
1490 label = dwarf2out_cfi_label ();
1492 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1494 insn = XEXP (src, 0);
1496 insn = PATTERN (insn);
1498 dwarf2out_frame_debug_expr (insn, label);
1501 /* Return the size of an unsigned LEB128 quantity. */
1503 static inline unsigned long
1504 size_of_uleb128 (value)
1505 register unsigned long value;
1507 register unsigned long size = 0;
1508 register unsigned byte;
1512 byte = (value & 0x7f);
1521 /* Return the size of a signed LEB128 quantity. */
1523 static inline unsigned long
1524 size_of_sleb128 (value)
1525 register long value;
1527 register unsigned long size = 0;
1528 register unsigned byte;
1532 byte = (value & 0x7f);
1536 while (!(((value == 0) && ((byte & 0x40) == 0))
1537 || ((value == -1) && ((byte & 0x40) != 0))));
1542 /* Output an unsigned LEB128 quantity. */
1545 output_uleb128 (value)
1546 register unsigned long value;
1548 unsigned long save_value = value;
1550 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1553 register unsigned byte = (value & 0x7f);
1556 /* More bytes to follow. */
1559 fprintf (asm_out_file, "0x%x", byte);
1561 fprintf (asm_out_file, ",");
1566 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1569 /* Output an signed LEB128 quantity. */
1572 output_sleb128 (value)
1573 register long value;
1576 register unsigned byte;
1577 long save_value = value;
1579 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1582 byte = (value & 0x7f);
1583 /* arithmetic shift */
1585 more = !((((value == 0) && ((byte & 0x40) == 0))
1586 || ((value == -1) && ((byte & 0x40) != 0))));
1590 fprintf (asm_out_file, "0x%x", byte);
1592 fprintf (asm_out_file, ",");
1597 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1600 /* Output a Call Frame Information opcode and its operand(s). */
1603 output_cfi (cfi, fde)
1604 register dw_cfi_ref cfi;
1605 register dw_fde_ref fde;
1607 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1609 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1611 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1613 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1614 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1615 fputc ('\n', asm_out_file);
1618 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1620 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1622 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1624 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1625 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1627 fputc ('\n', asm_out_file);
1628 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1629 fputc ('\n', asm_out_file);
1631 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1633 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1635 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1637 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1638 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1640 fputc ('\n', asm_out_file);
1644 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1646 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1647 dwarf_cfi_name (cfi->dw_cfi_opc));
1649 fputc ('\n', asm_out_file);
1650 switch (cfi->dw_cfi_opc)
1652 case DW_CFA_set_loc:
1653 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1654 fputc ('\n', asm_out_file);
1656 case DW_CFA_advance_loc1:
1657 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1658 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1659 fde->dw_fde_current_label);
1660 fputc ('\n', asm_out_file);
1661 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1663 case DW_CFA_advance_loc2:
1664 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1665 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1666 fde->dw_fde_current_label);
1667 fputc ('\n', asm_out_file);
1668 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1670 case DW_CFA_advance_loc4:
1671 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1672 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1673 fde->dw_fde_current_label);
1674 fputc ('\n', asm_out_file);
1675 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1677 #ifdef MIPS_DEBUGGING_INFO
1678 case DW_CFA_MIPS_advance_loc8:
1679 /* TODO: not currently implemented. */
1683 case DW_CFA_offset_extended:
1684 case DW_CFA_GNU_negative_offset_extended:
1685 case DW_CFA_def_cfa:
1686 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1687 fputc ('\n', asm_out_file);
1688 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1689 fputc ('\n', asm_out_file);
1691 case DW_CFA_restore_extended:
1692 case DW_CFA_undefined:
1693 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1694 fputc ('\n', asm_out_file);
1696 case DW_CFA_same_value:
1697 case DW_CFA_def_cfa_register:
1698 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1699 fputc ('\n', asm_out_file);
1701 case DW_CFA_register:
1702 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1703 fputc ('\n', asm_out_file);
1704 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1705 fputc ('\n', asm_out_file);
1707 case DW_CFA_def_cfa_offset:
1708 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1709 fputc ('\n', asm_out_file);
1711 case DW_CFA_GNU_window_save:
1713 case DW_CFA_GNU_args_size:
1714 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1715 fputc ('\n', asm_out_file);
1717 case DW_CFA_def_cfa_expression:
1718 output_cfa_loc (cfi);
1726 /* Output the call frame information used to used to record information
1727 that relates to calculating the frame pointer, and records the
1728 location of saved registers. */
1731 output_call_frame_info (for_eh)
1734 register unsigned long i;
1735 register dw_fde_ref fde;
1736 register dw_cfi_ref cfi;
1737 char l1[20], l2[20];
1738 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1742 /* Do we want to include a pointer to the exception table? */
1743 int eh_ptr = for_eh && exception_table_p ();
1745 /* If we don't have any functions we'll want to unwind out of, don't
1746 emit any EH unwind information. */
1749 for (i = 0; i < fde_table_in_use; ++i)
1750 if (! fde_table[i].nothrow)
1756 fputc ('\n', asm_out_file);
1758 /* We're going to be generating comments, so turn on app. */
1764 #ifdef EH_FRAME_SECTION
1765 EH_FRAME_SECTION ();
1767 tree label = get_file_function_name ('F');
1769 force_data_section ();
1770 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1771 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1772 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1774 assemble_label ("__FRAME_BEGIN__");
1777 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1779 /* Output the CIE. */
1780 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1781 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1782 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1783 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1785 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1787 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1790 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1792 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1795 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1798 fputc ('\n', asm_out_file);
1799 ASM_OUTPUT_LABEL (asm_out_file, l1);
1802 /* Now that the CIE pointer is PC-relative for EH,
1803 use 0 to identify the CIE. */
1804 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1806 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1809 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1811 fputc ('\n', asm_out_file);
1812 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1814 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1815 fputc ('\n', asm_out_file);
1818 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1820 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1822 fputc ('\n', asm_out_file);
1825 /* The CIE contains a pointer to the exception region info for the
1826 frame. Make the augmentation string three bytes (including the
1827 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1828 can't handle unaligned relocs. */
1831 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1832 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1836 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1838 fputc ('\n', asm_out_file);
1840 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1842 fprintf (asm_out_file, "\t%s pointer to exception region info",
1847 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1849 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1853 fputc ('\n', asm_out_file);
1856 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1858 fputc ('\n', asm_out_file);
1859 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1861 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1863 fputc ('\n', asm_out_file);
1864 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1866 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1868 fputc ('\n', asm_out_file);
1870 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1871 output_cfi (cfi, NULL);
1873 /* Pad the CIE out to an address sized boundary. */
1874 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1875 ASM_OUTPUT_LABEL (asm_out_file, l2);
1876 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1877 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1879 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1880 fputc ('\n', asm_out_file);
1883 /* Loop through all of the FDE's. */
1884 for (i = 0; i < fde_table_in_use; ++i)
1886 fde = &fde_table[i];
1888 /* Don't emit EH unwind info for leaf functions. */
1889 if (for_eh && fde->nothrow)
1892 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2);
1893 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2);
1894 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1895 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2);
1897 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1899 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1902 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1904 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1907 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1908 fputc ('\n', asm_out_file);
1909 ASM_OUTPUT_LABEL (asm_out_file, l1);
1911 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1912 emits a target dependent sized offset when for_eh is not true.
1913 This inconsistency may confuse gdb. The only case where we need a
1914 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1915 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1916 though in order to be compatible with the dwarf_fde struct in frame.c.
1917 If the for_eh case is changed, then the struct in frame.c has
1918 to be adjusted appropriately. */
1920 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1922 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1924 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1926 fputc ('\n', asm_out_file);
1927 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1929 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1931 fputc ('\n', asm_out_file);
1932 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1933 fde->dw_fde_end, fde->dw_fde_begin);
1935 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1937 fputc ('\n', asm_out_file);
1939 /* Loop through the Call Frame Instructions associated with
1941 fde->dw_fde_current_label = fde->dw_fde_begin;
1942 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1943 output_cfi (cfi, fde);
1945 /* Pad the FDE out to an address sized boundary. */
1946 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1947 ASM_OUTPUT_LABEL (asm_out_file, l2);
1948 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1949 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1951 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1952 fputc ('\n', asm_out_file);
1955 #ifndef EH_FRAME_SECTION
1958 /* Emit terminating zero for table. */
1959 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1960 fputc ('\n', asm_out_file);
1963 #ifdef MIPS_DEBUGGING_INFO
1964 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1965 get a value of 0. Putting .align 0 after the label fixes it. */
1966 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1969 /* Turn off app to make assembly quicker. */
1974 /* Output a marker (i.e. a label) for the beginning of a function, before
1978 dwarf2out_begin_prologue ()
1980 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1981 register dw_fde_ref fde;
1983 ++current_funcdef_number;
1985 function_section (current_function_decl);
1986 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1987 current_funcdef_number);
1988 ASM_OUTPUT_LABEL (asm_out_file, label);
1989 current_function_func_begin_label = get_identifier (label);
1991 /* Expand the fde table if necessary. */
1992 if (fde_table_in_use == fde_table_allocated)
1994 fde_table_allocated += FDE_TABLE_INCREMENT;
1996 = (dw_fde_ref) xrealloc (fde_table,
1997 fde_table_allocated * sizeof (dw_fde_node));
2000 /* Record the FDE associated with this function. */
2001 current_funcdef_fde = fde_table_in_use;
2003 /* Add the new FDE at the end of the fde_table. */
2004 fde = &fde_table[fde_table_in_use++];
2005 fde->dw_fde_begin = xstrdup (label);
2006 fde->dw_fde_current_label = NULL;
2007 fde->dw_fde_end = NULL;
2008 fde->dw_fde_cfi = NULL;
2009 fde->nothrow = current_function_nothrow;
2011 args_size = old_args_size = 0;
2014 /* Output a marker (i.e. a label) for the absolute end of the generated code
2015 for a function definition. This gets called *after* the epilogue code has
2019 dwarf2out_end_epilogue ()
2022 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2024 /* Output a label to mark the endpoint of the code generated for this
2026 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2027 ASM_OUTPUT_LABEL (asm_out_file, label);
2028 fde = &fde_table[fde_table_in_use - 1];
2029 fde->dw_fde_end = xstrdup (label);
2033 dwarf2out_frame_init ()
2035 /* Allocate the initial hunk of the fde_table. */
2036 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2037 fde_table_allocated = FDE_TABLE_INCREMENT;
2038 fde_table_in_use = 0;
2040 /* Generate the CFA instructions common to all FDE's. Do it now for the
2041 sake of lookup_cfa. */
2043 #ifdef DWARF2_UNWIND_INFO
2044 /* On entry, the Canonical Frame Address is at SP. */
2045 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2046 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2051 dwarf2out_frame_finish ()
2053 /* Output call frame information. */
2054 #ifdef MIPS_DEBUGGING_INFO
2055 if (write_symbols == DWARF2_DEBUG)
2056 output_call_frame_info (0);
2057 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2058 output_call_frame_info (1);
2060 if (write_symbols == DWARF2_DEBUG
2061 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2062 output_call_frame_info (1);
2066 /* And now, the subset of the debugging information support code necessary
2067 for emitting location expressions. */
2069 typedef struct dw_val_struct *dw_val_ref;
2070 typedef struct die_struct *dw_die_ref;
2071 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2073 /* Each DIE may have a series of attribute/value pairs. Values
2074 can take on several forms. The forms that are used in this
2075 implementation are listed below. */
2082 dw_val_class_unsigned_const,
2083 dw_val_class_long_long,
2086 dw_val_class_die_ref,
2087 dw_val_class_fde_ref,
2088 dw_val_class_lbl_id,
2089 dw_val_class_lbl_offset,
2094 /* Describe a double word constant value. */
2095 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2097 typedef struct dw_long_long_struct
2104 /* Describe a floating point constant value. */
2106 typedef struct dw_fp_struct
2113 /* The dw_val_node describes an attribute's value, as it is
2114 represented internally. */
2116 typedef struct dw_val_struct
2118 dw_val_class val_class;
2122 dw_loc_descr_ref val_loc;
2124 long unsigned val_unsigned;
2125 dw_long_long_const val_long_long;
2126 dw_float_const val_float;
2127 dw_die_ref val_die_ref;
2128 unsigned val_fde_index;
2131 unsigned char val_flag;
2137 /* Locations in memory are described using a sequence of stack machine
2140 typedef struct dw_loc_descr_struct
2142 dw_loc_descr_ref dw_loc_next;
2143 enum dwarf_location_atom dw_loc_opc;
2144 dw_val_node dw_loc_oprnd1;
2145 dw_val_node dw_loc_oprnd2;
2149 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2150 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2153 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2155 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2156 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2157 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2158 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2160 /* Convert a DWARF stack opcode into its string name. */
2163 dwarf_stack_op_name (op)
2164 register unsigned op;
2169 return "DW_OP_addr";
2171 return "DW_OP_deref";
2173 return "DW_OP_const1u";
2175 return "DW_OP_const1s";
2177 return "DW_OP_const2u";
2179 return "DW_OP_const2s";
2181 return "DW_OP_const4u";
2183 return "DW_OP_const4s";
2185 return "DW_OP_const8u";
2187 return "DW_OP_const8s";
2189 return "DW_OP_constu";
2191 return "DW_OP_consts";
2195 return "DW_OP_drop";
2197 return "DW_OP_over";
2199 return "DW_OP_pick";
2201 return "DW_OP_swap";
2205 return "DW_OP_xderef";
2213 return "DW_OP_minus";
2225 return "DW_OP_plus";
2226 case DW_OP_plus_uconst:
2227 return "DW_OP_plus_uconst";
2233 return "DW_OP_shra";
2251 return "DW_OP_skip";
2253 return "DW_OP_lit0";
2255 return "DW_OP_lit1";
2257 return "DW_OP_lit2";
2259 return "DW_OP_lit3";
2261 return "DW_OP_lit4";
2263 return "DW_OP_lit5";
2265 return "DW_OP_lit6";
2267 return "DW_OP_lit7";
2269 return "DW_OP_lit8";
2271 return "DW_OP_lit9";
2273 return "DW_OP_lit10";
2275 return "DW_OP_lit11";
2277 return "DW_OP_lit12";
2279 return "DW_OP_lit13";
2281 return "DW_OP_lit14";
2283 return "DW_OP_lit15";
2285 return "DW_OP_lit16";
2287 return "DW_OP_lit17";
2289 return "DW_OP_lit18";
2291 return "DW_OP_lit19";
2293 return "DW_OP_lit20";
2295 return "DW_OP_lit21";
2297 return "DW_OP_lit22";
2299 return "DW_OP_lit23";
2301 return "DW_OP_lit24";
2303 return "DW_OP_lit25";
2305 return "DW_OP_lit26";
2307 return "DW_OP_lit27";
2309 return "DW_OP_lit28";
2311 return "DW_OP_lit29";
2313 return "DW_OP_lit30";
2315 return "DW_OP_lit31";
2317 return "DW_OP_reg0";
2319 return "DW_OP_reg1";
2321 return "DW_OP_reg2";
2323 return "DW_OP_reg3";
2325 return "DW_OP_reg4";
2327 return "DW_OP_reg5";
2329 return "DW_OP_reg6";
2331 return "DW_OP_reg7";
2333 return "DW_OP_reg8";
2335 return "DW_OP_reg9";
2337 return "DW_OP_reg10";
2339 return "DW_OP_reg11";
2341 return "DW_OP_reg12";
2343 return "DW_OP_reg13";
2345 return "DW_OP_reg14";
2347 return "DW_OP_reg15";
2349 return "DW_OP_reg16";
2351 return "DW_OP_reg17";
2353 return "DW_OP_reg18";
2355 return "DW_OP_reg19";
2357 return "DW_OP_reg20";
2359 return "DW_OP_reg21";
2361 return "DW_OP_reg22";
2363 return "DW_OP_reg23";
2365 return "DW_OP_reg24";
2367 return "DW_OP_reg25";
2369 return "DW_OP_reg26";
2371 return "DW_OP_reg27";
2373 return "DW_OP_reg28";
2375 return "DW_OP_reg29";
2377 return "DW_OP_reg30";
2379 return "DW_OP_reg31";
2381 return "DW_OP_breg0";
2383 return "DW_OP_breg1";
2385 return "DW_OP_breg2";
2387 return "DW_OP_breg3";
2389 return "DW_OP_breg4";
2391 return "DW_OP_breg5";
2393 return "DW_OP_breg6";
2395 return "DW_OP_breg7";
2397 return "DW_OP_breg8";
2399 return "DW_OP_breg9";
2401 return "DW_OP_breg10";
2403 return "DW_OP_breg11";
2405 return "DW_OP_breg12";
2407 return "DW_OP_breg13";
2409 return "DW_OP_breg14";
2411 return "DW_OP_breg15";
2413 return "DW_OP_breg16";
2415 return "DW_OP_breg17";
2417 return "DW_OP_breg18";
2419 return "DW_OP_breg19";
2421 return "DW_OP_breg20";
2423 return "DW_OP_breg21";
2425 return "DW_OP_breg22";
2427 return "DW_OP_breg23";
2429 return "DW_OP_breg24";
2431 return "DW_OP_breg25";
2433 return "DW_OP_breg26";
2435 return "DW_OP_breg27";
2437 return "DW_OP_breg28";
2439 return "DW_OP_breg29";
2441 return "DW_OP_breg30";
2443 return "DW_OP_breg31";
2445 return "DW_OP_regx";
2447 return "DW_OP_fbreg";
2449 return "DW_OP_bregx";
2451 return "DW_OP_piece";
2452 case DW_OP_deref_size:
2453 return "DW_OP_deref_size";
2454 case DW_OP_xderef_size:
2455 return "DW_OP_xderef_size";
2459 return "OP_<unknown>";
2464 /* Return a pointer to a newly allocated location description. Location
2465 descriptions are simple expression terms that can be strung
2466 together to form more complicated location (address) descriptions. */
2468 static inline dw_loc_descr_ref
2469 new_loc_descr (op, oprnd1, oprnd2)
2470 register enum dwarf_location_atom op;
2471 register unsigned long oprnd1;
2472 register unsigned long oprnd2;
2474 register dw_loc_descr_ref descr
2475 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
2477 descr->dw_loc_next = NULL;
2478 descr->dw_loc_opc = op;
2479 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2480 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2481 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2482 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2487 /* Add a location description term to a location description expression. */
2490 add_loc_descr (list_head, descr)
2491 register dw_loc_descr_ref *list_head;
2492 register dw_loc_descr_ref descr;
2494 register dw_loc_descr_ref *d;
2496 /* Find the end of the chain. */
2497 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2503 /* Return the size of a location descriptor. */
2505 static unsigned long
2506 size_of_loc_descr (loc)
2507 register dw_loc_descr_ref loc;
2509 register unsigned long size = 1;
2511 switch (loc->dw_loc_opc)
2514 size += DWARF2_ADDR_SIZE;
2533 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2536 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2541 case DW_OP_plus_uconst:
2542 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2580 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2583 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2586 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2589 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2590 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2593 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2595 case DW_OP_deref_size:
2596 case DW_OP_xderef_size:
2606 /* Return the size of a series of location descriptors. */
2608 static unsigned long
2610 register dw_loc_descr_ref loc;
2612 register unsigned long size = 0;
2614 for (; loc != NULL; loc = loc->dw_loc_next)
2615 size += size_of_loc_descr (loc);
2620 /* Output location description stack opcode's operands (if any). */
2623 output_loc_operands (loc)
2624 register dw_loc_descr_ref loc;
2626 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2627 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2629 switch (loc->dw_loc_opc)
2631 #ifdef DWARF2_DEBUGGING_INFO
2633 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
2634 fputc ('\n', asm_out_file);
2638 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2639 fputc ('\n', asm_out_file);
2643 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
2644 fputc ('\n', asm_out_file);
2649 fputc ('\n', asm_out_file);
2653 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2654 fputc ('\n', asm_out_file);
2666 /* We currently don't make any attempt to make sure these are
2667 aligned properly like we do for the main unwind info, so
2668 don't support emitting things larger than a byte if we're
2669 only doing unwinding. */
2674 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2675 fputc ('\n', asm_out_file);
2678 output_uleb128 (val1->v.val_unsigned);
2679 fputc ('\n', asm_out_file);
2682 output_sleb128 (val1->v.val_int);
2683 fputc ('\n', asm_out_file);
2686 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
2687 fputc ('\n', asm_out_file);
2689 case DW_OP_plus_uconst:
2690 output_uleb128 (val1->v.val_unsigned);
2691 fputc ('\n', asm_out_file);
2725 output_sleb128 (val1->v.val_int);
2726 fputc ('\n', asm_out_file);
2729 output_uleb128 (val1->v.val_unsigned);
2730 fputc ('\n', asm_out_file);
2733 output_sleb128 (val1->v.val_int);
2734 fputc ('\n', asm_out_file);
2737 output_uleb128 (val1->v.val_unsigned);
2738 fputc ('\n', asm_out_file);
2739 output_sleb128 (val2->v.val_int);
2740 fputc ('\n', asm_out_file);
2743 output_uleb128 (val1->v.val_unsigned);
2744 fputc ('\n', asm_out_file);
2746 case DW_OP_deref_size:
2747 case DW_OP_xderef_size:
2748 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2749 fputc ('\n', asm_out_file);
2752 /* Other codes have no operands. */
2757 /* Output a sequence of location operations. */
2760 output_loc_sequence (loc)
2761 dw_loc_descr_ref loc;
2763 for (; loc != NULL; loc = loc->dw_loc_next)
2765 /* Output the opcode. */
2766 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
2768 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
2769 dwarf_stack_op_name (loc->dw_loc_opc));
2771 fputc ('\n', asm_out_file);
2773 /* Output the operand(s) (if any). */
2774 output_loc_operands (loc);
2778 /* This routine will generate the correct assembly data for a location
2779 description based on a cfi entry with a complex address. */
2782 output_cfa_loc (cfi)
2785 dw_loc_descr_ref loc;
2788 /* Output the size of the block. */
2789 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2790 size = size_of_locs (loc);
2791 output_uleb128 (size);
2792 fputc ('\n', asm_out_file);
2794 /* Now output the operations themselves. */
2795 output_loc_sequence (loc);
2798 /* This function builds a dwarf location descriptor seqeunce from
2799 a dw_cfa_location. */
2801 static struct dw_loc_descr_struct *
2803 dw_cfa_location *cfa;
2805 struct dw_loc_descr_struct *head, *tmp;
2807 if (cfa->indirect == 0)
2810 if (cfa->base_offset)
2811 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2813 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2814 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2815 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2816 add_loc_descr (&head, tmp);
2817 if (cfa->offset != 0)
2819 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2820 add_loc_descr (&head, tmp);
2825 /* This function fills in aa dw_cfa_location structure from a
2826 dwarf location descriptor sequence. */
2829 get_cfa_from_loc_descr (cfa, loc)
2830 dw_cfa_location *cfa;
2831 struct dw_loc_descr_struct * loc;
2833 struct dw_loc_descr_struct * ptr;
2835 cfa->base_offset = 0;
2839 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2841 enum dwarf_location_atom op = ptr->dw_loc_opc;
2876 cfa->reg = op - DW_OP_reg0;
2879 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2913 cfa->reg = op - DW_OP_breg0;
2914 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2917 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2918 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2923 case DW_OP_plus_uconst:
2924 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2927 fatal ("DW_LOC_OP %s not implememnted yet.\n",
2928 dwarf_stack_op_name (ptr->dw_loc_opc));
2932 #endif /* .debug_frame support */
2934 /* And now, the support for symbolic debugging information. */
2935 #ifdef DWARF2_DEBUGGING_INFO
2937 /* NOTE: In the comments in this file, many references are made to
2938 "Debugging Information Entries". This term is abbreviated as `DIE'
2939 throughout the remainder of this file. */
2941 /* An internal representation of the DWARF output is built, and then
2942 walked to generate the DWARF debugging info. The walk of the internal
2943 representation is done after the entire program has been compiled.
2944 The types below are used to describe the internal representation. */
2946 /* Various DIE's use offsets relative to the beginning of the
2947 .debug_info section to refer to each other. */
2949 typedef long int dw_offset;
2951 /* Define typedefs here to avoid circular dependencies. */
2953 typedef struct dw_attr_struct *dw_attr_ref;
2954 typedef struct dw_line_info_struct *dw_line_info_ref;
2955 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
2956 typedef struct pubname_struct *pubname_ref;
2957 typedef dw_die_ref *arange_ref;
2959 /* Each entry in the line_info_table maintains the file and
2960 line number associated with the label generated for that
2961 entry. The label gives the PC value associated with
2962 the line number entry. */
2964 typedef struct dw_line_info_struct
2966 unsigned long dw_file_num;
2967 unsigned long dw_line_num;
2971 /* Line information for functions in separate sections; each one gets its
2973 typedef struct dw_separate_line_info_struct
2975 unsigned long dw_file_num;
2976 unsigned long dw_line_num;
2977 unsigned long function;
2979 dw_separate_line_info_entry;
2981 /* Each DIE attribute has a field specifying the attribute kind,
2982 a link to the next attribute in the chain, and an attribute value.
2983 Attributes are typically linked below the DIE they modify. */
2985 typedef struct dw_attr_struct
2987 enum dwarf_attribute dw_attr;
2988 dw_attr_ref dw_attr_next;
2989 dw_val_node dw_attr_val;
2993 /* The Debugging Information Entry (DIE) structure */
2995 typedef struct die_struct
2997 enum dwarf_tag die_tag;
2998 dw_attr_ref die_attr;
2999 dw_die_ref die_parent;
3000 dw_die_ref die_child;
3002 dw_offset die_offset;
3003 unsigned long die_abbrev;
3007 /* The pubname structure */
3009 typedef struct pubname_struct
3016 /* The limbo die list structure. */
3017 typedef struct limbo_die_struct
3020 struct limbo_die_struct *next;
3024 /* How to start an assembler comment. */
3025 #ifndef ASM_COMMENT_START
3026 #define ASM_COMMENT_START ";#"
3029 /* Define a macro which returns non-zero for a TYPE_DECL which was
3030 implicitly generated for a tagged type.
3032 Note that unlike the gcc front end (which generates a NULL named
3033 TYPE_DECL node for each complete tagged type, each array type, and
3034 each function type node created) the g++ front end generates a
3035 _named_ TYPE_DECL node for each tagged type node created.
3036 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3037 generate a DW_TAG_typedef DIE for them. */
3039 #define TYPE_DECL_IS_STUB(decl) \
3040 (DECL_NAME (decl) == NULL_TREE \
3041 || (DECL_ARTIFICIAL (decl) \
3042 && is_tagged_type (TREE_TYPE (decl)) \
3043 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3044 /* This is necessary for stub decls that \
3045 appear in nested inline functions. */ \
3046 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3047 && (decl_ultimate_origin (decl) \
3048 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3050 /* Information concerning the compilation unit's programming
3051 language, and compiler version. */
3053 extern int flag_traditional;
3055 /* Fixed size portion of the DWARF compilation unit header. */
3056 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3058 /* Fixed size portion of debugging line information prolog. */
3059 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3061 /* Fixed size portion of public names info. */
3062 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3064 /* Fixed size portion of the address range info. */
3065 #define DWARF_ARANGES_HEADER_SIZE \
3066 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3067 - DWARF_OFFSET_SIZE)
3069 /* Size of padding portion in the address range info. It must be
3070 aligned to twice the pointer size. */
3071 #define DWARF_ARANGES_PAD_SIZE \
3072 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3073 - (2 * DWARF_OFFSET_SIZE + 4))
3075 /* The default is to have gcc emit the line number tables. */
3076 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3077 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3080 /* Define the architecture-dependent minimum instruction length (in bytes).
3081 In this implementation of DWARF, this field is used for information
3082 purposes only. Since GCC generates assembly language, we have
3083 no a priori knowledge of how many instruction bytes are generated
3084 for each source line, and therefore can use only the DW_LNE_set_address
3085 and DW_LNS_fixed_advance_pc line information commands. */
3087 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3088 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3091 /* Minimum line offset in a special line info. opcode.
3092 This value was chosen to give a reasonable range of values. */
3093 #define DWARF_LINE_BASE -10
3095 /* First special line opcde - leave room for the standard opcodes. */
3096 #define DWARF_LINE_OPCODE_BASE 10
3098 /* Range of line offsets in a special line info. opcode. */
3099 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3101 /* Flag that indicates the initial value of the is_stmt_start flag.
3102 In the present implementation, we do not mark any lines as
3103 the beginning of a source statement, because that information
3104 is not made available by the GCC front-end. */
3105 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3107 /* This location is used by calc_die_sizes() to keep track
3108 the offset of each DIE within the .debug_info section. */
3109 static unsigned long next_die_offset;
3111 /* Record the root of the DIE's built for the current compilation unit. */
3112 static dw_die_ref comp_unit_die;
3114 /* A list of DIEs with a NULL parent waiting to be relocated. */
3115 static limbo_die_node *limbo_die_list = 0;
3117 /* Pointer to an array of filenames referenced by this compilation unit. */
3118 static char **file_table;
3120 /* Total number of entries in the table (i.e. array) pointed to by
3121 `file_table'. This is the *total* and includes both used and unused
3123 static unsigned file_table_allocated;
3125 /* Number of entries in the file_table which are actually in use. */
3126 static unsigned file_table_in_use;
3128 /* Size (in elements) of increments by which we may expand the filename
3130 #define FILE_TABLE_INCREMENT 64
3132 /* Local pointer to the name of the main input file. Initialized in
3134 static const char *primary_filename;
3136 /* A pointer to the base of a table of references to DIE's that describe
3137 declarations. The table is indexed by DECL_UID() which is a unique
3138 number identifying each decl. */
3139 static dw_die_ref *decl_die_table;
3141 /* Number of elements currently allocated for the decl_die_table. */
3142 static unsigned decl_die_table_allocated;
3144 /* Number of elements in decl_die_table currently in use. */
3145 static unsigned decl_die_table_in_use;
3147 /* Size (in elements) of increments by which we may expand the
3149 #define DECL_DIE_TABLE_INCREMENT 256
3151 /* A pointer to the base of a table of references to declaration
3152 scopes. This table is a display which tracks the nesting
3153 of declaration scopes at the current scope and containing
3154 scopes. This table is used to find the proper place to
3155 define type declaration DIE's. */
3156 static tree *decl_scope_table;
3158 /* Number of elements currently allocated for the decl_scope_table. */
3159 static int decl_scope_table_allocated;
3161 /* Current level of nesting of declaration scopes. */
3162 static int decl_scope_depth;
3164 /* Size (in elements) of increments by which we may expand the
3165 decl_scope_table. */
3166 #define DECL_SCOPE_TABLE_INCREMENT 64
3168 /* A pointer to the base of a list of references to DIE's that
3169 are uniquely identified by their tag, presence/absence of
3170 children DIE's, and list of attribute/value pairs. */
3171 static dw_die_ref *abbrev_die_table;
3173 /* Number of elements currently allocated for abbrev_die_table. */
3174 static unsigned abbrev_die_table_allocated;
3176 /* Number of elements in type_die_table currently in use. */
3177 static unsigned abbrev_die_table_in_use;
3179 /* Size (in elements) of increments by which we may expand the
3180 abbrev_die_table. */
3181 #define ABBREV_DIE_TABLE_INCREMENT 256
3183 /* A pointer to the base of a table that contains line information
3184 for each source code line in .text in the compilation unit. */
3185 static dw_line_info_ref line_info_table;
3187 /* Number of elements currently allocated for line_info_table. */
3188 static unsigned line_info_table_allocated;
3190 /* Number of elements in separate_line_info_table currently in use. */
3191 static unsigned separate_line_info_table_in_use;
3193 /* A pointer to the base of a table that contains line information
3194 for each source code line outside of .text in the compilation unit. */
3195 static dw_separate_line_info_ref separate_line_info_table;
3197 /* Number of elements currently allocated for separate_line_info_table. */
3198 static unsigned separate_line_info_table_allocated;
3200 /* Number of elements in line_info_table currently in use. */
3201 static unsigned line_info_table_in_use;
3203 /* Size (in elements) of increments by which we may expand the
3205 #define LINE_INFO_TABLE_INCREMENT 1024
3207 /* A pointer to the base of a table that contains a list of publicly
3208 accessible names. */
3209 static pubname_ref pubname_table;
3211 /* Number of elements currently allocated for pubname_table. */
3212 static unsigned pubname_table_allocated;
3214 /* Number of elements in pubname_table currently in use. */
3215 static unsigned pubname_table_in_use;
3217 /* Size (in elements) of increments by which we may expand the
3219 #define PUBNAME_TABLE_INCREMENT 64
3221 /* A pointer to the base of a table that contains a list of publicly
3222 accessible names. */
3223 static arange_ref arange_table;
3225 /* Number of elements currently allocated for arange_table. */
3226 static unsigned arange_table_allocated;
3228 /* Number of elements in arange_table currently in use. */
3229 static unsigned arange_table_in_use;
3231 /* Size (in elements) of increments by which we may expand the
3233 #define ARANGE_TABLE_INCREMENT 64
3235 /* A pointer to the base of a list of incomplete types which might be
3236 completed at some later time. */
3238 static tree *incomplete_types_list;
3240 /* Number of elements currently allocated for the incomplete_types_list. */
3241 static unsigned incomplete_types_allocated;
3243 /* Number of elements of incomplete_types_list currently in use. */
3244 static unsigned incomplete_types;
3246 /* Size (in elements) of increments by which we may expand the incomplete
3247 types list. Actually, a single hunk of space of this size should
3248 be enough for most typical programs. */
3249 #define INCOMPLETE_TYPES_INCREMENT 64
3251 /* Record whether the function being analyzed contains inlined functions. */
3252 static int current_function_has_inlines;
3253 #if 0 && defined (MIPS_DEBUGGING_INFO)
3254 static int comp_unit_has_inlines;
3257 /* Array of RTXes referenced by the debugging information, which therefore
3258 must be kept around forever. We do this rather than perform GC on
3259 the dwarf info because almost all of the dwarf info lives forever, and
3260 it's easier to support non-GC frontends this way. */
3261 static varray_type used_rtx_varray;
3263 /* Forward declarations for functions defined in this file. */
3265 static int is_pseudo_reg PARAMS ((rtx));
3266 static tree type_main_variant PARAMS ((tree));
3267 static int is_tagged_type PARAMS ((tree));
3268 static const char *dwarf_tag_name PARAMS ((unsigned));
3269 static const char *dwarf_attr_name PARAMS ((unsigned));
3270 static const char *dwarf_form_name PARAMS ((unsigned));
3272 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3274 static tree decl_ultimate_origin PARAMS ((tree));
3275 static tree block_ultimate_origin PARAMS ((tree));
3276 static tree decl_class_context PARAMS ((tree));
3277 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3278 static void add_AT_flag PARAMS ((dw_die_ref,
3279 enum dwarf_attribute,
3281 static void add_AT_int PARAMS ((dw_die_ref,
3282 enum dwarf_attribute, long));
3283 static void add_AT_unsigned PARAMS ((dw_die_ref,
3284 enum dwarf_attribute,
3286 static void add_AT_long_long PARAMS ((dw_die_ref,
3287 enum dwarf_attribute,
3290 static void add_AT_float PARAMS ((dw_die_ref,
3291 enum dwarf_attribute,
3293 static void add_AT_string PARAMS ((dw_die_ref,
3294 enum dwarf_attribute,
3296 static void add_AT_die_ref PARAMS ((dw_die_ref,
3297 enum dwarf_attribute,
3299 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3300 enum dwarf_attribute,
3302 static void add_AT_loc PARAMS ((dw_die_ref,
3303 enum dwarf_attribute,
3305 static void add_AT_addr PARAMS ((dw_die_ref,
3306 enum dwarf_attribute,
3308 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3309 enum dwarf_attribute,
3311 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3312 enum dwarf_attribute,
3314 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3315 enum dwarf_attribute));
3316 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3317 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3318 static const char *get_AT_string PARAMS ((dw_die_ref,
3319 enum dwarf_attribute));
3320 static int get_AT_flag PARAMS ((dw_die_ref,
3321 enum dwarf_attribute));
3322 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3323 enum dwarf_attribute));
3324 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3325 enum dwarf_attribute));
3326 static int is_c_family PARAMS ((void));
3327 static int is_fortran PARAMS ((void));
3328 static void remove_AT PARAMS ((dw_die_ref,
3329 enum dwarf_attribute));
3330 static void remove_children PARAMS ((dw_die_ref));
3331 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3332 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3333 static dw_die_ref lookup_type_die PARAMS ((tree));
3334 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3335 static dw_die_ref lookup_decl_die PARAMS ((tree));
3336 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3337 static void print_spaces PARAMS ((FILE *));
3338 static void print_die PARAMS ((dw_die_ref, FILE *));
3339 static void print_dwarf_line_table PARAMS ((FILE *));
3340 static void add_sibling_attributes PARAMS ((dw_die_ref));
3341 static void build_abbrev_table PARAMS ((dw_die_ref));
3342 static unsigned long size_of_string PARAMS ((const char *));
3343 static int constant_size PARAMS ((long unsigned));
3344 static unsigned long size_of_die PARAMS ((dw_die_ref));
3345 static void calc_die_sizes PARAMS ((dw_die_ref));
3346 static unsigned long size_of_line_prolog PARAMS ((void));
3347 static unsigned long size_of_pubnames PARAMS ((void));
3348 static unsigned long size_of_aranges PARAMS ((void));
3349 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3350 static void output_value_format PARAMS ((dw_attr_ref));
3351 static void output_abbrev_section PARAMS ((void));
3352 static void output_die PARAMS ((dw_die_ref));
3353 static void output_compilation_unit_header PARAMS ((void));
3354 static const char *dwarf2_name PARAMS ((tree, int));
3355 static void add_pubname PARAMS ((tree, dw_die_ref));
3356 static void output_pubnames PARAMS ((void));
3357 static void add_arange PARAMS ((tree, dw_die_ref));
3358 static void output_aranges PARAMS ((void));
3359 static void output_line_info PARAMS ((void));
3360 static dw_die_ref base_type_die PARAMS ((tree));
3361 static tree root_type PARAMS ((tree));
3362 static int is_base_type PARAMS ((tree));
3363 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3364 static int type_is_enum PARAMS ((tree));
3365 static unsigned int reg_number PARAMS ((rtx));
3366 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3367 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3368 static int is_based_loc PARAMS ((rtx));
3369 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3370 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3371 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3372 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3373 static tree field_type PARAMS ((tree));
3374 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3375 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3376 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3377 static void add_AT_location_description PARAMS ((dw_die_ref,
3378 enum dwarf_attribute, rtx));
3379 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3380 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3381 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3382 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3383 static void add_bound_info PARAMS ((dw_die_ref,
3384 enum dwarf_attribute, tree));
3385 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3386 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3387 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3388 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3389 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3390 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3391 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3392 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3393 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3394 static void push_decl_scope PARAMS ((tree));
3395 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3396 static void pop_decl_scope PARAMS ((void));
3397 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3399 static const char *type_tag PARAMS ((tree));
3400 static tree member_declared_type PARAMS ((tree));
3402 static const char *decl_start_label PARAMS ((tree));
3404 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3405 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3407 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3409 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3410 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3411 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3412 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3413 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3414 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3415 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3416 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3417 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3418 static void gen_label_die PARAMS ((tree, dw_die_ref));
3419 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3420 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3421 static void gen_field_die PARAMS ((tree, dw_die_ref));
3422 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3423 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3424 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3425 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3426 static void gen_member_die PARAMS ((tree, dw_die_ref));
3427 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3428 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3429 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3430 static void gen_type_die PARAMS ((tree, dw_die_ref));
3431 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3432 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3433 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3434 static int is_redundant_typedef PARAMS ((tree));
3435 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3436 static unsigned lookup_filename PARAMS ((const char *));
3437 static void add_incomplete_type PARAMS ((tree));
3438 static void retry_incomplete_types PARAMS ((void));
3439 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3440 static void gen_abstract_function PARAMS ((tree));
3441 static rtx save_rtx PARAMS ((rtx));
3442 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3443 static void reverse_die_lists PARAMS ((dw_die_ref));
3445 /* Section names used to hold DWARF debugging information. */
3446 #ifndef DEBUG_INFO_SECTION
3447 #define DEBUG_INFO_SECTION ".debug_info"
3449 #ifndef ABBREV_SECTION
3450 #define ABBREV_SECTION ".debug_abbrev"
3452 #ifndef ARANGES_SECTION
3453 #define ARANGES_SECTION ".debug_aranges"
3455 #ifndef DW_MACINFO_SECTION
3456 #define DW_MACINFO_SECTION ".debug_macinfo"
3458 #ifndef DEBUG_LINE_SECTION
3459 #define DEBUG_LINE_SECTION ".debug_line"
3462 #define LOC_SECTION ".debug_loc"
3464 #ifndef PUBNAMES_SECTION
3465 #define PUBNAMES_SECTION ".debug_pubnames"
3468 #define STR_SECTION ".debug_str"
3471 /* Standard ELF section names for compiled code and data. */
3472 #ifndef TEXT_SECTION
3473 #define TEXT_SECTION ".text"
3475 #ifndef DATA_SECTION
3476 #define DATA_SECTION ".data"
3479 #define BSS_SECTION ".bss"
3482 /* Labels we insert at beginning sections we can reference instead of
3483 the section names themselves. */
3485 #ifndef TEXT_SECTION_LABEL
3486 #define TEXT_SECTION_LABEL "Ltext"
3488 #ifndef DEBUG_LINE_SECTION_LABEL
3489 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3491 #ifndef DEBUG_INFO_SECTION_LABEL
3492 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3494 #ifndef ABBREV_SECTION_LABEL
3495 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3499 /* Definitions of defaults for formats and names of various special
3500 (artificial) labels which may be generated within this file (when the -g
3501 options is used and DWARF_DEBUGGING_INFO is in effect.
3502 If necessary, these may be overridden from within the tm.h file, but
3503 typically, overriding these defaults is unnecessary. */
3505 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3506 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3507 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3508 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3509 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3511 #ifndef TEXT_END_LABEL
3512 #define TEXT_END_LABEL "Letext"
3514 #ifndef DATA_END_LABEL
3515 #define DATA_END_LABEL "Ledata"
3517 #ifndef BSS_END_LABEL
3518 #define BSS_END_LABEL "Lebss"
3520 #ifndef INSN_LABEL_FMT
3521 #define INSN_LABEL_FMT "LI%u_"
3523 #ifndef BLOCK_BEGIN_LABEL
3524 #define BLOCK_BEGIN_LABEL "LBB"
3526 #ifndef BLOCK_END_LABEL
3527 #define BLOCK_END_LABEL "LBE"
3529 #ifndef BODY_BEGIN_LABEL
3530 #define BODY_BEGIN_LABEL "Lbb"
3532 #ifndef BODY_END_LABEL
3533 #define BODY_END_LABEL "Lbe"
3535 #ifndef LINE_CODE_LABEL
3536 #define LINE_CODE_LABEL "LM"
3538 #ifndef SEPARATE_LINE_CODE_LABEL
3539 #define SEPARATE_LINE_CODE_LABEL "LSM"
3542 /* We allow a language front-end to designate a function that is to be
3543 called to "demangle" any name before it it put into a DIE. */
3545 static const char *(*demangle_name_func) PARAMS ((const char *));
3548 dwarf2out_set_demangle_name_func (func)
3549 const char *(*func) PARAMS ((const char *));
3551 demangle_name_func = func;
3554 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3555 that means adding it to used_rtx_varray. If not, that means making
3556 a copy on the permanent_obstack. */
3563 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3566 push_obstacks_nochange ();
3567 end_temporary_allocation ();
3568 orig = copy_rtx (orig);
3575 /* Test if rtl node points to a pseudo register. */
3581 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3582 || (GET_CODE (rtl) == SUBREG
3583 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3586 /* Return a reference to a type, with its const and volatile qualifiers
3590 type_main_variant (type)
3593 type = TYPE_MAIN_VARIANT (type);
3595 /* There really should be only one main variant among any group of variants
3596 of a given type (and all of the MAIN_VARIANT values for all members of
3597 the group should point to that one type) but sometimes the C front-end
3598 messes this up for array types, so we work around that bug here. */
3600 if (TREE_CODE (type) == ARRAY_TYPE)
3601 while (type != TYPE_MAIN_VARIANT (type))
3602 type = TYPE_MAIN_VARIANT (type);
3607 /* Return non-zero if the given type node represents a tagged type. */
3610 is_tagged_type (type)
3613 register enum tree_code code = TREE_CODE (type);
3615 return (code == RECORD_TYPE || code == UNION_TYPE
3616 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3619 /* Convert a DIE tag into its string name. */
3622 dwarf_tag_name (tag)
3623 register unsigned tag;
3627 case DW_TAG_padding:
3628 return "DW_TAG_padding";
3629 case DW_TAG_array_type:
3630 return "DW_TAG_array_type";
3631 case DW_TAG_class_type:
3632 return "DW_TAG_class_type";
3633 case DW_TAG_entry_point:
3634 return "DW_TAG_entry_point";
3635 case DW_TAG_enumeration_type:
3636 return "DW_TAG_enumeration_type";
3637 case DW_TAG_formal_parameter:
3638 return "DW_TAG_formal_parameter";
3639 case DW_TAG_imported_declaration:
3640 return "DW_TAG_imported_declaration";
3642 return "DW_TAG_label";
3643 case DW_TAG_lexical_block:
3644 return "DW_TAG_lexical_block";
3646 return "DW_TAG_member";
3647 case DW_TAG_pointer_type:
3648 return "DW_TAG_pointer_type";
3649 case DW_TAG_reference_type:
3650 return "DW_TAG_reference_type";
3651 case DW_TAG_compile_unit:
3652 return "DW_TAG_compile_unit";
3653 case DW_TAG_string_type:
3654 return "DW_TAG_string_type";
3655 case DW_TAG_structure_type:
3656 return "DW_TAG_structure_type";
3657 case DW_TAG_subroutine_type:
3658 return "DW_TAG_subroutine_type";
3659 case DW_TAG_typedef:
3660 return "DW_TAG_typedef";
3661 case DW_TAG_union_type:
3662 return "DW_TAG_union_type";
3663 case DW_TAG_unspecified_parameters:
3664 return "DW_TAG_unspecified_parameters";
3665 case DW_TAG_variant:
3666 return "DW_TAG_variant";
3667 case DW_TAG_common_block:
3668 return "DW_TAG_common_block";
3669 case DW_TAG_common_inclusion:
3670 return "DW_TAG_common_inclusion";
3671 case DW_TAG_inheritance:
3672 return "DW_TAG_inheritance";
3673 case DW_TAG_inlined_subroutine:
3674 return "DW_TAG_inlined_subroutine";
3676 return "DW_TAG_module";
3677 case DW_TAG_ptr_to_member_type:
3678 return "DW_TAG_ptr_to_member_type";
3679 case DW_TAG_set_type:
3680 return "DW_TAG_set_type";
3681 case DW_TAG_subrange_type:
3682 return "DW_TAG_subrange_type";
3683 case DW_TAG_with_stmt:
3684 return "DW_TAG_with_stmt";
3685 case DW_TAG_access_declaration:
3686 return "DW_TAG_access_declaration";
3687 case DW_TAG_base_type:
3688 return "DW_TAG_base_type";
3689 case DW_TAG_catch_block:
3690 return "DW_TAG_catch_block";
3691 case DW_TAG_const_type:
3692 return "DW_TAG_const_type";
3693 case DW_TAG_constant:
3694 return "DW_TAG_constant";
3695 case DW_TAG_enumerator:
3696 return "DW_TAG_enumerator";
3697 case DW_TAG_file_type:
3698 return "DW_TAG_file_type";
3700 return "DW_TAG_friend";
3701 case DW_TAG_namelist:
3702 return "DW_TAG_namelist";
3703 case DW_TAG_namelist_item:
3704 return "DW_TAG_namelist_item";
3705 case DW_TAG_packed_type:
3706 return "DW_TAG_packed_type";
3707 case DW_TAG_subprogram:
3708 return "DW_TAG_subprogram";
3709 case DW_TAG_template_type_param:
3710 return "DW_TAG_template_type_param";
3711 case DW_TAG_template_value_param:
3712 return "DW_TAG_template_value_param";
3713 case DW_TAG_thrown_type:
3714 return "DW_TAG_thrown_type";
3715 case DW_TAG_try_block:
3716 return "DW_TAG_try_block";
3717 case DW_TAG_variant_part:
3718 return "DW_TAG_variant_part";
3719 case DW_TAG_variable:
3720 return "DW_TAG_variable";
3721 case DW_TAG_volatile_type:
3722 return "DW_TAG_volatile_type";
3723 case DW_TAG_MIPS_loop:
3724 return "DW_TAG_MIPS_loop";
3725 case DW_TAG_format_label:
3726 return "DW_TAG_format_label";
3727 case DW_TAG_function_template:
3728 return "DW_TAG_function_template";
3729 case DW_TAG_class_template:
3730 return "DW_TAG_class_template";
3732 return "DW_TAG_<unknown>";
3736 /* Convert a DWARF attribute code into its string name. */
3739 dwarf_attr_name (attr)
3740 register unsigned attr;
3745 return "DW_AT_sibling";
3746 case DW_AT_location:
3747 return "DW_AT_location";
3749 return "DW_AT_name";
3750 case DW_AT_ordering:
3751 return "DW_AT_ordering";
3752 case DW_AT_subscr_data:
3753 return "DW_AT_subscr_data";
3754 case DW_AT_byte_size:
3755 return "DW_AT_byte_size";
3756 case DW_AT_bit_offset:
3757 return "DW_AT_bit_offset";
3758 case DW_AT_bit_size:
3759 return "DW_AT_bit_size";
3760 case DW_AT_element_list:
3761 return "DW_AT_element_list";
3762 case DW_AT_stmt_list:
3763 return "DW_AT_stmt_list";
3765 return "DW_AT_low_pc";
3767 return "DW_AT_high_pc";
3768 case DW_AT_language:
3769 return "DW_AT_language";
3771 return "DW_AT_member";
3773 return "DW_AT_discr";
3774 case DW_AT_discr_value:
3775 return "DW_AT_discr_value";
3776 case DW_AT_visibility:
3777 return "DW_AT_visibility";
3779 return "DW_AT_import";
3780 case DW_AT_string_length:
3781 return "DW_AT_string_length";
3782 case DW_AT_common_reference:
3783 return "DW_AT_common_reference";
3784 case DW_AT_comp_dir:
3785 return "DW_AT_comp_dir";
3786 case DW_AT_const_value:
3787 return "DW_AT_const_value";
3788 case DW_AT_containing_type:
3789 return "DW_AT_containing_type";
3790 case DW_AT_default_value:
3791 return "DW_AT_default_value";
3793 return "DW_AT_inline";
3794 case DW_AT_is_optional:
3795 return "DW_AT_is_optional";
3796 case DW_AT_lower_bound:
3797 return "DW_AT_lower_bound";
3798 case DW_AT_producer:
3799 return "DW_AT_producer";
3800 case DW_AT_prototyped:
3801 return "DW_AT_prototyped";
3802 case DW_AT_return_addr:
3803 return "DW_AT_return_addr";
3804 case DW_AT_start_scope:
3805 return "DW_AT_start_scope";
3806 case DW_AT_stride_size:
3807 return "DW_AT_stride_size";
3808 case DW_AT_upper_bound:
3809 return "DW_AT_upper_bound";
3810 case DW_AT_abstract_origin:
3811 return "DW_AT_abstract_origin";
3812 case DW_AT_accessibility:
3813 return "DW_AT_accessibility";
3814 case DW_AT_address_class:
3815 return "DW_AT_address_class";
3816 case DW_AT_artificial:
3817 return "DW_AT_artificial";
3818 case DW_AT_base_types:
3819 return "DW_AT_base_types";
3820 case DW_AT_calling_convention:
3821 return "DW_AT_calling_convention";
3823 return "DW_AT_count";
3824 case DW_AT_data_member_location:
3825 return "DW_AT_data_member_location";
3826 case DW_AT_decl_column:
3827 return "DW_AT_decl_column";
3828 case DW_AT_decl_file:
3829 return "DW_AT_decl_file";
3830 case DW_AT_decl_line:
3831 return "DW_AT_decl_line";
3832 case DW_AT_declaration:
3833 return "DW_AT_declaration";
3834 case DW_AT_discr_list:
3835 return "DW_AT_discr_list";
3836 case DW_AT_encoding:
3837 return "DW_AT_encoding";
3838 case DW_AT_external:
3839 return "DW_AT_external";
3840 case DW_AT_frame_base:
3841 return "DW_AT_frame_base";
3843 return "DW_AT_friend";
3844 case DW_AT_identifier_case:
3845 return "DW_AT_identifier_case";
3846 case DW_AT_macro_info:
3847 return "DW_AT_macro_info";
3848 case DW_AT_namelist_items:
3849 return "DW_AT_namelist_items";
3850 case DW_AT_priority:
3851 return "DW_AT_priority";
3853 return "DW_AT_segment";
3854 case DW_AT_specification:
3855 return "DW_AT_specification";
3856 case DW_AT_static_link:
3857 return "DW_AT_static_link";
3859 return "DW_AT_type";
3860 case DW_AT_use_location:
3861 return "DW_AT_use_location";
3862 case DW_AT_variable_parameter:
3863 return "DW_AT_variable_parameter";
3864 case DW_AT_virtuality:
3865 return "DW_AT_virtuality";
3866 case DW_AT_vtable_elem_location:
3867 return "DW_AT_vtable_elem_location";
3869 case DW_AT_MIPS_fde:
3870 return "DW_AT_MIPS_fde";
3871 case DW_AT_MIPS_loop_begin:
3872 return "DW_AT_MIPS_loop_begin";
3873 case DW_AT_MIPS_tail_loop_begin:
3874 return "DW_AT_MIPS_tail_loop_begin";
3875 case DW_AT_MIPS_epilog_begin:
3876 return "DW_AT_MIPS_epilog_begin";
3877 case DW_AT_MIPS_loop_unroll_factor:
3878 return "DW_AT_MIPS_loop_unroll_factor";
3879 case DW_AT_MIPS_software_pipeline_depth:
3880 return "DW_AT_MIPS_software_pipeline_depth";
3881 case DW_AT_MIPS_linkage_name:
3882 return "DW_AT_MIPS_linkage_name";
3883 case DW_AT_MIPS_stride:
3884 return "DW_AT_MIPS_stride";
3885 case DW_AT_MIPS_abstract_name:
3886 return "DW_AT_MIPS_abstract_name";
3887 case DW_AT_MIPS_clone_origin:
3888 return "DW_AT_MIPS_clone_origin";
3889 case DW_AT_MIPS_has_inlines:
3890 return "DW_AT_MIPS_has_inlines";
3892 case DW_AT_sf_names:
3893 return "DW_AT_sf_names";
3894 case DW_AT_src_info:
3895 return "DW_AT_src_info";
3896 case DW_AT_mac_info:
3897 return "DW_AT_mac_info";
3898 case DW_AT_src_coords:
3899 return "DW_AT_src_coords";
3900 case DW_AT_body_begin:
3901 return "DW_AT_body_begin";
3902 case DW_AT_body_end:
3903 return "DW_AT_body_end";
3905 return "DW_AT_<unknown>";
3909 /* Convert a DWARF value form code into its string name. */
3912 dwarf_form_name (form)
3913 register unsigned form;
3918 return "DW_FORM_addr";
3919 case DW_FORM_block2:
3920 return "DW_FORM_block2";
3921 case DW_FORM_block4:
3922 return "DW_FORM_block4";
3924 return "DW_FORM_data2";
3926 return "DW_FORM_data4";
3928 return "DW_FORM_data8";
3929 case DW_FORM_string:
3930 return "DW_FORM_string";
3932 return "DW_FORM_block";
3933 case DW_FORM_block1:
3934 return "DW_FORM_block1";
3936 return "DW_FORM_data1";
3938 return "DW_FORM_flag";
3940 return "DW_FORM_sdata";
3942 return "DW_FORM_strp";
3944 return "DW_FORM_udata";
3945 case DW_FORM_ref_addr:
3946 return "DW_FORM_ref_addr";
3948 return "DW_FORM_ref1";
3950 return "DW_FORM_ref2";
3952 return "DW_FORM_ref4";
3954 return "DW_FORM_ref8";
3955 case DW_FORM_ref_udata:
3956 return "DW_FORM_ref_udata";
3957 case DW_FORM_indirect:
3958 return "DW_FORM_indirect";
3960 return "DW_FORM_<unknown>";
3964 /* Convert a DWARF type code into its string name. */
3968 dwarf_type_encoding_name (enc)
3969 register unsigned enc;
3973 case DW_ATE_address:
3974 return "DW_ATE_address";
3975 case DW_ATE_boolean:
3976 return "DW_ATE_boolean";
3977 case DW_ATE_complex_float:
3978 return "DW_ATE_complex_float";
3980 return "DW_ATE_float";
3982 return "DW_ATE_signed";
3983 case DW_ATE_signed_char:
3984 return "DW_ATE_signed_char";
3985 case DW_ATE_unsigned:
3986 return "DW_ATE_unsigned";
3987 case DW_ATE_unsigned_char:
3988 return "DW_ATE_unsigned_char";
3990 return "DW_ATE_<unknown>";
3995 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3996 instance of an inlined instance of a decl which is local to an inline
3997 function, so we have to trace all of the way back through the origin chain
3998 to find out what sort of node actually served as the original seed for the
4002 decl_ultimate_origin (decl)
4005 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4006 nodes in the function to point to themselves; ignore that if
4007 we're trying to output the abstract instance of this function. */
4008 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4011 #ifdef ENABLE_CHECKING
4012 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4013 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4014 most distant ancestor, this should never happen. */
4018 return DECL_ABSTRACT_ORIGIN (decl);
4021 /* Determine the "ultimate origin" of a block. The block may be an inlined
4022 instance of an inlined instance of a block which is local to an inline
4023 function, so we have to trace all of the way back through the origin chain
4024 to find out what sort of node actually served as the original seed for the
4028 block_ultimate_origin (block)
4029 register tree block;
4031 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4033 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4034 nodes in the function to point to themselves; ignore that if
4035 we're trying to output the abstract instance of this function. */
4036 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4039 if (immediate_origin == NULL_TREE)
4043 register tree ret_val;
4044 register tree lookahead = immediate_origin;
4048 ret_val = lookahead;
4049 lookahead = (TREE_CODE (ret_val) == BLOCK)
4050 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4053 while (lookahead != NULL && lookahead != ret_val);
4059 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4060 of a virtual function may refer to a base class, so we check the 'this'
4064 decl_class_context (decl)
4067 tree context = NULL_TREE;
4069 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4070 context = DECL_CONTEXT (decl);
4072 context = TYPE_MAIN_VARIANT
4073 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4075 if (context && !TYPE_P (context))
4076 context = NULL_TREE;
4081 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4082 addition order, and correct that in add_sibling_attributes. */
4085 add_dwarf_attr (die, attr)
4086 register dw_die_ref die;
4087 register dw_attr_ref attr;
4089 if (die != NULL && attr != NULL)
4091 attr->dw_attr_next = die->die_attr;
4092 die->die_attr = attr;
4096 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4097 static inline dw_val_class
4101 return a->dw_attr_val.val_class;
4104 /* Add a flag value attribute to a DIE. */
4107 add_AT_flag (die, attr_kind, flag)
4108 register dw_die_ref die;
4109 register enum dwarf_attribute attr_kind;
4110 register unsigned flag;
4112 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4114 attr->dw_attr_next = NULL;
4115 attr->dw_attr = attr_kind;
4116 attr->dw_attr_val.val_class = dw_val_class_flag;
4117 attr->dw_attr_val.v.val_flag = flag;
4118 add_dwarf_attr (die, attr);
4121 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4122 static inline unsigned
4124 register dw_attr_ref a;
4126 if (a && AT_class (a) == dw_val_class_flag)
4127 return a->dw_attr_val.v.val_flag;
4132 /* Add a signed integer attribute value to a DIE. */
4135 add_AT_int (die, attr_kind, int_val)
4136 register dw_die_ref die;
4137 register enum dwarf_attribute attr_kind;
4138 register long int int_val;
4140 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4142 attr->dw_attr_next = NULL;
4143 attr->dw_attr = attr_kind;
4144 attr->dw_attr_val.val_class = dw_val_class_const;
4145 attr->dw_attr_val.v.val_int = int_val;
4146 add_dwarf_attr (die, attr);
4149 static inline long int AT_int PARAMS ((dw_attr_ref));
4150 static inline long int
4152 register dw_attr_ref a;
4154 if (a && AT_class (a) == dw_val_class_const)
4155 return a->dw_attr_val.v.val_int;
4160 /* Add an unsigned integer attribute value to a DIE. */
4163 add_AT_unsigned (die, attr_kind, unsigned_val)
4164 register dw_die_ref die;
4165 register enum dwarf_attribute attr_kind;
4166 register unsigned long unsigned_val;
4168 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4170 attr->dw_attr_next = NULL;
4171 attr->dw_attr = attr_kind;
4172 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4173 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4174 add_dwarf_attr (die, attr);
4177 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4178 static inline unsigned long
4180 register dw_attr_ref a;
4182 if (a && AT_class (a) == dw_val_class_unsigned_const)
4183 return a->dw_attr_val.v.val_unsigned;
4188 /* Add an unsigned double integer attribute value to a DIE. */
4191 add_AT_long_long (die, attr_kind, val_hi, val_low)
4192 register dw_die_ref die;
4193 register enum dwarf_attribute attr_kind;
4194 register unsigned long val_hi;
4195 register unsigned long val_low;
4197 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4199 attr->dw_attr_next = NULL;
4200 attr->dw_attr = attr_kind;
4201 attr->dw_attr_val.val_class = dw_val_class_long_long;
4202 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4203 attr->dw_attr_val.v.val_long_long.low = val_low;
4204 add_dwarf_attr (die, attr);
4207 /* Add a floating point attribute value to a DIE and return it. */
4210 add_AT_float (die, attr_kind, length, array)
4211 register dw_die_ref die;
4212 register enum dwarf_attribute attr_kind;
4213 register unsigned length;
4214 register long *array;
4216 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4218 attr->dw_attr_next = NULL;
4219 attr->dw_attr = attr_kind;
4220 attr->dw_attr_val.val_class = dw_val_class_float;
4221 attr->dw_attr_val.v.val_float.length = length;
4222 attr->dw_attr_val.v.val_float.array = array;
4223 add_dwarf_attr (die, attr);
4226 /* Add a string attribute value to a DIE. */
4229 add_AT_string (die, attr_kind, str)
4230 register dw_die_ref die;
4231 register enum dwarf_attribute attr_kind;
4232 register const char *str;
4234 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4236 attr->dw_attr_next = NULL;
4237 attr->dw_attr = attr_kind;
4238 attr->dw_attr_val.val_class = dw_val_class_str;
4239 attr->dw_attr_val.v.val_str = xstrdup (str);
4240 add_dwarf_attr (die, attr);
4243 static inline const char *AT_string PARAMS ((dw_attr_ref));
4244 static inline const char *
4246 register dw_attr_ref a;
4248 if (a && AT_class (a) == dw_val_class_str)
4249 return a->dw_attr_val.v.val_str;
4254 /* Add a DIE reference attribute value to a DIE. */
4257 add_AT_die_ref (die, attr_kind, targ_die)
4258 register dw_die_ref die;
4259 register enum dwarf_attribute attr_kind;
4260 register dw_die_ref targ_die;
4262 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4264 attr->dw_attr_next = NULL;
4265 attr->dw_attr = attr_kind;
4266 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4267 attr->dw_attr_val.v.val_die_ref = targ_die;
4268 add_dwarf_attr (die, attr);
4271 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4272 static inline dw_die_ref
4274 register dw_attr_ref a;
4276 if (a && AT_class (a) == dw_val_class_die_ref)
4277 return a->dw_attr_val.v.val_die_ref;
4282 /* Add an FDE reference attribute value to a DIE. */
4285 add_AT_fde_ref (die, attr_kind, targ_fde)
4286 register dw_die_ref die;
4287 register enum dwarf_attribute attr_kind;
4288 register unsigned targ_fde;
4290 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4292 attr->dw_attr_next = NULL;
4293 attr->dw_attr = attr_kind;
4294 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4295 attr->dw_attr_val.v.val_fde_index = targ_fde;
4296 add_dwarf_attr (die, attr);
4299 /* Add a location description attribute value to a DIE. */
4302 add_AT_loc (die, attr_kind, loc)
4303 register dw_die_ref die;
4304 register enum dwarf_attribute attr_kind;
4305 register dw_loc_descr_ref loc;
4307 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4309 attr->dw_attr_next = NULL;
4310 attr->dw_attr = attr_kind;
4311 attr->dw_attr_val.val_class = dw_val_class_loc;
4312 attr->dw_attr_val.v.val_loc = loc;
4313 add_dwarf_attr (die, attr);
4316 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4317 static inline dw_loc_descr_ref
4319 register dw_attr_ref a;
4321 if (a && AT_class (a) == dw_val_class_loc)
4322 return a->dw_attr_val.v.val_loc;
4327 /* Add an address constant attribute value to a DIE. */
4330 add_AT_addr (die, attr_kind, addr)
4331 register dw_die_ref die;
4332 register enum dwarf_attribute attr_kind;
4335 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4337 attr->dw_attr_next = NULL;
4338 attr->dw_attr = attr_kind;
4339 attr->dw_attr_val.val_class = dw_val_class_addr;
4340 attr->dw_attr_val.v.val_addr = addr;
4341 add_dwarf_attr (die, attr);
4344 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4347 register dw_attr_ref a;
4349 if (a && AT_class (a) == dw_val_class_addr)
4350 return a->dw_attr_val.v.val_addr;
4355 /* Add a label identifier attribute value to a DIE. */
4358 add_AT_lbl_id (die, attr_kind, lbl_id)
4359 register dw_die_ref die;
4360 register enum dwarf_attribute attr_kind;
4361 register const char *lbl_id;
4363 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4365 attr->dw_attr_next = NULL;
4366 attr->dw_attr = attr_kind;
4367 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4368 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4369 add_dwarf_attr (die, attr);
4372 /* Add a section offset attribute value to a DIE. */
4375 add_AT_lbl_offset (die, attr_kind, label)
4376 register dw_die_ref die;
4377 register enum dwarf_attribute attr_kind;
4378 register const char *label;
4380 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4382 attr->dw_attr_next = NULL;
4383 attr->dw_attr = attr_kind;
4384 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4385 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4386 add_dwarf_attr (die, attr);
4390 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4391 static inline const char *
4393 register dw_attr_ref a;
4395 if (a && (AT_class (a) == dw_val_class_lbl_id
4396 || AT_class (a) == dw_val_class_lbl_offset))
4397 return a->dw_attr_val.v.val_lbl_id;
4402 /* Get the attribute of type attr_kind. */
4404 static inline dw_attr_ref
4405 get_AT (die, attr_kind)
4406 register dw_die_ref die;
4407 register enum dwarf_attribute attr_kind;
4409 register dw_attr_ref a;
4410 register dw_die_ref spec = NULL;
4414 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4416 if (a->dw_attr == attr_kind)
4419 if (a->dw_attr == DW_AT_specification
4420 || a->dw_attr == DW_AT_abstract_origin)
4425 return get_AT (spec, attr_kind);
4431 /* Return the "low pc" attribute value, typically associated with
4432 a subprogram DIE. Return null if the "low pc" attribute is
4433 either not prsent, or if it cannot be represented as an
4434 assembler label identifier. */
4436 static inline const char *
4438 register dw_die_ref die;
4440 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4444 /* Return the "high pc" attribute value, typically associated with
4445 a subprogram DIE. Return null if the "high pc" attribute is
4446 either not prsent, or if it cannot be represented as an
4447 assembler label identifier. */
4449 static inline const char *
4451 register dw_die_ref die;
4453 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4457 /* Return the value of the string attribute designated by ATTR_KIND, or
4458 NULL if it is not present. */
4460 static inline const char *
4461 get_AT_string (die, attr_kind)
4462 register dw_die_ref die;
4463 register enum dwarf_attribute attr_kind;
4465 register dw_attr_ref a = get_AT (die, attr_kind);
4466 return AT_string (a);
4469 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4470 if it is not present. */
4473 get_AT_flag (die, attr_kind)
4474 register dw_die_ref die;
4475 register enum dwarf_attribute attr_kind;
4477 register dw_attr_ref a = get_AT (die, attr_kind);
4481 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4482 if it is not present. */
4484 static inline unsigned
4485 get_AT_unsigned (die, attr_kind)
4486 register dw_die_ref die;
4487 register enum dwarf_attribute attr_kind;
4489 register dw_attr_ref a = get_AT (die, attr_kind);
4490 return AT_unsigned (a);
4493 static inline dw_die_ref
4494 get_AT_ref (die, attr_kind)
4496 register enum dwarf_attribute attr_kind;
4498 register dw_attr_ref a = get_AT (die, attr_kind);
4505 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4507 return (lang == DW_LANG_C || lang == DW_LANG_C89
4508 || lang == DW_LANG_C_plus_plus);
4514 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4516 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4519 /* Free up the memory used by A. */
4521 static inline void free_AT PARAMS ((dw_attr_ref));
4526 switch (AT_class (a))
4528 case dw_val_class_str:
4529 case dw_val_class_lbl_id:
4530 case dw_val_class_lbl_offset:
4531 free (a->dw_attr_val.v.val_str);
4541 /* Remove the specified attribute if present. */
4544 remove_AT (die, attr_kind)
4545 register dw_die_ref die;
4546 register enum dwarf_attribute attr_kind;
4548 register dw_attr_ref *p;
4549 register dw_attr_ref removed = NULL;
4553 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4554 if ((*p)->dw_attr == attr_kind)
4557 *p = (*p)->dw_attr_next;
4566 /* Free up the memory used by DIE. */
4568 static inline void free_die PARAMS ((dw_die_ref));
4573 remove_children (die);
4577 /* Discard the children of this DIE. */
4580 remove_children (die)
4581 register dw_die_ref die;
4583 register dw_die_ref child_die = die->die_child;
4585 die->die_child = NULL;
4587 while (child_die != NULL)
4589 register dw_die_ref tmp_die = child_die;
4590 register dw_attr_ref a;
4592 child_die = child_die->die_sib;
4594 for (a = tmp_die->die_attr; a != NULL; )
4596 register dw_attr_ref tmp_a = a;
4598 a = a->dw_attr_next;
4606 /* Add a child DIE below its parent. We build the lists up in reverse
4607 addition order, and correct that in add_sibling_attributes. */
4610 add_child_die (die, child_die)
4611 register dw_die_ref die;
4612 register dw_die_ref child_die;
4614 if (die != NULL && child_die != NULL)
4616 if (die == child_die)
4618 child_die->die_parent = die;
4619 child_die->die_sib = die->die_child;
4620 die->die_child = child_die;
4624 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4625 is the specification, to the front of PARENT's list of children. */
4628 splice_child_die (parent, child)
4629 dw_die_ref parent, child;
4633 /* We want the declaration DIE from inside the class, not the
4634 specification DIE at toplevel. */
4635 if (child->die_parent != parent)
4637 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4642 if (child->die_parent != parent
4643 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4646 for (p = &(parent->die_child); *p; p = &((*p)->die_sib))
4649 *p = child->die_sib;
4653 child->die_sib = parent->die_child;
4654 parent->die_child = child;
4657 /* Return a pointer to a newly created DIE node. */
4659 static inline dw_die_ref
4660 new_die (tag_value, parent_die)
4661 register enum dwarf_tag tag_value;
4662 register dw_die_ref parent_die;
4664 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4666 die->die_tag = tag_value;
4667 die->die_abbrev = 0;
4668 die->die_offset = 0;
4669 die->die_child = NULL;
4670 die->die_parent = NULL;
4671 die->die_sib = NULL;
4672 die->die_attr = NULL;
4674 if (parent_die != NULL)
4675 add_child_die (parent_die, die);
4678 limbo_die_node *limbo_node;
4680 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4681 limbo_node->die = die;
4682 limbo_node->next = limbo_die_list;
4683 limbo_die_list = limbo_node;
4689 /* Return the DIE associated with the given type specifier. */
4691 static inline dw_die_ref
4692 lookup_type_die (type)
4695 if (TREE_CODE (type) == VECTOR_TYPE)
4696 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4697 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4700 /* Equate a DIE to a given type specifier. */
4703 equate_type_number_to_die (type, type_die)
4705 register dw_die_ref type_die;
4707 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4710 /* Return the DIE associated with a given declaration. */
4712 static inline dw_die_ref
4713 lookup_decl_die (decl)
4716 register unsigned decl_id = DECL_UID (decl);
4718 return (decl_id < decl_die_table_in_use
4719 ? decl_die_table[decl_id] : NULL);
4722 /* Equate a DIE to a particular declaration. */
4725 equate_decl_number_to_die (decl, decl_die)
4727 register dw_die_ref decl_die;
4729 register unsigned decl_id = DECL_UID (decl);
4730 register unsigned num_allocated;
4732 if (decl_id >= decl_die_table_allocated)
4735 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4736 / DECL_DIE_TABLE_INCREMENT)
4737 * DECL_DIE_TABLE_INCREMENT;
4740 = (dw_die_ref *) xrealloc (decl_die_table,
4741 sizeof (dw_die_ref) * num_allocated);
4743 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4744 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4745 decl_die_table_allocated = num_allocated;
4748 if (decl_id >= decl_die_table_in_use)
4749 decl_die_table_in_use = (decl_id + 1);
4751 decl_die_table[decl_id] = decl_die;
4754 /* Keep track of the number of spaces used to indent the
4755 output of the debugging routines that print the structure of
4756 the DIE internal representation. */
4757 static int print_indent;
4759 /* Indent the line the number of spaces given by print_indent. */
4762 print_spaces (outfile)
4765 fprintf (outfile, "%*s", print_indent, "");
4768 /* Print the information associated with a given DIE, and its children.
4769 This routine is a debugging aid only. */
4772 print_die (die, outfile)
4776 register dw_attr_ref a;
4777 register dw_die_ref c;
4779 print_spaces (outfile);
4780 fprintf (outfile, "DIE %4lu: %s\n",
4781 die->die_offset, dwarf_tag_name (die->die_tag));
4782 print_spaces (outfile);
4783 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4784 fprintf (outfile, " offset: %lu\n", die->die_offset);
4786 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4788 print_spaces (outfile);
4789 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4791 switch (AT_class (a))
4793 case dw_val_class_addr:
4794 fprintf (outfile, "address");
4796 case dw_val_class_loc:
4797 fprintf (outfile, "location descriptor");
4799 case dw_val_class_const:
4800 fprintf (outfile, "%ld", AT_int (a));
4802 case dw_val_class_unsigned_const:
4803 fprintf (outfile, "%lu", AT_unsigned (a));
4805 case dw_val_class_long_long:
4806 fprintf (outfile, "constant (%lu,%lu)",
4807 a->dw_attr_val.v.val_long_long.hi,
4808 a->dw_attr_val.v.val_long_long.low);
4810 case dw_val_class_float:
4811 fprintf (outfile, "floating-point constant");
4813 case dw_val_class_flag:
4814 fprintf (outfile, "%u", AT_flag (a));
4816 case dw_val_class_die_ref:
4817 if (AT_ref (a) != NULL)
4818 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4820 fprintf (outfile, "die -> <null>");
4822 case dw_val_class_lbl_id:
4823 case dw_val_class_lbl_offset:
4824 fprintf (outfile, "label: %s", AT_lbl (a));
4826 case dw_val_class_str:
4827 if (AT_string (a) != NULL)
4828 fprintf (outfile, "\"%s\"", AT_string (a));
4830 fprintf (outfile, "<null>");
4836 fprintf (outfile, "\n");
4839 if (die->die_child != NULL)
4842 for (c = die->die_child; c != NULL; c = c->die_sib)
4843 print_die (c, outfile);
4849 /* Print the contents of the source code line number correspondence table.
4850 This routine is a debugging aid only. */
4853 print_dwarf_line_table (outfile)
4856 register unsigned i;
4857 register dw_line_info_ref line_info;
4859 fprintf (outfile, "\n\nDWARF source line information\n");
4860 for (i = 1; i < line_info_table_in_use; ++i)
4862 line_info = &line_info_table[i];
4863 fprintf (outfile, "%5d: ", i);
4864 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4865 fprintf (outfile, "%6ld", line_info->dw_line_num);
4866 fprintf (outfile, "\n");
4869 fprintf (outfile, "\n\n");
4872 /* Print the information collected for a given DIE. */
4875 debug_dwarf_die (die)
4878 print_die (die, stderr);
4881 /* Print all DWARF information collected for the compilation unit.
4882 This routine is a debugging aid only. */
4888 print_die (comp_unit_die, stderr);
4889 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4890 print_dwarf_line_table (stderr);
4893 /* We build up the lists of children and attributes by pushing new ones
4894 onto the beginning of the list. Reverse the lists for DIE so that
4895 they are in order of addition. */
4898 reverse_die_lists (die)
4899 register dw_die_ref die;
4901 register dw_die_ref c, cp, cn;
4902 register dw_attr_ref a, ap, an;
4904 for (a = die->die_attr, ap = 0; a; a = an)
4906 an = a->dw_attr_next;
4907 a->dw_attr_next = ap;
4912 for (c = die->die_child, cp = 0; c; c = cn)
4918 die->die_child = cp;
4921 /* Traverse the DIE, reverse its lists of attributes and children, and
4922 add a sibling attribute if it may have the effect of speeding up
4923 access to siblings. To save some space, avoid generating sibling
4924 attributes for DIE's without children. */
4927 add_sibling_attributes (die)
4928 register dw_die_ref die;
4930 register dw_die_ref c;
4932 reverse_die_lists (die);
4934 if (die != comp_unit_die && die->die_sib && die->die_child != NULL)
4935 /* Add the sibling link to the front of the attribute list. */
4936 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
4938 for (c = die->die_child; c != NULL; c = c->die_sib)
4939 add_sibling_attributes (c);
4942 /* The format of each DIE (and its attribute value pairs)
4943 is encoded in an abbreviation table. This routine builds the
4944 abbreviation table and assigns a unique abbreviation id for
4945 each abbreviation entry. The children of each die are visited
4949 build_abbrev_table (die)
4950 register dw_die_ref die;
4952 register unsigned long abbrev_id;
4953 register unsigned long n_alloc;
4954 register dw_die_ref c;
4955 register dw_attr_ref d_attr, a_attr;
4956 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4958 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4960 if (abbrev->die_tag == die->die_tag)
4962 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
4964 a_attr = abbrev->die_attr;
4965 d_attr = die->die_attr;
4967 while (a_attr != NULL && d_attr != NULL)
4969 if ((a_attr->dw_attr != d_attr->dw_attr)
4970 || (value_format (a_attr) != value_format (d_attr)))
4973 a_attr = a_attr->dw_attr_next;
4974 d_attr = d_attr->dw_attr_next;
4977 if (a_attr == NULL && d_attr == NULL)
4983 if (abbrev_id >= abbrev_die_table_in_use)
4985 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
4987 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
4989 = (dw_die_ref *) xrealloc (abbrev_die_table,
4990 sizeof (dw_die_ref) * n_alloc);
4992 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
4993 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
4994 abbrev_die_table_allocated = n_alloc;
4997 ++abbrev_die_table_in_use;
4998 abbrev_die_table[abbrev_id] = die;
5001 die->die_abbrev = abbrev_id;
5002 for (c = die->die_child; c != NULL; c = c->die_sib)
5003 build_abbrev_table (c);
5006 /* Return the size of a string, including the null byte.
5008 This used to treat backslashes as escapes, and hence they were not included
5009 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5010 which treats a backslash as a backslash, escaping it if necessary, and hence
5011 we must include them in the count. */
5013 static unsigned long
5014 size_of_string (str)
5015 register const char *str;
5017 return strlen (str) + 1;
5020 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5023 constant_size (value)
5024 long unsigned value;
5031 log = floor_log2 (value);
5034 log = 1 << (floor_log2 (log) + 1);
5039 /* Return the size of a DIE, as it is represented in the
5040 .debug_info section. */
5042 static unsigned long
5044 register dw_die_ref die;
5046 register unsigned long size = 0;
5047 register dw_attr_ref a;
5049 size += size_of_uleb128 (die->die_abbrev);
5050 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5052 switch (AT_class (a))
5054 case dw_val_class_addr:
5055 size += DWARF2_ADDR_SIZE;
5057 case dw_val_class_loc:
5059 register unsigned long lsize = size_of_locs (AT_loc (a));
5062 size += constant_size (lsize);
5066 case dw_val_class_const:
5067 size += size_of_sleb128 (AT_int (a));
5069 case dw_val_class_unsigned_const:
5070 size += constant_size (AT_unsigned (a));
5072 case dw_val_class_long_long:
5073 size += 1 + 8; /* block */
5075 case dw_val_class_float:
5076 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5078 case dw_val_class_flag:
5081 case dw_val_class_die_ref:
5082 size += DWARF_OFFSET_SIZE;
5084 case dw_val_class_fde_ref:
5085 size += DWARF_OFFSET_SIZE;
5087 case dw_val_class_lbl_id:
5088 size += DWARF2_ADDR_SIZE;
5090 case dw_val_class_lbl_offset:
5091 size += DWARF_OFFSET_SIZE;
5093 case dw_val_class_str:
5094 size += size_of_string (AT_string (a));
5104 /* Size the debugging information associated with a given DIE.
5105 Visits the DIE's children recursively. Updates the global
5106 variable next_die_offset, on each time through. Uses the
5107 current value of next_die_offset to update the die_offset
5108 field in each DIE. */
5111 calc_die_sizes (die)
5114 register dw_die_ref c;
5115 die->die_offset = next_die_offset;
5116 next_die_offset += size_of_die (die);
5118 for (c = die->die_child; c != NULL; c = c->die_sib)
5121 if (die->die_child != NULL)
5122 /* Count the null byte used to terminate sibling lists. */
5123 next_die_offset += 1;
5126 /* Return the size of the line information prolog generated for the
5127 compilation unit. */
5129 static unsigned long
5130 size_of_line_prolog ()
5132 register unsigned long size;
5133 register unsigned long ft_index;
5135 size = DWARF_LINE_PROLOG_HEADER_SIZE;
5137 /* Count the size of the table giving number of args for each
5139 size += DWARF_LINE_OPCODE_BASE - 1;
5141 /* Include directory table is empty (at present). Count only the
5142 null byte used to terminate the table. */
5145 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5147 /* File name entry. */
5148 size += size_of_string (file_table[ft_index]);
5150 /* Include directory index. */
5151 size += size_of_uleb128 (0);
5153 /* Modification time. */
5154 size += size_of_uleb128 (0);
5156 /* File length in bytes. */
5157 size += size_of_uleb128 (0);
5160 /* Count the file table terminator. */
5165 /* Return the size of the .debug_pubnames table generated for the
5166 compilation unit. */
5168 static unsigned long
5171 register unsigned long size;
5172 register unsigned i;
5174 size = DWARF_PUBNAMES_HEADER_SIZE;
5175 for (i = 0; i < pubname_table_in_use; ++i)
5177 register pubname_ref p = &pubname_table[i];
5178 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5181 size += DWARF_OFFSET_SIZE;
5185 /* Return the size of the information in the .debug_aranges section. */
5187 static unsigned long
5190 register unsigned long size;
5192 size = DWARF_ARANGES_HEADER_SIZE;
5194 /* Count the address/length pair for this compilation unit. */
5195 size += 2 * DWARF2_ADDR_SIZE;
5196 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5198 /* Count the two zero words used to terminated the address range table. */
5199 size += 2 * DWARF2_ADDR_SIZE;
5203 /* Select the encoding of an attribute value. */
5205 static enum dwarf_form
5209 switch (a->dw_attr_val.val_class)
5211 case dw_val_class_addr:
5212 return DW_FORM_addr;
5213 case dw_val_class_loc:
5214 switch (constant_size (size_of_locs (AT_loc (a))))
5217 return DW_FORM_block1;
5219 return DW_FORM_block2;
5223 case dw_val_class_const:
5224 return DW_FORM_sdata;
5225 case dw_val_class_unsigned_const:
5226 switch (constant_size (AT_unsigned (a)))
5229 return DW_FORM_data1;
5231 return DW_FORM_data2;
5233 return DW_FORM_data4;
5235 return DW_FORM_data8;
5239 case dw_val_class_long_long:
5240 return DW_FORM_block1;
5241 case dw_val_class_float:
5242 return DW_FORM_block1;
5243 case dw_val_class_flag:
5244 return DW_FORM_flag;
5245 case dw_val_class_die_ref:
5247 case dw_val_class_fde_ref:
5248 return DW_FORM_data;
5249 case dw_val_class_lbl_id:
5250 return DW_FORM_addr;
5251 case dw_val_class_lbl_offset:
5252 return DW_FORM_data;
5253 case dw_val_class_str:
5254 return DW_FORM_string;
5260 /* Output the encoding of an attribute value. */
5263 output_value_format (a)
5266 enum dwarf_form form = value_format (a);
5268 output_uleb128 (form);
5270 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
5272 fputc ('\n', asm_out_file);
5275 /* Output the .debug_abbrev section which defines the DIE abbreviation
5279 output_abbrev_section ()
5281 unsigned long abbrev_id;
5284 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5286 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5288 output_uleb128 (abbrev_id);
5290 fprintf (asm_out_file, " (abbrev code)");
5292 fputc ('\n', asm_out_file);
5293 output_uleb128 (abbrev->die_tag);
5295 fprintf (asm_out_file, " (TAG: %s)",
5296 dwarf_tag_name (abbrev->die_tag));
5298 fputc ('\n', asm_out_file);
5299 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
5300 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
5303 fprintf (asm_out_file, "\t%s %s",
5305 (abbrev->die_child != NULL
5306 ? "DW_children_yes" : "DW_children_no"));
5308 fputc ('\n', asm_out_file);
5310 for (a_attr = abbrev->die_attr; a_attr != NULL;
5311 a_attr = a_attr->dw_attr_next)
5313 output_uleb128 (a_attr->dw_attr);
5315 fprintf (asm_out_file, " (%s)",
5316 dwarf_attr_name (a_attr->dw_attr));
5318 fputc ('\n', asm_out_file);
5319 output_value_format (a_attr);
5322 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
5325 /* Terminate the table. */
5326 fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP);
5329 /* Output the DIE and its attributes. Called recursively to generate
5330 the definitions of each child DIE. */
5334 register dw_die_ref die;
5336 register dw_attr_ref a;
5337 register dw_die_ref c;
5338 register unsigned long size;
5340 output_uleb128 (die->die_abbrev);
5342 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5343 die->die_offset, dwarf_tag_name (die->die_tag));
5345 fputc ('\n', asm_out_file);
5347 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5349 switch (AT_class (a))
5351 case dw_val_class_addr:
5352 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
5355 case dw_val_class_loc:
5356 size = size_of_locs (AT_loc (a));
5358 /* Output the block length for this list of location operations. */
5359 switch (constant_size (size))
5362 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5365 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5372 fprintf (asm_out_file, "\t%s %s",
5373 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5375 fputc ('\n', asm_out_file);
5377 output_loc_sequence (AT_loc (a));
5380 case dw_val_class_const:
5381 /* ??? It would be slightly more efficient to use a scheme like is
5382 used for unsigned constants below, but gdb 4.x does not sign
5383 extend. Gdb 5.x does sign extend. */
5384 output_sleb128 (AT_int (a));
5387 case dw_val_class_unsigned_const:
5388 switch (constant_size (AT_unsigned (a)))
5391 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
5394 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
5397 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
5400 ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a));
5407 case dw_val_class_long_long:
5408 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5410 fprintf (asm_out_file, "\t%s %s",
5411 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5413 fputc ('\n', asm_out_file);
5414 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file,
5415 a->dw_attr_val.v.val_long_long.hi,
5416 a->dw_attr_val.v.val_long_long.low);
5419 fprintf (asm_out_file,
5420 "\t%s long long constant", ASM_COMMENT_START);
5422 fputc ('\n', asm_out_file);
5425 case dw_val_class_float:
5427 register unsigned int i;
5428 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5429 a->dw_attr_val.v.val_float.length * 4);
5431 fprintf (asm_out_file, "\t%s %s",
5432 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5434 fputc ('\n', asm_out_file);
5435 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5437 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5438 a->dw_attr_val.v.val_float.array[i]);
5440 fprintf (asm_out_file, "\t%s fp constant word %u",
5441 ASM_COMMENT_START, i);
5443 fputc ('\n', asm_out_file);
5448 case dw_val_class_flag:
5449 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
5452 case dw_val_class_die_ref:
5453 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
5456 case dw_val_class_fde_ref:
5459 ASM_GENERATE_INTERNAL_LABEL
5460 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5461 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5462 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5466 case dw_val_class_lbl_id:
5467 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
5470 case dw_val_class_lbl_offset:
5471 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
5474 case dw_val_class_str:
5476 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
5478 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
5479 (int) strlen (AT_string (a)) + 1);
5486 if (AT_class (a) != dw_val_class_loc
5487 && AT_class (a) != dw_val_class_long_long
5488 && AT_class (a) != dw_val_class_float)
5491 fprintf (asm_out_file, "\t%s %s",
5492 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5494 fputc ('\n', asm_out_file);
5498 for (c = die->die_child; c != NULL; c = c->die_sib)
5501 if (die->die_child != NULL)
5503 /* Add null byte to terminate sibling list. */
5504 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5506 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
5507 ASM_COMMENT_START, die->die_offset);
5509 fputc ('\n', asm_out_file);
5513 /* Output the compilation unit that appears at the beginning of the
5514 .debug_info section, and precedes the DIE descriptions. */
5517 output_compilation_unit_header ()
5519 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
5521 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
5524 fputc ('\n', asm_out_file);
5525 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5527 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
5529 fputc ('\n', asm_out_file);
5530 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
5532 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
5535 fputc ('\n', asm_out_file);
5536 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
5538 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
5540 fputc ('\n', asm_out_file);
5543 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5544 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5545 argument list, and maybe the scope. */
5548 dwarf2_name (decl, scope)
5552 return (*decl_printable_name) (decl, scope ? 1 : 0);
5555 /* Add a new entry to .debug_pubnames if appropriate. */
5558 add_pubname (decl, die)
5564 if (! TREE_PUBLIC (decl))
5567 if (pubname_table_in_use == pubname_table_allocated)
5569 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5570 pubname_table = (pubname_ref) xrealloc
5571 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5574 p = &pubname_table[pubname_table_in_use++];
5577 p->name = xstrdup (dwarf2_name (decl, 1));
5580 /* Output the public names table used to speed up access to externally
5581 visible names. For now, only generate entries for externally
5582 visible procedures. */
5587 register unsigned i;
5588 register unsigned long pubnames_length = size_of_pubnames ();
5590 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
5593 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
5596 fputc ('\n', asm_out_file);
5597 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5600 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5602 fputc ('\n', asm_out_file);
5603 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5605 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5608 fputc ('\n', asm_out_file);
5609 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
5611 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
5613 fputc ('\n', asm_out_file);
5614 for (i = 0; i < pubname_table_in_use; ++i)
5616 register pubname_ref pub = &pubname_table[i];
5618 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
5620 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
5622 fputc ('\n', asm_out_file);
5626 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
5627 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
5631 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
5632 (int) strlen (pub->name) + 1);
5635 fputc ('\n', asm_out_file);
5638 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
5639 fputc ('\n', asm_out_file);
5642 /* Add a new entry to .debug_aranges if appropriate. */
5645 add_arange (decl, die)
5649 if (! DECL_SECTION_NAME (decl))
5652 if (arange_table_in_use == arange_table_allocated)
5654 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5656 = (arange_ref) xrealloc (arange_table,
5657 arange_table_allocated * sizeof (dw_die_ref));
5660 arange_table[arange_table_in_use++] = die;
5663 /* Output the information that goes into the .debug_aranges table.
5664 Namely, define the beginning and ending address range of the
5665 text section generated for this compilation unit. */
5670 register unsigned i;
5671 register unsigned long aranges_length = size_of_aranges ();
5673 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
5675 fprintf (asm_out_file, "\t%s Length of Address Ranges 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_OFFSET (asm_out_file, debug_info_section_label);
5686 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5689 fputc ('\n', asm_out_file);
5690 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
5692 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
5694 fputc ('\n', asm_out_file);
5695 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5697 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
5700 fputc ('\n', asm_out_file);
5702 /* We need to align to twice the pointer size here. */
5703 if (DWARF_ARANGES_PAD_SIZE)
5705 /* Pad using a 2 bytes word so that padding is correct
5706 for any pointer size. */
5707 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
5708 for (i = 2; i < DWARF_ARANGES_PAD_SIZE; i += 2)
5709 fprintf (asm_out_file, ",0");
5711 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5712 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
5715 fputc ('\n', asm_out_file);
5716 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
5718 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5720 fputc ('\n', asm_out_file);
5721 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
5722 text_section_label);
5724 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5726 fputc ('\n', asm_out_file);
5727 for (i = 0; i < arange_table_in_use; ++i)
5729 dw_die_ref die = arange_table[i];
5731 if (die->die_tag == DW_TAG_subprogram)
5732 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
5735 /* A static variable; extract the symbol from DW_AT_location.
5736 Note that this code isn't currently hit, as we only emit
5737 aranges for functions (jason 9/23/99). */
5739 dw_attr_ref a = get_AT (die, DW_AT_location);
5740 dw_loc_descr_ref loc;
5741 if (! a || AT_class (a) != dw_val_class_loc)
5745 if (loc->dw_loc_opc != DW_OP_addr)
5748 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
5749 loc->dw_loc_oprnd1.v.val_addr);
5753 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5755 fputc ('\n', asm_out_file);
5756 if (die->die_tag == DW_TAG_subprogram)
5757 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
5758 get_AT_low_pc (die));
5760 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5761 get_AT_unsigned (die, DW_AT_byte_size));
5764 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5766 fputc ('\n', asm_out_file);
5769 /* Output the terminator words. */
5770 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5771 fputc ('\n', asm_out_file);
5772 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5773 fputc ('\n', asm_out_file);
5776 /* Output the source line number correspondence information. This
5777 information goes into the .debug_line section. */
5782 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5783 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5784 register unsigned opc;
5785 register unsigned n_op_args;
5786 register unsigned long ft_index;
5787 register unsigned long lt_index;
5788 register unsigned long current_line;
5789 register long line_offset;
5790 register long line_delta;
5791 register unsigned long current_file;
5792 register unsigned long function;
5794 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
5796 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5799 fputc ('\n', asm_out_file);
5800 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
5801 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5803 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5805 fputc ('\n', asm_out_file);
5806 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
5808 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5810 fputc ('\n', asm_out_file);
5811 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
5813 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5816 fputc ('\n', asm_out_file);
5817 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
5819 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5822 fputc ('\n', asm_out_file);
5823 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
5825 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5828 fputc ('\n', asm_out_file);
5829 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
5831 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5834 fputc ('\n', asm_out_file);
5835 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5837 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5839 fputc ('\n', asm_out_file);
5840 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5844 case DW_LNS_advance_pc:
5845 case DW_LNS_advance_line:
5846 case DW_LNS_set_file:
5847 case DW_LNS_set_column:
5848 case DW_LNS_fixed_advance_pc:
5855 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5857 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5858 ASM_COMMENT_START, opc, n_op_args);
5859 fputc ('\n', asm_out_file);
5863 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5865 /* Include directory table is empty, at present */
5866 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5867 fputc ('\n', asm_out_file);
5869 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5871 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5875 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5876 fprintf (asm_out_file, "%s File Entry: 0x%lx",
5877 ASM_COMMENT_START, ft_index);
5881 ASM_OUTPUT_ASCII (asm_out_file,
5882 file_table[ft_index],
5883 (int) strlen (file_table[ft_index]) + 1);
5886 fputc ('\n', asm_out_file);
5888 /* Include directory index */
5890 fputc ('\n', asm_out_file);
5892 /* Modification time */
5894 fputc ('\n', asm_out_file);
5896 /* File length in bytes */
5898 fputc ('\n', asm_out_file);
5901 /* Terminate the file name table */
5902 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5903 fputc ('\n', asm_out_file);
5905 /* We used to set the address register to the first location in the text
5906 section here, but that didn't accomplish anything since we already
5907 have a line note for the opening brace of the first function. */
5909 /* Generate the line number to PC correspondence table, encoded as
5910 a series of state machine operations. */
5913 strcpy (prev_line_label, text_section_label);
5914 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5916 register dw_line_info_ref line_info = &line_info_table[lt_index];
5919 /* Disable this optimization for now; GDB wants to see two line notes
5920 at the beginning of a function so it can find the end of the
5923 /* Don't emit anything for redundant notes. Just updating the
5924 address doesn't accomplish anything, because we already assume
5925 that anything after the last address is this line. */
5926 if (line_info->dw_line_num == current_line
5927 && line_info->dw_file_num == current_file)
5931 /* Emit debug info for the address of the current line, choosing
5932 the encoding that uses the least amount of space. */
5933 /* ??? Unfortunately, we have little choice here currently, and must
5934 always use the most general form. Gcc does not know the address
5935 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5936 dwarf2 aware assemblers at this time, so we can't use any special
5937 pseudo ops that would allow the assembler to optimally encode this for
5938 us. Many ports do have length attributes which will give an upper
5939 bound on the address range. We could perhaps use length attributes
5940 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5941 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5944 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5945 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5947 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5950 fputc ('\n', asm_out_file);
5951 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5952 fputc ('\n', asm_out_file);
5956 /* This can handle any delta. This takes
5957 4+DWARF2_ADDR_SIZE bytes. */
5958 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5960 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5962 fputc ('\n', asm_out_file);
5963 output_uleb128 (1 + DWARF2_ADDR_SIZE);
5964 fputc ('\n', asm_out_file);
5965 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5966 fputc ('\n', asm_out_file);
5967 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5968 fputc ('\n', asm_out_file);
5970 strcpy (prev_line_label, line_label);
5972 /* Emit debug info for the source file of the current line, if
5973 different from the previous line. */
5974 if (line_info->dw_file_num != current_file)
5976 current_file = line_info->dw_file_num;
5977 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5979 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5981 fputc ('\n', asm_out_file);
5982 output_uleb128 (current_file);
5984 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5986 fputc ('\n', asm_out_file);
5989 /* Emit debug info for the current line number, choosing the encoding
5990 that uses the least amount of space. */
5991 if (line_info->dw_line_num != current_line)
5993 line_offset = line_info->dw_line_num - current_line;
5994 line_delta = line_offset - DWARF_LINE_BASE;
5995 current_line = line_info->dw_line_num;
5996 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5998 /* This can handle deltas from -10 to 234, using the current
5999 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6001 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6002 DWARF_LINE_OPCODE_BASE + line_delta);
6004 fprintf (asm_out_file,
6005 "\t%s line %ld", ASM_COMMENT_START, current_line);
6007 fputc ('\n', asm_out_file);
6011 /* This can handle any delta. This takes at least 4 bytes,
6012 depending on the value being encoded. */
6013 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6015 fprintf (asm_out_file, "\t%s advance to line %ld",
6016 ASM_COMMENT_START, current_line);
6018 fputc ('\n', asm_out_file);
6019 output_sleb128 (line_offset);
6020 fputc ('\n', asm_out_file);
6021 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6023 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6024 fputc ('\n', asm_out_file);
6029 /* We still need to start a new row, so output a copy insn. */
6030 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6032 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6033 fputc ('\n', asm_out_file);
6037 /* Emit debug info for the address of the end of the function. */
6040 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6042 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6045 fputc ('\n', asm_out_file);
6046 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
6047 fputc ('\n', asm_out_file);
6051 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6053 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
6054 fputc ('\n', asm_out_file);
6055 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6056 fputc ('\n', asm_out_file);
6057 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6058 fputc ('\n', asm_out_file);
6059 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
6060 fputc ('\n', asm_out_file);
6063 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6065 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
6067 fputc ('\n', asm_out_file);
6069 fputc ('\n', asm_out_file);
6070 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6071 fputc ('\n', asm_out_file);
6076 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
6078 register dw_separate_line_info_ref line_info
6079 = &separate_line_info_table[lt_index];
6082 /* Don't emit anything for redundant notes. */
6083 if (line_info->dw_line_num == current_line
6084 && line_info->dw_file_num == current_file
6085 && line_info->function == function)
6089 /* Emit debug info for the address of the current line. If this is
6090 a new function, or the first line of a function, then we need
6091 to handle it differently. */
6092 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6094 if (function != line_info->function)
6096 function = line_info->function;
6098 /* Set the address register to the first line in the function */
6099 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6101 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6104 fputc ('\n', asm_out_file);
6105 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6106 fputc ('\n', asm_out_file);
6107 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6108 fputc ('\n', asm_out_file);
6109 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6110 fputc ('\n', asm_out_file);
6114 /* ??? See the DW_LNS_advance_pc comment above. */
6117 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6119 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6122 fputc ('\n', asm_out_file);
6123 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6125 fputc ('\n', asm_out_file);
6129 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6131 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6133 fputc ('\n', asm_out_file);
6134 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6135 fputc ('\n', asm_out_file);
6136 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6137 fputc ('\n', asm_out_file);
6138 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6139 fputc ('\n', asm_out_file);
6142 strcpy (prev_line_label, line_label);
6144 /* Emit debug info for the source file of the current line, if
6145 different from the previous line. */
6146 if (line_info->dw_file_num != current_file)
6148 current_file = line_info->dw_file_num;
6149 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6151 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6153 fputc ('\n', asm_out_file);
6154 output_uleb128 (current_file);
6156 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
6158 fputc ('\n', asm_out_file);
6161 /* Emit debug info for the current line number, choosing the encoding
6162 that uses the least amount of space. */
6163 if (line_info->dw_line_num != current_line)
6165 line_offset = line_info->dw_line_num - current_line;
6166 line_delta = line_offset - DWARF_LINE_BASE;
6167 current_line = line_info->dw_line_num;
6168 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6170 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6171 DWARF_LINE_OPCODE_BASE + line_delta);
6173 fprintf (asm_out_file,
6174 "\t%s line %ld", ASM_COMMENT_START, current_line);
6176 fputc ('\n', asm_out_file);
6180 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6182 fprintf (asm_out_file, "\t%s advance to line %ld",
6183 ASM_COMMENT_START, current_line);
6185 fputc ('\n', asm_out_file);
6186 output_sleb128 (line_offset);
6187 fputc ('\n', asm_out_file);
6188 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6190 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6191 fputc ('\n', asm_out_file);
6196 /* We still need to start a new row, so output a copy insn. */
6197 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6199 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6200 fputc ('\n', asm_out_file);
6208 /* If we're done with a function, end its sequence. */
6209 if (lt_index == separate_line_info_table_in_use
6210 || separate_line_info_table[lt_index].function != function)
6215 /* Emit debug info for the address of the end of the function. */
6216 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6219 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6221 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6224 fputc ('\n', asm_out_file);
6225 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6227 fputc ('\n', asm_out_file);
6231 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6233 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6235 fputc ('\n', asm_out_file);
6236 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6237 fputc ('\n', asm_out_file);
6238 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6239 fputc ('\n', asm_out_file);
6240 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6241 fputc ('\n', asm_out_file);
6244 /* Output the marker for the end of this sequence. */
6245 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6247 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
6250 fputc ('\n', asm_out_file);
6252 fputc ('\n', asm_out_file);
6253 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6254 fputc ('\n', asm_out_file);
6258 /* Output the marker for the end of the line number info. */
6259 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
6262 /* Given a pointer to a tree node for some base type, return a pointer to
6263 a DIE that describes the given type.
6265 This routine must only be called for GCC type nodes that correspond to
6266 Dwarf base (fundamental) types. */
6269 base_type_die (type)
6272 register dw_die_ref base_type_result;
6273 register const char *type_name;
6274 register enum dwarf_type encoding;
6275 register tree name = TYPE_NAME (type);
6277 if (TREE_CODE (type) == ERROR_MARK
6278 || TREE_CODE (type) == VOID_TYPE)
6283 if (TREE_CODE (name) == TYPE_DECL)
6284 name = DECL_NAME (name);
6286 type_name = IDENTIFIER_POINTER (name);
6289 type_name = "__unknown__";
6291 switch (TREE_CODE (type))
6294 /* Carefully distinguish the C character types, without messing
6295 up if the language is not C. Note that we check only for the names
6296 that contain spaces; other names might occur by coincidence in other
6298 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6299 && (type == char_type_node
6300 || ! strcmp (type_name, "signed char")
6301 || ! strcmp (type_name, "unsigned char"))))
6303 if (TREE_UNSIGNED (type))
6304 encoding = DW_ATE_unsigned;
6306 encoding = DW_ATE_signed;
6309 /* else fall through */
6312 /* GNU Pascal/Ada CHAR type. Not used in C. */
6313 if (TREE_UNSIGNED (type))
6314 encoding = DW_ATE_unsigned_char;
6316 encoding = DW_ATE_signed_char;
6320 encoding = DW_ATE_float;
6323 /* Dwarf2 doesn't know anything about complex ints, so use
6324 a user defined type for it. */
6326 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6327 encoding = DW_ATE_complex_float;
6329 encoding = DW_ATE_lo_user;
6333 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6334 encoding = DW_ATE_boolean;
6338 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6341 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6342 if (demangle_name_func)
6343 type_name = (*demangle_name_func) (type_name);
6345 add_AT_string (base_type_result, DW_AT_name, type_name);
6346 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6347 int_size_in_bytes (type));
6348 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6350 return base_type_result;
6353 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6354 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6355 a given type is generally the same as the given type, except that if the
6356 given type is a pointer or reference type, then the root type of the given
6357 type is the root type of the "basis" type for the pointer or reference
6358 type. (This definition of the "root" type is recursive.) Also, the root
6359 type of a `const' qualified type or a `volatile' qualified type is the
6360 root type of the given type without the qualifiers. */
6366 if (TREE_CODE (type) == ERROR_MARK)
6367 return error_mark_node;
6369 switch (TREE_CODE (type))
6372 return error_mark_node;
6375 case REFERENCE_TYPE:
6376 return type_main_variant (root_type (TREE_TYPE (type)));
6379 return type_main_variant (type);
6383 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6384 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6390 switch (TREE_CODE (type))
6405 case QUAL_UNION_TYPE:
6410 case REFERENCE_TYPE:
6423 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6424 entry that chains various modifiers in front of the given type. */
6427 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6429 register int is_const_type;
6430 register int is_volatile_type;
6431 register dw_die_ref context_die;
6433 register enum tree_code code = TREE_CODE (type);
6434 register dw_die_ref mod_type_die = NULL;
6435 register dw_die_ref sub_die = NULL;
6436 register tree item_type = NULL;
6438 if (code != ERROR_MARK)
6440 type = build_type_variant (type, is_const_type, is_volatile_type);
6442 mod_type_die = lookup_type_die (type);
6444 return mod_type_die;
6446 /* Handle C typedef types. */
6447 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6448 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6450 tree dtype = TREE_TYPE (TYPE_NAME (type));
6453 /* For a named type, use the typedef. */
6454 gen_type_die (type, context_die);
6455 mod_type_die = lookup_type_die (type);
6458 else if (is_const_type < TYPE_READONLY (dtype)
6459 || is_volatile_type < TYPE_VOLATILE (dtype))
6460 /* cv-unqualified version of named type. Just use the unnamed
6461 type to which it refers. */
6463 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6464 is_const_type, is_volatile_type,
6466 /* Else cv-qualified version of named type; fall through. */
6471 else if (is_const_type)
6473 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6474 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6476 else if (is_volatile_type)
6478 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6479 sub_die = modified_type_die (type, 0, 0, context_die);
6481 else if (code == POINTER_TYPE)
6483 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6484 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6486 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6488 item_type = TREE_TYPE (type);
6490 else if (code == REFERENCE_TYPE)
6492 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6493 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6495 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6497 item_type = TREE_TYPE (type);
6499 else if (is_base_type (type))
6500 mod_type_die = base_type_die (type);
6503 gen_type_die (type, context_die);
6505 /* We have to get the type_main_variant here (and pass that to the
6506 `lookup_type_die' routine) because the ..._TYPE node we have
6507 might simply be a *copy* of some original type node (where the
6508 copy was created to help us keep track of typedef names) and
6509 that copy might have a different TYPE_UID from the original
6511 mod_type_die = lookup_type_die (type_main_variant (type));
6512 if (mod_type_die == NULL)
6517 equate_type_number_to_die (type, mod_type_die);
6519 /* We must do this after the equate_type_number_to_die call, in case
6520 this is a recursive type. This ensures that the modified_type_die
6521 recursion will terminate even if the type is recursive. Recursive
6522 types are possible in Ada. */
6523 sub_die = modified_type_die (item_type,
6524 TYPE_READONLY (item_type),
6525 TYPE_VOLATILE (item_type),
6528 if (sub_die != NULL)
6529 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6531 return mod_type_die;
6534 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6535 an enumerated type. */
6541 return TREE_CODE (type) == ENUMERAL_TYPE;
6544 /* Return the register number described by a given RTL node. */
6550 register unsigned regno = REGNO (rtl);
6552 if (regno >= FIRST_PSEUDO_REGISTER)
6554 warning ("internal regno botch: regno = %d\n", regno);
6558 regno = DBX_REGISTER_NUMBER (regno);
6562 /* Return a location descriptor that designates a machine register. */
6564 static dw_loc_descr_ref
6565 reg_loc_descriptor (rtl)
6568 register dw_loc_descr_ref loc_result = NULL;
6569 register unsigned reg = reg_number (rtl);
6572 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6574 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6579 /* Return a location descriptor that designates a base+offset location. */
6581 static dw_loc_descr_ref
6582 based_loc_descr (reg, offset)
6586 register dw_loc_descr_ref loc_result;
6587 /* For the "frame base", we use the frame pointer or stack pointer
6588 registers, since the RTL for local variables is relative to one of
6590 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6591 ? HARD_FRAME_POINTER_REGNUM
6592 : STACK_POINTER_REGNUM);
6595 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
6597 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
6599 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
6604 /* Return true if this RTL expression describes a base+offset calculation. */
6610 return (GET_CODE (rtl) == PLUS
6611 && ((GET_CODE (XEXP (rtl, 0)) == REG
6612 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
6615 /* The following routine converts the RTL for a variable or parameter
6616 (resident in memory) into an equivalent Dwarf representation of a
6617 mechanism for getting the address of that same variable onto the top of a
6618 hypothetical "address evaluation" stack.
6620 When creating memory location descriptors, we are effectively transforming
6621 the RTL for a memory-resident object into its Dwarf postfix expression
6622 equivalent. This routine recursively descends an RTL tree, turning
6623 it into Dwarf postfix code as it goes.
6625 MODE is the mode of the memory reference, needed to handle some
6626 autoincrement addressing modes. */
6628 static dw_loc_descr_ref
6629 mem_loc_descriptor (rtl, mode)
6631 enum machine_mode mode;
6633 dw_loc_descr_ref mem_loc_result = NULL;
6634 /* Note that for a dynamically sized array, the location we will generate a
6635 description of here will be the lowest numbered location which is
6636 actually within the array. That's *not* necessarily the same as the
6637 zeroth element of the array. */
6639 #ifdef ASM_SIMPLIFY_DWARF_ADDR
6640 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
6643 switch (GET_CODE (rtl))
6647 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
6648 just fall into the SUBREG code. */
6650 /* ... fall through ... */
6653 /* The case of a subreg may arise when we have a local (register)
6654 variable or a formal (register) parameter which doesn't quite fill
6655 up an entire register. For now, just assume that it is
6656 legitimate to make the Dwarf info refer to the whole register which
6657 contains the given subreg. */
6658 rtl = XEXP (rtl, 0);
6660 /* ... fall through ... */
6663 /* Whenever a register number forms a part of the description of the
6664 method for calculating the (dynamic) address of a memory resident
6665 object, DWARF rules require the register number be referred to as
6666 a "base register". This distinction is not based in any way upon
6667 what category of register the hardware believes the given register
6668 belongs to. This is strictly DWARF terminology we're dealing with
6669 here. Note that in cases where the location of a memory-resident
6670 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6671 OP_CONST (0)) the actual DWARF location descriptor that we generate
6672 may just be OP_BASEREG (basereg). This may look deceptively like
6673 the object in question was allocated to a register (rather than in
6674 memory) so DWARF consumers need to be aware of the subtle
6675 distinction between OP_REG and OP_BASEREG. */
6676 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
6680 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
6681 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6685 /* Some ports can transform a symbol ref into a label ref, because
6686 the symbol ref is too far away and has to be dumped into a constant
6690 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6691 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6692 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
6697 /* Turn these into a PLUS expression and fall into the PLUS code
6699 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
6700 GEN_INT (GET_CODE (rtl) == PRE_INC
6701 ? GET_MODE_UNIT_SIZE (mode)
6702 : - GET_MODE_UNIT_SIZE (mode)));
6704 /* ... fall through ... */
6707 if (is_based_loc (rtl))
6708 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
6709 INTVAL (XEXP (rtl, 1)));
6712 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0),
6714 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1),
6716 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
6721 /* If a pseudo-reg is optimized away, it is possible for it to
6722 be replaced with a MEM containing a multiply. */
6723 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode));
6724 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode));
6725 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
6729 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6736 return mem_loc_result;
6739 /* Return a descriptor that describes the concatenation of two locations.
6740 This is typically a complex variable. */
6742 static dw_loc_descr_ref
6743 concat_loc_descriptor (x0, x1)
6744 register rtx x0, x1;
6746 dw_loc_descr_ref cc_loc_result = NULL;
6748 if (!is_pseudo_reg (x0)
6749 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
6750 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
6751 add_loc_descr (&cc_loc_result,
6752 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
6754 if (!is_pseudo_reg (x1)
6755 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
6756 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
6757 add_loc_descr (&cc_loc_result,
6758 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
6760 return cc_loc_result;
6763 /* Output a proper Dwarf location descriptor for a variable or parameter
6764 which is either allocated in a register or in a memory location. For a
6765 register, we just generate an OP_REG and the register number. For a
6766 memory location we provide a Dwarf postfix expression describing how to
6767 generate the (dynamic) address of the object onto the address stack. */
6769 static dw_loc_descr_ref
6770 loc_descriptor (rtl)
6773 dw_loc_descr_ref loc_result = NULL;
6774 switch (GET_CODE (rtl))
6777 /* The case of a subreg may arise when we have a local (register)
6778 variable or a formal (register) parameter which doesn't quite fill
6779 up an entire register. For now, just assume that it is
6780 legitimate to make the Dwarf info refer to the whole register which
6781 contains the given subreg. */
6782 rtl = XEXP (rtl, 0);
6784 /* ... fall through ... */
6787 loc_result = reg_loc_descriptor (rtl);
6791 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
6795 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
6805 /* Given a value, round it up to the lowest multiple of `boundary'
6806 which is not less than the value itself. */
6808 static inline HOST_WIDE_INT
6809 ceiling (value, boundary)
6810 HOST_WIDE_INT value;
6811 unsigned int boundary;
6813 return (((value + boundary - 1) / boundary) * boundary);
6816 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6817 pointer to the declared type for the relevant field variable, or return
6818 `integer_type_node' if the given node turns out to be an
6827 if (TREE_CODE (decl) == ERROR_MARK)
6828 return integer_type_node;
6830 type = DECL_BIT_FIELD_TYPE (decl);
6831 if (type == NULL_TREE)
6832 type = TREE_TYPE (decl);
6837 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6838 node, return the alignment in bits for the type, or else return
6839 BITS_PER_WORD if the node actually turns out to be an
6842 static inline unsigned
6843 simple_type_align_in_bits (type)
6846 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6849 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6850 node, return the size in bits for the type if it is a constant, or else
6851 return the alignment for the type if the type's size is not constant, or
6852 else return BITS_PER_WORD if the type actually turns out to be an
6855 static inline unsigned HOST_WIDE_INT
6856 simple_type_size_in_bits (type)
6859 if (TREE_CODE (type) == ERROR_MARK)
6860 return BITS_PER_WORD;
6863 register tree type_size_tree = TYPE_SIZE (type);
6865 if (! host_integerp (type_size_tree, 1))
6866 return TYPE_ALIGN (type);
6868 return tree_low_cst (type_size_tree, 1);
6872 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6873 return the byte offset of the lowest addressed byte of the "containing
6874 object" for the given FIELD_DECL, or return 0 if we are unable to
6875 determine what that offset is, either because the argument turns out to
6876 be a pointer to an ERROR_MARK node, or because the offset is actually
6877 variable. (We can't handle the latter case just yet). */
6879 static HOST_WIDE_INT
6880 field_byte_offset (decl)
6883 unsigned int type_align_in_bytes;
6884 unsigned int type_align_in_bits;
6885 unsigned HOST_WIDE_INT type_size_in_bits;
6886 HOST_WIDE_INT object_offset_in_align_units;
6887 HOST_WIDE_INT object_offset_in_bits;
6888 HOST_WIDE_INT object_offset_in_bytes;
6890 tree field_size_tree;
6891 HOST_WIDE_INT bitpos_int;
6892 HOST_WIDE_INT deepest_bitpos;
6893 unsigned HOST_WIDE_INT field_size_in_bits;
6895 if (TREE_CODE (decl) == ERROR_MARK)
6898 if (TREE_CODE (decl) != FIELD_DECL)
6901 type = field_type (decl);
6902 field_size_tree = DECL_SIZE (decl);
6904 /* If there was an error, the size could be zero. */
6905 if (! field_size_tree)
6913 /* We cannot yet cope with fields whose positions are variable, so
6914 for now, when we see such things, we simply return 0. Someday, we may
6915 be able to handle such cases, but it will be damn difficult. */
6916 if (! host_integerp (bit_position (decl), 0))
6919 bitpos_int = int_bit_position (decl);
6921 /* If we don't know the size of the field, pretend it's a full word. */
6922 if (host_integerp (field_size_tree, 1))
6923 field_size_in_bits = tree_low_cst (field_size_tree, 1);
6925 field_size_in_bits = BITS_PER_WORD;
6927 type_size_in_bits = simple_type_size_in_bits (type);
6928 type_align_in_bits = simple_type_align_in_bits (type);
6929 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6931 /* Note that the GCC front-end doesn't make any attempt to keep track of
6932 the starting bit offset (relative to the start of the containing
6933 structure type) of the hypothetical "containing object" for a bit-
6934 field. Thus, when computing the byte offset value for the start of the
6935 "containing object" of a bit-field, we must deduce this information on
6936 our own. This can be rather tricky to do in some cases. For example,
6937 handling the following structure type definition when compiling for an
6938 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6941 struct S { int field1; long long field2:31; };
6943 Fortunately, there is a simple rule-of-thumb which can be
6944 used in such cases. When compiling for an i386/i486, GCC will allocate
6945 8 bytes for the structure shown above. It decides to do this based upon
6946 one simple rule for bit-field allocation. Quite simply, GCC allocates
6947 each "containing object" for each bit-field at the first (i.e. lowest
6948 addressed) legitimate alignment boundary (based upon the required
6949 minimum alignment for the declared type of the field) which it can
6950 possibly use, subject to the condition that there is still enough
6951 available space remaining in the containing object (when allocated at
6952 the selected point) to fully accommodate all of the bits of the
6953 bit-field itself. This simple rule makes it obvious why GCC allocates
6954 8 bytes for each object of the structure type shown above. When looking
6955 for a place to allocate the "containing object" for `field2', the
6956 compiler simply tries to allocate a 64-bit "containing object" at each
6957 successive 32-bit boundary (starting at zero) until it finds a place to
6958 allocate that 64- bit field such that at least 31 contiguous (and
6959 previously unallocated) bits remain within that selected 64 bit field.
6960 (As it turns out, for the example above, the compiler finds that it is
6961 OK to allocate the "containing object" 64-bit field at bit-offset zero
6962 within the structure type.) Here we attempt to work backwards from the
6963 limited set of facts we're given, and we try to deduce from those facts,
6964 where GCC must have believed that the containing object started (within
6965 the structure type). The value we deduce is then used (by the callers of
6966 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6967 for fields (both bit-fields and, in the case of DW_AT_location, regular
6970 /* Figure out the bit-distance from the start of the structure to the
6971 "deepest" bit of the bit-field. */
6972 deepest_bitpos = bitpos_int + field_size_in_bits;
6974 /* This is the tricky part. Use some fancy footwork to deduce where the
6975 lowest addressed bit of the containing object must be. */
6976 object_offset_in_bits
6977 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6979 /* Compute the offset of the containing object in "alignment units". */
6980 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6982 /* Compute the offset of the containing object in bytes. */
6983 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6985 return object_offset_in_bytes;
6988 /* The following routines define various Dwarf attributes and any data
6989 associated with them. */
6991 /* Add a location description attribute value to a DIE.
6993 This emits location attributes suitable for whole variables and
6994 whole parameters. Note that the location attributes for struct fields are
6995 generated by the routine `data_member_location_attribute' below. */
6998 add_AT_location_description (die, attr_kind, rtl)
7000 enum dwarf_attribute attr_kind;
7003 /* Handle a special case. If we are about to output a location descriptor
7004 for a variable or parameter which has been optimized out of existence,
7005 don't do that. A variable which has been optimized out
7006 of existence will have a DECL_RTL value which denotes a pseudo-reg.
7007 Currently, in some rare cases, variables can have DECL_RTL values which
7008 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
7009 elsewhere in the compiler. We treat such cases as if the variable(s) in
7010 question had been optimized out of existence. */
7012 if (is_pseudo_reg (rtl)
7013 || (GET_CODE (rtl) == MEM
7014 && is_pseudo_reg (XEXP (rtl, 0)))
7015 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
7016 references the internal argument pointer (a pseudo) in a function
7017 where all references to the internal argument pointer were
7018 eliminated via the optimizers. */
7019 || (GET_CODE (rtl) == MEM
7020 && GET_CODE (XEXP (rtl, 0)) == PLUS
7021 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
7022 || (GET_CODE (rtl) == CONCAT
7023 && is_pseudo_reg (XEXP (rtl, 0))
7024 && is_pseudo_reg (XEXP (rtl, 1))))
7027 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
7030 /* Attach the specialized form of location attribute used for data
7031 members of struct and union types. In the special case of a
7032 FIELD_DECL node which represents a bit-field, the "offset" part
7033 of this special location descriptor must indicate the distance
7034 in bytes from the lowest-addressed byte of the containing struct
7035 or union type to the lowest-addressed byte of the "containing
7036 object" for the bit-field. (See the `field_byte_offset' function
7037 above).. For any given bit-field, the "containing object" is a
7038 hypothetical object (of some integral or enum type) within which
7039 the given bit-field lives. The type of this hypothetical
7040 "containing object" is always the same as the declared type of
7041 the individual bit-field itself (for GCC anyway... the DWARF
7042 spec doesn't actually mandate this). Note that it is the size
7043 (in bytes) of the hypothetical "containing object" which will
7044 be given in the DW_AT_byte_size attribute for this bit-field.
7045 (See the `byte_size_attribute' function below.) It is also used
7046 when calculating the value of the DW_AT_bit_offset attribute.
7047 (See the `bit_offset_attribute' function below). */
7050 add_data_member_location_attribute (die, decl)
7051 register dw_die_ref die;
7054 register unsigned long offset;
7055 register dw_loc_descr_ref loc_descr;
7056 register enum dwarf_location_atom op;
7058 if (TREE_CODE (decl) == TREE_VEC)
7059 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
7061 offset = field_byte_offset (decl);
7063 /* The DWARF2 standard says that we should assume that the structure address
7064 is already on the stack, so we can specify a structure field address
7065 by using DW_OP_plus_uconst. */
7067 #ifdef MIPS_DEBUGGING_INFO
7068 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
7069 correctly. It works only if we leave the offset on the stack. */
7072 op = DW_OP_plus_uconst;
7075 loc_descr = new_loc_descr (op, offset, 0);
7076 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
7079 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
7080 does not have a "location" either in memory or in a register. These
7081 things can arise in GNU C when a constant is passed as an actual parameter
7082 to an inlined function. They can also arise in C++ where declared
7083 constants do not necessarily get memory "homes". */
7086 add_const_value_attribute (die, rtl)
7087 register dw_die_ref die;
7090 switch (GET_CODE (rtl))
7093 /* Note that a CONST_INT rtx could represent either an integer or a
7094 floating-point constant. A CONST_INT is used whenever the constant
7095 will fit into a single word. In all such cases, the original mode
7096 of the constant value is wiped out, and the CONST_INT rtx is
7097 assigned VOIDmode. */
7098 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
7102 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
7103 floating-point constant. A CONST_DOUBLE is used whenever the
7104 constant requires more than one word in order to be adequately
7105 represented. We output CONST_DOUBLEs as blocks. */
7107 register enum machine_mode mode = GET_MODE (rtl);
7109 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
7111 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
7115 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
7119 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
7123 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
7128 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
7135 add_AT_float (die, DW_AT_const_value, length, array);
7138 add_AT_long_long (die, DW_AT_const_value,
7139 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
7144 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
7150 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
7154 /* In cases where an inlined instance of an inline function is passed
7155 the address of an `auto' variable (which is local to the caller) we
7156 can get a situation where the DECL_RTL of the artificial local
7157 variable (for the inlining) which acts as a stand-in for the
7158 corresponding formal parameter (of the inline function) will look
7159 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
7160 exactly a compile-time constant expression, but it isn't the address
7161 of the (artificial) local variable either. Rather, it represents the
7162 *value* which the artificial local variable always has during its
7163 lifetime. We currently have no way to represent such quasi-constant
7164 values in Dwarf, so for now we just punt and generate nothing. */
7168 /* No other kinds of rtx should be possible here. */
7174 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
7175 data attribute for a variable or a parameter. We generate the
7176 DW_AT_const_value attribute only in those cases where the given variable
7177 or parameter does not have a true "location" either in memory or in a
7178 register. This can happen (for example) when a constant is passed as an
7179 actual argument in a call to an inline function. (It's possible that
7180 these things can crop up in other ways also.) Note that one type of
7181 constant value which can be passed into an inlined function is a constant
7182 pointer. This can happen for example if an actual argument in an inlined
7183 function call evaluates to a compile-time constant address. */
7186 add_location_or_const_value_attribute (die, decl)
7187 register dw_die_ref die;
7191 register tree declared_type;
7192 register tree passed_type;
7194 if (TREE_CODE (decl) == ERROR_MARK)
7197 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
7200 /* Here we have to decide where we are going to say the parameter "lives"
7201 (as far as the debugger is concerned). We only have a couple of
7202 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
7204 DECL_RTL normally indicates where the parameter lives during most of the
7205 activation of the function. If optimization is enabled however, this
7206 could be either NULL or else a pseudo-reg. Both of those cases indicate
7207 that the parameter doesn't really live anywhere (as far as the code
7208 generation parts of GCC are concerned) during most of the function's
7209 activation. That will happen (for example) if the parameter is never
7210 referenced within the function.
7212 We could just generate a location descriptor here for all non-NULL
7213 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
7214 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
7215 where DECL_RTL is NULL or is a pseudo-reg.
7217 Note however that we can only get away with using DECL_INCOMING_RTL as
7218 a backup substitute for DECL_RTL in certain limited cases. In cases
7219 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
7220 we can be sure that the parameter was passed using the same type as it is
7221 declared to have within the function, and that its DECL_INCOMING_RTL
7222 points us to a place where a value of that type is passed.
7224 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
7225 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
7226 because in these cases DECL_INCOMING_RTL points us to a value of some
7227 type which is *different* from the type of the parameter itself. Thus,
7228 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
7229 such cases, the debugger would end up (for example) trying to fetch a
7230 `float' from a place which actually contains the first part of a
7231 `double'. That would lead to really incorrect and confusing
7232 output at debug-time.
7234 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
7235 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
7236 are a couple of exceptions however. On little-endian machines we can
7237 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
7238 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
7239 an integral type that is smaller than TREE_TYPE (decl). These cases arise
7240 when (on a little-endian machine) a non-prototyped function has a
7241 parameter declared to be of type `short' or `char'. In such cases,
7242 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
7243 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
7244 passed `int' value. If the debugger then uses that address to fetch
7245 a `short' or a `char' (on a little-endian machine) the result will be
7246 the correct data, so we allow for such exceptional cases below.
7248 Note that our goal here is to describe the place where the given formal
7249 parameter lives during most of the function's activation (i.e. between
7250 the end of the prologue and the start of the epilogue). We'll do that
7251 as best as we can. Note however that if the given formal parameter is
7252 modified sometime during the execution of the function, then a stack
7253 backtrace (at debug-time) will show the function as having been
7254 called with the *new* value rather than the value which was
7255 originally passed in. This happens rarely enough that it is not
7256 a major problem, but it *is* a problem, and I'd like to fix it.
7258 A future version of dwarf2out.c may generate two additional
7259 attributes for any given DW_TAG_formal_parameter DIE which will
7260 describe the "passed type" and the "passed location" for the
7261 given formal parameter in addition to the attributes we now
7262 generate to indicate the "declared type" and the "active
7263 location" for each parameter. This additional set of attributes
7264 could be used by debuggers for stack backtraces. Separately, note
7265 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
7266 NULL also. This happens (for example) for inlined-instances of
7267 inline function formal parameters which are never referenced.
7268 This really shouldn't be happening. All PARM_DECL nodes should
7269 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
7270 doesn't currently generate these values for inlined instances of
7271 inline function parameters, so when we see such cases, we are
7272 just out-of-luck for the time being (until integrate.c
7275 /* Use DECL_RTL as the "location" unless we find something better. */
7276 rtl = DECL_RTL (decl);
7278 if (TREE_CODE (decl) == PARM_DECL)
7280 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
7282 declared_type = type_main_variant (TREE_TYPE (decl));
7283 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
7285 /* This decl represents a formal parameter which was optimized out.
7286 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
7287 all* cases where (rtl == NULL_RTX) just below. */
7288 if (declared_type == passed_type)
7289 rtl = DECL_INCOMING_RTL (decl);
7290 else if (! BYTES_BIG_ENDIAN
7291 && TREE_CODE (declared_type) == INTEGER_TYPE
7292 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
7293 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
7294 rtl = DECL_INCOMING_RTL (decl);
7297 /* If the parm was passed in registers, but lives on the stack, then
7298 make a big endian correction if the mode of the type of the
7299 parameter is not the same as the mode of the rtl. */
7300 /* ??? This is the same series of checks that are made in dbxout.c before
7301 we reach the big endian correction code there. It isn't clear if all
7302 of these checks are necessary here, but keeping them all is the safe
7304 else if (GET_CODE (rtl) == MEM
7305 && XEXP (rtl, 0) != const0_rtx
7306 && ! CONSTANT_P (XEXP (rtl, 0))
7307 /* Not passed in memory. */
7308 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
7309 /* Not passed by invisible reference. */
7310 && (GET_CODE (XEXP (rtl, 0)) != REG
7311 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
7312 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
7313 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
7314 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
7317 /* Big endian correction check. */
7319 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
7320 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
7323 int offset = (UNITS_PER_WORD
7324 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
7325 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
7326 plus_constant (XEXP (rtl, 0), offset));
7330 if (rtl == NULL_RTX)
7333 rtl = eliminate_regs (rtl, 0, NULL_RTX);
7334 #ifdef LEAF_REG_REMAP
7335 if (current_function_uses_only_leaf_regs)
7336 leaf_renumber_regs_insn (rtl);
7339 switch (GET_CODE (rtl))
7342 /* The address of a variable that was optimized away; don't emit
7353 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7354 add_const_value_attribute (die, rtl);
7361 add_AT_location_description (die, DW_AT_location, rtl);
7369 /* Generate an DW_AT_name attribute given some string value to be included as
7370 the value of the attribute. */
7373 add_name_attribute (die, name_string)
7374 register dw_die_ref die;
7375 register const char *name_string;
7377 if (name_string != NULL && *name_string != 0)
7379 if (demangle_name_func)
7380 name_string = (*demangle_name_func) (name_string);
7382 add_AT_string (die, DW_AT_name, name_string);
7386 /* Given a tree node describing an array bound (either lower or upper) output
7387 a representation for that bound. */
7390 add_bound_info (subrange_die, bound_attr, bound)
7391 register dw_die_ref subrange_die;
7392 register enum dwarf_attribute bound_attr;
7393 register tree bound;
7395 /* If this is an Ada unconstrained array type, then don't emit any debug
7396 info because the array bounds are unknown. They are parameterized when
7397 the type is instantiated. */
7398 if (contains_placeholder_p (bound))
7401 switch (TREE_CODE (bound))
7406 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7408 if (! host_integerp (bound, 0)
7409 || (bound_attr == DW_AT_lower_bound
7410 && ((is_c_family () && integer_zerop (bound))
7411 || (is_fortran () && integer_onep (bound)))))
7412 /* use the default */
7415 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
7420 case NON_LVALUE_EXPR:
7421 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7425 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7426 access the upper bound values may be bogus. If they refer to a
7427 register, they may only describe how to get at these values at the
7428 points in the generated code right after they have just been
7429 computed. Worse yet, in the typical case, the upper bound values
7430 will not even *be* computed in the optimized code (though the
7431 number of elements will), so these SAVE_EXPRs are entirely
7432 bogus. In order to compensate for this fact, we check here to see
7433 if optimization is enabled, and if so, we don't add an attribute
7434 for the (unknown and unknowable) upper bound. This should not
7435 cause too much trouble for existing (stupid?) debuggers because
7436 they have to deal with empty upper bounds location descriptions
7437 anyway in order to be able to deal with incomplete array types.
7438 Of course an intelligent debugger (GDB?) should be able to
7439 comprehend that a missing upper bound specification in a array
7440 type used for a storage class `auto' local array variable
7441 indicates that the upper bound is both unknown (at compile- time)
7442 and unknowable (at run-time) due to optimization.
7444 We assume that a MEM rtx is safe because gcc wouldn't put the
7445 value there unless it was going to be used repeatedly in the
7446 function, i.e. for cleanups. */
7447 if (! optimize || (SAVE_EXPR_RTL (bound)
7448 && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
7450 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7451 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7452 register rtx loc = SAVE_EXPR_RTL (bound);
7454 /* If the RTL for the SAVE_EXPR is memory, handle the case where
7455 it references an outer function's frame. */
7457 if (GET_CODE (loc) == MEM)
7459 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
7461 if (XEXP (loc, 0) != new_addr)
7462 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
7465 add_AT_flag (decl_die, DW_AT_artificial, 1);
7466 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
7467 add_AT_location_description (decl_die, DW_AT_location, loc);
7468 add_AT_die_ref (subrange_die, bound_attr, decl_die);
7471 /* Else leave out the attribute. */
7477 /* ??? These types of bounds can be created by the Ada front end,
7478 and it isn't clear how to emit debug info for them. */
7486 /* Note that the block of subscript information for an array type also
7487 includes information about the element type of type given array type. */
7490 add_subscript_info (type_die, type)
7491 register dw_die_ref type_die;
7494 #ifndef MIPS_DEBUGGING_INFO
7495 register unsigned dimension_number;
7497 register tree lower, upper;
7498 register dw_die_ref subrange_die;
7500 /* The GNU compilers represent multidimensional array types as sequences of
7501 one dimensional array types whose element types are themselves array
7502 types. Here we squish that down, so that each multidimensional array
7503 type gets only one array_type DIE in the Dwarf debugging info. The draft
7504 Dwarf specification say that we are allowed to do this kind of
7505 compression in C (because there is no difference between an array or
7506 arrays and a multidimensional array in C) but for other source languages
7507 (e.g. Ada) we probably shouldn't do this. */
7509 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7510 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7511 We work around this by disabling this feature. See also
7512 gen_array_type_die. */
7513 #ifndef MIPS_DEBUGGING_INFO
7514 for (dimension_number = 0;
7515 TREE_CODE (type) == ARRAY_TYPE;
7516 type = TREE_TYPE (type), dimension_number++)
7519 register tree domain = TYPE_DOMAIN (type);
7521 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7522 and (in GNU C only) variable bounds. Handle all three forms
7524 subrange_die = new_die (DW_TAG_subrange_type, type_die);
7527 /* We have an array type with specified bounds. */
7528 lower = TYPE_MIN_VALUE (domain);
7529 upper = TYPE_MAX_VALUE (domain);
7531 /* define the index type. */
7532 if (TREE_TYPE (domain))
7534 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7535 TREE_TYPE field. We can't emit debug info for this
7536 because it is an unnamed integral type. */
7537 if (TREE_CODE (domain) == INTEGER_TYPE
7538 && TYPE_NAME (domain) == NULL_TREE
7539 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
7540 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
7543 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
7547 /* ??? If upper is NULL, the array has unspecified length,
7548 but it does have a lower bound. This happens with Fortran
7550 Since the debugger is definitely going to need to know N
7551 to produce useful results, go ahead and output the lower
7552 bound solo, and hope the debugger can cope. */
7554 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
7556 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
7559 /* We have an array type with an unspecified length. The DWARF-2
7560 spec does not say how to handle this; let's just leave out the
7565 #ifndef MIPS_DEBUGGING_INFO
7571 add_byte_size_attribute (die, tree_node)
7573 register tree tree_node;
7575 register unsigned size;
7577 switch (TREE_CODE (tree_node))
7585 case QUAL_UNION_TYPE:
7586 size = int_size_in_bytes (tree_node);
7589 /* For a data member of a struct or union, the DW_AT_byte_size is
7590 generally given as the number of bytes normally allocated for an
7591 object of the *declared* type of the member itself. This is true
7592 even for bit-fields. */
7593 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
7599 /* Note that `size' might be -1 when we get to this point. If it is, that
7600 indicates that the byte size of the entity in question is variable. We
7601 have no good way of expressing this fact in Dwarf at the present time,
7602 so just let the -1 pass on through. */
7604 add_AT_unsigned (die, DW_AT_byte_size, size);
7607 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7608 which specifies the distance in bits from the highest order bit of the
7609 "containing object" for the bit-field to the highest order bit of the
7612 For any given bit-field, the "containing object" is a hypothetical
7613 object (of some integral or enum type) within which the given bit-field
7614 lives. The type of this hypothetical "containing object" is always the
7615 same as the declared type of the individual bit-field itself. The
7616 determination of the exact location of the "containing object" for a
7617 bit-field is rather complicated. It's handled by the
7618 `field_byte_offset' function (above).
7620 Note that it is the size (in bytes) of the hypothetical "containing object"
7621 which will be given in the DW_AT_byte_size attribute for this bit-field.
7622 (See `byte_size_attribute' above). */
7625 add_bit_offset_attribute (die, decl)
7626 register dw_die_ref die;
7629 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
7630 tree type = DECL_BIT_FIELD_TYPE (decl);
7631 HOST_WIDE_INT bitpos_int;
7632 HOST_WIDE_INT highest_order_object_bit_offset;
7633 HOST_WIDE_INT highest_order_field_bit_offset;
7634 HOST_WIDE_INT unsigned bit_offset;
7636 /* Must be a field and a bit field. */
7638 || TREE_CODE (decl) != FIELD_DECL)
7641 /* We can't yet handle bit-fields whose offsets are variable, so if we
7642 encounter such things, just return without generating any attribute
7643 whatsoever. Likewise for variable or too large size. */
7644 if (! host_integerp (bit_position (decl), 0)
7645 || ! host_integerp (DECL_SIZE (decl), 1))
7648 bitpos_int = int_bit_position (decl);
7650 /* Note that the bit offset is always the distance (in bits) from the
7651 highest-order bit of the "containing object" to the highest-order bit of
7652 the bit-field itself. Since the "high-order end" of any object or field
7653 is different on big-endian and little-endian machines, the computation
7654 below must take account of these differences. */
7655 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
7656 highest_order_field_bit_offset = bitpos_int;
7658 if (! BYTES_BIG_ENDIAN)
7660 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
7661 highest_order_object_bit_offset += simple_type_size_in_bits (type);
7665 = (! BYTES_BIG_ENDIAN
7666 ? highest_order_object_bit_offset - highest_order_field_bit_offset
7667 : highest_order_field_bit_offset - highest_order_object_bit_offset);
7669 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
7672 /* For a FIELD_DECL node which represents a bit field, output an attribute
7673 which specifies the length in bits of the given field. */
7676 add_bit_size_attribute (die, decl)
7677 register dw_die_ref die;
7680 /* Must be a field and a bit field. */
7681 if (TREE_CODE (decl) != FIELD_DECL
7682 || ! DECL_BIT_FIELD_TYPE (decl))
7685 if (host_integerp (DECL_SIZE (decl), 1))
7686 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
7689 /* If the compiled language is ANSI C, then add a 'prototyped'
7690 attribute, if arg types are given for the parameters of a function. */
7693 add_prototyped_attribute (die, func_type)
7694 register dw_die_ref die;
7695 register tree func_type;
7697 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
7698 && TYPE_ARG_TYPES (func_type) != NULL)
7699 add_AT_flag (die, DW_AT_prototyped, 1);
7703 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7704 by looking in either the type declaration or object declaration
7708 add_abstract_origin_attribute (die, origin)
7709 register dw_die_ref die;
7710 register tree origin;
7712 dw_die_ref origin_die = NULL;
7714 if (TREE_CODE (origin) != FUNCTION_DECL)
7716 /* We may have gotten separated from the block for the inlined
7717 function, if we're in an exception handler or some such; make
7718 sure that the abstract function has been written out.
7720 Doing this for nested functions is wrong, however; functions are
7721 distinct units, and our context might not even be inline. */
7724 fn = TYPE_STUB_DECL (fn);
7725 fn = decl_function_context (fn);
7727 gen_abstract_function (fn);
7730 if (DECL_P (origin))
7731 origin_die = lookup_decl_die (origin);
7732 else if (TYPE_P (origin))
7733 origin_die = lookup_type_die (origin);
7735 if (origin_die == NULL)
7738 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
7741 /* We do not currently support the pure_virtual attribute. */
7744 add_pure_or_virtual_attribute (die, func_decl)
7745 register dw_die_ref die;
7746 register tree func_decl;
7748 if (DECL_VINDEX (func_decl))
7750 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7752 if (host_integerp (DECL_VINDEX (func_decl), 0))
7753 add_AT_loc (die, DW_AT_vtable_elem_location,
7754 new_loc_descr (DW_OP_constu,
7755 tree_low_cst (DECL_VINDEX (func_decl), 0),
7758 /* GNU extension: Record what type this method came from originally. */
7759 if (debug_info_level > DINFO_LEVEL_TERSE)
7760 add_AT_die_ref (die, DW_AT_containing_type,
7761 lookup_type_die (DECL_CONTEXT (func_decl)));
7765 /* Add source coordinate attributes for the given decl. */
7768 add_src_coords_attributes (die, decl)
7769 register dw_die_ref die;
7772 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
7774 add_AT_unsigned (die, DW_AT_decl_file, file_index);
7775 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7778 /* Add an DW_AT_name attribute and source coordinate attribute for the
7779 given decl, but only if it actually has a name. */
7782 add_name_and_src_coords_attributes (die, decl)
7783 register dw_die_ref die;
7786 register tree decl_name;
7788 decl_name = DECL_NAME (decl);
7789 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
7791 add_name_attribute (die, dwarf2_name (decl, 0));
7792 if (! DECL_ARTIFICIAL (decl))
7793 add_src_coords_attributes (die, decl);
7795 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
7796 && TREE_PUBLIC (decl)
7797 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
7798 add_AT_string (die, DW_AT_MIPS_linkage_name,
7799 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
7803 /* Push a new declaration scope. */
7806 push_decl_scope (scope)
7809 /* Make room in the decl_scope_table, if necessary. */
7810 if (decl_scope_table_allocated == decl_scope_depth)
7812 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
7814 = (tree *) xrealloc (decl_scope_table,
7815 decl_scope_table_allocated * sizeof (tree));
7818 decl_scope_table[decl_scope_depth] = scope;
7822 /* Pop a declaration scope. */
7826 if (decl_scope_depth <= 0)
7831 /* Return the DIE for the scope that immediately contains this type.
7832 Non-named types get global scope. Named types nested in other
7833 types get their containing scope if it's open, or global scope
7834 otherwise. All other types (i.e. function-local named types) get
7835 the current active scope. */
7838 scope_die_for (t, context_die)
7840 register dw_die_ref context_die;
7842 register dw_die_ref scope_die = NULL;
7843 register tree containing_scope;
7846 /* Non-types always go in the current scope. */
7850 containing_scope = TYPE_CONTEXT (t);
7852 /* Ignore namespaces for the moment. */
7853 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
7854 containing_scope = NULL_TREE;
7856 /* Ignore function type "scopes" from the C frontend. They mean that
7857 a tagged type is local to a parmlist of a function declarator, but
7858 that isn't useful to DWARF. */
7859 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
7860 containing_scope = NULL_TREE;
7862 if (containing_scope == NULL_TREE)
7863 scope_die = comp_unit_die;
7864 else if (TYPE_P (containing_scope))
7866 /* For types, we can just look up the appropriate DIE. But
7867 first we check to see if we're in the middle of emitting it
7868 so we know where the new DIE should go. */
7870 for (i = decl_scope_depth - 1; i >= 0; --i)
7871 if (decl_scope_table[i] == containing_scope)
7876 if (debug_info_level > DINFO_LEVEL_TERSE
7877 && !TREE_ASM_WRITTEN (containing_scope))
7880 /* If none of the current dies are suitable, we get file scope. */
7881 scope_die = comp_unit_die;
7884 scope_die = lookup_type_die (containing_scope);
7887 scope_die = context_die;
7892 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
7894 static inline int local_scope_p PARAMS ((dw_die_ref));
7896 local_scope_p (context_die)
7897 dw_die_ref context_die;
7899 for (; context_die; context_die = context_die->die_parent)
7900 if (context_die->die_tag == DW_TAG_inlined_subroutine
7901 || context_die->die_tag == DW_TAG_subprogram)
7906 /* Returns nonzero iff CONTEXT_DIE is a class. */
7908 static inline int class_scope_p PARAMS ((dw_die_ref));
7910 class_scope_p (context_die)
7911 dw_die_ref context_die;
7914 && (context_die->die_tag == DW_TAG_structure_type
7915 || context_die->die_tag == DW_TAG_union_type));
7918 /* Many forms of DIEs require a "type description" attribute. This
7919 routine locates the proper "type descriptor" die for the type given
7920 by 'type', and adds an DW_AT_type attribute below the given die. */
7923 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
7924 register dw_die_ref object_die;
7926 register int decl_const;
7927 register int decl_volatile;
7928 register dw_die_ref context_die;
7930 register enum tree_code code = TREE_CODE (type);
7931 register dw_die_ref type_die = NULL;
7933 /* ??? If this type is an unnamed subrange type of an integral or
7934 floating-point type, use the inner type. This is because we have no
7935 support for unnamed types in base_type_die. This can happen if this is
7936 an Ada subrange type. Correct solution is emit a subrange type die. */
7937 if ((code == INTEGER_TYPE || code == REAL_TYPE)
7938 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
7939 type = TREE_TYPE (type), code = TREE_CODE (type);
7941 if (code == ERROR_MARK)
7944 /* Handle a special case. For functions whose return type is void, we
7945 generate *no* type attribute. (Note that no object may have type
7946 `void', so this only applies to function return types). */
7947 if (code == VOID_TYPE)
7950 type_die = modified_type_die (type,
7951 decl_const || TYPE_READONLY (type),
7952 decl_volatile || TYPE_VOLATILE (type),
7954 if (type_die != NULL)
7955 add_AT_die_ref (object_die, DW_AT_type, type_die);
7958 /* Given a tree pointer to a struct, class, union, or enum type node, return
7959 a pointer to the (string) tag name for the given type, or zero if the type
7960 was declared without a tag. */
7966 register const char *name = 0;
7968 if (TYPE_NAME (type) != 0)
7970 register tree t = 0;
7972 /* Find the IDENTIFIER_NODE for the type name. */
7973 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7974 t = TYPE_NAME (type);
7976 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7977 a TYPE_DECL node, regardless of whether or not a `typedef' was
7979 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7980 && ! DECL_IGNORED_P (TYPE_NAME (type)))
7981 t = DECL_NAME (TYPE_NAME (type));
7983 /* Now get the name as a string, or invent one. */
7985 name = IDENTIFIER_POINTER (t);
7988 return (name == 0 || *name == '\0') ? 0 : name;
7991 /* Return the type associated with a data member, make a special check
7992 for bit field types. */
7995 member_declared_type (member)
7996 register tree member;
7998 return (DECL_BIT_FIELD_TYPE (member)
7999 ? DECL_BIT_FIELD_TYPE (member)
8000 : TREE_TYPE (member));
8003 /* Get the decl's label, as described by its RTL. This may be different
8004 from the DECL_NAME name used in the source file. */
8008 decl_start_label (decl)
8013 x = DECL_RTL (decl);
8014 if (GET_CODE (x) != MEM)
8018 if (GET_CODE (x) != SYMBOL_REF)
8021 fnname = XSTR (x, 0);
8026 /* These routines generate the internal representation of the DIE's for
8027 the compilation unit. Debugging information is collected by walking
8028 the declaration trees passed in from dwarf2out_decl(). */
8031 gen_array_type_die (type, context_die)
8033 register dw_die_ref context_die;
8035 register dw_die_ref scope_die = scope_die_for (type, context_die);
8036 register dw_die_ref array_die;
8037 register tree element_type;
8039 /* ??? The SGI dwarf reader fails for array of array of enum types unless
8040 the inner array type comes before the outer array type. Thus we must
8041 call gen_type_die before we call new_die. See below also. */
8042 #ifdef MIPS_DEBUGGING_INFO
8043 gen_type_die (TREE_TYPE (type), context_die);
8046 array_die = new_die (DW_TAG_array_type, scope_die);
8049 /* We default the array ordering. SDB will probably do
8050 the right things even if DW_AT_ordering is not present. It's not even
8051 an issue until we start to get into multidimensional arrays anyway. If
8052 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
8053 then we'll have to put the DW_AT_ordering attribute back in. (But if
8054 and when we find out that we need to put these in, we will only do so
8055 for multidimensional arrays. */
8056 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
8059 #ifdef MIPS_DEBUGGING_INFO
8060 /* The SGI compilers handle arrays of unknown bound by setting
8061 AT_declaration and not emitting any subrange DIEs. */
8062 if (! TYPE_DOMAIN (type))
8063 add_AT_unsigned (array_die, DW_AT_declaration, 1);
8066 add_subscript_info (array_die, type);
8068 add_name_attribute (array_die, type_tag (type));
8069 equate_type_number_to_die (type, array_die);
8071 /* Add representation of the type of the elements of this array type. */
8072 element_type = TREE_TYPE (type);
8074 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8075 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8076 We work around this by disabling this feature. See also
8077 add_subscript_info. */
8078 #ifndef MIPS_DEBUGGING_INFO
8079 while (TREE_CODE (element_type) == ARRAY_TYPE)
8080 element_type = TREE_TYPE (element_type);
8082 gen_type_die (element_type, context_die);
8085 add_type_attribute (array_die, element_type, 0, 0, context_die);
8089 gen_set_type_die (type, context_die)
8091 register dw_die_ref context_die;
8093 register dw_die_ref type_die
8094 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
8096 equate_type_number_to_die (type, type_die);
8097 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
8102 gen_entry_point_die (decl, context_die)
8104 register dw_die_ref context_die;
8106 register tree origin = decl_ultimate_origin (decl);
8107 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
8109 add_abstract_origin_attribute (decl_die, origin);
8112 add_name_and_src_coords_attributes (decl_die, decl);
8113 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
8117 if (DECL_ABSTRACT (decl))
8118 equate_decl_number_to_die (decl, decl_die);
8120 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
8124 /* Remember a type in the incomplete_types_list. */
8127 add_incomplete_type (type)
8130 if (incomplete_types == incomplete_types_allocated)
8132 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
8133 incomplete_types_list
8134 = (tree *) xrealloc (incomplete_types_list,
8135 sizeof (tree) * incomplete_types_allocated);
8138 incomplete_types_list[incomplete_types++] = type;
8141 /* Walk through the list of incomplete types again, trying once more to
8142 emit full debugging info for them. */
8145 retry_incomplete_types ()
8149 while (incomplete_types)
8152 type = incomplete_types_list[incomplete_types];
8153 gen_type_die (type, comp_unit_die);
8157 /* Generate a DIE to represent an inlined instance of an enumeration type. */
8160 gen_inlined_enumeration_type_die (type, context_die)
8162 register dw_die_ref context_die;
8164 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
8166 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8167 be incomplete and such types are not marked. */
8168 add_abstract_origin_attribute (type_die, type);
8171 /* Generate a DIE to represent an inlined instance of a structure type. */
8174 gen_inlined_structure_type_die (type, context_die)
8176 register dw_die_ref context_die;
8178 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
8180 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8181 be incomplete and such types are not marked. */
8182 add_abstract_origin_attribute (type_die, type);
8185 /* Generate a DIE to represent an inlined instance of a union type. */
8188 gen_inlined_union_type_die (type, context_die)
8190 register dw_die_ref context_die;
8192 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
8194 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8195 be incomplete and such types are not marked. */
8196 add_abstract_origin_attribute (type_die, type);
8199 /* Generate a DIE to represent an enumeration type. Note that these DIEs
8200 include all of the information about the enumeration values also. Each
8201 enumerated type name/value is listed as a child of the enumerated type
8205 gen_enumeration_type_die (type, context_die)
8207 register dw_die_ref context_die;
8209 register dw_die_ref type_die = lookup_type_die (type);
8211 if (type_die == NULL)
8213 type_die = new_die (DW_TAG_enumeration_type,
8214 scope_die_for (type, context_die));
8215 equate_type_number_to_die (type, type_die);
8216 add_name_attribute (type_die, type_tag (type));
8218 else if (! TYPE_SIZE (type))
8221 remove_AT (type_die, DW_AT_declaration);
8223 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
8224 given enum type is incomplete, do not generate the DW_AT_byte_size
8225 attribute or the DW_AT_element_list attribute. */
8226 if (TYPE_SIZE (type))
8230 TREE_ASM_WRITTEN (type) = 1;
8231 add_byte_size_attribute (type_die, type);
8232 if (TYPE_STUB_DECL (type) != NULL_TREE)
8233 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8235 /* If the first reference to this type was as the return type of an
8236 inline function, then it may not have a parent. Fix this now. */
8237 if (type_die->die_parent == NULL)
8238 add_child_die (scope_die_for (type, context_die), type_die);
8240 for (link = TYPE_FIELDS (type);
8241 link != NULL; link = TREE_CHAIN (link))
8243 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
8245 add_name_attribute (enum_die,
8246 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
8248 if (host_integerp (TREE_VALUE (link), 0))
8250 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
8251 add_AT_int (enum_die, DW_AT_const_value,
8252 tree_low_cst (TREE_VALUE (link), 0));
8254 add_AT_unsigned (enum_die, DW_AT_const_value,
8255 tree_low_cst (TREE_VALUE (link), 0));
8260 add_AT_flag (type_die, DW_AT_declaration, 1);
8264 /* Generate a DIE to represent either a real live formal parameter decl or to
8265 represent just the type of some formal parameter position in some function
8268 Note that this routine is a bit unusual because its argument may be a
8269 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
8270 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
8271 node. If it's the former then this function is being called to output a
8272 DIE to represent a formal parameter object (or some inlining thereof). If
8273 it's the latter, then this function is only being called to output a
8274 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
8275 argument type of some subprogram type. */
8278 gen_formal_parameter_die (node, context_die)
8280 register dw_die_ref context_die;
8282 register dw_die_ref parm_die
8283 = new_die (DW_TAG_formal_parameter, context_die);
8284 register tree origin;
8286 switch (TREE_CODE_CLASS (TREE_CODE (node)))
8289 origin = decl_ultimate_origin (node);
8291 add_abstract_origin_attribute (parm_die, origin);
8294 add_name_and_src_coords_attributes (parm_die, node);
8295 add_type_attribute (parm_die, TREE_TYPE (node),
8296 TREE_READONLY (node),
8297 TREE_THIS_VOLATILE (node),
8299 if (DECL_ARTIFICIAL (node))
8300 add_AT_flag (parm_die, DW_AT_artificial, 1);
8303 equate_decl_number_to_die (node, parm_die);
8304 if (! DECL_ABSTRACT (node))
8305 add_location_or_const_value_attribute (parm_die, node);
8310 /* We were called with some kind of a ..._TYPE node. */
8311 add_type_attribute (parm_die, node, 0, 0, context_die);
8321 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
8322 at the end of an (ANSI prototyped) formal parameters list. */
8325 gen_unspecified_parameters_die (decl_or_type, context_die)
8326 register tree decl_or_type ATTRIBUTE_UNUSED;
8327 register dw_die_ref context_die;
8329 new_die (DW_TAG_unspecified_parameters, context_die);
8332 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
8333 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
8334 parameters as specified in some function type specification (except for
8335 those which appear as part of a function *definition*). */
8338 gen_formal_types_die (function_or_method_type, context_die)
8339 register tree function_or_method_type;
8340 register dw_die_ref context_die;
8343 register tree formal_type = NULL;
8344 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
8347 /* In the case where we are generating a formal types list for a C++
8348 non-static member function type, skip over the first thing on the
8349 TYPE_ARG_TYPES list because it only represents the type of the hidden
8350 `this pointer'. The debugger should be able to figure out (without
8351 being explicitly told) that this non-static member function type takes a
8352 `this pointer' and should be able to figure what the type of that hidden
8353 parameter is from the DW_AT_member attribute of the parent
8354 DW_TAG_subroutine_type DIE. */
8355 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
8356 first_parm_type = TREE_CHAIN (first_parm_type);
8359 /* Make our first pass over the list of formal parameter types and output a
8360 DW_TAG_formal_parameter DIE for each one. */
8361 for (link = first_parm_type; link; link = TREE_CHAIN (link))
8363 register dw_die_ref parm_die;
8365 formal_type = TREE_VALUE (link);
8366 if (formal_type == void_type_node)
8369 /* Output a (nameless) DIE to represent the formal parameter itself. */
8370 parm_die = gen_formal_parameter_die (formal_type, context_die);
8371 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8372 && link == first_parm_type)
8373 add_AT_flag (parm_die, DW_AT_artificial, 1);
8376 /* If this function type has an ellipsis, add a
8377 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8378 if (formal_type != void_type_node)
8379 gen_unspecified_parameters_die (function_or_method_type, context_die);
8381 /* Make our second (and final) pass over the list of formal parameter types
8382 and output DIEs to represent those types (as necessary). */
8383 for (link = TYPE_ARG_TYPES (function_or_method_type);
8385 link = TREE_CHAIN (link))
8387 formal_type = TREE_VALUE (link);
8388 if (formal_type == void_type_node)
8391 gen_type_die (formal_type, context_die);
8395 /* We want to generate the DIE for TYPE so that we can generate the
8396 die for MEMBER, which has been defined; we will need to refer back
8397 to the member declaration nested within TYPE. If we're trying to
8398 generate minimal debug info for TYPE, processing TYPE won't do the
8399 trick; we need to attach the member declaration by hand. */
8402 gen_type_die_for_member (type, member, context_die)
8404 dw_die_ref context_die;
8406 gen_type_die (type, context_die);
8408 /* If we're trying to avoid duplicate debug info, we may not have
8409 emitted the member decl for this function. Emit it now. */
8410 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
8411 && ! lookup_decl_die (member))
8413 if (decl_ultimate_origin (member))
8416 push_decl_scope (type);
8417 if (TREE_CODE (member) == FUNCTION_DECL)
8418 gen_subprogram_die (member, lookup_type_die (type));
8420 gen_variable_die (member, lookup_type_die (type));
8425 /* Generate the DWARF2 info for the "abstract" instance
8426 of a function which we may later generate inlined and/or
8427 out-of-line instances of. */
8430 gen_abstract_function (decl)
8433 register dw_die_ref old_die = lookup_decl_die (decl);
8436 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
8437 /* We've already generated the abstract instance. */
8440 save_fn = current_function_decl;
8441 current_function_decl = decl;
8443 set_decl_abstract_flags (decl, 1);
8444 dwarf2out_decl (decl);
8445 set_decl_abstract_flags (decl, 0);
8447 current_function_decl = save_fn;
8450 /* Generate a DIE to represent a declared function (either file-scope or
8454 gen_subprogram_die (decl, context_die)
8456 register dw_die_ref context_die;
8458 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
8459 register tree origin = decl_ultimate_origin (decl);
8460 register dw_die_ref subr_die;
8461 register rtx fp_reg;
8462 register tree fn_arg_types;
8463 register tree outer_scope;
8464 register dw_die_ref old_die = lookup_decl_die (decl);
8465 register int declaration = (current_function_decl != decl
8466 || class_scope_p (context_die));
8468 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
8469 be true, if we started to generate the abstract instance of an inline,
8470 decided to output its containing class, and proceeded to emit the
8471 declaration of the inline from the member list for the class. In that
8472 case, `declaration' takes priority; we'll get back to the abstract
8473 instance when we're done with the class. */
8475 /* The class-scope declaration DIE must be the primary DIE. */
8476 if (origin && declaration && class_scope_p (context_die))
8485 if (declaration && ! local_scope_p (context_die))
8488 /* Fixup die_parent for the abstract instance of a nested
8490 if (old_die && old_die->die_parent == NULL)
8491 add_child_die (context_die, old_die);
8493 subr_die = new_die (DW_TAG_subprogram, context_die);
8494 add_abstract_origin_attribute (subr_die, origin);
8496 else if (old_die && DECL_ABSTRACT (decl)
8497 && get_AT_unsigned (old_die, DW_AT_inline))
8499 /* This must be a redefinition of an extern inline function.
8500 We can just reuse the old die here. */
8503 /* Clear out the inlined attribute and parm types. */
8504 remove_AT (subr_die, DW_AT_inline);
8505 remove_children (subr_die);
8509 register unsigned file_index
8510 = lookup_filename (DECL_SOURCE_FILE (decl));
8512 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
8514 /* ??? This can happen if there is a bug in the program, for
8515 instance, if it has duplicate function definitions. Ideally,
8516 we should detect this case and ignore it. For now, if we have
8517 already reported an error, any error at all, then assume that
8518 we got here because of a input error, not a dwarf2 bug. */
8524 /* If the definition comes from the same place as the declaration,
8525 maybe use the old DIE. We always want the DIE for this function
8526 that has the *_pc attributes to be under comp_unit_die so the
8527 debugger can find it. For inlines, that is the concrete instance,
8528 so we can use the old DIE here. For non-inline methods, we want a
8529 specification DIE at toplevel, so we need a new DIE. For local
8530 class methods, this doesn't apply; we just use the old DIE. */
8531 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
8532 || context_die == NULL)
8533 && (DECL_ARTIFICIAL (decl)
8534 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
8535 && (get_AT_unsigned (old_die, DW_AT_decl_line)
8536 == (unsigned)DECL_SOURCE_LINE (decl)))))
8540 /* Clear out the declaration attribute and the parm types. */
8541 remove_AT (subr_die, DW_AT_declaration);
8542 remove_children (subr_die);
8546 subr_die = new_die (DW_TAG_subprogram, context_die);
8547 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
8548 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8549 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
8550 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8551 != (unsigned)DECL_SOURCE_LINE (decl))
8553 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8558 subr_die = new_die (DW_TAG_subprogram, context_die);
8560 if (TREE_PUBLIC (decl))
8561 add_AT_flag (subr_die, DW_AT_external, 1);
8563 add_name_and_src_coords_attributes (subr_die, decl);
8564 if (debug_info_level > DINFO_LEVEL_TERSE)
8566 register tree type = TREE_TYPE (decl);
8568 add_prototyped_attribute (subr_die, type);
8569 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
8572 add_pure_or_virtual_attribute (subr_die, decl);
8573 if (DECL_ARTIFICIAL (decl))
8574 add_AT_flag (subr_die, DW_AT_artificial, 1);
8575 if (TREE_PROTECTED (decl))
8576 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
8577 else if (TREE_PRIVATE (decl))
8578 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
8584 add_AT_flag (subr_die, DW_AT_declaration, 1);
8586 /* The first time we see a member function, it is in the context of
8587 the class to which it belongs. We make sure of this by emitting
8588 the class first. The next time is the definition, which is
8589 handled above. The two may come from the same source text. */
8590 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
8591 equate_decl_number_to_die (decl, subr_die);
8593 else if (DECL_ABSTRACT (decl))
8595 if (DECL_INLINE (decl) && !flag_no_inline)
8597 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
8598 inline functions, but not for extern inline functions.
8599 We can't get this completely correct because information
8600 about whether the function was declared inline is not
8602 if (DECL_DEFER_OUTPUT (decl))
8603 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
8605 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
8608 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
8610 equate_decl_number_to_die (decl, subr_die);
8612 else if (!DECL_EXTERNAL (decl))
8614 if (origin == NULL_TREE)
8615 equate_decl_number_to_die (decl, subr_die);
8617 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
8618 current_funcdef_number);
8619 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
8620 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
8621 current_funcdef_number);
8622 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
8624 add_pubname (decl, subr_die);
8625 add_arange (decl, subr_die);
8627 #ifdef MIPS_DEBUGGING_INFO
8628 /* Add a reference to the FDE for this routine. */
8629 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
8632 /* Define the "frame base" location for this routine. We use the
8633 frame pointer or stack pointer registers, since the RTL for local
8634 variables is relative to one of them. */
8636 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
8637 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
8640 /* ??? This fails for nested inline functions, because context_display
8641 is not part of the state saved/restored for inline functions. */
8642 if (current_function_needs_context)
8643 add_AT_location_description (subr_die, DW_AT_static_link,
8644 lookup_static_chain (decl));
8648 /* Now output descriptions of the arguments for this function. This gets
8649 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8650 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8651 `...' at the end of the formal parameter list. In order to find out if
8652 there was a trailing ellipsis or not, we must instead look at the type
8653 associated with the FUNCTION_DECL. This will be a node of type
8654 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8655 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8656 an ellipsis at the end. */
8658 /* In the case where we are describing a mere function declaration, all we
8659 need to do here (and all we *can* do here) is to describe the *types* of
8660 its formal parameters. */
8661 if (debug_info_level <= DINFO_LEVEL_TERSE)
8663 else if (declaration)
8664 gen_formal_types_die (TREE_TYPE (decl), subr_die);
8667 /* Generate DIEs to represent all known formal parameters */
8668 register tree arg_decls = DECL_ARGUMENTS (decl);
8671 /* When generating DIEs, generate the unspecified_parameters DIE
8672 instead if we come across the arg "__builtin_va_alist" */
8673 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
8674 if (TREE_CODE (parm) == PARM_DECL)
8676 if (DECL_NAME (parm)
8677 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
8678 "__builtin_va_alist"))
8679 gen_unspecified_parameters_die (parm, subr_die);
8681 gen_decl_die (parm, subr_die);
8684 /* Decide whether we need a unspecified_parameters DIE at the end.
8685 There are 2 more cases to do this for: 1) the ansi ... declaration -
8686 this is detectable when the end of the arg list is not a
8687 void_type_node 2) an unprototyped function declaration (not a
8688 definition). This just means that we have no info about the
8689 parameters at all. */
8690 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
8691 if (fn_arg_types != NULL)
8693 /* this is the prototyped case, check for ... */
8694 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
8695 gen_unspecified_parameters_die (decl, subr_die);
8697 else if (DECL_INITIAL (decl) == NULL_TREE)
8698 gen_unspecified_parameters_die (decl, subr_die);
8701 /* Output Dwarf info for all of the stuff within the body of the function
8702 (if it has one - it may be just a declaration). */
8703 outer_scope = DECL_INITIAL (decl);
8705 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8706 node created to represent a function. This outermost BLOCK actually
8707 represents the outermost binding contour for the function, i.e. the
8708 contour in which the function's formal parameters and labels get
8709 declared. Curiously, it appears that the front end doesn't actually
8710 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8711 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8712 list for the function instead.) The BLOCK_VARS list for the
8713 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8714 the function however, and we output DWARF info for those in
8715 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8716 node representing the function's outermost pair of curly braces, and
8717 any blocks used for the base and member initializers of a C++
8718 constructor function. */
8719 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
8721 current_function_has_inlines = 0;
8722 decls_for_scope (outer_scope, subr_die, 0);
8724 #if 0 && defined (MIPS_DEBUGGING_INFO)
8725 if (current_function_has_inlines)
8727 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
8728 if (! comp_unit_has_inlines)
8730 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
8731 comp_unit_has_inlines = 1;
8738 /* Generate a DIE to represent a declared data object. */
8741 gen_variable_die (decl, context_die)
8743 register dw_die_ref context_die;
8745 register tree origin = decl_ultimate_origin (decl);
8746 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
8748 dw_die_ref old_die = lookup_decl_die (decl);
8749 int declaration = (DECL_EXTERNAL (decl)
8750 || class_scope_p (context_die));
8753 add_abstract_origin_attribute (var_die, origin);
8754 /* Loop unrolling can create multiple blocks that refer to the same
8755 static variable, so we must test for the DW_AT_declaration flag. */
8756 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8757 copy decls and set the DECL_ABSTRACT flag on them instead of
8759 else if (old_die && TREE_STATIC (decl)
8760 && get_AT_flag (old_die, DW_AT_declaration) == 1)
8762 /* This is a definition of a C++ class level static. */
8763 add_AT_die_ref (var_die, DW_AT_specification, old_die);
8764 if (DECL_NAME (decl))
8766 register unsigned file_index
8767 = lookup_filename (DECL_SOURCE_FILE (decl));
8769 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8770 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
8772 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8773 != (unsigned)DECL_SOURCE_LINE (decl))
8775 add_AT_unsigned (var_die, DW_AT_decl_line,
8776 DECL_SOURCE_LINE (decl));
8781 add_name_and_src_coords_attributes (var_die, decl);
8782 add_type_attribute (var_die, TREE_TYPE (decl),
8783 TREE_READONLY (decl),
8784 TREE_THIS_VOLATILE (decl), context_die);
8786 if (TREE_PUBLIC (decl))
8787 add_AT_flag (var_die, DW_AT_external, 1);
8789 if (DECL_ARTIFICIAL (decl))
8790 add_AT_flag (var_die, DW_AT_artificial, 1);
8792 if (TREE_PROTECTED (decl))
8793 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
8795 else if (TREE_PRIVATE (decl))
8796 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
8800 add_AT_flag (var_die, DW_AT_declaration, 1);
8802 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
8803 equate_decl_number_to_die (decl, var_die);
8805 if (! declaration && ! DECL_ABSTRACT (decl))
8807 add_location_or_const_value_attribute (var_die, decl);
8808 add_pubname (decl, var_die);
8812 /* Generate a DIE to represent a label identifier. */
8815 gen_label_die (decl, context_die)
8817 register dw_die_ref context_die;
8819 register tree origin = decl_ultimate_origin (decl);
8820 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
8822 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8823 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
8826 add_abstract_origin_attribute (lbl_die, origin);
8828 add_name_and_src_coords_attributes (lbl_die, decl);
8830 if (DECL_ABSTRACT (decl))
8831 equate_decl_number_to_die (decl, lbl_die);
8834 insn = DECL_RTL (decl);
8836 /* Deleted labels are programmer specified labels which have been
8837 eliminated because of various optimisations. We still emit them
8838 here so that it is possible to put breakpoints on them. */
8839 if (GET_CODE (insn) == CODE_LABEL
8840 || ((GET_CODE (insn) == NOTE
8841 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
8843 /* When optimization is enabled (via -O) some parts of the compiler
8844 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8845 represent source-level labels which were explicitly declared by
8846 the user. This really shouldn't be happening though, so catch
8847 it if it ever does happen. */
8848 if (INSN_DELETED_P (insn))
8851 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
8852 ASM_GENERATE_INTERNAL_LABEL (label, label2,
8853 (unsigned) INSN_UID (insn));
8854 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
8859 /* Generate a DIE for a lexical block. */
8862 gen_lexical_block_die (stmt, context_die, depth)
8864 register dw_die_ref context_die;
8867 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
8868 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8870 if (! BLOCK_ABSTRACT (stmt))
8872 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8873 BLOCK_NUMBER (stmt));
8874 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
8875 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
8876 BLOCK_NUMBER (stmt));
8877 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
8880 decls_for_scope (stmt, stmt_die, depth);
8883 /* Generate a DIE for an inlined subprogram. */
8886 gen_inlined_subroutine_die (stmt, context_die, depth)
8888 register dw_die_ref context_die;
8891 if (! BLOCK_ABSTRACT (stmt))
8893 register dw_die_ref subr_die
8894 = new_die (DW_TAG_inlined_subroutine, context_die);
8895 register tree decl = block_ultimate_origin (stmt);
8896 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8898 /* Emit info for the abstract instance first, if we haven't yet. */
8899 gen_abstract_function (decl);
8901 add_abstract_origin_attribute (subr_die, decl);
8902 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8903 BLOCK_NUMBER (stmt));
8904 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
8905 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
8906 BLOCK_NUMBER (stmt));
8907 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
8908 decls_for_scope (stmt, subr_die, depth);
8909 current_function_has_inlines = 1;
8913 /* Generate a DIE for a field in a record, or structure. */
8916 gen_field_die (decl, context_die)
8918 register dw_die_ref context_die;
8920 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
8922 add_name_and_src_coords_attributes (decl_die, decl);
8923 add_type_attribute (decl_die, member_declared_type (decl),
8924 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
8927 /* If this is a bit field... */
8928 if (DECL_BIT_FIELD_TYPE (decl))
8930 add_byte_size_attribute (decl_die, decl);
8931 add_bit_size_attribute (decl_die, decl);
8932 add_bit_offset_attribute (decl_die, decl);
8935 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
8936 add_data_member_location_attribute (decl_die, decl);
8938 if (DECL_ARTIFICIAL (decl))
8939 add_AT_flag (decl_die, DW_AT_artificial, 1);
8941 if (TREE_PROTECTED (decl))
8942 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
8944 else if (TREE_PRIVATE (decl))
8945 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
8949 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8950 Use modified_type_die instead.
8951 We keep this code here just in case these types of DIEs may be needed to
8952 represent certain things in other languages (e.g. Pascal) someday. */
8954 gen_pointer_type_die (type, context_die)
8956 register dw_die_ref context_die;
8958 register dw_die_ref ptr_die
8959 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
8961 equate_type_number_to_die (type, ptr_die);
8962 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8963 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8966 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8967 Use modified_type_die instead.
8968 We keep this code here just in case these types of DIEs may be needed to
8969 represent certain things in other languages (e.g. Pascal) someday. */
8971 gen_reference_type_die (type, context_die)
8973 register dw_die_ref context_die;
8975 register dw_die_ref ref_die
8976 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
8978 equate_type_number_to_die (type, ref_die);
8979 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
8980 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8984 /* Generate a DIE for a pointer to a member type. */
8986 gen_ptr_to_mbr_type_die (type, context_die)
8988 register dw_die_ref context_die;
8990 register dw_die_ref ptr_die
8991 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8993 equate_type_number_to_die (type, ptr_die);
8994 add_AT_die_ref (ptr_die, DW_AT_containing_type,
8995 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
8996 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8999 /* Generate the DIE for the compilation unit. */
9002 gen_compile_unit_die (filename)
9003 register const char *filename;
9005 register dw_die_ref die;
9007 const char *wd = getpwd ();
9010 die = new_die (DW_TAG_compile_unit, NULL);
9011 add_name_attribute (die, filename);
9013 if (wd != NULL && filename[0] != DIR_SEPARATOR)
9014 add_AT_string (die, DW_AT_comp_dir, wd);
9016 sprintf (producer, "%s %s", language_string, version_string);
9018 #ifdef MIPS_DEBUGGING_INFO
9019 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
9020 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
9021 not appear in the producer string, the debugger reaches the conclusion
9022 that the object file is stripped and has no debugging information.
9023 To get the MIPS/SGI debugger to believe that there is debugging
9024 information in the object file, we add a -g to the producer string. */
9025 if (debug_info_level > DINFO_LEVEL_TERSE)
9026 strcat (producer, " -g");
9029 add_AT_string (die, DW_AT_producer, producer);
9031 if (strcmp (language_string, "GNU C++") == 0)
9032 language = DW_LANG_C_plus_plus;
9033 else if (strcmp (language_string, "GNU Ada") == 0)
9034 language = DW_LANG_Ada83;
9035 else if (strcmp (language_string, "GNU F77") == 0)
9036 language = DW_LANG_Fortran77;
9037 else if (strcmp (language_string, "GNU Pascal") == 0)
9038 language = DW_LANG_Pascal83;
9039 else if (flag_traditional)
9040 language = DW_LANG_C;
9042 language = DW_LANG_C89;
9044 add_AT_unsigned (die, DW_AT_language, language);
9049 /* Generate a DIE for a string type. */
9052 gen_string_type_die (type, context_die)
9054 register dw_die_ref context_die;
9056 register dw_die_ref type_die
9057 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
9059 equate_type_number_to_die (type, type_die);
9061 /* Fudge the string length attribute for now. */
9063 /* TODO: add string length info.
9064 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
9065 bound_representation (upper_bound, 0, 'u'); */
9068 /* Generate the DIE for a base class. */
9071 gen_inheritance_die (binfo, context_die)
9072 register tree binfo;
9073 register dw_die_ref context_die;
9075 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
9077 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
9078 add_data_member_location_attribute (die, binfo);
9080 if (TREE_VIA_VIRTUAL (binfo))
9081 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9082 if (TREE_VIA_PUBLIC (binfo))
9083 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
9084 else if (TREE_VIA_PROTECTED (binfo))
9085 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
9088 /* Generate a DIE for a class member. */
9091 gen_member_die (type, context_die)
9093 register dw_die_ref context_die;
9095 register tree member;
9098 /* If this is not an incomplete type, output descriptions of each of its
9099 members. Note that as we output the DIEs necessary to represent the
9100 members of this record or union type, we will also be trying to output
9101 DIEs to represent the *types* of those members. However the `type'
9102 function (above) will specifically avoid generating type DIEs for member
9103 types *within* the list of member DIEs for this (containing) type execpt
9104 for those types (of members) which are explicitly marked as also being
9105 members of this (containing) type themselves. The g++ front- end can
9106 force any given type to be treated as a member of some other
9107 (containing) type by setting the TYPE_CONTEXT of the given (member) type
9108 to point to the TREE node representing the appropriate (containing)
9111 /* First output info about the base classes. */
9112 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
9114 register tree bases = TYPE_BINFO_BASETYPES (type);
9115 register int n_bases = TREE_VEC_LENGTH (bases);
9118 for (i = 0; i < n_bases; i++)
9119 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
9122 /* Now output info about the data members and type members. */
9123 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
9125 /* If we thought we were generating minimal debug info for TYPE
9126 and then changed our minds, some of the member declarations
9127 may have already been defined. Don't define them again, but
9128 do put them in the right order. */
9130 child = lookup_decl_die (member);
9132 splice_child_die (context_die, child);
9134 gen_decl_die (member, context_die);
9137 /* Now output info about the function members (if any). */
9138 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
9140 child = lookup_decl_die (member);
9142 splice_child_die (context_die, child);
9144 gen_decl_die (member, context_die);
9148 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
9149 is set, we pretend that the type was never defined, so we only get the
9150 member DIEs needed by later specification DIEs. */
9153 gen_struct_or_union_type_die (type, context_die)
9155 register dw_die_ref context_die;
9157 register dw_die_ref type_die = lookup_type_die (type);
9158 register dw_die_ref scope_die = 0;
9159 register int nested = 0;
9160 int complete = (TYPE_SIZE (type)
9161 && (! TYPE_STUB_DECL (type)
9162 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
9164 if (type_die && ! complete)
9167 if (TYPE_CONTEXT (type) != NULL_TREE
9168 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
9171 scope_die = scope_die_for (type, context_die);
9173 if (! type_die || (nested && scope_die == comp_unit_die))
9174 /* First occurrence of type or toplevel definition of nested class. */
9176 register dw_die_ref old_die = type_die;
9178 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
9179 ? DW_TAG_structure_type : DW_TAG_union_type,
9181 equate_type_number_to_die (type, type_die);
9182 add_name_attribute (type_die, type_tag (type));
9184 add_AT_die_ref (type_die, DW_AT_specification, old_die);
9187 remove_AT (type_die, DW_AT_declaration);
9189 /* If this type has been completed, then give it a byte_size attribute and
9190 then give a list of members. */
9193 /* Prevent infinite recursion in cases where the type of some member of
9194 this type is expressed in terms of this type itself. */
9195 TREE_ASM_WRITTEN (type) = 1;
9196 add_byte_size_attribute (type_die, type);
9197 if (TYPE_STUB_DECL (type) != NULL_TREE)
9198 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9200 /* If the first reference to this type was as the return type of an
9201 inline function, then it may not have a parent. Fix this now. */
9202 if (type_die->die_parent == NULL)
9203 add_child_die (scope_die, type_die);
9205 push_decl_scope (type);
9206 gen_member_die (type, type_die);
9209 /* GNU extension: Record what type our vtable lives in. */
9210 if (TYPE_VFIELD (type))
9212 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
9214 gen_type_die (vtype, context_die);
9215 add_AT_die_ref (type_die, DW_AT_containing_type,
9216 lookup_type_die (vtype));
9221 add_AT_flag (type_die, DW_AT_declaration, 1);
9223 /* We don't need to do this for function-local types. */
9224 if (! decl_function_context (TYPE_STUB_DECL (type)))
9225 add_incomplete_type (type);
9229 /* Generate a DIE for a subroutine _type_. */
9232 gen_subroutine_type_die (type, context_die)
9234 register dw_die_ref context_die;
9236 register tree return_type = TREE_TYPE (type);
9237 register dw_die_ref subr_die
9238 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
9240 equate_type_number_to_die (type, subr_die);
9241 add_prototyped_attribute (subr_die, type);
9242 add_type_attribute (subr_die, return_type, 0, 0, context_die);
9243 gen_formal_types_die (type, subr_die);
9246 /* Generate a DIE for a type definition */
9249 gen_typedef_die (decl, context_die)
9251 register dw_die_ref context_die;
9253 register dw_die_ref type_die;
9254 register tree origin;
9256 if (TREE_ASM_WRITTEN (decl))
9258 TREE_ASM_WRITTEN (decl) = 1;
9260 type_die = new_die (DW_TAG_typedef, context_die);
9261 origin = decl_ultimate_origin (decl);
9263 add_abstract_origin_attribute (type_die, origin);
9267 add_name_and_src_coords_attributes (type_die, decl);
9268 if (DECL_ORIGINAL_TYPE (decl))
9270 type = DECL_ORIGINAL_TYPE (decl);
9272 if (type == TREE_TYPE (decl))
9275 equate_type_number_to_die (TREE_TYPE (decl), type_die);
9278 type = TREE_TYPE (decl);
9279 add_type_attribute (type_die, type, TREE_READONLY (decl),
9280 TREE_THIS_VOLATILE (decl), context_die);
9283 if (DECL_ABSTRACT (decl))
9284 equate_decl_number_to_die (decl, type_die);
9287 /* Generate a type description DIE. */
9290 gen_type_die (type, context_die)
9292 register dw_die_ref context_die;
9296 if (type == NULL_TREE || type == error_mark_node)
9299 /* We are going to output a DIE to represent the unqualified version of
9300 this type (i.e. without any const or volatile qualifiers) so get the
9301 main variant (i.e. the unqualified version) of this type now. */
9302 type = type_main_variant (type);
9304 if (TREE_ASM_WRITTEN (type))
9307 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9308 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
9310 TREE_ASM_WRITTEN (type) = 1;
9311 gen_decl_die (TYPE_NAME (type), context_die);
9315 switch (TREE_CODE (type))
9321 case REFERENCE_TYPE:
9322 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
9323 ensures that the gen_type_die recursion will terminate even if the
9324 type is recursive. Recursive types are possible in Ada. */
9325 /* ??? We could perhaps do this for all types before the switch
9327 TREE_ASM_WRITTEN (type) = 1;
9329 /* For these types, all that is required is that we output a DIE (or a
9330 set of DIEs) to represent the "basis" type. */
9331 gen_type_die (TREE_TYPE (type), context_die);
9335 /* This code is used for C++ pointer-to-data-member types.
9336 Output a description of the relevant class type. */
9337 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
9339 /* Output a description of the type of the object pointed to. */
9340 gen_type_die (TREE_TYPE (type), context_die);
9342 /* Now output a DIE to represent this pointer-to-data-member type
9344 gen_ptr_to_mbr_type_die (type, context_die);
9348 gen_type_die (TYPE_DOMAIN (type), context_die);
9349 gen_set_type_die (type, context_die);
9353 gen_type_die (TREE_TYPE (type), context_die);
9354 abort (); /* No way to represent these in Dwarf yet! */
9358 /* Force out return type (in case it wasn't forced out already). */
9359 gen_type_die (TREE_TYPE (type), context_die);
9360 gen_subroutine_type_die (type, context_die);
9364 /* Force out return type (in case it wasn't forced out already). */
9365 gen_type_die (TREE_TYPE (type), context_die);
9366 gen_subroutine_type_die (type, context_die);
9370 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
9372 gen_type_die (TREE_TYPE (type), context_die);
9373 gen_string_type_die (type, context_die);
9376 gen_array_type_die (type, context_die);
9380 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
9386 case QUAL_UNION_TYPE:
9387 /* If this is a nested type whose containing class hasn't been
9388 written out yet, writing it out will cover this one, too.
9389 This does not apply to instantiations of member class templates;
9390 they need to be added to the containing class as they are
9391 generated. FIXME: This hurts the idea of combining type decls
9392 from multiple TUs, since we can't predict what set of template
9393 instantiations we'll get. */
9394 if (TYPE_CONTEXT (type)
9395 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9396 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9398 gen_type_die (TYPE_CONTEXT (type), context_die);
9400 if (TREE_ASM_WRITTEN (type))
9403 /* If that failed, attach ourselves to the stub. */
9404 push_decl_scope (TYPE_CONTEXT (type));
9405 context_die = lookup_type_die (TYPE_CONTEXT (type));
9411 if (TREE_CODE (type) == ENUMERAL_TYPE)
9412 gen_enumeration_type_die (type, context_die);
9414 gen_struct_or_union_type_die (type, context_die);
9419 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9420 it up if it is ever completed. gen_*_type_die will set it for us
9421 when appropriate. */
9430 /* No DIEs needed for fundamental types. */
9434 /* No Dwarf representation currently defined. */
9441 TREE_ASM_WRITTEN (type) = 1;
9444 /* Generate a DIE for a tagged type instantiation. */
9447 gen_tagged_type_instantiation_die (type, context_die)
9449 register dw_die_ref context_die;
9451 if (type == NULL_TREE || type == error_mark_node)
9454 /* We are going to output a DIE to represent the unqualified version of
9455 this type (i.e. without any const or volatile qualifiers) so make sure
9456 that we have the main variant (i.e. the unqualified version) of this
9458 if (type != type_main_variant (type))
9461 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
9462 an instance of an unresolved type. */
9464 switch (TREE_CODE (type))
9470 gen_inlined_enumeration_type_die (type, context_die);
9474 gen_inlined_structure_type_die (type, context_die);
9478 case QUAL_UNION_TYPE:
9479 gen_inlined_union_type_die (type, context_die);
9487 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
9488 things which are local to the given block. */
9491 gen_block_die (stmt, context_die, depth)
9493 register dw_die_ref context_die;
9496 register int must_output_die = 0;
9497 register tree origin;
9499 register enum tree_code origin_code;
9501 /* Ignore blocks never really used to make RTL. */
9503 if (stmt == NULL_TREE || !TREE_USED (stmt)
9504 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
9507 /* Determine the "ultimate origin" of this block. This block may be an
9508 inlined instance of an inlined instance of inline function, so we have
9509 to trace all of the way back through the origin chain to find out what
9510 sort of node actually served as the original seed for the creation of
9511 the current block. */
9512 origin = block_ultimate_origin (stmt);
9513 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
9515 /* Determine if we need to output any Dwarf DIEs at all to represent this
9517 if (origin_code == FUNCTION_DECL)
9518 /* The outer scopes for inlinings *must* always be represented. We
9519 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9520 must_output_die = 1;
9523 /* In the case where the current block represents an inlining of the
9524 "body block" of an inline function, we must *NOT* output any DIE for
9525 this block because we have already output a DIE to represent the
9526 whole inlined function scope and the "body block" of any function
9527 doesn't really represent a different scope according to ANSI C
9528 rules. So we check here to make sure that this block does not
9529 represent a "body block inlining" before trying to set the
9530 `must_output_die' flag. */
9531 if (! is_body_block (origin ? origin : stmt))
9533 /* Determine if this block directly contains any "significant"
9534 local declarations which we will need to output DIEs for. */
9535 if (debug_info_level > DINFO_LEVEL_TERSE)
9536 /* We are not in terse mode so *any* local declaration counts
9537 as being a "significant" one. */
9538 must_output_die = (BLOCK_VARS (stmt) != NULL);
9540 /* We are in terse mode, so only local (nested) function
9541 definitions count as "significant" local declarations. */
9542 for (decl = BLOCK_VARS (stmt);
9543 decl != NULL; decl = TREE_CHAIN (decl))
9544 if (TREE_CODE (decl) == FUNCTION_DECL
9545 && DECL_INITIAL (decl))
9547 must_output_die = 1;
9553 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9554 DIE for any block which contains no significant local declarations at
9555 all. Rather, in such cases we just call `decls_for_scope' so that any
9556 needed Dwarf info for any sub-blocks will get properly generated. Note
9557 that in terse mode, our definition of what constitutes a "significant"
9558 local declaration gets restricted to include only inlined function
9559 instances and local (nested) function definitions. */
9560 if (must_output_die)
9562 if (origin_code == FUNCTION_DECL)
9563 gen_inlined_subroutine_die (stmt, context_die, depth);
9565 gen_lexical_block_die (stmt, context_die, depth);
9568 decls_for_scope (stmt, context_die, depth);
9571 /* Generate all of the decls declared within a given scope and (recursively)
9572 all of its sub-blocks. */
9575 decls_for_scope (stmt, context_die, depth)
9577 register dw_die_ref context_die;
9581 register tree subblocks;
9583 /* Ignore blocks never really used to make RTL. */
9584 if (stmt == NULL_TREE || ! TREE_USED (stmt))
9587 /* Output the DIEs to represent all of the data objects and typedefs
9588 declared directly within this block but not within any nested
9589 sub-blocks. Also, nested function and tag DIEs have been
9590 generated with a parent of NULL; fix that up now. */
9591 for (decl = BLOCK_VARS (stmt);
9592 decl != NULL; decl = TREE_CHAIN (decl))
9594 register dw_die_ref die;
9596 if (TREE_CODE (decl) == FUNCTION_DECL)
9597 die = lookup_decl_die (decl);
9598 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9599 die = lookup_type_die (TREE_TYPE (decl));
9603 if (die != NULL && die->die_parent == NULL)
9604 add_child_die (context_die, die);
9606 gen_decl_die (decl, context_die);
9609 /* Output the DIEs to represent all sub-blocks (and the items declared
9610 therein) of this block. */
9611 for (subblocks = BLOCK_SUBBLOCKS (stmt);
9613 subblocks = BLOCK_CHAIN (subblocks))
9614 gen_block_die (subblocks, context_die, depth + 1);
9617 /* Is this a typedef we can avoid emitting? */
9620 is_redundant_typedef (decl)
9623 if (TYPE_DECL_IS_STUB (decl))
9626 if (DECL_ARTIFICIAL (decl)
9627 && DECL_CONTEXT (decl)
9628 && is_tagged_type (DECL_CONTEXT (decl))
9629 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
9630 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
9631 /* Also ignore the artificial member typedef for the class name. */
9637 /* Generate Dwarf debug information for a decl described by DECL. */
9640 gen_decl_die (decl, context_die)
9642 register dw_die_ref context_die;
9644 register tree origin;
9646 if (TREE_CODE (decl) == ERROR_MARK)
9649 /* If this ..._DECL node is marked to be ignored, then ignore it. */
9650 if (DECL_IGNORED_P (decl))
9653 switch (TREE_CODE (decl))
9656 /* The individual enumerators of an enum type get output when we output
9657 the Dwarf representation of the relevant enum type itself. */
9661 /* Don't output any DIEs to represent mere function declarations,
9662 unless they are class members or explicit block externs. */
9663 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
9664 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
9667 /* If we're emitting an out-of-line copy of an inline function,
9668 emit info for the abstract instance and set up to refer to it. */
9669 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
9670 && ! class_scope_p (context_die)
9671 /* gen_abstract_function won't emit a die if this is just a
9672 declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
9673 that case, because that works only if we have a die. */
9674 && DECL_INITIAL (decl) != NULL_TREE)
9676 gen_abstract_function (decl);
9677 set_decl_origin_self (decl);
9680 if (debug_info_level > DINFO_LEVEL_TERSE)
9682 /* Before we describe the FUNCTION_DECL itself, make sure that we
9683 have described its return type. */
9684 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
9686 /* And its virtual context. */
9687 if (DECL_VINDEX (decl) != NULL_TREE)
9688 gen_type_die (DECL_CONTEXT (decl), context_die);
9690 /* And its containing type. */
9691 origin = decl_class_context (decl);
9692 if (origin != NULL_TREE)
9693 gen_type_die_for_member (origin, decl, context_die);
9696 /* Now output a DIE to represent the function itself. */
9697 gen_subprogram_die (decl, context_die);
9701 /* If we are in terse mode, don't generate any DIEs to represent any
9703 if (debug_info_level <= DINFO_LEVEL_TERSE)
9706 /* In the special case of a TYPE_DECL node representing the
9707 declaration of some type tag, if the given TYPE_DECL is marked as
9708 having been instantiated from some other (original) TYPE_DECL node
9709 (e.g. one which was generated within the original definition of an
9710 inline function) we have to generate a special (abbreviated)
9711 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9713 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
9715 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
9719 if (is_redundant_typedef (decl))
9720 gen_type_die (TREE_TYPE (decl), context_die);
9722 /* Output a DIE to represent the typedef itself. */
9723 gen_typedef_die (decl, context_die);
9727 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9728 gen_label_die (decl, context_die);
9732 /* If we are in terse mode, don't generate any DIEs to represent any
9733 variable declarations or definitions. */
9734 if (debug_info_level <= DINFO_LEVEL_TERSE)
9737 /* Output any DIEs that are needed to specify the type of this data
9739 gen_type_die (TREE_TYPE (decl), context_die);
9741 /* And its containing type. */
9742 origin = decl_class_context (decl);
9743 if (origin != NULL_TREE)
9744 gen_type_die_for_member (origin, decl, context_die);
9746 /* Now output the DIE to represent the data object itself. This gets
9747 complicated because of the possibility that the VAR_DECL really
9748 represents an inlined instance of a formal parameter for an inline
9750 origin = decl_ultimate_origin (decl);
9751 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
9752 gen_formal_parameter_die (decl, context_die);
9754 gen_variable_die (decl, context_die);
9758 /* Ignore the nameless fields that are used to skip bits, but
9759 handle C++ anonymous unions. */
9760 if (DECL_NAME (decl) != NULL_TREE
9761 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
9763 gen_type_die (member_declared_type (decl), context_die);
9764 gen_field_die (decl, context_die);
9769 gen_type_die (TREE_TYPE (decl), context_die);
9770 gen_formal_parameter_die (decl, context_die);
9773 case NAMESPACE_DECL:
9774 /* Ignore for now. */
9782 /* Add Ada "use" clause information for SGI Workshop debugger. */
9785 dwarf2out_add_library_unit_info (filename, context_list)
9786 const char *filename;
9787 const char *context_list;
9789 unsigned int file_index;
9791 if (filename != NULL)
9793 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
9794 tree context_list_decl
9795 = build_decl (LABEL_DECL, get_identifier (context_list),
9798 TREE_PUBLIC (context_list_decl) = TRUE;
9799 add_name_attribute (unit_die, context_list);
9800 file_index = lookup_filename (filename);
9801 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
9802 add_pubname (context_list_decl, unit_die);
9806 /* Write the debugging output for DECL. */
9809 dwarf2out_decl (decl)
9812 register dw_die_ref context_die = comp_unit_die;
9814 if (TREE_CODE (decl) == ERROR_MARK)
9817 /* If this ..._DECL node is marked to be ignored, then ignore it. */
9818 if (DECL_IGNORED_P (decl))
9821 switch (TREE_CODE (decl))
9824 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9825 builtin function. Explicit programmer-supplied declarations of
9826 these same functions should NOT be ignored however. */
9827 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
9830 /* What we would really like to do here is to filter out all mere
9831 file-scope declarations of file-scope functions which are never
9832 referenced later within this translation unit (and keep all of ones
9833 that *are* referenced later on) but we aren't clairvoyant, so we have
9834 no idea which functions will be referenced in the future (i.e. later
9835 on within the current translation unit). So here we just ignore all
9836 file-scope function declarations which are not also definitions. If
9837 and when the debugger needs to know something about these functions,
9838 it will have to hunt around and find the DWARF information associated
9839 with the definition of the function. Note that we can't just check
9840 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9841 definitions and which ones represent mere declarations. We have to
9842 check `DECL_INITIAL' instead. That's because the C front-end
9843 supports some weird semantics for "extern inline" function
9844 definitions. These can get inlined within the current translation
9845 unit (an thus, we need to generate DWARF info for their abstract
9846 instances so that the DWARF info for the concrete inlined instances
9847 can have something to refer to) but the compiler never generates any
9848 out-of-lines instances of such things (despite the fact that they
9849 *are* definitions). The important point is that the C front-end
9850 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9851 to generate DWARF for them anyway. Note that the C++ front-end also
9852 plays some similar games for inline function definitions appearing
9853 within include files which also contain
9854 `#pragma interface' pragmas. */
9855 if (DECL_INITIAL (decl) == NULL_TREE)
9858 /* If we're a nested function, initially use a parent of NULL; if we're
9859 a plain function, this will be fixed up in decls_for_scope. If
9860 we're a method, it will be ignored, since we already have a DIE. */
9861 if (decl_function_context (decl))
9867 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9868 declaration and if the declaration was never even referenced from
9869 within this entire compilation unit. We suppress these DIEs in
9870 order to save space in the .debug section (by eliminating entries
9871 which are probably useless). Note that we must not suppress
9872 block-local extern declarations (whether used or not) because that
9873 would screw-up the debugger's name lookup mechanism and cause it to
9874 miss things which really ought to be in scope at a given point. */
9875 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
9878 /* If we are in terse mode, don't generate any DIEs to represent any
9879 variable declarations or definitions. */
9880 if (debug_info_level <= DINFO_LEVEL_TERSE)
9885 /* Don't emit stubs for types unless they are needed by other DIEs. */
9886 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
9889 /* Don't bother trying to generate any DIEs to represent any of the
9890 normal built-in types for the language we are compiling. */
9891 if (DECL_SOURCE_LINE (decl) == 0)
9893 /* OK, we need to generate one for `bool' so GDB knows what type
9894 comparisons have. */
9895 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
9896 == DW_LANG_C_plus_plus)
9897 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
9898 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
9903 /* If we are in terse mode, don't generate any DIEs for types. */
9904 if (debug_info_level <= DINFO_LEVEL_TERSE)
9907 /* If we're a function-scope tag, initially use a parent of NULL;
9908 this will be fixed up in decls_for_scope. */
9909 if (decl_function_context (decl))
9918 gen_decl_die (decl, context_die);
9921 /* Output a marker (i.e. a label) for the beginning of the generated code for
9925 dwarf2out_begin_block (blocknum)
9926 register unsigned blocknum;
9928 function_section (current_function_decl);
9929 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
9932 /* Output a marker (i.e. a label) for the end of the generated code for a
9936 dwarf2out_end_block (blocknum)
9937 register unsigned blocknum;
9939 function_section (current_function_decl);
9940 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
9943 /* Returns nonzero if it is appropriate not to emit any debugging
9944 information for BLOCK, because it doesn't contain any instructions.
9946 Don't allow this for blocks with nested functions or local classes
9947 as we would end up with orphans, and in the presence of scheduling
9948 we may end up calling them anyway. */
9951 dwarf2out_ignore_block (block)
9955 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
9956 if (TREE_CODE (decl) == FUNCTION_DECL
9957 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
9962 /* Output a marker (i.e. a label) at a point in the assembly code which
9963 corresponds to a given source level label. */
9966 dwarf2out_label (insn)
9969 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9971 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9973 function_section (current_function_decl);
9974 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
9975 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
9976 (unsigned) INSN_UID (insn));
9980 /* Lookup a filename (in the list of filenames that we know about here in
9981 dwarf2out.c) and return its "index". The index of each (known) filename is
9982 just a unique number which is associated with only that one filename.
9983 We need such numbers for the sake of generating labels
9984 (in the .debug_sfnames section) and references to those
9985 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9986 If the filename given as an argument is not found in our current list,
9987 add it to the list and assign it the next available unique index number.
9988 In order to speed up searches, we remember the index of the filename
9989 was looked up last. This handles the majority of all searches. */
9992 lookup_filename (file_name)
9993 const char *file_name;
9995 static unsigned last_file_lookup_index = 0;
9996 register unsigned i;
9998 /* Check to see if the file name that was searched on the previous call
9999 matches this file name. If so, return the index. */
10000 if (last_file_lookup_index != 0)
10001 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
10002 return last_file_lookup_index;
10004 /* Didn't match the previous lookup, search the table */
10005 for (i = 1; i < file_table_in_use; ++i)
10006 if (strcmp (file_name, file_table[i]) == 0)
10008 last_file_lookup_index = i;
10012 /* Prepare to add a new table entry by making sure there is enough space in
10013 the table to do so. If not, expand the current table. */
10014 if (file_table_in_use == file_table_allocated)
10016 file_table_allocated += FILE_TABLE_INCREMENT;
10018 = (char **) xrealloc (file_table,
10019 file_table_allocated * sizeof (char *));
10022 /* Add the new entry to the end of the filename table. */
10023 file_table[file_table_in_use] = xstrdup (file_name);
10024 last_file_lookup_index = file_table_in_use++;
10026 return last_file_lookup_index;
10029 /* Output a label to mark the beginning of a source code line entry
10030 and record information relating to this source line, in
10031 'line_info_table' for later output of the .debug_line section. */
10034 dwarf2out_line (filename, line)
10035 register const char *filename;
10036 register unsigned line;
10038 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10040 function_section (current_function_decl);
10042 if (DWARF2_ASM_LINE_DEBUG_INFO)
10044 static const char *lastfile;
10046 /* Emit the .file and .loc directives understood by GNU as. */
10047 if (lastfile == 0 || strcmp (filename, lastfile))
10050 ggc_add_string_root ((char **) &lastfile, 1);
10052 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
10053 lastfile = filename;
10056 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
10058 /* Indicate that line number info exists. */
10059 ++line_info_table_in_use;
10061 /* Indicate that multiple line number tables exist. */
10062 if (DECL_SECTION_NAME (current_function_decl))
10063 ++separate_line_info_table_in_use;
10065 else if (DECL_SECTION_NAME (current_function_decl))
10067 register dw_separate_line_info_ref line_info;
10068 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
10069 separate_line_info_table_in_use);
10070 if (flag_debug_asm)
10071 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
10072 fputc ('\n', asm_out_file);
10074 /* expand the line info table if necessary */
10075 if (separate_line_info_table_in_use
10076 == separate_line_info_table_allocated)
10078 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10079 separate_line_info_table
10080 = (dw_separate_line_info_ref)
10081 xrealloc (separate_line_info_table,
10082 separate_line_info_table_allocated
10083 * sizeof (dw_separate_line_info_entry));
10086 /* Add the new entry at the end of the line_info_table. */
10088 = &separate_line_info_table[separate_line_info_table_in_use++];
10089 line_info->dw_file_num = lookup_filename (filename);
10090 line_info->dw_line_num = line;
10091 line_info->function = current_funcdef_number;
10095 register dw_line_info_ref line_info;
10097 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
10098 line_info_table_in_use);
10099 if (flag_debug_asm)
10100 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
10101 fputc ('\n', asm_out_file);
10103 /* Expand the line info table if necessary. */
10104 if (line_info_table_in_use == line_info_table_allocated)
10106 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10108 = (dw_line_info_ref)
10109 xrealloc (line_info_table,
10110 (line_info_table_allocated
10111 * sizeof (dw_line_info_entry)));
10114 /* Add the new entry at the end of the line_info_table. */
10115 line_info = &line_info_table[line_info_table_in_use++];
10116 line_info->dw_file_num = lookup_filename (filename);
10117 line_info->dw_line_num = line;
10122 /* Record the beginning of a new source file, for later output
10123 of the .debug_macinfo section. At present, unimplemented. */
10126 dwarf2out_start_source_file (filename)
10127 register const char *filename ATTRIBUTE_UNUSED;
10131 /* Record the end of a source file, for later output
10132 of the .debug_macinfo section. At present, unimplemented. */
10135 dwarf2out_end_source_file ()
10139 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10140 the tail part of the directive line, i.e. the part which is past the
10141 initial whitespace, #, whitespace, directive-name, whitespace part. */
10144 dwarf2out_define (lineno, buffer)
10145 register unsigned lineno ATTRIBUTE_UNUSED;
10146 register const char *buffer ATTRIBUTE_UNUSED;
10148 static int initialized = 0;
10151 dwarf2out_start_source_file (primary_filename);
10156 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10157 the tail part of the directive line, i.e. the part which is past the
10158 initial whitespace, #, whitespace, directive-name, whitespace part. */
10161 dwarf2out_undef (lineno, buffer)
10162 register unsigned lineno ATTRIBUTE_UNUSED;
10163 register const char *buffer ATTRIBUTE_UNUSED;
10167 /* Set up for Dwarf output at the start of compilation. */
10170 dwarf2out_init (asm_out_file, main_input_filename)
10171 register FILE *asm_out_file;
10172 register const char *main_input_filename;
10174 /* Remember the name of the primary input file. */
10175 primary_filename = main_input_filename;
10177 /* Allocate the initial hunk of the file_table. */
10178 file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
10179 file_table_allocated = FILE_TABLE_INCREMENT;
10181 /* Skip the first entry - file numbers begin at 1. */
10182 file_table_in_use = 1;
10184 /* Allocate the initial hunk of the decl_die_table. */
10186 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
10187 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
10188 decl_die_table_in_use = 0;
10190 /* Allocate the initial hunk of the decl_scope_table. */
10192 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
10193 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
10194 decl_scope_depth = 0;
10196 /* Allocate the initial hunk of the abbrev_die_table. */
10198 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
10199 sizeof (dw_die_ref));
10200 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
10201 /* Zero-th entry is allocated, but unused */
10202 abbrev_die_table_in_use = 1;
10204 /* Allocate the initial hunk of the line_info_table. */
10206 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
10207 sizeof (dw_line_info_entry));
10208 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
10209 /* Zero-th entry is allocated, but unused */
10210 line_info_table_in_use = 1;
10212 /* Generate the initial DIE for the .debug section. Note that the (string)
10213 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
10214 will (typically) be a relative pathname and that this pathname should be
10215 taken as being relative to the directory from which the compiler was
10216 invoked when the given (base) source file was compiled. */
10217 comp_unit_die = gen_compile_unit_die (main_input_filename);
10221 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
10222 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
10225 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
10226 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
10227 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
10228 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
10230 strcpy (text_section_label, stripattributes (TEXT_SECTION));
10231 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
10232 DEBUG_INFO_SECTION_LABEL, 0);
10233 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
10234 DEBUG_LINE_SECTION_LABEL, 0);
10236 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
10237 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
10238 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
10240 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
10241 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
10243 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
10244 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
10245 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
10246 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
10249 /* Output stuff that dwarf requires at the end of every file,
10250 and generate the DWARF-2 debugging info. */
10253 dwarf2out_finish ()
10255 limbo_die_node *node, *next_node;
10258 /* Traverse the limbo die list, and add parent/child links. The only
10259 dies without parents that should be here are concrete instances of
10260 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
10261 For concrete instances, we can get the parent die from the abstract
10263 for (node = limbo_die_list; node; node = next_node)
10265 next_node = node->next;
10268 if (die->die_parent == NULL)
10270 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
10272 add_child_die (origin->die_parent, die);
10273 else if (die == comp_unit_die)
10280 limbo_die_list = NULL;
10282 /* Walk through the list of incomplete types again, trying once more to
10283 emit full debugging info for them. */
10284 retry_incomplete_types ();
10286 /* Traverse the DIE's, reverse their lists of attributes and children,
10287 and add add sibling attributes to those DIE's that have children. */
10288 add_sibling_attributes (comp_unit_die);
10290 /* Output a terminator label for the .text section. */
10291 fputc ('\n', asm_out_file);
10292 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
10293 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
10296 /* Output a terminator label for the .data section. */
10297 fputc ('\n', asm_out_file);
10298 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
10299 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
10301 /* Output a terminator label for the .bss section. */
10302 fputc ('\n', asm_out_file);
10303 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
10304 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
10307 /* Output the source line correspondence table. */
10308 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
10310 if (! DWARF2_ASM_LINE_DEBUG_INFO)
10312 fputc ('\n', asm_out_file);
10313 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
10314 output_line_info ();
10317 /* We can only use the low/high_pc attributes if all of the code
10319 if (separate_line_info_table_in_use == 0)
10321 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
10322 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
10325 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
10326 debug_line_section_label);
10329 #if 0 /* unimplemented */
10330 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
10331 add_AT_unsigned (die, DW_AT_macro_info, 0);
10334 /* Output the abbreviation table. */
10335 fputc ('\n', asm_out_file);
10336 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
10337 build_abbrev_table (comp_unit_die);
10338 output_abbrev_section ();
10340 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10341 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
10342 calc_die_sizes (comp_unit_die);
10344 /* Output debugging information. */
10345 fputc ('\n', asm_out_file);
10346 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
10347 output_compilation_unit_header ();
10348 output_die (comp_unit_die);
10350 if (pubname_table_in_use)
10352 /* Output public names table. */
10353 fputc ('\n', asm_out_file);
10354 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
10355 output_pubnames ();
10358 /* We only put functions in the arange table, so don't write it out if
10359 we don't have any. */
10360 if (fde_table_in_use)
10362 /* Output the address range information. */
10363 fputc ('\n', asm_out_file);
10364 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
10368 #endif /* DWARF2_DEBUGGING_INFO */