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 /* We cannot use <assert.h> in GCC source, since that would include
62 GCC's assert.h, which may not be compatible with the host compiler. */
67 # define assert(e) do { if (! (e)) abort (); } while (0)
70 /* Decide whether we want to emit frame unwind information for the current
76 return (write_symbols
== DWARF2_DEBUG
77 #ifdef DWARF2_FRAME_INFO
80 #ifdef DWARF2_UNWIND_INFO
82 || (flag_exceptions
&& ! exceptions_via_longjmp
)
87 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
89 /* How to start an assembler comment. */
90 #ifndef ASM_COMMENT_START
91 #define ASM_COMMENT_START ";#"
94 typedef struct dw_cfi_struct
*dw_cfi_ref
;
95 typedef struct dw_fde_struct
*dw_fde_ref
;
96 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
98 /* Call frames are described using a sequence of Call Frame
99 Information instructions. The register number, offset
100 and address fields are provided as possible operands;
101 their use is selected by the opcode field. */
103 typedef union dw_cfi_oprnd_struct
105 unsigned long dw_cfi_reg_num
;
106 long int dw_cfi_offset
;
111 typedef struct dw_cfi_struct
113 dw_cfi_ref dw_cfi_next
;
114 enum dwarf_call_frame_info dw_cfi_opc
;
115 dw_cfi_oprnd dw_cfi_oprnd1
;
116 dw_cfi_oprnd dw_cfi_oprnd2
;
120 /* All call frame descriptions (FDE's) in the GCC generated DWARF
121 refer to a single Common Information Entry (CIE), defined at
122 the beginning of the .debug_frame section. This used of a single
123 CIE obviates the need to keep track of multiple CIE's
124 in the DWARF generation routines below. */
126 typedef struct dw_fde_struct
129 char *dw_fde_current_label
;
131 dw_cfi_ref dw_fde_cfi
;
136 /* Maximum size (in bytes) of an artificially generated label. */
137 #define MAX_ARTIFICIAL_LABEL_BYTES 30
139 /* Make sure we know the sizes of the various types dwarf can describe. These
140 are only defaults. If the sizes are different for your target, you should
141 override these values by defining the appropriate symbols in your tm.h
144 #ifndef CHAR_TYPE_SIZE
145 #define CHAR_TYPE_SIZE BITS_PER_UNIT
148 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
151 /* The size in bytes of a DWARF field indicating an offset or length
152 relative to a debug info section, specified to be 4 bytes in the DWARF-2
153 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
155 #ifndef DWARF_OFFSET_SIZE
156 #define DWARF_OFFSET_SIZE 4
159 #define DWARF_VERSION 2
161 /* Round SIZE up to the nearest BOUNDARY. */
162 #define DWARF_ROUND(SIZE,BOUNDARY) \
163 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
165 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
166 #ifdef STACK_GROWS_DOWNWARD
167 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
169 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
172 /* A pointer to the base of a table that contains frame description
173 information for each routine. */
174 static dw_fde_ref fde_table
;
176 /* Number of elements currently allocated for fde_table. */
177 static unsigned fde_table_allocated
;
179 /* Number of elements in fde_table currently in use. */
180 static unsigned fde_table_in_use
;
182 /* Size (in elements) of increments by which we may expand the
184 #define FDE_TABLE_INCREMENT 256
186 /* A list of call frame insns for the CIE. */
187 static dw_cfi_ref cie_cfi_head
;
189 /* The number of the current function definition for which debugging
190 information is being generated. These numbers range from 1 up to the
191 maximum number of function definitions contained within the current
192 compilation unit. These numbers are used to create unique label id's
193 unique to each function definition. */
194 static unsigned current_funcdef_number
= 0;
196 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
197 attribute that accelerates the lookup of the FDE associated
198 with the subprogram. This variable holds the table index of the FDE
199 associated with the current function (body) definition. */
200 static unsigned current_funcdef_fde
;
202 /* Forward declarations for functions defined in this file. */
204 static char *stripattributes
PARAMS ((const char *));
205 static const char *dwarf_cfi_name
PARAMS ((unsigned));
206 static dw_cfi_ref new_cfi
PARAMS ((void));
207 static void add_cfi
PARAMS ((dw_cfi_ref
*, dw_cfi_ref
));
208 static unsigned long size_of_uleb128
PARAMS ((unsigned long));
209 static unsigned long size_of_sleb128
PARAMS ((long));
210 static void output_uleb128
PARAMS ((unsigned long));
211 static void output_sleb128
PARAMS ((long));
212 static void add_fde_cfi
PARAMS ((char *, dw_cfi_ref
));
213 static void lookup_cfa_1
PARAMS ((dw_cfi_ref
, unsigned long *,
215 static void lookup_cfa
PARAMS ((unsigned long *, long *));
216 static void reg_save
PARAMS ((char *, unsigned, unsigned,
218 static void initial_return_save
PARAMS ((rtx
));
219 static void output_cfi
PARAMS ((dw_cfi_ref
, dw_fde_ref
));
220 static void output_call_frame_info
PARAMS ((int));
221 static unsigned reg_number
PARAMS ((rtx
));
222 static void dwarf2out_stack_adjust
PARAMS ((rtx
));
223 static void dwarf2out_frame_debug_expr
PARAMS ((rtx
, char *));
225 /* Definitions of defaults for assembler-dependent names of various
226 pseudo-ops and section names.
227 Theses may be overridden in the tm.h file (if necessary) for a particular
230 #ifdef OBJECT_FORMAT_ELF
231 #ifndef UNALIGNED_SHORT_ASM_OP
232 #define UNALIGNED_SHORT_ASM_OP ".2byte"
234 #ifndef UNALIGNED_INT_ASM_OP
235 #define UNALIGNED_INT_ASM_OP ".4byte"
237 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
238 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
240 #endif /* OBJECT_FORMAT_ELF */
243 #define ASM_BYTE_OP ".byte"
246 /* Data and reference forms for relocatable data. */
247 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
248 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
250 /* Pseudo-op for defining a new section. */
251 #ifndef SECTION_ASM_OP
252 #define SECTION_ASM_OP ".section"
255 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
256 print the SECTION_ASM_OP and the section name. The default here works for
257 almost all svr4 assemblers, except for the sparc, where the section name
258 must be enclosed in double quotes. (See sparcv4.h). */
259 #ifndef SECTION_FORMAT
260 #ifdef PUSHSECTION_FORMAT
261 #define SECTION_FORMAT PUSHSECTION_FORMAT
263 #define SECTION_FORMAT "\t%s\t%s\n"
267 #ifndef FRAME_SECTION
268 #define FRAME_SECTION ".debug_frame"
271 #ifndef FUNC_BEGIN_LABEL
272 #define FUNC_BEGIN_LABEL "LFB"
274 #ifndef FUNC_END_LABEL
275 #define FUNC_END_LABEL "LFE"
277 #define CIE_AFTER_SIZE_LABEL "LSCIE"
278 #define CIE_END_LABEL "LECIE"
279 #define CIE_LENGTH_LABEL "LLCIE"
280 #define FDE_AFTER_SIZE_LABEL "LSFDE"
281 #define FDE_END_LABEL "LEFDE"
282 #define FDE_LENGTH_LABEL "LLFDE"
284 /* Definitions of defaults for various types of primitive assembly language
285 output operations. These may be overridden from within the tm.h file,
286 but typically, that is unnecessary. */
288 #ifndef ASM_OUTPUT_SECTION
289 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
290 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
293 #ifndef ASM_OUTPUT_DWARF_DATA1
294 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
295 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
298 #ifndef ASM_OUTPUT_DWARF_DELTA1
299 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
300 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
301 assemble_name (FILE, LABEL1); \
302 fprintf (FILE, "-"); \
303 assemble_name (FILE, LABEL2); \
307 #ifdef UNALIGNED_INT_ASM_OP
309 #ifndef UNALIGNED_OFFSET_ASM_OP
310 #define UNALIGNED_OFFSET_ASM_OP \
311 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
314 #ifndef UNALIGNED_WORD_ASM_OP
315 #define UNALIGNED_WORD_ASM_OP \
316 ((PTR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : \
317 ((PTR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP : UNALIGNED_INT_ASM_OP))
320 #ifndef ASM_OUTPUT_DWARF_DELTA2
321 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
322 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
323 assemble_name (FILE, LABEL1); \
324 fprintf (FILE, "-"); \
325 assemble_name (FILE, LABEL2); \
329 #ifndef ASM_OUTPUT_DWARF_DELTA4
330 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
331 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
332 assemble_name (FILE, LABEL1); \
333 fprintf (FILE, "-"); \
334 assemble_name (FILE, LABEL2); \
338 #ifndef ASM_OUTPUT_DWARF_DELTA
339 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
340 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
341 assemble_name (FILE, LABEL1); \
342 fprintf (FILE, "-"); \
343 assemble_name (FILE, LABEL2); \
347 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
348 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
349 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
350 assemble_name (FILE, LABEL1); \
351 fprintf (FILE, "-"); \
352 assemble_name (FILE, LABEL2); \
356 #ifndef ASM_OUTPUT_DWARF_ADDR
357 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
358 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
359 assemble_name (FILE, LABEL); \
363 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
364 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
366 fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
367 output_addr_const ((FILE), (RTX)); \
371 #ifndef ASM_OUTPUT_DWARF_OFFSET4
372 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
373 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
374 assemble_name (FILE, LABEL); \
378 #ifndef ASM_OUTPUT_DWARF_OFFSET
379 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
380 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
381 assemble_name (FILE, LABEL); \
385 #ifndef ASM_OUTPUT_DWARF_DATA2
386 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
387 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
390 #ifndef ASM_OUTPUT_DWARF_DATA4
391 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
392 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
395 #ifndef ASM_OUTPUT_DWARF_DATA
396 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
397 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
398 (unsigned long) (VALUE))
401 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
402 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
403 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
404 (unsigned long) (VALUE))
407 #ifndef ASM_OUTPUT_DWARF_DATA8
408 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
410 if (WORDS_BIG_ENDIAN) \
412 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
413 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
417 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
418 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
423 #else /* UNALIGNED_INT_ASM_OP */
425 /* We don't have unaligned support, let's hope the normal output works for
428 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
429 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), PTR_SIZE, 1)
431 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
432 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
434 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
435 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
437 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
438 assemble_integer (gen_rtx_MINUS (HImode, \
439 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
440 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
443 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
444 assemble_integer (gen_rtx_MINUS (SImode, \
445 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
446 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
449 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
450 assemble_integer (gen_rtx_MINUS (Pmode, \
451 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
452 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
455 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
456 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
458 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
459 assemble_integer (GEN_INT (VALUE), 4, 1)
461 #endif /* UNALIGNED_INT_ASM_OP */
464 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
465 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
467 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
468 assemble_name (FILE, SY); \
470 assemble_name (FILE, HI); \
472 assemble_name (FILE, LO); \
475 #endif /* SET_ASM_OP */
477 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
478 newline is produced. When flag_debug_asm is asserted, we add commentary
479 at the end of the line, so we must avoid output of a newline here. */
480 #ifndef ASM_OUTPUT_DWARF_STRING
481 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
483 register int slen = strlen(P); \
484 register const char *p = (P); \
486 fprintf (FILE, "\t.ascii \""); \
487 for (i = 0; i < slen; i++) \
489 register int c = p[i]; \
490 if (c == '\"' || c == '\\') \
496 fprintf (FILE, "\\%o", c); \
499 fprintf (FILE, "\\0\""); \
504 /* The DWARF 2 CFA column which tracks the return address. Normally this
505 is the column for PC, or the first column after all of the hard
507 #ifndef DWARF_FRAME_RETURN_COLUMN
509 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
511 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
515 /* The mapping from gcc register number to DWARF 2 CFA column number. By
516 default, we just provide columns for all registers. */
517 #ifndef DWARF_FRAME_REGNUM
518 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
521 /* Hook used by __throw. */
524 expand_builtin_dwarf_fp_regnum ()
526 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
));
529 /* The offset from the incoming value of %sp to the top of the stack frame
530 for the current function. */
531 #ifndef INCOMING_FRAME_SP_OFFSET
532 #define INCOMING_FRAME_SP_OFFSET 0
535 /* Return a pointer to a copy of the section string name S with all
536 attributes stripped off, and an asterisk prepended (for assemble_name). */
542 char *stripped
= xmalloc (strlen (s
) + 2);
547 while (*s
&& *s
!= ',')
554 /* Return the register number described by a given RTL node. */
560 register unsigned regno
= REGNO (rtl
);
562 if (regno
>= DWARF_FRAME_REGISTERS
)
564 warning ("internal regno botch: regno = %d\n", regno
);
568 regno
= DBX_REGISTER_NUMBER (regno
);
572 /* Generate code to initialize the register size table. */
575 expand_builtin_init_dwarf_reg_sizes (address
)
579 enum machine_mode mode
= TYPE_MODE (char_type_node
);
580 rtx addr
= expand_expr (address
, NULL_RTX
, VOIDmode
, 0);
581 rtx mem
= gen_rtx_MEM (mode
, addr
);
583 for (i
= 0; i
< DWARF_FRAME_REGISTERS
; ++i
)
585 int offset
= i
* GET_MODE_SIZE (mode
);
586 int size
= GET_MODE_SIZE (reg_raw_mode
[i
]);
588 emit_move_insn (change_address (mem
, mode
,
589 plus_constant (addr
, offset
)),
594 /* Convert a DWARF call frame info. operation to its string name */
597 dwarf_cfi_name (cfi_opc
)
598 register unsigned cfi_opc
;
602 case DW_CFA_advance_loc
:
603 return "DW_CFA_advance_loc";
605 return "DW_CFA_offset";
607 return "DW_CFA_restore";
611 return "DW_CFA_set_loc";
612 case DW_CFA_advance_loc1
:
613 return "DW_CFA_advance_loc1";
614 case DW_CFA_advance_loc2
:
615 return "DW_CFA_advance_loc2";
616 case DW_CFA_advance_loc4
:
617 return "DW_CFA_advance_loc4";
618 case DW_CFA_offset_extended
:
619 return "DW_CFA_offset_extended";
620 case DW_CFA_restore_extended
:
621 return "DW_CFA_restore_extended";
622 case DW_CFA_undefined
:
623 return "DW_CFA_undefined";
624 case DW_CFA_same_value
:
625 return "DW_CFA_same_value";
626 case DW_CFA_register
:
627 return "DW_CFA_register";
628 case DW_CFA_remember_state
:
629 return "DW_CFA_remember_state";
630 case DW_CFA_restore_state
:
631 return "DW_CFA_restore_state";
633 return "DW_CFA_def_cfa";
634 case DW_CFA_def_cfa_register
:
635 return "DW_CFA_def_cfa_register";
636 case DW_CFA_def_cfa_offset
:
637 return "DW_CFA_def_cfa_offset";
639 /* SGI/MIPS specific */
640 case DW_CFA_MIPS_advance_loc8
:
641 return "DW_CFA_MIPS_advance_loc8";
644 case DW_CFA_GNU_window_save
:
645 return "DW_CFA_GNU_window_save";
646 case DW_CFA_GNU_args_size
:
647 return "DW_CFA_GNU_args_size";
648 case DW_CFA_GNU_negative_offset_extended
:
649 return "DW_CFA_GNU_negative_offset_extended";
652 return "DW_CFA_<unknown>";
656 /* Return a pointer to a newly allocated Call Frame Instruction. */
658 static inline dw_cfi_ref
661 register dw_cfi_ref cfi
= (dw_cfi_ref
) xmalloc (sizeof (dw_cfi_node
));
663 cfi
->dw_cfi_next
= NULL
;
664 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
665 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
670 /* Add a Call Frame Instruction to list of instructions. */
673 add_cfi (list_head
, cfi
)
674 register dw_cfi_ref
*list_head
;
675 register dw_cfi_ref cfi
;
677 register dw_cfi_ref
*p
;
679 /* Find the end of the chain. */
680 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
686 /* Generate a new label for the CFI info to refer to. */
689 dwarf2out_cfi_label ()
691 static char label
[20];
692 static unsigned long label_num
= 0;
694 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", label_num
++);
695 ASM_OUTPUT_LABEL (asm_out_file
, label
);
700 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
701 or to the CIE if LABEL is NULL. */
704 add_fde_cfi (label
, cfi
)
705 register char *label
;
706 register dw_cfi_ref cfi
;
710 register dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
713 label
= dwarf2out_cfi_label ();
715 if (fde
->dw_fde_current_label
== NULL
716 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
718 register dw_cfi_ref xcfi
;
720 fde
->dw_fde_current_label
= label
= xstrdup (label
);
722 /* Set the location counter to the new label. */
724 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
725 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
726 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
729 add_cfi (&fde
->dw_fde_cfi
, cfi
);
733 add_cfi (&cie_cfi_head
, cfi
);
736 /* Subroutine of lookup_cfa. */
739 lookup_cfa_1 (cfi
, regp
, offsetp
)
740 register dw_cfi_ref cfi
;
741 register unsigned long *regp
;
742 register long *offsetp
;
744 switch (cfi
->dw_cfi_opc
)
746 case DW_CFA_def_cfa_offset
:
747 *offsetp
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
749 case DW_CFA_def_cfa_register
:
750 *regp
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
753 *regp
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
754 *offsetp
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
761 /* Find the previous value for the CFA. */
764 lookup_cfa (regp
, offsetp
)
765 register unsigned long *regp
;
766 register long *offsetp
;
768 register dw_cfi_ref cfi
;
770 *regp
= (unsigned long) -1;
773 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
774 lookup_cfa_1 (cfi
, regp
, offsetp
);
776 if (fde_table_in_use
)
778 register dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
779 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
780 lookup_cfa_1 (cfi
, regp
, offsetp
);
784 /* The current rule for calculating the DWARF2 canonical frame address. */
785 static unsigned long cfa_reg
;
786 static long cfa_offset
;
788 /* The register used for saving registers to the stack, and its offset
790 static unsigned cfa_store_reg
;
791 static long cfa_store_offset
;
793 /* The running total of the size of arguments pushed onto the stack. */
794 static long args_size
;
796 /* The last args_size we actually output. */
797 static long old_args_size
;
799 /* Entry point to update the canonical frame address (CFA).
800 LABEL is passed to add_fde_cfi. The value of CFA is now to be
801 calculated from REG+OFFSET. */
804 dwarf2out_def_cfa (label
, reg
, offset
)
805 register char *label
;
806 register unsigned reg
;
807 register long offset
;
809 register dw_cfi_ref cfi
;
810 unsigned long old_reg
;
815 if (cfa_store_reg
== reg
)
816 cfa_store_offset
= offset
;
818 reg
= DWARF_FRAME_REGNUM (reg
);
819 lookup_cfa (&old_reg
, &old_offset
);
821 if (reg
== old_reg
&& offset
== old_offset
)
828 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
829 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= offset
;
832 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
833 else if (offset
== old_offset
&& old_reg
!= (unsigned long) -1)
835 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
836 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
842 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
843 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
844 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
847 add_fde_cfi (label
, cfi
);
850 /* Add the CFI for saving a register. REG is the CFA column number.
851 LABEL is passed to add_fde_cfi.
852 If SREG is -1, the register is saved at OFFSET from the CFA;
853 otherwise it is saved in SREG. */
856 reg_save (label
, reg
, sreg
, offset
)
857 register char * label
;
858 register unsigned reg
;
859 register unsigned sreg
;
860 register long offset
;
862 register dw_cfi_ref cfi
= new_cfi ();
864 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
866 /* The following comparison is correct. -1 is used to indicate that
867 the value isn't a register number. */
868 if (sreg
== (unsigned int) -1)
871 /* The register number won't fit in 6 bits, so we have to use
873 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
875 cfi
->dw_cfi_opc
= DW_CFA_offset
;
877 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
880 cfi
->dw_cfi_opc
= DW_CFA_GNU_negative_offset_extended
;
883 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
887 cfi
->dw_cfi_opc
= DW_CFA_register
;
888 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
891 add_fde_cfi (label
, cfi
);
894 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
895 This CFI tells the unwinder that it needs to restore the window registers
896 from the previous frame's window save area.
898 ??? Perhaps we should note in the CIE where windows are saved (instead of
899 assuming 0(cfa)) and what registers are in the window. */
902 dwarf2out_window_save (label
)
903 register char * label
;
905 register dw_cfi_ref cfi
= new_cfi ();
906 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
907 add_fde_cfi (label
, cfi
);
910 /* Add a CFI to update the running total of the size of arguments
911 pushed onto the stack. */
914 dwarf2out_args_size (label
, size
)
918 register dw_cfi_ref cfi
;
920 if (size
== old_args_size
)
922 old_args_size
= size
;
925 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
926 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
927 add_fde_cfi (label
, cfi
);
930 /* Entry point for saving a register to the stack. REG is the GCC register
931 number. LABEL and OFFSET are passed to reg_save. */
934 dwarf2out_reg_save (label
, reg
, offset
)
935 register char * label
;
936 register unsigned reg
;
937 register long offset
;
939 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
942 /* Entry point for saving the return address in the stack.
943 LABEL and OFFSET are passed to reg_save. */
946 dwarf2out_return_save (label
, offset
)
947 register char * label
;
948 register long offset
;
950 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, -1, offset
);
953 /* Entry point for saving the return address in a register.
954 LABEL and SREG are passed to reg_save. */
957 dwarf2out_return_reg (label
, sreg
)
958 register char * label
;
959 register unsigned sreg
;
961 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, sreg
, 0);
964 /* Record the initial position of the return address. RTL is
965 INCOMING_RETURN_ADDR_RTX. */
968 initial_return_save (rtl
)
971 unsigned int reg
= (unsigned int) -1;
974 switch (GET_CODE (rtl
))
977 /* RA is in a register. */
978 reg
= reg_number (rtl
);
981 /* RA is on the stack. */
983 switch (GET_CODE (rtl
))
986 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
991 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
993 offset
= INTVAL (XEXP (rtl
, 1));
996 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
998 offset
= -INTVAL (XEXP (rtl
, 1));
1005 /* The return address is at some offset from any value we can
1006 actually load. For instance, on the SPARC it is in %i7+8. Just
1007 ignore the offset for now; it doesn't matter for unwinding frames. */
1008 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
1010 initial_return_save (XEXP (rtl
, 0));
1016 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa_offset
);
1019 /* Check INSN to see if it looks like a push or a stack adjustment, and
1020 make a note of it if it does. EH uses this information to find out how
1021 much extra space it needs to pop off the stack. */
1024 dwarf2out_stack_adjust (insn
)
1030 if (! asynchronous_exceptions
&& GET_CODE (insn
) == CALL_INSN
)
1032 /* Extract the size of the args from the CALL rtx itself. */
1034 insn
= PATTERN (insn
);
1035 if (GET_CODE (insn
) == PARALLEL
)
1036 insn
= XVECEXP (insn
, 0, 0);
1037 if (GET_CODE (insn
) == SET
)
1038 insn
= SET_SRC (insn
);
1039 assert (GET_CODE (insn
) == CALL
);
1040 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1044 /* If only calls can throw, and we have a frame pointer,
1045 save up adjustments until we see the CALL_INSN. */
1046 else if (! asynchronous_exceptions
1047 && cfa_reg
!= STACK_POINTER_REGNUM
)
1050 if (GET_CODE (insn
) == BARRIER
)
1052 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1053 the compiler will have already emitted a stack adjustment, but
1054 doesn't bother for calls to noreturn functions. */
1055 #ifdef STACK_GROWS_DOWNWARD
1056 offset
= -args_size
;
1061 else if (GET_CODE (PATTERN (insn
)) == SET
)
1066 insn
= PATTERN (insn
);
1067 src
= SET_SRC (insn
);
1068 dest
= SET_DEST (insn
);
1070 if (dest
== stack_pointer_rtx
)
1072 /* (set (reg sp) (plus (reg sp) (const_int))) */
1073 code
= GET_CODE (src
);
1074 if (! (code
== PLUS
|| code
== MINUS
)
1075 || XEXP (src
, 0) != stack_pointer_rtx
1076 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1079 offset
= INTVAL (XEXP (src
, 1));
1081 else if (GET_CODE (dest
) == MEM
)
1083 /* (set (mem (pre_dec (reg sp))) (foo)) */
1084 src
= XEXP (dest
, 0);
1085 code
= GET_CODE (src
);
1087 if (! (code
== PRE_DEC
|| code
== PRE_INC
)
1088 || XEXP (src
, 0) != stack_pointer_rtx
)
1091 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1096 if (code
== PLUS
|| code
== PRE_INC
)
1105 if (cfa_reg
== STACK_POINTER_REGNUM
)
1106 cfa_offset
+= offset
;
1108 #ifndef STACK_GROWS_DOWNWARD
1111 args_size
+= offset
;
1115 label
= dwarf2out_cfi_label ();
1116 dwarf2out_def_cfa (label
, cfa_reg
, cfa_offset
);
1117 dwarf2out_args_size (label
, args_size
);
1120 /* A temporary register used in adjusting SP or setting up the store_reg. */
1121 static unsigned cfa_temp_reg
;
1123 /* A temporary value used in adjusting SP or setting up the store_reg. */
1124 static long cfa_temp_value
;
1126 /* Record call frame debugging information for an expression, which either
1127 sets SP or FP (adjusting how we calculate the frame address) or saves a
1128 register to the stack. */
1131 dwarf2out_frame_debug_expr (expr
, label
)
1138 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1139 the PARALLEL independantly. The first element is always processed if
1140 it is a SET. This is for backward compatability. Other elements
1141 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1142 flag is set in them. */
1144 if (GET_CODE (expr
) == PARALLEL
)
1147 int limit
= XVECLEN (expr
, 0);
1149 for (par_index
= 0; par_index
< limit
; par_index
++)
1151 rtx x
= XVECEXP (expr
, 0, par_index
);
1153 if (GET_CODE (x
) == SET
&&
1154 (RTX_FRAME_RELATED_P (x
) || par_index
== 0))
1155 dwarf2out_frame_debug_expr (x
, label
);
1160 if (GET_CODE (expr
) != SET
)
1163 src
= SET_SRC (expr
);
1164 dest
= SET_DEST (expr
);
1166 switch (GET_CODE (dest
))
1169 /* Update the CFA rule wrt SP or FP. Make sure src is
1170 relative to the current CFA register. */
1171 switch (GET_CODE (src
))
1173 /* Setting FP from SP. */
1175 if (cfa_reg
!= (unsigned) REGNO (src
))
1177 if (REGNO (dest
) != STACK_POINTER_REGNUM
1178 && !(frame_pointer_needed
1179 && REGNO (dest
) == HARD_FRAME_POINTER_REGNUM
))
1181 cfa_reg
= REGNO (dest
);
1186 if (dest
== stack_pointer_rtx
)
1189 switch (GET_CODE (XEXP (src
, 1)))
1192 offset
= INTVAL (XEXP (src
, 1));
1195 if ((unsigned) REGNO (XEXP (src
, 1)) != cfa_temp_reg
)
1197 offset
= cfa_temp_value
;
1203 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1205 /* Restoring SP from FP in the epilogue. */
1206 if (cfa_reg
!= (unsigned) HARD_FRAME_POINTER_REGNUM
)
1208 cfa_reg
= STACK_POINTER_REGNUM
;
1210 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1213 if (GET_CODE (src
) == PLUS
)
1215 if (cfa_reg
== STACK_POINTER_REGNUM
)
1216 cfa_offset
+= offset
;
1217 if (cfa_store_reg
== STACK_POINTER_REGNUM
)
1218 cfa_store_offset
+= offset
;
1220 else if (dest
== hard_frame_pointer_rtx
)
1222 /* Either setting the FP from an offset of the SP,
1223 or adjusting the FP */
1224 if (! frame_pointer_needed
1225 || REGNO (dest
) != HARD_FRAME_POINTER_REGNUM
)
1228 if (XEXP (src
, 0) == stack_pointer_rtx
1229 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1231 if (cfa_reg
!= STACK_POINTER_REGNUM
)
1233 offset
= INTVAL (XEXP (src
, 1));
1234 if (GET_CODE (src
) == PLUS
)
1236 cfa_offset
+= offset
;
1237 cfa_reg
= HARD_FRAME_POINTER_REGNUM
;
1239 else if (XEXP (src
, 0) == hard_frame_pointer_rtx
1240 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1242 if (cfa_reg
!= (unsigned) HARD_FRAME_POINTER_REGNUM
)
1244 offset
= INTVAL (XEXP (src
, 1));
1245 if (GET_CODE (src
) == PLUS
)
1247 cfa_offset
+= offset
;
1255 if (GET_CODE (src
) != PLUS
1256 || XEXP (src
, 1) != stack_pointer_rtx
)
1258 if (GET_CODE (XEXP (src
, 0)) != REG
1259 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp_reg
)
1261 if (cfa_reg
!= STACK_POINTER_REGNUM
)
1263 cfa_store_reg
= REGNO (dest
);
1264 cfa_store_offset
= cfa_offset
- cfa_temp_value
;
1269 cfa_temp_reg
= REGNO (dest
);
1270 cfa_temp_value
= INTVAL (src
);
1274 if (GET_CODE (XEXP (src
, 0)) != REG
1275 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp_reg
1276 || (unsigned) REGNO (dest
) != cfa_temp_reg
1277 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1279 cfa_temp_value
|= INTVAL (XEXP (src
, 1));
1285 dwarf2out_def_cfa (label
, cfa_reg
, cfa_offset
);
1289 /* Saving a register to the stack. Make sure dest is relative to the
1291 if (GET_CODE (src
) != REG
)
1293 switch (GET_CODE (XEXP (dest
, 0)))
1298 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1299 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1302 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1303 || cfa_store_reg
!= STACK_POINTER_REGNUM
)
1305 cfa_store_offset
+= offset
;
1306 if (cfa_reg
== STACK_POINTER_REGNUM
)
1307 cfa_offset
= cfa_store_offset
;
1309 offset
= -cfa_store_offset
;
1312 /* With an offset. */
1315 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1316 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1319 if (cfa_store_reg
!= (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1321 offset
-= cfa_store_offset
;
1324 /* Without an offset. */
1326 if (cfa_store_reg
!= (unsigned) REGNO (XEXP (dest
, 0)))
1328 offset
= -cfa_store_offset
;
1334 dwarf2out_def_cfa (label
, cfa_reg
, cfa_offset
);
1335 dwarf2out_reg_save (label
, REGNO (src
), offset
);
1344 /* Record call frame debugging information for INSN, which either
1345 sets SP or FP (adjusting how we calculate the frame address) or saves a
1346 register to the stack. If INSN is NULL_RTX, initialize our state. */
1349 dwarf2out_frame_debug (insn
)
1355 if (insn
== NULL_RTX
)
1357 /* Set up state for generating call frame debug info. */
1358 lookup_cfa (&cfa_reg
, &cfa_offset
);
1359 if (cfa_reg
!= (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1361 cfa_reg
= STACK_POINTER_REGNUM
;
1362 cfa_store_reg
= cfa_reg
;
1363 cfa_store_offset
= cfa_offset
;
1369 if (! RTX_FRAME_RELATED_P (insn
))
1371 dwarf2out_stack_adjust (insn
);
1375 label
= dwarf2out_cfi_label ();
1377 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1379 insn
= XEXP (src
, 0);
1381 insn
= PATTERN (insn
);
1383 dwarf2out_frame_debug_expr (insn
, label
);
1386 /* Return the size of an unsigned LEB128 quantity. */
1388 static inline unsigned long
1389 size_of_uleb128 (value
)
1390 register unsigned long value
;
1392 register unsigned long size
= 0;
1393 register unsigned byte
;
1397 byte
= (value
& 0x7f);
1406 /* Return the size of a signed LEB128 quantity. */
1408 static inline unsigned long
1409 size_of_sleb128 (value
)
1410 register long value
;
1412 register unsigned long size
= 0;
1413 register unsigned byte
;
1417 byte
= (value
& 0x7f);
1421 while (!(((value
== 0) && ((byte
& 0x40) == 0))
1422 || ((value
== -1) && ((byte
& 0x40) != 0))));
1427 /* Output an unsigned LEB128 quantity. */
1430 output_uleb128 (value
)
1431 register unsigned long value
;
1433 unsigned long save_value
= value
;
1435 fprintf (asm_out_file
, "\t%s\t", ASM_BYTE_OP
);
1438 register unsigned byte
= (value
& 0x7f);
1441 /* More bytes to follow. */
1444 fprintf (asm_out_file
, "0x%x", byte
);
1446 fprintf (asm_out_file
, ",");
1451 fprintf (asm_out_file
, "\t%s ULEB128 0x%lx", ASM_COMMENT_START
, save_value
);
1454 /* Output an signed LEB128 quantity. */
1457 output_sleb128 (value
)
1458 register long value
;
1461 register unsigned byte
;
1462 long save_value
= value
;
1464 fprintf (asm_out_file
, "\t%s\t", ASM_BYTE_OP
);
1467 byte
= (value
& 0x7f);
1468 /* arithmetic shift */
1470 more
= !((((value
== 0) && ((byte
& 0x40) == 0))
1471 || ((value
== -1) && ((byte
& 0x40) != 0))));
1475 fprintf (asm_out_file
, "0x%x", byte
);
1477 fprintf (asm_out_file
, ",");
1482 fprintf (asm_out_file
, "\t%s SLEB128 %ld", ASM_COMMENT_START
, save_value
);
1485 /* Output a Call Frame Information opcode and its operand(s). */
1488 output_cfi (cfi
, fde
)
1489 register dw_cfi_ref cfi
;
1490 register dw_fde_ref fde
;
1492 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1494 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
1496 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f));
1498 fprintf (asm_out_file
, "\t%s DW_CFA_advance_loc 0x%lx",
1499 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1500 fputc ('\n', asm_out_file
);
1503 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1505 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
1507 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f));
1509 fprintf (asm_out_file
, "\t%s DW_CFA_offset, column 0x%lx",
1510 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1512 fputc ('\n', asm_out_file
);
1513 output_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
1514 fputc ('\n', asm_out_file
);
1516 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1518 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
1520 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f));
1522 fprintf (asm_out_file
, "\t%s DW_CFA_restore, column 0x%lx",
1523 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1525 fputc ('\n', asm_out_file
);
1529 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, cfi
->dw_cfi_opc
);
1531 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
,
1532 dwarf_cfi_name (cfi
->dw_cfi_opc
));
1534 fputc ('\n', asm_out_file
);
1535 switch (cfi
->dw_cfi_opc
)
1537 case DW_CFA_set_loc
:
1538 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
);
1539 fputc ('\n', asm_out_file
);
1541 case DW_CFA_advance_loc1
:
1542 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file
,
1543 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1544 fde
->dw_fde_current_label
);
1545 fputc ('\n', asm_out_file
);
1546 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1548 case DW_CFA_advance_loc2
:
1549 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
,
1550 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1551 fde
->dw_fde_current_label
);
1552 fputc ('\n', asm_out_file
);
1553 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1555 case DW_CFA_advance_loc4
:
1556 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
,
1557 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1558 fde
->dw_fde_current_label
);
1559 fputc ('\n', asm_out_file
);
1560 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1562 #ifdef MIPS_DEBUGGING_INFO
1563 case DW_CFA_MIPS_advance_loc8
:
1564 /* TODO: not currently implemented. */
1568 case DW_CFA_offset_extended
:
1569 case DW_CFA_GNU_negative_offset_extended
:
1570 case DW_CFA_def_cfa
:
1571 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1572 fputc ('\n', asm_out_file
);
1573 output_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
1574 fputc ('\n', asm_out_file
);
1576 case DW_CFA_restore_extended
:
1577 case DW_CFA_undefined
:
1578 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1579 fputc ('\n', asm_out_file
);
1581 case DW_CFA_same_value
:
1582 case DW_CFA_def_cfa_register
:
1583 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1584 fputc ('\n', asm_out_file
);
1586 case DW_CFA_register
:
1587 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1588 fputc ('\n', asm_out_file
);
1589 output_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
);
1590 fputc ('\n', asm_out_file
);
1592 case DW_CFA_def_cfa_offset
:
1593 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1594 fputc ('\n', asm_out_file
);
1596 case DW_CFA_GNU_window_save
:
1598 case DW_CFA_GNU_args_size
:
1599 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1600 fputc ('\n', asm_out_file
);
1608 /* Output the call frame information used to used to record information
1609 that relates to calculating the frame pointer, and records the
1610 location of saved registers. */
1613 output_call_frame_info (for_eh
)
1616 register unsigned long i
;
1617 register dw_fde_ref fde
;
1618 register dw_cfi_ref cfi
;
1619 char l1
[20], l2
[20];
1620 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1624 /* Do we want to include a pointer to the exception table? */
1625 int eh_ptr
= for_eh
&& exception_table_p ();
1627 /* If we don't have any functions we'll want to unwind out of, don't
1628 emit any EH unwind information. */
1631 for (i
= 0; i
< fde_table_in_use
; ++i
)
1632 if (! fde_table
[i
].nothrow
)
1638 fputc ('\n', asm_out_file
);
1640 /* We're going to be generating comments, so turn on app. */
1646 #ifdef EH_FRAME_SECTION
1647 EH_FRAME_SECTION ();
1649 tree label
= get_file_function_name ('F');
1651 force_data_section ();
1652 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
1653 ASM_GLOBALIZE_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
1654 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
1656 assemble_label ("__FRAME_BEGIN__");
1659 ASM_OUTPUT_SECTION (asm_out_file
, FRAME_SECTION
);
1661 /* Output the CIE. */
1662 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
1663 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
1664 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1665 ASM_GENERATE_INTERNAL_LABEL (ld
, CIE_LENGTH_LABEL
, for_eh
);
1667 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file
, ld
);
1669 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, ld
);
1672 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
, l2
, l1
);
1674 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, l2
, l1
);
1677 fprintf (asm_out_file
, "\t%s Length of Common Information Entry",
1680 fputc ('\n', asm_out_file
);
1681 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1684 /* Now that the CIE pointer is PC-relative for EH,
1685 use 0 to identify the CIE. */
1686 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 0);
1688 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, DW_CIE_ID
);
1691 fprintf (asm_out_file
, "\t%s CIE Identifier Tag", ASM_COMMENT_START
);
1693 fputc ('\n', asm_out_file
);
1694 if (! for_eh
&& DWARF_OFFSET_SIZE
== 8)
1696 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, DW_CIE_ID
);
1697 fputc ('\n', asm_out_file
);
1700 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_CIE_VERSION
);
1702 fprintf (asm_out_file
, "\t%s CIE Version", ASM_COMMENT_START
);
1704 fputc ('\n', asm_out_file
);
1707 /* The CIE contains a pointer to the exception region info for the
1708 frame. Make the augmentation string three bytes (including the
1709 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1710 can't handle unaligned relocs. */
1713 ASM_OUTPUT_DWARF_STRING (asm_out_file
, "eh");
1714 fprintf (asm_out_file
, "\t%s CIE Augmentation", ASM_COMMENT_START
);
1718 ASM_OUTPUT_ASCII (asm_out_file
, "eh", 3);
1720 fputc ('\n', asm_out_file
);
1722 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, "__EXCEPTION_TABLE__");
1724 fprintf (asm_out_file
, "\t%s pointer to exception region info",
1729 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
1731 fprintf (asm_out_file
, "\t%s CIE Augmentation (none)",
1735 fputc ('\n', asm_out_file
);
1738 fprintf (asm_out_file
, " (CIE Code Alignment Factor)");
1740 fputc ('\n', asm_out_file
);
1741 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT
);
1743 fprintf (asm_out_file
, " (CIE Data Alignment Factor)");
1745 fputc ('\n', asm_out_file
);
1746 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_FRAME_RETURN_COLUMN
);
1748 fprintf (asm_out_file
, "\t%s CIE RA Column", ASM_COMMENT_START
);
1750 fputc ('\n', asm_out_file
);
1752 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
1753 output_cfi (cfi
, NULL
);
1755 /* Pad the CIE out to an address sized boundary. */
1756 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
1757 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
1758 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1759 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file
, ld
, l2
, l1
);
1761 fprintf (asm_out_file
, "\t%s CIE Length Symbol", ASM_COMMENT_START
);
1762 fputc ('\n', asm_out_file
);
1765 /* Loop through all of the FDE's. */
1766 for (i
= 0; i
< fde_table_in_use
; ++i
)
1768 fde
= &fde_table
[i
];
1770 /* Don't emit EH unwind info for leaf functions. */
1771 if (for_eh
&& fde
->nothrow
)
1774 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
*2);
1775 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
*2);
1776 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1777 ASM_GENERATE_INTERNAL_LABEL (ld
, FDE_LENGTH_LABEL
, for_eh
+ i
*2);
1779 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file
, ld
);
1781 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, ld
);
1784 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
, l2
, l1
);
1786 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, l2
, l1
);
1789 fprintf (asm_out_file
, "\t%s FDE Length", ASM_COMMENT_START
);
1790 fputc ('\n', asm_out_file
);
1791 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1793 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1794 emits a target dependent sized offset when for_eh is not true.
1795 This inconsistency may confuse gdb. The only case where we need a
1796 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1797 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1798 though in order to be compatible with the dwarf_fde struct in frame.c.
1799 If the for_eh case is changed, then the struct in frame.c has
1800 to be adjusted appropriately. */
1802 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
, l1
, "__FRAME_BEGIN__");
1804 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, stripattributes (FRAME_SECTION
));
1806 fprintf (asm_out_file
, "\t%s FDE CIE offset", ASM_COMMENT_START
);
1808 fputc ('\n', asm_out_file
);
1809 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, fde
->dw_fde_begin
);
1811 fprintf (asm_out_file
, "\t%s FDE initial location", ASM_COMMENT_START
);
1813 fputc ('\n', asm_out_file
);
1814 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
,
1815 fde
->dw_fde_end
, fde
->dw_fde_begin
);
1817 fprintf (asm_out_file
, "\t%s FDE address range", ASM_COMMENT_START
);
1819 fputc ('\n', asm_out_file
);
1821 /* Loop through the Call Frame Instructions associated with
1823 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
1824 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
1825 output_cfi (cfi
, fde
);
1827 /* Pad the FDE out to an address sized boundary. */
1828 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
1829 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
1830 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1831 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file
, ld
, l2
, l1
);
1833 fprintf (asm_out_file
, "\t%s FDE Length Symbol", ASM_COMMENT_START
);
1834 fputc ('\n', asm_out_file
);
1837 #ifndef EH_FRAME_SECTION
1840 /* Emit terminating zero for table. */
1841 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 0);
1842 fputc ('\n', asm_out_file
);
1845 #ifdef MIPS_DEBUGGING_INFO
1846 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1847 get a value of 0. Putting .align 0 after the label fixes it. */
1848 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
1851 /* Turn off app to make assembly quicker. */
1856 /* Output a marker (i.e. a label) for the beginning of a function, before
1860 dwarf2out_begin_prologue ()
1862 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1863 register dw_fde_ref fde
;
1865 ++current_funcdef_number
;
1867 function_section (current_function_decl
);
1868 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1869 current_funcdef_number
);
1870 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1871 current_function_func_begin_label
= get_identifier (label
);
1873 /* Expand the fde table if necessary. */
1874 if (fde_table_in_use
== fde_table_allocated
)
1876 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
1878 = (dw_fde_ref
) xrealloc (fde_table
,
1879 fde_table_allocated
* sizeof (dw_fde_node
));
1882 /* Record the FDE associated with this function. */
1883 current_funcdef_fde
= fde_table_in_use
;
1885 /* Add the new FDE at the end of the fde_table. */
1886 fde
= &fde_table
[fde_table_in_use
++];
1887 fde
->dw_fde_begin
= xstrdup (label
);
1888 fde
->dw_fde_current_label
= NULL
;
1889 fde
->dw_fde_end
= NULL
;
1890 fde
->dw_fde_cfi
= NULL
;
1891 fde
->nothrow
= current_function_nothrow
;
1893 args_size
= old_args_size
= 0;
1896 /* Output a marker (i.e. a label) for the absolute end of the generated code
1897 for a function definition. This gets called *after* the epilogue code has
1901 dwarf2out_end_epilogue ()
1904 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1906 /* Output a label to mark the endpoint of the code generated for this
1908 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
, current_funcdef_number
);
1909 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1910 fde
= &fde_table
[fde_table_in_use
- 1];
1911 fde
->dw_fde_end
= xstrdup (label
);
1915 dwarf2out_frame_init ()
1917 /* Allocate the initial hunk of the fde_table. */
1918 fde_table
= (dw_fde_ref
) xcalloc (FDE_TABLE_INCREMENT
, sizeof (dw_fde_node
));
1919 fde_table_allocated
= FDE_TABLE_INCREMENT
;
1920 fde_table_in_use
= 0;
1922 /* Generate the CFA instructions common to all FDE's. Do it now for the
1923 sake of lookup_cfa. */
1925 #ifdef DWARF2_UNWIND_INFO
1926 /* On entry, the Canonical Frame Address is at SP. */
1927 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
1928 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
1933 dwarf2out_frame_finish ()
1935 /* Output call frame information. */
1936 #ifdef MIPS_DEBUGGING_INFO
1937 if (write_symbols
== DWARF2_DEBUG
)
1938 output_call_frame_info (0);
1939 if (flag_unwind_tables
|| (flag_exceptions
&& ! exceptions_via_longjmp
))
1940 output_call_frame_info (1);
1942 if (write_symbols
== DWARF2_DEBUG
1943 || flag_unwind_tables
|| (flag_exceptions
&& ! exceptions_via_longjmp
))
1944 output_call_frame_info (1);
1948 #endif /* .debug_frame support */
1950 /* And now, the support for symbolic debugging information. */
1951 #ifdef DWARF2_DEBUGGING_INFO
1953 /* NOTE: In the comments in this file, many references are made to
1954 "Debugging Information Entries". This term is abbreviated as `DIE'
1955 throughout the remainder of this file. */
1957 /* An internal representation of the DWARF output is built, and then
1958 walked to generate the DWARF debugging info. The walk of the internal
1959 representation is done after the entire program has been compiled.
1960 The types below are used to describe the internal representation. */
1962 /* Each DIE may have a series of attribute/value pairs. Values
1963 can take on several forms. The forms that are used in this
1964 implementation are listed below. */
1971 dw_val_class_unsigned_const
,
1972 dw_val_class_long_long
,
1975 dw_val_class_die_ref
,
1976 dw_val_class_fde_ref
,
1977 dw_val_class_lbl_id
,
1978 dw_val_class_lbl_offset
,
1983 /* Various DIE's use offsets relative to the beginning of the
1984 .debug_info section to refer to each other. */
1986 typedef long int dw_offset
;
1988 /* Define typedefs here to avoid circular dependencies. */
1990 typedef struct die_struct
*dw_die_ref
;
1991 typedef struct dw_attr_struct
*dw_attr_ref
;
1992 typedef struct dw_val_struct
*dw_val_ref
;
1993 typedef struct dw_line_info_struct
*dw_line_info_ref
;
1994 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
1995 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
1996 typedef struct pubname_struct
*pubname_ref
;
1997 typedef dw_die_ref
*arange_ref
;
1999 /* Describe a double word constant value. */
2001 typedef struct dw_long_long_struct
2008 /* Describe a floating point constant value. */
2010 typedef struct dw_fp_struct
2017 /* Each entry in the line_info_table maintains the file and
2018 line number associated with the label generated for that
2019 entry. The label gives the PC value associated with
2020 the line number entry. */
2022 typedef struct dw_line_info_struct
2024 unsigned long dw_file_num
;
2025 unsigned long dw_line_num
;
2029 /* Line information for functions in separate sections; each one gets its
2031 typedef struct dw_separate_line_info_struct
2033 unsigned long dw_file_num
;
2034 unsigned long dw_line_num
;
2035 unsigned long function
;
2037 dw_separate_line_info_entry
;
2039 /* The dw_val_node describes an attribute's value, as it is
2040 represented internally. */
2042 typedef struct dw_val_struct
2044 dw_val_class val_class
;
2048 dw_loc_descr_ref val_loc
;
2050 long unsigned val_unsigned
;
2051 dw_long_long_const val_long_long
;
2052 dw_float_const val_float
;
2053 dw_die_ref val_die_ref
;
2054 unsigned val_fde_index
;
2057 unsigned char val_flag
;
2063 /* Locations in memory are described using a sequence of stack machine
2066 typedef struct dw_loc_descr_struct
2068 dw_loc_descr_ref dw_loc_next
;
2069 enum dwarf_location_atom dw_loc_opc
;
2070 dw_val_node dw_loc_oprnd1
;
2071 dw_val_node dw_loc_oprnd2
;
2075 /* Each DIE attribute has a field specifying the attribute kind,
2076 a link to the next attribute in the chain, and an attribute value.
2077 Attributes are typically linked below the DIE they modify. */
2079 typedef struct dw_attr_struct
2081 enum dwarf_attribute dw_attr
;
2082 dw_attr_ref dw_attr_next
;
2083 dw_val_node dw_attr_val
;
2087 /* The Debugging Information Entry (DIE) structure */
2089 typedef struct die_struct
2091 enum dwarf_tag die_tag
;
2092 dw_attr_ref die_attr
;
2093 dw_die_ref die_parent
;
2094 dw_die_ref die_child
;
2096 dw_offset die_offset
;
2097 unsigned long die_abbrev
;
2101 /* The pubname structure */
2103 typedef struct pubname_struct
2110 /* The limbo die list structure. */
2111 typedef struct limbo_die_struct
2114 struct limbo_die_struct
*next
;
2118 /* How to start an assembler comment. */
2119 #ifndef ASM_COMMENT_START
2120 #define ASM_COMMENT_START ";#"
2123 /* Define a macro which returns non-zero for a TYPE_DECL which was
2124 implicitly generated for a tagged type.
2126 Note that unlike the gcc front end (which generates a NULL named
2127 TYPE_DECL node for each complete tagged type, each array type, and
2128 each function type node created) the g++ front end generates a
2129 _named_ TYPE_DECL node for each tagged type node created.
2130 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2131 generate a DW_TAG_typedef DIE for them. */
2133 #define TYPE_DECL_IS_STUB(decl) \
2134 (DECL_NAME (decl) == NULL_TREE \
2135 || (DECL_ARTIFICIAL (decl) \
2136 && is_tagged_type (TREE_TYPE (decl)) \
2137 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2138 /* This is necessary for stub decls that \
2139 appear in nested inline functions. */ \
2140 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2141 && (decl_ultimate_origin (decl) \
2142 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2144 /* Information concerning the compilation unit's programming
2145 language, and compiler version. */
2147 extern int flag_traditional
;
2149 /* Fixed size portion of the DWARF compilation unit header. */
2150 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2152 /* Fixed size portion of debugging line information prolog. */
2153 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2155 /* Fixed size portion of public names info. */
2156 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2158 /* Fixed size portion of the address range info. */
2159 #define DWARF_ARANGES_HEADER_SIZE \
2160 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
2162 /* Size of padding portion in the address range info. It must be
2163 aligned to twice the pointer size. */
2164 #define DWARF_ARANGES_PAD_SIZE \
2165 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) \
2166 - (2 * DWARF_OFFSET_SIZE + 4))
2168 /* The default is to have gcc emit the line number tables. */
2169 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2170 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2173 /* Define the architecture-dependent minimum instruction length (in bytes).
2174 In this implementation of DWARF, this field is used for information
2175 purposes only. Since GCC generates assembly language, we have
2176 no a priori knowledge of how many instruction bytes are generated
2177 for each source line, and therefore can use only the DW_LNE_set_address
2178 and DW_LNS_fixed_advance_pc line information commands. */
2180 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2181 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2184 /* Minimum line offset in a special line info. opcode.
2185 This value was chosen to give a reasonable range of values. */
2186 #define DWARF_LINE_BASE -10
2188 /* First special line opcde - leave room for the standard opcodes. */
2189 #define DWARF_LINE_OPCODE_BASE 10
2191 /* Range of line offsets in a special line info. opcode. */
2192 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2194 /* Flag that indicates the initial value of the is_stmt_start flag.
2195 In the present implementation, we do not mark any lines as
2196 the beginning of a source statement, because that information
2197 is not made available by the GCC front-end. */
2198 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2200 /* This location is used by calc_die_sizes() to keep track
2201 the offset of each DIE within the .debug_info section. */
2202 static unsigned long next_die_offset
;
2204 /* Record the root of the DIE's built for the current compilation unit. */
2205 static dw_die_ref comp_unit_die
;
2207 /* A list of DIEs with a NULL parent waiting to be relocated. */
2208 static limbo_die_node
*limbo_die_list
= 0;
2210 /* Pointer to an array of filenames referenced by this compilation unit. */
2211 static char **file_table
;
2213 /* Total number of entries in the table (i.e. array) pointed to by
2214 `file_table'. This is the *total* and includes both used and unused
2216 static unsigned file_table_allocated
;
2218 /* Number of entries in the file_table which are actually in use. */
2219 static unsigned file_table_in_use
;
2221 /* Size (in elements) of increments by which we may expand the filename
2223 #define FILE_TABLE_INCREMENT 64
2225 /* Local pointer to the name of the main input file. Initialized in
2227 static char *primary_filename
;
2229 /* A pointer to the base of a table of references to DIE's that describe
2230 declarations. The table is indexed by DECL_UID() which is a unique
2231 number identifying each decl. */
2232 static dw_die_ref
*decl_die_table
;
2234 /* Number of elements currently allocated for the decl_die_table. */
2235 static unsigned decl_die_table_allocated
;
2237 /* Number of elements in decl_die_table currently in use. */
2238 static unsigned decl_die_table_in_use
;
2240 /* Size (in elements) of increments by which we may expand the
2242 #define DECL_DIE_TABLE_INCREMENT 256
2244 /* A pointer to the base of a table of references to declaration
2245 scopes. This table is a display which tracks the nesting
2246 of declaration scopes at the current scope and containing
2247 scopes. This table is used to find the proper place to
2248 define type declaration DIE's. */
2249 static tree
*decl_scope_table
;
2251 /* Number of elements currently allocated for the decl_scope_table. */
2252 static int decl_scope_table_allocated
;
2254 /* Current level of nesting of declaration scopes. */
2255 static int decl_scope_depth
;
2257 /* Size (in elements) of increments by which we may expand the
2258 decl_scope_table. */
2259 #define DECL_SCOPE_TABLE_INCREMENT 64
2261 /* A pointer to the base of a list of references to DIE's that
2262 are uniquely identified by their tag, presence/absence of
2263 children DIE's, and list of attribute/value pairs. */
2264 static dw_die_ref
*abbrev_die_table
;
2266 /* Number of elements currently allocated for abbrev_die_table. */
2267 static unsigned abbrev_die_table_allocated
;
2269 /* Number of elements in type_die_table currently in use. */
2270 static unsigned abbrev_die_table_in_use
;
2272 /* Size (in elements) of increments by which we may expand the
2273 abbrev_die_table. */
2274 #define ABBREV_DIE_TABLE_INCREMENT 256
2276 /* A pointer to the base of a table that contains line information
2277 for each source code line in .text in the compilation unit. */
2278 static dw_line_info_ref line_info_table
;
2280 /* Number of elements currently allocated for line_info_table. */
2281 static unsigned line_info_table_allocated
;
2283 /* Number of elements in separate_line_info_table currently in use. */
2284 static unsigned separate_line_info_table_in_use
;
2286 /* A pointer to the base of a table that contains line information
2287 for each source code line outside of .text in the compilation unit. */
2288 static dw_separate_line_info_ref separate_line_info_table
;
2290 /* Number of elements currently allocated for separate_line_info_table. */
2291 static unsigned separate_line_info_table_allocated
;
2293 /* Number of elements in line_info_table currently in use. */
2294 static unsigned line_info_table_in_use
;
2296 /* Size (in elements) of increments by which we may expand the
2298 #define LINE_INFO_TABLE_INCREMENT 1024
2300 /* A pointer to the base of a table that contains a list of publicly
2301 accessible names. */
2302 static pubname_ref pubname_table
;
2304 /* Number of elements currently allocated for pubname_table. */
2305 static unsigned pubname_table_allocated
;
2307 /* Number of elements in pubname_table currently in use. */
2308 static unsigned pubname_table_in_use
;
2310 /* Size (in elements) of increments by which we may expand the
2312 #define PUBNAME_TABLE_INCREMENT 64
2314 /* A pointer to the base of a table that contains a list of publicly
2315 accessible names. */
2316 static arange_ref arange_table
;
2318 /* Number of elements currently allocated for arange_table. */
2319 static unsigned arange_table_allocated
;
2321 /* Number of elements in arange_table currently in use. */
2322 static unsigned arange_table_in_use
;
2324 /* Size (in elements) of increments by which we may expand the
2326 #define ARANGE_TABLE_INCREMENT 64
2328 /* A pointer to the base of a list of incomplete types which might be
2329 completed at some later time. */
2331 static tree
*incomplete_types_list
;
2333 /* Number of elements currently allocated for the incomplete_types_list. */
2334 static unsigned incomplete_types_allocated
;
2336 /* Number of elements of incomplete_types_list currently in use. */
2337 static unsigned incomplete_types
;
2339 /* Size (in elements) of increments by which we may expand the incomplete
2340 types list. Actually, a single hunk of space of this size should
2341 be enough for most typical programs. */
2342 #define INCOMPLETE_TYPES_INCREMENT 64
2344 /* Record whether the function being analyzed contains inlined functions. */
2345 static int current_function_has_inlines
;
2346 #if 0 && defined (MIPS_DEBUGGING_INFO)
2347 static int comp_unit_has_inlines
;
2350 /* Array of RTXes referenced by the debugging information, which therefore
2351 must be kept around forever. We do this rather than perform GC on
2352 the dwarf info because almost all of the dwarf info lives forever, and
2353 it's easier to support non-GC frontends this way. */
2354 static varray_type used_rtx_varray
;
2356 /* Forward declarations for functions defined in this file. */
2358 static int is_pseudo_reg
PARAMS ((rtx
));
2359 static tree type_main_variant
PARAMS ((tree
));
2360 static int is_tagged_type
PARAMS ((tree
));
2361 static const char *dwarf_tag_name
PARAMS ((unsigned));
2362 static const char *dwarf_attr_name
PARAMS ((unsigned));
2363 static const char *dwarf_form_name
PARAMS ((unsigned));
2364 static const char *dwarf_stack_op_name
PARAMS ((unsigned));
2366 static const char *dwarf_type_encoding_name
PARAMS ((unsigned));
2368 static tree decl_ultimate_origin
PARAMS ((tree
));
2369 static tree block_ultimate_origin
PARAMS ((tree
));
2370 static tree decl_class_context
PARAMS ((tree
));
2371 static void add_dwarf_attr
PARAMS ((dw_die_ref
, dw_attr_ref
));
2372 static void add_AT_flag
PARAMS ((dw_die_ref
,
2373 enum dwarf_attribute
,
2375 static void add_AT_int
PARAMS ((dw_die_ref
,
2376 enum dwarf_attribute
, long));
2377 static void add_AT_unsigned
PARAMS ((dw_die_ref
,
2378 enum dwarf_attribute
,
2380 static void add_AT_long_long
PARAMS ((dw_die_ref
,
2381 enum dwarf_attribute
,
2384 static void add_AT_float
PARAMS ((dw_die_ref
,
2385 enum dwarf_attribute
,
2387 static void add_AT_string
PARAMS ((dw_die_ref
,
2388 enum dwarf_attribute
,
2390 static void add_AT_die_ref
PARAMS ((dw_die_ref
,
2391 enum dwarf_attribute
,
2393 static void add_AT_fde_ref
PARAMS ((dw_die_ref
,
2394 enum dwarf_attribute
,
2396 static void add_AT_loc
PARAMS ((dw_die_ref
,
2397 enum dwarf_attribute
,
2399 static void add_AT_addr
PARAMS ((dw_die_ref
,
2400 enum dwarf_attribute
,
2402 static void add_AT_lbl_id
PARAMS ((dw_die_ref
,
2403 enum dwarf_attribute
,
2405 static void add_AT_lbl_offset
PARAMS ((dw_die_ref
,
2406 enum dwarf_attribute
,
2408 static dw_attr_ref get_AT
PARAMS ((dw_die_ref
,
2409 enum dwarf_attribute
));
2410 static const char *get_AT_low_pc
PARAMS ((dw_die_ref
));
2411 static const char *get_AT_hi_pc
PARAMS ((dw_die_ref
));
2412 static const char *get_AT_string
PARAMS ((dw_die_ref
,
2413 enum dwarf_attribute
));
2414 static int get_AT_flag
PARAMS ((dw_die_ref
,
2415 enum dwarf_attribute
));
2416 static unsigned get_AT_unsigned
PARAMS ((dw_die_ref
,
2417 enum dwarf_attribute
));
2418 static inline dw_die_ref get_AT_ref
PARAMS ((dw_die_ref
,
2419 enum dwarf_attribute
));
2420 static int is_c_family
PARAMS ((void));
2421 static int is_fortran
PARAMS ((void));
2422 static void remove_AT
PARAMS ((dw_die_ref
,
2423 enum dwarf_attribute
));
2424 static void remove_children
PARAMS ((dw_die_ref
));
2425 static void add_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
2426 static dw_die_ref new_die
PARAMS ((enum dwarf_tag
, dw_die_ref
));
2427 static dw_die_ref lookup_type_die
PARAMS ((tree
));
2428 static void equate_type_number_to_die
PARAMS ((tree
, dw_die_ref
));
2429 static dw_die_ref lookup_decl_die
PARAMS ((tree
));
2430 static void equate_decl_number_to_die
PARAMS ((tree
, dw_die_ref
));
2431 static dw_loc_descr_ref new_loc_descr
PARAMS ((enum dwarf_location_atom
,
2434 static void add_loc_descr
PARAMS ((dw_loc_descr_ref
*,
2436 static void print_spaces
PARAMS ((FILE *));
2437 static void print_die
PARAMS ((dw_die_ref
, FILE *));
2438 static void print_dwarf_line_table
PARAMS ((FILE *));
2439 static void add_sibling_attributes
PARAMS ((dw_die_ref
));
2440 static void build_abbrev_table
PARAMS ((dw_die_ref
));
2441 static unsigned long size_of_string
PARAMS ((const char *));
2442 static unsigned long size_of_loc_descr
PARAMS ((dw_loc_descr_ref
));
2443 static unsigned long size_of_locs
PARAMS ((dw_loc_descr_ref
));
2444 static int constant_size
PARAMS ((long unsigned));
2445 static unsigned long size_of_die
PARAMS ((dw_die_ref
));
2446 static void calc_die_sizes
PARAMS ((dw_die_ref
));
2447 static unsigned long size_of_line_prolog
PARAMS ((void));
2448 static unsigned long size_of_pubnames
PARAMS ((void));
2449 static unsigned long size_of_aranges
PARAMS ((void));
2450 static enum dwarf_form value_format
PARAMS ((dw_attr_ref
));
2451 static void output_value_format
PARAMS ((dw_attr_ref
));
2452 static void output_abbrev_section
PARAMS ((void));
2453 static void output_loc_operands
PARAMS ((dw_loc_descr_ref
));
2454 static void output_die
PARAMS ((dw_die_ref
));
2455 static void output_compilation_unit_header
PARAMS ((void));
2456 static const char *dwarf2_name
PARAMS ((tree
, int));
2457 static void add_pubname
PARAMS ((tree
, dw_die_ref
));
2458 static void output_pubnames
PARAMS ((void));
2459 static void add_arange
PARAMS ((tree
, dw_die_ref
));
2460 static void output_aranges
PARAMS ((void));
2461 static void output_line_info
PARAMS ((void));
2462 static dw_die_ref base_type_die
PARAMS ((tree
));
2463 static tree root_type
PARAMS ((tree
));
2464 static int is_base_type
PARAMS ((tree
));
2465 static dw_die_ref modified_type_die
PARAMS ((tree
, int, int, dw_die_ref
));
2466 static int type_is_enum
PARAMS ((tree
));
2467 static dw_loc_descr_ref reg_loc_descriptor
PARAMS ((rtx
));
2468 static dw_loc_descr_ref based_loc_descr
PARAMS ((unsigned, long));
2469 static int is_based_loc
PARAMS ((rtx
));
2470 static dw_loc_descr_ref mem_loc_descriptor
PARAMS ((rtx
, enum machine_mode mode
));
2471 static dw_loc_descr_ref concat_loc_descriptor
PARAMS ((rtx
, rtx
));
2472 static dw_loc_descr_ref loc_descriptor
PARAMS ((rtx
));
2473 static unsigned ceiling
PARAMS ((unsigned, unsigned));
2474 static tree field_type
PARAMS ((tree
));
2475 static unsigned simple_type_align_in_bits
PARAMS ((tree
));
2476 static unsigned simple_type_size_in_bits
PARAMS ((tree
));
2477 static unsigned field_byte_offset
PARAMS ((tree
));
2478 static void add_AT_location_description
PARAMS ((dw_die_ref
,
2479 enum dwarf_attribute
, rtx
));
2480 static void add_data_member_location_attribute
PARAMS ((dw_die_ref
, tree
));
2481 static void add_const_value_attribute
PARAMS ((dw_die_ref
, rtx
));
2482 static void add_location_or_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
2483 static void add_name_attribute
PARAMS ((dw_die_ref
, const char *));
2484 static void add_bound_info
PARAMS ((dw_die_ref
,
2485 enum dwarf_attribute
, tree
));
2486 static void add_subscript_info
PARAMS ((dw_die_ref
, tree
));
2487 static void add_byte_size_attribute
PARAMS ((dw_die_ref
, tree
));
2488 static void add_bit_offset_attribute
PARAMS ((dw_die_ref
, tree
));
2489 static void add_bit_size_attribute
PARAMS ((dw_die_ref
, tree
));
2490 static void add_prototyped_attribute
PARAMS ((dw_die_ref
, tree
));
2491 static void add_abstract_origin_attribute
PARAMS ((dw_die_ref
, tree
));
2492 static void add_pure_or_virtual_attribute
PARAMS ((dw_die_ref
, tree
));
2493 static void add_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
2494 static void add_name_and_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
2495 static void push_decl_scope
PARAMS ((tree
));
2496 static dw_die_ref scope_die_for
PARAMS ((tree
, dw_die_ref
));
2497 static void pop_decl_scope
PARAMS ((void));
2498 static void add_type_attribute
PARAMS ((dw_die_ref
, tree
, int, int,
2500 static char *type_tag
PARAMS ((tree
));
2501 static tree member_declared_type
PARAMS ((tree
));
2503 static char *decl_start_label
PARAMS ((tree
));
2505 static void gen_array_type_die
PARAMS ((tree
, dw_die_ref
));
2506 static void gen_set_type_die
PARAMS ((tree
, dw_die_ref
));
2508 static void gen_entry_point_die
PARAMS ((tree
, dw_die_ref
));
2510 static void gen_inlined_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
2511 static void gen_inlined_structure_type_die
PARAMS ((tree
, dw_die_ref
));
2512 static void gen_inlined_union_type_die
PARAMS ((tree
, dw_die_ref
));
2513 static void gen_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
2514 static dw_die_ref gen_formal_parameter_die
PARAMS ((tree
, dw_die_ref
));
2515 static void gen_unspecified_parameters_die
PARAMS ((tree
, dw_die_ref
));
2516 static void gen_formal_types_die
PARAMS ((tree
, dw_die_ref
));
2517 static void gen_subprogram_die
PARAMS ((tree
, dw_die_ref
));
2518 static void gen_variable_die
PARAMS ((tree
, dw_die_ref
));
2519 static void gen_label_die
PARAMS ((tree
, dw_die_ref
));
2520 static void gen_lexical_block_die
PARAMS ((tree
, dw_die_ref
, int));
2521 static void gen_inlined_subroutine_die
PARAMS ((tree
, dw_die_ref
, int));
2522 static void gen_field_die
PARAMS ((tree
, dw_die_ref
));
2523 static void gen_ptr_to_mbr_type_die
PARAMS ((tree
, dw_die_ref
));
2524 static dw_die_ref gen_compile_unit_die
PARAMS ((const char *));
2525 static void gen_string_type_die
PARAMS ((tree
, dw_die_ref
));
2526 static void gen_inheritance_die
PARAMS ((tree
, dw_die_ref
));
2527 static void gen_member_die
PARAMS ((tree
, dw_die_ref
));
2528 static void gen_struct_or_union_type_die
PARAMS ((tree
, dw_die_ref
));
2529 static void gen_subroutine_type_die
PARAMS ((tree
, dw_die_ref
));
2530 static void gen_typedef_die
PARAMS ((tree
, dw_die_ref
));
2531 static void gen_type_die
PARAMS ((tree
, dw_die_ref
));
2532 static void gen_tagged_type_instantiation_die
PARAMS ((tree
, dw_die_ref
));
2533 static void gen_block_die
PARAMS ((tree
, dw_die_ref
, int));
2534 static void decls_for_scope
PARAMS ((tree
, dw_die_ref
, int));
2535 static int is_redundant_typedef
PARAMS ((tree
));
2536 static void gen_decl_die
PARAMS ((tree
, dw_die_ref
));
2537 static unsigned lookup_filename
PARAMS ((const char *));
2538 static void add_incomplete_type
PARAMS ((tree
));
2539 static void retry_incomplete_types
PARAMS ((void));
2540 static void gen_type_die_for_member
PARAMS ((tree
, tree
, dw_die_ref
));
2541 static void gen_abstract_function
PARAMS ((tree
));
2542 static rtx save_rtx
PARAMS ((rtx
));
2543 static void splice_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
2544 static void reverse_die_lists
PARAMS ((dw_die_ref
));
2546 /* Section names used to hold DWARF debugging information. */
2547 #ifndef DEBUG_INFO_SECTION
2548 #define DEBUG_INFO_SECTION ".debug_info"
2550 #ifndef ABBREV_SECTION
2551 #define ABBREV_SECTION ".debug_abbrev"
2553 #ifndef ARANGES_SECTION
2554 #define ARANGES_SECTION ".debug_aranges"
2556 #ifndef DW_MACINFO_SECTION
2557 #define DW_MACINFO_SECTION ".debug_macinfo"
2559 #ifndef DEBUG_LINE_SECTION
2560 #define DEBUG_LINE_SECTION ".debug_line"
2563 #define LOC_SECTION ".debug_loc"
2565 #ifndef PUBNAMES_SECTION
2566 #define PUBNAMES_SECTION ".debug_pubnames"
2569 #define STR_SECTION ".debug_str"
2572 /* Standard ELF section names for compiled code and data. */
2573 #ifndef TEXT_SECTION
2574 #define TEXT_SECTION ".text"
2576 #ifndef DATA_SECTION
2577 #define DATA_SECTION ".data"
2580 #define BSS_SECTION ".bss"
2583 /* Labels we insert at beginning sections we can reference instead of
2584 the section names themselves. */
2586 #ifndef TEXT_SECTION_LABEL
2587 #define TEXT_SECTION_LABEL "Ltext"
2589 #ifndef DEBUG_LINE_SECTION_LABEL
2590 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
2592 #ifndef DEBUG_INFO_SECTION_LABEL
2593 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
2595 #ifndef ABBREV_SECTION_LABEL
2596 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
2600 /* Definitions of defaults for formats and names of various special
2601 (artificial) labels which may be generated within this file (when the -g
2602 options is used and DWARF_DEBUGGING_INFO is in effect.
2603 If necessary, these may be overridden from within the tm.h file, but
2604 typically, overriding these defaults is unnecessary. */
2606 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2607 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2608 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2609 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2610 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2612 #ifndef TEXT_END_LABEL
2613 #define TEXT_END_LABEL "Letext"
2615 #ifndef DATA_END_LABEL
2616 #define DATA_END_LABEL "Ledata"
2618 #ifndef BSS_END_LABEL
2619 #define BSS_END_LABEL "Lebss"
2621 #ifndef INSN_LABEL_FMT
2622 #define INSN_LABEL_FMT "LI%u_"
2624 #ifndef BLOCK_BEGIN_LABEL
2625 #define BLOCK_BEGIN_LABEL "LBB"
2627 #ifndef BLOCK_END_LABEL
2628 #define BLOCK_END_LABEL "LBE"
2630 #ifndef BODY_BEGIN_LABEL
2631 #define BODY_BEGIN_LABEL "Lbb"
2633 #ifndef BODY_END_LABEL
2634 #define BODY_END_LABEL "Lbe"
2636 #ifndef LINE_CODE_LABEL
2637 #define LINE_CODE_LABEL "LM"
2639 #ifndef SEPARATE_LINE_CODE_LABEL
2640 #define SEPARATE_LINE_CODE_LABEL "LSM"
2643 /* We allow a language front-end to designate a function that is to be
2644 called to "demangle" any name before it it put into a DIE. */
2646 static const char *(*demangle_name_func
) PARAMS ((const char *));
2649 dwarf2out_set_demangle_name_func (func
)
2650 const char *(*func
) PARAMS ((const char *));
2652 demangle_name_func
= func
;
2655 /* Return an rtx like ORIG which lives forever. If we're doing GC,
2656 that means adding it to used_rtx_varray. If not, that means making
2657 a copy on the permanent_obstack. */
2664 VARRAY_PUSH_RTX (used_rtx_varray
, orig
);
2667 push_obstacks_nochange ();
2668 end_temporary_allocation ();
2669 orig
= copy_rtx (orig
);
2676 /* Test if rtl node points to a pseudo register. */
2682 return (((GET_CODE (rtl
) == REG
) && (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
))
2683 || ((GET_CODE (rtl
) == SUBREG
)
2684 && (REGNO (XEXP (rtl
, 0)) >= FIRST_PSEUDO_REGISTER
)));
2687 /* Return a reference to a type, with its const and volatile qualifiers
2691 type_main_variant (type
)
2694 type
= TYPE_MAIN_VARIANT (type
);
2696 /* There really should be only one main variant among any group of variants
2697 of a given type (and all of the MAIN_VARIANT values for all members of
2698 the group should point to that one type) but sometimes the C front-end
2699 messes this up for array types, so we work around that bug here. */
2701 if (TREE_CODE (type
) == ARRAY_TYPE
)
2702 while (type
!= TYPE_MAIN_VARIANT (type
))
2703 type
= TYPE_MAIN_VARIANT (type
);
2708 /* Return non-zero if the given type node represents a tagged type. */
2711 is_tagged_type (type
)
2714 register enum tree_code code
= TREE_CODE (type
);
2716 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
2717 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
2720 /* Convert a DIE tag into its string name. */
2723 dwarf_tag_name (tag
)
2724 register unsigned tag
;
2728 case DW_TAG_padding
:
2729 return "DW_TAG_padding";
2730 case DW_TAG_array_type
:
2731 return "DW_TAG_array_type";
2732 case DW_TAG_class_type
:
2733 return "DW_TAG_class_type";
2734 case DW_TAG_entry_point
:
2735 return "DW_TAG_entry_point";
2736 case DW_TAG_enumeration_type
:
2737 return "DW_TAG_enumeration_type";
2738 case DW_TAG_formal_parameter
:
2739 return "DW_TAG_formal_parameter";
2740 case DW_TAG_imported_declaration
:
2741 return "DW_TAG_imported_declaration";
2743 return "DW_TAG_label";
2744 case DW_TAG_lexical_block
:
2745 return "DW_TAG_lexical_block";
2747 return "DW_TAG_member";
2748 case DW_TAG_pointer_type
:
2749 return "DW_TAG_pointer_type";
2750 case DW_TAG_reference_type
:
2751 return "DW_TAG_reference_type";
2752 case DW_TAG_compile_unit
:
2753 return "DW_TAG_compile_unit";
2754 case DW_TAG_string_type
:
2755 return "DW_TAG_string_type";
2756 case DW_TAG_structure_type
:
2757 return "DW_TAG_structure_type";
2758 case DW_TAG_subroutine_type
:
2759 return "DW_TAG_subroutine_type";
2760 case DW_TAG_typedef
:
2761 return "DW_TAG_typedef";
2762 case DW_TAG_union_type
:
2763 return "DW_TAG_union_type";
2764 case DW_TAG_unspecified_parameters
:
2765 return "DW_TAG_unspecified_parameters";
2766 case DW_TAG_variant
:
2767 return "DW_TAG_variant";
2768 case DW_TAG_common_block
:
2769 return "DW_TAG_common_block";
2770 case DW_TAG_common_inclusion
:
2771 return "DW_TAG_common_inclusion";
2772 case DW_TAG_inheritance
:
2773 return "DW_TAG_inheritance";
2774 case DW_TAG_inlined_subroutine
:
2775 return "DW_TAG_inlined_subroutine";
2777 return "DW_TAG_module";
2778 case DW_TAG_ptr_to_member_type
:
2779 return "DW_TAG_ptr_to_member_type";
2780 case DW_TAG_set_type
:
2781 return "DW_TAG_set_type";
2782 case DW_TAG_subrange_type
:
2783 return "DW_TAG_subrange_type";
2784 case DW_TAG_with_stmt
:
2785 return "DW_TAG_with_stmt";
2786 case DW_TAG_access_declaration
:
2787 return "DW_TAG_access_declaration";
2788 case DW_TAG_base_type
:
2789 return "DW_TAG_base_type";
2790 case DW_TAG_catch_block
:
2791 return "DW_TAG_catch_block";
2792 case DW_TAG_const_type
:
2793 return "DW_TAG_const_type";
2794 case DW_TAG_constant
:
2795 return "DW_TAG_constant";
2796 case DW_TAG_enumerator
:
2797 return "DW_TAG_enumerator";
2798 case DW_TAG_file_type
:
2799 return "DW_TAG_file_type";
2801 return "DW_TAG_friend";
2802 case DW_TAG_namelist
:
2803 return "DW_TAG_namelist";
2804 case DW_TAG_namelist_item
:
2805 return "DW_TAG_namelist_item";
2806 case DW_TAG_packed_type
:
2807 return "DW_TAG_packed_type";
2808 case DW_TAG_subprogram
:
2809 return "DW_TAG_subprogram";
2810 case DW_TAG_template_type_param
:
2811 return "DW_TAG_template_type_param";
2812 case DW_TAG_template_value_param
:
2813 return "DW_TAG_template_value_param";
2814 case DW_TAG_thrown_type
:
2815 return "DW_TAG_thrown_type";
2816 case DW_TAG_try_block
:
2817 return "DW_TAG_try_block";
2818 case DW_TAG_variant_part
:
2819 return "DW_TAG_variant_part";
2820 case DW_TAG_variable
:
2821 return "DW_TAG_variable";
2822 case DW_TAG_volatile_type
:
2823 return "DW_TAG_volatile_type";
2824 case DW_TAG_MIPS_loop
:
2825 return "DW_TAG_MIPS_loop";
2826 case DW_TAG_format_label
:
2827 return "DW_TAG_format_label";
2828 case DW_TAG_function_template
:
2829 return "DW_TAG_function_template";
2830 case DW_TAG_class_template
:
2831 return "DW_TAG_class_template";
2833 return "DW_TAG_<unknown>";
2837 /* Convert a DWARF attribute code into its string name. */
2840 dwarf_attr_name (attr
)
2841 register unsigned attr
;
2846 return "DW_AT_sibling";
2847 case DW_AT_location
:
2848 return "DW_AT_location";
2850 return "DW_AT_name";
2851 case DW_AT_ordering
:
2852 return "DW_AT_ordering";
2853 case DW_AT_subscr_data
:
2854 return "DW_AT_subscr_data";
2855 case DW_AT_byte_size
:
2856 return "DW_AT_byte_size";
2857 case DW_AT_bit_offset
:
2858 return "DW_AT_bit_offset";
2859 case DW_AT_bit_size
:
2860 return "DW_AT_bit_size";
2861 case DW_AT_element_list
:
2862 return "DW_AT_element_list";
2863 case DW_AT_stmt_list
:
2864 return "DW_AT_stmt_list";
2866 return "DW_AT_low_pc";
2868 return "DW_AT_high_pc";
2869 case DW_AT_language
:
2870 return "DW_AT_language";
2872 return "DW_AT_member";
2874 return "DW_AT_discr";
2875 case DW_AT_discr_value
:
2876 return "DW_AT_discr_value";
2877 case DW_AT_visibility
:
2878 return "DW_AT_visibility";
2880 return "DW_AT_import";
2881 case DW_AT_string_length
:
2882 return "DW_AT_string_length";
2883 case DW_AT_common_reference
:
2884 return "DW_AT_common_reference";
2885 case DW_AT_comp_dir
:
2886 return "DW_AT_comp_dir";
2887 case DW_AT_const_value
:
2888 return "DW_AT_const_value";
2889 case DW_AT_containing_type
:
2890 return "DW_AT_containing_type";
2891 case DW_AT_default_value
:
2892 return "DW_AT_default_value";
2894 return "DW_AT_inline";
2895 case DW_AT_is_optional
:
2896 return "DW_AT_is_optional";
2897 case DW_AT_lower_bound
:
2898 return "DW_AT_lower_bound";
2899 case DW_AT_producer
:
2900 return "DW_AT_producer";
2901 case DW_AT_prototyped
:
2902 return "DW_AT_prototyped";
2903 case DW_AT_return_addr
:
2904 return "DW_AT_return_addr";
2905 case DW_AT_start_scope
:
2906 return "DW_AT_start_scope";
2907 case DW_AT_stride_size
:
2908 return "DW_AT_stride_size";
2909 case DW_AT_upper_bound
:
2910 return "DW_AT_upper_bound";
2911 case DW_AT_abstract_origin
:
2912 return "DW_AT_abstract_origin";
2913 case DW_AT_accessibility
:
2914 return "DW_AT_accessibility";
2915 case DW_AT_address_class
:
2916 return "DW_AT_address_class";
2917 case DW_AT_artificial
:
2918 return "DW_AT_artificial";
2919 case DW_AT_base_types
:
2920 return "DW_AT_base_types";
2921 case DW_AT_calling_convention
:
2922 return "DW_AT_calling_convention";
2924 return "DW_AT_count";
2925 case DW_AT_data_member_location
:
2926 return "DW_AT_data_member_location";
2927 case DW_AT_decl_column
:
2928 return "DW_AT_decl_column";
2929 case DW_AT_decl_file
:
2930 return "DW_AT_decl_file";
2931 case DW_AT_decl_line
:
2932 return "DW_AT_decl_line";
2933 case DW_AT_declaration
:
2934 return "DW_AT_declaration";
2935 case DW_AT_discr_list
:
2936 return "DW_AT_discr_list";
2937 case DW_AT_encoding
:
2938 return "DW_AT_encoding";
2939 case DW_AT_external
:
2940 return "DW_AT_external";
2941 case DW_AT_frame_base
:
2942 return "DW_AT_frame_base";
2944 return "DW_AT_friend";
2945 case DW_AT_identifier_case
:
2946 return "DW_AT_identifier_case";
2947 case DW_AT_macro_info
:
2948 return "DW_AT_macro_info";
2949 case DW_AT_namelist_items
:
2950 return "DW_AT_namelist_items";
2951 case DW_AT_priority
:
2952 return "DW_AT_priority";
2954 return "DW_AT_segment";
2955 case DW_AT_specification
:
2956 return "DW_AT_specification";
2957 case DW_AT_static_link
:
2958 return "DW_AT_static_link";
2960 return "DW_AT_type";
2961 case DW_AT_use_location
:
2962 return "DW_AT_use_location";
2963 case DW_AT_variable_parameter
:
2964 return "DW_AT_variable_parameter";
2965 case DW_AT_virtuality
:
2966 return "DW_AT_virtuality";
2967 case DW_AT_vtable_elem_location
:
2968 return "DW_AT_vtable_elem_location";
2970 case DW_AT_MIPS_fde
:
2971 return "DW_AT_MIPS_fde";
2972 case DW_AT_MIPS_loop_begin
:
2973 return "DW_AT_MIPS_loop_begin";
2974 case DW_AT_MIPS_tail_loop_begin
:
2975 return "DW_AT_MIPS_tail_loop_begin";
2976 case DW_AT_MIPS_epilog_begin
:
2977 return "DW_AT_MIPS_epilog_begin";
2978 case DW_AT_MIPS_loop_unroll_factor
:
2979 return "DW_AT_MIPS_loop_unroll_factor";
2980 case DW_AT_MIPS_software_pipeline_depth
:
2981 return "DW_AT_MIPS_software_pipeline_depth";
2982 case DW_AT_MIPS_linkage_name
:
2983 return "DW_AT_MIPS_linkage_name";
2984 case DW_AT_MIPS_stride
:
2985 return "DW_AT_MIPS_stride";
2986 case DW_AT_MIPS_abstract_name
:
2987 return "DW_AT_MIPS_abstract_name";
2988 case DW_AT_MIPS_clone_origin
:
2989 return "DW_AT_MIPS_clone_origin";
2990 case DW_AT_MIPS_has_inlines
:
2991 return "DW_AT_MIPS_has_inlines";
2993 case DW_AT_sf_names
:
2994 return "DW_AT_sf_names";
2995 case DW_AT_src_info
:
2996 return "DW_AT_src_info";
2997 case DW_AT_mac_info
:
2998 return "DW_AT_mac_info";
2999 case DW_AT_src_coords
:
3000 return "DW_AT_src_coords";
3001 case DW_AT_body_begin
:
3002 return "DW_AT_body_begin";
3003 case DW_AT_body_end
:
3004 return "DW_AT_body_end";
3006 return "DW_AT_<unknown>";
3010 /* Convert a DWARF value form code into its string name. */
3013 dwarf_form_name (form
)
3014 register unsigned form
;
3019 return "DW_FORM_addr";
3020 case DW_FORM_block2
:
3021 return "DW_FORM_block2";
3022 case DW_FORM_block4
:
3023 return "DW_FORM_block4";
3025 return "DW_FORM_data2";
3027 return "DW_FORM_data4";
3029 return "DW_FORM_data8";
3030 case DW_FORM_string
:
3031 return "DW_FORM_string";
3033 return "DW_FORM_block";
3034 case DW_FORM_block1
:
3035 return "DW_FORM_block1";
3037 return "DW_FORM_data1";
3039 return "DW_FORM_flag";
3041 return "DW_FORM_sdata";
3043 return "DW_FORM_strp";
3045 return "DW_FORM_udata";
3046 case DW_FORM_ref_addr
:
3047 return "DW_FORM_ref_addr";
3049 return "DW_FORM_ref1";
3051 return "DW_FORM_ref2";
3053 return "DW_FORM_ref4";
3055 return "DW_FORM_ref8";
3056 case DW_FORM_ref_udata
:
3057 return "DW_FORM_ref_udata";
3058 case DW_FORM_indirect
:
3059 return "DW_FORM_indirect";
3061 return "DW_FORM_<unknown>";
3065 /* Convert a DWARF stack opcode into its string name. */
3068 dwarf_stack_op_name (op
)
3069 register unsigned op
;
3074 return "DW_OP_addr";
3076 return "DW_OP_deref";
3078 return "DW_OP_const1u";
3080 return "DW_OP_const1s";
3082 return "DW_OP_const2u";
3084 return "DW_OP_const2s";
3086 return "DW_OP_const4u";
3088 return "DW_OP_const4s";
3090 return "DW_OP_const8u";
3092 return "DW_OP_const8s";
3094 return "DW_OP_constu";
3096 return "DW_OP_consts";
3100 return "DW_OP_drop";
3102 return "DW_OP_over";
3104 return "DW_OP_pick";
3106 return "DW_OP_swap";
3110 return "DW_OP_xderef";
3118 return "DW_OP_minus";
3130 return "DW_OP_plus";
3131 case DW_OP_plus_uconst
:
3132 return "DW_OP_plus_uconst";
3138 return "DW_OP_shra";
3156 return "DW_OP_skip";
3158 return "DW_OP_lit0";
3160 return "DW_OP_lit1";
3162 return "DW_OP_lit2";
3164 return "DW_OP_lit3";
3166 return "DW_OP_lit4";
3168 return "DW_OP_lit5";
3170 return "DW_OP_lit6";
3172 return "DW_OP_lit7";
3174 return "DW_OP_lit8";
3176 return "DW_OP_lit9";
3178 return "DW_OP_lit10";
3180 return "DW_OP_lit11";
3182 return "DW_OP_lit12";
3184 return "DW_OP_lit13";
3186 return "DW_OP_lit14";
3188 return "DW_OP_lit15";
3190 return "DW_OP_lit16";
3192 return "DW_OP_lit17";
3194 return "DW_OP_lit18";
3196 return "DW_OP_lit19";
3198 return "DW_OP_lit20";
3200 return "DW_OP_lit21";
3202 return "DW_OP_lit22";
3204 return "DW_OP_lit23";
3206 return "DW_OP_lit24";
3208 return "DW_OP_lit25";
3210 return "DW_OP_lit26";
3212 return "DW_OP_lit27";
3214 return "DW_OP_lit28";
3216 return "DW_OP_lit29";
3218 return "DW_OP_lit30";
3220 return "DW_OP_lit31";
3222 return "DW_OP_reg0";
3224 return "DW_OP_reg1";
3226 return "DW_OP_reg2";
3228 return "DW_OP_reg3";
3230 return "DW_OP_reg4";
3232 return "DW_OP_reg5";
3234 return "DW_OP_reg6";
3236 return "DW_OP_reg7";
3238 return "DW_OP_reg8";
3240 return "DW_OP_reg9";
3242 return "DW_OP_reg10";
3244 return "DW_OP_reg11";
3246 return "DW_OP_reg12";
3248 return "DW_OP_reg13";
3250 return "DW_OP_reg14";
3252 return "DW_OP_reg15";
3254 return "DW_OP_reg16";
3256 return "DW_OP_reg17";
3258 return "DW_OP_reg18";
3260 return "DW_OP_reg19";
3262 return "DW_OP_reg20";
3264 return "DW_OP_reg21";
3266 return "DW_OP_reg22";
3268 return "DW_OP_reg23";
3270 return "DW_OP_reg24";
3272 return "DW_OP_reg25";
3274 return "DW_OP_reg26";
3276 return "DW_OP_reg27";
3278 return "DW_OP_reg28";
3280 return "DW_OP_reg29";
3282 return "DW_OP_reg30";
3284 return "DW_OP_reg31";
3286 return "DW_OP_breg0";
3288 return "DW_OP_breg1";
3290 return "DW_OP_breg2";
3292 return "DW_OP_breg3";
3294 return "DW_OP_breg4";
3296 return "DW_OP_breg5";
3298 return "DW_OP_breg6";
3300 return "DW_OP_breg7";
3302 return "DW_OP_breg8";
3304 return "DW_OP_breg9";
3306 return "DW_OP_breg10";
3308 return "DW_OP_breg11";
3310 return "DW_OP_breg12";
3312 return "DW_OP_breg13";
3314 return "DW_OP_breg14";
3316 return "DW_OP_breg15";
3318 return "DW_OP_breg16";
3320 return "DW_OP_breg17";
3322 return "DW_OP_breg18";
3324 return "DW_OP_breg19";
3326 return "DW_OP_breg20";
3328 return "DW_OP_breg21";
3330 return "DW_OP_breg22";
3332 return "DW_OP_breg23";
3334 return "DW_OP_breg24";
3336 return "DW_OP_breg25";
3338 return "DW_OP_breg26";
3340 return "DW_OP_breg27";
3342 return "DW_OP_breg28";
3344 return "DW_OP_breg29";
3346 return "DW_OP_breg30";
3348 return "DW_OP_breg31";
3350 return "DW_OP_regx";
3352 return "DW_OP_fbreg";
3354 return "DW_OP_bregx";
3356 return "DW_OP_piece";
3357 case DW_OP_deref_size
:
3358 return "DW_OP_deref_size";
3359 case DW_OP_xderef_size
:
3360 return "DW_OP_xderef_size";
3364 return "OP_<unknown>";
3368 /* Convert a DWARF type code into its string name. */
3372 dwarf_type_encoding_name (enc
)
3373 register unsigned enc
;
3377 case DW_ATE_address
:
3378 return "DW_ATE_address";
3379 case DW_ATE_boolean
:
3380 return "DW_ATE_boolean";
3381 case DW_ATE_complex_float
:
3382 return "DW_ATE_complex_float";
3384 return "DW_ATE_float";
3386 return "DW_ATE_signed";
3387 case DW_ATE_signed_char
:
3388 return "DW_ATE_signed_char";
3389 case DW_ATE_unsigned
:
3390 return "DW_ATE_unsigned";
3391 case DW_ATE_unsigned_char
:
3392 return "DW_ATE_unsigned_char";
3394 return "DW_ATE_<unknown>";
3399 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3400 instance of an inlined instance of a decl which is local to an inline
3401 function, so we have to trace all of the way back through the origin chain
3402 to find out what sort of node actually served as the original seed for the
3406 decl_ultimate_origin (decl
)
3409 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3410 nodes in the function to point to themselves; ignore that if
3411 we're trying to output the abstract instance of this function. */
3412 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3415 #ifdef ENABLE_CHECKING
3416 if (DECL_FROM_INLINE (DECL_ORIGIN (decl
)))
3417 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3418 most distant ancestor, this should never happen. */
3422 return DECL_ABSTRACT_ORIGIN (decl
);
3425 /* Determine the "ultimate origin" of a block. The block may be an inlined
3426 instance of an inlined instance of a block which is local to an inline
3427 function, so we have to trace all of the way back through the origin chain
3428 to find out what sort of node actually served as the original seed for the
3432 block_ultimate_origin (block
)
3433 register tree block
;
3435 register tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
3437 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
3438 nodes in the function to point to themselves; ignore that if
3439 we're trying to output the abstract instance of this function. */
3440 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
3443 if (immediate_origin
== NULL_TREE
)
3447 register tree ret_val
;
3448 register tree lookahead
= immediate_origin
;
3452 ret_val
= lookahead
;
3453 lookahead
= (TREE_CODE (ret_val
) == BLOCK
)
3454 ? BLOCK_ABSTRACT_ORIGIN (ret_val
)
3457 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
3463 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3464 of a virtual function may refer to a base class, so we check the 'this'
3468 decl_class_context (decl
)
3471 tree context
= NULL_TREE
;
3473 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3474 context
= DECL_CONTEXT (decl
);
3476 context
= TYPE_MAIN_VARIANT
3477 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3479 if (context
&& TREE_CODE_CLASS (TREE_CODE (context
)) != 't')
3480 context
= NULL_TREE
;
3485 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
3486 addition order, and correct that in add_sibling_attributes. */
3489 add_dwarf_attr (die
, attr
)
3490 register dw_die_ref die
;
3491 register dw_attr_ref attr
;
3493 if (die
!= NULL
&& attr
!= NULL
)
3495 attr
->dw_attr_next
= die
->die_attr
;
3496 die
->die_attr
= attr
;
3500 static inline dw_val_class AT_class
PARAMS ((dw_attr_ref
));
3501 static inline dw_val_class
3505 return a
->dw_attr_val
.val_class
;
3508 /* Add a flag value attribute to a DIE. */
3511 add_AT_flag (die
, attr_kind
, flag
)
3512 register dw_die_ref die
;
3513 register enum dwarf_attribute attr_kind
;
3514 register unsigned flag
;
3516 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3518 attr
->dw_attr_next
= NULL
;
3519 attr
->dw_attr
= attr_kind
;
3520 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
3521 attr
->dw_attr_val
.v
.val_flag
= flag
;
3522 add_dwarf_attr (die
, attr
);
3525 static inline unsigned AT_flag
PARAMS ((dw_attr_ref
));
3526 static inline unsigned
3528 register dw_attr_ref a
;
3530 if (a
&& AT_class (a
) == dw_val_class_flag
)
3531 return a
->dw_attr_val
.v
.val_flag
;
3536 /* Add a signed integer attribute value to a DIE. */
3539 add_AT_int (die
, attr_kind
, int_val
)
3540 register dw_die_ref die
;
3541 register enum dwarf_attribute attr_kind
;
3542 register long int int_val
;
3544 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3546 attr
->dw_attr_next
= NULL
;
3547 attr
->dw_attr
= attr_kind
;
3548 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
3549 attr
->dw_attr_val
.v
.val_int
= int_val
;
3550 add_dwarf_attr (die
, attr
);
3553 static inline long int AT_int
PARAMS ((dw_attr_ref
));
3554 static inline long int
3556 register dw_attr_ref a
;
3558 if (a
&& AT_class (a
) == dw_val_class_const
)
3559 return a
->dw_attr_val
.v
.val_int
;
3564 /* Add an unsigned integer attribute value to a DIE. */
3567 add_AT_unsigned (die
, attr_kind
, unsigned_val
)
3568 register dw_die_ref die
;
3569 register enum dwarf_attribute attr_kind
;
3570 register unsigned long unsigned_val
;
3572 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3574 attr
->dw_attr_next
= NULL
;
3575 attr
->dw_attr
= attr_kind
;
3576 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3577 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3578 add_dwarf_attr (die
, attr
);
3581 static inline unsigned long AT_unsigned
PARAMS ((dw_attr_ref
));
3582 static inline unsigned long
3584 register dw_attr_ref a
;
3586 if (a
&& AT_class (a
) == dw_val_class_unsigned_const
)
3587 return a
->dw_attr_val
.v
.val_unsigned
;
3592 /* Add an unsigned double integer attribute value to a DIE. */
3595 add_AT_long_long (die
, attr_kind
, val_hi
, val_low
)
3596 register dw_die_ref die
;
3597 register enum dwarf_attribute attr_kind
;
3598 register unsigned long val_hi
;
3599 register unsigned long val_low
;
3601 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3603 attr
->dw_attr_next
= NULL
;
3604 attr
->dw_attr
= attr_kind
;
3605 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
3606 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
3607 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
3608 add_dwarf_attr (die
, attr
);
3611 /* Add a floating point attribute value to a DIE and return it. */
3614 add_AT_float (die
, attr_kind
, length
, array
)
3615 register dw_die_ref die
;
3616 register enum dwarf_attribute attr_kind
;
3617 register unsigned length
;
3618 register long *array
;
3620 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3622 attr
->dw_attr_next
= NULL
;
3623 attr
->dw_attr
= attr_kind
;
3624 attr
->dw_attr_val
.val_class
= dw_val_class_float
;
3625 attr
->dw_attr_val
.v
.val_float
.length
= length
;
3626 attr
->dw_attr_val
.v
.val_float
.array
= array
;
3627 add_dwarf_attr (die
, attr
);
3630 /* Add a string attribute value to a DIE. */
3633 add_AT_string (die
, attr_kind
, str
)
3634 register dw_die_ref die
;
3635 register enum dwarf_attribute attr_kind
;
3636 register const char *str
;
3638 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3640 attr
->dw_attr_next
= NULL
;
3641 attr
->dw_attr
= attr_kind
;
3642 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
3643 attr
->dw_attr_val
.v
.val_str
= xstrdup (str
);
3644 add_dwarf_attr (die
, attr
);
3647 static inline const char *AT_string
PARAMS ((dw_attr_ref
));
3648 static inline const char *
3650 register dw_attr_ref a
;
3652 if (a
&& AT_class (a
) == dw_val_class_str
)
3653 return a
->dw_attr_val
.v
.val_str
;
3658 /* Add a DIE reference attribute value to a DIE. */
3661 add_AT_die_ref (die
, attr_kind
, targ_die
)
3662 register dw_die_ref die
;
3663 register enum dwarf_attribute attr_kind
;
3664 register dw_die_ref targ_die
;
3666 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3668 attr
->dw_attr_next
= NULL
;
3669 attr
->dw_attr
= attr_kind
;
3670 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
3671 attr
->dw_attr_val
.v
.val_die_ref
= targ_die
;
3672 add_dwarf_attr (die
, attr
);
3675 static inline dw_die_ref AT_ref
PARAMS ((dw_attr_ref
));
3676 static inline dw_die_ref
3678 register dw_attr_ref a
;
3680 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
3681 return a
->dw_attr_val
.v
.val_die_ref
;
3686 /* Add an FDE reference attribute value to a DIE. */
3689 add_AT_fde_ref (die
, attr_kind
, targ_fde
)
3690 register dw_die_ref die
;
3691 register enum dwarf_attribute attr_kind
;
3692 register unsigned targ_fde
;
3694 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3696 attr
->dw_attr_next
= NULL
;
3697 attr
->dw_attr
= attr_kind
;
3698 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
3699 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
3700 add_dwarf_attr (die
, attr
);
3703 /* Add a location description attribute value to a DIE. */
3706 add_AT_loc (die
, attr_kind
, loc
)
3707 register dw_die_ref die
;
3708 register enum dwarf_attribute attr_kind
;
3709 register dw_loc_descr_ref loc
;
3711 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3713 attr
->dw_attr_next
= NULL
;
3714 attr
->dw_attr
= attr_kind
;
3715 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
3716 attr
->dw_attr_val
.v
.val_loc
= loc
;
3717 add_dwarf_attr (die
, attr
);
3720 static inline dw_loc_descr_ref AT_loc
PARAMS ((dw_attr_ref
));
3721 static inline dw_loc_descr_ref
3723 register dw_attr_ref a
;
3725 if (a
&& AT_class (a
) == dw_val_class_loc
)
3726 return a
->dw_attr_val
.v
.val_loc
;
3731 /* Add an address constant attribute value to a DIE. */
3734 add_AT_addr (die
, attr_kind
, addr
)
3735 register dw_die_ref die
;
3736 register enum dwarf_attribute attr_kind
;
3739 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3741 attr
->dw_attr_next
= NULL
;
3742 attr
->dw_attr
= attr_kind
;
3743 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
3744 attr
->dw_attr_val
.v
.val_addr
= addr
;
3745 add_dwarf_attr (die
, attr
);
3748 static inline rtx AT_addr
PARAMS ((dw_attr_ref
));
3751 register dw_attr_ref a
;
3753 if (a
&& AT_class (a
) == dw_val_class_addr
)
3754 return a
->dw_attr_val
.v
.val_addr
;
3759 /* Add a label identifier attribute value to a DIE. */
3762 add_AT_lbl_id (die
, attr_kind
, lbl_id
)
3763 register dw_die_ref die
;
3764 register enum dwarf_attribute attr_kind
;
3765 register char *lbl_id
;
3767 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3769 attr
->dw_attr_next
= NULL
;
3770 attr
->dw_attr
= attr_kind
;
3771 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3772 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
3773 add_dwarf_attr (die
, attr
);
3776 /* Add a section offset attribute value to a DIE. */
3779 add_AT_lbl_offset (die
, attr_kind
, label
)
3780 register dw_die_ref die
;
3781 register enum dwarf_attribute attr_kind
;
3782 register char *label
;
3784 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3786 attr
->dw_attr_next
= NULL
;
3787 attr
->dw_attr
= attr_kind
;
3788 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_offset
;
3789 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
3790 add_dwarf_attr (die
, attr
);
3794 static inline const char *AT_lbl
PARAMS ((dw_attr_ref
));
3795 static inline const char *
3797 register dw_attr_ref a
;
3799 if (a
&& (AT_class (a
) == dw_val_class_lbl_id
3800 || AT_class (a
) == dw_val_class_lbl_offset
))
3801 return a
->dw_attr_val
.v
.val_lbl_id
;
3806 /* Get the attribute of type attr_kind. */
3808 static inline dw_attr_ref
3809 get_AT (die
, attr_kind
)
3810 register dw_die_ref die
;
3811 register enum dwarf_attribute attr_kind
;
3813 register dw_attr_ref a
;
3814 register dw_die_ref spec
= NULL
;
3818 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
3820 if (a
->dw_attr
== attr_kind
)
3823 if (a
->dw_attr
== DW_AT_specification
3824 || a
->dw_attr
== DW_AT_abstract_origin
)
3829 return get_AT (spec
, attr_kind
);
3835 /* Return the "low pc" attribute value, typically associated with
3836 a subprogram DIE. Return null if the "low pc" attribute is
3837 either not prsent, or if it cannot be represented as an
3838 assembler label identifier. */
3840 static inline const char *
3842 register dw_die_ref die
;
3844 register dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
3848 /* Return the "high pc" attribute value, typically associated with
3849 a subprogram DIE. Return null if the "high pc" attribute is
3850 either not prsent, or if it cannot be represented as an
3851 assembler label identifier. */
3853 static inline const char *
3855 register dw_die_ref die
;
3857 register dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
3861 /* Return the value of the string attribute designated by ATTR_KIND, or
3862 NULL if it is not present. */
3864 static inline const char *
3865 get_AT_string (die
, attr_kind
)
3866 register dw_die_ref die
;
3867 register enum dwarf_attribute attr_kind
;
3869 register dw_attr_ref a
= get_AT (die
, attr_kind
);
3870 return AT_string (a
);
3873 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3874 if it is not present. */
3877 get_AT_flag (die
, attr_kind
)
3878 register dw_die_ref die
;
3879 register enum dwarf_attribute attr_kind
;
3881 register dw_attr_ref a
= get_AT (die
, attr_kind
);
3885 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3886 if it is not present. */
3888 static inline unsigned
3889 get_AT_unsigned (die
, attr_kind
)
3890 register dw_die_ref die
;
3891 register enum dwarf_attribute attr_kind
;
3893 register dw_attr_ref a
= get_AT (die
, attr_kind
);
3894 return AT_unsigned (a
);
3897 static inline dw_die_ref
3898 get_AT_ref (die
, attr_kind
)
3900 register enum dwarf_attribute attr_kind
;
3902 register dw_attr_ref a
= get_AT (die
, attr_kind
);
3909 register unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
3911 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
3912 || lang
== DW_LANG_C_plus_plus
);
3918 register unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
3920 return (lang
== DW_LANG_Fortran77
|| lang
== DW_LANG_Fortran90
);
3923 /* Free up the memory used by A. */
3925 static inline void free_AT
PARAMS ((dw_attr_ref
));
3930 switch (AT_class (a
))
3932 case dw_val_class_str
:
3933 case dw_val_class_lbl_id
:
3934 case dw_val_class_lbl_offset
:
3935 free (a
->dw_attr_val
.v
.val_str
);
3945 /* Remove the specified attribute if present. */
3948 remove_AT (die
, attr_kind
)
3949 register dw_die_ref die
;
3950 register enum dwarf_attribute attr_kind
;
3952 register dw_attr_ref
*p
;
3953 register dw_attr_ref removed
= NULL
;
3957 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
3958 if ((*p
)->dw_attr
== attr_kind
)
3961 *p
= (*p
)->dw_attr_next
;
3970 /* Free up the memory used by DIE. */
3972 static inline void free_die
PARAMS ((dw_die_ref
));
3977 remove_children (die
);
3981 /* Discard the children of this DIE. */
3984 remove_children (die
)
3985 register dw_die_ref die
;
3987 register dw_die_ref child_die
= die
->die_child
;
3989 die
->die_child
= NULL
;
3991 while (child_die
!= NULL
)
3993 register dw_die_ref tmp_die
= child_die
;
3994 register dw_attr_ref a
;
3996 child_die
= child_die
->die_sib
;
3998 for (a
= tmp_die
->die_attr
; a
!= NULL
; )
4000 register dw_attr_ref tmp_a
= a
;
4002 a
= a
->dw_attr_next
;
4010 /* Add a child DIE below its parent. We build the lists up in reverse
4011 addition order, and correct that in add_sibling_attributes. */
4014 add_child_die (die
, child_die
)
4015 register dw_die_ref die
;
4016 register dw_die_ref child_die
;
4018 if (die
!= NULL
&& child_die
!= NULL
)
4020 if (die
== child_die
)
4022 child_die
->die_parent
= die
;
4023 child_die
->die_sib
= die
->die_child
;
4024 die
->die_child
= child_die
;
4028 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4029 is the specification, to the front of PARENT's list of children. */
4032 splice_child_die (parent
, child
)
4033 dw_die_ref parent
, child
;
4037 /* We want the declaration DIE from inside the class, not the
4038 specification DIE at toplevel. */
4039 if (child
->die_parent
!= parent
)
4041 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4046 if (child
->die_parent
!= parent
4047 && child
->die_parent
!= get_AT_ref (parent
, DW_AT_specification
))
4050 for (p
= &(parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
4053 *p
= child
->die_sib
;
4057 child
->die_sib
= parent
->die_child
;
4058 parent
->die_child
= child
;
4061 /* Return a pointer to a newly created DIE node. */
4063 static inline dw_die_ref
4064 new_die (tag_value
, parent_die
)
4065 register enum dwarf_tag tag_value
;
4066 register dw_die_ref parent_die
;
4068 register dw_die_ref die
= (dw_die_ref
) xmalloc (sizeof (die_node
));
4070 die
->die_tag
= tag_value
;
4071 die
->die_abbrev
= 0;
4072 die
->die_offset
= 0;
4073 die
->die_child
= NULL
;
4074 die
->die_parent
= NULL
;
4075 die
->die_sib
= NULL
;
4076 die
->die_attr
= NULL
;
4078 if (parent_die
!= NULL
)
4079 add_child_die (parent_die
, die
);
4082 limbo_die_node
*limbo_node
;
4084 limbo_node
= (limbo_die_node
*) xmalloc (sizeof (limbo_die_node
));
4085 limbo_node
->die
= die
;
4086 limbo_node
->next
= limbo_die_list
;
4087 limbo_die_list
= limbo_node
;
4093 /* Return the DIE associated with the given type specifier. */
4095 static inline dw_die_ref
4096 lookup_type_die (type
)
4099 return (dw_die_ref
) TYPE_SYMTAB_POINTER (type
);
4102 /* Equate a DIE to a given type specifier. */
4105 equate_type_number_to_die (type
, type_die
)
4107 register dw_die_ref type_die
;
4109 TYPE_SYMTAB_POINTER (type
) = (char *) type_die
;
4112 /* Return the DIE associated with a given declaration. */
4114 static inline dw_die_ref
4115 lookup_decl_die (decl
)
4118 register unsigned decl_id
= DECL_UID (decl
);
4120 return (decl_id
< decl_die_table_in_use
4121 ? decl_die_table
[decl_id
] : NULL
);
4124 /* Equate a DIE to a particular declaration. */
4127 equate_decl_number_to_die (decl
, decl_die
)
4129 register dw_die_ref decl_die
;
4131 register unsigned decl_id
= DECL_UID (decl
);
4132 register unsigned num_allocated
;
4134 if (decl_id
>= decl_die_table_allocated
)
4137 = ((decl_id
+ 1 + DECL_DIE_TABLE_INCREMENT
- 1)
4138 / DECL_DIE_TABLE_INCREMENT
)
4139 * DECL_DIE_TABLE_INCREMENT
;
4142 = (dw_die_ref
*) xrealloc (decl_die_table
,
4143 sizeof (dw_die_ref
) * num_allocated
);
4145 bzero ((char *) &decl_die_table
[decl_die_table_allocated
],
4146 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
4147 decl_die_table_allocated
= num_allocated
;
4150 if (decl_id
>= decl_die_table_in_use
)
4151 decl_die_table_in_use
= (decl_id
+ 1);
4153 decl_die_table
[decl_id
] = decl_die
;
4156 /* Return a pointer to a newly allocated location description. Location
4157 descriptions are simple expression terms that can be strung
4158 together to form more complicated location (address) descriptions. */
4160 static inline dw_loc_descr_ref
4161 new_loc_descr (op
, oprnd1
, oprnd2
)
4162 register enum dwarf_location_atom op
;
4163 register unsigned long oprnd1
;
4164 register unsigned long oprnd2
;
4166 register dw_loc_descr_ref descr
4167 = (dw_loc_descr_ref
) xmalloc (sizeof (dw_loc_descr_node
));
4169 descr
->dw_loc_next
= NULL
;
4170 descr
->dw_loc_opc
= op
;
4171 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
4172 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
4173 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
4174 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
4179 /* Add a location description term to a location description expression. */
4182 add_loc_descr (list_head
, descr
)
4183 register dw_loc_descr_ref
*list_head
;
4184 register dw_loc_descr_ref descr
;
4186 register dw_loc_descr_ref
*d
;
4188 /* Find the end of the chain. */
4189 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
4195 /* Keep track of the number of spaces used to indent the
4196 output of the debugging routines that print the structure of
4197 the DIE internal representation. */
4198 static int print_indent
;
4200 /* Indent the line the number of spaces given by print_indent. */
4203 print_spaces (outfile
)
4206 fprintf (outfile
, "%*s", print_indent
, "");
4209 /* Print the information associated with a given DIE, and its children.
4210 This routine is a debugging aid only. */
4213 print_die (die
, outfile
)
4217 register dw_attr_ref a
;
4218 register dw_die_ref c
;
4220 print_spaces (outfile
);
4221 fprintf (outfile
, "DIE %4lu: %s\n",
4222 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
4223 print_spaces (outfile
);
4224 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
4225 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
4227 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4229 print_spaces (outfile
);
4230 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
4232 switch (AT_class (a
))
4234 case dw_val_class_addr
:
4235 fprintf (outfile
, "address");
4237 case dw_val_class_loc
:
4238 fprintf (outfile
, "location descriptor");
4240 case dw_val_class_const
:
4241 fprintf (outfile
, "%ld", AT_int (a
));
4243 case dw_val_class_unsigned_const
:
4244 fprintf (outfile
, "%lu", AT_unsigned (a
));
4246 case dw_val_class_long_long
:
4247 fprintf (outfile
, "constant (%lu,%lu)",
4248 a
->dw_attr_val
.v
.val_long_long
.hi
,
4249 a
->dw_attr_val
.v
.val_long_long
.low
);
4251 case dw_val_class_float
:
4252 fprintf (outfile
, "floating-point constant");
4254 case dw_val_class_flag
:
4255 fprintf (outfile
, "%u", AT_flag (a
));
4257 case dw_val_class_die_ref
:
4258 if (AT_ref (a
) != NULL
)
4259 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
4261 fprintf (outfile
, "die -> <null>");
4263 case dw_val_class_lbl_id
:
4264 case dw_val_class_lbl_offset
:
4265 fprintf (outfile
, "label: %s", AT_lbl (a
));
4267 case dw_val_class_str
:
4268 if (AT_string (a
) != NULL
)
4269 fprintf (outfile
, "\"%s\"", AT_string (a
));
4271 fprintf (outfile
, "<null>");
4277 fprintf (outfile
, "\n");
4280 if (die
->die_child
!= NULL
)
4283 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4284 print_die (c
, outfile
);
4290 /* Print the contents of the source code line number correspondence table.
4291 This routine is a debugging aid only. */
4294 print_dwarf_line_table (outfile
)
4297 register unsigned i
;
4298 register dw_line_info_ref line_info
;
4300 fprintf (outfile
, "\n\nDWARF source line information\n");
4301 for (i
= 1; i
< line_info_table_in_use
; ++i
)
4303 line_info
= &line_info_table
[i
];
4304 fprintf (outfile
, "%5d: ", i
);
4305 fprintf (outfile
, "%-20s", file_table
[line_info
->dw_file_num
]);
4306 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
4307 fprintf (outfile
, "\n");
4310 fprintf (outfile
, "\n\n");
4313 /* Print the information collected for a given DIE. */
4316 debug_dwarf_die (die
)
4319 print_die (die
, stderr
);
4322 /* Print all DWARF information collected for the compilation unit.
4323 This routine is a debugging aid only. */
4329 print_die (comp_unit_die
, stderr
);
4330 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
4331 print_dwarf_line_table (stderr
);
4334 /* We build up the lists of children and attributes by pushing new ones
4335 onto the beginning of the list. Reverse the lists for DIE so that
4336 they are in order of addition. */
4339 reverse_die_lists (die
)
4340 register dw_die_ref die
;
4342 register dw_die_ref c
, cp
, cn
;
4343 register dw_attr_ref a
, ap
, an
;
4345 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
4347 an
= a
->dw_attr_next
;
4348 a
->dw_attr_next
= ap
;
4353 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
4359 die
->die_child
= cp
;
4362 /* Traverse the DIE, reverse its lists of attributes and children, and
4363 add a sibling attribute if it may have the effect of speeding up
4364 access to siblings. To save some space, avoid generating sibling
4365 attributes for DIE's without children. */
4368 add_sibling_attributes (die
)
4369 register dw_die_ref die
;
4371 register dw_die_ref c
;
4373 reverse_die_lists (die
);
4375 if (die
!= comp_unit_die
&& die
->die_sib
&& die
->die_child
!= NULL
)
4376 /* Add the sibling link to the front of the attribute list. */
4377 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
4379 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4380 add_sibling_attributes (c
);
4383 /* The format of each DIE (and its attribute value pairs)
4384 is encoded in an abbreviation table. This routine builds the
4385 abbreviation table and assigns a unique abbreviation id for
4386 each abbreviation entry. The children of each die are visited
4390 build_abbrev_table (die
)
4391 register dw_die_ref die
;
4393 register unsigned long abbrev_id
;
4394 register unsigned long n_alloc
;
4395 register dw_die_ref c
;
4396 register dw_attr_ref d_attr
, a_attr
;
4397 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
4399 register dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
4401 if (abbrev
->die_tag
== die
->die_tag
)
4403 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
4405 a_attr
= abbrev
->die_attr
;
4406 d_attr
= die
->die_attr
;
4408 while (a_attr
!= NULL
&& d_attr
!= NULL
)
4410 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
4411 || (value_format (a_attr
) != value_format (d_attr
)))
4414 a_attr
= a_attr
->dw_attr_next
;
4415 d_attr
= d_attr
->dw_attr_next
;
4418 if (a_attr
== NULL
&& d_attr
== NULL
)
4424 if (abbrev_id
>= abbrev_die_table_in_use
)
4426 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
4428 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
4430 = (dw_die_ref
*) xrealloc (abbrev_die_table
,
4431 sizeof (dw_die_ref
) * n_alloc
);
4433 bzero ((char *) &abbrev_die_table
[abbrev_die_table_allocated
],
4434 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
4435 abbrev_die_table_allocated
= n_alloc
;
4438 ++abbrev_die_table_in_use
;
4439 abbrev_die_table
[abbrev_id
] = die
;
4442 die
->die_abbrev
= abbrev_id
;
4443 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4444 build_abbrev_table (c
);
4447 /* Return the size of a string, including the null byte.
4449 This used to treat backslashes as escapes, and hence they were not included
4450 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
4451 which treats a backslash as a backslash, escaping it if necessary, and hence
4452 we must include them in the count. */
4454 static unsigned long
4455 size_of_string (str
)
4456 register const char *str
;
4458 return strlen (str
) + 1;
4461 /* Return the size of a location descriptor. */
4463 static unsigned long
4464 size_of_loc_descr (loc
)
4465 register dw_loc_descr_ref loc
;
4467 register unsigned long size
= 1;
4469 switch (loc
->dw_loc_opc
)
4491 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4494 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4499 case DW_OP_plus_uconst
:
4500 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4538 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4541 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4544 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4547 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4548 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
4551 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4553 case DW_OP_deref_size
:
4554 case DW_OP_xderef_size
:
4564 /* Return the size of a series of location descriptors. */
4566 static unsigned long
4568 register dw_loc_descr_ref loc
;
4570 register unsigned long size
= 0;
4572 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
4573 size
+= size_of_loc_descr (loc
);
4578 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4581 constant_size (value
)
4582 long unsigned value
;
4589 log
= floor_log2 (value
);
4592 log
= 1 << (floor_log2 (log
) + 1);
4597 /* Return the size of a DIE, as it is represented in the
4598 .debug_info section. */
4600 static unsigned long
4602 register dw_die_ref die
;
4604 register unsigned long size
= 0;
4605 register dw_attr_ref a
;
4607 size
+= size_of_uleb128 (die
->die_abbrev
);
4608 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4610 switch (AT_class (a
))
4612 case dw_val_class_addr
:
4615 case dw_val_class_loc
:
4617 register unsigned long lsize
= size_of_locs (AT_loc (a
));
4620 size
+= constant_size (lsize
);
4624 case dw_val_class_const
:
4627 case dw_val_class_unsigned_const
:
4628 size
+= constant_size (AT_unsigned (a
));
4630 case dw_val_class_long_long
:
4631 size
+= 1 + 8; /* block */
4633 case dw_val_class_float
:
4634 size
+= 1 + a
->dw_attr_val
.v
.val_float
.length
* 4; /* block */
4636 case dw_val_class_flag
:
4639 case dw_val_class_die_ref
:
4640 size
+= DWARF_OFFSET_SIZE
;
4642 case dw_val_class_fde_ref
:
4643 size
+= DWARF_OFFSET_SIZE
;
4645 case dw_val_class_lbl_id
:
4648 case dw_val_class_lbl_offset
:
4649 size
+= DWARF_OFFSET_SIZE
;
4651 case dw_val_class_str
:
4652 size
+= size_of_string (AT_string (a
));
4662 /* Size the debugging information associated with a given DIE.
4663 Visits the DIE's children recursively. Updates the global
4664 variable next_die_offset, on each time through. Uses the
4665 current value of next_die_offset to update the die_offset
4666 field in each DIE. */
4669 calc_die_sizes (die
)
4672 register dw_die_ref c
;
4673 die
->die_offset
= next_die_offset
;
4674 next_die_offset
+= size_of_die (die
);
4676 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4679 if (die
->die_child
!= NULL
)
4680 /* Count the null byte used to terminate sibling lists. */
4681 next_die_offset
+= 1;
4684 /* Return the size of the line information prolog generated for the
4685 compilation unit. */
4687 static unsigned long
4688 size_of_line_prolog ()
4690 register unsigned long size
;
4691 register unsigned long ft_index
;
4693 size
= DWARF_LINE_PROLOG_HEADER_SIZE
;
4695 /* Count the size of the table giving number of args for each
4697 size
+= DWARF_LINE_OPCODE_BASE
- 1;
4699 /* Include directory table is empty (at present). Count only the
4700 null byte used to terminate the table. */
4703 for (ft_index
= 1; ft_index
< file_table_in_use
; ++ft_index
)
4705 /* File name entry. */
4706 size
+= size_of_string (file_table
[ft_index
]);
4708 /* Include directory index. */
4709 size
+= size_of_uleb128 (0);
4711 /* Modification time. */
4712 size
+= size_of_uleb128 (0);
4714 /* File length in bytes. */
4715 size
+= size_of_uleb128 (0);
4718 /* Count the file table terminator. */
4723 /* Return the size of the .debug_pubnames table generated for the
4724 compilation unit. */
4726 static unsigned long
4729 register unsigned long size
;
4730 register unsigned i
;
4732 size
= DWARF_PUBNAMES_HEADER_SIZE
;
4733 for (i
= 0; i
< pubname_table_in_use
; ++i
)
4735 register pubname_ref p
= &pubname_table
[i
];
4736 size
+= DWARF_OFFSET_SIZE
+ size_of_string (p
->name
);
4739 size
+= DWARF_OFFSET_SIZE
;
4743 /* Return the size of the information in the .debug_aranges section. */
4745 static unsigned long
4748 register unsigned long size
;
4750 size
= DWARF_ARANGES_HEADER_SIZE
;
4752 /* Count the address/length pair for this compilation unit. */
4753 size
+= 2 * PTR_SIZE
;
4754 size
+= 2 * PTR_SIZE
* arange_table_in_use
;
4756 /* Count the two zero words used to terminated the address range table. */
4757 size
+= 2 * PTR_SIZE
;
4761 /* Select the encoding of an attribute value. */
4763 static enum dwarf_form
4767 switch (a
->dw_attr_val
.val_class
)
4769 case dw_val_class_addr
:
4770 return DW_FORM_addr
;
4771 case dw_val_class_loc
:
4772 switch (constant_size (size_of_locs (AT_loc (a
))))
4775 return DW_FORM_block1
;
4777 return DW_FORM_block2
;
4781 case dw_val_class_const
:
4782 return DW_FORM_data4
;
4783 case dw_val_class_unsigned_const
:
4784 switch (constant_size (AT_unsigned (a
)))
4787 return DW_FORM_data1
;
4789 return DW_FORM_data2
;
4791 return DW_FORM_data4
;
4793 return DW_FORM_data8
;
4797 case dw_val_class_long_long
:
4798 return DW_FORM_block1
;
4799 case dw_val_class_float
:
4800 return DW_FORM_block1
;
4801 case dw_val_class_flag
:
4802 return DW_FORM_flag
;
4803 case dw_val_class_die_ref
:
4805 case dw_val_class_fde_ref
:
4806 return DW_FORM_data
;
4807 case dw_val_class_lbl_id
:
4808 return DW_FORM_addr
;
4809 case dw_val_class_lbl_offset
:
4810 return DW_FORM_data
;
4811 case dw_val_class_str
:
4812 return DW_FORM_string
;
4818 /* Output the encoding of an attribute value. */
4821 output_value_format (a
)
4824 enum dwarf_form form
= value_format (a
);
4826 output_uleb128 (form
);
4828 fprintf (asm_out_file
, " (%s)", dwarf_form_name (form
));
4830 fputc ('\n', asm_out_file
);
4833 /* Output the .debug_abbrev section which defines the DIE abbreviation
4837 output_abbrev_section ()
4839 unsigned long abbrev_id
;
4842 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
4844 register dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
4846 output_uleb128 (abbrev_id
);
4848 fprintf (asm_out_file
, " (abbrev code)");
4850 fputc ('\n', asm_out_file
);
4851 output_uleb128 (abbrev
->die_tag
);
4853 fprintf (asm_out_file
, " (TAG: %s)",
4854 dwarf_tag_name (abbrev
->die_tag
));
4856 fputc ('\n', asm_out_file
);
4857 fprintf (asm_out_file
, "\t%s\t0x%x", ASM_BYTE_OP
,
4858 abbrev
->die_child
!= NULL
? DW_children_yes
: DW_children_no
);
4861 fprintf (asm_out_file
, "\t%s %s",
4863 (abbrev
->die_child
!= NULL
4864 ? "DW_children_yes" : "DW_children_no"));
4866 fputc ('\n', asm_out_file
);
4868 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
4869 a_attr
= a_attr
->dw_attr_next
)
4871 output_uleb128 (a_attr
->dw_attr
);
4873 fprintf (asm_out_file
, " (%s)",
4874 dwarf_attr_name (a_attr
->dw_attr
));
4876 fputc ('\n', asm_out_file
);
4877 output_value_format (a_attr
);
4880 fprintf (asm_out_file
, "\t%s\t0,0\n", ASM_BYTE_OP
);
4883 /* Terminate the table. */
4884 fprintf (asm_out_file
, "\t%s\t0\n", ASM_BYTE_OP
);
4887 /* Output location description stack opcode's operands (if any). */
4890 output_loc_operands (loc
)
4891 register dw_loc_descr_ref loc
;
4893 register dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
4894 register dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
4896 switch (loc
->dw_loc_opc
)
4899 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
, val1
->v
.val_addr
);
4900 fputc ('\n', asm_out_file
);
4904 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_flag
);
4905 fputc ('\n', asm_out_file
);
4909 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, val1
->v
.val_int
);
4910 fputc ('\n', asm_out_file
);
4914 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, val1
->v
.val_int
);
4915 fputc ('\n', asm_out_file
);
4920 fputc ('\n', asm_out_file
);
4923 output_uleb128 (val1
->v
.val_unsigned
);
4924 fputc ('\n', asm_out_file
);
4927 output_sleb128 (val1
->v
.val_int
);
4928 fputc ('\n', asm_out_file
);
4931 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_int
);
4932 fputc ('\n', asm_out_file
);
4934 case DW_OP_plus_uconst
:
4935 output_uleb128 (val1
->v
.val_unsigned
);
4936 fputc ('\n', asm_out_file
);
4940 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, val1
->v
.val_int
);
4941 fputc ('\n', asm_out_file
);
4975 output_sleb128 (val1
->v
.val_int
);
4976 fputc ('\n', asm_out_file
);
4979 output_uleb128 (val1
->v
.val_unsigned
);
4980 fputc ('\n', asm_out_file
);
4983 output_sleb128 (val1
->v
.val_int
);
4984 fputc ('\n', asm_out_file
);
4987 output_uleb128 (val1
->v
.val_unsigned
);
4988 fputc ('\n', asm_out_file
);
4989 output_sleb128 (val2
->v
.val_int
);
4990 fputc ('\n', asm_out_file
);
4993 output_uleb128 (val1
->v
.val_unsigned
);
4994 fputc ('\n', asm_out_file
);
4996 case DW_OP_deref_size
:
4997 case DW_OP_xderef_size
:
4998 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_flag
);
4999 fputc ('\n', asm_out_file
);
5006 /* Output the DIE and its attributes. Called recursively to generate
5007 the definitions of each child DIE. */
5011 register dw_die_ref die
;
5013 register dw_attr_ref a
;
5014 register dw_die_ref c
;
5015 register unsigned long size
;
5016 register dw_loc_descr_ref loc
;
5018 output_uleb128 (die
->die_abbrev
);
5020 fprintf (asm_out_file
, " (DIE (0x%lx) %s)",
5021 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5023 fputc ('\n', asm_out_file
);
5025 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5027 switch (AT_class (a
))
5029 case dw_val_class_addr
:
5030 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
, AT_addr (a
));
5033 case dw_val_class_loc
:
5034 size
= size_of_locs (AT_loc (a
));
5036 /* Output the block length for this list of location operations. */
5037 switch (constant_size (size
))
5040 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, size
);
5043 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, size
);
5050 fprintf (asm_out_file
, "\t%s %s",
5051 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5053 fputc ('\n', asm_out_file
);
5054 for (loc
= AT_loc (a
); loc
!= NULL
; loc
= loc
->dw_loc_next
)
5056 /* Output the opcode. */
5057 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, loc
->dw_loc_opc
);
5059 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
,
5060 dwarf_stack_op_name (loc
->dw_loc_opc
));
5062 fputc ('\n', asm_out_file
);
5064 /* Output the operand(s) (if any). */
5065 output_loc_operands (loc
);
5069 case dw_val_class_const
:
5070 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, AT_int (a
));
5073 case dw_val_class_unsigned_const
:
5074 switch (constant_size (AT_unsigned (a
)))
5077 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, AT_unsigned (a
));
5080 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, AT_unsigned (a
));
5083 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, AT_unsigned (a
));
5086 ASM_OUTPUT_DWARF_DATA8 (asm_out_file
,
5087 a
->dw_attr_val
.v
.val_long_long
.hi
,
5088 a
->dw_attr_val
.v
.val_long_long
.low
);
5095 case dw_val_class_long_long
:
5096 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 8);
5098 fprintf (asm_out_file
, "\t%s %s",
5099 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5101 fputc ('\n', asm_out_file
);
5102 ASM_OUTPUT_DWARF_DATA8 (asm_out_file
,
5103 a
->dw_attr_val
.v
.val_long_long
.hi
,
5104 a
->dw_attr_val
.v
.val_long_long
.low
);
5107 fprintf (asm_out_file
,
5108 "\t%s long long constant", ASM_COMMENT_START
);
5110 fputc ('\n', asm_out_file
);
5113 case dw_val_class_float
:
5115 register unsigned int i
;
5116 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
5117 a
->dw_attr_val
.v
.val_float
.length
* 4);
5119 fprintf (asm_out_file
, "\t%s %s",
5120 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5122 fputc ('\n', asm_out_file
);
5123 for (i
= 0; i
< a
->dw_attr_val
.v
.val_float
.length
; ++i
)
5125 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
,
5126 a
->dw_attr_val
.v
.val_float
.array
[i
]);
5128 fprintf (asm_out_file
, "\t%s fp constant word %u",
5129 ASM_COMMENT_START
, i
);
5131 fputc ('\n', asm_out_file
);
5136 case dw_val_class_flag
:
5137 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, AT_flag (a
));
5140 case dw_val_class_die_ref
:
5141 ASM_OUTPUT_DWARF_DATA (asm_out_file
, AT_ref (a
)->die_offset
);
5144 case dw_val_class_fde_ref
:
5147 ASM_GENERATE_INTERNAL_LABEL
5148 (l1
, FDE_AFTER_SIZE_LABEL
, a
->dw_attr_val
.v
.val_fde_index
* 2);
5149 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, l1
);
5150 fprintf (asm_out_file
, " - %d", DWARF_OFFSET_SIZE
);
5154 case dw_val_class_lbl_id
:
5155 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, AT_lbl (a
));
5158 case dw_val_class_lbl_offset
:
5159 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, AT_lbl (a
));
5162 case dw_val_class_str
:
5164 ASM_OUTPUT_DWARF_STRING (asm_out_file
, AT_string (a
));
5166 ASM_OUTPUT_ASCII (asm_out_file
, AT_string (a
),
5167 (int) strlen (AT_string (a
)) + 1);
5174 if (AT_class (a
) != dw_val_class_loc
5175 && AT_class (a
) != dw_val_class_long_long
5176 && AT_class (a
) != dw_val_class_float
)
5179 fprintf (asm_out_file
, "\t%s %s",
5180 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5182 fputc ('\n', asm_out_file
);
5186 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5189 if (die
->die_child
!= NULL
)
5191 /* Add null byte to terminate sibling list. */
5192 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5194 fprintf (asm_out_file
, "\t%s end of children of DIE 0x%lx",
5195 ASM_COMMENT_START
, die
->die_offset
);
5197 fputc ('\n', asm_out_file
);
5201 /* Output the compilation unit that appears at the beginning of the
5202 .debug_info section, and precedes the DIE descriptions. */
5205 output_compilation_unit_header ()
5207 ASM_OUTPUT_DWARF_DATA (asm_out_file
, next_die_offset
- DWARF_OFFSET_SIZE
);
5209 fprintf (asm_out_file
, "\t%s Length of Compilation Unit Info.",
5212 fputc ('\n', asm_out_file
);
5213 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5215 fprintf (asm_out_file
, "\t%s DWARF version number", ASM_COMMENT_START
);
5217 fputc ('\n', asm_out_file
);
5218 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, abbrev_section_label
);
5220 fprintf (asm_out_file
, "\t%s Offset Into Abbrev. Section",
5223 fputc ('\n', asm_out_file
);
5224 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, PTR_SIZE
);
5226 fprintf (asm_out_file
, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START
);
5228 fputc ('\n', asm_out_file
);
5231 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5232 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5233 argument list, and maybe the scope. */
5236 dwarf2_name (decl
, scope
)
5240 return (*decl_printable_name
) (decl
, scope
? 1 : 0);
5243 /* Add a new entry to .debug_pubnames if appropriate. */
5246 add_pubname (decl
, die
)
5252 if (! TREE_PUBLIC (decl
))
5255 if (pubname_table_in_use
== pubname_table_allocated
)
5257 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
5258 pubname_table
= (pubname_ref
) xrealloc
5259 (pubname_table
, pubname_table_allocated
* sizeof (pubname_entry
));
5262 p
= &pubname_table
[pubname_table_in_use
++];
5265 p
->name
= xstrdup (dwarf2_name (decl
, 1));
5268 /* Output the public names table used to speed up access to externally
5269 visible names. For now, only generate entries for externally
5270 visible procedures. */
5275 register unsigned i
;
5276 register unsigned long pubnames_length
= size_of_pubnames ();
5278 ASM_OUTPUT_DWARF_DATA (asm_out_file
, pubnames_length
);
5281 fprintf (asm_out_file
, "\t%s Length of Public Names Info.",
5284 fputc ('\n', asm_out_file
);
5285 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5288 fprintf (asm_out_file
, "\t%s DWARF Version", ASM_COMMENT_START
);
5290 fputc ('\n', asm_out_file
);
5291 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, debug_info_section_label
);
5293 fprintf (asm_out_file
, "\t%s Offset of Compilation Unit Info.",
5296 fputc ('\n', asm_out_file
);
5297 ASM_OUTPUT_DWARF_DATA (asm_out_file
, next_die_offset
);
5299 fprintf (asm_out_file
, "\t%s Compilation Unit Length", ASM_COMMENT_START
);
5301 fputc ('\n', asm_out_file
);
5302 for (i
= 0; i
< pubname_table_in_use
; ++i
)
5304 register pubname_ref pub
= &pubname_table
[i
];
5306 ASM_OUTPUT_DWARF_DATA (asm_out_file
, pub
->die
->die_offset
);
5308 fprintf (asm_out_file
, "\t%s DIE offset", ASM_COMMENT_START
);
5310 fputc ('\n', asm_out_file
);
5314 ASM_OUTPUT_DWARF_STRING (asm_out_file
, pub
->name
);
5315 fprintf (asm_out_file
, "%s external name", ASM_COMMENT_START
);
5319 ASM_OUTPUT_ASCII (asm_out_file
, pub
->name
,
5320 (int) strlen (pub
->name
) + 1);
5323 fputc ('\n', asm_out_file
);
5326 ASM_OUTPUT_DWARF_DATA (asm_out_file
, 0);
5327 fputc ('\n', asm_out_file
);
5330 /* Add a new entry to .debug_aranges if appropriate. */
5333 add_arange (decl
, die
)
5337 if (! DECL_SECTION_NAME (decl
))
5340 if (arange_table_in_use
== arange_table_allocated
)
5342 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
5344 = (arange_ref
) xrealloc (arange_table
,
5345 arange_table_allocated
* sizeof (dw_die_ref
));
5348 arange_table
[arange_table_in_use
++] = die
;
5351 /* Output the information that goes into the .debug_aranges table.
5352 Namely, define the beginning and ending address range of the
5353 text section generated for this compilation unit. */
5358 register unsigned i
;
5359 register unsigned long aranges_length
= size_of_aranges ();
5361 ASM_OUTPUT_DWARF_DATA (asm_out_file
, aranges_length
);
5363 fprintf (asm_out_file
, "\t%s Length of Address Ranges Info.",
5366 fputc ('\n', asm_out_file
);
5367 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5369 fprintf (asm_out_file
, "\t%s DWARF Version", ASM_COMMENT_START
);
5371 fputc ('\n', asm_out_file
);
5372 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, debug_info_section_label
);
5374 fprintf (asm_out_file
, "\t%s Offset of Compilation Unit Info.",
5377 fputc ('\n', asm_out_file
);
5378 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, PTR_SIZE
);
5380 fprintf (asm_out_file
, "\t%s Size of Address", ASM_COMMENT_START
);
5382 fputc ('\n', asm_out_file
);
5383 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5385 fprintf (asm_out_file
, "\t%s Size of Segment Descriptor",
5388 fputc ('\n', asm_out_file
);
5390 /* We need to align to twice the pointer size here. */
5391 if (DWARF_ARANGES_PAD_SIZE
)
5393 /* Pad using a 2 bytes word so that padding is correct
5394 for any pointer size. */
5395 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, 0);
5396 for (i
= 2; i
< DWARF_ARANGES_PAD_SIZE
; i
+= 2)
5397 fprintf (asm_out_file
, ",0");
5399 fprintf (asm_out_file
, "\t%s Pad to %d byte boundary",
5400 ASM_COMMENT_START
, 2 * PTR_SIZE
);
5403 fputc ('\n', asm_out_file
);
5404 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, text_section_label
);
5406 fprintf (asm_out_file
, "\t%s Address", ASM_COMMENT_START
);
5408 fputc ('\n', asm_out_file
);
5409 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
, text_end_label
,
5410 text_section_label
);
5412 fprintf (asm_out_file
, "%s Length", ASM_COMMENT_START
);
5414 fputc ('\n', asm_out_file
);
5415 for (i
= 0; i
< arange_table_in_use
; ++i
)
5417 dw_die_ref die
= arange_table
[i
];
5419 if (die
->die_tag
== DW_TAG_subprogram
)
5420 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, get_AT_low_pc (die
));
5423 /* A static variable; extract the symbol from DW_AT_location.
5424 Note that this code isn't currently hit, as we only emit
5425 aranges for functions (jason 9/23/99). */
5427 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
5428 dw_loc_descr_ref loc
;
5429 if (! a
|| AT_class (a
) != dw_val_class_loc
)
5433 if (loc
->dw_loc_opc
!= DW_OP_addr
)
5436 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
,
5437 loc
->dw_loc_oprnd1
.v
.val_addr
);
5441 fprintf (asm_out_file
, "\t%s Address", ASM_COMMENT_START
);
5443 fputc ('\n', asm_out_file
);
5444 if (die
->die_tag
== DW_TAG_subprogram
)
5445 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
, get_AT_hi_pc (die
),
5446 get_AT_low_pc (die
));
5448 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
,
5449 get_AT_unsigned (die
, DW_AT_byte_size
));
5452 fprintf (asm_out_file
, "%s Length", ASM_COMMENT_START
);
5454 fputc ('\n', asm_out_file
);
5457 /* Output the terminator words. */
5458 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
, 0);
5459 fputc ('\n', asm_out_file
);
5460 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
, 0);
5461 fputc ('\n', asm_out_file
);
5464 /* Output the source line number correspondence information. This
5465 information goes into the .debug_line section. */
5470 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5471 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5472 register unsigned opc
;
5473 register unsigned n_op_args
;
5474 register unsigned long ft_index
;
5475 register unsigned long lt_index
;
5476 register unsigned long current_line
;
5477 register long line_offset
;
5478 register long line_delta
;
5479 register unsigned long current_file
;
5480 register unsigned long function
;
5482 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, ".LTEND", ".LTSTART");
5484 fprintf (asm_out_file
, "\t%s Length of Source Line Info.",
5487 fputc ('\n', asm_out_file
);
5488 ASM_OUTPUT_LABEL (asm_out_file
, ".LTSTART");
5489 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5491 fprintf (asm_out_file
, "\t%s DWARF Version", ASM_COMMENT_START
);
5493 fputc ('\n', asm_out_file
);
5494 ASM_OUTPUT_DWARF_DATA (asm_out_file
, size_of_line_prolog ());
5496 fprintf (asm_out_file
, "\t%s Prolog Length", ASM_COMMENT_START
);
5498 fputc ('\n', asm_out_file
);
5499 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_LINE_MIN_INSTR_LENGTH
);
5501 fprintf (asm_out_file
, "\t%s Minimum Instruction Length",
5504 fputc ('\n', asm_out_file
);
5505 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_LINE_DEFAULT_IS_STMT_START
);
5507 fprintf (asm_out_file
, "\t%s Default is_stmt_start flag",
5510 fputc ('\n', asm_out_file
);
5511 fprintf (asm_out_file
, "\t%s\t%d", ASM_BYTE_OP
, DWARF_LINE_BASE
);
5513 fprintf (asm_out_file
, "\t%s Line Base Value (Special Opcodes)",
5516 fputc ('\n', asm_out_file
);
5517 fprintf (asm_out_file
, "\t%s\t%u", ASM_BYTE_OP
, DWARF_LINE_RANGE
);
5519 fprintf (asm_out_file
, "\t%s Line Range Value (Special Opcodes)",
5522 fputc ('\n', asm_out_file
);
5523 fprintf (asm_out_file
, "\t%s\t%u", ASM_BYTE_OP
, DWARF_LINE_OPCODE_BASE
);
5525 fprintf (asm_out_file
, "\t%s Special Opcode Base", ASM_COMMENT_START
);
5527 fputc ('\n', asm_out_file
);
5528 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; ++opc
)
5532 case DW_LNS_advance_pc
:
5533 case DW_LNS_advance_line
:
5534 case DW_LNS_set_file
:
5535 case DW_LNS_set_column
:
5536 case DW_LNS_fixed_advance_pc
:
5543 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, n_op_args
);
5545 fprintf (asm_out_file
, "\t%s opcode: 0x%x has %d args",
5546 ASM_COMMENT_START
, opc
, n_op_args
);
5547 fputc ('\n', asm_out_file
);
5551 fprintf (asm_out_file
, "%s Include Directory Table\n", ASM_COMMENT_START
);
5553 /* Include directory table is empty, at present */
5554 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5555 fputc ('\n', asm_out_file
);
5557 fprintf (asm_out_file
, "%s File Name Table\n", ASM_COMMENT_START
);
5559 for (ft_index
= 1; ft_index
< file_table_in_use
; ++ft_index
)
5563 ASM_OUTPUT_DWARF_STRING (asm_out_file
, file_table
[ft_index
]);
5564 fprintf (asm_out_file
, "%s File Entry: 0x%lx",
5565 ASM_COMMENT_START
, ft_index
);
5569 ASM_OUTPUT_ASCII (asm_out_file
,
5570 file_table
[ft_index
],
5571 (int) strlen (file_table
[ft_index
]) + 1);
5574 fputc ('\n', asm_out_file
);
5576 /* Include directory index */
5578 fputc ('\n', asm_out_file
);
5580 /* Modification time */
5582 fputc ('\n', asm_out_file
);
5584 /* File length in bytes */
5586 fputc ('\n', asm_out_file
);
5589 /* Terminate the file name table */
5590 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5591 fputc ('\n', asm_out_file
);
5593 /* We used to set the address register to the first location in the text
5594 section here, but that didn't accomplish anything since we already
5595 have a line note for the opening brace of the first function. */
5597 /* Generate the line number to PC correspondence table, encoded as
5598 a series of state machine operations. */
5601 strcpy (prev_line_label
, text_section_label
);
5602 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
5604 register dw_line_info_ref line_info
= &line_info_table
[lt_index
];
5607 /* Disable this optimization for now; GDB wants to see two line notes
5608 at the beginning of a function so it can find the end of the
5611 /* Don't emit anything for redundant notes. Just updating the
5612 address doesn't accomplish anything, because we already assume
5613 that anything after the last address is this line. */
5614 if (line_info
->dw_line_num
== current_line
5615 && line_info
->dw_file_num
== current_file
)
5619 /* Emit debug info for the address of the current line, choosing
5620 the encoding that uses the least amount of space. */
5621 /* ??? Unfortunately, we have little choice here currently, and must
5622 always use the most general form. Gcc does not know the address
5623 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5624 dwarf2 aware assemblers at this time, so we can't use any special
5625 pseudo ops that would allow the assembler to optimally encode this for
5626 us. Many ports do have length attributes which will give an upper
5627 bound on the address range. We could perhaps use length attributes
5628 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5629 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
5632 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5633 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
5635 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
5638 fputc ('\n', asm_out_file
);
5639 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
, prev_line_label
);
5640 fputc ('\n', asm_out_file
);
5644 /* This can handle any delta. This takes 4+PTR_SIZE bytes. */
5645 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5647 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
5649 fputc ('\n', asm_out_file
);
5650 output_uleb128 (1 + PTR_SIZE
);
5651 fputc ('\n', asm_out_file
);
5652 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5653 fputc ('\n', asm_out_file
);
5654 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
5655 fputc ('\n', asm_out_file
);
5657 strcpy (prev_line_label
, line_label
);
5659 /* Emit debug info for the source file of the current line, if
5660 different from the previous line. */
5661 if (line_info
->dw_file_num
!= current_file
)
5663 current_file
= line_info
->dw_file_num
;
5664 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_set_file
);
5666 fprintf (asm_out_file
, "\t%s DW_LNS_set_file", ASM_COMMENT_START
);
5668 fputc ('\n', asm_out_file
);
5669 output_uleb128 (current_file
);
5671 fprintf (asm_out_file
, " (\"%s\")", file_table
[current_file
]);
5673 fputc ('\n', asm_out_file
);
5676 /* Emit debug info for the current line number, choosing the encoding
5677 that uses the least amount of space. */
5678 if (line_info
->dw_line_num
!= current_line
)
5680 line_offset
= line_info
->dw_line_num
- current_line
;
5681 line_delta
= line_offset
- DWARF_LINE_BASE
;
5682 current_line
= line_info
->dw_line_num
;
5683 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
5685 /* This can handle deltas from -10 to 234, using the current
5686 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5688 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
5689 DWARF_LINE_OPCODE_BASE
+ line_delta
);
5691 fprintf (asm_out_file
,
5692 "\t%s line %ld", ASM_COMMENT_START
, current_line
);
5694 fputc ('\n', asm_out_file
);
5698 /* This can handle any delta. This takes at least 4 bytes,
5699 depending on the value being encoded. */
5700 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_advance_line
);
5702 fprintf (asm_out_file
, "\t%s advance to line %ld",
5703 ASM_COMMENT_START
, current_line
);
5705 fputc ('\n', asm_out_file
);
5706 output_sleb128 (line_offset
);
5707 fputc ('\n', asm_out_file
);
5708 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
5710 fprintf (asm_out_file
, "\t%s DW_LNS_copy", ASM_COMMENT_START
);
5711 fputc ('\n', asm_out_file
);
5716 /* We still need to start a new row, so output a copy insn. */
5717 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
5719 fprintf (asm_out_file
, "\t%s DW_LNS_copy", ASM_COMMENT_START
);
5720 fputc ('\n', asm_out_file
);
5724 /* Emit debug info for the address of the end of the function. */
5727 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
5729 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
5732 fputc ('\n', asm_out_file
);
5733 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, text_end_label
, prev_line_label
);
5734 fputc ('\n', asm_out_file
);
5738 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5740 fprintf (asm_out_file
, "\t%s DW_LNE_set_address", ASM_COMMENT_START
);
5741 fputc ('\n', asm_out_file
);
5742 output_uleb128 (1 + PTR_SIZE
);
5743 fputc ('\n', asm_out_file
);
5744 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5745 fputc ('\n', asm_out_file
);
5746 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, text_end_label
);
5747 fputc ('\n', asm_out_file
);
5750 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5752 fprintf (asm_out_file
, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START
);
5754 fputc ('\n', asm_out_file
);
5756 fputc ('\n', asm_out_file
);
5757 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_end_sequence
);
5758 fputc ('\n', asm_out_file
);
5763 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
; )
5765 register dw_separate_line_info_ref line_info
5766 = &separate_line_info_table
[lt_index
];
5769 /* Don't emit anything for redundant notes. */
5770 if (line_info
->dw_line_num
== current_line
5771 && line_info
->dw_file_num
== current_file
5772 && line_info
->function
== function
)
5776 /* Emit debug info for the address of the current line. If this is
5777 a new function, or the first line of a function, then we need
5778 to handle it differently. */
5779 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
5781 if (function
!= line_info
->function
)
5783 function
= line_info
->function
;
5785 /* Set the address register to the first line in the function */
5786 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5788 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
5791 fputc ('\n', asm_out_file
);
5792 output_uleb128 (1 + PTR_SIZE
);
5793 fputc ('\n', asm_out_file
);
5794 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5795 fputc ('\n', asm_out_file
);
5796 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
5797 fputc ('\n', asm_out_file
);
5801 /* ??? See the DW_LNS_advance_pc comment above. */
5804 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
5806 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
5809 fputc ('\n', asm_out_file
);
5810 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
,
5812 fputc ('\n', asm_out_file
);
5816 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5818 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
5820 fputc ('\n', asm_out_file
);
5821 output_uleb128 (1 + PTR_SIZE
);
5822 fputc ('\n', asm_out_file
);
5823 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5824 fputc ('\n', asm_out_file
);
5825 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
5826 fputc ('\n', asm_out_file
);
5829 strcpy (prev_line_label
, line_label
);
5831 /* Emit debug info for the source file of the current line, if
5832 different from the previous line. */
5833 if (line_info
->dw_file_num
!= current_file
)
5835 current_file
= line_info
->dw_file_num
;
5836 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_set_file
);
5838 fprintf (asm_out_file
, "\t%s DW_LNS_set_file", ASM_COMMENT_START
);
5840 fputc ('\n', asm_out_file
);
5841 output_uleb128 (current_file
);
5843 fprintf (asm_out_file
, " (\"%s\")", file_table
[current_file
]);
5845 fputc ('\n', asm_out_file
);
5848 /* Emit debug info for the current line number, choosing the encoding
5849 that uses the least amount of space. */
5850 if (line_info
->dw_line_num
!= current_line
)
5852 line_offset
= line_info
->dw_line_num
- current_line
;
5853 line_delta
= line_offset
- DWARF_LINE_BASE
;
5854 current_line
= line_info
->dw_line_num
;
5855 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
5857 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
5858 DWARF_LINE_OPCODE_BASE
+ line_delta
);
5860 fprintf (asm_out_file
,
5861 "\t%s line %ld", ASM_COMMENT_START
, current_line
);
5863 fputc ('\n', asm_out_file
);
5867 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_advance_line
);
5869 fprintf (asm_out_file
, "\t%s advance to line %ld",
5870 ASM_COMMENT_START
, current_line
);
5872 fputc ('\n', asm_out_file
);
5873 output_sleb128 (line_offset
);
5874 fputc ('\n', asm_out_file
);
5875 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
5877 fprintf (asm_out_file
, "\t%s DW_LNS_copy", ASM_COMMENT_START
);
5878 fputc ('\n', asm_out_file
);
5883 /* We still need to start a new row, so output a copy insn. */
5884 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
5886 fprintf (asm_out_file
, "\t%s DW_LNS_copy", ASM_COMMENT_START
);
5887 fputc ('\n', asm_out_file
);
5895 /* If we're done with a function, end its sequence. */
5896 if (lt_index
== separate_line_info_table_in_use
5897 || separate_line_info_table
[lt_index
].function
!= function
)
5902 /* Emit debug info for the address of the end of the function. */
5903 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
5906 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
5908 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
5911 fputc ('\n', asm_out_file
);
5912 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
,
5914 fputc ('\n', asm_out_file
);
5918 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5920 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
5922 fputc ('\n', asm_out_file
);
5923 output_uleb128 (1 + PTR_SIZE
);
5924 fputc ('\n', asm_out_file
);
5925 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5926 fputc ('\n', asm_out_file
);
5927 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
5928 fputc ('\n', asm_out_file
);
5931 /* Output the marker for the end of this sequence. */
5932 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5934 fprintf (asm_out_file
, "\t%s DW_LNE_end_sequence",
5937 fputc ('\n', asm_out_file
);
5939 fputc ('\n', asm_out_file
);
5940 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_end_sequence
);
5941 fputc ('\n', asm_out_file
);
5945 /* Output the marker for the end of the line number info. */
5946 ASM_OUTPUT_LABEL (asm_out_file
, ".LTEND");
5949 /* Given a pointer to a tree node for some base type, return a pointer to
5950 a DIE that describes the given type.
5952 This routine must only be called for GCC type nodes that correspond to
5953 Dwarf base (fundamental) types. */
5956 base_type_die (type
)
5959 register dw_die_ref base_type_result
;
5960 register const char *type_name
;
5961 register enum dwarf_type encoding
;
5962 register tree name
= TYPE_NAME (type
);
5964 if (TREE_CODE (type
) == ERROR_MARK
5965 || TREE_CODE (type
) == VOID_TYPE
)
5970 if (TREE_CODE (name
) == TYPE_DECL
)
5971 name
= DECL_NAME (name
);
5973 type_name
= IDENTIFIER_POINTER (name
);
5976 type_name
= "__unknown__";
5978 switch (TREE_CODE (type
))
5981 /* Carefully distinguish the C character types, without messing
5982 up if the language is not C. Note that we check only for the names
5983 that contain spaces; other names might occur by coincidence in other
5985 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
5986 && (type
== char_type_node
5987 || ! strcmp (type_name
, "signed char")
5988 || ! strcmp (type_name
, "unsigned char"))))
5990 if (TREE_UNSIGNED (type
))
5991 encoding
= DW_ATE_unsigned
;
5993 encoding
= DW_ATE_signed
;
5996 /* else fall through */
5999 /* GNU Pascal/Ada CHAR type. Not used in C. */
6000 if (TREE_UNSIGNED (type
))
6001 encoding
= DW_ATE_unsigned_char
;
6003 encoding
= DW_ATE_signed_char
;
6007 encoding
= DW_ATE_float
;
6010 /* Dwarf2 doesn't know anything about complex ints, so use
6011 a user defined type for it. */
6013 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
6014 encoding
= DW_ATE_complex_float
;
6016 encoding
= DW_ATE_lo_user
;
6020 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6021 encoding
= DW_ATE_boolean
;
6025 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6028 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
);
6029 if (demangle_name_func
)
6030 type_name
= (*demangle_name_func
) (type_name
);
6032 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
6033 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
6034 int_size_in_bytes (type
));
6035 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
6037 return base_type_result
;
6040 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6041 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6042 a given type is generally the same as the given type, except that if the
6043 given type is a pointer or reference type, then the root type of the given
6044 type is the root type of the "basis" type for the pointer or reference
6045 type. (This definition of the "root" type is recursive.) Also, the root
6046 type of a `const' qualified type or a `volatile' qualified type is the
6047 root type of the given type without the qualifiers. */
6053 if (TREE_CODE (type
) == ERROR_MARK
)
6054 return error_mark_node
;
6056 switch (TREE_CODE (type
))
6059 return error_mark_node
;
6062 case REFERENCE_TYPE
:
6063 return type_main_variant (root_type (TREE_TYPE (type
)));
6066 return type_main_variant (type
);
6070 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6071 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6077 switch (TREE_CODE (type
))
6092 case QUAL_UNION_TYPE
:
6097 case REFERENCE_TYPE
:
6110 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6111 entry that chains various modifiers in front of the given type. */
6114 modified_type_die (type
, is_const_type
, is_volatile_type
, context_die
)
6116 register int is_const_type
;
6117 register int is_volatile_type
;
6118 register dw_die_ref context_die
;
6120 register enum tree_code code
= TREE_CODE (type
);
6121 register dw_die_ref mod_type_die
= NULL
;
6122 register dw_die_ref sub_die
= NULL
;
6123 register tree item_type
= NULL
;
6125 if (code
!= ERROR_MARK
)
6127 type
= build_type_variant (type
, is_const_type
, is_volatile_type
);
6129 mod_type_die
= lookup_type_die (type
);
6131 return mod_type_die
;
6133 /* Handle C typedef types. */
6134 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
6135 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
6137 tree dtype
= TREE_TYPE (TYPE_NAME (type
));
6140 /* For a named type, use the typedef. */
6141 gen_type_die (type
, context_die
);
6142 mod_type_die
= lookup_type_die (type
);
6145 else if (is_const_type
< TYPE_READONLY (dtype
)
6146 || is_volatile_type
< TYPE_VOLATILE (dtype
))
6147 /* cv-unqualified version of named type. Just use the unnamed
6148 type to which it refers. */
6150 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)),
6151 is_const_type
, is_volatile_type
,
6153 /* Else cv-qualified version of named type; fall through. */
6158 else if (is_const_type
)
6160 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
);
6161 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
6163 else if (is_volatile_type
)
6165 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
);
6166 sub_die
= modified_type_die (type
, 0, 0, context_die
);
6168 else if (code
== POINTER_TYPE
)
6170 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
);
6171 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
6173 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
6175 item_type
= TREE_TYPE (type
);
6177 else if (code
== REFERENCE_TYPE
)
6179 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
);
6180 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
6182 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
6184 item_type
= TREE_TYPE (type
);
6186 else if (is_base_type (type
))
6187 mod_type_die
= base_type_die (type
);
6190 gen_type_die (type
, context_die
);
6192 /* We have to get the type_main_variant here (and pass that to the
6193 `lookup_type_die' routine) because the ..._TYPE node we have
6194 might simply be a *copy* of some original type node (where the
6195 copy was created to help us keep track of typedef names) and
6196 that copy might have a different TYPE_UID from the original
6198 mod_type_die
= lookup_type_die (type_main_variant (type
));
6199 if (mod_type_die
== NULL
)
6204 equate_type_number_to_die (type
, mod_type_die
);
6206 /* We must do this after the equate_type_number_to_die call, in case
6207 this is a recursive type. This ensures that the modified_type_die
6208 recursion will terminate even if the type is recursive. Recursive
6209 types are possible in Ada. */
6210 sub_die
= modified_type_die (item_type
,
6211 TYPE_READONLY (item_type
),
6212 TYPE_VOLATILE (item_type
),
6215 if (sub_die
!= NULL
)
6216 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
6218 return mod_type_die
;
6221 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6222 an enumerated type. */
6228 return TREE_CODE (type
) == ENUMERAL_TYPE
;
6231 /* Return a location descriptor that designates a machine register. */
6233 static dw_loc_descr_ref
6234 reg_loc_descriptor (rtl
)
6237 register dw_loc_descr_ref loc_result
= NULL
;
6238 register unsigned reg
= reg_number (rtl
);
6241 loc_result
= new_loc_descr (DW_OP_reg0
+ reg
, 0, 0);
6243 loc_result
= new_loc_descr (DW_OP_regx
, reg
, 0);
6248 /* Return a location descriptor that designates a base+offset location. */
6250 static dw_loc_descr_ref
6251 based_loc_descr (reg
, offset
)
6255 register dw_loc_descr_ref loc_result
;
6256 /* For the "frame base", we use the frame pointer or stack pointer
6257 registers, since the RTL for local variables is relative to one of
6259 register unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
6260 ? HARD_FRAME_POINTER_REGNUM
6261 : STACK_POINTER_REGNUM
);
6264 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
6266 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
6268 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
6273 /* Return true if this RTL expression describes a base+offset calculation. */
6279 return (GET_CODE (rtl
) == PLUS
6280 && ((GET_CODE (XEXP (rtl
, 0)) == REG
6281 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
6284 /* The following routine converts the RTL for a variable or parameter
6285 (resident in memory) into an equivalent Dwarf representation of a
6286 mechanism for getting the address of that same variable onto the top of a
6287 hypothetical "address evaluation" stack.
6289 When creating memory location descriptors, we are effectively transforming
6290 the RTL for a memory-resident object into its Dwarf postfix expression
6291 equivalent. This routine recursively descends an RTL tree, turning
6292 it into Dwarf postfix code as it goes.
6294 MODE is the mode of the memory reference, needed to handle some
6295 autoincrement addressing modes. */
6297 static dw_loc_descr_ref
6298 mem_loc_descriptor (rtl
, mode
)
6300 enum machine_mode mode
;
6302 dw_loc_descr_ref mem_loc_result
= NULL
;
6303 /* Note that for a dynamically sized array, the location we will generate a
6304 description of here will be the lowest numbered location which is
6305 actually within the array. That's *not* necessarily the same as the
6306 zeroth element of the array. */
6308 #ifdef ASM_SIMPLIFY_DWARF_ADDR
6309 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
6312 switch (GET_CODE (rtl
))
6316 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
6317 just fall into the SUBREG code. */
6319 /* ... fall through ... */
6322 /* The case of a subreg may arise when we have a local (register)
6323 variable or a formal (register) parameter which doesn't quite fill
6324 up an entire register. For now, just assume that it is
6325 legitimate to make the Dwarf info refer to the whole register which
6326 contains the given subreg. */
6327 rtl
= XEXP (rtl
, 0);
6329 /* ... fall through ... */
6332 /* Whenever a register number forms a part of the description of the
6333 method for calculating the (dynamic) address of a memory resident
6334 object, DWARF rules require the register number be referred to as
6335 a "base register". This distinction is not based in any way upon
6336 what category of register the hardware believes the given register
6337 belongs to. This is strictly DWARF terminology we're dealing with
6338 here. Note that in cases where the location of a memory-resident
6339 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6340 OP_CONST (0)) the actual DWARF location descriptor that we generate
6341 may just be OP_BASEREG (basereg). This may look deceptively like
6342 the object in question was allocated to a register (rather than in
6343 memory) so DWARF consumers need to be aware of the subtle
6344 distinction between OP_REG and OP_BASEREG. */
6345 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
6349 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
6350 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
6354 /* Some ports can transform a symbol ref into a label ref, because
6355 the symbol ref is too far away and has to be dumped into a constant
6359 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
6360 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
6361 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= save_rtx (rtl
);
6366 /* Turn these into a PLUS expression and fall into the PLUS code
6368 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
6369 GEN_INT (GET_CODE (rtl
) == PRE_INC
6370 ? GET_MODE_UNIT_SIZE (mode
)
6371 : - GET_MODE_UNIT_SIZE (mode
)));
6373 /* ... fall through ... */
6376 if (is_based_loc (rtl
))
6377 mem_loc_result
= based_loc_descr (reg_number (XEXP (rtl
, 0)),
6378 INTVAL (XEXP (rtl
, 1)));
6381 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 0),
6383 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 1),
6385 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_plus
, 0, 0));
6390 /* If a pseudo-reg is optimized away, it is possible for it to
6391 be replaced with a MEM containing a multiply. */
6392 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 0), mode
));
6393 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 1), mode
));
6394 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
6398 mem_loc_result
= new_loc_descr (DW_OP_constu
, INTVAL (rtl
), 0);
6405 return mem_loc_result
;
6408 /* Return a descriptor that describes the concatenation of two locations.
6409 This is typically a complex variable. */
6411 static dw_loc_descr_ref
6412 concat_loc_descriptor (x0
, x1
)
6413 register rtx x0
, x1
;
6415 dw_loc_descr_ref cc_loc_result
= NULL
;
6417 if (!is_pseudo_reg (x0
)
6418 && (GET_CODE (x0
) != MEM
|| !is_pseudo_reg (XEXP (x0
, 0))))
6419 add_loc_descr (&cc_loc_result
, loc_descriptor (x0
));
6420 add_loc_descr (&cc_loc_result
,
6421 new_loc_descr (DW_OP_piece
, GET_MODE_SIZE (GET_MODE (x0
)), 0));
6423 if (!is_pseudo_reg (x1
)
6424 && (GET_CODE (x1
) != MEM
|| !is_pseudo_reg (XEXP (x1
, 0))))
6425 add_loc_descr (&cc_loc_result
, loc_descriptor (x1
));
6426 add_loc_descr (&cc_loc_result
,
6427 new_loc_descr (DW_OP_piece
, GET_MODE_SIZE (GET_MODE (x1
)), 0));
6429 return cc_loc_result
;
6432 /* Output a proper Dwarf location descriptor for a variable or parameter
6433 which is either allocated in a register or in a memory location. For a
6434 register, we just generate an OP_REG and the register number. For a
6435 memory location we provide a Dwarf postfix expression describing how to
6436 generate the (dynamic) address of the object onto the address stack. */
6438 static dw_loc_descr_ref
6439 loc_descriptor (rtl
)
6442 dw_loc_descr_ref loc_result
= NULL
;
6443 switch (GET_CODE (rtl
))
6446 /* The case of a subreg may arise when we have a local (register)
6447 variable or a formal (register) parameter which doesn't quite fill
6448 up an entire register. For now, just assume that it is
6449 legitimate to make the Dwarf info refer to the whole register which
6450 contains the given subreg. */
6451 rtl
= XEXP (rtl
, 0);
6453 /* ... fall through ... */
6456 loc_result
= reg_loc_descriptor (rtl
);
6460 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
6464 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
6474 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
6475 which is not less than the value itself. */
6477 static inline unsigned
6478 ceiling (value
, boundary
)
6479 register unsigned value
;
6480 register unsigned boundary
;
6482 return (((value
+ boundary
- 1) / boundary
) * boundary
);
6485 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6486 pointer to the declared type for the relevant field variable, or return
6487 `integer_type_node' if the given node turns out to be an
6496 if (TREE_CODE (decl
) == ERROR_MARK
)
6497 return integer_type_node
;
6499 type
= DECL_BIT_FIELD_TYPE (decl
);
6500 if (type
== NULL_TREE
)
6501 type
= TREE_TYPE (decl
);
6506 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6507 node, return the alignment in bits for the type, or else return
6508 BITS_PER_WORD if the node actually turns out to be an
6511 static inline unsigned
6512 simple_type_align_in_bits (type
)
6515 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
6518 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6519 node, return the size in bits for the type if it is a constant, or else
6520 return the alignment for the type if the type's size is not constant, or
6521 else return BITS_PER_WORD if the type actually turns out to be an
6524 static inline unsigned
6525 simple_type_size_in_bits (type
)
6528 if (TREE_CODE (type
) == ERROR_MARK
)
6529 return BITS_PER_WORD
;
6532 register tree type_size_tree
= TYPE_SIZE (type
);
6534 if (TREE_CODE (type_size_tree
) != INTEGER_CST
)
6535 return TYPE_ALIGN (type
);
6537 return (unsigned) TREE_INT_CST_LOW (type_size_tree
);
6541 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6542 return the byte offset of the lowest addressed byte of the "containing
6543 object" for the given FIELD_DECL, or return 0 if we are unable to
6544 determine what that offset is, either because the argument turns out to
6545 be a pointer to an ERROR_MARK node, or because the offset is actually
6546 variable. (We can't handle the latter case just yet). */
6549 field_byte_offset (decl
)
6552 register unsigned type_align_in_bytes
;
6553 register unsigned type_align_in_bits
;
6554 register unsigned type_size_in_bits
;
6555 register unsigned object_offset_in_align_units
;
6556 register unsigned object_offset_in_bits
;
6557 register unsigned object_offset_in_bytes
;
6559 register tree bitpos_tree
;
6560 register tree field_size_tree
;
6561 register unsigned bitpos_int
;
6562 register unsigned deepest_bitpos
;
6563 register unsigned field_size_in_bits
;
6565 if (TREE_CODE (decl
) == ERROR_MARK
)
6568 if (TREE_CODE (decl
) != FIELD_DECL
)
6571 type
= field_type (decl
);
6573 bitpos_tree
= DECL_FIELD_BITPOS (decl
);
6574 field_size_tree
= DECL_SIZE (decl
);
6576 /* If there was an error, the size could be zero. */
6577 if (! field_size_tree
)
6584 /* We cannot yet cope with fields whose positions are variable, so
6585 for now, when we see such things, we simply return 0. Someday, we may
6586 be able to handle such cases, but it will be damn difficult. */
6587 if (TREE_CODE (bitpos_tree
) != INTEGER_CST
)
6590 bitpos_int
= (unsigned) TREE_INT_CST_LOW (bitpos_tree
);
6592 /* If we don't know the size of the field, pretend it's a full word. */
6593 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
6594 field_size_in_bits
= (unsigned) TREE_INT_CST_LOW (field_size_tree
);
6596 field_size_in_bits
= BITS_PER_WORD
;
6598 type_size_in_bits
= simple_type_size_in_bits (type
);
6599 type_align_in_bits
= simple_type_align_in_bits (type
);
6600 type_align_in_bytes
= type_align_in_bits
/ BITS_PER_UNIT
;
6602 /* Note that the GCC front-end doesn't make any attempt to keep track of
6603 the starting bit offset (relative to the start of the containing
6604 structure type) of the hypothetical "containing object" for a bit-
6605 field. Thus, when computing the byte offset value for the start of the
6606 "containing object" of a bit-field, we must deduce this information on
6607 our own. This can be rather tricky to do in some cases. For example,
6608 handling the following structure type definition when compiling for an
6609 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6612 struct S { int field1; long long field2:31; };
6614 Fortunately, there is a simple rule-of-thumb which can be
6615 used in such cases. When compiling for an i386/i486, GCC will allocate
6616 8 bytes for the structure shown above. It decides to do this based upon
6617 one simple rule for bit-field allocation. Quite simply, GCC allocates
6618 each "containing object" for each bit-field at the first (i.e. lowest
6619 addressed) legitimate alignment boundary (based upon the required
6620 minimum alignment for the declared type of the field) which it can
6621 possibly use, subject to the condition that there is still enough
6622 available space remaining in the containing object (when allocated at
6623 the selected point) to fully accommodate all of the bits of the
6624 bit-field itself. This simple rule makes it obvious why GCC allocates
6625 8 bytes for each object of the structure type shown above. When looking
6626 for a place to allocate the "containing object" for `field2', the
6627 compiler simply tries to allocate a 64-bit "containing object" at each
6628 successive 32-bit boundary (starting at zero) until it finds a place to
6629 allocate that 64- bit field such that at least 31 contiguous (and
6630 previously unallocated) bits remain within that selected 64 bit field.
6631 (As it turns out, for the example above, the compiler finds that it is
6632 OK to allocate the "containing object" 64-bit field at bit-offset zero
6633 within the structure type.) Here we attempt to work backwards from the
6634 limited set of facts we're given, and we try to deduce from those facts,
6635 where GCC must have believed that the containing object started (within
6636 the structure type). The value we deduce is then used (by the callers of
6637 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6638 for fields (both bit-fields and, in the case of DW_AT_location, regular
6641 /* Figure out the bit-distance from the start of the structure to the
6642 "deepest" bit of the bit-field. */
6643 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
6645 /* This is the tricky part. Use some fancy footwork to deduce where the
6646 lowest addressed bit of the containing object must be. */
6647 object_offset_in_bits
6648 = ceiling (deepest_bitpos
, type_align_in_bits
) - type_size_in_bits
;
6650 /* Compute the offset of the containing object in "alignment units". */
6651 object_offset_in_align_units
= object_offset_in_bits
/ type_align_in_bits
;
6653 /* Compute the offset of the containing object in bytes. */
6654 object_offset_in_bytes
= object_offset_in_align_units
* type_align_in_bytes
;
6656 return object_offset_in_bytes
;
6659 /* The following routines define various Dwarf attributes and any data
6660 associated with them. */
6662 /* Add a location description attribute value to a DIE.
6664 This emits location attributes suitable for whole variables and
6665 whole parameters. Note that the location attributes for struct fields are
6666 generated by the routine `data_member_location_attribute' below. */
6669 add_AT_location_description (die
, attr_kind
, rtl
)
6671 enum dwarf_attribute attr_kind
;
6674 /* Handle a special case. If we are about to output a location descriptor
6675 for a variable or parameter which has been optimized out of existence,
6676 don't do that. A variable which has been optimized out
6677 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6678 Currently, in some rare cases, variables can have DECL_RTL values which
6679 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6680 elsewhere in the compiler. We treat such cases as if the variable(s) in
6681 question had been optimized out of existence. */
6683 if (is_pseudo_reg (rtl
)
6684 || (GET_CODE (rtl
) == MEM
6685 && is_pseudo_reg (XEXP (rtl
, 0)))
6686 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
6687 references the internal argument pointer (a pseudo) in a function
6688 where all references to the internal argument pointer were
6689 eliminated via the optimizers. */
6690 || (GET_CODE (rtl
) == MEM
6691 && GET_CODE (XEXP (rtl
, 0)) == PLUS
6692 && is_pseudo_reg (XEXP (XEXP (rtl
, 0), 0)))
6693 || (GET_CODE (rtl
) == CONCAT
6694 && is_pseudo_reg (XEXP (rtl
, 0))
6695 && is_pseudo_reg (XEXP (rtl
, 1))))
6698 add_AT_loc (die
, attr_kind
, loc_descriptor (rtl
));
6701 /* Attach the specialized form of location attribute used for data
6702 members of struct and union types. In the special case of a
6703 FIELD_DECL node which represents a bit-field, the "offset" part
6704 of this special location descriptor must indicate the distance
6705 in bytes from the lowest-addressed byte of the containing struct
6706 or union type to the lowest-addressed byte of the "containing
6707 object" for the bit-field. (See the `field_byte_offset' function
6708 above).. For any given bit-field, the "containing object" is a
6709 hypothetical object (of some integral or enum type) within which
6710 the given bit-field lives. The type of this hypothetical
6711 "containing object" is always the same as the declared type of
6712 the individual bit-field itself (for GCC anyway... the DWARF
6713 spec doesn't actually mandate this). Note that it is the size
6714 (in bytes) of the hypothetical "containing object" which will
6715 be given in the DW_AT_byte_size attribute for this bit-field.
6716 (See the `byte_size_attribute' function below.) It is also used
6717 when calculating the value of the DW_AT_bit_offset attribute.
6718 (See the `bit_offset_attribute' function below). */
6721 add_data_member_location_attribute (die
, decl
)
6722 register dw_die_ref die
;
6725 register unsigned long offset
;
6726 register dw_loc_descr_ref loc_descr
;
6727 register enum dwarf_location_atom op
;
6729 if (TREE_CODE (decl
) == TREE_VEC
)
6730 offset
= TREE_INT_CST_LOW (BINFO_OFFSET (decl
));
6732 offset
= field_byte_offset (decl
);
6734 /* The DWARF2 standard says that we should assume that the structure address
6735 is already on the stack, so we can specify a structure field address
6736 by using DW_OP_plus_uconst. */
6738 #ifdef MIPS_DEBUGGING_INFO
6739 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6740 correctly. It works only if we leave the offset on the stack. */
6743 op
= DW_OP_plus_uconst
;
6746 loc_descr
= new_loc_descr (op
, offset
, 0);
6747 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
6750 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6751 does not have a "location" either in memory or in a register. These
6752 things can arise in GNU C when a constant is passed as an actual parameter
6753 to an inlined function. They can also arise in C++ where declared
6754 constants do not necessarily get memory "homes". */
6757 add_const_value_attribute (die
, rtl
)
6758 register dw_die_ref die
;
6761 switch (GET_CODE (rtl
))
6764 /* Note that a CONST_INT rtx could represent either an integer or a
6765 floating-point constant. A CONST_INT is used whenever the constant
6766 will fit into a single word. In all such cases, the original mode
6767 of the constant value is wiped out, and the CONST_INT rtx is
6768 assigned VOIDmode. */
6769 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned) INTVAL (rtl
));
6773 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6774 floating-point constant. A CONST_DOUBLE is used whenever the
6775 constant requires more than one word in order to be adequately
6776 represented. We output CONST_DOUBLEs as blocks. */
6778 register enum machine_mode mode
= GET_MODE (rtl
);
6780 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
6782 register unsigned length
= GET_MODE_SIZE (mode
) / sizeof (long);
6786 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
6790 REAL_VALUE_TO_TARGET_SINGLE (rv
, array
[0]);
6794 REAL_VALUE_TO_TARGET_DOUBLE (rv
, array
);
6799 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv
, array
);
6806 add_AT_float (die
, DW_AT_const_value
, length
, array
);
6809 add_AT_long_long (die
, DW_AT_const_value
,
6810 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
6815 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
6821 add_AT_addr (die
, DW_AT_const_value
, save_rtx (rtl
));
6825 /* In cases where an inlined instance of an inline function is passed
6826 the address of an `auto' variable (which is local to the caller) we
6827 can get a situation where the DECL_RTL of the artificial local
6828 variable (for the inlining) which acts as a stand-in for the
6829 corresponding formal parameter (of the inline function) will look
6830 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6831 exactly a compile-time constant expression, but it isn't the address
6832 of the (artificial) local variable either. Rather, it represents the
6833 *value* which the artificial local variable always has during its
6834 lifetime. We currently have no way to represent such quasi-constant
6835 values in Dwarf, so for now we just punt and generate nothing. */
6839 /* No other kinds of rtx should be possible here. */
6845 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6846 data attribute for a variable or a parameter. We generate the
6847 DW_AT_const_value attribute only in those cases where the given variable
6848 or parameter does not have a true "location" either in memory or in a
6849 register. This can happen (for example) when a constant is passed as an
6850 actual argument in a call to an inline function. (It's possible that
6851 these things can crop up in other ways also.) Note that one type of
6852 constant value which can be passed into an inlined function is a constant
6853 pointer. This can happen for example if an actual argument in an inlined
6854 function call evaluates to a compile-time constant address. */
6857 add_location_or_const_value_attribute (die
, decl
)
6858 register dw_die_ref die
;
6862 register tree declared_type
;
6863 register tree passed_type
;
6865 if (TREE_CODE (decl
) == ERROR_MARK
)
6868 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
)
6871 /* Here we have to decide where we are going to say the parameter "lives"
6872 (as far as the debugger is concerned). We only have a couple of
6873 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6875 DECL_RTL normally indicates where the parameter lives during most of the
6876 activation of the function. If optimization is enabled however, this
6877 could be either NULL or else a pseudo-reg. Both of those cases indicate
6878 that the parameter doesn't really live anywhere (as far as the code
6879 generation parts of GCC are concerned) during most of the function's
6880 activation. That will happen (for example) if the parameter is never
6881 referenced within the function.
6883 We could just generate a location descriptor here for all non-NULL
6884 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6885 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6886 where DECL_RTL is NULL or is a pseudo-reg.
6888 Note however that we can only get away with using DECL_INCOMING_RTL as
6889 a backup substitute for DECL_RTL in certain limited cases. In cases
6890 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6891 we can be sure that the parameter was passed using the same type as it is
6892 declared to have within the function, and that its DECL_INCOMING_RTL
6893 points us to a place where a value of that type is passed.
6895 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6896 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6897 because in these cases DECL_INCOMING_RTL points us to a value of some
6898 type which is *different* from the type of the parameter itself. Thus,
6899 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6900 such cases, the debugger would end up (for example) trying to fetch a
6901 `float' from a place which actually contains the first part of a
6902 `double'. That would lead to really incorrect and confusing
6903 output at debug-time.
6905 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6906 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6907 are a couple of exceptions however. On little-endian machines we can
6908 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6909 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6910 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6911 when (on a little-endian machine) a non-prototyped function has a
6912 parameter declared to be of type `short' or `char'. In such cases,
6913 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6914 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6915 passed `int' value. If the debugger then uses that address to fetch
6916 a `short' or a `char' (on a little-endian machine) the result will be
6917 the correct data, so we allow for such exceptional cases below.
6919 Note that our goal here is to describe the place where the given formal
6920 parameter lives during most of the function's activation (i.e. between
6921 the end of the prologue and the start of the epilogue). We'll do that
6922 as best as we can. Note however that if the given formal parameter is
6923 modified sometime during the execution of the function, then a stack
6924 backtrace (at debug-time) will show the function as having been
6925 called with the *new* value rather than the value which was
6926 originally passed in. This happens rarely enough that it is not
6927 a major problem, but it *is* a problem, and I'd like to fix it.
6929 A future version of dwarf2out.c may generate two additional
6930 attributes for any given DW_TAG_formal_parameter DIE which will
6931 describe the "passed type" and the "passed location" for the
6932 given formal parameter in addition to the attributes we now
6933 generate to indicate the "declared type" and the "active
6934 location" for each parameter. This additional set of attributes
6935 could be used by debuggers for stack backtraces. Separately, note
6936 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6937 NULL also. This happens (for example) for inlined-instances of
6938 inline function formal parameters which are never referenced.
6939 This really shouldn't be happening. All PARM_DECL nodes should
6940 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6941 doesn't currently generate these values for inlined instances of
6942 inline function parameters, so when we see such cases, we are
6943 just out-of-luck for the time being (until integrate.c
6946 /* Use DECL_RTL as the "location" unless we find something better. */
6947 rtl
= DECL_RTL (decl
);
6949 if (TREE_CODE (decl
) == PARM_DECL
)
6951 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
6953 declared_type
= type_main_variant (TREE_TYPE (decl
));
6954 passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
6956 /* This decl represents a formal parameter which was optimized out.
6957 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
6958 all* cases where (rtl == NULL_RTX) just below. */
6959 if (declared_type
== passed_type
)
6960 rtl
= DECL_INCOMING_RTL (decl
);
6961 else if (! BYTES_BIG_ENDIAN
6962 && TREE_CODE (declared_type
) == INTEGER_TYPE
6963 && (GET_MODE_SIZE (TYPE_MODE (declared_type
))
6964 <= GET_MODE_SIZE (TYPE_MODE (passed_type
))))
6965 rtl
= DECL_INCOMING_RTL (decl
);
6968 /* If the parm was passed in registers, but lives on the stack, then
6969 make a big endian correction if the mode of the type of the
6970 parameter is not the same as the mode of the rtl. */
6971 /* ??? This is the same series of checks that are made in dbxout.c before
6972 we reach the big endian correction code there. It isn't clear if all
6973 of these checks are necessary here, but keeping them all is the safe
6975 else if (GET_CODE (rtl
) == MEM
6976 && XEXP (rtl
, 0) != const0_rtx
6977 && ! CONSTANT_P (XEXP (rtl
, 0))
6978 /* Not passed in memory. */
6979 && GET_CODE (DECL_INCOMING_RTL (decl
)) != MEM
6980 /* Not passed by invisible reference. */
6981 && (GET_CODE (XEXP (rtl
, 0)) != REG
6982 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
6983 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
6984 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
6985 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
6988 /* Big endian correction check. */
6990 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
6991 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
6994 int offset
= (UNITS_PER_WORD
6995 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
6996 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
6997 plus_constant (XEXP (rtl
, 0), offset
));
7001 if (rtl
== NULL_RTX
)
7004 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
7005 #ifdef LEAF_REG_REMAP
7006 if (current_function_uses_only_leaf_regs
)
7007 leaf_renumber_regs_insn (rtl
);
7010 switch (GET_CODE (rtl
))
7013 /* The address of a variable that was optimized away; don't emit
7024 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7025 add_const_value_attribute (die
, rtl
);
7032 add_AT_location_description (die
, DW_AT_location
, rtl
);
7040 /* Generate an DW_AT_name attribute given some string value to be included as
7041 the value of the attribute. */
7044 add_name_attribute (die
, name_string
)
7045 register dw_die_ref die
;
7046 register const char *name_string
;
7048 if (name_string
!= NULL
&& *name_string
!= 0)
7050 if (demangle_name_func
)
7051 name_string
= (*demangle_name_func
) (name_string
);
7053 add_AT_string (die
, DW_AT_name
, name_string
);
7057 /* Given a tree node describing an array bound (either lower or upper) output
7058 a representation for that bound. */
7061 add_bound_info (subrange_die
, bound_attr
, bound
)
7062 register dw_die_ref subrange_die
;
7063 register enum dwarf_attribute bound_attr
;
7064 register tree bound
;
7066 register unsigned bound_value
= 0;
7068 /* If this is an Ada unconstrained array type, then don't emit any debug
7069 info because the array bounds are unknown. They are parameterized when
7070 the type is instantiated. */
7071 if (contains_placeholder_p (bound
))
7074 switch (TREE_CODE (bound
))
7079 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7081 bound_value
= TREE_INT_CST_LOW (bound
);
7082 if (bound_attr
== DW_AT_lower_bound
7083 && ((is_c_family () && bound_value
== 0)
7084 || (is_fortran () && bound_value
== 1)))
7085 /* use the default */;
7087 add_AT_unsigned (subrange_die
, bound_attr
, bound_value
);
7092 case NON_LVALUE_EXPR
:
7093 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
7097 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7098 access the upper bound values may be bogus. If they refer to a
7099 register, they may only describe how to get at these values at the
7100 points in the generated code right after they have just been
7101 computed. Worse yet, in the typical case, the upper bound values
7102 will not even *be* computed in the optimized code (though the
7103 number of elements will), so these SAVE_EXPRs are entirely
7104 bogus. In order to compensate for this fact, we check here to see
7105 if optimization is enabled, and if so, we don't add an attribute
7106 for the (unknown and unknowable) upper bound. This should not
7107 cause too much trouble for existing (stupid?) debuggers because
7108 they have to deal with empty upper bounds location descriptions
7109 anyway in order to be able to deal with incomplete array types.
7110 Of course an intelligent debugger (GDB?) should be able to
7111 comprehend that a missing upper bound specification in a array
7112 type used for a storage class `auto' local array variable
7113 indicates that the upper bound is both unknown (at compile- time)
7114 and unknowable (at run-time) due to optimization.
7116 We assume that a MEM rtx is safe because gcc wouldn't put the
7117 value there unless it was going to be used repeatedly in the
7118 function, i.e. for cleanups. */
7119 if (! optimize
|| GET_CODE (SAVE_EXPR_RTL (bound
)) == MEM
)
7121 register dw_die_ref ctx
= lookup_decl_die (current_function_decl
);
7122 register dw_die_ref decl_die
= new_die (DW_TAG_variable
, ctx
);
7123 register rtx loc
= SAVE_EXPR_RTL (bound
);
7125 /* If the RTL for the SAVE_EXPR is memory, handle the case where
7126 it references an outer function's frame. */
7128 if (GET_CODE (loc
) == MEM
)
7130 rtx new_addr
= fix_lexical_addr (XEXP (loc
, 0), bound
);
7132 if (XEXP (loc
, 0) != new_addr
)
7133 loc
= gen_rtx_MEM (GET_MODE (loc
), new_addr
);
7136 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
7137 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
7138 add_AT_location_description (decl_die
, DW_AT_location
, loc
);
7139 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
7142 /* Else leave out the attribute. */
7148 /* ??? These types of bounds can be created by the Ada front end,
7149 and it isn't clear how to emit debug info for them. */
7157 /* Note that the block of subscript information for an array type also
7158 includes information about the element type of type given array type. */
7161 add_subscript_info (type_die
, type
)
7162 register dw_die_ref type_die
;
7165 #ifndef MIPS_DEBUGGING_INFO
7166 register unsigned dimension_number
;
7168 register tree lower
, upper
;
7169 register dw_die_ref subrange_die
;
7171 /* The GNU compilers represent multidimensional array types as sequences of
7172 one dimensional array types whose element types are themselves array
7173 types. Here we squish that down, so that each multidimensional array
7174 type gets only one array_type DIE in the Dwarf debugging info. The draft
7175 Dwarf specification say that we are allowed to do this kind of
7176 compression in C (because there is no difference between an array or
7177 arrays and a multidimensional array in C) but for other source languages
7178 (e.g. Ada) we probably shouldn't do this. */
7180 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7181 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7182 We work around this by disabling this feature. See also
7183 gen_array_type_die. */
7184 #ifndef MIPS_DEBUGGING_INFO
7185 for (dimension_number
= 0;
7186 TREE_CODE (type
) == ARRAY_TYPE
;
7187 type
= TREE_TYPE (type
), dimension_number
++)
7190 register tree domain
= TYPE_DOMAIN (type
);
7192 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7193 and (in GNU C only) variable bounds. Handle all three forms
7195 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
);
7198 /* We have an array type with specified bounds. */
7199 lower
= TYPE_MIN_VALUE (domain
);
7200 upper
= TYPE_MAX_VALUE (domain
);
7202 /* define the index type. */
7203 if (TREE_TYPE (domain
))
7205 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7206 TREE_TYPE field. We can't emit debug info for this
7207 because it is an unnamed integral type. */
7208 if (TREE_CODE (domain
) == INTEGER_TYPE
7209 && TYPE_NAME (domain
) == NULL_TREE
7210 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
7211 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
7214 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
7218 /* ??? If upper is NULL, the array has unspecified length,
7219 but it does have a lower bound. This happens with Fortran
7221 Since the debugger is definitely going to need to know N
7222 to produce useful results, go ahead and output the lower
7223 bound solo, and hope the debugger can cope. */
7225 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
7227 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
7230 /* We have an array type with an unspecified length. The DWARF-2
7231 spec does not say how to handle this; let's just leave out the
7236 #ifndef MIPS_DEBUGGING_INFO
7242 add_byte_size_attribute (die
, tree_node
)
7244 register tree tree_node
;
7246 register unsigned size
;
7248 switch (TREE_CODE (tree_node
))
7256 case QUAL_UNION_TYPE
:
7257 size
= int_size_in_bytes (tree_node
);
7260 /* For a data member of a struct or union, the DW_AT_byte_size is
7261 generally given as the number of bytes normally allocated for an
7262 object of the *declared* type of the member itself. This is true
7263 even for bit-fields. */
7264 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
7270 /* Note that `size' might be -1 when we get to this point. If it is, that
7271 indicates that the byte size of the entity in question is variable. We
7272 have no good way of expressing this fact in Dwarf at the present time,
7273 so just let the -1 pass on through. */
7275 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
7278 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7279 which specifies the distance in bits from the highest order bit of the
7280 "containing object" for the bit-field to the highest order bit of the
7283 For any given bit-field, the "containing object" is a hypothetical
7284 object (of some integral or enum type) within which the given bit-field
7285 lives. The type of this hypothetical "containing object" is always the
7286 same as the declared type of the individual bit-field itself. The
7287 determination of the exact location of the "containing object" for a
7288 bit-field is rather complicated. It's handled by the
7289 `field_byte_offset' function (above).
7291 Note that it is the size (in bytes) of the hypothetical "containing object"
7292 which will be given in the DW_AT_byte_size attribute for this bit-field.
7293 (See `byte_size_attribute' above). */
7296 add_bit_offset_attribute (die
, decl
)
7297 register dw_die_ref die
;
7300 register unsigned object_offset_in_bytes
= field_byte_offset (decl
);
7301 register tree type
= DECL_BIT_FIELD_TYPE (decl
);
7302 register tree bitpos_tree
= DECL_FIELD_BITPOS (decl
);
7303 register unsigned bitpos_int
;
7304 register unsigned highest_order_object_bit_offset
;
7305 register unsigned highest_order_field_bit_offset
;
7306 register unsigned bit_offset
;
7308 /* Must be a field and a bit field. */
7310 || TREE_CODE (decl
) != FIELD_DECL
)
7313 /* We can't yet handle bit-fields whose offsets are variable, so if we
7314 encounter such things, just return without generating any attribute
7316 if (TREE_CODE (bitpos_tree
) != INTEGER_CST
)
7319 bitpos_int
= (unsigned) TREE_INT_CST_LOW (bitpos_tree
);
7321 /* Note that the bit offset is always the distance (in bits) from the
7322 highest-order bit of the "containing object" to the highest-order bit of
7323 the bit-field itself. Since the "high-order end" of any object or field
7324 is different on big-endian and little-endian machines, the computation
7325 below must take account of these differences. */
7326 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
7327 highest_order_field_bit_offset
= bitpos_int
;
7329 if (! BYTES_BIG_ENDIAN
)
7331 highest_order_field_bit_offset
7332 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl
));
7334 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
7338 = (! BYTES_BIG_ENDIAN
7339 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
7340 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
7342 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
7345 /* For a FIELD_DECL node which represents a bit field, output an attribute
7346 which specifies the length in bits of the given field. */
7349 add_bit_size_attribute (die
, decl
)
7350 register dw_die_ref die
;
7353 /* Must be a field and a bit field. */
7354 if (TREE_CODE (decl
) != FIELD_DECL
7355 || ! DECL_BIT_FIELD_TYPE (decl
))
7357 add_AT_unsigned (die
, DW_AT_bit_size
,
7358 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl
)));
7361 /* If the compiled language is ANSI C, then add a 'prototyped'
7362 attribute, if arg types are given for the parameters of a function. */
7365 add_prototyped_attribute (die
, func_type
)
7366 register dw_die_ref die
;
7367 register tree func_type
;
7369 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
7370 && TYPE_ARG_TYPES (func_type
) != NULL
)
7371 add_AT_flag (die
, DW_AT_prototyped
, 1);
7375 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7376 by looking in either the type declaration or object declaration
7380 add_abstract_origin_attribute (die
, origin
)
7381 register dw_die_ref die
;
7382 register tree origin
;
7384 dw_die_ref origin_die
= NULL
;
7386 if (TREE_CODE (origin
) != FUNCTION_DECL
)
7388 /* We may have gotten separated from the block for the inlined
7389 function, if we're in an exception handler or some such; make
7390 sure that the abstract function has been written out.
7392 Doing this for nested functions is wrong, however; functions are
7393 distinct units, and our context might not even be inline. */
7396 fn
= TYPE_STUB_DECL (fn
);
7397 fn
= decl_function_context (fn
);
7399 gen_abstract_function (fn
);
7402 if (TREE_CODE_CLASS (TREE_CODE (origin
)) == 'd')
7403 origin_die
= lookup_decl_die (origin
);
7404 else if (TREE_CODE_CLASS (TREE_CODE (origin
)) == 't')
7405 origin_die
= lookup_type_die (origin
);
7407 if (origin_die
== NULL
)
7410 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
7413 /* We do not currently support the pure_virtual attribute. */
7416 add_pure_or_virtual_attribute (die
, func_decl
)
7417 register dw_die_ref die
;
7418 register tree func_decl
;
7420 if (DECL_VINDEX (func_decl
))
7422 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
7423 add_AT_loc (die
, DW_AT_vtable_elem_location
,
7424 new_loc_descr (DW_OP_constu
,
7425 TREE_INT_CST_LOW (DECL_VINDEX (func_decl
)),
7428 /* GNU extension: Record what type this method came from originally. */
7429 if (debug_info_level
> DINFO_LEVEL_TERSE
)
7430 add_AT_die_ref (die
, DW_AT_containing_type
,
7431 lookup_type_die (DECL_CONTEXT (func_decl
)));
7435 /* Add source coordinate attributes for the given decl. */
7438 add_src_coords_attributes (die
, decl
)
7439 register dw_die_ref die
;
7442 register unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
7444 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
7445 add_AT_unsigned (die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
7448 /* Add an DW_AT_name attribute and source coordinate attribute for the
7449 given decl, but only if it actually has a name. */
7452 add_name_and_src_coords_attributes (die
, decl
)
7453 register dw_die_ref die
;
7456 register tree decl_name
;
7458 decl_name
= DECL_NAME (decl
);
7459 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
7461 add_name_attribute (die
, dwarf2_name (decl
, 0));
7462 if (! DECL_ARTIFICIAL (decl
))
7463 add_src_coords_attributes (die
, decl
);
7465 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
7466 && TREE_PUBLIC (decl
)
7467 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
7468 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
7469 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
7473 /* Push a new declaration scope. */
7476 push_decl_scope (scope
)
7479 /* Make room in the decl_scope_table, if necessary. */
7480 if (decl_scope_table_allocated
== decl_scope_depth
)
7482 decl_scope_table_allocated
+= DECL_SCOPE_TABLE_INCREMENT
;
7484 = (tree
*) xrealloc (decl_scope_table
,
7485 decl_scope_table_allocated
* sizeof (tree
));
7488 decl_scope_table
[decl_scope_depth
] = scope
;
7492 /* Pop a declaration scope. */
7496 if (decl_scope_depth
<= 0)
7501 /* Return the DIE for the scope that immediately contains this type.
7502 Non-named types get global scope. Named types nested in other
7503 types get their containing scope if it's open, or global scope
7504 otherwise. All other types (i.e. function-local named types) get
7505 the current active scope. */
7508 scope_die_for (t
, context_die
)
7510 register dw_die_ref context_die
;
7512 register dw_die_ref scope_die
= NULL
;
7513 register tree containing_scope
;
7516 /* Non-types always go in the current scope. */
7520 containing_scope
= TYPE_CONTEXT (t
);
7522 /* Ignore namespaces for the moment. */
7523 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
7524 containing_scope
= NULL_TREE
;
7526 /* Ignore function type "scopes" from the C frontend. They mean that
7527 a tagged type is local to a parmlist of a function declarator, but
7528 that isn't useful to DWARF. */
7529 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
7530 containing_scope
= NULL_TREE
;
7532 if (containing_scope
== NULL_TREE
)
7533 scope_die
= comp_unit_die
;
7534 else if (TYPE_P (containing_scope
))
7536 /* For types, we can just look up the appropriate DIE. But
7537 first we check to see if we're in the middle of emitting it
7538 so we know where the new DIE should go. */
7540 for (i
= decl_scope_depth
- 1; i
>= 0; --i
)
7541 if (decl_scope_table
[i
] == containing_scope
)
7546 if (debug_info_level
> DINFO_LEVEL_TERSE
7547 && !TREE_ASM_WRITTEN (containing_scope
))
7550 /* If none of the current dies are suitable, we get file scope. */
7551 scope_die
= comp_unit_die
;
7554 scope_die
= lookup_type_die (containing_scope
);
7557 scope_die
= context_die
;
7562 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
7564 static inline int local_scope_p
PARAMS ((dw_die_ref
));
7566 local_scope_p (context_die
)
7567 dw_die_ref context_die
;
7569 for (; context_die
; context_die
= context_die
->die_parent
)
7570 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
7571 || context_die
->die_tag
== DW_TAG_subprogram
)
7576 /* Returns nonzero iff CONTEXT_DIE is a class. */
7578 static inline int class_scope_p
PARAMS ((dw_die_ref
));
7580 class_scope_p (context_die
)
7581 dw_die_ref context_die
;
7584 && (context_die
->die_tag
== DW_TAG_structure_type
7585 || context_die
->die_tag
== DW_TAG_union_type
));
7588 /* Many forms of DIEs require a "type description" attribute. This
7589 routine locates the proper "type descriptor" die for the type given
7590 by 'type', and adds an DW_AT_type attribute below the given die. */
7593 add_type_attribute (object_die
, type
, decl_const
, decl_volatile
, context_die
)
7594 register dw_die_ref object_die
;
7596 register int decl_const
;
7597 register int decl_volatile
;
7598 register dw_die_ref context_die
;
7600 register enum tree_code code
= TREE_CODE (type
);
7601 register dw_die_ref type_die
= NULL
;
7603 /* ??? If this type is an unnamed subrange type of an integral or
7604 floating-point type, use the inner type. This is because we have no
7605 support for unnamed types in base_type_die. This can happen if this is
7606 an Ada subrange type. Correct solution is emit a subrange type die. */
7607 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
7608 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
7609 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
7611 if (code
== ERROR_MARK
)
7614 /* Handle a special case. For functions whose return type is void, we
7615 generate *no* type attribute. (Note that no object may have type
7616 `void', so this only applies to function return types). */
7617 if (code
== VOID_TYPE
)
7620 type_die
= modified_type_die (type
,
7621 decl_const
|| TYPE_READONLY (type
),
7622 decl_volatile
|| TYPE_VOLATILE (type
),
7624 if (type_die
!= NULL
)
7625 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
7628 /* Given a tree pointer to a struct, class, union, or enum type node, return
7629 a pointer to the (string) tag name for the given type, or zero if the type
7630 was declared without a tag. */
7636 register char *name
= 0;
7638 if (TYPE_NAME (type
) != 0)
7640 register tree t
= 0;
7642 /* Find the IDENTIFIER_NODE for the type name. */
7643 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
7644 t
= TYPE_NAME (type
);
7646 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7647 a TYPE_DECL node, regardless of whether or not a `typedef' was
7649 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
7650 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
7651 t
= DECL_NAME (TYPE_NAME (type
));
7653 /* Now get the name as a string, or invent one. */
7655 name
= IDENTIFIER_POINTER (t
);
7658 return (name
== 0 || *name
== '\0') ? 0 : name
;
7661 /* Return the type associated with a data member, make a special check
7662 for bit field types. */
7665 member_declared_type (member
)
7666 register tree member
;
7668 return (DECL_BIT_FIELD_TYPE (member
)
7669 ? DECL_BIT_FIELD_TYPE (member
)
7670 : TREE_TYPE (member
));
7673 /* Get the decl's label, as described by its RTL. This may be different
7674 from the DECL_NAME name used in the source file. */
7678 decl_start_label (decl
)
7683 x
= DECL_RTL (decl
);
7684 if (GET_CODE (x
) != MEM
)
7688 if (GET_CODE (x
) != SYMBOL_REF
)
7691 fnname
= XSTR (x
, 0);
7696 /* These routines generate the internal representation of the DIE's for
7697 the compilation unit. Debugging information is collected by walking
7698 the declaration trees passed in from dwarf2out_decl(). */
7701 gen_array_type_die (type
, context_die
)
7703 register dw_die_ref context_die
;
7705 register dw_die_ref scope_die
= scope_die_for (type
, context_die
);
7706 register dw_die_ref array_die
;
7707 register tree element_type
;
7709 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7710 the inner array type comes before the outer array type. Thus we must
7711 call gen_type_die before we call new_die. See below also. */
7712 #ifdef MIPS_DEBUGGING_INFO
7713 gen_type_die (TREE_TYPE (type
), context_die
);
7716 array_die
= new_die (DW_TAG_array_type
, scope_die
);
7719 /* We default the array ordering. SDB will probably do
7720 the right things even if DW_AT_ordering is not present. It's not even
7721 an issue until we start to get into multidimensional arrays anyway. If
7722 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7723 then we'll have to put the DW_AT_ordering attribute back in. (But if
7724 and when we find out that we need to put these in, we will only do so
7725 for multidimensional arrays. */
7726 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
7729 #ifdef MIPS_DEBUGGING_INFO
7730 /* The SGI compilers handle arrays of unknown bound by setting
7731 AT_declaration and not emitting any subrange DIEs. */
7732 if (! TYPE_DOMAIN (type
))
7733 add_AT_unsigned (array_die
, DW_AT_declaration
, 1);
7736 add_subscript_info (array_die
, type
);
7738 add_name_attribute (array_die
, type_tag (type
));
7739 equate_type_number_to_die (type
, array_die
);
7741 /* Add representation of the type of the elements of this array type. */
7742 element_type
= TREE_TYPE (type
);
7744 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7745 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7746 We work around this by disabling this feature. See also
7747 add_subscript_info. */
7748 #ifndef MIPS_DEBUGGING_INFO
7749 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
7750 element_type
= TREE_TYPE (element_type
);
7752 gen_type_die (element_type
, context_die
);
7755 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
7759 gen_set_type_die (type
, context_die
)
7761 register dw_die_ref context_die
;
7763 register dw_die_ref type_die
7764 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
));
7766 equate_type_number_to_die (type
, type_die
);
7767 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
7772 gen_entry_point_die (decl
, context_die
)
7774 register dw_die_ref context_die
;
7776 register tree origin
= decl_ultimate_origin (decl
);
7777 register dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
);
7779 add_abstract_origin_attribute (decl_die
, origin
);
7782 add_name_and_src_coords_attributes (decl_die
, decl
);
7783 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
7787 if (DECL_ABSTRACT (decl
))
7788 equate_decl_number_to_die (decl
, decl_die
);
7790 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
7794 /* Remember a type in the incomplete_types_list. */
7797 add_incomplete_type (type
)
7800 if (incomplete_types
== incomplete_types_allocated
)
7802 incomplete_types_allocated
+= INCOMPLETE_TYPES_INCREMENT
;
7803 incomplete_types_list
7804 = (tree
*) xrealloc (incomplete_types_list
,
7805 sizeof (tree
) * incomplete_types_allocated
);
7808 incomplete_types_list
[incomplete_types
++] = type
;
7811 /* Walk through the list of incomplete types again, trying once more to
7812 emit full debugging info for them. */
7815 retry_incomplete_types ()
7819 while (incomplete_types
)
7822 type
= incomplete_types_list
[incomplete_types
];
7823 gen_type_die (type
, comp_unit_die
);
7827 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7830 gen_inlined_enumeration_type_die (type
, context_die
)
7832 register dw_die_ref context_die
;
7834 register dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
,
7836 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7837 be incomplete and such types are not marked. */
7838 add_abstract_origin_attribute (type_die
, type
);
7841 /* Generate a DIE to represent an inlined instance of a structure type. */
7844 gen_inlined_structure_type_die (type
, context_die
)
7846 register dw_die_ref context_die
;
7848 register dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
);
7850 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7851 be incomplete and such types are not marked. */
7852 add_abstract_origin_attribute (type_die
, type
);
7855 /* Generate a DIE to represent an inlined instance of a union type. */
7858 gen_inlined_union_type_die (type
, context_die
)
7860 register dw_die_ref context_die
;
7862 register dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
);
7864 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7865 be incomplete and such types are not marked. */
7866 add_abstract_origin_attribute (type_die
, type
);
7869 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7870 include all of the information about the enumeration values also. Each
7871 enumerated type name/value is listed as a child of the enumerated type
7875 gen_enumeration_type_die (type
, context_die
)
7877 register dw_die_ref context_die
;
7879 register dw_die_ref type_die
= lookup_type_die (type
);
7881 if (type_die
== NULL
)
7883 type_die
= new_die (DW_TAG_enumeration_type
,
7884 scope_die_for (type
, context_die
));
7885 equate_type_number_to_die (type
, type_die
);
7886 add_name_attribute (type_die
, type_tag (type
));
7888 else if (! TYPE_SIZE (type
))
7891 remove_AT (type_die
, DW_AT_declaration
);
7893 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7894 given enum type is incomplete, do not generate the DW_AT_byte_size
7895 attribute or the DW_AT_element_list attribute. */
7896 if (TYPE_SIZE (type
))
7900 TREE_ASM_WRITTEN (type
) = 1;
7901 add_byte_size_attribute (type_die
, type
);
7902 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
7903 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
7905 /* If the first reference to this type was as the return type of an
7906 inline function, then it may not have a parent. Fix this now. */
7907 if (type_die
->die_parent
== NULL
)
7908 add_child_die (scope_die_for (type
, context_die
), type_die
);
7910 for (link
= TYPE_FIELDS (type
);
7911 link
!= NULL
; link
= TREE_CHAIN (link
))
7913 register dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
);
7915 add_name_attribute (enum_die
,
7916 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
7917 add_AT_unsigned (enum_die
, DW_AT_const_value
,
7918 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link
)));
7922 add_AT_flag (type_die
, DW_AT_declaration
, 1);
7926 /* Generate a DIE to represent either a real live formal parameter decl or to
7927 represent just the type of some formal parameter position in some function
7930 Note that this routine is a bit unusual because its argument may be a
7931 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7932 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7933 node. If it's the former then this function is being called to output a
7934 DIE to represent a formal parameter object (or some inlining thereof). If
7935 it's the latter, then this function is only being called to output a
7936 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7937 argument type of some subprogram type. */
7940 gen_formal_parameter_die (node
, context_die
)
7942 register dw_die_ref context_die
;
7944 register dw_die_ref parm_die
7945 = new_die (DW_TAG_formal_parameter
, context_die
);
7946 register tree origin
;
7948 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
7951 origin
= decl_ultimate_origin (node
);
7953 add_abstract_origin_attribute (parm_die
, origin
);
7956 add_name_and_src_coords_attributes (parm_die
, node
);
7957 add_type_attribute (parm_die
, TREE_TYPE (node
),
7958 TREE_READONLY (node
),
7959 TREE_THIS_VOLATILE (node
),
7961 if (DECL_ARTIFICIAL (node
))
7962 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
7965 equate_decl_number_to_die (node
, parm_die
);
7966 if (! DECL_ABSTRACT (node
))
7967 add_location_or_const_value_attribute (parm_die
, node
);
7972 /* We were called with some kind of a ..._TYPE node. */
7973 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
7983 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
7984 at the end of an (ANSI prototyped) formal parameters list. */
7987 gen_unspecified_parameters_die (decl_or_type
, context_die
)
7988 register tree decl_or_type ATTRIBUTE_UNUSED
;
7989 register dw_die_ref context_die
;
7991 new_die (DW_TAG_unspecified_parameters
, context_die
);
7994 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
7995 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
7996 parameters as specified in some function type specification (except for
7997 those which appear as part of a function *definition*).
7999 Note we must be careful here to output all of the parameter DIEs before*
8000 we output any DIEs needed to represent the types of the formal parameters.
8001 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
8002 non-parameter DIE it sees ends the formal parameter list. */
8005 gen_formal_types_die (function_or_method_type
, context_die
)
8006 register tree function_or_method_type
;
8007 register dw_die_ref context_die
;
8010 register tree formal_type
= NULL
;
8011 register tree first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
8014 /* In the case where we are generating a formal types list for a C++
8015 non-static member function type, skip over the first thing on the
8016 TYPE_ARG_TYPES list because it only represents the type of the hidden
8017 `this pointer'. The debugger should be able to figure out (without
8018 being explicitly told) that this non-static member function type takes a
8019 `this pointer' and should be able to figure what the type of that hidden
8020 parameter is from the DW_AT_member attribute of the parent
8021 DW_TAG_subroutine_type DIE. */
8022 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
)
8023 first_parm_type
= TREE_CHAIN (first_parm_type
);
8026 /* Make our first pass over the list of formal parameter types and output a
8027 DW_TAG_formal_parameter DIE for each one. */
8028 for (link
= first_parm_type
; link
; link
= TREE_CHAIN (link
))
8030 register dw_die_ref parm_die
;
8032 formal_type
= TREE_VALUE (link
);
8033 if (formal_type
== void_type_node
)
8036 /* Output a (nameless) DIE to represent the formal parameter itself. */
8037 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
8038 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
8039 && link
== first_parm_type
)
8040 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
8043 /* If this function type has an ellipsis, add a
8044 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8045 if (formal_type
!= void_type_node
)
8046 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
8048 /* Make our second (and final) pass over the list of formal parameter types
8049 and output DIEs to represent those types (as necessary). */
8050 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
8052 link
= TREE_CHAIN (link
))
8054 formal_type
= TREE_VALUE (link
);
8055 if (formal_type
== void_type_node
)
8058 gen_type_die (formal_type
, context_die
);
8062 /* We want to generate the DIE for TYPE so that we can generate the
8063 die for MEMBER, which has been defined; we will need to refer back
8064 to the member declaration nested within TYPE. If we're trying to
8065 generate minimal debug info for TYPE, processing TYPE won't do the
8066 trick; we need to attach the member declaration by hand. */
8069 gen_type_die_for_member (type
, member
, context_die
)
8071 dw_die_ref context_die
;
8073 gen_type_die (type
, context_die
);
8075 /* If we're trying to avoid duplicate debug info, we may not have
8076 emitted the member decl for this function. Emit it now. */
8077 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
8078 && ! lookup_decl_die (member
))
8080 if (decl_ultimate_origin (member
))
8083 push_decl_scope (type
);
8084 if (TREE_CODE (member
) == FUNCTION_DECL
)
8085 gen_subprogram_die (member
, lookup_type_die (type
));
8087 gen_variable_die (member
, lookup_type_die (type
));
8092 /* Generate the DWARF2 info for the "abstract" instance
8093 of a function which we may later generate inlined and/or
8094 out-of-line instances of. */
8097 gen_abstract_function (decl
)
8100 register dw_die_ref old_die
= lookup_decl_die (decl
);
8103 if (old_die
&& get_AT_unsigned (old_die
, DW_AT_inline
))
8104 /* We've already generated the abstract instance. */
8107 save_fn
= current_function_decl
;
8108 current_function_decl
= decl
;
8110 set_decl_abstract_flags (decl
, 1);
8111 dwarf2out_decl (decl
);
8112 set_decl_abstract_flags (decl
, 0);
8114 current_function_decl
= save_fn
;
8117 /* Generate a DIE to represent a declared function (either file-scope or
8121 gen_subprogram_die (decl
, context_die
)
8123 register dw_die_ref context_die
;
8125 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
8126 register tree origin
= decl_ultimate_origin (decl
);
8127 register dw_die_ref subr_die
;
8128 register rtx fp_reg
;
8129 register tree fn_arg_types
;
8130 register tree outer_scope
;
8131 register dw_die_ref old_die
= lookup_decl_die (decl
);
8132 register int declaration
= (current_function_decl
!= decl
8133 || class_scope_p (context_die
));
8135 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
8136 be true, if we started to generate the abstract instance of an inline,
8137 decided to output its containing class, and proceeded to emit the
8138 declaration of the inline from the member list for the class. In that
8139 case, `declaration' takes priority; we'll get back to the abstract
8140 instance when we're done with the class. */
8144 if (declaration
&& ! local_scope_p (context_die
))
8147 subr_die
= new_die (DW_TAG_subprogram
, context_die
);
8148 add_abstract_origin_attribute (subr_die
, origin
);
8150 else if (old_die
&& DECL_ABSTRACT (decl
)
8151 && get_AT_unsigned (old_die
, DW_AT_inline
))
8153 /* This must be a redefinition of an extern inline function.
8154 We can just reuse the old die here. */
8157 /* Clear out the inlined attribute and parm types. */
8158 remove_AT (subr_die
, DW_AT_inline
);
8159 remove_children (subr_die
);
8163 register unsigned file_index
8164 = lookup_filename (DECL_SOURCE_FILE (decl
));
8166 if (get_AT_flag (old_die
, DW_AT_declaration
) != 1)
8168 /* ??? This can happen if there is a bug in the program, for
8169 instance, if it has duplicate function definitions. Ideally,
8170 we should detect this case and ignore it. For now, if we have
8171 already reported an error, any error at all, then assume that
8172 we got here because of a input error, not a dwarf2 bug. */
8178 /* If the definition comes from the same place as the declaration,
8179 maybe use the old DIE. We always want the DIE for this function
8180 that has the *_pc attributes to be under comp_unit_die so the
8181 debugger can find it. For inlines, that is the concrete instance,
8182 so we can use the old DIE here. For non-inline methods, we want a
8183 specification DIE at toplevel, so we need a new DIE. For local
8184 class methods, this doesn't apply; we just use the old DIE. */
8185 if ((DECL_ABSTRACT (decl
) || old_die
->die_parent
== comp_unit_die
8186 || context_die
== NULL
)
8187 && (DECL_ARTIFICIAL (decl
)
8188 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
8189 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
8190 == (unsigned)DECL_SOURCE_LINE (decl
)))))
8194 /* Clear out the declaration attribute and the parm types. */
8195 remove_AT (subr_die
, DW_AT_declaration
);
8196 remove_children (subr_die
);
8200 subr_die
= new_die (DW_TAG_subprogram
, context_die
);
8201 add_AT_die_ref (subr_die
, DW_AT_specification
, old_die
);
8202 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
8203 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
8204 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
8205 != (unsigned)DECL_SOURCE_LINE (decl
))
8207 (subr_die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
8212 subr_die
= new_die (DW_TAG_subprogram
, context_die
);
8214 if (TREE_PUBLIC (decl
))
8215 add_AT_flag (subr_die
, DW_AT_external
, 1);
8217 add_name_and_src_coords_attributes (subr_die
, decl
);
8218 if (debug_info_level
> DINFO_LEVEL_TERSE
)
8220 register tree type
= TREE_TYPE (decl
);
8222 add_prototyped_attribute (subr_die
, type
);
8223 add_type_attribute (subr_die
, TREE_TYPE (type
), 0, 0, context_die
);
8226 add_pure_or_virtual_attribute (subr_die
, decl
);
8227 if (DECL_ARTIFICIAL (decl
))
8228 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
8229 if (TREE_PROTECTED (decl
))
8230 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8231 else if (TREE_PRIVATE (decl
))
8232 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
8238 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
8240 /* The first time we see a member function, it is in the context of
8241 the class to which it belongs. We make sure of this by emitting
8242 the class first. The next time is the definition, which is
8243 handled above. The two may come from the same source text. */
8244 if (DECL_CONTEXT (decl
) || DECL_ABSTRACT (decl
))
8245 equate_decl_number_to_die (decl
, subr_die
);
8247 else if (DECL_ABSTRACT (decl
))
8249 if (DECL_INLINE (decl
) && !flag_no_inline
)
8251 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
8252 inline functions, but not for extern inline functions.
8253 We can't get this completely correct because information
8254 about whether the function was declared inline is not
8256 if (DECL_DEFER_OUTPUT (decl
))
8257 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
8259 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
8262 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
8264 equate_decl_number_to_die (decl
, subr_die
);
8266 else if (!DECL_EXTERNAL (decl
))
8268 if (origin
== NULL_TREE
)
8269 equate_decl_number_to_die (decl
, subr_die
);
8271 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
8272 current_funcdef_number
);
8273 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
8274 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
8275 current_funcdef_number
);
8276 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
8278 add_pubname (decl
, subr_die
);
8279 add_arange (decl
, subr_die
);
8281 #ifdef MIPS_DEBUGGING_INFO
8282 /* Add a reference to the FDE for this routine. */
8283 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
8286 /* Define the "frame base" location for this routine. We use the
8287 frame pointer or stack pointer registers, since the RTL for local
8288 variables is relative to one of them. */
8290 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
8291 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
8294 /* ??? This fails for nested inline functions, because context_display
8295 is not part of the state saved/restored for inline functions. */
8296 if (current_function_needs_context
)
8297 add_AT_location_description (subr_die
, DW_AT_static_link
,
8298 lookup_static_chain (decl
));
8302 /* Now output descriptions of the arguments for this function. This gets
8303 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8304 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8305 `...' at the end of the formal parameter list. In order to find out if
8306 there was a trailing ellipsis or not, we must instead look at the type
8307 associated with the FUNCTION_DECL. This will be a node of type
8308 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8309 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8310 an ellipsis at the end. */
8312 /* In the case where we are describing a mere function declaration, all we
8313 need to do here (and all we *can* do here) is to describe the *types* of
8314 its formal parameters. */
8315 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
8317 else if (declaration
)
8318 gen_formal_types_die (TREE_TYPE (decl
), subr_die
);
8321 /* Generate DIEs to represent all known formal parameters */
8322 register tree arg_decls
= DECL_ARGUMENTS (decl
);
8325 /* When generating DIEs, generate the unspecified_parameters DIE
8326 instead if we come across the arg "__builtin_va_alist" */
8327 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
8328 if (TREE_CODE (parm
) == PARM_DECL
)
8330 if (DECL_NAME (parm
)
8331 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
8332 "__builtin_va_alist"))
8333 gen_unspecified_parameters_die (parm
, subr_die
);
8335 gen_decl_die (parm
, subr_die
);
8338 /* Decide whether we need a unspecified_parameters DIE at the end.
8339 There are 2 more cases to do this for: 1) the ansi ... declaration -
8340 this is detectable when the end of the arg list is not a
8341 void_type_node 2) an unprototyped function declaration (not a
8342 definition). This just means that we have no info about the
8343 parameters at all. */
8344 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
8345 if (fn_arg_types
!= NULL
)
8347 /* this is the prototyped case, check for ... */
8348 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
8349 gen_unspecified_parameters_die (decl
, subr_die
);
8351 else if (DECL_INITIAL (decl
) == NULL_TREE
)
8352 gen_unspecified_parameters_die (decl
, subr_die
);
8355 /* Output Dwarf info for all of the stuff within the body of the function
8356 (if it has one - it may be just a declaration). */
8357 outer_scope
= DECL_INITIAL (decl
);
8359 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8360 node created to represent a function. This outermost BLOCK actually
8361 represents the outermost binding contour for the function, i.e. the
8362 contour in which the function's formal parameters and labels get
8363 declared. Curiously, it appears that the front end doesn't actually
8364 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8365 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8366 list for the function instead.) The BLOCK_VARS list for the
8367 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8368 the function however, and we output DWARF info for those in
8369 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8370 node representing the function's outermost pair of curly braces, and
8371 any blocks used for the base and member initializers of a C++
8372 constructor function. */
8373 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
8375 current_function_has_inlines
= 0;
8376 decls_for_scope (outer_scope
, subr_die
, 0);
8378 #if 0 && defined (MIPS_DEBUGGING_INFO)
8379 if (current_function_has_inlines
)
8381 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
8382 if (! comp_unit_has_inlines
)
8384 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
8385 comp_unit_has_inlines
= 1;
8392 /* Generate a DIE to represent a declared data object. */
8395 gen_variable_die (decl
, context_die
)
8397 register dw_die_ref context_die
;
8399 register tree origin
= decl_ultimate_origin (decl
);
8400 register dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
);
8402 dw_die_ref old_die
= lookup_decl_die (decl
);
8403 int declaration
= (DECL_EXTERNAL (decl
)
8404 || class_scope_p (context_die
));
8407 add_abstract_origin_attribute (var_die
, origin
);
8408 /* Loop unrolling can create multiple blocks that refer to the same
8409 static variable, so we must test for the DW_AT_declaration flag. */
8410 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8411 copy decls and set the DECL_ABSTRACT flag on them instead of
8413 else if (old_die
&& TREE_STATIC (decl
)
8414 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
8416 /* This is a definition of a C++ class level static. */
8417 add_AT_die_ref (var_die
, DW_AT_specification
, old_die
);
8418 if (DECL_NAME (decl
))
8420 register unsigned file_index
8421 = lookup_filename (DECL_SOURCE_FILE (decl
));
8423 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
8424 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
8426 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
8427 != (unsigned)DECL_SOURCE_LINE (decl
))
8429 add_AT_unsigned (var_die
, DW_AT_decl_line
,
8430 DECL_SOURCE_LINE (decl
));
8435 add_name_and_src_coords_attributes (var_die
, decl
);
8436 add_type_attribute (var_die
, TREE_TYPE (decl
),
8437 TREE_READONLY (decl
),
8438 TREE_THIS_VOLATILE (decl
), context_die
);
8440 if (TREE_PUBLIC (decl
))
8441 add_AT_flag (var_die
, DW_AT_external
, 1);
8443 if (DECL_ARTIFICIAL (decl
))
8444 add_AT_flag (var_die
, DW_AT_artificial
, 1);
8446 if (TREE_PROTECTED (decl
))
8447 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8449 else if (TREE_PRIVATE (decl
))
8450 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
8454 add_AT_flag (var_die
, DW_AT_declaration
, 1);
8456 if (class_scope_p (context_die
) || DECL_ABSTRACT (decl
))
8457 equate_decl_number_to_die (decl
, var_die
);
8459 if (! declaration
&& ! DECL_ABSTRACT (decl
))
8461 add_location_or_const_value_attribute (var_die
, decl
);
8462 add_pubname (decl
, var_die
);
8466 /* Generate a DIE to represent a label identifier. */
8469 gen_label_die (decl
, context_die
)
8471 register dw_die_ref context_die
;
8473 register tree origin
= decl_ultimate_origin (decl
);
8474 register dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
);
8476 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8477 char label2
[MAX_ARTIFICIAL_LABEL_BYTES
];
8480 add_abstract_origin_attribute (lbl_die
, origin
);
8482 add_name_and_src_coords_attributes (lbl_die
, decl
);
8484 if (DECL_ABSTRACT (decl
))
8485 equate_decl_number_to_die (decl
, lbl_die
);
8488 insn
= DECL_RTL (decl
);
8490 /* Deleted labels are programmer specified labels which have been
8491 eliminated because of various optimisations. We still emit them
8492 here so that it is possible to put breakpoints on them. */
8493 if (GET_CODE (insn
) == CODE_LABEL
8494 || ((GET_CODE (insn
) == NOTE
8495 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
)))
8497 /* When optimization is enabled (via -O) some parts of the compiler
8498 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8499 represent source-level labels which were explicitly declared by
8500 the user. This really shouldn't be happening though, so catch
8501 it if it ever does happen. */
8502 if (INSN_DELETED_P (insn
))
8505 sprintf (label2
, INSN_LABEL_FMT
, current_funcdef_number
);
8506 ASM_GENERATE_INTERNAL_LABEL (label
, label2
,
8507 (unsigned) INSN_UID (insn
));
8508 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
8513 /* Generate a DIE for a lexical block. */
8516 gen_lexical_block_die (stmt
, context_die
, depth
)
8518 register dw_die_ref context_die
;
8521 register dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
);
8522 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8524 if (! BLOCK_ABSTRACT (stmt
))
8526 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
8527 BLOCK_NUMBER (stmt
));
8528 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
8529 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
8530 BLOCK_NUMBER (stmt
));
8531 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
8534 decls_for_scope (stmt
, stmt_die
, depth
);
8537 /* Generate a DIE for an inlined subprogram. */
8540 gen_inlined_subroutine_die (stmt
, context_die
, depth
)
8542 register dw_die_ref context_die
;
8545 if (! BLOCK_ABSTRACT (stmt
))
8547 register dw_die_ref subr_die
8548 = new_die (DW_TAG_inlined_subroutine
, context_die
);
8549 register tree decl
= block_ultimate_origin (stmt
);
8550 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8552 /* Emit info for the abstract instance first, if we haven't yet. */
8553 gen_abstract_function (decl
);
8555 add_abstract_origin_attribute (subr_die
, decl
);
8556 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
8557 BLOCK_NUMBER (stmt
));
8558 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
8559 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
8560 BLOCK_NUMBER (stmt
));
8561 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
8562 decls_for_scope (stmt
, subr_die
, depth
);
8563 current_function_has_inlines
= 1;
8567 /* Generate a DIE for a field in a record, or structure. */
8570 gen_field_die (decl
, context_die
)
8572 register dw_die_ref context_die
;
8574 register dw_die_ref decl_die
= new_die (DW_TAG_member
, context_die
);
8576 add_name_and_src_coords_attributes (decl_die
, decl
);
8577 add_type_attribute (decl_die
, member_declared_type (decl
),
8578 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
8581 /* If this is a bit field... */
8582 if (DECL_BIT_FIELD_TYPE (decl
))
8584 add_byte_size_attribute (decl_die
, decl
);
8585 add_bit_size_attribute (decl_die
, decl
);
8586 add_bit_offset_attribute (decl_die
, decl
);
8589 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
8590 add_data_member_location_attribute (decl_die
, decl
);
8592 if (DECL_ARTIFICIAL (decl
))
8593 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
8595 if (TREE_PROTECTED (decl
))
8596 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8598 else if (TREE_PRIVATE (decl
))
8599 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
8603 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8604 Use modified_type_die instead.
8605 We keep this code here just in case these types of DIEs may be needed to
8606 represent certain things in other languages (e.g. Pascal) someday. */
8608 gen_pointer_type_die (type
, context_die
)
8610 register dw_die_ref context_die
;
8612 register dw_die_ref ptr_die
8613 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
));
8615 equate_type_number_to_die (type
, ptr_die
);
8616 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
8617 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
8620 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8621 Use modified_type_die instead.
8622 We keep this code here just in case these types of DIEs may be needed to
8623 represent certain things in other languages (e.g. Pascal) someday. */
8625 gen_reference_type_die (type
, context_die
)
8627 register dw_die_ref context_die
;
8629 register dw_die_ref ref_die
8630 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
));
8632 equate_type_number_to_die (type
, ref_die
);
8633 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
8634 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
8638 /* Generate a DIE for a pointer to a member type. */
8640 gen_ptr_to_mbr_type_die (type
, context_die
)
8642 register dw_die_ref context_die
;
8644 register dw_die_ref ptr_die
8645 = new_die (DW_TAG_ptr_to_member_type
, scope_die_for (type
, context_die
));
8647 equate_type_number_to_die (type
, ptr_die
);
8648 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
8649 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
8650 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
8653 /* Generate the DIE for the compilation unit. */
8656 gen_compile_unit_die (filename
)
8657 register const char *filename
;
8659 register dw_die_ref die
;
8661 char *wd
= getpwd ();
8664 die
= new_die (DW_TAG_compile_unit
, NULL
);
8665 add_name_attribute (die
, filename
);
8667 if (wd
!= NULL
&& filename
[0] != DIR_SEPARATOR
)
8668 add_AT_string (die
, DW_AT_comp_dir
, wd
);
8670 sprintf (producer
, "%s %s", language_string
, version_string
);
8672 #ifdef MIPS_DEBUGGING_INFO
8673 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8674 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8675 not appear in the producer string, the debugger reaches the conclusion
8676 that the object file is stripped and has no debugging information.
8677 To get the MIPS/SGI debugger to believe that there is debugging
8678 information in the object file, we add a -g to the producer string. */
8679 if (debug_info_level
> DINFO_LEVEL_TERSE
)
8680 strcat (producer
, " -g");
8683 add_AT_string (die
, DW_AT_producer
, producer
);
8685 if (strcmp (language_string
, "GNU C++") == 0)
8686 language
= DW_LANG_C_plus_plus
;
8687 else if (strcmp (language_string
, "GNU Ada") == 0)
8688 language
= DW_LANG_Ada83
;
8689 else if (strcmp (language_string
, "GNU F77") == 0)
8690 language
= DW_LANG_Fortran77
;
8691 else if (strcmp (language_string
, "GNU Pascal") == 0)
8692 language
= DW_LANG_Pascal83
;
8693 else if (flag_traditional
)
8694 language
= DW_LANG_C
;
8696 language
= DW_LANG_C89
;
8698 add_AT_unsigned (die
, DW_AT_language
, language
);
8703 /* Generate a DIE for a string type. */
8706 gen_string_type_die (type
, context_die
)
8708 register dw_die_ref context_die
;
8710 register dw_die_ref type_die
8711 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
));
8713 equate_type_number_to_die (type
, type_die
);
8715 /* Fudge the string length attribute for now. */
8717 /* TODO: add string length info.
8718 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8719 bound_representation (upper_bound, 0, 'u'); */
8722 /* Generate the DIE for a base class. */
8725 gen_inheritance_die (binfo
, context_die
)
8726 register tree binfo
;
8727 register dw_die_ref context_die
;
8729 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
);
8731 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
8732 add_data_member_location_attribute (die
, binfo
);
8734 if (TREE_VIA_VIRTUAL (binfo
))
8735 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
8736 if (TREE_VIA_PUBLIC (binfo
))
8737 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
8738 else if (TREE_VIA_PROTECTED (binfo
))
8739 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8742 /* Generate a DIE for a class member. */
8745 gen_member_die (type
, context_die
)
8747 register dw_die_ref context_die
;
8749 register tree member
;
8752 /* If this is not an incomplete type, output descriptions of each of its
8753 members. Note that as we output the DIEs necessary to represent the
8754 members of this record or union type, we will also be trying to output
8755 DIEs to represent the *types* of those members. However the `type'
8756 function (above) will specifically avoid generating type DIEs for member
8757 types *within* the list of member DIEs for this (containing) type execpt
8758 for those types (of members) which are explicitly marked as also being
8759 members of this (containing) type themselves. The g++ front- end can
8760 force any given type to be treated as a member of some other
8761 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8762 to point to the TREE node representing the appropriate (containing)
8765 /* First output info about the base classes. */
8766 if (TYPE_BINFO (type
) && TYPE_BINFO_BASETYPES (type
))
8768 register tree bases
= TYPE_BINFO_BASETYPES (type
);
8769 register int n_bases
= TREE_VEC_LENGTH (bases
);
8772 for (i
= 0; i
< n_bases
; i
++)
8773 gen_inheritance_die (TREE_VEC_ELT (bases
, i
), context_die
);
8776 /* Now output info about the data members and type members. */
8777 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
8779 /* If we thought we were generating minimal debug info for TYPE
8780 and then changed our minds, some of the member declarations
8781 may have already been defined. Don't define them again, but
8782 do put them in the right order. */
8784 child
= lookup_decl_die (member
);
8786 splice_child_die (context_die
, child
);
8788 gen_decl_die (member
, context_die
);
8791 /* Now output info about the function members (if any). */
8792 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
8794 child
= lookup_decl_die (member
);
8796 splice_child_die (context_die
, child
);
8798 gen_decl_die (member
, context_die
);
8802 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
8803 is set, we pretend that the type was never defined, so we only get the
8804 member DIEs needed by later specification DIEs. */
8807 gen_struct_or_union_type_die (type
, context_die
)
8809 register dw_die_ref context_die
;
8811 register dw_die_ref type_die
= lookup_type_die (type
);
8812 register dw_die_ref scope_die
= 0;
8813 register int nested
= 0;
8814 int complete
= (TYPE_SIZE (type
)
8815 && (! TYPE_STUB_DECL (type
)
8816 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
8818 if (type_die
&& ! complete
)
8821 if (TYPE_CONTEXT (type
) != NULL_TREE
8822 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
)))
8825 scope_die
= scope_die_for (type
, context_die
);
8827 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
8828 /* First occurrence of type or toplevel definition of nested class. */
8830 register dw_die_ref old_die
= type_die
;
8832 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
8833 ? DW_TAG_structure_type
: DW_TAG_union_type
,
8835 equate_type_number_to_die (type
, type_die
);
8836 add_name_attribute (type_die
, type_tag (type
));
8838 add_AT_die_ref (type_die
, DW_AT_specification
, old_die
);
8841 remove_AT (type_die
, DW_AT_declaration
);
8843 /* If this type has been completed, then give it a byte_size attribute and
8844 then give a list of members. */
8847 /* Prevent infinite recursion in cases where the type of some member of
8848 this type is expressed in terms of this type itself. */
8849 TREE_ASM_WRITTEN (type
) = 1;
8850 add_byte_size_attribute (type_die
, type
);
8851 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
8852 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
8854 /* If the first reference to this type was as the return type of an
8855 inline function, then it may not have a parent. Fix this now. */
8856 if (type_die
->die_parent
== NULL
)
8857 add_child_die (scope_die
, type_die
);
8859 push_decl_scope (type
);
8860 gen_member_die (type
, type_die
);
8863 /* GNU extension: Record what type our vtable lives in. */
8864 if (TYPE_VFIELD (type
))
8866 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
8868 gen_type_die (vtype
, context_die
);
8869 add_AT_die_ref (type_die
, DW_AT_containing_type
,
8870 lookup_type_die (vtype
));
8875 add_AT_flag (type_die
, DW_AT_declaration
, 1);
8877 /* We don't need to do this for function-local types. */
8878 if (! decl_function_context (TYPE_STUB_DECL (type
)))
8879 add_incomplete_type (type
);
8883 /* Generate a DIE for a subroutine _type_. */
8886 gen_subroutine_type_die (type
, context_die
)
8888 register dw_die_ref context_die
;
8890 register tree return_type
= TREE_TYPE (type
);
8891 register dw_die_ref subr_die
8892 = new_die (DW_TAG_subroutine_type
, scope_die_for (type
, context_die
));
8894 equate_type_number_to_die (type
, subr_die
);
8895 add_prototyped_attribute (subr_die
, type
);
8896 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
8897 gen_formal_types_die (type
, subr_die
);
8900 /* Generate a DIE for a type definition */
8903 gen_typedef_die (decl
, context_die
)
8905 register dw_die_ref context_die
;
8907 register dw_die_ref type_die
;
8908 register tree origin
;
8910 if (TREE_ASM_WRITTEN (decl
))
8912 TREE_ASM_WRITTEN (decl
) = 1;
8914 type_die
= new_die (DW_TAG_typedef
, context_die
);
8915 origin
= decl_ultimate_origin (decl
);
8917 add_abstract_origin_attribute (type_die
, origin
);
8921 add_name_and_src_coords_attributes (type_die
, decl
);
8922 if (DECL_ORIGINAL_TYPE (decl
))
8924 type
= DECL_ORIGINAL_TYPE (decl
);
8925 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
8928 type
= TREE_TYPE (decl
);
8929 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
8930 TREE_THIS_VOLATILE (decl
), context_die
);
8933 if (DECL_ABSTRACT (decl
))
8934 equate_decl_number_to_die (decl
, type_die
);
8937 /* Generate a type description DIE. */
8940 gen_type_die (type
, context_die
)
8942 register dw_die_ref context_die
;
8946 if (type
== NULL_TREE
|| type
== error_mark_node
)
8949 /* We are going to output a DIE to represent the unqualified version of
8950 this type (i.e. without any const or volatile qualifiers) so get the
8951 main variant (i.e. the unqualified version) of this type now. */
8952 type
= type_main_variant (type
);
8954 if (TREE_ASM_WRITTEN (type
))
8957 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
8958 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
8960 TREE_ASM_WRITTEN (type
) = 1;
8961 gen_decl_die (TYPE_NAME (type
), context_die
);
8965 switch (TREE_CODE (type
))
8971 case REFERENCE_TYPE
:
8972 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
8973 ensures that the gen_type_die recursion will terminate even if the
8974 type is recursive. Recursive types are possible in Ada. */
8975 /* ??? We could perhaps do this for all types before the switch
8977 TREE_ASM_WRITTEN (type
) = 1;
8979 /* For these types, all that is required is that we output a DIE (or a
8980 set of DIEs) to represent the "basis" type. */
8981 gen_type_die (TREE_TYPE (type
), context_die
);
8985 /* This code is used for C++ pointer-to-data-member types.
8986 Output a description of the relevant class type. */
8987 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
8989 /* Output a description of the type of the object pointed to. */
8990 gen_type_die (TREE_TYPE (type
), context_die
);
8992 /* Now output a DIE to represent this pointer-to-data-member type
8994 gen_ptr_to_mbr_type_die (type
, context_die
);
8998 gen_type_die (TYPE_DOMAIN (type
), context_die
);
8999 gen_set_type_die (type
, context_die
);
9003 gen_type_die (TREE_TYPE (type
), context_die
);
9004 abort (); /* No way to represent these in Dwarf yet! */
9008 /* Force out return type (in case it wasn't forced out already). */
9009 gen_type_die (TREE_TYPE (type
), context_die
);
9010 gen_subroutine_type_die (type
, context_die
);
9014 /* Force out return type (in case it wasn't forced out already). */
9015 gen_type_die (TREE_TYPE (type
), context_die
);
9016 gen_subroutine_type_die (type
, context_die
);
9020 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
9022 gen_type_die (TREE_TYPE (type
), context_die
);
9023 gen_string_type_die (type
, context_die
);
9026 gen_array_type_die (type
, context_die
);
9032 case QUAL_UNION_TYPE
:
9033 /* If this is a nested type whose containing class hasn't been
9034 written out yet, writing it out will cover this one, too.
9035 This does not apply to instantiations of member class templates;
9036 they need to be added to the containing class as they are
9037 generated. FIXME: This hurts the idea of combining type decls
9038 from multiple TUs, since we can't predict what set of template
9039 instantiations we'll get. */
9040 if (TYPE_CONTEXT (type
)
9041 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
9042 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
9044 gen_type_die (TYPE_CONTEXT (type
), context_die
);
9046 if (TREE_ASM_WRITTEN (type
))
9049 /* If that failed, attach ourselves to the stub. */
9050 push_decl_scope (TYPE_CONTEXT (type
));
9051 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
9057 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
9058 gen_enumeration_type_die (type
, context_die
);
9060 gen_struct_or_union_type_die (type
, context_die
);
9065 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9066 it up if it is ever completed. gen_*_type_die will set it for us
9067 when appropriate. */
9076 /* No DIEs needed for fundamental types. */
9080 /* No Dwarf representation currently defined. */
9087 TREE_ASM_WRITTEN (type
) = 1;
9090 /* Generate a DIE for a tagged type instantiation. */
9093 gen_tagged_type_instantiation_die (type
, context_die
)
9095 register dw_die_ref context_die
;
9097 if (type
== NULL_TREE
|| type
== error_mark_node
)
9100 /* We are going to output a DIE to represent the unqualified version of
9101 this type (i.e. without any const or volatile qualifiers) so make sure
9102 that we have the main variant (i.e. the unqualified version) of this
9104 if (type
!= type_main_variant (type
))
9107 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
9108 an instance of an unresolved type. */
9110 switch (TREE_CODE (type
))
9116 gen_inlined_enumeration_type_die (type
, context_die
);
9120 gen_inlined_structure_type_die (type
, context_die
);
9124 case QUAL_UNION_TYPE
:
9125 gen_inlined_union_type_die (type
, context_die
);
9133 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
9134 things which are local to the given block. */
9137 gen_block_die (stmt
, context_die
, depth
)
9139 register dw_die_ref context_die
;
9142 register int must_output_die
= 0;
9143 register tree origin
;
9145 register enum tree_code origin_code
;
9147 /* Ignore blocks never really used to make RTL. */
9149 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
)
9150 || (!TREE_ASM_WRITTEN (stmt
) && !BLOCK_ABSTRACT (stmt
)))
9153 /* Determine the "ultimate origin" of this block. This block may be an
9154 inlined instance of an inlined instance of inline function, so we have
9155 to trace all of the way back through the origin chain to find out what
9156 sort of node actually served as the original seed for the creation of
9157 the current block. */
9158 origin
= block_ultimate_origin (stmt
);
9159 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
9161 /* Determine if we need to output any Dwarf DIEs at all to represent this
9163 if (origin_code
== FUNCTION_DECL
)
9164 /* The outer scopes for inlinings *must* always be represented. We
9165 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9166 must_output_die
= 1;
9169 /* In the case where the current block represents an inlining of the
9170 "body block" of an inline function, we must *NOT* output any DIE for
9171 this block because we have already output a DIE to represent the
9172 whole inlined function scope and the "body block" of any function
9173 doesn't really represent a different scope according to ANSI C
9174 rules. So we check here to make sure that this block does not
9175 represent a "body block inlining" before trying to set the
9176 `must_output_die' flag. */
9177 if (! is_body_block (origin
? origin
: stmt
))
9179 /* Determine if this block directly contains any "significant"
9180 local declarations which we will need to output DIEs for. */
9181 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9182 /* We are not in terse mode so *any* local declaration counts
9183 as being a "significant" one. */
9184 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
9186 /* We are in terse mode, so only local (nested) function
9187 definitions count as "significant" local declarations. */
9188 for (decl
= BLOCK_VARS (stmt
);
9189 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
9190 if (TREE_CODE (decl
) == FUNCTION_DECL
9191 && DECL_INITIAL (decl
))
9193 must_output_die
= 1;
9199 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9200 DIE for any block which contains no significant local declarations at
9201 all. Rather, in such cases we just call `decls_for_scope' so that any
9202 needed Dwarf info for any sub-blocks will get properly generated. Note
9203 that in terse mode, our definition of what constitutes a "significant"
9204 local declaration gets restricted to include only inlined function
9205 instances and local (nested) function definitions. */
9206 if (must_output_die
)
9208 if (origin_code
== FUNCTION_DECL
)
9209 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
9211 gen_lexical_block_die (stmt
, context_die
, depth
);
9214 decls_for_scope (stmt
, context_die
, depth
);
9217 /* Generate all of the decls declared within a given scope and (recursively)
9218 all of its sub-blocks. */
9221 decls_for_scope (stmt
, context_die
, depth
)
9223 register dw_die_ref context_die
;
9227 register tree subblocks
;
9229 /* Ignore blocks never really used to make RTL. */
9230 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
9233 /* Output the DIEs to represent all of the data objects and typedefs
9234 declared directly within this block but not within any nested
9235 sub-blocks. Also, nested function and tag DIEs have been
9236 generated with a parent of NULL; fix that up now. */
9237 for (decl
= BLOCK_VARS (stmt
);
9238 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
9240 register dw_die_ref die
;
9242 if (TREE_CODE (decl
) == FUNCTION_DECL
)
9243 die
= lookup_decl_die (decl
);
9244 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
9245 die
= lookup_type_die (TREE_TYPE (decl
));
9249 if (die
!= NULL
&& die
->die_parent
== NULL
)
9250 add_child_die (context_die
, die
);
9252 gen_decl_die (decl
, context_die
);
9255 /* Output the DIEs to represent all sub-blocks (and the items declared
9256 therein) of this block. */
9257 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
9259 subblocks
= BLOCK_CHAIN (subblocks
))
9260 gen_block_die (subblocks
, context_die
, depth
+ 1);
9263 /* Is this a typedef we can avoid emitting? */
9266 is_redundant_typedef (decl
)
9269 if (TYPE_DECL_IS_STUB (decl
))
9272 if (DECL_ARTIFICIAL (decl
)
9273 && DECL_CONTEXT (decl
)
9274 && is_tagged_type (DECL_CONTEXT (decl
))
9275 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
9276 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
9277 /* Also ignore the artificial member typedef for the class name. */
9283 /* Generate Dwarf debug information for a decl described by DECL. */
9286 gen_decl_die (decl
, context_die
)
9288 register dw_die_ref context_die
;
9290 register tree origin
;
9292 if (TREE_CODE (decl
) == ERROR_MARK
)
9295 /* If this ..._DECL node is marked to be ignored, then ignore it. */
9296 if (DECL_IGNORED_P (decl
))
9299 switch (TREE_CODE (decl
))
9302 /* The individual enumerators of an enum type get output when we output
9303 the Dwarf representation of the relevant enum type itself. */
9307 /* Don't output any DIEs to represent mere function declarations,
9308 unless they are class members or explicit block externs. */
9309 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
9310 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
9313 /* Emit info for the abstract instance first, if we haven't yet. */
9314 origin
= decl_ultimate_origin (decl
);
9316 gen_abstract_function (origin
);
9318 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9320 /* Before we describe the FUNCTION_DECL itself, make sure that we
9321 have described its return type. */
9322 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
9324 /* And its virtual context. */
9325 if (DECL_VINDEX (decl
) != NULL_TREE
)
9326 gen_type_die (DECL_CONTEXT (decl
), context_die
);
9328 /* And its containing type. */
9329 origin
= decl_class_context (decl
);
9330 if (origin
!= NULL_TREE
)
9331 gen_type_die_for_member (origin
, decl
, context_die
);
9334 /* Now output a DIE to represent the function itself. */
9335 gen_subprogram_die (decl
, context_die
);
9339 /* If we are in terse mode, don't generate any DIEs to represent any
9341 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9344 /* In the special case of a TYPE_DECL node representing the
9345 declaration of some type tag, if the given TYPE_DECL is marked as
9346 having been instantiated from some other (original) TYPE_DECL node
9347 (e.g. one which was generated within the original definition of an
9348 inline function) we have to generate a special (abbreviated)
9349 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9351 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
9353 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
9357 if (is_redundant_typedef (decl
))
9358 gen_type_die (TREE_TYPE (decl
), context_die
);
9360 /* Output a DIE to represent the typedef itself. */
9361 gen_typedef_die (decl
, context_die
);
9365 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
9366 gen_label_die (decl
, context_die
);
9370 /* If we are in terse mode, don't generate any DIEs to represent any
9371 variable declarations or definitions. */
9372 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9375 /* Output any DIEs that are needed to specify the type of this data
9377 gen_type_die (TREE_TYPE (decl
), context_die
);
9379 /* And its containing type. */
9380 origin
= decl_class_context (decl
);
9381 if (origin
!= NULL_TREE
)
9382 gen_type_die_for_member (origin
, decl
, context_die
);
9384 /* Now output the DIE to represent the data object itself. This gets
9385 complicated because of the possibility that the VAR_DECL really
9386 represents an inlined instance of a formal parameter for an inline
9388 origin
= decl_ultimate_origin (decl
);
9389 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
9390 gen_formal_parameter_die (decl
, context_die
);
9392 gen_variable_die (decl
, context_die
);
9396 /* Ignore the nameless fields that are used to skip bits, but
9397 handle C++ anonymous unions. */
9398 if (DECL_NAME (decl
) != NULL_TREE
9399 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
)
9401 gen_type_die (member_declared_type (decl
), context_die
);
9402 gen_field_die (decl
, context_die
);
9407 gen_type_die (TREE_TYPE (decl
), context_die
);
9408 gen_formal_parameter_die (decl
, context_die
);
9411 case NAMESPACE_DECL
:
9412 /* Ignore for now. */
9420 /* Add Ada "use" clause information for SGI Workshop debugger. */
9423 dwarf2out_add_library_unit_info (filename
, context_list
)
9424 const char *filename
;
9425 const char *context_list
;
9427 unsigned int file_index
;
9429 if (filename
!= NULL
)
9431 dw_die_ref unit_die
= new_die (DW_TAG_module
, comp_unit_die
);
9432 tree context_list_decl
9433 = build_decl (LABEL_DECL
, get_identifier (context_list
),
9436 TREE_PUBLIC (context_list_decl
) = TRUE
;
9437 add_name_attribute (unit_die
, context_list
);
9438 file_index
= lookup_filename (filename
);
9439 add_AT_unsigned (unit_die
, DW_AT_decl_file
, file_index
);
9440 add_pubname (context_list_decl
, unit_die
);
9444 /* Write the debugging output for DECL. */
9447 dwarf2out_decl (decl
)
9450 register dw_die_ref context_die
= comp_unit_die
;
9452 if (TREE_CODE (decl
) == ERROR_MARK
)
9455 /* If this ..._DECL node is marked to be ignored, then ignore it. */
9456 if (DECL_IGNORED_P (decl
))
9459 switch (TREE_CODE (decl
))
9462 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9463 builtin function. Explicit programmer-supplied declarations of
9464 these same functions should NOT be ignored however. */
9465 if (DECL_EXTERNAL (decl
) && DECL_BUILT_IN (decl
))
9468 /* What we would really like to do here is to filter out all mere
9469 file-scope declarations of file-scope functions which are never
9470 referenced later within this translation unit (and keep all of ones
9471 that *are* referenced later on) but we aren't clairvoyant, so we have
9472 no idea which functions will be referenced in the future (i.e. later
9473 on within the current translation unit). So here we just ignore all
9474 file-scope function declarations which are not also definitions. If
9475 and when the debugger needs to know something about these functions,
9476 it will have to hunt around and find the DWARF information associated
9477 with the definition of the function. Note that we can't just check
9478 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9479 definitions and which ones represent mere declarations. We have to
9480 check `DECL_INITIAL' instead. That's because the C front-end
9481 supports some weird semantics for "extern inline" function
9482 definitions. These can get inlined within the current translation
9483 unit (an thus, we need to generate DWARF info for their abstract
9484 instances so that the DWARF info for the concrete inlined instances
9485 can have something to refer to) but the compiler never generates any
9486 out-of-lines instances of such things (despite the fact that they
9487 *are* definitions). The important point is that the C front-end
9488 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9489 to generate DWARF for them anyway. Note that the C++ front-end also
9490 plays some similar games for inline function definitions appearing
9491 within include files which also contain
9492 `#pragma interface' pragmas. */
9493 if (DECL_INITIAL (decl
) == NULL_TREE
)
9496 /* If we're a nested function, initially use a parent of NULL; if we're
9497 a plain function, this will be fixed up in decls_for_scope. If
9498 we're a method, it will be ignored, since we already have a DIE. */
9499 if (decl_function_context (decl
))
9505 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9506 declaration and if the declaration was never even referenced from
9507 within this entire compilation unit. We suppress these DIEs in
9508 order to save space in the .debug section (by eliminating entries
9509 which are probably useless). Note that we must not suppress
9510 block-local extern declarations (whether used or not) because that
9511 would screw-up the debugger's name lookup mechanism and cause it to
9512 miss things which really ought to be in scope at a given point. */
9513 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
9516 /* If we are in terse mode, don't generate any DIEs to represent any
9517 variable declarations or definitions. */
9518 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9523 /* Don't bother trying to generate any DIEs to represent any of the
9524 normal built-in types for the language we are compiling. */
9525 if (DECL_SOURCE_LINE (decl
) == 0)
9527 /* OK, we need to generate one for `bool' so GDB knows what type
9528 comparisons have. */
9529 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
9530 == DW_LANG_C_plus_plus
)
9531 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
)
9532 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
9537 /* If we are in terse mode, don't generate any DIEs for types. */
9538 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9541 /* If we're a function-scope tag, initially use a parent of NULL;
9542 this will be fixed up in decls_for_scope. */
9543 if (decl_function_context (decl
))
9552 gen_decl_die (decl
, context_die
);
9555 /* Output a marker (i.e. a label) for the beginning of the generated code for
9559 dwarf2out_begin_block (blocknum
)
9560 register unsigned blocknum
;
9562 function_section (current_function_decl
);
9563 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
9566 /* Output a marker (i.e. a label) for the end of the generated code for a
9570 dwarf2out_end_block (blocknum
)
9571 register unsigned blocknum
;
9573 function_section (current_function_decl
);
9574 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
9577 /* We've decided not to emit any debugging information for BLOCK; make
9578 sure that we don't end up with orphans as a result. */
9581 dwarf2out_ignore_block (block
)
9585 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
9589 if (TREE_CODE (decl
) == FUNCTION_DECL
)
9590 die
= lookup_decl_die (decl
);
9591 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
9592 die
= lookup_type_die (TREE_TYPE (decl
));
9596 /* Just give them a dummy value for parent so dwarf2out_finish
9597 doesn't blow up; we would use add_child_die if we really
9598 wanted to add them to comp_unit_die's children. */
9599 if (die
&& die
->die_parent
== 0)
9600 die
->die_parent
= comp_unit_die
;
9604 /* Output a marker (i.e. a label) at a point in the assembly code which
9605 corresponds to a given source level label. */
9608 dwarf2out_label (insn
)
9611 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9613 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
9615 function_section (current_function_decl
);
9616 sprintf (label
, INSN_LABEL_FMT
, current_funcdef_number
);
9617 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, label
,
9618 (unsigned) INSN_UID (insn
));
9622 /* Lookup a filename (in the list of filenames that we know about here in
9623 dwarf2out.c) and return its "index". The index of each (known) filename is
9624 just a unique number which is associated with only that one filename.
9625 We need such numbers for the sake of generating labels
9626 (in the .debug_sfnames section) and references to those
9627 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9628 If the filename given as an argument is not found in our current list,
9629 add it to the list and assign it the next available unique index number.
9630 In order to speed up searches, we remember the index of the filename
9631 was looked up last. This handles the majority of all searches. */
9634 lookup_filename (file_name
)
9635 const char *file_name
;
9637 static unsigned last_file_lookup_index
= 0;
9638 register unsigned i
;
9640 /* Check to see if the file name that was searched on the previous call
9641 matches this file name. If so, return the index. */
9642 if (last_file_lookup_index
!= 0)
9643 if (strcmp (file_name
, file_table
[last_file_lookup_index
]) == 0)
9644 return last_file_lookup_index
;
9646 /* Didn't match the previous lookup, search the table */
9647 for (i
= 1; i
< file_table_in_use
; ++i
)
9648 if (strcmp (file_name
, file_table
[i
]) == 0)
9650 last_file_lookup_index
= i
;
9654 /* Prepare to add a new table entry by making sure there is enough space in
9655 the table to do so. If not, expand the current table. */
9656 if (file_table_in_use
== file_table_allocated
)
9658 file_table_allocated
+= FILE_TABLE_INCREMENT
;
9660 = (char **) xrealloc (file_table
,
9661 file_table_allocated
* sizeof (char *));
9664 /* Add the new entry to the end of the filename table. */
9665 file_table
[file_table_in_use
] = xstrdup (file_name
);
9666 last_file_lookup_index
= file_table_in_use
++;
9668 return last_file_lookup_index
;
9671 /* Output a label to mark the beginning of a source code line entry
9672 and record information relating to this source line, in
9673 'line_info_table' for later output of the .debug_line section. */
9676 dwarf2out_line (filename
, line
)
9677 register const char *filename
;
9678 register unsigned line
;
9680 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
9682 function_section (current_function_decl
);
9684 if (DWARF2_ASM_LINE_DEBUG_INFO
)
9686 static const char *lastfile
;
9688 /* Emit the .file and .loc directives understood by GNU as. */
9689 if (lastfile
== 0 || strcmp (filename
, lastfile
))
9692 ggc_add_string_root ((char **) &lastfile
, 1);
9694 fprintf (asm_out_file
, "\t.file 0 \"%s\"\n", filename
);
9695 lastfile
= filename
;
9698 fprintf (asm_out_file
, "\t.loc 0 %d 0\n", line
);
9700 /* Indicate that line number info exists. */
9701 ++line_info_table_in_use
;
9703 /* Indicate that multiple line number tables exist. */
9704 if (DECL_SECTION_NAME (current_function_decl
))
9705 ++separate_line_info_table_in_use
;
9707 else if (DECL_SECTION_NAME (current_function_decl
))
9709 register dw_separate_line_info_ref line_info
;
9710 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
9711 separate_line_info_table_in_use
);
9713 fprintf (asm_out_file
, "\t%s line %d", ASM_COMMENT_START
, line
);
9714 fputc ('\n', asm_out_file
);
9716 /* expand the line info table if necessary */
9717 if (separate_line_info_table_in_use
9718 == separate_line_info_table_allocated
)
9720 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
9721 separate_line_info_table
9722 = (dw_separate_line_info_ref
)
9723 xrealloc (separate_line_info_table
,
9724 separate_line_info_table_allocated
9725 * sizeof (dw_separate_line_info_entry
));
9728 /* Add the new entry at the end of the line_info_table. */
9730 = &separate_line_info_table
[separate_line_info_table_in_use
++];
9731 line_info
->dw_file_num
= lookup_filename (filename
);
9732 line_info
->dw_line_num
= line
;
9733 line_info
->function
= current_funcdef_number
;
9737 register dw_line_info_ref line_info
;
9739 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, LINE_CODE_LABEL
,
9740 line_info_table_in_use
);
9742 fprintf (asm_out_file
, "\t%s line %d", ASM_COMMENT_START
, line
);
9743 fputc ('\n', asm_out_file
);
9745 /* Expand the line info table if necessary. */
9746 if (line_info_table_in_use
== line_info_table_allocated
)
9748 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
9750 = (dw_line_info_ref
)
9751 xrealloc (line_info_table
,
9752 (line_info_table_allocated
9753 * sizeof (dw_line_info_entry
)));
9756 /* Add the new entry at the end of the line_info_table. */
9757 line_info
= &line_info_table
[line_info_table_in_use
++];
9758 line_info
->dw_file_num
= lookup_filename (filename
);
9759 line_info
->dw_line_num
= line
;
9764 /* Record the beginning of a new source file, for later output
9765 of the .debug_macinfo section. At present, unimplemented. */
9768 dwarf2out_start_source_file (filename
)
9769 register const char *filename ATTRIBUTE_UNUSED
;
9773 /* Record the end of a source file, for later output
9774 of the .debug_macinfo section. At present, unimplemented. */
9777 dwarf2out_end_source_file ()
9781 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9782 the tail part of the directive line, i.e. the part which is past the
9783 initial whitespace, #, whitespace, directive-name, whitespace part. */
9786 dwarf2out_define (lineno
, buffer
)
9787 register unsigned lineno ATTRIBUTE_UNUSED
;
9788 register const char *buffer ATTRIBUTE_UNUSED
;
9790 static int initialized
= 0;
9793 dwarf2out_start_source_file (primary_filename
);
9798 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9799 the tail part of the directive line, i.e. the part which is past the
9800 initial whitespace, #, whitespace, directive-name, whitespace part. */
9803 dwarf2out_undef (lineno
, buffer
)
9804 register unsigned lineno ATTRIBUTE_UNUSED
;
9805 register const char *buffer ATTRIBUTE_UNUSED
;
9809 /* Set up for Dwarf output at the start of compilation. */
9812 dwarf2out_init (asm_out_file
, main_input_filename
)
9813 register FILE *asm_out_file
;
9814 register char *main_input_filename
;
9816 /* Remember the name of the primary input file. */
9817 primary_filename
= main_input_filename
;
9819 /* Allocate the initial hunk of the file_table. */
9820 file_table
= (char **) xcalloc (FILE_TABLE_INCREMENT
, sizeof (char *));
9821 file_table_allocated
= FILE_TABLE_INCREMENT
;
9823 /* Skip the first entry - file numbers begin at 1. */
9824 file_table_in_use
= 1;
9826 /* Allocate the initial hunk of the decl_die_table. */
9828 = (dw_die_ref
*) xcalloc (DECL_DIE_TABLE_INCREMENT
, sizeof (dw_die_ref
));
9829 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
9830 decl_die_table_in_use
= 0;
9832 /* Allocate the initial hunk of the decl_scope_table. */
9834 = (tree
*) xcalloc (DECL_SCOPE_TABLE_INCREMENT
, sizeof (tree
));
9835 decl_scope_table_allocated
= DECL_SCOPE_TABLE_INCREMENT
;
9836 decl_scope_depth
= 0;
9838 /* Allocate the initial hunk of the abbrev_die_table. */
9840 = (dw_die_ref
*) xcalloc (ABBREV_DIE_TABLE_INCREMENT
,
9841 sizeof (dw_die_ref
));
9842 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
9843 /* Zero-th entry is allocated, but unused */
9844 abbrev_die_table_in_use
= 1;
9846 /* Allocate the initial hunk of the line_info_table. */
9848 = (dw_line_info_ref
) xcalloc (LINE_INFO_TABLE_INCREMENT
,
9849 sizeof (dw_line_info_entry
));
9850 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
9851 /* Zero-th entry is allocated, but unused */
9852 line_info_table_in_use
= 1;
9854 /* Generate the initial DIE for the .debug section. Note that the (string)
9855 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9856 will (typically) be a relative pathname and that this pathname should be
9857 taken as being relative to the directory from which the compiler was
9858 invoked when the given (base) source file was compiled. */
9859 comp_unit_die
= gen_compile_unit_die (main_input_filename
);
9863 VARRAY_RTX_INIT (used_rtx_varray
, 32, "used_rtx_varray");
9864 ggc_add_rtx_varray_root (&used_rtx_varray
, 1);
9867 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
9868 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
, ABBREV_SECTION_LABEL
, 0);
9869 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
9870 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
9872 strcpy (text_section_label
, stripattributes (TEXT_SECTION
));
9873 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
9874 DEBUG_INFO_SECTION_LABEL
, 0);
9875 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
9876 DEBUG_LINE_SECTION_LABEL
, 0);
9878 ASM_OUTPUT_SECTION (asm_out_file
, ABBREV_SECTION
);
9879 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
9880 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
9882 ASM_OUTPUT_SECTION (asm_out_file
, TEXT_SECTION
);
9883 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
9885 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_INFO_SECTION
);
9886 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
9887 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_LINE_SECTION
);
9888 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
9891 /* Output stuff that dwarf requires at the end of every file,
9892 and generate the DWARF-2 debugging info. */
9897 limbo_die_node
*node
, *next_node
;
9900 /* Traverse the limbo die list, and add parent/child links. The only
9901 dies without parents that should be here are concrete instances of
9902 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9903 For concrete instances, we can get the parent die from the abstract
9905 for (node
= limbo_die_list
; node
; node
= next_node
)
9907 next_node
= node
->next
;
9910 if (die
->die_parent
== NULL
)
9912 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
9914 add_child_die (origin
->die_parent
, die
);
9915 else if (die
== comp_unit_die
)
9922 limbo_die_list
= NULL
;
9924 /* Walk through the list of incomplete types again, trying once more to
9925 emit full debugging info for them. */
9926 retry_incomplete_types ();
9928 /* Traverse the DIE's, reverse their lists of attributes and children,
9929 and add add sibling attributes to those DIE's that have children. */
9930 add_sibling_attributes (comp_unit_die
);
9932 /* Output a terminator label for the .text section. */
9933 fputc ('\n', asm_out_file
);
9934 ASM_OUTPUT_SECTION (asm_out_file
, TEXT_SECTION
);
9935 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, TEXT_END_LABEL
, 0);
9938 /* Output a terminator label for the .data section. */
9939 fputc ('\n', asm_out_file
);
9940 ASM_OUTPUT_SECTION (asm_out_file
, DATA_SECTION
);
9941 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, DATA_END_LABEL
, 0);
9943 /* Output a terminator label for the .bss section. */
9944 fputc ('\n', asm_out_file
);
9945 ASM_OUTPUT_SECTION (asm_out_file
, BSS_SECTION
);
9946 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BSS_END_LABEL
, 0);
9949 /* Output the source line correspondence table. */
9950 if (line_info_table_in_use
> 1 || separate_line_info_table_in_use
)
9952 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
9954 fputc ('\n', asm_out_file
);
9955 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_LINE_SECTION
);
9956 output_line_info ();
9959 /* We can only use the low/high_pc attributes if all of the code
9961 if (separate_line_info_table_in_use
== 0)
9963 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
9964 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
9967 add_AT_lbl_offset (comp_unit_die
, DW_AT_stmt_list
,
9968 debug_line_section_label
);
9971 #if 0 /* unimplemented */
9972 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
&& primary
)
9973 add_AT_unsigned (die
, DW_AT_macro_info
, 0);
9976 /* Output the abbreviation table. */
9977 fputc ('\n', asm_out_file
);
9978 ASM_OUTPUT_SECTION (asm_out_file
, ABBREV_SECTION
);
9979 build_abbrev_table (comp_unit_die
);
9980 output_abbrev_section ();
9982 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9983 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
9984 calc_die_sizes (comp_unit_die
);
9986 /* Output debugging information. */
9987 fputc ('\n', asm_out_file
);
9988 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_INFO_SECTION
);
9989 output_compilation_unit_header ();
9990 output_die (comp_unit_die
);
9992 if (pubname_table_in_use
)
9994 /* Output public names table. */
9995 fputc ('\n', asm_out_file
);
9996 ASM_OUTPUT_SECTION (asm_out_file
, PUBNAMES_SECTION
);
10000 /* We only put functions in the arange table, so don't write it out if
10001 we don't have any. */
10002 if (fde_table_in_use
)
10004 /* Output the address range information. */
10005 fputc ('\n', asm_out_file
);
10006 ASM_OUTPUT_SECTION (asm_out_file
, ARANGES_SECTION
);
10010 #endif /* DWARF2_DEBUGGING_INFO */