1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997 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%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
389 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
393 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
394 fprintf ((FILE), "\t%s\t0x%x", 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
];
581 /* CCmode is arbitrarily given a size of 4 bytes. It is more useful
582 to use the same size as word_mode, since that reduces the number
583 of ranges we need. It should not matter, since the result should
584 never be used for a condition code register anyways. */
587 size
= GET_MODE_SIZE (mode
);
589 if (size
!= last_size
)
591 ranges
[n_ranges
].beg
= i
;
592 ranges
[n_ranges
].size
= last_size
= GET_MODE_SIZE (reg_raw_mode
[i
]);
597 ranges
[n_ranges
-1].end
= i
;
600 /* The usual case: fp regs surrounded by general regs. */
601 if (n_ranges
== 3 && ranges
[0].size
== ranges
[2].size
)
603 if ((DWARF_FRAME_REGNUM (ranges
[1].end
)
604 - DWARF_FRAME_REGNUM (ranges
[1].beg
))
605 != ranges
[1].end
- ranges
[1].beg
)
607 t
= fold (build (GE_EXPR
, integer_type_node
, reg_tree
,
608 build_int_2 (DWARF_FRAME_REGNUM (ranges
[1].beg
), 0)));
609 t2
= fold (build (LE_EXPR
, integer_type_node
, reg_tree
,
610 build_int_2 (DWARF_FRAME_REGNUM (ranges
[1].end
), 0)));
611 t
= fold (build (TRUTH_ANDIF_EXPR
, integer_type_node
, t
, t2
));
612 t
= fold (build (COND_EXPR
, integer_type_node
, t
,
613 build_int_2 (ranges
[1].size
, 0),
614 build_int_2 (ranges
[0].size
, 0)));
619 t
= build_int_2 (ranges
[n_ranges
].size
, 0);
620 size
= DWARF_FRAME_REGNUM (ranges
[n_ranges
].beg
);
623 if ((DWARF_FRAME_REGNUM (ranges
[n_ranges
].end
)
624 - DWARF_FRAME_REGNUM (ranges
[n_ranges
].beg
))
625 != ranges
[n_ranges
].end
- ranges
[n_ranges
].beg
)
627 if (DWARF_FRAME_REGNUM (ranges
[n_ranges
].beg
) >= size
)
629 size
= DWARF_FRAME_REGNUM (ranges
[n_ranges
].beg
);
630 t2
= fold (build (LE_EXPR
, integer_type_node
, reg_tree
,
631 build_int_2 (DWARF_FRAME_REGNUM
632 (ranges
[n_ranges
].end
), 0)));
633 t
= fold (build (COND_EXPR
, integer_type_node
, t2
,
634 build_int_2 (ranges
[n_ranges
].size
, 0), t
));
637 return expand_expr (t
, target
, Pmode
, 0);
640 /* Convert a DWARF call frame info. operation to its string name */
643 dwarf_cfi_name (cfi_opc
)
644 register unsigned cfi_opc
;
648 case DW_CFA_advance_loc
:
649 return "DW_CFA_advance_loc";
651 return "DW_CFA_offset";
653 return "DW_CFA_restore";
657 return "DW_CFA_set_loc";
658 case DW_CFA_advance_loc1
:
659 return "DW_CFA_advance_loc1";
660 case DW_CFA_advance_loc2
:
661 return "DW_CFA_advance_loc2";
662 case DW_CFA_advance_loc4
:
663 return "DW_CFA_advance_loc4";
664 case DW_CFA_offset_extended
:
665 return "DW_CFA_offset_extended";
666 case DW_CFA_restore_extended
:
667 return "DW_CFA_restore_extended";
668 case DW_CFA_undefined
:
669 return "DW_CFA_undefined";
670 case DW_CFA_same_value
:
671 return "DW_CFA_same_value";
672 case DW_CFA_register
:
673 return "DW_CFA_register";
674 case DW_CFA_remember_state
:
675 return "DW_CFA_remember_state";
676 case DW_CFA_restore_state
:
677 return "DW_CFA_restore_state";
679 return "DW_CFA_def_cfa";
680 case DW_CFA_def_cfa_register
:
681 return "DW_CFA_def_cfa_register";
682 case DW_CFA_def_cfa_offset
:
683 return "DW_CFA_def_cfa_offset";
685 /* SGI/MIPS specific */
686 case DW_CFA_MIPS_advance_loc8
:
687 return "DW_CFA_MIPS_advance_loc8";
690 case DW_CFA_GNU_window_save
:
691 return "DW_CFA_GNU_window_save";
692 case DW_CFA_GNU_args_size
:
693 return "DW_CFA_GNU_args_size";
696 return "DW_CFA_<unknown>";
700 /* Return a pointer to a newly allocated Call Frame Instruction. */
702 static inline dw_cfi_ref
705 register dw_cfi_ref cfi
= (dw_cfi_ref
) xmalloc (sizeof (dw_cfi_node
));
707 cfi
->dw_cfi_next
= NULL
;
708 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
709 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
714 /* Add a Call Frame Instruction to list of instructions. */
717 add_cfi (list_head
, cfi
)
718 register dw_cfi_ref
*list_head
;
719 register dw_cfi_ref cfi
;
721 register dw_cfi_ref
*p
;
723 /* Find the end of the chain. */
724 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
730 /* Generate a new label for the CFI info to refer to. */
733 dwarf2out_cfi_label ()
735 static char label
[20];
736 static unsigned long label_num
= 0;
738 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", label_num
++);
739 ASM_OUTPUT_LABEL (asm_out_file
, label
);
744 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
745 or to the CIE if LABEL is NULL. */
748 add_fde_cfi (label
, cfi
)
749 register char *label
;
750 register dw_cfi_ref cfi
;
754 register dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
757 label
= dwarf2out_cfi_label ();
759 if (fde
->dw_fde_current_label
== NULL
760 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
762 register dw_cfi_ref xcfi
;
764 fde
->dw_fde_current_label
= label
= xstrdup (label
);
766 /* Set the location counter to the new label. */
768 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
769 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
770 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
773 add_cfi (&fde
->dw_fde_cfi
, cfi
);
777 add_cfi (&cie_cfi_head
, cfi
);
780 /* Subroutine of lookup_cfa. */
783 lookup_cfa_1 (cfi
, regp
, offsetp
)
784 register dw_cfi_ref cfi
;
785 register unsigned long *regp
;
786 register long *offsetp
;
788 switch (cfi
->dw_cfi_opc
)
790 case DW_CFA_def_cfa_offset
:
791 *offsetp
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
793 case DW_CFA_def_cfa_register
:
794 *regp
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
797 *regp
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
798 *offsetp
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
805 /* Find the previous value for the CFA. */
808 lookup_cfa (regp
, offsetp
)
809 register unsigned long *regp
;
810 register long *offsetp
;
812 register dw_cfi_ref cfi
;
814 *regp
= (unsigned long) -1;
817 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
818 lookup_cfa_1 (cfi
, regp
, offsetp
);
820 if (fde_table_in_use
)
822 register dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
823 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
824 lookup_cfa_1 (cfi
, regp
, offsetp
);
828 /* The current rule for calculating the DWARF2 canonical frame address. */
829 static unsigned long cfa_reg
;
830 static long cfa_offset
;
832 /* The register used for saving registers to the stack, and its offset
834 static unsigned cfa_store_reg
;
835 static long cfa_store_offset
;
837 /* The running total of the size of arguments pushed onto the stack. */
838 static long args_size
;
840 /* Entry point to update the canonical frame address (CFA).
841 LABEL is passed to add_fde_cfi. The value of CFA is now to be
842 calculated from REG+OFFSET. */
845 dwarf2out_def_cfa (label
, reg
, offset
)
846 register char *label
;
847 register unsigned reg
;
848 register long offset
;
850 register dw_cfi_ref cfi
;
851 unsigned long old_reg
;
856 if (cfa_store_reg
== reg
)
857 cfa_store_offset
= offset
;
859 reg
= DWARF_FRAME_REGNUM (reg
);
860 lookup_cfa (&old_reg
, &old_offset
);
862 if (reg
== old_reg
&& offset
== old_offset
)
869 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
870 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= offset
;
873 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
874 else if (offset
== old_offset
&& old_reg
!= (unsigned long) -1)
876 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
877 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
883 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
884 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
885 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
888 add_fde_cfi (label
, cfi
);
891 /* Add the CFI for saving a register. REG is the CFA column number.
892 LABEL is passed to add_fde_cfi.
893 If SREG is -1, the register is saved at OFFSET from the CFA;
894 otherwise it is saved in SREG. */
897 reg_save (label
, reg
, sreg
, offset
)
898 register char * label
;
899 register unsigned reg
;
900 register unsigned sreg
;
901 register long offset
;
903 register dw_cfi_ref cfi
= new_cfi ();
905 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
910 /* The register number won't fit in 6 bits, so we have to use
912 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
914 cfi
->dw_cfi_opc
= DW_CFA_offset
;
916 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
919 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
923 cfi
->dw_cfi_opc
= DW_CFA_register
;
924 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
927 add_fde_cfi (label
, cfi
);
930 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
931 This CFI tells the unwinder that it needs to restore the window registers
932 from the previous frame's window save area.
934 ??? Perhaps we should note in the CIE where windows are saved (instead of
935 assuming 0(cfa)) and what registers are in the window. */
938 dwarf2out_window_save (label
)
939 register char * label
;
941 register dw_cfi_ref cfi
= new_cfi ();
942 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
943 add_fde_cfi (label
, cfi
);
946 /* Add a CFI to update the running total of the size of arguments
947 pushed onto the stack. */
950 dwarf2out_args_size (label
, size
)
954 register dw_cfi_ref cfi
= new_cfi ();
955 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
956 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
957 add_fde_cfi (label
, cfi
);
960 /* Entry point for saving a register to the stack. REG is the GCC register
961 number. LABEL and OFFSET are passed to reg_save. */
964 dwarf2out_reg_save (label
, reg
, offset
)
965 register char * label
;
966 register unsigned reg
;
967 register long offset
;
969 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
972 /* Entry point for saving the return address in the stack.
973 LABEL and OFFSET are passed to reg_save. */
976 dwarf2out_return_save (label
, offset
)
977 register char * label
;
978 register long offset
;
980 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, -1, offset
);
983 /* Entry point for saving the return address in a register.
984 LABEL and SREG are passed to reg_save. */
987 dwarf2out_return_reg (label
, sreg
)
988 register char * label
;
989 register unsigned sreg
;
991 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, sreg
, 0);
994 /* Record the initial position of the return address. RTL is
995 INCOMING_RETURN_ADDR_RTX. */
998 initial_return_save (rtl
)
1004 switch (GET_CODE (rtl
))
1007 /* RA is in a register. */
1008 reg
= reg_number (rtl
);
1011 /* RA is on the stack. */
1012 rtl
= XEXP (rtl
, 0);
1013 switch (GET_CODE (rtl
))
1016 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
1021 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
1023 offset
= INTVAL (XEXP (rtl
, 1));
1026 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
1028 offset
= -INTVAL (XEXP (rtl
, 1));
1035 /* The return address is at some offset from any value we can
1036 actually load. For instance, on the SPARC it is in %i7+8. Just
1037 ignore the offset for now; it doesn't matter for unwinding frames. */
1038 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
1040 initial_return_save (XEXP (rtl
, 0));
1046 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa_offset
);
1049 /* Check INSN to see if it looks like a push or a stack adjustment, and
1050 make a note of it if it does. EH uses this information to find out how
1051 much extra space it needs to pop off the stack. */
1054 dwarf2out_stack_adjust (insn
)
1060 if (GET_CODE (insn
) == BARRIER
)
1062 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1063 the compiler will have already emitted a stack adjustment, but
1064 doesn't bother for calls to noreturn functions. */
1065 #ifdef STACK_GROWS_DOWNWARD
1066 offset
= -args_size
;
1071 else if (GET_CODE (PATTERN (insn
)) == SET
)
1076 insn
= PATTERN (insn
);
1077 src
= SET_SRC (insn
);
1078 dest
= SET_DEST (insn
);
1080 if (dest
== stack_pointer_rtx
)
1082 /* (set (reg sp) (plus (reg sp) (const_int))) */
1083 code
= GET_CODE (src
);
1084 if (! (code
== PLUS
|| code
== MINUS
)
1085 || XEXP (src
, 0) != stack_pointer_rtx
1086 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1089 offset
= INTVAL (XEXP (src
, 1));
1091 else if (GET_CODE (dest
) == MEM
)
1093 /* (set (mem (pre_dec (reg sp))) (foo)) */
1094 src
= XEXP (dest
, 0);
1095 code
= GET_CODE (src
);
1097 if (! (code
== PRE_DEC
|| code
== PRE_INC
)
1098 || XEXP (src
, 0) != stack_pointer_rtx
)
1101 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1106 if (code
== PLUS
|| code
== PRE_INC
)
1115 if (cfa_reg
== STACK_POINTER_REGNUM
)
1116 cfa_offset
+= offset
;
1118 #ifndef STACK_GROWS_DOWNWARD
1121 args_size
+= offset
;
1125 label
= dwarf2out_cfi_label ();
1126 dwarf2out_def_cfa (label
, cfa_reg
, cfa_offset
);
1127 dwarf2out_args_size (label
, args_size
);
1130 /* Record call frame debugging information for INSN, which either
1131 sets SP or FP (adjusting how we calculate the frame address) or saves a
1132 register to the stack. If INSN is NULL_RTX, initialize our state. */
1135 dwarf2out_frame_debug (insn
)
1142 /* A temporary register used in adjusting SP or setting up the store_reg. */
1143 static unsigned cfa_temp_reg
;
1144 static long cfa_temp_value
;
1146 if (insn
== NULL_RTX
)
1148 /* Set up state for generating call frame debug info. */
1149 lookup_cfa (&cfa_reg
, &cfa_offset
);
1150 if (cfa_reg
!= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1152 cfa_reg
= STACK_POINTER_REGNUM
;
1153 cfa_store_reg
= cfa_reg
;
1154 cfa_store_offset
= cfa_offset
;
1160 if (! RTX_FRAME_RELATED_P (insn
))
1162 dwarf2out_stack_adjust (insn
);
1166 label
= dwarf2out_cfi_label ();
1168 insn
= PATTERN (insn
);
1169 /* Assume that in a PARALLEL prologue insn, only the first elt is
1170 significant. Currently this is true. */
1171 if (GET_CODE (insn
) == PARALLEL
)
1172 insn
= XVECEXP (insn
, 0, 0);
1173 if (GET_CODE (insn
) != SET
)
1176 src
= SET_SRC (insn
);
1177 dest
= SET_DEST (insn
);
1179 switch (GET_CODE (dest
))
1182 /* Update the CFA rule wrt SP or FP. Make sure src is
1183 relative to the current CFA register. */
1184 switch (GET_CODE (src
))
1186 /* Setting FP from SP. */
1188 if (cfa_reg
!= REGNO (src
))
1190 if (REGNO (dest
) != STACK_POINTER_REGNUM
1191 && !(frame_pointer_needed
1192 && REGNO (dest
) == HARD_FRAME_POINTER_REGNUM
))
1194 cfa_reg
= REGNO (dest
);
1199 if (dest
== stack_pointer_rtx
)
1202 switch (GET_CODE (XEXP (src
, 1)))
1205 offset
= INTVAL (XEXP (src
, 1));
1208 if (REGNO (XEXP (src
, 1)) != cfa_temp_reg
)
1210 offset
= cfa_temp_value
;
1216 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1218 /* Restoring SP from FP in the epilogue. */
1219 if (cfa_reg
!= HARD_FRAME_POINTER_REGNUM
)
1221 cfa_reg
= STACK_POINTER_REGNUM
;
1223 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1226 if (GET_CODE (src
) == PLUS
)
1228 if (cfa_reg
== STACK_POINTER_REGNUM
)
1229 cfa_offset
+= offset
;
1230 if (cfa_store_reg
== STACK_POINTER_REGNUM
)
1231 cfa_store_offset
+= offset
;
1233 else if (dest
== hard_frame_pointer_rtx
)
1235 /* Either setting the FP from an offset of the SP,
1236 or adjusting the FP */
1237 if (! frame_pointer_needed
1238 || REGNO (dest
) != HARD_FRAME_POINTER_REGNUM
)
1241 if (XEXP (src
, 0) == stack_pointer_rtx
1242 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1244 if (cfa_reg
!= STACK_POINTER_REGNUM
)
1246 offset
= INTVAL (XEXP (src
, 1));
1247 if (GET_CODE (src
) == PLUS
)
1249 cfa_offset
+= offset
;
1250 cfa_reg
= HARD_FRAME_POINTER_REGNUM
;
1252 else if (XEXP (src
, 0) == hard_frame_pointer_rtx
1253 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1255 if (cfa_reg
!= HARD_FRAME_POINTER_REGNUM
)
1257 offset
= INTVAL (XEXP (src
, 1));
1258 if (GET_CODE (src
) == PLUS
)
1260 cfa_offset
+= offset
;
1268 if (GET_CODE (src
) != PLUS
1269 || XEXP (src
, 1) != stack_pointer_rtx
)
1271 if (GET_CODE (XEXP (src
, 0)) != REG
1272 || REGNO (XEXP (src
, 0)) != cfa_temp_reg
)
1274 if (cfa_reg
!= STACK_POINTER_REGNUM
)
1276 cfa_store_reg
= REGNO (dest
);
1277 cfa_store_offset
= cfa_offset
- cfa_temp_value
;
1282 cfa_temp_reg
= REGNO (dest
);
1283 cfa_temp_value
= INTVAL (src
);
1287 if (GET_CODE (XEXP (src
, 0)) != REG
1288 || REGNO (XEXP (src
, 0)) != cfa_temp_reg
1289 || REGNO (dest
) != cfa_temp_reg
1290 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1292 cfa_temp_value
|= INTVAL (XEXP (src
, 1));
1298 dwarf2out_def_cfa (label
, cfa_reg
, cfa_offset
);
1302 /* Saving a register to the stack. Make sure dest is relative to the
1304 if (GET_CODE (src
) != REG
)
1306 switch (GET_CODE (XEXP (dest
, 0)))
1311 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1312 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1315 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1316 || cfa_store_reg
!= STACK_POINTER_REGNUM
)
1318 cfa_store_offset
+= offset
;
1319 if (cfa_reg
== STACK_POINTER_REGNUM
)
1320 cfa_offset
= cfa_store_offset
;
1322 offset
= -cfa_store_offset
;
1325 /* With an offset. */
1328 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1329 if (GET_CODE (src
) == MINUS
)
1332 if (cfa_store_reg
!= REGNO (XEXP (XEXP (dest
, 0), 0)))
1334 offset
-= cfa_store_offset
;
1340 dwarf2out_def_cfa (label
, cfa_reg
, cfa_offset
);
1341 dwarf2out_reg_save (label
, REGNO (src
), offset
);
1349 /* Return the size of an unsigned LEB128 quantity. */
1351 static inline unsigned long
1352 size_of_uleb128 (value
)
1353 register unsigned long value
;
1355 register unsigned long size
= 0;
1356 register unsigned byte
;
1360 byte
= (value
& 0x7f);
1369 /* Return the size of a signed LEB128 quantity. */
1371 static inline unsigned long
1372 size_of_sleb128 (value
)
1373 register long value
;
1375 register unsigned long size
= 0;
1376 register unsigned byte
;
1380 byte
= (value
& 0x7f);
1384 while (!(((value
== 0) && ((byte
& 0x40) == 0))
1385 || ((value
== -1) && ((byte
& 0x40) != 0))));
1390 /* Output an unsigned LEB128 quantity. */
1393 output_uleb128 (value
)
1394 register unsigned long value
;
1396 unsigned long save_value
= value
;
1398 fprintf (asm_out_file
, "\t%s\t", ASM_BYTE_OP
);
1401 register unsigned byte
= (value
& 0x7f);
1404 /* More bytes to follow. */
1407 fprintf (asm_out_file
, "0x%x", byte
);
1409 fprintf (asm_out_file
, ",");
1414 fprintf (asm_out_file
, "\t%s ULEB128 0x%x", ASM_COMMENT_START
, save_value
);
1417 /* Output an signed LEB128 quantity. */
1420 output_sleb128 (value
)
1421 register long value
;
1424 register unsigned byte
;
1425 long save_value
= value
;
1427 fprintf (asm_out_file
, "\t%s\t", ASM_BYTE_OP
);
1430 byte
= (value
& 0x7f);
1431 /* arithmetic shift */
1433 more
= !((((value
== 0) && ((byte
& 0x40) == 0))
1434 || ((value
== -1) && ((byte
& 0x40) != 0))));
1438 fprintf (asm_out_file
, "0x%x", byte
);
1440 fprintf (asm_out_file
, ",");
1445 fprintf (asm_out_file
, "\t%s SLEB128 %d", ASM_COMMENT_START
, save_value
);
1448 /* Output a Call Frame Information opcode and its operand(s). */
1451 output_cfi (cfi
, fde
)
1452 register dw_cfi_ref cfi
;
1453 register dw_fde_ref fde
;
1455 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1457 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
1459 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f));
1461 fprintf (asm_out_file
, "\t%s DW_CFA_advance_loc 0x%x",
1462 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1463 fputc ('\n', asm_out_file
);
1466 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1468 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
1470 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f));
1472 fprintf (asm_out_file
, "\t%s DW_CFA_offset, column 0x%x",
1473 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1475 fputc ('\n', asm_out_file
);
1476 output_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
1477 fputc ('\n', asm_out_file
);
1479 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1481 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
1483 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f));
1485 fprintf (asm_out_file
, "\t%s DW_CFA_restore, column 0x%x",
1486 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1488 fputc ('\n', asm_out_file
);
1492 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, cfi
->dw_cfi_opc
);
1494 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
,
1495 dwarf_cfi_name (cfi
->dw_cfi_opc
));
1497 fputc ('\n', asm_out_file
);
1498 switch (cfi
->dw_cfi_opc
)
1500 case DW_CFA_set_loc
:
1501 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
);
1502 fputc ('\n', asm_out_file
);
1504 case DW_CFA_advance_loc1
:
1505 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file
,
1506 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1507 fde
->dw_fde_current_label
);
1508 fputc ('\n', asm_out_file
);
1509 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1511 case DW_CFA_advance_loc2
:
1512 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
,
1513 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1514 fde
->dw_fde_current_label
);
1515 fputc ('\n', asm_out_file
);
1516 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1518 case DW_CFA_advance_loc4
:
1519 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
,
1520 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1521 fde
->dw_fde_current_label
);
1522 fputc ('\n', asm_out_file
);
1523 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1525 #ifdef MIPS_DEBUGGING_INFO
1526 case DW_CFA_MIPS_advance_loc8
:
1527 /* TODO: not currently implemented. */
1531 case DW_CFA_offset_extended
:
1532 case DW_CFA_def_cfa
:
1533 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1534 fputc ('\n', asm_out_file
);
1535 output_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
1536 fputc ('\n', asm_out_file
);
1538 case DW_CFA_restore_extended
:
1539 case DW_CFA_undefined
:
1540 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1541 fputc ('\n', asm_out_file
);
1543 case DW_CFA_same_value
:
1544 case DW_CFA_def_cfa_register
:
1545 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1546 fputc ('\n', asm_out_file
);
1548 case DW_CFA_register
:
1549 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1550 fputc ('\n', asm_out_file
);
1551 output_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
);
1552 fputc ('\n', asm_out_file
);
1554 case DW_CFA_def_cfa_offset
:
1555 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1556 fputc ('\n', asm_out_file
);
1558 case DW_CFA_GNU_window_save
:
1560 case DW_CFA_GNU_args_size
:
1561 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1562 fputc ('\n', asm_out_file
);
1570 #if !defined (EH_FRAME_SECTION)
1571 #if defined (EH_FRAME_SECTION_ASM_OP)
1572 #define EH_FRAME_SECTION() eh_frame_section();
1574 #if defined (ASM_OUTPUT_SECTION_NAME)
1575 #define EH_FRAME_SECTION() \
1577 named_section (NULL_TREE, ".eh_frame", 0); \
1583 /* Output the call frame information used to used to record information
1584 that relates to calculating the frame pointer, and records the
1585 location of saved registers. */
1588 output_call_frame_info (for_eh
)
1591 register unsigned long i
, j
;
1592 register dw_fde_ref fde
;
1593 register unsigned long fde_size
;
1594 register dw_cfi_ref cfi
;
1595 unsigned long fde_pad
;
1596 char l1
[20], l2
[20];
1597 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1601 /* Do we want to include a pointer to the exception table? */
1602 int eh_ptr
= for_eh
&& exception_table_p ();
1604 fputc ('\n', asm_out_file
);
1606 /* We're going to be generating comments, so turn on app. */
1612 #ifdef EH_FRAME_SECTION
1613 EH_FRAME_SECTION ();
1615 tree label
= get_file_function_name ('F');
1618 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
1619 ASM_GLOBALIZE_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
1620 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
1622 assemble_label ("__FRAME_BEGIN__");
1625 ASM_OUTPUT_SECTION (asm_out_file
, FRAME_SECTION
);
1627 /* Output the CIE. */
1628 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
1629 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
1630 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1631 ASM_GENERATE_INTERNAL_LABEL (ld
, CIE_LENGTH_LABEL
, for_eh
);
1633 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file
, ld
);
1635 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, ld
);
1638 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
, l2
, l1
);
1640 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, l2
, l1
);
1643 fprintf (asm_out_file
, "\t%s Length of Common Information Entry",
1646 fputc ('\n', asm_out_file
);
1647 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1650 /* Now that the CIE pointer is PC-relative for EH,
1651 use 0 to identify the CIE. */
1652 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 0);
1654 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, DW_CIE_ID
);
1657 fprintf (asm_out_file
, "\t%s CIE Identifier Tag", ASM_COMMENT_START
);
1659 fputc ('\n', asm_out_file
);
1660 if (! for_eh
&& DWARF_OFFSET_SIZE
== 8)
1662 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, DW_CIE_ID
);
1663 fputc ('\n', asm_out_file
);
1666 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_CIE_VERSION
);
1668 fprintf (asm_out_file
, "\t%s CIE Version", ASM_COMMENT_START
);
1670 fputc ('\n', asm_out_file
);
1673 /* The CIE contains a pointer to the exception region info for the
1674 frame. Make the augmentation string three bytes (including the
1675 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1676 can't handle unaligned relocs. */
1679 ASM_OUTPUT_DWARF_STRING (asm_out_file
, "eh");
1680 fprintf (asm_out_file
, "\t%s CIE Augmentation", ASM_COMMENT_START
);
1684 ASM_OUTPUT_ASCII (asm_out_file
, "eh", 3);
1686 fputc ('\n', asm_out_file
);
1688 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, "__EXCEPTION_TABLE__");
1690 fprintf (asm_out_file
, "\t%s pointer to exception region info",
1695 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
1697 fprintf (asm_out_file
, "\t%s CIE Augmentation (none)",
1701 fputc ('\n', asm_out_file
);
1704 fprintf (asm_out_file
, " (CIE Code Alignment Factor)");
1706 fputc ('\n', asm_out_file
);
1707 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT
);
1709 fprintf (asm_out_file
, " (CIE Data Alignment Factor)");
1711 fputc ('\n', asm_out_file
);
1712 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_FRAME_RETURN_COLUMN
);
1714 fprintf (asm_out_file
, "\t%s CIE RA Column", ASM_COMMENT_START
);
1716 fputc ('\n', asm_out_file
);
1718 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
1719 output_cfi (cfi
, NULL
);
1721 /* Pad the CIE out to an address sized boundary. */
1722 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
1723 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
1724 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1725 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file
, ld
, l2
, l1
);
1727 fprintf (asm_out_file
, "\t%s CIE Length Symbol", ASM_COMMENT_START
);
1728 fputc ('\n', asm_out_file
);
1731 /* Loop through all of the FDE's. */
1732 for (i
= 0; i
< fde_table_in_use
; ++i
)
1734 fde
= &fde_table
[i
];
1736 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
*2);
1737 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
*2);
1738 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1739 ASM_GENERATE_INTERNAL_LABEL (ld
, FDE_LENGTH_LABEL
, for_eh
+ i
*2);
1741 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file
, ld
);
1743 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, ld
);
1746 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
, l2
, l1
);
1748 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, l2
, l1
);
1751 fprintf (asm_out_file
, "\t%s FDE Length", ASM_COMMENT_START
);
1752 fputc ('\n', asm_out_file
);
1753 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1756 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, l1
, "__FRAME_BEGIN__");
1758 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, stripattributes (FRAME_SECTION
));
1760 fprintf (asm_out_file
, "\t%s FDE CIE offset", ASM_COMMENT_START
);
1762 fputc ('\n', asm_out_file
);
1763 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, fde
->dw_fde_begin
);
1765 fprintf (asm_out_file
, "\t%s FDE initial location", ASM_COMMENT_START
);
1767 fputc ('\n', asm_out_file
);
1768 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
,
1769 fde
->dw_fde_end
, fde
->dw_fde_begin
);
1771 fprintf (asm_out_file
, "\t%s FDE address range", ASM_COMMENT_START
);
1773 fputc ('\n', asm_out_file
);
1775 /* Loop through the Call Frame Instructions associated with
1777 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
1778 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
1779 output_cfi (cfi
, fde
);
1781 /* Pad the FDE out to an address sized boundary. */
1782 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
1783 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
1784 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1785 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file
, ld
, l2
, l1
);
1787 fprintf (asm_out_file
, "\t%s FDE Length Symbol", ASM_COMMENT_START
);
1788 fputc ('\n', asm_out_file
);
1791 #ifndef EH_FRAME_SECTION
1794 /* Emit terminating zero for table. */
1795 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 0);
1796 fputc ('\n', asm_out_file
);
1799 #ifdef MIPS_DEBUGGING_INFO
1800 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1801 get a value of 0. Putting .align 0 after the label fixes it. */
1802 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
1805 /* Turn off app to make assembly quicker. */
1810 /* Output a marker (i.e. a label) for the beginning of a function, before
1814 dwarf2out_begin_prologue ()
1816 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1817 register dw_fde_ref fde
;
1819 ++current_funcdef_number
;
1821 function_section (current_function_decl
);
1822 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1823 current_funcdef_number
);
1824 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1826 /* Expand the fde table if necessary. */
1827 if (fde_table_in_use
== fde_table_allocated
)
1829 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
1831 = (dw_fde_ref
) xrealloc (fde_table
,
1832 fde_table_allocated
* sizeof (dw_fde_node
));
1835 /* Record the FDE associated with this function. */
1836 current_funcdef_fde
= fde_table_in_use
;
1838 /* Add the new FDE at the end of the fde_table. */
1839 fde
= &fde_table
[fde_table_in_use
++];
1840 fde
->dw_fde_begin
= xstrdup (label
);
1841 fde
->dw_fde_current_label
= NULL
;
1842 fde
->dw_fde_end
= NULL
;
1843 fde
->dw_fde_cfi
= NULL
;
1848 /* Output a marker (i.e. a label) for the absolute end of the generated code
1849 for a function definition. This gets called *after* the epilogue code has
1853 dwarf2out_end_epilogue ()
1856 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1858 /* Output a label to mark the endpoint of the code generated for this
1860 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
, current_funcdef_number
);
1861 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1862 fde
= &fde_table
[fde_table_in_use
- 1];
1863 fde
->dw_fde_end
= xstrdup (label
);
1867 dwarf2out_frame_init ()
1869 /* Allocate the initial hunk of the fde_table. */
1871 = (dw_fde_ref
) xmalloc (FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
1872 bzero ((char *) fde_table
, FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
1873 fde_table_allocated
= FDE_TABLE_INCREMENT
;
1874 fde_table_in_use
= 0;
1876 /* Generate the CFA instructions common to all FDE's. Do it now for the
1877 sake of lookup_cfa. */
1879 #ifdef DWARF2_UNWIND_INFO
1880 /* On entry, the Canonical Frame Address is at SP. */
1881 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
1882 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
1887 dwarf2out_frame_finish ()
1889 /* Output call frame information. */
1890 #ifdef MIPS_DEBUGGING_INFO
1891 if (write_symbols
== DWARF2_DEBUG
)
1892 output_call_frame_info (0);
1893 if (flag_exceptions
&& ! exceptions_via_longjmp
)
1894 output_call_frame_info (1);
1896 if (write_symbols
== DWARF2_DEBUG
1897 || (flag_exceptions
&& ! exceptions_via_longjmp
))
1898 output_call_frame_info (1);
1902 #endif /* .debug_frame support */
1904 /* And now, the support for symbolic debugging information. */
1905 #ifdef DWARF2_DEBUGGING_INFO
1907 extern char *getpwd ();
1909 /* NOTE: In the comments in this file, many references are made to
1910 "Debugging Information Entries". This term is abbreviated as `DIE'
1911 throughout the remainder of this file. */
1913 /* An internal representation of the DWARF output is built, and then
1914 walked to generate the DWARF debugging info. The walk of the internal
1915 representation is done after the entire program has been compiled.
1916 The types below are used to describe the internal representation. */
1918 /* Each DIE may have a series of attribute/value pairs. Values
1919 can take on several forms. The forms that are used in this
1920 implementation are listed below. */
1927 dw_val_class_unsigned_const
,
1928 dw_val_class_long_long
,
1931 dw_val_class_die_ref
,
1932 dw_val_class_fde_ref
,
1933 dw_val_class_lbl_id
,
1934 dw_val_class_section_offset
,
1939 /* Various DIE's use offsets relative to the beginning of the
1940 .debug_info section to refer to each other. */
1942 typedef long int dw_offset
;
1944 /* Define typedefs here to avoid circular dependencies. */
1946 typedef struct die_struct
*dw_die_ref
;
1947 typedef struct dw_attr_struct
*dw_attr_ref
;
1948 typedef struct dw_val_struct
*dw_val_ref
;
1949 typedef struct dw_line_info_struct
*dw_line_info_ref
;
1950 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
1951 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
1952 typedef struct pubname_struct
*pubname_ref
;
1953 typedef dw_die_ref
*arange_ref
;
1955 /* Describe a double word constant value. */
1957 typedef struct dw_long_long_struct
1964 /* Describe a floating point constant value. */
1966 typedef struct dw_fp_struct
1973 /* Each entry in the line_info_table maintains the file and
1974 line number associated with the label generated for that
1975 entry. The label gives the PC value associated with
1976 the line number entry. */
1978 typedef struct dw_line_info_struct
1980 unsigned long dw_file_num
;
1981 unsigned long dw_line_num
;
1985 /* Line information for functions in separate sections; each one gets its
1987 typedef struct dw_separate_line_info_struct
1989 unsigned long dw_file_num
;
1990 unsigned long dw_line_num
;
1991 unsigned long function
;
1993 dw_separate_line_info_entry
;
1995 /* The dw_val_node describes an attribute's value, as it is
1996 represented internally. */
1998 typedef struct dw_val_struct
2000 dw_val_class val_class
;
2004 dw_loc_descr_ref val_loc
;
2006 long unsigned val_unsigned
;
2007 dw_long_long_const val_long_long
;
2008 dw_float_const val_float
;
2009 dw_die_ref val_die_ref
;
2010 unsigned val_fde_index
;
2014 unsigned char val_flag
;
2020 /* Locations in memory are described using a sequence of stack machine
2023 typedef struct dw_loc_descr_struct
2025 dw_loc_descr_ref dw_loc_next
;
2026 enum dwarf_location_atom dw_loc_opc
;
2027 dw_val_node dw_loc_oprnd1
;
2028 dw_val_node dw_loc_oprnd2
;
2032 /* Each DIE attribute has a field specifying the attribute kind,
2033 a link to the next attribute in the chain, and an attribute value.
2034 Attributes are typically linked below the DIE they modify. */
2036 typedef struct dw_attr_struct
2038 enum dwarf_attribute dw_attr
;
2039 dw_attr_ref dw_attr_next
;
2040 dw_val_node dw_attr_val
;
2044 /* The Debugging Information Entry (DIE) structure */
2046 typedef struct die_struct
2048 enum dwarf_tag die_tag
;
2049 dw_attr_ref die_attr
;
2050 dw_attr_ref die_attr_last
;
2051 dw_die_ref die_parent
;
2052 dw_die_ref die_child
;
2053 dw_die_ref die_child_last
;
2055 dw_offset die_offset
;
2056 unsigned long die_abbrev
;
2060 /* The pubname structure */
2062 typedef struct pubname_struct
2069 /* The limbo die list structure. */
2070 typedef struct limbo_die_struct
2073 struct limbo_die_struct
*next
;
2077 /* How to start an assembler comment. */
2078 #ifndef ASM_COMMENT_START
2079 #define ASM_COMMENT_START ";#"
2082 /* Define a macro which returns non-zero for a TYPE_DECL which was
2083 implicitly generated for a tagged type.
2085 Note that unlike the gcc front end (which generates a NULL named
2086 TYPE_DECL node for each complete tagged type, each array type, and
2087 each function type node created) the g++ front end generates a
2088 _named_ TYPE_DECL node for each tagged type node created.
2089 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2090 generate a DW_TAG_typedef DIE for them. */
2092 #define TYPE_DECL_IS_STUB(decl) \
2093 (DECL_NAME (decl) == NULL_TREE \
2094 || (DECL_ARTIFICIAL (decl) \
2095 && is_tagged_type (TREE_TYPE (decl)) \
2096 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2097 /* This is necessary for stub decls that \
2098 appear in nested inline functions. */ \
2099 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2100 && (decl_ultimate_origin (decl) \
2101 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2103 /* Information concerning the compilation unit's programming
2104 language, and compiler version. */
2106 extern int flag_traditional
;
2107 extern char *version_string
;
2108 extern char *language_string
;
2110 /* Fixed size portion of the DWARF compilation unit header. */
2111 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2113 /* Fixed size portion of debugging line information prolog. */
2114 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2116 /* Fixed size portion of public names info. */
2117 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2119 /* Fixed size portion of the address range info. */
2120 #define DWARF_ARANGES_HEADER_SIZE \
2121 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
2123 /* Define the architecture-dependent minimum instruction length (in bytes).
2124 In this implementation of DWARF, this field is used for information
2125 purposes only. Since GCC generates assembly language, we have
2126 no a priori knowledge of how many instruction bytes are generated
2127 for each source line, and therefore can use only the DW_LNE_set_address
2128 and DW_LNS_fixed_advance_pc line information commands. */
2130 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2131 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2134 /* Minimum line offset in a special line info. opcode.
2135 This value was chosen to give a reasonable range of values. */
2136 #define DWARF_LINE_BASE -10
2138 /* First special line opcde - leave room for the standard opcodes. */
2139 #define DWARF_LINE_OPCODE_BASE 10
2141 /* Range of line offsets in a special line info. opcode. */
2142 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2144 /* Flag that indicates the initial value of the is_stmt_start flag.
2145 In the present implementation, we do not mark any lines as
2146 the beginning of a source statement, because that information
2147 is not made available by the GCC front-end. */
2148 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2150 /* This location is used by calc_die_sizes() to keep track
2151 the offset of each DIE within the .debug_info section. */
2152 static unsigned long next_die_offset
;
2154 /* Record the root of the DIE's built for the current compilation unit. */
2155 static dw_die_ref comp_unit_die
;
2157 /* A list of DIEs with a NULL parent waiting to be relocated. */
2158 static limbo_die_node
*limbo_die_list
= 0;
2160 /* Pointer to an array of filenames referenced by this compilation unit. */
2161 static char **file_table
;
2163 /* Total number of entries in the table (i.e. array) pointed to by
2164 `file_table'. This is the *total* and includes both used and unused
2166 static unsigned file_table_allocated
;
2168 /* Number of entries in the file_table which are actually in use. */
2169 static unsigned file_table_in_use
;
2171 /* Size (in elements) of increments by which we may expand the filename
2173 #define FILE_TABLE_INCREMENT 64
2175 /* Local pointer to the name of the main input file. Initialized in
2177 static char *primary_filename
;
2179 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
2180 which their beginnings are encountered. We output Dwarf debugging info
2181 that refers to the beginnings and ends of the ranges of code for each
2182 lexical block. The labels themselves are generated in final.c, which
2183 assigns numbers to the blocks in the same way. */
2184 static unsigned next_block_number
= 2;
2186 /* A pointer to the base of a table of references to DIE's that describe
2187 declarations. The table is indexed by DECL_UID() which is a unique
2188 number identifying each decl. */
2189 static dw_die_ref
*decl_die_table
;
2191 /* Number of elements currently allocated for the decl_die_table. */
2192 static unsigned decl_die_table_allocated
;
2194 /* Number of elements in decl_die_table currently in use. */
2195 static unsigned decl_die_table_in_use
;
2197 /* Size (in elements) of increments by which we may expand the
2199 #define DECL_DIE_TABLE_INCREMENT 256
2201 /* A pointer to the base of a table of references to declaration
2202 scopes. This table is a display which tracks the nesting
2203 of declaration scopes at the current scope and containing
2204 scopes. This table is used to find the proper place to
2205 define type declaration DIE's. */
2206 static tree
*decl_scope_table
;
2208 /* Number of elements currently allocated for the decl_scope_table. */
2209 static unsigned decl_scope_table_allocated
;
2211 /* Current level of nesting of declaration scopes. */
2212 static unsigned decl_scope_depth
;
2214 /* Size (in elements) of increments by which we may expand the
2215 decl_scope_table. */
2216 #define DECL_SCOPE_TABLE_INCREMENT 64
2218 /* A pointer to the base of a list of references to DIE's that
2219 are uniquely identified by their tag, presence/absence of
2220 children DIE's, and list of attribute/value pairs. */
2221 static dw_die_ref
*abbrev_die_table
;
2223 /* Number of elements currently allocated for abbrev_die_table. */
2224 static unsigned abbrev_die_table_allocated
;
2226 /* Number of elements in type_die_table currently in use. */
2227 static unsigned abbrev_die_table_in_use
;
2229 /* Size (in elements) of increments by which we may expand the
2230 abbrev_die_table. */
2231 #define ABBREV_DIE_TABLE_INCREMENT 256
2233 /* A pointer to the base of a table that contains line information
2234 for each source code line in .text in the compilation unit. */
2235 static dw_line_info_ref line_info_table
;
2237 /* Number of elements currently allocated for line_info_table. */
2238 static unsigned line_info_table_allocated
;
2240 /* Number of elements in separate_line_info_table currently in use. */
2241 static unsigned separate_line_info_table_in_use
;
2243 /* A pointer to the base of a table that contains line information
2244 for each source code line outside of .text in the compilation unit. */
2245 static dw_separate_line_info_ref separate_line_info_table
;
2247 /* Number of elements currently allocated for separate_line_info_table. */
2248 static unsigned separate_line_info_table_allocated
;
2250 /* Number of elements in line_info_table currently in use. */
2251 static unsigned line_info_table_in_use
;
2253 /* Size (in elements) of increments by which we may expand the
2255 #define LINE_INFO_TABLE_INCREMENT 1024
2257 /* A pointer to the base of a table that contains a list of publicly
2258 accessible names. */
2259 static pubname_ref pubname_table
;
2261 /* Number of elements currently allocated for pubname_table. */
2262 static unsigned pubname_table_allocated
;
2264 /* Number of elements in pubname_table currently in use. */
2265 static unsigned pubname_table_in_use
;
2267 /* Size (in elements) of increments by which we may expand the
2269 #define PUBNAME_TABLE_INCREMENT 64
2271 /* A pointer to the base of a table that contains a list of publicly
2272 accessible names. */
2273 static arange_ref arange_table
;
2275 /* Number of elements currently allocated for arange_table. */
2276 static unsigned arange_table_allocated
;
2278 /* Number of elements in arange_table currently in use. */
2279 static unsigned arange_table_in_use
;
2281 /* Size (in elements) of increments by which we may expand the
2283 #define ARANGE_TABLE_INCREMENT 64
2285 /* A pointer to the base of a list of pending types which we haven't
2286 generated DIEs for yet, but which we will have to come back to
2289 static tree
*pending_types_list
;
2291 /* Number of elements currently allocated for the pending_types_list. */
2292 static unsigned pending_types_allocated
;
2294 /* Number of elements of pending_types_list currently in use. */
2295 static unsigned pending_types
;
2297 /* Size (in elements) of increments by which we may expand the pending
2298 types list. Actually, a single hunk of space of this size should
2299 be enough for most typical programs. */
2300 #define PENDING_TYPES_INCREMENT 64
2302 /* Record whether the function being analyzed contains inlined functions. */
2303 static int current_function_has_inlines
;
2304 static int comp_unit_has_inlines
;
2306 /* A pointer to the ..._DECL node which we have most recently been working
2307 on. We keep this around just in case something about it looks screwy and
2308 we want to tell the user what the source coordinates for the actual
2310 static tree dwarf_last_decl
;
2312 /* Forward declarations for functions defined in this file. */
2314 static void addr_const_to_string
PROTO((char *, rtx
));
2315 static char *addr_to_string
PROTO((rtx
));
2316 static int is_pseudo_reg
PROTO((rtx
));
2317 static tree type_main_variant
PROTO((tree
));
2318 static int is_tagged_type
PROTO((tree
));
2319 static char *dwarf_tag_name
PROTO((unsigned));
2320 static char *dwarf_attr_name
PROTO((unsigned));
2321 static char *dwarf_form_name
PROTO((unsigned));
2322 static char *dwarf_stack_op_name
PROTO((unsigned));
2323 static char *dwarf_type_encoding_name
PROTO((unsigned));
2324 static tree decl_ultimate_origin
PROTO((tree
));
2325 static tree block_ultimate_origin
PROTO((tree
));
2326 static tree decl_class_context
PROTO((tree
));
2327 static void add_dwarf_attr
PROTO((dw_die_ref
, dw_attr_ref
));
2328 static void add_AT_flag
PROTO((dw_die_ref
,
2329 enum dwarf_attribute
,
2331 static void add_AT_int
PROTO((dw_die_ref
,
2332 enum dwarf_attribute
, long));
2333 static void add_AT_unsigned
PROTO((dw_die_ref
,
2334 enum dwarf_attribute
,
2336 static void add_AT_long_long
PROTO((dw_die_ref
,
2337 enum dwarf_attribute
,
2338 unsigned long, unsigned long));
2339 static void add_AT_float
PROTO((dw_die_ref
,
2340 enum dwarf_attribute
,
2342 static void add_AT_string
PROTO((dw_die_ref
,
2343 enum dwarf_attribute
, char *));
2344 static void add_AT_die_ref
PROTO((dw_die_ref
,
2345 enum dwarf_attribute
,
2347 static void add_AT_fde_ref
PROTO((dw_die_ref
,
2348 enum dwarf_attribute
,
2350 static void add_AT_loc
PROTO((dw_die_ref
,
2351 enum dwarf_attribute
,
2353 static void add_AT_addr
PROTO((dw_die_ref
,
2354 enum dwarf_attribute
, char *));
2355 static void add_AT_lbl_id
PROTO((dw_die_ref
,
2356 enum dwarf_attribute
, char *));
2357 static void add_AT_section_offset
PROTO((dw_die_ref
,
2358 enum dwarf_attribute
, char *));
2359 static int is_extern_subr_die
PROTO((dw_die_ref
));
2360 static dw_attr_ref get_AT
PROTO((dw_die_ref
,
2361 enum dwarf_attribute
));
2362 static char *get_AT_low_pc
PROTO((dw_die_ref
));
2363 static char *get_AT_hi_pc
PROTO((dw_die_ref
));
2364 static char *get_AT_string
PROTO((dw_die_ref
,
2365 enum dwarf_attribute
));
2366 static int get_AT_flag
PROTO((dw_die_ref
,
2367 enum dwarf_attribute
));
2368 static unsigned get_AT_unsigned
PROTO((dw_die_ref
,
2369 enum dwarf_attribute
));
2370 static int is_c_family
PROTO((void));
2371 static int is_fortran
PROTO((void));
2372 static void remove_AT
PROTO((dw_die_ref
,
2373 enum dwarf_attribute
));
2374 static void remove_children
PROTO((dw_die_ref
));
2375 static void add_child_die
PROTO((dw_die_ref
, dw_die_ref
));
2376 static dw_die_ref new_die
PROTO((enum dwarf_tag
, dw_die_ref
));
2377 static dw_die_ref lookup_type_die
PROTO((tree
));
2378 static void equate_type_number_to_die
PROTO((tree
, dw_die_ref
));
2379 static dw_die_ref lookup_decl_die
PROTO((tree
));
2380 static void equate_decl_number_to_die
PROTO((tree
, dw_die_ref
));
2381 static dw_loc_descr_ref new_loc_descr
PROTO((enum dwarf_location_atom
,
2382 unsigned long, unsigned long));
2383 static void add_loc_descr
PROTO((dw_loc_descr_ref
*,
2385 static void print_spaces
PROTO((FILE *));
2386 static void print_die
PROTO((dw_die_ref
, FILE *));
2387 static void print_dwarf_line_table
PROTO((FILE *));
2388 static void add_sibling_attributes
PROTO((dw_die_ref
));
2389 static void build_abbrev_table
PROTO((dw_die_ref
));
2390 static unsigned long size_of_string
PROTO((char *));
2391 static unsigned long size_of_loc_descr
PROTO((dw_loc_descr_ref
));
2392 static unsigned long size_of_locs
PROTO((dw_loc_descr_ref
));
2393 static int constant_size
PROTO((long unsigned));
2394 static unsigned long size_of_die
PROTO((dw_die_ref
));
2395 static void calc_die_sizes
PROTO((dw_die_ref
));
2396 static unsigned long size_of_prolog
PROTO((void));
2397 static unsigned long size_of_line_info
PROTO((void));
2398 static unsigned long size_of_pubnames
PROTO((void));
2399 static unsigned long size_of_aranges
PROTO((void));
2400 static enum dwarf_form value_format
PROTO((dw_val_ref
));
2401 static void output_value_format
PROTO((dw_val_ref
));
2402 static void output_abbrev_section
PROTO((void));
2403 static void output_loc_operands
PROTO((dw_loc_descr_ref
));
2404 static unsigned long sibling_offset
PROTO((dw_die_ref
));
2405 static void output_die
PROTO((dw_die_ref
));
2406 static void output_compilation_unit_header
PROTO((void));
2407 static char *dwarf2_name
PROTO((tree
, int));
2408 static void add_pubname
PROTO((tree
, dw_die_ref
));
2409 static void output_pubnames
PROTO((void));
2410 static void add_arrange
PROTO((tree
, dw_die_ref
));
2411 static void output_arranges
PROTO((void));
2412 static void output_line_info
PROTO((void));
2413 static int is_body_block
PROTO((tree
));
2414 static dw_die_ref base_type_die
PROTO((tree
));
2415 static tree root_type
PROTO((tree
));
2416 static int is_base_type
PROTO((tree
));
2417 static dw_die_ref modified_type_die
PROTO((tree
, int, int, dw_die_ref
));
2418 static int type_is_enum
PROTO((tree
));
2419 static dw_loc_descr_ref reg_loc_descriptor
PROTO((rtx
));
2420 static dw_loc_descr_ref based_loc_descr
PROTO((unsigned, long));
2421 static int is_based_loc
PROTO((rtx
));
2422 static dw_loc_descr_ref mem_loc_descriptor
PROTO((rtx
));
2423 static dw_loc_descr_ref concat_loc_descriptor
PROTO((rtx
, rtx
));
2424 static dw_loc_descr_ref loc_descriptor
PROTO((rtx
));
2425 static unsigned ceiling
PROTO((unsigned, unsigned));
2426 static tree field_type
PROTO((tree
));
2427 static unsigned simple_type_align_in_bits
PROTO((tree
));
2428 static unsigned simple_type_size_in_bits
PROTO((tree
));
2429 static unsigned field_byte_offset
PROTO((tree
));
2430 static void add_AT_location_description
PROTO((dw_die_ref
,
2431 enum dwarf_attribute
, rtx
));
2432 static void add_data_member_location_attribute
PROTO((dw_die_ref
, tree
));
2433 static void add_const_value_attribute
PROTO((dw_die_ref
, rtx
));
2434 static void add_location_or_const_value_attribute
PROTO((dw_die_ref
, tree
));
2435 static void add_name_attribute
PROTO((dw_die_ref
, char *));
2436 static void add_bound_info
PROTO((dw_die_ref
,
2437 enum dwarf_attribute
, tree
));
2438 static void add_subscript_info
PROTO((dw_die_ref
, tree
));
2439 static void add_byte_size_attribute
PROTO((dw_die_ref
, tree
));
2440 static void add_bit_offset_attribute
PROTO((dw_die_ref
, tree
));
2441 static void add_bit_size_attribute
PROTO((dw_die_ref
, tree
));
2442 static void add_prototyped_attribute
PROTO((dw_die_ref
, tree
));
2443 static void add_abstract_origin_attribute
PROTO((dw_die_ref
, tree
));
2444 static void add_pure_or_virtual_attribute
PROTO((dw_die_ref
, tree
));
2445 static void add_src_coords_attributes
PROTO((dw_die_ref
, tree
));
2446 static void ad_name_and_src_coords_attributes
PROTO((dw_die_ref
, tree
));
2447 static void push_decl_scope
PROTO((tree
));
2448 static dw_die_ref scope_die_for
PROTO((tree
, dw_die_ref
));
2449 static void pop_decl_scope
PROTO((void));
2450 static void add_type_attribute
PROTO((dw_die_ref
, tree
, int, int,
2452 static char *type_tag
PROTO((tree
));
2453 static tree member_declared_type
PROTO((tree
));
2454 static char *decl_start_label
PROTO((tree
));
2455 static void gen_arrqay_type_die
PROTO((tree
, dw_die_ref
));
2456 static void gen_set_type_die
PROTO((tree
, dw_die_ref
));
2457 static void gen_entry_point_die
PROTO((tree
, dw_die_ref
));
2458 static void pend_type
PROTO((tree
));
2459 static void output_pending_types_for_scope
PROTO((dw_die_ref
));
2460 static void gen_inlined_enumeration_type_die
PROTO((tree
, dw_die_ref
));
2461 static void gen_inlined_structure_type_die
PROTO((tree
, dw_die_ref
));
2462 static void gen_inlined_union_type_die
PROTO((tree
, dw_die_ref
));
2463 static void gen_enumeration_type_die
PROTO((tree
, dw_die_ref
));
2464 static dw_die_ref gen_formal_parameter_die
PROTO((tree
, dw_die_ref
));
2465 static void gen_unspecified_parameters_die
PROTO((tree
, dw_die_ref
));
2466 static void gen_formal_types_die
PROTO((tree
, dw_die_ref
));
2467 static void gen_subprogram_die
PROTO((tree
, dw_die_ref
));
2468 static void gen_variable_die
PROTO((tree
, dw_die_ref
));
2469 static void gen_label_die
PROTO((tree
, dw_die_ref
));
2470 static void gen_lexical_block_die
PROTO((tree
, dw_die_ref
, int));
2471 static void gen_inlined_subprogram_die
PROTO((tree
, dw_die_ref
, int));
2472 static void gen_field_die
PROTO((tree
, dw_die_ref
));
2473 static void gen_ptr_to_mbr_type_die
PROTO((tree
, dw_die_ref
));
2474 static void gen_compile_unit_die
PROTO((char *));
2475 static void gen_string_type_die
PROTO((tree
, dw_die_ref
));
2476 static void gen_inheritance_die
PROTO((tree
, dw_die_ref
));
2477 static void gen_member_die
PROTO((tree
, dw_die_ref
));
2478 static void gen_struct_or_union_type_die
PROTO((tree
, dw_die_ref
));
2479 static void gen_subroutine_type_die
PROTO((tree
, dw_die_ref
));
2480 static void gen_typedef_die
PROTO((tree
, dw_die_ref
));
2481 static void gen_type_die
PROTO((tree
, dw_die_ref
));
2482 static void gen_tagged_type_instantiation_die
PROTO((tree
, dw_die_ref
));
2483 static void gen_block_die
PROTO((tree
, dw_die_ref
, int));
2484 static void decls_for_scope
PROTO((tree
, dw_die_ref
, int));
2485 static int is_redundant_typedef
PROTO((tree
));
2486 static void gen_decl_die
PROTO((tree
, dw_die_ref
));
2487 static unsigned lookup_filename
PROTO((char *));
2489 /* Section names used to hold DWARF debugging information. */
2490 #ifndef DEBUG_INFO_SECTION
2491 #define DEBUG_INFO_SECTION ".debug_info"
2493 #ifndef ABBREV_SECTION
2494 #define ABBREV_SECTION ".debug_abbrev"
2496 #ifndef ARANGES_SECTION
2497 #define ARANGES_SECTION ".debug_aranges"
2499 #ifndef DW_MACINFO_SECTION
2500 #define DW_MACINFO_SECTION ".debug_macinfo"
2502 #ifndef DEBUG_LINE_SECTION
2503 #define DEBUG_LINE_SECTION ".debug_line"
2506 #define LOC_SECTION ".debug_loc"
2508 #ifndef PUBNAMES_SECTION
2509 #define PUBNAMES_SECTION ".debug_pubnames"
2512 #define STR_SECTION ".debug_str"
2515 /* Standard ELF section names for compiled code and data. */
2516 #ifndef TEXT_SECTION
2517 #define TEXT_SECTION ".text"
2519 #ifndef DATA_SECTION
2520 #define DATA_SECTION ".data"
2523 #define BSS_SECTION ".bss"
2527 /* Definitions of defaults for formats and names of various special
2528 (artificial) labels which may be generated within this file (when the -g
2529 options is used and DWARF_DEBUGGING_INFO is in effect.
2530 If necessary, these may be overridden from within the tm.h file, but
2531 typically, overriding these defaults is unnecessary. */
2533 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2535 #ifndef TEXT_END_LABEL
2536 #define TEXT_END_LABEL "Letext"
2538 #ifndef DATA_END_LABEL
2539 #define DATA_END_LABEL "Ledata"
2541 #ifndef BSS_END_LABEL
2542 #define BSS_END_LABEL "Lebss"
2544 #ifndef INSN_LABEL_FMT
2545 #define INSN_LABEL_FMT "LI%u_"
2547 #ifndef BLOCK_BEGIN_LABEL
2548 #define BLOCK_BEGIN_LABEL "LBB"
2550 #ifndef BLOCK_END_LABEL
2551 #define BLOCK_END_LABEL "LBE"
2553 #ifndef BODY_BEGIN_LABEL
2554 #define BODY_BEGIN_LABEL "Lbb"
2556 #ifndef BODY_END_LABEL
2557 #define BODY_END_LABEL "Lbe"
2559 #ifndef LINE_CODE_LABEL
2560 #define LINE_CODE_LABEL "LM"
2562 #ifndef SEPARATE_LINE_CODE_LABEL
2563 #define SEPARATE_LINE_CODE_LABEL "LSM"
2566 /* Convert a reference to the assembler name of a C-level name. This
2567 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
2568 a string rather than writing to a file. */
2569 #ifndef ASM_NAME_TO_STRING
2570 #define ASM_NAME_TO_STRING(STR, NAME) \
2572 if ((NAME)[0] == '*') \
2573 strcpy (STR, NAME+1); \
2575 strcpy (STR, NAME); \
2580 /* Convert an integer constant expression into assembler syntax. Addition
2581 and subtraction are the only arithmetic that may appear in these
2582 expressions. This is an adaptation of output_addr_const in final.c.
2583 Here, the target of the conversion is a string buffer. We can't use
2584 output_addr_const directly, because it writes to a file. */
2587 addr_const_to_string (str
, x
)
2596 switch (GET_CODE (x
))
2606 ASM_NAME_TO_STRING (buf1
, XSTR (x
, 0));
2611 ASM_GENERATE_INTERNAL_LABEL (buf1
, "L", CODE_LABEL_NUMBER (XEXP (x
, 0)));
2612 ASM_NAME_TO_STRING (buf2
, buf1
);
2617 ASM_GENERATE_INTERNAL_LABEL (buf1
, "L", CODE_LABEL_NUMBER (x
));
2618 ASM_NAME_TO_STRING (buf2
, buf1
);
2623 sprintf (buf1
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
));
2628 /* This used to output parentheses around the expression, but that does
2629 not work on the 386 (either ATT or BSD assembler). */
2630 addr_const_to_string (buf1
, XEXP (x
, 0));
2635 if (GET_MODE (x
) == VOIDmode
)
2637 /* We can use %d if the number is one word and positive. */
2638 if (CONST_DOUBLE_HIGH (x
))
2639 sprintf (buf1
, HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
2640 CONST_DOUBLE_HIGH (x
), CONST_DOUBLE_LOW (x
));
2641 else if (CONST_DOUBLE_LOW (x
) < 0)
2642 sprintf (buf1
, HOST_WIDE_INT_PRINT_HEX
, CONST_DOUBLE_LOW (x
));
2644 sprintf (buf1
, HOST_WIDE_INT_PRINT_DEC
,
2645 CONST_DOUBLE_LOW (x
));
2649 /* We can't handle floating point constants; PRINT_OPERAND must
2651 output_operand_lossage ("floating constant misused");
2655 /* Some assemblers need integer constants to appear last (eg masm). */
2656 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
2658 addr_const_to_string (buf1
, XEXP (x
, 1));
2660 if (INTVAL (XEXP (x
, 0)) >= 0)
2663 addr_const_to_string (buf1
, XEXP (x
, 0));
2668 addr_const_to_string (buf1
, XEXP (x
, 0));
2670 if (INTVAL (XEXP (x
, 1)) >= 0)
2673 addr_const_to_string (buf1
, XEXP (x
, 1));
2679 /* Avoid outputting things like x-x or x+5-x, since some assemblers
2680 can't handle that. */
2681 x
= simplify_subtraction (x
);
2682 if (GET_CODE (x
) != MINUS
)
2685 addr_const_to_string (buf1
, XEXP (x
, 0));
2688 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
2689 && INTVAL (XEXP (x
, 1)) < 0)
2691 strcat (str
, ASM_OPEN_PAREN
);
2692 addr_const_to_string (buf1
, XEXP (x
, 1));
2694 strcat (str
, ASM_CLOSE_PAREN
);
2698 addr_const_to_string (buf1
, XEXP (x
, 1));
2705 addr_const_to_string (buf1
, XEXP (x
, 0));
2710 output_operand_lossage ("invalid expression as operand");
2714 /* Convert an address constant to a string, and return a pointer to
2715 a copy of the result, located on the heap. */
2722 addr_const_to_string (buf
, x
);
2723 return xstrdup (buf
);
2726 /* Test if rtl node points to a pseudo register. */
2732 return (((GET_CODE (rtl
) == REG
) && (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
))
2733 || ((GET_CODE (rtl
) == SUBREG
)
2734 && (REGNO (XEXP (rtl
, 0)) >= FIRST_PSEUDO_REGISTER
)));
2737 /* Return a reference to a type, with its const and volatile qualifiers
2741 type_main_variant (type
)
2744 type
= TYPE_MAIN_VARIANT (type
);
2746 /* There really should be only one main variant among any group of variants
2747 of a given type (and all of the MAIN_VARIANT values for all members of
2748 the group should point to that one type) but sometimes the C front-end
2749 messes this up for array types, so we work around that bug here. */
2751 if (TREE_CODE (type
) == ARRAY_TYPE
)
2752 while (type
!= TYPE_MAIN_VARIANT (type
))
2753 type
= TYPE_MAIN_VARIANT (type
);
2758 /* Return non-zero if the given type node represents a tagged type. */
2761 is_tagged_type (type
)
2764 register enum tree_code code
= TREE_CODE (type
);
2766 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
2767 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
2770 /* Convert a DIE tag into its string name. */
2773 dwarf_tag_name (tag
)
2774 register unsigned tag
;
2778 case DW_TAG_padding
:
2779 return "DW_TAG_padding";
2780 case DW_TAG_array_type
:
2781 return "DW_TAG_array_type";
2782 case DW_TAG_class_type
:
2783 return "DW_TAG_class_type";
2784 case DW_TAG_entry_point
:
2785 return "DW_TAG_entry_point";
2786 case DW_TAG_enumeration_type
:
2787 return "DW_TAG_enumeration_type";
2788 case DW_TAG_formal_parameter
:
2789 return "DW_TAG_formal_parameter";
2790 case DW_TAG_imported_declaration
:
2791 return "DW_TAG_imported_declaration";
2793 return "DW_TAG_label";
2794 case DW_TAG_lexical_block
:
2795 return "DW_TAG_lexical_block";
2797 return "DW_TAG_member";
2798 case DW_TAG_pointer_type
:
2799 return "DW_TAG_pointer_type";
2800 case DW_TAG_reference_type
:
2801 return "DW_TAG_reference_type";
2802 case DW_TAG_compile_unit
:
2803 return "DW_TAG_compile_unit";
2804 case DW_TAG_string_type
:
2805 return "DW_TAG_string_type";
2806 case DW_TAG_structure_type
:
2807 return "DW_TAG_structure_type";
2808 case DW_TAG_subroutine_type
:
2809 return "DW_TAG_subroutine_type";
2810 case DW_TAG_typedef
:
2811 return "DW_TAG_typedef";
2812 case DW_TAG_union_type
:
2813 return "DW_TAG_union_type";
2814 case DW_TAG_unspecified_parameters
:
2815 return "DW_TAG_unspecified_parameters";
2816 case DW_TAG_variant
:
2817 return "DW_TAG_variant";
2818 case DW_TAG_common_block
:
2819 return "DW_TAG_common_block";
2820 case DW_TAG_common_inclusion
:
2821 return "DW_TAG_common_inclusion";
2822 case DW_TAG_inheritance
:
2823 return "DW_TAG_inheritance";
2824 case DW_TAG_inlined_subroutine
:
2825 return "DW_TAG_inlined_subroutine";
2827 return "DW_TAG_module";
2828 case DW_TAG_ptr_to_member_type
:
2829 return "DW_TAG_ptr_to_member_type";
2830 case DW_TAG_set_type
:
2831 return "DW_TAG_set_type";
2832 case DW_TAG_subrange_type
:
2833 return "DW_TAG_subrange_type";
2834 case DW_TAG_with_stmt
:
2835 return "DW_TAG_with_stmt";
2836 case DW_TAG_access_declaration
:
2837 return "DW_TAG_access_declaration";
2838 case DW_TAG_base_type
:
2839 return "DW_TAG_base_type";
2840 case DW_TAG_catch_block
:
2841 return "DW_TAG_catch_block";
2842 case DW_TAG_const_type
:
2843 return "DW_TAG_const_type";
2844 case DW_TAG_constant
:
2845 return "DW_TAG_constant";
2846 case DW_TAG_enumerator
:
2847 return "DW_TAG_enumerator";
2848 case DW_TAG_file_type
:
2849 return "DW_TAG_file_type";
2851 return "DW_TAG_friend";
2852 case DW_TAG_namelist
:
2853 return "DW_TAG_namelist";
2854 case DW_TAG_namelist_item
:
2855 return "DW_TAG_namelist_item";
2856 case DW_TAG_packed_type
:
2857 return "DW_TAG_packed_type";
2858 case DW_TAG_subprogram
:
2859 return "DW_TAG_subprogram";
2860 case DW_TAG_template_type_param
:
2861 return "DW_TAG_template_type_param";
2862 case DW_TAG_template_value_param
:
2863 return "DW_TAG_template_value_param";
2864 case DW_TAG_thrown_type
:
2865 return "DW_TAG_thrown_type";
2866 case DW_TAG_try_block
:
2867 return "DW_TAG_try_block";
2868 case DW_TAG_variant_part
:
2869 return "DW_TAG_variant_part";
2870 case DW_TAG_variable
:
2871 return "DW_TAG_variable";
2872 case DW_TAG_volatile_type
:
2873 return "DW_TAG_volatile_type";
2874 case DW_TAG_MIPS_loop
:
2875 return "DW_TAG_MIPS_loop";
2876 case DW_TAG_format_label
:
2877 return "DW_TAG_format_label";
2878 case DW_TAG_function_template
:
2879 return "DW_TAG_function_template";
2880 case DW_TAG_class_template
:
2881 return "DW_TAG_class_template";
2883 return "DW_TAG_<unknown>";
2887 /* Convert a DWARF attribute code into its string name. */
2890 dwarf_attr_name (attr
)
2891 register unsigned attr
;
2896 return "DW_AT_sibling";
2897 case DW_AT_location
:
2898 return "DW_AT_location";
2900 return "DW_AT_name";
2901 case DW_AT_ordering
:
2902 return "DW_AT_ordering";
2903 case DW_AT_subscr_data
:
2904 return "DW_AT_subscr_data";
2905 case DW_AT_byte_size
:
2906 return "DW_AT_byte_size";
2907 case DW_AT_bit_offset
:
2908 return "DW_AT_bit_offset";
2909 case DW_AT_bit_size
:
2910 return "DW_AT_bit_size";
2911 case DW_AT_element_list
:
2912 return "DW_AT_element_list";
2913 case DW_AT_stmt_list
:
2914 return "DW_AT_stmt_list";
2916 return "DW_AT_low_pc";
2918 return "DW_AT_high_pc";
2919 case DW_AT_language
:
2920 return "DW_AT_language";
2922 return "DW_AT_member";
2924 return "DW_AT_discr";
2925 case DW_AT_discr_value
:
2926 return "DW_AT_discr_value";
2927 case DW_AT_visibility
:
2928 return "DW_AT_visibility";
2930 return "DW_AT_import";
2931 case DW_AT_string_length
:
2932 return "DW_AT_string_length";
2933 case DW_AT_common_reference
:
2934 return "DW_AT_common_reference";
2935 case DW_AT_comp_dir
:
2936 return "DW_AT_comp_dir";
2937 case DW_AT_const_value
:
2938 return "DW_AT_const_value";
2939 case DW_AT_containing_type
:
2940 return "DW_AT_containing_type";
2941 case DW_AT_default_value
:
2942 return "DW_AT_default_value";
2944 return "DW_AT_inline";
2945 case DW_AT_is_optional
:
2946 return "DW_AT_is_optional";
2947 case DW_AT_lower_bound
:
2948 return "DW_AT_lower_bound";
2949 case DW_AT_producer
:
2950 return "DW_AT_producer";
2951 case DW_AT_prototyped
:
2952 return "DW_AT_prototyped";
2953 case DW_AT_return_addr
:
2954 return "DW_AT_return_addr";
2955 case DW_AT_start_scope
:
2956 return "DW_AT_start_scope";
2957 case DW_AT_stride_size
:
2958 return "DW_AT_stride_size";
2959 case DW_AT_upper_bound
:
2960 return "DW_AT_upper_bound";
2961 case DW_AT_abstract_origin
:
2962 return "DW_AT_abstract_origin";
2963 case DW_AT_accessibility
:
2964 return "DW_AT_accessibility";
2965 case DW_AT_address_class
:
2966 return "DW_AT_address_class";
2967 case DW_AT_artificial
:
2968 return "DW_AT_artificial";
2969 case DW_AT_base_types
:
2970 return "DW_AT_base_types";
2971 case DW_AT_calling_convention
:
2972 return "DW_AT_calling_convention";
2974 return "DW_AT_count";
2975 case DW_AT_data_member_location
:
2976 return "DW_AT_data_member_location";
2977 case DW_AT_decl_column
:
2978 return "DW_AT_decl_column";
2979 case DW_AT_decl_file
:
2980 return "DW_AT_decl_file";
2981 case DW_AT_decl_line
:
2982 return "DW_AT_decl_line";
2983 case DW_AT_declaration
:
2984 return "DW_AT_declaration";
2985 case DW_AT_discr_list
:
2986 return "DW_AT_discr_list";
2987 case DW_AT_encoding
:
2988 return "DW_AT_encoding";
2989 case DW_AT_external
:
2990 return "DW_AT_external";
2991 case DW_AT_frame_base
:
2992 return "DW_AT_frame_base";
2994 return "DW_AT_friend";
2995 case DW_AT_identifier_case
:
2996 return "DW_AT_identifier_case";
2997 case DW_AT_macro_info
:
2998 return "DW_AT_macro_info";
2999 case DW_AT_namelist_items
:
3000 return "DW_AT_namelist_items";
3001 case DW_AT_priority
:
3002 return "DW_AT_priority";
3004 return "DW_AT_segment";
3005 case DW_AT_specification
:
3006 return "DW_AT_specification";
3007 case DW_AT_static_link
:
3008 return "DW_AT_static_link";
3010 return "DW_AT_type";
3011 case DW_AT_use_location
:
3012 return "DW_AT_use_location";
3013 case DW_AT_variable_parameter
:
3014 return "DW_AT_variable_parameter";
3015 case DW_AT_virtuality
:
3016 return "DW_AT_virtuality";
3017 case DW_AT_vtable_elem_location
:
3018 return "DW_AT_vtable_elem_location";
3020 case DW_AT_MIPS_fde
:
3021 return "DW_AT_MIPS_fde";
3022 case DW_AT_MIPS_loop_begin
:
3023 return "DW_AT_MIPS_loop_begin";
3024 case DW_AT_MIPS_tail_loop_begin
:
3025 return "DW_AT_MIPS_tail_loop_begin";
3026 case DW_AT_MIPS_epilog_begin
:
3027 return "DW_AT_MIPS_epilog_begin";
3028 case DW_AT_MIPS_loop_unroll_factor
:
3029 return "DW_AT_MIPS_loop_unroll_factor";
3030 case DW_AT_MIPS_software_pipeline_depth
:
3031 return "DW_AT_MIPS_software_pipeline_depth";
3032 case DW_AT_MIPS_linkage_name
:
3033 return "DW_AT_MIPS_linkage_name";
3034 case DW_AT_MIPS_stride
:
3035 return "DW_AT_MIPS_stride";
3036 case DW_AT_MIPS_abstract_name
:
3037 return "DW_AT_MIPS_abstract_name";
3038 case DW_AT_MIPS_clone_origin
:
3039 return "DW_AT_MIPS_clone_origin";
3040 case DW_AT_MIPS_has_inlines
:
3041 return "DW_AT_MIPS_has_inlines";
3043 case DW_AT_sf_names
:
3044 return "DW_AT_sf_names";
3045 case DW_AT_src_info
:
3046 return "DW_AT_src_info";
3047 case DW_AT_mac_info
:
3048 return "DW_AT_mac_info";
3049 case DW_AT_src_coords
:
3050 return "DW_AT_src_coords";
3051 case DW_AT_body_begin
:
3052 return "DW_AT_body_begin";
3053 case DW_AT_body_end
:
3054 return "DW_AT_body_end";
3056 return "DW_AT_<unknown>";
3060 /* Convert a DWARF value form code into its string name. */
3063 dwarf_form_name (form
)
3064 register unsigned form
;
3069 return "DW_FORM_addr";
3070 case DW_FORM_block2
:
3071 return "DW_FORM_block2";
3072 case DW_FORM_block4
:
3073 return "DW_FORM_block4";
3075 return "DW_FORM_data2";
3077 return "DW_FORM_data4";
3079 return "DW_FORM_data8";
3080 case DW_FORM_string
:
3081 return "DW_FORM_string";
3083 return "DW_FORM_block";
3084 case DW_FORM_block1
:
3085 return "DW_FORM_block1";
3087 return "DW_FORM_data1";
3089 return "DW_FORM_flag";
3091 return "DW_FORM_sdata";
3093 return "DW_FORM_strp";
3095 return "DW_FORM_udata";
3096 case DW_FORM_ref_addr
:
3097 return "DW_FORM_ref_addr";
3099 return "DW_FORM_ref1";
3101 return "DW_FORM_ref2";
3103 return "DW_FORM_ref4";
3105 return "DW_FORM_ref8";
3106 case DW_FORM_ref_udata
:
3107 return "DW_FORM_ref_udata";
3108 case DW_FORM_indirect
:
3109 return "DW_FORM_indirect";
3111 return "DW_FORM_<unknown>";
3115 /* Convert a DWARF stack opcode into its string name. */
3118 dwarf_stack_op_name (op
)
3119 register unsigned op
;
3124 return "DW_OP_addr";
3126 return "DW_OP_deref";
3128 return "DW_OP_const1u";
3130 return "DW_OP_const1s";
3132 return "DW_OP_const2u";
3134 return "DW_OP_const2s";
3136 return "DW_OP_const4u";
3138 return "DW_OP_const4s";
3140 return "DW_OP_const8u";
3142 return "DW_OP_const8s";
3144 return "DW_OP_constu";
3146 return "DW_OP_consts";
3150 return "DW_OP_drop";
3152 return "DW_OP_over";
3154 return "DW_OP_pick";
3156 return "DW_OP_swap";
3160 return "DW_OP_xderef";
3168 return "DW_OP_minus";
3180 return "DW_OP_plus";
3181 case DW_OP_plus_uconst
:
3182 return "DW_OP_plus_uconst";
3188 return "DW_OP_shra";
3206 return "DW_OP_skip";
3208 return "DW_OP_lit0";
3210 return "DW_OP_lit1";
3212 return "DW_OP_lit2";
3214 return "DW_OP_lit3";
3216 return "DW_OP_lit4";
3218 return "DW_OP_lit5";
3220 return "DW_OP_lit6";
3222 return "DW_OP_lit7";
3224 return "DW_OP_lit8";
3226 return "DW_OP_lit9";
3228 return "DW_OP_lit10";
3230 return "DW_OP_lit11";
3232 return "DW_OP_lit12";
3234 return "DW_OP_lit13";
3236 return "DW_OP_lit14";
3238 return "DW_OP_lit15";
3240 return "DW_OP_lit16";
3242 return "DW_OP_lit17";
3244 return "DW_OP_lit18";
3246 return "DW_OP_lit19";
3248 return "DW_OP_lit20";
3250 return "DW_OP_lit21";
3252 return "DW_OP_lit22";
3254 return "DW_OP_lit23";
3256 return "DW_OP_lit24";
3258 return "DW_OP_lit25";
3260 return "DW_OP_lit26";
3262 return "DW_OP_lit27";
3264 return "DW_OP_lit28";
3266 return "DW_OP_lit29";
3268 return "DW_OP_lit30";
3270 return "DW_OP_lit31";
3272 return "DW_OP_reg0";
3274 return "DW_OP_reg1";
3276 return "DW_OP_reg2";
3278 return "DW_OP_reg3";
3280 return "DW_OP_reg4";
3282 return "DW_OP_reg5";
3284 return "DW_OP_reg6";
3286 return "DW_OP_reg7";
3288 return "DW_OP_reg8";
3290 return "DW_OP_reg9";
3292 return "DW_OP_reg10";
3294 return "DW_OP_reg11";
3296 return "DW_OP_reg12";
3298 return "DW_OP_reg13";
3300 return "DW_OP_reg14";
3302 return "DW_OP_reg15";
3304 return "DW_OP_reg16";
3306 return "DW_OP_reg17";
3308 return "DW_OP_reg18";
3310 return "DW_OP_reg19";
3312 return "DW_OP_reg20";
3314 return "DW_OP_reg21";
3316 return "DW_OP_reg22";
3318 return "DW_OP_reg23";
3320 return "DW_OP_reg24";
3322 return "DW_OP_reg25";
3324 return "DW_OP_reg26";
3326 return "DW_OP_reg27";
3328 return "DW_OP_reg28";
3330 return "DW_OP_reg29";
3332 return "DW_OP_reg30";
3334 return "DW_OP_reg31";
3336 return "DW_OP_breg0";
3338 return "DW_OP_breg1";
3340 return "DW_OP_breg2";
3342 return "DW_OP_breg3";
3344 return "DW_OP_breg4";
3346 return "DW_OP_breg5";
3348 return "DW_OP_breg6";
3350 return "DW_OP_breg7";
3352 return "DW_OP_breg8";
3354 return "DW_OP_breg9";
3356 return "DW_OP_breg10";
3358 return "DW_OP_breg11";
3360 return "DW_OP_breg12";
3362 return "DW_OP_breg13";
3364 return "DW_OP_breg14";
3366 return "DW_OP_breg15";
3368 return "DW_OP_breg16";
3370 return "DW_OP_breg17";
3372 return "DW_OP_breg18";
3374 return "DW_OP_breg19";
3376 return "DW_OP_breg20";
3378 return "DW_OP_breg21";
3380 return "DW_OP_breg22";
3382 return "DW_OP_breg23";
3384 return "DW_OP_breg24";
3386 return "DW_OP_breg25";
3388 return "DW_OP_breg26";
3390 return "DW_OP_breg27";
3392 return "DW_OP_breg28";
3394 return "DW_OP_breg29";
3396 return "DW_OP_breg30";
3398 return "DW_OP_breg31";
3400 return "DW_OP_regx";
3402 return "DW_OP_fbreg";
3404 return "DW_OP_bregx";
3406 return "DW_OP_piece";
3407 case DW_OP_deref_size
:
3408 return "DW_OP_deref_size";
3409 case DW_OP_xderef_size
:
3410 return "DW_OP_xderef_size";
3414 return "OP_<unknown>";
3418 /* Convert a DWARF type code into its string name. */
3421 dwarf_type_encoding_name (enc
)
3422 register unsigned enc
;
3426 case DW_ATE_address
:
3427 return "DW_ATE_address";
3428 case DW_ATE_boolean
:
3429 return "DW_ATE_boolean";
3430 case DW_ATE_complex_float
:
3431 return "DW_ATE_complex_float";
3433 return "DW_ATE_float";
3435 return "DW_ATE_signed";
3436 case DW_ATE_signed_char
:
3437 return "DW_ATE_signed_char";
3438 case DW_ATE_unsigned
:
3439 return "DW_ATE_unsigned";
3440 case DW_ATE_unsigned_char
:
3441 return "DW_ATE_unsigned_char";
3443 return "DW_ATE_<unknown>";
3447 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3448 instance of an inlined instance of a decl which is local to an inline
3449 function, so we have to trace all of the way back through the origin chain
3450 to find out what sort of node actually served as the original seed for the
3454 decl_ultimate_origin (decl
)
3457 register tree immediate_origin
= DECL_ABSTRACT_ORIGIN (decl
);
3459 if (immediate_origin
== NULL_TREE
)
3463 register tree ret_val
;
3464 register tree lookahead
= immediate_origin
;
3468 ret_val
= lookahead
;
3469 lookahead
= DECL_ABSTRACT_ORIGIN (ret_val
);
3471 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
3477 /* Determine the "ultimate origin" of a block. The block may be an inlined
3478 instance of an inlined instance of a block which is local to an inline
3479 function, so we have to trace all of the way back through the origin chain
3480 to find out what sort of node actually served as the original seed for the
3484 block_ultimate_origin (block
)
3485 register tree block
;
3487 register tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
3489 if (immediate_origin
== NULL_TREE
)
3493 register tree ret_val
;
3494 register tree lookahead
= immediate_origin
;
3498 ret_val
= lookahead
;
3499 lookahead
= (TREE_CODE (ret_val
) == BLOCK
)
3500 ? BLOCK_ABSTRACT_ORIGIN (ret_val
)
3503 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
3509 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3510 of a virtual function may refer to a base class, so we check the 'this'
3514 decl_class_context (decl
)
3517 tree context
= NULL_TREE
;
3519 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3520 context
= DECL_CONTEXT (decl
);
3522 context
= TYPE_MAIN_VARIANT
3523 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3525 if (context
&& TREE_CODE_CLASS (TREE_CODE (context
)) != 't')
3526 context
= NULL_TREE
;
3531 /* Add an attribute/value pair to a DIE */
3534 add_dwarf_attr (die
, attr
)
3535 register dw_die_ref die
;
3536 register dw_attr_ref attr
;
3538 if (die
!= NULL
&& attr
!= NULL
)
3540 if (die
->die_attr
== NULL
)
3542 die
->die_attr
= attr
;
3543 die
->die_attr_last
= attr
;
3547 die
->die_attr_last
->dw_attr_next
= attr
;
3548 die
->die_attr_last
= attr
;
3553 /* Add a flag value attribute to a DIE. */
3556 add_AT_flag (die
, attr_kind
, flag
)
3557 register dw_die_ref die
;
3558 register enum dwarf_attribute attr_kind
;
3559 register unsigned flag
;
3561 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3563 attr
->dw_attr_next
= NULL
;
3564 attr
->dw_attr
= attr_kind
;
3565 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
3566 attr
->dw_attr_val
.v
.val_flag
= flag
;
3567 add_dwarf_attr (die
, attr
);
3570 /* Add a signed integer attribute value to a DIE. */
3573 add_AT_int (die
, attr_kind
, int_val
)
3574 register dw_die_ref die
;
3575 register enum dwarf_attribute attr_kind
;
3576 register long int int_val
;
3578 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3580 attr
->dw_attr_next
= NULL
;
3581 attr
->dw_attr
= attr_kind
;
3582 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
3583 attr
->dw_attr_val
.v
.val_int
= int_val
;
3584 add_dwarf_attr (die
, attr
);
3587 /* Add an unsigned integer attribute value to a DIE. */
3590 add_AT_unsigned (die
, attr_kind
, unsigned_val
)
3591 register dw_die_ref die
;
3592 register enum dwarf_attribute attr_kind
;
3593 register unsigned long unsigned_val
;
3595 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3597 attr
->dw_attr_next
= NULL
;
3598 attr
->dw_attr
= attr_kind
;
3599 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3600 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3601 add_dwarf_attr (die
, attr
);
3604 /* Add an unsigned double integer attribute value to a DIE. */
3607 add_AT_long_long (die
, attr_kind
, val_hi
, val_low
)
3608 register dw_die_ref die
;
3609 register enum dwarf_attribute attr_kind
;
3610 register unsigned long val_hi
;
3611 register unsigned long val_low
;
3613 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3615 attr
->dw_attr_next
= NULL
;
3616 attr
->dw_attr
= attr_kind
;
3617 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
3618 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
3619 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
3620 add_dwarf_attr (die
, attr
);
3623 /* Add a floating point attribute value to a DIE and return it. */
3626 add_AT_float (die
, attr_kind
, length
, array
)
3627 register dw_die_ref die
;
3628 register enum dwarf_attribute attr_kind
;
3629 register unsigned length
;
3630 register long *array
;
3632 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3634 attr
->dw_attr_next
= NULL
;
3635 attr
->dw_attr
= attr_kind
;
3636 attr
->dw_attr_val
.val_class
= dw_val_class_float
;
3637 attr
->dw_attr_val
.v
.val_float
.length
= length
;
3638 attr
->dw_attr_val
.v
.val_float
.array
= array
;
3639 add_dwarf_attr (die
, attr
);
3642 /* Add a string attribute value to a DIE. */
3645 add_AT_string (die
, attr_kind
, str
)
3646 register dw_die_ref die
;
3647 register enum dwarf_attribute attr_kind
;
3650 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3652 attr
->dw_attr_next
= NULL
;
3653 attr
->dw_attr
= attr_kind
;
3654 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
3655 attr
->dw_attr_val
.v
.val_str
= xstrdup (str
);
3656 add_dwarf_attr (die
, attr
);
3659 /* Add a DIE reference attribute value to a DIE. */
3662 add_AT_die_ref (die
, attr_kind
, targ_die
)
3663 register dw_die_ref die
;
3664 register enum dwarf_attribute attr_kind
;
3665 register dw_die_ref targ_die
;
3667 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3669 attr
->dw_attr_next
= NULL
;
3670 attr
->dw_attr
= attr_kind
;
3671 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
3672 attr
->dw_attr_val
.v
.val_die_ref
= targ_die
;
3673 add_dwarf_attr (die
, attr
);
3676 /* Add an FDE reference attribute value to a DIE. */
3679 add_AT_fde_ref (die
, attr_kind
, targ_fde
)
3680 register dw_die_ref die
;
3681 register enum dwarf_attribute attr_kind
;
3682 register unsigned targ_fde
;
3684 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3686 attr
->dw_attr_next
= NULL
;
3687 attr
->dw_attr
= attr_kind
;
3688 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
3689 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
3690 add_dwarf_attr (die
, attr
);
3693 /* Add a location description attribute value to a DIE. */
3696 add_AT_loc (die
, attr_kind
, loc
)
3697 register dw_die_ref die
;
3698 register enum dwarf_attribute attr_kind
;
3699 register dw_loc_descr_ref loc
;
3701 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3703 attr
->dw_attr_next
= NULL
;
3704 attr
->dw_attr
= attr_kind
;
3705 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
3706 attr
->dw_attr_val
.v
.val_loc
= loc
;
3707 add_dwarf_attr (die
, attr
);
3710 /* Add an address constant attribute value to a DIE. */
3713 add_AT_addr (die
, attr_kind
, addr
)
3714 register dw_die_ref die
;
3715 register enum dwarf_attribute attr_kind
;
3718 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3720 attr
->dw_attr_next
= NULL
;
3721 attr
->dw_attr
= attr_kind
;
3722 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
3723 attr
->dw_attr_val
.v
.val_addr
= addr
;
3724 add_dwarf_attr (die
, attr
);
3727 /* Add a label identifier attribute value to a DIE. */
3730 add_AT_lbl_id (die
, attr_kind
, lbl_id
)
3731 register dw_die_ref die
;
3732 register enum dwarf_attribute attr_kind
;
3733 register char *lbl_id
;
3735 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3737 attr
->dw_attr_next
= NULL
;
3738 attr
->dw_attr
= attr_kind
;
3739 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3740 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
3741 add_dwarf_attr (die
, attr
);
3744 /* Add a section offset attribute value to a DIE. */
3747 add_AT_section_offset (die
, attr_kind
, section
)
3748 register dw_die_ref die
;
3749 register enum dwarf_attribute attr_kind
;
3750 register char *section
;
3752 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
3754 attr
->dw_attr_next
= NULL
;
3755 attr
->dw_attr
= attr_kind
;
3756 attr
->dw_attr_val
.val_class
= dw_val_class_section_offset
;
3757 attr
->dw_attr_val
.v
.val_section
= section
;
3758 add_dwarf_attr (die
, attr
);
3762 /* Test if die refers to an external subroutine. */
3765 is_extern_subr_die (die
)
3766 register dw_die_ref die
;
3768 register dw_attr_ref a
;
3769 register int is_subr
= FALSE
;
3770 register int is_extern
= FALSE
;
3772 if (die
!= NULL
&& die
->die_tag
== DW_TAG_subprogram
)
3775 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
3777 if (a
->dw_attr
== DW_AT_external
3778 && a
->dw_attr_val
.val_class
== dw_val_class_flag
3779 && a
->dw_attr_val
.v
.val_flag
!= 0)
3787 return is_subr
&& is_extern
;
3790 /* Get the attribute of type attr_kind. */
3792 static inline dw_attr_ref
3793 get_AT (die
, attr_kind
)
3794 register dw_die_ref die
;
3795 register enum dwarf_attribute attr_kind
;
3797 register dw_attr_ref a
;
3798 register dw_die_ref spec
= NULL
;
3802 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
3804 if (a
->dw_attr
== attr_kind
)
3807 if (a
->dw_attr
== DW_AT_specification
3808 || a
->dw_attr
== DW_AT_abstract_origin
)
3809 spec
= a
->dw_attr_val
.v
.val_die_ref
;
3813 return get_AT (spec
, attr_kind
);
3819 /* Return the "low pc" attribute value, typically associated with
3820 a subprogram DIE. Return null if the "low pc" attribute is
3821 either not prsent, or if it cannot be represented as an
3822 assembler label identifier. */
3824 static inline char *
3826 register dw_die_ref die
;
3828 register dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
3830 if (a
&& a
->dw_attr_val
.val_class
== dw_val_class_lbl_id
)
3831 return a
->dw_attr_val
.v
.val_lbl_id
;
3836 /* Return the "high pc" attribute value, typically associated with
3837 a subprogram DIE. Return null if the "high pc" attribute is
3838 either not prsent, or if it cannot be represented as an
3839 assembler label identifier. */
3841 static inline char *
3843 register dw_die_ref die
;
3845 register dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
3847 if (a
&& a
->dw_attr_val
.val_class
== dw_val_class_lbl_id
)
3848 return a
->dw_attr_val
.v
.val_lbl_id
;
3853 /* Return the value of the string attribute designated by ATTR_KIND, or
3854 NULL if it is not present. */
3856 static inline char *
3857 get_AT_string (die
, attr_kind
)
3858 register dw_die_ref die
;
3859 register enum dwarf_attribute attr_kind
;
3861 register dw_attr_ref a
= get_AT (die
, attr_kind
);
3863 if (a
&& a
->dw_attr_val
.val_class
== dw_val_class_str
)
3864 return a
->dw_attr_val
.v
.val_str
;
3869 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3870 if it is not present. */
3873 get_AT_flag (die
, attr_kind
)
3874 register dw_die_ref die
;
3875 register enum dwarf_attribute attr_kind
;
3877 register dw_attr_ref a
= get_AT (die
, attr_kind
);
3879 if (a
&& a
->dw_attr_val
.val_class
== dw_val_class_flag
)
3880 return a
->dw_attr_val
.v
.val_flag
;
3885 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3886 if it is not present. */
3888 static inline unsigned
3889 get_AT_unsigned (die
, attr_kind
)
3890 register dw_die_ref die
;
3891 register enum dwarf_attribute attr_kind
;
3893 register dw_attr_ref a
= get_AT (die
, attr_kind
);
3895 if (a
&& a
->dw_attr_val
.val_class
== dw_val_class_unsigned_const
)
3896 return a
->dw_attr_val
.v
.val_unsigned
;
3904 register unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
3906 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
3907 || lang
== DW_LANG_C_plus_plus
);
3913 register unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
3915 return (lang
== DW_LANG_Fortran77
|| lang
== DW_LANG_Fortran90
);
3918 /* Remove the specified attribute if present. */
3921 remove_AT (die
, attr_kind
)
3922 register dw_die_ref die
;
3923 register enum dwarf_attribute attr_kind
;
3925 register dw_attr_ref a
;
3926 register dw_attr_ref removed
= NULL
;;
3930 if (die
->die_attr
->dw_attr
== attr_kind
)
3932 removed
= die
->die_attr
;
3933 if (die
->die_attr_last
== die
->die_attr
)
3934 die
->die_attr_last
= NULL
;
3936 die
->die_attr
= die
->die_attr
->dw_attr_next
;
3940 for (a
= die
->die_attr
; a
->dw_attr_next
!= NULL
;
3941 a
= a
->dw_attr_next
)
3942 if (a
->dw_attr_next
->dw_attr
== attr_kind
)
3944 removed
= a
->dw_attr_next
;
3945 if (die
->die_attr_last
== a
->dw_attr_next
)
3946 die
->die_attr_last
= a
;
3948 a
->dw_attr_next
= a
->dw_attr_next
->dw_attr_next
;
3957 /* Discard the children of this DIE. */
3960 remove_children (die
)
3961 register dw_die_ref die
;
3963 register dw_die_ref child_die
= die
->die_child
;
3965 die
->die_child
= NULL
;
3966 die
->die_child_last
= NULL
;
3968 while (child_die
!= NULL
)
3970 register dw_die_ref tmp_die
= child_die
;
3971 register dw_attr_ref a
;
3973 child_die
= child_die
->die_sib
;
3975 for (a
= tmp_die
->die_attr
; a
!= NULL
; )
3977 register dw_attr_ref tmp_a
= a
;
3979 a
= a
->dw_attr_next
;
3987 /* Add a child DIE below its parent. */
3990 add_child_die (die
, child_die
)
3991 register dw_die_ref die
;
3992 register dw_die_ref child_die
;
3994 if (die
!= NULL
&& child_die
!= NULL
)
3996 if (die
== child_die
)
3998 child_die
->die_parent
= die
;
3999 child_die
->die_sib
= NULL
;
4001 if (die
->die_child
== NULL
)
4003 die
->die_child
= child_die
;
4004 die
->die_child_last
= child_die
;
4008 die
->die_child_last
->die_sib
= child_die
;
4009 die
->die_child_last
= child_die
;
4014 /* Return a pointer to a newly created DIE node. */
4016 static inline dw_die_ref
4017 new_die (tag_value
, parent_die
)
4018 register enum dwarf_tag tag_value
;
4019 register dw_die_ref parent_die
;
4021 register dw_die_ref die
= (dw_die_ref
) xmalloc (sizeof (die_node
));
4023 die
->die_tag
= tag_value
;
4024 die
->die_abbrev
= 0;
4025 die
->die_offset
= 0;
4026 die
->die_child
= NULL
;
4027 die
->die_parent
= NULL
;
4028 die
->die_sib
= NULL
;
4029 die
->die_child_last
= NULL
;
4030 die
->die_attr
= NULL
;
4031 die
->die_attr_last
= NULL
;
4033 if (parent_die
!= NULL
)
4034 add_child_die (parent_die
, die
);
4037 limbo_die_node
*limbo_node
;
4039 limbo_node
= (limbo_die_node
*) xmalloc (sizeof (limbo_die_node
));
4040 limbo_node
->die
= die
;
4041 limbo_node
->next
= limbo_die_list
;
4042 limbo_die_list
= limbo_node
;
4048 /* Return the DIE associated with the given type specifier. */
4050 static inline dw_die_ref
4051 lookup_type_die (type
)
4054 return (dw_die_ref
) TYPE_SYMTAB_POINTER (type
);
4057 /* Equate a DIE to a given type specifier. */
4060 equate_type_number_to_die (type
, type_die
)
4062 register dw_die_ref type_die
;
4064 TYPE_SYMTAB_POINTER (type
) = (char *) type_die
;
4067 /* Return the DIE associated with a given declaration. */
4069 static inline dw_die_ref
4070 lookup_decl_die (decl
)
4073 register unsigned decl_id
= DECL_UID (decl
);
4075 return (decl_id
< decl_die_table_in_use
4076 ? decl_die_table
[decl_id
] : NULL
);
4079 /* Equate a DIE to a particular declaration. */
4082 equate_decl_number_to_die (decl
, decl_die
)
4084 register dw_die_ref decl_die
;
4086 register unsigned decl_id
= DECL_UID (decl
);
4087 register unsigned i
;
4088 register unsigned num_allocated
;
4090 if (decl_id
>= decl_die_table_allocated
)
4093 = ((decl_id
+ 1 + DECL_DIE_TABLE_INCREMENT
- 1)
4094 / DECL_DIE_TABLE_INCREMENT
)
4095 * DECL_DIE_TABLE_INCREMENT
;
4098 = (dw_die_ref
*) xrealloc (decl_die_table
,
4099 sizeof (dw_die_ref
) * num_allocated
);
4101 bzero ((char *) &decl_die_table
[decl_die_table_allocated
],
4102 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
4103 decl_die_table_allocated
= num_allocated
;
4106 if (decl_id
>= decl_die_table_in_use
)
4107 decl_die_table_in_use
= (decl_id
+ 1);
4109 decl_die_table
[decl_id
] = decl_die
;
4112 /* Return a pointer to a newly allocated location description. Location
4113 descriptions are simple expression terms that can be strung
4114 together to form more complicated location (address) descriptions. */
4116 static inline dw_loc_descr_ref
4117 new_loc_descr (op
, oprnd1
, oprnd2
)
4118 register enum dwarf_location_atom op
;
4119 register unsigned long oprnd1
;
4120 register unsigned long oprnd2
;
4122 register dw_loc_descr_ref descr
4123 = (dw_loc_descr_ref
) xmalloc (sizeof (dw_loc_descr_node
));
4125 descr
->dw_loc_next
= NULL
;
4126 descr
->dw_loc_opc
= op
;
4127 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
4128 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
4129 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
4130 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
4135 /* Add a location description term to a location description expression. */
4138 add_loc_descr (list_head
, descr
)
4139 register dw_loc_descr_ref
*list_head
;
4140 register dw_loc_descr_ref descr
;
4142 register dw_loc_descr_ref
*d
;
4144 /* Find the end of the chain. */
4145 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
4151 /* Keep track of the number of spaces used to indent the
4152 output of the debugging routines that print the structure of
4153 the DIE internal representation. */
4154 static int print_indent
;
4156 /* Indent the line the number of spaces given by print_indent. */
4159 print_spaces (outfile
)
4162 fprintf (outfile
, "%*s", print_indent
, "");
4165 /* Print the information associated with a given DIE, and its children.
4166 This routine is a debugging aid only. */
4169 print_die (die
, outfile
)
4173 register dw_attr_ref a
;
4174 register dw_die_ref c
;
4176 print_spaces (outfile
);
4177 fprintf (outfile
, "DIE %4u: %s\n",
4178 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
4179 print_spaces (outfile
);
4180 fprintf (outfile
, " abbrev id: %u", die
->die_abbrev
);
4181 fprintf (outfile
, " offset: %u\n", die
->die_offset
);
4183 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4185 print_spaces (outfile
);
4186 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
4188 switch (a
->dw_attr_val
.val_class
)
4190 case dw_val_class_addr
:
4191 fprintf (outfile
, "address");
4193 case dw_val_class_loc
:
4194 fprintf (outfile
, "location descriptor");
4196 case dw_val_class_const
:
4197 fprintf (outfile
, "%d", a
->dw_attr_val
.v
.val_int
);
4199 case dw_val_class_unsigned_const
:
4200 fprintf (outfile
, "%u", a
->dw_attr_val
.v
.val_unsigned
);
4202 case dw_val_class_long_long
:
4203 fprintf (outfile
, "constant (%u,%u)",
4204 a
->dw_attr_val
.v
.val_long_long
.hi
,
4205 a
->dw_attr_val
.v
.val_long_long
.low
);
4207 case dw_val_class_float
:
4208 fprintf (outfile
, "floating-point constant");
4210 case dw_val_class_flag
:
4211 fprintf (outfile
, "%u", a
->dw_attr_val
.v
.val_flag
);
4213 case dw_val_class_die_ref
:
4214 if (a
->dw_attr_val
.v
.val_die_ref
!= NULL
)
4215 fprintf (outfile
, "die -> %u",
4216 a
->dw_attr_val
.v
.val_die_ref
->die_offset
);
4218 fprintf (outfile
, "die -> <null>");
4220 case dw_val_class_lbl_id
:
4221 fprintf (outfile
, "label: %s", a
->dw_attr_val
.v
.val_lbl_id
);
4223 case dw_val_class_section_offset
:
4224 fprintf (outfile
, "section: %s", a
->dw_attr_val
.v
.val_section
);
4226 case dw_val_class_str
:
4227 if (a
->dw_attr_val
.v
.val_str
!= NULL
)
4228 fprintf (outfile
, "\"%s\"", a
->dw_attr_val
.v
.val_str
);
4230 fprintf (outfile
, "<null>");
4236 fprintf (outfile
, "\n");
4239 if (die
->die_child
!= NULL
)
4242 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4243 print_die (c
, outfile
);
4249 /* Print the contents of the source code line number correspondence table.
4250 This routine is a debugging aid only. */
4253 print_dwarf_line_table (outfile
)
4256 register unsigned i
;
4257 register dw_line_info_ref line_info
;
4259 fprintf (outfile
, "\n\nDWARF source line information\n");
4260 for (i
= 1; i
< line_info_table_in_use
; ++i
)
4262 line_info
= &line_info_table
[i
];
4263 fprintf (outfile
, "%5d: ", i
);
4264 fprintf (outfile
, "%-20s", file_table
[line_info
->dw_file_num
]);
4265 fprintf (outfile
, "%6d", line_info
->dw_line_num
);
4266 fprintf (outfile
, "\n");
4269 fprintf (outfile
, "\n\n");
4272 /* Print the information collected for a given DIE. */
4275 debug_dwarf_die (die
)
4278 print_die (die
, stderr
);
4281 /* Print all DWARF information collected for the compilation unit.
4282 This routine is a debugging aid only. */
4288 print_die (comp_unit_die
, stderr
);
4289 print_dwarf_line_table (stderr
);
4292 /* Traverse the DIE, and add a sibling attribute if it may have the
4293 effect of speeding up access to siblings. To save some space,
4294 avoid generating sibling attributes for DIE's without children. */
4297 add_sibling_attributes(die
)
4298 register dw_die_ref die
;
4300 register dw_die_ref c
;
4301 register dw_attr_ref attr
;
4302 if (die
!= comp_unit_die
&& die
->die_child
!= NULL
)
4304 attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4305 attr
->dw_attr_next
= NULL
;
4306 attr
->dw_attr
= DW_AT_sibling
;
4307 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
4308 attr
->dw_attr_val
.v
.val_die_ref
= die
->die_sib
;
4310 /* Add the sibling link to the front of the attribute list. */
4311 attr
->dw_attr_next
= die
->die_attr
;
4312 if (die
->die_attr
== NULL
)
4313 die
->die_attr_last
= attr
;
4315 die
->die_attr
= attr
;
4318 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4319 add_sibling_attributes (c
);
4322 /* The format of each DIE (and its attribute value pairs)
4323 is encoded in an abbreviation table. This routine builds the
4324 abbreviation table and assigns a unique abbreviation id for
4325 each abbreviation entry. The children of each die are visited
4329 build_abbrev_table (die
)
4330 register dw_die_ref die
;
4332 register unsigned long abbrev_id
;
4333 register unsigned long n_alloc
;
4334 register dw_die_ref c
;
4335 register dw_attr_ref d_attr
, a_attr
;
4336 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
4338 register dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
4340 if (abbrev
->die_tag
== die
->die_tag
)
4342 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
4344 a_attr
= abbrev
->die_attr
;
4345 d_attr
= die
->die_attr
;
4347 while (a_attr
!= NULL
&& d_attr
!= NULL
)
4349 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
4350 || (value_format (&a_attr
->dw_attr_val
)
4351 != value_format (&d_attr
->dw_attr_val
)))
4354 a_attr
= a_attr
->dw_attr_next
;
4355 d_attr
= d_attr
->dw_attr_next
;
4358 if (a_attr
== NULL
&& d_attr
== NULL
)
4364 if (abbrev_id
>= abbrev_die_table_in_use
)
4366 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
4368 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
4370 = (dw_die_ref
*) xrealloc (abbrev_die_table
,
4371 sizeof (dw_die_ref
) * n_alloc
);
4373 bzero ((char *) &abbrev_die_table
[abbrev_die_table_allocated
],
4374 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
4375 abbrev_die_table_allocated
= n_alloc
;
4378 ++abbrev_die_table_in_use
;
4379 abbrev_die_table
[abbrev_id
] = die
;
4382 die
->die_abbrev
= abbrev_id
;
4383 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4384 build_abbrev_table (c
);
4387 /* Return the size of a string, including the null byte. */
4389 static unsigned long
4390 size_of_string (str
)
4393 register unsigned long size
= 0;
4394 register unsigned long slen
= strlen (str
);
4395 register unsigned long i
;
4396 register unsigned c
;
4398 for (i
= 0; i
< slen
; ++i
)
4407 /* Null terminator. */
4412 /* Return the size of a location descriptor. */
4414 static unsigned long
4415 size_of_loc_descr (loc
)
4416 register dw_loc_descr_ref loc
;
4418 register unsigned long size
= 1;
4420 switch (loc
->dw_loc_opc
)
4442 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4445 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4450 case DW_OP_plus_uconst
:
4451 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4489 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4492 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4495 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4498 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4499 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
4502 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4504 case DW_OP_deref_size
:
4505 case DW_OP_xderef_size
:
4515 /* Return the size of a series of location descriptors. */
4517 static unsigned long
4519 register dw_loc_descr_ref loc
;
4521 register unsigned long size
= 0;
4523 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
4524 size
+= size_of_loc_descr (loc
);
4529 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4532 constant_size (value
)
4533 long unsigned value
;
4540 log
= floor_log2 (value
);
4543 log
= 1 << (floor_log2 (log
) + 1);
4548 /* Return the size of a DIE, as it is represented in the
4549 .debug_info section. */
4551 static unsigned long
4553 register dw_die_ref die
;
4555 register unsigned long size
= 0;
4556 register dw_attr_ref a
;
4558 size
+= size_of_uleb128 (die
->die_abbrev
);
4559 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4561 switch (a
->dw_attr_val
.val_class
)
4563 case dw_val_class_addr
:
4566 case dw_val_class_loc
:
4568 register unsigned long lsize
4569 = size_of_locs (a
->dw_attr_val
.v
.val_loc
);
4572 size
+= constant_size (lsize
);
4576 case dw_val_class_const
:
4579 case dw_val_class_unsigned_const
:
4580 size
+= constant_size (a
->dw_attr_val
.v
.val_unsigned
);
4582 case dw_val_class_long_long
:
4583 size
+= 1 + 8; /* block */
4585 case dw_val_class_float
:
4586 size
+= 1 + a
->dw_attr_val
.v
.val_float
.length
* 4; /* block */
4588 case dw_val_class_flag
:
4591 case dw_val_class_die_ref
:
4592 size
+= DWARF_OFFSET_SIZE
;
4594 case dw_val_class_fde_ref
:
4595 size
+= DWARF_OFFSET_SIZE
;
4597 case dw_val_class_lbl_id
:
4600 case dw_val_class_section_offset
:
4601 size
+= DWARF_OFFSET_SIZE
;
4603 case dw_val_class_str
:
4604 size
+= size_of_string (a
->dw_attr_val
.v
.val_str
);
4614 /* Size the debugging information associated with a given DIE.
4615 Visits the DIE's children recursively. Updates the global
4616 variable next_die_offset, on each time through. Uses the
4617 current value of next_die_offset to update the die_offset
4618 field in each DIE. */
4621 calc_die_sizes (die
)
4624 register dw_die_ref c
;
4625 die
->die_offset
= next_die_offset
;
4626 next_die_offset
+= size_of_die (die
);
4628 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4631 if (die
->die_child
!= NULL
)
4632 /* Count the null byte used to terminate sibling lists. */
4633 next_die_offset
+= 1;
4636 /* Return the size of the line information prolog generated for the
4637 compilation unit. */
4639 static unsigned long
4640 size_of_line_prolog ()
4642 register unsigned long size
;
4643 register unsigned long ft_index
;
4645 size
= DWARF_LINE_PROLOG_HEADER_SIZE
;
4647 /* Count the size of the table giving number of args for each
4649 size
+= DWARF_LINE_OPCODE_BASE
- 1;
4651 /* Include directory table is empty (at present). Count only the
4652 the null byte used to terminate the table. */
4655 for (ft_index
= 1; ft_index
< file_table_in_use
; ++ft_index
)
4657 /* File name entry. */
4658 size
+= size_of_string (file_table
[ft_index
]);
4660 /* Include directory index. */
4661 size
+= size_of_uleb128 (0);
4663 /* Modification time. */
4664 size
+= size_of_uleb128 (0);
4666 /* File length in bytes. */
4667 size
+= size_of_uleb128 (0);
4670 /* Count the file table terminator. */
4675 /* Return the size of the line information generated for this
4676 compilation unit. */
4678 static unsigned long
4679 size_of_line_info ()
4681 register unsigned long size
;
4682 register unsigned long lt_index
;
4683 register unsigned long current_line
;
4684 register long line_offset
;
4685 register long line_delta
;
4686 register unsigned long current_file
;
4687 register unsigned long function
;
4688 unsigned long size_of_set_address
;
4690 /* Size of a DW_LNE_set_address instruction. */
4691 size_of_set_address
= 1 + size_of_uleb128 (1 + PTR_SIZE
) + 1 + PTR_SIZE
;
4693 /* Version number. */
4696 /* Prolog length specifier. */
4697 size
+= DWARF_OFFSET_SIZE
;
4700 size
+= size_of_line_prolog ();
4702 /* Set address register instruction. */
4703 size
+= size_of_set_address
;
4707 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
4709 register dw_line_info_ref line_info
;
4711 /* Advance pc instruction. */
4712 /* ??? See the DW_LNS_advance_pc comment in output_line_info. */
4716 size
+= size_of_set_address
;
4718 line_info
= &line_info_table
[lt_index
];
4719 if (line_info
->dw_file_num
!= current_file
)
4721 /* Set file number instruction. */
4723 current_file
= line_info
->dw_file_num
;
4724 size
+= size_of_uleb128 (current_file
);
4727 if (line_info
->dw_line_num
!= current_line
)
4729 line_offset
= line_info
->dw_line_num
- current_line
;
4730 line_delta
= line_offset
- DWARF_LINE_BASE
;
4731 current_line
= line_info
->dw_line_num
;
4732 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
4733 /* 1-byte special line number instruction. */
4737 /* Advance line instruction. */
4739 size
+= size_of_sleb128 (line_offset
);
4740 /* Generate line entry instruction. */
4746 /* Advance pc instruction. */
4750 size
+= size_of_set_address
;
4752 /* End of line number info. marker. */
4753 size
+= 1 + size_of_uleb128 (1) + 1;
4758 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
; )
4760 register dw_separate_line_info_ref line_info
4761 = &separate_line_info_table
[lt_index
];
4762 if (function
!= line_info
->function
)
4764 function
= line_info
->function
;
4765 /* Set address register instruction. */
4766 size
+= size_of_set_address
;
4770 /* Advance pc instruction. */
4774 size
+= size_of_set_address
;
4777 if (line_info
->dw_file_num
!= current_file
)
4779 /* Set file number instruction. */
4781 current_file
= line_info
->dw_file_num
;
4782 size
+= size_of_uleb128 (current_file
);
4785 if (line_info
->dw_line_num
!= current_line
)
4787 line_offset
= line_info
->dw_line_num
- current_line
;
4788 line_delta
= line_offset
- DWARF_LINE_BASE
;
4789 current_line
= line_info
->dw_line_num
;
4790 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
4791 /* 1-byte special line number instruction. */
4795 /* Advance line instruction. */
4797 size
+= size_of_sleb128 (line_offset
);
4799 /* Generate line entry instruction. */
4806 /* If we're done with a function, end its sequence. */
4807 if (lt_index
== separate_line_info_table_in_use
4808 || separate_line_info_table
[lt_index
].function
!= function
)
4813 /* Advance pc instruction. */
4817 size
+= size_of_set_address
;
4819 /* End of line number info. marker. */
4820 size
+= 1 + size_of_uleb128 (1) + 1;
4827 /* Return the size of the .debug_pubnames table generated for the
4828 compilation unit. */
4830 static unsigned long
4833 register unsigned long size
;
4834 register unsigned i
;
4836 size
= DWARF_PUBNAMES_HEADER_SIZE
;
4837 for (i
= 0; i
< pubname_table_in_use
; ++i
)
4839 register pubname_ref p
= &pubname_table
[i
];
4840 size
+= DWARF_OFFSET_SIZE
+ size_of_string (p
->name
);
4843 size
+= DWARF_OFFSET_SIZE
;
4847 /* Return the size of the information in the .debug_aranges section. */
4849 static unsigned long
4852 register unsigned long size
;
4854 size
= DWARF_ARANGES_HEADER_SIZE
;
4856 /* Count the address/length pair for this compilation unit. */
4857 size
+= 2 * PTR_SIZE
;
4858 size
+= 2 * PTR_SIZE
* arange_table_in_use
;
4860 /* Count the two zero words used to terminated the address range table. */
4861 size
+= 2 * PTR_SIZE
;
4865 /* Select the encoding of an attribute value. */
4867 static enum dwarf_form
4871 switch (v
->val_class
)
4873 case dw_val_class_addr
:
4874 return DW_FORM_addr
;
4875 case dw_val_class_loc
:
4876 switch (constant_size (size_of_locs (v
->v
.val_loc
)))
4879 return DW_FORM_block1
;
4881 return DW_FORM_block2
;
4885 case dw_val_class_const
:
4886 return DW_FORM_data4
;
4887 case dw_val_class_unsigned_const
:
4888 switch (constant_size (v
->v
.val_unsigned
))
4891 return DW_FORM_data1
;
4893 return DW_FORM_data2
;
4895 return DW_FORM_data4
;
4897 return DW_FORM_data8
;
4901 case dw_val_class_long_long
:
4902 return DW_FORM_block1
;
4903 case dw_val_class_float
:
4904 return DW_FORM_block1
;
4905 case dw_val_class_flag
:
4906 return DW_FORM_flag
;
4907 case dw_val_class_die_ref
:
4909 case dw_val_class_fde_ref
:
4910 return DW_FORM_data
;
4911 case dw_val_class_lbl_id
:
4912 return DW_FORM_addr
;
4913 case dw_val_class_section_offset
:
4914 return DW_FORM_data
;
4915 case dw_val_class_str
:
4916 return DW_FORM_string
;
4922 /* Output the encoding of an attribute value. */
4925 output_value_format (v
)
4928 enum dwarf_form form
= value_format (v
);
4930 output_uleb128 (form
);
4932 fprintf (asm_out_file
, " (%s)", dwarf_form_name (form
));
4934 fputc ('\n', asm_out_file
);
4937 /* Output the .debug_abbrev section which defines the DIE abbreviation
4941 output_abbrev_section ()
4943 unsigned long abbrev_id
;
4946 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
4948 register dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
4950 output_uleb128 (abbrev_id
);
4952 fprintf (asm_out_file
, " (abbrev code)");
4954 fputc ('\n', asm_out_file
);
4955 output_uleb128 (abbrev
->die_tag
);
4957 fprintf (asm_out_file
, " (TAG: %s)",
4958 dwarf_tag_name (abbrev
->die_tag
));
4960 fputc ('\n', asm_out_file
);
4961 fprintf (asm_out_file
, "\t%s\t0x%x", ASM_BYTE_OP
,
4962 abbrev
->die_child
!= NULL
? DW_children_yes
: DW_children_no
);
4965 fprintf (asm_out_file
, "\t%s %s",
4967 (abbrev
->die_child
!= NULL
4968 ? "DW_children_yes" : "DW_children_no"));
4970 fputc ('\n', asm_out_file
);
4972 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
4973 a_attr
= a_attr
->dw_attr_next
)
4975 output_uleb128 (a_attr
->dw_attr
);
4977 fprintf (asm_out_file
, " (%s)",
4978 dwarf_attr_name (a_attr
->dw_attr
));
4980 fputc ('\n', asm_out_file
);
4981 output_value_format (&a_attr
->dw_attr_val
);
4984 fprintf (asm_out_file
, "\t%s\t0,0\n", ASM_BYTE_OP
);
4988 /* Output location description stack opcode's operands (if any). */
4991 output_loc_operands (loc
)
4992 register dw_loc_descr_ref loc
;
4994 register dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
4995 register dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
4997 switch (loc
->dw_loc_opc
)
5000 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
, val1
->v
.val_addr
);
5001 fputc ('\n', asm_out_file
);
5005 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_flag
);
5006 fputc ('\n', asm_out_file
);
5010 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, val1
->v
.val_int
);
5011 fputc ('\n', asm_out_file
);
5015 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, val1
->v
.val_int
);
5016 fputc ('\n', asm_out_file
);
5021 fputc ('\n', asm_out_file
);
5024 output_uleb128 (val1
->v
.val_unsigned
);
5025 fputc ('\n', asm_out_file
);
5028 output_sleb128 (val1
->v
.val_int
);
5029 fputc ('\n', asm_out_file
);
5032 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_int
);
5033 fputc ('\n', asm_out_file
);
5035 case DW_OP_plus_uconst
:
5036 output_uleb128 (val1
->v
.val_unsigned
);
5037 fputc ('\n', asm_out_file
);
5041 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, val1
->v
.val_int
);
5042 fputc ('\n', asm_out_file
);
5076 output_sleb128 (val1
->v
.val_int
);
5077 fputc ('\n', asm_out_file
);
5080 output_uleb128 (val1
->v
.val_unsigned
);
5081 fputc ('\n', asm_out_file
);
5084 output_sleb128 (val1
->v
.val_int
);
5085 fputc ('\n', asm_out_file
);
5088 output_uleb128 (val1
->v
.val_unsigned
);
5089 fputc ('\n', asm_out_file
);
5090 output_sleb128 (val2
->v
.val_int
);
5091 fputc ('\n', asm_out_file
);
5094 output_uleb128 (val1
->v
.val_unsigned
);
5095 fputc ('\n', asm_out_file
);
5097 case DW_OP_deref_size
:
5098 case DW_OP_xderef_size
:
5099 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_flag
);
5100 fputc ('\n', asm_out_file
);
5107 /* Compute the offset of a sibling. */
5109 static unsigned long
5110 sibling_offset (die
)
5113 unsigned long offset
;
5115 if (die
->die_child_last
== NULL
)
5116 offset
= die
->die_offset
+ size_of_die (die
);
5118 offset
= sibling_offset (die
->die_child_last
) + 1;
5123 /* Output the DIE and its attributes. Called recursively to generate
5124 the definitions of each child DIE. */
5128 register dw_die_ref die
;
5130 register dw_attr_ref a
;
5131 register dw_die_ref c
;
5132 register unsigned long ref_offset
;
5133 register unsigned long size
;
5134 register dw_loc_descr_ref loc
;
5137 output_uleb128 (die
->die_abbrev
);
5139 fprintf (asm_out_file
, " (DIE (0x%x) %s)",
5140 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5142 fputc ('\n', asm_out_file
);
5144 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5146 switch (a
->dw_attr_val
.val_class
)
5148 case dw_val_class_addr
:
5149 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
,
5150 a
->dw_attr_val
.v
.val_addr
);
5153 case dw_val_class_loc
:
5154 size
= size_of_locs (a
->dw_attr_val
.v
.val_loc
);
5156 /* Output the block length for this list of location operations. */
5157 switch (constant_size (size
))
5160 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, size
);
5163 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, size
);
5170 fprintf (asm_out_file
, "\t%s %s",
5171 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5173 fputc ('\n', asm_out_file
);
5174 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
;
5175 loc
= loc
->dw_loc_next
)
5177 /* Output the opcode. */
5178 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, loc
->dw_loc_opc
);
5180 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
,
5181 dwarf_stack_op_name (loc
->dw_loc_opc
));
5183 fputc ('\n', asm_out_file
);
5185 /* Output the operand(s) (if any). */
5186 output_loc_operands (loc
);
5190 case dw_val_class_const
:
5191 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, a
->dw_attr_val
.v
.val_int
);
5194 case dw_val_class_unsigned_const
:
5195 switch (constant_size (a
->dw_attr_val
.v
.val_unsigned
))
5198 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
5199 a
->dw_attr_val
.v
.val_unsigned
);
5202 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
,
5203 a
->dw_attr_val
.v
.val_unsigned
);
5206 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
,
5207 a
->dw_attr_val
.v
.val_unsigned
);
5210 ASM_OUTPUT_DWARF_DATA8 (asm_out_file
,
5211 a
->dw_attr_val
.v
.val_long_long
.hi
,
5212 a
->dw_attr_val
.v
.val_long_long
.low
);
5219 case dw_val_class_long_long
:
5220 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 8);
5222 fprintf (asm_out_file
, "\t%s %s",
5223 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5225 fputc ('\n', asm_out_file
);
5226 ASM_OUTPUT_DWARF_DATA8 (asm_out_file
,
5227 a
->dw_attr_val
.v
.val_long_long
.hi
,
5228 a
->dw_attr_val
.v
.val_long_long
.low
);
5231 fprintf (asm_out_file
,
5232 "\t%s long long constant", ASM_COMMENT_START
);
5234 fputc ('\n', asm_out_file
);
5237 case dw_val_class_float
:
5238 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
5239 a
->dw_attr_val
.v
.val_float
.length
* 4);
5241 fprintf (asm_out_file
, "\t%s %s",
5242 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5244 fputc ('\n', asm_out_file
);
5245 for (i
= 0; i
< a
->dw_attr_val
.v
.val_float
.length
; ++i
)
5247 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
,
5248 a
->dw_attr_val
.v
.val_float
.array
[i
]);
5250 fprintf (asm_out_file
, "\t%s fp constant word %d",
5251 ASM_COMMENT_START
, i
);
5253 fputc ('\n', asm_out_file
);
5257 case dw_val_class_flag
:
5258 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, a
->dw_attr_val
.v
.val_flag
);
5261 case dw_val_class_die_ref
:
5262 if (a
->dw_attr_val
.v
.val_die_ref
!= NULL
)
5263 ref_offset
= a
->dw_attr_val
.v
.val_die_ref
->die_offset
;
5264 else if (a
->dw_attr
== DW_AT_sibling
)
5265 ref_offset
= sibling_offset(die
);
5269 ASM_OUTPUT_DWARF_DATA (asm_out_file
, ref_offset
);
5272 case dw_val_class_fde_ref
:
5275 ASM_GENERATE_INTERNAL_LABEL
5276 (l1
, FDE_AFTER_SIZE_LABEL
, a
->dw_attr_val
.v
.val_fde_index
* 2);
5277 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, l1
);
5278 fprintf (asm_out_file
, " - %d", DWARF_OFFSET_SIZE
);
5282 case dw_val_class_lbl_id
:
5283 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, a
->dw_attr_val
.v
.val_lbl_id
);
5286 case dw_val_class_section_offset
:
5287 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
,
5289 (a
->dw_attr_val
.v
.val_section
));
5292 case dw_val_class_str
:
5294 ASM_OUTPUT_DWARF_STRING (asm_out_file
, a
->dw_attr_val
.v
.val_str
);
5296 ASM_OUTPUT_ASCII (asm_out_file
,
5297 a
->dw_attr_val
.v
.val_str
,
5298 strlen (a
->dw_attr_val
.v
.val_str
) + 1);
5305 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
5306 && a
->dw_attr_val
.val_class
!= dw_val_class_long_long
5307 && a
->dw_attr_val
.val_class
!= dw_val_class_float
)
5310 fprintf (asm_out_file
, "\t%s %s",
5311 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5313 fputc ('\n', asm_out_file
);
5317 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5320 if (die
->die_child
!= NULL
)
5322 /* Add null byte to terminate sibling list. */
5323 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5325 fprintf (asm_out_file
, "\t%s end of children of DIE 0x%x",
5326 ASM_COMMENT_START
, die
->die_offset
);
5328 fputc ('\n', asm_out_file
);
5332 /* Output the compilation unit that appears at the beginning of the
5333 .debug_info section, and precedes the DIE descriptions. */
5336 output_compilation_unit_header ()
5338 ASM_OUTPUT_DWARF_DATA (asm_out_file
, next_die_offset
- DWARF_OFFSET_SIZE
);
5340 fprintf (asm_out_file
, "\t%s Length of Compilation Unit Info.",
5343 fputc ('\n', asm_out_file
);
5344 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5346 fprintf (asm_out_file
, "\t%s DWARF version number", ASM_COMMENT_START
);
5348 fputc ('\n', asm_out_file
);
5349 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, stripattributes (ABBREV_SECTION
));
5351 fprintf (asm_out_file
, "\t%s Offset Into Abbrev. Section",
5354 fputc ('\n', asm_out_file
);
5355 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, PTR_SIZE
);
5357 fprintf (asm_out_file
, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START
);
5359 fputc ('\n', asm_out_file
);
5362 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5363 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5364 argument list, and maybe the scope. */
5367 dwarf2_name (decl
, scope
)
5371 return (*decl_printable_name
) (decl
, scope
? 1 : 0);
5374 /* Add a new entry to .debug_pubnames if appropriate. */
5377 add_pubname (decl
, die
)
5383 if (! TREE_PUBLIC (decl
))
5386 if (pubname_table_in_use
== pubname_table_allocated
)
5388 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
5389 pubname_table
= (pubname_ref
) xrealloc
5390 (pubname_table
, pubname_table_allocated
* sizeof (pubname_entry
));
5393 p
= &pubname_table
[pubname_table_in_use
++];
5396 p
->name
= xstrdup (dwarf2_name (decl
, 1));
5399 /* Output the public names table used to speed up access to externally
5400 visible names. For now, only generate entries for externally
5401 visible procedures. */
5406 register unsigned i
;
5407 register unsigned long pubnames_length
= size_of_pubnames ();
5409 ASM_OUTPUT_DWARF_DATA (asm_out_file
, pubnames_length
);
5412 fprintf (asm_out_file
, "\t%s Length of Public Names Info.",
5415 fputc ('\n', asm_out_file
);
5416 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5419 fprintf (asm_out_file
, "\t%s DWARF Version", ASM_COMMENT_START
);
5421 fputc ('\n', asm_out_file
);
5422 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, stripattributes (DEBUG_INFO_SECTION
));
5424 fprintf (asm_out_file
, "\t%s Offset of Compilation Unit Info.",
5427 fputc ('\n', asm_out_file
);
5428 ASM_OUTPUT_DWARF_DATA (asm_out_file
, next_die_offset
);
5430 fprintf (asm_out_file
, "\t%s Compilation Unit Length", ASM_COMMENT_START
);
5432 fputc ('\n', asm_out_file
);
5433 for (i
= 0; i
< pubname_table_in_use
; ++i
)
5435 register pubname_ref pub
= &pubname_table
[i
];
5437 ASM_OUTPUT_DWARF_DATA (asm_out_file
, pub
->die
->die_offset
);
5439 fprintf (asm_out_file
, "\t%s DIE offset", ASM_COMMENT_START
);
5441 fputc ('\n', asm_out_file
);
5445 ASM_OUTPUT_DWARF_STRING (asm_out_file
, pub
->name
);
5446 fprintf (asm_out_file
, "%s external name", ASM_COMMENT_START
);
5450 ASM_OUTPUT_ASCII (asm_out_file
, pub
->name
, strlen (pub
->name
) + 1);
5453 fputc ('\n', asm_out_file
);
5456 ASM_OUTPUT_DWARF_DATA (asm_out_file
, 0);
5457 fputc ('\n', asm_out_file
);
5460 /* Add a new entry to .debug_aranges if appropriate. */
5463 add_arange (decl
, die
)
5467 if (! DECL_SECTION_NAME (decl
))
5470 if (arange_table_in_use
== arange_table_allocated
)
5472 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
5474 = (arange_ref
) xrealloc (arange_table
,
5475 arange_table_allocated
* sizeof (dw_die_ref
));
5478 arange_table
[arange_table_in_use
++] = die
;
5481 /* Output the information that goes into the .debug_aranges table.
5482 Namely, define the beginning and ending address range of the
5483 text section generated for this compilation unit. */
5488 register unsigned i
;
5489 register unsigned long aranges_length
= size_of_aranges ();
5491 ASM_OUTPUT_DWARF_DATA (asm_out_file
, aranges_length
);
5493 fprintf (asm_out_file
, "\t%s Length of Address Ranges Info.",
5496 fputc ('\n', asm_out_file
);
5497 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5499 fprintf (asm_out_file
, "\t%s DWARF Version", ASM_COMMENT_START
);
5501 fputc ('\n', asm_out_file
);
5502 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, stripattributes (DEBUG_INFO_SECTION
));
5504 fprintf (asm_out_file
, "\t%s Offset of Compilation Unit Info.",
5507 fputc ('\n', asm_out_file
);
5508 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, PTR_SIZE
);
5510 fprintf (asm_out_file
, "\t%s Size of Address", ASM_COMMENT_START
);
5512 fputc ('\n', asm_out_file
);
5513 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5515 fprintf (asm_out_file
, "\t%s Size of Segment Descriptor",
5518 fputc ('\n', asm_out_file
);
5519 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 4);
5521 fprintf (asm_out_file
, ",0,0");
5524 fprintf (asm_out_file
, "\t%s Pad to %d byte boundary",
5525 ASM_COMMENT_START
, 2 * PTR_SIZE
);
5527 fputc ('\n', asm_out_file
);
5528 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, TEXT_SECTION
);
5530 fprintf (asm_out_file
, "\t%s Address", ASM_COMMENT_START
);
5532 fputc ('\n', asm_out_file
);
5533 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
, text_end_label
, TEXT_SECTION
);
5535 fprintf (asm_out_file
, "%s Length", ASM_COMMENT_START
);
5537 fputc ('\n', asm_out_file
);
5538 for (i
= 0; i
< arange_table_in_use
; ++i
)
5540 dw_die_ref a
= arange_table
[i
];
5542 if (a
->die_tag
== DW_TAG_subprogram
)
5543 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, get_AT_low_pc (a
));
5546 char *name
= get_AT_string (a
, DW_AT_MIPS_linkage_name
);
5548 name
= get_AT_string (a
, DW_AT_name
);
5550 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, name
);
5554 fprintf (asm_out_file
, "\t%s Address", ASM_COMMENT_START
);
5556 fputc ('\n', asm_out_file
);
5557 if (a
->die_tag
== DW_TAG_subprogram
)
5558 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
, get_AT_hi_pc (a
),
5561 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
,
5562 get_AT_unsigned (a
, DW_AT_byte_size
));
5565 fprintf (asm_out_file
, "%s Length", ASM_COMMENT_START
);
5567 fputc ('\n', asm_out_file
);
5570 /* Output the terminator words. */
5571 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
, 0);
5572 fputc ('\n', asm_out_file
);
5573 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
, 0);
5574 fputc ('\n', asm_out_file
);
5577 /* Output the source line number correspondence information. This
5578 information goes into the .debug_line section.
5580 If the format of this data changes, then the function size_of_line_info
5581 must also be adjusted the same way. */
5586 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5587 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5588 register unsigned opc
;
5589 register unsigned n_op_args
;
5590 register unsigned long ft_index
;
5591 register unsigned long lt_index
;
5592 register unsigned long current_line
;
5593 register long line_offset
;
5594 register long line_delta
;
5595 register unsigned long current_file
;
5596 register unsigned long function
;
5598 ASM_OUTPUT_DWARF_DATA (asm_out_file
, size_of_line_info ());
5600 fprintf (asm_out_file
, "\t%s Length of Source Line Info.",
5603 fputc ('\n', asm_out_file
);
5604 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
5606 fprintf (asm_out_file
, "\t%s DWARF Version", ASM_COMMENT_START
);
5608 fputc ('\n', asm_out_file
);
5609 ASM_OUTPUT_DWARF_DATA (asm_out_file
, size_of_line_prolog ());
5611 fprintf (asm_out_file
, "\t%s Prolog Length", ASM_COMMENT_START
);
5613 fputc ('\n', asm_out_file
);
5614 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_LINE_MIN_INSTR_LENGTH
);
5616 fprintf (asm_out_file
, "\t%s Minimum Instruction Length",
5619 fputc ('\n', asm_out_file
);
5620 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_LINE_DEFAULT_IS_STMT_START
);
5622 fprintf (asm_out_file
, "\t%s Default is_stmt_start flag",
5625 fputc ('\n', asm_out_file
);
5626 fprintf (asm_out_file
, "\t%s\t%d", ASM_BYTE_OP
, DWARF_LINE_BASE
);
5628 fprintf (asm_out_file
, "\t%s Line Base Value (Special Opcodes)",
5631 fputc ('\n', asm_out_file
);
5632 fprintf (asm_out_file
, "\t%s\t%u", ASM_BYTE_OP
, DWARF_LINE_RANGE
);
5634 fprintf (asm_out_file
, "\t%s Line Range Value (Special Opcodes)",
5637 fputc ('\n', asm_out_file
);
5638 fprintf (asm_out_file
, "\t%s\t%u", ASM_BYTE_OP
, DWARF_LINE_OPCODE_BASE
);
5640 fprintf (asm_out_file
, "\t%s Special Opcode Base", ASM_COMMENT_START
);
5642 fputc ('\n', asm_out_file
);
5643 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; ++opc
)
5647 case DW_LNS_advance_pc
:
5648 case DW_LNS_advance_line
:
5649 case DW_LNS_set_file
:
5650 case DW_LNS_set_column
:
5651 case DW_LNS_fixed_advance_pc
:
5658 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, n_op_args
);
5660 fprintf (asm_out_file
, "\t%s opcode: 0x%x has %d args",
5661 ASM_COMMENT_START
, opc
, n_op_args
);
5662 fputc ('\n', asm_out_file
);
5666 fprintf (asm_out_file
, "%s Include Directory Table\n", ASM_COMMENT_START
);
5668 /* Include directory table is empty, at present */
5669 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5670 fputc ('\n', asm_out_file
);
5672 fprintf (asm_out_file
, "%s File Name Table\n", ASM_COMMENT_START
);
5674 for (ft_index
= 1; ft_index
< file_table_in_use
; ++ft_index
)
5678 ASM_OUTPUT_DWARF_STRING (asm_out_file
, file_table
[ft_index
]);
5679 fprintf (asm_out_file
, "%s File Entry: 0x%x",
5680 ASM_COMMENT_START
, ft_index
);
5684 ASM_OUTPUT_ASCII (asm_out_file
,
5685 file_table
[ft_index
],
5686 strlen (file_table
[ft_index
]) + 1);
5689 fputc ('\n', asm_out_file
);
5691 /* Include directory index */
5693 fputc ('\n', asm_out_file
);
5695 /* Modification time */
5697 fputc ('\n', asm_out_file
);
5699 /* File length in bytes */
5701 fputc ('\n', asm_out_file
);
5704 /* Terminate the file name table */
5705 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5706 fputc ('\n', asm_out_file
);
5708 /* Set the address register to the first location in the text section */
5709 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5711 fprintf (asm_out_file
, "\t%s DW_LNE_set_address", ASM_COMMENT_START
);
5713 fputc ('\n', asm_out_file
);
5714 output_uleb128 (1 + PTR_SIZE
);
5715 fputc ('\n', asm_out_file
);
5716 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5717 fputc ('\n', asm_out_file
);
5718 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, TEXT_SECTION
);
5719 fputc ('\n', asm_out_file
);
5721 /* Generate the line number to PC correspondence table, encoded as
5722 a series of state machine operations. */
5725 strcpy (prev_line_label
, TEXT_SECTION
);
5726 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
5728 register dw_line_info_ref line_info
;
5730 /* Emit debug info for the address of the current line, choosing
5731 the encoding that uses the least amount of space. */
5732 /* ??? Unfortunately, we have little choice here currently, and must
5733 always use the most general form. Gcc does not know the address
5734 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5735 dwarf2 aware assemblers at this time, so we can't use any special
5736 pseudo ops that would allow the assembler to optimally encode this for
5737 us. Many ports do have length attributes which will give an upper
5738 bound on the address range. We could perhaps use length attributes
5739 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5740 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
5743 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5744 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
5746 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
5749 fputc ('\n', asm_out_file
);
5750 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
, prev_line_label
);
5751 fputc ('\n', asm_out_file
);
5755 /* This can handle any delta. This takes 4+PTR_SIZE bytes. */
5756 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5758 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
5760 fputc ('\n', asm_out_file
);
5761 output_uleb128 (1 + PTR_SIZE
);
5762 fputc ('\n', asm_out_file
);
5763 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5764 fputc ('\n', asm_out_file
);
5765 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
5766 fputc ('\n', asm_out_file
);
5768 strcpy (prev_line_label
, line_label
);
5770 /* Emit debug info for the source file of the current line, if
5771 different from the previous line. */
5772 line_info
= &line_info_table
[lt_index
];
5773 if (line_info
->dw_file_num
!= current_file
)
5775 current_file
= line_info
->dw_file_num
;
5776 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_set_file
);
5778 fprintf (asm_out_file
, "\t%s DW_LNS_set_file", ASM_COMMENT_START
);
5780 fputc ('\n', asm_out_file
);
5781 output_uleb128 (current_file
);
5783 fprintf (asm_out_file
, " (\"%s\")", file_table
[current_file
]);
5785 fputc ('\n', asm_out_file
);
5788 /* Emit debug info for the current line number, choosing the encoding
5789 that uses the least amount of space. */
5790 line_offset
= line_info
->dw_line_num
- current_line
;
5791 line_delta
= line_offset
- DWARF_LINE_BASE
;
5792 current_line
= line_info
->dw_line_num
;
5793 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
5795 /* This can handle deltas from -10 to 234, using the current
5796 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5798 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
5799 DWARF_LINE_OPCODE_BASE
+ line_delta
);
5801 fprintf (asm_out_file
,
5802 "\t%s line %d", ASM_COMMENT_START
, current_line
);
5804 fputc ('\n', asm_out_file
);
5808 /* This can handle any delta. This takes at least 4 bytes, depending
5809 on the value being encoded. */
5810 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_advance_line
);
5812 fprintf (asm_out_file
, "\t%s advance to line %d",
5813 ASM_COMMENT_START
, current_line
);
5815 fputc ('\n', asm_out_file
);
5816 output_sleb128 (line_offset
);
5817 fputc ('\n', asm_out_file
);
5818 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
5819 fputc ('\n', asm_out_file
);
5823 /* Emit debug info for the address of the end of the function. */
5826 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
5828 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
5831 fputc ('\n', asm_out_file
);
5832 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, text_end_label
, prev_line_label
);
5833 fputc ('\n', asm_out_file
);
5837 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5839 fprintf (asm_out_file
, "\t%s DW_LNE_set_address", ASM_COMMENT_START
);
5840 fputc ('\n', asm_out_file
);
5841 output_uleb128 (1 + PTR_SIZE
);
5842 fputc ('\n', asm_out_file
);
5843 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5844 fputc ('\n', asm_out_file
);
5845 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, text_end_label
);
5846 fputc ('\n', asm_out_file
);
5849 /* Output the marker for the end of the line number info. */
5850 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5852 fprintf (asm_out_file
, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START
);
5854 fputc ('\n', asm_out_file
);
5856 fputc ('\n', asm_out_file
);
5857 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_end_sequence
);
5858 fputc ('\n', asm_out_file
);
5863 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
; )
5865 register dw_separate_line_info_ref line_info
5866 = &separate_line_info_table
[lt_index
];
5868 /* Emit debug info for the address of the current line. If this is
5869 a new function, or the first line of a function, then we need
5870 to handle it differently. */
5871 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
5873 if (function
!= line_info
->function
)
5875 function
= line_info
->function
;
5877 /* Set the address register to the first line in the function */
5878 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5880 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
5883 fputc ('\n', asm_out_file
);
5884 output_uleb128 (1 + PTR_SIZE
);
5885 fputc ('\n', asm_out_file
);
5886 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5887 fputc ('\n', asm_out_file
);
5888 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
5889 fputc ('\n', asm_out_file
);
5893 /* ??? See the DW_LNS_advance_pc comment above. */
5896 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
5898 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
5901 fputc ('\n', asm_out_file
);
5902 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
,
5904 fputc ('\n', asm_out_file
);
5908 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5910 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
5912 fputc ('\n', asm_out_file
);
5913 output_uleb128 (1 + PTR_SIZE
);
5914 fputc ('\n', asm_out_file
);
5915 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
5916 fputc ('\n', asm_out_file
);
5917 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
5918 fputc ('\n', asm_out_file
);
5921 strcpy (prev_line_label
, line_label
);
5923 /* Emit debug info for the source file of the current line, if
5924 different from the previous line. */
5925 if (line_info
->dw_file_num
!= current_file
)
5927 current_file
= line_info
->dw_file_num
;
5928 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_set_file
);
5930 fprintf (asm_out_file
, "\t%s DW_LNS_set_file", ASM_COMMENT_START
);
5932 fputc ('\n', asm_out_file
);
5933 output_uleb128 (current_file
);
5935 fprintf (asm_out_file
, " (\"%s\")", file_table
[current_file
]);
5937 fputc ('\n', asm_out_file
);
5940 /* Emit debug info for the current line number, choosing the encoding
5941 that uses the least amount of space. */
5942 if (line_info
->dw_line_num
!= current_line
)
5944 line_offset
= line_info
->dw_line_num
- current_line
;
5945 line_delta
= line_offset
- DWARF_LINE_BASE
;
5946 current_line
= line_info
->dw_line_num
;
5947 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
5949 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
5950 DWARF_LINE_OPCODE_BASE
+ line_delta
);
5952 fprintf (asm_out_file
,
5953 "\t%s line %d", ASM_COMMENT_START
, current_line
);
5955 fputc ('\n', asm_out_file
);
5959 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_advance_line
);
5961 fprintf (asm_out_file
, "\t%s advance to line %d",
5962 ASM_COMMENT_START
, current_line
);
5964 fputc ('\n', asm_out_file
);
5965 output_sleb128 (line_offset
);
5966 fputc ('\n', asm_out_file
);
5967 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
5968 fputc ('\n', asm_out_file
);
5974 /* If we're done with a function, end its sequence. */
5975 if (lt_index
== separate_line_info_table_in_use
5976 || separate_line_info_table
[lt_index
].function
!= function
)
5981 /* Emit debug info for the address of the end of the function. */
5982 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
5985 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
5987 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
5990 fputc ('\n', asm_out_file
);
5991 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
,
5993 fputc ('\n', asm_out_file
);
5997 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
5999 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
6001 fputc ('\n', asm_out_file
);
6002 output_uleb128 (1 + PTR_SIZE
);
6003 fputc ('\n', asm_out_file
);
6004 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
6005 fputc ('\n', asm_out_file
);
6006 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
6007 fputc ('\n', asm_out_file
);
6010 /* Output the marker for the end of this sequence. */
6011 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
6013 fprintf (asm_out_file
, "\t%s DW_LNE_end_sequence",
6016 fputc ('\n', asm_out_file
);
6018 fputc ('\n', asm_out_file
);
6019 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_end_sequence
);
6020 fputc ('\n', asm_out_file
);
6025 /* Given a pointer to a BLOCK node return non-zero if (and only if) the node
6026 in question represents the outermost pair of curly braces (i.e. the "body
6027 block") of a function or method.
6029 For any BLOCK node representing a "body block" of a function or method, the
6030 BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
6031 represents the outermost (function) scope for the function or method (i.e.
6032 the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
6033 *that* node in turn will point to the relevant FUNCTION_DECL node. */
6036 is_body_block (stmt
)
6039 if (TREE_CODE (stmt
) == BLOCK
)
6041 register tree parent
= BLOCK_SUPERCONTEXT (stmt
);
6043 if (TREE_CODE (parent
) == BLOCK
)
6045 register tree grandparent
= BLOCK_SUPERCONTEXT (parent
);
6047 if (TREE_CODE (grandparent
) == FUNCTION_DECL
)
6055 /* Given a pointer to a tree node for some base type, return a pointer to
6056 a DIE that describes the given type.
6058 This routine must only be called for GCC type nodes that correspond to
6059 Dwarf base (fundamental) types. */
6062 base_type_die (type
)
6065 register dw_die_ref base_type_result
;
6066 register char *type_name
;
6067 register enum dwarf_type encoding
;
6068 register tree name
= TYPE_NAME (type
);
6070 if (TREE_CODE (type
) == ERROR_MARK
6071 || TREE_CODE (type
) == VOID_TYPE
)
6074 if (TREE_CODE (name
) == TYPE_DECL
)
6075 name
= DECL_NAME (name
);
6076 type_name
= IDENTIFIER_POINTER (name
);
6078 switch (TREE_CODE (type
))
6081 /* Carefully distinguish the C character types, without messing
6082 up if the language is not C. Note that we check only for the names
6083 that contain spaces; other names might occur by coincidence in other
6085 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
6086 && (type
== char_type_node
6087 || ! strcmp (type_name
, "signed char")
6088 || ! strcmp (type_name
, "unsigned char"))))
6090 if (TREE_UNSIGNED (type
))
6091 encoding
= DW_ATE_unsigned
;
6093 encoding
= DW_ATE_signed
;
6096 /* else fall through */
6099 /* GNU Pascal/Ada CHAR type. Not used in C. */
6100 if (TREE_UNSIGNED (type
))
6101 encoding
= DW_ATE_unsigned_char
;
6103 encoding
= DW_ATE_signed_char
;
6107 encoding
= DW_ATE_float
;
6111 encoding
= DW_ATE_complex_float
;
6115 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6116 encoding
= DW_ATE_boolean
;
6120 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6123 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
);
6124 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
6125 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
6126 TYPE_PRECISION (type
) / BITS_PER_UNIT
);
6127 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
6129 return base_type_result
;
6132 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6133 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6134 a given type is generally the same as the given type, except that if the
6135 given type is a pointer or reference type, then the root type of the given
6136 type is the root type of the "basis" type for the pointer or reference
6137 type. (This definition of the "root" type is recursive.) Also, the root
6138 type of a `const' qualified type or a `volatile' qualified type is the
6139 root type of the given type without the qualifiers. */
6145 if (TREE_CODE (type
) == ERROR_MARK
)
6146 return error_mark_node
;
6148 switch (TREE_CODE (type
))
6151 return error_mark_node
;
6154 case REFERENCE_TYPE
:
6155 return type_main_variant (root_type (TREE_TYPE (type
)));
6158 return type_main_variant (type
);
6162 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6163 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6169 switch (TREE_CODE (type
))
6184 case QUAL_UNION_TYPE
:
6189 case REFERENCE_TYPE
:
6202 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6203 entry that chains various modifiers in front of the given type. */
6206 modified_type_die (type
, is_const_type
, is_volatile_type
, context_die
)
6208 register int is_const_type
;
6209 register int is_volatile_type
;
6210 register dw_die_ref context_die
;
6212 register enum tree_code code
= TREE_CODE (type
);
6213 register dw_die_ref mod_type_die
= NULL
;
6214 register dw_die_ref sub_die
= NULL
;
6215 register tree item_type
= NULL
;
6217 if (code
!= ERROR_MARK
)
6219 type
= build_type_variant (type
, is_const_type
, is_volatile_type
);
6221 mod_type_die
= lookup_type_die (type
);
6223 return mod_type_die
;
6225 /* Handle C typedef types. */
6226 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
6227 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
6229 tree dtype
= TREE_TYPE (TYPE_NAME (type
));
6232 /* For a named type, use the typedef. */
6233 gen_type_die (type
, context_die
);
6234 mod_type_die
= lookup_type_die (type
);
6237 else if (is_const_type
< TYPE_READONLY (dtype
)
6238 || is_volatile_type
< TYPE_VOLATILE (dtype
))
6239 /* cv-unqualified version of named type. Just use the unnamed
6240 type to which it refers. */
6242 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)),
6243 is_const_type
, is_volatile_type
,
6245 /* Else cv-qualified version of named type; fall through. */
6250 else if (is_const_type
)
6252 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
);
6253 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
6255 else if (is_volatile_type
)
6257 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
);
6258 sub_die
= modified_type_die (type
, 0, 0, context_die
);
6260 else if (code
== POINTER_TYPE
)
6262 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
);
6263 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
6265 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
6267 item_type
= TREE_TYPE (type
);
6269 else if (code
== REFERENCE_TYPE
)
6271 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
);
6272 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
6274 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
6276 item_type
= TREE_TYPE (type
);
6278 else if (is_base_type (type
))
6279 mod_type_die
= base_type_die (type
);
6282 gen_type_die (type
, context_die
);
6284 /* We have to get the type_main_variant here (and pass that to the
6285 `lookup_type_die' routine) because the ..._TYPE node we have
6286 might simply be a *copy* of some original type node (where the
6287 copy was created to help us keep track of typedef names) and
6288 that copy might have a different TYPE_UID from the original
6290 mod_type_die
= lookup_type_die (type_main_variant (type
));
6291 if (mod_type_die
== NULL
)
6296 equate_type_number_to_die (type
, mod_type_die
);
6298 /* We must do this after the equate_type_number_to_die call, in case
6299 this is a recursive type. This ensures that the modified_type_die
6300 recursion will terminate even if the type is recursive. Recursive
6301 types are possible in Ada. */
6302 sub_die
= modified_type_die (item_type
,
6303 TYPE_READONLY (item_type
),
6304 TYPE_VOLATILE (item_type
),
6307 if (sub_die
!= NULL
)
6308 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
6310 return mod_type_die
;
6313 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6314 an enumerated type. */
6320 return TREE_CODE (type
) == ENUMERAL_TYPE
;
6323 /* Return a location descriptor that designates a machine register. */
6325 static dw_loc_descr_ref
6326 reg_loc_descriptor (rtl
)
6329 register dw_loc_descr_ref loc_result
= NULL
;
6330 register unsigned reg
= reg_number (rtl
);
6332 if (reg
>= 0 && reg
<= 31)
6333 loc_result
= new_loc_descr (DW_OP_reg0
+ reg
, 0, 0);
6335 loc_result
= new_loc_descr (DW_OP_regx
, reg
, 0);
6340 /* Return a location descriptor that designates a base+offset location. */
6342 static dw_loc_descr_ref
6343 based_loc_descr (reg
, offset
)
6347 register dw_loc_descr_ref loc_result
;
6348 /* For the "frame base", we use the frame pointer or stack pointer
6349 registers, since the RTL for local variables is relative to one of
6351 register unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
6352 ? HARD_FRAME_POINTER_REGNUM
6353 : STACK_POINTER_REGNUM
);
6356 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
6357 else if (reg
>= 0 && reg
<= 31)
6358 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
6360 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
6365 /* Return true if this RTL expression describes a base+offset calculation. */
6371 return (GET_CODE (rtl
) == PLUS
6372 && ((GET_CODE (XEXP (rtl
, 0)) == REG
6373 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
6376 /* The following routine converts the RTL for a variable or parameter
6377 (resident in memory) into an equivalent Dwarf representation of a
6378 mechanism for getting the address of that same variable onto the top of a
6379 hypothetical "address evaluation" stack.
6381 When creating memory location descriptors, we are effectively transforming
6382 the RTL for a memory-resident object into its Dwarf postfix expression
6383 equivalent. This routine recursively descends an RTL tree, turning
6384 it into Dwarf postfix code as it goes. */
6386 static dw_loc_descr_ref
6387 mem_loc_descriptor (rtl
)
6390 dw_loc_descr_ref mem_loc_result
= NULL
;
6391 /* Note that for a dynamically sized array, the location we will generate a
6392 description of here will be the lowest numbered location which is
6393 actually within the array. That's *not* necessarily the same as the
6394 zeroth element of the array. */
6396 switch (GET_CODE (rtl
))
6399 /* The case of a subreg may arise when we have a local (register)
6400 variable or a formal (register) parameter which doesn't quite fill
6401 up an entire register. For now, just assume that it is
6402 legitimate to make the Dwarf info refer to the whole register which
6403 contains the given subreg. */
6404 rtl
= XEXP (rtl
, 0);
6406 /* ... fall through ... */
6409 /* Whenever a register number forms a part of the description of the
6410 method for calculating the (dynamic) address of a memory resident
6411 object, DWARF rules require the register number be referred to as
6412 a "base register". This distinction is not based in any way upon
6413 what category of register the hardware believes the given register
6414 belongs to. This is strictly DWARF terminology we're dealing with
6415 here. Note that in cases where the location of a memory-resident
6416 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6417 OP_CONST (0)) the actual DWARF location descriptor that we generate
6418 may just be OP_BASEREG (basereg). This may look deceptively like
6419 the object in question was allocated to a register (rather than in
6420 memory) so DWARF consumers need to be aware of the subtle
6421 distinction between OP_REG and OP_BASEREG. */
6422 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
6426 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0));
6427 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
6432 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
6433 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
6434 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= addr_to_string (rtl
);
6438 if (is_based_loc (rtl
))
6439 mem_loc_result
= based_loc_descr (reg_number (XEXP (rtl
, 0)),
6440 INTVAL (XEXP (rtl
, 1)));
6443 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 0)));
6444 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 1)));
6445 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_plus
, 0, 0));
6450 /* If a pseudo-reg is optimized away, it is possible for it to
6451 be replaced with a MEM containing a multiply. */
6452 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 0)));
6453 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 1)));
6454 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
6458 mem_loc_result
= new_loc_descr (DW_OP_constu
, INTVAL (rtl
), 0);
6465 return mem_loc_result
;
6468 /* Return a descriptor that describes the concatenation of two locations.
6469 This is typically a complex variable. */
6471 static dw_loc_descr_ref
6472 concat_loc_descriptor (x0
, x1
)
6473 register rtx x0
, x1
;
6475 dw_loc_descr_ref cc_loc_result
= NULL
;
6477 if (!is_pseudo_reg (x0
)
6478 && (GET_CODE (x0
) != MEM
|| !is_pseudo_reg (XEXP (x0
, 0))))
6479 add_loc_descr (&cc_loc_result
, loc_descriptor (x0
));
6480 add_loc_descr (&cc_loc_result
,
6481 new_loc_descr (DW_OP_piece
, GET_MODE_SIZE (GET_MODE (x0
)), 0));
6483 if (!is_pseudo_reg (x1
)
6484 && (GET_CODE (x1
) != MEM
|| !is_pseudo_reg (XEXP (x1
, 0))))
6485 add_loc_descr (&cc_loc_result
, loc_descriptor (x1
));
6486 add_loc_descr (&cc_loc_result
,
6487 new_loc_descr (DW_OP_piece
, GET_MODE_SIZE (GET_MODE (x1
)), 0));
6489 return cc_loc_result
;
6492 /* Output a proper Dwarf location descriptor for a variable or parameter
6493 which is either allocated in a register or in a memory location. For a
6494 register, we just generate an OP_REG and the register number. For a
6495 memory location we provide a Dwarf postfix expression describing how to
6496 generate the (dynamic) address of the object onto the address stack. */
6498 static dw_loc_descr_ref
6499 loc_descriptor (rtl
)
6502 dw_loc_descr_ref loc_result
= NULL
;
6503 switch (GET_CODE (rtl
))
6506 /* The case of a subreg may arise when we have a local (register)
6507 variable or a formal (register) parameter which doesn't quite fill
6508 up an entire register. For now, just assume that it is
6509 legitimate to make the Dwarf info refer to the whole register which
6510 contains the given subreg. */
6511 rtl
= XEXP (rtl
, 0);
6513 /* ... fall through ... */
6516 loc_result
= reg_loc_descriptor (rtl
);
6520 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0));
6524 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
6534 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
6535 which is not less than the value itself. */
6537 static inline unsigned
6538 ceiling (value
, boundary
)
6539 register unsigned value
;
6540 register unsigned boundary
;
6542 return (((value
+ boundary
- 1) / boundary
) * boundary
);
6545 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6546 pointer to the declared type for the relevant field variable, or return
6547 `integer_type_node' if the given node turns out to be an
6556 if (TREE_CODE (decl
) == ERROR_MARK
)
6557 return integer_type_node
;
6559 type
= DECL_BIT_FIELD_TYPE (decl
);
6560 if (type
== NULL_TREE
)
6561 type
= TREE_TYPE (decl
);
6566 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6567 node, return the alignment in bits for the type, or else return
6568 BITS_PER_WORD if the node actually turns out to be an
6571 static inline unsigned
6572 simple_type_align_in_bits (type
)
6575 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
6578 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6579 node, return the size in bits for the type if it is a constant, or else
6580 return the alignment for the type if the type's size is not constant, or
6581 else return BITS_PER_WORD if the type actually turns out to be an
6584 static inline unsigned
6585 simple_type_size_in_bits (type
)
6588 if (TREE_CODE (type
) == ERROR_MARK
)
6589 return BITS_PER_WORD
;
6592 register tree type_size_tree
= TYPE_SIZE (type
);
6594 if (TREE_CODE (type_size_tree
) != INTEGER_CST
)
6595 return TYPE_ALIGN (type
);
6597 return (unsigned) TREE_INT_CST_LOW (type_size_tree
);
6601 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6602 return the byte offset of the lowest addressed byte of the "containing
6603 object" for the given FIELD_DECL, or return 0 if we are unable to
6604 determine what that offset is, either because the argument turns out to
6605 be a pointer to an ERROR_MARK node, or because the offset is actually
6606 variable. (We can't handle the latter case just yet). */
6609 field_byte_offset (decl
)
6612 register unsigned type_align_in_bytes
;
6613 register unsigned type_align_in_bits
;
6614 register unsigned type_size_in_bits
;
6615 register unsigned object_offset_in_align_units
;
6616 register unsigned object_offset_in_bits
;
6617 register unsigned object_offset_in_bytes
;
6619 register tree bitpos_tree
;
6620 register tree field_size_tree
;
6621 register unsigned bitpos_int
;
6622 register unsigned deepest_bitpos
;
6623 register unsigned field_size_in_bits
;
6625 if (TREE_CODE (decl
) == ERROR_MARK
)
6628 if (TREE_CODE (decl
) != FIELD_DECL
)
6631 type
= field_type (decl
);
6633 bitpos_tree
= DECL_FIELD_BITPOS (decl
);
6634 field_size_tree
= DECL_SIZE (decl
);
6636 /* We cannot yet cope with fields whose positions or sizes are variable, so
6637 for now, when we see such things, we simply return 0. Someday, we may
6638 be able to handle such cases, but it will be damn difficult. */
6639 if (TREE_CODE (bitpos_tree
) != INTEGER_CST
)
6641 bitpos_int
= (unsigned) TREE_INT_CST_LOW (bitpos_tree
);
6643 if (TREE_CODE (field_size_tree
) != INTEGER_CST
)
6646 field_size_in_bits
= (unsigned) TREE_INT_CST_LOW (field_size_tree
);
6647 type_size_in_bits
= simple_type_size_in_bits (type
);
6648 type_align_in_bits
= simple_type_align_in_bits (type
);
6649 type_align_in_bytes
= type_align_in_bits
/ BITS_PER_UNIT
;
6651 /* Note that the GCC front-end doesn't make any attempt to keep track of
6652 the starting bit offset (relative to the start of the containing
6653 structure type) of the hypothetical "containing object" for a bit-
6654 field. Thus, when computing the byte offset value for the start of the
6655 "containing object" of a bit-field, we must deduce this information on
6656 our own. This can be rather tricky to do in some cases. For example,
6657 handling the following structure type definition when compiling for an
6658 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6661 struct S { int field1; long long field2:31; };
6663 Fortunately, there is a simple rule-of-thumb which can be
6664 used in such cases. When compiling for an i386/i486, GCC will allocate
6665 8 bytes for the structure shown above. It decides to do this based upon
6666 one simple rule for bit-field allocation. Quite simply, GCC allocates
6667 each "containing object" for each bit-field at the first (i.e. lowest
6668 addressed) legitimate alignment boundary (based upon the required
6669 minimum alignment for the declared type of the field) which it can
6670 possibly use, subject to the condition that there is still enough
6671 available space remaining in the containing object (when allocated at
6672 the selected point) to fully accommodate all of the bits of the
6673 bit-field itself. This simple rule makes it obvious why GCC allocates
6674 8 bytes for each object of the structure type shown above. When looking
6675 for a place to allocate the "containing object" for `field2', the
6676 compiler simply tries to allocate a 64-bit "containing object" at each
6677 successive 32-bit boundary (starting at zero) until it finds a place to
6678 allocate that 64- bit field such that at least 31 contiguous (and
6679 previously unallocated) bits remain within that selected 64 bit field.
6680 (As it turns out, for the example above, the compiler finds that it is
6681 OK to allocate the "containing object" 64-bit field at bit-offset zero
6682 within the structure type.) Here we attempt to work backwards from the
6683 limited set of facts we're given, and we try to deduce from those facts,
6684 where GCC must have believed that the containing object started (within
6685 the structure type). The value we deduce is then used (by the callers of
6686 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6687 for fields (both bit-fields and, in the case of DW_AT_location, regular
6690 /* Figure out the bit-distance from the start of the structure to the
6691 "deepest" bit of the bit-field. */
6692 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
6694 /* This is the tricky part. Use some fancy footwork to deduce where the
6695 lowest addressed bit of the containing object must be. */
6696 object_offset_in_bits
6697 = ceiling (deepest_bitpos
, type_align_in_bits
) - type_size_in_bits
;
6699 /* Compute the offset of the containing object in "alignment units". */
6700 object_offset_in_align_units
= object_offset_in_bits
/ type_align_in_bits
;
6702 /* Compute the offset of the containing object in bytes. */
6703 object_offset_in_bytes
= object_offset_in_align_units
* type_align_in_bytes
;
6705 return object_offset_in_bytes
;
6708 /* The following routines define various Dwarf attributes and any data
6709 associated with them. */
6711 /* Add a location description attribute value to a DIE.
6713 This emits location attributes suitable for whole variables and
6714 whole parameters. Note that the location attributes for struct fields are
6715 generated by the routine `data_member_location_attribute' below. */
6718 add_AT_location_description (die
, attr_kind
, rtl
)
6720 enum dwarf_attribute attr_kind
;
6723 /* Handle a special case. If we are about to output a location descriptor
6724 for a variable or parameter which has been optimized out of existence,
6725 don't do that. A variable which has been optimized out
6726 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6727 Currently, in some rare cases, variables can have DECL_RTL values which
6728 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6729 elsewhere in the compiler. We treat such cases as if the variable(s) in
6730 question had been optimized out of existence. */
6732 if (is_pseudo_reg (rtl
)
6733 || (GET_CODE (rtl
) == MEM
6734 && is_pseudo_reg (XEXP (rtl
, 0)))
6735 || (GET_CODE (rtl
) == CONCAT
6736 && is_pseudo_reg (XEXP (rtl
, 0))
6737 && is_pseudo_reg (XEXP (rtl
, 1))))
6740 add_AT_loc (die
, attr_kind
, loc_descriptor (rtl
));
6743 /* Attach the specialized form of location attribute used for data
6744 members of struct and union types. In the special case of a
6745 FIELD_DECL node which represents a bit-field, the "offset" part
6746 of this special location descriptor must indicate the distance
6747 in bytes from the lowest-addressed byte of the containing struct
6748 or union type to the lowest-addressed byte of the "containing
6749 object" for the bit-field. (See the `field_byte_offset' function
6750 above).. For any given bit-field, the "containing object" is a
6751 hypothetical object (of some integral or enum type) within which
6752 the given bit-field lives. The type of this hypothetical
6753 "containing object" is always the same as the declared type of
6754 the individual bit-field itself (for GCC anyway... the DWARF
6755 spec doesn't actually mandate this). Note that it is the size
6756 (in bytes) of the hypothetical "containing object" which will
6757 be given in the DW_AT_byte_size attribute for this bit-field.
6758 (See the `byte_size_attribute' function below.) It is also used
6759 when calculating the value of the DW_AT_bit_offset attribute.
6760 (See the `bit_offset_attribute' function below). */
6763 add_data_member_location_attribute (die
, decl
)
6764 register dw_die_ref die
;
6767 register unsigned long offset
;
6768 register dw_loc_descr_ref loc_descr
;
6769 register enum dwarf_location_atom op
;
6771 if (TREE_CODE (decl
) == TREE_VEC
)
6772 offset
= TREE_INT_CST_LOW (BINFO_OFFSET (decl
));
6774 offset
= field_byte_offset (decl
);
6776 /* The DWARF2 standard says that we should assume that the structure address
6777 is already on the stack, so we can specify a structure field address
6778 by using DW_OP_plus_uconst. */
6780 #ifdef MIPS_DEBUGGING_INFO
6781 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6782 correctly. It works only if we leave the offset on the stack. */
6785 op
= DW_OP_plus_uconst
;
6788 loc_descr
= new_loc_descr (op
, offset
, 0);
6789 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
6792 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6793 does not have a "location" either in memory or in a register. These
6794 things can arise in GNU C when a constant is passed as an actual parameter
6795 to an inlined function. They can also arise in C++ where declared
6796 constants do not necessarily get memory "homes". */
6799 add_const_value_attribute (die
, rtl
)
6800 register dw_die_ref die
;
6803 switch (GET_CODE (rtl
))
6806 /* Note that a CONST_INT rtx could represent either an integer or a
6807 floating-point constant. A CONST_INT is used whenever the constant
6808 will fit into a single word. In all such cases, the original mode
6809 of the constant value is wiped out, and the CONST_INT rtx is
6810 assigned VOIDmode. */
6811 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned) INTVAL (rtl
));
6815 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6816 floating-point constant. A CONST_DOUBLE is used whenever the
6817 constant requires more than one word in order to be adequately
6818 represented. We output CONST_DOUBLEs as blocks. */
6820 register enum machine_mode mode
= GET_MODE (rtl
);
6822 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
6824 register unsigned length
= GET_MODE_SIZE (mode
) / sizeof (long);
6828 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
6832 REAL_VALUE_TO_TARGET_SINGLE (rv
, array
[0]);
6836 REAL_VALUE_TO_TARGET_DOUBLE (rv
, array
);
6841 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv
, array
);
6848 add_AT_float (die
, DW_AT_const_value
, length
, array
);
6851 add_AT_long_long (die
, DW_AT_const_value
,
6852 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
6857 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
6863 add_AT_addr (die
, DW_AT_const_value
, addr_to_string (rtl
));
6867 /* In cases where an inlined instance of an inline function is passed
6868 the address of an `auto' variable (which is local to the caller) we
6869 can get a situation where the DECL_RTL of the artificial local
6870 variable (for the inlining) which acts as a stand-in for the
6871 corresponding formal parameter (of the inline function) will look
6872 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6873 exactly a compile-time constant expression, but it isn't the address
6874 of the (artificial) local variable either. Rather, it represents the
6875 *value* which the artificial local variable always has during its
6876 lifetime. We currently have no way to represent such quasi-constant
6877 values in Dwarf, so for now we just punt and generate nothing. */
6881 /* No other kinds of rtx should be possible here. */
6887 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6888 data attribute for a variable or a parameter. We generate the
6889 DW_AT_const_value attribute only in those cases where the given variable
6890 or parameter does not have a true "location" either in memory or in a
6891 register. This can happen (for example) when a constant is passed as an
6892 actual argument in a call to an inline function. (It's possible that
6893 these things can crop up in other ways also.) Note that one type of
6894 constant value which can be passed into an inlined function is a constant
6895 pointer. This can happen for example if an actual argument in an inlined
6896 function call evaluates to a compile-time constant address. */
6899 add_location_or_const_value_attribute (die
, decl
)
6900 register dw_die_ref die
;
6904 register tree declared_type
;
6905 register tree passed_type
;
6907 if (TREE_CODE (decl
) == ERROR_MARK
)
6910 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
)
6913 /* Here we have to decide where we are going to say the parameter "lives"
6914 (as far as the debugger is concerned). We only have a couple of
6915 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6917 DECL_RTL normally indicates where the parameter lives during most of the
6918 activation of the function. If optimization is enabled however, this
6919 could be either NULL or else a pseudo-reg. Both of those cases indicate
6920 that the parameter doesn't really live anywhere (as far as the code
6921 generation parts of GCC are concerned) during most of the function's
6922 activation. That will happen (for example) if the parameter is never
6923 referenced within the function.
6925 We could just generate a location descriptor here for all non-NULL
6926 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6927 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6928 where DECL_RTL is NULL or is a pseudo-reg.
6930 Note however that we can only get away with using DECL_INCOMING_RTL as
6931 a backup substitute for DECL_RTL in certain limited cases. In cases
6932 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6933 we can be sure that the parameter was passed using the same type as it is
6934 declared to have within the function, and that its DECL_INCOMING_RTL
6935 points us to a place where a value of that type is passed.
6937 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6938 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6939 because in these cases DECL_INCOMING_RTL points us to a value of some
6940 type which is *different* from the type of the parameter itself. Thus,
6941 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6942 such cases, the debugger would end up (for example) trying to fetch a
6943 `float' from a place which actually contains the first part of a
6944 `double'. That would lead to really incorrect and confusing
6945 output at debug-time.
6947 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6948 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6949 are a couple of exceptions however. On little-endian machines we can
6950 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6951 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6952 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6953 when (on a little-endian machine) a non-prototyped function has a
6954 parameter declared to be of type `short' or `char'. In such cases,
6955 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6956 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6957 passed `int' value. If the debugger then uses that address to fetch
6958 a `short' or a `char' (on a little-endian machine) the result will be
6959 the correct data, so we allow for such exceptional cases below.
6961 Note that our goal here is to describe the place where the given formal
6962 parameter lives during most of the function's activation (i.e. between
6963 the end of the prologue and the start of the epilogue). We'll do that
6964 as best as we can. Note however that if the given formal parameter is
6965 modified sometime during the execution of the function, then a stack
6966 backtrace (at debug-time) will show the function as having been
6967 called with the *new* value rather than the value which was
6968 originally passed in. This happens rarely enough that it is not
6969 a major problem, but it *is* a problem, and I'd like to fix it.
6971 A future version of dwarf2out.c may generate two additional
6972 attributes for any given DW_TAG_formal_parameter DIE which will
6973 describe the "passed type" and the "passed location" for the
6974 given formal parameter in addition to the attributes we now
6975 generate to indicate the "declared type" and the "active
6976 location" for each parameter. This additional set of attributes
6977 could be used by debuggers for stack backtraces. Separately, note
6978 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6979 NULL also. This happens (for example) for inlined-instances of
6980 inline function formal parameters which are never referenced.
6981 This really shouldn't be happening. All PARM_DECL nodes should
6982 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6983 doesn't currently generate these values for inlined instances of
6984 inline function parameters, so when we see such cases, we are
6985 just out-of-luck for the time being (until integrate.c
6988 /* Use DECL_RTL as the "location" unless we find something better. */
6989 rtl
= DECL_RTL (decl
);
6991 if (TREE_CODE (decl
) == PARM_DECL
)
6993 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
6995 declared_type
= type_main_variant (TREE_TYPE (decl
));
6996 passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
6998 /* This decl represents a formal parameter which was optimized out.
6999 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
7000 all* cases where (rtl == NULL_RTX) just below. */
7001 if (declared_type
== passed_type
)
7002 rtl
= DECL_INCOMING_RTL (decl
);
7003 else if (! BYTES_BIG_ENDIAN
7004 && TREE_CODE (declared_type
) == INTEGER_TYPE
7005 && TYPE_SIZE (declared_type
) <= TYPE_SIZE (passed_type
))
7006 rtl
= DECL_INCOMING_RTL (decl
);
7010 if (rtl
== NULL_RTX
)
7013 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
7014 #ifdef LEAF_REG_REMAP
7016 leaf_renumber_regs_insn (rtl
);
7019 switch (GET_CODE (rtl
))
7022 /* The address of a variable that was optimized away; don't emit
7033 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7034 add_const_value_attribute (die
, rtl
);
7041 add_AT_location_description (die
, DW_AT_location
, rtl
);
7049 /* Generate an DW_AT_name attribute given some string value to be included as
7050 the value of the attribute. */
7053 add_name_attribute (die
, name_string
)
7054 register dw_die_ref die
;
7055 register char *name_string
;
7057 if (name_string
!= NULL
&& *name_string
!= 0)
7058 add_AT_string (die
, DW_AT_name
, name_string
);
7061 /* Given a tree node describing an array bound (either lower or upper) output
7062 a representation for that bound. */
7065 add_bound_info (subrange_die
, bound_attr
, bound
)
7066 register dw_die_ref subrange_die
;
7067 register enum dwarf_attribute bound_attr
;
7068 register tree bound
;
7070 register unsigned bound_value
= 0;
7072 /* If this is an Ada unconstrained array type, then don't emit any debug
7073 info because the array bounds are unknown. They are parameterized when
7074 the type is instantiated. */
7075 if (contains_placeholder_p (bound
))
7078 switch (TREE_CODE (bound
))
7083 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7085 bound_value
= TREE_INT_CST_LOW (bound
);
7086 if (bound_attr
== DW_AT_lower_bound
7087 && ((is_c_family () && bound_value
== 0)
7088 || (is_fortran () && bound_value
== 1)))
7089 /* use the default */;
7091 add_AT_unsigned (subrange_die
, bound_attr
, bound_value
);
7096 case NON_LVALUE_EXPR
:
7097 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
7101 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7102 access the upper bound values may be bogus. If they refer to a
7103 register, they may only describe how to get at these values at the
7104 points in the generated code right after they have just been
7105 computed. Worse yet, in the typical case, the upper bound values
7106 will not even *be* computed in the optimized code (though the
7107 number of elements will), so these SAVE_EXPRs are entirely
7108 bogus. In order to compensate for this fact, we check here to see
7109 if optimization is enabled, and if so, we don't add an attribute
7110 for the (unknown and unknowable) upper bound. This should not
7111 cause too much trouble for existing (stupid?) debuggers because
7112 they have to deal with empty upper bounds location descriptions
7113 anyway in order to be able to deal with incomplete array types.
7114 Of course an intelligent debugger (GDB?) should be able to
7115 comprehend that a missing upper bound specification in a array
7116 type used for a storage class `auto' local array variable
7117 indicates that the upper bound is both unknown (at compile- time)
7118 and unknowable (at run-time) due to optimization.
7120 We assume that a MEM rtx is safe because gcc wouldn't put the
7121 value there unless it was going to be used repeatedly in the
7122 function, i.e. for cleanups. */
7123 if (! optimize
|| GET_CODE (SAVE_EXPR_RTL (bound
)) == MEM
)
7125 register dw_die_ref ctx
= lookup_decl_die (current_function_decl
);
7126 register dw_die_ref decl_die
= new_die (DW_TAG_variable
, ctx
);
7127 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
7128 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
7129 add_AT_location_description (decl_die
, DW_AT_location
,
7130 SAVE_EXPR_RTL (bound
));
7131 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
7134 /* Else leave out the attribute. */
7140 /* ??? These types of bounds can be created by the Ada front end,
7141 and it isn't clear how to emit debug info for them. */
7149 /* Note that the block of subscript information for an array type also
7150 includes information about the element type of type given array type. */
7153 add_subscript_info (type_die
, type
)
7154 register dw_die_ref type_die
;
7157 register unsigned dimension_number
;
7158 register tree lower
, upper
;
7159 register dw_die_ref subrange_die
;
7161 /* The GNU compilers represent multidimensional array types as sequences of
7162 one dimensional array types whose element types are themselves array
7163 types. Here we squish that down, so that each multidimensional array
7164 type gets only one array_type DIE in the Dwarf debugging info. The draft
7165 Dwarf specification say that we are allowed to do this kind of
7166 compression in C (because there is no difference between an array or
7167 arrays and a multidimensional array in C) but for other source languages
7168 (e.g. Ada) we probably shouldn't do this. */
7170 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7171 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7172 We work around this by disabling this feature. See also
7173 gen_array_type_die. */
7174 #ifndef MIPS_DEBUGGING_INFO
7175 for (dimension_number
= 0;
7176 TREE_CODE (type
) == ARRAY_TYPE
;
7177 type
= TREE_TYPE (type
), dimension_number
++)
7180 register tree domain
= TYPE_DOMAIN (type
);
7182 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7183 and (in GNU C only) variable bounds. Handle all three forms
7185 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
);
7188 /* We have an array type with specified bounds. */
7189 lower
= TYPE_MIN_VALUE (domain
);
7190 upper
= TYPE_MAX_VALUE (domain
);
7192 /* define the index type. */
7193 if (TREE_TYPE (domain
))
7195 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7196 TREE_TYPE field. We can't emit debug info for this
7197 because it is an unnamed integral type. */
7198 if (TREE_CODE (domain
) == INTEGER_TYPE
7199 && TYPE_NAME (domain
) == NULL_TREE
7200 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
7201 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
7204 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
7208 /* ??? If upper is NULL, the array has unspecified length,
7209 but it does have a lower bound. This happens with Fortran
7211 Since the debugger is definitely going to need to know N
7212 to produce useful results, go ahead and output the lower
7213 bound solo, and hope the debugger can cope. */
7215 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
7217 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
7220 /* We have an array type with an unspecified length. The DWARF-2
7221 spec does not say how to handle this; let's just leave out the
7225 #ifndef MIPS_DEBUGGING_INFO
7231 add_byte_size_attribute (die
, tree_node
)
7233 register tree tree_node
;
7235 register unsigned size
;
7237 switch (TREE_CODE (tree_node
))
7245 case QUAL_UNION_TYPE
:
7246 size
= int_size_in_bytes (tree_node
);
7249 /* For a data member of a struct or union, the DW_AT_byte_size is
7250 generally given as the number of bytes normally allocated for an
7251 object of the *declared* type of the member itself. This is true
7252 even for bit-fields. */
7253 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
7259 /* Note that `size' might be -1 when we get to this point. If it is, that
7260 indicates that the byte size of the entity in question is variable. We
7261 have no good way of expressing this fact in Dwarf at the present time,
7262 so just let the -1 pass on through. */
7264 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
7267 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7268 which specifies the distance in bits from the highest order bit of the
7269 "containing object" for the bit-field to the highest order bit of the
7272 For any given bit-field, the "containing object" is a hypothetical
7273 object (of some integral or enum type) within which the given bit-field
7274 lives. The type of this hypothetical "containing object" is always the
7275 same as the declared type of the individual bit-field itself. The
7276 determination of the exact location of the "containing object" for a
7277 bit-field is rather complicated. It's handled by the
7278 `field_byte_offset' function (above).
7280 Note that it is the size (in bytes) of the hypothetical "containing object"
7281 which will be given in the DW_AT_byte_size attribute for this bit-field.
7282 (See `byte_size_attribute' above). */
7285 add_bit_offset_attribute (die
, decl
)
7286 register dw_die_ref die
;
7289 register unsigned object_offset_in_bytes
= field_byte_offset (decl
);
7290 register tree type
= DECL_BIT_FIELD_TYPE (decl
);
7291 register tree bitpos_tree
= DECL_FIELD_BITPOS (decl
);
7292 register unsigned bitpos_int
;
7293 register unsigned highest_order_object_bit_offset
;
7294 register unsigned highest_order_field_bit_offset
;
7295 register unsigned bit_offset
;
7297 /* Must be a field and a bit field. */
7299 || TREE_CODE (decl
) != FIELD_DECL
)
7302 /* We can't yet handle bit-fields whose offsets are variable, so if we
7303 encounter such things, just return without generating any attribute
7305 if (TREE_CODE (bitpos_tree
) != INTEGER_CST
)
7308 bitpos_int
= (unsigned) TREE_INT_CST_LOW (bitpos_tree
);
7310 /* Note that the bit offset is always the distance (in bits) from the
7311 highest-order bit of the "containing object" to the highest-order bit of
7312 the bit-field itself. Since the "high-order end" of any object or field
7313 is different on big-endian and little-endian machines, the computation
7314 below must take account of these differences. */
7315 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
7316 highest_order_field_bit_offset
= bitpos_int
;
7318 if (! BYTES_BIG_ENDIAN
)
7320 highest_order_field_bit_offset
7321 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl
));
7323 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
7327 = (! BYTES_BIG_ENDIAN
7328 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
7329 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
7331 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
7334 /* For a FIELD_DECL node which represents a bit field, output an attribute
7335 which specifies the length in bits of the given field. */
7338 add_bit_size_attribute (die
, decl
)
7339 register dw_die_ref die
;
7342 /* Must be a field and a bit field. */
7343 if (TREE_CODE (decl
) != FIELD_DECL
7344 || ! DECL_BIT_FIELD_TYPE (decl
))
7346 add_AT_unsigned (die
, DW_AT_bit_size
,
7347 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl
)));
7350 /* If the compiled language is ANSI C, then add a 'prototyped'
7351 attribute, if arg types are given for the parameters of a function. */
7354 add_prototyped_attribute (die
, func_type
)
7355 register dw_die_ref die
;
7356 register tree func_type
;
7358 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
7359 && TYPE_ARG_TYPES (func_type
) != NULL
)
7360 add_AT_flag (die
, DW_AT_prototyped
, 1);
7364 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7365 by looking in either the type declaration or object declaration
7369 add_abstract_origin_attribute (die
, origin
)
7370 register dw_die_ref die
;
7371 register tree origin
;
7373 dw_die_ref origin_die
= NULL
;
7374 if (TREE_CODE_CLASS (TREE_CODE (origin
)) == 'd')
7375 origin_die
= lookup_decl_die (origin
);
7376 else if (TREE_CODE_CLASS (TREE_CODE (origin
)) == 't')
7377 origin_die
= lookup_type_die (origin
);
7379 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
7382 /* We do not currently support the pure_virtual attribute. */
7385 add_pure_or_virtual_attribute (die
, func_decl
)
7386 register dw_die_ref die
;
7387 register tree func_decl
;
7389 if (DECL_VINDEX (func_decl
))
7391 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
7392 add_AT_loc (die
, DW_AT_vtable_elem_location
,
7393 new_loc_descr (DW_OP_constu
,
7394 TREE_INT_CST_LOW (DECL_VINDEX (func_decl
)),
7397 /* GNU extension: Record what type this method came from originally. */
7398 if (debug_info_level
> DINFO_LEVEL_TERSE
)
7399 add_AT_die_ref (die
, DW_AT_containing_type
,
7400 lookup_type_die (DECL_CONTEXT (func_decl
)));
7404 /* Add source coordinate attributes for the given decl. */
7407 add_src_coords_attributes (die
, decl
)
7408 register dw_die_ref die
;
7411 register unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
7413 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
7414 add_AT_unsigned (die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
7417 /* Add an DW_AT_name attribute and source coordinate attribute for the
7418 given decl, but only if it actually has a name. */
7421 add_name_and_src_coords_attributes (die
, decl
)
7422 register dw_die_ref die
;
7425 register tree decl_name
;
7427 decl_name
= DECL_NAME (decl
);
7428 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
7430 add_name_attribute (die
, dwarf2_name (decl
, 0));
7431 add_src_coords_attributes (die
, decl
);
7432 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
7433 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
7434 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
7435 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
7439 /* Push a new declaration scope. */
7442 push_decl_scope (scope
)
7445 /* Make room in the decl_scope_table, if necessary. */
7446 if (decl_scope_table_allocated
== decl_scope_depth
)
7448 decl_scope_table_allocated
+= DECL_SCOPE_TABLE_INCREMENT
;
7450 = (tree
*) xrealloc (decl_scope_table
,
7451 decl_scope_table_allocated
* sizeof (tree
));
7454 decl_scope_table
[decl_scope_depth
++] = scope
;
7457 /* Return the DIE for the scope the immediately contains this declaration. */
7460 scope_die_for (t
, context_die
)
7462 register dw_die_ref context_die
;
7464 register dw_die_ref scope_die
= NULL
;
7465 register tree containing_scope
;
7466 register unsigned long i
;
7468 /* Walk back up the declaration tree looking for a place to define
7470 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
7471 containing_scope
= TYPE_CONTEXT (t
);
7472 else if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_VINDEX (t
))
7473 containing_scope
= decl_class_context (t
);
7475 containing_scope
= DECL_CONTEXT (t
);
7477 /* Function-local tags and functions get stuck in limbo until they are
7478 fixed up by decls_for_scope. */
7479 if (context_die
== NULL
&& containing_scope
!= NULL_TREE
7480 && (TREE_CODE (t
) == FUNCTION_DECL
|| is_tagged_type (t
)))
7483 if (containing_scope
== NULL_TREE
)
7484 scope_die
= comp_unit_die
;
7487 for (i
= decl_scope_depth
, scope_die
= context_die
;
7488 i
> 0 && decl_scope_table
[i
- 1] != containing_scope
;
7489 scope_die
= scope_die
->die_parent
, --i
)
7494 if (scope_die
!= comp_unit_die
7495 || TREE_CODE_CLASS (TREE_CODE (containing_scope
)) != 't')
7497 if (debug_info_level
> DINFO_LEVEL_TERSE
7498 && !TREE_ASM_WRITTEN (containing_scope
))
7506 /* Pop a declaration scope. */
7510 if (decl_scope_depth
<= 0)
7515 /* Many forms of DIEs require a "type description" attribute. This
7516 routine locates the proper "type descriptor" die for the type given
7517 by 'type', and adds an DW_AT_type attribute below the given die. */
7520 add_type_attribute (object_die
, type
, decl_const
, decl_volatile
, context_die
)
7521 register dw_die_ref object_die
;
7523 register int decl_const
;
7524 register int decl_volatile
;
7525 register dw_die_ref context_die
;
7527 register enum tree_code code
= TREE_CODE (type
);
7528 register dw_die_ref type_die
= NULL
;
7530 /* ??? If this type is an unnamed subrange type of an integral or
7531 floating-point type, use the inner type. This is because we have no
7532 support for unnamed types in base_type_die. This can happen if this is
7533 an Ada subrange type. Correct solution is emit a subrange type die. */
7534 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
7535 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
7536 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
7538 if (code
== ERROR_MARK
)
7541 /* Handle a special case. For functions whose return type is void, we
7542 generate *no* type attribute. (Note that no object may have type
7543 `void', so this only applies to function return types). */
7544 if (code
== VOID_TYPE
)
7547 type_die
= modified_type_die (type
,
7548 decl_const
|| TYPE_READONLY (type
),
7549 decl_volatile
|| TYPE_VOLATILE (type
),
7551 if (type_die
!= NULL
)
7552 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
7555 /* Given a tree pointer to a struct, class, union, or enum type node, return
7556 a pointer to the (string) tag name for the given type, or zero if the type
7557 was declared without a tag. */
7563 register char *name
= 0;
7565 if (TYPE_NAME (type
) != 0)
7567 register tree t
= 0;
7569 /* Find the IDENTIFIER_NODE for the type name. */
7570 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
7571 t
= TYPE_NAME (type
);
7573 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7574 a TYPE_DECL node, regardless of whether or not a `typedef' was
7576 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
7577 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
7578 t
= DECL_NAME (TYPE_NAME (type
));
7580 /* Now get the name as a string, or invent one. */
7582 name
= IDENTIFIER_POINTER (t
);
7585 return (name
== 0 || *name
== '\0') ? 0 : name
;
7588 /* Return the type associated with a data member, make a special check
7589 for bit field types. */
7592 member_declared_type (member
)
7593 register tree member
;
7595 return (DECL_BIT_FIELD_TYPE (member
)
7596 ? DECL_BIT_FIELD_TYPE (member
)
7597 : TREE_TYPE (member
));
7600 /* Get the decl's label, as described by its RTL. This may be different
7601 from the DECL_NAME name used in the source file. */
7604 decl_start_label (decl
)
7609 x
= DECL_RTL (decl
);
7610 if (GET_CODE (x
) != MEM
)
7614 if (GET_CODE (x
) != SYMBOL_REF
)
7617 fnname
= XSTR (x
, 0);
7621 /* These routines generate the internal representation of the DIE's for
7622 the compilation unit. Debugging information is collected by walking
7623 the declaration trees passed in from dwarf2out_decl(). */
7626 gen_array_type_die (type
, context_die
)
7628 register dw_die_ref context_die
;
7630 register dw_die_ref scope_die
= scope_die_for (type
, context_die
);
7631 register dw_die_ref array_die
;
7632 register tree element_type
;
7634 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7635 the inner array type comes before the outer array type. Thus we must
7636 call gen_type_die before we call new_die. See below also. */
7637 #ifdef MIPS_DEBUGGING_INFO
7638 gen_type_die (TREE_TYPE (type
), context_die
);
7641 array_die
= new_die (DW_TAG_array_type
, scope_die
);
7644 /* We default the array ordering. SDB will probably do
7645 the right things even if DW_AT_ordering is not present. It's not even
7646 an issue until we start to get into multidimensional arrays anyway. If
7647 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7648 then we'll have to put the DW_AT_ordering attribute back in. (But if
7649 and when we find out that we need to put these in, we will only do so
7650 for multidimensional arrays. */
7651 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
7654 #ifdef MIPS_DEBUGGING_INFO
7655 /* The SGI compilers handle arrays of unknown bound by setting
7656 AT_declaration and not emitting any subrange DIEs. */
7657 if (! TYPE_DOMAIN (type
))
7658 add_AT_unsigned (array_die
, DW_AT_declaration
, 1);
7661 add_subscript_info (array_die
, type
);
7663 equate_type_number_to_die (type
, array_die
);
7665 /* Add representation of the type of the elements of this array type. */
7666 element_type
= TREE_TYPE (type
);
7668 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7669 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7670 We work around this by disabling this feature. See also
7671 add_subscript_info. */
7672 #ifndef MIPS_DEBUGGING_INFO
7673 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
7674 element_type
= TREE_TYPE (element_type
);
7676 gen_type_die (element_type
, context_die
);
7679 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
7683 gen_set_type_die (type
, context_die
)
7685 register dw_die_ref context_die
;
7687 register dw_die_ref type_die
7688 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
));
7690 equate_type_number_to_die (type
, type_die
);
7691 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
7695 gen_entry_point_die (decl
, context_die
)
7697 register dw_die_ref context_die
;
7699 register tree origin
= decl_ultimate_origin (decl
);
7700 register dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
);
7702 add_abstract_origin_attribute (decl_die
, origin
);
7705 add_name_and_src_coords_attributes (decl_die
, decl
);
7706 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
7710 if (DECL_ABSTRACT (decl
))
7711 equate_decl_number_to_die (decl
, decl_die
);
7713 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
7716 /* Remember a type in the pending_types_list. */
7722 if (pending_types
== pending_types_allocated
)
7724 pending_types_allocated
+= PENDING_TYPES_INCREMENT
;
7726 = (tree
*) xrealloc (pending_types_list
,
7727 sizeof (tree
) * pending_types_allocated
);
7730 pending_types_list
[pending_types
++] = type
;
7733 /* Output any pending types (from the pending_types list) which we can output
7734 now (taking into account the scope that we are working on now).
7736 For each type output, remove the given type from the pending_types_list
7737 *before* we try to output it. */
7740 output_pending_types_for_scope (context_die
)
7741 register dw_die_ref context_die
;
7745 while (pending_types
)
7748 type
= pending_types_list
[pending_types
];
7749 gen_type_die (type
, context_die
);
7750 if (!TREE_ASM_WRITTEN (type
))
7755 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7758 gen_inlined_enumeration_type_die (type
, context_die
)
7760 register dw_die_ref context_die
;
7762 register dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
,
7763 scope_die_for (type
, context_die
));
7765 if (!TREE_ASM_WRITTEN (type
))
7767 add_abstract_origin_attribute (type_die
, type
);
7770 /* Generate a DIE to represent an inlined instance of a structure type. */
7773 gen_inlined_structure_type_die (type
, context_die
)
7775 register dw_die_ref context_die
;
7777 register dw_die_ref type_die
= new_die (DW_TAG_structure_type
,
7778 scope_die_for (type
, context_die
));
7780 if (!TREE_ASM_WRITTEN (type
))
7782 add_abstract_origin_attribute (type_die
, type
);
7785 /* Generate a DIE to represent an inlined instance of a union type. */
7788 gen_inlined_union_type_die (type
, context_die
)
7790 register dw_die_ref context_die
;
7792 register dw_die_ref type_die
= new_die (DW_TAG_union_type
,
7793 scope_die_for (type
, context_die
));
7795 if (!TREE_ASM_WRITTEN (type
))
7797 add_abstract_origin_attribute (type_die
, type
);
7800 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7801 include all of the information about the enumeration values also. Each
7802 enumerated type name/value is listed as a child of the enumerated type
7806 gen_enumeration_type_die (type
, context_die
)
7808 register dw_die_ref context_die
;
7810 register dw_die_ref type_die
= lookup_type_die (type
);
7812 if (type_die
== NULL
)
7814 type_die
= new_die (DW_TAG_enumeration_type
,
7815 scope_die_for (type
, context_die
));
7816 equate_type_number_to_die (type
, type_die
);
7817 add_name_attribute (type_die
, type_tag (type
));
7819 else if (! TYPE_SIZE (type
))
7822 remove_AT (type_die
, DW_AT_declaration
);
7824 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7825 given enum type is incomplete, do not generate the DW_AT_byte_size
7826 attribute or the DW_AT_element_list attribute. */
7827 if (TYPE_SIZE (type
))
7831 TREE_ASM_WRITTEN (type
) = 1;
7832 add_byte_size_attribute (type_die
, type
);
7833 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
7834 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
7836 /* If the first reference to this type was as the return type of an
7837 inline function, then it may not have a parent. Fix this now. */
7838 if (type_die
->die_parent
== NULL
)
7839 add_child_die (scope_die_for (type
, context_die
), type_die
);
7841 for (link
= TYPE_FIELDS (type
);
7842 link
!= NULL
; link
= TREE_CHAIN (link
))
7844 register dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
);
7846 add_name_attribute (enum_die
,
7847 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
7848 add_AT_unsigned (enum_die
, DW_AT_const_value
,
7849 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link
)));
7853 add_AT_flag (type_die
, DW_AT_declaration
, 1);
7857 /* Generate a DIE to represent either a real live formal parameter decl or to
7858 represent just the type of some formal parameter position in some function
7861 Note that this routine is a bit unusual because its argument may be a
7862 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7863 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7864 node. If it's the former then this function is being called to output a
7865 DIE to represent a formal parameter object (or some inlining thereof). If
7866 it's the latter, then this function is only being called to output a
7867 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7868 argument type of some subprogram type. */
7871 gen_formal_parameter_die (node
, context_die
)
7873 register dw_die_ref context_die
;
7875 register dw_die_ref parm_die
7876 = new_die (DW_TAG_formal_parameter
, context_die
);
7877 register tree origin
;
7879 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
7882 origin
= decl_ultimate_origin (node
);
7884 add_abstract_origin_attribute (parm_die
, origin
);
7887 add_name_and_src_coords_attributes (parm_die
, node
);
7888 add_type_attribute (parm_die
, TREE_TYPE (node
),
7889 TREE_READONLY (node
),
7890 TREE_THIS_VOLATILE (node
),
7892 if (DECL_ARTIFICIAL (node
))
7893 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
7896 equate_decl_number_to_die (node
, parm_die
);
7897 if (! DECL_ABSTRACT (node
))
7898 add_location_or_const_value_attribute (parm_die
, node
);
7903 /* We were called with some kind of a ..._TYPE node. */
7904 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
7914 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
7915 at the end of an (ANSI prototyped) formal parameters list. */
7918 gen_unspecified_parameters_die (decl_or_type
, context_die
)
7919 register tree decl_or_type
;
7920 register dw_die_ref context_die
;
7922 register dw_die_ref parm_die
= new_die (DW_TAG_unspecified_parameters
,
7926 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
7927 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
7928 parameters as specified in some function type specification (except for
7929 those which appear as part of a function *definition*).
7931 Note we must be careful here to output all of the parameter DIEs before*
7932 we output any DIEs needed to represent the types of the formal parameters.
7933 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
7934 non-parameter DIE it sees ends the formal parameter list. */
7937 gen_formal_types_die (function_or_method_type
, context_die
)
7938 register tree function_or_method_type
;
7939 register dw_die_ref context_die
;
7942 register tree formal_type
= NULL
;
7943 register tree first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
7946 /* In the case where we are generating a formal types list for a C++
7947 non-static member function type, skip over the first thing on the
7948 TYPE_ARG_TYPES list because it only represents the type of the hidden
7949 `this pointer'. The debugger should be able to figure out (without
7950 being explicitly told) that this non-static member function type takes a
7951 `this pointer' and should be able to figure what the type of that hidden
7952 parameter is from the DW_AT_member attribute of the parent
7953 DW_TAG_subroutine_type DIE. */
7954 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
)
7955 first_parm_type
= TREE_CHAIN (first_parm_type
);
7958 /* Make our first pass over the list of formal parameter types and output a
7959 DW_TAG_formal_parameter DIE for each one. */
7960 for (link
= first_parm_type
; link
; link
= TREE_CHAIN (link
))
7962 register dw_die_ref parm_die
;
7964 formal_type
= TREE_VALUE (link
);
7965 if (formal_type
== void_type_node
)
7968 /* Output a (nameless) DIE to represent the formal parameter itself. */
7969 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
7970 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
7971 && link
== first_parm_type
)
7972 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
7975 /* If this function type has an ellipsis, add a
7976 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
7977 if (formal_type
!= void_type_node
)
7978 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
7980 /* Make our second (and final) pass over the list of formal parameter types
7981 and output DIEs to represent those types (as necessary). */
7982 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
7984 link
= TREE_CHAIN (link
))
7986 formal_type
= TREE_VALUE (link
);
7987 if (formal_type
== void_type_node
)
7990 gen_type_die (formal_type
, context_die
);
7994 /* Generate a DIE to represent a declared function (either file-scope or
7998 gen_subprogram_die (decl
, context_die
)
8000 register dw_die_ref context_die
;
8002 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
8003 register tree origin
= decl_ultimate_origin (decl
);
8004 register dw_die_ref subr_die
;
8005 register dw_loc_descr_ref fp_loc
= NULL
;
8006 register rtx fp_reg
;
8007 register tree fn_arg_types
;
8008 register tree outer_scope
;
8009 register dw_die_ref old_die
= lookup_decl_die (decl
);
8010 register int declaration
8011 = (current_function_decl
!= decl
8013 && (context_die
->die_tag
== DW_TAG_structure_type
8014 || context_die
->die_tag
== DW_TAG_union_type
)));
8018 subr_die
= new_die (DW_TAG_subprogram
, context_die
);
8019 add_abstract_origin_attribute (subr_die
, origin
);
8021 else if (old_die
&& DECL_ABSTRACT (decl
)
8022 && get_AT_unsigned (old_die
, DW_AT_inline
))
8024 /* This must be a redefinition of an extern inline function.
8025 We can just reuse the old die here. */
8028 /* Clear out the inlined attribute and parm types. */
8029 remove_AT (subr_die
, DW_AT_inline
);
8030 remove_children (subr_die
);
8034 register unsigned file_index
8035 = lookup_filename (DECL_SOURCE_FILE (decl
));
8037 if (get_AT_flag (old_die
, DW_AT_declaration
) != 1)
8040 /* If the definition comes from the same place as the declaration,
8041 maybe use the old DIE. We always want the DIE for this function
8042 that has the *_pc attributes to be under comp_unit_die so the
8043 debugger can find it. For inlines, that is the concrete instance,
8044 so we can use the old DIE here. For non-inline methods, we want a
8045 specification DIE at toplevel, so we need a new DIE. For local
8046 class methods, this does not apply. */
8047 if ((DECL_ABSTRACT (decl
) || old_die
->die_parent
== comp_unit_die
8048 || context_die
== NULL
)
8049 && get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
8050 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
8051 == DECL_SOURCE_LINE (decl
)))
8055 /* Clear out the declaration attribute and the parm types. */
8056 remove_AT (subr_die
, DW_AT_declaration
);
8057 remove_children (subr_die
);
8061 subr_die
= new_die (DW_TAG_subprogram
, context_die
);
8062 add_AT_die_ref (subr_die
, DW_AT_specification
, old_die
);
8063 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
8064 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
8065 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
8066 != DECL_SOURCE_LINE (decl
))
8068 (subr_die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
8073 register dw_die_ref scope_die
;
8075 if (DECL_CONTEXT (decl
))
8076 scope_die
= scope_die_for (decl
, context_die
);
8078 /* Don't put block extern declarations under comp_unit_die. */
8079 scope_die
= context_die
;
8081 subr_die
= new_die (DW_TAG_subprogram
, scope_die
);
8083 if (TREE_PUBLIC (decl
))
8084 add_AT_flag (subr_die
, DW_AT_external
, 1);
8086 add_name_and_src_coords_attributes (subr_die
, decl
);
8087 if (debug_info_level
> DINFO_LEVEL_TERSE
)
8089 register tree type
= TREE_TYPE (decl
);
8091 add_prototyped_attribute (subr_die
, type
);
8092 add_type_attribute (subr_die
, TREE_TYPE (type
), 0, 0, context_die
);
8095 add_pure_or_virtual_attribute (subr_die
, decl
);
8096 if (DECL_ARTIFICIAL (decl
))
8097 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
8098 if (TREE_PROTECTED (decl
))
8099 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8100 else if (TREE_PRIVATE (decl
))
8101 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
8106 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
8108 /* The first time we see a member function, it is in the context of
8109 the class to which it belongs. We make sure of this by emitting
8110 the class first. The next time is the definition, which is
8111 handled above. The two may come from the same source text. */
8112 if (DECL_CONTEXT (decl
))
8113 equate_decl_number_to_die (decl
, subr_die
);
8115 else if (DECL_ABSTRACT (decl
))
8117 /* ??? Checking DECL_DEFER_OUTPUT is correct for static inline functions,
8118 but not for extern inline functions. We can't get this completely
8119 correct because information about whether the function was declared
8120 inline is not saved anywhere. */
8121 if (DECL_DEFER_OUTPUT (decl
))
8123 if (DECL_INLINE (decl
))
8124 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
8126 add_AT_unsigned (subr_die
, DW_AT_inline
,
8127 DW_INL_declared_not_inlined
);
8129 else if (DECL_INLINE (decl
))
8130 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
8134 equate_decl_number_to_die (decl
, subr_die
);
8136 else if (!DECL_EXTERNAL (decl
))
8138 if (origin
== NULL_TREE
)
8139 equate_decl_number_to_die (decl
, subr_die
);
8141 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
8142 current_funcdef_number
);
8143 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
8144 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
8145 current_funcdef_number
);
8146 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
8148 add_pubname (decl
, subr_die
);
8149 add_arange (decl
, subr_die
);
8151 #ifdef MIPS_DEBUGGING_INFO
8152 /* Add a reference to the FDE for this routine. */
8153 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
8156 /* Define the "frame base" location for this routine. We use the
8157 frame pointer or stack pointer registers, since the RTL for local
8158 variables is relative to one of them. */
8160 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
8161 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
8164 /* ??? This fails for nested inline functions, because context_display
8165 is not part of the state saved/restored for inline functions. */
8166 if (current_function_needs_context
)
8167 add_AT_location_description (subr_die
, DW_AT_static_link
,
8168 lookup_static_chain (decl
));
8172 /* Now output descriptions of the arguments for this function. This gets
8173 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8174 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8175 `...' at the end of the formal parameter list. In order to find out if
8176 there was a trailing ellipsis or not, we must instead look at the type
8177 associated with the FUNCTION_DECL. This will be a node of type
8178 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8179 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8180 an ellipsis at the end. */
8181 push_decl_scope (decl
);
8183 /* In the case where we are describing a mere function declaration, all we
8184 need to do here (and all we *can* do here) is to describe the *types* of
8185 its formal parameters. */
8186 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
8188 else if (declaration
)
8189 gen_formal_types_die (TREE_TYPE (decl
), subr_die
);
8192 /* Generate DIEs to represent all known formal parameters */
8193 register tree arg_decls
= DECL_ARGUMENTS (decl
);
8196 /* When generating DIEs, generate the unspecified_parameters DIE
8197 instead if we come across the arg "__builtin_va_alist" */
8198 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
8199 if (TREE_CODE (parm
) == PARM_DECL
)
8201 if (DECL_NAME (parm
)
8202 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
8203 "__builtin_va_alist"))
8204 gen_unspecified_parameters_die (parm
, subr_die
);
8206 gen_decl_die (parm
, subr_die
);
8209 /* Decide whether we need a unspecified_parameters DIE at the end.
8210 There are 2 more cases to do this for: 1) the ansi ... declaration -
8211 this is detectable when the end of the arg list is not a
8212 void_type_node 2) an unprototyped function declaration (not a
8213 definition). This just means that we have no info about the
8214 parameters at all. */
8215 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
8216 if (fn_arg_types
!= NULL
)
8218 /* this is the prototyped case, check for ... */
8219 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
8220 gen_unspecified_parameters_die (decl
, subr_die
);
8222 else if (DECL_INITIAL (decl
) == NULL_TREE
)
8223 gen_unspecified_parameters_die (decl
, subr_die
);
8226 /* Output Dwarf info for all of the stuff within the body of the function
8227 (if it has one - it may be just a declaration). */
8228 outer_scope
= DECL_INITIAL (decl
);
8230 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8231 node created to represent a function. This outermost BLOCK actually
8232 represents the outermost binding contour for the function, i.e. the
8233 contour in which the function's formal parameters and labels get
8234 declared. Curiously, it appears that the front end doesn't actually
8235 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8236 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8237 list for the function instead.) The BLOCK_VARS list for the
8238 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8239 the function however, and we output DWARF info for those in
8240 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8241 node representing the function's outermost pair of curly braces, and
8242 any blocks used for the base and member initializers of a C++
8243 constructor function. */
8244 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
8246 current_function_has_inlines
= 0;
8247 decls_for_scope (outer_scope
, subr_die
, 0);
8249 #if 0 && defined (MIPS_DEBUGGING_INFO)
8250 if (current_function_has_inlines
)
8252 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
8253 if (! comp_unit_has_inlines
)
8255 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
8256 comp_unit_has_inlines
= 1;
8265 /* Generate a DIE to represent a declared data object. */
8268 gen_variable_die (decl
, context_die
)
8270 register dw_die_ref context_die
;
8272 register tree origin
= decl_ultimate_origin (decl
);
8273 register dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
);
8275 dw_die_ref old_die
= lookup_decl_die (decl
);
8277 = (DECL_EXTERNAL (decl
)
8278 || current_function_decl
!= decl_function_context (decl
)
8279 || context_die
->die_tag
== DW_TAG_structure_type
8280 || context_die
->die_tag
== DW_TAG_union_type
);
8283 add_abstract_origin_attribute (var_die
, origin
);
8284 /* Loop unrolling can create multiple blocks that refer to the same
8285 static variable, so we must test for the DW_AT_declaration flag. */
8286 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8287 copy decls and set the DECL_ABSTRACT flag on them instead of
8289 else if (old_die
&& TREE_STATIC (decl
)
8290 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
8292 /* ??? This is an instantiation of a C++ class level static. */
8293 add_AT_die_ref (var_die
, DW_AT_specification
, old_die
);
8294 if (DECL_NAME (decl
))
8296 register unsigned file_index
8297 = lookup_filename (DECL_SOURCE_FILE (decl
));
8299 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
8300 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
8302 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
8303 != DECL_SOURCE_LINE (decl
))
8305 add_AT_unsigned (var_die
, DW_AT_decl_line
,
8306 DECL_SOURCE_LINE (decl
));
8311 add_name_and_src_coords_attributes (var_die
, decl
);
8312 add_type_attribute (var_die
, TREE_TYPE (decl
),
8313 TREE_READONLY (decl
),
8314 TREE_THIS_VOLATILE (decl
), context_die
);
8316 if (TREE_PUBLIC (decl
))
8317 add_AT_flag (var_die
, DW_AT_external
, 1);
8319 if (DECL_ARTIFICIAL (decl
))
8320 add_AT_flag (var_die
, DW_AT_artificial
, 1);
8322 if (TREE_PROTECTED (decl
))
8323 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8325 else if (TREE_PRIVATE (decl
))
8326 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
8330 add_AT_flag (var_die
, DW_AT_declaration
, 1);
8332 if ((declaration
&& decl_class_context (decl
)) || DECL_ABSTRACT (decl
))
8333 equate_decl_number_to_die (decl
, var_die
);
8335 if (! declaration
&& ! DECL_ABSTRACT (decl
))
8337 equate_decl_number_to_die (decl
, var_die
);
8338 add_location_or_const_value_attribute (var_die
, decl
);
8339 add_pubname (decl
, var_die
);
8343 /* Generate a DIE to represent a label identifier. */
8346 gen_label_die (decl
, context_die
)
8348 register dw_die_ref context_die
;
8350 register tree origin
= decl_ultimate_origin (decl
);
8351 register dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
);
8353 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8354 char label2
[MAX_ARTIFICIAL_LABEL_BYTES
];
8357 add_abstract_origin_attribute (lbl_die
, origin
);
8359 add_name_and_src_coords_attributes (lbl_die
, decl
);
8361 if (DECL_ABSTRACT (decl
))
8362 equate_decl_number_to_die (decl
, lbl_die
);
8365 insn
= DECL_RTL (decl
);
8366 if (GET_CODE (insn
) == CODE_LABEL
)
8368 /* When optimization is enabled (via -O) some parts of the compiler
8369 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8370 represent source-level labels which were explicitly declared by
8371 the user. This really shouldn't be happening though, so catch
8372 it if it ever does happen. */
8373 if (INSN_DELETED_P (insn
))
8376 sprintf (label2
, INSN_LABEL_FMT
, current_funcdef_number
);
8377 ASM_GENERATE_INTERNAL_LABEL (label
, label2
,
8378 (unsigned) INSN_UID (insn
));
8379 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
8384 /* Generate a DIE for a lexical block. */
8387 gen_lexical_block_die (stmt
, context_die
, depth
)
8389 register dw_die_ref context_die
;
8392 register dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
);
8393 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8395 if (! BLOCK_ABSTRACT (stmt
))
8397 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
8399 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
8400 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
, next_block_number
);
8401 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
8404 push_decl_scope (stmt
);
8405 decls_for_scope (stmt
, stmt_die
, depth
);
8409 /* Generate a DIE for an inlined subprogram. */
8412 gen_inlined_subroutine_die (stmt
, context_die
, depth
)
8414 register dw_die_ref context_die
;
8417 if (! BLOCK_ABSTRACT (stmt
))
8419 register dw_die_ref subr_die
8420 = new_die (DW_TAG_inlined_subroutine
, context_die
);
8421 register tree decl
= block_ultimate_origin (stmt
);
8422 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8424 add_abstract_origin_attribute (subr_die
, decl
);
8425 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
8427 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
8428 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
, next_block_number
);
8429 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
8430 push_decl_scope (decl
);
8431 decls_for_scope (stmt
, subr_die
, depth
);
8433 current_function_has_inlines
= 1;
8437 /* Generate a DIE for a field in a record, or structure. */
8440 gen_field_die (decl
, context_die
)
8442 register dw_die_ref context_die
;
8444 register dw_die_ref decl_die
= new_die (DW_TAG_member
, context_die
);
8446 add_name_and_src_coords_attributes (decl_die
, decl
);
8447 add_type_attribute (decl_die
, member_declared_type (decl
),
8448 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
8451 /* If this is a bit field... */
8452 if (DECL_BIT_FIELD_TYPE (decl
))
8454 add_byte_size_attribute (decl_die
, decl
);
8455 add_bit_size_attribute (decl_die
, decl
);
8456 add_bit_offset_attribute (decl_die
, decl
);
8459 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
8460 add_data_member_location_attribute (decl_die
, decl
);
8462 if (DECL_ARTIFICIAL (decl
))
8463 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
8465 if (TREE_PROTECTED (decl
))
8466 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8468 else if (TREE_PRIVATE (decl
))
8469 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
8473 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8474 Use modified_type_die instead.
8475 We keep this code here just in case these types of DIEs may be needed to
8476 represent certain things in other languages (e.g. Pascal) someday. */
8478 gen_pointer_type_die (type
, context_die
)
8480 register dw_die_ref context_die
;
8482 register dw_die_ref ptr_die
8483 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
));
8485 equate_type_number_to_die (type
, ptr_die
);
8486 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
8487 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
8490 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8491 Use modified_type_die instead.
8492 We keep this code here just in case these types of DIEs may be needed to
8493 represent certain things in other languages (e.g. Pascal) someday. */
8495 gen_reference_type_die (type
, context_die
)
8497 register dw_die_ref context_die
;
8499 register dw_die_ref ref_die
8500 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
));
8502 equate_type_number_to_die (type
, ref_die
);
8503 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
8504 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
8508 /* Generate a DIE for a pointer to a member type. */
8510 gen_ptr_to_mbr_type_die (type
, context_die
)
8512 register dw_die_ref context_die
;
8514 register dw_die_ref ptr_die
8515 = new_die (DW_TAG_ptr_to_member_type
, scope_die_for (type
, context_die
));
8517 equate_type_number_to_die (type
, ptr_die
);
8518 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
8519 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
8520 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
8523 /* Generate the DIE for the compilation unit. */
8526 gen_compile_unit_die (main_input_filename
)
8527 register char *main_input_filename
;
8530 char *wd
= getpwd ();
8532 comp_unit_die
= new_die (DW_TAG_compile_unit
, NULL
);
8533 add_name_attribute (comp_unit_die
, main_input_filename
);
8536 add_AT_string (comp_unit_die
, DW_AT_comp_dir
, wd
);
8538 sprintf (producer
, "%s %s", language_string
, version_string
);
8540 #ifdef MIPS_DEBUGGING_INFO
8541 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8542 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8543 not appear in the producer string, the debugger reaches the conclusion
8544 that the object file is stripped and has no debugging information.
8545 To get the MIPS/SGI debugger to believe that there is debugging
8546 information in the object file, we add a -g to the producer string. */
8547 if (debug_info_level
> DINFO_LEVEL_TERSE
)
8548 strcat (producer
, " -g");
8551 add_AT_string (comp_unit_die
, DW_AT_producer
, producer
);
8553 if (strcmp (language_string
, "GNU C++") == 0)
8554 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_C_plus_plus
);
8556 else if (strcmp (language_string
, "GNU Ada") == 0)
8557 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_Ada83
);
8559 else if (strcmp (language_string
, "GNU F77") == 0)
8560 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_Fortran77
);
8562 else if (strcmp (language_string
, "GNU Pascal") == 0)
8563 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_Pascal83
);
8565 else if (flag_traditional
)
8566 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_C
);
8569 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_C89
);
8571 #if 0 /* unimplemented */
8572 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
8573 add_AT_unsigned (comp_unit_die
, DW_AT_macro_info
, 0);
8577 /* Generate a DIE for a string type. */
8580 gen_string_type_die (type
, context_die
)
8582 register dw_die_ref context_die
;
8584 register dw_die_ref type_die
8585 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
));
8587 equate_type_number_to_die (type
, type_die
);
8589 /* Fudge the string length attribute for now. */
8591 /* TODO: add string length info.
8592 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8593 bound_representation (upper_bound, 0, 'u'); */
8596 /* Generate the DIE for a base class. */
8599 gen_inheritance_die (binfo
, context_die
)
8600 register tree binfo
;
8601 register dw_die_ref context_die
;
8603 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
);
8605 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
8606 add_data_member_location_attribute (die
, binfo
);
8608 if (TREE_VIA_VIRTUAL (binfo
))
8609 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
8610 if (TREE_VIA_PUBLIC (binfo
))
8611 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
8612 else if (TREE_VIA_PROTECTED (binfo
))
8613 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
8616 /* Generate a DIE for a class member. */
8619 gen_member_die (type
, context_die
)
8621 register dw_die_ref context_die
;
8623 register tree member
;
8625 /* If this is not an incomplete type, output descriptions of each of its
8626 members. Note that as we output the DIEs necessary to represent the
8627 members of this record or union type, we will also be trying to output
8628 DIEs to represent the *types* of those members. However the `type'
8629 function (above) will specifically avoid generating type DIEs for member
8630 types *within* the list of member DIEs for this (containing) type execpt
8631 for those types (of members) which are explicitly marked as also being
8632 members of this (containing) type themselves. The g++ front- end can
8633 force any given type to be treated as a member of some other
8634 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8635 to point to the TREE node representing the appropriate (containing)
8638 /* First output info about the base classes. */
8639 if (TYPE_BINFO (type
) && TYPE_BINFO_BASETYPES (type
))
8641 register tree bases
= TYPE_BINFO_BASETYPES (type
);
8642 register int n_bases
= TREE_VEC_LENGTH (bases
);
8645 for (i
= 0; i
< n_bases
; i
++)
8646 gen_inheritance_die (TREE_VEC_ELT (bases
, i
), context_die
);
8649 /* Now output info about the data members and type members. */
8650 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
8651 gen_decl_die (member
, context_die
);
8653 /* Now output info about the function members (if any). */
8654 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
8655 gen_decl_die (member
, context_die
);
8658 /* Generate a DIE for a structure or union type. */
8661 gen_struct_or_union_type_die (type
, context_die
)
8663 register dw_die_ref context_die
;
8665 register dw_die_ref type_die
= lookup_type_die (type
);
8666 register dw_die_ref scope_die
= 0;
8667 register int nested
= 0;
8669 if (type_die
&& ! TYPE_SIZE (type
))
8672 if (TYPE_CONTEXT (type
) != NULL_TREE
8673 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type
))) == 't')
8676 scope_die
= scope_die_for (type
, context_die
);
8678 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
8679 /* First occurrence of type or toplevel definition of nested class. */
8681 register dw_die_ref old_die
= type_die
;
8683 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
8684 ? DW_TAG_structure_type
: DW_TAG_union_type
,
8686 equate_type_number_to_die (type
, type_die
);
8687 add_name_attribute (type_die
, type_tag (type
));
8689 add_AT_die_ref (type_die
, DW_AT_specification
, old_die
);
8692 remove_AT (type_die
, DW_AT_declaration
);
8694 /* If we're not in the right context to be defining this type, defer to
8695 avoid tricky recursion. */
8696 if (TYPE_SIZE (type
) && decl_scope_depth
> 0 && scope_die
== comp_unit_die
)
8698 add_AT_flag (type_die
, DW_AT_declaration
, 1);
8701 /* If this type has been completed, then give it a byte_size attribute and
8702 then give a list of members. */
8703 else if (TYPE_SIZE (type
))
8705 /* Prevent infinite recursion in cases where the type of some member of
8706 this type is expressed in terms of this type itself. */
8707 TREE_ASM_WRITTEN (type
) = 1;
8708 add_byte_size_attribute (type_die
, type
);
8709 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
8710 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
8712 /* If the first reference to this type was as the return type of an
8713 inline function, then it may not have a parent. Fix this now. */
8714 if (type_die
->die_parent
== NULL
)
8715 add_child_die (scope_die
, type_die
);
8717 push_decl_scope (type
);
8718 gen_member_die (type
, type_die
);
8721 /* GNU extension: Record what type our vtable lives in. */
8722 if (TYPE_VFIELD (type
))
8724 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
8726 gen_type_die (vtype
, context_die
);
8727 add_AT_die_ref (type_die
, DW_AT_containing_type
,
8728 lookup_type_die (vtype
));
8732 add_AT_flag (type_die
, DW_AT_declaration
, 1);
8735 /* Generate a DIE for a subroutine _type_. */
8738 gen_subroutine_type_die (type
, context_die
)
8740 register dw_die_ref context_die
;
8742 register tree return_type
= TREE_TYPE (type
);
8743 register dw_die_ref subr_die
8744 = new_die (DW_TAG_subroutine_type
, scope_die_for (type
, context_die
));
8746 equate_type_number_to_die (type
, subr_die
);
8747 add_prototyped_attribute (subr_die
, type
);
8748 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
8749 gen_formal_types_die (type
, subr_die
);
8752 /* Generate a DIE for a type definition */
8755 gen_typedef_die (decl
, context_die
)
8757 register dw_die_ref context_die
;
8759 register dw_die_ref type_die
;
8760 register tree origin
;
8762 if (TREE_ASM_WRITTEN (decl
))
8764 TREE_ASM_WRITTEN (decl
) = 1;
8766 type_die
= new_die (DW_TAG_typedef
, scope_die_for (decl
, context_die
));
8767 origin
= decl_ultimate_origin (decl
);
8769 add_abstract_origin_attribute (type_die
, origin
);
8773 add_name_and_src_coords_attributes (type_die
, decl
);
8774 if (DECL_ORIGINAL_TYPE (decl
))
8776 type
= DECL_ORIGINAL_TYPE (decl
);
8777 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
8780 type
= TREE_TYPE (decl
);
8781 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
8782 TREE_THIS_VOLATILE (decl
), context_die
);
8785 if (DECL_ABSTRACT (decl
))
8786 equate_decl_number_to_die (decl
, type_die
);
8789 /* Generate a type description DIE. */
8792 gen_type_die (type
, context_die
)
8794 register dw_die_ref context_die
;
8796 if (type
== NULL_TREE
|| type
== error_mark_node
)
8799 /* We are going to output a DIE to represent the unqualified version of of
8800 this type (i.e. without any const or volatile qualifiers) so get the
8801 main variant (i.e. the unqualified version) of this type now. */
8802 type
= type_main_variant (type
);
8804 if (TREE_ASM_WRITTEN (type
))
8807 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
8808 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
8810 TREE_ASM_WRITTEN (type
) = 1;
8811 gen_decl_die (TYPE_NAME (type
), context_die
);
8815 switch (TREE_CODE (type
))
8821 case REFERENCE_TYPE
:
8822 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
8823 ensures that the gen_type_die recursion will terminate even if the
8824 type is recursive. Recursive types are possible in Ada. */
8825 /* ??? We could perhaps do this for all types before the switch
8827 TREE_ASM_WRITTEN (type
) = 1;
8829 /* For these types, all that is required is that we output a DIE (or a
8830 set of DIEs) to represent the "basis" type. */
8831 gen_type_die (TREE_TYPE (type
), context_die
);
8835 /* This code is used for C++ pointer-to-data-member types.
8836 Output a description of the relevant class type. */
8837 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
8839 /* Output a description of the type of the object pointed to. */
8840 gen_type_die (TREE_TYPE (type
), context_die
);
8842 /* Now output a DIE to represent this pointer-to-data-member type
8844 gen_ptr_to_mbr_type_die (type
, context_die
);
8848 gen_type_die (TYPE_DOMAIN (type
), context_die
);
8849 gen_set_type_die (type
, context_die
);
8853 gen_type_die (TREE_TYPE (type
), context_die
);
8854 abort (); /* No way to represent these in Dwarf yet! */
8858 /* Force out return type (in case it wasn't forced out already). */
8859 gen_type_die (TREE_TYPE (type
), context_die
);
8860 gen_subroutine_type_die (type
, context_die
);
8864 /* Force out return type (in case it wasn't forced out already). */
8865 gen_type_die (TREE_TYPE (type
), context_die
);
8866 gen_subroutine_type_die (type
, context_die
);
8870 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
8872 gen_type_die (TREE_TYPE (type
), context_die
);
8873 gen_string_type_die (type
, context_die
);
8876 gen_array_type_die (type
, context_die
);
8882 case QUAL_UNION_TYPE
:
8883 /* If this is a nested type whose containing class hasn't been
8884 written out yet, writing it out will cover this one, too. */
8885 if (TYPE_CONTEXT (type
)
8886 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type
))) == 't'
8887 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
8889 gen_type_die (TYPE_CONTEXT (type
), context_die
);
8891 if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
8894 /* If that failed, attach ourselves to the stub. */
8895 push_decl_scope (TYPE_CONTEXT (type
));
8896 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
8899 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
8900 gen_enumeration_type_die (type
, context_die
);
8902 gen_struct_or_union_type_die (type
, context_die
);
8904 if (TYPE_CONTEXT (type
)
8905 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type
))) == 't'
8906 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
8909 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
8910 it up if it is ever completed. gen_*_type_die will set it for us
8911 when appropriate. */
8920 /* No DIEs needed for fundamental types. */
8924 /* No Dwarf representation currently defined. */
8931 TREE_ASM_WRITTEN (type
) = 1;
8934 /* Generate a DIE for a tagged type instantiation. */
8937 gen_tagged_type_instantiation_die (type
, context_die
)
8939 register dw_die_ref context_die
;
8941 if (type
== NULL_TREE
|| type
== error_mark_node
)
8944 /* We are going to output a DIE to represent the unqualified version of of
8945 this type (i.e. without any const or volatile qualifiers) so make sure
8946 that we have the main variant (i.e. the unqualified version) of this
8948 if (type
!= type_main_variant (type
)
8949 || !TREE_ASM_WRITTEN (type
))
8952 switch (TREE_CODE (type
))
8958 gen_inlined_enumeration_type_die (type
, context_die
);
8962 gen_inlined_structure_type_die (type
, context_die
);
8966 case QUAL_UNION_TYPE
:
8967 gen_inlined_union_type_die (type
, context_die
);
8975 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
8976 things which are local to the given block. */
8979 gen_block_die (stmt
, context_die
, depth
)
8981 register dw_die_ref context_die
;
8984 register int must_output_die
= 0;
8985 register tree origin
;
8987 register enum tree_code origin_code
;
8989 /* Ignore blocks never really used to make RTL. */
8991 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
))
8994 /* Determine the "ultimate origin" of this block. This block may be an
8995 inlined instance of an inlined instance of inline function, so we have
8996 to trace all of the way back through the origin chain to find out what
8997 sort of node actually served as the original seed for the creation of
8998 the current block. */
8999 origin
= block_ultimate_origin (stmt
);
9000 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
9002 /* Determine if we need to output any Dwarf DIEs at all to represent this
9004 if (origin_code
== FUNCTION_DECL
)
9005 /* The outer scopes for inlinings *must* always be represented. We
9006 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9007 must_output_die
= 1;
9010 /* In the case where the current block represents an inlining of the
9011 "body block" of an inline function, we must *NOT* output any DIE for
9012 this block because we have already output a DIE to represent the
9013 whole inlined function scope and the "body block" of any function
9014 doesn't really represent a different scope according to ANSI C
9015 rules. So we check here to make sure that this block does not
9016 represent a "body block inlining" before trying to set the
9017 `must_output_die' flag. */
9018 if (! is_body_block (origin
? origin
: stmt
))
9020 /* Determine if this block directly contains any "significant"
9021 local declarations which we will need to output DIEs for. */
9022 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9023 /* We are not in terse mode so *any* local declaration counts
9024 as being a "significant" one. */
9025 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
9027 /* We are in terse mode, so only local (nested) function
9028 definitions count as "significant" local declarations. */
9029 for (decl
= BLOCK_VARS (stmt
);
9030 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
9031 if (TREE_CODE (decl
) == FUNCTION_DECL
9032 && DECL_INITIAL (decl
))
9034 must_output_die
= 1;
9040 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9041 DIE for any block which contains no significant local declarations at
9042 all. Rather, in such cases we just call `decls_for_scope' so that any
9043 needed Dwarf info for any sub-blocks will get properly generated. Note
9044 that in terse mode, our definition of what constitutes a "significant"
9045 local declaration gets restricted to include only inlined function
9046 instances and local (nested) function definitions. */
9047 if (must_output_die
)
9049 if (origin_code
== FUNCTION_DECL
)
9050 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
9052 gen_lexical_block_die (stmt
, context_die
, depth
);
9055 decls_for_scope (stmt
, context_die
, depth
);
9058 /* Generate all of the decls declared within a given scope and (recursively)
9059 all of it's sub-blocks. */
9062 decls_for_scope (stmt
, context_die
, depth
)
9064 register dw_die_ref context_die
;
9068 register tree subblocks
;
9070 /* Ignore blocks never really used to make RTL. */
9071 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
9074 if (!BLOCK_ABSTRACT (stmt
) && depth
> 0)
9075 next_block_number
++;
9077 /* Output the DIEs to represent all of the data objects and typedefs
9078 declared directly within this block but not within any nested
9079 sub-blocks. Also, nested function and tag DIEs have been
9080 generated with a parent of NULL; fix that up now. */
9081 for (decl
= BLOCK_VARS (stmt
);
9082 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
9084 register dw_die_ref die
;
9086 if (TREE_CODE (decl
) == FUNCTION_DECL
)
9087 die
= lookup_decl_die (decl
);
9088 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
9089 die
= lookup_type_die (TREE_TYPE (decl
));
9093 if (die
!= NULL
&& die
->die_parent
== NULL
)
9094 add_child_die (context_die
, die
);
9096 gen_decl_die (decl
, context_die
);
9099 /* Output the DIEs to represent all sub-blocks (and the items declared
9100 therein) of this block. */
9101 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
9103 subblocks
= BLOCK_CHAIN (subblocks
))
9104 gen_block_die (subblocks
, context_die
, depth
+ 1);
9107 /* Is this a typedef we can avoid emitting? */
9110 is_redundant_typedef (decl
)
9113 if (TYPE_DECL_IS_STUB (decl
))
9116 if (DECL_ARTIFICIAL (decl
)
9117 && DECL_CONTEXT (decl
)
9118 && is_tagged_type (DECL_CONTEXT (decl
))
9119 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
9120 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
9121 /* Also ignore the artificial member typedef for the class name. */
9127 /* Generate Dwarf debug information for a decl described by DECL. */
9130 gen_decl_die (decl
, context_die
)
9132 register dw_die_ref context_die
;
9134 register tree origin
;
9136 /* Make a note of the decl node we are going to be working on. We may need
9137 to give the user the source coordinates of where it appeared in case we
9138 notice (later on) that something about it looks screwy. */
9139 dwarf_last_decl
= decl
;
9141 if (TREE_CODE (decl
) == ERROR_MARK
)
9144 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
9145 ignore a function definition, since that would screw up our count of
9146 blocks, and that it turn will completely screw up the the labels we will
9147 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9148 subsequent blocks). */
9149 if (DECL_IGNORED_P (decl
) && TREE_CODE (decl
) != FUNCTION_DECL
)
9152 switch (TREE_CODE (decl
))
9155 /* The individual enumerators of an enum type get output when we output
9156 the Dwarf representation of the relevant enum type itself. */
9160 /* Don't output any DIEs to represent mere function declarations,
9161 unless they are class members or explicit block externs. */
9162 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
9163 && (current_function_decl
== NULL_TREE
|| ! DECL_ARTIFICIAL (decl
)))
9166 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9168 /* Before we describe the FUNCTION_DECL itself, make sure that we
9169 have described its return type. */
9170 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
9172 /* And its containing type. */
9173 origin
= decl_class_context (decl
);
9174 if (origin
!= NULL_TREE
)
9175 gen_type_die (origin
, context_die
);
9177 /* And its virtual context. */
9178 if (DECL_VINDEX (decl
) != NULL_TREE
)
9179 gen_type_die (DECL_CONTEXT (decl
), context_die
);
9182 /* Now output a DIE to represent the function itself. */
9183 gen_subprogram_die (decl
, context_die
);
9187 /* If we are in terse mode, don't generate any DIEs to represent any
9189 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9192 /* In the special case of a TYPE_DECL node representing the
9193 declaration of some type tag, if the given TYPE_DECL is marked as
9194 having been instantiated from some other (original) TYPE_DECL node
9195 (e.g. one which was generated within the original definition of an
9196 inline function) we have to generate a special (abbreviated)
9197 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9199 if (TYPE_DECL_IS_STUB (decl
) && DECL_ABSTRACT_ORIGIN (decl
) != NULL_TREE
)
9201 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
9205 if (is_redundant_typedef (decl
))
9206 gen_type_die (TREE_TYPE (decl
), context_die
);
9208 /* Output a DIE to represent the typedef itself. */
9209 gen_typedef_die (decl
, context_die
);
9213 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
9214 gen_label_die (decl
, context_die
);
9218 /* If we are in terse mode, don't generate any DIEs to represent any
9219 variable declarations or definitions. */
9220 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9223 /* Output any DIEs that are needed to specify the type of this data
9225 gen_type_die (TREE_TYPE (decl
), context_die
);
9227 /* And its containing type. */
9228 origin
= decl_class_context (decl
);
9229 if (origin
!= NULL_TREE
)
9230 gen_type_die (origin
, context_die
);
9232 /* Now output the DIE to represent the data object itself. This gets
9233 complicated because of the possibility that the VAR_DECL really
9234 represents an inlined instance of a formal parameter for an inline
9236 origin
= decl_ultimate_origin (decl
);
9237 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
9238 gen_formal_parameter_die (decl
, context_die
);
9240 gen_variable_die (decl
, context_die
);
9244 /* Ignore the nameless fields that are used to skip bits, but
9245 handle C++ anonymous unions. */
9246 if (DECL_NAME (decl
) != NULL_TREE
9247 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
)
9249 gen_type_die (member_declared_type (decl
), context_die
);
9250 gen_field_die (decl
, context_die
);
9255 gen_type_die (TREE_TYPE (decl
), context_die
);
9256 gen_formal_parameter_die (decl
, context_die
);
9264 /* Write the debugging output for DECL. */
9267 dwarf2out_decl (decl
)
9270 register dw_die_ref context_die
= comp_unit_die
;
9272 if (TREE_CODE (decl
) == ERROR_MARK
)
9275 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
9276 hope that the node in question doesn't represent a function definition.
9277 If it does, then totally ignoring it is bound to screw up our count of
9278 blocks, and that it turn will completely screw up the the labels we will
9279 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9280 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
9281 own sequence numbers with them!) */
9282 if (DECL_IGNORED_P (decl
))
9284 if (TREE_CODE (decl
) == FUNCTION_DECL
9285 && DECL_INITIAL (decl
) != NULL
)
9291 switch (TREE_CODE (decl
))
9294 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9295 builtin function. Explicit programmer-supplied declarations of
9296 these same functions should NOT be ignored however. */
9297 if (DECL_EXTERNAL (decl
) && DECL_FUNCTION_CODE (decl
))
9300 /* What we would really like to do here is to filter out all mere
9301 file-scope declarations of file-scope functions which are never
9302 referenced later within this translation unit (and keep all of ones
9303 that *are* referenced later on) but we aren't clairvoyant, so we have
9304 no idea which functions will be referenced in the future (i.e. later
9305 on within the current translation unit). So here we just ignore all
9306 file-scope function declarations which are not also definitions. If
9307 and when the debugger needs to know something about these functions,
9308 it wil have to hunt around and find the DWARF information associated
9309 with the definition of the function. Note that we can't just check
9310 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9311 definitions and which ones represent mere declarations. We have to
9312 check `DECL_INITIAL' instead. That's because the C front-end
9313 supports some weird semantics for "extern inline" function
9314 definitions. These can get inlined within the current translation
9315 unit (an thus, we need to generate DWARF info for their abstract
9316 instances so that the DWARF info for the concrete inlined instances
9317 can have something to refer to) but the compiler never generates any
9318 out-of-lines instances of such things (despite the fact that they
9319 *are* definitions). The important point is that the C front-end
9320 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9321 to generate DWARF for them anyway. Note that the C++ front-end also
9322 plays some similar games for inline function definitions appearing
9323 within include files which also contain
9324 `#pragma interface' pragmas. */
9325 if (DECL_INITIAL (decl
) == NULL_TREE
)
9328 /* If we're a nested function, initially use a parent of NULL; if we're
9329 a plain function, this will be fixed up in decls_for_scope. If
9330 we're a method, it will be ignored, since we already have a DIE. */
9331 if (decl_function_context (decl
))
9337 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9338 declaration and if the declaration was never even referenced from
9339 within this entire compilation unit. We suppress these DIEs in
9340 order to save space in the .debug section (by eliminating entries
9341 which are probably useless). Note that we must not suppress
9342 block-local extern declarations (whether used or not) because that
9343 would screw-up the debugger's name lookup mechanism and cause it to
9344 miss things which really ought to be in scope at a given point. */
9345 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
9348 /* If we are in terse mode, don't generate any DIEs to represent any
9349 variable declarations or definitions. */
9350 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9355 /* Don't bother trying to generate any DIEs to represent any of the
9356 normal built-in types for the language we are compiling. */
9357 if (DECL_SOURCE_LINE (decl
) == 0)
9359 /* OK, we need to generate one for `bool' so GDB knows what type
9360 comparisons have. */
9361 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
9362 == DW_LANG_C_plus_plus
)
9363 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
)
9364 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
9369 /* If we are in terse mode, don't generate any DIEs for types. */
9370 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9373 /* If we're a function-scope tag, initially use a parent of NULL;
9374 this will be fixed up in decls_for_scope. */
9375 if (decl_function_context (decl
))
9384 gen_decl_die (decl
, context_die
);
9385 output_pending_types_for_scope (comp_unit_die
);
9388 /* Output a marker (i.e. a label) for the beginning of the generated code for
9392 dwarf2out_begin_block (blocknum
)
9393 register unsigned blocknum
;
9395 function_section (current_function_decl
);
9396 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
9399 /* Output a marker (i.e. a label) for the end of the generated code for a
9403 dwarf2out_end_block (blocknum
)
9404 register unsigned blocknum
;
9406 function_section (current_function_decl
);
9407 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
9410 /* Output a marker (i.e. a label) at a point in the assembly code which
9411 corresponds to a given source level label. */
9414 dwarf2out_label (insn
)
9417 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9419 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
9421 function_section (current_function_decl
);
9422 sprintf (label
, INSN_LABEL_FMT
, current_funcdef_number
);
9423 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, label
,
9424 (unsigned) INSN_UID (insn
));
9428 /* Lookup a filename (in the list of filenames that we know about here in
9429 dwarf2out.c) and return its "index". The index of each (known) filename is
9430 just a unique number which is associated with only that one filename.
9431 We need such numbers for the sake of generating labels
9432 (in the .debug_sfnames section) and references to those
9433 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9434 If the filename given as an argument is not found in our current list,
9435 add it to the list and assign it the next available unique index number.
9436 In order to speed up searches, we remember the index of the filename
9437 was looked up last. This handles the majority of all searches. */
9440 lookup_filename (file_name
)
9443 static unsigned last_file_lookup_index
= 0;
9444 register unsigned i
;
9446 /* Check to see if the file name that was searched on the previous call
9447 matches this file name. If so, return the index. */
9448 if (last_file_lookup_index
!= 0)
9449 if (strcmp (file_name
, file_table
[last_file_lookup_index
]) == 0)
9450 return last_file_lookup_index
;
9452 /* Didn't match the previous lookup, search the table */
9453 for (i
= 1; i
< file_table_in_use
; ++i
)
9454 if (strcmp (file_name
, file_table
[i
]) == 0)
9456 last_file_lookup_index
= i
;
9460 /* Prepare to add a new table entry by making sure there is enough space in
9461 the table to do so. If not, expand the current table. */
9462 if (file_table_in_use
== file_table_allocated
)
9464 file_table_allocated
+= FILE_TABLE_INCREMENT
;
9466 = (char **) xrealloc (file_table
,
9467 file_table_allocated
* sizeof (char *));
9470 /* Add the new entry to the end of the filename table. */
9471 file_table
[file_table_in_use
] = xstrdup (file_name
);
9472 last_file_lookup_index
= file_table_in_use
++;
9474 return last_file_lookup_index
;
9477 /* Output a label to mark the beginning of a source code line entry
9478 and record information relating to this source line, in
9479 'line_info_table' for later output of the .debug_line section. */
9482 dwarf2out_line (filename
, line
)
9483 register char *filename
;
9484 register unsigned line
;
9486 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
9488 function_section (current_function_decl
);
9490 if (DECL_SECTION_NAME (current_function_decl
))
9492 register dw_separate_line_info_ref line_info
;
9493 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
9494 separate_line_info_table_in_use
);
9495 fputc ('\n', asm_out_file
);
9497 /* expand the line info table if necessary */
9498 if (separate_line_info_table_in_use
9499 == separate_line_info_table_allocated
)
9501 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
9502 separate_line_info_table
9503 = (dw_separate_line_info_ref
)
9504 xrealloc (separate_line_info_table
,
9505 separate_line_info_table_allocated
9506 * sizeof (dw_separate_line_info_entry
));
9509 /* Add the new entry at the end of the line_info_table. */
9511 = &separate_line_info_table
[separate_line_info_table_in_use
++];
9512 line_info
->dw_file_num
= lookup_filename (filename
);
9513 line_info
->dw_line_num
= line
;
9514 line_info
->function
= current_funcdef_number
;
9518 register dw_line_info_ref line_info
;
9520 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, LINE_CODE_LABEL
,
9521 line_info_table_in_use
);
9522 fputc ('\n', asm_out_file
);
9524 /* Expand the line info table if necessary. */
9525 if (line_info_table_in_use
== line_info_table_allocated
)
9527 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
9529 = (dw_line_info_ref
)
9530 xrealloc (line_info_table
,
9531 (line_info_table_allocated
9532 * sizeof (dw_line_info_entry
)));
9535 /* Add the new entry at the end of the line_info_table. */
9536 line_info
= &line_info_table
[line_info_table_in_use
++];
9537 line_info
->dw_file_num
= lookup_filename (filename
);
9538 line_info
->dw_line_num
= line
;
9543 /* Record the beginning of a new source file, for later output
9544 of the .debug_macinfo section. At present, unimplemented. */
9547 dwarf2out_start_source_file (filename
)
9548 register char *filename
;
9552 /* Record the end of a source file, for later output
9553 of the .debug_macinfo section. At present, unimplemented. */
9556 dwarf2out_end_source_file ()
9560 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9561 the tail part of the directive line, i.e. the part which is past the
9562 initial whitespace, #, whitespace, directive-name, whitespace part. */
9565 dwarf2out_define (lineno
, buffer
)
9566 register unsigned lineno
;
9567 register char *buffer
;
9569 static int initialized
= 0;
9572 dwarf2out_start_source_file (primary_filename
);
9577 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9578 the tail part of the directive line, i.e. the part which is past the
9579 initial whitespace, #, whitespace, directive-name, whitespace part. */
9582 dwarf2out_undef (lineno
, buffer
)
9583 register unsigned lineno
;
9584 register char *buffer
;
9588 /* Set up for Dwarf output at the start of compilation. */
9591 dwarf2out_init (asm_out_file
, main_input_filename
)
9592 register FILE *asm_out_file
;
9593 register char *main_input_filename
;
9595 /* Remember the name of the primary input file. */
9596 primary_filename
= main_input_filename
;
9598 /* Allocate the initial hunk of the file_table. */
9599 file_table
= (char **) xmalloc (FILE_TABLE_INCREMENT
* sizeof (char *));
9600 bzero ((char *) file_table
, FILE_TABLE_INCREMENT
* sizeof (char *));
9601 file_table_allocated
= FILE_TABLE_INCREMENT
;
9603 /* Skip the first entry - file numbers begin at 1. */
9604 file_table_in_use
= 1;
9606 /* Allocate the initial hunk of the decl_die_table. */
9608 = (dw_die_ref
*) xmalloc (DECL_DIE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
9609 bzero ((char *) decl_die_table
,
9610 DECL_DIE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
9611 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
9612 decl_die_table_in_use
= 0;
9614 /* Allocate the initial hunk of the decl_scope_table. */
9616 = (tree
*) xmalloc (DECL_SCOPE_TABLE_INCREMENT
* sizeof (tree
));
9617 bzero ((char *) decl_scope_table
,
9618 DECL_SCOPE_TABLE_INCREMENT
* sizeof (tree
));
9619 decl_scope_table_allocated
= DECL_SCOPE_TABLE_INCREMENT
;
9620 decl_scope_depth
= 0;
9622 /* Allocate the initial hunk of the abbrev_die_table. */
9624 = (dw_die_ref
*) xmalloc (ABBREV_DIE_TABLE_INCREMENT
9625 * sizeof (dw_die_ref
));
9626 bzero ((char *) abbrev_die_table
,
9627 ABBREV_DIE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
9628 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
9629 /* Zero-th entry is allocated, but unused */
9630 abbrev_die_table_in_use
= 1;
9632 /* Allocate the initial hunk of the line_info_table. */
9634 = (dw_line_info_ref
) xmalloc (LINE_INFO_TABLE_INCREMENT
9635 * sizeof (dw_line_info_entry
));
9636 bzero ((char *) line_info_table
,
9637 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
9638 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
9639 /* Zero-th entry is allocated, but unused */
9640 line_info_table_in_use
= 1;
9642 /* Generate the initial DIE for the .debug section. Note that the (string)
9643 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9644 will (typically) be a relative pathname and that this pathname should be
9645 taken as being relative to the directory from which the compiler was
9646 invoked when the given (base) source file was compiled. */
9647 gen_compile_unit_die (main_input_filename
);
9649 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
9652 /* Output stuff that dwarf requires at the end of every file,
9653 and generate the DWARF-2 debugging info. */
9658 limbo_die_node
*node
, *next_node
;
9662 /* Traverse the limbo die list, and add parent/child links. The only
9663 dies without parents that should be here are concrete instances of
9664 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9665 For concrete instances, we can get the parent die from the abstract
9667 for (node
= limbo_die_list
; node
; node
= next_node
)
9669 next_node
= node
->next
;
9672 if (die
->die_parent
== NULL
)
9674 a
= get_AT (die
, DW_AT_abstract_origin
);
9676 add_child_die (a
->dw_attr_val
.v
.val_die_ref
->die_parent
, die
);
9677 else if (die
== comp_unit_die
)
9685 /* Traverse the DIE tree and add sibling attributes to those DIE's
9686 that have children. */
9687 add_sibling_attributes (comp_unit_die
);
9689 /* Output a terminator label for the .text section. */
9690 fputc ('\n', asm_out_file
);
9691 ASM_OUTPUT_SECTION (asm_out_file
, TEXT_SECTION
);
9692 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, TEXT_END_LABEL
, 0);
9695 /* Output a terminator label for the .data section. */
9696 fputc ('\n', asm_out_file
);
9697 ASM_OUTPUT_SECTION (asm_out_file
, DATA_SECTION
);
9698 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, DATA_END_LABEL
, 0);
9700 /* Output a terminator label for the .bss section. */
9701 fputc ('\n', asm_out_file
);
9702 ASM_OUTPUT_SECTION (asm_out_file
, BSS_SECTION
);
9703 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BSS_END_LABEL
, 0);
9706 /* Output the source line correspondence table. */
9707 if (line_info_table_in_use
> 1 || separate_line_info_table_in_use
)
9709 fputc ('\n', asm_out_file
);
9710 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_LINE_SECTION
);
9711 output_line_info ();
9713 /* We can only use the low/high_pc attributes if all of the code
9715 if (separate_line_info_table_in_use
== 0)
9717 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, TEXT_SECTION
);
9718 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
9721 add_AT_section_offset (comp_unit_die
, DW_AT_stmt_list
, DEBUG_LINE_SECTION
);
9724 /* Output the abbreviation table. */
9725 fputc ('\n', asm_out_file
);
9726 ASM_OUTPUT_SECTION (asm_out_file
, ABBREV_SECTION
);
9727 build_abbrev_table (comp_unit_die
);
9728 output_abbrev_section ();
9730 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9731 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
9732 calc_die_sizes (comp_unit_die
);
9734 /* Output debugging information. */
9735 fputc ('\n', asm_out_file
);
9736 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_INFO_SECTION
);
9737 output_compilation_unit_header ();
9738 output_die (comp_unit_die
);
9740 if (pubname_table_in_use
)
9742 /* Output public names table. */
9743 fputc ('\n', asm_out_file
);
9744 ASM_OUTPUT_SECTION (asm_out_file
, PUBNAMES_SECTION
);
9748 if (fde_table_in_use
)
9750 /* Output the address range information. */
9751 fputc ('\n', asm_out_file
);
9752 ASM_OUTPUT_SECTION (asm_out_file
, ARANGES_SECTION
);
9756 #endif /* DWARF2_DEBUGGING_INFO */