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 /* Make sure we know the sizes of the various types dwarf can describe. These
143 are only defaults. If the sizes are different for your target, you should
144 override these values by defining the appropriate symbols in your tm.h
147 #ifndef CHAR_TYPE_SIZE
148 #define CHAR_TYPE_SIZE BITS_PER_UNIT
151 /* The size of the target's pointer type. */
153 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
156 /* The size of addresses as they appear in the Dwarf 2 data.
157 Some architectures use word addresses to refer to code locations,
158 but Dwarf 2 info always uses byte addresses. On such machines,
159 Dwarf 2 addresses need to be larger than the architecture's
161 #ifndef DWARF2_ADDR_SIZE
162 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
165 /* The size in bytes of a DWARF field indicating an offset or length
166 relative to a debug info section, specified to be 4 bytes in the
167 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
170 #ifndef DWARF_OFFSET_SIZE
171 #define DWARF_OFFSET_SIZE 4
174 #define DWARF_VERSION 2
176 /* Round SIZE up to the nearest BOUNDARY. */
177 #define DWARF_ROUND(SIZE,BOUNDARY) \
178 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
180 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
181 #ifdef STACK_GROWS_DOWNWARD
182 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
184 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
187 /* A pointer to the base of a table that contains frame description
188 information for each routine. */
189 static dw_fde_ref fde_table;
191 /* Number of elements currently allocated for fde_table. */
192 static unsigned fde_table_allocated;
194 /* Number of elements in fde_table currently in use. */
195 static unsigned fde_table_in_use;
197 /* Size (in elements) of increments by which we may expand the
199 #define FDE_TABLE_INCREMENT 256
201 /* A list of call frame insns for the CIE. */
202 static dw_cfi_ref cie_cfi_head;
204 /* The number of the current function definition for which debugging
205 information is being generated. These numbers range from 1 up to the
206 maximum number of function definitions contained within the current
207 compilation unit. These numbers are used to create unique label id's
208 unique to each function definition. */
209 static unsigned current_funcdef_number = 0;
211 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
212 attribute that accelerates the lookup of the FDE associated
213 with the subprogram. This variable holds the table index of the FDE
214 associated with the current function (body) definition. */
215 static unsigned current_funcdef_fde;
217 /* Forward declarations for functions defined in this file. */
219 static char *stripattributes PARAMS ((const char *));
220 static const char *dwarf_cfi_name PARAMS ((unsigned));
221 static dw_cfi_ref new_cfi PARAMS ((void));
222 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
223 static unsigned long size_of_uleb128 PARAMS ((unsigned long));
224 static unsigned long size_of_sleb128 PARAMS ((long));
225 static void output_uleb128 PARAMS ((unsigned long));
226 static void output_sleb128 PARAMS ((long));
227 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
228 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
229 static void lookup_cfa PARAMS ((dw_cfa_location *));
230 static void reg_save PARAMS ((const char *, unsigned,
232 static void initial_return_save PARAMS ((rtx));
233 static long stack_adjust_offset PARAMS ((rtx));
234 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
235 static void output_call_frame_info PARAMS ((int));
236 static void dwarf2out_stack_adjust PARAMS ((rtx));
237 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
239 /* Support for complex CFA locations. */
240 static void output_cfa_loc PARAMS ((dw_cfi_ref));
241 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
242 struct dw_loc_descr_struct *));
243 static struct dw_loc_descr_struct *build_cfa_loc
244 PARAMS ((dw_cfa_location *));
245 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
247 /* Definitions of defaults for assembler-dependent names of various
248 pseudo-ops and section names.
249 Theses may be overridden in the tm.h file (if necessary) for a particular
252 #ifdef OBJECT_FORMAT_ELF
253 #ifndef UNALIGNED_SHORT_ASM_OP
254 #define UNALIGNED_SHORT_ASM_OP ".2byte"
256 #ifndef UNALIGNED_INT_ASM_OP
257 #define UNALIGNED_INT_ASM_OP ".4byte"
259 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
260 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
262 #endif /* OBJECT_FORMAT_ELF */
265 #define ASM_BYTE_OP ".byte"
268 /* Data and reference forms for relocatable data. */
269 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
270 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
272 /* Pseudo-op for defining a new section. */
273 #ifndef SECTION_ASM_OP
274 #define SECTION_ASM_OP ".section"
277 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
278 print the SECTION_ASM_OP and the section name. The default here works for
279 almost all svr4 assemblers, except for the sparc, where the section name
280 must be enclosed in double quotes. (See sparcv4.h). */
281 #ifndef SECTION_FORMAT
282 #ifdef PUSHSECTION_FORMAT
283 #define SECTION_FORMAT PUSHSECTION_FORMAT
285 #define SECTION_FORMAT "\t%s\t%s\n"
289 #ifndef FRAME_SECTION
290 #define FRAME_SECTION ".debug_frame"
293 #ifndef FUNC_BEGIN_LABEL
294 #define FUNC_BEGIN_LABEL "LFB"
296 #ifndef FUNC_END_LABEL
297 #define FUNC_END_LABEL "LFE"
299 #define CIE_AFTER_SIZE_LABEL "LSCIE"
300 #define CIE_END_LABEL "LECIE"
301 #define CIE_LENGTH_LABEL "LLCIE"
302 #define FDE_AFTER_SIZE_LABEL "LSFDE"
303 #define FDE_END_LABEL "LEFDE"
304 #define FDE_LENGTH_LABEL "LLFDE"
305 #define DIE_LABEL_PREFIX "DW"
307 /* Definitions of defaults for various types of primitive assembly language
308 output operations. These may be overridden from within the tm.h file,
309 but typically, that is unnecessary. */
311 #ifndef ASM_OUTPUT_SECTION
312 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
313 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
316 #ifndef ASM_OUTPUT_DWARF_DATA1
317 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
318 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
321 #ifndef ASM_OUTPUT_DWARF_DELTA1
322 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
323 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
324 assemble_name (FILE, LABEL1); \
325 fprintf (FILE, "-"); \
326 assemble_name (FILE, LABEL2); \
330 #ifdef UNALIGNED_INT_ASM_OP
332 #ifndef UNALIGNED_OFFSET_ASM_OP
333 #define UNALIGNED_OFFSET_ASM_OP \
334 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
337 #ifndef UNALIGNED_WORD_ASM_OP
338 #define UNALIGNED_WORD_ASM_OP \
339 ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \
340 : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \
341 : UNALIGNED_INT_ASM_OP)
344 #ifndef ASM_OUTPUT_DWARF_DELTA2
345 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
346 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
347 assemble_name (FILE, LABEL1); \
348 fprintf (FILE, "-"); \
349 assemble_name (FILE, LABEL2); \
353 #ifndef ASM_OUTPUT_DWARF_DELTA4
354 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
355 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
356 assemble_name (FILE, LABEL1); \
357 fprintf (FILE, "-"); \
358 assemble_name (FILE, LABEL2); \
362 #ifndef ASM_OUTPUT_DWARF_DELTA
363 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
364 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
365 assemble_name (FILE, LABEL1); \
366 fprintf (FILE, "-"); \
367 assemble_name (FILE, LABEL2); \
371 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
372 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
373 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
374 assemble_name (FILE, LABEL1); \
375 fprintf (FILE, "-"); \
376 assemble_name (FILE, LABEL2); \
380 #ifndef ASM_OUTPUT_DWARF_ADDR
381 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
382 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
383 assemble_name (FILE, LABEL); \
387 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
388 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
390 fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
391 output_addr_const ((FILE), (RTX)); \
395 #ifndef ASM_OUTPUT_DWARF_OFFSET4
396 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
397 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
398 assemble_name (FILE, LABEL); \
402 #ifndef ASM_OUTPUT_DWARF_OFFSET
403 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
404 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
405 assemble_name (FILE, LABEL); \
409 #ifndef ASM_OUTPUT_DWARF_DATA2
410 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
411 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
414 #ifndef ASM_OUTPUT_DWARF_DATA4
415 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
416 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
419 #ifndef ASM_OUTPUT_DWARF_DATA8
420 #define ASM_OUTPUT_DWARF_DATA8(FILE,VALUE) \
421 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_DOUBLE_INT_ASM_OP, \
422 (unsigned long) (VALUE))
425 #ifndef ASM_OUTPUT_DWARF_DATA
426 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
427 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
428 (unsigned long) (VALUE))
431 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
432 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
433 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
434 (unsigned long) (VALUE))
437 #ifndef ASM_OUTPUT_DWARF_CONST_DOUBLE
438 #define ASM_OUTPUT_DWARF_CONST_DOUBLE(FILE,HIGH_VALUE,LOW_VALUE) \
440 if (WORDS_BIG_ENDIAN) \
442 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
443 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
447 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
448 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
453 #else /* UNALIGNED_INT_ASM_OP */
455 /* We don't have unaligned support, let's hope the normal output works for
456 .debug_frame. But we know it won't work for .debug_info. */
458 #ifdef DWARF2_DEBUGGING_INFO
459 #error DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP.
462 #ifndef ASM_OUTPUT_DWARF_ADDR
463 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
464 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1)
467 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
468 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) ASM_OUTPUT_DWARF_ADDR (FILE,RTX)
471 #ifndef ASM_OUTPUT_DWARF_OFFSET4
472 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
473 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
476 #ifndef ASM_OUTPUT_DWARF_OFFSET
477 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
478 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
481 #ifndef ASM_OUTPUT_DWARF_DELTA2
482 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
483 assemble_integer (gen_rtx_MINUS (HImode, \
484 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
485 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
489 #ifndef ASM_OUTPUT_DWARF_DELTA4
490 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
491 assemble_integer (gen_rtx_MINUS (SImode, \
492 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
493 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
497 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
498 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
499 assemble_integer (gen_rtx_MINUS (Pmode, \
500 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
501 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
505 #ifndef ASM_OUTPUT_DWARF_DELTA
506 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
507 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
510 #ifndef ASM_OUTPUT_DWARF_DATA2
511 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
512 assemble_integer (GEN_INT (VALUE), 2, 1)
515 #ifndef ASM_OUTPUT_DWARF_DATA4
516 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
517 assemble_integer (GEN_INT (VALUE), 4, 1)
520 #endif /* UNALIGNED_INT_ASM_OP */
523 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
524 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
526 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
527 assemble_name (FILE, SY); \
529 assemble_name (FILE, HI); \
531 assemble_name (FILE, LO); \
534 #endif /* SET_ASM_OP */
536 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
537 newline is produced. When flag_debug_asm is asserted, we add commentary
538 at the end of the line, so we must avoid output of a newline here. */
539 #ifndef ASM_OUTPUT_DWARF_STRING
540 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
542 register int slen = strlen(P); \
543 register const char *p = (P); \
545 fprintf (FILE, "\t.ascii \""); \
546 for (i = 0; i < slen; i++) \
548 register int c = p[i]; \
549 if (c == '\"' || c == '\\') \
555 fprintf (FILE, "\\%o", c); \
558 fprintf (FILE, "\\0\""); \
563 /* The DWARF 2 CFA column which tracks the return address. Normally this
564 is the column for PC, or the first column after all of the hard
566 #ifndef DWARF_FRAME_RETURN_COLUMN
568 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
570 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
574 /* The mapping from gcc register number to DWARF 2 CFA column number. By
575 default, we just provide columns for all registers. */
576 #ifndef DWARF_FRAME_REGNUM
577 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
580 /* Hook used by __throw. */
583 expand_builtin_dwarf_fp_regnum ()
585 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
588 /* The offset from the incoming value of %sp to the top of the stack frame
589 for the current function. */
590 #ifndef INCOMING_FRAME_SP_OFFSET
591 #define INCOMING_FRAME_SP_OFFSET 0
594 /* Return a pointer to a copy of the section string name S with all
595 attributes stripped off, and an asterisk prepended (for assemble_name). */
601 char *stripped = xmalloc (strlen (s) + 2);
606 while (*s && *s != ',')
613 /* Generate code to initialize the register size table. */
616 expand_builtin_init_dwarf_reg_sizes (address)
620 enum machine_mode mode = TYPE_MODE (char_type_node);
621 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
622 rtx mem = gen_rtx_MEM (mode, addr);
624 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
626 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
627 int size = GET_MODE_SIZE (reg_raw_mode[i]);
632 emit_move_insn (change_address (mem, mode,
633 plus_constant (addr, offset)),
638 /* Convert a DWARF call frame info. operation to its string name */
641 dwarf_cfi_name (cfi_opc)
642 register unsigned cfi_opc;
646 case DW_CFA_advance_loc:
647 return "DW_CFA_advance_loc";
649 return "DW_CFA_offset";
651 return "DW_CFA_restore";
655 return "DW_CFA_set_loc";
656 case DW_CFA_advance_loc1:
657 return "DW_CFA_advance_loc1";
658 case DW_CFA_advance_loc2:
659 return "DW_CFA_advance_loc2";
660 case DW_CFA_advance_loc4:
661 return "DW_CFA_advance_loc4";
662 case DW_CFA_offset_extended:
663 return "DW_CFA_offset_extended";
664 case DW_CFA_restore_extended:
665 return "DW_CFA_restore_extended";
666 case DW_CFA_undefined:
667 return "DW_CFA_undefined";
668 case DW_CFA_same_value:
669 return "DW_CFA_same_value";
670 case DW_CFA_register:
671 return "DW_CFA_register";
672 case DW_CFA_remember_state:
673 return "DW_CFA_remember_state";
674 case DW_CFA_restore_state:
675 return "DW_CFA_restore_state";
677 return "DW_CFA_def_cfa";
678 case DW_CFA_def_cfa_register:
679 return "DW_CFA_def_cfa_register";
680 case DW_CFA_def_cfa_offset:
681 return "DW_CFA_def_cfa_offset";
682 case DW_CFA_def_cfa_expression:
683 return "DW_CFA_def_cfa_expression";
685 /* SGI/MIPS specific */
686 case DW_CFA_MIPS_advance_loc8:
687 return "DW_CFA_MIPS_advance_loc8";
690 case DW_CFA_GNU_window_save:
691 return "DW_CFA_GNU_window_save";
692 case DW_CFA_GNU_args_size:
693 return "DW_CFA_GNU_args_size";
694 case DW_CFA_GNU_negative_offset_extended:
695 return "DW_CFA_GNU_negative_offset_extended";
698 return "DW_CFA_<unknown>";
702 /* Return a pointer to a newly allocated Call Frame Instruction. */
704 static inline dw_cfi_ref
707 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
709 cfi->dw_cfi_next = NULL;
710 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
711 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
716 /* Add a Call Frame Instruction to list of instructions. */
719 add_cfi (list_head, cfi)
720 register dw_cfi_ref *list_head;
721 register dw_cfi_ref cfi;
723 register dw_cfi_ref *p;
725 /* Find the end of the chain. */
726 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
732 /* Generate a new label for the CFI info to refer to. */
735 dwarf2out_cfi_label ()
737 static char label[20];
738 static unsigned long label_num = 0;
740 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
741 ASM_OUTPUT_LABEL (asm_out_file, label);
746 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
747 or to the CIE if LABEL is NULL. */
750 add_fde_cfi (label, cfi)
751 register const char *label;
752 register dw_cfi_ref cfi;
756 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
759 label = dwarf2out_cfi_label ();
761 if (fde->dw_fde_current_label == NULL
762 || strcmp (label, fde->dw_fde_current_label) != 0)
764 register dw_cfi_ref xcfi;
766 fde->dw_fde_current_label = label = xstrdup (label);
768 /* Set the location counter to the new label. */
770 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
771 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
772 add_cfi (&fde->dw_fde_cfi, xcfi);
775 add_cfi (&fde->dw_fde_cfi, cfi);
779 add_cfi (&cie_cfi_head, cfi);
782 /* Subroutine of lookup_cfa. */
785 lookup_cfa_1 (cfi, loc)
786 register dw_cfi_ref cfi;
787 register dw_cfa_location *loc;
789 switch (cfi->dw_cfi_opc)
791 case DW_CFA_def_cfa_offset:
792 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
794 case DW_CFA_def_cfa_register:
795 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
798 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
799 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
801 case DW_CFA_def_cfa_expression:
802 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
809 /* Find the previous value for the CFA. */
813 register dw_cfa_location *loc;
815 register dw_cfi_ref cfi;
817 loc->reg = (unsigned long) -1;
820 loc->base_offset = 0;
822 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
823 lookup_cfa_1 (cfi, loc);
825 if (fde_table_in_use)
827 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
828 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
829 lookup_cfa_1 (cfi, loc);
833 /* The current rule for calculating the DWARF2 canonical frame address. */
836 /* The register used for saving registers to the stack, and its offset
838 dw_cfa_location cfa_store;
840 /* The running total of the size of arguments pushed onto the stack. */
841 static long args_size;
843 /* The last args_size we actually output. */
844 static long old_args_size;
846 /* Entry point to update the canonical frame address (CFA).
847 LABEL is passed to add_fde_cfi. The value of CFA is now to be
848 calculated from REG+OFFSET. */
851 dwarf2out_def_cfa (label, reg, offset)
852 register const char *label;
861 def_cfa_1 (label, &loc);
864 /* This routine does the actual work. The CFA is now calculated from
865 the dw_cfa_location structure. */
867 def_cfa_1 (label, loc_p)
868 register const char *label;
869 dw_cfa_location *loc_p;
871 register dw_cfi_ref cfi;
872 dw_cfa_location old_cfa, loc;
877 if (cfa_store.reg == loc.reg && loc.indirect == 0)
878 cfa_store.offset = loc.offset;
880 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
881 lookup_cfa (&old_cfa);
883 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
884 loc.indirect == old_cfa.indirect)
886 if (loc.indirect == 0
887 || loc.base_offset == old_cfa.base_offset)
893 if (loc.reg == old_cfa.reg && !loc.indirect)
895 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
896 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
899 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
900 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
903 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
904 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
908 else if (loc.indirect == 0)
910 cfi->dw_cfi_opc = DW_CFA_def_cfa;
911 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
912 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
916 struct dw_loc_descr_struct *loc_list;
917 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
918 loc_list = build_cfa_loc (&loc);
919 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
922 add_fde_cfi (label, cfi);
925 /* Add the CFI for saving a register. REG is the CFA column number.
926 LABEL is passed to add_fde_cfi.
927 If SREG is -1, the register is saved at OFFSET from the CFA;
928 otherwise it is saved in SREG. */
931 reg_save (label, reg, sreg, offset)
932 register const char *label;
933 register unsigned reg;
934 register unsigned sreg;
935 register long offset;
937 register dw_cfi_ref cfi = new_cfi ();
939 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
941 /* The following comparison is correct. -1 is used to indicate that
942 the value isn't a register number. */
943 if (sreg == (unsigned int) -1)
946 /* The register number won't fit in 6 bits, so we have to use
948 cfi->dw_cfi_opc = DW_CFA_offset_extended;
950 cfi->dw_cfi_opc = DW_CFA_offset;
952 offset /= DWARF_CIE_DATA_ALIGNMENT;
955 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
958 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
960 else if (sreg == reg)
961 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
965 cfi->dw_cfi_opc = DW_CFA_register;
966 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
969 add_fde_cfi (label, cfi);
972 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
973 This CFI tells the unwinder that it needs to restore the window registers
974 from the previous frame's window save area.
976 ??? Perhaps we should note in the CIE where windows are saved (instead of
977 assuming 0(cfa)) and what registers are in the window. */
980 dwarf2out_window_save (label)
981 register const char *label;
983 register dw_cfi_ref cfi = new_cfi ();
984 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
985 add_fde_cfi (label, cfi);
988 /* Add a CFI to update the running total of the size of arguments
989 pushed onto the stack. */
992 dwarf2out_args_size (label, size)
996 register dw_cfi_ref cfi;
998 if (size == old_args_size)
1000 old_args_size = size;
1003 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1004 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1005 add_fde_cfi (label, cfi);
1008 /* Entry point for saving a register to the stack. REG is the GCC register
1009 number. LABEL and OFFSET are passed to reg_save. */
1012 dwarf2out_reg_save (label, reg, offset)
1013 register const char *label;
1014 register unsigned reg;
1015 register long offset;
1017 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
1020 /* Entry point for saving the return address in the stack.
1021 LABEL and OFFSET are passed to reg_save. */
1024 dwarf2out_return_save (label, offset)
1025 register const char *label;
1026 register long offset;
1028 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
1031 /* Entry point for saving the return address in a register.
1032 LABEL and SREG are passed to reg_save. */
1035 dwarf2out_return_reg (label, sreg)
1036 register const char *label;
1037 register unsigned sreg;
1039 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
1042 /* Record the initial position of the return address. RTL is
1043 INCOMING_RETURN_ADDR_RTX. */
1046 initial_return_save (rtl)
1049 unsigned int reg = (unsigned int) -1;
1052 switch (GET_CODE (rtl))
1055 /* RA is in a register. */
1056 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1059 /* RA is on the stack. */
1060 rtl = XEXP (rtl, 0);
1061 switch (GET_CODE (rtl))
1064 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1069 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1071 offset = INTVAL (XEXP (rtl, 1));
1074 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1076 offset = -INTVAL (XEXP (rtl, 1));
1083 /* The return address is at some offset from any value we can
1084 actually load. For instance, on the SPARC it is in %i7+8. Just
1085 ignore the offset for now; it doesn't matter for unwinding frames. */
1086 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1088 initial_return_save (XEXP (rtl, 0));
1094 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1097 /* Given a SET, calculate the amount of stack adjustment it
1101 stack_adjust_offset (pattern)
1104 rtx src = SET_SRC (pattern);
1105 rtx dest = SET_DEST (pattern);
1109 if (dest == stack_pointer_rtx)
1111 /* (set (reg sp) (plus (reg sp) (const_int))) */
1112 code = GET_CODE (src);
1113 if (! (code == PLUS || code == MINUS)
1114 || XEXP (src, 0) != stack_pointer_rtx
1115 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1118 offset = INTVAL (XEXP (src, 1));
1120 else if (GET_CODE (dest) == MEM)
1122 /* (set (mem (pre_dec (reg sp))) (foo)) */
1123 src = XEXP (dest, 0);
1124 code = GET_CODE (src);
1126 if (! (code == PRE_DEC || code == PRE_INC)
1127 || XEXP (src, 0) != stack_pointer_rtx)
1130 offset = GET_MODE_SIZE (GET_MODE (dest));
1135 if (code == PLUS || code == PRE_INC)
1141 /* Check INSN to see if it looks like a push or a stack adjustment, and
1142 make a note of it if it does. EH uses this information to find out how
1143 much extra space it needs to pop off the stack. */
1146 dwarf2out_stack_adjust (insn)
1152 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1154 /* Extract the size of the args from the CALL rtx itself. */
1156 insn = PATTERN (insn);
1157 if (GET_CODE (insn) == PARALLEL)
1158 insn = XVECEXP (insn, 0, 0);
1159 if (GET_CODE (insn) == SET)
1160 insn = SET_SRC (insn);
1161 if (GET_CODE (insn) != CALL)
1163 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1167 /* If only calls can throw, and we have a frame pointer,
1168 save up adjustments until we see the CALL_INSN. */
1169 else if (! asynchronous_exceptions
1170 && cfa.reg != STACK_POINTER_REGNUM)
1173 if (GET_CODE (insn) == BARRIER)
1175 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1176 the compiler will have already emitted a stack adjustment, but
1177 doesn't bother for calls to noreturn functions. */
1178 #ifdef STACK_GROWS_DOWNWARD
1179 offset = -args_size;
1184 else if (GET_CODE (PATTERN (insn)) == SET)
1186 offset = stack_adjust_offset (PATTERN (insn));
1188 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1189 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1191 /* There may be stack adjustments inside compound insns. Search
1196 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1198 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1199 if (GET_CODE (pattern) == SET)
1200 offset += stack_adjust_offset (pattern);
1209 if (cfa.reg == STACK_POINTER_REGNUM)
1210 cfa.offset += offset;
1212 #ifndef STACK_GROWS_DOWNWARD
1215 args_size += offset;
1219 label = dwarf2out_cfi_label ();
1220 def_cfa_1 (label, &cfa);
1221 dwarf2out_args_size (label, args_size);
1224 /* A temporary register used in adjusting SP or setting up the store_reg. */
1225 static unsigned cfa_temp_reg;
1227 /* A temporary value used in adjusting SP or setting up the store_reg. */
1228 static long cfa_temp_value;
1230 /* Record call frame debugging information for an expression, which either
1231 sets SP or FP (adjusting how we calculate the frame address) or saves a
1232 register to the stack. */
1235 dwarf2out_frame_debug_expr (expr, label)
1242 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1243 the PARALLEL independently. The first element is always processed if
1244 it is a SET. This is for backward compatability. Other elements
1245 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1246 flag is set in them. */
1248 if (GET_CODE (expr) == PARALLEL
1249 || GET_CODE (expr) == SEQUENCE)
1252 int limit = XVECLEN (expr, 0);
1254 for (par_index = 0; par_index < limit; par_index++)
1256 rtx x = XVECEXP (expr, 0, par_index);
1258 if (GET_CODE (x) == SET &&
1259 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1260 dwarf2out_frame_debug_expr (x, label);
1265 if (GET_CODE (expr) != SET)
1268 src = SET_SRC (expr);
1269 dest = SET_DEST (expr);
1271 switch (GET_CODE (dest))
1274 /* Update the CFA rule wrt SP or FP. Make sure src is
1275 relative to the current CFA register. */
1276 switch (GET_CODE (src))
1278 /* Setting FP from SP. */
1280 if (cfa.reg == (unsigned) REGNO (src))
1286 /* We used to require that dest be either SP or FP, but the
1287 ARM copies SP to a temporary register, and from there to
1288 FP. So we just rely on the backends to only set
1289 RTX_FRAME_RELATED_P on appropriate insns. */
1290 cfa.reg = REGNO (dest);
1295 if (dest == stack_pointer_rtx)
1298 switch (GET_CODE (XEXP (src, 1)))
1301 offset = INTVAL (XEXP (src, 1));
1304 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1306 offset = cfa_temp_value;
1312 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1314 /* Restoring SP from FP in the epilogue. */
1315 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1317 cfa.reg = STACK_POINTER_REGNUM;
1319 else if (XEXP (src, 0) != stack_pointer_rtx)
1322 if (GET_CODE (src) == PLUS)
1324 if (cfa.reg == STACK_POINTER_REGNUM)
1325 cfa.offset += offset;
1326 if (cfa_store.reg == STACK_POINTER_REGNUM)
1327 cfa_store.offset += offset;
1329 else if (dest == hard_frame_pointer_rtx)
1331 /* Either setting the FP from an offset of the SP,
1332 or adjusting the FP */
1333 if (! frame_pointer_needed)
1336 if (GET_CODE (XEXP (src, 0)) == REG
1337 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1338 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1340 offset = INTVAL (XEXP (src, 1));
1341 if (GET_CODE (src) == PLUS)
1343 cfa.offset += offset;
1344 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1351 if (GET_CODE (src) != PLUS
1352 || XEXP (src, 1) != stack_pointer_rtx)
1354 if (GET_CODE (XEXP (src, 0)) != REG
1355 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1357 if (cfa.reg != STACK_POINTER_REGNUM)
1359 cfa_store.reg = REGNO (dest);
1360 cfa_store.offset = cfa.offset - cfa_temp_value;
1365 cfa_temp_reg = REGNO (dest);
1366 cfa_temp_value = INTVAL (src);
1370 if (GET_CODE (XEXP (src, 0)) != REG
1371 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1372 || (unsigned) REGNO (dest) != cfa_temp_reg
1373 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1375 cfa_temp_value |= INTVAL (XEXP (src, 1));
1381 def_cfa_1 (label, &cfa);
1384 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1385 will fill in all of the bits. */
1390 cfa_temp_reg = REGNO (dest);
1391 cfa_temp_value = INTVAL (XEXP (src, 1));
1395 if (GET_CODE (src) != REG)
1398 /* Saving a register to the stack. Make sure dest is relative to the
1400 switch (GET_CODE (XEXP (dest, 0)))
1405 offset = GET_MODE_SIZE (GET_MODE (dest));
1406 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1409 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1410 || cfa_store.reg != STACK_POINTER_REGNUM)
1412 cfa_store.offset += offset;
1413 if (cfa.reg == STACK_POINTER_REGNUM)
1414 cfa.offset = cfa_store.offset;
1416 offset = -cfa_store.offset;
1419 /* With an offset. */
1422 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1423 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1426 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1428 offset -= cfa_store.offset;
1431 /* Without an offset. */
1433 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1435 offset = -cfa_store.offset;
1442 if (REGNO (src) != STACK_POINTER_REGNUM
1443 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1444 && (unsigned) REGNO (src) == cfa.reg)
1446 /* We're storing the current CFA reg into the stack. */
1448 if (cfa.offset == 0)
1450 /* If the source register is exactly the CFA, assume
1451 we're saving SP like any other register; this happens
1454 def_cfa_1 (label, &cfa);
1455 dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset);
1460 /* Otherwise, we'll need to look in the stack to
1461 calculate the CFA. */
1463 rtx x = XEXP (dest, 0);
1464 if (GET_CODE (x) != REG)
1466 if (GET_CODE (x) != REG)
1468 cfa.reg = (unsigned) REGNO (x);
1469 cfa.base_offset = offset;
1471 def_cfa_1 (label, &cfa);
1476 def_cfa_1 (label, &cfa);
1477 dwarf2out_reg_save (label, REGNO (src), offset);
1485 /* Record call frame debugging information for INSN, which either
1486 sets SP or FP (adjusting how we calculate the frame address) or saves a
1487 register to the stack. If INSN is NULL_RTX, initialize our state. */
1490 dwarf2out_frame_debug (insn)
1496 if (insn == NULL_RTX)
1498 /* Set up state for generating call frame debug info. */
1500 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1502 cfa.reg = STACK_POINTER_REGNUM;
1509 if (! RTX_FRAME_RELATED_P (insn))
1511 dwarf2out_stack_adjust (insn);
1515 label = dwarf2out_cfi_label ();
1517 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1519 insn = XEXP (src, 0);
1521 insn = PATTERN (insn);
1523 dwarf2out_frame_debug_expr (insn, label);
1526 /* Return the size of an unsigned LEB128 quantity. */
1528 static inline unsigned long
1529 size_of_uleb128 (value)
1530 register unsigned long value;
1532 register unsigned long size = 0;
1533 register unsigned byte;
1537 byte = (value & 0x7f);
1546 /* Return the size of a signed LEB128 quantity. */
1548 static inline unsigned long
1549 size_of_sleb128 (value)
1550 register long value;
1552 register unsigned long size = 0;
1553 register unsigned byte;
1557 byte = (value & 0x7f);
1561 while (!(((value == 0) && ((byte & 0x40) == 0))
1562 || ((value == -1) && ((byte & 0x40) != 0))));
1567 /* Output an unsigned LEB128 quantity. */
1570 output_uleb128 (value)
1571 register unsigned long value;
1573 unsigned long save_value = value;
1575 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1578 register unsigned byte = (value & 0x7f);
1581 /* More bytes to follow. */
1584 fprintf (asm_out_file, "0x%x", byte);
1586 fprintf (asm_out_file, ",");
1591 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1594 /* Output an signed LEB128 quantity. */
1597 output_sleb128 (value)
1598 register long value;
1601 register unsigned byte;
1602 long save_value = value;
1604 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1607 byte = (value & 0x7f);
1608 /* arithmetic shift */
1610 more = !((((value == 0) && ((byte & 0x40) == 0))
1611 || ((value == -1) && ((byte & 0x40) != 0))));
1615 fprintf (asm_out_file, "0x%x", byte);
1617 fprintf (asm_out_file, ",");
1622 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1625 /* Output a Call Frame Information opcode and its operand(s). */
1628 output_cfi (cfi, fde)
1629 register dw_cfi_ref cfi;
1630 register dw_fde_ref fde;
1632 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1634 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1636 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1638 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1639 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1640 fputc ('\n', asm_out_file);
1643 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1645 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1647 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1649 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1650 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1652 fputc ('\n', asm_out_file);
1653 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1654 fputc ('\n', asm_out_file);
1656 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1658 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1660 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1662 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1663 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1665 fputc ('\n', asm_out_file);
1669 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1671 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1672 dwarf_cfi_name (cfi->dw_cfi_opc));
1674 fputc ('\n', asm_out_file);
1675 switch (cfi->dw_cfi_opc)
1677 case DW_CFA_set_loc:
1678 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1679 fputc ('\n', asm_out_file);
1681 case DW_CFA_advance_loc1:
1682 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1683 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1684 fde->dw_fde_current_label);
1685 fputc ('\n', asm_out_file);
1686 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1688 case DW_CFA_advance_loc2:
1689 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1690 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1691 fde->dw_fde_current_label);
1692 fputc ('\n', asm_out_file);
1693 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1695 case DW_CFA_advance_loc4:
1696 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1697 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1698 fde->dw_fde_current_label);
1699 fputc ('\n', asm_out_file);
1700 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1702 #ifdef MIPS_DEBUGGING_INFO
1703 case DW_CFA_MIPS_advance_loc8:
1704 /* TODO: not currently implemented. */
1708 case DW_CFA_offset_extended:
1709 case DW_CFA_GNU_negative_offset_extended:
1710 case DW_CFA_def_cfa:
1711 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1712 fputc ('\n', asm_out_file);
1713 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1714 fputc ('\n', asm_out_file);
1716 case DW_CFA_restore_extended:
1717 case DW_CFA_undefined:
1718 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1719 fputc ('\n', asm_out_file);
1721 case DW_CFA_same_value:
1722 case DW_CFA_def_cfa_register:
1723 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1724 fputc ('\n', asm_out_file);
1726 case DW_CFA_register:
1727 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1728 fputc ('\n', asm_out_file);
1729 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1730 fputc ('\n', asm_out_file);
1732 case DW_CFA_def_cfa_offset:
1733 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1734 fputc ('\n', asm_out_file);
1736 case DW_CFA_GNU_window_save:
1738 case DW_CFA_GNU_args_size:
1739 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1740 fputc ('\n', asm_out_file);
1742 case DW_CFA_def_cfa_expression:
1743 output_cfa_loc (cfi);
1751 /* Output the call frame information used to used to record information
1752 that relates to calculating the frame pointer, and records the
1753 location of saved registers. */
1756 output_call_frame_info (for_eh)
1759 register unsigned long i;
1760 register dw_fde_ref fde;
1761 register dw_cfi_ref cfi;
1762 char l1[20], l2[20];
1763 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1767 /* Do we want to include a pointer to the exception table? */
1768 int eh_ptr = for_eh && exception_table_p ();
1770 /* If we don't have any functions we'll want to unwind out of, don't
1771 emit any EH unwind information. */
1774 for (i = 0; i < fde_table_in_use; ++i)
1775 if (! fde_table[i].nothrow)
1781 fputc ('\n', asm_out_file);
1783 /* We're going to be generating comments, so turn on app. */
1789 #ifdef EH_FRAME_SECTION
1790 EH_FRAME_SECTION ();
1792 tree label = get_file_function_name ('F');
1794 force_data_section ();
1795 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1796 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1797 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1799 assemble_label ("__FRAME_BEGIN__");
1802 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1804 /* Output the CIE. */
1805 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1806 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1807 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1808 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1810 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1812 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1815 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1817 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1820 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1823 fputc ('\n', asm_out_file);
1824 ASM_OUTPUT_LABEL (asm_out_file, l1);
1827 /* Now that the CIE pointer is PC-relative for EH,
1828 use 0 to identify the CIE. */
1829 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1831 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1834 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1836 fputc ('\n', asm_out_file);
1837 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1839 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1840 fputc ('\n', asm_out_file);
1843 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1845 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1847 fputc ('\n', asm_out_file);
1850 /* The CIE contains a pointer to the exception region info for the
1851 frame. Make the augmentation string three bytes (including the
1852 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1853 can't handle unaligned relocs. */
1856 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1857 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1861 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1863 fputc ('\n', asm_out_file);
1865 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1867 fprintf (asm_out_file, "\t%s pointer to exception region info",
1872 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1874 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1878 fputc ('\n', asm_out_file);
1881 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1883 fputc ('\n', asm_out_file);
1884 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1886 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1888 fputc ('\n', asm_out_file);
1889 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1891 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1893 fputc ('\n', asm_out_file);
1895 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1896 output_cfi (cfi, NULL);
1898 /* Pad the CIE out to an address sized boundary. */
1899 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1900 ASM_OUTPUT_LABEL (asm_out_file, l2);
1901 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1902 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1904 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1905 fputc ('\n', asm_out_file);
1908 /* Loop through all of the FDE's. */
1909 for (i = 0; i < fde_table_in_use; ++i)
1911 fde = &fde_table[i];
1913 /* Don't emit EH unwind info for leaf functions. */
1914 if (for_eh && fde->nothrow)
1917 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1918 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1919 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1920 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i * 2);
1922 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1924 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1927 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1929 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1932 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1933 fputc ('\n', asm_out_file);
1934 ASM_OUTPUT_LABEL (asm_out_file, l1);
1936 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1937 emits a target dependent sized offset when for_eh is not true.
1938 This inconsistency may confuse gdb. The only case where we need a
1939 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1940 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1941 though in order to be compatible with the dwarf_fde struct in frame.c.
1942 If the for_eh case is changed, then the struct in frame.c has
1943 to be adjusted appropriately. */
1945 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1947 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1949 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1951 fputc ('\n', asm_out_file);
1952 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1954 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1956 fputc ('\n', asm_out_file);
1957 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1958 fde->dw_fde_end, fde->dw_fde_begin);
1960 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1962 fputc ('\n', asm_out_file);
1964 /* Loop through the Call Frame Instructions associated with
1966 fde->dw_fde_current_label = fde->dw_fde_begin;
1967 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1968 output_cfi (cfi, fde);
1970 /* Pad the FDE out to an address sized boundary. */
1971 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1972 ASM_OUTPUT_LABEL (asm_out_file, l2);
1973 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1974 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1976 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1977 fputc ('\n', asm_out_file);
1980 #ifndef EH_FRAME_SECTION
1983 /* Emit terminating zero for table. */
1984 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1985 fputc ('\n', asm_out_file);
1988 #ifdef MIPS_DEBUGGING_INFO
1989 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1990 get a value of 0. Putting .align 0 after the label fixes it. */
1991 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1994 /* Turn off app to make assembly quicker. */
1999 /* Output a marker (i.e. a label) for the beginning of a function, before
2003 dwarf2out_begin_prologue ()
2005 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2006 register dw_fde_ref fde;
2008 ++current_funcdef_number;
2010 function_section (current_function_decl);
2011 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2012 current_funcdef_number);
2013 ASM_OUTPUT_LABEL (asm_out_file, label);
2014 current_function_func_begin_label = get_identifier (label);
2016 /* Expand the fde table if necessary. */
2017 if (fde_table_in_use == fde_table_allocated)
2019 fde_table_allocated += FDE_TABLE_INCREMENT;
2021 = (dw_fde_ref) xrealloc (fde_table,
2022 fde_table_allocated * sizeof (dw_fde_node));
2025 /* Record the FDE associated with this function. */
2026 current_funcdef_fde = fde_table_in_use;
2028 /* Add the new FDE at the end of the fde_table. */
2029 fde = &fde_table[fde_table_in_use++];
2030 fde->dw_fde_begin = xstrdup (label);
2031 fde->dw_fde_current_label = NULL;
2032 fde->dw_fde_end = NULL;
2033 fde->dw_fde_cfi = NULL;
2034 fde->nothrow = current_function_nothrow;
2036 args_size = old_args_size = 0;
2039 /* Output a marker (i.e. a label) for the absolute end of the generated code
2040 for a function definition. This gets called *after* the epilogue code has
2044 dwarf2out_end_epilogue ()
2047 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2049 /* Output a label to mark the endpoint of the code generated for this
2051 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2052 ASM_OUTPUT_LABEL (asm_out_file, label);
2053 fde = &fde_table[fde_table_in_use - 1];
2054 fde->dw_fde_end = xstrdup (label);
2058 dwarf2out_frame_init ()
2060 /* Allocate the initial hunk of the fde_table. */
2061 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2062 fde_table_allocated = FDE_TABLE_INCREMENT;
2063 fde_table_in_use = 0;
2065 /* Generate the CFA instructions common to all FDE's. Do it now for the
2066 sake of lookup_cfa. */
2068 #ifdef DWARF2_UNWIND_INFO
2069 /* On entry, the Canonical Frame Address is at SP. */
2070 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2071 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2076 dwarf2out_frame_finish ()
2078 /* Output call frame information. */
2079 #ifdef MIPS_DEBUGGING_INFO
2080 if (write_symbols == DWARF2_DEBUG)
2081 output_call_frame_info (0);
2082 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2083 output_call_frame_info (1);
2085 if (write_symbols == DWARF2_DEBUG
2086 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2087 output_call_frame_info (1);
2091 /* And now, the subset of the debugging information support code necessary
2092 for emitting location expressions. */
2094 typedef struct dw_val_struct *dw_val_ref;
2095 typedef struct die_struct *dw_die_ref;
2096 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2098 /* Each DIE may have a series of attribute/value pairs. Values
2099 can take on several forms. The forms that are used in this
2100 implementation are listed below. */
2107 dw_val_class_unsigned_const,
2108 dw_val_class_long_long,
2111 dw_val_class_die_ref,
2112 dw_val_class_fde_ref,
2113 dw_val_class_lbl_id,
2114 dw_val_class_lbl_offset,
2119 /* Describe a double word constant value. */
2120 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2122 typedef struct dw_long_long_struct
2129 /* Describe a floating point constant value. */
2131 typedef struct dw_fp_struct
2138 /* The dw_val_node describes an attribute's value, as it is
2139 represented internally. */
2141 typedef struct dw_val_struct
2143 dw_val_class val_class;
2147 dw_loc_descr_ref val_loc;
2149 long unsigned val_unsigned;
2150 dw_long_long_const val_long_long;
2151 dw_float_const val_float;
2156 unsigned val_fde_index;
2159 unsigned char val_flag;
2165 /* Locations in memory are described using a sequence of stack machine
2168 typedef struct dw_loc_descr_struct
2170 dw_loc_descr_ref dw_loc_next;
2171 enum dwarf_location_atom dw_loc_opc;
2172 dw_val_node dw_loc_oprnd1;
2173 dw_val_node dw_loc_oprnd2;
2177 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2178 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2181 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2183 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2184 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2185 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2186 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2188 /* Convert a DWARF stack opcode into its string name. */
2191 dwarf_stack_op_name (op)
2192 register unsigned op;
2197 return "DW_OP_addr";
2199 return "DW_OP_deref";
2201 return "DW_OP_const1u";
2203 return "DW_OP_const1s";
2205 return "DW_OP_const2u";
2207 return "DW_OP_const2s";
2209 return "DW_OP_const4u";
2211 return "DW_OP_const4s";
2213 return "DW_OP_const8u";
2215 return "DW_OP_const8s";
2217 return "DW_OP_constu";
2219 return "DW_OP_consts";
2223 return "DW_OP_drop";
2225 return "DW_OP_over";
2227 return "DW_OP_pick";
2229 return "DW_OP_swap";
2233 return "DW_OP_xderef";
2241 return "DW_OP_minus";
2253 return "DW_OP_plus";
2254 case DW_OP_plus_uconst:
2255 return "DW_OP_plus_uconst";
2261 return "DW_OP_shra";
2279 return "DW_OP_skip";
2281 return "DW_OP_lit0";
2283 return "DW_OP_lit1";
2285 return "DW_OP_lit2";
2287 return "DW_OP_lit3";
2289 return "DW_OP_lit4";
2291 return "DW_OP_lit5";
2293 return "DW_OP_lit6";
2295 return "DW_OP_lit7";
2297 return "DW_OP_lit8";
2299 return "DW_OP_lit9";
2301 return "DW_OP_lit10";
2303 return "DW_OP_lit11";
2305 return "DW_OP_lit12";
2307 return "DW_OP_lit13";
2309 return "DW_OP_lit14";
2311 return "DW_OP_lit15";
2313 return "DW_OP_lit16";
2315 return "DW_OP_lit17";
2317 return "DW_OP_lit18";
2319 return "DW_OP_lit19";
2321 return "DW_OP_lit20";
2323 return "DW_OP_lit21";
2325 return "DW_OP_lit22";
2327 return "DW_OP_lit23";
2329 return "DW_OP_lit24";
2331 return "DW_OP_lit25";
2333 return "DW_OP_lit26";
2335 return "DW_OP_lit27";
2337 return "DW_OP_lit28";
2339 return "DW_OP_lit29";
2341 return "DW_OP_lit30";
2343 return "DW_OP_lit31";
2345 return "DW_OP_reg0";
2347 return "DW_OP_reg1";
2349 return "DW_OP_reg2";
2351 return "DW_OP_reg3";
2353 return "DW_OP_reg4";
2355 return "DW_OP_reg5";
2357 return "DW_OP_reg6";
2359 return "DW_OP_reg7";
2361 return "DW_OP_reg8";
2363 return "DW_OP_reg9";
2365 return "DW_OP_reg10";
2367 return "DW_OP_reg11";
2369 return "DW_OP_reg12";
2371 return "DW_OP_reg13";
2373 return "DW_OP_reg14";
2375 return "DW_OP_reg15";
2377 return "DW_OP_reg16";
2379 return "DW_OP_reg17";
2381 return "DW_OP_reg18";
2383 return "DW_OP_reg19";
2385 return "DW_OP_reg20";
2387 return "DW_OP_reg21";
2389 return "DW_OP_reg22";
2391 return "DW_OP_reg23";
2393 return "DW_OP_reg24";
2395 return "DW_OP_reg25";
2397 return "DW_OP_reg26";
2399 return "DW_OP_reg27";
2401 return "DW_OP_reg28";
2403 return "DW_OP_reg29";
2405 return "DW_OP_reg30";
2407 return "DW_OP_reg31";
2409 return "DW_OP_breg0";
2411 return "DW_OP_breg1";
2413 return "DW_OP_breg2";
2415 return "DW_OP_breg3";
2417 return "DW_OP_breg4";
2419 return "DW_OP_breg5";
2421 return "DW_OP_breg6";
2423 return "DW_OP_breg7";
2425 return "DW_OP_breg8";
2427 return "DW_OP_breg9";
2429 return "DW_OP_breg10";
2431 return "DW_OP_breg11";
2433 return "DW_OP_breg12";
2435 return "DW_OP_breg13";
2437 return "DW_OP_breg14";
2439 return "DW_OP_breg15";
2441 return "DW_OP_breg16";
2443 return "DW_OP_breg17";
2445 return "DW_OP_breg18";
2447 return "DW_OP_breg19";
2449 return "DW_OP_breg20";
2451 return "DW_OP_breg21";
2453 return "DW_OP_breg22";
2455 return "DW_OP_breg23";
2457 return "DW_OP_breg24";
2459 return "DW_OP_breg25";
2461 return "DW_OP_breg26";
2463 return "DW_OP_breg27";
2465 return "DW_OP_breg28";
2467 return "DW_OP_breg29";
2469 return "DW_OP_breg30";
2471 return "DW_OP_breg31";
2473 return "DW_OP_regx";
2475 return "DW_OP_fbreg";
2477 return "DW_OP_bregx";
2479 return "DW_OP_piece";
2480 case DW_OP_deref_size:
2481 return "DW_OP_deref_size";
2482 case DW_OP_xderef_size:
2483 return "DW_OP_xderef_size";
2487 return "OP_<unknown>";
2491 /* Return a pointer to a newly allocated location description. Location
2492 descriptions are simple expression terms that can be strung
2493 together to form more complicated location (address) descriptions. */
2495 static inline dw_loc_descr_ref
2496 new_loc_descr (op, oprnd1, oprnd2)
2497 register enum dwarf_location_atom op;
2498 register unsigned long oprnd1;
2499 register unsigned long oprnd2;
2501 /* Use xcalloc here so we clear out all of the long_long constant in
2503 register dw_loc_descr_ref descr
2504 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2506 descr->dw_loc_opc = op;
2507 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2508 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2509 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2510 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2515 /* Add a location description term to a location description expression. */
2518 add_loc_descr (list_head, descr)
2519 register dw_loc_descr_ref *list_head;
2520 register dw_loc_descr_ref descr;
2522 register dw_loc_descr_ref *d;
2524 /* Find the end of the chain. */
2525 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2531 /* Return the size of a location descriptor. */
2533 static unsigned long
2534 size_of_loc_descr (loc)
2535 register dw_loc_descr_ref loc;
2537 register unsigned long size = 1;
2539 switch (loc->dw_loc_opc)
2542 size += DWARF2_ADDR_SIZE;
2561 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2564 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2569 case DW_OP_plus_uconst:
2570 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2608 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2611 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2614 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2617 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2618 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2621 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2623 case DW_OP_deref_size:
2624 case DW_OP_xderef_size:
2634 /* Return the size of a series of location descriptors. */
2636 static unsigned long
2638 register dw_loc_descr_ref loc;
2640 register unsigned long size = 0;
2642 for (; loc != NULL; loc = loc->dw_loc_next)
2643 size += size_of_loc_descr (loc);
2648 /* Output location description stack opcode's operands (if any). */
2651 output_loc_operands (loc)
2652 register dw_loc_descr_ref loc;
2654 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2655 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2657 switch (loc->dw_loc_opc)
2659 #ifdef DWARF2_DEBUGGING_INFO
2661 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
2662 fputc ('\n', asm_out_file);
2666 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2667 fputc ('\n', asm_out_file);
2671 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
2672 fputc ('\n', asm_out_file);
2677 fputc ('\n', asm_out_file);
2681 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2682 fputc ('\n', asm_out_file);
2694 /* We currently don't make any attempt to make sure these are
2695 aligned properly like we do for the main unwind info, so
2696 don't support emitting things larger than a byte if we're
2697 only doing unwinding. */
2702 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2703 fputc ('\n', asm_out_file);
2706 output_uleb128 (val1->v.val_unsigned);
2707 fputc ('\n', asm_out_file);
2710 output_sleb128 (val1->v.val_int);
2711 fputc ('\n', asm_out_file);
2714 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
2715 fputc ('\n', asm_out_file);
2717 case DW_OP_plus_uconst:
2718 output_uleb128 (val1->v.val_unsigned);
2719 fputc ('\n', asm_out_file);
2753 output_sleb128 (val1->v.val_int);
2754 fputc ('\n', asm_out_file);
2757 output_uleb128 (val1->v.val_unsigned);
2758 fputc ('\n', asm_out_file);
2761 output_sleb128 (val1->v.val_int);
2762 fputc ('\n', asm_out_file);
2765 output_uleb128 (val1->v.val_unsigned);
2766 fputc ('\n', asm_out_file);
2767 output_sleb128 (val2->v.val_int);
2768 fputc ('\n', asm_out_file);
2771 output_uleb128 (val1->v.val_unsigned);
2772 fputc ('\n', asm_out_file);
2774 case DW_OP_deref_size:
2775 case DW_OP_xderef_size:
2776 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2777 fputc ('\n', asm_out_file);
2780 /* Other codes have no operands. */
2785 /* Output a sequence of location operations. */
2788 output_loc_sequence (loc)
2789 dw_loc_descr_ref loc;
2791 for (; loc != NULL; loc = loc->dw_loc_next)
2793 /* Output the opcode. */
2794 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
2796 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
2797 dwarf_stack_op_name (loc->dw_loc_opc));
2799 fputc ('\n', asm_out_file);
2801 /* Output the operand(s) (if any). */
2802 output_loc_operands (loc);
2806 /* This routine will generate the correct assembly data for a location
2807 description based on a cfi entry with a complex address. */
2810 output_cfa_loc (cfi)
2813 dw_loc_descr_ref loc;
2816 /* Output the size of the block. */
2817 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2818 size = size_of_locs (loc);
2819 output_uleb128 (size);
2820 fputc ('\n', asm_out_file);
2822 /* Now output the operations themselves. */
2823 output_loc_sequence (loc);
2826 /* This function builds a dwarf location descriptor seqeunce from
2827 a dw_cfa_location. */
2829 static struct dw_loc_descr_struct *
2831 dw_cfa_location *cfa;
2833 struct dw_loc_descr_struct *head, *tmp;
2835 if (cfa->indirect == 0)
2838 if (cfa->base_offset)
2839 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2841 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2842 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2843 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2844 add_loc_descr (&head, tmp);
2845 if (cfa->offset != 0)
2847 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2848 add_loc_descr (&head, tmp);
2853 /* This function fills in aa dw_cfa_location structure from a
2854 dwarf location descriptor sequence. */
2857 get_cfa_from_loc_descr (cfa, loc)
2858 dw_cfa_location *cfa;
2859 struct dw_loc_descr_struct *loc;
2861 struct dw_loc_descr_struct *ptr;
2863 cfa->base_offset = 0;
2867 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2869 enum dwarf_location_atom op = ptr->dw_loc_opc;
2904 cfa->reg = op - DW_OP_reg0;
2907 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2941 cfa->reg = op - DW_OP_breg0;
2942 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2945 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2946 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2951 case DW_OP_plus_uconst:
2952 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2955 fatal ("DW_LOC_OP %s not implememnted yet.\n",
2956 dwarf_stack_op_name (ptr->dw_loc_opc));
2960 #endif /* .debug_frame support */
2962 /* And now, the support for symbolic debugging information. */
2963 #ifdef DWARF2_DEBUGGING_INFO
2965 /* NOTE: In the comments in this file, many references are made to
2966 "Debugging Information Entries". This term is abbreviated as `DIE'
2967 throughout the remainder of this file. */
2969 /* An internal representation of the DWARF output is built, and then
2970 walked to generate the DWARF debugging info. The walk of the internal
2971 representation is done after the entire program has been compiled.
2972 The types below are used to describe the internal representation. */
2974 /* Various DIE's use offsets relative to the beginning of the
2975 .debug_info section to refer to each other. */
2977 typedef long int dw_offset;
2979 /* Define typedefs here to avoid circular dependencies. */
2981 typedef struct dw_attr_struct *dw_attr_ref;
2982 typedef struct dw_line_info_struct *dw_line_info_ref;
2983 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
2984 typedef struct pubname_struct *pubname_ref;
2985 typedef dw_die_ref *arange_ref;
2987 /* Each entry in the line_info_table maintains the file and
2988 line number associated with the label generated for that
2989 entry. The label gives the PC value associated with
2990 the line number entry. */
2992 typedef struct dw_line_info_struct
2994 unsigned long dw_file_num;
2995 unsigned long dw_line_num;
2999 /* Line information for functions in separate sections; each one gets its
3001 typedef struct dw_separate_line_info_struct
3003 unsigned long dw_file_num;
3004 unsigned long dw_line_num;
3005 unsigned long function;
3007 dw_separate_line_info_entry;
3009 /* Each DIE attribute has a field specifying the attribute kind,
3010 a link to the next attribute in the chain, and an attribute value.
3011 Attributes are typically linked below the DIE they modify. */
3013 typedef struct dw_attr_struct
3015 enum dwarf_attribute dw_attr;
3016 dw_attr_ref dw_attr_next;
3017 dw_val_node dw_attr_val;
3021 /* The Debugging Information Entry (DIE) structure */
3023 typedef struct die_struct
3025 enum dwarf_tag die_tag;
3027 dw_attr_ref die_attr;
3028 dw_die_ref die_parent;
3029 dw_die_ref die_child;
3031 dw_offset die_offset;
3032 unsigned long die_abbrev;
3036 /* The pubname structure */
3038 typedef struct pubname_struct
3045 /* The limbo die list structure. */
3046 typedef struct limbo_die_struct
3049 struct limbo_die_struct *next;
3053 /* How to start an assembler comment. */
3054 #ifndef ASM_COMMENT_START
3055 #define ASM_COMMENT_START ";#"
3058 /* Define a macro which returns non-zero for a TYPE_DECL which was
3059 implicitly generated for a tagged type.
3061 Note that unlike the gcc front end (which generates a NULL named
3062 TYPE_DECL node for each complete tagged type, each array type, and
3063 each function type node created) the g++ front end generates a
3064 _named_ TYPE_DECL node for each tagged type node created.
3065 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3066 generate a DW_TAG_typedef DIE for them. */
3068 #define TYPE_DECL_IS_STUB(decl) \
3069 (DECL_NAME (decl) == NULL_TREE \
3070 || (DECL_ARTIFICIAL (decl) \
3071 && is_tagged_type (TREE_TYPE (decl)) \
3072 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3073 /* This is necessary for stub decls that \
3074 appear in nested inline functions. */ \
3075 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3076 && (decl_ultimate_origin (decl) \
3077 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3079 /* Information concerning the compilation unit's programming
3080 language, and compiler version. */
3082 extern int flag_traditional;
3084 /* Fixed size portion of the DWARF compilation unit header. */
3085 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3087 /* Fixed size portion of debugging line information prolog. */
3088 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3090 /* Fixed size portion of public names info. */
3091 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3093 /* Fixed size portion of the address range info. */
3094 #define DWARF_ARANGES_HEADER_SIZE \
3095 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3096 - DWARF_OFFSET_SIZE)
3098 /* Size of padding portion in the address range info. It must be
3099 aligned to twice the pointer size. */
3100 #define DWARF_ARANGES_PAD_SIZE \
3101 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3102 - (2 * DWARF_OFFSET_SIZE + 4))
3104 /* The default is to have gcc emit the line number tables. */
3105 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3106 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3109 /* Define the architecture-dependent minimum instruction length (in bytes).
3110 In this implementation of DWARF, this field is used for information
3111 purposes only. Since GCC generates assembly language, we have
3112 no a priori knowledge of how many instruction bytes are generated
3113 for each source line, and therefore can use only the DW_LNE_set_address
3114 and DW_LNS_fixed_advance_pc line information commands. */
3116 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3117 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3120 /* Minimum line offset in a special line info. opcode.
3121 This value was chosen to give a reasonable range of values. */
3122 #define DWARF_LINE_BASE -10
3124 /* First special line opcde - leave room for the standard opcodes. */
3125 #define DWARF_LINE_OPCODE_BASE 10
3127 /* Range of line offsets in a special line info. opcode. */
3128 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3130 /* Flag that indicates the initial value of the is_stmt_start flag.
3131 In the present implementation, we do not mark any lines as
3132 the beginning of a source statement, because that information
3133 is not made available by the GCC front-end. */
3134 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3136 /* This location is used by calc_die_sizes() to keep track
3137 the offset of each DIE within the .debug_info section. */
3138 static unsigned long next_die_offset;
3140 /* Record the root of the DIE's built for the current compilation unit. */
3141 static dw_die_ref comp_unit_die;
3143 /* A list of DIEs with a NULL parent waiting to be relocated. */
3144 static limbo_die_node *limbo_die_list = 0;
3146 /* Pointer to an array of filenames referenced by this compilation unit. */
3147 static char **file_table;
3149 /* Total number of entries in the table (i.e. array) pointed to by
3150 `file_table'. This is the *total* and includes both used and unused
3152 static unsigned file_table_allocated;
3154 /* Number of entries in the file_table which are actually in use. */
3155 static unsigned file_table_in_use;
3157 /* Size (in elements) of increments by which we may expand the filename
3159 #define FILE_TABLE_INCREMENT 64
3161 /* Local pointer to the name of the main input file. Initialized in
3163 static const char *primary_filename;
3165 /* A pointer to the base of a table of references to DIE's that describe
3166 declarations. The table is indexed by DECL_UID() which is a unique
3167 number identifying each decl. */
3168 static dw_die_ref *decl_die_table;
3170 /* Number of elements currently allocated for the decl_die_table. */
3171 static unsigned decl_die_table_allocated;
3173 /* Number of elements in decl_die_table currently in use. */
3174 static unsigned decl_die_table_in_use;
3176 /* Size (in elements) of increments by which we may expand the
3178 #define DECL_DIE_TABLE_INCREMENT 256
3180 /* A pointer to the base of a table of references to declaration
3181 scopes. This table is a display which tracks the nesting
3182 of declaration scopes at the current scope and containing
3183 scopes. This table is used to find the proper place to
3184 define type declaration DIE's. */
3185 static tree *decl_scope_table;
3187 /* Number of elements currently allocated for the decl_scope_table. */
3188 static int decl_scope_table_allocated;
3190 /* Current level of nesting of declaration scopes. */
3191 static int decl_scope_depth;
3193 /* Size (in elements) of increments by which we may expand the
3194 decl_scope_table. */
3195 #define DECL_SCOPE_TABLE_INCREMENT 64
3197 /* A pointer to the base of a list of references to DIE's that
3198 are uniquely identified by their tag, presence/absence of
3199 children DIE's, and list of attribute/value pairs. */
3200 static dw_die_ref *abbrev_die_table;
3202 /* Number of elements currently allocated for abbrev_die_table. */
3203 static unsigned abbrev_die_table_allocated;
3205 /* Number of elements in type_die_table currently in use. */
3206 static unsigned abbrev_die_table_in_use;
3208 /* Size (in elements) of increments by which we may expand the
3209 abbrev_die_table. */
3210 #define ABBREV_DIE_TABLE_INCREMENT 256
3212 /* A pointer to the base of a table that contains line information
3213 for each source code line in .text in the compilation unit. */
3214 static dw_line_info_ref line_info_table;
3216 /* Number of elements currently allocated for line_info_table. */
3217 static unsigned line_info_table_allocated;
3219 /* Number of elements in separate_line_info_table currently in use. */
3220 static unsigned separate_line_info_table_in_use;
3222 /* A pointer to the base of a table that contains line information
3223 for each source code line outside of .text in the compilation unit. */
3224 static dw_separate_line_info_ref separate_line_info_table;
3226 /* Number of elements currently allocated for separate_line_info_table. */
3227 static unsigned separate_line_info_table_allocated;
3229 /* Number of elements in line_info_table currently in use. */
3230 static unsigned line_info_table_in_use;
3232 /* Size (in elements) of increments by which we may expand the
3234 #define LINE_INFO_TABLE_INCREMENT 1024
3236 /* A pointer to the base of a table that contains a list of publicly
3237 accessible names. */
3238 static pubname_ref pubname_table;
3240 /* Number of elements currently allocated for pubname_table. */
3241 static unsigned pubname_table_allocated;
3243 /* Number of elements in pubname_table currently in use. */
3244 static unsigned pubname_table_in_use;
3246 /* Size (in elements) of increments by which we may expand the
3248 #define PUBNAME_TABLE_INCREMENT 64
3250 /* A pointer to the base of a table that contains a list of publicly
3251 accessible names. */
3252 static arange_ref arange_table;
3254 /* Number of elements currently allocated for arange_table. */
3255 static unsigned arange_table_allocated;
3257 /* Number of elements in arange_table currently in use. */
3258 static unsigned arange_table_in_use;
3260 /* Size (in elements) of increments by which we may expand the
3262 #define ARANGE_TABLE_INCREMENT 64
3264 /* A pointer to the base of a list of incomplete types which might be
3265 completed at some later time. */
3267 static tree *incomplete_types_list;
3269 /* Number of elements currently allocated for the incomplete_types_list. */
3270 static unsigned incomplete_types_allocated;
3272 /* Number of elements of incomplete_types_list currently in use. */
3273 static unsigned incomplete_types;
3275 /* Size (in elements) of increments by which we may expand the incomplete
3276 types list. Actually, a single hunk of space of this size should
3277 be enough for most typical programs. */
3278 #define INCOMPLETE_TYPES_INCREMENT 64
3280 /* Record whether the function being analyzed contains inlined functions. */
3281 static int current_function_has_inlines;
3282 #if 0 && defined (MIPS_DEBUGGING_INFO)
3283 static int comp_unit_has_inlines;
3286 /* Array of RTXes referenced by the debugging information, which therefore
3287 must be kept around forever. We do this rather than perform GC on
3288 the dwarf info because almost all of the dwarf info lives forever, and
3289 it's easier to support non-GC frontends this way. */
3290 static varray_type used_rtx_varray;
3292 /* Forward declarations for functions defined in this file. */
3294 static int is_pseudo_reg PARAMS ((rtx));
3295 static tree type_main_variant PARAMS ((tree));
3296 static int is_tagged_type PARAMS ((tree));
3297 static const char *dwarf_tag_name PARAMS ((unsigned));
3298 static const char *dwarf_attr_name PARAMS ((unsigned));
3299 static const char *dwarf_form_name PARAMS ((unsigned));
3301 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3303 static tree decl_ultimate_origin PARAMS ((tree));
3304 static tree block_ultimate_origin PARAMS ((tree));
3305 static tree decl_class_context PARAMS ((tree));
3306 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3307 static void add_AT_flag PARAMS ((dw_die_ref,
3308 enum dwarf_attribute,
3310 static void add_AT_int PARAMS ((dw_die_ref,
3311 enum dwarf_attribute, long));
3312 static void add_AT_unsigned PARAMS ((dw_die_ref,
3313 enum dwarf_attribute,
3315 static void add_AT_long_long PARAMS ((dw_die_ref,
3316 enum dwarf_attribute,
3319 static void add_AT_float PARAMS ((dw_die_ref,
3320 enum dwarf_attribute,
3322 static void add_AT_string PARAMS ((dw_die_ref,
3323 enum dwarf_attribute,
3325 static void add_AT_die_ref PARAMS ((dw_die_ref,
3326 enum dwarf_attribute,
3328 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3329 enum dwarf_attribute,
3331 static void add_AT_loc PARAMS ((dw_die_ref,
3332 enum dwarf_attribute,
3334 static void add_AT_addr PARAMS ((dw_die_ref,
3335 enum dwarf_attribute,
3337 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3338 enum dwarf_attribute,
3340 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3341 enum dwarf_attribute,
3343 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3344 enum dwarf_attribute));
3345 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3346 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3347 static const char *get_AT_string PARAMS ((dw_die_ref,
3348 enum dwarf_attribute));
3349 static int get_AT_flag PARAMS ((dw_die_ref,
3350 enum dwarf_attribute));
3351 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3352 enum dwarf_attribute));
3353 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3354 enum dwarf_attribute));
3355 static int is_c_family PARAMS ((void));
3356 static int is_java PARAMS ((void));
3357 static int is_fortran PARAMS ((void));
3358 static void remove_AT PARAMS ((dw_die_ref,
3359 enum dwarf_attribute));
3360 static void remove_children PARAMS ((dw_die_ref));
3361 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3362 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3363 static dw_die_ref lookup_type_die PARAMS ((tree));
3364 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3365 static dw_die_ref lookup_decl_die PARAMS ((tree));
3366 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3367 static void print_spaces PARAMS ((FILE *));
3368 static void print_die PARAMS ((dw_die_ref, FILE *));
3369 static void print_dwarf_line_table PARAMS ((FILE *));
3370 static void reverse_die_lists PARAMS ((dw_die_ref));
3371 static void reverse_all_dies PARAMS ((dw_die_ref));
3372 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3373 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3374 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3375 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3376 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3377 static void compute_section_prefix PARAMS ((dw_die_ref));
3378 static int is_type_die PARAMS ((dw_die_ref));
3379 static int is_comdat_die PARAMS ((dw_die_ref));
3380 static int is_symbol_die PARAMS ((dw_die_ref));
3381 static char *gen_internal_sym PARAMS ((void));
3382 static void assign_symbol_names PARAMS ((dw_die_ref));
3383 static void break_out_includes PARAMS ((dw_die_ref));
3384 static void add_sibling_attributes PARAMS ((dw_die_ref));
3385 static void build_abbrev_table PARAMS ((dw_die_ref));
3386 static unsigned long size_of_string PARAMS ((const char *));
3387 static int constant_size PARAMS ((long unsigned));
3388 static unsigned long size_of_die PARAMS ((dw_die_ref));
3389 static void calc_die_sizes PARAMS ((dw_die_ref));
3390 static void clear_die_sizes 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 add_name_attribute PARAMS ((dw_die_ref, const char *));
3431 static void add_bound_info PARAMS ((dw_die_ref,
3432 enum dwarf_attribute, tree));
3433 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3434 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3435 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3436 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3437 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3438 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3439 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3440 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3441 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3442 static void push_decl_scope PARAMS ((tree));
3443 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3444 static void pop_decl_scope PARAMS ((void));
3445 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3447 static const char *type_tag PARAMS ((tree));
3448 static tree member_declared_type PARAMS ((tree));
3450 static const char *decl_start_label PARAMS ((tree));
3452 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3453 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3455 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3457 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3458 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3459 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3460 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3461 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3462 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3463 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3464 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3465 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3466 static void gen_label_die PARAMS ((tree, dw_die_ref));
3467 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3468 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3469 static void gen_field_die PARAMS ((tree, dw_die_ref));
3470 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3471 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3472 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3473 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3474 static void gen_member_die PARAMS ((tree, dw_die_ref));
3475 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3476 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3477 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3478 static void gen_type_die PARAMS ((tree, dw_die_ref));
3479 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3480 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3481 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3482 static int is_redundant_typedef PARAMS ((tree));
3483 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3484 static unsigned lookup_filename PARAMS ((const char *));
3485 static void add_incomplete_type PARAMS ((tree));
3486 static void retry_incomplete_types PARAMS ((void));
3487 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3488 static void gen_abstract_function PARAMS ((tree));
3489 static rtx save_rtx PARAMS ((rtx));
3490 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3492 /* Section names used to hold DWARF debugging information. */
3493 #ifndef DEBUG_INFO_SECTION
3494 #define DEBUG_INFO_SECTION ".debug_info"
3496 #ifndef ABBREV_SECTION
3497 #define ABBREV_SECTION ".debug_abbrev"
3499 #ifndef ARANGES_SECTION
3500 #define ARANGES_SECTION ".debug_aranges"
3502 #ifndef DW_MACINFO_SECTION
3503 #define DW_MACINFO_SECTION ".debug_macinfo"
3505 #ifndef DEBUG_LINE_SECTION
3506 #define DEBUG_LINE_SECTION ".debug_line"
3509 #define LOC_SECTION ".debug_loc"
3511 #ifndef PUBNAMES_SECTION
3512 #define PUBNAMES_SECTION ".debug_pubnames"
3515 #define STR_SECTION ".debug_str"
3518 /* Standard ELF section names for compiled code and data. */
3519 #ifndef TEXT_SECTION
3520 #define TEXT_SECTION ".text"
3522 #ifndef DATA_SECTION
3523 #define DATA_SECTION ".data"
3526 #define BSS_SECTION ".bss"
3529 /* Labels we insert at beginning sections we can reference instead of
3530 the section names themselves. */
3532 #ifndef TEXT_SECTION_LABEL
3533 #define TEXT_SECTION_LABEL "Ltext"
3535 #ifndef DEBUG_LINE_SECTION_LABEL
3536 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3538 #ifndef DEBUG_INFO_SECTION_LABEL
3539 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3541 #ifndef ABBREV_SECTION_LABEL
3542 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3545 /* Definitions of defaults for formats and names of various special
3546 (artificial) labels which may be generated within this file (when the -g
3547 options is used and DWARF_DEBUGGING_INFO is in effect.
3548 If necessary, these may be overridden from within the tm.h file, but
3549 typically, overriding these defaults is unnecessary. */
3551 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3552 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3553 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3554 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3555 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3557 #ifndef TEXT_END_LABEL
3558 #define TEXT_END_LABEL "Letext"
3560 #ifndef DATA_END_LABEL
3561 #define DATA_END_LABEL "Ledata"
3563 #ifndef BSS_END_LABEL
3564 #define BSS_END_LABEL "Lebss"
3566 #ifndef INSN_LABEL_FMT
3567 #define INSN_LABEL_FMT "LI%u_"
3569 #ifndef BLOCK_BEGIN_LABEL
3570 #define BLOCK_BEGIN_LABEL "LBB"
3572 #ifndef BLOCK_END_LABEL
3573 #define BLOCK_END_LABEL "LBE"
3575 #ifndef BODY_BEGIN_LABEL
3576 #define BODY_BEGIN_LABEL "Lbb"
3578 #ifndef BODY_END_LABEL
3579 #define BODY_END_LABEL "Lbe"
3581 #ifndef LINE_CODE_LABEL
3582 #define LINE_CODE_LABEL "LM"
3584 #ifndef SEPARATE_LINE_CODE_LABEL
3585 #define SEPARATE_LINE_CODE_LABEL "LSM"
3588 /* We allow a language front-end to designate a function that is to be
3589 called to "demangle" any name before it it put into a DIE. */
3591 static const char *(*demangle_name_func) PARAMS ((const char *));
3594 dwarf2out_set_demangle_name_func (func)
3595 const char *(*func) PARAMS ((const char *));
3597 demangle_name_func = func;
3600 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3601 that means adding it to used_rtx_varray. If not, that means making
3602 a copy on the permanent_obstack. */
3609 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3612 push_obstacks_nochange ();
3613 end_temporary_allocation ();
3614 orig = copy_rtx (orig);
3621 /* Test if rtl node points to a pseudo register. */
3627 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3628 || (GET_CODE (rtl) == SUBREG
3629 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3632 /* Return a reference to a type, with its const and volatile qualifiers
3636 type_main_variant (type)
3639 type = TYPE_MAIN_VARIANT (type);
3641 /* There really should be only one main variant among any group of variants
3642 of a given type (and all of the MAIN_VARIANT values for all members of
3643 the group should point to that one type) but sometimes the C front-end
3644 messes this up for array types, so we work around that bug here. */
3646 if (TREE_CODE (type) == ARRAY_TYPE)
3647 while (type != TYPE_MAIN_VARIANT (type))
3648 type = TYPE_MAIN_VARIANT (type);
3653 /* Return non-zero if the given type node represents a tagged type. */
3656 is_tagged_type (type)
3659 register enum tree_code code = TREE_CODE (type);
3661 return (code == RECORD_TYPE || code == UNION_TYPE
3662 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3665 /* Convert a DIE tag into its string name. */
3668 dwarf_tag_name (tag)
3669 register unsigned tag;
3673 case DW_TAG_padding:
3674 return "DW_TAG_padding";
3675 case DW_TAG_array_type:
3676 return "DW_TAG_array_type";
3677 case DW_TAG_class_type:
3678 return "DW_TAG_class_type";
3679 case DW_TAG_entry_point:
3680 return "DW_TAG_entry_point";
3681 case DW_TAG_enumeration_type:
3682 return "DW_TAG_enumeration_type";
3683 case DW_TAG_formal_parameter:
3684 return "DW_TAG_formal_parameter";
3685 case DW_TAG_imported_declaration:
3686 return "DW_TAG_imported_declaration";
3688 return "DW_TAG_label";
3689 case DW_TAG_lexical_block:
3690 return "DW_TAG_lexical_block";
3692 return "DW_TAG_member";
3693 case DW_TAG_pointer_type:
3694 return "DW_TAG_pointer_type";
3695 case DW_TAG_reference_type:
3696 return "DW_TAG_reference_type";
3697 case DW_TAG_compile_unit:
3698 return "DW_TAG_compile_unit";
3699 case DW_TAG_string_type:
3700 return "DW_TAG_string_type";
3701 case DW_TAG_structure_type:
3702 return "DW_TAG_structure_type";
3703 case DW_TAG_subroutine_type:
3704 return "DW_TAG_subroutine_type";
3705 case DW_TAG_typedef:
3706 return "DW_TAG_typedef";
3707 case DW_TAG_union_type:
3708 return "DW_TAG_union_type";
3709 case DW_TAG_unspecified_parameters:
3710 return "DW_TAG_unspecified_parameters";
3711 case DW_TAG_variant:
3712 return "DW_TAG_variant";
3713 case DW_TAG_common_block:
3714 return "DW_TAG_common_block";
3715 case DW_TAG_common_inclusion:
3716 return "DW_TAG_common_inclusion";
3717 case DW_TAG_inheritance:
3718 return "DW_TAG_inheritance";
3719 case DW_TAG_inlined_subroutine:
3720 return "DW_TAG_inlined_subroutine";
3722 return "DW_TAG_module";
3723 case DW_TAG_ptr_to_member_type:
3724 return "DW_TAG_ptr_to_member_type";
3725 case DW_TAG_set_type:
3726 return "DW_TAG_set_type";
3727 case DW_TAG_subrange_type:
3728 return "DW_TAG_subrange_type";
3729 case DW_TAG_with_stmt:
3730 return "DW_TAG_with_stmt";
3731 case DW_TAG_access_declaration:
3732 return "DW_TAG_access_declaration";
3733 case DW_TAG_base_type:
3734 return "DW_TAG_base_type";
3735 case DW_TAG_catch_block:
3736 return "DW_TAG_catch_block";
3737 case DW_TAG_const_type:
3738 return "DW_TAG_const_type";
3739 case DW_TAG_constant:
3740 return "DW_TAG_constant";
3741 case DW_TAG_enumerator:
3742 return "DW_TAG_enumerator";
3743 case DW_TAG_file_type:
3744 return "DW_TAG_file_type";
3746 return "DW_TAG_friend";
3747 case DW_TAG_namelist:
3748 return "DW_TAG_namelist";
3749 case DW_TAG_namelist_item:
3750 return "DW_TAG_namelist_item";
3751 case DW_TAG_packed_type:
3752 return "DW_TAG_packed_type";
3753 case DW_TAG_subprogram:
3754 return "DW_TAG_subprogram";
3755 case DW_TAG_template_type_param:
3756 return "DW_TAG_template_type_param";
3757 case DW_TAG_template_value_param:
3758 return "DW_TAG_template_value_param";
3759 case DW_TAG_thrown_type:
3760 return "DW_TAG_thrown_type";
3761 case DW_TAG_try_block:
3762 return "DW_TAG_try_block";
3763 case DW_TAG_variant_part:
3764 return "DW_TAG_variant_part";
3765 case DW_TAG_variable:
3766 return "DW_TAG_variable";
3767 case DW_TAG_volatile_type:
3768 return "DW_TAG_volatile_type";
3769 case DW_TAG_MIPS_loop:
3770 return "DW_TAG_MIPS_loop";
3771 case DW_TAG_format_label:
3772 return "DW_TAG_format_label";
3773 case DW_TAG_function_template:
3774 return "DW_TAG_function_template";
3775 case DW_TAG_class_template:
3776 return "DW_TAG_class_template";
3777 case DW_TAG_GNU_BINCL:
3778 return "DW_TAG_GNU_BINCL";
3779 case DW_TAG_GNU_EINCL:
3780 return "DW_TAG_GNU_EINCL";
3782 return "DW_TAG_<unknown>";
3786 /* Convert a DWARF attribute code into its string name. */
3789 dwarf_attr_name (attr)
3790 register unsigned attr;
3795 return "DW_AT_sibling";
3796 case DW_AT_location:
3797 return "DW_AT_location";
3799 return "DW_AT_name";
3800 case DW_AT_ordering:
3801 return "DW_AT_ordering";
3802 case DW_AT_subscr_data:
3803 return "DW_AT_subscr_data";
3804 case DW_AT_byte_size:
3805 return "DW_AT_byte_size";
3806 case DW_AT_bit_offset:
3807 return "DW_AT_bit_offset";
3808 case DW_AT_bit_size:
3809 return "DW_AT_bit_size";
3810 case DW_AT_element_list:
3811 return "DW_AT_element_list";
3812 case DW_AT_stmt_list:
3813 return "DW_AT_stmt_list";
3815 return "DW_AT_low_pc";
3817 return "DW_AT_high_pc";
3818 case DW_AT_language:
3819 return "DW_AT_language";
3821 return "DW_AT_member";
3823 return "DW_AT_discr";
3824 case DW_AT_discr_value:
3825 return "DW_AT_discr_value";
3826 case DW_AT_visibility:
3827 return "DW_AT_visibility";
3829 return "DW_AT_import";
3830 case DW_AT_string_length:
3831 return "DW_AT_string_length";
3832 case DW_AT_common_reference:
3833 return "DW_AT_common_reference";
3834 case DW_AT_comp_dir:
3835 return "DW_AT_comp_dir";
3836 case DW_AT_const_value:
3837 return "DW_AT_const_value";
3838 case DW_AT_containing_type:
3839 return "DW_AT_containing_type";
3840 case DW_AT_default_value:
3841 return "DW_AT_default_value";
3843 return "DW_AT_inline";
3844 case DW_AT_is_optional:
3845 return "DW_AT_is_optional";
3846 case DW_AT_lower_bound:
3847 return "DW_AT_lower_bound";
3848 case DW_AT_producer:
3849 return "DW_AT_producer";
3850 case DW_AT_prototyped:
3851 return "DW_AT_prototyped";
3852 case DW_AT_return_addr:
3853 return "DW_AT_return_addr";
3854 case DW_AT_start_scope:
3855 return "DW_AT_start_scope";
3856 case DW_AT_stride_size:
3857 return "DW_AT_stride_size";
3858 case DW_AT_upper_bound:
3859 return "DW_AT_upper_bound";
3860 case DW_AT_abstract_origin:
3861 return "DW_AT_abstract_origin";
3862 case DW_AT_accessibility:
3863 return "DW_AT_accessibility";
3864 case DW_AT_address_class:
3865 return "DW_AT_address_class";
3866 case DW_AT_artificial:
3867 return "DW_AT_artificial";
3868 case DW_AT_base_types:
3869 return "DW_AT_base_types";
3870 case DW_AT_calling_convention:
3871 return "DW_AT_calling_convention";
3873 return "DW_AT_count";
3874 case DW_AT_data_member_location:
3875 return "DW_AT_data_member_location";
3876 case DW_AT_decl_column:
3877 return "DW_AT_decl_column";
3878 case DW_AT_decl_file:
3879 return "DW_AT_decl_file";
3880 case DW_AT_decl_line:
3881 return "DW_AT_decl_line";
3882 case DW_AT_declaration:
3883 return "DW_AT_declaration";
3884 case DW_AT_discr_list:
3885 return "DW_AT_discr_list";
3886 case DW_AT_encoding:
3887 return "DW_AT_encoding";
3888 case DW_AT_external:
3889 return "DW_AT_external";
3890 case DW_AT_frame_base:
3891 return "DW_AT_frame_base";
3893 return "DW_AT_friend";
3894 case DW_AT_identifier_case:
3895 return "DW_AT_identifier_case";
3896 case DW_AT_macro_info:
3897 return "DW_AT_macro_info";
3898 case DW_AT_namelist_items:
3899 return "DW_AT_namelist_items";
3900 case DW_AT_priority:
3901 return "DW_AT_priority";
3903 return "DW_AT_segment";
3904 case DW_AT_specification:
3905 return "DW_AT_specification";
3906 case DW_AT_static_link:
3907 return "DW_AT_static_link";
3909 return "DW_AT_type";
3910 case DW_AT_use_location:
3911 return "DW_AT_use_location";
3912 case DW_AT_variable_parameter:
3913 return "DW_AT_variable_parameter";
3914 case DW_AT_virtuality:
3915 return "DW_AT_virtuality";
3916 case DW_AT_vtable_elem_location:
3917 return "DW_AT_vtable_elem_location";
3919 case DW_AT_MIPS_fde:
3920 return "DW_AT_MIPS_fde";
3921 case DW_AT_MIPS_loop_begin:
3922 return "DW_AT_MIPS_loop_begin";
3923 case DW_AT_MIPS_tail_loop_begin:
3924 return "DW_AT_MIPS_tail_loop_begin";
3925 case DW_AT_MIPS_epilog_begin:
3926 return "DW_AT_MIPS_epilog_begin";
3927 case DW_AT_MIPS_loop_unroll_factor:
3928 return "DW_AT_MIPS_loop_unroll_factor";
3929 case DW_AT_MIPS_software_pipeline_depth:
3930 return "DW_AT_MIPS_software_pipeline_depth";
3931 case DW_AT_MIPS_linkage_name:
3932 return "DW_AT_MIPS_linkage_name";
3933 case DW_AT_MIPS_stride:
3934 return "DW_AT_MIPS_stride";
3935 case DW_AT_MIPS_abstract_name:
3936 return "DW_AT_MIPS_abstract_name";
3937 case DW_AT_MIPS_clone_origin:
3938 return "DW_AT_MIPS_clone_origin";
3939 case DW_AT_MIPS_has_inlines:
3940 return "DW_AT_MIPS_has_inlines";
3942 case DW_AT_sf_names:
3943 return "DW_AT_sf_names";
3944 case DW_AT_src_info:
3945 return "DW_AT_src_info";
3946 case DW_AT_mac_info:
3947 return "DW_AT_mac_info";
3948 case DW_AT_src_coords:
3949 return "DW_AT_src_coords";
3950 case DW_AT_body_begin:
3951 return "DW_AT_body_begin";
3952 case DW_AT_body_end:
3953 return "DW_AT_body_end";
3955 return "DW_AT_<unknown>";
3959 /* Convert a DWARF value form code into its string name. */
3962 dwarf_form_name (form)
3963 register unsigned form;
3968 return "DW_FORM_addr";
3969 case DW_FORM_block2:
3970 return "DW_FORM_block2";
3971 case DW_FORM_block4:
3972 return "DW_FORM_block4";
3974 return "DW_FORM_data2";
3976 return "DW_FORM_data4";
3978 return "DW_FORM_data8";
3979 case DW_FORM_string:
3980 return "DW_FORM_string";
3982 return "DW_FORM_block";
3983 case DW_FORM_block1:
3984 return "DW_FORM_block1";
3986 return "DW_FORM_data1";
3988 return "DW_FORM_flag";
3990 return "DW_FORM_sdata";
3992 return "DW_FORM_strp";
3994 return "DW_FORM_udata";
3995 case DW_FORM_ref_addr:
3996 return "DW_FORM_ref_addr";
3998 return "DW_FORM_ref1";
4000 return "DW_FORM_ref2";
4002 return "DW_FORM_ref4";
4004 return "DW_FORM_ref8";
4005 case DW_FORM_ref_udata:
4006 return "DW_FORM_ref_udata";
4007 case DW_FORM_indirect:
4008 return "DW_FORM_indirect";
4010 return "DW_FORM_<unknown>";
4014 /* Convert a DWARF type code into its string name. */
4018 dwarf_type_encoding_name (enc)
4019 register unsigned enc;
4023 case DW_ATE_address:
4024 return "DW_ATE_address";
4025 case DW_ATE_boolean:
4026 return "DW_ATE_boolean";
4027 case DW_ATE_complex_float:
4028 return "DW_ATE_complex_float";
4030 return "DW_ATE_float";
4032 return "DW_ATE_signed";
4033 case DW_ATE_signed_char:
4034 return "DW_ATE_signed_char";
4035 case DW_ATE_unsigned:
4036 return "DW_ATE_unsigned";
4037 case DW_ATE_unsigned_char:
4038 return "DW_ATE_unsigned_char";
4040 return "DW_ATE_<unknown>";
4045 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4046 instance of an inlined instance of a decl which is local to an inline
4047 function, so we have to trace all of the way back through the origin chain
4048 to find out what sort of node actually served as the original seed for the
4052 decl_ultimate_origin (decl)
4055 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4056 nodes in the function to point to themselves; ignore that if
4057 we're trying to output the abstract instance of this function. */
4058 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4061 #ifdef ENABLE_CHECKING
4062 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4063 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4064 most distant ancestor, this should never happen. */
4068 return DECL_ABSTRACT_ORIGIN (decl);
4071 /* Determine the "ultimate origin" of a block. The block may be an inlined
4072 instance of an inlined instance of a block which is local to an inline
4073 function, so we have to trace all of the way back through the origin chain
4074 to find out what sort of node actually served as the original seed for the
4078 block_ultimate_origin (block)
4079 register tree block;
4081 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4083 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4084 nodes in the function to point to themselves; ignore that if
4085 we're trying to output the abstract instance of this function. */
4086 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4089 if (immediate_origin == NULL_TREE)
4093 register tree ret_val;
4094 register tree lookahead = immediate_origin;
4098 ret_val = lookahead;
4099 lookahead = (TREE_CODE (ret_val) == BLOCK)
4100 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4103 while (lookahead != NULL && lookahead != ret_val);
4109 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4110 of a virtual function may refer to a base class, so we check the 'this'
4114 decl_class_context (decl)
4117 tree context = NULL_TREE;
4119 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4120 context = DECL_CONTEXT (decl);
4122 context = TYPE_MAIN_VARIANT
4123 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4125 if (context && !TYPE_P (context))
4126 context = NULL_TREE;
4131 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4132 addition order, and correct that in reverse_all_dies. */
4135 add_dwarf_attr (die, attr)
4136 register dw_die_ref die;
4137 register dw_attr_ref attr;
4139 if (die != NULL && attr != NULL)
4141 attr->dw_attr_next = die->die_attr;
4142 die->die_attr = attr;
4146 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4147 static inline dw_val_class
4151 return a->dw_attr_val.val_class;
4154 /* Add a flag value attribute to a DIE. */
4157 add_AT_flag (die, attr_kind, flag)
4158 register dw_die_ref die;
4159 register enum dwarf_attribute attr_kind;
4160 register unsigned flag;
4162 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4164 attr->dw_attr_next = NULL;
4165 attr->dw_attr = attr_kind;
4166 attr->dw_attr_val.val_class = dw_val_class_flag;
4167 attr->dw_attr_val.v.val_flag = flag;
4168 add_dwarf_attr (die, attr);
4171 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4172 static inline unsigned
4174 register dw_attr_ref a;
4176 if (a && AT_class (a) == dw_val_class_flag)
4177 return a->dw_attr_val.v.val_flag;
4182 /* Add a signed integer attribute value to a DIE. */
4185 add_AT_int (die, attr_kind, int_val)
4186 register dw_die_ref die;
4187 register enum dwarf_attribute attr_kind;
4188 register long int int_val;
4190 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4192 attr->dw_attr_next = NULL;
4193 attr->dw_attr = attr_kind;
4194 attr->dw_attr_val.val_class = dw_val_class_const;
4195 attr->dw_attr_val.v.val_int = int_val;
4196 add_dwarf_attr (die, attr);
4199 static inline long int AT_int PARAMS ((dw_attr_ref));
4200 static inline long int
4202 register dw_attr_ref a;
4204 if (a && AT_class (a) == dw_val_class_const)
4205 return a->dw_attr_val.v.val_int;
4210 /* Add an unsigned integer attribute value to a DIE. */
4213 add_AT_unsigned (die, attr_kind, unsigned_val)
4214 register dw_die_ref die;
4215 register enum dwarf_attribute attr_kind;
4216 register unsigned long unsigned_val;
4218 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4220 attr->dw_attr_next = NULL;
4221 attr->dw_attr = attr_kind;
4222 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4223 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4224 add_dwarf_attr (die, attr);
4227 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4228 static inline unsigned long
4230 register dw_attr_ref a;
4232 if (a && AT_class (a) == dw_val_class_unsigned_const)
4233 return a->dw_attr_val.v.val_unsigned;
4238 /* Add an unsigned double integer attribute value to a DIE. */
4241 add_AT_long_long (die, attr_kind, val_hi, val_low)
4242 register dw_die_ref die;
4243 register enum dwarf_attribute attr_kind;
4244 register unsigned long val_hi;
4245 register unsigned long val_low;
4247 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4249 attr->dw_attr_next = NULL;
4250 attr->dw_attr = attr_kind;
4251 attr->dw_attr_val.val_class = dw_val_class_long_long;
4252 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4253 attr->dw_attr_val.v.val_long_long.low = val_low;
4254 add_dwarf_attr (die, attr);
4257 /* Add a floating point attribute value to a DIE and return it. */
4260 add_AT_float (die, attr_kind, length, array)
4261 register dw_die_ref die;
4262 register enum dwarf_attribute attr_kind;
4263 register unsigned length;
4264 register long *array;
4266 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4268 attr->dw_attr_next = NULL;
4269 attr->dw_attr = attr_kind;
4270 attr->dw_attr_val.val_class = dw_val_class_float;
4271 attr->dw_attr_val.v.val_float.length = length;
4272 attr->dw_attr_val.v.val_float.array = array;
4273 add_dwarf_attr (die, attr);
4276 /* Add a string attribute value to a DIE. */
4279 add_AT_string (die, attr_kind, str)
4280 register dw_die_ref die;
4281 register enum dwarf_attribute attr_kind;
4282 register const char *str;
4284 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4286 attr->dw_attr_next = NULL;
4287 attr->dw_attr = attr_kind;
4288 attr->dw_attr_val.val_class = dw_val_class_str;
4289 attr->dw_attr_val.v.val_str = xstrdup (str);
4290 add_dwarf_attr (die, attr);
4293 static inline const char *AT_string PARAMS ((dw_attr_ref));
4294 static inline const char *
4296 register dw_attr_ref a;
4298 if (a && AT_class (a) == dw_val_class_str)
4299 return a->dw_attr_val.v.val_str;
4304 /* Add a DIE reference attribute value to a DIE. */
4307 add_AT_die_ref (die, attr_kind, targ_die)
4308 register dw_die_ref die;
4309 register enum dwarf_attribute attr_kind;
4310 register dw_die_ref targ_die;
4312 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4314 attr->dw_attr_next = NULL;
4315 attr->dw_attr = attr_kind;
4316 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4317 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4318 attr->dw_attr_val.v.val_die_ref.external = 0;
4319 add_dwarf_attr (die, attr);
4322 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4323 static inline dw_die_ref
4325 register dw_attr_ref a;
4327 if (a && AT_class (a) == dw_val_class_die_ref)
4328 return a->dw_attr_val.v.val_die_ref.die;
4333 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4336 register dw_attr_ref a;
4338 if (a && AT_class (a) == dw_val_class_die_ref)
4339 return a->dw_attr_val.v.val_die_ref.external;
4344 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4346 set_AT_ref_external (a, i)
4347 register dw_attr_ref a;
4350 if (a && AT_class (a) == dw_val_class_die_ref)
4351 a->dw_attr_val.v.val_die_ref.external = i;
4356 /* Add an FDE reference attribute value to a DIE. */
4359 add_AT_fde_ref (die, attr_kind, targ_fde)
4360 register dw_die_ref die;
4361 register enum dwarf_attribute attr_kind;
4362 register unsigned targ_fde;
4364 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4366 attr->dw_attr_next = NULL;
4367 attr->dw_attr = attr_kind;
4368 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4369 attr->dw_attr_val.v.val_fde_index = targ_fde;
4370 add_dwarf_attr (die, attr);
4373 /* Add a location description attribute value to a DIE. */
4376 add_AT_loc (die, attr_kind, loc)
4377 register dw_die_ref die;
4378 register enum dwarf_attribute attr_kind;
4379 register dw_loc_descr_ref loc;
4381 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4383 attr->dw_attr_next = NULL;
4384 attr->dw_attr = attr_kind;
4385 attr->dw_attr_val.val_class = dw_val_class_loc;
4386 attr->dw_attr_val.v.val_loc = loc;
4387 add_dwarf_attr (die, attr);
4390 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4391 static inline dw_loc_descr_ref
4393 register dw_attr_ref a;
4395 if (a && AT_class (a) == dw_val_class_loc)
4396 return a->dw_attr_val.v.val_loc;
4401 /* Add an address constant attribute value to a DIE. */
4404 add_AT_addr (die, attr_kind, addr)
4405 register dw_die_ref die;
4406 register enum dwarf_attribute attr_kind;
4409 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4411 attr->dw_attr_next = NULL;
4412 attr->dw_attr = attr_kind;
4413 attr->dw_attr_val.val_class = dw_val_class_addr;
4414 attr->dw_attr_val.v.val_addr = addr;
4415 add_dwarf_attr (die, attr);
4418 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4421 register dw_attr_ref a;
4423 if (a && AT_class (a) == dw_val_class_addr)
4424 return a->dw_attr_val.v.val_addr;
4429 /* Add a label identifier attribute value to a DIE. */
4432 add_AT_lbl_id (die, attr_kind, lbl_id)
4433 register dw_die_ref die;
4434 register enum dwarf_attribute attr_kind;
4435 register const char *lbl_id;
4437 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4439 attr->dw_attr_next = NULL;
4440 attr->dw_attr = attr_kind;
4441 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4442 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4443 add_dwarf_attr (die, attr);
4446 /* Add a section offset attribute value to a DIE. */
4449 add_AT_lbl_offset (die, attr_kind, label)
4450 register dw_die_ref die;
4451 register enum dwarf_attribute attr_kind;
4452 register const char *label;
4454 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4456 attr->dw_attr_next = NULL;
4457 attr->dw_attr = attr_kind;
4458 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4459 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4460 add_dwarf_attr (die, attr);
4463 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4464 static inline const char *
4466 register dw_attr_ref a;
4468 if (a && (AT_class (a) == dw_val_class_lbl_id
4469 || AT_class (a) == dw_val_class_lbl_offset))
4470 return a->dw_attr_val.v.val_lbl_id;
4475 /* Get the attribute of type attr_kind. */
4477 static inline dw_attr_ref
4478 get_AT (die, attr_kind)
4479 register dw_die_ref die;
4480 register enum dwarf_attribute attr_kind;
4482 register dw_attr_ref a;
4483 register dw_die_ref spec = NULL;
4487 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4489 if (a->dw_attr == attr_kind)
4492 if (a->dw_attr == DW_AT_specification
4493 || a->dw_attr == DW_AT_abstract_origin)
4498 return get_AT (spec, attr_kind);
4504 /* Return the "low pc" attribute value, typically associated with
4505 a subprogram DIE. Return null if the "low pc" attribute is
4506 either not prsent, or if it cannot be represented as an
4507 assembler label identifier. */
4509 static inline const char *
4511 register dw_die_ref die;
4513 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4514 return a ? AT_lbl (a) : NULL;
4517 /* Return the "high pc" attribute value, typically associated with
4518 a subprogram DIE. Return null if the "high pc" attribute is
4519 either not prsent, or if it cannot be represented as an
4520 assembler label identifier. */
4522 static inline const char *
4524 register dw_die_ref die;
4526 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4527 return a ? AT_lbl (a) : NULL;
4530 /* Return the value of the string attribute designated by ATTR_KIND, or
4531 NULL if it is not present. */
4533 static inline const char *
4534 get_AT_string (die, attr_kind)
4535 register dw_die_ref die;
4536 register enum dwarf_attribute attr_kind;
4538 register dw_attr_ref a = get_AT (die, attr_kind);
4539 return a ? AT_string (a) : NULL;
4542 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4543 if it is not present. */
4546 get_AT_flag (die, attr_kind)
4547 register dw_die_ref die;
4548 register enum dwarf_attribute attr_kind;
4550 register dw_attr_ref a = get_AT (die, attr_kind);
4551 return a ? AT_flag (a) : 0;
4554 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4555 if it is not present. */
4557 static inline unsigned
4558 get_AT_unsigned (die, attr_kind)
4559 register dw_die_ref die;
4560 register enum dwarf_attribute attr_kind;
4562 register dw_attr_ref a = get_AT (die, attr_kind);
4563 return a ? AT_unsigned (a) : 0;
4566 static inline dw_die_ref
4567 get_AT_ref (die, attr_kind)
4569 register enum dwarf_attribute attr_kind;
4571 register dw_attr_ref a = get_AT (die, attr_kind);
4572 return a ? AT_ref (a) : NULL;
4578 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4580 return (lang == DW_LANG_C || lang == DW_LANG_C89
4581 || lang == DW_LANG_C_plus_plus);
4587 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4589 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4595 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4597 return (lang == DW_LANG_Java);
4600 /* Free up the memory used by A. */
4602 static inline void free_AT PARAMS ((dw_attr_ref));
4607 switch (AT_class (a))
4609 case dw_val_class_str:
4610 case dw_val_class_lbl_id:
4611 case dw_val_class_lbl_offset:
4612 free (a->dw_attr_val.v.val_str);
4622 /* Remove the specified attribute if present. */
4625 remove_AT (die, attr_kind)
4626 register dw_die_ref die;
4627 register enum dwarf_attribute attr_kind;
4629 register dw_attr_ref *p;
4630 register dw_attr_ref removed = NULL;
4634 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4635 if ((*p)->dw_attr == attr_kind)
4638 *p = (*p)->dw_attr_next;
4647 /* Free up the memory used by DIE. */
4649 static inline void free_die PARAMS ((dw_die_ref));
4654 remove_children (die);
4658 /* Discard the children of this DIE. */
4661 remove_children (die)
4662 register dw_die_ref die;
4664 register dw_die_ref child_die = die->die_child;
4666 die->die_child = NULL;
4668 while (child_die != NULL)
4670 register dw_die_ref tmp_die = child_die;
4671 register dw_attr_ref a;
4673 child_die = child_die->die_sib;
4675 for (a = tmp_die->die_attr; a != NULL;)
4677 register dw_attr_ref tmp_a = a;
4679 a = a->dw_attr_next;
4687 /* Add a child DIE below its parent. We build the lists up in reverse
4688 addition order, and correct that in reverse_all_dies. */
4691 add_child_die (die, child_die)
4692 register dw_die_ref die;
4693 register dw_die_ref child_die;
4695 if (die != NULL && child_die != NULL)
4697 if (die == child_die)
4699 child_die->die_parent = die;
4700 child_die->die_sib = die->die_child;
4701 die->die_child = child_die;
4705 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4706 is the specification, to the front of PARENT's list of children. */
4709 splice_child_die (parent, child)
4710 dw_die_ref parent, child;
4714 /* We want the declaration DIE from inside the class, not the
4715 specification DIE at toplevel. */
4716 if (child->die_parent != parent)
4718 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4723 if (child->die_parent != parent
4724 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4727 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4730 *p = child->die_sib;
4734 child->die_sib = parent->die_child;
4735 parent->die_child = child;
4738 /* Return a pointer to a newly created DIE node. */
4740 static inline dw_die_ref
4741 new_die (tag_value, parent_die)
4742 register enum dwarf_tag tag_value;
4743 register dw_die_ref parent_die;
4745 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4747 die->die_tag = tag_value;
4748 die->die_abbrev = 0;
4749 die->die_offset = 0;
4750 die->die_child = NULL;
4751 die->die_parent = NULL;
4752 die->die_sib = NULL;
4753 die->die_attr = NULL;
4754 die->die_symbol = NULL;
4756 if (parent_die != NULL)
4757 add_child_die (parent_die, die);
4760 limbo_die_node *limbo_node;
4762 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4763 limbo_node->die = die;
4764 limbo_node->next = limbo_die_list;
4765 limbo_die_list = limbo_node;
4771 /* Return the DIE associated with the given type specifier. */
4773 static inline dw_die_ref
4774 lookup_type_die (type)
4777 if (TREE_CODE (type) == VECTOR_TYPE)
4778 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4779 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4782 /* Equate a DIE to a given type specifier. */
4785 equate_type_number_to_die (type, type_die)
4787 register dw_die_ref type_die;
4789 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4792 /* Return the DIE associated with a given declaration. */
4794 static inline dw_die_ref
4795 lookup_decl_die (decl)
4798 register unsigned decl_id = DECL_UID (decl);
4800 return (decl_id < decl_die_table_in_use
4801 ? decl_die_table[decl_id] : NULL);
4804 /* Equate a DIE to a particular declaration. */
4807 equate_decl_number_to_die (decl, decl_die)
4809 register dw_die_ref decl_die;
4811 register unsigned decl_id = DECL_UID (decl);
4812 register unsigned num_allocated;
4814 if (decl_id >= decl_die_table_allocated)
4817 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4818 / DECL_DIE_TABLE_INCREMENT)
4819 * DECL_DIE_TABLE_INCREMENT;
4822 = (dw_die_ref *) xrealloc (decl_die_table,
4823 sizeof (dw_die_ref) * num_allocated);
4825 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4826 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4827 decl_die_table_allocated = num_allocated;
4830 if (decl_id >= decl_die_table_in_use)
4831 decl_die_table_in_use = (decl_id + 1);
4833 decl_die_table[decl_id] = decl_die;
4836 /* Keep track of the number of spaces used to indent the
4837 output of the debugging routines that print the structure of
4838 the DIE internal representation. */
4839 static int print_indent;
4841 /* Indent the line the number of spaces given by print_indent. */
4844 print_spaces (outfile)
4847 fprintf (outfile, "%*s", print_indent, "");
4850 /* Print the information associated with a given DIE, and its children.
4851 This routine is a debugging aid only. */
4854 print_die (die, outfile)
4858 register dw_attr_ref a;
4859 register dw_die_ref c;
4861 print_spaces (outfile);
4862 fprintf (outfile, "DIE %4lu: %s\n",
4863 die->die_offset, dwarf_tag_name (die->die_tag));
4864 print_spaces (outfile);
4865 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4866 fprintf (outfile, " offset: %lu\n", die->die_offset);
4868 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4870 print_spaces (outfile);
4871 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4873 switch (AT_class (a))
4875 case dw_val_class_addr:
4876 fprintf (outfile, "address");
4878 case dw_val_class_loc:
4879 fprintf (outfile, "location descriptor");
4881 case dw_val_class_const:
4882 fprintf (outfile, "%ld", AT_int (a));
4884 case dw_val_class_unsigned_const:
4885 fprintf (outfile, "%lu", AT_unsigned (a));
4887 case dw_val_class_long_long:
4888 fprintf (outfile, "constant (%lu,%lu)",
4889 a->dw_attr_val.v.val_long_long.hi,
4890 a->dw_attr_val.v.val_long_long.low);
4892 case dw_val_class_float:
4893 fprintf (outfile, "floating-point constant");
4895 case dw_val_class_flag:
4896 fprintf (outfile, "%u", AT_flag (a));
4898 case dw_val_class_die_ref:
4899 if (AT_ref (a) != NULL)
4901 if (AT_ref (a)->die_offset == 0)
4902 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
4904 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4907 fprintf (outfile, "die -> <null>");
4909 case dw_val_class_lbl_id:
4910 case dw_val_class_lbl_offset:
4911 fprintf (outfile, "label: %s", AT_lbl (a));
4913 case dw_val_class_str:
4914 if (AT_string (a) != NULL)
4915 fprintf (outfile, "\"%s\"", AT_string (a));
4917 fprintf (outfile, "<null>");
4923 fprintf (outfile, "\n");
4926 if (die->die_child != NULL)
4929 for (c = die->die_child; c != NULL; c = c->die_sib)
4930 print_die (c, outfile);
4934 if (print_indent == 0)
4935 fprintf (outfile, "\n");
4938 /* Print the contents of the source code line number correspondence table.
4939 This routine is a debugging aid only. */
4942 print_dwarf_line_table (outfile)
4945 register unsigned i;
4946 register dw_line_info_ref line_info;
4948 fprintf (outfile, "\n\nDWARF source line information\n");
4949 for (i = 1; i < line_info_table_in_use; ++i)
4951 line_info = &line_info_table[i];
4952 fprintf (outfile, "%5d: ", i);
4953 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4954 fprintf (outfile, "%6ld", line_info->dw_line_num);
4955 fprintf (outfile, "\n");
4958 fprintf (outfile, "\n\n");
4961 /* Print the information collected for a given DIE. */
4964 debug_dwarf_die (die)
4967 print_die (die, stderr);
4970 /* Print all DWARF information collected for the compilation unit.
4971 This routine is a debugging aid only. */
4977 print_die (comp_unit_die, stderr);
4978 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4979 print_dwarf_line_table (stderr);
4982 /* We build up the lists of children and attributes by pushing new ones
4983 onto the beginning of the list. Reverse the lists for DIE so that
4984 they are in order of addition. */
4987 reverse_die_lists (die)
4988 register dw_die_ref die;
4990 register dw_die_ref c, cp, cn;
4991 register dw_attr_ref a, ap, an;
4993 for (a = die->die_attr, ap = 0; a; a = an)
4995 an = a->dw_attr_next;
4996 a->dw_attr_next = ap;
5001 for (c = die->die_child, cp = 0; c; c = cn)
5007 die->die_child = cp;
5010 /* reverse_die_lists only reverses the single die you pass it. Since
5011 we used to reverse all dies in add_sibling_attributes, which runs
5012 through all the dies, it would reverse all the dies. Now, however,
5013 since we don't call reverse_die_lists in add_sibling_attributes, we
5014 need a routine to recursively reverse all the dies. This is that
5018 reverse_all_dies (die)
5019 register dw_die_ref die;
5021 register dw_die_ref c;
5023 reverse_die_lists (die);
5025 for (c = die->die_child; c; c = c->die_sib)
5026 reverse_all_dies (c);
5029 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5030 the CU for the enclosing include file, if any. BINCL_DIE is the
5031 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5035 push_new_compile_unit (old_unit, bincl_die)
5036 dw_die_ref old_unit, bincl_die;
5038 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5039 dw_die_ref new_unit = gen_compile_unit_die (filename);
5040 new_unit->die_sib = old_unit;
5044 /* Close an include-file CU and reopen the enclosing one. */
5047 pop_compile_unit (old_unit)
5048 dw_die_ref old_unit;
5050 dw_die_ref new_unit = old_unit->die_sib;
5051 old_unit->die_sib = NULL;
5055 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5056 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5058 /* Calculate the checksum of a location expression. */
5061 loc_checksum (loc, ctx)
5062 dw_loc_descr_ref loc;
5063 struct md5_ctx *ctx;
5065 PROCESS (loc->dw_loc_opc);
5066 PROCESS (loc->dw_loc_oprnd1);
5067 PROCESS (loc->dw_loc_oprnd2);
5070 /* Calculate the checksum of an attribute. */
5073 attr_checksum (at, ctx)
5075 struct md5_ctx *ctx;
5077 dw_loc_descr_ref loc;
5080 PROCESS (at->dw_attr);
5082 /* We don't care about differences in file numbering. */
5083 if (at->dw_attr == DW_AT_decl_file
5084 /* Or that this was compiled with a different compiler snapshot; if
5085 the output is the same, that's what matters. */
5086 || at->dw_attr == DW_AT_producer)
5089 switch (AT_class (at))
5091 case dw_val_class_const:
5092 PROCESS (at->dw_attr_val.v.val_int);
5094 case dw_val_class_unsigned_const:
5095 PROCESS (at->dw_attr_val.v.val_unsigned);
5097 case dw_val_class_long_long:
5098 PROCESS (at->dw_attr_val.v.val_long_long);
5100 case dw_val_class_float:
5101 PROCESS (at->dw_attr_val.v.val_float);
5103 case dw_val_class_flag:
5104 PROCESS (at->dw_attr_val.v.val_flag);
5107 case dw_val_class_str:
5108 PROCESS_STRING (AT_string (at));
5110 case dw_val_class_addr:
5112 switch (GET_CODE (r))
5115 PROCESS_STRING (XSTR (r, 0));
5123 case dw_val_class_loc:
5124 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5125 loc_checksum (loc, ctx);
5128 case dw_val_class_die_ref:
5129 if (AT_ref (at)->die_offset)
5130 PROCESS (AT_ref (at)->die_offset);
5131 /* FIXME else use target die name or something. */
5133 case dw_val_class_fde_ref:
5134 case dw_val_class_lbl_id:
5135 case dw_val_class_lbl_offset:
5142 /* Calculate the checksum of a DIE. */
5145 die_checksum (die, ctx)
5147 struct md5_ctx *ctx;
5152 PROCESS (die->die_tag);
5154 for (a = die->die_attr; a; a = a->dw_attr_next)
5155 attr_checksum (a, ctx);
5157 for (c = die->die_child; c; c = c->die_sib)
5158 die_checksum (c, ctx);
5162 #undef PROCESS_STRING
5164 /* The prefix to attach to symbols on DIEs in the current comdat debug
5166 static char *comdat_symbol_id;
5168 /* The index of the current symbol within the current comdat CU. */
5169 static unsigned int comdat_symbol_number;
5171 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5172 children, and set comdat_symbol_id accordingly. */
5175 compute_section_prefix (unit_die)
5176 dw_die_ref unit_die;
5180 unsigned char checksum[16];
5183 md5_init_ctx (&ctx);
5184 die_checksum (unit_die, &ctx);
5185 md5_finish_ctx (&ctx, checksum);
5187 p = file_name_nondirectory (get_AT_string (unit_die, DW_AT_name));
5188 name = (char *) alloca (strlen (p) + 64);
5189 sprintf (name, "%s.", p);
5191 clean_symbol_name (name);
5193 p = name + strlen (name);
5194 for (i = 0; i < 4; ++i)
5196 sprintf (p, "%.2x", checksum[i]);
5200 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5201 comdat_symbol_number = 0;
5204 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5210 switch (die->die_tag)
5212 case DW_TAG_array_type:
5213 case DW_TAG_class_type:
5214 case DW_TAG_enumeration_type:
5215 case DW_TAG_pointer_type:
5216 case DW_TAG_reference_type:
5217 case DW_TAG_string_type:
5218 case DW_TAG_structure_type:
5219 case DW_TAG_subroutine_type:
5220 case DW_TAG_union_type:
5221 case DW_TAG_ptr_to_member_type:
5222 case DW_TAG_set_type:
5223 case DW_TAG_subrange_type:
5224 case DW_TAG_base_type:
5225 case DW_TAG_const_type:
5226 case DW_TAG_file_type:
5227 case DW_TAG_packed_type:
5228 case DW_TAG_volatile_type:
5235 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5236 Basically, we want to choose the bits that are likely to be shared between
5237 compilations (types) and leave out the bits that are specific to individual
5238 compilations (functions). */
5245 /* I think we want to leave base types and __vtbl_ptr_type in the
5246 main CU, as we do for stabs. The advantage is a greater
5247 likelihood of sharing between objects that don't include headers
5248 in the same order (and therefore would put the base types in a
5249 different comdat). jason 8/28/00 */
5250 if (c->die_tag == DW_TAG_base_type)
5253 if (c->die_tag == DW_TAG_pointer_type
5254 || c->die_tag == DW_TAG_reference_type
5255 || c->die_tag == DW_TAG_const_type
5256 || c->die_tag == DW_TAG_volatile_type)
5258 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5259 return t ? is_comdat_die (t) : 0;
5263 return is_type_die (c);
5266 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5267 compilation unit. */
5273 if (is_type_die (c))
5275 if (get_AT (c, DW_AT_declaration)
5276 && ! get_AT (c, DW_AT_specification))
5285 static int label_num;
5286 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5287 return xstrdup (buf);
5290 /* Assign symbols to all worthy DIEs under DIE. */
5293 assign_symbol_names (die)
5294 register dw_die_ref die;
5296 register dw_die_ref c;
5298 if (is_symbol_die (die))
5300 if (comdat_symbol_id)
5302 char *p = alloca (strlen (comdat_symbol_id) + 64);
5303 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5304 comdat_symbol_id, comdat_symbol_number++);
5305 die->die_symbol = xstrdup (p);
5308 die->die_symbol = gen_internal_sym ();
5311 for (c = die->die_child; c != NULL; c = c->die_sib)
5312 assign_symbol_names (c);
5315 /* Traverse the DIE (which is always comp_unit_die), and set up
5316 additional compilation units for each of the include files we see
5317 bracketed by BINCL/EINCL. */
5320 break_out_includes (die)
5321 register dw_die_ref die;
5324 register dw_die_ref unit = NULL;
5325 limbo_die_node *node;
5327 for (ptr = &(die->die_child); *ptr; )
5329 register dw_die_ref c = *ptr;
5331 if (c->die_tag == DW_TAG_GNU_BINCL
5332 || c->die_tag == DW_TAG_GNU_EINCL
5333 || (unit && is_comdat_die (c)))
5335 /* This DIE is for a secondary CU; remove it from the main one. */
5338 if (c->die_tag == DW_TAG_GNU_BINCL)
5340 unit = push_new_compile_unit (unit, c);
5343 else if (c->die_tag == DW_TAG_GNU_EINCL)
5345 unit = pop_compile_unit (unit);
5349 add_child_die (unit, c);
5353 /* Leave this DIE in the main CU. */
5354 ptr = &(c->die_sib);
5360 /* We can only use this in debugging, since the frontend doesn't check
5361 to make sure that we leave every include file we enter. */
5366 assign_symbol_names (die);
5367 for (node = limbo_die_list; node; node = node->next)
5369 compute_section_prefix (node->die);
5370 assign_symbol_names (node->die);
5374 /* Traverse the DIE and add a sibling attribute if it may have the
5375 effect of speeding up access to siblings. To save some space,
5376 avoid generating sibling attributes for DIE's without children. */
5379 add_sibling_attributes (die)
5380 register dw_die_ref die;
5382 register dw_die_ref c;
5384 if (die->die_tag != DW_TAG_compile_unit
5385 && die->die_sib && die->die_child != NULL)
5386 /* Add the sibling link to the front of the attribute list. */
5387 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5389 for (c = die->die_child; c != NULL; c = c->die_sib)
5390 add_sibling_attributes (c);
5393 /* The format of each DIE (and its attribute value pairs)
5394 is encoded in an abbreviation table. This routine builds the
5395 abbreviation table and assigns a unique abbreviation id for
5396 each abbreviation entry. The children of each die are visited
5400 build_abbrev_table (die)
5401 register dw_die_ref die;
5403 register unsigned long abbrev_id;
5404 register unsigned long n_alloc;
5405 register dw_die_ref c;
5406 register dw_attr_ref d_attr, a_attr;
5408 /* Scan the DIE references, and mark as external any that refer to
5409 DIEs from other CUs (i.e. those with cleared die_offset). */
5410 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5412 if (AT_class (d_attr) == dw_val_class_die_ref
5413 && AT_ref (d_attr)->die_offset == 0)
5415 if (AT_ref (d_attr)->die_symbol == 0)
5417 set_AT_ref_external (d_attr, 1);
5421 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5423 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5425 if (abbrev->die_tag == die->die_tag)
5427 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5429 a_attr = abbrev->die_attr;
5430 d_attr = die->die_attr;
5432 while (a_attr != NULL && d_attr != NULL)
5434 if ((a_attr->dw_attr != d_attr->dw_attr)
5435 || (value_format (a_attr) != value_format (d_attr)))
5438 a_attr = a_attr->dw_attr_next;
5439 d_attr = d_attr->dw_attr_next;
5442 if (a_attr == NULL && d_attr == NULL)
5448 if (abbrev_id >= abbrev_die_table_in_use)
5450 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5452 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5454 = (dw_die_ref *) xrealloc (abbrev_die_table,
5455 sizeof (dw_die_ref) * n_alloc);
5457 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
5458 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5459 abbrev_die_table_allocated = n_alloc;
5462 ++abbrev_die_table_in_use;
5463 abbrev_die_table[abbrev_id] = die;
5466 die->die_abbrev = abbrev_id;
5467 for (c = die->die_child; c != NULL; c = c->die_sib)
5468 build_abbrev_table (c);
5471 /* Return the size of a string, including the null byte.
5473 This used to treat backslashes as escapes, and hence they were not included
5474 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5475 which treats a backslash as a backslash, escaping it if necessary, and hence
5476 we must include them in the count. */
5478 static unsigned long
5479 size_of_string (str)
5480 register const char *str;
5482 return strlen (str) + 1;
5485 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5488 constant_size (value)
5489 long unsigned value;
5496 log = floor_log2 (value);
5499 log = 1 << (floor_log2 (log) + 1);
5504 /* Return the size of a DIE, as it is represented in the
5505 .debug_info section. */
5507 static unsigned long
5509 register dw_die_ref die;
5511 register unsigned long size = 0;
5512 register dw_attr_ref a;
5514 size += size_of_uleb128 (die->die_abbrev);
5515 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5517 switch (AT_class (a))
5519 case dw_val_class_addr:
5520 size += DWARF2_ADDR_SIZE;
5522 case dw_val_class_loc:
5524 register unsigned long lsize = size_of_locs (AT_loc (a));
5527 size += constant_size (lsize);
5531 case dw_val_class_const:
5532 size += size_of_sleb128 (AT_int (a));
5534 case dw_val_class_unsigned_const:
5535 size += constant_size (AT_unsigned (a));
5537 case dw_val_class_long_long:
5538 size += 1 + 8; /* block */
5540 case dw_val_class_float:
5541 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5543 case dw_val_class_flag:
5546 case dw_val_class_die_ref:
5547 size += DWARF_OFFSET_SIZE;
5549 case dw_val_class_fde_ref:
5550 size += DWARF_OFFSET_SIZE;
5552 case dw_val_class_lbl_id:
5553 size += DWARF2_ADDR_SIZE;
5555 case dw_val_class_lbl_offset:
5556 size += DWARF_OFFSET_SIZE;
5558 case dw_val_class_str:
5559 size += size_of_string (AT_string (a));
5569 /* Size the debugging information associated with a given DIE.
5570 Visits the DIE's children recursively. Updates the global
5571 variable next_die_offset, on each time through. Uses the
5572 current value of next_die_offset to update the die_offset
5573 field in each DIE. */
5576 calc_die_sizes (die)
5579 register dw_die_ref c;
5580 die->die_offset = next_die_offset;
5581 next_die_offset += size_of_die (die);
5583 for (c = die->die_child; c != NULL; c = c->die_sib)
5586 if (die->die_child != NULL)
5587 /* Count the null byte used to terminate sibling lists. */
5588 next_die_offset += 1;
5591 /* Clear the offsets and sizes for a die and its children. We do this so
5592 that we know whether or not a reference needs to use FORM_ref_addr; only
5593 DIEs in the same CU will have non-zero offsets available. */
5596 clear_die_sizes (die)
5599 register dw_die_ref c;
5600 die->die_offset = 0;
5601 for (c = die->die_child; c; c = c->die_sib)
5602 clear_die_sizes (c);
5605 /* Return the size of the line information prolog generated for the
5606 compilation unit. */
5608 static unsigned long
5609 size_of_line_prolog ()
5611 register unsigned long size;
5612 register unsigned long ft_index;
5614 size = DWARF_LINE_PROLOG_HEADER_SIZE;
5616 /* Count the size of the table giving number of args for each
5618 size += DWARF_LINE_OPCODE_BASE - 1;
5620 /* Include directory table is empty (at present). Count only the
5621 null byte used to terminate the table. */
5624 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5626 /* File name entry. */
5627 size += size_of_string (file_table[ft_index]);
5629 /* Include directory index. */
5630 size += size_of_uleb128 (0);
5632 /* Modification time. */
5633 size += size_of_uleb128 (0);
5635 /* File length in bytes. */
5636 size += size_of_uleb128 (0);
5639 /* Count the file table terminator. */
5644 /* Return the size of the .debug_pubnames table generated for the
5645 compilation unit. */
5647 static unsigned long
5650 register unsigned long size;
5651 register unsigned i;
5653 size = DWARF_PUBNAMES_HEADER_SIZE;
5654 for (i = 0; i < pubname_table_in_use; ++i)
5656 register pubname_ref p = &pubname_table[i];
5657 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5660 size += DWARF_OFFSET_SIZE;
5664 /* Return the size of the information in the .debug_aranges section. */
5666 static unsigned long
5669 register unsigned long size;
5671 size = DWARF_ARANGES_HEADER_SIZE;
5673 /* Count the address/length pair for this compilation unit. */
5674 size += 2 * DWARF2_ADDR_SIZE;
5675 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5677 /* Count the two zero words used to terminated the address range table. */
5678 size += 2 * DWARF2_ADDR_SIZE;
5682 /* Select the encoding of an attribute value. */
5684 static enum dwarf_form
5688 switch (a->dw_attr_val.val_class)
5690 case dw_val_class_addr:
5691 return DW_FORM_addr;
5692 case dw_val_class_loc:
5693 switch (constant_size (size_of_locs (AT_loc (a))))
5696 return DW_FORM_block1;
5698 return DW_FORM_block2;
5702 case dw_val_class_const:
5703 return DW_FORM_sdata;
5704 case dw_val_class_unsigned_const:
5705 switch (constant_size (AT_unsigned (a)))
5708 return DW_FORM_data1;
5710 return DW_FORM_data2;
5712 return DW_FORM_data4;
5714 return DW_FORM_data8;
5718 case dw_val_class_long_long:
5719 return DW_FORM_block1;
5720 case dw_val_class_float:
5721 return DW_FORM_block1;
5722 case dw_val_class_flag:
5723 return DW_FORM_flag;
5724 case dw_val_class_die_ref:
5725 if (AT_ref_external (a))
5726 return DW_FORM_ref_addr;
5729 case dw_val_class_fde_ref:
5730 return DW_FORM_data;
5731 case dw_val_class_lbl_id:
5732 return DW_FORM_addr;
5733 case dw_val_class_lbl_offset:
5734 return DW_FORM_data;
5735 case dw_val_class_str:
5736 return DW_FORM_string;
5742 /* Output the encoding of an attribute value. */
5745 output_value_format (a)
5748 enum dwarf_form form = value_format (a);
5750 output_uleb128 (form);
5752 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
5754 fputc ('\n', asm_out_file);
5757 /* Output the .debug_abbrev section which defines the DIE abbreviation
5761 output_abbrev_section ()
5763 unsigned long abbrev_id;
5766 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5768 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5770 output_uleb128 (abbrev_id);
5772 fprintf (asm_out_file, " (abbrev code)");
5774 fputc ('\n', asm_out_file);
5775 output_uleb128 (abbrev->die_tag);
5777 fprintf (asm_out_file, " (TAG: %s)",
5778 dwarf_tag_name (abbrev->die_tag));
5780 fputc ('\n', asm_out_file);
5781 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
5782 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
5785 fprintf (asm_out_file, "\t%s %s",
5787 (abbrev->die_child != NULL
5788 ? "DW_children_yes" : "DW_children_no"));
5790 fputc ('\n', asm_out_file);
5792 for (a_attr = abbrev->die_attr; a_attr != NULL;
5793 a_attr = a_attr->dw_attr_next)
5795 output_uleb128 (a_attr->dw_attr);
5797 fprintf (asm_out_file, " (%s)",
5798 dwarf_attr_name (a_attr->dw_attr));
5800 fputc ('\n', asm_out_file);
5801 output_value_format (a_attr);
5804 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
5807 /* Terminate the table. */
5808 fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP);
5811 /* Output a symbol we can use to refer to this DIE from another CU. */
5814 output_die_symbol (die)
5815 register dw_die_ref die;
5817 char *sym = die->die_symbol;
5822 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5823 /* We make these global, not weak; if the target doesn't support
5824 .linkonce, it doesn't support combining the sections, so debugging
5826 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5827 ASM_OUTPUT_LABEL (asm_out_file, sym);
5830 /* Output a symbolic (i.e. FORM_ref_addr) reference to TARGET_DIE. */
5833 output_symbolic_ref (target_die)
5834 dw_die_ref target_die;
5836 char *sym = target_die->die_symbol;
5841 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, sym);
5844 /* Output the DIE and its attributes. Called recursively to generate
5845 the definitions of each child DIE. */
5849 register dw_die_ref die;
5851 register dw_attr_ref a;
5852 register dw_die_ref c;
5853 register unsigned long size;
5855 /* If someone in another CU might refer to us, set up a symbol for
5856 them to point to. */
5857 if (die->die_symbol)
5858 output_die_symbol (die);
5860 output_uleb128 (die->die_abbrev);
5862 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5863 die->die_offset, dwarf_tag_name (die->die_tag));
5865 fputc ('\n', asm_out_file);
5867 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5869 switch (AT_class (a))
5871 case dw_val_class_addr:
5872 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
5875 case dw_val_class_loc:
5876 size = size_of_locs (AT_loc (a));
5878 /* Output the block length for this list of location operations. */
5879 switch (constant_size (size))
5882 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5885 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5892 fprintf (asm_out_file, "\t%s %s",
5893 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5895 fputc ('\n', asm_out_file);
5897 output_loc_sequence (AT_loc (a));
5900 case dw_val_class_const:
5901 /* ??? It would be slightly more efficient to use a scheme like is
5902 used for unsigned constants below, but gdb 4.x does not sign
5903 extend. Gdb 5.x does sign extend. */
5904 output_sleb128 (AT_int (a));
5907 case dw_val_class_unsigned_const:
5908 switch (constant_size (AT_unsigned (a)))
5911 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
5914 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
5917 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
5920 ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a));
5927 case dw_val_class_long_long:
5928 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5930 fprintf (asm_out_file, "\t%s %s",
5931 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5933 fputc ('\n', asm_out_file);
5934 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file,
5935 a->dw_attr_val.v.val_long_long.hi,
5936 a->dw_attr_val.v.val_long_long.low);
5939 fprintf (asm_out_file,
5940 "\t%s long long constant", ASM_COMMENT_START);
5942 fputc ('\n', asm_out_file);
5945 case dw_val_class_float:
5947 register unsigned int i;
5948 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5949 a->dw_attr_val.v.val_float.length * 4);
5951 fprintf (asm_out_file, "\t%s %s",
5952 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5954 fputc ('\n', asm_out_file);
5955 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5957 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5958 a->dw_attr_val.v.val_float.array[i]);
5960 fprintf (asm_out_file, "\t%s fp constant word %u",
5961 ASM_COMMENT_START, i);
5963 fputc ('\n', asm_out_file);
5968 case dw_val_class_flag:
5969 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
5972 case dw_val_class_die_ref:
5973 if (AT_ref_external (a))
5974 output_symbolic_ref (AT_ref (a));
5976 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
5979 case dw_val_class_fde_ref:
5982 ASM_GENERATE_INTERNAL_LABEL
5983 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5984 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5985 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5989 case dw_val_class_lbl_id:
5990 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
5993 case dw_val_class_lbl_offset:
5994 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
5997 case dw_val_class_str:
5999 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
6001 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
6002 (int) strlen (AT_string (a)) + 1);
6009 if (AT_class (a) != dw_val_class_loc
6010 && AT_class (a) != dw_val_class_long_long
6011 && AT_class (a) != dw_val_class_float)
6014 fprintf (asm_out_file, "\t%s %s",
6015 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6017 fputc ('\n', asm_out_file);
6021 for (c = die->die_child; c != NULL; c = c->die_sib)
6024 if (die->die_child != NULL)
6026 /* Add null byte to terminate sibling list. */
6027 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6029 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
6030 ASM_COMMENT_START, die->die_offset);
6032 fputc ('\n', asm_out_file);
6036 /* Output the compilation unit that appears at the beginning of the
6037 .debug_info section, and precedes the DIE descriptions. */
6040 output_compilation_unit_header ()
6042 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
6044 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
6047 fputc ('\n', asm_out_file);
6048 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6050 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
6052 fputc ('\n', asm_out_file);
6053 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
6055 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
6058 fputc ('\n', asm_out_file);
6059 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6061 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
6063 fputc ('\n', asm_out_file);
6066 /* Output the compilation unit DIE and its children. */
6069 output_comp_unit (die)
6074 if (die->die_child == 0)
6077 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6078 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6079 calc_die_sizes (die);
6081 build_abbrev_table (die);
6083 if (die->die_symbol)
6085 secname = (char *) alloca (strlen (die->die_symbol) + 24);
6086 sprintf (secname, ".gnu.linkonce.wi.%s", die->die_symbol);
6087 die->die_symbol = NULL;
6090 secname = (char *) DEBUG_INFO_SECTION;
6092 /* Output debugging information. */
6093 fputc ('\n', asm_out_file);
6094 ASM_OUTPUT_SECTION (asm_out_file, secname);
6095 output_compilation_unit_header ();
6098 /* Leave the sizes on the main CU, since we do it last and we use the
6099 sizes in output_pubnames. */
6100 if (die->die_symbol)
6101 clear_die_sizes (die);
6104 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6105 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6106 argument list, and maybe the scope. */
6109 dwarf2_name (decl, scope)
6113 return (*decl_printable_name) (decl, scope ? 1 : 0);
6116 /* Add a new entry to .debug_pubnames if appropriate. */
6119 add_pubname (decl, die)
6125 if (! TREE_PUBLIC (decl))
6128 if (pubname_table_in_use == pubname_table_allocated)
6130 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6131 pubname_table = (pubname_ref) xrealloc
6132 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6135 p = &pubname_table[pubname_table_in_use++];
6138 p->name = xstrdup (dwarf2_name (decl, 1));
6141 /* Output the public names table used to speed up access to externally
6142 visible names. For now, only generate entries for externally
6143 visible procedures. */
6148 register unsigned i;
6149 register unsigned long pubnames_length = size_of_pubnames ();
6151 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
6154 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
6157 fputc ('\n', asm_out_file);
6158 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6161 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6163 fputc ('\n', asm_out_file);
6164 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6166 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6169 fputc ('\n', asm_out_file);
6170 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
6172 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
6174 fputc ('\n', asm_out_file);
6175 for (i = 0; i < pubname_table_in_use; ++i)
6177 register pubname_ref pub = &pubname_table[i];
6179 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6180 if (pub->die->die_offset == 0)
6183 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
6185 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
6187 fputc ('\n', asm_out_file);
6191 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
6192 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
6196 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
6197 (int) strlen (pub->name) + 1);
6200 fputc ('\n', asm_out_file);
6203 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
6204 fputc ('\n', asm_out_file);
6207 /* Add a new entry to .debug_aranges if appropriate. */
6210 add_arange (decl, die)
6214 if (! DECL_SECTION_NAME (decl))
6217 if (arange_table_in_use == arange_table_allocated)
6219 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6221 = (arange_ref) xrealloc (arange_table,
6222 arange_table_allocated * sizeof (dw_die_ref));
6225 arange_table[arange_table_in_use++] = die;
6228 /* Output the information that goes into the .debug_aranges table.
6229 Namely, define the beginning and ending address range of the
6230 text section generated for this compilation unit. */
6235 register unsigned i;
6236 register unsigned long aranges_length = size_of_aranges ();
6238 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
6240 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
6243 fputc ('\n', asm_out_file);
6244 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6246 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6248 fputc ('\n', asm_out_file);
6249 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6251 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6254 fputc ('\n', asm_out_file);
6255 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6257 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
6259 fputc ('\n', asm_out_file);
6260 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6262 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
6265 fputc ('\n', asm_out_file);
6267 /* We need to align to twice the pointer size here. */
6268 if (DWARF_ARANGES_PAD_SIZE)
6270 /* Pad using a 2 bytes word so that padding is correct
6271 for any pointer size. */
6272 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
6273 for (i = 2; i < DWARF_ARANGES_PAD_SIZE; i += 2)
6274 fprintf (asm_out_file, ",0");
6276 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
6277 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
6280 fputc ('\n', asm_out_file);
6281 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
6283 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6285 fputc ('\n', asm_out_file);
6286 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
6287 text_section_label);
6289 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6291 fputc ('\n', asm_out_file);
6292 for (i = 0; i < arange_table_in_use; ++i)
6294 dw_die_ref die = arange_table[i];
6296 /* We shouldn't see aranges for DIEs outside of the main CU. */
6297 if (die->die_offset == 0)
6300 if (die->die_tag == DW_TAG_subprogram)
6301 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
6304 /* A static variable; extract the symbol from DW_AT_location.
6305 Note that this code isn't currently hit, as we only emit
6306 aranges for functions (jason 9/23/99). */
6308 dw_attr_ref a = get_AT (die, DW_AT_location);
6309 dw_loc_descr_ref loc;
6310 if (! a || AT_class (a) != dw_val_class_loc)
6314 if (loc->dw_loc_opc != DW_OP_addr)
6317 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
6318 loc->dw_loc_oprnd1.v.val_addr);
6322 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6324 fputc ('\n', asm_out_file);
6325 if (die->die_tag == DW_TAG_subprogram)
6326 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
6327 get_AT_low_pc (die));
6329 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
6330 get_AT_unsigned (die, DW_AT_byte_size));
6333 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6335 fputc ('\n', asm_out_file);
6338 /* Output the terminator words. */
6339 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6340 fputc ('\n', asm_out_file);
6341 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6342 fputc ('\n', asm_out_file);
6345 /* Output the source line number correspondence information. This
6346 information goes into the .debug_line section. */
6351 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6352 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6353 register unsigned opc;
6354 register unsigned n_op_args;
6355 register unsigned long ft_index;
6356 register unsigned long lt_index;
6357 register unsigned long current_line;
6358 register long line_offset;
6359 register long line_delta;
6360 register unsigned long current_file;
6361 register unsigned long function;
6363 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
6365 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
6368 fputc ('\n', asm_out_file);
6369 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
6370 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6372 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6374 fputc ('\n', asm_out_file);
6375 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
6377 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
6379 fputc ('\n', asm_out_file);
6380 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
6382 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
6385 fputc ('\n', asm_out_file);
6386 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
6388 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
6391 fputc ('\n', asm_out_file);
6392 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
6394 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
6397 fputc ('\n', asm_out_file);
6398 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
6400 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
6403 fputc ('\n', asm_out_file);
6404 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
6406 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
6408 fputc ('\n', asm_out_file);
6409 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6413 case DW_LNS_advance_pc:
6414 case DW_LNS_advance_line:
6415 case DW_LNS_set_file:
6416 case DW_LNS_set_column:
6417 case DW_LNS_fixed_advance_pc:
6424 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
6426 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
6427 ASM_COMMENT_START, opc, n_op_args);
6428 fputc ('\n', asm_out_file);
6432 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
6434 /* Include directory table is empty, at present */
6435 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6436 fputc ('\n', asm_out_file);
6438 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
6440 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
6444 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
6445 fprintf (asm_out_file, "%s File Entry: 0x%lx",
6446 ASM_COMMENT_START, ft_index);
6450 ASM_OUTPUT_ASCII (asm_out_file,
6451 file_table[ft_index],
6452 (int) strlen (file_table[ft_index]) + 1);
6455 fputc ('\n', asm_out_file);
6457 /* Include directory index */
6459 fputc ('\n', asm_out_file);
6461 /* Modification time */
6463 fputc ('\n', asm_out_file);
6465 /* File length in bytes */
6467 fputc ('\n', asm_out_file);
6470 /* Terminate the file name table */
6471 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6472 fputc ('\n', asm_out_file);
6474 /* We used to set the address register to the first location in the text
6475 section here, but that didn't accomplish anything since we already
6476 have a line note for the opening brace of the first function. */
6478 /* Generate the line number to PC correspondence table, encoded as
6479 a series of state machine operations. */
6482 strcpy (prev_line_label, text_section_label);
6483 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6485 register dw_line_info_ref line_info = &line_info_table[lt_index];
6488 /* Disable this optimization for now; GDB wants to see two line notes
6489 at the beginning of a function so it can find the end of the
6492 /* Don't emit anything for redundant notes. Just updating the
6493 address doesn't accomplish anything, because we already assume
6494 that anything after the last address is this line. */
6495 if (line_info->dw_line_num == current_line
6496 && line_info->dw_file_num == current_file)
6500 /* Emit debug info for the address of the current line, choosing
6501 the encoding that uses the least amount of space. */
6502 /* ??? Unfortunately, we have little choice here currently, and must
6503 always use the most general form. Gcc does not know the address
6504 delta itself, so we can't use DW_LNS_advance_pc. There are no known
6505 dwarf2 aware assemblers at this time, so we can't use any special
6506 pseudo ops that would allow the assembler to optimally encode this for
6507 us. Many ports do have length attributes which will give an upper
6508 bound on the address range. We could perhaps use length attributes
6509 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
6510 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6513 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6514 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6516 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6519 fputc ('\n', asm_out_file);
6520 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
6521 fputc ('\n', asm_out_file);
6525 /* This can handle any delta. This takes
6526 4+DWARF2_ADDR_SIZE bytes. */
6527 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6529 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6531 fputc ('\n', asm_out_file);
6532 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6533 fputc ('\n', asm_out_file);
6534 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6535 fputc ('\n', asm_out_file);
6536 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6537 fputc ('\n', asm_out_file);
6539 strcpy (prev_line_label, line_label);
6541 /* Emit debug info for the source file of the current line, if
6542 different from the previous line. */
6543 if (line_info->dw_file_num != current_file)
6545 current_file = line_info->dw_file_num;
6546 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6548 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6550 fputc ('\n', asm_out_file);
6551 output_uleb128 (current_file);
6553 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
6555 fputc ('\n', asm_out_file);
6558 /* Emit debug info for the current line number, choosing the encoding
6559 that uses the least amount of space. */
6560 if (line_info->dw_line_num != current_line)
6562 line_offset = line_info->dw_line_num - current_line;
6563 line_delta = line_offset - DWARF_LINE_BASE;
6564 current_line = line_info->dw_line_num;
6565 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6567 /* This can handle deltas from -10 to 234, using the current
6568 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6570 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6571 DWARF_LINE_OPCODE_BASE + line_delta);
6573 fprintf (asm_out_file,
6574 "\t%s line %ld", ASM_COMMENT_START, current_line);
6576 fputc ('\n', asm_out_file);
6580 /* This can handle any delta. This takes at least 4 bytes,
6581 depending on the value being encoded. */
6582 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6584 fprintf (asm_out_file, "\t%s advance to line %ld",
6585 ASM_COMMENT_START, current_line);
6587 fputc ('\n', asm_out_file);
6588 output_sleb128 (line_offset);
6589 fputc ('\n', asm_out_file);
6590 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6592 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6593 fputc ('\n', asm_out_file);
6598 /* We still need to start a new row, so output a copy insn. */
6599 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6601 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6602 fputc ('\n', asm_out_file);
6606 /* Emit debug info for the address of the end of the function. */
6609 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6611 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6614 fputc ('\n', asm_out_file);
6615 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
6616 fputc ('\n', asm_out_file);
6620 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6622 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
6623 fputc ('\n', asm_out_file);
6624 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6625 fputc ('\n', asm_out_file);
6626 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6627 fputc ('\n', asm_out_file);
6628 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
6629 fputc ('\n', asm_out_file);
6632 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6634 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
6636 fputc ('\n', asm_out_file);
6638 fputc ('\n', asm_out_file);
6639 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6640 fputc ('\n', asm_out_file);
6645 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6647 register dw_separate_line_info_ref line_info
6648 = &separate_line_info_table[lt_index];
6651 /* Don't emit anything for redundant notes. */
6652 if (line_info->dw_line_num == current_line
6653 && line_info->dw_file_num == current_file
6654 && line_info->function == function)
6658 /* Emit debug info for the address of the current line. If this is
6659 a new function, or the first line of a function, then we need
6660 to handle it differently. */
6661 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6663 if (function != line_info->function)
6665 function = line_info->function;
6667 /* Set the address register to the first line in the function */
6668 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6670 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6673 fputc ('\n', asm_out_file);
6674 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6675 fputc ('\n', asm_out_file);
6676 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6677 fputc ('\n', asm_out_file);
6678 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6679 fputc ('\n', asm_out_file);
6683 /* ??? See the DW_LNS_advance_pc comment above. */
6686 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6688 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6691 fputc ('\n', asm_out_file);
6692 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6694 fputc ('\n', asm_out_file);
6698 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6700 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6702 fputc ('\n', asm_out_file);
6703 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6704 fputc ('\n', asm_out_file);
6705 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6706 fputc ('\n', asm_out_file);
6707 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6708 fputc ('\n', asm_out_file);
6711 strcpy (prev_line_label, line_label);
6713 /* Emit debug info for the source file of the current line, if
6714 different from the previous line. */
6715 if (line_info->dw_file_num != current_file)
6717 current_file = line_info->dw_file_num;
6718 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6720 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6722 fputc ('\n', asm_out_file);
6723 output_uleb128 (current_file);
6725 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
6727 fputc ('\n', asm_out_file);
6730 /* Emit debug info for the current line number, choosing the encoding
6731 that uses the least amount of space. */
6732 if (line_info->dw_line_num != current_line)
6734 line_offset = line_info->dw_line_num - current_line;
6735 line_delta = line_offset - DWARF_LINE_BASE;
6736 current_line = line_info->dw_line_num;
6737 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6739 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6740 DWARF_LINE_OPCODE_BASE + line_delta);
6742 fprintf (asm_out_file,
6743 "\t%s line %ld", ASM_COMMENT_START, current_line);
6745 fputc ('\n', asm_out_file);
6749 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6751 fprintf (asm_out_file, "\t%s advance to line %ld",
6752 ASM_COMMENT_START, current_line);
6754 fputc ('\n', asm_out_file);
6755 output_sleb128 (line_offset);
6756 fputc ('\n', asm_out_file);
6757 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6759 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6760 fputc ('\n', asm_out_file);
6765 /* We still need to start a new row, so output a copy insn. */
6766 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6768 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6769 fputc ('\n', asm_out_file);
6777 /* If we're done with a function, end its sequence. */
6778 if (lt_index == separate_line_info_table_in_use
6779 || separate_line_info_table[lt_index].function != function)
6784 /* Emit debug info for the address of the end of the function. */
6785 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6788 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6790 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6793 fputc ('\n', asm_out_file);
6794 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6796 fputc ('\n', asm_out_file);
6800 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6802 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6804 fputc ('\n', asm_out_file);
6805 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6806 fputc ('\n', asm_out_file);
6807 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6808 fputc ('\n', asm_out_file);
6809 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6810 fputc ('\n', asm_out_file);
6813 /* Output the marker for the end of this sequence. */
6814 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6816 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
6819 fputc ('\n', asm_out_file);
6821 fputc ('\n', asm_out_file);
6822 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6823 fputc ('\n', asm_out_file);
6827 /* Output the marker for the end of the line number info. */
6828 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
6831 /* Given a pointer to a tree node for some base type, return a pointer to
6832 a DIE that describes the given type.
6834 This routine must only be called for GCC type nodes that correspond to
6835 Dwarf base (fundamental) types. */
6838 base_type_die (type)
6841 register dw_die_ref base_type_result;
6842 register const char *type_name;
6843 register enum dwarf_type encoding;
6844 register tree name = TYPE_NAME (type);
6846 if (TREE_CODE (type) == ERROR_MARK
6847 || TREE_CODE (type) == VOID_TYPE)
6852 if (TREE_CODE (name) == TYPE_DECL)
6853 name = DECL_NAME (name);
6855 type_name = IDENTIFIER_POINTER (name);
6858 type_name = "__unknown__";
6860 switch (TREE_CODE (type))
6863 /* Carefully distinguish the C character types, without messing
6864 up if the language is not C. Note that we check only for the names
6865 that contain spaces; other names might occur by coincidence in other
6867 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6868 && (type == char_type_node
6869 || ! strcmp (type_name, "signed char")
6870 || ! strcmp (type_name, "unsigned char"))))
6872 if (TREE_UNSIGNED (type))
6873 encoding = DW_ATE_unsigned;
6875 encoding = DW_ATE_signed;
6878 /* else fall through. */
6881 /* GNU Pascal/Ada CHAR type. Not used in C. */
6882 if (TREE_UNSIGNED (type))
6883 encoding = DW_ATE_unsigned_char;
6885 encoding = DW_ATE_signed_char;
6889 encoding = DW_ATE_float;
6892 /* Dwarf2 doesn't know anything about complex ints, so use
6893 a user defined type for it. */
6895 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6896 encoding = DW_ATE_complex_float;
6898 encoding = DW_ATE_lo_user;
6902 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6903 encoding = DW_ATE_boolean;
6907 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6910 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6911 if (demangle_name_func)
6912 type_name = (*demangle_name_func) (type_name);
6914 add_AT_string (base_type_result, DW_AT_name, type_name);
6915 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6916 int_size_in_bytes (type));
6917 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6919 return base_type_result;
6922 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6923 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6924 a given type is generally the same as the given type, except that if the
6925 given type is a pointer or reference type, then the root type of the given
6926 type is the root type of the "basis" type for the pointer or reference
6927 type. (This definition of the "root" type is recursive.) Also, the root
6928 type of a `const' qualified type or a `volatile' qualified type is the
6929 root type of the given type without the qualifiers. */
6935 if (TREE_CODE (type) == ERROR_MARK)
6936 return error_mark_node;
6938 switch (TREE_CODE (type))
6941 return error_mark_node;
6944 case REFERENCE_TYPE:
6945 return type_main_variant (root_type (TREE_TYPE (type)));
6948 return type_main_variant (type);
6952 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6953 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6959 switch (TREE_CODE (type))
6974 case QUAL_UNION_TYPE:
6979 case REFERENCE_TYPE:
6992 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6993 entry that chains various modifiers in front of the given type. */
6996 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6998 register int is_const_type;
6999 register int is_volatile_type;
7000 register dw_die_ref context_die;
7002 register enum tree_code code = TREE_CODE (type);
7003 register dw_die_ref mod_type_die = NULL;
7004 register dw_die_ref sub_die = NULL;
7005 register tree item_type = NULL;
7007 if (code != ERROR_MARK)
7009 type = build_type_variant (type, is_const_type, is_volatile_type);
7011 mod_type_die = lookup_type_die (type);
7013 return mod_type_die;
7015 /* Handle C typedef types. */
7016 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7017 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
7019 tree dtype = TREE_TYPE (TYPE_NAME (type));
7022 /* For a named type, use the typedef. */
7023 gen_type_die (type, context_die);
7024 mod_type_die = lookup_type_die (type);
7027 else if (is_const_type < TYPE_READONLY (dtype)
7028 || is_volatile_type < TYPE_VOLATILE (dtype))
7029 /* cv-unqualified version of named type. Just use the unnamed
7030 type to which it refers. */
7032 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
7033 is_const_type, is_volatile_type,
7035 /* Else cv-qualified version of named type; fall through. */
7041 else if (is_const_type)
7043 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7044 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7046 else if (is_volatile_type)
7048 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7049 sub_die = modified_type_die (type, 0, 0, context_die);
7051 else if (code == POINTER_TYPE)
7053 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7054 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7056 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7058 item_type = TREE_TYPE (type);
7060 else if (code == REFERENCE_TYPE)
7062 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7063 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7065 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7067 item_type = TREE_TYPE (type);
7069 else if (is_base_type (type))
7070 mod_type_die = base_type_die (type);
7073 gen_type_die (type, context_die);
7075 /* We have to get the type_main_variant here (and pass that to the
7076 `lookup_type_die' routine) because the ..._TYPE node we have
7077 might simply be a *copy* of some original type node (where the
7078 copy was created to help us keep track of typedef names) and
7079 that copy might have a different TYPE_UID from the original
7081 mod_type_die = lookup_type_die (type_main_variant (type));
7082 if (mod_type_die == NULL)
7087 equate_type_number_to_die (type, mod_type_die);
7089 /* We must do this after the equate_type_number_to_die call, in case
7090 this is a recursive type. This ensures that the modified_type_die
7091 recursion will terminate even if the type is recursive. Recursive
7092 types are possible in Ada. */
7093 sub_die = modified_type_die (item_type,
7094 TYPE_READONLY (item_type),
7095 TYPE_VOLATILE (item_type),
7098 if (sub_die != NULL)
7099 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7101 return mod_type_die;
7104 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7105 an enumerated type. */
7111 return TREE_CODE (type) == ENUMERAL_TYPE;
7114 /* Return the register number described by a given RTL node. */
7120 register unsigned regno = REGNO (rtl);
7122 if (regno >= FIRST_PSEUDO_REGISTER)
7124 warning ("internal regno botch: regno = %d\n", regno);
7128 regno = DBX_REGISTER_NUMBER (regno);
7132 /* Return a location descriptor that designates a machine register. */
7134 static dw_loc_descr_ref
7135 reg_loc_descriptor (rtl)
7138 register dw_loc_descr_ref loc_result = NULL;
7139 register unsigned reg = reg_number (rtl);
7142 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7144 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7149 /* Return a location descriptor that designates a base+offset location. */
7151 static dw_loc_descr_ref
7152 based_loc_descr (reg, offset)
7156 register dw_loc_descr_ref loc_result;
7157 /* For the "frame base", we use the frame pointer or stack pointer
7158 registers, since the RTL for local variables is relative to one of
7160 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7161 ? HARD_FRAME_POINTER_REGNUM
7162 : STACK_POINTER_REGNUM);
7165 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7167 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7169 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7174 /* Return true if this RTL expression describes a base+offset calculation. */
7180 return (GET_CODE (rtl) == PLUS
7181 && ((GET_CODE (XEXP (rtl, 0)) == REG
7182 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7185 /* The following routine converts the RTL for a variable or parameter
7186 (resident in memory) into an equivalent Dwarf representation of a
7187 mechanism for getting the address of that same variable onto the top of a
7188 hypothetical "address evaluation" stack.
7190 When creating memory location descriptors, we are effectively transforming
7191 the RTL for a memory-resident object into its Dwarf postfix expression
7192 equivalent. This routine recursively descends an RTL tree, turning
7193 it into Dwarf postfix code as it goes.
7195 MODE is the mode of the memory reference, needed to handle some
7196 autoincrement addressing modes. */
7198 static dw_loc_descr_ref
7199 mem_loc_descriptor (rtl, mode)
7201 enum machine_mode mode;
7203 dw_loc_descr_ref mem_loc_result = NULL;
7204 /* Note that for a dynamically sized array, the location we will generate a
7205 description of here will be the lowest numbered location which is
7206 actually within the array. That's *not* necessarily the same as the
7207 zeroth element of the array. */
7209 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7210 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7213 switch (GET_CODE (rtl))
7217 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7218 just fall into the SUBREG code. */
7223 /* The case of a subreg may arise when we have a local (register)
7224 variable or a formal (register) parameter which doesn't quite fill
7225 up an entire register. For now, just assume that it is
7226 legitimate to make the Dwarf info refer to the whole register which
7227 contains the given subreg. */
7228 rtl = XEXP (rtl, 0);
7233 /* Whenever a register number forms a part of the description of the
7234 method for calculating the (dynamic) address of a memory resident
7235 object, DWARF rules require the register number be referred to as
7236 a "base register". This distinction is not based in any way upon
7237 what category of register the hardware believes the given register
7238 belongs to. This is strictly DWARF terminology we're dealing with
7239 here. Note that in cases where the location of a memory-resident
7240 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7241 OP_CONST (0)) the actual DWARF location descriptor that we generate
7242 may just be OP_BASEREG (basereg). This may look deceptively like
7243 the object in question was allocated to a register (rather than in
7244 memory) so DWARF consumers need to be aware of the subtle
7245 distinction between OP_REG and OP_BASEREG. */
7246 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7250 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7251 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7255 /* Some ports can transform a symbol ref into a label ref, because
7256 the symbol ref is too far away and has to be dumped into a constant
7260 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7261 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7262 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7267 /* Turn these into a PLUS expression and fall into the PLUS code
7269 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7270 GEN_INT (GET_CODE (rtl) == PRE_INC
7271 ? GET_MODE_UNIT_SIZE (mode)
7272 : -GET_MODE_UNIT_SIZE (mode)));
7277 if (is_based_loc (rtl))
7278 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7279 INTVAL (XEXP (rtl, 1)));
7282 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0),
7284 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1),
7286 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
7291 /* If a pseudo-reg is optimized away, it is possible for it to
7292 be replaced with a MEM containing a multiply. */
7293 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode));
7294 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode));
7295 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7299 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
7306 return mem_loc_result;
7309 /* Return a descriptor that describes the concatenation of two locations.
7310 This is typically a complex variable. */
7312 static dw_loc_descr_ref
7313 concat_loc_descriptor (x0, x1)
7314 register rtx x0, x1;
7316 dw_loc_descr_ref cc_loc_result = NULL;
7318 if (!is_pseudo_reg (x0)
7319 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7320 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7321 add_loc_descr (&cc_loc_result,
7322 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7324 if (!is_pseudo_reg (x1)
7325 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7326 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7327 add_loc_descr (&cc_loc_result,
7328 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7330 return cc_loc_result;
7333 /* Output a proper Dwarf location descriptor for a variable or parameter
7334 which is either allocated in a register or in a memory location. For a
7335 register, we just generate an OP_REG and the register number. For a
7336 memory location we provide a Dwarf postfix expression describing how to
7337 generate the (dynamic) address of the object onto the address stack. */
7339 static dw_loc_descr_ref
7340 loc_descriptor (rtl)
7343 dw_loc_descr_ref loc_result = NULL;
7344 switch (GET_CODE (rtl))
7347 /* The case of a subreg may arise when we have a local (register)
7348 variable or a formal (register) parameter which doesn't quite fill
7349 up an entire register. For now, just assume that it is
7350 legitimate to make the Dwarf info refer to the whole register which
7351 contains the given subreg. */
7352 rtl = XEXP (rtl, 0);
7357 loc_result = reg_loc_descriptor (rtl);
7361 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7365 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7375 /* Given a value, round it up to the lowest multiple of `boundary'
7376 which is not less than the value itself. */
7378 static inline HOST_WIDE_INT
7379 ceiling (value, boundary)
7380 HOST_WIDE_INT value;
7381 unsigned int boundary;
7383 return (((value + boundary - 1) / boundary) * boundary);
7386 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
7387 pointer to the declared type for the relevant field variable, or return
7388 `integer_type_node' if the given node turns out to be an
7397 if (TREE_CODE (decl) == ERROR_MARK)
7398 return integer_type_node;
7400 type = DECL_BIT_FIELD_TYPE (decl);
7401 if (type == NULL_TREE)
7402 type = TREE_TYPE (decl);
7407 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7408 node, return the alignment in bits for the type, or else return
7409 BITS_PER_WORD if the node actually turns out to be an
7412 static inline unsigned
7413 simple_type_align_in_bits (type)
7416 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
7419 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7420 node, return the size in bits for the type if it is a constant, or else
7421 return the alignment for the type if the type's size is not constant, or
7422 else return BITS_PER_WORD if the type actually turns out to be an
7425 static inline unsigned HOST_WIDE_INT
7426 simple_type_size_in_bits (type)
7429 if (TREE_CODE (type) == ERROR_MARK)
7430 return BITS_PER_WORD;
7433 register tree type_size_tree = TYPE_SIZE (type);
7435 if (! host_integerp (type_size_tree, 1))
7436 return TYPE_ALIGN (type);
7438 return tree_low_cst (type_size_tree, 1);
7442 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
7443 return the byte offset of the lowest addressed byte of the "containing
7444 object" for the given FIELD_DECL, or return 0 if we are unable to
7445 determine what that offset is, either because the argument turns out to
7446 be a pointer to an ERROR_MARK node, or because the offset is actually
7447 variable. (We can't handle the latter case just yet). */
7449 static HOST_WIDE_INT
7450 field_byte_offset (decl)
7453 unsigned int type_align_in_bytes;
7454 unsigned int type_align_in_bits;
7455 unsigned HOST_WIDE_INT type_size_in_bits;
7456 HOST_WIDE_INT object_offset_in_align_units;
7457 HOST_WIDE_INT object_offset_in_bits;
7458 HOST_WIDE_INT object_offset_in_bytes;
7460 tree field_size_tree;
7461 HOST_WIDE_INT bitpos_int;
7462 HOST_WIDE_INT deepest_bitpos;
7463 unsigned HOST_WIDE_INT field_size_in_bits;
7465 if (TREE_CODE (decl) == ERROR_MARK)
7468 if (TREE_CODE (decl) != FIELD_DECL)
7471 type = field_type (decl);
7472 field_size_tree = DECL_SIZE (decl);
7474 /* If there was an error, the size could be zero. */
7475 if (! field_size_tree)
7483 /* We cannot yet cope with fields whose positions are variable, so
7484 for now, when we see such things, we simply return 0. Someday, we may
7485 be able to handle such cases, but it will be damn difficult. */
7486 if (! host_integerp (bit_position (decl), 0))
7489 bitpos_int = int_bit_position (decl);
7491 /* If we don't know the size of the field, pretend it's a full word. */
7492 if (host_integerp (field_size_tree, 1))
7493 field_size_in_bits = tree_low_cst (field_size_tree, 1);
7495 field_size_in_bits = BITS_PER_WORD;
7497 type_size_in_bits = simple_type_size_in_bits (type);
7498 type_align_in_bits = simple_type_align_in_bits (type);
7499 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
7501 /* Note that the GCC front-end doesn't make any attempt to keep track of
7502 the starting bit offset (relative to the start of the containing
7503 structure type) of the hypothetical "containing object" for a bit-
7504 field. Thus, when computing the byte offset value for the start of the
7505 "containing object" of a bit-field, we must deduce this information on
7506 our own. This can be rather tricky to do in some cases. For example,
7507 handling the following structure type definition when compiling for an
7508 i386/i486 target (which only aligns long long's to 32-bit boundaries)
7511 struct S { int field1; long long field2:31; };
7513 Fortunately, there is a simple rule-of-thumb which can be
7514 used in such cases. When compiling for an i386/i486, GCC will allocate
7515 8 bytes for the structure shown above. It decides to do this based upon
7516 one simple rule for bit-field allocation. Quite simply, GCC allocates
7517 each "containing object" for each bit-field at the first (i.e. lowest
7518 addressed) legitimate alignment boundary (based upon the required
7519 minimum alignment for the declared type of the field) which it can
7520 possibly use, subject to the condition that there is still enough
7521 available space remaining in the containing object (when allocated at
7522 the selected point) to fully accommodate all of the bits of the
7523 bit-field itself. This simple rule makes it obvious why GCC allocates
7524 8 bytes for each object of the structure type shown above. When looking
7525 for a place to allocate the "containing object" for `field2', the
7526 compiler simply tries to allocate a 64-bit "containing object" at each
7527 successive 32-bit boundary (starting at zero) until it finds a place to
7528 allocate that 64- bit field such that at least 31 contiguous (and
7529 previously unallocated) bits remain within that selected 64 bit field.
7530 (As it turns out, for the example above, the compiler finds that it is
7531 OK to allocate the "containing object" 64-bit field at bit-offset zero
7532 within the structure type.) Here we attempt to work backwards from the
7533 limited set of facts we're given, and we try to deduce from those facts,
7534 where GCC must have believed that the containing object started (within
7535 the structure type). The value we deduce is then used (by the callers of
7536 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
7537 for fields (both bit-fields and, in the case of DW_AT_location, regular
7540 /* Figure out the bit-distance from the start of the structure to the
7541 "deepest" bit of the bit-field. */
7542 deepest_bitpos = bitpos_int + field_size_in_bits;
7544 /* This is the tricky part. Use some fancy footwork to deduce where the
7545 lowest addressed bit of the containing object must be. */
7546 object_offset_in_bits
7547 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
7549 /* Compute the offset of the containing object in "alignment units". */
7550 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
7552 /* Compute the offset of the containing object in bytes. */
7553 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
7555 return object_offset_in_bytes;
7558 /* The following routines define various Dwarf attributes and any data
7559 associated with them. */
7561 /* Add a location description attribute value to a DIE.
7563 This emits location attributes suitable for whole variables and
7564 whole parameters. Note that the location attributes for struct fields are
7565 generated by the routine `data_member_location_attribute' below. */
7568 add_AT_location_description (die, attr_kind, rtl)
7570 enum dwarf_attribute attr_kind;
7573 /* Handle a special case. If we are about to output a location descriptor
7574 for a variable or parameter which has been optimized out of existence,
7575 don't do that. A variable which has been optimized out
7576 of existence will have a DECL_RTL value which denotes a pseudo-reg.
7577 Currently, in some rare cases, variables can have DECL_RTL values which
7578 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
7579 elsewhere in the compiler. We treat such cases as if the variable(s) in
7580 question had been optimized out of existence. */
7582 if (is_pseudo_reg (rtl)
7583 || (GET_CODE (rtl) == MEM
7584 && is_pseudo_reg (XEXP (rtl, 0)))
7585 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
7586 references the internal argument pointer (a pseudo) in a function
7587 where all references to the internal argument pointer were
7588 eliminated via the optimizers. */
7589 || (GET_CODE (rtl) == MEM
7590 && GET_CODE (XEXP (rtl, 0)) == PLUS
7591 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
7592 || (GET_CODE (rtl) == CONCAT
7593 && is_pseudo_reg (XEXP (rtl, 0))
7594 && is_pseudo_reg (XEXP (rtl, 1))))
7597 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
7600 /* Attach the specialized form of location attribute used for data
7601 members of struct and union types. In the special case of a
7602 FIELD_DECL node which represents a bit-field, the "offset" part
7603 of this special location descriptor must indicate the distance
7604 in bytes from the lowest-addressed byte of the containing struct
7605 or union type to the lowest-addressed byte of the "containing
7606 object" for the bit-field. (See the `field_byte_offset' function
7607 above).. For any given bit-field, the "containing object" is a
7608 hypothetical object (of some integral or enum type) within which
7609 the given bit-field lives. The type of this hypothetical
7610 "containing object" is always the same as the declared type of
7611 the individual bit-field itself (for GCC anyway... the DWARF
7612 spec doesn't actually mandate this). Note that it is the size
7613 (in bytes) of the hypothetical "containing object" which will
7614 be given in the DW_AT_byte_size attribute for this bit-field.
7615 (See the `byte_size_attribute' function below.) It is also used
7616 when calculating the value of the DW_AT_bit_offset attribute.
7617 (See the `bit_offset_attribute' function below). */
7620 add_data_member_location_attribute (die, decl)
7621 register dw_die_ref die;
7624 register unsigned long offset;
7625 register dw_loc_descr_ref loc_descr;
7626 register enum dwarf_location_atom op;
7628 if (TREE_CODE (decl) == TREE_VEC)
7629 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
7631 offset = field_byte_offset (decl);
7633 /* The DWARF2 standard says that we should assume that the structure address
7634 is already on the stack, so we can specify a structure field address
7635 by using DW_OP_plus_uconst. */
7637 #ifdef MIPS_DEBUGGING_INFO
7638 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
7639 correctly. It works only if we leave the offset on the stack. */
7642 op = DW_OP_plus_uconst;
7645 loc_descr = new_loc_descr (op, offset, 0);
7646 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
7649 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
7650 does not have a "location" either in memory or in a register. These
7651 things can arise in GNU C when a constant is passed as an actual parameter
7652 to an inlined function. They can also arise in C++ where declared
7653 constants do not necessarily get memory "homes". */
7656 add_const_value_attribute (die, rtl)
7657 register dw_die_ref die;
7660 switch (GET_CODE (rtl))
7663 /* Note that a CONST_INT rtx could represent either an integer or a
7664 floating-point constant. A CONST_INT is used whenever the constant
7665 will fit into a single word. In all such cases, the original mode
7666 of the constant value is wiped out, and the CONST_INT rtx is
7667 assigned VOIDmode. */
7668 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
7672 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
7673 floating-point constant. A CONST_DOUBLE is used whenever the
7674 constant requires more than one word in order to be adequately
7675 represented. We output CONST_DOUBLEs as blocks. */
7677 register enum machine_mode mode = GET_MODE (rtl);
7679 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
7681 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
7685 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
7689 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
7693 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
7698 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
7705 add_AT_float (die, DW_AT_const_value, length, array);
7708 add_AT_long_long (die, DW_AT_const_value,
7709 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
7714 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
7720 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
7724 /* In cases where an inlined instance of an inline function is passed
7725 the address of an `auto' variable (which is local to the caller) we
7726 can get a situation where the DECL_RTL of the artificial local
7727 variable (for the inlining) which acts as a stand-in for the
7728 corresponding formal parameter (of the inline function) will look
7729 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
7730 exactly a compile-time constant expression, but it isn't the address
7731 of the (artificial) local variable either. Rather, it represents the
7732 *value* which the artificial local variable always has during its
7733 lifetime. We currently have no way to represent such quasi-constant
7734 values in Dwarf, so for now we just punt and generate nothing. */
7738 /* No other kinds of rtx should be possible here. */
7744 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
7745 data attribute for a variable or a parameter. We generate the
7746 DW_AT_const_value attribute only in those cases where the given variable
7747 or parameter does not have a true "location" either in memory or in a
7748 register. This can happen (for example) when a constant is passed as an
7749 actual argument in a call to an inline function. (It's possible that
7750 these things can crop up in other ways also.) Note that one type of
7751 constant value which can be passed into an inlined function is a constant
7752 pointer. This can happen for example if an actual argument in an inlined
7753 function call evaluates to a compile-time constant address. */
7756 add_location_or_const_value_attribute (die, decl)
7757 register dw_die_ref die;
7761 register tree declared_type;
7762 register tree passed_type;
7764 if (TREE_CODE (decl) == ERROR_MARK)
7767 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
7770 /* Here we have to decide where we are going to say the parameter "lives"
7771 (as far as the debugger is concerned). We only have a couple of
7772 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
7774 DECL_RTL normally indicates where the parameter lives during most of the
7775 activation of the function. If optimization is enabled however, this
7776 could be either NULL or else a pseudo-reg. Both of those cases indicate
7777 that the parameter doesn't really live anywhere (as far as the code
7778 generation parts of GCC are concerned) during most of the function's
7779 activation. That will happen (for example) if the parameter is never
7780 referenced within the function.
7782 We could just generate a location descriptor here for all non-NULL
7783 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
7784 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
7785 where DECL_RTL is NULL or is a pseudo-reg.
7787 Note however that we can only get away with using DECL_INCOMING_RTL as
7788 a backup substitute for DECL_RTL in certain limited cases. In cases
7789 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
7790 we can be sure that the parameter was passed using the same type as it is
7791 declared to have within the function, and that its DECL_INCOMING_RTL
7792 points us to a place where a value of that type is passed.
7794 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
7795 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
7796 because in these cases DECL_INCOMING_RTL points us to a value of some
7797 type which is *different* from the type of the parameter itself. Thus,
7798 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
7799 such cases, the debugger would end up (for example) trying to fetch a
7800 `float' from a place which actually contains the first part of a
7801 `double'. That would lead to really incorrect and confusing
7802 output at debug-time.
7804 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
7805 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
7806 are a couple of exceptions however. On little-endian machines we can
7807 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
7808 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
7809 an integral type that is smaller than TREE_TYPE (decl). These cases arise
7810 when (on a little-endian machine) a non-prototyped function has a
7811 parameter declared to be of type `short' or `char'. In such cases,
7812 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
7813 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
7814 passed `int' value. If the debugger then uses that address to fetch
7815 a `short' or a `char' (on a little-endian machine) the result will be
7816 the correct data, so we allow for such exceptional cases below.
7818 Note that our goal here is to describe the place where the given formal
7819 parameter lives during most of the function's activation (i.e. between
7820 the end of the prologue and the start of the epilogue). We'll do that
7821 as best as we can. Note however that if the given formal parameter is
7822 modified sometime during the execution of the function, then a stack
7823 backtrace (at debug-time) will show the function as having been
7824 called with the *new* value rather than the value which was
7825 originally passed in. This happens rarely enough that it is not
7826 a major problem, but it *is* a problem, and I'd like to fix it.
7828 A future version of dwarf2out.c may generate two additional
7829 attributes for any given DW_TAG_formal_parameter DIE which will
7830 describe the "passed type" and the "passed location" for the
7831 given formal parameter in addition to the attributes we now
7832 generate to indicate the "declared type" and the "active
7833 location" for each parameter. This additional set of attributes
7834 could be used by debuggers for stack backtraces. Separately, note
7835 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
7836 NULL also. This happens (for example) for inlined-instances of
7837 inline function formal parameters which are never referenced.
7838 This really shouldn't be happening. All PARM_DECL nodes should
7839 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
7840 doesn't currently generate these values for inlined instances of
7841 inline function parameters, so when we see such cases, we are
7842 just out-of-luck for the time being (until integrate.c
7845 /* Use DECL_RTL as the "location" unless we find something better. */
7846 rtl = DECL_RTL (decl);
7848 if (TREE_CODE (decl) == PARM_DECL)
7850 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
7852 declared_type = type_main_variant (TREE_TYPE (decl));
7853 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
7855 /* This decl represents a formal parameter which was optimized out.
7856 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
7857 all* cases where (rtl == NULL_RTX) just below. */
7858 if (declared_type == passed_type)
7859 rtl = DECL_INCOMING_RTL (decl);
7860 else if (! BYTES_BIG_ENDIAN
7861 && TREE_CODE (declared_type) == INTEGER_TYPE
7862 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
7863 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
7864 rtl = DECL_INCOMING_RTL (decl);
7867 /* If the parm was passed in registers, but lives on the stack, then
7868 make a big endian correction if the mode of the type of the
7869 parameter is not the same as the mode of the rtl. */
7870 /* ??? This is the same series of checks that are made in dbxout.c before
7871 we reach the big endian correction code there. It isn't clear if all
7872 of these checks are necessary here, but keeping them all is the safe
7874 else if (GET_CODE (rtl) == MEM
7875 && XEXP (rtl, 0) != const0_rtx
7876 && ! CONSTANT_P (XEXP (rtl, 0))
7877 /* Not passed in memory. */
7878 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
7879 /* Not passed by invisible reference. */
7880 && (GET_CODE (XEXP (rtl, 0)) != REG
7881 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
7882 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
7883 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
7884 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
7887 /* Big endian correction check. */
7889 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
7890 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
7893 int offset = (UNITS_PER_WORD
7894 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
7895 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
7896 plus_constant (XEXP (rtl, 0), offset));
7900 if (rtl == NULL_RTX)
7903 rtl = eliminate_regs (rtl, 0, NULL_RTX);
7904 #ifdef LEAF_REG_REMAP
7905 if (current_function_uses_only_leaf_regs)
7906 leaf_renumber_regs_insn (rtl);
7909 switch (GET_CODE (rtl))
7912 /* The address of a variable that was optimized away; don't emit
7923 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7924 add_const_value_attribute (die, rtl);
7931 add_AT_location_description (die, DW_AT_location, rtl);
7939 /* Generate an DW_AT_name attribute given some string value to be included as
7940 the value of the attribute. */
7943 add_name_attribute (die, name_string)
7944 register dw_die_ref die;
7945 register const char *name_string;
7947 if (name_string != NULL && *name_string != 0)
7949 if (demangle_name_func)
7950 name_string = (*demangle_name_func) (name_string);
7952 add_AT_string (die, DW_AT_name, name_string);
7956 /* Given a tree node describing an array bound (either lower or upper) output
7957 a representation for that bound. */
7960 add_bound_info (subrange_die, bound_attr, bound)
7961 register dw_die_ref subrange_die;
7962 register enum dwarf_attribute bound_attr;
7963 register tree bound;
7965 /* If this is an Ada unconstrained array type, then don't emit any debug
7966 info because the array bounds are unknown. They are parameterized when
7967 the type is instantiated. */
7968 if (contains_placeholder_p (bound))
7971 switch (TREE_CODE (bound))
7976 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7978 if (! host_integerp (bound, 0)
7979 || (bound_attr == DW_AT_lower_bound
7980 && (((is_c_family () || is_java ()) && integer_zerop (bound))
7981 || (is_fortran () && integer_onep (bound)))))
7982 /* use the default */
7985 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
7990 case NON_LVALUE_EXPR:
7991 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7995 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7996 access the upper bound values may be bogus. If they refer to a
7997 register, they may only describe how to get at these values at the
7998 points in the generated code right after they have just been
7999 computed. Worse yet, in the typical case, the upper bound values
8000 will not even *be* computed in the optimized code (though the
8001 number of elements will), so these SAVE_EXPRs are entirely
8002 bogus. In order to compensate for this fact, we check here to see
8003 if optimization is enabled, and if so, we don't add an attribute
8004 for the (unknown and unknowable) upper bound. This should not
8005 cause too much trouble for existing (stupid?) debuggers because
8006 they have to deal with empty upper bounds location descriptions
8007 anyway in order to be able to deal with incomplete array types.
8008 Of course an intelligent debugger (GDB?) should be able to
8009 comprehend that a missing upper bound specification in a array
8010 type used for a storage class `auto' local array variable
8011 indicates that the upper bound is both unknown (at compile- time)
8012 and unknowable (at run-time) due to optimization.
8014 We assume that a MEM rtx is safe because gcc wouldn't put the
8015 value there unless it was going to be used repeatedly in the
8016 function, i.e. for cleanups. */
8017 if (! optimize || (SAVE_EXPR_RTL (bound)
8018 && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8020 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8021 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8022 register rtx loc = SAVE_EXPR_RTL (bound);
8024 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8025 it references an outer function's frame. */
8027 if (GET_CODE (loc) == MEM)
8029 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8031 if (XEXP (loc, 0) != new_addr)
8032 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8035 add_AT_flag (decl_die, DW_AT_artificial, 1);
8036 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8037 add_AT_location_description (decl_die, DW_AT_location, loc);
8038 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8041 /* Else leave out the attribute. */
8047 /* ??? These types of bounds can be created by the Ada front end,
8048 and it isn't clear how to emit debug info for them. */
8056 /* Note that the block of subscript information for an array type also
8057 includes information about the element type of type given array type. */
8060 add_subscript_info (type_die, type)
8061 register dw_die_ref type_die;
8064 #ifndef MIPS_DEBUGGING_INFO
8065 register unsigned dimension_number;
8067 register tree lower, upper;
8068 register dw_die_ref subrange_die;
8070 /* The GNU compilers represent multidimensional array types as sequences of
8071 one dimensional array types whose element types are themselves array
8072 types. Here we squish that down, so that each multidimensional array
8073 type gets only one array_type DIE in the Dwarf debugging info. The draft
8074 Dwarf specification say that we are allowed to do this kind of
8075 compression in C (because there is no difference between an array or
8076 arrays and a multidimensional array in C) but for other source languages
8077 (e.g. Ada) we probably shouldn't do this. */
8079 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8080 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8081 We work around this by disabling this feature. See also
8082 gen_array_type_die. */
8083 #ifndef MIPS_DEBUGGING_INFO
8084 for (dimension_number = 0;
8085 TREE_CODE (type) == ARRAY_TYPE;
8086 type = TREE_TYPE (type), dimension_number++)
8089 register tree domain = TYPE_DOMAIN (type);
8091 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8092 and (in GNU C only) variable bounds. Handle all three forms
8094 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8097 /* We have an array type with specified bounds. */
8098 lower = TYPE_MIN_VALUE (domain);
8099 upper = TYPE_MAX_VALUE (domain);
8101 /* define the index type. */
8102 if (TREE_TYPE (domain))
8104 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8105 TREE_TYPE field. We can't emit debug info for this
8106 because it is an unnamed integral type. */
8107 if (TREE_CODE (domain) == INTEGER_TYPE
8108 && TYPE_NAME (domain) == NULL_TREE
8109 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8110 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8113 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8117 /* ??? If upper is NULL, the array has unspecified length,
8118 but it does have a lower bound. This happens with Fortran
8120 Since the debugger is definitely going to need to know N
8121 to produce useful results, go ahead and output the lower
8122 bound solo, and hope the debugger can cope. */
8124 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8126 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8129 /* We have an array type with an unspecified length. The DWARF-2
8130 spec does not say how to handle this; let's just leave out the
8134 #ifndef MIPS_DEBUGGING_INFO
8140 add_byte_size_attribute (die, tree_node)
8142 register tree tree_node;
8144 register unsigned size;
8146 switch (TREE_CODE (tree_node))
8154 case QUAL_UNION_TYPE:
8155 size = int_size_in_bytes (tree_node);
8158 /* For a data member of a struct or union, the DW_AT_byte_size is
8159 generally given as the number of bytes normally allocated for an
8160 object of the *declared* type of the member itself. This is true
8161 even for bit-fields. */
8162 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8168 /* Note that `size' might be -1 when we get to this point. If it is, that
8169 indicates that the byte size of the entity in question is variable. We
8170 have no good way of expressing this fact in Dwarf at the present time,
8171 so just let the -1 pass on through. */
8173 add_AT_unsigned (die, DW_AT_byte_size, size);
8176 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8177 which specifies the distance in bits from the highest order bit of the
8178 "containing object" for the bit-field to the highest order bit of the
8181 For any given bit-field, the "containing object" is a hypothetical
8182 object (of some integral or enum type) within which the given bit-field
8183 lives. The type of this hypothetical "containing object" is always the
8184 same as the declared type of the individual bit-field itself. The
8185 determination of the exact location of the "containing object" for a
8186 bit-field is rather complicated. It's handled by the
8187 `field_byte_offset' function (above).
8189 Note that it is the size (in bytes) of the hypothetical "containing object"
8190 which will be given in the DW_AT_byte_size attribute for this bit-field.
8191 (See `byte_size_attribute' above). */
8194 add_bit_offset_attribute (die, decl)
8195 register dw_die_ref die;
8198 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8199 tree type = DECL_BIT_FIELD_TYPE (decl);
8200 HOST_WIDE_INT bitpos_int;
8201 HOST_WIDE_INT highest_order_object_bit_offset;
8202 HOST_WIDE_INT highest_order_field_bit_offset;
8203 HOST_WIDE_INT unsigned bit_offset;
8205 /* Must be a field and a bit field. */
8207 || TREE_CODE (decl) != FIELD_DECL)
8210 /* We can't yet handle bit-fields whose offsets are variable, so if we
8211 encounter such things, just return without generating any attribute
8212 whatsoever. Likewise for variable or too large size. */
8213 if (! host_integerp (bit_position (decl), 0)
8214 || ! host_integerp (DECL_SIZE (decl), 1))
8217 bitpos_int = int_bit_position (decl);
8219 /* Note that the bit offset is always the distance (in bits) from the
8220 highest-order bit of the "containing object" to the highest-order bit of
8221 the bit-field itself. Since the "high-order end" of any object or field
8222 is different on big-endian and little-endian machines, the computation
8223 below must take account of these differences. */
8224 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8225 highest_order_field_bit_offset = bitpos_int;
8227 if (! BYTES_BIG_ENDIAN)
8229 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8230 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8234 = (! BYTES_BIG_ENDIAN
8235 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8236 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8238 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8241 /* For a FIELD_DECL node which represents a bit field, output an attribute
8242 which specifies the length in bits of the given field. */
8245 add_bit_size_attribute (die, decl)
8246 register dw_die_ref die;
8249 /* Must be a field and a bit field. */
8250 if (TREE_CODE (decl) != FIELD_DECL
8251 || ! DECL_BIT_FIELD_TYPE (decl))
8254 if (host_integerp (DECL_SIZE (decl), 1))
8255 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8258 /* If the compiled language is ANSI C, then add a 'prototyped'
8259 attribute, if arg types are given for the parameters of a function. */
8262 add_prototyped_attribute (die, func_type)
8263 register dw_die_ref die;
8264 register tree func_type;
8266 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8267 && TYPE_ARG_TYPES (func_type) != NULL)
8268 add_AT_flag (die, DW_AT_prototyped, 1);
8271 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8272 by looking in either the type declaration or object declaration
8276 add_abstract_origin_attribute (die, origin)
8277 register dw_die_ref die;
8278 register tree origin;
8280 dw_die_ref origin_die = NULL;
8282 if (TREE_CODE (origin) != FUNCTION_DECL)
8284 /* We may have gotten separated from the block for the inlined
8285 function, if we're in an exception handler or some such; make
8286 sure that the abstract function has been written out.
8288 Doing this for nested functions is wrong, however; functions are
8289 distinct units, and our context might not even be inline. */
8292 fn = TYPE_STUB_DECL (fn);
8293 fn = decl_function_context (fn);
8295 gen_abstract_function (fn);
8298 if (DECL_P (origin))
8299 origin_die = lookup_decl_die (origin);
8300 else if (TYPE_P (origin))
8301 origin_die = lookup_type_die (origin);
8303 if (origin_die == NULL)
8306 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
8309 /* We do not currently support the pure_virtual attribute. */
8312 add_pure_or_virtual_attribute (die, func_decl)
8313 register dw_die_ref die;
8314 register tree func_decl;
8316 if (DECL_VINDEX (func_decl))
8318 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8320 if (host_integerp (DECL_VINDEX (func_decl), 0))
8321 add_AT_loc (die, DW_AT_vtable_elem_location,
8322 new_loc_descr (DW_OP_constu,
8323 tree_low_cst (DECL_VINDEX (func_decl), 0),
8326 /* GNU extension: Record what type this method came from originally. */
8327 if (debug_info_level > DINFO_LEVEL_TERSE)
8328 add_AT_die_ref (die, DW_AT_containing_type,
8329 lookup_type_die (DECL_CONTEXT (func_decl)));
8333 /* Add source coordinate attributes for the given decl. */
8336 add_src_coords_attributes (die, decl)
8337 register dw_die_ref die;
8340 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
8342 add_AT_unsigned (die, DW_AT_decl_file, file_index);
8343 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8346 /* Add an DW_AT_name attribute and source coordinate attribute for the
8347 given decl, but only if it actually has a name. */
8350 add_name_and_src_coords_attributes (die, decl)
8351 register dw_die_ref die;
8354 register tree decl_name;
8356 decl_name = DECL_NAME (decl);
8357 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
8359 add_name_attribute (die, dwarf2_name (decl, 0));
8360 if (! DECL_ARTIFICIAL (decl))
8361 add_src_coords_attributes (die, decl);
8363 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
8364 && TREE_PUBLIC (decl)
8365 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
8366 add_AT_string (die, DW_AT_MIPS_linkage_name,
8367 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
8371 /* Push a new declaration scope. */
8374 push_decl_scope (scope)
8377 /* Make room in the decl_scope_table, if necessary. */
8378 if (decl_scope_table_allocated == decl_scope_depth)
8380 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
8382 = (tree *) xrealloc (decl_scope_table,
8383 decl_scope_table_allocated * sizeof (tree));
8386 decl_scope_table[decl_scope_depth] = scope;
8390 /* Pop a declaration scope. */
8394 if (decl_scope_depth <= 0)
8399 /* Return the DIE for the scope that immediately contains this type.
8400 Non-named types get global scope. Named types nested in other
8401 types get their containing scope if it's open, or global scope
8402 otherwise. All other types (i.e. function-local named types) get
8403 the current active scope. */
8406 scope_die_for (t, context_die)
8408 register dw_die_ref context_die;
8410 register dw_die_ref scope_die = NULL;
8411 register tree containing_scope;
8414 /* Non-types always go in the current scope. */
8418 containing_scope = TYPE_CONTEXT (t);
8420 /* Ignore namespaces for the moment. */
8421 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
8422 containing_scope = NULL_TREE;
8424 /* Ignore function type "scopes" from the C frontend. They mean that
8425 a tagged type is local to a parmlist of a function declarator, but
8426 that isn't useful to DWARF. */
8427 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
8428 containing_scope = NULL_TREE;
8430 if (containing_scope == NULL_TREE)
8431 scope_die = comp_unit_die;
8432 else if (TYPE_P (containing_scope))
8434 /* For types, we can just look up the appropriate DIE. But
8435 first we check to see if we're in the middle of emitting it
8436 so we know where the new DIE should go. */
8438 for (i = decl_scope_depth - 1; i >= 0; --i)
8439 if (decl_scope_table[i] == containing_scope)
8444 if (debug_info_level > DINFO_LEVEL_TERSE
8445 && !TREE_ASM_WRITTEN (containing_scope))
8448 /* If none of the current dies are suitable, we get file scope. */
8449 scope_die = comp_unit_die;
8452 scope_die = lookup_type_die (containing_scope);
8455 scope_die = context_die;
8460 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
8462 static inline int local_scope_p PARAMS ((dw_die_ref));
8464 local_scope_p (context_die)
8465 dw_die_ref context_die;
8467 for (; context_die; context_die = context_die->die_parent)
8468 if (context_die->die_tag == DW_TAG_inlined_subroutine
8469 || context_die->die_tag == DW_TAG_subprogram)
8474 /* Returns nonzero iff CONTEXT_DIE is a class. */
8476 static inline int class_scope_p PARAMS ((dw_die_ref));
8478 class_scope_p (context_die)
8479 dw_die_ref context_die;
8482 && (context_die->die_tag == DW_TAG_structure_type
8483 || context_die->die_tag == DW_TAG_union_type));
8486 /* Many forms of DIEs require a "type description" attribute. This
8487 routine locates the proper "type descriptor" die for the type given
8488 by 'type', and adds an DW_AT_type attribute below the given die. */
8491 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
8492 register dw_die_ref object_die;
8494 register int decl_const;
8495 register int decl_volatile;
8496 register dw_die_ref context_die;
8498 register enum tree_code code = TREE_CODE (type);
8499 register dw_die_ref type_die = NULL;
8501 /* ??? If this type is an unnamed subrange type of an integral or
8502 floating-point type, use the inner type. This is because we have no
8503 support for unnamed types in base_type_die. This can happen if this is
8504 an Ada subrange type. Correct solution is emit a subrange type die. */
8505 if ((code == INTEGER_TYPE || code == REAL_TYPE)
8506 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
8507 type = TREE_TYPE (type), code = TREE_CODE (type);
8509 if (code == ERROR_MARK)
8512 /* Handle a special case. For functions whose return type is void, we
8513 generate *no* type attribute. (Note that no object may have type
8514 `void', so this only applies to function return types). */
8515 if (code == VOID_TYPE)
8518 type_die = modified_type_die (type,
8519 decl_const || TYPE_READONLY (type),
8520 decl_volatile || TYPE_VOLATILE (type),
8522 if (type_die != NULL)
8523 add_AT_die_ref (object_die, DW_AT_type, type_die);
8526 /* Given a tree pointer to a struct, class, union, or enum type node, return
8527 a pointer to the (string) tag name for the given type, or zero if the type
8528 was declared without a tag. */
8534 register const char *name = 0;
8536 if (TYPE_NAME (type) != 0)
8538 register tree t = 0;
8540 /* Find the IDENTIFIER_NODE for the type name. */
8541 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
8542 t = TYPE_NAME (type);
8544 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
8545 a TYPE_DECL node, regardless of whether or not a `typedef' was
8547 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8548 && ! DECL_IGNORED_P (TYPE_NAME (type)))
8549 t = DECL_NAME (TYPE_NAME (type));
8551 /* Now get the name as a string, or invent one. */
8553 name = IDENTIFIER_POINTER (t);
8556 return (name == 0 || *name == '\0') ? 0 : name;
8559 /* Return the type associated with a data member, make a special check
8560 for bit field types. */
8563 member_declared_type (member)
8564 register tree member;
8566 return (DECL_BIT_FIELD_TYPE (member)
8567 ? DECL_BIT_FIELD_TYPE (member)
8568 : TREE_TYPE (member));
8571 /* Get the decl's label, as described by its RTL. This may be different
8572 from the DECL_NAME name used in the source file. */
8576 decl_start_label (decl)
8581 x = DECL_RTL (decl);
8582 if (GET_CODE (x) != MEM)
8586 if (GET_CODE (x) != SYMBOL_REF)
8589 fnname = XSTR (x, 0);
8594 /* These routines generate the internal representation of the DIE's for
8595 the compilation unit. Debugging information is collected by walking
8596 the declaration trees passed in from dwarf2out_decl(). */
8599 gen_array_type_die (type, context_die)
8601 register dw_die_ref context_die;
8603 register dw_die_ref scope_die = scope_die_for (type, context_die);
8604 register dw_die_ref array_die;
8605 register tree element_type;
8607 /* ??? The SGI dwarf reader fails for array of array of enum types unless
8608 the inner array type comes before the outer array type. Thus we must
8609 call gen_type_die before we call new_die. See below also. */
8610 #ifdef MIPS_DEBUGGING_INFO
8611 gen_type_die (TREE_TYPE (type), context_die);
8614 array_die = new_die (DW_TAG_array_type, scope_die);
8617 /* We default the array ordering. SDB will probably do
8618 the right things even if DW_AT_ordering is not present. It's not even
8619 an issue until we start to get into multidimensional arrays anyway. If
8620 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
8621 then we'll have to put the DW_AT_ordering attribute back in. (But if
8622 and when we find out that we need to put these in, we will only do so
8623 for multidimensional arrays. */
8624 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
8627 #ifdef MIPS_DEBUGGING_INFO
8628 /* The SGI compilers handle arrays of unknown bound by setting
8629 AT_declaration and not emitting any subrange DIEs. */
8630 if (! TYPE_DOMAIN (type))
8631 add_AT_unsigned (array_die, DW_AT_declaration, 1);
8634 add_subscript_info (array_die, type);
8636 add_name_attribute (array_die, type_tag (type));
8637 equate_type_number_to_die (type, array_die);
8639 /* Add representation of the type of the elements of this array type. */
8640 element_type = TREE_TYPE (type);
8642 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8643 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8644 We work around this by disabling this feature. See also
8645 add_subscript_info. */
8646 #ifndef MIPS_DEBUGGING_INFO
8647 while (TREE_CODE (element_type) == ARRAY_TYPE)
8648 element_type = TREE_TYPE (element_type);
8650 gen_type_die (element_type, context_die);
8653 add_type_attribute (array_die, element_type, 0, 0, context_die);
8657 gen_set_type_die (type, context_die)
8659 register dw_die_ref context_die;
8661 register dw_die_ref type_die
8662 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
8664 equate_type_number_to_die (type, type_die);
8665 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
8670 gen_entry_point_die (decl, context_die)
8672 register dw_die_ref context_die;
8674 register tree origin = decl_ultimate_origin (decl);
8675 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
8677 add_abstract_origin_attribute (decl_die, origin);
8680 add_name_and_src_coords_attributes (decl_die, decl);
8681 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
8685 if (DECL_ABSTRACT (decl))
8686 equate_decl_number_to_die (decl, decl_die);
8688 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
8692 /* Remember a type in the incomplete_types_list. */
8695 add_incomplete_type (type)
8698 if (incomplete_types == incomplete_types_allocated)
8700 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
8701 incomplete_types_list
8702 = (tree *) xrealloc (incomplete_types_list,
8703 sizeof (tree) * incomplete_types_allocated);
8706 incomplete_types_list[incomplete_types++] = type;
8709 /* Walk through the list of incomplete types again, trying once more to
8710 emit full debugging info for them. */
8713 retry_incomplete_types ()
8717 while (incomplete_types)
8720 type = incomplete_types_list[incomplete_types];
8721 gen_type_die (type, comp_unit_die);
8725 /* Generate a DIE to represent an inlined instance of an enumeration type. */
8728 gen_inlined_enumeration_type_die (type, context_die)
8730 register dw_die_ref context_die;
8732 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
8734 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8735 be incomplete and such types are not marked. */
8736 add_abstract_origin_attribute (type_die, type);
8739 /* Generate a DIE to represent an inlined instance of a structure type. */
8742 gen_inlined_structure_type_die (type, context_die)
8744 register dw_die_ref context_die;
8746 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
8748 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8749 be incomplete and such types are not marked. */
8750 add_abstract_origin_attribute (type_die, type);
8753 /* Generate a DIE to represent an inlined instance of a union type. */
8756 gen_inlined_union_type_die (type, context_die)
8758 register dw_die_ref context_die;
8760 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
8762 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8763 be incomplete and such types are not marked. */
8764 add_abstract_origin_attribute (type_die, type);
8767 /* Generate a DIE to represent an enumeration type. Note that these DIEs
8768 include all of the information about the enumeration values also. Each
8769 enumerated type name/value is listed as a child of the enumerated type
8773 gen_enumeration_type_die (type, context_die)
8775 register dw_die_ref context_die;
8777 register dw_die_ref type_die = lookup_type_die (type);
8779 if (type_die == NULL)
8781 type_die = new_die (DW_TAG_enumeration_type,
8782 scope_die_for (type, context_die));
8783 equate_type_number_to_die (type, type_die);
8784 add_name_attribute (type_die, type_tag (type));
8786 else if (! TYPE_SIZE (type))
8789 remove_AT (type_die, DW_AT_declaration);
8791 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
8792 given enum type is incomplete, do not generate the DW_AT_byte_size
8793 attribute or the DW_AT_element_list attribute. */
8794 if (TYPE_SIZE (type))
8798 TREE_ASM_WRITTEN (type) = 1;
8799 add_byte_size_attribute (type_die, type);
8800 if (TYPE_STUB_DECL (type) != NULL_TREE)
8801 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8803 /* If the first reference to this type was as the return type of an
8804 inline function, then it may not have a parent. Fix this now. */
8805 if (type_die->die_parent == NULL)
8806 add_child_die (scope_die_for (type, context_die), type_die);
8808 for (link = TYPE_FIELDS (type);
8809 link != NULL; link = TREE_CHAIN (link))
8811 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
8813 add_name_attribute (enum_die,
8814 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
8816 if (host_integerp (TREE_VALUE (link), 0))
8818 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
8819 add_AT_int (enum_die, DW_AT_const_value,
8820 tree_low_cst (TREE_VALUE (link), 0));
8822 add_AT_unsigned (enum_die, DW_AT_const_value,
8823 tree_low_cst (TREE_VALUE (link), 0));
8828 add_AT_flag (type_die, DW_AT_declaration, 1);
8831 /* Generate a DIE to represent either a real live formal parameter decl or to
8832 represent just the type of some formal parameter position in some function
8835 Note that this routine is a bit unusual because its argument may be a
8836 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
8837 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
8838 node. If it's the former then this function is being called to output a
8839 DIE to represent a formal parameter object (or some inlining thereof). If
8840 it's the latter, then this function is only being called to output a
8841 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
8842 argument type of some subprogram type. */
8845 gen_formal_parameter_die (node, context_die)
8847 register dw_die_ref context_die;
8849 register dw_die_ref parm_die
8850 = new_die (DW_TAG_formal_parameter, context_die);
8851 register tree origin;
8853 switch (TREE_CODE_CLASS (TREE_CODE (node)))
8856 origin = decl_ultimate_origin (node);
8858 add_abstract_origin_attribute (parm_die, origin);
8861 add_name_and_src_coords_attributes (parm_die, node);
8862 add_type_attribute (parm_die, TREE_TYPE (node),
8863 TREE_READONLY (node),
8864 TREE_THIS_VOLATILE (node),
8866 if (DECL_ARTIFICIAL (node))
8867 add_AT_flag (parm_die, DW_AT_artificial, 1);
8870 equate_decl_number_to_die (node, parm_die);
8871 if (! DECL_ABSTRACT (node))
8872 add_location_or_const_value_attribute (parm_die, node);
8877 /* We were called with some kind of a ..._TYPE node. */
8878 add_type_attribute (parm_die, node, 0, 0, context_die);
8888 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
8889 at the end of an (ANSI prototyped) formal parameters list. */
8892 gen_unspecified_parameters_die (decl_or_type, context_die)
8893 register tree decl_or_type ATTRIBUTE_UNUSED;
8894 register dw_die_ref context_die;
8896 new_die (DW_TAG_unspecified_parameters, context_die);
8899 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
8900 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
8901 parameters as specified in some function type specification (except for
8902 those which appear as part of a function *definition*). */
8905 gen_formal_types_die (function_or_method_type, context_die)
8906 register tree function_or_method_type;
8907 register dw_die_ref context_die;
8910 register tree formal_type = NULL;
8911 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
8914 /* In the case where we are generating a formal types list for a C++
8915 non-static member function type, skip over the first thing on the
8916 TYPE_ARG_TYPES list because it only represents the type of the hidden
8917 `this pointer'. The debugger should be able to figure out (without
8918 being explicitly told) that this non-static member function type takes a
8919 `this pointer' and should be able to figure what the type of that hidden
8920 parameter is from the DW_AT_member attribute of the parent
8921 DW_TAG_subroutine_type DIE. */
8922 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
8923 first_parm_type = TREE_CHAIN (first_parm_type);
8926 /* Make our first pass over the list of formal parameter types and output a
8927 DW_TAG_formal_parameter DIE for each one. */
8928 for (link = first_parm_type; link; link = TREE_CHAIN (link))
8930 register dw_die_ref parm_die;
8932 formal_type = TREE_VALUE (link);
8933 if (formal_type == void_type_node)
8936 /* Output a (nameless) DIE to represent the formal parameter itself. */
8937 parm_die = gen_formal_parameter_die (formal_type, context_die);
8938 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8939 && link == first_parm_type)
8940 add_AT_flag (parm_die, DW_AT_artificial, 1);
8943 /* If this function type has an ellipsis, add a
8944 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8945 if (formal_type != void_type_node)
8946 gen_unspecified_parameters_die (function_or_method_type, context_die);
8948 /* Make our second (and final) pass over the list of formal parameter types
8949 and output DIEs to represent those types (as necessary). */
8950 for (link = TYPE_ARG_TYPES (function_or_method_type);
8952 link = TREE_CHAIN (link))
8954 formal_type = TREE_VALUE (link);
8955 if (formal_type == void_type_node)
8958 gen_type_die (formal_type, context_die);
8962 /* We want to generate the DIE for TYPE so that we can generate the
8963 die for MEMBER, which has been defined; we will need to refer back
8964 to the member declaration nested within TYPE. If we're trying to
8965 generate minimal debug info for TYPE, processing TYPE won't do the
8966 trick; we need to attach the member declaration by hand. */
8969 gen_type_die_for_member (type, member, context_die)
8971 dw_die_ref context_die;
8973 gen_type_die (type, context_die);
8975 /* If we're trying to avoid duplicate debug info, we may not have
8976 emitted the member decl for this function. Emit it now. */
8977 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
8978 && ! lookup_decl_die (member))
8980 if (decl_ultimate_origin (member))
8983 push_decl_scope (type);
8984 if (TREE_CODE (member) == FUNCTION_DECL)
8985 gen_subprogram_die (member, lookup_type_die (type));
8987 gen_variable_die (member, lookup_type_die (type));
8992 /* Generate the DWARF2 info for the "abstract" instance
8993 of a function which we may later generate inlined and/or
8994 out-of-line instances of. */
8997 gen_abstract_function (decl)
9000 register dw_die_ref old_die = lookup_decl_die (decl);
9003 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9004 /* We've already generated the abstract instance. */
9007 save_fn = current_function_decl;
9008 current_function_decl = decl;
9010 set_decl_abstract_flags (decl, 1);
9011 dwarf2out_decl (decl);
9012 set_decl_abstract_flags (decl, 0);
9014 current_function_decl = save_fn;
9017 /* Generate a DIE to represent a declared function (either file-scope or
9021 gen_subprogram_die (decl, context_die)
9023 register dw_die_ref context_die;
9025 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9026 register tree origin = decl_ultimate_origin (decl);
9027 register dw_die_ref subr_die;
9028 register rtx fp_reg;
9029 register tree fn_arg_types;
9030 register tree outer_scope;
9031 register dw_die_ref old_die = lookup_decl_die (decl);
9032 register int declaration = (current_function_decl != decl
9033 || class_scope_p (context_die));
9035 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9036 be true, if we started to generate the abstract instance of an inline,
9037 decided to output its containing class, and proceeded to emit the
9038 declaration of the inline from the member list for the class. In that
9039 case, `declaration' takes priority; we'll get back to the abstract
9040 instance when we're done with the class. */
9042 /* The class-scope declaration DIE must be the primary DIE. */
9043 if (origin && declaration && class_scope_p (context_die))
9052 if (declaration && ! local_scope_p (context_die))
9055 /* Fixup die_parent for the abstract instance of a nested
9057 if (old_die && old_die->die_parent == NULL)
9058 add_child_die (context_die, old_die);
9060 subr_die = new_die (DW_TAG_subprogram, context_die);
9061 add_abstract_origin_attribute (subr_die, origin);
9063 else if (old_die && DECL_ABSTRACT (decl)
9064 && get_AT_unsigned (old_die, DW_AT_inline))
9066 /* This must be a redefinition of an extern inline function.
9067 We can just reuse the old die here. */
9070 /* Clear out the inlined attribute and parm types. */
9071 remove_AT (subr_die, DW_AT_inline);
9072 remove_children (subr_die);
9076 register unsigned file_index
9077 = lookup_filename (DECL_SOURCE_FILE (decl));
9079 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
9081 /* ??? This can happen if there is a bug in the program, for
9082 instance, if it has duplicate function definitions. Ideally,
9083 we should detect this case and ignore it. For now, if we have
9084 already reported an error, any error at all, then assume that
9085 we got here because of a input error, not a dwarf2 bug. */
9091 /* If the definition comes from the same place as the declaration,
9092 maybe use the old DIE. We always want the DIE for this function
9093 that has the *_pc attributes to be under comp_unit_die so the
9094 debugger can find it. For inlines, that is the concrete instance,
9095 so we can use the old DIE here. For non-inline methods, we want a
9096 specification DIE at toplevel, so we need a new DIE. For local
9097 class methods, this doesn't apply; we just use the old DIE. */
9098 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
9099 || context_die == NULL)
9100 && (DECL_ARTIFICIAL (decl)
9101 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9102 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9103 == (unsigned) DECL_SOURCE_LINE (decl)))))
9107 /* Clear out the declaration attribute and the parm types. */
9108 remove_AT (subr_die, DW_AT_declaration);
9109 remove_children (subr_die);
9113 subr_die = new_die (DW_TAG_subprogram, context_die);
9114 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9115 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9116 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9117 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9118 != (unsigned) DECL_SOURCE_LINE (decl))
9120 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9125 subr_die = new_die (DW_TAG_subprogram, context_die);
9127 if (TREE_PUBLIC (decl))
9128 add_AT_flag (subr_die, DW_AT_external, 1);
9130 add_name_and_src_coords_attributes (subr_die, decl);
9131 if (debug_info_level > DINFO_LEVEL_TERSE)
9133 register tree type = TREE_TYPE (decl);
9135 add_prototyped_attribute (subr_die, type);
9136 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9139 add_pure_or_virtual_attribute (subr_die, decl);
9140 if (DECL_ARTIFICIAL (decl))
9141 add_AT_flag (subr_die, DW_AT_artificial, 1);
9142 if (TREE_PROTECTED (decl))
9143 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9144 else if (TREE_PRIVATE (decl))
9145 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9151 add_AT_flag (subr_die, DW_AT_declaration, 1);
9153 /* The first time we see a member function, it is in the context of
9154 the class to which it belongs. We make sure of this by emitting
9155 the class first. The next time is the definition, which is
9156 handled above. The two may come from the same source text. */
9157 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9158 equate_decl_number_to_die (decl, subr_die);
9160 else if (DECL_ABSTRACT (decl))
9162 if (DECL_INLINE (decl) && !flag_no_inline)
9164 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9165 inline functions, but not for extern inline functions.
9166 We can't get this completely correct because information
9167 about whether the function was declared inline is not
9169 if (DECL_DEFER_OUTPUT (decl))
9170 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9172 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9175 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9177 equate_decl_number_to_die (decl, subr_die);
9179 else if (!DECL_EXTERNAL (decl))
9181 if (origin == NULL_TREE)
9182 equate_decl_number_to_die (decl, subr_die);
9184 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9185 current_funcdef_number);
9186 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9187 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9188 current_funcdef_number);
9189 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9191 add_pubname (decl, subr_die);
9192 add_arange (decl, subr_die);
9194 #ifdef MIPS_DEBUGGING_INFO
9195 /* Add a reference to the FDE for this routine. */
9196 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9199 /* Define the "frame base" location for this routine. We use the
9200 frame pointer or stack pointer registers, since the RTL for local
9201 variables is relative to one of them. */
9203 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9204 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9207 /* ??? This fails for nested inline functions, because context_display
9208 is not part of the state saved/restored for inline functions. */
9209 if (current_function_needs_context)
9210 add_AT_location_description (subr_die, DW_AT_static_link,
9211 lookup_static_chain (decl));
9215 /* Now output descriptions of the arguments for this function. This gets
9216 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9217 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9218 `...' at the end of the formal parameter list. In order to find out if
9219 there was a trailing ellipsis or not, we must instead look at the type
9220 associated with the FUNCTION_DECL. This will be a node of type
9221 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9222 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9223 an ellipsis at the end. */
9225 /* In the case where we are describing a mere function declaration, all we
9226 need to do here (and all we *can* do here) is to describe the *types* of
9227 its formal parameters. */
9228 if (debug_info_level <= DINFO_LEVEL_TERSE)
9230 else if (declaration)
9231 gen_formal_types_die (TREE_TYPE (decl), subr_die);
9234 /* Generate DIEs to represent all known formal parameters */
9235 register tree arg_decls = DECL_ARGUMENTS (decl);
9238 /* When generating DIEs, generate the unspecified_parameters DIE
9239 instead if we come across the arg "__builtin_va_alist" */
9240 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9241 if (TREE_CODE (parm) == PARM_DECL)
9243 if (DECL_NAME (parm)
9244 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9245 "__builtin_va_alist"))
9246 gen_unspecified_parameters_die (parm, subr_die);
9248 gen_decl_die (parm, subr_die);
9251 /* Decide whether we need a unspecified_parameters DIE at the end.
9252 There are 2 more cases to do this for: 1) the ansi ... declaration -
9253 this is detectable when the end of the arg list is not a
9254 void_type_node 2) an unprototyped function declaration (not a
9255 definition). This just means that we have no info about the
9256 parameters at all. */
9257 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9258 if (fn_arg_types != NULL)
9260 /* this is the prototyped case, check for ... */
9261 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9262 gen_unspecified_parameters_die (decl, subr_die);
9264 else if (DECL_INITIAL (decl) == NULL_TREE)
9265 gen_unspecified_parameters_die (decl, subr_die);
9268 /* Output Dwarf info for all of the stuff within the body of the function
9269 (if it has one - it may be just a declaration). */
9270 outer_scope = DECL_INITIAL (decl);
9272 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9273 node created to represent a function. This outermost BLOCK actually
9274 represents the outermost binding contour for the function, i.e. the
9275 contour in which the function's formal parameters and labels get
9276 declared. Curiously, it appears that the front end doesn't actually
9277 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9278 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9279 list for the function instead.) The BLOCK_VARS list for the
9280 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9281 the function however, and we output DWARF info for those in
9282 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9283 node representing the function's outermost pair of curly braces, and
9284 any blocks used for the base and member initializers of a C++
9285 constructor function. */
9286 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
9288 current_function_has_inlines = 0;
9289 decls_for_scope (outer_scope, subr_die, 0);
9291 #if 0 && defined (MIPS_DEBUGGING_INFO)
9292 if (current_function_has_inlines)
9294 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
9295 if (! comp_unit_has_inlines)
9297 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
9298 comp_unit_has_inlines = 1;
9305 /* Generate a DIE to represent a declared data object. */
9308 gen_variable_die (decl, context_die)
9310 register dw_die_ref context_die;
9312 register tree origin = decl_ultimate_origin (decl);
9313 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
9315 dw_die_ref old_die = lookup_decl_die (decl);
9316 int declaration = (DECL_EXTERNAL (decl)
9317 || class_scope_p (context_die));
9320 add_abstract_origin_attribute (var_die, origin);
9321 /* Loop unrolling can create multiple blocks that refer to the same
9322 static variable, so we must test for the DW_AT_declaration flag. */
9323 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
9324 copy decls and set the DECL_ABSTRACT flag on them instead of
9326 else if (old_die && TREE_STATIC (decl)
9327 && get_AT_flag (old_die, DW_AT_declaration) == 1)
9329 /* This is a definition of a C++ class level static. */
9330 add_AT_die_ref (var_die, DW_AT_specification, old_die);
9331 if (DECL_NAME (decl))
9333 register unsigned file_index
9334 = lookup_filename (DECL_SOURCE_FILE (decl));
9336 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9337 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
9339 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9340 != (unsigned) DECL_SOURCE_LINE (decl))
9342 add_AT_unsigned (var_die, DW_AT_decl_line,
9343 DECL_SOURCE_LINE (decl));
9348 add_name_and_src_coords_attributes (var_die, decl);
9349 add_type_attribute (var_die, TREE_TYPE (decl),
9350 TREE_READONLY (decl),
9351 TREE_THIS_VOLATILE (decl), context_die);
9353 if (TREE_PUBLIC (decl))
9354 add_AT_flag (var_die, DW_AT_external, 1);
9356 if (DECL_ARTIFICIAL (decl))
9357 add_AT_flag (var_die, DW_AT_artificial, 1);
9359 if (TREE_PROTECTED (decl))
9360 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
9362 else if (TREE_PRIVATE (decl))
9363 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
9367 add_AT_flag (var_die, DW_AT_declaration, 1);
9369 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
9370 equate_decl_number_to_die (decl, var_die);
9372 if (! declaration && ! DECL_ABSTRACT (decl))
9374 add_location_or_const_value_attribute (var_die, decl);
9375 add_pubname (decl, var_die);
9379 /* Generate a DIE to represent a label identifier. */
9382 gen_label_die (decl, context_die)
9384 register dw_die_ref context_die;
9386 register tree origin = decl_ultimate_origin (decl);
9387 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
9389 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9390 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
9393 add_abstract_origin_attribute (lbl_die, origin);
9395 add_name_and_src_coords_attributes (lbl_die, decl);
9397 if (DECL_ABSTRACT (decl))
9398 equate_decl_number_to_die (decl, lbl_die);
9401 insn = DECL_RTL (decl);
9403 /* Deleted labels are programmer specified labels which have been
9404 eliminated because of various optimisations. We still emit them
9405 here so that it is possible to put breakpoints on them. */
9406 if (GET_CODE (insn) == CODE_LABEL
9407 || ((GET_CODE (insn) == NOTE
9408 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
9410 /* When optimization is enabled (via -O) some parts of the compiler
9411 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
9412 represent source-level labels which were explicitly declared by
9413 the user. This really shouldn't be happening though, so catch
9414 it if it ever does happen. */
9415 if (INSN_DELETED_P (insn))
9418 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
9419 ASM_GENERATE_INTERNAL_LABEL (label, label2,
9420 (unsigned) INSN_UID (insn));
9421 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
9426 /* Generate a DIE for a lexical block. */
9429 gen_lexical_block_die (stmt, context_die, depth)
9431 register dw_die_ref context_die;
9434 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
9435 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9437 if (! BLOCK_ABSTRACT (stmt))
9439 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9440 BLOCK_NUMBER (stmt));
9441 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
9442 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9443 BLOCK_NUMBER (stmt));
9444 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
9447 decls_for_scope (stmt, stmt_die, depth);
9450 /* Generate a DIE for an inlined subprogram. */
9453 gen_inlined_subroutine_die (stmt, context_die, depth)
9455 register dw_die_ref context_die;
9458 if (! BLOCK_ABSTRACT (stmt))
9460 register dw_die_ref subr_die
9461 = new_die (DW_TAG_inlined_subroutine, context_die);
9462 register tree decl = block_ultimate_origin (stmt);
9463 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9465 /* Emit info for the abstract instance first, if we haven't yet. */
9466 gen_abstract_function (decl);
9468 add_abstract_origin_attribute (subr_die, decl);
9469 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9470 BLOCK_NUMBER (stmt));
9471 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
9472 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9473 BLOCK_NUMBER (stmt));
9474 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
9475 decls_for_scope (stmt, subr_die, depth);
9476 current_function_has_inlines = 1;
9480 /* Generate a DIE for a field in a record, or structure. */
9483 gen_field_die (decl, context_die)
9485 register dw_die_ref context_die;
9487 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
9489 add_name_and_src_coords_attributes (decl_die, decl);
9490 add_type_attribute (decl_die, member_declared_type (decl),
9491 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
9494 /* If this is a bit field... */
9495 if (DECL_BIT_FIELD_TYPE (decl))
9497 add_byte_size_attribute (decl_die, decl);
9498 add_bit_size_attribute (decl_die, decl);
9499 add_bit_offset_attribute (decl_die, decl);
9502 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
9503 add_data_member_location_attribute (decl_die, decl);
9505 if (DECL_ARTIFICIAL (decl))
9506 add_AT_flag (decl_die, DW_AT_artificial, 1);
9508 if (TREE_PROTECTED (decl))
9509 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
9511 else if (TREE_PRIVATE (decl))
9512 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
9516 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9517 Use modified_type_die instead.
9518 We keep this code here just in case these types of DIEs may be needed to
9519 represent certain things in other languages (e.g. Pascal) someday. */
9521 gen_pointer_type_die (type, context_die)
9523 register dw_die_ref context_die;
9525 register dw_die_ref ptr_die
9526 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
9528 equate_type_number_to_die (type, ptr_die);
9529 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9530 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9533 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9534 Use modified_type_die instead.
9535 We keep this code here just in case these types of DIEs may be needed to
9536 represent certain things in other languages (e.g. Pascal) someday. */
9538 gen_reference_type_die (type, context_die)
9540 register dw_die_ref context_die;
9542 register dw_die_ref ref_die
9543 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
9545 equate_type_number_to_die (type, ref_die);
9546 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
9547 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9551 /* Generate a DIE for a pointer to a member type. */
9553 gen_ptr_to_mbr_type_die (type, context_die)
9555 register dw_die_ref context_die;
9557 register dw_die_ref ptr_die
9558 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
9560 equate_type_number_to_die (type, ptr_die);
9561 add_AT_die_ref (ptr_die, DW_AT_containing_type,
9562 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
9563 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9566 /* Generate the DIE for the compilation unit. */
9569 gen_compile_unit_die (filename)
9570 register const char *filename;
9572 register dw_die_ref die;
9574 const char *wd = getpwd ();
9577 die = new_die (DW_TAG_compile_unit, NULL);
9578 add_name_attribute (die, filename);
9580 if (wd != NULL && filename[0] != DIR_SEPARATOR)
9581 add_AT_string (die, DW_AT_comp_dir, wd);
9583 sprintf (producer, "%s %s", language_string, version_string);
9585 #ifdef MIPS_DEBUGGING_INFO
9586 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
9587 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
9588 not appear in the producer string, the debugger reaches the conclusion
9589 that the object file is stripped and has no debugging information.
9590 To get the MIPS/SGI debugger to believe that there is debugging
9591 information in the object file, we add a -g to the producer string. */
9592 if (debug_info_level > DINFO_LEVEL_TERSE)
9593 strcat (producer, " -g");
9596 add_AT_string (die, DW_AT_producer, producer);
9598 if (strcmp (language_string, "GNU C++") == 0)
9599 language = DW_LANG_C_plus_plus;
9600 else if (strcmp (language_string, "GNU Ada") == 0)
9601 language = DW_LANG_Ada83;
9602 else if (strcmp (language_string, "GNU F77") == 0)
9603 language = DW_LANG_Fortran77;
9604 else if (strcmp (language_string, "GNU Pascal") == 0)
9605 language = DW_LANG_Pascal83;
9606 else if (strcmp (language_string, "GNU Java") == 0)
9607 language = DW_LANG_Java;
9608 else if (flag_traditional)
9609 language = DW_LANG_C;
9611 language = DW_LANG_C89;
9613 add_AT_unsigned (die, DW_AT_language, language);
9618 /* Generate a DIE for a string type. */
9621 gen_string_type_die (type, context_die)
9623 register dw_die_ref context_die;
9625 register dw_die_ref type_die
9626 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
9628 equate_type_number_to_die (type, type_die);
9630 /* Fudge the string length attribute for now. */
9632 /* TODO: add string length info.
9633 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
9634 bound_representation (upper_bound, 0, 'u'); */
9637 /* Generate the DIE for a base class. */
9640 gen_inheritance_die (binfo, context_die)
9641 register tree binfo;
9642 register dw_die_ref context_die;
9644 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
9646 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
9647 add_data_member_location_attribute (die, binfo);
9649 if (TREE_VIA_VIRTUAL (binfo))
9650 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9651 if (TREE_VIA_PUBLIC (binfo))
9652 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
9653 else if (TREE_VIA_PROTECTED (binfo))
9654 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
9657 /* Generate a DIE for a class member. */
9660 gen_member_die (type, context_die)
9662 register dw_die_ref context_die;
9664 register tree member;
9667 /* If this is not an incomplete type, output descriptions of each of its
9668 members. Note that as we output the DIEs necessary to represent the
9669 members of this record or union type, we will also be trying to output
9670 DIEs to represent the *types* of those members. However the `type'
9671 function (above) will specifically avoid generating type DIEs for member
9672 types *within* the list of member DIEs for this (containing) type execpt
9673 for those types (of members) which are explicitly marked as also being
9674 members of this (containing) type themselves. The g++ front- end can
9675 force any given type to be treated as a member of some other
9676 (containing) type by setting the TYPE_CONTEXT of the given (member) type
9677 to point to the TREE node representing the appropriate (containing)
9680 /* First output info about the base classes. */
9681 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
9683 register tree bases = TYPE_BINFO_BASETYPES (type);
9684 register int n_bases = TREE_VEC_LENGTH (bases);
9687 for (i = 0; i < n_bases; i++)
9688 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
9691 /* Now output info about the data members and type members. */
9692 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
9694 /* If we thought we were generating minimal debug info for TYPE
9695 and then changed our minds, some of the member declarations
9696 may have already been defined. Don't define them again, but
9697 do put them in the right order. */
9699 child = lookup_decl_die (member);
9701 splice_child_die (context_die, child);
9703 gen_decl_die (member, context_die);
9706 /* Now output info about the function members (if any). */
9707 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
9709 child = lookup_decl_die (member);
9711 splice_child_die (context_die, child);
9713 gen_decl_die (member, context_die);
9717 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
9718 is set, we pretend that the type was never defined, so we only get the
9719 member DIEs needed by later specification DIEs. */
9722 gen_struct_or_union_type_die (type, context_die)
9724 register dw_die_ref context_die;
9726 register dw_die_ref type_die = lookup_type_die (type);
9727 register dw_die_ref scope_die = 0;
9728 register int nested = 0;
9729 int complete = (TYPE_SIZE (type)
9730 && (! TYPE_STUB_DECL (type)
9731 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
9733 if (type_die && ! complete)
9736 if (TYPE_CONTEXT (type) != NULL_TREE
9737 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
9740 scope_die = scope_die_for (type, context_die);
9742 if (! type_die || (nested && scope_die == comp_unit_die))
9743 /* First occurrence of type or toplevel definition of nested class. */
9745 register dw_die_ref old_die = type_die;
9747 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
9748 ? DW_TAG_structure_type : DW_TAG_union_type,
9750 equate_type_number_to_die (type, type_die);
9752 add_AT_die_ref (type_die, DW_AT_specification, old_die);
9754 add_name_attribute (type_die, type_tag (type));
9757 remove_AT (type_die, DW_AT_declaration);
9759 /* If this type has been completed, then give it a byte_size attribute and
9760 then give a list of members. */
9763 /* Prevent infinite recursion in cases where the type of some member of
9764 this type is expressed in terms of this type itself. */
9765 TREE_ASM_WRITTEN (type) = 1;
9766 add_byte_size_attribute (type_die, type);
9767 if (TYPE_STUB_DECL (type) != NULL_TREE)
9768 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9770 /* If the first reference to this type was as the return type of an
9771 inline function, then it may not have a parent. Fix this now. */
9772 if (type_die->die_parent == NULL)
9773 add_child_die (scope_die, type_die);
9775 push_decl_scope (type);
9776 gen_member_die (type, type_die);
9779 /* GNU extension: Record what type our vtable lives in. */
9780 if (TYPE_VFIELD (type))
9782 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
9784 gen_type_die (vtype, context_die);
9785 add_AT_die_ref (type_die, DW_AT_containing_type,
9786 lookup_type_die (vtype));
9791 add_AT_flag (type_die, DW_AT_declaration, 1);
9793 /* We don't need to do this for function-local types. */
9794 if (! decl_function_context (TYPE_STUB_DECL (type)))
9795 add_incomplete_type (type);
9799 /* Generate a DIE for a subroutine _type_. */
9802 gen_subroutine_type_die (type, context_die)
9804 register dw_die_ref context_die;
9806 register tree return_type = TREE_TYPE (type);
9807 register dw_die_ref subr_die
9808 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
9810 equate_type_number_to_die (type, subr_die);
9811 add_prototyped_attribute (subr_die, type);
9812 add_type_attribute (subr_die, return_type, 0, 0, context_die);
9813 gen_formal_types_die (type, subr_die);
9816 /* Generate a DIE for a type definition */
9819 gen_typedef_die (decl, context_die)
9821 register dw_die_ref context_die;
9823 register dw_die_ref type_die;
9824 register tree origin;
9826 if (TREE_ASM_WRITTEN (decl))
9828 TREE_ASM_WRITTEN (decl) = 1;
9830 type_die = new_die (DW_TAG_typedef, context_die);
9831 origin = decl_ultimate_origin (decl);
9833 add_abstract_origin_attribute (type_die, origin);
9837 add_name_and_src_coords_attributes (type_die, decl);
9838 if (DECL_ORIGINAL_TYPE (decl))
9840 type = DECL_ORIGINAL_TYPE (decl);
9842 if (type == TREE_TYPE (decl))
9845 equate_type_number_to_die (TREE_TYPE (decl), type_die);
9848 type = TREE_TYPE (decl);
9849 add_type_attribute (type_die, type, TREE_READONLY (decl),
9850 TREE_THIS_VOLATILE (decl), context_die);
9853 if (DECL_ABSTRACT (decl))
9854 equate_decl_number_to_die (decl, type_die);
9857 /* Generate a type description DIE. */
9860 gen_type_die (type, context_die)
9862 register dw_die_ref context_die;
9866 if (type == NULL_TREE || type == error_mark_node)
9869 /* We are going to output a DIE to represent the unqualified version of
9870 this type (i.e. without any const or volatile qualifiers) so get the
9871 main variant (i.e. the unqualified version) of this type now. */
9872 type = type_main_variant (type);
9874 if (TREE_ASM_WRITTEN (type))
9877 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9878 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
9880 TREE_ASM_WRITTEN (type) = 1;
9881 gen_decl_die (TYPE_NAME (type), context_die);
9885 switch (TREE_CODE (type))
9891 case REFERENCE_TYPE:
9892 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
9893 ensures that the gen_type_die recursion will terminate even if the
9894 type is recursive. Recursive types are possible in Ada. */
9895 /* ??? We could perhaps do this for all types before the switch
9897 TREE_ASM_WRITTEN (type) = 1;
9899 /* For these types, all that is required is that we output a DIE (or a
9900 set of DIEs) to represent the "basis" type. */
9901 gen_type_die (TREE_TYPE (type), context_die);
9905 /* This code is used for C++ pointer-to-data-member types.
9906 Output a description of the relevant class type. */
9907 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
9909 /* Output a description of the type of the object pointed to. */
9910 gen_type_die (TREE_TYPE (type), context_die);
9912 /* Now output a DIE to represent this pointer-to-data-member type
9914 gen_ptr_to_mbr_type_die (type, context_die);
9918 gen_type_die (TYPE_DOMAIN (type), context_die);
9919 gen_set_type_die (type, context_die);
9923 gen_type_die (TREE_TYPE (type), context_die);
9924 abort (); /* No way to represent these in Dwarf yet! */
9928 /* Force out return type (in case it wasn't forced out already). */
9929 gen_type_die (TREE_TYPE (type), context_die);
9930 gen_subroutine_type_die (type, context_die);
9934 /* Force out return type (in case it wasn't forced out already). */
9935 gen_type_die (TREE_TYPE (type), context_die);
9936 gen_subroutine_type_die (type, context_die);
9940 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
9942 gen_type_die (TREE_TYPE (type), context_die);
9943 gen_string_type_die (type, context_die);
9946 gen_array_type_die (type, context_die);
9950 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
9956 case QUAL_UNION_TYPE:
9957 /* If this is a nested type whose containing class hasn't been
9958 written out yet, writing it out will cover this one, too.
9959 This does not apply to instantiations of member class templates;
9960 they need to be added to the containing class as they are
9961 generated. FIXME: This hurts the idea of combining type decls
9962 from multiple TUs, since we can't predict what set of template
9963 instantiations we'll get. */
9964 if (TYPE_CONTEXT (type)
9965 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9966 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9968 gen_type_die (TYPE_CONTEXT (type), context_die);
9970 if (TREE_ASM_WRITTEN (type))
9973 /* If that failed, attach ourselves to the stub. */
9974 push_decl_scope (TYPE_CONTEXT (type));
9975 context_die = lookup_type_die (TYPE_CONTEXT (type));
9981 if (TREE_CODE (type) == ENUMERAL_TYPE)
9982 gen_enumeration_type_die (type, context_die);
9984 gen_struct_or_union_type_die (type, context_die);
9989 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9990 it up if it is ever completed. gen_*_type_die will set it for us
9991 when appropriate. */
10000 /* No DIEs needed for fundamental types. */
10004 /* No Dwarf representation currently defined. */
10011 TREE_ASM_WRITTEN (type) = 1;
10014 /* Generate a DIE for a tagged type instantiation. */
10017 gen_tagged_type_instantiation_die (type, context_die)
10018 register tree type;
10019 register dw_die_ref context_die;
10021 if (type == NULL_TREE || type == error_mark_node)
10024 /* We are going to output a DIE to represent the unqualified version of
10025 this type (i.e. without any const or volatile qualifiers) so make sure
10026 that we have the main variant (i.e. the unqualified version) of this
10028 if (type != type_main_variant (type))
10031 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10032 an instance of an unresolved type. */
10034 switch (TREE_CODE (type))
10039 case ENUMERAL_TYPE:
10040 gen_inlined_enumeration_type_die (type, context_die);
10044 gen_inlined_structure_type_die (type, context_die);
10048 case QUAL_UNION_TYPE:
10049 gen_inlined_union_type_die (type, context_die);
10057 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10058 things which are local to the given block. */
10061 gen_block_die (stmt, context_die, depth)
10062 register tree stmt;
10063 register dw_die_ref context_die;
10066 register int must_output_die = 0;
10067 register tree origin;
10068 register tree decl;
10069 register enum tree_code origin_code;
10071 /* Ignore blocks never really used to make RTL. */
10073 if (stmt == NULL_TREE || !TREE_USED (stmt)
10074 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10077 /* Determine the "ultimate origin" of this block. This block may be an
10078 inlined instance of an inlined instance of inline function, so we have
10079 to trace all of the way back through the origin chain to find out what
10080 sort of node actually served as the original seed for the creation of
10081 the current block. */
10082 origin = block_ultimate_origin (stmt);
10083 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10085 /* Determine if we need to output any Dwarf DIEs at all to represent this
10087 if (origin_code == FUNCTION_DECL)
10088 /* The outer scopes for inlinings *must* always be represented. We
10089 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10090 must_output_die = 1;
10093 /* In the case where the current block represents an inlining of the
10094 "body block" of an inline function, we must *NOT* output any DIE for
10095 this block because we have already output a DIE to represent the
10096 whole inlined function scope and the "body block" of any function
10097 doesn't really represent a different scope according to ANSI C
10098 rules. So we check here to make sure that this block does not
10099 represent a "body block inlining" before trying to set the
10100 `must_output_die' flag. */
10101 if (! is_body_block (origin ? origin : stmt))
10103 /* Determine if this block directly contains any "significant"
10104 local declarations which we will need to output DIEs for. */
10105 if (debug_info_level > DINFO_LEVEL_TERSE)
10106 /* We are not in terse mode so *any* local declaration counts
10107 as being a "significant" one. */
10108 must_output_die = (BLOCK_VARS (stmt) != NULL);
10110 /* We are in terse mode, so only local (nested) function
10111 definitions count as "significant" local declarations. */
10112 for (decl = BLOCK_VARS (stmt);
10113 decl != NULL; decl = TREE_CHAIN (decl))
10114 if (TREE_CODE (decl) == FUNCTION_DECL
10115 && DECL_INITIAL (decl))
10117 must_output_die = 1;
10123 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10124 DIE for any block which contains no significant local declarations at
10125 all. Rather, in such cases we just call `decls_for_scope' so that any
10126 needed Dwarf info for any sub-blocks will get properly generated. Note
10127 that in terse mode, our definition of what constitutes a "significant"
10128 local declaration gets restricted to include only inlined function
10129 instances and local (nested) function definitions. */
10130 if (must_output_die)
10132 if (origin_code == FUNCTION_DECL)
10133 gen_inlined_subroutine_die (stmt, context_die, depth);
10135 gen_lexical_block_die (stmt, context_die, depth);
10138 decls_for_scope (stmt, context_die, depth);
10141 /* Generate all of the decls declared within a given scope and (recursively)
10142 all of its sub-blocks. */
10145 decls_for_scope (stmt, context_die, depth)
10146 register tree stmt;
10147 register dw_die_ref context_die;
10150 register tree decl;
10151 register tree subblocks;
10153 /* Ignore blocks never really used to make RTL. */
10154 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10157 /* Output the DIEs to represent all of the data objects and typedefs
10158 declared directly within this block but not within any nested
10159 sub-blocks. Also, nested function and tag DIEs have been
10160 generated with a parent of NULL; fix that up now. */
10161 for (decl = BLOCK_VARS (stmt);
10162 decl != NULL; decl = TREE_CHAIN (decl))
10164 register dw_die_ref die;
10166 if (TREE_CODE (decl) == FUNCTION_DECL)
10167 die = lookup_decl_die (decl);
10168 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10169 die = lookup_type_die (TREE_TYPE (decl));
10173 if (die != NULL && die->die_parent == NULL)
10174 add_child_die (context_die, die);
10176 gen_decl_die (decl, context_die);
10179 /* Output the DIEs to represent all sub-blocks (and the items declared
10180 therein) of this block. */
10181 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10183 subblocks = BLOCK_CHAIN (subblocks))
10184 gen_block_die (subblocks, context_die, depth + 1);
10187 /* Is this a typedef we can avoid emitting? */
10190 is_redundant_typedef (decl)
10191 register tree decl;
10193 if (TYPE_DECL_IS_STUB (decl))
10196 if (DECL_ARTIFICIAL (decl)
10197 && DECL_CONTEXT (decl)
10198 && is_tagged_type (DECL_CONTEXT (decl))
10199 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10200 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10201 /* Also ignore the artificial member typedef for the class name. */
10207 /* Generate Dwarf debug information for a decl described by DECL. */
10210 gen_decl_die (decl, context_die)
10211 register tree decl;
10212 register dw_die_ref context_die;
10214 register tree origin;
10216 if (TREE_CODE (decl) == ERROR_MARK)
10219 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10220 if (DECL_IGNORED_P (decl))
10223 switch (TREE_CODE (decl))
10226 /* The individual enumerators of an enum type get output when we output
10227 the Dwarf representation of the relevant enum type itself. */
10230 case FUNCTION_DECL:
10231 /* Don't output any DIEs to represent mere function declarations,
10232 unless they are class members or explicit block externs. */
10233 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10234 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10237 /* If we're emitting an out-of-line copy of an inline function,
10238 emit info for the abstract instance and set up to refer to it. */
10239 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10240 && ! class_scope_p (context_die)
10241 /* gen_abstract_function won't emit a die if this is just a
10242 declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10243 that case, because that works only if we have a die. */
10244 && DECL_INITIAL (decl) != NULL_TREE)
10246 gen_abstract_function (decl);
10247 set_decl_origin_self (decl);
10250 if (debug_info_level > DINFO_LEVEL_TERSE)
10252 /* Before we describe the FUNCTION_DECL itself, make sure that we
10253 have described its return type. */
10254 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10256 /* And its virtual context. */
10257 if (DECL_VINDEX (decl) != NULL_TREE)
10258 gen_type_die (DECL_CONTEXT (decl), context_die);
10260 /* And its containing type. */
10261 origin = decl_class_context (decl);
10262 if (origin != NULL_TREE)
10263 gen_type_die_for_member (origin, decl, context_die);
10266 /* Now output a DIE to represent the function itself. */
10267 gen_subprogram_die (decl, context_die);
10271 /* If we are in terse mode, don't generate any DIEs to represent any
10272 actual typedefs. */
10273 if (debug_info_level <= DINFO_LEVEL_TERSE)
10276 /* In the special case of a TYPE_DECL node representing the
10277 declaration of some type tag, if the given TYPE_DECL is marked as
10278 having been instantiated from some other (original) TYPE_DECL node
10279 (e.g. one which was generated within the original definition of an
10280 inline function) we have to generate a special (abbreviated)
10281 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10283 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10285 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10289 if (is_redundant_typedef (decl))
10290 gen_type_die (TREE_TYPE (decl), context_die);
10292 /* Output a DIE to represent the typedef itself. */
10293 gen_typedef_die (decl, context_die);
10297 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10298 gen_label_die (decl, context_die);
10302 /* If we are in terse mode, don't generate any DIEs to represent any
10303 variable declarations or definitions. */
10304 if (debug_info_level <= DINFO_LEVEL_TERSE)
10307 /* Output any DIEs that are needed to specify the type of this data
10309 gen_type_die (TREE_TYPE (decl), context_die);
10311 /* And its containing type. */
10312 origin = decl_class_context (decl);
10313 if (origin != NULL_TREE)
10314 gen_type_die_for_member (origin, decl, context_die);
10316 /* Now output the DIE to represent the data object itself. This gets
10317 complicated because of the possibility that the VAR_DECL really
10318 represents an inlined instance of a formal parameter for an inline
10320 origin = decl_ultimate_origin (decl);
10321 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
10322 gen_formal_parameter_die (decl, context_die);
10324 gen_variable_die (decl, context_die);
10328 /* Ignore the nameless fields that are used to skip bits, but
10329 handle C++ anonymous unions. */
10330 if (DECL_NAME (decl) != NULL_TREE
10331 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
10333 gen_type_die (member_declared_type (decl), context_die);
10334 gen_field_die (decl, context_die);
10339 gen_type_die (TREE_TYPE (decl), context_die);
10340 gen_formal_parameter_die (decl, context_die);
10343 case NAMESPACE_DECL:
10344 /* Ignore for now. */
10352 /* Add Ada "use" clause information for SGI Workshop debugger. */
10355 dwarf2out_add_library_unit_info (filename, context_list)
10356 const char *filename;
10357 const char *context_list;
10359 unsigned int file_index;
10361 if (filename != NULL)
10363 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
10364 tree context_list_decl
10365 = build_decl (LABEL_DECL, get_identifier (context_list),
10368 TREE_PUBLIC (context_list_decl) = TRUE;
10369 add_name_attribute (unit_die, context_list);
10370 file_index = lookup_filename (filename);
10371 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
10372 add_pubname (context_list_decl, unit_die);
10376 /* Write the debugging output for DECL. */
10379 dwarf2out_decl (decl)
10380 register tree decl;
10382 register dw_die_ref context_die = comp_unit_die;
10384 if (TREE_CODE (decl) == ERROR_MARK)
10387 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10388 if (DECL_IGNORED_P (decl))
10391 switch (TREE_CODE (decl))
10393 case FUNCTION_DECL:
10394 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
10395 builtin function. Explicit programmer-supplied declarations of
10396 these same functions should NOT be ignored however. */
10397 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
10400 /* What we would really like to do here is to filter out all mere
10401 file-scope declarations of file-scope functions which are never
10402 referenced later within this translation unit (and keep all of ones
10403 that *are* referenced later on) but we aren't clairvoyant, so we have
10404 no idea which functions will be referenced in the future (i.e. later
10405 on within the current translation unit). So here we just ignore all
10406 file-scope function declarations which are not also definitions. If
10407 and when the debugger needs to know something about these functions,
10408 it will have to hunt around and find the DWARF information associated
10409 with the definition of the function. Note that we can't just check
10410 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
10411 definitions and which ones represent mere declarations. We have to
10412 check `DECL_INITIAL' instead. That's because the C front-end
10413 supports some weird semantics for "extern inline" function
10414 definitions. These can get inlined within the current translation
10415 unit (an thus, we need to generate DWARF info for their abstract
10416 instances so that the DWARF info for the concrete inlined instances
10417 can have something to refer to) but the compiler never generates any
10418 out-of-lines instances of such things (despite the fact that they
10419 *are* definitions). The important point is that the C front-end
10420 marks these "extern inline" functions as DECL_EXTERNAL, but we need
10421 to generate DWARF for them anyway. Note that the C++ front-end also
10422 plays some similar games for inline function definitions appearing
10423 within include files which also contain
10424 `#pragma interface' pragmas. */
10425 if (DECL_INITIAL (decl) == NULL_TREE)
10428 /* If we're a nested function, initially use a parent of NULL; if we're
10429 a plain function, this will be fixed up in decls_for_scope. If
10430 we're a method, it will be ignored, since we already have a DIE. */
10431 if (decl_function_context (decl))
10432 context_die = NULL;
10437 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
10438 declaration and if the declaration was never even referenced from
10439 within this entire compilation unit. We suppress these DIEs in
10440 order to save space in the .debug section (by eliminating entries
10441 which are probably useless). Note that we must not suppress
10442 block-local extern declarations (whether used or not) because that
10443 would screw-up the debugger's name lookup mechanism and cause it to
10444 miss things which really ought to be in scope at a given point. */
10445 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
10448 /* If we are in terse mode, don't generate any DIEs to represent any
10449 variable declarations or definitions. */
10450 if (debug_info_level <= DINFO_LEVEL_TERSE)
10455 /* Don't emit stubs for types unless they are needed by other DIEs. */
10456 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
10459 /* Don't bother trying to generate any DIEs to represent any of the
10460 normal built-in types for the language we are compiling. */
10461 if (DECL_SOURCE_LINE (decl) == 0)
10463 /* OK, we need to generate one for `bool' so GDB knows what type
10464 comparisons have. */
10465 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
10466 == DW_LANG_C_plus_plus)
10467 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
10468 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
10473 /* If we are in terse mode, don't generate any DIEs for types. */
10474 if (debug_info_level <= DINFO_LEVEL_TERSE)
10477 /* If we're a function-scope tag, initially use a parent of NULL;
10478 this will be fixed up in decls_for_scope. */
10479 if (decl_function_context (decl))
10480 context_die = NULL;
10488 gen_decl_die (decl, context_die);
10491 /* Output a marker (i.e. a label) for the beginning of the generated code for
10492 a lexical block. */
10495 dwarf2out_begin_block (blocknum)
10496 register unsigned blocknum;
10498 function_section (current_function_decl);
10499 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
10502 /* Output a marker (i.e. a label) for the end of the generated code for a
10506 dwarf2out_end_block (blocknum)
10507 register unsigned blocknum;
10509 function_section (current_function_decl);
10510 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
10513 /* Returns nonzero if it is appropriate not to emit any debugging
10514 information for BLOCK, because it doesn't contain any instructions.
10516 Don't allow this for blocks with nested functions or local classes
10517 as we would end up with orphans, and in the presence of scheduling
10518 we may end up calling them anyway. */
10521 dwarf2out_ignore_block (block)
10525 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
10526 if (TREE_CODE (decl) == FUNCTION_DECL
10527 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
10532 /* Output a marker (i.e. a label) at a point in the assembly code which
10533 corresponds to a given source level label. */
10536 dwarf2out_label (insn)
10539 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10541 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10543 function_section (current_function_decl);
10544 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
10545 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
10546 (unsigned) INSN_UID (insn));
10550 /* Lookup a filename (in the list of filenames that we know about here in
10551 dwarf2out.c) and return its "index". The index of each (known) filename is
10552 just a unique number which is associated with only that one filename.
10553 We need such numbers for the sake of generating labels
10554 (in the .debug_sfnames section) and references to those
10555 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
10556 If the filename given as an argument is not found in our current list,
10557 add it to the list and assign it the next available unique index number.
10558 In order to speed up searches, we remember the index of the filename
10559 was looked up last. This handles the majority of all searches. */
10562 lookup_filename (file_name)
10563 const char *file_name;
10565 static unsigned last_file_lookup_index = 0;
10566 register unsigned i;
10568 /* Check to see if the file name that was searched on the previous call
10569 matches this file name. If so, return the index. */
10570 if (last_file_lookup_index != 0)
10571 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
10572 return last_file_lookup_index;
10574 /* Didn't match the previous lookup, search the table */
10575 for (i = 1; i < file_table_in_use; ++i)
10576 if (strcmp (file_name, file_table[i]) == 0)
10578 last_file_lookup_index = i;
10582 /* Prepare to add a new table entry by making sure there is enough space in
10583 the table to do so. If not, expand the current table. */
10584 if (file_table_in_use == file_table_allocated)
10586 file_table_allocated += FILE_TABLE_INCREMENT;
10588 = (char **) xrealloc (file_table,
10589 file_table_allocated * sizeof (char *));
10592 /* Add the new entry to the end of the filename table. */
10593 file_table[file_table_in_use] = xstrdup (file_name);
10594 last_file_lookup_index = file_table_in_use++;
10596 return last_file_lookup_index;
10599 /* Output a label to mark the beginning of a source code line entry
10600 and record information relating to this source line, in
10601 'line_info_table' for later output of the .debug_line section. */
10604 dwarf2out_line (filename, line)
10605 register const char *filename;
10606 register unsigned line;
10608 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10610 function_section (current_function_decl);
10612 if (DWARF2_ASM_LINE_DEBUG_INFO)
10614 static const char *lastfile;
10616 /* Emit the .file and .loc directives understood by GNU as. */
10617 if (lastfile == 0 || strcmp (filename, lastfile))
10620 ggc_add_string_root ((char **) &lastfile, 1);
10622 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
10623 lastfile = filename;
10626 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
10628 /* Indicate that line number info exists. */
10629 ++line_info_table_in_use;
10631 /* Indicate that multiple line number tables exist. */
10632 if (DECL_SECTION_NAME (current_function_decl))
10633 ++separate_line_info_table_in_use;
10635 else if (DECL_SECTION_NAME (current_function_decl))
10637 register dw_separate_line_info_ref line_info;
10638 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
10639 separate_line_info_table_in_use);
10640 if (flag_debug_asm)
10641 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
10642 fputc ('\n', asm_out_file);
10644 /* expand the line info table if necessary */
10645 if (separate_line_info_table_in_use
10646 == separate_line_info_table_allocated)
10648 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10649 separate_line_info_table
10650 = (dw_separate_line_info_ref)
10651 xrealloc (separate_line_info_table,
10652 separate_line_info_table_allocated
10653 * sizeof (dw_separate_line_info_entry));
10656 /* Add the new entry at the end of the line_info_table. */
10658 = &separate_line_info_table[separate_line_info_table_in_use++];
10659 line_info->dw_file_num = lookup_filename (filename);
10660 line_info->dw_line_num = line;
10661 line_info->function = current_funcdef_number;
10665 register dw_line_info_ref line_info;
10667 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
10668 line_info_table_in_use);
10669 if (flag_debug_asm)
10670 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
10671 fputc ('\n', asm_out_file);
10673 /* Expand the line info table if necessary. */
10674 if (line_info_table_in_use == line_info_table_allocated)
10676 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10678 = (dw_line_info_ref)
10679 xrealloc (line_info_table,
10680 (line_info_table_allocated
10681 * sizeof (dw_line_info_entry)));
10684 /* Add the new entry at the end of the line_info_table. */
10685 line_info = &line_info_table[line_info_table_in_use++];
10686 line_info->dw_file_num = lookup_filename (filename);
10687 line_info->dw_line_num = line;
10692 /* Record the beginning of a new source file, for later output
10693 of the .debug_macinfo section. At present, unimplemented. */
10696 dwarf2out_start_source_file (filename)
10697 register const char *filename ATTRIBUTE_UNUSED;
10699 if (flag_eliminate_dwarf2_dups)
10701 /* Record the beginning of the file for break_out_includes. */
10702 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
10703 add_AT_string (bincl_die, DW_AT_name, filename);
10707 /* Record the end of a source file, for later output
10708 of the .debug_macinfo section. At present, unimplemented. */
10711 dwarf2out_end_source_file ()
10713 if (flag_eliminate_dwarf2_dups)
10715 /* Record the end of the file for break_out_includes. */
10716 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
10720 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10721 the tail part of the directive line, i.e. the part which is past the
10722 initial whitespace, #, whitespace, directive-name, whitespace part. */
10725 dwarf2out_define (lineno, buffer)
10726 register unsigned lineno ATTRIBUTE_UNUSED;
10727 register const char *buffer ATTRIBUTE_UNUSED;
10729 static int initialized = 0;
10732 dwarf2out_start_source_file (primary_filename);
10737 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10738 the tail part of the directive line, i.e. the part which is past the
10739 initial whitespace, #, whitespace, directive-name, whitespace part. */
10742 dwarf2out_undef (lineno, buffer)
10743 register unsigned lineno ATTRIBUTE_UNUSED;
10744 register const char *buffer ATTRIBUTE_UNUSED;
10748 /* Set up for Dwarf output at the start of compilation. */
10751 dwarf2out_init (asm_out_file, main_input_filename)
10752 register FILE *asm_out_file;
10753 register const char *main_input_filename;
10755 /* Remember the name of the primary input file. */
10756 primary_filename = main_input_filename;
10758 /* Allocate the initial hunk of the file_table. */
10759 file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
10760 file_table_allocated = FILE_TABLE_INCREMENT;
10762 /* Skip the first entry - file numbers begin at 1. */
10763 file_table_in_use = 1;
10765 /* Allocate the initial hunk of the decl_die_table. */
10767 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
10768 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
10769 decl_die_table_in_use = 0;
10771 /* Allocate the initial hunk of the decl_scope_table. */
10773 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
10774 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
10775 decl_scope_depth = 0;
10777 /* Allocate the initial hunk of the abbrev_die_table. */
10779 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
10780 sizeof (dw_die_ref));
10781 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
10782 /* Zero-th entry is allocated, but unused */
10783 abbrev_die_table_in_use = 1;
10785 /* Allocate the initial hunk of the line_info_table. */
10787 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
10788 sizeof (dw_line_info_entry));
10789 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
10790 /* Zero-th entry is allocated, but unused */
10791 line_info_table_in_use = 1;
10793 /* Generate the initial DIE for the .debug section. Note that the (string)
10794 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
10795 will (typically) be a relative pathname and that this pathname should be
10796 taken as being relative to the directory from which the compiler was
10797 invoked when the given (base) source file was compiled. */
10798 comp_unit_die = gen_compile_unit_die (main_input_filename);
10802 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
10803 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
10806 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
10807 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
10808 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
10809 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
10811 strcpy (text_section_label, stripattributes (TEXT_SECTION));
10812 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
10813 DEBUG_INFO_SECTION_LABEL, 0);
10814 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
10815 DEBUG_LINE_SECTION_LABEL, 0);
10817 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
10818 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
10819 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
10821 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
10822 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
10824 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
10825 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
10826 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
10827 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
10830 /* Output stuff that dwarf requires at the end of every file,
10831 and generate the DWARF-2 debugging info. */
10834 dwarf2out_finish ()
10836 limbo_die_node *node, *next_node;
10839 /* Traverse the limbo die list, and add parent/child links. The only
10840 dies without parents that should be here are concrete instances of
10841 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
10842 For concrete instances, we can get the parent die from the abstract
10844 for (node = limbo_die_list; node; node = next_node)
10846 next_node = node->next;
10849 if (die->die_parent == NULL)
10851 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
10853 add_child_die (origin->die_parent, die);
10854 else if (die == comp_unit_die)
10861 limbo_die_list = NULL;
10863 /* Walk through the list of incomplete types again, trying once more to
10864 emit full debugging info for them. */
10865 retry_incomplete_types ();
10867 /* We need to reverse all the dies before break_out_includes, or
10868 we'll see the end of an include file before the beginning. */
10869 reverse_all_dies (comp_unit_die);
10871 /* Generate separate CUs for each of the include files we've seen.
10872 They will go into limbo_die_list. */
10873 if (flag_eliminate_dwarf2_dups)
10874 break_out_includes (comp_unit_die);
10876 /* Traverse the DIE's and add add sibling attributes to those DIE's
10877 that have children. */
10878 add_sibling_attributes (comp_unit_die);
10879 for (node = limbo_die_list; node; node = node->next)
10880 add_sibling_attributes (node->die);
10882 /* Output a terminator label for the .text section. */
10883 fputc ('\n', asm_out_file);
10884 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
10885 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
10888 /* Output a terminator label for the .data section. */
10889 fputc ('\n', asm_out_file);
10890 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
10891 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
10893 /* Output a terminator label for the .bss section. */
10894 fputc ('\n', asm_out_file);
10895 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
10896 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
10899 /* Output the source line correspondence table. */
10900 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
10902 if (! DWARF2_ASM_LINE_DEBUG_INFO)
10904 fputc ('\n', asm_out_file);
10905 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
10906 output_line_info ();
10909 /* We can only use the low/high_pc attributes if all of the code
10911 if (separate_line_info_table_in_use == 0)
10913 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
10914 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
10917 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
10918 debug_line_section_label);
10921 #if 0 /* unimplemented */
10922 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
10923 add_AT_unsigned (die, DW_AT_macro_info, 0);
10926 /* Output all of the compilation units. We put the main one last so that
10927 the offsets are available to output_pubnames. */
10928 for (node = limbo_die_list; node; node = node->next)
10929 output_comp_unit (node->die);
10930 output_comp_unit (comp_unit_die);
10932 /* Output the abbreviation table. */
10933 fputc ('\n', asm_out_file);
10934 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
10935 output_abbrev_section ();
10937 if (pubname_table_in_use)
10939 /* Output public names table. */
10940 fputc ('\n', asm_out_file);
10941 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
10942 output_pubnames ();
10945 /* We only put functions in the arange table, so don't write it out if
10946 we don't have any. */
10947 if (fde_table_in_use)
10949 /* Output the address range information. */
10950 fputc ('\n', asm_out_file);
10951 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
10955 #endif /* DWARF2_DEBUGGING_INFO */