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
;
107 const char *dw_cfi_addr
;
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
128 const char *dw_fde_begin
;
129 const char *dw_fde_current_label
;
130 const char *dw_fde_end
;
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 /* The size of the target's pointer type. */
150 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
153 /* The size of addresses as they appear in the Dwarf 2 data.
154 Some architectures use word addresses to refer to code locations,
155 but Dwarf 2 info always uses byte addresses. On such machines,
156 Dwarf 2 addresses need to be larger than the architecture's
158 #ifndef DWARF2_ADDR_SIZE
159 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
162 /* The size in bytes of a DWARF field indicating an offset or length
163 relative to a debug info section, specified to be 4 bytes in the
164 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
167 #ifndef DWARF_OFFSET_SIZE
168 #define DWARF_OFFSET_SIZE 4
171 #define DWARF_VERSION 2
173 /* Round SIZE up to the nearest BOUNDARY. */
174 #define DWARF_ROUND(SIZE,BOUNDARY) \
175 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
177 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
178 #ifdef STACK_GROWS_DOWNWARD
179 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
181 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
184 /* A pointer to the base of a table that contains frame description
185 information for each routine. */
186 static dw_fde_ref fde_table
;
188 /* Number of elements currently allocated for fde_table. */
189 static unsigned fde_table_allocated
;
191 /* Number of elements in fde_table currently in use. */
192 static unsigned fde_table_in_use
;
194 /* Size (in elements) of increments by which we may expand the
196 #define FDE_TABLE_INCREMENT 256
198 /* A list of call frame insns for the CIE. */
199 static dw_cfi_ref cie_cfi_head
;
201 /* The number of the current function definition for which debugging
202 information is being generated. These numbers range from 1 up to the
203 maximum number of function definitions contained within the current
204 compilation unit. These numbers are used to create unique label id's
205 unique to each function definition. */
206 static unsigned current_funcdef_number
= 0;
208 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
209 attribute that accelerates the lookup of the FDE associated
210 with the subprogram. This variable holds the table index of the FDE
211 associated with the current function (body) definition. */
212 static unsigned current_funcdef_fde
;
214 /* Forward declarations for functions defined in this file. */
216 static char *stripattributes
PARAMS ((const char *));
217 static const char *dwarf_cfi_name
PARAMS ((unsigned));
218 static dw_cfi_ref new_cfi
PARAMS ((void));
219 static void add_cfi
PARAMS ((dw_cfi_ref
*, dw_cfi_ref
));
220 static unsigned long size_of_uleb128
PARAMS ((unsigned long));
221 static unsigned long size_of_sleb128
PARAMS ((long));
222 static void output_uleb128
PARAMS ((unsigned long));
223 static void output_sleb128
PARAMS ((long));
224 static void add_fde_cfi
PARAMS ((const char *, dw_cfi_ref
));
225 static void lookup_cfa_1
PARAMS ((dw_cfi_ref
, unsigned long *,
227 static void lookup_cfa
PARAMS ((unsigned long *, long *));
228 static void reg_save
PARAMS ((const char *, unsigned,
230 static void initial_return_save
PARAMS ((rtx
));
231 static void output_cfi
PARAMS ((dw_cfi_ref
, dw_fde_ref
));
232 static void output_call_frame_info
PARAMS ((int));
233 static unsigned int reg_number
PARAMS ((rtx
));
234 static void dwarf2out_stack_adjust
PARAMS ((rtx
));
235 static void dwarf2out_frame_debug_expr
PARAMS ((rtx
, const char *));
237 /* Definitions of defaults for assembler-dependent names of various
238 pseudo-ops and section names.
239 Theses may be overridden in the tm.h file (if necessary) for a particular
242 #ifdef OBJECT_FORMAT_ELF
243 #ifndef UNALIGNED_SHORT_ASM_OP
244 #define UNALIGNED_SHORT_ASM_OP ".2byte"
246 #ifndef UNALIGNED_INT_ASM_OP
247 #define UNALIGNED_INT_ASM_OP ".4byte"
249 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
250 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
252 #endif /* OBJECT_FORMAT_ELF */
255 #define ASM_BYTE_OP ".byte"
258 /* Data and reference forms for relocatable data. */
259 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
260 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
262 /* Pseudo-op for defining a new section. */
263 #ifndef SECTION_ASM_OP
264 #define SECTION_ASM_OP ".section"
267 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
268 print the SECTION_ASM_OP and the section name. The default here works for
269 almost all svr4 assemblers, except for the sparc, where the section name
270 must be enclosed in double quotes. (See sparcv4.h). */
271 #ifndef SECTION_FORMAT
272 #ifdef PUSHSECTION_FORMAT
273 #define SECTION_FORMAT PUSHSECTION_FORMAT
275 #define SECTION_FORMAT "\t%s\t%s\n"
279 #ifndef FRAME_SECTION
280 #define FRAME_SECTION ".debug_frame"
283 #ifndef FUNC_BEGIN_LABEL
284 #define FUNC_BEGIN_LABEL "LFB"
286 #ifndef FUNC_END_LABEL
287 #define FUNC_END_LABEL "LFE"
289 #define CIE_AFTER_SIZE_LABEL "LSCIE"
290 #define CIE_END_LABEL "LECIE"
291 #define CIE_LENGTH_LABEL "LLCIE"
292 #define FDE_AFTER_SIZE_LABEL "LSFDE"
293 #define FDE_END_LABEL "LEFDE"
294 #define FDE_LENGTH_LABEL "LLFDE"
296 /* Definitions of defaults for various types of primitive assembly language
297 output operations. These may be overridden from within the tm.h file,
298 but typically, that is unnecessary. */
300 #ifndef ASM_OUTPUT_SECTION
301 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
302 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
305 #ifndef ASM_OUTPUT_DWARF_DATA1
306 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
307 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
310 #ifndef ASM_OUTPUT_DWARF_DELTA1
311 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
312 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
313 assemble_name (FILE, LABEL1); \
314 fprintf (FILE, "-"); \
315 assemble_name (FILE, LABEL2); \
319 #ifdef UNALIGNED_INT_ASM_OP
321 #ifndef UNALIGNED_OFFSET_ASM_OP
322 #define UNALIGNED_OFFSET_ASM_OP \
323 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
326 #ifndef UNALIGNED_WORD_ASM_OP
327 #define UNALIGNED_WORD_ASM_OP \
328 ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \
329 : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \
330 : UNALIGNED_INT_ASM_OP)
333 #ifndef ASM_OUTPUT_DWARF_DELTA2
334 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
335 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
336 assemble_name (FILE, LABEL1); \
337 fprintf (FILE, "-"); \
338 assemble_name (FILE, LABEL2); \
342 #ifndef ASM_OUTPUT_DWARF_DELTA4
343 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
344 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
345 assemble_name (FILE, LABEL1); \
346 fprintf (FILE, "-"); \
347 assemble_name (FILE, LABEL2); \
351 #ifndef ASM_OUTPUT_DWARF_DELTA
352 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
353 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
354 assemble_name (FILE, LABEL1); \
355 fprintf (FILE, "-"); \
356 assemble_name (FILE, LABEL2); \
360 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
361 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
362 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
363 assemble_name (FILE, LABEL1); \
364 fprintf (FILE, "-"); \
365 assemble_name (FILE, LABEL2); \
369 #ifndef ASM_OUTPUT_DWARF_ADDR
370 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
371 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
372 assemble_name (FILE, LABEL); \
376 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
377 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
379 fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
380 output_addr_const ((FILE), (RTX)); \
384 #ifndef ASM_OUTPUT_DWARF_OFFSET4
385 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
386 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
387 assemble_name (FILE, LABEL); \
391 #ifndef ASM_OUTPUT_DWARF_OFFSET
392 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
393 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
394 assemble_name (FILE, LABEL); \
398 #ifndef ASM_OUTPUT_DWARF_DATA2
399 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
400 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
403 #ifndef ASM_OUTPUT_DWARF_DATA4
404 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
405 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
408 #ifndef ASM_OUTPUT_DWARF_DATA
409 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
410 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
411 (unsigned long) (VALUE))
414 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
415 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
416 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
417 (unsigned long) (VALUE))
420 #ifndef ASM_OUTPUT_DWARF_DATA8
421 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
423 if (WORDS_BIG_ENDIAN) \
425 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
426 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
430 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
431 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
436 #else /* UNALIGNED_INT_ASM_OP */
438 /* We don't have unaligned support, let's hope the normal output works for
441 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
442 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1)
444 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
445 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
447 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
448 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
450 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
451 assemble_integer (gen_rtx_MINUS (HImode, \
452 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
453 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
456 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
457 assemble_integer (gen_rtx_MINUS (SImode, \
458 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
459 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
462 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
463 assemble_integer (gen_rtx_MINUS (Pmode, \
464 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
465 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
468 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
469 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
471 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
472 assemble_integer (GEN_INT (VALUE), 4, 1)
474 #endif /* UNALIGNED_INT_ASM_OP */
477 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
478 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
480 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
481 assemble_name (FILE, SY); \
483 assemble_name (FILE, HI); \
485 assemble_name (FILE, LO); \
488 #endif /* SET_ASM_OP */
490 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
491 newline is produced. When flag_debug_asm is asserted, we add commentary
492 at the end of the line, so we must avoid output of a newline here. */
493 #ifndef ASM_OUTPUT_DWARF_STRING
494 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
496 register int slen = strlen(P); \
497 register const char *p = (P); \
499 fprintf (FILE, "\t.ascii \""); \
500 for (i = 0; i < slen; i++) \
502 register int c = p[i]; \
503 if (c == '\"' || c == '\\') \
509 fprintf (FILE, "\\%o", c); \
512 fprintf (FILE, "\\0\""); \
517 /* The DWARF 2 CFA column which tracks the return address. Normally this
518 is the column for PC, or the first column after all of the hard
520 #ifndef DWARF_FRAME_RETURN_COLUMN
522 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
524 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
528 /* The mapping from gcc register number to DWARF 2 CFA column number. By
529 default, we just provide columns for all registers. */
530 #ifndef DWARF_FRAME_REGNUM
531 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
534 /* Hook used by __throw. */
537 expand_builtin_dwarf_fp_regnum ()
539 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
));
542 /* The offset from the incoming value of %sp to the top of the stack frame
543 for the current function. */
544 #ifndef INCOMING_FRAME_SP_OFFSET
545 #define INCOMING_FRAME_SP_OFFSET 0
548 /* Return a pointer to a copy of the section string name S with all
549 attributes stripped off, and an asterisk prepended (for assemble_name). */
555 char *stripped
= xmalloc (strlen (s
) + 2);
560 while (*s
&& *s
!= ',')
567 /* Return the register number described by a given RTL node. */
573 register unsigned regno
= REGNO (rtl
);
575 if (regno
>= FIRST_PSEUDO_REGISTER
)
577 warning ("internal regno botch: regno = %d\n", regno
);
581 regno
= DBX_REGISTER_NUMBER (regno
);
585 /* Generate code to initialize the register size table. */
588 expand_builtin_init_dwarf_reg_sizes (address
)
592 enum machine_mode mode
= TYPE_MODE (char_type_node
);
593 rtx addr
= expand_expr (address
, NULL_RTX
, VOIDmode
, 0);
594 rtx mem
= gen_rtx_MEM (mode
, addr
);
596 for (i
= 0; i
< DWARF_FRAME_REGISTERS
; ++i
)
598 int offset
= i
* GET_MODE_SIZE (mode
);
599 int size
= GET_MODE_SIZE (reg_raw_mode
[i
]);
601 emit_move_insn (change_address (mem
, mode
,
602 plus_constant (addr
, offset
)),
607 /* Convert a DWARF call frame info. operation to its string name */
610 dwarf_cfi_name (cfi_opc
)
611 register unsigned cfi_opc
;
615 case DW_CFA_advance_loc
:
616 return "DW_CFA_advance_loc";
618 return "DW_CFA_offset";
620 return "DW_CFA_restore";
624 return "DW_CFA_set_loc";
625 case DW_CFA_advance_loc1
:
626 return "DW_CFA_advance_loc1";
627 case DW_CFA_advance_loc2
:
628 return "DW_CFA_advance_loc2";
629 case DW_CFA_advance_loc4
:
630 return "DW_CFA_advance_loc4";
631 case DW_CFA_offset_extended
:
632 return "DW_CFA_offset_extended";
633 case DW_CFA_restore_extended
:
634 return "DW_CFA_restore_extended";
635 case DW_CFA_undefined
:
636 return "DW_CFA_undefined";
637 case DW_CFA_same_value
:
638 return "DW_CFA_same_value";
639 case DW_CFA_register
:
640 return "DW_CFA_register";
641 case DW_CFA_remember_state
:
642 return "DW_CFA_remember_state";
643 case DW_CFA_restore_state
:
644 return "DW_CFA_restore_state";
646 return "DW_CFA_def_cfa";
647 case DW_CFA_def_cfa_register
:
648 return "DW_CFA_def_cfa_register";
649 case DW_CFA_def_cfa_offset
:
650 return "DW_CFA_def_cfa_offset";
652 /* SGI/MIPS specific */
653 case DW_CFA_MIPS_advance_loc8
:
654 return "DW_CFA_MIPS_advance_loc8";
657 case DW_CFA_GNU_window_save
:
658 return "DW_CFA_GNU_window_save";
659 case DW_CFA_GNU_args_size
:
660 return "DW_CFA_GNU_args_size";
661 case DW_CFA_GNU_negative_offset_extended
:
662 return "DW_CFA_GNU_negative_offset_extended";
665 return "DW_CFA_<unknown>";
669 /* Return a pointer to a newly allocated Call Frame Instruction. */
671 static inline dw_cfi_ref
674 register dw_cfi_ref cfi
= (dw_cfi_ref
) xmalloc (sizeof (dw_cfi_node
));
676 cfi
->dw_cfi_next
= NULL
;
677 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
678 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
683 /* Add a Call Frame Instruction to list of instructions. */
686 add_cfi (list_head
, cfi
)
687 register dw_cfi_ref
*list_head
;
688 register dw_cfi_ref cfi
;
690 register dw_cfi_ref
*p
;
692 /* Find the end of the chain. */
693 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
699 /* Generate a new label for the CFI info to refer to. */
702 dwarf2out_cfi_label ()
704 static char label
[20];
705 static unsigned long label_num
= 0;
707 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", label_num
++);
708 ASM_OUTPUT_LABEL (asm_out_file
, label
);
713 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
714 or to the CIE if LABEL is NULL. */
717 add_fde_cfi (label
, cfi
)
718 register const char *label
;
719 register dw_cfi_ref cfi
;
723 register dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
726 label
= dwarf2out_cfi_label ();
728 if (fde
->dw_fde_current_label
== NULL
729 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
731 register dw_cfi_ref xcfi
;
733 fde
->dw_fde_current_label
= label
= xstrdup (label
);
735 /* Set the location counter to the new label. */
737 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
738 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
739 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
742 add_cfi (&fde
->dw_fde_cfi
, cfi
);
746 add_cfi (&cie_cfi_head
, cfi
);
749 /* Subroutine of lookup_cfa. */
752 lookup_cfa_1 (cfi
, regp
, offsetp
)
753 register dw_cfi_ref cfi
;
754 register unsigned long *regp
;
755 register long *offsetp
;
757 switch (cfi
->dw_cfi_opc
)
759 case DW_CFA_def_cfa_offset
:
760 *offsetp
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
762 case DW_CFA_def_cfa_register
:
763 *regp
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
766 *regp
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
767 *offsetp
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
774 /* Find the previous value for the CFA. */
777 lookup_cfa (regp
, offsetp
)
778 register unsigned long *regp
;
779 register long *offsetp
;
781 register dw_cfi_ref cfi
;
783 *regp
= (unsigned long) -1;
786 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
787 lookup_cfa_1 (cfi
, regp
, offsetp
);
789 if (fde_table_in_use
)
791 register dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
792 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
793 lookup_cfa_1 (cfi
, regp
, offsetp
);
797 /* The current rule for calculating the DWARF2 canonical frame address. */
798 static unsigned long cfa_reg
;
799 static long cfa_offset
;
801 /* The register used for saving registers to the stack, and its offset
803 static unsigned cfa_store_reg
;
804 static long cfa_store_offset
;
806 /* The running total of the size of arguments pushed onto the stack. */
807 static long args_size
;
809 /* The last args_size we actually output. */
810 static long old_args_size
;
812 /* Entry point to update the canonical frame address (CFA).
813 LABEL is passed to add_fde_cfi. The value of CFA is now to be
814 calculated from REG+OFFSET. */
817 dwarf2out_def_cfa (label
, reg
, offset
)
818 register const char *label
;
819 register unsigned reg
;
820 register long offset
;
822 register dw_cfi_ref cfi
;
823 unsigned long old_reg
;
828 if (cfa_store_reg
== reg
)
829 cfa_store_offset
= offset
;
831 reg
= DWARF_FRAME_REGNUM (reg
);
832 lookup_cfa (&old_reg
, &old_offset
);
834 if (reg
== old_reg
&& offset
== old_offset
)
841 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
842 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= offset
;
845 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
846 else if (offset
== old_offset
&& old_reg
!= (unsigned long) -1)
848 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
849 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
855 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
856 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
857 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
860 add_fde_cfi (label
, cfi
);
863 /* Add the CFI for saving a register. REG is the CFA column number.
864 LABEL is passed to add_fde_cfi.
865 If SREG is -1, the register is saved at OFFSET from the CFA;
866 otherwise it is saved in SREG. */
869 reg_save (label
, reg
, sreg
, offset
)
870 register const char *label
;
871 register unsigned reg
;
872 register unsigned sreg
;
873 register long offset
;
875 register dw_cfi_ref cfi
= new_cfi ();
877 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
879 /* The following comparison is correct. -1 is used to indicate that
880 the value isn't a register number. */
881 if (sreg
== (unsigned int) -1)
884 /* The register number won't fit in 6 bits, so we have to use
886 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
888 cfi
->dw_cfi_opc
= DW_CFA_offset
;
890 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
893 cfi
->dw_cfi_opc
= DW_CFA_GNU_negative_offset_extended
;
896 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
898 else if (sreg
== reg
)
899 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
903 cfi
->dw_cfi_opc
= DW_CFA_register
;
904 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
907 add_fde_cfi (label
, cfi
);
910 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
911 This CFI tells the unwinder that it needs to restore the window registers
912 from the previous frame's window save area.
914 ??? Perhaps we should note in the CIE where windows are saved (instead of
915 assuming 0(cfa)) and what registers are in the window. */
918 dwarf2out_window_save (label
)
919 register const char *label
;
921 register dw_cfi_ref cfi
= new_cfi ();
922 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
923 add_fde_cfi (label
, cfi
);
926 /* Add a CFI to update the running total of the size of arguments
927 pushed onto the stack. */
930 dwarf2out_args_size (label
, size
)
934 register dw_cfi_ref cfi
;
936 if (size
== old_args_size
)
938 old_args_size
= size
;
941 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
942 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
943 add_fde_cfi (label
, cfi
);
946 /* Entry point for saving a register to the stack. REG is the GCC register
947 number. LABEL and OFFSET are passed to reg_save. */
950 dwarf2out_reg_save (label
, reg
, offset
)
951 register const char *label
;
952 register unsigned reg
;
953 register long offset
;
955 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
958 /* Entry point for saving the return address in the stack.
959 LABEL and OFFSET are passed to reg_save. */
962 dwarf2out_return_save (label
, offset
)
963 register const char *label
;
964 register long offset
;
966 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, -1, offset
);
969 /* Entry point for saving the return address in a register.
970 LABEL and SREG are passed to reg_save. */
973 dwarf2out_return_reg (label
, sreg
)
974 register const char *label
;
975 register unsigned sreg
;
977 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, sreg
, 0);
980 /* Record the initial position of the return address. RTL is
981 INCOMING_RETURN_ADDR_RTX. */
984 initial_return_save (rtl
)
987 unsigned int reg
= (unsigned int) -1;
990 switch (GET_CODE (rtl
))
993 /* RA is in a register. */
994 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
997 /* RA is on the stack. */
999 switch (GET_CODE (rtl
))
1002 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
1007 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
1009 offset
= INTVAL (XEXP (rtl
, 1));
1012 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
1014 offset
= -INTVAL (XEXP (rtl
, 1));
1021 /* The return address is at some offset from any value we can
1022 actually load. For instance, on the SPARC it is in %i7+8. Just
1023 ignore the offset for now; it doesn't matter for unwinding frames. */
1024 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
1026 initial_return_save (XEXP (rtl
, 0));
1032 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa_offset
);
1035 /* Check INSN to see if it looks like a push or a stack adjustment, and
1036 make a note of it if it does. EH uses this information to find out how
1037 much extra space it needs to pop off the stack. */
1040 dwarf2out_stack_adjust (insn
)
1046 if (! asynchronous_exceptions
&& GET_CODE (insn
) == CALL_INSN
)
1048 /* Extract the size of the args from the CALL rtx itself. */
1050 insn
= PATTERN (insn
);
1051 if (GET_CODE (insn
) == PARALLEL
)
1052 insn
= XVECEXP (insn
, 0, 0);
1053 if (GET_CODE (insn
) == SET
)
1054 insn
= SET_SRC (insn
);
1055 assert (GET_CODE (insn
) == CALL
);
1056 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1060 /* If only calls can throw, and we have a frame pointer,
1061 save up adjustments until we see the CALL_INSN. */
1062 else if (! asynchronous_exceptions
1063 && cfa_reg
!= STACK_POINTER_REGNUM
)
1066 if (GET_CODE (insn
) == BARRIER
)
1068 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1069 the compiler will have already emitted a stack adjustment, but
1070 doesn't bother for calls to noreturn functions. */
1071 #ifdef STACK_GROWS_DOWNWARD
1072 offset
= -args_size
;
1077 else if (GET_CODE (PATTERN (insn
)) == SET
)
1082 insn
= PATTERN (insn
);
1083 src
= SET_SRC (insn
);
1084 dest
= SET_DEST (insn
);
1086 if (dest
== stack_pointer_rtx
)
1088 /* (set (reg sp) (plus (reg sp) (const_int))) */
1089 code
= GET_CODE (src
);
1090 if (! (code
== PLUS
|| code
== MINUS
)
1091 || XEXP (src
, 0) != stack_pointer_rtx
1092 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1095 offset
= INTVAL (XEXP (src
, 1));
1097 else if (GET_CODE (dest
) == MEM
)
1099 /* (set (mem (pre_dec (reg sp))) (foo)) */
1100 src
= XEXP (dest
, 0);
1101 code
= GET_CODE (src
);
1103 if (! (code
== PRE_DEC
|| code
== PRE_INC
)
1104 || XEXP (src
, 0) != stack_pointer_rtx
)
1107 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1112 if (code
== PLUS
|| code
== PRE_INC
)
1121 if (cfa_reg
== STACK_POINTER_REGNUM
)
1122 cfa_offset
+= offset
;
1124 #ifndef STACK_GROWS_DOWNWARD
1127 args_size
+= offset
;
1131 label
= dwarf2out_cfi_label ();
1132 dwarf2out_def_cfa (label
, cfa_reg
, cfa_offset
);
1133 dwarf2out_args_size (label
, args_size
);
1136 /* A temporary register used in adjusting SP or setting up the store_reg. */
1137 static unsigned cfa_temp_reg
;
1139 /* A temporary value used in adjusting SP or setting up the store_reg. */
1140 static long cfa_temp_value
;
1142 /* Record call frame debugging information for an expression, which either
1143 sets SP or FP (adjusting how we calculate the frame address) or saves a
1144 register to the stack. */
1147 dwarf2out_frame_debug_expr (expr
, label
)
1154 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1155 the PARALLEL independantly. The first element is always processed if
1156 it is a SET. This is for backward compatability. Other elements
1157 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1158 flag is set in them. */
1160 if (GET_CODE (expr
) == PARALLEL
)
1163 int limit
= XVECLEN (expr
, 0);
1165 for (par_index
= 0; par_index
< limit
; par_index
++)
1167 rtx x
= XVECEXP (expr
, 0, par_index
);
1169 if (GET_CODE (x
) == SET
&&
1170 (RTX_FRAME_RELATED_P (x
) || par_index
== 0))
1171 dwarf2out_frame_debug_expr (x
, label
);
1176 if (GET_CODE (expr
) != SET
)
1179 src
= SET_SRC (expr
);
1180 dest
= SET_DEST (expr
);
1182 switch (GET_CODE (dest
))
1185 /* Update the CFA rule wrt SP or FP. Make sure src is
1186 relative to the current CFA register. */
1187 switch (GET_CODE (src
))
1189 /* Setting FP from SP. */
1191 if (cfa_reg
!= (unsigned) REGNO (src
))
1194 /* We used to require that dest be either SP or FP, but the
1195 ARM copies SP to a temporary register, and from there to
1196 FP. So we just rely on the backends to only set
1197 RTX_FRAME_RELATED_P on appropriate insns. */
1198 cfa_reg
= REGNO (dest
);
1203 if (dest
== stack_pointer_rtx
)
1206 switch (GET_CODE (XEXP (src
, 1)))
1209 offset
= INTVAL (XEXP (src
, 1));
1212 if ((unsigned) REGNO (XEXP (src
, 1)) != cfa_temp_reg
)
1214 offset
= cfa_temp_value
;
1220 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1222 /* Restoring SP from FP in the epilogue. */
1223 if (cfa_reg
!= (unsigned) HARD_FRAME_POINTER_REGNUM
)
1225 cfa_reg
= STACK_POINTER_REGNUM
;
1227 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1230 if (GET_CODE (src
) == PLUS
)
1232 if (cfa_reg
== STACK_POINTER_REGNUM
)
1233 cfa_offset
+= offset
;
1234 if (cfa_store_reg
== STACK_POINTER_REGNUM
)
1235 cfa_store_offset
+= offset
;
1237 else if (dest
== hard_frame_pointer_rtx
)
1239 /* Either setting the FP from an offset of the SP,
1240 or adjusting the FP */
1241 if (! frame_pointer_needed
)
1244 if (GET_CODE (XEXP (src
, 0)) == REG
1245 && (unsigned) REGNO (XEXP (src
, 0)) == cfa_reg
1246 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1248 offset
= INTVAL (XEXP (src
, 1));
1249 if (GET_CODE (src
) == PLUS
)
1251 cfa_offset
+= offset
;
1252 cfa_reg
= HARD_FRAME_POINTER_REGNUM
;
1259 if (GET_CODE (src
) != PLUS
1260 || XEXP (src
, 1) != stack_pointer_rtx
)
1262 if (GET_CODE (XEXP (src
, 0)) != REG
1263 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp_reg
)
1265 if (cfa_reg
!= STACK_POINTER_REGNUM
)
1267 cfa_store_reg
= REGNO (dest
);
1268 cfa_store_offset
= cfa_offset
- cfa_temp_value
;
1273 cfa_temp_reg
= REGNO (dest
);
1274 cfa_temp_value
= INTVAL (src
);
1278 if (GET_CODE (XEXP (src
, 0)) != REG
1279 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp_reg
1280 || (unsigned) REGNO (dest
) != cfa_temp_reg
1281 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1283 cfa_temp_value
|= INTVAL (XEXP (src
, 1));
1289 dwarf2out_def_cfa (label
, cfa_reg
, cfa_offset
);
1292 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1293 will fill in all of the bits. */
1298 cfa_temp_reg
= REGNO (dest
);
1299 cfa_temp_value
= INTVAL (XEXP (src
, 1));
1303 /* Saving a register to the stack. Make sure dest is relative to the
1305 if (GET_CODE (src
) != REG
)
1307 switch (GET_CODE (XEXP (dest
, 0)))
1312 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1313 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1316 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1317 || cfa_store_reg
!= STACK_POINTER_REGNUM
)
1319 cfa_store_offset
+= offset
;
1320 if (cfa_reg
== STACK_POINTER_REGNUM
)
1321 cfa_offset
= cfa_store_offset
;
1323 offset
= -cfa_store_offset
;
1326 /* With an offset. */
1329 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1330 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1333 if (cfa_store_reg
!= (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1335 offset
-= cfa_store_offset
;
1338 /* Without an offset. */
1340 if (cfa_store_reg
!= REGNO (XEXP (dest
, 0)))
1342 offset
= -cfa_store_offset
;
1348 dwarf2out_def_cfa (label
, cfa_reg
, cfa_offset
);
1349 dwarf2out_reg_save (label
, REGNO (src
), offset
);
1358 /* Record call frame debugging information for INSN, which either
1359 sets SP or FP (adjusting how we calculate the frame address) or saves a
1360 register to the stack. If INSN is NULL_RTX, initialize our state. */
1363 dwarf2out_frame_debug (insn
)
1369 if (insn
== NULL_RTX
)
1371 /* Set up state for generating call frame debug info. */
1372 lookup_cfa (&cfa_reg
, &cfa_offset
);
1373 if (cfa_reg
!= (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1375 cfa_reg
= STACK_POINTER_REGNUM
;
1376 cfa_store_reg
= cfa_reg
;
1377 cfa_store_offset
= cfa_offset
;
1383 if (! RTX_FRAME_RELATED_P (insn
))
1385 dwarf2out_stack_adjust (insn
);
1389 label
= dwarf2out_cfi_label ();
1391 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1393 insn
= XEXP (src
, 0);
1395 insn
= PATTERN (insn
);
1397 dwarf2out_frame_debug_expr (insn
, label
);
1400 /* Return the size of an unsigned LEB128 quantity. */
1402 static inline unsigned long
1403 size_of_uleb128 (value
)
1404 register unsigned long value
;
1406 register unsigned long size
= 0;
1407 register unsigned byte
;
1411 byte
= (value
& 0x7f);
1420 /* Return the size of a signed LEB128 quantity. */
1422 static inline unsigned long
1423 size_of_sleb128 (value
)
1424 register long value
;
1426 register unsigned long size
= 0;
1427 register unsigned byte
;
1431 byte
= (value
& 0x7f);
1435 while (!(((value
== 0) && ((byte
& 0x40) == 0))
1436 || ((value
== -1) && ((byte
& 0x40) != 0))));
1441 /* Output an unsigned LEB128 quantity. */
1444 output_uleb128 (value
)
1445 register unsigned long value
;
1447 unsigned long save_value
= value
;
1449 fprintf (asm_out_file
, "\t%s\t", ASM_BYTE_OP
);
1452 register unsigned byte
= (value
& 0x7f);
1455 /* More bytes to follow. */
1458 fprintf (asm_out_file
, "0x%x", byte
);
1460 fprintf (asm_out_file
, ",");
1465 fprintf (asm_out_file
, "\t%s ULEB128 0x%lx", ASM_COMMENT_START
, save_value
);
1468 /* Output an signed LEB128 quantity. */
1471 output_sleb128 (value
)
1472 register long value
;
1475 register unsigned byte
;
1476 long save_value
= value
;
1478 fprintf (asm_out_file
, "\t%s\t", ASM_BYTE_OP
);
1481 byte
= (value
& 0x7f);
1482 /* arithmetic shift */
1484 more
= !((((value
== 0) && ((byte
& 0x40) == 0))
1485 || ((value
== -1) && ((byte
& 0x40) != 0))));
1489 fprintf (asm_out_file
, "0x%x", byte
);
1491 fprintf (asm_out_file
, ",");
1496 fprintf (asm_out_file
, "\t%s SLEB128 %ld", ASM_COMMENT_START
, save_value
);
1499 /* Output a Call Frame Information opcode and its operand(s). */
1502 output_cfi (cfi
, fde
)
1503 register dw_cfi_ref cfi
;
1504 register dw_fde_ref fde
;
1506 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1508 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
1510 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f));
1512 fprintf (asm_out_file
, "\t%s DW_CFA_advance_loc 0x%lx",
1513 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1514 fputc ('\n', asm_out_file
);
1517 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1519 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
1521 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f));
1523 fprintf (asm_out_file
, "\t%s DW_CFA_offset, column 0x%lx",
1524 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1526 fputc ('\n', asm_out_file
);
1527 output_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
1528 fputc ('\n', asm_out_file
);
1530 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1532 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
1534 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f));
1536 fprintf (asm_out_file
, "\t%s DW_CFA_restore, column 0x%lx",
1537 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1539 fputc ('\n', asm_out_file
);
1543 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, cfi
->dw_cfi_opc
);
1545 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
,
1546 dwarf_cfi_name (cfi
->dw_cfi_opc
));
1548 fputc ('\n', asm_out_file
);
1549 switch (cfi
->dw_cfi_opc
)
1551 case DW_CFA_set_loc
:
1552 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
);
1553 fputc ('\n', asm_out_file
);
1555 case DW_CFA_advance_loc1
:
1556 ASM_OUTPUT_DWARF_DELTA1 (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 case DW_CFA_advance_loc2
:
1563 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
,
1564 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1565 fde
->dw_fde_current_label
);
1566 fputc ('\n', asm_out_file
);
1567 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1569 case DW_CFA_advance_loc4
:
1570 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
,
1571 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1572 fde
->dw_fde_current_label
);
1573 fputc ('\n', asm_out_file
);
1574 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1576 #ifdef MIPS_DEBUGGING_INFO
1577 case DW_CFA_MIPS_advance_loc8
:
1578 /* TODO: not currently implemented. */
1582 case DW_CFA_offset_extended
:
1583 case DW_CFA_GNU_negative_offset_extended
:
1584 case DW_CFA_def_cfa
:
1585 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1586 fputc ('\n', asm_out_file
);
1587 output_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
1588 fputc ('\n', asm_out_file
);
1590 case DW_CFA_restore_extended
:
1591 case DW_CFA_undefined
:
1592 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1593 fputc ('\n', asm_out_file
);
1595 case DW_CFA_same_value
:
1596 case DW_CFA_def_cfa_register
:
1597 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1598 fputc ('\n', asm_out_file
);
1600 case DW_CFA_register
:
1601 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1602 fputc ('\n', asm_out_file
);
1603 output_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
);
1604 fputc ('\n', asm_out_file
);
1606 case DW_CFA_def_cfa_offset
:
1607 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1608 fputc ('\n', asm_out_file
);
1610 case DW_CFA_GNU_window_save
:
1612 case DW_CFA_GNU_args_size
:
1613 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1614 fputc ('\n', asm_out_file
);
1622 /* Output the call frame information used to used to record information
1623 that relates to calculating the frame pointer, and records the
1624 location of saved registers. */
1627 output_call_frame_info (for_eh
)
1630 register unsigned long i
;
1631 register dw_fde_ref fde
;
1632 register dw_cfi_ref cfi
;
1633 char l1
[20], l2
[20];
1634 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1638 /* Do we want to include a pointer to the exception table? */
1639 int eh_ptr
= for_eh
&& exception_table_p ();
1641 /* If we don't have any functions we'll want to unwind out of, don't
1642 emit any EH unwind information. */
1645 for (i
= 0; i
< fde_table_in_use
; ++i
)
1646 if (! fde_table
[i
].nothrow
)
1652 fputc ('\n', asm_out_file
);
1654 /* We're going to be generating comments, so turn on app. */
1660 #ifdef EH_FRAME_SECTION
1661 EH_FRAME_SECTION ();
1663 tree label
= get_file_function_name ('F');
1665 force_data_section ();
1666 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DWARF2_ADDR_SIZE
));
1667 ASM_GLOBALIZE_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
1668 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
1670 assemble_label ("__FRAME_BEGIN__");
1673 ASM_OUTPUT_SECTION (asm_out_file
, FRAME_SECTION
);
1675 /* Output the CIE. */
1676 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
1677 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
1678 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1679 ASM_GENERATE_INTERNAL_LABEL (ld
, CIE_LENGTH_LABEL
, for_eh
);
1681 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file
, ld
);
1683 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, ld
);
1686 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
, l2
, l1
);
1688 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, l2
, l1
);
1691 fprintf (asm_out_file
, "\t%s Length of Common Information Entry",
1694 fputc ('\n', asm_out_file
);
1695 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1698 /* Now that the CIE pointer is PC-relative for EH,
1699 use 0 to identify the CIE. */
1700 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 0);
1702 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, DW_CIE_ID
);
1705 fprintf (asm_out_file
, "\t%s CIE Identifier Tag", ASM_COMMENT_START
);
1707 fputc ('\n', asm_out_file
);
1708 if (! for_eh
&& DWARF_OFFSET_SIZE
== 8)
1710 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, DW_CIE_ID
);
1711 fputc ('\n', asm_out_file
);
1714 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_CIE_VERSION
);
1716 fprintf (asm_out_file
, "\t%s CIE Version", ASM_COMMENT_START
);
1718 fputc ('\n', asm_out_file
);
1721 /* The CIE contains a pointer to the exception region info for the
1722 frame. Make the augmentation string three bytes (including the
1723 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1724 can't handle unaligned relocs. */
1727 ASM_OUTPUT_DWARF_STRING (asm_out_file
, "eh");
1728 fprintf (asm_out_file
, "\t%s CIE Augmentation", ASM_COMMENT_START
);
1732 ASM_OUTPUT_ASCII (asm_out_file
, "eh", 3);
1734 fputc ('\n', asm_out_file
);
1736 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, "__EXCEPTION_TABLE__");
1738 fprintf (asm_out_file
, "\t%s pointer to exception region info",
1743 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
1745 fprintf (asm_out_file
, "\t%s CIE Augmentation (none)",
1749 fputc ('\n', asm_out_file
);
1752 fprintf (asm_out_file
, " (CIE Code Alignment Factor)");
1754 fputc ('\n', asm_out_file
);
1755 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT
);
1757 fprintf (asm_out_file
, " (CIE Data Alignment Factor)");
1759 fputc ('\n', asm_out_file
);
1760 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_FRAME_RETURN_COLUMN
);
1762 fprintf (asm_out_file
, "\t%s CIE RA Column", ASM_COMMENT_START
);
1764 fputc ('\n', asm_out_file
);
1766 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
1767 output_cfi (cfi
, NULL
);
1769 /* Pad the CIE out to an address sized boundary. */
1770 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DWARF2_ADDR_SIZE
));
1771 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
1772 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1773 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file
, ld
, l2
, l1
);
1775 fprintf (asm_out_file
, "\t%s CIE Length Symbol", ASM_COMMENT_START
);
1776 fputc ('\n', asm_out_file
);
1779 /* Loop through all of the FDE's. */
1780 for (i
= 0; i
< fde_table_in_use
; ++i
)
1782 fde
= &fde_table
[i
];
1784 /* Don't emit EH unwind info for leaf functions. */
1785 if (for_eh
&& fde
->nothrow
)
1788 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
*2);
1789 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
*2);
1790 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1791 ASM_GENERATE_INTERNAL_LABEL (ld
, FDE_LENGTH_LABEL
, for_eh
+ i
*2);
1793 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file
, ld
);
1795 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, ld
);
1798 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
, l2
, l1
);
1800 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, l2
, l1
);
1803 fprintf (asm_out_file
, "\t%s FDE Length", ASM_COMMENT_START
);
1804 fputc ('\n', asm_out_file
);
1805 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1807 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1808 emits a target dependent sized offset when for_eh is not true.
1809 This inconsistency may confuse gdb. The only case where we need a
1810 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1811 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1812 though in order to be compatible with the dwarf_fde struct in frame.c.
1813 If the for_eh case is changed, then the struct in frame.c has
1814 to be adjusted appropriately. */
1816 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
, l1
, "__FRAME_BEGIN__");
1818 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, stripattributes (FRAME_SECTION
));
1820 fprintf (asm_out_file
, "\t%s FDE CIE offset", ASM_COMMENT_START
);
1822 fputc ('\n', asm_out_file
);
1823 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, fde
->dw_fde_begin
);
1825 fprintf (asm_out_file
, "\t%s FDE initial location", ASM_COMMENT_START
);
1827 fputc ('\n', asm_out_file
);
1828 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
,
1829 fde
->dw_fde_end
, fde
->dw_fde_begin
);
1831 fprintf (asm_out_file
, "\t%s FDE address range", ASM_COMMENT_START
);
1833 fputc ('\n', asm_out_file
);
1835 /* Loop through the Call Frame Instructions associated with
1837 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
1838 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
1839 output_cfi (cfi
, fde
);
1841 /* Pad the FDE out to an address sized boundary. */
1842 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DWARF2_ADDR_SIZE
));
1843 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
1844 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1845 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file
, ld
, l2
, l1
);
1847 fprintf (asm_out_file
, "\t%s FDE Length Symbol", ASM_COMMENT_START
);
1848 fputc ('\n', asm_out_file
);
1851 #ifndef EH_FRAME_SECTION
1854 /* Emit terminating zero for table. */
1855 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 0);
1856 fputc ('\n', asm_out_file
);
1859 #ifdef MIPS_DEBUGGING_INFO
1860 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1861 get a value of 0. Putting .align 0 after the label fixes it. */
1862 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
1865 /* Turn off app to make assembly quicker. */
1870 /* Output a marker (i.e. a label) for the beginning of a function, before
1874 dwarf2out_begin_prologue ()
1876 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1877 register dw_fde_ref fde
;
1879 ++current_funcdef_number
;
1881 function_section (current_function_decl
);
1882 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1883 current_funcdef_number
);
1884 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1885 current_function_func_begin_label
= get_identifier (label
);
1887 /* Expand the fde table if necessary. */
1888 if (fde_table_in_use
== fde_table_allocated
)
1890 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
1892 = (dw_fde_ref
) xrealloc (fde_table
,
1893 fde_table_allocated
* sizeof (dw_fde_node
));
1896 /* Record the FDE associated with this function. */
1897 current_funcdef_fde
= fde_table_in_use
;
1899 /* Add the new FDE at the end of the fde_table. */
1900 fde
= &fde_table
[fde_table_in_use
++];
1901 fde
->dw_fde_begin
= xstrdup (label
);
1902 fde
->dw_fde_current_label
= NULL
;
1903 fde
->dw_fde_end
= NULL
;
1904 fde
->dw_fde_cfi
= NULL
;
1905 fde
->nothrow
= current_function_nothrow
;
1907 args_size
= old_args_size
= 0;
1910 /* Output a marker (i.e. a label) for the absolute end of the generated code
1911 for a function definition. This gets called *after* the epilogue code has
1915 dwarf2out_end_epilogue ()
1918 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1920 /* Output a label to mark the endpoint of the code generated for this
1922 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
, current_funcdef_number
);
1923 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1924 fde
= &fde_table
[fde_table_in_use
- 1];
1925 fde
->dw_fde_end
= xstrdup (label
);
1929 dwarf2out_frame_init ()
1931 /* Allocate the initial hunk of the fde_table. */
1932 fde_table
= (dw_fde_ref
) xcalloc (FDE_TABLE_INCREMENT
, sizeof (dw_fde_node
));
1933 fde_table_allocated
= FDE_TABLE_INCREMENT
;
1934 fde_table_in_use
= 0;
1936 /* Generate the CFA instructions common to all FDE's. Do it now for the
1937 sake of lookup_cfa. */
1939 #ifdef DWARF2_UNWIND_INFO
1940 /* On entry, the Canonical Frame Address is at SP. */
1941 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
1942 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
1947 dwarf2out_frame_finish ()
1949 /* Output call frame information. */
1950 #ifdef MIPS_DEBUGGING_INFO
1951 if (write_symbols
== DWARF2_DEBUG
)
1952 output_call_frame_info (0);
1953 if (flag_unwind_tables
|| (flag_exceptions
&& ! exceptions_via_longjmp
))
1954 output_call_frame_info (1);
1956 if (write_symbols
== DWARF2_DEBUG
1957 || flag_unwind_tables
|| (flag_exceptions
&& ! exceptions_via_longjmp
))
1958 output_call_frame_info (1);
1962 #endif /* .debug_frame support */
1964 /* And now, the support for symbolic debugging information. */
1965 #ifdef DWARF2_DEBUGGING_INFO
1967 /* NOTE: In the comments in this file, many references are made to
1968 "Debugging Information Entries". This term is abbreviated as `DIE'
1969 throughout the remainder of this file. */
1971 /* An internal representation of the DWARF output is built, and then
1972 walked to generate the DWARF debugging info. The walk of the internal
1973 representation is done after the entire program has been compiled.
1974 The types below are used to describe the internal representation. */
1976 /* Each DIE may have a series of attribute/value pairs. Values
1977 can take on several forms. The forms that are used in this
1978 implementation are listed below. */
1985 dw_val_class_unsigned_const
,
1986 dw_val_class_long_long
,
1989 dw_val_class_die_ref
,
1990 dw_val_class_fde_ref
,
1991 dw_val_class_lbl_id
,
1992 dw_val_class_lbl_offset
,
1997 /* Various DIE's use offsets relative to the beginning of the
1998 .debug_info section to refer to each other. */
2000 typedef long int dw_offset
;
2002 /* Define typedefs here to avoid circular dependencies. */
2004 typedef struct die_struct
*dw_die_ref
;
2005 typedef struct dw_attr_struct
*dw_attr_ref
;
2006 typedef struct dw_val_struct
*dw_val_ref
;
2007 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2008 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
2009 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2010 typedef struct pubname_struct
*pubname_ref
;
2011 typedef dw_die_ref
*arange_ref
;
2013 /* Describe a double word constant value. */
2015 typedef struct dw_long_long_struct
2022 /* Describe a floating point constant value. */
2024 typedef struct dw_fp_struct
2031 /* Each entry in the line_info_table maintains the file and
2032 line number associated with the label generated for that
2033 entry. The label gives the PC value associated with
2034 the line number entry. */
2036 typedef struct dw_line_info_struct
2038 unsigned long dw_file_num
;
2039 unsigned long dw_line_num
;
2043 /* Line information for functions in separate sections; each one gets its
2045 typedef struct dw_separate_line_info_struct
2047 unsigned long dw_file_num
;
2048 unsigned long dw_line_num
;
2049 unsigned long function
;
2051 dw_separate_line_info_entry
;
2053 /* The dw_val_node describes an attribute's value, as it is
2054 represented internally. */
2056 typedef struct dw_val_struct
2058 dw_val_class val_class
;
2062 dw_loc_descr_ref val_loc
;
2064 long unsigned val_unsigned
;
2065 dw_long_long_const val_long_long
;
2066 dw_float_const val_float
;
2067 dw_die_ref val_die_ref
;
2068 unsigned val_fde_index
;
2071 unsigned char val_flag
;
2077 /* Locations in memory are described using a sequence of stack machine
2080 typedef struct dw_loc_descr_struct
2082 dw_loc_descr_ref dw_loc_next
;
2083 enum dwarf_location_atom dw_loc_opc
;
2084 dw_val_node dw_loc_oprnd1
;
2085 dw_val_node dw_loc_oprnd2
;
2089 /* Each DIE attribute has a field specifying the attribute kind,
2090 a link to the next attribute in the chain, and an attribute value.
2091 Attributes are typically linked below the DIE they modify. */
2093 typedef struct dw_attr_struct
2095 enum dwarf_attribute dw_attr
;
2096 dw_attr_ref dw_attr_next
;
2097 dw_val_node dw_attr_val
;
2101 /* The Debugging Information Entry (DIE) structure */
2103 typedef struct die_struct
2105 enum dwarf_tag die_tag
;
2106 dw_attr_ref die_attr
;
2107 dw_die_ref die_parent
;
2108 dw_die_ref die_child
;
2110 dw_offset die_offset
;
2111 unsigned long die_abbrev
;
2115 /* The pubname structure */
2117 typedef struct pubname_struct
2124 /* The limbo die list structure. */
2125 typedef struct limbo_die_struct
2128 struct limbo_die_struct
*next
;
2132 /* How to start an assembler comment. */
2133 #ifndef ASM_COMMENT_START
2134 #define ASM_COMMENT_START ";#"
2137 /* Define a macro which returns non-zero for a TYPE_DECL which was
2138 implicitly generated for a tagged type.
2140 Note that unlike the gcc front end (which generates a NULL named
2141 TYPE_DECL node for each complete tagged type, each array type, and
2142 each function type node created) the g++ front end generates a
2143 _named_ TYPE_DECL node for each tagged type node created.
2144 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2145 generate a DW_TAG_typedef DIE for them. */
2147 #define TYPE_DECL_IS_STUB(decl) \
2148 (DECL_NAME (decl) == NULL_TREE \
2149 || (DECL_ARTIFICIAL (decl) \
2150 && is_tagged_type (TREE_TYPE (decl)) \
2151 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2152 /* This is necessary for stub decls that \
2153 appear in nested inline functions. */ \
2154 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2155 && (decl_ultimate_origin (decl) \
2156 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2158 /* Information concerning the compilation unit's programming
2159 language, and compiler version. */
2161 extern int flag_traditional
;
2163 /* Fixed size portion of the DWARF compilation unit header. */
2164 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2166 /* Fixed size portion of debugging line information prolog. */
2167 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2169 /* Fixed size portion of public names info. */
2170 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2172 /* Fixed size portion of the address range info. */
2173 #define DWARF_ARANGES_HEADER_SIZE \
2174 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
2175 - DWARF_OFFSET_SIZE)
2177 /* Size of padding portion in the address range info. It must be
2178 aligned to twice the pointer size. */
2179 #define DWARF_ARANGES_PAD_SIZE \
2180 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
2181 - (2 * DWARF_OFFSET_SIZE + 4))
2183 /* The default is to have gcc emit the line number tables. */
2184 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2185 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2188 /* Define the architecture-dependent minimum instruction length (in bytes).
2189 In this implementation of DWARF, this field is used for information
2190 purposes only. Since GCC generates assembly language, we have
2191 no a priori knowledge of how many instruction bytes are generated
2192 for each source line, and therefore can use only the DW_LNE_set_address
2193 and DW_LNS_fixed_advance_pc line information commands. */
2195 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2196 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2199 /* Minimum line offset in a special line info. opcode.
2200 This value was chosen to give a reasonable range of values. */
2201 #define DWARF_LINE_BASE -10
2203 /* First special line opcde - leave room for the standard opcodes. */
2204 #define DWARF_LINE_OPCODE_BASE 10
2206 /* Range of line offsets in a special line info. opcode. */
2207 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2209 /* Flag that indicates the initial value of the is_stmt_start flag.
2210 In the present implementation, we do not mark any lines as
2211 the beginning of a source statement, because that information
2212 is not made available by the GCC front-end. */
2213 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2215 /* This location is used by calc_die_sizes() to keep track
2216 the offset of each DIE within the .debug_info section. */
2217 static unsigned long next_die_offset
;
2219 /* Record the root of the DIE's built for the current compilation unit. */
2220 static dw_die_ref comp_unit_die
;
2222 /* A list of DIEs with a NULL parent waiting to be relocated. */
2223 static limbo_die_node
*limbo_die_list
= 0;
2225 /* Pointer to an array of filenames referenced by this compilation unit. */
2226 static char **file_table
;
2228 /* Total number of entries in the table (i.e. array) pointed to by
2229 `file_table'. This is the *total* and includes both used and unused
2231 static unsigned file_table_allocated
;
2233 /* Number of entries in the file_table which are actually in use. */
2234 static unsigned file_table_in_use
;
2236 /* Size (in elements) of increments by which we may expand the filename
2238 #define FILE_TABLE_INCREMENT 64
2240 /* Local pointer to the name of the main input file. Initialized in
2242 static const char *primary_filename
;
2244 /* A pointer to the base of a table of references to DIE's that describe
2245 declarations. The table is indexed by DECL_UID() which is a unique
2246 number identifying each decl. */
2247 static dw_die_ref
*decl_die_table
;
2249 /* Number of elements currently allocated for the decl_die_table. */
2250 static unsigned decl_die_table_allocated
;
2252 /* Number of elements in decl_die_table currently in use. */
2253 static unsigned decl_die_table_in_use
;
2255 /* Size (in elements) of increments by which we may expand the
2257 #define DECL_DIE_TABLE_INCREMENT 256
2259 /* A pointer to the base of a table of references to declaration
2260 scopes. This table is a display which tracks the nesting
2261 of declaration scopes at the current scope and containing
2262 scopes. This table is used to find the proper place to
2263 define type declaration DIE's. */
2264 static tree
*decl_scope_table
;
2266 /* Number of elements currently allocated for the decl_scope_table. */
2267 static int decl_scope_table_allocated
;
2269 /* Current level of nesting of declaration scopes. */
2270 static int decl_scope_depth
;
2272 /* Size (in elements) of increments by which we may expand the
2273 decl_scope_table. */
2274 #define DECL_SCOPE_TABLE_INCREMENT 64
2276 /* A pointer to the base of a list of references to DIE's that
2277 are uniquely identified by their tag, presence/absence of
2278 children DIE's, and list of attribute/value pairs. */
2279 static dw_die_ref
*abbrev_die_table
;
2281 /* Number of elements currently allocated for abbrev_die_table. */
2282 static unsigned abbrev_die_table_allocated
;
2284 /* Number of elements in type_die_table currently in use. */
2285 static unsigned abbrev_die_table_in_use
;
2287 /* Size (in elements) of increments by which we may expand the
2288 abbrev_die_table. */
2289 #define ABBREV_DIE_TABLE_INCREMENT 256
2291 /* A pointer to the base of a table that contains line information
2292 for each source code line in .text in the compilation unit. */
2293 static dw_line_info_ref line_info_table
;
2295 /* Number of elements currently allocated for line_info_table. */
2296 static unsigned line_info_table_allocated
;
2298 /* Number of elements in separate_line_info_table currently in use. */
2299 static unsigned separate_line_info_table_in_use
;
2301 /* A pointer to the base of a table that contains line information
2302 for each source code line outside of .text in the compilation unit. */
2303 static dw_separate_line_info_ref separate_line_info_table
;
2305 /* Number of elements currently allocated for separate_line_info_table. */
2306 static unsigned separate_line_info_table_allocated
;
2308 /* Number of elements in line_info_table currently in use. */
2309 static unsigned line_info_table_in_use
;
2311 /* Size (in elements) of increments by which we may expand the
2313 #define LINE_INFO_TABLE_INCREMENT 1024
2315 /* A pointer to the base of a table that contains a list of publicly
2316 accessible names. */
2317 static pubname_ref pubname_table
;
2319 /* Number of elements currently allocated for pubname_table. */
2320 static unsigned pubname_table_allocated
;
2322 /* Number of elements in pubname_table currently in use. */
2323 static unsigned pubname_table_in_use
;
2325 /* Size (in elements) of increments by which we may expand the
2327 #define PUBNAME_TABLE_INCREMENT 64
2329 /* A pointer to the base of a table that contains a list of publicly
2330 accessible names. */
2331 static arange_ref arange_table
;
2333 /* Number of elements currently allocated for arange_table. */
2334 static unsigned arange_table_allocated
;
2336 /* Number of elements in arange_table currently in use. */
2337 static unsigned arange_table_in_use
;
2339 /* Size (in elements) of increments by which we may expand the
2341 #define ARANGE_TABLE_INCREMENT 64
2343 /* A pointer to the base of a list of incomplete types which might be
2344 completed at some later time. */
2346 static tree
*incomplete_types_list
;
2348 /* Number of elements currently allocated for the incomplete_types_list. */
2349 static unsigned incomplete_types_allocated
;
2351 /* Number of elements of incomplete_types_list currently in use. */
2352 static unsigned incomplete_types
;
2354 /* Size (in elements) of increments by which we may expand the incomplete
2355 types list. Actually, a single hunk of space of this size should
2356 be enough for most typical programs. */
2357 #define INCOMPLETE_TYPES_INCREMENT 64
2359 /* Record whether the function being analyzed contains inlined functions. */
2360 static int current_function_has_inlines
;
2361 #if 0 && defined (MIPS_DEBUGGING_INFO)
2362 static int comp_unit_has_inlines
;
2365 /* Array of RTXes referenced by the debugging information, which therefore
2366 must be kept around forever. We do this rather than perform GC on
2367 the dwarf info because almost all of the dwarf info lives forever, and
2368 it's easier to support non-GC frontends this way. */
2369 static varray_type used_rtx_varray
;
2371 /* Forward declarations for functions defined in this file. */
2373 static int is_pseudo_reg
PARAMS ((rtx
));
2374 static tree type_main_variant
PARAMS ((tree
));
2375 static int is_tagged_type
PARAMS ((tree
));
2376 static const char *dwarf_tag_name
PARAMS ((unsigned));
2377 static const char *dwarf_attr_name
PARAMS ((unsigned));
2378 static const char *dwarf_form_name
PARAMS ((unsigned));
2379 static const char *dwarf_stack_op_name
PARAMS ((unsigned));
2381 static const char *dwarf_type_encoding_name
PARAMS ((unsigned));
2383 static tree decl_ultimate_origin
PARAMS ((tree
));
2384 static tree block_ultimate_origin
PARAMS ((tree
));
2385 static tree decl_class_context
PARAMS ((tree
));
2386 static void add_dwarf_attr
PARAMS ((dw_die_ref
, dw_attr_ref
));
2387 static void add_AT_flag
PARAMS ((dw_die_ref
,
2388 enum dwarf_attribute
,
2390 static void add_AT_int
PARAMS ((dw_die_ref
,
2391 enum dwarf_attribute
, long));
2392 static void add_AT_unsigned
PARAMS ((dw_die_ref
,
2393 enum dwarf_attribute
,
2395 static void add_AT_long_long
PARAMS ((dw_die_ref
,
2396 enum dwarf_attribute
,
2399 static void add_AT_float
PARAMS ((dw_die_ref
,
2400 enum dwarf_attribute
,
2402 static void add_AT_string
PARAMS ((dw_die_ref
,
2403 enum dwarf_attribute
,
2405 static void add_AT_die_ref
PARAMS ((dw_die_ref
,
2406 enum dwarf_attribute
,
2408 static void add_AT_fde_ref
PARAMS ((dw_die_ref
,
2409 enum dwarf_attribute
,
2411 static void add_AT_loc
PARAMS ((dw_die_ref
,
2412 enum dwarf_attribute
,
2414 static void add_AT_addr
PARAMS ((dw_die_ref
,
2415 enum dwarf_attribute
,
2417 static void add_AT_lbl_id
PARAMS ((dw_die_ref
,
2418 enum dwarf_attribute
,
2420 static void add_AT_lbl_offset
PARAMS ((dw_die_ref
,
2421 enum dwarf_attribute
,
2423 static dw_attr_ref get_AT
PARAMS ((dw_die_ref
,
2424 enum dwarf_attribute
));
2425 static const char *get_AT_low_pc
PARAMS ((dw_die_ref
));
2426 static const char *get_AT_hi_pc
PARAMS ((dw_die_ref
));
2427 static const char *get_AT_string
PARAMS ((dw_die_ref
,
2428 enum dwarf_attribute
));
2429 static int get_AT_flag
PARAMS ((dw_die_ref
,
2430 enum dwarf_attribute
));
2431 static unsigned get_AT_unsigned
PARAMS ((dw_die_ref
,
2432 enum dwarf_attribute
));
2433 static inline dw_die_ref get_AT_ref
PARAMS ((dw_die_ref
,
2434 enum dwarf_attribute
));
2435 static int is_c_family
PARAMS ((void));
2436 static int is_fortran
PARAMS ((void));
2437 static void remove_AT
PARAMS ((dw_die_ref
,
2438 enum dwarf_attribute
));
2439 static void remove_children
PARAMS ((dw_die_ref
));
2440 static void add_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
2441 static dw_die_ref new_die
PARAMS ((enum dwarf_tag
, dw_die_ref
));
2442 static dw_die_ref lookup_type_die
PARAMS ((tree
));
2443 static void equate_type_number_to_die
PARAMS ((tree
, dw_die_ref
));
2444 static dw_die_ref lookup_decl_die
PARAMS ((tree
));
2445 static void equate_decl_number_to_die
PARAMS ((tree
, dw_die_ref
));
2446 static dw_loc_descr_ref new_loc_descr
PARAMS ((enum dwarf_location_atom
,
2449 static void add_loc_descr
PARAMS ((dw_loc_descr_ref
*,
2451 static void print_spaces
PARAMS ((FILE *));
2452 static void print_die
PARAMS ((dw_die_ref
, FILE *));
2453 static void print_dwarf_line_table
PARAMS ((FILE *));
2454 static void add_sibling_attributes
PARAMS ((dw_die_ref
));
2455 static void build_abbrev_table
PARAMS ((dw_die_ref
));
2456 static unsigned long size_of_string
PARAMS ((const char *));
2457 static unsigned long size_of_loc_descr
PARAMS ((dw_loc_descr_ref
));
2458 static unsigned long size_of_locs
PARAMS ((dw_loc_descr_ref
));
2459 static int constant_size
PARAMS ((long unsigned));
2460 static unsigned long size_of_die
PARAMS ((dw_die_ref
));
2461 static void calc_die_sizes
PARAMS ((dw_die_ref
));
2462 static unsigned long size_of_line_prolog
PARAMS ((void));
2463 static unsigned long size_of_pubnames
PARAMS ((void));
2464 static unsigned long size_of_aranges
PARAMS ((void));
2465 static enum dwarf_form value_format
PARAMS ((dw_attr_ref
));
2466 static void output_value_format
PARAMS ((dw_attr_ref
));
2467 static void output_abbrev_section
PARAMS ((void));
2468 static void output_loc_operands
PARAMS ((dw_loc_descr_ref
));
2469 static void output_die
PARAMS ((dw_die_ref
));
2470 static void output_compilation_unit_header
PARAMS ((void));
2471 static const char *dwarf2_name
PARAMS ((tree
, int));
2472 static void add_pubname
PARAMS ((tree
, dw_die_ref
));
2473 static void output_pubnames
PARAMS ((void));
2474 static void add_arange
PARAMS ((tree
, dw_die_ref
));
2475 static void output_aranges
PARAMS ((void));
2476 static void output_line_info
PARAMS ((void));
2477 static dw_die_ref base_type_die
PARAMS ((tree
));
2478 static tree root_type
PARAMS ((tree
));
2479 static int is_base_type
PARAMS ((tree
));
2480 static dw_die_ref modified_type_die
PARAMS ((tree
, int, int, dw_die_ref
));
2481 static int type_is_enum
PARAMS ((tree
));
2482 static dw_loc_descr_ref reg_loc_descriptor
PARAMS ((rtx
));
2483 static dw_loc_descr_ref based_loc_descr
PARAMS ((unsigned, long));
2484 static int is_based_loc
PARAMS ((rtx
));
2485 static dw_loc_descr_ref mem_loc_descriptor
PARAMS ((rtx
, enum machine_mode mode
));
2486 static dw_loc_descr_ref concat_loc_descriptor
PARAMS ((rtx
, rtx
));
2487 static dw_loc_descr_ref loc_descriptor
PARAMS ((rtx
));
2488 static HOST_WIDE_INT ceiling
PARAMS ((HOST_WIDE_INT
, unsigned int));
2489 static tree field_type
PARAMS ((tree
));
2490 static unsigned int simple_type_align_in_bits
PARAMS ((tree
));
2491 static unsigned HOST_WIDE_INT simple_type_size_in_bits
PARAMS ((tree
));
2492 static HOST_WIDE_INT field_byte_offset
PARAMS ((tree
));
2493 static void add_AT_location_description
PARAMS ((dw_die_ref
,
2494 enum dwarf_attribute
, rtx
));
2495 static void add_data_member_location_attribute
PARAMS ((dw_die_ref
, tree
));
2496 static void add_const_value_attribute
PARAMS ((dw_die_ref
, rtx
));
2497 static void add_location_or_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
2498 static void add_name_attribute
PARAMS ((dw_die_ref
, const char *));
2499 static void add_bound_info
PARAMS ((dw_die_ref
,
2500 enum dwarf_attribute
, tree
));
2501 static void add_subscript_info
PARAMS ((dw_die_ref
, tree
));
2502 static void add_byte_size_attribute
PARAMS ((dw_die_ref
, tree
));
2503 static void add_bit_offset_attribute
PARAMS ((dw_die_ref
, tree
));
2504 static void add_bit_size_attribute
PARAMS ((dw_die_ref
, tree
));
2505 static void add_prototyped_attribute
PARAMS ((dw_die_ref
, tree
));
2506 static void add_abstract_origin_attribute
PARAMS ((dw_die_ref
, tree
));
2507 static void add_pure_or_virtual_attribute
PARAMS ((dw_die_ref
, tree
));
2508 static void add_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
2509 static void add_name_and_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
2510 static void push_decl_scope
PARAMS ((tree
));
2511 static dw_die_ref scope_die_for
PARAMS ((tree
, dw_die_ref
));
2512 static void pop_decl_scope
PARAMS ((void));
2513 static void add_type_attribute
PARAMS ((dw_die_ref
, tree
, int, int,
2515 static const char *type_tag
PARAMS ((tree
));
2516 static tree member_declared_type
PARAMS ((tree
));
2518 static const char *decl_start_label
PARAMS ((tree
));
2520 static void gen_array_type_die
PARAMS ((tree
, dw_die_ref
));
2521 static void gen_set_type_die
PARAMS ((tree
, dw_die_ref
));
2523 static void gen_entry_point_die
PARAMS ((tree
, dw_die_ref
));
2525 static void gen_inlined_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
2526 static void gen_inlined_structure_type_die
PARAMS ((tree
, dw_die_ref
));
2527 static void gen_inlined_union_type_die
PARAMS ((tree
, dw_die_ref
));
2528 static void gen_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
2529 static dw_die_ref gen_formal_parameter_die
PARAMS ((tree
, dw_die_ref
));
2530 static void gen_unspecified_parameters_die
PARAMS ((tree
, dw_die_ref
));
2531 static void gen_formal_types_die
PARAMS ((tree
, dw_die_ref
));
2532 static void gen_subprogram_die
PARAMS ((tree
, dw_die_ref
));
2533 static void gen_variable_die
PARAMS ((tree
, dw_die_ref
));
2534 static void gen_label_die
PARAMS ((tree
, dw_die_ref
));
2535 static void gen_lexical_block_die
PARAMS ((tree
, dw_die_ref
, int));
2536 static void gen_inlined_subroutine_die
PARAMS ((tree
, dw_die_ref
, int));
2537 static void gen_field_die
PARAMS ((tree
, dw_die_ref
));
2538 static void gen_ptr_to_mbr_type_die
PARAMS ((tree
, dw_die_ref
));
2539 static dw_die_ref gen_compile_unit_die
PARAMS ((const char *));
2540 static void gen_string_type_die
PARAMS ((tree
, dw_die_ref
));
2541 static void gen_inheritance_die
PARAMS ((tree
, dw_die_ref
));
2542 static void gen_member_die
PARAMS ((tree
, dw_die_ref
));
2543 static void gen_struct_or_union_type_die
PARAMS ((tree
, dw_die_ref
));
2544 static void gen_subroutine_type_die
PARAMS ((tree
, dw_die_ref
));
2545 static void gen_typedef_die
PARAMS ((tree
, dw_die_ref
));
2546 static void gen_type_die
PARAMS ((tree
, dw_die_ref
));
2547 static void gen_tagged_type_instantiation_die
PARAMS ((tree
, dw_die_ref
));
2548 static void gen_block_die
PARAMS ((tree
, dw_die_ref
, int));
2549 static void decls_for_scope
PARAMS ((tree
, dw_die_ref
, int));
2550 static int is_redundant_typedef
PARAMS ((tree
));
2551 static void gen_decl_die
PARAMS ((tree
, dw_die_ref
));
2552 static unsigned lookup_filename
PARAMS ((const char *));
2553 static void add_incomplete_type
PARAMS ((tree
));
2554 static void retry_incomplete_types
PARAMS ((void));
2555 static void gen_type_die_for_member
PARAMS ((tree
, tree
, dw_die_ref
));
2556 static void gen_abstract_function
PARAMS ((tree
));
2557 static rtx save_rtx
PARAMS ((rtx
));
2558 static void splice_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
2559 static void reverse_die_lists
PARAMS ((dw_die_ref
));
2561 /* Section names used to hold DWARF debugging information. */
2562 #ifndef DEBUG_INFO_SECTION
2563 #define DEBUG_INFO_SECTION ".debug_info"
2565 #ifndef ABBREV_SECTION
2566 #define ABBREV_SECTION ".debug_abbrev"
2568 #ifndef ARANGES_SECTION
2569 #define ARANGES_SECTION ".debug_aranges"
2571 #ifndef DW_MACINFO_SECTION
2572 #define DW_MACINFO_SECTION ".debug_macinfo"
2574 #ifndef DEBUG_LINE_SECTION
2575 #define DEBUG_LINE_SECTION ".debug_line"
2578 #define LOC_SECTION ".debug_loc"
2580 #ifndef PUBNAMES_SECTION
2581 #define PUBNAMES_SECTION ".debug_pubnames"
2584 #define STR_SECTION ".debug_str"
2587 /* Standard ELF section names for compiled code and data. */
2588 #ifndef TEXT_SECTION
2589 #define TEXT_SECTION ".text"
2591 #ifndef DATA_SECTION
2592 #define DATA_SECTION ".data"
2595 #define BSS_SECTION ".bss"
2598 /* Labels we insert at beginning sections we can reference instead of
2599 the section names themselves. */
2601 #ifndef TEXT_SECTION_LABEL
2602 #define TEXT_SECTION_LABEL "Ltext"
2604 #ifndef DEBUG_LINE_SECTION_LABEL
2605 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
2607 #ifndef DEBUG_INFO_SECTION_LABEL
2608 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
2610 #ifndef ABBREV_SECTION_LABEL
2611 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
2615 /* Definitions of defaults for formats and names of various special
2616 (artificial) labels which may be generated within this file (when the -g
2617 options is used and DWARF_DEBUGGING_INFO is in effect.
2618 If necessary, these may be overridden from within the tm.h file, but
2619 typically, overriding these defaults is unnecessary. */
2621 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2622 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2623 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2624 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2625 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2627 #ifndef TEXT_END_LABEL
2628 #define TEXT_END_LABEL "Letext"
2630 #ifndef DATA_END_LABEL
2631 #define DATA_END_LABEL "Ledata"
2633 #ifndef BSS_END_LABEL
2634 #define BSS_END_LABEL "Lebss"
2636 #ifndef INSN_LABEL_FMT
2637 #define INSN_LABEL_FMT "LI%u_"
2639 #ifndef BLOCK_BEGIN_LABEL
2640 #define BLOCK_BEGIN_LABEL "LBB"
2642 #ifndef BLOCK_END_LABEL
2643 #define BLOCK_END_LABEL "LBE"
2645 #ifndef BODY_BEGIN_LABEL
2646 #define BODY_BEGIN_LABEL "Lbb"
2648 #ifndef BODY_END_LABEL
2649 #define BODY_END_LABEL "Lbe"
2651 #ifndef LINE_CODE_LABEL
2652 #define LINE_CODE_LABEL "LM"
2654 #ifndef SEPARATE_LINE_CODE_LABEL
2655 #define SEPARATE_LINE_CODE_LABEL "LSM"
2658 /* We allow a language front-end to designate a function that is to be
2659 called to "demangle" any name before it it put into a DIE. */
2661 static const char *(*demangle_name_func
) PARAMS ((const char *));
2664 dwarf2out_set_demangle_name_func (func
)
2665 const char *(*func
) PARAMS ((const char *));
2667 demangle_name_func
= func
;
2670 /* Return an rtx like ORIG which lives forever. If we're doing GC,
2671 that means adding it to used_rtx_varray. If not, that means making
2672 a copy on the permanent_obstack. */
2679 VARRAY_PUSH_RTX (used_rtx_varray
, orig
);
2682 push_obstacks_nochange ();
2683 end_temporary_allocation ();
2684 orig
= copy_rtx (orig
);
2691 /* Test if rtl node points to a pseudo register. */
2697 return ((GET_CODE (rtl
) == REG
&& REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
2698 || (GET_CODE (rtl
) == SUBREG
2699 && REGNO (XEXP (rtl
, 0)) >= FIRST_PSEUDO_REGISTER
));
2702 /* Return a reference to a type, with its const and volatile qualifiers
2706 type_main_variant (type
)
2709 type
= TYPE_MAIN_VARIANT (type
);
2711 /* There really should be only one main variant among any group of variants
2712 of a given type (and all of the MAIN_VARIANT values for all members of
2713 the group should point to that one type) but sometimes the C front-end
2714 messes this up for array types, so we work around that bug here. */
2716 if (TREE_CODE (type
) == ARRAY_TYPE
)
2717 while (type
!= TYPE_MAIN_VARIANT (type
))
2718 type
= TYPE_MAIN_VARIANT (type
);
2723 /* Return non-zero if the given type node represents a tagged type. */
2726 is_tagged_type (type
)
2729 register enum tree_code code
= TREE_CODE (type
);
2731 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
2732 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
2735 /* Convert a DIE tag into its string name. */
2738 dwarf_tag_name (tag
)
2739 register unsigned tag
;
2743 case DW_TAG_padding
:
2744 return "DW_TAG_padding";
2745 case DW_TAG_array_type
:
2746 return "DW_TAG_array_type";
2747 case DW_TAG_class_type
:
2748 return "DW_TAG_class_type";
2749 case DW_TAG_entry_point
:
2750 return "DW_TAG_entry_point";
2751 case DW_TAG_enumeration_type
:
2752 return "DW_TAG_enumeration_type";
2753 case DW_TAG_formal_parameter
:
2754 return "DW_TAG_formal_parameter";
2755 case DW_TAG_imported_declaration
:
2756 return "DW_TAG_imported_declaration";
2758 return "DW_TAG_label";
2759 case DW_TAG_lexical_block
:
2760 return "DW_TAG_lexical_block";
2762 return "DW_TAG_member";
2763 case DW_TAG_pointer_type
:
2764 return "DW_TAG_pointer_type";
2765 case DW_TAG_reference_type
:
2766 return "DW_TAG_reference_type";
2767 case DW_TAG_compile_unit
:
2768 return "DW_TAG_compile_unit";
2769 case DW_TAG_string_type
:
2770 return "DW_TAG_string_type";
2771 case DW_TAG_structure_type
:
2772 return "DW_TAG_structure_type";
2773 case DW_TAG_subroutine_type
:
2774 return "DW_TAG_subroutine_type";
2775 case DW_TAG_typedef
:
2776 return "DW_TAG_typedef";
2777 case DW_TAG_union_type
:
2778 return "DW_TAG_union_type";
2779 case DW_TAG_unspecified_parameters
:
2780 return "DW_TAG_unspecified_parameters";
2781 case DW_TAG_variant
:
2782 return "DW_TAG_variant";
2783 case DW_TAG_common_block
:
2784 return "DW_TAG_common_block";
2785 case DW_TAG_common_inclusion
:
2786 return "DW_TAG_common_inclusion";
2787 case DW_TAG_inheritance
:
2788 return "DW_TAG_inheritance";
2789 case DW_TAG_inlined_subroutine
:
2790 return "DW_TAG_inlined_subroutine";
2792 return "DW_TAG_module";
2793 case DW_TAG_ptr_to_member_type
:
2794 return "DW_TAG_ptr_to_member_type";
2795 case DW_TAG_set_type
:
2796 return "DW_TAG_set_type";
2797 case DW_TAG_subrange_type
:
2798 return "DW_TAG_subrange_type";
2799 case DW_TAG_with_stmt
:
2800 return "DW_TAG_with_stmt";
2801 case DW_TAG_access_declaration
:
2802 return "DW_TAG_access_declaration";
2803 case DW_TAG_base_type
:
2804 return "DW_TAG_base_type";
2805 case DW_TAG_catch_block
:
2806 return "DW_TAG_catch_block";
2807 case DW_TAG_const_type
:
2808 return "DW_TAG_const_type";
2809 case DW_TAG_constant
:
2810 return "DW_TAG_constant";
2811 case DW_TAG_enumerator
:
2812 return "DW_TAG_enumerator";
2813 case DW_TAG_file_type
:
2814 return "DW_TAG_file_type";
2816 return "DW_TAG_friend";
2817 case DW_TAG_namelist
:
2818 return "DW_TAG_namelist";
2819 case DW_TAG_namelist_item
:
2820 return "DW_TAG_namelist_item";
2821 case DW_TAG_packed_type
:
2822 return "DW_TAG_packed_type";
2823 case DW_TAG_subprogram
:
2824 return "DW_TAG_subprogram";
2825 case DW_TAG_template_type_param
:
2826 return "DW_TAG_template_type_param";
2827 case DW_TAG_template_value_param
:
2828 return "DW_TAG_template_value_param";
2829 case DW_TAG_thrown_type
:
2830 return "DW_TAG_thrown_type";
2831 case DW_TAG_try_block
:
2832 return "DW_TAG_try_block";
2833 case DW_TAG_variant_part
:
2834 return "DW_TAG_variant_part";
2835 case DW_TAG_variable
:
2836 return "DW_TAG_variable";
2837 case DW_TAG_volatile_type
:
2838 return "DW_TAG_volatile_type";
2839 case DW_TAG_MIPS_loop
:
2840 return "DW_TAG_MIPS_loop";
2841 case DW_TAG_format_label
:
2842 return "DW_TAG_format_label";
2843 case DW_TAG_function_template
:
2844 return "DW_TAG_function_template";
2845 case DW_TAG_class_template
:
2846 return "DW_TAG_class_template";
2848 return "DW_TAG_<unknown>";
2852 /* Convert a DWARF attribute code into its string name. */
2855 dwarf_attr_name (attr
)
2856 register unsigned attr
;
2861 return "DW_AT_sibling";
2862 case DW_AT_location
:
2863 return "DW_AT_location";
2865 return "DW_AT_name";
2866 case DW_AT_ordering
:
2867 return "DW_AT_ordering";
2868 case DW_AT_subscr_data
:
2869 return "DW_AT_subscr_data";
2870 case DW_AT_byte_size
:
2871 return "DW_AT_byte_size";
2872 case DW_AT_bit_offset
:
2873 return "DW_AT_bit_offset";
2874 case DW_AT_bit_size
:
2875 return "DW_AT_bit_size";
2876 case DW_AT_element_list
:
2877 return "DW_AT_element_list";
2878 case DW_AT_stmt_list
:
2879 return "DW_AT_stmt_list";
2881 return "DW_AT_low_pc";
2883 return "DW_AT_high_pc";
2884 case DW_AT_language
:
2885 return "DW_AT_language";
2887 return "DW_AT_member";
2889 return "DW_AT_discr";
2890 case DW_AT_discr_value
:
2891 return "DW_AT_discr_value";
2892 case DW_AT_visibility
:
2893 return "DW_AT_visibility";
2895 return "DW_AT_import";
2896 case DW_AT_string_length
:
2897 return "DW_AT_string_length";
2898 case DW_AT_common_reference
:
2899 return "DW_AT_common_reference";
2900 case DW_AT_comp_dir
:
2901 return "DW_AT_comp_dir";
2902 case DW_AT_const_value
:
2903 return "DW_AT_const_value";
2904 case DW_AT_containing_type
:
2905 return "DW_AT_containing_type";
2906 case DW_AT_default_value
:
2907 return "DW_AT_default_value";
2909 return "DW_AT_inline";
2910 case DW_AT_is_optional
:
2911 return "DW_AT_is_optional";
2912 case DW_AT_lower_bound
:
2913 return "DW_AT_lower_bound";
2914 case DW_AT_producer
:
2915 return "DW_AT_producer";
2916 case DW_AT_prototyped
:
2917 return "DW_AT_prototyped";
2918 case DW_AT_return_addr
:
2919 return "DW_AT_return_addr";
2920 case DW_AT_start_scope
:
2921 return "DW_AT_start_scope";
2922 case DW_AT_stride_size
:
2923 return "DW_AT_stride_size";
2924 case DW_AT_upper_bound
:
2925 return "DW_AT_upper_bound";
2926 case DW_AT_abstract_origin
:
2927 return "DW_AT_abstract_origin";
2928 case DW_AT_accessibility
:
2929 return "DW_AT_accessibility";
2930 case DW_AT_address_class
:
2931 return "DW_AT_address_class";
2932 case DW_AT_artificial
:
2933 return "DW_AT_artificial";
2934 case DW_AT_base_types
:
2935 return "DW_AT_base_types";
2936 case DW_AT_calling_convention
:
2937 return "DW_AT_calling_convention";
2939 return "DW_AT_count";
2940 case DW_AT_data_member_location
:
2941 return "DW_AT_data_member_location";
2942 case DW_AT_decl_column
:
2943 return "DW_AT_decl_column";
2944 case DW_AT_decl_file
:
2945 return "DW_AT_decl_file";
2946 case DW_AT_decl_line
:
2947 return "DW_AT_decl_line";
2948 case DW_AT_declaration
:
2949 return "DW_AT_declaration";
2950 case DW_AT_discr_list
:
2951 return "DW_AT_discr_list";
2952 case DW_AT_encoding
:
2953 return "DW_AT_encoding";
2954 case DW_AT_external
:
2955 return "DW_AT_external";
2956 case DW_AT_frame_base
:
2957 return "DW_AT_frame_base";
2959 return "DW_AT_friend";
2960 case DW_AT_identifier_case
:
2961 return "DW_AT_identifier_case";
2962 case DW_AT_macro_info
:
2963 return "DW_AT_macro_info";
2964 case DW_AT_namelist_items
:
2965 return "DW_AT_namelist_items";
2966 case DW_AT_priority
:
2967 return "DW_AT_priority";
2969 return "DW_AT_segment";
2970 case DW_AT_specification
:
2971 return "DW_AT_specification";
2972 case DW_AT_static_link
:
2973 return "DW_AT_static_link";
2975 return "DW_AT_type";
2976 case DW_AT_use_location
:
2977 return "DW_AT_use_location";
2978 case DW_AT_variable_parameter
:
2979 return "DW_AT_variable_parameter";
2980 case DW_AT_virtuality
:
2981 return "DW_AT_virtuality";
2982 case DW_AT_vtable_elem_location
:
2983 return "DW_AT_vtable_elem_location";
2985 case DW_AT_MIPS_fde
:
2986 return "DW_AT_MIPS_fde";
2987 case DW_AT_MIPS_loop_begin
:
2988 return "DW_AT_MIPS_loop_begin";
2989 case DW_AT_MIPS_tail_loop_begin
:
2990 return "DW_AT_MIPS_tail_loop_begin";
2991 case DW_AT_MIPS_epilog_begin
:
2992 return "DW_AT_MIPS_epilog_begin";
2993 case DW_AT_MIPS_loop_unroll_factor
:
2994 return "DW_AT_MIPS_loop_unroll_factor";
2995 case DW_AT_MIPS_software_pipeline_depth
:
2996 return "DW_AT_MIPS_software_pipeline_depth";
2997 case DW_AT_MIPS_linkage_name
:
2998 return "DW_AT_MIPS_linkage_name";
2999 case DW_AT_MIPS_stride
:
3000 return "DW_AT_MIPS_stride";
3001 case DW_AT_MIPS_abstract_name
:
3002 return "DW_AT_MIPS_abstract_name";
3003 case DW_AT_MIPS_clone_origin
:
3004 return "DW_AT_MIPS_clone_origin";
3005 case DW_AT_MIPS_has_inlines
:
3006 return "DW_AT_MIPS_has_inlines";
3008 case DW_AT_sf_names
:
3009 return "DW_AT_sf_names";
3010 case DW_AT_src_info
:
3011 return "DW_AT_src_info";
3012 case DW_AT_mac_info
:
3013 return "DW_AT_mac_info";
3014 case DW_AT_src_coords
:
3015 return "DW_AT_src_coords";
3016 case DW_AT_body_begin
:
3017 return "DW_AT_body_begin";
3018 case DW_AT_body_end
:
3019 return "DW_AT_body_end";
3021 return "DW_AT_<unknown>";
3025 /* Convert a DWARF value form code into its string name. */
3028 dwarf_form_name (form
)
3029 register unsigned form
;
3034 return "DW_FORM_addr";
3035 case DW_FORM_block2
:
3036 return "DW_FORM_block2";
3037 case DW_FORM_block4
:
3038 return "DW_FORM_block4";
3040 return "DW_FORM_data2";
3042 return "DW_FORM_data4";
3044 return "DW_FORM_data8";
3045 case DW_FORM_string
:
3046 return "DW_FORM_string";
3048 return "DW_FORM_block";
3049 case DW_FORM_block1
:
3050 return "DW_FORM_block1";
3052 return "DW_FORM_data1";
3054 return "DW_FORM_flag";
3056 return "DW_FORM_sdata";
3058 return "DW_FORM_strp";
3060 return "DW_FORM_udata";
3061 case DW_FORM_ref_addr
:
3062 return "DW_FORM_ref_addr";
3064 return "DW_FORM_ref1";
3066 return "DW_FORM_ref2";
3068 return "DW_FORM_ref4";
3070 return "DW_FORM_ref8";
3071 case DW_FORM_ref_udata
:
3072 return "DW_FORM_ref_udata";
3073 case DW_FORM_indirect
:
3074 return "DW_FORM_indirect";
3076 return "DW_FORM_<unknown>";
3080 /* Convert a DWARF stack opcode into its string name. */
3083 dwarf_stack_op_name (op
)
3084 register unsigned op
;
3089 return "DW_OP_addr";
3091 return "DW_OP_deref";
3093 return "DW_OP_const1u";
3095 return "DW_OP_const1s";
3097 return "DW_OP_const2u";
3099 return "DW_OP_const2s";
3101 return "DW_OP_const4u";
3103 return "DW_OP_const4s";
3105 return "DW_OP_const8u";
3107 return "DW_OP_const8s";
3109 return "DW_OP_constu";
3111 return "DW_OP_consts";
3115 return "DW_OP_drop";
3117 return "DW_OP_over";
3119 return "DW_OP_pick";
3121 return "DW_OP_swap";
3125 return "DW_OP_xderef";
3133 return "DW_OP_minus";
3145 return "DW_OP_plus";
3146 case DW_OP_plus_uconst
:
3147 return "DW_OP_plus_uconst";
3153 return "DW_OP_shra";
3171 return "DW_OP_skip";
3173 return "DW_OP_lit0";
3175 return "DW_OP_lit1";
3177 return "DW_OP_lit2";
3179 return "DW_OP_lit3";
3181 return "DW_OP_lit4";
3183 return "DW_OP_lit5";
3185 return "DW_OP_lit6";
3187 return "DW_OP_lit7";
3189 return "DW_OP_lit8";
3191 return "DW_OP_lit9";
3193 return "DW_OP_lit10";
3195 return "DW_OP_lit11";
3197 return "DW_OP_lit12";
3199 return "DW_OP_lit13";
3201 return "DW_OP_lit14";
3203 return "DW_OP_lit15";
3205 return "DW_OP_lit16";
3207 return "DW_OP_lit17";
3209 return "DW_OP_lit18";
3211 return "DW_OP_lit19";
3213 return "DW_OP_lit20";
3215 return "DW_OP_lit21";
3217 return "DW_OP_lit22";
3219 return "DW_OP_lit23";
3221 return "DW_OP_lit24";
3223 return "DW_OP_lit25";
3225 return "DW_OP_lit26";
3227 return "DW_OP_lit27";
3229 return "DW_OP_lit28";
3231 return "DW_OP_lit29";
3233 return "DW_OP_lit30";
3235 return "DW_OP_lit31";
3237 return "DW_OP_reg0";
3239 return "DW_OP_reg1";
3241 return "DW_OP_reg2";
3243 return "DW_OP_reg3";
3245 return "DW_OP_reg4";
3247 return "DW_OP_reg5";
3249 return "DW_OP_reg6";
3251 return "DW_OP_reg7";
3253 return "DW_OP_reg8";
3255 return "DW_OP_reg9";
3257 return "DW_OP_reg10";
3259 return "DW_OP_reg11";
3261 return "DW_OP_reg12";
3263 return "DW_OP_reg13";
3265 return "DW_OP_reg14";
3267 return "DW_OP_reg15";
3269 return "DW_OP_reg16";
3271 return "DW_OP_reg17";
3273 return "DW_OP_reg18";
3275 return "DW_OP_reg19";
3277 return "DW_OP_reg20";
3279 return "DW_OP_reg21";
3281 return "DW_OP_reg22";
3283 return "DW_OP_reg23";
3285 return "DW_OP_reg24";
3287 return "DW_OP_reg25";
3289 return "DW_OP_reg26";
3291 return "DW_OP_reg27";
3293 return "DW_OP_reg28";
3295 return "DW_OP_reg29";
3297 return "DW_OP_reg30";
3299 return "DW_OP_reg31";
3301 return "DW_OP_breg0";
3303 return "DW_OP_breg1";
3305 return "DW_OP_breg2";
3307 return "DW_OP_breg3";
3309 return "DW_OP_breg4";
3311 return "DW_OP_breg5";
3313 return "DW_OP_breg6";
3315 return "DW_OP_breg7";
3317 return "DW_OP_breg8";
3319 return "DW_OP_breg9";
3321 return "DW_OP_breg10";
3323 return "DW_OP_breg11";
3325 return "DW_OP_breg12";
3327 return "DW_OP_breg13";
3329 return "DW_OP_breg14";
3331 return "DW_OP_breg15";
3333 return "DW_OP_breg16";
3335 return "DW_OP_breg17";
3337 return "DW_OP_breg18";
3339 return "DW_OP_breg19";
3341 return "DW_OP_breg20";
3343 return "DW_OP_breg21";
3345 return "DW_OP_breg22";
3347 return "DW_OP_breg23";
3349 return "DW_OP_breg24";
3351 return "DW_OP_breg25";
3353 return "DW_OP_breg26";
3355 return "DW_OP_breg27";
3357 return "DW_OP_breg28";
3359 return "DW_OP_breg29";
3361 return "DW_OP_breg30";
3363 return "DW_OP_breg31";
3365 return "DW_OP_regx";
3367 return "DW_OP_fbreg";
3369 return "DW_OP_bregx";
3371 return "DW_OP_piece";
3372 case DW_OP_deref_size
:
3373 return "DW_OP_deref_size";
3374 case DW_OP_xderef_size
:
3375 return "DW_OP_xderef_size";
3379 return "OP_<unknown>";
3383 /* Convert a DWARF type code into its string name. */
3387 dwarf_type_encoding_name (enc
)
3388 register unsigned enc
;
3392 case DW_ATE_address
:
3393 return "DW_ATE_address";
3394 case DW_ATE_boolean
:
3395 return "DW_ATE_boolean";
3396 case DW_ATE_complex_float
:
3397 return "DW_ATE_complex_float";
3399 return "DW_ATE_float";
3401 return "DW_ATE_signed";
3402 case DW_ATE_signed_char
:
3403 return "DW_ATE_signed_char";
3404 case DW_ATE_unsigned
:
3405 return "DW_ATE_unsigned";
3406 case DW_ATE_unsigned_char
:
3407 return "DW_ATE_unsigned_char";
3409 return "DW_ATE_<unknown>";
3414 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3415 instance of an inlined instance of a decl which is local to an inline
3416 function, so we have to trace all of the way back through the origin chain
3417 to find out what sort of node actually served as the original seed for the
3421 decl_ultimate_origin (decl
)
3424 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3425 nodes in the function to point to themselves; ignore that if
3426 we're trying to output the abstract instance of this function. */
3427 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3430 #ifdef ENABLE_CHECKING
3431 if (DECL_FROM_INLINE (DECL_ORIGIN (decl
)))
3432 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3433 most distant ancestor, this should never happen. */
3437 return DECL_ABSTRACT_ORIGIN (decl
);
3440 /* Determine the "ultimate origin" of a block. The block may be an inlined
3441 instance of an inlined instance of a block which is local to an inline
3442 function, so we have to trace all of the way back through the origin chain
3443 to find out what sort of node actually served as the original seed for the
3447 block_ultimate_origin (block
)
3448 register tree block
;
3450 register tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
3452 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
3453 nodes in the function to point to themselves; ignore that if
3454 we're trying to output the abstract instance of this function. */
3455 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
3458 if (immediate_origin
== NULL_TREE
)
3462 register tree ret_val
;
3463 register tree lookahead
= immediate_origin
;
3467 ret_val
= lookahead
;
3468 lookahead
= (TREE_CODE (ret_val
) == BLOCK
)
3469 ? BLOCK_ABSTRACT_ORIGIN (ret_val
)
3472 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
3478 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3479 of a virtual function may refer to a base class, so we check the 'this'
3483 decl_class_context (decl
)
3486 tree context
= NULL_TREE
;
3488 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3489 context
= DECL_CONTEXT (decl
);
3491 context
= TYPE_MAIN_VARIANT
3492 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3494 if (context
&& !TYPE_P (context
))
3495 context
= NULL_TREE
;
3500 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
3501 addition order, and correct that in add_sibling_attributes. */
3504 add_dwarf_attr (die
, attr
)
3505 register dw_die_ref die
;
3506 register dw_attr_ref attr
;
3508 if (die
!= NULL
&& attr
!= NULL
)
3510 attr
->dw_attr_next
= die
->die_attr
;
3511 die
->die_attr
= attr
;
3515 static inline dw_val_class AT_class
PARAMS ((dw_attr_ref
));
3516 static inline dw_val_class
3520 return a
->dw_attr_val
.val_class
;
3523 /* Add a flag value attribute to a DIE. */
3526 add_AT_flag (die
, attr_kind
, flag
)
3527 register dw_die_ref die
;
3528 register enum dwarf_attribute attr_kind
;
3529 register unsigned flag
;
3531 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3533 attr
->dw_attr_next
= NULL
;
3534 attr
->dw_attr
= attr_kind
;
3535 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
3536 attr
->dw_attr_val
.v
.val_flag
= flag
;
3537 add_dwarf_attr (die
, attr
);
3540 static inline unsigned AT_flag
PARAMS ((dw_attr_ref
));
3541 static inline unsigned
3543 register dw_attr_ref a
;
3545 if (a
&& AT_class (a
) == dw_val_class_flag
)
3546 return a
->dw_attr_val
.v
.val_flag
;
3551 /* Add a signed integer attribute value to a DIE. */
3554 add_AT_int (die
, attr_kind
, int_val
)
3555 register dw_die_ref die
;
3556 register enum dwarf_attribute attr_kind
;
3557 register long int int_val
;
3559 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3561 attr
->dw_attr_next
= NULL
;
3562 attr
->dw_attr
= attr_kind
;
3563 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
3564 attr
->dw_attr_val
.v
.val_int
= int_val
;
3565 add_dwarf_attr (die
, attr
);
3568 static inline long int AT_int
PARAMS ((dw_attr_ref
));
3569 static inline long int
3571 register dw_attr_ref a
;
3573 if (a
&& AT_class (a
) == dw_val_class_const
)
3574 return a
->dw_attr_val
.v
.val_int
;
3579 /* Add an unsigned integer attribute value to a DIE. */
3582 add_AT_unsigned (die
, attr_kind
, unsigned_val
)
3583 register dw_die_ref die
;
3584 register enum dwarf_attribute attr_kind
;
3585 register unsigned long unsigned_val
;
3587 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3589 attr
->dw_attr_next
= NULL
;
3590 attr
->dw_attr
= attr_kind
;
3591 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3592 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3593 add_dwarf_attr (die
, attr
);
3596 static inline unsigned long AT_unsigned
PARAMS ((dw_attr_ref
));
3597 static inline unsigned long
3599 register dw_attr_ref a
;
3601 if (a
&& AT_class (a
) == dw_val_class_unsigned_const
)
3602 return a
->dw_attr_val
.v
.val_unsigned
;
3607 /* Add an unsigned double integer attribute value to a DIE. */
3610 add_AT_long_long (die
, attr_kind
, val_hi
, val_low
)
3611 register dw_die_ref die
;
3612 register enum dwarf_attribute attr_kind
;
3613 register unsigned long val_hi
;
3614 register unsigned long val_low
;
3616 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3618 attr
->dw_attr_next
= NULL
;
3619 attr
->dw_attr
= attr_kind
;
3620 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
3621 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
3622 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
3623 add_dwarf_attr (die
, attr
);
3626 /* Add a floating point attribute value to a DIE and return it. */
3629 add_AT_float (die
, attr_kind
, length
, array
)
3630 register dw_die_ref die
;
3631 register enum dwarf_attribute attr_kind
;
3632 register unsigned length
;
3633 register long *array
;
3635 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3637 attr
->dw_attr_next
= NULL
;
3638 attr
->dw_attr
= attr_kind
;
3639 attr
->dw_attr_val
.val_class
= dw_val_class_float
;
3640 attr
->dw_attr_val
.v
.val_float
.length
= length
;
3641 attr
->dw_attr_val
.v
.val_float
.array
= array
;
3642 add_dwarf_attr (die
, attr
);
3645 /* Add a string attribute value to a DIE. */
3648 add_AT_string (die
, attr_kind
, str
)
3649 register dw_die_ref die
;
3650 register enum dwarf_attribute attr_kind
;
3651 register const char *str
;
3653 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3655 attr
->dw_attr_next
= NULL
;
3656 attr
->dw_attr
= attr_kind
;
3657 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
3658 attr
->dw_attr_val
.v
.val_str
= xstrdup (str
);
3659 add_dwarf_attr (die
, attr
);
3662 static inline const char *AT_string
PARAMS ((dw_attr_ref
));
3663 static inline const char *
3665 register dw_attr_ref a
;
3667 if (a
&& AT_class (a
) == dw_val_class_str
)
3668 return a
->dw_attr_val
.v
.val_str
;
3673 /* Add a DIE reference attribute value to a DIE. */
3676 add_AT_die_ref (die
, attr_kind
, targ_die
)
3677 register dw_die_ref die
;
3678 register enum dwarf_attribute attr_kind
;
3679 register dw_die_ref targ_die
;
3681 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3683 attr
->dw_attr_next
= NULL
;
3684 attr
->dw_attr
= attr_kind
;
3685 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
3686 attr
->dw_attr_val
.v
.val_die_ref
= targ_die
;
3687 add_dwarf_attr (die
, attr
);
3690 static inline dw_die_ref AT_ref
PARAMS ((dw_attr_ref
));
3691 static inline dw_die_ref
3693 register dw_attr_ref a
;
3695 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
3696 return a
->dw_attr_val
.v
.val_die_ref
;
3701 /* Add an FDE reference attribute value to a DIE. */
3704 add_AT_fde_ref (die
, attr_kind
, targ_fde
)
3705 register dw_die_ref die
;
3706 register enum dwarf_attribute attr_kind
;
3707 register unsigned targ_fde
;
3709 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3711 attr
->dw_attr_next
= NULL
;
3712 attr
->dw_attr
= attr_kind
;
3713 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
3714 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
3715 add_dwarf_attr (die
, attr
);
3718 /* Add a location description attribute value to a DIE. */
3721 add_AT_loc (die
, attr_kind
, loc
)
3722 register dw_die_ref die
;
3723 register enum dwarf_attribute attr_kind
;
3724 register dw_loc_descr_ref loc
;
3726 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3728 attr
->dw_attr_next
= NULL
;
3729 attr
->dw_attr
= attr_kind
;
3730 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
3731 attr
->dw_attr_val
.v
.val_loc
= loc
;
3732 add_dwarf_attr (die
, attr
);
3735 static inline dw_loc_descr_ref AT_loc
PARAMS ((dw_attr_ref
));
3736 static inline dw_loc_descr_ref
3738 register dw_attr_ref a
;
3740 if (a
&& AT_class (a
) == dw_val_class_loc
)
3741 return a
->dw_attr_val
.v
.val_loc
;
3746 /* Add an address constant attribute value to a DIE. */
3749 add_AT_addr (die
, attr_kind
, addr
)
3750 register dw_die_ref die
;
3751 register enum dwarf_attribute attr_kind
;
3754 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3756 attr
->dw_attr_next
= NULL
;
3757 attr
->dw_attr
= attr_kind
;
3758 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
3759 attr
->dw_attr_val
.v
.val_addr
= addr
;
3760 add_dwarf_attr (die
, attr
);
3763 static inline rtx AT_addr
PARAMS ((dw_attr_ref
));
3766 register dw_attr_ref a
;
3768 if (a
&& AT_class (a
) == dw_val_class_addr
)
3769 return a
->dw_attr_val
.v
.val_addr
;
3774 /* Add a label identifier attribute value to a DIE. */
3777 add_AT_lbl_id (die
, attr_kind
, lbl_id
)
3778 register dw_die_ref die
;
3779 register enum dwarf_attribute attr_kind
;
3780 register const char *lbl_id
;
3782 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3784 attr
->dw_attr_next
= NULL
;
3785 attr
->dw_attr
= attr_kind
;
3786 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3787 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
3788 add_dwarf_attr (die
, attr
);
3791 /* Add a section offset attribute value to a DIE. */
3794 add_AT_lbl_offset (die
, attr_kind
, label
)
3795 register dw_die_ref die
;
3796 register enum dwarf_attribute attr_kind
;
3797 register const char *label
;
3799 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3801 attr
->dw_attr_next
= NULL
;
3802 attr
->dw_attr
= attr_kind
;
3803 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_offset
;
3804 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
3805 add_dwarf_attr (die
, attr
);
3809 static inline const char *AT_lbl
PARAMS ((dw_attr_ref
));
3810 static inline const char *
3812 register dw_attr_ref a
;
3814 if (a
&& (AT_class (a
) == dw_val_class_lbl_id
3815 || AT_class (a
) == dw_val_class_lbl_offset
))
3816 return a
->dw_attr_val
.v
.val_lbl_id
;
3821 /* Get the attribute of type attr_kind. */
3823 static inline dw_attr_ref
3824 get_AT (die
, attr_kind
)
3825 register dw_die_ref die
;
3826 register enum dwarf_attribute attr_kind
;
3828 register dw_attr_ref a
;
3829 register dw_die_ref spec
= NULL
;
3833 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
3835 if (a
->dw_attr
== attr_kind
)
3838 if (a
->dw_attr
== DW_AT_specification
3839 || a
->dw_attr
== DW_AT_abstract_origin
)
3844 return get_AT (spec
, attr_kind
);
3850 /* Return the "low pc" attribute value, typically associated with
3851 a subprogram DIE. Return null if the "low pc" attribute is
3852 either not prsent, or if it cannot be represented as an
3853 assembler label identifier. */
3855 static inline const char *
3857 register dw_die_ref die
;
3859 register dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
3863 /* Return the "high pc" attribute value, typically associated with
3864 a subprogram DIE. Return null if the "high pc" attribute is
3865 either not prsent, or if it cannot be represented as an
3866 assembler label identifier. */
3868 static inline const char *
3870 register dw_die_ref die
;
3872 register dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
3876 /* Return the value of the string attribute designated by ATTR_KIND, or
3877 NULL if it is not present. */
3879 static inline const char *
3880 get_AT_string (die
, attr_kind
)
3881 register dw_die_ref die
;
3882 register enum dwarf_attribute attr_kind
;
3884 register dw_attr_ref a
= get_AT (die
, attr_kind
);
3885 return AT_string (a
);
3888 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3889 if it is not present. */
3892 get_AT_flag (die
, attr_kind
)
3893 register dw_die_ref die
;
3894 register enum dwarf_attribute attr_kind
;
3896 register dw_attr_ref a
= get_AT (die
, attr_kind
);
3900 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3901 if it is not present. */
3903 static inline unsigned
3904 get_AT_unsigned (die
, attr_kind
)
3905 register dw_die_ref die
;
3906 register enum dwarf_attribute attr_kind
;
3908 register dw_attr_ref a
= get_AT (die
, attr_kind
);
3909 return AT_unsigned (a
);
3912 static inline dw_die_ref
3913 get_AT_ref (die
, attr_kind
)
3915 register enum dwarf_attribute attr_kind
;
3917 register dw_attr_ref a
= get_AT (die
, attr_kind
);
3924 register unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
3926 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
3927 || lang
== DW_LANG_C_plus_plus
);
3933 register unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
3935 return (lang
== DW_LANG_Fortran77
|| lang
== DW_LANG_Fortran90
);
3938 /* Free up the memory used by A. */
3940 static inline void free_AT
PARAMS ((dw_attr_ref
));
3945 switch (AT_class (a
))
3947 case dw_val_class_str
:
3948 case dw_val_class_lbl_id
:
3949 case dw_val_class_lbl_offset
:
3950 free (a
->dw_attr_val
.v
.val_str
);
3960 /* Remove the specified attribute if present. */
3963 remove_AT (die
, attr_kind
)
3964 register dw_die_ref die
;
3965 register enum dwarf_attribute attr_kind
;
3967 register dw_attr_ref
*p
;
3968 register dw_attr_ref removed
= NULL
;
3972 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
3973 if ((*p
)->dw_attr
== attr_kind
)
3976 *p
= (*p
)->dw_attr_next
;
3985 /* Free up the memory used by DIE. */
3987 static inline void free_die
PARAMS ((dw_die_ref
));
3992 remove_children (die
);
3996 /* Discard the children of this DIE. */
3999 remove_children (die
)
4000 register dw_die_ref die
;
4002 register dw_die_ref child_die
= die
->die_child
;
4004 die
->die_child
= NULL
;
4006 while (child_die
!= NULL
)
4008 register dw_die_ref tmp_die
= child_die
;
4009 register dw_attr_ref a
;
4011 child_die
= child_die
->die_sib
;
4013 for (a
= tmp_die
->die_attr
; a
!= NULL
; )
4015 register dw_attr_ref tmp_a
= a
;
4017 a
= a
->dw_attr_next
;
4025 /* Add a child DIE below its parent. We build the lists up in reverse
4026 addition order, and correct that in add_sibling_attributes. */
4029 add_child_die (die
, child_die
)
4030 register dw_die_ref die
;
4031 register dw_die_ref child_die
;
4033 if (die
!= NULL
&& child_die
!= NULL
)
4035 if (die
== child_die
)
4037 child_die
->die_parent
= die
;
4038 child_die
->die_sib
= die
->die_child
;
4039 die
->die_child
= child_die
;
4043 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4044 is the specification, to the front of PARENT's list of children. */
4047 splice_child_die (parent
, child
)
4048 dw_die_ref parent
, child
;
4052 /* We want the declaration DIE from inside the class, not the
4053 specification DIE at toplevel. */
4054 if (child
->die_parent
!= parent
)
4056 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4061 if (child
->die_parent
!= parent
4062 && child
->die_parent
!= get_AT_ref (parent
, DW_AT_specification
))
4065 for (p
= &(parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
4068 *p
= child
->die_sib
;
4072 child
->die_sib
= parent
->die_child
;
4073 parent
->die_child
= child
;
4076 /* Return a pointer to a newly created DIE node. */
4078 static inline dw_die_ref
4079 new_die (tag_value
, parent_die
)
4080 register enum dwarf_tag tag_value
;
4081 register dw_die_ref parent_die
;
4083 register dw_die_ref die
= (dw_die_ref
) xmalloc (sizeof (die_node
));
4085 die
->die_tag
= tag_value
;
4086 die
->die_abbrev
= 0;
4087 die
->die_offset
= 0;
4088 die
->die_child
= NULL
;
4089 die
->die_parent
= NULL
;
4090 die
->die_sib
= NULL
;
4091 die
->die_attr
= NULL
;
4093 if (parent_die
!= NULL
)
4094 add_child_die (parent_die
, die
);
4097 limbo_die_node
*limbo_node
;
4099 limbo_node
= (limbo_die_node
*) xmalloc (sizeof (limbo_die_node
));
4100 limbo_node
->die
= die
;
4101 limbo_node
->next
= limbo_die_list
;
4102 limbo_die_list
= limbo_node
;
4108 /* Return the DIE associated with the given type specifier. */
4110 static inline dw_die_ref
4111 lookup_type_die (type
)
4114 return (dw_die_ref
) TYPE_SYMTAB_POINTER (type
);
4117 /* Equate a DIE to a given type specifier. */
4120 equate_type_number_to_die (type
, type_die
)
4122 register dw_die_ref type_die
;
4124 TYPE_SYMTAB_POINTER (type
) = (char *) type_die
;
4127 /* Return the DIE associated with a given declaration. */
4129 static inline dw_die_ref
4130 lookup_decl_die (decl
)
4133 register unsigned decl_id
= DECL_UID (decl
);
4135 return (decl_id
< decl_die_table_in_use
4136 ? decl_die_table
[decl_id
] : NULL
);
4139 /* Equate a DIE to a particular declaration. */
4142 equate_decl_number_to_die (decl
, decl_die
)
4144 register dw_die_ref decl_die
;
4146 register unsigned decl_id
= DECL_UID (decl
);
4147 register unsigned num_allocated
;
4149 if (decl_id
>= decl_die_table_allocated
)
4152 = ((decl_id
+ 1 + DECL_DIE_TABLE_INCREMENT
- 1)
4153 / DECL_DIE_TABLE_INCREMENT
)
4154 * DECL_DIE_TABLE_INCREMENT
;
4157 = (dw_die_ref
*) xrealloc (decl_die_table
,
4158 sizeof (dw_die_ref
) * num_allocated
);
4160 bzero ((char *) &decl_die_table
[decl_die_table_allocated
],
4161 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
4162 decl_die_table_allocated
= num_allocated
;
4165 if (decl_id
>= decl_die_table_in_use
)
4166 decl_die_table_in_use
= (decl_id
+ 1);
4168 decl_die_table
[decl_id
] = decl_die
;
4171 /* Return a pointer to a newly allocated location description. Location
4172 descriptions are simple expression terms that can be strung
4173 together to form more complicated location (address) descriptions. */
4175 static inline dw_loc_descr_ref
4176 new_loc_descr (op
, oprnd1
, oprnd2
)
4177 register enum dwarf_location_atom op
;
4178 register unsigned long oprnd1
;
4179 register unsigned long oprnd2
;
4181 register dw_loc_descr_ref descr
4182 = (dw_loc_descr_ref
) xmalloc (sizeof (dw_loc_descr_node
));
4184 descr
->dw_loc_next
= NULL
;
4185 descr
->dw_loc_opc
= op
;
4186 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
4187 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
4188 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
4189 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
4194 /* Add a location description term to a location description expression. */
4197 add_loc_descr (list_head
, descr
)
4198 register dw_loc_descr_ref
*list_head
;
4199 register dw_loc_descr_ref descr
;
4201 register dw_loc_descr_ref
*d
;
4203 /* Find the end of the chain. */
4204 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
4210 /* Keep track of the number of spaces used to indent the
4211 output of the debugging routines that print the structure of
4212 the DIE internal representation. */
4213 static int print_indent
;
4215 /* Indent the line the number of spaces given by print_indent. */
4218 print_spaces (outfile
)
4221 fprintf (outfile
, "%*s", print_indent
, "");
4224 /* Print the information associated with a given DIE, and its children.
4225 This routine is a debugging aid only. */
4228 print_die (die
, outfile
)
4232 register dw_attr_ref a
;
4233 register dw_die_ref c
;
4235 print_spaces (outfile
);
4236 fprintf (outfile
, "DIE %4lu: %s\n",
4237 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
4238 print_spaces (outfile
);
4239 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
4240 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
4242 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4244 print_spaces (outfile
);
4245 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
4247 switch (AT_class (a
))
4249 case dw_val_class_addr
:
4250 fprintf (outfile
, "address");
4252 case dw_val_class_loc
:
4253 fprintf (outfile
, "location descriptor");
4255 case dw_val_class_const
:
4256 fprintf (outfile
, "%ld", AT_int (a
));
4258 case dw_val_class_unsigned_const
:
4259 fprintf (outfile
, "%lu", AT_unsigned (a
));
4261 case dw_val_class_long_long
:
4262 fprintf (outfile
, "constant (%lu,%lu)",
4263 a
->dw_attr_val
.v
.val_long_long
.hi
,
4264 a
->dw_attr_val
.v
.val_long_long
.low
);
4266 case dw_val_class_float
:
4267 fprintf (outfile
, "floating-point constant");
4269 case dw_val_class_flag
:
4270 fprintf (outfile
, "%u", AT_flag (a
));
4272 case dw_val_class_die_ref
:
4273 if (AT_ref (a
) != NULL
)
4274 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
4276 fprintf (outfile
, "die -> <null>");
4278 case dw_val_class_lbl_id
:
4279 case dw_val_class_lbl_offset
:
4280 fprintf (outfile
, "label: %s", AT_lbl (a
));
4282 case dw_val_class_str
:
4283 if (AT_string (a
) != NULL
)
4284 fprintf (outfile
, "\"%s\"", AT_string (a
));
4286 fprintf (outfile
, "<null>");
4292 fprintf (outfile
, "\n");
4295 if (die
->die_child
!= NULL
)
4298 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4299 print_die (c
, outfile
);
4305 /* Print the contents of the source code line number correspondence table.
4306 This routine is a debugging aid only. */
4309 print_dwarf_line_table (outfile
)
4312 register unsigned i
;
4313 register dw_line_info_ref line_info
;
4315 fprintf (outfile
, "\n\nDWARF source line information\n");
4316 for (i
= 1; i
< line_info_table_in_use
; ++i
)
4318 line_info
= &line_info_table
[i
];
4319 fprintf (outfile
, "%5d: ", i
);
4320 fprintf (outfile
, "%-20s", file_table
[line_info
->dw_file_num
]);
4321 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
4322 fprintf (outfile
, "\n");
4325 fprintf (outfile
, "\n\n");
4328 /* Print the information collected for a given DIE. */
4331 debug_dwarf_die (die
)
4334 print_die (die
, stderr
);
4337 /* Print all DWARF information collected for the compilation unit.
4338 This routine is a debugging aid only. */
4344 print_die (comp_unit_die
, stderr
);
4345 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
4346 print_dwarf_line_table (stderr
);
4349 /* We build up the lists of children and attributes by pushing new ones
4350 onto the beginning of the list. Reverse the lists for DIE so that
4351 they are in order of addition. */
4354 reverse_die_lists (die
)
4355 register dw_die_ref die
;
4357 register dw_die_ref c
, cp
, cn
;
4358 register dw_attr_ref a
, ap
, an
;
4360 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
4362 an
= a
->dw_attr_next
;
4363 a
->dw_attr_next
= ap
;
4368 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
4374 die
->die_child
= cp
;
4377 /* Traverse the DIE, reverse its lists of attributes and children, and
4378 add a sibling attribute if it may have the effect of speeding up
4379 access to siblings. To save some space, avoid generating sibling
4380 attributes for DIE's without children. */
4383 add_sibling_attributes (die
)
4384 register dw_die_ref die
;
4386 register dw_die_ref c
;
4388 reverse_die_lists (die
);
4390 if (die
!= comp_unit_die
&& die
->die_sib
&& die
->die_child
!= NULL
)
4391 /* Add the sibling link to the front of the attribute list. */
4392 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
4394 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4395 add_sibling_attributes (c
);
4398 /* The format of each DIE (and its attribute value pairs)
4399 is encoded in an abbreviation table. This routine builds the
4400 abbreviation table and assigns a unique abbreviation id for
4401 each abbreviation entry. The children of each die are visited
4405 build_abbrev_table (die
)
4406 register dw_die_ref die
;
4408 register unsigned long abbrev_id
;
4409 register unsigned long n_alloc
;
4410 register dw_die_ref c
;
4411 register dw_attr_ref d_attr
, a_attr
;
4412 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
4414 register dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
4416 if (abbrev
->die_tag
== die
->die_tag
)
4418 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
4420 a_attr
= abbrev
->die_attr
;
4421 d_attr
= die
->die_attr
;
4423 while (a_attr
!= NULL
&& d_attr
!= NULL
)
4425 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
4426 || (value_format (a_attr
) != value_format (d_attr
)))
4429 a_attr
= a_attr
->dw_attr_next
;
4430 d_attr
= d_attr
->dw_attr_next
;
4433 if (a_attr
== NULL
&& d_attr
== NULL
)
4439 if (abbrev_id
>= abbrev_die_table_in_use
)
4441 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
4443 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
4445 = (dw_die_ref
*) xrealloc (abbrev_die_table
,
4446 sizeof (dw_die_ref
) * n_alloc
);
4448 bzero ((char *) &abbrev_die_table
[abbrev_die_table_allocated
],
4449 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
4450 abbrev_die_table_allocated
= n_alloc
;
4453 ++abbrev_die_table_in_use
;
4454 abbrev_die_table
[abbrev_id
] = die
;
4457 die
->die_abbrev
= abbrev_id
;
4458 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4459 build_abbrev_table (c
);
4462 /* Return the size of a string, including the null byte.
4464 This used to treat backslashes as escapes, and hence they were not included
4465 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
4466 which treats a backslash as a backslash, escaping it if necessary, and hence
4467 we must include them in the count. */
4469 static unsigned long
4470 size_of_string (str
)
4471 register const char *str
;
4473 return strlen (str
) + 1;
4476 /* Return the size of a location descriptor. */
4478 static unsigned long
4479 size_of_loc_descr (loc
)
4480 register dw_loc_descr_ref loc
;
4482 register unsigned long size
= 1;
4484 switch (loc
->dw_loc_opc
)
4487 size
+= DWARF2_ADDR_SIZE
;
4506 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4509 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4514 case DW_OP_plus_uconst
:
4515 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4553 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4556 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4559 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4562 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4563 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
4566 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4568 case DW_OP_deref_size
:
4569 case DW_OP_xderef_size
:
4579 /* Return the size of a series of location descriptors. */
4581 static unsigned long
4583 register dw_loc_descr_ref loc
;
4585 register unsigned long size
= 0;
4587 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
4588 size
+= size_of_loc_descr (loc
);
4593 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4596 constant_size (value
)
4597 long unsigned value
;
4604 log
= floor_log2 (value
);
4607 log
= 1 << (floor_log2 (log
) + 1);
4612 /* Return the size of a DIE, as it is represented in the
4613 .debug_info section. */
4615 static unsigned long
4617 register dw_die_ref die
;
4619 register unsigned long size
= 0;
4620 register dw_attr_ref a
;
4622 size
+= size_of_uleb128 (die
->die_abbrev
);
4623 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4625 switch (AT_class (a
))
4627 case dw_val_class_addr
:
4628 size
+= DWARF2_ADDR_SIZE
;
4630 case dw_val_class_loc
:
4632 register unsigned long lsize
= size_of_locs (AT_loc (a
));
4635 size
+= constant_size (lsize
);
4639 case dw_val_class_const
:
4642 case dw_val_class_unsigned_const
:
4643 size
+= constant_size (AT_unsigned (a
));
4645 case dw_val_class_long_long
:
4646 size
+= 1 + 8; /* block */
4648 case dw_val_class_float
:
4649 size
+= 1 + a
->dw_attr_val
.v
.val_float
.length
* 4; /* block */
4651 case dw_val_class_flag
:
4654 case dw_val_class_die_ref
:
4655 size
+= DWARF_OFFSET_SIZE
;
4657 case dw_val_class_fde_ref
:
4658 size
+= DWARF_OFFSET_SIZE
;
4660 case dw_val_class_lbl_id
:
4661 size
+= DWARF2_ADDR_SIZE
;
4663 case dw_val_class_lbl_offset
:
4664 size
+= DWARF_OFFSET_SIZE
;
4666 case dw_val_class_str
:
4667 size
+= size_of_string (AT_string (a
));
4677 /* Size the debugging information associated with a given DIE.
4678 Visits the DIE's children recursively. Updates the global
4679 variable next_die_offset, on each time through. Uses the
4680 current value of next_die_offset to update the die_offset
4681 field in each DIE. */
4684 calc_die_sizes (die
)
4687 register dw_die_ref c
;
4688 die
->die_offset
= next_die_offset
;
4689 next_die_offset
+= size_of_die (die
);
4691 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4694 if (die
->die_child
!= NULL
)
4695 /* Count the null byte used to terminate sibling lists. */
4696 next_die_offset
+= 1;
4699 /* Return the size of the line information prolog generated for the
4700 compilation unit. */
4702 static unsigned long
4703 size_of_line_prolog ()
4705 register unsigned long size
;
4706 register unsigned long ft_index
;
4708 size
= DWARF_LINE_PROLOG_HEADER_SIZE
;
4710 /* Count the size of the table giving number of args for each
4712 size
+= DWARF_LINE_OPCODE_BASE
- 1;
4714 /* Include directory table is empty (at present). Count only the
4715 null byte used to terminate the table. */
4718 for (ft_index
= 1; ft_index
< file_table_in_use
; ++ft_index
)
4720 /* File name entry. */
4721 size
+= size_of_string (file_table
[ft_index
]);
4723 /* Include directory index. */
4724 size
+= size_of_uleb128 (0);
4726 /* Modification time. */
4727 size
+= size_of_uleb128 (0);
4729 /* File length in bytes. */
4730 size
+= size_of_uleb128 (0);
4733 /* Count the file table terminator. */
4738 /* Return the size of the .debug_pubnames table generated for the
4739 compilation unit. */
4741 static unsigned long
4744 register unsigned long size
;
4745 register unsigned i
;
4747 size
= DWARF_PUBNAMES_HEADER_SIZE
;
4748 for (i
= 0; i
< pubname_table_in_use
; ++i
)
4750 register pubname_ref p
= &pubname_table
[i
];
4751 size
+= DWARF_OFFSET_SIZE
+ size_of_string (p
->name
);
4754 size
+= DWARF_OFFSET_SIZE
;
4758 /* Return the size of the information in the .debug_aranges section. */
4760 static unsigned long
4763 register unsigned long size
;
4765 size
= DWARF_ARANGES_HEADER_SIZE
;
4767 /* Count the address/length pair for this compilation unit. */
4768 size
+= 2 * DWARF2_ADDR_SIZE
;
4769 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
4771 /* Count the two zero words used to terminated the address range table. */
4772 size
+= 2 * DWARF2_ADDR_SIZE
;
4776 /* Select the encoding of an attribute value. */
4778 static enum dwarf_form
4782 switch (a
->dw_attr_val
.val_class
)
4784 case dw_val_class_addr
:
4785 return DW_FORM_addr
;
4786 case dw_val_class_loc
:
4787 switch (constant_size (size_of_locs (AT_loc (a
))))
4790 return DW_FORM_block1
;
4792 return DW_FORM_block2
;
4796 case dw_val_class_const
:
4797 return DW_FORM_data4
;
4798 case dw_val_class_unsigned_const
:
4799 switch (constant_size (AT_unsigned (a
)))
4802 return DW_FORM_data1
;
4804 return DW_FORM_data2
;
4806 return DW_FORM_data4
;
4808 return DW_FORM_data8
;
4812 case dw_val_class_long_long
:
4813 return DW_FORM_block1
;
4814 case dw_val_class_float
:
4815 return DW_FORM_block1
;
4816 case dw_val_class_flag
:
4817 return DW_FORM_flag
;
4818 case dw_val_class_die_ref
:
4820 case dw_val_class_fde_ref
:
4821 return DW_FORM_data
;
4822 case dw_val_class_lbl_id
:
4823 return DW_FORM_addr
;
4824 case dw_val_class_lbl_offset
:
4825 return DW_FORM_data
;
4826 case dw_val_class_str
:
4827 return DW_FORM_string
;
4833 /* Output the encoding of an attribute value. */
4836 output_value_format (a
)
4839 enum dwarf_form form
= value_format (a
);
4841 output_uleb128 (form
);
4843 fprintf (asm_out_file
, " (%s)", dwarf_form_name (form
));
4845 fputc ('\n', asm_out_file
);
4848 /* Output the .debug_abbrev section which defines the DIE abbreviation
4852 output_abbrev_section ()
4854 unsigned long abbrev_id
;
4857 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
4859 register dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
4861 output_uleb128 (abbrev_id
);
4863 fprintf (asm_out_file
, " (abbrev code)");
4865 fputc ('\n', asm_out_file
);
4866 output_uleb128 (abbrev
->die_tag
);
4868 fprintf (asm_out_file
, " (TAG: %s)",
4869 dwarf_tag_name (abbrev
->die_tag
));
4871 fputc ('\n', asm_out_file
);
4872 fprintf (asm_out_file
, "\t%s\t0x%x", ASM_BYTE_OP
,
4873 abbrev
->die_child
!= NULL
? DW_children_yes
: DW_children_no
);
4876 fprintf (asm_out_file
, "\t%s %s",
4878 (abbrev
->die_child
!= NULL
4879 ? "DW_children_yes" : "DW_children_no"));
4881 fputc ('\n', asm_out_file
);
4883 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
4884 a_attr
= a_attr
->dw_attr_next
)
4886 output_uleb128 (a_attr
->dw_attr
);
4888 fprintf (asm_out_file
, " (%s)",
4889 dwarf_attr_name (a_attr
->dw_attr
));
4891 fputc ('\n', asm_out_file
);
4892 output_value_format (a_attr
);
4895 fprintf (asm_out_file
, "\t%s\t0,0\n", ASM_BYTE_OP
);
4898 /* Terminate the table. */
4899 fprintf (asm_out_file
, "\t%s\t0\n", ASM_BYTE_OP
);
4902 /* Output location description stack opcode's operands (if any). */
4905 output_loc_operands (loc
)
4906 register dw_loc_descr_ref loc
;
4908 register dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
4909 register dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
4911 switch (loc
->dw_loc_opc
)
4914 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
, val1
->v
.val_addr
);
4915 fputc ('\n', asm_out_file
);
4919 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_flag
);
4920 fputc ('\n', asm_out_file
);
4924 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, val1
->v
.val_int
);
4925 fputc ('\n', asm_out_file
);
4929 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, val1
->v
.val_int
);
4930 fputc ('\n', asm_out_file
);
4935 fputc ('\n', asm_out_file
);
4938 output_uleb128 (val1
->v
.val_unsigned
);
4939 fputc ('\n', asm_out_file
);
4942 output_sleb128 (val1
->v
.val_int
);
4943 fputc ('\n', asm_out_file
);
4946 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_int
);
4947 fputc ('\n', asm_out_file
);
4949 case DW_OP_plus_uconst
:
4950 output_uleb128 (val1
->v
.val_unsigned
);
4951 fputc ('\n', asm_out_file
);
4955 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, val1
->v
.val_int
);
4956 fputc ('\n', asm_out_file
);
4990 output_sleb128 (val1
->v
.val_int
);
4991 fputc ('\n', asm_out_file
);
4994 output_uleb128 (val1
->v
.val_unsigned
);
4995 fputc ('\n', asm_out_file
);
4998 output_sleb128 (val1
->v
.val_int
);
4999 fputc ('\n', asm_out_file
);
5002 output_uleb128 (val1
->v
.val_unsigned
);
5003 fputc ('\n', asm_out_file
);
5004 output_sleb128 (val2
->v
.val_int
);
5005 fputc ('\n', asm_out_file
);
5008 output_uleb128 (val1
->v
.val_unsigned
);
5009 fputc ('\n', asm_out_file
);
5011 case DW_OP_deref_size
:
5012 case DW_OP_xderef_size
:
5013 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_flag
);
5014 fputc ('\n', asm_out_file
);
5021 /* Output the DIE and its attributes. Called recursively to generate
5022 the definitions of each child DIE. */
5026 register dw_die_ref die
;
5028 register dw_attr_ref a
;
5029 register dw_die_ref c
;
5030 register unsigned long size
;
5031 register dw_loc_descr_ref loc
;
5033 output_uleb128 (die
->die_abbrev
);
5035 fprintf (asm_out_file
, " (DIE (0x%lx) %s)",
5036 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5038 fputc ('\n', asm_out_file
);
5040 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5042 switch (AT_class (a
))
5044 case dw_val_class_addr
:
5045 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
, AT_addr (a
));
5048 case dw_val_class_loc
:
5049 size
= size_of_locs (AT_loc (a
));
5051 /* Output the block length for this list of location operations. */
5052 switch (constant_size (size
))
5055 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, size
);
5058 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, size
);
5065 fprintf (asm_out_file
, "\t%s %s",
5066 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5068 fputc ('\n', asm_out_file
);
5069 for (loc
= AT_loc (a
); loc
!= NULL
; loc
= loc
->dw_loc_next
)
5071 /* Output the opcode. */
5072 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, loc
->dw_loc_opc
);
5074 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
,
5075 dwarf_stack_op_name (loc
->dw_loc_opc
));
5077 fputc ('\n', asm_out_file
);
5079 /* Output the operand(s) (if any). */
5080 output_loc_operands (loc
);
5084 case dw_val_class_const
:
5085 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, AT_int (a
));
5088 case dw_val_class_unsigned_const
:
5089 switch (constant_size (AT_unsigned (a
)))
5092 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, AT_unsigned (a
));
5095 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, AT_unsigned (a
));
5098 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, AT_unsigned (a
));
5101 ASM_OUTPUT_DWARF_DATA8 (asm_out_file
,
5102 a
->dw_attr_val
.v
.val_long_long
.hi
,
5103 a
->dw_attr_val
.v
.val_long_long
.low
);
5110 case dw_val_class_long_long
:
5111 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 8);
5113 fprintf (asm_out_file
, "\t%s %s",
5114 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5116 fputc ('\n', asm_out_file
);
5117 ASM_OUTPUT_DWARF_DATA8 (asm_out_file
,
5118 a
->dw_attr_val
.v
.val_long_long
.hi
,
5119 a
->dw_attr_val
.v
.val_long_long
.low
);
5122 fprintf (asm_out_file
,
5123 "\t%s long long constant", ASM_COMMENT_START
);
5125 fputc ('\n', asm_out_file
);
5128 case dw_val_class_float
:
5130 register unsigned int i
;
5131 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
5132 a
->dw_attr_val
.v
.val_float
.length
* 4);
5134 fprintf (asm_out_file
, "\t%s %s",
5135 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5137 fputc ('\n', asm_out_file
);
5138 for (i
= 0; i
< a
->dw_attr_val
.v
.val_float
.length
; ++i
)
5140 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
,
5141 a
->dw_attr_val
.v
.val_float
.array
[i
]);
5143 fprintf (asm_out_file
, "\t%s fp constant word %u",
5144 ASM_COMMENT_START
, i
);
5146 fputc ('\n', asm_out_file
);
5151 case dw_val_class_flag
:
5152 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, AT_flag (a
));
5155 case dw_val_class_die_ref
:
5156 ASM_OUTPUT_DWARF_DATA (asm_out_file
, AT_ref (a
)->die_offset
);
5159 case dw_val_class_fde_ref
:
5162 ASM_GENERATE_INTERNAL_LABEL
5163 (l1
, FDE_AFTER_SIZE_LABEL
, a
->dw_attr_val
.v
.val_fde_index
* 2);
5164 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, l1
);
5165 fprintf (asm_out_file
, " - %d", DWARF_OFFSET_SIZE
);
5169 case dw_val_class_lbl_id
:
5170 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, AT_lbl (a
));
5173 case dw_val_class_lbl_offset
:
5174 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, AT_lbl (a
));
5177 case dw_val_class_str
:
5179 ASM_OUTPUT_DWARF_STRING (asm_out_file
, AT_string (a
));
5181 ASM_OUTPUT_ASCII (asm_out_file
, AT_string (a
),
5182 (int) strlen (AT_string (a
)) + 1);
5189 if (AT_class (a
) != dw_val_class_loc
5190 && AT_class (a
) != dw_val_class_long_long
5191 && AT_class (a
) != dw_val_class_float
)
5194 fprintf (asm_out_file
, "\t%s %s",
5195 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5197 fputc ('\n', asm_out_file
);
5201 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5204 if (die
->die_child
!= NULL
)
5206 /* Add null byte to terminate sibling list. */
5207 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5209 fprintf (asm_out_file
, "\t%s end of children of DIE 0x%lx",
5210 ASM_COMMENT_START
, die
->die_offset
);
5212 fputc ('\n', asm_out_file
);
5216 /* Output the compilation unit that appears at the beginning of the
5217 .debug_info section, and precedes the DIE descriptions. */
5220 output_compilation_unit_header ()
5222 ASM_OUTPUT_DWARF_DATA (asm_out_file
, next_die_offset
- DWARF_OFFSET_SIZE
);
5224 fprintf (asm_out_file
, "\t%s Length of Compilation Unit Info.",
5227 fputc ('\n', asm_out_file
);
5228 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5230 fprintf (asm_out_file
, "\t%s DWARF version number", ASM_COMMENT_START
);
5232 fputc ('\n', asm_out_file
);
5233 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, abbrev_section_label
);
5235 fprintf (asm_out_file
, "\t%s Offset Into Abbrev. Section",
5238 fputc ('\n', asm_out_file
);
5239 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF2_ADDR_SIZE
);
5241 fprintf (asm_out_file
, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START
);
5243 fputc ('\n', asm_out_file
);
5246 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5247 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5248 argument list, and maybe the scope. */
5251 dwarf2_name (decl
, scope
)
5255 return (*decl_printable_name
) (decl
, scope
? 1 : 0);
5258 /* Add a new entry to .debug_pubnames if appropriate. */
5261 add_pubname (decl
, die
)
5267 if (! TREE_PUBLIC (decl
))
5270 if (pubname_table_in_use
== pubname_table_allocated
)
5272 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
5273 pubname_table
= (pubname_ref
) xrealloc
5274 (pubname_table
, pubname_table_allocated
* sizeof (pubname_entry
));
5277 p
= &pubname_table
[pubname_table_in_use
++];
5280 p
->name
= xstrdup (dwarf2_name (decl
, 1));
5283 /* Output the public names table used to speed up access to externally
5284 visible names. For now, only generate entries for externally
5285 visible procedures. */
5290 register unsigned i
;
5291 register unsigned long pubnames_length
= size_of_pubnames ();
5293 ASM_OUTPUT_DWARF_DATA (asm_out_file
, pubnames_length
);
5296 fprintf (asm_out_file
, "\t%s Length of Public Names Info.",
5299 fputc ('\n', asm_out_file
);
5300 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5303 fprintf (asm_out_file
, "\t%s DWARF Version", ASM_COMMENT_START
);
5305 fputc ('\n', asm_out_file
);
5306 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, debug_info_section_label
);
5308 fprintf (asm_out_file
, "\t%s Offset of Compilation Unit Info.",
5311 fputc ('\n', asm_out_file
);
5312 ASM_OUTPUT_DWARF_DATA (asm_out_file
, next_die_offset
);
5314 fprintf (asm_out_file
, "\t%s Compilation Unit Length", ASM_COMMENT_START
);
5316 fputc ('\n', asm_out_file
);
5317 for (i
= 0; i
< pubname_table_in_use
; ++i
)
5319 register pubname_ref pub
= &pubname_table
[i
];
5321 ASM_OUTPUT_DWARF_DATA (asm_out_file
, pub
->die
->die_offset
);
5323 fprintf (asm_out_file
, "\t%s DIE offset", ASM_COMMENT_START
);
5325 fputc ('\n', asm_out_file
);
5329 ASM_OUTPUT_DWARF_STRING (asm_out_file
, pub
->name
);
5330 fprintf (asm_out_file
, "%s external name", ASM_COMMENT_START
);
5334 ASM_OUTPUT_ASCII (asm_out_file
, pub
->name
,
5335 (int) strlen (pub
->name
) + 1);
5338 fputc ('\n', asm_out_file
);
5341 ASM_OUTPUT_DWARF_DATA (asm_out_file
, 0);
5342 fputc ('\n', asm_out_file
);
5345 /* Add a new entry to .debug_aranges if appropriate. */
5348 add_arange (decl
, die
)
5352 if (! DECL_SECTION_NAME (decl
))
5355 if (arange_table_in_use
== arange_table_allocated
)
5357 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
5359 = (arange_ref
) xrealloc (arange_table
,
5360 arange_table_allocated
* sizeof (dw_die_ref
));
5363 arange_table
[arange_table_in_use
++] = die
;
5366 /* Output the information that goes into the .debug_aranges table.
5367 Namely, define the beginning and ending address range of the
5368 text section generated for this compilation unit. */
5373 register unsigned i
;
5374 register unsigned long aranges_length
= size_of_aranges ();
5376 ASM_OUTPUT_DWARF_DATA (asm_out_file
, aranges_length
);
5378 fprintf (asm_out_file
, "\t%s Length of Address Ranges Info.",
5381 fputc ('\n', asm_out_file
);
5382 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5384 fprintf (asm_out_file
, "\t%s DWARF Version", ASM_COMMENT_START
);
5386 fputc ('\n', asm_out_file
);
5387 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, debug_info_section_label
);
5389 fprintf (asm_out_file
, "\t%s Offset of Compilation Unit Info.",
5392 fputc ('\n', asm_out_file
);
5393 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF2_ADDR_SIZE
);
5395 fprintf (asm_out_file
, "\t%s Size of Address", ASM_COMMENT_START
);
5397 fputc ('\n', asm_out_file
);
5398 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5400 fprintf (asm_out_file
, "\t%s Size of Segment Descriptor",
5403 fputc ('\n', asm_out_file
);
5405 /* We need to align to twice the pointer size here. */
5406 if (DWARF_ARANGES_PAD_SIZE
)
5408 /* Pad using a 2 bytes word so that padding is correct
5409 for any pointer size. */
5410 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, 0);
5411 for (i
= 2; i
< DWARF_ARANGES_PAD_SIZE
; i
+= 2)
5412 fprintf (asm_out_file
, ",0");
5414 fprintf (asm_out_file
, "\t%s Pad to %d byte boundary",
5415 ASM_COMMENT_START
, 2 * DWARF2_ADDR_SIZE
);
5418 fputc ('\n', asm_out_file
);
5419 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, text_section_label
);
5421 fprintf (asm_out_file
, "\t%s Address", ASM_COMMENT_START
);
5423 fputc ('\n', asm_out_file
);
5424 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
, text_end_label
,
5425 text_section_label
);
5427 fprintf (asm_out_file
, "%s Length", ASM_COMMENT_START
);
5429 fputc ('\n', asm_out_file
);
5430 for (i
= 0; i
< arange_table_in_use
; ++i
)
5432 dw_die_ref die
= arange_table
[i
];
5434 if (die
->die_tag
== DW_TAG_subprogram
)
5435 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, get_AT_low_pc (die
));
5438 /* A static variable; extract the symbol from DW_AT_location.
5439 Note that this code isn't currently hit, as we only emit
5440 aranges for functions (jason 9/23/99). */
5442 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
5443 dw_loc_descr_ref loc
;
5444 if (! a
|| AT_class (a
) != dw_val_class_loc
)
5448 if (loc
->dw_loc_opc
!= DW_OP_addr
)
5451 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
,
5452 loc
->dw_loc_oprnd1
.v
.val_addr
);
5456 fprintf (asm_out_file
, "\t%s Address", ASM_COMMENT_START
);
5458 fputc ('\n', asm_out_file
);
5459 if (die
->die_tag
== DW_TAG_subprogram
)
5460 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
, get_AT_hi_pc (die
),
5461 get_AT_low_pc (die
));
5463 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
,
5464 get_AT_unsigned (die
, DW_AT_byte_size
));
5467 fprintf (asm_out_file
, "%s Length", ASM_COMMENT_START
);
5469 fputc ('\n', asm_out_file
);
5472 /* Output the terminator words. */
5473 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
, 0);
5474 fputc ('\n', asm_out_file
);
5475 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
, 0);
5476 fputc ('\n', asm_out_file
);
5479 /* Output the source line number correspondence information. This
5480 information goes into the .debug_line section. */
5485 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5486 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5487 register unsigned opc
;
5488 register unsigned n_op_args
;
5489 register unsigned long ft_index
;
5490 register unsigned long lt_index
;
5491 register unsigned long current_line
;
5492 register long line_offset
;
5493 register long line_delta
;
5494 register unsigned long current_file
;
5495 register unsigned long function
;
5497 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, ".LTEND", ".LTSTART");
5499 fprintf (asm_out_file
, "\t%s Length of Source Line Info.",
5502 fputc ('\n', asm_out_file
);
5503 ASM_OUTPUT_LABEL (asm_out_file
, ".LTSTART");
5504 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5506 fprintf (asm_out_file
, "\t%s DWARF Version", ASM_COMMENT_START
);
5508 fputc ('\n', asm_out_file
);
5509 ASM_OUTPUT_DWARF_DATA (asm_out_file
, size_of_line_prolog ());
5511 fprintf (asm_out_file
, "\t%s Prolog Length", ASM_COMMENT_START
);
5513 fputc ('\n', asm_out_file
);
5514 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_LINE_MIN_INSTR_LENGTH
);
5516 fprintf (asm_out_file
, "\t%s Minimum Instruction Length",
5519 fputc ('\n', asm_out_file
);
5520 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_LINE_DEFAULT_IS_STMT_START
);
5522 fprintf (asm_out_file
, "\t%s Default is_stmt_start flag",
5525 fputc ('\n', asm_out_file
);
5526 fprintf (asm_out_file
, "\t%s\t%d", ASM_BYTE_OP
, DWARF_LINE_BASE
);
5528 fprintf (asm_out_file
, "\t%s Line Base Value (Special Opcodes)",
5531 fputc ('\n', asm_out_file
);
5532 fprintf (asm_out_file
, "\t%s\t%u", ASM_BYTE_OP
, DWARF_LINE_RANGE
);
5534 fprintf (asm_out_file
, "\t%s Line Range Value (Special Opcodes)",
5537 fputc ('\n', asm_out_file
);
5538 fprintf (asm_out_file
, "\t%s\t%u", ASM_BYTE_OP
, DWARF_LINE_OPCODE_BASE
);
5540 fprintf (asm_out_file
, "\t%s Special Opcode Base", ASM_COMMENT_START
);
5542 fputc ('\n', asm_out_file
);
5543 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; ++opc
)
5547 case DW_LNS_advance_pc
:
5548 case DW_LNS_advance_line
:
5549 case DW_LNS_set_file
:
5550 case DW_LNS_set_column
:
5551 case DW_LNS_fixed_advance_pc
:
5558 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, n_op_args
);
5560 fprintf (asm_out_file
, "\t%s opcode: 0x%x has %d args",
5561 ASM_COMMENT_START
, opc
, n_op_args
);
5562 fputc ('\n', asm_out_file
);
5566 fprintf (asm_out_file
, "%s Include Directory Table\n", ASM_COMMENT_START
);
5568 /* Include directory table is empty, at present */
5569 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5570 fputc ('\n', asm_out_file
);
5572 fprintf (asm_out_file
, "%s File Name Table\n", ASM_COMMENT_START
);
5574 for (ft_index
= 1; ft_index
< file_table_in_use
; ++ft_index
)
5578 ASM_OUTPUT_DWARF_STRING (asm_out_file
, file_table
[ft_index
]);
5579 fprintf (asm_out_file
, "%s File Entry: 0x%lx",
5580 ASM_COMMENT_START
, ft_index
);
5584 ASM_OUTPUT_ASCII (asm_out_file
,
5585 file_table
[ft_index
],
5586 (int) strlen (file_table
[ft_index
]) + 1);
5589 fputc ('\n', asm_out_file
);
5591 /* Include directory index */
5593 fputc ('\n', asm_out_file
);
5595 /* Modification time */
5597 fputc ('\n', asm_out_file
);
5599 /* File length in bytes */
5601 fputc ('\n', asm_out_file
);
5604 /* Terminate the file name table */
5605 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5606 fputc ('\n', asm_out_file
);
5608 /* We used to set the address register to the first location in the text
5609 section here, but that didn't accomplish anything since we already
5610 have a line note for the opening brace of the first function. */
5612 /* Generate the line number to PC correspondence table, encoded as
5613 a series of state machine operations. */
5616 strcpy (prev_line_label
, text_section_label
);
5617 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
5619 register dw_line_info_ref line_info
= &line_info_table
[lt_index
];
5622 /* Disable this optimization for now; GDB wants to see two line notes
5623 at the beginning of a function so it can find the end of the
5626 /* Don't emit anything for redundant notes. Just updating the
5627 address doesn't accomplish anything, because we already assume
5628 that anything after the last address is this line. */
5629 if (line_info
->dw_line_num
== current_line
5630 && line_info
->dw_file_num
== current_file
)
5634 /* Emit debug info for the address of the current line, choosing
5635 the encoding that uses the least amount of space. */
5636 /* ??? Unfortunately, we have little choice here currently, and must
5637 always use the most general form. Gcc does not know the address
5638 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5639 dwarf2 aware assemblers at this time, so we can't use any special
5640 pseudo ops that would allow the assembler to optimally encode this for
5641 us. Many ports do have length attributes which will give an upper
5642 bound on the address range. We could perhaps use length attributes
5643 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5644 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
5647 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5648 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
5650 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
5653 fputc ('\n', asm_out_file
);
5654 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
, prev_line_label
);
5655 fputc ('\n', asm_out_file
);
5659 /* This can handle any delta. This takes
5660 4+DWARF2_ADDR_SIZE bytes. */
5661 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5663 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
5665 fputc ('\n', asm_out_file
);
5666 output_uleb128 (1 + DWARF2_ADDR_SIZE
);
5667 fputc ('\n', asm_out_file
);
5668 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5669 fputc ('\n', asm_out_file
);
5670 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
5671 fputc ('\n', asm_out_file
);
5673 strcpy (prev_line_label
, line_label
);
5675 /* Emit debug info for the source file of the current line, if
5676 different from the previous line. */
5677 if (line_info
->dw_file_num
!= current_file
)
5679 current_file
= line_info
->dw_file_num
;
5680 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_set_file
);
5682 fprintf (asm_out_file
, "\t%s DW_LNS_set_file", ASM_COMMENT_START
);
5684 fputc ('\n', asm_out_file
);
5685 output_uleb128 (current_file
);
5687 fprintf (asm_out_file
, " (\"%s\")", file_table
[current_file
]);
5689 fputc ('\n', asm_out_file
);
5692 /* Emit debug info for the current line number, choosing the encoding
5693 that uses the least amount of space. */
5694 if (line_info
->dw_line_num
!= current_line
)
5696 line_offset
= line_info
->dw_line_num
- current_line
;
5697 line_delta
= line_offset
- DWARF_LINE_BASE
;
5698 current_line
= line_info
->dw_line_num
;
5699 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
5701 /* This can handle deltas from -10 to 234, using the current
5702 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5704 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
5705 DWARF_LINE_OPCODE_BASE
+ line_delta
);
5707 fprintf (asm_out_file
,
5708 "\t%s line %ld", ASM_COMMENT_START
, current_line
);
5710 fputc ('\n', asm_out_file
);
5714 /* This can handle any delta. This takes at least 4 bytes,
5715 depending on the value being encoded. */
5716 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_advance_line
);
5718 fprintf (asm_out_file
, "\t%s advance to line %ld",
5719 ASM_COMMENT_START
, current_line
);
5721 fputc ('\n', asm_out_file
);
5722 output_sleb128 (line_offset
);
5723 fputc ('\n', asm_out_file
);
5724 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
5726 fprintf (asm_out_file
, "\t%s DW_LNS_copy", ASM_COMMENT_START
);
5727 fputc ('\n', asm_out_file
);
5732 /* We still need to start a new row, so output a copy insn. */
5733 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
5735 fprintf (asm_out_file
, "\t%s DW_LNS_copy", ASM_COMMENT_START
);
5736 fputc ('\n', asm_out_file
);
5740 /* Emit debug info for the address of the end of the function. */
5743 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
5745 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
5748 fputc ('\n', asm_out_file
);
5749 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, text_end_label
, prev_line_label
);
5750 fputc ('\n', asm_out_file
);
5754 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5756 fprintf (asm_out_file
, "\t%s DW_LNE_set_address", ASM_COMMENT_START
);
5757 fputc ('\n', asm_out_file
);
5758 output_uleb128 (1 + DWARF2_ADDR_SIZE
);
5759 fputc ('\n', asm_out_file
);
5760 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5761 fputc ('\n', asm_out_file
);
5762 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, text_end_label
);
5763 fputc ('\n', asm_out_file
);
5766 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5768 fprintf (asm_out_file
, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START
);
5770 fputc ('\n', asm_out_file
);
5772 fputc ('\n', asm_out_file
);
5773 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_end_sequence
);
5774 fputc ('\n', asm_out_file
);
5779 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
; )
5781 register dw_separate_line_info_ref line_info
5782 = &separate_line_info_table
[lt_index
];
5785 /* Don't emit anything for redundant notes. */
5786 if (line_info
->dw_line_num
== current_line
5787 && line_info
->dw_file_num
== current_file
5788 && line_info
->function
== function
)
5792 /* Emit debug info for the address of the current line. If this is
5793 a new function, or the first line of a function, then we need
5794 to handle it differently. */
5795 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
5797 if (function
!= line_info
->function
)
5799 function
= line_info
->function
;
5801 /* Set the address register to the first line in the function */
5802 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5804 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
5807 fputc ('\n', asm_out_file
);
5808 output_uleb128 (1 + DWARF2_ADDR_SIZE
);
5809 fputc ('\n', asm_out_file
);
5810 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5811 fputc ('\n', asm_out_file
);
5812 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
5813 fputc ('\n', asm_out_file
);
5817 /* ??? See the DW_LNS_advance_pc comment above. */
5820 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
5822 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
5825 fputc ('\n', asm_out_file
);
5826 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
,
5828 fputc ('\n', asm_out_file
);
5832 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5834 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
5836 fputc ('\n', asm_out_file
);
5837 output_uleb128 (1 + DWARF2_ADDR_SIZE
);
5838 fputc ('\n', asm_out_file
);
5839 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5840 fputc ('\n', asm_out_file
);
5841 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
5842 fputc ('\n', asm_out_file
);
5845 strcpy (prev_line_label
, line_label
);
5847 /* Emit debug info for the source file of the current line, if
5848 different from the previous line. */
5849 if (line_info
->dw_file_num
!= current_file
)
5851 current_file
= line_info
->dw_file_num
;
5852 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_set_file
);
5854 fprintf (asm_out_file
, "\t%s DW_LNS_set_file", ASM_COMMENT_START
);
5856 fputc ('\n', asm_out_file
);
5857 output_uleb128 (current_file
);
5859 fprintf (asm_out_file
, " (\"%s\")", file_table
[current_file
]);
5861 fputc ('\n', asm_out_file
);
5864 /* Emit debug info for the current line number, choosing the encoding
5865 that uses the least amount of space. */
5866 if (line_info
->dw_line_num
!= current_line
)
5868 line_offset
= line_info
->dw_line_num
- current_line
;
5869 line_delta
= line_offset
- DWARF_LINE_BASE
;
5870 current_line
= line_info
->dw_line_num
;
5871 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
5873 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
5874 DWARF_LINE_OPCODE_BASE
+ line_delta
);
5876 fprintf (asm_out_file
,
5877 "\t%s line %ld", ASM_COMMENT_START
, current_line
);
5879 fputc ('\n', asm_out_file
);
5883 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_advance_line
);
5885 fprintf (asm_out_file
, "\t%s advance to line %ld",
5886 ASM_COMMENT_START
, current_line
);
5888 fputc ('\n', asm_out_file
);
5889 output_sleb128 (line_offset
);
5890 fputc ('\n', asm_out_file
);
5891 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
5893 fprintf (asm_out_file
, "\t%s DW_LNS_copy", ASM_COMMENT_START
);
5894 fputc ('\n', asm_out_file
);
5899 /* We still need to start a new row, so output a copy insn. */
5900 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
5902 fprintf (asm_out_file
, "\t%s DW_LNS_copy", ASM_COMMENT_START
);
5903 fputc ('\n', asm_out_file
);
5911 /* If we're done with a function, end its sequence. */
5912 if (lt_index
== separate_line_info_table_in_use
5913 || separate_line_info_table
[lt_index
].function
!= function
)
5918 /* Emit debug info for the address of the end of the function. */
5919 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
5922 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
5924 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
5927 fputc ('\n', asm_out_file
);
5928 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
,
5930 fputc ('\n', asm_out_file
);
5934 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5936 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
5938 fputc ('\n', asm_out_file
);
5939 output_uleb128 (1 + DWARF2_ADDR_SIZE
);
5940 fputc ('\n', asm_out_file
);
5941 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5942 fputc ('\n', asm_out_file
);
5943 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
5944 fputc ('\n', asm_out_file
);
5947 /* Output the marker for the end of this sequence. */
5948 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5950 fprintf (asm_out_file
, "\t%s DW_LNE_end_sequence",
5953 fputc ('\n', asm_out_file
);
5955 fputc ('\n', asm_out_file
);
5956 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_end_sequence
);
5957 fputc ('\n', asm_out_file
);
5961 /* Output the marker for the end of the line number info. */
5962 ASM_OUTPUT_LABEL (asm_out_file
, ".LTEND");
5965 /* Given a pointer to a tree node for some base type, return a pointer to
5966 a DIE that describes the given type.
5968 This routine must only be called for GCC type nodes that correspond to
5969 Dwarf base (fundamental) types. */
5972 base_type_die (type
)
5975 register dw_die_ref base_type_result
;
5976 register const char *type_name
;
5977 register enum dwarf_type encoding
;
5978 register tree name
= TYPE_NAME (type
);
5980 if (TREE_CODE (type
) == ERROR_MARK
5981 || TREE_CODE (type
) == VOID_TYPE
)
5986 if (TREE_CODE (name
) == TYPE_DECL
)
5987 name
= DECL_NAME (name
);
5989 type_name
= IDENTIFIER_POINTER (name
);
5992 type_name
= "__unknown__";
5994 switch (TREE_CODE (type
))
5997 /* Carefully distinguish the C character types, without messing
5998 up if the language is not C. Note that we check only for the names
5999 that contain spaces; other names might occur by coincidence in other
6001 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
6002 && (type
== char_type_node
6003 || ! strcmp (type_name
, "signed char")
6004 || ! strcmp (type_name
, "unsigned char"))))
6006 if (TREE_UNSIGNED (type
))
6007 encoding
= DW_ATE_unsigned
;
6009 encoding
= DW_ATE_signed
;
6012 /* else fall through */
6015 /* GNU Pascal/Ada CHAR type. Not used in C. */
6016 if (TREE_UNSIGNED (type
))
6017 encoding
= DW_ATE_unsigned_char
;
6019 encoding
= DW_ATE_signed_char
;
6023 encoding
= DW_ATE_float
;
6026 /* Dwarf2 doesn't know anything about complex ints, so use
6027 a user defined type for it. */
6029 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
6030 encoding
= DW_ATE_complex_float
;
6032 encoding
= DW_ATE_lo_user
;
6036 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6037 encoding
= DW_ATE_boolean
;
6041 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6044 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
);
6045 if (demangle_name_func
)
6046 type_name
= (*demangle_name_func
) (type_name
);
6048 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
6049 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
6050 int_size_in_bytes (type
));
6051 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
6053 return base_type_result
;
6056 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6057 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6058 a given type is generally the same as the given type, except that if the
6059 given type is a pointer or reference type, then the root type of the given
6060 type is the root type of the "basis" type for the pointer or reference
6061 type. (This definition of the "root" type is recursive.) Also, the root
6062 type of a `const' qualified type or a `volatile' qualified type is the
6063 root type of the given type without the qualifiers. */
6069 if (TREE_CODE (type
) == ERROR_MARK
)
6070 return error_mark_node
;
6072 switch (TREE_CODE (type
))
6075 return error_mark_node
;
6078 case REFERENCE_TYPE
:
6079 return type_main_variant (root_type (TREE_TYPE (type
)));
6082 return type_main_variant (type
);
6086 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6087 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6093 switch (TREE_CODE (type
))
6108 case QUAL_UNION_TYPE
:
6113 case REFERENCE_TYPE
:
6126 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6127 entry that chains various modifiers in front of the given type. */
6130 modified_type_die (type
, is_const_type
, is_volatile_type
, context_die
)
6132 register int is_const_type
;
6133 register int is_volatile_type
;
6134 register dw_die_ref context_die
;
6136 register enum tree_code code
= TREE_CODE (type
);
6137 register dw_die_ref mod_type_die
= NULL
;
6138 register dw_die_ref sub_die
= NULL
;
6139 register tree item_type
= NULL
;
6141 if (code
!= ERROR_MARK
)
6143 type
= build_type_variant (type
, is_const_type
, is_volatile_type
);
6145 mod_type_die
= lookup_type_die (type
);
6147 return mod_type_die
;
6149 /* Handle C typedef types. */
6150 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
6151 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
6153 tree dtype
= TREE_TYPE (TYPE_NAME (type
));
6156 /* For a named type, use the typedef. */
6157 gen_type_die (type
, context_die
);
6158 mod_type_die
= lookup_type_die (type
);
6161 else if (is_const_type
< TYPE_READONLY (dtype
)
6162 || is_volatile_type
< TYPE_VOLATILE (dtype
))
6163 /* cv-unqualified version of named type. Just use the unnamed
6164 type to which it refers. */
6166 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)),
6167 is_const_type
, is_volatile_type
,
6169 /* Else cv-qualified version of named type; fall through. */
6174 else if (is_const_type
)
6176 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
);
6177 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
6179 else if (is_volatile_type
)
6181 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
);
6182 sub_die
= modified_type_die (type
, 0, 0, context_die
);
6184 else if (code
== POINTER_TYPE
)
6186 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
);
6187 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
6189 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
6191 item_type
= TREE_TYPE (type
);
6193 else if (code
== REFERENCE_TYPE
)
6195 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
);
6196 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
6198 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
6200 item_type
= TREE_TYPE (type
);
6202 else if (is_base_type (type
))
6203 mod_type_die
= base_type_die (type
);
6206 gen_type_die (type
, context_die
);
6208 /* We have to get the type_main_variant here (and pass that to the
6209 `lookup_type_die' routine) because the ..._TYPE node we have
6210 might simply be a *copy* of some original type node (where the
6211 copy was created to help us keep track of typedef names) and
6212 that copy might have a different TYPE_UID from the original
6214 mod_type_die
= lookup_type_die (type_main_variant (type
));
6215 if (mod_type_die
== NULL
)
6220 equate_type_number_to_die (type
, mod_type_die
);
6222 /* We must do this after the equate_type_number_to_die call, in case
6223 this is a recursive type. This ensures that the modified_type_die
6224 recursion will terminate even if the type is recursive. Recursive
6225 types are possible in Ada. */
6226 sub_die
= modified_type_die (item_type
,
6227 TYPE_READONLY (item_type
),
6228 TYPE_VOLATILE (item_type
),
6231 if (sub_die
!= NULL
)
6232 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
6234 return mod_type_die
;
6237 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6238 an enumerated type. */
6244 return TREE_CODE (type
) == ENUMERAL_TYPE
;
6247 /* Return a location descriptor that designates a machine register. */
6249 static dw_loc_descr_ref
6250 reg_loc_descriptor (rtl
)
6253 register dw_loc_descr_ref loc_result
= NULL
;
6254 register unsigned reg
= reg_number (rtl
);
6257 loc_result
= new_loc_descr (DW_OP_reg0
+ reg
, 0, 0);
6259 loc_result
= new_loc_descr (DW_OP_regx
, reg
, 0);
6264 /* Return a location descriptor that designates a base+offset location. */
6266 static dw_loc_descr_ref
6267 based_loc_descr (reg
, offset
)
6271 register dw_loc_descr_ref loc_result
;
6272 /* For the "frame base", we use the frame pointer or stack pointer
6273 registers, since the RTL for local variables is relative to one of
6275 register unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
6276 ? HARD_FRAME_POINTER_REGNUM
6277 : STACK_POINTER_REGNUM
);
6280 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
6282 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
6284 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
6289 /* Return true if this RTL expression describes a base+offset calculation. */
6295 return (GET_CODE (rtl
) == PLUS
6296 && ((GET_CODE (XEXP (rtl
, 0)) == REG
6297 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
6300 /* The following routine converts the RTL for a variable or parameter
6301 (resident in memory) into an equivalent Dwarf representation of a
6302 mechanism for getting the address of that same variable onto the top of a
6303 hypothetical "address evaluation" stack.
6305 When creating memory location descriptors, we are effectively transforming
6306 the RTL for a memory-resident object into its Dwarf postfix expression
6307 equivalent. This routine recursively descends an RTL tree, turning
6308 it into Dwarf postfix code as it goes.
6310 MODE is the mode of the memory reference, needed to handle some
6311 autoincrement addressing modes. */
6313 static dw_loc_descr_ref
6314 mem_loc_descriptor (rtl
, mode
)
6316 enum machine_mode mode
;
6318 dw_loc_descr_ref mem_loc_result
= NULL
;
6319 /* Note that for a dynamically sized array, the location we will generate a
6320 description of here will be the lowest numbered location which is
6321 actually within the array. That's *not* necessarily the same as the
6322 zeroth element of the array. */
6324 #ifdef ASM_SIMPLIFY_DWARF_ADDR
6325 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
6328 switch (GET_CODE (rtl
))
6332 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
6333 just fall into the SUBREG code. */
6335 /* ... fall through ... */
6338 /* The case of a subreg may arise when we have a local (register)
6339 variable or a formal (register) parameter which doesn't quite fill
6340 up an entire register. For now, just assume that it is
6341 legitimate to make the Dwarf info refer to the whole register which
6342 contains the given subreg. */
6343 rtl
= XEXP (rtl
, 0);
6345 /* ... fall through ... */
6348 /* Whenever a register number forms a part of the description of the
6349 method for calculating the (dynamic) address of a memory resident
6350 object, DWARF rules require the register number be referred to as
6351 a "base register". This distinction is not based in any way upon
6352 what category of register the hardware believes the given register
6353 belongs to. This is strictly DWARF terminology we're dealing with
6354 here. Note that in cases where the location of a memory-resident
6355 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6356 OP_CONST (0)) the actual DWARF location descriptor that we generate
6357 may just be OP_BASEREG (basereg). This may look deceptively like
6358 the object in question was allocated to a register (rather than in
6359 memory) so DWARF consumers need to be aware of the subtle
6360 distinction between OP_REG and OP_BASEREG. */
6361 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
6365 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
6366 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
6370 /* Some ports can transform a symbol ref into a label ref, because
6371 the symbol ref is too far away and has to be dumped into a constant
6375 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
6376 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
6377 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= save_rtx (rtl
);
6382 /* Turn these into a PLUS expression and fall into the PLUS code
6384 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
6385 GEN_INT (GET_CODE (rtl
) == PRE_INC
6386 ? GET_MODE_UNIT_SIZE (mode
)
6387 : - GET_MODE_UNIT_SIZE (mode
)));
6389 /* ... fall through ... */
6392 if (is_based_loc (rtl
))
6393 mem_loc_result
= based_loc_descr (reg_number (XEXP (rtl
, 0)),
6394 INTVAL (XEXP (rtl
, 1)));
6397 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 0),
6399 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 1),
6401 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_plus
, 0, 0));
6406 /* If a pseudo-reg is optimized away, it is possible for it to
6407 be replaced with a MEM containing a multiply. */
6408 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 0), mode
));
6409 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 1), mode
));
6410 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
6414 mem_loc_result
= new_loc_descr (DW_OP_constu
, INTVAL (rtl
), 0);
6421 return mem_loc_result
;
6424 /* Return a descriptor that describes the concatenation of two locations.
6425 This is typically a complex variable. */
6427 static dw_loc_descr_ref
6428 concat_loc_descriptor (x0
, x1
)
6429 register rtx x0
, x1
;
6431 dw_loc_descr_ref cc_loc_result
= NULL
;
6433 if (!is_pseudo_reg (x0
)
6434 && (GET_CODE (x0
) != MEM
|| !is_pseudo_reg (XEXP (x0
, 0))))
6435 add_loc_descr (&cc_loc_result
, loc_descriptor (x0
));
6436 add_loc_descr (&cc_loc_result
,
6437 new_loc_descr (DW_OP_piece
, GET_MODE_SIZE (GET_MODE (x0
)), 0));
6439 if (!is_pseudo_reg (x1
)
6440 && (GET_CODE (x1
) != MEM
|| !is_pseudo_reg (XEXP (x1
, 0))))
6441 add_loc_descr (&cc_loc_result
, loc_descriptor (x1
));
6442 add_loc_descr (&cc_loc_result
,
6443 new_loc_descr (DW_OP_piece
, GET_MODE_SIZE (GET_MODE (x1
)), 0));
6445 return cc_loc_result
;
6448 /* Output a proper Dwarf location descriptor for a variable or parameter
6449 which is either allocated in a register or in a memory location. For a
6450 register, we just generate an OP_REG and the register number. For a
6451 memory location we provide a Dwarf postfix expression describing how to
6452 generate the (dynamic) address of the object onto the address stack. */
6454 static dw_loc_descr_ref
6455 loc_descriptor (rtl
)
6458 dw_loc_descr_ref loc_result
= NULL
;
6459 switch (GET_CODE (rtl
))
6462 /* The case of a subreg may arise when we have a local (register)
6463 variable or a formal (register) parameter which doesn't quite fill
6464 up an entire register. For now, just assume that it is
6465 legitimate to make the Dwarf info refer to the whole register which
6466 contains the given subreg. */
6467 rtl
= XEXP (rtl
, 0);
6469 /* ... fall through ... */
6472 loc_result
= reg_loc_descriptor (rtl
);
6476 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
6480 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
6490 /* Given a value, round it up to the lowest multiple of `boundary'
6491 which is not less than the value itself. */
6493 static inline HOST_WIDE_INT
6494 ceiling (value
, boundary
)
6495 HOST_WIDE_INT value
;
6496 unsigned int boundary
;
6498 return (((value
+ boundary
- 1) / boundary
) * boundary
);
6501 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6502 pointer to the declared type for the relevant field variable, or return
6503 `integer_type_node' if the given node turns out to be an
6512 if (TREE_CODE (decl
) == ERROR_MARK
)
6513 return integer_type_node
;
6515 type
= DECL_BIT_FIELD_TYPE (decl
);
6516 if (type
== NULL_TREE
)
6517 type
= TREE_TYPE (decl
);
6522 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6523 node, return the alignment in bits for the type, or else return
6524 BITS_PER_WORD if the node actually turns out to be an
6527 static inline unsigned
6528 simple_type_align_in_bits (type
)
6531 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
6534 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6535 node, return the size in bits for the type if it is a constant, or else
6536 return the alignment for the type if the type's size is not constant, or
6537 else return BITS_PER_WORD if the type actually turns out to be an
6540 static inline unsigned HOST_WIDE_INT
6541 simple_type_size_in_bits (type
)
6544 if (TREE_CODE (type
) == ERROR_MARK
)
6545 return BITS_PER_WORD
;
6548 register tree type_size_tree
= TYPE_SIZE (type
);
6550 if (! host_integerp (type_size_tree
, 1))
6551 return TYPE_ALIGN (type
);
6553 return tree_low_cst (type_size_tree
, 1);
6557 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6558 return the byte offset of the lowest addressed byte of the "containing
6559 object" for the given FIELD_DECL, or return 0 if we are unable to
6560 determine what that offset is, either because the argument turns out to
6561 be a pointer to an ERROR_MARK node, or because the offset is actually
6562 variable. (We can't handle the latter case just yet). */
6564 static HOST_WIDE_INT
6565 field_byte_offset (decl
)
6568 unsigned int type_align_in_bytes
;
6569 unsigned int type_align_in_bits
;
6570 unsigned HOST_WIDE_INT type_size_in_bits
;
6571 HOST_WIDE_INT object_offset_in_align_units
;
6572 HOST_WIDE_INT object_offset_in_bits
;
6573 HOST_WIDE_INT object_offset_in_bytes
;
6575 tree field_size_tree
;
6576 HOST_WIDE_INT bitpos_int
;
6577 HOST_WIDE_INT deepest_bitpos
;
6578 unsigned HOST_WIDE_INT field_size_in_bits
;
6580 if (TREE_CODE (decl
) == ERROR_MARK
)
6583 if (TREE_CODE (decl
) != FIELD_DECL
)
6586 type
= field_type (decl
);
6587 field_size_tree
= DECL_SIZE (decl
);
6589 /* If there was an error, the size could be zero. */
6590 if (! field_size_tree
)
6598 /* We cannot yet cope with fields whose positions are variable, so
6599 for now, when we see such things, we simply return 0. Someday, we may
6600 be able to handle such cases, but it will be damn difficult. */
6601 if (! host_integerp (bit_position (decl
), 0))
6604 bitpos_int
= int_bit_position (decl
);
6606 /* If we don't know the size of the field, pretend it's a full word. */
6607 if (host_integerp (field_size_tree
, 1))
6608 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
6610 field_size_in_bits
= BITS_PER_WORD
;
6612 type_size_in_bits
= simple_type_size_in_bits (type
);
6613 type_align_in_bits
= simple_type_align_in_bits (type
);
6614 type_align_in_bytes
= type_align_in_bits
/ BITS_PER_UNIT
;
6616 /* Note that the GCC front-end doesn't make any attempt to keep track of
6617 the starting bit offset (relative to the start of the containing
6618 structure type) of the hypothetical "containing object" for a bit-
6619 field. Thus, when computing the byte offset value for the start of the
6620 "containing object" of a bit-field, we must deduce this information on
6621 our own. This can be rather tricky to do in some cases. For example,
6622 handling the following structure type definition when compiling for an
6623 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6626 struct S { int field1; long long field2:31; };
6628 Fortunately, there is a simple rule-of-thumb which can be
6629 used in such cases. When compiling for an i386/i486, GCC will allocate
6630 8 bytes for the structure shown above. It decides to do this based upon
6631 one simple rule for bit-field allocation. Quite simply, GCC allocates
6632 each "containing object" for each bit-field at the first (i.e. lowest
6633 addressed) legitimate alignment boundary (based upon the required
6634 minimum alignment for the declared type of the field) which it can
6635 possibly use, subject to the condition that there is still enough
6636 available space remaining in the containing object (when allocated at
6637 the selected point) to fully accommodate all of the bits of the
6638 bit-field itself. This simple rule makes it obvious why GCC allocates
6639 8 bytes for each object of the structure type shown above. When looking
6640 for a place to allocate the "containing object" for `field2', the
6641 compiler simply tries to allocate a 64-bit "containing object" at each
6642 successive 32-bit boundary (starting at zero) until it finds a place to
6643 allocate that 64- bit field such that at least 31 contiguous (and
6644 previously unallocated) bits remain within that selected 64 bit field.
6645 (As it turns out, for the example above, the compiler finds that it is
6646 OK to allocate the "containing object" 64-bit field at bit-offset zero
6647 within the structure type.) Here we attempt to work backwards from the
6648 limited set of facts we're given, and we try to deduce from those facts,
6649 where GCC must have believed that the containing object started (within
6650 the structure type). The value we deduce is then used (by the callers of
6651 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6652 for fields (both bit-fields and, in the case of DW_AT_location, regular
6655 /* Figure out the bit-distance from the start of the structure to the
6656 "deepest" bit of the bit-field. */
6657 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
6659 /* This is the tricky part. Use some fancy footwork to deduce where the
6660 lowest addressed bit of the containing object must be. */
6661 object_offset_in_bits
6662 = ceiling (deepest_bitpos
, type_align_in_bits
) - type_size_in_bits
;
6664 /* Compute the offset of the containing object in "alignment units". */
6665 object_offset_in_align_units
= object_offset_in_bits
/ type_align_in_bits
;
6667 /* Compute the offset of the containing object in bytes. */
6668 object_offset_in_bytes
= object_offset_in_align_units
* type_align_in_bytes
;
6670 return object_offset_in_bytes
;
6673 /* The following routines define various Dwarf attributes and any data
6674 associated with them. */
6676 /* Add a location description attribute value to a DIE.
6678 This emits location attributes suitable for whole variables and
6679 whole parameters. Note that the location attributes for struct fields are
6680 generated by the routine `data_member_location_attribute' below. */
6683 add_AT_location_description (die
, attr_kind
, rtl
)
6685 enum dwarf_attribute attr_kind
;
6688 /* Handle a special case. If we are about to output a location descriptor
6689 for a variable or parameter which has been optimized out of existence,
6690 don't do that. A variable which has been optimized out
6691 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6692 Currently, in some rare cases, variables can have DECL_RTL values which
6693 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6694 elsewhere in the compiler. We treat such cases as if the variable(s) in
6695 question had been optimized out of existence. */
6697 if (is_pseudo_reg (rtl
)
6698 || (GET_CODE (rtl
) == MEM
6699 && is_pseudo_reg (XEXP (rtl
, 0)))
6700 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
6701 references the internal argument pointer (a pseudo) in a function
6702 where all references to the internal argument pointer were
6703 eliminated via the optimizers. */
6704 || (GET_CODE (rtl
) == MEM
6705 && GET_CODE (XEXP (rtl
, 0)) == PLUS
6706 && is_pseudo_reg (XEXP (XEXP (rtl
, 0), 0)))
6707 || (GET_CODE (rtl
) == CONCAT
6708 && is_pseudo_reg (XEXP (rtl
, 0))
6709 && is_pseudo_reg (XEXP (rtl
, 1))))
6712 add_AT_loc (die
, attr_kind
, loc_descriptor (rtl
));
6715 /* Attach the specialized form of location attribute used for data
6716 members of struct and union types. In the special case of a
6717 FIELD_DECL node which represents a bit-field, the "offset" part
6718 of this special location descriptor must indicate the distance
6719 in bytes from the lowest-addressed byte of the containing struct
6720 or union type to the lowest-addressed byte of the "containing
6721 object" for the bit-field. (See the `field_byte_offset' function
6722 above).. For any given bit-field, the "containing object" is a
6723 hypothetical object (of some integral or enum type) within which
6724 the given bit-field lives. The type of this hypothetical
6725 "containing object" is always the same as the declared type of
6726 the individual bit-field itself (for GCC anyway... the DWARF
6727 spec doesn't actually mandate this). Note that it is the size
6728 (in bytes) of the hypothetical "containing object" which will
6729 be given in the DW_AT_byte_size attribute for this bit-field.
6730 (See the `byte_size_attribute' function below.) It is also used
6731 when calculating the value of the DW_AT_bit_offset attribute.
6732 (See the `bit_offset_attribute' function below). */
6735 add_data_member_location_attribute (die
, decl
)
6736 register dw_die_ref die
;
6739 register unsigned long offset
;
6740 register dw_loc_descr_ref loc_descr
;
6741 register enum dwarf_location_atom op
;
6743 if (TREE_CODE (decl
) == TREE_VEC
)
6744 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
6746 offset
= field_byte_offset (decl
);
6748 /* The DWARF2 standard says that we should assume that the structure address
6749 is already on the stack, so we can specify a structure field address
6750 by using DW_OP_plus_uconst. */
6752 #ifdef MIPS_DEBUGGING_INFO
6753 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6754 correctly. It works only if we leave the offset on the stack. */
6757 op
= DW_OP_plus_uconst
;
6760 loc_descr
= new_loc_descr (op
, offset
, 0);
6761 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
6764 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6765 does not have a "location" either in memory or in a register. These
6766 things can arise in GNU C when a constant is passed as an actual parameter
6767 to an inlined function. They can also arise in C++ where declared
6768 constants do not necessarily get memory "homes". */
6771 add_const_value_attribute (die
, rtl
)
6772 register dw_die_ref die
;
6775 switch (GET_CODE (rtl
))
6778 /* Note that a CONST_INT rtx could represent either an integer or a
6779 floating-point constant. A CONST_INT is used whenever the constant
6780 will fit into a single word. In all such cases, the original mode
6781 of the constant value is wiped out, and the CONST_INT rtx is
6782 assigned VOIDmode. */
6783 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned) INTVAL (rtl
));
6787 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6788 floating-point constant. A CONST_DOUBLE is used whenever the
6789 constant requires more than one word in order to be adequately
6790 represented. We output CONST_DOUBLEs as blocks. */
6792 register enum machine_mode mode
= GET_MODE (rtl
);
6794 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
6796 register unsigned length
= GET_MODE_SIZE (mode
) / sizeof (long);
6800 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
6804 REAL_VALUE_TO_TARGET_SINGLE (rv
, array
[0]);
6808 REAL_VALUE_TO_TARGET_DOUBLE (rv
, array
);
6813 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv
, array
);
6820 add_AT_float (die
, DW_AT_const_value
, length
, array
);
6823 add_AT_long_long (die
, DW_AT_const_value
,
6824 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
6829 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
6835 add_AT_addr (die
, DW_AT_const_value
, save_rtx (rtl
));
6839 /* In cases where an inlined instance of an inline function is passed
6840 the address of an `auto' variable (which is local to the caller) we
6841 can get a situation where the DECL_RTL of the artificial local
6842 variable (for the inlining) which acts as a stand-in for the
6843 corresponding formal parameter (of the inline function) will look
6844 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6845 exactly a compile-time constant expression, but it isn't the address
6846 of the (artificial) local variable either. Rather, it represents the
6847 *value* which the artificial local variable always has during its
6848 lifetime. We currently have no way to represent such quasi-constant
6849 values in Dwarf, so for now we just punt and generate nothing. */
6853 /* No other kinds of rtx should be possible here. */
6859 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6860 data attribute for a variable or a parameter. We generate the
6861 DW_AT_const_value attribute only in those cases where the given variable
6862 or parameter does not have a true "location" either in memory or in a
6863 register. This can happen (for example) when a constant is passed as an
6864 actual argument in a call to an inline function. (It's possible that
6865 these things can crop up in other ways also.) Note that one type of
6866 constant value which can be passed into an inlined function is a constant
6867 pointer. This can happen for example if an actual argument in an inlined
6868 function call evaluates to a compile-time constant address. */
6871 add_location_or_const_value_attribute (die
, decl
)
6872 register dw_die_ref die
;
6876 register tree declared_type
;
6877 register tree passed_type
;
6879 if (TREE_CODE (decl
) == ERROR_MARK
)
6882 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
)
6885 /* Here we have to decide where we are going to say the parameter "lives"
6886 (as far as the debugger is concerned). We only have a couple of
6887 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6889 DECL_RTL normally indicates where the parameter lives during most of the
6890 activation of the function. If optimization is enabled however, this
6891 could be either NULL or else a pseudo-reg. Both of those cases indicate
6892 that the parameter doesn't really live anywhere (as far as the code
6893 generation parts of GCC are concerned) during most of the function's
6894 activation. That will happen (for example) if the parameter is never
6895 referenced within the function.
6897 We could just generate a location descriptor here for all non-NULL
6898 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6899 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6900 where DECL_RTL is NULL or is a pseudo-reg.
6902 Note however that we can only get away with using DECL_INCOMING_RTL as
6903 a backup substitute for DECL_RTL in certain limited cases. In cases
6904 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6905 we can be sure that the parameter was passed using the same type as it is
6906 declared to have within the function, and that its DECL_INCOMING_RTL
6907 points us to a place where a value of that type is passed.
6909 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6910 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6911 because in these cases DECL_INCOMING_RTL points us to a value of some
6912 type which is *different* from the type of the parameter itself. Thus,
6913 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6914 such cases, the debugger would end up (for example) trying to fetch a
6915 `float' from a place which actually contains the first part of a
6916 `double'. That would lead to really incorrect and confusing
6917 output at debug-time.
6919 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6920 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6921 are a couple of exceptions however. On little-endian machines we can
6922 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6923 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6924 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6925 when (on a little-endian machine) a non-prototyped function has a
6926 parameter declared to be of type `short' or `char'. In such cases,
6927 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6928 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6929 passed `int' value. If the debugger then uses that address to fetch
6930 a `short' or a `char' (on a little-endian machine) the result will be
6931 the correct data, so we allow for such exceptional cases below.
6933 Note that our goal here is to describe the place where the given formal
6934 parameter lives during most of the function's activation (i.e. between
6935 the end of the prologue and the start of the epilogue). We'll do that
6936 as best as we can. Note however that if the given formal parameter is
6937 modified sometime during the execution of the function, then a stack
6938 backtrace (at debug-time) will show the function as having been
6939 called with the *new* value rather than the value which was
6940 originally passed in. This happens rarely enough that it is not
6941 a major problem, but it *is* a problem, and I'd like to fix it.
6943 A future version of dwarf2out.c may generate two additional
6944 attributes for any given DW_TAG_formal_parameter DIE which will
6945 describe the "passed type" and the "passed location" for the
6946 given formal parameter in addition to the attributes we now
6947 generate to indicate the "declared type" and the "active
6948 location" for each parameter. This additional set of attributes
6949 could be used by debuggers for stack backtraces. Separately, note
6950 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6951 NULL also. This happens (for example) for inlined-instances of
6952 inline function formal parameters which are never referenced.
6953 This really shouldn't be happening. All PARM_DECL nodes should
6954 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6955 doesn't currently generate these values for inlined instances of
6956 inline function parameters, so when we see such cases, we are
6957 just out-of-luck for the time being (until integrate.c
6960 /* Use DECL_RTL as the "location" unless we find something better. */
6961 rtl
= DECL_RTL (decl
);
6963 if (TREE_CODE (decl
) == PARM_DECL
)
6965 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
6967 declared_type
= type_main_variant (TREE_TYPE (decl
));
6968 passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
6970 /* This decl represents a formal parameter which was optimized out.
6971 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
6972 all* cases where (rtl == NULL_RTX) just below. */
6973 if (declared_type
== passed_type
)
6974 rtl
= DECL_INCOMING_RTL (decl
);
6975 else if (! BYTES_BIG_ENDIAN
6976 && TREE_CODE (declared_type
) == INTEGER_TYPE
6977 && (GET_MODE_SIZE (TYPE_MODE (declared_type
))
6978 <= GET_MODE_SIZE (TYPE_MODE (passed_type
))))
6979 rtl
= DECL_INCOMING_RTL (decl
);
6982 /* If the parm was passed in registers, but lives on the stack, then
6983 make a big endian correction if the mode of the type of the
6984 parameter is not the same as the mode of the rtl. */
6985 /* ??? This is the same series of checks that are made in dbxout.c before
6986 we reach the big endian correction code there. It isn't clear if all
6987 of these checks are necessary here, but keeping them all is the safe
6989 else if (GET_CODE (rtl
) == MEM
6990 && XEXP (rtl
, 0) != const0_rtx
6991 && ! CONSTANT_P (XEXP (rtl
, 0))
6992 /* Not passed in memory. */
6993 && GET_CODE (DECL_INCOMING_RTL (decl
)) != MEM
6994 /* Not passed by invisible reference. */
6995 && (GET_CODE (XEXP (rtl
, 0)) != REG
6996 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
6997 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
6998 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
6999 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
7002 /* Big endian correction check. */
7004 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
7005 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
7008 int offset
= (UNITS_PER_WORD
7009 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
7010 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
7011 plus_constant (XEXP (rtl
, 0), offset
));
7015 if (rtl
== NULL_RTX
)
7018 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
7019 #ifdef LEAF_REG_REMAP
7020 if (current_function_uses_only_leaf_regs
)
7021 leaf_renumber_regs_insn (rtl
);
7024 switch (GET_CODE (rtl
))
7027 /* The address of a variable that was optimized away; don't emit
7038 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7039 add_const_value_attribute (die
, rtl
);
7046 add_AT_location_description (die
, DW_AT_location
, rtl
);
7054 /* Generate an DW_AT_name attribute given some string value to be included as
7055 the value of the attribute. */
7058 add_name_attribute (die
, name_string
)
7059 register dw_die_ref die
;
7060 register const char *name_string
;
7062 if (name_string
!= NULL
&& *name_string
!= 0)
7064 if (demangle_name_func
)
7065 name_string
= (*demangle_name_func
) (name_string
);
7067 add_AT_string (die
, DW_AT_name
, name_string
);
7071 /* Given a tree node describing an array bound (either lower or upper) output
7072 a representation for that bound. */
7075 add_bound_info (subrange_die
, bound_attr
, bound
)
7076 register dw_die_ref subrange_die
;
7077 register enum dwarf_attribute bound_attr
;
7078 register tree bound
;
7080 /* If this is an Ada unconstrained array type, then don't emit any debug
7081 info because the array bounds are unknown. They are parameterized when
7082 the type is instantiated. */
7083 if (contains_placeholder_p (bound
))
7086 switch (TREE_CODE (bound
))
7091 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7093 if (! host_integerp (bound
, 0)
7094 || (bound_attr
== DW_AT_lower_bound
7095 && ((is_c_family () && integer_zerop (bound
))
7096 || (is_fortran () && integer_onep (bound
)))))
7097 /* use the default */
7100 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
7105 case NON_LVALUE_EXPR
:
7106 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
7110 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7111 access the upper bound values may be bogus. If they refer to a
7112 register, they may only describe how to get at these values at the
7113 points in the generated code right after they have just been
7114 computed. Worse yet, in the typical case, the upper bound values
7115 will not even *be* computed in the optimized code (though the
7116 number of elements will), so these SAVE_EXPRs are entirely
7117 bogus. In order to compensate for this fact, we check here to see
7118 if optimization is enabled, and if so, we don't add an attribute
7119 for the (unknown and unknowable) upper bound. This should not
7120 cause too much trouble for existing (stupid?) debuggers because
7121 they have to deal with empty upper bounds location descriptions
7122 anyway in order to be able to deal with incomplete array types.
7123 Of course an intelligent debugger (GDB?) should be able to
7124 comprehend that a missing upper bound specification in a array
7125 type used for a storage class `auto' local array variable
7126 indicates that the upper bound is both unknown (at compile- time)
7127 and unknowable (at run-time) due to optimization.
7129 We assume that a MEM rtx is safe because gcc wouldn't put the
7130 value there unless it was going to be used repeatedly in the
7131 function, i.e. for cleanups. */
7132 if (! optimize
|| (SAVE_EXPR_RTL (bound
)
7133 && GET_CODE (SAVE_EXPR_RTL (bound
)) == MEM
))
7135 register dw_die_ref ctx
= lookup_decl_die (current_function_decl
);
7136 register dw_die_ref decl_die
= new_die (DW_TAG_variable
, ctx
);
7137 register rtx loc
= SAVE_EXPR_RTL (bound
);
7139 /* If the RTL for the SAVE_EXPR is memory, handle the case where
7140 it references an outer function's frame. */
7142 if (GET_CODE (loc
) == MEM
)
7144 rtx new_addr
= fix_lexical_addr (XEXP (loc
, 0), bound
);
7146 if (XEXP (loc
, 0) != new_addr
)
7147 loc
= gen_rtx_MEM (GET_MODE (loc
), new_addr
);
7150 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
7151 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
7152 add_AT_location_description (decl_die
, DW_AT_location
, loc
);
7153 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
7156 /* Else leave out the attribute. */
7162 /* ??? These types of bounds can be created by the Ada front end,
7163 and it isn't clear how to emit debug info for them. */
7171 /* Note that the block of subscript information for an array type also
7172 includes information about the element type of type given array type. */
7175 add_subscript_info (type_die
, type
)
7176 register dw_die_ref type_die
;
7179 #ifndef MIPS_DEBUGGING_INFO
7180 register unsigned dimension_number
;
7182 register tree lower
, upper
;
7183 register dw_die_ref subrange_die
;
7185 /* The GNU compilers represent multidimensional array types as sequences of
7186 one dimensional array types whose element types are themselves array
7187 types. Here we squish that down, so that each multidimensional array
7188 type gets only one array_type DIE in the Dwarf debugging info. The draft
7189 Dwarf specification say that we are allowed to do this kind of
7190 compression in C (because there is no difference between an array or
7191 arrays and a multidimensional array in C) but for other source languages
7192 (e.g. Ada) we probably shouldn't do this. */
7194 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7195 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7196 We work around this by disabling this feature. See also
7197 gen_array_type_die. */
7198 #ifndef MIPS_DEBUGGING_INFO
7199 for (dimension_number
= 0;
7200 TREE_CODE (type
) == ARRAY_TYPE
;
7201 type
= TREE_TYPE (type
), dimension_number
++)
7204 register tree domain
= TYPE_DOMAIN (type
);
7206 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7207 and (in GNU C only) variable bounds. Handle all three forms
7209 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
);
7212 /* We have an array type with specified bounds. */
7213 lower
= TYPE_MIN_VALUE (domain
);
7214 upper
= TYPE_MAX_VALUE (domain
);
7216 /* define the index type. */
7217 if (TREE_TYPE (domain
))
7219 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7220 TREE_TYPE field. We can't emit debug info for this
7221 because it is an unnamed integral type. */
7222 if (TREE_CODE (domain
) == INTEGER_TYPE
7223 && TYPE_NAME (domain
) == NULL_TREE
7224 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
7225 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
7228 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
7232 /* ??? If upper is NULL, the array has unspecified length,
7233 but it does have a lower bound. This happens with Fortran
7235 Since the debugger is definitely going to need to know N
7236 to produce useful results, go ahead and output the lower
7237 bound solo, and hope the debugger can cope. */
7239 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
7241 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
7244 /* We have an array type with an unspecified length. The DWARF-2
7245 spec does not say how to handle this; let's just leave out the
7250 #ifndef MIPS_DEBUGGING_INFO
7256 add_byte_size_attribute (die
, tree_node
)
7258 register tree tree_node
;
7260 register unsigned size
;
7262 switch (TREE_CODE (tree_node
))
7270 case QUAL_UNION_TYPE
:
7271 size
= int_size_in_bytes (tree_node
);
7274 /* For a data member of a struct or union, the DW_AT_byte_size is
7275 generally given as the number of bytes normally allocated for an
7276 object of the *declared* type of the member itself. This is true
7277 even for bit-fields. */
7278 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
7284 /* Note that `size' might be -1 when we get to this point. If it is, that
7285 indicates that the byte size of the entity in question is variable. We
7286 have no good way of expressing this fact in Dwarf at the present time,
7287 so just let the -1 pass on through. */
7289 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
7292 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7293 which specifies the distance in bits from the highest order bit of the
7294 "containing object" for the bit-field to the highest order bit of the
7297 For any given bit-field, the "containing object" is a hypothetical
7298 object (of some integral or enum type) within which the given bit-field
7299 lives. The type of this hypothetical "containing object" is always the
7300 same as the declared type of the individual bit-field itself. The
7301 determination of the exact location of the "containing object" for a
7302 bit-field is rather complicated. It's handled by the
7303 `field_byte_offset' function (above).
7305 Note that it is the size (in bytes) of the hypothetical "containing object"
7306 which will be given in the DW_AT_byte_size attribute for this bit-field.
7307 (See `byte_size_attribute' above). */
7310 add_bit_offset_attribute (die
, decl
)
7311 register dw_die_ref die
;
7314 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
7315 tree type
= DECL_BIT_FIELD_TYPE (decl
);
7316 HOST_WIDE_INT bitpos_int
;
7317 HOST_WIDE_INT highest_order_object_bit_offset
;
7318 HOST_WIDE_INT highest_order_field_bit_offset
;
7319 HOST_WIDE_INT
unsigned bit_offset
;
7321 /* Must be a field and a bit field. */
7323 || TREE_CODE (decl
) != FIELD_DECL
)
7326 /* We can't yet handle bit-fields whose offsets are variable, so if we
7327 encounter such things, just return without generating any attribute
7328 whatsoever. Likewise for variable or too large size. */
7329 if (! host_integerp (bit_position (decl
), 0)
7330 || ! host_integerp (DECL_SIZE (decl
), 1))
7333 bitpos_int
= int_bit_position (decl
);
7335 /* Note that the bit offset is always the distance (in bits) from the
7336 highest-order bit of the "containing object" to the highest-order bit of
7337 the bit-field itself. Since the "high-order end" of any object or field
7338 is different on big-endian and little-endian machines, the computation
7339 below must take account of these differences. */
7340 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
7341 highest_order_field_bit_offset
= bitpos_int
;
7343 if (! BYTES_BIG_ENDIAN
)
7345 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
7346 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
7350 = (! BYTES_BIG_ENDIAN
7351 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
7352 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
7354 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
7357 /* For a FIELD_DECL node which represents a bit field, output an attribute
7358 which specifies the length in bits of the given field. */
7361 add_bit_size_attribute (die
, decl
)
7362 register dw_die_ref die
;
7365 /* Must be a field and a bit field. */
7366 if (TREE_CODE (decl
) != FIELD_DECL
7367 || ! DECL_BIT_FIELD_TYPE (decl
))
7370 if (host_integerp (DECL_SIZE (decl
), 1))
7371 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
7374 /* If the compiled language is ANSI C, then add a 'prototyped'
7375 attribute, if arg types are given for the parameters of a function. */
7378 add_prototyped_attribute (die
, func_type
)
7379 register dw_die_ref die
;
7380 register tree func_type
;
7382 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
7383 && TYPE_ARG_TYPES (func_type
) != NULL
)
7384 add_AT_flag (die
, DW_AT_prototyped
, 1);
7388 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7389 by looking in either the type declaration or object declaration
7393 add_abstract_origin_attribute (die
, origin
)
7394 register dw_die_ref die
;
7395 register tree origin
;
7397 dw_die_ref origin_die
= NULL
;
7399 if (TREE_CODE (origin
) != FUNCTION_DECL
)
7401 /* We may have gotten separated from the block for the inlined
7402 function, if we're in an exception handler or some such; make
7403 sure that the abstract function has been written out.
7405 Doing this for nested functions is wrong, however; functions are
7406 distinct units, and our context might not even be inline. */
7409 fn
= TYPE_STUB_DECL (fn
);
7410 fn
= decl_function_context (fn
);
7412 gen_abstract_function (fn
);
7415 if (DECL_P (origin
))
7416 origin_die
= lookup_decl_die (origin
);
7417 else if (TYPE_P (origin
))
7418 origin_die
= lookup_type_die (origin
);
7420 if (origin_die
== NULL
)
7423 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
7426 /* We do not currently support the pure_virtual attribute. */
7429 add_pure_or_virtual_attribute (die
, func_decl
)
7430 register dw_die_ref die
;
7431 register tree func_decl
;
7433 if (DECL_VINDEX (func_decl
))
7435 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
7437 if (host_integerp (DECL_VINDEX (func_decl
), 0))
7438 add_AT_loc (die
, DW_AT_vtable_elem_location
,
7439 new_loc_descr (DW_OP_constu
,
7440 tree_low_cst (DECL_VINDEX (func_decl
), 0),
7443 /* GNU extension: Record what type this method came from originally. */
7444 if (debug_info_level
> DINFO_LEVEL_TERSE
)
7445 add_AT_die_ref (die
, DW_AT_containing_type
,
7446 lookup_type_die (DECL_CONTEXT (func_decl
)));
7450 /* Add source coordinate attributes for the given decl. */
7453 add_src_coords_attributes (die
, decl
)
7454 register dw_die_ref die
;
7457 register unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
7459 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
7460 add_AT_unsigned (die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
7463 /* Add an DW_AT_name attribute and source coordinate attribute for the
7464 given decl, but only if it actually has a name. */
7467 add_name_and_src_coords_attributes (die
, decl
)
7468 register dw_die_ref die
;
7471 register tree decl_name
;
7473 decl_name
= DECL_NAME (decl
);
7474 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
7476 add_name_attribute (die
, dwarf2_name (decl
, 0));
7477 if (! DECL_ARTIFICIAL (decl
))
7478 add_src_coords_attributes (die
, decl
);
7480 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
7481 && TREE_PUBLIC (decl
)
7482 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
7483 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
7484 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
7488 /* Push a new declaration scope. */
7491 push_decl_scope (scope
)
7494 /* Make room in the decl_scope_table, if necessary. */
7495 if (decl_scope_table_allocated
== decl_scope_depth
)
7497 decl_scope_table_allocated
+= DECL_SCOPE_TABLE_INCREMENT
;
7499 = (tree
*) xrealloc (decl_scope_table
,
7500 decl_scope_table_allocated
* sizeof (tree
));
7503 decl_scope_table
[decl_scope_depth
] = scope
;
7507 /* Pop a declaration scope. */
7511 if (decl_scope_depth
<= 0)
7516 /* Return the DIE for the scope that immediately contains this type.
7517 Non-named types get global scope. Named types nested in other
7518 types get their containing scope if it's open, or global scope
7519 otherwise. All other types (i.e. function-local named types) get
7520 the current active scope. */
7523 scope_die_for (t
, context_die
)
7525 register dw_die_ref context_die
;
7527 register dw_die_ref scope_die
= NULL
;
7528 register tree containing_scope
;
7531 /* Non-types always go in the current scope. */
7535 containing_scope
= TYPE_CONTEXT (t
);
7537 /* Ignore namespaces for the moment. */
7538 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
7539 containing_scope
= NULL_TREE
;
7541 /* Ignore function type "scopes" from the C frontend. They mean that
7542 a tagged type is local to a parmlist of a function declarator, but
7543 that isn't useful to DWARF. */
7544 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
7545 containing_scope
= NULL_TREE
;
7547 if (containing_scope
== NULL_TREE
)
7548 scope_die
= comp_unit_die
;
7549 else if (TYPE_P (containing_scope
))
7551 /* For types, we can just look up the appropriate DIE. But
7552 first we check to see if we're in the middle of emitting it
7553 so we know where the new DIE should go. */
7555 for (i
= decl_scope_depth
- 1; i
>= 0; --i
)
7556 if (decl_scope_table
[i
] == containing_scope
)
7561 if (debug_info_level
> DINFO_LEVEL_TERSE
7562 && !TREE_ASM_WRITTEN (containing_scope
))
7565 /* If none of the current dies are suitable, we get file scope. */
7566 scope_die
= comp_unit_die
;
7569 scope_die
= lookup_type_die (containing_scope
);
7572 scope_die
= context_die
;
7577 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
7579 static inline int local_scope_p
PARAMS ((dw_die_ref
));
7581 local_scope_p (context_die
)
7582 dw_die_ref context_die
;
7584 for (; context_die
; context_die
= context_die
->die_parent
)
7585 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
7586 || context_die
->die_tag
== DW_TAG_subprogram
)
7591 /* Returns nonzero iff CONTEXT_DIE is a class. */
7593 static inline int class_scope_p
PARAMS ((dw_die_ref
));
7595 class_scope_p (context_die
)
7596 dw_die_ref context_die
;
7599 && (context_die
->die_tag
== DW_TAG_structure_type
7600 || context_die
->die_tag
== DW_TAG_union_type
));
7603 /* Many forms of DIEs require a "type description" attribute. This
7604 routine locates the proper "type descriptor" die for the type given
7605 by 'type', and adds an DW_AT_type attribute below the given die. */
7608 add_type_attribute (object_die
, type
, decl_const
, decl_volatile
, context_die
)
7609 register dw_die_ref object_die
;
7611 register int decl_const
;
7612 register int decl_volatile
;
7613 register dw_die_ref context_die
;
7615 register enum tree_code code
= TREE_CODE (type
);
7616 register dw_die_ref type_die
= NULL
;
7618 /* ??? If this type is an unnamed subrange type of an integral or
7619 floating-point type, use the inner type. This is because we have no
7620 support for unnamed types in base_type_die. This can happen if this is
7621 an Ada subrange type. Correct solution is emit a subrange type die. */
7622 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
7623 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
7624 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
7626 if (code
== ERROR_MARK
)
7629 /* Handle a special case. For functions whose return type is void, we
7630 generate *no* type attribute. (Note that no object may have type
7631 `void', so this only applies to function return types). */
7632 if (code
== VOID_TYPE
)
7635 type_die
= modified_type_die (type
,
7636 decl_const
|| TYPE_READONLY (type
),
7637 decl_volatile
|| TYPE_VOLATILE (type
),
7639 if (type_die
!= NULL
)
7640 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
7643 /* Given a tree pointer to a struct, class, union, or enum type node, return
7644 a pointer to the (string) tag name for the given type, or zero if the type
7645 was declared without a tag. */
7651 register const char *name
= 0;
7653 if (TYPE_NAME (type
) != 0)
7655 register tree t
= 0;
7657 /* Find the IDENTIFIER_NODE for the type name. */
7658 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
7659 t
= TYPE_NAME (type
);
7661 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7662 a TYPE_DECL node, regardless of whether or not a `typedef' was
7664 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
7665 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
7666 t
= DECL_NAME (TYPE_NAME (type
));
7668 /* Now get the name as a string, or invent one. */
7670 name
= IDENTIFIER_POINTER (t
);
7673 return (name
== 0 || *name
== '\0') ? 0 : name
;
7676 /* Return the type associated with a data member, make a special check
7677 for bit field types. */
7680 member_declared_type (member
)
7681 register tree member
;
7683 return (DECL_BIT_FIELD_TYPE (member
)
7684 ? DECL_BIT_FIELD_TYPE (member
)
7685 : TREE_TYPE (member
));
7688 /* Get the decl's label, as described by its RTL. This may be different
7689 from the DECL_NAME name used in the source file. */
7693 decl_start_label (decl
)
7698 x
= DECL_RTL (decl
);
7699 if (GET_CODE (x
) != MEM
)
7703 if (GET_CODE (x
) != SYMBOL_REF
)
7706 fnname
= XSTR (x
, 0);
7711 /* These routines generate the internal representation of the DIE's for
7712 the compilation unit. Debugging information is collected by walking
7713 the declaration trees passed in from dwarf2out_decl(). */
7716 gen_array_type_die (type
, context_die
)
7718 register dw_die_ref context_die
;
7720 register dw_die_ref scope_die
= scope_die_for (type
, context_die
);
7721 register dw_die_ref array_die
;
7722 register tree element_type
;
7724 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7725 the inner array type comes before the outer array type. Thus we must
7726 call gen_type_die before we call new_die. See below also. */
7727 #ifdef MIPS_DEBUGGING_INFO
7728 gen_type_die (TREE_TYPE (type
), context_die
);
7731 array_die
= new_die (DW_TAG_array_type
, scope_die
);
7734 /* We default the array ordering. SDB will probably do
7735 the right things even if DW_AT_ordering is not present. It's not even
7736 an issue until we start to get into multidimensional arrays anyway. If
7737 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7738 then we'll have to put the DW_AT_ordering attribute back in. (But if
7739 and when we find out that we need to put these in, we will only do so
7740 for multidimensional arrays. */
7741 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
7744 #ifdef MIPS_DEBUGGING_INFO
7745 /* The SGI compilers handle arrays of unknown bound by setting
7746 AT_declaration and not emitting any subrange DIEs. */
7747 if (! TYPE_DOMAIN (type
))
7748 add_AT_unsigned (array_die
, DW_AT_declaration
, 1);
7751 add_subscript_info (array_die
, type
);
7753 add_name_attribute (array_die
, type_tag (type
));
7754 equate_type_number_to_die (type
, array_die
);
7756 /* Add representation of the type of the elements of this array type. */
7757 element_type
= TREE_TYPE (type
);
7759 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7760 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7761 We work around this by disabling this feature. See also
7762 add_subscript_info. */
7763 #ifndef MIPS_DEBUGGING_INFO
7764 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
7765 element_type
= TREE_TYPE (element_type
);
7767 gen_type_die (element_type
, context_die
);
7770 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
7774 gen_set_type_die (type
, context_die
)
7776 register dw_die_ref context_die
;
7778 register dw_die_ref type_die
7779 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
));
7781 equate_type_number_to_die (type
, type_die
);
7782 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
7787 gen_entry_point_die (decl
, context_die
)
7789 register dw_die_ref context_die
;
7791 register tree origin
= decl_ultimate_origin (decl
);
7792 register dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
);
7794 add_abstract_origin_attribute (decl_die
, origin
);
7797 add_name_and_src_coords_attributes (decl_die
, decl
);
7798 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
7802 if (DECL_ABSTRACT (decl
))
7803 equate_decl_number_to_die (decl
, decl_die
);
7805 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
7809 /* Remember a type in the incomplete_types_list. */
7812 add_incomplete_type (type
)
7815 if (incomplete_types
== incomplete_types_allocated
)
7817 incomplete_types_allocated
+= INCOMPLETE_TYPES_INCREMENT
;
7818 incomplete_types_list
7819 = (tree
*) xrealloc (incomplete_types_list
,
7820 sizeof (tree
) * incomplete_types_allocated
);
7823 incomplete_types_list
[incomplete_types
++] = type
;
7826 /* Walk through the list of incomplete types again, trying once more to
7827 emit full debugging info for them. */
7830 retry_incomplete_types ()
7834 while (incomplete_types
)
7837 type
= incomplete_types_list
[incomplete_types
];
7838 gen_type_die (type
, comp_unit_die
);
7842 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7845 gen_inlined_enumeration_type_die (type
, context_die
)
7847 register dw_die_ref context_die
;
7849 register dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
,
7851 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7852 be incomplete and such types are not marked. */
7853 add_abstract_origin_attribute (type_die
, type
);
7856 /* Generate a DIE to represent an inlined instance of a structure type. */
7859 gen_inlined_structure_type_die (type
, context_die
)
7861 register dw_die_ref context_die
;
7863 register dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
);
7865 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7866 be incomplete and such types are not marked. */
7867 add_abstract_origin_attribute (type_die
, type
);
7870 /* Generate a DIE to represent an inlined instance of a union type. */
7873 gen_inlined_union_type_die (type
, context_die
)
7875 register dw_die_ref context_die
;
7877 register dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
);
7879 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7880 be incomplete and such types are not marked. */
7881 add_abstract_origin_attribute (type_die
, type
);
7884 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7885 include all of the information about the enumeration values also. Each
7886 enumerated type name/value is listed as a child of the enumerated type
7890 gen_enumeration_type_die (type
, context_die
)
7892 register dw_die_ref context_die
;
7894 register dw_die_ref type_die
= lookup_type_die (type
);
7896 if (type_die
== NULL
)
7898 type_die
= new_die (DW_TAG_enumeration_type
,
7899 scope_die_for (type
, context_die
));
7900 equate_type_number_to_die (type
, type_die
);
7901 add_name_attribute (type_die
, type_tag (type
));
7903 else if (! TYPE_SIZE (type
))
7906 remove_AT (type_die
, DW_AT_declaration
);
7908 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7909 given enum type is incomplete, do not generate the DW_AT_byte_size
7910 attribute or the DW_AT_element_list attribute. */
7911 if (TYPE_SIZE (type
))
7915 TREE_ASM_WRITTEN (type
) = 1;
7916 add_byte_size_attribute (type_die
, type
);
7917 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
7918 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
7920 /* If the first reference to this type was as the return type of an
7921 inline function, then it may not have a parent. Fix this now. */
7922 if (type_die
->die_parent
== NULL
)
7923 add_child_die (scope_die_for (type
, context_die
), type_die
);
7925 for (link
= TYPE_FIELDS (type
);
7926 link
!= NULL
; link
= TREE_CHAIN (link
))
7928 register dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
);
7930 add_name_attribute (enum_die
,
7931 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
7933 if (host_integerp (TREE_VALUE (link
), 0))
7935 if (tree_int_cst_sgn (TREE_VALUE (link
)) < 0)
7936 add_AT_int (enum_die
, DW_AT_const_value
,
7937 tree_low_cst (TREE_VALUE (link
), 0));
7939 add_AT_unsigned (enum_die
, DW_AT_const_value
,
7940 tree_low_cst (TREE_VALUE (link
), 0));
7945 add_AT_flag (type_die
, DW_AT_declaration
, 1);
7949 /* Generate a DIE to represent either a real live formal parameter decl or to
7950 represent just the type of some formal parameter position in some function
7953 Note that this routine is a bit unusual because its argument may be a
7954 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7955 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7956 node. If it's the former then this function is being called to output a
7957 DIE to represent a formal parameter object (or some inlining thereof). If
7958 it's the latter, then this function is only being called to output a
7959 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7960 argument type of some subprogram type. */
7963 gen_formal_parameter_die (node
, context_die
)
7965 register dw_die_ref context_die
;
7967 register dw_die_ref parm_die
7968 = new_die (DW_TAG_formal_parameter
, context_die
);
7969 register tree origin
;
7971 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
7974 origin
= decl_ultimate_origin (node
);
7976 add_abstract_origin_attribute (parm_die
, origin
);
7979 add_name_and_src_coords_attributes (parm_die
, node
);
7980 add_type_attribute (parm_die
, TREE_TYPE (node
),
7981 TREE_READONLY (node
),
7982 TREE_THIS_VOLATILE (node
),
7984 if (DECL_ARTIFICIAL (node
))
7985 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
7988 equate_decl_number_to_die (node
, parm_die
);
7989 if (! DECL_ABSTRACT (node
))
7990 add_location_or_const_value_attribute (parm_die
, node
);
7995 /* We were called with some kind of a ..._TYPE node. */
7996 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
8006 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
8007 at the end of an (ANSI prototyped) formal parameters list. */
8010 gen_unspecified_parameters_die (decl_or_type
, context_die
)
8011 register tree decl_or_type ATTRIBUTE_UNUSED
;
8012 register dw_die_ref context_die
;
8014 new_die (DW_TAG_unspecified_parameters
, context_die
);
8017 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
8018 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
8019 parameters as specified in some function type specification (except for
8020 those which appear as part of a function *definition*). */
8023 gen_formal_types_die (function_or_method_type
, context_die
)
8024 register tree function_or_method_type
;
8025 register dw_die_ref context_die
;
8028 register tree formal_type
= NULL
;
8029 register tree first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
8032 /* In the case where we are generating a formal types list for a C++
8033 non-static member function type, skip over the first thing on the
8034 TYPE_ARG_TYPES list because it only represents the type of the hidden
8035 `this pointer'. The debugger should be able to figure out (without
8036 being explicitly told) that this non-static member function type takes a
8037 `this pointer' and should be able to figure what the type of that hidden
8038 parameter is from the DW_AT_member attribute of the parent
8039 DW_TAG_subroutine_type DIE. */
8040 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
)
8041 first_parm_type
= TREE_CHAIN (first_parm_type
);
8044 /* Make our first pass over the list of formal parameter types and output a
8045 DW_TAG_formal_parameter DIE for each one. */
8046 for (link
= first_parm_type
; link
; link
= TREE_CHAIN (link
))
8048 register dw_die_ref parm_die
;
8050 formal_type
= TREE_VALUE (link
);
8051 if (formal_type
== void_type_node
)
8054 /* Output a (nameless) DIE to represent the formal parameter itself. */
8055 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
8056 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
8057 && link
== first_parm_type
)
8058 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
8061 /* If this function type has an ellipsis, add a
8062 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8063 if (formal_type
!= void_type_node
)
8064 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
8066 /* Make our second (and final) pass over the list of formal parameter types
8067 and output DIEs to represent those types (as necessary). */
8068 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
8070 link
= TREE_CHAIN (link
))
8072 formal_type
= TREE_VALUE (link
);
8073 if (formal_type
== void_type_node
)
8076 gen_type_die (formal_type
, context_die
);
8080 /* We want to generate the DIE for TYPE so that we can generate the
8081 die for MEMBER, which has been defined; we will need to refer back
8082 to the member declaration nested within TYPE. If we're trying to
8083 generate minimal debug info for TYPE, processing TYPE won't do the
8084 trick; we need to attach the member declaration by hand. */
8087 gen_type_die_for_member (type
, member
, context_die
)
8089 dw_die_ref context_die
;
8091 gen_type_die (type
, context_die
);
8093 /* If we're trying to avoid duplicate debug info, we may not have
8094 emitted the member decl for this function. Emit it now. */
8095 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
8096 && ! lookup_decl_die (member
))
8098 if (decl_ultimate_origin (member
))
8101 push_decl_scope (type
);
8102 if (TREE_CODE (member
) == FUNCTION_DECL
)
8103 gen_subprogram_die (member
, lookup_type_die (type
));
8105 gen_variable_die (member
, lookup_type_die (type
));
8110 /* Generate the DWARF2 info for the "abstract" instance
8111 of a function which we may later generate inlined and/or
8112 out-of-line instances of. */
8115 gen_abstract_function (decl
)
8118 register dw_die_ref old_die
= lookup_decl_die (decl
);
8121 if (old_die
&& get_AT_unsigned (old_die
, DW_AT_inline
))
8122 /* We've already generated the abstract instance. */
8125 save_fn
= current_function_decl
;
8126 current_function_decl
= decl
;
8128 set_decl_abstract_flags (decl
, 1);
8129 dwarf2out_decl (decl
);
8130 set_decl_abstract_flags (decl
, 0);
8132 current_function_decl
= save_fn
;
8135 /* Generate a DIE to represent a declared function (either file-scope or
8139 gen_subprogram_die (decl
, context_die
)
8141 register dw_die_ref context_die
;
8143 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
8144 register tree origin
= decl_ultimate_origin (decl
);
8145 register dw_die_ref subr_die
;
8146 register rtx fp_reg
;
8147 register tree fn_arg_types
;
8148 register tree outer_scope
;
8149 register dw_die_ref old_die
= lookup_decl_die (decl
);
8150 register int declaration
= (current_function_decl
!= decl
8151 || class_scope_p (context_die
));
8153 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
8154 be true, if we started to generate the abstract instance of an inline,
8155 decided to output its containing class, and proceeded to emit the
8156 declaration of the inline from the member list for the class. In that
8157 case, `declaration' takes priority; we'll get back to the abstract
8158 instance when we're done with the class. */
8160 /* The class-scope declaration DIE must be the primary DIE. */
8161 if (origin
&& declaration
&& class_scope_p (context_die
))
8170 if (declaration
&& ! local_scope_p (context_die
))
8173 /* Fixup die_parent for the abstract instance of a nested
8175 if (old_die
&& old_die
->die_parent
== NULL
)
8176 add_child_die (context_die
, old_die
);
8178 subr_die
= new_die (DW_TAG_subprogram
, context_die
);
8179 add_abstract_origin_attribute (subr_die
, origin
);
8181 else if (old_die
&& DECL_ABSTRACT (decl
)
8182 && get_AT_unsigned (old_die
, DW_AT_inline
))
8184 /* This must be a redefinition of an extern inline function.
8185 We can just reuse the old die here. */
8188 /* Clear out the inlined attribute and parm types. */
8189 remove_AT (subr_die
, DW_AT_inline
);
8190 remove_children (subr_die
);
8194 register unsigned file_index
8195 = lookup_filename (DECL_SOURCE_FILE (decl
));
8197 if (get_AT_flag (old_die
, DW_AT_declaration
) != 1)
8199 /* ??? This can happen if there is a bug in the program, for
8200 instance, if it has duplicate function definitions. Ideally,
8201 we should detect this case and ignore it. For now, if we have
8202 already reported an error, any error at all, then assume that
8203 we got here because of a input error, not a dwarf2 bug. */
8209 /* If the definition comes from the same place as the declaration,
8210 maybe use the old DIE. We always want the DIE for this function
8211 that has the *_pc attributes to be under comp_unit_die so the
8212 debugger can find it. For inlines, that is the concrete instance,
8213 so we can use the old DIE here. For non-inline methods, we want a
8214 specification DIE at toplevel, so we need a new DIE. For local
8215 class methods, this doesn't apply; we just use the old DIE. */
8216 if ((DECL_ABSTRACT (decl
) || old_die
->die_parent
== comp_unit_die
8217 || context_die
== NULL
)
8218 && (DECL_ARTIFICIAL (decl
)
8219 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
8220 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
8221 == (unsigned)DECL_SOURCE_LINE (decl
)))))
8225 /* Clear out the declaration attribute and the parm types. */
8226 remove_AT (subr_die
, DW_AT_declaration
);
8227 remove_children (subr_die
);
8231 subr_die
= new_die (DW_TAG_subprogram
, context_die
);
8232 add_AT_die_ref (subr_die
, DW_AT_specification
, old_die
);
8233 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
8234 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
8235 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
8236 != (unsigned)DECL_SOURCE_LINE (decl
))
8238 (subr_die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
8243 subr_die
= new_die (DW_TAG_subprogram
, context_die
);
8245 if (TREE_PUBLIC (decl
))
8246 add_AT_flag (subr_die
, DW_AT_external
, 1);
8248 add_name_and_src_coords_attributes (subr_die
, decl
);
8249 if (debug_info_level
> DINFO_LEVEL_TERSE
)
8251 register tree type
= TREE_TYPE (decl
);
8253 add_prototyped_attribute (subr_die
, type
);
8254 add_type_attribute (subr_die
, TREE_TYPE (type
), 0, 0, context_die
);
8257 add_pure_or_virtual_attribute (subr_die
, decl
);
8258 if (DECL_ARTIFICIAL (decl
))
8259 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
8260 if (TREE_PROTECTED (decl
))
8261 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8262 else if (TREE_PRIVATE (decl
))
8263 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
8269 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
8271 /* The first time we see a member function, it is in the context of
8272 the class to which it belongs. We make sure of this by emitting
8273 the class first. The next time is the definition, which is
8274 handled above. The two may come from the same source text. */
8275 if (DECL_CONTEXT (decl
) || DECL_ABSTRACT (decl
))
8276 equate_decl_number_to_die (decl
, subr_die
);
8278 else if (DECL_ABSTRACT (decl
))
8280 if (DECL_INLINE (decl
) && !flag_no_inline
)
8282 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
8283 inline functions, but not for extern inline functions.
8284 We can't get this completely correct because information
8285 about whether the function was declared inline is not
8287 if (DECL_DEFER_OUTPUT (decl
))
8288 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
8290 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
8293 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
8295 equate_decl_number_to_die (decl
, subr_die
);
8297 else if (!DECL_EXTERNAL (decl
))
8299 if (origin
== NULL_TREE
)
8300 equate_decl_number_to_die (decl
, subr_die
);
8302 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
8303 current_funcdef_number
);
8304 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
8305 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
8306 current_funcdef_number
);
8307 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
8309 add_pubname (decl
, subr_die
);
8310 add_arange (decl
, subr_die
);
8312 #ifdef MIPS_DEBUGGING_INFO
8313 /* Add a reference to the FDE for this routine. */
8314 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
8317 /* Define the "frame base" location for this routine. We use the
8318 frame pointer or stack pointer registers, since the RTL for local
8319 variables is relative to one of them. */
8321 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
8322 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
8325 /* ??? This fails for nested inline functions, because context_display
8326 is not part of the state saved/restored for inline functions. */
8327 if (current_function_needs_context
)
8328 add_AT_location_description (subr_die
, DW_AT_static_link
,
8329 lookup_static_chain (decl
));
8333 /* Now output descriptions of the arguments for this function. This gets
8334 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8335 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8336 `...' at the end of the formal parameter list. In order to find out if
8337 there was a trailing ellipsis or not, we must instead look at the type
8338 associated with the FUNCTION_DECL. This will be a node of type
8339 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8340 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8341 an ellipsis at the end. */
8343 /* In the case where we are describing a mere function declaration, all we
8344 need to do here (and all we *can* do here) is to describe the *types* of
8345 its formal parameters. */
8346 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
8348 else if (declaration
)
8349 gen_formal_types_die (TREE_TYPE (decl
), subr_die
);
8352 /* Generate DIEs to represent all known formal parameters */
8353 register tree arg_decls
= DECL_ARGUMENTS (decl
);
8356 /* When generating DIEs, generate the unspecified_parameters DIE
8357 instead if we come across the arg "__builtin_va_alist" */
8358 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
8359 if (TREE_CODE (parm
) == PARM_DECL
)
8361 if (DECL_NAME (parm
)
8362 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
8363 "__builtin_va_alist"))
8364 gen_unspecified_parameters_die (parm
, subr_die
);
8366 gen_decl_die (parm
, subr_die
);
8369 /* Decide whether we need a unspecified_parameters DIE at the end.
8370 There are 2 more cases to do this for: 1) the ansi ... declaration -
8371 this is detectable when the end of the arg list is not a
8372 void_type_node 2) an unprototyped function declaration (not a
8373 definition). This just means that we have no info about the
8374 parameters at all. */
8375 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
8376 if (fn_arg_types
!= NULL
)
8378 /* this is the prototyped case, check for ... */
8379 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
8380 gen_unspecified_parameters_die (decl
, subr_die
);
8382 else if (DECL_INITIAL (decl
) == NULL_TREE
)
8383 gen_unspecified_parameters_die (decl
, subr_die
);
8386 /* Output Dwarf info for all of the stuff within the body of the function
8387 (if it has one - it may be just a declaration). */
8388 outer_scope
= DECL_INITIAL (decl
);
8390 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8391 node created to represent a function. This outermost BLOCK actually
8392 represents the outermost binding contour for the function, i.e. the
8393 contour in which the function's formal parameters and labels get
8394 declared. Curiously, it appears that the front end doesn't actually
8395 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8396 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8397 list for the function instead.) The BLOCK_VARS list for the
8398 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8399 the function however, and we output DWARF info for those in
8400 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8401 node representing the function's outermost pair of curly braces, and
8402 any blocks used for the base and member initializers of a C++
8403 constructor function. */
8404 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
8406 current_function_has_inlines
= 0;
8407 decls_for_scope (outer_scope
, subr_die
, 0);
8409 #if 0 && defined (MIPS_DEBUGGING_INFO)
8410 if (current_function_has_inlines
)
8412 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
8413 if (! comp_unit_has_inlines
)
8415 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
8416 comp_unit_has_inlines
= 1;
8423 /* Generate a DIE to represent a declared data object. */
8426 gen_variable_die (decl
, context_die
)
8428 register dw_die_ref context_die
;
8430 register tree origin
= decl_ultimate_origin (decl
);
8431 register dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
);
8433 dw_die_ref old_die
= lookup_decl_die (decl
);
8434 int declaration
= (DECL_EXTERNAL (decl
)
8435 || class_scope_p (context_die
));
8438 add_abstract_origin_attribute (var_die
, origin
);
8439 /* Loop unrolling can create multiple blocks that refer to the same
8440 static variable, so we must test for the DW_AT_declaration flag. */
8441 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8442 copy decls and set the DECL_ABSTRACT flag on them instead of
8444 else if (old_die
&& TREE_STATIC (decl
)
8445 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
8447 /* This is a definition of a C++ class level static. */
8448 add_AT_die_ref (var_die
, DW_AT_specification
, old_die
);
8449 if (DECL_NAME (decl
))
8451 register unsigned file_index
8452 = lookup_filename (DECL_SOURCE_FILE (decl
));
8454 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
8455 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
8457 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
8458 != (unsigned)DECL_SOURCE_LINE (decl
))
8460 add_AT_unsigned (var_die
, DW_AT_decl_line
,
8461 DECL_SOURCE_LINE (decl
));
8466 add_name_and_src_coords_attributes (var_die
, decl
);
8467 add_type_attribute (var_die
, TREE_TYPE (decl
),
8468 TREE_READONLY (decl
),
8469 TREE_THIS_VOLATILE (decl
), context_die
);
8471 if (TREE_PUBLIC (decl
))
8472 add_AT_flag (var_die
, DW_AT_external
, 1);
8474 if (DECL_ARTIFICIAL (decl
))
8475 add_AT_flag (var_die
, DW_AT_artificial
, 1);
8477 if (TREE_PROTECTED (decl
))
8478 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8480 else if (TREE_PRIVATE (decl
))
8481 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
8485 add_AT_flag (var_die
, DW_AT_declaration
, 1);
8487 if (class_scope_p (context_die
) || DECL_ABSTRACT (decl
))
8488 equate_decl_number_to_die (decl
, var_die
);
8490 if (! declaration
&& ! DECL_ABSTRACT (decl
))
8492 add_location_or_const_value_attribute (var_die
, decl
);
8493 add_pubname (decl
, var_die
);
8497 /* Generate a DIE to represent a label identifier. */
8500 gen_label_die (decl
, context_die
)
8502 register dw_die_ref context_die
;
8504 register tree origin
= decl_ultimate_origin (decl
);
8505 register dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
);
8507 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8508 char label2
[MAX_ARTIFICIAL_LABEL_BYTES
];
8511 add_abstract_origin_attribute (lbl_die
, origin
);
8513 add_name_and_src_coords_attributes (lbl_die
, decl
);
8515 if (DECL_ABSTRACT (decl
))
8516 equate_decl_number_to_die (decl
, lbl_die
);
8519 insn
= DECL_RTL (decl
);
8521 /* Deleted labels are programmer specified labels which have been
8522 eliminated because of various optimisations. We still emit them
8523 here so that it is possible to put breakpoints on them. */
8524 if (GET_CODE (insn
) == CODE_LABEL
8525 || ((GET_CODE (insn
) == NOTE
8526 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
)))
8528 /* When optimization is enabled (via -O) some parts of the compiler
8529 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8530 represent source-level labels which were explicitly declared by
8531 the user. This really shouldn't be happening though, so catch
8532 it if it ever does happen. */
8533 if (INSN_DELETED_P (insn
))
8536 sprintf (label2
, INSN_LABEL_FMT
, current_funcdef_number
);
8537 ASM_GENERATE_INTERNAL_LABEL (label
, label2
,
8538 (unsigned) INSN_UID (insn
));
8539 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
8544 /* Generate a DIE for a lexical block. */
8547 gen_lexical_block_die (stmt
, context_die
, depth
)
8549 register dw_die_ref context_die
;
8552 register dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
);
8553 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8555 if (! BLOCK_ABSTRACT (stmt
))
8557 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
8558 BLOCK_NUMBER (stmt
));
8559 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
8560 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
8561 BLOCK_NUMBER (stmt
));
8562 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
8565 decls_for_scope (stmt
, stmt_die
, depth
);
8568 /* Generate a DIE for an inlined subprogram. */
8571 gen_inlined_subroutine_die (stmt
, context_die
, depth
)
8573 register dw_die_ref context_die
;
8576 if (! BLOCK_ABSTRACT (stmt
))
8578 register dw_die_ref subr_die
8579 = new_die (DW_TAG_inlined_subroutine
, context_die
);
8580 register tree decl
= block_ultimate_origin (stmt
);
8581 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8583 /* Emit info for the abstract instance first, if we haven't yet. */
8584 gen_abstract_function (decl
);
8586 add_abstract_origin_attribute (subr_die
, decl
);
8587 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
8588 BLOCK_NUMBER (stmt
));
8589 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
8590 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
8591 BLOCK_NUMBER (stmt
));
8592 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
8593 decls_for_scope (stmt
, subr_die
, depth
);
8594 current_function_has_inlines
= 1;
8598 /* Generate a DIE for a field in a record, or structure. */
8601 gen_field_die (decl
, context_die
)
8603 register dw_die_ref context_die
;
8605 register dw_die_ref decl_die
= new_die (DW_TAG_member
, context_die
);
8607 add_name_and_src_coords_attributes (decl_die
, decl
);
8608 add_type_attribute (decl_die
, member_declared_type (decl
),
8609 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
8612 /* If this is a bit field... */
8613 if (DECL_BIT_FIELD_TYPE (decl
))
8615 add_byte_size_attribute (decl_die
, decl
);
8616 add_bit_size_attribute (decl_die
, decl
);
8617 add_bit_offset_attribute (decl_die
, decl
);
8620 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
8621 add_data_member_location_attribute (decl_die
, decl
);
8623 if (DECL_ARTIFICIAL (decl
))
8624 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
8626 if (TREE_PROTECTED (decl
))
8627 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8629 else if (TREE_PRIVATE (decl
))
8630 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
8634 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8635 Use modified_type_die instead.
8636 We keep this code here just in case these types of DIEs may be needed to
8637 represent certain things in other languages (e.g. Pascal) someday. */
8639 gen_pointer_type_die (type
, context_die
)
8641 register dw_die_ref context_die
;
8643 register dw_die_ref ptr_die
8644 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
));
8646 equate_type_number_to_die (type
, ptr_die
);
8647 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
8648 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
8651 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8652 Use modified_type_die instead.
8653 We keep this code here just in case these types of DIEs may be needed to
8654 represent certain things in other languages (e.g. Pascal) someday. */
8656 gen_reference_type_die (type
, context_die
)
8658 register dw_die_ref context_die
;
8660 register dw_die_ref ref_die
8661 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
));
8663 equate_type_number_to_die (type
, ref_die
);
8664 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
8665 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
8669 /* Generate a DIE for a pointer to a member type. */
8671 gen_ptr_to_mbr_type_die (type
, context_die
)
8673 register dw_die_ref context_die
;
8675 register dw_die_ref ptr_die
8676 = new_die (DW_TAG_ptr_to_member_type
, scope_die_for (type
, context_die
));
8678 equate_type_number_to_die (type
, ptr_die
);
8679 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
8680 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
8681 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
8684 /* Generate the DIE for the compilation unit. */
8687 gen_compile_unit_die (filename
)
8688 register const char *filename
;
8690 register dw_die_ref die
;
8692 const char *wd
= getpwd ();
8695 die
= new_die (DW_TAG_compile_unit
, NULL
);
8696 add_name_attribute (die
, filename
);
8698 if (wd
!= NULL
&& filename
[0] != DIR_SEPARATOR
)
8699 add_AT_string (die
, DW_AT_comp_dir
, wd
);
8701 sprintf (producer
, "%s %s", language_string
, version_string
);
8703 #ifdef MIPS_DEBUGGING_INFO
8704 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8705 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8706 not appear in the producer string, the debugger reaches the conclusion
8707 that the object file is stripped and has no debugging information.
8708 To get the MIPS/SGI debugger to believe that there is debugging
8709 information in the object file, we add a -g to the producer string. */
8710 if (debug_info_level
> DINFO_LEVEL_TERSE
)
8711 strcat (producer
, " -g");
8714 add_AT_string (die
, DW_AT_producer
, producer
);
8716 if (strcmp (language_string
, "GNU C++") == 0)
8717 language
= DW_LANG_C_plus_plus
;
8718 else if (strcmp (language_string
, "GNU Ada") == 0)
8719 language
= DW_LANG_Ada83
;
8720 else if (strcmp (language_string
, "GNU F77") == 0)
8721 language
= DW_LANG_Fortran77
;
8722 else if (strcmp (language_string
, "GNU Pascal") == 0)
8723 language
= DW_LANG_Pascal83
;
8724 else if (flag_traditional
)
8725 language
= DW_LANG_C
;
8727 language
= DW_LANG_C89
;
8729 add_AT_unsigned (die
, DW_AT_language
, language
);
8734 /* Generate a DIE for a string type. */
8737 gen_string_type_die (type
, context_die
)
8739 register dw_die_ref context_die
;
8741 register dw_die_ref type_die
8742 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
));
8744 equate_type_number_to_die (type
, type_die
);
8746 /* Fudge the string length attribute for now. */
8748 /* TODO: add string length info.
8749 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8750 bound_representation (upper_bound, 0, 'u'); */
8753 /* Generate the DIE for a base class. */
8756 gen_inheritance_die (binfo
, context_die
)
8757 register tree binfo
;
8758 register dw_die_ref context_die
;
8760 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
);
8762 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
8763 add_data_member_location_attribute (die
, binfo
);
8765 if (TREE_VIA_VIRTUAL (binfo
))
8766 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
8767 if (TREE_VIA_PUBLIC (binfo
))
8768 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
8769 else if (TREE_VIA_PROTECTED (binfo
))
8770 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8773 /* Generate a DIE for a class member. */
8776 gen_member_die (type
, context_die
)
8778 register dw_die_ref context_die
;
8780 register tree member
;
8783 /* If this is not an incomplete type, output descriptions of each of its
8784 members. Note that as we output the DIEs necessary to represent the
8785 members of this record or union type, we will also be trying to output
8786 DIEs to represent the *types* of those members. However the `type'
8787 function (above) will specifically avoid generating type DIEs for member
8788 types *within* the list of member DIEs for this (containing) type execpt
8789 for those types (of members) which are explicitly marked as also being
8790 members of this (containing) type themselves. The g++ front- end can
8791 force any given type to be treated as a member of some other
8792 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8793 to point to the TREE node representing the appropriate (containing)
8796 /* First output info about the base classes. */
8797 if (TYPE_BINFO (type
) && TYPE_BINFO_BASETYPES (type
))
8799 register tree bases
= TYPE_BINFO_BASETYPES (type
);
8800 register int n_bases
= TREE_VEC_LENGTH (bases
);
8803 for (i
= 0; i
< n_bases
; i
++)
8804 gen_inheritance_die (TREE_VEC_ELT (bases
, i
), context_die
);
8807 /* Now output info about the data members and type members. */
8808 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
8810 /* If we thought we were generating minimal debug info for TYPE
8811 and then changed our minds, some of the member declarations
8812 may have already been defined. Don't define them again, but
8813 do put them in the right order. */
8815 child
= lookup_decl_die (member
);
8817 splice_child_die (context_die
, child
);
8819 gen_decl_die (member
, context_die
);
8822 /* Now output info about the function members (if any). */
8823 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
8825 child
= lookup_decl_die (member
);
8827 splice_child_die (context_die
, child
);
8829 gen_decl_die (member
, context_die
);
8833 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
8834 is set, we pretend that the type was never defined, so we only get the
8835 member DIEs needed by later specification DIEs. */
8838 gen_struct_or_union_type_die (type
, context_die
)
8840 register dw_die_ref context_die
;
8842 register dw_die_ref type_die
= lookup_type_die (type
);
8843 register dw_die_ref scope_die
= 0;
8844 register int nested
= 0;
8845 int complete
= (TYPE_SIZE (type
)
8846 && (! TYPE_STUB_DECL (type
)
8847 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
8849 if (type_die
&& ! complete
)
8852 if (TYPE_CONTEXT (type
) != NULL_TREE
8853 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
)))
8856 scope_die
= scope_die_for (type
, context_die
);
8858 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
8859 /* First occurrence of type or toplevel definition of nested class. */
8861 register dw_die_ref old_die
= type_die
;
8863 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
8864 ? DW_TAG_structure_type
: DW_TAG_union_type
,
8866 equate_type_number_to_die (type
, type_die
);
8867 add_name_attribute (type_die
, type_tag (type
));
8869 add_AT_die_ref (type_die
, DW_AT_specification
, old_die
);
8872 remove_AT (type_die
, DW_AT_declaration
);
8874 /* If this type has been completed, then give it a byte_size attribute and
8875 then give a list of members. */
8878 /* Prevent infinite recursion in cases where the type of some member of
8879 this type is expressed in terms of this type itself. */
8880 TREE_ASM_WRITTEN (type
) = 1;
8881 add_byte_size_attribute (type_die
, type
);
8882 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
8883 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
8885 /* If the first reference to this type was as the return type of an
8886 inline function, then it may not have a parent. Fix this now. */
8887 if (type_die
->die_parent
== NULL
)
8888 add_child_die (scope_die
, type_die
);
8890 push_decl_scope (type
);
8891 gen_member_die (type
, type_die
);
8894 /* GNU extension: Record what type our vtable lives in. */
8895 if (TYPE_VFIELD (type
))
8897 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
8899 gen_type_die (vtype
, context_die
);
8900 add_AT_die_ref (type_die
, DW_AT_containing_type
,
8901 lookup_type_die (vtype
));
8906 add_AT_flag (type_die
, DW_AT_declaration
, 1);
8908 /* We don't need to do this for function-local types. */
8909 if (! decl_function_context (TYPE_STUB_DECL (type
)))
8910 add_incomplete_type (type
);
8914 /* Generate a DIE for a subroutine _type_. */
8917 gen_subroutine_type_die (type
, context_die
)
8919 register dw_die_ref context_die
;
8921 register tree return_type
= TREE_TYPE (type
);
8922 register dw_die_ref subr_die
8923 = new_die (DW_TAG_subroutine_type
, scope_die_for (type
, context_die
));
8925 equate_type_number_to_die (type
, subr_die
);
8926 add_prototyped_attribute (subr_die
, type
);
8927 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
8928 gen_formal_types_die (type
, subr_die
);
8931 /* Generate a DIE for a type definition */
8934 gen_typedef_die (decl
, context_die
)
8936 register dw_die_ref context_die
;
8938 register dw_die_ref type_die
;
8939 register tree origin
;
8941 if (TREE_ASM_WRITTEN (decl
))
8943 TREE_ASM_WRITTEN (decl
) = 1;
8945 type_die
= new_die (DW_TAG_typedef
, context_die
);
8946 origin
= decl_ultimate_origin (decl
);
8948 add_abstract_origin_attribute (type_die
, origin
);
8952 add_name_and_src_coords_attributes (type_die
, decl
);
8953 if (DECL_ORIGINAL_TYPE (decl
))
8955 type
= DECL_ORIGINAL_TYPE (decl
);
8956 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
8959 type
= TREE_TYPE (decl
);
8960 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
8961 TREE_THIS_VOLATILE (decl
), context_die
);
8964 if (DECL_ABSTRACT (decl
))
8965 equate_decl_number_to_die (decl
, type_die
);
8968 /* Generate a type description DIE. */
8971 gen_type_die (type
, context_die
)
8973 register dw_die_ref context_die
;
8977 if (type
== NULL_TREE
|| type
== error_mark_node
)
8980 /* We are going to output a DIE to represent the unqualified version of
8981 this type (i.e. without any const or volatile qualifiers) so get the
8982 main variant (i.e. the unqualified version) of this type now. */
8983 type
= type_main_variant (type
);
8985 if (TREE_ASM_WRITTEN (type
))
8988 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
8989 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
8991 TREE_ASM_WRITTEN (type
) = 1;
8992 gen_decl_die (TYPE_NAME (type
), context_die
);
8996 switch (TREE_CODE (type
))
9002 case REFERENCE_TYPE
:
9003 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
9004 ensures that the gen_type_die recursion will terminate even if the
9005 type is recursive. Recursive types are possible in Ada. */
9006 /* ??? We could perhaps do this for all types before the switch
9008 TREE_ASM_WRITTEN (type
) = 1;
9010 /* For these types, all that is required is that we output a DIE (or a
9011 set of DIEs) to represent the "basis" type. */
9012 gen_type_die (TREE_TYPE (type
), context_die
);
9016 /* This code is used for C++ pointer-to-data-member types.
9017 Output a description of the relevant class type. */
9018 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
9020 /* Output a description of the type of the object pointed to. */
9021 gen_type_die (TREE_TYPE (type
), context_die
);
9023 /* Now output a DIE to represent this pointer-to-data-member type
9025 gen_ptr_to_mbr_type_die (type
, context_die
);
9029 gen_type_die (TYPE_DOMAIN (type
), context_die
);
9030 gen_set_type_die (type
, context_die
);
9034 gen_type_die (TREE_TYPE (type
), context_die
);
9035 abort (); /* No way to represent these in Dwarf yet! */
9039 /* Force out return type (in case it wasn't forced out already). */
9040 gen_type_die (TREE_TYPE (type
), context_die
);
9041 gen_subroutine_type_die (type
, context_die
);
9045 /* Force out return type (in case it wasn't forced out already). */
9046 gen_type_die (TREE_TYPE (type
), context_die
);
9047 gen_subroutine_type_die (type
, context_die
);
9051 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
9053 gen_type_die (TREE_TYPE (type
), context_die
);
9054 gen_string_type_die (type
, context_die
);
9057 gen_array_type_die (type
, context_die
);
9063 case QUAL_UNION_TYPE
:
9064 /* If this is a nested type whose containing class hasn't been
9065 written out yet, writing it out will cover this one, too.
9066 This does not apply to instantiations of member class templates;
9067 they need to be added to the containing class as they are
9068 generated. FIXME: This hurts the idea of combining type decls
9069 from multiple TUs, since we can't predict what set of template
9070 instantiations we'll get. */
9071 if (TYPE_CONTEXT (type
)
9072 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
9073 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
9075 gen_type_die (TYPE_CONTEXT (type
), context_die
);
9077 if (TREE_ASM_WRITTEN (type
))
9080 /* If that failed, attach ourselves to the stub. */
9081 push_decl_scope (TYPE_CONTEXT (type
));
9082 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
9088 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
9089 gen_enumeration_type_die (type
, context_die
);
9091 gen_struct_or_union_type_die (type
, context_die
);
9096 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9097 it up if it is ever completed. gen_*_type_die will set it for us
9098 when appropriate. */
9107 /* No DIEs needed for fundamental types. */
9111 /* No Dwarf representation currently defined. */
9118 TREE_ASM_WRITTEN (type
) = 1;
9121 /* Generate a DIE for a tagged type instantiation. */
9124 gen_tagged_type_instantiation_die (type
, context_die
)
9126 register dw_die_ref context_die
;
9128 if (type
== NULL_TREE
|| type
== error_mark_node
)
9131 /* We are going to output a DIE to represent the unqualified version of
9132 this type (i.e. without any const or volatile qualifiers) so make sure
9133 that we have the main variant (i.e. the unqualified version) of this
9135 if (type
!= type_main_variant (type
))
9138 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
9139 an instance of an unresolved type. */
9141 switch (TREE_CODE (type
))
9147 gen_inlined_enumeration_type_die (type
, context_die
);
9151 gen_inlined_structure_type_die (type
, context_die
);
9155 case QUAL_UNION_TYPE
:
9156 gen_inlined_union_type_die (type
, context_die
);
9164 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
9165 things which are local to the given block. */
9168 gen_block_die (stmt
, context_die
, depth
)
9170 register dw_die_ref context_die
;
9173 register int must_output_die
= 0;
9174 register tree origin
;
9176 register enum tree_code origin_code
;
9178 /* Ignore blocks never really used to make RTL. */
9180 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
)
9181 || (!TREE_ASM_WRITTEN (stmt
) && !BLOCK_ABSTRACT (stmt
)))
9184 /* Determine the "ultimate origin" of this block. This block may be an
9185 inlined instance of an inlined instance of inline function, so we have
9186 to trace all of the way back through the origin chain to find out what
9187 sort of node actually served as the original seed for the creation of
9188 the current block. */
9189 origin
= block_ultimate_origin (stmt
);
9190 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
9192 /* Determine if we need to output any Dwarf DIEs at all to represent this
9194 if (origin_code
== FUNCTION_DECL
)
9195 /* The outer scopes for inlinings *must* always be represented. We
9196 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9197 must_output_die
= 1;
9200 /* In the case where the current block represents an inlining of the
9201 "body block" of an inline function, we must *NOT* output any DIE for
9202 this block because we have already output a DIE to represent the
9203 whole inlined function scope and the "body block" of any function
9204 doesn't really represent a different scope according to ANSI C
9205 rules. So we check here to make sure that this block does not
9206 represent a "body block inlining" before trying to set the
9207 `must_output_die' flag. */
9208 if (! is_body_block (origin
? origin
: stmt
))
9210 /* Determine if this block directly contains any "significant"
9211 local declarations which we will need to output DIEs for. */
9212 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9213 /* We are not in terse mode so *any* local declaration counts
9214 as being a "significant" one. */
9215 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
9217 /* We are in terse mode, so only local (nested) function
9218 definitions count as "significant" local declarations. */
9219 for (decl
= BLOCK_VARS (stmt
);
9220 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
9221 if (TREE_CODE (decl
) == FUNCTION_DECL
9222 && DECL_INITIAL (decl
))
9224 must_output_die
= 1;
9230 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9231 DIE for any block which contains no significant local declarations at
9232 all. Rather, in such cases we just call `decls_for_scope' so that any
9233 needed Dwarf info for any sub-blocks will get properly generated. Note
9234 that in terse mode, our definition of what constitutes a "significant"
9235 local declaration gets restricted to include only inlined function
9236 instances and local (nested) function definitions. */
9237 if (must_output_die
)
9239 if (origin_code
== FUNCTION_DECL
)
9240 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
9242 gen_lexical_block_die (stmt
, context_die
, depth
);
9245 decls_for_scope (stmt
, context_die
, depth
);
9248 /* Generate all of the decls declared within a given scope and (recursively)
9249 all of its sub-blocks. */
9252 decls_for_scope (stmt
, context_die
, depth
)
9254 register dw_die_ref context_die
;
9258 register tree subblocks
;
9260 /* Ignore blocks never really used to make RTL. */
9261 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
9264 /* Output the DIEs to represent all of the data objects and typedefs
9265 declared directly within this block but not within any nested
9266 sub-blocks. Also, nested function and tag DIEs have been
9267 generated with a parent of NULL; fix that up now. */
9268 for (decl
= BLOCK_VARS (stmt
);
9269 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
9271 register dw_die_ref die
;
9273 if (TREE_CODE (decl
) == FUNCTION_DECL
)
9274 die
= lookup_decl_die (decl
);
9275 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
9276 die
= lookup_type_die (TREE_TYPE (decl
));
9280 if (die
!= NULL
&& die
->die_parent
== NULL
)
9281 add_child_die (context_die
, die
);
9283 gen_decl_die (decl
, context_die
);
9286 /* Output the DIEs to represent all sub-blocks (and the items declared
9287 therein) of this block. */
9288 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
9290 subblocks
= BLOCK_CHAIN (subblocks
))
9291 gen_block_die (subblocks
, context_die
, depth
+ 1);
9294 /* Is this a typedef we can avoid emitting? */
9297 is_redundant_typedef (decl
)
9300 if (TYPE_DECL_IS_STUB (decl
))
9303 if (DECL_ARTIFICIAL (decl
)
9304 && DECL_CONTEXT (decl
)
9305 && is_tagged_type (DECL_CONTEXT (decl
))
9306 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
9307 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
9308 /* Also ignore the artificial member typedef for the class name. */
9314 /* Generate Dwarf debug information for a decl described by DECL. */
9317 gen_decl_die (decl
, context_die
)
9319 register dw_die_ref context_die
;
9321 register tree origin
;
9323 if (TREE_CODE (decl
) == ERROR_MARK
)
9326 /* If this ..._DECL node is marked to be ignored, then ignore it. */
9327 if (DECL_IGNORED_P (decl
))
9330 switch (TREE_CODE (decl
))
9333 /* The individual enumerators of an enum type get output when we output
9334 the Dwarf representation of the relevant enum type itself. */
9338 /* Don't output any DIEs to represent mere function declarations,
9339 unless they are class members or explicit block externs. */
9340 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
9341 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
9344 /* If we're emitting an out-of-line copy of an inline function,
9345 emit info for the abstract instance and set up to refer to it. */
9346 if (DECL_INLINE (decl
) && ! DECL_ABSTRACT (decl
)
9347 && ! class_scope_p (context_die
))
9349 gen_abstract_function (decl
);
9350 set_decl_origin_self (decl
);
9353 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9355 /* Before we describe the FUNCTION_DECL itself, make sure that we
9356 have described its return type. */
9357 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
9359 /* And its virtual context. */
9360 if (DECL_VINDEX (decl
) != NULL_TREE
)
9361 gen_type_die (DECL_CONTEXT (decl
), context_die
);
9363 /* And its containing type. */
9364 origin
= decl_class_context (decl
);
9365 if (origin
!= NULL_TREE
)
9366 gen_type_die_for_member (origin
, decl
, context_die
);
9369 /* Now output a DIE to represent the function itself. */
9370 gen_subprogram_die (decl
, context_die
);
9374 /* If we are in terse mode, don't generate any DIEs to represent any
9376 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9379 /* In the special case of a TYPE_DECL node representing the
9380 declaration of some type tag, if the given TYPE_DECL is marked as
9381 having been instantiated from some other (original) TYPE_DECL node
9382 (e.g. one which was generated within the original definition of an
9383 inline function) we have to generate a special (abbreviated)
9384 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9386 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
9388 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
9392 if (is_redundant_typedef (decl
))
9393 gen_type_die (TREE_TYPE (decl
), context_die
);
9395 /* Output a DIE to represent the typedef itself. */
9396 gen_typedef_die (decl
, context_die
);
9400 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
9401 gen_label_die (decl
, context_die
);
9405 /* If we are in terse mode, don't generate any DIEs to represent any
9406 variable declarations or definitions. */
9407 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9410 /* Output any DIEs that are needed to specify the type of this data
9412 gen_type_die (TREE_TYPE (decl
), context_die
);
9414 /* And its containing type. */
9415 origin
= decl_class_context (decl
);
9416 if (origin
!= NULL_TREE
)
9417 gen_type_die_for_member (origin
, decl
, context_die
);
9419 /* Now output the DIE to represent the data object itself. This gets
9420 complicated because of the possibility that the VAR_DECL really
9421 represents an inlined instance of a formal parameter for an inline
9423 origin
= decl_ultimate_origin (decl
);
9424 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
9425 gen_formal_parameter_die (decl
, context_die
);
9427 gen_variable_die (decl
, context_die
);
9431 /* Ignore the nameless fields that are used to skip bits, but
9432 handle C++ anonymous unions. */
9433 if (DECL_NAME (decl
) != NULL_TREE
9434 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
)
9436 gen_type_die (member_declared_type (decl
), context_die
);
9437 gen_field_die (decl
, context_die
);
9442 gen_type_die (TREE_TYPE (decl
), context_die
);
9443 gen_formal_parameter_die (decl
, context_die
);
9446 case NAMESPACE_DECL
:
9447 /* Ignore for now. */
9455 /* Add Ada "use" clause information for SGI Workshop debugger. */
9458 dwarf2out_add_library_unit_info (filename
, context_list
)
9459 const char *filename
;
9460 const char *context_list
;
9462 unsigned int file_index
;
9464 if (filename
!= NULL
)
9466 dw_die_ref unit_die
= new_die (DW_TAG_module
, comp_unit_die
);
9467 tree context_list_decl
9468 = build_decl (LABEL_DECL
, get_identifier (context_list
),
9471 TREE_PUBLIC (context_list_decl
) = TRUE
;
9472 add_name_attribute (unit_die
, context_list
);
9473 file_index
= lookup_filename (filename
);
9474 add_AT_unsigned (unit_die
, DW_AT_decl_file
, file_index
);
9475 add_pubname (context_list_decl
, unit_die
);
9479 /* Write the debugging output for DECL. */
9482 dwarf2out_decl (decl
)
9485 register dw_die_ref context_die
= comp_unit_die
;
9487 if (TREE_CODE (decl
) == ERROR_MARK
)
9490 /* If this ..._DECL node is marked to be ignored, then ignore it. */
9491 if (DECL_IGNORED_P (decl
))
9494 switch (TREE_CODE (decl
))
9497 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9498 builtin function. Explicit programmer-supplied declarations of
9499 these same functions should NOT be ignored however. */
9500 if (DECL_EXTERNAL (decl
) && DECL_BUILT_IN (decl
))
9503 /* What we would really like to do here is to filter out all mere
9504 file-scope declarations of file-scope functions which are never
9505 referenced later within this translation unit (and keep all of ones
9506 that *are* referenced later on) but we aren't clairvoyant, so we have
9507 no idea which functions will be referenced in the future (i.e. later
9508 on within the current translation unit). So here we just ignore all
9509 file-scope function declarations which are not also definitions. If
9510 and when the debugger needs to know something about these functions,
9511 it will have to hunt around and find the DWARF information associated
9512 with the definition of the function. Note that we can't just check
9513 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9514 definitions and which ones represent mere declarations. We have to
9515 check `DECL_INITIAL' instead. That's because the C front-end
9516 supports some weird semantics for "extern inline" function
9517 definitions. These can get inlined within the current translation
9518 unit (an thus, we need to generate DWARF info for their abstract
9519 instances so that the DWARF info for the concrete inlined instances
9520 can have something to refer to) but the compiler never generates any
9521 out-of-lines instances of such things (despite the fact that they
9522 *are* definitions). The important point is that the C front-end
9523 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9524 to generate DWARF for them anyway. Note that the C++ front-end also
9525 plays some similar games for inline function definitions appearing
9526 within include files which also contain
9527 `#pragma interface' pragmas. */
9528 if (DECL_INITIAL (decl
) == NULL_TREE
)
9531 /* If we're a nested function, initially use a parent of NULL; if we're
9532 a plain function, this will be fixed up in decls_for_scope. If
9533 we're a method, it will be ignored, since we already have a DIE. */
9534 if (decl_function_context (decl
))
9540 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9541 declaration and if the declaration was never even referenced from
9542 within this entire compilation unit. We suppress these DIEs in
9543 order to save space in the .debug section (by eliminating entries
9544 which are probably useless). Note that we must not suppress
9545 block-local extern declarations (whether used or not) because that
9546 would screw-up the debugger's name lookup mechanism and cause it to
9547 miss things which really ought to be in scope at a given point. */
9548 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
9551 /* If we are in terse mode, don't generate any DIEs to represent any
9552 variable declarations or definitions. */
9553 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9558 /* Don't emit stubs for types unless they are needed by other DIEs. */
9559 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
9562 /* Don't bother trying to generate any DIEs to represent any of the
9563 normal built-in types for the language we are compiling. */
9564 if (DECL_SOURCE_LINE (decl
) == 0)
9566 /* OK, we need to generate one for `bool' so GDB knows what type
9567 comparisons have. */
9568 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
9569 == DW_LANG_C_plus_plus
)
9570 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
)
9571 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
9576 /* If we are in terse mode, don't generate any DIEs for types. */
9577 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9580 /* If we're a function-scope tag, initially use a parent of NULL;
9581 this will be fixed up in decls_for_scope. */
9582 if (decl_function_context (decl
))
9591 gen_decl_die (decl
, context_die
);
9594 /* Output a marker (i.e. a label) for the beginning of the generated code for
9598 dwarf2out_begin_block (blocknum
)
9599 register unsigned blocknum
;
9601 function_section (current_function_decl
);
9602 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
9605 /* Output a marker (i.e. a label) for the end of the generated code for a
9609 dwarf2out_end_block (blocknum
)
9610 register unsigned blocknum
;
9612 function_section (current_function_decl
);
9613 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
9616 /* Returns nonzero if it is appropriate not to emit any debugging
9617 information for BLOCK, because it doesn't contain any instructions.
9619 Don't allow this for blocks with nested functions or local classes
9620 as we would end up with orphans, and in the presence of scheduling
9621 we may end up calling them anyway. */
9624 dwarf2out_ignore_block (block
)
9628 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
9629 if (TREE_CODE (decl
) == FUNCTION_DECL
9630 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
9635 /* Output a marker (i.e. a label) at a point in the assembly code which
9636 corresponds to a given source level label. */
9639 dwarf2out_label (insn
)
9642 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9644 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
9646 function_section (current_function_decl
);
9647 sprintf (label
, INSN_LABEL_FMT
, current_funcdef_number
);
9648 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, label
,
9649 (unsigned) INSN_UID (insn
));
9653 /* Lookup a filename (in the list of filenames that we know about here in
9654 dwarf2out.c) and return its "index". The index of each (known) filename is
9655 just a unique number which is associated with only that one filename.
9656 We need such numbers for the sake of generating labels
9657 (in the .debug_sfnames section) and references to those
9658 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9659 If the filename given as an argument is not found in our current list,
9660 add it to the list and assign it the next available unique index number.
9661 In order to speed up searches, we remember the index of the filename
9662 was looked up last. This handles the majority of all searches. */
9665 lookup_filename (file_name
)
9666 const char *file_name
;
9668 static unsigned last_file_lookup_index
= 0;
9669 register unsigned i
;
9671 /* Check to see if the file name that was searched on the previous call
9672 matches this file name. If so, return the index. */
9673 if (last_file_lookup_index
!= 0)
9674 if (strcmp (file_name
, file_table
[last_file_lookup_index
]) == 0)
9675 return last_file_lookup_index
;
9677 /* Didn't match the previous lookup, search the table */
9678 for (i
= 1; i
< file_table_in_use
; ++i
)
9679 if (strcmp (file_name
, file_table
[i
]) == 0)
9681 last_file_lookup_index
= i
;
9685 /* Prepare to add a new table entry by making sure there is enough space in
9686 the table to do so. If not, expand the current table. */
9687 if (file_table_in_use
== file_table_allocated
)
9689 file_table_allocated
+= FILE_TABLE_INCREMENT
;
9691 = (char **) xrealloc (file_table
,
9692 file_table_allocated
* sizeof (char *));
9695 /* Add the new entry to the end of the filename table. */
9696 file_table
[file_table_in_use
] = xstrdup (file_name
);
9697 last_file_lookup_index
= file_table_in_use
++;
9699 return last_file_lookup_index
;
9702 /* Output a label to mark the beginning of a source code line entry
9703 and record information relating to this source line, in
9704 'line_info_table' for later output of the .debug_line section. */
9707 dwarf2out_line (filename
, line
)
9708 register const char *filename
;
9709 register unsigned line
;
9711 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
9713 function_section (current_function_decl
);
9715 if (DWARF2_ASM_LINE_DEBUG_INFO
)
9717 static const char *lastfile
;
9719 /* Emit the .file and .loc directives understood by GNU as. */
9720 if (lastfile
== 0 || strcmp (filename
, lastfile
))
9723 ggc_add_string_root ((char **) &lastfile
, 1);
9725 fprintf (asm_out_file
, "\t.file 0 \"%s\"\n", filename
);
9726 lastfile
= filename
;
9729 fprintf (asm_out_file
, "\t.loc 0 %d 0\n", line
);
9731 /* Indicate that line number info exists. */
9732 ++line_info_table_in_use
;
9734 /* Indicate that multiple line number tables exist. */
9735 if (DECL_SECTION_NAME (current_function_decl
))
9736 ++separate_line_info_table_in_use
;
9738 else if (DECL_SECTION_NAME (current_function_decl
))
9740 register dw_separate_line_info_ref line_info
;
9741 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
9742 separate_line_info_table_in_use
);
9744 fprintf (asm_out_file
, "\t%s line %d", ASM_COMMENT_START
, line
);
9745 fputc ('\n', asm_out_file
);
9747 /* expand the line info table if necessary */
9748 if (separate_line_info_table_in_use
9749 == separate_line_info_table_allocated
)
9751 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
9752 separate_line_info_table
9753 = (dw_separate_line_info_ref
)
9754 xrealloc (separate_line_info_table
,
9755 separate_line_info_table_allocated
9756 * sizeof (dw_separate_line_info_entry
));
9759 /* Add the new entry at the end of the line_info_table. */
9761 = &separate_line_info_table
[separate_line_info_table_in_use
++];
9762 line_info
->dw_file_num
= lookup_filename (filename
);
9763 line_info
->dw_line_num
= line
;
9764 line_info
->function
= current_funcdef_number
;
9768 register dw_line_info_ref line_info
;
9770 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, LINE_CODE_LABEL
,
9771 line_info_table_in_use
);
9773 fprintf (asm_out_file
, "\t%s line %d", ASM_COMMENT_START
, line
);
9774 fputc ('\n', asm_out_file
);
9776 /* Expand the line info table if necessary. */
9777 if (line_info_table_in_use
== line_info_table_allocated
)
9779 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
9781 = (dw_line_info_ref
)
9782 xrealloc (line_info_table
,
9783 (line_info_table_allocated
9784 * sizeof (dw_line_info_entry
)));
9787 /* Add the new entry at the end of the line_info_table. */
9788 line_info
= &line_info_table
[line_info_table_in_use
++];
9789 line_info
->dw_file_num
= lookup_filename (filename
);
9790 line_info
->dw_line_num
= line
;
9795 /* Record the beginning of a new source file, for later output
9796 of the .debug_macinfo section. At present, unimplemented. */
9799 dwarf2out_start_source_file (filename
)
9800 register const char *filename ATTRIBUTE_UNUSED
;
9804 /* Record the end of a source file, for later output
9805 of the .debug_macinfo section. At present, unimplemented. */
9808 dwarf2out_end_source_file ()
9812 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9813 the tail part of the directive line, i.e. the part which is past the
9814 initial whitespace, #, whitespace, directive-name, whitespace part. */
9817 dwarf2out_define (lineno
, buffer
)
9818 register unsigned lineno ATTRIBUTE_UNUSED
;
9819 register const char *buffer ATTRIBUTE_UNUSED
;
9821 static int initialized
= 0;
9824 dwarf2out_start_source_file (primary_filename
);
9829 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9830 the tail part of the directive line, i.e. the part which is past the
9831 initial whitespace, #, whitespace, directive-name, whitespace part. */
9834 dwarf2out_undef (lineno
, buffer
)
9835 register unsigned lineno ATTRIBUTE_UNUSED
;
9836 register const char *buffer ATTRIBUTE_UNUSED
;
9840 /* Set up for Dwarf output at the start of compilation. */
9843 dwarf2out_init (asm_out_file
, main_input_filename
)
9844 register FILE *asm_out_file
;
9845 register const char *main_input_filename
;
9847 /* Remember the name of the primary input file. */
9848 primary_filename
= main_input_filename
;
9850 /* Allocate the initial hunk of the file_table. */
9851 file_table
= (char **) xcalloc (FILE_TABLE_INCREMENT
, sizeof (char *));
9852 file_table_allocated
= FILE_TABLE_INCREMENT
;
9854 /* Skip the first entry - file numbers begin at 1. */
9855 file_table_in_use
= 1;
9857 /* Allocate the initial hunk of the decl_die_table. */
9859 = (dw_die_ref
*) xcalloc (DECL_DIE_TABLE_INCREMENT
, sizeof (dw_die_ref
));
9860 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
9861 decl_die_table_in_use
= 0;
9863 /* Allocate the initial hunk of the decl_scope_table. */
9865 = (tree
*) xcalloc (DECL_SCOPE_TABLE_INCREMENT
, sizeof (tree
));
9866 decl_scope_table_allocated
= DECL_SCOPE_TABLE_INCREMENT
;
9867 decl_scope_depth
= 0;
9869 /* Allocate the initial hunk of the abbrev_die_table. */
9871 = (dw_die_ref
*) xcalloc (ABBREV_DIE_TABLE_INCREMENT
,
9872 sizeof (dw_die_ref
));
9873 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
9874 /* Zero-th entry is allocated, but unused */
9875 abbrev_die_table_in_use
= 1;
9877 /* Allocate the initial hunk of the line_info_table. */
9879 = (dw_line_info_ref
) xcalloc (LINE_INFO_TABLE_INCREMENT
,
9880 sizeof (dw_line_info_entry
));
9881 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
9882 /* Zero-th entry is allocated, but unused */
9883 line_info_table_in_use
= 1;
9885 /* Generate the initial DIE for the .debug section. Note that the (string)
9886 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9887 will (typically) be a relative pathname and that this pathname should be
9888 taken as being relative to the directory from which the compiler was
9889 invoked when the given (base) source file was compiled. */
9890 comp_unit_die
= gen_compile_unit_die (main_input_filename
);
9894 VARRAY_RTX_INIT (used_rtx_varray
, 32, "used_rtx_varray");
9895 ggc_add_rtx_varray_root (&used_rtx_varray
, 1);
9898 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
9899 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
, ABBREV_SECTION_LABEL
, 0);
9900 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
9901 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
9903 strcpy (text_section_label
, stripattributes (TEXT_SECTION
));
9904 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
9905 DEBUG_INFO_SECTION_LABEL
, 0);
9906 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
9907 DEBUG_LINE_SECTION_LABEL
, 0);
9909 ASM_OUTPUT_SECTION (asm_out_file
, ABBREV_SECTION
);
9910 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
9911 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
9913 ASM_OUTPUT_SECTION (asm_out_file
, TEXT_SECTION
);
9914 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
9916 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_INFO_SECTION
);
9917 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
9918 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_LINE_SECTION
);
9919 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
9922 /* Output stuff that dwarf requires at the end of every file,
9923 and generate the DWARF-2 debugging info. */
9928 limbo_die_node
*node
, *next_node
;
9931 /* Traverse the limbo die list, and add parent/child links. The only
9932 dies without parents that should be here are concrete instances of
9933 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9934 For concrete instances, we can get the parent die from the abstract
9936 for (node
= limbo_die_list
; node
; node
= next_node
)
9938 next_node
= node
->next
;
9941 if (die
->die_parent
== NULL
)
9943 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
9945 add_child_die (origin
->die_parent
, die
);
9946 else if (die
== comp_unit_die
)
9953 limbo_die_list
= NULL
;
9955 /* Walk through the list of incomplete types again, trying once more to
9956 emit full debugging info for them. */
9957 retry_incomplete_types ();
9959 /* Traverse the DIE's, reverse their lists of attributes and children,
9960 and add add sibling attributes to those DIE's that have children. */
9961 add_sibling_attributes (comp_unit_die
);
9963 /* Output a terminator label for the .text section. */
9964 fputc ('\n', asm_out_file
);
9965 ASM_OUTPUT_SECTION (asm_out_file
, TEXT_SECTION
);
9966 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, TEXT_END_LABEL
, 0);
9969 /* Output a terminator label for the .data section. */
9970 fputc ('\n', asm_out_file
);
9971 ASM_OUTPUT_SECTION (asm_out_file
, DATA_SECTION
);
9972 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, DATA_END_LABEL
, 0);
9974 /* Output a terminator label for the .bss section. */
9975 fputc ('\n', asm_out_file
);
9976 ASM_OUTPUT_SECTION (asm_out_file
, BSS_SECTION
);
9977 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BSS_END_LABEL
, 0);
9980 /* Output the source line correspondence table. */
9981 if (line_info_table_in_use
> 1 || separate_line_info_table_in_use
)
9983 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
9985 fputc ('\n', asm_out_file
);
9986 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_LINE_SECTION
);
9987 output_line_info ();
9990 /* We can only use the low/high_pc attributes if all of the code
9992 if (separate_line_info_table_in_use
== 0)
9994 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
9995 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
9998 add_AT_lbl_offset (comp_unit_die
, DW_AT_stmt_list
,
9999 debug_line_section_label
);
10002 #if 0 /* unimplemented */
10003 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
&& primary
)
10004 add_AT_unsigned (die
, DW_AT_macro_info
, 0);
10007 /* Output the abbreviation table. */
10008 fputc ('\n', asm_out_file
);
10009 ASM_OUTPUT_SECTION (asm_out_file
, ABBREV_SECTION
);
10010 build_abbrev_table (comp_unit_die
);
10011 output_abbrev_section ();
10013 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10014 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
10015 calc_die_sizes (comp_unit_die
);
10017 /* Output debugging information. */
10018 fputc ('\n', asm_out_file
);
10019 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_INFO_SECTION
);
10020 output_compilation_unit_header ();
10021 output_die (comp_unit_die
);
10023 if (pubname_table_in_use
)
10025 /* Output public names table. */
10026 fputc ('\n', asm_out_file
);
10027 ASM_OUTPUT_SECTION (asm_out_file
, PUBNAMES_SECTION
);
10028 output_pubnames ();
10031 /* We only put functions in the arange table, so don't write it out if
10032 we don't have any. */
10033 if (fde_table_in_use
)
10035 /* Output the address range information. */
10036 fputc ('\n', asm_out_file
);
10037 ASM_OUTPUT_SECTION (asm_out_file
, ARANGES_SECTION
);
10041 #endif /* DWARF2_DEBUGGING_INFO */