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)
5060 switch (AT_class (at))
5062 case dw_val_class_const:
5063 PROCESS (at->dw_attr_val.v.val_int);
5065 case dw_val_class_unsigned_const:
5066 PROCESS (at->dw_attr_val.v.val_unsigned);
5068 case dw_val_class_long_long:
5069 PROCESS (at->dw_attr_val.v.val_long_long);
5071 case dw_val_class_float:
5072 PROCESS (at->dw_attr_val.v.val_float);
5074 case dw_val_class_flag:
5075 PROCESS (at->dw_attr_val.v.val_flag);
5078 case dw_val_class_str:
5079 PROCESS_STRING (AT_string (at));
5081 case dw_val_class_addr:
5083 switch (GET_CODE (r))
5086 PROCESS_STRING (XSTR (r, 0));
5094 case dw_val_class_loc:
5095 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5096 loc_checksum (loc, ctx);
5099 case dw_val_class_die_ref:
5100 if (AT_ref (at)->die_offset)
5101 PROCESS (AT_ref (at)->die_offset);
5102 /* FIXME else use target die name or something. */
5104 case dw_val_class_fde_ref:
5105 case dw_val_class_lbl_id:
5106 case dw_val_class_lbl_offset:
5113 /* Calculate the checksum of a DIE. */
5116 die_checksum (die, ctx)
5118 struct md5_ctx *ctx;
5123 PROCESS (die->die_tag);
5125 for (a = die->die_attr; a; a = a->dw_attr_next)
5126 attr_checksum (a, ctx);
5128 for (c = die->die_child; c; c = c->die_sib)
5129 die_checksum (c, ctx);
5133 #undef PROCESS_STRING
5135 /* The prefix to attach to symbols on DIEs in the current comdat debug
5137 static char *comdat_symbol_id;
5139 /* The index of the current symbol within the current comdat CU. */
5140 static unsigned int comdat_symbol_number;
5142 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5143 children, and set comdat_symbol_id accordingly. */
5146 compute_section_prefix (unit_die)
5147 dw_die_ref unit_die;
5151 unsigned char checksum[16];
5154 md5_init_ctx (&ctx);
5155 die_checksum (unit_die, &ctx);
5156 md5_finish_ctx (&ctx, checksum);
5158 p = file_name_nondirectory (get_AT_string (unit_die, DW_AT_name));
5159 name = (char *) alloca (strlen (p) + 64);
5160 sprintf (name, "%s.", p);
5162 clean_symbol_name (name);
5164 p = name + strlen (name);
5165 for (i = 0; i < 4; ++i)
5167 sprintf (p, "%.2x", checksum[i]);
5171 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5172 comdat_symbol_number = 0;
5175 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5181 switch (die->die_tag)
5183 case DW_TAG_array_type:
5184 case DW_TAG_class_type:
5185 case DW_TAG_enumeration_type:
5186 case DW_TAG_pointer_type:
5187 case DW_TAG_reference_type:
5188 case DW_TAG_string_type:
5189 case DW_TAG_structure_type:
5190 case DW_TAG_subroutine_type:
5191 case DW_TAG_union_type:
5192 case DW_TAG_ptr_to_member_type:
5193 case DW_TAG_set_type:
5194 case DW_TAG_subrange_type:
5195 case DW_TAG_base_type:
5196 case DW_TAG_const_type:
5197 case DW_TAG_file_type:
5198 case DW_TAG_packed_type:
5199 case DW_TAG_volatile_type:
5206 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5207 Basically, we want to choose the bits that are likely to be shared between
5208 compilations (types) and leave out the bits that are specific to individual
5209 compilations (functions). */
5216 /* I think we want to leave base types and __vtbl_ptr_type in the
5217 main CU, as we do for stabs. The advantage is a greater
5218 likelihood of sharing between objects that don't include headers
5219 in the same order (and therefore would put the base types in a
5220 different comdat). jason 8/28/00 */
5221 if (c->die_tag == DW_TAG_base_type)
5224 if (c->die_tag == DW_TAG_pointer_type
5225 || c->die_tag == DW_TAG_reference_type
5226 || c->die_tag == DW_TAG_const_type
5227 || c->die_tag == DW_TAG_volatile_type)
5229 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5230 return t ? is_comdat_die (t) : 0;
5234 return is_type_die (c);
5237 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5238 compilation unit. */
5244 if (is_type_die (c))
5246 if (get_AT (c, DW_AT_declaration)
5247 && ! get_AT (c, DW_AT_specification))
5256 static int label_num;
5257 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5258 return xstrdup (buf);
5261 /* Assign symbols to all worthy DIEs under DIE. */
5264 assign_symbol_names (die)
5265 register dw_die_ref die;
5267 register dw_die_ref c;
5269 if (is_symbol_die (die))
5271 if (comdat_symbol_id)
5273 char *p = alloca (strlen (comdat_symbol_id) + 64);
5274 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5275 comdat_symbol_id, comdat_symbol_number++);
5276 die->die_symbol = xstrdup (p);
5279 die->die_symbol = gen_internal_sym ();
5282 for (c = die->die_child; c != NULL; c = c->die_sib)
5283 assign_symbol_names (c);
5286 /* Traverse the DIE (which is always comp_unit_die), and set up
5287 additional compilation units for each of the include files we see
5288 bracketed by BINCL/EINCL. */
5291 break_out_includes (die)
5292 register dw_die_ref die;
5295 register dw_die_ref unit = NULL;
5296 limbo_die_node *node;
5298 for (ptr = &(die->die_child); *ptr; )
5300 register dw_die_ref c = *ptr;
5302 if (c->die_tag == DW_TAG_GNU_BINCL
5303 || c->die_tag == DW_TAG_GNU_EINCL
5304 || (unit && is_comdat_die (c)))
5306 /* This DIE is for a secondary CU; remove it from the main one. */
5309 if (c->die_tag == DW_TAG_GNU_BINCL)
5311 unit = push_new_compile_unit (unit, c);
5314 else if (c->die_tag == DW_TAG_GNU_EINCL)
5316 unit = pop_compile_unit (unit);
5320 add_child_die (unit, c);
5324 /* Leave this DIE in the main CU. */
5325 ptr = &(c->die_sib);
5331 /* We can only use this in debugging, since the frontend doesn't check
5332 to make sure that we leave every include file we enter. */
5337 assign_symbol_names (die);
5338 for (node = limbo_die_list; node; node = node->next)
5340 compute_section_prefix (node->die);
5341 assign_symbol_names (node->die);
5345 /* Traverse the DIE and add a sibling attribute if it may have the
5346 effect of speeding up access to siblings. To save some space,
5347 avoid generating sibling attributes for DIE's without children. */
5350 add_sibling_attributes (die)
5351 register dw_die_ref die;
5353 register dw_die_ref c;
5355 if (die->die_tag != DW_TAG_compile_unit
5356 && die->die_sib && die->die_child != NULL)
5357 /* Add the sibling link to the front of the attribute list. */
5358 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5360 for (c = die->die_child; c != NULL; c = c->die_sib)
5361 add_sibling_attributes (c);
5364 /* The format of each DIE (and its attribute value pairs)
5365 is encoded in an abbreviation table. This routine builds the
5366 abbreviation table and assigns a unique abbreviation id for
5367 each abbreviation entry. The children of each die are visited
5371 build_abbrev_table (die)
5372 register dw_die_ref die;
5374 register unsigned long abbrev_id;
5375 register unsigned long n_alloc;
5376 register dw_die_ref c;
5377 register dw_attr_ref d_attr, a_attr;
5379 /* Scan the DIE references, and mark as external any that refer to
5380 DIEs from other CUs (i.e. those with cleared die_offset). */
5381 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5383 if (AT_class (d_attr) == dw_val_class_die_ref
5384 && AT_ref (d_attr)->die_offset == 0)
5386 if (AT_ref (d_attr)->die_symbol == 0)
5388 set_AT_ref_external (d_attr, 1);
5392 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5394 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5396 if (abbrev->die_tag == die->die_tag)
5398 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5400 a_attr = abbrev->die_attr;
5401 d_attr = die->die_attr;
5403 while (a_attr != NULL && d_attr != NULL)
5405 if ((a_attr->dw_attr != d_attr->dw_attr)
5406 || (value_format (a_attr) != value_format (d_attr)))
5409 a_attr = a_attr->dw_attr_next;
5410 d_attr = d_attr->dw_attr_next;
5413 if (a_attr == NULL && d_attr == NULL)
5419 if (abbrev_id >= abbrev_die_table_in_use)
5421 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5423 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5425 = (dw_die_ref *) xrealloc (abbrev_die_table,
5426 sizeof (dw_die_ref) * n_alloc);
5428 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
5429 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5430 abbrev_die_table_allocated = n_alloc;
5433 ++abbrev_die_table_in_use;
5434 abbrev_die_table[abbrev_id] = die;
5437 die->die_abbrev = abbrev_id;
5438 for (c = die->die_child; c != NULL; c = c->die_sib)
5439 build_abbrev_table (c);
5442 /* Return the size of a string, including the null byte.
5444 This used to treat backslashes as escapes, and hence they were not included
5445 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5446 which treats a backslash as a backslash, escaping it if necessary, and hence
5447 we must include them in the count. */
5449 static unsigned long
5450 size_of_string (str)
5451 register const char *str;
5453 return strlen (str) + 1;
5456 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5459 constant_size (value)
5460 long unsigned value;
5467 log = floor_log2 (value);
5470 log = 1 << (floor_log2 (log) + 1);
5475 /* Return the size of a DIE, as it is represented in the
5476 .debug_info section. */
5478 static unsigned long
5480 register dw_die_ref die;
5482 register unsigned long size = 0;
5483 register dw_attr_ref a;
5485 size += size_of_uleb128 (die->die_abbrev);
5486 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5488 switch (AT_class (a))
5490 case dw_val_class_addr:
5491 size += DWARF2_ADDR_SIZE;
5493 case dw_val_class_loc:
5495 register unsigned long lsize = size_of_locs (AT_loc (a));
5498 size += constant_size (lsize);
5502 case dw_val_class_const:
5503 size += size_of_sleb128 (AT_int (a));
5505 case dw_val_class_unsigned_const:
5506 size += constant_size (AT_unsigned (a));
5508 case dw_val_class_long_long:
5509 size += 1 + 8; /* block */
5511 case dw_val_class_float:
5512 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5514 case dw_val_class_flag:
5517 case dw_val_class_die_ref:
5518 size += DWARF_OFFSET_SIZE;
5520 case dw_val_class_fde_ref:
5521 size += DWARF_OFFSET_SIZE;
5523 case dw_val_class_lbl_id:
5524 size += DWARF2_ADDR_SIZE;
5526 case dw_val_class_lbl_offset:
5527 size += DWARF_OFFSET_SIZE;
5529 case dw_val_class_str:
5530 size += size_of_string (AT_string (a));
5540 /* Size the debugging information associated with a given DIE.
5541 Visits the DIE's children recursively. Updates the global
5542 variable next_die_offset, on each time through. Uses the
5543 current value of next_die_offset to update the die_offset
5544 field in each DIE. */
5547 calc_die_sizes (die)
5550 register dw_die_ref c;
5551 die->die_offset = next_die_offset;
5552 next_die_offset += size_of_die (die);
5554 for (c = die->die_child; c != NULL; c = c->die_sib)
5557 if (die->die_child != NULL)
5558 /* Count the null byte used to terminate sibling lists. */
5559 next_die_offset += 1;
5562 /* Clear the offsets and sizes for a die and its children. We do this so
5563 that we know whether or not a reference needs to use FORM_ref_addr; only
5564 DIEs in the same CU will have non-zero offsets available. */
5567 clear_die_sizes (die)
5570 register dw_die_ref c;
5571 die->die_offset = 0;
5572 for (c = die->die_child; c; c = c->die_sib)
5573 clear_die_sizes (c);
5576 /* Return the size of the line information prolog generated for the
5577 compilation unit. */
5579 static unsigned long
5580 size_of_line_prolog ()
5582 register unsigned long size;
5583 register unsigned long ft_index;
5585 size = DWARF_LINE_PROLOG_HEADER_SIZE;
5587 /* Count the size of the table giving number of args for each
5589 size += DWARF_LINE_OPCODE_BASE - 1;
5591 /* Include directory table is empty (at present). Count only the
5592 null byte used to terminate the table. */
5595 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5597 /* File name entry. */
5598 size += size_of_string (file_table[ft_index]);
5600 /* Include directory index. */
5601 size += size_of_uleb128 (0);
5603 /* Modification time. */
5604 size += size_of_uleb128 (0);
5606 /* File length in bytes. */
5607 size += size_of_uleb128 (0);
5610 /* Count the file table terminator. */
5615 /* Return the size of the .debug_pubnames table generated for the
5616 compilation unit. */
5618 static unsigned long
5621 register unsigned long size;
5622 register unsigned i;
5624 size = DWARF_PUBNAMES_HEADER_SIZE;
5625 for (i = 0; i < pubname_table_in_use; ++i)
5627 register pubname_ref p = &pubname_table[i];
5628 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5631 size += DWARF_OFFSET_SIZE;
5635 /* Return the size of the information in the .debug_aranges section. */
5637 static unsigned long
5640 register unsigned long size;
5642 size = DWARF_ARANGES_HEADER_SIZE;
5644 /* Count the address/length pair for this compilation unit. */
5645 size += 2 * DWARF2_ADDR_SIZE;
5646 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5648 /* Count the two zero words used to terminated the address range table. */
5649 size += 2 * DWARF2_ADDR_SIZE;
5653 /* Select the encoding of an attribute value. */
5655 static enum dwarf_form
5659 switch (a->dw_attr_val.val_class)
5661 case dw_val_class_addr:
5662 return DW_FORM_addr;
5663 case dw_val_class_loc:
5664 switch (constant_size (size_of_locs (AT_loc (a))))
5667 return DW_FORM_block1;
5669 return DW_FORM_block2;
5673 case dw_val_class_const:
5674 return DW_FORM_sdata;
5675 case dw_val_class_unsigned_const:
5676 switch (constant_size (AT_unsigned (a)))
5679 return DW_FORM_data1;
5681 return DW_FORM_data2;
5683 return DW_FORM_data4;
5685 return DW_FORM_data8;
5689 case dw_val_class_long_long:
5690 return DW_FORM_block1;
5691 case dw_val_class_float:
5692 return DW_FORM_block1;
5693 case dw_val_class_flag:
5694 return DW_FORM_flag;
5695 case dw_val_class_die_ref:
5696 if (AT_ref_external (a))
5697 return DW_FORM_ref_addr;
5700 case dw_val_class_fde_ref:
5701 return DW_FORM_data;
5702 case dw_val_class_lbl_id:
5703 return DW_FORM_addr;
5704 case dw_val_class_lbl_offset:
5705 return DW_FORM_data;
5706 case dw_val_class_str:
5707 return DW_FORM_string;
5713 /* Output the encoding of an attribute value. */
5716 output_value_format (a)
5719 enum dwarf_form form = value_format (a);
5721 output_uleb128 (form);
5723 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
5725 fputc ('\n', asm_out_file);
5728 /* Output the .debug_abbrev section which defines the DIE abbreviation
5732 output_abbrev_section ()
5734 unsigned long abbrev_id;
5737 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5739 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5741 output_uleb128 (abbrev_id);
5743 fprintf (asm_out_file, " (abbrev code)");
5745 fputc ('\n', asm_out_file);
5746 output_uleb128 (abbrev->die_tag);
5748 fprintf (asm_out_file, " (TAG: %s)",
5749 dwarf_tag_name (abbrev->die_tag));
5751 fputc ('\n', asm_out_file);
5752 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
5753 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
5756 fprintf (asm_out_file, "\t%s %s",
5758 (abbrev->die_child != NULL
5759 ? "DW_children_yes" : "DW_children_no"));
5761 fputc ('\n', asm_out_file);
5763 for (a_attr = abbrev->die_attr; a_attr != NULL;
5764 a_attr = a_attr->dw_attr_next)
5766 output_uleb128 (a_attr->dw_attr);
5768 fprintf (asm_out_file, " (%s)",
5769 dwarf_attr_name (a_attr->dw_attr));
5771 fputc ('\n', asm_out_file);
5772 output_value_format (a_attr);
5775 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
5778 /* Terminate the table. */
5779 fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP);
5782 /* Output a symbol we can use to refer to this DIE from another CU. */
5785 output_die_symbol (die)
5786 register dw_die_ref die;
5788 char *sym = die->die_symbol;
5793 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5794 /* We make these global, not weak; if the target doesn't support
5795 .linkonce, it doesn't support combining the sections, so debugging
5797 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5798 ASM_OUTPUT_LABEL (asm_out_file, sym);
5801 /* Output a symbolic (i.e. FORM_ref_addr) reference to TARGET_DIE. */
5804 output_symbolic_ref (target_die)
5805 dw_die_ref target_die;
5807 char *sym = target_die->die_symbol;
5812 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, sym);
5815 /* Output the DIE and its attributes. Called recursively to generate
5816 the definitions of each child DIE. */
5820 register dw_die_ref die;
5822 register dw_attr_ref a;
5823 register dw_die_ref c;
5824 register unsigned long size;
5826 /* If someone in another CU might refer to us, set up a symbol for
5827 them to point to. */
5828 if (die->die_symbol)
5829 output_die_symbol (die);
5831 output_uleb128 (die->die_abbrev);
5833 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5834 die->die_offset, dwarf_tag_name (die->die_tag));
5836 fputc ('\n', asm_out_file);
5838 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5840 switch (AT_class (a))
5842 case dw_val_class_addr:
5843 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
5846 case dw_val_class_loc:
5847 size = size_of_locs (AT_loc (a));
5849 /* Output the block length for this list of location operations. */
5850 switch (constant_size (size))
5853 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5856 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5863 fprintf (asm_out_file, "\t%s %s",
5864 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5866 fputc ('\n', asm_out_file);
5868 output_loc_sequence (AT_loc (a));
5871 case dw_val_class_const:
5872 /* ??? It would be slightly more efficient to use a scheme like is
5873 used for unsigned constants below, but gdb 4.x does not sign
5874 extend. Gdb 5.x does sign extend. */
5875 output_sleb128 (AT_int (a));
5878 case dw_val_class_unsigned_const:
5879 switch (constant_size (AT_unsigned (a)))
5882 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
5885 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
5888 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
5891 ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a));
5898 case dw_val_class_long_long:
5899 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5901 fprintf (asm_out_file, "\t%s %s",
5902 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5904 fputc ('\n', asm_out_file);
5905 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file,
5906 a->dw_attr_val.v.val_long_long.hi,
5907 a->dw_attr_val.v.val_long_long.low);
5910 fprintf (asm_out_file,
5911 "\t%s long long constant", ASM_COMMENT_START);
5913 fputc ('\n', asm_out_file);
5916 case dw_val_class_float:
5918 register unsigned int i;
5919 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5920 a->dw_attr_val.v.val_float.length * 4);
5922 fprintf (asm_out_file, "\t%s %s",
5923 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5925 fputc ('\n', asm_out_file);
5926 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5928 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5929 a->dw_attr_val.v.val_float.array[i]);
5931 fprintf (asm_out_file, "\t%s fp constant word %u",
5932 ASM_COMMENT_START, i);
5934 fputc ('\n', asm_out_file);
5939 case dw_val_class_flag:
5940 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
5943 case dw_val_class_die_ref:
5944 if (AT_ref_external (a))
5945 output_symbolic_ref (AT_ref (a));
5947 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
5950 case dw_val_class_fde_ref:
5953 ASM_GENERATE_INTERNAL_LABEL
5954 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5955 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5956 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5960 case dw_val_class_lbl_id:
5961 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
5964 case dw_val_class_lbl_offset:
5965 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
5968 case dw_val_class_str:
5970 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
5972 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
5973 (int) strlen (AT_string (a)) + 1);
5980 if (AT_class (a) != dw_val_class_loc
5981 && AT_class (a) != dw_val_class_long_long
5982 && AT_class (a) != dw_val_class_float)
5985 fprintf (asm_out_file, "\t%s %s",
5986 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5988 fputc ('\n', asm_out_file);
5992 for (c = die->die_child; c != NULL; c = c->die_sib)
5995 if (die->die_child != NULL)
5997 /* Add null byte to terminate sibling list. */
5998 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6000 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
6001 ASM_COMMENT_START, die->die_offset);
6003 fputc ('\n', asm_out_file);
6007 /* Output the compilation unit that appears at the beginning of the
6008 .debug_info section, and precedes the DIE descriptions. */
6011 output_compilation_unit_header ()
6013 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
6015 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
6018 fputc ('\n', asm_out_file);
6019 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6021 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
6023 fputc ('\n', asm_out_file);
6024 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
6026 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
6029 fputc ('\n', asm_out_file);
6030 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6032 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
6034 fputc ('\n', asm_out_file);
6037 /* Output the compilation unit DIE and its children. */
6040 output_comp_unit (die)
6045 if (die->die_child == 0)
6048 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6049 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6050 calc_die_sizes (die);
6052 build_abbrev_table (die);
6054 if (die->die_symbol)
6056 secname = (char *) alloca (strlen (die->die_symbol) + 24);
6057 sprintf (secname, ".gnu.linkonce.wi.%s", die->die_symbol);
6058 die->die_symbol = NULL;
6061 secname = (char *) DEBUG_INFO_SECTION;
6063 /* Output debugging information. */
6064 fputc ('\n', asm_out_file);
6065 ASM_OUTPUT_SECTION (asm_out_file, secname);
6066 output_compilation_unit_header ();
6069 /* Leave the sizes on the main CU, since we do it last and we use the
6070 sizes in output_pubnames. */
6071 if (die->die_symbol)
6072 clear_die_sizes (die);
6075 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6076 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6077 argument list, and maybe the scope. */
6080 dwarf2_name (decl, scope)
6084 return (*decl_printable_name) (decl, scope ? 1 : 0);
6087 /* Add a new entry to .debug_pubnames if appropriate. */
6090 add_pubname (decl, die)
6096 if (! TREE_PUBLIC (decl))
6099 if (pubname_table_in_use == pubname_table_allocated)
6101 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6102 pubname_table = (pubname_ref) xrealloc
6103 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6106 p = &pubname_table[pubname_table_in_use++];
6109 p->name = xstrdup (dwarf2_name (decl, 1));
6112 /* Output the public names table used to speed up access to externally
6113 visible names. For now, only generate entries for externally
6114 visible procedures. */
6119 register unsigned i;
6120 register unsigned long pubnames_length = size_of_pubnames ();
6122 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
6125 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
6128 fputc ('\n', asm_out_file);
6129 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6132 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6134 fputc ('\n', asm_out_file);
6135 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6137 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6140 fputc ('\n', asm_out_file);
6141 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
6143 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
6145 fputc ('\n', asm_out_file);
6146 for (i = 0; i < pubname_table_in_use; ++i)
6148 register pubname_ref pub = &pubname_table[i];
6150 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6151 if (pub->die->die_offset == 0)
6154 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
6156 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
6158 fputc ('\n', asm_out_file);
6162 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
6163 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
6167 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
6168 (int) strlen (pub->name) + 1);
6171 fputc ('\n', asm_out_file);
6174 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
6175 fputc ('\n', asm_out_file);
6178 /* Add a new entry to .debug_aranges if appropriate. */
6181 add_arange (decl, die)
6185 if (! DECL_SECTION_NAME (decl))
6188 if (arange_table_in_use == arange_table_allocated)
6190 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6192 = (arange_ref) xrealloc (arange_table,
6193 arange_table_allocated * sizeof (dw_die_ref));
6196 arange_table[arange_table_in_use++] = die;
6199 /* Output the information that goes into the .debug_aranges table.
6200 Namely, define the beginning and ending address range of the
6201 text section generated for this compilation unit. */
6206 register unsigned i;
6207 register unsigned long aranges_length = size_of_aranges ();
6209 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
6211 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
6214 fputc ('\n', asm_out_file);
6215 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6217 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6219 fputc ('\n', asm_out_file);
6220 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6222 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6225 fputc ('\n', asm_out_file);
6226 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6228 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
6230 fputc ('\n', asm_out_file);
6231 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6233 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
6236 fputc ('\n', asm_out_file);
6238 /* We need to align to twice the pointer size here. */
6239 if (DWARF_ARANGES_PAD_SIZE)
6241 /* Pad using a 2 bytes word so that padding is correct
6242 for any pointer size. */
6243 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
6244 for (i = 2; i < DWARF_ARANGES_PAD_SIZE; i += 2)
6245 fprintf (asm_out_file, ",0");
6247 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
6248 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
6251 fputc ('\n', asm_out_file);
6252 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
6254 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6256 fputc ('\n', asm_out_file);
6257 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
6258 text_section_label);
6260 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6262 fputc ('\n', asm_out_file);
6263 for (i = 0; i < arange_table_in_use; ++i)
6265 dw_die_ref die = arange_table[i];
6267 /* We shouldn't see aranges for DIEs outside of the main CU. */
6268 if (die->die_offset == 0)
6271 if (die->die_tag == DW_TAG_subprogram)
6272 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
6275 /* A static variable; extract the symbol from DW_AT_location.
6276 Note that this code isn't currently hit, as we only emit
6277 aranges for functions (jason 9/23/99). */
6279 dw_attr_ref a = get_AT (die, DW_AT_location);
6280 dw_loc_descr_ref loc;
6281 if (! a || AT_class (a) != dw_val_class_loc)
6285 if (loc->dw_loc_opc != DW_OP_addr)
6288 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
6289 loc->dw_loc_oprnd1.v.val_addr);
6293 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6295 fputc ('\n', asm_out_file);
6296 if (die->die_tag == DW_TAG_subprogram)
6297 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
6298 get_AT_low_pc (die));
6300 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
6301 get_AT_unsigned (die, DW_AT_byte_size));
6304 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6306 fputc ('\n', asm_out_file);
6309 /* Output the terminator words. */
6310 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6311 fputc ('\n', asm_out_file);
6312 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6313 fputc ('\n', asm_out_file);
6316 /* Output the source line number correspondence information. This
6317 information goes into the .debug_line section. */
6322 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6323 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6324 register unsigned opc;
6325 register unsigned n_op_args;
6326 register unsigned long ft_index;
6327 register unsigned long lt_index;
6328 register unsigned long current_line;
6329 register long line_offset;
6330 register long line_delta;
6331 register unsigned long current_file;
6332 register unsigned long function;
6334 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
6336 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
6339 fputc ('\n', asm_out_file);
6340 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
6341 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6343 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6345 fputc ('\n', asm_out_file);
6346 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
6348 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
6350 fputc ('\n', asm_out_file);
6351 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
6353 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
6356 fputc ('\n', asm_out_file);
6357 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
6359 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
6362 fputc ('\n', asm_out_file);
6363 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
6365 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
6368 fputc ('\n', asm_out_file);
6369 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
6371 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
6374 fputc ('\n', asm_out_file);
6375 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
6377 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
6379 fputc ('\n', asm_out_file);
6380 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6384 case DW_LNS_advance_pc:
6385 case DW_LNS_advance_line:
6386 case DW_LNS_set_file:
6387 case DW_LNS_set_column:
6388 case DW_LNS_fixed_advance_pc:
6395 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
6397 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
6398 ASM_COMMENT_START, opc, n_op_args);
6399 fputc ('\n', asm_out_file);
6403 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
6405 /* Include directory table is empty, at present */
6406 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6407 fputc ('\n', asm_out_file);
6409 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
6411 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
6415 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
6416 fprintf (asm_out_file, "%s File Entry: 0x%lx",
6417 ASM_COMMENT_START, ft_index);
6421 ASM_OUTPUT_ASCII (asm_out_file,
6422 file_table[ft_index],
6423 (int) strlen (file_table[ft_index]) + 1);
6426 fputc ('\n', asm_out_file);
6428 /* Include directory index */
6430 fputc ('\n', asm_out_file);
6432 /* Modification time */
6434 fputc ('\n', asm_out_file);
6436 /* File length in bytes */
6438 fputc ('\n', asm_out_file);
6441 /* Terminate the file name table */
6442 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6443 fputc ('\n', asm_out_file);
6445 /* We used to set the address register to the first location in the text
6446 section here, but that didn't accomplish anything since we already
6447 have a line note for the opening brace of the first function. */
6449 /* Generate the line number to PC correspondence table, encoded as
6450 a series of state machine operations. */
6453 strcpy (prev_line_label, text_section_label);
6454 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6456 register dw_line_info_ref line_info = &line_info_table[lt_index];
6459 /* Disable this optimization for now; GDB wants to see two line notes
6460 at the beginning of a function so it can find the end of the
6463 /* Don't emit anything for redundant notes. Just updating the
6464 address doesn't accomplish anything, because we already assume
6465 that anything after the last address is this line. */
6466 if (line_info->dw_line_num == current_line
6467 && line_info->dw_file_num == current_file)
6471 /* Emit debug info for the address of the current line, choosing
6472 the encoding that uses the least amount of space. */
6473 /* ??? Unfortunately, we have little choice here currently, and must
6474 always use the most general form. Gcc does not know the address
6475 delta itself, so we can't use DW_LNS_advance_pc. There are no known
6476 dwarf2 aware assemblers at this time, so we can't use any special
6477 pseudo ops that would allow the assembler to optimally encode this for
6478 us. Many ports do have length attributes which will give an upper
6479 bound on the address range. We could perhaps use length attributes
6480 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
6481 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6484 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6485 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6487 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6490 fputc ('\n', asm_out_file);
6491 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
6492 fputc ('\n', asm_out_file);
6496 /* This can handle any delta. This takes
6497 4+DWARF2_ADDR_SIZE bytes. */
6498 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6500 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6502 fputc ('\n', asm_out_file);
6503 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6504 fputc ('\n', asm_out_file);
6505 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6506 fputc ('\n', asm_out_file);
6507 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6508 fputc ('\n', asm_out_file);
6510 strcpy (prev_line_label, line_label);
6512 /* Emit debug info for the source file of the current line, if
6513 different from the previous line. */
6514 if (line_info->dw_file_num != current_file)
6516 current_file = line_info->dw_file_num;
6517 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6519 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6521 fputc ('\n', asm_out_file);
6522 output_uleb128 (current_file);
6524 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
6526 fputc ('\n', asm_out_file);
6529 /* Emit debug info for the current line number, choosing the encoding
6530 that uses the least amount of space. */
6531 if (line_info->dw_line_num != current_line)
6533 line_offset = line_info->dw_line_num - current_line;
6534 line_delta = line_offset - DWARF_LINE_BASE;
6535 current_line = line_info->dw_line_num;
6536 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6538 /* This can handle deltas from -10 to 234, using the current
6539 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6541 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6542 DWARF_LINE_OPCODE_BASE + line_delta);
6544 fprintf (asm_out_file,
6545 "\t%s line %ld", ASM_COMMENT_START, current_line);
6547 fputc ('\n', asm_out_file);
6551 /* This can handle any delta. This takes at least 4 bytes,
6552 depending on the value being encoded. */
6553 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6555 fprintf (asm_out_file, "\t%s advance to line %ld",
6556 ASM_COMMENT_START, current_line);
6558 fputc ('\n', asm_out_file);
6559 output_sleb128 (line_offset);
6560 fputc ('\n', asm_out_file);
6561 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6563 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6564 fputc ('\n', asm_out_file);
6569 /* We still need to start a new row, so output a copy insn. */
6570 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6572 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6573 fputc ('\n', asm_out_file);
6577 /* Emit debug info for the address of the end of the function. */
6580 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6582 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6585 fputc ('\n', asm_out_file);
6586 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
6587 fputc ('\n', asm_out_file);
6591 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6593 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
6594 fputc ('\n', asm_out_file);
6595 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6596 fputc ('\n', asm_out_file);
6597 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6598 fputc ('\n', asm_out_file);
6599 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
6600 fputc ('\n', asm_out_file);
6603 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6605 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
6607 fputc ('\n', asm_out_file);
6609 fputc ('\n', asm_out_file);
6610 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6611 fputc ('\n', asm_out_file);
6616 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6618 register dw_separate_line_info_ref line_info
6619 = &separate_line_info_table[lt_index];
6622 /* Don't emit anything for redundant notes. */
6623 if (line_info->dw_line_num == current_line
6624 && line_info->dw_file_num == current_file
6625 && line_info->function == function)
6629 /* Emit debug info for the address of the current line. If this is
6630 a new function, or the first line of a function, then we need
6631 to handle it differently. */
6632 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6634 if (function != line_info->function)
6636 function = line_info->function;
6638 /* Set the address register to the first line in the function */
6639 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6641 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6644 fputc ('\n', asm_out_file);
6645 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6646 fputc ('\n', asm_out_file);
6647 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6648 fputc ('\n', asm_out_file);
6649 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6650 fputc ('\n', asm_out_file);
6654 /* ??? See the DW_LNS_advance_pc comment above. */
6657 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6659 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6662 fputc ('\n', asm_out_file);
6663 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6665 fputc ('\n', asm_out_file);
6669 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6671 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6673 fputc ('\n', asm_out_file);
6674 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6675 fputc ('\n', asm_out_file);
6676 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6677 fputc ('\n', asm_out_file);
6678 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6679 fputc ('\n', asm_out_file);
6682 strcpy (prev_line_label, line_label);
6684 /* Emit debug info for the source file of the current line, if
6685 different from the previous line. */
6686 if (line_info->dw_file_num != current_file)
6688 current_file = line_info->dw_file_num;
6689 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6691 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6693 fputc ('\n', asm_out_file);
6694 output_uleb128 (current_file);
6696 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
6698 fputc ('\n', asm_out_file);
6701 /* Emit debug info for the current line number, choosing the encoding
6702 that uses the least amount of space. */
6703 if (line_info->dw_line_num != current_line)
6705 line_offset = line_info->dw_line_num - current_line;
6706 line_delta = line_offset - DWARF_LINE_BASE;
6707 current_line = line_info->dw_line_num;
6708 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6710 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6711 DWARF_LINE_OPCODE_BASE + line_delta);
6713 fprintf (asm_out_file,
6714 "\t%s line %ld", ASM_COMMENT_START, current_line);
6716 fputc ('\n', asm_out_file);
6720 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6722 fprintf (asm_out_file, "\t%s advance to line %ld",
6723 ASM_COMMENT_START, current_line);
6725 fputc ('\n', asm_out_file);
6726 output_sleb128 (line_offset);
6727 fputc ('\n', asm_out_file);
6728 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6730 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6731 fputc ('\n', asm_out_file);
6736 /* We still need to start a new row, so output a copy insn. */
6737 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6739 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6740 fputc ('\n', asm_out_file);
6748 /* If we're done with a function, end its sequence. */
6749 if (lt_index == separate_line_info_table_in_use
6750 || separate_line_info_table[lt_index].function != function)
6755 /* Emit debug info for the address of the end of the function. */
6756 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6759 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6761 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6764 fputc ('\n', asm_out_file);
6765 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6767 fputc ('\n', asm_out_file);
6771 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6773 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6775 fputc ('\n', asm_out_file);
6776 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6777 fputc ('\n', asm_out_file);
6778 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6779 fputc ('\n', asm_out_file);
6780 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6781 fputc ('\n', asm_out_file);
6784 /* Output the marker for the end of this sequence. */
6785 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6787 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
6790 fputc ('\n', asm_out_file);
6792 fputc ('\n', asm_out_file);
6793 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6794 fputc ('\n', asm_out_file);
6798 /* Output the marker for the end of the line number info. */
6799 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
6802 /* Given a pointer to a tree node for some base type, return a pointer to
6803 a DIE that describes the given type.
6805 This routine must only be called for GCC type nodes that correspond to
6806 Dwarf base (fundamental) types. */
6809 base_type_die (type)
6812 register dw_die_ref base_type_result;
6813 register const char *type_name;
6814 register enum dwarf_type encoding;
6815 register tree name = TYPE_NAME (type);
6817 if (TREE_CODE (type) == ERROR_MARK
6818 || TREE_CODE (type) == VOID_TYPE)
6823 if (TREE_CODE (name) == TYPE_DECL)
6824 name = DECL_NAME (name);
6826 type_name = IDENTIFIER_POINTER (name);
6829 type_name = "__unknown__";
6831 switch (TREE_CODE (type))
6834 /* Carefully distinguish the C character types, without messing
6835 up if the language is not C. Note that we check only for the names
6836 that contain spaces; other names might occur by coincidence in other
6838 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6839 && (type == char_type_node
6840 || ! strcmp (type_name, "signed char")
6841 || ! strcmp (type_name, "unsigned char"))))
6843 if (TREE_UNSIGNED (type))
6844 encoding = DW_ATE_unsigned;
6846 encoding = DW_ATE_signed;
6849 /* else fall through. */
6852 /* GNU Pascal/Ada CHAR type. Not used in C. */
6853 if (TREE_UNSIGNED (type))
6854 encoding = DW_ATE_unsigned_char;
6856 encoding = DW_ATE_signed_char;
6860 encoding = DW_ATE_float;
6863 /* Dwarf2 doesn't know anything about complex ints, so use
6864 a user defined type for it. */
6866 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6867 encoding = DW_ATE_complex_float;
6869 encoding = DW_ATE_lo_user;
6873 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6874 encoding = DW_ATE_boolean;
6878 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6881 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6882 if (demangle_name_func)
6883 type_name = (*demangle_name_func) (type_name);
6885 add_AT_string (base_type_result, DW_AT_name, type_name);
6886 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6887 int_size_in_bytes (type));
6888 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6890 return base_type_result;
6893 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6894 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6895 a given type is generally the same as the given type, except that if the
6896 given type is a pointer or reference type, then the root type of the given
6897 type is the root type of the "basis" type for the pointer or reference
6898 type. (This definition of the "root" type is recursive.) Also, the root
6899 type of a `const' qualified type or a `volatile' qualified type is the
6900 root type of the given type without the qualifiers. */
6906 if (TREE_CODE (type) == ERROR_MARK)
6907 return error_mark_node;
6909 switch (TREE_CODE (type))
6912 return error_mark_node;
6915 case REFERENCE_TYPE:
6916 return type_main_variant (root_type (TREE_TYPE (type)));
6919 return type_main_variant (type);
6923 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6924 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6930 switch (TREE_CODE (type))
6945 case QUAL_UNION_TYPE:
6950 case REFERENCE_TYPE:
6963 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6964 entry that chains various modifiers in front of the given type. */
6967 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6969 register int is_const_type;
6970 register int is_volatile_type;
6971 register dw_die_ref context_die;
6973 register enum tree_code code = TREE_CODE (type);
6974 register dw_die_ref mod_type_die = NULL;
6975 register dw_die_ref sub_die = NULL;
6976 register tree item_type = NULL;
6978 if (code != ERROR_MARK)
6980 type = build_type_variant (type, is_const_type, is_volatile_type);
6982 mod_type_die = lookup_type_die (type);
6984 return mod_type_die;
6986 /* Handle C typedef types. */
6987 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6988 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6990 tree dtype = TREE_TYPE (TYPE_NAME (type));
6993 /* For a named type, use the typedef. */
6994 gen_type_die (type, context_die);
6995 mod_type_die = lookup_type_die (type);
6998 else if (is_const_type < TYPE_READONLY (dtype)
6999 || is_volatile_type < TYPE_VOLATILE (dtype))
7000 /* cv-unqualified version of named type. Just use the unnamed
7001 type to which it refers. */
7003 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
7004 is_const_type, is_volatile_type,
7006 /* Else cv-qualified version of named type; fall through. */
7012 else if (is_const_type)
7014 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7015 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7017 else if (is_volatile_type)
7019 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7020 sub_die = modified_type_die (type, 0, 0, context_die);
7022 else if (code == POINTER_TYPE)
7024 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7025 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7027 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7029 item_type = TREE_TYPE (type);
7031 else if (code == REFERENCE_TYPE)
7033 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7034 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7036 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7038 item_type = TREE_TYPE (type);
7040 else if (is_base_type (type))
7041 mod_type_die = base_type_die (type);
7044 gen_type_die (type, context_die);
7046 /* We have to get the type_main_variant here (and pass that to the
7047 `lookup_type_die' routine) because the ..._TYPE node we have
7048 might simply be a *copy* of some original type node (where the
7049 copy was created to help us keep track of typedef names) and
7050 that copy might have a different TYPE_UID from the original
7052 mod_type_die = lookup_type_die (type_main_variant (type));
7053 if (mod_type_die == NULL)
7058 equate_type_number_to_die (type, mod_type_die);
7060 /* We must do this after the equate_type_number_to_die call, in case
7061 this is a recursive type. This ensures that the modified_type_die
7062 recursion will terminate even if the type is recursive. Recursive
7063 types are possible in Ada. */
7064 sub_die = modified_type_die (item_type,
7065 TYPE_READONLY (item_type),
7066 TYPE_VOLATILE (item_type),
7069 if (sub_die != NULL)
7070 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7072 return mod_type_die;
7075 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7076 an enumerated type. */
7082 return TREE_CODE (type) == ENUMERAL_TYPE;
7085 /* Return the register number described by a given RTL node. */
7091 register unsigned regno = REGNO (rtl);
7093 if (regno >= FIRST_PSEUDO_REGISTER)
7095 warning ("internal regno botch: regno = %d\n", regno);
7099 regno = DBX_REGISTER_NUMBER (regno);
7103 /* Return a location descriptor that designates a machine register. */
7105 static dw_loc_descr_ref
7106 reg_loc_descriptor (rtl)
7109 register dw_loc_descr_ref loc_result = NULL;
7110 register unsigned reg = reg_number (rtl);
7113 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7115 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7120 /* Return a location descriptor that designates a base+offset location. */
7122 static dw_loc_descr_ref
7123 based_loc_descr (reg, offset)
7127 register dw_loc_descr_ref loc_result;
7128 /* For the "frame base", we use the frame pointer or stack pointer
7129 registers, since the RTL for local variables is relative to one of
7131 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7132 ? HARD_FRAME_POINTER_REGNUM
7133 : STACK_POINTER_REGNUM);
7136 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7138 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7140 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7145 /* Return true if this RTL expression describes a base+offset calculation. */
7151 return (GET_CODE (rtl) == PLUS
7152 && ((GET_CODE (XEXP (rtl, 0)) == REG
7153 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7156 /* The following routine converts the RTL for a variable or parameter
7157 (resident in memory) into an equivalent Dwarf representation of a
7158 mechanism for getting the address of that same variable onto the top of a
7159 hypothetical "address evaluation" stack.
7161 When creating memory location descriptors, we are effectively transforming
7162 the RTL for a memory-resident object into its Dwarf postfix expression
7163 equivalent. This routine recursively descends an RTL tree, turning
7164 it into Dwarf postfix code as it goes.
7166 MODE is the mode of the memory reference, needed to handle some
7167 autoincrement addressing modes. */
7169 static dw_loc_descr_ref
7170 mem_loc_descriptor (rtl, mode)
7172 enum machine_mode mode;
7174 dw_loc_descr_ref mem_loc_result = NULL;
7175 /* Note that for a dynamically sized array, the location we will generate a
7176 description of here will be the lowest numbered location which is
7177 actually within the array. That's *not* necessarily the same as the
7178 zeroth element of the array. */
7180 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7181 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7184 switch (GET_CODE (rtl))
7188 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7189 just fall into the SUBREG code. */
7194 /* The case of a subreg may arise when we have a local (register)
7195 variable or a formal (register) parameter which doesn't quite fill
7196 up an entire register. For now, just assume that it is
7197 legitimate to make the Dwarf info refer to the whole register which
7198 contains the given subreg. */
7199 rtl = XEXP (rtl, 0);
7204 /* Whenever a register number forms a part of the description of the
7205 method for calculating the (dynamic) address of a memory resident
7206 object, DWARF rules require the register number be referred to as
7207 a "base register". This distinction is not based in any way upon
7208 what category of register the hardware believes the given register
7209 belongs to. This is strictly DWARF terminology we're dealing with
7210 here. Note that in cases where the location of a memory-resident
7211 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7212 OP_CONST (0)) the actual DWARF location descriptor that we generate
7213 may just be OP_BASEREG (basereg). This may look deceptively like
7214 the object in question was allocated to a register (rather than in
7215 memory) so DWARF consumers need to be aware of the subtle
7216 distinction between OP_REG and OP_BASEREG. */
7217 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7221 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7222 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7226 /* Some ports can transform a symbol ref into a label ref, because
7227 the symbol ref is too far away and has to be dumped into a constant
7231 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7232 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7233 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7238 /* Turn these into a PLUS expression and fall into the PLUS code
7240 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7241 GEN_INT (GET_CODE (rtl) == PRE_INC
7242 ? GET_MODE_UNIT_SIZE (mode)
7243 : -GET_MODE_UNIT_SIZE (mode)));
7248 if (is_based_loc (rtl))
7249 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7250 INTVAL (XEXP (rtl, 1)));
7253 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0),
7255 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1),
7257 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
7262 /* If a pseudo-reg is optimized away, it is possible for it to
7263 be replaced with a MEM containing a multiply. */
7264 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode));
7265 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode));
7266 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7270 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
7277 return mem_loc_result;
7280 /* Return a descriptor that describes the concatenation of two locations.
7281 This is typically a complex variable. */
7283 static dw_loc_descr_ref
7284 concat_loc_descriptor (x0, x1)
7285 register rtx x0, x1;
7287 dw_loc_descr_ref cc_loc_result = NULL;
7289 if (!is_pseudo_reg (x0)
7290 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7291 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7292 add_loc_descr (&cc_loc_result,
7293 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7295 if (!is_pseudo_reg (x1)
7296 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7297 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7298 add_loc_descr (&cc_loc_result,
7299 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7301 return cc_loc_result;
7304 /* Output a proper Dwarf location descriptor for a variable or parameter
7305 which is either allocated in a register or in a memory location. For a
7306 register, we just generate an OP_REG and the register number. For a
7307 memory location we provide a Dwarf postfix expression describing how to
7308 generate the (dynamic) address of the object onto the address stack. */
7310 static dw_loc_descr_ref
7311 loc_descriptor (rtl)
7314 dw_loc_descr_ref loc_result = NULL;
7315 switch (GET_CODE (rtl))
7318 /* The case of a subreg may arise when we have a local (register)
7319 variable or a formal (register) parameter which doesn't quite fill
7320 up an entire register. For now, just assume that it is
7321 legitimate to make the Dwarf info refer to the whole register which
7322 contains the given subreg. */
7323 rtl = XEXP (rtl, 0);
7328 loc_result = reg_loc_descriptor (rtl);
7332 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7336 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7346 /* Given a value, round it up to the lowest multiple of `boundary'
7347 which is not less than the value itself. */
7349 static inline HOST_WIDE_INT
7350 ceiling (value, boundary)
7351 HOST_WIDE_INT value;
7352 unsigned int boundary;
7354 return (((value + boundary - 1) / boundary) * boundary);
7357 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
7358 pointer to the declared type for the relevant field variable, or return
7359 `integer_type_node' if the given node turns out to be an
7368 if (TREE_CODE (decl) == ERROR_MARK)
7369 return integer_type_node;
7371 type = DECL_BIT_FIELD_TYPE (decl);
7372 if (type == NULL_TREE)
7373 type = TREE_TYPE (decl);
7378 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7379 node, return the alignment in bits for the type, or else return
7380 BITS_PER_WORD if the node actually turns out to be an
7383 static inline unsigned
7384 simple_type_align_in_bits (type)
7387 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
7390 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7391 node, return the size in bits for the type if it is a constant, or else
7392 return the alignment for the type if the type's size is not constant, or
7393 else return BITS_PER_WORD if the type actually turns out to be an
7396 static inline unsigned HOST_WIDE_INT
7397 simple_type_size_in_bits (type)
7400 if (TREE_CODE (type) == ERROR_MARK)
7401 return BITS_PER_WORD;
7404 register tree type_size_tree = TYPE_SIZE (type);
7406 if (! host_integerp (type_size_tree, 1))
7407 return TYPE_ALIGN (type);
7409 return tree_low_cst (type_size_tree, 1);
7413 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
7414 return the byte offset of the lowest addressed byte of the "containing
7415 object" for the given FIELD_DECL, or return 0 if we are unable to
7416 determine what that offset is, either because the argument turns out to
7417 be a pointer to an ERROR_MARK node, or because the offset is actually
7418 variable. (We can't handle the latter case just yet). */
7420 static HOST_WIDE_INT
7421 field_byte_offset (decl)
7424 unsigned int type_align_in_bytes;
7425 unsigned int type_align_in_bits;
7426 unsigned HOST_WIDE_INT type_size_in_bits;
7427 HOST_WIDE_INT object_offset_in_align_units;
7428 HOST_WIDE_INT object_offset_in_bits;
7429 HOST_WIDE_INT object_offset_in_bytes;
7431 tree field_size_tree;
7432 HOST_WIDE_INT bitpos_int;
7433 HOST_WIDE_INT deepest_bitpos;
7434 unsigned HOST_WIDE_INT field_size_in_bits;
7436 if (TREE_CODE (decl) == ERROR_MARK)
7439 if (TREE_CODE (decl) != FIELD_DECL)
7442 type = field_type (decl);
7443 field_size_tree = DECL_SIZE (decl);
7445 /* If there was an error, the size could be zero. */
7446 if (! field_size_tree)
7454 /* We cannot yet cope with fields whose positions are variable, so
7455 for now, when we see such things, we simply return 0. Someday, we may
7456 be able to handle such cases, but it will be damn difficult. */
7457 if (! host_integerp (bit_position (decl), 0))
7460 bitpos_int = int_bit_position (decl);
7462 /* If we don't know the size of the field, pretend it's a full word. */
7463 if (host_integerp (field_size_tree, 1))
7464 field_size_in_bits = tree_low_cst (field_size_tree, 1);
7466 field_size_in_bits = BITS_PER_WORD;
7468 type_size_in_bits = simple_type_size_in_bits (type);
7469 type_align_in_bits = simple_type_align_in_bits (type);
7470 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
7472 /* Note that the GCC front-end doesn't make any attempt to keep track of
7473 the starting bit offset (relative to the start of the containing
7474 structure type) of the hypothetical "containing object" for a bit-
7475 field. Thus, when computing the byte offset value for the start of the
7476 "containing object" of a bit-field, we must deduce this information on
7477 our own. This can be rather tricky to do in some cases. For example,
7478 handling the following structure type definition when compiling for an
7479 i386/i486 target (which only aligns long long's to 32-bit boundaries)
7482 struct S { int field1; long long field2:31; };
7484 Fortunately, there is a simple rule-of-thumb which can be
7485 used in such cases. When compiling for an i386/i486, GCC will allocate
7486 8 bytes for the structure shown above. It decides to do this based upon
7487 one simple rule for bit-field allocation. Quite simply, GCC allocates
7488 each "containing object" for each bit-field at the first (i.e. lowest
7489 addressed) legitimate alignment boundary (based upon the required
7490 minimum alignment for the declared type of the field) which it can
7491 possibly use, subject to the condition that there is still enough
7492 available space remaining in the containing object (when allocated at
7493 the selected point) to fully accommodate all of the bits of the
7494 bit-field itself. This simple rule makes it obvious why GCC allocates
7495 8 bytes for each object of the structure type shown above. When looking
7496 for a place to allocate the "containing object" for `field2', the
7497 compiler simply tries to allocate a 64-bit "containing object" at each
7498 successive 32-bit boundary (starting at zero) until it finds a place to
7499 allocate that 64- bit field such that at least 31 contiguous (and
7500 previously unallocated) bits remain within that selected 64 bit field.
7501 (As it turns out, for the example above, the compiler finds that it is
7502 OK to allocate the "containing object" 64-bit field at bit-offset zero
7503 within the structure type.) Here we attempt to work backwards from the
7504 limited set of facts we're given, and we try to deduce from those facts,
7505 where GCC must have believed that the containing object started (within
7506 the structure type). The value we deduce is then used (by the callers of
7507 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
7508 for fields (both bit-fields and, in the case of DW_AT_location, regular
7511 /* Figure out the bit-distance from the start of the structure to the
7512 "deepest" bit of the bit-field. */
7513 deepest_bitpos = bitpos_int + field_size_in_bits;
7515 /* This is the tricky part. Use some fancy footwork to deduce where the
7516 lowest addressed bit of the containing object must be. */
7517 object_offset_in_bits
7518 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
7520 /* Compute the offset of the containing object in "alignment units". */
7521 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
7523 /* Compute the offset of the containing object in bytes. */
7524 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
7526 return object_offset_in_bytes;
7529 /* The following routines define various Dwarf attributes and any data
7530 associated with them. */
7532 /* Add a location description attribute value to a DIE.
7534 This emits location attributes suitable for whole variables and
7535 whole parameters. Note that the location attributes for struct fields are
7536 generated by the routine `data_member_location_attribute' below. */
7539 add_AT_location_description (die, attr_kind, rtl)
7541 enum dwarf_attribute attr_kind;
7544 /* Handle a special case. If we are about to output a location descriptor
7545 for a variable or parameter which has been optimized out of existence,
7546 don't do that. A variable which has been optimized out
7547 of existence will have a DECL_RTL value which denotes a pseudo-reg.
7548 Currently, in some rare cases, variables can have DECL_RTL values which
7549 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
7550 elsewhere in the compiler. We treat such cases as if the variable(s) in
7551 question had been optimized out of existence. */
7553 if (is_pseudo_reg (rtl)
7554 || (GET_CODE (rtl) == MEM
7555 && is_pseudo_reg (XEXP (rtl, 0)))
7556 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
7557 references the internal argument pointer (a pseudo) in a function
7558 where all references to the internal argument pointer were
7559 eliminated via the optimizers. */
7560 || (GET_CODE (rtl) == MEM
7561 && GET_CODE (XEXP (rtl, 0)) == PLUS
7562 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
7563 || (GET_CODE (rtl) == CONCAT
7564 && is_pseudo_reg (XEXP (rtl, 0))
7565 && is_pseudo_reg (XEXP (rtl, 1))))
7568 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
7571 /* Attach the specialized form of location attribute used for data
7572 members of struct and union types. In the special case of a
7573 FIELD_DECL node which represents a bit-field, the "offset" part
7574 of this special location descriptor must indicate the distance
7575 in bytes from the lowest-addressed byte of the containing struct
7576 or union type to the lowest-addressed byte of the "containing
7577 object" for the bit-field. (See the `field_byte_offset' function
7578 above).. For any given bit-field, the "containing object" is a
7579 hypothetical object (of some integral or enum type) within which
7580 the given bit-field lives. The type of this hypothetical
7581 "containing object" is always the same as the declared type of
7582 the individual bit-field itself (for GCC anyway... the DWARF
7583 spec doesn't actually mandate this). Note that it is the size
7584 (in bytes) of the hypothetical "containing object" which will
7585 be given in the DW_AT_byte_size attribute for this bit-field.
7586 (See the `byte_size_attribute' function below.) It is also used
7587 when calculating the value of the DW_AT_bit_offset attribute.
7588 (See the `bit_offset_attribute' function below). */
7591 add_data_member_location_attribute (die, decl)
7592 register dw_die_ref die;
7595 register unsigned long offset;
7596 register dw_loc_descr_ref loc_descr;
7597 register enum dwarf_location_atom op;
7599 if (TREE_CODE (decl) == TREE_VEC)
7600 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
7602 offset = field_byte_offset (decl);
7604 /* The DWARF2 standard says that we should assume that the structure address
7605 is already on the stack, so we can specify a structure field address
7606 by using DW_OP_plus_uconst. */
7608 #ifdef MIPS_DEBUGGING_INFO
7609 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
7610 correctly. It works only if we leave the offset on the stack. */
7613 op = DW_OP_plus_uconst;
7616 loc_descr = new_loc_descr (op, offset, 0);
7617 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
7620 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
7621 does not have a "location" either in memory or in a register. These
7622 things can arise in GNU C when a constant is passed as an actual parameter
7623 to an inlined function. They can also arise in C++ where declared
7624 constants do not necessarily get memory "homes". */
7627 add_const_value_attribute (die, rtl)
7628 register dw_die_ref die;
7631 switch (GET_CODE (rtl))
7634 /* Note that a CONST_INT rtx could represent either an integer or a
7635 floating-point constant. A CONST_INT is used whenever the constant
7636 will fit into a single word. In all such cases, the original mode
7637 of the constant value is wiped out, and the CONST_INT rtx is
7638 assigned VOIDmode. */
7639 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
7643 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
7644 floating-point constant. A CONST_DOUBLE is used whenever the
7645 constant requires more than one word in order to be adequately
7646 represented. We output CONST_DOUBLEs as blocks. */
7648 register enum machine_mode mode = GET_MODE (rtl);
7650 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
7652 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
7656 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
7660 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
7664 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
7669 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
7676 add_AT_float (die, DW_AT_const_value, length, array);
7679 add_AT_long_long (die, DW_AT_const_value,
7680 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
7685 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
7691 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
7695 /* In cases where an inlined instance of an inline function is passed
7696 the address of an `auto' variable (which is local to the caller) we
7697 can get a situation where the DECL_RTL of the artificial local
7698 variable (for the inlining) which acts as a stand-in for the
7699 corresponding formal parameter (of the inline function) will look
7700 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
7701 exactly a compile-time constant expression, but it isn't the address
7702 of the (artificial) local variable either. Rather, it represents the
7703 *value* which the artificial local variable always has during its
7704 lifetime. We currently have no way to represent such quasi-constant
7705 values in Dwarf, so for now we just punt and generate nothing. */
7709 /* No other kinds of rtx should be possible here. */
7715 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
7716 data attribute for a variable or a parameter. We generate the
7717 DW_AT_const_value attribute only in those cases where the given variable
7718 or parameter does not have a true "location" either in memory or in a
7719 register. This can happen (for example) when a constant is passed as an
7720 actual argument in a call to an inline function. (It's possible that
7721 these things can crop up in other ways also.) Note that one type of
7722 constant value which can be passed into an inlined function is a constant
7723 pointer. This can happen for example if an actual argument in an inlined
7724 function call evaluates to a compile-time constant address. */
7727 add_location_or_const_value_attribute (die, decl)
7728 register dw_die_ref die;
7732 register tree declared_type;
7733 register tree passed_type;
7735 if (TREE_CODE (decl) == ERROR_MARK)
7738 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
7741 /* Here we have to decide where we are going to say the parameter "lives"
7742 (as far as the debugger is concerned). We only have a couple of
7743 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
7745 DECL_RTL normally indicates where the parameter lives during most of the
7746 activation of the function. If optimization is enabled however, this
7747 could be either NULL or else a pseudo-reg. Both of those cases indicate
7748 that the parameter doesn't really live anywhere (as far as the code
7749 generation parts of GCC are concerned) during most of the function's
7750 activation. That will happen (for example) if the parameter is never
7751 referenced within the function.
7753 We could just generate a location descriptor here for all non-NULL
7754 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
7755 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
7756 where DECL_RTL is NULL or is a pseudo-reg.
7758 Note however that we can only get away with using DECL_INCOMING_RTL as
7759 a backup substitute for DECL_RTL in certain limited cases. In cases
7760 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
7761 we can be sure that the parameter was passed using the same type as it is
7762 declared to have within the function, and that its DECL_INCOMING_RTL
7763 points us to a place where a value of that type is passed.
7765 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
7766 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
7767 because in these cases DECL_INCOMING_RTL points us to a value of some
7768 type which is *different* from the type of the parameter itself. Thus,
7769 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
7770 such cases, the debugger would end up (for example) trying to fetch a
7771 `float' from a place which actually contains the first part of a
7772 `double'. That would lead to really incorrect and confusing
7773 output at debug-time.
7775 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
7776 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
7777 are a couple of exceptions however. On little-endian machines we can
7778 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
7779 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
7780 an integral type that is smaller than TREE_TYPE (decl). These cases arise
7781 when (on a little-endian machine) a non-prototyped function has a
7782 parameter declared to be of type `short' or `char'. In such cases,
7783 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
7784 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
7785 passed `int' value. If the debugger then uses that address to fetch
7786 a `short' or a `char' (on a little-endian machine) the result will be
7787 the correct data, so we allow for such exceptional cases below.
7789 Note that our goal here is to describe the place where the given formal
7790 parameter lives during most of the function's activation (i.e. between
7791 the end of the prologue and the start of the epilogue). We'll do that
7792 as best as we can. Note however that if the given formal parameter is
7793 modified sometime during the execution of the function, then a stack
7794 backtrace (at debug-time) will show the function as having been
7795 called with the *new* value rather than the value which was
7796 originally passed in. This happens rarely enough that it is not
7797 a major problem, but it *is* a problem, and I'd like to fix it.
7799 A future version of dwarf2out.c may generate two additional
7800 attributes for any given DW_TAG_formal_parameter DIE which will
7801 describe the "passed type" and the "passed location" for the
7802 given formal parameter in addition to the attributes we now
7803 generate to indicate the "declared type" and the "active
7804 location" for each parameter. This additional set of attributes
7805 could be used by debuggers for stack backtraces. Separately, note
7806 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
7807 NULL also. This happens (for example) for inlined-instances of
7808 inline function formal parameters which are never referenced.
7809 This really shouldn't be happening. All PARM_DECL nodes should
7810 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
7811 doesn't currently generate these values for inlined instances of
7812 inline function parameters, so when we see such cases, we are
7813 just out-of-luck for the time being (until integrate.c
7816 /* Use DECL_RTL as the "location" unless we find something better. */
7817 rtl = DECL_RTL (decl);
7819 if (TREE_CODE (decl) == PARM_DECL)
7821 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
7823 declared_type = type_main_variant (TREE_TYPE (decl));
7824 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
7826 /* This decl represents a formal parameter which was optimized out.
7827 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
7828 all* cases where (rtl == NULL_RTX) just below. */
7829 if (declared_type == passed_type)
7830 rtl = DECL_INCOMING_RTL (decl);
7831 else if (! BYTES_BIG_ENDIAN
7832 && TREE_CODE (declared_type) == INTEGER_TYPE
7833 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
7834 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
7835 rtl = DECL_INCOMING_RTL (decl);
7838 /* If the parm was passed in registers, but lives on the stack, then
7839 make a big endian correction if the mode of the type of the
7840 parameter is not the same as the mode of the rtl. */
7841 /* ??? This is the same series of checks that are made in dbxout.c before
7842 we reach the big endian correction code there. It isn't clear if all
7843 of these checks are necessary here, but keeping them all is the safe
7845 else if (GET_CODE (rtl) == MEM
7846 && XEXP (rtl, 0) != const0_rtx
7847 && ! CONSTANT_P (XEXP (rtl, 0))
7848 /* Not passed in memory. */
7849 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
7850 /* Not passed by invisible reference. */
7851 && (GET_CODE (XEXP (rtl, 0)) != REG
7852 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
7853 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
7854 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
7855 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
7858 /* Big endian correction check. */
7860 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
7861 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
7864 int offset = (UNITS_PER_WORD
7865 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
7866 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
7867 plus_constant (XEXP (rtl, 0), offset));
7871 if (rtl == NULL_RTX)
7874 rtl = eliminate_regs (rtl, 0, NULL_RTX);
7875 #ifdef LEAF_REG_REMAP
7876 if (current_function_uses_only_leaf_regs)
7877 leaf_renumber_regs_insn (rtl);
7880 switch (GET_CODE (rtl))
7883 /* The address of a variable that was optimized away; don't emit
7894 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7895 add_const_value_attribute (die, rtl);
7902 add_AT_location_description (die, DW_AT_location, rtl);
7910 /* Generate an DW_AT_name attribute given some string value to be included as
7911 the value of the attribute. */
7914 add_name_attribute (die, name_string)
7915 register dw_die_ref die;
7916 register const char *name_string;
7918 if (name_string != NULL && *name_string != 0)
7920 if (demangle_name_func)
7921 name_string = (*demangle_name_func) (name_string);
7923 add_AT_string (die, DW_AT_name, name_string);
7927 /* Given a tree node describing an array bound (either lower or upper) output
7928 a representation for that bound. */
7931 add_bound_info (subrange_die, bound_attr, bound)
7932 register dw_die_ref subrange_die;
7933 register enum dwarf_attribute bound_attr;
7934 register tree bound;
7936 /* If this is an Ada unconstrained array type, then don't emit any debug
7937 info because the array bounds are unknown. They are parameterized when
7938 the type is instantiated. */
7939 if (contains_placeholder_p (bound))
7942 switch (TREE_CODE (bound))
7947 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7949 if (! host_integerp (bound, 0)
7950 || (bound_attr == DW_AT_lower_bound
7951 && (((is_c_family () || is_java ()) && integer_zerop (bound))
7952 || (is_fortran () && integer_onep (bound)))))
7953 /* use the default */
7956 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
7961 case NON_LVALUE_EXPR:
7962 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7966 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7967 access the upper bound values may be bogus. If they refer to a
7968 register, they may only describe how to get at these values at the
7969 points in the generated code right after they have just been
7970 computed. Worse yet, in the typical case, the upper bound values
7971 will not even *be* computed in the optimized code (though the
7972 number of elements will), so these SAVE_EXPRs are entirely
7973 bogus. In order to compensate for this fact, we check here to see
7974 if optimization is enabled, and if so, we don't add an attribute
7975 for the (unknown and unknowable) upper bound. This should not
7976 cause too much trouble for existing (stupid?) debuggers because
7977 they have to deal with empty upper bounds location descriptions
7978 anyway in order to be able to deal with incomplete array types.
7979 Of course an intelligent debugger (GDB?) should be able to
7980 comprehend that a missing upper bound specification in a array
7981 type used for a storage class `auto' local array variable
7982 indicates that the upper bound is both unknown (at compile- time)
7983 and unknowable (at run-time) due to optimization.
7985 We assume that a MEM rtx is safe because gcc wouldn't put the
7986 value there unless it was going to be used repeatedly in the
7987 function, i.e. for cleanups. */
7988 if (! optimize || (SAVE_EXPR_RTL (bound)
7989 && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
7991 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7992 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7993 register rtx loc = SAVE_EXPR_RTL (bound);
7995 /* If the RTL for the SAVE_EXPR is memory, handle the case where
7996 it references an outer function's frame. */
7998 if (GET_CODE (loc) == MEM)
8000 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8002 if (XEXP (loc, 0) != new_addr)
8003 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8006 add_AT_flag (decl_die, DW_AT_artificial, 1);
8007 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8008 add_AT_location_description (decl_die, DW_AT_location, loc);
8009 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8012 /* Else leave out the attribute. */
8018 /* ??? These types of bounds can be created by the Ada front end,
8019 and it isn't clear how to emit debug info for them. */
8027 /* Note that the block of subscript information for an array type also
8028 includes information about the element type of type given array type. */
8031 add_subscript_info (type_die, type)
8032 register dw_die_ref type_die;
8035 #ifndef MIPS_DEBUGGING_INFO
8036 register unsigned dimension_number;
8038 register tree lower, upper;
8039 register dw_die_ref subrange_die;
8041 /* The GNU compilers represent multidimensional array types as sequences of
8042 one dimensional array types whose element types are themselves array
8043 types. Here we squish that down, so that each multidimensional array
8044 type gets only one array_type DIE in the Dwarf debugging info. The draft
8045 Dwarf specification say that we are allowed to do this kind of
8046 compression in C (because there is no difference between an array or
8047 arrays and a multidimensional array in C) but for other source languages
8048 (e.g. Ada) we probably shouldn't do this. */
8050 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8051 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8052 We work around this by disabling this feature. See also
8053 gen_array_type_die. */
8054 #ifndef MIPS_DEBUGGING_INFO
8055 for (dimension_number = 0;
8056 TREE_CODE (type) == ARRAY_TYPE;
8057 type = TREE_TYPE (type), dimension_number++)
8060 register tree domain = TYPE_DOMAIN (type);
8062 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8063 and (in GNU C only) variable bounds. Handle all three forms
8065 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8068 /* We have an array type with specified bounds. */
8069 lower = TYPE_MIN_VALUE (domain);
8070 upper = TYPE_MAX_VALUE (domain);
8072 /* define the index type. */
8073 if (TREE_TYPE (domain))
8075 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8076 TREE_TYPE field. We can't emit debug info for this
8077 because it is an unnamed integral type. */
8078 if (TREE_CODE (domain) == INTEGER_TYPE
8079 && TYPE_NAME (domain) == NULL_TREE
8080 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8081 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8084 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8088 /* ??? If upper is NULL, the array has unspecified length,
8089 but it does have a lower bound. This happens with Fortran
8091 Since the debugger is definitely going to need to know N
8092 to produce useful results, go ahead and output the lower
8093 bound solo, and hope the debugger can cope. */
8095 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8097 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8100 /* We have an array type with an unspecified length. The DWARF-2
8101 spec does not say how to handle this; let's just leave out the
8105 #ifndef MIPS_DEBUGGING_INFO
8111 add_byte_size_attribute (die, tree_node)
8113 register tree tree_node;
8115 register unsigned size;
8117 switch (TREE_CODE (tree_node))
8125 case QUAL_UNION_TYPE:
8126 size = int_size_in_bytes (tree_node);
8129 /* For a data member of a struct or union, the DW_AT_byte_size is
8130 generally given as the number of bytes normally allocated for an
8131 object of the *declared* type of the member itself. This is true
8132 even for bit-fields. */
8133 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8139 /* Note that `size' might be -1 when we get to this point. If it is, that
8140 indicates that the byte size of the entity in question is variable. We
8141 have no good way of expressing this fact in Dwarf at the present time,
8142 so just let the -1 pass on through. */
8144 add_AT_unsigned (die, DW_AT_byte_size, size);
8147 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8148 which specifies the distance in bits from the highest order bit of the
8149 "containing object" for the bit-field to the highest order bit of the
8152 For any given bit-field, the "containing object" is a hypothetical
8153 object (of some integral or enum type) within which the given bit-field
8154 lives. The type of this hypothetical "containing object" is always the
8155 same as the declared type of the individual bit-field itself. The
8156 determination of the exact location of the "containing object" for a
8157 bit-field is rather complicated. It's handled by the
8158 `field_byte_offset' function (above).
8160 Note that it is the size (in bytes) of the hypothetical "containing object"
8161 which will be given in the DW_AT_byte_size attribute for this bit-field.
8162 (See `byte_size_attribute' above). */
8165 add_bit_offset_attribute (die, decl)
8166 register dw_die_ref die;
8169 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8170 tree type = DECL_BIT_FIELD_TYPE (decl);
8171 HOST_WIDE_INT bitpos_int;
8172 HOST_WIDE_INT highest_order_object_bit_offset;
8173 HOST_WIDE_INT highest_order_field_bit_offset;
8174 HOST_WIDE_INT unsigned bit_offset;
8176 /* Must be a field and a bit field. */
8178 || TREE_CODE (decl) != FIELD_DECL)
8181 /* We can't yet handle bit-fields whose offsets are variable, so if we
8182 encounter such things, just return without generating any attribute
8183 whatsoever. Likewise for variable or too large size. */
8184 if (! host_integerp (bit_position (decl), 0)
8185 || ! host_integerp (DECL_SIZE (decl), 1))
8188 bitpos_int = int_bit_position (decl);
8190 /* Note that the bit offset is always the distance (in bits) from the
8191 highest-order bit of the "containing object" to the highest-order bit of
8192 the bit-field itself. Since the "high-order end" of any object or field
8193 is different on big-endian and little-endian machines, the computation
8194 below must take account of these differences. */
8195 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8196 highest_order_field_bit_offset = bitpos_int;
8198 if (! BYTES_BIG_ENDIAN)
8200 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8201 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8205 = (! BYTES_BIG_ENDIAN
8206 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8207 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8209 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8212 /* For a FIELD_DECL node which represents a bit field, output an attribute
8213 which specifies the length in bits of the given field. */
8216 add_bit_size_attribute (die, decl)
8217 register dw_die_ref die;
8220 /* Must be a field and a bit field. */
8221 if (TREE_CODE (decl) != FIELD_DECL
8222 || ! DECL_BIT_FIELD_TYPE (decl))
8225 if (host_integerp (DECL_SIZE (decl), 1))
8226 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8229 /* If the compiled language is ANSI C, then add a 'prototyped'
8230 attribute, if arg types are given for the parameters of a function. */
8233 add_prototyped_attribute (die, func_type)
8234 register dw_die_ref die;
8235 register tree func_type;
8237 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8238 && TYPE_ARG_TYPES (func_type) != NULL)
8239 add_AT_flag (die, DW_AT_prototyped, 1);
8242 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8243 by looking in either the type declaration or object declaration
8247 add_abstract_origin_attribute (die, origin)
8248 register dw_die_ref die;
8249 register tree origin;
8251 dw_die_ref origin_die = NULL;
8253 if (TREE_CODE (origin) != FUNCTION_DECL)
8255 /* We may have gotten separated from the block for the inlined
8256 function, if we're in an exception handler or some such; make
8257 sure that the abstract function has been written out.
8259 Doing this for nested functions is wrong, however; functions are
8260 distinct units, and our context might not even be inline. */
8263 fn = TYPE_STUB_DECL (fn);
8264 fn = decl_function_context (fn);
8266 gen_abstract_function (fn);
8269 if (DECL_P (origin))
8270 origin_die = lookup_decl_die (origin);
8271 else if (TYPE_P (origin))
8272 origin_die = lookup_type_die (origin);
8274 if (origin_die == NULL)
8277 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
8280 /* We do not currently support the pure_virtual attribute. */
8283 add_pure_or_virtual_attribute (die, func_decl)
8284 register dw_die_ref die;
8285 register tree func_decl;
8287 if (DECL_VINDEX (func_decl))
8289 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8291 if (host_integerp (DECL_VINDEX (func_decl), 0))
8292 add_AT_loc (die, DW_AT_vtable_elem_location,
8293 new_loc_descr (DW_OP_constu,
8294 tree_low_cst (DECL_VINDEX (func_decl), 0),
8297 /* GNU extension: Record what type this method came from originally. */
8298 if (debug_info_level > DINFO_LEVEL_TERSE)
8299 add_AT_die_ref (die, DW_AT_containing_type,
8300 lookup_type_die (DECL_CONTEXT (func_decl)));
8304 /* Add source coordinate attributes for the given decl. */
8307 add_src_coords_attributes (die, decl)
8308 register dw_die_ref die;
8311 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
8313 add_AT_unsigned (die, DW_AT_decl_file, file_index);
8314 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8317 /* Add an DW_AT_name attribute and source coordinate attribute for the
8318 given decl, but only if it actually has a name. */
8321 add_name_and_src_coords_attributes (die, decl)
8322 register dw_die_ref die;
8325 register tree decl_name;
8327 decl_name = DECL_NAME (decl);
8328 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
8330 add_name_attribute (die, dwarf2_name (decl, 0));
8331 if (! DECL_ARTIFICIAL (decl))
8332 add_src_coords_attributes (die, decl);
8334 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
8335 && TREE_PUBLIC (decl)
8336 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
8337 add_AT_string (die, DW_AT_MIPS_linkage_name,
8338 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
8342 /* Push a new declaration scope. */
8345 push_decl_scope (scope)
8348 /* Make room in the decl_scope_table, if necessary. */
8349 if (decl_scope_table_allocated == decl_scope_depth)
8351 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
8353 = (tree *) xrealloc (decl_scope_table,
8354 decl_scope_table_allocated * sizeof (tree));
8357 decl_scope_table[decl_scope_depth] = scope;
8361 /* Pop a declaration scope. */
8365 if (decl_scope_depth <= 0)
8370 /* Return the DIE for the scope that immediately contains this type.
8371 Non-named types get global scope. Named types nested in other
8372 types get their containing scope if it's open, or global scope
8373 otherwise. All other types (i.e. function-local named types) get
8374 the current active scope. */
8377 scope_die_for (t, context_die)
8379 register dw_die_ref context_die;
8381 register dw_die_ref scope_die = NULL;
8382 register tree containing_scope;
8385 /* Non-types always go in the current scope. */
8389 containing_scope = TYPE_CONTEXT (t);
8391 /* Ignore namespaces for the moment. */
8392 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
8393 containing_scope = NULL_TREE;
8395 /* Ignore function type "scopes" from the C frontend. They mean that
8396 a tagged type is local to a parmlist of a function declarator, but
8397 that isn't useful to DWARF. */
8398 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
8399 containing_scope = NULL_TREE;
8401 if (containing_scope == NULL_TREE)
8402 scope_die = comp_unit_die;
8403 else if (TYPE_P (containing_scope))
8405 /* For types, we can just look up the appropriate DIE. But
8406 first we check to see if we're in the middle of emitting it
8407 so we know where the new DIE should go. */
8409 for (i = decl_scope_depth - 1; i >= 0; --i)
8410 if (decl_scope_table[i] == containing_scope)
8415 if (debug_info_level > DINFO_LEVEL_TERSE
8416 && !TREE_ASM_WRITTEN (containing_scope))
8419 /* If none of the current dies are suitable, we get file scope. */
8420 scope_die = comp_unit_die;
8423 scope_die = lookup_type_die (containing_scope);
8426 scope_die = context_die;
8431 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
8433 static inline int local_scope_p PARAMS ((dw_die_ref));
8435 local_scope_p (context_die)
8436 dw_die_ref context_die;
8438 for (; context_die; context_die = context_die->die_parent)
8439 if (context_die->die_tag == DW_TAG_inlined_subroutine
8440 || context_die->die_tag == DW_TAG_subprogram)
8445 /* Returns nonzero iff CONTEXT_DIE is a class. */
8447 static inline int class_scope_p PARAMS ((dw_die_ref));
8449 class_scope_p (context_die)
8450 dw_die_ref context_die;
8453 && (context_die->die_tag == DW_TAG_structure_type
8454 || context_die->die_tag == DW_TAG_union_type));
8457 /* Many forms of DIEs require a "type description" attribute. This
8458 routine locates the proper "type descriptor" die for the type given
8459 by 'type', and adds an DW_AT_type attribute below the given die. */
8462 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
8463 register dw_die_ref object_die;
8465 register int decl_const;
8466 register int decl_volatile;
8467 register dw_die_ref context_die;
8469 register enum tree_code code = TREE_CODE (type);
8470 register dw_die_ref type_die = NULL;
8472 /* ??? If this type is an unnamed subrange type of an integral or
8473 floating-point type, use the inner type. This is because we have no
8474 support for unnamed types in base_type_die. This can happen if this is
8475 an Ada subrange type. Correct solution is emit a subrange type die. */
8476 if ((code == INTEGER_TYPE || code == REAL_TYPE)
8477 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
8478 type = TREE_TYPE (type), code = TREE_CODE (type);
8480 if (code == ERROR_MARK)
8483 /* Handle a special case. For functions whose return type is void, we
8484 generate *no* type attribute. (Note that no object may have type
8485 `void', so this only applies to function return types). */
8486 if (code == VOID_TYPE)
8489 type_die = modified_type_die (type,
8490 decl_const || TYPE_READONLY (type),
8491 decl_volatile || TYPE_VOLATILE (type),
8493 if (type_die != NULL)
8494 add_AT_die_ref (object_die, DW_AT_type, type_die);
8497 /* Given a tree pointer to a struct, class, union, or enum type node, return
8498 a pointer to the (string) tag name for the given type, or zero if the type
8499 was declared without a tag. */
8505 register const char *name = 0;
8507 if (TYPE_NAME (type) != 0)
8509 register tree t = 0;
8511 /* Find the IDENTIFIER_NODE for the type name. */
8512 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
8513 t = TYPE_NAME (type);
8515 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
8516 a TYPE_DECL node, regardless of whether or not a `typedef' was
8518 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8519 && ! DECL_IGNORED_P (TYPE_NAME (type)))
8520 t = DECL_NAME (TYPE_NAME (type));
8522 /* Now get the name as a string, or invent one. */
8524 name = IDENTIFIER_POINTER (t);
8527 return (name == 0 || *name == '\0') ? 0 : name;
8530 /* Return the type associated with a data member, make a special check
8531 for bit field types. */
8534 member_declared_type (member)
8535 register tree member;
8537 return (DECL_BIT_FIELD_TYPE (member)
8538 ? DECL_BIT_FIELD_TYPE (member)
8539 : TREE_TYPE (member));
8542 /* Get the decl's label, as described by its RTL. This may be different
8543 from the DECL_NAME name used in the source file. */
8547 decl_start_label (decl)
8552 x = DECL_RTL (decl);
8553 if (GET_CODE (x) != MEM)
8557 if (GET_CODE (x) != SYMBOL_REF)
8560 fnname = XSTR (x, 0);
8565 /* These routines generate the internal representation of the DIE's for
8566 the compilation unit. Debugging information is collected by walking
8567 the declaration trees passed in from dwarf2out_decl(). */
8570 gen_array_type_die (type, context_die)
8572 register dw_die_ref context_die;
8574 register dw_die_ref scope_die = scope_die_for (type, context_die);
8575 register dw_die_ref array_die;
8576 register tree element_type;
8578 /* ??? The SGI dwarf reader fails for array of array of enum types unless
8579 the inner array type comes before the outer array type. Thus we must
8580 call gen_type_die before we call new_die. See below also. */
8581 #ifdef MIPS_DEBUGGING_INFO
8582 gen_type_die (TREE_TYPE (type), context_die);
8585 array_die = new_die (DW_TAG_array_type, scope_die);
8588 /* We default the array ordering. SDB will probably do
8589 the right things even if DW_AT_ordering is not present. It's not even
8590 an issue until we start to get into multidimensional arrays anyway. If
8591 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
8592 then we'll have to put the DW_AT_ordering attribute back in. (But if
8593 and when we find out that we need to put these in, we will only do so
8594 for multidimensional arrays. */
8595 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
8598 #ifdef MIPS_DEBUGGING_INFO
8599 /* The SGI compilers handle arrays of unknown bound by setting
8600 AT_declaration and not emitting any subrange DIEs. */
8601 if (! TYPE_DOMAIN (type))
8602 add_AT_unsigned (array_die, DW_AT_declaration, 1);
8605 add_subscript_info (array_die, type);
8607 add_name_attribute (array_die, type_tag (type));
8608 equate_type_number_to_die (type, array_die);
8610 /* Add representation of the type of the elements of this array type. */
8611 element_type = TREE_TYPE (type);
8613 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8614 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8615 We work around this by disabling this feature. See also
8616 add_subscript_info. */
8617 #ifndef MIPS_DEBUGGING_INFO
8618 while (TREE_CODE (element_type) == ARRAY_TYPE)
8619 element_type = TREE_TYPE (element_type);
8621 gen_type_die (element_type, context_die);
8624 add_type_attribute (array_die, element_type, 0, 0, context_die);
8628 gen_set_type_die (type, context_die)
8630 register dw_die_ref context_die;
8632 register dw_die_ref type_die
8633 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
8635 equate_type_number_to_die (type, type_die);
8636 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
8641 gen_entry_point_die (decl, context_die)
8643 register dw_die_ref context_die;
8645 register tree origin = decl_ultimate_origin (decl);
8646 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
8648 add_abstract_origin_attribute (decl_die, origin);
8651 add_name_and_src_coords_attributes (decl_die, decl);
8652 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
8656 if (DECL_ABSTRACT (decl))
8657 equate_decl_number_to_die (decl, decl_die);
8659 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
8663 /* Remember a type in the incomplete_types_list. */
8666 add_incomplete_type (type)
8669 if (incomplete_types == incomplete_types_allocated)
8671 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
8672 incomplete_types_list
8673 = (tree *) xrealloc (incomplete_types_list,
8674 sizeof (tree) * incomplete_types_allocated);
8677 incomplete_types_list[incomplete_types++] = type;
8680 /* Walk through the list of incomplete types again, trying once more to
8681 emit full debugging info for them. */
8684 retry_incomplete_types ()
8688 while (incomplete_types)
8691 type = incomplete_types_list[incomplete_types];
8692 gen_type_die (type, comp_unit_die);
8696 /* Generate a DIE to represent an inlined instance of an enumeration type. */
8699 gen_inlined_enumeration_type_die (type, context_die)
8701 register dw_die_ref context_die;
8703 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
8705 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8706 be incomplete and such types are not marked. */
8707 add_abstract_origin_attribute (type_die, type);
8710 /* Generate a DIE to represent an inlined instance of a structure type. */
8713 gen_inlined_structure_type_die (type, context_die)
8715 register dw_die_ref context_die;
8717 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
8719 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8720 be incomplete and such types are not marked. */
8721 add_abstract_origin_attribute (type_die, type);
8724 /* Generate a DIE to represent an inlined instance of a union type. */
8727 gen_inlined_union_type_die (type, context_die)
8729 register dw_die_ref context_die;
8731 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
8733 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8734 be incomplete and such types are not marked. */
8735 add_abstract_origin_attribute (type_die, type);
8738 /* Generate a DIE to represent an enumeration type. Note that these DIEs
8739 include all of the information about the enumeration values also. Each
8740 enumerated type name/value is listed as a child of the enumerated type
8744 gen_enumeration_type_die (type, context_die)
8746 register dw_die_ref context_die;
8748 register dw_die_ref type_die = lookup_type_die (type);
8750 if (type_die == NULL)
8752 type_die = new_die (DW_TAG_enumeration_type,
8753 scope_die_for (type, context_die));
8754 equate_type_number_to_die (type, type_die);
8755 add_name_attribute (type_die, type_tag (type));
8757 else if (! TYPE_SIZE (type))
8760 remove_AT (type_die, DW_AT_declaration);
8762 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
8763 given enum type is incomplete, do not generate the DW_AT_byte_size
8764 attribute or the DW_AT_element_list attribute. */
8765 if (TYPE_SIZE (type))
8769 TREE_ASM_WRITTEN (type) = 1;
8770 add_byte_size_attribute (type_die, type);
8771 if (TYPE_STUB_DECL (type) != NULL_TREE)
8772 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8774 /* If the first reference to this type was as the return type of an
8775 inline function, then it may not have a parent. Fix this now. */
8776 if (type_die->die_parent == NULL)
8777 add_child_die (scope_die_for (type, context_die), type_die);
8779 for (link = TYPE_FIELDS (type);
8780 link != NULL; link = TREE_CHAIN (link))
8782 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
8784 add_name_attribute (enum_die,
8785 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
8787 if (host_integerp (TREE_VALUE (link), 0))
8789 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
8790 add_AT_int (enum_die, DW_AT_const_value,
8791 tree_low_cst (TREE_VALUE (link), 0));
8793 add_AT_unsigned (enum_die, DW_AT_const_value,
8794 tree_low_cst (TREE_VALUE (link), 0));
8799 add_AT_flag (type_die, DW_AT_declaration, 1);
8802 /* Generate a DIE to represent either a real live formal parameter decl or to
8803 represent just the type of some formal parameter position in some function
8806 Note that this routine is a bit unusual because its argument may be a
8807 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
8808 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
8809 node. If it's the former then this function is being called to output a
8810 DIE to represent a formal parameter object (or some inlining thereof). If
8811 it's the latter, then this function is only being called to output a
8812 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
8813 argument type of some subprogram type. */
8816 gen_formal_parameter_die (node, context_die)
8818 register dw_die_ref context_die;
8820 register dw_die_ref parm_die
8821 = new_die (DW_TAG_formal_parameter, context_die);
8822 register tree origin;
8824 switch (TREE_CODE_CLASS (TREE_CODE (node)))
8827 origin = decl_ultimate_origin (node);
8829 add_abstract_origin_attribute (parm_die, origin);
8832 add_name_and_src_coords_attributes (parm_die, node);
8833 add_type_attribute (parm_die, TREE_TYPE (node),
8834 TREE_READONLY (node),
8835 TREE_THIS_VOLATILE (node),
8837 if (DECL_ARTIFICIAL (node))
8838 add_AT_flag (parm_die, DW_AT_artificial, 1);
8841 equate_decl_number_to_die (node, parm_die);
8842 if (! DECL_ABSTRACT (node))
8843 add_location_or_const_value_attribute (parm_die, node);
8848 /* We were called with some kind of a ..._TYPE node. */
8849 add_type_attribute (parm_die, node, 0, 0, context_die);
8859 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
8860 at the end of an (ANSI prototyped) formal parameters list. */
8863 gen_unspecified_parameters_die (decl_or_type, context_die)
8864 register tree decl_or_type ATTRIBUTE_UNUSED;
8865 register dw_die_ref context_die;
8867 new_die (DW_TAG_unspecified_parameters, context_die);
8870 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
8871 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
8872 parameters as specified in some function type specification (except for
8873 those which appear as part of a function *definition*). */
8876 gen_formal_types_die (function_or_method_type, context_die)
8877 register tree function_or_method_type;
8878 register dw_die_ref context_die;
8881 register tree formal_type = NULL;
8882 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
8885 /* In the case where we are generating a formal types list for a C++
8886 non-static member function type, skip over the first thing on the
8887 TYPE_ARG_TYPES list because it only represents the type of the hidden
8888 `this pointer'. The debugger should be able to figure out (without
8889 being explicitly told) that this non-static member function type takes a
8890 `this pointer' and should be able to figure what the type of that hidden
8891 parameter is from the DW_AT_member attribute of the parent
8892 DW_TAG_subroutine_type DIE. */
8893 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
8894 first_parm_type = TREE_CHAIN (first_parm_type);
8897 /* Make our first pass over the list of formal parameter types and output a
8898 DW_TAG_formal_parameter DIE for each one. */
8899 for (link = first_parm_type; link; link = TREE_CHAIN (link))
8901 register dw_die_ref parm_die;
8903 formal_type = TREE_VALUE (link);
8904 if (formal_type == void_type_node)
8907 /* Output a (nameless) DIE to represent the formal parameter itself. */
8908 parm_die = gen_formal_parameter_die (formal_type, context_die);
8909 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8910 && link == first_parm_type)
8911 add_AT_flag (parm_die, DW_AT_artificial, 1);
8914 /* If this function type has an ellipsis, add a
8915 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8916 if (formal_type != void_type_node)
8917 gen_unspecified_parameters_die (function_or_method_type, context_die);
8919 /* Make our second (and final) pass over the list of formal parameter types
8920 and output DIEs to represent those types (as necessary). */
8921 for (link = TYPE_ARG_TYPES (function_or_method_type);
8923 link = TREE_CHAIN (link))
8925 formal_type = TREE_VALUE (link);
8926 if (formal_type == void_type_node)
8929 gen_type_die (formal_type, context_die);
8933 /* We want to generate the DIE for TYPE so that we can generate the
8934 die for MEMBER, which has been defined; we will need to refer back
8935 to the member declaration nested within TYPE. If we're trying to
8936 generate minimal debug info for TYPE, processing TYPE won't do the
8937 trick; we need to attach the member declaration by hand. */
8940 gen_type_die_for_member (type, member, context_die)
8942 dw_die_ref context_die;
8944 gen_type_die (type, context_die);
8946 /* If we're trying to avoid duplicate debug info, we may not have
8947 emitted the member decl for this function. Emit it now. */
8948 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
8949 && ! lookup_decl_die (member))
8951 if (decl_ultimate_origin (member))
8954 push_decl_scope (type);
8955 if (TREE_CODE (member) == FUNCTION_DECL)
8956 gen_subprogram_die (member, lookup_type_die (type));
8958 gen_variable_die (member, lookup_type_die (type));
8963 /* Generate the DWARF2 info for the "abstract" instance
8964 of a function which we may later generate inlined and/or
8965 out-of-line instances of. */
8968 gen_abstract_function (decl)
8971 register dw_die_ref old_die = lookup_decl_die (decl);
8974 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
8975 /* We've already generated the abstract instance. */
8978 save_fn = current_function_decl;
8979 current_function_decl = decl;
8981 set_decl_abstract_flags (decl, 1);
8982 dwarf2out_decl (decl);
8983 set_decl_abstract_flags (decl, 0);
8985 current_function_decl = save_fn;
8988 /* Generate a DIE to represent a declared function (either file-scope or
8992 gen_subprogram_die (decl, context_die)
8994 register dw_die_ref context_die;
8996 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
8997 register tree origin = decl_ultimate_origin (decl);
8998 register dw_die_ref subr_die;
8999 register rtx fp_reg;
9000 register tree fn_arg_types;
9001 register tree outer_scope;
9002 register dw_die_ref old_die = lookup_decl_die (decl);
9003 register int declaration = (current_function_decl != decl
9004 || class_scope_p (context_die));
9006 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9007 be true, if we started to generate the abstract instance of an inline,
9008 decided to output its containing class, and proceeded to emit the
9009 declaration of the inline from the member list for the class. In that
9010 case, `declaration' takes priority; we'll get back to the abstract
9011 instance when we're done with the class. */
9013 /* The class-scope declaration DIE must be the primary DIE. */
9014 if (origin && declaration && class_scope_p (context_die))
9023 if (declaration && ! local_scope_p (context_die))
9026 /* Fixup die_parent for the abstract instance of a nested
9028 if (old_die && old_die->die_parent == NULL)
9029 add_child_die (context_die, old_die);
9031 subr_die = new_die (DW_TAG_subprogram, context_die);
9032 add_abstract_origin_attribute (subr_die, origin);
9034 else if (old_die && DECL_ABSTRACT (decl)
9035 && get_AT_unsigned (old_die, DW_AT_inline))
9037 /* This must be a redefinition of an extern inline function.
9038 We can just reuse the old die here. */
9041 /* Clear out the inlined attribute and parm types. */
9042 remove_AT (subr_die, DW_AT_inline);
9043 remove_children (subr_die);
9047 register unsigned file_index
9048 = lookup_filename (DECL_SOURCE_FILE (decl));
9050 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
9052 /* ??? This can happen if there is a bug in the program, for
9053 instance, if it has duplicate function definitions. Ideally,
9054 we should detect this case and ignore it. For now, if we have
9055 already reported an error, any error at all, then assume that
9056 we got here because of a input error, not a dwarf2 bug. */
9062 /* If the definition comes from the same place as the declaration,
9063 maybe use the old DIE. We always want the DIE for this function
9064 that has the *_pc attributes to be under comp_unit_die so the
9065 debugger can find it. For inlines, that is the concrete instance,
9066 so we can use the old DIE here. For non-inline methods, we want a
9067 specification DIE at toplevel, so we need a new DIE. For local
9068 class methods, this doesn't apply; we just use the old DIE. */
9069 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
9070 || context_die == NULL)
9071 && (DECL_ARTIFICIAL (decl)
9072 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9073 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9074 == (unsigned) DECL_SOURCE_LINE (decl)))))
9078 /* Clear out the declaration attribute and the parm types. */
9079 remove_AT (subr_die, DW_AT_declaration);
9080 remove_children (subr_die);
9084 subr_die = new_die (DW_TAG_subprogram, context_die);
9085 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9086 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9087 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9088 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9089 != (unsigned) DECL_SOURCE_LINE (decl))
9091 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9096 subr_die = new_die (DW_TAG_subprogram, context_die);
9098 if (TREE_PUBLIC (decl))
9099 add_AT_flag (subr_die, DW_AT_external, 1);
9101 add_name_and_src_coords_attributes (subr_die, decl);
9102 if (debug_info_level > DINFO_LEVEL_TERSE)
9104 register tree type = TREE_TYPE (decl);
9106 add_prototyped_attribute (subr_die, type);
9107 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9110 add_pure_or_virtual_attribute (subr_die, decl);
9111 if (DECL_ARTIFICIAL (decl))
9112 add_AT_flag (subr_die, DW_AT_artificial, 1);
9113 if (TREE_PROTECTED (decl))
9114 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9115 else if (TREE_PRIVATE (decl))
9116 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9122 add_AT_flag (subr_die, DW_AT_declaration, 1);
9124 /* The first time we see a member function, it is in the context of
9125 the class to which it belongs. We make sure of this by emitting
9126 the class first. The next time is the definition, which is
9127 handled above. The two may come from the same source text. */
9128 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9129 equate_decl_number_to_die (decl, subr_die);
9131 else if (DECL_ABSTRACT (decl))
9133 if (DECL_INLINE (decl) && !flag_no_inline)
9135 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9136 inline functions, but not for extern inline functions.
9137 We can't get this completely correct because information
9138 about whether the function was declared inline is not
9140 if (DECL_DEFER_OUTPUT (decl))
9141 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9143 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9146 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9148 equate_decl_number_to_die (decl, subr_die);
9150 else if (!DECL_EXTERNAL (decl))
9152 if (origin == NULL_TREE)
9153 equate_decl_number_to_die (decl, subr_die);
9155 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9156 current_funcdef_number);
9157 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9158 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9159 current_funcdef_number);
9160 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9162 add_pubname (decl, subr_die);
9163 add_arange (decl, subr_die);
9165 #ifdef MIPS_DEBUGGING_INFO
9166 /* Add a reference to the FDE for this routine. */
9167 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9170 /* Define the "frame base" location for this routine. We use the
9171 frame pointer or stack pointer registers, since the RTL for local
9172 variables is relative to one of them. */
9174 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9175 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9178 /* ??? This fails for nested inline functions, because context_display
9179 is not part of the state saved/restored for inline functions. */
9180 if (current_function_needs_context)
9181 add_AT_location_description (subr_die, DW_AT_static_link,
9182 lookup_static_chain (decl));
9186 /* Now output descriptions of the arguments for this function. This gets
9187 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9188 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9189 `...' at the end of the formal parameter list. In order to find out if
9190 there was a trailing ellipsis or not, we must instead look at the type
9191 associated with the FUNCTION_DECL. This will be a node of type
9192 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9193 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9194 an ellipsis at the end. */
9196 /* In the case where we are describing a mere function declaration, all we
9197 need to do here (and all we *can* do here) is to describe the *types* of
9198 its formal parameters. */
9199 if (debug_info_level <= DINFO_LEVEL_TERSE)
9201 else if (declaration)
9202 gen_formal_types_die (TREE_TYPE (decl), subr_die);
9205 /* Generate DIEs to represent all known formal parameters */
9206 register tree arg_decls = DECL_ARGUMENTS (decl);
9209 /* When generating DIEs, generate the unspecified_parameters DIE
9210 instead if we come across the arg "__builtin_va_alist" */
9211 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9212 if (TREE_CODE (parm) == PARM_DECL)
9214 if (DECL_NAME (parm)
9215 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9216 "__builtin_va_alist"))
9217 gen_unspecified_parameters_die (parm, subr_die);
9219 gen_decl_die (parm, subr_die);
9222 /* Decide whether we need a unspecified_parameters DIE at the end.
9223 There are 2 more cases to do this for: 1) the ansi ... declaration -
9224 this is detectable when the end of the arg list is not a
9225 void_type_node 2) an unprototyped function declaration (not a
9226 definition). This just means that we have no info about the
9227 parameters at all. */
9228 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9229 if (fn_arg_types != NULL)
9231 /* this is the prototyped case, check for ... */
9232 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9233 gen_unspecified_parameters_die (decl, subr_die);
9235 else if (DECL_INITIAL (decl) == NULL_TREE)
9236 gen_unspecified_parameters_die (decl, subr_die);
9239 /* Output Dwarf info for all of the stuff within the body of the function
9240 (if it has one - it may be just a declaration). */
9241 outer_scope = DECL_INITIAL (decl);
9243 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9244 node created to represent a function. This outermost BLOCK actually
9245 represents the outermost binding contour for the function, i.e. the
9246 contour in which the function's formal parameters and labels get
9247 declared. Curiously, it appears that the front end doesn't actually
9248 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9249 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9250 list for the function instead.) The BLOCK_VARS list for the
9251 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9252 the function however, and we output DWARF info for those in
9253 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9254 node representing the function's outermost pair of curly braces, and
9255 any blocks used for the base and member initializers of a C++
9256 constructor function. */
9257 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
9259 current_function_has_inlines = 0;
9260 decls_for_scope (outer_scope, subr_die, 0);
9262 #if 0 && defined (MIPS_DEBUGGING_INFO)
9263 if (current_function_has_inlines)
9265 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
9266 if (! comp_unit_has_inlines)
9268 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
9269 comp_unit_has_inlines = 1;
9276 /* Generate a DIE to represent a declared data object. */
9279 gen_variable_die (decl, context_die)
9281 register dw_die_ref context_die;
9283 register tree origin = decl_ultimate_origin (decl);
9284 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
9286 dw_die_ref old_die = lookup_decl_die (decl);
9287 int declaration = (DECL_EXTERNAL (decl)
9288 || class_scope_p (context_die));
9291 add_abstract_origin_attribute (var_die, origin);
9292 /* Loop unrolling can create multiple blocks that refer to the same
9293 static variable, so we must test for the DW_AT_declaration flag. */
9294 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
9295 copy decls and set the DECL_ABSTRACT flag on them instead of
9297 else if (old_die && TREE_STATIC (decl)
9298 && get_AT_flag (old_die, DW_AT_declaration) == 1)
9300 /* This is a definition of a C++ class level static. */
9301 add_AT_die_ref (var_die, DW_AT_specification, old_die);
9302 if (DECL_NAME (decl))
9304 register unsigned file_index
9305 = lookup_filename (DECL_SOURCE_FILE (decl));
9307 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9308 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
9310 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9311 != (unsigned) DECL_SOURCE_LINE (decl))
9313 add_AT_unsigned (var_die, DW_AT_decl_line,
9314 DECL_SOURCE_LINE (decl));
9319 add_name_and_src_coords_attributes (var_die, decl);
9320 add_type_attribute (var_die, TREE_TYPE (decl),
9321 TREE_READONLY (decl),
9322 TREE_THIS_VOLATILE (decl), context_die);
9324 if (TREE_PUBLIC (decl))
9325 add_AT_flag (var_die, DW_AT_external, 1);
9327 if (DECL_ARTIFICIAL (decl))
9328 add_AT_flag (var_die, DW_AT_artificial, 1);
9330 if (TREE_PROTECTED (decl))
9331 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
9333 else if (TREE_PRIVATE (decl))
9334 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
9338 add_AT_flag (var_die, DW_AT_declaration, 1);
9340 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
9341 equate_decl_number_to_die (decl, var_die);
9343 if (! declaration && ! DECL_ABSTRACT (decl))
9345 add_location_or_const_value_attribute (var_die, decl);
9346 add_pubname (decl, var_die);
9350 /* Generate a DIE to represent a label identifier. */
9353 gen_label_die (decl, context_die)
9355 register dw_die_ref context_die;
9357 register tree origin = decl_ultimate_origin (decl);
9358 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
9360 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9361 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
9364 add_abstract_origin_attribute (lbl_die, origin);
9366 add_name_and_src_coords_attributes (lbl_die, decl);
9368 if (DECL_ABSTRACT (decl))
9369 equate_decl_number_to_die (decl, lbl_die);
9372 insn = DECL_RTL (decl);
9374 /* Deleted labels are programmer specified labels which have been
9375 eliminated because of various optimisations. We still emit them
9376 here so that it is possible to put breakpoints on them. */
9377 if (GET_CODE (insn) == CODE_LABEL
9378 || ((GET_CODE (insn) == NOTE
9379 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
9381 /* When optimization is enabled (via -O) some parts of the compiler
9382 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
9383 represent source-level labels which were explicitly declared by
9384 the user. This really shouldn't be happening though, so catch
9385 it if it ever does happen. */
9386 if (INSN_DELETED_P (insn))
9389 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
9390 ASM_GENERATE_INTERNAL_LABEL (label, label2,
9391 (unsigned) INSN_UID (insn));
9392 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
9397 /* Generate a DIE for a lexical block. */
9400 gen_lexical_block_die (stmt, context_die, depth)
9402 register dw_die_ref context_die;
9405 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
9406 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9408 if (! BLOCK_ABSTRACT (stmt))
9410 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9411 BLOCK_NUMBER (stmt));
9412 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
9413 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9414 BLOCK_NUMBER (stmt));
9415 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
9418 decls_for_scope (stmt, stmt_die, depth);
9421 /* Generate a DIE for an inlined subprogram. */
9424 gen_inlined_subroutine_die (stmt, context_die, depth)
9426 register dw_die_ref context_die;
9429 if (! BLOCK_ABSTRACT (stmt))
9431 register dw_die_ref subr_die
9432 = new_die (DW_TAG_inlined_subroutine, context_die);
9433 register tree decl = block_ultimate_origin (stmt);
9434 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9436 /* Emit info for the abstract instance first, if we haven't yet. */
9437 gen_abstract_function (decl);
9439 add_abstract_origin_attribute (subr_die, decl);
9440 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9441 BLOCK_NUMBER (stmt));
9442 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
9443 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9444 BLOCK_NUMBER (stmt));
9445 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
9446 decls_for_scope (stmt, subr_die, depth);
9447 current_function_has_inlines = 1;
9451 /* Generate a DIE for a field in a record, or structure. */
9454 gen_field_die (decl, context_die)
9456 register dw_die_ref context_die;
9458 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
9460 add_name_and_src_coords_attributes (decl_die, decl);
9461 add_type_attribute (decl_die, member_declared_type (decl),
9462 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
9465 /* If this is a bit field... */
9466 if (DECL_BIT_FIELD_TYPE (decl))
9468 add_byte_size_attribute (decl_die, decl);
9469 add_bit_size_attribute (decl_die, decl);
9470 add_bit_offset_attribute (decl_die, decl);
9473 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
9474 add_data_member_location_attribute (decl_die, decl);
9476 if (DECL_ARTIFICIAL (decl))
9477 add_AT_flag (decl_die, DW_AT_artificial, 1);
9479 if (TREE_PROTECTED (decl))
9480 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
9482 else if (TREE_PRIVATE (decl))
9483 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
9487 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9488 Use modified_type_die instead.
9489 We keep this code here just in case these types of DIEs may be needed to
9490 represent certain things in other languages (e.g. Pascal) someday. */
9492 gen_pointer_type_die (type, context_die)
9494 register dw_die_ref context_die;
9496 register dw_die_ref ptr_die
9497 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
9499 equate_type_number_to_die (type, ptr_die);
9500 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9501 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9504 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9505 Use modified_type_die instead.
9506 We keep this code here just in case these types of DIEs may be needed to
9507 represent certain things in other languages (e.g. Pascal) someday. */
9509 gen_reference_type_die (type, context_die)
9511 register dw_die_ref context_die;
9513 register dw_die_ref ref_die
9514 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
9516 equate_type_number_to_die (type, ref_die);
9517 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
9518 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9522 /* Generate a DIE for a pointer to a member type. */
9524 gen_ptr_to_mbr_type_die (type, context_die)
9526 register dw_die_ref context_die;
9528 register dw_die_ref ptr_die
9529 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
9531 equate_type_number_to_die (type, ptr_die);
9532 add_AT_die_ref (ptr_die, DW_AT_containing_type,
9533 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
9534 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9537 /* Generate the DIE for the compilation unit. */
9540 gen_compile_unit_die (filename)
9541 register const char *filename;
9543 register dw_die_ref die;
9545 const char *wd = getpwd ();
9548 die = new_die (DW_TAG_compile_unit, NULL);
9549 add_name_attribute (die, filename);
9551 if (wd != NULL && filename[0] != DIR_SEPARATOR)
9552 add_AT_string (die, DW_AT_comp_dir, wd);
9554 sprintf (producer, "%s %s", language_string, version_string);
9556 #ifdef MIPS_DEBUGGING_INFO
9557 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
9558 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
9559 not appear in the producer string, the debugger reaches the conclusion
9560 that the object file is stripped and has no debugging information.
9561 To get the MIPS/SGI debugger to believe that there is debugging
9562 information in the object file, we add a -g to the producer string. */
9563 if (debug_info_level > DINFO_LEVEL_TERSE)
9564 strcat (producer, " -g");
9567 add_AT_string (die, DW_AT_producer, producer);
9569 if (strcmp (language_string, "GNU C++") == 0)
9570 language = DW_LANG_C_plus_plus;
9571 else if (strcmp (language_string, "GNU Ada") == 0)
9572 language = DW_LANG_Ada83;
9573 else if (strcmp (language_string, "GNU F77") == 0)
9574 language = DW_LANG_Fortran77;
9575 else if (strcmp (language_string, "GNU Pascal") == 0)
9576 language = DW_LANG_Pascal83;
9577 else if (strcmp (language_string, "GNU Java") == 0)
9578 language = DW_LANG_Java;
9579 else if (flag_traditional)
9580 language = DW_LANG_C;
9582 language = DW_LANG_C89;
9584 add_AT_unsigned (die, DW_AT_language, language);
9589 /* Generate a DIE for a string type. */
9592 gen_string_type_die (type, context_die)
9594 register dw_die_ref context_die;
9596 register dw_die_ref type_die
9597 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
9599 equate_type_number_to_die (type, type_die);
9601 /* Fudge the string length attribute for now. */
9603 /* TODO: add string length info.
9604 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
9605 bound_representation (upper_bound, 0, 'u'); */
9608 /* Generate the DIE for a base class. */
9611 gen_inheritance_die (binfo, context_die)
9612 register tree binfo;
9613 register dw_die_ref context_die;
9615 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
9617 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
9618 add_data_member_location_attribute (die, binfo);
9620 if (TREE_VIA_VIRTUAL (binfo))
9621 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9622 if (TREE_VIA_PUBLIC (binfo))
9623 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
9624 else if (TREE_VIA_PROTECTED (binfo))
9625 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
9628 /* Generate a DIE for a class member. */
9631 gen_member_die (type, context_die)
9633 register dw_die_ref context_die;
9635 register tree member;
9638 /* If this is not an incomplete type, output descriptions of each of its
9639 members. Note that as we output the DIEs necessary to represent the
9640 members of this record or union type, we will also be trying to output
9641 DIEs to represent the *types* of those members. However the `type'
9642 function (above) will specifically avoid generating type DIEs for member
9643 types *within* the list of member DIEs for this (containing) type execpt
9644 for those types (of members) which are explicitly marked as also being
9645 members of this (containing) type themselves. The g++ front- end can
9646 force any given type to be treated as a member of some other
9647 (containing) type by setting the TYPE_CONTEXT of the given (member) type
9648 to point to the TREE node representing the appropriate (containing)
9651 /* First output info about the base classes. */
9652 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
9654 register tree bases = TYPE_BINFO_BASETYPES (type);
9655 register int n_bases = TREE_VEC_LENGTH (bases);
9658 for (i = 0; i < n_bases; i++)
9659 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
9662 /* Now output info about the data members and type members. */
9663 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
9665 /* If we thought we were generating minimal debug info for TYPE
9666 and then changed our minds, some of the member declarations
9667 may have already been defined. Don't define them again, but
9668 do put them in the right order. */
9670 child = lookup_decl_die (member);
9672 splice_child_die (context_die, child);
9674 gen_decl_die (member, context_die);
9677 /* Now output info about the function members (if any). */
9678 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
9680 child = lookup_decl_die (member);
9682 splice_child_die (context_die, child);
9684 gen_decl_die (member, context_die);
9688 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
9689 is set, we pretend that the type was never defined, so we only get the
9690 member DIEs needed by later specification DIEs. */
9693 gen_struct_or_union_type_die (type, context_die)
9695 register dw_die_ref context_die;
9697 register dw_die_ref type_die = lookup_type_die (type);
9698 register dw_die_ref scope_die = 0;
9699 register int nested = 0;
9700 int complete = (TYPE_SIZE (type)
9701 && (! TYPE_STUB_DECL (type)
9702 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
9704 if (type_die && ! complete)
9707 if (TYPE_CONTEXT (type) != NULL_TREE
9708 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
9711 scope_die = scope_die_for (type, context_die);
9713 if (! type_die || (nested && scope_die == comp_unit_die))
9714 /* First occurrence of type or toplevel definition of nested class. */
9716 register dw_die_ref old_die = type_die;
9718 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
9719 ? DW_TAG_structure_type : DW_TAG_union_type,
9721 equate_type_number_to_die (type, type_die);
9723 add_AT_die_ref (type_die, DW_AT_specification, old_die);
9725 add_name_attribute (type_die, type_tag (type));
9728 remove_AT (type_die, DW_AT_declaration);
9730 /* If this type has been completed, then give it a byte_size attribute and
9731 then give a list of members. */
9734 /* Prevent infinite recursion in cases where the type of some member of
9735 this type is expressed in terms of this type itself. */
9736 TREE_ASM_WRITTEN (type) = 1;
9737 add_byte_size_attribute (type_die, type);
9738 if (TYPE_STUB_DECL (type) != NULL_TREE)
9739 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9741 /* If the first reference to this type was as the return type of an
9742 inline function, then it may not have a parent. Fix this now. */
9743 if (type_die->die_parent == NULL)
9744 add_child_die (scope_die, type_die);
9746 push_decl_scope (type);
9747 gen_member_die (type, type_die);
9750 /* GNU extension: Record what type our vtable lives in. */
9751 if (TYPE_VFIELD (type))
9753 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
9755 gen_type_die (vtype, context_die);
9756 add_AT_die_ref (type_die, DW_AT_containing_type,
9757 lookup_type_die (vtype));
9762 add_AT_flag (type_die, DW_AT_declaration, 1);
9764 /* We don't need to do this for function-local types. */
9765 if (! decl_function_context (TYPE_STUB_DECL (type)))
9766 add_incomplete_type (type);
9770 /* Generate a DIE for a subroutine _type_. */
9773 gen_subroutine_type_die (type, context_die)
9775 register dw_die_ref context_die;
9777 register tree return_type = TREE_TYPE (type);
9778 register dw_die_ref subr_die
9779 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
9781 equate_type_number_to_die (type, subr_die);
9782 add_prototyped_attribute (subr_die, type);
9783 add_type_attribute (subr_die, return_type, 0, 0, context_die);
9784 gen_formal_types_die (type, subr_die);
9787 /* Generate a DIE for a type definition */
9790 gen_typedef_die (decl, context_die)
9792 register dw_die_ref context_die;
9794 register dw_die_ref type_die;
9795 register tree origin;
9797 if (TREE_ASM_WRITTEN (decl))
9799 TREE_ASM_WRITTEN (decl) = 1;
9801 type_die = new_die (DW_TAG_typedef, context_die);
9802 origin = decl_ultimate_origin (decl);
9804 add_abstract_origin_attribute (type_die, origin);
9808 add_name_and_src_coords_attributes (type_die, decl);
9809 if (DECL_ORIGINAL_TYPE (decl))
9811 type = DECL_ORIGINAL_TYPE (decl);
9813 if (type == TREE_TYPE (decl))
9816 equate_type_number_to_die (TREE_TYPE (decl), type_die);
9819 type = TREE_TYPE (decl);
9820 add_type_attribute (type_die, type, TREE_READONLY (decl),
9821 TREE_THIS_VOLATILE (decl), context_die);
9824 if (DECL_ABSTRACT (decl))
9825 equate_decl_number_to_die (decl, type_die);
9828 /* Generate a type description DIE. */
9831 gen_type_die (type, context_die)
9833 register dw_die_ref context_die;
9837 if (type == NULL_TREE || type == error_mark_node)
9840 /* We are going to output a DIE to represent the unqualified version of
9841 this type (i.e. without any const or volatile qualifiers) so get the
9842 main variant (i.e. the unqualified version) of this type now. */
9843 type = type_main_variant (type);
9845 if (TREE_ASM_WRITTEN (type))
9848 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9849 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
9851 TREE_ASM_WRITTEN (type) = 1;
9852 gen_decl_die (TYPE_NAME (type), context_die);
9856 switch (TREE_CODE (type))
9862 case REFERENCE_TYPE:
9863 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
9864 ensures that the gen_type_die recursion will terminate even if the
9865 type is recursive. Recursive types are possible in Ada. */
9866 /* ??? We could perhaps do this for all types before the switch
9868 TREE_ASM_WRITTEN (type) = 1;
9870 /* For these types, all that is required is that we output a DIE (or a
9871 set of DIEs) to represent the "basis" type. */
9872 gen_type_die (TREE_TYPE (type), context_die);
9876 /* This code is used for C++ pointer-to-data-member types.
9877 Output a description of the relevant class type. */
9878 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
9880 /* Output a description of the type of the object pointed to. */
9881 gen_type_die (TREE_TYPE (type), context_die);
9883 /* Now output a DIE to represent this pointer-to-data-member type
9885 gen_ptr_to_mbr_type_die (type, context_die);
9889 gen_type_die (TYPE_DOMAIN (type), context_die);
9890 gen_set_type_die (type, context_die);
9894 gen_type_die (TREE_TYPE (type), context_die);
9895 abort (); /* No way to represent these in Dwarf yet! */
9899 /* Force out return type (in case it wasn't forced out already). */
9900 gen_type_die (TREE_TYPE (type), context_die);
9901 gen_subroutine_type_die (type, context_die);
9905 /* Force out return type (in case it wasn't forced out already). */
9906 gen_type_die (TREE_TYPE (type), context_die);
9907 gen_subroutine_type_die (type, context_die);
9911 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
9913 gen_type_die (TREE_TYPE (type), context_die);
9914 gen_string_type_die (type, context_die);
9917 gen_array_type_die (type, context_die);
9921 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
9927 case QUAL_UNION_TYPE:
9928 /* If this is a nested type whose containing class hasn't been
9929 written out yet, writing it out will cover this one, too.
9930 This does not apply to instantiations of member class templates;
9931 they need to be added to the containing class as they are
9932 generated. FIXME: This hurts the idea of combining type decls
9933 from multiple TUs, since we can't predict what set of template
9934 instantiations we'll get. */
9935 if (TYPE_CONTEXT (type)
9936 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9937 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9939 gen_type_die (TYPE_CONTEXT (type), context_die);
9941 if (TREE_ASM_WRITTEN (type))
9944 /* If that failed, attach ourselves to the stub. */
9945 push_decl_scope (TYPE_CONTEXT (type));
9946 context_die = lookup_type_die (TYPE_CONTEXT (type));
9952 if (TREE_CODE (type) == ENUMERAL_TYPE)
9953 gen_enumeration_type_die (type, context_die);
9955 gen_struct_or_union_type_die (type, context_die);
9960 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9961 it up if it is ever completed. gen_*_type_die will set it for us
9962 when appropriate. */
9971 /* No DIEs needed for fundamental types. */
9975 /* No Dwarf representation currently defined. */
9982 TREE_ASM_WRITTEN (type) = 1;
9985 /* Generate a DIE for a tagged type instantiation. */
9988 gen_tagged_type_instantiation_die (type, context_die)
9990 register dw_die_ref context_die;
9992 if (type == NULL_TREE || type == error_mark_node)
9995 /* We are going to output a DIE to represent the unqualified version of
9996 this type (i.e. without any const or volatile qualifiers) so make sure
9997 that we have the main variant (i.e. the unqualified version) of this
9999 if (type != type_main_variant (type))
10002 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10003 an instance of an unresolved type. */
10005 switch (TREE_CODE (type))
10010 case ENUMERAL_TYPE:
10011 gen_inlined_enumeration_type_die (type, context_die);
10015 gen_inlined_structure_type_die (type, context_die);
10019 case QUAL_UNION_TYPE:
10020 gen_inlined_union_type_die (type, context_die);
10028 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10029 things which are local to the given block. */
10032 gen_block_die (stmt, context_die, depth)
10033 register tree stmt;
10034 register dw_die_ref context_die;
10037 register int must_output_die = 0;
10038 register tree origin;
10039 register tree decl;
10040 register enum tree_code origin_code;
10042 /* Ignore blocks never really used to make RTL. */
10044 if (stmt == NULL_TREE || !TREE_USED (stmt)
10045 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10048 /* Determine the "ultimate origin" of this block. This block may be an
10049 inlined instance of an inlined instance of inline function, so we have
10050 to trace all of the way back through the origin chain to find out what
10051 sort of node actually served as the original seed for the creation of
10052 the current block. */
10053 origin = block_ultimate_origin (stmt);
10054 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10056 /* Determine if we need to output any Dwarf DIEs at all to represent this
10058 if (origin_code == FUNCTION_DECL)
10059 /* The outer scopes for inlinings *must* always be represented. We
10060 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10061 must_output_die = 1;
10064 /* In the case where the current block represents an inlining of the
10065 "body block" of an inline function, we must *NOT* output any DIE for
10066 this block because we have already output a DIE to represent the
10067 whole inlined function scope and the "body block" of any function
10068 doesn't really represent a different scope according to ANSI C
10069 rules. So we check here to make sure that this block does not
10070 represent a "body block inlining" before trying to set the
10071 `must_output_die' flag. */
10072 if (! is_body_block (origin ? origin : stmt))
10074 /* Determine if this block directly contains any "significant"
10075 local declarations which we will need to output DIEs for. */
10076 if (debug_info_level > DINFO_LEVEL_TERSE)
10077 /* We are not in terse mode so *any* local declaration counts
10078 as being a "significant" one. */
10079 must_output_die = (BLOCK_VARS (stmt) != NULL);
10081 /* We are in terse mode, so only local (nested) function
10082 definitions count as "significant" local declarations. */
10083 for (decl = BLOCK_VARS (stmt);
10084 decl != NULL; decl = TREE_CHAIN (decl))
10085 if (TREE_CODE (decl) == FUNCTION_DECL
10086 && DECL_INITIAL (decl))
10088 must_output_die = 1;
10094 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10095 DIE for any block which contains no significant local declarations at
10096 all. Rather, in such cases we just call `decls_for_scope' so that any
10097 needed Dwarf info for any sub-blocks will get properly generated. Note
10098 that in terse mode, our definition of what constitutes a "significant"
10099 local declaration gets restricted to include only inlined function
10100 instances and local (nested) function definitions. */
10101 if (must_output_die)
10103 if (origin_code == FUNCTION_DECL)
10104 gen_inlined_subroutine_die (stmt, context_die, depth);
10106 gen_lexical_block_die (stmt, context_die, depth);
10109 decls_for_scope (stmt, context_die, depth);
10112 /* Generate all of the decls declared within a given scope and (recursively)
10113 all of its sub-blocks. */
10116 decls_for_scope (stmt, context_die, depth)
10117 register tree stmt;
10118 register dw_die_ref context_die;
10121 register tree decl;
10122 register tree subblocks;
10124 /* Ignore blocks never really used to make RTL. */
10125 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10128 /* Output the DIEs to represent all of the data objects and typedefs
10129 declared directly within this block but not within any nested
10130 sub-blocks. Also, nested function and tag DIEs have been
10131 generated with a parent of NULL; fix that up now. */
10132 for (decl = BLOCK_VARS (stmt);
10133 decl != NULL; decl = TREE_CHAIN (decl))
10135 register dw_die_ref die;
10137 if (TREE_CODE (decl) == FUNCTION_DECL)
10138 die = lookup_decl_die (decl);
10139 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10140 die = lookup_type_die (TREE_TYPE (decl));
10144 if (die != NULL && die->die_parent == NULL)
10145 add_child_die (context_die, die);
10147 gen_decl_die (decl, context_die);
10150 /* Output the DIEs to represent all sub-blocks (and the items declared
10151 therein) of this block. */
10152 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10154 subblocks = BLOCK_CHAIN (subblocks))
10155 gen_block_die (subblocks, context_die, depth + 1);
10158 /* Is this a typedef we can avoid emitting? */
10161 is_redundant_typedef (decl)
10162 register tree decl;
10164 if (TYPE_DECL_IS_STUB (decl))
10167 if (DECL_ARTIFICIAL (decl)
10168 && DECL_CONTEXT (decl)
10169 && is_tagged_type (DECL_CONTEXT (decl))
10170 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10171 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10172 /* Also ignore the artificial member typedef for the class name. */
10178 /* Generate Dwarf debug information for a decl described by DECL. */
10181 gen_decl_die (decl, context_die)
10182 register tree decl;
10183 register dw_die_ref context_die;
10185 register tree origin;
10187 if (TREE_CODE (decl) == ERROR_MARK)
10190 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10191 if (DECL_IGNORED_P (decl))
10194 switch (TREE_CODE (decl))
10197 /* The individual enumerators of an enum type get output when we output
10198 the Dwarf representation of the relevant enum type itself. */
10201 case FUNCTION_DECL:
10202 /* Don't output any DIEs to represent mere function declarations,
10203 unless they are class members or explicit block externs. */
10204 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10205 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10208 /* If we're emitting an out-of-line copy of an inline function,
10209 emit info for the abstract instance and set up to refer to it. */
10210 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10211 && ! class_scope_p (context_die)
10212 /* gen_abstract_function won't emit a die if this is just a
10213 declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10214 that case, because that works only if we have a die. */
10215 && DECL_INITIAL (decl) != NULL_TREE)
10217 gen_abstract_function (decl);
10218 set_decl_origin_self (decl);
10221 if (debug_info_level > DINFO_LEVEL_TERSE)
10223 /* Before we describe the FUNCTION_DECL itself, make sure that we
10224 have described its return type. */
10225 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10227 /* And its virtual context. */
10228 if (DECL_VINDEX (decl) != NULL_TREE)
10229 gen_type_die (DECL_CONTEXT (decl), context_die);
10231 /* And its containing type. */
10232 origin = decl_class_context (decl);
10233 if (origin != NULL_TREE)
10234 gen_type_die_for_member (origin, decl, context_die);
10237 /* Now output a DIE to represent the function itself. */
10238 gen_subprogram_die (decl, context_die);
10242 /* If we are in terse mode, don't generate any DIEs to represent any
10243 actual typedefs. */
10244 if (debug_info_level <= DINFO_LEVEL_TERSE)
10247 /* In the special case of a TYPE_DECL node representing the
10248 declaration of some type tag, if the given TYPE_DECL is marked as
10249 having been instantiated from some other (original) TYPE_DECL node
10250 (e.g. one which was generated within the original definition of an
10251 inline function) we have to generate a special (abbreviated)
10252 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10254 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10256 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10260 if (is_redundant_typedef (decl))
10261 gen_type_die (TREE_TYPE (decl), context_die);
10263 /* Output a DIE to represent the typedef itself. */
10264 gen_typedef_die (decl, context_die);
10268 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10269 gen_label_die (decl, context_die);
10273 /* If we are in terse mode, don't generate any DIEs to represent any
10274 variable declarations or definitions. */
10275 if (debug_info_level <= DINFO_LEVEL_TERSE)
10278 /* Output any DIEs that are needed to specify the type of this data
10280 gen_type_die (TREE_TYPE (decl), context_die);
10282 /* And its containing type. */
10283 origin = decl_class_context (decl);
10284 if (origin != NULL_TREE)
10285 gen_type_die_for_member (origin, decl, context_die);
10287 /* Now output the DIE to represent the data object itself. This gets
10288 complicated because of the possibility that the VAR_DECL really
10289 represents an inlined instance of a formal parameter for an inline
10291 origin = decl_ultimate_origin (decl);
10292 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
10293 gen_formal_parameter_die (decl, context_die);
10295 gen_variable_die (decl, context_die);
10299 /* Ignore the nameless fields that are used to skip bits, but
10300 handle C++ anonymous unions. */
10301 if (DECL_NAME (decl) != NULL_TREE
10302 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
10304 gen_type_die (member_declared_type (decl), context_die);
10305 gen_field_die (decl, context_die);
10310 gen_type_die (TREE_TYPE (decl), context_die);
10311 gen_formal_parameter_die (decl, context_die);
10314 case NAMESPACE_DECL:
10315 /* Ignore for now. */
10323 /* Add Ada "use" clause information for SGI Workshop debugger. */
10326 dwarf2out_add_library_unit_info (filename, context_list)
10327 const char *filename;
10328 const char *context_list;
10330 unsigned int file_index;
10332 if (filename != NULL)
10334 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
10335 tree context_list_decl
10336 = build_decl (LABEL_DECL, get_identifier (context_list),
10339 TREE_PUBLIC (context_list_decl) = TRUE;
10340 add_name_attribute (unit_die, context_list);
10341 file_index = lookup_filename (filename);
10342 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
10343 add_pubname (context_list_decl, unit_die);
10347 /* Write the debugging output for DECL. */
10350 dwarf2out_decl (decl)
10351 register tree decl;
10353 register dw_die_ref context_die = comp_unit_die;
10355 if (TREE_CODE (decl) == ERROR_MARK)
10358 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10359 if (DECL_IGNORED_P (decl))
10362 switch (TREE_CODE (decl))
10364 case FUNCTION_DECL:
10365 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
10366 builtin function. Explicit programmer-supplied declarations of
10367 these same functions should NOT be ignored however. */
10368 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
10371 /* What we would really like to do here is to filter out all mere
10372 file-scope declarations of file-scope functions which are never
10373 referenced later within this translation unit (and keep all of ones
10374 that *are* referenced later on) but we aren't clairvoyant, so we have
10375 no idea which functions will be referenced in the future (i.e. later
10376 on within the current translation unit). So here we just ignore all
10377 file-scope function declarations which are not also definitions. If
10378 and when the debugger needs to know something about these functions,
10379 it will have to hunt around and find the DWARF information associated
10380 with the definition of the function. Note that we can't just check
10381 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
10382 definitions and which ones represent mere declarations. We have to
10383 check `DECL_INITIAL' instead. That's because the C front-end
10384 supports some weird semantics for "extern inline" function
10385 definitions. These can get inlined within the current translation
10386 unit (an thus, we need to generate DWARF info for their abstract
10387 instances so that the DWARF info for the concrete inlined instances
10388 can have something to refer to) but the compiler never generates any
10389 out-of-lines instances of such things (despite the fact that they
10390 *are* definitions). The important point is that the C front-end
10391 marks these "extern inline" functions as DECL_EXTERNAL, but we need
10392 to generate DWARF for them anyway. Note that the C++ front-end also
10393 plays some similar games for inline function definitions appearing
10394 within include files which also contain
10395 `#pragma interface' pragmas. */
10396 if (DECL_INITIAL (decl) == NULL_TREE)
10399 /* If we're a nested function, initially use a parent of NULL; if we're
10400 a plain function, this will be fixed up in decls_for_scope. If
10401 we're a method, it will be ignored, since we already have a DIE. */
10402 if (decl_function_context (decl))
10403 context_die = NULL;
10408 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
10409 declaration and if the declaration was never even referenced from
10410 within this entire compilation unit. We suppress these DIEs in
10411 order to save space in the .debug section (by eliminating entries
10412 which are probably useless). Note that we must not suppress
10413 block-local extern declarations (whether used or not) because that
10414 would screw-up the debugger's name lookup mechanism and cause it to
10415 miss things which really ought to be in scope at a given point. */
10416 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
10419 /* If we are in terse mode, don't generate any DIEs to represent any
10420 variable declarations or definitions. */
10421 if (debug_info_level <= DINFO_LEVEL_TERSE)
10426 /* Don't emit stubs for types unless they are needed by other DIEs. */
10427 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
10430 /* Don't bother trying to generate any DIEs to represent any of the
10431 normal built-in types for the language we are compiling. */
10432 if (DECL_SOURCE_LINE (decl) == 0)
10434 /* OK, we need to generate one for `bool' so GDB knows what type
10435 comparisons have. */
10436 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
10437 == DW_LANG_C_plus_plus)
10438 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
10439 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
10444 /* If we are in terse mode, don't generate any DIEs for types. */
10445 if (debug_info_level <= DINFO_LEVEL_TERSE)
10448 /* If we're a function-scope tag, initially use a parent of NULL;
10449 this will be fixed up in decls_for_scope. */
10450 if (decl_function_context (decl))
10451 context_die = NULL;
10459 gen_decl_die (decl, context_die);
10462 /* Output a marker (i.e. a label) for the beginning of the generated code for
10463 a lexical block. */
10466 dwarf2out_begin_block (blocknum)
10467 register unsigned blocknum;
10469 function_section (current_function_decl);
10470 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
10473 /* Output a marker (i.e. a label) for the end of the generated code for a
10477 dwarf2out_end_block (blocknum)
10478 register unsigned blocknum;
10480 function_section (current_function_decl);
10481 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
10484 /* Returns nonzero if it is appropriate not to emit any debugging
10485 information for BLOCK, because it doesn't contain any instructions.
10487 Don't allow this for blocks with nested functions or local classes
10488 as we would end up with orphans, and in the presence of scheduling
10489 we may end up calling them anyway. */
10492 dwarf2out_ignore_block (block)
10496 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
10497 if (TREE_CODE (decl) == FUNCTION_DECL
10498 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
10503 /* Output a marker (i.e. a label) at a point in the assembly code which
10504 corresponds to a given source level label. */
10507 dwarf2out_label (insn)
10510 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10512 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10514 function_section (current_function_decl);
10515 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
10516 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
10517 (unsigned) INSN_UID (insn));
10521 /* Lookup a filename (in the list of filenames that we know about here in
10522 dwarf2out.c) and return its "index". The index of each (known) filename is
10523 just a unique number which is associated with only that one filename.
10524 We need such numbers for the sake of generating labels
10525 (in the .debug_sfnames section) and references to those
10526 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
10527 If the filename given as an argument is not found in our current list,
10528 add it to the list and assign it the next available unique index number.
10529 In order to speed up searches, we remember the index of the filename
10530 was looked up last. This handles the majority of all searches. */
10533 lookup_filename (file_name)
10534 const char *file_name;
10536 static unsigned last_file_lookup_index = 0;
10537 register unsigned i;
10539 /* Check to see if the file name that was searched on the previous call
10540 matches this file name. If so, return the index. */
10541 if (last_file_lookup_index != 0)
10542 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
10543 return last_file_lookup_index;
10545 /* Didn't match the previous lookup, search the table */
10546 for (i = 1; i < file_table_in_use; ++i)
10547 if (strcmp (file_name, file_table[i]) == 0)
10549 last_file_lookup_index = i;
10553 /* Prepare to add a new table entry by making sure there is enough space in
10554 the table to do so. If not, expand the current table. */
10555 if (file_table_in_use == file_table_allocated)
10557 file_table_allocated += FILE_TABLE_INCREMENT;
10559 = (char **) xrealloc (file_table,
10560 file_table_allocated * sizeof (char *));
10563 /* Add the new entry to the end of the filename table. */
10564 file_table[file_table_in_use] = xstrdup (file_name);
10565 last_file_lookup_index = file_table_in_use++;
10567 return last_file_lookup_index;
10570 /* Output a label to mark the beginning of a source code line entry
10571 and record information relating to this source line, in
10572 'line_info_table' for later output of the .debug_line section. */
10575 dwarf2out_line (filename, line)
10576 register const char *filename;
10577 register unsigned line;
10579 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10581 function_section (current_function_decl);
10583 if (DWARF2_ASM_LINE_DEBUG_INFO)
10585 static const char *lastfile;
10587 /* Emit the .file and .loc directives understood by GNU as. */
10588 if (lastfile == 0 || strcmp (filename, lastfile))
10591 ggc_add_string_root ((char **) &lastfile, 1);
10593 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
10594 lastfile = filename;
10597 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
10599 /* Indicate that line number info exists. */
10600 ++line_info_table_in_use;
10602 /* Indicate that multiple line number tables exist. */
10603 if (DECL_SECTION_NAME (current_function_decl))
10604 ++separate_line_info_table_in_use;
10606 else if (DECL_SECTION_NAME (current_function_decl))
10608 register dw_separate_line_info_ref line_info;
10609 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
10610 separate_line_info_table_in_use);
10611 if (flag_debug_asm)
10612 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
10613 fputc ('\n', asm_out_file);
10615 /* expand the line info table if necessary */
10616 if (separate_line_info_table_in_use
10617 == separate_line_info_table_allocated)
10619 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10620 separate_line_info_table
10621 = (dw_separate_line_info_ref)
10622 xrealloc (separate_line_info_table,
10623 separate_line_info_table_allocated
10624 * sizeof (dw_separate_line_info_entry));
10627 /* Add the new entry at the end of the line_info_table. */
10629 = &separate_line_info_table[separate_line_info_table_in_use++];
10630 line_info->dw_file_num = lookup_filename (filename);
10631 line_info->dw_line_num = line;
10632 line_info->function = current_funcdef_number;
10636 register dw_line_info_ref line_info;
10638 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
10639 line_info_table_in_use);
10640 if (flag_debug_asm)
10641 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
10642 fputc ('\n', asm_out_file);
10644 /* Expand the line info table if necessary. */
10645 if (line_info_table_in_use == line_info_table_allocated)
10647 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10649 = (dw_line_info_ref)
10650 xrealloc (line_info_table,
10651 (line_info_table_allocated
10652 * sizeof (dw_line_info_entry)));
10655 /* Add the new entry at the end of the line_info_table. */
10656 line_info = &line_info_table[line_info_table_in_use++];
10657 line_info->dw_file_num = lookup_filename (filename);
10658 line_info->dw_line_num = line;
10663 /* Record the beginning of a new source file, for later output
10664 of the .debug_macinfo section. At present, unimplemented. */
10667 dwarf2out_start_source_file (filename)
10668 register const char *filename ATTRIBUTE_UNUSED;
10670 if (flag_eliminate_dwarf2_dups)
10672 /* Record the beginning of the file for break_out_includes. */
10673 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
10674 add_AT_string (bincl_die, DW_AT_name, filename);
10678 /* Record the end of a source file, for later output
10679 of the .debug_macinfo section. At present, unimplemented. */
10682 dwarf2out_end_source_file ()
10684 if (flag_eliminate_dwarf2_dups)
10686 /* Record the end of the file for break_out_includes. */
10687 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
10691 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10692 the tail part of the directive line, i.e. the part which is past the
10693 initial whitespace, #, whitespace, directive-name, whitespace part. */
10696 dwarf2out_define (lineno, buffer)
10697 register unsigned lineno ATTRIBUTE_UNUSED;
10698 register const char *buffer ATTRIBUTE_UNUSED;
10700 static int initialized = 0;
10703 dwarf2out_start_source_file (primary_filename);
10708 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10709 the tail part of the directive line, i.e. the part which is past the
10710 initial whitespace, #, whitespace, directive-name, whitespace part. */
10713 dwarf2out_undef (lineno, buffer)
10714 register unsigned lineno ATTRIBUTE_UNUSED;
10715 register const char *buffer ATTRIBUTE_UNUSED;
10719 /* Set up for Dwarf output at the start of compilation. */
10722 dwarf2out_init (asm_out_file, main_input_filename)
10723 register FILE *asm_out_file;
10724 register const char *main_input_filename;
10726 /* Remember the name of the primary input file. */
10727 primary_filename = main_input_filename;
10729 /* Allocate the initial hunk of the file_table. */
10730 file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
10731 file_table_allocated = FILE_TABLE_INCREMENT;
10733 /* Skip the first entry - file numbers begin at 1. */
10734 file_table_in_use = 1;
10736 /* Allocate the initial hunk of the decl_die_table. */
10738 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
10739 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
10740 decl_die_table_in_use = 0;
10742 /* Allocate the initial hunk of the decl_scope_table. */
10744 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
10745 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
10746 decl_scope_depth = 0;
10748 /* Allocate the initial hunk of the abbrev_die_table. */
10750 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
10751 sizeof (dw_die_ref));
10752 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
10753 /* Zero-th entry is allocated, but unused */
10754 abbrev_die_table_in_use = 1;
10756 /* Allocate the initial hunk of the line_info_table. */
10758 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
10759 sizeof (dw_line_info_entry));
10760 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
10761 /* Zero-th entry is allocated, but unused */
10762 line_info_table_in_use = 1;
10764 /* Generate the initial DIE for the .debug section. Note that the (string)
10765 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
10766 will (typically) be a relative pathname and that this pathname should be
10767 taken as being relative to the directory from which the compiler was
10768 invoked when the given (base) source file was compiled. */
10769 comp_unit_die = gen_compile_unit_die (main_input_filename);
10773 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
10774 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
10777 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
10778 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
10779 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
10780 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
10782 strcpy (text_section_label, stripattributes (TEXT_SECTION));
10783 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
10784 DEBUG_INFO_SECTION_LABEL, 0);
10785 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
10786 DEBUG_LINE_SECTION_LABEL, 0);
10788 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
10789 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
10790 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
10792 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
10793 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
10795 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
10796 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
10797 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
10798 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
10801 /* Output stuff that dwarf requires at the end of every file,
10802 and generate the DWARF-2 debugging info. */
10805 dwarf2out_finish ()
10807 limbo_die_node *node, *next_node;
10810 /* Traverse the limbo die list, and add parent/child links. The only
10811 dies without parents that should be here are concrete instances of
10812 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
10813 For concrete instances, we can get the parent die from the abstract
10815 for (node = limbo_die_list; node; node = next_node)
10817 next_node = node->next;
10820 if (die->die_parent == NULL)
10822 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
10824 add_child_die (origin->die_parent, die);
10825 else if (die == comp_unit_die)
10832 limbo_die_list = NULL;
10834 /* Walk through the list of incomplete types again, trying once more to
10835 emit full debugging info for them. */
10836 retry_incomplete_types ();
10838 /* We need to reverse all the dies before break_out_includes, or
10839 we'll see the end of an include file before the beginning. */
10840 reverse_all_dies (comp_unit_die);
10842 /* Generate separate CUs for each of the include files we've seen.
10843 They will go into limbo_die_list. */
10844 break_out_includes (comp_unit_die);
10846 /* Traverse the DIE's and add add sibling attributes to those DIE's
10847 that have children. */
10848 add_sibling_attributes (comp_unit_die);
10849 for (node = limbo_die_list; node; node = node->next)
10850 add_sibling_attributes (node->die);
10852 /* Output a terminator label for the .text section. */
10853 fputc ('\n', asm_out_file);
10854 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
10855 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
10858 /* Output a terminator label for the .data section. */
10859 fputc ('\n', asm_out_file);
10860 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
10861 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
10863 /* Output a terminator label for the .bss section. */
10864 fputc ('\n', asm_out_file);
10865 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
10866 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
10869 /* Output the source line correspondence table. */
10870 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
10872 if (! DWARF2_ASM_LINE_DEBUG_INFO)
10874 fputc ('\n', asm_out_file);
10875 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
10876 output_line_info ();
10879 /* We can only use the low/high_pc attributes if all of the code
10881 if (separate_line_info_table_in_use == 0)
10883 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
10884 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
10887 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
10888 debug_line_section_label);
10891 #if 0 /* unimplemented */
10892 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
10893 add_AT_unsigned (die, DW_AT_macro_info, 0);
10896 /* Output all of the compilation units. We put the main one last so that
10897 the offsets are available to output_pubnames. */
10898 for (node = limbo_die_list; node; node = node->next)
10899 output_comp_unit (node->die);
10900 output_comp_unit (comp_unit_die);
10902 /* Output the abbreviation table. */
10903 fputc ('\n', asm_out_file);
10904 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
10905 output_abbrev_section ();
10907 if (pubname_table_in_use)
10909 /* Output public names table. */
10910 fputc ('\n', asm_out_file);
10911 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
10912 output_pubnames ();
10915 /* We only put functions in the arange table, so don't write it out if
10916 we don't have any. */
10917 if (fde_table_in_use)
10919 /* Output the address range information. */
10920 fputc ('\n', asm_out_file);
10921 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
10925 #endif /* DWARF2_DEBUGGING_INFO */