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 != 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);
1856 /* Expand the fde table if necessary. */
1857 if (fde_table_in_use == fde_table_allocated)
1859 fde_table_allocated += FDE_TABLE_INCREMENT;
1861 = (dw_fde_ref) xrealloc (fde_table,
1862 fde_table_allocated * sizeof (dw_fde_node));
1865 /* Record the FDE associated with this function. */
1866 current_funcdef_fde = fde_table_in_use;
1868 /* Add the new FDE at the end of the fde_table. */
1869 fde = &fde_table[fde_table_in_use++];
1870 fde->dw_fde_begin = xstrdup (label);
1871 fde->dw_fde_current_label = NULL;
1872 fde->dw_fde_end = NULL;
1873 fde->dw_fde_cfi = NULL;
1875 args_size = old_args_size = 0;
1878 /* Output a marker (i.e. a label) for the absolute end of the generated code
1879 for a function definition. This gets called *after* the epilogue code has
1883 dwarf2out_end_epilogue ()
1886 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1888 /* Output a label to mark the endpoint of the code generated for this
1890 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1891 ASM_OUTPUT_LABEL (asm_out_file, label);
1892 fde = &fde_table[fde_table_in_use - 1];
1893 fde->dw_fde_end = xstrdup (label);
1897 dwarf2out_frame_init ()
1899 /* Allocate the initial hunk of the fde_table. */
1900 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
1901 fde_table_allocated = FDE_TABLE_INCREMENT;
1902 fde_table_in_use = 0;
1904 /* Generate the CFA instructions common to all FDE's. Do it now for the
1905 sake of lookup_cfa. */
1907 #ifdef DWARF2_UNWIND_INFO
1908 /* On entry, the Canonical Frame Address is at SP. */
1909 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1910 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1915 dwarf2out_frame_finish ()
1917 /* Output call frame information. */
1918 #ifdef MIPS_DEBUGGING_INFO
1919 if (write_symbols == DWARF2_DEBUG)
1920 output_call_frame_info (0);
1921 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1922 output_call_frame_info (1);
1924 if (write_symbols == DWARF2_DEBUG
1925 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1926 output_call_frame_info (1);
1930 #endif /* .debug_frame support */
1932 /* And now, the support for symbolic debugging information. */
1933 #ifdef DWARF2_DEBUGGING_INFO
1935 /* NOTE: In the comments in this file, many references are made to
1936 "Debugging Information Entries". This term is abbreviated as `DIE'
1937 throughout the remainder of this file. */
1939 /* An internal representation of the DWARF output is built, and then
1940 walked to generate the DWARF debugging info. The walk of the internal
1941 representation is done after the entire program has been compiled.
1942 The types below are used to describe the internal representation. */
1944 /* Each DIE may have a series of attribute/value pairs. Values
1945 can take on several forms. The forms that are used in this
1946 implementation are listed below. */
1953 dw_val_class_unsigned_const,
1954 dw_val_class_long_long,
1957 dw_val_class_die_ref,
1958 dw_val_class_fde_ref,
1959 dw_val_class_lbl_id,
1960 dw_val_class_lbl_offset,
1965 /* Various DIE's use offsets relative to the beginning of the
1966 .debug_info section to refer to each other. */
1968 typedef long int dw_offset;
1970 /* Define typedefs here to avoid circular dependencies. */
1972 typedef struct die_struct *dw_die_ref;
1973 typedef struct dw_attr_struct *dw_attr_ref;
1974 typedef struct dw_val_struct *dw_val_ref;
1975 typedef struct dw_line_info_struct *dw_line_info_ref;
1976 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
1977 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1978 typedef struct pubname_struct *pubname_ref;
1979 typedef dw_die_ref *arange_ref;
1981 /* Describe a double word constant value. */
1983 typedef struct dw_long_long_struct
1990 /* Describe a floating point constant value. */
1992 typedef struct dw_fp_struct
1999 /* Each entry in the line_info_table maintains the file and
2000 line number associated with the label generated for that
2001 entry. The label gives the PC value associated with
2002 the line number entry. */
2004 typedef struct dw_line_info_struct
2006 unsigned long dw_file_num;
2007 unsigned long dw_line_num;
2011 /* Line information for functions in separate sections; each one gets its
2013 typedef struct dw_separate_line_info_struct
2015 unsigned long dw_file_num;
2016 unsigned long dw_line_num;
2017 unsigned long function;
2019 dw_separate_line_info_entry;
2021 /* The dw_val_node describes an attribute's value, as it is
2022 represented internally. */
2024 typedef struct dw_val_struct
2026 dw_val_class val_class;
2030 dw_loc_descr_ref val_loc;
2032 long unsigned val_unsigned;
2033 dw_long_long_const val_long_long;
2034 dw_float_const val_float;
2035 dw_die_ref val_die_ref;
2036 unsigned val_fde_index;
2039 unsigned char val_flag;
2045 /* Locations in memory are described using a sequence of stack machine
2048 typedef struct dw_loc_descr_struct
2050 dw_loc_descr_ref dw_loc_next;
2051 enum dwarf_location_atom dw_loc_opc;
2052 dw_val_node dw_loc_oprnd1;
2053 dw_val_node dw_loc_oprnd2;
2057 /* Each DIE attribute has a field specifying the attribute kind,
2058 a link to the next attribute in the chain, and an attribute value.
2059 Attributes are typically linked below the DIE they modify. */
2061 typedef struct dw_attr_struct
2063 enum dwarf_attribute dw_attr;
2064 dw_attr_ref dw_attr_next;
2065 dw_val_node dw_attr_val;
2069 /* The Debugging Information Entry (DIE) structure */
2071 typedef struct die_struct
2073 enum dwarf_tag die_tag;
2074 dw_attr_ref die_attr;
2075 dw_die_ref die_parent;
2076 dw_die_ref die_child;
2078 dw_offset die_offset;
2079 unsigned long die_abbrev;
2083 /* The pubname structure */
2085 typedef struct pubname_struct
2092 /* The limbo die list structure. */
2093 typedef struct limbo_die_struct
2096 struct limbo_die_struct *next;
2100 /* How to start an assembler comment. */
2101 #ifndef ASM_COMMENT_START
2102 #define ASM_COMMENT_START ";#"
2105 /* Define a macro which returns non-zero for a TYPE_DECL which was
2106 implicitly generated for a tagged type.
2108 Note that unlike the gcc front end (which generates a NULL named
2109 TYPE_DECL node for each complete tagged type, each array type, and
2110 each function type node created) the g++ front end generates a
2111 _named_ TYPE_DECL node for each tagged type node created.
2112 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2113 generate a DW_TAG_typedef DIE for them. */
2115 #define TYPE_DECL_IS_STUB(decl) \
2116 (DECL_NAME (decl) == NULL_TREE \
2117 || (DECL_ARTIFICIAL (decl) \
2118 && is_tagged_type (TREE_TYPE (decl)) \
2119 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2120 /* This is necessary for stub decls that \
2121 appear in nested inline functions. */ \
2122 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2123 && (decl_ultimate_origin (decl) \
2124 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2126 /* Information concerning the compilation unit's programming
2127 language, and compiler version. */
2129 extern int flag_traditional;
2131 /* Fixed size portion of the DWARF compilation unit header. */
2132 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2134 /* Fixed size portion of debugging line information prolog. */
2135 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2137 /* Fixed size portion of public names info. */
2138 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2140 /* Fixed size portion of the address range info. */
2141 #define DWARF_ARANGES_HEADER_SIZE \
2142 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
2144 /* The default is to have gcc emit the line number tables. */
2145 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2146 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2149 /* Define the architecture-dependent minimum instruction length (in bytes).
2150 In this implementation of DWARF, this field is used for information
2151 purposes only. Since GCC generates assembly language, we have
2152 no a priori knowledge of how many instruction bytes are generated
2153 for each source line, and therefore can use only the DW_LNE_set_address
2154 and DW_LNS_fixed_advance_pc line information commands. */
2156 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2157 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2160 /* Minimum line offset in a special line info. opcode.
2161 This value was chosen to give a reasonable range of values. */
2162 #define DWARF_LINE_BASE -10
2164 /* First special line opcde - leave room for the standard opcodes. */
2165 #define DWARF_LINE_OPCODE_BASE 10
2167 /* Range of line offsets in a special line info. opcode. */
2168 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2170 /* Flag that indicates the initial value of the is_stmt_start flag.
2171 In the present implementation, we do not mark any lines as
2172 the beginning of a source statement, because that information
2173 is not made available by the GCC front-end. */
2174 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2176 /* This location is used by calc_die_sizes() to keep track
2177 the offset of each DIE within the .debug_info section. */
2178 static unsigned long next_die_offset;
2180 /* Record the root of the DIE's built for the current compilation unit. */
2181 static dw_die_ref comp_unit_die;
2183 /* A list of DIEs with a NULL parent waiting to be relocated. */
2184 static limbo_die_node *limbo_die_list = 0;
2186 /* Pointer to an array of filenames referenced by this compilation unit. */
2187 static char **file_table;
2189 /* Total number of entries in the table (i.e. array) pointed to by
2190 `file_table'. This is the *total* and includes both used and unused
2192 static unsigned file_table_allocated;
2194 /* Number of entries in the file_table which are actually in use. */
2195 static unsigned file_table_in_use;
2197 /* Size (in elements) of increments by which we may expand the filename
2199 #define FILE_TABLE_INCREMENT 64
2201 /* Local pointer to the name of the main input file. Initialized in
2203 static char *primary_filename;
2205 /* A pointer to the base of a table of references to DIE's that describe
2206 declarations. The table is indexed by DECL_UID() which is a unique
2207 number identifying each decl. */
2208 static dw_die_ref *decl_die_table;
2210 /* Number of elements currently allocated for the decl_die_table. */
2211 static unsigned decl_die_table_allocated;
2213 /* Number of elements in decl_die_table currently in use. */
2214 static unsigned decl_die_table_in_use;
2216 /* Size (in elements) of increments by which we may expand the
2218 #define DECL_DIE_TABLE_INCREMENT 256
2220 /* A pointer to the base of a table of references to declaration
2221 scopes. This table is a display which tracks the nesting
2222 of declaration scopes at the current scope and containing
2223 scopes. This table is used to find the proper place to
2224 define type declaration DIE's. */
2225 static tree *decl_scope_table;
2227 /* Number of elements currently allocated for the decl_scope_table. */
2228 static int decl_scope_table_allocated;
2230 /* Current level of nesting of declaration scopes. */
2231 static int decl_scope_depth;
2233 /* Size (in elements) of increments by which we may expand the
2234 decl_scope_table. */
2235 #define DECL_SCOPE_TABLE_INCREMENT 64
2237 /* A pointer to the base of a list of references to DIE's that
2238 are uniquely identified by their tag, presence/absence of
2239 children DIE's, and list of attribute/value pairs. */
2240 static dw_die_ref *abbrev_die_table;
2242 /* Number of elements currently allocated for abbrev_die_table. */
2243 static unsigned abbrev_die_table_allocated;
2245 /* Number of elements in type_die_table currently in use. */
2246 static unsigned abbrev_die_table_in_use;
2248 /* Size (in elements) of increments by which we may expand the
2249 abbrev_die_table. */
2250 #define ABBREV_DIE_TABLE_INCREMENT 256
2252 /* A pointer to the base of a table that contains line information
2253 for each source code line in .text in the compilation unit. */
2254 static dw_line_info_ref line_info_table;
2256 /* Number of elements currently allocated for line_info_table. */
2257 static unsigned line_info_table_allocated;
2259 /* Number of elements in separate_line_info_table currently in use. */
2260 static unsigned separate_line_info_table_in_use;
2262 /* A pointer to the base of a table that contains line information
2263 for each source code line outside of .text in the compilation unit. */
2264 static dw_separate_line_info_ref separate_line_info_table;
2266 /* Number of elements currently allocated for separate_line_info_table. */
2267 static unsigned separate_line_info_table_allocated;
2269 /* Number of elements in line_info_table currently in use. */
2270 static unsigned line_info_table_in_use;
2272 /* Size (in elements) of increments by which we may expand the
2274 #define LINE_INFO_TABLE_INCREMENT 1024
2276 /* A pointer to the base of a table that contains a list of publicly
2277 accessible names. */
2278 static pubname_ref pubname_table;
2280 /* Number of elements currently allocated for pubname_table. */
2281 static unsigned pubname_table_allocated;
2283 /* Number of elements in pubname_table currently in use. */
2284 static unsigned pubname_table_in_use;
2286 /* Size (in elements) of increments by which we may expand the
2288 #define PUBNAME_TABLE_INCREMENT 64
2290 /* A pointer to the base of a table that contains a list of publicly
2291 accessible names. */
2292 static arange_ref arange_table;
2294 /* Number of elements currently allocated for arange_table. */
2295 static unsigned arange_table_allocated;
2297 /* Number of elements in arange_table currently in use. */
2298 static unsigned arange_table_in_use;
2300 /* Size (in elements) of increments by which we may expand the
2302 #define ARANGE_TABLE_INCREMENT 64
2304 /* A pointer to the base of a list of incomplete types which might be
2305 completed at some later time. */
2307 static tree *incomplete_types_list;
2309 /* Number of elements currently allocated for the incomplete_types_list. */
2310 static unsigned incomplete_types_allocated;
2312 /* Number of elements of incomplete_types_list currently in use. */
2313 static unsigned incomplete_types;
2315 /* Size (in elements) of increments by which we may expand the incomplete
2316 types list. Actually, a single hunk of space of this size should
2317 be enough for most typical programs. */
2318 #define INCOMPLETE_TYPES_INCREMENT 64
2320 /* Record whether the function being analyzed contains inlined functions. */
2321 static int current_function_has_inlines;
2322 #if 0 && defined (MIPS_DEBUGGING_INFO)
2323 static int comp_unit_has_inlines;
2326 /* Array of RTXes referenced by the debugging information, which therefore
2327 must be kept around forever. We do this rather than perform GC on
2328 the dwarf info because almost all of the dwarf info lives forever, and
2329 it's easier to support non-GC frontends this way. */
2330 static varray_type used_rtx_varray;
2332 /* Forward declarations for functions defined in this file. */
2334 static int is_pseudo_reg PARAMS ((rtx));
2335 static tree type_main_variant PARAMS ((tree));
2336 static int is_tagged_type PARAMS ((tree));
2337 static const char *dwarf_tag_name PARAMS ((unsigned));
2338 static const char *dwarf_attr_name PARAMS ((unsigned));
2339 static const char *dwarf_form_name PARAMS ((unsigned));
2340 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2342 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
2344 static tree decl_ultimate_origin PARAMS ((tree));
2345 static tree block_ultimate_origin PARAMS ((tree));
2346 static tree decl_class_context PARAMS ((tree));
2347 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
2348 static void add_AT_flag PARAMS ((dw_die_ref,
2349 enum dwarf_attribute,
2351 static void add_AT_int PARAMS ((dw_die_ref,
2352 enum dwarf_attribute, long));
2353 static void add_AT_unsigned PARAMS ((dw_die_ref,
2354 enum dwarf_attribute,
2356 static void add_AT_long_long PARAMS ((dw_die_ref,
2357 enum dwarf_attribute,
2360 static void add_AT_float PARAMS ((dw_die_ref,
2361 enum dwarf_attribute,
2363 static void add_AT_string PARAMS ((dw_die_ref,
2364 enum dwarf_attribute,
2366 static void add_AT_die_ref PARAMS ((dw_die_ref,
2367 enum dwarf_attribute,
2369 static void add_AT_fde_ref PARAMS ((dw_die_ref,
2370 enum dwarf_attribute,
2372 static void add_AT_loc PARAMS ((dw_die_ref,
2373 enum dwarf_attribute,
2375 static void add_AT_addr PARAMS ((dw_die_ref,
2376 enum dwarf_attribute,
2378 static void add_AT_lbl_id PARAMS ((dw_die_ref,
2379 enum dwarf_attribute,
2381 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
2382 enum dwarf_attribute,
2384 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
2385 enum dwarf_attribute));
2386 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
2387 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
2388 static const char *get_AT_string PARAMS ((dw_die_ref,
2389 enum dwarf_attribute));
2390 static int get_AT_flag PARAMS ((dw_die_ref,
2391 enum dwarf_attribute));
2392 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
2393 enum dwarf_attribute));
2394 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
2395 enum dwarf_attribute));
2396 static int is_c_family PARAMS ((void));
2397 static int is_fortran PARAMS ((void));
2398 static void remove_AT PARAMS ((dw_die_ref,
2399 enum dwarf_attribute));
2400 static void remove_children PARAMS ((dw_die_ref));
2401 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
2402 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
2403 static dw_die_ref lookup_type_die PARAMS ((tree));
2404 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
2405 static dw_die_ref lookup_decl_die PARAMS ((tree));
2406 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
2407 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2410 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2412 static void print_spaces PARAMS ((FILE *));
2413 static void print_die PARAMS ((dw_die_ref, FILE *));
2414 static void print_dwarf_line_table PARAMS ((FILE *));
2415 static void add_sibling_attributes PARAMS ((dw_die_ref));
2416 static void build_abbrev_table PARAMS ((dw_die_ref));
2417 static unsigned long size_of_string PARAMS ((const char *));
2418 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2419 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2420 static int constant_size PARAMS ((long unsigned));
2421 static unsigned long size_of_die PARAMS ((dw_die_ref));
2422 static void calc_die_sizes PARAMS ((dw_die_ref));
2423 static unsigned long size_of_line_prolog PARAMS ((void));
2424 static unsigned long size_of_pubnames PARAMS ((void));
2425 static unsigned long size_of_aranges PARAMS ((void));
2426 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
2427 static void output_value_format PARAMS ((dw_attr_ref));
2428 static void output_abbrev_section PARAMS ((void));
2429 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2430 static void output_die PARAMS ((dw_die_ref));
2431 static void output_compilation_unit_header PARAMS ((void));
2432 static const char *dwarf2_name PARAMS ((tree, int));
2433 static void add_pubname PARAMS ((tree, dw_die_ref));
2434 static void output_pubnames PARAMS ((void));
2435 static void add_arange PARAMS ((tree, dw_die_ref));
2436 static void output_aranges PARAMS ((void));
2437 static void output_line_info PARAMS ((void));
2438 static int is_body_block PARAMS ((tree));
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 BLOCK node return non-zero if (and only if) the node
5927 in question represents the outermost pair of curly braces (i.e. the "body
5928 block") of a function or method.
5930 For any BLOCK node representing a "body block" of a function or method, the
5931 BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
5932 represents the outermost (function) scope for the function or method (i.e.
5933 the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
5934 *that* node in turn will point to the relevant FUNCTION_DECL node. */
5937 is_body_block (stmt)
5940 if (TREE_CODE (stmt) == BLOCK)
5942 register tree parent = BLOCK_SUPERCONTEXT (stmt);
5944 if (TREE_CODE (parent) == BLOCK)
5946 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
5948 if (TREE_CODE (grandparent) == FUNCTION_DECL)
5956 /* Given a pointer to a tree node for some base type, return a pointer to
5957 a DIE that describes the given type.
5959 This routine must only be called for GCC type nodes that correspond to
5960 Dwarf base (fundamental) types. */
5963 base_type_die (type)
5966 register dw_die_ref base_type_result;
5967 register const char *type_name;
5968 register enum dwarf_type encoding;
5969 register tree name = TYPE_NAME (type);
5971 if (TREE_CODE (type) == ERROR_MARK
5972 || TREE_CODE (type) == VOID_TYPE)
5977 if (TREE_CODE (name) == TYPE_DECL)
5978 name = DECL_NAME (name);
5980 type_name = IDENTIFIER_POINTER (name);
5983 type_name = "__unknown__";
5985 switch (TREE_CODE (type))
5988 /* Carefully distinguish the C character types, without messing
5989 up if the language is not C. Note that we check only for the names
5990 that contain spaces; other names might occur by coincidence in other
5992 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
5993 && (type == char_type_node
5994 || ! strcmp (type_name, "signed char")
5995 || ! strcmp (type_name, "unsigned char"))))
5997 if (TREE_UNSIGNED (type))
5998 encoding = DW_ATE_unsigned;
6000 encoding = DW_ATE_signed;
6003 /* else fall through */
6006 /* GNU Pascal/Ada CHAR type. Not used in C. */
6007 if (TREE_UNSIGNED (type))
6008 encoding = DW_ATE_unsigned_char;
6010 encoding = DW_ATE_signed_char;
6014 encoding = DW_ATE_float;
6017 /* Dwarf2 doesn't know anything about complex ints, so use
6018 a user defined type for it. */
6020 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6021 encoding = DW_ATE_complex_float;
6023 encoding = DW_ATE_lo_user;
6027 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6028 encoding = DW_ATE_boolean;
6032 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6035 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6036 if (demangle_name_func)
6037 type_name = (*demangle_name_func) (type_name);
6039 add_AT_string (base_type_result, DW_AT_name, type_name);
6040 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6041 int_size_in_bytes (type));
6042 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6044 return base_type_result;
6047 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6048 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6049 a given type is generally the same as the given type, except that if the
6050 given type is a pointer or reference type, then the root type of the given
6051 type is the root type of the "basis" type for the pointer or reference
6052 type. (This definition of the "root" type is recursive.) Also, the root
6053 type of a `const' qualified type or a `volatile' qualified type is the
6054 root type of the given type without the qualifiers. */
6060 if (TREE_CODE (type) == ERROR_MARK)
6061 return error_mark_node;
6063 switch (TREE_CODE (type))
6066 return error_mark_node;
6069 case REFERENCE_TYPE:
6070 return type_main_variant (root_type (TREE_TYPE (type)));
6073 return type_main_variant (type);
6077 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6078 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6084 switch (TREE_CODE (type))
6099 case QUAL_UNION_TYPE:
6104 case REFERENCE_TYPE:
6117 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6118 entry that chains various modifiers in front of the given type. */
6121 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6123 register int is_const_type;
6124 register int is_volatile_type;
6125 register dw_die_ref context_die;
6127 register enum tree_code code = TREE_CODE (type);
6128 register dw_die_ref mod_type_die = NULL;
6129 register dw_die_ref sub_die = NULL;
6130 register tree item_type = NULL;
6132 if (code != ERROR_MARK)
6134 type = build_type_variant (type, is_const_type, is_volatile_type);
6136 mod_type_die = lookup_type_die (type);
6138 return mod_type_die;
6140 /* Handle C typedef types. */
6141 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6142 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6144 tree dtype = TREE_TYPE (TYPE_NAME (type));
6147 /* For a named type, use the typedef. */
6148 gen_type_die (type, context_die);
6149 mod_type_die = lookup_type_die (type);
6152 else if (is_const_type < TYPE_READONLY (dtype)
6153 || is_volatile_type < TYPE_VOLATILE (dtype))
6154 /* cv-unqualified version of named type. Just use the unnamed
6155 type to which it refers. */
6157 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6158 is_const_type, is_volatile_type,
6160 /* Else cv-qualified version of named type; fall through. */
6165 else if (is_const_type)
6167 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6168 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6170 else if (is_volatile_type)
6172 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6173 sub_die = modified_type_die (type, 0, 0, context_die);
6175 else if (code == POINTER_TYPE)
6177 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6178 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6180 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6182 item_type = TREE_TYPE (type);
6184 else if (code == REFERENCE_TYPE)
6186 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6187 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6189 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6191 item_type = TREE_TYPE (type);
6193 else if (is_base_type (type))
6194 mod_type_die = base_type_die (type);
6197 gen_type_die (type, context_die);
6199 /* We have to get the type_main_variant here (and pass that to the
6200 `lookup_type_die' routine) because the ..._TYPE node we have
6201 might simply be a *copy* of some original type node (where the
6202 copy was created to help us keep track of typedef names) and
6203 that copy might have a different TYPE_UID from the original
6205 mod_type_die = lookup_type_die (type_main_variant (type));
6206 if (mod_type_die == NULL)
6211 equate_type_number_to_die (type, mod_type_die);
6213 /* We must do this after the equate_type_number_to_die call, in case
6214 this is a recursive type. This ensures that the modified_type_die
6215 recursion will terminate even if the type is recursive. Recursive
6216 types are possible in Ada. */
6217 sub_die = modified_type_die (item_type,
6218 TYPE_READONLY (item_type),
6219 TYPE_VOLATILE (item_type),
6222 if (sub_die != NULL)
6223 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6225 return mod_type_die;
6228 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6229 an enumerated type. */
6235 return TREE_CODE (type) == ENUMERAL_TYPE;
6238 /* Return a location descriptor that designates a machine register. */
6240 static dw_loc_descr_ref
6241 reg_loc_descriptor (rtl)
6244 register dw_loc_descr_ref loc_result = NULL;
6245 register unsigned reg = reg_number (rtl);
6248 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6250 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6255 /* Return a location descriptor that designates a base+offset location. */
6257 static dw_loc_descr_ref
6258 based_loc_descr (reg, offset)
6262 register dw_loc_descr_ref loc_result;
6263 /* For the "frame base", we use the frame pointer or stack pointer
6264 registers, since the RTL for local variables is relative to one of
6266 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6267 ? HARD_FRAME_POINTER_REGNUM
6268 : STACK_POINTER_REGNUM);
6271 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
6273 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
6275 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
6280 /* Return true if this RTL expression describes a base+offset calculation. */
6286 return (GET_CODE (rtl) == PLUS
6287 && ((GET_CODE (XEXP (rtl, 0)) == REG
6288 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
6291 /* The following routine converts the RTL for a variable or parameter
6292 (resident in memory) into an equivalent Dwarf representation of a
6293 mechanism for getting the address of that same variable onto the top of a
6294 hypothetical "address evaluation" stack.
6296 When creating memory location descriptors, we are effectively transforming
6297 the RTL for a memory-resident object into its Dwarf postfix expression
6298 equivalent. This routine recursively descends an RTL tree, turning
6299 it into Dwarf postfix code as it goes.
6301 MODE is the mode of the memory reference, needed to handle some
6302 autoincrement addressing modes. */
6304 static dw_loc_descr_ref
6305 mem_loc_descriptor (rtl, mode)
6307 enum machine_mode mode;
6309 dw_loc_descr_ref mem_loc_result = NULL;
6310 /* Note that for a dynamically sized array, the location we will generate a
6311 description of here will be the lowest numbered location which is
6312 actually within the array. That's *not* necessarily the same as the
6313 zeroth element of the array. */
6315 #ifdef ASM_SIMPLIFY_DWARF_ADDR
6316 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
6319 switch (GET_CODE (rtl))
6323 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
6324 just fall into the SUBREG code. */
6326 /* ... fall through ... */
6329 /* The case of a subreg may arise when we have a local (register)
6330 variable or a formal (register) parameter which doesn't quite fill
6331 up an entire register. For now, just assume that it is
6332 legitimate to make the Dwarf info refer to the whole register which
6333 contains the given subreg. */
6334 rtl = XEXP (rtl, 0);
6336 /* ... fall through ... */
6339 /* Whenever a register number forms a part of the description of the
6340 method for calculating the (dynamic) address of a memory resident
6341 object, DWARF rules require the register number be referred to as
6342 a "base register". This distinction is not based in any way upon
6343 what category of register the hardware believes the given register
6344 belongs to. This is strictly DWARF terminology we're dealing with
6345 here. Note that in cases where the location of a memory-resident
6346 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6347 OP_CONST (0)) the actual DWARF location descriptor that we generate
6348 may just be OP_BASEREG (basereg). This may look deceptively like
6349 the object in question was allocated to a register (rather than in
6350 memory) so DWARF consumers need to be aware of the subtle
6351 distinction between OP_REG and OP_BASEREG. */
6352 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
6356 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
6357 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6361 /* Some ports can transform a symbol ref into a label ref, because
6362 the symbol ref is too far away and has to be dumped into a constant
6366 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6367 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6368 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
6373 /* Turn these into a PLUS expression and fall into the PLUS code
6375 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
6376 GEN_INT (GET_CODE (rtl) == PRE_INC
6377 ? GET_MODE_UNIT_SIZE (mode)
6378 : - GET_MODE_UNIT_SIZE (mode)));
6380 /* ... fall through ... */
6383 if (is_based_loc (rtl))
6384 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
6385 INTVAL (XEXP (rtl, 1)));
6388 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0),
6390 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1),
6392 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
6397 /* If a pseudo-reg is optimized away, it is possible for it to
6398 be replaced with a MEM containing a multiply. */
6399 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode));
6400 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode));
6401 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
6405 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6412 return mem_loc_result;
6415 /* Return a descriptor that describes the concatenation of two locations.
6416 This is typically a complex variable. */
6418 static dw_loc_descr_ref
6419 concat_loc_descriptor (x0, x1)
6420 register rtx x0, x1;
6422 dw_loc_descr_ref cc_loc_result = NULL;
6424 if (!is_pseudo_reg (x0)
6425 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
6426 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
6427 add_loc_descr (&cc_loc_result,
6428 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
6430 if (!is_pseudo_reg (x1)
6431 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
6432 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
6433 add_loc_descr (&cc_loc_result,
6434 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
6436 return cc_loc_result;
6439 /* Output a proper Dwarf location descriptor for a variable or parameter
6440 which is either allocated in a register or in a memory location. For a
6441 register, we just generate an OP_REG and the register number. For a
6442 memory location we provide a Dwarf postfix expression describing how to
6443 generate the (dynamic) address of the object onto the address stack. */
6445 static dw_loc_descr_ref
6446 loc_descriptor (rtl)
6449 dw_loc_descr_ref loc_result = NULL;
6450 switch (GET_CODE (rtl))
6453 /* The case of a subreg may arise when we have a local (register)
6454 variable or a formal (register) parameter which doesn't quite fill
6455 up an entire register. For now, just assume that it is
6456 legitimate to make the Dwarf info refer to the whole register which
6457 contains the given subreg. */
6458 rtl = XEXP (rtl, 0);
6460 /* ... fall through ... */
6463 loc_result = reg_loc_descriptor (rtl);
6467 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
6471 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
6481 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
6482 which is not less than the value itself. */
6484 static inline unsigned
6485 ceiling (value, boundary)
6486 register unsigned value;
6487 register unsigned boundary;
6489 return (((value + boundary - 1) / boundary) * boundary);
6492 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6493 pointer to the declared type for the relevant field variable, or return
6494 `integer_type_node' if the given node turns out to be an
6503 if (TREE_CODE (decl) == ERROR_MARK)
6504 return integer_type_node;
6506 type = DECL_BIT_FIELD_TYPE (decl);
6507 if (type == NULL_TREE)
6508 type = TREE_TYPE (decl);
6513 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6514 node, return the alignment in bits for the type, or else return
6515 BITS_PER_WORD if the node actually turns out to be an
6518 static inline unsigned
6519 simple_type_align_in_bits (type)
6522 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6525 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6526 node, return the size in bits for the type if it is a constant, or else
6527 return the alignment for the type if the type's size is not constant, or
6528 else return BITS_PER_WORD if the type actually turns out to be an
6531 static inline unsigned
6532 simple_type_size_in_bits (type)
6535 if (TREE_CODE (type) == ERROR_MARK)
6536 return BITS_PER_WORD;
6539 register tree type_size_tree = TYPE_SIZE (type);
6541 if (TREE_CODE (type_size_tree) != INTEGER_CST)
6542 return TYPE_ALIGN (type);
6544 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
6548 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6549 return the byte offset of the lowest addressed byte of the "containing
6550 object" for the given FIELD_DECL, or return 0 if we are unable to
6551 determine what that offset is, either because the argument turns out to
6552 be a pointer to an ERROR_MARK node, or because the offset is actually
6553 variable. (We can't handle the latter case just yet). */
6556 field_byte_offset (decl)
6559 register unsigned type_align_in_bytes;
6560 register unsigned type_align_in_bits;
6561 register unsigned type_size_in_bits;
6562 register unsigned object_offset_in_align_units;
6563 register unsigned object_offset_in_bits;
6564 register unsigned object_offset_in_bytes;
6566 register tree bitpos_tree;
6567 register tree field_size_tree;
6568 register unsigned bitpos_int;
6569 register unsigned deepest_bitpos;
6570 register unsigned field_size_in_bits;
6572 if (TREE_CODE (decl) == ERROR_MARK)
6575 if (TREE_CODE (decl) != FIELD_DECL)
6578 type = field_type (decl);
6580 bitpos_tree = DECL_FIELD_BITPOS (decl);
6581 field_size_tree = DECL_SIZE (decl);
6583 /* If there was an error, the size could be zero. */
6584 if (! field_size_tree)
6591 /* We cannot yet cope with fields whose positions are variable, so
6592 for now, when we see such things, we simply return 0. Someday, we may
6593 be able to handle such cases, but it will be damn difficult. */
6594 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6597 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6599 /* If we don't know the size of the field, pretend it's a full word. */
6600 if (TREE_CODE (field_size_tree) == INTEGER_CST)
6601 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
6603 field_size_in_bits = BITS_PER_WORD;
6605 type_size_in_bits = simple_type_size_in_bits (type);
6606 type_align_in_bits = simple_type_align_in_bits (type);
6607 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6609 /* Note that the GCC front-end doesn't make any attempt to keep track of
6610 the starting bit offset (relative to the start of the containing
6611 structure type) of the hypothetical "containing object" for a bit-
6612 field. Thus, when computing the byte offset value for the start of the
6613 "containing object" of a bit-field, we must deduce this information on
6614 our own. This can be rather tricky to do in some cases. For example,
6615 handling the following structure type definition when compiling for an
6616 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6619 struct S { int field1; long long field2:31; };
6621 Fortunately, there is a simple rule-of-thumb which can be
6622 used in such cases. When compiling for an i386/i486, GCC will allocate
6623 8 bytes for the structure shown above. It decides to do this based upon
6624 one simple rule for bit-field allocation. Quite simply, GCC allocates
6625 each "containing object" for each bit-field at the first (i.e. lowest
6626 addressed) legitimate alignment boundary (based upon the required
6627 minimum alignment for the declared type of the field) which it can
6628 possibly use, subject to the condition that there is still enough
6629 available space remaining in the containing object (when allocated at
6630 the selected point) to fully accommodate all of the bits of the
6631 bit-field itself. This simple rule makes it obvious why GCC allocates
6632 8 bytes for each object of the structure type shown above. When looking
6633 for a place to allocate the "containing object" for `field2', the
6634 compiler simply tries to allocate a 64-bit "containing object" at each
6635 successive 32-bit boundary (starting at zero) until it finds a place to
6636 allocate that 64- bit field such that at least 31 contiguous (and
6637 previously unallocated) bits remain within that selected 64 bit field.
6638 (As it turns out, for the example above, the compiler finds that it is
6639 OK to allocate the "containing object" 64-bit field at bit-offset zero
6640 within the structure type.) Here we attempt to work backwards from the
6641 limited set of facts we're given, and we try to deduce from those facts,
6642 where GCC must have believed that the containing object started (within
6643 the structure type). The value we deduce is then used (by the callers of
6644 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6645 for fields (both bit-fields and, in the case of DW_AT_location, regular
6648 /* Figure out the bit-distance from the start of the structure to the
6649 "deepest" bit of the bit-field. */
6650 deepest_bitpos = bitpos_int + field_size_in_bits;
6652 /* This is the tricky part. Use some fancy footwork to deduce where the
6653 lowest addressed bit of the containing object must be. */
6654 object_offset_in_bits
6655 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6657 /* Compute the offset of the containing object in "alignment units". */
6658 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6660 /* Compute the offset of the containing object in bytes. */
6661 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6663 return object_offset_in_bytes;
6666 /* The following routines define various Dwarf attributes and any data
6667 associated with them. */
6669 /* Add a location description attribute value to a DIE.
6671 This emits location attributes suitable for whole variables and
6672 whole parameters. Note that the location attributes for struct fields are
6673 generated by the routine `data_member_location_attribute' below. */
6676 add_AT_location_description (die, attr_kind, rtl)
6678 enum dwarf_attribute attr_kind;
6681 /* Handle a special case. If we are about to output a location descriptor
6682 for a variable or parameter which has been optimized out of existence,
6683 don't do that. A variable which has been optimized out
6684 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6685 Currently, in some rare cases, variables can have DECL_RTL values which
6686 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6687 elsewhere in the compiler. We treat such cases as if the variable(s) in
6688 question had been optimized out of existence. */
6690 if (is_pseudo_reg (rtl)
6691 || (GET_CODE (rtl) == MEM
6692 && is_pseudo_reg (XEXP (rtl, 0)))
6693 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
6694 references the internal argument pointer (a pseudo) in a function
6695 where all references to the internal argument pointer were
6696 eliminated via the optimizers. */
6697 || (GET_CODE (rtl) == MEM
6698 && GET_CODE (XEXP (rtl, 0)) == PLUS
6699 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
6700 || (GET_CODE (rtl) == CONCAT
6701 && is_pseudo_reg (XEXP (rtl, 0))
6702 && is_pseudo_reg (XEXP (rtl, 1))))
6705 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
6708 /* Attach the specialized form of location attribute used for data
6709 members of struct and union types. In the special case of a
6710 FIELD_DECL node which represents a bit-field, the "offset" part
6711 of this special location descriptor must indicate the distance
6712 in bytes from the lowest-addressed byte of the containing struct
6713 or union type to the lowest-addressed byte of the "containing
6714 object" for the bit-field. (See the `field_byte_offset' function
6715 above).. For any given bit-field, the "containing object" is a
6716 hypothetical object (of some integral or enum type) within which
6717 the given bit-field lives. The type of this hypothetical
6718 "containing object" is always the same as the declared type of
6719 the individual bit-field itself (for GCC anyway... the DWARF
6720 spec doesn't actually mandate this). Note that it is the size
6721 (in bytes) of the hypothetical "containing object" which will
6722 be given in the DW_AT_byte_size attribute for this bit-field.
6723 (See the `byte_size_attribute' function below.) It is also used
6724 when calculating the value of the DW_AT_bit_offset attribute.
6725 (See the `bit_offset_attribute' function below). */
6728 add_data_member_location_attribute (die, decl)
6729 register dw_die_ref die;
6732 register unsigned long offset;
6733 register dw_loc_descr_ref loc_descr;
6734 register enum dwarf_location_atom op;
6736 if (TREE_CODE (decl) == TREE_VEC)
6737 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
6739 offset = field_byte_offset (decl);
6741 /* The DWARF2 standard says that we should assume that the structure address
6742 is already on the stack, so we can specify a structure field address
6743 by using DW_OP_plus_uconst. */
6745 #ifdef MIPS_DEBUGGING_INFO
6746 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6747 correctly. It works only if we leave the offset on the stack. */
6750 op = DW_OP_plus_uconst;
6753 loc_descr = new_loc_descr (op, offset, 0);
6754 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6757 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6758 does not have a "location" either in memory or in a register. These
6759 things can arise in GNU C when a constant is passed as an actual parameter
6760 to an inlined function. They can also arise in C++ where declared
6761 constants do not necessarily get memory "homes". */
6764 add_const_value_attribute (die, rtl)
6765 register dw_die_ref die;
6768 switch (GET_CODE (rtl))
6771 /* Note that a CONST_INT rtx could represent either an integer or a
6772 floating-point constant. A CONST_INT is used whenever the constant
6773 will fit into a single word. In all such cases, the original mode
6774 of the constant value is wiped out, and the CONST_INT rtx is
6775 assigned VOIDmode. */
6776 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6780 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6781 floating-point constant. A CONST_DOUBLE is used whenever the
6782 constant requires more than one word in order to be adequately
6783 represented. We output CONST_DOUBLEs as blocks. */
6785 register enum machine_mode mode = GET_MODE (rtl);
6787 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6789 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6793 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6797 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6801 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6806 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6813 add_AT_float (die, DW_AT_const_value, length, array);
6816 add_AT_long_long (die, DW_AT_const_value,
6817 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6822 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6828 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
6832 /* In cases where an inlined instance of an inline function is passed
6833 the address of an `auto' variable (which is local to the caller) we
6834 can get a situation where the DECL_RTL of the artificial local
6835 variable (for the inlining) which acts as a stand-in for the
6836 corresponding formal parameter (of the inline function) will look
6837 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6838 exactly a compile-time constant expression, but it isn't the address
6839 of the (artificial) local variable either. Rather, it represents the
6840 *value* which the artificial local variable always has during its
6841 lifetime. We currently have no way to represent such quasi-constant
6842 values in Dwarf, so for now we just punt and generate nothing. */
6846 /* No other kinds of rtx should be possible here. */
6852 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6853 data attribute for a variable or a parameter. We generate the
6854 DW_AT_const_value attribute only in those cases where the given variable
6855 or parameter does not have a true "location" either in memory or in a
6856 register. This can happen (for example) when a constant is passed as an
6857 actual argument in a call to an inline function. (It's possible that
6858 these things can crop up in other ways also.) Note that one type of
6859 constant value which can be passed into an inlined function is a constant
6860 pointer. This can happen for example if an actual argument in an inlined
6861 function call evaluates to a compile-time constant address. */
6864 add_location_or_const_value_attribute (die, decl)
6865 register dw_die_ref die;
6869 register tree declared_type;
6870 register tree passed_type;
6872 if (TREE_CODE (decl) == ERROR_MARK)
6875 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6878 /* Here we have to decide where we are going to say the parameter "lives"
6879 (as far as the debugger is concerned). We only have a couple of
6880 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6882 DECL_RTL normally indicates where the parameter lives during most of the
6883 activation of the function. If optimization is enabled however, this
6884 could be either NULL or else a pseudo-reg. Both of those cases indicate
6885 that the parameter doesn't really live anywhere (as far as the code
6886 generation parts of GCC are concerned) during most of the function's
6887 activation. That will happen (for example) if the parameter is never
6888 referenced within the function.
6890 We could just generate a location descriptor here for all non-NULL
6891 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6892 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6893 where DECL_RTL is NULL or is a pseudo-reg.
6895 Note however that we can only get away with using DECL_INCOMING_RTL as
6896 a backup substitute for DECL_RTL in certain limited cases. In cases
6897 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6898 we can be sure that the parameter was passed using the same type as it is
6899 declared to have within the function, and that its DECL_INCOMING_RTL
6900 points us to a place where a value of that type is passed.
6902 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6903 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6904 because in these cases DECL_INCOMING_RTL points us to a value of some
6905 type which is *different* from the type of the parameter itself. Thus,
6906 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6907 such cases, the debugger would end up (for example) trying to fetch a
6908 `float' from a place which actually contains the first part of a
6909 `double'. That would lead to really incorrect and confusing
6910 output at debug-time.
6912 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6913 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6914 are a couple of exceptions however. On little-endian machines we can
6915 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6916 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6917 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6918 when (on a little-endian machine) a non-prototyped function has a
6919 parameter declared to be of type `short' or `char'. In such cases,
6920 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6921 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6922 passed `int' value. If the debugger then uses that address to fetch
6923 a `short' or a `char' (on a little-endian machine) the result will be
6924 the correct data, so we allow for such exceptional cases below.
6926 Note that our goal here is to describe the place where the given formal
6927 parameter lives during most of the function's activation (i.e. between
6928 the end of the prologue and the start of the epilogue). We'll do that
6929 as best as we can. Note however that if the given formal parameter is
6930 modified sometime during the execution of the function, then a stack
6931 backtrace (at debug-time) will show the function as having been
6932 called with the *new* value rather than the value which was
6933 originally passed in. This happens rarely enough that it is not
6934 a major problem, but it *is* a problem, and I'd like to fix it.
6936 A future version of dwarf2out.c may generate two additional
6937 attributes for any given DW_TAG_formal_parameter DIE which will
6938 describe the "passed type" and the "passed location" for the
6939 given formal parameter in addition to the attributes we now
6940 generate to indicate the "declared type" and the "active
6941 location" for each parameter. This additional set of attributes
6942 could be used by debuggers for stack backtraces. Separately, note
6943 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6944 NULL also. This happens (for example) for inlined-instances of
6945 inline function formal parameters which are never referenced.
6946 This really shouldn't be happening. All PARM_DECL nodes should
6947 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6948 doesn't currently generate these values for inlined instances of
6949 inline function parameters, so when we see such cases, we are
6950 just out-of-luck for the time being (until integrate.c
6953 /* Use DECL_RTL as the "location" unless we find something better. */
6954 rtl = DECL_RTL (decl);
6956 if (TREE_CODE (decl) == PARM_DECL)
6958 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
6960 declared_type = type_main_variant (TREE_TYPE (decl));
6961 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
6963 /* This decl represents a formal parameter which was optimized out.
6964 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
6965 all* cases where (rtl == NULL_RTX) just below. */
6966 if (declared_type == passed_type)
6967 rtl = DECL_INCOMING_RTL (decl);
6968 else if (! BYTES_BIG_ENDIAN
6969 && TREE_CODE (declared_type) == INTEGER_TYPE
6970 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
6971 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
6972 rtl = DECL_INCOMING_RTL (decl);
6975 /* If the parm was passed in registers, but lives on the stack, then
6976 make a big endian correction if the mode of the type of the
6977 parameter is not the same as the mode of the rtl. */
6978 /* ??? This is the same series of checks that are made in dbxout.c before
6979 we reach the big endian correction code there. It isn't clear if all
6980 of these checks are necessary here, but keeping them all is the safe
6982 else if (GET_CODE (rtl) == MEM
6983 && XEXP (rtl, 0) != const0_rtx
6984 && ! CONSTANT_P (XEXP (rtl, 0))
6985 /* Not passed in memory. */
6986 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
6987 /* Not passed by invisible reference. */
6988 && (GET_CODE (XEXP (rtl, 0)) != REG
6989 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
6990 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
6991 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
6992 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
6995 /* Big endian correction check. */
6997 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
6998 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
7001 int offset = (UNITS_PER_WORD
7002 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
7003 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
7004 plus_constant (XEXP (rtl, 0), offset));
7008 if (rtl == NULL_RTX)
7011 rtl = eliminate_regs (rtl, 0, NULL_RTX);
7012 #ifdef LEAF_REG_REMAP
7013 if (current_function_uses_only_leaf_regs)
7014 leaf_renumber_regs_insn (rtl);
7017 switch (GET_CODE (rtl))
7020 /* The address of a variable that was optimized away; don't emit
7031 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7032 add_const_value_attribute (die, rtl);
7039 add_AT_location_description (die, DW_AT_location, rtl);
7047 /* Generate an DW_AT_name attribute given some string value to be included as
7048 the value of the attribute. */
7051 add_name_attribute (die, name_string)
7052 register dw_die_ref die;
7053 register const char *name_string;
7055 if (name_string != NULL && *name_string != 0)
7057 if (demangle_name_func)
7058 name_string = (*demangle_name_func) (name_string);
7060 add_AT_string (die, DW_AT_name, name_string);
7064 /* Given a tree node describing an array bound (either lower or upper) output
7065 a representation for that bound. */
7068 add_bound_info (subrange_die, bound_attr, bound)
7069 register dw_die_ref subrange_die;
7070 register enum dwarf_attribute bound_attr;
7071 register tree bound;
7073 register unsigned bound_value = 0;
7075 /* If this is an Ada unconstrained array type, then don't emit any debug
7076 info because the array bounds are unknown. They are parameterized when
7077 the type is instantiated. */
7078 if (contains_placeholder_p (bound))
7081 switch (TREE_CODE (bound))
7086 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7088 bound_value = TREE_INT_CST_LOW (bound);
7089 if (bound_attr == DW_AT_lower_bound
7090 && ((is_c_family () && bound_value == 0)
7091 || (is_fortran () && bound_value == 1)))
7092 /* use the default */;
7094 add_AT_unsigned (subrange_die, bound_attr, bound_value);
7099 case NON_LVALUE_EXPR:
7100 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7104 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7105 access the upper bound values may be bogus. If they refer to a
7106 register, they may only describe how to get at these values at the
7107 points in the generated code right after they have just been
7108 computed. Worse yet, in the typical case, the upper bound values
7109 will not even *be* computed in the optimized code (though the
7110 number of elements will), so these SAVE_EXPRs are entirely
7111 bogus. In order to compensate for this fact, we check here to see
7112 if optimization is enabled, and if so, we don't add an attribute
7113 for the (unknown and unknowable) upper bound. This should not
7114 cause too much trouble for existing (stupid?) debuggers because
7115 they have to deal with empty upper bounds location descriptions
7116 anyway in order to be able to deal with incomplete array types.
7117 Of course an intelligent debugger (GDB?) should be able to
7118 comprehend that a missing upper bound specification in a array
7119 type used for a storage class `auto' local array variable
7120 indicates that the upper bound is both unknown (at compile- time)
7121 and unknowable (at run-time) due to optimization.
7123 We assume that a MEM rtx is safe because gcc wouldn't put the
7124 value there unless it was going to be used repeatedly in the
7125 function, i.e. for cleanups. */
7126 if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)
7128 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7129 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7130 register rtx loc = SAVE_EXPR_RTL (bound);
7132 /* If the RTL for the SAVE_EXPR is memory, handle the case where
7133 it references an outer function's frame. */
7135 if (GET_CODE (loc) == MEM)
7137 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
7139 if (XEXP (loc, 0) != new_addr)
7140 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
7143 add_AT_flag (decl_die, DW_AT_artificial, 1);
7144 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
7145 add_AT_location_description (decl_die, DW_AT_location, loc);
7146 add_AT_die_ref (subrange_die, bound_attr, decl_die);
7149 /* Else leave out the attribute. */
7155 /* ??? These types of bounds can be created by the Ada front end,
7156 and it isn't clear how to emit debug info for them. */
7164 /* Note that the block of subscript information for an array type also
7165 includes information about the element type of type given array type. */
7168 add_subscript_info (type_die, type)
7169 register dw_die_ref type_die;
7172 #ifndef MIPS_DEBUGGING_INFO
7173 register unsigned dimension_number;
7175 register tree lower, upper;
7176 register dw_die_ref subrange_die;
7178 /* The GNU compilers represent multidimensional array types as sequences of
7179 one dimensional array types whose element types are themselves array
7180 types. Here we squish that down, so that each multidimensional array
7181 type gets only one array_type DIE in the Dwarf debugging info. The draft
7182 Dwarf specification say that we are allowed to do this kind of
7183 compression in C (because there is no difference between an array or
7184 arrays and a multidimensional array in C) but for other source languages
7185 (e.g. Ada) we probably shouldn't do this. */
7187 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7188 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7189 We work around this by disabling this feature. See also
7190 gen_array_type_die. */
7191 #ifndef MIPS_DEBUGGING_INFO
7192 for (dimension_number = 0;
7193 TREE_CODE (type) == ARRAY_TYPE;
7194 type = TREE_TYPE (type), dimension_number++)
7197 register tree domain = TYPE_DOMAIN (type);
7199 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7200 and (in GNU C only) variable bounds. Handle all three forms
7202 subrange_die = new_die (DW_TAG_subrange_type, type_die);
7205 /* We have an array type with specified bounds. */
7206 lower = TYPE_MIN_VALUE (domain);
7207 upper = TYPE_MAX_VALUE (domain);
7209 /* define the index type. */
7210 if (TREE_TYPE (domain))
7212 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7213 TREE_TYPE field. We can't emit debug info for this
7214 because it is an unnamed integral type. */
7215 if (TREE_CODE (domain) == INTEGER_TYPE
7216 && TYPE_NAME (domain) == NULL_TREE
7217 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
7218 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
7221 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
7225 /* ??? If upper is NULL, the array has unspecified length,
7226 but it does have a lower bound. This happens with Fortran
7228 Since the debugger is definitely going to need to know N
7229 to produce useful results, go ahead and output the lower
7230 bound solo, and hope the debugger can cope. */
7232 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
7234 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
7237 /* We have an array type with an unspecified length. The DWARF-2
7238 spec does not say how to handle this; let's just leave out the
7243 #ifndef MIPS_DEBUGGING_INFO
7249 add_byte_size_attribute (die, tree_node)
7251 register tree tree_node;
7253 register unsigned size;
7255 switch (TREE_CODE (tree_node))
7263 case QUAL_UNION_TYPE:
7264 size = int_size_in_bytes (tree_node);
7267 /* For a data member of a struct or union, the DW_AT_byte_size is
7268 generally given as the number of bytes normally allocated for an
7269 object of the *declared* type of the member itself. This is true
7270 even for bit-fields. */
7271 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
7277 /* Note that `size' might be -1 when we get to this point. If it is, that
7278 indicates that the byte size of the entity in question is variable. We
7279 have no good way of expressing this fact in Dwarf at the present time,
7280 so just let the -1 pass on through. */
7282 add_AT_unsigned (die, DW_AT_byte_size, size);
7285 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7286 which specifies the distance in bits from the highest order bit of the
7287 "containing object" for the bit-field to the highest order bit of the
7290 For any given bit-field, the "containing object" is a hypothetical
7291 object (of some integral or enum type) within which the given bit-field
7292 lives. The type of this hypothetical "containing object" is always the
7293 same as the declared type of the individual bit-field itself. The
7294 determination of the exact location of the "containing object" for a
7295 bit-field is rather complicated. It's handled by the
7296 `field_byte_offset' function (above).
7298 Note that it is the size (in bytes) of the hypothetical "containing object"
7299 which will be given in the DW_AT_byte_size attribute for this bit-field.
7300 (See `byte_size_attribute' above). */
7303 add_bit_offset_attribute (die, decl)
7304 register dw_die_ref die;
7307 register unsigned object_offset_in_bytes = field_byte_offset (decl);
7308 register tree type = DECL_BIT_FIELD_TYPE (decl);
7309 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
7310 register unsigned bitpos_int;
7311 register unsigned highest_order_object_bit_offset;
7312 register unsigned highest_order_field_bit_offset;
7313 register unsigned bit_offset;
7315 /* Must be a field and a bit field. */
7317 || TREE_CODE (decl) != FIELD_DECL)
7320 /* We can't yet handle bit-fields whose offsets are variable, so if we
7321 encounter such things, just return without generating any attribute
7323 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
7326 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
7328 /* Note that the bit offset is always the distance (in bits) from the
7329 highest-order bit of the "containing object" to the highest-order bit of
7330 the bit-field itself. Since the "high-order end" of any object or field
7331 is different on big-endian and little-endian machines, the computation
7332 below must take account of these differences. */
7333 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
7334 highest_order_field_bit_offset = bitpos_int;
7336 if (! BYTES_BIG_ENDIAN)
7338 highest_order_field_bit_offset
7339 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
7341 highest_order_object_bit_offset += simple_type_size_in_bits (type);
7345 = (! BYTES_BIG_ENDIAN
7346 ? highest_order_object_bit_offset - highest_order_field_bit_offset
7347 : highest_order_field_bit_offset - highest_order_object_bit_offset);
7349 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
7352 /* For a FIELD_DECL node which represents a bit field, output an attribute
7353 which specifies the length in bits of the given field. */
7356 add_bit_size_attribute (die, decl)
7357 register dw_die_ref die;
7360 /* Must be a field and a bit field. */
7361 if (TREE_CODE (decl) != FIELD_DECL
7362 || ! DECL_BIT_FIELD_TYPE (decl))
7364 add_AT_unsigned (die, DW_AT_bit_size,
7365 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
7368 /* If the compiled language is ANSI C, then add a 'prototyped'
7369 attribute, if arg types are given for the parameters of a function. */
7372 add_prototyped_attribute (die, func_type)
7373 register dw_die_ref die;
7374 register tree func_type;
7376 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
7377 && TYPE_ARG_TYPES (func_type) != NULL)
7378 add_AT_flag (die, DW_AT_prototyped, 1);
7382 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7383 by looking in either the type declaration or object declaration
7387 add_abstract_origin_attribute (die, origin)
7388 register dw_die_ref die;
7389 register tree origin;
7391 dw_die_ref origin_die = NULL;
7393 if (TREE_CODE (origin) != FUNCTION_DECL)
7395 /* We may have gotten separated from the block for the inlined
7396 function, if we're in an exception handler or some such; make
7397 sure that the abstract function has been written out.
7399 Doing this for nested functions is wrong, however; functions are
7400 distinct units, and our context might not even be inline. */
7401 tree fn = decl_function_context (origin);
7403 gen_abstract_function (fn);
7406 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
7407 origin_die = lookup_decl_die (origin);
7408 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
7409 origin_die = lookup_type_die (origin);
7411 if (origin_die == NULL)
7414 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
7417 /* We do not currently support the pure_virtual attribute. */
7420 add_pure_or_virtual_attribute (die, func_decl)
7421 register dw_die_ref die;
7422 register tree func_decl;
7424 if (DECL_VINDEX (func_decl))
7426 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7427 add_AT_loc (die, DW_AT_vtable_elem_location,
7428 new_loc_descr (DW_OP_constu,
7429 TREE_INT_CST_LOW (DECL_VINDEX (func_decl)),
7432 /* GNU extension: Record what type this method came from originally. */
7433 if (debug_info_level > DINFO_LEVEL_TERSE)
7434 add_AT_die_ref (die, DW_AT_containing_type,
7435 lookup_type_die (DECL_CONTEXT (func_decl)));
7439 /* Add source coordinate attributes for the given decl. */
7442 add_src_coords_attributes (die, decl)
7443 register dw_die_ref die;
7446 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
7448 add_AT_unsigned (die, DW_AT_decl_file, file_index);
7449 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7452 /* Add an DW_AT_name attribute and source coordinate attribute for the
7453 given decl, but only if it actually has a name. */
7456 add_name_and_src_coords_attributes (die, decl)
7457 register dw_die_ref die;
7460 register tree decl_name;
7462 decl_name = DECL_NAME (decl);
7463 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
7465 add_name_attribute (die, dwarf2_name (decl, 0));
7466 if (! DECL_ARTIFICIAL (decl))
7467 add_src_coords_attributes (die, decl);
7469 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
7470 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
7471 add_AT_string (die, DW_AT_MIPS_linkage_name,
7472 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
7476 /* Push a new declaration scope. */
7479 push_decl_scope (scope)
7482 /* Make room in the decl_scope_table, if necessary. */
7483 if (decl_scope_table_allocated == decl_scope_depth)
7485 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
7487 = (tree *) xrealloc (decl_scope_table,
7488 decl_scope_table_allocated * sizeof (tree));
7491 decl_scope_table[decl_scope_depth] = scope;
7495 /* Pop a declaration scope. */
7499 if (decl_scope_depth <= 0)
7504 /* Return the DIE for the scope that immediately contains this type.
7505 Non-named types get global scope. Named types nested in other
7506 types get their containing scope if it's open, or global scope
7507 otherwise. All other types (i.e. function-local named types) get
7508 the current active scope. */
7511 scope_die_for (t, context_die)
7513 register dw_die_ref context_die;
7515 register dw_die_ref scope_die = NULL;
7516 register tree containing_scope;
7519 /* Non-types always go in the current scope. */
7523 containing_scope = TYPE_CONTEXT (t);
7525 /* Ignore namespaces for the moment. */
7526 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
7527 containing_scope = NULL_TREE;
7529 /* Ignore function type "scopes" from the C frontend. They mean that
7530 a tagged type is local to a parmlist of a function declarator, but
7531 that isn't useful to DWARF. */
7532 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
7533 containing_scope = NULL_TREE;
7535 if (containing_scope == NULL_TREE)
7536 scope_die = comp_unit_die;
7537 else if (TYPE_P (containing_scope))
7539 /* For types, we can just look up the appropriate DIE. But
7540 first we check to see if we're in the middle of emitting it
7541 so we know where the new DIE should go. */
7543 for (i = decl_scope_depth - 1; i >= 0; --i)
7544 if (decl_scope_table[i] == containing_scope)
7549 if (debug_info_level > DINFO_LEVEL_TERSE
7550 && !TREE_ASM_WRITTEN (containing_scope))
7553 /* If none of the current dies are suitable, we get file scope. */
7554 scope_die = comp_unit_die;
7557 scope_die = lookup_type_die (containing_scope);
7560 scope_die = context_die;
7565 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
7567 static inline int local_scope_p PARAMS ((dw_die_ref));
7569 local_scope_p (context_die)
7570 dw_die_ref context_die;
7572 for (; context_die; context_die = context_die->die_parent)
7573 if (context_die->die_tag == DW_TAG_inlined_subroutine
7574 || context_die->die_tag == DW_TAG_subprogram)
7579 /* Returns nonzero iff CONTEXT_DIE is a class. */
7581 static inline int class_scope_p PARAMS ((dw_die_ref));
7583 class_scope_p (context_die)
7584 dw_die_ref context_die;
7587 && (context_die->die_tag == DW_TAG_structure_type
7588 || context_die->die_tag == DW_TAG_union_type));
7591 /* Many forms of DIEs require a "type description" attribute. This
7592 routine locates the proper "type descriptor" die for the type given
7593 by 'type', and adds an DW_AT_type attribute below the given die. */
7596 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
7597 register dw_die_ref object_die;
7599 register int decl_const;
7600 register int decl_volatile;
7601 register dw_die_ref context_die;
7603 register enum tree_code code = TREE_CODE (type);
7604 register dw_die_ref type_die = NULL;
7606 /* ??? If this type is an unnamed subrange type of an integral or
7607 floating-point type, use the inner type. This is because we have no
7608 support for unnamed types in base_type_die. This can happen if this is
7609 an Ada subrange type. Correct solution is emit a subrange type die. */
7610 if ((code == INTEGER_TYPE || code == REAL_TYPE)
7611 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
7612 type = TREE_TYPE (type), code = TREE_CODE (type);
7614 if (code == ERROR_MARK)
7617 /* Handle a special case. For functions whose return type is void, we
7618 generate *no* type attribute. (Note that no object may have type
7619 `void', so this only applies to function return types). */
7620 if (code == VOID_TYPE)
7623 type_die = modified_type_die (type,
7624 decl_const || TYPE_READONLY (type),
7625 decl_volatile || TYPE_VOLATILE (type),
7627 if (type_die != NULL)
7628 add_AT_die_ref (object_die, DW_AT_type, type_die);
7631 /* Given a tree pointer to a struct, class, union, or enum type node, return
7632 a pointer to the (string) tag name for the given type, or zero if the type
7633 was declared without a tag. */
7639 register char *name = 0;
7641 if (TYPE_NAME (type) != 0)
7643 register tree t = 0;
7645 /* Find the IDENTIFIER_NODE for the type name. */
7646 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7647 t = TYPE_NAME (type);
7649 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7650 a TYPE_DECL node, regardless of whether or not a `typedef' was
7652 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7653 && ! DECL_IGNORED_P (TYPE_NAME (type)))
7654 t = DECL_NAME (TYPE_NAME (type));
7656 /* Now get the name as a string, or invent one. */
7658 name = IDENTIFIER_POINTER (t);
7661 return (name == 0 || *name == '\0') ? 0 : name;
7664 /* Return the type associated with a data member, make a special check
7665 for bit field types. */
7668 member_declared_type (member)
7669 register tree member;
7671 return (DECL_BIT_FIELD_TYPE (member)
7672 ? DECL_BIT_FIELD_TYPE (member)
7673 : TREE_TYPE (member));
7676 /* Get the decl's label, as described by its RTL. This may be different
7677 from the DECL_NAME name used in the source file. */
7681 decl_start_label (decl)
7686 x = DECL_RTL (decl);
7687 if (GET_CODE (x) != MEM)
7691 if (GET_CODE (x) != SYMBOL_REF)
7694 fnname = XSTR (x, 0);
7699 /* These routines generate the internal representation of the DIE's for
7700 the compilation unit. Debugging information is collected by walking
7701 the declaration trees passed in from dwarf2out_decl(). */
7704 gen_array_type_die (type, context_die)
7706 register dw_die_ref context_die;
7708 register dw_die_ref scope_die = scope_die_for (type, context_die);
7709 register dw_die_ref array_die;
7710 register tree element_type;
7712 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7713 the inner array type comes before the outer array type. Thus we must
7714 call gen_type_die before we call new_die. See below also. */
7715 #ifdef MIPS_DEBUGGING_INFO
7716 gen_type_die (TREE_TYPE (type), context_die);
7719 array_die = new_die (DW_TAG_array_type, scope_die);
7722 /* We default the array ordering. SDB will probably do
7723 the right things even if DW_AT_ordering is not present. It's not even
7724 an issue until we start to get into multidimensional arrays anyway. If
7725 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7726 then we'll have to put the DW_AT_ordering attribute back in. (But if
7727 and when we find out that we need to put these in, we will only do so
7728 for multidimensional arrays. */
7729 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
7732 #ifdef MIPS_DEBUGGING_INFO
7733 /* The SGI compilers handle arrays of unknown bound by setting
7734 AT_declaration and not emitting any subrange DIEs. */
7735 if (! TYPE_DOMAIN (type))
7736 add_AT_unsigned (array_die, DW_AT_declaration, 1);
7739 add_subscript_info (array_die, type);
7741 add_name_attribute (array_die, type_tag (type));
7742 equate_type_number_to_die (type, array_die);
7744 /* Add representation of the type of the elements of this array type. */
7745 element_type = TREE_TYPE (type);
7747 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7748 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7749 We work around this by disabling this feature. See also
7750 add_subscript_info. */
7751 #ifndef MIPS_DEBUGGING_INFO
7752 while (TREE_CODE (element_type) == ARRAY_TYPE)
7753 element_type = TREE_TYPE (element_type);
7755 gen_type_die (element_type, context_die);
7758 add_type_attribute (array_die, element_type, 0, 0, context_die);
7762 gen_set_type_die (type, context_die)
7764 register dw_die_ref context_die;
7766 register dw_die_ref type_die
7767 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7769 equate_type_number_to_die (type, type_die);
7770 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7775 gen_entry_point_die (decl, context_die)
7777 register dw_die_ref context_die;
7779 register tree origin = decl_ultimate_origin (decl);
7780 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
7782 add_abstract_origin_attribute (decl_die, origin);
7785 add_name_and_src_coords_attributes (decl_die, decl);
7786 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
7790 if (DECL_ABSTRACT (decl))
7791 equate_decl_number_to_die (decl, decl_die);
7793 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
7797 /* Remember a type in the incomplete_types_list. */
7800 add_incomplete_type (type)
7803 if (incomplete_types == incomplete_types_allocated)
7805 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
7806 incomplete_types_list
7807 = (tree *) xrealloc (incomplete_types_list,
7808 sizeof (tree) * incomplete_types_allocated);
7811 incomplete_types_list[incomplete_types++] = type;
7814 /* Walk through the list of incomplete types again, trying once more to
7815 emit full debugging info for them. */
7818 retry_incomplete_types ()
7822 while (incomplete_types)
7825 type = incomplete_types_list[incomplete_types];
7826 gen_type_die (type, comp_unit_die);
7830 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7833 gen_inlined_enumeration_type_die (type, context_die)
7835 register dw_die_ref context_die;
7837 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
7839 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7840 be incomplete and such types are not marked. */
7841 add_abstract_origin_attribute (type_die, type);
7844 /* Generate a DIE to represent an inlined instance of a structure type. */
7847 gen_inlined_structure_type_die (type, context_die)
7849 register dw_die_ref context_die;
7851 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
7853 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7854 be incomplete and such types are not marked. */
7855 add_abstract_origin_attribute (type_die, type);
7858 /* Generate a DIE to represent an inlined instance of a union type. */
7861 gen_inlined_union_type_die (type, context_die)
7863 register dw_die_ref context_die;
7865 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
7867 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7868 be incomplete and such types are not marked. */
7869 add_abstract_origin_attribute (type_die, type);
7872 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7873 include all of the information about the enumeration values also. Each
7874 enumerated type name/value is listed as a child of the enumerated type
7878 gen_enumeration_type_die (type, context_die)
7880 register dw_die_ref context_die;
7882 register dw_die_ref type_die = lookup_type_die (type);
7884 if (type_die == NULL)
7886 type_die = new_die (DW_TAG_enumeration_type,
7887 scope_die_for (type, context_die));
7888 equate_type_number_to_die (type, type_die);
7889 add_name_attribute (type_die, type_tag (type));
7891 else if (! TYPE_SIZE (type))
7894 remove_AT (type_die, DW_AT_declaration);
7896 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7897 given enum type is incomplete, do not generate the DW_AT_byte_size
7898 attribute or the DW_AT_element_list attribute. */
7899 if (TYPE_SIZE (type))
7903 TREE_ASM_WRITTEN (type) = 1;
7904 add_byte_size_attribute (type_die, type);
7905 if (TYPE_STUB_DECL (type) != NULL_TREE)
7906 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
7908 /* If the first reference to this type was as the return type of an
7909 inline function, then it may not have a parent. Fix this now. */
7910 if (type_die->die_parent == NULL)
7911 add_child_die (scope_die_for (type, context_die), type_die);
7913 for (link = TYPE_FIELDS (type);
7914 link != NULL; link = TREE_CHAIN (link))
7916 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
7918 add_name_attribute (enum_die,
7919 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
7920 add_AT_unsigned (enum_die, DW_AT_const_value,
7921 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
7925 add_AT_flag (type_die, DW_AT_declaration, 1);
7929 /* Generate a DIE to represent either a real live formal parameter decl or to
7930 represent just the type of some formal parameter position in some function
7933 Note that this routine is a bit unusual because its argument may be a
7934 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7935 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7936 node. If it's the former then this function is being called to output a
7937 DIE to represent a formal parameter object (or some inlining thereof). If
7938 it's the latter, then this function is only being called to output a
7939 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7940 argument type of some subprogram type. */
7943 gen_formal_parameter_die (node, context_die)
7945 register dw_die_ref context_die;
7947 register dw_die_ref parm_die
7948 = new_die (DW_TAG_formal_parameter, context_die);
7949 register tree origin;
7951 switch (TREE_CODE_CLASS (TREE_CODE (node)))
7954 origin = decl_ultimate_origin (node);
7956 add_abstract_origin_attribute (parm_die, origin);
7959 add_name_and_src_coords_attributes (parm_die, node);
7960 add_type_attribute (parm_die, TREE_TYPE (node),
7961 TREE_READONLY (node),
7962 TREE_THIS_VOLATILE (node),
7964 if (DECL_ARTIFICIAL (node))
7965 add_AT_flag (parm_die, DW_AT_artificial, 1);
7968 equate_decl_number_to_die (node, parm_die);
7969 if (! DECL_ABSTRACT (node))
7970 add_location_or_const_value_attribute (parm_die, node);
7975 /* We were called with some kind of a ..._TYPE node. */
7976 add_type_attribute (parm_die, node, 0, 0, context_die);
7986 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
7987 at the end of an (ANSI prototyped) formal parameters list. */
7990 gen_unspecified_parameters_die (decl_or_type, context_die)
7991 register tree decl_or_type ATTRIBUTE_UNUSED;
7992 register dw_die_ref context_die;
7994 new_die (DW_TAG_unspecified_parameters, context_die);
7997 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
7998 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
7999 parameters as specified in some function type specification (except for
8000 those which appear as part of a function *definition*).
8002 Note we must be careful here to output all of the parameter DIEs before*
8003 we output any DIEs needed to represent the types of the formal parameters.
8004 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
8005 non-parameter DIE it sees ends the formal parameter list. */
8008 gen_formal_types_die (function_or_method_type, context_die)
8009 register tree function_or_method_type;
8010 register dw_die_ref context_die;
8013 register tree formal_type = NULL;
8014 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
8017 /* In the case where we are generating a formal types list for a C++
8018 non-static member function type, skip over the first thing on the
8019 TYPE_ARG_TYPES list because it only represents the type of the hidden
8020 `this pointer'. The debugger should be able to figure out (without
8021 being explicitly told) that this non-static member function type takes a
8022 `this pointer' and should be able to figure what the type of that hidden
8023 parameter is from the DW_AT_member attribute of the parent
8024 DW_TAG_subroutine_type DIE. */
8025 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
8026 first_parm_type = TREE_CHAIN (first_parm_type);
8029 /* Make our first pass over the list of formal parameter types and output a
8030 DW_TAG_formal_parameter DIE for each one. */
8031 for (link = first_parm_type; link; link = TREE_CHAIN (link))
8033 register dw_die_ref parm_die;
8035 formal_type = TREE_VALUE (link);
8036 if (formal_type == void_type_node)
8039 /* Output a (nameless) DIE to represent the formal parameter itself. */
8040 parm_die = gen_formal_parameter_die (formal_type, context_die);
8041 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8042 && link == first_parm_type)
8043 add_AT_flag (parm_die, DW_AT_artificial, 1);
8046 /* If this function type has an ellipsis, add a
8047 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8048 if (formal_type != void_type_node)
8049 gen_unspecified_parameters_die (function_or_method_type, context_die);
8051 /* Make our second (and final) pass over the list of formal parameter types
8052 and output DIEs to represent those types (as necessary). */
8053 for (link = TYPE_ARG_TYPES (function_or_method_type);
8055 link = TREE_CHAIN (link))
8057 formal_type = TREE_VALUE (link);
8058 if (formal_type == void_type_node)
8061 gen_type_die (formal_type, context_die);
8065 /* We want to generate the DIE for TYPE so that we can generate the
8066 die for MEMBER, which has been defined; we will need to refer back
8067 to the member declaration nested within TYPE. If we're trying to
8068 generate minimal debug info for TYPE, processing TYPE won't do the
8069 trick; we need to attach the member declaration by hand. */
8072 gen_type_die_for_member (type, member, context_die)
8074 dw_die_ref context_die;
8076 gen_type_die (type, context_die);
8078 /* If we're trying to avoid duplicate debug info, we may not have
8079 emitted the member decl for this function. Emit it now. */
8080 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
8081 && ! lookup_decl_die (member))
8083 if (decl_ultimate_origin (member))
8086 push_decl_scope (type);
8087 if (TREE_CODE (member) == FUNCTION_DECL)
8088 gen_subprogram_die (member, lookup_type_die (type));
8090 gen_variable_die (member, lookup_type_die (type));
8095 /* Generate the DWARF2 info for the "abstract" instance
8096 of a function which we may later generate inlined and/or
8097 out-of-line instances of. */
8100 gen_abstract_function (decl)
8103 register dw_die_ref old_die = lookup_decl_die (decl);
8106 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
8107 /* We've already generated the abstract instance. */
8110 save_fn = current_function_decl;
8111 current_function_decl = decl;
8113 set_decl_abstract_flags (decl, 1);
8114 dwarf2out_decl (decl);
8115 set_decl_abstract_flags (decl, 0);
8117 current_function_decl = save_fn;
8120 /* Generate a DIE to represent a declared function (either file-scope or
8124 gen_subprogram_die (decl, context_die)
8126 register dw_die_ref context_die;
8128 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
8129 register tree origin = decl_ultimate_origin (decl);
8130 register dw_die_ref subr_die;
8131 register rtx fp_reg;
8132 register tree fn_arg_types;
8133 register tree outer_scope;
8134 register dw_die_ref old_die = lookup_decl_die (decl);
8135 register int declaration = (current_function_decl != decl
8136 || class_scope_p (context_die));
8138 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
8139 be true, if we started to generate the abstract instance of an inline,
8140 decided to output its containing class, and proceeded to emit the
8141 declaration of the inline from the member list for the class. In that
8142 case, `declaration' takes priority; we'll get back to the abstract
8143 instance when we're done with the class. */
8147 if (declaration && ! local_scope_p (context_die))
8150 subr_die = new_die (DW_TAG_subprogram, context_die);
8151 add_abstract_origin_attribute (subr_die, origin);
8153 else if (old_die && DECL_ABSTRACT (decl)
8154 && get_AT_unsigned (old_die, DW_AT_inline))
8156 /* This must be a redefinition of an extern inline function.
8157 We can just reuse the old die here. */
8160 /* Clear out the inlined attribute and parm types. */
8161 remove_AT (subr_die, DW_AT_inline);
8162 remove_children (subr_die);
8166 register unsigned file_index
8167 = lookup_filename (DECL_SOURCE_FILE (decl));
8169 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
8171 /* ??? This can happen if there is a bug in the program, for
8172 instance, if it has duplicate function definitions. Ideally,
8173 we should detect this case and ignore it. For now, if we have
8174 already reported an error, any error at all, then assume that
8175 we got here because of a input error, not a dwarf2 bug. */
8181 /* If the definition comes from the same place as the declaration,
8182 maybe use the old DIE. We always want the DIE for this function
8183 that has the *_pc attributes to be under comp_unit_die so the
8184 debugger can find it. For inlines, that is the concrete instance,
8185 so we can use the old DIE here. For non-inline methods, we want a
8186 specification DIE at toplevel, so we need a new DIE. For local
8187 class methods, this doesn't apply; we just use the old DIE. */
8188 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
8189 || context_die == NULL)
8190 && (DECL_ARTIFICIAL (decl)
8191 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
8192 && (get_AT_unsigned (old_die, DW_AT_decl_line)
8193 == (unsigned)DECL_SOURCE_LINE (decl)))))
8197 /* Clear out the declaration attribute and the parm types. */
8198 remove_AT (subr_die, DW_AT_declaration);
8199 remove_children (subr_die);
8203 subr_die = new_die (DW_TAG_subprogram, context_die);
8204 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
8205 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8206 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
8207 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8208 != (unsigned)DECL_SOURCE_LINE (decl))
8210 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8215 subr_die = new_die (DW_TAG_subprogram, context_die);
8217 if (TREE_PUBLIC (decl))
8218 add_AT_flag (subr_die, DW_AT_external, 1);
8220 add_name_and_src_coords_attributes (subr_die, decl);
8221 if (debug_info_level > DINFO_LEVEL_TERSE)
8223 register tree type = TREE_TYPE (decl);
8225 add_prototyped_attribute (subr_die, type);
8226 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
8229 add_pure_or_virtual_attribute (subr_die, decl);
8230 if (DECL_ARTIFICIAL (decl))
8231 add_AT_flag (subr_die, DW_AT_artificial, 1);
8232 if (TREE_PROTECTED (decl))
8233 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
8234 else if (TREE_PRIVATE (decl))
8235 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
8241 add_AT_flag (subr_die, DW_AT_declaration, 1);
8243 /* The first time we see a member function, it is in the context of
8244 the class to which it belongs. We make sure of this by emitting
8245 the class first. The next time is the definition, which is
8246 handled above. The two may come from the same source text. */
8247 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
8248 equate_decl_number_to_die (decl, subr_die);
8250 else if (DECL_ABSTRACT (decl))
8252 if (DECL_INLINE (decl) && !flag_no_inline)
8254 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
8255 inline functions, but not for extern inline functions.
8256 We can't get this completely correct because information
8257 about whether the function was declared inline is not
8259 if (DECL_DEFER_OUTPUT (decl))
8260 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
8262 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
8265 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
8267 equate_decl_number_to_die (decl, subr_die);
8269 else if (!DECL_EXTERNAL (decl))
8271 if (origin == NULL_TREE)
8272 equate_decl_number_to_die (decl, subr_die);
8274 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
8275 current_funcdef_number);
8276 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
8277 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
8278 current_funcdef_number);
8279 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
8281 add_pubname (decl, subr_die);
8282 add_arange (decl, subr_die);
8284 #ifdef MIPS_DEBUGGING_INFO
8285 /* Add a reference to the FDE for this routine. */
8286 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
8289 /* Define the "frame base" location for this routine. We use the
8290 frame pointer or stack pointer registers, since the RTL for local
8291 variables is relative to one of them. */
8293 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
8294 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
8297 /* ??? This fails for nested inline functions, because context_display
8298 is not part of the state saved/restored for inline functions. */
8299 if (current_function_needs_context)
8300 add_AT_location_description (subr_die, DW_AT_static_link,
8301 lookup_static_chain (decl));
8305 /* Now output descriptions of the arguments for this function. This gets
8306 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8307 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8308 `...' at the end of the formal parameter list. In order to find out if
8309 there was a trailing ellipsis or not, we must instead look at the type
8310 associated with the FUNCTION_DECL. This will be a node of type
8311 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8312 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8313 an ellipsis at the end. */
8315 /* In the case where we are describing a mere function declaration, all we
8316 need to do here (and all we *can* do here) is to describe the *types* of
8317 its formal parameters. */
8318 if (debug_info_level <= DINFO_LEVEL_TERSE)
8320 else if (declaration)
8321 gen_formal_types_die (TREE_TYPE (decl), subr_die);
8324 /* Generate DIEs to represent all known formal parameters */
8325 register tree arg_decls = DECL_ARGUMENTS (decl);
8328 /* When generating DIEs, generate the unspecified_parameters DIE
8329 instead if we come across the arg "__builtin_va_alist" */
8330 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
8331 if (TREE_CODE (parm) == PARM_DECL)
8333 if (DECL_NAME (parm)
8334 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
8335 "__builtin_va_alist"))
8336 gen_unspecified_parameters_die (parm, subr_die);
8338 gen_decl_die (parm, subr_die);
8341 /* Decide whether we need a unspecified_parameters DIE at the end.
8342 There are 2 more cases to do this for: 1) the ansi ... declaration -
8343 this is detectable when the end of the arg list is not a
8344 void_type_node 2) an unprototyped function declaration (not a
8345 definition). This just means that we have no info about the
8346 parameters at all. */
8347 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
8348 if (fn_arg_types != NULL)
8350 /* this is the prototyped case, check for ... */
8351 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
8352 gen_unspecified_parameters_die (decl, subr_die);
8354 else if (DECL_INITIAL (decl) == NULL_TREE)
8355 gen_unspecified_parameters_die (decl, subr_die);
8358 /* Output Dwarf info for all of the stuff within the body of the function
8359 (if it has one - it may be just a declaration). */
8360 outer_scope = DECL_INITIAL (decl);
8362 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8363 node created to represent a function. This outermost BLOCK actually
8364 represents the outermost binding contour for the function, i.e. the
8365 contour in which the function's formal parameters and labels get
8366 declared. Curiously, it appears that the front end doesn't actually
8367 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8368 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8369 list for the function instead.) The BLOCK_VARS list for the
8370 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8371 the function however, and we output DWARF info for those in
8372 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8373 node representing the function's outermost pair of curly braces, and
8374 any blocks used for the base and member initializers of a C++
8375 constructor function. */
8376 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
8378 current_function_has_inlines = 0;
8379 decls_for_scope (outer_scope, subr_die, 0);
8381 #if 0 && defined (MIPS_DEBUGGING_INFO)
8382 if (current_function_has_inlines)
8384 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
8385 if (! comp_unit_has_inlines)
8387 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
8388 comp_unit_has_inlines = 1;
8395 /* Generate a DIE to represent a declared data object. */
8398 gen_variable_die (decl, context_die)
8400 register dw_die_ref context_die;
8402 register tree origin = decl_ultimate_origin (decl);
8403 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
8405 dw_die_ref old_die = lookup_decl_die (decl);
8406 int declaration = (DECL_EXTERNAL (decl)
8407 || class_scope_p (context_die));
8410 add_abstract_origin_attribute (var_die, origin);
8411 /* Loop unrolling can create multiple blocks that refer to the same
8412 static variable, so we must test for the DW_AT_declaration flag. */
8413 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8414 copy decls and set the DECL_ABSTRACT flag on them instead of
8416 else if (old_die && TREE_STATIC (decl)
8417 && get_AT_flag (old_die, DW_AT_declaration) == 1)
8419 /* This is a definition of a C++ class level static. */
8420 add_AT_die_ref (var_die, DW_AT_specification, old_die);
8421 if (DECL_NAME (decl))
8423 register unsigned file_index
8424 = lookup_filename (DECL_SOURCE_FILE (decl));
8426 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8427 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
8429 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8430 != (unsigned)DECL_SOURCE_LINE (decl))
8432 add_AT_unsigned (var_die, DW_AT_decl_line,
8433 DECL_SOURCE_LINE (decl));
8438 add_name_and_src_coords_attributes (var_die, decl);
8439 add_type_attribute (var_die, TREE_TYPE (decl),
8440 TREE_READONLY (decl),
8441 TREE_THIS_VOLATILE (decl), context_die);
8443 if (TREE_PUBLIC (decl))
8444 add_AT_flag (var_die, DW_AT_external, 1);
8446 if (DECL_ARTIFICIAL (decl))
8447 add_AT_flag (var_die, DW_AT_artificial, 1);
8449 if (TREE_PROTECTED (decl))
8450 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
8452 else if (TREE_PRIVATE (decl))
8453 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
8457 add_AT_flag (var_die, DW_AT_declaration, 1);
8459 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
8460 equate_decl_number_to_die (decl, var_die);
8462 if (! declaration && ! DECL_ABSTRACT (decl))
8464 add_location_or_const_value_attribute (var_die, decl);
8465 add_pubname (decl, var_die);
8469 /* Generate a DIE to represent a label identifier. */
8472 gen_label_die (decl, context_die)
8474 register dw_die_ref context_die;
8476 register tree origin = decl_ultimate_origin (decl);
8477 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
8479 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8480 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
8483 add_abstract_origin_attribute (lbl_die, origin);
8485 add_name_and_src_coords_attributes (lbl_die, decl);
8487 if (DECL_ABSTRACT (decl))
8488 equate_decl_number_to_die (decl, lbl_die);
8491 insn = DECL_RTL (decl);
8493 /* Deleted labels are programmer specified labels which have been
8494 eliminated because of various optimisations. We still emit them
8495 here so that it is possible to put breakpoints on them. */
8496 if (GET_CODE (insn) == CODE_LABEL
8497 || ((GET_CODE (insn) == NOTE
8498 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
8500 /* When optimization is enabled (via -O) some parts of the compiler
8501 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8502 represent source-level labels which were explicitly declared by
8503 the user. This really shouldn't be happening though, so catch
8504 it if it ever does happen. */
8505 if (INSN_DELETED_P (insn))
8508 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
8509 ASM_GENERATE_INTERNAL_LABEL (label, label2,
8510 (unsigned) INSN_UID (insn));
8511 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
8516 /* Generate a DIE for a lexical block. */
8519 gen_lexical_block_die (stmt, context_die, depth)
8521 register dw_die_ref context_die;
8524 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
8525 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8527 if (! BLOCK_ABSTRACT (stmt))
8529 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8530 BLOCK_NUMBER (stmt));
8531 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
8532 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
8533 BLOCK_NUMBER (stmt));
8534 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
8537 decls_for_scope (stmt, stmt_die, depth);
8540 /* Generate a DIE for an inlined subprogram. */
8543 gen_inlined_subroutine_die (stmt, context_die, depth)
8545 register dw_die_ref context_die;
8548 if (! BLOCK_ABSTRACT (stmt))
8550 register dw_die_ref subr_die
8551 = new_die (DW_TAG_inlined_subroutine, context_die);
8552 register tree decl = block_ultimate_origin (stmt);
8553 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8555 /* Emit info for the abstract instance first, if we haven't yet. */
8556 gen_abstract_function (decl);
8558 add_abstract_origin_attribute (subr_die, decl);
8559 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8560 BLOCK_NUMBER (stmt));
8561 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
8562 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
8563 BLOCK_NUMBER (stmt));
8564 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
8565 decls_for_scope (stmt, subr_die, depth);
8566 current_function_has_inlines = 1;
8570 /* Generate a DIE for a field in a record, or structure. */
8573 gen_field_die (decl, context_die)
8575 register dw_die_ref context_die;
8577 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
8579 add_name_and_src_coords_attributes (decl_die, decl);
8580 add_type_attribute (decl_die, member_declared_type (decl),
8581 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
8584 /* If this is a bit field... */
8585 if (DECL_BIT_FIELD_TYPE (decl))
8587 add_byte_size_attribute (decl_die, decl);
8588 add_bit_size_attribute (decl_die, decl);
8589 add_bit_offset_attribute (decl_die, decl);
8592 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
8593 add_data_member_location_attribute (decl_die, decl);
8595 if (DECL_ARTIFICIAL (decl))
8596 add_AT_flag (decl_die, DW_AT_artificial, 1);
8598 if (TREE_PROTECTED (decl))
8599 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
8601 else if (TREE_PRIVATE (decl))
8602 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
8606 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8607 Use modified_type_die instead.
8608 We keep this code here just in case these types of DIEs may be needed to
8609 represent certain things in other languages (e.g. Pascal) someday. */
8611 gen_pointer_type_die (type, context_die)
8613 register dw_die_ref context_die;
8615 register dw_die_ref ptr_die
8616 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
8618 equate_type_number_to_die (type, ptr_die);
8619 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8620 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8623 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8624 Use modified_type_die instead.
8625 We keep this code here just in case these types of DIEs may be needed to
8626 represent certain things in other languages (e.g. Pascal) someday. */
8628 gen_reference_type_die (type, context_die)
8630 register dw_die_ref context_die;
8632 register dw_die_ref ref_die
8633 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
8635 equate_type_number_to_die (type, ref_die);
8636 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
8637 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8641 /* Generate a DIE for a pointer to a member type. */
8643 gen_ptr_to_mbr_type_die (type, context_die)
8645 register dw_die_ref context_die;
8647 register dw_die_ref ptr_die
8648 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8650 equate_type_number_to_die (type, ptr_die);
8651 add_AT_die_ref (ptr_die, DW_AT_containing_type,
8652 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
8653 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8656 /* Generate the DIE for the compilation unit. */
8659 gen_compile_unit_die (filename)
8660 register const char *filename;
8662 register dw_die_ref die;
8664 char *wd = getpwd ();
8667 die = new_die (DW_TAG_compile_unit, NULL);
8668 add_name_attribute (die, filename);
8670 if (wd != NULL && filename[0] != DIR_SEPARATOR)
8671 add_AT_string (die, DW_AT_comp_dir, wd);
8673 sprintf (producer, "%s %s", language_string, version_string);
8675 #ifdef MIPS_DEBUGGING_INFO
8676 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8677 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8678 not appear in the producer string, the debugger reaches the conclusion
8679 that the object file is stripped and has no debugging information.
8680 To get the MIPS/SGI debugger to believe that there is debugging
8681 information in the object file, we add a -g to the producer string. */
8682 if (debug_info_level > DINFO_LEVEL_TERSE)
8683 strcat (producer, " -g");
8686 add_AT_string (die, DW_AT_producer, producer);
8688 if (strcmp (language_string, "GNU C++") == 0)
8689 language = DW_LANG_C_plus_plus;
8690 else if (strcmp (language_string, "GNU Ada") == 0)
8691 language = DW_LANG_Ada83;
8692 else if (strcmp (language_string, "GNU F77") == 0)
8693 language = DW_LANG_Fortran77;
8694 else if (strcmp (language_string, "GNU Pascal") == 0)
8695 language = DW_LANG_Pascal83;
8696 else if (flag_traditional)
8697 language = DW_LANG_C;
8699 language = DW_LANG_C89;
8701 add_AT_unsigned (die, DW_AT_language, language);
8706 /* Generate a DIE for a string type. */
8709 gen_string_type_die (type, context_die)
8711 register dw_die_ref context_die;
8713 register dw_die_ref type_die
8714 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
8716 equate_type_number_to_die (type, type_die);
8718 /* Fudge the string length attribute for now. */
8720 /* TODO: add string length info.
8721 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8722 bound_representation (upper_bound, 0, 'u'); */
8725 /* Generate the DIE for a base class. */
8728 gen_inheritance_die (binfo, context_die)
8729 register tree binfo;
8730 register dw_die_ref context_die;
8732 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
8734 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
8735 add_data_member_location_attribute (die, binfo);
8737 if (TREE_VIA_VIRTUAL (binfo))
8738 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8739 if (TREE_VIA_PUBLIC (binfo))
8740 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
8741 else if (TREE_VIA_PROTECTED (binfo))
8742 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
8745 /* Generate a DIE for a class member. */
8748 gen_member_die (type, context_die)
8750 register dw_die_ref context_die;
8752 register tree member;
8755 /* If this is not an incomplete type, output descriptions of each of its
8756 members. Note that as we output the DIEs necessary to represent the
8757 members of this record or union type, we will also be trying to output
8758 DIEs to represent the *types* of those members. However the `type'
8759 function (above) will specifically avoid generating type DIEs for member
8760 types *within* the list of member DIEs for this (containing) type execpt
8761 for those types (of members) which are explicitly marked as also being
8762 members of this (containing) type themselves. The g++ front- end can
8763 force any given type to be treated as a member of some other
8764 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8765 to point to the TREE node representing the appropriate (containing)
8768 /* First output info about the base classes. */
8769 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
8771 register tree bases = TYPE_BINFO_BASETYPES (type);
8772 register int n_bases = TREE_VEC_LENGTH (bases);
8775 for (i = 0; i < n_bases; i++)
8776 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
8779 /* Now output info about the data members and type members. */
8780 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
8782 /* If we thought we were generating minimal debug info for TYPE
8783 and then changed our minds, some of the member declarations
8784 may have already been defined. Don't define them again, but
8785 do put them in the right order. */
8787 child = lookup_decl_die (member);
8789 splice_child_die (context_die, child);
8791 gen_decl_die (member, context_die);
8794 /* Now output info about the function members (if any). */
8795 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
8797 child = lookup_decl_die (member);
8799 splice_child_die (context_die, child);
8801 gen_decl_die (member, context_die);
8805 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
8806 is set, we pretend that the type was never defined, so we only get the
8807 member DIEs needed by later specification DIEs. */
8810 gen_struct_or_union_type_die (type, context_die)
8812 register dw_die_ref context_die;
8814 register dw_die_ref type_die = lookup_type_die (type);
8815 register dw_die_ref scope_die = 0;
8816 register int nested = 0;
8817 int complete = (TYPE_SIZE (type)
8818 && (! TYPE_STUB_DECL (type)
8819 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
8821 if (type_die && ! complete)
8824 if (TYPE_CONTEXT (type) != NULL_TREE
8825 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
8828 scope_die = scope_die_for (type, context_die);
8830 if (! type_die || (nested && scope_die == comp_unit_die))
8831 /* First occurrence of type or toplevel definition of nested class. */
8833 register dw_die_ref old_die = type_die;
8835 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
8836 ? DW_TAG_structure_type : DW_TAG_union_type,
8838 equate_type_number_to_die (type, type_die);
8839 add_name_attribute (type_die, type_tag (type));
8841 add_AT_die_ref (type_die, DW_AT_specification, old_die);
8844 remove_AT (type_die, DW_AT_declaration);
8846 /* If this type has been completed, then give it a byte_size attribute and
8847 then give a list of members. */
8850 /* Prevent infinite recursion in cases where the type of some member of
8851 this type is expressed in terms of this type itself. */
8852 TREE_ASM_WRITTEN (type) = 1;
8853 add_byte_size_attribute (type_die, type);
8854 if (TYPE_STUB_DECL (type) != NULL_TREE)
8855 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8857 /* If the first reference to this type was as the return type of an
8858 inline function, then it may not have a parent. Fix this now. */
8859 if (type_die->die_parent == NULL)
8860 add_child_die (scope_die, type_die);
8862 push_decl_scope (type);
8863 gen_member_die (type, type_die);
8866 /* GNU extension: Record what type our vtable lives in. */
8867 if (TYPE_VFIELD (type))
8869 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
8871 gen_type_die (vtype, context_die);
8872 add_AT_die_ref (type_die, DW_AT_containing_type,
8873 lookup_type_die (vtype));
8878 add_AT_flag (type_die, DW_AT_declaration, 1);
8880 /* We don't need to do this for function-local types. */
8881 if (! decl_function_context (TYPE_STUB_DECL (type)))
8882 add_incomplete_type (type);
8886 /* Generate a DIE for a subroutine _type_. */
8889 gen_subroutine_type_die (type, context_die)
8891 register dw_die_ref context_die;
8893 register tree return_type = TREE_TYPE (type);
8894 register dw_die_ref subr_die
8895 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
8897 equate_type_number_to_die (type, subr_die);
8898 add_prototyped_attribute (subr_die, type);
8899 add_type_attribute (subr_die, return_type, 0, 0, context_die);
8900 gen_formal_types_die (type, subr_die);
8903 /* Generate a DIE for a type definition */
8906 gen_typedef_die (decl, context_die)
8908 register dw_die_ref context_die;
8910 register dw_die_ref type_die;
8911 register tree origin;
8913 if (TREE_ASM_WRITTEN (decl))
8915 TREE_ASM_WRITTEN (decl) = 1;
8917 type_die = new_die (DW_TAG_typedef, context_die);
8918 origin = decl_ultimate_origin (decl);
8920 add_abstract_origin_attribute (type_die, origin);
8924 add_name_and_src_coords_attributes (type_die, decl);
8925 if (DECL_ORIGINAL_TYPE (decl))
8927 type = DECL_ORIGINAL_TYPE (decl);
8928 equate_type_number_to_die (TREE_TYPE (decl), type_die);
8931 type = TREE_TYPE (decl);
8932 add_type_attribute (type_die, type, TREE_READONLY (decl),
8933 TREE_THIS_VOLATILE (decl), context_die);
8936 if (DECL_ABSTRACT (decl))
8937 equate_decl_number_to_die (decl, type_die);
8940 /* Generate a type description DIE. */
8943 gen_type_die (type, context_die)
8945 register dw_die_ref context_die;
8949 if (type == NULL_TREE || type == error_mark_node)
8952 /* We are going to output a DIE to represent the unqualified version of
8953 this type (i.e. without any const or volatile qualifiers) so get the
8954 main variant (i.e. the unqualified version) of this type now. */
8955 type = type_main_variant (type);
8957 if (TREE_ASM_WRITTEN (type))
8960 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8961 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
8963 TREE_ASM_WRITTEN (type) = 1;
8964 gen_decl_die (TYPE_NAME (type), context_die);
8968 switch (TREE_CODE (type))
8974 case REFERENCE_TYPE:
8975 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
8976 ensures that the gen_type_die recursion will terminate even if the
8977 type is recursive. Recursive types are possible in Ada. */
8978 /* ??? We could perhaps do this for all types before the switch
8980 TREE_ASM_WRITTEN (type) = 1;
8982 /* For these types, all that is required is that we output a DIE (or a
8983 set of DIEs) to represent the "basis" type. */
8984 gen_type_die (TREE_TYPE (type), context_die);
8988 /* This code is used for C++ pointer-to-data-member types.
8989 Output a description of the relevant class type. */
8990 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
8992 /* Output a description of the type of the object pointed to. */
8993 gen_type_die (TREE_TYPE (type), context_die);
8995 /* Now output a DIE to represent this pointer-to-data-member type
8997 gen_ptr_to_mbr_type_die (type, context_die);
9001 gen_type_die (TYPE_DOMAIN (type), context_die);
9002 gen_set_type_die (type, context_die);
9006 gen_type_die (TREE_TYPE (type), context_die);
9007 abort (); /* No way to represent these in Dwarf yet! */
9011 /* Force out return type (in case it wasn't forced out already). */
9012 gen_type_die (TREE_TYPE (type), context_die);
9013 gen_subroutine_type_die (type, context_die);
9017 /* Force out return type (in case it wasn't forced out already). */
9018 gen_type_die (TREE_TYPE (type), context_die);
9019 gen_subroutine_type_die (type, context_die);
9023 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
9025 gen_type_die (TREE_TYPE (type), context_die);
9026 gen_string_type_die (type, context_die);
9029 gen_array_type_die (type, context_die);
9035 case QUAL_UNION_TYPE:
9036 /* If this is a nested type whose containing class hasn't been
9037 written out yet, writing it out will cover this one, too.
9038 This does not apply to instantiations of member class templates;
9039 they need to be added to the containing class as they are
9040 generated. FIXME: This hurts the idea of combining type decls
9041 from multiple TUs, since we can't predict what set of template
9042 instantiations we'll get. */
9043 if (TYPE_CONTEXT (type)
9044 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9045 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9047 gen_type_die (TYPE_CONTEXT (type), context_die);
9049 if (TREE_ASM_WRITTEN (type))
9052 /* If that failed, attach ourselves to the stub. */
9053 push_decl_scope (TYPE_CONTEXT (type));
9054 context_die = lookup_type_die (TYPE_CONTEXT (type));
9060 if (TREE_CODE (type) == ENUMERAL_TYPE)
9061 gen_enumeration_type_die (type, context_die);
9063 gen_struct_or_union_type_die (type, context_die);
9068 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9069 it up if it is ever completed. gen_*_type_die will set it for us
9070 when appropriate. */
9079 /* No DIEs needed for fundamental types. */
9083 /* No Dwarf representation currently defined. */
9090 TREE_ASM_WRITTEN (type) = 1;
9093 /* Generate a DIE for a tagged type instantiation. */
9096 gen_tagged_type_instantiation_die (type, context_die)
9098 register dw_die_ref context_die;
9100 if (type == NULL_TREE || type == error_mark_node)
9103 /* We are going to output a DIE to represent the unqualified version of
9104 this type (i.e. without any const or volatile qualifiers) so make sure
9105 that we have the main variant (i.e. the unqualified version) of this
9107 if (type != type_main_variant (type))
9110 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
9111 an instance of an unresolved type. */
9113 switch (TREE_CODE (type))
9119 gen_inlined_enumeration_type_die (type, context_die);
9123 gen_inlined_structure_type_die (type, context_die);
9127 case QUAL_UNION_TYPE:
9128 gen_inlined_union_type_die (type, context_die);
9136 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
9137 things which are local to the given block. */
9140 gen_block_die (stmt, context_die, depth)
9142 register dw_die_ref context_die;
9145 register int must_output_die = 0;
9146 register tree origin;
9148 register enum tree_code origin_code;
9150 /* Ignore blocks never really used to make RTL. */
9152 if (stmt == NULL_TREE || !TREE_USED (stmt) || !TREE_ASM_WRITTEN (stmt))
9155 /* Determine the "ultimate origin" of this block. This block may be an
9156 inlined instance of an inlined instance of inline function, so we have
9157 to trace all of the way back through the origin chain to find out what
9158 sort of node actually served as the original seed for the creation of
9159 the current block. */
9160 origin = block_ultimate_origin (stmt);
9161 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
9163 /* Determine if we need to output any Dwarf DIEs at all to represent this
9165 if (origin_code == FUNCTION_DECL)
9166 /* The outer scopes for inlinings *must* always be represented. We
9167 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9168 must_output_die = 1;
9171 /* In the case where the current block represents an inlining of the
9172 "body block" of an inline function, we must *NOT* output any DIE for
9173 this block because we have already output a DIE to represent the
9174 whole inlined function scope and the "body block" of any function
9175 doesn't really represent a different scope according to ANSI C
9176 rules. So we check here to make sure that this block does not
9177 represent a "body block inlining" before trying to set the
9178 `must_output_die' flag. */
9179 if (! is_body_block (origin ? origin : stmt))
9181 /* Determine if this block directly contains any "significant"
9182 local declarations which we will need to output DIEs for. */
9183 if (debug_info_level > DINFO_LEVEL_TERSE)
9184 /* We are not in terse mode so *any* local declaration counts
9185 as being a "significant" one. */
9186 must_output_die = (BLOCK_VARS (stmt) != NULL);
9188 /* We are in terse mode, so only local (nested) function
9189 definitions count as "significant" local declarations. */
9190 for (decl = BLOCK_VARS (stmt);
9191 decl != NULL; decl = TREE_CHAIN (decl))
9192 if (TREE_CODE (decl) == FUNCTION_DECL
9193 && DECL_INITIAL (decl))
9195 must_output_die = 1;
9201 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9202 DIE for any block which contains no significant local declarations at
9203 all. Rather, in such cases we just call `decls_for_scope' so that any
9204 needed Dwarf info for any sub-blocks will get properly generated. Note
9205 that in terse mode, our definition of what constitutes a "significant"
9206 local declaration gets restricted to include only inlined function
9207 instances and local (nested) function definitions. */
9208 if (must_output_die)
9210 if (origin_code == FUNCTION_DECL)
9211 gen_inlined_subroutine_die (stmt, context_die, depth);
9213 gen_lexical_block_die (stmt, context_die, depth);
9216 decls_for_scope (stmt, context_die, depth);
9219 /* Generate all of the decls declared within a given scope and (recursively)
9220 all of its sub-blocks. */
9223 decls_for_scope (stmt, context_die, depth)
9225 register dw_die_ref context_die;
9229 register tree subblocks;
9231 /* Ignore blocks never really used to make RTL. */
9232 if (stmt == NULL_TREE || ! TREE_USED (stmt))
9235 /* Output the DIEs to represent all of the data objects and typedefs
9236 declared directly within this block but not within any nested
9237 sub-blocks. Also, nested function and tag DIEs have been
9238 generated with a parent of NULL; fix that up now. */
9239 for (decl = BLOCK_VARS (stmt);
9240 decl != NULL; decl = TREE_CHAIN (decl))
9242 register dw_die_ref die;
9244 if (TREE_CODE (decl) == FUNCTION_DECL)
9245 die = lookup_decl_die (decl);
9246 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9247 die = lookup_type_die (TREE_TYPE (decl));
9251 if (die != NULL && die->die_parent == NULL)
9252 add_child_die (context_die, die);
9254 gen_decl_die (decl, context_die);
9257 /* Output the DIEs to represent all sub-blocks (and the items declared
9258 therein) of this block. */
9259 for (subblocks = BLOCK_SUBBLOCKS (stmt);
9261 subblocks = BLOCK_CHAIN (subblocks))
9262 gen_block_die (subblocks, context_die, depth + 1);
9265 /* Is this a typedef we can avoid emitting? */
9268 is_redundant_typedef (decl)
9271 if (TYPE_DECL_IS_STUB (decl))
9274 if (DECL_ARTIFICIAL (decl)
9275 && DECL_CONTEXT (decl)
9276 && is_tagged_type (DECL_CONTEXT (decl))
9277 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
9278 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
9279 /* Also ignore the artificial member typedef for the class name. */
9285 /* Generate Dwarf debug information for a decl described by DECL. */
9288 gen_decl_die (decl, context_die)
9290 register dw_die_ref context_die;
9292 register tree origin;
9294 if (TREE_CODE (decl) == ERROR_MARK)
9297 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
9298 ignore a function definition, since that would screw up our count of
9299 blocks, and that in turn will completely screw up the labels we will
9300 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9301 subsequent blocks). */
9302 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
9305 switch (TREE_CODE (decl))
9308 /* The individual enumerators of an enum type get output when we output
9309 the Dwarf representation of the relevant enum type itself. */
9313 /* Don't output any DIEs to represent mere function declarations,
9314 unless they are class members or explicit block externs. */
9315 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
9316 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
9319 /* Emit info for the abstract instance first, if we haven't yet. */
9320 origin = decl_ultimate_origin (decl);
9322 gen_abstract_function (origin);
9324 if (debug_info_level > DINFO_LEVEL_TERSE)
9326 /* Before we describe the FUNCTION_DECL itself, make sure that we
9327 have described its return type. */
9328 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
9330 /* And its virtual context. */
9331 if (DECL_VINDEX (decl) != NULL_TREE)
9332 gen_type_die (DECL_CONTEXT (decl), context_die);
9334 /* And its containing type. */
9335 origin = decl_class_context (decl);
9336 if (origin != NULL_TREE)
9337 gen_type_die_for_member (origin, decl, context_die);
9340 /* Now output a DIE to represent the function itself. */
9341 gen_subprogram_die (decl, context_die);
9345 /* If we are in terse mode, don't generate any DIEs to represent any
9347 if (debug_info_level <= DINFO_LEVEL_TERSE)
9350 /* In the special case of a TYPE_DECL node representing the
9351 declaration of some type tag, if the given TYPE_DECL is marked as
9352 having been instantiated from some other (original) TYPE_DECL node
9353 (e.g. one which was generated within the original definition of an
9354 inline function) we have to generate a special (abbreviated)
9355 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9357 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
9359 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
9363 if (is_redundant_typedef (decl))
9364 gen_type_die (TREE_TYPE (decl), context_die);
9366 /* Output a DIE to represent the typedef itself. */
9367 gen_typedef_die (decl, context_die);
9371 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9372 gen_label_die (decl, context_die);
9376 /* If we are in terse mode, don't generate any DIEs to represent any
9377 variable declarations or definitions. */
9378 if (debug_info_level <= DINFO_LEVEL_TERSE)
9381 /* Output any DIEs that are needed to specify the type of this data
9383 gen_type_die (TREE_TYPE (decl), context_die);
9385 /* And its containing type. */
9386 origin = decl_class_context (decl);
9387 if (origin != NULL_TREE)
9388 gen_type_die_for_member (origin, decl, context_die);
9390 /* Now output the DIE to represent the data object itself. This gets
9391 complicated because of the possibility that the VAR_DECL really
9392 represents an inlined instance of a formal parameter for an inline
9394 origin = decl_ultimate_origin (decl);
9395 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
9396 gen_formal_parameter_die (decl, context_die);
9398 gen_variable_die (decl, context_die);
9402 /* Ignore the nameless fields that are used to skip bits, but
9403 handle C++ anonymous unions. */
9404 if (DECL_NAME (decl) != NULL_TREE
9405 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
9407 gen_type_die (member_declared_type (decl), context_die);
9408 gen_field_die (decl, context_die);
9413 gen_type_die (TREE_TYPE (decl), context_die);
9414 gen_formal_parameter_die (decl, context_die);
9417 case NAMESPACE_DECL:
9418 /* Ignore for now. */
9426 /* Add Ada "use" clause information for SGI Workshop debugger. */
9429 dwarf2out_add_library_unit_info (filename, context_list)
9430 const char *filename;
9431 const char *context_list;
9433 unsigned int file_index;
9435 if (filename != NULL)
9437 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
9438 tree context_list_decl
9439 = build_decl (LABEL_DECL, get_identifier (context_list),
9442 TREE_PUBLIC (context_list_decl) = TRUE;
9443 add_name_attribute (unit_die, context_list);
9444 file_index = lookup_filename (filename);
9445 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
9446 add_pubname (context_list_decl, unit_die);
9450 /* Write the debugging output for DECL. */
9453 dwarf2out_decl (decl)
9456 register dw_die_ref context_die = comp_unit_die;
9458 if (TREE_CODE (decl) == ERROR_MARK)
9461 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
9462 hope that the node in question doesn't represent a function definition.
9463 If it does, then totally ignoring it is bound to screw up our count of
9464 blocks, and that in turn will completely screw up the labels we will
9465 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9466 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
9467 own sequence numbers with them!) */
9468 if (DECL_IGNORED_P (decl))
9470 if (TREE_CODE (decl) == FUNCTION_DECL
9471 && DECL_INITIAL (decl) != NULL)
9477 switch (TREE_CODE (decl))
9480 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9481 builtin function. Explicit programmer-supplied declarations of
9482 these same functions should NOT be ignored however. */
9483 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
9486 /* What we would really like to do here is to filter out all mere
9487 file-scope declarations of file-scope functions which are never
9488 referenced later within this translation unit (and keep all of ones
9489 that *are* referenced later on) but we aren't clairvoyant, so we have
9490 no idea which functions will be referenced in the future (i.e. later
9491 on within the current translation unit). So here we just ignore all
9492 file-scope function declarations which are not also definitions. If
9493 and when the debugger needs to know something about these functions,
9494 it will have to hunt around and find the DWARF information associated
9495 with the definition of the function. Note that we can't just check
9496 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9497 definitions and which ones represent mere declarations. We have to
9498 check `DECL_INITIAL' instead. That's because the C front-end
9499 supports some weird semantics for "extern inline" function
9500 definitions. These can get inlined within the current translation
9501 unit (an thus, we need to generate DWARF info for their abstract
9502 instances so that the DWARF info for the concrete inlined instances
9503 can have something to refer to) but the compiler never generates any
9504 out-of-lines instances of such things (despite the fact that they
9505 *are* definitions). The important point is that the C front-end
9506 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9507 to generate DWARF for them anyway. Note that the C++ front-end also
9508 plays some similar games for inline function definitions appearing
9509 within include files which also contain
9510 `#pragma interface' pragmas. */
9511 if (DECL_INITIAL (decl) == NULL_TREE)
9514 /* If we're a nested function, initially use a parent of NULL; if we're
9515 a plain function, this will be fixed up in decls_for_scope. If
9516 we're a method, it will be ignored, since we already have a DIE. */
9517 if (decl_function_context (decl))
9523 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9524 declaration and if the declaration was never even referenced from
9525 within this entire compilation unit. We suppress these DIEs in
9526 order to save space in the .debug section (by eliminating entries
9527 which are probably useless). Note that we must not suppress
9528 block-local extern declarations (whether used or not) because that
9529 would screw-up the debugger's name lookup mechanism and cause it to
9530 miss things which really ought to be in scope at a given point. */
9531 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
9534 /* If we are in terse mode, don't generate any DIEs to represent any
9535 variable declarations or definitions. */
9536 if (debug_info_level <= DINFO_LEVEL_TERSE)
9541 /* Don't bother trying to generate any DIEs to represent any of the
9542 normal built-in types for the language we are compiling. */
9543 if (DECL_SOURCE_LINE (decl) == 0)
9545 /* OK, we need to generate one for `bool' so GDB knows what type
9546 comparisons have. */
9547 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
9548 == DW_LANG_C_plus_plus)
9549 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
9550 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
9555 /* If we are in terse mode, don't generate any DIEs for types. */
9556 if (debug_info_level <= DINFO_LEVEL_TERSE)
9559 /* If we're a function-scope tag, initially use a parent of NULL;
9560 this will be fixed up in decls_for_scope. */
9561 if (decl_function_context (decl))
9570 gen_decl_die (decl, context_die);
9573 /* Output a marker (i.e. a label) for the beginning of the generated code for
9577 dwarf2out_begin_block (blocknum)
9578 register unsigned blocknum;
9580 function_section (current_function_decl);
9581 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
9584 /* Output a marker (i.e. a label) for the end of the generated code for a
9588 dwarf2out_end_block (blocknum)
9589 register unsigned blocknum;
9591 function_section (current_function_decl);
9592 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
9595 /* Output a marker (i.e. a label) at a point in the assembly code which
9596 corresponds to a given source level label. */
9599 dwarf2out_label (insn)
9602 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9604 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9606 function_section (current_function_decl);
9607 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
9608 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
9609 (unsigned) INSN_UID (insn));
9613 /* Lookup a filename (in the list of filenames that we know about here in
9614 dwarf2out.c) and return its "index". The index of each (known) filename is
9615 just a unique number which is associated with only that one filename.
9616 We need such numbers for the sake of generating labels
9617 (in the .debug_sfnames section) and references to those
9618 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9619 If the filename given as an argument is not found in our current list,
9620 add it to the list and assign it the next available unique index number.
9621 In order to speed up searches, we remember the index of the filename
9622 was looked up last. This handles the majority of all searches. */
9625 lookup_filename (file_name)
9626 const char *file_name;
9628 static unsigned last_file_lookup_index = 0;
9629 register unsigned i;
9631 /* Check to see if the file name that was searched on the previous call
9632 matches this file name. If so, return the index. */
9633 if (last_file_lookup_index != 0)
9634 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
9635 return last_file_lookup_index;
9637 /* Didn't match the previous lookup, search the table */
9638 for (i = 1; i < file_table_in_use; ++i)
9639 if (strcmp (file_name, file_table[i]) == 0)
9641 last_file_lookup_index = i;
9645 /* Prepare to add a new table entry by making sure there is enough space in
9646 the table to do so. If not, expand the current table. */
9647 if (file_table_in_use == file_table_allocated)
9649 file_table_allocated += FILE_TABLE_INCREMENT;
9651 = (char **) xrealloc (file_table,
9652 file_table_allocated * sizeof (char *));
9655 /* Add the new entry to the end of the filename table. */
9656 file_table[file_table_in_use] = xstrdup (file_name);
9657 last_file_lookup_index = file_table_in_use++;
9659 return last_file_lookup_index;
9662 /* Output a label to mark the beginning of a source code line entry
9663 and record information relating to this source line, in
9664 'line_info_table' for later output of the .debug_line section. */
9667 dwarf2out_line (filename, line)
9668 register const char *filename;
9669 register unsigned line;
9671 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9673 function_section (current_function_decl);
9675 if (DWARF2_ASM_LINE_DEBUG_INFO)
9677 static const char *lastfile;
9679 /* Emit the .file and .loc directives understood by GNU as. */
9680 if (lastfile == 0 || strcmp (filename, lastfile))
9683 ggc_add_string_root ((char **) &lastfile, 1);
9685 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
9686 lastfile = filename;
9689 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
9691 /* Indicate that line number info exists. */
9692 ++line_info_table_in_use;
9694 /* Indicate that multiple line number tables exist. */
9695 if (DECL_SECTION_NAME (current_function_decl))
9696 ++separate_line_info_table_in_use;
9698 else if (DECL_SECTION_NAME (current_function_decl))
9700 register dw_separate_line_info_ref line_info;
9701 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
9702 separate_line_info_table_in_use);
9704 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9705 fputc ('\n', asm_out_file);
9707 /* expand the line info table if necessary */
9708 if (separate_line_info_table_in_use
9709 == separate_line_info_table_allocated)
9711 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9712 separate_line_info_table
9713 = (dw_separate_line_info_ref)
9714 xrealloc (separate_line_info_table,
9715 separate_line_info_table_allocated
9716 * sizeof (dw_separate_line_info_entry));
9719 /* Add the new entry at the end of the line_info_table. */
9721 = &separate_line_info_table[separate_line_info_table_in_use++];
9722 line_info->dw_file_num = lookup_filename (filename);
9723 line_info->dw_line_num = line;
9724 line_info->function = current_funcdef_number;
9728 register dw_line_info_ref line_info;
9730 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
9731 line_info_table_in_use);
9733 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9734 fputc ('\n', asm_out_file);
9736 /* Expand the line info table if necessary. */
9737 if (line_info_table_in_use == line_info_table_allocated)
9739 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9741 = (dw_line_info_ref)
9742 xrealloc (line_info_table,
9743 (line_info_table_allocated
9744 * sizeof (dw_line_info_entry)));
9747 /* Add the new entry at the end of the line_info_table. */
9748 line_info = &line_info_table[line_info_table_in_use++];
9749 line_info->dw_file_num = lookup_filename (filename);
9750 line_info->dw_line_num = line;
9755 /* Record the beginning of a new source file, for later output
9756 of the .debug_macinfo section. At present, unimplemented. */
9759 dwarf2out_start_source_file (filename)
9760 register const char *filename ATTRIBUTE_UNUSED;
9764 /* Record the end of a source file, for later output
9765 of the .debug_macinfo section. At present, unimplemented. */
9768 dwarf2out_end_source_file ()
9772 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9773 the tail part of the directive line, i.e. the part which is past the
9774 initial whitespace, #, whitespace, directive-name, whitespace part. */
9777 dwarf2out_define (lineno, buffer)
9778 register unsigned lineno ATTRIBUTE_UNUSED;
9779 register const char *buffer ATTRIBUTE_UNUSED;
9781 static int initialized = 0;
9784 dwarf2out_start_source_file (primary_filename);
9789 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9790 the tail part of the directive line, i.e. the part which is past the
9791 initial whitespace, #, whitespace, directive-name, whitespace part. */
9794 dwarf2out_undef (lineno, buffer)
9795 register unsigned lineno ATTRIBUTE_UNUSED;
9796 register const char *buffer ATTRIBUTE_UNUSED;
9800 /* Set up for Dwarf output at the start of compilation. */
9803 dwarf2out_init (asm_out_file, main_input_filename)
9804 register FILE *asm_out_file;
9805 register char *main_input_filename;
9807 /* Remember the name of the primary input file. */
9808 primary_filename = main_input_filename;
9810 /* Allocate the initial hunk of the file_table. */
9811 file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
9812 file_table_allocated = FILE_TABLE_INCREMENT;
9814 /* Skip the first entry - file numbers begin at 1. */
9815 file_table_in_use = 1;
9817 /* Allocate the initial hunk of the decl_die_table. */
9819 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
9820 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
9821 decl_die_table_in_use = 0;
9823 /* Allocate the initial hunk of the decl_scope_table. */
9825 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
9826 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
9827 decl_scope_depth = 0;
9829 /* Allocate the initial hunk of the abbrev_die_table. */
9831 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
9832 sizeof (dw_die_ref));
9833 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
9834 /* Zero-th entry is allocated, but unused */
9835 abbrev_die_table_in_use = 1;
9837 /* Allocate the initial hunk of the line_info_table. */
9839 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
9840 sizeof (dw_line_info_entry));
9841 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
9842 /* Zero-th entry is allocated, but unused */
9843 line_info_table_in_use = 1;
9845 /* Generate the initial DIE for the .debug section. Note that the (string)
9846 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9847 will (typically) be a relative pathname and that this pathname should be
9848 taken as being relative to the directory from which the compiler was
9849 invoked when the given (base) source file was compiled. */
9850 comp_unit_die = gen_compile_unit_die (main_input_filename);
9854 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
9855 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
9858 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
9859 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
9860 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9861 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
9863 strcpy (text_section_label, stripattributes (TEXT_SECTION));
9864 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
9865 DEBUG_INFO_SECTION_LABEL, 0);
9866 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
9867 DEBUG_LINE_SECTION_LABEL, 0);
9869 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9870 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
9871 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9873 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9874 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
9876 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9877 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
9878 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9879 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
9882 /* Output stuff that dwarf requires at the end of every file,
9883 and generate the DWARF-2 debugging info. */
9888 limbo_die_node *node, *next_node;
9891 /* Traverse the limbo die list, and add parent/child links. The only
9892 dies without parents that should be here are concrete instances of
9893 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9894 For concrete instances, we can get the parent die from the abstract
9896 for (node = limbo_die_list; node; node = next_node)
9898 next_node = node->next;
9901 if (die->die_parent == NULL)
9903 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
9905 add_child_die (origin->die_parent, die);
9906 else if (die == comp_unit_die)
9913 limbo_die_list = NULL;
9915 /* Walk through the list of incomplete types again, trying once more to
9916 emit full debugging info for them. */
9917 retry_incomplete_types ();
9919 /* Traverse the DIE's, reverse their lists of attributes and children,
9920 and add add sibling attributes to those DIE's that have children. */
9921 add_sibling_attributes (comp_unit_die);
9923 /* Output a terminator label for the .text section. */
9924 fputc ('\n', asm_out_file);
9925 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9926 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
9929 /* Output a terminator label for the .data section. */
9930 fputc ('\n', asm_out_file);
9931 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
9932 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
9934 /* Output a terminator label for the .bss section. */
9935 fputc ('\n', asm_out_file);
9936 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
9937 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
9940 /* Output the source line correspondence table. */
9941 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
9943 if (! DWARF2_ASM_LINE_DEBUG_INFO)
9945 fputc ('\n', asm_out_file);
9946 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9947 output_line_info ();
9950 /* We can only use the low/high_pc attributes if all of the code
9952 if (separate_line_info_table_in_use == 0)
9954 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
9955 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
9958 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
9959 debug_line_section_label);
9962 #if 0 /* unimplemented */
9963 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
9964 add_AT_unsigned (die, DW_AT_macro_info, 0);
9967 /* Output the abbreviation table. */
9968 fputc ('\n', asm_out_file);
9969 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9970 build_abbrev_table (comp_unit_die);
9971 output_abbrev_section ();
9973 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9974 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9975 calc_die_sizes (comp_unit_die);
9977 /* Output debugging information. */
9978 fputc ('\n', asm_out_file);
9979 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9980 output_compilation_unit_header ();
9981 output_die (comp_unit_die);
9983 if (pubname_table_in_use)
9985 /* Output public names table. */
9986 fputc ('\n', asm_out_file);
9987 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
9991 /* We only put functions in the arange table, so don't write it out if
9992 we don't have any. */
9993 if (fde_table_in_use)
9995 /* Output the address range information. */
9996 fputc ('\n', asm_out_file);
9997 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
10001 #endif /* DWARF2_DEBUGGING_INFO */