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 Emit .debug_line header even when there are no functions, since
27 the file numbers are used by .debug_info. Alternately, leave
28 out locations for types and decls.
29 Avoid talking about ctors and op= for PODs.
30 Factor out common prologue sequences into multiple CIEs. */
32 /* The first part of this file deals with the DWARF 2 frame unwind
33 information, which is also used by the GCC efficient exception handling
34 mechanism. The second part, controlled only by an #ifdef
35 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
44 #include "hard-reg-set.h"
46 #include "insn-config.h"
52 #include "dwarf2out.h"
59 /* Decide whether we want to emit frame unwind information for the current
65 return (write_symbols == DWARF2_DEBUG
66 #ifdef DWARF2_FRAME_INFO
69 #ifdef DWARF2_UNWIND_INFO
71 || (flag_exceptions && ! exceptions_via_longjmp)
76 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
78 /* How to start an assembler comment. */
79 #ifndef ASM_COMMENT_START
80 #define ASM_COMMENT_START ";#"
83 typedef struct dw_cfi_struct *dw_cfi_ref;
84 typedef struct dw_fde_struct *dw_fde_ref;
85 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
87 /* Call frames are described using a sequence of Call Frame
88 Information instructions. The register number, offset
89 and address fields are provided as possible operands;
90 their use is selected by the opcode field. */
92 typedef union dw_cfi_oprnd_struct
94 unsigned long dw_cfi_reg_num;
95 long int dw_cfi_offset;
96 const char *dw_cfi_addr;
97 struct dw_loc_descr_struct *dw_cfi_loc;
101 typedef struct dw_cfi_struct
103 dw_cfi_ref dw_cfi_next;
104 enum dwarf_call_frame_info dw_cfi_opc;
105 dw_cfi_oprnd dw_cfi_oprnd1;
106 dw_cfi_oprnd dw_cfi_oprnd2;
110 /* This is how we define the location of the CFA. We use to handle it
111 as REG + OFFSET all the time, but now it can be more complex.
112 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
113 Instead of passing around REG and OFFSET, we pass a copy
114 of this structure. */
115 typedef struct cfa_loc
120 int indirect; /* 1 if CFA is accessed via a dereference. */
123 /* All call frame descriptions (FDE's) in the GCC generated DWARF
124 refer to a single Common Information Entry (CIE), defined at
125 the beginning of the .debug_frame section. This used of a single
126 CIE obviates the need to keep track of multiple CIE's
127 in the DWARF generation routines below. */
129 typedef struct dw_fde_struct
131 const char *dw_fde_begin;
132 const char *dw_fde_current_label;
133 const char *dw_fde_end;
134 dw_cfi_ref dw_fde_cfi;
139 /* Maximum size (in bytes) of an artificially generated label. */
140 #define MAX_ARTIFICIAL_LABEL_BYTES 30
142 /* The size of the target's pointer type. */
144 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
147 /* The size of addresses as they appear in the Dwarf 2 data.
148 Some architectures use word addresses to refer to code locations,
149 but Dwarf 2 info always uses byte addresses. On such machines,
150 Dwarf 2 addresses need to be larger than the architecture's
152 #ifndef DWARF2_ADDR_SIZE
153 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
156 /* The size in bytes of a DWARF field indicating an offset or length
157 relative to a debug info section, specified to be 4 bytes in the
158 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
161 #ifndef DWARF_OFFSET_SIZE
162 #define DWARF_OFFSET_SIZE 4
165 #define DWARF_VERSION 2
167 /* Round SIZE up to the nearest BOUNDARY. */
168 #define DWARF_ROUND(SIZE,BOUNDARY) \
169 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
171 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
172 #ifdef STACK_GROWS_DOWNWARD
173 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
175 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
178 /* A pointer to the base of a table that contains frame description
179 information for each routine. */
180 static dw_fde_ref fde_table;
182 /* Number of elements currently allocated for fde_table. */
183 static unsigned fde_table_allocated;
185 /* Number of elements in fde_table currently in use. */
186 static unsigned fde_table_in_use;
188 /* Size (in elements) of increments by which we may expand the
190 #define FDE_TABLE_INCREMENT 256
192 /* A list of call frame insns for the CIE. */
193 static dw_cfi_ref cie_cfi_head;
195 /* The number of the current function definition for which debugging
196 information is being generated. These numbers range from 1 up to the
197 maximum number of function definitions contained within the current
198 compilation unit. These numbers are used to create unique label id's
199 unique to each function definition. */
200 static unsigned current_funcdef_number = 0;
202 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
203 attribute that accelerates the lookup of the FDE associated
204 with the subprogram. This variable holds the table index of the FDE
205 associated with the current function (body) definition. */
206 static unsigned current_funcdef_fde;
208 /* Forward declarations for functions defined in this file. */
210 static char *stripattributes PARAMS ((const char *));
211 static const char *dwarf_cfi_name PARAMS ((unsigned));
212 static dw_cfi_ref new_cfi PARAMS ((void));
213 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
214 static unsigned long size_of_uleb128 PARAMS ((unsigned long));
215 static unsigned long size_of_sleb128 PARAMS ((long));
216 static void output_uleb128 PARAMS ((unsigned long));
217 static void output_sleb128 PARAMS ((long));
218 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
219 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
220 static void lookup_cfa PARAMS ((dw_cfa_location *));
221 static void reg_save PARAMS ((const char *, unsigned,
223 static void initial_return_save PARAMS ((rtx));
224 static long stack_adjust_offset PARAMS ((rtx));
225 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
226 static void output_call_frame_info PARAMS ((int));
227 static void dwarf2out_stack_adjust PARAMS ((rtx));
228 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
230 /* Support for complex CFA locations. */
231 static void output_cfa_loc PARAMS ((dw_cfi_ref));
232 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
233 struct dw_loc_descr_struct *));
234 static struct dw_loc_descr_struct *build_cfa_loc
235 PARAMS ((dw_cfa_location *));
236 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
238 /* Definitions of defaults for assembler-dependent names of various
239 pseudo-ops and section names.
240 Theses may be overridden in the tm.h file (if necessary) for a particular
243 #ifdef OBJECT_FORMAT_ELF
244 #ifndef UNALIGNED_SHORT_ASM_OP
245 #define UNALIGNED_SHORT_ASM_OP "\t.2byte\t"
247 #ifndef UNALIGNED_INT_ASM_OP
248 #define UNALIGNED_INT_ASM_OP "\t.4byte\t"
250 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
251 #define UNALIGNED_DOUBLE_INT_ASM_OP "\t.8byte\t"
253 #endif /* OBJECT_FORMAT_ELF */
256 #define ASM_BYTE_OP "\t.byte\t"
259 /* Data and reference forms for relocatable data. */
260 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
261 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
263 /* Pseudo-op for defining a new section. */
264 #ifndef SECTION_ASM_OP
265 #define SECTION_ASM_OP "\t.section\t"
268 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
269 print the SECTION_ASM_OP and the section name. The default here works for
270 almost all svr4 assemblers, except for the sparc, where the section name
271 must be enclosed in double quotes. (See sparcv4.h). */
272 #ifndef SECTION_FORMAT
273 #ifdef PUSHSECTION_FORMAT
274 #define SECTION_FORMAT PUSHSECTION_FORMAT
276 #define SECTION_FORMAT "%s%s\n"
280 #ifndef FRAME_SECTION
281 #define FRAME_SECTION ".debug_frame"
284 #ifndef FUNC_BEGIN_LABEL
285 #define FUNC_BEGIN_LABEL "LFB"
287 #ifndef FUNC_END_LABEL
288 #define FUNC_END_LABEL "LFE"
290 #define CIE_AFTER_SIZE_LABEL "LSCIE"
291 #define CIE_END_LABEL "LECIE"
292 #define CIE_LENGTH_LABEL "LLCIE"
293 #define FDE_AFTER_SIZE_LABEL "LSFDE"
294 #define FDE_END_LABEL "LEFDE"
295 #define FDE_LENGTH_LABEL "LLFDE"
296 #define DIE_LABEL_PREFIX "DW"
298 /* Definitions of defaults for various types of primitive assembly language
299 output operations. These may be overridden from within the tm.h file,
300 but typically, that is unnecessary. */
302 #ifndef ASM_OUTPUT_SECTION
303 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
304 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
307 #ifndef ASM_OUTPUT_DWARF_DATA1
308 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
309 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
312 #ifndef ASM_OUTPUT_DWARF_DELTA1
313 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
314 do { fprintf ((FILE), "%s", ASM_BYTE_OP); \
315 assemble_name (FILE, LABEL1); \
316 fprintf (FILE, "-"); \
317 assemble_name (FILE, LABEL2); \
321 #ifdef UNALIGNED_INT_ASM_OP
323 #ifndef UNALIGNED_OFFSET_ASM_OP
324 #define UNALIGNED_OFFSET_ASM_OP \
325 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
328 #ifndef UNALIGNED_WORD_ASM_OP
329 #define UNALIGNED_WORD_ASM_OP \
330 ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \
331 : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \
332 : UNALIGNED_INT_ASM_OP)
335 #ifndef ASM_OUTPUT_DWARF_DELTA2
336 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
337 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \
338 assemble_name (FILE, LABEL1); \
339 fprintf (FILE, "-"); \
340 assemble_name (FILE, LABEL2); \
344 #ifndef ASM_OUTPUT_DWARF_DELTA4
345 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
346 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
347 assemble_name (FILE, LABEL1); \
348 fprintf (FILE, "-"); \
349 assemble_name (FILE, LABEL2); \
353 #ifndef ASM_OUTPUT_DWARF_DELTA
354 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
355 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \
356 assemble_name (FILE, LABEL1); \
357 fprintf (FILE, "-"); \
358 assemble_name (FILE, LABEL2); \
362 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
363 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
364 do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
365 assemble_name (FILE, LABEL1); \
366 fprintf (FILE, "-"); \
367 assemble_name (FILE, LABEL2); \
371 #ifndef ASM_OUTPUT_DWARF_ADDR
372 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
373 do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
374 assemble_name (FILE, LABEL); \
378 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
379 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
381 fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
382 output_addr_const ((FILE), (RTX)); \
386 #ifndef ASM_OUTPUT_DWARF_OFFSET4
387 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
388 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
389 assemble_name (FILE, LABEL); \
393 #ifndef ASM_OUTPUT_DWARF_OFFSET
394 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
395 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \
396 assemble_name (FILE, LABEL); \
400 #ifndef ASM_OUTPUT_DWARF_DATA2
401 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
402 fprintf ((FILE), "%s0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
405 #ifndef ASM_OUTPUT_DWARF_DATA4
406 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
407 fprintf ((FILE), "%s0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
410 #ifndef ASM_OUTPUT_DWARF_DATA8
411 #define ASM_OUTPUT_DWARF_DATA8(FILE,VALUE) \
412 fprintf ((FILE), "%s0x%lx", UNALIGNED_DOUBLE_INT_ASM_OP, \
413 (unsigned long) (VALUE))
416 #ifndef ASM_OUTPUT_DWARF_DATA
417 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
418 fprintf ((FILE), "%s0x%lx", UNALIGNED_OFFSET_ASM_OP, \
419 (unsigned long) (VALUE))
422 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
423 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
424 fprintf ((FILE), "%s0x%lx", UNALIGNED_WORD_ASM_OP, \
425 (unsigned long) (VALUE))
428 #ifndef ASM_OUTPUT_DWARF_CONST_DOUBLE
429 #define ASM_OUTPUT_DWARF_CONST_DOUBLE(FILE,HIGH_VALUE,LOW_VALUE) \
431 if (WORDS_BIG_ENDIAN) \
433 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
434 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
438 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
439 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
444 #else /* UNALIGNED_INT_ASM_OP */
446 /* We don't have unaligned support, let's hope the normal output works for
447 .debug_frame. But we know it won't work for .debug_info. */
449 #ifdef DWARF2_DEBUGGING_INFO
450 #error DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP.
453 #ifndef ASM_OUTPUT_DWARF_ADDR
454 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
455 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1)
458 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
459 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) ASM_OUTPUT_DWARF_ADDR (FILE,RTX)
462 #ifndef ASM_OUTPUT_DWARF_OFFSET4
463 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
464 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
467 #ifndef ASM_OUTPUT_DWARF_OFFSET
468 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
469 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
472 #ifndef ASM_OUTPUT_DWARF_DELTA2
473 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
474 assemble_integer (gen_rtx_MINUS (HImode, \
475 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
476 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
480 #ifndef ASM_OUTPUT_DWARF_DELTA4
481 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
482 assemble_integer (gen_rtx_MINUS (SImode, \
483 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
484 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
488 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
489 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
490 assemble_integer (gen_rtx_MINUS (Pmode, \
491 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
492 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
496 #ifndef ASM_OUTPUT_DWARF_DELTA
497 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
498 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
501 #ifndef ASM_OUTPUT_DWARF_DATA2
502 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
503 assemble_integer (GEN_INT (VALUE), 2, 1)
506 #ifndef ASM_OUTPUT_DWARF_DATA4
507 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
508 assemble_integer (GEN_INT (VALUE), 4, 1)
511 #endif /* UNALIGNED_INT_ASM_OP */
514 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
515 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
517 fprintf (FILE, "%s", SET_ASM_OP); \
518 assemble_name (FILE, SY); \
520 assemble_name (FILE, HI); \
522 assemble_name (FILE, LO); \
525 #endif /* SET_ASM_OP */
527 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
528 newline is produced. When flag_debug_asm is asserted, we add commentary
529 at the end of the line, so we must avoid output of a newline here. */
530 #ifndef ASM_OUTPUT_DWARF_STRING
531 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
533 register int slen = strlen(P); \
534 register const char *p = (P); \
536 fprintf (FILE, "\t.ascii \""); \
537 for (i = 0; i < slen; i++) \
539 register int c = p[i]; \
540 if (c == '\"' || c == '\\') \
546 fprintf (FILE, "\\%o", c); \
549 fprintf (FILE, "\\0\""); \
554 /* The DWARF 2 CFA column which tracks the return address. Normally this
555 is the column for PC, or the first column after all of the hard
557 #ifndef DWARF_FRAME_RETURN_COLUMN
559 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
561 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
565 /* The mapping from gcc register number to DWARF 2 CFA column number. By
566 default, we just provide columns for all registers. */
567 #ifndef DWARF_FRAME_REGNUM
568 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
571 /* Hook used by __throw. */
574 expand_builtin_dwarf_fp_regnum ()
576 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
579 /* The offset from the incoming value of %sp to the top of the stack frame
580 for the current function. */
581 #ifndef INCOMING_FRAME_SP_OFFSET
582 #define INCOMING_FRAME_SP_OFFSET 0
585 /* Return a pointer to a copy of the section string name S with all
586 attributes stripped off, and an asterisk prepended (for assemble_name). */
592 char *stripped = xmalloc (strlen (s) + 2);
597 while (*s && *s != ',')
604 /* Generate code to initialize the register size table. */
607 expand_builtin_init_dwarf_reg_sizes (address)
611 enum machine_mode mode = TYPE_MODE (char_type_node);
612 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
613 rtx mem = gen_rtx_MEM (mode, addr);
615 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
617 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
618 int size = GET_MODE_SIZE (reg_raw_mode[i]);
623 emit_move_insn (change_address (mem, mode,
624 plus_constant (addr, offset)),
629 /* Convert a DWARF call frame info. operation to its string name */
632 dwarf_cfi_name (cfi_opc)
633 register unsigned cfi_opc;
637 case DW_CFA_advance_loc:
638 return "DW_CFA_advance_loc";
640 return "DW_CFA_offset";
642 return "DW_CFA_restore";
646 return "DW_CFA_set_loc";
647 case DW_CFA_advance_loc1:
648 return "DW_CFA_advance_loc1";
649 case DW_CFA_advance_loc2:
650 return "DW_CFA_advance_loc2";
651 case DW_CFA_advance_loc4:
652 return "DW_CFA_advance_loc4";
653 case DW_CFA_offset_extended:
654 return "DW_CFA_offset_extended";
655 case DW_CFA_restore_extended:
656 return "DW_CFA_restore_extended";
657 case DW_CFA_undefined:
658 return "DW_CFA_undefined";
659 case DW_CFA_same_value:
660 return "DW_CFA_same_value";
661 case DW_CFA_register:
662 return "DW_CFA_register";
663 case DW_CFA_remember_state:
664 return "DW_CFA_remember_state";
665 case DW_CFA_restore_state:
666 return "DW_CFA_restore_state";
668 return "DW_CFA_def_cfa";
669 case DW_CFA_def_cfa_register:
670 return "DW_CFA_def_cfa_register";
671 case DW_CFA_def_cfa_offset:
672 return "DW_CFA_def_cfa_offset";
673 case DW_CFA_def_cfa_expression:
674 return "DW_CFA_def_cfa_expression";
676 /* SGI/MIPS specific */
677 case DW_CFA_MIPS_advance_loc8:
678 return "DW_CFA_MIPS_advance_loc8";
681 case DW_CFA_GNU_window_save:
682 return "DW_CFA_GNU_window_save";
683 case DW_CFA_GNU_args_size:
684 return "DW_CFA_GNU_args_size";
685 case DW_CFA_GNU_negative_offset_extended:
686 return "DW_CFA_GNU_negative_offset_extended";
689 return "DW_CFA_<unknown>";
693 /* Return a pointer to a newly allocated Call Frame Instruction. */
695 static inline dw_cfi_ref
698 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
700 cfi->dw_cfi_next = NULL;
701 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
702 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
707 /* Add a Call Frame Instruction to list of instructions. */
710 add_cfi (list_head, cfi)
711 register dw_cfi_ref *list_head;
712 register dw_cfi_ref cfi;
714 register dw_cfi_ref *p;
716 /* Find the end of the chain. */
717 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
723 /* Generate a new label for the CFI info to refer to. */
726 dwarf2out_cfi_label ()
728 static char label[20];
729 static unsigned long label_num = 0;
731 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
732 ASM_OUTPUT_LABEL (asm_out_file, label);
737 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
738 or to the CIE if LABEL is NULL. */
741 add_fde_cfi (label, cfi)
742 register const char *label;
743 register dw_cfi_ref cfi;
747 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
750 label = dwarf2out_cfi_label ();
752 if (fde->dw_fde_current_label == NULL
753 || strcmp (label, fde->dw_fde_current_label) != 0)
755 register dw_cfi_ref xcfi;
757 fde->dw_fde_current_label = label = xstrdup (label);
759 /* Set the location counter to the new label. */
761 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
762 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
763 add_cfi (&fde->dw_fde_cfi, xcfi);
766 add_cfi (&fde->dw_fde_cfi, cfi);
770 add_cfi (&cie_cfi_head, cfi);
773 /* Subroutine of lookup_cfa. */
776 lookup_cfa_1 (cfi, loc)
777 register dw_cfi_ref cfi;
778 register dw_cfa_location *loc;
780 switch (cfi->dw_cfi_opc)
782 case DW_CFA_def_cfa_offset:
783 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
785 case DW_CFA_def_cfa_register:
786 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
789 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
790 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
792 case DW_CFA_def_cfa_expression:
793 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
800 /* Find the previous value for the CFA. */
804 register dw_cfa_location *loc;
806 register dw_cfi_ref cfi;
808 loc->reg = (unsigned long) -1;
811 loc->base_offset = 0;
813 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
814 lookup_cfa_1 (cfi, loc);
816 if (fde_table_in_use)
818 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
819 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
820 lookup_cfa_1 (cfi, loc);
824 /* The current rule for calculating the DWARF2 canonical frame address. */
827 /* The register used for saving registers to the stack, and its offset
829 dw_cfa_location cfa_store;
831 /* The running total of the size of arguments pushed onto the stack. */
832 static long args_size;
834 /* The last args_size we actually output. */
835 static long old_args_size;
837 /* Entry point to update the canonical frame address (CFA).
838 LABEL is passed to add_fde_cfi. The value of CFA is now to be
839 calculated from REG+OFFSET. */
842 dwarf2out_def_cfa (label, reg, offset)
843 register const char *label;
852 def_cfa_1 (label, &loc);
855 /* This routine does the actual work. The CFA is now calculated from
856 the dw_cfa_location structure. */
858 def_cfa_1 (label, loc_p)
859 register const char *label;
860 dw_cfa_location *loc_p;
862 register dw_cfi_ref cfi;
863 dw_cfa_location old_cfa, loc;
868 if (cfa_store.reg == loc.reg && loc.indirect == 0)
869 cfa_store.offset = loc.offset;
871 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
872 lookup_cfa (&old_cfa);
874 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
875 loc.indirect == old_cfa.indirect)
877 if (loc.indirect == 0
878 || loc.base_offset == old_cfa.base_offset)
884 if (loc.reg == old_cfa.reg && !loc.indirect)
886 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
887 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
890 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
891 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
894 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
895 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
899 else if (loc.indirect == 0)
901 cfi->dw_cfi_opc = DW_CFA_def_cfa;
902 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
903 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
907 struct dw_loc_descr_struct *loc_list;
908 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
909 loc_list = build_cfa_loc (&loc);
910 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
913 add_fde_cfi (label, cfi);
916 /* Add the CFI for saving a register. REG is the CFA column number.
917 LABEL is passed to add_fde_cfi.
918 If SREG is -1, the register is saved at OFFSET from the CFA;
919 otherwise it is saved in SREG. */
922 reg_save (label, reg, sreg, offset)
923 register const char *label;
924 register unsigned reg;
925 register unsigned sreg;
926 register long offset;
928 register dw_cfi_ref cfi = new_cfi ();
930 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
932 /* The following comparison is correct. -1 is used to indicate that
933 the value isn't a register number. */
934 if (sreg == (unsigned int) -1)
937 /* The register number won't fit in 6 bits, so we have to use
939 cfi->dw_cfi_opc = DW_CFA_offset_extended;
941 cfi->dw_cfi_opc = DW_CFA_offset;
943 offset /= DWARF_CIE_DATA_ALIGNMENT;
946 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
949 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
951 else if (sreg == reg)
952 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
956 cfi->dw_cfi_opc = DW_CFA_register;
957 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
960 add_fde_cfi (label, cfi);
963 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
964 This CFI tells the unwinder that it needs to restore the window registers
965 from the previous frame's window save area.
967 ??? Perhaps we should note in the CIE where windows are saved (instead of
968 assuming 0(cfa)) and what registers are in the window. */
971 dwarf2out_window_save (label)
972 register const char *label;
974 register dw_cfi_ref cfi = new_cfi ();
975 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
976 add_fde_cfi (label, cfi);
979 /* Add a CFI to update the running total of the size of arguments
980 pushed onto the stack. */
983 dwarf2out_args_size (label, size)
987 register dw_cfi_ref cfi;
989 if (size == old_args_size)
991 old_args_size = size;
994 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
995 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
996 add_fde_cfi (label, cfi);
999 /* Entry point for saving a register to the stack. REG is the GCC register
1000 number. LABEL and OFFSET are passed to reg_save. */
1003 dwarf2out_reg_save (label, reg, offset)
1004 register const char *label;
1005 register unsigned reg;
1006 register long offset;
1008 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
1011 /* Entry point for saving the return address in the stack.
1012 LABEL and OFFSET are passed to reg_save. */
1015 dwarf2out_return_save (label, offset)
1016 register const char *label;
1017 register long offset;
1019 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
1022 /* Entry point for saving the return address in a register.
1023 LABEL and SREG are passed to reg_save. */
1026 dwarf2out_return_reg (label, sreg)
1027 register const char *label;
1028 register unsigned sreg;
1030 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
1033 /* Record the initial position of the return address. RTL is
1034 INCOMING_RETURN_ADDR_RTX. */
1037 initial_return_save (rtl)
1040 unsigned int reg = (unsigned int) -1;
1043 switch (GET_CODE (rtl))
1046 /* RA is in a register. */
1047 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1050 /* RA is on the stack. */
1051 rtl = XEXP (rtl, 0);
1052 switch (GET_CODE (rtl))
1055 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1060 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1062 offset = INTVAL (XEXP (rtl, 1));
1065 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1067 offset = -INTVAL (XEXP (rtl, 1));
1074 /* The return address is at some offset from any value we can
1075 actually load. For instance, on the SPARC it is in %i7+8. Just
1076 ignore the offset for now; it doesn't matter for unwinding frames. */
1077 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1079 initial_return_save (XEXP (rtl, 0));
1085 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1088 /* Given a SET, calculate the amount of stack adjustment it
1092 stack_adjust_offset (pattern)
1095 rtx src = SET_SRC (pattern);
1096 rtx dest = SET_DEST (pattern);
1100 if (dest == stack_pointer_rtx)
1102 /* (set (reg sp) (plus (reg sp) (const_int))) */
1103 code = GET_CODE (src);
1104 if (! (code == PLUS || code == MINUS)
1105 || XEXP (src, 0) != stack_pointer_rtx
1106 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1109 offset = INTVAL (XEXP (src, 1));
1111 else if (GET_CODE (dest) == MEM)
1113 /* (set (mem (pre_dec (reg sp))) (foo)) */
1114 src = XEXP (dest, 0);
1115 code = GET_CODE (src);
1117 if (! (code == PRE_DEC || code == PRE_INC)
1118 || XEXP (src, 0) != stack_pointer_rtx)
1121 offset = GET_MODE_SIZE (GET_MODE (dest));
1126 if (code == PLUS || code == PRE_INC)
1132 /* Check INSN to see if it looks like a push or a stack adjustment, and
1133 make a note of it if it does. EH uses this information to find out how
1134 much extra space it needs to pop off the stack. */
1137 dwarf2out_stack_adjust (insn)
1143 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1145 /* Extract the size of the args from the CALL rtx itself. */
1147 insn = PATTERN (insn);
1148 if (GET_CODE (insn) == PARALLEL)
1149 insn = XVECEXP (insn, 0, 0);
1150 if (GET_CODE (insn) == SET)
1151 insn = SET_SRC (insn);
1152 if (GET_CODE (insn) != CALL)
1154 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1158 /* If only calls can throw, and we have a frame pointer,
1159 save up adjustments until we see the CALL_INSN. */
1160 else if (! asynchronous_exceptions
1161 && cfa.reg != STACK_POINTER_REGNUM)
1164 if (GET_CODE (insn) == BARRIER)
1166 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1167 the compiler will have already emitted a stack adjustment, but
1168 doesn't bother for calls to noreturn functions. */
1169 #ifdef STACK_GROWS_DOWNWARD
1170 offset = -args_size;
1175 else if (GET_CODE (PATTERN (insn)) == SET)
1177 offset = stack_adjust_offset (PATTERN (insn));
1179 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1180 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1182 /* There may be stack adjustments inside compound insns. Search
1187 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1189 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1190 if (GET_CODE (pattern) == SET)
1191 offset += stack_adjust_offset (pattern);
1200 if (cfa.reg == STACK_POINTER_REGNUM)
1201 cfa.offset += offset;
1203 #ifndef STACK_GROWS_DOWNWARD
1206 args_size += offset;
1210 label = dwarf2out_cfi_label ();
1211 def_cfa_1 (label, &cfa);
1212 dwarf2out_args_size (label, args_size);
1215 /* A temporary register used in adjusting SP or setting up the store_reg. */
1216 static unsigned cfa_temp_reg;
1218 /* A temporary value used in adjusting SP or setting up the store_reg. */
1219 static long cfa_temp_value;
1221 /* Record call frame debugging information for an expression, which either
1222 sets SP or FP (adjusting how we calculate the frame address) or saves a
1223 register to the stack. */
1226 dwarf2out_frame_debug_expr (expr, label)
1233 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1234 the PARALLEL independently. The first element is always processed if
1235 it is a SET. This is for backward compatability. Other elements
1236 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1237 flag is set in them. */
1239 if (GET_CODE (expr) == PARALLEL
1240 || GET_CODE (expr) == SEQUENCE)
1243 int limit = XVECLEN (expr, 0);
1245 for (par_index = 0; par_index < limit; par_index++)
1247 rtx x = XVECEXP (expr, 0, par_index);
1249 if (GET_CODE (x) == SET &&
1250 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1251 dwarf2out_frame_debug_expr (x, label);
1256 if (GET_CODE (expr) != SET)
1259 src = SET_SRC (expr);
1260 dest = SET_DEST (expr);
1262 switch (GET_CODE (dest))
1265 /* Update the CFA rule wrt SP or FP. Make sure src is
1266 relative to the current CFA register. */
1267 switch (GET_CODE (src))
1269 /* Setting FP from SP. */
1271 if (cfa.reg == (unsigned) REGNO (src))
1277 /* We used to require that dest be either SP or FP, but the
1278 ARM copies SP to a temporary register, and from there to
1279 FP. So we just rely on the backends to only set
1280 RTX_FRAME_RELATED_P on appropriate insns. */
1281 cfa.reg = REGNO (dest);
1286 if (dest == stack_pointer_rtx)
1289 switch (GET_CODE (XEXP (src, 1)))
1292 offset = INTVAL (XEXP (src, 1));
1295 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1297 offset = cfa_temp_value;
1303 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1305 /* Restoring SP from FP in the epilogue. */
1306 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1308 cfa.reg = STACK_POINTER_REGNUM;
1310 else if (XEXP (src, 0) != stack_pointer_rtx)
1313 if (GET_CODE (src) == PLUS)
1315 if (cfa.reg == STACK_POINTER_REGNUM)
1316 cfa.offset += offset;
1317 if (cfa_store.reg == STACK_POINTER_REGNUM)
1318 cfa_store.offset += offset;
1320 else if (dest == hard_frame_pointer_rtx)
1322 /* Either setting the FP from an offset of the SP,
1323 or adjusting the FP */
1324 if (! frame_pointer_needed)
1327 if (GET_CODE (XEXP (src, 0)) == REG
1328 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1329 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1331 offset = INTVAL (XEXP (src, 1));
1332 if (GET_CODE (src) == PLUS)
1334 cfa.offset += offset;
1335 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1342 if (GET_CODE (src) != PLUS
1343 || XEXP (src, 1) != stack_pointer_rtx)
1345 if (GET_CODE (XEXP (src, 0)) != REG
1346 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1348 if (cfa.reg != STACK_POINTER_REGNUM)
1350 cfa_store.reg = REGNO (dest);
1351 cfa_store.offset = cfa.offset - cfa_temp_value;
1356 cfa_temp_reg = REGNO (dest);
1357 cfa_temp_value = INTVAL (src);
1361 if (GET_CODE (XEXP (src, 0)) != REG
1362 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1363 || (unsigned) REGNO (dest) != cfa_temp_reg
1364 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1366 cfa_temp_value |= INTVAL (XEXP (src, 1));
1372 def_cfa_1 (label, &cfa);
1375 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1376 will fill in all of the bits. */
1381 cfa_temp_reg = REGNO (dest);
1382 cfa_temp_value = INTVAL (XEXP (src, 1));
1386 if (GET_CODE (src) != REG)
1389 /* Saving a register to the stack. Make sure dest is relative to the
1391 switch (GET_CODE (XEXP (dest, 0)))
1396 offset = GET_MODE_SIZE (GET_MODE (dest));
1397 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1400 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1401 || cfa_store.reg != STACK_POINTER_REGNUM)
1403 cfa_store.offset += offset;
1404 if (cfa.reg == STACK_POINTER_REGNUM)
1405 cfa.offset = cfa_store.offset;
1407 offset = -cfa_store.offset;
1410 /* With an offset. */
1413 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1414 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1417 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1419 offset -= cfa_store.offset;
1422 /* Without an offset. */
1424 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1426 offset = -cfa_store.offset;
1433 if (REGNO (src) != STACK_POINTER_REGNUM
1434 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1435 && (unsigned) REGNO (src) == cfa.reg)
1437 /* We're storing the current CFA reg into the stack. */
1439 if (cfa.offset == 0)
1441 /* If the source register is exactly the CFA, assume
1442 we're saving SP like any other register; this happens
1445 def_cfa_1 (label, &cfa);
1446 dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset);
1451 /* Otherwise, we'll need to look in the stack to
1452 calculate the CFA. */
1454 rtx x = XEXP (dest, 0);
1455 if (GET_CODE (x) != REG)
1457 if (GET_CODE (x) != REG)
1459 cfa.reg = (unsigned) REGNO (x);
1460 cfa.base_offset = offset;
1462 def_cfa_1 (label, &cfa);
1467 def_cfa_1 (label, &cfa);
1468 dwarf2out_reg_save (label, REGNO (src), offset);
1476 /* Record call frame debugging information for INSN, which either
1477 sets SP or FP (adjusting how we calculate the frame address) or saves a
1478 register to the stack. If INSN is NULL_RTX, initialize our state. */
1481 dwarf2out_frame_debug (insn)
1487 if (insn == NULL_RTX)
1489 /* Set up state for generating call frame debug info. */
1491 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1493 cfa.reg = STACK_POINTER_REGNUM;
1500 if (! RTX_FRAME_RELATED_P (insn))
1502 dwarf2out_stack_adjust (insn);
1506 label = dwarf2out_cfi_label ();
1508 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1510 insn = XEXP (src, 0);
1512 insn = PATTERN (insn);
1514 dwarf2out_frame_debug_expr (insn, label);
1517 /* Return the size of an unsigned LEB128 quantity. */
1519 static inline unsigned long
1520 size_of_uleb128 (value)
1521 register unsigned long value;
1523 register unsigned long size = 0;
1524 register unsigned byte;
1528 byte = (value & 0x7f);
1537 /* Return the size of a signed LEB128 quantity. */
1539 static inline unsigned long
1540 size_of_sleb128 (value)
1541 register long value;
1543 register unsigned long size = 0;
1544 register unsigned byte;
1548 byte = (value & 0x7f);
1552 while (!(((value == 0) && ((byte & 0x40) == 0))
1553 || ((value == -1) && ((byte & 0x40) != 0))));
1558 /* Output an unsigned LEB128 quantity. */
1561 output_uleb128 (value)
1562 register unsigned long value;
1564 unsigned long save_value = value;
1566 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1569 register unsigned byte = (value & 0x7f);
1572 /* More bytes to follow. */
1575 fprintf (asm_out_file, "0x%x", byte);
1577 fprintf (asm_out_file, ",");
1582 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1585 /* Output an signed LEB128 quantity. */
1588 output_sleb128 (value)
1589 register long value;
1592 register unsigned byte;
1593 long save_value = value;
1595 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1598 byte = (value & 0x7f);
1599 /* arithmetic shift */
1601 more = !((((value == 0) && ((byte & 0x40) == 0))
1602 || ((value == -1) && ((byte & 0x40) != 0))));
1606 fprintf (asm_out_file, "0x%x", byte);
1608 fprintf (asm_out_file, ",");
1613 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1616 /* Output a Call Frame Information opcode and its operand(s). */
1619 output_cfi (cfi, fde)
1620 register dw_cfi_ref cfi;
1621 register dw_fde_ref fde;
1623 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1625 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1627 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1629 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1630 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1631 fputc ('\n', asm_out_file);
1634 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1636 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1638 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1640 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1641 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1643 fputc ('\n', asm_out_file);
1644 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1645 fputc ('\n', asm_out_file);
1647 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1649 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1651 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1653 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1654 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1656 fputc ('\n', asm_out_file);
1660 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1662 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1663 dwarf_cfi_name (cfi->dw_cfi_opc));
1665 fputc ('\n', asm_out_file);
1666 switch (cfi->dw_cfi_opc)
1668 case DW_CFA_set_loc:
1669 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1670 fputc ('\n', asm_out_file);
1672 case DW_CFA_advance_loc1:
1673 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1674 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1675 fde->dw_fde_current_label);
1676 fputc ('\n', asm_out_file);
1677 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1679 case DW_CFA_advance_loc2:
1680 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1681 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1682 fde->dw_fde_current_label);
1683 fputc ('\n', asm_out_file);
1684 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1686 case DW_CFA_advance_loc4:
1687 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1688 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1689 fde->dw_fde_current_label);
1690 fputc ('\n', asm_out_file);
1691 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1693 #ifdef MIPS_DEBUGGING_INFO
1694 case DW_CFA_MIPS_advance_loc8:
1695 /* TODO: not currently implemented. */
1699 case DW_CFA_offset_extended:
1700 case DW_CFA_GNU_negative_offset_extended:
1701 case DW_CFA_def_cfa:
1702 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1703 fputc ('\n', asm_out_file);
1704 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1705 fputc ('\n', asm_out_file);
1707 case DW_CFA_restore_extended:
1708 case DW_CFA_undefined:
1709 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1710 fputc ('\n', asm_out_file);
1712 case DW_CFA_same_value:
1713 case DW_CFA_def_cfa_register:
1714 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1715 fputc ('\n', asm_out_file);
1717 case DW_CFA_register:
1718 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1719 fputc ('\n', asm_out_file);
1720 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1721 fputc ('\n', asm_out_file);
1723 case DW_CFA_def_cfa_offset:
1724 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1725 fputc ('\n', asm_out_file);
1727 case DW_CFA_GNU_window_save:
1729 case DW_CFA_GNU_args_size:
1730 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1731 fputc ('\n', asm_out_file);
1733 case DW_CFA_def_cfa_expression:
1734 output_cfa_loc (cfi);
1742 /* Output the call frame information used to used to record information
1743 that relates to calculating the frame pointer, and records the
1744 location of saved registers. */
1747 output_call_frame_info (for_eh)
1750 register unsigned long i;
1751 register dw_fde_ref fde;
1752 register dw_cfi_ref cfi;
1753 char l1[20], l2[20];
1754 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1758 /* Do we want to include a pointer to the exception table? */
1759 int eh_ptr = for_eh && exception_table_p ();
1761 /* If we don't have any functions we'll want to unwind out of, don't
1762 emit any EH unwind information. */
1765 for (i = 0; i < fde_table_in_use; ++i)
1766 if (! fde_table[i].nothrow)
1772 fputc ('\n', asm_out_file);
1774 /* We're going to be generating comments, so turn on app. */
1780 #ifdef EH_FRAME_SECTION
1781 EH_FRAME_SECTION ();
1783 tree label = get_file_function_name ('F');
1785 force_data_section ();
1786 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1787 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1788 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1790 assemble_label ("__FRAME_BEGIN__");
1793 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1795 /* Output the CIE. */
1796 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1797 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1798 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1799 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1801 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1803 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1806 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1808 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1811 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1814 fputc ('\n', asm_out_file);
1815 ASM_OUTPUT_LABEL (asm_out_file, l1);
1818 /* Now that the CIE pointer is PC-relative for EH,
1819 use 0 to identify the CIE. */
1820 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1822 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1825 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1827 fputc ('\n', asm_out_file);
1828 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1830 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1831 fputc ('\n', asm_out_file);
1834 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1836 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1838 fputc ('\n', asm_out_file);
1841 /* The CIE contains a pointer to the exception region info for the
1842 frame. Make the augmentation string three bytes (including the
1843 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1844 can't handle unaligned relocs. */
1847 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1848 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1852 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1854 fputc ('\n', asm_out_file);
1856 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1858 fprintf (asm_out_file, "\t%s pointer to exception region info",
1863 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1865 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1869 fputc ('\n', asm_out_file);
1872 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1874 fputc ('\n', asm_out_file);
1875 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1877 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1879 fputc ('\n', asm_out_file);
1880 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1882 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1884 fputc ('\n', asm_out_file);
1886 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1887 output_cfi (cfi, NULL);
1889 /* Pad the CIE out to an address sized boundary. */
1890 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1891 ASM_OUTPUT_LABEL (asm_out_file, l2);
1892 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1893 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1895 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1896 fputc ('\n', asm_out_file);
1899 /* Loop through all of the FDE's. */
1900 for (i = 0; i < fde_table_in_use; ++i)
1902 fde = &fde_table[i];
1904 /* Don't emit EH unwind info for leaf functions. */
1905 if (for_eh && fde->nothrow)
1908 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1909 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1910 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1911 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i * 2);
1913 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1915 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1918 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1920 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1923 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1924 fputc ('\n', asm_out_file);
1925 ASM_OUTPUT_LABEL (asm_out_file, l1);
1927 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1928 emits a target dependent sized offset when for_eh is not true.
1929 This inconsistency may confuse gdb. The only case where we need a
1930 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1931 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1932 though in order to be compatible with the dwarf_fde struct in frame.c.
1933 If the for_eh case is changed, then the struct in frame.c has
1934 to be adjusted appropriately. */
1936 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1938 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1940 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1942 fputc ('\n', asm_out_file);
1943 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1945 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1947 fputc ('\n', asm_out_file);
1948 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1949 fde->dw_fde_end, fde->dw_fde_begin);
1951 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1953 fputc ('\n', asm_out_file);
1955 /* Loop through the Call Frame Instructions associated with
1957 fde->dw_fde_current_label = fde->dw_fde_begin;
1958 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1959 output_cfi (cfi, fde);
1961 /* Pad the FDE out to an address sized boundary. */
1962 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1963 ASM_OUTPUT_LABEL (asm_out_file, l2);
1964 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1965 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1967 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1968 fputc ('\n', asm_out_file);
1971 #ifndef EH_FRAME_SECTION
1974 /* Emit terminating zero for table. */
1975 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1976 fputc ('\n', asm_out_file);
1979 #ifdef MIPS_DEBUGGING_INFO
1980 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1981 get a value of 0. Putting .align 0 after the label fixes it. */
1982 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1985 /* Turn off app to make assembly quicker. */
1990 /* Output a marker (i.e. a label) for the beginning of a function, before
1994 dwarf2out_begin_prologue ()
1996 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1997 register dw_fde_ref fde;
1999 ++current_funcdef_number;
2001 function_section (current_function_decl);
2002 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2003 current_funcdef_number);
2004 ASM_OUTPUT_LABEL (asm_out_file, label);
2005 current_function_func_begin_label = get_identifier (label);
2007 /* Expand the fde table if necessary. */
2008 if (fde_table_in_use == fde_table_allocated)
2010 fde_table_allocated += FDE_TABLE_INCREMENT;
2012 = (dw_fde_ref) xrealloc (fde_table,
2013 fde_table_allocated * sizeof (dw_fde_node));
2016 /* Record the FDE associated with this function. */
2017 current_funcdef_fde = fde_table_in_use;
2019 /* Add the new FDE at the end of the fde_table. */
2020 fde = &fde_table[fde_table_in_use++];
2021 fde->dw_fde_begin = xstrdup (label);
2022 fde->dw_fde_current_label = NULL;
2023 fde->dw_fde_end = NULL;
2024 fde->dw_fde_cfi = NULL;
2025 fde->nothrow = current_function_nothrow;
2027 args_size = old_args_size = 0;
2030 /* Output a marker (i.e. a label) for the absolute end of the generated code
2031 for a function definition. This gets called *after* the epilogue code has
2035 dwarf2out_end_epilogue ()
2038 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2040 /* Output a label to mark the endpoint of the code generated for this
2042 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2043 ASM_OUTPUT_LABEL (asm_out_file, label);
2044 fde = &fde_table[fde_table_in_use - 1];
2045 fde->dw_fde_end = xstrdup (label);
2049 dwarf2out_frame_init ()
2051 /* Allocate the initial hunk of the fde_table. */
2052 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2053 fde_table_allocated = FDE_TABLE_INCREMENT;
2054 fde_table_in_use = 0;
2056 /* Generate the CFA instructions common to all FDE's. Do it now for the
2057 sake of lookup_cfa. */
2059 #ifdef DWARF2_UNWIND_INFO
2060 /* On entry, the Canonical Frame Address is at SP. */
2061 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2062 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2067 dwarf2out_frame_finish ()
2069 /* Output call frame information. */
2070 #ifdef MIPS_DEBUGGING_INFO
2071 if (write_symbols == DWARF2_DEBUG)
2072 output_call_frame_info (0);
2073 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2074 output_call_frame_info (1);
2076 if (write_symbols == DWARF2_DEBUG
2077 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2078 output_call_frame_info (1);
2082 /* And now, the subset of the debugging information support code necessary
2083 for emitting location expressions. */
2085 typedef struct dw_val_struct *dw_val_ref;
2086 typedef struct die_struct *dw_die_ref;
2087 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2089 /* Each DIE may have a series of attribute/value pairs. Values
2090 can take on several forms. The forms that are used in this
2091 implementation are listed below. */
2098 dw_val_class_unsigned_const,
2099 dw_val_class_long_long,
2102 dw_val_class_die_ref,
2103 dw_val_class_fde_ref,
2104 dw_val_class_lbl_id,
2105 dw_val_class_lbl_offset,
2110 /* Describe a double word constant value. */
2111 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2113 typedef struct dw_long_long_struct
2120 /* Describe a floating point constant value. */
2122 typedef struct dw_fp_struct
2129 /* The dw_val_node describes an attribute's value, as it is
2130 represented internally. */
2132 typedef struct dw_val_struct
2134 dw_val_class val_class;
2138 dw_loc_descr_ref val_loc;
2140 long unsigned val_unsigned;
2141 dw_long_long_const val_long_long;
2142 dw_float_const val_float;
2147 unsigned val_fde_index;
2150 unsigned char val_flag;
2156 /* Locations in memory are described using a sequence of stack machine
2159 typedef struct dw_loc_descr_struct
2161 dw_loc_descr_ref dw_loc_next;
2162 enum dwarf_location_atom dw_loc_opc;
2163 dw_val_node dw_loc_oprnd1;
2164 dw_val_node dw_loc_oprnd2;
2168 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2169 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2172 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2174 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2175 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2176 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2177 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2179 /* Convert a DWARF stack opcode into its string name. */
2182 dwarf_stack_op_name (op)
2183 register unsigned op;
2188 return "DW_OP_addr";
2190 return "DW_OP_deref";
2192 return "DW_OP_const1u";
2194 return "DW_OP_const1s";
2196 return "DW_OP_const2u";
2198 return "DW_OP_const2s";
2200 return "DW_OP_const4u";
2202 return "DW_OP_const4s";
2204 return "DW_OP_const8u";
2206 return "DW_OP_const8s";
2208 return "DW_OP_constu";
2210 return "DW_OP_consts";
2214 return "DW_OP_drop";
2216 return "DW_OP_over";
2218 return "DW_OP_pick";
2220 return "DW_OP_swap";
2224 return "DW_OP_xderef";
2232 return "DW_OP_minus";
2244 return "DW_OP_plus";
2245 case DW_OP_plus_uconst:
2246 return "DW_OP_plus_uconst";
2252 return "DW_OP_shra";
2270 return "DW_OP_skip";
2272 return "DW_OP_lit0";
2274 return "DW_OP_lit1";
2276 return "DW_OP_lit2";
2278 return "DW_OP_lit3";
2280 return "DW_OP_lit4";
2282 return "DW_OP_lit5";
2284 return "DW_OP_lit6";
2286 return "DW_OP_lit7";
2288 return "DW_OP_lit8";
2290 return "DW_OP_lit9";
2292 return "DW_OP_lit10";
2294 return "DW_OP_lit11";
2296 return "DW_OP_lit12";
2298 return "DW_OP_lit13";
2300 return "DW_OP_lit14";
2302 return "DW_OP_lit15";
2304 return "DW_OP_lit16";
2306 return "DW_OP_lit17";
2308 return "DW_OP_lit18";
2310 return "DW_OP_lit19";
2312 return "DW_OP_lit20";
2314 return "DW_OP_lit21";
2316 return "DW_OP_lit22";
2318 return "DW_OP_lit23";
2320 return "DW_OP_lit24";
2322 return "DW_OP_lit25";
2324 return "DW_OP_lit26";
2326 return "DW_OP_lit27";
2328 return "DW_OP_lit28";
2330 return "DW_OP_lit29";
2332 return "DW_OP_lit30";
2334 return "DW_OP_lit31";
2336 return "DW_OP_reg0";
2338 return "DW_OP_reg1";
2340 return "DW_OP_reg2";
2342 return "DW_OP_reg3";
2344 return "DW_OP_reg4";
2346 return "DW_OP_reg5";
2348 return "DW_OP_reg6";
2350 return "DW_OP_reg7";
2352 return "DW_OP_reg8";
2354 return "DW_OP_reg9";
2356 return "DW_OP_reg10";
2358 return "DW_OP_reg11";
2360 return "DW_OP_reg12";
2362 return "DW_OP_reg13";
2364 return "DW_OP_reg14";
2366 return "DW_OP_reg15";
2368 return "DW_OP_reg16";
2370 return "DW_OP_reg17";
2372 return "DW_OP_reg18";
2374 return "DW_OP_reg19";
2376 return "DW_OP_reg20";
2378 return "DW_OP_reg21";
2380 return "DW_OP_reg22";
2382 return "DW_OP_reg23";
2384 return "DW_OP_reg24";
2386 return "DW_OP_reg25";
2388 return "DW_OP_reg26";
2390 return "DW_OP_reg27";
2392 return "DW_OP_reg28";
2394 return "DW_OP_reg29";
2396 return "DW_OP_reg30";
2398 return "DW_OP_reg31";
2400 return "DW_OP_breg0";
2402 return "DW_OP_breg1";
2404 return "DW_OP_breg2";
2406 return "DW_OP_breg3";
2408 return "DW_OP_breg4";
2410 return "DW_OP_breg5";
2412 return "DW_OP_breg6";
2414 return "DW_OP_breg7";
2416 return "DW_OP_breg8";
2418 return "DW_OP_breg9";
2420 return "DW_OP_breg10";
2422 return "DW_OP_breg11";
2424 return "DW_OP_breg12";
2426 return "DW_OP_breg13";
2428 return "DW_OP_breg14";
2430 return "DW_OP_breg15";
2432 return "DW_OP_breg16";
2434 return "DW_OP_breg17";
2436 return "DW_OP_breg18";
2438 return "DW_OP_breg19";
2440 return "DW_OP_breg20";
2442 return "DW_OP_breg21";
2444 return "DW_OP_breg22";
2446 return "DW_OP_breg23";
2448 return "DW_OP_breg24";
2450 return "DW_OP_breg25";
2452 return "DW_OP_breg26";
2454 return "DW_OP_breg27";
2456 return "DW_OP_breg28";
2458 return "DW_OP_breg29";
2460 return "DW_OP_breg30";
2462 return "DW_OP_breg31";
2464 return "DW_OP_regx";
2466 return "DW_OP_fbreg";
2468 return "DW_OP_bregx";
2470 return "DW_OP_piece";
2471 case DW_OP_deref_size:
2472 return "DW_OP_deref_size";
2473 case DW_OP_xderef_size:
2474 return "DW_OP_xderef_size";
2478 return "OP_<unknown>";
2482 /* Return a pointer to a newly allocated location description. Location
2483 descriptions are simple expression terms that can be strung
2484 together to form more complicated location (address) descriptions. */
2486 static inline dw_loc_descr_ref
2487 new_loc_descr (op, oprnd1, oprnd2)
2488 register enum dwarf_location_atom op;
2489 register unsigned long oprnd1;
2490 register unsigned long oprnd2;
2492 /* Use xcalloc here so we clear out all of the long_long constant in
2494 register dw_loc_descr_ref descr
2495 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2497 descr->dw_loc_opc = op;
2498 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2499 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2500 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2501 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2506 /* Add a location description term to a location description expression. */
2509 add_loc_descr (list_head, descr)
2510 register dw_loc_descr_ref *list_head;
2511 register dw_loc_descr_ref descr;
2513 register dw_loc_descr_ref *d;
2515 /* Find the end of the chain. */
2516 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2522 /* Return the size of a location descriptor. */
2524 static unsigned long
2525 size_of_loc_descr (loc)
2526 register dw_loc_descr_ref loc;
2528 register unsigned long size = 1;
2530 switch (loc->dw_loc_opc)
2533 size += DWARF2_ADDR_SIZE;
2552 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2555 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2560 case DW_OP_plus_uconst:
2561 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2599 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2602 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2605 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2608 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2609 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2612 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2614 case DW_OP_deref_size:
2615 case DW_OP_xderef_size:
2625 /* Return the size of a series of location descriptors. */
2627 static unsigned long
2629 register dw_loc_descr_ref loc;
2631 register unsigned long size = 0;
2633 for (; loc != NULL; loc = loc->dw_loc_next)
2634 size += size_of_loc_descr (loc);
2639 /* Output location description stack opcode's operands (if any). */
2642 output_loc_operands (loc)
2643 register dw_loc_descr_ref loc;
2645 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2646 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2648 switch (loc->dw_loc_opc)
2650 #ifdef DWARF2_DEBUGGING_INFO
2652 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
2653 fputc ('\n', asm_out_file);
2657 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2658 fputc ('\n', asm_out_file);
2662 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
2663 fputc ('\n', asm_out_file);
2668 fputc ('\n', asm_out_file);
2672 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2673 fputc ('\n', asm_out_file);
2685 /* We currently don't make any attempt to make sure these are
2686 aligned properly like we do for the main unwind info, so
2687 don't support emitting things larger than a byte if we're
2688 only doing unwinding. */
2693 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2694 fputc ('\n', asm_out_file);
2697 output_uleb128 (val1->v.val_unsigned);
2698 fputc ('\n', asm_out_file);
2701 output_sleb128 (val1->v.val_int);
2702 fputc ('\n', asm_out_file);
2705 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
2706 fputc ('\n', asm_out_file);
2708 case DW_OP_plus_uconst:
2709 output_uleb128 (val1->v.val_unsigned);
2710 fputc ('\n', asm_out_file);
2744 output_sleb128 (val1->v.val_int);
2745 fputc ('\n', asm_out_file);
2748 output_uleb128 (val1->v.val_unsigned);
2749 fputc ('\n', asm_out_file);
2752 output_sleb128 (val1->v.val_int);
2753 fputc ('\n', asm_out_file);
2756 output_uleb128 (val1->v.val_unsigned);
2757 fputc ('\n', asm_out_file);
2758 output_sleb128 (val2->v.val_int);
2759 fputc ('\n', asm_out_file);
2762 output_uleb128 (val1->v.val_unsigned);
2763 fputc ('\n', asm_out_file);
2765 case DW_OP_deref_size:
2766 case DW_OP_xderef_size:
2767 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2768 fputc ('\n', asm_out_file);
2771 /* Other codes have no operands. */
2776 /* Output a sequence of location operations. */
2779 output_loc_sequence (loc)
2780 dw_loc_descr_ref loc;
2782 for (; loc != NULL; loc = loc->dw_loc_next)
2784 /* Output the opcode. */
2785 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
2787 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
2788 dwarf_stack_op_name (loc->dw_loc_opc));
2790 fputc ('\n', asm_out_file);
2792 /* Output the operand(s) (if any). */
2793 output_loc_operands (loc);
2797 /* This routine will generate the correct assembly data for a location
2798 description based on a cfi entry with a complex address. */
2801 output_cfa_loc (cfi)
2804 dw_loc_descr_ref loc;
2807 /* Output the size of the block. */
2808 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2809 size = size_of_locs (loc);
2810 output_uleb128 (size);
2811 fputc ('\n', asm_out_file);
2813 /* Now output the operations themselves. */
2814 output_loc_sequence (loc);
2817 /* This function builds a dwarf location descriptor seqeunce from
2818 a dw_cfa_location. */
2820 static struct dw_loc_descr_struct *
2822 dw_cfa_location *cfa;
2824 struct dw_loc_descr_struct *head, *tmp;
2826 if (cfa->indirect == 0)
2829 if (cfa->base_offset)
2832 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2834 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2836 else if (cfa->reg <= 31)
2837 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2839 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2840 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2841 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2842 add_loc_descr (&head, tmp);
2843 if (cfa->offset != 0)
2845 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2846 add_loc_descr (&head, tmp);
2851 /* This function fills in aa dw_cfa_location structure from a
2852 dwarf location descriptor sequence. */
2855 get_cfa_from_loc_descr (cfa, loc)
2856 dw_cfa_location *cfa;
2857 struct dw_loc_descr_struct *loc;
2859 struct dw_loc_descr_struct *ptr;
2861 cfa->base_offset = 0;
2865 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2867 enum dwarf_location_atom op = ptr->dw_loc_opc;
2902 cfa->reg = op - DW_OP_reg0;
2905 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2939 cfa->reg = op - DW_OP_breg0;
2940 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2943 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2944 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2949 case DW_OP_plus_uconst:
2950 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2953 fatal ("DW_LOC_OP %s not implememnted yet.\n",
2954 dwarf_stack_op_name (ptr->dw_loc_opc));
2958 #endif /* .debug_frame support */
2960 /* And now, the support for symbolic debugging information. */
2961 #ifdef DWARF2_DEBUGGING_INFO
2963 /* NOTE: In the comments in this file, many references are made to
2964 "Debugging Information Entries". This term is abbreviated as `DIE'
2965 throughout the remainder of this file. */
2967 /* An internal representation of the DWARF output is built, and then
2968 walked to generate the DWARF debugging info. The walk of the internal
2969 representation is done after the entire program has been compiled.
2970 The types below are used to describe the internal representation. */
2972 /* Various DIE's use offsets relative to the beginning of the
2973 .debug_info section to refer to each other. */
2975 typedef long int dw_offset;
2977 /* Define typedefs here to avoid circular dependencies. */
2979 typedef struct dw_attr_struct *dw_attr_ref;
2980 typedef struct dw_line_info_struct *dw_line_info_ref;
2981 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
2982 typedef struct pubname_struct *pubname_ref;
2983 typedef dw_die_ref *arange_ref;
2985 /* Each entry in the line_info_table maintains the file and
2986 line number associated with the label generated for that
2987 entry. The label gives the PC value associated with
2988 the line number entry. */
2990 typedef struct dw_line_info_struct
2992 unsigned long dw_file_num;
2993 unsigned long dw_line_num;
2997 /* Line information for functions in separate sections; each one gets its
2999 typedef struct dw_separate_line_info_struct
3001 unsigned long dw_file_num;
3002 unsigned long dw_line_num;
3003 unsigned long function;
3005 dw_separate_line_info_entry;
3007 /* Each DIE attribute has a field specifying the attribute kind,
3008 a link to the next attribute in the chain, and an attribute value.
3009 Attributes are typically linked below the DIE they modify. */
3011 typedef struct dw_attr_struct
3013 enum dwarf_attribute dw_attr;
3014 dw_attr_ref dw_attr_next;
3015 dw_val_node dw_attr_val;
3019 /* The Debugging Information Entry (DIE) structure */
3021 typedef struct die_struct
3023 enum dwarf_tag die_tag;
3025 dw_attr_ref die_attr;
3026 dw_die_ref die_parent;
3027 dw_die_ref die_child;
3029 dw_offset die_offset;
3030 unsigned long die_abbrev;
3035 /* The pubname structure */
3037 typedef struct pubname_struct
3044 /* The limbo die list structure. */
3045 typedef struct limbo_die_struct
3048 struct limbo_die_struct *next;
3052 /* How to start an assembler comment. */
3053 #ifndef ASM_COMMENT_START
3054 #define ASM_COMMENT_START ";#"
3057 /* Define a macro which returns non-zero for a TYPE_DECL which was
3058 implicitly generated for a tagged type.
3060 Note that unlike the gcc front end (which generates a NULL named
3061 TYPE_DECL node for each complete tagged type, each array type, and
3062 each function type node created) the g++ front end generates a
3063 _named_ TYPE_DECL node for each tagged type node created.
3064 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3065 generate a DW_TAG_typedef DIE for them. */
3067 #define TYPE_DECL_IS_STUB(decl) \
3068 (DECL_NAME (decl) == NULL_TREE \
3069 || (DECL_ARTIFICIAL (decl) \
3070 && is_tagged_type (TREE_TYPE (decl)) \
3071 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3072 /* This is necessary for stub decls that \
3073 appear in nested inline functions. */ \
3074 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3075 && (decl_ultimate_origin (decl) \
3076 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3078 /* Information concerning the compilation unit's programming
3079 language, and compiler version. */
3081 extern int flag_traditional;
3083 /* Fixed size portion of the DWARF compilation unit header. */
3084 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3086 /* Fixed size portion of debugging line information prolog. */
3087 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3089 /* Fixed size portion of public names info. */
3090 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3092 /* Fixed size portion of the address range info. */
3093 #define DWARF_ARANGES_HEADER_SIZE \
3094 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3095 - DWARF_OFFSET_SIZE)
3097 /* Size of padding portion in the address range info. It must be
3098 aligned to twice the pointer size. */
3099 #define DWARF_ARANGES_PAD_SIZE \
3100 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3101 - (2 * DWARF_OFFSET_SIZE + 4))
3103 /* The default is to have gcc emit the line number tables. */
3104 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3105 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3108 /* Define the architecture-dependent minimum instruction length (in bytes).
3109 In this implementation of DWARF, this field is used for information
3110 purposes only. Since GCC generates assembly language, we have
3111 no a priori knowledge of how many instruction bytes are generated
3112 for each source line, and therefore can use only the DW_LNE_set_address
3113 and DW_LNS_fixed_advance_pc line information commands. */
3115 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3116 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3119 /* Minimum line offset in a special line info. opcode.
3120 This value was chosen to give a reasonable range of values. */
3121 #define DWARF_LINE_BASE -10
3123 /* First special line opcde - leave room for the standard opcodes. */
3124 #define DWARF_LINE_OPCODE_BASE 10
3126 /* Range of line offsets in a special line info. opcode. */
3127 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3129 /* Flag that indicates the initial value of the is_stmt_start flag.
3130 In the present implementation, we do not mark any lines as
3131 the beginning of a source statement, because that information
3132 is not made available by the GCC front-end. */
3133 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3135 /* This location is used by calc_die_sizes() to keep track
3136 the offset of each DIE within the .debug_info section. */
3137 static unsigned long next_die_offset;
3139 /* Record the root of the DIE's built for the current compilation unit. */
3140 static dw_die_ref comp_unit_die;
3142 /* A list of DIEs with a NULL parent waiting to be relocated. */
3143 static limbo_die_node *limbo_die_list = 0;
3145 /* Pointer to an array of filenames referenced by this compilation unit. */
3146 static char **file_table;
3148 /* Total number of entries in the table (i.e. array) pointed to by
3149 `file_table'. This is the *total* and includes both used and unused
3151 static unsigned file_table_allocated;
3153 /* Number of entries in the file_table which are actually in use. */
3154 static unsigned file_table_in_use;
3156 /* Size (in elements) of increments by which we may expand the filename
3158 #define FILE_TABLE_INCREMENT 64
3160 /* Local pointer to the name of the main input file. Initialized in
3162 static const char *primary_filename;
3164 /* A pointer to the base of a table of references to DIE's that describe
3165 declarations. The table is indexed by DECL_UID() which is a unique
3166 number identifying each decl. */
3167 static dw_die_ref *decl_die_table;
3169 /* Number of elements currently allocated for the decl_die_table. */
3170 static unsigned decl_die_table_allocated;
3172 /* Number of elements in decl_die_table currently in use. */
3173 static unsigned decl_die_table_in_use;
3175 /* Size (in elements) of increments by which we may expand the
3177 #define DECL_DIE_TABLE_INCREMENT 256
3179 /* A pointer to the base of a table of references to declaration
3180 scopes. This table is a display which tracks the nesting
3181 of declaration scopes at the current scope and containing
3182 scopes. This table is used to find the proper place to
3183 define type declaration DIE's. */
3184 static tree *decl_scope_table;
3186 /* Number of elements currently allocated for the decl_scope_table. */
3187 static int decl_scope_table_allocated;
3189 /* Current level of nesting of declaration scopes. */
3190 static int decl_scope_depth;
3192 /* Size (in elements) of increments by which we may expand the
3193 decl_scope_table. */
3194 #define DECL_SCOPE_TABLE_INCREMENT 64
3196 /* A pointer to the base of a list of references to DIE's that
3197 are uniquely identified by their tag, presence/absence of
3198 children DIE's, and list of attribute/value pairs. */
3199 static dw_die_ref *abbrev_die_table;
3201 /* Number of elements currently allocated for abbrev_die_table. */
3202 static unsigned abbrev_die_table_allocated;
3204 /* Number of elements in type_die_table currently in use. */
3205 static unsigned abbrev_die_table_in_use;
3207 /* Size (in elements) of increments by which we may expand the
3208 abbrev_die_table. */
3209 #define ABBREV_DIE_TABLE_INCREMENT 256
3211 /* A pointer to the base of a table that contains line information
3212 for each source code line in .text in the compilation unit. */
3213 static dw_line_info_ref line_info_table;
3215 /* Number of elements currently allocated for line_info_table. */
3216 static unsigned line_info_table_allocated;
3218 /* Number of elements in separate_line_info_table currently in use. */
3219 static unsigned separate_line_info_table_in_use;
3221 /* A pointer to the base of a table that contains line information
3222 for each source code line outside of .text in the compilation unit. */
3223 static dw_separate_line_info_ref separate_line_info_table;
3225 /* Number of elements currently allocated for separate_line_info_table. */
3226 static unsigned separate_line_info_table_allocated;
3228 /* Number of elements in line_info_table currently in use. */
3229 static unsigned line_info_table_in_use;
3231 /* Size (in elements) of increments by which we may expand the
3233 #define LINE_INFO_TABLE_INCREMENT 1024
3235 /* A pointer to the base of a table that contains a list of publicly
3236 accessible names. */
3237 static pubname_ref pubname_table;
3239 /* Number of elements currently allocated for pubname_table. */
3240 static unsigned pubname_table_allocated;
3242 /* Number of elements in pubname_table currently in use. */
3243 static unsigned pubname_table_in_use;
3245 /* Size (in elements) of increments by which we may expand the
3247 #define PUBNAME_TABLE_INCREMENT 64
3249 /* A pointer to the base of a table that contains a list of publicly
3250 accessible names. */
3251 static arange_ref arange_table;
3253 /* Number of elements currently allocated for arange_table. */
3254 static unsigned arange_table_allocated;
3256 /* Number of elements in arange_table currently in use. */
3257 static unsigned arange_table_in_use;
3259 /* Size (in elements) of increments by which we may expand the
3261 #define ARANGE_TABLE_INCREMENT 64
3263 /* A pointer to the base of a list of incomplete types which might be
3264 completed at some later time. */
3266 static tree *incomplete_types_list;
3268 /* Number of elements currently allocated for the incomplete_types_list. */
3269 static unsigned incomplete_types_allocated;
3271 /* Number of elements of incomplete_types_list currently in use. */
3272 static unsigned incomplete_types;
3274 /* Size (in elements) of increments by which we may expand the incomplete
3275 types list. Actually, a single hunk of space of this size should
3276 be enough for most typical programs. */
3277 #define INCOMPLETE_TYPES_INCREMENT 64
3279 /* Record whether the function being analyzed contains inlined functions. */
3280 static int current_function_has_inlines;
3281 #if 0 && defined (MIPS_DEBUGGING_INFO)
3282 static int comp_unit_has_inlines;
3285 /* Array of RTXes referenced by the debugging information, which therefore
3286 must be kept around forever. We do this rather than perform GC on
3287 the dwarf info because almost all of the dwarf info lives forever, and
3288 it's easier to support non-GC frontends this way. */
3289 static varray_type used_rtx_varray;
3291 /* Forward declarations for functions defined in this file. */
3293 static int is_pseudo_reg PARAMS ((rtx));
3294 static tree type_main_variant PARAMS ((tree));
3295 static int is_tagged_type PARAMS ((tree));
3296 static const char *dwarf_tag_name PARAMS ((unsigned));
3297 static const char *dwarf_attr_name PARAMS ((unsigned));
3298 static const char *dwarf_form_name PARAMS ((unsigned));
3300 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3302 static tree decl_ultimate_origin PARAMS ((tree));
3303 static tree block_ultimate_origin PARAMS ((tree));
3304 static tree decl_class_context PARAMS ((tree));
3305 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3306 static void add_AT_flag PARAMS ((dw_die_ref,
3307 enum dwarf_attribute,
3309 static void add_AT_int PARAMS ((dw_die_ref,
3310 enum dwarf_attribute, long));
3311 static void add_AT_unsigned PARAMS ((dw_die_ref,
3312 enum dwarf_attribute,
3314 static void add_AT_long_long PARAMS ((dw_die_ref,
3315 enum dwarf_attribute,
3318 static void add_AT_float PARAMS ((dw_die_ref,
3319 enum dwarf_attribute,
3321 static void add_AT_string PARAMS ((dw_die_ref,
3322 enum dwarf_attribute,
3324 static void add_AT_die_ref PARAMS ((dw_die_ref,
3325 enum dwarf_attribute,
3327 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3328 enum dwarf_attribute,
3330 static void add_AT_loc PARAMS ((dw_die_ref,
3331 enum dwarf_attribute,
3333 static void add_AT_addr PARAMS ((dw_die_ref,
3334 enum dwarf_attribute,
3336 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3337 enum dwarf_attribute,
3339 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3340 enum dwarf_attribute,
3342 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3343 enum dwarf_attribute));
3344 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3345 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3346 static const char *get_AT_string PARAMS ((dw_die_ref,
3347 enum dwarf_attribute));
3348 static int get_AT_flag PARAMS ((dw_die_ref,
3349 enum dwarf_attribute));
3350 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3351 enum dwarf_attribute));
3352 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3353 enum dwarf_attribute));
3354 static int is_c_family PARAMS ((void));
3355 static int is_java PARAMS ((void));
3356 static int is_fortran PARAMS ((void));
3357 static void remove_AT PARAMS ((dw_die_ref,
3358 enum dwarf_attribute));
3359 static void remove_children PARAMS ((dw_die_ref));
3360 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3361 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3362 static dw_die_ref lookup_type_die PARAMS ((tree));
3363 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3364 static dw_die_ref lookup_decl_die PARAMS ((tree));
3365 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3366 static void print_spaces PARAMS ((FILE *));
3367 static void print_die PARAMS ((dw_die_ref, FILE *));
3368 static void print_dwarf_line_table PARAMS ((FILE *));
3369 static void reverse_die_lists PARAMS ((dw_die_ref));
3370 static void reverse_all_dies PARAMS ((dw_die_ref));
3371 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3372 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3373 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3374 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3375 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3376 static void compute_section_prefix PARAMS ((dw_die_ref));
3377 static int is_type_die PARAMS ((dw_die_ref));
3378 static int is_comdat_die PARAMS ((dw_die_ref));
3379 static int is_symbol_die PARAMS ((dw_die_ref));
3380 static char *gen_internal_sym PARAMS ((void));
3381 static void assign_symbol_names PARAMS ((dw_die_ref));
3382 static void break_out_includes PARAMS ((dw_die_ref));
3383 static void add_sibling_attributes PARAMS ((dw_die_ref));
3384 static void build_abbrev_table PARAMS ((dw_die_ref));
3385 static unsigned long size_of_string PARAMS ((const char *));
3386 static int constant_size PARAMS ((long unsigned));
3387 static unsigned long size_of_die PARAMS ((dw_die_ref));
3388 static void calc_die_sizes PARAMS ((dw_die_ref));
3389 static void mark_dies PARAMS ((dw_die_ref));
3390 static void unmark_dies PARAMS ((dw_die_ref));
3391 static unsigned long size_of_line_prolog PARAMS ((void));
3392 static unsigned long size_of_pubnames PARAMS ((void));
3393 static unsigned long size_of_aranges PARAMS ((void));
3394 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3395 static void output_value_format PARAMS ((dw_attr_ref));
3396 static void output_abbrev_section PARAMS ((void));
3397 static void output_die_symbol PARAMS ((dw_die_ref));
3398 static void output_symbolic_ref PARAMS ((dw_die_ref));
3399 static void output_die PARAMS ((dw_die_ref));
3400 static void output_compilation_unit_header PARAMS ((void));
3401 static void output_comp_unit PARAMS ((dw_die_ref));
3402 static const char *dwarf2_name PARAMS ((tree, int));
3403 static void add_pubname PARAMS ((tree, dw_die_ref));
3404 static void output_pubnames PARAMS ((void));
3405 static void add_arange PARAMS ((tree, dw_die_ref));
3406 static void output_aranges PARAMS ((void));
3407 static void output_line_info PARAMS ((void));
3408 static dw_die_ref base_type_die PARAMS ((tree));
3409 static tree root_type PARAMS ((tree));
3410 static int is_base_type PARAMS ((tree));
3411 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3412 static int type_is_enum PARAMS ((tree));
3413 static unsigned int reg_number PARAMS ((rtx));
3414 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3415 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3416 static int is_based_loc PARAMS ((rtx));
3417 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3418 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3419 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3420 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3421 static tree field_type PARAMS ((tree));
3422 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3423 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3424 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3425 static void add_AT_location_description PARAMS ((dw_die_ref,
3426 enum dwarf_attribute, rtx));
3427 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3428 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3429 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3430 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3431 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3432 static void add_bound_info PARAMS ((dw_die_ref,
3433 enum dwarf_attribute, tree));
3434 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3435 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3436 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3437 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3438 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3439 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3440 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3441 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3442 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3443 static void push_decl_scope PARAMS ((tree));
3444 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3445 static void pop_decl_scope PARAMS ((void));
3446 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3448 static const char *type_tag PARAMS ((tree));
3449 static tree member_declared_type PARAMS ((tree));
3451 static const char *decl_start_label PARAMS ((tree));
3453 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3454 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3456 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3458 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3459 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3460 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3461 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3462 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3463 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3464 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3465 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3466 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3467 static void gen_label_die PARAMS ((tree, dw_die_ref));
3468 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3469 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3470 static void gen_field_die PARAMS ((tree, dw_die_ref));
3471 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3472 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3473 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3474 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3475 static void gen_member_die PARAMS ((tree, dw_die_ref));
3476 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3477 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3478 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3479 static void gen_type_die PARAMS ((tree, dw_die_ref));
3480 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3481 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3482 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3483 static int is_redundant_typedef PARAMS ((tree));
3484 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3485 static unsigned lookup_filename PARAMS ((const char *));
3486 static void add_incomplete_type PARAMS ((tree));
3487 static void retry_incomplete_types PARAMS ((void));
3488 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3489 static void gen_abstract_function PARAMS ((tree));
3490 static rtx save_rtx PARAMS ((rtx));
3491 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3493 /* Section names used to hold DWARF debugging information. */
3494 #ifndef DEBUG_INFO_SECTION
3495 #define DEBUG_INFO_SECTION ".debug_info"
3497 #ifndef ABBREV_SECTION
3498 #define ABBREV_SECTION ".debug_abbrev"
3500 #ifndef ARANGES_SECTION
3501 #define ARANGES_SECTION ".debug_aranges"
3503 #ifndef DW_MACINFO_SECTION
3504 #define DW_MACINFO_SECTION ".debug_macinfo"
3506 #ifndef DEBUG_LINE_SECTION
3507 #define DEBUG_LINE_SECTION ".debug_line"
3510 #define LOC_SECTION ".debug_loc"
3512 #ifndef PUBNAMES_SECTION
3513 #define PUBNAMES_SECTION ".debug_pubnames"
3516 #define STR_SECTION ".debug_str"
3519 /* Standard ELF section names for compiled code and data. */
3520 #ifndef TEXT_SECTION
3521 #define TEXT_SECTION ".text"
3523 #ifndef DATA_SECTION
3524 #define DATA_SECTION ".data"
3527 #define BSS_SECTION ".bss"
3530 /* Labels we insert at beginning sections we can reference instead of
3531 the section names themselves. */
3533 #ifndef TEXT_SECTION_LABEL
3534 #define TEXT_SECTION_LABEL "Ltext"
3536 #ifndef DEBUG_LINE_SECTION_LABEL
3537 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3539 #ifndef DEBUG_INFO_SECTION_LABEL
3540 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3542 #ifndef ABBREV_SECTION_LABEL
3543 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3546 /* Definitions of defaults for formats and names of various special
3547 (artificial) labels which may be generated within this file (when the -g
3548 options is used and DWARF_DEBUGGING_INFO is in effect.
3549 If necessary, these may be overridden from within the tm.h file, but
3550 typically, overriding these defaults is unnecessary. */
3552 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3553 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3554 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3555 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3556 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3558 #ifndef TEXT_END_LABEL
3559 #define TEXT_END_LABEL "Letext"
3561 #ifndef DATA_END_LABEL
3562 #define DATA_END_LABEL "Ledata"
3564 #ifndef BSS_END_LABEL
3565 #define BSS_END_LABEL "Lebss"
3567 #ifndef INSN_LABEL_FMT
3568 #define INSN_LABEL_FMT "LI%u_"
3570 #ifndef BLOCK_BEGIN_LABEL
3571 #define BLOCK_BEGIN_LABEL "LBB"
3573 #ifndef BLOCK_END_LABEL
3574 #define BLOCK_END_LABEL "LBE"
3576 #ifndef BODY_BEGIN_LABEL
3577 #define BODY_BEGIN_LABEL "Lbb"
3579 #ifndef BODY_END_LABEL
3580 #define BODY_END_LABEL "Lbe"
3582 #ifndef LINE_CODE_LABEL
3583 #define LINE_CODE_LABEL "LM"
3585 #ifndef SEPARATE_LINE_CODE_LABEL
3586 #define SEPARATE_LINE_CODE_LABEL "LSM"
3589 /* We allow a language front-end to designate a function that is to be
3590 called to "demangle" any name before it it put into a DIE. */
3592 static const char *(*demangle_name_func) PARAMS ((const char *));
3595 dwarf2out_set_demangle_name_func (func)
3596 const char *(*func) PARAMS ((const char *));
3598 demangle_name_func = func;
3601 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3602 that means adding it to used_rtx_varray. If not, that means making
3603 a copy on the permanent_obstack. */
3610 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3613 push_obstacks_nochange ();
3614 end_temporary_allocation ();
3615 orig = copy_rtx (orig);
3622 /* Test if rtl node points to a pseudo register. */
3628 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3629 || (GET_CODE (rtl) == SUBREG
3630 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3633 /* Return a reference to a type, with its const and volatile qualifiers
3637 type_main_variant (type)
3640 type = TYPE_MAIN_VARIANT (type);
3642 /* There really should be only one main variant among any group of variants
3643 of a given type (and all of the MAIN_VARIANT values for all members of
3644 the group should point to that one type) but sometimes the C front-end
3645 messes this up for array types, so we work around that bug here. */
3647 if (TREE_CODE (type) == ARRAY_TYPE)
3648 while (type != TYPE_MAIN_VARIANT (type))
3649 type = TYPE_MAIN_VARIANT (type);
3654 /* Return non-zero if the given type node represents a tagged type. */
3657 is_tagged_type (type)
3660 register enum tree_code code = TREE_CODE (type);
3662 return (code == RECORD_TYPE || code == UNION_TYPE
3663 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3666 /* Convert a DIE tag into its string name. */
3669 dwarf_tag_name (tag)
3670 register unsigned tag;
3674 case DW_TAG_padding:
3675 return "DW_TAG_padding";
3676 case DW_TAG_array_type:
3677 return "DW_TAG_array_type";
3678 case DW_TAG_class_type:
3679 return "DW_TAG_class_type";
3680 case DW_TAG_entry_point:
3681 return "DW_TAG_entry_point";
3682 case DW_TAG_enumeration_type:
3683 return "DW_TAG_enumeration_type";
3684 case DW_TAG_formal_parameter:
3685 return "DW_TAG_formal_parameter";
3686 case DW_TAG_imported_declaration:
3687 return "DW_TAG_imported_declaration";
3689 return "DW_TAG_label";
3690 case DW_TAG_lexical_block:
3691 return "DW_TAG_lexical_block";
3693 return "DW_TAG_member";
3694 case DW_TAG_pointer_type:
3695 return "DW_TAG_pointer_type";
3696 case DW_TAG_reference_type:
3697 return "DW_TAG_reference_type";
3698 case DW_TAG_compile_unit:
3699 return "DW_TAG_compile_unit";
3700 case DW_TAG_string_type:
3701 return "DW_TAG_string_type";
3702 case DW_TAG_structure_type:
3703 return "DW_TAG_structure_type";
3704 case DW_TAG_subroutine_type:
3705 return "DW_TAG_subroutine_type";
3706 case DW_TAG_typedef:
3707 return "DW_TAG_typedef";
3708 case DW_TAG_union_type:
3709 return "DW_TAG_union_type";
3710 case DW_TAG_unspecified_parameters:
3711 return "DW_TAG_unspecified_parameters";
3712 case DW_TAG_variant:
3713 return "DW_TAG_variant";
3714 case DW_TAG_common_block:
3715 return "DW_TAG_common_block";
3716 case DW_TAG_common_inclusion:
3717 return "DW_TAG_common_inclusion";
3718 case DW_TAG_inheritance:
3719 return "DW_TAG_inheritance";
3720 case DW_TAG_inlined_subroutine:
3721 return "DW_TAG_inlined_subroutine";
3723 return "DW_TAG_module";
3724 case DW_TAG_ptr_to_member_type:
3725 return "DW_TAG_ptr_to_member_type";
3726 case DW_TAG_set_type:
3727 return "DW_TAG_set_type";
3728 case DW_TAG_subrange_type:
3729 return "DW_TAG_subrange_type";
3730 case DW_TAG_with_stmt:
3731 return "DW_TAG_with_stmt";
3732 case DW_TAG_access_declaration:
3733 return "DW_TAG_access_declaration";
3734 case DW_TAG_base_type:
3735 return "DW_TAG_base_type";
3736 case DW_TAG_catch_block:
3737 return "DW_TAG_catch_block";
3738 case DW_TAG_const_type:
3739 return "DW_TAG_const_type";
3740 case DW_TAG_constant:
3741 return "DW_TAG_constant";
3742 case DW_TAG_enumerator:
3743 return "DW_TAG_enumerator";
3744 case DW_TAG_file_type:
3745 return "DW_TAG_file_type";
3747 return "DW_TAG_friend";
3748 case DW_TAG_namelist:
3749 return "DW_TAG_namelist";
3750 case DW_TAG_namelist_item:
3751 return "DW_TAG_namelist_item";
3752 case DW_TAG_packed_type:
3753 return "DW_TAG_packed_type";
3754 case DW_TAG_subprogram:
3755 return "DW_TAG_subprogram";
3756 case DW_TAG_template_type_param:
3757 return "DW_TAG_template_type_param";
3758 case DW_TAG_template_value_param:
3759 return "DW_TAG_template_value_param";
3760 case DW_TAG_thrown_type:
3761 return "DW_TAG_thrown_type";
3762 case DW_TAG_try_block:
3763 return "DW_TAG_try_block";
3764 case DW_TAG_variant_part:
3765 return "DW_TAG_variant_part";
3766 case DW_TAG_variable:
3767 return "DW_TAG_variable";
3768 case DW_TAG_volatile_type:
3769 return "DW_TAG_volatile_type";
3770 case DW_TAG_MIPS_loop:
3771 return "DW_TAG_MIPS_loop";
3772 case DW_TAG_format_label:
3773 return "DW_TAG_format_label";
3774 case DW_TAG_function_template:
3775 return "DW_TAG_function_template";
3776 case DW_TAG_class_template:
3777 return "DW_TAG_class_template";
3778 case DW_TAG_GNU_BINCL:
3779 return "DW_TAG_GNU_BINCL";
3780 case DW_TAG_GNU_EINCL:
3781 return "DW_TAG_GNU_EINCL";
3783 return "DW_TAG_<unknown>";
3787 /* Convert a DWARF attribute code into its string name. */
3790 dwarf_attr_name (attr)
3791 register unsigned attr;
3796 return "DW_AT_sibling";
3797 case DW_AT_location:
3798 return "DW_AT_location";
3800 return "DW_AT_name";
3801 case DW_AT_ordering:
3802 return "DW_AT_ordering";
3803 case DW_AT_subscr_data:
3804 return "DW_AT_subscr_data";
3805 case DW_AT_byte_size:
3806 return "DW_AT_byte_size";
3807 case DW_AT_bit_offset:
3808 return "DW_AT_bit_offset";
3809 case DW_AT_bit_size:
3810 return "DW_AT_bit_size";
3811 case DW_AT_element_list:
3812 return "DW_AT_element_list";
3813 case DW_AT_stmt_list:
3814 return "DW_AT_stmt_list";
3816 return "DW_AT_low_pc";
3818 return "DW_AT_high_pc";
3819 case DW_AT_language:
3820 return "DW_AT_language";
3822 return "DW_AT_member";
3824 return "DW_AT_discr";
3825 case DW_AT_discr_value:
3826 return "DW_AT_discr_value";
3827 case DW_AT_visibility:
3828 return "DW_AT_visibility";
3830 return "DW_AT_import";
3831 case DW_AT_string_length:
3832 return "DW_AT_string_length";
3833 case DW_AT_common_reference:
3834 return "DW_AT_common_reference";
3835 case DW_AT_comp_dir:
3836 return "DW_AT_comp_dir";
3837 case DW_AT_const_value:
3838 return "DW_AT_const_value";
3839 case DW_AT_containing_type:
3840 return "DW_AT_containing_type";
3841 case DW_AT_default_value:
3842 return "DW_AT_default_value";
3844 return "DW_AT_inline";
3845 case DW_AT_is_optional:
3846 return "DW_AT_is_optional";
3847 case DW_AT_lower_bound:
3848 return "DW_AT_lower_bound";
3849 case DW_AT_producer:
3850 return "DW_AT_producer";
3851 case DW_AT_prototyped:
3852 return "DW_AT_prototyped";
3853 case DW_AT_return_addr:
3854 return "DW_AT_return_addr";
3855 case DW_AT_start_scope:
3856 return "DW_AT_start_scope";
3857 case DW_AT_stride_size:
3858 return "DW_AT_stride_size";
3859 case DW_AT_upper_bound:
3860 return "DW_AT_upper_bound";
3861 case DW_AT_abstract_origin:
3862 return "DW_AT_abstract_origin";
3863 case DW_AT_accessibility:
3864 return "DW_AT_accessibility";
3865 case DW_AT_address_class:
3866 return "DW_AT_address_class";
3867 case DW_AT_artificial:
3868 return "DW_AT_artificial";
3869 case DW_AT_base_types:
3870 return "DW_AT_base_types";
3871 case DW_AT_calling_convention:
3872 return "DW_AT_calling_convention";
3874 return "DW_AT_count";
3875 case DW_AT_data_member_location:
3876 return "DW_AT_data_member_location";
3877 case DW_AT_decl_column:
3878 return "DW_AT_decl_column";
3879 case DW_AT_decl_file:
3880 return "DW_AT_decl_file";
3881 case DW_AT_decl_line:
3882 return "DW_AT_decl_line";
3883 case DW_AT_declaration:
3884 return "DW_AT_declaration";
3885 case DW_AT_discr_list:
3886 return "DW_AT_discr_list";
3887 case DW_AT_encoding:
3888 return "DW_AT_encoding";
3889 case DW_AT_external:
3890 return "DW_AT_external";
3891 case DW_AT_frame_base:
3892 return "DW_AT_frame_base";
3894 return "DW_AT_friend";
3895 case DW_AT_identifier_case:
3896 return "DW_AT_identifier_case";
3897 case DW_AT_macro_info:
3898 return "DW_AT_macro_info";
3899 case DW_AT_namelist_items:
3900 return "DW_AT_namelist_items";
3901 case DW_AT_priority:
3902 return "DW_AT_priority";
3904 return "DW_AT_segment";
3905 case DW_AT_specification:
3906 return "DW_AT_specification";
3907 case DW_AT_static_link:
3908 return "DW_AT_static_link";
3910 return "DW_AT_type";
3911 case DW_AT_use_location:
3912 return "DW_AT_use_location";
3913 case DW_AT_variable_parameter:
3914 return "DW_AT_variable_parameter";
3915 case DW_AT_virtuality:
3916 return "DW_AT_virtuality";
3917 case DW_AT_vtable_elem_location:
3918 return "DW_AT_vtable_elem_location";
3920 case DW_AT_MIPS_fde:
3921 return "DW_AT_MIPS_fde";
3922 case DW_AT_MIPS_loop_begin:
3923 return "DW_AT_MIPS_loop_begin";
3924 case DW_AT_MIPS_tail_loop_begin:
3925 return "DW_AT_MIPS_tail_loop_begin";
3926 case DW_AT_MIPS_epilog_begin:
3927 return "DW_AT_MIPS_epilog_begin";
3928 case DW_AT_MIPS_loop_unroll_factor:
3929 return "DW_AT_MIPS_loop_unroll_factor";
3930 case DW_AT_MIPS_software_pipeline_depth:
3931 return "DW_AT_MIPS_software_pipeline_depth";
3932 case DW_AT_MIPS_linkage_name:
3933 return "DW_AT_MIPS_linkage_name";
3934 case DW_AT_MIPS_stride:
3935 return "DW_AT_MIPS_stride";
3936 case DW_AT_MIPS_abstract_name:
3937 return "DW_AT_MIPS_abstract_name";
3938 case DW_AT_MIPS_clone_origin:
3939 return "DW_AT_MIPS_clone_origin";
3940 case DW_AT_MIPS_has_inlines:
3941 return "DW_AT_MIPS_has_inlines";
3943 case DW_AT_sf_names:
3944 return "DW_AT_sf_names";
3945 case DW_AT_src_info:
3946 return "DW_AT_src_info";
3947 case DW_AT_mac_info:
3948 return "DW_AT_mac_info";
3949 case DW_AT_src_coords:
3950 return "DW_AT_src_coords";
3951 case DW_AT_body_begin:
3952 return "DW_AT_body_begin";
3953 case DW_AT_body_end:
3954 return "DW_AT_body_end";
3956 return "DW_AT_<unknown>";
3960 /* Convert a DWARF value form code into its string name. */
3963 dwarf_form_name (form)
3964 register unsigned form;
3969 return "DW_FORM_addr";
3970 case DW_FORM_block2:
3971 return "DW_FORM_block2";
3972 case DW_FORM_block4:
3973 return "DW_FORM_block4";
3975 return "DW_FORM_data2";
3977 return "DW_FORM_data4";
3979 return "DW_FORM_data8";
3980 case DW_FORM_string:
3981 return "DW_FORM_string";
3983 return "DW_FORM_block";
3984 case DW_FORM_block1:
3985 return "DW_FORM_block1";
3987 return "DW_FORM_data1";
3989 return "DW_FORM_flag";
3991 return "DW_FORM_sdata";
3993 return "DW_FORM_strp";
3995 return "DW_FORM_udata";
3996 case DW_FORM_ref_addr:
3997 return "DW_FORM_ref_addr";
3999 return "DW_FORM_ref1";
4001 return "DW_FORM_ref2";
4003 return "DW_FORM_ref4";
4005 return "DW_FORM_ref8";
4006 case DW_FORM_ref_udata:
4007 return "DW_FORM_ref_udata";
4008 case DW_FORM_indirect:
4009 return "DW_FORM_indirect";
4011 return "DW_FORM_<unknown>";
4015 /* Convert a DWARF type code into its string name. */
4019 dwarf_type_encoding_name (enc)
4020 register unsigned enc;
4024 case DW_ATE_address:
4025 return "DW_ATE_address";
4026 case DW_ATE_boolean:
4027 return "DW_ATE_boolean";
4028 case DW_ATE_complex_float:
4029 return "DW_ATE_complex_float";
4031 return "DW_ATE_float";
4033 return "DW_ATE_signed";
4034 case DW_ATE_signed_char:
4035 return "DW_ATE_signed_char";
4036 case DW_ATE_unsigned:
4037 return "DW_ATE_unsigned";
4038 case DW_ATE_unsigned_char:
4039 return "DW_ATE_unsigned_char";
4041 return "DW_ATE_<unknown>";
4046 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4047 instance of an inlined instance of a decl which is local to an inline
4048 function, so we have to trace all of the way back through the origin chain
4049 to find out what sort of node actually served as the original seed for the
4053 decl_ultimate_origin (decl)
4056 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4057 nodes in the function to point to themselves; ignore that if
4058 we're trying to output the abstract instance of this function. */
4059 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4062 #ifdef ENABLE_CHECKING
4063 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4064 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4065 most distant ancestor, this should never happen. */
4069 return DECL_ABSTRACT_ORIGIN (decl);
4072 /* Determine the "ultimate origin" of a block. The block may be an inlined
4073 instance of an inlined instance of a block which is local to an inline
4074 function, so we have to trace all of the way back through the origin chain
4075 to find out what sort of node actually served as the original seed for the
4079 block_ultimate_origin (block)
4080 register tree block;
4082 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4084 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4085 nodes in the function to point to themselves; ignore that if
4086 we're trying to output the abstract instance of this function. */
4087 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4090 if (immediate_origin == NULL_TREE)
4094 register tree ret_val;
4095 register tree lookahead = immediate_origin;
4099 ret_val = lookahead;
4100 lookahead = (TREE_CODE (ret_val) == BLOCK)
4101 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4104 while (lookahead != NULL && lookahead != ret_val);
4110 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4111 of a virtual function may refer to a base class, so we check the 'this'
4115 decl_class_context (decl)
4118 tree context = NULL_TREE;
4120 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4121 context = DECL_CONTEXT (decl);
4123 context = TYPE_MAIN_VARIANT
4124 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4126 if (context && !TYPE_P (context))
4127 context = NULL_TREE;
4132 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4133 addition order, and correct that in reverse_all_dies. */
4136 add_dwarf_attr (die, attr)
4137 register dw_die_ref die;
4138 register dw_attr_ref attr;
4140 if (die != NULL && attr != NULL)
4142 attr->dw_attr_next = die->die_attr;
4143 die->die_attr = attr;
4147 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4148 static inline dw_val_class
4152 return a->dw_attr_val.val_class;
4155 /* Add a flag value attribute to a DIE. */
4158 add_AT_flag (die, attr_kind, flag)
4159 register dw_die_ref die;
4160 register enum dwarf_attribute attr_kind;
4161 register unsigned flag;
4163 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4165 attr->dw_attr_next = NULL;
4166 attr->dw_attr = attr_kind;
4167 attr->dw_attr_val.val_class = dw_val_class_flag;
4168 attr->dw_attr_val.v.val_flag = flag;
4169 add_dwarf_attr (die, attr);
4172 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4173 static inline unsigned
4175 register dw_attr_ref a;
4177 if (a && AT_class (a) == dw_val_class_flag)
4178 return a->dw_attr_val.v.val_flag;
4183 /* Add a signed integer attribute value to a DIE. */
4186 add_AT_int (die, attr_kind, int_val)
4187 register dw_die_ref die;
4188 register enum dwarf_attribute attr_kind;
4189 register long int int_val;
4191 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4193 attr->dw_attr_next = NULL;
4194 attr->dw_attr = attr_kind;
4195 attr->dw_attr_val.val_class = dw_val_class_const;
4196 attr->dw_attr_val.v.val_int = int_val;
4197 add_dwarf_attr (die, attr);
4200 static inline long int AT_int PARAMS ((dw_attr_ref));
4201 static inline long int
4203 register dw_attr_ref a;
4205 if (a && AT_class (a) == dw_val_class_const)
4206 return a->dw_attr_val.v.val_int;
4211 /* Add an unsigned integer attribute value to a DIE. */
4214 add_AT_unsigned (die, attr_kind, unsigned_val)
4215 register dw_die_ref die;
4216 register enum dwarf_attribute attr_kind;
4217 register unsigned long unsigned_val;
4219 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4221 attr->dw_attr_next = NULL;
4222 attr->dw_attr = attr_kind;
4223 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4224 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4225 add_dwarf_attr (die, attr);
4228 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4229 static inline unsigned long
4231 register dw_attr_ref a;
4233 if (a && AT_class (a) == dw_val_class_unsigned_const)
4234 return a->dw_attr_val.v.val_unsigned;
4239 /* Add an unsigned double integer attribute value to a DIE. */
4242 add_AT_long_long (die, attr_kind, val_hi, val_low)
4243 register dw_die_ref die;
4244 register enum dwarf_attribute attr_kind;
4245 register unsigned long val_hi;
4246 register unsigned long val_low;
4248 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4250 attr->dw_attr_next = NULL;
4251 attr->dw_attr = attr_kind;
4252 attr->dw_attr_val.val_class = dw_val_class_long_long;
4253 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4254 attr->dw_attr_val.v.val_long_long.low = val_low;
4255 add_dwarf_attr (die, attr);
4258 /* Add a floating point attribute value to a DIE and return it. */
4261 add_AT_float (die, attr_kind, length, array)
4262 register dw_die_ref die;
4263 register enum dwarf_attribute attr_kind;
4264 register unsigned length;
4265 register long *array;
4267 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4269 attr->dw_attr_next = NULL;
4270 attr->dw_attr = attr_kind;
4271 attr->dw_attr_val.val_class = dw_val_class_float;
4272 attr->dw_attr_val.v.val_float.length = length;
4273 attr->dw_attr_val.v.val_float.array = array;
4274 add_dwarf_attr (die, attr);
4277 /* Add a string attribute value to a DIE. */
4280 add_AT_string (die, attr_kind, str)
4281 register dw_die_ref die;
4282 register enum dwarf_attribute attr_kind;
4283 register const char *str;
4285 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4287 attr->dw_attr_next = NULL;
4288 attr->dw_attr = attr_kind;
4289 attr->dw_attr_val.val_class = dw_val_class_str;
4290 attr->dw_attr_val.v.val_str = xstrdup (str);
4291 add_dwarf_attr (die, attr);
4294 static inline const char *AT_string PARAMS ((dw_attr_ref));
4295 static inline const char *
4297 register dw_attr_ref a;
4299 if (a && AT_class (a) == dw_val_class_str)
4300 return a->dw_attr_val.v.val_str;
4305 /* Add a DIE reference attribute value to a DIE. */
4308 add_AT_die_ref (die, attr_kind, targ_die)
4309 register dw_die_ref die;
4310 register enum dwarf_attribute attr_kind;
4311 register dw_die_ref targ_die;
4313 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4315 attr->dw_attr_next = NULL;
4316 attr->dw_attr = attr_kind;
4317 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4318 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4319 attr->dw_attr_val.v.val_die_ref.external = 0;
4320 add_dwarf_attr (die, attr);
4323 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4324 static inline dw_die_ref
4326 register dw_attr_ref a;
4328 if (a && AT_class (a) == dw_val_class_die_ref)
4329 return a->dw_attr_val.v.val_die_ref.die;
4334 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4337 register dw_attr_ref a;
4339 if (a && AT_class (a) == dw_val_class_die_ref)
4340 return a->dw_attr_val.v.val_die_ref.external;
4345 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4347 set_AT_ref_external (a, i)
4348 register dw_attr_ref a;
4351 if (a && AT_class (a) == dw_val_class_die_ref)
4352 a->dw_attr_val.v.val_die_ref.external = i;
4357 /* Add an FDE reference attribute value to a DIE. */
4360 add_AT_fde_ref (die, attr_kind, targ_fde)
4361 register dw_die_ref die;
4362 register enum dwarf_attribute attr_kind;
4363 register unsigned targ_fde;
4365 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4367 attr->dw_attr_next = NULL;
4368 attr->dw_attr = attr_kind;
4369 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4370 attr->dw_attr_val.v.val_fde_index = targ_fde;
4371 add_dwarf_attr (die, attr);
4374 /* Add a location description attribute value to a DIE. */
4377 add_AT_loc (die, attr_kind, loc)
4378 register dw_die_ref die;
4379 register enum dwarf_attribute attr_kind;
4380 register dw_loc_descr_ref loc;
4382 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4384 attr->dw_attr_next = NULL;
4385 attr->dw_attr = attr_kind;
4386 attr->dw_attr_val.val_class = dw_val_class_loc;
4387 attr->dw_attr_val.v.val_loc = loc;
4388 add_dwarf_attr (die, attr);
4391 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4392 static inline dw_loc_descr_ref
4394 register dw_attr_ref a;
4396 if (a && AT_class (a) == dw_val_class_loc)
4397 return a->dw_attr_val.v.val_loc;
4402 /* Add an address constant attribute value to a DIE. */
4405 add_AT_addr (die, attr_kind, addr)
4406 register dw_die_ref die;
4407 register enum dwarf_attribute attr_kind;
4410 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4412 attr->dw_attr_next = NULL;
4413 attr->dw_attr = attr_kind;
4414 attr->dw_attr_val.val_class = dw_val_class_addr;
4415 attr->dw_attr_val.v.val_addr = addr;
4416 add_dwarf_attr (die, attr);
4419 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4422 register dw_attr_ref a;
4424 if (a && AT_class (a) == dw_val_class_addr)
4425 return a->dw_attr_val.v.val_addr;
4430 /* Add a label identifier attribute value to a DIE. */
4433 add_AT_lbl_id (die, attr_kind, lbl_id)
4434 register dw_die_ref die;
4435 register enum dwarf_attribute attr_kind;
4436 register const char *lbl_id;
4438 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4440 attr->dw_attr_next = NULL;
4441 attr->dw_attr = attr_kind;
4442 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4443 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4444 add_dwarf_attr (die, attr);
4447 /* Add a section offset attribute value to a DIE. */
4450 add_AT_lbl_offset (die, attr_kind, label)
4451 register dw_die_ref die;
4452 register enum dwarf_attribute attr_kind;
4453 register const char *label;
4455 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4457 attr->dw_attr_next = NULL;
4458 attr->dw_attr = attr_kind;
4459 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4460 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4461 add_dwarf_attr (die, attr);
4464 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4465 static inline const char *
4467 register dw_attr_ref a;
4469 if (a && (AT_class (a) == dw_val_class_lbl_id
4470 || AT_class (a) == dw_val_class_lbl_offset))
4471 return a->dw_attr_val.v.val_lbl_id;
4476 /* Get the attribute of type attr_kind. */
4478 static inline dw_attr_ref
4479 get_AT (die, attr_kind)
4480 register dw_die_ref die;
4481 register enum dwarf_attribute attr_kind;
4483 register dw_attr_ref a;
4484 register dw_die_ref spec = NULL;
4488 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4490 if (a->dw_attr == attr_kind)
4493 if (a->dw_attr == DW_AT_specification
4494 || a->dw_attr == DW_AT_abstract_origin)
4499 return get_AT (spec, attr_kind);
4505 /* Return the "low pc" attribute value, typically associated with
4506 a subprogram DIE. Return null if the "low pc" attribute is
4507 either not prsent, or if it cannot be represented as an
4508 assembler label identifier. */
4510 static inline const char *
4512 register dw_die_ref die;
4514 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4515 return a ? AT_lbl (a) : NULL;
4518 /* Return the "high pc" attribute value, typically associated with
4519 a subprogram DIE. Return null if the "high pc" attribute is
4520 either not prsent, or if it cannot be represented as an
4521 assembler label identifier. */
4523 static inline const char *
4525 register dw_die_ref die;
4527 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4528 return a ? AT_lbl (a) : NULL;
4531 /* Return the value of the string attribute designated by ATTR_KIND, or
4532 NULL if it is not present. */
4534 static inline const char *
4535 get_AT_string (die, attr_kind)
4536 register dw_die_ref die;
4537 register enum dwarf_attribute attr_kind;
4539 register dw_attr_ref a = get_AT (die, attr_kind);
4540 return a ? AT_string (a) : NULL;
4543 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4544 if it is not present. */
4547 get_AT_flag (die, attr_kind)
4548 register dw_die_ref die;
4549 register enum dwarf_attribute attr_kind;
4551 register dw_attr_ref a = get_AT (die, attr_kind);
4552 return a ? AT_flag (a) : 0;
4555 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4556 if it is not present. */
4558 static inline unsigned
4559 get_AT_unsigned (die, attr_kind)
4560 register dw_die_ref die;
4561 register enum dwarf_attribute attr_kind;
4563 register dw_attr_ref a = get_AT (die, attr_kind);
4564 return a ? AT_unsigned (a) : 0;
4567 static inline dw_die_ref
4568 get_AT_ref (die, attr_kind)
4570 register enum dwarf_attribute attr_kind;
4572 register dw_attr_ref a = get_AT (die, attr_kind);
4573 return a ? AT_ref (a) : NULL;
4579 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4581 return (lang == DW_LANG_C || lang == DW_LANG_C89
4582 || lang == DW_LANG_C_plus_plus);
4588 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4590 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4596 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4598 return (lang == DW_LANG_Java);
4601 /* Free up the memory used by A. */
4603 static inline void free_AT PARAMS ((dw_attr_ref));
4608 switch (AT_class (a))
4610 case dw_val_class_str:
4611 case dw_val_class_lbl_id:
4612 case dw_val_class_lbl_offset:
4613 free (a->dw_attr_val.v.val_str);
4616 case dw_val_class_float:
4617 free (a->dw_attr_val.v.val_float.array);
4627 /* Remove the specified attribute if present. */
4630 remove_AT (die, attr_kind)
4631 register dw_die_ref die;
4632 register enum dwarf_attribute attr_kind;
4634 register dw_attr_ref *p;
4635 register dw_attr_ref removed = NULL;
4639 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4640 if ((*p)->dw_attr == attr_kind)
4643 *p = (*p)->dw_attr_next;
4652 /* Free up the memory used by DIE. */
4654 static inline void free_die PARAMS ((dw_die_ref));
4659 remove_children (die);
4663 /* Discard the children of this DIE. */
4666 remove_children (die)
4667 register dw_die_ref die;
4669 register dw_die_ref child_die = die->die_child;
4671 die->die_child = NULL;
4673 while (child_die != NULL)
4675 register dw_die_ref tmp_die = child_die;
4676 register dw_attr_ref a;
4678 child_die = child_die->die_sib;
4680 for (a = tmp_die->die_attr; a != NULL;)
4682 register dw_attr_ref tmp_a = a;
4684 a = a->dw_attr_next;
4692 /* Add a child DIE below its parent. We build the lists up in reverse
4693 addition order, and correct that in reverse_all_dies. */
4696 add_child_die (die, child_die)
4697 register dw_die_ref die;
4698 register dw_die_ref child_die;
4700 if (die != NULL && child_die != NULL)
4702 if (die == child_die)
4704 child_die->die_parent = die;
4705 child_die->die_sib = die->die_child;
4706 die->die_child = child_die;
4710 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4711 is the specification, to the front of PARENT's list of children. */
4714 splice_child_die (parent, child)
4715 dw_die_ref parent, child;
4719 /* We want the declaration DIE from inside the class, not the
4720 specification DIE at toplevel. */
4721 if (child->die_parent != parent)
4723 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4728 if (child->die_parent != parent
4729 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4732 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4735 *p = child->die_sib;
4739 child->die_sib = parent->die_child;
4740 parent->die_child = child;
4743 /* Return a pointer to a newly created DIE node. */
4745 static inline dw_die_ref
4746 new_die (tag_value, parent_die)
4747 register enum dwarf_tag tag_value;
4748 register dw_die_ref parent_die;
4750 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4752 die->die_tag = tag_value;
4753 die->die_abbrev = 0;
4754 die->die_offset = 0;
4755 die->die_child = NULL;
4756 die->die_parent = NULL;
4757 die->die_sib = NULL;
4758 die->die_attr = NULL;
4759 die->die_symbol = NULL;
4761 if (parent_die != NULL)
4762 add_child_die (parent_die, die);
4765 limbo_die_node *limbo_node;
4767 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4768 limbo_node->die = die;
4769 limbo_node->next = limbo_die_list;
4770 limbo_die_list = limbo_node;
4776 /* Return the DIE associated with the given type specifier. */
4778 static inline dw_die_ref
4779 lookup_type_die (type)
4782 if (TREE_CODE (type) == VECTOR_TYPE)
4783 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4784 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4787 /* Equate a DIE to a given type specifier. */
4790 equate_type_number_to_die (type, type_die)
4792 register dw_die_ref type_die;
4794 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4797 /* Return the DIE associated with a given declaration. */
4799 static inline dw_die_ref
4800 lookup_decl_die (decl)
4803 register unsigned decl_id = DECL_UID (decl);
4805 return (decl_id < decl_die_table_in_use
4806 ? decl_die_table[decl_id] : NULL);
4809 /* Equate a DIE to a particular declaration. */
4812 equate_decl_number_to_die (decl, decl_die)
4814 register dw_die_ref decl_die;
4816 register unsigned decl_id = DECL_UID (decl);
4817 register unsigned num_allocated;
4819 if (decl_id >= decl_die_table_allocated)
4822 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4823 / DECL_DIE_TABLE_INCREMENT)
4824 * DECL_DIE_TABLE_INCREMENT;
4827 = (dw_die_ref *) xrealloc (decl_die_table,
4828 sizeof (dw_die_ref) * num_allocated);
4830 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4831 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4832 decl_die_table_allocated = num_allocated;
4835 if (decl_id >= decl_die_table_in_use)
4836 decl_die_table_in_use = (decl_id + 1);
4838 decl_die_table[decl_id] = decl_die;
4841 /* Keep track of the number of spaces used to indent the
4842 output of the debugging routines that print the structure of
4843 the DIE internal representation. */
4844 static int print_indent;
4846 /* Indent the line the number of spaces given by print_indent. */
4849 print_spaces (outfile)
4852 fprintf (outfile, "%*s", print_indent, "");
4855 /* Print the information associated with a given DIE, and its children.
4856 This routine is a debugging aid only. */
4859 print_die (die, outfile)
4863 register dw_attr_ref a;
4864 register dw_die_ref c;
4866 print_spaces (outfile);
4867 fprintf (outfile, "DIE %4lu: %s\n",
4868 die->die_offset, dwarf_tag_name (die->die_tag));
4869 print_spaces (outfile);
4870 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4871 fprintf (outfile, " offset: %lu\n", die->die_offset);
4873 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4875 print_spaces (outfile);
4876 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4878 switch (AT_class (a))
4880 case dw_val_class_addr:
4881 fprintf (outfile, "address");
4883 case dw_val_class_loc:
4884 fprintf (outfile, "location descriptor");
4886 case dw_val_class_const:
4887 fprintf (outfile, "%ld", AT_int (a));
4889 case dw_val_class_unsigned_const:
4890 fprintf (outfile, "%lu", AT_unsigned (a));
4892 case dw_val_class_long_long:
4893 fprintf (outfile, "constant (%lu,%lu)",
4894 a->dw_attr_val.v.val_long_long.hi,
4895 a->dw_attr_val.v.val_long_long.low);
4897 case dw_val_class_float:
4898 fprintf (outfile, "floating-point constant");
4900 case dw_val_class_flag:
4901 fprintf (outfile, "%u", AT_flag (a));
4903 case dw_val_class_die_ref:
4904 if (AT_ref (a) != NULL)
4906 if (AT_ref (a)->die_symbol)
4907 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
4909 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4912 fprintf (outfile, "die -> <null>");
4914 case dw_val_class_lbl_id:
4915 case dw_val_class_lbl_offset:
4916 fprintf (outfile, "label: %s", AT_lbl (a));
4918 case dw_val_class_str:
4919 if (AT_string (a) != NULL)
4920 fprintf (outfile, "\"%s\"", AT_string (a));
4922 fprintf (outfile, "<null>");
4928 fprintf (outfile, "\n");
4931 if (die->die_child != NULL)
4934 for (c = die->die_child; c != NULL; c = c->die_sib)
4935 print_die (c, outfile);
4939 if (print_indent == 0)
4940 fprintf (outfile, "\n");
4943 /* Print the contents of the source code line number correspondence table.
4944 This routine is a debugging aid only. */
4947 print_dwarf_line_table (outfile)
4950 register unsigned i;
4951 register dw_line_info_ref line_info;
4953 fprintf (outfile, "\n\nDWARF source line information\n");
4954 for (i = 1; i < line_info_table_in_use; ++i)
4956 line_info = &line_info_table[i];
4957 fprintf (outfile, "%5d: ", i);
4958 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4959 fprintf (outfile, "%6ld", line_info->dw_line_num);
4960 fprintf (outfile, "\n");
4963 fprintf (outfile, "\n\n");
4966 /* Print the information collected for a given DIE. */
4969 debug_dwarf_die (die)
4972 print_die (die, stderr);
4975 /* Print all DWARF information collected for the compilation unit.
4976 This routine is a debugging aid only. */
4982 print_die (comp_unit_die, stderr);
4983 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4984 print_dwarf_line_table (stderr);
4987 /* We build up the lists of children and attributes by pushing new ones
4988 onto the beginning of the list. Reverse the lists for DIE so that
4989 they are in order of addition. */
4992 reverse_die_lists (die)
4993 register dw_die_ref die;
4995 register dw_die_ref c, cp, cn;
4996 register dw_attr_ref a, ap, an;
4998 for (a = die->die_attr, ap = 0; a; a = an)
5000 an = a->dw_attr_next;
5001 a->dw_attr_next = ap;
5006 for (c = die->die_child, cp = 0; c; c = cn)
5012 die->die_child = cp;
5015 /* reverse_die_lists only reverses the single die you pass it. Since
5016 we used to reverse all dies in add_sibling_attributes, which runs
5017 through all the dies, it would reverse all the dies. Now, however,
5018 since we don't call reverse_die_lists in add_sibling_attributes, we
5019 need a routine to recursively reverse all the dies. This is that
5023 reverse_all_dies (die)
5024 register dw_die_ref die;
5026 register dw_die_ref c;
5028 reverse_die_lists (die);
5030 for (c = die->die_child; c; c = c->die_sib)
5031 reverse_all_dies (c);
5034 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5035 the CU for the enclosing include file, if any. BINCL_DIE is the
5036 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5040 push_new_compile_unit (old_unit, bincl_die)
5041 dw_die_ref old_unit, bincl_die;
5043 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5044 dw_die_ref new_unit = gen_compile_unit_die (filename);
5045 new_unit->die_sib = old_unit;
5049 /* Close an include-file CU and reopen the enclosing one. */
5052 pop_compile_unit (old_unit)
5053 dw_die_ref old_unit;
5055 dw_die_ref new_unit = old_unit->die_sib;
5056 old_unit->die_sib = NULL;
5060 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5061 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5063 /* Calculate the checksum of a location expression. */
5066 loc_checksum (loc, ctx)
5067 dw_loc_descr_ref loc;
5068 struct md5_ctx *ctx;
5070 PROCESS (loc->dw_loc_opc);
5071 PROCESS (loc->dw_loc_oprnd1);
5072 PROCESS (loc->dw_loc_oprnd2);
5075 /* Calculate the checksum of an attribute. */
5078 attr_checksum (at, ctx)
5080 struct md5_ctx *ctx;
5082 dw_loc_descr_ref loc;
5085 PROCESS (at->dw_attr);
5087 /* We don't care about differences in file numbering. */
5088 if (at->dw_attr == DW_AT_decl_file
5089 /* Or that this was compiled with a different compiler snapshot; if
5090 the output is the same, that's what matters. */
5091 || at->dw_attr == DW_AT_producer)
5094 switch (AT_class (at))
5096 case dw_val_class_const:
5097 PROCESS (at->dw_attr_val.v.val_int);
5099 case dw_val_class_unsigned_const:
5100 PROCESS (at->dw_attr_val.v.val_unsigned);
5102 case dw_val_class_long_long:
5103 PROCESS (at->dw_attr_val.v.val_long_long);
5105 case dw_val_class_float:
5106 PROCESS (at->dw_attr_val.v.val_float);
5108 case dw_val_class_flag:
5109 PROCESS (at->dw_attr_val.v.val_flag);
5112 case dw_val_class_str:
5113 PROCESS_STRING (AT_string (at));
5115 case dw_val_class_addr:
5117 switch (GET_CODE (r))
5120 PROCESS_STRING (XSTR (r, 0));
5128 case dw_val_class_loc:
5129 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5130 loc_checksum (loc, ctx);
5133 case dw_val_class_die_ref:
5134 if (AT_ref (at)->die_offset)
5135 PROCESS (AT_ref (at)->die_offset);
5136 /* FIXME else use target die name or something. */
5138 case dw_val_class_fde_ref:
5139 case dw_val_class_lbl_id:
5140 case dw_val_class_lbl_offset:
5147 /* Calculate the checksum of a DIE. */
5150 die_checksum (die, ctx)
5152 struct md5_ctx *ctx;
5157 PROCESS (die->die_tag);
5159 for (a = die->die_attr; a; a = a->dw_attr_next)
5160 attr_checksum (a, ctx);
5162 for (c = die->die_child; c; c = c->die_sib)
5163 die_checksum (c, ctx);
5167 #undef PROCESS_STRING
5169 /* The prefix to attach to symbols on DIEs in the current comdat debug
5171 static char *comdat_symbol_id;
5173 /* The index of the current symbol within the current comdat CU. */
5174 static unsigned int comdat_symbol_number;
5176 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5177 children, and set comdat_symbol_id accordingly. */
5180 compute_section_prefix (unit_die)
5181 dw_die_ref unit_die;
5185 unsigned char checksum[16];
5188 md5_init_ctx (&ctx);
5189 die_checksum (unit_die, &ctx);
5190 md5_finish_ctx (&ctx, checksum);
5192 p = file_name_nondirectory (get_AT_string (unit_die, DW_AT_name));
5193 name = (char *) alloca (strlen (p) + 64);
5194 sprintf (name, "%s.", p);
5196 clean_symbol_name (name);
5198 p = name + strlen (name);
5199 for (i = 0; i < 4; ++i)
5201 sprintf (p, "%.2x", checksum[i]);
5205 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5206 comdat_symbol_number = 0;
5209 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5215 switch (die->die_tag)
5217 case DW_TAG_array_type:
5218 case DW_TAG_class_type:
5219 case DW_TAG_enumeration_type:
5220 case DW_TAG_pointer_type:
5221 case DW_TAG_reference_type:
5222 case DW_TAG_string_type:
5223 case DW_TAG_structure_type:
5224 case DW_TAG_subroutine_type:
5225 case DW_TAG_union_type:
5226 case DW_TAG_ptr_to_member_type:
5227 case DW_TAG_set_type:
5228 case DW_TAG_subrange_type:
5229 case DW_TAG_base_type:
5230 case DW_TAG_const_type:
5231 case DW_TAG_file_type:
5232 case DW_TAG_packed_type:
5233 case DW_TAG_volatile_type:
5240 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5241 Basically, we want to choose the bits that are likely to be shared between
5242 compilations (types) and leave out the bits that are specific to individual
5243 compilations (functions). */
5250 /* I think we want to leave base types and __vtbl_ptr_type in the
5251 main CU, as we do for stabs. The advantage is a greater
5252 likelihood of sharing between objects that don't include headers
5253 in the same order (and therefore would put the base types in a
5254 different comdat). jason 8/28/00 */
5255 if (c->die_tag == DW_TAG_base_type)
5258 if (c->die_tag == DW_TAG_pointer_type
5259 || c->die_tag == DW_TAG_reference_type
5260 || c->die_tag == DW_TAG_const_type
5261 || c->die_tag == DW_TAG_volatile_type)
5263 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5264 return t ? is_comdat_die (t) : 0;
5268 return is_type_die (c);
5271 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5272 compilation unit. */
5278 if (is_type_die (c))
5280 if (get_AT (c, DW_AT_declaration)
5281 && ! get_AT (c, DW_AT_specification))
5290 static int label_num;
5291 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5292 return xstrdup (buf);
5295 /* Assign symbols to all worthy DIEs under DIE. */
5298 assign_symbol_names (die)
5299 register dw_die_ref die;
5301 register dw_die_ref c;
5303 if (is_symbol_die (die))
5305 if (comdat_symbol_id)
5307 char *p = alloca (strlen (comdat_symbol_id) + 64);
5308 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5309 comdat_symbol_id, comdat_symbol_number++);
5310 die->die_symbol = xstrdup (p);
5313 die->die_symbol = gen_internal_sym ();
5316 for (c = die->die_child; c != NULL; c = c->die_sib)
5317 assign_symbol_names (c);
5320 /* Traverse the DIE (which is always comp_unit_die), and set up
5321 additional compilation units for each of the include files we see
5322 bracketed by BINCL/EINCL. */
5325 break_out_includes (die)
5326 register dw_die_ref die;
5329 register dw_die_ref unit = NULL;
5330 limbo_die_node *node;
5332 for (ptr = &(die->die_child); *ptr; )
5334 register dw_die_ref c = *ptr;
5336 if (c->die_tag == DW_TAG_GNU_BINCL
5337 || c->die_tag == DW_TAG_GNU_EINCL
5338 || (unit && is_comdat_die (c)))
5340 /* This DIE is for a secondary CU; remove it from the main one. */
5343 if (c->die_tag == DW_TAG_GNU_BINCL)
5345 unit = push_new_compile_unit (unit, c);
5348 else if (c->die_tag == DW_TAG_GNU_EINCL)
5350 unit = pop_compile_unit (unit);
5354 add_child_die (unit, c);
5358 /* Leave this DIE in the main CU. */
5359 ptr = &(c->die_sib);
5365 /* We can only use this in debugging, since the frontend doesn't check
5366 to make sure that we leave every include file we enter. */
5371 assign_symbol_names (die);
5372 for (node = limbo_die_list; node; node = node->next)
5374 compute_section_prefix (node->die);
5375 assign_symbol_names (node->die);
5379 /* Traverse the DIE and add a sibling attribute if it may have the
5380 effect of speeding up access to siblings. To save some space,
5381 avoid generating sibling attributes for DIE's without children. */
5384 add_sibling_attributes (die)
5385 register dw_die_ref die;
5387 register dw_die_ref c;
5389 if (die->die_tag != DW_TAG_compile_unit
5390 && die->die_sib && die->die_child != NULL)
5391 /* Add the sibling link to the front of the attribute list. */
5392 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5394 for (c = die->die_child; c != NULL; c = c->die_sib)
5395 add_sibling_attributes (c);
5398 /* The format of each DIE (and its attribute value pairs)
5399 is encoded in an abbreviation table. This routine builds the
5400 abbreviation table and assigns a unique abbreviation id for
5401 each abbreviation entry. The children of each die are visited
5405 build_abbrev_table (die)
5406 register dw_die_ref die;
5408 register unsigned long abbrev_id;
5409 register unsigned long n_alloc;
5410 register dw_die_ref c;
5411 register dw_attr_ref d_attr, a_attr;
5413 /* Scan the DIE references, and mark as external any that refer to
5414 DIEs from other CUs (i.e. those which are not marked). */
5415 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5417 if (AT_class (d_attr) == dw_val_class_die_ref
5418 && AT_ref (d_attr)->die_mark == 0)
5420 if (AT_ref (d_attr)->die_symbol == 0)
5422 set_AT_ref_external (d_attr, 1);
5426 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5428 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5430 if (abbrev->die_tag == die->die_tag)
5432 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5434 a_attr = abbrev->die_attr;
5435 d_attr = die->die_attr;
5437 while (a_attr != NULL && d_attr != NULL)
5439 if ((a_attr->dw_attr != d_attr->dw_attr)
5440 || (value_format (a_attr) != value_format (d_attr)))
5443 a_attr = a_attr->dw_attr_next;
5444 d_attr = d_attr->dw_attr_next;
5447 if (a_attr == NULL && d_attr == NULL)
5453 if (abbrev_id >= abbrev_die_table_in_use)
5455 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5457 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5459 = (dw_die_ref *) xrealloc (abbrev_die_table,
5460 sizeof (dw_die_ref) * n_alloc);
5462 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
5463 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5464 abbrev_die_table_allocated = n_alloc;
5467 ++abbrev_die_table_in_use;
5468 abbrev_die_table[abbrev_id] = die;
5471 die->die_abbrev = abbrev_id;
5472 for (c = die->die_child; c != NULL; c = c->die_sib)
5473 build_abbrev_table (c);
5476 /* Return the size of a string, including the null byte.
5478 This used to treat backslashes as escapes, and hence they were not included
5479 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5480 which treats a backslash as a backslash, escaping it if necessary, and hence
5481 we must include them in the count. */
5483 static unsigned long
5484 size_of_string (str)
5485 register const char *str;
5487 return strlen (str) + 1;
5490 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5493 constant_size (value)
5494 long unsigned value;
5501 log = floor_log2 (value);
5504 log = 1 << (floor_log2 (log) + 1);
5509 /* Return the size of a DIE, as it is represented in the
5510 .debug_info section. */
5512 static unsigned long
5514 register dw_die_ref die;
5516 register unsigned long size = 0;
5517 register dw_attr_ref a;
5519 size += size_of_uleb128 (die->die_abbrev);
5520 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5522 switch (AT_class (a))
5524 case dw_val_class_addr:
5525 size += DWARF2_ADDR_SIZE;
5527 case dw_val_class_loc:
5529 register unsigned long lsize = size_of_locs (AT_loc (a));
5532 size += constant_size (lsize);
5536 case dw_val_class_const:
5537 size += size_of_sleb128 (AT_int (a));
5539 case dw_val_class_unsigned_const:
5540 size += constant_size (AT_unsigned (a));
5542 case dw_val_class_long_long:
5543 size += 1 + 8; /* block */
5545 case dw_val_class_float:
5546 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5548 case dw_val_class_flag:
5551 case dw_val_class_die_ref:
5552 size += DWARF_OFFSET_SIZE;
5554 case dw_val_class_fde_ref:
5555 size += DWARF_OFFSET_SIZE;
5557 case dw_val_class_lbl_id:
5558 size += DWARF2_ADDR_SIZE;
5560 case dw_val_class_lbl_offset:
5561 size += DWARF_OFFSET_SIZE;
5563 case dw_val_class_str:
5564 size += size_of_string (AT_string (a));
5574 /* Size the debugging information associated with a given DIE.
5575 Visits the DIE's children recursively. Updates the global
5576 variable next_die_offset, on each time through. Uses the
5577 current value of next_die_offset to update the die_offset
5578 field in each DIE. */
5581 calc_die_sizes (die)
5584 register dw_die_ref c;
5585 die->die_offset = next_die_offset;
5586 next_die_offset += size_of_die (die);
5588 for (c = die->die_child; c != NULL; c = c->die_sib)
5591 if (die->die_child != NULL)
5592 /* Count the null byte used to terminate sibling lists. */
5593 next_die_offset += 1;
5596 /* Set the marks for a die and its children. We do this so
5597 that we know whether or not a reference needs to use FORM_ref_addr; only
5598 DIEs in the same CU will be marked. We used to clear out the offset
5599 and use that as the flag, but ran into ordering problems. */
5605 register dw_die_ref c;
5607 for (c = die->die_child; c; c = c->die_sib)
5611 /* Clear the marks for a die and its children. */
5617 register dw_die_ref c;
5619 for (c = die->die_child; c; c = c->die_sib)
5623 /* Return the size of the line information prolog generated for the
5624 compilation unit. */
5626 static unsigned long
5627 size_of_line_prolog ()
5629 register unsigned long size;
5630 register unsigned long ft_index;
5632 size = DWARF_LINE_PROLOG_HEADER_SIZE;
5634 /* Count the size of the table giving number of args for each
5636 size += DWARF_LINE_OPCODE_BASE - 1;
5638 /* Include directory table is empty (at present). Count only the
5639 null byte used to terminate the table. */
5642 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5644 /* File name entry. */
5645 size += size_of_string (file_table[ft_index]);
5647 /* Include directory index. */
5648 size += size_of_uleb128 (0);
5650 /* Modification time. */
5651 size += size_of_uleb128 (0);
5653 /* File length in bytes. */
5654 size += size_of_uleb128 (0);
5657 /* Count the file table terminator. */
5662 /* Return the size of the .debug_pubnames table generated for the
5663 compilation unit. */
5665 static unsigned long
5668 register unsigned long size;
5669 register unsigned i;
5671 size = DWARF_PUBNAMES_HEADER_SIZE;
5672 for (i = 0; i < pubname_table_in_use; ++i)
5674 register pubname_ref p = &pubname_table[i];
5675 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5678 size += DWARF_OFFSET_SIZE;
5682 /* Return the size of the information in the .debug_aranges section. */
5684 static unsigned long
5687 register unsigned long size;
5689 size = DWARF_ARANGES_HEADER_SIZE;
5691 /* Count the address/length pair for this compilation unit. */
5692 size += 2 * DWARF2_ADDR_SIZE;
5693 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5695 /* Count the two zero words used to terminated the address range table. */
5696 size += 2 * DWARF2_ADDR_SIZE;
5700 /* Select the encoding of an attribute value. */
5702 static enum dwarf_form
5706 switch (a->dw_attr_val.val_class)
5708 case dw_val_class_addr:
5709 return DW_FORM_addr;
5710 case dw_val_class_loc:
5711 switch (constant_size (size_of_locs (AT_loc (a))))
5714 return DW_FORM_block1;
5716 return DW_FORM_block2;
5720 case dw_val_class_const:
5721 return DW_FORM_sdata;
5722 case dw_val_class_unsigned_const:
5723 switch (constant_size (AT_unsigned (a)))
5726 return DW_FORM_data1;
5728 return DW_FORM_data2;
5730 return DW_FORM_data4;
5732 return DW_FORM_data8;
5736 case dw_val_class_long_long:
5737 return DW_FORM_block1;
5738 case dw_val_class_float:
5739 return DW_FORM_block1;
5740 case dw_val_class_flag:
5741 return DW_FORM_flag;
5742 case dw_val_class_die_ref:
5743 if (AT_ref_external (a))
5744 return DW_FORM_ref_addr;
5747 case dw_val_class_fde_ref:
5748 return DW_FORM_data;
5749 case dw_val_class_lbl_id:
5750 return DW_FORM_addr;
5751 case dw_val_class_lbl_offset:
5752 return DW_FORM_data;
5753 case dw_val_class_str:
5754 return DW_FORM_string;
5760 /* Output the encoding of an attribute value. */
5763 output_value_format (a)
5766 enum dwarf_form form = value_format (a);
5768 output_uleb128 (form);
5770 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
5772 fputc ('\n', asm_out_file);
5775 /* Output the .debug_abbrev section which defines the DIE abbreviation
5779 output_abbrev_section ()
5781 unsigned long abbrev_id;
5784 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5786 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5788 output_uleb128 (abbrev_id);
5790 fprintf (asm_out_file, " (abbrev code)");
5792 fputc ('\n', asm_out_file);
5793 output_uleb128 (abbrev->die_tag);
5795 fprintf (asm_out_file, " (TAG: %s)",
5796 dwarf_tag_name (abbrev->die_tag));
5798 fputc ('\n', asm_out_file);
5799 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP,
5800 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
5803 fprintf (asm_out_file, "\t%s %s",
5805 (abbrev->die_child != NULL
5806 ? "DW_children_yes" : "DW_children_no"));
5808 fputc ('\n', asm_out_file);
5810 for (a_attr = abbrev->die_attr; a_attr != NULL;
5811 a_attr = a_attr->dw_attr_next)
5813 output_uleb128 (a_attr->dw_attr);
5815 fprintf (asm_out_file, " (%s)",
5816 dwarf_attr_name (a_attr->dw_attr));
5818 fputc ('\n', asm_out_file);
5819 output_value_format (a_attr);
5822 fprintf (asm_out_file, "%s0,0\n", ASM_BYTE_OP);
5825 /* Terminate the table. */
5826 fprintf (asm_out_file, "%s0\n", ASM_BYTE_OP);
5829 /* Output a symbol we can use to refer to this DIE from another CU. */
5832 output_die_symbol (die)
5833 register dw_die_ref die;
5835 char *sym = die->die_symbol;
5840 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5841 /* We make these global, not weak; if the target doesn't support
5842 .linkonce, it doesn't support combining the sections, so debugging
5844 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5845 ASM_OUTPUT_LABEL (asm_out_file, sym);
5848 /* Output a symbolic (i.e. FORM_ref_addr) reference to TARGET_DIE. */
5851 output_symbolic_ref (target_die)
5852 dw_die_ref target_die;
5854 char *sym = target_die->die_symbol;
5859 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, sym);
5862 /* Output the DIE and its attributes. Called recursively to generate
5863 the definitions of each child DIE. */
5867 register dw_die_ref die;
5869 register dw_attr_ref a;
5870 register dw_die_ref c;
5871 register unsigned long size;
5873 /* If someone in another CU might refer to us, set up a symbol for
5874 them to point to. */
5875 if (die->die_symbol)
5876 output_die_symbol (die);
5878 output_uleb128 (die->die_abbrev);
5880 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5881 die->die_offset, dwarf_tag_name (die->die_tag));
5883 fputc ('\n', asm_out_file);
5885 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5887 switch (AT_class (a))
5889 case dw_val_class_addr:
5890 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
5893 case dw_val_class_loc:
5894 size = size_of_locs (AT_loc (a));
5896 /* Output the block length for this list of location operations. */
5897 switch (constant_size (size))
5900 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5903 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5910 fprintf (asm_out_file, "\t%s %s",
5911 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5913 fputc ('\n', asm_out_file);
5915 output_loc_sequence (AT_loc (a));
5918 case dw_val_class_const:
5919 /* ??? It would be slightly more efficient to use a scheme like is
5920 used for unsigned constants below, but gdb 4.x does not sign
5921 extend. Gdb 5.x does sign extend. */
5922 output_sleb128 (AT_int (a));
5925 case dw_val_class_unsigned_const:
5926 switch (constant_size (AT_unsigned (a)))
5929 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
5932 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
5935 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
5938 ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a));
5945 case dw_val_class_long_long:
5946 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5948 fprintf (asm_out_file, "\t%s %s",
5949 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5951 fputc ('\n', asm_out_file);
5952 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file,
5953 a->dw_attr_val.v.val_long_long.hi,
5954 a->dw_attr_val.v.val_long_long.low);
5957 fprintf (asm_out_file,
5958 "\t%s long long constant", ASM_COMMENT_START);
5960 fputc ('\n', asm_out_file);
5963 case dw_val_class_float:
5965 register unsigned int i;
5966 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5967 a->dw_attr_val.v.val_float.length * 4);
5969 fprintf (asm_out_file, "\t%s %s",
5970 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5972 fputc ('\n', asm_out_file);
5973 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5975 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5976 a->dw_attr_val.v.val_float.array[i]);
5978 fprintf (asm_out_file, "\t%s fp constant word %u",
5979 ASM_COMMENT_START, i);
5981 fputc ('\n', asm_out_file);
5986 case dw_val_class_flag:
5987 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
5990 case dw_val_class_die_ref:
5991 if (AT_ref_external (a))
5992 output_symbolic_ref (AT_ref (a));
5994 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
5997 case dw_val_class_fde_ref:
6000 ASM_GENERATE_INTERNAL_LABEL
6001 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
6002 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
6003 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
6007 case dw_val_class_lbl_id:
6008 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
6011 case dw_val_class_lbl_offset:
6012 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
6015 case dw_val_class_str:
6017 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
6019 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
6020 (int) strlen (AT_string (a)) + 1);
6027 if (AT_class (a) != dw_val_class_loc
6028 && AT_class (a) != dw_val_class_long_long
6029 && AT_class (a) != dw_val_class_float)
6032 fprintf (asm_out_file, "\t%s %s",
6033 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6035 fputc ('\n', asm_out_file);
6039 for (c = die->die_child; c != NULL; c = c->die_sib)
6042 if (die->die_child != NULL)
6044 /* Add null byte to terminate sibling list. */
6045 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6047 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
6048 ASM_COMMENT_START, die->die_offset);
6050 fputc ('\n', asm_out_file);
6054 /* Output the compilation unit that appears at the beginning of the
6055 .debug_info section, and precedes the DIE descriptions. */
6058 output_compilation_unit_header ()
6060 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
6062 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
6065 fputc ('\n', asm_out_file);
6066 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6068 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
6070 fputc ('\n', asm_out_file);
6071 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
6073 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
6076 fputc ('\n', asm_out_file);
6077 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6079 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
6081 fputc ('\n', asm_out_file);
6084 /* Output the compilation unit DIE and its children. */
6087 output_comp_unit (die)
6092 if (die->die_child == 0)
6095 /* Mark all the DIEs in this CU so we know which get local refs. */
6098 build_abbrev_table (die);
6100 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6101 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6102 calc_die_sizes (die);
6104 if (die->die_symbol)
6106 secname = (char *) alloca (strlen (die->die_symbol) + 24);
6107 sprintf (secname, ".gnu.linkonce.wi.%s", die->die_symbol);
6108 die->die_symbol = NULL;
6111 secname = (char *) DEBUG_INFO_SECTION;
6113 /* Output debugging information. */
6114 fputc ('\n', asm_out_file);
6115 ASM_OUTPUT_SECTION (asm_out_file, secname);
6116 output_compilation_unit_header ();
6119 /* Leave the marks on the main CU, so we can check them in
6121 if (die->die_symbol)
6125 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6126 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6127 argument list, and maybe the scope. */
6130 dwarf2_name (decl, scope)
6134 return (*decl_printable_name) (decl, scope ? 1 : 0);
6137 /* Add a new entry to .debug_pubnames if appropriate. */
6140 add_pubname (decl, die)
6146 if (! TREE_PUBLIC (decl))
6149 if (pubname_table_in_use == pubname_table_allocated)
6151 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6152 pubname_table = (pubname_ref) xrealloc
6153 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6156 p = &pubname_table[pubname_table_in_use++];
6159 p->name = xstrdup (dwarf2_name (decl, 1));
6162 /* Output the public names table used to speed up access to externally
6163 visible names. For now, only generate entries for externally
6164 visible procedures. */
6169 register unsigned i;
6170 register unsigned long pubnames_length = size_of_pubnames ();
6172 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
6175 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
6178 fputc ('\n', asm_out_file);
6179 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6182 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6184 fputc ('\n', asm_out_file);
6185 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6187 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6190 fputc ('\n', asm_out_file);
6191 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
6193 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
6195 fputc ('\n', asm_out_file);
6196 for (i = 0; i < pubname_table_in_use; ++i)
6198 register pubname_ref pub = &pubname_table[i];
6200 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6201 if (pub->die->die_mark == 0)
6204 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
6206 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
6208 fputc ('\n', asm_out_file);
6212 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
6213 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
6217 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
6218 (int) strlen (pub->name) + 1);
6221 fputc ('\n', asm_out_file);
6224 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
6225 fputc ('\n', asm_out_file);
6228 /* Add a new entry to .debug_aranges if appropriate. */
6231 add_arange (decl, die)
6235 if (! DECL_SECTION_NAME (decl))
6238 if (arange_table_in_use == arange_table_allocated)
6240 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6242 = (arange_ref) xrealloc (arange_table,
6243 arange_table_allocated * sizeof (dw_die_ref));
6246 arange_table[arange_table_in_use++] = die;
6249 /* Output the information that goes into the .debug_aranges table.
6250 Namely, define the beginning and ending address range of the
6251 text section generated for this compilation unit. */
6256 register unsigned i;
6257 register unsigned long aranges_length = size_of_aranges ();
6259 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
6261 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
6264 fputc ('\n', asm_out_file);
6265 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6267 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6269 fputc ('\n', asm_out_file);
6270 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6272 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6275 fputc ('\n', asm_out_file);
6276 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6278 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
6280 fputc ('\n', asm_out_file);
6281 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6283 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
6286 fputc ('\n', asm_out_file);
6288 /* We need to align to twice the pointer size here. */
6289 if (DWARF_ARANGES_PAD_SIZE)
6291 /* Pad using a 2 bytes word so that padding is correct
6292 for any pointer size. */
6293 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
6294 for (i = 2; i < DWARF_ARANGES_PAD_SIZE; i += 2)
6295 fprintf (asm_out_file, ",0");
6297 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
6298 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
6301 fputc ('\n', asm_out_file);
6302 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
6304 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6306 fputc ('\n', asm_out_file);
6307 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
6308 text_section_label);
6310 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6312 fputc ('\n', asm_out_file);
6313 for (i = 0; i < arange_table_in_use; ++i)
6315 dw_die_ref die = arange_table[i];
6317 /* We shouldn't see aranges for DIEs outside of the main CU. */
6318 if (die->die_mark == 0)
6321 if (die->die_tag == DW_TAG_subprogram)
6322 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
6325 /* A static variable; extract the symbol from DW_AT_location.
6326 Note that this code isn't currently hit, as we only emit
6327 aranges for functions (jason 9/23/99). */
6329 dw_attr_ref a = get_AT (die, DW_AT_location);
6330 dw_loc_descr_ref loc;
6331 if (! a || AT_class (a) != dw_val_class_loc)
6335 if (loc->dw_loc_opc != DW_OP_addr)
6338 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
6339 loc->dw_loc_oprnd1.v.val_addr);
6343 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6345 fputc ('\n', asm_out_file);
6346 if (die->die_tag == DW_TAG_subprogram)
6347 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
6348 get_AT_low_pc (die));
6350 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
6351 get_AT_unsigned (die, DW_AT_byte_size));
6354 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6356 fputc ('\n', asm_out_file);
6359 /* Output the terminator words. */
6360 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6361 fputc ('\n', asm_out_file);
6362 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6363 fputc ('\n', asm_out_file);
6366 /* Output the source line number correspondence information. This
6367 information goes into the .debug_line section. */
6372 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6373 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6374 register unsigned opc;
6375 register unsigned n_op_args;
6376 register unsigned long ft_index;
6377 register unsigned long lt_index;
6378 register unsigned long current_line;
6379 register long line_offset;
6380 register long line_delta;
6381 register unsigned long current_file;
6382 register unsigned long function;
6384 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
6386 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
6389 fputc ('\n', asm_out_file);
6390 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
6391 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6393 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6395 fputc ('\n', asm_out_file);
6396 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
6398 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
6400 fputc ('\n', asm_out_file);
6401 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
6403 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
6406 fputc ('\n', asm_out_file);
6407 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
6409 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
6412 fputc ('\n', asm_out_file);
6413 fprintf (asm_out_file, "%s%d", ASM_BYTE_OP, DWARF_LINE_BASE);
6415 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
6418 fputc ('\n', asm_out_file);
6419 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
6421 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
6424 fputc ('\n', asm_out_file);
6425 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
6427 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
6429 fputc ('\n', asm_out_file);
6430 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6434 case DW_LNS_advance_pc:
6435 case DW_LNS_advance_line:
6436 case DW_LNS_set_file:
6437 case DW_LNS_set_column:
6438 case DW_LNS_fixed_advance_pc:
6445 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
6447 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
6448 ASM_COMMENT_START, opc, n_op_args);
6449 fputc ('\n', asm_out_file);
6453 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
6455 /* Include directory table is empty, at present */
6456 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6457 fputc ('\n', asm_out_file);
6459 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
6461 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
6465 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
6466 fprintf (asm_out_file, "%s File Entry: 0x%lx",
6467 ASM_COMMENT_START, ft_index);
6471 ASM_OUTPUT_ASCII (asm_out_file,
6472 file_table[ft_index],
6473 (int) strlen (file_table[ft_index]) + 1);
6476 fputc ('\n', asm_out_file);
6478 /* Include directory index */
6480 fputc ('\n', asm_out_file);
6482 /* Modification time */
6484 fputc ('\n', asm_out_file);
6486 /* File length in bytes */
6488 fputc ('\n', asm_out_file);
6491 /* Terminate the file name table */
6492 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6493 fputc ('\n', asm_out_file);
6495 /* We used to set the address register to the first location in the text
6496 section here, but that didn't accomplish anything since we already
6497 have a line note for the opening brace of the first function. */
6499 /* Generate the line number to PC correspondence table, encoded as
6500 a series of state machine operations. */
6503 strcpy (prev_line_label, text_section_label);
6504 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6506 register dw_line_info_ref line_info = &line_info_table[lt_index];
6509 /* Disable this optimization for now; GDB wants to see two line notes
6510 at the beginning of a function so it can find the end of the
6513 /* Don't emit anything for redundant notes. Just updating the
6514 address doesn't accomplish anything, because we already assume
6515 that anything after the last address is this line. */
6516 if (line_info->dw_line_num == current_line
6517 && line_info->dw_file_num == current_file)
6521 /* Emit debug info for the address of the current line, choosing
6522 the encoding that uses the least amount of space. */
6523 /* ??? Unfortunately, we have little choice here currently, and must
6524 always use the most general form. Gcc does not know the address
6525 delta itself, so we can't use DW_LNS_advance_pc. There are no known
6526 dwarf2 aware assemblers at this time, so we can't use any special
6527 pseudo ops that would allow the assembler to optimally encode this for
6528 us. Many ports do have length attributes which will give an upper
6529 bound on the address range. We could perhaps use length attributes
6530 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
6531 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6534 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6535 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6537 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6540 fputc ('\n', asm_out_file);
6541 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
6542 fputc ('\n', asm_out_file);
6546 /* This can handle any delta. This takes
6547 4+DWARF2_ADDR_SIZE bytes. */
6548 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6550 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6552 fputc ('\n', asm_out_file);
6553 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6554 fputc ('\n', asm_out_file);
6555 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6556 fputc ('\n', asm_out_file);
6557 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6558 fputc ('\n', asm_out_file);
6560 strcpy (prev_line_label, line_label);
6562 /* Emit debug info for the source file of the current line, if
6563 different from the previous line. */
6564 if (line_info->dw_file_num != current_file)
6566 current_file = line_info->dw_file_num;
6567 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6569 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6571 fputc ('\n', asm_out_file);
6572 output_uleb128 (current_file);
6574 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
6576 fputc ('\n', asm_out_file);
6579 /* Emit debug info for the current line number, choosing the encoding
6580 that uses the least amount of space. */
6581 if (line_info->dw_line_num != current_line)
6583 line_offset = line_info->dw_line_num - current_line;
6584 line_delta = line_offset - DWARF_LINE_BASE;
6585 current_line = line_info->dw_line_num;
6586 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6588 /* This can handle deltas from -10 to 234, using the current
6589 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6591 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6592 DWARF_LINE_OPCODE_BASE + line_delta);
6594 fprintf (asm_out_file,
6595 "\t%s line %ld", ASM_COMMENT_START, current_line);
6597 fputc ('\n', asm_out_file);
6601 /* This can handle any delta. This takes at least 4 bytes,
6602 depending on the value being encoded. */
6603 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6605 fprintf (asm_out_file, "\t%s advance to line %ld",
6606 ASM_COMMENT_START, current_line);
6608 fputc ('\n', asm_out_file);
6609 output_sleb128 (line_offset);
6610 fputc ('\n', asm_out_file);
6611 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6613 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6614 fputc ('\n', asm_out_file);
6619 /* We still need to start a new row, so output a copy insn. */
6620 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6622 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6623 fputc ('\n', asm_out_file);
6627 /* Emit debug info for the address of the end of the function. */
6630 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6632 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6635 fputc ('\n', asm_out_file);
6636 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
6637 fputc ('\n', asm_out_file);
6641 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6643 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
6644 fputc ('\n', asm_out_file);
6645 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6646 fputc ('\n', asm_out_file);
6647 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6648 fputc ('\n', asm_out_file);
6649 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
6650 fputc ('\n', asm_out_file);
6653 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6655 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
6657 fputc ('\n', asm_out_file);
6659 fputc ('\n', asm_out_file);
6660 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6661 fputc ('\n', asm_out_file);
6666 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6668 register dw_separate_line_info_ref line_info
6669 = &separate_line_info_table[lt_index];
6672 /* Don't emit anything for redundant notes. */
6673 if (line_info->dw_line_num == current_line
6674 && line_info->dw_file_num == current_file
6675 && line_info->function == function)
6679 /* Emit debug info for the address of the current line. If this is
6680 a new function, or the first line of a function, then we need
6681 to handle it differently. */
6682 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6684 if (function != line_info->function)
6686 function = line_info->function;
6688 /* Set the address register to the first line in the function */
6689 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6691 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6694 fputc ('\n', asm_out_file);
6695 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6696 fputc ('\n', asm_out_file);
6697 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6698 fputc ('\n', asm_out_file);
6699 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6700 fputc ('\n', asm_out_file);
6704 /* ??? See the DW_LNS_advance_pc comment above. */
6707 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6709 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6712 fputc ('\n', asm_out_file);
6713 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6715 fputc ('\n', asm_out_file);
6719 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6721 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6723 fputc ('\n', asm_out_file);
6724 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6725 fputc ('\n', asm_out_file);
6726 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6727 fputc ('\n', asm_out_file);
6728 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6729 fputc ('\n', asm_out_file);
6732 strcpy (prev_line_label, line_label);
6734 /* Emit debug info for the source file of the current line, if
6735 different from the previous line. */
6736 if (line_info->dw_file_num != current_file)
6738 current_file = line_info->dw_file_num;
6739 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6741 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6743 fputc ('\n', asm_out_file);
6744 output_uleb128 (current_file);
6746 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
6748 fputc ('\n', asm_out_file);
6751 /* Emit debug info for the current line number, choosing the encoding
6752 that uses the least amount of space. */
6753 if (line_info->dw_line_num != current_line)
6755 line_offset = line_info->dw_line_num - current_line;
6756 line_delta = line_offset - DWARF_LINE_BASE;
6757 current_line = line_info->dw_line_num;
6758 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6760 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6761 DWARF_LINE_OPCODE_BASE + line_delta);
6763 fprintf (asm_out_file,
6764 "\t%s line %ld", ASM_COMMENT_START, current_line);
6766 fputc ('\n', asm_out_file);
6770 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6772 fprintf (asm_out_file, "\t%s advance to line %ld",
6773 ASM_COMMENT_START, current_line);
6775 fputc ('\n', asm_out_file);
6776 output_sleb128 (line_offset);
6777 fputc ('\n', asm_out_file);
6778 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6780 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6781 fputc ('\n', asm_out_file);
6786 /* We still need to start a new row, so output a copy insn. */
6787 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6789 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6790 fputc ('\n', asm_out_file);
6798 /* If we're done with a function, end its sequence. */
6799 if (lt_index == separate_line_info_table_in_use
6800 || separate_line_info_table[lt_index].function != function)
6805 /* Emit debug info for the address of the end of the function. */
6806 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6809 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6811 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6814 fputc ('\n', asm_out_file);
6815 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6817 fputc ('\n', asm_out_file);
6821 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6823 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6825 fputc ('\n', asm_out_file);
6826 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6827 fputc ('\n', asm_out_file);
6828 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6829 fputc ('\n', asm_out_file);
6830 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6831 fputc ('\n', asm_out_file);
6834 /* Output the marker for the end of this sequence. */
6835 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6837 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
6840 fputc ('\n', asm_out_file);
6842 fputc ('\n', asm_out_file);
6843 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6844 fputc ('\n', asm_out_file);
6848 /* Output the marker for the end of the line number info. */
6849 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
6852 /* Given a pointer to a tree node for some base type, return a pointer to
6853 a DIE that describes the given type.
6855 This routine must only be called for GCC type nodes that correspond to
6856 Dwarf base (fundamental) types. */
6859 base_type_die (type)
6862 register dw_die_ref base_type_result;
6863 register const char *type_name;
6864 register enum dwarf_type encoding;
6865 register tree name = TYPE_NAME (type);
6867 if (TREE_CODE (type) == ERROR_MARK
6868 || TREE_CODE (type) == VOID_TYPE)
6873 if (TREE_CODE (name) == TYPE_DECL)
6874 name = DECL_NAME (name);
6876 type_name = IDENTIFIER_POINTER (name);
6879 type_name = "__unknown__";
6881 switch (TREE_CODE (type))
6884 /* Carefully distinguish the C character types, without messing
6885 up if the language is not C. Note that we check only for the names
6886 that contain spaces; other names might occur by coincidence in other
6888 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6889 && (type == char_type_node
6890 || ! strcmp (type_name, "signed char")
6891 || ! strcmp (type_name, "unsigned char"))))
6893 if (TREE_UNSIGNED (type))
6894 encoding = DW_ATE_unsigned;
6896 encoding = DW_ATE_signed;
6899 /* else fall through. */
6902 /* GNU Pascal/Ada CHAR type. Not used in C. */
6903 if (TREE_UNSIGNED (type))
6904 encoding = DW_ATE_unsigned_char;
6906 encoding = DW_ATE_signed_char;
6910 encoding = DW_ATE_float;
6913 /* Dwarf2 doesn't know anything about complex ints, so use
6914 a user defined type for it. */
6916 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6917 encoding = DW_ATE_complex_float;
6919 encoding = DW_ATE_lo_user;
6923 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6924 encoding = DW_ATE_boolean;
6928 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6931 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6932 if (demangle_name_func)
6933 type_name = (*demangle_name_func) (type_name);
6935 add_AT_string (base_type_result, DW_AT_name, type_name);
6936 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6937 int_size_in_bytes (type));
6938 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6940 return base_type_result;
6943 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6944 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6945 a given type is generally the same as the given type, except that if the
6946 given type is a pointer or reference type, then the root type of the given
6947 type is the root type of the "basis" type for the pointer or reference
6948 type. (This definition of the "root" type is recursive.) Also, the root
6949 type of a `const' qualified type or a `volatile' qualified type is the
6950 root type of the given type without the qualifiers. */
6956 if (TREE_CODE (type) == ERROR_MARK)
6957 return error_mark_node;
6959 switch (TREE_CODE (type))
6962 return error_mark_node;
6965 case REFERENCE_TYPE:
6966 return type_main_variant (root_type (TREE_TYPE (type)));
6969 return type_main_variant (type);
6973 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6974 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6980 switch (TREE_CODE (type))
6995 case QUAL_UNION_TYPE:
7000 case REFERENCE_TYPE:
7013 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7014 entry that chains various modifiers in front of the given type. */
7017 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7019 register int is_const_type;
7020 register int is_volatile_type;
7021 register dw_die_ref context_die;
7023 register enum tree_code code = TREE_CODE (type);
7024 register dw_die_ref mod_type_die = NULL;
7025 register dw_die_ref sub_die = NULL;
7026 register tree item_type = NULL;
7028 if (code != ERROR_MARK)
7030 type = build_type_variant (type, is_const_type, is_volatile_type);
7032 mod_type_die = lookup_type_die (type);
7034 return mod_type_die;
7036 /* Handle C typedef types. */
7037 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7038 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
7040 tree dtype = TREE_TYPE (TYPE_NAME (type));
7043 /* For a named type, use the typedef. */
7044 gen_type_die (type, context_die);
7045 mod_type_die = lookup_type_die (type);
7048 else if (is_const_type < TYPE_READONLY (dtype)
7049 || is_volatile_type < TYPE_VOLATILE (dtype))
7050 /* cv-unqualified version of named type. Just use the unnamed
7051 type to which it refers. */
7053 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
7054 is_const_type, is_volatile_type,
7056 /* Else cv-qualified version of named type; fall through. */
7062 else if (is_const_type)
7064 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7065 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7067 else if (is_volatile_type)
7069 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7070 sub_die = modified_type_die (type, 0, 0, context_die);
7072 else if (code == POINTER_TYPE)
7074 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7075 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7077 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7079 item_type = TREE_TYPE (type);
7081 else if (code == REFERENCE_TYPE)
7083 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7084 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7086 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7088 item_type = TREE_TYPE (type);
7090 else if (is_base_type (type))
7091 mod_type_die = base_type_die (type);
7094 gen_type_die (type, context_die);
7096 /* We have to get the type_main_variant here (and pass that to the
7097 `lookup_type_die' routine) because the ..._TYPE node we have
7098 might simply be a *copy* of some original type node (where the
7099 copy was created to help us keep track of typedef names) and
7100 that copy might have a different TYPE_UID from the original
7102 mod_type_die = lookup_type_die (type_main_variant (type));
7103 if (mod_type_die == NULL)
7108 equate_type_number_to_die (type, mod_type_die);
7110 /* We must do this after the equate_type_number_to_die call, in case
7111 this is a recursive type. This ensures that the modified_type_die
7112 recursion will terminate even if the type is recursive. Recursive
7113 types are possible in Ada. */
7114 sub_die = modified_type_die (item_type,
7115 TYPE_READONLY (item_type),
7116 TYPE_VOLATILE (item_type),
7119 if (sub_die != NULL)
7120 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7122 return mod_type_die;
7125 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7126 an enumerated type. */
7132 return TREE_CODE (type) == ENUMERAL_TYPE;
7135 /* Return the register number described by a given RTL node. */
7141 register unsigned regno = REGNO (rtl);
7143 if (regno >= FIRST_PSEUDO_REGISTER)
7145 warning ("internal regno botch: regno = %d\n", regno);
7149 regno = DBX_REGISTER_NUMBER (regno);
7153 /* Return a location descriptor that designates a machine register. */
7155 static dw_loc_descr_ref
7156 reg_loc_descriptor (rtl)
7159 register dw_loc_descr_ref loc_result = NULL;
7160 register unsigned reg = reg_number (rtl);
7163 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7165 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7170 /* Return a location descriptor that designates a base+offset location. */
7172 static dw_loc_descr_ref
7173 based_loc_descr (reg, offset)
7177 register dw_loc_descr_ref loc_result;
7178 /* For the "frame base", we use the frame pointer or stack pointer
7179 registers, since the RTL for local variables is relative to one of
7181 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7182 ? HARD_FRAME_POINTER_REGNUM
7183 : STACK_POINTER_REGNUM);
7186 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7188 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7190 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7195 /* Return true if this RTL expression describes a base+offset calculation. */
7201 return (GET_CODE (rtl) == PLUS
7202 && ((GET_CODE (XEXP (rtl, 0)) == REG
7203 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7206 /* The following routine converts the RTL for a variable or parameter
7207 (resident in memory) into an equivalent Dwarf representation of a
7208 mechanism for getting the address of that same variable onto the top of a
7209 hypothetical "address evaluation" stack.
7211 When creating memory location descriptors, we are effectively transforming
7212 the RTL for a memory-resident object into its Dwarf postfix expression
7213 equivalent. This routine recursively descends an RTL tree, turning
7214 it into Dwarf postfix code as it goes.
7216 MODE is the mode of the memory reference, needed to handle some
7217 autoincrement addressing modes. */
7219 static dw_loc_descr_ref
7220 mem_loc_descriptor (rtl, mode)
7222 enum machine_mode mode;
7224 dw_loc_descr_ref mem_loc_result = NULL;
7225 /* Note that for a dynamically sized array, the location we will generate a
7226 description of here will be the lowest numbered location which is
7227 actually within the array. That's *not* necessarily the same as the
7228 zeroth element of the array. */
7230 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7231 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7234 switch (GET_CODE (rtl))
7238 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7239 just fall into the SUBREG code. */
7244 /* The case of a subreg may arise when we have a local (register)
7245 variable or a formal (register) parameter which doesn't quite fill
7246 up an entire register. For now, just assume that it is
7247 legitimate to make the Dwarf info refer to the whole register which
7248 contains the given subreg. */
7249 rtl = XEXP (rtl, 0);
7254 /* Whenever a register number forms a part of the description of the
7255 method for calculating the (dynamic) address of a memory resident
7256 object, DWARF rules require the register number be referred to as
7257 a "base register". This distinction is not based in any way upon
7258 what category of register the hardware believes the given register
7259 belongs to. This is strictly DWARF terminology we're dealing with
7260 here. Note that in cases where the location of a memory-resident
7261 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7262 OP_CONST (0)) the actual DWARF location descriptor that we generate
7263 may just be OP_BASEREG (basereg). This may look deceptively like
7264 the object in question was allocated to a register (rather than in
7265 memory) so DWARF consumers need to be aware of the subtle
7266 distinction between OP_REG and OP_BASEREG. */
7267 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7271 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7272 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7276 /* Some ports can transform a symbol ref into a label ref, because
7277 the symbol ref is too far away and has to be dumped into a constant
7281 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7282 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7283 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7288 /* Turn these into a PLUS expression and fall into the PLUS code
7290 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7291 GEN_INT (GET_CODE (rtl) == PRE_INC
7292 ? GET_MODE_UNIT_SIZE (mode)
7293 : -GET_MODE_UNIT_SIZE (mode)));
7298 if (is_based_loc (rtl))
7299 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7300 INTVAL (XEXP (rtl, 1)));
7303 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0),
7305 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1),
7307 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
7312 /* If a pseudo-reg is optimized away, it is possible for it to
7313 be replaced with a MEM containing a multiply. */
7314 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode));
7315 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode));
7316 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7320 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
7327 return mem_loc_result;
7330 /* Return a descriptor that describes the concatenation of two locations.
7331 This is typically a complex variable. */
7333 static dw_loc_descr_ref
7334 concat_loc_descriptor (x0, x1)
7335 register rtx x0, x1;
7337 dw_loc_descr_ref cc_loc_result = NULL;
7339 if (!is_pseudo_reg (x0)
7340 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7341 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7342 add_loc_descr (&cc_loc_result,
7343 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7345 if (!is_pseudo_reg (x1)
7346 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7347 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7348 add_loc_descr (&cc_loc_result,
7349 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7351 return cc_loc_result;
7354 /* Output a proper Dwarf location descriptor for a variable or parameter
7355 which is either allocated in a register or in a memory location. For a
7356 register, we just generate an OP_REG and the register number. For a
7357 memory location we provide a Dwarf postfix expression describing how to
7358 generate the (dynamic) address of the object onto the address stack. */
7360 static dw_loc_descr_ref
7361 loc_descriptor (rtl)
7364 dw_loc_descr_ref loc_result = NULL;
7365 switch (GET_CODE (rtl))
7368 /* The case of a subreg may arise when we have a local (register)
7369 variable or a formal (register) parameter which doesn't quite fill
7370 up an entire register. For now, just assume that it is
7371 legitimate to make the Dwarf info refer to the whole register which
7372 contains the given subreg. */
7373 rtl = XEXP (rtl, 0);
7378 loc_result = reg_loc_descriptor (rtl);
7382 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7386 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7396 /* Given a value, round it up to the lowest multiple of `boundary'
7397 which is not less than the value itself. */
7399 static inline HOST_WIDE_INT
7400 ceiling (value, boundary)
7401 HOST_WIDE_INT value;
7402 unsigned int boundary;
7404 return (((value + boundary - 1) / boundary) * boundary);
7407 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
7408 pointer to the declared type for the relevant field variable, or return
7409 `integer_type_node' if the given node turns out to be an
7418 if (TREE_CODE (decl) == ERROR_MARK)
7419 return integer_type_node;
7421 type = DECL_BIT_FIELD_TYPE (decl);
7422 if (type == NULL_TREE)
7423 type = TREE_TYPE (decl);
7428 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7429 node, return the alignment in bits for the type, or else return
7430 BITS_PER_WORD if the node actually turns out to be an
7433 static inline unsigned
7434 simple_type_align_in_bits (type)
7437 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
7440 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7441 node, return the size in bits for the type if it is a constant, or else
7442 return the alignment for the type if the type's size is not constant, or
7443 else return BITS_PER_WORD if the type actually turns out to be an
7446 static inline unsigned HOST_WIDE_INT
7447 simple_type_size_in_bits (type)
7450 if (TREE_CODE (type) == ERROR_MARK)
7451 return BITS_PER_WORD;
7454 register tree type_size_tree = TYPE_SIZE (type);
7456 if (! host_integerp (type_size_tree, 1))
7457 return TYPE_ALIGN (type);
7459 return tree_low_cst (type_size_tree, 1);
7463 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
7464 return the byte offset of the lowest addressed byte of the "containing
7465 object" for the given FIELD_DECL, or return 0 if we are unable to
7466 determine what that offset is, either because the argument turns out to
7467 be a pointer to an ERROR_MARK node, or because the offset is actually
7468 variable. (We can't handle the latter case just yet). */
7470 static HOST_WIDE_INT
7471 field_byte_offset (decl)
7474 unsigned int type_align_in_bytes;
7475 unsigned int type_align_in_bits;
7476 unsigned HOST_WIDE_INT type_size_in_bits;
7477 HOST_WIDE_INT object_offset_in_align_units;
7478 HOST_WIDE_INT object_offset_in_bits;
7479 HOST_WIDE_INT object_offset_in_bytes;
7481 tree field_size_tree;
7482 HOST_WIDE_INT bitpos_int;
7483 HOST_WIDE_INT deepest_bitpos;
7484 unsigned HOST_WIDE_INT field_size_in_bits;
7486 if (TREE_CODE (decl) == ERROR_MARK)
7489 if (TREE_CODE (decl) != FIELD_DECL)
7492 type = field_type (decl);
7493 field_size_tree = DECL_SIZE (decl);
7495 /* If there was an error, the size could be zero. */
7496 if (! field_size_tree)
7504 /* We cannot yet cope with fields whose positions are variable, so
7505 for now, when we see such things, we simply return 0. Someday, we may
7506 be able to handle such cases, but it will be damn difficult. */
7507 if (! host_integerp (bit_position (decl), 0))
7510 bitpos_int = int_bit_position (decl);
7512 /* If we don't know the size of the field, pretend it's a full word. */
7513 if (host_integerp (field_size_tree, 1))
7514 field_size_in_bits = tree_low_cst (field_size_tree, 1);
7516 field_size_in_bits = BITS_PER_WORD;
7518 type_size_in_bits = simple_type_size_in_bits (type);
7519 type_align_in_bits = simple_type_align_in_bits (type);
7520 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
7522 /* Note that the GCC front-end doesn't make any attempt to keep track of
7523 the starting bit offset (relative to the start of the containing
7524 structure type) of the hypothetical "containing object" for a bit-
7525 field. Thus, when computing the byte offset value for the start of the
7526 "containing object" of a bit-field, we must deduce this information on
7527 our own. This can be rather tricky to do in some cases. For example,
7528 handling the following structure type definition when compiling for an
7529 i386/i486 target (which only aligns long long's to 32-bit boundaries)
7532 struct S { int field1; long long field2:31; };
7534 Fortunately, there is a simple rule-of-thumb which can be
7535 used in such cases. When compiling for an i386/i486, GCC will allocate
7536 8 bytes for the structure shown above. It decides to do this based upon
7537 one simple rule for bit-field allocation. Quite simply, GCC allocates
7538 each "containing object" for each bit-field at the first (i.e. lowest
7539 addressed) legitimate alignment boundary (based upon the required
7540 minimum alignment for the declared type of the field) which it can
7541 possibly use, subject to the condition that there is still enough
7542 available space remaining in the containing object (when allocated at
7543 the selected point) to fully accommodate all of the bits of the
7544 bit-field itself. This simple rule makes it obvious why GCC allocates
7545 8 bytes for each object of the structure type shown above. When looking
7546 for a place to allocate the "containing object" for `field2', the
7547 compiler simply tries to allocate a 64-bit "containing object" at each
7548 successive 32-bit boundary (starting at zero) until it finds a place to
7549 allocate that 64- bit field such that at least 31 contiguous (and
7550 previously unallocated) bits remain within that selected 64 bit field.
7551 (As it turns out, for the example above, the compiler finds that it is
7552 OK to allocate the "containing object" 64-bit field at bit-offset zero
7553 within the structure type.) Here we attempt to work backwards from the
7554 limited set of facts we're given, and we try to deduce from those facts,
7555 where GCC must have believed that the containing object started (within
7556 the structure type). The value we deduce is then used (by the callers of
7557 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
7558 for fields (both bit-fields and, in the case of DW_AT_location, regular
7561 /* Figure out the bit-distance from the start of the structure to the
7562 "deepest" bit of the bit-field. */
7563 deepest_bitpos = bitpos_int + field_size_in_bits;
7565 /* This is the tricky part. Use some fancy footwork to deduce where the
7566 lowest addressed bit of the containing object must be. */
7567 object_offset_in_bits
7568 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
7570 /* Compute the offset of the containing object in "alignment units". */
7571 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
7573 /* Compute the offset of the containing object in bytes. */
7574 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
7576 return object_offset_in_bytes;
7579 /* The following routines define various Dwarf attributes and any data
7580 associated with them. */
7582 /* Add a location description attribute value to a DIE.
7584 This emits location attributes suitable for whole variables and
7585 whole parameters. Note that the location attributes for struct fields are
7586 generated by the routine `data_member_location_attribute' below. */
7589 add_AT_location_description (die, attr_kind, rtl)
7591 enum dwarf_attribute attr_kind;
7594 /* Handle a special case. If we are about to output a location descriptor
7595 for a variable or parameter which has been optimized out of existence,
7596 don't do that. A variable which has been optimized out
7597 of existence will have a DECL_RTL value which denotes a pseudo-reg.
7598 Currently, in some rare cases, variables can have DECL_RTL values which
7599 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
7600 elsewhere in the compiler. We treat such cases as if the variable(s) in
7601 question had been optimized out of existence. */
7603 if (is_pseudo_reg (rtl)
7604 || (GET_CODE (rtl) == MEM
7605 && is_pseudo_reg (XEXP (rtl, 0)))
7606 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
7607 references the internal argument pointer (a pseudo) in a function
7608 where all references to the internal argument pointer were
7609 eliminated via the optimizers. */
7610 || (GET_CODE (rtl) == MEM
7611 && GET_CODE (XEXP (rtl, 0)) == PLUS
7612 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
7613 || (GET_CODE (rtl) == CONCAT
7614 && is_pseudo_reg (XEXP (rtl, 0))
7615 && is_pseudo_reg (XEXP (rtl, 1))))
7618 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
7621 /* Attach the specialized form of location attribute used for data
7622 members of struct and union types. In the special case of a
7623 FIELD_DECL node which represents a bit-field, the "offset" part
7624 of this special location descriptor must indicate the distance
7625 in bytes from the lowest-addressed byte of the containing struct
7626 or union type to the lowest-addressed byte of the "containing
7627 object" for the bit-field. (See the `field_byte_offset' function
7628 above).. For any given bit-field, the "containing object" is a
7629 hypothetical object (of some integral or enum type) within which
7630 the given bit-field lives. The type of this hypothetical
7631 "containing object" is always the same as the declared type of
7632 the individual bit-field itself (for GCC anyway... the DWARF
7633 spec doesn't actually mandate this). Note that it is the size
7634 (in bytes) of the hypothetical "containing object" which will
7635 be given in the DW_AT_byte_size attribute for this bit-field.
7636 (See the `byte_size_attribute' function below.) It is also used
7637 when calculating the value of the DW_AT_bit_offset attribute.
7638 (See the `bit_offset_attribute' function below). */
7641 add_data_member_location_attribute (die, decl)
7642 register dw_die_ref die;
7645 register unsigned long offset;
7646 register dw_loc_descr_ref loc_descr;
7647 register enum dwarf_location_atom op;
7649 if (TREE_CODE (decl) == TREE_VEC)
7650 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
7652 offset = field_byte_offset (decl);
7654 /* The DWARF2 standard says that we should assume that the structure address
7655 is already on the stack, so we can specify a structure field address
7656 by using DW_OP_plus_uconst. */
7658 #ifdef MIPS_DEBUGGING_INFO
7659 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
7660 correctly. It works only if we leave the offset on the stack. */
7663 op = DW_OP_plus_uconst;
7666 loc_descr = new_loc_descr (op, offset, 0);
7667 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
7670 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
7671 does not have a "location" either in memory or in a register. These
7672 things can arise in GNU C when a constant is passed as an actual parameter
7673 to an inlined function. They can also arise in C++ where declared
7674 constants do not necessarily get memory "homes". */
7677 add_const_value_attribute (die, rtl)
7678 register dw_die_ref die;
7681 switch (GET_CODE (rtl))
7684 /* Note that a CONST_INT rtx could represent either an integer or a
7685 floating-point constant. A CONST_INT is used whenever the constant
7686 will fit into a single word. In all such cases, the original mode
7687 of the constant value is wiped out, and the CONST_INT rtx is
7688 assigned VOIDmode. */
7689 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
7693 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
7694 floating-point constant. A CONST_DOUBLE is used whenever the
7695 constant requires more than one word in order to be adequately
7696 represented. We output CONST_DOUBLEs as blocks. */
7698 register enum machine_mode mode = GET_MODE (rtl);
7700 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
7702 register unsigned length = GET_MODE_SIZE (mode) / 4;
7703 long *array = (long *) xmalloc (sizeof (long) * length);
7706 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
7710 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
7714 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
7719 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
7726 add_AT_float (die, DW_AT_const_value, length, array);
7729 add_AT_long_long (die, DW_AT_const_value,
7730 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
7735 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
7741 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
7745 /* In cases where an inlined instance of an inline function is passed
7746 the address of an `auto' variable (which is local to the caller) we
7747 can get a situation where the DECL_RTL of the artificial local
7748 variable (for the inlining) which acts as a stand-in for the
7749 corresponding formal parameter (of the inline function) will look
7750 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
7751 exactly a compile-time constant expression, but it isn't the address
7752 of the (artificial) local variable either. Rather, it represents the
7753 *value* which the artificial local variable always has during its
7754 lifetime. We currently have no way to represent such quasi-constant
7755 values in Dwarf, so for now we just punt and generate nothing. */
7759 /* No other kinds of rtx should be possible here. */
7765 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
7766 data attribute for a variable or a parameter. We generate the
7767 DW_AT_const_value attribute only in those cases where the given variable
7768 or parameter does not have a true "location" either in memory or in a
7769 register. This can happen (for example) when a constant is passed as an
7770 actual argument in a call to an inline function. (It's possible that
7771 these things can crop up in other ways also.) Note that one type of
7772 constant value which can be passed into an inlined function is a constant
7773 pointer. This can happen for example if an actual argument in an inlined
7774 function call evaluates to a compile-time constant address. */
7777 add_location_or_const_value_attribute (die, decl)
7778 register dw_die_ref die;
7782 register tree declared_type;
7783 register tree passed_type;
7785 if (TREE_CODE (decl) == ERROR_MARK)
7788 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
7791 /* Here we have to decide where we are going to say the parameter "lives"
7792 (as far as the debugger is concerned). We only have a couple of
7793 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
7795 DECL_RTL normally indicates where the parameter lives during most of the
7796 activation of the function. If optimization is enabled however, this
7797 could be either NULL or else a pseudo-reg. Both of those cases indicate
7798 that the parameter doesn't really live anywhere (as far as the code
7799 generation parts of GCC are concerned) during most of the function's
7800 activation. That will happen (for example) if the parameter is never
7801 referenced within the function.
7803 We could just generate a location descriptor here for all non-NULL
7804 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
7805 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
7806 where DECL_RTL is NULL or is a pseudo-reg.
7808 Note however that we can only get away with using DECL_INCOMING_RTL as
7809 a backup substitute for DECL_RTL in certain limited cases. In cases
7810 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
7811 we can be sure that the parameter was passed using the same type as it is
7812 declared to have within the function, and that its DECL_INCOMING_RTL
7813 points us to a place where a value of that type is passed.
7815 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
7816 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
7817 because in these cases DECL_INCOMING_RTL points us to a value of some
7818 type which is *different* from the type of the parameter itself. Thus,
7819 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
7820 such cases, the debugger would end up (for example) trying to fetch a
7821 `float' from a place which actually contains the first part of a
7822 `double'. That would lead to really incorrect and confusing
7823 output at debug-time.
7825 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
7826 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
7827 are a couple of exceptions however. On little-endian machines we can
7828 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
7829 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
7830 an integral type that is smaller than TREE_TYPE (decl). These cases arise
7831 when (on a little-endian machine) a non-prototyped function has a
7832 parameter declared to be of type `short' or `char'. In such cases,
7833 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
7834 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
7835 passed `int' value. If the debugger then uses that address to fetch
7836 a `short' or a `char' (on a little-endian machine) the result will be
7837 the correct data, so we allow for such exceptional cases below.
7839 Note that our goal here is to describe the place where the given formal
7840 parameter lives during most of the function's activation (i.e. between
7841 the end of the prologue and the start of the epilogue). We'll do that
7842 as best as we can. Note however that if the given formal parameter is
7843 modified sometime during the execution of the function, then a stack
7844 backtrace (at debug-time) will show the function as having been
7845 called with the *new* value rather than the value which was
7846 originally passed in. This happens rarely enough that it is not
7847 a major problem, but it *is* a problem, and I'd like to fix it.
7849 A future version of dwarf2out.c may generate two additional
7850 attributes for any given DW_TAG_formal_parameter DIE which will
7851 describe the "passed type" and the "passed location" for the
7852 given formal parameter in addition to the attributes we now
7853 generate to indicate the "declared type" and the "active
7854 location" for each parameter. This additional set of attributes
7855 could be used by debuggers for stack backtraces. Separately, note
7856 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
7857 NULL also. This happens (for example) for inlined-instances of
7858 inline function formal parameters which are never referenced.
7859 This really shouldn't be happening. All PARM_DECL nodes should
7860 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
7861 doesn't currently generate these values for inlined instances of
7862 inline function parameters, so when we see such cases, we are
7863 just out-of-luck for the time being (until integrate.c
7866 /* Use DECL_RTL as the "location" unless we find something better. */
7867 rtl = DECL_RTL (decl);
7869 if (TREE_CODE (decl) == PARM_DECL)
7871 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
7873 declared_type = type_main_variant (TREE_TYPE (decl));
7874 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
7876 /* This decl represents a formal parameter which was optimized out.
7877 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
7878 all* cases where (rtl == NULL_RTX) just below. */
7879 if (declared_type == passed_type)
7880 rtl = DECL_INCOMING_RTL (decl);
7881 else if (! BYTES_BIG_ENDIAN
7882 && TREE_CODE (declared_type) == INTEGER_TYPE
7883 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
7884 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
7885 rtl = DECL_INCOMING_RTL (decl);
7888 /* If the parm was passed in registers, but lives on the stack, then
7889 make a big endian correction if the mode of the type of the
7890 parameter is not the same as the mode of the rtl. */
7891 /* ??? This is the same series of checks that are made in dbxout.c before
7892 we reach the big endian correction code there. It isn't clear if all
7893 of these checks are necessary here, but keeping them all is the safe
7895 else if (GET_CODE (rtl) == MEM
7896 && XEXP (rtl, 0) != const0_rtx
7897 && ! CONSTANT_P (XEXP (rtl, 0))
7898 /* Not passed in memory. */
7899 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
7900 /* Not passed by invisible reference. */
7901 && (GET_CODE (XEXP (rtl, 0)) != REG
7902 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
7903 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
7904 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
7905 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
7908 /* Big endian correction check. */
7910 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
7911 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
7914 int offset = (UNITS_PER_WORD
7915 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
7916 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
7917 plus_constant (XEXP (rtl, 0), offset));
7921 if (rtl == NULL_RTX)
7924 rtl = eliminate_regs (rtl, 0, NULL_RTX);
7925 #ifdef LEAF_REG_REMAP
7926 if (current_function_uses_only_leaf_regs)
7927 leaf_renumber_regs_insn (rtl);
7930 switch (GET_CODE (rtl))
7933 /* The address of a variable that was optimized away; don't emit
7944 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7945 add_const_value_attribute (die, rtl);
7952 add_AT_location_description (die, DW_AT_location, rtl);
7960 /* If we don't have a copy of this variable in memory for some reason (such
7961 as a C++ member constant that doesn't have an out-of-line definition),
7962 we should tell the debugger about the constant value. */
7965 tree_add_const_value_attribute (var_die, decl)
7969 tree init = DECL_INITIAL (decl);
7970 tree type = TREE_TYPE (decl);
7972 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
7973 && initializer_constant_valid_p (init, type) == null_pointer_node)
7978 switch (TREE_CODE (type))
7981 if (host_integerp (init, 0))
7982 add_AT_unsigned (var_die, DW_AT_const_value,
7983 TREE_INT_CST_LOW (init));
7985 add_AT_long_long (var_die, DW_AT_const_value,
7986 TREE_INT_CST_HIGH (init),
7987 TREE_INT_CST_LOW (init));
7994 /* Generate an DW_AT_name attribute given some string value to be included as
7995 the value of the attribute. */
7998 add_name_attribute (die, name_string)
7999 register dw_die_ref die;
8000 register const char *name_string;
8002 if (name_string != NULL && *name_string != 0)
8004 if (demangle_name_func)
8005 name_string = (*demangle_name_func) (name_string);
8007 add_AT_string (die, DW_AT_name, name_string);
8011 /* Given a tree node describing an array bound (either lower or upper) output
8012 a representation for that bound. */
8015 add_bound_info (subrange_die, bound_attr, bound)
8016 register dw_die_ref subrange_die;
8017 register enum dwarf_attribute bound_attr;
8018 register tree bound;
8020 /* If this is an Ada unconstrained array type, then don't emit any debug
8021 info because the array bounds are unknown. They are parameterized when
8022 the type is instantiated. */
8023 if (contains_placeholder_p (bound))
8026 switch (TREE_CODE (bound))
8031 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8033 if (! host_integerp (bound, 0)
8034 || (bound_attr == DW_AT_lower_bound
8035 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8036 || (is_fortran () && integer_onep (bound)))))
8037 /* use the default */
8040 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8045 case NON_LVALUE_EXPR:
8046 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8050 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8051 access the upper bound values may be bogus. If they refer to a
8052 register, they may only describe how to get at these values at the
8053 points in the generated code right after they have just been
8054 computed. Worse yet, in the typical case, the upper bound values
8055 will not even *be* computed in the optimized code (though the
8056 number of elements will), so these SAVE_EXPRs are entirely
8057 bogus. In order to compensate for this fact, we check here to see
8058 if optimization is enabled, and if so, we don't add an attribute
8059 for the (unknown and unknowable) upper bound. This should not
8060 cause too much trouble for existing (stupid?) debuggers because
8061 they have to deal with empty upper bounds location descriptions
8062 anyway in order to be able to deal with incomplete array types.
8063 Of course an intelligent debugger (GDB?) should be able to
8064 comprehend that a missing upper bound specification in a array
8065 type used for a storage class `auto' local array variable
8066 indicates that the upper bound is both unknown (at compile- time)
8067 and unknowable (at run-time) due to optimization.
8069 We assume that a MEM rtx is safe because gcc wouldn't put the
8070 value there unless it was going to be used repeatedly in the
8071 function, i.e. for cleanups. */
8072 if (! optimize || (SAVE_EXPR_RTL (bound)
8073 && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8075 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8076 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8077 register rtx loc = SAVE_EXPR_RTL (bound);
8079 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8080 it references an outer function's frame. */
8082 if (GET_CODE (loc) == MEM)
8084 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8086 if (XEXP (loc, 0) != new_addr)
8087 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8090 add_AT_flag (decl_die, DW_AT_artificial, 1);
8091 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8092 add_AT_location_description (decl_die, DW_AT_location, loc);
8093 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8096 /* Else leave out the attribute. */
8102 /* ??? These types of bounds can be created by the Ada front end,
8103 and it isn't clear how to emit debug info for them. */
8111 /* Note that the block of subscript information for an array type also
8112 includes information about the element type of type given array type. */
8115 add_subscript_info (type_die, type)
8116 register dw_die_ref type_die;
8119 #ifndef MIPS_DEBUGGING_INFO
8120 register unsigned dimension_number;
8122 register tree lower, upper;
8123 register dw_die_ref subrange_die;
8125 /* The GNU compilers represent multidimensional array types as sequences of
8126 one dimensional array types whose element types are themselves array
8127 types. Here we squish that down, so that each multidimensional array
8128 type gets only one array_type DIE in the Dwarf debugging info. The draft
8129 Dwarf specification say that we are allowed to do this kind of
8130 compression in C (because there is no difference between an array or
8131 arrays and a multidimensional array in C) but for other source languages
8132 (e.g. Ada) we probably shouldn't do this. */
8134 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8135 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8136 We work around this by disabling this feature. See also
8137 gen_array_type_die. */
8138 #ifndef MIPS_DEBUGGING_INFO
8139 for (dimension_number = 0;
8140 TREE_CODE (type) == ARRAY_TYPE;
8141 type = TREE_TYPE (type), dimension_number++)
8144 register tree domain = TYPE_DOMAIN (type);
8146 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8147 and (in GNU C only) variable bounds. Handle all three forms
8149 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8152 /* We have an array type with specified bounds. */
8153 lower = TYPE_MIN_VALUE (domain);
8154 upper = TYPE_MAX_VALUE (domain);
8156 /* define the index type. */
8157 if (TREE_TYPE (domain))
8159 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8160 TREE_TYPE field. We can't emit debug info for this
8161 because it is an unnamed integral type. */
8162 if (TREE_CODE (domain) == INTEGER_TYPE
8163 && TYPE_NAME (domain) == NULL_TREE
8164 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8165 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8168 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8172 /* ??? If upper is NULL, the array has unspecified length,
8173 but it does have a lower bound. This happens with Fortran
8175 Since the debugger is definitely going to need to know N
8176 to produce useful results, go ahead and output the lower
8177 bound solo, and hope the debugger can cope. */
8179 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8181 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8184 /* We have an array type with an unspecified length. The DWARF-2
8185 spec does not say how to handle this; let's just leave out the
8189 #ifndef MIPS_DEBUGGING_INFO
8195 add_byte_size_attribute (die, tree_node)
8197 register tree tree_node;
8199 register unsigned size;
8201 switch (TREE_CODE (tree_node))
8209 case QUAL_UNION_TYPE:
8210 size = int_size_in_bytes (tree_node);
8213 /* For a data member of a struct or union, the DW_AT_byte_size is
8214 generally given as the number of bytes normally allocated for an
8215 object of the *declared* type of the member itself. This is true
8216 even for bit-fields. */
8217 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8223 /* Note that `size' might be -1 when we get to this point. If it is, that
8224 indicates that the byte size of the entity in question is variable. We
8225 have no good way of expressing this fact in Dwarf at the present time,
8226 so just let the -1 pass on through. */
8228 add_AT_unsigned (die, DW_AT_byte_size, size);
8231 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8232 which specifies the distance in bits from the highest order bit of the
8233 "containing object" for the bit-field to the highest order bit of the
8236 For any given bit-field, the "containing object" is a hypothetical
8237 object (of some integral or enum type) within which the given bit-field
8238 lives. The type of this hypothetical "containing object" is always the
8239 same as the declared type of the individual bit-field itself. The
8240 determination of the exact location of the "containing object" for a
8241 bit-field is rather complicated. It's handled by the
8242 `field_byte_offset' function (above).
8244 Note that it is the size (in bytes) of the hypothetical "containing object"
8245 which will be given in the DW_AT_byte_size attribute for this bit-field.
8246 (See `byte_size_attribute' above). */
8249 add_bit_offset_attribute (die, decl)
8250 register dw_die_ref die;
8253 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8254 tree type = DECL_BIT_FIELD_TYPE (decl);
8255 HOST_WIDE_INT bitpos_int;
8256 HOST_WIDE_INT highest_order_object_bit_offset;
8257 HOST_WIDE_INT highest_order_field_bit_offset;
8258 HOST_WIDE_INT unsigned bit_offset;
8260 /* Must be a field and a bit field. */
8262 || TREE_CODE (decl) != FIELD_DECL)
8265 /* We can't yet handle bit-fields whose offsets are variable, so if we
8266 encounter such things, just return without generating any attribute
8267 whatsoever. Likewise for variable or too large size. */
8268 if (! host_integerp (bit_position (decl), 0)
8269 || ! host_integerp (DECL_SIZE (decl), 1))
8272 bitpos_int = int_bit_position (decl);
8274 /* Note that the bit offset is always the distance (in bits) from the
8275 highest-order bit of the "containing object" to the highest-order bit of
8276 the bit-field itself. Since the "high-order end" of any object or field
8277 is different on big-endian and little-endian machines, the computation
8278 below must take account of these differences. */
8279 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8280 highest_order_field_bit_offset = bitpos_int;
8282 if (! BYTES_BIG_ENDIAN)
8284 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8285 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8289 = (! BYTES_BIG_ENDIAN
8290 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8291 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8293 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8296 /* For a FIELD_DECL node which represents a bit field, output an attribute
8297 which specifies the length in bits of the given field. */
8300 add_bit_size_attribute (die, decl)
8301 register dw_die_ref die;
8304 /* Must be a field and a bit field. */
8305 if (TREE_CODE (decl) != FIELD_DECL
8306 || ! DECL_BIT_FIELD_TYPE (decl))
8309 if (host_integerp (DECL_SIZE (decl), 1))
8310 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8313 /* If the compiled language is ANSI C, then add a 'prototyped'
8314 attribute, if arg types are given for the parameters of a function. */
8317 add_prototyped_attribute (die, func_type)
8318 register dw_die_ref die;
8319 register tree func_type;
8321 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8322 && TYPE_ARG_TYPES (func_type) != NULL)
8323 add_AT_flag (die, DW_AT_prototyped, 1);
8326 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8327 by looking in either the type declaration or object declaration
8331 add_abstract_origin_attribute (die, origin)
8332 register dw_die_ref die;
8333 register tree origin;
8335 dw_die_ref origin_die = NULL;
8337 if (TREE_CODE (origin) != FUNCTION_DECL)
8339 /* We may have gotten separated from the block for the inlined
8340 function, if we're in an exception handler or some such; make
8341 sure that the abstract function has been written out.
8343 Doing this for nested functions is wrong, however; functions are
8344 distinct units, and our context might not even be inline. */
8347 fn = TYPE_STUB_DECL (fn);
8348 fn = decl_function_context (fn);
8350 gen_abstract_function (fn);
8353 if (DECL_P (origin))
8354 origin_die = lookup_decl_die (origin);
8355 else if (TYPE_P (origin))
8356 origin_die = lookup_type_die (origin);
8358 if (origin_die == NULL)
8361 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
8364 /* We do not currently support the pure_virtual attribute. */
8367 add_pure_or_virtual_attribute (die, func_decl)
8368 register dw_die_ref die;
8369 register tree func_decl;
8371 if (DECL_VINDEX (func_decl))
8373 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8375 if (host_integerp (DECL_VINDEX (func_decl), 0))
8376 add_AT_loc (die, DW_AT_vtable_elem_location,
8377 new_loc_descr (DW_OP_constu,
8378 tree_low_cst (DECL_VINDEX (func_decl), 0),
8381 /* GNU extension: Record what type this method came from originally. */
8382 if (debug_info_level > DINFO_LEVEL_TERSE)
8383 add_AT_die_ref (die, DW_AT_containing_type,
8384 lookup_type_die (DECL_CONTEXT (func_decl)));
8388 /* Add source coordinate attributes for the given decl. */
8391 add_src_coords_attributes (die, decl)
8392 register dw_die_ref die;
8395 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
8397 add_AT_unsigned (die, DW_AT_decl_file, file_index);
8398 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8401 /* Add an DW_AT_name attribute and source coordinate attribute for the
8402 given decl, but only if it actually has a name. */
8405 add_name_and_src_coords_attributes (die, decl)
8406 register dw_die_ref die;
8409 register tree decl_name;
8411 decl_name = DECL_NAME (decl);
8412 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
8414 add_name_attribute (die, dwarf2_name (decl, 0));
8415 if (! DECL_ARTIFICIAL (decl))
8416 add_src_coords_attributes (die, decl);
8418 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
8419 && TREE_PUBLIC (decl)
8420 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
8421 add_AT_string (die, DW_AT_MIPS_linkage_name,
8422 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
8426 /* Push a new declaration scope. */
8429 push_decl_scope (scope)
8432 /* Make room in the decl_scope_table, if necessary. */
8433 if (decl_scope_table_allocated == decl_scope_depth)
8435 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
8437 = (tree *) xrealloc (decl_scope_table,
8438 decl_scope_table_allocated * sizeof (tree));
8441 decl_scope_table[decl_scope_depth] = scope;
8445 /* Pop a declaration scope. */
8449 if (decl_scope_depth <= 0)
8454 /* Return the DIE for the scope that immediately contains this type.
8455 Non-named types get global scope. Named types nested in other
8456 types get their containing scope if it's open, or global scope
8457 otherwise. All other types (i.e. function-local named types) get
8458 the current active scope. */
8461 scope_die_for (t, context_die)
8463 register dw_die_ref context_die;
8465 register dw_die_ref scope_die = NULL;
8466 register tree containing_scope;
8469 /* Non-types always go in the current scope. */
8473 containing_scope = TYPE_CONTEXT (t);
8475 /* Ignore namespaces for the moment. */
8476 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
8477 containing_scope = NULL_TREE;
8479 /* Ignore function type "scopes" from the C frontend. They mean that
8480 a tagged type is local to a parmlist of a function declarator, but
8481 that isn't useful to DWARF. */
8482 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
8483 containing_scope = NULL_TREE;
8485 if (containing_scope == NULL_TREE)
8486 scope_die = comp_unit_die;
8487 else if (TYPE_P (containing_scope))
8489 /* For types, we can just look up the appropriate DIE. But
8490 first we check to see if we're in the middle of emitting it
8491 so we know where the new DIE should go. */
8493 for (i = decl_scope_depth - 1; i >= 0; --i)
8494 if (decl_scope_table[i] == containing_scope)
8499 if (debug_info_level > DINFO_LEVEL_TERSE
8500 && !TREE_ASM_WRITTEN (containing_scope))
8503 /* If none of the current dies are suitable, we get file scope. */
8504 scope_die = comp_unit_die;
8507 scope_die = lookup_type_die (containing_scope);
8510 scope_die = context_die;
8515 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
8517 static inline int local_scope_p PARAMS ((dw_die_ref));
8519 local_scope_p (context_die)
8520 dw_die_ref context_die;
8522 for (; context_die; context_die = context_die->die_parent)
8523 if (context_die->die_tag == DW_TAG_inlined_subroutine
8524 || context_die->die_tag == DW_TAG_subprogram)
8529 /* Returns nonzero iff CONTEXT_DIE is a class. */
8531 static inline int class_scope_p PARAMS ((dw_die_ref));
8533 class_scope_p (context_die)
8534 dw_die_ref context_die;
8537 && (context_die->die_tag == DW_TAG_structure_type
8538 || context_die->die_tag == DW_TAG_union_type));
8541 /* Many forms of DIEs require a "type description" attribute. This
8542 routine locates the proper "type descriptor" die for the type given
8543 by 'type', and adds an DW_AT_type attribute below the given die. */
8546 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
8547 register dw_die_ref object_die;
8549 register int decl_const;
8550 register int decl_volatile;
8551 register dw_die_ref context_die;
8553 register enum tree_code code = TREE_CODE (type);
8554 register dw_die_ref type_die = NULL;
8556 /* ??? If this type is an unnamed subrange type of an integral or
8557 floating-point type, use the inner type. This is because we have no
8558 support for unnamed types in base_type_die. This can happen if this is
8559 an Ada subrange type. Correct solution is emit a subrange type die. */
8560 if ((code == INTEGER_TYPE || code == REAL_TYPE)
8561 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
8562 type = TREE_TYPE (type), code = TREE_CODE (type);
8564 if (code == ERROR_MARK)
8567 /* Handle a special case. For functions whose return type is void, we
8568 generate *no* type attribute. (Note that no object may have type
8569 `void', so this only applies to function return types). */
8570 if (code == VOID_TYPE)
8573 type_die = modified_type_die (type,
8574 decl_const || TYPE_READONLY (type),
8575 decl_volatile || TYPE_VOLATILE (type),
8577 if (type_die != NULL)
8578 add_AT_die_ref (object_die, DW_AT_type, type_die);
8581 /* Given a tree pointer to a struct, class, union, or enum type node, return
8582 a pointer to the (string) tag name for the given type, or zero if the type
8583 was declared without a tag. */
8589 register const char *name = 0;
8591 if (TYPE_NAME (type) != 0)
8593 register tree t = 0;
8595 /* Find the IDENTIFIER_NODE for the type name. */
8596 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
8597 t = TYPE_NAME (type);
8599 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
8600 a TYPE_DECL node, regardless of whether or not a `typedef' was
8602 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8603 && ! DECL_IGNORED_P (TYPE_NAME (type)))
8604 t = DECL_NAME (TYPE_NAME (type));
8606 /* Now get the name as a string, or invent one. */
8608 name = IDENTIFIER_POINTER (t);
8611 return (name == 0 || *name == '\0') ? 0 : name;
8614 /* Return the type associated with a data member, make a special check
8615 for bit field types. */
8618 member_declared_type (member)
8619 register tree member;
8621 return (DECL_BIT_FIELD_TYPE (member)
8622 ? DECL_BIT_FIELD_TYPE (member)
8623 : TREE_TYPE (member));
8626 /* Get the decl's label, as described by its RTL. This may be different
8627 from the DECL_NAME name used in the source file. */
8631 decl_start_label (decl)
8636 x = DECL_RTL (decl);
8637 if (GET_CODE (x) != MEM)
8641 if (GET_CODE (x) != SYMBOL_REF)
8644 fnname = XSTR (x, 0);
8649 /* These routines generate the internal representation of the DIE's for
8650 the compilation unit. Debugging information is collected by walking
8651 the declaration trees passed in from dwarf2out_decl(). */
8654 gen_array_type_die (type, context_die)
8656 register dw_die_ref context_die;
8658 register dw_die_ref scope_die = scope_die_for (type, context_die);
8659 register dw_die_ref array_die;
8660 register tree element_type;
8662 /* ??? The SGI dwarf reader fails for array of array of enum types unless
8663 the inner array type comes before the outer array type. Thus we must
8664 call gen_type_die before we call new_die. See below also. */
8665 #ifdef MIPS_DEBUGGING_INFO
8666 gen_type_die (TREE_TYPE (type), context_die);
8669 array_die = new_die (DW_TAG_array_type, scope_die);
8672 /* We default the array ordering. SDB will probably do
8673 the right things even if DW_AT_ordering is not present. It's not even
8674 an issue until we start to get into multidimensional arrays anyway. If
8675 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
8676 then we'll have to put the DW_AT_ordering attribute back in. (But if
8677 and when we find out that we need to put these in, we will only do so
8678 for multidimensional arrays. */
8679 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
8682 #ifdef MIPS_DEBUGGING_INFO
8683 /* The SGI compilers handle arrays of unknown bound by setting
8684 AT_declaration and not emitting any subrange DIEs. */
8685 if (! TYPE_DOMAIN (type))
8686 add_AT_unsigned (array_die, DW_AT_declaration, 1);
8689 add_subscript_info (array_die, type);
8691 add_name_attribute (array_die, type_tag (type));
8692 equate_type_number_to_die (type, array_die);
8694 /* Add representation of the type of the elements of this array type. */
8695 element_type = TREE_TYPE (type);
8697 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8698 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8699 We work around this by disabling this feature. See also
8700 add_subscript_info. */
8701 #ifndef MIPS_DEBUGGING_INFO
8702 while (TREE_CODE (element_type) == ARRAY_TYPE)
8703 element_type = TREE_TYPE (element_type);
8705 gen_type_die (element_type, context_die);
8708 add_type_attribute (array_die, element_type, 0, 0, context_die);
8712 gen_set_type_die (type, context_die)
8714 register dw_die_ref context_die;
8716 register dw_die_ref type_die
8717 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
8719 equate_type_number_to_die (type, type_die);
8720 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
8725 gen_entry_point_die (decl, context_die)
8727 register dw_die_ref context_die;
8729 register tree origin = decl_ultimate_origin (decl);
8730 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
8732 add_abstract_origin_attribute (decl_die, origin);
8735 add_name_and_src_coords_attributes (decl_die, decl);
8736 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
8740 if (DECL_ABSTRACT (decl))
8741 equate_decl_number_to_die (decl, decl_die);
8743 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
8747 /* Remember a type in the incomplete_types_list. */
8750 add_incomplete_type (type)
8753 if (incomplete_types == incomplete_types_allocated)
8755 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
8756 incomplete_types_list
8757 = (tree *) xrealloc (incomplete_types_list,
8758 sizeof (tree) * incomplete_types_allocated);
8761 incomplete_types_list[incomplete_types++] = type;
8764 /* Walk through the list of incomplete types again, trying once more to
8765 emit full debugging info for them. */
8768 retry_incomplete_types ()
8772 while (incomplete_types)
8775 type = incomplete_types_list[incomplete_types];
8776 gen_type_die (type, comp_unit_die);
8780 /* Generate a DIE to represent an inlined instance of an enumeration type. */
8783 gen_inlined_enumeration_type_die (type, context_die)
8785 register dw_die_ref context_die;
8787 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
8789 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8790 be incomplete and such types are not marked. */
8791 add_abstract_origin_attribute (type_die, type);
8794 /* Generate a DIE to represent an inlined instance of a structure type. */
8797 gen_inlined_structure_type_die (type, context_die)
8799 register dw_die_ref context_die;
8801 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
8803 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8804 be incomplete and such types are not marked. */
8805 add_abstract_origin_attribute (type_die, type);
8808 /* Generate a DIE to represent an inlined instance of a union type. */
8811 gen_inlined_union_type_die (type, context_die)
8813 register dw_die_ref context_die;
8815 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
8817 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8818 be incomplete and such types are not marked. */
8819 add_abstract_origin_attribute (type_die, type);
8822 /* Generate a DIE to represent an enumeration type. Note that these DIEs
8823 include all of the information about the enumeration values also. Each
8824 enumerated type name/value is listed as a child of the enumerated type
8828 gen_enumeration_type_die (type, context_die)
8830 register dw_die_ref context_die;
8832 register dw_die_ref type_die = lookup_type_die (type);
8834 if (type_die == NULL)
8836 type_die = new_die (DW_TAG_enumeration_type,
8837 scope_die_for (type, context_die));
8838 equate_type_number_to_die (type, type_die);
8839 add_name_attribute (type_die, type_tag (type));
8841 else if (! TYPE_SIZE (type))
8844 remove_AT (type_die, DW_AT_declaration);
8846 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
8847 given enum type is incomplete, do not generate the DW_AT_byte_size
8848 attribute or the DW_AT_element_list attribute. */
8849 if (TYPE_SIZE (type))
8853 TREE_ASM_WRITTEN (type) = 1;
8854 add_byte_size_attribute (type_die, type);
8855 if (TYPE_STUB_DECL (type) != NULL_TREE)
8856 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8858 /* If the first reference to this type was as the return type of an
8859 inline function, then it may not have a parent. Fix this now. */
8860 if (type_die->die_parent == NULL)
8861 add_child_die (scope_die_for (type, context_die), type_die);
8863 for (link = TYPE_FIELDS (type);
8864 link != NULL; link = TREE_CHAIN (link))
8866 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
8868 add_name_attribute (enum_die,
8869 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
8871 if (host_integerp (TREE_VALUE (link), 0))
8873 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
8874 add_AT_int (enum_die, DW_AT_const_value,
8875 tree_low_cst (TREE_VALUE (link), 0));
8877 add_AT_unsigned (enum_die, DW_AT_const_value,
8878 tree_low_cst (TREE_VALUE (link), 0));
8883 add_AT_flag (type_die, DW_AT_declaration, 1);
8886 /* Generate a DIE to represent either a real live formal parameter decl or to
8887 represent just the type of some formal parameter position in some function
8890 Note that this routine is a bit unusual because its argument may be a
8891 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
8892 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
8893 node. If it's the former then this function is being called to output a
8894 DIE to represent a formal parameter object (or some inlining thereof). If
8895 it's the latter, then this function is only being called to output a
8896 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
8897 argument type of some subprogram type. */
8900 gen_formal_parameter_die (node, context_die)
8902 register dw_die_ref context_die;
8904 register dw_die_ref parm_die
8905 = new_die (DW_TAG_formal_parameter, context_die);
8906 register tree origin;
8908 switch (TREE_CODE_CLASS (TREE_CODE (node)))
8911 origin = decl_ultimate_origin (node);
8913 add_abstract_origin_attribute (parm_die, origin);
8916 add_name_and_src_coords_attributes (parm_die, node);
8917 add_type_attribute (parm_die, TREE_TYPE (node),
8918 TREE_READONLY (node),
8919 TREE_THIS_VOLATILE (node),
8921 if (DECL_ARTIFICIAL (node))
8922 add_AT_flag (parm_die, DW_AT_artificial, 1);
8925 equate_decl_number_to_die (node, parm_die);
8926 if (! DECL_ABSTRACT (node))
8927 add_location_or_const_value_attribute (parm_die, node);
8932 /* We were called with some kind of a ..._TYPE node. */
8933 add_type_attribute (parm_die, node, 0, 0, context_die);
8943 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
8944 at the end of an (ANSI prototyped) formal parameters list. */
8947 gen_unspecified_parameters_die (decl_or_type, context_die)
8948 register tree decl_or_type ATTRIBUTE_UNUSED;
8949 register dw_die_ref context_die;
8951 new_die (DW_TAG_unspecified_parameters, context_die);
8954 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
8955 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
8956 parameters as specified in some function type specification (except for
8957 those which appear as part of a function *definition*). */
8960 gen_formal_types_die (function_or_method_type, context_die)
8961 register tree function_or_method_type;
8962 register dw_die_ref context_die;
8965 register tree formal_type = NULL;
8966 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
8969 /* In the case where we are generating a formal types list for a C++
8970 non-static member function type, skip over the first thing on the
8971 TYPE_ARG_TYPES list because it only represents the type of the hidden
8972 `this pointer'. The debugger should be able to figure out (without
8973 being explicitly told) that this non-static member function type takes a
8974 `this pointer' and should be able to figure what the type of that hidden
8975 parameter is from the DW_AT_member attribute of the parent
8976 DW_TAG_subroutine_type DIE. */
8977 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
8978 first_parm_type = TREE_CHAIN (first_parm_type);
8981 /* Make our first pass over the list of formal parameter types and output a
8982 DW_TAG_formal_parameter DIE for each one. */
8983 for (link = first_parm_type; link; link = TREE_CHAIN (link))
8985 register dw_die_ref parm_die;
8987 formal_type = TREE_VALUE (link);
8988 if (formal_type == void_type_node)
8991 /* Output a (nameless) DIE to represent the formal parameter itself. */
8992 parm_die = gen_formal_parameter_die (formal_type, context_die);
8993 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8994 && link == first_parm_type)
8995 add_AT_flag (parm_die, DW_AT_artificial, 1);
8998 /* If this function type has an ellipsis, add a
8999 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9000 if (formal_type != void_type_node)
9001 gen_unspecified_parameters_die (function_or_method_type, context_die);
9003 /* Make our second (and final) pass over the list of formal parameter types
9004 and output DIEs to represent those types (as necessary). */
9005 for (link = TYPE_ARG_TYPES (function_or_method_type);
9007 link = TREE_CHAIN (link))
9009 formal_type = TREE_VALUE (link);
9010 if (formal_type == void_type_node)
9013 gen_type_die (formal_type, context_die);
9017 /* We want to generate the DIE for TYPE so that we can generate the
9018 die for MEMBER, which has been defined; we will need to refer back
9019 to the member declaration nested within TYPE. If we're trying to
9020 generate minimal debug info for TYPE, processing TYPE won't do the
9021 trick; we need to attach the member declaration by hand. */
9024 gen_type_die_for_member (type, member, context_die)
9026 dw_die_ref context_die;
9028 gen_type_die (type, context_die);
9030 /* If we're trying to avoid duplicate debug info, we may not have
9031 emitted the member decl for this function. Emit it now. */
9032 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9033 && ! lookup_decl_die (member))
9035 if (decl_ultimate_origin (member))
9038 push_decl_scope (type);
9039 if (TREE_CODE (member) == FUNCTION_DECL)
9040 gen_subprogram_die (member, lookup_type_die (type));
9042 gen_variable_die (member, lookup_type_die (type));
9047 /* Generate the DWARF2 info for the "abstract" instance
9048 of a function which we may later generate inlined and/or
9049 out-of-line instances of. */
9052 gen_abstract_function (decl)
9055 register dw_die_ref old_die = lookup_decl_die (decl);
9058 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9059 /* We've already generated the abstract instance. */
9062 save_fn = current_function_decl;
9063 current_function_decl = decl;
9065 set_decl_abstract_flags (decl, 1);
9066 dwarf2out_decl (decl);
9067 set_decl_abstract_flags (decl, 0);
9069 current_function_decl = save_fn;
9072 /* Generate a DIE to represent a declared function (either file-scope or
9076 gen_subprogram_die (decl, context_die)
9078 register dw_die_ref context_die;
9080 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9081 register tree origin = decl_ultimate_origin (decl);
9082 register dw_die_ref subr_die;
9083 register rtx fp_reg;
9084 register tree fn_arg_types;
9085 register tree outer_scope;
9086 register dw_die_ref old_die = lookup_decl_die (decl);
9087 register int declaration = (current_function_decl != decl
9088 || class_scope_p (context_die));
9090 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9091 be true, if we started to generate the abstract instance of an inline,
9092 decided to output its containing class, and proceeded to emit the
9093 declaration of the inline from the member list for the class. In that
9094 case, `declaration' takes priority; we'll get back to the abstract
9095 instance when we're done with the class. */
9097 /* The class-scope declaration DIE must be the primary DIE. */
9098 if (origin && declaration && class_scope_p (context_die))
9107 if (declaration && ! local_scope_p (context_die))
9110 /* Fixup die_parent for the abstract instance of a nested
9112 if (old_die && old_die->die_parent == NULL)
9113 add_child_die (context_die, old_die);
9115 subr_die = new_die (DW_TAG_subprogram, context_die);
9116 add_abstract_origin_attribute (subr_die, origin);
9118 else if (old_die && DECL_ABSTRACT (decl)
9119 && get_AT_unsigned (old_die, DW_AT_inline))
9121 /* This must be a redefinition of an extern inline function.
9122 We can just reuse the old die here. */
9125 /* Clear out the inlined attribute and parm types. */
9126 remove_AT (subr_die, DW_AT_inline);
9127 remove_children (subr_die);
9131 register unsigned file_index
9132 = lookup_filename (DECL_SOURCE_FILE (decl));
9134 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
9136 /* ??? This can happen if there is a bug in the program, for
9137 instance, if it has duplicate function definitions. Ideally,
9138 we should detect this case and ignore it. For now, if we have
9139 already reported an error, any error at all, then assume that
9140 we got here because of a input error, not a dwarf2 bug. */
9146 /* If the definition comes from the same place as the declaration,
9147 maybe use the old DIE. We always want the DIE for this function
9148 that has the *_pc attributes to be under comp_unit_die so the
9149 debugger can find it. For inlines, that is the concrete instance,
9150 so we can use the old DIE here. For non-inline methods, we want a
9151 specification DIE at toplevel, so we need a new DIE. For local
9152 class methods, this doesn't apply; we just use the old DIE. */
9153 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
9154 || context_die == NULL)
9155 && (DECL_ARTIFICIAL (decl)
9156 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9157 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9158 == (unsigned) DECL_SOURCE_LINE (decl)))))
9162 /* Clear out the declaration attribute and the parm types. */
9163 remove_AT (subr_die, DW_AT_declaration);
9164 remove_children (subr_die);
9168 subr_die = new_die (DW_TAG_subprogram, context_die);
9169 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9170 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9171 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9172 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9173 != (unsigned) DECL_SOURCE_LINE (decl))
9175 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9180 subr_die = new_die (DW_TAG_subprogram, context_die);
9182 if (TREE_PUBLIC (decl))
9183 add_AT_flag (subr_die, DW_AT_external, 1);
9185 add_name_and_src_coords_attributes (subr_die, decl);
9186 if (debug_info_level > DINFO_LEVEL_TERSE)
9188 register tree type = TREE_TYPE (decl);
9190 add_prototyped_attribute (subr_die, type);
9191 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9194 add_pure_or_virtual_attribute (subr_die, decl);
9195 if (DECL_ARTIFICIAL (decl))
9196 add_AT_flag (subr_die, DW_AT_artificial, 1);
9197 if (TREE_PROTECTED (decl))
9198 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9199 else if (TREE_PRIVATE (decl))
9200 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9206 add_AT_flag (subr_die, DW_AT_declaration, 1);
9208 /* The first time we see a member function, it is in the context of
9209 the class to which it belongs. We make sure of this by emitting
9210 the class first. The next time is the definition, which is
9211 handled above. The two may come from the same source text. */
9212 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9213 equate_decl_number_to_die (decl, subr_die);
9215 else if (DECL_ABSTRACT (decl))
9217 if (DECL_INLINE (decl) && !flag_no_inline)
9219 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9220 inline functions, but not for extern inline functions.
9221 We can't get this completely correct because information
9222 about whether the function was declared inline is not
9224 if (DECL_DEFER_OUTPUT (decl))
9225 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9227 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9230 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9232 equate_decl_number_to_die (decl, subr_die);
9234 else if (!DECL_EXTERNAL (decl))
9236 if (origin == NULL_TREE)
9237 equate_decl_number_to_die (decl, subr_die);
9239 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9240 current_funcdef_number);
9241 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9242 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9243 current_funcdef_number);
9244 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9246 add_pubname (decl, subr_die);
9247 add_arange (decl, subr_die);
9249 #ifdef MIPS_DEBUGGING_INFO
9250 /* Add a reference to the FDE for this routine. */
9251 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9254 /* Define the "frame base" location for this routine. We use the
9255 frame pointer or stack pointer registers, since the RTL for local
9256 variables is relative to one of them. */
9258 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9259 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9262 /* ??? This fails for nested inline functions, because context_display
9263 is not part of the state saved/restored for inline functions. */
9264 if (current_function_needs_context)
9265 add_AT_location_description (subr_die, DW_AT_static_link,
9266 lookup_static_chain (decl));
9270 /* Now output descriptions of the arguments for this function. This gets
9271 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9272 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9273 `...' at the end of the formal parameter list. In order to find out if
9274 there was a trailing ellipsis or not, we must instead look at the type
9275 associated with the FUNCTION_DECL. This will be a node of type
9276 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9277 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9278 an ellipsis at the end. */
9280 /* In the case where we are describing a mere function declaration, all we
9281 need to do here (and all we *can* do here) is to describe the *types* of
9282 its formal parameters. */
9283 if (debug_info_level <= DINFO_LEVEL_TERSE)
9285 else if (declaration)
9286 gen_formal_types_die (TREE_TYPE (decl), subr_die);
9289 /* Generate DIEs to represent all known formal parameters */
9290 register tree arg_decls = DECL_ARGUMENTS (decl);
9293 /* When generating DIEs, generate the unspecified_parameters DIE
9294 instead if we come across the arg "__builtin_va_alist" */
9295 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9296 if (TREE_CODE (parm) == PARM_DECL)
9298 if (DECL_NAME (parm)
9299 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9300 "__builtin_va_alist"))
9301 gen_unspecified_parameters_die (parm, subr_die);
9303 gen_decl_die (parm, subr_die);
9306 /* Decide whether we need a unspecified_parameters DIE at the end.
9307 There are 2 more cases to do this for: 1) the ansi ... declaration -
9308 this is detectable when the end of the arg list is not a
9309 void_type_node 2) an unprototyped function declaration (not a
9310 definition). This just means that we have no info about the
9311 parameters at all. */
9312 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9313 if (fn_arg_types != NULL)
9315 /* this is the prototyped case, check for ... */
9316 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9317 gen_unspecified_parameters_die (decl, subr_die);
9319 else if (DECL_INITIAL (decl) == NULL_TREE)
9320 gen_unspecified_parameters_die (decl, subr_die);
9323 /* Output Dwarf info for all of the stuff within the body of the function
9324 (if it has one - it may be just a declaration). */
9325 outer_scope = DECL_INITIAL (decl);
9327 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9328 node created to represent a function. This outermost BLOCK actually
9329 represents the outermost binding contour for the function, i.e. the
9330 contour in which the function's formal parameters and labels get
9331 declared. Curiously, it appears that the front end doesn't actually
9332 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9333 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9334 list for the function instead.) The BLOCK_VARS list for the
9335 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9336 the function however, and we output DWARF info for those in
9337 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9338 node representing the function's outermost pair of curly braces, and
9339 any blocks used for the base and member initializers of a C++
9340 constructor function. */
9341 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
9343 current_function_has_inlines = 0;
9344 decls_for_scope (outer_scope, subr_die, 0);
9346 #if 0 && defined (MIPS_DEBUGGING_INFO)
9347 if (current_function_has_inlines)
9349 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
9350 if (! comp_unit_has_inlines)
9352 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
9353 comp_unit_has_inlines = 1;
9360 /* Generate a DIE to represent a declared data object. */
9363 gen_variable_die (decl, context_die)
9365 register dw_die_ref context_die;
9367 register tree origin = decl_ultimate_origin (decl);
9368 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
9370 dw_die_ref old_die = lookup_decl_die (decl);
9371 int declaration = (DECL_EXTERNAL (decl)
9372 || class_scope_p (context_die));
9375 add_abstract_origin_attribute (var_die, origin);
9376 /* Loop unrolling can create multiple blocks that refer to the same
9377 static variable, so we must test for the DW_AT_declaration flag. */
9378 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
9379 copy decls and set the DECL_ABSTRACT flag on them instead of
9381 else if (old_die && TREE_STATIC (decl)
9382 && get_AT_flag (old_die, DW_AT_declaration) == 1)
9384 /* This is a definition of a C++ class level static. */
9385 add_AT_die_ref (var_die, DW_AT_specification, old_die);
9386 if (DECL_NAME (decl))
9388 register unsigned file_index
9389 = lookup_filename (DECL_SOURCE_FILE (decl));
9391 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9392 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
9394 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9395 != (unsigned) DECL_SOURCE_LINE (decl))
9397 add_AT_unsigned (var_die, DW_AT_decl_line,
9398 DECL_SOURCE_LINE (decl));
9403 add_name_and_src_coords_attributes (var_die, decl);
9404 add_type_attribute (var_die, TREE_TYPE (decl),
9405 TREE_READONLY (decl),
9406 TREE_THIS_VOLATILE (decl), context_die);
9408 if (TREE_PUBLIC (decl))
9409 add_AT_flag (var_die, DW_AT_external, 1);
9411 if (DECL_ARTIFICIAL (decl))
9412 add_AT_flag (var_die, DW_AT_artificial, 1);
9414 if (TREE_PROTECTED (decl))
9415 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
9417 else if (TREE_PRIVATE (decl))
9418 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
9422 add_AT_flag (var_die, DW_AT_declaration, 1);
9424 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
9425 equate_decl_number_to_die (decl, var_die);
9427 if (! declaration && ! DECL_ABSTRACT (decl))
9429 add_location_or_const_value_attribute (var_die, decl);
9430 add_pubname (decl, var_die);
9433 tree_add_const_value_attribute (var_die, decl);
9436 /* Generate a DIE to represent a label identifier. */
9439 gen_label_die (decl, context_die)
9441 register dw_die_ref context_die;
9443 register tree origin = decl_ultimate_origin (decl);
9444 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
9446 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9447 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
9450 add_abstract_origin_attribute (lbl_die, origin);
9452 add_name_and_src_coords_attributes (lbl_die, decl);
9454 if (DECL_ABSTRACT (decl))
9455 equate_decl_number_to_die (decl, lbl_die);
9458 insn = DECL_RTL (decl);
9460 /* Deleted labels are programmer specified labels which have been
9461 eliminated because of various optimisations. We still emit them
9462 here so that it is possible to put breakpoints on them. */
9463 if (GET_CODE (insn) == CODE_LABEL
9464 || ((GET_CODE (insn) == NOTE
9465 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
9467 /* When optimization is enabled (via -O) some parts of the compiler
9468 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
9469 represent source-level labels which were explicitly declared by
9470 the user. This really shouldn't be happening though, so catch
9471 it if it ever does happen. */
9472 if (INSN_DELETED_P (insn))
9475 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
9476 ASM_GENERATE_INTERNAL_LABEL (label, label2,
9477 (unsigned) INSN_UID (insn));
9478 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
9483 /* Generate a DIE for a lexical block. */
9486 gen_lexical_block_die (stmt, context_die, depth)
9488 register dw_die_ref context_die;
9491 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
9492 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9494 if (! BLOCK_ABSTRACT (stmt))
9496 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9497 BLOCK_NUMBER (stmt));
9498 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
9499 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9500 BLOCK_NUMBER (stmt));
9501 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
9504 decls_for_scope (stmt, stmt_die, depth);
9507 /* Generate a DIE for an inlined subprogram. */
9510 gen_inlined_subroutine_die (stmt, context_die, depth)
9512 register dw_die_ref context_die;
9515 if (! BLOCK_ABSTRACT (stmt))
9517 register dw_die_ref subr_die
9518 = new_die (DW_TAG_inlined_subroutine, context_die);
9519 register tree decl = block_ultimate_origin (stmt);
9520 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9522 /* Emit info for the abstract instance first, if we haven't yet. */
9523 gen_abstract_function (decl);
9525 add_abstract_origin_attribute (subr_die, decl);
9526 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9527 BLOCK_NUMBER (stmt));
9528 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
9529 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9530 BLOCK_NUMBER (stmt));
9531 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
9532 decls_for_scope (stmt, subr_die, depth);
9533 current_function_has_inlines = 1;
9537 /* Generate a DIE for a field in a record, or structure. */
9540 gen_field_die (decl, context_die)
9542 register dw_die_ref context_die;
9544 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
9546 add_name_and_src_coords_attributes (decl_die, decl);
9547 add_type_attribute (decl_die, member_declared_type (decl),
9548 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
9551 /* If this is a bit field... */
9552 if (DECL_BIT_FIELD_TYPE (decl))
9554 add_byte_size_attribute (decl_die, decl);
9555 add_bit_size_attribute (decl_die, decl);
9556 add_bit_offset_attribute (decl_die, decl);
9559 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
9560 add_data_member_location_attribute (decl_die, decl);
9562 if (DECL_ARTIFICIAL (decl))
9563 add_AT_flag (decl_die, DW_AT_artificial, 1);
9565 if (TREE_PROTECTED (decl))
9566 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
9568 else if (TREE_PRIVATE (decl))
9569 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
9573 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9574 Use modified_type_die instead.
9575 We keep this code here just in case these types of DIEs may be needed to
9576 represent certain things in other languages (e.g. Pascal) someday. */
9578 gen_pointer_type_die (type, context_die)
9580 register dw_die_ref context_die;
9582 register dw_die_ref ptr_die
9583 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
9585 equate_type_number_to_die (type, ptr_die);
9586 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9587 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9590 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9591 Use modified_type_die instead.
9592 We keep this code here just in case these types of DIEs may be needed to
9593 represent certain things in other languages (e.g. Pascal) someday. */
9595 gen_reference_type_die (type, context_die)
9597 register dw_die_ref context_die;
9599 register dw_die_ref ref_die
9600 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
9602 equate_type_number_to_die (type, ref_die);
9603 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
9604 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9608 /* Generate a DIE for a pointer to a member type. */
9610 gen_ptr_to_mbr_type_die (type, context_die)
9612 register dw_die_ref context_die;
9614 register dw_die_ref ptr_die
9615 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
9617 equate_type_number_to_die (type, ptr_die);
9618 add_AT_die_ref (ptr_die, DW_AT_containing_type,
9619 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
9620 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9623 /* Generate the DIE for the compilation unit. */
9626 gen_compile_unit_die (filename)
9627 register const char *filename;
9629 register dw_die_ref die;
9631 const char *wd = getpwd ();
9634 die = new_die (DW_TAG_compile_unit, NULL);
9635 add_name_attribute (die, filename);
9637 if (wd != NULL && filename[0] != DIR_SEPARATOR)
9638 add_AT_string (die, DW_AT_comp_dir, wd);
9640 sprintf (producer, "%s %s", language_string, version_string);
9642 #ifdef MIPS_DEBUGGING_INFO
9643 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
9644 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
9645 not appear in the producer string, the debugger reaches the conclusion
9646 that the object file is stripped and has no debugging information.
9647 To get the MIPS/SGI debugger to believe that there is debugging
9648 information in the object file, we add a -g to the producer string. */
9649 if (debug_info_level > DINFO_LEVEL_TERSE)
9650 strcat (producer, " -g");
9653 add_AT_string (die, DW_AT_producer, producer);
9655 if (strcmp (language_string, "GNU C++") == 0)
9656 language = DW_LANG_C_plus_plus;
9657 else if (strcmp (language_string, "GNU Ada") == 0)
9658 language = DW_LANG_Ada83;
9659 else if (strcmp (language_string, "GNU F77") == 0)
9660 language = DW_LANG_Fortran77;
9661 else if (strcmp (language_string, "GNU Pascal") == 0)
9662 language = DW_LANG_Pascal83;
9663 else if (strcmp (language_string, "GNU Java") == 0)
9664 language = DW_LANG_Java;
9665 else if (flag_traditional)
9666 language = DW_LANG_C;
9668 language = DW_LANG_C89;
9670 add_AT_unsigned (die, DW_AT_language, language);
9675 /* Generate a DIE for a string type. */
9678 gen_string_type_die (type, context_die)
9680 register dw_die_ref context_die;
9682 register dw_die_ref type_die
9683 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
9685 equate_type_number_to_die (type, type_die);
9687 /* Fudge the string length attribute for now. */
9689 /* TODO: add string length info.
9690 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
9691 bound_representation (upper_bound, 0, 'u'); */
9694 /* Generate the DIE for a base class. */
9697 gen_inheritance_die (binfo, context_die)
9698 register tree binfo;
9699 register dw_die_ref context_die;
9701 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
9703 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
9704 add_data_member_location_attribute (die, binfo);
9706 if (TREE_VIA_VIRTUAL (binfo))
9707 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9708 if (TREE_VIA_PUBLIC (binfo))
9709 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
9710 else if (TREE_VIA_PROTECTED (binfo))
9711 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
9714 /* Generate a DIE for a class member. */
9717 gen_member_die (type, context_die)
9719 register dw_die_ref context_die;
9721 register tree member;
9724 /* If this is not an incomplete type, output descriptions of each of its
9725 members. Note that as we output the DIEs necessary to represent the
9726 members of this record or union type, we will also be trying to output
9727 DIEs to represent the *types* of those members. However the `type'
9728 function (above) will specifically avoid generating type DIEs for member
9729 types *within* the list of member DIEs for this (containing) type execpt
9730 for those types (of members) which are explicitly marked as also being
9731 members of this (containing) type themselves. The g++ front- end can
9732 force any given type to be treated as a member of some other
9733 (containing) type by setting the TYPE_CONTEXT of the given (member) type
9734 to point to the TREE node representing the appropriate (containing)
9737 /* First output info about the base classes. */
9738 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
9740 register tree bases = TYPE_BINFO_BASETYPES (type);
9741 register int n_bases = TREE_VEC_LENGTH (bases);
9744 for (i = 0; i < n_bases; i++)
9745 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
9748 /* Now output info about the data members and type members. */
9749 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
9751 /* If we thought we were generating minimal debug info for TYPE
9752 and then changed our minds, some of the member declarations
9753 may have already been defined. Don't define them again, but
9754 do put them in the right order. */
9756 child = lookup_decl_die (member);
9758 splice_child_die (context_die, child);
9760 gen_decl_die (member, context_die);
9763 /* Now output info about the function members (if any). */
9764 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
9766 child = lookup_decl_die (member);
9768 splice_child_die (context_die, child);
9770 gen_decl_die (member, context_die);
9774 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
9775 is set, we pretend that the type was never defined, so we only get the
9776 member DIEs needed by later specification DIEs. */
9779 gen_struct_or_union_type_die (type, context_die)
9781 register dw_die_ref context_die;
9783 register dw_die_ref type_die = lookup_type_die (type);
9784 register dw_die_ref scope_die = 0;
9785 register int nested = 0;
9786 int complete = (TYPE_SIZE (type)
9787 && (! TYPE_STUB_DECL (type)
9788 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
9790 if (type_die && ! complete)
9793 if (TYPE_CONTEXT (type) != NULL_TREE
9794 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
9797 scope_die = scope_die_for (type, context_die);
9799 if (! type_die || (nested && scope_die == comp_unit_die))
9800 /* First occurrence of type or toplevel definition of nested class. */
9802 register dw_die_ref old_die = type_die;
9804 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
9805 ? DW_TAG_structure_type : DW_TAG_union_type,
9807 equate_type_number_to_die (type, type_die);
9809 add_AT_die_ref (type_die, DW_AT_specification, old_die);
9811 add_name_attribute (type_die, type_tag (type));
9814 remove_AT (type_die, DW_AT_declaration);
9816 /* If this type has been completed, then give it a byte_size attribute and
9817 then give a list of members. */
9820 /* Prevent infinite recursion in cases where the type of some member of
9821 this type is expressed in terms of this type itself. */
9822 TREE_ASM_WRITTEN (type) = 1;
9823 add_byte_size_attribute (type_die, type);
9824 if (TYPE_STUB_DECL (type) != NULL_TREE)
9825 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9827 /* If the first reference to this type was as the return type of an
9828 inline function, then it may not have a parent. Fix this now. */
9829 if (type_die->die_parent == NULL)
9830 add_child_die (scope_die, type_die);
9832 push_decl_scope (type);
9833 gen_member_die (type, type_die);
9836 /* GNU extension: Record what type our vtable lives in. */
9837 if (TYPE_VFIELD (type))
9839 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
9841 gen_type_die (vtype, context_die);
9842 add_AT_die_ref (type_die, DW_AT_containing_type,
9843 lookup_type_die (vtype));
9848 add_AT_flag (type_die, DW_AT_declaration, 1);
9850 /* We don't need to do this for function-local types. */
9851 if (! decl_function_context (TYPE_STUB_DECL (type)))
9852 add_incomplete_type (type);
9856 /* Generate a DIE for a subroutine _type_. */
9859 gen_subroutine_type_die (type, context_die)
9861 register dw_die_ref context_die;
9863 register tree return_type = TREE_TYPE (type);
9864 register dw_die_ref subr_die
9865 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
9867 equate_type_number_to_die (type, subr_die);
9868 add_prototyped_attribute (subr_die, type);
9869 add_type_attribute (subr_die, return_type, 0, 0, context_die);
9870 gen_formal_types_die (type, subr_die);
9873 /* Generate a DIE for a type definition */
9876 gen_typedef_die (decl, context_die)
9878 register dw_die_ref context_die;
9880 register dw_die_ref type_die;
9881 register tree origin;
9883 if (TREE_ASM_WRITTEN (decl))
9885 TREE_ASM_WRITTEN (decl) = 1;
9887 type_die = new_die (DW_TAG_typedef, context_die);
9888 origin = decl_ultimate_origin (decl);
9890 add_abstract_origin_attribute (type_die, origin);
9894 add_name_and_src_coords_attributes (type_die, decl);
9895 if (DECL_ORIGINAL_TYPE (decl))
9897 type = DECL_ORIGINAL_TYPE (decl);
9899 if (type == TREE_TYPE (decl))
9902 equate_type_number_to_die (TREE_TYPE (decl), type_die);
9905 type = TREE_TYPE (decl);
9906 add_type_attribute (type_die, type, TREE_READONLY (decl),
9907 TREE_THIS_VOLATILE (decl), context_die);
9910 if (DECL_ABSTRACT (decl))
9911 equate_decl_number_to_die (decl, type_die);
9914 /* Generate a type description DIE. */
9917 gen_type_die (type, context_die)
9919 register dw_die_ref context_die;
9923 if (type == NULL_TREE || type == error_mark_node)
9926 /* We are going to output a DIE to represent the unqualified version of
9927 this type (i.e. without any const or volatile qualifiers) so get the
9928 main variant (i.e. the unqualified version) of this type now. */
9929 type = type_main_variant (type);
9931 if (TREE_ASM_WRITTEN (type))
9934 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9935 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
9937 TREE_ASM_WRITTEN (type) = 1;
9938 gen_decl_die (TYPE_NAME (type), context_die);
9942 switch (TREE_CODE (type))
9948 case REFERENCE_TYPE:
9949 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
9950 ensures that the gen_type_die recursion will terminate even if the
9951 type is recursive. Recursive types are possible in Ada. */
9952 /* ??? We could perhaps do this for all types before the switch
9954 TREE_ASM_WRITTEN (type) = 1;
9956 /* For these types, all that is required is that we output a DIE (or a
9957 set of DIEs) to represent the "basis" type. */
9958 gen_type_die (TREE_TYPE (type), context_die);
9962 /* This code is used for C++ pointer-to-data-member types.
9963 Output a description of the relevant class type. */
9964 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
9966 /* Output a description of the type of the object pointed to. */
9967 gen_type_die (TREE_TYPE (type), context_die);
9969 /* Now output a DIE to represent this pointer-to-data-member type
9971 gen_ptr_to_mbr_type_die (type, context_die);
9975 gen_type_die (TYPE_DOMAIN (type), context_die);
9976 gen_set_type_die (type, context_die);
9980 gen_type_die (TREE_TYPE (type), context_die);
9981 abort (); /* No way to represent these in Dwarf yet! */
9985 /* Force out return type (in case it wasn't forced out already). */
9986 gen_type_die (TREE_TYPE (type), context_die);
9987 gen_subroutine_type_die (type, context_die);
9991 /* Force out return type (in case it wasn't forced out already). */
9992 gen_type_die (TREE_TYPE (type), context_die);
9993 gen_subroutine_type_die (type, context_die);
9997 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
9999 gen_type_die (TREE_TYPE (type), context_die);
10000 gen_string_type_die (type, context_die);
10003 gen_array_type_die (type, context_die);
10007 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10010 case ENUMERAL_TYPE:
10013 case QUAL_UNION_TYPE:
10014 /* If this is a nested type whose containing class hasn't been
10015 written out yet, writing it out will cover this one, too.
10016 This does not apply to instantiations of member class templates;
10017 they need to be added to the containing class as they are
10018 generated. FIXME: This hurts the idea of combining type decls
10019 from multiple TUs, since we can't predict what set of template
10020 instantiations we'll get. */
10021 if (TYPE_CONTEXT (type)
10022 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10023 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10025 gen_type_die (TYPE_CONTEXT (type), context_die);
10027 if (TREE_ASM_WRITTEN (type))
10030 /* If that failed, attach ourselves to the stub. */
10031 push_decl_scope (TYPE_CONTEXT (type));
10032 context_die = lookup_type_die (TYPE_CONTEXT (type));
10038 if (TREE_CODE (type) == ENUMERAL_TYPE)
10039 gen_enumeration_type_die (type, context_die);
10041 gen_struct_or_union_type_die (type, context_die);
10046 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10047 it up if it is ever completed. gen_*_type_die will set it for us
10048 when appropriate. */
10057 /* No DIEs needed for fundamental types. */
10061 /* No Dwarf representation currently defined. */
10068 TREE_ASM_WRITTEN (type) = 1;
10071 /* Generate a DIE for a tagged type instantiation. */
10074 gen_tagged_type_instantiation_die (type, context_die)
10075 register tree type;
10076 register dw_die_ref context_die;
10078 if (type == NULL_TREE || type == error_mark_node)
10081 /* We are going to output a DIE to represent the unqualified version of
10082 this type (i.e. without any const or volatile qualifiers) so make sure
10083 that we have the main variant (i.e. the unqualified version) of this
10085 if (type != type_main_variant (type))
10088 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10089 an instance of an unresolved type. */
10091 switch (TREE_CODE (type))
10096 case ENUMERAL_TYPE:
10097 gen_inlined_enumeration_type_die (type, context_die);
10101 gen_inlined_structure_type_die (type, context_die);
10105 case QUAL_UNION_TYPE:
10106 gen_inlined_union_type_die (type, context_die);
10114 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10115 things which are local to the given block. */
10118 gen_block_die (stmt, context_die, depth)
10119 register tree stmt;
10120 register dw_die_ref context_die;
10123 register int must_output_die = 0;
10124 register tree origin;
10125 register tree decl;
10126 register enum tree_code origin_code;
10128 /* Ignore blocks never really used to make RTL. */
10130 if (stmt == NULL_TREE || !TREE_USED (stmt)
10131 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10134 /* Determine the "ultimate origin" of this block. This block may be an
10135 inlined instance of an inlined instance of inline function, so we have
10136 to trace all of the way back through the origin chain to find out what
10137 sort of node actually served as the original seed for the creation of
10138 the current block. */
10139 origin = block_ultimate_origin (stmt);
10140 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10142 /* Determine if we need to output any Dwarf DIEs at all to represent this
10144 if (origin_code == FUNCTION_DECL)
10145 /* The outer scopes for inlinings *must* always be represented. We
10146 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10147 must_output_die = 1;
10150 /* In the case where the current block represents an inlining of the
10151 "body block" of an inline function, we must *NOT* output any DIE for
10152 this block because we have already output a DIE to represent the
10153 whole inlined function scope and the "body block" of any function
10154 doesn't really represent a different scope according to ANSI C
10155 rules. So we check here to make sure that this block does not
10156 represent a "body block inlining" before trying to set the
10157 `must_output_die' flag. */
10158 if (! is_body_block (origin ? origin : stmt))
10160 /* Determine if this block directly contains any "significant"
10161 local declarations which we will need to output DIEs for. */
10162 if (debug_info_level > DINFO_LEVEL_TERSE)
10163 /* We are not in terse mode so *any* local declaration counts
10164 as being a "significant" one. */
10165 must_output_die = (BLOCK_VARS (stmt) != NULL);
10167 /* We are in terse mode, so only local (nested) function
10168 definitions count as "significant" local declarations. */
10169 for (decl = BLOCK_VARS (stmt);
10170 decl != NULL; decl = TREE_CHAIN (decl))
10171 if (TREE_CODE (decl) == FUNCTION_DECL
10172 && DECL_INITIAL (decl))
10174 must_output_die = 1;
10180 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10181 DIE for any block which contains no significant local declarations at
10182 all. Rather, in such cases we just call `decls_for_scope' so that any
10183 needed Dwarf info for any sub-blocks will get properly generated. Note
10184 that in terse mode, our definition of what constitutes a "significant"
10185 local declaration gets restricted to include only inlined function
10186 instances and local (nested) function definitions. */
10187 if (must_output_die)
10189 if (origin_code == FUNCTION_DECL)
10190 gen_inlined_subroutine_die (stmt, context_die, depth);
10192 gen_lexical_block_die (stmt, context_die, depth);
10195 decls_for_scope (stmt, context_die, depth);
10198 /* Generate all of the decls declared within a given scope and (recursively)
10199 all of its sub-blocks. */
10202 decls_for_scope (stmt, context_die, depth)
10203 register tree stmt;
10204 register dw_die_ref context_die;
10207 register tree decl;
10208 register tree subblocks;
10210 /* Ignore blocks never really used to make RTL. */
10211 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10214 /* Output the DIEs to represent all of the data objects and typedefs
10215 declared directly within this block but not within any nested
10216 sub-blocks. Also, nested function and tag DIEs have been
10217 generated with a parent of NULL; fix that up now. */
10218 for (decl = BLOCK_VARS (stmt);
10219 decl != NULL; decl = TREE_CHAIN (decl))
10221 register dw_die_ref die;
10223 if (TREE_CODE (decl) == FUNCTION_DECL)
10224 die = lookup_decl_die (decl);
10225 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10226 die = lookup_type_die (TREE_TYPE (decl));
10230 if (die != NULL && die->die_parent == NULL)
10231 add_child_die (context_die, die);
10233 gen_decl_die (decl, context_die);
10236 /* Output the DIEs to represent all sub-blocks (and the items declared
10237 therein) of this block. */
10238 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10240 subblocks = BLOCK_CHAIN (subblocks))
10241 gen_block_die (subblocks, context_die, depth + 1);
10244 /* Is this a typedef we can avoid emitting? */
10247 is_redundant_typedef (decl)
10248 register tree decl;
10250 if (TYPE_DECL_IS_STUB (decl))
10253 if (DECL_ARTIFICIAL (decl)
10254 && DECL_CONTEXT (decl)
10255 && is_tagged_type (DECL_CONTEXT (decl))
10256 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10257 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10258 /* Also ignore the artificial member typedef for the class name. */
10264 /* Generate Dwarf debug information for a decl described by DECL. */
10267 gen_decl_die (decl, context_die)
10268 register tree decl;
10269 register dw_die_ref context_die;
10271 register tree origin;
10273 if (TREE_CODE (decl) == ERROR_MARK)
10276 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10277 if (DECL_IGNORED_P (decl))
10280 switch (TREE_CODE (decl))
10283 /* The individual enumerators of an enum type get output when we output
10284 the Dwarf representation of the relevant enum type itself. */
10287 case FUNCTION_DECL:
10288 /* Don't output any DIEs to represent mere function declarations,
10289 unless they are class members or explicit block externs. */
10290 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10291 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10294 /* If we're emitting an out-of-line copy of an inline function,
10295 emit info for the abstract instance and set up to refer to it. */
10296 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10297 && ! class_scope_p (context_die)
10298 /* gen_abstract_function won't emit a die if this is just a
10299 declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10300 that case, because that works only if we have a die. */
10301 && DECL_INITIAL (decl) != NULL_TREE)
10303 gen_abstract_function (decl);
10304 set_decl_origin_self (decl);
10307 if (debug_info_level > DINFO_LEVEL_TERSE)
10309 /* Before we describe the FUNCTION_DECL itself, make sure that we
10310 have described its return type. */
10311 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10313 /* And its virtual context. */
10314 if (DECL_VINDEX (decl) != NULL_TREE)
10315 gen_type_die (DECL_CONTEXT (decl), context_die);
10317 /* And its containing type. */
10318 origin = decl_class_context (decl);
10319 if (origin != NULL_TREE)
10320 gen_type_die_for_member (origin, decl, context_die);
10323 /* Now output a DIE to represent the function itself. */
10324 gen_subprogram_die (decl, context_die);
10328 /* If we are in terse mode, don't generate any DIEs to represent any
10329 actual typedefs. */
10330 if (debug_info_level <= DINFO_LEVEL_TERSE)
10333 /* In the special case of a TYPE_DECL node representing the
10334 declaration of some type tag, if the given TYPE_DECL is marked as
10335 having been instantiated from some other (original) TYPE_DECL node
10336 (e.g. one which was generated within the original definition of an
10337 inline function) we have to generate a special (abbreviated)
10338 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10340 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10342 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10346 if (is_redundant_typedef (decl))
10347 gen_type_die (TREE_TYPE (decl), context_die);
10349 /* Output a DIE to represent the typedef itself. */
10350 gen_typedef_die (decl, context_die);
10354 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10355 gen_label_die (decl, context_die);
10359 /* If we are in terse mode, don't generate any DIEs to represent any
10360 variable declarations or definitions. */
10361 if (debug_info_level <= DINFO_LEVEL_TERSE)
10364 /* Output any DIEs that are needed to specify the type of this data
10366 gen_type_die (TREE_TYPE (decl), context_die);
10368 /* And its containing type. */
10369 origin = decl_class_context (decl);
10370 if (origin != NULL_TREE)
10371 gen_type_die_for_member (origin, decl, context_die);
10373 /* Now output the DIE to represent the data object itself. This gets
10374 complicated because of the possibility that the VAR_DECL really
10375 represents an inlined instance of a formal parameter for an inline
10377 origin = decl_ultimate_origin (decl);
10378 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
10379 gen_formal_parameter_die (decl, context_die);
10381 gen_variable_die (decl, context_die);
10385 /* Ignore the nameless fields that are used to skip bits, but
10386 handle C++ anonymous unions. */
10387 if (DECL_NAME (decl) != NULL_TREE
10388 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
10390 gen_type_die (member_declared_type (decl), context_die);
10391 gen_field_die (decl, context_die);
10396 gen_type_die (TREE_TYPE (decl), context_die);
10397 gen_formal_parameter_die (decl, context_die);
10400 case NAMESPACE_DECL:
10401 /* Ignore for now. */
10409 /* Add Ada "use" clause information for SGI Workshop debugger. */
10412 dwarf2out_add_library_unit_info (filename, context_list)
10413 const char *filename;
10414 const char *context_list;
10416 unsigned int file_index;
10418 if (filename != NULL)
10420 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
10421 tree context_list_decl
10422 = build_decl (LABEL_DECL, get_identifier (context_list),
10425 TREE_PUBLIC (context_list_decl) = TRUE;
10426 add_name_attribute (unit_die, context_list);
10427 file_index = lookup_filename (filename);
10428 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
10429 add_pubname (context_list_decl, unit_die);
10433 /* Write the debugging output for DECL. */
10436 dwarf2out_decl (decl)
10437 register tree decl;
10439 register dw_die_ref context_die = comp_unit_die;
10441 if (TREE_CODE (decl) == ERROR_MARK)
10444 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10445 if (DECL_IGNORED_P (decl))
10448 switch (TREE_CODE (decl))
10450 case FUNCTION_DECL:
10451 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
10452 builtin function. Explicit programmer-supplied declarations of
10453 these same functions should NOT be ignored however. */
10454 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
10457 /* What we would really like to do here is to filter out all mere
10458 file-scope declarations of file-scope functions which are never
10459 referenced later within this translation unit (and keep all of ones
10460 that *are* referenced later on) but we aren't clairvoyant, so we have
10461 no idea which functions will be referenced in the future (i.e. later
10462 on within the current translation unit). So here we just ignore all
10463 file-scope function declarations which are not also definitions. If
10464 and when the debugger needs to know something about these functions,
10465 it will have to hunt around and find the DWARF information associated
10466 with the definition of the function. Note that we can't just check
10467 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
10468 definitions and which ones represent mere declarations. We have to
10469 check `DECL_INITIAL' instead. That's because the C front-end
10470 supports some weird semantics for "extern inline" function
10471 definitions. These can get inlined within the current translation
10472 unit (an thus, we need to generate DWARF info for their abstract
10473 instances so that the DWARF info for the concrete inlined instances
10474 can have something to refer to) but the compiler never generates any
10475 out-of-lines instances of such things (despite the fact that they
10476 *are* definitions). The important point is that the C front-end
10477 marks these "extern inline" functions as DECL_EXTERNAL, but we need
10478 to generate DWARF for them anyway. Note that the C++ front-end also
10479 plays some similar games for inline function definitions appearing
10480 within include files which also contain
10481 `#pragma interface' pragmas. */
10482 if (DECL_INITIAL (decl) == NULL_TREE)
10485 /* If we're a nested function, initially use a parent of NULL; if we're
10486 a plain function, this will be fixed up in decls_for_scope. If
10487 we're a method, it will be ignored, since we already have a DIE. */
10488 if (decl_function_context (decl))
10489 context_die = NULL;
10494 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
10495 declaration and if the declaration was never even referenced from
10496 within this entire compilation unit. We suppress these DIEs in
10497 order to save space in the .debug section (by eliminating entries
10498 which are probably useless). Note that we must not suppress
10499 block-local extern declarations (whether used or not) because that
10500 would screw-up the debugger's name lookup mechanism and cause it to
10501 miss things which really ought to be in scope at a given point. */
10502 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
10505 /* If we are in terse mode, don't generate any DIEs to represent any
10506 variable declarations or definitions. */
10507 if (debug_info_level <= DINFO_LEVEL_TERSE)
10512 /* Don't emit stubs for types unless they are needed by other DIEs. */
10513 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
10516 /* Don't bother trying to generate any DIEs to represent any of the
10517 normal built-in types for the language we are compiling. */
10518 if (DECL_SOURCE_LINE (decl) == 0)
10520 /* OK, we need to generate one for `bool' so GDB knows what type
10521 comparisons have. */
10522 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
10523 == DW_LANG_C_plus_plus)
10524 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
10525 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
10530 /* If we are in terse mode, don't generate any DIEs for types. */
10531 if (debug_info_level <= DINFO_LEVEL_TERSE)
10534 /* If we're a function-scope tag, initially use a parent of NULL;
10535 this will be fixed up in decls_for_scope. */
10536 if (decl_function_context (decl))
10537 context_die = NULL;
10545 gen_decl_die (decl, context_die);
10548 /* Output a marker (i.e. a label) for the beginning of the generated code for
10549 a lexical block. */
10552 dwarf2out_begin_block (blocknum)
10553 register unsigned blocknum;
10555 function_section (current_function_decl);
10556 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
10559 /* Output a marker (i.e. a label) for the end of the generated code for a
10563 dwarf2out_end_block (blocknum)
10564 register unsigned blocknum;
10566 function_section (current_function_decl);
10567 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
10570 /* Returns nonzero if it is appropriate not to emit any debugging
10571 information for BLOCK, because it doesn't contain any instructions.
10573 Don't allow this for blocks with nested functions or local classes
10574 as we would end up with orphans, and in the presence of scheduling
10575 we may end up calling them anyway. */
10578 dwarf2out_ignore_block (block)
10582 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
10583 if (TREE_CODE (decl) == FUNCTION_DECL
10584 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
10589 /* Output a marker (i.e. a label) at a point in the assembly code which
10590 corresponds to a given source level label. */
10593 dwarf2out_label (insn)
10596 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10598 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10600 function_section (current_function_decl);
10601 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
10602 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
10603 (unsigned) INSN_UID (insn));
10607 /* Lookup a filename (in the list of filenames that we know about here in
10608 dwarf2out.c) and return its "index". The index of each (known) filename is
10609 just a unique number which is associated with only that one filename.
10610 We need such numbers for the sake of generating labels
10611 (in the .debug_sfnames section) and references to those
10612 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
10613 If the filename given as an argument is not found in our current list,
10614 add it to the list and assign it the next available unique index number.
10615 In order to speed up searches, we remember the index of the filename
10616 was looked up last. This handles the majority of all searches. */
10619 lookup_filename (file_name)
10620 const char *file_name;
10622 static unsigned last_file_lookup_index = 0;
10623 register unsigned i;
10625 /* Check to see if the file name that was searched on the previous call
10626 matches this file name. If so, return the index. */
10627 if (last_file_lookup_index != 0)
10628 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
10629 return last_file_lookup_index;
10631 /* Didn't match the previous lookup, search the table */
10632 for (i = 1; i < file_table_in_use; ++i)
10633 if (strcmp (file_name, file_table[i]) == 0)
10635 last_file_lookup_index = i;
10639 /* Prepare to add a new table entry by making sure there is enough space in
10640 the table to do so. If not, expand the current table. */
10641 if (file_table_in_use == file_table_allocated)
10643 file_table_allocated += FILE_TABLE_INCREMENT;
10645 = (char **) xrealloc (file_table,
10646 file_table_allocated * sizeof (char *));
10649 /* Add the new entry to the end of the filename table. */
10650 file_table[file_table_in_use] = xstrdup (file_name);
10651 last_file_lookup_index = file_table_in_use++;
10653 return last_file_lookup_index;
10656 /* Output a label to mark the beginning of a source code line entry
10657 and record information relating to this source line, in
10658 'line_info_table' for later output of the .debug_line section. */
10661 dwarf2out_line (filename, line)
10662 register const char *filename;
10663 register unsigned line;
10665 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10667 function_section (current_function_decl);
10669 if (DWARF2_ASM_LINE_DEBUG_INFO)
10671 static const char *lastfile;
10673 /* Emit the .file and .loc directives understood by GNU as. */
10674 if (lastfile == 0 || strcmp (filename, lastfile))
10677 ggc_add_string_root ((char **) &lastfile, 1);
10679 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
10680 lastfile = filename;
10683 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
10685 /* Indicate that line number info exists. */
10686 ++line_info_table_in_use;
10688 /* Indicate that multiple line number tables exist. */
10689 if (DECL_SECTION_NAME (current_function_decl))
10690 ++separate_line_info_table_in_use;
10692 else if (DECL_SECTION_NAME (current_function_decl))
10694 register dw_separate_line_info_ref line_info;
10695 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
10696 separate_line_info_table_in_use);
10697 if (flag_debug_asm)
10698 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
10699 fputc ('\n', asm_out_file);
10701 /* expand the line info table if necessary */
10702 if (separate_line_info_table_in_use
10703 == separate_line_info_table_allocated)
10705 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10706 separate_line_info_table
10707 = (dw_separate_line_info_ref)
10708 xrealloc (separate_line_info_table,
10709 separate_line_info_table_allocated
10710 * sizeof (dw_separate_line_info_entry));
10713 /* Add the new entry at the end of the line_info_table. */
10715 = &separate_line_info_table[separate_line_info_table_in_use++];
10716 line_info->dw_file_num = lookup_filename (filename);
10717 line_info->dw_line_num = line;
10718 line_info->function = current_funcdef_number;
10722 register dw_line_info_ref line_info;
10724 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
10725 line_info_table_in_use);
10726 if (flag_debug_asm)
10727 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
10728 fputc ('\n', asm_out_file);
10730 /* Expand the line info table if necessary. */
10731 if (line_info_table_in_use == line_info_table_allocated)
10733 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10735 = (dw_line_info_ref)
10736 xrealloc (line_info_table,
10737 (line_info_table_allocated
10738 * sizeof (dw_line_info_entry)));
10741 /* Add the new entry at the end of the line_info_table. */
10742 line_info = &line_info_table[line_info_table_in_use++];
10743 line_info->dw_file_num = lookup_filename (filename);
10744 line_info->dw_line_num = line;
10749 /* Record the beginning of a new source file, for later output
10750 of the .debug_macinfo section. At present, unimplemented. */
10753 dwarf2out_start_source_file (filename)
10754 register const char *filename ATTRIBUTE_UNUSED;
10756 if (flag_eliminate_dwarf2_dups)
10758 /* Record the beginning of the file for break_out_includes. */
10759 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
10760 add_AT_string (bincl_die, DW_AT_name, filename);
10764 /* Record the end of a source file, for later output
10765 of the .debug_macinfo section. At present, unimplemented. */
10768 dwarf2out_end_source_file ()
10770 if (flag_eliminate_dwarf2_dups)
10772 /* Record the end of the file for break_out_includes. */
10773 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
10777 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10778 the tail part of the directive line, i.e. the part which is past the
10779 initial whitespace, #, whitespace, directive-name, whitespace part. */
10782 dwarf2out_define (lineno, buffer)
10783 register unsigned lineno ATTRIBUTE_UNUSED;
10784 register const char *buffer ATTRIBUTE_UNUSED;
10786 static int initialized = 0;
10789 dwarf2out_start_source_file (primary_filename);
10794 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10795 the tail part of the directive line, i.e. the part which is past the
10796 initial whitespace, #, whitespace, directive-name, whitespace part. */
10799 dwarf2out_undef (lineno, buffer)
10800 register unsigned lineno ATTRIBUTE_UNUSED;
10801 register const char *buffer ATTRIBUTE_UNUSED;
10805 /* Set up for Dwarf output at the start of compilation. */
10808 dwarf2out_init (asm_out_file, main_input_filename)
10809 register FILE *asm_out_file;
10810 register const char *main_input_filename;
10812 /* Remember the name of the primary input file. */
10813 primary_filename = main_input_filename;
10815 /* Allocate the initial hunk of the file_table. */
10816 file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
10817 file_table_allocated = FILE_TABLE_INCREMENT;
10819 /* Skip the first entry - file numbers begin at 1. */
10820 file_table_in_use = 1;
10822 /* Allocate the initial hunk of the decl_die_table. */
10824 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
10825 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
10826 decl_die_table_in_use = 0;
10828 /* Allocate the initial hunk of the decl_scope_table. */
10830 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
10831 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
10832 decl_scope_depth = 0;
10834 /* Allocate the initial hunk of the abbrev_die_table. */
10836 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
10837 sizeof (dw_die_ref));
10838 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
10839 /* Zero-th entry is allocated, but unused */
10840 abbrev_die_table_in_use = 1;
10842 /* Allocate the initial hunk of the line_info_table. */
10844 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
10845 sizeof (dw_line_info_entry));
10846 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
10847 /* Zero-th entry is allocated, but unused */
10848 line_info_table_in_use = 1;
10850 /* Generate the initial DIE for the .debug section. Note that the (string)
10851 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
10852 will (typically) be a relative pathname and that this pathname should be
10853 taken as being relative to the directory from which the compiler was
10854 invoked when the given (base) source file was compiled. */
10855 comp_unit_die = gen_compile_unit_die (main_input_filename);
10859 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
10860 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
10863 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
10864 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
10865 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
10866 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
10868 strcpy (text_section_label, stripattributes (TEXT_SECTION));
10869 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
10870 DEBUG_INFO_SECTION_LABEL, 0);
10871 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
10872 DEBUG_LINE_SECTION_LABEL, 0);
10874 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
10875 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
10876 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
10878 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
10879 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
10881 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
10882 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
10883 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
10884 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
10887 /* Output stuff that dwarf requires at the end of every file,
10888 and generate the DWARF-2 debugging info. */
10891 dwarf2out_finish ()
10893 limbo_die_node *node, *next_node;
10896 /* Traverse the limbo die list, and add parent/child links. The only
10897 dies without parents that should be here are concrete instances of
10898 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
10899 For concrete instances, we can get the parent die from the abstract
10901 for (node = limbo_die_list; node; node = next_node)
10903 next_node = node->next;
10906 if (die->die_parent == NULL)
10908 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
10910 add_child_die (origin->die_parent, die);
10911 else if (die == comp_unit_die)
10918 limbo_die_list = NULL;
10920 /* Walk through the list of incomplete types again, trying once more to
10921 emit full debugging info for them. */
10922 retry_incomplete_types ();
10924 /* We need to reverse all the dies before break_out_includes, or
10925 we'll see the end of an include file before the beginning. */
10926 reverse_all_dies (comp_unit_die);
10928 /* Generate separate CUs for each of the include files we've seen.
10929 They will go into limbo_die_list. */
10930 if (flag_eliminate_dwarf2_dups)
10931 break_out_includes (comp_unit_die);
10933 /* Traverse the DIE's and add add sibling attributes to those DIE's
10934 that have children. */
10935 add_sibling_attributes (comp_unit_die);
10936 for (node = limbo_die_list; node; node = node->next)
10937 add_sibling_attributes (node->die);
10939 /* Output a terminator label for the .text section. */
10940 fputc ('\n', asm_out_file);
10941 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
10942 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
10945 /* Output a terminator label for the .data section. */
10946 fputc ('\n', asm_out_file);
10947 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
10948 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
10950 /* Output a terminator label for the .bss section. */
10951 fputc ('\n', asm_out_file);
10952 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
10953 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
10956 /* Output the source line correspondence table. */
10957 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
10959 if (! DWARF2_ASM_LINE_DEBUG_INFO)
10961 fputc ('\n', asm_out_file);
10962 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
10963 output_line_info ();
10966 /* We can only use the low/high_pc attributes if all of the code
10968 if (separate_line_info_table_in_use == 0)
10970 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
10971 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
10974 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
10975 debug_line_section_label);
10978 #if 0 /* unimplemented */
10979 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
10980 add_AT_unsigned (die, DW_AT_macro_info, 0);
10983 /* Output all of the compilation units. We put the main one last so that
10984 the offsets are available to output_pubnames. */
10985 for (node = limbo_die_list; node; node = node->next)
10986 output_comp_unit (node->die);
10987 output_comp_unit (comp_unit_die);
10989 /* Output the abbreviation table. */
10990 fputc ('\n', asm_out_file);
10991 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
10992 output_abbrev_section ();
10994 if (pubname_table_in_use)
10996 /* Output public names table. */
10997 fputc ('\n', asm_out_file);
10998 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
10999 output_pubnames ();
11002 /* We only put functions in the arange table, so don't write it out if
11003 we don't have any. */
11004 if (fde_table_in_use)
11006 /* Output the address range information. */
11007 fputc ('\n', asm_out_file);
11008 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11012 #endif /* DWARF2_DEBUGGING_INFO */