1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 93, 95, 96, 97, 1998 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com).
4 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /* The first part of this file deals with the DWARF 2 frame unwind
24 information, which is also used by the GCC efficient exception handling
25 mechanism. The second part, controlled only by an #ifdef
26 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
35 #include "hard-reg-set.h"
37 #include "insn-config.h"
44 /* We cannot use <assert.h> in GCC source, since that would include
45 GCC's assert.h, which may not be compatible with the host compiler. */
50 # define assert(e) do { if (! (e)) abort (); } while (0)
53 /* Decide whether we want to emit frame unwind information for the current
59 return (write_symbols
== DWARF2_DEBUG
60 #ifdef DWARF2_UNWIND_INFO
61 || (flag_exceptions
&& ! exceptions_via_longjmp
)
66 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
72 /* How to start an assembler comment. */
73 #ifndef ASM_COMMENT_START
74 #define ASM_COMMENT_START ";#"
77 typedef struct dw_cfi_struct
*dw_cfi_ref
;
78 typedef struct dw_fde_struct
*dw_fde_ref
;
79 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
81 /* Call frames are described using a sequence of Call Frame
82 Information instructions. The register number, offset
83 and address fields are provided as possible operands;
84 their use is selected by the opcode field. */
86 typedef union dw_cfi_oprnd_struct
88 unsigned long dw_cfi_reg_num
;
89 long int dw_cfi_offset
;
94 typedef struct dw_cfi_struct
96 dw_cfi_ref dw_cfi_next
;
97 enum dwarf_call_frame_info dw_cfi_opc
;
98 dw_cfi_oprnd dw_cfi_oprnd1
;
99 dw_cfi_oprnd dw_cfi_oprnd2
;
103 /* All call frame descriptions (FDE's) in the GCC generated DWARF
104 refer to a single Common Information Entry (CIE), defined at
105 the beginning of the .debug_frame section. This used of a single
106 CIE obviates the need to keep track of multiple CIE's
107 in the DWARF generation routines below. */
109 typedef struct dw_fde_struct
112 char *dw_fde_current_label
;
114 dw_cfi_ref dw_fde_cfi
;
118 /* Maximum size (in bytes) of an artificially generated label. */
119 #define MAX_ARTIFICIAL_LABEL_BYTES 30
121 /* Make sure we know the sizes of the various types dwarf can describe. These
122 are only defaults. If the sizes are different for your target, you should
123 override these values by defining the appropriate symbols in your tm.h
126 #ifndef CHAR_TYPE_SIZE
127 #define CHAR_TYPE_SIZE BITS_PER_UNIT
130 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
133 /* The size in bytes of a DWARF field indicating an offset or length
134 relative to a debug info section, specified to be 4 bytes in the DWARF-2
135 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
137 #ifndef DWARF_OFFSET_SIZE
138 #define DWARF_OFFSET_SIZE 4
141 #define DWARF_VERSION 2
143 /* Round SIZE up to the nearest BOUNDARY. */
144 #define DWARF_ROUND(SIZE,BOUNDARY) \
145 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
147 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
148 #ifdef STACK_GROWS_DOWNWARD
149 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
151 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
154 /* A pointer to the base of a table that contains frame description
155 information for each routine. */
156 static dw_fde_ref fde_table
;
158 /* Number of elements currently allocated for fde_table. */
159 static unsigned fde_table_allocated
;
161 /* Number of elements in fde_table currently in use. */
162 static unsigned fde_table_in_use
;
164 /* Size (in elements) of increments by which we may expand the
166 #define FDE_TABLE_INCREMENT 256
168 /* A list of call frame insns for the CIE. */
169 static dw_cfi_ref cie_cfi_head
;
171 /* The number of the current function definition for which debugging
172 information is being generated. These numbers range from 1 up to the
173 maximum number of function definitions contained within the current
174 compilation unit. These numbers are used to create unique label id's
175 unique to each function definition. */
176 static unsigned current_funcdef_number
= 0;
178 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
179 attribute that accelerates the lookup of the FDE associated
180 with the subprogram. This variable holds the table index of the FDE
181 associated with the current function (body) definition. */
182 static unsigned current_funcdef_fde
;
184 /* Forward declarations for functions defined in this file. */
186 static char *stripattributes
PROTO((char *));
187 static char *dwarf_cfi_name
PROTO((unsigned));
188 static dw_cfi_ref new_cfi
PROTO((void));
189 static void add_cfi
PROTO((dw_cfi_ref
*, dw_cfi_ref
));
190 static unsigned long size_of_uleb128
PROTO((unsigned long));
191 static unsigned long size_of_sleb128
PROTO((long));
192 static void output_uleb128
PROTO((unsigned long));
193 static void output_sleb128
PROTO((long));
194 static void add_fde_cfi
PROTO((char *, dw_cfi_ref
));
195 static void lookup_cfa_1
PROTO((dw_cfi_ref
, unsigned long *,
197 static void lookup_cfa
PROTO((unsigned long *, long *));
198 static void reg_save
PROTO((char *, unsigned, unsigned,
200 static void initial_return_save
PROTO((rtx
));
201 static void output_cfi
PROTO((dw_cfi_ref
, dw_fde_ref
));
202 static void output_call_frame_info
PROTO((int));
203 static unsigned reg_number
PROTO((rtx
));
205 /* Definitions of defaults for assembler-dependent names of various
206 pseudo-ops and section names.
207 Theses may be overridden in the tm.h file (if necessary) for a particular
210 #ifdef OBJECT_FORMAT_ELF
211 #ifndef UNALIGNED_SHORT_ASM_OP
212 #define UNALIGNED_SHORT_ASM_OP ".2byte"
214 #ifndef UNALIGNED_INT_ASM_OP
215 #define UNALIGNED_INT_ASM_OP ".4byte"
217 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
218 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
220 #endif /* OBJECT_FORMAT_ELF */
223 #define ASM_BYTE_OP ".byte"
226 /* Data and reference forms for relocatable data. */
227 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
228 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
230 /* Pseudo-op for defining a new section. */
231 #ifndef SECTION_ASM_OP
232 #define SECTION_ASM_OP ".section"
235 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
236 print the SECTION_ASM_OP and the section name. The default here works for
237 almost all svr4 assemblers, except for the sparc, where the section name
238 must be enclosed in double quotes. (See sparcv4.h). */
239 #ifndef SECTION_FORMAT
240 #ifdef PUSHSECTION_FORMAT
241 #define SECTION_FORMAT PUSHSECTION_FORMAT
243 #define SECTION_FORMAT "\t%s\t%s\n"
247 #ifndef FRAME_SECTION
248 #define FRAME_SECTION ".debug_frame"
251 #ifndef FUNC_BEGIN_LABEL
252 #define FUNC_BEGIN_LABEL "LFB"
254 #ifndef FUNC_END_LABEL
255 #define FUNC_END_LABEL "LFE"
257 #define CIE_AFTER_SIZE_LABEL "LSCIE"
258 #define CIE_END_LABEL "LECIE"
259 #define CIE_LENGTH_LABEL "LLCIE"
260 #define FDE_AFTER_SIZE_LABEL "LSFDE"
261 #define FDE_END_LABEL "LEFDE"
262 #define FDE_LENGTH_LABEL "LLFDE"
264 /* Definitions of defaults for various types of primitive assembly language
265 output operations. These may be overridden from within the tm.h file,
266 but typically, that is unnecessary. */
268 #ifndef ASM_OUTPUT_SECTION
269 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
270 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
273 #ifndef ASM_OUTPUT_DWARF_DATA1
274 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
275 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
278 #ifndef ASM_OUTPUT_DWARF_DELTA1
279 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
280 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
281 assemble_name (FILE, LABEL1); \
282 fprintf (FILE, "-"); \
283 assemble_name (FILE, LABEL2); \
287 #ifdef UNALIGNED_INT_ASM_OP
289 #ifndef UNALIGNED_OFFSET_ASM_OP
290 #define UNALIGNED_OFFSET_ASM_OP \
291 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
294 #ifndef UNALIGNED_WORD_ASM_OP
295 #define UNALIGNED_WORD_ASM_OP \
296 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
299 #ifndef ASM_OUTPUT_DWARF_DELTA2
300 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
301 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
302 assemble_name (FILE, LABEL1); \
303 fprintf (FILE, "-"); \
304 assemble_name (FILE, LABEL2); \
308 #ifndef ASM_OUTPUT_DWARF_DELTA4
309 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
310 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
311 assemble_name (FILE, LABEL1); \
312 fprintf (FILE, "-"); \
313 assemble_name (FILE, LABEL2); \
317 #ifndef ASM_OUTPUT_DWARF_DELTA
318 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
319 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
320 assemble_name (FILE, LABEL1); \
321 fprintf (FILE, "-"); \
322 assemble_name (FILE, LABEL2); \
326 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
327 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
328 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
329 assemble_name (FILE, LABEL1); \
330 fprintf (FILE, "-"); \
331 assemble_name (FILE, LABEL2); \
335 #ifndef ASM_OUTPUT_DWARF_ADDR
336 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
337 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
338 assemble_name (FILE, LABEL); \
342 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
343 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
344 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
347 #ifndef ASM_OUTPUT_DWARF_OFFSET4
348 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
349 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
350 assemble_name (FILE, LABEL); \
354 #ifndef ASM_OUTPUT_DWARF_OFFSET
355 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
356 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
357 assemble_name (FILE, LABEL); \
361 #ifndef ASM_OUTPUT_DWARF_DATA2
362 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
363 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
366 #ifndef ASM_OUTPUT_DWARF_DATA4
367 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
368 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
371 #ifndef ASM_OUTPUT_DWARF_DATA
372 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
373 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
374 (unsigned long) VALUE)
377 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
378 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
379 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
380 (unsigned long) VALUE)
383 #ifndef ASM_OUTPUT_DWARF_DATA8
384 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
386 if (WORDS_BIG_ENDIAN) \
388 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
389 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
393 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
394 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
399 #else /* UNALIGNED_INT_ASM_OP */
401 /* We don't have unaligned support, let's hope the normal output works for
404 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
405 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), PTR_SIZE, 1)
407 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
408 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
410 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
411 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
413 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
414 assemble_integer (gen_rtx_MINUS (HImode, \
415 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
416 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
419 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
420 assemble_integer (gen_rtx_MINUS (SImode, \
421 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
422 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
425 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
426 assemble_integer (gen_rtx_MINUS (Pmode, \
427 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
428 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
431 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
432 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
434 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
435 assemble_integer (GEN_INT (VALUE), 4, 1)
437 #endif /* UNALIGNED_INT_ASM_OP */
440 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
441 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
443 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
444 assemble_name (FILE, SY); \
446 assemble_name (FILE, HI); \
448 assemble_name (FILE, LO); \
451 #endif /* SET_ASM_OP */
453 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
454 newline is produced. When flag_debug_asm is asserted, we add commentary
455 at the end of the line, so we must avoid output of a newline here. */
456 #ifndef ASM_OUTPUT_DWARF_STRING
457 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
459 register int slen = strlen(P); \
460 register char *p = (P); \
462 fprintf (FILE, "\t.ascii \""); \
463 for (i = 0; i < slen; i++) \
465 register int c = p[i]; \
466 if (c == '\"' || c == '\\') \
468 if (c >= ' ' && c < 0177) \
472 fprintf (FILE, "\\%o", c); \
475 fprintf (FILE, "\\0\""); \
480 /* The DWARF 2 CFA column which tracks the return address. Normally this
481 is the column for PC, or the first column after all of the hard
483 #ifndef DWARF_FRAME_RETURN_COLUMN
485 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
487 #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER
491 /* The mapping from gcc register number to DWARF 2 CFA column number. By
492 default, we just provide columns for all registers. */
493 #ifndef DWARF_FRAME_REGNUM
494 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
497 /* Hook used by __throw. */
500 expand_builtin_dwarf_fp_regnum ()
502 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
));
505 /* The offset from the incoming value of %sp to the top of the stack frame
506 for the current function. */
507 #ifndef INCOMING_FRAME_SP_OFFSET
508 #define INCOMING_FRAME_SP_OFFSET 0
511 /* Return a pointer to a copy of the section string name S with all
512 attributes stripped off. */
518 char *stripped
= xstrdup (s
);
521 while (*p
&& *p
!= ',')
528 /* Return the register number described by a given RTL node. */
534 register unsigned regno
= REGNO (rtl
);
536 if (regno
>= FIRST_PSEUDO_REGISTER
)
538 warning ("internal regno botch: regno = %d\n", regno
);
542 regno
= DBX_REGISTER_NUMBER (regno
);
546 struct reg_size_range
553 /* Given a register number in REG_TREE, return an rtx for its size in bytes.
554 We do this in kind of a roundabout way, by building up a list of
555 register size ranges and seeing where our register falls in one of those
556 ranges. We need to do it this way because REG_TREE is not a constant,
557 and the target macros were not designed to make this task easy. */
560 expand_builtin_dwarf_reg_size (reg_tree
, target
)
564 enum machine_mode mode
;
566 struct reg_size_range ranges
[5];
573 for (; i
< FIRST_PSEUDO_REGISTER
; ++i
)
575 /* The return address is out of order on the MIPS, and we don't use
576 copy_reg for it anyway, so we don't care here how large it is. */
577 if (DWARF_FRAME_REGNUM (i
) == DWARF_FRAME_RETURN_COLUMN
)
580 mode
= reg_raw_mode
[i
];
582 /* CCmode is arbitrarily given a size of 4 bytes. It is more useful
583 to use the same size as word_mode, since that reduces the number
584 of ranges we need. It should not matter, since the result should
585 never be used for a condition code register anyways. */
586 if (GET_MODE_CLASS (mode
) == MODE_CC
)
589 size
= GET_MODE_SIZE (mode
);
591 /* If this register is not valid in the specified mode and
592 we have a previous size, use that for the size of this
593 register to avoid making junk tiny ranges. */
594 if (! HARD_REGNO_MODE_OK (i
, mode
) && last_size
!= -1)
597 if (size
!= last_size
)
599 ranges
[n_ranges
].beg
= i
;
600 ranges
[n_ranges
].size
= last_size
= size
;
605 ranges
[n_ranges
-1].end
= i
;
608 /* The usual case: fp regs surrounded by general regs. */
609 if (n_ranges
== 3 && ranges
[0].size
== ranges
[2].size
)
611 if ((DWARF_FRAME_REGNUM (ranges
[1].end
)
612 - DWARF_FRAME_REGNUM (ranges
[1].beg
))
613 != ranges
[1].end
- ranges
[1].beg
)
615 t
= fold (build (GE_EXPR
, integer_type_node
, reg_tree
,
616 build_int_2 (DWARF_FRAME_REGNUM (ranges
[1].beg
), 0)));
617 t2
= fold (build (LE_EXPR
, integer_type_node
, reg_tree
,
618 build_int_2 (DWARF_FRAME_REGNUM (ranges
[1].end
), 0)));
619 t
= fold (build (TRUTH_ANDIF_EXPR
, integer_type_node
, t
, t2
));
620 t
= fold (build (COND_EXPR
, integer_type_node
, t
,
621 build_int_2 (ranges
[1].size
, 0),
622 build_int_2 (ranges
[0].size
, 0)));
627 t
= build_int_2 (ranges
[n_ranges
].size
, 0);
628 size
= DWARF_FRAME_REGNUM (ranges
[n_ranges
].beg
);
631 if ((DWARF_FRAME_REGNUM (ranges
[n_ranges
].end
)
632 - DWARF_FRAME_REGNUM (ranges
[n_ranges
].beg
))
633 != ranges
[n_ranges
].end
- ranges
[n_ranges
].beg
)
635 if (DWARF_FRAME_REGNUM (ranges
[n_ranges
].beg
) >= size
)
637 size
= DWARF_FRAME_REGNUM (ranges
[n_ranges
].beg
);
638 t2
= fold (build (LE_EXPR
, integer_type_node
, reg_tree
,
639 build_int_2 (DWARF_FRAME_REGNUM
640 (ranges
[n_ranges
].end
), 0)));
641 t
= fold (build (COND_EXPR
, integer_type_node
, t2
,
642 build_int_2 (ranges
[n_ranges
].size
, 0), t
));
645 return expand_expr (t
, target
, Pmode
, 0);
648 /* Convert a DWARF call frame info. operation to its string name */
651 dwarf_cfi_name (cfi_opc
)
652 register unsigned cfi_opc
;
656 case DW_CFA_advance_loc
:
657 return "DW_CFA_advance_loc";
659 return "DW_CFA_offset";
661 return "DW_CFA_restore";
665 return "DW_CFA_set_loc";
666 case DW_CFA_advance_loc1
:
667 return "DW_CFA_advance_loc1";
668 case DW_CFA_advance_loc2
:
669 return "DW_CFA_advance_loc2";
670 case DW_CFA_advance_loc4
:
671 return "DW_CFA_advance_loc4";
672 case DW_CFA_offset_extended
:
673 return "DW_CFA_offset_extended";
674 case DW_CFA_restore_extended
:
675 return "DW_CFA_restore_extended";
676 case DW_CFA_undefined
:
677 return "DW_CFA_undefined";
678 case DW_CFA_same_value
:
679 return "DW_CFA_same_value";
680 case DW_CFA_register
:
681 return "DW_CFA_register";
682 case DW_CFA_remember_state
:
683 return "DW_CFA_remember_state";
684 case DW_CFA_restore_state
:
685 return "DW_CFA_restore_state";
687 return "DW_CFA_def_cfa";
688 case DW_CFA_def_cfa_register
:
689 return "DW_CFA_def_cfa_register";
690 case DW_CFA_def_cfa_offset
:
691 return "DW_CFA_def_cfa_offset";
693 /* SGI/MIPS specific */
694 case DW_CFA_MIPS_advance_loc8
:
695 return "DW_CFA_MIPS_advance_loc8";
698 case DW_CFA_GNU_window_save
:
699 return "DW_CFA_GNU_window_save";
700 case DW_CFA_GNU_args_size
:
701 return "DW_CFA_GNU_args_size";
704 return "DW_CFA_<unknown>";
708 /* Return a pointer to a newly allocated Call Frame Instruction. */
710 static inline dw_cfi_ref
713 register dw_cfi_ref cfi
= (dw_cfi_ref
) xmalloc (sizeof (dw_cfi_node
));
715 cfi
->dw_cfi_next
= NULL
;
716 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
717 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
722 /* Add a Call Frame Instruction to list of instructions. */
725 add_cfi (list_head
, cfi
)
726 register dw_cfi_ref
*list_head
;
727 register dw_cfi_ref cfi
;
729 register dw_cfi_ref
*p
;
731 /* Find the end of the chain. */
732 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
738 /* Generate a new label for the CFI info to refer to. */
741 dwarf2out_cfi_label ()
743 static char label
[20];
744 static unsigned long label_num
= 0;
746 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", label_num
++);
747 ASM_OUTPUT_LABEL (asm_out_file
, label
);
752 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
753 or to the CIE if LABEL is NULL. */
756 add_fde_cfi (label
, cfi
)
757 register char *label
;
758 register dw_cfi_ref cfi
;
762 register dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
765 label
= dwarf2out_cfi_label ();
767 if (fde
->dw_fde_current_label
== NULL
768 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
770 register dw_cfi_ref xcfi
;
772 fde
->dw_fde_current_label
= label
= xstrdup (label
);
774 /* Set the location counter to the new label. */
776 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
777 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
778 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
781 add_cfi (&fde
->dw_fde_cfi
, cfi
);
785 add_cfi (&cie_cfi_head
, cfi
);
788 /* Subroutine of lookup_cfa. */
791 lookup_cfa_1 (cfi
, regp
, offsetp
)
792 register dw_cfi_ref cfi
;
793 register unsigned long *regp
;
794 register long *offsetp
;
796 switch (cfi
->dw_cfi_opc
)
798 case DW_CFA_def_cfa_offset
:
799 *offsetp
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
801 case DW_CFA_def_cfa_register
:
802 *regp
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
805 *regp
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
806 *offsetp
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
813 /* Find the previous value for the CFA. */
816 lookup_cfa (regp
, offsetp
)
817 register unsigned long *regp
;
818 register long *offsetp
;
820 register dw_cfi_ref cfi
;
822 *regp
= (unsigned long) -1;
825 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
826 lookup_cfa_1 (cfi
, regp
, offsetp
);
828 if (fde_table_in_use
)
830 register dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
831 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
832 lookup_cfa_1 (cfi
, regp
, offsetp
);
836 /* The current rule for calculating the DWARF2 canonical frame address. */
837 static unsigned long cfa_reg
;
838 static long cfa_offset
;
840 /* The register used for saving registers to the stack, and its offset
842 static unsigned cfa_store_reg
;
843 static long cfa_store_offset
;
845 /* The running total of the size of arguments pushed onto the stack. */
846 static long args_size
;
848 /* The last args_size we actually output. */
849 static long old_args_size
;
851 /* Entry point to update the canonical frame address (CFA).
852 LABEL is passed to add_fde_cfi. The value of CFA is now to be
853 calculated from REG+OFFSET. */
856 dwarf2out_def_cfa (label
, reg
, offset
)
857 register char *label
;
858 register unsigned reg
;
859 register long offset
;
861 register dw_cfi_ref cfi
;
862 unsigned long old_reg
;
867 if (cfa_store_reg
== reg
)
868 cfa_store_offset
= offset
;
870 reg
= DWARF_FRAME_REGNUM (reg
);
871 lookup_cfa (&old_reg
, &old_offset
);
873 if (reg
== old_reg
&& offset
== old_offset
)
880 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
881 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= offset
;
884 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
885 else if (offset
== old_offset
&& old_reg
!= (unsigned long) -1)
887 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
888 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
894 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
895 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
896 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
899 add_fde_cfi (label
, cfi
);
902 /* Add the CFI for saving a register. REG is the CFA column number.
903 LABEL is passed to add_fde_cfi.
904 If SREG is -1, the register is saved at OFFSET from the CFA;
905 otherwise it is saved in SREG. */
908 reg_save (label
, reg
, sreg
, offset
)
909 register char * label
;
910 register unsigned reg
;
911 register unsigned sreg
;
912 register long offset
;
914 register dw_cfi_ref cfi
= new_cfi ();
916 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
918 /* The following comparison is correct. -1 is used to indicate that
919 the value isn't a register number. */
920 if (sreg
== (unsigned int) -1)
923 /* The register number won't fit in 6 bits, so we have to use
925 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
927 cfi
->dw_cfi_opc
= DW_CFA_offset
;
929 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
932 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
936 cfi
->dw_cfi_opc
= DW_CFA_register
;
937 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
940 add_fde_cfi (label
, cfi
);
943 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
944 This CFI tells the unwinder that it needs to restore the window registers
945 from the previous frame's window save area.
947 ??? Perhaps we should note in the CIE where windows are saved (instead of
948 assuming 0(cfa)) and what registers are in the window. */
951 dwarf2out_window_save (label
)
952 register char * label
;
954 register dw_cfi_ref cfi
= new_cfi ();
955 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
956 add_fde_cfi (label
, cfi
);
959 /* Add a CFI to update the running total of the size of arguments
960 pushed onto the stack. */
963 dwarf2out_args_size (label
, size
)
967 register dw_cfi_ref cfi
;
969 if (size
== old_args_size
)
971 old_args_size
= size
;
974 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
975 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
976 add_fde_cfi (label
, cfi
);
979 /* Entry point for saving a register to the stack. REG is the GCC register
980 number. LABEL and OFFSET are passed to reg_save. */
983 dwarf2out_reg_save (label
, reg
, offset
)
984 register char * label
;
985 register unsigned reg
;
986 register long offset
;
988 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
991 /* Entry point for saving the return address in the stack.
992 LABEL and OFFSET are passed to reg_save. */
995 dwarf2out_return_save (label
, offset
)
996 register char * label
;
997 register long offset
;
999 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, -1, offset
);
1002 /* Entry point for saving the return address in a register.
1003 LABEL and SREG are passed to reg_save. */
1006 dwarf2out_return_reg (label
, sreg
)
1007 register char * label
;
1008 register unsigned sreg
;
1010 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, sreg
, 0);
1013 /* Record the initial position of the return address. RTL is
1014 INCOMING_RETURN_ADDR_RTX. */
1017 initial_return_save (rtl
)
1023 switch (GET_CODE (rtl
))
1026 /* RA is in a register. */
1027 reg
= reg_number (rtl
);
1030 /* RA is on the stack. */
1031 rtl
= XEXP (rtl
, 0);
1032 switch (GET_CODE (rtl
))
1035 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
1040 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
1042 offset
= INTVAL (XEXP (rtl
, 1));
1045 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
1047 offset
= -INTVAL (XEXP (rtl
, 1));
1054 /* The return address is at some offset from any value we can
1055 actually load. For instance, on the SPARC it is in %i7+8. Just
1056 ignore the offset for now; it doesn't matter for unwinding frames. */
1057 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
1059 initial_return_save (XEXP (rtl
, 0));
1065 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa_offset
);
1068 /* Check INSN to see if it looks like a push or a stack adjustment, and
1069 make a note of it if it does. EH uses this information to find out how
1070 much extra space it needs to pop off the stack. */
1073 dwarf2out_stack_adjust (insn
)
1079 if (! asynchronous_exceptions
&& GET_CODE (insn
) == CALL_INSN
)
1081 /* Extract the size of the args from the CALL rtx itself. */
1083 insn
= PATTERN (insn
);
1084 if (GET_CODE (insn
) == PARALLEL
)
1085 insn
= XVECEXP (insn
, 0, 0);
1086 if (GET_CODE (insn
) == SET
)
1087 insn
= SET_SRC (insn
);
1088 assert (GET_CODE (insn
) == CALL
);
1089 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1093 /* If only calls can throw, and we have a frame pointer,
1094 save up adjustments until we see the CALL_INSN. */
1095 else if (! asynchronous_exceptions
1096 && cfa_reg
!= STACK_POINTER_REGNUM
)
1099 if (GET_CODE (insn
) == BARRIER
)
1101 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1102 the compiler will have already emitted a stack adjustment, but
1103 doesn't bother for calls to noreturn functions. */
1104 #ifdef STACK_GROWS_DOWNWARD
1105 offset
= -args_size
;
1110 else if (GET_CODE (PATTERN (insn
)) == SET
)
1115 insn
= PATTERN (insn
);
1116 src
= SET_SRC (insn
);
1117 dest
= SET_DEST (insn
);
1119 if (dest
== stack_pointer_rtx
)
1121 /* (set (reg sp) (plus (reg sp) (const_int))) */
1122 code
= GET_CODE (src
);
1123 if (! (code
== PLUS
|| code
== MINUS
)
1124 || XEXP (src
, 0) != stack_pointer_rtx
1125 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1128 offset
= INTVAL (XEXP (src
, 1));
1130 else if (GET_CODE (dest
) == MEM
)
1132 /* (set (mem (pre_dec (reg sp))) (foo)) */
1133 src
= XEXP (dest
, 0);
1134 code
= GET_CODE (src
);
1136 if (! (code
== PRE_DEC
|| code
== PRE_INC
)
1137 || XEXP (src
, 0) != stack_pointer_rtx
)
1140 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1145 if (code
== PLUS
|| code
== PRE_INC
)
1154 if (cfa_reg
== STACK_POINTER_REGNUM
)
1155 cfa_offset
+= offset
;
1157 #ifndef STACK_GROWS_DOWNWARD
1160 args_size
+= offset
;
1164 label
= dwarf2out_cfi_label ();
1165 dwarf2out_def_cfa (label
, cfa_reg
, cfa_offset
);
1166 dwarf2out_args_size (label
, args_size
);
1169 /* Record call frame debugging information for INSN, which either
1170 sets SP or FP (adjusting how we calculate the frame address) or saves a
1171 register to the stack. If INSN is NULL_RTX, initialize our state. */
1174 dwarf2out_frame_debug (insn
)
1181 /* A temporary register used in adjusting SP or setting up the store_reg. */
1182 static unsigned cfa_temp_reg
;
1183 static long cfa_temp_value
;
1185 if (insn
== NULL_RTX
)
1187 /* Set up state for generating call frame debug info. */
1188 lookup_cfa (&cfa_reg
, &cfa_offset
);
1189 if (cfa_reg
!= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1191 cfa_reg
= STACK_POINTER_REGNUM
;
1192 cfa_store_reg
= cfa_reg
;
1193 cfa_store_offset
= cfa_offset
;
1199 if (! RTX_FRAME_RELATED_P (insn
))
1201 dwarf2out_stack_adjust (insn
);
1205 label
= dwarf2out_cfi_label ();
1207 insn
= PATTERN (insn
);
1208 /* Assume that in a PARALLEL prologue insn, only the first elt is
1209 significant. Currently this is true. */
1210 if (GET_CODE (insn
) == PARALLEL
)
1211 insn
= XVECEXP (insn
, 0, 0);
1212 if (GET_CODE (insn
) != SET
)
1215 src
= SET_SRC (insn
);
1216 dest
= SET_DEST (insn
);
1218 switch (GET_CODE (dest
))
1221 /* Update the CFA rule wrt SP or FP. Make sure src is
1222 relative to the current CFA register. */
1223 switch (GET_CODE (src
))
1225 /* Setting FP from SP. */
1227 if (cfa_reg
!= REGNO (src
))
1229 if (REGNO (dest
) != STACK_POINTER_REGNUM
1230 && !(frame_pointer_needed
1231 && REGNO (dest
) == HARD_FRAME_POINTER_REGNUM
))
1233 cfa_reg
= REGNO (dest
);
1238 if (dest
== stack_pointer_rtx
)
1241 switch (GET_CODE (XEXP (src
, 1)))
1244 offset
= INTVAL (XEXP (src
, 1));
1247 if (REGNO (XEXP (src
, 1)) != cfa_temp_reg
)
1249 offset
= cfa_temp_value
;
1255 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1257 /* Restoring SP from FP in the epilogue. */
1258 if (cfa_reg
!= HARD_FRAME_POINTER_REGNUM
)
1260 cfa_reg
= STACK_POINTER_REGNUM
;
1262 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1265 if (GET_CODE (src
) == PLUS
)
1267 if (cfa_reg
== STACK_POINTER_REGNUM
)
1268 cfa_offset
+= offset
;
1269 if (cfa_store_reg
== STACK_POINTER_REGNUM
)
1270 cfa_store_offset
+= offset
;
1272 else if (dest
== hard_frame_pointer_rtx
)
1274 /* Either setting the FP from an offset of the SP,
1275 or adjusting the FP */
1276 if (! frame_pointer_needed
1277 || REGNO (dest
) != HARD_FRAME_POINTER_REGNUM
)
1280 if (XEXP (src
, 0) == stack_pointer_rtx
1281 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1283 if (cfa_reg
!= STACK_POINTER_REGNUM
)
1285 offset
= INTVAL (XEXP (src
, 1));
1286 if (GET_CODE (src
) == PLUS
)
1288 cfa_offset
+= offset
;
1289 cfa_reg
= HARD_FRAME_POINTER_REGNUM
;
1291 else if (XEXP (src
, 0) == hard_frame_pointer_rtx
1292 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1294 if (cfa_reg
!= HARD_FRAME_POINTER_REGNUM
)
1296 offset
= INTVAL (XEXP (src
, 1));
1297 if (GET_CODE (src
) == PLUS
)
1299 cfa_offset
+= offset
;
1307 if (GET_CODE (src
) != PLUS
1308 || XEXP (src
, 1) != stack_pointer_rtx
)
1310 if (GET_CODE (XEXP (src
, 0)) != REG
1311 || REGNO (XEXP (src
, 0)) != cfa_temp_reg
)
1313 if (cfa_reg
!= STACK_POINTER_REGNUM
)
1315 cfa_store_reg
= REGNO (dest
);
1316 cfa_store_offset
= cfa_offset
- cfa_temp_value
;
1321 cfa_temp_reg
= REGNO (dest
);
1322 cfa_temp_value
= INTVAL (src
);
1326 if (GET_CODE (XEXP (src
, 0)) != REG
1327 || REGNO (XEXP (src
, 0)) != cfa_temp_reg
1328 || REGNO (dest
) != cfa_temp_reg
1329 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1331 cfa_temp_value
|= INTVAL (XEXP (src
, 1));
1337 dwarf2out_def_cfa (label
, cfa_reg
, cfa_offset
);
1341 /* Saving a register to the stack. Make sure dest is relative to the
1343 if (GET_CODE (src
) != REG
)
1345 switch (GET_CODE (XEXP (dest
, 0)))
1350 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1351 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1354 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1355 || cfa_store_reg
!= STACK_POINTER_REGNUM
)
1357 cfa_store_offset
+= offset
;
1358 if (cfa_reg
== STACK_POINTER_REGNUM
)
1359 cfa_offset
= cfa_store_offset
;
1361 offset
= -cfa_store_offset
;
1364 /* With an offset. */
1367 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1368 if (GET_CODE (src
) == MINUS
)
1371 if (cfa_store_reg
!= REGNO (XEXP (XEXP (dest
, 0), 0)))
1373 offset
-= cfa_store_offset
;
1379 dwarf2out_def_cfa (label
, cfa_reg
, cfa_offset
);
1380 dwarf2out_reg_save (label
, REGNO (src
), offset
);
1388 /* Return the size of an unsigned LEB128 quantity. */
1390 static inline unsigned long
1391 size_of_uleb128 (value
)
1392 register unsigned long value
;
1394 register unsigned long size
= 0;
1395 register unsigned byte
;
1399 byte
= (value
& 0x7f);
1408 /* Return the size of a signed LEB128 quantity. */
1410 static inline unsigned long
1411 size_of_sleb128 (value
)
1412 register long value
;
1414 register unsigned long size
= 0;
1415 register unsigned byte
;
1419 byte
= (value
& 0x7f);
1423 while (!(((value
== 0) && ((byte
& 0x40) == 0))
1424 || ((value
== -1) && ((byte
& 0x40) != 0))));
1429 /* Output an unsigned LEB128 quantity. */
1432 output_uleb128 (value
)
1433 register unsigned long value
;
1435 unsigned long save_value
= value
;
1437 fprintf (asm_out_file
, "\t%s\t", ASM_BYTE_OP
);
1440 register unsigned byte
= (value
& 0x7f);
1443 /* More bytes to follow. */
1446 fprintf (asm_out_file
, "0x%x", byte
);
1448 fprintf (asm_out_file
, ",");
1453 fprintf (asm_out_file
, "\t%s ULEB128 0x%lx", ASM_COMMENT_START
, save_value
);
1456 /* Output an signed LEB128 quantity. */
1459 output_sleb128 (value
)
1460 register long value
;
1463 register unsigned byte
;
1464 long save_value
= value
;
1466 fprintf (asm_out_file
, "\t%s\t", ASM_BYTE_OP
);
1469 byte
= (value
& 0x7f);
1470 /* arithmetic shift */
1472 more
= !((((value
== 0) && ((byte
& 0x40) == 0))
1473 || ((value
== -1) && ((byte
& 0x40) != 0))));
1477 fprintf (asm_out_file
, "0x%x", byte
);
1479 fprintf (asm_out_file
, ",");
1484 fprintf (asm_out_file
, "\t%s SLEB128 %ld", ASM_COMMENT_START
, save_value
);
1487 /* Output a Call Frame Information opcode and its operand(s). */
1490 output_cfi (cfi
, fde
)
1491 register dw_cfi_ref cfi
;
1492 register dw_fde_ref fde
;
1494 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1496 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
1498 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f));
1500 fprintf (asm_out_file
, "\t%s DW_CFA_advance_loc 0x%lx",
1501 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1502 fputc ('\n', asm_out_file
);
1505 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1507 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
1509 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f));
1511 fprintf (asm_out_file
, "\t%s DW_CFA_offset, column 0x%lx",
1512 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1514 fputc ('\n', asm_out_file
);
1515 output_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
1516 fputc ('\n', asm_out_file
);
1518 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1520 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
1522 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f));
1524 fprintf (asm_out_file
, "\t%s DW_CFA_restore, column 0x%lx",
1525 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1527 fputc ('\n', asm_out_file
);
1531 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, cfi
->dw_cfi_opc
);
1533 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
,
1534 dwarf_cfi_name (cfi
->dw_cfi_opc
));
1536 fputc ('\n', asm_out_file
);
1537 switch (cfi
->dw_cfi_opc
)
1539 case DW_CFA_set_loc
:
1540 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
);
1541 fputc ('\n', asm_out_file
);
1543 case DW_CFA_advance_loc1
:
1544 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file
,
1545 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1546 fde
->dw_fde_current_label
);
1547 fputc ('\n', asm_out_file
);
1548 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1550 case DW_CFA_advance_loc2
:
1551 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
,
1552 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1553 fde
->dw_fde_current_label
);
1554 fputc ('\n', asm_out_file
);
1555 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1557 case DW_CFA_advance_loc4
:
1558 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
,
1559 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1560 fde
->dw_fde_current_label
);
1561 fputc ('\n', asm_out_file
);
1562 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1564 #ifdef MIPS_DEBUGGING_INFO
1565 case DW_CFA_MIPS_advance_loc8
:
1566 /* TODO: not currently implemented. */
1570 case DW_CFA_offset_extended
:
1571 case DW_CFA_def_cfa
:
1572 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1573 fputc ('\n', asm_out_file
);
1574 output_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
1575 fputc ('\n', asm_out_file
);
1577 case DW_CFA_restore_extended
:
1578 case DW_CFA_undefined
:
1579 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1580 fputc ('\n', asm_out_file
);
1582 case DW_CFA_same_value
:
1583 case DW_CFA_def_cfa_register
:
1584 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1585 fputc ('\n', asm_out_file
);
1587 case DW_CFA_register
:
1588 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1589 fputc ('\n', asm_out_file
);
1590 output_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
);
1591 fputc ('\n', asm_out_file
);
1593 case DW_CFA_def_cfa_offset
:
1594 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1595 fputc ('\n', asm_out_file
);
1597 case DW_CFA_GNU_window_save
:
1599 case DW_CFA_GNU_args_size
:
1600 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1601 fputc ('\n', asm_out_file
);
1609 #if !defined (EH_FRAME_SECTION)
1610 #if defined (EH_FRAME_SECTION_ASM_OP)
1611 #define EH_FRAME_SECTION() eh_frame_section();
1613 #if defined (ASM_OUTPUT_SECTION_NAME)
1614 #define EH_FRAME_SECTION() \
1616 named_section (NULL_TREE, ".eh_frame", 0); \
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 fputc ('\n', asm_out_file
);
1643 /* We're going to be generating comments, so turn on app. */
1649 #ifdef EH_FRAME_SECTION
1650 EH_FRAME_SECTION ();
1652 tree label
= get_file_function_name ('F');
1655 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
1656 ASM_GLOBALIZE_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
1657 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
1659 assemble_label ("__FRAME_BEGIN__");
1662 ASM_OUTPUT_SECTION (asm_out_file
, FRAME_SECTION
);
1664 /* Output the CIE. */
1665 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
1666 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
1667 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1668 ASM_GENERATE_INTERNAL_LABEL (ld
, CIE_LENGTH_LABEL
, for_eh
);
1670 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file
, ld
);
1672 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, ld
);
1675 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
, l2
, l1
);
1677 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, l2
, l1
);
1680 fprintf (asm_out_file
, "\t%s Length of Common Information Entry",
1683 fputc ('\n', asm_out_file
);
1684 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1687 /* Now that the CIE pointer is PC-relative for EH,
1688 use 0 to identify the CIE. */
1689 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 0);
1691 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, DW_CIE_ID
);
1694 fprintf (asm_out_file
, "\t%s CIE Identifier Tag", ASM_COMMENT_START
);
1696 fputc ('\n', asm_out_file
);
1697 if (! for_eh
&& DWARF_OFFSET_SIZE
== 8)
1699 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, DW_CIE_ID
);
1700 fputc ('\n', asm_out_file
);
1703 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_CIE_VERSION
);
1705 fprintf (asm_out_file
, "\t%s CIE Version", ASM_COMMENT_START
);
1707 fputc ('\n', asm_out_file
);
1710 /* The CIE contains a pointer to the exception region info for the
1711 frame. Make the augmentation string three bytes (including the
1712 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1713 can't handle unaligned relocs. */
1716 ASM_OUTPUT_DWARF_STRING (asm_out_file
, "eh");
1717 fprintf (asm_out_file
, "\t%s CIE Augmentation", ASM_COMMENT_START
);
1721 ASM_OUTPUT_ASCII (asm_out_file
, "eh", 3);
1723 fputc ('\n', asm_out_file
);
1725 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, "__EXCEPTION_TABLE__");
1727 fprintf (asm_out_file
, "\t%s pointer to exception region info",
1732 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
1734 fprintf (asm_out_file
, "\t%s CIE Augmentation (none)",
1738 fputc ('\n', asm_out_file
);
1741 fprintf (asm_out_file
, " (CIE Code Alignment Factor)");
1743 fputc ('\n', asm_out_file
);
1744 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT
);
1746 fprintf (asm_out_file
, " (CIE Data Alignment Factor)");
1748 fputc ('\n', asm_out_file
);
1749 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_FRAME_RETURN_COLUMN
);
1751 fprintf (asm_out_file
, "\t%s CIE RA Column", ASM_COMMENT_START
);
1753 fputc ('\n', asm_out_file
);
1755 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
1756 output_cfi (cfi
, NULL
);
1758 /* Pad the CIE out to an address sized boundary. */
1759 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
1760 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
1761 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1762 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file
, ld
, l2
, l1
);
1764 fprintf (asm_out_file
, "\t%s CIE Length Symbol", ASM_COMMENT_START
);
1765 fputc ('\n', asm_out_file
);
1768 /* Loop through all of the FDE's. */
1769 for (i
= 0; i
< fde_table_in_use
; ++i
)
1771 fde
= &fde_table
[i
];
1773 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
*2);
1774 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
*2);
1775 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1776 ASM_GENERATE_INTERNAL_LABEL (ld
, FDE_LENGTH_LABEL
, for_eh
+ i
*2);
1778 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file
, ld
);
1780 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, ld
);
1783 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
, l2
, l1
);
1785 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, l2
, l1
);
1788 fprintf (asm_out_file
, "\t%s FDE Length", ASM_COMMENT_START
);
1789 fputc ('\n', asm_out_file
);
1790 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1793 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, l1
, "__FRAME_BEGIN__");
1795 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, stripattributes (FRAME_SECTION
));
1797 fprintf (asm_out_file
, "\t%s FDE CIE offset", ASM_COMMENT_START
);
1799 fputc ('\n', asm_out_file
);
1800 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, fde
->dw_fde_begin
);
1802 fprintf (asm_out_file
, "\t%s FDE initial location", ASM_COMMENT_START
);
1804 fputc ('\n', asm_out_file
);
1805 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
,
1806 fde
->dw_fde_end
, fde
->dw_fde_begin
);
1808 fprintf (asm_out_file
, "\t%s FDE address range", ASM_COMMENT_START
);
1810 fputc ('\n', asm_out_file
);
1812 /* Loop through the Call Frame Instructions associated with
1814 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
1815 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
1816 output_cfi (cfi
, fde
);
1818 /* Pad the FDE out to an address sized boundary. */
1819 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
1820 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
1821 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1822 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file
, ld
, l2
, l1
);
1824 fprintf (asm_out_file
, "\t%s FDE Length Symbol", ASM_COMMENT_START
);
1825 fputc ('\n', asm_out_file
);
1828 #ifndef EH_FRAME_SECTION
1831 /* Emit terminating zero for table. */
1832 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 0);
1833 fputc ('\n', asm_out_file
);
1836 #ifdef MIPS_DEBUGGING_INFO
1837 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1838 get a value of 0. Putting .align 0 after the label fixes it. */
1839 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
1842 /* Turn off app to make assembly quicker. */
1847 /* Output a marker (i.e. a label) for the beginning of a function, before
1851 dwarf2out_begin_prologue ()
1853 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1854 register dw_fde_ref fde
;
1856 ++current_funcdef_number
;
1858 function_section (current_function_decl
);
1859 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1860 current_funcdef_number
);
1861 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1863 /* Expand the fde table if necessary. */
1864 if (fde_table_in_use
== fde_table_allocated
)
1866 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
1868 = (dw_fde_ref
) xrealloc (fde_table
,
1869 fde_table_allocated
* sizeof (dw_fde_node
));
1872 /* Record the FDE associated with this function. */
1873 current_funcdef_fde
= fde_table_in_use
;
1875 /* Add the new FDE at the end of the fde_table. */
1876 fde
= &fde_table
[fde_table_in_use
++];
1877 fde
->dw_fde_begin
= xstrdup (label
);
1878 fde
->dw_fde_current_label
= NULL
;
1879 fde
->dw_fde_end
= NULL
;
1880 fde
->dw_fde_cfi
= NULL
;
1882 args_size
= old_args_size
= 0;
1885 /* Output a marker (i.e. a label) for the absolute end of the generated code
1886 for a function definition. This gets called *after* the epilogue code has
1890 dwarf2out_end_epilogue ()
1893 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1895 /* Output a label to mark the endpoint of the code generated for this
1897 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
, current_funcdef_number
);
1898 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1899 fde
= &fde_table
[fde_table_in_use
- 1];
1900 fde
->dw_fde_end
= xstrdup (label
);
1904 dwarf2out_frame_init ()
1906 /* Allocate the initial hunk of the fde_table. */
1908 = (dw_fde_ref
) xmalloc (FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
1909 bzero ((char *) fde_table
, FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
1910 fde_table_allocated
= FDE_TABLE_INCREMENT
;
1911 fde_table_in_use
= 0;
1913 /* Generate the CFA instructions common to all FDE's. Do it now for the
1914 sake of lookup_cfa. */
1916 #ifdef DWARF2_UNWIND_INFO
1917 /* On entry, the Canonical Frame Address is at SP. */
1918 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
1919 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
1924 dwarf2out_frame_finish ()
1926 /* Output call frame information. */
1927 #ifdef MIPS_DEBUGGING_INFO
1928 if (write_symbols
== DWARF2_DEBUG
)
1929 output_call_frame_info (0);
1930 if (flag_exceptions
&& ! exceptions_via_longjmp
)
1931 output_call_frame_info (1);
1933 if (write_symbols
== DWARF2_DEBUG
1934 || (flag_exceptions
&& ! exceptions_via_longjmp
))
1935 output_call_frame_info (1);
1939 #endif /* .debug_frame support */
1941 /* And now, the support for symbolic debugging information. */
1942 #ifdef DWARF2_DEBUGGING_INFO
1944 extern char *getpwd ();
1946 /* NOTE: In the comments in this file, many references are made to
1947 "Debugging Information Entries". This term is abbreviated as `DIE'
1948 throughout the remainder of this file. */
1950 /* An internal representation of the DWARF output is built, and then
1951 walked to generate the DWARF debugging info. The walk of the internal
1952 representation is done after the entire program has been compiled.
1953 The types below are used to describe the internal representation. */
1955 /* Each DIE may have a series of attribute/value pairs. Values
1956 can take on several forms. The forms that are used in this
1957 implementation are listed below. */
1964 dw_val_class_unsigned_const
,
1965 dw_val_class_long_long
,
1968 dw_val_class_die_ref
,
1969 dw_val_class_fde_ref
,
1970 dw_val_class_lbl_id
,
1971 dw_val_class_section_offset
,
1976 /* Various DIE's use offsets relative to the beginning of the
1977 .debug_info section to refer to each other. */
1979 typedef long int dw_offset
;
1981 /* Define typedefs here to avoid circular dependencies. */
1983 typedef struct die_struct
*dw_die_ref
;
1984 typedef struct dw_attr_struct
*dw_attr_ref
;
1985 typedef struct dw_val_struct
*dw_val_ref
;
1986 typedef struct dw_line_info_struct
*dw_line_info_ref
;
1987 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
1988 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
1989 typedef struct pubname_struct
*pubname_ref
;
1990 typedef dw_die_ref
*arange_ref
;
1992 /* Describe a double word constant value. */
1994 typedef struct dw_long_long_struct
2001 /* Describe a floating point constant value. */
2003 typedef struct dw_fp_struct
2010 /* Each entry in the line_info_table maintains the file and
2011 line number associated with the label generated for that
2012 entry. The label gives the PC value associated with
2013 the line number entry. */
2015 typedef struct dw_line_info_struct
2017 unsigned long dw_file_num
;
2018 unsigned long dw_line_num
;
2022 /* Line information for functions in separate sections; each one gets its
2024 typedef struct dw_separate_line_info_struct
2026 unsigned long dw_file_num
;
2027 unsigned long dw_line_num
;
2028 unsigned long function
;
2030 dw_separate_line_info_entry
;
2032 /* The dw_val_node describes an attribute's value, as it is
2033 represented internally. */
2035 typedef struct dw_val_struct
2037 dw_val_class val_class
;
2041 dw_loc_descr_ref val_loc
;
2043 long unsigned val_unsigned
;
2044 dw_long_long_const val_long_long
;
2045 dw_float_const val_float
;
2046 dw_die_ref val_die_ref
;
2047 unsigned val_fde_index
;
2051 unsigned char val_flag
;
2057 /* Locations in memory are described using a sequence of stack machine
2060 typedef struct dw_loc_descr_struct
2062 dw_loc_descr_ref dw_loc_next
;
2063 enum dwarf_location_atom dw_loc_opc
;
2064 dw_val_node dw_loc_oprnd1
;
2065 dw_val_node dw_loc_oprnd2
;
2069 /* Each DIE attribute has a field specifying the attribute kind,
2070 a link to the next attribute in the chain, and an attribute value.
2071 Attributes are typically linked below the DIE they modify. */
2073 typedef struct dw_attr_struct
2075 enum dwarf_attribute dw_attr
;
2076 dw_attr_ref dw_attr_next
;
2077 dw_val_node dw_attr_val
;
2081 /* The Debugging Information Entry (DIE) structure */
2083 typedef struct die_struct
2085 enum dwarf_tag die_tag
;
2086 dw_attr_ref die_attr
;
2087 dw_attr_ref die_attr_last
;
2088 dw_die_ref die_parent
;
2089 dw_die_ref die_child
;
2090 dw_die_ref die_child_last
;
2092 dw_offset die_offset
;
2093 unsigned long die_abbrev
;
2097 /* The pubname structure */
2099 typedef struct pubname_struct
2106 /* The limbo die list structure. */
2107 typedef struct limbo_die_struct
2110 struct limbo_die_struct
*next
;
2114 /* How to start an assembler comment. */
2115 #ifndef ASM_COMMENT_START
2116 #define ASM_COMMENT_START ";#"
2119 /* Define a macro which returns non-zero for a TYPE_DECL which was
2120 implicitly generated for a tagged type.
2122 Note that unlike the gcc front end (which generates a NULL named
2123 TYPE_DECL node for each complete tagged type, each array type, and
2124 each function type node created) the g++ front end generates a
2125 _named_ TYPE_DECL node for each tagged type node created.
2126 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2127 generate a DW_TAG_typedef DIE for them. */
2129 #define TYPE_DECL_IS_STUB(decl) \
2130 (DECL_NAME (decl) == NULL_TREE \
2131 || (DECL_ARTIFICIAL (decl) \
2132 && is_tagged_type (TREE_TYPE (decl)) \
2133 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2134 /* This is necessary for stub decls that \
2135 appear in nested inline functions. */ \
2136 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2137 && (decl_ultimate_origin (decl) \
2138 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2140 /* Information concerning the compilation unit's programming
2141 language, and compiler version. */
2143 extern int flag_traditional
;
2144 extern char *version_string
;
2145 extern char *language_string
;
2147 /* Fixed size portion of the DWARF compilation unit header. */
2148 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2150 /* Fixed size portion of debugging line information prolog. */
2151 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2153 /* Fixed size portion of public names info. */
2154 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2156 /* Fixed size portion of the address range info. */
2157 #define DWARF_ARANGES_HEADER_SIZE \
2158 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
2160 /* Define the architecture-dependent minimum instruction length (in bytes).
2161 In this implementation of DWARF, this field is used for information
2162 purposes only. Since GCC generates assembly language, we have
2163 no a priori knowledge of how many instruction bytes are generated
2164 for each source line, and therefore can use only the DW_LNE_set_address
2165 and DW_LNS_fixed_advance_pc line information commands. */
2167 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2168 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2171 /* Minimum line offset in a special line info. opcode.
2172 This value was chosen to give a reasonable range of values. */
2173 #define DWARF_LINE_BASE -10
2175 /* First special line opcde - leave room for the standard opcodes. */
2176 #define DWARF_LINE_OPCODE_BASE 10
2178 /* Range of line offsets in a special line info. opcode. */
2179 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2181 /* Flag that indicates the initial value of the is_stmt_start flag.
2182 In the present implementation, we do not mark any lines as
2183 the beginning of a source statement, because that information
2184 is not made available by the GCC front-end. */
2185 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2187 /* This location is used by calc_die_sizes() to keep track
2188 the offset of each DIE within the .debug_info section. */
2189 static unsigned long next_die_offset
;
2191 /* Record the root of the DIE's built for the current compilation unit. */
2192 static dw_die_ref comp_unit_die
;
2194 /* A list of DIEs with a NULL parent waiting to be relocated. */
2195 static limbo_die_node
*limbo_die_list
= 0;
2197 /* Pointer to an array of filenames referenced by this compilation unit. */
2198 static char **file_table
;
2200 /* Total number of entries in the table (i.e. array) pointed to by
2201 `file_table'. This is the *total* and includes both used and unused
2203 static unsigned file_table_allocated
;
2205 /* Number of entries in the file_table which are actually in use. */
2206 static unsigned file_table_in_use
;
2208 /* Size (in elements) of increments by which we may expand the filename
2210 #define FILE_TABLE_INCREMENT 64
2212 /* Local pointer to the name of the main input file. Initialized in
2214 static char *primary_filename
;
2216 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
2217 which their beginnings are encountered. We output Dwarf debugging info
2218 that refers to the beginnings and ends of the ranges of code for each
2219 lexical block. The labels themselves are generated in final.c, which
2220 assigns numbers to the blocks in the same way. */
2221 static unsigned next_block_number
= 2;
2223 /* A pointer to the base of a table of references to DIE's that describe
2224 declarations. The table is indexed by DECL_UID() which is a unique
2225 number identifying each decl. */
2226 static dw_die_ref
*decl_die_table
;
2228 /* Number of elements currently allocated for the decl_die_table. */
2229 static unsigned decl_die_table_allocated
;
2231 /* Number of elements in decl_die_table currently in use. */
2232 static unsigned decl_die_table_in_use
;
2234 /* Size (in elements) of increments by which we may expand the
2236 #define DECL_DIE_TABLE_INCREMENT 256
2238 /* Structure used for the decl_scope table. scope is the current declaration
2239 scope, and previous is the entry that is the parent of this scope. This
2240 is usually but not always the immediately preceeding entry. */
2242 typedef struct decl_scope_struct
2249 /* A pointer to the base of a table of references to declaration
2250 scopes. This table is a display which tracks the nesting
2251 of declaration scopes at the current scope and containing
2252 scopes. This table is used to find the proper place to
2253 define type declaration DIE's. */
2254 static decl_scope_node
*decl_scope_table
;
2256 /* Number of elements currently allocated for the decl_scope_table. */
2257 static int decl_scope_table_allocated
;
2259 /* Current level of nesting of declaration scopes. */
2260 static int decl_scope_depth
;
2262 /* Size (in elements) of increments by which we may expand the
2263 decl_scope_table. */
2264 #define DECL_SCOPE_TABLE_INCREMENT 64
2266 /* A pointer to the base of a list of references to DIE's that
2267 are uniquely identified by their tag, presence/absence of
2268 children DIE's, and list of attribute/value pairs. */
2269 static dw_die_ref
*abbrev_die_table
;
2271 /* Number of elements currently allocated for abbrev_die_table. */
2272 static unsigned abbrev_die_table_allocated
;
2274 /* Number of elements in type_die_table currently in use. */
2275 static unsigned abbrev_die_table_in_use
;
2277 /* Size (in elements) of increments by which we may expand the
2278 abbrev_die_table. */
2279 #define ABBREV_DIE_TABLE_INCREMENT 256
2281 /* A pointer to the base of a table that contains line information
2282 for each source code line in .text in the compilation unit. */
2283 static dw_line_info_ref line_info_table
;
2285 /* Number of elements currently allocated for line_info_table. */
2286 static unsigned line_info_table_allocated
;
2288 /* Number of elements in separate_line_info_table currently in use. */
2289 static unsigned separate_line_info_table_in_use
;
2291 /* A pointer to the base of a table that contains line information
2292 for each source code line outside of .text in the compilation unit. */
2293 static dw_separate_line_info_ref separate_line_info_table
;
2295 /* Number of elements currently allocated for separate_line_info_table. */
2296 static unsigned separate_line_info_table_allocated
;
2298 /* Number of elements in line_info_table currently in use. */
2299 static unsigned line_info_table_in_use
;
2301 /* Size (in elements) of increments by which we may expand the
2303 #define LINE_INFO_TABLE_INCREMENT 1024
2305 /* A pointer to the base of a table that contains a list of publicly
2306 accessible names. */
2307 static pubname_ref pubname_table
;
2309 /* Number of elements currently allocated for pubname_table. */
2310 static unsigned pubname_table_allocated
;
2312 /* Number of elements in pubname_table currently in use. */
2313 static unsigned pubname_table_in_use
;
2315 /* Size (in elements) of increments by which we may expand the
2317 #define PUBNAME_TABLE_INCREMENT 64
2319 /* A pointer to the base of a table that contains a list of publicly
2320 accessible names. */
2321 static arange_ref arange_table
;
2323 /* Number of elements currently allocated for arange_table. */
2324 static unsigned arange_table_allocated
;
2326 /* Number of elements in arange_table currently in use. */
2327 static unsigned arange_table_in_use
;
2329 /* Size (in elements) of increments by which we may expand the
2331 #define ARANGE_TABLE_INCREMENT 64
2333 /* A pointer to the base of a list of pending types which we haven't
2334 generated DIEs for yet, but which we will have to come back to
2337 static tree
*pending_types_list
;
2339 /* Number of elements currently allocated for the pending_types_list. */
2340 static unsigned pending_types_allocated
;
2342 /* Number of elements of pending_types_list currently in use. */
2343 static unsigned pending_types
;
2345 /* Size (in elements) of increments by which we may expand the pending
2346 types list. Actually, a single hunk of space of this size should
2347 be enough for most typical programs. */
2348 #define PENDING_TYPES_INCREMENT 64
2350 /* Record whether the function being analyzed contains inlined functions. */
2351 static int current_function_has_inlines
;
2352 #if 0 && defined (MIPS_DEBUGGING_INFO)
2353 static int comp_unit_has_inlines
;
2356 /* A pointer to the ..._DECL node which we have most recently been working
2357 on. We keep this around just in case something about it looks screwy and
2358 we want to tell the user what the source coordinates for the actual
2360 static tree dwarf_last_decl
;
2362 /* Forward declarations for functions defined in this file. */
2364 static void addr_const_to_string
PROTO((char *, rtx
));
2365 static char *addr_to_string
PROTO((rtx
));
2366 static int is_pseudo_reg
PROTO((rtx
));
2367 static tree type_main_variant
PROTO((tree
));
2368 static int is_tagged_type
PROTO((tree
));
2369 static char *dwarf_tag_name
PROTO((unsigned));
2370 static char *dwarf_attr_name
PROTO((unsigned));
2371 static char *dwarf_form_name
PROTO((unsigned));
2372 static char *dwarf_stack_op_name
PROTO((unsigned));
2373 static char *dwarf_type_encoding_name
PROTO((unsigned));
2374 static tree decl_ultimate_origin
PROTO((tree
));
2375 static tree block_ultimate_origin
PROTO((tree
));
2376 static tree decl_class_context
PROTO((tree
));
2377 static void add_dwarf_attr
PROTO((dw_die_ref
, dw_attr_ref
));
2378 static void add_AT_flag
PROTO((dw_die_ref
,
2379 enum dwarf_attribute
,
2381 static void add_AT_int
PROTO((dw_die_ref
,
2382 enum dwarf_attribute
, long));
2383 static void add_AT_unsigned
PROTO((dw_die_ref
,
2384 enum dwarf_attribute
,
2386 static void add_AT_long_long
PROTO((dw_die_ref
,
2387 enum dwarf_attribute
,
2388 unsigned long, unsigned long));
2389 static void add_AT_float
PROTO((dw_die_ref
,
2390 enum dwarf_attribute
,
2392 static void add_AT_string
PROTO((dw_die_ref
,
2393 enum dwarf_attribute
, char *));
2394 static void add_AT_die_ref
PROTO((dw_die_ref
,
2395 enum dwarf_attribute
,
2397 static void add_AT_fde_ref
PROTO((dw_die_ref
,
2398 enum dwarf_attribute
,
2400 static void add_AT_loc
PROTO((dw_die_ref
,
2401 enum dwarf_attribute
,
2403 static void add_AT_addr
PROTO((dw_die_ref
,
2404 enum dwarf_attribute
, char *));
2405 static void add_AT_lbl_id
PROTO((dw_die_ref
,
2406 enum dwarf_attribute
, char *));
2407 static void add_AT_section_offset
PROTO((dw_die_ref
,
2408 enum dwarf_attribute
, char *));
2409 static int is_extern_subr_die
PROTO((dw_die_ref
));
2410 static dw_attr_ref get_AT
PROTO((dw_die_ref
,
2411 enum dwarf_attribute
));
2412 static char *get_AT_low_pc
PROTO((dw_die_ref
));
2413 static char *get_AT_hi_pc
PROTO((dw_die_ref
));
2414 static char *get_AT_string
PROTO((dw_die_ref
,
2415 enum dwarf_attribute
));
2416 static int get_AT_flag
PROTO((dw_die_ref
,
2417 enum dwarf_attribute
));
2418 static unsigned get_AT_unsigned
PROTO((dw_die_ref
,
2419 enum dwarf_attribute
));
2420 static int is_c_family
PROTO((void));
2421 static int is_fortran
PROTO((void));
2422 static void remove_AT
PROTO((dw_die_ref
,
2423 enum dwarf_attribute
));
2424 static void remove_children
PROTO((dw_die_ref
));
2425 static void add_child_die
PROTO((dw_die_ref
, dw_die_ref
));
2426 static dw_die_ref new_die
PROTO((enum dwarf_tag
, dw_die_ref
));
2427 static dw_die_ref lookup_type_die
PROTO((tree
));
2428 static void equate_type_number_to_die
PROTO((tree
, dw_die_ref
));
2429 static dw_die_ref lookup_decl_die
PROTO((tree
));
2430 static void equate_decl_number_to_die
PROTO((tree
, dw_die_ref
));
2431 static dw_loc_descr_ref new_loc_descr
PROTO((enum dwarf_location_atom
,
2432 unsigned long, unsigned long));
2433 static void add_loc_descr
PROTO((dw_loc_descr_ref
*,
2435 static void print_spaces
PROTO((FILE *));
2436 static void print_die
PROTO((dw_die_ref
, FILE *));
2437 static void print_dwarf_line_table
PROTO((FILE *));
2438 static void add_sibling_attributes
PROTO((dw_die_ref
));
2439 static void build_abbrev_table
PROTO((dw_die_ref
));
2440 static unsigned long size_of_string
PROTO((char *));
2441 static unsigned long size_of_loc_descr
PROTO((dw_loc_descr_ref
));
2442 static unsigned long size_of_locs
PROTO((dw_loc_descr_ref
));
2443 static int constant_size
PROTO((long unsigned));
2444 static unsigned long size_of_die
PROTO((dw_die_ref
));
2445 static void calc_die_sizes
PROTO((dw_die_ref
));
2446 static unsigned long size_of_line_prolog
PROTO((void));
2447 static unsigned long size_of_line_info
PROTO((void));
2448 static unsigned long size_of_pubnames
PROTO((void));
2449 static unsigned long size_of_aranges
PROTO((void));
2450 static enum dwarf_form value_format
PROTO((dw_val_ref
));
2451 static void output_value_format
PROTO((dw_val_ref
));
2452 static void output_abbrev_section
PROTO((void));
2453 static void output_loc_operands
PROTO((dw_loc_descr_ref
));
2454 static unsigned long sibling_offset
PROTO((dw_die_ref
));
2455 static void output_die
PROTO((dw_die_ref
));
2456 static void output_compilation_unit_header
PROTO((void));
2457 static char *dwarf2_name
PROTO((tree
, int));
2458 static void add_pubname
PROTO((tree
, dw_die_ref
));
2459 static void output_pubnames
PROTO((void));
2460 static void add_arange
PROTO((tree
, dw_die_ref
));
2461 static void output_aranges
PROTO((void));
2462 static void output_line_info
PROTO((void));
2463 static int is_body_block
PROTO((tree
));
2464 static dw_die_ref base_type_die
PROTO((tree
));
2465 static tree root_type
PROTO((tree
));
2466 static int is_base_type
PROTO((tree
));
2467 static dw_die_ref modified_type_die
PROTO((tree
, int, int, dw_die_ref
));
2468 static int type_is_enum
PROTO((tree
));
2469 static dw_loc_descr_ref reg_loc_descriptor
PROTO((rtx
));
2470 static dw_loc_descr_ref based_loc_descr
PROTO((unsigned, long));
2471 static int is_based_loc
PROTO((rtx
));
2472 static dw_loc_descr_ref mem_loc_descriptor
PROTO((rtx
));
2473 static dw_loc_descr_ref concat_loc_descriptor
PROTO((rtx
, rtx
));
2474 static dw_loc_descr_ref loc_descriptor
PROTO((rtx
));
2475 static unsigned ceiling
PROTO((unsigned, unsigned));
2476 static tree field_type
PROTO((tree
));
2477 static unsigned simple_type_align_in_bits
PROTO((tree
));
2478 static unsigned simple_type_size_in_bits
PROTO((tree
));
2479 static unsigned field_byte_offset
PROTO((tree
));
2480 static void add_AT_location_description
PROTO((dw_die_ref
,
2481 enum dwarf_attribute
, rtx
));
2482 static void add_data_member_location_attribute
PROTO((dw_die_ref
, tree
));
2483 static void add_const_value_attribute
PROTO((dw_die_ref
, rtx
));
2484 static void add_location_or_const_value_attribute
PROTO((dw_die_ref
, tree
));
2485 static void add_name_attribute
PROTO((dw_die_ref
, char *));
2486 static void add_bound_info
PROTO((dw_die_ref
,
2487 enum dwarf_attribute
, tree
));
2488 static void add_subscript_info
PROTO((dw_die_ref
, tree
));
2489 static void add_byte_size_attribute
PROTO((dw_die_ref
, tree
));
2490 static void add_bit_offset_attribute
PROTO((dw_die_ref
, tree
));
2491 static void add_bit_size_attribute
PROTO((dw_die_ref
, tree
));
2492 static void add_prototyped_attribute
PROTO((dw_die_ref
, tree
));
2493 static void add_abstract_origin_attribute
PROTO((dw_die_ref
, tree
));
2494 static void add_pure_or_virtual_attribute
PROTO((dw_die_ref
, tree
));
2495 static void add_src_coords_attributes
PROTO((dw_die_ref
, tree
));
2496 static void add_name_and_src_coords_attributes
PROTO((dw_die_ref
, tree
));
2497 static void push_decl_scope
PROTO((tree
));
2498 static dw_die_ref scope_die_for
PROTO((tree
, dw_die_ref
));
2499 static void pop_decl_scope
PROTO((void));
2500 static void add_type_attribute
PROTO((dw_die_ref
, tree
, int, int,
2502 static char *type_tag
PROTO((tree
));
2503 static tree member_declared_type
PROTO((tree
));
2504 static char *decl_start_label
PROTO((tree
));
2505 static void gen_array_type_die
PROTO((tree
, dw_die_ref
));
2506 static void gen_set_type_die
PROTO((tree
, dw_die_ref
));
2507 static void gen_entry_point_die
PROTO((tree
, dw_die_ref
));
2508 static void pend_type
PROTO((tree
));
2509 static void output_pending_types_for_scope
PROTO((dw_die_ref
));
2510 static void gen_inlined_enumeration_type_die
PROTO((tree
, dw_die_ref
));
2511 static void gen_inlined_structure_type_die
PROTO((tree
, dw_die_ref
));
2512 static void gen_inlined_union_type_die
PROTO((tree
, dw_die_ref
));
2513 static void gen_enumeration_type_die
PROTO((tree
, dw_die_ref
));
2514 static dw_die_ref gen_formal_parameter_die
PROTO((tree
, dw_die_ref
));
2515 static void gen_unspecified_parameters_die
PROTO((tree
, dw_die_ref
));
2516 static void gen_formal_types_die
PROTO((tree
, dw_die_ref
));
2517 static void gen_subprogram_die
PROTO((tree
, dw_die_ref
));
2518 static void gen_variable_die
PROTO((tree
, dw_die_ref
));
2519 static void gen_label_die
PROTO((tree
, dw_die_ref
));
2520 static void gen_lexical_block_die
PROTO((tree
, dw_die_ref
, int));
2521 static void gen_inlined_subroutine_die
PROTO((tree
, dw_die_ref
, int));
2522 static void gen_field_die
PROTO((tree
, dw_die_ref
));
2523 static void gen_ptr_to_mbr_type_die
PROTO((tree
, dw_die_ref
));
2524 static void gen_compile_unit_die
PROTO((char *));
2525 static void gen_string_type_die
PROTO((tree
, dw_die_ref
));
2526 static void gen_inheritance_die
PROTO((tree
, dw_die_ref
));
2527 static void gen_member_die
PROTO((tree
, dw_die_ref
));
2528 static void gen_struct_or_union_type_die
PROTO((tree
, dw_die_ref
));
2529 static void gen_subroutine_type_die
PROTO((tree
, dw_die_ref
));
2530 static void gen_typedef_die
PROTO((tree
, dw_die_ref
));
2531 static void gen_type_die
PROTO((tree
, dw_die_ref
));
2532 static void gen_tagged_type_instantiation_die
PROTO((tree
, dw_die_ref
));
2533 static void gen_block_die
PROTO((tree
, dw_die_ref
, int));
2534 static void decls_for_scope
PROTO((tree
, dw_die_ref
, int));
2535 static int is_redundant_typedef
PROTO((tree
));
2536 static void gen_decl_die
PROTO((tree
, dw_die_ref
));
2537 static unsigned lookup_filename
PROTO((char *));
2539 /* Section names used to hold DWARF debugging information. */
2540 #ifndef DEBUG_INFO_SECTION
2541 #define DEBUG_INFO_SECTION ".debug_info"
2543 #ifndef ABBREV_SECTION
2544 #define ABBREV_SECTION ".debug_abbrev"
2546 #ifndef ARANGES_SECTION
2547 #define ARANGES_SECTION ".debug_aranges"
2549 #ifndef DW_MACINFO_SECTION
2550 #define DW_MACINFO_SECTION ".debug_macinfo"
2552 #ifndef DEBUG_LINE_SECTION
2553 #define DEBUG_LINE_SECTION ".debug_line"
2556 #define LOC_SECTION ".debug_loc"
2558 #ifndef PUBNAMES_SECTION
2559 #define PUBNAMES_SECTION ".debug_pubnames"
2562 #define STR_SECTION ".debug_str"
2565 /* Standard ELF section names for compiled code and data. */
2566 #ifndef TEXT_SECTION
2567 #define TEXT_SECTION ".text"
2569 #ifndef DATA_SECTION
2570 #define DATA_SECTION ".data"
2573 #define BSS_SECTION ".bss"
2577 /* Definitions of defaults for formats and names of various special
2578 (artificial) labels which may be generated within this file (when the -g
2579 options is used and DWARF_DEBUGGING_INFO is in effect.
2580 If necessary, these may be overridden from within the tm.h file, but
2581 typically, overriding these defaults is unnecessary. */
2583 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2585 #ifndef TEXT_END_LABEL
2586 #define TEXT_END_LABEL "Letext"
2588 #ifndef DATA_END_LABEL
2589 #define DATA_END_LABEL "Ledata"
2591 #ifndef BSS_END_LABEL
2592 #define BSS_END_LABEL "Lebss"
2594 #ifndef INSN_LABEL_FMT
2595 #define INSN_LABEL_FMT "LI%u_"
2597 #ifndef BLOCK_BEGIN_LABEL
2598 #define BLOCK_BEGIN_LABEL "LBB"
2600 #ifndef BLOCK_END_LABEL
2601 #define BLOCK_END_LABEL "LBE"
2603 #ifndef BODY_BEGIN_LABEL
2604 #define BODY_BEGIN_LABEL "Lbb"
2606 #ifndef BODY_END_LABEL
2607 #define BODY_END_LABEL "Lbe"
2609 #ifndef LINE_CODE_LABEL
2610 #define LINE_CODE_LABEL "LM"
2612 #ifndef SEPARATE_LINE_CODE_LABEL
2613 #define SEPARATE_LINE_CODE_LABEL "LSM"
2616 /* Convert a reference to the assembler name of a C-level name. This
2617 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
2618 a string rather than writing to a file. */
2619 #ifndef ASM_NAME_TO_STRING
2620 #define ASM_NAME_TO_STRING(STR, NAME) \
2622 if ((NAME)[0] == '*') \
2623 strcpy (STR, NAME+1); \
2625 strcpy (STR, NAME); \
2630 /* Convert an integer constant expression into assembler syntax. Addition
2631 and subtraction are the only arithmetic that may appear in these
2632 expressions. This is an adaptation of output_addr_const in final.c.
2633 Here, the target of the conversion is a string buffer. We can't use
2634 output_addr_const directly, because it writes to a file. */
2637 addr_const_to_string (str
, x
)
2646 switch (GET_CODE (x
))
2656 ASM_NAME_TO_STRING (buf1
, XSTR (x
, 0));
2661 ASM_GENERATE_INTERNAL_LABEL (buf1
, "L", CODE_LABEL_NUMBER (XEXP (x
, 0)));
2662 ASM_NAME_TO_STRING (buf2
, buf1
);
2667 ASM_GENERATE_INTERNAL_LABEL (buf1
, "L", CODE_LABEL_NUMBER (x
));
2668 ASM_NAME_TO_STRING (buf2
, buf1
);
2673 sprintf (buf1
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
));
2678 /* This used to output parentheses around the expression, but that does
2679 not work on the 386 (either ATT or BSD assembler). */
2680 addr_const_to_string (buf1
, XEXP (x
, 0));
2685 if (GET_MODE (x
) == VOIDmode
)
2687 /* We can use %d if the number is one word and positive. */
2688 if (CONST_DOUBLE_HIGH (x
))
2689 sprintf (buf1
, HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
2690 CONST_DOUBLE_HIGH (x
), CONST_DOUBLE_LOW (x
));
2691 else if (CONST_DOUBLE_LOW (x
) < 0)
2692 sprintf (buf1
, HOST_WIDE_INT_PRINT_HEX
, CONST_DOUBLE_LOW (x
));
2694 sprintf (buf1
, HOST_WIDE_INT_PRINT_DEC
,
2695 CONST_DOUBLE_LOW (x
));
2699 /* We can't handle floating point constants; PRINT_OPERAND must
2701 output_operand_lossage ("floating constant misused");
2705 /* Some assemblers need integer constants to appear last (eg masm). */
2706 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
2708 addr_const_to_string (buf1
, XEXP (x
, 1));
2710 if (INTVAL (XEXP (x
, 0)) >= 0)
2713 addr_const_to_string (buf1
, XEXP (x
, 0));
2718 addr_const_to_string (buf1
, XEXP (x
, 0));
2720 if (INTVAL (XEXP (x
, 1)) >= 0)
2723 addr_const_to_string (buf1
, XEXP (x
, 1));
2729 /* Avoid outputting things like x-x or x+5-x, since some assemblers
2730 can't handle that. */
2731 x
= simplify_subtraction (x
);
2732 if (GET_CODE (x
) != MINUS
)
2735 addr_const_to_string (buf1
, XEXP (x
, 0));
2738 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
2739 && INTVAL (XEXP (x
, 1)) < 0)
2741 strcat (str
, ASM_OPEN_PAREN
);
2742 addr_const_to_string (buf1
, XEXP (x
, 1));
2744 strcat (str
, ASM_CLOSE_PAREN
);
2748 addr_const_to_string (buf1
, XEXP (x
, 1));
2755 addr_const_to_string (buf1
, XEXP (x
, 0));
2760 output_operand_lossage ("invalid expression as operand");
2764 /* Convert an address constant to a string, and return a pointer to
2765 a copy of the result, located on the heap. */
2772 addr_const_to_string (buf
, x
);
2773 return xstrdup (buf
);
2776 /* Test if rtl node points to a pseudo register. */
2782 return (((GET_CODE (rtl
) == REG
) && (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
))
2783 || ((GET_CODE (rtl
) == SUBREG
)
2784 && (REGNO (XEXP (rtl
, 0)) >= FIRST_PSEUDO_REGISTER
)));
2787 /* Return a reference to a type, with its const and volatile qualifiers
2791 type_main_variant (type
)
2794 type
= TYPE_MAIN_VARIANT (type
);
2796 /* There really should be only one main variant among any group of variants
2797 of a given type (and all of the MAIN_VARIANT values for all members of
2798 the group should point to that one type) but sometimes the C front-end
2799 messes this up for array types, so we work around that bug here. */
2801 if (TREE_CODE (type
) == ARRAY_TYPE
)
2802 while (type
!= TYPE_MAIN_VARIANT (type
))
2803 type
= TYPE_MAIN_VARIANT (type
);
2808 /* Return non-zero if the given type node represents a tagged type. */
2811 is_tagged_type (type
)
2814 register enum tree_code code
= TREE_CODE (type
);
2816 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
2817 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
2820 /* Convert a DIE tag into its string name. */
2823 dwarf_tag_name (tag
)
2824 register unsigned tag
;
2828 case DW_TAG_padding
:
2829 return "DW_TAG_padding";
2830 case DW_TAG_array_type
:
2831 return "DW_TAG_array_type";
2832 case DW_TAG_class_type
:
2833 return "DW_TAG_class_type";
2834 case DW_TAG_entry_point
:
2835 return "DW_TAG_entry_point";
2836 case DW_TAG_enumeration_type
:
2837 return "DW_TAG_enumeration_type";
2838 case DW_TAG_formal_parameter
:
2839 return "DW_TAG_formal_parameter";
2840 case DW_TAG_imported_declaration
:
2841 return "DW_TAG_imported_declaration";
2843 return "DW_TAG_label";
2844 case DW_TAG_lexical_block
:
2845 return "DW_TAG_lexical_block";
2847 return "DW_TAG_member";
2848 case DW_TAG_pointer_type
:
2849 return "DW_TAG_pointer_type";
2850 case DW_TAG_reference_type
:
2851 return "DW_TAG_reference_type";
2852 case DW_TAG_compile_unit
:
2853 return "DW_TAG_compile_unit";
2854 case DW_TAG_string_type
:
2855 return "DW_TAG_string_type";
2856 case DW_TAG_structure_type
:
2857 return "DW_TAG_structure_type";
2858 case DW_TAG_subroutine_type
:
2859 return "DW_TAG_subroutine_type";
2860 case DW_TAG_typedef
:
2861 return "DW_TAG_typedef";
2862 case DW_TAG_union_type
:
2863 return "DW_TAG_union_type";
2864 case DW_TAG_unspecified_parameters
:
2865 return "DW_TAG_unspecified_parameters";
2866 case DW_TAG_variant
:
2867 return "DW_TAG_variant";
2868 case DW_TAG_common_block
:
2869 return "DW_TAG_common_block";
2870 case DW_TAG_common_inclusion
:
2871 return "DW_TAG_common_inclusion";
2872 case DW_TAG_inheritance
:
2873 return "DW_TAG_inheritance";
2874 case DW_TAG_inlined_subroutine
:
2875 return "DW_TAG_inlined_subroutine";
2877 return "DW_TAG_module";
2878 case DW_TAG_ptr_to_member_type
:
2879 return "DW_TAG_ptr_to_member_type";
2880 case DW_TAG_set_type
:
2881 return "DW_TAG_set_type";
2882 case DW_TAG_subrange_type
:
2883 return "DW_TAG_subrange_type";
2884 case DW_TAG_with_stmt
:
2885 return "DW_TAG_with_stmt";
2886 case DW_TAG_access_declaration
:
2887 return "DW_TAG_access_declaration";
2888 case DW_TAG_base_type
:
2889 return "DW_TAG_base_type";
2890 case DW_TAG_catch_block
:
2891 return "DW_TAG_catch_block";
2892 case DW_TAG_const_type
:
2893 return "DW_TAG_const_type";
2894 case DW_TAG_constant
:
2895 return "DW_TAG_constant";
2896 case DW_TAG_enumerator
:
2897 return "DW_TAG_enumerator";
2898 case DW_TAG_file_type
:
2899 return "DW_TAG_file_type";
2901 return "DW_TAG_friend";
2902 case DW_TAG_namelist
:
2903 return "DW_TAG_namelist";
2904 case DW_TAG_namelist_item
:
2905 return "DW_TAG_namelist_item";
2906 case DW_TAG_packed_type
:
2907 return "DW_TAG_packed_type";
2908 case DW_TAG_subprogram
:
2909 return "DW_TAG_subprogram";
2910 case DW_TAG_template_type_param
:
2911 return "DW_TAG_template_type_param";
2912 case DW_TAG_template_value_param
:
2913 return "DW_TAG_template_value_param";
2914 case DW_TAG_thrown_type
:
2915 return "DW_TAG_thrown_type";
2916 case DW_TAG_try_block
:
2917 return "DW_TAG_try_block";
2918 case DW_TAG_variant_part
:
2919 return "DW_TAG_variant_part";
2920 case DW_TAG_variable
:
2921 return "DW_TAG_variable";
2922 case DW_TAG_volatile_type
:
2923 return "DW_TAG_volatile_type";
2924 case DW_TAG_MIPS_loop
:
2925 return "DW_TAG_MIPS_loop";
2926 case DW_TAG_format_label
:
2927 return "DW_TAG_format_label";
2928 case DW_TAG_function_template
:
2929 return "DW_TAG_function_template";
2930 case DW_TAG_class_template
:
2931 return "DW_TAG_class_template";
2933 return "DW_TAG_<unknown>";
2937 /* Convert a DWARF attribute code into its string name. */
2940 dwarf_attr_name (attr
)
2941 register unsigned attr
;
2946 return "DW_AT_sibling";
2947 case DW_AT_location
:
2948 return "DW_AT_location";
2950 return "DW_AT_name";
2951 case DW_AT_ordering
:
2952 return "DW_AT_ordering";
2953 case DW_AT_subscr_data
:
2954 return "DW_AT_subscr_data";
2955 case DW_AT_byte_size
:
2956 return "DW_AT_byte_size";
2957 case DW_AT_bit_offset
:
2958 return "DW_AT_bit_offset";
2959 case DW_AT_bit_size
:
2960 return "DW_AT_bit_size";
2961 case DW_AT_element_list
:
2962 return "DW_AT_element_list";
2963 case DW_AT_stmt_list
:
2964 return "DW_AT_stmt_list";
2966 return "DW_AT_low_pc";
2968 return "DW_AT_high_pc";
2969 case DW_AT_language
:
2970 return "DW_AT_language";
2972 return "DW_AT_member";
2974 return "DW_AT_discr";
2975 case DW_AT_discr_value
:
2976 return "DW_AT_discr_value";
2977 case DW_AT_visibility
:
2978 return "DW_AT_visibility";
2980 return "DW_AT_import";
2981 case DW_AT_string_length
:
2982 return "DW_AT_string_length";
2983 case DW_AT_common_reference
:
2984 return "DW_AT_common_reference";
2985 case DW_AT_comp_dir
:
2986 return "DW_AT_comp_dir";
2987 case DW_AT_const_value
:
2988 return "DW_AT_const_value";
2989 case DW_AT_containing_type
:
2990 return "DW_AT_containing_type";
2991 case DW_AT_default_value
:
2992 return "DW_AT_default_value";
2994 return "DW_AT_inline";
2995 case DW_AT_is_optional
:
2996 return "DW_AT_is_optional";
2997 case DW_AT_lower_bound
:
2998 return "DW_AT_lower_bound";
2999 case DW_AT_producer
:
3000 return "DW_AT_producer";
3001 case DW_AT_prototyped
:
3002 return "DW_AT_prototyped";
3003 case DW_AT_return_addr
:
3004 return "DW_AT_return_addr";
3005 case DW_AT_start_scope
:
3006 return "DW_AT_start_scope";
3007 case DW_AT_stride_size
:
3008 return "DW_AT_stride_size";
3009 case DW_AT_upper_bound
:
3010 return "DW_AT_upper_bound";
3011 case DW_AT_abstract_origin
:
3012 return "DW_AT_abstract_origin";
3013 case DW_AT_accessibility
:
3014 return "DW_AT_accessibility";
3015 case DW_AT_address_class
:
3016 return "DW_AT_address_class";
3017 case DW_AT_artificial
:
3018 return "DW_AT_artificial";
3019 case DW_AT_base_types
:
3020 return "DW_AT_base_types";
3021 case DW_AT_calling_convention
:
3022 return "DW_AT_calling_convention";
3024 return "DW_AT_count";
3025 case DW_AT_data_member_location
:
3026 return "DW_AT_data_member_location";
3027 case DW_AT_decl_column
:
3028 return "DW_AT_decl_column";
3029 case DW_AT_decl_file
:
3030 return "DW_AT_decl_file";
3031 case DW_AT_decl_line
:
3032 return "DW_AT_decl_line";
3033 case DW_AT_declaration
:
3034 return "DW_AT_declaration";
3035 case DW_AT_discr_list
:
3036 return "DW_AT_discr_list";
3037 case DW_AT_encoding
:
3038 return "DW_AT_encoding";
3039 case DW_AT_external
:
3040 return "DW_AT_external";
3041 case DW_AT_frame_base
:
3042 return "DW_AT_frame_base";
3044 return "DW_AT_friend";
3045 case DW_AT_identifier_case
:
3046 return "DW_AT_identifier_case";
3047 case DW_AT_macro_info
:
3048 return "DW_AT_macro_info";
3049 case DW_AT_namelist_items
:
3050 return "DW_AT_namelist_items";
3051 case DW_AT_priority
:
3052 return "DW_AT_priority";
3054 return "DW_AT_segment";
3055 case DW_AT_specification
:
3056 return "DW_AT_specification";
3057 case DW_AT_static_link
:
3058 return "DW_AT_static_link";
3060 return "DW_AT_type";
3061 case DW_AT_use_location
:
3062 return "DW_AT_use_location";
3063 case DW_AT_variable_parameter
:
3064 return "DW_AT_variable_parameter";
3065 case DW_AT_virtuality
:
3066 return "DW_AT_virtuality";
3067 case DW_AT_vtable_elem_location
:
3068 return "DW_AT_vtable_elem_location";
3070 case DW_AT_MIPS_fde
:
3071 return "DW_AT_MIPS_fde";
3072 case DW_AT_MIPS_loop_begin
:
3073 return "DW_AT_MIPS_loop_begin";
3074 case DW_AT_MIPS_tail_loop_begin
:
3075 return "DW_AT_MIPS_tail_loop_begin";
3076 case DW_AT_MIPS_epilog_begin
:
3077 return "DW_AT_MIPS_epilog_begin";
3078 case DW_AT_MIPS_loop_unroll_factor
:
3079 return "DW_AT_MIPS_loop_unroll_factor";
3080 case DW_AT_MIPS_software_pipeline_depth
:
3081 return "DW_AT_MIPS_software_pipeline_depth";
3082 case DW_AT_MIPS_linkage_name
:
3083 return "DW_AT_MIPS_linkage_name";
3084 case DW_AT_MIPS_stride
:
3085 return "DW_AT_MIPS_stride";
3086 case DW_AT_MIPS_abstract_name
:
3087 return "DW_AT_MIPS_abstract_name";
3088 case DW_AT_MIPS_clone_origin
:
3089 return "DW_AT_MIPS_clone_origin";
3090 case DW_AT_MIPS_has_inlines
:
3091 return "DW_AT_MIPS_has_inlines";
3093 case DW_AT_sf_names
:
3094 return "DW_AT_sf_names";
3095 case DW_AT_src_info
:
3096 return "DW_AT_src_info";
3097 case DW_AT_mac_info
:
3098 return "DW_AT_mac_info";
3099 case DW_AT_src_coords
:
3100 return "DW_AT_src_coords";
3101 case DW_AT_body_begin
:
3102 return "DW_AT_body_begin";
3103 case DW_AT_body_end
:
3104 return "DW_AT_body_end";
3106 return "DW_AT_<unknown>";
3110 /* Convert a DWARF value form code into its string name. */
3113 dwarf_form_name (form
)
3114 register unsigned form
;
3119 return "DW_FORM_addr";
3120 case DW_FORM_block2
:
3121 return "DW_FORM_block2";
3122 case DW_FORM_block4
:
3123 return "DW_FORM_block4";
3125 return "DW_FORM_data2";
3127 return "DW_FORM_data4";
3129 return "DW_FORM_data8";
3130 case DW_FORM_string
:
3131 return "DW_FORM_string";
3133 return "DW_FORM_block";
3134 case DW_FORM_block1
:
3135 return "DW_FORM_block1";
3137 return "DW_FORM_data1";
3139 return "DW_FORM_flag";
3141 return "DW_FORM_sdata";
3143 return "DW_FORM_strp";
3145 return "DW_FORM_udata";
3146 case DW_FORM_ref_addr
:
3147 return "DW_FORM_ref_addr";
3149 return "DW_FORM_ref1";
3151 return "DW_FORM_ref2";
3153 return "DW_FORM_ref4";
3155 return "DW_FORM_ref8";
3156 case DW_FORM_ref_udata
:
3157 return "DW_FORM_ref_udata";
3158 case DW_FORM_indirect
:
3159 return "DW_FORM_indirect";
3161 return "DW_FORM_<unknown>";
3165 /* Convert a DWARF stack opcode into its string name. */
3168 dwarf_stack_op_name (op
)
3169 register unsigned op
;
3174 return "DW_OP_addr";
3176 return "DW_OP_deref";
3178 return "DW_OP_const1u";
3180 return "DW_OP_const1s";
3182 return "DW_OP_const2u";
3184 return "DW_OP_const2s";
3186 return "DW_OP_const4u";
3188 return "DW_OP_const4s";
3190 return "DW_OP_const8u";
3192 return "DW_OP_const8s";
3194 return "DW_OP_constu";
3196 return "DW_OP_consts";
3200 return "DW_OP_drop";
3202 return "DW_OP_over";
3204 return "DW_OP_pick";
3206 return "DW_OP_swap";
3210 return "DW_OP_xderef";
3218 return "DW_OP_minus";
3230 return "DW_OP_plus";
3231 case DW_OP_plus_uconst
:
3232 return "DW_OP_plus_uconst";
3238 return "DW_OP_shra";
3256 return "DW_OP_skip";
3258 return "DW_OP_lit0";
3260 return "DW_OP_lit1";
3262 return "DW_OP_lit2";
3264 return "DW_OP_lit3";
3266 return "DW_OP_lit4";
3268 return "DW_OP_lit5";
3270 return "DW_OP_lit6";
3272 return "DW_OP_lit7";
3274 return "DW_OP_lit8";
3276 return "DW_OP_lit9";
3278 return "DW_OP_lit10";
3280 return "DW_OP_lit11";
3282 return "DW_OP_lit12";
3284 return "DW_OP_lit13";
3286 return "DW_OP_lit14";
3288 return "DW_OP_lit15";
3290 return "DW_OP_lit16";
3292 return "DW_OP_lit17";
3294 return "DW_OP_lit18";
3296 return "DW_OP_lit19";
3298 return "DW_OP_lit20";
3300 return "DW_OP_lit21";
3302 return "DW_OP_lit22";
3304 return "DW_OP_lit23";
3306 return "DW_OP_lit24";
3308 return "DW_OP_lit25";
3310 return "DW_OP_lit26";
3312 return "DW_OP_lit27";
3314 return "DW_OP_lit28";
3316 return "DW_OP_lit29";
3318 return "DW_OP_lit30";
3320 return "DW_OP_lit31";
3322 return "DW_OP_reg0";
3324 return "DW_OP_reg1";
3326 return "DW_OP_reg2";
3328 return "DW_OP_reg3";
3330 return "DW_OP_reg4";
3332 return "DW_OP_reg5";
3334 return "DW_OP_reg6";
3336 return "DW_OP_reg7";
3338 return "DW_OP_reg8";
3340 return "DW_OP_reg9";
3342 return "DW_OP_reg10";
3344 return "DW_OP_reg11";
3346 return "DW_OP_reg12";
3348 return "DW_OP_reg13";
3350 return "DW_OP_reg14";
3352 return "DW_OP_reg15";
3354 return "DW_OP_reg16";
3356 return "DW_OP_reg17";
3358 return "DW_OP_reg18";
3360 return "DW_OP_reg19";
3362 return "DW_OP_reg20";
3364 return "DW_OP_reg21";
3366 return "DW_OP_reg22";
3368 return "DW_OP_reg23";
3370 return "DW_OP_reg24";
3372 return "DW_OP_reg25";
3374 return "DW_OP_reg26";
3376 return "DW_OP_reg27";
3378 return "DW_OP_reg28";
3380 return "DW_OP_reg29";
3382 return "DW_OP_reg30";
3384 return "DW_OP_reg31";
3386 return "DW_OP_breg0";
3388 return "DW_OP_breg1";
3390 return "DW_OP_breg2";
3392 return "DW_OP_breg3";
3394 return "DW_OP_breg4";
3396 return "DW_OP_breg5";
3398 return "DW_OP_breg6";
3400 return "DW_OP_breg7";
3402 return "DW_OP_breg8";
3404 return "DW_OP_breg9";
3406 return "DW_OP_breg10";
3408 return "DW_OP_breg11";
3410 return "DW_OP_breg12";
3412 return "DW_OP_breg13";
3414 return "DW_OP_breg14";
3416 return "DW_OP_breg15";
3418 return "DW_OP_breg16";
3420 return "DW_OP_breg17";
3422 return "DW_OP_breg18";
3424 return "DW_OP_breg19";
3426 return "DW_OP_breg20";
3428 return "DW_OP_breg21";
3430 return "DW_OP_breg22";
3432 return "DW_OP_breg23";
3434 return "DW_OP_breg24";
3436 return "DW_OP_breg25";
3438 return "DW_OP_breg26";
3440 return "DW_OP_breg27";
3442 return "DW_OP_breg28";
3444 return "DW_OP_breg29";
3446 return "DW_OP_breg30";
3448 return "DW_OP_breg31";
3450 return "DW_OP_regx";
3452 return "DW_OP_fbreg";
3454 return "DW_OP_bregx";
3456 return "DW_OP_piece";
3457 case DW_OP_deref_size
:
3458 return "DW_OP_deref_size";
3459 case DW_OP_xderef_size
:
3460 return "DW_OP_xderef_size";
3464 return "OP_<unknown>";
3468 /* Convert a DWARF type code into its string name. */
3471 dwarf_type_encoding_name (enc
)
3472 register unsigned enc
;
3476 case DW_ATE_address
:
3477 return "DW_ATE_address";
3478 case DW_ATE_boolean
:
3479 return "DW_ATE_boolean";
3480 case DW_ATE_complex_float
:
3481 return "DW_ATE_complex_float";
3483 return "DW_ATE_float";
3485 return "DW_ATE_signed";
3486 case DW_ATE_signed_char
:
3487 return "DW_ATE_signed_char";
3488 case DW_ATE_unsigned
:
3489 return "DW_ATE_unsigned";
3490 case DW_ATE_unsigned_char
:
3491 return "DW_ATE_unsigned_char";
3493 return "DW_ATE_<unknown>";
3497 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3498 instance of an inlined instance of a decl which is local to an inline
3499 function, so we have to trace all of the way back through the origin chain
3500 to find out what sort of node actually served as the original seed for the
3504 decl_ultimate_origin (decl
)
3507 register tree immediate_origin
= DECL_ABSTRACT_ORIGIN (decl
);
3509 if (immediate_origin
== NULL_TREE
)
3513 register tree ret_val
;
3514 register tree lookahead
= immediate_origin
;
3518 ret_val
= lookahead
;
3519 lookahead
= DECL_ABSTRACT_ORIGIN (ret_val
);
3521 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
3527 /* Determine the "ultimate origin" of a block. The block may be an inlined
3528 instance of an inlined instance of a block which is local to an inline
3529 function, so we have to trace all of the way back through the origin chain
3530 to find out what sort of node actually served as the original seed for the
3534 block_ultimate_origin (block
)
3535 register tree block
;
3537 register tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
3539 if (immediate_origin
== NULL_TREE
)
3543 register tree ret_val
;
3544 register tree lookahead
= immediate_origin
;
3548 ret_val
= lookahead
;
3549 lookahead
= (TREE_CODE (ret_val
) == BLOCK
)
3550 ? BLOCK_ABSTRACT_ORIGIN (ret_val
)
3553 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
3559 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3560 of a virtual function may refer to a base class, so we check the 'this'
3564 decl_class_context (decl
)
3567 tree context
= NULL_TREE
;
3569 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3570 context
= DECL_CONTEXT (decl
);
3572 context
= TYPE_MAIN_VARIANT
3573 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3575 if (context
&& TREE_CODE_CLASS (TREE_CODE (context
)) != 't')
3576 context
= NULL_TREE
;
3581 /* Add an attribute/value pair to a DIE */
3584 add_dwarf_attr (die
, attr
)
3585 register dw_die_ref die
;
3586 register dw_attr_ref attr
;
3588 if (die
!= NULL
&& attr
!= NULL
)
3590 if (die
->die_attr
== NULL
)
3592 die
->die_attr
= attr
;
3593 die
->die_attr_last
= attr
;
3597 die
->die_attr_last
->dw_attr_next
= attr
;
3598 die
->die_attr_last
= attr
;
3603 /* Add a flag value attribute to a DIE. */
3606 add_AT_flag (die
, attr_kind
, flag
)
3607 register dw_die_ref die
;
3608 register enum dwarf_attribute attr_kind
;
3609 register unsigned flag
;
3611 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3613 attr
->dw_attr_next
= NULL
;
3614 attr
->dw_attr
= attr_kind
;
3615 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
3616 attr
->dw_attr_val
.v
.val_flag
= flag
;
3617 add_dwarf_attr (die
, attr
);
3620 /* Add a signed integer attribute value to a DIE. */
3623 add_AT_int (die
, attr_kind
, int_val
)
3624 register dw_die_ref die
;
3625 register enum dwarf_attribute attr_kind
;
3626 register long int int_val
;
3628 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3630 attr
->dw_attr_next
= NULL
;
3631 attr
->dw_attr
= attr_kind
;
3632 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
3633 attr
->dw_attr_val
.v
.val_int
= int_val
;
3634 add_dwarf_attr (die
, attr
);
3637 /* Add an unsigned integer attribute value to a DIE. */
3640 add_AT_unsigned (die
, attr_kind
, unsigned_val
)
3641 register dw_die_ref die
;
3642 register enum dwarf_attribute attr_kind
;
3643 register unsigned long unsigned_val
;
3645 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3647 attr
->dw_attr_next
= NULL
;
3648 attr
->dw_attr
= attr_kind
;
3649 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3650 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3651 add_dwarf_attr (die
, attr
);
3654 /* Add an unsigned double integer attribute value to a DIE. */
3657 add_AT_long_long (die
, attr_kind
, val_hi
, val_low
)
3658 register dw_die_ref die
;
3659 register enum dwarf_attribute attr_kind
;
3660 register unsigned long val_hi
;
3661 register unsigned long val_low
;
3663 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3665 attr
->dw_attr_next
= NULL
;
3666 attr
->dw_attr
= attr_kind
;
3667 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
3668 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
3669 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
3670 add_dwarf_attr (die
, attr
);
3673 /* Add a floating point attribute value to a DIE and return it. */
3676 add_AT_float (die
, attr_kind
, length
, array
)
3677 register dw_die_ref die
;
3678 register enum dwarf_attribute attr_kind
;
3679 register unsigned length
;
3680 register long *array
;
3682 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3684 attr
->dw_attr_next
= NULL
;
3685 attr
->dw_attr
= attr_kind
;
3686 attr
->dw_attr_val
.val_class
= dw_val_class_float
;
3687 attr
->dw_attr_val
.v
.val_float
.length
= length
;
3688 attr
->dw_attr_val
.v
.val_float
.array
= array
;
3689 add_dwarf_attr (die
, attr
);
3692 /* Add a string attribute value to a DIE. */
3695 add_AT_string (die
, attr_kind
, str
)
3696 register dw_die_ref die
;
3697 register enum dwarf_attribute attr_kind
;
3700 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3702 attr
->dw_attr_next
= NULL
;
3703 attr
->dw_attr
= attr_kind
;
3704 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
3705 attr
->dw_attr_val
.v
.val_str
= xstrdup (str
);
3706 add_dwarf_attr (die
, attr
);
3709 /* Add a DIE reference attribute value to a DIE. */
3712 add_AT_die_ref (die
, attr_kind
, targ_die
)
3713 register dw_die_ref die
;
3714 register enum dwarf_attribute attr_kind
;
3715 register dw_die_ref targ_die
;
3717 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3719 attr
->dw_attr_next
= NULL
;
3720 attr
->dw_attr
= attr_kind
;
3721 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
3722 attr
->dw_attr_val
.v
.val_die_ref
= targ_die
;
3723 add_dwarf_attr (die
, attr
);
3726 /* Add an FDE reference attribute value to a DIE. */
3729 add_AT_fde_ref (die
, attr_kind
, targ_fde
)
3730 register dw_die_ref die
;
3731 register enum dwarf_attribute attr_kind
;
3732 register unsigned targ_fde
;
3734 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3736 attr
->dw_attr_next
= NULL
;
3737 attr
->dw_attr
= attr_kind
;
3738 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
3739 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
3740 add_dwarf_attr (die
, attr
);
3743 /* Add a location description attribute value to a DIE. */
3746 add_AT_loc (die
, attr_kind
, loc
)
3747 register dw_die_ref die
;
3748 register enum dwarf_attribute attr_kind
;
3749 register dw_loc_descr_ref loc
;
3751 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3753 attr
->dw_attr_next
= NULL
;
3754 attr
->dw_attr
= attr_kind
;
3755 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
3756 attr
->dw_attr_val
.v
.val_loc
= loc
;
3757 add_dwarf_attr (die
, attr
);
3760 /* Add an address constant attribute value to a DIE. */
3763 add_AT_addr (die
, attr_kind
, addr
)
3764 register dw_die_ref die
;
3765 register enum dwarf_attribute attr_kind
;
3768 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3770 attr
->dw_attr_next
= NULL
;
3771 attr
->dw_attr
= attr_kind
;
3772 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
3773 attr
->dw_attr_val
.v
.val_addr
= addr
;
3774 add_dwarf_attr (die
, attr
);
3777 /* Add a label identifier attribute value to a DIE. */
3780 add_AT_lbl_id (die
, attr_kind
, lbl_id
)
3781 register dw_die_ref die
;
3782 register enum dwarf_attribute attr_kind
;
3783 register char *lbl_id
;
3785 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3787 attr
->dw_attr_next
= NULL
;
3788 attr
->dw_attr
= attr_kind
;
3789 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3790 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
3791 add_dwarf_attr (die
, attr
);
3794 /* Add a section offset attribute value to a DIE. */
3797 add_AT_section_offset (die
, attr_kind
, section
)
3798 register dw_die_ref die
;
3799 register enum dwarf_attribute attr_kind
;
3800 register char *section
;
3802 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3804 attr
->dw_attr_next
= NULL
;
3805 attr
->dw_attr
= attr_kind
;
3806 attr
->dw_attr_val
.val_class
= dw_val_class_section_offset
;
3807 attr
->dw_attr_val
.v
.val_section
= section
;
3808 add_dwarf_attr (die
, attr
);
3812 /* Test if die refers to an external subroutine. */
3815 is_extern_subr_die (die
)
3816 register dw_die_ref die
;
3818 register dw_attr_ref a
;
3819 register int is_subr
= FALSE
;
3820 register int is_extern
= FALSE
;
3822 if (die
!= NULL
&& die
->die_tag
== DW_TAG_subprogram
)
3825 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
3827 if (a
->dw_attr
== DW_AT_external
3828 && a
->dw_attr_val
.val_class
== dw_val_class_flag
3829 && a
->dw_attr_val
.v
.val_flag
!= 0)
3837 return is_subr
&& is_extern
;
3840 /* Get the attribute of type attr_kind. */
3842 static inline dw_attr_ref
3843 get_AT (die
, attr_kind
)
3844 register dw_die_ref die
;
3845 register enum dwarf_attribute attr_kind
;
3847 register dw_attr_ref a
;
3848 register dw_die_ref spec
= NULL
;
3852 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
3854 if (a
->dw_attr
== attr_kind
)
3857 if (a
->dw_attr
== DW_AT_specification
3858 || a
->dw_attr
== DW_AT_abstract_origin
)
3859 spec
= a
->dw_attr_val
.v
.val_die_ref
;
3863 return get_AT (spec
, attr_kind
);
3869 /* Return the "low pc" attribute value, typically associated with
3870 a subprogram DIE. Return null if the "low pc" attribute is
3871 either not prsent, or if it cannot be represented as an
3872 assembler label identifier. */
3874 static inline char *
3876 register dw_die_ref die
;
3878 register dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
3880 if (a
&& a
->dw_attr_val
.val_class
== dw_val_class_lbl_id
)
3881 return a
->dw_attr_val
.v
.val_lbl_id
;
3886 /* Return the "high pc" attribute value, typically associated with
3887 a subprogram DIE. Return null if the "high pc" attribute is
3888 either not prsent, or if it cannot be represented as an
3889 assembler label identifier. */
3891 static inline char *
3893 register dw_die_ref die
;
3895 register dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
3897 if (a
&& a
->dw_attr_val
.val_class
== dw_val_class_lbl_id
)
3898 return a
->dw_attr_val
.v
.val_lbl_id
;
3903 /* Return the value of the string attribute designated by ATTR_KIND, or
3904 NULL if it is not present. */
3906 static inline char *
3907 get_AT_string (die
, attr_kind
)
3908 register dw_die_ref die
;
3909 register enum dwarf_attribute attr_kind
;
3911 register dw_attr_ref a
= get_AT (die
, attr_kind
);
3913 if (a
&& a
->dw_attr_val
.val_class
== dw_val_class_str
)
3914 return a
->dw_attr_val
.v
.val_str
;
3919 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3920 if it is not present. */
3923 get_AT_flag (die
, attr_kind
)
3924 register dw_die_ref die
;
3925 register enum dwarf_attribute attr_kind
;
3927 register dw_attr_ref a
= get_AT (die
, attr_kind
);
3929 if (a
&& a
->dw_attr_val
.val_class
== dw_val_class_flag
)
3930 return a
->dw_attr_val
.v
.val_flag
;
3935 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3936 if it is not present. */
3938 static inline unsigned
3939 get_AT_unsigned (die
, attr_kind
)
3940 register dw_die_ref die
;
3941 register enum dwarf_attribute attr_kind
;
3943 register dw_attr_ref a
= get_AT (die
, attr_kind
);
3945 if (a
&& a
->dw_attr_val
.val_class
== dw_val_class_unsigned_const
)
3946 return a
->dw_attr_val
.v
.val_unsigned
;
3954 register unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
3956 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
3957 || lang
== DW_LANG_C_plus_plus
);
3963 register unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
3965 return (lang
== DW_LANG_Fortran77
|| lang
== DW_LANG_Fortran90
);
3968 /* Remove the specified attribute if present. */
3971 remove_AT (die
, attr_kind
)
3972 register dw_die_ref die
;
3973 register enum dwarf_attribute attr_kind
;
3975 register dw_attr_ref a
;
3976 register dw_attr_ref removed
= NULL
;;
3980 if (die
->die_attr
->dw_attr
== attr_kind
)
3982 removed
= die
->die_attr
;
3983 if (die
->die_attr_last
== die
->die_attr
)
3984 die
->die_attr_last
= NULL
;
3986 die
->die_attr
= die
->die_attr
->dw_attr_next
;
3990 for (a
= die
->die_attr
; a
->dw_attr_next
!= NULL
;
3991 a
= a
->dw_attr_next
)
3992 if (a
->dw_attr_next
->dw_attr
== attr_kind
)
3994 removed
= a
->dw_attr_next
;
3995 if (die
->die_attr_last
== a
->dw_attr_next
)
3996 die
->die_attr_last
= a
;
3998 a
->dw_attr_next
= a
->dw_attr_next
->dw_attr_next
;
4007 /* Discard the children of this DIE. */
4010 remove_children (die
)
4011 register dw_die_ref die
;
4013 register dw_die_ref child_die
= die
->die_child
;
4015 die
->die_child
= NULL
;
4016 die
->die_child_last
= NULL
;
4018 while (child_die
!= NULL
)
4020 register dw_die_ref tmp_die
= child_die
;
4021 register dw_attr_ref a
;
4023 child_die
= child_die
->die_sib
;
4025 for (a
= tmp_die
->die_attr
; a
!= NULL
; )
4027 register dw_attr_ref tmp_a
= a
;
4029 a
= a
->dw_attr_next
;
4037 /* Add a child DIE below its parent. */
4040 add_child_die (die
, child_die
)
4041 register dw_die_ref die
;
4042 register dw_die_ref child_die
;
4044 if (die
!= NULL
&& child_die
!= NULL
)
4046 if (die
== child_die
)
4048 child_die
->die_parent
= die
;
4049 child_die
->die_sib
= NULL
;
4051 if (die
->die_child
== NULL
)
4053 die
->die_child
= child_die
;
4054 die
->die_child_last
= child_die
;
4058 die
->die_child_last
->die_sib
= child_die
;
4059 die
->die_child_last
= child_die
;
4064 /* Return a pointer to a newly created DIE node. */
4066 static inline dw_die_ref
4067 new_die (tag_value
, parent_die
)
4068 register enum dwarf_tag tag_value
;
4069 register dw_die_ref parent_die
;
4071 register dw_die_ref die
= (dw_die_ref
) xmalloc (sizeof (die_node
));
4073 die
->die_tag
= tag_value
;
4074 die
->die_abbrev
= 0;
4075 die
->die_offset
= 0;
4076 die
->die_child
= NULL
;
4077 die
->die_parent
= NULL
;
4078 die
->die_sib
= NULL
;
4079 die
->die_child_last
= NULL
;
4080 die
->die_attr
= NULL
;
4081 die
->die_attr_last
= NULL
;
4083 if (parent_die
!= NULL
)
4084 add_child_die (parent_die
, die
);
4087 limbo_die_node
*limbo_node
;
4089 limbo_node
= (limbo_die_node
*) xmalloc (sizeof (limbo_die_node
));
4090 limbo_node
->die
= die
;
4091 limbo_node
->next
= limbo_die_list
;
4092 limbo_die_list
= limbo_node
;
4098 /* Return the DIE associated with the given type specifier. */
4100 static inline dw_die_ref
4101 lookup_type_die (type
)
4104 return (dw_die_ref
) TYPE_SYMTAB_POINTER (type
);
4107 /* Equate a DIE to a given type specifier. */
4110 equate_type_number_to_die (type
, type_die
)
4112 register dw_die_ref type_die
;
4114 TYPE_SYMTAB_POINTER (type
) = (char *) type_die
;
4117 /* Return the DIE associated with a given declaration. */
4119 static inline dw_die_ref
4120 lookup_decl_die (decl
)
4123 register unsigned decl_id
= DECL_UID (decl
);
4125 return (decl_id
< decl_die_table_in_use
4126 ? decl_die_table
[decl_id
] : NULL
);
4129 /* Equate a DIE to a particular declaration. */
4132 equate_decl_number_to_die (decl
, decl_die
)
4134 register dw_die_ref decl_die
;
4136 register unsigned decl_id
= DECL_UID (decl
);
4137 register unsigned num_allocated
;
4139 if (decl_id
>= decl_die_table_allocated
)
4142 = ((decl_id
+ 1 + DECL_DIE_TABLE_INCREMENT
- 1)
4143 / DECL_DIE_TABLE_INCREMENT
)
4144 * DECL_DIE_TABLE_INCREMENT
;
4147 = (dw_die_ref
*) xrealloc (decl_die_table
,
4148 sizeof (dw_die_ref
) * num_allocated
);
4150 bzero ((char *) &decl_die_table
[decl_die_table_allocated
],
4151 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
4152 decl_die_table_allocated
= num_allocated
;
4155 if (decl_id
>= decl_die_table_in_use
)
4156 decl_die_table_in_use
= (decl_id
+ 1);
4158 decl_die_table
[decl_id
] = decl_die
;
4161 /* Return a pointer to a newly allocated location description. Location
4162 descriptions are simple expression terms that can be strung
4163 together to form more complicated location (address) descriptions. */
4165 static inline dw_loc_descr_ref
4166 new_loc_descr (op
, oprnd1
, oprnd2
)
4167 register enum dwarf_location_atom op
;
4168 register unsigned long oprnd1
;
4169 register unsigned long oprnd2
;
4171 register dw_loc_descr_ref descr
4172 = (dw_loc_descr_ref
) xmalloc (sizeof (dw_loc_descr_node
));
4174 descr
->dw_loc_next
= NULL
;
4175 descr
->dw_loc_opc
= op
;
4176 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
4177 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
4178 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
4179 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
4184 /* Add a location description term to a location description expression. */
4187 add_loc_descr (list_head
, descr
)
4188 register dw_loc_descr_ref
*list_head
;
4189 register dw_loc_descr_ref descr
;
4191 register dw_loc_descr_ref
*d
;
4193 /* Find the end of the chain. */
4194 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
4200 /* Keep track of the number of spaces used to indent the
4201 output of the debugging routines that print the structure of
4202 the DIE internal representation. */
4203 static int print_indent
;
4205 /* Indent the line the number of spaces given by print_indent. */
4208 print_spaces (outfile
)
4211 fprintf (outfile
, "%*s", print_indent
, "");
4214 /* Print the information associated with a given DIE, and its children.
4215 This routine is a debugging aid only. */
4218 print_die (die
, outfile
)
4222 register dw_attr_ref a
;
4223 register dw_die_ref c
;
4225 print_spaces (outfile
);
4226 fprintf (outfile
, "DIE %4lu: %s\n",
4227 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
4228 print_spaces (outfile
);
4229 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
4230 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
4232 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4234 print_spaces (outfile
);
4235 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
4237 switch (a
->dw_attr_val
.val_class
)
4239 case dw_val_class_addr
:
4240 fprintf (outfile
, "address");
4242 case dw_val_class_loc
:
4243 fprintf (outfile
, "location descriptor");
4245 case dw_val_class_const
:
4246 fprintf (outfile
, "%ld", a
->dw_attr_val
.v
.val_int
);
4248 case dw_val_class_unsigned_const
:
4249 fprintf (outfile
, "%lu", a
->dw_attr_val
.v
.val_unsigned
);
4251 case dw_val_class_long_long
:
4252 fprintf (outfile
, "constant (%lu,%lu)",
4253 a
->dw_attr_val
.v
.val_long_long
.hi
,
4254 a
->dw_attr_val
.v
.val_long_long
.low
);
4256 case dw_val_class_float
:
4257 fprintf (outfile
, "floating-point constant");
4259 case dw_val_class_flag
:
4260 fprintf (outfile
, "%u", a
->dw_attr_val
.v
.val_flag
);
4262 case dw_val_class_die_ref
:
4263 if (a
->dw_attr_val
.v
.val_die_ref
!= NULL
)
4264 fprintf (outfile
, "die -> %lu",
4265 a
->dw_attr_val
.v
.val_die_ref
->die_offset
);
4267 fprintf (outfile
, "die -> <null>");
4269 case dw_val_class_lbl_id
:
4270 fprintf (outfile
, "label: %s", a
->dw_attr_val
.v
.val_lbl_id
);
4272 case dw_val_class_section_offset
:
4273 fprintf (outfile
, "section: %s", a
->dw_attr_val
.v
.val_section
);
4275 case dw_val_class_str
:
4276 if (a
->dw_attr_val
.v
.val_str
!= NULL
)
4277 fprintf (outfile
, "\"%s\"", a
->dw_attr_val
.v
.val_str
);
4279 fprintf (outfile
, "<null>");
4285 fprintf (outfile
, "\n");
4288 if (die
->die_child
!= NULL
)
4291 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4292 print_die (c
, outfile
);
4298 /* Print the contents of the source code line number correspondence table.
4299 This routine is a debugging aid only. */
4302 print_dwarf_line_table (outfile
)
4305 register unsigned i
;
4306 register dw_line_info_ref line_info
;
4308 fprintf (outfile
, "\n\nDWARF source line information\n");
4309 for (i
= 1; i
< line_info_table_in_use
; ++i
)
4311 line_info
= &line_info_table
[i
];
4312 fprintf (outfile
, "%5d: ", i
);
4313 fprintf (outfile
, "%-20s", file_table
[line_info
->dw_file_num
]);
4314 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
4315 fprintf (outfile
, "\n");
4318 fprintf (outfile
, "\n\n");
4321 /* Print the information collected for a given DIE. */
4324 debug_dwarf_die (die
)
4327 print_die (die
, stderr
);
4330 /* Print all DWARF information collected for the compilation unit.
4331 This routine is a debugging aid only. */
4337 print_die (comp_unit_die
, stderr
);
4338 print_dwarf_line_table (stderr
);
4341 /* Traverse the DIE, and add a sibling attribute if it may have the
4342 effect of speeding up access to siblings. To save some space,
4343 avoid generating sibling attributes for DIE's without children. */
4346 add_sibling_attributes(die
)
4347 register dw_die_ref die
;
4349 register dw_die_ref c
;
4350 register dw_attr_ref attr
;
4351 if (die
!= comp_unit_die
&& die
->die_child
!= NULL
)
4353 attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4354 attr
->dw_attr_next
= NULL
;
4355 attr
->dw_attr
= DW_AT_sibling
;
4356 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
4357 attr
->dw_attr_val
.v
.val_die_ref
= die
->die_sib
;
4359 /* Add the sibling link to the front of the attribute list. */
4360 attr
->dw_attr_next
= die
->die_attr
;
4361 if (die
->die_attr
== NULL
)
4362 die
->die_attr_last
= attr
;
4364 die
->die_attr
= attr
;
4367 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4368 add_sibling_attributes (c
);
4371 /* The format of each DIE (and its attribute value pairs)
4372 is encoded in an abbreviation table. This routine builds the
4373 abbreviation table and assigns a unique abbreviation id for
4374 each abbreviation entry. The children of each die are visited
4378 build_abbrev_table (die
)
4379 register dw_die_ref die
;
4381 register unsigned long abbrev_id
;
4382 register unsigned long n_alloc
;
4383 register dw_die_ref c
;
4384 register dw_attr_ref d_attr
, a_attr
;
4385 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
4387 register dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
4389 if (abbrev
->die_tag
== die
->die_tag
)
4391 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
4393 a_attr
= abbrev
->die_attr
;
4394 d_attr
= die
->die_attr
;
4396 while (a_attr
!= NULL
&& d_attr
!= NULL
)
4398 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
4399 || (value_format (&a_attr
->dw_attr_val
)
4400 != value_format (&d_attr
->dw_attr_val
)))
4403 a_attr
= a_attr
->dw_attr_next
;
4404 d_attr
= d_attr
->dw_attr_next
;
4407 if (a_attr
== NULL
&& d_attr
== NULL
)
4413 if (abbrev_id
>= abbrev_die_table_in_use
)
4415 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
4417 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
4419 = (dw_die_ref
*) xrealloc (abbrev_die_table
,
4420 sizeof (dw_die_ref
) * n_alloc
);
4422 bzero ((char *) &abbrev_die_table
[abbrev_die_table_allocated
],
4423 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
4424 abbrev_die_table_allocated
= n_alloc
;
4427 ++abbrev_die_table_in_use
;
4428 abbrev_die_table
[abbrev_id
] = die
;
4431 die
->die_abbrev
= abbrev_id
;
4432 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4433 build_abbrev_table (c
);
4436 /* Return the size of a string, including the null byte. */
4438 static unsigned long
4439 size_of_string (str
)
4442 register unsigned long size
= 0;
4443 register unsigned long slen
= strlen (str
);
4444 register unsigned long i
;
4445 register unsigned c
;
4447 for (i
= 0; i
< slen
; ++i
)
4456 /* Null terminator. */
4461 /* Return the size of a location descriptor. */
4463 static unsigned long
4464 size_of_loc_descr (loc
)
4465 register dw_loc_descr_ref loc
;
4467 register unsigned long size
= 1;
4469 switch (loc
->dw_loc_opc
)
4491 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4494 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4499 case DW_OP_plus_uconst
:
4500 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4538 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4541 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4544 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4547 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4548 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
4551 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4553 case DW_OP_deref_size
:
4554 case DW_OP_xderef_size
:
4564 /* Return the size of a series of location descriptors. */
4566 static unsigned long
4568 register dw_loc_descr_ref loc
;
4570 register unsigned long size
= 0;
4572 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
4573 size
+= size_of_loc_descr (loc
);
4578 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4581 constant_size (value
)
4582 long unsigned value
;
4589 log
= floor_log2 (value
);
4592 log
= 1 << (floor_log2 (log
) + 1);
4597 /* Return the size of a DIE, as it is represented in the
4598 .debug_info section. */
4600 static unsigned long
4602 register dw_die_ref die
;
4604 register unsigned long size
= 0;
4605 register dw_attr_ref a
;
4607 size
+= size_of_uleb128 (die
->die_abbrev
);
4608 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4610 switch (a
->dw_attr_val
.val_class
)
4612 case dw_val_class_addr
:
4615 case dw_val_class_loc
:
4617 register unsigned long lsize
4618 = size_of_locs (a
->dw_attr_val
.v
.val_loc
);
4621 size
+= constant_size (lsize
);
4625 case dw_val_class_const
:
4628 case dw_val_class_unsigned_const
:
4629 size
+= constant_size (a
->dw_attr_val
.v
.val_unsigned
);
4631 case dw_val_class_long_long
:
4632 size
+= 1 + 8; /* block */
4634 case dw_val_class_float
:
4635 size
+= 1 + a
->dw_attr_val
.v
.val_float
.length
* 4; /* block */
4637 case dw_val_class_flag
:
4640 case dw_val_class_die_ref
:
4641 size
+= DWARF_OFFSET_SIZE
;
4643 case dw_val_class_fde_ref
:
4644 size
+= DWARF_OFFSET_SIZE
;
4646 case dw_val_class_lbl_id
:
4649 case dw_val_class_section_offset
:
4650 size
+= DWARF_OFFSET_SIZE
;
4652 case dw_val_class_str
:
4653 size
+= size_of_string (a
->dw_attr_val
.v
.val_str
);
4663 /* Size the debugging information associated with a given DIE.
4664 Visits the DIE's children recursively. Updates the global
4665 variable next_die_offset, on each time through. Uses the
4666 current value of next_die_offset to update the die_offset
4667 field in each DIE. */
4670 calc_die_sizes (die
)
4673 register dw_die_ref c
;
4674 die
->die_offset
= next_die_offset
;
4675 next_die_offset
+= size_of_die (die
);
4677 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4680 if (die
->die_child
!= NULL
)
4681 /* Count the null byte used to terminate sibling lists. */
4682 next_die_offset
+= 1;
4685 /* Return the size of the line information prolog generated for the
4686 compilation unit. */
4688 static unsigned long
4689 size_of_line_prolog ()
4691 register unsigned long size
;
4692 register unsigned long ft_index
;
4694 size
= DWARF_LINE_PROLOG_HEADER_SIZE
;
4696 /* Count the size of the table giving number of args for each
4698 size
+= DWARF_LINE_OPCODE_BASE
- 1;
4700 /* Include directory table is empty (at present). Count only the
4701 the null byte used to terminate the table. */
4704 for (ft_index
= 1; ft_index
< file_table_in_use
; ++ft_index
)
4706 /* File name entry. */
4707 size
+= size_of_string (file_table
[ft_index
]);
4709 /* Include directory index. */
4710 size
+= size_of_uleb128 (0);
4712 /* Modification time. */
4713 size
+= size_of_uleb128 (0);
4715 /* File length in bytes. */
4716 size
+= size_of_uleb128 (0);
4719 /* Count the file table terminator. */
4724 /* Return the size of the line information generated for this
4725 compilation unit. */
4727 static unsigned long
4728 size_of_line_info ()
4730 register unsigned long size
;
4731 register unsigned long lt_index
;
4732 register unsigned long current_line
;
4733 register long line_offset
;
4734 register long line_delta
;
4735 register unsigned long current_file
;
4736 register unsigned long function
;
4737 unsigned long size_of_set_address
;
4739 /* Size of a DW_LNE_set_address instruction. */
4740 size_of_set_address
= 1 + size_of_uleb128 (1 + PTR_SIZE
) + 1 + PTR_SIZE
;
4742 /* Version number. */
4745 /* Prolog length specifier. */
4746 size
+= DWARF_OFFSET_SIZE
;
4749 size
+= size_of_line_prolog ();
4751 /* Set address register instruction. */
4752 size
+= size_of_set_address
;
4756 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
4758 register dw_line_info_ref line_info
;
4760 /* Advance pc instruction. */
4761 /* ??? See the DW_LNS_advance_pc comment in output_line_info. */
4765 size
+= size_of_set_address
;
4767 line_info
= &line_info_table
[lt_index
];
4768 if (line_info
->dw_file_num
!= current_file
)
4770 /* Set file number instruction. */
4772 current_file
= line_info
->dw_file_num
;
4773 size
+= size_of_uleb128 (current_file
);
4776 if (line_info
->dw_line_num
!= current_line
)
4778 line_offset
= line_info
->dw_line_num
- current_line
;
4779 line_delta
= line_offset
- DWARF_LINE_BASE
;
4780 current_line
= line_info
->dw_line_num
;
4781 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
4782 /* 1-byte special line number instruction. */
4786 /* Advance line instruction. */
4788 size
+= size_of_sleb128 (line_offset
);
4789 /* Generate line entry instruction. */
4795 /* Advance pc instruction. */
4799 size
+= size_of_set_address
;
4801 /* End of line number info. marker. */
4802 size
+= 1 + size_of_uleb128 (1) + 1;
4807 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
; )
4809 register dw_separate_line_info_ref line_info
4810 = &separate_line_info_table
[lt_index
];
4811 if (function
!= line_info
->function
)
4813 function
= line_info
->function
;
4814 /* Set address register instruction. */
4815 size
+= size_of_set_address
;
4819 /* Advance pc instruction. */
4823 size
+= size_of_set_address
;
4826 if (line_info
->dw_file_num
!= current_file
)
4828 /* Set file number instruction. */
4830 current_file
= line_info
->dw_file_num
;
4831 size
+= size_of_uleb128 (current_file
);
4834 if (line_info
->dw_line_num
!= current_line
)
4836 line_offset
= line_info
->dw_line_num
- current_line
;
4837 line_delta
= line_offset
- DWARF_LINE_BASE
;
4838 current_line
= line_info
->dw_line_num
;
4839 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
4840 /* 1-byte special line number instruction. */
4844 /* Advance line instruction. */
4846 size
+= size_of_sleb128 (line_offset
);
4848 /* Generate line entry instruction. */
4855 /* If we're done with a function, end its sequence. */
4856 if (lt_index
== separate_line_info_table_in_use
4857 || separate_line_info_table
[lt_index
].function
!= function
)
4862 /* Advance pc instruction. */
4866 size
+= size_of_set_address
;
4868 /* End of line number info. marker. */
4869 size
+= 1 + size_of_uleb128 (1) + 1;
4876 /* Return the size of the .debug_pubnames table generated for the
4877 compilation unit. */
4879 static unsigned long
4882 register unsigned long size
;
4883 register unsigned i
;
4885 size
= DWARF_PUBNAMES_HEADER_SIZE
;
4886 for (i
= 0; i
< pubname_table_in_use
; ++i
)
4888 register pubname_ref p
= &pubname_table
[i
];
4889 size
+= DWARF_OFFSET_SIZE
+ size_of_string (p
->name
);
4892 size
+= DWARF_OFFSET_SIZE
;
4896 /* Return the size of the information in the .debug_aranges section. */
4898 static unsigned long
4901 register unsigned long size
;
4903 size
= DWARF_ARANGES_HEADER_SIZE
;
4905 /* Count the address/length pair for this compilation unit. */
4906 size
+= 2 * PTR_SIZE
;
4907 size
+= 2 * PTR_SIZE
* arange_table_in_use
;
4909 /* Count the two zero words used to terminated the address range table. */
4910 size
+= 2 * PTR_SIZE
;
4914 /* Select the encoding of an attribute value. */
4916 static enum dwarf_form
4920 switch (v
->val_class
)
4922 case dw_val_class_addr
:
4923 return DW_FORM_addr
;
4924 case dw_val_class_loc
:
4925 switch (constant_size (size_of_locs (v
->v
.val_loc
)))
4928 return DW_FORM_block1
;
4930 return DW_FORM_block2
;
4934 case dw_val_class_const
:
4935 return DW_FORM_data4
;
4936 case dw_val_class_unsigned_const
:
4937 switch (constant_size (v
->v
.val_unsigned
))
4940 return DW_FORM_data1
;
4942 return DW_FORM_data2
;
4944 return DW_FORM_data4
;
4946 return DW_FORM_data8
;
4950 case dw_val_class_long_long
:
4951 return DW_FORM_block1
;
4952 case dw_val_class_float
:
4953 return DW_FORM_block1
;
4954 case dw_val_class_flag
:
4955 return DW_FORM_flag
;
4956 case dw_val_class_die_ref
:
4958 case dw_val_class_fde_ref
:
4959 return DW_FORM_data
;
4960 case dw_val_class_lbl_id
:
4961 return DW_FORM_addr
;
4962 case dw_val_class_section_offset
:
4963 return DW_FORM_data
;
4964 case dw_val_class_str
:
4965 return DW_FORM_string
;
4971 /* Output the encoding of an attribute value. */
4974 output_value_format (v
)
4977 enum dwarf_form form
= value_format (v
);
4979 output_uleb128 (form
);
4981 fprintf (asm_out_file
, " (%s)", dwarf_form_name (form
));
4983 fputc ('\n', asm_out_file
);
4986 /* Output the .debug_abbrev section which defines the DIE abbreviation
4990 output_abbrev_section ()
4992 unsigned long abbrev_id
;
4995 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
4997 register dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
4999 output_uleb128 (abbrev_id
);
5001 fprintf (asm_out_file
, " (abbrev code)");
5003 fputc ('\n', asm_out_file
);
5004 output_uleb128 (abbrev
->die_tag
);
5006 fprintf (asm_out_file
, " (TAG: %s)",
5007 dwarf_tag_name (abbrev
->die_tag
));
5009 fputc ('\n', asm_out_file
);
5010 fprintf (asm_out_file
, "\t%s\t0x%x", ASM_BYTE_OP
,
5011 abbrev
->die_child
!= NULL
? DW_children_yes
: DW_children_no
);
5014 fprintf (asm_out_file
, "\t%s %s",
5016 (abbrev
->die_child
!= NULL
5017 ? "DW_children_yes" : "DW_children_no"));
5019 fputc ('\n', asm_out_file
);
5021 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
5022 a_attr
= a_attr
->dw_attr_next
)
5024 output_uleb128 (a_attr
->dw_attr
);
5026 fprintf (asm_out_file
, " (%s)",
5027 dwarf_attr_name (a_attr
->dw_attr
));
5029 fputc ('\n', asm_out_file
);
5030 output_value_format (&a_attr
->dw_attr_val
);
5033 fprintf (asm_out_file
, "\t%s\t0,0\n", ASM_BYTE_OP
);
5037 /* Output location description stack opcode's operands (if any). */
5040 output_loc_operands (loc
)
5041 register dw_loc_descr_ref loc
;
5043 register dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
5044 register dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
5046 switch (loc
->dw_loc_opc
)
5049 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
, val1
->v
.val_addr
);
5050 fputc ('\n', asm_out_file
);
5054 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_flag
);
5055 fputc ('\n', asm_out_file
);
5059 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, val1
->v
.val_int
);
5060 fputc ('\n', asm_out_file
);
5064 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, val1
->v
.val_int
);
5065 fputc ('\n', asm_out_file
);
5070 fputc ('\n', asm_out_file
);
5073 output_uleb128 (val1
->v
.val_unsigned
);
5074 fputc ('\n', asm_out_file
);
5077 output_sleb128 (val1
->v
.val_int
);
5078 fputc ('\n', asm_out_file
);
5081 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_int
);
5082 fputc ('\n', asm_out_file
);
5084 case DW_OP_plus_uconst
:
5085 output_uleb128 (val1
->v
.val_unsigned
);
5086 fputc ('\n', asm_out_file
);
5090 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, val1
->v
.val_int
);
5091 fputc ('\n', asm_out_file
);
5125 output_sleb128 (val1
->v
.val_int
);
5126 fputc ('\n', asm_out_file
);
5129 output_uleb128 (val1
->v
.val_unsigned
);
5130 fputc ('\n', asm_out_file
);
5133 output_sleb128 (val1
->v
.val_int
);
5134 fputc ('\n', asm_out_file
);
5137 output_uleb128 (val1
->v
.val_unsigned
);
5138 fputc ('\n', asm_out_file
);
5139 output_sleb128 (val2
->v
.val_int
);
5140 fputc ('\n', asm_out_file
);
5143 output_uleb128 (val1
->v
.val_unsigned
);
5144 fputc ('\n', asm_out_file
);
5146 case DW_OP_deref_size
:
5147 case DW_OP_xderef_size
:
5148 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_flag
);
5149 fputc ('\n', asm_out_file
);
5156 /* Compute the offset of a sibling. */
5158 static unsigned long
5159 sibling_offset (die
)
5162 unsigned long offset
;
5164 if (die
->die_child_last
== NULL
)
5165 offset
= die
->die_offset
+ size_of_die (die
);
5167 offset
= sibling_offset (die
->die_child_last
) + 1;
5172 /* Output the DIE and its attributes. Called recursively to generate
5173 the definitions of each child DIE. */
5177 register dw_die_ref die
;
5179 register dw_attr_ref a
;
5180 register dw_die_ref c
;
5181 register unsigned long ref_offset
;
5182 register unsigned long size
;
5183 register dw_loc_descr_ref loc
;
5186 output_uleb128 (die
->die_abbrev
);
5188 fprintf (asm_out_file
, " (DIE (0x%lx) %s)",
5189 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5191 fputc ('\n', asm_out_file
);
5193 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5195 switch (a
->dw_attr_val
.val_class
)
5197 case dw_val_class_addr
:
5198 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
,
5199 a
->dw_attr_val
.v
.val_addr
);
5202 case dw_val_class_loc
:
5203 size
= size_of_locs (a
->dw_attr_val
.v
.val_loc
);
5205 /* Output the block length for this list of location operations. */
5206 switch (constant_size (size
))
5209 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, size
);
5212 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, size
);
5219 fprintf (asm_out_file
, "\t%s %s",
5220 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5222 fputc ('\n', asm_out_file
);
5223 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
;
5224 loc
= loc
->dw_loc_next
)
5226 /* Output the opcode. */
5227 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, loc
->dw_loc_opc
);
5229 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
,
5230 dwarf_stack_op_name (loc
->dw_loc_opc
));
5232 fputc ('\n', asm_out_file
);
5234 /* Output the operand(s) (if any). */
5235 output_loc_operands (loc
);
5239 case dw_val_class_const
:
5240 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, a
->dw_attr_val
.v
.val_int
);
5243 case dw_val_class_unsigned_const
:
5244 switch (constant_size (a
->dw_attr_val
.v
.val_unsigned
))
5247 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
5248 a
->dw_attr_val
.v
.val_unsigned
);
5251 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
,
5252 a
->dw_attr_val
.v
.val_unsigned
);
5255 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
,
5256 a
->dw_attr_val
.v
.val_unsigned
);
5259 ASM_OUTPUT_DWARF_DATA8 (asm_out_file
,
5260 a
->dw_attr_val
.v
.val_long_long
.hi
,
5261 a
->dw_attr_val
.v
.val_long_long
.low
);
5268 case dw_val_class_long_long
:
5269 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 8);
5271 fprintf (asm_out_file
, "\t%s %s",
5272 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5274 fputc ('\n', asm_out_file
);
5275 ASM_OUTPUT_DWARF_DATA8 (asm_out_file
,
5276 a
->dw_attr_val
.v
.val_long_long
.hi
,
5277 a
->dw_attr_val
.v
.val_long_long
.low
);
5280 fprintf (asm_out_file
,
5281 "\t%s long long constant", ASM_COMMENT_START
);
5283 fputc ('\n', asm_out_file
);
5286 case dw_val_class_float
:
5287 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
5288 a
->dw_attr_val
.v
.val_float
.length
* 4);
5290 fprintf (asm_out_file
, "\t%s %s",
5291 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5293 fputc ('\n', asm_out_file
);
5294 for (i
= 0; i
< a
->dw_attr_val
.v
.val_float
.length
; ++i
)
5296 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
,
5297 a
->dw_attr_val
.v
.val_float
.array
[i
]);
5299 fprintf (asm_out_file
, "\t%s fp constant word %d",
5300 ASM_COMMENT_START
, i
);
5302 fputc ('\n', asm_out_file
);
5306 case dw_val_class_flag
:
5307 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, a
->dw_attr_val
.v
.val_flag
);
5310 case dw_val_class_die_ref
:
5311 if (a
->dw_attr_val
.v
.val_die_ref
!= NULL
)
5312 ref_offset
= a
->dw_attr_val
.v
.val_die_ref
->die_offset
;
5313 else if (a
->dw_attr
== DW_AT_sibling
)
5314 ref_offset
= sibling_offset(die
);
5318 ASM_OUTPUT_DWARF_DATA (asm_out_file
, ref_offset
);
5321 case dw_val_class_fde_ref
:
5324 ASM_GENERATE_INTERNAL_LABEL
5325 (l1
, FDE_AFTER_SIZE_LABEL
, a
->dw_attr_val
.v
.val_fde_index
* 2);
5326 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, l1
);
5327 fprintf (asm_out_file
, " - %d", DWARF_OFFSET_SIZE
);
5331 case dw_val_class_lbl_id
:
5332 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, a
->dw_attr_val
.v
.val_lbl_id
);
5335 case dw_val_class_section_offset
:
5336 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
,
5338 (a
->dw_attr_val
.v
.val_section
));
5341 case dw_val_class_str
:
5343 ASM_OUTPUT_DWARF_STRING (asm_out_file
, a
->dw_attr_val
.v
.val_str
);
5345 ASM_OUTPUT_ASCII (asm_out_file
,
5346 a
->dw_attr_val
.v
.val_str
,
5347 strlen (a
->dw_attr_val
.v
.val_str
) + 1);
5354 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
5355 && a
->dw_attr_val
.val_class
!= dw_val_class_long_long
5356 && a
->dw_attr_val
.val_class
!= dw_val_class_float
)
5359 fprintf (asm_out_file
, "\t%s %s",
5360 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5362 fputc ('\n', asm_out_file
);
5366 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5369 if (die
->die_child
!= NULL
)
5371 /* Add null byte to terminate sibling list. */
5372 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5374 fprintf (asm_out_file
, "\t%s end of children of DIE 0x%lx",
5375 ASM_COMMENT_START
, die
->die_offset
);
5377 fputc ('\n', asm_out_file
);
5381 /* Output the compilation unit that appears at the beginning of the
5382 .debug_info section, and precedes the DIE descriptions. */
5385 output_compilation_unit_header ()
5387 ASM_OUTPUT_DWARF_DATA (asm_out_file
, next_die_offset
- DWARF_OFFSET_SIZE
);
5389 fprintf (asm_out_file
, "\t%s Length of Compilation Unit Info.",
5392 fputc ('\n', asm_out_file
);
5393 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5395 fprintf (asm_out_file
, "\t%s DWARF version number", ASM_COMMENT_START
);
5397 fputc ('\n', asm_out_file
);
5398 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, stripattributes (ABBREV_SECTION
));
5400 fprintf (asm_out_file
, "\t%s Offset Into Abbrev. Section",
5403 fputc ('\n', asm_out_file
);
5404 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, PTR_SIZE
);
5406 fprintf (asm_out_file
, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START
);
5408 fputc ('\n', asm_out_file
);
5411 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5412 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5413 argument list, and maybe the scope. */
5416 dwarf2_name (decl
, scope
)
5420 return (*decl_printable_name
) (decl
, scope
? 1 : 0);
5423 /* Add a new entry to .debug_pubnames if appropriate. */
5426 add_pubname (decl
, die
)
5432 if (! TREE_PUBLIC (decl
))
5435 if (pubname_table_in_use
== pubname_table_allocated
)
5437 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
5438 pubname_table
= (pubname_ref
) xrealloc
5439 (pubname_table
, pubname_table_allocated
* sizeof (pubname_entry
));
5442 p
= &pubname_table
[pubname_table_in_use
++];
5445 p
->name
= xstrdup (dwarf2_name (decl
, 1));
5448 /* Output the public names table used to speed up access to externally
5449 visible names. For now, only generate entries for externally
5450 visible procedures. */
5455 register unsigned i
;
5456 register unsigned long pubnames_length
= size_of_pubnames ();
5458 ASM_OUTPUT_DWARF_DATA (asm_out_file
, pubnames_length
);
5461 fprintf (asm_out_file
, "\t%s Length of Public Names Info.",
5464 fputc ('\n', asm_out_file
);
5465 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5468 fprintf (asm_out_file
, "\t%s DWARF Version", ASM_COMMENT_START
);
5470 fputc ('\n', asm_out_file
);
5471 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, stripattributes (DEBUG_INFO_SECTION
));
5473 fprintf (asm_out_file
, "\t%s Offset of Compilation Unit Info.",
5476 fputc ('\n', asm_out_file
);
5477 ASM_OUTPUT_DWARF_DATA (asm_out_file
, next_die_offset
);
5479 fprintf (asm_out_file
, "\t%s Compilation Unit Length", ASM_COMMENT_START
);
5481 fputc ('\n', asm_out_file
);
5482 for (i
= 0; i
< pubname_table_in_use
; ++i
)
5484 register pubname_ref pub
= &pubname_table
[i
];
5486 ASM_OUTPUT_DWARF_DATA (asm_out_file
, pub
->die
->die_offset
);
5488 fprintf (asm_out_file
, "\t%s DIE offset", ASM_COMMENT_START
);
5490 fputc ('\n', asm_out_file
);
5494 ASM_OUTPUT_DWARF_STRING (asm_out_file
, pub
->name
);
5495 fprintf (asm_out_file
, "%s external name", ASM_COMMENT_START
);
5499 ASM_OUTPUT_ASCII (asm_out_file
, pub
->name
, strlen (pub
->name
) + 1);
5502 fputc ('\n', asm_out_file
);
5505 ASM_OUTPUT_DWARF_DATA (asm_out_file
, 0);
5506 fputc ('\n', asm_out_file
);
5509 /* Add a new entry to .debug_aranges if appropriate. */
5512 add_arange (decl
, die
)
5516 if (! DECL_SECTION_NAME (decl
))
5519 if (arange_table_in_use
== arange_table_allocated
)
5521 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
5523 = (arange_ref
) xrealloc (arange_table
,
5524 arange_table_allocated
* sizeof (dw_die_ref
));
5527 arange_table
[arange_table_in_use
++] = die
;
5530 /* Output the information that goes into the .debug_aranges table.
5531 Namely, define the beginning and ending address range of the
5532 text section generated for this compilation unit. */
5537 register unsigned i
;
5538 register unsigned long aranges_length
= size_of_aranges ();
5540 ASM_OUTPUT_DWARF_DATA (asm_out_file
, aranges_length
);
5542 fprintf (asm_out_file
, "\t%s Length of Address Ranges Info.",
5545 fputc ('\n', asm_out_file
);
5546 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5548 fprintf (asm_out_file
, "\t%s DWARF Version", ASM_COMMENT_START
);
5550 fputc ('\n', asm_out_file
);
5551 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, stripattributes (DEBUG_INFO_SECTION
));
5553 fprintf (asm_out_file
, "\t%s Offset of Compilation Unit Info.",
5556 fputc ('\n', asm_out_file
);
5557 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, PTR_SIZE
);
5559 fprintf (asm_out_file
, "\t%s Size of Address", ASM_COMMENT_START
);
5561 fputc ('\n', asm_out_file
);
5562 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5564 fprintf (asm_out_file
, "\t%s Size of Segment Descriptor",
5567 fputc ('\n', asm_out_file
);
5568 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 4);
5570 fprintf (asm_out_file
, ",0,0");
5573 fprintf (asm_out_file
, "\t%s Pad to %d byte boundary",
5574 ASM_COMMENT_START
, 2 * PTR_SIZE
);
5576 fputc ('\n', asm_out_file
);
5577 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, TEXT_SECTION
);
5579 fprintf (asm_out_file
, "\t%s Address", ASM_COMMENT_START
);
5581 fputc ('\n', asm_out_file
);
5582 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
, text_end_label
, TEXT_SECTION
);
5584 fprintf (asm_out_file
, "%s Length", ASM_COMMENT_START
);
5586 fputc ('\n', asm_out_file
);
5587 for (i
= 0; i
< arange_table_in_use
; ++i
)
5589 dw_die_ref a
= arange_table
[i
];
5591 if (a
->die_tag
== DW_TAG_subprogram
)
5592 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, get_AT_low_pc (a
));
5595 char *name
= get_AT_string (a
, DW_AT_MIPS_linkage_name
);
5597 name
= get_AT_string (a
, DW_AT_name
);
5599 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, name
);
5603 fprintf (asm_out_file
, "\t%s Address", ASM_COMMENT_START
);
5605 fputc ('\n', asm_out_file
);
5606 if (a
->die_tag
== DW_TAG_subprogram
)
5607 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
, get_AT_hi_pc (a
),
5610 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
,
5611 get_AT_unsigned (a
, DW_AT_byte_size
));
5614 fprintf (asm_out_file
, "%s Length", ASM_COMMENT_START
);
5616 fputc ('\n', asm_out_file
);
5619 /* Output the terminator words. */
5620 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
, 0);
5621 fputc ('\n', asm_out_file
);
5622 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
, 0);
5623 fputc ('\n', asm_out_file
);
5626 /* Output the source line number correspondence information. This
5627 information goes into the .debug_line section.
5629 If the format of this data changes, then the function size_of_line_info
5630 must also be adjusted the same way. */
5635 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5636 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5637 register unsigned opc
;
5638 register unsigned n_op_args
;
5639 register unsigned long ft_index
;
5640 register unsigned long lt_index
;
5641 register unsigned long current_line
;
5642 register long line_offset
;
5643 register long line_delta
;
5644 register unsigned long current_file
;
5645 register unsigned long function
;
5647 ASM_OUTPUT_DWARF_DATA (asm_out_file
, size_of_line_info ());
5649 fprintf (asm_out_file
, "\t%s Length of Source Line Info.",
5652 fputc ('\n', asm_out_file
);
5653 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5655 fprintf (asm_out_file
, "\t%s DWARF Version", ASM_COMMENT_START
);
5657 fputc ('\n', asm_out_file
);
5658 ASM_OUTPUT_DWARF_DATA (asm_out_file
, size_of_line_prolog ());
5660 fprintf (asm_out_file
, "\t%s Prolog Length", ASM_COMMENT_START
);
5662 fputc ('\n', asm_out_file
);
5663 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_LINE_MIN_INSTR_LENGTH
);
5665 fprintf (asm_out_file
, "\t%s Minimum Instruction Length",
5668 fputc ('\n', asm_out_file
);
5669 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_LINE_DEFAULT_IS_STMT_START
);
5671 fprintf (asm_out_file
, "\t%s Default is_stmt_start flag",
5674 fputc ('\n', asm_out_file
);
5675 fprintf (asm_out_file
, "\t%s\t%d", ASM_BYTE_OP
, DWARF_LINE_BASE
);
5677 fprintf (asm_out_file
, "\t%s Line Base Value (Special Opcodes)",
5680 fputc ('\n', asm_out_file
);
5681 fprintf (asm_out_file
, "\t%s\t%u", ASM_BYTE_OP
, DWARF_LINE_RANGE
);
5683 fprintf (asm_out_file
, "\t%s Line Range Value (Special Opcodes)",
5686 fputc ('\n', asm_out_file
);
5687 fprintf (asm_out_file
, "\t%s\t%u", ASM_BYTE_OP
, DWARF_LINE_OPCODE_BASE
);
5689 fprintf (asm_out_file
, "\t%s Special Opcode Base", ASM_COMMENT_START
);
5691 fputc ('\n', asm_out_file
);
5692 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; ++opc
)
5696 case DW_LNS_advance_pc
:
5697 case DW_LNS_advance_line
:
5698 case DW_LNS_set_file
:
5699 case DW_LNS_set_column
:
5700 case DW_LNS_fixed_advance_pc
:
5707 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, n_op_args
);
5709 fprintf (asm_out_file
, "\t%s opcode: 0x%x has %d args",
5710 ASM_COMMENT_START
, opc
, n_op_args
);
5711 fputc ('\n', asm_out_file
);
5715 fprintf (asm_out_file
, "%s Include Directory Table\n", ASM_COMMENT_START
);
5717 /* Include directory table is empty, at present */
5718 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5719 fputc ('\n', asm_out_file
);
5721 fprintf (asm_out_file
, "%s File Name Table\n", ASM_COMMENT_START
);
5723 for (ft_index
= 1; ft_index
< file_table_in_use
; ++ft_index
)
5727 ASM_OUTPUT_DWARF_STRING (asm_out_file
, file_table
[ft_index
]);
5728 fprintf (asm_out_file
, "%s File Entry: 0x%lx",
5729 ASM_COMMENT_START
, ft_index
);
5733 ASM_OUTPUT_ASCII (asm_out_file
,
5734 file_table
[ft_index
],
5735 strlen (file_table
[ft_index
]) + 1);
5738 fputc ('\n', asm_out_file
);
5740 /* Include directory index */
5742 fputc ('\n', asm_out_file
);
5744 /* Modification time */
5746 fputc ('\n', asm_out_file
);
5748 /* File length in bytes */
5750 fputc ('\n', asm_out_file
);
5753 /* Terminate the file name table */
5754 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5755 fputc ('\n', asm_out_file
);
5757 /* Set the address register to the first location in the text section */
5758 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5760 fprintf (asm_out_file
, "\t%s DW_LNE_set_address", ASM_COMMENT_START
);
5762 fputc ('\n', asm_out_file
);
5763 output_uleb128 (1 + PTR_SIZE
);
5764 fputc ('\n', asm_out_file
);
5765 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5766 fputc ('\n', asm_out_file
);
5767 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, TEXT_SECTION
);
5768 fputc ('\n', asm_out_file
);
5770 /* Generate the line number to PC correspondence table, encoded as
5771 a series of state machine operations. */
5774 strcpy (prev_line_label
, TEXT_SECTION
);
5775 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
5777 register dw_line_info_ref line_info
;
5779 /* Emit debug info for the address of the current line, choosing
5780 the encoding that uses the least amount of space. */
5781 /* ??? Unfortunately, we have little choice here currently, and must
5782 always use the most general form. Gcc does not know the address
5783 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5784 dwarf2 aware assemblers at this time, so we can't use any special
5785 pseudo ops that would allow the assembler to optimally encode this for
5786 us. Many ports do have length attributes which will give an upper
5787 bound on the address range. We could perhaps use length attributes
5788 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5789 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
5792 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5793 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
5795 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
5798 fputc ('\n', asm_out_file
);
5799 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
, prev_line_label
);
5800 fputc ('\n', asm_out_file
);
5804 /* This can handle any delta. This takes 4+PTR_SIZE bytes. */
5805 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5807 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
5809 fputc ('\n', asm_out_file
);
5810 output_uleb128 (1 + PTR_SIZE
);
5811 fputc ('\n', asm_out_file
);
5812 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5813 fputc ('\n', asm_out_file
);
5814 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
5815 fputc ('\n', asm_out_file
);
5817 strcpy (prev_line_label
, line_label
);
5819 /* Emit debug info for the source file of the current line, if
5820 different from the previous line. */
5821 line_info
= &line_info_table
[lt_index
];
5822 if (line_info
->dw_file_num
!= current_file
)
5824 current_file
= line_info
->dw_file_num
;
5825 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_set_file
);
5827 fprintf (asm_out_file
, "\t%s DW_LNS_set_file", ASM_COMMENT_START
);
5829 fputc ('\n', asm_out_file
);
5830 output_uleb128 (current_file
);
5832 fprintf (asm_out_file
, " (\"%s\")", file_table
[current_file
]);
5834 fputc ('\n', asm_out_file
);
5837 /* Emit debug info for the current line number, choosing the encoding
5838 that uses the least amount of space. */
5839 line_offset
= line_info
->dw_line_num
- current_line
;
5840 line_delta
= line_offset
- DWARF_LINE_BASE
;
5841 current_line
= line_info
->dw_line_num
;
5842 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
5844 /* This can handle deltas from -10 to 234, using the current
5845 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5847 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
5848 DWARF_LINE_OPCODE_BASE
+ line_delta
);
5850 fprintf (asm_out_file
,
5851 "\t%s line %ld", ASM_COMMENT_START
, current_line
);
5853 fputc ('\n', asm_out_file
);
5857 /* This can handle any delta. This takes at least 4 bytes, depending
5858 on the value being encoded. */
5859 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_advance_line
);
5861 fprintf (asm_out_file
, "\t%s advance to line %ld",
5862 ASM_COMMENT_START
, current_line
);
5864 fputc ('\n', asm_out_file
);
5865 output_sleb128 (line_offset
);
5866 fputc ('\n', asm_out_file
);
5867 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
5868 fputc ('\n', asm_out_file
);
5872 /* Emit debug info for the address of the end of the function. */
5875 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
5877 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
5880 fputc ('\n', asm_out_file
);
5881 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, text_end_label
, prev_line_label
);
5882 fputc ('\n', asm_out_file
);
5886 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5888 fprintf (asm_out_file
, "\t%s DW_LNE_set_address", ASM_COMMENT_START
);
5889 fputc ('\n', asm_out_file
);
5890 output_uleb128 (1 + PTR_SIZE
);
5891 fputc ('\n', asm_out_file
);
5892 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5893 fputc ('\n', asm_out_file
);
5894 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, text_end_label
);
5895 fputc ('\n', asm_out_file
);
5898 /* Output the marker for the end of the line number info. */
5899 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5901 fprintf (asm_out_file
, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START
);
5903 fputc ('\n', asm_out_file
);
5905 fputc ('\n', asm_out_file
);
5906 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_end_sequence
);
5907 fputc ('\n', asm_out_file
);
5912 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
; )
5914 register dw_separate_line_info_ref line_info
5915 = &separate_line_info_table
[lt_index
];
5917 /* Emit debug info for the address of the current line. If this is
5918 a new function, or the first line of a function, then we need
5919 to handle it differently. */
5920 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
5922 if (function
!= line_info
->function
)
5924 function
= line_info
->function
;
5926 /* Set the address register to the first line in the function */
5927 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5929 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
5932 fputc ('\n', asm_out_file
);
5933 output_uleb128 (1 + PTR_SIZE
);
5934 fputc ('\n', asm_out_file
);
5935 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5936 fputc ('\n', asm_out_file
);
5937 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
5938 fputc ('\n', asm_out_file
);
5942 /* ??? See the DW_LNS_advance_pc comment above. */
5945 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
5947 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
5950 fputc ('\n', asm_out_file
);
5951 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
,
5953 fputc ('\n', asm_out_file
);
5957 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5959 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
5961 fputc ('\n', asm_out_file
);
5962 output_uleb128 (1 + PTR_SIZE
);
5963 fputc ('\n', asm_out_file
);
5964 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5965 fputc ('\n', asm_out_file
);
5966 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
5967 fputc ('\n', asm_out_file
);
5970 strcpy (prev_line_label
, line_label
);
5972 /* Emit debug info for the source file of the current line, if
5973 different from the previous line. */
5974 if (line_info
->dw_file_num
!= current_file
)
5976 current_file
= line_info
->dw_file_num
;
5977 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_set_file
);
5979 fprintf (asm_out_file
, "\t%s DW_LNS_set_file", ASM_COMMENT_START
);
5981 fputc ('\n', asm_out_file
);
5982 output_uleb128 (current_file
);
5984 fprintf (asm_out_file
, " (\"%s\")", file_table
[current_file
]);
5986 fputc ('\n', asm_out_file
);
5989 /* Emit debug info for the current line number, choosing the encoding
5990 that uses the least amount of space. */
5991 if (line_info
->dw_line_num
!= current_line
)
5993 line_offset
= line_info
->dw_line_num
- current_line
;
5994 line_delta
= line_offset
- DWARF_LINE_BASE
;
5995 current_line
= line_info
->dw_line_num
;
5996 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
5998 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
5999 DWARF_LINE_OPCODE_BASE
+ line_delta
);
6001 fprintf (asm_out_file
,
6002 "\t%s line %ld", ASM_COMMENT_START
, current_line
);
6004 fputc ('\n', asm_out_file
);
6008 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_advance_line
);
6010 fprintf (asm_out_file
, "\t%s advance to line %ld",
6011 ASM_COMMENT_START
, current_line
);
6013 fputc ('\n', asm_out_file
);
6014 output_sleb128 (line_offset
);
6015 fputc ('\n', asm_out_file
);
6016 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
6017 fputc ('\n', asm_out_file
);
6023 /* If we're done with a function, end its sequence. */
6024 if (lt_index
== separate_line_info_table_in_use
6025 || separate_line_info_table
[lt_index
].function
!= function
)
6030 /* Emit debug info for the address of the end of the function. */
6031 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
6034 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
6036 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
6039 fputc ('\n', asm_out_file
);
6040 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
,
6042 fputc ('\n', asm_out_file
);
6046 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
6048 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
6050 fputc ('\n', asm_out_file
);
6051 output_uleb128 (1 + PTR_SIZE
);
6052 fputc ('\n', asm_out_file
);
6053 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
6054 fputc ('\n', asm_out_file
);
6055 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
6056 fputc ('\n', asm_out_file
);
6059 /* Output the marker for the end of this sequence. */
6060 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
6062 fprintf (asm_out_file
, "\t%s DW_LNE_end_sequence",
6065 fputc ('\n', asm_out_file
);
6067 fputc ('\n', asm_out_file
);
6068 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_end_sequence
);
6069 fputc ('\n', asm_out_file
);
6074 /* Given a pointer to a BLOCK node return non-zero if (and only if) the node
6075 in question represents the outermost pair of curly braces (i.e. the "body
6076 block") of a function or method.
6078 For any BLOCK node representing a "body block" of a function or method, the
6079 BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
6080 represents the outermost (function) scope for the function or method (i.e.
6081 the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
6082 *that* node in turn will point to the relevant FUNCTION_DECL node. */
6085 is_body_block (stmt
)
6088 if (TREE_CODE (stmt
) == BLOCK
)
6090 register tree parent
= BLOCK_SUPERCONTEXT (stmt
);
6092 if (TREE_CODE (parent
) == BLOCK
)
6094 register tree grandparent
= BLOCK_SUPERCONTEXT (parent
);
6096 if (TREE_CODE (grandparent
) == FUNCTION_DECL
)
6104 /* Given a pointer to a tree node for some base type, return a pointer to
6105 a DIE that describes the given type.
6107 This routine must only be called for GCC type nodes that correspond to
6108 Dwarf base (fundamental) types. */
6111 base_type_die (type
)
6114 register dw_die_ref base_type_result
;
6115 register char *type_name
;
6116 register enum dwarf_type encoding
;
6117 register tree name
= TYPE_NAME (type
);
6119 if (TREE_CODE (type
) == ERROR_MARK
6120 || TREE_CODE (type
) == VOID_TYPE
)
6123 if (TREE_CODE (name
) == TYPE_DECL
)
6124 name
= DECL_NAME (name
);
6125 type_name
= IDENTIFIER_POINTER (name
);
6127 switch (TREE_CODE (type
))
6130 /* Carefully distinguish the C character types, without messing
6131 up if the language is not C. Note that we check only for the names
6132 that contain spaces; other names might occur by coincidence in other
6134 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
6135 && (type
== char_type_node
6136 || ! strcmp (type_name
, "signed char")
6137 || ! strcmp (type_name
, "unsigned char"))))
6139 if (TREE_UNSIGNED (type
))
6140 encoding
= DW_ATE_unsigned
;
6142 encoding
= DW_ATE_signed
;
6145 /* else fall through */
6148 /* GNU Pascal/Ada CHAR type. Not used in C. */
6149 if (TREE_UNSIGNED (type
))
6150 encoding
= DW_ATE_unsigned_char
;
6152 encoding
= DW_ATE_signed_char
;
6156 encoding
= DW_ATE_float
;
6160 encoding
= DW_ATE_complex_float
;
6164 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6165 encoding
= DW_ATE_boolean
;
6169 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6172 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
);
6173 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
6174 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
6175 TYPE_PRECISION (type
) / BITS_PER_UNIT
);
6176 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
6178 return base_type_result
;
6181 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6182 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6183 a given type is generally the same as the given type, except that if the
6184 given type is a pointer or reference type, then the root type of the given
6185 type is the root type of the "basis" type for the pointer or reference
6186 type. (This definition of the "root" type is recursive.) Also, the root
6187 type of a `const' qualified type or a `volatile' qualified type is the
6188 root type of the given type without the qualifiers. */
6194 if (TREE_CODE (type
) == ERROR_MARK
)
6195 return error_mark_node
;
6197 switch (TREE_CODE (type
))
6200 return error_mark_node
;
6203 case REFERENCE_TYPE
:
6204 return type_main_variant (root_type (TREE_TYPE (type
)));
6207 return type_main_variant (type
);
6211 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6212 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6218 switch (TREE_CODE (type
))
6233 case QUAL_UNION_TYPE
:
6238 case REFERENCE_TYPE
:
6251 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6252 entry that chains various modifiers in front of the given type. */
6255 modified_type_die (type
, is_const_type
, is_volatile_type
, context_die
)
6257 register int is_const_type
;
6258 register int is_volatile_type
;
6259 register dw_die_ref context_die
;
6261 register enum tree_code code
= TREE_CODE (type
);
6262 register dw_die_ref mod_type_die
= NULL
;
6263 register dw_die_ref sub_die
= NULL
;
6264 register tree item_type
= NULL
;
6266 if (code
!= ERROR_MARK
)
6268 type
= build_type_variant (type
, is_const_type
, is_volatile_type
);
6270 mod_type_die
= lookup_type_die (type
);
6272 return mod_type_die
;
6274 /* Handle C typedef types. */
6275 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
6276 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
6278 tree dtype
= TREE_TYPE (TYPE_NAME (type
));
6281 /* For a named type, use the typedef. */
6282 gen_type_die (type
, context_die
);
6283 mod_type_die
= lookup_type_die (type
);
6286 else if (is_const_type
< TYPE_READONLY (dtype
)
6287 || is_volatile_type
< TYPE_VOLATILE (dtype
))
6288 /* cv-unqualified version of named type. Just use the unnamed
6289 type to which it refers. */
6291 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)),
6292 is_const_type
, is_volatile_type
,
6294 /* Else cv-qualified version of named type; fall through. */
6299 else if (is_const_type
)
6301 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
);
6302 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
6304 else if (is_volatile_type
)
6306 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
);
6307 sub_die
= modified_type_die (type
, 0, 0, context_die
);
6309 else if (code
== POINTER_TYPE
)
6311 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
);
6312 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
6314 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
6316 item_type
= TREE_TYPE (type
);
6318 else if (code
== REFERENCE_TYPE
)
6320 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
);
6321 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
6323 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
6325 item_type
= TREE_TYPE (type
);
6327 else if (is_base_type (type
))
6328 mod_type_die
= base_type_die (type
);
6331 gen_type_die (type
, context_die
);
6333 /* We have to get the type_main_variant here (and pass that to the
6334 `lookup_type_die' routine) because the ..._TYPE node we have
6335 might simply be a *copy* of some original type node (where the
6336 copy was created to help us keep track of typedef names) and
6337 that copy might have a different TYPE_UID from the original
6339 mod_type_die
= lookup_type_die (type_main_variant (type
));
6340 if (mod_type_die
== NULL
)
6345 equate_type_number_to_die (type
, mod_type_die
);
6347 /* We must do this after the equate_type_number_to_die call, in case
6348 this is a recursive type. This ensures that the modified_type_die
6349 recursion will terminate even if the type is recursive. Recursive
6350 types are possible in Ada. */
6351 sub_die
= modified_type_die (item_type
,
6352 TYPE_READONLY (item_type
),
6353 TYPE_VOLATILE (item_type
),
6356 if (sub_die
!= NULL
)
6357 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
6359 return mod_type_die
;
6362 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6363 an enumerated type. */
6369 return TREE_CODE (type
) == ENUMERAL_TYPE
;
6372 /* Return a location descriptor that designates a machine register. */
6374 static dw_loc_descr_ref
6375 reg_loc_descriptor (rtl
)
6378 register dw_loc_descr_ref loc_result
= NULL
;
6379 register unsigned reg
= reg_number (rtl
);
6382 loc_result
= new_loc_descr (DW_OP_reg0
+ reg
, 0, 0);
6384 loc_result
= new_loc_descr (DW_OP_regx
, reg
, 0);
6389 /* Return a location descriptor that designates a base+offset location. */
6391 static dw_loc_descr_ref
6392 based_loc_descr (reg
, offset
)
6396 register dw_loc_descr_ref loc_result
;
6397 /* For the "frame base", we use the frame pointer or stack pointer
6398 registers, since the RTL for local variables is relative to one of
6400 register unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
6401 ? HARD_FRAME_POINTER_REGNUM
6402 : STACK_POINTER_REGNUM
);
6405 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
6407 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
6409 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
6414 /* Return true if this RTL expression describes a base+offset calculation. */
6420 return (GET_CODE (rtl
) == PLUS
6421 && ((GET_CODE (XEXP (rtl
, 0)) == REG
6422 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
6425 /* The following routine converts the RTL for a variable or parameter
6426 (resident in memory) into an equivalent Dwarf representation of a
6427 mechanism for getting the address of that same variable onto the top of a
6428 hypothetical "address evaluation" stack.
6430 When creating memory location descriptors, we are effectively transforming
6431 the RTL for a memory-resident object into its Dwarf postfix expression
6432 equivalent. This routine recursively descends an RTL tree, turning
6433 it into Dwarf postfix code as it goes. */
6435 static dw_loc_descr_ref
6436 mem_loc_descriptor (rtl
)
6439 dw_loc_descr_ref mem_loc_result
= NULL
;
6440 /* Note that for a dynamically sized array, the location we will generate a
6441 description of here will be the lowest numbered location which is
6442 actually within the array. That's *not* necessarily the same as the
6443 zeroth element of the array. */
6445 switch (GET_CODE (rtl
))
6448 /* The case of a subreg may arise when we have a local (register)
6449 variable or a formal (register) parameter which doesn't quite fill
6450 up an entire register. For now, just assume that it is
6451 legitimate to make the Dwarf info refer to the whole register which
6452 contains the given subreg. */
6453 rtl
= XEXP (rtl
, 0);
6455 /* ... fall through ... */
6458 /* Whenever a register number forms a part of the description of the
6459 method for calculating the (dynamic) address of a memory resident
6460 object, DWARF rules require the register number be referred to as
6461 a "base register". This distinction is not based in any way upon
6462 what category of register the hardware believes the given register
6463 belongs to. This is strictly DWARF terminology we're dealing with
6464 here. Note that in cases where the location of a memory-resident
6465 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6466 OP_CONST (0)) the actual DWARF location descriptor that we generate
6467 may just be OP_BASEREG (basereg). This may look deceptively like
6468 the object in question was allocated to a register (rather than in
6469 memory) so DWARF consumers need to be aware of the subtle
6470 distinction between OP_REG and OP_BASEREG. */
6471 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
6475 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0));
6476 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
6481 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
6482 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
6483 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= addr_to_string (rtl
);
6487 if (is_based_loc (rtl
))
6488 mem_loc_result
= based_loc_descr (reg_number (XEXP (rtl
, 0)),
6489 INTVAL (XEXP (rtl
, 1)));
6492 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 0)));
6493 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 1)));
6494 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_plus
, 0, 0));
6499 /* If a pseudo-reg is optimized away, it is possible for it to
6500 be replaced with a MEM containing a multiply. */
6501 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 0)));
6502 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 1)));
6503 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
6507 mem_loc_result
= new_loc_descr (DW_OP_constu
, INTVAL (rtl
), 0);
6514 return mem_loc_result
;
6517 /* Return a descriptor that describes the concatenation of two locations.
6518 This is typically a complex variable. */
6520 static dw_loc_descr_ref
6521 concat_loc_descriptor (x0
, x1
)
6522 register rtx x0
, x1
;
6524 dw_loc_descr_ref cc_loc_result
= NULL
;
6526 if (!is_pseudo_reg (x0
)
6527 && (GET_CODE (x0
) != MEM
|| !is_pseudo_reg (XEXP (x0
, 0))))
6528 add_loc_descr (&cc_loc_result
, loc_descriptor (x0
));
6529 add_loc_descr (&cc_loc_result
,
6530 new_loc_descr (DW_OP_piece
, GET_MODE_SIZE (GET_MODE (x0
)), 0));
6532 if (!is_pseudo_reg (x1
)
6533 && (GET_CODE (x1
) != MEM
|| !is_pseudo_reg (XEXP (x1
, 0))))
6534 add_loc_descr (&cc_loc_result
, loc_descriptor (x1
));
6535 add_loc_descr (&cc_loc_result
,
6536 new_loc_descr (DW_OP_piece
, GET_MODE_SIZE (GET_MODE (x1
)), 0));
6538 return cc_loc_result
;
6541 /* Output a proper Dwarf location descriptor for a variable or parameter
6542 which is either allocated in a register or in a memory location. For a
6543 register, we just generate an OP_REG and the register number. For a
6544 memory location we provide a Dwarf postfix expression describing how to
6545 generate the (dynamic) address of the object onto the address stack. */
6547 static dw_loc_descr_ref
6548 loc_descriptor (rtl
)
6551 dw_loc_descr_ref loc_result
= NULL
;
6552 switch (GET_CODE (rtl
))
6555 /* The case of a subreg may arise when we have a local (register)
6556 variable or a formal (register) parameter which doesn't quite fill
6557 up an entire register. For now, just assume that it is
6558 legitimate to make the Dwarf info refer to the whole register which
6559 contains the given subreg. */
6560 rtl
= XEXP (rtl
, 0);
6562 /* ... fall through ... */
6565 loc_result
= reg_loc_descriptor (rtl
);
6569 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0));
6573 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
6583 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
6584 which is not less than the value itself. */
6586 static inline unsigned
6587 ceiling (value
, boundary
)
6588 register unsigned value
;
6589 register unsigned boundary
;
6591 return (((value
+ boundary
- 1) / boundary
) * boundary
);
6594 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6595 pointer to the declared type for the relevant field variable, or return
6596 `integer_type_node' if the given node turns out to be an
6605 if (TREE_CODE (decl
) == ERROR_MARK
)
6606 return integer_type_node
;
6608 type
= DECL_BIT_FIELD_TYPE (decl
);
6609 if (type
== NULL_TREE
)
6610 type
= TREE_TYPE (decl
);
6615 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6616 node, return the alignment in bits for the type, or else return
6617 BITS_PER_WORD if the node actually turns out to be an
6620 static inline unsigned
6621 simple_type_align_in_bits (type
)
6624 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
6627 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6628 node, return the size in bits for the type if it is a constant, or else
6629 return the alignment for the type if the type's size is not constant, or
6630 else return BITS_PER_WORD if the type actually turns out to be an
6633 static inline unsigned
6634 simple_type_size_in_bits (type
)
6637 if (TREE_CODE (type
) == ERROR_MARK
)
6638 return BITS_PER_WORD
;
6641 register tree type_size_tree
= TYPE_SIZE (type
);
6643 if (TREE_CODE (type_size_tree
) != INTEGER_CST
)
6644 return TYPE_ALIGN (type
);
6646 return (unsigned) TREE_INT_CST_LOW (type_size_tree
);
6650 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6651 return the byte offset of the lowest addressed byte of the "containing
6652 object" for the given FIELD_DECL, or return 0 if we are unable to
6653 determine what that offset is, either because the argument turns out to
6654 be a pointer to an ERROR_MARK node, or because the offset is actually
6655 variable. (We can't handle the latter case just yet). */
6658 field_byte_offset (decl
)
6661 register unsigned type_align_in_bytes
;
6662 register unsigned type_align_in_bits
;
6663 register unsigned type_size_in_bits
;
6664 register unsigned object_offset_in_align_units
;
6665 register unsigned object_offset_in_bits
;
6666 register unsigned object_offset_in_bytes
;
6668 register tree bitpos_tree
;
6669 register tree field_size_tree
;
6670 register unsigned bitpos_int
;
6671 register unsigned deepest_bitpos
;
6672 register unsigned field_size_in_bits
;
6674 if (TREE_CODE (decl
) == ERROR_MARK
)
6677 if (TREE_CODE (decl
) != FIELD_DECL
)
6680 type
= field_type (decl
);
6682 bitpos_tree
= DECL_FIELD_BITPOS (decl
);
6683 field_size_tree
= DECL_SIZE (decl
);
6685 /* We cannot yet cope with fields whose positions or sizes are variable, so
6686 for now, when we see such things, we simply return 0. Someday, we may
6687 be able to handle such cases, but it will be damn difficult. */
6688 if (TREE_CODE (bitpos_tree
) != INTEGER_CST
)
6690 bitpos_int
= (unsigned) TREE_INT_CST_LOW (bitpos_tree
);
6692 if (TREE_CODE (field_size_tree
) != INTEGER_CST
)
6695 field_size_in_bits
= (unsigned) TREE_INT_CST_LOW (field_size_tree
);
6696 type_size_in_bits
= simple_type_size_in_bits (type
);
6697 type_align_in_bits
= simple_type_align_in_bits (type
);
6698 type_align_in_bytes
= type_align_in_bits
/ BITS_PER_UNIT
;
6700 /* Note that the GCC front-end doesn't make any attempt to keep track of
6701 the starting bit offset (relative to the start of the containing
6702 structure type) of the hypothetical "containing object" for a bit-
6703 field. Thus, when computing the byte offset value for the start of the
6704 "containing object" of a bit-field, we must deduce this information on
6705 our own. This can be rather tricky to do in some cases. For example,
6706 handling the following structure type definition when compiling for an
6707 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6710 struct S { int field1; long long field2:31; };
6712 Fortunately, there is a simple rule-of-thumb which can be
6713 used in such cases. When compiling for an i386/i486, GCC will allocate
6714 8 bytes for the structure shown above. It decides to do this based upon
6715 one simple rule for bit-field allocation. Quite simply, GCC allocates
6716 each "containing object" for each bit-field at the first (i.e. lowest
6717 addressed) legitimate alignment boundary (based upon the required
6718 minimum alignment for the declared type of the field) which it can
6719 possibly use, subject to the condition that there is still enough
6720 available space remaining in the containing object (when allocated at
6721 the selected point) to fully accommodate all of the bits of the
6722 bit-field itself. This simple rule makes it obvious why GCC allocates
6723 8 bytes for each object of the structure type shown above. When looking
6724 for a place to allocate the "containing object" for `field2', the
6725 compiler simply tries to allocate a 64-bit "containing object" at each
6726 successive 32-bit boundary (starting at zero) until it finds a place to
6727 allocate that 64- bit field such that at least 31 contiguous (and
6728 previously unallocated) bits remain within that selected 64 bit field.
6729 (As it turns out, for the example above, the compiler finds that it is
6730 OK to allocate the "containing object" 64-bit field at bit-offset zero
6731 within the structure type.) Here we attempt to work backwards from the
6732 limited set of facts we're given, and we try to deduce from those facts,
6733 where GCC must have believed that the containing object started (within
6734 the structure type). The value we deduce is then used (by the callers of
6735 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6736 for fields (both bit-fields and, in the case of DW_AT_location, regular
6739 /* Figure out the bit-distance from the start of the structure to the
6740 "deepest" bit of the bit-field. */
6741 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
6743 /* This is the tricky part. Use some fancy footwork to deduce where the
6744 lowest addressed bit of the containing object must be. */
6745 object_offset_in_bits
6746 = ceiling (deepest_bitpos
, type_align_in_bits
) - type_size_in_bits
;
6748 /* Compute the offset of the containing object in "alignment units". */
6749 object_offset_in_align_units
= object_offset_in_bits
/ type_align_in_bits
;
6751 /* Compute the offset of the containing object in bytes. */
6752 object_offset_in_bytes
= object_offset_in_align_units
* type_align_in_bytes
;
6754 return object_offset_in_bytes
;
6757 /* The following routines define various Dwarf attributes and any data
6758 associated with them. */
6760 /* Add a location description attribute value to a DIE.
6762 This emits location attributes suitable for whole variables and
6763 whole parameters. Note that the location attributes for struct fields are
6764 generated by the routine `data_member_location_attribute' below. */
6767 add_AT_location_description (die
, attr_kind
, rtl
)
6769 enum dwarf_attribute attr_kind
;
6772 /* Handle a special case. If we are about to output a location descriptor
6773 for a variable or parameter which has been optimized out of existence,
6774 don't do that. A variable which has been optimized out
6775 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6776 Currently, in some rare cases, variables can have DECL_RTL values which
6777 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6778 elsewhere in the compiler. We treat such cases as if the variable(s) in
6779 question had been optimized out of existence. */
6781 if (is_pseudo_reg (rtl
)
6782 || (GET_CODE (rtl
) == MEM
6783 && is_pseudo_reg (XEXP (rtl
, 0)))
6784 || (GET_CODE (rtl
) == CONCAT
6785 && is_pseudo_reg (XEXP (rtl
, 0))
6786 && is_pseudo_reg (XEXP (rtl
, 1))))
6789 add_AT_loc (die
, attr_kind
, loc_descriptor (rtl
));
6792 /* Attach the specialized form of location attribute used for data
6793 members of struct and union types. In the special case of a
6794 FIELD_DECL node which represents a bit-field, the "offset" part
6795 of this special location descriptor must indicate the distance
6796 in bytes from the lowest-addressed byte of the containing struct
6797 or union type to the lowest-addressed byte of the "containing
6798 object" for the bit-field. (See the `field_byte_offset' function
6799 above).. For any given bit-field, the "containing object" is a
6800 hypothetical object (of some integral or enum type) within which
6801 the given bit-field lives. The type of this hypothetical
6802 "containing object" is always the same as the declared type of
6803 the individual bit-field itself (for GCC anyway... the DWARF
6804 spec doesn't actually mandate this). Note that it is the size
6805 (in bytes) of the hypothetical "containing object" which will
6806 be given in the DW_AT_byte_size attribute for this bit-field.
6807 (See the `byte_size_attribute' function below.) It is also used
6808 when calculating the value of the DW_AT_bit_offset attribute.
6809 (See the `bit_offset_attribute' function below). */
6812 add_data_member_location_attribute (die
, decl
)
6813 register dw_die_ref die
;
6816 register unsigned long offset
;
6817 register dw_loc_descr_ref loc_descr
;
6818 register enum dwarf_location_atom op
;
6820 if (TREE_CODE (decl
) == TREE_VEC
)
6821 offset
= TREE_INT_CST_LOW (BINFO_OFFSET (decl
));
6823 offset
= field_byte_offset (decl
);
6825 /* The DWARF2 standard says that we should assume that the structure address
6826 is already on the stack, so we can specify a structure field address
6827 by using DW_OP_plus_uconst. */
6829 #ifdef MIPS_DEBUGGING_INFO
6830 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6831 correctly. It works only if we leave the offset on the stack. */
6834 op
= DW_OP_plus_uconst
;
6837 loc_descr
= new_loc_descr (op
, offset
, 0);
6838 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
6841 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6842 does not have a "location" either in memory or in a register. These
6843 things can arise in GNU C when a constant is passed as an actual parameter
6844 to an inlined function. They can also arise in C++ where declared
6845 constants do not necessarily get memory "homes". */
6848 add_const_value_attribute (die
, rtl
)
6849 register dw_die_ref die
;
6852 switch (GET_CODE (rtl
))
6855 /* Note that a CONST_INT rtx could represent either an integer or a
6856 floating-point constant. A CONST_INT is used whenever the constant
6857 will fit into a single word. In all such cases, the original mode
6858 of the constant value is wiped out, and the CONST_INT rtx is
6859 assigned VOIDmode. */
6860 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned) INTVAL (rtl
));
6864 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6865 floating-point constant. A CONST_DOUBLE is used whenever the
6866 constant requires more than one word in order to be adequately
6867 represented. We output CONST_DOUBLEs as blocks. */
6869 register enum machine_mode mode
= GET_MODE (rtl
);
6871 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
6873 register unsigned length
= GET_MODE_SIZE (mode
) / sizeof (long);
6877 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
6881 REAL_VALUE_TO_TARGET_SINGLE (rv
, array
[0]);
6885 REAL_VALUE_TO_TARGET_DOUBLE (rv
, array
);
6890 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv
, array
);
6897 add_AT_float (die
, DW_AT_const_value
, length
, array
);
6900 add_AT_long_long (die
, DW_AT_const_value
,
6901 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
6906 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
6912 add_AT_addr (die
, DW_AT_const_value
, addr_to_string (rtl
));
6916 /* In cases where an inlined instance of an inline function is passed
6917 the address of an `auto' variable (which is local to the caller) we
6918 can get a situation where the DECL_RTL of the artificial local
6919 variable (for the inlining) which acts as a stand-in for the
6920 corresponding formal parameter (of the inline function) will look
6921 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6922 exactly a compile-time constant expression, but it isn't the address
6923 of the (artificial) local variable either. Rather, it represents the
6924 *value* which the artificial local variable always has during its
6925 lifetime. We currently have no way to represent such quasi-constant
6926 values in Dwarf, so for now we just punt and generate nothing. */
6930 /* No other kinds of rtx should be possible here. */
6936 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6937 data attribute for a variable or a parameter. We generate the
6938 DW_AT_const_value attribute only in those cases where the given variable
6939 or parameter does not have a true "location" either in memory or in a
6940 register. This can happen (for example) when a constant is passed as an
6941 actual argument in a call to an inline function. (It's possible that
6942 these things can crop up in other ways also.) Note that one type of
6943 constant value which can be passed into an inlined function is a constant
6944 pointer. This can happen for example if an actual argument in an inlined
6945 function call evaluates to a compile-time constant address. */
6948 add_location_or_const_value_attribute (die
, decl
)
6949 register dw_die_ref die
;
6953 register tree declared_type
;
6954 register tree passed_type
;
6956 if (TREE_CODE (decl
) == ERROR_MARK
)
6959 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
)
6962 /* Here we have to decide where we are going to say the parameter "lives"
6963 (as far as the debugger is concerned). We only have a couple of
6964 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6966 DECL_RTL normally indicates where the parameter lives during most of the
6967 activation of the function. If optimization is enabled however, this
6968 could be either NULL or else a pseudo-reg. Both of those cases indicate
6969 that the parameter doesn't really live anywhere (as far as the code
6970 generation parts of GCC are concerned) during most of the function's
6971 activation. That will happen (for example) if the parameter is never
6972 referenced within the function.
6974 We could just generate a location descriptor here for all non-NULL
6975 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6976 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6977 where DECL_RTL is NULL or is a pseudo-reg.
6979 Note however that we can only get away with using DECL_INCOMING_RTL as
6980 a backup substitute for DECL_RTL in certain limited cases. In cases
6981 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6982 we can be sure that the parameter was passed using the same type as it is
6983 declared to have within the function, and that its DECL_INCOMING_RTL
6984 points us to a place where a value of that type is passed.
6986 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6987 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6988 because in these cases DECL_INCOMING_RTL points us to a value of some
6989 type which is *different* from the type of the parameter itself. Thus,
6990 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6991 such cases, the debugger would end up (for example) trying to fetch a
6992 `float' from a place which actually contains the first part of a
6993 `double'. That would lead to really incorrect and confusing
6994 output at debug-time.
6996 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6997 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6998 are a couple of exceptions however. On little-endian machines we can
6999 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
7000 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
7001 an integral type that is smaller than TREE_TYPE (decl). These cases arise
7002 when (on a little-endian machine) a non-prototyped function has a
7003 parameter declared to be of type `short' or `char'. In such cases,
7004 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
7005 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
7006 passed `int' value. If the debugger then uses that address to fetch
7007 a `short' or a `char' (on a little-endian machine) the result will be
7008 the correct data, so we allow for such exceptional cases below.
7010 Note that our goal here is to describe the place where the given formal
7011 parameter lives during most of the function's activation (i.e. between
7012 the end of the prologue and the start of the epilogue). We'll do that
7013 as best as we can. Note however that if the given formal parameter is
7014 modified sometime during the execution of the function, then a stack
7015 backtrace (at debug-time) will show the function as having been
7016 called with the *new* value rather than the value which was
7017 originally passed in. This happens rarely enough that it is not
7018 a major problem, but it *is* a problem, and I'd like to fix it.
7020 A future version of dwarf2out.c may generate two additional
7021 attributes for any given DW_TAG_formal_parameter DIE which will
7022 describe the "passed type" and the "passed location" for the
7023 given formal parameter in addition to the attributes we now
7024 generate to indicate the "declared type" and the "active
7025 location" for each parameter. This additional set of attributes
7026 could be used by debuggers for stack backtraces. Separately, note
7027 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
7028 NULL also. This happens (for example) for inlined-instances of
7029 inline function formal parameters which are never referenced.
7030 This really shouldn't be happening. All PARM_DECL nodes should
7031 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
7032 doesn't currently generate these values for inlined instances of
7033 inline function parameters, so when we see such cases, we are
7034 just out-of-luck for the time being (until integrate.c
7037 /* Use DECL_RTL as the "location" unless we find something better. */
7038 rtl
= DECL_RTL (decl
);
7040 if (TREE_CODE (decl
) == PARM_DECL
)
7042 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
7044 declared_type
= type_main_variant (TREE_TYPE (decl
));
7045 passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
7047 /* This decl represents a formal parameter which was optimized out.
7048 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
7049 all* cases where (rtl == NULL_RTX) just below. */
7050 if (declared_type
== passed_type
)
7051 rtl
= DECL_INCOMING_RTL (decl
);
7052 else if (! BYTES_BIG_ENDIAN
7053 && TREE_CODE (declared_type
) == INTEGER_TYPE
7054 && TYPE_SIZE (declared_type
) <= TYPE_SIZE (passed_type
))
7055 rtl
= DECL_INCOMING_RTL (decl
);
7059 if (rtl
== NULL_RTX
)
7062 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
7063 #ifdef LEAF_REG_REMAP
7065 leaf_renumber_regs_insn (rtl
);
7068 switch (GET_CODE (rtl
))
7071 /* The address of a variable that was optimized away; don't emit
7082 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7083 add_const_value_attribute (die
, rtl
);
7090 add_AT_location_description (die
, DW_AT_location
, rtl
);
7098 /* Generate an DW_AT_name attribute given some string value to be included as
7099 the value of the attribute. */
7102 add_name_attribute (die
, name_string
)
7103 register dw_die_ref die
;
7104 register char *name_string
;
7106 if (name_string
!= NULL
&& *name_string
!= 0)
7107 add_AT_string (die
, DW_AT_name
, name_string
);
7110 /* Given a tree node describing an array bound (either lower or upper) output
7111 a representation for that bound. */
7114 add_bound_info (subrange_die
, bound_attr
, bound
)
7115 register dw_die_ref subrange_die
;
7116 register enum dwarf_attribute bound_attr
;
7117 register tree bound
;
7119 register unsigned bound_value
= 0;
7121 /* If this is an Ada unconstrained array type, then don't emit any debug
7122 info because the array bounds are unknown. They are parameterized when
7123 the type is instantiated. */
7124 if (contains_placeholder_p (bound
))
7127 switch (TREE_CODE (bound
))
7132 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7134 bound_value
= TREE_INT_CST_LOW (bound
);
7135 if (bound_attr
== DW_AT_lower_bound
7136 && ((is_c_family () && bound_value
== 0)
7137 || (is_fortran () && bound_value
== 1)))
7138 /* use the default */;
7140 add_AT_unsigned (subrange_die
, bound_attr
, bound_value
);
7145 case NON_LVALUE_EXPR
:
7146 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
7150 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7151 access the upper bound values may be bogus. If they refer to a
7152 register, they may only describe how to get at these values at the
7153 points in the generated code right after they have just been
7154 computed. Worse yet, in the typical case, the upper bound values
7155 will not even *be* computed in the optimized code (though the
7156 number of elements will), so these SAVE_EXPRs are entirely
7157 bogus. In order to compensate for this fact, we check here to see
7158 if optimization is enabled, and if so, we don't add an attribute
7159 for the (unknown and unknowable) upper bound. This should not
7160 cause too much trouble for existing (stupid?) debuggers because
7161 they have to deal with empty upper bounds location descriptions
7162 anyway in order to be able to deal with incomplete array types.
7163 Of course an intelligent debugger (GDB?) should be able to
7164 comprehend that a missing upper bound specification in a array
7165 type used for a storage class `auto' local array variable
7166 indicates that the upper bound is both unknown (at compile- time)
7167 and unknowable (at run-time) due to optimization.
7169 We assume that a MEM rtx is safe because gcc wouldn't put the
7170 value there unless it was going to be used repeatedly in the
7171 function, i.e. for cleanups. */
7172 if (! optimize
|| GET_CODE (SAVE_EXPR_RTL (bound
)) == MEM
)
7174 register dw_die_ref ctx
= lookup_decl_die (current_function_decl
);
7175 register dw_die_ref decl_die
= new_die (DW_TAG_variable
, ctx
);
7176 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
7177 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
7178 add_AT_location_description (decl_die
, DW_AT_location
,
7179 SAVE_EXPR_RTL (bound
));
7180 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
7183 /* Else leave out the attribute. */
7189 /* ??? These types of bounds can be created by the Ada front end,
7190 and it isn't clear how to emit debug info for them. */
7198 /* Note that the block of subscript information for an array type also
7199 includes information about the element type of type given array type. */
7202 add_subscript_info (type_die
, type
)
7203 register dw_die_ref type_die
;
7206 #ifndef MIPS_DEBUGGING_INFO
7207 register unsigned dimension_number
;
7209 register tree lower
, upper
;
7210 register dw_die_ref subrange_die
;
7212 /* The GNU compilers represent multidimensional array types as sequences of
7213 one dimensional array types whose element types are themselves array
7214 types. Here we squish that down, so that each multidimensional array
7215 type gets only one array_type DIE in the Dwarf debugging info. The draft
7216 Dwarf specification say that we are allowed to do this kind of
7217 compression in C (because there is no difference between an array or
7218 arrays and a multidimensional array in C) but for other source languages
7219 (e.g. Ada) we probably shouldn't do this. */
7221 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7222 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7223 We work around this by disabling this feature. See also
7224 gen_array_type_die. */
7225 #ifndef MIPS_DEBUGGING_INFO
7226 for (dimension_number
= 0;
7227 TREE_CODE (type
) == ARRAY_TYPE
;
7228 type
= TREE_TYPE (type
), dimension_number
++)
7231 register tree domain
= TYPE_DOMAIN (type
);
7233 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7234 and (in GNU C only) variable bounds. Handle all three forms
7236 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
);
7239 /* We have an array type with specified bounds. */
7240 lower
= TYPE_MIN_VALUE (domain
);
7241 upper
= TYPE_MAX_VALUE (domain
);
7243 /* define the index type. */
7244 if (TREE_TYPE (domain
))
7246 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7247 TREE_TYPE field. We can't emit debug info for this
7248 because it is an unnamed integral type. */
7249 if (TREE_CODE (domain
) == INTEGER_TYPE
7250 && TYPE_NAME (domain
) == NULL_TREE
7251 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
7252 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
7255 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
7259 /* ??? If upper is NULL, the array has unspecified length,
7260 but it does have a lower bound. This happens with Fortran
7262 Since the debugger is definitely going to need to know N
7263 to produce useful results, go ahead and output the lower
7264 bound solo, and hope the debugger can cope. */
7266 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
7268 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
7271 /* We have an array type with an unspecified length. The DWARF-2
7272 spec does not say how to handle this; let's just leave out the
7277 #ifndef MIPS_DEBUGGING_INFO
7283 add_byte_size_attribute (die
, tree_node
)
7285 register tree tree_node
;
7287 register unsigned size
;
7289 switch (TREE_CODE (tree_node
))
7297 case QUAL_UNION_TYPE
:
7298 size
= int_size_in_bytes (tree_node
);
7301 /* For a data member of a struct or union, the DW_AT_byte_size is
7302 generally given as the number of bytes normally allocated for an
7303 object of the *declared* type of the member itself. This is true
7304 even for bit-fields. */
7305 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
7311 /* Note that `size' might be -1 when we get to this point. If it is, that
7312 indicates that the byte size of the entity in question is variable. We
7313 have no good way of expressing this fact in Dwarf at the present time,
7314 so just let the -1 pass on through. */
7316 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
7319 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7320 which specifies the distance in bits from the highest order bit of the
7321 "containing object" for the bit-field to the highest order bit of the
7324 For any given bit-field, the "containing object" is a hypothetical
7325 object (of some integral or enum type) within which the given bit-field
7326 lives. The type of this hypothetical "containing object" is always the
7327 same as the declared type of the individual bit-field itself. The
7328 determination of the exact location of the "containing object" for a
7329 bit-field is rather complicated. It's handled by the
7330 `field_byte_offset' function (above).
7332 Note that it is the size (in bytes) of the hypothetical "containing object"
7333 which will be given in the DW_AT_byte_size attribute for this bit-field.
7334 (See `byte_size_attribute' above). */
7337 add_bit_offset_attribute (die
, decl
)
7338 register dw_die_ref die
;
7341 register unsigned object_offset_in_bytes
= field_byte_offset (decl
);
7342 register tree type
= DECL_BIT_FIELD_TYPE (decl
);
7343 register tree bitpos_tree
= DECL_FIELD_BITPOS (decl
);
7344 register unsigned bitpos_int
;
7345 register unsigned highest_order_object_bit_offset
;
7346 register unsigned highest_order_field_bit_offset
;
7347 register unsigned bit_offset
;
7349 /* Must be a field and a bit field. */
7351 || TREE_CODE (decl
) != FIELD_DECL
)
7354 /* We can't yet handle bit-fields whose offsets are variable, so if we
7355 encounter such things, just return without generating any attribute
7357 if (TREE_CODE (bitpos_tree
) != INTEGER_CST
)
7360 bitpos_int
= (unsigned) TREE_INT_CST_LOW (bitpos_tree
);
7362 /* Note that the bit offset is always the distance (in bits) from the
7363 highest-order bit of the "containing object" to the highest-order bit of
7364 the bit-field itself. Since the "high-order end" of any object or field
7365 is different on big-endian and little-endian machines, the computation
7366 below must take account of these differences. */
7367 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
7368 highest_order_field_bit_offset
= bitpos_int
;
7370 if (! BYTES_BIG_ENDIAN
)
7372 highest_order_field_bit_offset
7373 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl
));
7375 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
7379 = (! BYTES_BIG_ENDIAN
7380 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
7381 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
7383 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
7386 /* For a FIELD_DECL node which represents a bit field, output an attribute
7387 which specifies the length in bits of the given field. */
7390 add_bit_size_attribute (die
, decl
)
7391 register dw_die_ref die
;
7394 /* Must be a field and a bit field. */
7395 if (TREE_CODE (decl
) != FIELD_DECL
7396 || ! DECL_BIT_FIELD_TYPE (decl
))
7398 add_AT_unsigned (die
, DW_AT_bit_size
,
7399 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl
)));
7402 /* If the compiled language is ANSI C, then add a 'prototyped'
7403 attribute, if arg types are given for the parameters of a function. */
7406 add_prototyped_attribute (die
, func_type
)
7407 register dw_die_ref die
;
7408 register tree func_type
;
7410 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
7411 && TYPE_ARG_TYPES (func_type
) != NULL
)
7412 add_AT_flag (die
, DW_AT_prototyped
, 1);
7416 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7417 by looking in either the type declaration or object declaration
7421 add_abstract_origin_attribute (die
, origin
)
7422 register dw_die_ref die
;
7423 register tree origin
;
7425 dw_die_ref origin_die
= NULL
;
7426 if (TREE_CODE_CLASS (TREE_CODE (origin
)) == 'd')
7427 origin_die
= lookup_decl_die (origin
);
7428 else if (TREE_CODE_CLASS (TREE_CODE (origin
)) == 't')
7429 origin_die
= lookup_type_die (origin
);
7431 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
7434 /* We do not currently support the pure_virtual attribute. */
7437 add_pure_or_virtual_attribute (die
, func_decl
)
7438 register dw_die_ref die
;
7439 register tree func_decl
;
7441 if (DECL_VINDEX (func_decl
))
7443 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
7444 add_AT_loc (die
, DW_AT_vtable_elem_location
,
7445 new_loc_descr (DW_OP_constu
,
7446 TREE_INT_CST_LOW (DECL_VINDEX (func_decl
)),
7449 /* GNU extension: Record what type this method came from originally. */
7450 if (debug_info_level
> DINFO_LEVEL_TERSE
)
7451 add_AT_die_ref (die
, DW_AT_containing_type
,
7452 lookup_type_die (DECL_CONTEXT (func_decl
)));
7456 /* Add source coordinate attributes for the given decl. */
7459 add_src_coords_attributes (die
, decl
)
7460 register dw_die_ref die
;
7463 register unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
7465 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
7466 add_AT_unsigned (die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
7469 /* Add an DW_AT_name attribute and source coordinate attribute for the
7470 given decl, but only if it actually has a name. */
7473 add_name_and_src_coords_attributes (die
, decl
)
7474 register dw_die_ref die
;
7477 register tree decl_name
;
7479 decl_name
= DECL_NAME (decl
);
7480 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
7482 add_name_attribute (die
, dwarf2_name (decl
, 0));
7483 add_src_coords_attributes (die
, decl
);
7484 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
7485 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
7486 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
7487 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
7491 /* Push a new declaration scope. */
7494 push_decl_scope (scope
)
7497 tree containing_scope
;
7500 /* Make room in the decl_scope_table, if necessary. */
7501 if (decl_scope_table_allocated
== decl_scope_depth
)
7503 decl_scope_table_allocated
+= DECL_SCOPE_TABLE_INCREMENT
;
7505 = (decl_scope_node
*) xrealloc (decl_scope_table
,
7506 (decl_scope_table_allocated
7507 * sizeof (decl_scope_node
)));
7510 decl_scope_table
[decl_scope_depth
].scope
= scope
;
7512 /* Sometimes, while recursively emitting subtypes within a class type,
7513 we end up recuring on a subtype at a higher level then the current
7514 subtype. In such a case, we need to search the decl_scope_table to
7515 find the parent of this subtype. */
7517 if (TREE_CODE_CLASS (TREE_CODE (scope
)) == 't')
7518 containing_scope
= TYPE_CONTEXT (scope
);
7520 containing_scope
= NULL_TREE
;
7522 /* The normal case. */
7523 if (decl_scope_depth
== 0
7524 || containing_scope
== NULL_TREE
7525 || containing_scope
== decl_scope_table
[decl_scope_depth
- 1].scope
)
7526 decl_scope_table
[decl_scope_depth
].previous
= decl_scope_depth
- 1;
7529 /* We need to search for the containing_scope. */
7530 for (i
= 0; i
< decl_scope_depth
; i
++)
7531 if (decl_scope_table
[i
].scope
== containing_scope
)
7534 if (i
== decl_scope_depth
)
7537 decl_scope_table
[decl_scope_depth
].previous
= i
;
7543 /* Return the DIE for the scope the immediately contains this declaration. */
7546 scope_die_for (t
, context_die
)
7548 register dw_die_ref context_die
;
7550 register dw_die_ref scope_die
= NULL
;
7551 register tree containing_scope
;
7554 /* Walk back up the declaration tree looking for a place to define
7556 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
7557 containing_scope
= TYPE_CONTEXT (t
);
7558 else if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_VINDEX (t
))
7559 containing_scope
= decl_class_context (t
);
7561 containing_scope
= DECL_CONTEXT (t
);
7563 /* Function-local tags and functions get stuck in limbo until they are
7564 fixed up by decls_for_scope. */
7565 if (context_die
== NULL
&& containing_scope
!= NULL_TREE
7566 && (TREE_CODE (t
) == FUNCTION_DECL
|| is_tagged_type (t
)))
7569 if (containing_scope
== NULL_TREE
)
7570 scope_die
= comp_unit_die
;
7573 for (i
= decl_scope_depth
- 1, scope_die
= context_die
;
7574 i
>= 0 && decl_scope_table
[i
].scope
!= containing_scope
;
7575 (scope_die
= scope_die
->die_parent
,
7576 i
= decl_scope_table
[i
].previous
))
7581 if (scope_die
!= comp_unit_die
7582 || TREE_CODE_CLASS (TREE_CODE (containing_scope
)) != 't')
7584 if (debug_info_level
> DINFO_LEVEL_TERSE
7585 && !TREE_ASM_WRITTEN (containing_scope
))
7593 /* Pop a declaration scope. */
7597 if (decl_scope_depth
<= 0)
7602 /* Many forms of DIEs require a "type description" attribute. This
7603 routine locates the proper "type descriptor" die for the type given
7604 by 'type', and adds an DW_AT_type attribute below the given die. */
7607 add_type_attribute (object_die
, type
, decl_const
, decl_volatile
, context_die
)
7608 register dw_die_ref object_die
;
7610 register int decl_const
;
7611 register int decl_volatile
;
7612 register dw_die_ref context_die
;
7614 register enum tree_code code
= TREE_CODE (type
);
7615 register dw_die_ref type_die
= NULL
;
7617 /* ??? If this type is an unnamed subrange type of an integral or
7618 floating-point type, use the inner type. This is because we have no
7619 support for unnamed types in base_type_die. This can happen if this is
7620 an Ada subrange type. Correct solution is emit a subrange type die. */
7621 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
7622 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
7623 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
7625 if (code
== ERROR_MARK
)
7628 /* Handle a special case. For functions whose return type is void, we
7629 generate *no* type attribute. (Note that no object may have type
7630 `void', so this only applies to function return types). */
7631 if (code
== VOID_TYPE
)
7634 type_die
= modified_type_die (type
,
7635 decl_const
|| TYPE_READONLY (type
),
7636 decl_volatile
|| TYPE_VOLATILE (type
),
7638 if (type_die
!= NULL
)
7639 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
7642 /* Given a tree pointer to a struct, class, union, or enum type node, return
7643 a pointer to the (string) tag name for the given type, or zero if the type
7644 was declared without a tag. */
7650 register char *name
= 0;
7652 if (TYPE_NAME (type
) != 0)
7654 register tree t
= 0;
7656 /* Find the IDENTIFIER_NODE for the type name. */
7657 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
7658 t
= TYPE_NAME (type
);
7660 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7661 a TYPE_DECL node, regardless of whether or not a `typedef' was
7663 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
7664 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
7665 t
= DECL_NAME (TYPE_NAME (type
));
7667 /* Now get the name as a string, or invent one. */
7669 name
= IDENTIFIER_POINTER (t
);
7672 return (name
== 0 || *name
== '\0') ? 0 : name
;
7675 /* Return the type associated with a data member, make a special check
7676 for bit field types. */
7679 member_declared_type (member
)
7680 register tree member
;
7682 return (DECL_BIT_FIELD_TYPE (member
)
7683 ? DECL_BIT_FIELD_TYPE (member
)
7684 : TREE_TYPE (member
));
7687 /* Get the decl's label, as described by its RTL. This may be different
7688 from the DECL_NAME name used in the source file. */
7691 decl_start_label (decl
)
7696 x
= DECL_RTL (decl
);
7697 if (GET_CODE (x
) != MEM
)
7701 if (GET_CODE (x
) != SYMBOL_REF
)
7704 fnname
= XSTR (x
, 0);
7708 /* These routines generate the internal representation of the DIE's for
7709 the compilation unit. Debugging information is collected by walking
7710 the declaration trees passed in from dwarf2out_decl(). */
7713 gen_array_type_die (type
, context_die
)
7715 register dw_die_ref context_die
;
7717 register dw_die_ref scope_die
= scope_die_for (type
, context_die
);
7718 register dw_die_ref array_die
;
7719 register tree element_type
;
7721 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7722 the inner array type comes before the outer array type. Thus we must
7723 call gen_type_die before we call new_die. See below also. */
7724 #ifdef MIPS_DEBUGGING_INFO
7725 gen_type_die (TREE_TYPE (type
), context_die
);
7728 array_die
= new_die (DW_TAG_array_type
, scope_die
);
7731 /* We default the array ordering. SDB will probably do
7732 the right things even if DW_AT_ordering is not present. It's not even
7733 an issue until we start to get into multidimensional arrays anyway. If
7734 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7735 then we'll have to put the DW_AT_ordering attribute back in. (But if
7736 and when we find out that we need to put these in, we will only do so
7737 for multidimensional arrays. */
7738 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
7741 #ifdef MIPS_DEBUGGING_INFO
7742 /* The SGI compilers handle arrays of unknown bound by setting
7743 AT_declaration and not emitting any subrange DIEs. */
7744 if (! TYPE_DOMAIN (type
))
7745 add_AT_unsigned (array_die
, DW_AT_declaration
, 1);
7748 add_subscript_info (array_die
, type
);
7750 equate_type_number_to_die (type
, array_die
);
7752 /* Add representation of the type of the elements of this array type. */
7753 element_type
= TREE_TYPE (type
);
7755 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7756 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7757 We work around this by disabling this feature. See also
7758 add_subscript_info. */
7759 #ifndef MIPS_DEBUGGING_INFO
7760 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
7761 element_type
= TREE_TYPE (element_type
);
7763 gen_type_die (element_type
, context_die
);
7766 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
7770 gen_set_type_die (type
, context_die
)
7772 register dw_die_ref context_die
;
7774 register dw_die_ref type_die
7775 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
));
7777 equate_type_number_to_die (type
, type_die
);
7778 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
7782 gen_entry_point_die (decl
, context_die
)
7784 register dw_die_ref context_die
;
7786 register tree origin
= decl_ultimate_origin (decl
);
7787 register dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
);
7789 add_abstract_origin_attribute (decl_die
, origin
);
7792 add_name_and_src_coords_attributes (decl_die
, decl
);
7793 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
7797 if (DECL_ABSTRACT (decl
))
7798 equate_decl_number_to_die (decl
, decl_die
);
7800 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
7803 /* Remember a type in the pending_types_list. */
7809 if (pending_types
== pending_types_allocated
)
7811 pending_types_allocated
+= PENDING_TYPES_INCREMENT
;
7813 = (tree
*) xrealloc (pending_types_list
,
7814 sizeof (tree
) * pending_types_allocated
);
7817 pending_types_list
[pending_types
++] = type
;
7820 /* Output any pending types (from the pending_types list) which we can output
7821 now (taking into account the scope that we are working on now).
7823 For each type output, remove the given type from the pending_types_list
7824 *before* we try to output it. */
7827 output_pending_types_for_scope (context_die
)
7828 register dw_die_ref context_die
;
7832 while (pending_types
)
7835 type
= pending_types_list
[pending_types
];
7836 gen_type_die (type
, context_die
);
7837 if (!TREE_ASM_WRITTEN (type
))
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
,
7850 scope_die_for (type
, context_die
));
7852 if (!TREE_ASM_WRITTEN (type
))
7854 add_abstract_origin_attribute (type_die
, type
);
7857 /* Generate a DIE to represent an inlined instance of a structure type. */
7860 gen_inlined_structure_type_die (type
, context_die
)
7862 register dw_die_ref context_die
;
7864 register dw_die_ref type_die
= new_die (DW_TAG_structure_type
,
7865 scope_die_for (type
, context_die
));
7867 if (!TREE_ASM_WRITTEN (type
))
7869 add_abstract_origin_attribute (type_die
, type
);
7872 /* Generate a DIE to represent an inlined instance of a union type. */
7875 gen_inlined_union_type_die (type
, context_die
)
7877 register dw_die_ref context_die
;
7879 register dw_die_ref type_die
= new_die (DW_TAG_union_type
,
7880 scope_die_for (type
, context_die
));
7882 if (!TREE_ASM_WRITTEN (type
))
7884 add_abstract_origin_attribute (type_die
, type
);
7887 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7888 include all of the information about the enumeration values also. Each
7889 enumerated type name/value is listed as a child of the enumerated type
7893 gen_enumeration_type_die (type
, context_die
)
7895 register dw_die_ref context_die
;
7897 register dw_die_ref type_die
= lookup_type_die (type
);
7899 if (type_die
== NULL
)
7901 type_die
= new_die (DW_TAG_enumeration_type
,
7902 scope_die_for (type
, context_die
));
7903 equate_type_number_to_die (type
, type_die
);
7904 add_name_attribute (type_die
, type_tag (type
));
7906 else if (! TYPE_SIZE (type
))
7909 remove_AT (type_die
, DW_AT_declaration
);
7911 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7912 given enum type is incomplete, do not generate the DW_AT_byte_size
7913 attribute or the DW_AT_element_list attribute. */
7914 if (TYPE_SIZE (type
))
7918 TREE_ASM_WRITTEN (type
) = 1;
7919 add_byte_size_attribute (type_die
, type
);
7920 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
7921 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
7923 /* If the first reference to this type was as the return type of an
7924 inline function, then it may not have a parent. Fix this now. */
7925 if (type_die
->die_parent
== NULL
)
7926 add_child_die (scope_die_for (type
, context_die
), type_die
);
7928 for (link
= TYPE_FIELDS (type
);
7929 link
!= NULL
; link
= TREE_CHAIN (link
))
7931 register dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
);
7933 add_name_attribute (enum_die
,
7934 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
7935 add_AT_unsigned (enum_die
, DW_AT_const_value
,
7936 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link
)));
7940 add_AT_flag (type_die
, DW_AT_declaration
, 1);
7944 /* Generate a DIE to represent either a real live formal parameter decl or to
7945 represent just the type of some formal parameter position in some function
7948 Note that this routine is a bit unusual because its argument may be a
7949 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7950 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7951 node. If it's the former then this function is being called to output a
7952 DIE to represent a formal parameter object (or some inlining thereof). If
7953 it's the latter, then this function is only being called to output a
7954 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7955 argument type of some subprogram type. */
7958 gen_formal_parameter_die (node
, context_die
)
7960 register dw_die_ref context_die
;
7962 register dw_die_ref parm_die
7963 = new_die (DW_TAG_formal_parameter
, context_die
);
7964 register tree origin
;
7966 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
7969 origin
= decl_ultimate_origin (node
);
7971 add_abstract_origin_attribute (parm_die
, origin
);
7974 add_name_and_src_coords_attributes (parm_die
, node
);
7975 add_type_attribute (parm_die
, TREE_TYPE (node
),
7976 TREE_READONLY (node
),
7977 TREE_THIS_VOLATILE (node
),
7979 if (DECL_ARTIFICIAL (node
))
7980 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
7983 equate_decl_number_to_die (node
, parm_die
);
7984 if (! DECL_ABSTRACT (node
))
7985 add_location_or_const_value_attribute (parm_die
, node
);
7990 /* We were called with some kind of a ..._TYPE node. */
7991 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
8001 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
8002 at the end of an (ANSI prototyped) formal parameters list. */
8005 gen_unspecified_parameters_die (decl_or_type
, context_die
)
8006 register tree decl_or_type
;
8007 register dw_die_ref context_die
;
8009 register dw_die_ref parm_die
= new_die (DW_TAG_unspecified_parameters
,
8013 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
8014 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
8015 parameters as specified in some function type specification (except for
8016 those which appear as part of a function *definition*).
8018 Note we must be careful here to output all of the parameter DIEs before*
8019 we output any DIEs needed to represent the types of the formal parameters.
8020 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
8021 non-parameter DIE it sees ends the formal parameter list. */
8024 gen_formal_types_die (function_or_method_type
, context_die
)
8025 register tree function_or_method_type
;
8026 register dw_die_ref context_die
;
8029 register tree formal_type
= NULL
;
8030 register tree first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
8033 /* In the case where we are generating a formal types list for a C++
8034 non-static member function type, skip over the first thing on the
8035 TYPE_ARG_TYPES list because it only represents the type of the hidden
8036 `this pointer'. The debugger should be able to figure out (without
8037 being explicitly told) that this non-static member function type takes a
8038 `this pointer' and should be able to figure what the type of that hidden
8039 parameter is from the DW_AT_member attribute of the parent
8040 DW_TAG_subroutine_type DIE. */
8041 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
)
8042 first_parm_type
= TREE_CHAIN (first_parm_type
);
8045 /* Make our first pass over the list of formal parameter types and output a
8046 DW_TAG_formal_parameter DIE for each one. */
8047 for (link
= first_parm_type
; link
; link
= TREE_CHAIN (link
))
8049 register dw_die_ref parm_die
;
8051 formal_type
= TREE_VALUE (link
);
8052 if (formal_type
== void_type_node
)
8055 /* Output a (nameless) DIE to represent the formal parameter itself. */
8056 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
8057 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
8058 && link
== first_parm_type
)
8059 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
8062 /* If this function type has an ellipsis, add a
8063 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8064 if (formal_type
!= void_type_node
)
8065 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
8067 /* Make our second (and final) pass over the list of formal parameter types
8068 and output DIEs to represent those types (as necessary). */
8069 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
8071 link
= TREE_CHAIN (link
))
8073 formal_type
= TREE_VALUE (link
);
8074 if (formal_type
== void_type_node
)
8077 gen_type_die (formal_type
, context_die
);
8081 /* Generate a DIE to represent a declared function (either file-scope or
8085 gen_subprogram_die (decl
, context_die
)
8087 register dw_die_ref context_die
;
8089 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
8090 register tree origin
= decl_ultimate_origin (decl
);
8091 register dw_die_ref subr_die
;
8092 register rtx fp_reg
;
8093 register tree fn_arg_types
;
8094 register tree outer_scope
;
8095 register dw_die_ref old_die
= lookup_decl_die (decl
);
8096 register int declaration
8097 = (current_function_decl
!= decl
8099 && (context_die
->die_tag
== DW_TAG_structure_type
8100 || context_die
->die_tag
== DW_TAG_union_type
)));
8104 subr_die
= new_die (DW_TAG_subprogram
, context_die
);
8105 add_abstract_origin_attribute (subr_die
, origin
);
8107 else if (old_die
&& DECL_ABSTRACT (decl
)
8108 && get_AT_unsigned (old_die
, DW_AT_inline
))
8110 /* This must be a redefinition of an extern inline function.
8111 We can just reuse the old die here. */
8114 /* Clear out the inlined attribute and parm types. */
8115 remove_AT (subr_die
, DW_AT_inline
);
8116 remove_children (subr_die
);
8120 register unsigned file_index
8121 = lookup_filename (DECL_SOURCE_FILE (decl
));
8123 if (get_AT_flag (old_die
, DW_AT_declaration
) != 1)
8126 /* If the definition comes from the same place as the declaration,
8127 maybe use the old DIE. We always want the DIE for this function
8128 that has the *_pc attributes to be under comp_unit_die so the
8129 debugger can find it. For inlines, that is the concrete instance,
8130 so we can use the old DIE here. For non-inline methods, we want a
8131 specification DIE at toplevel, so we need a new DIE. For local
8132 class methods, this does not apply. */
8133 if ((DECL_ABSTRACT (decl
) || old_die
->die_parent
== comp_unit_die
8134 || context_die
== NULL
)
8135 && get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
8136 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
8137 == DECL_SOURCE_LINE (decl
)))
8141 /* Clear out the declaration attribute and the parm types. */
8142 remove_AT (subr_die
, DW_AT_declaration
);
8143 remove_children (subr_die
);
8147 subr_die
= new_die (DW_TAG_subprogram
, context_die
);
8148 add_AT_die_ref (subr_die
, DW_AT_specification
, old_die
);
8149 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
8150 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
8151 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
8152 != DECL_SOURCE_LINE (decl
))
8154 (subr_die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
8159 register dw_die_ref scope_die
;
8161 if (DECL_CONTEXT (decl
))
8162 scope_die
= scope_die_for (decl
, context_die
);
8164 /* Don't put block extern declarations under comp_unit_die. */
8165 scope_die
= context_die
;
8167 subr_die
= new_die (DW_TAG_subprogram
, scope_die
);
8169 if (TREE_PUBLIC (decl
))
8170 add_AT_flag (subr_die
, DW_AT_external
, 1);
8172 add_name_and_src_coords_attributes (subr_die
, decl
);
8173 if (debug_info_level
> DINFO_LEVEL_TERSE
)
8175 register tree type
= TREE_TYPE (decl
);
8177 add_prototyped_attribute (subr_die
, type
);
8178 add_type_attribute (subr_die
, TREE_TYPE (type
), 0, 0, context_die
);
8181 add_pure_or_virtual_attribute (subr_die
, decl
);
8182 if (DECL_ARTIFICIAL (decl
))
8183 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
8184 if (TREE_PROTECTED (decl
))
8185 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8186 else if (TREE_PRIVATE (decl
))
8187 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
8192 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
8194 /* The first time we see a member function, it is in the context of
8195 the class to which it belongs. We make sure of this by emitting
8196 the class first. The next time is the definition, which is
8197 handled above. The two may come from the same source text. */
8198 if (DECL_CONTEXT (decl
))
8199 equate_decl_number_to_die (decl
, subr_die
);
8201 else if (DECL_ABSTRACT (decl
))
8203 /* ??? Checking DECL_DEFER_OUTPUT is correct for static inline functions,
8204 but not for extern inline functions. We can't get this completely
8205 correct because information about whether the function was declared
8206 inline is not saved anywhere. */
8207 if (DECL_DEFER_OUTPUT (decl
))
8209 if (DECL_INLINE (decl
))
8210 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
8212 add_AT_unsigned (subr_die
, DW_AT_inline
,
8213 DW_INL_declared_not_inlined
);
8215 else if (DECL_INLINE (decl
))
8216 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
8220 equate_decl_number_to_die (decl
, subr_die
);
8222 else if (!DECL_EXTERNAL (decl
))
8224 if (origin
== NULL_TREE
)
8225 equate_decl_number_to_die (decl
, subr_die
);
8227 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
8228 current_funcdef_number
);
8229 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
8230 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
8231 current_funcdef_number
);
8232 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
8234 add_pubname (decl
, subr_die
);
8235 add_arange (decl
, subr_die
);
8237 #ifdef MIPS_DEBUGGING_INFO
8238 /* Add a reference to the FDE for this routine. */
8239 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
8242 /* Define the "frame base" location for this routine. We use the
8243 frame pointer or stack pointer registers, since the RTL for local
8244 variables is relative to one of them. */
8246 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
8247 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
8250 /* ??? This fails for nested inline functions, because context_display
8251 is not part of the state saved/restored for inline functions. */
8252 if (current_function_needs_context
)
8253 add_AT_location_description (subr_die
, DW_AT_static_link
,
8254 lookup_static_chain (decl
));
8258 /* Now output descriptions of the arguments for this function. This gets
8259 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8260 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8261 `...' at the end of the formal parameter list. In order to find out if
8262 there was a trailing ellipsis or not, we must instead look at the type
8263 associated with the FUNCTION_DECL. This will be a node of type
8264 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8265 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8266 an ellipsis at the end. */
8267 push_decl_scope (decl
);
8269 /* In the case where we are describing a mere function declaration, all we
8270 need to do here (and all we *can* do here) is to describe the *types* of
8271 its formal parameters. */
8272 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
8274 else if (declaration
)
8275 gen_formal_types_die (TREE_TYPE (decl
), subr_die
);
8278 /* Generate DIEs to represent all known formal parameters */
8279 register tree arg_decls
= DECL_ARGUMENTS (decl
);
8282 /* When generating DIEs, generate the unspecified_parameters DIE
8283 instead if we come across the arg "__builtin_va_alist" */
8284 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
8285 if (TREE_CODE (parm
) == PARM_DECL
)
8287 if (DECL_NAME (parm
)
8288 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
8289 "__builtin_va_alist"))
8290 gen_unspecified_parameters_die (parm
, subr_die
);
8292 gen_decl_die (parm
, subr_die
);
8295 /* Decide whether we need a unspecified_parameters DIE at the end.
8296 There are 2 more cases to do this for: 1) the ansi ... declaration -
8297 this is detectable when the end of the arg list is not a
8298 void_type_node 2) an unprototyped function declaration (not a
8299 definition). This just means that we have no info about the
8300 parameters at all. */
8301 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
8302 if (fn_arg_types
!= NULL
)
8304 /* this is the prototyped case, check for ... */
8305 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
8306 gen_unspecified_parameters_die (decl
, subr_die
);
8308 else if (DECL_INITIAL (decl
) == NULL_TREE
)
8309 gen_unspecified_parameters_die (decl
, subr_die
);
8312 /* Output Dwarf info for all of the stuff within the body of the function
8313 (if it has one - it may be just a declaration). */
8314 outer_scope
= DECL_INITIAL (decl
);
8316 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8317 node created to represent a function. This outermost BLOCK actually
8318 represents the outermost binding contour for the function, i.e. the
8319 contour in which the function's formal parameters and labels get
8320 declared. Curiously, it appears that the front end doesn't actually
8321 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8322 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8323 list for the function instead.) The BLOCK_VARS list for the
8324 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8325 the function however, and we output DWARF info for those in
8326 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8327 node representing the function's outermost pair of curly braces, and
8328 any blocks used for the base and member initializers of a C++
8329 constructor function. */
8330 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
8332 current_function_has_inlines
= 0;
8333 decls_for_scope (outer_scope
, subr_die
, 0);
8335 #if 0 && defined (MIPS_DEBUGGING_INFO)
8336 if (current_function_has_inlines
)
8338 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
8339 if (! comp_unit_has_inlines
)
8341 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
8342 comp_unit_has_inlines
= 1;
8351 /* Generate a DIE to represent a declared data object. */
8354 gen_variable_die (decl
, context_die
)
8356 register dw_die_ref context_die
;
8358 register tree origin
= decl_ultimate_origin (decl
);
8359 register dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
);
8361 dw_die_ref old_die
= lookup_decl_die (decl
);
8363 = (DECL_EXTERNAL (decl
)
8364 || current_function_decl
!= decl_function_context (decl
)
8365 || context_die
->die_tag
== DW_TAG_structure_type
8366 || context_die
->die_tag
== DW_TAG_union_type
);
8369 add_abstract_origin_attribute (var_die
, origin
);
8370 /* Loop unrolling can create multiple blocks that refer to the same
8371 static variable, so we must test for the DW_AT_declaration flag. */
8372 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8373 copy decls and set the DECL_ABSTRACT flag on them instead of
8375 else if (old_die
&& TREE_STATIC (decl
)
8376 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
8378 /* ??? This is an instantiation of a C++ class level static. */
8379 add_AT_die_ref (var_die
, DW_AT_specification
, old_die
);
8380 if (DECL_NAME (decl
))
8382 register unsigned file_index
8383 = lookup_filename (DECL_SOURCE_FILE (decl
));
8385 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
8386 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
8388 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
8389 != DECL_SOURCE_LINE (decl
))
8391 add_AT_unsigned (var_die
, DW_AT_decl_line
,
8392 DECL_SOURCE_LINE (decl
));
8397 add_name_and_src_coords_attributes (var_die
, decl
);
8398 add_type_attribute (var_die
, TREE_TYPE (decl
),
8399 TREE_READONLY (decl
),
8400 TREE_THIS_VOLATILE (decl
), context_die
);
8402 if (TREE_PUBLIC (decl
))
8403 add_AT_flag (var_die
, DW_AT_external
, 1);
8405 if (DECL_ARTIFICIAL (decl
))
8406 add_AT_flag (var_die
, DW_AT_artificial
, 1);
8408 if (TREE_PROTECTED (decl
))
8409 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8411 else if (TREE_PRIVATE (decl
))
8412 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
8416 add_AT_flag (var_die
, DW_AT_declaration
, 1);
8418 if ((declaration
&& decl_class_context (decl
)) || DECL_ABSTRACT (decl
))
8419 equate_decl_number_to_die (decl
, var_die
);
8421 if (! declaration
&& ! DECL_ABSTRACT (decl
))
8423 equate_decl_number_to_die (decl
, var_die
);
8424 add_location_or_const_value_attribute (var_die
, decl
);
8425 add_pubname (decl
, var_die
);
8429 /* Generate a DIE to represent a label identifier. */
8432 gen_label_die (decl
, context_die
)
8434 register dw_die_ref context_die
;
8436 register tree origin
= decl_ultimate_origin (decl
);
8437 register dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
);
8439 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8440 char label2
[MAX_ARTIFICIAL_LABEL_BYTES
];
8443 add_abstract_origin_attribute (lbl_die
, origin
);
8445 add_name_and_src_coords_attributes (lbl_die
, decl
);
8447 if (DECL_ABSTRACT (decl
))
8448 equate_decl_number_to_die (decl
, lbl_die
);
8451 insn
= DECL_RTL (decl
);
8452 if (GET_CODE (insn
) == CODE_LABEL
)
8454 /* When optimization is enabled (via -O) some parts of the compiler
8455 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8456 represent source-level labels which were explicitly declared by
8457 the user. This really shouldn't be happening though, so catch
8458 it if it ever does happen. */
8459 if (INSN_DELETED_P (insn
))
8462 sprintf (label2
, INSN_LABEL_FMT
, current_funcdef_number
);
8463 ASM_GENERATE_INTERNAL_LABEL (label
, label2
,
8464 (unsigned) INSN_UID (insn
));
8465 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
8470 /* Generate a DIE for a lexical block. */
8473 gen_lexical_block_die (stmt
, context_die
, depth
)
8475 register dw_die_ref context_die
;
8478 register dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
);
8479 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8481 if (! BLOCK_ABSTRACT (stmt
))
8483 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
8485 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
8486 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
, next_block_number
);
8487 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
8490 push_decl_scope (stmt
);
8491 decls_for_scope (stmt
, stmt_die
, depth
);
8495 /* Generate a DIE for an inlined subprogram. */
8498 gen_inlined_subroutine_die (stmt
, context_die
, depth
)
8500 register dw_die_ref context_die
;
8503 if (! BLOCK_ABSTRACT (stmt
))
8505 register dw_die_ref subr_die
8506 = new_die (DW_TAG_inlined_subroutine
, context_die
);
8507 register tree decl
= block_ultimate_origin (stmt
);
8508 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8510 add_abstract_origin_attribute (subr_die
, decl
);
8511 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
8513 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
8514 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
, next_block_number
);
8515 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
8516 push_decl_scope (decl
);
8517 decls_for_scope (stmt
, subr_die
, depth
);
8519 current_function_has_inlines
= 1;
8523 /* Generate a DIE for a field in a record, or structure. */
8526 gen_field_die (decl
, context_die
)
8528 register dw_die_ref context_die
;
8530 register dw_die_ref decl_die
= new_die (DW_TAG_member
, context_die
);
8532 add_name_and_src_coords_attributes (decl_die
, decl
);
8533 add_type_attribute (decl_die
, member_declared_type (decl
),
8534 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
8537 /* If this is a bit field... */
8538 if (DECL_BIT_FIELD_TYPE (decl
))
8540 add_byte_size_attribute (decl_die
, decl
);
8541 add_bit_size_attribute (decl_die
, decl
);
8542 add_bit_offset_attribute (decl_die
, decl
);
8545 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
8546 add_data_member_location_attribute (decl_die
, decl
);
8548 if (DECL_ARTIFICIAL (decl
))
8549 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
8551 if (TREE_PROTECTED (decl
))
8552 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8554 else if (TREE_PRIVATE (decl
))
8555 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
8559 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8560 Use modified_type_die instead.
8561 We keep this code here just in case these types of DIEs may be needed to
8562 represent certain things in other languages (e.g. Pascal) someday. */
8564 gen_pointer_type_die (type
, context_die
)
8566 register dw_die_ref context_die
;
8568 register dw_die_ref ptr_die
8569 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
));
8571 equate_type_number_to_die (type
, ptr_die
);
8572 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
8573 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
8576 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8577 Use modified_type_die instead.
8578 We keep this code here just in case these types of DIEs may be needed to
8579 represent certain things in other languages (e.g. Pascal) someday. */
8581 gen_reference_type_die (type
, context_die
)
8583 register dw_die_ref context_die
;
8585 register dw_die_ref ref_die
8586 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
));
8588 equate_type_number_to_die (type
, ref_die
);
8589 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
8590 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
8594 /* Generate a DIE for a pointer to a member type. */
8596 gen_ptr_to_mbr_type_die (type
, context_die
)
8598 register dw_die_ref context_die
;
8600 register dw_die_ref ptr_die
8601 = new_die (DW_TAG_ptr_to_member_type
, scope_die_for (type
, context_die
));
8603 equate_type_number_to_die (type
, ptr_die
);
8604 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
8605 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
8606 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
8609 /* Generate the DIE for the compilation unit. */
8612 gen_compile_unit_die (main_input_filename
)
8613 register char *main_input_filename
;
8616 char *wd
= getpwd ();
8618 comp_unit_die
= new_die (DW_TAG_compile_unit
, NULL
);
8619 add_name_attribute (comp_unit_die
, main_input_filename
);
8622 add_AT_string (comp_unit_die
, DW_AT_comp_dir
, wd
);
8624 sprintf (producer
, "%s %s", language_string
, version_string
);
8626 #ifdef MIPS_DEBUGGING_INFO
8627 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8628 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8629 not appear in the producer string, the debugger reaches the conclusion
8630 that the object file is stripped and has no debugging information.
8631 To get the MIPS/SGI debugger to believe that there is debugging
8632 information in the object file, we add a -g to the producer string. */
8633 if (debug_info_level
> DINFO_LEVEL_TERSE
)
8634 strcat (producer
, " -g");
8637 add_AT_string (comp_unit_die
, DW_AT_producer
, producer
);
8639 if (strcmp (language_string
, "GNU C++") == 0)
8640 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_C_plus_plus
);
8642 else if (strcmp (language_string
, "GNU Ada") == 0)
8643 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_Ada83
);
8645 else if (strcmp (language_string
, "GNU F77") == 0)
8646 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_Fortran77
);
8648 else if (strcmp (language_string
, "GNU Pascal") == 0)
8649 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_Pascal83
);
8651 else if (flag_traditional
)
8652 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_C
);
8655 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_C89
);
8657 #if 0 /* unimplemented */
8658 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
8659 add_AT_unsigned (comp_unit_die
, DW_AT_macro_info
, 0);
8663 /* Generate a DIE for a string type. */
8666 gen_string_type_die (type
, context_die
)
8668 register dw_die_ref context_die
;
8670 register dw_die_ref type_die
8671 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
));
8673 equate_type_number_to_die (type
, type_die
);
8675 /* Fudge the string length attribute for now. */
8677 /* TODO: add string length info.
8678 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8679 bound_representation (upper_bound, 0, 'u'); */
8682 /* Generate the DIE for a base class. */
8685 gen_inheritance_die (binfo
, context_die
)
8686 register tree binfo
;
8687 register dw_die_ref context_die
;
8689 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
);
8691 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
8692 add_data_member_location_attribute (die
, binfo
);
8694 if (TREE_VIA_VIRTUAL (binfo
))
8695 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
8696 if (TREE_VIA_PUBLIC (binfo
))
8697 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
8698 else if (TREE_VIA_PROTECTED (binfo
))
8699 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8702 /* Generate a DIE for a class member. */
8705 gen_member_die (type
, context_die
)
8707 register dw_die_ref context_die
;
8709 register tree member
;
8711 /* If this is not an incomplete type, output descriptions of each of its
8712 members. Note that as we output the DIEs necessary to represent the
8713 members of this record or union type, we will also be trying to output
8714 DIEs to represent the *types* of those members. However the `type'
8715 function (above) will specifically avoid generating type DIEs for member
8716 types *within* the list of member DIEs for this (containing) type execpt
8717 for those types (of members) which are explicitly marked as also being
8718 members of this (containing) type themselves. The g++ front- end can
8719 force any given type to be treated as a member of some other
8720 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8721 to point to the TREE node representing the appropriate (containing)
8724 /* First output info about the base classes. */
8725 if (TYPE_BINFO (type
) && TYPE_BINFO_BASETYPES (type
))
8727 register tree bases
= TYPE_BINFO_BASETYPES (type
);
8728 register int n_bases
= TREE_VEC_LENGTH (bases
);
8731 for (i
= 0; i
< n_bases
; i
++)
8732 gen_inheritance_die (TREE_VEC_ELT (bases
, i
), context_die
);
8735 /* Now output info about the data members and type members. */
8736 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
8737 gen_decl_die (member
, context_die
);
8739 /* Now output info about the function members (if any). */
8740 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
8741 gen_decl_die (member
, context_die
);
8744 /* Generate a DIE for a structure or union type. */
8747 gen_struct_or_union_type_die (type
, context_die
)
8749 register dw_die_ref context_die
;
8751 register dw_die_ref type_die
= lookup_type_die (type
);
8752 register dw_die_ref scope_die
= 0;
8753 register int nested
= 0;
8755 if (type_die
&& ! TYPE_SIZE (type
))
8758 if (TYPE_CONTEXT (type
) != NULL_TREE
8759 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type
))) == 't')
8762 scope_die
= scope_die_for (type
, context_die
);
8764 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
8765 /* First occurrence of type or toplevel definition of nested class. */
8767 register dw_die_ref old_die
= type_die
;
8769 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
8770 ? DW_TAG_structure_type
: DW_TAG_union_type
,
8772 equate_type_number_to_die (type
, type_die
);
8773 add_name_attribute (type_die
, type_tag (type
));
8775 add_AT_die_ref (type_die
, DW_AT_specification
, old_die
);
8778 remove_AT (type_die
, DW_AT_declaration
);
8780 /* If we're not in the right context to be defining this type, defer to
8781 avoid tricky recursion. */
8782 if (TYPE_SIZE (type
) && decl_scope_depth
> 0 && scope_die
== comp_unit_die
)
8784 add_AT_flag (type_die
, DW_AT_declaration
, 1);
8787 /* If this type has been completed, then give it a byte_size attribute and
8788 then give a list of members. */
8789 else if (TYPE_SIZE (type
))
8791 /* Prevent infinite recursion in cases where the type of some member of
8792 this type is expressed in terms of this type itself. */
8793 TREE_ASM_WRITTEN (type
) = 1;
8794 add_byte_size_attribute (type_die
, type
);
8795 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
8796 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
8798 /* If the first reference to this type was as the return type of an
8799 inline function, then it may not have a parent. Fix this now. */
8800 if (type_die
->die_parent
== NULL
)
8801 add_child_die (scope_die
, type_die
);
8803 push_decl_scope (type
);
8804 gen_member_die (type
, type_die
);
8807 /* GNU extension: Record what type our vtable lives in. */
8808 if (TYPE_VFIELD (type
))
8810 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
8812 gen_type_die (vtype
, context_die
);
8813 add_AT_die_ref (type_die
, DW_AT_containing_type
,
8814 lookup_type_die (vtype
));
8818 add_AT_flag (type_die
, DW_AT_declaration
, 1);
8821 /* Generate a DIE for a subroutine _type_. */
8824 gen_subroutine_type_die (type
, context_die
)
8826 register dw_die_ref context_die
;
8828 register tree return_type
= TREE_TYPE (type
);
8829 register dw_die_ref subr_die
8830 = new_die (DW_TAG_subroutine_type
, scope_die_for (type
, context_die
));
8832 equate_type_number_to_die (type
, subr_die
);
8833 add_prototyped_attribute (subr_die
, type
);
8834 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
8835 gen_formal_types_die (type
, subr_die
);
8838 /* Generate a DIE for a type definition */
8841 gen_typedef_die (decl
, context_die
)
8843 register dw_die_ref context_die
;
8845 register dw_die_ref type_die
;
8846 register tree origin
;
8848 if (TREE_ASM_WRITTEN (decl
))
8850 TREE_ASM_WRITTEN (decl
) = 1;
8852 type_die
= new_die (DW_TAG_typedef
, scope_die_for (decl
, context_die
));
8853 origin
= decl_ultimate_origin (decl
);
8855 add_abstract_origin_attribute (type_die
, origin
);
8859 add_name_and_src_coords_attributes (type_die
, decl
);
8860 if (DECL_ORIGINAL_TYPE (decl
))
8862 type
= DECL_ORIGINAL_TYPE (decl
);
8863 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
8866 type
= TREE_TYPE (decl
);
8867 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
8868 TREE_THIS_VOLATILE (decl
), context_die
);
8871 if (DECL_ABSTRACT (decl
))
8872 equate_decl_number_to_die (decl
, type_die
);
8875 /* Generate a type description DIE. */
8878 gen_type_die (type
, context_die
)
8880 register dw_die_ref context_die
;
8882 if (type
== NULL_TREE
|| type
== error_mark_node
)
8885 /* We are going to output a DIE to represent the unqualified version of of
8886 this type (i.e. without any const or volatile qualifiers) so get the
8887 main variant (i.e. the unqualified version) of this type now. */
8888 type
= type_main_variant (type
);
8890 if (TREE_ASM_WRITTEN (type
))
8893 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
8894 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
8896 TREE_ASM_WRITTEN (type
) = 1;
8897 gen_decl_die (TYPE_NAME (type
), context_die
);
8901 switch (TREE_CODE (type
))
8907 case REFERENCE_TYPE
:
8908 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
8909 ensures that the gen_type_die recursion will terminate even if the
8910 type is recursive. Recursive types are possible in Ada. */
8911 /* ??? We could perhaps do this for all types before the switch
8913 TREE_ASM_WRITTEN (type
) = 1;
8915 /* For these types, all that is required is that we output a DIE (or a
8916 set of DIEs) to represent the "basis" type. */
8917 gen_type_die (TREE_TYPE (type
), context_die
);
8921 /* This code is used for C++ pointer-to-data-member types.
8922 Output a description of the relevant class type. */
8923 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
8925 /* Output a description of the type of the object pointed to. */
8926 gen_type_die (TREE_TYPE (type
), context_die
);
8928 /* Now output a DIE to represent this pointer-to-data-member type
8930 gen_ptr_to_mbr_type_die (type
, context_die
);
8934 gen_type_die (TYPE_DOMAIN (type
), context_die
);
8935 gen_set_type_die (type
, context_die
);
8939 gen_type_die (TREE_TYPE (type
), context_die
);
8940 abort (); /* No way to represent these in Dwarf yet! */
8944 /* Force out return type (in case it wasn't forced out already). */
8945 gen_type_die (TREE_TYPE (type
), context_die
);
8946 gen_subroutine_type_die (type
, context_die
);
8950 /* Force out return type (in case it wasn't forced out already). */
8951 gen_type_die (TREE_TYPE (type
), context_die
);
8952 gen_subroutine_type_die (type
, context_die
);
8956 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
8958 gen_type_die (TREE_TYPE (type
), context_die
);
8959 gen_string_type_die (type
, context_die
);
8962 gen_array_type_die (type
, context_die
);
8968 case QUAL_UNION_TYPE
:
8969 /* If this is a nested type whose containing class hasn't been
8970 written out yet, writing it out will cover this one, too. */
8971 if (TYPE_CONTEXT (type
)
8972 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type
))) == 't'
8973 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
8975 gen_type_die (TYPE_CONTEXT (type
), context_die
);
8977 if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
8980 /* If that failed, attach ourselves to the stub. */
8981 push_decl_scope (TYPE_CONTEXT (type
));
8982 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
8985 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
8986 gen_enumeration_type_die (type
, context_die
);
8988 gen_struct_or_union_type_die (type
, context_die
);
8990 if (TYPE_CONTEXT (type
)
8991 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type
))) == 't'
8992 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
8995 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
8996 it up if it is ever completed. gen_*_type_die will set it for us
8997 when appropriate. */
9006 /* No DIEs needed for fundamental types. */
9010 /* No Dwarf representation currently defined. */
9017 TREE_ASM_WRITTEN (type
) = 1;
9020 /* Generate a DIE for a tagged type instantiation. */
9023 gen_tagged_type_instantiation_die (type
, context_die
)
9025 register dw_die_ref context_die
;
9027 if (type
== NULL_TREE
|| type
== error_mark_node
)
9030 /* We are going to output a DIE to represent the unqualified version of of
9031 this type (i.e. without any const or volatile qualifiers) so make sure
9032 that we have the main variant (i.e. the unqualified version) of this
9034 if (type
!= type_main_variant (type
)
9035 || !TREE_ASM_WRITTEN (type
))
9038 switch (TREE_CODE (type
))
9044 gen_inlined_enumeration_type_die (type
, context_die
);
9048 gen_inlined_structure_type_die (type
, context_die
);
9052 case QUAL_UNION_TYPE
:
9053 gen_inlined_union_type_die (type
, context_die
);
9061 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
9062 things which are local to the given block. */
9065 gen_block_die (stmt
, context_die
, depth
)
9067 register dw_die_ref context_die
;
9070 register int must_output_die
= 0;
9071 register tree origin
;
9073 register enum tree_code origin_code
;
9075 /* Ignore blocks never really used to make RTL. */
9077 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
))
9080 /* Determine the "ultimate origin" of this block. This block may be an
9081 inlined instance of an inlined instance of inline function, so we have
9082 to trace all of the way back through the origin chain to find out what
9083 sort of node actually served as the original seed for the creation of
9084 the current block. */
9085 origin
= block_ultimate_origin (stmt
);
9086 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
9088 /* Determine if we need to output any Dwarf DIEs at all to represent this
9090 if (origin_code
== FUNCTION_DECL
)
9091 /* The outer scopes for inlinings *must* always be represented. We
9092 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9093 must_output_die
= 1;
9096 /* In the case where the current block represents an inlining of the
9097 "body block" of an inline function, we must *NOT* output any DIE for
9098 this block because we have already output a DIE to represent the
9099 whole inlined function scope and the "body block" of any function
9100 doesn't really represent a different scope according to ANSI C
9101 rules. So we check here to make sure that this block does not
9102 represent a "body block inlining" before trying to set the
9103 `must_output_die' flag. */
9104 if (! is_body_block (origin
? origin
: stmt
))
9106 /* Determine if this block directly contains any "significant"
9107 local declarations which we will need to output DIEs for. */
9108 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9109 /* We are not in terse mode so *any* local declaration counts
9110 as being a "significant" one. */
9111 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
9113 /* We are in terse mode, so only local (nested) function
9114 definitions count as "significant" local declarations. */
9115 for (decl
= BLOCK_VARS (stmt
);
9116 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
9117 if (TREE_CODE (decl
) == FUNCTION_DECL
9118 && DECL_INITIAL (decl
))
9120 must_output_die
= 1;
9126 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9127 DIE for any block which contains no significant local declarations at
9128 all. Rather, in such cases we just call `decls_for_scope' so that any
9129 needed Dwarf info for any sub-blocks will get properly generated. Note
9130 that in terse mode, our definition of what constitutes a "significant"
9131 local declaration gets restricted to include only inlined function
9132 instances and local (nested) function definitions. */
9133 if (must_output_die
)
9135 if (origin_code
== FUNCTION_DECL
)
9136 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
9138 gen_lexical_block_die (stmt
, context_die
, depth
);
9141 decls_for_scope (stmt
, context_die
, depth
);
9144 /* Generate all of the decls declared within a given scope and (recursively)
9145 all of it's sub-blocks. */
9148 decls_for_scope (stmt
, context_die
, depth
)
9150 register dw_die_ref context_die
;
9154 register tree subblocks
;
9156 /* Ignore blocks never really used to make RTL. */
9157 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
9160 if (!BLOCK_ABSTRACT (stmt
) && depth
> 0)
9161 next_block_number
++;
9163 /* Output the DIEs to represent all of the data objects and typedefs
9164 declared directly within this block but not within any nested
9165 sub-blocks. Also, nested function and tag DIEs have been
9166 generated with a parent of NULL; fix that up now. */
9167 for (decl
= BLOCK_VARS (stmt
);
9168 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
9170 register dw_die_ref die
;
9172 if (TREE_CODE (decl
) == FUNCTION_DECL
)
9173 die
= lookup_decl_die (decl
);
9174 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
9175 die
= lookup_type_die (TREE_TYPE (decl
));
9179 if (die
!= NULL
&& die
->die_parent
== NULL
)
9180 add_child_die (context_die
, die
);
9182 gen_decl_die (decl
, context_die
);
9185 /* Output the DIEs to represent all sub-blocks (and the items declared
9186 therein) of this block. */
9187 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
9189 subblocks
= BLOCK_CHAIN (subblocks
))
9190 gen_block_die (subblocks
, context_die
, depth
+ 1);
9193 /* Is this a typedef we can avoid emitting? */
9196 is_redundant_typedef (decl
)
9199 if (TYPE_DECL_IS_STUB (decl
))
9202 if (DECL_ARTIFICIAL (decl
)
9203 && DECL_CONTEXT (decl
)
9204 && is_tagged_type (DECL_CONTEXT (decl
))
9205 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
9206 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
9207 /* Also ignore the artificial member typedef for the class name. */
9213 /* Generate Dwarf debug information for a decl described by DECL. */
9216 gen_decl_die (decl
, context_die
)
9218 register dw_die_ref context_die
;
9220 register tree origin
;
9222 /* Make a note of the decl node we are going to be working on. We may need
9223 to give the user the source coordinates of where it appeared in case we
9224 notice (later on) that something about it looks screwy. */
9225 dwarf_last_decl
= decl
;
9227 if (TREE_CODE (decl
) == ERROR_MARK
)
9230 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
9231 ignore a function definition, since that would screw up our count of
9232 blocks, and that it turn will completely screw up the the labels we will
9233 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9234 subsequent blocks). */
9235 if (DECL_IGNORED_P (decl
) && TREE_CODE (decl
) != FUNCTION_DECL
)
9238 switch (TREE_CODE (decl
))
9241 /* The individual enumerators of an enum type get output when we output
9242 the Dwarf representation of the relevant enum type itself. */
9246 /* Don't output any DIEs to represent mere function declarations,
9247 unless they are class members or explicit block externs. */
9248 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
9249 && (current_function_decl
== NULL_TREE
|| ! DECL_ARTIFICIAL (decl
)))
9252 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9254 /* Before we describe the FUNCTION_DECL itself, make sure that we
9255 have described its return type. */
9256 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
9258 /* And its containing type. */
9259 origin
= decl_class_context (decl
);
9260 if (origin
!= NULL_TREE
)
9261 gen_type_die (origin
, context_die
);
9263 /* And its virtual context. */
9264 if (DECL_VINDEX (decl
) != NULL_TREE
)
9265 gen_type_die (DECL_CONTEXT (decl
), context_die
);
9268 /* Now output a DIE to represent the function itself. */
9269 gen_subprogram_die (decl
, context_die
);
9273 /* If we are in terse mode, don't generate any DIEs to represent any
9275 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9278 /* In the special case of a TYPE_DECL node representing the
9279 declaration of some type tag, if the given TYPE_DECL is marked as
9280 having been instantiated from some other (original) TYPE_DECL node
9281 (e.g. one which was generated within the original definition of an
9282 inline function) we have to generate a special (abbreviated)
9283 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9285 if (TYPE_DECL_IS_STUB (decl
) && DECL_ABSTRACT_ORIGIN (decl
) != NULL_TREE
)
9287 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
9291 if (is_redundant_typedef (decl
))
9292 gen_type_die (TREE_TYPE (decl
), context_die
);
9294 /* Output a DIE to represent the typedef itself. */
9295 gen_typedef_die (decl
, context_die
);
9299 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
9300 gen_label_die (decl
, context_die
);
9304 /* If we are in terse mode, don't generate any DIEs to represent any
9305 variable declarations or definitions. */
9306 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9309 /* Output any DIEs that are needed to specify the type of this data
9311 gen_type_die (TREE_TYPE (decl
), context_die
);
9313 /* And its containing type. */
9314 origin
= decl_class_context (decl
);
9315 if (origin
!= NULL_TREE
)
9316 gen_type_die (origin
, context_die
);
9318 /* Now output the DIE to represent the data object itself. This gets
9319 complicated because of the possibility that the VAR_DECL really
9320 represents an inlined instance of a formal parameter for an inline
9322 origin
= decl_ultimate_origin (decl
);
9323 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
9324 gen_formal_parameter_die (decl
, context_die
);
9326 gen_variable_die (decl
, context_die
);
9330 /* Ignore the nameless fields that are used to skip bits, but
9331 handle C++ anonymous unions. */
9332 if (DECL_NAME (decl
) != NULL_TREE
9333 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
)
9335 gen_type_die (member_declared_type (decl
), context_die
);
9336 gen_field_die (decl
, context_die
);
9341 gen_type_die (TREE_TYPE (decl
), context_die
);
9342 gen_formal_parameter_die (decl
, context_die
);
9350 /* Write the debugging output for DECL. */
9353 dwarf2out_decl (decl
)
9356 register dw_die_ref context_die
= comp_unit_die
;
9358 if (TREE_CODE (decl
) == ERROR_MARK
)
9361 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
9362 hope that the node in question doesn't represent a function definition.
9363 If it does, then totally ignoring it is bound to screw up our count of
9364 blocks, and that it turn will completely screw up the the labels we will
9365 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9366 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
9367 own sequence numbers with them!) */
9368 if (DECL_IGNORED_P (decl
))
9370 if (TREE_CODE (decl
) == FUNCTION_DECL
9371 && DECL_INITIAL (decl
) != NULL
)
9377 switch (TREE_CODE (decl
))
9380 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9381 builtin function. Explicit programmer-supplied declarations of
9382 these same functions should NOT be ignored however. */
9383 if (DECL_EXTERNAL (decl
) && DECL_FUNCTION_CODE (decl
))
9386 /* What we would really like to do here is to filter out all mere
9387 file-scope declarations of file-scope functions which are never
9388 referenced later within this translation unit (and keep all of ones
9389 that *are* referenced later on) but we aren't clairvoyant, so we have
9390 no idea which functions will be referenced in the future (i.e. later
9391 on within the current translation unit). So here we just ignore all
9392 file-scope function declarations which are not also definitions. If
9393 and when the debugger needs to know something about these functions,
9394 it wil have to hunt around and find the DWARF information associated
9395 with the definition of the function. Note that we can't just check
9396 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9397 definitions and which ones represent mere declarations. We have to
9398 check `DECL_INITIAL' instead. That's because the C front-end
9399 supports some weird semantics for "extern inline" function
9400 definitions. These can get inlined within the current translation
9401 unit (an thus, we need to generate DWARF info for their abstract
9402 instances so that the DWARF info for the concrete inlined instances
9403 can have something to refer to) but the compiler never generates any
9404 out-of-lines instances of such things (despite the fact that they
9405 *are* definitions). The important point is that the C front-end
9406 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9407 to generate DWARF for them anyway. Note that the C++ front-end also
9408 plays some similar games for inline function definitions appearing
9409 within include files which also contain
9410 `#pragma interface' pragmas. */
9411 if (DECL_INITIAL (decl
) == NULL_TREE
)
9414 /* If we're a nested function, initially use a parent of NULL; if we're
9415 a plain function, this will be fixed up in decls_for_scope. If
9416 we're a method, it will be ignored, since we already have a DIE. */
9417 if (decl_function_context (decl
))
9423 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9424 declaration and if the declaration was never even referenced from
9425 within this entire compilation unit. We suppress these DIEs in
9426 order to save space in the .debug section (by eliminating entries
9427 which are probably useless). Note that we must not suppress
9428 block-local extern declarations (whether used or not) because that
9429 would screw-up the debugger's name lookup mechanism and cause it to
9430 miss things which really ought to be in scope at a given point. */
9431 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
9434 /* If we are in terse mode, don't generate any DIEs to represent any
9435 variable declarations or definitions. */
9436 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9441 /* Don't bother trying to generate any DIEs to represent any of the
9442 normal built-in types for the language we are compiling. */
9443 if (DECL_SOURCE_LINE (decl
) == 0)
9445 /* OK, we need to generate one for `bool' so GDB knows what type
9446 comparisons have. */
9447 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
9448 == DW_LANG_C_plus_plus
)
9449 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
)
9450 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
9455 /* If we are in terse mode, don't generate any DIEs for types. */
9456 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9459 /* If we're a function-scope tag, initially use a parent of NULL;
9460 this will be fixed up in decls_for_scope. */
9461 if (decl_function_context (decl
))
9470 gen_decl_die (decl
, context_die
);
9471 output_pending_types_for_scope (comp_unit_die
);
9474 /* Output a marker (i.e. a label) for the beginning of the generated code for
9478 dwarf2out_begin_block (blocknum
)
9479 register unsigned blocknum
;
9481 function_section (current_function_decl
);
9482 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
9485 /* Output a marker (i.e. a label) for the end of the generated code for a
9489 dwarf2out_end_block (blocknum
)
9490 register unsigned blocknum
;
9492 function_section (current_function_decl
);
9493 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
9496 /* Output a marker (i.e. a label) at a point in the assembly code which
9497 corresponds to a given source level label. */
9500 dwarf2out_label (insn
)
9503 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9505 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
9507 function_section (current_function_decl
);
9508 sprintf (label
, INSN_LABEL_FMT
, current_funcdef_number
);
9509 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, label
,
9510 (unsigned) INSN_UID (insn
));
9514 /* Lookup a filename (in the list of filenames that we know about here in
9515 dwarf2out.c) and return its "index". The index of each (known) filename is
9516 just a unique number which is associated with only that one filename.
9517 We need such numbers for the sake of generating labels
9518 (in the .debug_sfnames section) and references to those
9519 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9520 If the filename given as an argument is not found in our current list,
9521 add it to the list and assign it the next available unique index number.
9522 In order to speed up searches, we remember the index of the filename
9523 was looked up last. This handles the majority of all searches. */
9526 lookup_filename (file_name
)
9529 static unsigned last_file_lookup_index
= 0;
9530 register unsigned i
;
9532 /* Check to see if the file name that was searched on the previous call
9533 matches this file name. If so, return the index. */
9534 if (last_file_lookup_index
!= 0)
9535 if (strcmp (file_name
, file_table
[last_file_lookup_index
]) == 0)
9536 return last_file_lookup_index
;
9538 /* Didn't match the previous lookup, search the table */
9539 for (i
= 1; i
< file_table_in_use
; ++i
)
9540 if (strcmp (file_name
, file_table
[i
]) == 0)
9542 last_file_lookup_index
= i
;
9546 /* Prepare to add a new table entry by making sure there is enough space in
9547 the table to do so. If not, expand the current table. */
9548 if (file_table_in_use
== file_table_allocated
)
9550 file_table_allocated
+= FILE_TABLE_INCREMENT
;
9552 = (char **) xrealloc (file_table
,
9553 file_table_allocated
* sizeof (char *));
9556 /* Add the new entry to the end of the filename table. */
9557 file_table
[file_table_in_use
] = xstrdup (file_name
);
9558 last_file_lookup_index
= file_table_in_use
++;
9560 return last_file_lookup_index
;
9563 /* Output a label to mark the beginning of a source code line entry
9564 and record information relating to this source line, in
9565 'line_info_table' for later output of the .debug_line section. */
9568 dwarf2out_line (filename
, line
)
9569 register char *filename
;
9570 register unsigned line
;
9572 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
9574 function_section (current_function_decl
);
9576 if (DECL_SECTION_NAME (current_function_decl
))
9578 register dw_separate_line_info_ref line_info
;
9579 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
9580 separate_line_info_table_in_use
);
9581 fputc ('\n', asm_out_file
);
9583 /* expand the line info table if necessary */
9584 if (separate_line_info_table_in_use
9585 == separate_line_info_table_allocated
)
9587 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
9588 separate_line_info_table
9589 = (dw_separate_line_info_ref
)
9590 xrealloc (separate_line_info_table
,
9591 separate_line_info_table_allocated
9592 * sizeof (dw_separate_line_info_entry
));
9595 /* Add the new entry at the end of the line_info_table. */
9597 = &separate_line_info_table
[separate_line_info_table_in_use
++];
9598 line_info
->dw_file_num
= lookup_filename (filename
);
9599 line_info
->dw_line_num
= line
;
9600 line_info
->function
= current_funcdef_number
;
9604 register dw_line_info_ref line_info
;
9606 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, LINE_CODE_LABEL
,
9607 line_info_table_in_use
);
9608 fputc ('\n', asm_out_file
);
9610 /* Expand the line info table if necessary. */
9611 if (line_info_table_in_use
== line_info_table_allocated
)
9613 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
9615 = (dw_line_info_ref
)
9616 xrealloc (line_info_table
,
9617 (line_info_table_allocated
9618 * sizeof (dw_line_info_entry
)));
9621 /* Add the new entry at the end of the line_info_table. */
9622 line_info
= &line_info_table
[line_info_table_in_use
++];
9623 line_info
->dw_file_num
= lookup_filename (filename
);
9624 line_info
->dw_line_num
= line
;
9629 /* Record the beginning of a new source file, for later output
9630 of the .debug_macinfo section. At present, unimplemented. */
9633 dwarf2out_start_source_file (filename
)
9634 register char *filename
;
9638 /* Record the end of a source file, for later output
9639 of the .debug_macinfo section. At present, unimplemented. */
9642 dwarf2out_end_source_file ()
9646 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9647 the tail part of the directive line, i.e. the part which is past the
9648 initial whitespace, #, whitespace, directive-name, whitespace part. */
9651 dwarf2out_define (lineno
, buffer
)
9652 register unsigned lineno
;
9653 register char *buffer
;
9655 static int initialized
= 0;
9658 dwarf2out_start_source_file (primary_filename
);
9663 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9664 the tail part of the directive line, i.e. the part which is past the
9665 initial whitespace, #, whitespace, directive-name, whitespace part. */
9668 dwarf2out_undef (lineno
, buffer
)
9669 register unsigned lineno
;
9670 register char *buffer
;
9674 /* Set up for Dwarf output at the start of compilation. */
9677 dwarf2out_init (asm_out_file
, main_input_filename
)
9678 register FILE *asm_out_file
;
9679 register char *main_input_filename
;
9681 /* Remember the name of the primary input file. */
9682 primary_filename
= main_input_filename
;
9684 /* Allocate the initial hunk of the file_table. */
9685 file_table
= (char **) xmalloc (FILE_TABLE_INCREMENT
* sizeof (char *));
9686 bzero ((char *) file_table
, FILE_TABLE_INCREMENT
* sizeof (char *));
9687 file_table_allocated
= FILE_TABLE_INCREMENT
;
9689 /* Skip the first entry - file numbers begin at 1. */
9690 file_table_in_use
= 1;
9692 /* Allocate the initial hunk of the decl_die_table. */
9694 = (dw_die_ref
*) xmalloc (DECL_DIE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
9695 bzero ((char *) decl_die_table
,
9696 DECL_DIE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
9697 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
9698 decl_die_table_in_use
= 0;
9700 /* Allocate the initial hunk of the decl_scope_table. */
9702 = (decl_scope_node
*) xmalloc (DECL_SCOPE_TABLE_INCREMENT
9703 * sizeof (decl_scope_node
));
9704 bzero ((char *) decl_scope_table
,
9705 DECL_SCOPE_TABLE_INCREMENT
* sizeof (decl_scope_node
));
9706 decl_scope_table_allocated
= DECL_SCOPE_TABLE_INCREMENT
;
9707 decl_scope_depth
= 0;
9709 /* Allocate the initial hunk of the abbrev_die_table. */
9711 = (dw_die_ref
*) xmalloc (ABBREV_DIE_TABLE_INCREMENT
9712 * sizeof (dw_die_ref
));
9713 bzero ((char *) abbrev_die_table
,
9714 ABBREV_DIE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
9715 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
9716 /* Zero-th entry is allocated, but unused */
9717 abbrev_die_table_in_use
= 1;
9719 /* Allocate the initial hunk of the line_info_table. */
9721 = (dw_line_info_ref
) xmalloc (LINE_INFO_TABLE_INCREMENT
9722 * sizeof (dw_line_info_entry
));
9723 bzero ((char *) line_info_table
,
9724 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
9725 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
9726 /* Zero-th entry is allocated, but unused */
9727 line_info_table_in_use
= 1;
9729 /* Generate the initial DIE for the .debug section. Note that the (string)
9730 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9731 will (typically) be a relative pathname and that this pathname should be
9732 taken as being relative to the directory from which the compiler was
9733 invoked when the given (base) source file was compiled. */
9734 gen_compile_unit_die (main_input_filename
);
9736 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
9739 /* Output stuff that dwarf requires at the end of every file,
9740 and generate the DWARF-2 debugging info. */
9745 limbo_die_node
*node
, *next_node
;
9749 /* Traverse the limbo die list, and add parent/child links. The only
9750 dies without parents that should be here are concrete instances of
9751 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9752 For concrete instances, we can get the parent die from the abstract
9754 for (node
= limbo_die_list
; node
; node
= next_node
)
9756 next_node
= node
->next
;
9759 if (die
->die_parent
== NULL
)
9761 a
= get_AT (die
, DW_AT_abstract_origin
);
9763 add_child_die (a
->dw_attr_val
.v
.val_die_ref
->die_parent
, die
);
9764 else if (die
== comp_unit_die
)
9772 /* Traverse the DIE tree and add sibling attributes to those DIE's
9773 that have children. */
9774 add_sibling_attributes (comp_unit_die
);
9776 /* Output a terminator label for the .text section. */
9777 fputc ('\n', asm_out_file
);
9778 ASM_OUTPUT_SECTION (asm_out_file
, TEXT_SECTION
);
9779 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, TEXT_END_LABEL
, 0);
9782 /* Output a terminator label for the .data section. */
9783 fputc ('\n', asm_out_file
);
9784 ASM_OUTPUT_SECTION (asm_out_file
, DATA_SECTION
);
9785 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, DATA_END_LABEL
, 0);
9787 /* Output a terminator label for the .bss section. */
9788 fputc ('\n', asm_out_file
);
9789 ASM_OUTPUT_SECTION (asm_out_file
, BSS_SECTION
);
9790 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BSS_END_LABEL
, 0);
9793 /* Output the source line correspondence table. */
9794 if (line_info_table_in_use
> 1 || separate_line_info_table_in_use
)
9796 fputc ('\n', asm_out_file
);
9797 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_LINE_SECTION
);
9798 output_line_info ();
9800 /* We can only use the low/high_pc attributes if all of the code
9802 if (separate_line_info_table_in_use
== 0)
9804 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, TEXT_SECTION
);
9805 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
9808 add_AT_section_offset (comp_unit_die
, DW_AT_stmt_list
, DEBUG_LINE_SECTION
);
9811 /* Output the abbreviation table. */
9812 fputc ('\n', asm_out_file
);
9813 ASM_OUTPUT_SECTION (asm_out_file
, ABBREV_SECTION
);
9814 build_abbrev_table (comp_unit_die
);
9815 output_abbrev_section ();
9817 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9818 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
9819 calc_die_sizes (comp_unit_die
);
9821 /* Output debugging information. */
9822 fputc ('\n', asm_out_file
);
9823 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_INFO_SECTION
);
9824 output_compilation_unit_header ();
9825 output_die (comp_unit_die
);
9827 if (pubname_table_in_use
)
9829 /* Output public names table. */
9830 fputc ('\n', asm_out_file
);
9831 ASM_OUTPUT_SECTION (asm_out_file
, PUBNAMES_SECTION
);
9835 if (fde_table_in_use
)
9837 /* Output the address range information. */
9838 fputc ('\n', asm_out_file
);
9839 ASM_OUTPUT_SECTION (asm_out_file
, ARANGES_SECTION
);
9843 #endif /* DWARF2_DEBUGGING_INFO */