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 /* Decide whether we want to emit frame unwind information for the current
50 return (write_symbols == DWARF2_DEBUG
51 #ifdef DWARF2_UNWIND_INFO
52 || (flag_exceptions && ! exceptions_via_longjmp)
57 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
63 /* How to start an assembler comment. */
64 #ifndef ASM_COMMENT_START
65 #define ASM_COMMENT_START ";#"
68 typedef struct dw_cfi_struct *dw_cfi_ref;
69 typedef struct dw_fde_struct *dw_fde_ref;
70 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
72 /* Call frames are described using a sequence of Call Frame
73 Information instructions. The register number, offset
74 and address fields are provided as possible operands;
75 their use is selected by the opcode field. */
77 typedef union dw_cfi_oprnd_struct
79 unsigned long dw_cfi_reg_num;
80 long int dw_cfi_offset;
85 typedef struct dw_cfi_struct
87 dw_cfi_ref dw_cfi_next;
88 enum dwarf_call_frame_info dw_cfi_opc;
89 dw_cfi_oprnd dw_cfi_oprnd1;
90 dw_cfi_oprnd dw_cfi_oprnd2;
94 /* All call frame descriptions (FDE's) in the GCC generated DWARF
95 refer to a single Common Information Entry (CIE), defined at
96 the beginning of the .debug_frame section. This used of a single
97 CIE obviates the need to keep track of multiple CIE's
98 in the DWARF generation routines below. */
100 typedef struct dw_fde_struct
103 char *dw_fde_current_label;
105 dw_cfi_ref dw_fde_cfi;
109 /* Maximum size (in bytes) of an artificially generated label. */
110 #define MAX_ARTIFICIAL_LABEL_BYTES 30
112 /* Make sure we know the sizes of the various types dwarf can describe. These
113 are only defaults. If the sizes are different for your target, you should
114 override these values by defining the appropriate symbols in your tm.h
117 #ifndef CHAR_TYPE_SIZE
118 #define CHAR_TYPE_SIZE BITS_PER_UNIT
121 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
124 /* The size in bytes of a DWARF field indicating an offset or length
125 relative to a debug info section, specified to be 4 bytes in the DWARF-2
126 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
128 #ifndef DWARF_OFFSET_SIZE
129 #define DWARF_OFFSET_SIZE 4
132 #define DWARF_VERSION 2
134 /* Round SIZE up to the nearest BOUNDARY. */
135 #define DWARF_ROUND(SIZE,BOUNDARY) \
136 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
138 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
139 #ifdef STACK_GROWS_DOWNWARD
140 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
142 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
145 /* A pointer to the base of a table that contains frame description
146 information for each routine. */
147 static dw_fde_ref fde_table;
149 /* Number of elements currently allocated for fde_table. */
150 static unsigned fde_table_allocated;
152 /* Number of elements in fde_table currently in use. */
153 static unsigned fde_table_in_use;
155 /* Size (in elements) of increments by which we may expand the
157 #define FDE_TABLE_INCREMENT 256
159 /* A list of call frame insns for the CIE. */
160 static dw_cfi_ref cie_cfi_head;
162 /* The number of the current function definition for which debugging
163 information is being generated. These numbers range from 1 up to the
164 maximum number of function definitions contained within the current
165 compilation unit. These numbers are used to create unique label id's
166 unique to each function definition. */
167 static unsigned current_funcdef_number = 0;
169 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
170 attribute that accelerates the lookup of the FDE associated
171 with the subprogram. This variable holds the table index of the FDE
172 associated with the current function (body) definition. */
173 static unsigned current_funcdef_fde;
175 /* Forward declarations for functions defined in this file. */
177 static char *stripattributes PROTO((char *));
178 static char *dwarf_cfi_name PROTO((unsigned));
179 static dw_cfi_ref new_cfi PROTO((void));
180 static void add_cfi PROTO((dw_cfi_ref *, dw_cfi_ref));
181 static unsigned long size_of_uleb128 PROTO((unsigned long));
182 static unsigned long size_of_sleb128 PROTO((long));
183 static void output_uleb128 PROTO((unsigned long));
184 static void output_sleb128 PROTO((long));
185 static void add_fde_cfi PROTO((char *, dw_cfi_ref));
186 static void lookup_cfa_1 PROTO((dw_cfi_ref, unsigned long *,
188 static void lookup_cfa PROTO((unsigned long *, long *));
189 static void reg_save PROTO((char *, unsigned, unsigned,
191 static void initial_return_save PROTO((rtx));
192 static void output_cfi PROTO((dw_cfi_ref, dw_fde_ref));
193 static void output_call_frame_info PROTO((int));
194 static unsigned reg_number PROTO((rtx));
196 /* Definitions of defaults for assembler-dependent names of various
197 pseudo-ops and section names.
198 Theses may be overridden in the tm.h file (if necessary) for a particular
201 #ifdef OBJECT_FORMAT_ELF
202 #ifndef UNALIGNED_SHORT_ASM_OP
203 #define UNALIGNED_SHORT_ASM_OP ".2byte"
205 #ifndef UNALIGNED_INT_ASM_OP
206 #define UNALIGNED_INT_ASM_OP ".4byte"
208 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
209 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
211 #endif /* OBJECT_FORMAT_ELF */
214 #define ASM_BYTE_OP ".byte"
217 /* Data and reference forms for relocatable data. */
218 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
219 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
221 /* Pseudo-op for defining a new section. */
222 #ifndef SECTION_ASM_OP
223 #define SECTION_ASM_OP ".section"
226 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
227 print the SECTION_ASM_OP and the section name. The default here works for
228 almost all svr4 assemblers, except for the sparc, where the section name
229 must be enclosed in double quotes. (See sparcv4.h). */
230 #ifndef SECTION_FORMAT
231 #ifdef PUSHSECTION_FORMAT
232 #define SECTION_FORMAT PUSHSECTION_FORMAT
234 #define SECTION_FORMAT "\t%s\t%s\n"
238 #ifndef FRAME_SECTION
239 #define FRAME_SECTION ".debug_frame"
242 #ifndef FUNC_BEGIN_LABEL
243 #define FUNC_BEGIN_LABEL "LFB"
245 #ifndef FUNC_END_LABEL
246 #define FUNC_END_LABEL "LFE"
248 #define CIE_AFTER_SIZE_LABEL "LSCIE"
249 #define CIE_END_LABEL "LECIE"
250 #define CIE_LENGTH_LABEL "LLCIE"
251 #define FDE_AFTER_SIZE_LABEL "LSFDE"
252 #define FDE_END_LABEL "LEFDE"
253 #define FDE_LENGTH_LABEL "LLFDE"
255 /* Definitions of defaults for various types of primitive assembly language
256 output operations. These may be overridden from within the tm.h file,
257 but typically, that is unecessary. */
259 #ifndef ASM_OUTPUT_SECTION
260 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
261 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
264 #ifndef ASM_OUTPUT_DWARF_DATA1
265 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
266 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
269 #ifndef ASM_OUTPUT_DWARF_DELTA1
270 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
271 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
272 assemble_name (FILE, LABEL1); \
273 fprintf (FILE, "-"); \
274 assemble_name (FILE, LABEL2); \
278 #ifdef UNALIGNED_INT_ASM_OP
280 #ifndef UNALIGNED_OFFSET_ASM_OP
281 #define UNALIGNED_OFFSET_ASM_OP \
282 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
285 #ifndef UNALIGNED_WORD_ASM_OP
286 #define UNALIGNED_WORD_ASM_OP \
287 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
290 #ifndef ASM_OUTPUT_DWARF_DELTA2
291 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
292 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
293 assemble_name (FILE, LABEL1); \
294 fprintf (FILE, "-"); \
295 assemble_name (FILE, LABEL2); \
299 #ifndef ASM_OUTPUT_DWARF_DELTA4
300 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
301 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
302 assemble_name (FILE, LABEL1); \
303 fprintf (FILE, "-"); \
304 assemble_name (FILE, LABEL2); \
308 #ifndef ASM_OUTPUT_DWARF_DELTA
309 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
310 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
311 assemble_name (FILE, LABEL1); \
312 fprintf (FILE, "-"); \
313 assemble_name (FILE, LABEL2); \
317 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
318 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
319 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
320 assemble_name (FILE, LABEL1); \
321 fprintf (FILE, "-"); \
322 assemble_name (FILE, LABEL2); \
326 #ifndef ASM_OUTPUT_DWARF_ADDR
327 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
328 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
329 assemble_name (FILE, LABEL); \
333 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
334 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
335 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
338 #ifndef ASM_OUTPUT_DWARF_OFFSET4
339 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
340 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
341 assemble_name (FILE, LABEL); \
345 #ifndef ASM_OUTPUT_DWARF_OFFSET
346 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
347 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
348 assemble_name (FILE, LABEL); \
352 #ifndef ASM_OUTPUT_DWARF_DATA2
353 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
354 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
357 #ifndef ASM_OUTPUT_DWARF_DATA4
358 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
359 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
362 #ifndef ASM_OUTPUT_DWARF_DATA
363 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
364 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
365 (unsigned long) VALUE)
368 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
369 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
370 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
371 (unsigned long) VALUE)
374 #ifndef ASM_OUTPUT_DWARF_DATA8
375 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
377 if (WORDS_BIG_ENDIAN) \
379 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
380 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
384 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
385 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
390 #else /* UNALIGNED_INT_ASM_OP */
392 /* We don't have unaligned support, let's hope the normal output works for
395 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
396 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, LABEL), PTR_SIZE, 1)
398 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
399 assemble_integer (gen_rtx (SYMBOL_REF, SImode, LABEL), 4, 1)
401 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
402 assemble_integer (gen_rtx (SYMBOL_REF, SImode, LABEL), 4, 1)
404 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
405 assemble_integer (gen_rtx (MINUS, HImode, \
406 gen_rtx (SYMBOL_REF, Pmode, LABEL1), \
407 gen_rtx (SYMBOL_REF, Pmode, LABEL2)), \
410 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
411 assemble_integer (gen_rtx (MINUS, SImode, \
412 gen_rtx (SYMBOL_REF, Pmode, LABEL1), \
413 gen_rtx (SYMBOL_REF, Pmode, LABEL2)), \
416 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
417 assemble_integer (gen_rtx (MINUS, Pmode, \
418 gen_rtx (SYMBOL_REF, Pmode, LABEL1), \
419 gen_rtx (SYMBOL_REF, Pmode, LABEL2)), \
422 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
423 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
425 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
426 assemble_integer (GEN_INT (VALUE), 4, 1)
428 #endif /* UNALIGNED_INT_ASM_OP */
431 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
432 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
434 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
435 assemble_name (FILE, SY); \
437 assemble_name (FILE, HI); \
439 assemble_name (FILE, LO); \
442 #endif /* SET_ASM_OP */
444 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
445 newline is produced. When flag_debug_asm is asserted, we add commentary
446 at the end of the line, so we must avoid output of a newline here. */
447 #ifndef ASM_OUTPUT_DWARF_STRING
448 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
450 register int slen = strlen(P); \
451 register char *p = (P); \
453 fprintf (FILE, "\t.ascii \""); \
454 for (i = 0; i < slen; i++) \
456 register int c = p[i]; \
457 if (c == '\"' || c == '\\') \
459 if (c >= ' ' && c < 0177) \
463 fprintf (FILE, "\\%o", c); \
466 fprintf (FILE, "\\0\""); \
471 /* The DWARF 2 CFA column which tracks the return address. Normally this
472 is the column for PC, or the first column after all of the hard
474 #ifndef DWARF_FRAME_RETURN_COLUMN
476 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
478 #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER
482 /* The mapping from gcc register number to DWARF 2 CFA column number. By
483 default, we just provide columns for all registers. */
484 #ifndef DWARF_FRAME_REGNUM
485 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
488 /* Hook used by __throw. */
491 expand_builtin_dwarf_fp_regnum ()
493 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
496 /* The offset from the incoming value of %sp to the top of the stack frame
497 for the current function. */
498 #ifndef INCOMING_FRAME_SP_OFFSET
499 #define INCOMING_FRAME_SP_OFFSET 0
502 /* Return a pointer to a copy of the section string name S with all
503 attributes stripped off. */
509 char *stripped = xstrdup (s);
512 while (*p && *p != ',')
519 /* Return the register number described by a given RTL node. */
525 register unsigned regno = REGNO (rtl);
527 if (regno >= FIRST_PSEUDO_REGISTER)
529 warning ("internal regno botch: regno = %d\n", regno);
533 regno = DBX_REGISTER_NUMBER (regno);
537 struct reg_size_range
544 /* Given a register number in REG_TREE, return an rtx for its size in bytes.
545 We do this in kind of a roundabout way, by building up a list of
546 register size ranges and seeing where our register falls in one of those
547 ranges. We need to do it this way because REG_TREE is not a constant,
548 and the target macros were not designed to make this task easy. */
551 expand_builtin_dwarf_reg_size (reg_tree, target)
555 enum machine_mode mode;
557 struct reg_size_range ranges[5];
564 for (; i < FIRST_PSEUDO_REGISTER; ++i)
566 /* The return address is out of order on the MIPS, and we don't use
567 copy_reg for it anyway, so we don't care here how large it is. */
568 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
571 mode = reg_raw_mode[i];
572 /* CCmode is arbitrarily given a size of 4 bytes. It is more useful
573 to use the same size as word_mode, since that reduces the number
574 of ranges we need. It should not matter, since the result should
575 never be used for a condition code register anyways. */
578 size = GET_MODE_SIZE (mode);
580 if (size != last_size)
582 ranges[n_ranges].beg = i;
583 ranges[n_ranges].size = last_size = GET_MODE_SIZE (reg_raw_mode[i]);
588 ranges[n_ranges-1].end = i;
591 /* The usual case: fp regs surrounded by general regs. */
592 if (n_ranges == 3 && ranges[0].size == ranges[2].size)
594 if ((DWARF_FRAME_REGNUM (ranges[1].end)
595 - DWARF_FRAME_REGNUM (ranges[1].beg))
596 != ranges[1].end - ranges[1].beg)
598 t = fold (build (GE_EXPR, integer_type_node, reg_tree,
599 build_int_2 (DWARF_FRAME_REGNUM (ranges[1].beg), 0)));
600 t2 = fold (build (LE_EXPR, integer_type_node, reg_tree,
601 build_int_2 (DWARF_FRAME_REGNUM (ranges[1].end), 0)));
602 t = fold (build (TRUTH_ANDIF_EXPR, integer_type_node, t, t2));
603 t = fold (build (COND_EXPR, integer_type_node, t,
604 build_int_2 (ranges[1].size, 0),
605 build_int_2 (ranges[0].size, 0)));
610 t = build_int_2 (ranges[n_ranges].size, 0);
611 size = DWARF_FRAME_REGNUM (ranges[n_ranges].beg);
614 if ((DWARF_FRAME_REGNUM (ranges[n_ranges].end)
615 - DWARF_FRAME_REGNUM (ranges[n_ranges].beg))
616 != ranges[n_ranges].end - ranges[n_ranges].beg)
618 if (DWARF_FRAME_REGNUM (ranges[n_ranges].beg) >= size)
620 size = DWARF_FRAME_REGNUM (ranges[n_ranges].beg);
621 t2 = fold (build (LE_EXPR, integer_type_node, reg_tree,
622 build_int_2 (DWARF_FRAME_REGNUM
623 (ranges[n_ranges].end), 0)));
624 t = fold (build (COND_EXPR, integer_type_node, t2,
625 build_int_2 (ranges[n_ranges].size, 0), t));
628 return expand_expr (t, target, Pmode, 0);
631 /* Convert a DWARF call frame info. operation to its string name */
634 dwarf_cfi_name (cfi_opc)
635 register unsigned cfi_opc;
639 case DW_CFA_advance_loc:
640 return "DW_CFA_advance_loc";
642 return "DW_CFA_offset";
644 return "DW_CFA_restore";
648 return "DW_CFA_set_loc";
649 case DW_CFA_advance_loc1:
650 return "DW_CFA_advance_loc1";
651 case DW_CFA_advance_loc2:
652 return "DW_CFA_advance_loc2";
653 case DW_CFA_advance_loc4:
654 return "DW_CFA_advance_loc4";
655 case DW_CFA_offset_extended:
656 return "DW_CFA_offset_extended";
657 case DW_CFA_restore_extended:
658 return "DW_CFA_restore_extended";
659 case DW_CFA_undefined:
660 return "DW_CFA_undefined";
661 case DW_CFA_same_value:
662 return "DW_CFA_same_value";
663 case DW_CFA_register:
664 return "DW_CFA_register";
665 case DW_CFA_remember_state:
666 return "DW_CFA_remember_state";
667 case DW_CFA_restore_state:
668 return "DW_CFA_restore_state";
670 return "DW_CFA_def_cfa";
671 case DW_CFA_def_cfa_register:
672 return "DW_CFA_def_cfa_register";
673 case DW_CFA_def_cfa_offset:
674 return "DW_CFA_def_cfa_offset";
676 /* SGI/MIPS specific */
677 case DW_CFA_MIPS_advance_loc8:
678 return "DW_CFA_MIPS_advance_loc8";
681 case DW_CFA_GNU_window_save:
682 return "DW_CFA_GNU_window_save";
683 case DW_CFA_GNU_args_size:
684 return "DW_CFA_GNU_args_size";
687 return "DW_CFA_<unknown>";
691 /* Return a pointer to a newly allocated Call Frame Instruction. */
693 static inline dw_cfi_ref
696 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
698 cfi->dw_cfi_next = NULL;
699 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
700 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
705 /* Add a Call Frame Instruction to list of instructions. */
708 add_cfi (list_head, cfi)
709 register dw_cfi_ref *list_head;
710 register dw_cfi_ref cfi;
712 register dw_cfi_ref *p;
714 /* Find the end of the chain. */
715 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
721 /* Generate a new label for the CFI info to refer to. */
724 dwarf2out_cfi_label ()
726 static char label[20];
727 static unsigned long label_num = 0;
729 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
730 ASM_OUTPUT_LABEL (asm_out_file, label);
735 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
736 or to the CIE if LABEL is NULL. */
739 add_fde_cfi (label, cfi)
740 register char *label;
741 register dw_cfi_ref cfi;
745 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
748 label = dwarf2out_cfi_label ();
750 if (fde->dw_fde_current_label == NULL
751 || strcmp (label, fde->dw_fde_current_label) != 0)
753 register dw_cfi_ref xcfi;
755 fde->dw_fde_current_label = label = xstrdup (label);
757 /* Set the location counter to the new label. */
759 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
760 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
761 add_cfi (&fde->dw_fde_cfi, xcfi);
764 add_cfi (&fde->dw_fde_cfi, cfi);
768 add_cfi (&cie_cfi_head, cfi);
771 /* Subroutine of lookup_cfa. */
774 lookup_cfa_1 (cfi, regp, offsetp)
775 register dw_cfi_ref cfi;
776 register unsigned long *regp;
777 register long *offsetp;
779 switch (cfi->dw_cfi_opc)
781 case DW_CFA_def_cfa_offset:
782 *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
784 case DW_CFA_def_cfa_register:
785 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
788 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
789 *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
796 /* Find the previous value for the CFA. */
799 lookup_cfa (regp, offsetp)
800 register unsigned long *regp;
801 register long *offsetp;
803 register dw_cfi_ref cfi;
805 *regp = (unsigned long) -1;
808 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
809 lookup_cfa_1 (cfi, regp, offsetp);
811 if (fde_table_in_use)
813 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
814 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
815 lookup_cfa_1 (cfi, regp, offsetp);
819 /* The current rule for calculating the DWARF2 canonical frame address. */
820 static unsigned long cfa_reg;
821 static long cfa_offset;
823 /* The register used for saving registers to the stack, and its offset
825 static unsigned cfa_store_reg;
826 static long cfa_store_offset;
828 /* The running total of the size of arguments pushed onto the stack. */
829 static long args_size;
831 /* Entry point to update the canonical frame address (CFA).
832 LABEL is passed to add_fde_cfi. The value of CFA is now to be
833 calculated from REG+OFFSET. */
836 dwarf2out_def_cfa (label, reg, offset)
837 register char *label;
838 register unsigned reg;
839 register long offset;
841 register dw_cfi_ref cfi;
842 unsigned long old_reg;
847 if (cfa_store_reg == reg)
848 cfa_store_offset = offset;
850 reg = DWARF_FRAME_REGNUM (reg);
851 lookup_cfa (&old_reg, &old_offset);
853 if (reg == old_reg && offset == old_offset)
860 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
861 cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
864 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
865 else if (offset == old_offset && old_reg != (unsigned long) -1)
867 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
868 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
874 cfi->dw_cfi_opc = DW_CFA_def_cfa;
875 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
876 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
879 add_fde_cfi (label, cfi);
882 /* Add the CFI for saving a register. REG is the CFA column number.
883 LABEL is passed to add_fde_cfi.
884 If SREG is -1, the register is saved at OFFSET from the CFA;
885 otherwise it is saved in SREG. */
888 reg_save (label, reg, sreg, offset)
889 register char * label;
890 register unsigned reg;
891 register unsigned sreg;
892 register long offset;
894 register dw_cfi_ref cfi = new_cfi ();
896 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
901 /* The register number won't fit in 6 bits, so we have to use
903 cfi->dw_cfi_opc = DW_CFA_offset_extended;
905 cfi->dw_cfi_opc = DW_CFA_offset;
907 offset /= DWARF_CIE_DATA_ALIGNMENT;
910 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
914 cfi->dw_cfi_opc = DW_CFA_register;
915 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
918 add_fde_cfi (label, cfi);
921 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
922 This CFI tells the unwinder that it needs to restore the window registers
923 from the previous frame's window save area.
925 ??? Perhaps we should note in the CIE where windows are saved (instead of
926 assuming 0(cfa)) and what registers are in the window. */
929 dwarf2out_window_save (label)
930 register char * label;
932 register dw_cfi_ref cfi = new_cfi ();
933 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
934 add_fde_cfi (label, cfi);
937 /* Add a CFI to update the running total of the size of arguments
938 pushed onto the stack. */
941 dwarf2out_args_size (label, size)
945 register dw_cfi_ref cfi = new_cfi ();
946 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
947 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
948 add_fde_cfi (label, cfi);
951 /* Entry point for saving a register to the stack. REG is the GCC register
952 number. LABEL and OFFSET are passed to reg_save. */
955 dwarf2out_reg_save (label, reg, offset)
956 register char * label;
957 register unsigned reg;
958 register long offset;
960 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
963 /* Entry point for saving the return address in the stack.
964 LABEL and OFFSET are passed to reg_save. */
967 dwarf2out_return_save (label, offset)
968 register char * label;
969 register long offset;
971 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
974 /* Entry point for saving the return address in a register.
975 LABEL and SREG are passed to reg_save. */
978 dwarf2out_return_reg (label, sreg)
979 register char * label;
980 register unsigned sreg;
982 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
985 /* Record the initial position of the return address. RTL is
986 INCOMING_RETURN_ADDR_RTX. */
989 initial_return_save (rtl)
995 switch (GET_CODE (rtl))
998 /* RA is in a register. */
999 reg = reg_number (rtl);
1002 /* RA is on the stack. */
1003 rtl = XEXP (rtl, 0);
1004 switch (GET_CODE (rtl))
1007 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1012 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1014 offset = INTVAL (XEXP (rtl, 1));
1017 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1019 offset = -INTVAL (XEXP (rtl, 1));
1026 /* The return address is at some offset from any value we can
1027 actually load. For instance, on the SPARC it is in %i7+8. Just
1028 ignore the offset for now; it doesn't matter for unwinding frames. */
1029 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1031 initial_return_save (XEXP (rtl, 0));
1037 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset);
1040 /* Check INSN to see if it looks like a push or a stack adjustment, and
1041 make a note of it if it does. EH uses this information to find out how
1042 much extra space it needs to pop off the stack. */
1045 dwarf2out_stack_adjust (insn)
1051 if (GET_CODE (insn) == BARRIER)
1053 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1054 the compiler will have already emitted a stack adjustment, but
1055 doesn't bother for calls to noreturn functions. */
1056 #ifdef STACK_GROWS_DOWNWARD
1057 offset = -args_size;
1062 else if (GET_CODE (PATTERN (insn)) == SET)
1067 insn = PATTERN (insn);
1068 src = SET_SRC (insn);
1069 dest = SET_DEST (insn);
1071 if (dest == stack_pointer_rtx)
1073 /* (set (reg sp) (plus (reg sp) (const_int))) */
1074 code = GET_CODE (src);
1075 if (! (code == PLUS || code == MINUS)
1076 || XEXP (src, 0) != stack_pointer_rtx
1077 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1080 offset = INTVAL (XEXP (src, 1));
1082 else if (GET_CODE (dest) == MEM)
1084 /* (set (mem (pre_dec (reg sp))) (foo)) */
1085 src = XEXP (dest, 0);
1086 code = GET_CODE (src);
1088 if (! (code == PRE_DEC || code == PRE_INC)
1089 || XEXP (src, 0) != stack_pointer_rtx)
1092 offset = GET_MODE_SIZE (GET_MODE (dest));
1097 if (code == PLUS || code == PRE_INC)
1106 if (cfa_reg == STACK_POINTER_REGNUM)
1107 cfa_offset += offset;
1109 #ifndef STACK_GROWS_DOWNWARD
1112 args_size += offset;
1116 label = dwarf2out_cfi_label ();
1117 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1118 dwarf2out_args_size (label, args_size);
1121 /* Record call frame debugging information for INSN, which either
1122 sets SP or FP (adjusting how we calculate the frame address) or saves a
1123 register to the stack. If INSN is NULL_RTX, initialize our state. */
1126 dwarf2out_frame_debug (insn)
1133 /* A temporary register used in adjusting SP or setting up the store_reg. */
1134 static unsigned cfa_temp_reg;
1135 static long cfa_temp_value;
1137 if (insn == NULL_RTX)
1139 /* Set up state for generating call frame debug info. */
1140 lookup_cfa (&cfa_reg, &cfa_offset);
1141 if (cfa_reg != DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1143 cfa_reg = STACK_POINTER_REGNUM;
1144 cfa_store_reg = cfa_reg;
1145 cfa_store_offset = cfa_offset;
1151 if (! RTX_FRAME_RELATED_P (insn))
1153 dwarf2out_stack_adjust (insn);
1157 label = dwarf2out_cfi_label ();
1159 insn = PATTERN (insn);
1160 /* Assume that in a PARALLEL prologue insn, only the first elt is
1161 significant. Currently this is true. */
1162 if (GET_CODE (insn) == PARALLEL)
1163 insn = XVECEXP (insn, 0, 0);
1164 if (GET_CODE (insn) != SET)
1167 src = SET_SRC (insn);
1168 dest = SET_DEST (insn);
1170 switch (GET_CODE (dest))
1173 /* Update the CFA rule wrt SP or FP. Make sure src is
1174 relative to the current CFA register. */
1175 switch (GET_CODE (src))
1177 /* Setting FP from SP. */
1179 if (cfa_reg != REGNO (src))
1181 if (REGNO (dest) != STACK_POINTER_REGNUM
1182 && !(frame_pointer_needed
1183 && REGNO (dest) == HARD_FRAME_POINTER_REGNUM))
1185 cfa_reg = REGNO (dest);
1190 if (dest == stack_pointer_rtx)
1193 switch (GET_CODE (XEXP (src, 1)))
1196 offset = INTVAL (XEXP (src, 1));
1199 if (REGNO (XEXP (src, 1)) != cfa_temp_reg)
1201 offset = cfa_temp_value;
1207 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1209 /* Restoring SP from FP in the epilogue. */
1210 if (cfa_reg != HARD_FRAME_POINTER_REGNUM)
1212 cfa_reg = STACK_POINTER_REGNUM;
1214 else if (XEXP (src, 0) != stack_pointer_rtx)
1217 if (GET_CODE (src) == PLUS)
1219 if (cfa_reg == STACK_POINTER_REGNUM)
1220 cfa_offset += offset;
1221 if (cfa_store_reg == STACK_POINTER_REGNUM)
1222 cfa_store_offset += offset;
1226 if (GET_CODE (src) != PLUS
1227 || XEXP (src, 1) != stack_pointer_rtx)
1229 if (GET_CODE (XEXP (src, 0)) != REG
1230 || REGNO (XEXP (src, 0)) != cfa_temp_reg)
1232 if (cfa_reg != STACK_POINTER_REGNUM)
1234 cfa_store_reg = REGNO (dest);
1235 cfa_store_offset = cfa_offset - cfa_temp_value;
1240 cfa_temp_reg = REGNO (dest);
1241 cfa_temp_value = INTVAL (src);
1245 if (GET_CODE (XEXP (src, 0)) != REG
1246 || REGNO (XEXP (src, 0)) != cfa_temp_reg
1247 || REGNO (dest) != cfa_temp_reg
1248 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1250 cfa_temp_value |= INTVAL (XEXP (src, 1));
1256 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1260 /* Saving a register to the stack. Make sure dest is relative to the
1262 if (GET_CODE (src) != REG)
1264 switch (GET_CODE (XEXP (dest, 0)))
1269 offset = GET_MODE_SIZE (GET_MODE (dest));
1270 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1273 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1274 || cfa_store_reg != STACK_POINTER_REGNUM)
1276 cfa_store_offset += offset;
1277 if (cfa_reg == STACK_POINTER_REGNUM)
1278 cfa_offset = cfa_store_offset;
1280 offset = -cfa_store_offset;
1283 /* With an offset. */
1286 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1287 if (GET_CODE (src) == MINUS)
1290 if (cfa_store_reg != REGNO (XEXP (XEXP (dest, 0), 0)))
1292 offset -= cfa_store_offset;
1298 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1299 dwarf2out_reg_save (label, REGNO (src), offset);
1307 /* Return the size of an unsigned LEB128 quantity. */
1309 static inline unsigned long
1310 size_of_uleb128 (value)
1311 register unsigned long value;
1313 register unsigned long size = 0;
1314 register unsigned byte;
1318 byte = (value & 0x7f);
1327 /* Return the size of a signed LEB128 quantity. */
1329 static inline unsigned long
1330 size_of_sleb128 (value)
1331 register long value;
1333 register unsigned long size = 0;
1334 register unsigned byte;
1338 byte = (value & 0x7f);
1342 while (!(((value == 0) && ((byte & 0x40) == 0))
1343 || ((value == -1) && ((byte & 0x40) != 0))));
1348 /* Output an unsigned LEB128 quantity. */
1351 output_uleb128 (value)
1352 register unsigned long value;
1354 unsigned long save_value = value;
1356 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1359 register unsigned byte = (value & 0x7f);
1362 /* More bytes to follow. */
1365 fprintf (asm_out_file, "0x%x", byte);
1367 fprintf (asm_out_file, ",");
1372 fprintf (asm_out_file, "\t%s ULEB128 0x%x", ASM_COMMENT_START, save_value);
1375 /* Output an signed LEB128 quantity. */
1378 output_sleb128 (value)
1379 register long value;
1382 register unsigned byte;
1383 long save_value = value;
1385 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1388 byte = (value & 0x7f);
1389 /* arithmetic shift */
1391 more = !((((value == 0) && ((byte & 0x40) == 0))
1392 || ((value == -1) && ((byte & 0x40) != 0))));
1396 fprintf (asm_out_file, "0x%x", byte);
1398 fprintf (asm_out_file, ",");
1403 fprintf (asm_out_file, "\t%s SLEB128 %d", ASM_COMMENT_START, save_value);
1406 /* Output a Call Frame Information opcode and its operand(s). */
1409 output_cfi (cfi, fde)
1410 register dw_cfi_ref cfi;
1411 register dw_fde_ref fde;
1413 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1415 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1417 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1419 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%x",
1420 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1421 fputc ('\n', asm_out_file);
1424 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1426 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1428 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1430 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%x",
1431 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1433 fputc ('\n', asm_out_file);
1434 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1435 fputc ('\n', asm_out_file);
1437 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1439 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1441 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1443 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%x",
1444 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1446 fputc ('\n', asm_out_file);
1450 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1452 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1453 dwarf_cfi_name (cfi->dw_cfi_opc));
1455 fputc ('\n', asm_out_file);
1456 switch (cfi->dw_cfi_opc)
1458 case DW_CFA_set_loc:
1459 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1460 fputc ('\n', asm_out_file);
1462 case DW_CFA_advance_loc1:
1463 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1464 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1465 fde->dw_fde_current_label);
1466 fputc ('\n', asm_out_file);
1467 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1469 case DW_CFA_advance_loc2:
1470 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1471 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1472 fde->dw_fde_current_label);
1473 fputc ('\n', asm_out_file);
1474 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1476 case DW_CFA_advance_loc4:
1477 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1478 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1479 fde->dw_fde_current_label);
1480 fputc ('\n', asm_out_file);
1481 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1483 #ifdef MIPS_DEBUGGING_INFO
1484 case DW_CFA_MIPS_advance_loc8:
1485 /* TODO: not currently implemented. */
1489 case DW_CFA_offset_extended:
1490 case DW_CFA_def_cfa:
1491 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1492 fputc ('\n', asm_out_file);
1493 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1494 fputc ('\n', asm_out_file);
1496 case DW_CFA_restore_extended:
1497 case DW_CFA_undefined:
1498 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1499 fputc ('\n', asm_out_file);
1501 case DW_CFA_same_value:
1502 case DW_CFA_def_cfa_register:
1503 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1504 fputc ('\n', asm_out_file);
1506 case DW_CFA_register:
1507 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1508 fputc ('\n', asm_out_file);
1509 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1510 fputc ('\n', asm_out_file);
1512 case DW_CFA_def_cfa_offset:
1513 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1514 fputc ('\n', asm_out_file);
1516 case DW_CFA_GNU_window_save:
1518 case DW_CFA_GNU_args_size:
1519 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1520 fputc ('\n', asm_out_file);
1528 #if !defined (EH_FRAME_SECTION)
1529 #if defined (EH_FRAME_SECTION_ASM_OP)
1530 #define EH_FRAME_SECTION() eh_frame_section();
1532 #if defined (ASM_OUTPUT_SECTION_NAME)
1533 #define EH_FRAME_SECTION() \
1535 named_section (NULL_TREE, ".eh_frame", 0); \
1541 /* Output the call frame information used to used to record information
1542 that relates to calculating the frame pointer, and records the
1543 location of saved registers. */
1546 output_call_frame_info (for_eh)
1549 register unsigned long i, j;
1550 register dw_fde_ref fde;
1551 register unsigned long fde_size;
1552 register dw_cfi_ref cfi;
1553 unsigned long fde_pad;
1554 char l1[20], l2[20];
1555 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1559 /* Do we want to include a pointer to the exception table? */
1560 int eh_ptr = for_eh && exception_table_p ();
1562 fputc ('\n', asm_out_file);
1564 /* We're going to be generating comments, so turn on app. */
1570 #ifdef EH_FRAME_SECTION
1571 EH_FRAME_SECTION ();
1573 tree label = get_file_function_name ('F');
1576 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1577 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1579 assemble_label ("__FRAME_BEGIN__");
1582 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1584 /* Output the CIE. */
1585 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1586 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1587 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1588 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1590 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1592 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1595 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1597 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1600 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1603 fputc ('\n', asm_out_file);
1604 ASM_OUTPUT_LABEL (asm_out_file, l1);
1607 /* Now that the CIE pointer is PC-relative for EH,
1608 use 0 to identify the CIE. */
1609 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1611 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1614 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1616 fputc ('\n', asm_out_file);
1617 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1619 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1620 fputc ('\n', asm_out_file);
1623 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1625 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1627 fputc ('\n', asm_out_file);
1630 /* The CIE contains a pointer to the exception region info for the
1631 frame. Make the augmentation string three bytes (including the
1632 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1633 can't handle unaligned relocs. */
1636 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1637 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1641 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1643 fputc ('\n', asm_out_file);
1645 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1647 fprintf (asm_out_file, "\t%s pointer to exception region info",
1652 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1654 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1658 fputc ('\n', asm_out_file);
1661 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1663 fputc ('\n', asm_out_file);
1664 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1666 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1668 fputc ('\n', asm_out_file);
1669 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1671 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1673 fputc ('\n', asm_out_file);
1675 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1676 output_cfi (cfi, NULL);
1678 /* Pad the CIE out to an address sized boundary. */
1679 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1680 ASM_OUTPUT_LABEL (asm_out_file, l2);
1681 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1682 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1684 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1685 fputc ('\n', asm_out_file);
1688 /* Loop through all of the FDE's. */
1689 for (i = 0; i < fde_table_in_use; ++i)
1691 fde = &fde_table[i];
1693 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2);
1694 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2);
1695 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1696 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2);
1698 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1700 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1703 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1705 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1708 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1709 fputc ('\n', asm_out_file);
1710 ASM_OUTPUT_LABEL (asm_out_file, l1);
1713 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l1, "__FRAME_BEGIN__");
1715 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1717 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1719 fputc ('\n', asm_out_file);
1720 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1722 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1724 fputc ('\n', asm_out_file);
1725 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1726 fde->dw_fde_end, fde->dw_fde_begin);
1728 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1730 fputc ('\n', asm_out_file);
1732 /* Loop through the Call Frame Instructions associated with
1734 fde->dw_fde_current_label = fde->dw_fde_begin;
1735 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1736 output_cfi (cfi, fde);
1738 /* Pad the FDE out to an address sized boundary. */
1739 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1740 ASM_OUTPUT_LABEL (asm_out_file, l2);
1741 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1742 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1744 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1745 fputc ('\n', asm_out_file);
1748 #ifndef EH_FRAME_SECTION
1751 /* Emit terminating zero for table. */
1752 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1753 fputc ('\n', asm_out_file);
1756 #ifdef MIPS_DEBUGGING_INFO
1757 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1758 get a value of 0. Putting .align 0 after the label fixes it. */
1759 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1762 /* Turn off app to make assembly quicker. */
1767 /* Output a marker (i.e. a label) for the beginning of a function, before
1771 dwarf2out_begin_prologue ()
1773 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1774 register dw_fde_ref fde;
1776 ++current_funcdef_number;
1778 function_section (current_function_decl);
1779 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1780 current_funcdef_number);
1781 ASM_OUTPUT_LABEL (asm_out_file, label);
1783 /* Expand the fde table if necessary. */
1784 if (fde_table_in_use == fde_table_allocated)
1786 fde_table_allocated += FDE_TABLE_INCREMENT;
1788 = (dw_fde_ref) xrealloc (fde_table,
1789 fde_table_allocated * sizeof (dw_fde_node));
1792 /* Record the FDE associated with this function. */
1793 current_funcdef_fde = fde_table_in_use;
1795 /* Add the new FDE at the end of the fde_table. */
1796 fde = &fde_table[fde_table_in_use++];
1797 fde->dw_fde_begin = xstrdup (label);
1798 fde->dw_fde_current_label = NULL;
1799 fde->dw_fde_end = NULL;
1800 fde->dw_fde_cfi = NULL;
1805 /* Output a marker (i.e. a label) for the absolute end of the generated code
1806 for a function definition. This gets called *after* the epilogue code has
1810 dwarf2out_end_epilogue ()
1813 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1815 /* Output a label to mark the endpoint of the code generated for this
1817 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1818 ASM_OUTPUT_LABEL (asm_out_file, label);
1819 fde = &fde_table[fde_table_in_use - 1];
1820 fde->dw_fde_end = xstrdup (label);
1824 dwarf2out_frame_init ()
1826 /* Allocate the initial hunk of the fde_table. */
1828 = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1829 bzero ((char *) fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1830 fde_table_allocated = FDE_TABLE_INCREMENT;
1831 fde_table_in_use = 0;
1833 /* Generate the CFA instructions common to all FDE's. Do it now for the
1834 sake of lookup_cfa. */
1836 #ifdef DWARF2_UNWIND_INFO
1837 /* On entry, the Canonical Frame Address is at SP. */
1838 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1839 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1844 dwarf2out_frame_finish ()
1846 /* Output call frame information. */
1847 #ifdef MIPS_DEBUGGING_INFO
1848 if (write_symbols == DWARF2_DEBUG)
1849 output_call_frame_info (0);
1850 if (flag_exceptions && ! exceptions_via_longjmp)
1851 output_call_frame_info (1);
1853 if (write_symbols == DWARF2_DEBUG
1854 || (flag_exceptions && ! exceptions_via_longjmp))
1855 output_call_frame_info (1);
1859 #endif /* .debug_frame support */
1861 /* And now, the support for symbolic debugging information. */
1862 #ifdef DWARF2_DEBUGGING_INFO
1864 extern char *getpwd ();
1866 /* NOTE: In the comments in this file, many references are made to
1867 "Debugging Information Entries". This term is abbreviated as `DIE'
1868 throughout the remainder of this file. */
1870 /* An internal representation of the DWARF output is built, and then
1871 walked to generate the DWARF debugging info. The walk of the internal
1872 representation is done after the entire program has been compiled.
1873 The types below are used to describe the internal representation. */
1875 /* Each DIE may have a series of attribute/value pairs. Values
1876 can take on several forms. The forms that are used in this
1877 implementation are listed below. */
1884 dw_val_class_unsigned_const,
1885 dw_val_class_long_long,
1888 dw_val_class_die_ref,
1889 dw_val_class_fde_ref,
1890 dw_val_class_lbl_id,
1891 dw_val_class_section_offset,
1896 /* Various DIE's use offsets relative to the beginning of the
1897 .debug_info section to refer to each other. */
1899 typedef long int dw_offset;
1901 /* Define typedefs here to avoid circular dependencies. */
1903 typedef struct die_struct *dw_die_ref;
1904 typedef struct dw_attr_struct *dw_attr_ref;
1905 typedef struct dw_val_struct *dw_val_ref;
1906 typedef struct dw_line_info_struct *dw_line_info_ref;
1907 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
1908 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1909 typedef struct pubname_struct *pubname_ref;
1910 typedef dw_die_ref *arange_ref;
1912 /* Describe a double word constant value. */
1914 typedef struct dw_long_long_struct
1921 /* Describe a floating point constant value. */
1923 typedef struct dw_fp_struct
1930 /* Each entry in the line_info_table maintains the file and
1931 line nuber associated with the label generated for that
1932 entry. The label gives the PC value associated with
1933 the line number entry. */
1935 typedef struct dw_line_info_struct
1937 unsigned long dw_file_num;
1938 unsigned long dw_line_num;
1942 /* Line information for functions in separate sections; each one gets its
1944 typedef struct dw_separate_line_info_struct
1946 unsigned long dw_file_num;
1947 unsigned long dw_line_num;
1948 unsigned long function;
1950 dw_separate_line_info_entry;
1952 /* The dw_val_node describes an attibute's value, as it is
1953 represented internally. */
1955 typedef struct dw_val_struct
1957 dw_val_class val_class;
1961 dw_loc_descr_ref val_loc;
1963 long unsigned val_unsigned;
1964 dw_long_long_const val_long_long;
1965 dw_float_const val_float;
1966 dw_die_ref val_die_ref;
1967 unsigned val_fde_index;
1971 unsigned char val_flag;
1977 /* Locations in memory are described using a sequence of stack machine
1980 typedef struct dw_loc_descr_struct
1982 dw_loc_descr_ref dw_loc_next;
1983 enum dwarf_location_atom dw_loc_opc;
1984 dw_val_node dw_loc_oprnd1;
1985 dw_val_node dw_loc_oprnd2;
1989 /* Each DIE attribute has a field specifying the attribute kind,
1990 a link to the next attribute in the chain, and an attribute value.
1991 Attributes are typically linked below the DIE they modify. */
1993 typedef struct dw_attr_struct
1995 enum dwarf_attribute dw_attr;
1996 dw_attr_ref dw_attr_next;
1997 dw_val_node dw_attr_val;
2001 /* The Debugging Information Entry (DIE) structure */
2003 typedef struct die_struct
2005 enum dwarf_tag die_tag;
2006 dw_attr_ref die_attr;
2007 dw_attr_ref die_attr_last;
2008 dw_die_ref die_parent;
2009 dw_die_ref die_child;
2010 dw_die_ref die_child_last;
2012 dw_offset die_offset;
2013 unsigned long die_abbrev;
2017 /* The pubname structure */
2019 typedef struct pubname_struct
2026 /* The limbo die list structure. */
2027 typedef struct limbo_die_struct
2030 struct limbo_die_struct *next;
2034 /* How to start an assembler comment. */
2035 #ifndef ASM_COMMENT_START
2036 #define ASM_COMMENT_START ";#"
2039 /* Define a macro which returns non-zero for a TYPE_DECL which was
2040 implicitly generated for a tagged type.
2042 Note that unlike the gcc front end (which generates a NULL named
2043 TYPE_DECL node for each complete tagged type, each array type, and
2044 each function type node created) the g++ front end generates a
2045 _named_ TYPE_DECL node for each tagged type node created.
2046 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2047 generate a DW_TAG_typedef DIE for them. */
2049 #define TYPE_DECL_IS_STUB(decl) \
2050 (DECL_NAME (decl) == NULL_TREE \
2051 || (DECL_ARTIFICIAL (decl) \
2052 && is_tagged_type (TREE_TYPE (decl)) \
2053 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2054 /* This is necessary for stub decls that \
2055 appear in nested inline functions. */ \
2056 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2057 && (decl_ultimate_origin (decl) \
2058 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2060 /* Information concerning the compilation unit's programming
2061 language, and compiler version. */
2063 extern int flag_traditional;
2064 extern char *version_string;
2065 extern char *language_string;
2067 /* Fixed size portion of the DWARF compilation unit header. */
2068 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2070 /* Fixed size portion of debugging line information prolog. */
2071 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2073 /* Fixed size portion of public names info. */
2074 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2076 /* Fixed size portion of the address range info. */
2077 #define DWARF_ARANGES_HEADER_SIZE \
2078 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
2080 /* Define the architecture-dependent minimum instruction length (in bytes).
2081 In this implementation of DWARF, this field is used for information
2082 purposes only. Since GCC generates assembly language, we have
2083 no a priori knowledge of how many instruction bytes are generated
2084 for each source line, and therefore can use only the DW_LNE_set_address
2085 and DW_LNS_fixed_advance_pc line information commands. */
2087 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2088 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2091 /* Minimum line offset in a special line info. opcode.
2092 This value was chosen to give a reasonable range of values. */
2093 #define DWARF_LINE_BASE -10
2095 /* First special line opcde - leave room for the standard opcodes. */
2096 #define DWARF_LINE_OPCODE_BASE 10
2098 /* Range of line offsets in a special line info. opcode. */
2099 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2101 /* Flag that indicates the initial value of the is_stmt_start flag.
2102 In the present implementation, we do not mark any lines as
2103 the beginning of a source statement, because that information
2104 is not made available by the GCC front-end. */
2105 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2107 /* This location is used by calc_die_sizes() to keep track
2108 the offset of each DIE within the .debug_info section. */
2109 static unsigned long next_die_offset;
2111 /* Record the root of the DIE's built for the current compilation unit. */
2112 static dw_die_ref comp_unit_die;
2114 /* A list of DIEs with a NULL parent waiting to be relocated. */
2115 static limbo_die_node *limbo_die_list = 0;
2117 /* Pointer to an array of filenames referenced by this compilation unit. */
2118 static char **file_table;
2120 /* Total number of entries in the table (i.e. array) pointed to by
2121 `file_table'. This is the *total* and includes both used and unused
2123 static unsigned file_table_allocated;
2125 /* Number of entries in the file_table which are actually in use. */
2126 static unsigned file_table_in_use;
2128 /* Size (in elements) of increments by which we may expand the filename
2130 #define FILE_TABLE_INCREMENT 64
2132 /* Local pointer to the name of the main input file. Initialized in
2134 static char *primary_filename;
2136 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
2137 which their beginnings are encountered. We output Dwarf debugging info
2138 that refers to the beginnings and ends of the ranges of code for each
2139 lexical block. The labels themselves are generated in final.c, which
2140 assigns numbers to the blocks in the same way. */
2141 static unsigned next_block_number = 2;
2143 /* A pointer to the base of a table of references to DIE's that describe
2144 declarations. The table is indexed by DECL_UID() which is a unique
2145 number, indentifying each decl. */
2146 static dw_die_ref *decl_die_table;
2148 /* Number of elements currently allocated for the decl_die_table. */
2149 static unsigned decl_die_table_allocated;
2151 /* Number of elements in decl_die_table currently in use. */
2152 static unsigned decl_die_table_in_use;
2154 /* Size (in elements) of increments by which we may expand the
2156 #define DECL_DIE_TABLE_INCREMENT 256
2158 /* A pointer to the base of a table of references to declaration
2159 scopes. This table is a display which tracks the nesting
2160 of declaration scopes at the current scope and containing
2161 scopes. This table is used to find the proper place to
2162 define type declaration DIE's. */
2163 static tree *decl_scope_table;
2165 /* Number of elements currently allocated for the decl_scope_table. */
2166 static unsigned decl_scope_table_allocated;
2168 /* Current level of nesting of declataion scopes. */
2169 static unsigned decl_scope_depth;
2171 /* Size (in elements) of increments by which we may expand the
2172 decl_scope_table. */
2173 #define DECL_SCOPE_TABLE_INCREMENT 64
2175 /* A pointer to the base of a list of references to DIE's that
2176 are uniquely identified by their tag, presence/absence of
2177 children DIE's, and list of attribute/value pairs. */
2178 static dw_die_ref *abbrev_die_table;
2180 /* Number of elements currently allocated for abbrev_die_table. */
2181 static unsigned abbrev_die_table_allocated;
2183 /* Number of elements in type_die_table currently in use. */
2184 static unsigned abbrev_die_table_in_use;
2186 /* Size (in elements) of increments by which we may expand the
2187 abbrev_die_table. */
2188 #define ABBREV_DIE_TABLE_INCREMENT 256
2190 /* A pointer to the base of a table that contains line information
2191 for each source code line in .text in the compilation unit. */
2192 static dw_line_info_ref line_info_table;
2194 /* Number of elements currently allocated for line_info_table. */
2195 static unsigned line_info_table_allocated;
2197 /* Number of elements in separate_line_info_table currently in use. */
2198 static unsigned separate_line_info_table_in_use;
2200 /* A pointer to the base of a table that contains line information
2201 for each source code line outside of .text in the compilation unit. */
2202 static dw_separate_line_info_ref separate_line_info_table;
2204 /* Number of elements currently allocated for separate_line_info_table. */
2205 static unsigned separate_line_info_table_allocated;
2207 /* Number of elements in line_info_table currently in use. */
2208 static unsigned line_info_table_in_use;
2210 /* Size (in elements) of increments by which we may expand the
2212 #define LINE_INFO_TABLE_INCREMENT 1024
2214 /* A pointer to the base of a table that contains a list of publicly
2215 accessible names. */
2216 static pubname_ref pubname_table;
2218 /* Number of elements currently allocated for pubname_table. */
2219 static unsigned pubname_table_allocated;
2221 /* Number of elements in pubname_table currently in use. */
2222 static unsigned pubname_table_in_use;
2224 /* Size (in elements) of increments by which we may expand the
2226 #define PUBNAME_TABLE_INCREMENT 64
2228 /* A pointer to the base of a table that contains a list of publicly
2229 accessible names. */
2230 static arange_ref arange_table;
2232 /* Number of elements currently allocated for arange_table. */
2233 static unsigned arange_table_allocated;
2235 /* Number of elements in arange_table currently in use. */
2236 static unsigned arange_table_in_use;
2238 /* Size (in elements) of increments by which we may expand the
2240 #define ARANGE_TABLE_INCREMENT 64
2242 /* A pointer to the base of a list of pending types which we haven't
2243 generated DIEs for yet, but which we will have to come back to
2246 static tree *pending_types_list;
2248 /* Number of elements currently allocated for the pending_types_list. */
2249 static unsigned pending_types_allocated;
2251 /* Number of elements of pending_types_list currently in use. */
2252 static unsigned pending_types;
2254 /* Size (in elements) of increments by which we may expand the pending
2255 types list. Actually, a single hunk of space of this size should
2256 be enough for most typical programs. */
2257 #define PENDING_TYPES_INCREMENT 64
2259 /* Record whether the function being analyzed contains inlined functions. */
2260 static int current_function_has_inlines;
2261 static int comp_unit_has_inlines;
2263 /* A pointer to the ..._DECL node which we have most recently been working
2264 on. We keep this around just in case something about it looks screwy and
2265 we want to tell the user what the source coordinates for the actual
2267 static tree dwarf_last_decl;
2269 /* Forward declarations for functions defined in this file. */
2271 static void addr_const_to_string PROTO((char *, rtx));
2272 static char *addr_to_string PROTO((rtx));
2273 static int is_pseudo_reg PROTO((rtx));
2274 static tree type_main_variant PROTO((tree));
2275 static int is_tagged_type PROTO((tree));
2276 static char *dwarf_tag_name PROTO((unsigned));
2277 static char *dwarf_attr_name PROTO((unsigned));
2278 static char *dwarf_form_name PROTO((unsigned));
2279 static char *dwarf_stack_op_name PROTO((unsigned));
2280 static char *dwarf_type_encoding_name PROTO((unsigned));
2281 static tree decl_ultimate_origin PROTO((tree));
2282 static tree block_ultimate_origin PROTO((tree));
2283 static tree decl_class_context PROTO((tree));
2284 static void add_dwarf_attr PROTO((dw_die_ref, dw_attr_ref));
2285 static void add_AT_flag PROTO((dw_die_ref,
2286 enum dwarf_attribute,
2288 static void add_AT_int PROTO((dw_die_ref,
2289 enum dwarf_attribute, long));
2290 static void add_AT_unsigned PROTO((dw_die_ref,
2291 enum dwarf_attribute,
2293 static void add_AT_long_long PROTO((dw_die_ref,
2294 enum dwarf_attribute,
2295 unsigned long, unsigned long));
2296 static void add_AT_float PROTO((dw_die_ref,
2297 enum dwarf_attribute,
2299 static void add_AT_string PROTO((dw_die_ref,
2300 enum dwarf_attribute, char *));
2301 static void add_AT_die_ref PROTO((dw_die_ref,
2302 enum dwarf_attribute,
2304 static void add_AT_fde_ref PROTO((dw_die_ref,
2305 enum dwarf_attribute,
2307 static void add_AT_loc PROTO((dw_die_ref,
2308 enum dwarf_attribute,
2310 static void add_AT_addr PROTO((dw_die_ref,
2311 enum dwarf_attribute, char *));
2312 static void add_AT_lbl_id PROTO((dw_die_ref,
2313 enum dwarf_attribute, char *));
2314 static void add_AT_setion_offset PROTO((dw_die_ref,
2315 enum dwarf_attribute, char *));
2316 static int is_extern_subr_die PROTO((dw_die_ref));
2317 static dw_attr_ref get_AT PROTO((dw_die_ref,
2318 enum dwarf_attribute));
2319 static char *get_AT_low_pc PROTO((dw_die_ref));
2320 static char *get_AT_hi_pc PROTO((dw_die_ref));
2321 static char *get_AT_string PROTO((dw_die_ref,
2322 enum dwarf_attribute));
2323 static int get_AT_flag PROTO((dw_die_ref,
2324 enum dwarf_attribute));
2325 static unsigned get_AT_unsigned PROTO((dw_die_ref,
2326 enum dwarf_attribute));
2327 static int is_c_family PROTO((void));
2328 static int is_fortran PROTO((void));
2329 static void remove_AT PROTO((dw_die_ref,
2330 enum dwarf_attribute));
2331 static void remove_children PROTO((dw_die_ref));
2332 static void add_child_die PROTO((dw_die_ref, dw_die_ref));
2333 static dw_die_ref new_die PROTO((enum dwarf_tag, dw_die_ref));
2334 static dw_die_ref lookup_type_die PROTO((tree));
2335 static void equate_type_number_to_die PROTO((tree, dw_die_ref));
2336 static dw_die_ref lookup_decl_die PROTO((tree));
2337 static void equate_decl_number_to_die PROTO((tree, dw_die_ref));
2338 static dw_loc_descr_ref new_loc_descr PROTO((enum dwarf_location_atom,
2339 unsigned long, unsigned long));
2340 static void add_loc_descr PROTO((dw_loc_descr_ref *,
2342 static void print_spaces PROTO((FILE *));
2343 static void print_die PROTO((dw_die_ref, FILE *));
2344 static void print_dwarf_line_table PROTO((FILE *));
2345 static void add_sibling_atttributes PROTO((dw_die_ref));
2346 static void build_abbrev_table PROTO((dw_die_ref));
2347 static unsigned long size_of_string PROTO((char *));
2348 static unsigned long size_of_loc_descr PROTO((dw_loc_descr_ref));
2349 static unsigned long size_of_locs PROTO((dw_loc_descr_ref));
2350 static int constant_size PROTO((long unsigned));
2351 static unsigned long size_of_die PROTO((dw_die_ref));
2352 static void calc_die_sizes PROTO((dw_die_ref));
2353 static unsigned long size_of_prolog PROTO((void));
2354 static unsigned long size_of_line_info PROTO((void));
2355 static unsigned long size_of_pubnames PROTO((void));
2356 static unsigned long size_of_aranges PROTO((void));
2357 static enum dwarf_form value_format PROTO((dw_val_ref));
2358 static void output_value_format PROTO((dw_val_ref));
2359 static void output_abbrev_section PROTO((void));
2360 static void output_loc_operands PROTO((dw_loc_descr_ref));
2361 static unsigned long sibling_offset PROTO((dw_die_ref));
2362 static void output_die PROTO((dw_die_ref));
2363 static void output_compilation_unit_header PROTO((void));
2364 static char *dwarf2_name PROTO((tree, int));
2365 static void add_pubname PROTO((tree, dw_die_ref));
2366 static void output_pubnames PROTO((void));
2367 static void add_arrange PROTO((tree, dw_die_ref));
2368 static void output_arranges PROTO((void));
2369 static void output_line_info PROTO((void));
2370 static int is_body_block PROTO((tree));
2371 static dw_die_ref base_type_die PROTO((tree));
2372 static tree root_type PROTO((tree));
2373 static int is_base_type PROTO((tree));
2374 static dw_die_ref modified_type_die PROTO((tree, int, int, dw_die_ref));
2375 static int type_is_enum PROTO((tree));
2376 static dw_loc_descr_ref reg_loc_descriptor PROTO((rtx));
2377 static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long));
2378 static int is_based_loc PROTO((rtx));
2379 static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx));
2380 static dw_loc_descr_ref concat_loc_descriptor PROTO((rtx, rtx));
2381 static dw_loc_descr_ref loc_descriptor PROTO((rtx));
2382 static unsigned ceiling PROTO((unsigned, unsigned));
2383 static tree field_type PROTO((tree));
2384 static unsigned simple_type_align_in_bits PROTO((tree));
2385 static unsigned simple_type_size_in_bits PROTO((tree));
2386 static unsigned field_byte_offset PROTO((tree));
2387 static void add_AT_location_description PROTO((dw_die_ref,
2388 enum dwarf_attribute, rtx));
2389 static void add_data_member_location_attribute PROTO((dw_die_ref, tree));
2390 static void add_const_value_attribute PROTO((dw_die_ref, rtx));
2391 static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree));
2392 static void add_name_attribute PROTO((dw_die_ref, char *));
2393 static void add_bound_info PROTO((dw_die_ref,
2394 enum dwarf_attribute, tree));
2395 static void add_subscript_info PROTO((dw_die_ref, tree));
2396 static void add_byte_size_attribute PROTO((dw_die_ref, tree));
2397 static void add_bit_offset_attribute PROTO((dw_die_ref, tree));
2398 static void add_bit_size_attribute PROTO((dw_die_ref, tree));
2399 static void add_prototyped_attribute PROTO((dw_die_ref, tree));
2400 static void add_abstract_origin_attribute PROTO((dw_die_ref, tree));
2401 static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree));
2402 static void add_src_coords_attributes PROTO((dw_die_ref, tree));
2403 static void ad_name_and_src_coords_attributes PROTO((dw_die_ref, tree));
2404 static void push_decl_scope PROTO((tree));
2405 static dw_die_ref scope_die_for PROTO((tree, dw_die_ref));
2406 static void pop_decl_scope PROTO((void));
2407 static void add_type_attribute PROTO((dw_die_ref, tree, int, int,
2409 static char *type_tag PROTO((tree));
2410 static tree member_declared_type PROTO((tree));
2411 static char *decl_start_label PROTO((tree));
2412 static void gen_arrqay_type_die PROTO((tree, dw_die_ref));
2413 static void gen_set_type_die PROTO((tree, dw_die_ref));
2414 static void gen_entry_point_die PROTO((tree, dw_die_ref));
2415 static void pend_type PROTO((tree));
2416 static void output_pending_types_for_scope PROTO((dw_die_ref));
2417 static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref));
2418 static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref));
2419 static void gen_inlined_union_type_die PROTO((tree, dw_die_ref));
2420 static void gen_enumeration_type_die PROTO((tree, dw_die_ref));
2421 static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref));
2422 static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref));
2423 static void gen_formal_types_die PROTO((tree, dw_die_ref));
2424 static void gen_subprogram_die PROTO((tree, dw_die_ref));
2425 static void gen_variable_die PROTO((tree, dw_die_ref));
2426 static void gen_label_die PROTO((tree, dw_die_ref));
2427 static void gen_lexical_block_die PROTO((tree, dw_die_ref, int));
2428 static void gen_inlined_subprogram_die PROTO((tree, dw_die_ref, int));
2429 static void gen_field_die PROTO((tree, dw_die_ref));
2430 static void gen_ptr_to_mbr_type_die PROTO((tree, dw_die_ref));
2431 static void gen_compile_unit_die PROTO((char *));
2432 static void gen_string_type_die PROTO((tree, dw_die_ref));
2433 static void gen_inheritance_die PROTO((tree, dw_die_ref));
2434 static void gen_member_die PROTO((tree, dw_die_ref));
2435 static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref));
2436 static void gen_subroutine_type_die PROTO((tree, dw_die_ref));
2437 static void gen_typedef_die PROTO((tree, dw_die_ref));
2438 static void gen_type_die PROTO((tree, dw_die_ref));
2439 static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref));
2440 static void gen_block_die PROTO((tree, dw_die_ref, int));
2441 static void decls_for_scope PROTO((tree, dw_die_ref, int));
2442 static int is_redundant_typedef PROTO((tree));
2443 static void gen_decl_die PROTO((tree, dw_die_ref));
2444 static unsigned lookup_filename PROTO((char *));
2446 /* Section names used to hold DWARF debugging information. */
2447 #ifndef DEBUG_INFO_SECTION
2448 #define DEBUG_INFO_SECTION ".debug_info"
2450 #ifndef ABBREV_SECTION
2451 #define ABBREV_SECTION ".debug_abbrev"
2453 #ifndef ARANGES_SECTION
2454 #define ARANGES_SECTION ".debug_aranges"
2456 #ifndef DW_MACINFO_SECTION
2457 #define DW_MACINFO_SECTION ".debug_macinfo"
2459 #ifndef DEBUG_LINE_SECTION
2460 #define DEBUG_LINE_SECTION ".debug_line"
2463 #define LOC_SECTION ".debug_loc"
2465 #ifndef PUBNAMES_SECTION
2466 #define PUBNAMES_SECTION ".debug_pubnames"
2469 #define STR_SECTION ".debug_str"
2472 /* Standerd ELF section names for compiled code and data. */
2473 #ifndef TEXT_SECTION
2474 #define TEXT_SECTION ".text"
2476 #ifndef DATA_SECTION
2477 #define DATA_SECTION ".data"
2480 #define BSS_SECTION ".bss"
2484 /* Definitions of defaults for formats and names of various special
2485 (artificial) labels which may be generated within this file (when the -g
2486 options is used and DWARF_DEBUGGING_INFO is in effect.
2487 If necessary, these may be overridden from within the tm.h file, but
2488 typically, overriding these defaults is unnecessary. */
2490 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2492 #ifndef TEXT_END_LABEL
2493 #define TEXT_END_LABEL "Letext"
2495 #ifndef DATA_END_LABEL
2496 #define DATA_END_LABEL "Ledata"
2498 #ifndef BSS_END_LABEL
2499 #define BSS_END_LABEL "Lebss"
2501 #ifndef INSN_LABEL_FMT
2502 #define INSN_LABEL_FMT "LI%u_"
2504 #ifndef BLOCK_BEGIN_LABEL
2505 #define BLOCK_BEGIN_LABEL "LBB"
2507 #ifndef BLOCK_END_LABEL
2508 #define BLOCK_END_LABEL "LBE"
2510 #ifndef BODY_BEGIN_LABEL
2511 #define BODY_BEGIN_LABEL "Lbb"
2513 #ifndef BODY_END_LABEL
2514 #define BODY_END_LABEL "Lbe"
2516 #ifndef LINE_CODE_LABEL
2517 #define LINE_CODE_LABEL "LM"
2519 #ifndef SEPARATE_LINE_CODE_LABEL
2520 #define SEPARATE_LINE_CODE_LABEL "LSM"
2523 /* Convert a reference to the assembler name of a C-level name. This
2524 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
2525 a string rather than writing to a file. */
2526 #ifndef ASM_NAME_TO_STRING
2527 #define ASM_NAME_TO_STRING(STR, NAME) \
2529 if ((NAME)[0] == '*') \
2530 strcpy (STR, NAME+1); \
2532 strcpy (STR, NAME); \
2537 /* Convert an integer constant expression into assembler syntax. Addition
2538 and subtraction are the only arithmetic that may appear in these
2539 expressions. This is an adaptation of output_addr_const in final.c.
2540 Here, the target of the conversion is a string buffer. We can't use
2541 output_addr_const directly, because it writes to a file. */
2544 addr_const_to_string (str, x)
2553 switch (GET_CODE (x))
2563 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
2568 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2569 ASM_NAME_TO_STRING (buf2, buf1);
2574 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
2575 ASM_NAME_TO_STRING (buf2, buf1);
2580 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
2585 /* This used to output parentheses around the expression, but that does
2586 not work on the 386 (either ATT or BSD assembler). */
2587 addr_const_to_string (buf1, XEXP (x, 0));
2592 if (GET_MODE (x) == VOIDmode)
2594 /* We can use %d if the number is one word and positive. */
2595 if (CONST_DOUBLE_HIGH (x))
2596 sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
2597 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2598 else if (CONST_DOUBLE_LOW (x) < 0)
2599 sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
2601 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
2602 CONST_DOUBLE_LOW (x));
2606 /* We can't handle floating point constants; PRINT_OPERAND must
2608 output_operand_lossage ("floating constant misused");
2612 /* Some assemblers need integer constants to appear last (eg masm). */
2613 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2615 addr_const_to_string (buf1, XEXP (x, 1));
2617 if (INTVAL (XEXP (x, 0)) >= 0)
2620 addr_const_to_string (buf1, XEXP (x, 0));
2625 addr_const_to_string (buf1, XEXP (x, 0));
2627 if (INTVAL (XEXP (x, 1)) >= 0)
2630 addr_const_to_string (buf1, XEXP (x, 1));
2636 /* Avoid outputting things like x-x or x+5-x, since some assemblers
2637 can't handle that. */
2638 x = simplify_subtraction (x);
2639 if (GET_CODE (x) != MINUS)
2642 addr_const_to_string (buf1, XEXP (x, 0));
2645 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2646 && INTVAL (XEXP (x, 1)) < 0)
2648 strcat (str, ASM_OPEN_PAREN);
2649 addr_const_to_string (buf1, XEXP (x, 1));
2651 strcat (str, ASM_CLOSE_PAREN);
2655 addr_const_to_string (buf1, XEXP (x, 1));
2662 addr_const_to_string (buf1, XEXP (x, 0));
2667 output_operand_lossage ("invalid expression as operand");
2671 /* Convert an address constant to a string, and return a pointer to
2672 a copy of the result, located on the heap. */
2679 addr_const_to_string (buf, x);
2680 return xstrdup (buf);
2683 /* Test if rtl node points to a psuedo register. */
2689 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
2690 || ((GET_CODE (rtl) == SUBREG)
2691 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
2694 /* Return a reference to a type, with its const and volatile qualifiers
2698 type_main_variant (type)
2701 type = TYPE_MAIN_VARIANT (type);
2703 /* There really should be only one main variant among any group of variants
2704 of a given type (and all of the MAIN_VARIANT values for all members of
2705 the group should point to that one type) but sometimes the C front-end
2706 messes this up for array types, so we work around that bug here. */
2708 if (TREE_CODE (type) == ARRAY_TYPE)
2709 while (type != TYPE_MAIN_VARIANT (type))
2710 type = TYPE_MAIN_VARIANT (type);
2715 /* Return non-zero if the given type node represents a tagged type. */
2718 is_tagged_type (type)
2721 register enum tree_code code = TREE_CODE (type);
2723 return (code == RECORD_TYPE || code == UNION_TYPE
2724 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
2727 /* Convert a DIE tag into its string name. */
2730 dwarf_tag_name (tag)
2731 register unsigned tag;
2735 case DW_TAG_padding:
2736 return "DW_TAG_padding";
2737 case DW_TAG_array_type:
2738 return "DW_TAG_array_type";
2739 case DW_TAG_class_type:
2740 return "DW_TAG_class_type";
2741 case DW_TAG_entry_point:
2742 return "DW_TAG_entry_point";
2743 case DW_TAG_enumeration_type:
2744 return "DW_TAG_enumeration_type";
2745 case DW_TAG_formal_parameter:
2746 return "DW_TAG_formal_parameter";
2747 case DW_TAG_imported_declaration:
2748 return "DW_TAG_imported_declaration";
2750 return "DW_TAG_label";
2751 case DW_TAG_lexical_block:
2752 return "DW_TAG_lexical_block";
2754 return "DW_TAG_member";
2755 case DW_TAG_pointer_type:
2756 return "DW_TAG_pointer_type";
2757 case DW_TAG_reference_type:
2758 return "DW_TAG_reference_type";
2759 case DW_TAG_compile_unit:
2760 return "DW_TAG_compile_unit";
2761 case DW_TAG_string_type:
2762 return "DW_TAG_string_type";
2763 case DW_TAG_structure_type:
2764 return "DW_TAG_structure_type";
2765 case DW_TAG_subroutine_type:
2766 return "DW_TAG_subroutine_type";
2767 case DW_TAG_typedef:
2768 return "DW_TAG_typedef";
2769 case DW_TAG_union_type:
2770 return "DW_TAG_union_type";
2771 case DW_TAG_unspecified_parameters:
2772 return "DW_TAG_unspecified_parameters";
2773 case DW_TAG_variant:
2774 return "DW_TAG_variant";
2775 case DW_TAG_common_block:
2776 return "DW_TAG_common_block";
2777 case DW_TAG_common_inclusion:
2778 return "DW_TAG_common_inclusion";
2779 case DW_TAG_inheritance:
2780 return "DW_TAG_inheritance";
2781 case DW_TAG_inlined_subroutine:
2782 return "DW_TAG_inlined_subroutine";
2784 return "DW_TAG_module";
2785 case DW_TAG_ptr_to_member_type:
2786 return "DW_TAG_ptr_to_member_type";
2787 case DW_TAG_set_type:
2788 return "DW_TAG_set_type";
2789 case DW_TAG_subrange_type:
2790 return "DW_TAG_subrange_type";
2791 case DW_TAG_with_stmt:
2792 return "DW_TAG_with_stmt";
2793 case DW_TAG_access_declaration:
2794 return "DW_TAG_access_declaration";
2795 case DW_TAG_base_type:
2796 return "DW_TAG_base_type";
2797 case DW_TAG_catch_block:
2798 return "DW_TAG_catch_block";
2799 case DW_TAG_const_type:
2800 return "DW_TAG_const_type";
2801 case DW_TAG_constant:
2802 return "DW_TAG_constant";
2803 case DW_TAG_enumerator:
2804 return "DW_TAG_enumerator";
2805 case DW_TAG_file_type:
2806 return "DW_TAG_file_type";
2808 return "DW_TAG_friend";
2809 case DW_TAG_namelist:
2810 return "DW_TAG_namelist";
2811 case DW_TAG_namelist_item:
2812 return "DW_TAG_namelist_item";
2813 case DW_TAG_packed_type:
2814 return "DW_TAG_packed_type";
2815 case DW_TAG_subprogram:
2816 return "DW_TAG_subprogram";
2817 case DW_TAG_template_type_param:
2818 return "DW_TAG_template_type_param";
2819 case DW_TAG_template_value_param:
2820 return "DW_TAG_template_value_param";
2821 case DW_TAG_thrown_type:
2822 return "DW_TAG_thrown_type";
2823 case DW_TAG_try_block:
2824 return "DW_TAG_try_block";
2825 case DW_TAG_variant_part:
2826 return "DW_TAG_variant_part";
2827 case DW_TAG_variable:
2828 return "DW_TAG_variable";
2829 case DW_TAG_volatile_type:
2830 return "DW_TAG_volatile_type";
2831 case DW_TAG_MIPS_loop:
2832 return "DW_TAG_MIPS_loop";
2833 case DW_TAG_format_label:
2834 return "DW_TAG_format_label";
2835 case DW_TAG_function_template:
2836 return "DW_TAG_function_template";
2837 case DW_TAG_class_template:
2838 return "DW_TAG_class_template";
2840 return "DW_TAG_<unknown>";
2844 /* Convert a DWARF attribute code into its string name. */
2847 dwarf_attr_name (attr)
2848 register unsigned attr;
2853 return "DW_AT_sibling";
2854 case DW_AT_location:
2855 return "DW_AT_location";
2857 return "DW_AT_name";
2858 case DW_AT_ordering:
2859 return "DW_AT_ordering";
2860 case DW_AT_subscr_data:
2861 return "DW_AT_subscr_data";
2862 case DW_AT_byte_size:
2863 return "DW_AT_byte_size";
2864 case DW_AT_bit_offset:
2865 return "DW_AT_bit_offset";
2866 case DW_AT_bit_size:
2867 return "DW_AT_bit_size";
2868 case DW_AT_element_list:
2869 return "DW_AT_element_list";
2870 case DW_AT_stmt_list:
2871 return "DW_AT_stmt_list";
2873 return "DW_AT_low_pc";
2875 return "DW_AT_high_pc";
2876 case DW_AT_language:
2877 return "DW_AT_language";
2879 return "DW_AT_member";
2881 return "DW_AT_discr";
2882 case DW_AT_discr_value:
2883 return "DW_AT_discr_value";
2884 case DW_AT_visibility:
2885 return "DW_AT_visibility";
2887 return "DW_AT_import";
2888 case DW_AT_string_length:
2889 return "DW_AT_string_length";
2890 case DW_AT_common_reference:
2891 return "DW_AT_common_reference";
2892 case DW_AT_comp_dir:
2893 return "DW_AT_comp_dir";
2894 case DW_AT_const_value:
2895 return "DW_AT_const_value";
2896 case DW_AT_containing_type:
2897 return "DW_AT_containing_type";
2898 case DW_AT_default_value:
2899 return "DW_AT_default_value";
2901 return "DW_AT_inline";
2902 case DW_AT_is_optional:
2903 return "DW_AT_is_optional";
2904 case DW_AT_lower_bound:
2905 return "DW_AT_lower_bound";
2906 case DW_AT_producer:
2907 return "DW_AT_producer";
2908 case DW_AT_prototyped:
2909 return "DW_AT_prototyped";
2910 case DW_AT_return_addr:
2911 return "DW_AT_return_addr";
2912 case DW_AT_start_scope:
2913 return "DW_AT_start_scope";
2914 case DW_AT_stride_size:
2915 return "DW_AT_stride_size";
2916 case DW_AT_upper_bound:
2917 return "DW_AT_upper_bound";
2918 case DW_AT_abstract_origin:
2919 return "DW_AT_abstract_origin";
2920 case DW_AT_accessibility:
2921 return "DW_AT_accessibility";
2922 case DW_AT_address_class:
2923 return "DW_AT_address_class";
2924 case DW_AT_artificial:
2925 return "DW_AT_artificial";
2926 case DW_AT_base_types:
2927 return "DW_AT_base_types";
2928 case DW_AT_calling_convention:
2929 return "DW_AT_calling_convention";
2931 return "DW_AT_count";
2932 case DW_AT_data_member_location:
2933 return "DW_AT_data_member_location";
2934 case DW_AT_decl_column:
2935 return "DW_AT_decl_column";
2936 case DW_AT_decl_file:
2937 return "DW_AT_decl_file";
2938 case DW_AT_decl_line:
2939 return "DW_AT_decl_line";
2940 case DW_AT_declaration:
2941 return "DW_AT_declaration";
2942 case DW_AT_discr_list:
2943 return "DW_AT_discr_list";
2944 case DW_AT_encoding:
2945 return "DW_AT_encoding";
2946 case DW_AT_external:
2947 return "DW_AT_external";
2948 case DW_AT_frame_base:
2949 return "DW_AT_frame_base";
2951 return "DW_AT_friend";
2952 case DW_AT_identifier_case:
2953 return "DW_AT_identifier_case";
2954 case DW_AT_macro_info:
2955 return "DW_AT_macro_info";
2956 case DW_AT_namelist_items:
2957 return "DW_AT_namelist_items";
2958 case DW_AT_priority:
2959 return "DW_AT_priority";
2961 return "DW_AT_segment";
2962 case DW_AT_specification:
2963 return "DW_AT_specification";
2964 case DW_AT_static_link:
2965 return "DW_AT_static_link";
2967 return "DW_AT_type";
2968 case DW_AT_use_location:
2969 return "DW_AT_use_location";
2970 case DW_AT_variable_parameter:
2971 return "DW_AT_variable_parameter";
2972 case DW_AT_virtuality:
2973 return "DW_AT_virtuality";
2974 case DW_AT_vtable_elem_location:
2975 return "DW_AT_vtable_elem_location";
2977 case DW_AT_MIPS_fde:
2978 return "DW_AT_MIPS_fde";
2979 case DW_AT_MIPS_loop_begin:
2980 return "DW_AT_MIPS_loop_begin";
2981 case DW_AT_MIPS_tail_loop_begin:
2982 return "DW_AT_MIPS_tail_loop_begin";
2983 case DW_AT_MIPS_epilog_begin:
2984 return "DW_AT_MIPS_epilog_begin";
2985 case DW_AT_MIPS_loop_unroll_factor:
2986 return "DW_AT_MIPS_loop_unroll_factor";
2987 case DW_AT_MIPS_software_pipeline_depth:
2988 return "DW_AT_MIPS_software_pipeline_depth";
2989 case DW_AT_MIPS_linkage_name:
2990 return "DW_AT_MIPS_linkage_name";
2991 case DW_AT_MIPS_stride:
2992 return "DW_AT_MIPS_stride";
2993 case DW_AT_MIPS_abstract_name:
2994 return "DW_AT_MIPS_abstract_name";
2995 case DW_AT_MIPS_clone_origin:
2996 return "DW_AT_MIPS_clone_origin";
2997 case DW_AT_MIPS_has_inlines:
2998 return "DW_AT_MIPS_has_inlines";
3000 case DW_AT_sf_names:
3001 return "DW_AT_sf_names";
3002 case DW_AT_src_info:
3003 return "DW_AT_src_info";
3004 case DW_AT_mac_info:
3005 return "DW_AT_mac_info";
3006 case DW_AT_src_coords:
3007 return "DW_AT_src_coords";
3008 case DW_AT_body_begin:
3009 return "DW_AT_body_begin";
3010 case DW_AT_body_end:
3011 return "DW_AT_body_end";
3013 return "DW_AT_<unknown>";
3017 /* Convert a DWARF value form code into its string name. */
3020 dwarf_form_name (form)
3021 register unsigned form;
3026 return "DW_FORM_addr";
3027 case DW_FORM_block2:
3028 return "DW_FORM_block2";
3029 case DW_FORM_block4:
3030 return "DW_FORM_block4";
3032 return "DW_FORM_data2";
3034 return "DW_FORM_data4";
3036 return "DW_FORM_data8";
3037 case DW_FORM_string:
3038 return "DW_FORM_string";
3040 return "DW_FORM_block";
3041 case DW_FORM_block1:
3042 return "DW_FORM_block1";
3044 return "DW_FORM_data1";
3046 return "DW_FORM_flag";
3048 return "DW_FORM_sdata";
3050 return "DW_FORM_strp";
3052 return "DW_FORM_udata";
3053 case DW_FORM_ref_addr:
3054 return "DW_FORM_ref_addr";
3056 return "DW_FORM_ref1";
3058 return "DW_FORM_ref2";
3060 return "DW_FORM_ref4";
3062 return "DW_FORM_ref8";
3063 case DW_FORM_ref_udata:
3064 return "DW_FORM_ref_udata";
3065 case DW_FORM_indirect:
3066 return "DW_FORM_indirect";
3068 return "DW_FORM_<unknown>";
3072 /* Convert a DWARF stack opcode into its string name. */
3075 dwarf_stack_op_name (op)
3076 register unsigned op;
3081 return "DW_OP_addr";
3083 return "DW_OP_deref";
3085 return "DW_OP_const1u";
3087 return "DW_OP_const1s";
3089 return "DW_OP_const2u";
3091 return "DW_OP_const2s";
3093 return "DW_OP_const4u";
3095 return "DW_OP_const4s";
3097 return "DW_OP_const8u";
3099 return "DW_OP_const8s";
3101 return "DW_OP_constu";
3103 return "DW_OP_consts";
3107 return "DW_OP_drop";
3109 return "DW_OP_over";
3111 return "DW_OP_pick";
3113 return "DW_OP_swap";
3117 return "DW_OP_xderef";
3125 return "DW_OP_minus";
3137 return "DW_OP_plus";
3138 case DW_OP_plus_uconst:
3139 return "DW_OP_plus_uconst";
3145 return "DW_OP_shra";
3163 return "DW_OP_skip";
3165 return "DW_OP_lit0";
3167 return "DW_OP_lit1";
3169 return "DW_OP_lit2";
3171 return "DW_OP_lit3";
3173 return "DW_OP_lit4";
3175 return "DW_OP_lit5";
3177 return "DW_OP_lit6";
3179 return "DW_OP_lit7";
3181 return "DW_OP_lit8";
3183 return "DW_OP_lit9";
3185 return "DW_OP_lit10";
3187 return "DW_OP_lit11";
3189 return "DW_OP_lit12";
3191 return "DW_OP_lit13";
3193 return "DW_OP_lit14";
3195 return "DW_OP_lit15";
3197 return "DW_OP_lit16";
3199 return "DW_OP_lit17";
3201 return "DW_OP_lit18";
3203 return "DW_OP_lit19";
3205 return "DW_OP_lit20";
3207 return "DW_OP_lit21";
3209 return "DW_OP_lit22";
3211 return "DW_OP_lit23";
3213 return "DW_OP_lit24";
3215 return "DW_OP_lit25";
3217 return "DW_OP_lit26";
3219 return "DW_OP_lit27";
3221 return "DW_OP_lit28";
3223 return "DW_OP_lit29";
3225 return "DW_OP_lit30";
3227 return "DW_OP_lit31";
3229 return "DW_OP_reg0";
3231 return "DW_OP_reg1";
3233 return "DW_OP_reg2";
3235 return "DW_OP_reg3";
3237 return "DW_OP_reg4";
3239 return "DW_OP_reg5";
3241 return "DW_OP_reg6";
3243 return "DW_OP_reg7";
3245 return "DW_OP_reg8";
3247 return "DW_OP_reg9";
3249 return "DW_OP_reg10";
3251 return "DW_OP_reg11";
3253 return "DW_OP_reg12";
3255 return "DW_OP_reg13";
3257 return "DW_OP_reg14";
3259 return "DW_OP_reg15";
3261 return "DW_OP_reg16";
3263 return "DW_OP_reg17";
3265 return "DW_OP_reg18";
3267 return "DW_OP_reg19";
3269 return "DW_OP_reg20";
3271 return "DW_OP_reg21";
3273 return "DW_OP_reg22";
3275 return "DW_OP_reg23";
3277 return "DW_OP_reg24";
3279 return "DW_OP_reg25";
3281 return "DW_OP_reg26";
3283 return "DW_OP_reg27";
3285 return "DW_OP_reg28";
3287 return "DW_OP_reg29";
3289 return "DW_OP_reg30";
3291 return "DW_OP_reg31";
3293 return "DW_OP_breg0";
3295 return "DW_OP_breg1";
3297 return "DW_OP_breg2";
3299 return "DW_OP_breg3";
3301 return "DW_OP_breg4";
3303 return "DW_OP_breg5";
3305 return "DW_OP_breg6";
3307 return "DW_OP_breg7";
3309 return "DW_OP_breg8";
3311 return "DW_OP_breg9";
3313 return "DW_OP_breg10";
3315 return "DW_OP_breg11";
3317 return "DW_OP_breg12";
3319 return "DW_OP_breg13";
3321 return "DW_OP_breg14";
3323 return "DW_OP_breg15";
3325 return "DW_OP_breg16";
3327 return "DW_OP_breg17";
3329 return "DW_OP_breg18";
3331 return "DW_OP_breg19";
3333 return "DW_OP_breg20";
3335 return "DW_OP_breg21";
3337 return "DW_OP_breg22";
3339 return "DW_OP_breg23";
3341 return "DW_OP_breg24";
3343 return "DW_OP_breg25";
3345 return "DW_OP_breg26";
3347 return "DW_OP_breg27";
3349 return "DW_OP_breg28";
3351 return "DW_OP_breg29";
3353 return "DW_OP_breg30";
3355 return "DW_OP_breg31";
3357 return "DW_OP_regx";
3359 return "DW_OP_fbreg";
3361 return "DW_OP_bregx";
3363 return "DW_OP_piece";
3364 case DW_OP_deref_size:
3365 return "DW_OP_deref_size";
3366 case DW_OP_xderef_size:
3367 return "DW_OP_xderef_size";
3371 return "OP_<unknown>";
3375 /* Convert a DWARF type code into its string name. */
3378 dwarf_type_encoding_name (enc)
3379 register unsigned enc;
3383 case DW_ATE_address:
3384 return "DW_ATE_address";
3385 case DW_ATE_boolean:
3386 return "DW_ATE_boolean";
3387 case DW_ATE_complex_float:
3388 return "DW_ATE_complex_float";
3390 return "DW_ATE_float";
3392 return "DW_ATE_signed";
3393 case DW_ATE_signed_char:
3394 return "DW_ATE_signed_char";
3395 case DW_ATE_unsigned:
3396 return "DW_ATE_unsigned";
3397 case DW_ATE_unsigned_char:
3398 return "DW_ATE_unsigned_char";
3400 return "DW_ATE_<unknown>";
3404 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3405 instance of an inlined instance of a decl which is local to an inline
3406 function, so we have to trace all of the way back through the origin chain
3407 to find out what sort of node actually served as the original seed for the
3411 decl_ultimate_origin (decl)
3414 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
3416 if (immediate_origin == NULL_TREE)
3420 register tree ret_val;
3421 register tree lookahead = immediate_origin;
3425 ret_val = lookahead;
3426 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
3428 while (lookahead != NULL && lookahead != ret_val);
3434 /* Determine the "ultimate origin" of a block. The block may be an inlined
3435 instance of an inlined instance of a block which is local to an inline
3436 function, so we have to trace all of the way back through the origin chain
3437 to find out what sort of node actually served as the original seed for the
3441 block_ultimate_origin (block)
3442 register tree block;
3444 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3446 if (immediate_origin == NULL_TREE)
3450 register tree ret_val;
3451 register tree lookahead = immediate_origin;
3455 ret_val = lookahead;
3456 lookahead = (TREE_CODE (ret_val) == BLOCK)
3457 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3460 while (lookahead != NULL && lookahead != ret_val);
3466 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3467 of a virtual function may refer to a base class, so we check the 'this'
3471 decl_class_context (decl)
3474 tree context = NULL_TREE;
3476 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3477 context = DECL_CONTEXT (decl);
3479 context = TYPE_MAIN_VARIANT
3480 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3482 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
3483 context = NULL_TREE;
3488 /* Add an attribute/value pair to a DIE */
3491 add_dwarf_attr (die, attr)
3492 register dw_die_ref die;
3493 register dw_attr_ref attr;
3495 if (die != NULL && attr != NULL)
3497 if (die->die_attr == NULL)
3499 die->die_attr = attr;
3500 die->die_attr_last = attr;
3504 die->die_attr_last->dw_attr_next = attr;
3505 die->die_attr_last = attr;
3510 /* Add a flag value attribute to a DIE. */
3513 add_AT_flag (die, attr_kind, flag)
3514 register dw_die_ref die;
3515 register enum dwarf_attribute attr_kind;
3516 register unsigned flag;
3518 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3520 attr->dw_attr_next = NULL;
3521 attr->dw_attr = attr_kind;
3522 attr->dw_attr_val.val_class = dw_val_class_flag;
3523 attr->dw_attr_val.v.val_flag = flag;
3524 add_dwarf_attr (die, attr);
3527 /* Add a signed integer attribute value to a DIE. */
3530 add_AT_int (die, attr_kind, int_val)
3531 register dw_die_ref die;
3532 register enum dwarf_attribute attr_kind;
3533 register long int int_val;
3535 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3537 attr->dw_attr_next = NULL;
3538 attr->dw_attr = attr_kind;
3539 attr->dw_attr_val.val_class = dw_val_class_const;
3540 attr->dw_attr_val.v.val_int = int_val;
3541 add_dwarf_attr (die, attr);
3544 /* Add an unsigned integer attribute value to a DIE. */
3547 add_AT_unsigned (die, attr_kind, unsigned_val)
3548 register dw_die_ref die;
3549 register enum dwarf_attribute attr_kind;
3550 register unsigned long unsigned_val;
3552 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3554 attr->dw_attr_next = NULL;
3555 attr->dw_attr = attr_kind;
3556 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
3557 attr->dw_attr_val.v.val_unsigned = unsigned_val;
3558 add_dwarf_attr (die, attr);
3561 /* Add an unsigned double integer attribute value to a DIE. */
3564 add_AT_long_long (die, attr_kind, val_hi, val_low)
3565 register dw_die_ref die;
3566 register enum dwarf_attribute attr_kind;
3567 register unsigned long val_hi;
3568 register unsigned long val_low;
3570 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3572 attr->dw_attr_next = NULL;
3573 attr->dw_attr = attr_kind;
3574 attr->dw_attr_val.val_class = dw_val_class_long_long;
3575 attr->dw_attr_val.v.val_long_long.hi = val_hi;
3576 attr->dw_attr_val.v.val_long_long.low = val_low;
3577 add_dwarf_attr (die, attr);
3580 /* Add a floating point attribute value to a DIE and return it. */
3583 add_AT_float (die, attr_kind, length, array)
3584 register dw_die_ref die;
3585 register enum dwarf_attribute attr_kind;
3586 register unsigned length;
3587 register long *array;
3589 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3591 attr->dw_attr_next = NULL;
3592 attr->dw_attr = attr_kind;
3593 attr->dw_attr_val.val_class = dw_val_class_float;
3594 attr->dw_attr_val.v.val_float.length = length;
3595 attr->dw_attr_val.v.val_float.array = array;
3596 add_dwarf_attr (die, attr);
3599 /* Add a string attribute value to a DIE. */
3602 add_AT_string (die, attr_kind, str)
3603 register dw_die_ref die;
3604 register enum dwarf_attribute attr_kind;
3607 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3609 attr->dw_attr_next = NULL;
3610 attr->dw_attr = attr_kind;
3611 attr->dw_attr_val.val_class = dw_val_class_str;
3612 attr->dw_attr_val.v.val_str = xstrdup (str);
3613 add_dwarf_attr (die, attr);
3616 /* Add a DIE reference attribute value to a DIE. */
3619 add_AT_die_ref (die, attr_kind, targ_die)
3620 register dw_die_ref die;
3621 register enum dwarf_attribute attr_kind;
3622 register dw_die_ref targ_die;
3624 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3626 attr->dw_attr_next = NULL;
3627 attr->dw_attr = attr_kind;
3628 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3629 attr->dw_attr_val.v.val_die_ref = targ_die;
3630 add_dwarf_attr (die, attr);
3633 /* Add an FDE reference attribute value to a DIE. */
3636 add_AT_fde_ref (die, attr_kind, targ_fde)
3637 register dw_die_ref die;
3638 register enum dwarf_attribute attr_kind;
3639 register unsigned targ_fde;
3641 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3643 attr->dw_attr_next = NULL;
3644 attr->dw_attr = attr_kind;
3645 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
3646 attr->dw_attr_val.v.val_fde_index = targ_fde;
3647 add_dwarf_attr (die, attr);
3650 /* Add a location description attribute value to a DIE. */
3653 add_AT_loc (die, attr_kind, loc)
3654 register dw_die_ref die;
3655 register enum dwarf_attribute attr_kind;
3656 register dw_loc_descr_ref loc;
3658 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3660 attr->dw_attr_next = NULL;
3661 attr->dw_attr = attr_kind;
3662 attr->dw_attr_val.val_class = dw_val_class_loc;
3663 attr->dw_attr_val.v.val_loc = loc;
3664 add_dwarf_attr (die, attr);
3667 /* Add an address constant attribute value to a DIE. */
3670 add_AT_addr (die, attr_kind, addr)
3671 register dw_die_ref die;
3672 register enum dwarf_attribute attr_kind;
3675 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3677 attr->dw_attr_next = NULL;
3678 attr->dw_attr = attr_kind;
3679 attr->dw_attr_val.val_class = dw_val_class_addr;
3680 attr->dw_attr_val.v.val_addr = addr;
3681 add_dwarf_attr (die, attr);
3684 /* Add a label identifier attribute value to a DIE. */
3687 add_AT_lbl_id (die, attr_kind, lbl_id)
3688 register dw_die_ref die;
3689 register enum dwarf_attribute attr_kind;
3690 register char *lbl_id;
3692 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3694 attr->dw_attr_next = NULL;
3695 attr->dw_attr = attr_kind;
3696 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
3697 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
3698 add_dwarf_attr (die, attr);
3701 /* Add a section offset attribute value to a DIE. */
3704 add_AT_section_offset (die, attr_kind, section)
3705 register dw_die_ref die;
3706 register enum dwarf_attribute attr_kind;
3707 register char *section;
3709 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3711 attr->dw_attr_next = NULL;
3712 attr->dw_attr = attr_kind;
3713 attr->dw_attr_val.val_class = dw_val_class_section_offset;
3714 attr->dw_attr_val.v.val_section = section;
3715 add_dwarf_attr (die, attr);
3719 /* Test if die refers to an external subroutine. */
3722 is_extern_subr_die (die)
3723 register dw_die_ref die;
3725 register dw_attr_ref a;
3726 register int is_subr = FALSE;
3727 register int is_extern = FALSE;
3729 if (die != NULL && die->die_tag == DW_TAG_subprogram)
3732 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3734 if (a->dw_attr == DW_AT_external
3735 && a->dw_attr_val.val_class == dw_val_class_flag
3736 && a->dw_attr_val.v.val_flag != 0)
3744 return is_subr && is_extern;
3747 /* Get the attribute of type attr_kind. */
3749 static inline dw_attr_ref
3750 get_AT (die, attr_kind)
3751 register dw_die_ref die;
3752 register enum dwarf_attribute attr_kind;
3754 register dw_attr_ref a;
3755 register dw_die_ref spec = NULL;
3759 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3761 if (a->dw_attr == attr_kind)
3764 if (a->dw_attr == DW_AT_specification
3765 || a->dw_attr == DW_AT_abstract_origin)
3766 spec = a->dw_attr_val.v.val_die_ref;
3770 return get_AT (spec, attr_kind);
3776 /* Return the "low pc" attribute value, typically associated with
3777 a subprogram DIE. Return null if the "low pc" attribute is
3778 either not prsent, or if it cannot be represented as an
3779 assembler label identifier. */
3781 static inline char *
3783 register dw_die_ref die;
3785 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
3787 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3788 return a->dw_attr_val.v.val_lbl_id;
3793 /* Return the "high pc" attribute value, typically associated with
3794 a subprogram DIE. Return null if the "high pc" attribute is
3795 either not prsent, or if it cannot be represented as an
3796 assembler label identifier. */
3798 static inline char *
3800 register dw_die_ref die;
3802 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
3804 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3805 return a->dw_attr_val.v.val_lbl_id;
3810 /* Return the value of the string attribute designated by ATTR_KIND, or
3811 NULL if it is not present. */
3813 static inline char *
3814 get_AT_string (die, attr_kind)
3815 register dw_die_ref die;
3816 register enum dwarf_attribute attr_kind;
3818 register dw_attr_ref a = get_AT (die, attr_kind);
3820 if (a && a->dw_attr_val.val_class == dw_val_class_str)
3821 return a->dw_attr_val.v.val_str;
3826 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3827 if it is not present. */
3830 get_AT_flag (die, attr_kind)
3831 register dw_die_ref die;
3832 register enum dwarf_attribute attr_kind;
3834 register dw_attr_ref a = get_AT (die, attr_kind);
3836 if (a && a->dw_attr_val.val_class == dw_val_class_flag)
3837 return a->dw_attr_val.v.val_flag;
3842 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3843 if it is not present. */
3845 static inline unsigned
3846 get_AT_unsigned (die, attr_kind)
3847 register dw_die_ref die;
3848 register enum dwarf_attribute attr_kind;
3850 register dw_attr_ref a = get_AT (die, attr_kind);
3852 if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
3853 return a->dw_attr_val.v.val_unsigned;
3861 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3863 return (lang == DW_LANG_C || lang == DW_LANG_C89
3864 || lang == DW_LANG_C_plus_plus);
3870 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3872 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
3875 /* Remove the specified attribute if present. */
3878 remove_AT (die, attr_kind)
3879 register dw_die_ref die;
3880 register enum dwarf_attribute attr_kind;
3882 register dw_attr_ref a;
3883 register dw_attr_ref removed = NULL;;
3887 if (die->die_attr->dw_attr == attr_kind)
3889 removed = die->die_attr;
3890 if (die->die_attr_last == die->die_attr)
3891 die->die_attr_last = NULL;
3893 die->die_attr = die->die_attr->dw_attr_next;
3897 for (a = die->die_attr; a->dw_attr_next != NULL;
3898 a = a->dw_attr_next)
3899 if (a->dw_attr_next->dw_attr == attr_kind)
3901 removed = a->dw_attr_next;
3902 if (die->die_attr_last == a->dw_attr_next)
3903 die->die_attr_last = a;
3905 a->dw_attr_next = a->dw_attr_next->dw_attr_next;
3914 /* Discard the children of this DIE. */
3917 remove_children (die)
3918 register dw_die_ref die;
3920 register dw_die_ref child_die = die->die_child;
3922 die->die_child = NULL;
3923 die->die_child_last = NULL;
3925 while (child_die != NULL)
3927 register dw_die_ref tmp_die = child_die;
3928 register dw_attr_ref a;
3930 child_die = child_die->die_sib;
3932 for (a = tmp_die->die_attr; a != NULL; )
3934 register dw_attr_ref tmp_a = a;
3936 a = a->dw_attr_next;
3944 /* Add a child DIE below its parent. */
3947 add_child_die (die, child_die)
3948 register dw_die_ref die;
3949 register dw_die_ref child_die;
3951 if (die != NULL && child_die != NULL)
3953 if (die == child_die)
3955 child_die->die_parent = die;
3956 child_die->die_sib = NULL;
3958 if (die->die_child == NULL)
3960 die->die_child = child_die;
3961 die->die_child_last = child_die;
3965 die->die_child_last->die_sib = child_die;
3966 die->die_child_last = child_die;
3971 /* Return a pointer to a newly created DIE node. */
3973 static inline dw_die_ref
3974 new_die (tag_value, parent_die)
3975 register enum dwarf_tag tag_value;
3976 register dw_die_ref parent_die;
3978 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
3980 die->die_tag = tag_value;
3981 die->die_abbrev = 0;
3982 die->die_offset = 0;
3983 die->die_child = NULL;
3984 die->die_parent = NULL;
3985 die->die_sib = NULL;
3986 die->die_child_last = NULL;
3987 die->die_attr = NULL;
3988 die->die_attr_last = NULL;
3990 if (parent_die != NULL)
3991 add_child_die (parent_die, die);
3994 limbo_die_node *limbo_node;
3996 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
3997 limbo_node->die = die;
3998 limbo_node->next = limbo_die_list;
3999 limbo_die_list = limbo_node;
4005 /* Return the DIE associated with the given type specifier. */
4007 static inline dw_die_ref
4008 lookup_type_die (type)
4011 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4014 /* Equate a DIE to a given type specifier. */
4017 equate_type_number_to_die (type, type_die)
4019 register dw_die_ref type_die;
4021 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4024 /* Return the DIE associated with a given declaration. */
4026 static inline dw_die_ref
4027 lookup_decl_die (decl)
4030 register unsigned decl_id = DECL_UID (decl);
4032 return (decl_id < decl_die_table_in_use
4033 ? decl_die_table[decl_id] : NULL);
4036 /* Equate a DIE to a particular declaration. */
4039 equate_decl_number_to_die (decl, decl_die)
4041 register dw_die_ref decl_die;
4043 register unsigned decl_id = DECL_UID (decl);
4044 register unsigned i;
4045 register unsigned num_allocated;
4047 if (decl_id >= decl_die_table_allocated)
4050 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4051 / DECL_DIE_TABLE_INCREMENT)
4052 * DECL_DIE_TABLE_INCREMENT;
4055 = (dw_die_ref *) xrealloc (decl_die_table,
4056 sizeof (dw_die_ref) * num_allocated);
4058 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4059 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4060 decl_die_table_allocated = num_allocated;
4063 if (decl_id >= decl_die_table_in_use)
4064 decl_die_table_in_use = (decl_id + 1);
4066 decl_die_table[decl_id] = decl_die;
4069 /* Return a pointer to a newly allocated location description. Location
4070 descriptions are simple expression terms that can be strung
4071 together to form more complicated location (address) descriptions. */
4073 static inline dw_loc_descr_ref
4074 new_loc_descr (op, oprnd1, oprnd2)
4075 register enum dwarf_location_atom op;
4076 register unsigned long oprnd1;
4077 register unsigned long oprnd2;
4079 register dw_loc_descr_ref descr
4080 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
4082 descr->dw_loc_next = NULL;
4083 descr->dw_loc_opc = op;
4084 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4085 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4086 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4087 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4092 /* Add a location description term to a location description expression. */
4095 add_loc_descr (list_head, descr)
4096 register dw_loc_descr_ref *list_head;
4097 register dw_loc_descr_ref descr;
4099 register dw_loc_descr_ref *d;
4101 /* Find the end of the chain. */
4102 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4108 /* Keep track of the number of spaces used to indent the
4109 output of the debugging routines that print the structure of
4110 the DIE internal representation. */
4111 static int print_indent;
4113 /* Indent the line the number of spaces given by print_indent. */
4116 print_spaces (outfile)
4119 fprintf (outfile, "%*s", print_indent, "");
4122 /* Print the information assoaciated with a given DIE, and its children.
4123 This routine is a debugging aid only. */
4126 print_die (die, outfile)
4130 register dw_attr_ref a;
4131 register dw_die_ref c;
4133 print_spaces (outfile);
4134 fprintf (outfile, "DIE %4u: %s\n",
4135 die->die_offset, dwarf_tag_name (die->die_tag));
4136 print_spaces (outfile);
4137 fprintf (outfile, " abbrev id: %u", die->die_abbrev);
4138 fprintf (outfile, " offset: %u\n", die->die_offset);
4140 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4142 print_spaces (outfile);
4143 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4145 switch (a->dw_attr_val.val_class)
4147 case dw_val_class_addr:
4148 fprintf (outfile, "address");
4150 case dw_val_class_loc:
4151 fprintf (outfile, "location descriptor");
4153 case dw_val_class_const:
4154 fprintf (outfile, "%d", a->dw_attr_val.v.val_int);
4156 case dw_val_class_unsigned_const:
4157 fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned);
4159 case dw_val_class_long_long:
4160 fprintf (outfile, "constant (%u,%u)",
4161 a->dw_attr_val.v.val_long_long.hi,
4162 a->dw_attr_val.v.val_long_long.low);
4164 case dw_val_class_float:
4165 fprintf (outfile, "floating-point constant");
4167 case dw_val_class_flag:
4168 fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
4170 case dw_val_class_die_ref:
4171 if (a->dw_attr_val.v.val_die_ref != NULL)
4172 fprintf (outfile, "die -> %u",
4173 a->dw_attr_val.v.val_die_ref->die_offset);
4175 fprintf (outfile, "die -> <null>");
4177 case dw_val_class_lbl_id:
4178 fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
4180 case dw_val_class_section_offset:
4181 fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section);
4183 case dw_val_class_str:
4184 if (a->dw_attr_val.v.val_str != NULL)
4185 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
4187 fprintf (outfile, "<null>");
4193 fprintf (outfile, "\n");
4196 if (die->die_child != NULL)
4199 for (c = die->die_child; c != NULL; c = c->die_sib)
4200 print_die (c, outfile);
4206 /* Print the contents of the source code line number correspondence table.
4207 This routine is a debugging aid only. */
4210 print_dwarf_line_table (outfile)
4213 register unsigned i;
4214 register dw_line_info_ref line_info;
4216 fprintf (outfile, "\n\nDWARF source line information\n");
4217 for (i = 1; i < line_info_table_in_use; ++i)
4219 line_info = &line_info_table[i];
4220 fprintf (outfile, "%5d: ", i);
4221 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4222 fprintf (outfile, "%6d", line_info->dw_line_num);
4223 fprintf (outfile, "\n");
4226 fprintf (outfile, "\n\n");
4229 /* Print the information collected for a given DIE. */
4232 debug_dwarf_die (die)
4235 print_die (die, stderr);
4238 /* Print all DWARF information collected for the compilation unit.
4239 This routine is a debugging aid only. */
4245 print_die (comp_unit_die, stderr);
4246 print_dwarf_line_table (stderr);
4249 /* Traverse the DIE, and add a sibling attribute if it may have the
4250 effect of speeding up access to siblings. To save some space,
4251 avoid generating sibling attributes for DIE's without children. */
4254 add_sibling_attributes(die)
4255 register dw_die_ref die;
4257 register dw_die_ref c;
4258 register dw_attr_ref attr;
4259 if (die != comp_unit_die && die->die_child != NULL)
4261 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4262 attr->dw_attr_next = NULL;
4263 attr->dw_attr = DW_AT_sibling;
4264 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4265 attr->dw_attr_val.v.val_die_ref = die->die_sib;
4267 /* Add the sibling link to the front of the attribute list. */
4268 attr->dw_attr_next = die->die_attr;
4269 if (die->die_attr == NULL)
4270 die->die_attr_last = attr;
4272 die->die_attr = attr;
4275 for (c = die->die_child; c != NULL; c = c->die_sib)
4276 add_sibling_attributes (c);
4279 /* The format of each DIE (and its attribute value pairs)
4280 is encoded in an abbreviation table. This routine builds the
4281 abbreviation table and assigns a unique abbreviation id for
4282 each abbreviation entry. The children of each die are visited
4286 build_abbrev_table (die)
4287 register dw_die_ref die;
4289 register unsigned long abbrev_id;
4290 register unsigned long n_alloc;
4291 register dw_die_ref c;
4292 register dw_attr_ref d_attr, a_attr;
4293 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4295 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4297 if (abbrev->die_tag == die->die_tag)
4299 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
4301 a_attr = abbrev->die_attr;
4302 d_attr = die->die_attr;
4304 while (a_attr != NULL && d_attr != NULL)
4306 if ((a_attr->dw_attr != d_attr->dw_attr)
4307 || (value_format (&a_attr->dw_attr_val)
4308 != value_format (&d_attr->dw_attr_val)))
4311 a_attr = a_attr->dw_attr_next;
4312 d_attr = d_attr->dw_attr_next;
4315 if (a_attr == NULL && d_attr == NULL)
4321 if (abbrev_id >= abbrev_die_table_in_use)
4323 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
4325 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
4327 = (dw_die_ref *) xrealloc (abbrev_die_table,
4328 sizeof (dw_die_ref) * n_alloc);
4330 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
4331 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
4332 abbrev_die_table_allocated = n_alloc;
4335 ++abbrev_die_table_in_use;
4336 abbrev_die_table[abbrev_id] = die;
4339 die->die_abbrev = abbrev_id;
4340 for (c = die->die_child; c != NULL; c = c->die_sib)
4341 build_abbrev_table (c);
4344 /* Return the size of a string, including the null byte. */
4346 static unsigned long
4347 size_of_string (str)
4350 register unsigned long size = 0;
4351 register unsigned long slen = strlen (str);
4352 register unsigned long i;
4353 register unsigned c;
4355 for (i = 0; i < slen; ++i)
4364 /* Null terminator. */
4369 /* Return the size of a location descriptor. */
4371 static unsigned long
4372 size_of_loc_descr (loc)
4373 register dw_loc_descr_ref loc;
4375 register unsigned long size = 1;
4377 switch (loc->dw_loc_opc)
4399 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4402 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4407 case DW_OP_plus_uconst:
4408 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4446 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4449 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4452 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4455 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4456 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4459 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4461 case DW_OP_deref_size:
4462 case DW_OP_xderef_size:
4472 /* Return the size of a series of location descriptors. */
4474 static unsigned long
4476 register dw_loc_descr_ref loc;
4478 register unsigned long size = 0;
4480 for (; loc != NULL; loc = loc->dw_loc_next)
4481 size += size_of_loc_descr (loc);
4486 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4489 constant_size (value)
4490 long unsigned value;
4497 log = floor_log2 (value);
4500 log = 1 << (floor_log2 (log) + 1);
4505 /* Return the size of a DIE, as it is represented in the
4506 .debug_info section. */
4508 static unsigned long
4510 register dw_die_ref die;
4512 register unsigned long size = 0;
4513 register dw_attr_ref a;
4515 size += size_of_uleb128 (die->die_abbrev);
4516 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4518 switch (a->dw_attr_val.val_class)
4520 case dw_val_class_addr:
4523 case dw_val_class_loc:
4525 register unsigned long lsize
4526 = size_of_locs (a->dw_attr_val.v.val_loc);
4529 size += constant_size (lsize);
4533 case dw_val_class_const:
4536 case dw_val_class_unsigned_const:
4537 size += constant_size (a->dw_attr_val.v.val_unsigned);
4539 case dw_val_class_long_long:
4540 size += 1 + 8; /* block */
4542 case dw_val_class_float:
4543 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
4545 case dw_val_class_flag:
4548 case dw_val_class_die_ref:
4549 size += DWARF_OFFSET_SIZE;
4551 case dw_val_class_fde_ref:
4552 size += DWARF_OFFSET_SIZE;
4554 case dw_val_class_lbl_id:
4557 case dw_val_class_section_offset:
4558 size += DWARF_OFFSET_SIZE;
4560 case dw_val_class_str:
4561 size += size_of_string (a->dw_attr_val.v.val_str);
4571 /* Size the debgging information associted with a given DIE.
4572 Visits the DIE's children recursively. Updates the global
4573 variable next_die_offset, on each time through. Uses the
4574 current value of next_die_offset to updete the die_offset
4575 field in each DIE. */
4578 calc_die_sizes (die)
4581 register dw_die_ref c;
4582 die->die_offset = next_die_offset;
4583 next_die_offset += size_of_die (die);
4585 for (c = die->die_child; c != NULL; c = c->die_sib)
4588 if (die->die_child != NULL)
4589 /* Count the null byte used to terminate sibling lists. */
4590 next_die_offset += 1;
4593 /* Return the size of the line information prolog generated for the
4594 compilation unit. */
4596 static unsigned long
4597 size_of_line_prolog ()
4599 register unsigned long size;
4600 register unsigned long ft_index;
4602 size = DWARF_LINE_PROLOG_HEADER_SIZE;
4604 /* Count the size of the table giving number of args for each
4606 size += DWARF_LINE_OPCODE_BASE - 1;
4608 /* Include directory table is empty (at present). Count only the
4609 the null byte used to terminate the table. */
4612 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4614 /* File name entry. */
4615 size += size_of_string (file_table[ft_index]);
4617 /* Include directory index. */
4618 size += size_of_uleb128 (0);
4620 /* Modification time. */
4621 size += size_of_uleb128 (0);
4623 /* File length in bytes. */
4624 size += size_of_uleb128 (0);
4627 /* Count the file table terminator. */
4632 /* Return the size of the line information generated for this
4633 compilation unit. */
4635 static unsigned long
4636 size_of_line_info ()
4638 register unsigned long size;
4639 register unsigned long lt_index;
4640 register unsigned long current_line;
4641 register long line_offset;
4642 register long line_delta;
4643 register unsigned long current_file;
4644 register unsigned long function;
4645 unsigned long size_of_set_address;
4647 /* Size of a DW_LNE_set_address instruction. */
4648 size_of_set_address = 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
4650 /* Version number. */
4653 /* Prolog length specifier. */
4654 size += DWARF_OFFSET_SIZE;
4657 size += size_of_line_prolog ();
4659 /* Set address register instruction. */
4660 size += size_of_set_address;
4664 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
4666 register dw_line_info_ref line_info;
4668 /* Advance pc instruction. */
4669 /* ??? See the DW_LNS_advance_pc comment in output_line_info. */
4673 size += size_of_set_address;
4675 line_info = &line_info_table[lt_index];
4676 if (line_info->dw_file_num != current_file)
4678 /* Set file number instruction. */
4680 current_file = line_info->dw_file_num;
4681 size += size_of_uleb128 (current_file);
4684 if (line_info->dw_line_num != current_line)
4686 line_offset = line_info->dw_line_num - current_line;
4687 line_delta = line_offset - DWARF_LINE_BASE;
4688 current_line = line_info->dw_line_num;
4689 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4690 /* 1-byte special line number instruction. */
4694 /* Advance line instruction. */
4696 size += size_of_sleb128 (line_offset);
4697 /* Generate line entry instruction. */
4703 /* Advance pc instruction. */
4707 size += size_of_set_address;
4709 /* End of line number info. marker. */
4710 size += 1 + size_of_uleb128 (1) + 1;
4715 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
4717 register dw_separate_line_info_ref line_info
4718 = &separate_line_info_table[lt_index];
4719 if (function != line_info->function)
4721 function = line_info->function;
4722 /* Set address register instruction. */
4723 size += size_of_set_address;
4727 /* Advance pc instruction. */
4731 size += size_of_set_address;
4734 if (line_info->dw_file_num != current_file)
4736 /* Set file number instruction. */
4738 current_file = line_info->dw_file_num;
4739 size += size_of_uleb128 (current_file);
4742 if (line_info->dw_line_num != current_line)
4744 line_offset = line_info->dw_line_num - current_line;
4745 line_delta = line_offset - DWARF_LINE_BASE;
4746 current_line = line_info->dw_line_num;
4747 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4748 /* 1-byte special line number instruction. */
4752 /* Advance line instruction. */
4754 size += size_of_sleb128 (line_offset);
4756 /* Generate line entry instruction. */
4763 /* If we're done with a function, end its sequence. */
4764 if (lt_index == separate_line_info_table_in_use
4765 || separate_line_info_table[lt_index].function != function)
4770 /* Advance pc instruction. */
4774 size += size_of_set_address;
4776 /* End of line number info. marker. */
4777 size += 1 + size_of_uleb128 (1) + 1;
4784 /* Return the size of the .debug_pubnames table generated for the
4785 compilation unit. */
4787 static unsigned long
4790 register unsigned long size;
4791 register unsigned i;
4793 size = DWARF_PUBNAMES_HEADER_SIZE;
4794 for (i = 0; i < pubname_table_in_use; ++i)
4796 register pubname_ref p = &pubname_table[i];
4797 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
4800 size += DWARF_OFFSET_SIZE;
4804 /* Return the size of the information in the .debug_aranges seciton. */
4806 static unsigned long
4809 register unsigned long size;
4811 size = DWARF_ARANGES_HEADER_SIZE;
4813 /* Count the address/length pair for this compilation unit. */
4814 size += 2 * PTR_SIZE;
4815 size += 2 * PTR_SIZE * arange_table_in_use;
4817 /* Count the two zero words used to terminated the address range table. */
4818 size += 2 * PTR_SIZE;
4822 /* Select the encoding of an attribute value. */
4824 static enum dwarf_form
4828 switch (v->val_class)
4830 case dw_val_class_addr:
4831 return DW_FORM_addr;
4832 case dw_val_class_loc:
4833 switch (constant_size (size_of_locs (v->v.val_loc)))
4836 return DW_FORM_block1;
4838 return DW_FORM_block2;
4842 case dw_val_class_const:
4843 return DW_FORM_data4;
4844 case dw_val_class_unsigned_const:
4845 switch (constant_size (v->v.val_unsigned))
4848 return DW_FORM_data1;
4850 return DW_FORM_data2;
4852 return DW_FORM_data4;
4854 return DW_FORM_data8;
4858 case dw_val_class_long_long:
4859 return DW_FORM_block1;
4860 case dw_val_class_float:
4861 return DW_FORM_block1;
4862 case dw_val_class_flag:
4863 return DW_FORM_flag;
4864 case dw_val_class_die_ref:
4866 case dw_val_class_fde_ref:
4867 return DW_FORM_data;
4868 case dw_val_class_lbl_id:
4869 return DW_FORM_addr;
4870 case dw_val_class_section_offset:
4871 return DW_FORM_data;
4872 case dw_val_class_str:
4873 return DW_FORM_string;
4879 /* Output the encoding of an attribute value. */
4882 output_value_format (v)
4885 enum dwarf_form form = value_format (v);
4887 output_uleb128 (form);
4889 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
4891 fputc ('\n', asm_out_file);
4894 /* Output the .debug_abbrev section which defines the DIE abbreviation
4898 output_abbrev_section ()
4900 unsigned long abbrev_id;
4903 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4905 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4907 output_uleb128 (abbrev_id);
4909 fprintf (asm_out_file, " (abbrev code)");
4911 fputc ('\n', asm_out_file);
4912 output_uleb128 (abbrev->die_tag);
4914 fprintf (asm_out_file, " (TAG: %s)",
4915 dwarf_tag_name (abbrev->die_tag));
4917 fputc ('\n', asm_out_file);
4918 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
4919 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
4922 fprintf (asm_out_file, "\t%s %s",
4924 (abbrev->die_child != NULL
4925 ? "DW_children_yes" : "DW_children_no"));
4927 fputc ('\n', asm_out_file);
4929 for (a_attr = abbrev->die_attr; a_attr != NULL;
4930 a_attr = a_attr->dw_attr_next)
4932 output_uleb128 (a_attr->dw_attr);
4934 fprintf (asm_out_file, " (%s)",
4935 dwarf_attr_name (a_attr->dw_attr));
4937 fputc ('\n', asm_out_file);
4938 output_value_format (&a_attr->dw_attr_val);
4941 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
4945 /* Output location description stack opcode's operands (if any). */
4948 output_loc_operands (loc)
4949 register dw_loc_descr_ref loc;
4951 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
4952 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
4954 switch (loc->dw_loc_opc)
4957 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
4958 fputc ('\n', asm_out_file);
4962 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4963 fputc ('\n', asm_out_file);
4967 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4968 fputc ('\n', asm_out_file);
4972 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
4973 fputc ('\n', asm_out_file);
4978 fputc ('\n', asm_out_file);
4981 output_uleb128 (val1->v.val_unsigned);
4982 fputc ('\n', asm_out_file);
4985 output_sleb128 (val1->v.val_int);
4986 fputc ('\n', asm_out_file);
4989 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
4990 fputc ('\n', asm_out_file);
4992 case DW_OP_plus_uconst:
4993 output_uleb128 (val1->v.val_unsigned);
4994 fputc ('\n', asm_out_file);
4998 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4999 fputc ('\n', asm_out_file);
5033 output_sleb128 (val1->v.val_int);
5034 fputc ('\n', asm_out_file);
5037 output_uleb128 (val1->v.val_unsigned);
5038 fputc ('\n', asm_out_file);
5041 output_sleb128 (val1->v.val_int);
5042 fputc ('\n', asm_out_file);
5045 output_uleb128 (val1->v.val_unsigned);
5046 fputc ('\n', asm_out_file);
5047 output_sleb128 (val2->v.val_int);
5048 fputc ('\n', asm_out_file);
5051 output_uleb128 (val1->v.val_unsigned);
5052 fputc ('\n', asm_out_file);
5054 case DW_OP_deref_size:
5055 case DW_OP_xderef_size:
5056 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
5057 fputc ('\n', asm_out_file);
5064 /* Compute the offset of a sibling. */
5066 static unsigned long
5067 sibling_offset (die)
5070 unsigned long offset;
5072 if (die->die_child_last == NULL)
5073 offset = die->die_offset + size_of_die (die);
5075 offset = sibling_offset (die->die_child_last) + 1;
5080 /* Output the DIE and its attributes. Called recursively to generate
5081 the definitions of each child DIE. */
5085 register dw_die_ref die;
5087 register dw_attr_ref a;
5088 register dw_die_ref c;
5089 register unsigned long ref_offset;
5090 register unsigned long size;
5091 register dw_loc_descr_ref loc;
5094 output_uleb128 (die->die_abbrev);
5096 fprintf (asm_out_file, " (DIE (0x%x) %s)",
5097 die->die_offset, dwarf_tag_name (die->die_tag));
5099 fputc ('\n', asm_out_file);
5101 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5103 switch (a->dw_attr_val.val_class)
5105 case dw_val_class_addr:
5106 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
5107 a->dw_attr_val.v.val_addr);
5110 case dw_val_class_loc:
5111 size = size_of_locs (a->dw_attr_val.v.val_loc);
5113 /* Output the block length for this list of location operations. */
5114 switch (constant_size (size))
5117 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5120 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5127 fprintf (asm_out_file, "\t%s %s",
5128 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5130 fputc ('\n', asm_out_file);
5131 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
5132 loc = loc->dw_loc_next)
5134 /* Output the opcode. */
5135 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
5137 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
5138 dwarf_stack_op_name (loc->dw_loc_opc));
5140 fputc ('\n', asm_out_file);
5142 /* Output the operand(s) (if any). */
5143 output_loc_operands (loc);
5147 case dw_val_class_const:
5148 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
5151 case dw_val_class_unsigned_const:
5152 switch (constant_size (a->dw_attr_val.v.val_unsigned))
5155 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5156 a->dw_attr_val.v.val_unsigned);
5159 ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
5160 a->dw_attr_val.v.val_unsigned);
5163 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5164 a->dw_attr_val.v.val_unsigned);
5167 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5168 a->dw_attr_val.v.val_long_long.hi,
5169 a->dw_attr_val.v.val_long_long.low);
5176 case dw_val_class_long_long:
5177 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5179 fprintf (asm_out_file, "\t%s %s",
5180 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5182 fputc ('\n', asm_out_file);
5183 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5184 a->dw_attr_val.v.val_long_long.hi,
5185 a->dw_attr_val.v.val_long_long.low);
5188 fprintf (asm_out_file,
5189 "\t%s long long constant", ASM_COMMENT_START);
5191 fputc ('\n', asm_out_file);
5194 case dw_val_class_float:
5195 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5196 a->dw_attr_val.v.val_float.length * 4);
5198 fprintf (asm_out_file, "\t%s %s",
5199 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5201 fputc ('\n', asm_out_file);
5202 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5204 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5205 a->dw_attr_val.v.val_float.array[i]);
5207 fprintf (asm_out_file, "\t%s fp constant word %d",
5208 ASM_COMMENT_START, i);
5210 fputc ('\n', asm_out_file);
5214 case dw_val_class_flag:
5215 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
5218 case dw_val_class_die_ref:
5219 if (a->dw_attr_val.v.val_die_ref != NULL)
5220 ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
5221 else if (a->dw_attr == DW_AT_sibling)
5222 ref_offset = sibling_offset(die);
5226 ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
5229 case dw_val_class_fde_ref:
5232 ASM_GENERATE_INTERNAL_LABEL
5233 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5234 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5235 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5239 case dw_val_class_lbl_id:
5240 ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
5243 case dw_val_class_section_offset:
5244 ASM_OUTPUT_DWARF_OFFSET (asm_out_file,
5246 (a->dw_attr_val.v.val_section));
5249 case dw_val_class_str:
5251 ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
5253 ASM_OUTPUT_ASCII (asm_out_file,
5254 a->dw_attr_val.v.val_str,
5255 strlen (a->dw_attr_val.v.val_str) + 1);
5262 if (a->dw_attr_val.val_class != dw_val_class_loc
5263 && a->dw_attr_val.val_class != dw_val_class_long_long
5264 && a->dw_attr_val.val_class != dw_val_class_float)
5267 fprintf (asm_out_file, "\t%s %s",
5268 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5270 fputc ('\n', asm_out_file);
5274 for (c = die->die_child; c != NULL; c = c->die_sib)
5277 if (die->die_child != NULL)
5279 /* Add null byte to terminate sibling list. */
5280 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5282 fprintf (asm_out_file, "\t%s end of children of DIE 0x%x",
5283 ASM_COMMENT_START, die->die_offset);
5285 fputc ('\n', asm_out_file);
5289 /* Output the compilation unit that appears at the beginning of the
5290 .debug_info section, and precedes the DIE descriptions. */
5293 output_compilation_unit_header ()
5295 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
5297 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
5300 fputc ('\n', asm_out_file);
5301 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5303 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
5305 fputc ('\n', asm_out_file);
5306 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION));
5308 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
5311 fputc ('\n', asm_out_file);
5312 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5314 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
5316 fputc ('\n', asm_out_file);
5319 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5320 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5321 argument list, and maybe the scope. */
5324 dwarf2_name (decl, scope)
5328 return (*decl_printable_name) (decl, scope ? 1 : 0);
5331 /* Add a new entry to .debug_pubnames if appropriate. */
5334 add_pubname (decl, die)
5340 if (! TREE_PUBLIC (decl))
5343 if (pubname_table_in_use == pubname_table_allocated)
5345 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5346 pubname_table = (pubname_ref) xrealloc
5347 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5350 p = &pubname_table[pubname_table_in_use++];
5353 p->name = xstrdup (dwarf2_name (decl, 1));
5356 /* Output the public names table used to speed up access to externally
5357 visible names. For now, only generate entries for externally
5358 visible procedures. */
5363 register unsigned i;
5364 register unsigned long pubnames_length = size_of_pubnames ();
5366 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
5369 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
5372 fputc ('\n', asm_out_file);
5373 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5376 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5378 fputc ('\n', asm_out_file);
5379 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_INFO_SECTION));
5381 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5384 fputc ('\n', asm_out_file);
5385 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
5387 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
5389 fputc ('\n', asm_out_file);
5390 for (i = 0; i < pubname_table_in_use; ++i)
5392 register pubname_ref pub = &pubname_table[i];
5394 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
5396 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
5398 fputc ('\n', asm_out_file);
5402 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
5403 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
5407 ASM_OUTPUT_ASCII (asm_out_file, pub->name, strlen (pub->name) + 1);
5410 fputc ('\n', asm_out_file);
5413 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
5414 fputc ('\n', asm_out_file);
5417 /* Add a new entry to .debug_aranges if appropriate. */
5420 add_arange (decl, die)
5424 if (! DECL_SECTION_NAME (decl))
5427 if (arange_table_in_use == arange_table_allocated)
5429 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5431 = (arange_ref) xrealloc (arange_table,
5432 arange_table_allocated * sizeof (dw_die_ref));
5435 arange_table[arange_table_in_use++] = die;
5438 /* Output the information that goes into the .debug_aranges table.
5439 Namely, define the beginning and ending address range of the
5440 text section generated for this compilation unit. */
5445 register unsigned i;
5446 register unsigned long aranges_length = size_of_aranges ();
5448 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
5450 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
5453 fputc ('\n', asm_out_file);
5454 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5456 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5458 fputc ('\n', asm_out_file);
5459 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_INFO_SECTION));
5461 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5464 fputc ('\n', asm_out_file);
5465 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5467 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
5469 fputc ('\n', asm_out_file);
5470 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5472 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
5475 fputc ('\n', asm_out_file);
5476 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
5478 fprintf (asm_out_file, ",0,0");
5481 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5482 ASM_COMMENT_START, 2 * PTR_SIZE);
5484 fputc ('\n', asm_out_file);
5485 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
5487 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5489 fputc ('\n', asm_out_file);
5490 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label, TEXT_SECTION);
5492 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5494 fputc ('\n', asm_out_file);
5495 for (i = 0; i < arange_table_in_use; ++i)
5497 dw_die_ref a = arange_table[i];
5499 if (a->die_tag == DW_TAG_subprogram)
5500 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a));
5503 char *name = get_AT_string (a, DW_AT_MIPS_linkage_name);
5505 name = get_AT_string (a, DW_AT_name);
5507 ASM_OUTPUT_DWARF_ADDR (asm_out_file, name);
5511 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5513 fputc ('\n', asm_out_file);
5514 if (a->die_tag == DW_TAG_subprogram)
5515 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a),
5518 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5519 get_AT_unsigned (a, DW_AT_byte_size));
5522 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5524 fputc ('\n', asm_out_file);
5527 /* Output the terminator words. */
5528 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5529 fputc ('\n', asm_out_file);
5530 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5531 fputc ('\n', asm_out_file);
5534 /* Output the source line number correspondence information. This
5535 information goes into the .debug_line section.
5537 If the format of this data changes, then the function size_of_line_info
5538 must also be adjusted the same way. */
5543 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5544 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5545 register unsigned opc;
5546 register unsigned n_op_args;
5547 register unsigned long ft_index;
5548 register unsigned long lt_index;
5549 register unsigned long current_line;
5550 register long line_offset;
5551 register long line_delta;
5552 register unsigned long current_file;
5553 register unsigned long function;
5555 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ());
5557 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5560 fputc ('\n', asm_out_file);
5561 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5563 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5565 fputc ('\n', asm_out_file);
5566 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
5568 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5570 fputc ('\n', asm_out_file);
5571 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
5573 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5576 fputc ('\n', asm_out_file);
5577 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
5579 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5582 fputc ('\n', asm_out_file);
5583 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
5585 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5588 fputc ('\n', asm_out_file);
5589 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
5591 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5594 fputc ('\n', asm_out_file);
5595 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5597 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5599 fputc ('\n', asm_out_file);
5600 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5604 case DW_LNS_advance_pc:
5605 case DW_LNS_advance_line:
5606 case DW_LNS_set_file:
5607 case DW_LNS_set_column:
5608 case DW_LNS_fixed_advance_pc:
5615 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5617 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5618 ASM_COMMENT_START, opc, n_op_args);
5619 fputc ('\n', asm_out_file);
5623 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5625 /* Include directory table is empty, at present */
5626 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5627 fputc ('\n', asm_out_file);
5629 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5631 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5635 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5636 fprintf (asm_out_file, "%s File Entry: 0x%x",
5637 ASM_COMMENT_START, ft_index);
5641 ASM_OUTPUT_ASCII (asm_out_file,
5642 file_table[ft_index],
5643 strlen (file_table[ft_index]) + 1);
5646 fputc ('\n', asm_out_file);
5648 /* Include directory index */
5650 fputc ('\n', asm_out_file);
5652 /* Modification time */
5654 fputc ('\n', asm_out_file);
5656 /* File length in bytes */
5658 fputc ('\n', asm_out_file);
5661 /* Terminate the file name table */
5662 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5663 fputc ('\n', asm_out_file);
5665 /* Set the address register to the first location in the text section */
5666 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5668 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5670 fputc ('\n', asm_out_file);
5671 output_uleb128 (1 + PTR_SIZE);
5672 fputc ('\n', asm_out_file);
5673 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5674 fputc ('\n', asm_out_file);
5675 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
5676 fputc ('\n', asm_out_file);
5678 /* Generate the line number to PC correspondence table, encoded as
5679 a series of state machine operations. */
5682 strcpy (prev_line_label, TEXT_SECTION);
5683 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5685 register dw_line_info_ref line_info;
5687 /* Emit debug info for the address of the current line, choosing
5688 the encoding that uses the least amount of space. */
5689 /* ??? Unfortunately, we have little choice here currently, and must
5690 always use the most general form. Gcc does not know the address
5691 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5692 dwarf2 aware assemblers at this time, so we can't use any special
5693 pseudo ops that would allow the assembler to optimally encode this for
5694 us. Many ports do have length attributes which will give an upper
5695 bound on the address range. We could perhaps use length attributes
5696 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5697 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5700 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5701 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5703 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5706 fputc ('\n', asm_out_file);
5707 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5708 fputc ('\n', asm_out_file);
5712 /* This can handle any delta. This takes 4+PTR_SIZE bytes. */
5713 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5715 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5717 fputc ('\n', asm_out_file);
5718 output_uleb128 (1 + PTR_SIZE);
5719 fputc ('\n', asm_out_file);
5720 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5721 fputc ('\n', asm_out_file);
5722 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5723 fputc ('\n', asm_out_file);
5725 strcpy (prev_line_label, line_label);
5727 /* Emit debug info for the source file of the current line, if
5728 different from the previous line. */
5729 line_info = &line_info_table[lt_index];
5730 if (line_info->dw_file_num != current_file)
5732 current_file = line_info->dw_file_num;
5733 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5735 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5737 fputc ('\n', asm_out_file);
5738 output_uleb128 (current_file);
5740 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5742 fputc ('\n', asm_out_file);
5745 /* Emit debug info for the current line number, choosing the encoding
5746 that uses the least amount of space. */
5747 line_offset = line_info->dw_line_num - current_line;
5748 line_delta = line_offset - DWARF_LINE_BASE;
5749 current_line = line_info->dw_line_num;
5750 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5752 /* This can handle deltas from -10 to 234, using the current
5753 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5755 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5756 DWARF_LINE_OPCODE_BASE + line_delta);
5758 fprintf (asm_out_file,
5759 "\t%s line %d", ASM_COMMENT_START, current_line);
5761 fputc ('\n', asm_out_file);
5765 /* This can handle any delta. This takes at least 4 bytes, depending
5766 on the value being encoded. */
5767 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5769 fprintf (asm_out_file, "\t%s advance to line %d",
5770 ASM_COMMENT_START, current_line);
5772 fputc ('\n', asm_out_file);
5773 output_sleb128 (line_offset);
5774 fputc ('\n', asm_out_file);
5775 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5776 fputc ('\n', asm_out_file);
5780 /* Emit debug info for the address of the end of the function. */
5783 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5785 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5788 fputc ('\n', asm_out_file);
5789 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
5790 fputc ('\n', asm_out_file);
5794 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5796 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5797 fputc ('\n', asm_out_file);
5798 output_uleb128 (1 + PTR_SIZE);
5799 fputc ('\n', asm_out_file);
5800 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5801 fputc ('\n', asm_out_file);
5802 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
5803 fputc ('\n', asm_out_file);
5806 /* Output the marker for the end of the line number info. */
5807 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5809 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
5811 fputc ('\n', asm_out_file);
5813 fputc ('\n', asm_out_file);
5814 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5815 fputc ('\n', asm_out_file);
5820 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5822 register dw_separate_line_info_ref line_info
5823 = &separate_line_info_table[lt_index];
5825 /* Emit debug info for the address of the current line. If this is
5826 a new function, or the first line of a function, then we need
5827 to handle it differently. */
5828 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
5830 if (function != line_info->function)
5832 function = line_info->function;
5834 /* Set the address register to the first line in the function */
5835 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5837 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
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, line_label);
5846 fputc ('\n', asm_out_file);
5850 /* ??? See the DW_LNS_advance_pc comment above. */
5853 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5855 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5858 fputc ('\n', asm_out_file);
5859 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5861 fputc ('\n', asm_out_file);
5865 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5867 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5869 fputc ('\n', asm_out_file);
5870 output_uleb128 (1 + PTR_SIZE);
5871 fputc ('\n', asm_out_file);
5872 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5873 fputc ('\n', asm_out_file);
5874 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5875 fputc ('\n', asm_out_file);
5878 strcpy (prev_line_label, line_label);
5880 /* Emit debug info for the source file of the current line, if
5881 different from the previous line. */
5882 if (line_info->dw_file_num != current_file)
5884 current_file = line_info->dw_file_num;
5885 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5887 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5889 fputc ('\n', asm_out_file);
5890 output_uleb128 (current_file);
5892 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5894 fputc ('\n', asm_out_file);
5897 /* Emit debug info for the current line number, choosing the encoding
5898 that uses the least amount of space. */
5899 if (line_info->dw_line_num != current_line)
5901 line_offset = line_info->dw_line_num - current_line;
5902 line_delta = line_offset - DWARF_LINE_BASE;
5903 current_line = line_info->dw_line_num;
5904 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5906 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5907 DWARF_LINE_OPCODE_BASE + line_delta);
5909 fprintf (asm_out_file,
5910 "\t%s line %d", ASM_COMMENT_START, current_line);
5912 fputc ('\n', asm_out_file);
5916 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5918 fprintf (asm_out_file, "\t%s advance to line %d",
5919 ASM_COMMENT_START, current_line);
5921 fputc ('\n', asm_out_file);
5922 output_sleb128 (line_offset);
5923 fputc ('\n', asm_out_file);
5924 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5925 fputc ('\n', asm_out_file);
5931 /* If we're done with a function, end its sequence. */
5932 if (lt_index == separate_line_info_table_in_use
5933 || separate_line_info_table[lt_index].function != function)
5938 /* Emit debug info for the address of the end of the function. */
5939 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
5942 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5944 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5947 fputc ('\n', asm_out_file);
5948 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5950 fputc ('\n', asm_out_file);
5954 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5956 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5958 fputc ('\n', asm_out_file);
5959 output_uleb128 (1 + PTR_SIZE);
5960 fputc ('\n', asm_out_file);
5961 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5962 fputc ('\n', asm_out_file);
5963 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5964 fputc ('\n', asm_out_file);
5967 /* Output the marker for the end of this sequence. */
5968 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5970 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
5973 fputc ('\n', asm_out_file);
5975 fputc ('\n', asm_out_file);
5976 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5977 fputc ('\n', asm_out_file);
5982 /* Given a pointer to a BLOCK node return non-zero if (and only if) the node
5983 in question represents the outermost pair of curly braces (i.e. the "body
5984 block") of a function or method.
5986 For any BLOCK node representing a "body block" of a function or method, the
5987 BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
5988 represents the outermost (function) scope for the function or method (i.e.
5989 the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
5990 *that* node in turn will point to the relevant FUNCTION_DECL node. */
5993 is_body_block (stmt)
5996 if (TREE_CODE (stmt) == BLOCK)
5998 register tree parent = BLOCK_SUPERCONTEXT (stmt);
6000 if (TREE_CODE (parent) == BLOCK)
6002 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
6004 if (TREE_CODE (grandparent) == FUNCTION_DECL)
6012 /* Given a pointer to a tree node for some base type, return a pointer to
6013 a DIE that describes the given type.
6015 This routine must only be called for GCC type nodes that correspond to
6016 Dwarf base (fundamental) types. */
6019 base_type_die (type)
6022 register dw_die_ref base_type_result;
6023 register char *type_name;
6024 register enum dwarf_type encoding;
6025 register tree name = TYPE_NAME (type);
6027 if (TREE_CODE (type) == ERROR_MARK
6028 || TREE_CODE (type) == VOID_TYPE)
6031 if (TREE_CODE (name) == TYPE_DECL)
6032 name = DECL_NAME (name);
6033 type_name = IDENTIFIER_POINTER (name);
6035 switch (TREE_CODE (type))
6038 /* Carefully distinguish the C character types, without messing
6039 up if the language is not C. Note that we check only for the names
6040 that contain spaces; other names might occur by coincidence in other
6042 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6043 && (type == char_type_node
6044 || ! strcmp (type_name, "signed char")
6045 || ! strcmp (type_name, "unsigned char"))))
6047 if (TREE_UNSIGNED (type))
6048 encoding = DW_ATE_unsigned;
6050 encoding = DW_ATE_signed;
6053 /* else fall through */
6056 /* GNU Pascal/Ada CHAR type. Not used in C. */
6057 if (TREE_UNSIGNED (type))
6058 encoding = DW_ATE_unsigned_char;
6060 encoding = DW_ATE_signed_char;
6064 encoding = DW_ATE_float;
6068 encoding = DW_ATE_complex_float;
6072 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6073 encoding = DW_ATE_boolean;
6077 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6080 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6081 add_AT_string (base_type_result, DW_AT_name, type_name);
6082 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6083 TYPE_PRECISION (type) / BITS_PER_UNIT);
6084 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6086 return base_type_result;
6089 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6090 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6091 a given type is generally the same as the given type, except that if the
6092 given type is a pointer or reference type, then the root type of the given
6093 type is the root type of the "basis" type for the pointer or reference
6094 type. (This definition of the "root" type is recursive.) Also, the root
6095 type of a `const' qualified type or a `volatile' qualified type is the
6096 root type of the given type without the qualifiers. */
6102 if (TREE_CODE (type) == ERROR_MARK)
6103 return error_mark_node;
6105 switch (TREE_CODE (type))
6108 return error_mark_node;
6111 case REFERENCE_TYPE:
6112 return type_main_variant (root_type (TREE_TYPE (type)));
6115 return type_main_variant (type);
6119 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6120 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6126 switch (TREE_CODE (type))
6141 case QUAL_UNION_TYPE:
6146 case REFERENCE_TYPE:
6159 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6160 entry that chains various modifiers in front of the given type. */
6163 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6165 register int is_const_type;
6166 register int is_volatile_type;
6167 register dw_die_ref context_die;
6169 register enum tree_code code = TREE_CODE (type);
6170 register dw_die_ref mod_type_die = NULL;
6171 register dw_die_ref sub_die = NULL;
6172 register tree item_type = NULL;
6174 if (code != ERROR_MARK)
6176 type = build_type_variant (type, is_const_type, is_volatile_type);
6178 mod_type_die = lookup_type_die (type);
6180 return mod_type_die;
6182 /* Handle C typedef types. */
6183 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6184 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6186 tree dtype = TREE_TYPE (TYPE_NAME (type));
6189 /* For a named type, use the typedef. */
6190 gen_type_die (type, context_die);
6191 mod_type_die = lookup_type_die (type);
6194 else if (is_const_type < TYPE_READONLY (dtype)
6195 || is_volatile_type < TYPE_VOLATILE (dtype))
6196 /* cv-unqualified version of named type. Just use the unnamed
6197 type to which it refers. */
6199 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6200 is_const_type, is_volatile_type,
6202 /* Else cv-qualified version of named type; fall through. */
6207 else if (is_const_type)
6209 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6210 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6212 else if (is_volatile_type)
6214 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6215 sub_die = modified_type_die (type, 0, 0, context_die);
6217 else if (code == POINTER_TYPE)
6219 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6220 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6222 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6224 item_type = TREE_TYPE (type);
6226 else if (code == REFERENCE_TYPE)
6228 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6229 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6231 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6233 item_type = TREE_TYPE (type);
6235 else if (is_base_type (type))
6236 mod_type_die = base_type_die (type);
6239 gen_type_die (type, context_die);
6241 /* We have to get the type_main_variant here (and pass that to the
6242 `lookup_type_die' routine) because the ..._TYPE node we have
6243 might simply be a *copy* of some original type node (where the
6244 copy was created to help us keep track of typedef names) and
6245 that copy might have a different TYPE_UID from the original
6247 mod_type_die = lookup_type_die (type_main_variant (type));
6248 if (mod_type_die == NULL)
6253 equate_type_number_to_die (type, mod_type_die);
6255 /* We must do this after the equate_type_number_to_die call, in case
6256 this is a recursive type. This ensures that the modified_type_die
6257 recursion will terminate even if the type is recursive. Recursive
6258 types are possible in Ada. */
6259 sub_die = modified_type_die (item_type,
6260 TYPE_READONLY (item_type),
6261 TYPE_VOLATILE (item_type),
6264 if (sub_die != NULL)
6265 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6267 return mod_type_die;
6270 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6271 an enumerated type. */
6277 return TREE_CODE (type) == ENUMERAL_TYPE;
6280 /* Return a location descriptor that designates a machine register. */
6282 static dw_loc_descr_ref
6283 reg_loc_descriptor (rtl)
6286 register dw_loc_descr_ref loc_result = NULL;
6287 register unsigned reg = reg_number (rtl);
6289 if (reg >= 0 && reg <= 31)
6290 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6292 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6297 /* Return a location descriptor that designates a base+offset location. */
6299 static dw_loc_descr_ref
6300 based_loc_descr (reg, offset)
6304 register dw_loc_descr_ref loc_result;
6305 /* For the "frame base", we use the frame pointer or stack pointer
6306 registers, since the RTL for local variables is relative to one of
6308 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6309 ? HARD_FRAME_POINTER_REGNUM
6310 : STACK_POINTER_REGNUM);
6313 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
6314 else if (reg >= 0 && reg <= 31)
6315 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
6317 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
6322 /* Return true if this RTL expression describes a base+offset calculation. */
6328 return (GET_CODE (rtl) == PLUS
6329 && ((GET_CODE (XEXP (rtl, 0)) == REG
6330 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
6333 /* The following routine converts the RTL for a variable or parameter
6334 (resident in memory) into an equivalent Dwarf representation of a
6335 mechanism for getting the address of that same variable onto the top of a
6336 hypothetical "address evaluation" stack.
6338 When creating memory location descriptors, we are effectively transforming
6339 the RTL for a memory-resident object into its Dwarf postfix expression
6340 equivalent. This routine recursively descends an RTL tree, turning
6341 it into Dwarf postfix code as it goes. */
6343 static dw_loc_descr_ref
6344 mem_loc_descriptor (rtl)
6347 dw_loc_descr_ref mem_loc_result = NULL;
6348 /* Note that for a dynamically sized array, the location we will generate a
6349 description of here will be the lowest numbered location which is
6350 actually within the array. That's *not* necessarily the same as the
6351 zeroth element of the array. */
6353 switch (GET_CODE (rtl))
6356 /* The case of a subreg may arise when we have a local (register)
6357 variable or a formal (register) parameter which doesn't quite fill
6358 up an entire register. For now, just assume that it is
6359 legitimate to make the Dwarf info refer to the whole register which
6360 contains the given subreg. */
6361 rtl = XEXP (rtl, 0);
6363 /* ... fall through ... */
6366 /* Whenever a register number forms a part of the description of the
6367 method for calculating the (dynamic) address of a memory resident
6368 object, DWARF rules require the register number be referred to as
6369 a "base register". This distinction is not based in any way upon
6370 what category of register the hardware believes the given register
6371 belongs to. This is strictly DWARF terminology we're dealing with
6372 here. Note that in cases where the location of a memory-resident
6373 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6374 OP_CONST (0)) the actual DWARF location descriptor that we generate
6375 may just be OP_BASEREG (basereg). This may look deceptively like
6376 the object in question was allocated to a register (rather than in
6377 memory) so DWARF consumers need to be aware of the subtle
6378 distinction between OP_REG and OP_BASEREG. */
6379 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
6383 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0));
6384 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6389 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6390 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6391 mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
6395 if (is_based_loc (rtl))
6396 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
6397 INTVAL (XEXP (rtl, 1)));
6400 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
6401 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
6402 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
6407 /* If a pseudo-reg is optimized away, it is possible for it to
6408 be replaced with a MEM containing a multiply. */
6409 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
6410 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
6411 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
6415 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6422 return mem_loc_result;
6425 /* Return a descriptor that describes the concatination of two locations.
6426 This is typically a complex variable. */
6428 static dw_loc_descr_ref
6429 concat_loc_descriptor (x0, x1)
6430 register rtx x0, x1;
6432 dw_loc_descr_ref cc_loc_result = NULL;
6434 if (!is_pseudo_reg (x0)
6435 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
6436 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
6437 add_loc_descr (&cc_loc_result,
6438 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
6440 if (!is_pseudo_reg (x1)
6441 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
6442 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
6443 add_loc_descr (&cc_loc_result,
6444 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
6446 return cc_loc_result;
6449 /* Output a proper Dwarf location descriptor for a variable or parameter
6450 which is either allocated in a register or in a memory location. For a
6451 register, we just generate an OP_REG and the register number. For a
6452 memory location we provide a Dwarf postfix expression describing how to
6453 generate the (dynamic) address of the object onto the address stack. */
6455 static dw_loc_descr_ref
6456 loc_descriptor (rtl)
6459 dw_loc_descr_ref loc_result = NULL;
6460 switch (GET_CODE (rtl))
6463 /* The case of a subreg may arise when we have a local (register)
6464 variable or a formal (register) parameter which doesn't quite fill
6465 up an entire register. For now, just assume that it is
6466 legitimate to make the Dwarf info refer to the whole register which
6467 contains the given subreg. */
6468 rtl = XEXP (rtl, 0);
6470 /* ... fall through ... */
6473 loc_result = reg_loc_descriptor (rtl);
6477 loc_result = mem_loc_descriptor (XEXP (rtl, 0));
6481 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
6491 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
6492 which is not less than the value itself. */
6494 static inline unsigned
6495 ceiling (value, boundary)
6496 register unsigned value;
6497 register unsigned boundary;
6499 return (((value + boundary - 1) / boundary) * boundary);
6502 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6503 pointer to the declared type for the relevant field variable, or return
6504 `integer_type_node' if the given node turns out to be an
6513 if (TREE_CODE (decl) == ERROR_MARK)
6514 return integer_type_node;
6516 type = DECL_BIT_FIELD_TYPE (decl);
6517 if (type == NULL_TREE)
6518 type = TREE_TYPE (decl);
6523 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6524 node, return the alignment in bits for the type, or else return
6525 BITS_PER_WORD if the node actually turns out to be an
6528 static inline unsigned
6529 simple_type_align_in_bits (type)
6532 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6535 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6536 node, return the size in bits for the type if it is a constant, or else
6537 return the alignment for the type if the type's size is not constant, or
6538 else return BITS_PER_WORD if the type actually turns out to be an
6541 static inline unsigned
6542 simple_type_size_in_bits (type)
6545 if (TREE_CODE (type) == ERROR_MARK)
6546 return BITS_PER_WORD;
6549 register tree type_size_tree = TYPE_SIZE (type);
6551 if (TREE_CODE (type_size_tree) != INTEGER_CST)
6552 return TYPE_ALIGN (type);
6554 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
6558 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6559 return the byte offset of the lowest addressed byte of the "containing
6560 object" for the given FIELD_DECL, or return 0 if we are unable to
6561 determine what that offset is, either because the argument turns out to
6562 be a pointer to an ERROR_MARK node, or because the offset is actually
6563 variable. (We can't handle the latter case just yet). */
6566 field_byte_offset (decl)
6569 register unsigned type_align_in_bytes;
6570 register unsigned type_align_in_bits;
6571 register unsigned type_size_in_bits;
6572 register unsigned object_offset_in_align_units;
6573 register unsigned object_offset_in_bits;
6574 register unsigned object_offset_in_bytes;
6576 register tree bitpos_tree;
6577 register tree field_size_tree;
6578 register unsigned bitpos_int;
6579 register unsigned deepest_bitpos;
6580 register unsigned field_size_in_bits;
6582 if (TREE_CODE (decl) == ERROR_MARK)
6585 if (TREE_CODE (decl) != FIELD_DECL)
6588 type = field_type (decl);
6590 bitpos_tree = DECL_FIELD_BITPOS (decl);
6591 field_size_tree = DECL_SIZE (decl);
6593 /* We cannot yet cope with fields whose positions or sizes are variable, so
6594 for now, when we see such things, we simply return 0. Someday, we may
6595 be able to handle such cases, but it will be damn difficult. */
6596 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6598 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6600 if (TREE_CODE (field_size_tree) != INTEGER_CST)
6603 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
6604 type_size_in_bits = simple_type_size_in_bits (type);
6605 type_align_in_bits = simple_type_align_in_bits (type);
6606 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6608 /* Note that the GCC front-end doesn't make any attempt to keep track of
6609 the starting bit offset (relative to the start of the containing
6610 structure type) of the hypothetical "containing object" for a bit-
6611 field. Thus, when computing the byte offset value for the start of the
6612 "containing object" of a bit-field, we must deduce this information on
6613 our own. This can be rather tricky to do in some cases. For example,
6614 handling the following structure type definition when compiling for an
6615 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6618 struct S { int field1; long long field2:31; };
6620 Fortunately, there is a simple rule-of-thumb which can be
6621 used in such cases. When compiling for an i386/i486, GCC will allocate
6622 8 bytes for the structure shown above. It decides to do this based upon
6623 one simple rule for bit-field allocation. Quite simply, GCC allocates
6624 each "containing object" for each bit-field at the first (i.e. lowest
6625 addressed) legitimate alignment boundary (based upon the required
6626 minimum alignment for the declared type of the field) which it can
6627 possibly use, subject to the condition that there is still enough
6628 available space remaining in the containing object (when allocated at
6629 the selected point) to fully accommodate all of the bits of the
6630 bit-field itself. This simple rule makes it obvious why GCC allocates
6631 8 bytes for each object of the structure type shown above. When looking
6632 for a place to allocate the "containing object" for `field2', the
6633 compiler simply tries to allocate a 64-bit "containing object" at each
6634 successive 32-bit boundary (starting at zero) until it finds a place to
6635 allocate that 64- bit field such that at least 31 contiguous (and
6636 previously unallocated) bits remain within that selected 64 bit field.
6637 (As it turns out, for the example above, the compiler finds that it is
6638 OK to allocate the "containing object" 64-bit field at bit-offset zero
6639 within the structure type.) Here we attempt to work backwards from the
6640 limited set of facts we're given, and we try to deduce from those facts,
6641 where GCC must have believed that the containing object started (within
6642 the structure type). The value we deduce is then used (by the callers of
6643 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6644 for fields (both bit-fields and, in the case of DW_AT_location, regular
6647 /* Figure out the bit-distance from the start of the structure to the
6648 "deepest" bit of the bit-field. */
6649 deepest_bitpos = bitpos_int + field_size_in_bits;
6651 /* This is the tricky part. Use some fancy footwork to deduce where the
6652 lowest addressed bit of the containing object must be. */
6653 object_offset_in_bits
6654 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6656 /* Compute the offset of the containing object in "alignment units". */
6657 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6659 /* Compute the offset of the containing object in bytes. */
6660 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6662 return object_offset_in_bytes;
6665 /* The following routines define various Dwarf attributes and any data
6666 associated with them. */
6668 /* Add a location description attribute value to a DIE.
6670 This emits location attributes suitable for whole variables and
6671 whole parameters. Note that the location attributes for struct fields are
6672 generated by the routine `data_member_location_attribute' below. */
6675 add_AT_location_description (die, attr_kind, rtl)
6677 enum dwarf_attribute attr_kind;
6680 /* Handle a special case. If we are about to output a location descriptor
6681 for a variable or parameter which has been optimized out of existence,
6682 don't do that. A variable which has been optimized out
6683 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6684 Currently, in some rare cases, variables can have DECL_RTL values which
6685 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6686 elsewhere in the compiler. We treat such cases as if the variable(s) in
6687 question had been optimized out of existence. */
6689 if (is_pseudo_reg (rtl)
6690 || (GET_CODE (rtl) == MEM
6691 && is_pseudo_reg (XEXP (rtl, 0)))
6692 || (GET_CODE (rtl) == CONCAT
6693 && is_pseudo_reg (XEXP (rtl, 0))
6694 && is_pseudo_reg (XEXP (rtl, 1))))
6697 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
6700 /* Attach the specialized form of location attribute used for data
6701 members of struct and union types. In the special case of a
6702 FIELD_DECL node which represents a bit-field, the "offset" part
6703 of this special location descriptor must indicate the distance
6704 in bytes from the lowest-addressed byte of the containing struct
6705 or union type to the lowest-addressed byte of the "containing
6706 object" for the bit-field. (See the `field_byte_offset' function
6707 above).. For any given bit-field, the "containing object" is a
6708 hypothetical object (of some integral or enum type) within which
6709 the given bit-field lives. The type of this hypothetical
6710 "containing object" is always the same as the declared type of
6711 the individual bit-field itself (for GCC anyway... the DWARF
6712 spec doesn't actually mandate this). Note that it is the size
6713 (in bytes) of the hypothetical "containing object" which will
6714 be given in the DW_AT_byte_size attribute for this bit-field.
6715 (See the `byte_size_attribute' function below.) It is also used
6716 when calculating the value of the DW_AT_bit_offset attribute.
6717 (See the `bit_offset_attribute' function below). */
6720 add_data_member_location_attribute (die, decl)
6721 register dw_die_ref die;
6724 register unsigned long offset;
6725 register dw_loc_descr_ref loc_descr;
6726 register enum dwarf_location_atom op;
6728 if (TREE_CODE (decl) == TREE_VEC)
6729 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
6731 offset = field_byte_offset (decl);
6733 /* The DWARF2 standard says that we should assume that the structure address
6734 is already on the stack, so we can specify a structure field address
6735 by using DW_OP_plus_uconst. */
6737 #ifdef MIPS_DEBUGGING_INFO
6738 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6739 correctly. It works only if we leave the offset on the stack. */
6742 op = DW_OP_plus_uconst;
6745 loc_descr = new_loc_descr (op, offset, 0);
6746 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6749 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6750 does not have a "location" either in memory or in a register. These
6751 things can arise in GNU C when a constant is passed as an actual parameter
6752 to an inlined function. They can also arise in C++ where declared
6753 constants do not necessarily get memory "homes". */
6756 add_const_value_attribute (die, rtl)
6757 register dw_die_ref die;
6760 switch (GET_CODE (rtl))
6763 /* Note that a CONST_INT rtx could represent either an integer or a
6764 floating-point constant. A CONST_INT is used whenever the constant
6765 will fit into a single word. In all such cases, the original mode
6766 of the constant value is wiped out, and the CONST_INT rtx is
6767 assigned VOIDmode. */
6768 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6772 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6773 floating-point constant. A CONST_DOUBLE is used whenever the
6774 constant requires more than one word in order to be adequately
6775 represented. We output CONST_DOUBLEs as blocks. */
6777 register enum machine_mode mode = GET_MODE (rtl);
6779 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6781 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6785 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6789 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6793 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6798 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6805 add_AT_float (die, DW_AT_const_value, length, array);
6808 add_AT_long_long (die, DW_AT_const_value,
6809 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6814 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6820 add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
6824 /* In cases where an inlined instance of an inline function is passed
6825 the address of an `auto' variable (which is local to the caller) we
6826 can get a situation where the DECL_RTL of the artificial local
6827 variable (for the inlining) which acts as a stand-in for the
6828 corresponding formal parameter (of the inline function) will look
6829 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6830 exactly a compile-time constant expression, but it isn't the address
6831 of the (artificial) local variable either. Rather, it represents the
6832 *value* which the artificial local variable always has during its
6833 lifetime. We currently have no way to represent such quasi-constant
6834 values in Dwarf, so for now we just punt and generate nothing. */
6838 /* No other kinds of rtx should be possible here. */
6844 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6845 data attribute for a variable or a parameter. We generate the
6846 DW_AT_const_value attribute only in those cases where the given variable
6847 or parameter does not have a true "location" either in memory or in a
6848 register. This can happen (for example) when a constant is passed as an
6849 actual argument in a call to an inline function. (It's possible that
6850 these things can crop up in other ways also.) Note that one type of
6851 constant value which can be passed into an inlined function is a constant
6852 pointer. This can happen for example if an actual argument in an inlined
6853 function call evaluates to a compile-time constant address. */
6856 add_location_or_const_value_attribute (die, decl)
6857 register dw_die_ref die;
6861 register tree declared_type;
6862 register tree passed_type;
6864 if (TREE_CODE (decl) == ERROR_MARK)
6867 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6870 /* Here we have to decide where we are going to say the parameter "lives"
6871 (as far as the debugger is concerned). We only have a couple of
6872 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6874 DECL_RTL normally indicates where the parameter lives during most of the
6875 activation of the function. If optimization is enabled however, this
6876 could be either NULL or else a pseudo-reg. Both of those cases indicate
6877 that the parameter doesn't really live anywhere (as far as the code
6878 generation parts of GCC are concerned) during most of the function's
6879 activation. That will happen (for example) if the parameter is never
6880 referenced within the function.
6882 We could just generate a location descriptor here for all non-NULL
6883 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6884 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6885 where DECL_RTL is NULL or is a pseudo-reg.
6887 Note however that we can only get away with using DECL_INCOMING_RTL as
6888 a backup substitute for DECL_RTL in certain limited cases. In cases
6889 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6890 we can be sure that the parameter was passed using the same type as it is
6891 declared to have within the function, and that its DECL_INCOMING_RTL
6892 points us to a place where a value of that type is passed.
6894 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6895 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6896 because in these cases DECL_INCOMING_RTL points us to a value of some
6897 type which is *different* from the type of the parameter itself. Thus,
6898 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6899 such cases, the debugger would end up (for example) trying to fetch a
6900 `float' from a place which actually contains the first part of a
6901 `double'. That would lead to really incorrect and confusing
6902 output at debug-time.
6904 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6905 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6906 are a couple of exceptions however. On little-endian machines we can
6907 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6908 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6909 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6910 when (on a little-endian machine) a non-prototyped function has a
6911 parameter declared to be of type `short' or `char'. In such cases,
6912 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6913 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6914 passed `int' value. If the debugger then uses that address to fetch
6915 a `short' or a `char' (on a little-endian machine) the result will be
6916 the correct data, so we allow for such exceptional cases below.
6918 Note that our goal here is to describe the place where the given formal
6919 parameter lives during most of the function's activation (i.e. between
6920 the end of the prologue and the start of the epilogue). We'll do that
6921 as best as we can. Note however that if the given formal parameter is
6922 modified sometime during the execution of the function, then a stack
6923 backtrace (at debug-time) will show the function as having been
6924 called with the *new* value rather than the value which was
6925 originally passed in. This happens rarely enough that it is not
6926 a major problem, but it *is* a problem, and I'd like to fix it.
6928 A future version of dwarf2out.c may generate two additional
6929 attributes for any given DW_TAG_formal_parameter DIE which will
6930 describe the "passed type" and the "passed location" for the
6931 given formal parameter in addition to the attributes we now
6932 generate to indicate the "declared type" and the "active
6933 location" for each parameter. This additional set of attributes
6934 could be used by debuggers for stack backtraces. Separately, note
6935 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6936 NULL also. This happens (for example) for inlined-instances of
6937 inline function formal parameters which are never referenced.
6938 This really shouldn't be happening. All PARM_DECL nodes should
6939 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6940 doesn't currently generate these values for inlined instances of
6941 inline function parameters, so when we see such cases, we are
6942 just SOL (shit-out-of-luck) for the time being (until integrate.c
6945 /* Use DECL_RTL as the "location" unless we find something better. */
6946 rtl = DECL_RTL (decl);
6948 if (TREE_CODE (decl) == PARM_DECL)
6950 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
6952 declared_type = type_main_variant (TREE_TYPE (decl));
6953 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
6955 /* This decl represents a formal parameter which was optimized out.
6956 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
6957 all* cases where (rtl == NULL_RTX) just below. */
6958 if (declared_type == passed_type)
6959 rtl = DECL_INCOMING_RTL (decl);
6960 else if (! BYTES_BIG_ENDIAN
6961 && TREE_CODE (declared_type) == INTEGER_TYPE
6962 && TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
6963 rtl = DECL_INCOMING_RTL (decl);
6967 if (rtl == NULL_RTX)
6970 rtl = eliminate_regs (rtl, 0, NULL_RTX, 0);
6971 #ifdef LEAF_REG_REMAP
6973 leaf_renumber_regs_insn (rtl);
6976 switch (GET_CODE (rtl))
6979 /* The address of a variable that was optimized away; don't emit
6990 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
6991 add_const_value_attribute (die, rtl);
6998 add_AT_location_description (die, DW_AT_location, rtl);
7006 /* Generate an DW_AT_name attribute given some string value to be included as
7007 the value of the attribute. */
7010 add_name_attribute (die, name_string)
7011 register dw_die_ref die;
7012 register char *name_string;
7014 if (name_string != NULL && *name_string != 0)
7015 add_AT_string (die, DW_AT_name, name_string);
7018 /* Given a tree node describing an array bound (either lower or upper) output
7019 a representation for that bound. */
7022 add_bound_info (subrange_die, bound_attr, bound)
7023 register dw_die_ref subrange_die;
7024 register enum dwarf_attribute bound_attr;
7025 register tree bound;
7027 register unsigned bound_value = 0;
7029 /* If this is an Ada unconstrained array type, then don't emit any debug
7030 info because the array bounds are unknown. They are parameterized when
7031 the type is instantiated. */
7032 if (contains_placeholder_p (bound))
7035 switch (TREE_CODE (bound))
7040 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7042 bound_value = TREE_INT_CST_LOW (bound);
7043 if (bound_attr == DW_AT_lower_bound
7044 && ((is_c_family () && bound_value == 0)
7045 || (is_fortran () && bound_value == 1)))
7046 /* use the default */;
7048 add_AT_unsigned (subrange_die, bound_attr, bound_value);
7053 case NON_LVALUE_EXPR:
7054 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7058 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7059 access the upper bound values may be bogus. If they refer to a
7060 register, they may only describe how to get at these values at the
7061 points in the generated code right after they have just been
7062 computed. Worse yet, in the typical case, the upper bound values
7063 will not even *be* computed in the optimized code (though the
7064 number of elements will), so these SAVE_EXPRs are entirely
7065 bogus. In order to compensate for this fact, we check here to see
7066 if optimization is enabled, and if so, we don't add an attribute
7067 for the (unknown and unknowable) upper bound. This should not
7068 cause too much trouble for existing (stupid?) debuggers because
7069 they have to deal with empty upper bounds location descriptions
7070 anyway in order to be able to deal with incomplete array types.
7071 Of course an intelligent debugger (GDB?) should be able to
7072 comprehend that a missing upper bound specification in a array
7073 type used for a storage class `auto' local array variable
7074 indicates that the upper bound is both unknown (at compile- time)
7075 and unknowable (at run-time) due to optimization.
7077 We assume that a MEM rtx is safe because gcc wouldn't put the
7078 value there unless it was going to be used repeatedly in the
7079 function, i.e. for cleanups. */
7080 if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)
7082 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7083 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7084 add_AT_flag (decl_die, DW_AT_artificial, 1);
7085 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
7086 add_AT_location_description (decl_die, DW_AT_location,
7087 SAVE_EXPR_RTL (bound));
7088 add_AT_die_ref (subrange_die, bound_attr, decl_die);
7091 /* Else leave out the attribute. */
7096 /* ??? These types of bounds can be created by the Ada front end,
7097 and it isn't clear how to emit debug info for them. */
7105 /* Note that the block of subscript information for an array type also
7106 includes information about the element type of type given array type. */
7109 add_subscript_info (type_die, type)
7110 register dw_die_ref type_die;
7113 register unsigned dimension_number;
7114 register tree lower, upper;
7115 register dw_die_ref subrange_die;
7117 /* The GNU compilers represent multidimensional array types as sequences of
7118 one dimensional array types whose element types are themselves array
7119 types. Here we squish that down, so that each multidimensional array
7120 type gets only one array_type DIE in the Dwarf debugging info. The draft
7121 Dwarf specification say that we are allowed to do this kind of
7122 compression in C (because there is no difference between an array or
7123 arrays and a multidimensional array in C) but for other source languages
7124 (e.g. Ada) we probably shouldn't do this. */
7126 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7127 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7128 We work around this by disabling this feature. See also
7129 gen_array_type_die. */
7130 #ifndef MIPS_DEBUGGING_INFO
7131 for (dimension_number = 0;
7132 TREE_CODE (type) == ARRAY_TYPE;
7133 type = TREE_TYPE (type), dimension_number++)
7136 register tree domain = TYPE_DOMAIN (type);
7138 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7139 and (in GNU C only) variable bounds. Handle all three forms
7141 subrange_die = new_die (DW_TAG_subrange_type, type_die);
7144 /* We have an array type with specified bounds. */
7145 lower = TYPE_MIN_VALUE (domain);
7146 upper = TYPE_MAX_VALUE (domain);
7148 /* define the index type. */
7149 if (TREE_TYPE (domain))
7151 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7152 TREE_TYPE field. We can't emit debug info for this
7153 because it is an unnamed integral type. */
7154 if (TREE_CODE (domain) == INTEGER_TYPE
7155 && TYPE_NAME (domain) == NULL_TREE
7156 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
7157 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
7160 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
7164 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
7165 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
7168 /* We have an array type with an unspecified length. The DWARF-2
7169 spec does not say how to handle this; let's just leave out the
7173 #ifndef MIPS_DEBUGGING_INFO
7179 add_byte_size_attribute (die, tree_node)
7181 register tree tree_node;
7183 register unsigned size;
7185 switch (TREE_CODE (tree_node))
7193 case QUAL_UNION_TYPE:
7194 size = int_size_in_bytes (tree_node);
7197 /* For a data member of a struct or union, the DW_AT_byte_size is
7198 generally given as the number of bytes normally allocated for an
7199 object of the *declared* type of the member itself. This is true
7200 even for bit-fields. */
7201 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
7207 /* Note that `size' might be -1 when we get to this point. If it is, that
7208 indicates that the byte size of the entity in question is variable. We
7209 have no good way of expressing this fact in Dwarf at the present time,
7210 so just let the -1 pass on through. */
7212 add_AT_unsigned (die, DW_AT_byte_size, size);
7215 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7216 which specifies the distance in bits from the highest order bit of the
7217 "containing object" for the bit-field to the highest order bit of the
7220 For any given bit-field, the "containing object" is a hypothetical
7221 object (of some integral or enum type) within which the given bit-field
7222 lives. The type of this hypothetical "containing object" is always the
7223 same as the declared type of the individual bit-field itself. The
7224 determination of the exact location of the "containing object" for a
7225 bit-field is rather complicated. It's handled by the
7226 `field_byte_offset' function (above).
7228 Note that it is the size (in bytes) of the hypothetical "containing object"
7229 which will be given in the DW_AT_byte_size attribute for this bit-field.
7230 (See `byte_size_attribute' above). */
7233 add_bit_offset_attribute (die, decl)
7234 register dw_die_ref die;
7237 register unsigned object_offset_in_bytes = field_byte_offset (decl);
7238 register tree type = DECL_BIT_FIELD_TYPE (decl);
7239 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
7240 register unsigned bitpos_int;
7241 register unsigned highest_order_object_bit_offset;
7242 register unsigned highest_order_field_bit_offset;
7243 register unsigned bit_offset;
7245 /* Must be a field and a bit field. */
7247 || TREE_CODE (decl) != FIELD_DECL)
7250 /* We can't yet handle bit-fields whose offsets are variable, so if we
7251 encounter such things, just return without generating any attribute
7253 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
7256 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
7258 /* Note that the bit offset is always the distance (in bits) from the
7259 highest-order bit of the "containing object" to the highest-order bit of
7260 the bit-field itself. Since the "high-order end" of any object or field
7261 is different on big-endian and little-endian machines, the computation
7262 below must take account of these differences. */
7263 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
7264 highest_order_field_bit_offset = bitpos_int;
7266 if (! BYTES_BIG_ENDIAN)
7268 highest_order_field_bit_offset
7269 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
7271 highest_order_object_bit_offset += simple_type_size_in_bits (type);
7275 = (! BYTES_BIG_ENDIAN
7276 ? highest_order_object_bit_offset - highest_order_field_bit_offset
7277 : highest_order_field_bit_offset - highest_order_object_bit_offset);
7279 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
7282 /* For a FIELD_DECL node which represents a bit field, output an attribute
7283 which specifies the length in bits of the given field. */
7286 add_bit_size_attribute (die, decl)
7287 register dw_die_ref die;
7290 /* Must be a field and a bit field. */
7291 if (TREE_CODE (decl) != FIELD_DECL
7292 || ! DECL_BIT_FIELD_TYPE (decl))
7294 add_AT_unsigned (die, DW_AT_bit_size,
7295 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
7298 /* If the compiled language is ANSI C, then add a 'prototyped'
7299 attribute, if arg types are given for the parameters of a function. */
7302 add_prototyped_attribute (die, func_type)
7303 register dw_die_ref die;
7304 register tree func_type;
7306 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
7307 && TYPE_ARG_TYPES (func_type) != NULL)
7308 add_AT_flag (die, DW_AT_prototyped, 1);
7312 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7313 by looking in either the type declaration or object declaration
7317 add_abstract_origin_attribute (die, origin)
7318 register dw_die_ref die;
7319 register tree origin;
7321 dw_die_ref origin_die = NULL;
7322 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
7323 origin_die = lookup_decl_die (origin);
7324 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
7325 origin_die = lookup_type_die (origin);
7327 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
7330 /* We do not currently support the pure_virtual attribute. */
7333 add_pure_or_virtual_attribute (die, func_decl)
7334 register dw_die_ref die;
7335 register tree func_decl;
7337 if (DECL_VINDEX (func_decl))
7339 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7340 add_AT_loc (die, DW_AT_vtable_elem_location,
7341 new_loc_descr (DW_OP_constu,
7342 TREE_INT_CST_LOW (DECL_VINDEX (func_decl)),
7345 /* GNU extension: Record what type this method came from originally. */
7346 if (debug_info_level > DINFO_LEVEL_TERSE)
7347 add_AT_die_ref (die, DW_AT_containing_type,
7348 lookup_type_die (DECL_CONTEXT (func_decl)));
7352 /* Add source coordinate attributes for the given decl. */
7355 add_src_coords_attributes (die, decl)
7356 register dw_die_ref die;
7359 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
7361 add_AT_unsigned (die, DW_AT_decl_file, file_index);
7362 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7365 /* Add an DW_AT_name attribute and source coordinate attribute for the
7366 given decl, but only if it actually has a name. */
7369 add_name_and_src_coords_attributes (die, decl)
7370 register dw_die_ref die;
7373 register tree decl_name;
7375 decl_name = DECL_NAME (decl);
7376 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
7378 add_name_attribute (die, dwarf2_name (decl, 0));
7379 add_src_coords_attributes (die, decl);
7380 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
7381 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
7382 add_AT_string (die, DW_AT_MIPS_linkage_name,
7383 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
7387 /* Push a new declaration scope. */
7390 push_decl_scope (scope)
7393 /* Make room in the decl_scope_table, if necessary. */
7394 if (decl_scope_table_allocated == decl_scope_depth)
7396 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
7398 = (tree *) xrealloc (decl_scope_table,
7399 decl_scope_table_allocated * sizeof (tree));
7402 decl_scope_table[decl_scope_depth++] = scope;
7405 /* Return the DIE for the scope the immediately contains this declaration. */
7408 scope_die_for (t, context_die)
7410 register dw_die_ref context_die;
7412 register dw_die_ref scope_die = NULL;
7413 register tree containing_scope;
7414 register unsigned long i;
7416 /* Walk back up the declaration tree looking for a place to define
7418 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
7419 containing_scope = TYPE_CONTEXT (t);
7420 else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t))
7421 containing_scope = decl_class_context (t);
7423 containing_scope = DECL_CONTEXT (t);
7425 /* Function-local tags and functions get stuck in limbo until they are
7426 fixed up by decls_for_scope. */
7427 if (context_die == NULL && containing_scope != NULL_TREE
7428 && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t)))
7431 if (containing_scope == NULL_TREE)
7432 scope_die = comp_unit_die;
7435 for (i = decl_scope_depth, scope_die = context_die;
7436 i > 0 && decl_scope_table[i - 1] != containing_scope;
7437 scope_die = scope_die->die_parent, --i)
7442 if (scope_die != comp_unit_die
7443 || TREE_CODE_CLASS (TREE_CODE (containing_scope)) != 't')
7445 if (debug_info_level > DINFO_LEVEL_TERSE
7446 && !TREE_ASM_WRITTEN (containing_scope))
7454 /* Pop a declaration scope. */
7458 if (decl_scope_depth <= 0)
7463 /* Many forms of DIEs require a "type description" attribute. This
7464 routine locates the proper "type descriptor" die for the type given
7465 by 'type', and adds an DW_AT_type attribute below the given die. */
7468 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
7469 register dw_die_ref object_die;
7471 register int decl_const;
7472 register int decl_volatile;
7473 register dw_die_ref context_die;
7475 register enum tree_code code = TREE_CODE (type);
7476 register dw_die_ref type_die = NULL;
7478 /* ??? If this type is an unnamed subrange type of an integral or
7479 floating-point type, use the inner type. This is because we have no
7480 support for unnamed types in base_type_die. This can happen if this is
7481 an Ada subrange type. Correct solution is emit a subrange type die. */
7482 if ((code == INTEGER_TYPE || code == REAL_TYPE)
7483 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
7484 type = TREE_TYPE (type), code = TREE_CODE (type);
7486 if (code == ERROR_MARK)
7489 /* Handle a special case. For functions whose return type is void, we
7490 generate *no* type attribute. (Note that no object may have type
7491 `void', so this only applies to function return types). */
7492 if (code == VOID_TYPE)
7495 type_die = modified_type_die (type,
7496 decl_const || TYPE_READONLY (type),
7497 decl_volatile || TYPE_VOLATILE (type),
7499 if (type_die != NULL)
7500 add_AT_die_ref (object_die, DW_AT_type, type_die);
7503 /* Given a tree pointer to a struct, class, union, or enum type node, return
7504 a pointer to the (string) tag name for the given type, or zero if the type
7505 was declared without a tag. */
7511 register char *name = 0;
7513 if (TYPE_NAME (type) != 0)
7515 register tree t = 0;
7517 /* Find the IDENTIFIER_NODE for the type name. */
7518 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7519 t = TYPE_NAME (type);
7521 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7522 a TYPE_DECL node, regardless of whether or not a `typedef' was
7524 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7525 && ! DECL_IGNORED_P (TYPE_NAME (type)))
7526 t = DECL_NAME (TYPE_NAME (type));
7528 /* Now get the name as a string, or invent one. */
7530 name = IDENTIFIER_POINTER (t);
7533 return (name == 0 || *name == '\0') ? 0 : name;
7536 /* Return the type associated with a data member, make a special check
7537 for bit field types. */
7540 member_declared_type (member)
7541 register tree member;
7543 return (DECL_BIT_FIELD_TYPE (member)
7544 ? DECL_BIT_FIELD_TYPE (member)
7545 : TREE_TYPE (member));
7548 /* Get the decl's label, as described by its RTL. This may be different
7549 from the DECL_NAME name used in the source file. */
7552 decl_start_label (decl)
7557 x = DECL_RTL (decl);
7558 if (GET_CODE (x) != MEM)
7562 if (GET_CODE (x) != SYMBOL_REF)
7565 fnname = XSTR (x, 0);
7569 /* These routines generate the internnal representation of the DIE's for
7570 the compilation unit. Debugging information is collected by walking
7571 the declaration trees passed in from dwarf2out_decl(). */
7574 gen_array_type_die (type, context_die)
7576 register dw_die_ref context_die;
7578 register dw_die_ref scope_die = scope_die_for (type, context_die);
7579 register dw_die_ref array_die;
7580 register tree element_type;
7582 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7583 the inner array type comes before the outer array type. Thus we must
7584 call gen_type_die before we call new_die. See below also. */
7585 #ifdef MIPS_DEBUGGING_INFO
7586 gen_type_die (TREE_TYPE (type), context_die);
7589 array_die = new_die (DW_TAG_array_type, scope_die);
7592 /* We default the array ordering. SDB will probably do
7593 the right things even if DW_AT_ordering is not present. It's not even
7594 an issue until we start to get into multidimensional arrays anyway. If
7595 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7596 then we'll have to put the DW_AT_ordering attribute back in. (But if
7597 and when we find out that we need to put these in, we will only do so
7598 for multidimensional arrays. */
7599 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
7602 #ifdef MIPS_DEBUGGING_INFO
7603 /* The SGI compilers handle arrays of unknown bound by setting
7604 AT_declaration and not emitting any subrange DIEs. */
7605 if (! TYPE_DOMAIN (type))
7606 add_AT_unsigned (array_die, DW_AT_declaration, 1);
7609 add_subscript_info (array_die, type);
7611 equate_type_number_to_die (type, array_die);
7613 /* Add representation of the type of the elements of this array type. */
7614 element_type = TREE_TYPE (type);
7616 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7617 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7618 We work around this by disabling this feature. See also
7619 add_subscript_info. */
7620 #ifndef MIPS_DEBUGGING_INFO
7621 while (TREE_CODE (element_type) == ARRAY_TYPE)
7622 element_type = TREE_TYPE (element_type);
7624 gen_type_die (element_type, context_die);
7627 add_type_attribute (array_die, element_type, 0, 0, context_die);
7631 gen_set_type_die (type, context_die)
7633 register dw_die_ref context_die;
7635 register dw_die_ref type_die
7636 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7638 equate_type_number_to_die (type, type_die);
7639 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7643 gen_entry_point_die (decl, context_die)
7645 register dw_die_ref context_die;
7647 register tree origin = decl_ultimate_origin (decl);
7648 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
7650 add_abstract_origin_attribute (decl_die, origin);
7653 add_name_and_src_coords_attributes (decl_die, decl);
7654 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
7658 if (DECL_ABSTRACT (decl))
7659 equate_decl_number_to_die (decl, decl_die);
7661 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
7664 /* Remember a type in the pending_types_list. */
7670 if (pending_types == pending_types_allocated)
7672 pending_types_allocated += PENDING_TYPES_INCREMENT;
7674 = (tree *) xrealloc (pending_types_list,
7675 sizeof (tree) * pending_types_allocated);
7678 pending_types_list[pending_types++] = type;
7681 /* Output any pending types (from the pending_types list) which we can output
7682 now (taking into account the scope that we are working on now).
7684 For each type output, remove the given type from the pending_types_list
7685 *before* we try to output it. */
7688 output_pending_types_for_scope (context_die)
7689 register dw_die_ref context_die;
7693 while (pending_types)
7696 type = pending_types_list[pending_types];
7697 gen_type_die (type, context_die);
7698 if (!TREE_ASM_WRITTEN (type))
7703 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7706 gen_inlined_enumeration_type_die (type, context_die)
7708 register dw_die_ref context_die;
7710 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
7711 scope_die_for (type, context_die));
7713 if (!TREE_ASM_WRITTEN (type))
7715 add_abstract_origin_attribute (type_die, type);
7718 /* Generate a DIE to represent an inlined instance of a structure type. */
7721 gen_inlined_structure_type_die (type, context_die)
7723 register dw_die_ref context_die;
7725 register dw_die_ref type_die = new_die (DW_TAG_structure_type,
7726 scope_die_for (type, context_die));
7728 if (!TREE_ASM_WRITTEN (type))
7730 add_abstract_origin_attribute (type_die, type);
7733 /* Generate a DIE to represent an inlined instance of a union type. */
7736 gen_inlined_union_type_die (type, context_die)
7738 register dw_die_ref context_die;
7740 register dw_die_ref type_die = new_die (DW_TAG_union_type,
7741 scope_die_for (type, context_die));
7743 if (!TREE_ASM_WRITTEN (type))
7745 add_abstract_origin_attribute (type_die, type);
7748 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7749 include all of the information about the enumeration values also. Each
7750 enumerated type name/value is listed as a child of the enumerated type
7754 gen_enumeration_type_die (type, context_die)
7756 register dw_die_ref context_die;
7758 register dw_die_ref type_die = lookup_type_die (type);
7760 if (type_die == NULL)
7762 type_die = new_die (DW_TAG_enumeration_type,
7763 scope_die_for (type, context_die));
7764 equate_type_number_to_die (type, type_die);
7765 add_name_attribute (type_die, type_tag (type));
7767 else if (! TYPE_SIZE (type))
7770 remove_AT (type_die, DW_AT_declaration);
7772 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7773 given enum type is incomplete, do not generate the DW_AT_byte_size
7774 attribute or the DW_AT_element_list attribute. */
7775 if (TYPE_SIZE (type))
7779 TREE_ASM_WRITTEN (type) = 1;
7780 add_byte_size_attribute (type_die, type);
7781 if (TYPE_STUB_DECL (type) != NULL_TREE)
7782 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
7784 /* If the first reference to this type was as the return type of an
7785 inline function, then it may not have a parent. Fix this now. */
7786 if (type_die->die_parent == NULL)
7787 add_child_die (scope_die_for (type, context_die), type_die);
7789 for (link = TYPE_FIELDS (type);
7790 link != NULL; link = TREE_CHAIN (link))
7792 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
7794 add_name_attribute (enum_die,
7795 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
7796 add_AT_unsigned (enum_die, DW_AT_const_value,
7797 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
7801 add_AT_flag (type_die, DW_AT_declaration, 1);
7805 /* Generate a DIE to represent either a real live formal parameter decl or to
7806 represent just the type of some formal parameter position in some function
7809 Note that this routine is a bit unusual because its argument may be a
7810 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7811 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7812 node. If it's the former then this function is being called to output a
7813 DIE to represent a formal parameter object (or some inlining thereof). If
7814 it's the latter, then this function is only being called to output a
7815 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7816 argument type of some subprogram type. */
7819 gen_formal_parameter_die (node, context_die)
7821 register dw_die_ref context_die;
7823 register dw_die_ref parm_die
7824 = new_die (DW_TAG_formal_parameter, context_die);
7825 register tree origin;
7827 switch (TREE_CODE_CLASS (TREE_CODE (node)))
7830 origin = decl_ultimate_origin (node);
7832 add_abstract_origin_attribute (parm_die, origin);
7835 add_name_and_src_coords_attributes (parm_die, node);
7836 add_type_attribute (parm_die, TREE_TYPE (node),
7837 TREE_READONLY (node),
7838 TREE_THIS_VOLATILE (node),
7840 if (DECL_ARTIFICIAL (node))
7841 add_AT_flag (parm_die, DW_AT_artificial, 1);
7844 equate_decl_number_to_die (node, parm_die);
7845 if (! DECL_ABSTRACT (node))
7846 add_location_or_const_value_attribute (parm_die, node);
7851 /* We were called with some kind of a ..._TYPE node. */
7852 add_type_attribute (parm_die, node, 0, 0, context_die);
7862 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
7863 at the end of an (ANSI prototyped) formal parameters list. */
7866 gen_unspecified_parameters_die (decl_or_type, context_die)
7867 register tree decl_or_type;
7868 register dw_die_ref context_die;
7870 register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters,
7874 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
7875 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
7876 parameters as specified in some function type specification (except for
7877 those which appear as part of a function *definition*).
7879 Note we must be careful here to output all of the parameter DIEs before*
7880 we output any DIEs needed to represent the types of the formal parameters.
7881 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
7882 non-parameter DIE it sees ends the formal parameter list. */
7885 gen_formal_types_die (function_or_method_type, context_die)
7886 register tree function_or_method_type;
7887 register dw_die_ref context_die;
7890 register tree formal_type = NULL;
7891 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
7894 /* In the case where we are generating a formal types list for a C++
7895 non-static member function type, skip over the first thing on the
7896 TYPE_ARG_TYPES list because it only represents the type of the hidden
7897 `this pointer'. The debugger should be able to figure out (without
7898 being explicitly told) that this non-static member function type takes a
7899 `this pointer' and should be able to figure what the type of that hidden
7900 parameter is from the DW_AT_member attribute of the parent
7901 DW_TAG_subroutine_type DIE. */
7902 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
7903 first_parm_type = TREE_CHAIN (first_parm_type);
7906 /* Make our first pass over the list of formal parameter types and output a
7907 DW_TAG_formal_parameter DIE for each one. */
7908 for (link = first_parm_type; link; link = TREE_CHAIN (link))
7910 register dw_die_ref parm_die;
7912 formal_type = TREE_VALUE (link);
7913 if (formal_type == void_type_node)
7916 /* Output a (nameless) DIE to represent the formal parameter itself. */
7917 parm_die = gen_formal_parameter_die (formal_type, context_die);
7918 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
7919 && link == first_parm_type)
7920 add_AT_flag (parm_die, DW_AT_artificial, 1);
7923 /* If this function type has an ellipsis, add a
7924 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
7925 if (formal_type != void_type_node)
7926 gen_unspecified_parameters_die (function_or_method_type, context_die);
7928 /* Make our second (and final) pass over the list of formal parameter types
7929 and output DIEs to represent those types (as necessary). */
7930 for (link = TYPE_ARG_TYPES (function_or_method_type);
7932 link = TREE_CHAIN (link))
7934 formal_type = TREE_VALUE (link);
7935 if (formal_type == void_type_node)
7938 gen_type_die (formal_type, context_die);
7942 /* Generate a DIE to represent a declared function (either file-scope or
7946 gen_subprogram_die (decl, context_die)
7948 register dw_die_ref context_die;
7950 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
7951 register tree origin = decl_ultimate_origin (decl);
7952 register dw_die_ref subr_die;
7953 register dw_loc_descr_ref fp_loc = NULL;
7954 register rtx fp_reg;
7955 register tree fn_arg_types;
7956 register tree outer_scope;
7957 register dw_die_ref old_die = lookup_decl_die (decl);
7958 register int declaration
7959 = (current_function_decl != decl
7961 && (context_die->die_tag == DW_TAG_structure_type
7962 || context_die->die_tag == DW_TAG_union_type)));
7966 subr_die = new_die (DW_TAG_subprogram, context_die);
7967 add_abstract_origin_attribute (subr_die, origin);
7969 else if (old_die && DECL_ABSTRACT (decl)
7970 && get_AT_unsigned (old_die, DW_AT_inline))
7972 /* This must be a redefinition of an extern inline function.
7973 We can just reuse the old die here. */
7976 /* Clear out the inlined attribute and parm types. */
7977 remove_AT (subr_die, DW_AT_inline);
7978 remove_children (subr_die);
7982 register unsigned file_index
7983 = lookup_filename (DECL_SOURCE_FILE (decl));
7985 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
7988 /* If the definition comes from the same place as the declaration,
7989 maybe use the old DIE. We always want the DIE for this function
7990 that has the *_pc attributes to be under comp_unit_die so the
7991 debugger can find it. For inlines, that is the concrete instance,
7992 so we can use the old DIE here. For non-inline methods, we want a
7993 specification DIE at toplevel, so we need a new DIE. For local
7994 class methods, this does not apply. */
7995 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
7996 || context_die == NULL)
7997 && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
7998 && (get_AT_unsigned (old_die, DW_AT_decl_line)
7999 == DECL_SOURCE_LINE (decl)))
8003 /* Clear out the declaration attribute and the parm types. */
8004 remove_AT (subr_die, DW_AT_declaration);
8005 remove_children (subr_die);
8009 subr_die = new_die (DW_TAG_subprogram, context_die);
8010 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
8011 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8012 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
8013 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8014 != DECL_SOURCE_LINE (decl))
8016 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8021 register dw_die_ref scope_die;
8023 if (DECL_CONTEXT (decl))
8024 scope_die = scope_die_for (decl, context_die);
8026 /* Don't put block extern declarations under comp_unit_die. */
8027 scope_die = context_die;
8029 subr_die = new_die (DW_TAG_subprogram, scope_die);
8031 if (TREE_PUBLIC (decl))
8032 add_AT_flag (subr_die, DW_AT_external, 1);
8034 add_name_and_src_coords_attributes (subr_die, decl);
8035 if (debug_info_level > DINFO_LEVEL_TERSE)
8037 register tree type = TREE_TYPE (decl);
8039 add_prototyped_attribute (subr_die, type);
8040 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
8043 add_pure_or_virtual_attribute (subr_die, decl);
8044 if (DECL_ARTIFICIAL (decl))
8045 add_AT_flag (subr_die, DW_AT_artificial, 1);
8046 if (TREE_PROTECTED (decl))
8047 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
8048 else if (TREE_PRIVATE (decl))
8049 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
8054 add_AT_flag (subr_die, DW_AT_declaration, 1);
8056 /* The first time we see a member function, it is in the context of
8057 the class to which it belongs. We make sure of this by emitting
8058 the class first. The next time is the definition, which is
8059 handled above. The two may come from the same source text. */
8060 if (DECL_CONTEXT (decl))
8061 equate_decl_number_to_die (decl, subr_die);
8063 else if (DECL_ABSTRACT (decl))
8065 /* ??? Checking DECL_DEFER_OUTPUT is correct for static inline functions,
8066 but not for extern inline functions. We can't get this completely
8067 correct because information about whether the function was declared
8068 inline is not saved anywhere. */
8069 if (DECL_DEFER_OUTPUT (decl))
8071 if (DECL_INLINE (decl))
8072 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
8074 add_AT_unsigned (subr_die, DW_AT_inline,
8075 DW_INL_declared_not_inlined);
8077 else if (DECL_INLINE (decl))
8078 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
8082 equate_decl_number_to_die (decl, subr_die);
8084 else if (!DECL_EXTERNAL (decl))
8086 if (origin == NULL_TREE)
8087 equate_decl_number_to_die (decl, subr_die);
8089 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
8090 current_funcdef_number);
8091 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
8092 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
8093 current_funcdef_number);
8094 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
8096 add_pubname (decl, subr_die);
8097 add_arange (decl, subr_die);
8099 #ifdef MIPS_DEBUGGING_INFO
8100 /* Add a reference to the FDE for this routine. */
8101 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
8104 /* Define the "frame base" location for this routine. We use the
8105 frame pointer or stack pointer registers, since the RTL for local
8106 variables is relative to one of them. */
8108 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
8109 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
8112 /* ??? This fails for nested inline functions, because context_display
8113 is not part of the state saved/restored for inline functions. */
8114 if (current_function_needs_context)
8115 add_AT_location_description (subr_die, DW_AT_static_link,
8116 lookup_static_chain (decl));
8120 /* Now output descriptions of the arguments for this function. This gets
8121 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8122 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8123 `...' at the end of the formal parameter list. In order to find out if
8124 there was a trailing ellipsis or not, we must instead look at the type
8125 associated with the FUNCTION_DECL. This will be a node of type
8126 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8127 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8128 an ellipsis at the end. */
8129 push_decl_scope (decl);
8131 /* In the case where we are describing a mere function declaration, all we
8132 need to do here (and all we *can* do here) is to describe the *types* of
8133 its formal parameters. */
8134 if (debug_info_level <= DINFO_LEVEL_TERSE)
8136 else if (declaration)
8137 gen_formal_types_die (TREE_TYPE (decl), subr_die);
8140 /* Generate DIEs to represent all known formal parameters */
8141 register tree arg_decls = DECL_ARGUMENTS (decl);
8144 /* When generating DIEs, generate the unspecified_parameters DIE
8145 instead if we come across the arg "__builtin_va_alist" */
8146 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
8147 if (TREE_CODE (parm) == PARM_DECL)
8149 if (DECL_NAME (parm)
8150 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
8151 "__builtin_va_alist"))
8152 gen_unspecified_parameters_die (parm, subr_die);
8154 gen_decl_die (parm, subr_die);
8157 /* Decide whether we need a unspecified_parameters DIE at the end.
8158 There are 2 more cases to do this for: 1) the ansi ... declaration -
8159 this is detectable when the end of the arg list is not a
8160 void_type_node 2) an unprototyped function declaration (not a
8161 definition). This just means that we have no info about the
8162 parameters at all. */
8163 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
8164 if (fn_arg_types != NULL)
8166 /* this is the prototyped case, check for ... */
8167 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
8168 gen_unspecified_parameters_die (decl, subr_die);
8170 else if (DECL_INITIAL (decl) == NULL_TREE)
8171 gen_unspecified_parameters_die (decl, subr_die);
8174 /* Output Dwarf info for all of the stuff within the body of the function
8175 (if it has one - it may be just a declaration). */
8176 outer_scope = DECL_INITIAL (decl);
8178 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8179 node created to represent a function. This outermost BLOCK actually
8180 represents the outermost binding contour for the function, i.e. the
8181 contour in which the function's formal parameters and labels get
8182 declared. Curiously, it appears that the front end doesn't actually
8183 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8184 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8185 list for the function instead.) The BLOCK_VARS list for the
8186 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8187 the function however, and we output DWARF info for those in
8188 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8189 node representing the function's outermost pair of curly braces, and
8190 any blocks used for the base and member initializers of a C++
8191 constructor function. */
8192 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
8194 current_function_has_inlines = 0;
8195 decls_for_scope (outer_scope, subr_die, 0);
8197 #if 0 && defined (MIPS_DEBUGGING_INFO)
8198 if (current_function_has_inlines)
8200 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
8201 if (! comp_unit_has_inlines)
8203 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
8204 comp_unit_has_inlines = 1;
8213 /* Generate a DIE to represent a declared data object. */
8216 gen_variable_die (decl, context_die)
8218 register dw_die_ref context_die;
8220 register tree origin = decl_ultimate_origin (decl);
8221 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
8223 dw_die_ref old_die = lookup_decl_die (decl);
8225 = (DECL_EXTERNAL (decl)
8226 || current_function_decl != decl_function_context (decl)
8227 || context_die->die_tag == DW_TAG_structure_type
8228 || context_die->die_tag == DW_TAG_union_type);
8231 add_abstract_origin_attribute (var_die, origin);
8232 /* Loop unrolling can create multiple blocks that refer to the same
8233 static variable, so we must test for the DW_AT_declaration flag. */
8234 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8235 copy decls and set the DECL_ABSTRACT flag on them instead of
8237 else if (old_die && TREE_STATIC (decl)
8238 && get_AT_flag (old_die, DW_AT_declaration) == 1)
8240 /* ??? This is an instantiation of a C++ class level static. */
8241 add_AT_die_ref (var_die, DW_AT_specification, old_die);
8242 if (DECL_NAME (decl))
8244 register unsigned file_index
8245 = lookup_filename (DECL_SOURCE_FILE (decl));
8247 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8248 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
8250 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8251 != DECL_SOURCE_LINE (decl))
8253 add_AT_unsigned (var_die, DW_AT_decl_line,
8254 DECL_SOURCE_LINE (decl));
8259 add_name_and_src_coords_attributes (var_die, decl);
8260 add_type_attribute (var_die, TREE_TYPE (decl),
8261 TREE_READONLY (decl),
8262 TREE_THIS_VOLATILE (decl), context_die);
8264 if (TREE_PUBLIC (decl))
8265 add_AT_flag (var_die, DW_AT_external, 1);
8267 if (DECL_ARTIFICIAL (decl))
8268 add_AT_flag (var_die, DW_AT_artificial, 1);
8270 if (TREE_PROTECTED (decl))
8271 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
8273 else if (TREE_PRIVATE (decl))
8274 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
8278 add_AT_flag (var_die, DW_AT_declaration, 1);
8280 if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl))
8281 equate_decl_number_to_die (decl, var_die);
8283 if (! declaration && ! DECL_ABSTRACT (decl))
8285 equate_decl_number_to_die (decl, var_die);
8286 add_location_or_const_value_attribute (var_die, decl);
8287 add_pubname (decl, var_die);
8291 /* Generate a DIE to represent a label identifier. */
8294 gen_label_die (decl, context_die)
8296 register dw_die_ref context_die;
8298 register tree origin = decl_ultimate_origin (decl);
8299 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
8301 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8302 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
8305 add_abstract_origin_attribute (lbl_die, origin);
8307 add_name_and_src_coords_attributes (lbl_die, decl);
8309 if (DECL_ABSTRACT (decl))
8310 equate_decl_number_to_die (decl, lbl_die);
8313 insn = DECL_RTL (decl);
8314 if (GET_CODE (insn) == CODE_LABEL)
8316 /* When optimization is enabled (via -O) some parts of the compiler
8317 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8318 represent source-level labels which were explicitly declared by
8319 the user. This really shouldn't be happening though, so catch
8320 it if it ever does happen. */
8321 if (INSN_DELETED_P (insn))
8324 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
8325 ASM_GENERATE_INTERNAL_LABEL (label, label2,
8326 (unsigned) INSN_UID (insn));
8327 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
8332 /* Generate a DIE for a lexical block. */
8335 gen_lexical_block_die (stmt, context_die, depth)
8337 register dw_die_ref context_die;
8340 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
8341 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8343 if (! BLOCK_ABSTRACT (stmt))
8345 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8347 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
8348 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
8349 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
8352 push_decl_scope (stmt);
8353 decls_for_scope (stmt, stmt_die, depth);
8357 /* Generate a DIE for an inlined subprogram. */
8360 gen_inlined_subroutine_die (stmt, context_die, depth)
8362 register dw_die_ref context_die;
8365 if (! BLOCK_ABSTRACT (stmt))
8367 register dw_die_ref subr_die
8368 = new_die (DW_TAG_inlined_subroutine, context_die);
8369 register tree decl = block_ultimate_origin (stmt);
8370 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8372 add_abstract_origin_attribute (subr_die, decl);
8373 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8375 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
8376 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
8377 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
8378 push_decl_scope (decl);
8379 decls_for_scope (stmt, subr_die, depth);
8381 current_function_has_inlines = 1;
8385 /* Generate a DIE for a field in a record, or structure. */
8388 gen_field_die (decl, context_die)
8390 register dw_die_ref context_die;
8392 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
8394 add_name_and_src_coords_attributes (decl_die, decl);
8395 add_type_attribute (decl_die, member_declared_type (decl),
8396 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
8399 /* If this is a bit field... */
8400 if (DECL_BIT_FIELD_TYPE (decl))
8402 add_byte_size_attribute (decl_die, decl);
8403 add_bit_size_attribute (decl_die, decl);
8404 add_bit_offset_attribute (decl_die, decl);
8407 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
8408 add_data_member_location_attribute (decl_die, decl);
8410 if (DECL_ARTIFICIAL (decl))
8411 add_AT_flag (decl_die, DW_AT_artificial, 1);
8413 if (TREE_PROTECTED (decl))
8414 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
8416 else if (TREE_PRIVATE (decl))
8417 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
8421 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8422 Use modified_type_die instead.
8423 We keep this code here just in case these types of DIEs may be needed to
8424 represent certain things in other languages (e.g. Pascal) someday. */
8426 gen_pointer_type_die (type, context_die)
8428 register dw_die_ref context_die;
8430 register dw_die_ref ptr_die
8431 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
8433 equate_type_number_to_die (type, ptr_die);
8434 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8435 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8438 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8439 Use modified_type_die instead.
8440 We keep this code here just in case these types of DIEs may be needed to
8441 represent certain things in other languages (e.g. Pascal) someday. */
8443 gen_reference_type_die (type, context_die)
8445 register dw_die_ref context_die;
8447 register dw_die_ref ref_die
8448 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
8450 equate_type_number_to_die (type, ref_die);
8451 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
8452 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8456 /* Generate a DIE for a pointer to a member type. */
8458 gen_ptr_to_mbr_type_die (type, context_die)
8460 register dw_die_ref context_die;
8462 register dw_die_ref ptr_die
8463 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8465 equate_type_number_to_die (type, ptr_die);
8466 add_AT_die_ref (ptr_die, DW_AT_containing_type,
8467 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
8468 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8471 /* Generate the DIE for the compilation unit. */
8474 gen_compile_unit_die (main_input_filename)
8475 register char *main_input_filename;
8478 char *wd = getpwd ();
8480 comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
8481 add_name_attribute (comp_unit_die, main_input_filename);
8484 add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
8486 sprintf (producer, "%s %s", language_string, version_string);
8488 #ifdef MIPS_DEBUGGING_INFO
8489 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8490 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8491 not appear in the producer string, the debugger reaches the conclusion
8492 that the object file is stripped and has no debugging information.
8493 To get the MIPS/SGI debugger to believe that there is debugging
8494 information in the object file, we add a -g to the producer string. */
8495 if (debug_info_level > DINFO_LEVEL_TERSE)
8496 strcat (producer, " -g");
8499 add_AT_string (comp_unit_die, DW_AT_producer, producer);
8501 if (strcmp (language_string, "GNU C++") == 0)
8502 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
8504 else if (strcmp (language_string, "GNU Ada") == 0)
8505 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
8507 else if (strcmp (language_string, "GNU F77") == 0)
8508 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77);
8510 else if (strcmp (language_string, "GNU Pascal") == 0)
8511 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Pascal83);
8513 else if (flag_traditional)
8514 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
8517 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
8519 #if 0 /* unimplemented */
8520 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
8521 add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
8525 /* Generate a DIE for a string type. */
8528 gen_string_type_die (type, context_die)
8530 register dw_die_ref context_die;
8532 register dw_die_ref type_die
8533 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
8535 equate_type_number_to_die (type, type_die);
8537 /* Fudge the string length attribute for now. */
8539 /* TODO: add string length info.
8540 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8541 bound_representation (upper_bound, 0, 'u'); */
8544 /* Generate the DIE for a base class. */
8547 gen_inheritance_die (binfo, context_die)
8548 register tree binfo;
8549 register dw_die_ref context_die;
8551 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
8553 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
8554 add_data_member_location_attribute (die, binfo);
8556 if (TREE_VIA_VIRTUAL (binfo))
8557 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8558 if (TREE_VIA_PUBLIC (binfo))
8559 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
8560 else if (TREE_VIA_PROTECTED (binfo))
8561 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
8564 /* Genearate a DIE for a class member. */
8567 gen_member_die (type, context_die)
8569 register dw_die_ref context_die;
8571 register tree member;
8573 /* If this is not an incomplete type, output descriptions of each of its
8574 members. Note that as we output the DIEs necessary to represent the
8575 members of this record or union type, we will also be trying to output
8576 DIEs to represent the *types* of those members. However the `type'
8577 function (above) will specifically avoid generating type DIEs for member
8578 types *within* the list of member DIEs for this (containing) type execpt
8579 for those types (of members) which are explicitly marked as also being
8580 members of this (containing) type themselves. The g++ front- end can
8581 force any given type to be treated as a member of some other
8582 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8583 to point to the TREE node representing the appropriate (containing)
8586 /* First output info about the base classes. */
8587 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
8589 register tree bases = TYPE_BINFO_BASETYPES (type);
8590 register int n_bases = TREE_VEC_LENGTH (bases);
8593 for (i = 0; i < n_bases; i++)
8594 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
8597 /* Now output info about the data members and type members. */
8598 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
8599 gen_decl_die (member, context_die);
8601 /* Now output info about the function members (if any). */
8602 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
8603 gen_decl_die (member, context_die);
8606 /* Generate a DIE for a structure or union type. */
8609 gen_struct_or_union_type_die (type, context_die)
8611 register dw_die_ref context_die;
8613 register dw_die_ref type_die = lookup_type_die (type);
8614 register dw_die_ref scope_die = 0;
8615 register int nested = 0;
8617 if (type_die && ! TYPE_SIZE (type))
8620 if (TYPE_CONTEXT (type) != NULL_TREE
8621 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't')
8624 scope_die = scope_die_for (type, context_die);
8626 if (! type_die || (nested && scope_die == comp_unit_die))
8627 /* First occurrence of type or toplevel definition of nested class. */
8629 register dw_die_ref old_die = type_die;
8631 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
8632 ? DW_TAG_structure_type : DW_TAG_union_type,
8634 equate_type_number_to_die (type, type_die);
8635 add_name_attribute (type_die, type_tag (type));
8637 add_AT_die_ref (type_die, DW_AT_specification, old_die);
8640 remove_AT (type_die, DW_AT_declaration);
8642 /* If we're not in the right context to be defining this type, defer to
8643 avoid tricky recursion. */
8644 if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die)
8646 add_AT_flag (type_die, DW_AT_declaration, 1);
8649 /* If this type has been completed, then give it a byte_size attribute and
8650 then give a list of members. */
8651 else if (TYPE_SIZE (type))
8653 /* Prevent infinite recursion in cases where the type of some member of
8654 this type is expressed in terms of this type itself. */
8655 TREE_ASM_WRITTEN (type) = 1;
8656 add_byte_size_attribute (type_die, type);
8657 if (TYPE_STUB_DECL (type) != NULL_TREE)
8658 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8660 /* If the first reference to this type was as the return type of an
8661 inline function, then it may not have a parent. Fix this now. */
8662 if (type_die->die_parent == NULL)
8663 add_child_die (scope_die, type_die);
8665 push_decl_scope (type);
8666 gen_member_die (type, type_die);
8669 /* GNU extension: Record what type our vtable lives in. */
8670 if (TYPE_VFIELD (type))
8672 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
8674 gen_type_die (vtype, context_die);
8675 add_AT_die_ref (type_die, DW_AT_containing_type,
8676 lookup_type_die (vtype));
8680 add_AT_flag (type_die, DW_AT_declaration, 1);
8683 /* Generate a DIE for a subroutine _type_. */
8686 gen_subroutine_type_die (type, context_die)
8688 register dw_die_ref context_die;
8690 register tree return_type = TREE_TYPE (type);
8691 register dw_die_ref subr_die
8692 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
8694 equate_type_number_to_die (type, subr_die);
8695 add_prototyped_attribute (subr_die, type);
8696 add_type_attribute (subr_die, return_type, 0, 0, context_die);
8697 gen_formal_types_die (type, subr_die);
8700 /* Generate a DIE for a type definition */
8703 gen_typedef_die (decl, context_die)
8705 register dw_die_ref context_die;
8707 register dw_die_ref type_die;
8708 register tree origin;
8710 if (TREE_ASM_WRITTEN (decl))
8712 TREE_ASM_WRITTEN (decl) = 1;
8714 type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
8715 origin = decl_ultimate_origin (decl);
8717 add_abstract_origin_attribute (type_die, origin);
8721 add_name_and_src_coords_attributes (type_die, decl);
8722 if (DECL_ORIGINAL_TYPE (decl))
8724 type = DECL_ORIGINAL_TYPE (decl);
8725 equate_type_number_to_die (TREE_TYPE (decl), type_die);
8728 type = TREE_TYPE (decl);
8729 add_type_attribute (type_die, type, TREE_READONLY (decl),
8730 TREE_THIS_VOLATILE (decl), context_die);
8733 if (DECL_ABSTRACT (decl))
8734 equate_decl_number_to_die (decl, type_die);
8737 /* Generate a type description DIE. */
8740 gen_type_die (type, context_die)
8742 register dw_die_ref context_die;
8744 if (type == NULL_TREE || type == error_mark_node)
8747 /* We are going to output a DIE to represent the unqualified version of of
8748 this type (i.e. without any const or volatile qualifiers) so get the
8749 main variant (i.e. the unqualified version) of this type now. */
8750 type = type_main_variant (type);
8752 if (TREE_ASM_WRITTEN (type))
8755 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8756 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
8758 TREE_ASM_WRITTEN (type) = 1;
8759 gen_decl_die (TYPE_NAME (type), context_die);
8763 switch (TREE_CODE (type))
8769 case REFERENCE_TYPE:
8770 /* For these types, all that is required is that we output a DIE (or a
8771 set of DIEs) to represent the "basis" type. */
8772 gen_type_die (TREE_TYPE (type), context_die);
8776 /* This code is used for C++ pointer-to-data-member types.
8777 Output a description of the relevant class type. */
8778 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
8780 /* Output a description of the type of the object pointed to. */
8781 gen_type_die (TREE_TYPE (type), context_die);
8783 /* Now output a DIE to represent this pointer-to-data-member type
8785 gen_ptr_to_mbr_type_die (type, context_die);
8789 gen_type_die (TYPE_DOMAIN (type), context_die);
8790 gen_set_type_die (type, context_die);
8794 gen_type_die (TREE_TYPE (type), context_die);
8795 abort (); /* No way to represent these in Dwarf yet! */
8799 /* Force out return type (in case it wasn't forced out already). */
8800 gen_type_die (TREE_TYPE (type), context_die);
8801 gen_subroutine_type_die (type, context_die);
8805 /* Force out return type (in case it wasn't forced out already). */
8806 gen_type_die (TREE_TYPE (type), context_die);
8807 gen_subroutine_type_die (type, context_die);
8811 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
8813 gen_type_die (TREE_TYPE (type), context_die);
8814 gen_string_type_die (type, context_die);
8817 gen_array_type_die (type, context_die);
8823 case QUAL_UNION_TYPE:
8824 /* If this is a nested type whose containing class hasn't been
8825 written out yet, writing it out will cover this one, too. */
8826 if (TYPE_CONTEXT (type)
8827 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
8828 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8830 gen_type_die (TYPE_CONTEXT (type), context_die);
8832 if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8835 /* If that failed, attach ourselves to the stub. */
8836 push_decl_scope (TYPE_CONTEXT (type));
8837 context_die = lookup_type_die (TYPE_CONTEXT (type));
8840 if (TREE_CODE (type) == ENUMERAL_TYPE)
8841 gen_enumeration_type_die (type, context_die);
8843 gen_struct_or_union_type_die (type, context_die);
8845 if (TYPE_CONTEXT (type)
8846 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
8847 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8850 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
8851 it up if it is ever completed. gen_*_type_die will set it for us
8852 when appropriate. */
8861 /* No DIEs needed for fundamental types. */
8865 /* No Dwarf representation currently defined. */
8872 TREE_ASM_WRITTEN (type) = 1;
8875 /* Generate a DIE for a tagged type instantiation. */
8878 gen_tagged_type_instantiation_die (type, context_die)
8880 register dw_die_ref context_die;
8882 if (type == NULL_TREE || type == error_mark_node)
8885 /* We are going to output a DIE to represent the unqualified version of of
8886 this type (i.e. without any const or volatile qualifiers) so make sure
8887 that we have the main variant (i.e. the unqualified version) of this
8889 if (type != type_main_variant (type)
8890 || !TREE_ASM_WRITTEN (type))
8893 switch (TREE_CODE (type))
8899 gen_inlined_enumeration_type_die (type, context_die);
8903 gen_inlined_structure_type_die (type, context_die);
8907 case QUAL_UNION_TYPE:
8908 gen_inlined_union_type_die (type, context_die);
8916 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
8917 things which are local to the given block. */
8920 gen_block_die (stmt, context_die, depth)
8922 register dw_die_ref context_die;
8925 register int must_output_die = 0;
8926 register tree origin;
8928 register enum tree_code origin_code;
8930 /* Ignore blocks never really used to make RTL. */
8932 if (stmt == NULL_TREE || !TREE_USED (stmt))
8935 /* Determine the "ultimate origin" of this block. This block may be an
8936 inlined instance of an inlined instance of inline function, so we have
8937 to trace all of the way back through the origin chain to find out what
8938 sort of node actually served as the original seed for the creation of
8939 the current block. */
8940 origin = block_ultimate_origin (stmt);
8941 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
8943 /* Determine if we need to output any Dwarf DIEs at all to represent this
8945 if (origin_code == FUNCTION_DECL)
8946 /* The outer scopes for inlinings *must* always be represented. We
8947 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
8948 must_output_die = 1;
8951 /* In the case where the current block represents an inlining of the
8952 "body block" of an inline function, we must *NOT* output any DIE for
8953 this block because we have already output a DIE to represent the
8954 whole inlined function scope and the "body block" of any function
8955 doesn't really represent a different scope according to ANSI C
8956 rules. So we check here to make sure that this block does not
8957 represent a "body block inlining" before trying to set the
8958 `must_output_die' flag. */
8959 if (! is_body_block (origin ? origin : stmt))
8961 /* Determine if this block directly contains any "significant"
8962 local declarations which we will need to output DIEs for. */
8963 if (debug_info_level > DINFO_LEVEL_TERSE)
8964 /* We are not in terse mode so *any* local declaration counts
8965 as being a "significant" one. */
8966 must_output_die = (BLOCK_VARS (stmt) != NULL);
8968 /* We are in terse mode, so only local (nested) function
8969 definitions count as "significant" local declarations. */
8970 for (decl = BLOCK_VARS (stmt);
8971 decl != NULL; decl = TREE_CHAIN (decl))
8972 if (TREE_CODE (decl) == FUNCTION_DECL
8973 && DECL_INITIAL (decl))
8975 must_output_die = 1;
8981 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
8982 DIE for any block which contains no significant local declarations at
8983 all. Rather, in such cases we just call `decls_for_scope' so that any
8984 needed Dwarf info for any sub-blocks will get properly generated. Note
8985 that in terse mode, our definition of what constitutes a "significant"
8986 local declaration gets restricted to include only inlined function
8987 instances and local (nested) function definitions. */
8988 if (must_output_die)
8990 if (origin_code == FUNCTION_DECL)
8991 gen_inlined_subroutine_die (stmt, context_die, depth);
8993 gen_lexical_block_die (stmt, context_die, depth);
8996 decls_for_scope (stmt, context_die, depth);
8999 /* Generate all of the decls declared within a given scope and (recursively)
9000 all of it's sub-blocks. */
9003 decls_for_scope (stmt, context_die, depth)
9005 register dw_die_ref context_die;
9009 register tree subblocks;
9011 /* Ignore blocks never really used to make RTL. */
9012 if (stmt == NULL_TREE || ! TREE_USED (stmt))
9015 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
9016 next_block_number++;
9018 /* Output the DIEs to represent all of the data objects and typedefs
9019 declared directly within this block but not within any nested
9020 sub-blocks. Also, nested function and tag DIEs have been
9021 generated with a parent of NULL; fix that up now. */
9022 for (decl = BLOCK_VARS (stmt);
9023 decl != NULL; decl = TREE_CHAIN (decl))
9025 register dw_die_ref die;
9027 if (TREE_CODE (decl) == FUNCTION_DECL)
9028 die = lookup_decl_die (decl);
9029 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9030 die = lookup_type_die (TREE_TYPE (decl));
9034 if (die != NULL && die->die_parent == NULL)
9035 add_child_die (context_die, die);
9037 gen_decl_die (decl, context_die);
9040 /* Output the DIEs to represent all sub-blocks (and the items declared
9041 therein) of this block. */
9042 for (subblocks = BLOCK_SUBBLOCKS (stmt);
9044 subblocks = BLOCK_CHAIN (subblocks))
9045 gen_block_die (subblocks, context_die, depth + 1);
9048 /* Is this a typedef we can avoid emitting? */
9051 is_redundant_typedef (decl)
9054 if (TYPE_DECL_IS_STUB (decl))
9057 if (DECL_ARTIFICIAL (decl)
9058 && DECL_CONTEXT (decl)
9059 && is_tagged_type (DECL_CONTEXT (decl))
9060 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
9061 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
9062 /* Also ignore the artificial member typedef for the class name. */
9068 /* Generate Dwarf debug information for a decl described by DECL. */
9071 gen_decl_die (decl, context_die)
9073 register dw_die_ref context_die;
9075 register tree origin;
9077 /* Make a note of the decl node we are going to be working on. We may need
9078 to give the user the source coordinates of where it appeared in case we
9079 notice (later on) that something about it looks screwy. */
9080 dwarf_last_decl = decl;
9082 if (TREE_CODE (decl) == ERROR_MARK)
9085 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
9086 ignore a function definition, since that would screw up our count of
9087 blocks, and that it turn will completely screw up the the labels we will
9088 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9089 subsequent blocks). */
9090 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
9093 switch (TREE_CODE (decl))
9096 /* The individual enumerators of an enum type get output when we output
9097 the Dwarf representation of the relevant enum type itself. */
9101 /* Don't output any DIEs to represent mere function declarations,
9102 unless they are class members or explicit block externs. */
9103 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
9104 && (current_function_decl == NULL_TREE || ! DECL_ARTIFICIAL (decl)))
9107 if (debug_info_level > DINFO_LEVEL_TERSE)
9109 /* Before we describe the FUNCTION_DECL itself, make sure that we
9110 have described its return type. */
9111 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
9113 /* And its containing type. */
9114 origin = decl_class_context (decl);
9115 if (origin != NULL_TREE)
9116 gen_type_die (origin, context_die);
9118 /* And its virtual context. */
9119 if (DECL_VINDEX (decl) != NULL_TREE)
9120 gen_type_die (DECL_CONTEXT (decl), context_die);
9123 /* Now output a DIE to represent the function itself. */
9124 gen_subprogram_die (decl, context_die);
9128 /* If we are in terse mode, don't generate any DIEs to represent any
9130 if (debug_info_level <= DINFO_LEVEL_TERSE)
9133 /* In the special case of a TYPE_DECL node representing the
9134 declaration of some type tag, if the given TYPE_DECL is marked as
9135 having been instantiated from some other (original) TYPE_DECL node
9136 (e.g. one which was generated within the original definition of an
9137 inline function) we have to generate a special (abbreviated)
9138 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9140 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
9142 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
9146 if (is_redundant_typedef (decl))
9147 gen_type_die (TREE_TYPE (decl), context_die);
9149 /* Output a DIE to represent the typedef itself. */
9150 gen_typedef_die (decl, context_die);
9154 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9155 gen_label_die (decl, context_die);
9159 /* If we are in terse mode, don't generate any DIEs to represent any
9160 variable declarations or definitions. */
9161 if (debug_info_level <= DINFO_LEVEL_TERSE)
9164 /* Output any DIEs that are needed to specify the type of this data
9166 gen_type_die (TREE_TYPE (decl), context_die);
9168 /* And its containing type. */
9169 origin = decl_class_context (decl);
9170 if (origin != NULL_TREE)
9171 gen_type_die (origin, context_die);
9173 /* Now output the DIE to represent the data object itself. This gets
9174 complicated because of the possibility that the VAR_DECL really
9175 represents an inlined instance of a formal parameter for an inline
9177 origin = decl_ultimate_origin (decl);
9178 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
9179 gen_formal_parameter_die (decl, context_die);
9181 gen_variable_die (decl, context_die);
9185 /* Ignore the nameless fields that are used to skip bits, but
9186 handle C++ anonymous unions. */
9187 if (DECL_NAME (decl) != NULL_TREE
9188 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
9190 gen_type_die (member_declared_type (decl), context_die);
9191 gen_field_die (decl, context_die);
9196 gen_type_die (TREE_TYPE (decl), context_die);
9197 gen_formal_parameter_die (decl, context_die);
9205 /* Write the debugging output for DECL. */
9208 dwarf2out_decl (decl)
9211 register dw_die_ref context_die = comp_unit_die;
9213 if (TREE_CODE (decl) == ERROR_MARK)
9216 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
9217 hope that the node in question doesn't represent a function definition.
9218 If it does, then totally ignoring it is bound to screw up our count of
9219 blocks, and that it turn will completely screw up the the labels we will
9220 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9221 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
9222 own sequence numbers with them!) */
9223 if (DECL_IGNORED_P (decl))
9225 if (TREE_CODE (decl) == FUNCTION_DECL
9226 && DECL_INITIAL (decl) != NULL)
9232 switch (TREE_CODE (decl))
9235 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9236 builtin function. Explicit programmer-supplied declarations of
9237 these same functions should NOT be ignored however. */
9238 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
9241 /* What we would really like to do here is to filter out all mere
9242 file-scope declarations of file-scope functions which are never
9243 referenced later within this translation unit (and keep all of ones
9244 that *are* referenced later on) but we aren't clarvoiant, so we have
9245 no idea which functions will be referenced in the future (i.e. later
9246 on within the current translation unit). So here we just ignore all
9247 file-scope function declarations which are not also definitions. If
9248 and when the debugger needs to know something about these funcstion,
9249 it wil have to hunt around and find the DWARF information associated
9250 with the definition of the function. Note that we can't just check
9251 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9252 definitions and which ones represent mere declarations. We have to
9253 check `DECL_INITIAL' instead. That's because the C front-end
9254 supports some weird semantics for "extern inline" function
9255 definitions. These can get inlined within the current translation
9256 unit (an thus, we need to generate DWARF info for their abstract
9257 instances so that the DWARF info for the concrete inlined instances
9258 can have something to refer to) but the compiler never generates any
9259 out-of-lines instances of such things (despite the fact that they
9260 *are* definitions). The important point is that the C front-end
9261 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9262 to generate DWARF for them anyway. Note that the C++ front-end also
9263 plays some similar games for inline function definitions appearing
9264 within include files which also contain
9265 `#pragma interface' pragmas. */
9266 if (DECL_INITIAL (decl) == NULL_TREE)
9269 /* If we're a nested function, initially use a parent of NULL; if we're
9270 a plain function, this will be fixed up in decls_for_scope. If
9271 we're a method, it will be ignored, since we already have a DIE. */
9272 if (decl_function_context (decl))
9278 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9279 declaration and if the declaration was never even referenced from
9280 within this entire compilation unit. We suppress these DIEs in
9281 order to save space in the .debug section (by eliminating entries
9282 which are probably useless). Note that we must not suppress
9283 block-local extern declarations (whether used or not) because that
9284 would screw-up the debugger's name lookup mechanism and cause it to
9285 miss things which really ought to be in scope at a given point. */
9286 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
9289 /* If we are in terse mode, don't generate any DIEs to represent any
9290 variable declarations or definitions. */
9291 if (debug_info_level <= DINFO_LEVEL_TERSE)
9296 /* Don't bother trying to generate any DIEs to represent any of the
9297 normal built-in types for the language we are compiling. */
9298 if (DECL_SOURCE_LINE (decl) == 0)
9300 /* OK, we need to generate one for `bool' so GDB knows what type
9301 comparisons have. */
9302 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
9303 == DW_LANG_C_plus_plus)
9304 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
9305 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
9310 /* If we are in terse mode, don't generate any DIEs for types. */
9311 if (debug_info_level <= DINFO_LEVEL_TERSE)
9314 /* If we're a function-scope tag, initially use a parent of NULL;
9315 this will be fixed up in decls_for_scope. */
9316 if (decl_function_context (decl))
9325 gen_decl_die (decl, context_die);
9326 output_pending_types_for_scope (comp_unit_die);
9329 /* Output a marker (i.e. a label) for the beginning of the generated code for
9333 dwarf2out_begin_block (blocknum)
9334 register unsigned blocknum;
9336 function_section (current_function_decl);
9337 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
9340 /* Output a marker (i.e. a label) for the end of the generated code for a
9344 dwarf2out_end_block (blocknum)
9345 register unsigned blocknum;
9347 function_section (current_function_decl);
9348 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
9351 /* Output a marker (i.e. a label) at a point in the assembly code which
9352 corresponds to a given source level label. */
9355 dwarf2out_label (insn)
9358 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9360 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9362 function_section (current_function_decl);
9363 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
9364 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
9365 (unsigned) INSN_UID (insn));
9369 /* Lookup a filename (in the list of filenames that we know about here in
9370 dwarf2out.c) and return its "index". The index of each (known) filename is
9371 just a unique number which is associated with only that one filename.
9372 We need such numbers for the sake of generating labels
9373 (in the .debug_sfnames section) and references to those
9374 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9375 If the filename given as an argument is not found in our current list,
9376 add it to the list and assign it the next available unique index number.
9377 In order to speed up searches, we remember the index of the filename
9378 was looked up last. This handles the majority of all searches. */
9381 lookup_filename (file_name)
9384 static unsigned last_file_lookup_index = 0;
9385 register unsigned i;
9387 /* Check to see if the file name that was searched on the previous call
9388 matches this file name. If so, return the index. */
9389 if (last_file_lookup_index != 0)
9390 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
9391 return last_file_lookup_index;
9393 /* Didn't match the previous lookup, search the table */
9394 for (i = 1; i < file_table_in_use; ++i)
9395 if (strcmp (file_name, file_table[i]) == 0)
9397 last_file_lookup_index = i;
9401 /* Prepare to add a new table entry by making sure there is enough space in
9402 the table to do so. If not, expand the current table. */
9403 if (file_table_in_use == file_table_allocated)
9405 file_table_allocated += FILE_TABLE_INCREMENT;
9407 = (char **) xrealloc (file_table,
9408 file_table_allocated * sizeof (char *));
9411 /* Add the new entry to the end of the filename table. */
9412 file_table[file_table_in_use] = xstrdup (file_name);
9413 last_file_lookup_index = file_table_in_use++;
9415 return last_file_lookup_index;
9418 /* Output a label to mark the beginning of a source code line entry
9419 and record information relating to this source line, in
9420 'line_info_table' for later output of the .debug_line section. */
9423 dwarf2out_line (filename, line)
9424 register char *filename;
9425 register unsigned line;
9427 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9429 function_section (current_function_decl);
9431 if (DECL_SECTION_NAME (current_function_decl))
9433 register dw_separate_line_info_ref line_info;
9434 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
9435 separate_line_info_table_in_use);
9436 fputc ('\n', asm_out_file);
9438 /* expand the line info table if necessary */
9439 if (separate_line_info_table_in_use
9440 == separate_line_info_table_allocated)
9442 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9443 separate_line_info_table
9444 = (dw_separate_line_info_ref)
9445 xrealloc (separate_line_info_table,
9446 separate_line_info_table_allocated
9447 * sizeof (dw_separate_line_info_entry));
9450 /* Add the new entry at the end of the line_info_table. */
9452 = &separate_line_info_table[separate_line_info_table_in_use++];
9453 line_info->dw_file_num = lookup_filename (filename);
9454 line_info->dw_line_num = line;
9455 line_info->function = current_funcdef_number;
9459 register dw_line_info_ref line_info;
9461 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
9462 line_info_table_in_use);
9463 fputc ('\n', asm_out_file);
9465 /* Expand the line info table if necessary. */
9466 if (line_info_table_in_use == line_info_table_allocated)
9468 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9470 = (dw_line_info_ref)
9471 xrealloc (line_info_table,
9472 (line_info_table_allocated
9473 * sizeof (dw_line_info_entry)));
9476 /* Add the new entry at the end of the line_info_table. */
9477 line_info = &line_info_table[line_info_table_in_use++];
9478 line_info->dw_file_num = lookup_filename (filename);
9479 line_info->dw_line_num = line;
9484 /* Record the beginning of a new source file, for later output
9485 of the .debug_macinfo section. At present, unimplemented. */
9488 dwarf2out_start_source_file (filename)
9489 register char *filename;
9493 /* Record the end of a source file, for later output
9494 of the .debug_macinfo section. At present, unimplemented. */
9497 dwarf2out_end_source_file ()
9501 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9502 the tail part of the directive line, i.e. the part which is past the
9503 initial whitespace, #, whitespace, directive-name, whitespace part. */
9506 dwarf2out_define (lineno, buffer)
9507 register unsigned lineno;
9508 register char *buffer;
9510 static int initialized = 0;
9513 dwarf2out_start_source_file (primary_filename);
9518 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9519 the tail part of the directive line, i.e. the part which is past the
9520 initial whitespace, #, whitespace, directive-name, whitespace part. */
9523 dwarf2out_undef (lineno, buffer)
9524 register unsigned lineno;
9525 register char *buffer;
9529 /* Set up for Dwarf output at the start of compilation. */
9532 dwarf2out_init (asm_out_file, main_input_filename)
9533 register FILE *asm_out_file;
9534 register char *main_input_filename;
9536 /* Remember the name of the primary input file. */
9537 primary_filename = main_input_filename;
9539 /* Allocate the initial hunk of the file_table. */
9540 file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *));
9541 bzero ((char *) file_table, FILE_TABLE_INCREMENT * sizeof (char *));
9542 file_table_allocated = FILE_TABLE_INCREMENT;
9544 /* Skip the first entry - file numbers begin at 1. */
9545 file_table_in_use = 1;
9547 /* Allocate the initial hunk of the decl_die_table. */
9549 = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
9550 bzero ((char *) decl_die_table,
9551 DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
9552 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
9553 decl_die_table_in_use = 0;
9555 /* Allocate the initial hunk of the decl_scope_table. */
9557 = (tree *) xmalloc (DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
9558 bzero ((char *) decl_scope_table,
9559 DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
9560 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
9561 decl_scope_depth = 0;
9563 /* Allocate the initial hunk of the abbrev_die_table. */
9565 = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT
9566 * sizeof (dw_die_ref));
9567 bzero ((char *) abbrev_die_table,
9568 ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
9569 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
9570 /* Zero-th entry is allocated, but unused */
9571 abbrev_die_table_in_use = 1;
9573 /* Allocate the initial hunk of the line_info_table. */
9575 = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT
9576 * sizeof (dw_line_info_entry));
9577 bzero ((char *) line_info_table,
9578 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
9579 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
9580 /* Zero-th entry is allocated, but unused */
9581 line_info_table_in_use = 1;
9583 /* Generate the initial DIE for the .debug section. Note that the (string)
9584 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9585 will (typically) be a relative pathname and that this pathname should be
9586 taken as being relative to the directory from which the compiler was
9587 invoked when the given (base) source file was compiled. */
9588 gen_compile_unit_die (main_input_filename);
9590 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
9593 /* Output stuff that dwarf requires at the end of every file,
9594 and generate the DWARF-2 debugging info. */
9599 limbo_die_node *node, *next_node;
9603 /* Traverse the limbo die list, and add parent/child links. The only
9604 dies without parents that should be here are concrete instances of
9605 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9606 For concrete instances, we can get the parent die from the abstract
9608 for (node = limbo_die_list; node; node = next_node)
9610 next_node = node->next;
9613 if (die->die_parent == NULL)
9615 a = get_AT (die, DW_AT_abstract_origin);
9617 add_child_die (a->dw_attr_val.v.val_die_ref->die_parent, die);
9618 else if (die == comp_unit_die)
9626 /* Traverse the DIE tree and add sibling attributes to those DIE's
9627 that have children. */
9628 add_sibling_attributes (comp_unit_die);
9630 /* Output a terminator label for the .text section. */
9631 fputc ('\n', asm_out_file);
9632 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9633 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
9636 /* Output a terminator label for the .data section. */
9637 fputc ('\n', asm_out_file);
9638 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
9639 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
9641 /* Output a terminator label for the .bss section. */
9642 fputc ('\n', asm_out_file);
9643 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
9644 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
9647 /* Output the source line correspondence table. */
9648 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
9650 fputc ('\n', asm_out_file);
9651 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9652 output_line_info ();
9654 /* We can only use the low/high_pc attributes if all of the code
9656 if (separate_line_info_table_in_use == 0)
9658 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_SECTION);
9659 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
9662 add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, DEBUG_LINE_SECTION);
9665 /* Output the abbreviation table. */
9666 fputc ('\n', asm_out_file);
9667 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9668 build_abbrev_table (comp_unit_die);
9669 output_abbrev_section ();
9671 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9672 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9673 calc_die_sizes (comp_unit_die);
9675 /* Output debugging information. */
9676 fputc ('\n', asm_out_file);
9677 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9678 output_compilation_unit_header ();
9679 output_die (comp_unit_die);
9681 if (pubname_table_in_use)
9683 /* Output public names table. */
9684 fputc ('\n', asm_out_file);
9685 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
9689 if (fde_table_in_use)
9691 /* Output the address range information. */
9692 fputc ('\n', asm_out_file);
9693 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
9697 #endif /* DWARF2_DEBUGGING_INFO */