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 void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
234 static void output_call_frame_info PARAMS ((int));
235 static void dwarf2out_stack_adjust PARAMS ((rtx));
236 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
238 /* Support for complex CFA locations. */
239 static void output_cfa_loc PARAMS ((dw_cfi_ref));
240 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
241 struct dw_loc_descr_struct *));
242 static struct dw_loc_descr_struct *build_cfa_loc
243 PARAMS ((dw_cfa_location *));
244 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
246 /* Definitions of defaults for assembler-dependent names of various
247 pseudo-ops and section names.
248 Theses may be overridden in the tm.h file (if necessary) for a particular
251 #ifdef OBJECT_FORMAT_ELF
252 #ifndef UNALIGNED_SHORT_ASM_OP
253 #define UNALIGNED_SHORT_ASM_OP ".2byte"
255 #ifndef UNALIGNED_INT_ASM_OP
256 #define UNALIGNED_INT_ASM_OP ".4byte"
258 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
259 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
261 #endif /* OBJECT_FORMAT_ELF */
264 #define ASM_BYTE_OP ".byte"
267 /* Data and reference forms for relocatable data. */
268 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
269 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
271 /* Pseudo-op for defining a new section. */
272 #ifndef SECTION_ASM_OP
273 #define SECTION_ASM_OP ".section"
276 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
277 print the SECTION_ASM_OP and the section name. The default here works for
278 almost all svr4 assemblers, except for the sparc, where the section name
279 must be enclosed in double quotes. (See sparcv4.h). */
280 #ifndef SECTION_FORMAT
281 #ifdef PUSHSECTION_FORMAT
282 #define SECTION_FORMAT PUSHSECTION_FORMAT
284 #define SECTION_FORMAT "\t%s\t%s\n"
288 #ifndef FRAME_SECTION
289 #define FRAME_SECTION ".debug_frame"
292 #ifndef FUNC_BEGIN_LABEL
293 #define FUNC_BEGIN_LABEL "LFB"
295 #ifndef FUNC_END_LABEL
296 #define FUNC_END_LABEL "LFE"
298 #define CIE_AFTER_SIZE_LABEL "LSCIE"
299 #define CIE_END_LABEL "LECIE"
300 #define CIE_LENGTH_LABEL "LLCIE"
301 #define FDE_AFTER_SIZE_LABEL "LSFDE"
302 #define FDE_END_LABEL "LEFDE"
303 #define FDE_LENGTH_LABEL "LLFDE"
304 #define DIE_LABEL_PREFIX "DW"
306 /* Definitions of defaults for various types of primitive assembly language
307 output operations. These may be overridden from within the tm.h file,
308 but typically, that is unnecessary. */
310 #ifndef ASM_OUTPUT_SECTION
311 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
312 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
315 #ifndef ASM_OUTPUT_DWARF_DATA1
316 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
317 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
320 #ifndef ASM_OUTPUT_DWARF_DELTA1
321 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
322 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
323 assemble_name (FILE, LABEL1); \
324 fprintf (FILE, "-"); \
325 assemble_name (FILE, LABEL2); \
329 #ifdef UNALIGNED_INT_ASM_OP
331 #ifndef UNALIGNED_OFFSET_ASM_OP
332 #define UNALIGNED_OFFSET_ASM_OP \
333 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
336 #ifndef UNALIGNED_WORD_ASM_OP
337 #define UNALIGNED_WORD_ASM_OP \
338 ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \
339 : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \
340 : UNALIGNED_INT_ASM_OP)
343 #ifndef ASM_OUTPUT_DWARF_DELTA2
344 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
345 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
346 assemble_name (FILE, LABEL1); \
347 fprintf (FILE, "-"); \
348 assemble_name (FILE, LABEL2); \
352 #ifndef ASM_OUTPUT_DWARF_DELTA4
353 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
354 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
355 assemble_name (FILE, LABEL1); \
356 fprintf (FILE, "-"); \
357 assemble_name (FILE, LABEL2); \
361 #ifndef ASM_OUTPUT_DWARF_DELTA
362 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
363 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
364 assemble_name (FILE, LABEL1); \
365 fprintf (FILE, "-"); \
366 assemble_name (FILE, LABEL2); \
370 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
371 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
372 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
373 assemble_name (FILE, LABEL1); \
374 fprintf (FILE, "-"); \
375 assemble_name (FILE, LABEL2); \
379 #ifndef ASM_OUTPUT_DWARF_ADDR
380 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
381 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
382 assemble_name (FILE, LABEL); \
386 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
387 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
389 fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
390 output_addr_const ((FILE), (RTX)); \
394 #ifndef ASM_OUTPUT_DWARF_OFFSET4
395 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
396 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
397 assemble_name (FILE, LABEL); \
401 #ifndef ASM_OUTPUT_DWARF_OFFSET
402 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
403 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
404 assemble_name (FILE, LABEL); \
408 #ifndef ASM_OUTPUT_DWARF_DATA2
409 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
410 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
413 #ifndef ASM_OUTPUT_DWARF_DATA4
414 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
415 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
418 #ifndef ASM_OUTPUT_DWARF_DATA8
419 #define ASM_OUTPUT_DWARF_DATA8(FILE,VALUE) \
420 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_DOUBLE_INT_ASM_OP, \
421 (unsigned long) (VALUE))
424 #ifndef ASM_OUTPUT_DWARF_DATA
425 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
426 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
427 (unsigned long) (VALUE))
430 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
431 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
432 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
433 (unsigned long) (VALUE))
436 #ifndef ASM_OUTPUT_DWARF_CONST_DOUBLE
437 #define ASM_OUTPUT_DWARF_CONST_DOUBLE(FILE,HIGH_VALUE,LOW_VALUE) \
439 if (WORDS_BIG_ENDIAN) \
441 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
442 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
446 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
447 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
452 #else /* UNALIGNED_INT_ASM_OP */
454 /* We don't have unaligned support, let's hope the normal output works for
455 .debug_frame. But we know it won't work for .debug_info. */
457 #ifdef DWARF2_DEBUGGING_INFO
458 #error DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP.
461 #ifndef ASM_OUTPUT_DWARF_ADDR
462 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
463 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1)
466 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
467 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) ASM_OUTPUT_DWARF_ADDR (FILE,RTX)
470 #ifndef ASM_OUTPUT_DWARF_OFFSET4
471 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
472 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
475 #ifndef ASM_OUTPUT_DWARF_OFFSET
476 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
477 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
480 #ifndef ASM_OUTPUT_DWARF_DELTA2
481 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
482 assemble_integer (gen_rtx_MINUS (HImode, \
483 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
484 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
488 #ifndef ASM_OUTPUT_DWARF_DELTA4
489 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
490 assemble_integer (gen_rtx_MINUS (SImode, \
491 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
492 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
496 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
497 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
498 assemble_integer (gen_rtx_MINUS (Pmode, \
499 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
500 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
504 #ifndef ASM_OUTPUT_DWARF_DELTA
505 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
506 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
509 #ifndef ASM_OUTPUT_DWARF_DATA2
510 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
511 assemble_integer (GEN_INT (VALUE), 2, 1)
514 #ifndef ASM_OUTPUT_DWARF_DATA4
515 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
516 assemble_integer (GEN_INT (VALUE), 4, 1)
519 #endif /* UNALIGNED_INT_ASM_OP */
522 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
523 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
525 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
526 assemble_name (FILE, SY); \
528 assemble_name (FILE, HI); \
530 assemble_name (FILE, LO); \
533 #endif /* SET_ASM_OP */
535 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
536 newline is produced. When flag_debug_asm is asserted, we add commentary
537 at the end of the line, so we must avoid output of a newline here. */
538 #ifndef ASM_OUTPUT_DWARF_STRING
539 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
541 register int slen = strlen(P); \
542 register const char *p = (P); \
544 fprintf (FILE, "\t.ascii \""); \
545 for (i = 0; i < slen; i++) \
547 register int c = p[i]; \
548 if (c == '\"' || c == '\\') \
554 fprintf (FILE, "\\%o", c); \
557 fprintf (FILE, "\\0\""); \
562 /* The DWARF 2 CFA column which tracks the return address. Normally this
563 is the column for PC, or the first column after all of the hard
565 #ifndef DWARF_FRAME_RETURN_COLUMN
567 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
569 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
573 /* The mapping from gcc register number to DWARF 2 CFA column number. By
574 default, we just provide columns for all registers. */
575 #ifndef DWARF_FRAME_REGNUM
576 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
579 /* Hook used by __throw. */
582 expand_builtin_dwarf_fp_regnum ()
584 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
587 /* The offset from the incoming value of %sp to the top of the stack frame
588 for the current function. */
589 #ifndef INCOMING_FRAME_SP_OFFSET
590 #define INCOMING_FRAME_SP_OFFSET 0
593 /* Return a pointer to a copy of the section string name S with all
594 attributes stripped off, and an asterisk prepended (for assemble_name). */
600 char *stripped = xmalloc (strlen (s) + 2);
605 while (*s && *s != ',')
612 /* Generate code to initialize the register size table. */
615 expand_builtin_init_dwarf_reg_sizes (address)
619 enum machine_mode mode = TYPE_MODE (char_type_node);
620 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
621 rtx mem = gen_rtx_MEM (mode, addr);
623 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
625 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
626 int size = GET_MODE_SIZE (reg_raw_mode[i]);
631 emit_move_insn (change_address (mem, mode,
632 plus_constant (addr, offset)),
637 /* Convert a DWARF call frame info. operation to its string name */
640 dwarf_cfi_name (cfi_opc)
641 register unsigned cfi_opc;
645 case DW_CFA_advance_loc:
646 return "DW_CFA_advance_loc";
648 return "DW_CFA_offset";
650 return "DW_CFA_restore";
654 return "DW_CFA_set_loc";
655 case DW_CFA_advance_loc1:
656 return "DW_CFA_advance_loc1";
657 case DW_CFA_advance_loc2:
658 return "DW_CFA_advance_loc2";
659 case DW_CFA_advance_loc4:
660 return "DW_CFA_advance_loc4";
661 case DW_CFA_offset_extended:
662 return "DW_CFA_offset_extended";
663 case DW_CFA_restore_extended:
664 return "DW_CFA_restore_extended";
665 case DW_CFA_undefined:
666 return "DW_CFA_undefined";
667 case DW_CFA_same_value:
668 return "DW_CFA_same_value";
669 case DW_CFA_register:
670 return "DW_CFA_register";
671 case DW_CFA_remember_state:
672 return "DW_CFA_remember_state";
673 case DW_CFA_restore_state:
674 return "DW_CFA_restore_state";
676 return "DW_CFA_def_cfa";
677 case DW_CFA_def_cfa_register:
678 return "DW_CFA_def_cfa_register";
679 case DW_CFA_def_cfa_offset:
680 return "DW_CFA_def_cfa_offset";
681 case DW_CFA_def_cfa_expression:
682 return "DW_CFA_def_cfa_expression";
684 /* SGI/MIPS specific */
685 case DW_CFA_MIPS_advance_loc8:
686 return "DW_CFA_MIPS_advance_loc8";
689 case DW_CFA_GNU_window_save:
690 return "DW_CFA_GNU_window_save";
691 case DW_CFA_GNU_args_size:
692 return "DW_CFA_GNU_args_size";
693 case DW_CFA_GNU_negative_offset_extended:
694 return "DW_CFA_GNU_negative_offset_extended";
697 return "DW_CFA_<unknown>";
701 /* Return a pointer to a newly allocated Call Frame Instruction. */
703 static inline dw_cfi_ref
706 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
708 cfi->dw_cfi_next = NULL;
709 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
710 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
715 /* Add a Call Frame Instruction to list of instructions. */
718 add_cfi (list_head, cfi)
719 register dw_cfi_ref *list_head;
720 register dw_cfi_ref cfi;
722 register dw_cfi_ref *p;
724 /* Find the end of the chain. */
725 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
731 /* Generate a new label for the CFI info to refer to. */
734 dwarf2out_cfi_label ()
736 static char label[20];
737 static unsigned long label_num = 0;
739 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
740 ASM_OUTPUT_LABEL (asm_out_file, label);
745 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
746 or to the CIE if LABEL is NULL. */
749 add_fde_cfi (label, cfi)
750 register const char *label;
751 register dw_cfi_ref cfi;
755 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
758 label = dwarf2out_cfi_label ();
760 if (fde->dw_fde_current_label == NULL
761 || strcmp (label, fde->dw_fde_current_label) != 0)
763 register dw_cfi_ref xcfi;
765 fde->dw_fde_current_label = label = xstrdup (label);
767 /* Set the location counter to the new label. */
769 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
770 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
771 add_cfi (&fde->dw_fde_cfi, xcfi);
774 add_cfi (&fde->dw_fde_cfi, cfi);
778 add_cfi (&cie_cfi_head, cfi);
781 /* Subroutine of lookup_cfa. */
784 lookup_cfa_1 (cfi, loc)
785 register dw_cfi_ref cfi;
786 register dw_cfa_location *loc;
788 switch (cfi->dw_cfi_opc)
790 case DW_CFA_def_cfa_offset:
791 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
793 case DW_CFA_def_cfa_register:
794 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
797 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
798 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
800 case DW_CFA_def_cfa_expression:
801 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
808 /* Find the previous value for the CFA. */
812 register dw_cfa_location *loc;
814 register dw_cfi_ref cfi;
816 loc->reg = (unsigned long) -1;
819 loc->base_offset = 0;
821 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
822 lookup_cfa_1 (cfi, loc);
824 if (fde_table_in_use)
826 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
827 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
828 lookup_cfa_1 (cfi, loc);
832 /* The current rule for calculating the DWARF2 canonical frame address. */
835 /* The register used for saving registers to the stack, and its offset
837 dw_cfa_location cfa_store;
839 /* The running total of the size of arguments pushed onto the stack. */
840 static long args_size;
842 /* The last args_size we actually output. */
843 static long old_args_size;
845 /* Entry point to update the canonical frame address (CFA).
846 LABEL is passed to add_fde_cfi. The value of CFA is now to be
847 calculated from REG+OFFSET. */
850 dwarf2out_def_cfa (label, reg, offset)
851 register const char *label;
860 def_cfa_1 (label, &loc);
863 /* This routine does the actual work. The CFA is now calculated from
864 the dw_cfa_location structure. */
866 def_cfa_1 (label, loc_p)
867 register const char *label;
868 dw_cfa_location *loc_p;
870 register dw_cfi_ref cfi;
871 dw_cfa_location old_cfa, loc;
876 if (cfa_store.reg == loc.reg && loc.indirect == 0)
877 cfa_store.offset = loc.offset;
879 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
880 lookup_cfa (&old_cfa);
882 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
883 loc.indirect == old_cfa.indirect)
885 if (loc.indirect == 0
886 || loc.base_offset == old_cfa.base_offset)
892 if (loc.reg == old_cfa.reg && !loc.indirect)
894 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
895 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
898 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
899 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
902 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
903 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
907 else if (loc.indirect == 0)
909 cfi->dw_cfi_opc = DW_CFA_def_cfa;
910 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
911 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
915 struct dw_loc_descr_struct *loc_list;
916 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
917 loc_list = build_cfa_loc (&loc);
918 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
921 add_fde_cfi (label, cfi);
924 /* Add the CFI for saving a register. REG is the CFA column number.
925 LABEL is passed to add_fde_cfi.
926 If SREG is -1, the register is saved at OFFSET from the CFA;
927 otherwise it is saved in SREG. */
930 reg_save (label, reg, sreg, offset)
931 register const char *label;
932 register unsigned reg;
933 register unsigned sreg;
934 register long offset;
936 register dw_cfi_ref cfi = new_cfi ();
938 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
940 /* The following comparison is correct. -1 is used to indicate that
941 the value isn't a register number. */
942 if (sreg == (unsigned int) -1)
945 /* The register number won't fit in 6 bits, so we have to use
947 cfi->dw_cfi_opc = DW_CFA_offset_extended;
949 cfi->dw_cfi_opc = DW_CFA_offset;
951 offset /= DWARF_CIE_DATA_ALIGNMENT;
954 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
957 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
959 else if (sreg == reg)
960 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
964 cfi->dw_cfi_opc = DW_CFA_register;
965 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
968 add_fde_cfi (label, cfi);
971 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
972 This CFI tells the unwinder that it needs to restore the window registers
973 from the previous frame's window save area.
975 ??? Perhaps we should note in the CIE where windows are saved (instead of
976 assuming 0(cfa)) and what registers are in the window. */
979 dwarf2out_window_save (label)
980 register const char *label;
982 register dw_cfi_ref cfi = new_cfi ();
983 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
984 add_fde_cfi (label, cfi);
987 /* Add a CFI to update the running total of the size of arguments
988 pushed onto the stack. */
991 dwarf2out_args_size (label, size)
995 register dw_cfi_ref cfi;
997 if (size == old_args_size)
999 old_args_size = size;
1002 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1003 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1004 add_fde_cfi (label, cfi);
1007 /* Entry point for saving a register to the stack. REG is the GCC register
1008 number. LABEL and OFFSET are passed to reg_save. */
1011 dwarf2out_reg_save (label, reg, offset)
1012 register const char *label;
1013 register unsigned reg;
1014 register long offset;
1016 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
1019 /* Entry point for saving the return address in the stack.
1020 LABEL and OFFSET are passed to reg_save. */
1023 dwarf2out_return_save (label, offset)
1024 register const char *label;
1025 register long offset;
1027 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
1030 /* Entry point for saving the return address in a register.
1031 LABEL and SREG are passed to reg_save. */
1034 dwarf2out_return_reg (label, sreg)
1035 register const char *label;
1036 register unsigned sreg;
1038 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
1041 /* Record the initial position of the return address. RTL is
1042 INCOMING_RETURN_ADDR_RTX. */
1045 initial_return_save (rtl)
1048 unsigned int reg = (unsigned int) -1;
1051 switch (GET_CODE (rtl))
1054 /* RA is in a register. */
1055 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1058 /* RA is on the stack. */
1059 rtl = XEXP (rtl, 0);
1060 switch (GET_CODE (rtl))
1063 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1068 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1070 offset = INTVAL (XEXP (rtl, 1));
1073 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1075 offset = -INTVAL (XEXP (rtl, 1));
1082 /* The return address is at some offset from any value we can
1083 actually load. For instance, on the SPARC it is in %i7+8. Just
1084 ignore the offset for now; it doesn't matter for unwinding frames. */
1085 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1087 initial_return_save (XEXP (rtl, 0));
1093 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1096 /* Check INSN to see if it looks like a push or a stack adjustment, and
1097 make a note of it if it does. EH uses this information to find out how
1098 much extra space it needs to pop off the stack. */
1101 dwarf2out_stack_adjust (insn)
1107 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1109 /* Extract the size of the args from the CALL rtx itself. */
1111 insn = PATTERN (insn);
1112 if (GET_CODE (insn) == PARALLEL)
1113 insn = XVECEXP (insn, 0, 0);
1114 if (GET_CODE (insn) == SET)
1115 insn = SET_SRC (insn);
1116 if (GET_CODE (insn) != CALL)
1118 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1122 /* If only calls can throw, and we have a frame pointer,
1123 save up adjustments until we see the CALL_INSN. */
1124 else if (! asynchronous_exceptions
1125 && cfa.reg != STACK_POINTER_REGNUM)
1128 if (GET_CODE (insn) == BARRIER)
1130 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1131 the compiler will have already emitted a stack adjustment, but
1132 doesn't bother for calls to noreturn functions. */
1133 #ifdef STACK_GROWS_DOWNWARD
1134 offset = -args_size;
1139 else if (GET_CODE (PATTERN (insn)) == SET)
1144 insn = PATTERN (insn);
1145 src = SET_SRC (insn);
1146 dest = SET_DEST (insn);
1148 if (dest == stack_pointer_rtx)
1150 /* (set (reg sp) (plus (reg sp) (const_int))) */
1151 code = GET_CODE (src);
1152 if (! (code == PLUS || code == MINUS)
1153 || XEXP (src, 0) != stack_pointer_rtx
1154 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1157 offset = INTVAL (XEXP (src, 1));
1159 else if (GET_CODE (dest) == MEM)
1161 /* (set (mem (pre_dec (reg sp))) (foo)) */
1162 src = XEXP (dest, 0);
1163 code = GET_CODE (src);
1165 if (! (code == PRE_DEC || code == PRE_INC)
1166 || XEXP (src, 0) != stack_pointer_rtx)
1169 offset = GET_MODE_SIZE (GET_MODE (dest));
1174 if (code == PLUS || code == PRE_INC)
1183 if (cfa.reg == STACK_POINTER_REGNUM)
1184 cfa.offset += offset;
1186 #ifndef STACK_GROWS_DOWNWARD
1189 args_size += offset;
1193 label = dwarf2out_cfi_label ();
1194 def_cfa_1 (label, &cfa);
1195 dwarf2out_args_size (label, args_size);
1198 /* A temporary register used in adjusting SP or setting up the store_reg. */
1199 static unsigned cfa_temp_reg;
1201 /* A temporary value used in adjusting SP or setting up the store_reg. */
1202 static long cfa_temp_value;
1204 /* Record call frame debugging information for an expression, which either
1205 sets SP or FP (adjusting how we calculate the frame address) or saves a
1206 register to the stack. */
1209 dwarf2out_frame_debug_expr (expr, label)
1216 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1217 the PARALLEL independently. The first element is always processed if
1218 it is a SET. This is for backward compatability. Other elements
1219 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1220 flag is set in them. */
1222 if (GET_CODE (expr) == PARALLEL
1223 || GET_CODE (expr) == SEQUENCE)
1226 int limit = XVECLEN (expr, 0);
1228 for (par_index = 0; par_index < limit; par_index++)
1230 rtx x = XVECEXP (expr, 0, par_index);
1232 if (GET_CODE (x) == SET &&
1233 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1234 dwarf2out_frame_debug_expr (x, label);
1239 if (GET_CODE (expr) != SET)
1242 src = SET_SRC (expr);
1243 dest = SET_DEST (expr);
1245 switch (GET_CODE (dest))
1248 /* Update the CFA rule wrt SP or FP. Make sure src is
1249 relative to the current CFA register. */
1250 switch (GET_CODE (src))
1252 /* Setting FP from SP. */
1254 if (cfa.reg == (unsigned) REGNO (src))
1260 /* We used to require that dest be either SP or FP, but the
1261 ARM copies SP to a temporary register, and from there to
1262 FP. So we just rely on the backends to only set
1263 RTX_FRAME_RELATED_P on appropriate insns. */
1264 cfa.reg = REGNO (dest);
1269 if (dest == stack_pointer_rtx)
1272 switch (GET_CODE (XEXP (src, 1)))
1275 offset = INTVAL (XEXP (src, 1));
1278 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1280 offset = cfa_temp_value;
1286 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1288 /* Restoring SP from FP in the epilogue. */
1289 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1291 cfa.reg = STACK_POINTER_REGNUM;
1293 else if (XEXP (src, 0) != stack_pointer_rtx)
1296 if (GET_CODE (src) == PLUS)
1298 if (cfa.reg == STACK_POINTER_REGNUM)
1299 cfa.offset += offset;
1300 if (cfa_store.reg == STACK_POINTER_REGNUM)
1301 cfa_store.offset += offset;
1303 else if (dest == hard_frame_pointer_rtx)
1305 /* Either setting the FP from an offset of the SP,
1306 or adjusting the FP */
1307 if (! frame_pointer_needed)
1310 if (GET_CODE (XEXP (src, 0)) == REG
1311 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1312 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1314 offset = INTVAL (XEXP (src, 1));
1315 if (GET_CODE (src) == PLUS)
1317 cfa.offset += offset;
1318 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1325 if (GET_CODE (src) != PLUS
1326 || XEXP (src, 1) != stack_pointer_rtx)
1328 if (GET_CODE (XEXP (src, 0)) != REG
1329 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1331 if (cfa.reg != STACK_POINTER_REGNUM)
1333 cfa_store.reg = REGNO (dest);
1334 cfa_store.offset = cfa.offset - cfa_temp_value;
1339 cfa_temp_reg = REGNO (dest);
1340 cfa_temp_value = INTVAL (src);
1344 if (GET_CODE (XEXP (src, 0)) != REG
1345 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1346 || (unsigned) REGNO (dest) != cfa_temp_reg
1347 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1349 cfa_temp_value |= INTVAL (XEXP (src, 1));
1355 def_cfa_1 (label, &cfa);
1358 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1359 will fill in all of the bits. */
1364 cfa_temp_reg = REGNO (dest);
1365 cfa_temp_value = INTVAL (XEXP (src, 1));
1369 if (GET_CODE (src) != REG)
1372 /* Saving a register to the stack. Make sure dest is relative to the
1374 switch (GET_CODE (XEXP (dest, 0)))
1379 offset = GET_MODE_SIZE (GET_MODE (dest));
1380 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1383 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1384 || cfa_store.reg != STACK_POINTER_REGNUM)
1386 cfa_store.offset += offset;
1387 if (cfa.reg == STACK_POINTER_REGNUM)
1388 cfa.offset = cfa_store.offset;
1390 offset = -cfa_store.offset;
1393 /* With an offset. */
1396 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1397 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1400 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1402 offset -= cfa_store.offset;
1405 /* Without an offset. */
1407 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1409 offset = -cfa_store.offset;
1416 if (REGNO (src) != STACK_POINTER_REGNUM
1417 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1418 && (unsigned) REGNO (src) == cfa.reg)
1420 /* We're storing the current CFA reg into the stack. */
1422 if (cfa.offset == 0)
1424 /* If the source register is exactly the CFA, assume
1425 we're saving SP like any other register; this happens
1428 def_cfa_1 (label, &cfa);
1429 dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset);
1434 /* Otherwise, we'll need to look in the stack to
1435 calculate the CFA. */
1437 rtx x = XEXP (dest, 0);
1438 if (GET_CODE (x) != REG)
1440 if (GET_CODE (x) != REG)
1442 cfa.reg = (unsigned) REGNO (x);
1443 cfa.base_offset = offset;
1445 def_cfa_1 (label, &cfa);
1450 def_cfa_1 (label, &cfa);
1451 dwarf2out_reg_save (label, REGNO (src), offset);
1459 /* Record call frame debugging information for INSN, which either
1460 sets SP or FP (adjusting how we calculate the frame address) or saves a
1461 register to the stack. If INSN is NULL_RTX, initialize our state. */
1464 dwarf2out_frame_debug (insn)
1470 if (insn == NULL_RTX)
1472 /* Set up state for generating call frame debug info. */
1474 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1476 cfa.reg = STACK_POINTER_REGNUM;
1483 if (! RTX_FRAME_RELATED_P (insn))
1485 dwarf2out_stack_adjust (insn);
1489 label = dwarf2out_cfi_label ();
1491 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1493 insn = XEXP (src, 0);
1495 insn = PATTERN (insn);
1497 dwarf2out_frame_debug_expr (insn, label);
1500 /* Return the size of an unsigned LEB128 quantity. */
1502 static inline unsigned long
1503 size_of_uleb128 (value)
1504 register unsigned long value;
1506 register unsigned long size = 0;
1507 register unsigned byte;
1511 byte = (value & 0x7f);
1520 /* Return the size of a signed LEB128 quantity. */
1522 static inline unsigned long
1523 size_of_sleb128 (value)
1524 register long value;
1526 register unsigned long size = 0;
1527 register unsigned byte;
1531 byte = (value & 0x7f);
1535 while (!(((value == 0) && ((byte & 0x40) == 0))
1536 || ((value == -1) && ((byte & 0x40) != 0))));
1541 /* Output an unsigned LEB128 quantity. */
1544 output_uleb128 (value)
1545 register unsigned long value;
1547 unsigned long save_value = value;
1549 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1552 register unsigned byte = (value & 0x7f);
1555 /* More bytes to follow. */
1558 fprintf (asm_out_file, "0x%x", byte);
1560 fprintf (asm_out_file, ",");
1565 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1568 /* Output an signed LEB128 quantity. */
1571 output_sleb128 (value)
1572 register long value;
1575 register unsigned byte;
1576 long save_value = value;
1578 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1581 byte = (value & 0x7f);
1582 /* arithmetic shift */
1584 more = !((((value == 0) && ((byte & 0x40) == 0))
1585 || ((value == -1) && ((byte & 0x40) != 0))));
1589 fprintf (asm_out_file, "0x%x", byte);
1591 fprintf (asm_out_file, ",");
1596 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1599 /* Output a Call Frame Information opcode and its operand(s). */
1602 output_cfi (cfi, fde)
1603 register dw_cfi_ref cfi;
1604 register dw_fde_ref fde;
1606 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1608 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1610 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1612 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1613 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1614 fputc ('\n', asm_out_file);
1617 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1619 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1621 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1623 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1624 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1626 fputc ('\n', asm_out_file);
1627 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1628 fputc ('\n', asm_out_file);
1630 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1632 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1634 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1636 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1637 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1639 fputc ('\n', asm_out_file);
1643 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1645 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1646 dwarf_cfi_name (cfi->dw_cfi_opc));
1648 fputc ('\n', asm_out_file);
1649 switch (cfi->dw_cfi_opc)
1651 case DW_CFA_set_loc:
1652 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1653 fputc ('\n', asm_out_file);
1655 case DW_CFA_advance_loc1:
1656 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1657 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1658 fde->dw_fde_current_label);
1659 fputc ('\n', asm_out_file);
1660 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1662 case DW_CFA_advance_loc2:
1663 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1664 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1665 fde->dw_fde_current_label);
1666 fputc ('\n', asm_out_file);
1667 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1669 case DW_CFA_advance_loc4:
1670 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1671 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1672 fde->dw_fde_current_label);
1673 fputc ('\n', asm_out_file);
1674 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1676 #ifdef MIPS_DEBUGGING_INFO
1677 case DW_CFA_MIPS_advance_loc8:
1678 /* TODO: not currently implemented. */
1682 case DW_CFA_offset_extended:
1683 case DW_CFA_GNU_negative_offset_extended:
1684 case DW_CFA_def_cfa:
1685 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1686 fputc ('\n', asm_out_file);
1687 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1688 fputc ('\n', asm_out_file);
1690 case DW_CFA_restore_extended:
1691 case DW_CFA_undefined:
1692 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1693 fputc ('\n', asm_out_file);
1695 case DW_CFA_same_value:
1696 case DW_CFA_def_cfa_register:
1697 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1698 fputc ('\n', asm_out_file);
1700 case DW_CFA_register:
1701 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1702 fputc ('\n', asm_out_file);
1703 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1704 fputc ('\n', asm_out_file);
1706 case DW_CFA_def_cfa_offset:
1707 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1708 fputc ('\n', asm_out_file);
1710 case DW_CFA_GNU_window_save:
1712 case DW_CFA_GNU_args_size:
1713 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1714 fputc ('\n', asm_out_file);
1716 case DW_CFA_def_cfa_expression:
1717 output_cfa_loc (cfi);
1725 /* Output the call frame information used to used to record information
1726 that relates to calculating the frame pointer, and records the
1727 location of saved registers. */
1730 output_call_frame_info (for_eh)
1733 register unsigned long i;
1734 register dw_fde_ref fde;
1735 register dw_cfi_ref cfi;
1736 char l1[20], l2[20];
1737 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1741 /* Do we want to include a pointer to the exception table? */
1742 int eh_ptr = for_eh && exception_table_p ();
1744 /* If we don't have any functions we'll want to unwind out of, don't
1745 emit any EH unwind information. */
1748 for (i = 0; i < fde_table_in_use; ++i)
1749 if (! fde_table[i].nothrow)
1755 fputc ('\n', asm_out_file);
1757 /* We're going to be generating comments, so turn on app. */
1763 #ifdef EH_FRAME_SECTION
1764 EH_FRAME_SECTION ();
1766 tree label = get_file_function_name ('F');
1768 force_data_section ();
1769 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1770 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1771 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1773 assemble_label ("__FRAME_BEGIN__");
1776 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1778 /* Output the CIE. */
1779 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1780 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1781 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1782 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1784 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1786 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1789 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1791 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1794 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1797 fputc ('\n', asm_out_file);
1798 ASM_OUTPUT_LABEL (asm_out_file, l1);
1801 /* Now that the CIE pointer is PC-relative for EH,
1802 use 0 to identify the CIE. */
1803 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1805 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1808 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1810 fputc ('\n', asm_out_file);
1811 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1813 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1814 fputc ('\n', asm_out_file);
1817 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1819 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1821 fputc ('\n', asm_out_file);
1824 /* The CIE contains a pointer to the exception region info for the
1825 frame. Make the augmentation string three bytes (including the
1826 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1827 can't handle unaligned relocs. */
1830 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1831 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1835 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1837 fputc ('\n', asm_out_file);
1839 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1841 fprintf (asm_out_file, "\t%s pointer to exception region info",
1846 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1848 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1852 fputc ('\n', asm_out_file);
1855 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1857 fputc ('\n', asm_out_file);
1858 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1860 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1862 fputc ('\n', asm_out_file);
1863 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1865 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1867 fputc ('\n', asm_out_file);
1869 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1870 output_cfi (cfi, NULL);
1872 /* Pad the CIE out to an address sized boundary. */
1873 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1874 ASM_OUTPUT_LABEL (asm_out_file, l2);
1875 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1876 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1878 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1879 fputc ('\n', asm_out_file);
1882 /* Loop through all of the FDE's. */
1883 for (i = 0; i < fde_table_in_use; ++i)
1885 fde = &fde_table[i];
1887 /* Don't emit EH unwind info for leaf functions. */
1888 if (for_eh && fde->nothrow)
1891 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1892 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1893 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1894 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i * 2);
1896 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1898 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1901 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1903 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1906 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1907 fputc ('\n', asm_out_file);
1908 ASM_OUTPUT_LABEL (asm_out_file, l1);
1910 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1911 emits a target dependent sized offset when for_eh is not true.
1912 This inconsistency may confuse gdb. The only case where we need a
1913 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1914 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1915 though in order to be compatible with the dwarf_fde struct in frame.c.
1916 If the for_eh case is changed, then the struct in frame.c has
1917 to be adjusted appropriately. */
1919 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1921 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1923 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1925 fputc ('\n', asm_out_file);
1926 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1928 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1930 fputc ('\n', asm_out_file);
1931 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1932 fde->dw_fde_end, fde->dw_fde_begin);
1934 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1936 fputc ('\n', asm_out_file);
1938 /* Loop through the Call Frame Instructions associated with
1940 fde->dw_fde_current_label = fde->dw_fde_begin;
1941 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1942 output_cfi (cfi, fde);
1944 /* Pad the FDE out to an address sized boundary. */
1945 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1946 ASM_OUTPUT_LABEL (asm_out_file, l2);
1947 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1948 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1950 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1951 fputc ('\n', asm_out_file);
1954 #ifndef EH_FRAME_SECTION
1957 /* Emit terminating zero for table. */
1958 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1959 fputc ('\n', asm_out_file);
1962 #ifdef MIPS_DEBUGGING_INFO
1963 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1964 get a value of 0. Putting .align 0 after the label fixes it. */
1965 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1968 /* Turn off app to make assembly quicker. */
1973 /* Output a marker (i.e. a label) for the beginning of a function, before
1977 dwarf2out_begin_prologue ()
1979 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1980 register dw_fde_ref fde;
1982 ++current_funcdef_number;
1984 function_section (current_function_decl);
1985 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1986 current_funcdef_number);
1987 ASM_OUTPUT_LABEL (asm_out_file, label);
1988 current_function_func_begin_label = get_identifier (label);
1990 /* Expand the fde table if necessary. */
1991 if (fde_table_in_use == fde_table_allocated)
1993 fde_table_allocated += FDE_TABLE_INCREMENT;
1995 = (dw_fde_ref) xrealloc (fde_table,
1996 fde_table_allocated * sizeof (dw_fde_node));
1999 /* Record the FDE associated with this function. */
2000 current_funcdef_fde = fde_table_in_use;
2002 /* Add the new FDE at the end of the fde_table. */
2003 fde = &fde_table[fde_table_in_use++];
2004 fde->dw_fde_begin = xstrdup (label);
2005 fde->dw_fde_current_label = NULL;
2006 fde->dw_fde_end = NULL;
2007 fde->dw_fde_cfi = NULL;
2008 fde->nothrow = current_function_nothrow;
2010 args_size = old_args_size = 0;
2013 /* Output a marker (i.e. a label) for the absolute end of the generated code
2014 for a function definition. This gets called *after* the epilogue code has
2018 dwarf2out_end_epilogue ()
2021 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2023 /* Output a label to mark the endpoint of the code generated for this
2025 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2026 ASM_OUTPUT_LABEL (asm_out_file, label);
2027 fde = &fde_table[fde_table_in_use - 1];
2028 fde->dw_fde_end = xstrdup (label);
2032 dwarf2out_frame_init ()
2034 /* Allocate the initial hunk of the fde_table. */
2035 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2036 fde_table_allocated = FDE_TABLE_INCREMENT;
2037 fde_table_in_use = 0;
2039 /* Generate the CFA instructions common to all FDE's. Do it now for the
2040 sake of lookup_cfa. */
2042 #ifdef DWARF2_UNWIND_INFO
2043 /* On entry, the Canonical Frame Address is at SP. */
2044 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2045 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2050 dwarf2out_frame_finish ()
2052 /* Output call frame information. */
2053 #ifdef MIPS_DEBUGGING_INFO
2054 if (write_symbols == DWARF2_DEBUG)
2055 output_call_frame_info (0);
2056 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2057 output_call_frame_info (1);
2059 if (write_symbols == DWARF2_DEBUG
2060 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2061 output_call_frame_info (1);
2065 /* And now, the subset of the debugging information support code necessary
2066 for emitting location expressions. */
2068 typedef struct dw_val_struct *dw_val_ref;
2069 typedef struct die_struct *dw_die_ref;
2070 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2072 /* Each DIE may have a series of attribute/value pairs. Values
2073 can take on several forms. The forms that are used in this
2074 implementation are listed below. */
2081 dw_val_class_unsigned_const,
2082 dw_val_class_long_long,
2085 dw_val_class_die_ref,
2086 dw_val_class_fde_ref,
2087 dw_val_class_lbl_id,
2088 dw_val_class_lbl_offset,
2093 /* Describe a double word constant value. */
2094 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2096 typedef struct dw_long_long_struct
2103 /* Describe a floating point constant value. */
2105 typedef struct dw_fp_struct
2112 /* The dw_val_node describes an attribute's value, as it is
2113 represented internally. */
2115 typedef struct dw_val_struct
2117 dw_val_class val_class;
2121 dw_loc_descr_ref val_loc;
2123 long unsigned val_unsigned;
2124 dw_long_long_const val_long_long;
2125 dw_float_const val_float;
2130 unsigned val_fde_index;
2133 unsigned char val_flag;
2139 /* Locations in memory are described using a sequence of stack machine
2142 typedef struct dw_loc_descr_struct
2144 dw_loc_descr_ref dw_loc_next;
2145 enum dwarf_location_atom dw_loc_opc;
2146 dw_val_node dw_loc_oprnd1;
2147 dw_val_node dw_loc_oprnd2;
2151 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2152 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2155 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2157 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2158 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2159 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2160 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2162 /* Convert a DWARF stack opcode into its string name. */
2165 dwarf_stack_op_name (op)
2166 register unsigned op;
2171 return "DW_OP_addr";
2173 return "DW_OP_deref";
2175 return "DW_OP_const1u";
2177 return "DW_OP_const1s";
2179 return "DW_OP_const2u";
2181 return "DW_OP_const2s";
2183 return "DW_OP_const4u";
2185 return "DW_OP_const4s";
2187 return "DW_OP_const8u";
2189 return "DW_OP_const8s";
2191 return "DW_OP_constu";
2193 return "DW_OP_consts";
2197 return "DW_OP_drop";
2199 return "DW_OP_over";
2201 return "DW_OP_pick";
2203 return "DW_OP_swap";
2207 return "DW_OP_xderef";
2215 return "DW_OP_minus";
2227 return "DW_OP_plus";
2228 case DW_OP_plus_uconst:
2229 return "DW_OP_plus_uconst";
2235 return "DW_OP_shra";
2253 return "DW_OP_skip";
2255 return "DW_OP_lit0";
2257 return "DW_OP_lit1";
2259 return "DW_OP_lit2";
2261 return "DW_OP_lit3";
2263 return "DW_OP_lit4";
2265 return "DW_OP_lit5";
2267 return "DW_OP_lit6";
2269 return "DW_OP_lit7";
2271 return "DW_OP_lit8";
2273 return "DW_OP_lit9";
2275 return "DW_OP_lit10";
2277 return "DW_OP_lit11";
2279 return "DW_OP_lit12";
2281 return "DW_OP_lit13";
2283 return "DW_OP_lit14";
2285 return "DW_OP_lit15";
2287 return "DW_OP_lit16";
2289 return "DW_OP_lit17";
2291 return "DW_OP_lit18";
2293 return "DW_OP_lit19";
2295 return "DW_OP_lit20";
2297 return "DW_OP_lit21";
2299 return "DW_OP_lit22";
2301 return "DW_OP_lit23";
2303 return "DW_OP_lit24";
2305 return "DW_OP_lit25";
2307 return "DW_OP_lit26";
2309 return "DW_OP_lit27";
2311 return "DW_OP_lit28";
2313 return "DW_OP_lit29";
2315 return "DW_OP_lit30";
2317 return "DW_OP_lit31";
2319 return "DW_OP_reg0";
2321 return "DW_OP_reg1";
2323 return "DW_OP_reg2";
2325 return "DW_OP_reg3";
2327 return "DW_OP_reg4";
2329 return "DW_OP_reg5";
2331 return "DW_OP_reg6";
2333 return "DW_OP_reg7";
2335 return "DW_OP_reg8";
2337 return "DW_OP_reg9";
2339 return "DW_OP_reg10";
2341 return "DW_OP_reg11";
2343 return "DW_OP_reg12";
2345 return "DW_OP_reg13";
2347 return "DW_OP_reg14";
2349 return "DW_OP_reg15";
2351 return "DW_OP_reg16";
2353 return "DW_OP_reg17";
2355 return "DW_OP_reg18";
2357 return "DW_OP_reg19";
2359 return "DW_OP_reg20";
2361 return "DW_OP_reg21";
2363 return "DW_OP_reg22";
2365 return "DW_OP_reg23";
2367 return "DW_OP_reg24";
2369 return "DW_OP_reg25";
2371 return "DW_OP_reg26";
2373 return "DW_OP_reg27";
2375 return "DW_OP_reg28";
2377 return "DW_OP_reg29";
2379 return "DW_OP_reg30";
2381 return "DW_OP_reg31";
2383 return "DW_OP_breg0";
2385 return "DW_OP_breg1";
2387 return "DW_OP_breg2";
2389 return "DW_OP_breg3";
2391 return "DW_OP_breg4";
2393 return "DW_OP_breg5";
2395 return "DW_OP_breg6";
2397 return "DW_OP_breg7";
2399 return "DW_OP_breg8";
2401 return "DW_OP_breg9";
2403 return "DW_OP_breg10";
2405 return "DW_OP_breg11";
2407 return "DW_OP_breg12";
2409 return "DW_OP_breg13";
2411 return "DW_OP_breg14";
2413 return "DW_OP_breg15";
2415 return "DW_OP_breg16";
2417 return "DW_OP_breg17";
2419 return "DW_OP_breg18";
2421 return "DW_OP_breg19";
2423 return "DW_OP_breg20";
2425 return "DW_OP_breg21";
2427 return "DW_OP_breg22";
2429 return "DW_OP_breg23";
2431 return "DW_OP_breg24";
2433 return "DW_OP_breg25";
2435 return "DW_OP_breg26";
2437 return "DW_OP_breg27";
2439 return "DW_OP_breg28";
2441 return "DW_OP_breg29";
2443 return "DW_OP_breg30";
2445 return "DW_OP_breg31";
2447 return "DW_OP_regx";
2449 return "DW_OP_fbreg";
2451 return "DW_OP_bregx";
2453 return "DW_OP_piece";
2454 case DW_OP_deref_size:
2455 return "DW_OP_deref_size";
2456 case DW_OP_xderef_size:
2457 return "DW_OP_xderef_size";
2461 return "OP_<unknown>";
2465 /* Return a pointer to a newly allocated location description. Location
2466 descriptions are simple expression terms that can be strung
2467 together to form more complicated location (address) descriptions. */
2469 static inline dw_loc_descr_ref
2470 new_loc_descr (op, oprnd1, oprnd2)
2471 register enum dwarf_location_atom op;
2472 register unsigned long oprnd1;
2473 register unsigned long oprnd2;
2475 /* Use xcalloc here so we clear out all of the long_long constant in
2477 register dw_loc_descr_ref descr
2478 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2480 descr->dw_loc_opc = op;
2481 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2482 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2483 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2484 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2489 /* Add a location description term to a location description expression. */
2492 add_loc_descr (list_head, descr)
2493 register dw_loc_descr_ref *list_head;
2494 register dw_loc_descr_ref descr;
2496 register dw_loc_descr_ref *d;
2498 /* Find the end of the chain. */
2499 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2505 /* Return the size of a location descriptor. */
2507 static unsigned long
2508 size_of_loc_descr (loc)
2509 register dw_loc_descr_ref loc;
2511 register unsigned long size = 1;
2513 switch (loc->dw_loc_opc)
2516 size += DWARF2_ADDR_SIZE;
2535 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2538 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2543 case DW_OP_plus_uconst:
2544 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2582 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2585 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2588 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2591 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2592 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2595 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2597 case DW_OP_deref_size:
2598 case DW_OP_xderef_size:
2608 /* Return the size of a series of location descriptors. */
2610 static unsigned long
2612 register dw_loc_descr_ref loc;
2614 register unsigned long size = 0;
2616 for (; loc != NULL; loc = loc->dw_loc_next)
2617 size += size_of_loc_descr (loc);
2622 /* Output location description stack opcode's operands (if any). */
2625 output_loc_operands (loc)
2626 register dw_loc_descr_ref loc;
2628 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2629 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2631 switch (loc->dw_loc_opc)
2633 #ifdef DWARF2_DEBUGGING_INFO
2635 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
2636 fputc ('\n', asm_out_file);
2640 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2641 fputc ('\n', asm_out_file);
2645 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
2646 fputc ('\n', asm_out_file);
2651 fputc ('\n', asm_out_file);
2655 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2656 fputc ('\n', asm_out_file);
2668 /* We currently don't make any attempt to make sure these are
2669 aligned properly like we do for the main unwind info, so
2670 don't support emitting things larger than a byte if we're
2671 only doing unwinding. */
2676 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2677 fputc ('\n', asm_out_file);
2680 output_uleb128 (val1->v.val_unsigned);
2681 fputc ('\n', asm_out_file);
2684 output_sleb128 (val1->v.val_int);
2685 fputc ('\n', asm_out_file);
2688 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
2689 fputc ('\n', asm_out_file);
2691 case DW_OP_plus_uconst:
2692 output_uleb128 (val1->v.val_unsigned);
2693 fputc ('\n', asm_out_file);
2727 output_sleb128 (val1->v.val_int);
2728 fputc ('\n', asm_out_file);
2731 output_uleb128 (val1->v.val_unsigned);
2732 fputc ('\n', asm_out_file);
2735 output_sleb128 (val1->v.val_int);
2736 fputc ('\n', asm_out_file);
2739 output_uleb128 (val1->v.val_unsigned);
2740 fputc ('\n', asm_out_file);
2741 output_sleb128 (val2->v.val_int);
2742 fputc ('\n', asm_out_file);
2745 output_uleb128 (val1->v.val_unsigned);
2746 fputc ('\n', asm_out_file);
2748 case DW_OP_deref_size:
2749 case DW_OP_xderef_size:
2750 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2751 fputc ('\n', asm_out_file);
2754 /* Other codes have no operands. */
2759 /* Output a sequence of location operations. */
2762 output_loc_sequence (loc)
2763 dw_loc_descr_ref loc;
2765 for (; loc != NULL; loc = loc->dw_loc_next)
2767 /* Output the opcode. */
2768 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
2770 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
2771 dwarf_stack_op_name (loc->dw_loc_opc));
2773 fputc ('\n', asm_out_file);
2775 /* Output the operand(s) (if any). */
2776 output_loc_operands (loc);
2780 /* This routine will generate the correct assembly data for a location
2781 description based on a cfi entry with a complex address. */
2784 output_cfa_loc (cfi)
2787 dw_loc_descr_ref loc;
2790 /* Output the size of the block. */
2791 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2792 size = size_of_locs (loc);
2793 output_uleb128 (size);
2794 fputc ('\n', asm_out_file);
2796 /* Now output the operations themselves. */
2797 output_loc_sequence (loc);
2800 /* This function builds a dwarf location descriptor seqeunce from
2801 a dw_cfa_location. */
2803 static struct dw_loc_descr_struct *
2805 dw_cfa_location *cfa;
2807 struct dw_loc_descr_struct *head, *tmp;
2809 if (cfa->indirect == 0)
2812 if (cfa->base_offset)
2813 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2815 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2816 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2817 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2818 add_loc_descr (&head, tmp);
2819 if (cfa->offset != 0)
2821 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2822 add_loc_descr (&head, tmp);
2827 /* This function fills in aa dw_cfa_location structure from a
2828 dwarf location descriptor sequence. */
2831 get_cfa_from_loc_descr (cfa, loc)
2832 dw_cfa_location *cfa;
2833 struct dw_loc_descr_struct *loc;
2835 struct dw_loc_descr_struct *ptr;
2837 cfa->base_offset = 0;
2841 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2843 enum dwarf_location_atom op = ptr->dw_loc_opc;
2878 cfa->reg = op - DW_OP_reg0;
2881 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2915 cfa->reg = op - DW_OP_breg0;
2916 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2919 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2920 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2925 case DW_OP_plus_uconst:
2926 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2929 fatal ("DW_LOC_OP %s not implememnted yet.\n",
2930 dwarf_stack_op_name (ptr->dw_loc_opc));
2934 #endif /* .debug_frame support */
2936 /* And now, the support for symbolic debugging information. */
2937 #ifdef DWARF2_DEBUGGING_INFO
2939 /* NOTE: In the comments in this file, many references are made to
2940 "Debugging Information Entries". This term is abbreviated as `DIE'
2941 throughout the remainder of this file. */
2943 /* An internal representation of the DWARF output is built, and then
2944 walked to generate the DWARF debugging info. The walk of the internal
2945 representation is done after the entire program has been compiled.
2946 The types below are used to describe the internal representation. */
2948 /* Various DIE's use offsets relative to the beginning of the
2949 .debug_info section to refer to each other. */
2951 typedef long int dw_offset;
2953 /* Define typedefs here to avoid circular dependencies. */
2955 typedef struct dw_attr_struct *dw_attr_ref;
2956 typedef struct dw_line_info_struct *dw_line_info_ref;
2957 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
2958 typedef struct pubname_struct *pubname_ref;
2959 typedef dw_die_ref *arange_ref;
2961 /* Each entry in the line_info_table maintains the file and
2962 line number associated with the label generated for that
2963 entry. The label gives the PC value associated with
2964 the line number entry. */
2966 typedef struct dw_line_info_struct
2968 unsigned long dw_file_num;
2969 unsigned long dw_line_num;
2973 /* Line information for functions in separate sections; each one gets its
2975 typedef struct dw_separate_line_info_struct
2977 unsigned long dw_file_num;
2978 unsigned long dw_line_num;
2979 unsigned long function;
2981 dw_separate_line_info_entry;
2983 /* Each DIE attribute has a field specifying the attribute kind,
2984 a link to the next attribute in the chain, and an attribute value.
2985 Attributes are typically linked below the DIE they modify. */
2987 typedef struct dw_attr_struct
2989 enum dwarf_attribute dw_attr;
2990 dw_attr_ref dw_attr_next;
2991 dw_val_node dw_attr_val;
2995 /* The Debugging Information Entry (DIE) structure */
2997 typedef struct die_struct
2999 enum dwarf_tag die_tag;
3001 dw_attr_ref die_attr;
3002 dw_die_ref die_parent;
3003 dw_die_ref die_child;
3005 dw_offset die_offset;
3006 unsigned long die_abbrev;
3010 /* The pubname structure */
3012 typedef struct pubname_struct
3019 /* The limbo die list structure. */
3020 typedef struct limbo_die_struct
3023 struct limbo_die_struct *next;
3027 /* How to start an assembler comment. */
3028 #ifndef ASM_COMMENT_START
3029 #define ASM_COMMENT_START ";#"
3032 /* Define a macro which returns non-zero for a TYPE_DECL which was
3033 implicitly generated for a tagged type.
3035 Note that unlike the gcc front end (which generates a NULL named
3036 TYPE_DECL node for each complete tagged type, each array type, and
3037 each function type node created) the g++ front end generates a
3038 _named_ TYPE_DECL node for each tagged type node created.
3039 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3040 generate a DW_TAG_typedef DIE for them. */
3042 #define TYPE_DECL_IS_STUB(decl) \
3043 (DECL_NAME (decl) == NULL_TREE \
3044 || (DECL_ARTIFICIAL (decl) \
3045 && is_tagged_type (TREE_TYPE (decl)) \
3046 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3047 /* This is necessary for stub decls that \
3048 appear in nested inline functions. */ \
3049 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3050 && (decl_ultimate_origin (decl) \
3051 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3053 /* Information concerning the compilation unit's programming
3054 language, and compiler version. */
3056 extern int flag_traditional;
3058 /* Fixed size portion of the DWARF compilation unit header. */
3059 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3061 /* Fixed size portion of debugging line information prolog. */
3062 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3064 /* Fixed size portion of public names info. */
3065 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3067 /* Fixed size portion of the address range info. */
3068 #define DWARF_ARANGES_HEADER_SIZE \
3069 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3070 - DWARF_OFFSET_SIZE)
3072 /* Size of padding portion in the address range info. It must be
3073 aligned to twice the pointer size. */
3074 #define DWARF_ARANGES_PAD_SIZE \
3075 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3076 - (2 * DWARF_OFFSET_SIZE + 4))
3078 /* The default is to have gcc emit the line number tables. */
3079 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3080 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3083 /* Define the architecture-dependent minimum instruction length (in bytes).
3084 In this implementation of DWARF, this field is used for information
3085 purposes only. Since GCC generates assembly language, we have
3086 no a priori knowledge of how many instruction bytes are generated
3087 for each source line, and therefore can use only the DW_LNE_set_address
3088 and DW_LNS_fixed_advance_pc line information commands. */
3090 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3091 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3094 /* Minimum line offset in a special line info. opcode.
3095 This value was chosen to give a reasonable range of values. */
3096 #define DWARF_LINE_BASE -10
3098 /* First special line opcde - leave room for the standard opcodes. */
3099 #define DWARF_LINE_OPCODE_BASE 10
3101 /* Range of line offsets in a special line info. opcode. */
3102 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3104 /* Flag that indicates the initial value of the is_stmt_start flag.
3105 In the present implementation, we do not mark any lines as
3106 the beginning of a source statement, because that information
3107 is not made available by the GCC front-end. */
3108 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3110 /* This location is used by calc_die_sizes() to keep track
3111 the offset of each DIE within the .debug_info section. */
3112 static unsigned long next_die_offset;
3114 /* Record the root of the DIE's built for the current compilation unit. */
3115 static dw_die_ref comp_unit_die;
3117 /* A list of DIEs with a NULL parent waiting to be relocated. */
3118 static limbo_die_node *limbo_die_list = 0;
3120 /* Pointer to an array of filenames referenced by this compilation unit. */
3121 static char **file_table;
3123 /* Total number of entries in the table (i.e. array) pointed to by
3124 `file_table'. This is the *total* and includes both used and unused
3126 static unsigned file_table_allocated;
3128 /* Number of entries in the file_table which are actually in use. */
3129 static unsigned file_table_in_use;
3131 /* Size (in elements) of increments by which we may expand the filename
3133 #define FILE_TABLE_INCREMENT 64
3135 /* Local pointer to the name of the main input file. Initialized in
3137 static const char *primary_filename;
3139 /* A pointer to the base of a table of references to DIE's that describe
3140 declarations. The table is indexed by DECL_UID() which is a unique
3141 number identifying each decl. */
3142 static dw_die_ref *decl_die_table;
3144 /* Number of elements currently allocated for the decl_die_table. */
3145 static unsigned decl_die_table_allocated;
3147 /* Number of elements in decl_die_table currently in use. */
3148 static unsigned decl_die_table_in_use;
3150 /* Size (in elements) of increments by which we may expand the
3152 #define DECL_DIE_TABLE_INCREMENT 256
3154 /* A pointer to the base of a table of references to declaration
3155 scopes. This table is a display which tracks the nesting
3156 of declaration scopes at the current scope and containing
3157 scopes. This table is used to find the proper place to
3158 define type declaration DIE's. */
3159 static tree *decl_scope_table;
3161 /* Number of elements currently allocated for the decl_scope_table. */
3162 static int decl_scope_table_allocated;
3164 /* Current level of nesting of declaration scopes. */
3165 static int decl_scope_depth;
3167 /* Size (in elements) of increments by which we may expand the
3168 decl_scope_table. */
3169 #define DECL_SCOPE_TABLE_INCREMENT 64
3171 /* A pointer to the base of a list of references to DIE's that
3172 are uniquely identified by their tag, presence/absence of
3173 children DIE's, and list of attribute/value pairs. */
3174 static dw_die_ref *abbrev_die_table;
3176 /* Number of elements currently allocated for abbrev_die_table. */
3177 static unsigned abbrev_die_table_allocated;
3179 /* Number of elements in type_die_table currently in use. */
3180 static unsigned abbrev_die_table_in_use;
3182 /* Size (in elements) of increments by which we may expand the
3183 abbrev_die_table. */
3184 #define ABBREV_DIE_TABLE_INCREMENT 256
3186 /* A pointer to the base of a table that contains line information
3187 for each source code line in .text in the compilation unit. */
3188 static dw_line_info_ref line_info_table;
3190 /* Number of elements currently allocated for line_info_table. */
3191 static unsigned line_info_table_allocated;
3193 /* Number of elements in separate_line_info_table currently in use. */
3194 static unsigned separate_line_info_table_in_use;
3196 /* A pointer to the base of a table that contains line information
3197 for each source code line outside of .text in the compilation unit. */
3198 static dw_separate_line_info_ref separate_line_info_table;
3200 /* Number of elements currently allocated for separate_line_info_table. */
3201 static unsigned separate_line_info_table_allocated;
3203 /* Number of elements in line_info_table currently in use. */
3204 static unsigned line_info_table_in_use;
3206 /* Size (in elements) of increments by which we may expand the
3208 #define LINE_INFO_TABLE_INCREMENT 1024
3210 /* A pointer to the base of a table that contains a list of publicly
3211 accessible names. */
3212 static pubname_ref pubname_table;
3214 /* Number of elements currently allocated for pubname_table. */
3215 static unsigned pubname_table_allocated;
3217 /* Number of elements in pubname_table currently in use. */
3218 static unsigned pubname_table_in_use;
3220 /* Size (in elements) of increments by which we may expand the
3222 #define PUBNAME_TABLE_INCREMENT 64
3224 /* A pointer to the base of a table that contains a list of publicly
3225 accessible names. */
3226 static arange_ref arange_table;
3228 /* Number of elements currently allocated for arange_table. */
3229 static unsigned arange_table_allocated;
3231 /* Number of elements in arange_table currently in use. */
3232 static unsigned arange_table_in_use;
3234 /* Size (in elements) of increments by which we may expand the
3236 #define ARANGE_TABLE_INCREMENT 64
3238 /* A pointer to the base of a list of incomplete types which might be
3239 completed at some later time. */
3241 static tree *incomplete_types_list;
3243 /* Number of elements currently allocated for the incomplete_types_list. */
3244 static unsigned incomplete_types_allocated;
3246 /* Number of elements of incomplete_types_list currently in use. */
3247 static unsigned incomplete_types;
3249 /* Size (in elements) of increments by which we may expand the incomplete
3250 types list. Actually, a single hunk of space of this size should
3251 be enough for most typical programs. */
3252 #define INCOMPLETE_TYPES_INCREMENT 64
3254 /* Record whether the function being analyzed contains inlined functions. */
3255 static int current_function_has_inlines;
3256 #if 0 && defined (MIPS_DEBUGGING_INFO)
3257 static int comp_unit_has_inlines;
3260 /* Array of RTXes referenced by the debugging information, which therefore
3261 must be kept around forever. We do this rather than perform GC on
3262 the dwarf info because almost all of the dwarf info lives forever, and
3263 it's easier to support non-GC frontends this way. */
3264 static varray_type used_rtx_varray;
3266 /* Forward declarations for functions defined in this file. */
3268 static int is_pseudo_reg PARAMS ((rtx));
3269 static tree type_main_variant PARAMS ((tree));
3270 static int is_tagged_type PARAMS ((tree));
3271 static const char *dwarf_tag_name PARAMS ((unsigned));
3272 static const char *dwarf_attr_name PARAMS ((unsigned));
3273 static const char *dwarf_form_name PARAMS ((unsigned));
3275 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3277 static tree decl_ultimate_origin PARAMS ((tree));
3278 static tree block_ultimate_origin PARAMS ((tree));
3279 static tree decl_class_context PARAMS ((tree));
3280 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3281 static void add_AT_flag PARAMS ((dw_die_ref,
3282 enum dwarf_attribute,
3284 static void add_AT_int PARAMS ((dw_die_ref,
3285 enum dwarf_attribute, long));
3286 static void add_AT_unsigned PARAMS ((dw_die_ref,
3287 enum dwarf_attribute,
3289 static void add_AT_long_long PARAMS ((dw_die_ref,
3290 enum dwarf_attribute,
3293 static void add_AT_float PARAMS ((dw_die_ref,
3294 enum dwarf_attribute,
3296 static void add_AT_string PARAMS ((dw_die_ref,
3297 enum dwarf_attribute,
3299 static void add_AT_die_ref PARAMS ((dw_die_ref,
3300 enum dwarf_attribute,
3302 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3303 enum dwarf_attribute,
3305 static void add_AT_loc PARAMS ((dw_die_ref,
3306 enum dwarf_attribute,
3308 static void add_AT_addr PARAMS ((dw_die_ref,
3309 enum dwarf_attribute,
3311 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3312 enum dwarf_attribute,
3314 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3315 enum dwarf_attribute,
3317 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3318 enum dwarf_attribute));
3319 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3320 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3321 static const char *get_AT_string PARAMS ((dw_die_ref,
3322 enum dwarf_attribute));
3323 static int get_AT_flag PARAMS ((dw_die_ref,
3324 enum dwarf_attribute));
3325 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3326 enum dwarf_attribute));
3327 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3328 enum dwarf_attribute));
3329 static int is_c_family PARAMS ((void));
3330 static int is_java PARAMS ((void));
3331 static int is_fortran PARAMS ((void));
3332 static void remove_AT PARAMS ((dw_die_ref,
3333 enum dwarf_attribute));
3334 static void remove_children PARAMS ((dw_die_ref));
3335 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3336 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3337 static dw_die_ref lookup_type_die PARAMS ((tree));
3338 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3339 static dw_die_ref lookup_decl_die PARAMS ((tree));
3340 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3341 static void print_spaces PARAMS ((FILE *));
3342 static void print_die PARAMS ((dw_die_ref, FILE *));
3343 static void print_dwarf_line_table PARAMS ((FILE *));
3344 static void reverse_die_lists PARAMS ((dw_die_ref));
3345 static void reverse_all_dies PARAMS ((dw_die_ref));
3346 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3347 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3348 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3349 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3350 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3351 static void compute_section_prefix PARAMS ((dw_die_ref));
3352 static int is_type_die PARAMS ((dw_die_ref));
3353 static int is_comdat_die PARAMS ((dw_die_ref));
3354 static int is_symbol_die PARAMS ((dw_die_ref));
3355 static char *gen_internal_sym PARAMS ((void));
3356 static void assign_symbol_names PARAMS ((dw_die_ref));
3357 static void break_out_includes PARAMS ((dw_die_ref));
3358 static void add_sibling_attributes PARAMS ((dw_die_ref));
3359 static void build_abbrev_table PARAMS ((dw_die_ref));
3360 static unsigned long size_of_string PARAMS ((const char *));
3361 static int constant_size PARAMS ((long unsigned));
3362 static unsigned long size_of_die PARAMS ((dw_die_ref));
3363 static void calc_die_sizes PARAMS ((dw_die_ref));
3364 static void clear_die_sizes PARAMS ((dw_die_ref));
3365 static unsigned long size_of_line_prolog PARAMS ((void));
3366 static unsigned long size_of_pubnames PARAMS ((void));
3367 static unsigned long size_of_aranges PARAMS ((void));
3368 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3369 static void output_value_format PARAMS ((dw_attr_ref));
3370 static void output_abbrev_section PARAMS ((void));
3371 static void output_die_symbol PARAMS ((dw_die_ref));
3372 static void output_symbolic_ref PARAMS ((dw_die_ref));
3373 static void output_die PARAMS ((dw_die_ref));
3374 static void output_compilation_unit_header PARAMS ((void));
3375 static void output_comp_unit PARAMS ((dw_die_ref));
3376 static const char *dwarf2_name PARAMS ((tree, int));
3377 static void add_pubname PARAMS ((tree, dw_die_ref));
3378 static void output_pubnames PARAMS ((void));
3379 static void add_arange PARAMS ((tree, dw_die_ref));
3380 static void output_aranges PARAMS ((void));
3381 static void output_line_info PARAMS ((void));
3382 static dw_die_ref base_type_die PARAMS ((tree));
3383 static tree root_type PARAMS ((tree));
3384 static int is_base_type PARAMS ((tree));
3385 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3386 static int type_is_enum PARAMS ((tree));
3387 static unsigned int reg_number PARAMS ((rtx));
3388 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3389 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3390 static int is_based_loc PARAMS ((rtx));
3391 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3392 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3393 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3394 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3395 static tree field_type PARAMS ((tree));
3396 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3397 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3398 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3399 static void add_AT_location_description PARAMS ((dw_die_ref,
3400 enum dwarf_attribute, rtx));
3401 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3402 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3403 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3404 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3405 static void add_bound_info PARAMS ((dw_die_ref,
3406 enum dwarf_attribute, tree));
3407 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3408 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3409 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3410 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3411 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3412 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3413 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3414 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3415 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3416 static void push_decl_scope PARAMS ((tree));
3417 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3418 static void pop_decl_scope PARAMS ((void));
3419 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3421 static const char *type_tag PARAMS ((tree));
3422 static tree member_declared_type PARAMS ((tree));
3424 static const char *decl_start_label PARAMS ((tree));
3426 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3427 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3429 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3431 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3432 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3433 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3434 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3435 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3436 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3437 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3438 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3439 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3440 static void gen_label_die PARAMS ((tree, dw_die_ref));
3441 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3442 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3443 static void gen_field_die PARAMS ((tree, dw_die_ref));
3444 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3445 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3446 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3447 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3448 static void gen_member_die PARAMS ((tree, dw_die_ref));
3449 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3450 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3451 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3452 static void gen_type_die PARAMS ((tree, dw_die_ref));
3453 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3454 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3455 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3456 static int is_redundant_typedef PARAMS ((tree));
3457 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3458 static unsigned lookup_filename PARAMS ((const char *));
3459 static void add_incomplete_type PARAMS ((tree));
3460 static void retry_incomplete_types PARAMS ((void));
3461 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3462 static void gen_abstract_function PARAMS ((tree));
3463 static rtx save_rtx PARAMS ((rtx));
3464 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3466 /* Section names used to hold DWARF debugging information. */
3467 #ifndef DEBUG_INFO_SECTION
3468 #define DEBUG_INFO_SECTION ".debug_info"
3470 #ifndef ABBREV_SECTION
3471 #define ABBREV_SECTION ".debug_abbrev"
3473 #ifndef ARANGES_SECTION
3474 #define ARANGES_SECTION ".debug_aranges"
3476 #ifndef DW_MACINFO_SECTION
3477 #define DW_MACINFO_SECTION ".debug_macinfo"
3479 #ifndef DEBUG_LINE_SECTION
3480 #define DEBUG_LINE_SECTION ".debug_line"
3483 #define LOC_SECTION ".debug_loc"
3485 #ifndef PUBNAMES_SECTION
3486 #define PUBNAMES_SECTION ".debug_pubnames"
3489 #define STR_SECTION ".debug_str"
3492 /* Standard ELF section names for compiled code and data. */
3493 #ifndef TEXT_SECTION
3494 #define TEXT_SECTION ".text"
3496 #ifndef DATA_SECTION
3497 #define DATA_SECTION ".data"
3500 #define BSS_SECTION ".bss"
3503 /* Labels we insert at beginning sections we can reference instead of
3504 the section names themselves. */
3506 #ifndef TEXT_SECTION_LABEL
3507 #define TEXT_SECTION_LABEL "Ltext"
3509 #ifndef DEBUG_LINE_SECTION_LABEL
3510 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3512 #ifndef DEBUG_INFO_SECTION_LABEL
3513 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3515 #ifndef ABBREV_SECTION_LABEL
3516 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3519 /* Definitions of defaults for formats and names of various special
3520 (artificial) labels which may be generated within this file (when the -g
3521 options is used and DWARF_DEBUGGING_INFO is in effect.
3522 If necessary, these may be overridden from within the tm.h file, but
3523 typically, overriding these defaults is unnecessary. */
3525 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3526 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3527 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3528 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3529 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3531 #ifndef TEXT_END_LABEL
3532 #define TEXT_END_LABEL "Letext"
3534 #ifndef DATA_END_LABEL
3535 #define DATA_END_LABEL "Ledata"
3537 #ifndef BSS_END_LABEL
3538 #define BSS_END_LABEL "Lebss"
3540 #ifndef INSN_LABEL_FMT
3541 #define INSN_LABEL_FMT "LI%u_"
3543 #ifndef BLOCK_BEGIN_LABEL
3544 #define BLOCK_BEGIN_LABEL "LBB"
3546 #ifndef BLOCK_END_LABEL
3547 #define BLOCK_END_LABEL "LBE"
3549 #ifndef BODY_BEGIN_LABEL
3550 #define BODY_BEGIN_LABEL "Lbb"
3552 #ifndef BODY_END_LABEL
3553 #define BODY_END_LABEL "Lbe"
3555 #ifndef LINE_CODE_LABEL
3556 #define LINE_CODE_LABEL "LM"
3558 #ifndef SEPARATE_LINE_CODE_LABEL
3559 #define SEPARATE_LINE_CODE_LABEL "LSM"
3562 /* We allow a language front-end to designate a function that is to be
3563 called to "demangle" any name before it it put into a DIE. */
3565 static const char *(*demangle_name_func) PARAMS ((const char *));
3568 dwarf2out_set_demangle_name_func (func)
3569 const char *(*func) PARAMS ((const char *));
3571 demangle_name_func = func;
3574 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3575 that means adding it to used_rtx_varray. If not, that means making
3576 a copy on the permanent_obstack. */
3583 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3586 push_obstacks_nochange ();
3587 end_temporary_allocation ();
3588 orig = copy_rtx (orig);
3595 /* Test if rtl node points to a pseudo register. */
3601 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3602 || (GET_CODE (rtl) == SUBREG
3603 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3606 /* Return a reference to a type, with its const and volatile qualifiers
3610 type_main_variant (type)
3613 type = TYPE_MAIN_VARIANT (type);
3615 /* There really should be only one main variant among any group of variants
3616 of a given type (and all of the MAIN_VARIANT values for all members of
3617 the group should point to that one type) but sometimes the C front-end
3618 messes this up for array types, so we work around that bug here. */
3620 if (TREE_CODE (type) == ARRAY_TYPE)
3621 while (type != TYPE_MAIN_VARIANT (type))
3622 type = TYPE_MAIN_VARIANT (type);
3627 /* Return non-zero if the given type node represents a tagged type. */
3630 is_tagged_type (type)
3633 register enum tree_code code = TREE_CODE (type);
3635 return (code == RECORD_TYPE || code == UNION_TYPE
3636 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3639 /* Convert a DIE tag into its string name. */
3642 dwarf_tag_name (tag)
3643 register unsigned tag;
3647 case DW_TAG_padding:
3648 return "DW_TAG_padding";
3649 case DW_TAG_array_type:
3650 return "DW_TAG_array_type";
3651 case DW_TAG_class_type:
3652 return "DW_TAG_class_type";
3653 case DW_TAG_entry_point:
3654 return "DW_TAG_entry_point";
3655 case DW_TAG_enumeration_type:
3656 return "DW_TAG_enumeration_type";
3657 case DW_TAG_formal_parameter:
3658 return "DW_TAG_formal_parameter";
3659 case DW_TAG_imported_declaration:
3660 return "DW_TAG_imported_declaration";
3662 return "DW_TAG_label";
3663 case DW_TAG_lexical_block:
3664 return "DW_TAG_lexical_block";
3666 return "DW_TAG_member";
3667 case DW_TAG_pointer_type:
3668 return "DW_TAG_pointer_type";
3669 case DW_TAG_reference_type:
3670 return "DW_TAG_reference_type";
3671 case DW_TAG_compile_unit:
3672 return "DW_TAG_compile_unit";
3673 case DW_TAG_string_type:
3674 return "DW_TAG_string_type";
3675 case DW_TAG_structure_type:
3676 return "DW_TAG_structure_type";
3677 case DW_TAG_subroutine_type:
3678 return "DW_TAG_subroutine_type";
3679 case DW_TAG_typedef:
3680 return "DW_TAG_typedef";
3681 case DW_TAG_union_type:
3682 return "DW_TAG_union_type";
3683 case DW_TAG_unspecified_parameters:
3684 return "DW_TAG_unspecified_parameters";
3685 case DW_TAG_variant:
3686 return "DW_TAG_variant";
3687 case DW_TAG_common_block:
3688 return "DW_TAG_common_block";
3689 case DW_TAG_common_inclusion:
3690 return "DW_TAG_common_inclusion";
3691 case DW_TAG_inheritance:
3692 return "DW_TAG_inheritance";
3693 case DW_TAG_inlined_subroutine:
3694 return "DW_TAG_inlined_subroutine";
3696 return "DW_TAG_module";
3697 case DW_TAG_ptr_to_member_type:
3698 return "DW_TAG_ptr_to_member_type";
3699 case DW_TAG_set_type:
3700 return "DW_TAG_set_type";
3701 case DW_TAG_subrange_type:
3702 return "DW_TAG_subrange_type";
3703 case DW_TAG_with_stmt:
3704 return "DW_TAG_with_stmt";
3705 case DW_TAG_access_declaration:
3706 return "DW_TAG_access_declaration";
3707 case DW_TAG_base_type:
3708 return "DW_TAG_base_type";
3709 case DW_TAG_catch_block:
3710 return "DW_TAG_catch_block";
3711 case DW_TAG_const_type:
3712 return "DW_TAG_const_type";
3713 case DW_TAG_constant:
3714 return "DW_TAG_constant";
3715 case DW_TAG_enumerator:
3716 return "DW_TAG_enumerator";
3717 case DW_TAG_file_type:
3718 return "DW_TAG_file_type";
3720 return "DW_TAG_friend";
3721 case DW_TAG_namelist:
3722 return "DW_TAG_namelist";
3723 case DW_TAG_namelist_item:
3724 return "DW_TAG_namelist_item";
3725 case DW_TAG_packed_type:
3726 return "DW_TAG_packed_type";
3727 case DW_TAG_subprogram:
3728 return "DW_TAG_subprogram";
3729 case DW_TAG_template_type_param:
3730 return "DW_TAG_template_type_param";
3731 case DW_TAG_template_value_param:
3732 return "DW_TAG_template_value_param";
3733 case DW_TAG_thrown_type:
3734 return "DW_TAG_thrown_type";
3735 case DW_TAG_try_block:
3736 return "DW_TAG_try_block";
3737 case DW_TAG_variant_part:
3738 return "DW_TAG_variant_part";
3739 case DW_TAG_variable:
3740 return "DW_TAG_variable";
3741 case DW_TAG_volatile_type:
3742 return "DW_TAG_volatile_type";
3743 case DW_TAG_MIPS_loop:
3744 return "DW_TAG_MIPS_loop";
3745 case DW_TAG_format_label:
3746 return "DW_TAG_format_label";
3747 case DW_TAG_function_template:
3748 return "DW_TAG_function_template";
3749 case DW_TAG_class_template:
3750 return "DW_TAG_class_template";
3751 case DW_TAG_GNU_BINCL:
3752 return "DW_TAG_GNU_BINCL";
3753 case DW_TAG_GNU_EINCL:
3754 return "DW_TAG_GNU_EINCL";
3756 return "DW_TAG_<unknown>";
3760 /* Convert a DWARF attribute code into its string name. */
3763 dwarf_attr_name (attr)
3764 register unsigned attr;
3769 return "DW_AT_sibling";
3770 case DW_AT_location:
3771 return "DW_AT_location";
3773 return "DW_AT_name";
3774 case DW_AT_ordering:
3775 return "DW_AT_ordering";
3776 case DW_AT_subscr_data:
3777 return "DW_AT_subscr_data";
3778 case DW_AT_byte_size:
3779 return "DW_AT_byte_size";
3780 case DW_AT_bit_offset:
3781 return "DW_AT_bit_offset";
3782 case DW_AT_bit_size:
3783 return "DW_AT_bit_size";
3784 case DW_AT_element_list:
3785 return "DW_AT_element_list";
3786 case DW_AT_stmt_list:
3787 return "DW_AT_stmt_list";
3789 return "DW_AT_low_pc";
3791 return "DW_AT_high_pc";
3792 case DW_AT_language:
3793 return "DW_AT_language";
3795 return "DW_AT_member";
3797 return "DW_AT_discr";
3798 case DW_AT_discr_value:
3799 return "DW_AT_discr_value";
3800 case DW_AT_visibility:
3801 return "DW_AT_visibility";
3803 return "DW_AT_import";
3804 case DW_AT_string_length:
3805 return "DW_AT_string_length";
3806 case DW_AT_common_reference:
3807 return "DW_AT_common_reference";
3808 case DW_AT_comp_dir:
3809 return "DW_AT_comp_dir";
3810 case DW_AT_const_value:
3811 return "DW_AT_const_value";
3812 case DW_AT_containing_type:
3813 return "DW_AT_containing_type";
3814 case DW_AT_default_value:
3815 return "DW_AT_default_value";
3817 return "DW_AT_inline";
3818 case DW_AT_is_optional:
3819 return "DW_AT_is_optional";
3820 case DW_AT_lower_bound:
3821 return "DW_AT_lower_bound";
3822 case DW_AT_producer:
3823 return "DW_AT_producer";
3824 case DW_AT_prototyped:
3825 return "DW_AT_prototyped";
3826 case DW_AT_return_addr:
3827 return "DW_AT_return_addr";
3828 case DW_AT_start_scope:
3829 return "DW_AT_start_scope";
3830 case DW_AT_stride_size:
3831 return "DW_AT_stride_size";
3832 case DW_AT_upper_bound:
3833 return "DW_AT_upper_bound";
3834 case DW_AT_abstract_origin:
3835 return "DW_AT_abstract_origin";
3836 case DW_AT_accessibility:
3837 return "DW_AT_accessibility";
3838 case DW_AT_address_class:
3839 return "DW_AT_address_class";
3840 case DW_AT_artificial:
3841 return "DW_AT_artificial";
3842 case DW_AT_base_types:
3843 return "DW_AT_base_types";
3844 case DW_AT_calling_convention:
3845 return "DW_AT_calling_convention";
3847 return "DW_AT_count";
3848 case DW_AT_data_member_location:
3849 return "DW_AT_data_member_location";
3850 case DW_AT_decl_column:
3851 return "DW_AT_decl_column";
3852 case DW_AT_decl_file:
3853 return "DW_AT_decl_file";
3854 case DW_AT_decl_line:
3855 return "DW_AT_decl_line";
3856 case DW_AT_declaration:
3857 return "DW_AT_declaration";
3858 case DW_AT_discr_list:
3859 return "DW_AT_discr_list";
3860 case DW_AT_encoding:
3861 return "DW_AT_encoding";
3862 case DW_AT_external:
3863 return "DW_AT_external";
3864 case DW_AT_frame_base:
3865 return "DW_AT_frame_base";
3867 return "DW_AT_friend";
3868 case DW_AT_identifier_case:
3869 return "DW_AT_identifier_case";
3870 case DW_AT_macro_info:
3871 return "DW_AT_macro_info";
3872 case DW_AT_namelist_items:
3873 return "DW_AT_namelist_items";
3874 case DW_AT_priority:
3875 return "DW_AT_priority";
3877 return "DW_AT_segment";
3878 case DW_AT_specification:
3879 return "DW_AT_specification";
3880 case DW_AT_static_link:
3881 return "DW_AT_static_link";
3883 return "DW_AT_type";
3884 case DW_AT_use_location:
3885 return "DW_AT_use_location";
3886 case DW_AT_variable_parameter:
3887 return "DW_AT_variable_parameter";
3888 case DW_AT_virtuality:
3889 return "DW_AT_virtuality";
3890 case DW_AT_vtable_elem_location:
3891 return "DW_AT_vtable_elem_location";
3893 case DW_AT_MIPS_fde:
3894 return "DW_AT_MIPS_fde";
3895 case DW_AT_MIPS_loop_begin:
3896 return "DW_AT_MIPS_loop_begin";
3897 case DW_AT_MIPS_tail_loop_begin:
3898 return "DW_AT_MIPS_tail_loop_begin";
3899 case DW_AT_MIPS_epilog_begin:
3900 return "DW_AT_MIPS_epilog_begin";
3901 case DW_AT_MIPS_loop_unroll_factor:
3902 return "DW_AT_MIPS_loop_unroll_factor";
3903 case DW_AT_MIPS_software_pipeline_depth:
3904 return "DW_AT_MIPS_software_pipeline_depth";
3905 case DW_AT_MIPS_linkage_name:
3906 return "DW_AT_MIPS_linkage_name";
3907 case DW_AT_MIPS_stride:
3908 return "DW_AT_MIPS_stride";
3909 case DW_AT_MIPS_abstract_name:
3910 return "DW_AT_MIPS_abstract_name";
3911 case DW_AT_MIPS_clone_origin:
3912 return "DW_AT_MIPS_clone_origin";
3913 case DW_AT_MIPS_has_inlines:
3914 return "DW_AT_MIPS_has_inlines";
3916 case DW_AT_sf_names:
3917 return "DW_AT_sf_names";
3918 case DW_AT_src_info:
3919 return "DW_AT_src_info";
3920 case DW_AT_mac_info:
3921 return "DW_AT_mac_info";
3922 case DW_AT_src_coords:
3923 return "DW_AT_src_coords";
3924 case DW_AT_body_begin:
3925 return "DW_AT_body_begin";
3926 case DW_AT_body_end:
3927 return "DW_AT_body_end";
3929 return "DW_AT_<unknown>";
3933 /* Convert a DWARF value form code into its string name. */
3936 dwarf_form_name (form)
3937 register unsigned form;
3942 return "DW_FORM_addr";
3943 case DW_FORM_block2:
3944 return "DW_FORM_block2";
3945 case DW_FORM_block4:
3946 return "DW_FORM_block4";
3948 return "DW_FORM_data2";
3950 return "DW_FORM_data4";
3952 return "DW_FORM_data8";
3953 case DW_FORM_string:
3954 return "DW_FORM_string";
3956 return "DW_FORM_block";
3957 case DW_FORM_block1:
3958 return "DW_FORM_block1";
3960 return "DW_FORM_data1";
3962 return "DW_FORM_flag";
3964 return "DW_FORM_sdata";
3966 return "DW_FORM_strp";
3968 return "DW_FORM_udata";
3969 case DW_FORM_ref_addr:
3970 return "DW_FORM_ref_addr";
3972 return "DW_FORM_ref1";
3974 return "DW_FORM_ref2";
3976 return "DW_FORM_ref4";
3978 return "DW_FORM_ref8";
3979 case DW_FORM_ref_udata:
3980 return "DW_FORM_ref_udata";
3981 case DW_FORM_indirect:
3982 return "DW_FORM_indirect";
3984 return "DW_FORM_<unknown>";
3988 /* Convert a DWARF type code into its string name. */
3992 dwarf_type_encoding_name (enc)
3993 register unsigned enc;
3997 case DW_ATE_address:
3998 return "DW_ATE_address";
3999 case DW_ATE_boolean:
4000 return "DW_ATE_boolean";
4001 case DW_ATE_complex_float:
4002 return "DW_ATE_complex_float";
4004 return "DW_ATE_float";
4006 return "DW_ATE_signed";
4007 case DW_ATE_signed_char:
4008 return "DW_ATE_signed_char";
4009 case DW_ATE_unsigned:
4010 return "DW_ATE_unsigned";
4011 case DW_ATE_unsigned_char:
4012 return "DW_ATE_unsigned_char";
4014 return "DW_ATE_<unknown>";
4019 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4020 instance of an inlined instance of a decl which is local to an inline
4021 function, so we have to trace all of the way back through the origin chain
4022 to find out what sort of node actually served as the original seed for the
4026 decl_ultimate_origin (decl)
4029 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4030 nodes in the function to point to themselves; ignore that if
4031 we're trying to output the abstract instance of this function. */
4032 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4035 #ifdef ENABLE_CHECKING
4036 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4037 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4038 most distant ancestor, this should never happen. */
4042 return DECL_ABSTRACT_ORIGIN (decl);
4045 /* Determine the "ultimate origin" of a block. The block may be an inlined
4046 instance of an inlined instance of a block 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 block_ultimate_origin (block)
4053 register tree block;
4055 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4057 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4058 nodes in the function to point to themselves; ignore that if
4059 we're trying to output the abstract instance of this function. */
4060 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4063 if (immediate_origin == NULL_TREE)
4067 register tree ret_val;
4068 register tree lookahead = immediate_origin;
4072 ret_val = lookahead;
4073 lookahead = (TREE_CODE (ret_val) == BLOCK)
4074 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4077 while (lookahead != NULL && lookahead != ret_val);
4083 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4084 of a virtual function may refer to a base class, so we check the 'this'
4088 decl_class_context (decl)
4091 tree context = NULL_TREE;
4093 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4094 context = DECL_CONTEXT (decl);
4096 context = TYPE_MAIN_VARIANT
4097 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4099 if (context && !TYPE_P (context))
4100 context = NULL_TREE;
4105 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4106 addition order, and correct that in reverse_all_dies. */
4109 add_dwarf_attr (die, attr)
4110 register dw_die_ref die;
4111 register dw_attr_ref attr;
4113 if (die != NULL && attr != NULL)
4115 attr->dw_attr_next = die->die_attr;
4116 die->die_attr = attr;
4120 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4121 static inline dw_val_class
4125 return a->dw_attr_val.val_class;
4128 /* Add a flag value attribute to a DIE. */
4131 add_AT_flag (die, attr_kind, flag)
4132 register dw_die_ref die;
4133 register enum dwarf_attribute attr_kind;
4134 register unsigned flag;
4136 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4138 attr->dw_attr_next = NULL;
4139 attr->dw_attr = attr_kind;
4140 attr->dw_attr_val.val_class = dw_val_class_flag;
4141 attr->dw_attr_val.v.val_flag = flag;
4142 add_dwarf_attr (die, attr);
4145 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4146 static inline unsigned
4148 register dw_attr_ref a;
4150 if (a && AT_class (a) == dw_val_class_flag)
4151 return a->dw_attr_val.v.val_flag;
4156 /* Add a signed integer attribute value to a DIE. */
4159 add_AT_int (die, attr_kind, int_val)
4160 register dw_die_ref die;
4161 register enum dwarf_attribute attr_kind;
4162 register long int int_val;
4164 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4166 attr->dw_attr_next = NULL;
4167 attr->dw_attr = attr_kind;
4168 attr->dw_attr_val.val_class = dw_val_class_const;
4169 attr->dw_attr_val.v.val_int = int_val;
4170 add_dwarf_attr (die, attr);
4173 static inline long int AT_int PARAMS ((dw_attr_ref));
4174 static inline long int
4176 register dw_attr_ref a;
4178 if (a && AT_class (a) == dw_val_class_const)
4179 return a->dw_attr_val.v.val_int;
4184 /* Add an unsigned integer attribute value to a DIE. */
4187 add_AT_unsigned (die, attr_kind, unsigned_val)
4188 register dw_die_ref die;
4189 register enum dwarf_attribute attr_kind;
4190 register unsigned long unsigned_val;
4192 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4194 attr->dw_attr_next = NULL;
4195 attr->dw_attr = attr_kind;
4196 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4197 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4198 add_dwarf_attr (die, attr);
4201 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4202 static inline unsigned long
4204 register dw_attr_ref a;
4206 if (a && AT_class (a) == dw_val_class_unsigned_const)
4207 return a->dw_attr_val.v.val_unsigned;
4212 /* Add an unsigned double integer attribute value to a DIE. */
4215 add_AT_long_long (die, attr_kind, val_hi, val_low)
4216 register dw_die_ref die;
4217 register enum dwarf_attribute attr_kind;
4218 register unsigned long val_hi;
4219 register unsigned long val_low;
4221 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4223 attr->dw_attr_next = NULL;
4224 attr->dw_attr = attr_kind;
4225 attr->dw_attr_val.val_class = dw_val_class_long_long;
4226 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4227 attr->dw_attr_val.v.val_long_long.low = val_low;
4228 add_dwarf_attr (die, attr);
4231 /* Add a floating point attribute value to a DIE and return it. */
4234 add_AT_float (die, attr_kind, length, array)
4235 register dw_die_ref die;
4236 register enum dwarf_attribute attr_kind;
4237 register unsigned length;
4238 register long *array;
4240 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4242 attr->dw_attr_next = NULL;
4243 attr->dw_attr = attr_kind;
4244 attr->dw_attr_val.val_class = dw_val_class_float;
4245 attr->dw_attr_val.v.val_float.length = length;
4246 attr->dw_attr_val.v.val_float.array = array;
4247 add_dwarf_attr (die, attr);
4250 /* Add a string attribute value to a DIE. */
4253 add_AT_string (die, attr_kind, str)
4254 register dw_die_ref die;
4255 register enum dwarf_attribute attr_kind;
4256 register const char *str;
4258 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4260 attr->dw_attr_next = NULL;
4261 attr->dw_attr = attr_kind;
4262 attr->dw_attr_val.val_class = dw_val_class_str;
4263 attr->dw_attr_val.v.val_str = xstrdup (str);
4264 add_dwarf_attr (die, attr);
4267 static inline const char *AT_string PARAMS ((dw_attr_ref));
4268 static inline const char *
4270 register dw_attr_ref a;
4272 if (a && AT_class (a) == dw_val_class_str)
4273 return a->dw_attr_val.v.val_str;
4278 /* Add a DIE reference attribute value to a DIE. */
4281 add_AT_die_ref (die, attr_kind, targ_die)
4282 register dw_die_ref die;
4283 register enum dwarf_attribute attr_kind;
4284 register dw_die_ref targ_die;
4286 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4288 attr->dw_attr_next = NULL;
4289 attr->dw_attr = attr_kind;
4290 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4291 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4292 attr->dw_attr_val.v.val_die_ref.external = 0;
4293 add_dwarf_attr (die, attr);
4296 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4297 static inline dw_die_ref
4299 register dw_attr_ref a;
4301 if (a && AT_class (a) == dw_val_class_die_ref)
4302 return a->dw_attr_val.v.val_die_ref.die;
4307 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4310 register dw_attr_ref a;
4312 if (a && AT_class (a) == dw_val_class_die_ref)
4313 return a->dw_attr_val.v.val_die_ref.external;
4318 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4320 set_AT_ref_external (a, i)
4321 register dw_attr_ref a;
4324 if (a && AT_class (a) == dw_val_class_die_ref)
4325 a->dw_attr_val.v.val_die_ref.external = i;
4330 /* Add an FDE reference attribute value to a DIE. */
4333 add_AT_fde_ref (die, attr_kind, targ_fde)
4334 register dw_die_ref die;
4335 register enum dwarf_attribute attr_kind;
4336 register unsigned targ_fde;
4338 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4340 attr->dw_attr_next = NULL;
4341 attr->dw_attr = attr_kind;
4342 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4343 attr->dw_attr_val.v.val_fde_index = targ_fde;
4344 add_dwarf_attr (die, attr);
4347 /* Add a location description attribute value to a DIE. */
4350 add_AT_loc (die, attr_kind, loc)
4351 register dw_die_ref die;
4352 register enum dwarf_attribute attr_kind;
4353 register dw_loc_descr_ref loc;
4355 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4357 attr->dw_attr_next = NULL;
4358 attr->dw_attr = attr_kind;
4359 attr->dw_attr_val.val_class = dw_val_class_loc;
4360 attr->dw_attr_val.v.val_loc = loc;
4361 add_dwarf_attr (die, attr);
4364 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4365 static inline dw_loc_descr_ref
4367 register dw_attr_ref a;
4369 if (a && AT_class (a) == dw_val_class_loc)
4370 return a->dw_attr_val.v.val_loc;
4375 /* Add an address constant attribute value to a DIE. */
4378 add_AT_addr (die, attr_kind, addr)
4379 register dw_die_ref die;
4380 register enum dwarf_attribute attr_kind;
4383 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4385 attr->dw_attr_next = NULL;
4386 attr->dw_attr = attr_kind;
4387 attr->dw_attr_val.val_class = dw_val_class_addr;
4388 attr->dw_attr_val.v.val_addr = addr;
4389 add_dwarf_attr (die, attr);
4392 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4395 register dw_attr_ref a;
4397 if (a && AT_class (a) == dw_val_class_addr)
4398 return a->dw_attr_val.v.val_addr;
4403 /* Add a label identifier attribute value to a DIE. */
4406 add_AT_lbl_id (die, attr_kind, lbl_id)
4407 register dw_die_ref die;
4408 register enum dwarf_attribute attr_kind;
4409 register const char *lbl_id;
4411 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4413 attr->dw_attr_next = NULL;
4414 attr->dw_attr = attr_kind;
4415 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4416 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4417 add_dwarf_attr (die, attr);
4420 /* Add a section offset attribute value to a DIE. */
4423 add_AT_lbl_offset (die, attr_kind, label)
4424 register dw_die_ref die;
4425 register enum dwarf_attribute attr_kind;
4426 register const char *label;
4428 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4430 attr->dw_attr_next = NULL;
4431 attr->dw_attr = attr_kind;
4432 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4433 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4434 add_dwarf_attr (die, attr);
4437 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4438 static inline const char *
4440 register dw_attr_ref a;
4442 if (a && (AT_class (a) == dw_val_class_lbl_id
4443 || AT_class (a) == dw_val_class_lbl_offset))
4444 return a->dw_attr_val.v.val_lbl_id;
4449 /* Get the attribute of type attr_kind. */
4451 static inline dw_attr_ref
4452 get_AT (die, attr_kind)
4453 register dw_die_ref die;
4454 register enum dwarf_attribute attr_kind;
4456 register dw_attr_ref a;
4457 register dw_die_ref spec = NULL;
4461 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4463 if (a->dw_attr == attr_kind)
4466 if (a->dw_attr == DW_AT_specification
4467 || a->dw_attr == DW_AT_abstract_origin)
4472 return get_AT (spec, attr_kind);
4478 /* Return the "low pc" attribute value, typically associated with
4479 a subprogram DIE. Return null if the "low pc" attribute is
4480 either not prsent, or if it cannot be represented as an
4481 assembler label identifier. */
4483 static inline const char *
4485 register dw_die_ref die;
4487 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4488 return a ? AT_lbl (a) : NULL;
4491 /* Return the "high pc" attribute value, typically associated with
4492 a subprogram DIE. Return null if the "high pc" attribute is
4493 either not prsent, or if it cannot be represented as an
4494 assembler label identifier. */
4496 static inline const char *
4498 register dw_die_ref die;
4500 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4501 return a ? AT_lbl (a) : NULL;
4504 /* Return the value of the string attribute designated by ATTR_KIND, or
4505 NULL if it is not present. */
4507 static inline const char *
4508 get_AT_string (die, attr_kind)
4509 register dw_die_ref die;
4510 register enum dwarf_attribute attr_kind;
4512 register dw_attr_ref a = get_AT (die, attr_kind);
4513 return a ? AT_string (a) : NULL;
4516 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4517 if it is not present. */
4520 get_AT_flag (die, attr_kind)
4521 register dw_die_ref die;
4522 register enum dwarf_attribute attr_kind;
4524 register dw_attr_ref a = get_AT (die, attr_kind);
4525 return a ? AT_flag (a) : 0;
4528 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4529 if it is not present. */
4531 static inline unsigned
4532 get_AT_unsigned (die, attr_kind)
4533 register dw_die_ref die;
4534 register enum dwarf_attribute attr_kind;
4536 register dw_attr_ref a = get_AT (die, attr_kind);
4537 return a ? AT_unsigned (a) : 0;
4540 static inline dw_die_ref
4541 get_AT_ref (die, attr_kind)
4543 register enum dwarf_attribute attr_kind;
4545 register dw_attr_ref a = get_AT (die, attr_kind);
4546 return a ? AT_ref (a) : NULL;
4552 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4554 return (lang == DW_LANG_C || lang == DW_LANG_C89
4555 || lang == DW_LANG_C_plus_plus);
4561 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4563 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4569 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4571 return (lang == DW_LANG_Java);
4574 /* Free up the memory used by A. */
4576 static inline void free_AT PARAMS ((dw_attr_ref));
4581 switch (AT_class (a))
4583 case dw_val_class_str:
4584 case dw_val_class_lbl_id:
4585 case dw_val_class_lbl_offset:
4586 free (a->dw_attr_val.v.val_str);
4596 /* Remove the specified attribute if present. */
4599 remove_AT (die, attr_kind)
4600 register dw_die_ref die;
4601 register enum dwarf_attribute attr_kind;
4603 register dw_attr_ref *p;
4604 register dw_attr_ref removed = NULL;
4608 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4609 if ((*p)->dw_attr == attr_kind)
4612 *p = (*p)->dw_attr_next;
4621 /* Free up the memory used by DIE. */
4623 static inline void free_die PARAMS ((dw_die_ref));
4628 remove_children (die);
4632 /* Discard the children of this DIE. */
4635 remove_children (die)
4636 register dw_die_ref die;
4638 register dw_die_ref child_die = die->die_child;
4640 die->die_child = NULL;
4642 while (child_die != NULL)
4644 register dw_die_ref tmp_die = child_die;
4645 register dw_attr_ref a;
4647 child_die = child_die->die_sib;
4649 for (a = tmp_die->die_attr; a != NULL;)
4651 register dw_attr_ref tmp_a = a;
4653 a = a->dw_attr_next;
4661 /* Add a child DIE below its parent. We build the lists up in reverse
4662 addition order, and correct that in reverse_all_dies. */
4665 add_child_die (die, child_die)
4666 register dw_die_ref die;
4667 register dw_die_ref child_die;
4669 if (die != NULL && child_die != NULL)
4671 if (die == child_die)
4673 child_die->die_parent = die;
4674 child_die->die_sib = die->die_child;
4675 die->die_child = child_die;
4679 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4680 is the specification, to the front of PARENT's list of children. */
4683 splice_child_die (parent, child)
4684 dw_die_ref parent, child;
4688 /* We want the declaration DIE from inside the class, not the
4689 specification DIE at toplevel. */
4690 if (child->die_parent != parent)
4692 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4697 if (child->die_parent != parent
4698 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4701 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4704 *p = child->die_sib;
4708 child->die_sib = parent->die_child;
4709 parent->die_child = child;
4712 /* Return a pointer to a newly created DIE node. */
4714 static inline dw_die_ref
4715 new_die (tag_value, parent_die)
4716 register enum dwarf_tag tag_value;
4717 register dw_die_ref parent_die;
4719 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4721 die->die_tag = tag_value;
4722 die->die_abbrev = 0;
4723 die->die_offset = 0;
4724 die->die_child = NULL;
4725 die->die_parent = NULL;
4726 die->die_sib = NULL;
4727 die->die_attr = NULL;
4728 die->die_symbol = NULL;
4730 if (parent_die != NULL)
4731 add_child_die (parent_die, die);
4734 limbo_die_node *limbo_node;
4736 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4737 limbo_node->die = die;
4738 limbo_node->next = limbo_die_list;
4739 limbo_die_list = limbo_node;
4745 /* Return the DIE associated with the given type specifier. */
4747 static inline dw_die_ref
4748 lookup_type_die (type)
4751 if (TREE_CODE (type) == VECTOR_TYPE)
4752 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4753 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4756 /* Equate a DIE to a given type specifier. */
4759 equate_type_number_to_die (type, type_die)
4761 register dw_die_ref type_die;
4763 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4766 /* Return the DIE associated with a given declaration. */
4768 static inline dw_die_ref
4769 lookup_decl_die (decl)
4772 register unsigned decl_id = DECL_UID (decl);
4774 return (decl_id < decl_die_table_in_use
4775 ? decl_die_table[decl_id] : NULL);
4778 /* Equate a DIE to a particular declaration. */
4781 equate_decl_number_to_die (decl, decl_die)
4783 register dw_die_ref decl_die;
4785 register unsigned decl_id = DECL_UID (decl);
4786 register unsigned num_allocated;
4788 if (decl_id >= decl_die_table_allocated)
4791 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4792 / DECL_DIE_TABLE_INCREMENT)
4793 * DECL_DIE_TABLE_INCREMENT;
4796 = (dw_die_ref *) xrealloc (decl_die_table,
4797 sizeof (dw_die_ref) * num_allocated);
4799 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4800 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4801 decl_die_table_allocated = num_allocated;
4804 if (decl_id >= decl_die_table_in_use)
4805 decl_die_table_in_use = (decl_id + 1);
4807 decl_die_table[decl_id] = decl_die;
4810 /* Keep track of the number of spaces used to indent the
4811 output of the debugging routines that print the structure of
4812 the DIE internal representation. */
4813 static int print_indent;
4815 /* Indent the line the number of spaces given by print_indent. */
4818 print_spaces (outfile)
4821 fprintf (outfile, "%*s", print_indent, "");
4824 /* Print the information associated with a given DIE, and its children.
4825 This routine is a debugging aid only. */
4828 print_die (die, outfile)
4832 register dw_attr_ref a;
4833 register dw_die_ref c;
4835 print_spaces (outfile);
4836 fprintf (outfile, "DIE %4lu: %s\n",
4837 die->die_offset, dwarf_tag_name (die->die_tag));
4838 print_spaces (outfile);
4839 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4840 fprintf (outfile, " offset: %lu\n", die->die_offset);
4842 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4844 print_spaces (outfile);
4845 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4847 switch (AT_class (a))
4849 case dw_val_class_addr:
4850 fprintf (outfile, "address");
4852 case dw_val_class_loc:
4853 fprintf (outfile, "location descriptor");
4855 case dw_val_class_const:
4856 fprintf (outfile, "%ld", AT_int (a));
4858 case dw_val_class_unsigned_const:
4859 fprintf (outfile, "%lu", AT_unsigned (a));
4861 case dw_val_class_long_long:
4862 fprintf (outfile, "constant (%lu,%lu)",
4863 a->dw_attr_val.v.val_long_long.hi,
4864 a->dw_attr_val.v.val_long_long.low);
4866 case dw_val_class_float:
4867 fprintf (outfile, "floating-point constant");
4869 case dw_val_class_flag:
4870 fprintf (outfile, "%u", AT_flag (a));
4872 case dw_val_class_die_ref:
4873 if (AT_ref (a) != NULL)
4875 if (AT_ref (a)->die_offset == 0)
4876 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
4878 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4881 fprintf (outfile, "die -> <null>");
4883 case dw_val_class_lbl_id:
4884 case dw_val_class_lbl_offset:
4885 fprintf (outfile, "label: %s", AT_lbl (a));
4887 case dw_val_class_str:
4888 if (AT_string (a) != NULL)
4889 fprintf (outfile, "\"%s\"", AT_string (a));
4891 fprintf (outfile, "<null>");
4897 fprintf (outfile, "\n");
4900 if (die->die_child != NULL)
4903 for (c = die->die_child; c != NULL; c = c->die_sib)
4904 print_die (c, outfile);
4908 if (print_indent == 0)
4909 fprintf (outfile, "\n");
4912 /* Print the contents of the source code line number correspondence table.
4913 This routine is a debugging aid only. */
4916 print_dwarf_line_table (outfile)
4919 register unsigned i;
4920 register dw_line_info_ref line_info;
4922 fprintf (outfile, "\n\nDWARF source line information\n");
4923 for (i = 1; i < line_info_table_in_use; ++i)
4925 line_info = &line_info_table[i];
4926 fprintf (outfile, "%5d: ", i);
4927 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4928 fprintf (outfile, "%6ld", line_info->dw_line_num);
4929 fprintf (outfile, "\n");
4932 fprintf (outfile, "\n\n");
4935 /* Print the information collected for a given DIE. */
4938 debug_dwarf_die (die)
4941 print_die (die, stderr);
4944 /* Print all DWARF information collected for the compilation unit.
4945 This routine is a debugging aid only. */
4951 print_die (comp_unit_die, stderr);
4952 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4953 print_dwarf_line_table (stderr);
4956 /* We build up the lists of children and attributes by pushing new ones
4957 onto the beginning of the list. Reverse the lists for DIE so that
4958 they are in order of addition. */
4961 reverse_die_lists (die)
4962 register dw_die_ref die;
4964 register dw_die_ref c, cp, cn;
4965 register dw_attr_ref a, ap, an;
4967 for (a = die->die_attr, ap = 0; a; a = an)
4969 an = a->dw_attr_next;
4970 a->dw_attr_next = ap;
4975 for (c = die->die_child, cp = 0; c; c = cn)
4981 die->die_child = cp;
4984 /* reverse_die_lists only reverses the single die you pass it. Since
4985 we used to reverse all dies in add_sibling_attributes, which runs
4986 through all the dies, it would reverse all the dies. Now, however,
4987 since we don't call reverse_die_lists in add_sibling_attributes, we
4988 need a routine to recursively reverse all the dies. This is that
4992 reverse_all_dies (die)
4993 register dw_die_ref die;
4995 register dw_die_ref c;
4997 reverse_die_lists (die);
4999 for (c = die->die_child; c; c = c->die_sib)
5000 reverse_all_dies (c);
5003 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5004 the CU for the enclosing include file, if any. BINCL_DIE is the
5005 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5009 push_new_compile_unit (old_unit, bincl_die)
5010 dw_die_ref old_unit, bincl_die;
5012 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5013 dw_die_ref new_unit = gen_compile_unit_die (filename);
5014 new_unit->die_sib = old_unit;
5018 /* Close an include-file CU and reopen the enclosing one. */
5021 pop_compile_unit (old_unit)
5022 dw_die_ref old_unit;
5024 dw_die_ref new_unit = old_unit->die_sib;
5025 old_unit->die_sib = NULL;
5029 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5030 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5032 /* Calculate the checksum of a location expression. */
5035 loc_checksum (loc, ctx)
5036 dw_loc_descr_ref loc;
5037 struct md5_ctx *ctx;
5039 PROCESS (loc->dw_loc_opc);
5040 PROCESS (loc->dw_loc_oprnd1);
5041 PROCESS (loc->dw_loc_oprnd2);
5044 /* Calculate the checksum of an attribute. */
5047 attr_checksum (at, ctx)
5049 struct md5_ctx *ctx;
5051 dw_loc_descr_ref loc;
5054 PROCESS (at->dw_attr);
5056 /* We don't care about differences in file numbering. */
5057 if (at->dw_attr == DW_AT_decl_file
5058 /* Or that this was compiled with a different compiler snapshot; if
5059 the output is the same, that's what matters. */
5060 || at->dw_attr == DW_AT_producer)
5063 switch (AT_class (at))
5065 case dw_val_class_const:
5066 PROCESS (at->dw_attr_val.v.val_int);
5068 case dw_val_class_unsigned_const:
5069 PROCESS (at->dw_attr_val.v.val_unsigned);
5071 case dw_val_class_long_long:
5072 PROCESS (at->dw_attr_val.v.val_long_long);
5074 case dw_val_class_float:
5075 PROCESS (at->dw_attr_val.v.val_float);
5077 case dw_val_class_flag:
5078 PROCESS (at->dw_attr_val.v.val_flag);
5081 case dw_val_class_str:
5082 PROCESS_STRING (AT_string (at));
5084 case dw_val_class_addr:
5086 switch (GET_CODE (r))
5089 PROCESS_STRING (XSTR (r, 0));
5097 case dw_val_class_loc:
5098 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5099 loc_checksum (loc, ctx);
5102 case dw_val_class_die_ref:
5103 if (AT_ref (at)->die_offset)
5104 PROCESS (AT_ref (at)->die_offset);
5105 /* FIXME else use target die name or something. */
5107 case dw_val_class_fde_ref:
5108 case dw_val_class_lbl_id:
5109 case dw_val_class_lbl_offset:
5116 /* Calculate the checksum of a DIE. */
5119 die_checksum (die, ctx)
5121 struct md5_ctx *ctx;
5126 PROCESS (die->die_tag);
5128 for (a = die->die_attr; a; a = a->dw_attr_next)
5129 attr_checksum (a, ctx);
5131 for (c = die->die_child; c; c = c->die_sib)
5132 die_checksum (c, ctx);
5136 #undef PROCESS_STRING
5138 /* The prefix to attach to symbols on DIEs in the current comdat debug
5140 static char *comdat_symbol_id;
5142 /* The index of the current symbol within the current comdat CU. */
5143 static unsigned int comdat_symbol_number;
5145 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5146 children, and set comdat_symbol_id accordingly. */
5149 compute_section_prefix (unit_die)
5150 dw_die_ref unit_die;
5154 unsigned char checksum[16];
5157 md5_init_ctx (&ctx);
5158 die_checksum (unit_die, &ctx);
5159 md5_finish_ctx (&ctx, checksum);
5161 p = file_name_nondirectory (get_AT_string (unit_die, DW_AT_name));
5162 name = (char *) alloca (strlen (p) + 64);
5163 sprintf (name, "%s.", p);
5165 clean_symbol_name (name);
5167 p = name + strlen (name);
5168 for (i = 0; i < 4; ++i)
5170 sprintf (p, "%.2x", checksum[i]);
5174 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5175 comdat_symbol_number = 0;
5178 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5184 switch (die->die_tag)
5186 case DW_TAG_array_type:
5187 case DW_TAG_class_type:
5188 case DW_TAG_enumeration_type:
5189 case DW_TAG_pointer_type:
5190 case DW_TAG_reference_type:
5191 case DW_TAG_string_type:
5192 case DW_TAG_structure_type:
5193 case DW_TAG_subroutine_type:
5194 case DW_TAG_union_type:
5195 case DW_TAG_ptr_to_member_type:
5196 case DW_TAG_set_type:
5197 case DW_TAG_subrange_type:
5198 case DW_TAG_base_type:
5199 case DW_TAG_const_type:
5200 case DW_TAG_file_type:
5201 case DW_TAG_packed_type:
5202 case DW_TAG_volatile_type:
5209 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5210 Basically, we want to choose the bits that are likely to be shared between
5211 compilations (types) and leave out the bits that are specific to individual
5212 compilations (functions). */
5219 /* I think we want to leave base types and __vtbl_ptr_type in the
5220 main CU, as we do for stabs. The advantage is a greater
5221 likelihood of sharing between objects that don't include headers
5222 in the same order (and therefore would put the base types in a
5223 different comdat). jason 8/28/00 */
5224 if (c->die_tag == DW_TAG_base_type)
5227 if (c->die_tag == DW_TAG_pointer_type
5228 || c->die_tag == DW_TAG_reference_type
5229 || c->die_tag == DW_TAG_const_type
5230 || c->die_tag == DW_TAG_volatile_type)
5232 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5233 return t ? is_comdat_die (t) : 0;
5237 return is_type_die (c);
5240 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5241 compilation unit. */
5247 if (is_type_die (c))
5249 if (get_AT (c, DW_AT_declaration)
5250 && ! get_AT (c, DW_AT_specification))
5259 static int label_num;
5260 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5261 return xstrdup (buf);
5264 /* Assign symbols to all worthy DIEs under DIE. */
5267 assign_symbol_names (die)
5268 register dw_die_ref die;
5270 register dw_die_ref c;
5272 if (is_symbol_die (die))
5274 if (comdat_symbol_id)
5276 char *p = alloca (strlen (comdat_symbol_id) + 64);
5277 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5278 comdat_symbol_id, comdat_symbol_number++);
5279 die->die_symbol = xstrdup (p);
5282 die->die_symbol = gen_internal_sym ();
5285 for (c = die->die_child; c != NULL; c = c->die_sib)
5286 assign_symbol_names (c);
5289 /* Traverse the DIE (which is always comp_unit_die), and set up
5290 additional compilation units for each of the include files we see
5291 bracketed by BINCL/EINCL. */
5294 break_out_includes (die)
5295 register dw_die_ref die;
5298 register dw_die_ref unit = NULL;
5299 limbo_die_node *node;
5301 for (ptr = &(die->die_child); *ptr; )
5303 register dw_die_ref c = *ptr;
5305 if (c->die_tag == DW_TAG_GNU_BINCL
5306 || c->die_tag == DW_TAG_GNU_EINCL
5307 || (unit && is_comdat_die (c)))
5309 /* This DIE is for a secondary CU; remove it from the main one. */
5312 if (c->die_tag == DW_TAG_GNU_BINCL)
5314 unit = push_new_compile_unit (unit, c);
5317 else if (c->die_tag == DW_TAG_GNU_EINCL)
5319 unit = pop_compile_unit (unit);
5323 add_child_die (unit, c);
5327 /* Leave this DIE in the main CU. */
5328 ptr = &(c->die_sib);
5334 /* We can only use this in debugging, since the frontend doesn't check
5335 to make sure that we leave every include file we enter. */
5340 assign_symbol_names (die);
5341 for (node = limbo_die_list; node; node = node->next)
5343 compute_section_prefix (node->die);
5344 assign_symbol_names (node->die);
5348 /* Traverse the DIE and add a sibling attribute if it may have the
5349 effect of speeding up access to siblings. To save some space,
5350 avoid generating sibling attributes for DIE's without children. */
5353 add_sibling_attributes (die)
5354 register dw_die_ref die;
5356 register dw_die_ref c;
5358 if (die->die_tag != DW_TAG_compile_unit
5359 && die->die_sib && die->die_child != NULL)
5360 /* Add the sibling link to the front of the attribute list. */
5361 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5363 for (c = die->die_child; c != NULL; c = c->die_sib)
5364 add_sibling_attributes (c);
5367 /* The format of each DIE (and its attribute value pairs)
5368 is encoded in an abbreviation table. This routine builds the
5369 abbreviation table and assigns a unique abbreviation id for
5370 each abbreviation entry. The children of each die are visited
5374 build_abbrev_table (die)
5375 register dw_die_ref die;
5377 register unsigned long abbrev_id;
5378 register unsigned long n_alloc;
5379 register dw_die_ref c;
5380 register dw_attr_ref d_attr, a_attr;
5382 /* Scan the DIE references, and mark as external any that refer to
5383 DIEs from other CUs (i.e. those with cleared die_offset). */
5384 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5386 if (AT_class (d_attr) == dw_val_class_die_ref
5387 && AT_ref (d_attr)->die_offset == 0)
5389 if (AT_ref (d_attr)->die_symbol == 0)
5391 set_AT_ref_external (d_attr, 1);
5395 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5397 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5399 if (abbrev->die_tag == die->die_tag)
5401 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5403 a_attr = abbrev->die_attr;
5404 d_attr = die->die_attr;
5406 while (a_attr != NULL && d_attr != NULL)
5408 if ((a_attr->dw_attr != d_attr->dw_attr)
5409 || (value_format (a_attr) != value_format (d_attr)))
5412 a_attr = a_attr->dw_attr_next;
5413 d_attr = d_attr->dw_attr_next;
5416 if (a_attr == NULL && d_attr == NULL)
5422 if (abbrev_id >= abbrev_die_table_in_use)
5424 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5426 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5428 = (dw_die_ref *) xrealloc (abbrev_die_table,
5429 sizeof (dw_die_ref) * n_alloc);
5431 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
5432 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5433 abbrev_die_table_allocated = n_alloc;
5436 ++abbrev_die_table_in_use;
5437 abbrev_die_table[abbrev_id] = die;
5440 die->die_abbrev = abbrev_id;
5441 for (c = die->die_child; c != NULL; c = c->die_sib)
5442 build_abbrev_table (c);
5445 /* Return the size of a string, including the null byte.
5447 This used to treat backslashes as escapes, and hence they were not included
5448 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5449 which treats a backslash as a backslash, escaping it if necessary, and hence
5450 we must include them in the count. */
5452 static unsigned long
5453 size_of_string (str)
5454 register const char *str;
5456 return strlen (str) + 1;
5459 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5462 constant_size (value)
5463 long unsigned value;
5470 log = floor_log2 (value);
5473 log = 1 << (floor_log2 (log) + 1);
5478 /* Return the size of a DIE, as it is represented in the
5479 .debug_info section. */
5481 static unsigned long
5483 register dw_die_ref die;
5485 register unsigned long size = 0;
5486 register dw_attr_ref a;
5488 size += size_of_uleb128 (die->die_abbrev);
5489 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5491 switch (AT_class (a))
5493 case dw_val_class_addr:
5494 size += DWARF2_ADDR_SIZE;
5496 case dw_val_class_loc:
5498 register unsigned long lsize = size_of_locs (AT_loc (a));
5501 size += constant_size (lsize);
5505 case dw_val_class_const:
5506 size += size_of_sleb128 (AT_int (a));
5508 case dw_val_class_unsigned_const:
5509 size += constant_size (AT_unsigned (a));
5511 case dw_val_class_long_long:
5512 size += 1 + 8; /* block */
5514 case dw_val_class_float:
5515 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5517 case dw_val_class_flag:
5520 case dw_val_class_die_ref:
5521 size += DWARF_OFFSET_SIZE;
5523 case dw_val_class_fde_ref:
5524 size += DWARF_OFFSET_SIZE;
5526 case dw_val_class_lbl_id:
5527 size += DWARF2_ADDR_SIZE;
5529 case dw_val_class_lbl_offset:
5530 size += DWARF_OFFSET_SIZE;
5532 case dw_val_class_str:
5533 size += size_of_string (AT_string (a));
5543 /* Size the debugging information associated with a given DIE.
5544 Visits the DIE's children recursively. Updates the global
5545 variable next_die_offset, on each time through. Uses the
5546 current value of next_die_offset to update the die_offset
5547 field in each DIE. */
5550 calc_die_sizes (die)
5553 register dw_die_ref c;
5554 die->die_offset = next_die_offset;
5555 next_die_offset += size_of_die (die);
5557 for (c = die->die_child; c != NULL; c = c->die_sib)
5560 if (die->die_child != NULL)
5561 /* Count the null byte used to terminate sibling lists. */
5562 next_die_offset += 1;
5565 /* Clear the offsets and sizes for a die and its children. We do this so
5566 that we know whether or not a reference needs to use FORM_ref_addr; only
5567 DIEs in the same CU will have non-zero offsets available. */
5570 clear_die_sizes (die)
5573 register dw_die_ref c;
5574 die->die_offset = 0;
5575 for (c = die->die_child; c; c = c->die_sib)
5576 clear_die_sizes (c);
5579 /* Return the size of the line information prolog generated for the
5580 compilation unit. */
5582 static unsigned long
5583 size_of_line_prolog ()
5585 register unsigned long size;
5586 register unsigned long ft_index;
5588 size = DWARF_LINE_PROLOG_HEADER_SIZE;
5590 /* Count the size of the table giving number of args for each
5592 size += DWARF_LINE_OPCODE_BASE - 1;
5594 /* Include directory table is empty (at present). Count only the
5595 null byte used to terminate the table. */
5598 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5600 /* File name entry. */
5601 size += size_of_string (file_table[ft_index]);
5603 /* Include directory index. */
5604 size += size_of_uleb128 (0);
5606 /* Modification time. */
5607 size += size_of_uleb128 (0);
5609 /* File length in bytes. */
5610 size += size_of_uleb128 (0);
5613 /* Count the file table terminator. */
5618 /* Return the size of the .debug_pubnames table generated for the
5619 compilation unit. */
5621 static unsigned long
5624 register unsigned long size;
5625 register unsigned i;
5627 size = DWARF_PUBNAMES_HEADER_SIZE;
5628 for (i = 0; i < pubname_table_in_use; ++i)
5630 register pubname_ref p = &pubname_table[i];
5631 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5634 size += DWARF_OFFSET_SIZE;
5638 /* Return the size of the information in the .debug_aranges section. */
5640 static unsigned long
5643 register unsigned long size;
5645 size = DWARF_ARANGES_HEADER_SIZE;
5647 /* Count the address/length pair for this compilation unit. */
5648 size += 2 * DWARF2_ADDR_SIZE;
5649 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5651 /* Count the two zero words used to terminated the address range table. */
5652 size += 2 * DWARF2_ADDR_SIZE;
5656 /* Select the encoding of an attribute value. */
5658 static enum dwarf_form
5662 switch (a->dw_attr_val.val_class)
5664 case dw_val_class_addr:
5665 return DW_FORM_addr;
5666 case dw_val_class_loc:
5667 switch (constant_size (size_of_locs (AT_loc (a))))
5670 return DW_FORM_block1;
5672 return DW_FORM_block2;
5676 case dw_val_class_const:
5677 return DW_FORM_sdata;
5678 case dw_val_class_unsigned_const:
5679 switch (constant_size (AT_unsigned (a)))
5682 return DW_FORM_data1;
5684 return DW_FORM_data2;
5686 return DW_FORM_data4;
5688 return DW_FORM_data8;
5692 case dw_val_class_long_long:
5693 return DW_FORM_block1;
5694 case dw_val_class_float:
5695 return DW_FORM_block1;
5696 case dw_val_class_flag:
5697 return DW_FORM_flag;
5698 case dw_val_class_die_ref:
5699 if (AT_ref_external (a))
5700 return DW_FORM_ref_addr;
5703 case dw_val_class_fde_ref:
5704 return DW_FORM_data;
5705 case dw_val_class_lbl_id:
5706 return DW_FORM_addr;
5707 case dw_val_class_lbl_offset:
5708 return DW_FORM_data;
5709 case dw_val_class_str:
5710 return DW_FORM_string;
5716 /* Output the encoding of an attribute value. */
5719 output_value_format (a)
5722 enum dwarf_form form = value_format (a);
5724 output_uleb128 (form);
5726 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
5728 fputc ('\n', asm_out_file);
5731 /* Output the .debug_abbrev section which defines the DIE abbreviation
5735 output_abbrev_section ()
5737 unsigned long abbrev_id;
5740 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5742 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5744 output_uleb128 (abbrev_id);
5746 fprintf (asm_out_file, " (abbrev code)");
5748 fputc ('\n', asm_out_file);
5749 output_uleb128 (abbrev->die_tag);
5751 fprintf (asm_out_file, " (TAG: %s)",
5752 dwarf_tag_name (abbrev->die_tag));
5754 fputc ('\n', asm_out_file);
5755 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
5756 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
5759 fprintf (asm_out_file, "\t%s %s",
5761 (abbrev->die_child != NULL
5762 ? "DW_children_yes" : "DW_children_no"));
5764 fputc ('\n', asm_out_file);
5766 for (a_attr = abbrev->die_attr; a_attr != NULL;
5767 a_attr = a_attr->dw_attr_next)
5769 output_uleb128 (a_attr->dw_attr);
5771 fprintf (asm_out_file, " (%s)",
5772 dwarf_attr_name (a_attr->dw_attr));
5774 fputc ('\n', asm_out_file);
5775 output_value_format (a_attr);
5778 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
5781 /* Terminate the table. */
5782 fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP);
5785 /* Output a symbol we can use to refer to this DIE from another CU. */
5788 output_die_symbol (die)
5789 register dw_die_ref die;
5791 char *sym = die->die_symbol;
5796 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5797 /* We make these global, not weak; if the target doesn't support
5798 .linkonce, it doesn't support combining the sections, so debugging
5800 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5801 ASM_OUTPUT_LABEL (asm_out_file, sym);
5804 /* Output a symbolic (i.e. FORM_ref_addr) reference to TARGET_DIE. */
5807 output_symbolic_ref (target_die)
5808 dw_die_ref target_die;
5810 char *sym = target_die->die_symbol;
5815 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, sym);
5818 /* Output the DIE and its attributes. Called recursively to generate
5819 the definitions of each child DIE. */
5823 register dw_die_ref die;
5825 register dw_attr_ref a;
5826 register dw_die_ref c;
5827 register unsigned long size;
5829 /* If someone in another CU might refer to us, set up a symbol for
5830 them to point to. */
5831 if (die->die_symbol)
5832 output_die_symbol (die);
5834 output_uleb128 (die->die_abbrev);
5836 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5837 die->die_offset, dwarf_tag_name (die->die_tag));
5839 fputc ('\n', asm_out_file);
5841 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5843 switch (AT_class (a))
5845 case dw_val_class_addr:
5846 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
5849 case dw_val_class_loc:
5850 size = size_of_locs (AT_loc (a));
5852 /* Output the block length for this list of location operations. */
5853 switch (constant_size (size))
5856 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5859 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5866 fprintf (asm_out_file, "\t%s %s",
5867 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5869 fputc ('\n', asm_out_file);
5871 output_loc_sequence (AT_loc (a));
5874 case dw_val_class_const:
5875 /* ??? It would be slightly more efficient to use a scheme like is
5876 used for unsigned constants below, but gdb 4.x does not sign
5877 extend. Gdb 5.x does sign extend. */
5878 output_sleb128 (AT_int (a));
5881 case dw_val_class_unsigned_const:
5882 switch (constant_size (AT_unsigned (a)))
5885 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
5888 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
5891 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
5894 ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a));
5901 case dw_val_class_long_long:
5902 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5904 fprintf (asm_out_file, "\t%s %s",
5905 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5907 fputc ('\n', asm_out_file);
5908 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file,
5909 a->dw_attr_val.v.val_long_long.hi,
5910 a->dw_attr_val.v.val_long_long.low);
5913 fprintf (asm_out_file,
5914 "\t%s long long constant", ASM_COMMENT_START);
5916 fputc ('\n', asm_out_file);
5919 case dw_val_class_float:
5921 register unsigned int i;
5922 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5923 a->dw_attr_val.v.val_float.length * 4);
5925 fprintf (asm_out_file, "\t%s %s",
5926 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5928 fputc ('\n', asm_out_file);
5929 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5931 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5932 a->dw_attr_val.v.val_float.array[i]);
5934 fprintf (asm_out_file, "\t%s fp constant word %u",
5935 ASM_COMMENT_START, i);
5937 fputc ('\n', asm_out_file);
5942 case dw_val_class_flag:
5943 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
5946 case dw_val_class_die_ref:
5947 if (AT_ref_external (a))
5948 output_symbolic_ref (AT_ref (a));
5950 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
5953 case dw_val_class_fde_ref:
5956 ASM_GENERATE_INTERNAL_LABEL
5957 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5958 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5959 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5963 case dw_val_class_lbl_id:
5964 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
5967 case dw_val_class_lbl_offset:
5968 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
5971 case dw_val_class_str:
5973 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
5975 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
5976 (int) strlen (AT_string (a)) + 1);
5983 if (AT_class (a) != dw_val_class_loc
5984 && AT_class (a) != dw_val_class_long_long
5985 && AT_class (a) != dw_val_class_float)
5988 fprintf (asm_out_file, "\t%s %s",
5989 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5991 fputc ('\n', asm_out_file);
5995 for (c = die->die_child; c != NULL; c = c->die_sib)
5998 if (die->die_child != NULL)
6000 /* Add null byte to terminate sibling list. */
6001 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6003 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
6004 ASM_COMMENT_START, die->die_offset);
6006 fputc ('\n', asm_out_file);
6010 /* Output the compilation unit that appears at the beginning of the
6011 .debug_info section, and precedes the DIE descriptions. */
6014 output_compilation_unit_header ()
6016 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
6018 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
6021 fputc ('\n', asm_out_file);
6022 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6024 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
6026 fputc ('\n', asm_out_file);
6027 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
6029 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
6032 fputc ('\n', asm_out_file);
6033 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6035 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
6037 fputc ('\n', asm_out_file);
6040 /* Output the compilation unit DIE and its children. */
6043 output_comp_unit (die)
6048 if (die->die_child == 0)
6051 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6052 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6053 calc_die_sizes (die);
6055 build_abbrev_table (die);
6057 if (die->die_symbol)
6059 secname = (char *) alloca (strlen (die->die_symbol) + 24);
6060 sprintf (secname, ".gnu.linkonce.wi.%s", die->die_symbol);
6061 die->die_symbol = NULL;
6064 secname = (char *) DEBUG_INFO_SECTION;
6066 /* Output debugging information. */
6067 fputc ('\n', asm_out_file);
6068 ASM_OUTPUT_SECTION (asm_out_file, secname);
6069 output_compilation_unit_header ();
6072 /* Leave the sizes on the main CU, since we do it last and we use the
6073 sizes in output_pubnames. */
6074 if (die->die_symbol)
6075 clear_die_sizes (die);
6078 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6079 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6080 argument list, and maybe the scope. */
6083 dwarf2_name (decl, scope)
6087 return (*decl_printable_name) (decl, scope ? 1 : 0);
6090 /* Add a new entry to .debug_pubnames if appropriate. */
6093 add_pubname (decl, die)
6099 if (! TREE_PUBLIC (decl))
6102 if (pubname_table_in_use == pubname_table_allocated)
6104 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6105 pubname_table = (pubname_ref) xrealloc
6106 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6109 p = &pubname_table[pubname_table_in_use++];
6112 p->name = xstrdup (dwarf2_name (decl, 1));
6115 /* Output the public names table used to speed up access to externally
6116 visible names. For now, only generate entries for externally
6117 visible procedures. */
6122 register unsigned i;
6123 register unsigned long pubnames_length = size_of_pubnames ();
6125 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
6128 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
6131 fputc ('\n', asm_out_file);
6132 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6135 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6137 fputc ('\n', asm_out_file);
6138 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6140 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6143 fputc ('\n', asm_out_file);
6144 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
6146 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
6148 fputc ('\n', asm_out_file);
6149 for (i = 0; i < pubname_table_in_use; ++i)
6151 register pubname_ref pub = &pubname_table[i];
6153 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6154 if (pub->die->die_offset == 0)
6157 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
6159 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
6161 fputc ('\n', asm_out_file);
6165 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
6166 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
6170 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
6171 (int) strlen (pub->name) + 1);
6174 fputc ('\n', asm_out_file);
6177 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
6178 fputc ('\n', asm_out_file);
6181 /* Add a new entry to .debug_aranges if appropriate. */
6184 add_arange (decl, die)
6188 if (! DECL_SECTION_NAME (decl))
6191 if (arange_table_in_use == arange_table_allocated)
6193 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6195 = (arange_ref) xrealloc (arange_table,
6196 arange_table_allocated * sizeof (dw_die_ref));
6199 arange_table[arange_table_in_use++] = die;
6202 /* Output the information that goes into the .debug_aranges table.
6203 Namely, define the beginning and ending address range of the
6204 text section generated for this compilation unit. */
6209 register unsigned i;
6210 register unsigned long aranges_length = size_of_aranges ();
6212 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
6214 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
6217 fputc ('\n', asm_out_file);
6218 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6220 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6222 fputc ('\n', asm_out_file);
6223 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6225 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6228 fputc ('\n', asm_out_file);
6229 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6231 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
6233 fputc ('\n', asm_out_file);
6234 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6236 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
6239 fputc ('\n', asm_out_file);
6241 /* We need to align to twice the pointer size here. */
6242 if (DWARF_ARANGES_PAD_SIZE)
6244 /* Pad using a 2 bytes word so that padding is correct
6245 for any pointer size. */
6246 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
6247 for (i = 2; i < DWARF_ARANGES_PAD_SIZE; i += 2)
6248 fprintf (asm_out_file, ",0");
6250 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
6251 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
6254 fputc ('\n', asm_out_file);
6255 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
6257 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6259 fputc ('\n', asm_out_file);
6260 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
6261 text_section_label);
6263 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6265 fputc ('\n', asm_out_file);
6266 for (i = 0; i < arange_table_in_use; ++i)
6268 dw_die_ref die = arange_table[i];
6270 /* We shouldn't see aranges for DIEs outside of the main CU. */
6271 if (die->die_offset == 0)
6274 if (die->die_tag == DW_TAG_subprogram)
6275 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
6278 /* A static variable; extract the symbol from DW_AT_location.
6279 Note that this code isn't currently hit, as we only emit
6280 aranges for functions (jason 9/23/99). */
6282 dw_attr_ref a = get_AT (die, DW_AT_location);
6283 dw_loc_descr_ref loc;
6284 if (! a || AT_class (a) != dw_val_class_loc)
6288 if (loc->dw_loc_opc != DW_OP_addr)
6291 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
6292 loc->dw_loc_oprnd1.v.val_addr);
6296 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6298 fputc ('\n', asm_out_file);
6299 if (die->die_tag == DW_TAG_subprogram)
6300 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
6301 get_AT_low_pc (die));
6303 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
6304 get_AT_unsigned (die, DW_AT_byte_size));
6307 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6309 fputc ('\n', asm_out_file);
6312 /* Output the terminator words. */
6313 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6314 fputc ('\n', asm_out_file);
6315 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6316 fputc ('\n', asm_out_file);
6319 /* Output the source line number correspondence information. This
6320 information goes into the .debug_line section. */
6325 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6326 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6327 register unsigned opc;
6328 register unsigned n_op_args;
6329 register unsigned long ft_index;
6330 register unsigned long lt_index;
6331 register unsigned long current_line;
6332 register long line_offset;
6333 register long line_delta;
6334 register unsigned long current_file;
6335 register unsigned long function;
6337 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
6339 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
6342 fputc ('\n', asm_out_file);
6343 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
6344 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6346 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6348 fputc ('\n', asm_out_file);
6349 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
6351 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
6353 fputc ('\n', asm_out_file);
6354 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
6356 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
6359 fputc ('\n', asm_out_file);
6360 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
6362 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
6365 fputc ('\n', asm_out_file);
6366 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
6368 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
6371 fputc ('\n', asm_out_file);
6372 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
6374 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
6377 fputc ('\n', asm_out_file);
6378 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
6380 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
6382 fputc ('\n', asm_out_file);
6383 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6387 case DW_LNS_advance_pc:
6388 case DW_LNS_advance_line:
6389 case DW_LNS_set_file:
6390 case DW_LNS_set_column:
6391 case DW_LNS_fixed_advance_pc:
6398 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
6400 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
6401 ASM_COMMENT_START, opc, n_op_args);
6402 fputc ('\n', asm_out_file);
6406 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
6408 /* Include directory table is empty, at present */
6409 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6410 fputc ('\n', asm_out_file);
6412 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
6414 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
6418 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
6419 fprintf (asm_out_file, "%s File Entry: 0x%lx",
6420 ASM_COMMENT_START, ft_index);
6424 ASM_OUTPUT_ASCII (asm_out_file,
6425 file_table[ft_index],
6426 (int) strlen (file_table[ft_index]) + 1);
6429 fputc ('\n', asm_out_file);
6431 /* Include directory index */
6433 fputc ('\n', asm_out_file);
6435 /* Modification time */
6437 fputc ('\n', asm_out_file);
6439 /* File length in bytes */
6441 fputc ('\n', asm_out_file);
6444 /* Terminate the file name table */
6445 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6446 fputc ('\n', asm_out_file);
6448 /* We used to set the address register to the first location in the text
6449 section here, but that didn't accomplish anything since we already
6450 have a line note for the opening brace of the first function. */
6452 /* Generate the line number to PC correspondence table, encoded as
6453 a series of state machine operations. */
6456 strcpy (prev_line_label, text_section_label);
6457 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6459 register dw_line_info_ref line_info = &line_info_table[lt_index];
6462 /* Disable this optimization for now; GDB wants to see two line notes
6463 at the beginning of a function so it can find the end of the
6466 /* Don't emit anything for redundant notes. Just updating the
6467 address doesn't accomplish anything, because we already assume
6468 that anything after the last address is this line. */
6469 if (line_info->dw_line_num == current_line
6470 && line_info->dw_file_num == current_file)
6474 /* Emit debug info for the address of the current line, choosing
6475 the encoding that uses the least amount of space. */
6476 /* ??? Unfortunately, we have little choice here currently, and must
6477 always use the most general form. Gcc does not know the address
6478 delta itself, so we can't use DW_LNS_advance_pc. There are no known
6479 dwarf2 aware assemblers at this time, so we can't use any special
6480 pseudo ops that would allow the assembler to optimally encode this for
6481 us. Many ports do have length attributes which will give an upper
6482 bound on the address range. We could perhaps use length attributes
6483 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
6484 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6487 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6488 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6490 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6493 fputc ('\n', asm_out_file);
6494 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
6495 fputc ('\n', asm_out_file);
6499 /* This can handle any delta. This takes
6500 4+DWARF2_ADDR_SIZE bytes. */
6501 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6503 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6505 fputc ('\n', asm_out_file);
6506 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6507 fputc ('\n', asm_out_file);
6508 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6509 fputc ('\n', asm_out_file);
6510 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6511 fputc ('\n', asm_out_file);
6513 strcpy (prev_line_label, line_label);
6515 /* Emit debug info for the source file of the current line, if
6516 different from the previous line. */
6517 if (line_info->dw_file_num != current_file)
6519 current_file = line_info->dw_file_num;
6520 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6522 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6524 fputc ('\n', asm_out_file);
6525 output_uleb128 (current_file);
6527 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
6529 fputc ('\n', asm_out_file);
6532 /* Emit debug info for the current line number, choosing the encoding
6533 that uses the least amount of space. */
6534 if (line_info->dw_line_num != current_line)
6536 line_offset = line_info->dw_line_num - current_line;
6537 line_delta = line_offset - DWARF_LINE_BASE;
6538 current_line = line_info->dw_line_num;
6539 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6541 /* This can handle deltas from -10 to 234, using the current
6542 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6544 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6545 DWARF_LINE_OPCODE_BASE + line_delta);
6547 fprintf (asm_out_file,
6548 "\t%s line %ld", ASM_COMMENT_START, current_line);
6550 fputc ('\n', asm_out_file);
6554 /* This can handle any delta. This takes at least 4 bytes,
6555 depending on the value being encoded. */
6556 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6558 fprintf (asm_out_file, "\t%s advance to line %ld",
6559 ASM_COMMENT_START, current_line);
6561 fputc ('\n', asm_out_file);
6562 output_sleb128 (line_offset);
6563 fputc ('\n', asm_out_file);
6564 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6566 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6567 fputc ('\n', asm_out_file);
6572 /* We still need to start a new row, so output a copy insn. */
6573 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6575 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6576 fputc ('\n', asm_out_file);
6580 /* Emit debug info for the address of the end of the function. */
6583 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6585 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6588 fputc ('\n', asm_out_file);
6589 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
6590 fputc ('\n', asm_out_file);
6594 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6596 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
6597 fputc ('\n', asm_out_file);
6598 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6599 fputc ('\n', asm_out_file);
6600 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6601 fputc ('\n', asm_out_file);
6602 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
6603 fputc ('\n', asm_out_file);
6606 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6608 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
6610 fputc ('\n', asm_out_file);
6612 fputc ('\n', asm_out_file);
6613 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6614 fputc ('\n', asm_out_file);
6619 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6621 register dw_separate_line_info_ref line_info
6622 = &separate_line_info_table[lt_index];
6625 /* Don't emit anything for redundant notes. */
6626 if (line_info->dw_line_num == current_line
6627 && line_info->dw_file_num == current_file
6628 && line_info->function == function)
6632 /* Emit debug info for the address of the current line. If this is
6633 a new function, or the first line of a function, then we need
6634 to handle it differently. */
6635 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6637 if (function != line_info->function)
6639 function = line_info->function;
6641 /* Set the address register to the first line in the function */
6642 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6644 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6647 fputc ('\n', asm_out_file);
6648 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6649 fputc ('\n', asm_out_file);
6650 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6651 fputc ('\n', asm_out_file);
6652 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6653 fputc ('\n', asm_out_file);
6657 /* ??? See the DW_LNS_advance_pc comment above. */
6660 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6662 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6665 fputc ('\n', asm_out_file);
6666 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6668 fputc ('\n', asm_out_file);
6672 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6674 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6676 fputc ('\n', asm_out_file);
6677 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6678 fputc ('\n', asm_out_file);
6679 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6680 fputc ('\n', asm_out_file);
6681 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6682 fputc ('\n', asm_out_file);
6685 strcpy (prev_line_label, line_label);
6687 /* Emit debug info for the source file of the current line, if
6688 different from the previous line. */
6689 if (line_info->dw_file_num != current_file)
6691 current_file = line_info->dw_file_num;
6692 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6694 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6696 fputc ('\n', asm_out_file);
6697 output_uleb128 (current_file);
6699 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
6701 fputc ('\n', asm_out_file);
6704 /* Emit debug info for the current line number, choosing the encoding
6705 that uses the least amount of space. */
6706 if (line_info->dw_line_num != current_line)
6708 line_offset = line_info->dw_line_num - current_line;
6709 line_delta = line_offset - DWARF_LINE_BASE;
6710 current_line = line_info->dw_line_num;
6711 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6713 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6714 DWARF_LINE_OPCODE_BASE + line_delta);
6716 fprintf (asm_out_file,
6717 "\t%s line %ld", ASM_COMMENT_START, current_line);
6719 fputc ('\n', asm_out_file);
6723 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6725 fprintf (asm_out_file, "\t%s advance to line %ld",
6726 ASM_COMMENT_START, current_line);
6728 fputc ('\n', asm_out_file);
6729 output_sleb128 (line_offset);
6730 fputc ('\n', asm_out_file);
6731 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6733 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6734 fputc ('\n', asm_out_file);
6739 /* We still need to start a new row, so output a copy insn. */
6740 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6742 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6743 fputc ('\n', asm_out_file);
6751 /* If we're done with a function, end its sequence. */
6752 if (lt_index == separate_line_info_table_in_use
6753 || separate_line_info_table[lt_index].function != function)
6758 /* Emit debug info for the address of the end of the function. */
6759 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6762 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6764 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6767 fputc ('\n', asm_out_file);
6768 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6770 fputc ('\n', asm_out_file);
6774 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6776 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6778 fputc ('\n', asm_out_file);
6779 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6780 fputc ('\n', asm_out_file);
6781 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6782 fputc ('\n', asm_out_file);
6783 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6784 fputc ('\n', asm_out_file);
6787 /* Output the marker for the end of this sequence. */
6788 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6790 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
6793 fputc ('\n', asm_out_file);
6795 fputc ('\n', asm_out_file);
6796 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6797 fputc ('\n', asm_out_file);
6801 /* Output the marker for the end of the line number info. */
6802 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
6805 /* Given a pointer to a tree node for some base type, return a pointer to
6806 a DIE that describes the given type.
6808 This routine must only be called for GCC type nodes that correspond to
6809 Dwarf base (fundamental) types. */
6812 base_type_die (type)
6815 register dw_die_ref base_type_result;
6816 register const char *type_name;
6817 register enum dwarf_type encoding;
6818 register tree name = TYPE_NAME (type);
6820 if (TREE_CODE (type) == ERROR_MARK
6821 || TREE_CODE (type) == VOID_TYPE)
6826 if (TREE_CODE (name) == TYPE_DECL)
6827 name = DECL_NAME (name);
6829 type_name = IDENTIFIER_POINTER (name);
6832 type_name = "__unknown__";
6834 switch (TREE_CODE (type))
6837 /* Carefully distinguish the C character types, without messing
6838 up if the language is not C. Note that we check only for the names
6839 that contain spaces; other names might occur by coincidence in other
6841 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6842 && (type == char_type_node
6843 || ! strcmp (type_name, "signed char")
6844 || ! strcmp (type_name, "unsigned char"))))
6846 if (TREE_UNSIGNED (type))
6847 encoding = DW_ATE_unsigned;
6849 encoding = DW_ATE_signed;
6852 /* else fall through. */
6855 /* GNU Pascal/Ada CHAR type. Not used in C. */
6856 if (TREE_UNSIGNED (type))
6857 encoding = DW_ATE_unsigned_char;
6859 encoding = DW_ATE_signed_char;
6863 encoding = DW_ATE_float;
6866 /* Dwarf2 doesn't know anything about complex ints, so use
6867 a user defined type for it. */
6869 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6870 encoding = DW_ATE_complex_float;
6872 encoding = DW_ATE_lo_user;
6876 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6877 encoding = DW_ATE_boolean;
6881 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6884 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6885 if (demangle_name_func)
6886 type_name = (*demangle_name_func) (type_name);
6888 add_AT_string (base_type_result, DW_AT_name, type_name);
6889 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6890 int_size_in_bytes (type));
6891 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6893 return base_type_result;
6896 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6897 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6898 a given type is generally the same as the given type, except that if the
6899 given type is a pointer or reference type, then the root type of the given
6900 type is the root type of the "basis" type for the pointer or reference
6901 type. (This definition of the "root" type is recursive.) Also, the root
6902 type of a `const' qualified type or a `volatile' qualified type is the
6903 root type of the given type without the qualifiers. */
6909 if (TREE_CODE (type) == ERROR_MARK)
6910 return error_mark_node;
6912 switch (TREE_CODE (type))
6915 return error_mark_node;
6918 case REFERENCE_TYPE:
6919 return type_main_variant (root_type (TREE_TYPE (type)));
6922 return type_main_variant (type);
6926 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6927 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6933 switch (TREE_CODE (type))
6948 case QUAL_UNION_TYPE:
6953 case REFERENCE_TYPE:
6966 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6967 entry that chains various modifiers in front of the given type. */
6970 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6972 register int is_const_type;
6973 register int is_volatile_type;
6974 register dw_die_ref context_die;
6976 register enum tree_code code = TREE_CODE (type);
6977 register dw_die_ref mod_type_die = NULL;
6978 register dw_die_ref sub_die = NULL;
6979 register tree item_type = NULL;
6981 if (code != ERROR_MARK)
6983 type = build_type_variant (type, is_const_type, is_volatile_type);
6985 mod_type_die = lookup_type_die (type);
6987 return mod_type_die;
6989 /* Handle C typedef types. */
6990 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6991 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6993 tree dtype = TREE_TYPE (TYPE_NAME (type));
6996 /* For a named type, use the typedef. */
6997 gen_type_die (type, context_die);
6998 mod_type_die = lookup_type_die (type);
7001 else if (is_const_type < TYPE_READONLY (dtype)
7002 || is_volatile_type < TYPE_VOLATILE (dtype))
7003 /* cv-unqualified version of named type. Just use the unnamed
7004 type to which it refers. */
7006 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
7007 is_const_type, is_volatile_type,
7009 /* Else cv-qualified version of named type; fall through. */
7015 else if (is_const_type)
7017 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7018 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7020 else if (is_volatile_type)
7022 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7023 sub_die = modified_type_die (type, 0, 0, context_die);
7025 else if (code == POINTER_TYPE)
7027 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7028 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7030 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7032 item_type = TREE_TYPE (type);
7034 else if (code == REFERENCE_TYPE)
7036 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7037 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7039 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7041 item_type = TREE_TYPE (type);
7043 else if (is_base_type (type))
7044 mod_type_die = base_type_die (type);
7047 gen_type_die (type, context_die);
7049 /* We have to get the type_main_variant here (and pass that to the
7050 `lookup_type_die' routine) because the ..._TYPE node we have
7051 might simply be a *copy* of some original type node (where the
7052 copy was created to help us keep track of typedef names) and
7053 that copy might have a different TYPE_UID from the original
7055 mod_type_die = lookup_type_die (type_main_variant (type));
7056 if (mod_type_die == NULL)
7061 equate_type_number_to_die (type, mod_type_die);
7063 /* We must do this after the equate_type_number_to_die call, in case
7064 this is a recursive type. This ensures that the modified_type_die
7065 recursion will terminate even if the type is recursive. Recursive
7066 types are possible in Ada. */
7067 sub_die = modified_type_die (item_type,
7068 TYPE_READONLY (item_type),
7069 TYPE_VOLATILE (item_type),
7072 if (sub_die != NULL)
7073 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7075 return mod_type_die;
7078 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7079 an enumerated type. */
7085 return TREE_CODE (type) == ENUMERAL_TYPE;
7088 /* Return the register number described by a given RTL node. */
7094 register unsigned regno = REGNO (rtl);
7096 if (regno >= FIRST_PSEUDO_REGISTER)
7098 warning ("internal regno botch: regno = %d\n", regno);
7102 regno = DBX_REGISTER_NUMBER (regno);
7106 /* Return a location descriptor that designates a machine register. */
7108 static dw_loc_descr_ref
7109 reg_loc_descriptor (rtl)
7112 register dw_loc_descr_ref loc_result = NULL;
7113 register unsigned reg = reg_number (rtl);
7116 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7118 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7123 /* Return a location descriptor that designates a base+offset location. */
7125 static dw_loc_descr_ref
7126 based_loc_descr (reg, offset)
7130 register dw_loc_descr_ref loc_result;
7131 /* For the "frame base", we use the frame pointer or stack pointer
7132 registers, since the RTL for local variables is relative to one of
7134 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7135 ? HARD_FRAME_POINTER_REGNUM
7136 : STACK_POINTER_REGNUM);
7139 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7141 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7143 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7148 /* Return true if this RTL expression describes a base+offset calculation. */
7154 return (GET_CODE (rtl) == PLUS
7155 && ((GET_CODE (XEXP (rtl, 0)) == REG
7156 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7159 /* The following routine converts the RTL for a variable or parameter
7160 (resident in memory) into an equivalent Dwarf representation of a
7161 mechanism for getting the address of that same variable onto the top of a
7162 hypothetical "address evaluation" stack.
7164 When creating memory location descriptors, we are effectively transforming
7165 the RTL for a memory-resident object into its Dwarf postfix expression
7166 equivalent. This routine recursively descends an RTL tree, turning
7167 it into Dwarf postfix code as it goes.
7169 MODE is the mode of the memory reference, needed to handle some
7170 autoincrement addressing modes. */
7172 static dw_loc_descr_ref
7173 mem_loc_descriptor (rtl, mode)
7175 enum machine_mode mode;
7177 dw_loc_descr_ref mem_loc_result = NULL;
7178 /* Note that for a dynamically sized array, the location we will generate a
7179 description of here will be the lowest numbered location which is
7180 actually within the array. That's *not* necessarily the same as the
7181 zeroth element of the array. */
7183 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7184 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7187 switch (GET_CODE (rtl))
7191 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7192 just fall into the SUBREG code. */
7197 /* The case of a subreg may arise when we have a local (register)
7198 variable or a formal (register) parameter which doesn't quite fill
7199 up an entire register. For now, just assume that it is
7200 legitimate to make the Dwarf info refer to the whole register which
7201 contains the given subreg. */
7202 rtl = XEXP (rtl, 0);
7207 /* Whenever a register number forms a part of the description of the
7208 method for calculating the (dynamic) address of a memory resident
7209 object, DWARF rules require the register number be referred to as
7210 a "base register". This distinction is not based in any way upon
7211 what category of register the hardware believes the given register
7212 belongs to. This is strictly DWARF terminology we're dealing with
7213 here. Note that in cases where the location of a memory-resident
7214 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7215 OP_CONST (0)) the actual DWARF location descriptor that we generate
7216 may just be OP_BASEREG (basereg). This may look deceptively like
7217 the object in question was allocated to a register (rather than in
7218 memory) so DWARF consumers need to be aware of the subtle
7219 distinction between OP_REG and OP_BASEREG. */
7220 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7224 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7225 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7229 /* Some ports can transform a symbol ref into a label ref, because
7230 the symbol ref is too far away and has to be dumped into a constant
7234 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7235 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7236 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7241 /* Turn these into a PLUS expression and fall into the PLUS code
7243 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7244 GEN_INT (GET_CODE (rtl) == PRE_INC
7245 ? GET_MODE_UNIT_SIZE (mode)
7246 : -GET_MODE_UNIT_SIZE (mode)));
7251 if (is_based_loc (rtl))
7252 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7253 INTVAL (XEXP (rtl, 1)));
7256 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0),
7258 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1),
7260 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
7265 /* If a pseudo-reg is optimized away, it is possible for it to
7266 be replaced with a MEM containing a multiply. */
7267 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode));
7268 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode));
7269 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7273 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
7280 return mem_loc_result;
7283 /* Return a descriptor that describes the concatenation of two locations.
7284 This is typically a complex variable. */
7286 static dw_loc_descr_ref
7287 concat_loc_descriptor (x0, x1)
7288 register rtx x0, x1;
7290 dw_loc_descr_ref cc_loc_result = NULL;
7292 if (!is_pseudo_reg (x0)
7293 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7294 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7295 add_loc_descr (&cc_loc_result,
7296 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7298 if (!is_pseudo_reg (x1)
7299 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7300 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7301 add_loc_descr (&cc_loc_result,
7302 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7304 return cc_loc_result;
7307 /* Output a proper Dwarf location descriptor for a variable or parameter
7308 which is either allocated in a register or in a memory location. For a
7309 register, we just generate an OP_REG and the register number. For a
7310 memory location we provide a Dwarf postfix expression describing how to
7311 generate the (dynamic) address of the object onto the address stack. */
7313 static dw_loc_descr_ref
7314 loc_descriptor (rtl)
7317 dw_loc_descr_ref loc_result = NULL;
7318 switch (GET_CODE (rtl))
7321 /* The case of a subreg may arise when we have a local (register)
7322 variable or a formal (register) parameter which doesn't quite fill
7323 up an entire register. For now, just assume that it is
7324 legitimate to make the Dwarf info refer to the whole register which
7325 contains the given subreg. */
7326 rtl = XEXP (rtl, 0);
7331 loc_result = reg_loc_descriptor (rtl);
7335 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7339 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7349 /* Given a value, round it up to the lowest multiple of `boundary'
7350 which is not less than the value itself. */
7352 static inline HOST_WIDE_INT
7353 ceiling (value, boundary)
7354 HOST_WIDE_INT value;
7355 unsigned int boundary;
7357 return (((value + boundary - 1) / boundary) * boundary);
7360 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
7361 pointer to the declared type for the relevant field variable, or return
7362 `integer_type_node' if the given node turns out to be an
7371 if (TREE_CODE (decl) == ERROR_MARK)
7372 return integer_type_node;
7374 type = DECL_BIT_FIELD_TYPE (decl);
7375 if (type == NULL_TREE)
7376 type = TREE_TYPE (decl);
7381 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7382 node, return the alignment in bits for the type, or else return
7383 BITS_PER_WORD if the node actually turns out to be an
7386 static inline unsigned
7387 simple_type_align_in_bits (type)
7390 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
7393 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7394 node, return the size in bits for the type if it is a constant, or else
7395 return the alignment for the type if the type's size is not constant, or
7396 else return BITS_PER_WORD if the type actually turns out to be an
7399 static inline unsigned HOST_WIDE_INT
7400 simple_type_size_in_bits (type)
7403 if (TREE_CODE (type) == ERROR_MARK)
7404 return BITS_PER_WORD;
7407 register tree type_size_tree = TYPE_SIZE (type);
7409 if (! host_integerp (type_size_tree, 1))
7410 return TYPE_ALIGN (type);
7412 return tree_low_cst (type_size_tree, 1);
7416 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
7417 return the byte offset of the lowest addressed byte of the "containing
7418 object" for the given FIELD_DECL, or return 0 if we are unable to
7419 determine what that offset is, either because the argument turns out to
7420 be a pointer to an ERROR_MARK node, or because the offset is actually
7421 variable. (We can't handle the latter case just yet). */
7423 static HOST_WIDE_INT
7424 field_byte_offset (decl)
7427 unsigned int type_align_in_bytes;
7428 unsigned int type_align_in_bits;
7429 unsigned HOST_WIDE_INT type_size_in_bits;
7430 HOST_WIDE_INT object_offset_in_align_units;
7431 HOST_WIDE_INT object_offset_in_bits;
7432 HOST_WIDE_INT object_offset_in_bytes;
7434 tree field_size_tree;
7435 HOST_WIDE_INT bitpos_int;
7436 HOST_WIDE_INT deepest_bitpos;
7437 unsigned HOST_WIDE_INT field_size_in_bits;
7439 if (TREE_CODE (decl) == ERROR_MARK)
7442 if (TREE_CODE (decl) != FIELD_DECL)
7445 type = field_type (decl);
7446 field_size_tree = DECL_SIZE (decl);
7448 /* If there was an error, the size could be zero. */
7449 if (! field_size_tree)
7457 /* We cannot yet cope with fields whose positions are variable, so
7458 for now, when we see such things, we simply return 0. Someday, we may
7459 be able to handle such cases, but it will be damn difficult. */
7460 if (! host_integerp (bit_position (decl), 0))
7463 bitpos_int = int_bit_position (decl);
7465 /* If we don't know the size of the field, pretend it's a full word. */
7466 if (host_integerp (field_size_tree, 1))
7467 field_size_in_bits = tree_low_cst (field_size_tree, 1);
7469 field_size_in_bits = BITS_PER_WORD;
7471 type_size_in_bits = simple_type_size_in_bits (type);
7472 type_align_in_bits = simple_type_align_in_bits (type);
7473 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
7475 /* Note that the GCC front-end doesn't make any attempt to keep track of
7476 the starting bit offset (relative to the start of the containing
7477 structure type) of the hypothetical "containing object" for a bit-
7478 field. Thus, when computing the byte offset value for the start of the
7479 "containing object" of a bit-field, we must deduce this information on
7480 our own. This can be rather tricky to do in some cases. For example,
7481 handling the following structure type definition when compiling for an
7482 i386/i486 target (which only aligns long long's to 32-bit boundaries)
7485 struct S { int field1; long long field2:31; };
7487 Fortunately, there is a simple rule-of-thumb which can be
7488 used in such cases. When compiling for an i386/i486, GCC will allocate
7489 8 bytes for the structure shown above. It decides to do this based upon
7490 one simple rule for bit-field allocation. Quite simply, GCC allocates
7491 each "containing object" for each bit-field at the first (i.e. lowest
7492 addressed) legitimate alignment boundary (based upon the required
7493 minimum alignment for the declared type of the field) which it can
7494 possibly use, subject to the condition that there is still enough
7495 available space remaining in the containing object (when allocated at
7496 the selected point) to fully accommodate all of the bits of the
7497 bit-field itself. This simple rule makes it obvious why GCC allocates
7498 8 bytes for each object of the structure type shown above. When looking
7499 for a place to allocate the "containing object" for `field2', the
7500 compiler simply tries to allocate a 64-bit "containing object" at each
7501 successive 32-bit boundary (starting at zero) until it finds a place to
7502 allocate that 64- bit field such that at least 31 contiguous (and
7503 previously unallocated) bits remain within that selected 64 bit field.
7504 (As it turns out, for the example above, the compiler finds that it is
7505 OK to allocate the "containing object" 64-bit field at bit-offset zero
7506 within the structure type.) Here we attempt to work backwards from the
7507 limited set of facts we're given, and we try to deduce from those facts,
7508 where GCC must have believed that the containing object started (within
7509 the structure type). The value we deduce is then used (by the callers of
7510 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
7511 for fields (both bit-fields and, in the case of DW_AT_location, regular
7514 /* Figure out the bit-distance from the start of the structure to the
7515 "deepest" bit of the bit-field. */
7516 deepest_bitpos = bitpos_int + field_size_in_bits;
7518 /* This is the tricky part. Use some fancy footwork to deduce where the
7519 lowest addressed bit of the containing object must be. */
7520 object_offset_in_bits
7521 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
7523 /* Compute the offset of the containing object in "alignment units". */
7524 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
7526 /* Compute the offset of the containing object in bytes. */
7527 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
7529 return object_offset_in_bytes;
7532 /* The following routines define various Dwarf attributes and any data
7533 associated with them. */
7535 /* Add a location description attribute value to a DIE.
7537 This emits location attributes suitable for whole variables and
7538 whole parameters. Note that the location attributes for struct fields are
7539 generated by the routine `data_member_location_attribute' below. */
7542 add_AT_location_description (die, attr_kind, rtl)
7544 enum dwarf_attribute attr_kind;
7547 /* Handle a special case. If we are about to output a location descriptor
7548 for a variable or parameter which has been optimized out of existence,
7549 don't do that. A variable which has been optimized out
7550 of existence will have a DECL_RTL value which denotes a pseudo-reg.
7551 Currently, in some rare cases, variables can have DECL_RTL values which
7552 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
7553 elsewhere in the compiler. We treat such cases as if the variable(s) in
7554 question had been optimized out of existence. */
7556 if (is_pseudo_reg (rtl)
7557 || (GET_CODE (rtl) == MEM
7558 && is_pseudo_reg (XEXP (rtl, 0)))
7559 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
7560 references the internal argument pointer (a pseudo) in a function
7561 where all references to the internal argument pointer were
7562 eliminated via the optimizers. */
7563 || (GET_CODE (rtl) == MEM
7564 && GET_CODE (XEXP (rtl, 0)) == PLUS
7565 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
7566 || (GET_CODE (rtl) == CONCAT
7567 && is_pseudo_reg (XEXP (rtl, 0))
7568 && is_pseudo_reg (XEXP (rtl, 1))))
7571 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
7574 /* Attach the specialized form of location attribute used for data
7575 members of struct and union types. In the special case of a
7576 FIELD_DECL node which represents a bit-field, the "offset" part
7577 of this special location descriptor must indicate the distance
7578 in bytes from the lowest-addressed byte of the containing struct
7579 or union type to the lowest-addressed byte of the "containing
7580 object" for the bit-field. (See the `field_byte_offset' function
7581 above).. For any given bit-field, the "containing object" is a
7582 hypothetical object (of some integral or enum type) within which
7583 the given bit-field lives. The type of this hypothetical
7584 "containing object" is always the same as the declared type of
7585 the individual bit-field itself (for GCC anyway... the DWARF
7586 spec doesn't actually mandate this). Note that it is the size
7587 (in bytes) of the hypothetical "containing object" which will
7588 be given in the DW_AT_byte_size attribute for this bit-field.
7589 (See the `byte_size_attribute' function below.) It is also used
7590 when calculating the value of the DW_AT_bit_offset attribute.
7591 (See the `bit_offset_attribute' function below). */
7594 add_data_member_location_attribute (die, decl)
7595 register dw_die_ref die;
7598 register unsigned long offset;
7599 register dw_loc_descr_ref loc_descr;
7600 register enum dwarf_location_atom op;
7602 if (TREE_CODE (decl) == TREE_VEC)
7603 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
7605 offset = field_byte_offset (decl);
7607 /* The DWARF2 standard says that we should assume that the structure address
7608 is already on the stack, so we can specify a structure field address
7609 by using DW_OP_plus_uconst. */
7611 #ifdef MIPS_DEBUGGING_INFO
7612 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
7613 correctly. It works only if we leave the offset on the stack. */
7616 op = DW_OP_plus_uconst;
7619 loc_descr = new_loc_descr (op, offset, 0);
7620 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
7623 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
7624 does not have a "location" either in memory or in a register. These
7625 things can arise in GNU C when a constant is passed as an actual parameter
7626 to an inlined function. They can also arise in C++ where declared
7627 constants do not necessarily get memory "homes". */
7630 add_const_value_attribute (die, rtl)
7631 register dw_die_ref die;
7634 switch (GET_CODE (rtl))
7637 /* Note that a CONST_INT rtx could represent either an integer or a
7638 floating-point constant. A CONST_INT is used whenever the constant
7639 will fit into a single word. In all such cases, the original mode
7640 of the constant value is wiped out, and the CONST_INT rtx is
7641 assigned VOIDmode. */
7642 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
7646 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
7647 floating-point constant. A CONST_DOUBLE is used whenever the
7648 constant requires more than one word in order to be adequately
7649 represented. We output CONST_DOUBLEs as blocks. */
7651 register enum machine_mode mode = GET_MODE (rtl);
7653 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
7655 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
7659 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
7663 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
7667 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
7672 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
7679 add_AT_float (die, DW_AT_const_value, length, array);
7682 add_AT_long_long (die, DW_AT_const_value,
7683 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
7688 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
7694 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
7698 /* In cases where an inlined instance of an inline function is passed
7699 the address of an `auto' variable (which is local to the caller) we
7700 can get a situation where the DECL_RTL of the artificial local
7701 variable (for the inlining) which acts as a stand-in for the
7702 corresponding formal parameter (of the inline function) will look
7703 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
7704 exactly a compile-time constant expression, but it isn't the address
7705 of the (artificial) local variable either. Rather, it represents the
7706 *value* which the artificial local variable always has during its
7707 lifetime. We currently have no way to represent such quasi-constant
7708 values in Dwarf, so for now we just punt and generate nothing. */
7712 /* No other kinds of rtx should be possible here. */
7718 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
7719 data attribute for a variable or a parameter. We generate the
7720 DW_AT_const_value attribute only in those cases where the given variable
7721 or parameter does not have a true "location" either in memory or in a
7722 register. This can happen (for example) when a constant is passed as an
7723 actual argument in a call to an inline function. (It's possible that
7724 these things can crop up in other ways also.) Note that one type of
7725 constant value which can be passed into an inlined function is a constant
7726 pointer. This can happen for example if an actual argument in an inlined
7727 function call evaluates to a compile-time constant address. */
7730 add_location_or_const_value_attribute (die, decl)
7731 register dw_die_ref die;
7735 register tree declared_type;
7736 register tree passed_type;
7738 if (TREE_CODE (decl) == ERROR_MARK)
7741 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
7744 /* Here we have to decide where we are going to say the parameter "lives"
7745 (as far as the debugger is concerned). We only have a couple of
7746 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
7748 DECL_RTL normally indicates where the parameter lives during most of the
7749 activation of the function. If optimization is enabled however, this
7750 could be either NULL or else a pseudo-reg. Both of those cases indicate
7751 that the parameter doesn't really live anywhere (as far as the code
7752 generation parts of GCC are concerned) during most of the function's
7753 activation. That will happen (for example) if the parameter is never
7754 referenced within the function.
7756 We could just generate a location descriptor here for all non-NULL
7757 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
7758 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
7759 where DECL_RTL is NULL or is a pseudo-reg.
7761 Note however that we can only get away with using DECL_INCOMING_RTL as
7762 a backup substitute for DECL_RTL in certain limited cases. In cases
7763 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
7764 we can be sure that the parameter was passed using the same type as it is
7765 declared to have within the function, and that its DECL_INCOMING_RTL
7766 points us to a place where a value of that type is passed.
7768 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
7769 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
7770 because in these cases DECL_INCOMING_RTL points us to a value of some
7771 type which is *different* from the type of the parameter itself. Thus,
7772 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
7773 such cases, the debugger would end up (for example) trying to fetch a
7774 `float' from a place which actually contains the first part of a
7775 `double'. That would lead to really incorrect and confusing
7776 output at debug-time.
7778 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
7779 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
7780 are a couple of exceptions however. On little-endian machines we can
7781 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
7782 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
7783 an integral type that is smaller than TREE_TYPE (decl). These cases arise
7784 when (on a little-endian machine) a non-prototyped function has a
7785 parameter declared to be of type `short' or `char'. In such cases,
7786 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
7787 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
7788 passed `int' value. If the debugger then uses that address to fetch
7789 a `short' or a `char' (on a little-endian machine) the result will be
7790 the correct data, so we allow for such exceptional cases below.
7792 Note that our goal here is to describe the place where the given formal
7793 parameter lives during most of the function's activation (i.e. between
7794 the end of the prologue and the start of the epilogue). We'll do that
7795 as best as we can. Note however that if the given formal parameter is
7796 modified sometime during the execution of the function, then a stack
7797 backtrace (at debug-time) will show the function as having been
7798 called with the *new* value rather than the value which was
7799 originally passed in. This happens rarely enough that it is not
7800 a major problem, but it *is* a problem, and I'd like to fix it.
7802 A future version of dwarf2out.c may generate two additional
7803 attributes for any given DW_TAG_formal_parameter DIE which will
7804 describe the "passed type" and the "passed location" for the
7805 given formal parameter in addition to the attributes we now
7806 generate to indicate the "declared type" and the "active
7807 location" for each parameter. This additional set of attributes
7808 could be used by debuggers for stack backtraces. Separately, note
7809 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
7810 NULL also. This happens (for example) for inlined-instances of
7811 inline function formal parameters which are never referenced.
7812 This really shouldn't be happening. All PARM_DECL nodes should
7813 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
7814 doesn't currently generate these values for inlined instances of
7815 inline function parameters, so when we see such cases, we are
7816 just out-of-luck for the time being (until integrate.c
7819 /* Use DECL_RTL as the "location" unless we find something better. */
7820 rtl = DECL_RTL (decl);
7822 if (TREE_CODE (decl) == PARM_DECL)
7824 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
7826 declared_type = type_main_variant (TREE_TYPE (decl));
7827 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
7829 /* This decl represents a formal parameter which was optimized out.
7830 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
7831 all* cases where (rtl == NULL_RTX) just below. */
7832 if (declared_type == passed_type)
7833 rtl = DECL_INCOMING_RTL (decl);
7834 else if (! BYTES_BIG_ENDIAN
7835 && TREE_CODE (declared_type) == INTEGER_TYPE
7836 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
7837 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
7838 rtl = DECL_INCOMING_RTL (decl);
7841 /* If the parm was passed in registers, but lives on the stack, then
7842 make a big endian correction if the mode of the type of the
7843 parameter is not the same as the mode of the rtl. */
7844 /* ??? This is the same series of checks that are made in dbxout.c before
7845 we reach the big endian correction code there. It isn't clear if all
7846 of these checks are necessary here, but keeping them all is the safe
7848 else if (GET_CODE (rtl) == MEM
7849 && XEXP (rtl, 0) != const0_rtx
7850 && ! CONSTANT_P (XEXP (rtl, 0))
7851 /* Not passed in memory. */
7852 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
7853 /* Not passed by invisible reference. */
7854 && (GET_CODE (XEXP (rtl, 0)) != REG
7855 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
7856 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
7857 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
7858 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
7861 /* Big endian correction check. */
7863 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
7864 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
7867 int offset = (UNITS_PER_WORD
7868 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
7869 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
7870 plus_constant (XEXP (rtl, 0), offset));
7874 if (rtl == NULL_RTX)
7877 rtl = eliminate_regs (rtl, 0, NULL_RTX);
7878 #ifdef LEAF_REG_REMAP
7879 if (current_function_uses_only_leaf_regs)
7880 leaf_renumber_regs_insn (rtl);
7883 switch (GET_CODE (rtl))
7886 /* The address of a variable that was optimized away; don't emit
7897 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7898 add_const_value_attribute (die, rtl);
7905 add_AT_location_description (die, DW_AT_location, rtl);
7913 /* Generate an DW_AT_name attribute given some string value to be included as
7914 the value of the attribute. */
7917 add_name_attribute (die, name_string)
7918 register dw_die_ref die;
7919 register const char *name_string;
7921 if (name_string != NULL && *name_string != 0)
7923 if (demangle_name_func)
7924 name_string = (*demangle_name_func) (name_string);
7926 add_AT_string (die, DW_AT_name, name_string);
7930 /* Given a tree node describing an array bound (either lower or upper) output
7931 a representation for that bound. */
7934 add_bound_info (subrange_die, bound_attr, bound)
7935 register dw_die_ref subrange_die;
7936 register enum dwarf_attribute bound_attr;
7937 register tree bound;
7939 /* If this is an Ada unconstrained array type, then don't emit any debug
7940 info because the array bounds are unknown. They are parameterized when
7941 the type is instantiated. */
7942 if (contains_placeholder_p (bound))
7945 switch (TREE_CODE (bound))
7950 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7952 if (! host_integerp (bound, 0)
7953 || (bound_attr == DW_AT_lower_bound
7954 && (((is_c_family () || is_java ()) && integer_zerop (bound))
7955 || (is_fortran () && integer_onep (bound)))))
7956 /* use the default */
7959 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
7964 case NON_LVALUE_EXPR:
7965 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7969 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7970 access the upper bound values may be bogus. If they refer to a
7971 register, they may only describe how to get at these values at the
7972 points in the generated code right after they have just been
7973 computed. Worse yet, in the typical case, the upper bound values
7974 will not even *be* computed in the optimized code (though the
7975 number of elements will), so these SAVE_EXPRs are entirely
7976 bogus. In order to compensate for this fact, we check here to see
7977 if optimization is enabled, and if so, we don't add an attribute
7978 for the (unknown and unknowable) upper bound. This should not
7979 cause too much trouble for existing (stupid?) debuggers because
7980 they have to deal with empty upper bounds location descriptions
7981 anyway in order to be able to deal with incomplete array types.
7982 Of course an intelligent debugger (GDB?) should be able to
7983 comprehend that a missing upper bound specification in a array
7984 type used for a storage class `auto' local array variable
7985 indicates that the upper bound is both unknown (at compile- time)
7986 and unknowable (at run-time) due to optimization.
7988 We assume that a MEM rtx is safe because gcc wouldn't put the
7989 value there unless it was going to be used repeatedly in the
7990 function, i.e. for cleanups. */
7991 if (! optimize || (SAVE_EXPR_RTL (bound)
7992 && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
7994 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7995 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7996 register rtx loc = SAVE_EXPR_RTL (bound);
7998 /* If the RTL for the SAVE_EXPR is memory, handle the case where
7999 it references an outer function's frame. */
8001 if (GET_CODE (loc) == MEM)
8003 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8005 if (XEXP (loc, 0) != new_addr)
8006 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8009 add_AT_flag (decl_die, DW_AT_artificial, 1);
8010 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8011 add_AT_location_description (decl_die, DW_AT_location, loc);
8012 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8015 /* Else leave out the attribute. */
8021 /* ??? These types of bounds can be created by the Ada front end,
8022 and it isn't clear how to emit debug info for them. */
8030 /* Note that the block of subscript information for an array type also
8031 includes information about the element type of type given array type. */
8034 add_subscript_info (type_die, type)
8035 register dw_die_ref type_die;
8038 #ifndef MIPS_DEBUGGING_INFO
8039 register unsigned dimension_number;
8041 register tree lower, upper;
8042 register dw_die_ref subrange_die;
8044 /* The GNU compilers represent multidimensional array types as sequences of
8045 one dimensional array types whose element types are themselves array
8046 types. Here we squish that down, so that each multidimensional array
8047 type gets only one array_type DIE in the Dwarf debugging info. The draft
8048 Dwarf specification say that we are allowed to do this kind of
8049 compression in C (because there is no difference between an array or
8050 arrays and a multidimensional array in C) but for other source languages
8051 (e.g. Ada) we probably shouldn't do this. */
8053 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8054 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8055 We work around this by disabling this feature. See also
8056 gen_array_type_die. */
8057 #ifndef MIPS_DEBUGGING_INFO
8058 for (dimension_number = 0;
8059 TREE_CODE (type) == ARRAY_TYPE;
8060 type = TREE_TYPE (type), dimension_number++)
8063 register tree domain = TYPE_DOMAIN (type);
8065 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8066 and (in GNU C only) variable bounds. Handle all three forms
8068 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8071 /* We have an array type with specified bounds. */
8072 lower = TYPE_MIN_VALUE (domain);
8073 upper = TYPE_MAX_VALUE (domain);
8075 /* define the index type. */
8076 if (TREE_TYPE (domain))
8078 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8079 TREE_TYPE field. We can't emit debug info for this
8080 because it is an unnamed integral type. */
8081 if (TREE_CODE (domain) == INTEGER_TYPE
8082 && TYPE_NAME (domain) == NULL_TREE
8083 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8084 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8087 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8091 /* ??? If upper is NULL, the array has unspecified length,
8092 but it does have a lower bound. This happens with Fortran
8094 Since the debugger is definitely going to need to know N
8095 to produce useful results, go ahead and output the lower
8096 bound solo, and hope the debugger can cope. */
8098 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8100 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8103 /* We have an array type with an unspecified length. The DWARF-2
8104 spec does not say how to handle this; let's just leave out the
8108 #ifndef MIPS_DEBUGGING_INFO
8114 add_byte_size_attribute (die, tree_node)
8116 register tree tree_node;
8118 register unsigned size;
8120 switch (TREE_CODE (tree_node))
8128 case QUAL_UNION_TYPE:
8129 size = int_size_in_bytes (tree_node);
8132 /* For a data member of a struct or union, the DW_AT_byte_size is
8133 generally given as the number of bytes normally allocated for an
8134 object of the *declared* type of the member itself. This is true
8135 even for bit-fields. */
8136 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8142 /* Note that `size' might be -1 when we get to this point. If it is, that
8143 indicates that the byte size of the entity in question is variable. We
8144 have no good way of expressing this fact in Dwarf at the present time,
8145 so just let the -1 pass on through. */
8147 add_AT_unsigned (die, DW_AT_byte_size, size);
8150 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8151 which specifies the distance in bits from the highest order bit of the
8152 "containing object" for the bit-field to the highest order bit of the
8155 For any given bit-field, the "containing object" is a hypothetical
8156 object (of some integral or enum type) within which the given bit-field
8157 lives. The type of this hypothetical "containing object" is always the
8158 same as the declared type of the individual bit-field itself. The
8159 determination of the exact location of the "containing object" for a
8160 bit-field is rather complicated. It's handled by the
8161 `field_byte_offset' function (above).
8163 Note that it is the size (in bytes) of the hypothetical "containing object"
8164 which will be given in the DW_AT_byte_size attribute for this bit-field.
8165 (See `byte_size_attribute' above). */
8168 add_bit_offset_attribute (die, decl)
8169 register dw_die_ref die;
8172 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8173 tree type = DECL_BIT_FIELD_TYPE (decl);
8174 HOST_WIDE_INT bitpos_int;
8175 HOST_WIDE_INT highest_order_object_bit_offset;
8176 HOST_WIDE_INT highest_order_field_bit_offset;
8177 HOST_WIDE_INT unsigned bit_offset;
8179 /* Must be a field and a bit field. */
8181 || TREE_CODE (decl) != FIELD_DECL)
8184 /* We can't yet handle bit-fields whose offsets are variable, so if we
8185 encounter such things, just return without generating any attribute
8186 whatsoever. Likewise for variable or too large size. */
8187 if (! host_integerp (bit_position (decl), 0)
8188 || ! host_integerp (DECL_SIZE (decl), 1))
8191 bitpos_int = int_bit_position (decl);
8193 /* Note that the bit offset is always the distance (in bits) from the
8194 highest-order bit of the "containing object" to the highest-order bit of
8195 the bit-field itself. Since the "high-order end" of any object or field
8196 is different on big-endian and little-endian machines, the computation
8197 below must take account of these differences. */
8198 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8199 highest_order_field_bit_offset = bitpos_int;
8201 if (! BYTES_BIG_ENDIAN)
8203 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8204 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8208 = (! BYTES_BIG_ENDIAN
8209 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8210 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8212 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8215 /* For a FIELD_DECL node which represents a bit field, output an attribute
8216 which specifies the length in bits of the given field. */
8219 add_bit_size_attribute (die, decl)
8220 register dw_die_ref die;
8223 /* Must be a field and a bit field. */
8224 if (TREE_CODE (decl) != FIELD_DECL
8225 || ! DECL_BIT_FIELD_TYPE (decl))
8228 if (host_integerp (DECL_SIZE (decl), 1))
8229 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8232 /* If the compiled language is ANSI C, then add a 'prototyped'
8233 attribute, if arg types are given for the parameters of a function. */
8236 add_prototyped_attribute (die, func_type)
8237 register dw_die_ref die;
8238 register tree func_type;
8240 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8241 && TYPE_ARG_TYPES (func_type) != NULL)
8242 add_AT_flag (die, DW_AT_prototyped, 1);
8245 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8246 by looking in either the type declaration or object declaration
8250 add_abstract_origin_attribute (die, origin)
8251 register dw_die_ref die;
8252 register tree origin;
8254 dw_die_ref origin_die = NULL;
8256 if (TREE_CODE (origin) != FUNCTION_DECL)
8258 /* We may have gotten separated from the block for the inlined
8259 function, if we're in an exception handler or some such; make
8260 sure that the abstract function has been written out.
8262 Doing this for nested functions is wrong, however; functions are
8263 distinct units, and our context might not even be inline. */
8266 fn = TYPE_STUB_DECL (fn);
8267 fn = decl_function_context (fn);
8269 gen_abstract_function (fn);
8272 if (DECL_P (origin))
8273 origin_die = lookup_decl_die (origin);
8274 else if (TYPE_P (origin))
8275 origin_die = lookup_type_die (origin);
8277 if (origin_die == NULL)
8280 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
8283 /* We do not currently support the pure_virtual attribute. */
8286 add_pure_or_virtual_attribute (die, func_decl)
8287 register dw_die_ref die;
8288 register tree func_decl;
8290 if (DECL_VINDEX (func_decl))
8292 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8294 if (host_integerp (DECL_VINDEX (func_decl), 0))
8295 add_AT_loc (die, DW_AT_vtable_elem_location,
8296 new_loc_descr (DW_OP_constu,
8297 tree_low_cst (DECL_VINDEX (func_decl), 0),
8300 /* GNU extension: Record what type this method came from originally. */
8301 if (debug_info_level > DINFO_LEVEL_TERSE)
8302 add_AT_die_ref (die, DW_AT_containing_type,
8303 lookup_type_die (DECL_CONTEXT (func_decl)));
8307 /* Add source coordinate attributes for the given decl. */
8310 add_src_coords_attributes (die, decl)
8311 register dw_die_ref die;
8314 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
8316 add_AT_unsigned (die, DW_AT_decl_file, file_index);
8317 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8320 /* Add an DW_AT_name attribute and source coordinate attribute for the
8321 given decl, but only if it actually has a name. */
8324 add_name_and_src_coords_attributes (die, decl)
8325 register dw_die_ref die;
8328 register tree decl_name;
8330 decl_name = DECL_NAME (decl);
8331 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
8333 add_name_attribute (die, dwarf2_name (decl, 0));
8334 if (! DECL_ARTIFICIAL (decl))
8335 add_src_coords_attributes (die, decl);
8337 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
8338 && TREE_PUBLIC (decl)
8339 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
8340 add_AT_string (die, DW_AT_MIPS_linkage_name,
8341 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
8345 /* Push a new declaration scope. */
8348 push_decl_scope (scope)
8351 /* Make room in the decl_scope_table, if necessary. */
8352 if (decl_scope_table_allocated == decl_scope_depth)
8354 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
8356 = (tree *) xrealloc (decl_scope_table,
8357 decl_scope_table_allocated * sizeof (tree));
8360 decl_scope_table[decl_scope_depth] = scope;
8364 /* Pop a declaration scope. */
8368 if (decl_scope_depth <= 0)
8373 /* Return the DIE for the scope that immediately contains this type.
8374 Non-named types get global scope. Named types nested in other
8375 types get their containing scope if it's open, or global scope
8376 otherwise. All other types (i.e. function-local named types) get
8377 the current active scope. */
8380 scope_die_for (t, context_die)
8382 register dw_die_ref context_die;
8384 register dw_die_ref scope_die = NULL;
8385 register tree containing_scope;
8388 /* Non-types always go in the current scope. */
8392 containing_scope = TYPE_CONTEXT (t);
8394 /* Ignore namespaces for the moment. */
8395 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
8396 containing_scope = NULL_TREE;
8398 /* Ignore function type "scopes" from the C frontend. They mean that
8399 a tagged type is local to a parmlist of a function declarator, but
8400 that isn't useful to DWARF. */
8401 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
8402 containing_scope = NULL_TREE;
8404 if (containing_scope == NULL_TREE)
8405 scope_die = comp_unit_die;
8406 else if (TYPE_P (containing_scope))
8408 /* For types, we can just look up the appropriate DIE. But
8409 first we check to see if we're in the middle of emitting it
8410 so we know where the new DIE should go. */
8412 for (i = decl_scope_depth - 1; i >= 0; --i)
8413 if (decl_scope_table[i] == containing_scope)
8418 if (debug_info_level > DINFO_LEVEL_TERSE
8419 && !TREE_ASM_WRITTEN (containing_scope))
8422 /* If none of the current dies are suitable, we get file scope. */
8423 scope_die = comp_unit_die;
8426 scope_die = lookup_type_die (containing_scope);
8429 scope_die = context_die;
8434 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
8436 static inline int local_scope_p PARAMS ((dw_die_ref));
8438 local_scope_p (context_die)
8439 dw_die_ref context_die;
8441 for (; context_die; context_die = context_die->die_parent)
8442 if (context_die->die_tag == DW_TAG_inlined_subroutine
8443 || context_die->die_tag == DW_TAG_subprogram)
8448 /* Returns nonzero iff CONTEXT_DIE is a class. */
8450 static inline int class_scope_p PARAMS ((dw_die_ref));
8452 class_scope_p (context_die)
8453 dw_die_ref context_die;
8456 && (context_die->die_tag == DW_TAG_structure_type
8457 || context_die->die_tag == DW_TAG_union_type));
8460 /* Many forms of DIEs require a "type description" attribute. This
8461 routine locates the proper "type descriptor" die for the type given
8462 by 'type', and adds an DW_AT_type attribute below the given die. */
8465 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
8466 register dw_die_ref object_die;
8468 register int decl_const;
8469 register int decl_volatile;
8470 register dw_die_ref context_die;
8472 register enum tree_code code = TREE_CODE (type);
8473 register dw_die_ref type_die = NULL;
8475 /* ??? If this type is an unnamed subrange type of an integral or
8476 floating-point type, use the inner type. This is because we have no
8477 support for unnamed types in base_type_die. This can happen if this is
8478 an Ada subrange type. Correct solution is emit a subrange type die. */
8479 if ((code == INTEGER_TYPE || code == REAL_TYPE)
8480 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
8481 type = TREE_TYPE (type), code = TREE_CODE (type);
8483 if (code == ERROR_MARK)
8486 /* Handle a special case. For functions whose return type is void, we
8487 generate *no* type attribute. (Note that no object may have type
8488 `void', so this only applies to function return types). */
8489 if (code == VOID_TYPE)
8492 type_die = modified_type_die (type,
8493 decl_const || TYPE_READONLY (type),
8494 decl_volatile || TYPE_VOLATILE (type),
8496 if (type_die != NULL)
8497 add_AT_die_ref (object_die, DW_AT_type, type_die);
8500 /* Given a tree pointer to a struct, class, union, or enum type node, return
8501 a pointer to the (string) tag name for the given type, or zero if the type
8502 was declared without a tag. */
8508 register const char *name = 0;
8510 if (TYPE_NAME (type) != 0)
8512 register tree t = 0;
8514 /* Find the IDENTIFIER_NODE for the type name. */
8515 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
8516 t = TYPE_NAME (type);
8518 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
8519 a TYPE_DECL node, regardless of whether or not a `typedef' was
8521 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8522 && ! DECL_IGNORED_P (TYPE_NAME (type)))
8523 t = DECL_NAME (TYPE_NAME (type));
8525 /* Now get the name as a string, or invent one. */
8527 name = IDENTIFIER_POINTER (t);
8530 return (name == 0 || *name == '\0') ? 0 : name;
8533 /* Return the type associated with a data member, make a special check
8534 for bit field types. */
8537 member_declared_type (member)
8538 register tree member;
8540 return (DECL_BIT_FIELD_TYPE (member)
8541 ? DECL_BIT_FIELD_TYPE (member)
8542 : TREE_TYPE (member));
8545 /* Get the decl's label, as described by its RTL. This may be different
8546 from the DECL_NAME name used in the source file. */
8550 decl_start_label (decl)
8555 x = DECL_RTL (decl);
8556 if (GET_CODE (x) != MEM)
8560 if (GET_CODE (x) != SYMBOL_REF)
8563 fnname = XSTR (x, 0);
8568 /* These routines generate the internal representation of the DIE's for
8569 the compilation unit. Debugging information is collected by walking
8570 the declaration trees passed in from dwarf2out_decl(). */
8573 gen_array_type_die (type, context_die)
8575 register dw_die_ref context_die;
8577 register dw_die_ref scope_die = scope_die_for (type, context_die);
8578 register dw_die_ref array_die;
8579 register tree element_type;
8581 /* ??? The SGI dwarf reader fails for array of array of enum types unless
8582 the inner array type comes before the outer array type. Thus we must
8583 call gen_type_die before we call new_die. See below also. */
8584 #ifdef MIPS_DEBUGGING_INFO
8585 gen_type_die (TREE_TYPE (type), context_die);
8588 array_die = new_die (DW_TAG_array_type, scope_die);
8591 /* We default the array ordering. SDB will probably do
8592 the right things even if DW_AT_ordering is not present. It's not even
8593 an issue until we start to get into multidimensional arrays anyway. If
8594 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
8595 then we'll have to put the DW_AT_ordering attribute back in. (But if
8596 and when we find out that we need to put these in, we will only do so
8597 for multidimensional arrays. */
8598 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
8601 #ifdef MIPS_DEBUGGING_INFO
8602 /* The SGI compilers handle arrays of unknown bound by setting
8603 AT_declaration and not emitting any subrange DIEs. */
8604 if (! TYPE_DOMAIN (type))
8605 add_AT_unsigned (array_die, DW_AT_declaration, 1);
8608 add_subscript_info (array_die, type);
8610 add_name_attribute (array_die, type_tag (type));
8611 equate_type_number_to_die (type, array_die);
8613 /* Add representation of the type of the elements of this array type. */
8614 element_type = TREE_TYPE (type);
8616 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8617 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8618 We work around this by disabling this feature. See also
8619 add_subscript_info. */
8620 #ifndef MIPS_DEBUGGING_INFO
8621 while (TREE_CODE (element_type) == ARRAY_TYPE)
8622 element_type = TREE_TYPE (element_type);
8624 gen_type_die (element_type, context_die);
8627 add_type_attribute (array_die, element_type, 0, 0, context_die);
8631 gen_set_type_die (type, context_die)
8633 register dw_die_ref context_die;
8635 register dw_die_ref type_die
8636 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
8638 equate_type_number_to_die (type, type_die);
8639 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
8644 gen_entry_point_die (decl, context_die)
8646 register dw_die_ref context_die;
8648 register tree origin = decl_ultimate_origin (decl);
8649 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
8651 add_abstract_origin_attribute (decl_die, origin);
8654 add_name_and_src_coords_attributes (decl_die, decl);
8655 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
8659 if (DECL_ABSTRACT (decl))
8660 equate_decl_number_to_die (decl, decl_die);
8662 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
8666 /* Remember a type in the incomplete_types_list. */
8669 add_incomplete_type (type)
8672 if (incomplete_types == incomplete_types_allocated)
8674 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
8675 incomplete_types_list
8676 = (tree *) xrealloc (incomplete_types_list,
8677 sizeof (tree) * incomplete_types_allocated);
8680 incomplete_types_list[incomplete_types++] = type;
8683 /* Walk through the list of incomplete types again, trying once more to
8684 emit full debugging info for them. */
8687 retry_incomplete_types ()
8691 while (incomplete_types)
8694 type = incomplete_types_list[incomplete_types];
8695 gen_type_die (type, comp_unit_die);
8699 /* Generate a DIE to represent an inlined instance of an enumeration type. */
8702 gen_inlined_enumeration_type_die (type, context_die)
8704 register dw_die_ref context_die;
8706 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
8708 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8709 be incomplete and such types are not marked. */
8710 add_abstract_origin_attribute (type_die, type);
8713 /* Generate a DIE to represent an inlined instance of a structure type. */
8716 gen_inlined_structure_type_die (type, context_die)
8718 register dw_die_ref context_die;
8720 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
8722 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8723 be incomplete and such types are not marked. */
8724 add_abstract_origin_attribute (type_die, type);
8727 /* Generate a DIE to represent an inlined instance of a union type. */
8730 gen_inlined_union_type_die (type, context_die)
8732 register dw_die_ref context_die;
8734 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
8736 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8737 be incomplete and such types are not marked. */
8738 add_abstract_origin_attribute (type_die, type);
8741 /* Generate a DIE to represent an enumeration type. Note that these DIEs
8742 include all of the information about the enumeration values also. Each
8743 enumerated type name/value is listed as a child of the enumerated type
8747 gen_enumeration_type_die (type, context_die)
8749 register dw_die_ref context_die;
8751 register dw_die_ref type_die = lookup_type_die (type);
8753 if (type_die == NULL)
8755 type_die = new_die (DW_TAG_enumeration_type,
8756 scope_die_for (type, context_die));
8757 equate_type_number_to_die (type, type_die);
8758 add_name_attribute (type_die, type_tag (type));
8760 else if (! TYPE_SIZE (type))
8763 remove_AT (type_die, DW_AT_declaration);
8765 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
8766 given enum type is incomplete, do not generate the DW_AT_byte_size
8767 attribute or the DW_AT_element_list attribute. */
8768 if (TYPE_SIZE (type))
8772 TREE_ASM_WRITTEN (type) = 1;
8773 add_byte_size_attribute (type_die, type);
8774 if (TYPE_STUB_DECL (type) != NULL_TREE)
8775 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8777 /* If the first reference to this type was as the return type of an
8778 inline function, then it may not have a parent. Fix this now. */
8779 if (type_die->die_parent == NULL)
8780 add_child_die (scope_die_for (type, context_die), type_die);
8782 for (link = TYPE_FIELDS (type);
8783 link != NULL; link = TREE_CHAIN (link))
8785 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
8787 add_name_attribute (enum_die,
8788 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
8790 if (host_integerp (TREE_VALUE (link), 0))
8792 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
8793 add_AT_int (enum_die, DW_AT_const_value,
8794 tree_low_cst (TREE_VALUE (link), 0));
8796 add_AT_unsigned (enum_die, DW_AT_const_value,
8797 tree_low_cst (TREE_VALUE (link), 0));
8802 add_AT_flag (type_die, DW_AT_declaration, 1);
8805 /* Generate a DIE to represent either a real live formal parameter decl or to
8806 represent just the type of some formal parameter position in some function
8809 Note that this routine is a bit unusual because its argument may be a
8810 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
8811 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
8812 node. If it's the former then this function is being called to output a
8813 DIE to represent a formal parameter object (or some inlining thereof). If
8814 it's the latter, then this function is only being called to output a
8815 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
8816 argument type of some subprogram type. */
8819 gen_formal_parameter_die (node, context_die)
8821 register dw_die_ref context_die;
8823 register dw_die_ref parm_die
8824 = new_die (DW_TAG_formal_parameter, context_die);
8825 register tree origin;
8827 switch (TREE_CODE_CLASS (TREE_CODE (node)))
8830 origin = decl_ultimate_origin (node);
8832 add_abstract_origin_attribute (parm_die, origin);
8835 add_name_and_src_coords_attributes (parm_die, node);
8836 add_type_attribute (parm_die, TREE_TYPE (node),
8837 TREE_READONLY (node),
8838 TREE_THIS_VOLATILE (node),
8840 if (DECL_ARTIFICIAL (node))
8841 add_AT_flag (parm_die, DW_AT_artificial, 1);
8844 equate_decl_number_to_die (node, parm_die);
8845 if (! DECL_ABSTRACT (node))
8846 add_location_or_const_value_attribute (parm_die, node);
8851 /* We were called with some kind of a ..._TYPE node. */
8852 add_type_attribute (parm_die, node, 0, 0, context_die);
8862 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
8863 at the end of an (ANSI prototyped) formal parameters list. */
8866 gen_unspecified_parameters_die (decl_or_type, context_die)
8867 register tree decl_or_type ATTRIBUTE_UNUSED;
8868 register dw_die_ref context_die;
8870 new_die (DW_TAG_unspecified_parameters, context_die);
8873 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
8874 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
8875 parameters as specified in some function type specification (except for
8876 those which appear as part of a function *definition*). */
8879 gen_formal_types_die (function_or_method_type, context_die)
8880 register tree function_or_method_type;
8881 register dw_die_ref context_die;
8884 register tree formal_type = NULL;
8885 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
8888 /* In the case where we are generating a formal types list for a C++
8889 non-static member function type, skip over the first thing on the
8890 TYPE_ARG_TYPES list because it only represents the type of the hidden
8891 `this pointer'. The debugger should be able to figure out (without
8892 being explicitly told) that this non-static member function type takes a
8893 `this pointer' and should be able to figure what the type of that hidden
8894 parameter is from the DW_AT_member attribute of the parent
8895 DW_TAG_subroutine_type DIE. */
8896 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
8897 first_parm_type = TREE_CHAIN (first_parm_type);
8900 /* Make our first pass over the list of formal parameter types and output a
8901 DW_TAG_formal_parameter DIE for each one. */
8902 for (link = first_parm_type; link; link = TREE_CHAIN (link))
8904 register dw_die_ref parm_die;
8906 formal_type = TREE_VALUE (link);
8907 if (formal_type == void_type_node)
8910 /* Output a (nameless) DIE to represent the formal parameter itself. */
8911 parm_die = gen_formal_parameter_die (formal_type, context_die);
8912 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8913 && link == first_parm_type)
8914 add_AT_flag (parm_die, DW_AT_artificial, 1);
8917 /* If this function type has an ellipsis, add a
8918 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8919 if (formal_type != void_type_node)
8920 gen_unspecified_parameters_die (function_or_method_type, context_die);
8922 /* Make our second (and final) pass over the list of formal parameter types
8923 and output DIEs to represent those types (as necessary). */
8924 for (link = TYPE_ARG_TYPES (function_or_method_type);
8926 link = TREE_CHAIN (link))
8928 formal_type = TREE_VALUE (link);
8929 if (formal_type == void_type_node)
8932 gen_type_die (formal_type, context_die);
8936 /* We want to generate the DIE for TYPE so that we can generate the
8937 die for MEMBER, which has been defined; we will need to refer back
8938 to the member declaration nested within TYPE. If we're trying to
8939 generate minimal debug info for TYPE, processing TYPE won't do the
8940 trick; we need to attach the member declaration by hand. */
8943 gen_type_die_for_member (type, member, context_die)
8945 dw_die_ref context_die;
8947 gen_type_die (type, context_die);
8949 /* If we're trying to avoid duplicate debug info, we may not have
8950 emitted the member decl for this function. Emit it now. */
8951 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
8952 && ! lookup_decl_die (member))
8954 if (decl_ultimate_origin (member))
8957 push_decl_scope (type);
8958 if (TREE_CODE (member) == FUNCTION_DECL)
8959 gen_subprogram_die (member, lookup_type_die (type));
8961 gen_variable_die (member, lookup_type_die (type));
8966 /* Generate the DWARF2 info for the "abstract" instance
8967 of a function which we may later generate inlined and/or
8968 out-of-line instances of. */
8971 gen_abstract_function (decl)
8974 register dw_die_ref old_die = lookup_decl_die (decl);
8977 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
8978 /* We've already generated the abstract instance. */
8981 save_fn = current_function_decl;
8982 current_function_decl = decl;
8984 set_decl_abstract_flags (decl, 1);
8985 dwarf2out_decl (decl);
8986 set_decl_abstract_flags (decl, 0);
8988 current_function_decl = save_fn;
8991 /* Generate a DIE to represent a declared function (either file-scope or
8995 gen_subprogram_die (decl, context_die)
8997 register dw_die_ref context_die;
8999 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9000 register tree origin = decl_ultimate_origin (decl);
9001 register dw_die_ref subr_die;
9002 register rtx fp_reg;
9003 register tree fn_arg_types;
9004 register tree outer_scope;
9005 register dw_die_ref old_die = lookup_decl_die (decl);
9006 register int declaration = (current_function_decl != decl
9007 || class_scope_p (context_die));
9009 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9010 be true, if we started to generate the abstract instance of an inline,
9011 decided to output its containing class, and proceeded to emit the
9012 declaration of the inline from the member list for the class. In that
9013 case, `declaration' takes priority; we'll get back to the abstract
9014 instance when we're done with the class. */
9016 /* The class-scope declaration DIE must be the primary DIE. */
9017 if (origin && declaration && class_scope_p (context_die))
9026 if (declaration && ! local_scope_p (context_die))
9029 /* Fixup die_parent for the abstract instance of a nested
9031 if (old_die && old_die->die_parent == NULL)
9032 add_child_die (context_die, old_die);
9034 subr_die = new_die (DW_TAG_subprogram, context_die);
9035 add_abstract_origin_attribute (subr_die, origin);
9037 else if (old_die && DECL_ABSTRACT (decl)
9038 && get_AT_unsigned (old_die, DW_AT_inline))
9040 /* This must be a redefinition of an extern inline function.
9041 We can just reuse the old die here. */
9044 /* Clear out the inlined attribute and parm types. */
9045 remove_AT (subr_die, DW_AT_inline);
9046 remove_children (subr_die);
9050 register unsigned file_index
9051 = lookup_filename (DECL_SOURCE_FILE (decl));
9053 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
9055 /* ??? This can happen if there is a bug in the program, for
9056 instance, if it has duplicate function definitions. Ideally,
9057 we should detect this case and ignore it. For now, if we have
9058 already reported an error, any error at all, then assume that
9059 we got here because of a input error, not a dwarf2 bug. */
9065 /* If the definition comes from the same place as the declaration,
9066 maybe use the old DIE. We always want the DIE for this function
9067 that has the *_pc attributes to be under comp_unit_die so the
9068 debugger can find it. For inlines, that is the concrete instance,
9069 so we can use the old DIE here. For non-inline methods, we want a
9070 specification DIE at toplevel, so we need a new DIE. For local
9071 class methods, this doesn't apply; we just use the old DIE. */
9072 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
9073 || context_die == NULL)
9074 && (DECL_ARTIFICIAL (decl)
9075 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9076 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9077 == (unsigned) DECL_SOURCE_LINE (decl)))))
9081 /* Clear out the declaration attribute and the parm types. */
9082 remove_AT (subr_die, DW_AT_declaration);
9083 remove_children (subr_die);
9087 subr_die = new_die (DW_TAG_subprogram, context_die);
9088 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9089 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9090 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9091 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9092 != (unsigned) DECL_SOURCE_LINE (decl))
9094 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9099 subr_die = new_die (DW_TAG_subprogram, context_die);
9101 if (TREE_PUBLIC (decl))
9102 add_AT_flag (subr_die, DW_AT_external, 1);
9104 add_name_and_src_coords_attributes (subr_die, decl);
9105 if (debug_info_level > DINFO_LEVEL_TERSE)
9107 register tree type = TREE_TYPE (decl);
9109 add_prototyped_attribute (subr_die, type);
9110 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9113 add_pure_or_virtual_attribute (subr_die, decl);
9114 if (DECL_ARTIFICIAL (decl))
9115 add_AT_flag (subr_die, DW_AT_artificial, 1);
9116 if (TREE_PROTECTED (decl))
9117 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9118 else if (TREE_PRIVATE (decl))
9119 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9125 add_AT_flag (subr_die, DW_AT_declaration, 1);
9127 /* The first time we see a member function, it is in the context of
9128 the class to which it belongs. We make sure of this by emitting
9129 the class first. The next time is the definition, which is
9130 handled above. The two may come from the same source text. */
9131 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9132 equate_decl_number_to_die (decl, subr_die);
9134 else if (DECL_ABSTRACT (decl))
9136 if (DECL_INLINE (decl) && !flag_no_inline)
9138 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9139 inline functions, but not for extern inline functions.
9140 We can't get this completely correct because information
9141 about whether the function was declared inline is not
9143 if (DECL_DEFER_OUTPUT (decl))
9144 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9146 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9149 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9151 equate_decl_number_to_die (decl, subr_die);
9153 else if (!DECL_EXTERNAL (decl))
9155 if (origin == NULL_TREE)
9156 equate_decl_number_to_die (decl, subr_die);
9158 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9159 current_funcdef_number);
9160 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9161 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9162 current_funcdef_number);
9163 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9165 add_pubname (decl, subr_die);
9166 add_arange (decl, subr_die);
9168 #ifdef MIPS_DEBUGGING_INFO
9169 /* Add a reference to the FDE for this routine. */
9170 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9173 /* Define the "frame base" location for this routine. We use the
9174 frame pointer or stack pointer registers, since the RTL for local
9175 variables is relative to one of them. */
9177 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9178 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9181 /* ??? This fails for nested inline functions, because context_display
9182 is not part of the state saved/restored for inline functions. */
9183 if (current_function_needs_context)
9184 add_AT_location_description (subr_die, DW_AT_static_link,
9185 lookup_static_chain (decl));
9189 /* Now output descriptions of the arguments for this function. This gets
9190 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9191 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9192 `...' at the end of the formal parameter list. In order to find out if
9193 there was a trailing ellipsis or not, we must instead look at the type
9194 associated with the FUNCTION_DECL. This will be a node of type
9195 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9196 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9197 an ellipsis at the end. */
9199 /* In the case where we are describing a mere function declaration, all we
9200 need to do here (and all we *can* do here) is to describe the *types* of
9201 its formal parameters. */
9202 if (debug_info_level <= DINFO_LEVEL_TERSE)
9204 else if (declaration)
9205 gen_formal_types_die (TREE_TYPE (decl), subr_die);
9208 /* Generate DIEs to represent all known formal parameters */
9209 register tree arg_decls = DECL_ARGUMENTS (decl);
9212 /* When generating DIEs, generate the unspecified_parameters DIE
9213 instead if we come across the arg "__builtin_va_alist" */
9214 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9215 if (TREE_CODE (parm) == PARM_DECL)
9217 if (DECL_NAME (parm)
9218 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9219 "__builtin_va_alist"))
9220 gen_unspecified_parameters_die (parm, subr_die);
9222 gen_decl_die (parm, subr_die);
9225 /* Decide whether we need a unspecified_parameters DIE at the end.
9226 There are 2 more cases to do this for: 1) the ansi ... declaration -
9227 this is detectable when the end of the arg list is not a
9228 void_type_node 2) an unprototyped function declaration (not a
9229 definition). This just means that we have no info about the
9230 parameters at all. */
9231 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9232 if (fn_arg_types != NULL)
9234 /* this is the prototyped case, check for ... */
9235 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9236 gen_unspecified_parameters_die (decl, subr_die);
9238 else if (DECL_INITIAL (decl) == NULL_TREE)
9239 gen_unspecified_parameters_die (decl, subr_die);
9242 /* Output Dwarf info for all of the stuff within the body of the function
9243 (if it has one - it may be just a declaration). */
9244 outer_scope = DECL_INITIAL (decl);
9246 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9247 node created to represent a function. This outermost BLOCK actually
9248 represents the outermost binding contour for the function, i.e. the
9249 contour in which the function's formal parameters and labels get
9250 declared. Curiously, it appears that the front end doesn't actually
9251 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9252 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9253 list for the function instead.) The BLOCK_VARS list for the
9254 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9255 the function however, and we output DWARF info for those in
9256 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9257 node representing the function's outermost pair of curly braces, and
9258 any blocks used for the base and member initializers of a C++
9259 constructor function. */
9260 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
9262 current_function_has_inlines = 0;
9263 decls_for_scope (outer_scope, subr_die, 0);
9265 #if 0 && defined (MIPS_DEBUGGING_INFO)
9266 if (current_function_has_inlines)
9268 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
9269 if (! comp_unit_has_inlines)
9271 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
9272 comp_unit_has_inlines = 1;
9279 /* Generate a DIE to represent a declared data object. */
9282 gen_variable_die (decl, context_die)
9284 register dw_die_ref context_die;
9286 register tree origin = decl_ultimate_origin (decl);
9287 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
9289 dw_die_ref old_die = lookup_decl_die (decl);
9290 int declaration = (DECL_EXTERNAL (decl)
9291 || class_scope_p (context_die));
9294 add_abstract_origin_attribute (var_die, origin);
9295 /* Loop unrolling can create multiple blocks that refer to the same
9296 static variable, so we must test for the DW_AT_declaration flag. */
9297 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
9298 copy decls and set the DECL_ABSTRACT flag on them instead of
9300 else if (old_die && TREE_STATIC (decl)
9301 && get_AT_flag (old_die, DW_AT_declaration) == 1)
9303 /* This is a definition of a C++ class level static. */
9304 add_AT_die_ref (var_die, DW_AT_specification, old_die);
9305 if (DECL_NAME (decl))
9307 register unsigned file_index
9308 = lookup_filename (DECL_SOURCE_FILE (decl));
9310 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9311 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
9313 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9314 != (unsigned) DECL_SOURCE_LINE (decl))
9316 add_AT_unsigned (var_die, DW_AT_decl_line,
9317 DECL_SOURCE_LINE (decl));
9322 add_name_and_src_coords_attributes (var_die, decl);
9323 add_type_attribute (var_die, TREE_TYPE (decl),
9324 TREE_READONLY (decl),
9325 TREE_THIS_VOLATILE (decl), context_die);
9327 if (TREE_PUBLIC (decl))
9328 add_AT_flag (var_die, DW_AT_external, 1);
9330 if (DECL_ARTIFICIAL (decl))
9331 add_AT_flag (var_die, DW_AT_artificial, 1);
9333 if (TREE_PROTECTED (decl))
9334 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
9336 else if (TREE_PRIVATE (decl))
9337 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
9341 add_AT_flag (var_die, DW_AT_declaration, 1);
9343 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
9344 equate_decl_number_to_die (decl, var_die);
9346 if (! declaration && ! DECL_ABSTRACT (decl))
9348 add_location_or_const_value_attribute (var_die, decl);
9349 add_pubname (decl, var_die);
9353 /* Generate a DIE to represent a label identifier. */
9356 gen_label_die (decl, context_die)
9358 register dw_die_ref context_die;
9360 register tree origin = decl_ultimate_origin (decl);
9361 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
9363 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9364 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
9367 add_abstract_origin_attribute (lbl_die, origin);
9369 add_name_and_src_coords_attributes (lbl_die, decl);
9371 if (DECL_ABSTRACT (decl))
9372 equate_decl_number_to_die (decl, lbl_die);
9375 insn = DECL_RTL (decl);
9377 /* Deleted labels are programmer specified labels which have been
9378 eliminated because of various optimisations. We still emit them
9379 here so that it is possible to put breakpoints on them. */
9380 if (GET_CODE (insn) == CODE_LABEL
9381 || ((GET_CODE (insn) == NOTE
9382 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
9384 /* When optimization is enabled (via -O) some parts of the compiler
9385 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
9386 represent source-level labels which were explicitly declared by
9387 the user. This really shouldn't be happening though, so catch
9388 it if it ever does happen. */
9389 if (INSN_DELETED_P (insn))
9392 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
9393 ASM_GENERATE_INTERNAL_LABEL (label, label2,
9394 (unsigned) INSN_UID (insn));
9395 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
9400 /* Generate a DIE for a lexical block. */
9403 gen_lexical_block_die (stmt, context_die, depth)
9405 register dw_die_ref context_die;
9408 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
9409 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9411 if (! BLOCK_ABSTRACT (stmt))
9413 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9414 BLOCK_NUMBER (stmt));
9415 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
9416 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9417 BLOCK_NUMBER (stmt));
9418 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
9421 decls_for_scope (stmt, stmt_die, depth);
9424 /* Generate a DIE for an inlined subprogram. */
9427 gen_inlined_subroutine_die (stmt, context_die, depth)
9429 register dw_die_ref context_die;
9432 if (! BLOCK_ABSTRACT (stmt))
9434 register dw_die_ref subr_die
9435 = new_die (DW_TAG_inlined_subroutine, context_die);
9436 register tree decl = block_ultimate_origin (stmt);
9437 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9439 /* Emit info for the abstract instance first, if we haven't yet. */
9440 gen_abstract_function (decl);
9442 add_abstract_origin_attribute (subr_die, decl);
9443 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9444 BLOCK_NUMBER (stmt));
9445 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
9446 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9447 BLOCK_NUMBER (stmt));
9448 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
9449 decls_for_scope (stmt, subr_die, depth);
9450 current_function_has_inlines = 1;
9454 /* Generate a DIE for a field in a record, or structure. */
9457 gen_field_die (decl, context_die)
9459 register dw_die_ref context_die;
9461 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
9463 add_name_and_src_coords_attributes (decl_die, decl);
9464 add_type_attribute (decl_die, member_declared_type (decl),
9465 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
9468 /* If this is a bit field... */
9469 if (DECL_BIT_FIELD_TYPE (decl))
9471 add_byte_size_attribute (decl_die, decl);
9472 add_bit_size_attribute (decl_die, decl);
9473 add_bit_offset_attribute (decl_die, decl);
9476 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
9477 add_data_member_location_attribute (decl_die, decl);
9479 if (DECL_ARTIFICIAL (decl))
9480 add_AT_flag (decl_die, DW_AT_artificial, 1);
9482 if (TREE_PROTECTED (decl))
9483 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
9485 else if (TREE_PRIVATE (decl))
9486 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
9490 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9491 Use modified_type_die instead.
9492 We keep this code here just in case these types of DIEs may be needed to
9493 represent certain things in other languages (e.g. Pascal) someday. */
9495 gen_pointer_type_die (type, context_die)
9497 register dw_die_ref context_die;
9499 register dw_die_ref ptr_die
9500 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
9502 equate_type_number_to_die (type, ptr_die);
9503 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9504 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9507 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9508 Use modified_type_die instead.
9509 We keep this code here just in case these types of DIEs may be needed to
9510 represent certain things in other languages (e.g. Pascal) someday. */
9512 gen_reference_type_die (type, context_die)
9514 register dw_die_ref context_die;
9516 register dw_die_ref ref_die
9517 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
9519 equate_type_number_to_die (type, ref_die);
9520 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
9521 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9525 /* Generate a DIE for a pointer to a member type. */
9527 gen_ptr_to_mbr_type_die (type, context_die)
9529 register dw_die_ref context_die;
9531 register dw_die_ref ptr_die
9532 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
9534 equate_type_number_to_die (type, ptr_die);
9535 add_AT_die_ref (ptr_die, DW_AT_containing_type,
9536 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
9537 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9540 /* Generate the DIE for the compilation unit. */
9543 gen_compile_unit_die (filename)
9544 register const char *filename;
9546 register dw_die_ref die;
9548 const char *wd = getpwd ();
9551 die = new_die (DW_TAG_compile_unit, NULL);
9552 add_name_attribute (die, filename);
9554 if (wd != NULL && filename[0] != DIR_SEPARATOR)
9555 add_AT_string (die, DW_AT_comp_dir, wd);
9557 sprintf (producer, "%s %s", language_string, version_string);
9559 #ifdef MIPS_DEBUGGING_INFO
9560 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
9561 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
9562 not appear in the producer string, the debugger reaches the conclusion
9563 that the object file is stripped and has no debugging information.
9564 To get the MIPS/SGI debugger to believe that there is debugging
9565 information in the object file, we add a -g to the producer string. */
9566 if (debug_info_level > DINFO_LEVEL_TERSE)
9567 strcat (producer, " -g");
9570 add_AT_string (die, DW_AT_producer, producer);
9572 if (strcmp (language_string, "GNU C++") == 0)
9573 language = DW_LANG_C_plus_plus;
9574 else if (strcmp (language_string, "GNU Ada") == 0)
9575 language = DW_LANG_Ada83;
9576 else if (strcmp (language_string, "GNU F77") == 0)
9577 language = DW_LANG_Fortran77;
9578 else if (strcmp (language_string, "GNU Pascal") == 0)
9579 language = DW_LANG_Pascal83;
9580 else if (strcmp (language_string, "GNU Java") == 0)
9581 language = DW_LANG_Java;
9582 else if (flag_traditional)
9583 language = DW_LANG_C;
9585 language = DW_LANG_C89;
9587 add_AT_unsigned (die, DW_AT_language, language);
9592 /* Generate a DIE for a string type. */
9595 gen_string_type_die (type, context_die)
9597 register dw_die_ref context_die;
9599 register dw_die_ref type_die
9600 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
9602 equate_type_number_to_die (type, type_die);
9604 /* Fudge the string length attribute for now. */
9606 /* TODO: add string length info.
9607 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
9608 bound_representation (upper_bound, 0, 'u'); */
9611 /* Generate the DIE for a base class. */
9614 gen_inheritance_die (binfo, context_die)
9615 register tree binfo;
9616 register dw_die_ref context_die;
9618 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
9620 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
9621 add_data_member_location_attribute (die, binfo);
9623 if (TREE_VIA_VIRTUAL (binfo))
9624 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9625 if (TREE_VIA_PUBLIC (binfo))
9626 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
9627 else if (TREE_VIA_PROTECTED (binfo))
9628 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
9631 /* Generate a DIE for a class member. */
9634 gen_member_die (type, context_die)
9636 register dw_die_ref context_die;
9638 register tree member;
9641 /* If this is not an incomplete type, output descriptions of each of its
9642 members. Note that as we output the DIEs necessary to represent the
9643 members of this record or union type, we will also be trying to output
9644 DIEs to represent the *types* of those members. However the `type'
9645 function (above) will specifically avoid generating type DIEs for member
9646 types *within* the list of member DIEs for this (containing) type execpt
9647 for those types (of members) which are explicitly marked as also being
9648 members of this (containing) type themselves. The g++ front- end can
9649 force any given type to be treated as a member of some other
9650 (containing) type by setting the TYPE_CONTEXT of the given (member) type
9651 to point to the TREE node representing the appropriate (containing)
9654 /* First output info about the base classes. */
9655 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
9657 register tree bases = TYPE_BINFO_BASETYPES (type);
9658 register int n_bases = TREE_VEC_LENGTH (bases);
9661 for (i = 0; i < n_bases; i++)
9662 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
9665 /* Now output info about the data members and type members. */
9666 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
9668 /* If we thought we were generating minimal debug info for TYPE
9669 and then changed our minds, some of the member declarations
9670 may have already been defined. Don't define them again, but
9671 do put them in the right order. */
9673 child = lookup_decl_die (member);
9675 splice_child_die (context_die, child);
9677 gen_decl_die (member, context_die);
9680 /* Now output info about the function members (if any). */
9681 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
9683 child = lookup_decl_die (member);
9685 splice_child_die (context_die, child);
9687 gen_decl_die (member, context_die);
9691 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
9692 is set, we pretend that the type was never defined, so we only get the
9693 member DIEs needed by later specification DIEs. */
9696 gen_struct_or_union_type_die (type, context_die)
9698 register dw_die_ref context_die;
9700 register dw_die_ref type_die = lookup_type_die (type);
9701 register dw_die_ref scope_die = 0;
9702 register int nested = 0;
9703 int complete = (TYPE_SIZE (type)
9704 && (! TYPE_STUB_DECL (type)
9705 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
9707 if (type_die && ! complete)
9710 if (TYPE_CONTEXT (type) != NULL_TREE
9711 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
9714 scope_die = scope_die_for (type, context_die);
9716 if (! type_die || (nested && scope_die == comp_unit_die))
9717 /* First occurrence of type or toplevel definition of nested class. */
9719 register dw_die_ref old_die = type_die;
9721 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
9722 ? DW_TAG_structure_type : DW_TAG_union_type,
9724 equate_type_number_to_die (type, type_die);
9726 add_AT_die_ref (type_die, DW_AT_specification, old_die);
9728 add_name_attribute (type_die, type_tag (type));
9731 remove_AT (type_die, DW_AT_declaration);
9733 /* If this type has been completed, then give it a byte_size attribute and
9734 then give a list of members. */
9737 /* Prevent infinite recursion in cases where the type of some member of
9738 this type is expressed in terms of this type itself. */
9739 TREE_ASM_WRITTEN (type) = 1;
9740 add_byte_size_attribute (type_die, type);
9741 if (TYPE_STUB_DECL (type) != NULL_TREE)
9742 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9744 /* If the first reference to this type was as the return type of an
9745 inline function, then it may not have a parent. Fix this now. */
9746 if (type_die->die_parent == NULL)
9747 add_child_die (scope_die, type_die);
9749 push_decl_scope (type);
9750 gen_member_die (type, type_die);
9753 /* GNU extension: Record what type our vtable lives in. */
9754 if (TYPE_VFIELD (type))
9756 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
9758 gen_type_die (vtype, context_die);
9759 add_AT_die_ref (type_die, DW_AT_containing_type,
9760 lookup_type_die (vtype));
9765 add_AT_flag (type_die, DW_AT_declaration, 1);
9767 /* We don't need to do this for function-local types. */
9768 if (! decl_function_context (TYPE_STUB_DECL (type)))
9769 add_incomplete_type (type);
9773 /* Generate a DIE for a subroutine _type_. */
9776 gen_subroutine_type_die (type, context_die)
9778 register dw_die_ref context_die;
9780 register tree return_type = TREE_TYPE (type);
9781 register dw_die_ref subr_die
9782 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
9784 equate_type_number_to_die (type, subr_die);
9785 add_prototyped_attribute (subr_die, type);
9786 add_type_attribute (subr_die, return_type, 0, 0, context_die);
9787 gen_formal_types_die (type, subr_die);
9790 /* Generate a DIE for a type definition */
9793 gen_typedef_die (decl, context_die)
9795 register dw_die_ref context_die;
9797 register dw_die_ref type_die;
9798 register tree origin;
9800 if (TREE_ASM_WRITTEN (decl))
9802 TREE_ASM_WRITTEN (decl) = 1;
9804 type_die = new_die (DW_TAG_typedef, context_die);
9805 origin = decl_ultimate_origin (decl);
9807 add_abstract_origin_attribute (type_die, origin);
9811 add_name_and_src_coords_attributes (type_die, decl);
9812 if (DECL_ORIGINAL_TYPE (decl))
9814 type = DECL_ORIGINAL_TYPE (decl);
9816 if (type == TREE_TYPE (decl))
9819 equate_type_number_to_die (TREE_TYPE (decl), type_die);
9822 type = TREE_TYPE (decl);
9823 add_type_attribute (type_die, type, TREE_READONLY (decl),
9824 TREE_THIS_VOLATILE (decl), context_die);
9827 if (DECL_ABSTRACT (decl))
9828 equate_decl_number_to_die (decl, type_die);
9831 /* Generate a type description DIE. */
9834 gen_type_die (type, context_die)
9836 register dw_die_ref context_die;
9840 if (type == NULL_TREE || type == error_mark_node)
9843 /* We are going to output a DIE to represent the unqualified version of
9844 this type (i.e. without any const or volatile qualifiers) so get the
9845 main variant (i.e. the unqualified version) of this type now. */
9846 type = type_main_variant (type);
9848 if (TREE_ASM_WRITTEN (type))
9851 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9852 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
9854 TREE_ASM_WRITTEN (type) = 1;
9855 gen_decl_die (TYPE_NAME (type), context_die);
9859 switch (TREE_CODE (type))
9865 case REFERENCE_TYPE:
9866 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
9867 ensures that the gen_type_die recursion will terminate even if the
9868 type is recursive. Recursive types are possible in Ada. */
9869 /* ??? We could perhaps do this for all types before the switch
9871 TREE_ASM_WRITTEN (type) = 1;
9873 /* For these types, all that is required is that we output a DIE (or a
9874 set of DIEs) to represent the "basis" type. */
9875 gen_type_die (TREE_TYPE (type), context_die);
9879 /* This code is used for C++ pointer-to-data-member types.
9880 Output a description of the relevant class type. */
9881 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
9883 /* Output a description of the type of the object pointed to. */
9884 gen_type_die (TREE_TYPE (type), context_die);
9886 /* Now output a DIE to represent this pointer-to-data-member type
9888 gen_ptr_to_mbr_type_die (type, context_die);
9892 gen_type_die (TYPE_DOMAIN (type), context_die);
9893 gen_set_type_die (type, context_die);
9897 gen_type_die (TREE_TYPE (type), context_die);
9898 abort (); /* No way to represent these in Dwarf yet! */
9902 /* Force out return type (in case it wasn't forced out already). */
9903 gen_type_die (TREE_TYPE (type), context_die);
9904 gen_subroutine_type_die (type, context_die);
9908 /* Force out return type (in case it wasn't forced out already). */
9909 gen_type_die (TREE_TYPE (type), context_die);
9910 gen_subroutine_type_die (type, context_die);
9914 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
9916 gen_type_die (TREE_TYPE (type), context_die);
9917 gen_string_type_die (type, context_die);
9920 gen_array_type_die (type, context_die);
9924 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
9930 case QUAL_UNION_TYPE:
9931 /* If this is a nested type whose containing class hasn't been
9932 written out yet, writing it out will cover this one, too.
9933 This does not apply to instantiations of member class templates;
9934 they need to be added to the containing class as they are
9935 generated. FIXME: This hurts the idea of combining type decls
9936 from multiple TUs, since we can't predict what set of template
9937 instantiations we'll get. */
9938 if (TYPE_CONTEXT (type)
9939 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9940 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9942 gen_type_die (TYPE_CONTEXT (type), context_die);
9944 if (TREE_ASM_WRITTEN (type))
9947 /* If that failed, attach ourselves to the stub. */
9948 push_decl_scope (TYPE_CONTEXT (type));
9949 context_die = lookup_type_die (TYPE_CONTEXT (type));
9955 if (TREE_CODE (type) == ENUMERAL_TYPE)
9956 gen_enumeration_type_die (type, context_die);
9958 gen_struct_or_union_type_die (type, context_die);
9963 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9964 it up if it is ever completed. gen_*_type_die will set it for us
9965 when appropriate. */
9974 /* No DIEs needed for fundamental types. */
9978 /* No Dwarf representation currently defined. */
9985 TREE_ASM_WRITTEN (type) = 1;
9988 /* Generate a DIE for a tagged type instantiation. */
9991 gen_tagged_type_instantiation_die (type, context_die)
9993 register dw_die_ref context_die;
9995 if (type == NULL_TREE || type == error_mark_node)
9998 /* We are going to output a DIE to represent the unqualified version of
9999 this type (i.e. without any const or volatile qualifiers) so make sure
10000 that we have the main variant (i.e. the unqualified version) of this
10002 if (type != type_main_variant (type))
10005 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10006 an instance of an unresolved type. */
10008 switch (TREE_CODE (type))
10013 case ENUMERAL_TYPE:
10014 gen_inlined_enumeration_type_die (type, context_die);
10018 gen_inlined_structure_type_die (type, context_die);
10022 case QUAL_UNION_TYPE:
10023 gen_inlined_union_type_die (type, context_die);
10031 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10032 things which are local to the given block. */
10035 gen_block_die (stmt, context_die, depth)
10036 register tree stmt;
10037 register dw_die_ref context_die;
10040 register int must_output_die = 0;
10041 register tree origin;
10042 register tree decl;
10043 register enum tree_code origin_code;
10045 /* Ignore blocks never really used to make RTL. */
10047 if (stmt == NULL_TREE || !TREE_USED (stmt)
10048 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10051 /* Determine the "ultimate origin" of this block. This block may be an
10052 inlined instance of an inlined instance of inline function, so we have
10053 to trace all of the way back through the origin chain to find out what
10054 sort of node actually served as the original seed for the creation of
10055 the current block. */
10056 origin = block_ultimate_origin (stmt);
10057 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10059 /* Determine if we need to output any Dwarf DIEs at all to represent this
10061 if (origin_code == FUNCTION_DECL)
10062 /* The outer scopes for inlinings *must* always be represented. We
10063 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10064 must_output_die = 1;
10067 /* In the case where the current block represents an inlining of the
10068 "body block" of an inline function, we must *NOT* output any DIE for
10069 this block because we have already output a DIE to represent the
10070 whole inlined function scope and the "body block" of any function
10071 doesn't really represent a different scope according to ANSI C
10072 rules. So we check here to make sure that this block does not
10073 represent a "body block inlining" before trying to set the
10074 `must_output_die' flag. */
10075 if (! is_body_block (origin ? origin : stmt))
10077 /* Determine if this block directly contains any "significant"
10078 local declarations which we will need to output DIEs for. */
10079 if (debug_info_level > DINFO_LEVEL_TERSE)
10080 /* We are not in terse mode so *any* local declaration counts
10081 as being a "significant" one. */
10082 must_output_die = (BLOCK_VARS (stmt) != NULL);
10084 /* We are in terse mode, so only local (nested) function
10085 definitions count as "significant" local declarations. */
10086 for (decl = BLOCK_VARS (stmt);
10087 decl != NULL; decl = TREE_CHAIN (decl))
10088 if (TREE_CODE (decl) == FUNCTION_DECL
10089 && DECL_INITIAL (decl))
10091 must_output_die = 1;
10097 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10098 DIE for any block which contains no significant local declarations at
10099 all. Rather, in such cases we just call `decls_for_scope' so that any
10100 needed Dwarf info for any sub-blocks will get properly generated. Note
10101 that in terse mode, our definition of what constitutes a "significant"
10102 local declaration gets restricted to include only inlined function
10103 instances and local (nested) function definitions. */
10104 if (must_output_die)
10106 if (origin_code == FUNCTION_DECL)
10107 gen_inlined_subroutine_die (stmt, context_die, depth);
10109 gen_lexical_block_die (stmt, context_die, depth);
10112 decls_for_scope (stmt, context_die, depth);
10115 /* Generate all of the decls declared within a given scope and (recursively)
10116 all of its sub-blocks. */
10119 decls_for_scope (stmt, context_die, depth)
10120 register tree stmt;
10121 register dw_die_ref context_die;
10124 register tree decl;
10125 register tree subblocks;
10127 /* Ignore blocks never really used to make RTL. */
10128 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10131 /* Output the DIEs to represent all of the data objects and typedefs
10132 declared directly within this block but not within any nested
10133 sub-blocks. Also, nested function and tag DIEs have been
10134 generated with a parent of NULL; fix that up now. */
10135 for (decl = BLOCK_VARS (stmt);
10136 decl != NULL; decl = TREE_CHAIN (decl))
10138 register dw_die_ref die;
10140 if (TREE_CODE (decl) == FUNCTION_DECL)
10141 die = lookup_decl_die (decl);
10142 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10143 die = lookup_type_die (TREE_TYPE (decl));
10147 if (die != NULL && die->die_parent == NULL)
10148 add_child_die (context_die, die);
10150 gen_decl_die (decl, context_die);
10153 /* Output the DIEs to represent all sub-blocks (and the items declared
10154 therein) of this block. */
10155 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10157 subblocks = BLOCK_CHAIN (subblocks))
10158 gen_block_die (subblocks, context_die, depth + 1);
10161 /* Is this a typedef we can avoid emitting? */
10164 is_redundant_typedef (decl)
10165 register tree decl;
10167 if (TYPE_DECL_IS_STUB (decl))
10170 if (DECL_ARTIFICIAL (decl)
10171 && DECL_CONTEXT (decl)
10172 && is_tagged_type (DECL_CONTEXT (decl))
10173 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10174 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10175 /* Also ignore the artificial member typedef for the class name. */
10181 /* Generate Dwarf debug information for a decl described by DECL. */
10184 gen_decl_die (decl, context_die)
10185 register tree decl;
10186 register dw_die_ref context_die;
10188 register tree origin;
10190 if (TREE_CODE (decl) == ERROR_MARK)
10193 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10194 if (DECL_IGNORED_P (decl))
10197 switch (TREE_CODE (decl))
10200 /* The individual enumerators of an enum type get output when we output
10201 the Dwarf representation of the relevant enum type itself. */
10204 case FUNCTION_DECL:
10205 /* Don't output any DIEs to represent mere function declarations,
10206 unless they are class members or explicit block externs. */
10207 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10208 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10211 /* If we're emitting an out-of-line copy of an inline function,
10212 emit info for the abstract instance and set up to refer to it. */
10213 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10214 && ! class_scope_p (context_die)
10215 /* gen_abstract_function won't emit a die if this is just a
10216 declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10217 that case, because that works only if we have a die. */
10218 && DECL_INITIAL (decl) != NULL_TREE)
10220 gen_abstract_function (decl);
10221 set_decl_origin_self (decl);
10224 if (debug_info_level > DINFO_LEVEL_TERSE)
10226 /* Before we describe the FUNCTION_DECL itself, make sure that we
10227 have described its return type. */
10228 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10230 /* And its virtual context. */
10231 if (DECL_VINDEX (decl) != NULL_TREE)
10232 gen_type_die (DECL_CONTEXT (decl), context_die);
10234 /* And its containing type. */
10235 origin = decl_class_context (decl);
10236 if (origin != NULL_TREE)
10237 gen_type_die_for_member (origin, decl, context_die);
10240 /* Now output a DIE to represent the function itself. */
10241 gen_subprogram_die (decl, context_die);
10245 /* If we are in terse mode, don't generate any DIEs to represent any
10246 actual typedefs. */
10247 if (debug_info_level <= DINFO_LEVEL_TERSE)
10250 /* In the special case of a TYPE_DECL node representing the
10251 declaration of some type tag, if the given TYPE_DECL is marked as
10252 having been instantiated from some other (original) TYPE_DECL node
10253 (e.g. one which was generated within the original definition of an
10254 inline function) we have to generate a special (abbreviated)
10255 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10257 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10259 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10263 if (is_redundant_typedef (decl))
10264 gen_type_die (TREE_TYPE (decl), context_die);
10266 /* Output a DIE to represent the typedef itself. */
10267 gen_typedef_die (decl, context_die);
10271 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10272 gen_label_die (decl, context_die);
10276 /* If we are in terse mode, don't generate any DIEs to represent any
10277 variable declarations or definitions. */
10278 if (debug_info_level <= DINFO_LEVEL_TERSE)
10281 /* Output any DIEs that are needed to specify the type of this data
10283 gen_type_die (TREE_TYPE (decl), context_die);
10285 /* And its containing type. */
10286 origin = decl_class_context (decl);
10287 if (origin != NULL_TREE)
10288 gen_type_die_for_member (origin, decl, context_die);
10290 /* Now output the DIE to represent the data object itself. This gets
10291 complicated because of the possibility that the VAR_DECL really
10292 represents an inlined instance of a formal parameter for an inline
10294 origin = decl_ultimate_origin (decl);
10295 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
10296 gen_formal_parameter_die (decl, context_die);
10298 gen_variable_die (decl, context_die);
10302 /* Ignore the nameless fields that are used to skip bits, but
10303 handle C++ anonymous unions. */
10304 if (DECL_NAME (decl) != NULL_TREE
10305 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
10307 gen_type_die (member_declared_type (decl), context_die);
10308 gen_field_die (decl, context_die);
10313 gen_type_die (TREE_TYPE (decl), context_die);
10314 gen_formal_parameter_die (decl, context_die);
10317 case NAMESPACE_DECL:
10318 /* Ignore for now. */
10326 /* Add Ada "use" clause information for SGI Workshop debugger. */
10329 dwarf2out_add_library_unit_info (filename, context_list)
10330 const char *filename;
10331 const char *context_list;
10333 unsigned int file_index;
10335 if (filename != NULL)
10337 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
10338 tree context_list_decl
10339 = build_decl (LABEL_DECL, get_identifier (context_list),
10342 TREE_PUBLIC (context_list_decl) = TRUE;
10343 add_name_attribute (unit_die, context_list);
10344 file_index = lookup_filename (filename);
10345 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
10346 add_pubname (context_list_decl, unit_die);
10350 /* Write the debugging output for DECL. */
10353 dwarf2out_decl (decl)
10354 register tree decl;
10356 register dw_die_ref context_die = comp_unit_die;
10358 if (TREE_CODE (decl) == ERROR_MARK)
10361 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10362 if (DECL_IGNORED_P (decl))
10365 switch (TREE_CODE (decl))
10367 case FUNCTION_DECL:
10368 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
10369 builtin function. Explicit programmer-supplied declarations of
10370 these same functions should NOT be ignored however. */
10371 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
10374 /* What we would really like to do here is to filter out all mere
10375 file-scope declarations of file-scope functions which are never
10376 referenced later within this translation unit (and keep all of ones
10377 that *are* referenced later on) but we aren't clairvoyant, so we have
10378 no idea which functions will be referenced in the future (i.e. later
10379 on within the current translation unit). So here we just ignore all
10380 file-scope function declarations which are not also definitions. If
10381 and when the debugger needs to know something about these functions,
10382 it will have to hunt around and find the DWARF information associated
10383 with the definition of the function. Note that we can't just check
10384 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
10385 definitions and which ones represent mere declarations. We have to
10386 check `DECL_INITIAL' instead. That's because the C front-end
10387 supports some weird semantics for "extern inline" function
10388 definitions. These can get inlined within the current translation
10389 unit (an thus, we need to generate DWARF info for their abstract
10390 instances so that the DWARF info for the concrete inlined instances
10391 can have something to refer to) but the compiler never generates any
10392 out-of-lines instances of such things (despite the fact that they
10393 *are* definitions). The important point is that the C front-end
10394 marks these "extern inline" functions as DECL_EXTERNAL, but we need
10395 to generate DWARF for them anyway. Note that the C++ front-end also
10396 plays some similar games for inline function definitions appearing
10397 within include files which also contain
10398 `#pragma interface' pragmas. */
10399 if (DECL_INITIAL (decl) == NULL_TREE)
10402 /* If we're a nested function, initially use a parent of NULL; if we're
10403 a plain function, this will be fixed up in decls_for_scope. If
10404 we're a method, it will be ignored, since we already have a DIE. */
10405 if (decl_function_context (decl))
10406 context_die = NULL;
10411 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
10412 declaration and if the declaration was never even referenced from
10413 within this entire compilation unit. We suppress these DIEs in
10414 order to save space in the .debug section (by eliminating entries
10415 which are probably useless). Note that we must not suppress
10416 block-local extern declarations (whether used or not) because that
10417 would screw-up the debugger's name lookup mechanism and cause it to
10418 miss things which really ought to be in scope at a given point. */
10419 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
10422 /* If we are in terse mode, don't generate any DIEs to represent any
10423 variable declarations or definitions. */
10424 if (debug_info_level <= DINFO_LEVEL_TERSE)
10429 /* Don't emit stubs for types unless they are needed by other DIEs. */
10430 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
10433 /* Don't bother trying to generate any DIEs to represent any of the
10434 normal built-in types for the language we are compiling. */
10435 if (DECL_SOURCE_LINE (decl) == 0)
10437 /* OK, we need to generate one for `bool' so GDB knows what type
10438 comparisons have. */
10439 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
10440 == DW_LANG_C_plus_plus)
10441 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
10442 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
10447 /* If we are in terse mode, don't generate any DIEs for types. */
10448 if (debug_info_level <= DINFO_LEVEL_TERSE)
10451 /* If we're a function-scope tag, initially use a parent of NULL;
10452 this will be fixed up in decls_for_scope. */
10453 if (decl_function_context (decl))
10454 context_die = NULL;
10462 gen_decl_die (decl, context_die);
10465 /* Output a marker (i.e. a label) for the beginning of the generated code for
10466 a lexical block. */
10469 dwarf2out_begin_block (blocknum)
10470 register unsigned blocknum;
10472 function_section (current_function_decl);
10473 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
10476 /* Output a marker (i.e. a label) for the end of the generated code for a
10480 dwarf2out_end_block (blocknum)
10481 register unsigned blocknum;
10483 function_section (current_function_decl);
10484 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
10487 /* Returns nonzero if it is appropriate not to emit any debugging
10488 information for BLOCK, because it doesn't contain any instructions.
10490 Don't allow this for blocks with nested functions or local classes
10491 as we would end up with orphans, and in the presence of scheduling
10492 we may end up calling them anyway. */
10495 dwarf2out_ignore_block (block)
10499 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
10500 if (TREE_CODE (decl) == FUNCTION_DECL
10501 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
10506 /* Output a marker (i.e. a label) at a point in the assembly code which
10507 corresponds to a given source level label. */
10510 dwarf2out_label (insn)
10513 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10515 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10517 function_section (current_function_decl);
10518 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
10519 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
10520 (unsigned) INSN_UID (insn));
10524 /* Lookup a filename (in the list of filenames that we know about here in
10525 dwarf2out.c) and return its "index". The index of each (known) filename is
10526 just a unique number which is associated with only that one filename.
10527 We need such numbers for the sake of generating labels
10528 (in the .debug_sfnames section) and references to those
10529 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
10530 If the filename given as an argument is not found in our current list,
10531 add it to the list and assign it the next available unique index number.
10532 In order to speed up searches, we remember the index of the filename
10533 was looked up last. This handles the majority of all searches. */
10536 lookup_filename (file_name)
10537 const char *file_name;
10539 static unsigned last_file_lookup_index = 0;
10540 register unsigned i;
10542 /* Check to see if the file name that was searched on the previous call
10543 matches this file name. If so, return the index. */
10544 if (last_file_lookup_index != 0)
10545 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
10546 return last_file_lookup_index;
10548 /* Didn't match the previous lookup, search the table */
10549 for (i = 1; i < file_table_in_use; ++i)
10550 if (strcmp (file_name, file_table[i]) == 0)
10552 last_file_lookup_index = i;
10556 /* Prepare to add a new table entry by making sure there is enough space in
10557 the table to do so. If not, expand the current table. */
10558 if (file_table_in_use == file_table_allocated)
10560 file_table_allocated += FILE_TABLE_INCREMENT;
10562 = (char **) xrealloc (file_table,
10563 file_table_allocated * sizeof (char *));
10566 /* Add the new entry to the end of the filename table. */
10567 file_table[file_table_in_use] = xstrdup (file_name);
10568 last_file_lookup_index = file_table_in_use++;
10570 return last_file_lookup_index;
10573 /* Output a label to mark the beginning of a source code line entry
10574 and record information relating to this source line, in
10575 'line_info_table' for later output of the .debug_line section. */
10578 dwarf2out_line (filename, line)
10579 register const char *filename;
10580 register unsigned line;
10582 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10584 function_section (current_function_decl);
10586 if (DWARF2_ASM_LINE_DEBUG_INFO)
10588 static const char *lastfile;
10590 /* Emit the .file and .loc directives understood by GNU as. */
10591 if (lastfile == 0 || strcmp (filename, lastfile))
10594 ggc_add_string_root ((char **) &lastfile, 1);
10596 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
10597 lastfile = filename;
10600 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
10602 /* Indicate that line number info exists. */
10603 ++line_info_table_in_use;
10605 /* Indicate that multiple line number tables exist. */
10606 if (DECL_SECTION_NAME (current_function_decl))
10607 ++separate_line_info_table_in_use;
10609 else if (DECL_SECTION_NAME (current_function_decl))
10611 register dw_separate_line_info_ref line_info;
10612 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
10613 separate_line_info_table_in_use);
10614 if (flag_debug_asm)
10615 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
10616 fputc ('\n', asm_out_file);
10618 /* expand the line info table if necessary */
10619 if (separate_line_info_table_in_use
10620 == separate_line_info_table_allocated)
10622 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10623 separate_line_info_table
10624 = (dw_separate_line_info_ref)
10625 xrealloc (separate_line_info_table,
10626 separate_line_info_table_allocated
10627 * sizeof (dw_separate_line_info_entry));
10630 /* Add the new entry at the end of the line_info_table. */
10632 = &separate_line_info_table[separate_line_info_table_in_use++];
10633 line_info->dw_file_num = lookup_filename (filename);
10634 line_info->dw_line_num = line;
10635 line_info->function = current_funcdef_number;
10639 register dw_line_info_ref line_info;
10641 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
10642 line_info_table_in_use);
10643 if (flag_debug_asm)
10644 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
10645 fputc ('\n', asm_out_file);
10647 /* Expand the line info table if necessary. */
10648 if (line_info_table_in_use == line_info_table_allocated)
10650 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10652 = (dw_line_info_ref)
10653 xrealloc (line_info_table,
10654 (line_info_table_allocated
10655 * sizeof (dw_line_info_entry)));
10658 /* Add the new entry at the end of the line_info_table. */
10659 line_info = &line_info_table[line_info_table_in_use++];
10660 line_info->dw_file_num = lookup_filename (filename);
10661 line_info->dw_line_num = line;
10666 /* Record the beginning of a new source file, for later output
10667 of the .debug_macinfo section. At present, unimplemented. */
10670 dwarf2out_start_source_file (filename)
10671 register const char *filename ATTRIBUTE_UNUSED;
10673 if (flag_eliminate_dwarf2_dups)
10675 /* Record the beginning of the file for break_out_includes. */
10676 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
10677 add_AT_string (bincl_die, DW_AT_name, filename);
10681 /* Record the end of a source file, for later output
10682 of the .debug_macinfo section. At present, unimplemented. */
10685 dwarf2out_end_source_file ()
10687 if (flag_eliminate_dwarf2_dups)
10689 /* Record the end of the file for break_out_includes. */
10690 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
10694 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10695 the tail part of the directive line, i.e. the part which is past the
10696 initial whitespace, #, whitespace, directive-name, whitespace part. */
10699 dwarf2out_define (lineno, buffer)
10700 register unsigned lineno ATTRIBUTE_UNUSED;
10701 register const char *buffer ATTRIBUTE_UNUSED;
10703 static int initialized = 0;
10706 dwarf2out_start_source_file (primary_filename);
10711 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10712 the tail part of the directive line, i.e. the part which is past the
10713 initial whitespace, #, whitespace, directive-name, whitespace part. */
10716 dwarf2out_undef (lineno, buffer)
10717 register unsigned lineno ATTRIBUTE_UNUSED;
10718 register const char *buffer ATTRIBUTE_UNUSED;
10722 /* Set up for Dwarf output at the start of compilation. */
10725 dwarf2out_init (asm_out_file, main_input_filename)
10726 register FILE *asm_out_file;
10727 register const char *main_input_filename;
10729 /* Remember the name of the primary input file. */
10730 primary_filename = main_input_filename;
10732 /* Allocate the initial hunk of the file_table. */
10733 file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
10734 file_table_allocated = FILE_TABLE_INCREMENT;
10736 /* Skip the first entry - file numbers begin at 1. */
10737 file_table_in_use = 1;
10739 /* Allocate the initial hunk of the decl_die_table. */
10741 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
10742 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
10743 decl_die_table_in_use = 0;
10745 /* Allocate the initial hunk of the decl_scope_table. */
10747 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
10748 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
10749 decl_scope_depth = 0;
10751 /* Allocate the initial hunk of the abbrev_die_table. */
10753 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
10754 sizeof (dw_die_ref));
10755 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
10756 /* Zero-th entry is allocated, but unused */
10757 abbrev_die_table_in_use = 1;
10759 /* Allocate the initial hunk of the line_info_table. */
10761 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
10762 sizeof (dw_line_info_entry));
10763 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
10764 /* Zero-th entry is allocated, but unused */
10765 line_info_table_in_use = 1;
10767 /* Generate the initial DIE for the .debug section. Note that the (string)
10768 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
10769 will (typically) be a relative pathname and that this pathname should be
10770 taken as being relative to the directory from which the compiler was
10771 invoked when the given (base) source file was compiled. */
10772 comp_unit_die = gen_compile_unit_die (main_input_filename);
10776 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
10777 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
10780 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
10781 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
10782 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
10783 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
10785 strcpy (text_section_label, stripattributes (TEXT_SECTION));
10786 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
10787 DEBUG_INFO_SECTION_LABEL, 0);
10788 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
10789 DEBUG_LINE_SECTION_LABEL, 0);
10791 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
10792 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
10793 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
10795 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
10796 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
10798 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
10799 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
10800 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
10801 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
10804 /* Output stuff that dwarf requires at the end of every file,
10805 and generate the DWARF-2 debugging info. */
10808 dwarf2out_finish ()
10810 limbo_die_node *node, *next_node;
10813 /* Traverse the limbo die list, and add parent/child links. The only
10814 dies without parents that should be here are concrete instances of
10815 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
10816 For concrete instances, we can get the parent die from the abstract
10818 for (node = limbo_die_list; node; node = next_node)
10820 next_node = node->next;
10823 if (die->die_parent == NULL)
10825 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
10827 add_child_die (origin->die_parent, die);
10828 else if (die == comp_unit_die)
10835 limbo_die_list = NULL;
10837 /* Walk through the list of incomplete types again, trying once more to
10838 emit full debugging info for them. */
10839 retry_incomplete_types ();
10841 /* We need to reverse all the dies before break_out_includes, or
10842 we'll see the end of an include file before the beginning. */
10843 reverse_all_dies (comp_unit_die);
10845 /* Generate separate CUs for each of the include files we've seen.
10846 They will go into limbo_die_list. */
10847 if (flag_eliminate_dwarf2_dups)
10848 break_out_includes (comp_unit_die);
10850 /* Traverse the DIE's and add add sibling attributes to those DIE's
10851 that have children. */
10852 add_sibling_attributes (comp_unit_die);
10853 for (node = limbo_die_list; node; node = node->next)
10854 add_sibling_attributes (node->die);
10856 /* Output a terminator label for the .text section. */
10857 fputc ('\n', asm_out_file);
10858 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
10859 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
10862 /* Output a terminator label for the .data section. */
10863 fputc ('\n', asm_out_file);
10864 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
10865 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
10867 /* Output a terminator label for the .bss section. */
10868 fputc ('\n', asm_out_file);
10869 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
10870 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
10873 /* Output the source line correspondence table. */
10874 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
10876 if (! DWARF2_ASM_LINE_DEBUG_INFO)
10878 fputc ('\n', asm_out_file);
10879 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
10880 output_line_info ();
10883 /* We can only use the low/high_pc attributes if all of the code
10885 if (separate_line_info_table_in_use == 0)
10887 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
10888 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
10891 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
10892 debug_line_section_label);
10895 #if 0 /* unimplemented */
10896 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
10897 add_AT_unsigned (die, DW_AT_macro_info, 0);
10900 /* Output all of the compilation units. We put the main one last so that
10901 the offsets are available to output_pubnames. */
10902 for (node = limbo_die_list; node; node = node->next)
10903 output_comp_unit (node->die);
10904 output_comp_unit (comp_unit_die);
10906 /* Output the abbreviation table. */
10907 fputc ('\n', asm_out_file);
10908 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
10909 output_abbrev_section ();
10911 if (pubname_table_in_use)
10913 /* Output public names table. */
10914 fputc ('\n', asm_out_file);
10915 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
10916 output_pubnames ();
10919 /* We only put functions in the arange table, so don't write it out if
10920 we don't have any. */
10921 if (fde_table_in_use)
10923 /* Output the address range information. */
10924 fputc ('\n', asm_out_file);
10925 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
10929 #endif /* DWARF2_DEBUGGING_INFO */