1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 93, 95, 96, 97, 1998 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com).
4 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /* The first part of this file deals with the DWARF 2 frame unwind
24 information, which is also used by the GCC efficient exception handling
25 mechanism. The second part, controlled only by an #ifdef
26 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
35 #include "hard-reg-set.h"
37 #include "insn-config.h"
44 /* We cannot use <assert.h> in GCC source, since that would include
45 GCC's assert.h, which may not be compatible with the host compiler. */
50 # define assert(e) do { if (! (e)) abort (); } while (0)
53 /* Decide whether we want to emit frame unwind information for the current
59 return (write_symbols == DWARF2_DEBUG
60 #ifdef DWARF2_UNWIND_INFO
61 || (flag_exceptions && ! exceptions_via_longjmp)
66 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
72 /* How to start an assembler comment. */
73 #ifndef ASM_COMMENT_START
74 #define ASM_COMMENT_START ";#"
77 typedef struct dw_cfi_struct *dw_cfi_ref;
78 typedef struct dw_fde_struct *dw_fde_ref;
79 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
81 /* Call frames are described using a sequence of Call Frame
82 Information instructions. The register number, offset
83 and address fields are provided as possible operands;
84 their use is selected by the opcode field. */
86 typedef union dw_cfi_oprnd_struct
88 unsigned long dw_cfi_reg_num;
89 long int dw_cfi_offset;
94 typedef struct dw_cfi_struct
96 dw_cfi_ref dw_cfi_next;
97 enum dwarf_call_frame_info dw_cfi_opc;
98 dw_cfi_oprnd dw_cfi_oprnd1;
99 dw_cfi_oprnd dw_cfi_oprnd2;
103 /* All call frame descriptions (FDE's) in the GCC generated DWARF
104 refer to a single Common Information Entry (CIE), defined at
105 the beginning of the .debug_frame section. This used of a single
106 CIE obviates the need to keep track of multiple CIE's
107 in the DWARF generation routines below. */
109 typedef struct dw_fde_struct
112 char *dw_fde_current_label;
114 dw_cfi_ref dw_fde_cfi;
118 /* Maximum size (in bytes) of an artificially generated label. */
119 #define MAX_ARTIFICIAL_LABEL_BYTES 30
121 /* Make sure we know the sizes of the various types dwarf can describe. These
122 are only defaults. If the sizes are different for your target, you should
123 override these values by defining the appropriate symbols in your tm.h
126 #ifndef CHAR_TYPE_SIZE
127 #define CHAR_TYPE_SIZE BITS_PER_UNIT
130 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
133 /* The size in bytes of a DWARF field indicating an offset or length
134 relative to a debug info section, specified to be 4 bytes in the DWARF-2
135 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
137 #ifndef DWARF_OFFSET_SIZE
138 #define DWARF_OFFSET_SIZE 4
141 #define DWARF_VERSION 2
143 /* Round SIZE up to the nearest BOUNDARY. */
144 #define DWARF_ROUND(SIZE,BOUNDARY) \
145 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
147 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
148 #ifdef STACK_GROWS_DOWNWARD
149 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
151 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
154 /* A pointer to the base of a table that contains frame description
155 information for each routine. */
156 static dw_fde_ref fde_table;
158 /* Number of elements currently allocated for fde_table. */
159 static unsigned fde_table_allocated;
161 /* Number of elements in fde_table currently in use. */
162 static unsigned fde_table_in_use;
164 /* Size (in elements) of increments by which we may expand the
166 #define FDE_TABLE_INCREMENT 256
168 /* A list of call frame insns for the CIE. */
169 static dw_cfi_ref cie_cfi_head;
171 /* The number of the current function definition for which debugging
172 information is being generated. These numbers range from 1 up to the
173 maximum number of function definitions contained within the current
174 compilation unit. These numbers are used to create unique label id's
175 unique to each function definition. */
176 static unsigned current_funcdef_number = 0;
178 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
179 attribute that accelerates the lookup of the FDE associated
180 with the subprogram. This variable holds the table index of the FDE
181 associated with the current function (body) definition. */
182 static unsigned current_funcdef_fde;
184 /* Forward declarations for functions defined in this file. */
186 static char *stripattributes PROTO((char *));
187 static char *dwarf_cfi_name PROTO((unsigned));
188 static dw_cfi_ref new_cfi PROTO((void));
189 static void add_cfi PROTO((dw_cfi_ref *, dw_cfi_ref));
190 static unsigned long size_of_uleb128 PROTO((unsigned long));
191 static unsigned long size_of_sleb128 PROTO((long));
192 static void output_uleb128 PROTO((unsigned long));
193 static void output_sleb128 PROTO((long));
194 static void add_fde_cfi PROTO((char *, dw_cfi_ref));
195 static void lookup_cfa_1 PROTO((dw_cfi_ref, unsigned long *,
197 static void lookup_cfa PROTO((unsigned long *, long *));
198 static void reg_save PROTO((char *, unsigned, unsigned,
200 static void initial_return_save PROTO((rtx));
201 static void output_cfi PROTO((dw_cfi_ref, dw_fde_ref));
202 static void output_call_frame_info PROTO((int));
203 static unsigned reg_number PROTO((rtx));
204 static void dwarf2out_stack_adjust PROTO((rtx));
206 /* Definitions of defaults for assembler-dependent names of various
207 pseudo-ops and section names.
208 Theses may be overridden in the tm.h file (if necessary) for a particular
211 #ifdef OBJECT_FORMAT_ELF
212 #ifndef UNALIGNED_SHORT_ASM_OP
213 #define UNALIGNED_SHORT_ASM_OP ".2byte"
215 #ifndef UNALIGNED_INT_ASM_OP
216 #define UNALIGNED_INT_ASM_OP ".4byte"
218 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
219 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
221 #endif /* OBJECT_FORMAT_ELF */
224 #define ASM_BYTE_OP ".byte"
227 /* Data and reference forms for relocatable data. */
228 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
229 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
231 /* Pseudo-op for defining a new section. */
232 #ifndef SECTION_ASM_OP
233 #define SECTION_ASM_OP ".section"
236 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
237 print the SECTION_ASM_OP and the section name. The default here works for
238 almost all svr4 assemblers, except for the sparc, where the section name
239 must be enclosed in double quotes. (See sparcv4.h). */
240 #ifndef SECTION_FORMAT
241 #ifdef PUSHSECTION_FORMAT
242 #define SECTION_FORMAT PUSHSECTION_FORMAT
244 #define SECTION_FORMAT "\t%s\t%s\n"
248 #ifndef FRAME_SECTION
249 #define FRAME_SECTION ".debug_frame"
252 #ifndef FUNC_BEGIN_LABEL
253 #define FUNC_BEGIN_LABEL "LFB"
255 #ifndef FUNC_END_LABEL
256 #define FUNC_END_LABEL "LFE"
258 #define CIE_AFTER_SIZE_LABEL "LSCIE"
259 #define CIE_END_LABEL "LECIE"
260 #define CIE_LENGTH_LABEL "LLCIE"
261 #define FDE_AFTER_SIZE_LABEL "LSFDE"
262 #define FDE_END_LABEL "LEFDE"
263 #define FDE_LENGTH_LABEL "LLFDE"
265 /* Definitions of defaults for various types of primitive assembly language
266 output operations. These may be overridden from within the tm.h file,
267 but typically, that is unnecessary. */
269 #ifndef ASM_OUTPUT_SECTION
270 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
271 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
274 #ifndef ASM_OUTPUT_DWARF_DATA1
275 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
276 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
279 #ifndef ASM_OUTPUT_DWARF_DELTA1
280 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
281 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
282 assemble_name (FILE, LABEL1); \
283 fprintf (FILE, "-"); \
284 assemble_name (FILE, LABEL2); \
288 #ifdef UNALIGNED_INT_ASM_OP
290 #ifndef UNALIGNED_OFFSET_ASM_OP
291 #define UNALIGNED_OFFSET_ASM_OP \
292 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
295 #ifndef UNALIGNED_WORD_ASM_OP
296 #define UNALIGNED_WORD_ASM_OP \
297 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
300 #ifndef ASM_OUTPUT_DWARF_DELTA2
301 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
302 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
303 assemble_name (FILE, LABEL1); \
304 fprintf (FILE, "-"); \
305 assemble_name (FILE, LABEL2); \
309 #ifndef ASM_OUTPUT_DWARF_DELTA4
310 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
311 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
312 assemble_name (FILE, LABEL1); \
313 fprintf (FILE, "-"); \
314 assemble_name (FILE, LABEL2); \
318 #ifndef ASM_OUTPUT_DWARF_DELTA
319 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
320 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
321 assemble_name (FILE, LABEL1); \
322 fprintf (FILE, "-"); \
323 assemble_name (FILE, LABEL2); \
327 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
328 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
329 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
330 assemble_name (FILE, LABEL1); \
331 fprintf (FILE, "-"); \
332 assemble_name (FILE, LABEL2); \
336 #ifndef ASM_OUTPUT_DWARF_ADDR
337 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
338 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
339 assemble_name (FILE, LABEL); \
343 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
344 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
345 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
348 #ifndef ASM_OUTPUT_DWARF_OFFSET4
349 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
350 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
351 assemble_name (FILE, LABEL); \
355 #ifndef ASM_OUTPUT_DWARF_OFFSET
356 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
357 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
358 assemble_name (FILE, LABEL); \
362 #ifndef ASM_OUTPUT_DWARF_DATA2
363 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
364 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
367 #ifndef ASM_OUTPUT_DWARF_DATA4
368 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
369 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
372 #ifndef ASM_OUTPUT_DWARF_DATA
373 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
374 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
375 (unsigned long) VALUE)
378 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
379 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
380 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
381 (unsigned long) VALUE)
384 #ifndef ASM_OUTPUT_DWARF_DATA8
385 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
387 if (WORDS_BIG_ENDIAN) \
389 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
390 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
394 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
395 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
400 #else /* UNALIGNED_INT_ASM_OP */
402 /* We don't have unaligned support, let's hope the normal output works for
405 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
406 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), PTR_SIZE, 1)
408 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
409 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
411 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
412 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
414 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
415 assemble_integer (gen_rtx_MINUS (HImode, \
416 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
417 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
420 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
421 assemble_integer (gen_rtx_MINUS (SImode, \
422 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
423 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
426 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
427 assemble_integer (gen_rtx_MINUS (Pmode, \
428 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
429 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
432 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
433 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
435 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
436 assemble_integer (GEN_INT (VALUE), 4, 1)
438 #endif /* UNALIGNED_INT_ASM_OP */
441 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
442 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
444 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
445 assemble_name (FILE, SY); \
447 assemble_name (FILE, HI); \
449 assemble_name (FILE, LO); \
452 #endif /* SET_ASM_OP */
454 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
455 newline is produced. When flag_debug_asm is asserted, we add commentary
456 at the end of the line, so we must avoid output of a newline here. */
457 #ifndef ASM_OUTPUT_DWARF_STRING
458 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
460 register int slen = strlen(P); \
461 register char *p = (P); \
463 fprintf (FILE, "\t.ascii \""); \
464 for (i = 0; i < slen; i++) \
466 register int c = p[i]; \
467 if (c == '\"' || c == '\\') \
469 if (c >= ' ' && c < 0177) \
473 fprintf (FILE, "\\%o", c); \
476 fprintf (FILE, "\\0\""); \
481 /* The DWARF 2 CFA column which tracks the return address. Normally this
482 is the column for PC, or the first column after all of the hard
484 #ifndef DWARF_FRAME_RETURN_COLUMN
486 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
488 #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER
492 /* The mapping from gcc register number to DWARF 2 CFA column number. By
493 default, we just provide columns for all registers. */
494 #ifndef DWARF_FRAME_REGNUM
495 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
498 /* Hook used by __throw. */
501 expand_builtin_dwarf_fp_regnum ()
503 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
506 /* The offset from the incoming value of %sp to the top of the stack frame
507 for the current function. */
508 #ifndef INCOMING_FRAME_SP_OFFSET
509 #define INCOMING_FRAME_SP_OFFSET 0
512 /* Return a pointer to a copy of the section string name S with all
513 attributes stripped off. */
519 char *stripped = xstrdup (s);
522 while (*p && *p != ',')
529 /* Return the register number described by a given RTL node. */
535 register unsigned regno = REGNO (rtl);
537 if (regno >= FIRST_PSEUDO_REGISTER)
539 warning ("internal regno botch: regno = %d\n", regno);
543 regno = DBX_REGISTER_NUMBER (regno);
547 struct reg_size_range
554 /* Given a register number in REG_TREE, return an rtx for its size in bytes.
555 We do this in kind of a roundabout way, by building up a list of
556 register size ranges and seeing where our register falls in one of those
557 ranges. We need to do it this way because REG_TREE is not a constant,
558 and the target macros were not designed to make this task easy. */
561 expand_builtin_dwarf_reg_size (reg_tree, target)
565 enum machine_mode mode;
567 struct reg_size_range ranges[5];
574 for (; i < FIRST_PSEUDO_REGISTER; ++i)
576 /* The return address is out of order on the MIPS, and we don't use
577 copy_reg for it anyway, so we don't care here how large it is. */
578 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
581 mode = reg_raw_mode[i];
583 /* CCmode is arbitrarily given a size of 4 bytes. It is more useful
584 to use the same size as word_mode, since that reduces the number
585 of ranges we need. It should not matter, since the result should
586 never be used for a condition code register anyways. */
587 if (GET_MODE_CLASS (mode) == MODE_CC)
590 size = GET_MODE_SIZE (mode);
592 /* If this register is not valid in the specified mode and
593 we have a previous size, use that for the size of this
594 register to avoid making junk tiny ranges. */
595 if (! HARD_REGNO_MODE_OK (i, mode) && last_size != -1)
598 if (size != last_size)
600 ranges[n_ranges].beg = i;
601 ranges[n_ranges].size = last_size = size;
606 ranges[n_ranges-1].end = i;
609 /* The usual case: fp regs surrounded by general regs. */
610 if (n_ranges == 3 && ranges[0].size == ranges[2].size)
612 if ((DWARF_FRAME_REGNUM (ranges[1].end)
613 - DWARF_FRAME_REGNUM (ranges[1].beg))
614 != ranges[1].end - ranges[1].beg)
616 t = fold (build (GE_EXPR, integer_type_node, reg_tree,
617 build_int_2 (DWARF_FRAME_REGNUM (ranges[1].beg), 0)));
618 t2 = fold (build (LE_EXPR, integer_type_node, reg_tree,
619 build_int_2 (DWARF_FRAME_REGNUM (ranges[1].end), 0)));
620 t = fold (build (TRUTH_ANDIF_EXPR, integer_type_node, t, t2));
621 t = fold (build (COND_EXPR, integer_type_node, t,
622 build_int_2 (ranges[1].size, 0),
623 build_int_2 (ranges[0].size, 0)));
628 t = build_int_2 (ranges[n_ranges].size, 0);
629 size = DWARF_FRAME_REGNUM (ranges[n_ranges].beg);
632 if ((DWARF_FRAME_REGNUM (ranges[n_ranges].end)
633 - DWARF_FRAME_REGNUM (ranges[n_ranges].beg))
634 != ranges[n_ranges].end - ranges[n_ranges].beg)
636 if (DWARF_FRAME_REGNUM (ranges[n_ranges].beg) >= size)
638 size = DWARF_FRAME_REGNUM (ranges[n_ranges].beg);
639 t2 = fold (build (LE_EXPR, integer_type_node, reg_tree,
640 build_int_2 (DWARF_FRAME_REGNUM
641 (ranges[n_ranges].end), 0)));
642 t = fold (build (COND_EXPR, integer_type_node, t2,
643 build_int_2 (ranges[n_ranges].size, 0), t));
646 return expand_expr (t, target, Pmode, 0);
649 /* Convert a DWARF call frame info. operation to its string name */
652 dwarf_cfi_name (cfi_opc)
653 register unsigned cfi_opc;
657 case DW_CFA_advance_loc:
658 return "DW_CFA_advance_loc";
660 return "DW_CFA_offset";
662 return "DW_CFA_restore";
666 return "DW_CFA_set_loc";
667 case DW_CFA_advance_loc1:
668 return "DW_CFA_advance_loc1";
669 case DW_CFA_advance_loc2:
670 return "DW_CFA_advance_loc2";
671 case DW_CFA_advance_loc4:
672 return "DW_CFA_advance_loc4";
673 case DW_CFA_offset_extended:
674 return "DW_CFA_offset_extended";
675 case DW_CFA_restore_extended:
676 return "DW_CFA_restore_extended";
677 case DW_CFA_undefined:
678 return "DW_CFA_undefined";
679 case DW_CFA_same_value:
680 return "DW_CFA_same_value";
681 case DW_CFA_register:
682 return "DW_CFA_register";
683 case DW_CFA_remember_state:
684 return "DW_CFA_remember_state";
685 case DW_CFA_restore_state:
686 return "DW_CFA_restore_state";
688 return "DW_CFA_def_cfa";
689 case DW_CFA_def_cfa_register:
690 return "DW_CFA_def_cfa_register";
691 case DW_CFA_def_cfa_offset:
692 return "DW_CFA_def_cfa_offset";
694 /* SGI/MIPS specific */
695 case DW_CFA_MIPS_advance_loc8:
696 return "DW_CFA_MIPS_advance_loc8";
699 case DW_CFA_GNU_window_save:
700 return "DW_CFA_GNU_window_save";
701 case DW_CFA_GNU_args_size:
702 return "DW_CFA_GNU_args_size";
705 return "DW_CFA_<unknown>";
709 /* Return a pointer to a newly allocated Call Frame Instruction. */
711 static inline dw_cfi_ref
714 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
716 cfi->dw_cfi_next = NULL;
717 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
718 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
723 /* Add a Call Frame Instruction to list of instructions. */
726 add_cfi (list_head, cfi)
727 register dw_cfi_ref *list_head;
728 register dw_cfi_ref cfi;
730 register dw_cfi_ref *p;
732 /* Find the end of the chain. */
733 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
739 /* Generate a new label for the CFI info to refer to. */
742 dwarf2out_cfi_label ()
744 static char label[20];
745 static unsigned long label_num = 0;
747 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
748 ASM_OUTPUT_LABEL (asm_out_file, label);
753 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
754 or to the CIE if LABEL is NULL. */
757 add_fde_cfi (label, cfi)
758 register char *label;
759 register dw_cfi_ref cfi;
763 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
766 label = dwarf2out_cfi_label ();
768 if (fde->dw_fde_current_label == NULL
769 || strcmp (label, fde->dw_fde_current_label) != 0)
771 register dw_cfi_ref xcfi;
773 fde->dw_fde_current_label = label = xstrdup (label);
775 /* Set the location counter to the new label. */
777 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
778 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
779 add_cfi (&fde->dw_fde_cfi, xcfi);
782 add_cfi (&fde->dw_fde_cfi, cfi);
786 add_cfi (&cie_cfi_head, cfi);
789 /* Subroutine of lookup_cfa. */
792 lookup_cfa_1 (cfi, regp, offsetp)
793 register dw_cfi_ref cfi;
794 register unsigned long *regp;
795 register long *offsetp;
797 switch (cfi->dw_cfi_opc)
799 case DW_CFA_def_cfa_offset:
800 *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
802 case DW_CFA_def_cfa_register:
803 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
806 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
807 *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
814 /* Find the previous value for the CFA. */
817 lookup_cfa (regp, offsetp)
818 register unsigned long *regp;
819 register long *offsetp;
821 register dw_cfi_ref cfi;
823 *regp = (unsigned long) -1;
826 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
827 lookup_cfa_1 (cfi, regp, offsetp);
829 if (fde_table_in_use)
831 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
832 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
833 lookup_cfa_1 (cfi, regp, offsetp);
837 /* The current rule for calculating the DWARF2 canonical frame address. */
838 static unsigned long cfa_reg;
839 static long cfa_offset;
841 /* The register used for saving registers to the stack, and its offset
843 static unsigned cfa_store_reg;
844 static long cfa_store_offset;
846 /* The running total of the size of arguments pushed onto the stack. */
847 static long args_size;
849 /* The last args_size we actually output. */
850 static long old_args_size;
852 /* Entry point to update the canonical frame address (CFA).
853 LABEL is passed to add_fde_cfi. The value of CFA is now to be
854 calculated from REG+OFFSET. */
857 dwarf2out_def_cfa (label, reg, offset)
858 register char *label;
859 register unsigned reg;
860 register long offset;
862 register dw_cfi_ref cfi;
863 unsigned long old_reg;
868 if (cfa_store_reg == reg)
869 cfa_store_offset = offset;
871 reg = DWARF_FRAME_REGNUM (reg);
872 lookup_cfa (&old_reg, &old_offset);
874 if (reg == old_reg && offset == old_offset)
881 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
882 cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
885 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
886 else if (offset == old_offset && old_reg != (unsigned long) -1)
888 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
889 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
895 cfi->dw_cfi_opc = DW_CFA_def_cfa;
896 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
897 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
900 add_fde_cfi (label, cfi);
903 /* Add the CFI for saving a register. REG is the CFA column number.
904 LABEL is passed to add_fde_cfi.
905 If SREG is -1, the register is saved at OFFSET from the CFA;
906 otherwise it is saved in SREG. */
909 reg_save (label, reg, sreg, offset)
910 register char * label;
911 register unsigned reg;
912 register unsigned sreg;
913 register long offset;
915 register dw_cfi_ref cfi = new_cfi ();
917 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
919 /* The following comparison is correct. -1 is used to indicate that
920 the value isn't a register number. */
921 if (sreg == (unsigned int) -1)
924 /* The register number won't fit in 6 bits, so we have to use
926 cfi->dw_cfi_opc = DW_CFA_offset_extended;
928 cfi->dw_cfi_opc = DW_CFA_offset;
930 offset /= DWARF_CIE_DATA_ALIGNMENT;
933 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
937 cfi->dw_cfi_opc = DW_CFA_register;
938 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
941 add_fde_cfi (label, cfi);
944 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
945 This CFI tells the unwinder that it needs to restore the window registers
946 from the previous frame's window save area.
948 ??? Perhaps we should note in the CIE where windows are saved (instead of
949 assuming 0(cfa)) and what registers are in the window. */
952 dwarf2out_window_save (label)
953 register char * label;
955 register dw_cfi_ref cfi = new_cfi ();
956 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
957 add_fde_cfi (label, cfi);
960 /* Add a CFI to update the running total of the size of arguments
961 pushed onto the stack. */
964 dwarf2out_args_size (label, size)
968 register dw_cfi_ref cfi;
970 if (size == old_args_size)
972 old_args_size = size;
975 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
976 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
977 add_fde_cfi (label, cfi);
980 /* Entry point for saving a register to the stack. REG is the GCC register
981 number. LABEL and OFFSET are passed to reg_save. */
984 dwarf2out_reg_save (label, reg, offset)
985 register char * label;
986 register unsigned reg;
987 register long offset;
989 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
992 /* Entry point for saving the return address in the stack.
993 LABEL and OFFSET are passed to reg_save. */
996 dwarf2out_return_save (label, offset)
997 register char * label;
998 register long offset;
1000 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
1003 /* Entry point for saving the return address in a register.
1004 LABEL and SREG are passed to reg_save. */
1007 dwarf2out_return_reg (label, sreg)
1008 register char * label;
1009 register unsigned sreg;
1011 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
1014 /* Record the initial position of the return address. RTL is
1015 INCOMING_RETURN_ADDR_RTX. */
1018 initial_return_save (rtl)
1024 switch (GET_CODE (rtl))
1027 /* RA is in a register. */
1028 reg = reg_number (rtl);
1031 /* RA is on the stack. */
1032 rtl = XEXP (rtl, 0);
1033 switch (GET_CODE (rtl))
1036 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1041 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1043 offset = INTVAL (XEXP (rtl, 1));
1046 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1048 offset = -INTVAL (XEXP (rtl, 1));
1055 /* The return address is at some offset from any value we can
1056 actually load. For instance, on the SPARC it is in %i7+8. Just
1057 ignore the offset for now; it doesn't matter for unwinding frames. */
1058 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1060 initial_return_save (XEXP (rtl, 0));
1066 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset);
1069 /* Check INSN to see if it looks like a push or a stack adjustment, and
1070 make a note of it if it does. EH uses this information to find out how
1071 much extra space it needs to pop off the stack. */
1074 dwarf2out_stack_adjust (insn)
1080 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1082 /* Extract the size of the args from the CALL rtx itself. */
1084 insn = PATTERN (insn);
1085 if (GET_CODE (insn) == PARALLEL)
1086 insn = XVECEXP (insn, 0, 0);
1087 if (GET_CODE (insn) == SET)
1088 insn = SET_SRC (insn);
1089 assert (GET_CODE (insn) == CALL);
1090 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1094 /* If only calls can throw, and we have a frame pointer,
1095 save up adjustments until we see the CALL_INSN. */
1096 else if (! asynchronous_exceptions
1097 && cfa_reg != STACK_POINTER_REGNUM)
1100 if (GET_CODE (insn) == BARRIER)
1102 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1103 the compiler will have already emitted a stack adjustment, but
1104 doesn't bother for calls to noreturn functions. */
1105 #ifdef STACK_GROWS_DOWNWARD
1106 offset = -args_size;
1111 else if (GET_CODE (PATTERN (insn)) == SET)
1116 insn = PATTERN (insn);
1117 src = SET_SRC (insn);
1118 dest = SET_DEST (insn);
1120 if (dest == stack_pointer_rtx)
1122 /* (set (reg sp) (plus (reg sp) (const_int))) */
1123 code = GET_CODE (src);
1124 if (! (code == PLUS || code == MINUS)
1125 || XEXP (src, 0) != stack_pointer_rtx
1126 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1129 offset = INTVAL (XEXP (src, 1));
1131 else if (GET_CODE (dest) == MEM)
1133 /* (set (mem (pre_dec (reg sp))) (foo)) */
1134 src = XEXP (dest, 0);
1135 code = GET_CODE (src);
1137 if (! (code == PRE_DEC || code == PRE_INC)
1138 || XEXP (src, 0) != stack_pointer_rtx)
1141 offset = GET_MODE_SIZE (GET_MODE (dest));
1146 if (code == PLUS || code == PRE_INC)
1155 if (cfa_reg == STACK_POINTER_REGNUM)
1156 cfa_offset += offset;
1158 #ifndef STACK_GROWS_DOWNWARD
1161 args_size += offset;
1165 label = dwarf2out_cfi_label ();
1166 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1167 dwarf2out_args_size (label, args_size);
1170 /* Record call frame debugging information for INSN, which either
1171 sets SP or FP (adjusting how we calculate the frame address) or saves a
1172 register to the stack. If INSN is NULL_RTX, initialize our state. */
1175 dwarf2out_frame_debug (insn)
1182 /* A temporary register used in adjusting SP or setting up the store_reg. */
1183 static unsigned cfa_temp_reg;
1184 static long cfa_temp_value;
1186 if (insn == NULL_RTX)
1188 /* Set up state for generating call frame debug info. */
1189 lookup_cfa (&cfa_reg, &cfa_offset);
1190 if (cfa_reg != DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1192 cfa_reg = STACK_POINTER_REGNUM;
1193 cfa_store_reg = cfa_reg;
1194 cfa_store_offset = cfa_offset;
1200 if (! RTX_FRAME_RELATED_P (insn))
1202 dwarf2out_stack_adjust (insn);
1206 label = dwarf2out_cfi_label ();
1208 insn = PATTERN (insn);
1209 /* Assume that in a PARALLEL prologue insn, only the first elt is
1210 significant. Currently this is true. */
1211 if (GET_CODE (insn) == PARALLEL)
1212 insn = XVECEXP (insn, 0, 0);
1213 if (GET_CODE (insn) != SET)
1216 src = SET_SRC (insn);
1217 dest = SET_DEST (insn);
1219 switch (GET_CODE (dest))
1222 /* Update the CFA rule wrt SP or FP. Make sure src is
1223 relative to the current CFA register. */
1224 switch (GET_CODE (src))
1226 /* Setting FP from SP. */
1228 if (cfa_reg != REGNO (src))
1230 if (REGNO (dest) != STACK_POINTER_REGNUM
1231 && !(frame_pointer_needed
1232 && REGNO (dest) == HARD_FRAME_POINTER_REGNUM))
1234 cfa_reg = REGNO (dest);
1239 if (dest == stack_pointer_rtx)
1242 switch (GET_CODE (XEXP (src, 1)))
1245 offset = INTVAL (XEXP (src, 1));
1248 if (REGNO (XEXP (src, 1)) != cfa_temp_reg)
1250 offset = cfa_temp_value;
1256 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1258 /* Restoring SP from FP in the epilogue. */
1259 if (cfa_reg != HARD_FRAME_POINTER_REGNUM)
1261 cfa_reg = STACK_POINTER_REGNUM;
1263 else if (XEXP (src, 0) != stack_pointer_rtx)
1266 if (GET_CODE (src) == PLUS)
1268 if (cfa_reg == STACK_POINTER_REGNUM)
1269 cfa_offset += offset;
1270 if (cfa_store_reg == STACK_POINTER_REGNUM)
1271 cfa_store_offset += offset;
1273 else if (dest == hard_frame_pointer_rtx)
1275 /* Either setting the FP from an offset of the SP,
1276 or adjusting the FP */
1277 if (! frame_pointer_needed
1278 || REGNO (dest) != HARD_FRAME_POINTER_REGNUM)
1281 if (XEXP (src, 0) == stack_pointer_rtx
1282 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1284 if (cfa_reg != STACK_POINTER_REGNUM)
1286 offset = INTVAL (XEXP (src, 1));
1287 if (GET_CODE (src) == PLUS)
1289 cfa_offset += offset;
1290 cfa_reg = HARD_FRAME_POINTER_REGNUM;
1292 else if (XEXP (src, 0) == hard_frame_pointer_rtx
1293 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1295 if (cfa_reg != HARD_FRAME_POINTER_REGNUM)
1297 offset = INTVAL (XEXP (src, 1));
1298 if (GET_CODE (src) == PLUS)
1300 cfa_offset += offset;
1308 if (GET_CODE (src) != PLUS
1309 || XEXP (src, 1) != stack_pointer_rtx)
1311 if (GET_CODE (XEXP (src, 0)) != REG
1312 || REGNO (XEXP (src, 0)) != cfa_temp_reg)
1314 if (cfa_reg != STACK_POINTER_REGNUM)
1316 cfa_store_reg = REGNO (dest);
1317 cfa_store_offset = cfa_offset - cfa_temp_value;
1322 cfa_temp_reg = REGNO (dest);
1323 cfa_temp_value = INTVAL (src);
1327 if (GET_CODE (XEXP (src, 0)) != REG
1328 || REGNO (XEXP (src, 0)) != cfa_temp_reg
1329 || REGNO (dest) != cfa_temp_reg
1330 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1332 cfa_temp_value |= INTVAL (XEXP (src, 1));
1338 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1342 /* Saving a register to the stack. Make sure dest is relative to the
1344 if (GET_CODE (src) != REG)
1346 switch (GET_CODE (XEXP (dest, 0)))
1351 offset = GET_MODE_SIZE (GET_MODE (dest));
1352 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1355 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1356 || cfa_store_reg != STACK_POINTER_REGNUM)
1358 cfa_store_offset += offset;
1359 if (cfa_reg == STACK_POINTER_REGNUM)
1360 cfa_offset = cfa_store_offset;
1362 offset = -cfa_store_offset;
1365 /* With an offset. */
1368 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1369 if (GET_CODE (src) == MINUS)
1372 if (cfa_store_reg != REGNO (XEXP (XEXP (dest, 0), 0)))
1374 offset -= cfa_store_offset;
1380 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1381 dwarf2out_reg_save (label, REGNO (src), offset);
1389 /* Return the size of an unsigned LEB128 quantity. */
1391 static inline unsigned long
1392 size_of_uleb128 (value)
1393 register unsigned long value;
1395 register unsigned long size = 0;
1396 register unsigned byte;
1400 byte = (value & 0x7f);
1409 /* Return the size of a signed LEB128 quantity. */
1411 static inline unsigned long
1412 size_of_sleb128 (value)
1413 register long value;
1415 register unsigned long size = 0;
1416 register unsigned byte;
1420 byte = (value & 0x7f);
1424 while (!(((value == 0) && ((byte & 0x40) == 0))
1425 || ((value == -1) && ((byte & 0x40) != 0))));
1430 /* Output an unsigned LEB128 quantity. */
1433 output_uleb128 (value)
1434 register unsigned long value;
1436 unsigned long save_value = value;
1438 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1441 register unsigned byte = (value & 0x7f);
1444 /* More bytes to follow. */
1447 fprintf (asm_out_file, "0x%x", byte);
1449 fprintf (asm_out_file, ",");
1454 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1457 /* Output an signed LEB128 quantity. */
1460 output_sleb128 (value)
1461 register long value;
1464 register unsigned byte;
1465 long save_value = value;
1467 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1470 byte = (value & 0x7f);
1471 /* arithmetic shift */
1473 more = !((((value == 0) && ((byte & 0x40) == 0))
1474 || ((value == -1) && ((byte & 0x40) != 0))));
1478 fprintf (asm_out_file, "0x%x", byte);
1480 fprintf (asm_out_file, ",");
1485 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1488 /* Output a Call Frame Information opcode and its operand(s). */
1491 output_cfi (cfi, fde)
1492 register dw_cfi_ref cfi;
1493 register dw_fde_ref fde;
1495 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1497 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1499 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1501 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1502 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1503 fputc ('\n', asm_out_file);
1506 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1508 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1510 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1512 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1513 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1515 fputc ('\n', asm_out_file);
1516 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1517 fputc ('\n', asm_out_file);
1519 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1521 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1523 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1525 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1526 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1528 fputc ('\n', asm_out_file);
1532 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1534 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1535 dwarf_cfi_name (cfi->dw_cfi_opc));
1537 fputc ('\n', asm_out_file);
1538 switch (cfi->dw_cfi_opc)
1540 case DW_CFA_set_loc:
1541 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1542 fputc ('\n', asm_out_file);
1544 case DW_CFA_advance_loc1:
1545 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1546 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1547 fde->dw_fde_current_label);
1548 fputc ('\n', asm_out_file);
1549 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1551 case DW_CFA_advance_loc2:
1552 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1553 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1554 fde->dw_fde_current_label);
1555 fputc ('\n', asm_out_file);
1556 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1558 case DW_CFA_advance_loc4:
1559 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1560 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1561 fde->dw_fde_current_label);
1562 fputc ('\n', asm_out_file);
1563 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1565 #ifdef MIPS_DEBUGGING_INFO
1566 case DW_CFA_MIPS_advance_loc8:
1567 /* TODO: not currently implemented. */
1571 case DW_CFA_offset_extended:
1572 case DW_CFA_def_cfa:
1573 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1574 fputc ('\n', asm_out_file);
1575 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1576 fputc ('\n', asm_out_file);
1578 case DW_CFA_restore_extended:
1579 case DW_CFA_undefined:
1580 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1581 fputc ('\n', asm_out_file);
1583 case DW_CFA_same_value:
1584 case DW_CFA_def_cfa_register:
1585 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1586 fputc ('\n', asm_out_file);
1588 case DW_CFA_register:
1589 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1590 fputc ('\n', asm_out_file);
1591 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1592 fputc ('\n', asm_out_file);
1594 case DW_CFA_def_cfa_offset:
1595 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1596 fputc ('\n', asm_out_file);
1598 case DW_CFA_GNU_window_save:
1600 case DW_CFA_GNU_args_size:
1601 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1602 fputc ('\n', asm_out_file);
1610 #if !defined (EH_FRAME_SECTION)
1611 #if defined (EH_FRAME_SECTION_ASM_OP)
1612 #define EH_FRAME_SECTION() eh_frame_section();
1614 #if defined (ASM_OUTPUT_SECTION_NAME)
1615 #define EH_FRAME_SECTION() \
1617 named_section (NULL_TREE, ".eh_frame", 0); \
1623 /* Output the call frame information used to used to record information
1624 that relates to calculating the frame pointer, and records the
1625 location of saved registers. */
1628 output_call_frame_info (for_eh)
1631 register unsigned long i;
1632 register dw_fde_ref fde;
1633 register dw_cfi_ref cfi;
1634 char l1[20], l2[20];
1635 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1639 /* Do we want to include a pointer to the exception table? */
1640 int eh_ptr = for_eh && exception_table_p ();
1642 fputc ('\n', asm_out_file);
1644 /* We're going to be generating comments, so turn on app. */
1650 #ifdef EH_FRAME_SECTION
1651 EH_FRAME_SECTION ();
1653 tree label = get_file_function_name ('F');
1656 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1657 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1658 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1660 assemble_label ("__FRAME_BEGIN__");
1663 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1665 /* Output the CIE. */
1666 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1667 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1668 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1669 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1671 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1673 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1676 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1678 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1681 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1684 fputc ('\n', asm_out_file);
1685 ASM_OUTPUT_LABEL (asm_out_file, l1);
1688 /* Now that the CIE pointer is PC-relative for EH,
1689 use 0 to identify the CIE. */
1690 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1692 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1695 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1697 fputc ('\n', asm_out_file);
1698 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1700 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1701 fputc ('\n', asm_out_file);
1704 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1706 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1708 fputc ('\n', asm_out_file);
1711 /* The CIE contains a pointer to the exception region info for the
1712 frame. Make the augmentation string three bytes (including the
1713 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1714 can't handle unaligned relocs. */
1717 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1718 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1722 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1724 fputc ('\n', asm_out_file);
1726 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1728 fprintf (asm_out_file, "\t%s pointer to exception region info",
1733 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1735 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1739 fputc ('\n', asm_out_file);
1742 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1744 fputc ('\n', asm_out_file);
1745 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1747 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1749 fputc ('\n', asm_out_file);
1750 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1752 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1754 fputc ('\n', asm_out_file);
1756 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1757 output_cfi (cfi, NULL);
1759 /* Pad the CIE out to an address sized boundary. */
1760 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1761 ASM_OUTPUT_LABEL (asm_out_file, l2);
1762 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1763 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1765 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1766 fputc ('\n', asm_out_file);
1769 /* Loop through all of the FDE's. */
1770 for (i = 0; i < fde_table_in_use; ++i)
1772 fde = &fde_table[i];
1774 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2);
1775 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2);
1776 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1777 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2);
1779 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1781 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1784 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1786 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1789 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1790 fputc ('\n', asm_out_file);
1791 ASM_OUTPUT_LABEL (asm_out_file, l1);
1794 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l1, "__FRAME_BEGIN__");
1796 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1798 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1800 fputc ('\n', asm_out_file);
1801 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1803 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1805 fputc ('\n', asm_out_file);
1806 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1807 fde->dw_fde_end, fde->dw_fde_begin);
1809 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1811 fputc ('\n', asm_out_file);
1813 /* Loop through the Call Frame Instructions associated with
1815 fde->dw_fde_current_label = fde->dw_fde_begin;
1816 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1817 output_cfi (cfi, fde);
1819 /* Pad the FDE out to an address sized boundary. */
1820 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1821 ASM_OUTPUT_LABEL (asm_out_file, l2);
1822 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1823 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1825 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1826 fputc ('\n', asm_out_file);
1829 #ifndef EH_FRAME_SECTION
1832 /* Emit terminating zero for table. */
1833 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1834 fputc ('\n', asm_out_file);
1837 #ifdef MIPS_DEBUGGING_INFO
1838 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1839 get a value of 0. Putting .align 0 after the label fixes it. */
1840 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1843 /* Turn off app to make assembly quicker. */
1848 /* Output a marker (i.e. a label) for the beginning of a function, before
1852 dwarf2out_begin_prologue ()
1854 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1855 register dw_fde_ref fde;
1857 ++current_funcdef_number;
1859 function_section (current_function_decl);
1860 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1861 current_funcdef_number);
1862 ASM_OUTPUT_LABEL (asm_out_file, label);
1864 /* Expand the fde table if necessary. */
1865 if (fde_table_in_use == fde_table_allocated)
1867 fde_table_allocated += FDE_TABLE_INCREMENT;
1869 = (dw_fde_ref) xrealloc (fde_table,
1870 fde_table_allocated * sizeof (dw_fde_node));
1873 /* Record the FDE associated with this function. */
1874 current_funcdef_fde = fde_table_in_use;
1876 /* Add the new FDE at the end of the fde_table. */
1877 fde = &fde_table[fde_table_in_use++];
1878 fde->dw_fde_begin = xstrdup (label);
1879 fde->dw_fde_current_label = NULL;
1880 fde->dw_fde_end = NULL;
1881 fde->dw_fde_cfi = NULL;
1883 args_size = old_args_size = 0;
1886 /* Output a marker (i.e. a label) for the absolute end of the generated code
1887 for a function definition. This gets called *after* the epilogue code has
1891 dwarf2out_end_epilogue ()
1894 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1896 /* Output a label to mark the endpoint of the code generated for this
1898 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1899 ASM_OUTPUT_LABEL (asm_out_file, label);
1900 fde = &fde_table[fde_table_in_use - 1];
1901 fde->dw_fde_end = xstrdup (label);
1905 dwarf2out_frame_init ()
1907 /* Allocate the initial hunk of the fde_table. */
1909 = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1910 bzero ((char *) fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1911 fde_table_allocated = FDE_TABLE_INCREMENT;
1912 fde_table_in_use = 0;
1914 /* Generate the CFA instructions common to all FDE's. Do it now for the
1915 sake of lookup_cfa. */
1917 #ifdef DWARF2_UNWIND_INFO
1918 /* On entry, the Canonical Frame Address is at SP. */
1919 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1920 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1925 dwarf2out_frame_finish ()
1927 /* Output call frame information. */
1928 #ifdef MIPS_DEBUGGING_INFO
1929 if (write_symbols == DWARF2_DEBUG)
1930 output_call_frame_info (0);
1931 if (flag_exceptions && ! exceptions_via_longjmp)
1932 output_call_frame_info (1);
1934 if (write_symbols == DWARF2_DEBUG
1935 || (flag_exceptions && ! exceptions_via_longjmp))
1936 output_call_frame_info (1);
1940 #endif /* .debug_frame support */
1942 /* And now, the support for symbolic debugging information. */
1943 #ifdef DWARF2_DEBUGGING_INFO
1945 extern char *getpwd ();
1947 /* NOTE: In the comments in this file, many references are made to
1948 "Debugging Information Entries". This term is abbreviated as `DIE'
1949 throughout the remainder of this file. */
1951 /* An internal representation of the DWARF output is built, and then
1952 walked to generate the DWARF debugging info. The walk of the internal
1953 representation is done after the entire program has been compiled.
1954 The types below are used to describe the internal representation. */
1956 /* Each DIE may have a series of attribute/value pairs. Values
1957 can take on several forms. The forms that are used in this
1958 implementation are listed below. */
1965 dw_val_class_unsigned_const,
1966 dw_val_class_long_long,
1969 dw_val_class_die_ref,
1970 dw_val_class_fde_ref,
1971 dw_val_class_lbl_id,
1972 dw_val_class_section_offset,
1977 /* Various DIE's use offsets relative to the beginning of the
1978 .debug_info section to refer to each other. */
1980 typedef long int dw_offset;
1982 /* Define typedefs here to avoid circular dependencies. */
1984 typedef struct die_struct *dw_die_ref;
1985 typedef struct dw_attr_struct *dw_attr_ref;
1986 typedef struct dw_val_struct *dw_val_ref;
1987 typedef struct dw_line_info_struct *dw_line_info_ref;
1988 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
1989 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1990 typedef struct pubname_struct *pubname_ref;
1991 typedef dw_die_ref *arange_ref;
1993 /* Describe a double word constant value. */
1995 typedef struct dw_long_long_struct
2002 /* Describe a floating point constant value. */
2004 typedef struct dw_fp_struct
2011 /* Each entry in the line_info_table maintains the file and
2012 line number associated with the label generated for that
2013 entry. The label gives the PC value associated with
2014 the line number entry. */
2016 typedef struct dw_line_info_struct
2018 unsigned long dw_file_num;
2019 unsigned long dw_line_num;
2023 /* Line information for functions in separate sections; each one gets its
2025 typedef struct dw_separate_line_info_struct
2027 unsigned long dw_file_num;
2028 unsigned long dw_line_num;
2029 unsigned long function;
2031 dw_separate_line_info_entry;
2033 /* The dw_val_node describes an attribute's value, as it is
2034 represented internally. */
2036 typedef struct dw_val_struct
2038 dw_val_class val_class;
2042 dw_loc_descr_ref val_loc;
2044 long unsigned val_unsigned;
2045 dw_long_long_const val_long_long;
2046 dw_float_const val_float;
2047 dw_die_ref val_die_ref;
2048 unsigned val_fde_index;
2052 unsigned char val_flag;
2058 /* Locations in memory are described using a sequence of stack machine
2061 typedef struct dw_loc_descr_struct
2063 dw_loc_descr_ref dw_loc_next;
2064 enum dwarf_location_atom dw_loc_opc;
2065 dw_val_node dw_loc_oprnd1;
2066 dw_val_node dw_loc_oprnd2;
2070 /* Each DIE attribute has a field specifying the attribute kind,
2071 a link to the next attribute in the chain, and an attribute value.
2072 Attributes are typically linked below the DIE they modify. */
2074 typedef struct dw_attr_struct
2076 enum dwarf_attribute dw_attr;
2077 dw_attr_ref dw_attr_next;
2078 dw_val_node dw_attr_val;
2082 /* The Debugging Information Entry (DIE) structure */
2084 typedef struct die_struct
2086 enum dwarf_tag die_tag;
2087 dw_attr_ref die_attr;
2088 dw_attr_ref die_attr_last;
2089 dw_die_ref die_parent;
2090 dw_die_ref die_child;
2091 dw_die_ref die_child_last;
2093 dw_offset die_offset;
2094 unsigned long die_abbrev;
2098 /* The pubname structure */
2100 typedef struct pubname_struct
2107 /* The limbo die list structure. */
2108 typedef struct limbo_die_struct
2111 struct limbo_die_struct *next;
2115 /* How to start an assembler comment. */
2116 #ifndef ASM_COMMENT_START
2117 #define ASM_COMMENT_START ";#"
2120 /* Define a macro which returns non-zero for a TYPE_DECL which was
2121 implicitly generated for a tagged type.
2123 Note that unlike the gcc front end (which generates a NULL named
2124 TYPE_DECL node for each complete tagged type, each array type, and
2125 each function type node created) the g++ front end generates a
2126 _named_ TYPE_DECL node for each tagged type node created.
2127 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2128 generate a DW_TAG_typedef DIE for them. */
2130 #define TYPE_DECL_IS_STUB(decl) \
2131 (DECL_NAME (decl) == NULL_TREE \
2132 || (DECL_ARTIFICIAL (decl) \
2133 && is_tagged_type (TREE_TYPE (decl)) \
2134 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2135 /* This is necessary for stub decls that \
2136 appear in nested inline functions. */ \
2137 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2138 && (decl_ultimate_origin (decl) \
2139 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2141 /* Information concerning the compilation unit's programming
2142 language, and compiler version. */
2144 extern int flag_traditional;
2145 extern char *version_string;
2146 extern char *language_string;
2148 /* Fixed size portion of the DWARF compilation unit header. */
2149 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2151 /* Fixed size portion of debugging line information prolog. */
2152 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2154 /* Fixed size portion of public names info. */
2155 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2157 /* Fixed size portion of the address range info. */
2158 #define DWARF_ARANGES_HEADER_SIZE \
2159 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
2161 /* Define the architecture-dependent minimum instruction length (in bytes).
2162 In this implementation of DWARF, this field is used for information
2163 purposes only. Since GCC generates assembly language, we have
2164 no a priori knowledge of how many instruction bytes are generated
2165 for each source line, and therefore can use only the DW_LNE_set_address
2166 and DW_LNS_fixed_advance_pc line information commands. */
2168 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2169 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2172 /* Minimum line offset in a special line info. opcode.
2173 This value was chosen to give a reasonable range of values. */
2174 #define DWARF_LINE_BASE -10
2176 /* First special line opcde - leave room for the standard opcodes. */
2177 #define DWARF_LINE_OPCODE_BASE 10
2179 /* Range of line offsets in a special line info. opcode. */
2180 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2182 /* Flag that indicates the initial value of the is_stmt_start flag.
2183 In the present implementation, we do not mark any lines as
2184 the beginning of a source statement, because that information
2185 is not made available by the GCC front-end. */
2186 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2188 /* This location is used by calc_die_sizes() to keep track
2189 the offset of each DIE within the .debug_info section. */
2190 static unsigned long next_die_offset;
2192 /* Record the root of the DIE's built for the current compilation unit. */
2193 static dw_die_ref comp_unit_die;
2195 /* A list of DIEs with a NULL parent waiting to be relocated. */
2196 static limbo_die_node *limbo_die_list = 0;
2198 /* Pointer to an array of filenames referenced by this compilation unit. */
2199 static char **file_table;
2201 /* Total number of entries in the table (i.e. array) pointed to by
2202 `file_table'. This is the *total* and includes both used and unused
2204 static unsigned file_table_allocated;
2206 /* Number of entries in the file_table which are actually in use. */
2207 static unsigned file_table_in_use;
2209 /* Size (in elements) of increments by which we may expand the filename
2211 #define FILE_TABLE_INCREMENT 64
2213 /* Local pointer to the name of the main input file. Initialized in
2215 static char *primary_filename;
2217 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
2218 which their beginnings are encountered. We output Dwarf debugging info
2219 that refers to the beginnings and ends of the ranges of code for each
2220 lexical block. The labels themselves are generated in final.c, which
2221 assigns numbers to the blocks in the same way. */
2222 static unsigned next_block_number = 2;
2224 /* A pointer to the base of a table of references to DIE's that describe
2225 declarations. The table is indexed by DECL_UID() which is a unique
2226 number identifying each decl. */
2227 static dw_die_ref *decl_die_table;
2229 /* Number of elements currently allocated for the decl_die_table. */
2230 static unsigned decl_die_table_allocated;
2232 /* Number of elements in decl_die_table currently in use. */
2233 static unsigned decl_die_table_in_use;
2235 /* Size (in elements) of increments by which we may expand the
2237 #define DECL_DIE_TABLE_INCREMENT 256
2239 /* Structure used for the decl_scope table. scope is the current declaration
2240 scope, and previous is the entry that is the parent of this scope. This
2241 is usually but not always the immediately preceeding entry. */
2243 typedef struct decl_scope_struct
2250 /* A pointer to the base of a table of references to declaration
2251 scopes. This table is a display which tracks the nesting
2252 of declaration scopes at the current scope and containing
2253 scopes. This table is used to find the proper place to
2254 define type declaration DIE's. */
2255 static decl_scope_node *decl_scope_table;
2257 /* Number of elements currently allocated for the decl_scope_table. */
2258 static int decl_scope_table_allocated;
2260 /* Current level of nesting of declaration scopes. */
2261 static int decl_scope_depth;
2263 /* Size (in elements) of increments by which we may expand the
2264 decl_scope_table. */
2265 #define DECL_SCOPE_TABLE_INCREMENT 64
2267 /* A pointer to the base of a list of references to DIE's that
2268 are uniquely identified by their tag, presence/absence of
2269 children DIE's, and list of attribute/value pairs. */
2270 static dw_die_ref *abbrev_die_table;
2272 /* Number of elements currently allocated for abbrev_die_table. */
2273 static unsigned abbrev_die_table_allocated;
2275 /* Number of elements in type_die_table currently in use. */
2276 static unsigned abbrev_die_table_in_use;
2278 /* Size (in elements) of increments by which we may expand the
2279 abbrev_die_table. */
2280 #define ABBREV_DIE_TABLE_INCREMENT 256
2282 /* A pointer to the base of a table that contains line information
2283 for each source code line in .text in the compilation unit. */
2284 static dw_line_info_ref line_info_table;
2286 /* Number of elements currently allocated for line_info_table. */
2287 static unsigned line_info_table_allocated;
2289 /* Number of elements in separate_line_info_table currently in use. */
2290 static unsigned separate_line_info_table_in_use;
2292 /* A pointer to the base of a table that contains line information
2293 for each source code line outside of .text in the compilation unit. */
2294 static dw_separate_line_info_ref separate_line_info_table;
2296 /* Number of elements currently allocated for separate_line_info_table. */
2297 static unsigned separate_line_info_table_allocated;
2299 /* Number of elements in line_info_table currently in use. */
2300 static unsigned line_info_table_in_use;
2302 /* Size (in elements) of increments by which we may expand the
2304 #define LINE_INFO_TABLE_INCREMENT 1024
2306 /* A pointer to the base of a table that contains a list of publicly
2307 accessible names. */
2308 static pubname_ref pubname_table;
2310 /* Number of elements currently allocated for pubname_table. */
2311 static unsigned pubname_table_allocated;
2313 /* Number of elements in pubname_table currently in use. */
2314 static unsigned pubname_table_in_use;
2316 /* Size (in elements) of increments by which we may expand the
2318 #define PUBNAME_TABLE_INCREMENT 64
2320 /* A pointer to the base of a table that contains a list of publicly
2321 accessible names. */
2322 static arange_ref arange_table;
2324 /* Number of elements currently allocated for arange_table. */
2325 static unsigned arange_table_allocated;
2327 /* Number of elements in arange_table currently in use. */
2328 static unsigned arange_table_in_use;
2330 /* Size (in elements) of increments by which we may expand the
2332 #define ARANGE_TABLE_INCREMENT 64
2334 /* A pointer to the base of a list of pending types which we haven't
2335 generated DIEs for yet, but which we will have to come back to
2338 static tree *pending_types_list;
2340 /* Number of elements currently allocated for the pending_types_list. */
2341 static unsigned pending_types_allocated;
2343 /* Number of elements of pending_types_list currently in use. */
2344 static unsigned pending_types;
2346 /* Size (in elements) of increments by which we may expand the pending
2347 types list. Actually, a single hunk of space of this size should
2348 be enough for most typical programs. */
2349 #define PENDING_TYPES_INCREMENT 64
2351 /* Record whether the function being analyzed contains inlined functions. */
2352 static int current_function_has_inlines;
2353 #if 0 && defined (MIPS_DEBUGGING_INFO)
2354 static int comp_unit_has_inlines;
2357 /* A pointer to the ..._DECL node which we have most recently been working
2358 on. We keep this around just in case something about it looks screwy and
2359 we want to tell the user what the source coordinates for the actual
2361 static tree dwarf_last_decl;
2363 /* Forward declarations for functions defined in this file. */
2365 static void addr_const_to_string PROTO((char *, rtx));
2366 static char *addr_to_string PROTO((rtx));
2367 static int is_pseudo_reg PROTO((rtx));
2368 static tree type_main_variant PROTO((tree));
2369 static int is_tagged_type PROTO((tree));
2370 static char *dwarf_tag_name PROTO((unsigned));
2371 static char *dwarf_attr_name PROTO((unsigned));
2372 static char *dwarf_form_name PROTO((unsigned));
2373 static char *dwarf_stack_op_name PROTO((unsigned));
2374 static char *dwarf_type_encoding_name PROTO((unsigned));
2375 static tree decl_ultimate_origin PROTO((tree));
2376 static tree block_ultimate_origin PROTO((tree));
2377 static tree decl_class_context PROTO((tree));
2378 static void add_dwarf_attr PROTO((dw_die_ref, dw_attr_ref));
2379 static void add_AT_flag PROTO((dw_die_ref,
2380 enum dwarf_attribute,
2382 static void add_AT_int PROTO((dw_die_ref,
2383 enum dwarf_attribute, long));
2384 static void add_AT_unsigned PROTO((dw_die_ref,
2385 enum dwarf_attribute,
2387 static void add_AT_long_long PROTO((dw_die_ref,
2388 enum dwarf_attribute,
2389 unsigned long, unsigned long));
2390 static void add_AT_float PROTO((dw_die_ref,
2391 enum dwarf_attribute,
2393 static void add_AT_string PROTO((dw_die_ref,
2394 enum dwarf_attribute, char *));
2395 static void add_AT_die_ref PROTO((dw_die_ref,
2396 enum dwarf_attribute,
2398 static void add_AT_fde_ref PROTO((dw_die_ref,
2399 enum dwarf_attribute,
2401 static void add_AT_loc PROTO((dw_die_ref,
2402 enum dwarf_attribute,
2404 static void add_AT_addr PROTO((dw_die_ref,
2405 enum dwarf_attribute, char *));
2406 static void add_AT_lbl_id PROTO((dw_die_ref,
2407 enum dwarf_attribute, char *));
2408 static void add_AT_section_offset PROTO((dw_die_ref,
2409 enum dwarf_attribute, char *));
2410 static int is_extern_subr_die PROTO((dw_die_ref));
2411 static dw_attr_ref get_AT PROTO((dw_die_ref,
2412 enum dwarf_attribute));
2413 static char *get_AT_low_pc PROTO((dw_die_ref));
2414 static char *get_AT_hi_pc PROTO((dw_die_ref));
2415 static char *get_AT_string PROTO((dw_die_ref,
2416 enum dwarf_attribute));
2417 static int get_AT_flag PROTO((dw_die_ref,
2418 enum dwarf_attribute));
2419 static unsigned get_AT_unsigned PROTO((dw_die_ref,
2420 enum dwarf_attribute));
2421 static int is_c_family PROTO((void));
2422 static int is_fortran PROTO((void));
2423 static void remove_AT PROTO((dw_die_ref,
2424 enum dwarf_attribute));
2425 static void remove_children PROTO((dw_die_ref));
2426 static void add_child_die PROTO((dw_die_ref, dw_die_ref));
2427 static dw_die_ref new_die PROTO((enum dwarf_tag, dw_die_ref));
2428 static dw_die_ref lookup_type_die PROTO((tree));
2429 static void equate_type_number_to_die PROTO((tree, dw_die_ref));
2430 static dw_die_ref lookup_decl_die PROTO((tree));
2431 static void equate_decl_number_to_die PROTO((tree, dw_die_ref));
2432 static dw_loc_descr_ref new_loc_descr PROTO((enum dwarf_location_atom,
2433 unsigned long, unsigned long));
2434 static void add_loc_descr PROTO((dw_loc_descr_ref *,
2436 static void print_spaces PROTO((FILE *));
2437 static void print_die PROTO((dw_die_ref, FILE *));
2438 static void print_dwarf_line_table PROTO((FILE *));
2439 static void add_sibling_attributes PROTO((dw_die_ref));
2440 static void build_abbrev_table PROTO((dw_die_ref));
2441 static unsigned long size_of_string PROTO((char *));
2442 static unsigned long size_of_loc_descr PROTO((dw_loc_descr_ref));
2443 static unsigned long size_of_locs PROTO((dw_loc_descr_ref));
2444 static int constant_size PROTO((long unsigned));
2445 static unsigned long size_of_die PROTO((dw_die_ref));
2446 static void calc_die_sizes PROTO((dw_die_ref));
2447 static unsigned long size_of_line_prolog PROTO((void));
2448 static unsigned long size_of_line_info PROTO((void));
2449 static unsigned long size_of_pubnames PROTO((void));
2450 static unsigned long size_of_aranges PROTO((void));
2451 static enum dwarf_form value_format PROTO((dw_val_ref));
2452 static void output_value_format PROTO((dw_val_ref));
2453 static void output_abbrev_section PROTO((void));
2454 static void output_loc_operands PROTO((dw_loc_descr_ref));
2455 static unsigned long sibling_offset PROTO((dw_die_ref));
2456 static void output_die PROTO((dw_die_ref));
2457 static void output_compilation_unit_header PROTO((void));
2458 static char *dwarf2_name PROTO((tree, int));
2459 static void add_pubname PROTO((tree, dw_die_ref));
2460 static void output_pubnames PROTO((void));
2461 static void add_arange PROTO((tree, dw_die_ref));
2462 static void output_aranges PROTO((void));
2463 static void output_line_info PROTO((void));
2464 static int is_body_block PROTO((tree));
2465 static dw_die_ref base_type_die PROTO((tree));
2466 static tree root_type PROTO((tree));
2467 static int is_base_type PROTO((tree));
2468 static dw_die_ref modified_type_die PROTO((tree, int, int, dw_die_ref));
2469 static int type_is_enum PROTO((tree));
2470 static dw_loc_descr_ref reg_loc_descriptor PROTO((rtx));
2471 static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long));
2472 static int is_based_loc PROTO((rtx));
2473 static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx));
2474 static dw_loc_descr_ref concat_loc_descriptor PROTO((rtx, rtx));
2475 static dw_loc_descr_ref loc_descriptor PROTO((rtx));
2476 static unsigned ceiling PROTO((unsigned, unsigned));
2477 static tree field_type PROTO((tree));
2478 static unsigned simple_type_align_in_bits PROTO((tree));
2479 static unsigned simple_type_size_in_bits PROTO((tree));
2480 static unsigned field_byte_offset PROTO((tree));
2481 static void add_AT_location_description PROTO((dw_die_ref,
2482 enum dwarf_attribute, rtx));
2483 static void add_data_member_location_attribute PROTO((dw_die_ref, tree));
2484 static void add_const_value_attribute PROTO((dw_die_ref, rtx));
2485 static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree));
2486 static void add_name_attribute PROTO((dw_die_ref, char *));
2487 static void add_bound_info PROTO((dw_die_ref,
2488 enum dwarf_attribute, tree));
2489 static void add_subscript_info PROTO((dw_die_ref, tree));
2490 static void add_byte_size_attribute PROTO((dw_die_ref, tree));
2491 static void add_bit_offset_attribute PROTO((dw_die_ref, tree));
2492 static void add_bit_size_attribute PROTO((dw_die_ref, tree));
2493 static void add_prototyped_attribute PROTO((dw_die_ref, tree));
2494 static void add_abstract_origin_attribute PROTO((dw_die_ref, tree));
2495 static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree));
2496 static void add_src_coords_attributes PROTO((dw_die_ref, tree));
2497 static void add_name_and_src_coords_attributes PROTO((dw_die_ref, tree));
2498 static void push_decl_scope PROTO((tree));
2499 static dw_die_ref scope_die_for PROTO((tree, dw_die_ref));
2500 static void pop_decl_scope PROTO((void));
2501 static void add_type_attribute PROTO((dw_die_ref, tree, int, int,
2503 static char *type_tag PROTO((tree));
2504 static tree member_declared_type PROTO((tree));
2505 static char *decl_start_label PROTO((tree));
2506 static void gen_array_type_die PROTO((tree, dw_die_ref));
2507 static void gen_set_type_die PROTO((tree, dw_die_ref));
2508 static void gen_entry_point_die PROTO((tree, dw_die_ref));
2509 static void pend_type PROTO((tree));
2510 static void output_pending_types_for_scope PROTO((dw_die_ref));
2511 static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref));
2512 static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref));
2513 static void gen_inlined_union_type_die PROTO((tree, dw_die_ref));
2514 static void gen_enumeration_type_die PROTO((tree, dw_die_ref));
2515 static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref));
2516 static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref));
2517 static void gen_formal_types_die PROTO((tree, dw_die_ref));
2518 static void gen_subprogram_die PROTO((tree, dw_die_ref));
2519 static void gen_variable_die PROTO((tree, dw_die_ref));
2520 static void gen_label_die PROTO((tree, dw_die_ref));
2521 static void gen_lexical_block_die PROTO((tree, dw_die_ref, int));
2522 static void gen_inlined_subroutine_die PROTO((tree, dw_die_ref, int));
2523 static void gen_field_die PROTO((tree, dw_die_ref));
2524 static void gen_ptr_to_mbr_type_die PROTO((tree, dw_die_ref));
2525 static void gen_compile_unit_die PROTO((char *));
2526 static void gen_string_type_die PROTO((tree, dw_die_ref));
2527 static void gen_inheritance_die PROTO((tree, dw_die_ref));
2528 static void gen_member_die PROTO((tree, dw_die_ref));
2529 static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref));
2530 static void gen_subroutine_type_die PROTO((tree, dw_die_ref));
2531 static void gen_typedef_die PROTO((tree, dw_die_ref));
2532 static void gen_type_die PROTO((tree, dw_die_ref));
2533 static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref));
2534 static void gen_block_die PROTO((tree, dw_die_ref, int));
2535 static void decls_for_scope PROTO((tree, dw_die_ref, int));
2536 static int is_redundant_typedef PROTO((tree));
2537 static void gen_decl_die PROTO((tree, dw_die_ref));
2538 static unsigned lookup_filename PROTO((char *));
2540 /* Section names used to hold DWARF debugging information. */
2541 #ifndef DEBUG_INFO_SECTION
2542 #define DEBUG_INFO_SECTION ".debug_info"
2544 #ifndef ABBREV_SECTION
2545 #define ABBREV_SECTION ".debug_abbrev"
2547 #ifndef ARANGES_SECTION
2548 #define ARANGES_SECTION ".debug_aranges"
2550 #ifndef DW_MACINFO_SECTION
2551 #define DW_MACINFO_SECTION ".debug_macinfo"
2553 #ifndef DEBUG_LINE_SECTION
2554 #define DEBUG_LINE_SECTION ".debug_line"
2557 #define LOC_SECTION ".debug_loc"
2559 #ifndef PUBNAMES_SECTION
2560 #define PUBNAMES_SECTION ".debug_pubnames"
2563 #define STR_SECTION ".debug_str"
2566 /* Standard ELF section names for compiled code and data. */
2567 #ifndef TEXT_SECTION
2568 #define TEXT_SECTION ".text"
2570 #ifndef DATA_SECTION
2571 #define DATA_SECTION ".data"
2574 #define BSS_SECTION ".bss"
2578 /* Definitions of defaults for formats and names of various special
2579 (artificial) labels which may be generated within this file (when the -g
2580 options is used and DWARF_DEBUGGING_INFO is in effect.
2581 If necessary, these may be overridden from within the tm.h file, but
2582 typically, overriding these defaults is unnecessary. */
2584 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2586 #ifndef TEXT_END_LABEL
2587 #define TEXT_END_LABEL "Letext"
2589 #ifndef DATA_END_LABEL
2590 #define DATA_END_LABEL "Ledata"
2592 #ifndef BSS_END_LABEL
2593 #define BSS_END_LABEL "Lebss"
2595 #ifndef INSN_LABEL_FMT
2596 #define INSN_LABEL_FMT "LI%u_"
2598 #ifndef BLOCK_BEGIN_LABEL
2599 #define BLOCK_BEGIN_LABEL "LBB"
2601 #ifndef BLOCK_END_LABEL
2602 #define BLOCK_END_LABEL "LBE"
2604 #ifndef BODY_BEGIN_LABEL
2605 #define BODY_BEGIN_LABEL "Lbb"
2607 #ifndef BODY_END_LABEL
2608 #define BODY_END_LABEL "Lbe"
2610 #ifndef LINE_CODE_LABEL
2611 #define LINE_CODE_LABEL "LM"
2613 #ifndef SEPARATE_LINE_CODE_LABEL
2614 #define SEPARATE_LINE_CODE_LABEL "LSM"
2617 /* Convert a reference to the assembler name of a C-level name. This
2618 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
2619 a string rather than writing to a file. */
2620 #ifndef ASM_NAME_TO_STRING
2621 #define ASM_NAME_TO_STRING(STR, NAME) \
2623 if ((NAME)[0] == '*') \
2624 strcpy (STR, NAME+1); \
2626 strcpy (STR, NAME); \
2631 /* Convert an integer constant expression into assembler syntax. Addition
2632 and subtraction are the only arithmetic that may appear in these
2633 expressions. This is an adaptation of output_addr_const in final.c.
2634 Here, the target of the conversion is a string buffer. We can't use
2635 output_addr_const directly, because it writes to a file. */
2638 addr_const_to_string (str, x)
2647 switch (GET_CODE (x))
2657 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
2662 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2663 ASM_NAME_TO_STRING (buf2, buf1);
2668 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
2669 ASM_NAME_TO_STRING (buf2, buf1);
2674 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
2679 /* This used to output parentheses around the expression, but that does
2680 not work on the 386 (either ATT or BSD assembler). */
2681 addr_const_to_string (buf1, XEXP (x, 0));
2686 if (GET_MODE (x) == VOIDmode)
2688 /* We can use %d if the number is one word and positive. */
2689 if (CONST_DOUBLE_HIGH (x))
2690 sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
2691 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2692 else if (CONST_DOUBLE_LOW (x) < 0)
2693 sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
2695 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
2696 CONST_DOUBLE_LOW (x));
2700 /* We can't handle floating point constants; PRINT_OPERAND must
2702 output_operand_lossage ("floating constant misused");
2706 /* Some assemblers need integer constants to appear last (eg masm). */
2707 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2709 addr_const_to_string (buf1, XEXP (x, 1));
2711 if (INTVAL (XEXP (x, 0)) >= 0)
2714 addr_const_to_string (buf1, XEXP (x, 0));
2719 addr_const_to_string (buf1, XEXP (x, 0));
2721 if (INTVAL (XEXP (x, 1)) >= 0)
2724 addr_const_to_string (buf1, XEXP (x, 1));
2730 /* Avoid outputting things like x-x or x+5-x, since some assemblers
2731 can't handle that. */
2732 x = simplify_subtraction (x);
2733 if (GET_CODE (x) != MINUS)
2736 addr_const_to_string (buf1, XEXP (x, 0));
2739 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2740 && INTVAL (XEXP (x, 1)) < 0)
2742 strcat (str, ASM_OPEN_PAREN);
2743 addr_const_to_string (buf1, XEXP (x, 1));
2745 strcat (str, ASM_CLOSE_PAREN);
2749 addr_const_to_string (buf1, XEXP (x, 1));
2756 addr_const_to_string (buf1, XEXP (x, 0));
2761 output_operand_lossage ("invalid expression as operand");
2765 /* Convert an address constant to a string, and return a pointer to
2766 a copy of the result, located on the heap. */
2773 addr_const_to_string (buf, x);
2774 return xstrdup (buf);
2777 /* Test if rtl node points to a pseudo register. */
2783 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
2784 || ((GET_CODE (rtl) == SUBREG)
2785 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
2788 /* Return a reference to a type, with its const and volatile qualifiers
2792 type_main_variant (type)
2795 type = TYPE_MAIN_VARIANT (type);
2797 /* There really should be only one main variant among any group of variants
2798 of a given type (and all of the MAIN_VARIANT values for all members of
2799 the group should point to that one type) but sometimes the C front-end
2800 messes this up for array types, so we work around that bug here. */
2802 if (TREE_CODE (type) == ARRAY_TYPE)
2803 while (type != TYPE_MAIN_VARIANT (type))
2804 type = TYPE_MAIN_VARIANT (type);
2809 /* Return non-zero if the given type node represents a tagged type. */
2812 is_tagged_type (type)
2815 register enum tree_code code = TREE_CODE (type);
2817 return (code == RECORD_TYPE || code == UNION_TYPE
2818 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
2821 /* Convert a DIE tag into its string name. */
2824 dwarf_tag_name (tag)
2825 register unsigned tag;
2829 case DW_TAG_padding:
2830 return "DW_TAG_padding";
2831 case DW_TAG_array_type:
2832 return "DW_TAG_array_type";
2833 case DW_TAG_class_type:
2834 return "DW_TAG_class_type";
2835 case DW_TAG_entry_point:
2836 return "DW_TAG_entry_point";
2837 case DW_TAG_enumeration_type:
2838 return "DW_TAG_enumeration_type";
2839 case DW_TAG_formal_parameter:
2840 return "DW_TAG_formal_parameter";
2841 case DW_TAG_imported_declaration:
2842 return "DW_TAG_imported_declaration";
2844 return "DW_TAG_label";
2845 case DW_TAG_lexical_block:
2846 return "DW_TAG_lexical_block";
2848 return "DW_TAG_member";
2849 case DW_TAG_pointer_type:
2850 return "DW_TAG_pointer_type";
2851 case DW_TAG_reference_type:
2852 return "DW_TAG_reference_type";
2853 case DW_TAG_compile_unit:
2854 return "DW_TAG_compile_unit";
2855 case DW_TAG_string_type:
2856 return "DW_TAG_string_type";
2857 case DW_TAG_structure_type:
2858 return "DW_TAG_structure_type";
2859 case DW_TAG_subroutine_type:
2860 return "DW_TAG_subroutine_type";
2861 case DW_TAG_typedef:
2862 return "DW_TAG_typedef";
2863 case DW_TAG_union_type:
2864 return "DW_TAG_union_type";
2865 case DW_TAG_unspecified_parameters:
2866 return "DW_TAG_unspecified_parameters";
2867 case DW_TAG_variant:
2868 return "DW_TAG_variant";
2869 case DW_TAG_common_block:
2870 return "DW_TAG_common_block";
2871 case DW_TAG_common_inclusion:
2872 return "DW_TAG_common_inclusion";
2873 case DW_TAG_inheritance:
2874 return "DW_TAG_inheritance";
2875 case DW_TAG_inlined_subroutine:
2876 return "DW_TAG_inlined_subroutine";
2878 return "DW_TAG_module";
2879 case DW_TAG_ptr_to_member_type:
2880 return "DW_TAG_ptr_to_member_type";
2881 case DW_TAG_set_type:
2882 return "DW_TAG_set_type";
2883 case DW_TAG_subrange_type:
2884 return "DW_TAG_subrange_type";
2885 case DW_TAG_with_stmt:
2886 return "DW_TAG_with_stmt";
2887 case DW_TAG_access_declaration:
2888 return "DW_TAG_access_declaration";
2889 case DW_TAG_base_type:
2890 return "DW_TAG_base_type";
2891 case DW_TAG_catch_block:
2892 return "DW_TAG_catch_block";
2893 case DW_TAG_const_type:
2894 return "DW_TAG_const_type";
2895 case DW_TAG_constant:
2896 return "DW_TAG_constant";
2897 case DW_TAG_enumerator:
2898 return "DW_TAG_enumerator";
2899 case DW_TAG_file_type:
2900 return "DW_TAG_file_type";
2902 return "DW_TAG_friend";
2903 case DW_TAG_namelist:
2904 return "DW_TAG_namelist";
2905 case DW_TAG_namelist_item:
2906 return "DW_TAG_namelist_item";
2907 case DW_TAG_packed_type:
2908 return "DW_TAG_packed_type";
2909 case DW_TAG_subprogram:
2910 return "DW_TAG_subprogram";
2911 case DW_TAG_template_type_param:
2912 return "DW_TAG_template_type_param";
2913 case DW_TAG_template_value_param:
2914 return "DW_TAG_template_value_param";
2915 case DW_TAG_thrown_type:
2916 return "DW_TAG_thrown_type";
2917 case DW_TAG_try_block:
2918 return "DW_TAG_try_block";
2919 case DW_TAG_variant_part:
2920 return "DW_TAG_variant_part";
2921 case DW_TAG_variable:
2922 return "DW_TAG_variable";
2923 case DW_TAG_volatile_type:
2924 return "DW_TAG_volatile_type";
2925 case DW_TAG_MIPS_loop:
2926 return "DW_TAG_MIPS_loop";
2927 case DW_TAG_format_label:
2928 return "DW_TAG_format_label";
2929 case DW_TAG_function_template:
2930 return "DW_TAG_function_template";
2931 case DW_TAG_class_template:
2932 return "DW_TAG_class_template";
2934 return "DW_TAG_<unknown>";
2938 /* Convert a DWARF attribute code into its string name. */
2941 dwarf_attr_name (attr)
2942 register unsigned attr;
2947 return "DW_AT_sibling";
2948 case DW_AT_location:
2949 return "DW_AT_location";
2951 return "DW_AT_name";
2952 case DW_AT_ordering:
2953 return "DW_AT_ordering";
2954 case DW_AT_subscr_data:
2955 return "DW_AT_subscr_data";
2956 case DW_AT_byte_size:
2957 return "DW_AT_byte_size";
2958 case DW_AT_bit_offset:
2959 return "DW_AT_bit_offset";
2960 case DW_AT_bit_size:
2961 return "DW_AT_bit_size";
2962 case DW_AT_element_list:
2963 return "DW_AT_element_list";
2964 case DW_AT_stmt_list:
2965 return "DW_AT_stmt_list";
2967 return "DW_AT_low_pc";
2969 return "DW_AT_high_pc";
2970 case DW_AT_language:
2971 return "DW_AT_language";
2973 return "DW_AT_member";
2975 return "DW_AT_discr";
2976 case DW_AT_discr_value:
2977 return "DW_AT_discr_value";
2978 case DW_AT_visibility:
2979 return "DW_AT_visibility";
2981 return "DW_AT_import";
2982 case DW_AT_string_length:
2983 return "DW_AT_string_length";
2984 case DW_AT_common_reference:
2985 return "DW_AT_common_reference";
2986 case DW_AT_comp_dir:
2987 return "DW_AT_comp_dir";
2988 case DW_AT_const_value:
2989 return "DW_AT_const_value";
2990 case DW_AT_containing_type:
2991 return "DW_AT_containing_type";
2992 case DW_AT_default_value:
2993 return "DW_AT_default_value";
2995 return "DW_AT_inline";
2996 case DW_AT_is_optional:
2997 return "DW_AT_is_optional";
2998 case DW_AT_lower_bound:
2999 return "DW_AT_lower_bound";
3000 case DW_AT_producer:
3001 return "DW_AT_producer";
3002 case DW_AT_prototyped:
3003 return "DW_AT_prototyped";
3004 case DW_AT_return_addr:
3005 return "DW_AT_return_addr";
3006 case DW_AT_start_scope:
3007 return "DW_AT_start_scope";
3008 case DW_AT_stride_size:
3009 return "DW_AT_stride_size";
3010 case DW_AT_upper_bound:
3011 return "DW_AT_upper_bound";
3012 case DW_AT_abstract_origin:
3013 return "DW_AT_abstract_origin";
3014 case DW_AT_accessibility:
3015 return "DW_AT_accessibility";
3016 case DW_AT_address_class:
3017 return "DW_AT_address_class";
3018 case DW_AT_artificial:
3019 return "DW_AT_artificial";
3020 case DW_AT_base_types:
3021 return "DW_AT_base_types";
3022 case DW_AT_calling_convention:
3023 return "DW_AT_calling_convention";
3025 return "DW_AT_count";
3026 case DW_AT_data_member_location:
3027 return "DW_AT_data_member_location";
3028 case DW_AT_decl_column:
3029 return "DW_AT_decl_column";
3030 case DW_AT_decl_file:
3031 return "DW_AT_decl_file";
3032 case DW_AT_decl_line:
3033 return "DW_AT_decl_line";
3034 case DW_AT_declaration:
3035 return "DW_AT_declaration";
3036 case DW_AT_discr_list:
3037 return "DW_AT_discr_list";
3038 case DW_AT_encoding:
3039 return "DW_AT_encoding";
3040 case DW_AT_external:
3041 return "DW_AT_external";
3042 case DW_AT_frame_base:
3043 return "DW_AT_frame_base";
3045 return "DW_AT_friend";
3046 case DW_AT_identifier_case:
3047 return "DW_AT_identifier_case";
3048 case DW_AT_macro_info:
3049 return "DW_AT_macro_info";
3050 case DW_AT_namelist_items:
3051 return "DW_AT_namelist_items";
3052 case DW_AT_priority:
3053 return "DW_AT_priority";
3055 return "DW_AT_segment";
3056 case DW_AT_specification:
3057 return "DW_AT_specification";
3058 case DW_AT_static_link:
3059 return "DW_AT_static_link";
3061 return "DW_AT_type";
3062 case DW_AT_use_location:
3063 return "DW_AT_use_location";
3064 case DW_AT_variable_parameter:
3065 return "DW_AT_variable_parameter";
3066 case DW_AT_virtuality:
3067 return "DW_AT_virtuality";
3068 case DW_AT_vtable_elem_location:
3069 return "DW_AT_vtable_elem_location";
3071 case DW_AT_MIPS_fde:
3072 return "DW_AT_MIPS_fde";
3073 case DW_AT_MIPS_loop_begin:
3074 return "DW_AT_MIPS_loop_begin";
3075 case DW_AT_MIPS_tail_loop_begin:
3076 return "DW_AT_MIPS_tail_loop_begin";
3077 case DW_AT_MIPS_epilog_begin:
3078 return "DW_AT_MIPS_epilog_begin";
3079 case DW_AT_MIPS_loop_unroll_factor:
3080 return "DW_AT_MIPS_loop_unroll_factor";
3081 case DW_AT_MIPS_software_pipeline_depth:
3082 return "DW_AT_MIPS_software_pipeline_depth";
3083 case DW_AT_MIPS_linkage_name:
3084 return "DW_AT_MIPS_linkage_name";
3085 case DW_AT_MIPS_stride:
3086 return "DW_AT_MIPS_stride";
3087 case DW_AT_MIPS_abstract_name:
3088 return "DW_AT_MIPS_abstract_name";
3089 case DW_AT_MIPS_clone_origin:
3090 return "DW_AT_MIPS_clone_origin";
3091 case DW_AT_MIPS_has_inlines:
3092 return "DW_AT_MIPS_has_inlines";
3094 case DW_AT_sf_names:
3095 return "DW_AT_sf_names";
3096 case DW_AT_src_info:
3097 return "DW_AT_src_info";
3098 case DW_AT_mac_info:
3099 return "DW_AT_mac_info";
3100 case DW_AT_src_coords:
3101 return "DW_AT_src_coords";
3102 case DW_AT_body_begin:
3103 return "DW_AT_body_begin";
3104 case DW_AT_body_end:
3105 return "DW_AT_body_end";
3107 return "DW_AT_<unknown>";
3111 /* Convert a DWARF value form code into its string name. */
3114 dwarf_form_name (form)
3115 register unsigned form;
3120 return "DW_FORM_addr";
3121 case DW_FORM_block2:
3122 return "DW_FORM_block2";
3123 case DW_FORM_block4:
3124 return "DW_FORM_block4";
3126 return "DW_FORM_data2";
3128 return "DW_FORM_data4";
3130 return "DW_FORM_data8";
3131 case DW_FORM_string:
3132 return "DW_FORM_string";
3134 return "DW_FORM_block";
3135 case DW_FORM_block1:
3136 return "DW_FORM_block1";
3138 return "DW_FORM_data1";
3140 return "DW_FORM_flag";
3142 return "DW_FORM_sdata";
3144 return "DW_FORM_strp";
3146 return "DW_FORM_udata";
3147 case DW_FORM_ref_addr:
3148 return "DW_FORM_ref_addr";
3150 return "DW_FORM_ref1";
3152 return "DW_FORM_ref2";
3154 return "DW_FORM_ref4";
3156 return "DW_FORM_ref8";
3157 case DW_FORM_ref_udata:
3158 return "DW_FORM_ref_udata";
3159 case DW_FORM_indirect:
3160 return "DW_FORM_indirect";
3162 return "DW_FORM_<unknown>";
3166 /* Convert a DWARF stack opcode into its string name. */
3169 dwarf_stack_op_name (op)
3170 register unsigned op;
3175 return "DW_OP_addr";
3177 return "DW_OP_deref";
3179 return "DW_OP_const1u";
3181 return "DW_OP_const1s";
3183 return "DW_OP_const2u";
3185 return "DW_OP_const2s";
3187 return "DW_OP_const4u";
3189 return "DW_OP_const4s";
3191 return "DW_OP_const8u";
3193 return "DW_OP_const8s";
3195 return "DW_OP_constu";
3197 return "DW_OP_consts";
3201 return "DW_OP_drop";
3203 return "DW_OP_over";
3205 return "DW_OP_pick";
3207 return "DW_OP_swap";
3211 return "DW_OP_xderef";
3219 return "DW_OP_minus";
3231 return "DW_OP_plus";
3232 case DW_OP_plus_uconst:
3233 return "DW_OP_plus_uconst";
3239 return "DW_OP_shra";
3257 return "DW_OP_skip";
3259 return "DW_OP_lit0";
3261 return "DW_OP_lit1";
3263 return "DW_OP_lit2";
3265 return "DW_OP_lit3";
3267 return "DW_OP_lit4";
3269 return "DW_OP_lit5";
3271 return "DW_OP_lit6";
3273 return "DW_OP_lit7";
3275 return "DW_OP_lit8";
3277 return "DW_OP_lit9";
3279 return "DW_OP_lit10";
3281 return "DW_OP_lit11";
3283 return "DW_OP_lit12";
3285 return "DW_OP_lit13";
3287 return "DW_OP_lit14";
3289 return "DW_OP_lit15";
3291 return "DW_OP_lit16";
3293 return "DW_OP_lit17";
3295 return "DW_OP_lit18";
3297 return "DW_OP_lit19";
3299 return "DW_OP_lit20";
3301 return "DW_OP_lit21";
3303 return "DW_OP_lit22";
3305 return "DW_OP_lit23";
3307 return "DW_OP_lit24";
3309 return "DW_OP_lit25";
3311 return "DW_OP_lit26";
3313 return "DW_OP_lit27";
3315 return "DW_OP_lit28";
3317 return "DW_OP_lit29";
3319 return "DW_OP_lit30";
3321 return "DW_OP_lit31";
3323 return "DW_OP_reg0";
3325 return "DW_OP_reg1";
3327 return "DW_OP_reg2";
3329 return "DW_OP_reg3";
3331 return "DW_OP_reg4";
3333 return "DW_OP_reg5";
3335 return "DW_OP_reg6";
3337 return "DW_OP_reg7";
3339 return "DW_OP_reg8";
3341 return "DW_OP_reg9";
3343 return "DW_OP_reg10";
3345 return "DW_OP_reg11";
3347 return "DW_OP_reg12";
3349 return "DW_OP_reg13";
3351 return "DW_OP_reg14";
3353 return "DW_OP_reg15";
3355 return "DW_OP_reg16";
3357 return "DW_OP_reg17";
3359 return "DW_OP_reg18";
3361 return "DW_OP_reg19";
3363 return "DW_OP_reg20";
3365 return "DW_OP_reg21";
3367 return "DW_OP_reg22";
3369 return "DW_OP_reg23";
3371 return "DW_OP_reg24";
3373 return "DW_OP_reg25";
3375 return "DW_OP_reg26";
3377 return "DW_OP_reg27";
3379 return "DW_OP_reg28";
3381 return "DW_OP_reg29";
3383 return "DW_OP_reg30";
3385 return "DW_OP_reg31";
3387 return "DW_OP_breg0";
3389 return "DW_OP_breg1";
3391 return "DW_OP_breg2";
3393 return "DW_OP_breg3";
3395 return "DW_OP_breg4";
3397 return "DW_OP_breg5";
3399 return "DW_OP_breg6";
3401 return "DW_OP_breg7";
3403 return "DW_OP_breg8";
3405 return "DW_OP_breg9";
3407 return "DW_OP_breg10";
3409 return "DW_OP_breg11";
3411 return "DW_OP_breg12";
3413 return "DW_OP_breg13";
3415 return "DW_OP_breg14";
3417 return "DW_OP_breg15";
3419 return "DW_OP_breg16";
3421 return "DW_OP_breg17";
3423 return "DW_OP_breg18";
3425 return "DW_OP_breg19";
3427 return "DW_OP_breg20";
3429 return "DW_OP_breg21";
3431 return "DW_OP_breg22";
3433 return "DW_OP_breg23";
3435 return "DW_OP_breg24";
3437 return "DW_OP_breg25";
3439 return "DW_OP_breg26";
3441 return "DW_OP_breg27";
3443 return "DW_OP_breg28";
3445 return "DW_OP_breg29";
3447 return "DW_OP_breg30";
3449 return "DW_OP_breg31";
3451 return "DW_OP_regx";
3453 return "DW_OP_fbreg";
3455 return "DW_OP_bregx";
3457 return "DW_OP_piece";
3458 case DW_OP_deref_size:
3459 return "DW_OP_deref_size";
3460 case DW_OP_xderef_size:
3461 return "DW_OP_xderef_size";
3465 return "OP_<unknown>";
3469 /* Convert a DWARF type code into its string name. */
3472 dwarf_type_encoding_name (enc)
3473 register unsigned enc;
3477 case DW_ATE_address:
3478 return "DW_ATE_address";
3479 case DW_ATE_boolean:
3480 return "DW_ATE_boolean";
3481 case DW_ATE_complex_float:
3482 return "DW_ATE_complex_float";
3484 return "DW_ATE_float";
3486 return "DW_ATE_signed";
3487 case DW_ATE_signed_char:
3488 return "DW_ATE_signed_char";
3489 case DW_ATE_unsigned:
3490 return "DW_ATE_unsigned";
3491 case DW_ATE_unsigned_char:
3492 return "DW_ATE_unsigned_char";
3494 return "DW_ATE_<unknown>";
3498 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3499 instance of an inlined instance of a decl which is local to an inline
3500 function, so we have to trace all of the way back through the origin chain
3501 to find out what sort of node actually served as the original seed for the
3505 decl_ultimate_origin (decl)
3508 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
3510 if (immediate_origin == NULL_TREE)
3514 register tree ret_val;
3515 register tree lookahead = immediate_origin;
3519 ret_val = lookahead;
3520 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
3522 while (lookahead != NULL && lookahead != ret_val);
3528 /* Determine the "ultimate origin" of a block. The block may be an inlined
3529 instance of an inlined instance of a block which is local to an inline
3530 function, so we have to trace all of the way back through the origin chain
3531 to find out what sort of node actually served as the original seed for the
3535 block_ultimate_origin (block)
3536 register tree block;
3538 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3540 if (immediate_origin == NULL_TREE)
3544 register tree ret_val;
3545 register tree lookahead = immediate_origin;
3549 ret_val = lookahead;
3550 lookahead = (TREE_CODE (ret_val) == BLOCK)
3551 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3554 while (lookahead != NULL && lookahead != ret_val);
3560 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3561 of a virtual function may refer to a base class, so we check the 'this'
3565 decl_class_context (decl)
3568 tree context = NULL_TREE;
3570 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3571 context = DECL_CONTEXT (decl);
3573 context = TYPE_MAIN_VARIANT
3574 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3576 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
3577 context = NULL_TREE;
3582 /* Add an attribute/value pair to a DIE */
3585 add_dwarf_attr (die, attr)
3586 register dw_die_ref die;
3587 register dw_attr_ref attr;
3589 if (die != NULL && attr != NULL)
3591 if (die->die_attr == NULL)
3593 die->die_attr = attr;
3594 die->die_attr_last = attr;
3598 die->die_attr_last->dw_attr_next = attr;
3599 die->die_attr_last = attr;
3604 /* Add a flag value attribute to a DIE. */
3607 add_AT_flag (die, attr_kind, flag)
3608 register dw_die_ref die;
3609 register enum dwarf_attribute attr_kind;
3610 register unsigned flag;
3612 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3614 attr->dw_attr_next = NULL;
3615 attr->dw_attr = attr_kind;
3616 attr->dw_attr_val.val_class = dw_val_class_flag;
3617 attr->dw_attr_val.v.val_flag = flag;
3618 add_dwarf_attr (die, attr);
3621 /* Add a signed integer attribute value to a DIE. */
3624 add_AT_int (die, attr_kind, int_val)
3625 register dw_die_ref die;
3626 register enum dwarf_attribute attr_kind;
3627 register long int int_val;
3629 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3631 attr->dw_attr_next = NULL;
3632 attr->dw_attr = attr_kind;
3633 attr->dw_attr_val.val_class = dw_val_class_const;
3634 attr->dw_attr_val.v.val_int = int_val;
3635 add_dwarf_attr (die, attr);
3638 /* Add an unsigned integer attribute value to a DIE. */
3641 add_AT_unsigned (die, attr_kind, unsigned_val)
3642 register dw_die_ref die;
3643 register enum dwarf_attribute attr_kind;
3644 register unsigned long unsigned_val;
3646 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3648 attr->dw_attr_next = NULL;
3649 attr->dw_attr = attr_kind;
3650 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
3651 attr->dw_attr_val.v.val_unsigned = unsigned_val;
3652 add_dwarf_attr (die, attr);
3655 /* Add an unsigned double integer attribute value to a DIE. */
3658 add_AT_long_long (die, attr_kind, val_hi, val_low)
3659 register dw_die_ref die;
3660 register enum dwarf_attribute attr_kind;
3661 register unsigned long val_hi;
3662 register unsigned long val_low;
3664 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3666 attr->dw_attr_next = NULL;
3667 attr->dw_attr = attr_kind;
3668 attr->dw_attr_val.val_class = dw_val_class_long_long;
3669 attr->dw_attr_val.v.val_long_long.hi = val_hi;
3670 attr->dw_attr_val.v.val_long_long.low = val_low;
3671 add_dwarf_attr (die, attr);
3674 /* Add a floating point attribute value to a DIE and return it. */
3677 add_AT_float (die, attr_kind, length, array)
3678 register dw_die_ref die;
3679 register enum dwarf_attribute attr_kind;
3680 register unsigned length;
3681 register long *array;
3683 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3685 attr->dw_attr_next = NULL;
3686 attr->dw_attr = attr_kind;
3687 attr->dw_attr_val.val_class = dw_val_class_float;
3688 attr->dw_attr_val.v.val_float.length = length;
3689 attr->dw_attr_val.v.val_float.array = array;
3690 add_dwarf_attr (die, attr);
3693 /* Add a string attribute value to a DIE. */
3696 add_AT_string (die, attr_kind, str)
3697 register dw_die_ref die;
3698 register enum dwarf_attribute attr_kind;
3701 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3703 attr->dw_attr_next = NULL;
3704 attr->dw_attr = attr_kind;
3705 attr->dw_attr_val.val_class = dw_val_class_str;
3706 attr->dw_attr_val.v.val_str = xstrdup (str);
3707 add_dwarf_attr (die, attr);
3710 /* Add a DIE reference attribute value to a DIE. */
3713 add_AT_die_ref (die, attr_kind, targ_die)
3714 register dw_die_ref die;
3715 register enum dwarf_attribute attr_kind;
3716 register dw_die_ref targ_die;
3718 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3720 attr->dw_attr_next = NULL;
3721 attr->dw_attr = attr_kind;
3722 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3723 attr->dw_attr_val.v.val_die_ref = targ_die;
3724 add_dwarf_attr (die, attr);
3727 /* Add an FDE reference attribute value to a DIE. */
3730 add_AT_fde_ref (die, attr_kind, targ_fde)
3731 register dw_die_ref die;
3732 register enum dwarf_attribute attr_kind;
3733 register unsigned targ_fde;
3735 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3737 attr->dw_attr_next = NULL;
3738 attr->dw_attr = attr_kind;
3739 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
3740 attr->dw_attr_val.v.val_fde_index = targ_fde;
3741 add_dwarf_attr (die, attr);
3744 /* Add a location description attribute value to a DIE. */
3747 add_AT_loc (die, attr_kind, loc)
3748 register dw_die_ref die;
3749 register enum dwarf_attribute attr_kind;
3750 register dw_loc_descr_ref loc;
3752 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3754 attr->dw_attr_next = NULL;
3755 attr->dw_attr = attr_kind;
3756 attr->dw_attr_val.val_class = dw_val_class_loc;
3757 attr->dw_attr_val.v.val_loc = loc;
3758 add_dwarf_attr (die, attr);
3761 /* Add an address constant attribute value to a DIE. */
3764 add_AT_addr (die, attr_kind, addr)
3765 register dw_die_ref die;
3766 register enum dwarf_attribute attr_kind;
3769 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3771 attr->dw_attr_next = NULL;
3772 attr->dw_attr = attr_kind;
3773 attr->dw_attr_val.val_class = dw_val_class_addr;
3774 attr->dw_attr_val.v.val_addr = addr;
3775 add_dwarf_attr (die, attr);
3778 /* Add a label identifier attribute value to a DIE. */
3781 add_AT_lbl_id (die, attr_kind, lbl_id)
3782 register dw_die_ref die;
3783 register enum dwarf_attribute attr_kind;
3784 register char *lbl_id;
3786 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3788 attr->dw_attr_next = NULL;
3789 attr->dw_attr = attr_kind;
3790 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
3791 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
3792 add_dwarf_attr (die, attr);
3795 /* Add a section offset attribute value to a DIE. */
3798 add_AT_section_offset (die, attr_kind, section)
3799 register dw_die_ref die;
3800 register enum dwarf_attribute attr_kind;
3801 register char *section;
3803 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3805 attr->dw_attr_next = NULL;
3806 attr->dw_attr = attr_kind;
3807 attr->dw_attr_val.val_class = dw_val_class_section_offset;
3808 attr->dw_attr_val.v.val_section = section;
3809 add_dwarf_attr (die, attr);
3813 /* Test if die refers to an external subroutine. */
3816 is_extern_subr_die (die)
3817 register dw_die_ref die;
3819 register dw_attr_ref a;
3820 register int is_subr = FALSE;
3821 register int is_extern = FALSE;
3823 if (die != NULL && die->die_tag == DW_TAG_subprogram)
3826 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3828 if (a->dw_attr == DW_AT_external
3829 && a->dw_attr_val.val_class == dw_val_class_flag
3830 && a->dw_attr_val.v.val_flag != 0)
3838 return is_subr && is_extern;
3841 /* Get the attribute of type attr_kind. */
3843 static inline dw_attr_ref
3844 get_AT (die, attr_kind)
3845 register dw_die_ref die;
3846 register enum dwarf_attribute attr_kind;
3848 register dw_attr_ref a;
3849 register dw_die_ref spec = NULL;
3853 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3855 if (a->dw_attr == attr_kind)
3858 if (a->dw_attr == DW_AT_specification
3859 || a->dw_attr == DW_AT_abstract_origin)
3860 spec = a->dw_attr_val.v.val_die_ref;
3864 return get_AT (spec, attr_kind);
3870 /* Return the "low pc" attribute value, typically associated with
3871 a subprogram DIE. Return null if the "low pc" attribute is
3872 either not prsent, or if it cannot be represented as an
3873 assembler label identifier. */
3875 static inline char *
3877 register dw_die_ref die;
3879 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
3881 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3882 return a->dw_attr_val.v.val_lbl_id;
3887 /* Return the "high pc" attribute value, typically associated with
3888 a subprogram DIE. Return null if the "high pc" attribute is
3889 either not prsent, or if it cannot be represented as an
3890 assembler label identifier. */
3892 static inline char *
3894 register dw_die_ref die;
3896 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
3898 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3899 return a->dw_attr_val.v.val_lbl_id;
3904 /* Return the value of the string attribute designated by ATTR_KIND, or
3905 NULL if it is not present. */
3907 static inline char *
3908 get_AT_string (die, attr_kind)
3909 register dw_die_ref die;
3910 register enum dwarf_attribute attr_kind;
3912 register dw_attr_ref a = get_AT (die, attr_kind);
3914 if (a && a->dw_attr_val.val_class == dw_val_class_str)
3915 return a->dw_attr_val.v.val_str;
3920 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3921 if it is not present. */
3924 get_AT_flag (die, attr_kind)
3925 register dw_die_ref die;
3926 register enum dwarf_attribute attr_kind;
3928 register dw_attr_ref a = get_AT (die, attr_kind);
3930 if (a && a->dw_attr_val.val_class == dw_val_class_flag)
3931 return a->dw_attr_val.v.val_flag;
3936 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3937 if it is not present. */
3939 static inline unsigned
3940 get_AT_unsigned (die, attr_kind)
3941 register dw_die_ref die;
3942 register enum dwarf_attribute attr_kind;
3944 register dw_attr_ref a = get_AT (die, attr_kind);
3946 if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
3947 return a->dw_attr_val.v.val_unsigned;
3955 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3957 return (lang == DW_LANG_C || lang == DW_LANG_C89
3958 || lang == DW_LANG_C_plus_plus);
3964 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3966 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
3969 /* Remove the specified attribute if present. */
3972 remove_AT (die, attr_kind)
3973 register dw_die_ref die;
3974 register enum dwarf_attribute attr_kind;
3976 register dw_attr_ref a;
3977 register dw_attr_ref removed = NULL;;
3981 if (die->die_attr->dw_attr == attr_kind)
3983 removed = die->die_attr;
3984 if (die->die_attr_last == die->die_attr)
3985 die->die_attr_last = NULL;
3987 die->die_attr = die->die_attr->dw_attr_next;
3991 for (a = die->die_attr; a->dw_attr_next != NULL;
3992 a = a->dw_attr_next)
3993 if (a->dw_attr_next->dw_attr == attr_kind)
3995 removed = a->dw_attr_next;
3996 if (die->die_attr_last == a->dw_attr_next)
3997 die->die_attr_last = a;
3999 a->dw_attr_next = a->dw_attr_next->dw_attr_next;
4008 /* Discard the children of this DIE. */
4011 remove_children (die)
4012 register dw_die_ref die;
4014 register dw_die_ref child_die = die->die_child;
4016 die->die_child = NULL;
4017 die->die_child_last = NULL;
4019 while (child_die != NULL)
4021 register dw_die_ref tmp_die = child_die;
4022 register dw_attr_ref a;
4024 child_die = child_die->die_sib;
4026 for (a = tmp_die->die_attr; a != NULL; )
4028 register dw_attr_ref tmp_a = a;
4030 a = a->dw_attr_next;
4038 /* Add a child DIE below its parent. */
4041 add_child_die (die, child_die)
4042 register dw_die_ref die;
4043 register dw_die_ref child_die;
4045 if (die != NULL && child_die != NULL)
4047 if (die == child_die)
4049 child_die->die_parent = die;
4050 child_die->die_sib = NULL;
4052 if (die->die_child == NULL)
4054 die->die_child = child_die;
4055 die->die_child_last = child_die;
4059 die->die_child_last->die_sib = child_die;
4060 die->die_child_last = child_die;
4065 /* Return a pointer to a newly created DIE node. */
4067 static inline dw_die_ref
4068 new_die (tag_value, parent_die)
4069 register enum dwarf_tag tag_value;
4070 register dw_die_ref parent_die;
4072 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4074 die->die_tag = tag_value;
4075 die->die_abbrev = 0;
4076 die->die_offset = 0;
4077 die->die_child = NULL;
4078 die->die_parent = NULL;
4079 die->die_sib = NULL;
4080 die->die_child_last = NULL;
4081 die->die_attr = NULL;
4082 die->die_attr_last = NULL;
4084 if (parent_die != NULL)
4085 add_child_die (parent_die, die);
4088 limbo_die_node *limbo_node;
4090 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4091 limbo_node->die = die;
4092 limbo_node->next = limbo_die_list;
4093 limbo_die_list = limbo_node;
4099 /* Return the DIE associated with the given type specifier. */
4101 static inline dw_die_ref
4102 lookup_type_die (type)
4105 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4108 /* Equate a DIE to a given type specifier. */
4111 equate_type_number_to_die (type, type_die)
4113 register dw_die_ref type_die;
4115 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4118 /* Return the DIE associated with a given declaration. */
4120 static inline dw_die_ref
4121 lookup_decl_die (decl)
4124 register unsigned decl_id = DECL_UID (decl);
4126 return (decl_id < decl_die_table_in_use
4127 ? decl_die_table[decl_id] : NULL);
4130 /* Equate a DIE to a particular declaration. */
4133 equate_decl_number_to_die (decl, decl_die)
4135 register dw_die_ref decl_die;
4137 register unsigned decl_id = DECL_UID (decl);
4138 register unsigned num_allocated;
4140 if (decl_id >= decl_die_table_allocated)
4143 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4144 / DECL_DIE_TABLE_INCREMENT)
4145 * DECL_DIE_TABLE_INCREMENT;
4148 = (dw_die_ref *) xrealloc (decl_die_table,
4149 sizeof (dw_die_ref) * num_allocated);
4151 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4152 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4153 decl_die_table_allocated = num_allocated;
4156 if (decl_id >= decl_die_table_in_use)
4157 decl_die_table_in_use = (decl_id + 1);
4159 decl_die_table[decl_id] = decl_die;
4162 /* Return a pointer to a newly allocated location description. Location
4163 descriptions are simple expression terms that can be strung
4164 together to form more complicated location (address) descriptions. */
4166 static inline dw_loc_descr_ref
4167 new_loc_descr (op, oprnd1, oprnd2)
4168 register enum dwarf_location_atom op;
4169 register unsigned long oprnd1;
4170 register unsigned long oprnd2;
4172 register dw_loc_descr_ref descr
4173 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
4175 descr->dw_loc_next = NULL;
4176 descr->dw_loc_opc = op;
4177 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4178 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4179 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4180 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4185 /* Add a location description term to a location description expression. */
4188 add_loc_descr (list_head, descr)
4189 register dw_loc_descr_ref *list_head;
4190 register dw_loc_descr_ref descr;
4192 register dw_loc_descr_ref *d;
4194 /* Find the end of the chain. */
4195 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4201 /* Keep track of the number of spaces used to indent the
4202 output of the debugging routines that print the structure of
4203 the DIE internal representation. */
4204 static int print_indent;
4206 /* Indent the line the number of spaces given by print_indent. */
4209 print_spaces (outfile)
4212 fprintf (outfile, "%*s", print_indent, "");
4215 /* Print the information associated with a given DIE, and its children.
4216 This routine is a debugging aid only. */
4219 print_die (die, outfile)
4223 register dw_attr_ref a;
4224 register dw_die_ref c;
4226 print_spaces (outfile);
4227 fprintf (outfile, "DIE %4lu: %s\n",
4228 die->die_offset, dwarf_tag_name (die->die_tag));
4229 print_spaces (outfile);
4230 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4231 fprintf (outfile, " offset: %lu\n", die->die_offset);
4233 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4235 print_spaces (outfile);
4236 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4238 switch (a->dw_attr_val.val_class)
4240 case dw_val_class_addr:
4241 fprintf (outfile, "address");
4243 case dw_val_class_loc:
4244 fprintf (outfile, "location descriptor");
4246 case dw_val_class_const:
4247 fprintf (outfile, "%ld", a->dw_attr_val.v.val_int);
4249 case dw_val_class_unsigned_const:
4250 fprintf (outfile, "%lu", a->dw_attr_val.v.val_unsigned);
4252 case dw_val_class_long_long:
4253 fprintf (outfile, "constant (%lu,%lu)",
4254 a->dw_attr_val.v.val_long_long.hi,
4255 a->dw_attr_val.v.val_long_long.low);
4257 case dw_val_class_float:
4258 fprintf (outfile, "floating-point constant");
4260 case dw_val_class_flag:
4261 fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
4263 case dw_val_class_die_ref:
4264 if (a->dw_attr_val.v.val_die_ref != NULL)
4265 fprintf (outfile, "die -> %lu",
4266 a->dw_attr_val.v.val_die_ref->die_offset);
4268 fprintf (outfile, "die -> <null>");
4270 case dw_val_class_lbl_id:
4271 fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
4273 case dw_val_class_section_offset:
4274 fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section);
4276 case dw_val_class_str:
4277 if (a->dw_attr_val.v.val_str != NULL)
4278 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
4280 fprintf (outfile, "<null>");
4286 fprintf (outfile, "\n");
4289 if (die->die_child != NULL)
4292 for (c = die->die_child; c != NULL; c = c->die_sib)
4293 print_die (c, outfile);
4299 /* Print the contents of the source code line number correspondence table.
4300 This routine is a debugging aid only. */
4303 print_dwarf_line_table (outfile)
4306 register unsigned i;
4307 register dw_line_info_ref line_info;
4309 fprintf (outfile, "\n\nDWARF source line information\n");
4310 for (i = 1; i < line_info_table_in_use; ++i)
4312 line_info = &line_info_table[i];
4313 fprintf (outfile, "%5d: ", i);
4314 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4315 fprintf (outfile, "%6ld", line_info->dw_line_num);
4316 fprintf (outfile, "\n");
4319 fprintf (outfile, "\n\n");
4322 /* Print the information collected for a given DIE. */
4325 debug_dwarf_die (die)
4328 print_die (die, stderr);
4331 /* Print all DWARF information collected for the compilation unit.
4332 This routine is a debugging aid only. */
4338 print_die (comp_unit_die, stderr);
4339 print_dwarf_line_table (stderr);
4342 /* Traverse the DIE, and add a sibling attribute if it may have the
4343 effect of speeding up access to siblings. To save some space,
4344 avoid generating sibling attributes for DIE's without children. */
4347 add_sibling_attributes(die)
4348 register dw_die_ref die;
4350 register dw_die_ref c;
4351 register dw_attr_ref attr;
4352 if (die != comp_unit_die && die->die_child != NULL)
4354 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4355 attr->dw_attr_next = NULL;
4356 attr->dw_attr = DW_AT_sibling;
4357 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4358 attr->dw_attr_val.v.val_die_ref = die->die_sib;
4360 /* Add the sibling link to the front of the attribute list. */
4361 attr->dw_attr_next = die->die_attr;
4362 if (die->die_attr == NULL)
4363 die->die_attr_last = attr;
4365 die->die_attr = attr;
4368 for (c = die->die_child; c != NULL; c = c->die_sib)
4369 add_sibling_attributes (c);
4372 /* The format of each DIE (and its attribute value pairs)
4373 is encoded in an abbreviation table. This routine builds the
4374 abbreviation table and assigns a unique abbreviation id for
4375 each abbreviation entry. The children of each die are visited
4379 build_abbrev_table (die)
4380 register dw_die_ref die;
4382 register unsigned long abbrev_id;
4383 register unsigned long n_alloc;
4384 register dw_die_ref c;
4385 register dw_attr_ref d_attr, a_attr;
4386 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4388 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4390 if (abbrev->die_tag == die->die_tag)
4392 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
4394 a_attr = abbrev->die_attr;
4395 d_attr = die->die_attr;
4397 while (a_attr != NULL && d_attr != NULL)
4399 if ((a_attr->dw_attr != d_attr->dw_attr)
4400 || (value_format (&a_attr->dw_attr_val)
4401 != value_format (&d_attr->dw_attr_val)))
4404 a_attr = a_attr->dw_attr_next;
4405 d_attr = d_attr->dw_attr_next;
4408 if (a_attr == NULL && d_attr == NULL)
4414 if (abbrev_id >= abbrev_die_table_in_use)
4416 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
4418 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
4420 = (dw_die_ref *) xrealloc (abbrev_die_table,
4421 sizeof (dw_die_ref) * n_alloc);
4423 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
4424 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
4425 abbrev_die_table_allocated = n_alloc;
4428 ++abbrev_die_table_in_use;
4429 abbrev_die_table[abbrev_id] = die;
4432 die->die_abbrev = abbrev_id;
4433 for (c = die->die_child; c != NULL; c = c->die_sib)
4434 build_abbrev_table (c);
4437 /* Return the size of a string, including the null byte. */
4439 static unsigned long
4440 size_of_string (str)
4443 register unsigned long size = 0;
4444 register unsigned long slen = strlen (str);
4445 register unsigned long i;
4446 register unsigned c;
4448 for (i = 0; i < slen; ++i)
4457 /* Null terminator. */
4462 /* Return the size of a location descriptor. */
4464 static unsigned long
4465 size_of_loc_descr (loc)
4466 register dw_loc_descr_ref loc;
4468 register unsigned long size = 1;
4470 switch (loc->dw_loc_opc)
4492 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4495 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4500 case DW_OP_plus_uconst:
4501 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4539 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4542 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4545 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4548 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4549 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4552 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4554 case DW_OP_deref_size:
4555 case DW_OP_xderef_size:
4565 /* Return the size of a series of location descriptors. */
4567 static unsigned long
4569 register dw_loc_descr_ref loc;
4571 register unsigned long size = 0;
4573 for (; loc != NULL; loc = loc->dw_loc_next)
4574 size += size_of_loc_descr (loc);
4579 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4582 constant_size (value)
4583 long unsigned value;
4590 log = floor_log2 (value);
4593 log = 1 << (floor_log2 (log) + 1);
4598 /* Return the size of a DIE, as it is represented in the
4599 .debug_info section. */
4601 static unsigned long
4603 register dw_die_ref die;
4605 register unsigned long size = 0;
4606 register dw_attr_ref a;
4608 size += size_of_uleb128 (die->die_abbrev);
4609 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4611 switch (a->dw_attr_val.val_class)
4613 case dw_val_class_addr:
4616 case dw_val_class_loc:
4618 register unsigned long lsize
4619 = size_of_locs (a->dw_attr_val.v.val_loc);
4622 size += constant_size (lsize);
4626 case dw_val_class_const:
4629 case dw_val_class_unsigned_const:
4630 size += constant_size (a->dw_attr_val.v.val_unsigned);
4632 case dw_val_class_long_long:
4633 size += 1 + 8; /* block */
4635 case dw_val_class_float:
4636 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
4638 case dw_val_class_flag:
4641 case dw_val_class_die_ref:
4642 size += DWARF_OFFSET_SIZE;
4644 case dw_val_class_fde_ref:
4645 size += DWARF_OFFSET_SIZE;
4647 case dw_val_class_lbl_id:
4650 case dw_val_class_section_offset:
4651 size += DWARF_OFFSET_SIZE;
4653 case dw_val_class_str:
4654 size += size_of_string (a->dw_attr_val.v.val_str);
4664 /* Size the debugging information associated with a given DIE.
4665 Visits the DIE's children recursively. Updates the global
4666 variable next_die_offset, on each time through. Uses the
4667 current value of next_die_offset to update the die_offset
4668 field in each DIE. */
4671 calc_die_sizes (die)
4674 register dw_die_ref c;
4675 die->die_offset = next_die_offset;
4676 next_die_offset += size_of_die (die);
4678 for (c = die->die_child; c != NULL; c = c->die_sib)
4681 if (die->die_child != NULL)
4682 /* Count the null byte used to terminate sibling lists. */
4683 next_die_offset += 1;
4686 /* Return the size of the line information prolog generated for the
4687 compilation unit. */
4689 static unsigned long
4690 size_of_line_prolog ()
4692 register unsigned long size;
4693 register unsigned long ft_index;
4695 size = DWARF_LINE_PROLOG_HEADER_SIZE;
4697 /* Count the size of the table giving number of args for each
4699 size += DWARF_LINE_OPCODE_BASE - 1;
4701 /* Include directory table is empty (at present). Count only the
4702 the null byte used to terminate the table. */
4705 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4707 /* File name entry. */
4708 size += size_of_string (file_table[ft_index]);
4710 /* Include directory index. */
4711 size += size_of_uleb128 (0);
4713 /* Modification time. */
4714 size += size_of_uleb128 (0);
4716 /* File length in bytes. */
4717 size += size_of_uleb128 (0);
4720 /* Count the file table terminator. */
4725 /* Return the size of the line information generated for this
4726 compilation unit. */
4728 static unsigned long
4729 size_of_line_info ()
4731 register unsigned long size;
4732 register unsigned long lt_index;
4733 register unsigned long current_line;
4734 register long line_offset;
4735 register long line_delta;
4736 register unsigned long current_file;
4737 register unsigned long function;
4738 unsigned long size_of_set_address;
4740 /* Size of a DW_LNE_set_address instruction. */
4741 size_of_set_address = 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
4743 /* Version number. */
4746 /* Prolog length specifier. */
4747 size += DWARF_OFFSET_SIZE;
4750 size += size_of_line_prolog ();
4752 /* Set address register instruction. */
4753 size += size_of_set_address;
4757 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
4759 register dw_line_info_ref line_info;
4761 /* Advance pc instruction. */
4762 /* ??? See the DW_LNS_advance_pc comment in output_line_info. */
4766 size += size_of_set_address;
4768 line_info = &line_info_table[lt_index];
4769 if (line_info->dw_file_num != current_file)
4771 /* Set file number instruction. */
4773 current_file = line_info->dw_file_num;
4774 size += size_of_uleb128 (current_file);
4777 if (line_info->dw_line_num != current_line)
4779 line_offset = line_info->dw_line_num - current_line;
4780 line_delta = line_offset - DWARF_LINE_BASE;
4781 current_line = line_info->dw_line_num;
4782 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4783 /* 1-byte special line number instruction. */
4787 /* Advance line instruction. */
4789 size += size_of_sleb128 (line_offset);
4790 /* Generate line entry instruction. */
4796 /* Advance pc instruction. */
4800 size += size_of_set_address;
4802 /* End of line number info. marker. */
4803 size += 1 + size_of_uleb128 (1) + 1;
4808 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
4810 register dw_separate_line_info_ref line_info
4811 = &separate_line_info_table[lt_index];
4812 if (function != line_info->function)
4814 function = line_info->function;
4815 /* Set address register instruction. */
4816 size += size_of_set_address;
4820 /* Advance pc instruction. */
4824 size += size_of_set_address;
4827 if (line_info->dw_file_num != current_file)
4829 /* Set file number instruction. */
4831 current_file = line_info->dw_file_num;
4832 size += size_of_uleb128 (current_file);
4835 if (line_info->dw_line_num != current_line)
4837 line_offset = line_info->dw_line_num - current_line;
4838 line_delta = line_offset - DWARF_LINE_BASE;
4839 current_line = line_info->dw_line_num;
4840 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4841 /* 1-byte special line number instruction. */
4845 /* Advance line instruction. */
4847 size += size_of_sleb128 (line_offset);
4849 /* Generate line entry instruction. */
4856 /* If we're done with a function, end its sequence. */
4857 if (lt_index == separate_line_info_table_in_use
4858 || separate_line_info_table[lt_index].function != function)
4863 /* Advance pc instruction. */
4867 size += size_of_set_address;
4869 /* End of line number info. marker. */
4870 size += 1 + size_of_uleb128 (1) + 1;
4877 /* Return the size of the .debug_pubnames table generated for the
4878 compilation unit. */
4880 static unsigned long
4883 register unsigned long size;
4884 register unsigned i;
4886 size = DWARF_PUBNAMES_HEADER_SIZE;
4887 for (i = 0; i < pubname_table_in_use; ++i)
4889 register pubname_ref p = &pubname_table[i];
4890 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
4893 size += DWARF_OFFSET_SIZE;
4897 /* Return the size of the information in the .debug_aranges section. */
4899 static unsigned long
4902 register unsigned long size;
4904 size = DWARF_ARANGES_HEADER_SIZE;
4906 /* Count the address/length pair for this compilation unit. */
4907 size += 2 * PTR_SIZE;
4908 size += 2 * PTR_SIZE * arange_table_in_use;
4910 /* Count the two zero words used to terminated the address range table. */
4911 size += 2 * PTR_SIZE;
4915 /* Select the encoding of an attribute value. */
4917 static enum dwarf_form
4921 switch (v->val_class)
4923 case dw_val_class_addr:
4924 return DW_FORM_addr;
4925 case dw_val_class_loc:
4926 switch (constant_size (size_of_locs (v->v.val_loc)))
4929 return DW_FORM_block1;
4931 return DW_FORM_block2;
4935 case dw_val_class_const:
4936 return DW_FORM_data4;
4937 case dw_val_class_unsigned_const:
4938 switch (constant_size (v->v.val_unsigned))
4941 return DW_FORM_data1;
4943 return DW_FORM_data2;
4945 return DW_FORM_data4;
4947 return DW_FORM_data8;
4951 case dw_val_class_long_long:
4952 return DW_FORM_block1;
4953 case dw_val_class_float:
4954 return DW_FORM_block1;
4955 case dw_val_class_flag:
4956 return DW_FORM_flag;
4957 case dw_val_class_die_ref:
4959 case dw_val_class_fde_ref:
4960 return DW_FORM_data;
4961 case dw_val_class_lbl_id:
4962 return DW_FORM_addr;
4963 case dw_val_class_section_offset:
4964 return DW_FORM_data;
4965 case dw_val_class_str:
4966 return DW_FORM_string;
4972 /* Output the encoding of an attribute value. */
4975 output_value_format (v)
4978 enum dwarf_form form = value_format (v);
4980 output_uleb128 (form);
4982 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
4984 fputc ('\n', asm_out_file);
4987 /* Output the .debug_abbrev section which defines the DIE abbreviation
4991 output_abbrev_section ()
4993 unsigned long abbrev_id;
4996 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4998 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5000 output_uleb128 (abbrev_id);
5002 fprintf (asm_out_file, " (abbrev code)");
5004 fputc ('\n', asm_out_file);
5005 output_uleb128 (abbrev->die_tag);
5007 fprintf (asm_out_file, " (TAG: %s)",
5008 dwarf_tag_name (abbrev->die_tag));
5010 fputc ('\n', asm_out_file);
5011 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
5012 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
5015 fprintf (asm_out_file, "\t%s %s",
5017 (abbrev->die_child != NULL
5018 ? "DW_children_yes" : "DW_children_no"));
5020 fputc ('\n', asm_out_file);
5022 for (a_attr = abbrev->die_attr; a_attr != NULL;
5023 a_attr = a_attr->dw_attr_next)
5025 output_uleb128 (a_attr->dw_attr);
5027 fprintf (asm_out_file, " (%s)",
5028 dwarf_attr_name (a_attr->dw_attr));
5030 fputc ('\n', asm_out_file);
5031 output_value_format (&a_attr->dw_attr_val);
5034 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
5038 /* Output location description stack opcode's operands (if any). */
5041 output_loc_operands (loc)
5042 register dw_loc_descr_ref loc;
5044 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
5045 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
5047 switch (loc->dw_loc_opc)
5050 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
5051 fputc ('\n', asm_out_file);
5055 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
5056 fputc ('\n', asm_out_file);
5060 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
5061 fputc ('\n', asm_out_file);
5065 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
5066 fputc ('\n', asm_out_file);
5071 fputc ('\n', asm_out_file);
5074 output_uleb128 (val1->v.val_unsigned);
5075 fputc ('\n', asm_out_file);
5078 output_sleb128 (val1->v.val_int);
5079 fputc ('\n', asm_out_file);
5082 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
5083 fputc ('\n', asm_out_file);
5085 case DW_OP_plus_uconst:
5086 output_uleb128 (val1->v.val_unsigned);
5087 fputc ('\n', asm_out_file);
5091 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
5092 fputc ('\n', asm_out_file);
5126 output_sleb128 (val1->v.val_int);
5127 fputc ('\n', asm_out_file);
5130 output_uleb128 (val1->v.val_unsigned);
5131 fputc ('\n', asm_out_file);
5134 output_sleb128 (val1->v.val_int);
5135 fputc ('\n', asm_out_file);
5138 output_uleb128 (val1->v.val_unsigned);
5139 fputc ('\n', asm_out_file);
5140 output_sleb128 (val2->v.val_int);
5141 fputc ('\n', asm_out_file);
5144 output_uleb128 (val1->v.val_unsigned);
5145 fputc ('\n', asm_out_file);
5147 case DW_OP_deref_size:
5148 case DW_OP_xderef_size:
5149 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
5150 fputc ('\n', asm_out_file);
5157 /* Compute the offset of a sibling. */
5159 static unsigned long
5160 sibling_offset (die)
5163 unsigned long offset;
5165 if (die->die_child_last == NULL)
5166 offset = die->die_offset + size_of_die (die);
5168 offset = sibling_offset (die->die_child_last) + 1;
5173 /* Output the DIE and its attributes. Called recursively to generate
5174 the definitions of each child DIE. */
5178 register dw_die_ref die;
5180 register dw_attr_ref a;
5181 register dw_die_ref c;
5182 register unsigned long ref_offset;
5183 register unsigned long size;
5184 register dw_loc_descr_ref loc;
5187 output_uleb128 (die->die_abbrev);
5189 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5190 die->die_offset, dwarf_tag_name (die->die_tag));
5192 fputc ('\n', asm_out_file);
5194 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5196 switch (a->dw_attr_val.val_class)
5198 case dw_val_class_addr:
5199 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
5200 a->dw_attr_val.v.val_addr);
5203 case dw_val_class_loc:
5204 size = size_of_locs (a->dw_attr_val.v.val_loc);
5206 /* Output the block length for this list of location operations. */
5207 switch (constant_size (size))
5210 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5213 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5220 fprintf (asm_out_file, "\t%s %s",
5221 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5223 fputc ('\n', asm_out_file);
5224 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
5225 loc = loc->dw_loc_next)
5227 /* Output the opcode. */
5228 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
5230 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
5231 dwarf_stack_op_name (loc->dw_loc_opc));
5233 fputc ('\n', asm_out_file);
5235 /* Output the operand(s) (if any). */
5236 output_loc_operands (loc);
5240 case dw_val_class_const:
5241 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
5244 case dw_val_class_unsigned_const:
5245 switch (constant_size (a->dw_attr_val.v.val_unsigned))
5248 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5249 a->dw_attr_val.v.val_unsigned);
5252 ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
5253 a->dw_attr_val.v.val_unsigned);
5256 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5257 a->dw_attr_val.v.val_unsigned);
5260 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5261 a->dw_attr_val.v.val_long_long.hi,
5262 a->dw_attr_val.v.val_long_long.low);
5269 case dw_val_class_long_long:
5270 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5272 fprintf (asm_out_file, "\t%s %s",
5273 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5275 fputc ('\n', asm_out_file);
5276 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5277 a->dw_attr_val.v.val_long_long.hi,
5278 a->dw_attr_val.v.val_long_long.low);
5281 fprintf (asm_out_file,
5282 "\t%s long long constant", ASM_COMMENT_START);
5284 fputc ('\n', asm_out_file);
5287 case dw_val_class_float:
5288 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5289 a->dw_attr_val.v.val_float.length * 4);
5291 fprintf (asm_out_file, "\t%s %s",
5292 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5294 fputc ('\n', asm_out_file);
5295 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5297 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5298 a->dw_attr_val.v.val_float.array[i]);
5300 fprintf (asm_out_file, "\t%s fp constant word %d",
5301 ASM_COMMENT_START, i);
5303 fputc ('\n', asm_out_file);
5307 case dw_val_class_flag:
5308 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
5311 case dw_val_class_die_ref:
5312 if (a->dw_attr_val.v.val_die_ref != NULL)
5313 ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
5314 else if (a->dw_attr == DW_AT_sibling)
5315 ref_offset = sibling_offset(die);
5319 ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
5322 case dw_val_class_fde_ref:
5325 ASM_GENERATE_INTERNAL_LABEL
5326 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5327 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5328 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5332 case dw_val_class_lbl_id:
5333 ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
5336 case dw_val_class_section_offset:
5337 ASM_OUTPUT_DWARF_OFFSET (asm_out_file,
5339 (a->dw_attr_val.v.val_section));
5342 case dw_val_class_str:
5344 ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
5346 ASM_OUTPUT_ASCII (asm_out_file,
5347 a->dw_attr_val.v.val_str,
5348 strlen (a->dw_attr_val.v.val_str) + 1);
5355 if (a->dw_attr_val.val_class != dw_val_class_loc
5356 && a->dw_attr_val.val_class != dw_val_class_long_long
5357 && a->dw_attr_val.val_class != dw_val_class_float)
5360 fprintf (asm_out_file, "\t%s %s",
5361 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5363 fputc ('\n', asm_out_file);
5367 for (c = die->die_child; c != NULL; c = c->die_sib)
5370 if (die->die_child != NULL)
5372 /* Add null byte to terminate sibling list. */
5373 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5375 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
5376 ASM_COMMENT_START, die->die_offset);
5378 fputc ('\n', asm_out_file);
5382 /* Output the compilation unit that appears at the beginning of the
5383 .debug_info section, and precedes the DIE descriptions. */
5386 output_compilation_unit_header ()
5388 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
5390 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
5393 fputc ('\n', asm_out_file);
5394 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5396 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
5398 fputc ('\n', asm_out_file);
5399 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION));
5401 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
5404 fputc ('\n', asm_out_file);
5405 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5407 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
5409 fputc ('\n', asm_out_file);
5412 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5413 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5414 argument list, and maybe the scope. */
5417 dwarf2_name (decl, scope)
5421 return (*decl_printable_name) (decl, scope ? 1 : 0);
5424 /* Add a new entry to .debug_pubnames if appropriate. */
5427 add_pubname (decl, die)
5433 if (! TREE_PUBLIC (decl))
5436 if (pubname_table_in_use == pubname_table_allocated)
5438 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5439 pubname_table = (pubname_ref) xrealloc
5440 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5443 p = &pubname_table[pubname_table_in_use++];
5446 p->name = xstrdup (dwarf2_name (decl, 1));
5449 /* Output the public names table used to speed up access to externally
5450 visible names. For now, only generate entries for externally
5451 visible procedures. */
5456 register unsigned i;
5457 register unsigned long pubnames_length = size_of_pubnames ();
5459 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
5462 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
5465 fputc ('\n', asm_out_file);
5466 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5469 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5471 fputc ('\n', asm_out_file);
5472 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_INFO_SECTION));
5474 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5477 fputc ('\n', asm_out_file);
5478 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
5480 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
5482 fputc ('\n', asm_out_file);
5483 for (i = 0; i < pubname_table_in_use; ++i)
5485 register pubname_ref pub = &pubname_table[i];
5487 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
5489 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
5491 fputc ('\n', asm_out_file);
5495 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
5496 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
5500 ASM_OUTPUT_ASCII (asm_out_file, pub->name, strlen (pub->name) + 1);
5503 fputc ('\n', asm_out_file);
5506 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
5507 fputc ('\n', asm_out_file);
5510 /* Add a new entry to .debug_aranges if appropriate. */
5513 add_arange (decl, die)
5517 if (! DECL_SECTION_NAME (decl))
5520 if (arange_table_in_use == arange_table_allocated)
5522 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5524 = (arange_ref) xrealloc (arange_table,
5525 arange_table_allocated * sizeof (dw_die_ref));
5528 arange_table[arange_table_in_use++] = die;
5531 /* Output the information that goes into the .debug_aranges table.
5532 Namely, define the beginning and ending address range of the
5533 text section generated for this compilation unit. */
5538 register unsigned i;
5539 register unsigned long aranges_length = size_of_aranges ();
5541 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
5543 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
5546 fputc ('\n', asm_out_file);
5547 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5549 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5551 fputc ('\n', asm_out_file);
5552 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_INFO_SECTION));
5554 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5557 fputc ('\n', asm_out_file);
5558 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5560 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
5562 fputc ('\n', asm_out_file);
5563 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5565 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
5568 fputc ('\n', asm_out_file);
5569 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
5571 fprintf (asm_out_file, ",0,0");
5574 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5575 ASM_COMMENT_START, 2 * PTR_SIZE);
5577 fputc ('\n', asm_out_file);
5578 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
5580 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5582 fputc ('\n', asm_out_file);
5583 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label, TEXT_SECTION);
5585 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5587 fputc ('\n', asm_out_file);
5588 for (i = 0; i < arange_table_in_use; ++i)
5590 dw_die_ref a = arange_table[i];
5592 if (a->die_tag == DW_TAG_subprogram)
5593 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a));
5596 char *name = get_AT_string (a, DW_AT_MIPS_linkage_name);
5598 name = get_AT_string (a, DW_AT_name);
5600 ASM_OUTPUT_DWARF_ADDR (asm_out_file, name);
5604 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5606 fputc ('\n', asm_out_file);
5607 if (a->die_tag == DW_TAG_subprogram)
5608 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a),
5611 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5612 get_AT_unsigned (a, DW_AT_byte_size));
5615 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5617 fputc ('\n', asm_out_file);
5620 /* Output the terminator words. */
5621 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5622 fputc ('\n', asm_out_file);
5623 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5624 fputc ('\n', asm_out_file);
5627 /* Output the source line number correspondence information. This
5628 information goes into the .debug_line section.
5630 If the format of this data changes, then the function size_of_line_info
5631 must also be adjusted the same way. */
5636 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5637 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5638 register unsigned opc;
5639 register unsigned n_op_args;
5640 register unsigned long ft_index;
5641 register unsigned long lt_index;
5642 register unsigned long current_line;
5643 register long line_offset;
5644 register long line_delta;
5645 register unsigned long current_file;
5646 register unsigned long function;
5648 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ());
5650 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5653 fputc ('\n', asm_out_file);
5654 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5656 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5658 fputc ('\n', asm_out_file);
5659 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
5661 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5663 fputc ('\n', asm_out_file);
5664 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
5666 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5669 fputc ('\n', asm_out_file);
5670 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
5672 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5675 fputc ('\n', asm_out_file);
5676 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
5678 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5681 fputc ('\n', asm_out_file);
5682 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
5684 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5687 fputc ('\n', asm_out_file);
5688 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5690 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5692 fputc ('\n', asm_out_file);
5693 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5697 case DW_LNS_advance_pc:
5698 case DW_LNS_advance_line:
5699 case DW_LNS_set_file:
5700 case DW_LNS_set_column:
5701 case DW_LNS_fixed_advance_pc:
5708 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5710 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5711 ASM_COMMENT_START, opc, n_op_args);
5712 fputc ('\n', asm_out_file);
5716 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5718 /* Include directory table is empty, at present */
5719 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5720 fputc ('\n', asm_out_file);
5722 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5724 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5728 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5729 fprintf (asm_out_file, "%s File Entry: 0x%lx",
5730 ASM_COMMENT_START, ft_index);
5734 ASM_OUTPUT_ASCII (asm_out_file,
5735 file_table[ft_index],
5736 strlen (file_table[ft_index]) + 1);
5739 fputc ('\n', asm_out_file);
5741 /* Include directory index */
5743 fputc ('\n', asm_out_file);
5745 /* Modification time */
5747 fputc ('\n', asm_out_file);
5749 /* File length in bytes */
5751 fputc ('\n', asm_out_file);
5754 /* Terminate the file name table */
5755 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5756 fputc ('\n', asm_out_file);
5758 /* Set the address register to the first location in the text section */
5759 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5761 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5763 fputc ('\n', asm_out_file);
5764 output_uleb128 (1 + PTR_SIZE);
5765 fputc ('\n', asm_out_file);
5766 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5767 fputc ('\n', asm_out_file);
5768 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
5769 fputc ('\n', asm_out_file);
5771 /* Generate the line number to PC correspondence table, encoded as
5772 a series of state machine operations. */
5775 strcpy (prev_line_label, TEXT_SECTION);
5776 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5778 register dw_line_info_ref line_info;
5780 /* Emit debug info for the address of the current line, choosing
5781 the encoding that uses the least amount of space. */
5782 /* ??? Unfortunately, we have little choice here currently, and must
5783 always use the most general form. Gcc does not know the address
5784 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5785 dwarf2 aware assemblers at this time, so we can't use any special
5786 pseudo ops that would allow the assembler to optimally encode this for
5787 us. Many ports do have length attributes which will give an upper
5788 bound on the address range. We could perhaps use length attributes
5789 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5790 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5793 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5794 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5796 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5799 fputc ('\n', asm_out_file);
5800 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5801 fputc ('\n', asm_out_file);
5805 /* This can handle any delta. This takes 4+PTR_SIZE bytes. */
5806 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5808 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5810 fputc ('\n', asm_out_file);
5811 output_uleb128 (1 + PTR_SIZE);
5812 fputc ('\n', asm_out_file);
5813 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5814 fputc ('\n', asm_out_file);
5815 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5816 fputc ('\n', asm_out_file);
5818 strcpy (prev_line_label, line_label);
5820 /* Emit debug info for the source file of the current line, if
5821 different from the previous line. */
5822 line_info = &line_info_table[lt_index];
5823 if (line_info->dw_file_num != current_file)
5825 current_file = line_info->dw_file_num;
5826 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5828 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5830 fputc ('\n', asm_out_file);
5831 output_uleb128 (current_file);
5833 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5835 fputc ('\n', asm_out_file);
5838 /* Emit debug info for the current line number, choosing the encoding
5839 that uses the least amount of space. */
5840 line_offset = line_info->dw_line_num - current_line;
5841 line_delta = line_offset - DWARF_LINE_BASE;
5842 current_line = line_info->dw_line_num;
5843 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5845 /* This can handle deltas from -10 to 234, using the current
5846 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5848 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5849 DWARF_LINE_OPCODE_BASE + line_delta);
5851 fprintf (asm_out_file,
5852 "\t%s line %ld", ASM_COMMENT_START, current_line);
5854 fputc ('\n', asm_out_file);
5858 /* This can handle any delta. This takes at least 4 bytes, depending
5859 on the value being encoded. */
5860 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5862 fprintf (asm_out_file, "\t%s advance to line %ld",
5863 ASM_COMMENT_START, current_line);
5865 fputc ('\n', asm_out_file);
5866 output_sleb128 (line_offset);
5867 fputc ('\n', asm_out_file);
5868 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5869 fputc ('\n', asm_out_file);
5873 /* Emit debug info for the address of the end of the function. */
5876 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5878 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5881 fputc ('\n', asm_out_file);
5882 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
5883 fputc ('\n', asm_out_file);
5887 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5889 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5890 fputc ('\n', asm_out_file);
5891 output_uleb128 (1 + PTR_SIZE);
5892 fputc ('\n', asm_out_file);
5893 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5894 fputc ('\n', asm_out_file);
5895 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
5896 fputc ('\n', asm_out_file);
5899 /* Output the marker for the end of the line number info. */
5900 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5902 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
5904 fputc ('\n', asm_out_file);
5906 fputc ('\n', asm_out_file);
5907 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5908 fputc ('\n', asm_out_file);
5913 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5915 register dw_separate_line_info_ref line_info
5916 = &separate_line_info_table[lt_index];
5918 /* Emit debug info for the address of the current line. If this is
5919 a new function, or the first line of a function, then we need
5920 to handle it differently. */
5921 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
5923 if (function != line_info->function)
5925 function = line_info->function;
5927 /* Set the address register to the first line in the function */
5928 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5930 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5933 fputc ('\n', asm_out_file);
5934 output_uleb128 (1 + PTR_SIZE);
5935 fputc ('\n', asm_out_file);
5936 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5937 fputc ('\n', asm_out_file);
5938 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5939 fputc ('\n', asm_out_file);
5943 /* ??? See the DW_LNS_advance_pc comment above. */
5946 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5948 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5951 fputc ('\n', asm_out_file);
5952 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5954 fputc ('\n', asm_out_file);
5958 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5960 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5962 fputc ('\n', asm_out_file);
5963 output_uleb128 (1 + PTR_SIZE);
5964 fputc ('\n', asm_out_file);
5965 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5966 fputc ('\n', asm_out_file);
5967 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5968 fputc ('\n', asm_out_file);
5971 strcpy (prev_line_label, line_label);
5973 /* Emit debug info for the source file of the current line, if
5974 different from the previous line. */
5975 if (line_info->dw_file_num != current_file)
5977 current_file = line_info->dw_file_num;
5978 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5980 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5982 fputc ('\n', asm_out_file);
5983 output_uleb128 (current_file);
5985 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5987 fputc ('\n', asm_out_file);
5990 /* Emit debug info for the current line number, choosing the encoding
5991 that uses the least amount of space. */
5992 if (line_info->dw_line_num != current_line)
5994 line_offset = line_info->dw_line_num - current_line;
5995 line_delta = line_offset - DWARF_LINE_BASE;
5996 current_line = line_info->dw_line_num;
5997 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5999 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6000 DWARF_LINE_OPCODE_BASE + line_delta);
6002 fprintf (asm_out_file,
6003 "\t%s line %ld", ASM_COMMENT_START, current_line);
6005 fputc ('\n', asm_out_file);
6009 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6011 fprintf (asm_out_file, "\t%s advance to line %ld",
6012 ASM_COMMENT_START, current_line);
6014 fputc ('\n', asm_out_file);
6015 output_sleb128 (line_offset);
6016 fputc ('\n', asm_out_file);
6017 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6018 fputc ('\n', asm_out_file);
6024 /* If we're done with a function, end its sequence. */
6025 if (lt_index == separate_line_info_table_in_use
6026 || separate_line_info_table[lt_index].function != function)
6031 /* Emit debug info for the address of the end of the function. */
6032 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6035 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6037 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6040 fputc ('\n', asm_out_file);
6041 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6043 fputc ('\n', asm_out_file);
6047 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6049 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6051 fputc ('\n', asm_out_file);
6052 output_uleb128 (1 + PTR_SIZE);
6053 fputc ('\n', asm_out_file);
6054 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6055 fputc ('\n', asm_out_file);
6056 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6057 fputc ('\n', asm_out_file);
6060 /* Output the marker for the end of this sequence. */
6061 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6063 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
6066 fputc ('\n', asm_out_file);
6068 fputc ('\n', asm_out_file);
6069 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6070 fputc ('\n', asm_out_file);
6075 /* Given a pointer to a BLOCK node return non-zero if (and only if) the node
6076 in question represents the outermost pair of curly braces (i.e. the "body
6077 block") of a function or method.
6079 For any BLOCK node representing a "body block" of a function or method, the
6080 BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
6081 represents the outermost (function) scope for the function or method (i.e.
6082 the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
6083 *that* node in turn will point to the relevant FUNCTION_DECL node. */
6086 is_body_block (stmt)
6089 if (TREE_CODE (stmt) == BLOCK)
6091 register tree parent = BLOCK_SUPERCONTEXT (stmt);
6093 if (TREE_CODE (parent) == BLOCK)
6095 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
6097 if (TREE_CODE (grandparent) == FUNCTION_DECL)
6105 /* Given a pointer to a tree node for some base type, return a pointer to
6106 a DIE that describes the given type.
6108 This routine must only be called for GCC type nodes that correspond to
6109 Dwarf base (fundamental) types. */
6112 base_type_die (type)
6115 register dw_die_ref base_type_result;
6116 register char *type_name;
6117 register enum dwarf_type encoding;
6118 register tree name = TYPE_NAME (type);
6120 if (TREE_CODE (type) == ERROR_MARK
6121 || TREE_CODE (type) == VOID_TYPE)
6124 if (TREE_CODE (name) == TYPE_DECL)
6125 name = DECL_NAME (name);
6126 type_name = IDENTIFIER_POINTER (name);
6128 switch (TREE_CODE (type))
6131 /* Carefully distinguish the C character types, without messing
6132 up if the language is not C. Note that we check only for the names
6133 that contain spaces; other names might occur by coincidence in other
6135 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6136 && (type == char_type_node
6137 || ! strcmp (type_name, "signed char")
6138 || ! strcmp (type_name, "unsigned char"))))
6140 if (TREE_UNSIGNED (type))
6141 encoding = DW_ATE_unsigned;
6143 encoding = DW_ATE_signed;
6146 /* else fall through */
6149 /* GNU Pascal/Ada CHAR type. Not used in C. */
6150 if (TREE_UNSIGNED (type))
6151 encoding = DW_ATE_unsigned_char;
6153 encoding = DW_ATE_signed_char;
6157 encoding = DW_ATE_float;
6161 encoding = DW_ATE_complex_float;
6165 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6166 encoding = DW_ATE_boolean;
6170 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6173 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6174 add_AT_string (base_type_result, DW_AT_name, type_name);
6175 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6176 TYPE_PRECISION (type) / BITS_PER_UNIT);
6177 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6179 return base_type_result;
6182 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6183 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6184 a given type is generally the same as the given type, except that if the
6185 given type is a pointer or reference type, then the root type of the given
6186 type is the root type of the "basis" type for the pointer or reference
6187 type. (This definition of the "root" type is recursive.) Also, the root
6188 type of a `const' qualified type or a `volatile' qualified type is the
6189 root type of the given type without the qualifiers. */
6195 if (TREE_CODE (type) == ERROR_MARK)
6196 return error_mark_node;
6198 switch (TREE_CODE (type))
6201 return error_mark_node;
6204 case REFERENCE_TYPE:
6205 return type_main_variant (root_type (TREE_TYPE (type)));
6208 return type_main_variant (type);
6212 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6213 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6219 switch (TREE_CODE (type))
6234 case QUAL_UNION_TYPE:
6239 case REFERENCE_TYPE:
6252 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6253 entry that chains various modifiers in front of the given type. */
6256 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6258 register int is_const_type;
6259 register int is_volatile_type;
6260 register dw_die_ref context_die;
6262 register enum tree_code code = TREE_CODE (type);
6263 register dw_die_ref mod_type_die = NULL;
6264 register dw_die_ref sub_die = NULL;
6265 register tree item_type = NULL;
6267 if (code != ERROR_MARK)
6269 type = build_type_variant (type, is_const_type, is_volatile_type);
6271 mod_type_die = lookup_type_die (type);
6273 return mod_type_die;
6275 /* Handle C typedef types. */
6276 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6277 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6279 tree dtype = TREE_TYPE (TYPE_NAME (type));
6282 /* For a named type, use the typedef. */
6283 gen_type_die (type, context_die);
6284 mod_type_die = lookup_type_die (type);
6287 else if (is_const_type < TYPE_READONLY (dtype)
6288 || is_volatile_type < TYPE_VOLATILE (dtype))
6289 /* cv-unqualified version of named type. Just use the unnamed
6290 type to which it refers. */
6292 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6293 is_const_type, is_volatile_type,
6295 /* Else cv-qualified version of named type; fall through. */
6300 else if (is_const_type)
6302 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6303 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6305 else if (is_volatile_type)
6307 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6308 sub_die = modified_type_die (type, 0, 0, context_die);
6310 else if (code == POINTER_TYPE)
6312 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6313 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6315 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6317 item_type = TREE_TYPE (type);
6319 else if (code == REFERENCE_TYPE)
6321 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6322 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6324 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6326 item_type = TREE_TYPE (type);
6328 else if (is_base_type (type))
6329 mod_type_die = base_type_die (type);
6332 gen_type_die (type, context_die);
6334 /* We have to get the type_main_variant here (and pass that to the
6335 `lookup_type_die' routine) because the ..._TYPE node we have
6336 might simply be a *copy* of some original type node (where the
6337 copy was created to help us keep track of typedef names) and
6338 that copy might have a different TYPE_UID from the original
6340 mod_type_die = lookup_type_die (type_main_variant (type));
6341 if (mod_type_die == NULL)
6346 equate_type_number_to_die (type, mod_type_die);
6348 /* We must do this after the equate_type_number_to_die call, in case
6349 this is a recursive type. This ensures that the modified_type_die
6350 recursion will terminate even if the type is recursive. Recursive
6351 types are possible in Ada. */
6352 sub_die = modified_type_die (item_type,
6353 TYPE_READONLY (item_type),
6354 TYPE_VOLATILE (item_type),
6357 if (sub_die != NULL)
6358 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6360 return mod_type_die;
6363 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6364 an enumerated type. */
6370 return TREE_CODE (type) == ENUMERAL_TYPE;
6373 /* Return a location descriptor that designates a machine register. */
6375 static dw_loc_descr_ref
6376 reg_loc_descriptor (rtl)
6379 register dw_loc_descr_ref loc_result = NULL;
6380 register unsigned reg = reg_number (rtl);
6383 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6385 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6390 /* Return a location descriptor that designates a base+offset location. */
6392 static dw_loc_descr_ref
6393 based_loc_descr (reg, offset)
6397 register dw_loc_descr_ref loc_result;
6398 /* For the "frame base", we use the frame pointer or stack pointer
6399 registers, since the RTL for local variables is relative to one of
6401 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6402 ? HARD_FRAME_POINTER_REGNUM
6403 : STACK_POINTER_REGNUM);
6406 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
6408 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
6410 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
6415 /* Return true if this RTL expression describes a base+offset calculation. */
6421 return (GET_CODE (rtl) == PLUS
6422 && ((GET_CODE (XEXP (rtl, 0)) == REG
6423 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
6426 /* The following routine converts the RTL for a variable or parameter
6427 (resident in memory) into an equivalent Dwarf representation of a
6428 mechanism for getting the address of that same variable onto the top of a
6429 hypothetical "address evaluation" stack.
6431 When creating memory location descriptors, we are effectively transforming
6432 the RTL for a memory-resident object into its Dwarf postfix expression
6433 equivalent. This routine recursively descends an RTL tree, turning
6434 it into Dwarf postfix code as it goes. */
6436 static dw_loc_descr_ref
6437 mem_loc_descriptor (rtl)
6440 dw_loc_descr_ref mem_loc_result = NULL;
6441 /* Note that for a dynamically sized array, the location we will generate a
6442 description of here will be the lowest numbered location which is
6443 actually within the array. That's *not* necessarily the same as the
6444 zeroth element of the array. */
6446 switch (GET_CODE (rtl))
6449 /* The case of a subreg may arise when we have a local (register)
6450 variable or a formal (register) parameter which doesn't quite fill
6451 up an entire register. For now, just assume that it is
6452 legitimate to make the Dwarf info refer to the whole register which
6453 contains the given subreg. */
6454 rtl = XEXP (rtl, 0);
6456 /* ... fall through ... */
6459 /* Whenever a register number forms a part of the description of the
6460 method for calculating the (dynamic) address of a memory resident
6461 object, DWARF rules require the register number be referred to as
6462 a "base register". This distinction is not based in any way upon
6463 what category of register the hardware believes the given register
6464 belongs to. This is strictly DWARF terminology we're dealing with
6465 here. Note that in cases where the location of a memory-resident
6466 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6467 OP_CONST (0)) the actual DWARF location descriptor that we generate
6468 may just be OP_BASEREG (basereg). This may look deceptively like
6469 the object in question was allocated to a register (rather than in
6470 memory) so DWARF consumers need to be aware of the subtle
6471 distinction between OP_REG and OP_BASEREG. */
6472 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
6476 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0));
6477 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6482 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6483 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6484 mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
6488 if (is_based_loc (rtl))
6489 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
6490 INTVAL (XEXP (rtl, 1)));
6493 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
6494 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
6495 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
6500 /* If a pseudo-reg is optimized away, it is possible for it to
6501 be replaced with a MEM containing a multiply. */
6502 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
6503 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
6504 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
6508 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6515 return mem_loc_result;
6518 /* Return a descriptor that describes the concatenation of two locations.
6519 This is typically a complex variable. */
6521 static dw_loc_descr_ref
6522 concat_loc_descriptor (x0, x1)
6523 register rtx x0, x1;
6525 dw_loc_descr_ref cc_loc_result = NULL;
6527 if (!is_pseudo_reg (x0)
6528 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
6529 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
6530 add_loc_descr (&cc_loc_result,
6531 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
6533 if (!is_pseudo_reg (x1)
6534 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
6535 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
6536 add_loc_descr (&cc_loc_result,
6537 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
6539 return cc_loc_result;
6542 /* Output a proper Dwarf location descriptor for a variable or parameter
6543 which is either allocated in a register or in a memory location. For a
6544 register, we just generate an OP_REG and the register number. For a
6545 memory location we provide a Dwarf postfix expression describing how to
6546 generate the (dynamic) address of the object onto the address stack. */
6548 static dw_loc_descr_ref
6549 loc_descriptor (rtl)
6552 dw_loc_descr_ref loc_result = NULL;
6553 switch (GET_CODE (rtl))
6556 /* The case of a subreg may arise when we have a local (register)
6557 variable or a formal (register) parameter which doesn't quite fill
6558 up an entire register. For now, just assume that it is
6559 legitimate to make the Dwarf info refer to the whole register which
6560 contains the given subreg. */
6561 rtl = XEXP (rtl, 0);
6563 /* ... fall through ... */
6566 loc_result = reg_loc_descriptor (rtl);
6570 loc_result = mem_loc_descriptor (XEXP (rtl, 0));
6574 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
6584 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
6585 which is not less than the value itself. */
6587 static inline unsigned
6588 ceiling (value, boundary)
6589 register unsigned value;
6590 register unsigned boundary;
6592 return (((value + boundary - 1) / boundary) * boundary);
6595 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6596 pointer to the declared type for the relevant field variable, or return
6597 `integer_type_node' if the given node turns out to be an
6606 if (TREE_CODE (decl) == ERROR_MARK)
6607 return integer_type_node;
6609 type = DECL_BIT_FIELD_TYPE (decl);
6610 if (type == NULL_TREE)
6611 type = TREE_TYPE (decl);
6616 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6617 node, return the alignment in bits for the type, or else return
6618 BITS_PER_WORD if the node actually turns out to be an
6621 static inline unsigned
6622 simple_type_align_in_bits (type)
6625 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6628 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6629 node, return the size in bits for the type if it is a constant, or else
6630 return the alignment for the type if the type's size is not constant, or
6631 else return BITS_PER_WORD if the type actually turns out to be an
6634 static inline unsigned
6635 simple_type_size_in_bits (type)
6638 if (TREE_CODE (type) == ERROR_MARK)
6639 return BITS_PER_WORD;
6642 register tree type_size_tree = TYPE_SIZE (type);
6644 if (TREE_CODE (type_size_tree) != INTEGER_CST)
6645 return TYPE_ALIGN (type);
6647 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
6651 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6652 return the byte offset of the lowest addressed byte of the "containing
6653 object" for the given FIELD_DECL, or return 0 if we are unable to
6654 determine what that offset is, either because the argument turns out to
6655 be a pointer to an ERROR_MARK node, or because the offset is actually
6656 variable. (We can't handle the latter case just yet). */
6659 field_byte_offset (decl)
6662 register unsigned type_align_in_bytes;
6663 register unsigned type_align_in_bits;
6664 register unsigned type_size_in_bits;
6665 register unsigned object_offset_in_align_units;
6666 register unsigned object_offset_in_bits;
6667 register unsigned object_offset_in_bytes;
6669 register tree bitpos_tree;
6670 register tree field_size_tree;
6671 register unsigned bitpos_int;
6672 register unsigned deepest_bitpos;
6673 register unsigned field_size_in_bits;
6675 if (TREE_CODE (decl) == ERROR_MARK)
6678 if (TREE_CODE (decl) != FIELD_DECL)
6681 type = field_type (decl);
6683 bitpos_tree = DECL_FIELD_BITPOS (decl);
6684 field_size_tree = DECL_SIZE (decl);
6686 /* We cannot yet cope with fields whose positions or sizes are variable, so
6687 for now, when we see such things, we simply return 0. Someday, we may
6688 be able to handle such cases, but it will be damn difficult. */
6689 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6691 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6693 if (TREE_CODE (field_size_tree) != INTEGER_CST)
6696 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
6697 type_size_in_bits = simple_type_size_in_bits (type);
6698 type_align_in_bits = simple_type_align_in_bits (type);
6699 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6701 /* Note that the GCC front-end doesn't make any attempt to keep track of
6702 the starting bit offset (relative to the start of the containing
6703 structure type) of the hypothetical "containing object" for a bit-
6704 field. Thus, when computing the byte offset value for the start of the
6705 "containing object" of a bit-field, we must deduce this information on
6706 our own. This can be rather tricky to do in some cases. For example,
6707 handling the following structure type definition when compiling for an
6708 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6711 struct S { int field1; long long field2:31; };
6713 Fortunately, there is a simple rule-of-thumb which can be
6714 used in such cases. When compiling for an i386/i486, GCC will allocate
6715 8 bytes for the structure shown above. It decides to do this based upon
6716 one simple rule for bit-field allocation. Quite simply, GCC allocates
6717 each "containing object" for each bit-field at the first (i.e. lowest
6718 addressed) legitimate alignment boundary (based upon the required
6719 minimum alignment for the declared type of the field) which it can
6720 possibly use, subject to the condition that there is still enough
6721 available space remaining in the containing object (when allocated at
6722 the selected point) to fully accommodate all of the bits of the
6723 bit-field itself. This simple rule makes it obvious why GCC allocates
6724 8 bytes for each object of the structure type shown above. When looking
6725 for a place to allocate the "containing object" for `field2', the
6726 compiler simply tries to allocate a 64-bit "containing object" at each
6727 successive 32-bit boundary (starting at zero) until it finds a place to
6728 allocate that 64- bit field such that at least 31 contiguous (and
6729 previously unallocated) bits remain within that selected 64 bit field.
6730 (As it turns out, for the example above, the compiler finds that it is
6731 OK to allocate the "containing object" 64-bit field at bit-offset zero
6732 within the structure type.) Here we attempt to work backwards from the
6733 limited set of facts we're given, and we try to deduce from those facts,
6734 where GCC must have believed that the containing object started (within
6735 the structure type). The value we deduce is then used (by the callers of
6736 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6737 for fields (both bit-fields and, in the case of DW_AT_location, regular
6740 /* Figure out the bit-distance from the start of the structure to the
6741 "deepest" bit of the bit-field. */
6742 deepest_bitpos = bitpos_int + field_size_in_bits;
6744 /* This is the tricky part. Use some fancy footwork to deduce where the
6745 lowest addressed bit of the containing object must be. */
6746 object_offset_in_bits
6747 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6749 /* Compute the offset of the containing object in "alignment units". */
6750 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6752 /* Compute the offset of the containing object in bytes. */
6753 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6755 return object_offset_in_bytes;
6758 /* The following routines define various Dwarf attributes and any data
6759 associated with them. */
6761 /* Add a location description attribute value to a DIE.
6763 This emits location attributes suitable for whole variables and
6764 whole parameters. Note that the location attributes for struct fields are
6765 generated by the routine `data_member_location_attribute' below. */
6768 add_AT_location_description (die, attr_kind, rtl)
6770 enum dwarf_attribute attr_kind;
6773 /* Handle a special case. If we are about to output a location descriptor
6774 for a variable or parameter which has been optimized out of existence,
6775 don't do that. A variable which has been optimized out
6776 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6777 Currently, in some rare cases, variables can have DECL_RTL values which
6778 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6779 elsewhere in the compiler. We treat such cases as if the variable(s) in
6780 question had been optimized out of existence. */
6782 if (is_pseudo_reg (rtl)
6783 || (GET_CODE (rtl) == MEM
6784 && is_pseudo_reg (XEXP (rtl, 0)))
6785 || (GET_CODE (rtl) == CONCAT
6786 && is_pseudo_reg (XEXP (rtl, 0))
6787 && is_pseudo_reg (XEXP (rtl, 1))))
6790 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
6793 /* Attach the specialized form of location attribute used for data
6794 members of struct and union types. In the special case of a
6795 FIELD_DECL node which represents a bit-field, the "offset" part
6796 of this special location descriptor must indicate the distance
6797 in bytes from the lowest-addressed byte of the containing struct
6798 or union type to the lowest-addressed byte of the "containing
6799 object" for the bit-field. (See the `field_byte_offset' function
6800 above).. For any given bit-field, the "containing object" is a
6801 hypothetical object (of some integral or enum type) within which
6802 the given bit-field lives. The type of this hypothetical
6803 "containing object" is always the same as the declared type of
6804 the individual bit-field itself (for GCC anyway... the DWARF
6805 spec doesn't actually mandate this). Note that it is the size
6806 (in bytes) of the hypothetical "containing object" which will
6807 be given in the DW_AT_byte_size attribute for this bit-field.
6808 (See the `byte_size_attribute' function below.) It is also used
6809 when calculating the value of the DW_AT_bit_offset attribute.
6810 (See the `bit_offset_attribute' function below). */
6813 add_data_member_location_attribute (die, decl)
6814 register dw_die_ref die;
6817 register unsigned long offset;
6818 register dw_loc_descr_ref loc_descr;
6819 register enum dwarf_location_atom op;
6821 if (TREE_CODE (decl) == TREE_VEC)
6822 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
6824 offset = field_byte_offset (decl);
6826 /* The DWARF2 standard says that we should assume that the structure address
6827 is already on the stack, so we can specify a structure field address
6828 by using DW_OP_plus_uconst. */
6830 #ifdef MIPS_DEBUGGING_INFO
6831 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6832 correctly. It works only if we leave the offset on the stack. */
6835 op = DW_OP_plus_uconst;
6838 loc_descr = new_loc_descr (op, offset, 0);
6839 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6842 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6843 does not have a "location" either in memory or in a register. These
6844 things can arise in GNU C when a constant is passed as an actual parameter
6845 to an inlined function. They can also arise in C++ where declared
6846 constants do not necessarily get memory "homes". */
6849 add_const_value_attribute (die, rtl)
6850 register dw_die_ref die;
6853 switch (GET_CODE (rtl))
6856 /* Note that a CONST_INT rtx could represent either an integer or a
6857 floating-point constant. A CONST_INT is used whenever the constant
6858 will fit into a single word. In all such cases, the original mode
6859 of the constant value is wiped out, and the CONST_INT rtx is
6860 assigned VOIDmode. */
6861 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6865 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6866 floating-point constant. A CONST_DOUBLE is used whenever the
6867 constant requires more than one word in order to be adequately
6868 represented. We output CONST_DOUBLEs as blocks. */
6870 register enum machine_mode mode = GET_MODE (rtl);
6872 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6874 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6878 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6882 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6886 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6891 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6898 add_AT_float (die, DW_AT_const_value, length, array);
6901 add_AT_long_long (die, DW_AT_const_value,
6902 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6907 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6913 add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
6917 /* In cases where an inlined instance of an inline function is passed
6918 the address of an `auto' variable (which is local to the caller) we
6919 can get a situation where the DECL_RTL of the artificial local
6920 variable (for the inlining) which acts as a stand-in for the
6921 corresponding formal parameter (of the inline function) will look
6922 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6923 exactly a compile-time constant expression, but it isn't the address
6924 of the (artificial) local variable either. Rather, it represents the
6925 *value* which the artificial local variable always has during its
6926 lifetime. We currently have no way to represent such quasi-constant
6927 values in Dwarf, so for now we just punt and generate nothing. */
6931 /* No other kinds of rtx should be possible here. */
6937 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6938 data attribute for a variable or a parameter. We generate the
6939 DW_AT_const_value attribute only in those cases where the given variable
6940 or parameter does not have a true "location" either in memory or in a
6941 register. This can happen (for example) when a constant is passed as an
6942 actual argument in a call to an inline function. (It's possible that
6943 these things can crop up in other ways also.) Note that one type of
6944 constant value which can be passed into an inlined function is a constant
6945 pointer. This can happen for example if an actual argument in an inlined
6946 function call evaluates to a compile-time constant address. */
6949 add_location_or_const_value_attribute (die, decl)
6950 register dw_die_ref die;
6954 register tree declared_type;
6955 register tree passed_type;
6957 if (TREE_CODE (decl) == ERROR_MARK)
6960 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6963 /* Here we have to decide where we are going to say the parameter "lives"
6964 (as far as the debugger is concerned). We only have a couple of
6965 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6967 DECL_RTL normally indicates where the parameter lives during most of the
6968 activation of the function. If optimization is enabled however, this
6969 could be either NULL or else a pseudo-reg. Both of those cases indicate
6970 that the parameter doesn't really live anywhere (as far as the code
6971 generation parts of GCC are concerned) during most of the function's
6972 activation. That will happen (for example) if the parameter is never
6973 referenced within the function.
6975 We could just generate a location descriptor here for all non-NULL
6976 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6977 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6978 where DECL_RTL is NULL or is a pseudo-reg.
6980 Note however that we can only get away with using DECL_INCOMING_RTL as
6981 a backup substitute for DECL_RTL in certain limited cases. In cases
6982 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6983 we can be sure that the parameter was passed using the same type as it is
6984 declared to have within the function, and that its DECL_INCOMING_RTL
6985 points us to a place where a value of that type is passed.
6987 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6988 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6989 because in these cases DECL_INCOMING_RTL points us to a value of some
6990 type which is *different* from the type of the parameter itself. Thus,
6991 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6992 such cases, the debugger would end up (for example) trying to fetch a
6993 `float' from a place which actually contains the first part of a
6994 `double'. That would lead to really incorrect and confusing
6995 output at debug-time.
6997 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6998 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6999 are a couple of exceptions however. On little-endian machines we can
7000 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
7001 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
7002 an integral type that is smaller than TREE_TYPE (decl). These cases arise
7003 when (on a little-endian machine) a non-prototyped function has a
7004 parameter declared to be of type `short' or `char'. In such cases,
7005 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
7006 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
7007 passed `int' value. If the debugger then uses that address to fetch
7008 a `short' or a `char' (on a little-endian machine) the result will be
7009 the correct data, so we allow for such exceptional cases below.
7011 Note that our goal here is to describe the place where the given formal
7012 parameter lives during most of the function's activation (i.e. between
7013 the end of the prologue and the start of the epilogue). We'll do that
7014 as best as we can. Note however that if the given formal parameter is
7015 modified sometime during the execution of the function, then a stack
7016 backtrace (at debug-time) will show the function as having been
7017 called with the *new* value rather than the value which was
7018 originally passed in. This happens rarely enough that it is not
7019 a major problem, but it *is* a problem, and I'd like to fix it.
7021 A future version of dwarf2out.c may generate two additional
7022 attributes for any given DW_TAG_formal_parameter DIE which will
7023 describe the "passed type" and the "passed location" for the
7024 given formal parameter in addition to the attributes we now
7025 generate to indicate the "declared type" and the "active
7026 location" for each parameter. This additional set of attributes
7027 could be used by debuggers for stack backtraces. Separately, note
7028 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
7029 NULL also. This happens (for example) for inlined-instances of
7030 inline function formal parameters which are never referenced.
7031 This really shouldn't be happening. All PARM_DECL nodes should
7032 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
7033 doesn't currently generate these values for inlined instances of
7034 inline function parameters, so when we see such cases, we are
7035 just out-of-luck for the time being (until integrate.c
7038 /* Use DECL_RTL as the "location" unless we find something better. */
7039 rtl = DECL_RTL (decl);
7041 if (TREE_CODE (decl) == PARM_DECL)
7043 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
7045 declared_type = type_main_variant (TREE_TYPE (decl));
7046 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
7048 /* This decl represents a formal parameter which was optimized out.
7049 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
7050 all* cases where (rtl == NULL_RTX) just below. */
7051 if (declared_type == passed_type)
7052 rtl = DECL_INCOMING_RTL (decl);
7053 else if (! BYTES_BIG_ENDIAN
7054 && TREE_CODE (declared_type) == INTEGER_TYPE
7055 && TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
7056 rtl = DECL_INCOMING_RTL (decl);
7060 if (rtl == NULL_RTX)
7063 rtl = eliminate_regs (rtl, 0, NULL_RTX);
7064 #ifdef LEAF_REG_REMAP
7066 leaf_renumber_regs_insn (rtl);
7069 switch (GET_CODE (rtl))
7072 /* The address of a variable that was optimized away; don't emit
7083 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7084 add_const_value_attribute (die, rtl);
7091 add_AT_location_description (die, DW_AT_location, rtl);
7099 /* Generate an DW_AT_name attribute given some string value to be included as
7100 the value of the attribute. */
7103 add_name_attribute (die, name_string)
7104 register dw_die_ref die;
7105 register char *name_string;
7107 if (name_string != NULL && *name_string != 0)
7108 add_AT_string (die, DW_AT_name, name_string);
7111 /* Given a tree node describing an array bound (either lower or upper) output
7112 a representation for that bound. */
7115 add_bound_info (subrange_die, bound_attr, bound)
7116 register dw_die_ref subrange_die;
7117 register enum dwarf_attribute bound_attr;
7118 register tree bound;
7120 register unsigned bound_value = 0;
7122 /* If this is an Ada unconstrained array type, then don't emit any debug
7123 info because the array bounds are unknown. They are parameterized when
7124 the type is instantiated. */
7125 if (contains_placeholder_p (bound))
7128 switch (TREE_CODE (bound))
7133 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7135 bound_value = TREE_INT_CST_LOW (bound);
7136 if (bound_attr == DW_AT_lower_bound
7137 && ((is_c_family () && bound_value == 0)
7138 || (is_fortran () && bound_value == 1)))
7139 /* use the default */;
7141 add_AT_unsigned (subrange_die, bound_attr, bound_value);
7146 case NON_LVALUE_EXPR:
7147 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7151 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7152 access the upper bound values may be bogus. If they refer to a
7153 register, they may only describe how to get at these values at the
7154 points in the generated code right after they have just been
7155 computed. Worse yet, in the typical case, the upper bound values
7156 will not even *be* computed in the optimized code (though the
7157 number of elements will), so these SAVE_EXPRs are entirely
7158 bogus. In order to compensate for this fact, we check here to see
7159 if optimization is enabled, and if so, we don't add an attribute
7160 for the (unknown and unknowable) upper bound. This should not
7161 cause too much trouble for existing (stupid?) debuggers because
7162 they have to deal with empty upper bounds location descriptions
7163 anyway in order to be able to deal with incomplete array types.
7164 Of course an intelligent debugger (GDB?) should be able to
7165 comprehend that a missing upper bound specification in a array
7166 type used for a storage class `auto' local array variable
7167 indicates that the upper bound is both unknown (at compile- time)
7168 and unknowable (at run-time) due to optimization.
7170 We assume that a MEM rtx is safe because gcc wouldn't put the
7171 value there unless it was going to be used repeatedly in the
7172 function, i.e. for cleanups. */
7173 if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)
7175 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7176 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7177 add_AT_flag (decl_die, DW_AT_artificial, 1);
7178 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
7179 add_AT_location_description (decl_die, DW_AT_location,
7180 SAVE_EXPR_RTL (bound));
7181 add_AT_die_ref (subrange_die, bound_attr, decl_die);
7184 /* Else leave out the attribute. */
7190 /* ??? These types of bounds can be created by the Ada front end,
7191 and it isn't clear how to emit debug info for them. */
7199 /* Note that the block of subscript information for an array type also
7200 includes information about the element type of type given array type. */
7203 add_subscript_info (type_die, type)
7204 register dw_die_ref type_die;
7207 #ifndef MIPS_DEBUGGING_INFO
7208 register unsigned dimension_number;
7210 register tree lower, upper;
7211 register dw_die_ref subrange_die;
7213 /* The GNU compilers represent multidimensional array types as sequences of
7214 one dimensional array types whose element types are themselves array
7215 types. Here we squish that down, so that each multidimensional array
7216 type gets only one array_type DIE in the Dwarf debugging info. The draft
7217 Dwarf specification say that we are allowed to do this kind of
7218 compression in C (because there is no difference between an array or
7219 arrays and a multidimensional array in C) but for other source languages
7220 (e.g. Ada) we probably shouldn't do this. */
7222 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7223 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7224 We work around this by disabling this feature. See also
7225 gen_array_type_die. */
7226 #ifndef MIPS_DEBUGGING_INFO
7227 for (dimension_number = 0;
7228 TREE_CODE (type) == ARRAY_TYPE;
7229 type = TREE_TYPE (type), dimension_number++)
7232 register tree domain = TYPE_DOMAIN (type);
7234 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7235 and (in GNU C only) variable bounds. Handle all three forms
7237 subrange_die = new_die (DW_TAG_subrange_type, type_die);
7240 /* We have an array type with specified bounds. */
7241 lower = TYPE_MIN_VALUE (domain);
7242 upper = TYPE_MAX_VALUE (domain);
7244 /* define the index type. */
7245 if (TREE_TYPE (domain))
7247 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7248 TREE_TYPE field. We can't emit debug info for this
7249 because it is an unnamed integral type. */
7250 if (TREE_CODE (domain) == INTEGER_TYPE
7251 && TYPE_NAME (domain) == NULL_TREE
7252 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
7253 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
7256 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
7260 /* ??? If upper is NULL, the array has unspecified length,
7261 but it does have a lower bound. This happens with Fortran
7263 Since the debugger is definitely going to need to know N
7264 to produce useful results, go ahead and output the lower
7265 bound solo, and hope the debugger can cope. */
7267 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
7269 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
7272 /* We have an array type with an unspecified length. The DWARF-2
7273 spec does not say how to handle this; let's just leave out the
7278 #ifndef MIPS_DEBUGGING_INFO
7284 add_byte_size_attribute (die, tree_node)
7286 register tree tree_node;
7288 register unsigned size;
7290 switch (TREE_CODE (tree_node))
7298 case QUAL_UNION_TYPE:
7299 size = int_size_in_bytes (tree_node);
7302 /* For a data member of a struct or union, the DW_AT_byte_size is
7303 generally given as the number of bytes normally allocated for an
7304 object of the *declared* type of the member itself. This is true
7305 even for bit-fields. */
7306 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
7312 /* Note that `size' might be -1 when we get to this point. If it is, that
7313 indicates that the byte size of the entity in question is variable. We
7314 have no good way of expressing this fact in Dwarf at the present time,
7315 so just let the -1 pass on through. */
7317 add_AT_unsigned (die, DW_AT_byte_size, size);
7320 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7321 which specifies the distance in bits from the highest order bit of the
7322 "containing object" for the bit-field to the highest order bit of the
7325 For any given bit-field, the "containing object" is a hypothetical
7326 object (of some integral or enum type) within which the given bit-field
7327 lives. The type of this hypothetical "containing object" is always the
7328 same as the declared type of the individual bit-field itself. The
7329 determination of the exact location of the "containing object" for a
7330 bit-field is rather complicated. It's handled by the
7331 `field_byte_offset' function (above).
7333 Note that it is the size (in bytes) of the hypothetical "containing object"
7334 which will be given in the DW_AT_byte_size attribute for this bit-field.
7335 (See `byte_size_attribute' above). */
7338 add_bit_offset_attribute (die, decl)
7339 register dw_die_ref die;
7342 register unsigned object_offset_in_bytes = field_byte_offset (decl);
7343 register tree type = DECL_BIT_FIELD_TYPE (decl);
7344 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
7345 register unsigned bitpos_int;
7346 register unsigned highest_order_object_bit_offset;
7347 register unsigned highest_order_field_bit_offset;
7348 register unsigned bit_offset;
7350 /* Must be a field and a bit field. */
7352 || TREE_CODE (decl) != FIELD_DECL)
7355 /* We can't yet handle bit-fields whose offsets are variable, so if we
7356 encounter such things, just return without generating any attribute
7358 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
7361 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
7363 /* Note that the bit offset is always the distance (in bits) from the
7364 highest-order bit of the "containing object" to the highest-order bit of
7365 the bit-field itself. Since the "high-order end" of any object or field
7366 is different on big-endian and little-endian machines, the computation
7367 below must take account of these differences. */
7368 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
7369 highest_order_field_bit_offset = bitpos_int;
7371 if (! BYTES_BIG_ENDIAN)
7373 highest_order_field_bit_offset
7374 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
7376 highest_order_object_bit_offset += simple_type_size_in_bits (type);
7380 = (! BYTES_BIG_ENDIAN
7381 ? highest_order_object_bit_offset - highest_order_field_bit_offset
7382 : highest_order_field_bit_offset - highest_order_object_bit_offset);
7384 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
7387 /* For a FIELD_DECL node which represents a bit field, output an attribute
7388 which specifies the length in bits of the given field. */
7391 add_bit_size_attribute (die, decl)
7392 register dw_die_ref die;
7395 /* Must be a field and a bit field. */
7396 if (TREE_CODE (decl) != FIELD_DECL
7397 || ! DECL_BIT_FIELD_TYPE (decl))
7399 add_AT_unsigned (die, DW_AT_bit_size,
7400 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
7403 /* If the compiled language is ANSI C, then add a 'prototyped'
7404 attribute, if arg types are given for the parameters of a function. */
7407 add_prototyped_attribute (die, func_type)
7408 register dw_die_ref die;
7409 register tree func_type;
7411 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
7412 && TYPE_ARG_TYPES (func_type) != NULL)
7413 add_AT_flag (die, DW_AT_prototyped, 1);
7417 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7418 by looking in either the type declaration or object declaration
7422 add_abstract_origin_attribute (die, origin)
7423 register dw_die_ref die;
7424 register tree origin;
7426 dw_die_ref origin_die = NULL;
7427 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
7428 origin_die = lookup_decl_die (origin);
7429 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
7430 origin_die = lookup_type_die (origin);
7432 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
7435 /* We do not currently support the pure_virtual attribute. */
7438 add_pure_or_virtual_attribute (die, func_decl)
7439 register dw_die_ref die;
7440 register tree func_decl;
7442 if (DECL_VINDEX (func_decl))
7444 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7445 add_AT_loc (die, DW_AT_vtable_elem_location,
7446 new_loc_descr (DW_OP_constu,
7447 TREE_INT_CST_LOW (DECL_VINDEX (func_decl)),
7450 /* GNU extension: Record what type this method came from originally. */
7451 if (debug_info_level > DINFO_LEVEL_TERSE)
7452 add_AT_die_ref (die, DW_AT_containing_type,
7453 lookup_type_die (DECL_CONTEXT (func_decl)));
7457 /* Add source coordinate attributes for the given decl. */
7460 add_src_coords_attributes (die, decl)
7461 register dw_die_ref die;
7464 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
7466 add_AT_unsigned (die, DW_AT_decl_file, file_index);
7467 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7470 /* Add an DW_AT_name attribute and source coordinate attribute for the
7471 given decl, but only if it actually has a name. */
7474 add_name_and_src_coords_attributes (die, decl)
7475 register dw_die_ref die;
7478 register tree decl_name;
7480 decl_name = DECL_NAME (decl);
7481 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
7483 add_name_attribute (die, dwarf2_name (decl, 0));
7484 add_src_coords_attributes (die, decl);
7485 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
7486 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
7487 add_AT_string (die, DW_AT_MIPS_linkage_name,
7488 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
7492 /* Push a new declaration scope. */
7495 push_decl_scope (scope)
7498 tree containing_scope;
7501 /* Make room in the decl_scope_table, if necessary. */
7502 if (decl_scope_table_allocated == decl_scope_depth)
7504 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
7506 = (decl_scope_node *) xrealloc (decl_scope_table,
7507 (decl_scope_table_allocated
7508 * sizeof (decl_scope_node)));
7511 decl_scope_table[decl_scope_depth].scope = scope;
7513 /* Sometimes, while recursively emitting subtypes within a class type,
7514 we end up recuring on a subtype at a higher level then the current
7515 subtype. In such a case, we need to search the decl_scope_table to
7516 find the parent of this subtype. */
7518 if (TREE_CODE_CLASS (TREE_CODE (scope)) == 't')
7519 containing_scope = TYPE_CONTEXT (scope);
7521 containing_scope = NULL_TREE;
7523 /* The normal case. */
7524 if (decl_scope_depth == 0
7525 || containing_scope == NULL_TREE
7526 /* Ignore namespaces for the moment. */
7527 || TREE_CODE (containing_scope) == NAMESPACE_DECL
7528 || containing_scope == decl_scope_table[decl_scope_depth - 1].scope)
7529 decl_scope_table[decl_scope_depth].previous = decl_scope_depth - 1;
7532 /* We need to search for the containing_scope. */
7533 for (i = 0; i < decl_scope_depth; i++)
7534 if (decl_scope_table[i].scope == containing_scope)
7537 if (i == decl_scope_depth)
7540 decl_scope_table[decl_scope_depth].previous = i;
7546 /* Return the DIE for the scope that immediately contains this declaration. */
7549 scope_die_for (t, context_die)
7551 register dw_die_ref context_die;
7553 register dw_die_ref scope_die = NULL;
7554 register tree containing_scope;
7557 /* Walk back up the declaration tree looking for a place to define
7559 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
7560 containing_scope = TYPE_CONTEXT (t);
7561 else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t))
7562 containing_scope = decl_class_context (t);
7564 containing_scope = DECL_CONTEXT (t);
7566 /* Ignore namespaces for the moment. */
7567 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
7568 containing_scope = NULL_TREE;
7570 /* Function-local tags and functions get stuck in limbo until they are
7571 fixed up by decls_for_scope. */
7572 if (context_die == NULL && containing_scope != NULL_TREE
7573 && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t)))
7576 if (containing_scope == NULL_TREE)
7577 scope_die = comp_unit_die;
7580 for (i = decl_scope_depth - 1, scope_die = context_die;
7581 i >= 0 && decl_scope_table[i].scope != containing_scope;
7582 (scope_die = scope_die->die_parent,
7583 i = decl_scope_table[i].previous))
7586 /* ??? Integrate_decl_tree does not handle BLOCK_TYPE_TAGS, nor
7587 does it try to handle types defined by TYPE_DECLs. Such types
7588 thus have an incorrect TYPE_CONTEXT, which points to the block
7589 they were originally defined in, instead of the current block
7590 created by function inlining. We try to detect that here and
7593 if (i < 0 && scope_die == comp_unit_die
7594 && TREE_CODE (containing_scope) == BLOCK
7595 && is_tagged_type (t)
7596 && (block_ultimate_origin (decl_scope_table[decl_scope_depth - 1].scope)
7597 == containing_scope))
7599 scope_die = context_die;
7600 /* Since the checks below are no longer applicable. */
7606 if (scope_die != comp_unit_die
7607 || TREE_CODE_CLASS (TREE_CODE (containing_scope)) != 't')
7609 if (debug_info_level > DINFO_LEVEL_TERSE
7610 && !TREE_ASM_WRITTEN (containing_scope))
7618 /* Pop a declaration scope. */
7622 if (decl_scope_depth <= 0)
7627 /* Many forms of DIEs require a "type description" attribute. This
7628 routine locates the proper "type descriptor" die for the type given
7629 by 'type', and adds an DW_AT_type attribute below the given die. */
7632 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
7633 register dw_die_ref object_die;
7635 register int decl_const;
7636 register int decl_volatile;
7637 register dw_die_ref context_die;
7639 register enum tree_code code = TREE_CODE (type);
7640 register dw_die_ref type_die = NULL;
7642 /* ??? If this type is an unnamed subrange type of an integral or
7643 floating-point type, use the inner type. This is because we have no
7644 support for unnamed types in base_type_die. This can happen if this is
7645 an Ada subrange type. Correct solution is emit a subrange type die. */
7646 if ((code == INTEGER_TYPE || code == REAL_TYPE)
7647 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
7648 type = TREE_TYPE (type), code = TREE_CODE (type);
7650 if (code == ERROR_MARK)
7653 /* Handle a special case. For functions whose return type is void, we
7654 generate *no* type attribute. (Note that no object may have type
7655 `void', so this only applies to function return types). */
7656 if (code == VOID_TYPE)
7659 type_die = modified_type_die (type,
7660 decl_const || TYPE_READONLY (type),
7661 decl_volatile || TYPE_VOLATILE (type),
7663 if (type_die != NULL)
7664 add_AT_die_ref (object_die, DW_AT_type, type_die);
7667 /* Given a tree pointer to a struct, class, union, or enum type node, return
7668 a pointer to the (string) tag name for the given type, or zero if the type
7669 was declared without a tag. */
7675 register char *name = 0;
7677 if (TYPE_NAME (type) != 0)
7679 register tree t = 0;
7681 /* Find the IDENTIFIER_NODE for the type name. */
7682 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7683 t = TYPE_NAME (type);
7685 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7686 a TYPE_DECL node, regardless of whether or not a `typedef' was
7688 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7689 && ! DECL_IGNORED_P (TYPE_NAME (type)))
7690 t = DECL_NAME (TYPE_NAME (type));
7692 /* Now get the name as a string, or invent one. */
7694 name = IDENTIFIER_POINTER (t);
7697 return (name == 0 || *name == '\0') ? 0 : name;
7700 /* Return the type associated with a data member, make a special check
7701 for bit field types. */
7704 member_declared_type (member)
7705 register tree member;
7707 return (DECL_BIT_FIELD_TYPE (member)
7708 ? DECL_BIT_FIELD_TYPE (member)
7709 : TREE_TYPE (member));
7712 /* Get the decl's label, as described by its RTL. This may be different
7713 from the DECL_NAME name used in the source file. */
7716 decl_start_label (decl)
7721 x = DECL_RTL (decl);
7722 if (GET_CODE (x) != MEM)
7726 if (GET_CODE (x) != SYMBOL_REF)
7729 fnname = XSTR (x, 0);
7733 /* These routines generate the internal representation of the DIE's for
7734 the compilation unit. Debugging information is collected by walking
7735 the declaration trees passed in from dwarf2out_decl(). */
7738 gen_array_type_die (type, context_die)
7740 register dw_die_ref context_die;
7742 register dw_die_ref scope_die = scope_die_for (type, context_die);
7743 register dw_die_ref array_die;
7744 register tree element_type;
7746 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7747 the inner array type comes before the outer array type. Thus we must
7748 call gen_type_die before we call new_die. See below also. */
7749 #ifdef MIPS_DEBUGGING_INFO
7750 gen_type_die (TREE_TYPE (type), context_die);
7753 array_die = new_die (DW_TAG_array_type, scope_die);
7756 /* We default the array ordering. SDB will probably do
7757 the right things even if DW_AT_ordering is not present. It's not even
7758 an issue until we start to get into multidimensional arrays anyway. If
7759 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7760 then we'll have to put the DW_AT_ordering attribute back in. (But if
7761 and when we find out that we need to put these in, we will only do so
7762 for multidimensional arrays. */
7763 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
7766 #ifdef MIPS_DEBUGGING_INFO
7767 /* The SGI compilers handle arrays of unknown bound by setting
7768 AT_declaration and not emitting any subrange DIEs. */
7769 if (! TYPE_DOMAIN (type))
7770 add_AT_unsigned (array_die, DW_AT_declaration, 1);
7773 add_subscript_info (array_die, type);
7775 equate_type_number_to_die (type, array_die);
7777 /* Add representation of the type of the elements of this array type. */
7778 element_type = TREE_TYPE (type);
7780 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7781 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7782 We work around this by disabling this feature. See also
7783 add_subscript_info. */
7784 #ifndef MIPS_DEBUGGING_INFO
7785 while (TREE_CODE (element_type) == ARRAY_TYPE)
7786 element_type = TREE_TYPE (element_type);
7788 gen_type_die (element_type, context_die);
7791 add_type_attribute (array_die, element_type, 0, 0, context_die);
7795 gen_set_type_die (type, context_die)
7797 register dw_die_ref context_die;
7799 register dw_die_ref type_die
7800 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7802 equate_type_number_to_die (type, type_die);
7803 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7807 gen_entry_point_die (decl, context_die)
7809 register dw_die_ref context_die;
7811 register tree origin = decl_ultimate_origin (decl);
7812 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
7814 add_abstract_origin_attribute (decl_die, origin);
7817 add_name_and_src_coords_attributes (decl_die, decl);
7818 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
7822 if (DECL_ABSTRACT (decl))
7823 equate_decl_number_to_die (decl, decl_die);
7825 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
7828 /* Remember a type in the pending_types_list. */
7834 if (pending_types == pending_types_allocated)
7836 pending_types_allocated += PENDING_TYPES_INCREMENT;
7838 = (tree *) xrealloc (pending_types_list,
7839 sizeof (tree) * pending_types_allocated);
7842 pending_types_list[pending_types++] = type;
7845 /* Output any pending types (from the pending_types list) which we can output
7846 now (taking into account the scope that we are working on now).
7848 For each type output, remove the given type from the pending_types_list
7849 *before* we try to output it. */
7852 output_pending_types_for_scope (context_die)
7853 register dw_die_ref context_die;
7857 while (pending_types)
7860 type = pending_types_list[pending_types];
7861 gen_type_die (type, context_die);
7862 if (!TREE_ASM_WRITTEN (type))
7867 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7870 gen_inlined_enumeration_type_die (type, context_die)
7872 register dw_die_ref context_die;
7874 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
7875 scope_die_for (type, context_die));
7877 if (!TREE_ASM_WRITTEN (type))
7879 add_abstract_origin_attribute (type_die, type);
7882 /* Generate a DIE to represent an inlined instance of a structure type. */
7885 gen_inlined_structure_type_die (type, context_die)
7887 register dw_die_ref context_die;
7889 register dw_die_ref type_die = new_die (DW_TAG_structure_type,
7890 scope_die_for (type, context_die));
7892 if (!TREE_ASM_WRITTEN (type))
7894 add_abstract_origin_attribute (type_die, type);
7897 /* Generate a DIE to represent an inlined instance of a union type. */
7900 gen_inlined_union_type_die (type, context_die)
7902 register dw_die_ref context_die;
7904 register dw_die_ref type_die = new_die (DW_TAG_union_type,
7905 scope_die_for (type, context_die));
7907 if (!TREE_ASM_WRITTEN (type))
7909 add_abstract_origin_attribute (type_die, type);
7912 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7913 include all of the information about the enumeration values also. Each
7914 enumerated type name/value is listed as a child of the enumerated type
7918 gen_enumeration_type_die (type, context_die)
7920 register dw_die_ref context_die;
7922 register dw_die_ref type_die = lookup_type_die (type);
7924 if (type_die == NULL)
7926 type_die = new_die (DW_TAG_enumeration_type,
7927 scope_die_for (type, context_die));
7928 equate_type_number_to_die (type, type_die);
7929 add_name_attribute (type_die, type_tag (type));
7931 else if (! TYPE_SIZE (type))
7934 remove_AT (type_die, DW_AT_declaration);
7936 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7937 given enum type is incomplete, do not generate the DW_AT_byte_size
7938 attribute or the DW_AT_element_list attribute. */
7939 if (TYPE_SIZE (type))
7943 TREE_ASM_WRITTEN (type) = 1;
7944 add_byte_size_attribute (type_die, type);
7945 if (TYPE_STUB_DECL (type) != NULL_TREE)
7946 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
7948 /* If the first reference to this type was as the return type of an
7949 inline function, then it may not have a parent. Fix this now. */
7950 if (type_die->die_parent == NULL)
7951 add_child_die (scope_die_for (type, context_die), type_die);
7953 for (link = TYPE_FIELDS (type);
7954 link != NULL; link = TREE_CHAIN (link))
7956 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
7958 add_name_attribute (enum_die,
7959 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
7960 add_AT_unsigned (enum_die, DW_AT_const_value,
7961 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
7965 add_AT_flag (type_die, DW_AT_declaration, 1);
7969 /* Generate a DIE to represent either a real live formal parameter decl or to
7970 represent just the type of some formal parameter position in some function
7973 Note that this routine is a bit unusual because its argument may be a
7974 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7975 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7976 node. If it's the former then this function is being called to output a
7977 DIE to represent a formal parameter object (or some inlining thereof). If
7978 it's the latter, then this function is only being called to output a
7979 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7980 argument type of some subprogram type. */
7983 gen_formal_parameter_die (node, context_die)
7985 register dw_die_ref context_die;
7987 register dw_die_ref parm_die
7988 = new_die (DW_TAG_formal_parameter, context_die);
7989 register tree origin;
7991 switch (TREE_CODE_CLASS (TREE_CODE (node)))
7994 origin = decl_ultimate_origin (node);
7996 add_abstract_origin_attribute (parm_die, origin);
7999 add_name_and_src_coords_attributes (parm_die, node);
8000 add_type_attribute (parm_die, TREE_TYPE (node),
8001 TREE_READONLY (node),
8002 TREE_THIS_VOLATILE (node),
8004 if (DECL_ARTIFICIAL (node))
8005 add_AT_flag (parm_die, DW_AT_artificial, 1);
8008 equate_decl_number_to_die (node, parm_die);
8009 if (! DECL_ABSTRACT (node))
8010 add_location_or_const_value_attribute (parm_die, node);
8015 /* We were called with some kind of a ..._TYPE node. */
8016 add_type_attribute (parm_die, node, 0, 0, context_die);
8026 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
8027 at the end of an (ANSI prototyped) formal parameters list. */
8030 gen_unspecified_parameters_die (decl_or_type, context_die)
8031 register tree decl_or_type;
8032 register dw_die_ref context_die;
8034 register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters,
8038 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
8039 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
8040 parameters as specified in some function type specification (except for
8041 those which appear as part of a function *definition*).
8043 Note we must be careful here to output all of the parameter DIEs before*
8044 we output any DIEs needed to represent the types of the formal parameters.
8045 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
8046 non-parameter DIE it sees ends the formal parameter list. */
8049 gen_formal_types_die (function_or_method_type, context_die)
8050 register tree function_or_method_type;
8051 register dw_die_ref context_die;
8054 register tree formal_type = NULL;
8055 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
8058 /* In the case where we are generating a formal types list for a C++
8059 non-static member function type, skip over the first thing on the
8060 TYPE_ARG_TYPES list because it only represents the type of the hidden
8061 `this pointer'. The debugger should be able to figure out (without
8062 being explicitly told) that this non-static member function type takes a
8063 `this pointer' and should be able to figure what the type of that hidden
8064 parameter is from the DW_AT_member attribute of the parent
8065 DW_TAG_subroutine_type DIE. */
8066 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
8067 first_parm_type = TREE_CHAIN (first_parm_type);
8070 /* Make our first pass over the list of formal parameter types and output a
8071 DW_TAG_formal_parameter DIE for each one. */
8072 for (link = first_parm_type; link; link = TREE_CHAIN (link))
8074 register dw_die_ref parm_die;
8076 formal_type = TREE_VALUE (link);
8077 if (formal_type == void_type_node)
8080 /* Output a (nameless) DIE to represent the formal parameter itself. */
8081 parm_die = gen_formal_parameter_die (formal_type, context_die);
8082 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8083 && link == first_parm_type)
8084 add_AT_flag (parm_die, DW_AT_artificial, 1);
8087 /* If this function type has an ellipsis, add a
8088 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8089 if (formal_type != void_type_node)
8090 gen_unspecified_parameters_die (function_or_method_type, context_die);
8092 /* Make our second (and final) pass over the list of formal parameter types
8093 and output DIEs to represent those types (as necessary). */
8094 for (link = TYPE_ARG_TYPES (function_or_method_type);
8096 link = TREE_CHAIN (link))
8098 formal_type = TREE_VALUE (link);
8099 if (formal_type == void_type_node)
8102 gen_type_die (formal_type, context_die);
8106 /* Generate a DIE to represent a declared function (either file-scope or
8110 gen_subprogram_die (decl, context_die)
8112 register dw_die_ref context_die;
8114 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
8115 register tree origin = decl_ultimate_origin (decl);
8116 register dw_die_ref subr_die;
8117 register rtx fp_reg;
8118 register tree fn_arg_types;
8119 register tree outer_scope;
8120 register dw_die_ref old_die = lookup_decl_die (decl);
8121 register int declaration
8122 = (current_function_decl != decl
8124 && (context_die->die_tag == DW_TAG_structure_type
8125 || context_die->die_tag == DW_TAG_union_type)));
8129 subr_die = new_die (DW_TAG_subprogram, context_die);
8130 add_abstract_origin_attribute (subr_die, origin);
8132 else if (old_die && DECL_ABSTRACT (decl)
8133 && get_AT_unsigned (old_die, DW_AT_inline))
8135 /* This must be a redefinition of an extern inline function.
8136 We can just reuse the old die here. */
8139 /* Clear out the inlined attribute and parm types. */
8140 remove_AT (subr_die, DW_AT_inline);
8141 remove_children (subr_die);
8145 register unsigned file_index
8146 = lookup_filename (DECL_SOURCE_FILE (decl));
8148 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
8151 /* If the definition comes from the same place as the declaration,
8152 maybe use the old DIE. We always want the DIE for this function
8153 that has the *_pc attributes to be under comp_unit_die so the
8154 debugger can find it. For inlines, that is the concrete instance,
8155 so we can use the old DIE here. For non-inline methods, we want a
8156 specification DIE at toplevel, so we need a new DIE. For local
8157 class methods, this does not apply. */
8158 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
8159 || context_die == NULL)
8160 && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
8161 && (get_AT_unsigned (old_die, DW_AT_decl_line)
8162 == DECL_SOURCE_LINE (decl)))
8166 /* Clear out the declaration attribute and the parm types. */
8167 remove_AT (subr_die, DW_AT_declaration);
8168 remove_children (subr_die);
8172 subr_die = new_die (DW_TAG_subprogram, context_die);
8173 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
8174 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8175 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
8176 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8177 != DECL_SOURCE_LINE (decl))
8179 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8184 register dw_die_ref scope_die;
8186 if (DECL_CONTEXT (decl))
8187 scope_die = scope_die_for (decl, context_die);
8189 /* Don't put block extern declarations under comp_unit_die. */
8190 scope_die = context_die;
8192 subr_die = new_die (DW_TAG_subprogram, scope_die);
8194 if (TREE_PUBLIC (decl))
8195 add_AT_flag (subr_die, DW_AT_external, 1);
8197 add_name_and_src_coords_attributes (subr_die, decl);
8198 if (debug_info_level > DINFO_LEVEL_TERSE)
8200 register tree type = TREE_TYPE (decl);
8202 add_prototyped_attribute (subr_die, type);
8203 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
8206 add_pure_or_virtual_attribute (subr_die, decl);
8207 if (DECL_ARTIFICIAL (decl))
8208 add_AT_flag (subr_die, DW_AT_artificial, 1);
8209 if (TREE_PROTECTED (decl))
8210 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
8211 else if (TREE_PRIVATE (decl))
8212 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
8217 add_AT_flag (subr_die, DW_AT_declaration, 1);
8219 /* The first time we see a member function, it is in the context of
8220 the class to which it belongs. We make sure of this by emitting
8221 the class first. The next time is the definition, which is
8222 handled above. The two may come from the same source text. */
8223 if (DECL_CONTEXT (decl))
8224 equate_decl_number_to_die (decl, subr_die);
8226 else if (DECL_ABSTRACT (decl))
8228 /* ??? Checking DECL_DEFER_OUTPUT is correct for static inline functions,
8229 but not for extern inline functions. We can't get this completely
8230 correct because information about whether the function was declared
8231 inline is not saved anywhere. */
8232 if (DECL_DEFER_OUTPUT (decl))
8234 if (DECL_INLINE (decl))
8235 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
8237 add_AT_unsigned (subr_die, DW_AT_inline,
8238 DW_INL_declared_not_inlined);
8240 else if (DECL_INLINE (decl))
8241 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
8245 equate_decl_number_to_die (decl, subr_die);
8247 else if (!DECL_EXTERNAL (decl))
8249 if (origin == NULL_TREE)
8250 equate_decl_number_to_die (decl, subr_die);
8252 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
8253 current_funcdef_number);
8254 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
8255 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
8256 current_funcdef_number);
8257 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
8259 add_pubname (decl, subr_die);
8260 add_arange (decl, subr_die);
8262 #ifdef MIPS_DEBUGGING_INFO
8263 /* Add a reference to the FDE for this routine. */
8264 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
8267 /* Define the "frame base" location for this routine. We use the
8268 frame pointer or stack pointer registers, since the RTL for local
8269 variables is relative to one of them. */
8271 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
8272 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
8275 /* ??? This fails for nested inline functions, because context_display
8276 is not part of the state saved/restored for inline functions. */
8277 if (current_function_needs_context)
8278 add_AT_location_description (subr_die, DW_AT_static_link,
8279 lookup_static_chain (decl));
8283 /* Now output descriptions of the arguments for this function. This gets
8284 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8285 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8286 `...' at the end of the formal parameter list. In order to find out if
8287 there was a trailing ellipsis or not, we must instead look at the type
8288 associated with the FUNCTION_DECL. This will be a node of type
8289 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8290 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8291 an ellipsis at the end. */
8292 push_decl_scope (decl);
8294 /* In the case where we are describing a mere function declaration, all we
8295 need to do here (and all we *can* do here) is to describe the *types* of
8296 its formal parameters. */
8297 if (debug_info_level <= DINFO_LEVEL_TERSE)
8299 else if (declaration)
8300 gen_formal_types_die (TREE_TYPE (decl), subr_die);
8303 /* Generate DIEs to represent all known formal parameters */
8304 register tree arg_decls = DECL_ARGUMENTS (decl);
8307 /* When generating DIEs, generate the unspecified_parameters DIE
8308 instead if we come across the arg "__builtin_va_alist" */
8309 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
8310 if (TREE_CODE (parm) == PARM_DECL)
8312 if (DECL_NAME (parm)
8313 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
8314 "__builtin_va_alist"))
8315 gen_unspecified_parameters_die (parm, subr_die);
8317 gen_decl_die (parm, subr_die);
8320 /* Decide whether we need a unspecified_parameters DIE at the end.
8321 There are 2 more cases to do this for: 1) the ansi ... declaration -
8322 this is detectable when the end of the arg list is not a
8323 void_type_node 2) an unprototyped function declaration (not a
8324 definition). This just means that we have no info about the
8325 parameters at all. */
8326 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
8327 if (fn_arg_types != NULL)
8329 /* this is the prototyped case, check for ... */
8330 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
8331 gen_unspecified_parameters_die (decl, subr_die);
8333 else if (DECL_INITIAL (decl) == NULL_TREE)
8334 gen_unspecified_parameters_die (decl, subr_die);
8337 /* Output Dwarf info for all of the stuff within the body of the function
8338 (if it has one - it may be just a declaration). */
8339 outer_scope = DECL_INITIAL (decl);
8341 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8342 node created to represent a function. This outermost BLOCK actually
8343 represents the outermost binding contour for the function, i.e. the
8344 contour in which the function's formal parameters and labels get
8345 declared. Curiously, it appears that the front end doesn't actually
8346 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8347 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8348 list for the function instead.) The BLOCK_VARS list for the
8349 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8350 the function however, and we output DWARF info for those in
8351 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8352 node representing the function's outermost pair of curly braces, and
8353 any blocks used for the base and member initializers of a C++
8354 constructor function. */
8355 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
8357 current_function_has_inlines = 0;
8358 decls_for_scope (outer_scope, subr_die, 0);
8360 #if 0 && defined (MIPS_DEBUGGING_INFO)
8361 if (current_function_has_inlines)
8363 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
8364 if (! comp_unit_has_inlines)
8366 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
8367 comp_unit_has_inlines = 1;
8376 /* Generate a DIE to represent a declared data object. */
8379 gen_variable_die (decl, context_die)
8381 register dw_die_ref context_die;
8383 register tree origin = decl_ultimate_origin (decl);
8384 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
8386 dw_die_ref old_die = lookup_decl_die (decl);
8388 = (DECL_EXTERNAL (decl)
8389 || current_function_decl != decl_function_context (decl)
8390 || context_die->die_tag == DW_TAG_structure_type
8391 || context_die->die_tag == DW_TAG_union_type);
8394 add_abstract_origin_attribute (var_die, origin);
8395 /* Loop unrolling can create multiple blocks that refer to the same
8396 static variable, so we must test for the DW_AT_declaration flag. */
8397 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8398 copy decls and set the DECL_ABSTRACT flag on them instead of
8400 else if (old_die && TREE_STATIC (decl)
8401 && get_AT_flag (old_die, DW_AT_declaration) == 1)
8403 /* ??? This is an instantiation of a C++ class level static. */
8404 add_AT_die_ref (var_die, DW_AT_specification, old_die);
8405 if (DECL_NAME (decl))
8407 register unsigned file_index
8408 = lookup_filename (DECL_SOURCE_FILE (decl));
8410 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8411 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
8413 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8414 != DECL_SOURCE_LINE (decl))
8416 add_AT_unsigned (var_die, DW_AT_decl_line,
8417 DECL_SOURCE_LINE (decl));
8422 add_name_and_src_coords_attributes (var_die, decl);
8423 add_type_attribute (var_die, TREE_TYPE (decl),
8424 TREE_READONLY (decl),
8425 TREE_THIS_VOLATILE (decl), context_die);
8427 if (TREE_PUBLIC (decl))
8428 add_AT_flag (var_die, DW_AT_external, 1);
8430 if (DECL_ARTIFICIAL (decl))
8431 add_AT_flag (var_die, DW_AT_artificial, 1);
8433 if (TREE_PROTECTED (decl))
8434 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
8436 else if (TREE_PRIVATE (decl))
8437 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
8441 add_AT_flag (var_die, DW_AT_declaration, 1);
8443 if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl))
8444 equate_decl_number_to_die (decl, var_die);
8446 if (! declaration && ! DECL_ABSTRACT (decl))
8448 equate_decl_number_to_die (decl, var_die);
8449 add_location_or_const_value_attribute (var_die, decl);
8450 add_pubname (decl, var_die);
8454 /* Generate a DIE to represent a label identifier. */
8457 gen_label_die (decl, context_die)
8459 register dw_die_ref context_die;
8461 register tree origin = decl_ultimate_origin (decl);
8462 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
8464 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8465 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
8468 add_abstract_origin_attribute (lbl_die, origin);
8470 add_name_and_src_coords_attributes (lbl_die, decl);
8472 if (DECL_ABSTRACT (decl))
8473 equate_decl_number_to_die (decl, lbl_die);
8476 insn = DECL_RTL (decl);
8477 if (GET_CODE (insn) == CODE_LABEL)
8479 /* When optimization is enabled (via -O) some parts of the compiler
8480 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8481 represent source-level labels which were explicitly declared by
8482 the user. This really shouldn't be happening though, so catch
8483 it if it ever does happen. */
8484 if (INSN_DELETED_P (insn))
8487 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
8488 ASM_GENERATE_INTERNAL_LABEL (label, label2,
8489 (unsigned) INSN_UID (insn));
8490 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
8495 /* Generate a DIE for a lexical block. */
8498 gen_lexical_block_die (stmt, context_die, depth)
8500 register dw_die_ref context_die;
8503 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
8504 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8506 if (! BLOCK_ABSTRACT (stmt))
8508 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8510 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
8511 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
8512 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
8515 push_decl_scope (stmt);
8516 decls_for_scope (stmt, stmt_die, depth);
8520 /* Generate a DIE for an inlined subprogram. */
8523 gen_inlined_subroutine_die (stmt, context_die, depth)
8525 register dw_die_ref context_die;
8528 if (! BLOCK_ABSTRACT (stmt))
8530 register dw_die_ref subr_die
8531 = new_die (DW_TAG_inlined_subroutine, context_die);
8532 register tree decl = block_ultimate_origin (stmt);
8533 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8535 add_abstract_origin_attribute (subr_die, decl);
8536 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8538 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
8539 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
8540 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
8541 push_decl_scope (decl);
8542 decls_for_scope (stmt, subr_die, depth);
8544 current_function_has_inlines = 1;
8548 /* Generate a DIE for a field in a record, or structure. */
8551 gen_field_die (decl, context_die)
8553 register dw_die_ref context_die;
8555 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
8557 add_name_and_src_coords_attributes (decl_die, decl);
8558 add_type_attribute (decl_die, member_declared_type (decl),
8559 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
8562 /* If this is a bit field... */
8563 if (DECL_BIT_FIELD_TYPE (decl))
8565 add_byte_size_attribute (decl_die, decl);
8566 add_bit_size_attribute (decl_die, decl);
8567 add_bit_offset_attribute (decl_die, decl);
8570 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
8571 add_data_member_location_attribute (decl_die, decl);
8573 if (DECL_ARTIFICIAL (decl))
8574 add_AT_flag (decl_die, DW_AT_artificial, 1);
8576 if (TREE_PROTECTED (decl))
8577 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
8579 else if (TREE_PRIVATE (decl))
8580 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
8584 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8585 Use modified_type_die instead.
8586 We keep this code here just in case these types of DIEs may be needed to
8587 represent certain things in other languages (e.g. Pascal) someday. */
8589 gen_pointer_type_die (type, context_die)
8591 register dw_die_ref context_die;
8593 register dw_die_ref ptr_die
8594 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
8596 equate_type_number_to_die (type, ptr_die);
8597 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8598 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8601 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8602 Use modified_type_die instead.
8603 We keep this code here just in case these types of DIEs may be needed to
8604 represent certain things in other languages (e.g. Pascal) someday. */
8606 gen_reference_type_die (type, context_die)
8608 register dw_die_ref context_die;
8610 register dw_die_ref ref_die
8611 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
8613 equate_type_number_to_die (type, ref_die);
8614 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
8615 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8619 /* Generate a DIE for a pointer to a member type. */
8621 gen_ptr_to_mbr_type_die (type, context_die)
8623 register dw_die_ref context_die;
8625 register dw_die_ref ptr_die
8626 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8628 equate_type_number_to_die (type, ptr_die);
8629 add_AT_die_ref (ptr_die, DW_AT_containing_type,
8630 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
8631 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8634 /* Generate the DIE for the compilation unit. */
8637 gen_compile_unit_die (main_input_filename)
8638 register char *main_input_filename;
8641 char *wd = getpwd ();
8643 comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
8644 add_name_attribute (comp_unit_die, main_input_filename);
8647 add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
8649 sprintf (producer, "%s %s", language_string, version_string);
8651 #ifdef MIPS_DEBUGGING_INFO
8652 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8653 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8654 not appear in the producer string, the debugger reaches the conclusion
8655 that the object file is stripped and has no debugging information.
8656 To get the MIPS/SGI debugger to believe that there is debugging
8657 information in the object file, we add a -g to the producer string. */
8658 if (debug_info_level > DINFO_LEVEL_TERSE)
8659 strcat (producer, " -g");
8662 add_AT_string (comp_unit_die, DW_AT_producer, producer);
8664 if (strcmp (language_string, "GNU C++") == 0)
8665 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
8667 else if (strcmp (language_string, "GNU Ada") == 0)
8668 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
8670 else if (strcmp (language_string, "GNU F77") == 0)
8671 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77);
8673 else if (strcmp (language_string, "GNU Pascal") == 0)
8674 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Pascal83);
8676 else if (flag_traditional)
8677 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
8680 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
8682 #if 0 /* unimplemented */
8683 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
8684 add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
8688 /* Generate a DIE for a string type. */
8691 gen_string_type_die (type, context_die)
8693 register dw_die_ref context_die;
8695 register dw_die_ref type_die
8696 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
8698 equate_type_number_to_die (type, type_die);
8700 /* Fudge the string length attribute for now. */
8702 /* TODO: add string length info.
8703 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8704 bound_representation (upper_bound, 0, 'u'); */
8707 /* Generate the DIE for a base class. */
8710 gen_inheritance_die (binfo, context_die)
8711 register tree binfo;
8712 register dw_die_ref context_die;
8714 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
8716 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
8717 add_data_member_location_attribute (die, binfo);
8719 if (TREE_VIA_VIRTUAL (binfo))
8720 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8721 if (TREE_VIA_PUBLIC (binfo))
8722 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
8723 else if (TREE_VIA_PROTECTED (binfo))
8724 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
8727 /* Generate a DIE for a class member. */
8730 gen_member_die (type, context_die)
8732 register dw_die_ref context_die;
8734 register tree member;
8736 /* If this is not an incomplete type, output descriptions of each of its
8737 members. Note that as we output the DIEs necessary to represent the
8738 members of this record or union type, we will also be trying to output
8739 DIEs to represent the *types* of those members. However the `type'
8740 function (above) will specifically avoid generating type DIEs for member
8741 types *within* the list of member DIEs for this (containing) type execpt
8742 for those types (of members) which are explicitly marked as also being
8743 members of this (containing) type themselves. The g++ front- end can
8744 force any given type to be treated as a member of some other
8745 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8746 to point to the TREE node representing the appropriate (containing)
8749 /* First output info about the base classes. */
8750 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
8752 register tree bases = TYPE_BINFO_BASETYPES (type);
8753 register int n_bases = TREE_VEC_LENGTH (bases);
8756 for (i = 0; i < n_bases; i++)
8757 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
8760 /* Now output info about the data members and type members. */
8761 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
8762 gen_decl_die (member, context_die);
8764 /* Now output info about the function members (if any). */
8765 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
8766 gen_decl_die (member, context_die);
8769 /* Generate a DIE for a structure or union type. */
8772 gen_struct_or_union_type_die (type, context_die)
8774 register dw_die_ref context_die;
8776 register dw_die_ref type_die = lookup_type_die (type);
8777 register dw_die_ref scope_die = 0;
8778 register int nested = 0;
8780 if (type_die && ! TYPE_SIZE (type))
8783 if (TYPE_CONTEXT (type) != NULL_TREE
8784 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't')
8787 scope_die = scope_die_for (type, context_die);
8789 if (! type_die || (nested && scope_die == comp_unit_die))
8790 /* First occurrence of type or toplevel definition of nested class. */
8792 register dw_die_ref old_die = type_die;
8794 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
8795 ? DW_TAG_structure_type : DW_TAG_union_type,
8797 equate_type_number_to_die (type, type_die);
8798 add_name_attribute (type_die, type_tag (type));
8800 add_AT_die_ref (type_die, DW_AT_specification, old_die);
8803 remove_AT (type_die, DW_AT_declaration);
8805 /* If we're not in the right context to be defining this type, defer to
8806 avoid tricky recursion. */
8807 if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die)
8809 add_AT_flag (type_die, DW_AT_declaration, 1);
8812 /* If this type has been completed, then give it a byte_size attribute and
8813 then give a list of members. */
8814 else if (TYPE_SIZE (type))
8816 /* Prevent infinite recursion in cases where the type of some member of
8817 this type is expressed in terms of this type itself. */
8818 TREE_ASM_WRITTEN (type) = 1;
8819 add_byte_size_attribute (type_die, type);
8820 if (TYPE_STUB_DECL (type) != NULL_TREE)
8821 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8823 /* If the first reference to this type was as the return type of an
8824 inline function, then it may not have a parent. Fix this now. */
8825 if (type_die->die_parent == NULL)
8826 add_child_die (scope_die, type_die);
8828 push_decl_scope (type);
8829 gen_member_die (type, type_die);
8832 /* GNU extension: Record what type our vtable lives in. */
8833 if (TYPE_VFIELD (type))
8835 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
8837 gen_type_die (vtype, context_die);
8838 add_AT_die_ref (type_die, DW_AT_containing_type,
8839 lookup_type_die (vtype));
8843 add_AT_flag (type_die, DW_AT_declaration, 1);
8846 /* Generate a DIE for a subroutine _type_. */
8849 gen_subroutine_type_die (type, context_die)
8851 register dw_die_ref context_die;
8853 register tree return_type = TREE_TYPE (type);
8854 register dw_die_ref subr_die
8855 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
8857 equate_type_number_to_die (type, subr_die);
8858 add_prototyped_attribute (subr_die, type);
8859 add_type_attribute (subr_die, return_type, 0, 0, context_die);
8860 gen_formal_types_die (type, subr_die);
8863 /* Generate a DIE for a type definition */
8866 gen_typedef_die (decl, context_die)
8868 register dw_die_ref context_die;
8870 register dw_die_ref type_die;
8871 register tree origin;
8873 if (TREE_ASM_WRITTEN (decl))
8875 TREE_ASM_WRITTEN (decl) = 1;
8877 type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
8878 origin = decl_ultimate_origin (decl);
8880 add_abstract_origin_attribute (type_die, origin);
8884 add_name_and_src_coords_attributes (type_die, decl);
8885 if (DECL_ORIGINAL_TYPE (decl))
8887 type = DECL_ORIGINAL_TYPE (decl);
8888 equate_type_number_to_die (TREE_TYPE (decl), type_die);
8891 type = TREE_TYPE (decl);
8892 add_type_attribute (type_die, type, TREE_READONLY (decl),
8893 TREE_THIS_VOLATILE (decl), context_die);
8896 if (DECL_ABSTRACT (decl))
8897 equate_decl_number_to_die (decl, type_die);
8900 /* Generate a type description DIE. */
8903 gen_type_die (type, context_die)
8905 register dw_die_ref context_die;
8907 if (type == NULL_TREE || type == error_mark_node)
8910 /* We are going to output a DIE to represent the unqualified version of of
8911 this type (i.e. without any const or volatile qualifiers) so get the
8912 main variant (i.e. the unqualified version) of this type now. */
8913 type = type_main_variant (type);
8915 if (TREE_ASM_WRITTEN (type))
8918 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8919 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
8921 TREE_ASM_WRITTEN (type) = 1;
8922 gen_decl_die (TYPE_NAME (type), context_die);
8926 switch (TREE_CODE (type))
8932 case REFERENCE_TYPE:
8933 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
8934 ensures that the gen_type_die recursion will terminate even if the
8935 type is recursive. Recursive types are possible in Ada. */
8936 /* ??? We could perhaps do this for all types before the switch
8938 TREE_ASM_WRITTEN (type) = 1;
8940 /* For these types, all that is required is that we output a DIE (or a
8941 set of DIEs) to represent the "basis" type. */
8942 gen_type_die (TREE_TYPE (type), context_die);
8946 /* This code is used for C++ pointer-to-data-member types.
8947 Output a description of the relevant class type. */
8948 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
8950 /* Output a description of the type of the object pointed to. */
8951 gen_type_die (TREE_TYPE (type), context_die);
8953 /* Now output a DIE to represent this pointer-to-data-member type
8955 gen_ptr_to_mbr_type_die (type, context_die);
8959 gen_type_die (TYPE_DOMAIN (type), context_die);
8960 gen_set_type_die (type, context_die);
8964 gen_type_die (TREE_TYPE (type), context_die);
8965 abort (); /* No way to represent these in Dwarf yet! */
8969 /* Force out return type (in case it wasn't forced out already). */
8970 gen_type_die (TREE_TYPE (type), context_die);
8971 gen_subroutine_type_die (type, context_die);
8975 /* Force out return type (in case it wasn't forced out already). */
8976 gen_type_die (TREE_TYPE (type), context_die);
8977 gen_subroutine_type_die (type, context_die);
8981 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
8983 gen_type_die (TREE_TYPE (type), context_die);
8984 gen_string_type_die (type, context_die);
8987 gen_array_type_die (type, context_die);
8993 case QUAL_UNION_TYPE:
8994 /* If this is a nested type whose containing class hasn't been
8995 written out yet, writing it out will cover this one, too. */
8996 if (TYPE_CONTEXT (type)
8997 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
8998 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9000 gen_type_die (TYPE_CONTEXT (type), context_die);
9002 if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9005 /* If that failed, attach ourselves to the stub. */
9006 push_decl_scope (TYPE_CONTEXT (type));
9007 context_die = lookup_type_die (TYPE_CONTEXT (type));
9010 if (TREE_CODE (type) == ENUMERAL_TYPE)
9011 gen_enumeration_type_die (type, context_die);
9013 gen_struct_or_union_type_die (type, context_die);
9015 if (TYPE_CONTEXT (type)
9016 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
9017 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9020 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9021 it up if it is ever completed. gen_*_type_die will set it for us
9022 when appropriate. */
9031 /* No DIEs needed for fundamental types. */
9035 /* No Dwarf representation currently defined. */
9042 TREE_ASM_WRITTEN (type) = 1;
9045 /* Generate a DIE for a tagged type instantiation. */
9048 gen_tagged_type_instantiation_die (type, context_die)
9050 register dw_die_ref context_die;
9052 if (type == NULL_TREE || type == error_mark_node)
9055 /* We are going to output a DIE to represent the unqualified version of of
9056 this type (i.e. without any const or volatile qualifiers) so make sure
9057 that we have the main variant (i.e. the unqualified version) of this
9059 if (type != type_main_variant (type)
9060 || !TREE_ASM_WRITTEN (type))
9063 switch (TREE_CODE (type))
9069 gen_inlined_enumeration_type_die (type, context_die);
9073 gen_inlined_structure_type_die (type, context_die);
9077 case QUAL_UNION_TYPE:
9078 gen_inlined_union_type_die (type, context_die);
9086 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
9087 things which are local to the given block. */
9090 gen_block_die (stmt, context_die, depth)
9092 register dw_die_ref context_die;
9095 register int must_output_die = 0;
9096 register tree origin;
9098 register enum tree_code origin_code;
9100 /* Ignore blocks never really used to make RTL. */
9102 if (stmt == NULL_TREE || !TREE_USED (stmt))
9105 /* Determine the "ultimate origin" of this block. This block may be an
9106 inlined instance of an inlined instance of inline function, so we have
9107 to trace all of the way back through the origin chain to find out what
9108 sort of node actually served as the original seed for the creation of
9109 the current block. */
9110 origin = block_ultimate_origin (stmt);
9111 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
9113 /* Determine if we need to output any Dwarf DIEs at all to represent this
9115 if (origin_code == FUNCTION_DECL)
9116 /* The outer scopes for inlinings *must* always be represented. We
9117 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9118 must_output_die = 1;
9121 /* In the case where the current block represents an inlining of the
9122 "body block" of an inline function, we must *NOT* output any DIE for
9123 this block because we have already output a DIE to represent the
9124 whole inlined function scope and the "body block" of any function
9125 doesn't really represent a different scope according to ANSI C
9126 rules. So we check here to make sure that this block does not
9127 represent a "body block inlining" before trying to set the
9128 `must_output_die' flag. */
9129 if (! is_body_block (origin ? origin : stmt))
9131 /* Determine if this block directly contains any "significant"
9132 local declarations which we will need to output DIEs for. */
9133 if (debug_info_level > DINFO_LEVEL_TERSE)
9134 /* We are not in terse mode so *any* local declaration counts
9135 as being a "significant" one. */
9136 must_output_die = (BLOCK_VARS (stmt) != NULL);
9138 /* We are in terse mode, so only local (nested) function
9139 definitions count as "significant" local declarations. */
9140 for (decl = BLOCK_VARS (stmt);
9141 decl != NULL; decl = TREE_CHAIN (decl))
9142 if (TREE_CODE (decl) == FUNCTION_DECL
9143 && DECL_INITIAL (decl))
9145 must_output_die = 1;
9151 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9152 DIE for any block which contains no significant local declarations at
9153 all. Rather, in such cases we just call `decls_for_scope' so that any
9154 needed Dwarf info for any sub-blocks will get properly generated. Note
9155 that in terse mode, our definition of what constitutes a "significant"
9156 local declaration gets restricted to include only inlined function
9157 instances and local (nested) function definitions. */
9158 if (must_output_die)
9160 if (origin_code == FUNCTION_DECL)
9161 gen_inlined_subroutine_die (stmt, context_die, depth);
9163 gen_lexical_block_die (stmt, context_die, depth);
9166 decls_for_scope (stmt, context_die, depth);
9169 /* Generate all of the decls declared within a given scope and (recursively)
9170 all of it's sub-blocks. */
9173 decls_for_scope (stmt, context_die, depth)
9175 register dw_die_ref context_die;
9179 register tree subblocks;
9181 /* Ignore blocks never really used to make RTL. */
9182 if (stmt == NULL_TREE || ! TREE_USED (stmt))
9185 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
9186 next_block_number++;
9188 /* Output the DIEs to represent all of the data objects and typedefs
9189 declared directly within this block but not within any nested
9190 sub-blocks. Also, nested function and tag DIEs have been
9191 generated with a parent of NULL; fix that up now. */
9192 for (decl = BLOCK_VARS (stmt);
9193 decl != NULL; decl = TREE_CHAIN (decl))
9195 register dw_die_ref die;
9197 if (TREE_CODE (decl) == FUNCTION_DECL)
9198 die = lookup_decl_die (decl);
9199 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9200 die = lookup_type_die (TREE_TYPE (decl));
9204 if (die != NULL && die->die_parent == NULL)
9205 add_child_die (context_die, die);
9207 gen_decl_die (decl, context_die);
9210 /* Output the DIEs to represent all sub-blocks (and the items declared
9211 therein) of this block. */
9212 for (subblocks = BLOCK_SUBBLOCKS (stmt);
9214 subblocks = BLOCK_CHAIN (subblocks))
9215 gen_block_die (subblocks, context_die, depth + 1);
9218 /* Is this a typedef we can avoid emitting? */
9221 is_redundant_typedef (decl)
9224 if (TYPE_DECL_IS_STUB (decl))
9227 if (DECL_ARTIFICIAL (decl)
9228 && DECL_CONTEXT (decl)
9229 && is_tagged_type (DECL_CONTEXT (decl))
9230 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
9231 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
9232 /* Also ignore the artificial member typedef for the class name. */
9238 /* Generate Dwarf debug information for a decl described by DECL. */
9241 gen_decl_die (decl, context_die)
9243 register dw_die_ref context_die;
9245 register tree origin;
9247 /* Make a note of the decl node we are going to be working on. We may need
9248 to give the user the source coordinates of where it appeared in case we
9249 notice (later on) that something about it looks screwy. */
9250 dwarf_last_decl = decl;
9252 if (TREE_CODE (decl) == ERROR_MARK)
9255 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
9256 ignore a function definition, since that would screw up our count of
9257 blocks, and that it turn will completely screw up the the labels we will
9258 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9259 subsequent blocks). */
9260 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
9263 switch (TREE_CODE (decl))
9266 /* The individual enumerators of an enum type get output when we output
9267 the Dwarf representation of the relevant enum type itself. */
9271 /* Don't output any DIEs to represent mere function declarations,
9272 unless they are class members or explicit block externs. */
9273 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
9274 && (current_function_decl == NULL_TREE || ! DECL_ARTIFICIAL (decl)))
9277 if (debug_info_level > DINFO_LEVEL_TERSE)
9279 /* Before we describe the FUNCTION_DECL itself, make sure that we
9280 have described its return type. */
9281 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
9283 /* And its containing type. */
9284 origin = decl_class_context (decl);
9285 if (origin != NULL_TREE)
9286 gen_type_die (origin, context_die);
9288 /* And its virtual context. */
9289 if (DECL_VINDEX (decl) != NULL_TREE)
9290 gen_type_die (DECL_CONTEXT (decl), context_die);
9293 /* Now output a DIE to represent the function itself. */
9294 gen_subprogram_die (decl, context_die);
9298 /* If we are in terse mode, don't generate any DIEs to represent any
9300 if (debug_info_level <= DINFO_LEVEL_TERSE)
9303 /* In the special case of a TYPE_DECL node representing the
9304 declaration of some type tag, if the given TYPE_DECL is marked as
9305 having been instantiated from some other (original) TYPE_DECL node
9306 (e.g. one which was generated within the original definition of an
9307 inline function) we have to generate a special (abbreviated)
9308 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9310 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
9312 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
9316 if (is_redundant_typedef (decl))
9317 gen_type_die (TREE_TYPE (decl), context_die);
9319 /* Output a DIE to represent the typedef itself. */
9320 gen_typedef_die (decl, context_die);
9324 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9325 gen_label_die (decl, context_die);
9329 /* If we are in terse mode, don't generate any DIEs to represent any
9330 variable declarations or definitions. */
9331 if (debug_info_level <= DINFO_LEVEL_TERSE)
9334 /* Output any DIEs that are needed to specify the type of this data
9336 gen_type_die (TREE_TYPE (decl), context_die);
9338 /* And its containing type. */
9339 origin = decl_class_context (decl);
9340 if (origin != NULL_TREE)
9341 gen_type_die (origin, context_die);
9343 /* Now output the DIE to represent the data object itself. This gets
9344 complicated because of the possibility that the VAR_DECL really
9345 represents an inlined instance of a formal parameter for an inline
9347 origin = decl_ultimate_origin (decl);
9348 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
9349 gen_formal_parameter_die (decl, context_die);
9351 gen_variable_die (decl, context_die);
9355 /* Ignore the nameless fields that are used to skip bits, but
9356 handle C++ anonymous unions. */
9357 if (DECL_NAME (decl) != NULL_TREE
9358 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
9360 gen_type_die (member_declared_type (decl), context_die);
9361 gen_field_die (decl, context_die);
9366 gen_type_die (TREE_TYPE (decl), context_die);
9367 gen_formal_parameter_die (decl, context_die);
9375 /* Write the debugging output for DECL. */
9378 dwarf2out_decl (decl)
9381 register dw_die_ref context_die = comp_unit_die;
9383 if (TREE_CODE (decl) == ERROR_MARK)
9386 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
9387 hope that the node in question doesn't represent a function definition.
9388 If it does, then totally ignoring it is bound to screw up our count of
9389 blocks, and that it turn will completely screw up the the labels we will
9390 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9391 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
9392 own sequence numbers with them!) */
9393 if (DECL_IGNORED_P (decl))
9395 if (TREE_CODE (decl) == FUNCTION_DECL
9396 && DECL_INITIAL (decl) != NULL)
9402 switch (TREE_CODE (decl))
9405 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9406 builtin function. Explicit programmer-supplied declarations of
9407 these same functions should NOT be ignored however. */
9408 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
9411 /* What we would really like to do here is to filter out all mere
9412 file-scope declarations of file-scope functions which are never
9413 referenced later within this translation unit (and keep all of ones
9414 that *are* referenced later on) but we aren't clairvoyant, so we have
9415 no idea which functions will be referenced in the future (i.e. later
9416 on within the current translation unit). So here we just ignore all
9417 file-scope function declarations which are not also definitions. If
9418 and when the debugger needs to know something about these functions,
9419 it wil have to hunt around and find the DWARF information associated
9420 with the definition of the function. Note that we can't just check
9421 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9422 definitions and which ones represent mere declarations. We have to
9423 check `DECL_INITIAL' instead. That's because the C front-end
9424 supports some weird semantics for "extern inline" function
9425 definitions. These can get inlined within the current translation
9426 unit (an thus, we need to generate DWARF info for their abstract
9427 instances so that the DWARF info for the concrete inlined instances
9428 can have something to refer to) but the compiler never generates any
9429 out-of-lines instances of such things (despite the fact that they
9430 *are* definitions). The important point is that the C front-end
9431 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9432 to generate DWARF for them anyway. Note that the C++ front-end also
9433 plays some similar games for inline function definitions appearing
9434 within include files which also contain
9435 `#pragma interface' pragmas. */
9436 if (DECL_INITIAL (decl) == NULL_TREE)
9439 /* If we're a nested function, initially use a parent of NULL; if we're
9440 a plain function, this will be fixed up in decls_for_scope. If
9441 we're a method, it will be ignored, since we already have a DIE. */
9442 if (decl_function_context (decl))
9448 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9449 declaration and if the declaration was never even referenced from
9450 within this entire compilation unit. We suppress these DIEs in
9451 order to save space in the .debug section (by eliminating entries
9452 which are probably useless). Note that we must not suppress
9453 block-local extern declarations (whether used or not) because that
9454 would screw-up the debugger's name lookup mechanism and cause it to
9455 miss things which really ought to be in scope at a given point. */
9456 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
9459 /* If we are in terse mode, don't generate any DIEs to represent any
9460 variable declarations or definitions. */
9461 if (debug_info_level <= DINFO_LEVEL_TERSE)
9466 /* Don't bother trying to generate any DIEs to represent any of the
9467 normal built-in types for the language we are compiling. */
9468 if (DECL_SOURCE_LINE (decl) == 0)
9470 /* OK, we need to generate one for `bool' so GDB knows what type
9471 comparisons have. */
9472 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
9473 == DW_LANG_C_plus_plus)
9474 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
9475 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
9480 /* If we are in terse mode, don't generate any DIEs for types. */
9481 if (debug_info_level <= DINFO_LEVEL_TERSE)
9484 /* If we're a function-scope tag, initially use a parent of NULL;
9485 this will be fixed up in decls_for_scope. */
9486 if (decl_function_context (decl))
9495 gen_decl_die (decl, context_die);
9496 output_pending_types_for_scope (comp_unit_die);
9499 /* Output a marker (i.e. a label) for the beginning of the generated code for
9503 dwarf2out_begin_block (blocknum)
9504 register unsigned blocknum;
9506 function_section (current_function_decl);
9507 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
9510 /* Output a marker (i.e. a label) for the end of the generated code for a
9514 dwarf2out_end_block (blocknum)
9515 register unsigned blocknum;
9517 function_section (current_function_decl);
9518 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
9521 /* Output a marker (i.e. a label) at a point in the assembly code which
9522 corresponds to a given source level label. */
9525 dwarf2out_label (insn)
9528 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9530 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9532 function_section (current_function_decl);
9533 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
9534 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
9535 (unsigned) INSN_UID (insn));
9539 /* Lookup a filename (in the list of filenames that we know about here in
9540 dwarf2out.c) and return its "index". The index of each (known) filename is
9541 just a unique number which is associated with only that one filename.
9542 We need such numbers for the sake of generating labels
9543 (in the .debug_sfnames section) and references to those
9544 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9545 If the filename given as an argument is not found in our current list,
9546 add it to the list and assign it the next available unique index number.
9547 In order to speed up searches, we remember the index of the filename
9548 was looked up last. This handles the majority of all searches. */
9551 lookup_filename (file_name)
9554 static unsigned last_file_lookup_index = 0;
9555 register unsigned i;
9557 /* Check to see if the file name that was searched on the previous call
9558 matches this file name. If so, return the index. */
9559 if (last_file_lookup_index != 0)
9560 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
9561 return last_file_lookup_index;
9563 /* Didn't match the previous lookup, search the table */
9564 for (i = 1; i < file_table_in_use; ++i)
9565 if (strcmp (file_name, file_table[i]) == 0)
9567 last_file_lookup_index = i;
9571 /* Prepare to add a new table entry by making sure there is enough space in
9572 the table to do so. If not, expand the current table. */
9573 if (file_table_in_use == file_table_allocated)
9575 file_table_allocated += FILE_TABLE_INCREMENT;
9577 = (char **) xrealloc (file_table,
9578 file_table_allocated * sizeof (char *));
9581 /* Add the new entry to the end of the filename table. */
9582 file_table[file_table_in_use] = xstrdup (file_name);
9583 last_file_lookup_index = file_table_in_use++;
9585 return last_file_lookup_index;
9588 /* Output a label to mark the beginning of a source code line entry
9589 and record information relating to this source line, in
9590 'line_info_table' for later output of the .debug_line section. */
9593 dwarf2out_line (filename, line)
9594 register char *filename;
9595 register unsigned line;
9597 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9599 function_section (current_function_decl);
9601 if (DECL_SECTION_NAME (current_function_decl))
9603 register dw_separate_line_info_ref line_info;
9604 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
9605 separate_line_info_table_in_use);
9606 fputc ('\n', asm_out_file);
9608 /* expand the line info table if necessary */
9609 if (separate_line_info_table_in_use
9610 == separate_line_info_table_allocated)
9612 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9613 separate_line_info_table
9614 = (dw_separate_line_info_ref)
9615 xrealloc (separate_line_info_table,
9616 separate_line_info_table_allocated
9617 * sizeof (dw_separate_line_info_entry));
9620 /* Add the new entry at the end of the line_info_table. */
9622 = &separate_line_info_table[separate_line_info_table_in_use++];
9623 line_info->dw_file_num = lookup_filename (filename);
9624 line_info->dw_line_num = line;
9625 line_info->function = current_funcdef_number;
9629 register dw_line_info_ref line_info;
9631 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
9632 line_info_table_in_use);
9633 fputc ('\n', asm_out_file);
9635 /* Expand the line info table if necessary. */
9636 if (line_info_table_in_use == line_info_table_allocated)
9638 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9640 = (dw_line_info_ref)
9641 xrealloc (line_info_table,
9642 (line_info_table_allocated
9643 * sizeof (dw_line_info_entry)));
9646 /* Add the new entry at the end of the line_info_table. */
9647 line_info = &line_info_table[line_info_table_in_use++];
9648 line_info->dw_file_num = lookup_filename (filename);
9649 line_info->dw_line_num = line;
9654 /* Record the beginning of a new source file, for later output
9655 of the .debug_macinfo section. At present, unimplemented. */
9658 dwarf2out_start_source_file (filename)
9659 register char *filename;
9663 /* Record the end of a source file, for later output
9664 of the .debug_macinfo section. At present, unimplemented. */
9667 dwarf2out_end_source_file ()
9671 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9672 the tail part of the directive line, i.e. the part which is past the
9673 initial whitespace, #, whitespace, directive-name, whitespace part. */
9676 dwarf2out_define (lineno, buffer)
9677 register unsigned lineno;
9678 register char *buffer;
9680 static int initialized = 0;
9683 dwarf2out_start_source_file (primary_filename);
9688 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9689 the tail part of the directive line, i.e. the part which is past the
9690 initial whitespace, #, whitespace, directive-name, whitespace part. */
9693 dwarf2out_undef (lineno, buffer)
9694 register unsigned lineno;
9695 register char *buffer;
9699 /* Set up for Dwarf output at the start of compilation. */
9702 dwarf2out_init (asm_out_file, main_input_filename)
9703 register FILE *asm_out_file;
9704 register char *main_input_filename;
9706 /* Remember the name of the primary input file. */
9707 primary_filename = main_input_filename;
9709 /* Allocate the initial hunk of the file_table. */
9710 file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *));
9711 bzero ((char *) file_table, FILE_TABLE_INCREMENT * sizeof (char *));
9712 file_table_allocated = FILE_TABLE_INCREMENT;
9714 /* Skip the first entry - file numbers begin at 1. */
9715 file_table_in_use = 1;
9717 /* Allocate the initial hunk of the decl_die_table. */
9719 = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
9720 bzero ((char *) decl_die_table,
9721 DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
9722 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
9723 decl_die_table_in_use = 0;
9725 /* Allocate the initial hunk of the decl_scope_table. */
9727 = (decl_scope_node *) xmalloc (DECL_SCOPE_TABLE_INCREMENT
9728 * sizeof (decl_scope_node));
9729 bzero ((char *) decl_scope_table,
9730 DECL_SCOPE_TABLE_INCREMENT * sizeof (decl_scope_node));
9731 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
9732 decl_scope_depth = 0;
9734 /* Allocate the initial hunk of the abbrev_die_table. */
9736 = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT
9737 * sizeof (dw_die_ref));
9738 bzero ((char *) abbrev_die_table,
9739 ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
9740 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
9741 /* Zero-th entry is allocated, but unused */
9742 abbrev_die_table_in_use = 1;
9744 /* Allocate the initial hunk of the line_info_table. */
9746 = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT
9747 * sizeof (dw_line_info_entry));
9748 bzero ((char *) line_info_table,
9749 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
9750 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
9751 /* Zero-th entry is allocated, but unused */
9752 line_info_table_in_use = 1;
9754 /* Generate the initial DIE for the .debug section. Note that the (string)
9755 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9756 will (typically) be a relative pathname and that this pathname should be
9757 taken as being relative to the directory from which the compiler was
9758 invoked when the given (base) source file was compiled. */
9759 gen_compile_unit_die (main_input_filename);
9761 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
9764 /* Output stuff that dwarf requires at the end of every file,
9765 and generate the DWARF-2 debugging info. */
9770 limbo_die_node *node, *next_node;
9774 /* Traverse the limbo die list, and add parent/child links. The only
9775 dies without parents that should be here are concrete instances of
9776 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9777 For concrete instances, we can get the parent die from the abstract
9779 for (node = limbo_die_list; node; node = next_node)
9781 next_node = node->next;
9784 if (die->die_parent == NULL)
9786 a = get_AT (die, DW_AT_abstract_origin);
9788 add_child_die (a->dw_attr_val.v.val_die_ref->die_parent, die);
9789 else if (die == comp_unit_die)
9797 /* Traverse the DIE tree and add sibling attributes to those DIE's
9798 that have children. */
9799 add_sibling_attributes (comp_unit_die);
9801 /* Output a terminator label for the .text section. */
9802 fputc ('\n', asm_out_file);
9803 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9804 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
9807 /* Output a terminator label for the .data section. */
9808 fputc ('\n', asm_out_file);
9809 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
9810 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
9812 /* Output a terminator label for the .bss section. */
9813 fputc ('\n', asm_out_file);
9814 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
9815 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
9818 /* Output the source line correspondence table. */
9819 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
9821 fputc ('\n', asm_out_file);
9822 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9823 output_line_info ();
9825 /* We can only use the low/high_pc attributes if all of the code
9827 if (separate_line_info_table_in_use == 0)
9829 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_SECTION);
9830 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
9833 add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, DEBUG_LINE_SECTION);
9836 /* Output the abbreviation table. */
9837 fputc ('\n', asm_out_file);
9838 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9839 build_abbrev_table (comp_unit_die);
9840 output_abbrev_section ();
9842 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9843 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9844 calc_die_sizes (comp_unit_die);
9846 /* Output debugging information. */
9847 fputc ('\n', asm_out_file);
9848 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9849 output_compilation_unit_header ();
9850 output_die (comp_unit_die);
9852 if (pubname_table_in_use)
9854 /* Output public names table. */
9855 fputc ('\n', asm_out_file);
9856 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
9860 if (fde_table_in_use)
9862 /* Output the address range information. */
9863 fputc ('\n', asm_out_file);
9864 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
9868 #endif /* DWARF2_DEBUGGING_INFO */