1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* TODO: Implement .debug_str handling, and share entries somehow.
26 Eliminate duplicates by putting common info in a separate section
27 to be collected by the linker and referring to it with
29 Emit .debug_line header even when there are no functions, since
30 the file numbers are used by .debug_info. Alternately, leave
31 out locations for types and decls.
32 Avoid talking about ctors and op= for PODs.
33 Factor out common prologue sequences into multiple CIEs. */
35 /* The first part of this file deals with the DWARF 2 frame unwind
36 information, which is also used by the GCC efficient exception handling
37 mechanism. The second part, controlled only by an #ifdef
38 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
47 #include "hard-reg-set.h"
49 #include "insn-config.h"
55 #include "dwarf2out.h"
61 /* We cannot use <assert.h> in GCC source, since that would include
62 GCC's assert.h, which may not be compatible with the host compiler. */
67 # define assert(e) do { if (! (e)) abort (); } while (0)
70 /* Decide whether we want to emit frame unwind information for the current
76 return (write_symbols == DWARF2_DEBUG
77 #ifdef DWARF2_FRAME_INFO
80 #ifdef DWARF2_UNWIND_INFO
82 || (flag_exceptions && ! exceptions_via_longjmp)
87 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
89 /* How to start an assembler comment. */
90 #ifndef ASM_COMMENT_START
91 #define ASM_COMMENT_START ";#"
94 typedef struct dw_cfi_struct *dw_cfi_ref;
95 typedef struct dw_fde_struct *dw_fde_ref;
96 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
98 /* Call frames are described using a sequence of Call Frame
99 Information instructions. The register number, offset
100 and address fields are provided as possible operands;
101 their use is selected by the opcode field. */
103 typedef union dw_cfi_oprnd_struct
105 unsigned long dw_cfi_reg_num;
106 long int dw_cfi_offset;
111 typedef struct dw_cfi_struct
113 dw_cfi_ref dw_cfi_next;
114 enum dwarf_call_frame_info dw_cfi_opc;
115 dw_cfi_oprnd dw_cfi_oprnd1;
116 dw_cfi_oprnd dw_cfi_oprnd2;
120 /* All call frame descriptions (FDE's) in the GCC generated DWARF
121 refer to a single Common Information Entry (CIE), defined at
122 the beginning of the .debug_frame section. This used of a single
123 CIE obviates the need to keep track of multiple CIE's
124 in the DWARF generation routines below. */
126 typedef struct dw_fde_struct
129 char *dw_fde_current_label;
131 dw_cfi_ref dw_fde_cfi;
135 /* Maximum size (in bytes) of an artificially generated label. */
136 #define MAX_ARTIFICIAL_LABEL_BYTES 30
138 /* Make sure we know the sizes of the various types dwarf can describe. These
139 are only defaults. If the sizes are different for your target, you should
140 override these values by defining the appropriate symbols in your tm.h
143 #ifndef CHAR_TYPE_SIZE
144 #define CHAR_TYPE_SIZE BITS_PER_UNIT
147 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
150 /* The size in bytes of a DWARF field indicating an offset or length
151 relative to a debug info section, specified to be 4 bytes in the DWARF-2
152 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
154 #ifndef DWARF_OFFSET_SIZE
155 #define DWARF_OFFSET_SIZE 4
158 #define DWARF_VERSION 2
160 /* Round SIZE up to the nearest BOUNDARY. */
161 #define DWARF_ROUND(SIZE,BOUNDARY) \
162 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
164 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
165 #ifdef STACK_GROWS_DOWNWARD
166 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
168 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
171 /* A pointer to the base of a table that contains frame description
172 information for each routine. */
173 static dw_fde_ref fde_table;
175 /* Number of elements currently allocated for fde_table. */
176 static unsigned fde_table_allocated;
178 /* Number of elements in fde_table currently in use. */
179 static unsigned fde_table_in_use;
181 /* Size (in elements) of increments by which we may expand the
183 #define FDE_TABLE_INCREMENT 256
185 /* A list of call frame insns for the CIE. */
186 static dw_cfi_ref cie_cfi_head;
188 /* The number of the current function definition for which debugging
189 information is being generated. These numbers range from 1 up to the
190 maximum number of function definitions contained within the current
191 compilation unit. These numbers are used to create unique label id's
192 unique to each function definition. */
193 static unsigned current_funcdef_number = 0;
195 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
196 attribute that accelerates the lookup of the FDE associated
197 with the subprogram. This variable holds the table index of the FDE
198 associated with the current function (body) definition. */
199 static unsigned current_funcdef_fde;
201 /* Forward declarations for functions defined in this file. */
203 static char *stripattributes PARAMS ((const char *));
204 static const char *dwarf_cfi_name PARAMS ((unsigned));
205 static dw_cfi_ref new_cfi PARAMS ((void));
206 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
207 static unsigned long size_of_uleb128 PARAMS ((unsigned long));
208 static unsigned long size_of_sleb128 PARAMS ((long));
209 static void output_uleb128 PARAMS ((unsigned long));
210 static void output_sleb128 PARAMS ((long));
211 static void add_fde_cfi PARAMS ((char *, dw_cfi_ref));
212 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, unsigned long *,
214 static void lookup_cfa PARAMS ((unsigned long *, long *));
215 static void reg_save PARAMS ((char *, unsigned, unsigned,
217 static void initial_return_save PARAMS ((rtx));
218 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
219 static void output_call_frame_info PARAMS ((int));
220 static unsigned reg_number PARAMS ((rtx));
221 static void dwarf2out_stack_adjust PARAMS ((rtx));
222 static void dwarf2out_frame_debug_expr PARAMS ((rtx, char *));
224 /* Definitions of defaults for assembler-dependent names of various
225 pseudo-ops and section names.
226 Theses may be overridden in the tm.h file (if necessary) for a particular
229 #ifdef OBJECT_FORMAT_ELF
230 #ifndef UNALIGNED_SHORT_ASM_OP
231 #define UNALIGNED_SHORT_ASM_OP ".2byte"
233 #ifndef UNALIGNED_INT_ASM_OP
234 #define UNALIGNED_INT_ASM_OP ".4byte"
236 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
237 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
239 #endif /* OBJECT_FORMAT_ELF */
242 #define ASM_BYTE_OP ".byte"
245 /* Data and reference forms for relocatable data. */
246 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
247 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
249 /* Pseudo-op for defining a new section. */
250 #ifndef SECTION_ASM_OP
251 #define SECTION_ASM_OP ".section"
254 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
255 print the SECTION_ASM_OP and the section name. The default here works for
256 almost all svr4 assemblers, except for the sparc, where the section name
257 must be enclosed in double quotes. (See sparcv4.h). */
258 #ifndef SECTION_FORMAT
259 #ifdef PUSHSECTION_FORMAT
260 #define SECTION_FORMAT PUSHSECTION_FORMAT
262 #define SECTION_FORMAT "\t%s\t%s\n"
266 #ifndef FRAME_SECTION
267 #define FRAME_SECTION ".debug_frame"
270 #ifndef FUNC_BEGIN_LABEL
271 #define FUNC_BEGIN_LABEL "LFB"
273 #ifndef FUNC_END_LABEL
274 #define FUNC_END_LABEL "LFE"
276 #define CIE_AFTER_SIZE_LABEL "LSCIE"
277 #define CIE_END_LABEL "LECIE"
278 #define CIE_LENGTH_LABEL "LLCIE"
279 #define FDE_AFTER_SIZE_LABEL "LSFDE"
280 #define FDE_END_LABEL "LEFDE"
281 #define FDE_LENGTH_LABEL "LLFDE"
283 /* Definitions of defaults for various types of primitive assembly language
284 output operations. These may be overridden from within the tm.h file,
285 but typically, that is unnecessary. */
287 #ifndef ASM_OUTPUT_SECTION
288 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
289 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
292 #ifndef ASM_OUTPUT_DWARF_DATA1
293 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
294 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
297 #ifndef ASM_OUTPUT_DWARF_DELTA1
298 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
299 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
300 assemble_name (FILE, LABEL1); \
301 fprintf (FILE, "-"); \
302 assemble_name (FILE, LABEL2); \
306 #ifdef UNALIGNED_INT_ASM_OP
308 #ifndef UNALIGNED_OFFSET_ASM_OP
309 #define UNALIGNED_OFFSET_ASM_OP \
310 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
313 #ifndef UNALIGNED_WORD_ASM_OP
314 #define UNALIGNED_WORD_ASM_OP \
315 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
318 #ifndef ASM_OUTPUT_DWARF_DELTA2
319 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
320 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
321 assemble_name (FILE, LABEL1); \
322 fprintf (FILE, "-"); \
323 assemble_name (FILE, LABEL2); \
327 #ifndef ASM_OUTPUT_DWARF_DELTA4
328 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
329 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
330 assemble_name (FILE, LABEL1); \
331 fprintf (FILE, "-"); \
332 assemble_name (FILE, LABEL2); \
336 #ifndef ASM_OUTPUT_DWARF_DELTA
337 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
338 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
339 assemble_name (FILE, LABEL1); \
340 fprintf (FILE, "-"); \
341 assemble_name (FILE, LABEL2); \
345 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
346 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
347 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
348 assemble_name (FILE, LABEL1); \
349 fprintf (FILE, "-"); \
350 assemble_name (FILE, LABEL2); \
354 #ifndef ASM_OUTPUT_DWARF_ADDR
355 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
356 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
357 assemble_name (FILE, LABEL); \
361 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
362 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
364 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
365 output_addr_const ((FILE), (RTX)); \
366 fputc ('\n', (FILE)); \
370 #ifndef ASM_OUTPUT_DWARF_OFFSET4
371 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
372 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
373 assemble_name (FILE, LABEL); \
377 #ifndef ASM_OUTPUT_DWARF_OFFSET
378 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
379 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
380 assemble_name (FILE, LABEL); \
384 #ifndef ASM_OUTPUT_DWARF_DATA2
385 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
386 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
389 #ifndef ASM_OUTPUT_DWARF_DATA4
390 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
391 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
394 #ifndef ASM_OUTPUT_DWARF_DATA
395 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
396 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
397 (unsigned long) (VALUE))
400 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
401 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
402 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
403 (unsigned long) (VALUE))
406 #ifndef ASM_OUTPUT_DWARF_DATA8
407 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
409 if (WORDS_BIG_ENDIAN) \
411 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
412 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
416 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
417 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
422 #else /* UNALIGNED_INT_ASM_OP */
424 /* We don't have unaligned support, let's hope the normal output works for
427 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
428 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), PTR_SIZE, 1)
430 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
431 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
433 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
434 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
436 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
437 assemble_integer (gen_rtx_MINUS (HImode, \
438 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
439 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
442 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
443 assemble_integer (gen_rtx_MINUS (SImode, \
444 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
445 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
448 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
449 assemble_integer (gen_rtx_MINUS (Pmode, \
450 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
451 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
454 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
455 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
457 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
458 assemble_integer (GEN_INT (VALUE), 4, 1)
460 #endif /* UNALIGNED_INT_ASM_OP */
463 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
464 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
466 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
467 assemble_name (FILE, SY); \
469 assemble_name (FILE, HI); \
471 assemble_name (FILE, LO); \
474 #endif /* SET_ASM_OP */
476 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
477 newline is produced. When flag_debug_asm is asserted, we add commentary
478 at the end of the line, so we must avoid output of a newline here. */
479 #ifndef ASM_OUTPUT_DWARF_STRING
480 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
482 register int slen = strlen(P); \
483 register const char *p = (P); \
485 fprintf (FILE, "\t.ascii \""); \
486 for (i = 0; i < slen; i++) \
488 register int c = p[i]; \
489 if (c == '\"' || c == '\\') \
495 fprintf (FILE, "\\%o", c); \
498 fprintf (FILE, "\\0\""); \
503 /* The DWARF 2 CFA column which tracks the return address. Normally this
504 is the column for PC, or the first column after all of the hard
506 #ifndef DWARF_FRAME_RETURN_COLUMN
508 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
510 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
514 /* The mapping from gcc register number to DWARF 2 CFA column number. By
515 default, we just provide columns for all registers. */
516 #ifndef DWARF_FRAME_REGNUM
517 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
520 /* Hook used by __throw. */
523 expand_builtin_dwarf_fp_regnum ()
525 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
528 /* The offset from the incoming value of %sp to the top of the stack frame
529 for the current function. */
530 #ifndef INCOMING_FRAME_SP_OFFSET
531 #define INCOMING_FRAME_SP_OFFSET 0
534 /* Return a pointer to a copy of the section string name S with all
535 attributes stripped off, and an asterisk prepended (for assemble_name). */
541 char *stripped = xmalloc (strlen (s) + 2);
546 while (*s && *s != ',')
553 /* Return the register number described by a given RTL node. */
559 register unsigned regno = REGNO (rtl);
561 if (regno >= DWARF_FRAME_REGISTERS)
563 warning ("internal regno botch: regno = %d\n", regno);
567 regno = DBX_REGISTER_NUMBER (regno);
571 /* Generate code to initialize the register size table. */
574 expand_builtin_init_dwarf_reg_sizes (address)
578 enum machine_mode mode = TYPE_MODE (char_type_node);
579 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
580 rtx mem = gen_rtx_MEM (mode, addr);
582 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
584 int offset = i * GET_MODE_SIZE (mode);
585 int size = GET_MODE_SIZE (reg_raw_mode[i]);
587 emit_move_insn (change_address (mem, mode,
588 plus_constant (addr, offset)),
593 /* Convert a DWARF call frame info. operation to its string name */
596 dwarf_cfi_name (cfi_opc)
597 register unsigned cfi_opc;
601 case DW_CFA_advance_loc:
602 return "DW_CFA_advance_loc";
604 return "DW_CFA_offset";
606 return "DW_CFA_restore";
610 return "DW_CFA_set_loc";
611 case DW_CFA_advance_loc1:
612 return "DW_CFA_advance_loc1";
613 case DW_CFA_advance_loc2:
614 return "DW_CFA_advance_loc2";
615 case DW_CFA_advance_loc4:
616 return "DW_CFA_advance_loc4";
617 case DW_CFA_offset_extended:
618 return "DW_CFA_offset_extended";
619 case DW_CFA_restore_extended:
620 return "DW_CFA_restore_extended";
621 case DW_CFA_undefined:
622 return "DW_CFA_undefined";
623 case DW_CFA_same_value:
624 return "DW_CFA_same_value";
625 case DW_CFA_register:
626 return "DW_CFA_register";
627 case DW_CFA_remember_state:
628 return "DW_CFA_remember_state";
629 case DW_CFA_restore_state:
630 return "DW_CFA_restore_state";
632 return "DW_CFA_def_cfa";
633 case DW_CFA_def_cfa_register:
634 return "DW_CFA_def_cfa_register";
635 case DW_CFA_def_cfa_offset:
636 return "DW_CFA_def_cfa_offset";
638 /* SGI/MIPS specific */
639 case DW_CFA_MIPS_advance_loc8:
640 return "DW_CFA_MIPS_advance_loc8";
643 case DW_CFA_GNU_window_save:
644 return "DW_CFA_GNU_window_save";
645 case DW_CFA_GNU_args_size:
646 return "DW_CFA_GNU_args_size";
647 case DW_CFA_GNU_negative_offset_extended:
648 return "DW_CFA_GNU_negative_offset_extended";
651 return "DW_CFA_<unknown>";
655 /* Return a pointer to a newly allocated Call Frame Instruction. */
657 static inline dw_cfi_ref
660 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
662 cfi->dw_cfi_next = NULL;
663 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
664 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
669 /* Add a Call Frame Instruction to list of instructions. */
672 add_cfi (list_head, cfi)
673 register dw_cfi_ref *list_head;
674 register dw_cfi_ref cfi;
676 register dw_cfi_ref *p;
678 /* Find the end of the chain. */
679 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
685 /* Generate a new label for the CFI info to refer to. */
688 dwarf2out_cfi_label ()
690 static char label[20];
691 static unsigned long label_num = 0;
693 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
694 ASM_OUTPUT_LABEL (asm_out_file, label);
699 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
700 or to the CIE if LABEL is NULL. */
703 add_fde_cfi (label, cfi)
704 register char *label;
705 register dw_cfi_ref cfi;
709 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
712 label = dwarf2out_cfi_label ();
714 if (fde->dw_fde_current_label == NULL
715 || strcmp (label, fde->dw_fde_current_label) != 0)
717 register dw_cfi_ref xcfi;
719 fde->dw_fde_current_label = label = xstrdup (label);
721 /* Set the location counter to the new label. */
723 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
724 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
725 add_cfi (&fde->dw_fde_cfi, xcfi);
728 add_cfi (&fde->dw_fde_cfi, cfi);
732 add_cfi (&cie_cfi_head, cfi);
735 /* Subroutine of lookup_cfa. */
738 lookup_cfa_1 (cfi, regp, offsetp)
739 register dw_cfi_ref cfi;
740 register unsigned long *regp;
741 register long *offsetp;
743 switch (cfi->dw_cfi_opc)
745 case DW_CFA_def_cfa_offset:
746 *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
748 case DW_CFA_def_cfa_register:
749 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
752 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
753 *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
760 /* Find the previous value for the CFA. */
763 lookup_cfa (regp, offsetp)
764 register unsigned long *regp;
765 register long *offsetp;
767 register dw_cfi_ref cfi;
769 *regp = (unsigned long) -1;
772 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
773 lookup_cfa_1 (cfi, regp, offsetp);
775 if (fde_table_in_use)
777 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
778 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
779 lookup_cfa_1 (cfi, regp, offsetp);
783 /* The current rule for calculating the DWARF2 canonical frame address. */
784 static unsigned long cfa_reg;
785 static long cfa_offset;
787 /* The register used for saving registers to the stack, and its offset
789 static unsigned cfa_store_reg;
790 static long cfa_store_offset;
792 /* The running total of the size of arguments pushed onto the stack. */
793 static long args_size;
795 /* The last args_size we actually output. */
796 static long old_args_size;
798 /* Entry point to update the canonical frame address (CFA).
799 LABEL is passed to add_fde_cfi. The value of CFA is now to be
800 calculated from REG+OFFSET. */
803 dwarf2out_def_cfa (label, reg, offset)
804 register char *label;
805 register unsigned reg;
806 register long offset;
808 register dw_cfi_ref cfi;
809 unsigned long old_reg;
814 if (cfa_store_reg == reg)
815 cfa_store_offset = offset;
817 reg = DWARF_FRAME_REGNUM (reg);
818 lookup_cfa (&old_reg, &old_offset);
820 if (reg == old_reg && offset == old_offset)
827 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
828 cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
831 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
832 else if (offset == old_offset && old_reg != (unsigned long) -1)
834 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
835 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
841 cfi->dw_cfi_opc = DW_CFA_def_cfa;
842 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
843 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
846 add_fde_cfi (label, cfi);
849 /* Add the CFI for saving a register. REG is the CFA column number.
850 LABEL is passed to add_fde_cfi.
851 If SREG is -1, the register is saved at OFFSET from the CFA;
852 otherwise it is saved in SREG. */
855 reg_save (label, reg, sreg, offset)
856 register char * label;
857 register unsigned reg;
858 register unsigned sreg;
859 register long offset;
861 register dw_cfi_ref cfi = new_cfi ();
863 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
865 /* The following comparison is correct. -1 is used to indicate that
866 the value isn't a register number. */
867 if (sreg == (unsigned int) -1)
870 /* The register number won't fit in 6 bits, so we have to use
872 cfi->dw_cfi_opc = DW_CFA_offset_extended;
874 cfi->dw_cfi_opc = DW_CFA_offset;
876 offset /= DWARF_CIE_DATA_ALIGNMENT;
879 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
882 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
886 cfi->dw_cfi_opc = DW_CFA_register;
887 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
890 add_fde_cfi (label, cfi);
893 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
894 This CFI tells the unwinder that it needs to restore the window registers
895 from the previous frame's window save area.
897 ??? Perhaps we should note in the CIE where windows are saved (instead of
898 assuming 0(cfa)) and what registers are in the window. */
901 dwarf2out_window_save (label)
902 register char * label;
904 register dw_cfi_ref cfi = new_cfi ();
905 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
906 add_fde_cfi (label, cfi);
909 /* Add a CFI to update the running total of the size of arguments
910 pushed onto the stack. */
913 dwarf2out_args_size (label, size)
917 register dw_cfi_ref cfi;
919 if (size == old_args_size)
921 old_args_size = size;
924 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
925 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
926 add_fde_cfi (label, cfi);
929 /* Entry point for saving a register to the stack. REG is the GCC register
930 number. LABEL and OFFSET are passed to reg_save. */
933 dwarf2out_reg_save (label, reg, offset)
934 register char * label;
935 register unsigned reg;
936 register long offset;
938 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
941 /* Entry point for saving the return address in the stack.
942 LABEL and OFFSET are passed to reg_save. */
945 dwarf2out_return_save (label, offset)
946 register char * label;
947 register long offset;
949 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
952 /* Entry point for saving the return address in a register.
953 LABEL and SREG are passed to reg_save. */
956 dwarf2out_return_reg (label, sreg)
957 register char * label;
958 register unsigned sreg;
960 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
963 /* Record the initial position of the return address. RTL is
964 INCOMING_RETURN_ADDR_RTX. */
967 initial_return_save (rtl)
970 unsigned int reg = (unsigned int) -1;
973 switch (GET_CODE (rtl))
976 /* RA is in a register. */
977 reg = reg_number (rtl);
980 /* RA is on the stack. */
982 switch (GET_CODE (rtl))
985 if (REGNO (rtl) != STACK_POINTER_REGNUM)
990 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
992 offset = INTVAL (XEXP (rtl, 1));
995 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
997 offset = -INTVAL (XEXP (rtl, 1));
1004 /* The return address is at some offset from any value we can
1005 actually load. For instance, on the SPARC it is in %i7+8. Just
1006 ignore the offset for now; it doesn't matter for unwinding frames. */
1007 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1009 initial_return_save (XEXP (rtl, 0));
1015 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset);
1018 /* Check INSN to see if it looks like a push or a stack adjustment, and
1019 make a note of it if it does. EH uses this information to find out how
1020 much extra space it needs to pop off the stack. */
1023 dwarf2out_stack_adjust (insn)
1029 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1031 /* Extract the size of the args from the CALL rtx itself. */
1033 insn = PATTERN (insn);
1034 if (GET_CODE (insn) == PARALLEL)
1035 insn = XVECEXP (insn, 0, 0);
1036 if (GET_CODE (insn) == SET)
1037 insn = SET_SRC (insn);
1038 assert (GET_CODE (insn) == CALL);
1039 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1043 /* If only calls can throw, and we have a frame pointer,
1044 save up adjustments until we see the CALL_INSN. */
1045 else if (! asynchronous_exceptions
1046 && cfa_reg != STACK_POINTER_REGNUM)
1049 if (GET_CODE (insn) == BARRIER)
1051 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1052 the compiler will have already emitted a stack adjustment, but
1053 doesn't bother for calls to noreturn functions. */
1054 #ifdef STACK_GROWS_DOWNWARD
1055 offset = -args_size;
1060 else if (GET_CODE (PATTERN (insn)) == SET)
1065 insn = PATTERN (insn);
1066 src = SET_SRC (insn);
1067 dest = SET_DEST (insn);
1069 if (dest == stack_pointer_rtx)
1071 /* (set (reg sp) (plus (reg sp) (const_int))) */
1072 code = GET_CODE (src);
1073 if (! (code == PLUS || code == MINUS)
1074 || XEXP (src, 0) != stack_pointer_rtx
1075 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1078 offset = INTVAL (XEXP (src, 1));
1080 else if (GET_CODE (dest) == MEM)
1082 /* (set (mem (pre_dec (reg sp))) (foo)) */
1083 src = XEXP (dest, 0);
1084 code = GET_CODE (src);
1086 if (! (code == PRE_DEC || code == PRE_INC)
1087 || XEXP (src, 0) != stack_pointer_rtx)
1090 offset = GET_MODE_SIZE (GET_MODE (dest));
1095 if (code == PLUS || code == PRE_INC)
1104 if (cfa_reg == STACK_POINTER_REGNUM)
1105 cfa_offset += offset;
1107 #ifndef STACK_GROWS_DOWNWARD
1110 args_size += offset;
1114 label = dwarf2out_cfi_label ();
1115 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1116 dwarf2out_args_size (label, args_size);
1119 /* A temporary register used in adjusting SP or setting up the store_reg. */
1120 static unsigned cfa_temp_reg;
1122 /* A temporary value used in adjusting SP or setting up the store_reg. */
1123 static long cfa_temp_value;
1125 /* Record call frame debugging information for an expression, which either
1126 sets SP or FP (adjusting how we calculate the frame address) or saves a
1127 register to the stack. */
1130 dwarf2out_frame_debug_expr (expr, label)
1137 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1138 the PARALLEL independantly. The first element is always processed if
1139 it is a SET. This is for backward compatability. Other elements
1140 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1141 flag is set in them. */
1143 if (GET_CODE (expr) == PARALLEL)
1146 int limit = XVECLEN (expr, 0);
1148 for (par_index = 0; par_index < limit; par_index++)
1150 rtx x = XVECEXP (expr, 0, par_index);
1152 if (GET_CODE (x) == SET &&
1153 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1154 dwarf2out_frame_debug_expr (x, label);
1159 if (GET_CODE (expr) != SET)
1162 src = SET_SRC (expr);
1163 dest = SET_DEST (expr);
1165 switch (GET_CODE (dest))
1168 /* Update the CFA rule wrt SP or FP. Make sure src is
1169 relative to the current CFA register. */
1170 switch (GET_CODE (src))
1172 /* Setting FP from SP. */
1174 if (cfa_reg != (unsigned) REGNO (src))
1176 if (REGNO (dest) != STACK_POINTER_REGNUM
1177 && !(frame_pointer_needed
1178 && REGNO (dest) == HARD_FRAME_POINTER_REGNUM))
1180 cfa_reg = REGNO (dest);
1185 if (dest == stack_pointer_rtx)
1188 switch (GET_CODE (XEXP (src, 1)))
1191 offset = INTVAL (XEXP (src, 1));
1194 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1196 offset = cfa_temp_value;
1202 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1204 /* Restoring SP from FP in the epilogue. */
1205 if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1207 cfa_reg = STACK_POINTER_REGNUM;
1209 else if (XEXP (src, 0) != stack_pointer_rtx)
1212 if (GET_CODE (src) == PLUS)
1214 if (cfa_reg == STACK_POINTER_REGNUM)
1215 cfa_offset += offset;
1216 if (cfa_store_reg == STACK_POINTER_REGNUM)
1217 cfa_store_offset += offset;
1219 else if (dest == hard_frame_pointer_rtx)
1221 /* Either setting the FP from an offset of the SP,
1222 or adjusting the FP */
1223 if (! frame_pointer_needed
1224 || REGNO (dest) != HARD_FRAME_POINTER_REGNUM)
1227 if (XEXP (src, 0) == stack_pointer_rtx
1228 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1230 if (cfa_reg != STACK_POINTER_REGNUM)
1232 offset = INTVAL (XEXP (src, 1));
1233 if (GET_CODE (src) == PLUS)
1235 cfa_offset += offset;
1236 cfa_reg = HARD_FRAME_POINTER_REGNUM;
1238 else if (XEXP (src, 0) == hard_frame_pointer_rtx
1239 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1241 if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1243 offset = INTVAL (XEXP (src, 1));
1244 if (GET_CODE (src) == PLUS)
1246 cfa_offset += offset;
1254 if (GET_CODE (src) != PLUS
1255 || XEXP (src, 1) != stack_pointer_rtx)
1257 if (GET_CODE (XEXP (src, 0)) != REG
1258 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1260 if (cfa_reg != STACK_POINTER_REGNUM)
1262 cfa_store_reg = REGNO (dest);
1263 cfa_store_offset = cfa_offset - cfa_temp_value;
1268 cfa_temp_reg = REGNO (dest);
1269 cfa_temp_value = INTVAL (src);
1273 if (GET_CODE (XEXP (src, 0)) != REG
1274 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1275 || (unsigned) REGNO (dest) != cfa_temp_reg
1276 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1278 cfa_temp_value |= INTVAL (XEXP (src, 1));
1284 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1288 /* Saving a register to the stack. Make sure dest is relative to the
1290 if (GET_CODE (src) != REG)
1292 switch (GET_CODE (XEXP (dest, 0)))
1297 offset = GET_MODE_SIZE (GET_MODE (dest));
1298 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1301 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1302 || cfa_store_reg != STACK_POINTER_REGNUM)
1304 cfa_store_offset += offset;
1305 if (cfa_reg == STACK_POINTER_REGNUM)
1306 cfa_offset = cfa_store_offset;
1308 offset = -cfa_store_offset;
1311 /* With an offset. */
1314 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1315 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1318 if (cfa_store_reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1320 offset -= cfa_store_offset;
1323 /* Without an offset. */
1325 if (cfa_store_reg != (unsigned) REGNO (XEXP (dest, 0)))
1327 offset = -cfa_store_offset;
1333 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1334 dwarf2out_reg_save (label, REGNO (src), offset);
1343 /* Record call frame debugging information for INSN, which either
1344 sets SP or FP (adjusting how we calculate the frame address) or saves a
1345 register to the stack. If INSN is NULL_RTX, initialize our state. */
1348 dwarf2out_frame_debug (insn)
1354 if (insn == NULL_RTX)
1356 /* Set up state for generating call frame debug info. */
1357 lookup_cfa (&cfa_reg, &cfa_offset);
1358 if (cfa_reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1360 cfa_reg = STACK_POINTER_REGNUM;
1361 cfa_store_reg = cfa_reg;
1362 cfa_store_offset = cfa_offset;
1368 if (! RTX_FRAME_RELATED_P (insn))
1370 dwarf2out_stack_adjust (insn);
1374 label = dwarf2out_cfi_label ();
1376 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1378 insn = XEXP (src, 0);
1380 insn = PATTERN (insn);
1382 dwarf2out_frame_debug_expr (insn, label);
1385 /* Return the size of an unsigned LEB128 quantity. */
1387 static inline unsigned long
1388 size_of_uleb128 (value)
1389 register unsigned long value;
1391 register unsigned long size = 0;
1392 register unsigned byte;
1396 byte = (value & 0x7f);
1405 /* Return the size of a signed LEB128 quantity. */
1407 static inline unsigned long
1408 size_of_sleb128 (value)
1409 register long value;
1411 register unsigned long size = 0;
1412 register unsigned byte;
1416 byte = (value & 0x7f);
1420 while (!(((value == 0) && ((byte & 0x40) == 0))
1421 || ((value == -1) && ((byte & 0x40) != 0))));
1426 /* Output an unsigned LEB128 quantity. */
1429 output_uleb128 (value)
1430 register unsigned long value;
1432 unsigned long save_value = value;
1434 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1437 register unsigned byte = (value & 0x7f);
1440 /* More bytes to follow. */
1443 fprintf (asm_out_file, "0x%x", byte);
1445 fprintf (asm_out_file, ",");
1450 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1453 /* Output an signed LEB128 quantity. */
1456 output_sleb128 (value)
1457 register long value;
1460 register unsigned byte;
1461 long save_value = value;
1463 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1466 byte = (value & 0x7f);
1467 /* arithmetic shift */
1469 more = !((((value == 0) && ((byte & 0x40) == 0))
1470 || ((value == -1) && ((byte & 0x40) != 0))));
1474 fprintf (asm_out_file, "0x%x", byte);
1476 fprintf (asm_out_file, ",");
1481 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1484 /* Output a Call Frame Information opcode and its operand(s). */
1487 output_cfi (cfi, fde)
1488 register dw_cfi_ref cfi;
1489 register dw_fde_ref fde;
1491 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1493 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1495 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1497 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1498 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1499 fputc ('\n', asm_out_file);
1502 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1504 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1506 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1508 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1509 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1511 fputc ('\n', asm_out_file);
1512 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1513 fputc ('\n', asm_out_file);
1515 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1517 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1519 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1521 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1522 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1524 fputc ('\n', asm_out_file);
1528 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1530 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1531 dwarf_cfi_name (cfi->dw_cfi_opc));
1533 fputc ('\n', asm_out_file);
1534 switch (cfi->dw_cfi_opc)
1536 case DW_CFA_set_loc:
1537 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1538 fputc ('\n', asm_out_file);
1540 case DW_CFA_advance_loc1:
1541 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1542 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1543 fde->dw_fde_current_label);
1544 fputc ('\n', asm_out_file);
1545 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1547 case DW_CFA_advance_loc2:
1548 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1549 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1550 fde->dw_fde_current_label);
1551 fputc ('\n', asm_out_file);
1552 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1554 case DW_CFA_advance_loc4:
1555 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1556 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1557 fde->dw_fde_current_label);
1558 fputc ('\n', asm_out_file);
1559 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1561 #ifdef MIPS_DEBUGGING_INFO
1562 case DW_CFA_MIPS_advance_loc8:
1563 /* TODO: not currently implemented. */
1567 case DW_CFA_offset_extended:
1568 case DW_CFA_GNU_negative_offset_extended:
1569 case DW_CFA_def_cfa:
1570 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1571 fputc ('\n', asm_out_file);
1572 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1573 fputc ('\n', asm_out_file);
1575 case DW_CFA_restore_extended:
1576 case DW_CFA_undefined:
1577 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1578 fputc ('\n', asm_out_file);
1580 case DW_CFA_same_value:
1581 case DW_CFA_def_cfa_register:
1582 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1583 fputc ('\n', asm_out_file);
1585 case DW_CFA_register:
1586 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1587 fputc ('\n', asm_out_file);
1588 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1589 fputc ('\n', asm_out_file);
1591 case DW_CFA_def_cfa_offset:
1592 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1593 fputc ('\n', asm_out_file);
1595 case DW_CFA_GNU_window_save:
1597 case DW_CFA_GNU_args_size:
1598 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1599 fputc ('\n', asm_out_file);
1607 /* Output the call frame information used to used to record information
1608 that relates to calculating the frame pointer, and records the
1609 location of saved registers. */
1612 output_call_frame_info (for_eh)
1615 register unsigned long i;
1616 register dw_fde_ref fde;
1617 register dw_cfi_ref cfi;
1618 char l1[20], l2[20];
1619 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1623 /* Do we want to include a pointer to the exception table? */
1624 int eh_ptr = for_eh && exception_table_p ();
1626 fputc ('\n', asm_out_file);
1628 /* We're going to be generating comments, so turn on app. */
1634 #ifdef EH_FRAME_SECTION
1635 EH_FRAME_SECTION ();
1637 tree label = get_file_function_name ('F');
1639 force_data_section ();
1640 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1641 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1642 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1644 assemble_label ("__FRAME_BEGIN__");
1647 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1649 /* Output the CIE. */
1650 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1651 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1652 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1653 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1655 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1657 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1660 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1662 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1665 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1668 fputc ('\n', asm_out_file);
1669 ASM_OUTPUT_LABEL (asm_out_file, l1);
1672 /* Now that the CIE pointer is PC-relative for EH,
1673 use 0 to identify the CIE. */
1674 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1676 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1679 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1681 fputc ('\n', asm_out_file);
1682 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1684 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1685 fputc ('\n', asm_out_file);
1688 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1690 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1692 fputc ('\n', asm_out_file);
1695 /* The CIE contains a pointer to the exception region info for the
1696 frame. Make the augmentation string three bytes (including the
1697 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1698 can't handle unaligned relocs. */
1701 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1702 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1706 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1708 fputc ('\n', asm_out_file);
1710 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1712 fprintf (asm_out_file, "\t%s pointer to exception region info",
1717 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1719 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1723 fputc ('\n', asm_out_file);
1726 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1728 fputc ('\n', asm_out_file);
1729 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1731 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1733 fputc ('\n', asm_out_file);
1734 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1736 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1738 fputc ('\n', asm_out_file);
1740 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1741 output_cfi (cfi, NULL);
1743 /* Pad the CIE out to an address sized boundary. */
1744 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1745 ASM_OUTPUT_LABEL (asm_out_file, l2);
1746 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1747 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1749 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1750 fputc ('\n', asm_out_file);
1753 /* Loop through all of the FDE's. */
1754 for (i = 0; i < fde_table_in_use; ++i)
1756 fde = &fde_table[i];
1758 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2);
1759 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2);
1760 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1761 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2);
1763 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1765 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1768 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1770 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1773 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1774 fputc ('\n', asm_out_file);
1775 ASM_OUTPUT_LABEL (asm_out_file, l1);
1777 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1778 emits a target dependent sized offset when for_eh is not true.
1779 This inconsistency may confuse gdb. The only case where we need a
1780 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1781 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1782 though in order to be compatible with the dwarf_fde struct in frame.c.
1783 If the for_eh case is changed, then the struct in frame.c has
1784 to be adjusted appropriately. */
1786 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1788 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1790 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1792 fputc ('\n', asm_out_file);
1793 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1795 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1797 fputc ('\n', asm_out_file);
1798 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1799 fde->dw_fde_end, fde->dw_fde_begin);
1801 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1803 fputc ('\n', asm_out_file);
1805 /* Loop through the Call Frame Instructions associated with
1807 fde->dw_fde_current_label = fde->dw_fde_begin;
1808 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1809 output_cfi (cfi, fde);
1811 /* Pad the FDE out to an address sized boundary. */
1812 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1813 ASM_OUTPUT_LABEL (asm_out_file, l2);
1814 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1815 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1817 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1818 fputc ('\n', asm_out_file);
1821 #ifndef EH_FRAME_SECTION
1824 /* Emit terminating zero for table. */
1825 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1826 fputc ('\n', asm_out_file);
1829 #ifdef MIPS_DEBUGGING_INFO
1830 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1831 get a value of 0. Putting .align 0 after the label fixes it. */
1832 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1835 /* Turn off app to make assembly quicker. */
1840 /* Output a marker (i.e. a label) for the beginning of a function, before
1844 dwarf2out_begin_prologue ()
1846 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1847 register dw_fde_ref fde;
1849 ++current_funcdef_number;
1851 function_section (current_function_decl);
1852 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1853 current_funcdef_number);
1854 ASM_OUTPUT_LABEL (asm_out_file, label);
1855 current_function_func_begin_label = get_identifier (label);
1857 /* Expand the fde table if necessary. */
1858 if (fde_table_in_use == fde_table_allocated)
1860 fde_table_allocated += FDE_TABLE_INCREMENT;
1862 = (dw_fde_ref) xrealloc (fde_table,
1863 fde_table_allocated * sizeof (dw_fde_node));
1866 /* Record the FDE associated with this function. */
1867 current_funcdef_fde = fde_table_in_use;
1869 /* Add the new FDE at the end of the fde_table. */
1870 fde = &fde_table[fde_table_in_use++];
1871 fde->dw_fde_begin = xstrdup (label);
1872 fde->dw_fde_current_label = NULL;
1873 fde->dw_fde_end = NULL;
1874 fde->dw_fde_cfi = NULL;
1876 args_size = old_args_size = 0;
1879 /* Output a marker (i.e. a label) for the absolute end of the generated code
1880 for a function definition. This gets called *after* the epilogue code has
1884 dwarf2out_end_epilogue ()
1887 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1889 /* Output a label to mark the endpoint of the code generated for this
1891 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1892 ASM_OUTPUT_LABEL (asm_out_file, label);
1893 fde = &fde_table[fde_table_in_use - 1];
1894 fde->dw_fde_end = xstrdup (label);
1898 dwarf2out_frame_init ()
1900 /* Allocate the initial hunk of the fde_table. */
1901 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
1902 fde_table_allocated = FDE_TABLE_INCREMENT;
1903 fde_table_in_use = 0;
1905 /* Generate the CFA instructions common to all FDE's. Do it now for the
1906 sake of lookup_cfa. */
1908 #ifdef DWARF2_UNWIND_INFO
1909 /* On entry, the Canonical Frame Address is at SP. */
1910 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1911 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1916 dwarf2out_frame_finish ()
1918 /* Output call frame information. */
1919 #ifdef MIPS_DEBUGGING_INFO
1920 if (write_symbols == DWARF2_DEBUG)
1921 output_call_frame_info (0);
1922 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1923 output_call_frame_info (1);
1925 if (write_symbols == DWARF2_DEBUG
1926 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1927 output_call_frame_info (1);
1931 #endif /* .debug_frame support */
1933 /* And now, the support for symbolic debugging information. */
1934 #ifdef DWARF2_DEBUGGING_INFO
1936 /* NOTE: In the comments in this file, many references are made to
1937 "Debugging Information Entries". This term is abbreviated as `DIE'
1938 throughout the remainder of this file. */
1940 /* An internal representation of the DWARF output is built, and then
1941 walked to generate the DWARF debugging info. The walk of the internal
1942 representation is done after the entire program has been compiled.
1943 The types below are used to describe the internal representation. */
1945 /* Each DIE may have a series of attribute/value pairs. Values
1946 can take on several forms. The forms that are used in this
1947 implementation are listed below. */
1954 dw_val_class_unsigned_const,
1955 dw_val_class_long_long,
1958 dw_val_class_die_ref,
1959 dw_val_class_fde_ref,
1960 dw_val_class_lbl_id,
1961 dw_val_class_lbl_offset,
1966 /* Various DIE's use offsets relative to the beginning of the
1967 .debug_info section to refer to each other. */
1969 typedef long int dw_offset;
1971 /* Define typedefs here to avoid circular dependencies. */
1973 typedef struct die_struct *dw_die_ref;
1974 typedef struct dw_attr_struct *dw_attr_ref;
1975 typedef struct dw_val_struct *dw_val_ref;
1976 typedef struct dw_line_info_struct *dw_line_info_ref;
1977 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
1978 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1979 typedef struct pubname_struct *pubname_ref;
1980 typedef dw_die_ref *arange_ref;
1982 /* Describe a double word constant value. */
1984 typedef struct dw_long_long_struct
1991 /* Describe a floating point constant value. */
1993 typedef struct dw_fp_struct
2000 /* Each entry in the line_info_table maintains the file and
2001 line number associated with the label generated for that
2002 entry. The label gives the PC value associated with
2003 the line number entry. */
2005 typedef struct dw_line_info_struct
2007 unsigned long dw_file_num;
2008 unsigned long dw_line_num;
2012 /* Line information for functions in separate sections; each one gets its
2014 typedef struct dw_separate_line_info_struct
2016 unsigned long dw_file_num;
2017 unsigned long dw_line_num;
2018 unsigned long function;
2020 dw_separate_line_info_entry;
2022 /* The dw_val_node describes an attribute's value, as it is
2023 represented internally. */
2025 typedef struct dw_val_struct
2027 dw_val_class val_class;
2031 dw_loc_descr_ref val_loc;
2033 long unsigned val_unsigned;
2034 dw_long_long_const val_long_long;
2035 dw_float_const val_float;
2036 dw_die_ref val_die_ref;
2037 unsigned val_fde_index;
2040 unsigned char val_flag;
2046 /* Locations in memory are described using a sequence of stack machine
2049 typedef struct dw_loc_descr_struct
2051 dw_loc_descr_ref dw_loc_next;
2052 enum dwarf_location_atom dw_loc_opc;
2053 dw_val_node dw_loc_oprnd1;
2054 dw_val_node dw_loc_oprnd2;
2058 /* Each DIE attribute has a field specifying the attribute kind,
2059 a link to the next attribute in the chain, and an attribute value.
2060 Attributes are typically linked below the DIE they modify. */
2062 typedef struct dw_attr_struct
2064 enum dwarf_attribute dw_attr;
2065 dw_attr_ref dw_attr_next;
2066 dw_val_node dw_attr_val;
2070 /* The Debugging Information Entry (DIE) structure */
2072 typedef struct die_struct
2074 enum dwarf_tag die_tag;
2075 dw_attr_ref die_attr;
2076 dw_die_ref die_parent;
2077 dw_die_ref die_child;
2079 dw_offset die_offset;
2080 unsigned long die_abbrev;
2084 /* The pubname structure */
2086 typedef struct pubname_struct
2093 /* The limbo die list structure. */
2094 typedef struct limbo_die_struct
2097 struct limbo_die_struct *next;
2101 /* How to start an assembler comment. */
2102 #ifndef ASM_COMMENT_START
2103 #define ASM_COMMENT_START ";#"
2106 /* Define a macro which returns non-zero for a TYPE_DECL which was
2107 implicitly generated for a tagged type.
2109 Note that unlike the gcc front end (which generates a NULL named
2110 TYPE_DECL node for each complete tagged type, each array type, and
2111 each function type node created) the g++ front end generates a
2112 _named_ TYPE_DECL node for each tagged type node created.
2113 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2114 generate a DW_TAG_typedef DIE for them. */
2116 #define TYPE_DECL_IS_STUB(decl) \
2117 (DECL_NAME (decl) == NULL_TREE \
2118 || (DECL_ARTIFICIAL (decl) \
2119 && is_tagged_type (TREE_TYPE (decl)) \
2120 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2121 /* This is necessary for stub decls that \
2122 appear in nested inline functions. */ \
2123 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2124 && (decl_ultimate_origin (decl) \
2125 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2127 /* Information concerning the compilation unit's programming
2128 language, and compiler version. */
2130 extern int flag_traditional;
2132 /* Fixed size portion of the DWARF compilation unit header. */
2133 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2135 /* Fixed size portion of debugging line information prolog. */
2136 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2138 /* Fixed size portion of public names info. */
2139 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2141 /* Fixed size portion of the address range info. */
2142 #define DWARF_ARANGES_HEADER_SIZE \
2143 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
2145 /* The default is to have gcc emit the line number tables. */
2146 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2147 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2150 /* Define the architecture-dependent minimum instruction length (in bytes).
2151 In this implementation of DWARF, this field is used for information
2152 purposes only. Since GCC generates assembly language, we have
2153 no a priori knowledge of how many instruction bytes are generated
2154 for each source line, and therefore can use only the DW_LNE_set_address
2155 and DW_LNS_fixed_advance_pc line information commands. */
2157 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2158 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2161 /* Minimum line offset in a special line info. opcode.
2162 This value was chosen to give a reasonable range of values. */
2163 #define DWARF_LINE_BASE -10
2165 /* First special line opcde - leave room for the standard opcodes. */
2166 #define DWARF_LINE_OPCODE_BASE 10
2168 /* Range of line offsets in a special line info. opcode. */
2169 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2171 /* Flag that indicates the initial value of the is_stmt_start flag.
2172 In the present implementation, we do not mark any lines as
2173 the beginning of a source statement, because that information
2174 is not made available by the GCC front-end. */
2175 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2177 /* This location is used by calc_die_sizes() to keep track
2178 the offset of each DIE within the .debug_info section. */
2179 static unsigned long next_die_offset;
2181 /* Record the root of the DIE's built for the current compilation unit. */
2182 static dw_die_ref comp_unit_die;
2184 /* A list of DIEs with a NULL parent waiting to be relocated. */
2185 static limbo_die_node *limbo_die_list = 0;
2187 /* Pointer to an array of filenames referenced by this compilation unit. */
2188 static char **file_table;
2190 /* Total number of entries in the table (i.e. array) pointed to by
2191 `file_table'. This is the *total* and includes both used and unused
2193 static unsigned file_table_allocated;
2195 /* Number of entries in the file_table which are actually in use. */
2196 static unsigned file_table_in_use;
2198 /* Size (in elements) of increments by which we may expand the filename
2200 #define FILE_TABLE_INCREMENT 64
2202 /* Local pointer to the name of the main input file. Initialized in
2204 static char *primary_filename;
2206 /* A pointer to the base of a table of references to DIE's that describe
2207 declarations. The table is indexed by DECL_UID() which is a unique
2208 number identifying each decl. */
2209 static dw_die_ref *decl_die_table;
2211 /* Number of elements currently allocated for the decl_die_table. */
2212 static unsigned decl_die_table_allocated;
2214 /* Number of elements in decl_die_table currently in use. */
2215 static unsigned decl_die_table_in_use;
2217 /* Size (in elements) of increments by which we may expand the
2219 #define DECL_DIE_TABLE_INCREMENT 256
2221 /* A pointer to the base of a table of references to declaration
2222 scopes. This table is a display which tracks the nesting
2223 of declaration scopes at the current scope and containing
2224 scopes. This table is used to find the proper place to
2225 define type declaration DIE's. */
2226 static tree *decl_scope_table;
2228 /* Number of elements currently allocated for the decl_scope_table. */
2229 static int decl_scope_table_allocated;
2231 /* Current level of nesting of declaration scopes. */
2232 static int decl_scope_depth;
2234 /* Size (in elements) of increments by which we may expand the
2235 decl_scope_table. */
2236 #define DECL_SCOPE_TABLE_INCREMENT 64
2238 /* A pointer to the base of a list of references to DIE's that
2239 are uniquely identified by their tag, presence/absence of
2240 children DIE's, and list of attribute/value pairs. */
2241 static dw_die_ref *abbrev_die_table;
2243 /* Number of elements currently allocated for abbrev_die_table. */
2244 static unsigned abbrev_die_table_allocated;
2246 /* Number of elements in type_die_table currently in use. */
2247 static unsigned abbrev_die_table_in_use;
2249 /* Size (in elements) of increments by which we may expand the
2250 abbrev_die_table. */
2251 #define ABBREV_DIE_TABLE_INCREMENT 256
2253 /* A pointer to the base of a table that contains line information
2254 for each source code line in .text in the compilation unit. */
2255 static dw_line_info_ref line_info_table;
2257 /* Number of elements currently allocated for line_info_table. */
2258 static unsigned line_info_table_allocated;
2260 /* Number of elements in separate_line_info_table currently in use. */
2261 static unsigned separate_line_info_table_in_use;
2263 /* A pointer to the base of a table that contains line information
2264 for each source code line outside of .text in the compilation unit. */
2265 static dw_separate_line_info_ref separate_line_info_table;
2267 /* Number of elements currently allocated for separate_line_info_table. */
2268 static unsigned separate_line_info_table_allocated;
2270 /* Number of elements in line_info_table currently in use. */
2271 static unsigned line_info_table_in_use;
2273 /* Size (in elements) of increments by which we may expand the
2275 #define LINE_INFO_TABLE_INCREMENT 1024
2277 /* A pointer to the base of a table that contains a list of publicly
2278 accessible names. */
2279 static pubname_ref pubname_table;
2281 /* Number of elements currently allocated for pubname_table. */
2282 static unsigned pubname_table_allocated;
2284 /* Number of elements in pubname_table currently in use. */
2285 static unsigned pubname_table_in_use;
2287 /* Size (in elements) of increments by which we may expand the
2289 #define PUBNAME_TABLE_INCREMENT 64
2291 /* A pointer to the base of a table that contains a list of publicly
2292 accessible names. */
2293 static arange_ref arange_table;
2295 /* Number of elements currently allocated for arange_table. */
2296 static unsigned arange_table_allocated;
2298 /* Number of elements in arange_table currently in use. */
2299 static unsigned arange_table_in_use;
2301 /* Size (in elements) of increments by which we may expand the
2303 #define ARANGE_TABLE_INCREMENT 64
2305 /* A pointer to the base of a list of incomplete types which might be
2306 completed at some later time. */
2308 static tree *incomplete_types_list;
2310 /* Number of elements currently allocated for the incomplete_types_list. */
2311 static unsigned incomplete_types_allocated;
2313 /* Number of elements of incomplete_types_list currently in use. */
2314 static unsigned incomplete_types;
2316 /* Size (in elements) of increments by which we may expand the incomplete
2317 types list. Actually, a single hunk of space of this size should
2318 be enough for most typical programs. */
2319 #define INCOMPLETE_TYPES_INCREMENT 64
2321 /* Record whether the function being analyzed contains inlined functions. */
2322 static int current_function_has_inlines;
2323 #if 0 && defined (MIPS_DEBUGGING_INFO)
2324 static int comp_unit_has_inlines;
2327 /* Array of RTXes referenced by the debugging information, which therefore
2328 must be kept around forever. We do this rather than perform GC on
2329 the dwarf info because almost all of the dwarf info lives forever, and
2330 it's easier to support non-GC frontends this way. */
2331 static varray_type used_rtx_varray;
2333 /* Forward declarations for functions defined in this file. */
2335 static int is_pseudo_reg PARAMS ((rtx));
2336 static tree type_main_variant PARAMS ((tree));
2337 static int is_tagged_type PARAMS ((tree));
2338 static const char *dwarf_tag_name PARAMS ((unsigned));
2339 static const char *dwarf_attr_name PARAMS ((unsigned));
2340 static const char *dwarf_form_name PARAMS ((unsigned));
2341 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2343 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
2345 static tree decl_ultimate_origin PARAMS ((tree));
2346 static tree block_ultimate_origin PARAMS ((tree));
2347 static tree decl_class_context PARAMS ((tree));
2348 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
2349 static void add_AT_flag PARAMS ((dw_die_ref,
2350 enum dwarf_attribute,
2352 static void add_AT_int PARAMS ((dw_die_ref,
2353 enum dwarf_attribute, long));
2354 static void add_AT_unsigned PARAMS ((dw_die_ref,
2355 enum dwarf_attribute,
2357 static void add_AT_long_long PARAMS ((dw_die_ref,
2358 enum dwarf_attribute,
2361 static void add_AT_float PARAMS ((dw_die_ref,
2362 enum dwarf_attribute,
2364 static void add_AT_string PARAMS ((dw_die_ref,
2365 enum dwarf_attribute,
2367 static void add_AT_die_ref PARAMS ((dw_die_ref,
2368 enum dwarf_attribute,
2370 static void add_AT_fde_ref PARAMS ((dw_die_ref,
2371 enum dwarf_attribute,
2373 static void add_AT_loc PARAMS ((dw_die_ref,
2374 enum dwarf_attribute,
2376 static void add_AT_addr PARAMS ((dw_die_ref,
2377 enum dwarf_attribute,
2379 static void add_AT_lbl_id PARAMS ((dw_die_ref,
2380 enum dwarf_attribute,
2382 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
2383 enum dwarf_attribute,
2385 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
2386 enum dwarf_attribute));
2387 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
2388 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
2389 static const char *get_AT_string PARAMS ((dw_die_ref,
2390 enum dwarf_attribute));
2391 static int get_AT_flag PARAMS ((dw_die_ref,
2392 enum dwarf_attribute));
2393 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
2394 enum dwarf_attribute));
2395 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
2396 enum dwarf_attribute));
2397 static int is_c_family PARAMS ((void));
2398 static int is_fortran PARAMS ((void));
2399 static void remove_AT PARAMS ((dw_die_ref,
2400 enum dwarf_attribute));
2401 static void remove_children PARAMS ((dw_die_ref));
2402 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
2403 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
2404 static dw_die_ref lookup_type_die PARAMS ((tree));
2405 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
2406 static dw_die_ref lookup_decl_die PARAMS ((tree));
2407 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
2408 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2411 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2413 static void print_spaces PARAMS ((FILE *));
2414 static void print_die PARAMS ((dw_die_ref, FILE *));
2415 static void print_dwarf_line_table PARAMS ((FILE *));
2416 static void add_sibling_attributes PARAMS ((dw_die_ref));
2417 static void build_abbrev_table PARAMS ((dw_die_ref));
2418 static unsigned long size_of_string PARAMS ((const char *));
2419 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2420 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2421 static int constant_size PARAMS ((long unsigned));
2422 static unsigned long size_of_die PARAMS ((dw_die_ref));
2423 static void calc_die_sizes PARAMS ((dw_die_ref));
2424 static unsigned long size_of_line_prolog PARAMS ((void));
2425 static unsigned long size_of_pubnames PARAMS ((void));
2426 static unsigned long size_of_aranges PARAMS ((void));
2427 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
2428 static void output_value_format PARAMS ((dw_attr_ref));
2429 static void output_abbrev_section PARAMS ((void));
2430 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2431 static void output_die PARAMS ((dw_die_ref));
2432 static void output_compilation_unit_header PARAMS ((void));
2433 static const char *dwarf2_name PARAMS ((tree, int));
2434 static void add_pubname PARAMS ((tree, dw_die_ref));
2435 static void output_pubnames PARAMS ((void));
2436 static void add_arange PARAMS ((tree, dw_die_ref));
2437 static void output_aranges PARAMS ((void));
2438 static void output_line_info PARAMS ((void));
2439 static dw_die_ref base_type_die PARAMS ((tree));
2440 static tree root_type PARAMS ((tree));
2441 static int is_base_type PARAMS ((tree));
2442 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
2443 static int type_is_enum PARAMS ((tree));
2444 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
2445 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
2446 static int is_based_loc PARAMS ((rtx));
2447 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
2448 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
2449 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
2450 static unsigned ceiling PARAMS ((unsigned, unsigned));
2451 static tree field_type PARAMS ((tree));
2452 static unsigned simple_type_align_in_bits PARAMS ((tree));
2453 static unsigned simple_type_size_in_bits PARAMS ((tree));
2454 static unsigned field_byte_offset PARAMS ((tree));
2455 static void add_AT_location_description PARAMS ((dw_die_ref,
2456 enum dwarf_attribute, rtx));
2457 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
2458 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
2459 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
2460 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
2461 static void add_bound_info PARAMS ((dw_die_ref,
2462 enum dwarf_attribute, tree));
2463 static void add_subscript_info PARAMS ((dw_die_ref, tree));
2464 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
2465 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
2466 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
2467 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
2468 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
2469 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
2470 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
2471 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
2472 static void push_decl_scope PARAMS ((tree));
2473 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
2474 static void pop_decl_scope PARAMS ((void));
2475 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
2477 static char *type_tag PARAMS ((tree));
2478 static tree member_declared_type PARAMS ((tree));
2480 static char *decl_start_label PARAMS ((tree));
2482 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
2483 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
2485 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
2487 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
2488 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
2489 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
2490 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
2491 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
2492 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
2493 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
2494 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
2495 static void gen_variable_die PARAMS ((tree, dw_die_ref));
2496 static void gen_label_die PARAMS ((tree, dw_die_ref));
2497 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
2498 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
2499 static void gen_field_die PARAMS ((tree, dw_die_ref));
2500 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
2501 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
2502 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
2503 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
2504 static void gen_member_die PARAMS ((tree, dw_die_ref));
2505 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
2506 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
2507 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
2508 static void gen_type_die PARAMS ((tree, dw_die_ref));
2509 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
2510 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
2511 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
2512 static int is_redundant_typedef PARAMS ((tree));
2513 static void gen_decl_die PARAMS ((tree, dw_die_ref));
2514 static unsigned lookup_filename PARAMS ((const char *));
2515 static void add_incomplete_type PARAMS ((tree));
2516 static void retry_incomplete_types PARAMS ((void));
2517 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
2518 static void gen_abstract_function PARAMS ((tree));
2519 static rtx save_rtx PARAMS ((rtx));
2520 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
2521 static void reverse_die_lists PARAMS ((dw_die_ref));
2523 /* Section names used to hold DWARF debugging information. */
2524 #ifndef DEBUG_INFO_SECTION
2525 #define DEBUG_INFO_SECTION ".debug_info"
2527 #ifndef ABBREV_SECTION
2528 #define ABBREV_SECTION ".debug_abbrev"
2530 #ifndef ARANGES_SECTION
2531 #define ARANGES_SECTION ".debug_aranges"
2533 #ifndef DW_MACINFO_SECTION
2534 #define DW_MACINFO_SECTION ".debug_macinfo"
2536 #ifndef DEBUG_LINE_SECTION
2537 #define DEBUG_LINE_SECTION ".debug_line"
2540 #define LOC_SECTION ".debug_loc"
2542 #ifndef PUBNAMES_SECTION
2543 #define PUBNAMES_SECTION ".debug_pubnames"
2546 #define STR_SECTION ".debug_str"
2549 /* Standard ELF section names for compiled code and data. */
2550 #ifndef TEXT_SECTION
2551 #define TEXT_SECTION ".text"
2553 #ifndef DATA_SECTION
2554 #define DATA_SECTION ".data"
2557 #define BSS_SECTION ".bss"
2560 /* Labels we insert at beginning sections we can reference instead of
2561 the section names themselves. */
2563 #ifndef TEXT_SECTION_LABEL
2564 #define TEXT_SECTION_LABEL "Ltext"
2566 #ifndef DEBUG_LINE_SECTION_LABEL
2567 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
2569 #ifndef DEBUG_INFO_SECTION_LABEL
2570 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
2572 #ifndef ABBREV_SECTION_LABEL
2573 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
2577 /* Definitions of defaults for formats and names of various special
2578 (artificial) labels which may be generated within this file (when the -g
2579 options is used and DWARF_DEBUGGING_INFO is in effect.
2580 If necessary, these may be overridden from within the tm.h file, but
2581 typically, overriding these defaults is unnecessary. */
2583 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2584 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2585 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2586 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2587 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2589 #ifndef TEXT_END_LABEL
2590 #define TEXT_END_LABEL "Letext"
2592 #ifndef DATA_END_LABEL
2593 #define DATA_END_LABEL "Ledata"
2595 #ifndef BSS_END_LABEL
2596 #define BSS_END_LABEL "Lebss"
2598 #ifndef INSN_LABEL_FMT
2599 #define INSN_LABEL_FMT "LI%u_"
2601 #ifndef BLOCK_BEGIN_LABEL
2602 #define BLOCK_BEGIN_LABEL "LBB"
2604 #ifndef BLOCK_END_LABEL
2605 #define BLOCK_END_LABEL "LBE"
2607 #ifndef BODY_BEGIN_LABEL
2608 #define BODY_BEGIN_LABEL "Lbb"
2610 #ifndef BODY_END_LABEL
2611 #define BODY_END_LABEL "Lbe"
2613 #ifndef LINE_CODE_LABEL
2614 #define LINE_CODE_LABEL "LM"
2616 #ifndef SEPARATE_LINE_CODE_LABEL
2617 #define SEPARATE_LINE_CODE_LABEL "LSM"
2620 /* We allow a language front-end to designate a function that is to be
2621 called to "demangle" any name before it it put into a DIE. */
2623 static const char *(*demangle_name_func) PARAMS ((const char *));
2626 dwarf2out_set_demangle_name_func (func)
2627 const char *(*func) PARAMS ((const char *));
2629 demangle_name_func = func;
2632 /* Return an rtx like ORIG which lives forever. If we're doing GC,
2633 that means adding it to used_rtx_varray. If not, that means making
2634 a copy on the permanent_obstack. */
2641 VARRAY_PUSH_RTX (used_rtx_varray, orig);
2644 push_obstacks_nochange ();
2645 end_temporary_allocation ();
2646 orig = copy_rtx (orig);
2653 /* Test if rtl node points to a pseudo register. */
2659 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
2660 || ((GET_CODE (rtl) == SUBREG)
2661 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
2664 /* Return a reference to a type, with its const and volatile qualifiers
2668 type_main_variant (type)
2671 type = TYPE_MAIN_VARIANT (type);
2673 /* There really should be only one main variant among any group of variants
2674 of a given type (and all of the MAIN_VARIANT values for all members of
2675 the group should point to that one type) but sometimes the C front-end
2676 messes this up for array types, so we work around that bug here. */
2678 if (TREE_CODE (type) == ARRAY_TYPE)
2679 while (type != TYPE_MAIN_VARIANT (type))
2680 type = TYPE_MAIN_VARIANT (type);
2685 /* Return non-zero if the given type node represents a tagged type. */
2688 is_tagged_type (type)
2691 register enum tree_code code = TREE_CODE (type);
2693 return (code == RECORD_TYPE || code == UNION_TYPE
2694 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
2697 /* Convert a DIE tag into its string name. */
2700 dwarf_tag_name (tag)
2701 register unsigned tag;
2705 case DW_TAG_padding:
2706 return "DW_TAG_padding";
2707 case DW_TAG_array_type:
2708 return "DW_TAG_array_type";
2709 case DW_TAG_class_type:
2710 return "DW_TAG_class_type";
2711 case DW_TAG_entry_point:
2712 return "DW_TAG_entry_point";
2713 case DW_TAG_enumeration_type:
2714 return "DW_TAG_enumeration_type";
2715 case DW_TAG_formal_parameter:
2716 return "DW_TAG_formal_parameter";
2717 case DW_TAG_imported_declaration:
2718 return "DW_TAG_imported_declaration";
2720 return "DW_TAG_label";
2721 case DW_TAG_lexical_block:
2722 return "DW_TAG_lexical_block";
2724 return "DW_TAG_member";
2725 case DW_TAG_pointer_type:
2726 return "DW_TAG_pointer_type";
2727 case DW_TAG_reference_type:
2728 return "DW_TAG_reference_type";
2729 case DW_TAG_compile_unit:
2730 return "DW_TAG_compile_unit";
2731 case DW_TAG_string_type:
2732 return "DW_TAG_string_type";
2733 case DW_TAG_structure_type:
2734 return "DW_TAG_structure_type";
2735 case DW_TAG_subroutine_type:
2736 return "DW_TAG_subroutine_type";
2737 case DW_TAG_typedef:
2738 return "DW_TAG_typedef";
2739 case DW_TAG_union_type:
2740 return "DW_TAG_union_type";
2741 case DW_TAG_unspecified_parameters:
2742 return "DW_TAG_unspecified_parameters";
2743 case DW_TAG_variant:
2744 return "DW_TAG_variant";
2745 case DW_TAG_common_block:
2746 return "DW_TAG_common_block";
2747 case DW_TAG_common_inclusion:
2748 return "DW_TAG_common_inclusion";
2749 case DW_TAG_inheritance:
2750 return "DW_TAG_inheritance";
2751 case DW_TAG_inlined_subroutine:
2752 return "DW_TAG_inlined_subroutine";
2754 return "DW_TAG_module";
2755 case DW_TAG_ptr_to_member_type:
2756 return "DW_TAG_ptr_to_member_type";
2757 case DW_TAG_set_type:
2758 return "DW_TAG_set_type";
2759 case DW_TAG_subrange_type:
2760 return "DW_TAG_subrange_type";
2761 case DW_TAG_with_stmt:
2762 return "DW_TAG_with_stmt";
2763 case DW_TAG_access_declaration:
2764 return "DW_TAG_access_declaration";
2765 case DW_TAG_base_type:
2766 return "DW_TAG_base_type";
2767 case DW_TAG_catch_block:
2768 return "DW_TAG_catch_block";
2769 case DW_TAG_const_type:
2770 return "DW_TAG_const_type";
2771 case DW_TAG_constant:
2772 return "DW_TAG_constant";
2773 case DW_TAG_enumerator:
2774 return "DW_TAG_enumerator";
2775 case DW_TAG_file_type:
2776 return "DW_TAG_file_type";
2778 return "DW_TAG_friend";
2779 case DW_TAG_namelist:
2780 return "DW_TAG_namelist";
2781 case DW_TAG_namelist_item:
2782 return "DW_TAG_namelist_item";
2783 case DW_TAG_packed_type:
2784 return "DW_TAG_packed_type";
2785 case DW_TAG_subprogram:
2786 return "DW_TAG_subprogram";
2787 case DW_TAG_template_type_param:
2788 return "DW_TAG_template_type_param";
2789 case DW_TAG_template_value_param:
2790 return "DW_TAG_template_value_param";
2791 case DW_TAG_thrown_type:
2792 return "DW_TAG_thrown_type";
2793 case DW_TAG_try_block:
2794 return "DW_TAG_try_block";
2795 case DW_TAG_variant_part:
2796 return "DW_TAG_variant_part";
2797 case DW_TAG_variable:
2798 return "DW_TAG_variable";
2799 case DW_TAG_volatile_type:
2800 return "DW_TAG_volatile_type";
2801 case DW_TAG_MIPS_loop:
2802 return "DW_TAG_MIPS_loop";
2803 case DW_TAG_format_label:
2804 return "DW_TAG_format_label";
2805 case DW_TAG_function_template:
2806 return "DW_TAG_function_template";
2807 case DW_TAG_class_template:
2808 return "DW_TAG_class_template";
2810 return "DW_TAG_<unknown>";
2814 /* Convert a DWARF attribute code into its string name. */
2817 dwarf_attr_name (attr)
2818 register unsigned attr;
2823 return "DW_AT_sibling";
2824 case DW_AT_location:
2825 return "DW_AT_location";
2827 return "DW_AT_name";
2828 case DW_AT_ordering:
2829 return "DW_AT_ordering";
2830 case DW_AT_subscr_data:
2831 return "DW_AT_subscr_data";
2832 case DW_AT_byte_size:
2833 return "DW_AT_byte_size";
2834 case DW_AT_bit_offset:
2835 return "DW_AT_bit_offset";
2836 case DW_AT_bit_size:
2837 return "DW_AT_bit_size";
2838 case DW_AT_element_list:
2839 return "DW_AT_element_list";
2840 case DW_AT_stmt_list:
2841 return "DW_AT_stmt_list";
2843 return "DW_AT_low_pc";
2845 return "DW_AT_high_pc";
2846 case DW_AT_language:
2847 return "DW_AT_language";
2849 return "DW_AT_member";
2851 return "DW_AT_discr";
2852 case DW_AT_discr_value:
2853 return "DW_AT_discr_value";
2854 case DW_AT_visibility:
2855 return "DW_AT_visibility";
2857 return "DW_AT_import";
2858 case DW_AT_string_length:
2859 return "DW_AT_string_length";
2860 case DW_AT_common_reference:
2861 return "DW_AT_common_reference";
2862 case DW_AT_comp_dir:
2863 return "DW_AT_comp_dir";
2864 case DW_AT_const_value:
2865 return "DW_AT_const_value";
2866 case DW_AT_containing_type:
2867 return "DW_AT_containing_type";
2868 case DW_AT_default_value:
2869 return "DW_AT_default_value";
2871 return "DW_AT_inline";
2872 case DW_AT_is_optional:
2873 return "DW_AT_is_optional";
2874 case DW_AT_lower_bound:
2875 return "DW_AT_lower_bound";
2876 case DW_AT_producer:
2877 return "DW_AT_producer";
2878 case DW_AT_prototyped:
2879 return "DW_AT_prototyped";
2880 case DW_AT_return_addr:
2881 return "DW_AT_return_addr";
2882 case DW_AT_start_scope:
2883 return "DW_AT_start_scope";
2884 case DW_AT_stride_size:
2885 return "DW_AT_stride_size";
2886 case DW_AT_upper_bound:
2887 return "DW_AT_upper_bound";
2888 case DW_AT_abstract_origin:
2889 return "DW_AT_abstract_origin";
2890 case DW_AT_accessibility:
2891 return "DW_AT_accessibility";
2892 case DW_AT_address_class:
2893 return "DW_AT_address_class";
2894 case DW_AT_artificial:
2895 return "DW_AT_artificial";
2896 case DW_AT_base_types:
2897 return "DW_AT_base_types";
2898 case DW_AT_calling_convention:
2899 return "DW_AT_calling_convention";
2901 return "DW_AT_count";
2902 case DW_AT_data_member_location:
2903 return "DW_AT_data_member_location";
2904 case DW_AT_decl_column:
2905 return "DW_AT_decl_column";
2906 case DW_AT_decl_file:
2907 return "DW_AT_decl_file";
2908 case DW_AT_decl_line:
2909 return "DW_AT_decl_line";
2910 case DW_AT_declaration:
2911 return "DW_AT_declaration";
2912 case DW_AT_discr_list:
2913 return "DW_AT_discr_list";
2914 case DW_AT_encoding:
2915 return "DW_AT_encoding";
2916 case DW_AT_external:
2917 return "DW_AT_external";
2918 case DW_AT_frame_base:
2919 return "DW_AT_frame_base";
2921 return "DW_AT_friend";
2922 case DW_AT_identifier_case:
2923 return "DW_AT_identifier_case";
2924 case DW_AT_macro_info:
2925 return "DW_AT_macro_info";
2926 case DW_AT_namelist_items:
2927 return "DW_AT_namelist_items";
2928 case DW_AT_priority:
2929 return "DW_AT_priority";
2931 return "DW_AT_segment";
2932 case DW_AT_specification:
2933 return "DW_AT_specification";
2934 case DW_AT_static_link:
2935 return "DW_AT_static_link";
2937 return "DW_AT_type";
2938 case DW_AT_use_location:
2939 return "DW_AT_use_location";
2940 case DW_AT_variable_parameter:
2941 return "DW_AT_variable_parameter";
2942 case DW_AT_virtuality:
2943 return "DW_AT_virtuality";
2944 case DW_AT_vtable_elem_location:
2945 return "DW_AT_vtable_elem_location";
2947 case DW_AT_MIPS_fde:
2948 return "DW_AT_MIPS_fde";
2949 case DW_AT_MIPS_loop_begin:
2950 return "DW_AT_MIPS_loop_begin";
2951 case DW_AT_MIPS_tail_loop_begin:
2952 return "DW_AT_MIPS_tail_loop_begin";
2953 case DW_AT_MIPS_epilog_begin:
2954 return "DW_AT_MIPS_epilog_begin";
2955 case DW_AT_MIPS_loop_unroll_factor:
2956 return "DW_AT_MIPS_loop_unroll_factor";
2957 case DW_AT_MIPS_software_pipeline_depth:
2958 return "DW_AT_MIPS_software_pipeline_depth";
2959 case DW_AT_MIPS_linkage_name:
2960 return "DW_AT_MIPS_linkage_name";
2961 case DW_AT_MIPS_stride:
2962 return "DW_AT_MIPS_stride";
2963 case DW_AT_MIPS_abstract_name:
2964 return "DW_AT_MIPS_abstract_name";
2965 case DW_AT_MIPS_clone_origin:
2966 return "DW_AT_MIPS_clone_origin";
2967 case DW_AT_MIPS_has_inlines:
2968 return "DW_AT_MIPS_has_inlines";
2970 case DW_AT_sf_names:
2971 return "DW_AT_sf_names";
2972 case DW_AT_src_info:
2973 return "DW_AT_src_info";
2974 case DW_AT_mac_info:
2975 return "DW_AT_mac_info";
2976 case DW_AT_src_coords:
2977 return "DW_AT_src_coords";
2978 case DW_AT_body_begin:
2979 return "DW_AT_body_begin";
2980 case DW_AT_body_end:
2981 return "DW_AT_body_end";
2983 return "DW_AT_<unknown>";
2987 /* Convert a DWARF value form code into its string name. */
2990 dwarf_form_name (form)
2991 register unsigned form;
2996 return "DW_FORM_addr";
2997 case DW_FORM_block2:
2998 return "DW_FORM_block2";
2999 case DW_FORM_block4:
3000 return "DW_FORM_block4";
3002 return "DW_FORM_data2";
3004 return "DW_FORM_data4";
3006 return "DW_FORM_data8";
3007 case DW_FORM_string:
3008 return "DW_FORM_string";
3010 return "DW_FORM_block";
3011 case DW_FORM_block1:
3012 return "DW_FORM_block1";
3014 return "DW_FORM_data1";
3016 return "DW_FORM_flag";
3018 return "DW_FORM_sdata";
3020 return "DW_FORM_strp";
3022 return "DW_FORM_udata";
3023 case DW_FORM_ref_addr:
3024 return "DW_FORM_ref_addr";
3026 return "DW_FORM_ref1";
3028 return "DW_FORM_ref2";
3030 return "DW_FORM_ref4";
3032 return "DW_FORM_ref8";
3033 case DW_FORM_ref_udata:
3034 return "DW_FORM_ref_udata";
3035 case DW_FORM_indirect:
3036 return "DW_FORM_indirect";
3038 return "DW_FORM_<unknown>";
3042 /* Convert a DWARF stack opcode into its string name. */
3045 dwarf_stack_op_name (op)
3046 register unsigned op;
3051 return "DW_OP_addr";
3053 return "DW_OP_deref";
3055 return "DW_OP_const1u";
3057 return "DW_OP_const1s";
3059 return "DW_OP_const2u";
3061 return "DW_OP_const2s";
3063 return "DW_OP_const4u";
3065 return "DW_OP_const4s";
3067 return "DW_OP_const8u";
3069 return "DW_OP_const8s";
3071 return "DW_OP_constu";
3073 return "DW_OP_consts";
3077 return "DW_OP_drop";
3079 return "DW_OP_over";
3081 return "DW_OP_pick";
3083 return "DW_OP_swap";
3087 return "DW_OP_xderef";
3095 return "DW_OP_minus";
3107 return "DW_OP_plus";
3108 case DW_OP_plus_uconst:
3109 return "DW_OP_plus_uconst";
3115 return "DW_OP_shra";
3133 return "DW_OP_skip";
3135 return "DW_OP_lit0";
3137 return "DW_OP_lit1";
3139 return "DW_OP_lit2";
3141 return "DW_OP_lit3";
3143 return "DW_OP_lit4";
3145 return "DW_OP_lit5";
3147 return "DW_OP_lit6";
3149 return "DW_OP_lit7";
3151 return "DW_OP_lit8";
3153 return "DW_OP_lit9";
3155 return "DW_OP_lit10";
3157 return "DW_OP_lit11";
3159 return "DW_OP_lit12";
3161 return "DW_OP_lit13";
3163 return "DW_OP_lit14";
3165 return "DW_OP_lit15";
3167 return "DW_OP_lit16";
3169 return "DW_OP_lit17";
3171 return "DW_OP_lit18";
3173 return "DW_OP_lit19";
3175 return "DW_OP_lit20";
3177 return "DW_OP_lit21";
3179 return "DW_OP_lit22";
3181 return "DW_OP_lit23";
3183 return "DW_OP_lit24";
3185 return "DW_OP_lit25";
3187 return "DW_OP_lit26";
3189 return "DW_OP_lit27";
3191 return "DW_OP_lit28";
3193 return "DW_OP_lit29";
3195 return "DW_OP_lit30";
3197 return "DW_OP_lit31";
3199 return "DW_OP_reg0";
3201 return "DW_OP_reg1";
3203 return "DW_OP_reg2";
3205 return "DW_OP_reg3";
3207 return "DW_OP_reg4";
3209 return "DW_OP_reg5";
3211 return "DW_OP_reg6";
3213 return "DW_OP_reg7";
3215 return "DW_OP_reg8";
3217 return "DW_OP_reg9";
3219 return "DW_OP_reg10";
3221 return "DW_OP_reg11";
3223 return "DW_OP_reg12";
3225 return "DW_OP_reg13";
3227 return "DW_OP_reg14";
3229 return "DW_OP_reg15";
3231 return "DW_OP_reg16";
3233 return "DW_OP_reg17";
3235 return "DW_OP_reg18";
3237 return "DW_OP_reg19";
3239 return "DW_OP_reg20";
3241 return "DW_OP_reg21";
3243 return "DW_OP_reg22";
3245 return "DW_OP_reg23";
3247 return "DW_OP_reg24";
3249 return "DW_OP_reg25";
3251 return "DW_OP_reg26";
3253 return "DW_OP_reg27";
3255 return "DW_OP_reg28";
3257 return "DW_OP_reg29";
3259 return "DW_OP_reg30";
3261 return "DW_OP_reg31";
3263 return "DW_OP_breg0";
3265 return "DW_OP_breg1";
3267 return "DW_OP_breg2";
3269 return "DW_OP_breg3";
3271 return "DW_OP_breg4";
3273 return "DW_OP_breg5";
3275 return "DW_OP_breg6";
3277 return "DW_OP_breg7";
3279 return "DW_OP_breg8";
3281 return "DW_OP_breg9";
3283 return "DW_OP_breg10";
3285 return "DW_OP_breg11";
3287 return "DW_OP_breg12";
3289 return "DW_OP_breg13";
3291 return "DW_OP_breg14";
3293 return "DW_OP_breg15";
3295 return "DW_OP_breg16";
3297 return "DW_OP_breg17";
3299 return "DW_OP_breg18";
3301 return "DW_OP_breg19";
3303 return "DW_OP_breg20";
3305 return "DW_OP_breg21";
3307 return "DW_OP_breg22";
3309 return "DW_OP_breg23";
3311 return "DW_OP_breg24";
3313 return "DW_OP_breg25";
3315 return "DW_OP_breg26";
3317 return "DW_OP_breg27";
3319 return "DW_OP_breg28";
3321 return "DW_OP_breg29";
3323 return "DW_OP_breg30";
3325 return "DW_OP_breg31";
3327 return "DW_OP_regx";
3329 return "DW_OP_fbreg";
3331 return "DW_OP_bregx";
3333 return "DW_OP_piece";
3334 case DW_OP_deref_size:
3335 return "DW_OP_deref_size";
3336 case DW_OP_xderef_size:
3337 return "DW_OP_xderef_size";
3341 return "OP_<unknown>";
3345 /* Convert a DWARF type code into its string name. */
3349 dwarf_type_encoding_name (enc)
3350 register unsigned enc;
3354 case DW_ATE_address:
3355 return "DW_ATE_address";
3356 case DW_ATE_boolean:
3357 return "DW_ATE_boolean";
3358 case DW_ATE_complex_float:
3359 return "DW_ATE_complex_float";
3361 return "DW_ATE_float";
3363 return "DW_ATE_signed";
3364 case DW_ATE_signed_char:
3365 return "DW_ATE_signed_char";
3366 case DW_ATE_unsigned:
3367 return "DW_ATE_unsigned";
3368 case DW_ATE_unsigned_char:
3369 return "DW_ATE_unsigned_char";
3371 return "DW_ATE_<unknown>";
3376 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3377 instance of an inlined instance of a decl which is local to an inline
3378 function, so we have to trace all of the way back through the origin chain
3379 to find out what sort of node actually served as the original seed for the
3383 decl_ultimate_origin (decl)
3386 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3387 nodes in the function to point to themselves; ignore that if
3388 we're trying to output the abstract instance of this function. */
3389 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
3392 #ifdef ENABLE_CHECKING
3393 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
3394 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3395 most distant ancestor, this should never happen. */
3399 return DECL_ABSTRACT_ORIGIN (decl);
3402 /* Determine the "ultimate origin" of a block. The block may be an inlined
3403 instance of an inlined instance of a block which is local to an inline
3404 function, so we have to trace all of the way back through the origin chain
3405 to find out what sort of node actually served as the original seed for the
3409 block_ultimate_origin (block)
3410 register tree block;
3412 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3414 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
3415 nodes in the function to point to themselves; ignore that if
3416 we're trying to output the abstract instance of this function. */
3417 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
3420 if (immediate_origin == NULL_TREE)
3424 register tree ret_val;
3425 register tree lookahead = immediate_origin;
3429 ret_val = lookahead;
3430 lookahead = (TREE_CODE (ret_val) == BLOCK)
3431 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3434 while (lookahead != NULL && lookahead != ret_val);
3440 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3441 of a virtual function may refer to a base class, so we check the 'this'
3445 decl_class_context (decl)
3448 tree context = NULL_TREE;
3450 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3451 context = DECL_CONTEXT (decl);
3453 context = TYPE_MAIN_VARIANT
3454 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3456 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
3457 context = NULL_TREE;
3462 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
3463 addition order, and correct that in add_sibling_attributes. */
3466 add_dwarf_attr (die, attr)
3467 register dw_die_ref die;
3468 register dw_attr_ref attr;
3470 if (die != NULL && attr != NULL)
3472 attr->dw_attr_next = die->die_attr;
3473 die->die_attr = attr;
3477 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
3478 static inline dw_val_class
3482 return a->dw_attr_val.val_class;
3485 /* Add a flag value attribute to a DIE. */
3488 add_AT_flag (die, attr_kind, flag)
3489 register dw_die_ref die;
3490 register enum dwarf_attribute attr_kind;
3491 register unsigned flag;
3493 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3495 attr->dw_attr_next = NULL;
3496 attr->dw_attr = attr_kind;
3497 attr->dw_attr_val.val_class = dw_val_class_flag;
3498 attr->dw_attr_val.v.val_flag = flag;
3499 add_dwarf_attr (die, attr);
3502 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
3503 static inline unsigned
3505 register dw_attr_ref a;
3507 if (a && AT_class (a) == dw_val_class_flag)
3508 return a->dw_attr_val.v.val_flag;
3513 /* Add a signed integer attribute value to a DIE. */
3516 add_AT_int (die, attr_kind, int_val)
3517 register dw_die_ref die;
3518 register enum dwarf_attribute attr_kind;
3519 register long int int_val;
3521 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3523 attr->dw_attr_next = NULL;
3524 attr->dw_attr = attr_kind;
3525 attr->dw_attr_val.val_class = dw_val_class_const;
3526 attr->dw_attr_val.v.val_int = int_val;
3527 add_dwarf_attr (die, attr);
3530 static inline long int AT_int PARAMS ((dw_attr_ref));
3531 static inline long int
3533 register dw_attr_ref a;
3535 if (a && AT_class (a) == dw_val_class_const)
3536 return a->dw_attr_val.v.val_int;
3541 /* Add an unsigned integer attribute value to a DIE. */
3544 add_AT_unsigned (die, attr_kind, unsigned_val)
3545 register dw_die_ref die;
3546 register enum dwarf_attribute attr_kind;
3547 register unsigned long unsigned_val;
3549 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3551 attr->dw_attr_next = NULL;
3552 attr->dw_attr = attr_kind;
3553 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
3554 attr->dw_attr_val.v.val_unsigned = unsigned_val;
3555 add_dwarf_attr (die, attr);
3558 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
3559 static inline unsigned long
3561 register dw_attr_ref a;
3563 if (a && AT_class (a) == dw_val_class_unsigned_const)
3564 return a->dw_attr_val.v.val_unsigned;
3569 /* Add an unsigned double integer attribute value to a DIE. */
3572 add_AT_long_long (die, attr_kind, val_hi, val_low)
3573 register dw_die_ref die;
3574 register enum dwarf_attribute attr_kind;
3575 register unsigned long val_hi;
3576 register unsigned long val_low;
3578 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3580 attr->dw_attr_next = NULL;
3581 attr->dw_attr = attr_kind;
3582 attr->dw_attr_val.val_class = dw_val_class_long_long;
3583 attr->dw_attr_val.v.val_long_long.hi = val_hi;
3584 attr->dw_attr_val.v.val_long_long.low = val_low;
3585 add_dwarf_attr (die, attr);
3588 /* Add a floating point attribute value to a DIE and return it. */
3591 add_AT_float (die, attr_kind, length, array)
3592 register dw_die_ref die;
3593 register enum dwarf_attribute attr_kind;
3594 register unsigned length;
3595 register long *array;
3597 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3599 attr->dw_attr_next = NULL;
3600 attr->dw_attr = attr_kind;
3601 attr->dw_attr_val.val_class = dw_val_class_float;
3602 attr->dw_attr_val.v.val_float.length = length;
3603 attr->dw_attr_val.v.val_float.array = array;
3604 add_dwarf_attr (die, attr);
3607 /* Add a string attribute value to a DIE. */
3610 add_AT_string (die, attr_kind, str)
3611 register dw_die_ref die;
3612 register enum dwarf_attribute attr_kind;
3613 register const char *str;
3615 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3617 attr->dw_attr_next = NULL;
3618 attr->dw_attr = attr_kind;
3619 attr->dw_attr_val.val_class = dw_val_class_str;
3620 attr->dw_attr_val.v.val_str = xstrdup (str);
3621 add_dwarf_attr (die, attr);
3624 static inline const char *AT_string PARAMS ((dw_attr_ref));
3625 static inline const char *
3627 register dw_attr_ref a;
3629 if (a && AT_class (a) == dw_val_class_str)
3630 return a->dw_attr_val.v.val_str;
3635 /* Add a DIE reference attribute value to a DIE. */
3638 add_AT_die_ref (die, attr_kind, targ_die)
3639 register dw_die_ref die;
3640 register enum dwarf_attribute attr_kind;
3641 register dw_die_ref targ_die;
3643 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3645 attr->dw_attr_next = NULL;
3646 attr->dw_attr = attr_kind;
3647 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3648 attr->dw_attr_val.v.val_die_ref = targ_die;
3649 add_dwarf_attr (die, attr);
3652 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
3653 static inline dw_die_ref
3655 register dw_attr_ref a;
3657 if (a && AT_class (a) == dw_val_class_die_ref)
3658 return a->dw_attr_val.v.val_die_ref;
3663 /* Add an FDE reference attribute value to a DIE. */
3666 add_AT_fde_ref (die, attr_kind, targ_fde)
3667 register dw_die_ref die;
3668 register enum dwarf_attribute attr_kind;
3669 register unsigned targ_fde;
3671 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3673 attr->dw_attr_next = NULL;
3674 attr->dw_attr = attr_kind;
3675 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
3676 attr->dw_attr_val.v.val_fde_index = targ_fde;
3677 add_dwarf_attr (die, attr);
3680 /* Add a location description attribute value to a DIE. */
3683 add_AT_loc (die, attr_kind, loc)
3684 register dw_die_ref die;
3685 register enum dwarf_attribute attr_kind;
3686 register dw_loc_descr_ref loc;
3688 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3690 attr->dw_attr_next = NULL;
3691 attr->dw_attr = attr_kind;
3692 attr->dw_attr_val.val_class = dw_val_class_loc;
3693 attr->dw_attr_val.v.val_loc = loc;
3694 add_dwarf_attr (die, attr);
3697 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
3698 static inline dw_loc_descr_ref
3700 register dw_attr_ref a;
3702 if (a && AT_class (a) == dw_val_class_loc)
3703 return a->dw_attr_val.v.val_loc;
3708 /* Add an address constant attribute value to a DIE. */
3711 add_AT_addr (die, attr_kind, addr)
3712 register dw_die_ref die;
3713 register enum dwarf_attribute attr_kind;
3716 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3718 attr->dw_attr_next = NULL;
3719 attr->dw_attr = attr_kind;
3720 attr->dw_attr_val.val_class = dw_val_class_addr;
3721 attr->dw_attr_val.v.val_addr = addr;
3722 add_dwarf_attr (die, attr);
3725 static inline rtx AT_addr PARAMS ((dw_attr_ref));
3728 register dw_attr_ref a;
3730 if (a && AT_class (a) == dw_val_class_addr)
3731 return a->dw_attr_val.v.val_addr;
3736 /* Add a label identifier attribute value to a DIE. */
3739 add_AT_lbl_id (die, attr_kind, lbl_id)
3740 register dw_die_ref die;
3741 register enum dwarf_attribute attr_kind;
3742 register char *lbl_id;
3744 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3746 attr->dw_attr_next = NULL;
3747 attr->dw_attr = attr_kind;
3748 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
3749 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
3750 add_dwarf_attr (die, attr);
3753 /* Add a section offset attribute value to a DIE. */
3756 add_AT_lbl_offset (die, attr_kind, label)
3757 register dw_die_ref die;
3758 register enum dwarf_attribute attr_kind;
3759 register char *label;
3761 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3763 attr->dw_attr_next = NULL;
3764 attr->dw_attr = attr_kind;
3765 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
3766 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
3767 add_dwarf_attr (die, attr);
3771 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
3772 static inline const char *
3774 register dw_attr_ref a;
3776 if (a && (AT_class (a) == dw_val_class_lbl_id
3777 || AT_class (a) == dw_val_class_lbl_offset))
3778 return a->dw_attr_val.v.val_lbl_id;
3783 /* Get the attribute of type attr_kind. */
3785 static inline dw_attr_ref
3786 get_AT (die, attr_kind)
3787 register dw_die_ref die;
3788 register enum dwarf_attribute attr_kind;
3790 register dw_attr_ref a;
3791 register dw_die_ref spec = NULL;
3795 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3797 if (a->dw_attr == attr_kind)
3800 if (a->dw_attr == DW_AT_specification
3801 || a->dw_attr == DW_AT_abstract_origin)
3806 return get_AT (spec, attr_kind);
3812 /* Return the "low pc" attribute value, typically associated with
3813 a subprogram DIE. Return null if the "low pc" attribute is
3814 either not prsent, or if it cannot be represented as an
3815 assembler label identifier. */
3817 static inline const char *
3819 register dw_die_ref die;
3821 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
3825 /* Return the "high pc" attribute value, typically associated with
3826 a subprogram DIE. Return null if the "high pc" attribute is
3827 either not prsent, or if it cannot be represented as an
3828 assembler label identifier. */
3830 static inline const char *
3832 register dw_die_ref die;
3834 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
3838 /* Return the value of the string attribute designated by ATTR_KIND, or
3839 NULL if it is not present. */
3841 static inline const char *
3842 get_AT_string (die, attr_kind)
3843 register dw_die_ref die;
3844 register enum dwarf_attribute attr_kind;
3846 register dw_attr_ref a = get_AT (die, attr_kind);
3847 return AT_string (a);
3850 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3851 if it is not present. */
3854 get_AT_flag (die, attr_kind)
3855 register dw_die_ref die;
3856 register enum dwarf_attribute attr_kind;
3858 register dw_attr_ref a = get_AT (die, attr_kind);
3862 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3863 if it is not present. */
3865 static inline unsigned
3866 get_AT_unsigned (die, attr_kind)
3867 register dw_die_ref die;
3868 register enum dwarf_attribute attr_kind;
3870 register dw_attr_ref a = get_AT (die, attr_kind);
3871 return AT_unsigned (a);
3874 static inline dw_die_ref
3875 get_AT_ref (die, attr_kind)
3877 register enum dwarf_attribute attr_kind;
3879 register dw_attr_ref a = get_AT (die, attr_kind);
3886 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3888 return (lang == DW_LANG_C || lang == DW_LANG_C89
3889 || lang == DW_LANG_C_plus_plus);
3895 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3897 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
3900 /* Free up the memory used by A. */
3902 static inline void free_AT PARAMS ((dw_attr_ref));
3907 switch (AT_class (a))
3909 case dw_val_class_str:
3910 case dw_val_class_lbl_id:
3911 case dw_val_class_lbl_offset:
3912 free (a->dw_attr_val.v.val_str);
3922 /* Remove the specified attribute if present. */
3925 remove_AT (die, attr_kind)
3926 register dw_die_ref die;
3927 register enum dwarf_attribute attr_kind;
3929 register dw_attr_ref *p;
3930 register dw_attr_ref removed = NULL;
3934 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
3935 if ((*p)->dw_attr == attr_kind)
3938 *p = (*p)->dw_attr_next;
3947 /* Free up the memory used by DIE. */
3949 static inline void free_die PARAMS ((dw_die_ref));
3954 remove_children (die);
3958 /* Discard the children of this DIE. */
3961 remove_children (die)
3962 register dw_die_ref die;
3964 register dw_die_ref child_die = die->die_child;
3966 die->die_child = NULL;
3968 while (child_die != NULL)
3970 register dw_die_ref tmp_die = child_die;
3971 register dw_attr_ref a;
3973 child_die = child_die->die_sib;
3975 for (a = tmp_die->die_attr; a != NULL; )
3977 register dw_attr_ref tmp_a = a;
3979 a = a->dw_attr_next;
3987 /* Add a child DIE below its parent. We build the lists up in reverse
3988 addition order, and correct that in add_sibling_attributes. */
3991 add_child_die (die, child_die)
3992 register dw_die_ref die;
3993 register dw_die_ref child_die;
3995 if (die != NULL && child_die != NULL)
3997 if (die == child_die)
3999 child_die->die_parent = die;
4000 child_die->die_sib = die->die_child;
4001 die->die_child = child_die;
4005 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4006 is the specification, to the front of PARENT's list of children. */
4009 splice_child_die (parent, child)
4010 dw_die_ref parent, child;
4014 /* We want the declaration DIE from inside the class, not the
4015 specification DIE at toplevel. */
4016 if (child->die_parent != parent)
4018 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4023 if (child->die_parent != parent
4024 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4027 for (p = &(parent->die_child); *p; p = &((*p)->die_sib))
4030 *p = child->die_sib;
4034 child->die_sib = parent->die_child;
4035 parent->die_child = child;
4038 /* Return a pointer to a newly created DIE node. */
4040 static inline dw_die_ref
4041 new_die (tag_value, parent_die)
4042 register enum dwarf_tag tag_value;
4043 register dw_die_ref parent_die;
4045 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4047 die->die_tag = tag_value;
4048 die->die_abbrev = 0;
4049 die->die_offset = 0;
4050 die->die_child = NULL;
4051 die->die_parent = NULL;
4052 die->die_sib = NULL;
4053 die->die_attr = NULL;
4055 if (parent_die != NULL)
4056 add_child_die (parent_die, die);
4059 limbo_die_node *limbo_node;
4061 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4062 limbo_node->die = die;
4063 limbo_node->next = limbo_die_list;
4064 limbo_die_list = limbo_node;
4070 /* Return the DIE associated with the given type specifier. */
4072 static inline dw_die_ref
4073 lookup_type_die (type)
4076 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4079 /* Equate a DIE to a given type specifier. */
4082 equate_type_number_to_die (type, type_die)
4084 register dw_die_ref type_die;
4086 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4089 /* Return the DIE associated with a given declaration. */
4091 static inline dw_die_ref
4092 lookup_decl_die (decl)
4095 register unsigned decl_id = DECL_UID (decl);
4097 return (decl_id < decl_die_table_in_use
4098 ? decl_die_table[decl_id] : NULL);
4101 /* Equate a DIE to a particular declaration. */
4104 equate_decl_number_to_die (decl, decl_die)
4106 register dw_die_ref decl_die;
4108 register unsigned decl_id = DECL_UID (decl);
4109 register unsigned num_allocated;
4111 if (decl_id >= decl_die_table_allocated)
4114 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4115 / DECL_DIE_TABLE_INCREMENT)
4116 * DECL_DIE_TABLE_INCREMENT;
4119 = (dw_die_ref *) xrealloc (decl_die_table,
4120 sizeof (dw_die_ref) * num_allocated);
4122 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4123 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4124 decl_die_table_allocated = num_allocated;
4127 if (decl_id >= decl_die_table_in_use)
4128 decl_die_table_in_use = (decl_id + 1);
4130 decl_die_table[decl_id] = decl_die;
4133 /* Return a pointer to a newly allocated location description. Location
4134 descriptions are simple expression terms that can be strung
4135 together to form more complicated location (address) descriptions. */
4137 static inline dw_loc_descr_ref
4138 new_loc_descr (op, oprnd1, oprnd2)
4139 register enum dwarf_location_atom op;
4140 register unsigned long oprnd1;
4141 register unsigned long oprnd2;
4143 register dw_loc_descr_ref descr
4144 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
4146 descr->dw_loc_next = NULL;
4147 descr->dw_loc_opc = op;
4148 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4149 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4150 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4151 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4156 /* Add a location description term to a location description expression. */
4159 add_loc_descr (list_head, descr)
4160 register dw_loc_descr_ref *list_head;
4161 register dw_loc_descr_ref descr;
4163 register dw_loc_descr_ref *d;
4165 /* Find the end of the chain. */
4166 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4172 /* Keep track of the number of spaces used to indent the
4173 output of the debugging routines that print the structure of
4174 the DIE internal representation. */
4175 static int print_indent;
4177 /* Indent the line the number of spaces given by print_indent. */
4180 print_spaces (outfile)
4183 fprintf (outfile, "%*s", print_indent, "");
4186 /* Print the information associated with a given DIE, and its children.
4187 This routine is a debugging aid only. */
4190 print_die (die, outfile)
4194 register dw_attr_ref a;
4195 register dw_die_ref c;
4197 print_spaces (outfile);
4198 fprintf (outfile, "DIE %4lu: %s\n",
4199 die->die_offset, dwarf_tag_name (die->die_tag));
4200 print_spaces (outfile);
4201 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4202 fprintf (outfile, " offset: %lu\n", die->die_offset);
4204 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4206 print_spaces (outfile);
4207 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4209 switch (AT_class (a))
4211 case dw_val_class_addr:
4212 fprintf (outfile, "address");
4214 case dw_val_class_loc:
4215 fprintf (outfile, "location descriptor");
4217 case dw_val_class_const:
4218 fprintf (outfile, "%ld", AT_int (a));
4220 case dw_val_class_unsigned_const:
4221 fprintf (outfile, "%lu", AT_unsigned (a));
4223 case dw_val_class_long_long:
4224 fprintf (outfile, "constant (%lu,%lu)",
4225 a->dw_attr_val.v.val_long_long.hi,
4226 a->dw_attr_val.v.val_long_long.low);
4228 case dw_val_class_float:
4229 fprintf (outfile, "floating-point constant");
4231 case dw_val_class_flag:
4232 fprintf (outfile, "%u", AT_flag (a));
4234 case dw_val_class_die_ref:
4235 if (AT_ref (a) != NULL)
4236 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4238 fprintf (outfile, "die -> <null>");
4240 case dw_val_class_lbl_id:
4241 case dw_val_class_lbl_offset:
4242 fprintf (outfile, "label: %s", AT_lbl (a));
4244 case dw_val_class_str:
4245 if (AT_string (a) != NULL)
4246 fprintf (outfile, "\"%s\"", AT_string (a));
4248 fprintf (outfile, "<null>");
4254 fprintf (outfile, "\n");
4257 if (die->die_child != NULL)
4260 for (c = die->die_child; c != NULL; c = c->die_sib)
4261 print_die (c, outfile);
4267 /* Print the contents of the source code line number correspondence table.
4268 This routine is a debugging aid only. */
4271 print_dwarf_line_table (outfile)
4274 register unsigned i;
4275 register dw_line_info_ref line_info;
4277 fprintf (outfile, "\n\nDWARF source line information\n");
4278 for (i = 1; i < line_info_table_in_use; ++i)
4280 line_info = &line_info_table[i];
4281 fprintf (outfile, "%5d: ", i);
4282 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4283 fprintf (outfile, "%6ld", line_info->dw_line_num);
4284 fprintf (outfile, "\n");
4287 fprintf (outfile, "\n\n");
4290 /* Print the information collected for a given DIE. */
4293 debug_dwarf_die (die)
4296 print_die (die, stderr);
4299 /* Print all DWARF information collected for the compilation unit.
4300 This routine is a debugging aid only. */
4306 print_die (comp_unit_die, stderr);
4307 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4308 print_dwarf_line_table (stderr);
4311 /* We build up the lists of children and attributes by pushing new ones
4312 onto the beginning of the list. Reverse the lists for DIE so that
4313 they are in order of addition. */
4316 reverse_die_lists (die)
4317 register dw_die_ref die;
4319 register dw_die_ref c, cp, cn;
4320 register dw_attr_ref a, ap, an;
4322 for (a = die->die_attr, ap = 0; a; a = an)
4324 an = a->dw_attr_next;
4325 a->dw_attr_next = ap;
4330 for (c = die->die_child, cp = 0; c; c = cn)
4336 die->die_child = cp;
4339 /* Traverse the DIE, reverse its lists of attributes and children, and
4340 add a sibling attribute if it may have the effect of speeding up
4341 access to siblings. To save some space, avoid generating sibling
4342 attributes for DIE's without children. */
4345 add_sibling_attributes (die)
4346 register dw_die_ref die;
4348 register dw_die_ref c;
4350 reverse_die_lists (die);
4352 if (die != comp_unit_die && die->die_sib && die->die_child != NULL)
4353 /* Add the sibling link to the front of the attribute list. */
4354 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
4356 for (c = die->die_child; c != NULL; c = c->die_sib)
4357 add_sibling_attributes (c);
4360 /* The format of each DIE (and its attribute value pairs)
4361 is encoded in an abbreviation table. This routine builds the
4362 abbreviation table and assigns a unique abbreviation id for
4363 each abbreviation entry. The children of each die are visited
4367 build_abbrev_table (die)
4368 register dw_die_ref die;
4370 register unsigned long abbrev_id;
4371 register unsigned long n_alloc;
4372 register dw_die_ref c;
4373 register dw_attr_ref d_attr, a_attr;
4374 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4376 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4378 if (abbrev->die_tag == die->die_tag)
4380 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
4382 a_attr = abbrev->die_attr;
4383 d_attr = die->die_attr;
4385 while (a_attr != NULL && d_attr != NULL)
4387 if ((a_attr->dw_attr != d_attr->dw_attr)
4388 || (value_format (a_attr) != value_format (d_attr)))
4391 a_attr = a_attr->dw_attr_next;
4392 d_attr = d_attr->dw_attr_next;
4395 if (a_attr == NULL && d_attr == NULL)
4401 if (abbrev_id >= abbrev_die_table_in_use)
4403 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
4405 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
4407 = (dw_die_ref *) xrealloc (abbrev_die_table,
4408 sizeof (dw_die_ref) * n_alloc);
4410 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
4411 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
4412 abbrev_die_table_allocated = n_alloc;
4415 ++abbrev_die_table_in_use;
4416 abbrev_die_table[abbrev_id] = die;
4419 die->die_abbrev = abbrev_id;
4420 for (c = die->die_child; c != NULL; c = c->die_sib)
4421 build_abbrev_table (c);
4424 /* Return the size of a string, including the null byte.
4426 This used to treat backslashes as escapes, and hence they were not included
4427 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
4428 which treats a backslash as a backslash, escaping it if necessary, and hence
4429 we must include them in the count. */
4431 static unsigned long
4432 size_of_string (str)
4433 register const char *str;
4435 return strlen (str) + 1;
4438 /* Return the size of a location descriptor. */
4440 static unsigned long
4441 size_of_loc_descr (loc)
4442 register dw_loc_descr_ref loc;
4444 register unsigned long size = 1;
4446 switch (loc->dw_loc_opc)
4468 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4471 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4476 case DW_OP_plus_uconst:
4477 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4515 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4518 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4521 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4524 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4525 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4528 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4530 case DW_OP_deref_size:
4531 case DW_OP_xderef_size:
4541 /* Return the size of a series of location descriptors. */
4543 static unsigned long
4545 register dw_loc_descr_ref loc;
4547 register unsigned long size = 0;
4549 for (; loc != NULL; loc = loc->dw_loc_next)
4550 size += size_of_loc_descr (loc);
4555 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4558 constant_size (value)
4559 long unsigned value;
4566 log = floor_log2 (value);
4569 log = 1 << (floor_log2 (log) + 1);
4574 /* Return the size of a DIE, as it is represented in the
4575 .debug_info section. */
4577 static unsigned long
4579 register dw_die_ref die;
4581 register unsigned long size = 0;
4582 register dw_attr_ref a;
4584 size += size_of_uleb128 (die->die_abbrev);
4585 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4587 switch (AT_class (a))
4589 case dw_val_class_addr:
4592 case dw_val_class_loc:
4594 register unsigned long lsize = size_of_locs (AT_loc (a));
4597 size += constant_size (lsize);
4601 case dw_val_class_const:
4604 case dw_val_class_unsigned_const:
4605 size += constant_size (AT_unsigned (a));
4607 case dw_val_class_long_long:
4608 size += 1 + 8; /* block */
4610 case dw_val_class_float:
4611 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
4613 case dw_val_class_flag:
4616 case dw_val_class_die_ref:
4617 size += DWARF_OFFSET_SIZE;
4619 case dw_val_class_fde_ref:
4620 size += DWARF_OFFSET_SIZE;
4622 case dw_val_class_lbl_id:
4625 case dw_val_class_lbl_offset:
4626 size += DWARF_OFFSET_SIZE;
4628 case dw_val_class_str:
4629 size += size_of_string (AT_string (a));
4639 /* Size the debugging information associated with a given DIE.
4640 Visits the DIE's children recursively. Updates the global
4641 variable next_die_offset, on each time through. Uses the
4642 current value of next_die_offset to update the die_offset
4643 field in each DIE. */
4646 calc_die_sizes (die)
4649 register dw_die_ref c;
4650 die->die_offset = next_die_offset;
4651 next_die_offset += size_of_die (die);
4653 for (c = die->die_child; c != NULL; c = c->die_sib)
4656 if (die->die_child != NULL)
4657 /* Count the null byte used to terminate sibling lists. */
4658 next_die_offset += 1;
4661 /* Return the size of the line information prolog generated for the
4662 compilation unit. */
4664 static unsigned long
4665 size_of_line_prolog ()
4667 register unsigned long size;
4668 register unsigned long ft_index;
4670 size = DWARF_LINE_PROLOG_HEADER_SIZE;
4672 /* Count the size of the table giving number of args for each
4674 size += DWARF_LINE_OPCODE_BASE - 1;
4676 /* Include directory table is empty (at present). Count only the
4677 null byte used to terminate the table. */
4680 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4682 /* File name entry. */
4683 size += size_of_string (file_table[ft_index]);
4685 /* Include directory index. */
4686 size += size_of_uleb128 (0);
4688 /* Modification time. */
4689 size += size_of_uleb128 (0);
4691 /* File length in bytes. */
4692 size += size_of_uleb128 (0);
4695 /* Count the file table terminator. */
4700 /* Return the size of the .debug_pubnames table generated for the
4701 compilation unit. */
4703 static unsigned long
4706 register unsigned long size;
4707 register unsigned i;
4709 size = DWARF_PUBNAMES_HEADER_SIZE;
4710 for (i = 0; i < pubname_table_in_use; ++i)
4712 register pubname_ref p = &pubname_table[i];
4713 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
4716 size += DWARF_OFFSET_SIZE;
4720 /* Return the size of the information in the .debug_aranges section. */
4722 static unsigned long
4725 register unsigned long size;
4727 size = DWARF_ARANGES_HEADER_SIZE;
4729 /* Count the address/length pair for this compilation unit. */
4730 size += 2 * PTR_SIZE;
4731 size += 2 * PTR_SIZE * arange_table_in_use;
4733 /* Count the two zero words used to terminated the address range table. */
4734 size += 2 * PTR_SIZE;
4738 /* Select the encoding of an attribute value. */
4740 static enum dwarf_form
4744 switch (a->dw_attr_val.val_class)
4746 case dw_val_class_addr:
4747 return DW_FORM_addr;
4748 case dw_val_class_loc:
4749 switch (constant_size (size_of_locs (AT_loc (a))))
4752 return DW_FORM_block1;
4754 return DW_FORM_block2;
4758 case dw_val_class_const:
4759 return DW_FORM_data4;
4760 case dw_val_class_unsigned_const:
4761 switch (constant_size (AT_unsigned (a)))
4764 return DW_FORM_data1;
4766 return DW_FORM_data2;
4768 return DW_FORM_data4;
4770 return DW_FORM_data8;
4774 case dw_val_class_long_long:
4775 return DW_FORM_block1;
4776 case dw_val_class_float:
4777 return DW_FORM_block1;
4778 case dw_val_class_flag:
4779 return DW_FORM_flag;
4780 case dw_val_class_die_ref:
4782 case dw_val_class_fde_ref:
4783 return DW_FORM_data;
4784 case dw_val_class_lbl_id:
4785 return DW_FORM_addr;
4786 case dw_val_class_lbl_offset:
4787 return DW_FORM_data;
4788 case dw_val_class_str:
4789 return DW_FORM_string;
4795 /* Output the encoding of an attribute value. */
4798 output_value_format (a)
4801 enum dwarf_form form = value_format (a);
4803 output_uleb128 (form);
4805 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
4807 fputc ('\n', asm_out_file);
4810 /* Output the .debug_abbrev section which defines the DIE abbreviation
4814 output_abbrev_section ()
4816 unsigned long abbrev_id;
4819 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4821 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4823 output_uleb128 (abbrev_id);
4825 fprintf (asm_out_file, " (abbrev code)");
4827 fputc ('\n', asm_out_file);
4828 output_uleb128 (abbrev->die_tag);
4830 fprintf (asm_out_file, " (TAG: %s)",
4831 dwarf_tag_name (abbrev->die_tag));
4833 fputc ('\n', asm_out_file);
4834 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
4835 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
4838 fprintf (asm_out_file, "\t%s %s",
4840 (abbrev->die_child != NULL
4841 ? "DW_children_yes" : "DW_children_no"));
4843 fputc ('\n', asm_out_file);
4845 for (a_attr = abbrev->die_attr; a_attr != NULL;
4846 a_attr = a_attr->dw_attr_next)
4848 output_uleb128 (a_attr->dw_attr);
4850 fprintf (asm_out_file, " (%s)",
4851 dwarf_attr_name (a_attr->dw_attr));
4853 fputc ('\n', asm_out_file);
4854 output_value_format (a_attr);
4857 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
4860 /* Terminate the table. */
4861 fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP);
4864 /* Output location description stack opcode's operands (if any). */
4867 output_loc_operands (loc)
4868 register dw_loc_descr_ref loc;
4870 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
4871 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
4873 switch (loc->dw_loc_opc)
4876 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
4877 fputc ('\n', asm_out_file);
4881 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4882 fputc ('\n', asm_out_file);
4886 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4887 fputc ('\n', asm_out_file);
4891 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
4892 fputc ('\n', asm_out_file);
4897 fputc ('\n', asm_out_file);
4900 output_uleb128 (val1->v.val_unsigned);
4901 fputc ('\n', asm_out_file);
4904 output_sleb128 (val1->v.val_int);
4905 fputc ('\n', asm_out_file);
4908 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
4909 fputc ('\n', asm_out_file);
4911 case DW_OP_plus_uconst:
4912 output_uleb128 (val1->v.val_unsigned);
4913 fputc ('\n', asm_out_file);
4917 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4918 fputc ('\n', asm_out_file);
4952 output_sleb128 (val1->v.val_int);
4953 fputc ('\n', asm_out_file);
4956 output_uleb128 (val1->v.val_unsigned);
4957 fputc ('\n', asm_out_file);
4960 output_sleb128 (val1->v.val_int);
4961 fputc ('\n', asm_out_file);
4964 output_uleb128 (val1->v.val_unsigned);
4965 fputc ('\n', asm_out_file);
4966 output_sleb128 (val2->v.val_int);
4967 fputc ('\n', asm_out_file);
4970 output_uleb128 (val1->v.val_unsigned);
4971 fputc ('\n', asm_out_file);
4973 case DW_OP_deref_size:
4974 case DW_OP_xderef_size:
4975 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4976 fputc ('\n', asm_out_file);
4983 /* Output the DIE and its attributes. Called recursively to generate
4984 the definitions of each child DIE. */
4988 register dw_die_ref die;
4990 register dw_attr_ref a;
4991 register dw_die_ref c;
4992 register unsigned long size;
4993 register dw_loc_descr_ref loc;
4995 output_uleb128 (die->die_abbrev);
4997 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
4998 die->die_offset, dwarf_tag_name (die->die_tag));
5000 fputc ('\n', asm_out_file);
5002 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5004 switch (AT_class (a))
5006 case dw_val_class_addr:
5007 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
5010 case dw_val_class_loc:
5011 size = size_of_locs (AT_loc (a));
5013 /* Output the block length for this list of location operations. */
5014 switch (constant_size (size))
5017 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5020 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5027 fprintf (asm_out_file, "\t%s %s",
5028 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5030 fputc ('\n', asm_out_file);
5031 for (loc = AT_loc (a); loc != NULL; loc = loc->dw_loc_next)
5033 /* Output the opcode. */
5034 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
5036 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
5037 dwarf_stack_op_name (loc->dw_loc_opc));
5039 fputc ('\n', asm_out_file);
5041 /* Output the operand(s) (if any). */
5042 output_loc_operands (loc);
5046 case dw_val_class_const:
5047 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_int (a));
5050 case dw_val_class_unsigned_const:
5051 switch (constant_size (AT_unsigned (a)))
5054 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
5057 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
5060 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
5063 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5064 a->dw_attr_val.v.val_long_long.hi,
5065 a->dw_attr_val.v.val_long_long.low);
5072 case dw_val_class_long_long:
5073 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5075 fprintf (asm_out_file, "\t%s %s",
5076 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5078 fputc ('\n', asm_out_file);
5079 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5080 a->dw_attr_val.v.val_long_long.hi,
5081 a->dw_attr_val.v.val_long_long.low);
5084 fprintf (asm_out_file,
5085 "\t%s long long constant", ASM_COMMENT_START);
5087 fputc ('\n', asm_out_file);
5090 case dw_val_class_float:
5092 register unsigned int i;
5093 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5094 a->dw_attr_val.v.val_float.length * 4);
5096 fprintf (asm_out_file, "\t%s %s",
5097 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5099 fputc ('\n', asm_out_file);
5100 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5102 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5103 a->dw_attr_val.v.val_float.array[i]);
5105 fprintf (asm_out_file, "\t%s fp constant word %u",
5106 ASM_COMMENT_START, i);
5108 fputc ('\n', asm_out_file);
5113 case dw_val_class_flag:
5114 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
5117 case dw_val_class_die_ref:
5118 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
5121 case dw_val_class_fde_ref:
5124 ASM_GENERATE_INTERNAL_LABEL
5125 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5126 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5127 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5131 case dw_val_class_lbl_id:
5132 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
5135 case dw_val_class_lbl_offset:
5136 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
5139 case dw_val_class_str:
5141 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
5143 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
5144 (int) strlen (AT_string (a)) + 1);
5151 if (AT_class (a) != dw_val_class_loc
5152 && AT_class (a) != dw_val_class_long_long
5153 && AT_class (a) != dw_val_class_float)
5156 fprintf (asm_out_file, "\t%s %s",
5157 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5159 fputc ('\n', asm_out_file);
5163 for (c = die->die_child; c != NULL; c = c->die_sib)
5166 if (die->die_child != NULL)
5168 /* Add null byte to terminate sibling list. */
5169 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5171 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
5172 ASM_COMMENT_START, die->die_offset);
5174 fputc ('\n', asm_out_file);
5178 /* Output the compilation unit that appears at the beginning of the
5179 .debug_info section, and precedes the DIE descriptions. */
5182 output_compilation_unit_header ()
5184 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
5186 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
5189 fputc ('\n', asm_out_file);
5190 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5192 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
5194 fputc ('\n', asm_out_file);
5195 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
5197 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
5200 fputc ('\n', asm_out_file);
5201 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5203 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
5205 fputc ('\n', asm_out_file);
5208 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5209 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5210 argument list, and maybe the scope. */
5213 dwarf2_name (decl, scope)
5217 return (*decl_printable_name) (decl, scope ? 1 : 0);
5220 /* Add a new entry to .debug_pubnames if appropriate. */
5223 add_pubname (decl, die)
5229 if (! TREE_PUBLIC (decl))
5232 if (pubname_table_in_use == pubname_table_allocated)
5234 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5235 pubname_table = (pubname_ref) xrealloc
5236 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5239 p = &pubname_table[pubname_table_in_use++];
5242 p->name = xstrdup (dwarf2_name (decl, 1));
5245 /* Output the public names table used to speed up access to externally
5246 visible names. For now, only generate entries for externally
5247 visible procedures. */
5252 register unsigned i;
5253 register unsigned long pubnames_length = size_of_pubnames ();
5255 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
5258 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
5261 fputc ('\n', asm_out_file);
5262 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5265 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5267 fputc ('\n', asm_out_file);
5268 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5270 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5273 fputc ('\n', asm_out_file);
5274 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
5276 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
5278 fputc ('\n', asm_out_file);
5279 for (i = 0; i < pubname_table_in_use; ++i)
5281 register pubname_ref pub = &pubname_table[i];
5283 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
5285 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
5287 fputc ('\n', asm_out_file);
5291 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
5292 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
5296 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
5297 (int) strlen (pub->name) + 1);
5300 fputc ('\n', asm_out_file);
5303 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
5304 fputc ('\n', asm_out_file);
5307 /* Add a new entry to .debug_aranges if appropriate. */
5310 add_arange (decl, die)
5314 if (! DECL_SECTION_NAME (decl))
5317 if (arange_table_in_use == arange_table_allocated)
5319 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5321 = (arange_ref) xrealloc (arange_table,
5322 arange_table_allocated * sizeof (dw_die_ref));
5325 arange_table[arange_table_in_use++] = die;
5328 /* Output the information that goes into the .debug_aranges table.
5329 Namely, define the beginning and ending address range of the
5330 text section generated for this compilation unit. */
5335 register unsigned i;
5336 register unsigned long aranges_length = size_of_aranges ();
5338 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
5340 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
5343 fputc ('\n', asm_out_file);
5344 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5346 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5348 fputc ('\n', asm_out_file);
5349 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5351 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5354 fputc ('\n', asm_out_file);
5355 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5357 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
5359 fputc ('\n', asm_out_file);
5360 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5362 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
5365 fputc ('\n', asm_out_file);
5366 /* We need to align to twice the pointer size here.
5367 If DWARF_OFFSET_SIZE == 4, then we have emitted 12 bytes, and need 4
5368 bytes of padding to align for either 4 or 8 byte pointers. */
5369 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5370 /* If DWARF_OFFSET_SIZE == 8, then we have emitted 20 bytes, and need 12
5371 bytes of padding to align for 8 byte pointers. We have already emitted
5372 4 bytes of padding, so emit 8 more here. */
5373 if (DWARF_OFFSET_SIZE == 8)
5374 fprintf (asm_out_file, ",0,0");
5377 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5378 ASM_COMMENT_START, 2 * PTR_SIZE);
5380 fputc ('\n', asm_out_file);
5381 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
5383 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5385 fputc ('\n', asm_out_file);
5386 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
5387 text_section_label);
5389 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5391 fputc ('\n', asm_out_file);
5392 for (i = 0; i < arange_table_in_use; ++i)
5394 dw_die_ref die = arange_table[i];
5396 if (die->die_tag == DW_TAG_subprogram)
5397 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
5400 /* A static variable; extract the symbol from DW_AT_location.
5401 Note that this code isn't currently hit, as we only emit
5402 aranges for functions (jason 9/23/99). */
5404 dw_attr_ref a = get_AT (die, DW_AT_location);
5405 dw_loc_descr_ref loc;
5406 if (! a || AT_class (a) != dw_val_class_loc)
5410 if (loc->dw_loc_opc != DW_OP_addr)
5413 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
5414 loc->dw_loc_oprnd1.v.val_addr);
5418 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5420 fputc ('\n', asm_out_file);
5421 if (die->die_tag == DW_TAG_subprogram)
5422 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
5423 get_AT_low_pc (die));
5425 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5426 get_AT_unsigned (die, DW_AT_byte_size));
5429 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5431 fputc ('\n', asm_out_file);
5434 /* Output the terminator words. */
5435 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5436 fputc ('\n', asm_out_file);
5437 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5438 fputc ('\n', asm_out_file);
5441 /* Output the source line number correspondence information. This
5442 information goes into the .debug_line section. */
5447 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5448 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5449 register unsigned opc;
5450 register unsigned n_op_args;
5451 register unsigned long ft_index;
5452 register unsigned long lt_index;
5453 register unsigned long current_line;
5454 register long line_offset;
5455 register long line_delta;
5456 register unsigned long current_file;
5457 register unsigned long function;
5459 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
5461 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5464 fputc ('\n', asm_out_file);
5465 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
5466 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5468 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5470 fputc ('\n', asm_out_file);
5471 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
5473 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5475 fputc ('\n', asm_out_file);
5476 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
5478 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5481 fputc ('\n', asm_out_file);
5482 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
5484 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5487 fputc ('\n', asm_out_file);
5488 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
5490 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5493 fputc ('\n', asm_out_file);
5494 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
5496 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5499 fputc ('\n', asm_out_file);
5500 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5502 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5504 fputc ('\n', asm_out_file);
5505 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5509 case DW_LNS_advance_pc:
5510 case DW_LNS_advance_line:
5511 case DW_LNS_set_file:
5512 case DW_LNS_set_column:
5513 case DW_LNS_fixed_advance_pc:
5520 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5522 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5523 ASM_COMMENT_START, opc, n_op_args);
5524 fputc ('\n', asm_out_file);
5528 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5530 /* Include directory table is empty, at present */
5531 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5532 fputc ('\n', asm_out_file);
5534 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5536 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5540 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5541 fprintf (asm_out_file, "%s File Entry: 0x%lx",
5542 ASM_COMMENT_START, ft_index);
5546 ASM_OUTPUT_ASCII (asm_out_file,
5547 file_table[ft_index],
5548 (int) strlen (file_table[ft_index]) + 1);
5551 fputc ('\n', asm_out_file);
5553 /* Include directory index */
5555 fputc ('\n', asm_out_file);
5557 /* Modification time */
5559 fputc ('\n', asm_out_file);
5561 /* File length in bytes */
5563 fputc ('\n', asm_out_file);
5566 /* Terminate the file name table */
5567 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5568 fputc ('\n', asm_out_file);
5570 /* We used to set the address register to the first location in the text
5571 section here, but that didn't accomplish anything since we already
5572 have a line note for the opening brace of the first function. */
5574 /* Generate the line number to PC correspondence table, encoded as
5575 a series of state machine operations. */
5578 strcpy (prev_line_label, text_section_label);
5579 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5581 register dw_line_info_ref line_info = &line_info_table[lt_index];
5584 /* Disable this optimization for now; GDB wants to see two line notes
5585 at the beginning of a function so it can find the end of the
5588 /* Don't emit anything for redundant notes. Just updating the
5589 address doesn't accomplish anything, because we already assume
5590 that anything after the last address is this line. */
5591 if (line_info->dw_line_num == current_line
5592 && line_info->dw_file_num == current_file)
5596 /* Emit debug info for the address of the current line, choosing
5597 the encoding that uses the least amount of space. */
5598 /* ??? Unfortunately, we have little choice here currently, and must
5599 always use the most general form. Gcc does not know the address
5600 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5601 dwarf2 aware assemblers at this time, so we can't use any special
5602 pseudo ops that would allow the assembler to optimally encode this for
5603 us. Many ports do have length attributes which will give an upper
5604 bound on the address range. We could perhaps use length attributes
5605 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5606 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5609 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5610 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5612 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5615 fputc ('\n', asm_out_file);
5616 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5617 fputc ('\n', asm_out_file);
5621 /* This can handle any delta. This takes 4+PTR_SIZE bytes. */
5622 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5624 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5626 fputc ('\n', asm_out_file);
5627 output_uleb128 (1 + PTR_SIZE);
5628 fputc ('\n', asm_out_file);
5629 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5630 fputc ('\n', asm_out_file);
5631 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5632 fputc ('\n', asm_out_file);
5634 strcpy (prev_line_label, line_label);
5636 /* Emit debug info for the source file of the current line, if
5637 different from the previous line. */
5638 if (line_info->dw_file_num != current_file)
5640 current_file = line_info->dw_file_num;
5641 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5643 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5645 fputc ('\n', asm_out_file);
5646 output_uleb128 (current_file);
5648 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5650 fputc ('\n', asm_out_file);
5653 /* Emit debug info for the current line number, choosing the encoding
5654 that uses the least amount of space. */
5655 if (line_info->dw_line_num != current_line)
5657 line_offset = line_info->dw_line_num - current_line;
5658 line_delta = line_offset - DWARF_LINE_BASE;
5659 current_line = line_info->dw_line_num;
5660 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5662 /* This can handle deltas from -10 to 234, using the current
5663 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5665 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5666 DWARF_LINE_OPCODE_BASE + line_delta);
5668 fprintf (asm_out_file,
5669 "\t%s line %ld", ASM_COMMENT_START, current_line);
5671 fputc ('\n', asm_out_file);
5675 /* This can handle any delta. This takes at least 4 bytes,
5676 depending on the value being encoded. */
5677 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5679 fprintf (asm_out_file, "\t%s advance to line %ld",
5680 ASM_COMMENT_START, current_line);
5682 fputc ('\n', asm_out_file);
5683 output_sleb128 (line_offset);
5684 fputc ('\n', asm_out_file);
5685 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5687 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5688 fputc ('\n', asm_out_file);
5693 /* We still need to start a new row, so output a copy insn. */
5694 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5696 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5697 fputc ('\n', asm_out_file);
5701 /* Emit debug info for the address of the end of the function. */
5704 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5706 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5709 fputc ('\n', asm_out_file);
5710 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
5711 fputc ('\n', asm_out_file);
5715 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5717 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5718 fputc ('\n', asm_out_file);
5719 output_uleb128 (1 + PTR_SIZE);
5720 fputc ('\n', asm_out_file);
5721 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5722 fputc ('\n', asm_out_file);
5723 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
5724 fputc ('\n', asm_out_file);
5727 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5729 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
5731 fputc ('\n', asm_out_file);
5733 fputc ('\n', asm_out_file);
5734 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5735 fputc ('\n', asm_out_file);
5740 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5742 register dw_separate_line_info_ref line_info
5743 = &separate_line_info_table[lt_index];
5746 /* Don't emit anything for redundant notes. */
5747 if (line_info->dw_line_num == current_line
5748 && line_info->dw_file_num == current_file
5749 && line_info->function == function)
5753 /* Emit debug info for the address of the current line. If this is
5754 a new function, or the first line of a function, then we need
5755 to handle it differently. */
5756 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
5758 if (function != line_info->function)
5760 function = line_info->function;
5762 /* Set the address register to the first line in the function */
5763 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5765 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5768 fputc ('\n', asm_out_file);
5769 output_uleb128 (1 + PTR_SIZE);
5770 fputc ('\n', asm_out_file);
5771 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5772 fputc ('\n', asm_out_file);
5773 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5774 fputc ('\n', asm_out_file);
5778 /* ??? See the DW_LNS_advance_pc comment above. */
5781 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5783 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5786 fputc ('\n', asm_out_file);
5787 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5789 fputc ('\n', asm_out_file);
5793 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5795 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5797 fputc ('\n', asm_out_file);
5798 output_uleb128 (1 + PTR_SIZE);
5799 fputc ('\n', asm_out_file);
5800 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5801 fputc ('\n', asm_out_file);
5802 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5803 fputc ('\n', asm_out_file);
5806 strcpy (prev_line_label, line_label);
5808 /* Emit debug info for the source file of the current line, if
5809 different from the previous line. */
5810 if (line_info->dw_file_num != current_file)
5812 current_file = line_info->dw_file_num;
5813 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5815 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5817 fputc ('\n', asm_out_file);
5818 output_uleb128 (current_file);
5820 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5822 fputc ('\n', asm_out_file);
5825 /* Emit debug info for the current line number, choosing the encoding
5826 that uses the least amount of space. */
5827 if (line_info->dw_line_num != current_line)
5829 line_offset = line_info->dw_line_num - current_line;
5830 line_delta = line_offset - DWARF_LINE_BASE;
5831 current_line = line_info->dw_line_num;
5832 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5834 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5835 DWARF_LINE_OPCODE_BASE + line_delta);
5837 fprintf (asm_out_file,
5838 "\t%s line %ld", ASM_COMMENT_START, current_line);
5840 fputc ('\n', asm_out_file);
5844 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5846 fprintf (asm_out_file, "\t%s advance to line %ld",
5847 ASM_COMMENT_START, current_line);
5849 fputc ('\n', asm_out_file);
5850 output_sleb128 (line_offset);
5851 fputc ('\n', asm_out_file);
5852 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5854 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5855 fputc ('\n', asm_out_file);
5860 /* We still need to start a new row, so output a copy insn. */
5861 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5863 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5864 fputc ('\n', asm_out_file);
5872 /* If we're done with a function, end its sequence. */
5873 if (lt_index == separate_line_info_table_in_use
5874 || separate_line_info_table[lt_index].function != function)
5879 /* Emit debug info for the address of the end of the function. */
5880 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
5883 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5885 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5888 fputc ('\n', asm_out_file);
5889 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5891 fputc ('\n', asm_out_file);
5895 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5897 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5899 fputc ('\n', asm_out_file);
5900 output_uleb128 (1 + PTR_SIZE);
5901 fputc ('\n', asm_out_file);
5902 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5903 fputc ('\n', asm_out_file);
5904 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5905 fputc ('\n', asm_out_file);
5908 /* Output the marker for the end of this sequence. */
5909 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5911 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
5914 fputc ('\n', asm_out_file);
5916 fputc ('\n', asm_out_file);
5917 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5918 fputc ('\n', asm_out_file);
5922 /* Output the marker for the end of the line number info. */
5923 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
5926 /* Given a pointer to a tree node for some base type, return a pointer to
5927 a DIE that describes the given type.
5929 This routine must only be called for GCC type nodes that correspond to
5930 Dwarf base (fundamental) types. */
5933 base_type_die (type)
5936 register dw_die_ref base_type_result;
5937 register const char *type_name;
5938 register enum dwarf_type encoding;
5939 register tree name = TYPE_NAME (type);
5941 if (TREE_CODE (type) == ERROR_MARK
5942 || TREE_CODE (type) == VOID_TYPE)
5947 if (TREE_CODE (name) == TYPE_DECL)
5948 name = DECL_NAME (name);
5950 type_name = IDENTIFIER_POINTER (name);
5953 type_name = "__unknown__";
5955 switch (TREE_CODE (type))
5958 /* Carefully distinguish the C character types, without messing
5959 up if the language is not C. Note that we check only for the names
5960 that contain spaces; other names might occur by coincidence in other
5962 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
5963 && (type == char_type_node
5964 || ! strcmp (type_name, "signed char")
5965 || ! strcmp (type_name, "unsigned char"))))
5967 if (TREE_UNSIGNED (type))
5968 encoding = DW_ATE_unsigned;
5970 encoding = DW_ATE_signed;
5973 /* else fall through */
5976 /* GNU Pascal/Ada CHAR type. Not used in C. */
5977 if (TREE_UNSIGNED (type))
5978 encoding = DW_ATE_unsigned_char;
5980 encoding = DW_ATE_signed_char;
5984 encoding = DW_ATE_float;
5987 /* Dwarf2 doesn't know anything about complex ints, so use
5988 a user defined type for it. */
5990 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
5991 encoding = DW_ATE_complex_float;
5993 encoding = DW_ATE_lo_user;
5997 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
5998 encoding = DW_ATE_boolean;
6002 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6005 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6006 if (demangle_name_func)
6007 type_name = (*demangle_name_func) (type_name);
6009 add_AT_string (base_type_result, DW_AT_name, type_name);
6010 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6011 int_size_in_bytes (type));
6012 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6014 return base_type_result;
6017 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6018 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6019 a given type is generally the same as the given type, except that if the
6020 given type is a pointer or reference type, then the root type of the given
6021 type is the root type of the "basis" type for the pointer or reference
6022 type. (This definition of the "root" type is recursive.) Also, the root
6023 type of a `const' qualified type or a `volatile' qualified type is the
6024 root type of the given type without the qualifiers. */
6030 if (TREE_CODE (type) == ERROR_MARK)
6031 return error_mark_node;
6033 switch (TREE_CODE (type))
6036 return error_mark_node;
6039 case REFERENCE_TYPE:
6040 return type_main_variant (root_type (TREE_TYPE (type)));
6043 return type_main_variant (type);
6047 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6048 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6054 switch (TREE_CODE (type))
6069 case QUAL_UNION_TYPE:
6074 case REFERENCE_TYPE:
6087 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6088 entry that chains various modifiers in front of the given type. */
6091 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6093 register int is_const_type;
6094 register int is_volatile_type;
6095 register dw_die_ref context_die;
6097 register enum tree_code code = TREE_CODE (type);
6098 register dw_die_ref mod_type_die = NULL;
6099 register dw_die_ref sub_die = NULL;
6100 register tree item_type = NULL;
6102 if (code != ERROR_MARK)
6104 type = build_type_variant (type, is_const_type, is_volatile_type);
6106 mod_type_die = lookup_type_die (type);
6108 return mod_type_die;
6110 /* Handle C typedef types. */
6111 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6112 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6114 tree dtype = TREE_TYPE (TYPE_NAME (type));
6117 /* For a named type, use the typedef. */
6118 gen_type_die (type, context_die);
6119 mod_type_die = lookup_type_die (type);
6122 else if (is_const_type < TYPE_READONLY (dtype)
6123 || is_volatile_type < TYPE_VOLATILE (dtype))
6124 /* cv-unqualified version of named type. Just use the unnamed
6125 type to which it refers. */
6127 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6128 is_const_type, is_volatile_type,
6130 /* Else cv-qualified version of named type; fall through. */
6135 else if (is_const_type)
6137 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6138 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6140 else if (is_volatile_type)
6142 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6143 sub_die = modified_type_die (type, 0, 0, context_die);
6145 else if (code == POINTER_TYPE)
6147 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6148 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6150 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6152 item_type = TREE_TYPE (type);
6154 else if (code == REFERENCE_TYPE)
6156 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6157 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6159 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6161 item_type = TREE_TYPE (type);
6163 else if (is_base_type (type))
6164 mod_type_die = base_type_die (type);
6167 gen_type_die (type, context_die);
6169 /* We have to get the type_main_variant here (and pass that to the
6170 `lookup_type_die' routine) because the ..._TYPE node we have
6171 might simply be a *copy* of some original type node (where the
6172 copy was created to help us keep track of typedef names) and
6173 that copy might have a different TYPE_UID from the original
6175 mod_type_die = lookup_type_die (type_main_variant (type));
6176 if (mod_type_die == NULL)
6181 equate_type_number_to_die (type, mod_type_die);
6183 /* We must do this after the equate_type_number_to_die call, in case
6184 this is a recursive type. This ensures that the modified_type_die
6185 recursion will terminate even if the type is recursive. Recursive
6186 types are possible in Ada. */
6187 sub_die = modified_type_die (item_type,
6188 TYPE_READONLY (item_type),
6189 TYPE_VOLATILE (item_type),
6192 if (sub_die != NULL)
6193 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6195 return mod_type_die;
6198 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6199 an enumerated type. */
6205 return TREE_CODE (type) == ENUMERAL_TYPE;
6208 /* Return a location descriptor that designates a machine register. */
6210 static dw_loc_descr_ref
6211 reg_loc_descriptor (rtl)
6214 register dw_loc_descr_ref loc_result = NULL;
6215 register unsigned reg = reg_number (rtl);
6218 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6220 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6225 /* Return a location descriptor that designates a base+offset location. */
6227 static dw_loc_descr_ref
6228 based_loc_descr (reg, offset)
6232 register dw_loc_descr_ref loc_result;
6233 /* For the "frame base", we use the frame pointer or stack pointer
6234 registers, since the RTL for local variables is relative to one of
6236 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6237 ? HARD_FRAME_POINTER_REGNUM
6238 : STACK_POINTER_REGNUM);
6241 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
6243 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
6245 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
6250 /* Return true if this RTL expression describes a base+offset calculation. */
6256 return (GET_CODE (rtl) == PLUS
6257 && ((GET_CODE (XEXP (rtl, 0)) == REG
6258 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
6261 /* The following routine converts the RTL for a variable or parameter
6262 (resident in memory) into an equivalent Dwarf representation of a
6263 mechanism for getting the address of that same variable onto the top of a
6264 hypothetical "address evaluation" stack.
6266 When creating memory location descriptors, we are effectively transforming
6267 the RTL for a memory-resident object into its Dwarf postfix expression
6268 equivalent. This routine recursively descends an RTL tree, turning
6269 it into Dwarf postfix code as it goes.
6271 MODE is the mode of the memory reference, needed to handle some
6272 autoincrement addressing modes. */
6274 static dw_loc_descr_ref
6275 mem_loc_descriptor (rtl, mode)
6277 enum machine_mode mode;
6279 dw_loc_descr_ref mem_loc_result = NULL;
6280 /* Note that for a dynamically sized array, the location we will generate a
6281 description of here will be the lowest numbered location which is
6282 actually within the array. That's *not* necessarily the same as the
6283 zeroth element of the array. */
6285 #ifdef ASM_SIMPLIFY_DWARF_ADDR
6286 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
6289 switch (GET_CODE (rtl))
6293 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
6294 just fall into the SUBREG code. */
6296 /* ... fall through ... */
6299 /* The case of a subreg may arise when we have a local (register)
6300 variable or a formal (register) parameter which doesn't quite fill
6301 up an entire register. For now, just assume that it is
6302 legitimate to make the Dwarf info refer to the whole register which
6303 contains the given subreg. */
6304 rtl = XEXP (rtl, 0);
6306 /* ... fall through ... */
6309 /* Whenever a register number forms a part of the description of the
6310 method for calculating the (dynamic) address of a memory resident
6311 object, DWARF rules require the register number be referred to as
6312 a "base register". This distinction is not based in any way upon
6313 what category of register the hardware believes the given register
6314 belongs to. This is strictly DWARF terminology we're dealing with
6315 here. Note that in cases where the location of a memory-resident
6316 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6317 OP_CONST (0)) the actual DWARF location descriptor that we generate
6318 may just be OP_BASEREG (basereg). This may look deceptively like
6319 the object in question was allocated to a register (rather than in
6320 memory) so DWARF consumers need to be aware of the subtle
6321 distinction between OP_REG and OP_BASEREG. */
6322 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
6326 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
6327 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6331 /* Some ports can transform a symbol ref into a label ref, because
6332 the symbol ref is too far away and has to be dumped into a constant
6336 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6337 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6338 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
6343 /* Turn these into a PLUS expression and fall into the PLUS code
6345 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
6346 GEN_INT (GET_CODE (rtl) == PRE_INC
6347 ? GET_MODE_UNIT_SIZE (mode)
6348 : - GET_MODE_UNIT_SIZE (mode)));
6350 /* ... fall through ... */
6353 if (is_based_loc (rtl))
6354 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
6355 INTVAL (XEXP (rtl, 1)));
6358 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0),
6360 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1),
6362 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
6367 /* If a pseudo-reg is optimized away, it is possible for it to
6368 be replaced with a MEM containing a multiply. */
6369 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode));
6370 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode));
6371 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
6375 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6382 return mem_loc_result;
6385 /* Return a descriptor that describes the concatenation of two locations.
6386 This is typically a complex variable. */
6388 static dw_loc_descr_ref
6389 concat_loc_descriptor (x0, x1)
6390 register rtx x0, x1;
6392 dw_loc_descr_ref cc_loc_result = NULL;
6394 if (!is_pseudo_reg (x0)
6395 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
6396 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
6397 add_loc_descr (&cc_loc_result,
6398 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
6400 if (!is_pseudo_reg (x1)
6401 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
6402 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
6403 add_loc_descr (&cc_loc_result,
6404 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
6406 return cc_loc_result;
6409 /* Output a proper Dwarf location descriptor for a variable or parameter
6410 which is either allocated in a register or in a memory location. For a
6411 register, we just generate an OP_REG and the register number. For a
6412 memory location we provide a Dwarf postfix expression describing how to
6413 generate the (dynamic) address of the object onto the address stack. */
6415 static dw_loc_descr_ref
6416 loc_descriptor (rtl)
6419 dw_loc_descr_ref loc_result = NULL;
6420 switch (GET_CODE (rtl))
6423 /* The case of a subreg may arise when we have a local (register)
6424 variable or a formal (register) parameter which doesn't quite fill
6425 up an entire register. For now, just assume that it is
6426 legitimate to make the Dwarf info refer to the whole register which
6427 contains the given subreg. */
6428 rtl = XEXP (rtl, 0);
6430 /* ... fall through ... */
6433 loc_result = reg_loc_descriptor (rtl);
6437 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
6441 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
6451 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
6452 which is not less than the value itself. */
6454 static inline unsigned
6455 ceiling (value, boundary)
6456 register unsigned value;
6457 register unsigned boundary;
6459 return (((value + boundary - 1) / boundary) * boundary);
6462 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6463 pointer to the declared type for the relevant field variable, or return
6464 `integer_type_node' if the given node turns out to be an
6473 if (TREE_CODE (decl) == ERROR_MARK)
6474 return integer_type_node;
6476 type = DECL_BIT_FIELD_TYPE (decl);
6477 if (type == NULL_TREE)
6478 type = TREE_TYPE (decl);
6483 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6484 node, return the alignment in bits for the type, or else return
6485 BITS_PER_WORD if the node actually turns out to be an
6488 static inline unsigned
6489 simple_type_align_in_bits (type)
6492 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6495 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6496 node, return the size in bits for the type if it is a constant, or else
6497 return the alignment for the type if the type's size is not constant, or
6498 else return BITS_PER_WORD if the type actually turns out to be an
6501 static inline unsigned
6502 simple_type_size_in_bits (type)
6505 if (TREE_CODE (type) == ERROR_MARK)
6506 return BITS_PER_WORD;
6509 register tree type_size_tree = TYPE_SIZE (type);
6511 if (TREE_CODE (type_size_tree) != INTEGER_CST)
6512 return TYPE_ALIGN (type);
6514 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
6518 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6519 return the byte offset of the lowest addressed byte of the "containing
6520 object" for the given FIELD_DECL, or return 0 if we are unable to
6521 determine what that offset is, either because the argument turns out to
6522 be a pointer to an ERROR_MARK node, or because the offset is actually
6523 variable. (We can't handle the latter case just yet). */
6526 field_byte_offset (decl)
6529 register unsigned type_align_in_bytes;
6530 register unsigned type_align_in_bits;
6531 register unsigned type_size_in_bits;
6532 register unsigned object_offset_in_align_units;
6533 register unsigned object_offset_in_bits;
6534 register unsigned object_offset_in_bytes;
6536 register tree bitpos_tree;
6537 register tree field_size_tree;
6538 register unsigned bitpos_int;
6539 register unsigned deepest_bitpos;
6540 register unsigned field_size_in_bits;
6542 if (TREE_CODE (decl) == ERROR_MARK)
6545 if (TREE_CODE (decl) != FIELD_DECL)
6548 type = field_type (decl);
6550 bitpos_tree = DECL_FIELD_BITPOS (decl);
6551 field_size_tree = DECL_SIZE (decl);
6553 /* If there was an error, the size could be zero. */
6554 if (! field_size_tree)
6561 /* We cannot yet cope with fields whose positions are variable, so
6562 for now, when we see such things, we simply return 0. Someday, we may
6563 be able to handle such cases, but it will be damn difficult. */
6564 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6567 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6569 /* If we don't know the size of the field, pretend it's a full word. */
6570 if (TREE_CODE (field_size_tree) == INTEGER_CST)
6571 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
6573 field_size_in_bits = BITS_PER_WORD;
6575 type_size_in_bits = simple_type_size_in_bits (type);
6576 type_align_in_bits = simple_type_align_in_bits (type);
6577 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6579 /* Note that the GCC front-end doesn't make any attempt to keep track of
6580 the starting bit offset (relative to the start of the containing
6581 structure type) of the hypothetical "containing object" for a bit-
6582 field. Thus, when computing the byte offset value for the start of the
6583 "containing object" of a bit-field, we must deduce this information on
6584 our own. This can be rather tricky to do in some cases. For example,
6585 handling the following structure type definition when compiling for an
6586 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6589 struct S { int field1; long long field2:31; };
6591 Fortunately, there is a simple rule-of-thumb which can be
6592 used in such cases. When compiling for an i386/i486, GCC will allocate
6593 8 bytes for the structure shown above. It decides to do this based upon
6594 one simple rule for bit-field allocation. Quite simply, GCC allocates
6595 each "containing object" for each bit-field at the first (i.e. lowest
6596 addressed) legitimate alignment boundary (based upon the required
6597 minimum alignment for the declared type of the field) which it can
6598 possibly use, subject to the condition that there is still enough
6599 available space remaining in the containing object (when allocated at
6600 the selected point) to fully accommodate all of the bits of the
6601 bit-field itself. This simple rule makes it obvious why GCC allocates
6602 8 bytes for each object of the structure type shown above. When looking
6603 for a place to allocate the "containing object" for `field2', the
6604 compiler simply tries to allocate a 64-bit "containing object" at each
6605 successive 32-bit boundary (starting at zero) until it finds a place to
6606 allocate that 64- bit field such that at least 31 contiguous (and
6607 previously unallocated) bits remain within that selected 64 bit field.
6608 (As it turns out, for the example above, the compiler finds that it is
6609 OK to allocate the "containing object" 64-bit field at bit-offset zero
6610 within the structure type.) Here we attempt to work backwards from the
6611 limited set of facts we're given, and we try to deduce from those facts,
6612 where GCC must have believed that the containing object started (within
6613 the structure type). The value we deduce is then used (by the callers of
6614 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6615 for fields (both bit-fields and, in the case of DW_AT_location, regular
6618 /* Figure out the bit-distance from the start of the structure to the
6619 "deepest" bit of the bit-field. */
6620 deepest_bitpos = bitpos_int + field_size_in_bits;
6622 /* This is the tricky part. Use some fancy footwork to deduce where the
6623 lowest addressed bit of the containing object must be. */
6624 object_offset_in_bits
6625 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6627 /* Compute the offset of the containing object in "alignment units". */
6628 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6630 /* Compute the offset of the containing object in bytes. */
6631 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6633 return object_offset_in_bytes;
6636 /* The following routines define various Dwarf attributes and any data
6637 associated with them. */
6639 /* Add a location description attribute value to a DIE.
6641 This emits location attributes suitable for whole variables and
6642 whole parameters. Note that the location attributes for struct fields are
6643 generated by the routine `data_member_location_attribute' below. */
6646 add_AT_location_description (die, attr_kind, rtl)
6648 enum dwarf_attribute attr_kind;
6651 /* Handle a special case. If we are about to output a location descriptor
6652 for a variable or parameter which has been optimized out of existence,
6653 don't do that. A variable which has been optimized out
6654 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6655 Currently, in some rare cases, variables can have DECL_RTL values which
6656 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6657 elsewhere in the compiler. We treat such cases as if the variable(s) in
6658 question had been optimized out of existence. */
6660 if (is_pseudo_reg (rtl)
6661 || (GET_CODE (rtl) == MEM
6662 && is_pseudo_reg (XEXP (rtl, 0)))
6663 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
6664 references the internal argument pointer (a pseudo) in a function
6665 where all references to the internal argument pointer were
6666 eliminated via the optimizers. */
6667 || (GET_CODE (rtl) == MEM
6668 && GET_CODE (XEXP (rtl, 0)) == PLUS
6669 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
6670 || (GET_CODE (rtl) == CONCAT
6671 && is_pseudo_reg (XEXP (rtl, 0))
6672 && is_pseudo_reg (XEXP (rtl, 1))))
6675 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
6678 /* Attach the specialized form of location attribute used for data
6679 members of struct and union types. In the special case of a
6680 FIELD_DECL node which represents a bit-field, the "offset" part
6681 of this special location descriptor must indicate the distance
6682 in bytes from the lowest-addressed byte of the containing struct
6683 or union type to the lowest-addressed byte of the "containing
6684 object" for the bit-field. (See the `field_byte_offset' function
6685 above).. For any given bit-field, the "containing object" is a
6686 hypothetical object (of some integral or enum type) within which
6687 the given bit-field lives. The type of this hypothetical
6688 "containing object" is always the same as the declared type of
6689 the individual bit-field itself (for GCC anyway... the DWARF
6690 spec doesn't actually mandate this). Note that it is the size
6691 (in bytes) of the hypothetical "containing object" which will
6692 be given in the DW_AT_byte_size attribute for this bit-field.
6693 (See the `byte_size_attribute' function below.) It is also used
6694 when calculating the value of the DW_AT_bit_offset attribute.
6695 (See the `bit_offset_attribute' function below). */
6698 add_data_member_location_attribute (die, decl)
6699 register dw_die_ref die;
6702 register unsigned long offset;
6703 register dw_loc_descr_ref loc_descr;
6704 register enum dwarf_location_atom op;
6706 if (TREE_CODE (decl) == TREE_VEC)
6707 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
6709 offset = field_byte_offset (decl);
6711 /* The DWARF2 standard says that we should assume that the structure address
6712 is already on the stack, so we can specify a structure field address
6713 by using DW_OP_plus_uconst. */
6715 #ifdef MIPS_DEBUGGING_INFO
6716 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6717 correctly. It works only if we leave the offset on the stack. */
6720 op = DW_OP_plus_uconst;
6723 loc_descr = new_loc_descr (op, offset, 0);
6724 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6727 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6728 does not have a "location" either in memory or in a register. These
6729 things can arise in GNU C when a constant is passed as an actual parameter
6730 to an inlined function. They can also arise in C++ where declared
6731 constants do not necessarily get memory "homes". */
6734 add_const_value_attribute (die, rtl)
6735 register dw_die_ref die;
6738 switch (GET_CODE (rtl))
6741 /* Note that a CONST_INT rtx could represent either an integer or a
6742 floating-point constant. A CONST_INT is used whenever the constant
6743 will fit into a single word. In all such cases, the original mode
6744 of the constant value is wiped out, and the CONST_INT rtx is
6745 assigned VOIDmode. */
6746 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6750 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6751 floating-point constant. A CONST_DOUBLE is used whenever the
6752 constant requires more than one word in order to be adequately
6753 represented. We output CONST_DOUBLEs as blocks. */
6755 register enum machine_mode mode = GET_MODE (rtl);
6757 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6759 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6763 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6767 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6771 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6776 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6783 add_AT_float (die, DW_AT_const_value, length, array);
6786 add_AT_long_long (die, DW_AT_const_value,
6787 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6792 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6798 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
6802 /* In cases where an inlined instance of an inline function is passed
6803 the address of an `auto' variable (which is local to the caller) we
6804 can get a situation where the DECL_RTL of the artificial local
6805 variable (for the inlining) which acts as a stand-in for the
6806 corresponding formal parameter (of the inline function) will look
6807 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6808 exactly a compile-time constant expression, but it isn't the address
6809 of the (artificial) local variable either. Rather, it represents the
6810 *value* which the artificial local variable always has during its
6811 lifetime. We currently have no way to represent such quasi-constant
6812 values in Dwarf, so for now we just punt and generate nothing. */
6816 /* No other kinds of rtx should be possible here. */
6822 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6823 data attribute for a variable or a parameter. We generate the
6824 DW_AT_const_value attribute only in those cases where the given variable
6825 or parameter does not have a true "location" either in memory or in a
6826 register. This can happen (for example) when a constant is passed as an
6827 actual argument in a call to an inline function. (It's possible that
6828 these things can crop up in other ways also.) Note that one type of
6829 constant value which can be passed into an inlined function is a constant
6830 pointer. This can happen for example if an actual argument in an inlined
6831 function call evaluates to a compile-time constant address. */
6834 add_location_or_const_value_attribute (die, decl)
6835 register dw_die_ref die;
6839 register tree declared_type;
6840 register tree passed_type;
6842 if (TREE_CODE (decl) == ERROR_MARK)
6845 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6848 /* Here we have to decide where we are going to say the parameter "lives"
6849 (as far as the debugger is concerned). We only have a couple of
6850 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6852 DECL_RTL normally indicates where the parameter lives during most of the
6853 activation of the function. If optimization is enabled however, this
6854 could be either NULL or else a pseudo-reg. Both of those cases indicate
6855 that the parameter doesn't really live anywhere (as far as the code
6856 generation parts of GCC are concerned) during most of the function's
6857 activation. That will happen (for example) if the parameter is never
6858 referenced within the function.
6860 We could just generate a location descriptor here for all non-NULL
6861 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6862 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6863 where DECL_RTL is NULL or is a pseudo-reg.
6865 Note however that we can only get away with using DECL_INCOMING_RTL as
6866 a backup substitute for DECL_RTL in certain limited cases. In cases
6867 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6868 we can be sure that the parameter was passed using the same type as it is
6869 declared to have within the function, and that its DECL_INCOMING_RTL
6870 points us to a place where a value of that type is passed.
6872 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6873 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6874 because in these cases DECL_INCOMING_RTL points us to a value of some
6875 type which is *different* from the type of the parameter itself. Thus,
6876 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6877 such cases, the debugger would end up (for example) trying to fetch a
6878 `float' from a place which actually contains the first part of a
6879 `double'. That would lead to really incorrect and confusing
6880 output at debug-time.
6882 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6883 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6884 are a couple of exceptions however. On little-endian machines we can
6885 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6886 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6887 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6888 when (on a little-endian machine) a non-prototyped function has a
6889 parameter declared to be of type `short' or `char'. In such cases,
6890 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6891 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6892 passed `int' value. If the debugger then uses that address to fetch
6893 a `short' or a `char' (on a little-endian machine) the result will be
6894 the correct data, so we allow for such exceptional cases below.
6896 Note that our goal here is to describe the place where the given formal
6897 parameter lives during most of the function's activation (i.e. between
6898 the end of the prologue and the start of the epilogue). We'll do that
6899 as best as we can. Note however that if the given formal parameter is
6900 modified sometime during the execution of the function, then a stack
6901 backtrace (at debug-time) will show the function as having been
6902 called with the *new* value rather than the value which was
6903 originally passed in. This happens rarely enough that it is not
6904 a major problem, but it *is* a problem, and I'd like to fix it.
6906 A future version of dwarf2out.c may generate two additional
6907 attributes for any given DW_TAG_formal_parameter DIE which will
6908 describe the "passed type" and the "passed location" for the
6909 given formal parameter in addition to the attributes we now
6910 generate to indicate the "declared type" and the "active
6911 location" for each parameter. This additional set of attributes
6912 could be used by debuggers for stack backtraces. Separately, note
6913 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6914 NULL also. This happens (for example) for inlined-instances of
6915 inline function formal parameters which are never referenced.
6916 This really shouldn't be happening. All PARM_DECL nodes should
6917 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6918 doesn't currently generate these values for inlined instances of
6919 inline function parameters, so when we see such cases, we are
6920 just out-of-luck for the time being (until integrate.c
6923 /* Use DECL_RTL as the "location" unless we find something better. */
6924 rtl = DECL_RTL (decl);
6926 if (TREE_CODE (decl) == PARM_DECL)
6928 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
6930 declared_type = type_main_variant (TREE_TYPE (decl));
6931 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
6933 /* This decl represents a formal parameter which was optimized out.
6934 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
6935 all* cases where (rtl == NULL_RTX) just below. */
6936 if (declared_type == passed_type)
6937 rtl = DECL_INCOMING_RTL (decl);
6938 else if (! BYTES_BIG_ENDIAN
6939 && TREE_CODE (declared_type) == INTEGER_TYPE
6940 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
6941 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
6942 rtl = DECL_INCOMING_RTL (decl);
6945 /* If the parm was passed in registers, but lives on the stack, then
6946 make a big endian correction if the mode of the type of the
6947 parameter is not the same as the mode of the rtl. */
6948 /* ??? This is the same series of checks that are made in dbxout.c before
6949 we reach the big endian correction code there. It isn't clear if all
6950 of these checks are necessary here, but keeping them all is the safe
6952 else if (GET_CODE (rtl) == MEM
6953 && XEXP (rtl, 0) != const0_rtx
6954 && ! CONSTANT_P (XEXP (rtl, 0))
6955 /* Not passed in memory. */
6956 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
6957 /* Not passed by invisible reference. */
6958 && (GET_CODE (XEXP (rtl, 0)) != REG
6959 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
6960 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
6961 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
6962 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
6965 /* Big endian correction check. */
6967 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
6968 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
6971 int offset = (UNITS_PER_WORD
6972 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
6973 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
6974 plus_constant (XEXP (rtl, 0), offset));
6978 if (rtl == NULL_RTX)
6981 rtl = eliminate_regs (rtl, 0, NULL_RTX);
6982 #ifdef LEAF_REG_REMAP
6983 if (current_function_uses_only_leaf_regs)
6984 leaf_renumber_regs_insn (rtl);
6987 switch (GET_CODE (rtl))
6990 /* The address of a variable that was optimized away; don't emit
7001 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7002 add_const_value_attribute (die, rtl);
7009 add_AT_location_description (die, DW_AT_location, rtl);
7017 /* Generate an DW_AT_name attribute given some string value to be included as
7018 the value of the attribute. */
7021 add_name_attribute (die, name_string)
7022 register dw_die_ref die;
7023 register const char *name_string;
7025 if (name_string != NULL && *name_string != 0)
7027 if (demangle_name_func)
7028 name_string = (*demangle_name_func) (name_string);
7030 add_AT_string (die, DW_AT_name, name_string);
7034 /* Given a tree node describing an array bound (either lower or upper) output
7035 a representation for that bound. */
7038 add_bound_info (subrange_die, bound_attr, bound)
7039 register dw_die_ref subrange_die;
7040 register enum dwarf_attribute bound_attr;
7041 register tree bound;
7043 register unsigned bound_value = 0;
7045 /* If this is an Ada unconstrained array type, then don't emit any debug
7046 info because the array bounds are unknown. They are parameterized when
7047 the type is instantiated. */
7048 if (contains_placeholder_p (bound))
7051 switch (TREE_CODE (bound))
7056 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7058 bound_value = TREE_INT_CST_LOW (bound);
7059 if (bound_attr == DW_AT_lower_bound
7060 && ((is_c_family () && bound_value == 0)
7061 || (is_fortran () && bound_value == 1)))
7062 /* use the default */;
7064 add_AT_unsigned (subrange_die, bound_attr, bound_value);
7069 case NON_LVALUE_EXPR:
7070 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7074 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7075 access the upper bound values may be bogus. If they refer to a
7076 register, they may only describe how to get at these values at the
7077 points in the generated code right after they have just been
7078 computed. Worse yet, in the typical case, the upper bound values
7079 will not even *be* computed in the optimized code (though the
7080 number of elements will), so these SAVE_EXPRs are entirely
7081 bogus. In order to compensate for this fact, we check here to see
7082 if optimization is enabled, and if so, we don't add an attribute
7083 for the (unknown and unknowable) upper bound. This should not
7084 cause too much trouble for existing (stupid?) debuggers because
7085 they have to deal with empty upper bounds location descriptions
7086 anyway in order to be able to deal with incomplete array types.
7087 Of course an intelligent debugger (GDB?) should be able to
7088 comprehend that a missing upper bound specification in a array
7089 type used for a storage class `auto' local array variable
7090 indicates that the upper bound is both unknown (at compile- time)
7091 and unknowable (at run-time) due to optimization.
7093 We assume that a MEM rtx is safe because gcc wouldn't put the
7094 value there unless it was going to be used repeatedly in the
7095 function, i.e. for cleanups. */
7096 if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)
7098 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7099 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7100 register rtx loc = SAVE_EXPR_RTL (bound);
7102 /* If the RTL for the SAVE_EXPR is memory, handle the case where
7103 it references an outer function's frame. */
7105 if (GET_CODE (loc) == MEM)
7107 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
7109 if (XEXP (loc, 0) != new_addr)
7110 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
7113 add_AT_flag (decl_die, DW_AT_artificial, 1);
7114 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
7115 add_AT_location_description (decl_die, DW_AT_location, loc);
7116 add_AT_die_ref (subrange_die, bound_attr, decl_die);
7119 /* Else leave out the attribute. */
7125 /* ??? These types of bounds can be created by the Ada front end,
7126 and it isn't clear how to emit debug info for them. */
7134 /* Note that the block of subscript information for an array type also
7135 includes information about the element type of type given array type. */
7138 add_subscript_info (type_die, type)
7139 register dw_die_ref type_die;
7142 #ifndef MIPS_DEBUGGING_INFO
7143 register unsigned dimension_number;
7145 register tree lower, upper;
7146 register dw_die_ref subrange_die;
7148 /* The GNU compilers represent multidimensional array types as sequences of
7149 one dimensional array types whose element types are themselves array
7150 types. Here we squish that down, so that each multidimensional array
7151 type gets only one array_type DIE in the Dwarf debugging info. The draft
7152 Dwarf specification say that we are allowed to do this kind of
7153 compression in C (because there is no difference between an array or
7154 arrays and a multidimensional array in C) but for other source languages
7155 (e.g. Ada) we probably shouldn't do this. */
7157 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7158 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7159 We work around this by disabling this feature. See also
7160 gen_array_type_die. */
7161 #ifndef MIPS_DEBUGGING_INFO
7162 for (dimension_number = 0;
7163 TREE_CODE (type) == ARRAY_TYPE;
7164 type = TREE_TYPE (type), dimension_number++)
7167 register tree domain = TYPE_DOMAIN (type);
7169 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7170 and (in GNU C only) variable bounds. Handle all three forms
7172 subrange_die = new_die (DW_TAG_subrange_type, type_die);
7175 /* We have an array type with specified bounds. */
7176 lower = TYPE_MIN_VALUE (domain);
7177 upper = TYPE_MAX_VALUE (domain);
7179 /* define the index type. */
7180 if (TREE_TYPE (domain))
7182 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7183 TREE_TYPE field. We can't emit debug info for this
7184 because it is an unnamed integral type. */
7185 if (TREE_CODE (domain) == INTEGER_TYPE
7186 && TYPE_NAME (domain) == NULL_TREE
7187 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
7188 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
7191 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
7195 /* ??? If upper is NULL, the array has unspecified length,
7196 but it does have a lower bound. This happens with Fortran
7198 Since the debugger is definitely going to need to know N
7199 to produce useful results, go ahead and output the lower
7200 bound solo, and hope the debugger can cope. */
7202 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
7204 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
7207 /* We have an array type with an unspecified length. The DWARF-2
7208 spec does not say how to handle this; let's just leave out the
7213 #ifndef MIPS_DEBUGGING_INFO
7219 add_byte_size_attribute (die, tree_node)
7221 register tree tree_node;
7223 register unsigned size;
7225 switch (TREE_CODE (tree_node))
7233 case QUAL_UNION_TYPE:
7234 size = int_size_in_bytes (tree_node);
7237 /* For a data member of a struct or union, the DW_AT_byte_size is
7238 generally given as the number of bytes normally allocated for an
7239 object of the *declared* type of the member itself. This is true
7240 even for bit-fields. */
7241 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
7247 /* Note that `size' might be -1 when we get to this point. If it is, that
7248 indicates that the byte size of the entity in question is variable. We
7249 have no good way of expressing this fact in Dwarf at the present time,
7250 so just let the -1 pass on through. */
7252 add_AT_unsigned (die, DW_AT_byte_size, size);
7255 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7256 which specifies the distance in bits from the highest order bit of the
7257 "containing object" for the bit-field to the highest order bit of the
7260 For any given bit-field, the "containing object" is a hypothetical
7261 object (of some integral or enum type) within which the given bit-field
7262 lives. The type of this hypothetical "containing object" is always the
7263 same as the declared type of the individual bit-field itself. The
7264 determination of the exact location of the "containing object" for a
7265 bit-field is rather complicated. It's handled by the
7266 `field_byte_offset' function (above).
7268 Note that it is the size (in bytes) of the hypothetical "containing object"
7269 which will be given in the DW_AT_byte_size attribute for this bit-field.
7270 (See `byte_size_attribute' above). */
7273 add_bit_offset_attribute (die, decl)
7274 register dw_die_ref die;
7277 register unsigned object_offset_in_bytes = field_byte_offset (decl);
7278 register tree type = DECL_BIT_FIELD_TYPE (decl);
7279 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
7280 register unsigned bitpos_int;
7281 register unsigned highest_order_object_bit_offset;
7282 register unsigned highest_order_field_bit_offset;
7283 register unsigned bit_offset;
7285 /* Must be a field and a bit field. */
7287 || TREE_CODE (decl) != FIELD_DECL)
7290 /* We can't yet handle bit-fields whose offsets are variable, so if we
7291 encounter such things, just return without generating any attribute
7293 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
7296 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
7298 /* Note that the bit offset is always the distance (in bits) from the
7299 highest-order bit of the "containing object" to the highest-order bit of
7300 the bit-field itself. Since the "high-order end" of any object or field
7301 is different on big-endian and little-endian machines, the computation
7302 below must take account of these differences. */
7303 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
7304 highest_order_field_bit_offset = bitpos_int;
7306 if (! BYTES_BIG_ENDIAN)
7308 highest_order_field_bit_offset
7309 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
7311 highest_order_object_bit_offset += simple_type_size_in_bits (type);
7315 = (! BYTES_BIG_ENDIAN
7316 ? highest_order_object_bit_offset - highest_order_field_bit_offset
7317 : highest_order_field_bit_offset - highest_order_object_bit_offset);
7319 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
7322 /* For a FIELD_DECL node which represents a bit field, output an attribute
7323 which specifies the length in bits of the given field. */
7326 add_bit_size_attribute (die, decl)
7327 register dw_die_ref die;
7330 /* Must be a field and a bit field. */
7331 if (TREE_CODE (decl) != FIELD_DECL
7332 || ! DECL_BIT_FIELD_TYPE (decl))
7334 add_AT_unsigned (die, DW_AT_bit_size,
7335 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
7338 /* If the compiled language is ANSI C, then add a 'prototyped'
7339 attribute, if arg types are given for the parameters of a function. */
7342 add_prototyped_attribute (die, func_type)
7343 register dw_die_ref die;
7344 register tree func_type;
7346 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
7347 && TYPE_ARG_TYPES (func_type) != NULL)
7348 add_AT_flag (die, DW_AT_prototyped, 1);
7352 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7353 by looking in either the type declaration or object declaration
7357 add_abstract_origin_attribute (die, origin)
7358 register dw_die_ref die;
7359 register tree origin;
7361 dw_die_ref origin_die = NULL;
7363 if (TREE_CODE (origin) != FUNCTION_DECL)
7365 /* We may have gotten separated from the block for the inlined
7366 function, if we're in an exception handler or some such; make
7367 sure that the abstract function has been written out.
7369 Doing this for nested functions is wrong, however; functions are
7370 distinct units, and our context might not even be inline. */
7371 tree fn = decl_function_context (origin);
7373 gen_abstract_function (fn);
7376 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
7377 origin_die = lookup_decl_die (origin);
7378 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
7379 origin_die = lookup_type_die (origin);
7381 if (origin_die == NULL)
7384 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
7387 /* We do not currently support the pure_virtual attribute. */
7390 add_pure_or_virtual_attribute (die, func_decl)
7391 register dw_die_ref die;
7392 register tree func_decl;
7394 if (DECL_VINDEX (func_decl))
7396 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7397 add_AT_loc (die, DW_AT_vtable_elem_location,
7398 new_loc_descr (DW_OP_constu,
7399 TREE_INT_CST_LOW (DECL_VINDEX (func_decl)),
7402 /* GNU extension: Record what type this method came from originally. */
7403 if (debug_info_level > DINFO_LEVEL_TERSE)
7404 add_AT_die_ref (die, DW_AT_containing_type,
7405 lookup_type_die (DECL_CONTEXT (func_decl)));
7409 /* Add source coordinate attributes for the given decl. */
7412 add_src_coords_attributes (die, decl)
7413 register dw_die_ref die;
7416 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
7418 add_AT_unsigned (die, DW_AT_decl_file, file_index);
7419 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7422 /* Add an DW_AT_name attribute and source coordinate attribute for the
7423 given decl, but only if it actually has a name. */
7426 add_name_and_src_coords_attributes (die, decl)
7427 register dw_die_ref die;
7430 register tree decl_name;
7432 decl_name = DECL_NAME (decl);
7433 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
7435 add_name_attribute (die, dwarf2_name (decl, 0));
7436 if (! DECL_ARTIFICIAL (decl))
7437 add_src_coords_attributes (die, decl);
7439 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
7440 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
7441 add_AT_string (die, DW_AT_MIPS_linkage_name,
7442 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
7446 /* Push a new declaration scope. */
7449 push_decl_scope (scope)
7452 /* Make room in the decl_scope_table, if necessary. */
7453 if (decl_scope_table_allocated == decl_scope_depth)
7455 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
7457 = (tree *) xrealloc (decl_scope_table,
7458 decl_scope_table_allocated * sizeof (tree));
7461 decl_scope_table[decl_scope_depth] = scope;
7465 /* Pop a declaration scope. */
7469 if (decl_scope_depth <= 0)
7474 /* Return the DIE for the scope that immediately contains this type.
7475 Non-named types get global scope. Named types nested in other
7476 types get their containing scope if it's open, or global scope
7477 otherwise. All other types (i.e. function-local named types) get
7478 the current active scope. */
7481 scope_die_for (t, context_die)
7483 register dw_die_ref context_die;
7485 register dw_die_ref scope_die = NULL;
7486 register tree containing_scope;
7489 /* Non-types always go in the current scope. */
7493 containing_scope = TYPE_CONTEXT (t);
7495 /* Ignore namespaces for the moment. */
7496 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
7497 containing_scope = NULL_TREE;
7499 /* Ignore function type "scopes" from the C frontend. They mean that
7500 a tagged type is local to a parmlist of a function declarator, but
7501 that isn't useful to DWARF. */
7502 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
7503 containing_scope = NULL_TREE;
7505 if (containing_scope == NULL_TREE)
7506 scope_die = comp_unit_die;
7507 else if (TYPE_P (containing_scope))
7509 /* For types, we can just look up the appropriate DIE. But
7510 first we check to see if we're in the middle of emitting it
7511 so we know where the new DIE should go. */
7513 for (i = decl_scope_depth - 1; i >= 0; --i)
7514 if (decl_scope_table[i] == containing_scope)
7519 if (debug_info_level > DINFO_LEVEL_TERSE
7520 && !TREE_ASM_WRITTEN (containing_scope))
7523 /* If none of the current dies are suitable, we get file scope. */
7524 scope_die = comp_unit_die;
7527 scope_die = lookup_type_die (containing_scope);
7530 scope_die = context_die;
7535 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
7537 static inline int local_scope_p PARAMS ((dw_die_ref));
7539 local_scope_p (context_die)
7540 dw_die_ref context_die;
7542 for (; context_die; context_die = context_die->die_parent)
7543 if (context_die->die_tag == DW_TAG_inlined_subroutine
7544 || context_die->die_tag == DW_TAG_subprogram)
7549 /* Returns nonzero iff CONTEXT_DIE is a class. */
7551 static inline int class_scope_p PARAMS ((dw_die_ref));
7553 class_scope_p (context_die)
7554 dw_die_ref context_die;
7557 && (context_die->die_tag == DW_TAG_structure_type
7558 || context_die->die_tag == DW_TAG_union_type));
7561 /* Many forms of DIEs require a "type description" attribute. This
7562 routine locates the proper "type descriptor" die for the type given
7563 by 'type', and adds an DW_AT_type attribute below the given die. */
7566 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
7567 register dw_die_ref object_die;
7569 register int decl_const;
7570 register int decl_volatile;
7571 register dw_die_ref context_die;
7573 register enum tree_code code = TREE_CODE (type);
7574 register dw_die_ref type_die = NULL;
7576 /* ??? If this type is an unnamed subrange type of an integral or
7577 floating-point type, use the inner type. This is because we have no
7578 support for unnamed types in base_type_die. This can happen if this is
7579 an Ada subrange type. Correct solution is emit a subrange type die. */
7580 if ((code == INTEGER_TYPE || code == REAL_TYPE)
7581 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
7582 type = TREE_TYPE (type), code = TREE_CODE (type);
7584 if (code == ERROR_MARK)
7587 /* Handle a special case. For functions whose return type is void, we
7588 generate *no* type attribute. (Note that no object may have type
7589 `void', so this only applies to function return types). */
7590 if (code == VOID_TYPE)
7593 type_die = modified_type_die (type,
7594 decl_const || TYPE_READONLY (type),
7595 decl_volatile || TYPE_VOLATILE (type),
7597 if (type_die != NULL)
7598 add_AT_die_ref (object_die, DW_AT_type, type_die);
7601 /* Given a tree pointer to a struct, class, union, or enum type node, return
7602 a pointer to the (string) tag name for the given type, or zero if the type
7603 was declared without a tag. */
7609 register char *name = 0;
7611 if (TYPE_NAME (type) != 0)
7613 register tree t = 0;
7615 /* Find the IDENTIFIER_NODE for the type name. */
7616 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7617 t = TYPE_NAME (type);
7619 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7620 a TYPE_DECL node, regardless of whether or not a `typedef' was
7622 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7623 && ! DECL_IGNORED_P (TYPE_NAME (type)))
7624 t = DECL_NAME (TYPE_NAME (type));
7626 /* Now get the name as a string, or invent one. */
7628 name = IDENTIFIER_POINTER (t);
7631 return (name == 0 || *name == '\0') ? 0 : name;
7634 /* Return the type associated with a data member, make a special check
7635 for bit field types. */
7638 member_declared_type (member)
7639 register tree member;
7641 return (DECL_BIT_FIELD_TYPE (member)
7642 ? DECL_BIT_FIELD_TYPE (member)
7643 : TREE_TYPE (member));
7646 /* Get the decl's label, as described by its RTL. This may be different
7647 from the DECL_NAME name used in the source file. */
7651 decl_start_label (decl)
7656 x = DECL_RTL (decl);
7657 if (GET_CODE (x) != MEM)
7661 if (GET_CODE (x) != SYMBOL_REF)
7664 fnname = XSTR (x, 0);
7669 /* These routines generate the internal representation of the DIE's for
7670 the compilation unit. Debugging information is collected by walking
7671 the declaration trees passed in from dwarf2out_decl(). */
7674 gen_array_type_die (type, context_die)
7676 register dw_die_ref context_die;
7678 register dw_die_ref scope_die = scope_die_for (type, context_die);
7679 register dw_die_ref array_die;
7680 register tree element_type;
7682 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7683 the inner array type comes before the outer array type. Thus we must
7684 call gen_type_die before we call new_die. See below also. */
7685 #ifdef MIPS_DEBUGGING_INFO
7686 gen_type_die (TREE_TYPE (type), context_die);
7689 array_die = new_die (DW_TAG_array_type, scope_die);
7692 /* We default the array ordering. SDB will probably do
7693 the right things even if DW_AT_ordering is not present. It's not even
7694 an issue until we start to get into multidimensional arrays anyway. If
7695 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7696 then we'll have to put the DW_AT_ordering attribute back in. (But if
7697 and when we find out that we need to put these in, we will only do so
7698 for multidimensional arrays. */
7699 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
7702 #ifdef MIPS_DEBUGGING_INFO
7703 /* The SGI compilers handle arrays of unknown bound by setting
7704 AT_declaration and not emitting any subrange DIEs. */
7705 if (! TYPE_DOMAIN (type))
7706 add_AT_unsigned (array_die, DW_AT_declaration, 1);
7709 add_subscript_info (array_die, type);
7711 add_name_attribute (array_die, type_tag (type));
7712 equate_type_number_to_die (type, array_die);
7714 /* Add representation of the type of the elements of this array type. */
7715 element_type = TREE_TYPE (type);
7717 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7718 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7719 We work around this by disabling this feature. See also
7720 add_subscript_info. */
7721 #ifndef MIPS_DEBUGGING_INFO
7722 while (TREE_CODE (element_type) == ARRAY_TYPE)
7723 element_type = TREE_TYPE (element_type);
7725 gen_type_die (element_type, context_die);
7728 add_type_attribute (array_die, element_type, 0, 0, context_die);
7732 gen_set_type_die (type, context_die)
7734 register dw_die_ref context_die;
7736 register dw_die_ref type_die
7737 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7739 equate_type_number_to_die (type, type_die);
7740 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7745 gen_entry_point_die (decl, context_die)
7747 register dw_die_ref context_die;
7749 register tree origin = decl_ultimate_origin (decl);
7750 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
7752 add_abstract_origin_attribute (decl_die, origin);
7755 add_name_and_src_coords_attributes (decl_die, decl);
7756 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
7760 if (DECL_ABSTRACT (decl))
7761 equate_decl_number_to_die (decl, decl_die);
7763 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
7767 /* Remember a type in the incomplete_types_list. */
7770 add_incomplete_type (type)
7773 if (incomplete_types == incomplete_types_allocated)
7775 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
7776 incomplete_types_list
7777 = (tree *) xrealloc (incomplete_types_list,
7778 sizeof (tree) * incomplete_types_allocated);
7781 incomplete_types_list[incomplete_types++] = type;
7784 /* Walk through the list of incomplete types again, trying once more to
7785 emit full debugging info for them. */
7788 retry_incomplete_types ()
7792 while (incomplete_types)
7795 type = incomplete_types_list[incomplete_types];
7796 gen_type_die (type, comp_unit_die);
7800 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7803 gen_inlined_enumeration_type_die (type, context_die)
7805 register dw_die_ref context_die;
7807 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
7809 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7810 be incomplete and such types are not marked. */
7811 add_abstract_origin_attribute (type_die, type);
7814 /* Generate a DIE to represent an inlined instance of a structure type. */
7817 gen_inlined_structure_type_die (type, context_die)
7819 register dw_die_ref context_die;
7821 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
7823 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7824 be incomplete and such types are not marked. */
7825 add_abstract_origin_attribute (type_die, type);
7828 /* Generate a DIE to represent an inlined instance of a union type. */
7831 gen_inlined_union_type_die (type, context_die)
7833 register dw_die_ref context_die;
7835 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
7837 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7838 be incomplete and such types are not marked. */
7839 add_abstract_origin_attribute (type_die, type);
7842 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7843 include all of the information about the enumeration values also. Each
7844 enumerated type name/value is listed as a child of the enumerated type
7848 gen_enumeration_type_die (type, context_die)
7850 register dw_die_ref context_die;
7852 register dw_die_ref type_die = lookup_type_die (type);
7854 if (type_die == NULL)
7856 type_die = new_die (DW_TAG_enumeration_type,
7857 scope_die_for (type, context_die));
7858 equate_type_number_to_die (type, type_die);
7859 add_name_attribute (type_die, type_tag (type));
7861 else if (! TYPE_SIZE (type))
7864 remove_AT (type_die, DW_AT_declaration);
7866 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7867 given enum type is incomplete, do not generate the DW_AT_byte_size
7868 attribute or the DW_AT_element_list attribute. */
7869 if (TYPE_SIZE (type))
7873 TREE_ASM_WRITTEN (type) = 1;
7874 add_byte_size_attribute (type_die, type);
7875 if (TYPE_STUB_DECL (type) != NULL_TREE)
7876 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
7878 /* If the first reference to this type was as the return type of an
7879 inline function, then it may not have a parent. Fix this now. */
7880 if (type_die->die_parent == NULL)
7881 add_child_die (scope_die_for (type, context_die), type_die);
7883 for (link = TYPE_FIELDS (type);
7884 link != NULL; link = TREE_CHAIN (link))
7886 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
7888 add_name_attribute (enum_die,
7889 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
7890 add_AT_unsigned (enum_die, DW_AT_const_value,
7891 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
7895 add_AT_flag (type_die, DW_AT_declaration, 1);
7899 /* Generate a DIE to represent either a real live formal parameter decl or to
7900 represent just the type of some formal parameter position in some function
7903 Note that this routine is a bit unusual because its argument may be a
7904 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7905 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7906 node. If it's the former then this function is being called to output a
7907 DIE to represent a formal parameter object (or some inlining thereof). If
7908 it's the latter, then this function is only being called to output a
7909 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7910 argument type of some subprogram type. */
7913 gen_formal_parameter_die (node, context_die)
7915 register dw_die_ref context_die;
7917 register dw_die_ref parm_die
7918 = new_die (DW_TAG_formal_parameter, context_die);
7919 register tree origin;
7921 switch (TREE_CODE_CLASS (TREE_CODE (node)))
7924 origin = decl_ultimate_origin (node);
7926 add_abstract_origin_attribute (parm_die, origin);
7929 add_name_and_src_coords_attributes (parm_die, node);
7930 add_type_attribute (parm_die, TREE_TYPE (node),
7931 TREE_READONLY (node),
7932 TREE_THIS_VOLATILE (node),
7934 if (DECL_ARTIFICIAL (node))
7935 add_AT_flag (parm_die, DW_AT_artificial, 1);
7938 equate_decl_number_to_die (node, parm_die);
7939 if (! DECL_ABSTRACT (node))
7940 add_location_or_const_value_attribute (parm_die, node);
7945 /* We were called with some kind of a ..._TYPE node. */
7946 add_type_attribute (parm_die, node, 0, 0, context_die);
7956 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
7957 at the end of an (ANSI prototyped) formal parameters list. */
7960 gen_unspecified_parameters_die (decl_or_type, context_die)
7961 register tree decl_or_type ATTRIBUTE_UNUSED;
7962 register dw_die_ref context_die;
7964 new_die (DW_TAG_unspecified_parameters, context_die);
7967 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
7968 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
7969 parameters as specified in some function type specification (except for
7970 those which appear as part of a function *definition*).
7972 Note we must be careful here to output all of the parameter DIEs before*
7973 we output any DIEs needed to represent the types of the formal parameters.
7974 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
7975 non-parameter DIE it sees ends the formal parameter list. */
7978 gen_formal_types_die (function_or_method_type, context_die)
7979 register tree function_or_method_type;
7980 register dw_die_ref context_die;
7983 register tree formal_type = NULL;
7984 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
7987 /* In the case where we are generating a formal types list for a C++
7988 non-static member function type, skip over the first thing on the
7989 TYPE_ARG_TYPES list because it only represents the type of the hidden
7990 `this pointer'. The debugger should be able to figure out (without
7991 being explicitly told) that this non-static member function type takes a
7992 `this pointer' and should be able to figure what the type of that hidden
7993 parameter is from the DW_AT_member attribute of the parent
7994 DW_TAG_subroutine_type DIE. */
7995 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
7996 first_parm_type = TREE_CHAIN (first_parm_type);
7999 /* Make our first pass over the list of formal parameter types and output a
8000 DW_TAG_formal_parameter DIE for each one. */
8001 for (link = first_parm_type; link; link = TREE_CHAIN (link))
8003 register dw_die_ref parm_die;
8005 formal_type = TREE_VALUE (link);
8006 if (formal_type == void_type_node)
8009 /* Output a (nameless) DIE to represent the formal parameter itself. */
8010 parm_die = gen_formal_parameter_die (formal_type, context_die);
8011 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8012 && link == first_parm_type)
8013 add_AT_flag (parm_die, DW_AT_artificial, 1);
8016 /* If this function type has an ellipsis, add a
8017 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8018 if (formal_type != void_type_node)
8019 gen_unspecified_parameters_die (function_or_method_type, context_die);
8021 /* Make our second (and final) pass over the list of formal parameter types
8022 and output DIEs to represent those types (as necessary). */
8023 for (link = TYPE_ARG_TYPES (function_or_method_type);
8025 link = TREE_CHAIN (link))
8027 formal_type = TREE_VALUE (link);
8028 if (formal_type == void_type_node)
8031 gen_type_die (formal_type, context_die);
8035 /* We want to generate the DIE for TYPE so that we can generate the
8036 die for MEMBER, which has been defined; we will need to refer back
8037 to the member declaration nested within TYPE. If we're trying to
8038 generate minimal debug info for TYPE, processing TYPE won't do the
8039 trick; we need to attach the member declaration by hand. */
8042 gen_type_die_for_member (type, member, context_die)
8044 dw_die_ref context_die;
8046 gen_type_die (type, context_die);
8048 /* If we're trying to avoid duplicate debug info, we may not have
8049 emitted the member decl for this function. Emit it now. */
8050 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
8051 && ! lookup_decl_die (member))
8053 if (decl_ultimate_origin (member))
8056 push_decl_scope (type);
8057 if (TREE_CODE (member) == FUNCTION_DECL)
8058 gen_subprogram_die (member, lookup_type_die (type));
8060 gen_variable_die (member, lookup_type_die (type));
8065 /* Generate the DWARF2 info for the "abstract" instance
8066 of a function which we may later generate inlined and/or
8067 out-of-line instances of. */
8070 gen_abstract_function (decl)
8073 register dw_die_ref old_die = lookup_decl_die (decl);
8076 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
8077 /* We've already generated the abstract instance. */
8080 save_fn = current_function_decl;
8081 current_function_decl = decl;
8083 set_decl_abstract_flags (decl, 1);
8084 dwarf2out_decl (decl);
8085 set_decl_abstract_flags (decl, 0);
8087 current_function_decl = save_fn;
8090 /* Generate a DIE to represent a declared function (either file-scope or
8094 gen_subprogram_die (decl, context_die)
8096 register dw_die_ref context_die;
8098 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
8099 register tree origin = decl_ultimate_origin (decl);
8100 register dw_die_ref subr_die;
8101 register rtx fp_reg;
8102 register tree fn_arg_types;
8103 register tree outer_scope;
8104 register dw_die_ref old_die = lookup_decl_die (decl);
8105 register int declaration = (current_function_decl != decl
8106 || class_scope_p (context_die));
8108 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
8109 be true, if we started to generate the abstract instance of an inline,
8110 decided to output its containing class, and proceeded to emit the
8111 declaration of the inline from the member list for the class. In that
8112 case, `declaration' takes priority; we'll get back to the abstract
8113 instance when we're done with the class. */
8117 if (declaration && ! local_scope_p (context_die))
8120 subr_die = new_die (DW_TAG_subprogram, context_die);
8121 add_abstract_origin_attribute (subr_die, origin);
8123 else if (old_die && DECL_ABSTRACT (decl)
8124 && get_AT_unsigned (old_die, DW_AT_inline))
8126 /* This must be a redefinition of an extern inline function.
8127 We can just reuse the old die here. */
8130 /* Clear out the inlined attribute and parm types. */
8131 remove_AT (subr_die, DW_AT_inline);
8132 remove_children (subr_die);
8136 register unsigned file_index
8137 = lookup_filename (DECL_SOURCE_FILE (decl));
8139 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
8141 /* ??? This can happen if there is a bug in the program, for
8142 instance, if it has duplicate function definitions. Ideally,
8143 we should detect this case and ignore it. For now, if we have
8144 already reported an error, any error at all, then assume that
8145 we got here because of a input error, not a dwarf2 bug. */
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 doesn't apply; we just use the old DIE. */
8158 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
8159 || context_die == NULL)
8160 && (DECL_ARTIFICIAL (decl)
8161 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
8162 && (get_AT_unsigned (old_die, DW_AT_decl_line)
8163 == (unsigned)DECL_SOURCE_LINE (decl)))))
8167 /* Clear out the declaration attribute and the parm types. */
8168 remove_AT (subr_die, DW_AT_declaration);
8169 remove_children (subr_die);
8173 subr_die = new_die (DW_TAG_subprogram, context_die);
8174 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
8175 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8176 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
8177 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8178 != (unsigned)DECL_SOURCE_LINE (decl))
8180 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8185 subr_die = new_die (DW_TAG_subprogram, context_die);
8187 if (TREE_PUBLIC (decl))
8188 add_AT_flag (subr_die, DW_AT_external, 1);
8190 add_name_and_src_coords_attributes (subr_die, decl);
8191 if (debug_info_level > DINFO_LEVEL_TERSE)
8193 register tree type = TREE_TYPE (decl);
8195 add_prototyped_attribute (subr_die, type);
8196 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
8199 add_pure_or_virtual_attribute (subr_die, decl);
8200 if (DECL_ARTIFICIAL (decl))
8201 add_AT_flag (subr_die, DW_AT_artificial, 1);
8202 if (TREE_PROTECTED (decl))
8203 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
8204 else if (TREE_PRIVATE (decl))
8205 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
8211 add_AT_flag (subr_die, DW_AT_declaration, 1);
8213 /* The first time we see a member function, it is in the context of
8214 the class to which it belongs. We make sure of this by emitting
8215 the class first. The next time is the definition, which is
8216 handled above. The two may come from the same source text. */
8217 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
8218 equate_decl_number_to_die (decl, subr_die);
8220 else if (DECL_ABSTRACT (decl))
8222 if (DECL_INLINE (decl) && !flag_no_inline)
8224 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
8225 inline functions, but not for extern inline functions.
8226 We can't get this completely correct because information
8227 about whether the function was declared inline is not
8229 if (DECL_DEFER_OUTPUT (decl))
8230 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
8232 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
8235 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
8237 equate_decl_number_to_die (decl, subr_die);
8239 else if (!DECL_EXTERNAL (decl))
8241 if (origin == NULL_TREE)
8242 equate_decl_number_to_die (decl, subr_die);
8244 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
8245 current_funcdef_number);
8246 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
8247 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
8248 current_funcdef_number);
8249 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
8251 add_pubname (decl, subr_die);
8252 add_arange (decl, subr_die);
8254 #ifdef MIPS_DEBUGGING_INFO
8255 /* Add a reference to the FDE for this routine. */
8256 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
8259 /* Define the "frame base" location for this routine. We use the
8260 frame pointer or stack pointer registers, since the RTL for local
8261 variables is relative to one of them. */
8263 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
8264 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
8267 /* ??? This fails for nested inline functions, because context_display
8268 is not part of the state saved/restored for inline functions. */
8269 if (current_function_needs_context)
8270 add_AT_location_description (subr_die, DW_AT_static_link,
8271 lookup_static_chain (decl));
8275 /* Now output descriptions of the arguments for this function. This gets
8276 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8277 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8278 `...' at the end of the formal parameter list. In order to find out if
8279 there was a trailing ellipsis or not, we must instead look at the type
8280 associated with the FUNCTION_DECL. This will be a node of type
8281 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8282 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8283 an ellipsis at the end. */
8285 /* In the case where we are describing a mere function declaration, all we
8286 need to do here (and all we *can* do here) is to describe the *types* of
8287 its formal parameters. */
8288 if (debug_info_level <= DINFO_LEVEL_TERSE)
8290 else if (declaration)
8291 gen_formal_types_die (TREE_TYPE (decl), subr_die);
8294 /* Generate DIEs to represent all known formal parameters */
8295 register tree arg_decls = DECL_ARGUMENTS (decl);
8298 /* When generating DIEs, generate the unspecified_parameters DIE
8299 instead if we come across the arg "__builtin_va_alist" */
8300 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
8301 if (TREE_CODE (parm) == PARM_DECL)
8303 if (DECL_NAME (parm)
8304 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
8305 "__builtin_va_alist"))
8306 gen_unspecified_parameters_die (parm, subr_die);
8308 gen_decl_die (parm, subr_die);
8311 /* Decide whether we need a unspecified_parameters DIE at the end.
8312 There are 2 more cases to do this for: 1) the ansi ... declaration -
8313 this is detectable when the end of the arg list is not a
8314 void_type_node 2) an unprototyped function declaration (not a
8315 definition). This just means that we have no info about the
8316 parameters at all. */
8317 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
8318 if (fn_arg_types != NULL)
8320 /* this is the prototyped case, check for ... */
8321 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
8322 gen_unspecified_parameters_die (decl, subr_die);
8324 else if (DECL_INITIAL (decl) == NULL_TREE)
8325 gen_unspecified_parameters_die (decl, subr_die);
8328 /* Output Dwarf info for all of the stuff within the body of the function
8329 (if it has one - it may be just a declaration). */
8330 outer_scope = DECL_INITIAL (decl);
8332 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8333 node created to represent a function. This outermost BLOCK actually
8334 represents the outermost binding contour for the function, i.e. the
8335 contour in which the function's formal parameters and labels get
8336 declared. Curiously, it appears that the front end doesn't actually
8337 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8338 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8339 list for the function instead.) The BLOCK_VARS list for the
8340 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8341 the function however, and we output DWARF info for those in
8342 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8343 node representing the function's outermost pair of curly braces, and
8344 any blocks used for the base and member initializers of a C++
8345 constructor function. */
8346 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
8348 current_function_has_inlines = 0;
8349 decls_for_scope (outer_scope, subr_die, 0);
8351 #if 0 && defined (MIPS_DEBUGGING_INFO)
8352 if (current_function_has_inlines)
8354 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
8355 if (! comp_unit_has_inlines)
8357 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
8358 comp_unit_has_inlines = 1;
8365 /* Generate a DIE to represent a declared data object. */
8368 gen_variable_die (decl, context_die)
8370 register dw_die_ref context_die;
8372 register tree origin = decl_ultimate_origin (decl);
8373 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
8375 dw_die_ref old_die = lookup_decl_die (decl);
8376 int declaration = (DECL_EXTERNAL (decl)
8377 || class_scope_p (context_die));
8380 add_abstract_origin_attribute (var_die, origin);
8381 /* Loop unrolling can create multiple blocks that refer to the same
8382 static variable, so we must test for the DW_AT_declaration flag. */
8383 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8384 copy decls and set the DECL_ABSTRACT flag on them instead of
8386 else if (old_die && TREE_STATIC (decl)
8387 && get_AT_flag (old_die, DW_AT_declaration) == 1)
8389 /* This is a definition of a C++ class level static. */
8390 add_AT_die_ref (var_die, DW_AT_specification, old_die);
8391 if (DECL_NAME (decl))
8393 register unsigned file_index
8394 = lookup_filename (DECL_SOURCE_FILE (decl));
8396 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8397 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
8399 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8400 != (unsigned)DECL_SOURCE_LINE (decl))
8402 add_AT_unsigned (var_die, DW_AT_decl_line,
8403 DECL_SOURCE_LINE (decl));
8408 add_name_and_src_coords_attributes (var_die, decl);
8409 add_type_attribute (var_die, TREE_TYPE (decl),
8410 TREE_READONLY (decl),
8411 TREE_THIS_VOLATILE (decl), context_die);
8413 if (TREE_PUBLIC (decl))
8414 add_AT_flag (var_die, DW_AT_external, 1);
8416 if (DECL_ARTIFICIAL (decl))
8417 add_AT_flag (var_die, DW_AT_artificial, 1);
8419 if (TREE_PROTECTED (decl))
8420 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
8422 else if (TREE_PRIVATE (decl))
8423 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
8427 add_AT_flag (var_die, DW_AT_declaration, 1);
8429 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
8430 equate_decl_number_to_die (decl, var_die);
8432 if (! declaration && ! DECL_ABSTRACT (decl))
8434 add_location_or_const_value_attribute (var_die, decl);
8435 add_pubname (decl, var_die);
8439 /* Generate a DIE to represent a label identifier. */
8442 gen_label_die (decl, context_die)
8444 register dw_die_ref context_die;
8446 register tree origin = decl_ultimate_origin (decl);
8447 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
8449 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8450 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
8453 add_abstract_origin_attribute (lbl_die, origin);
8455 add_name_and_src_coords_attributes (lbl_die, decl);
8457 if (DECL_ABSTRACT (decl))
8458 equate_decl_number_to_die (decl, lbl_die);
8461 insn = DECL_RTL (decl);
8463 /* Deleted labels are programmer specified labels which have been
8464 eliminated because of various optimisations. We still emit them
8465 here so that it is possible to put breakpoints on them. */
8466 if (GET_CODE (insn) == CODE_LABEL
8467 || ((GET_CODE (insn) == NOTE
8468 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
8470 /* When optimization is enabled (via -O) some parts of the compiler
8471 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8472 represent source-level labels which were explicitly declared by
8473 the user. This really shouldn't be happening though, so catch
8474 it if it ever does happen. */
8475 if (INSN_DELETED_P (insn))
8478 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
8479 ASM_GENERATE_INTERNAL_LABEL (label, label2,
8480 (unsigned) INSN_UID (insn));
8481 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
8486 /* Generate a DIE for a lexical block. */
8489 gen_lexical_block_die (stmt, context_die, depth)
8491 register dw_die_ref context_die;
8494 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
8495 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8497 if (! BLOCK_ABSTRACT (stmt))
8499 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8500 BLOCK_NUMBER (stmt));
8501 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
8502 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
8503 BLOCK_NUMBER (stmt));
8504 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
8507 decls_for_scope (stmt, stmt_die, depth);
8510 /* Generate a DIE for an inlined subprogram. */
8513 gen_inlined_subroutine_die (stmt, context_die, depth)
8515 register dw_die_ref context_die;
8518 if (! BLOCK_ABSTRACT (stmt))
8520 register dw_die_ref subr_die
8521 = new_die (DW_TAG_inlined_subroutine, context_die);
8522 register tree decl = block_ultimate_origin (stmt);
8523 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8525 /* Emit info for the abstract instance first, if we haven't yet. */
8526 gen_abstract_function (decl);
8528 add_abstract_origin_attribute (subr_die, decl);
8529 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8530 BLOCK_NUMBER (stmt));
8531 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
8532 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
8533 BLOCK_NUMBER (stmt));
8534 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
8535 decls_for_scope (stmt, subr_die, depth);
8536 current_function_has_inlines = 1;
8540 /* Generate a DIE for a field in a record, or structure. */
8543 gen_field_die (decl, context_die)
8545 register dw_die_ref context_die;
8547 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
8549 add_name_and_src_coords_attributes (decl_die, decl);
8550 add_type_attribute (decl_die, member_declared_type (decl),
8551 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
8554 /* If this is a bit field... */
8555 if (DECL_BIT_FIELD_TYPE (decl))
8557 add_byte_size_attribute (decl_die, decl);
8558 add_bit_size_attribute (decl_die, decl);
8559 add_bit_offset_attribute (decl_die, decl);
8562 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
8563 add_data_member_location_attribute (decl_die, decl);
8565 if (DECL_ARTIFICIAL (decl))
8566 add_AT_flag (decl_die, DW_AT_artificial, 1);
8568 if (TREE_PROTECTED (decl))
8569 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
8571 else if (TREE_PRIVATE (decl))
8572 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
8576 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8577 Use modified_type_die instead.
8578 We keep this code here just in case these types of DIEs may be needed to
8579 represent certain things in other languages (e.g. Pascal) someday. */
8581 gen_pointer_type_die (type, context_die)
8583 register dw_die_ref context_die;
8585 register dw_die_ref ptr_die
8586 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
8588 equate_type_number_to_die (type, ptr_die);
8589 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8590 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8593 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8594 Use modified_type_die instead.
8595 We keep this code here just in case these types of DIEs may be needed to
8596 represent certain things in other languages (e.g. Pascal) someday. */
8598 gen_reference_type_die (type, context_die)
8600 register dw_die_ref context_die;
8602 register dw_die_ref ref_die
8603 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
8605 equate_type_number_to_die (type, ref_die);
8606 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
8607 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8611 /* Generate a DIE for a pointer to a member type. */
8613 gen_ptr_to_mbr_type_die (type, context_die)
8615 register dw_die_ref context_die;
8617 register dw_die_ref ptr_die
8618 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8620 equate_type_number_to_die (type, ptr_die);
8621 add_AT_die_ref (ptr_die, DW_AT_containing_type,
8622 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
8623 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8626 /* Generate the DIE for the compilation unit. */
8629 gen_compile_unit_die (filename)
8630 register const char *filename;
8632 register dw_die_ref die;
8634 char *wd = getpwd ();
8637 die = new_die (DW_TAG_compile_unit, NULL);
8638 add_name_attribute (die, filename);
8640 if (wd != NULL && filename[0] != DIR_SEPARATOR)
8641 add_AT_string (die, DW_AT_comp_dir, wd);
8643 sprintf (producer, "%s %s", language_string, version_string);
8645 #ifdef MIPS_DEBUGGING_INFO
8646 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8647 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8648 not appear in the producer string, the debugger reaches the conclusion
8649 that the object file is stripped and has no debugging information.
8650 To get the MIPS/SGI debugger to believe that there is debugging
8651 information in the object file, we add a -g to the producer string. */
8652 if (debug_info_level > DINFO_LEVEL_TERSE)
8653 strcat (producer, " -g");
8656 add_AT_string (die, DW_AT_producer, producer);
8658 if (strcmp (language_string, "GNU C++") == 0)
8659 language = DW_LANG_C_plus_plus;
8660 else if (strcmp (language_string, "GNU Ada") == 0)
8661 language = DW_LANG_Ada83;
8662 else if (strcmp (language_string, "GNU F77") == 0)
8663 language = DW_LANG_Fortran77;
8664 else if (strcmp (language_string, "GNU Pascal") == 0)
8665 language = DW_LANG_Pascal83;
8666 else if (flag_traditional)
8667 language = DW_LANG_C;
8669 language = DW_LANG_C89;
8671 add_AT_unsigned (die, DW_AT_language, language);
8676 /* Generate a DIE for a string type. */
8679 gen_string_type_die (type, context_die)
8681 register dw_die_ref context_die;
8683 register dw_die_ref type_die
8684 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
8686 equate_type_number_to_die (type, type_die);
8688 /* Fudge the string length attribute for now. */
8690 /* TODO: add string length info.
8691 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8692 bound_representation (upper_bound, 0, 'u'); */
8695 /* Generate the DIE for a base class. */
8698 gen_inheritance_die (binfo, context_die)
8699 register tree binfo;
8700 register dw_die_ref context_die;
8702 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
8704 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
8705 add_data_member_location_attribute (die, binfo);
8707 if (TREE_VIA_VIRTUAL (binfo))
8708 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8709 if (TREE_VIA_PUBLIC (binfo))
8710 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
8711 else if (TREE_VIA_PROTECTED (binfo))
8712 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
8715 /* Generate a DIE for a class member. */
8718 gen_member_die (type, context_die)
8720 register dw_die_ref context_die;
8722 register tree member;
8725 /* If this is not an incomplete type, output descriptions of each of its
8726 members. Note that as we output the DIEs necessary to represent the
8727 members of this record or union type, we will also be trying to output
8728 DIEs to represent the *types* of those members. However the `type'
8729 function (above) will specifically avoid generating type DIEs for member
8730 types *within* the list of member DIEs for this (containing) type execpt
8731 for those types (of members) which are explicitly marked as also being
8732 members of this (containing) type themselves. The g++ front- end can
8733 force any given type to be treated as a member of some other
8734 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8735 to point to the TREE node representing the appropriate (containing)
8738 /* First output info about the base classes. */
8739 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
8741 register tree bases = TYPE_BINFO_BASETYPES (type);
8742 register int n_bases = TREE_VEC_LENGTH (bases);
8745 for (i = 0; i < n_bases; i++)
8746 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
8749 /* Now output info about the data members and type members. */
8750 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
8752 /* If we thought we were generating minimal debug info for TYPE
8753 and then changed our minds, some of the member declarations
8754 may have already been defined. Don't define them again, but
8755 do put them in the right order. */
8757 child = lookup_decl_die (member);
8759 splice_child_die (context_die, child);
8761 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))
8767 child = lookup_decl_die (member);
8769 splice_child_die (context_die, child);
8771 gen_decl_die (member, context_die);
8775 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
8776 is set, we pretend that the type was never defined, so we only get the
8777 member DIEs needed by later specification DIEs. */
8780 gen_struct_or_union_type_die (type, context_die)
8782 register dw_die_ref context_die;
8784 register dw_die_ref type_die = lookup_type_die (type);
8785 register dw_die_ref scope_die = 0;
8786 register int nested = 0;
8787 int complete = (TYPE_SIZE (type)
8788 && (! TYPE_STUB_DECL (type)
8789 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
8791 if (type_die && ! complete)
8794 if (TYPE_CONTEXT (type) != NULL_TREE
8795 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
8798 scope_die = scope_die_for (type, context_die);
8800 if (! type_die || (nested && scope_die == comp_unit_die))
8801 /* First occurrence of type or toplevel definition of nested class. */
8803 register dw_die_ref old_die = type_die;
8805 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
8806 ? DW_TAG_structure_type : DW_TAG_union_type,
8808 equate_type_number_to_die (type, type_die);
8809 add_name_attribute (type_die, type_tag (type));
8811 add_AT_die_ref (type_die, DW_AT_specification, old_die);
8814 remove_AT (type_die, DW_AT_declaration);
8816 /* If this type has been completed, then give it a byte_size attribute and
8817 then give a list of members. */
8820 /* Prevent infinite recursion in cases where the type of some member of
8821 this type is expressed in terms of this type itself. */
8822 TREE_ASM_WRITTEN (type) = 1;
8823 add_byte_size_attribute (type_die, type);
8824 if (TYPE_STUB_DECL (type) != NULL_TREE)
8825 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8827 /* If the first reference to this type was as the return type of an
8828 inline function, then it may not have a parent. Fix this now. */
8829 if (type_die->die_parent == NULL)
8830 add_child_die (scope_die, type_die);
8832 push_decl_scope (type);
8833 gen_member_die (type, type_die);
8836 /* GNU extension: Record what type our vtable lives in. */
8837 if (TYPE_VFIELD (type))
8839 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
8841 gen_type_die (vtype, context_die);
8842 add_AT_die_ref (type_die, DW_AT_containing_type,
8843 lookup_type_die (vtype));
8848 add_AT_flag (type_die, DW_AT_declaration, 1);
8850 /* We don't need to do this for function-local types. */
8851 if (! decl_function_context (TYPE_STUB_DECL (type)))
8852 add_incomplete_type (type);
8856 /* Generate a DIE for a subroutine _type_. */
8859 gen_subroutine_type_die (type, context_die)
8861 register dw_die_ref context_die;
8863 register tree return_type = TREE_TYPE (type);
8864 register dw_die_ref subr_die
8865 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
8867 equate_type_number_to_die (type, subr_die);
8868 add_prototyped_attribute (subr_die, type);
8869 add_type_attribute (subr_die, return_type, 0, 0, context_die);
8870 gen_formal_types_die (type, subr_die);
8873 /* Generate a DIE for a type definition */
8876 gen_typedef_die (decl, context_die)
8878 register dw_die_ref context_die;
8880 register dw_die_ref type_die;
8881 register tree origin;
8883 if (TREE_ASM_WRITTEN (decl))
8885 TREE_ASM_WRITTEN (decl) = 1;
8887 type_die = new_die (DW_TAG_typedef, context_die);
8888 origin = decl_ultimate_origin (decl);
8890 add_abstract_origin_attribute (type_die, origin);
8894 add_name_and_src_coords_attributes (type_die, decl);
8895 if (DECL_ORIGINAL_TYPE (decl))
8897 type = DECL_ORIGINAL_TYPE (decl);
8898 equate_type_number_to_die (TREE_TYPE (decl), type_die);
8901 type = TREE_TYPE (decl);
8902 add_type_attribute (type_die, type, TREE_READONLY (decl),
8903 TREE_THIS_VOLATILE (decl), context_die);
8906 if (DECL_ABSTRACT (decl))
8907 equate_decl_number_to_die (decl, type_die);
8910 /* Generate a type description DIE. */
8913 gen_type_die (type, context_die)
8915 register dw_die_ref context_die;
8919 if (type == NULL_TREE || type == error_mark_node)
8922 /* We are going to output a DIE to represent the unqualified version of
8923 this type (i.e. without any const or volatile qualifiers) so get the
8924 main variant (i.e. the unqualified version) of this type now. */
8925 type = type_main_variant (type);
8927 if (TREE_ASM_WRITTEN (type))
8930 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8931 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
8933 TREE_ASM_WRITTEN (type) = 1;
8934 gen_decl_die (TYPE_NAME (type), context_die);
8938 switch (TREE_CODE (type))
8944 case REFERENCE_TYPE:
8945 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
8946 ensures that the gen_type_die recursion will terminate even if the
8947 type is recursive. Recursive types are possible in Ada. */
8948 /* ??? We could perhaps do this for all types before the switch
8950 TREE_ASM_WRITTEN (type) = 1;
8952 /* For these types, all that is required is that we output a DIE (or a
8953 set of DIEs) to represent the "basis" type. */
8954 gen_type_die (TREE_TYPE (type), context_die);
8958 /* This code is used for C++ pointer-to-data-member types.
8959 Output a description of the relevant class type. */
8960 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
8962 /* Output a description of the type of the object pointed to. */
8963 gen_type_die (TREE_TYPE (type), context_die);
8965 /* Now output a DIE to represent this pointer-to-data-member type
8967 gen_ptr_to_mbr_type_die (type, context_die);
8971 gen_type_die (TYPE_DOMAIN (type), context_die);
8972 gen_set_type_die (type, context_die);
8976 gen_type_die (TREE_TYPE (type), context_die);
8977 abort (); /* No way to represent these in Dwarf yet! */
8981 /* Force out return type (in case it wasn't forced out already). */
8982 gen_type_die (TREE_TYPE (type), context_die);
8983 gen_subroutine_type_die (type, context_die);
8987 /* Force out return type (in case it wasn't forced out already). */
8988 gen_type_die (TREE_TYPE (type), context_die);
8989 gen_subroutine_type_die (type, context_die);
8993 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
8995 gen_type_die (TREE_TYPE (type), context_die);
8996 gen_string_type_die (type, context_die);
8999 gen_array_type_die (type, context_die);
9005 case QUAL_UNION_TYPE:
9006 /* If this is a nested type whose containing class hasn't been
9007 written out yet, writing it out will cover this one, too.
9008 This does not apply to instantiations of member class templates;
9009 they need to be added to the containing class as they are
9010 generated. FIXME: This hurts the idea of combining type decls
9011 from multiple TUs, since we can't predict what set of template
9012 instantiations we'll get. */
9013 if (TYPE_CONTEXT (type)
9014 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9015 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9017 gen_type_die (TYPE_CONTEXT (type), context_die);
9019 if (TREE_ASM_WRITTEN (type))
9022 /* If that failed, attach ourselves to the stub. */
9023 push_decl_scope (TYPE_CONTEXT (type));
9024 context_die = lookup_type_die (TYPE_CONTEXT (type));
9030 if (TREE_CODE (type) == ENUMERAL_TYPE)
9031 gen_enumeration_type_die (type, context_die);
9033 gen_struct_or_union_type_die (type, context_die);
9038 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9039 it up if it is ever completed. gen_*_type_die will set it for us
9040 when appropriate. */
9049 /* No DIEs needed for fundamental types. */
9053 /* No Dwarf representation currently defined. */
9060 TREE_ASM_WRITTEN (type) = 1;
9063 /* Generate a DIE for a tagged type instantiation. */
9066 gen_tagged_type_instantiation_die (type, context_die)
9068 register dw_die_ref context_die;
9070 if (type == NULL_TREE || type == error_mark_node)
9073 /* We are going to output a DIE to represent the unqualified version of
9074 this type (i.e. without any const or volatile qualifiers) so make sure
9075 that we have the main variant (i.e. the unqualified version) of this
9077 if (type != type_main_variant (type))
9080 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
9081 an instance of an unresolved type. */
9083 switch (TREE_CODE (type))
9089 gen_inlined_enumeration_type_die (type, context_die);
9093 gen_inlined_structure_type_die (type, context_die);
9097 case QUAL_UNION_TYPE:
9098 gen_inlined_union_type_die (type, context_die);
9106 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
9107 things which are local to the given block. */
9110 gen_block_die (stmt, context_die, depth)
9112 register dw_die_ref context_die;
9115 register int must_output_die = 0;
9116 register tree origin;
9118 register enum tree_code origin_code;
9120 /* Ignore blocks never really used to make RTL. */
9122 if (stmt == NULL_TREE || !TREE_USED (stmt)
9123 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
9126 /* Determine the "ultimate origin" of this block. This block may be an
9127 inlined instance of an inlined instance of inline function, so we have
9128 to trace all of the way back through the origin chain to find out what
9129 sort of node actually served as the original seed for the creation of
9130 the current block. */
9131 origin = block_ultimate_origin (stmt);
9132 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
9134 /* Determine if we need to output any Dwarf DIEs at all to represent this
9136 if (origin_code == FUNCTION_DECL)
9137 /* The outer scopes for inlinings *must* always be represented. We
9138 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9139 must_output_die = 1;
9142 /* In the case where the current block represents an inlining of the
9143 "body block" of an inline function, we must *NOT* output any DIE for
9144 this block because we have already output a DIE to represent the
9145 whole inlined function scope and the "body block" of any function
9146 doesn't really represent a different scope according to ANSI C
9147 rules. So we check here to make sure that this block does not
9148 represent a "body block inlining" before trying to set the
9149 `must_output_die' flag. */
9150 if (! is_body_block (origin ? origin : stmt))
9152 /* Determine if this block directly contains any "significant"
9153 local declarations which we will need to output DIEs for. */
9154 if (debug_info_level > DINFO_LEVEL_TERSE)
9155 /* We are not in terse mode so *any* local declaration counts
9156 as being a "significant" one. */
9157 must_output_die = (BLOCK_VARS (stmt) != NULL);
9159 /* We are in terse mode, so only local (nested) function
9160 definitions count as "significant" local declarations. */
9161 for (decl = BLOCK_VARS (stmt);
9162 decl != NULL; decl = TREE_CHAIN (decl))
9163 if (TREE_CODE (decl) == FUNCTION_DECL
9164 && DECL_INITIAL (decl))
9166 must_output_die = 1;
9172 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9173 DIE for any block which contains no significant local declarations at
9174 all. Rather, in such cases we just call `decls_for_scope' so that any
9175 needed Dwarf info for any sub-blocks will get properly generated. Note
9176 that in terse mode, our definition of what constitutes a "significant"
9177 local declaration gets restricted to include only inlined function
9178 instances and local (nested) function definitions. */
9179 if (must_output_die)
9181 if (origin_code == FUNCTION_DECL)
9182 gen_inlined_subroutine_die (stmt, context_die, depth);
9184 gen_lexical_block_die (stmt, context_die, depth);
9187 decls_for_scope (stmt, context_die, depth);
9190 /* Generate all of the decls declared within a given scope and (recursively)
9191 all of its sub-blocks. */
9194 decls_for_scope (stmt, context_die, depth)
9196 register dw_die_ref context_die;
9200 register tree subblocks;
9202 /* Ignore blocks never really used to make RTL. */
9203 if (stmt == NULL_TREE || ! TREE_USED (stmt))
9206 /* Output the DIEs to represent all of the data objects and typedefs
9207 declared directly within this block but not within any nested
9208 sub-blocks. Also, nested function and tag DIEs have been
9209 generated with a parent of NULL; fix that up now. */
9210 for (decl = BLOCK_VARS (stmt);
9211 decl != NULL; decl = TREE_CHAIN (decl))
9213 register dw_die_ref die;
9215 if (TREE_CODE (decl) == FUNCTION_DECL)
9216 die = lookup_decl_die (decl);
9217 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9218 die = lookup_type_die (TREE_TYPE (decl));
9222 if (die != NULL && die->die_parent == NULL)
9223 add_child_die (context_die, die);
9225 gen_decl_die (decl, context_die);
9228 /* Output the DIEs to represent all sub-blocks (and the items declared
9229 therein) of this block. */
9230 for (subblocks = BLOCK_SUBBLOCKS (stmt);
9232 subblocks = BLOCK_CHAIN (subblocks))
9233 gen_block_die (subblocks, context_die, depth + 1);
9236 /* Is this a typedef we can avoid emitting? */
9239 is_redundant_typedef (decl)
9242 if (TYPE_DECL_IS_STUB (decl))
9245 if (DECL_ARTIFICIAL (decl)
9246 && DECL_CONTEXT (decl)
9247 && is_tagged_type (DECL_CONTEXT (decl))
9248 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
9249 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
9250 /* Also ignore the artificial member typedef for the class name. */
9256 /* Generate Dwarf debug information for a decl described by DECL. */
9259 gen_decl_die (decl, context_die)
9261 register dw_die_ref context_die;
9263 register tree origin;
9265 if (TREE_CODE (decl) == ERROR_MARK)
9268 /* If this ..._DECL node is marked to be ignored, then ignore it. */
9269 if (DECL_IGNORED_P (decl))
9272 switch (TREE_CODE (decl))
9275 /* The individual enumerators of an enum type get output when we output
9276 the Dwarf representation of the relevant enum type itself. */
9280 /* Don't output any DIEs to represent mere function declarations,
9281 unless they are class members or explicit block externs. */
9282 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
9283 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
9286 /* Emit info for the abstract instance first, if we haven't yet. */
9287 origin = decl_ultimate_origin (decl);
9289 gen_abstract_function (origin);
9291 if (debug_info_level > DINFO_LEVEL_TERSE)
9293 /* Before we describe the FUNCTION_DECL itself, make sure that we
9294 have described its return type. */
9295 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
9297 /* And its virtual context. */
9298 if (DECL_VINDEX (decl) != NULL_TREE)
9299 gen_type_die (DECL_CONTEXT (decl), context_die);
9301 /* And its containing type. */
9302 origin = decl_class_context (decl);
9303 if (origin != NULL_TREE)
9304 gen_type_die_for_member (origin, decl, context_die);
9307 /* Now output a DIE to represent the function itself. */
9308 gen_subprogram_die (decl, context_die);
9312 /* If we are in terse mode, don't generate any DIEs to represent any
9314 if (debug_info_level <= DINFO_LEVEL_TERSE)
9317 /* In the special case of a TYPE_DECL node representing the
9318 declaration of some type tag, if the given TYPE_DECL is marked as
9319 having been instantiated from some other (original) TYPE_DECL node
9320 (e.g. one which was generated within the original definition of an
9321 inline function) we have to generate a special (abbreviated)
9322 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9324 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
9326 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
9330 if (is_redundant_typedef (decl))
9331 gen_type_die (TREE_TYPE (decl), context_die);
9333 /* Output a DIE to represent the typedef itself. */
9334 gen_typedef_die (decl, context_die);
9338 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9339 gen_label_die (decl, context_die);
9343 /* If we are in terse mode, don't generate any DIEs to represent any
9344 variable declarations or definitions. */
9345 if (debug_info_level <= DINFO_LEVEL_TERSE)
9348 /* Output any DIEs that are needed to specify the type of this data
9350 gen_type_die (TREE_TYPE (decl), context_die);
9352 /* And its containing type. */
9353 origin = decl_class_context (decl);
9354 if (origin != NULL_TREE)
9355 gen_type_die_for_member (origin, decl, context_die);
9357 /* Now output the DIE to represent the data object itself. This gets
9358 complicated because of the possibility that the VAR_DECL really
9359 represents an inlined instance of a formal parameter for an inline
9361 origin = decl_ultimate_origin (decl);
9362 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
9363 gen_formal_parameter_die (decl, context_die);
9365 gen_variable_die (decl, context_die);
9369 /* Ignore the nameless fields that are used to skip bits, but
9370 handle C++ anonymous unions. */
9371 if (DECL_NAME (decl) != NULL_TREE
9372 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
9374 gen_type_die (member_declared_type (decl), context_die);
9375 gen_field_die (decl, context_die);
9380 gen_type_die (TREE_TYPE (decl), context_die);
9381 gen_formal_parameter_die (decl, context_die);
9384 case NAMESPACE_DECL:
9385 /* Ignore for now. */
9393 /* Add Ada "use" clause information for SGI Workshop debugger. */
9396 dwarf2out_add_library_unit_info (filename, context_list)
9397 const char *filename;
9398 const char *context_list;
9400 unsigned int file_index;
9402 if (filename != NULL)
9404 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
9405 tree context_list_decl
9406 = build_decl (LABEL_DECL, get_identifier (context_list),
9409 TREE_PUBLIC (context_list_decl) = TRUE;
9410 add_name_attribute (unit_die, context_list);
9411 file_index = lookup_filename (filename);
9412 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
9413 add_pubname (context_list_decl, unit_die);
9417 /* Write the debugging output for DECL. */
9420 dwarf2out_decl (decl)
9423 register dw_die_ref context_die = comp_unit_die;
9425 if (TREE_CODE (decl) == ERROR_MARK)
9428 /* If this ..._DECL node is marked to be ignored, then ignore it. */
9429 if (DECL_IGNORED_P (decl))
9432 switch (TREE_CODE (decl))
9435 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9436 builtin function. Explicit programmer-supplied declarations of
9437 these same functions should NOT be ignored however. */
9438 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
9441 /* What we would really like to do here is to filter out all mere
9442 file-scope declarations of file-scope functions which are never
9443 referenced later within this translation unit (and keep all of ones
9444 that *are* referenced later on) but we aren't clairvoyant, so we have
9445 no idea which functions will be referenced in the future (i.e. later
9446 on within the current translation unit). So here we just ignore all
9447 file-scope function declarations which are not also definitions. If
9448 and when the debugger needs to know something about these functions,
9449 it will have to hunt around and find the DWARF information associated
9450 with the definition of the function. Note that we can't just check
9451 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9452 definitions and which ones represent mere declarations. We have to
9453 check `DECL_INITIAL' instead. That's because the C front-end
9454 supports some weird semantics for "extern inline" function
9455 definitions. These can get inlined within the current translation
9456 unit (an thus, we need to generate DWARF info for their abstract
9457 instances so that the DWARF info for the concrete inlined instances
9458 can have something to refer to) but the compiler never generates any
9459 out-of-lines instances of such things (despite the fact that they
9460 *are* definitions). The important point is that the C front-end
9461 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9462 to generate DWARF for them anyway. Note that the C++ front-end also
9463 plays some similar games for inline function definitions appearing
9464 within include files which also contain
9465 `#pragma interface' pragmas. */
9466 if (DECL_INITIAL (decl) == NULL_TREE)
9469 /* If we're a nested function, initially use a parent of NULL; if we're
9470 a plain function, this will be fixed up in decls_for_scope. If
9471 we're a method, it will be ignored, since we already have a DIE. */
9472 if (decl_function_context (decl))
9478 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9479 declaration and if the declaration was never even referenced from
9480 within this entire compilation unit. We suppress these DIEs in
9481 order to save space in the .debug section (by eliminating entries
9482 which are probably useless). Note that we must not suppress
9483 block-local extern declarations (whether used or not) because that
9484 would screw-up the debugger's name lookup mechanism and cause it to
9485 miss things which really ought to be in scope at a given point. */
9486 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
9489 /* If we are in terse mode, don't generate any DIEs to represent any
9490 variable declarations or definitions. */
9491 if (debug_info_level <= DINFO_LEVEL_TERSE)
9496 /* Don't bother trying to generate any DIEs to represent any of the
9497 normal built-in types for the language we are compiling. */
9498 if (DECL_SOURCE_LINE (decl) == 0)
9500 /* OK, we need to generate one for `bool' so GDB knows what type
9501 comparisons have. */
9502 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
9503 == DW_LANG_C_plus_plus)
9504 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
9505 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
9510 /* If we are in terse mode, don't generate any DIEs for types. */
9511 if (debug_info_level <= DINFO_LEVEL_TERSE)
9514 /* If we're a function-scope tag, initially use a parent of NULL;
9515 this will be fixed up in decls_for_scope. */
9516 if (decl_function_context (decl))
9525 gen_decl_die (decl, context_die);
9528 /* Output a marker (i.e. a label) for the beginning of the generated code for
9532 dwarf2out_begin_block (blocknum)
9533 register unsigned blocknum;
9535 function_section (current_function_decl);
9536 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
9539 /* Output a marker (i.e. a label) for the end of the generated code for a
9543 dwarf2out_end_block (blocknum)
9544 register unsigned blocknum;
9546 function_section (current_function_decl);
9547 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
9550 /* We've decided not to emit any debugging information for BLOCK; make
9551 sure that we don't end up with orphans as a result. */
9554 dwarf2out_ignore_block (block)
9558 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
9562 if (TREE_CODE (decl) == FUNCTION_DECL)
9563 die = lookup_decl_die (decl);
9564 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9565 die = lookup_type_die (TREE_TYPE (decl));
9569 /* Just give them a dummy value for parent so dwarf2out_finish
9570 doesn't blow up; we would use add_child_die if we really
9571 wanted to add them to comp_unit_die's children. */
9572 if (die && die->die_parent == 0)
9573 die->die_parent = comp_unit_die;
9577 /* Output a marker (i.e. a label) at a point in the assembly code which
9578 corresponds to a given source level label. */
9581 dwarf2out_label (insn)
9584 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9586 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9588 function_section (current_function_decl);
9589 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
9590 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
9591 (unsigned) INSN_UID (insn));
9595 /* Lookup a filename (in the list of filenames that we know about here in
9596 dwarf2out.c) and return its "index". The index of each (known) filename is
9597 just a unique number which is associated with only that one filename.
9598 We need such numbers for the sake of generating labels
9599 (in the .debug_sfnames section) and references to those
9600 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9601 If the filename given as an argument is not found in our current list,
9602 add it to the list and assign it the next available unique index number.
9603 In order to speed up searches, we remember the index of the filename
9604 was looked up last. This handles the majority of all searches. */
9607 lookup_filename (file_name)
9608 const char *file_name;
9610 static unsigned last_file_lookup_index = 0;
9611 register unsigned i;
9613 /* Check to see if the file name that was searched on the previous call
9614 matches this file name. If so, return the index. */
9615 if (last_file_lookup_index != 0)
9616 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
9617 return last_file_lookup_index;
9619 /* Didn't match the previous lookup, search the table */
9620 for (i = 1; i < file_table_in_use; ++i)
9621 if (strcmp (file_name, file_table[i]) == 0)
9623 last_file_lookup_index = i;
9627 /* Prepare to add a new table entry by making sure there is enough space in
9628 the table to do so. If not, expand the current table. */
9629 if (file_table_in_use == file_table_allocated)
9631 file_table_allocated += FILE_TABLE_INCREMENT;
9633 = (char **) xrealloc (file_table,
9634 file_table_allocated * sizeof (char *));
9637 /* Add the new entry to the end of the filename table. */
9638 file_table[file_table_in_use] = xstrdup (file_name);
9639 last_file_lookup_index = file_table_in_use++;
9641 return last_file_lookup_index;
9644 /* Output a label to mark the beginning of a source code line entry
9645 and record information relating to this source line, in
9646 'line_info_table' for later output of the .debug_line section. */
9649 dwarf2out_line (filename, line)
9650 register const char *filename;
9651 register unsigned line;
9653 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9655 function_section (current_function_decl);
9657 if (DWARF2_ASM_LINE_DEBUG_INFO)
9659 static const char *lastfile;
9661 /* Emit the .file and .loc directives understood by GNU as. */
9662 if (lastfile == 0 || strcmp (filename, lastfile))
9665 ggc_add_string_root ((char **) &lastfile, 1);
9667 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
9668 lastfile = filename;
9671 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
9673 /* Indicate that line number info exists. */
9674 ++line_info_table_in_use;
9676 /* Indicate that multiple line number tables exist. */
9677 if (DECL_SECTION_NAME (current_function_decl))
9678 ++separate_line_info_table_in_use;
9680 else if (DECL_SECTION_NAME (current_function_decl))
9682 register dw_separate_line_info_ref line_info;
9683 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
9684 separate_line_info_table_in_use);
9686 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9687 fputc ('\n', asm_out_file);
9689 /* expand the line info table if necessary */
9690 if (separate_line_info_table_in_use
9691 == separate_line_info_table_allocated)
9693 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9694 separate_line_info_table
9695 = (dw_separate_line_info_ref)
9696 xrealloc (separate_line_info_table,
9697 separate_line_info_table_allocated
9698 * sizeof (dw_separate_line_info_entry));
9701 /* Add the new entry at the end of the line_info_table. */
9703 = &separate_line_info_table[separate_line_info_table_in_use++];
9704 line_info->dw_file_num = lookup_filename (filename);
9705 line_info->dw_line_num = line;
9706 line_info->function = current_funcdef_number;
9710 register dw_line_info_ref line_info;
9712 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
9713 line_info_table_in_use);
9715 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9716 fputc ('\n', asm_out_file);
9718 /* Expand the line info table if necessary. */
9719 if (line_info_table_in_use == line_info_table_allocated)
9721 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9723 = (dw_line_info_ref)
9724 xrealloc (line_info_table,
9725 (line_info_table_allocated
9726 * sizeof (dw_line_info_entry)));
9729 /* Add the new entry at the end of the line_info_table. */
9730 line_info = &line_info_table[line_info_table_in_use++];
9731 line_info->dw_file_num = lookup_filename (filename);
9732 line_info->dw_line_num = line;
9737 /* Record the beginning of a new source file, for later output
9738 of the .debug_macinfo section. At present, unimplemented. */
9741 dwarf2out_start_source_file (filename)
9742 register const char *filename ATTRIBUTE_UNUSED;
9746 /* Record the end of a source file, for later output
9747 of the .debug_macinfo section. At present, unimplemented. */
9750 dwarf2out_end_source_file ()
9754 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9755 the tail part of the directive line, i.e. the part which is past the
9756 initial whitespace, #, whitespace, directive-name, whitespace part. */
9759 dwarf2out_define (lineno, buffer)
9760 register unsigned lineno ATTRIBUTE_UNUSED;
9761 register const char *buffer ATTRIBUTE_UNUSED;
9763 static int initialized = 0;
9766 dwarf2out_start_source_file (primary_filename);
9771 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9772 the tail part of the directive line, i.e. the part which is past the
9773 initial whitespace, #, whitespace, directive-name, whitespace part. */
9776 dwarf2out_undef (lineno, buffer)
9777 register unsigned lineno ATTRIBUTE_UNUSED;
9778 register const char *buffer ATTRIBUTE_UNUSED;
9782 /* Set up for Dwarf output at the start of compilation. */
9785 dwarf2out_init (asm_out_file, main_input_filename)
9786 register FILE *asm_out_file;
9787 register char *main_input_filename;
9789 /* Remember the name of the primary input file. */
9790 primary_filename = main_input_filename;
9792 /* Allocate the initial hunk of the file_table. */
9793 file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
9794 file_table_allocated = FILE_TABLE_INCREMENT;
9796 /* Skip the first entry - file numbers begin at 1. */
9797 file_table_in_use = 1;
9799 /* Allocate the initial hunk of the decl_die_table. */
9801 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
9802 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
9803 decl_die_table_in_use = 0;
9805 /* Allocate the initial hunk of the decl_scope_table. */
9807 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
9808 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
9809 decl_scope_depth = 0;
9811 /* Allocate the initial hunk of the abbrev_die_table. */
9813 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
9814 sizeof (dw_die_ref));
9815 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
9816 /* Zero-th entry is allocated, but unused */
9817 abbrev_die_table_in_use = 1;
9819 /* Allocate the initial hunk of the line_info_table. */
9821 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
9822 sizeof (dw_line_info_entry));
9823 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
9824 /* Zero-th entry is allocated, but unused */
9825 line_info_table_in_use = 1;
9827 /* Generate the initial DIE for the .debug section. Note that the (string)
9828 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9829 will (typically) be a relative pathname and that this pathname should be
9830 taken as being relative to the directory from which the compiler was
9831 invoked when the given (base) source file was compiled. */
9832 comp_unit_die = gen_compile_unit_die (main_input_filename);
9836 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
9837 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
9840 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
9841 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
9842 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9843 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
9845 strcpy (text_section_label, stripattributes (TEXT_SECTION));
9846 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
9847 DEBUG_INFO_SECTION_LABEL, 0);
9848 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
9849 DEBUG_LINE_SECTION_LABEL, 0);
9851 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9852 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
9853 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9855 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9856 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
9858 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9859 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
9860 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9861 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
9864 /* Output stuff that dwarf requires at the end of every file,
9865 and generate the DWARF-2 debugging info. */
9870 limbo_die_node *node, *next_node;
9873 /* Traverse the limbo die list, and add parent/child links. The only
9874 dies without parents that should be here are concrete instances of
9875 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9876 For concrete instances, we can get the parent die from the abstract
9878 for (node = limbo_die_list; node; node = next_node)
9880 next_node = node->next;
9883 if (die->die_parent == NULL)
9885 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
9887 add_child_die (origin->die_parent, die);
9888 else if (die == comp_unit_die)
9895 limbo_die_list = NULL;
9897 /* Walk through the list of incomplete types again, trying once more to
9898 emit full debugging info for them. */
9899 retry_incomplete_types ();
9901 /* Traverse the DIE's, reverse their lists of attributes and children,
9902 and add add sibling attributes to those DIE's that have children. */
9903 add_sibling_attributes (comp_unit_die);
9905 /* Output a terminator label for the .text section. */
9906 fputc ('\n', asm_out_file);
9907 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9908 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
9911 /* Output a terminator label for the .data section. */
9912 fputc ('\n', asm_out_file);
9913 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
9914 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
9916 /* Output a terminator label for the .bss section. */
9917 fputc ('\n', asm_out_file);
9918 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
9919 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
9922 /* Output the source line correspondence table. */
9923 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
9925 if (! DWARF2_ASM_LINE_DEBUG_INFO)
9927 fputc ('\n', asm_out_file);
9928 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9929 output_line_info ();
9932 /* We can only use the low/high_pc attributes if all of the code
9934 if (separate_line_info_table_in_use == 0)
9936 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
9937 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
9940 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
9941 debug_line_section_label);
9944 #if 0 /* unimplemented */
9945 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
9946 add_AT_unsigned (die, DW_AT_macro_info, 0);
9949 /* Output the abbreviation table. */
9950 fputc ('\n', asm_out_file);
9951 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9952 build_abbrev_table (comp_unit_die);
9953 output_abbrev_section ();
9955 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9956 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9957 calc_die_sizes (comp_unit_die);
9959 /* Output debugging information. */
9960 fputc ('\n', asm_out_file);
9961 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9962 output_compilation_unit_header ();
9963 output_die (comp_unit_die);
9965 if (pubname_table_in_use)
9967 /* Output public names table. */
9968 fputc ('\n', asm_out_file);
9969 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
9973 /* We only put functions in the arange table, so don't write it out if
9974 we don't have any. */
9975 if (fde_table_in_use)
9977 /* Output the address range information. */
9978 fputc ('\n', asm_out_file);
9979 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
9983 #endif /* DWARF2_DEBUGGING_INFO */