1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* TODO: Implement .debug_str handling, and share entries somehow.
26 Eliminate duplicates by putting common info in a separate section
27 to be collected by the linker and referring to it with
29 Emit .debug_line header even when there are no functions, since
30 the file numbers are used by .debug_info. Alternately, leave
31 out locations for types and decls.
32 Avoid talking about ctors and op= for PODs.
33 Factor out common prologue sequences into multiple CIEs. */
35 /* The first part of this file deals with the DWARF 2 frame unwind
36 information, which is also used by the GCC efficient exception handling
37 mechanism. The second part, controlled only by an #ifdef
38 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
47 #include "hard-reg-set.h"
49 #include "insn-config.h"
55 #include "dwarf2out.h"
61 /* We cannot use <assert.h> in GCC source, since that would include
62 GCC's assert.h, which may not be compatible with the host compiler. */
67 # define assert(e) do { if (! (e)) abort (); } while (0)
70 /* Decide whether we want to emit frame unwind information for the current
76 return (write_symbols == DWARF2_DEBUG
77 #ifdef DWARF2_FRAME_INFO
80 #ifdef DWARF2_UNWIND_INFO
82 || (flag_exceptions && ! exceptions_via_longjmp)
87 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
89 /* How to start an assembler comment. */
90 #ifndef ASM_COMMENT_START
91 #define ASM_COMMENT_START ";#"
94 typedef struct dw_cfi_struct *dw_cfi_ref;
95 typedef struct dw_fde_struct *dw_fde_ref;
96 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
98 /* Call frames are described using a sequence of Call Frame
99 Information instructions. The register number, offset
100 and address fields are provided as possible operands;
101 their use is selected by the opcode field. */
103 typedef union dw_cfi_oprnd_struct
105 unsigned long dw_cfi_reg_num;
106 long int dw_cfi_offset;
107 const char *dw_cfi_addr;
108 struct dw_loc_descr_struct *dw_cfi_loc;
112 typedef struct dw_cfi_struct
114 dw_cfi_ref dw_cfi_next;
115 enum dwarf_call_frame_info dw_cfi_opc;
116 dw_cfi_oprnd dw_cfi_oprnd1;
117 dw_cfi_oprnd dw_cfi_oprnd2;
121 /* This is how we define the location of the CFA. We use to handle it
122 as REG + OFFSET all the time, but now it can be more complex.
123 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
124 Instead of passing around REG and OFFSET, we pass a copy
125 of this structure. */
126 typedef struct cfa_loc
131 int indirect; /* 1 if CFA is accessed via a dereference. */
134 /* All call frame descriptions (FDE's) in the GCC generated DWARF
135 refer to a single Common Information Entry (CIE), defined at
136 the beginning of the .debug_frame section. This used of a single
137 CIE obviates the need to keep track of multiple CIE's
138 in the DWARF generation routines below. */
140 typedef struct dw_fde_struct
142 const char *dw_fde_begin;
143 const char *dw_fde_current_label;
144 const char *dw_fde_end;
145 dw_cfi_ref dw_fde_cfi;
150 /* Maximum size (in bytes) of an artificially generated label. */
151 #define MAX_ARTIFICIAL_LABEL_BYTES 30
153 /* Make sure we know the sizes of the various types dwarf can describe. These
154 are only defaults. If the sizes are different for your target, you should
155 override these values by defining the appropriate symbols in your tm.h
158 #ifndef CHAR_TYPE_SIZE
159 #define CHAR_TYPE_SIZE BITS_PER_UNIT
162 /* The size of the target's pointer type. */
164 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
167 /* The size of addresses as they appear in the Dwarf 2 data.
168 Some architectures use word addresses to refer to code locations,
169 but Dwarf 2 info always uses byte addresses. On such machines,
170 Dwarf 2 addresses need to be larger than the architecture's
172 #ifndef DWARF2_ADDR_SIZE
173 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
176 /* The size in bytes of a DWARF field indicating an offset or length
177 relative to a debug info section, specified to be 4 bytes in the
178 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
181 #ifndef DWARF_OFFSET_SIZE
182 #define DWARF_OFFSET_SIZE 4
185 #define DWARF_VERSION 2
187 /* Round SIZE up to the nearest BOUNDARY. */
188 #define DWARF_ROUND(SIZE,BOUNDARY) \
189 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
191 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
192 #ifdef STACK_GROWS_DOWNWARD
193 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
195 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
198 /* A pointer to the base of a table that contains frame description
199 information for each routine. */
200 static dw_fde_ref fde_table;
202 /* Number of elements currently allocated for fde_table. */
203 static unsigned fde_table_allocated;
205 /* Number of elements in fde_table currently in use. */
206 static unsigned fde_table_in_use;
208 /* Size (in elements) of increments by which we may expand the
210 #define FDE_TABLE_INCREMENT 256
212 /* A list of call frame insns for the CIE. */
213 static dw_cfi_ref cie_cfi_head;
215 /* The number of the current function definition for which debugging
216 information is being generated. These numbers range from 1 up to the
217 maximum number of function definitions contained within the current
218 compilation unit. These numbers are used to create unique label id's
219 unique to each function definition. */
220 static unsigned current_funcdef_number = 0;
222 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
223 attribute that accelerates the lookup of the FDE associated
224 with the subprogram. This variable holds the table index of the FDE
225 associated with the current function (body) definition. */
226 static unsigned current_funcdef_fde;
228 /* Forward declarations for functions defined in this file. */
230 static char *stripattributes PARAMS ((const char *));
231 static const char *dwarf_cfi_name PARAMS ((unsigned));
232 static dw_cfi_ref new_cfi PARAMS ((void));
233 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
234 static unsigned long size_of_uleb128 PARAMS ((unsigned long));
235 static unsigned long size_of_sleb128 PARAMS ((long));
236 static void output_uleb128 PARAMS ((unsigned long));
237 static void output_sleb128 PARAMS ((long));
238 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
239 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
240 static void lookup_cfa PARAMS ((dw_cfa_location *));
241 static void reg_save PARAMS ((const char *, unsigned,
243 static void initial_return_save PARAMS ((rtx));
244 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
245 static void output_call_frame_info PARAMS ((int));
246 static void dwarf2out_stack_adjust PARAMS ((rtx));
247 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
249 /* Support for complex CFA locations. */
250 static void output_cfa_loc PARAMS ((dw_cfi_ref));
251 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
252 struct dw_loc_descr_struct *));
253 static struct dw_loc_descr_struct *build_cfa_loc
254 PARAMS ((dw_cfa_location *));
255 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
257 /* Definitions of defaults for assembler-dependent names of various
258 pseudo-ops and section names.
259 Theses may be overridden in the tm.h file (if necessary) for a particular
262 #ifdef OBJECT_FORMAT_ELF
263 #ifndef UNALIGNED_SHORT_ASM_OP
264 #define UNALIGNED_SHORT_ASM_OP ".2byte"
266 #ifndef UNALIGNED_INT_ASM_OP
267 #define UNALIGNED_INT_ASM_OP ".4byte"
269 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
270 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
272 #endif /* OBJECT_FORMAT_ELF */
275 #define ASM_BYTE_OP ".byte"
278 /* Data and reference forms for relocatable data. */
279 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
280 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
282 /* Pseudo-op for defining a new section. */
283 #ifndef SECTION_ASM_OP
284 #define SECTION_ASM_OP ".section"
287 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
288 print the SECTION_ASM_OP and the section name. The default here works for
289 almost all svr4 assemblers, except for the sparc, where the section name
290 must be enclosed in double quotes. (See sparcv4.h). */
291 #ifndef SECTION_FORMAT
292 #ifdef PUSHSECTION_FORMAT
293 #define SECTION_FORMAT PUSHSECTION_FORMAT
295 #define SECTION_FORMAT "\t%s\t%s\n"
299 #ifndef FRAME_SECTION
300 #define FRAME_SECTION ".debug_frame"
303 #ifndef FUNC_BEGIN_LABEL
304 #define FUNC_BEGIN_LABEL "LFB"
306 #ifndef FUNC_END_LABEL
307 #define FUNC_END_LABEL "LFE"
309 #define CIE_AFTER_SIZE_LABEL "LSCIE"
310 #define CIE_END_LABEL "LECIE"
311 #define CIE_LENGTH_LABEL "LLCIE"
312 #define FDE_AFTER_SIZE_LABEL "LSFDE"
313 #define FDE_END_LABEL "LEFDE"
314 #define FDE_LENGTH_LABEL "LLFDE"
316 /* Definitions of defaults for various types of primitive assembly language
317 output operations. These may be overridden from within the tm.h file,
318 but typically, that is unnecessary. */
320 #ifndef ASM_OUTPUT_SECTION
321 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
322 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
325 #ifndef ASM_OUTPUT_DWARF_DATA1
326 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
327 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
330 #ifndef ASM_OUTPUT_DWARF_DELTA1
331 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
332 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
333 assemble_name (FILE, LABEL1); \
334 fprintf (FILE, "-"); \
335 assemble_name (FILE, LABEL2); \
339 #ifdef UNALIGNED_INT_ASM_OP
341 #ifndef UNALIGNED_OFFSET_ASM_OP
342 #define UNALIGNED_OFFSET_ASM_OP \
343 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
346 #ifndef UNALIGNED_WORD_ASM_OP
347 #define UNALIGNED_WORD_ASM_OP \
348 ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \
349 : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \
350 : UNALIGNED_INT_ASM_OP)
353 #ifndef ASM_OUTPUT_DWARF_DELTA2
354 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
355 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
356 assemble_name (FILE, LABEL1); \
357 fprintf (FILE, "-"); \
358 assemble_name (FILE, LABEL2); \
362 #ifndef ASM_OUTPUT_DWARF_DELTA4
363 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
364 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
365 assemble_name (FILE, LABEL1); \
366 fprintf (FILE, "-"); \
367 assemble_name (FILE, LABEL2); \
371 #ifndef ASM_OUTPUT_DWARF_DELTA
372 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
373 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
374 assemble_name (FILE, LABEL1); \
375 fprintf (FILE, "-"); \
376 assemble_name (FILE, LABEL2); \
380 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
381 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
382 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
383 assemble_name (FILE, LABEL1); \
384 fprintf (FILE, "-"); \
385 assemble_name (FILE, LABEL2); \
389 #ifndef ASM_OUTPUT_DWARF_ADDR
390 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
391 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
392 assemble_name (FILE, LABEL); \
396 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
397 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
399 fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
400 output_addr_const ((FILE), (RTX)); \
404 #ifndef ASM_OUTPUT_DWARF_OFFSET4
405 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
406 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
407 assemble_name (FILE, LABEL); \
411 #ifndef ASM_OUTPUT_DWARF_OFFSET
412 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
413 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
414 assemble_name (FILE, LABEL); \
418 #ifndef ASM_OUTPUT_DWARF_DATA2
419 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
420 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
423 #ifndef ASM_OUTPUT_DWARF_DATA4
424 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
425 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
428 #ifndef ASM_OUTPUT_DWARF_DATA8
429 #define ASM_OUTPUT_DWARF_DATA8(FILE,VALUE) \
430 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_DOUBLE_INT_ASM_OP, \
431 (unsigned long) (VALUE))
434 #ifndef ASM_OUTPUT_DWARF_DATA
435 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
436 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
437 (unsigned long) (VALUE))
440 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
441 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
442 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
443 (unsigned long) (VALUE))
446 #ifndef ASM_OUTPUT_DWARF_CONST_DOUBLE
447 #define ASM_OUTPUT_DWARF_CONST_DOUBLE(FILE,HIGH_VALUE,LOW_VALUE) \
449 if (WORDS_BIG_ENDIAN) \
451 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
452 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
456 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
457 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
462 #else /* UNALIGNED_INT_ASM_OP */
464 /* We don't have unaligned support, let's hope the normal output works for
467 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
468 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1)
470 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
471 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
473 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
474 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
476 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
477 assemble_integer (gen_rtx_MINUS (HImode, \
478 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
479 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
482 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
483 assemble_integer (gen_rtx_MINUS (SImode, \
484 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
485 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
488 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
489 assemble_integer (gen_rtx_MINUS (Pmode, \
490 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
491 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
494 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
495 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
497 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
498 assemble_integer (GEN_INT (VALUE), 2, 1)
500 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
501 assemble_integer (GEN_INT (VALUE), 4, 1)
503 #endif /* UNALIGNED_INT_ASM_OP */
506 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
507 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
509 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
510 assemble_name (FILE, SY); \
512 assemble_name (FILE, HI); \
514 assemble_name (FILE, LO); \
517 #endif /* SET_ASM_OP */
519 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
520 newline is produced. When flag_debug_asm is asserted, we add commentary
521 at the end of the line, so we must avoid output of a newline here. */
522 #ifndef ASM_OUTPUT_DWARF_STRING
523 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
525 register int slen = strlen(P); \
526 register const char *p = (P); \
528 fprintf (FILE, "\t.ascii \""); \
529 for (i = 0; i < slen; i++) \
531 register int c = p[i]; \
532 if (c == '\"' || c == '\\') \
538 fprintf (FILE, "\\%o", c); \
541 fprintf (FILE, "\\0\""); \
546 /* The DWARF 2 CFA column which tracks the return address. Normally this
547 is the column for PC, or the first column after all of the hard
549 #ifndef DWARF_FRAME_RETURN_COLUMN
551 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
553 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
557 /* The mapping from gcc register number to DWARF 2 CFA column number. By
558 default, we just provide columns for all registers. */
559 #ifndef DWARF_FRAME_REGNUM
560 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
563 /* Hook used by __throw. */
566 expand_builtin_dwarf_fp_regnum ()
568 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
571 /* The offset from the incoming value of %sp to the top of the stack frame
572 for the current function. */
573 #ifndef INCOMING_FRAME_SP_OFFSET
574 #define INCOMING_FRAME_SP_OFFSET 0
577 /* Return a pointer to a copy of the section string name S with all
578 attributes stripped off, and an asterisk prepended (for assemble_name). */
584 char *stripped = xmalloc (strlen (s) + 2);
589 while (*s && *s != ',')
596 /* Generate code to initialize the register size table. */
599 expand_builtin_init_dwarf_reg_sizes (address)
603 enum machine_mode mode = TYPE_MODE (char_type_node);
604 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
605 rtx mem = gen_rtx_MEM (mode, addr);
607 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
609 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
610 int size = GET_MODE_SIZE (reg_raw_mode[i]);
615 emit_move_insn (change_address (mem, mode,
616 plus_constant (addr, offset)),
621 /* Convert a DWARF call frame info. operation to its string name */
624 dwarf_cfi_name (cfi_opc)
625 register unsigned cfi_opc;
629 case DW_CFA_advance_loc:
630 return "DW_CFA_advance_loc";
632 return "DW_CFA_offset";
634 return "DW_CFA_restore";
638 return "DW_CFA_set_loc";
639 case DW_CFA_advance_loc1:
640 return "DW_CFA_advance_loc1";
641 case DW_CFA_advance_loc2:
642 return "DW_CFA_advance_loc2";
643 case DW_CFA_advance_loc4:
644 return "DW_CFA_advance_loc4";
645 case DW_CFA_offset_extended:
646 return "DW_CFA_offset_extended";
647 case DW_CFA_restore_extended:
648 return "DW_CFA_restore_extended";
649 case DW_CFA_undefined:
650 return "DW_CFA_undefined";
651 case DW_CFA_same_value:
652 return "DW_CFA_same_value";
653 case DW_CFA_register:
654 return "DW_CFA_register";
655 case DW_CFA_remember_state:
656 return "DW_CFA_remember_state";
657 case DW_CFA_restore_state:
658 return "DW_CFA_restore_state";
660 return "DW_CFA_def_cfa";
661 case DW_CFA_def_cfa_register:
662 return "DW_CFA_def_cfa_register";
663 case DW_CFA_def_cfa_offset:
664 return "DW_CFA_def_cfa_offset";
665 case DW_CFA_def_cfa_expression:
666 return "DW_CFA_def_cfa_expression";
668 /* SGI/MIPS specific */
669 case DW_CFA_MIPS_advance_loc8:
670 return "DW_CFA_MIPS_advance_loc8";
673 case DW_CFA_GNU_window_save:
674 return "DW_CFA_GNU_window_save";
675 case DW_CFA_GNU_args_size:
676 return "DW_CFA_GNU_args_size";
677 case DW_CFA_GNU_negative_offset_extended:
678 return "DW_CFA_GNU_negative_offset_extended";
681 return "DW_CFA_<unknown>";
685 /* Return a pointer to a newly allocated Call Frame Instruction. */
687 static inline dw_cfi_ref
690 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
692 cfi->dw_cfi_next = NULL;
693 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
694 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
699 /* Add a Call Frame Instruction to list of instructions. */
702 add_cfi (list_head, cfi)
703 register dw_cfi_ref *list_head;
704 register dw_cfi_ref cfi;
706 register dw_cfi_ref *p;
708 /* Find the end of the chain. */
709 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
715 /* Generate a new label for the CFI info to refer to. */
718 dwarf2out_cfi_label ()
720 static char label[20];
721 static unsigned long label_num = 0;
723 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
724 ASM_OUTPUT_LABEL (asm_out_file, label);
729 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
730 or to the CIE if LABEL is NULL. */
733 add_fde_cfi (label, cfi)
734 register const char *label;
735 register dw_cfi_ref cfi;
739 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
742 label = dwarf2out_cfi_label ();
744 if (fde->dw_fde_current_label == NULL
745 || strcmp (label, fde->dw_fde_current_label) != 0)
747 register dw_cfi_ref xcfi;
749 fde->dw_fde_current_label = label = xstrdup (label);
751 /* Set the location counter to the new label. */
753 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
754 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
755 add_cfi (&fde->dw_fde_cfi, xcfi);
758 add_cfi (&fde->dw_fde_cfi, cfi);
762 add_cfi (&cie_cfi_head, cfi);
765 /* Subroutine of lookup_cfa. */
768 lookup_cfa_1 (cfi, loc)
769 register dw_cfi_ref cfi;
770 register dw_cfa_location *loc;
772 switch (cfi->dw_cfi_opc)
774 case DW_CFA_def_cfa_offset:
775 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
777 case DW_CFA_def_cfa_register:
778 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
781 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
782 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
784 case DW_CFA_def_cfa_expression:
785 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
792 /* Find the previous value for the CFA. */
796 register dw_cfa_location *loc;
798 register dw_cfi_ref cfi;
800 loc->reg = (unsigned long) -1;
803 loc->base_offset = 0;
805 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
806 lookup_cfa_1 (cfi, loc);
808 if (fde_table_in_use)
810 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
811 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
812 lookup_cfa_1 (cfi, loc);
816 /* The current rule for calculating the DWARF2 canonical frame address. */
819 /* The register used for saving registers to the stack, and its offset
821 dw_cfa_location cfa_store;
823 /* The running total of the size of arguments pushed onto the stack. */
824 static long args_size;
826 /* The last args_size we actually output. */
827 static long old_args_size;
829 /* Entry point to update the canonical frame address (CFA).
830 LABEL is passed to add_fde_cfi. The value of CFA is now to be
831 calculated from REG+OFFSET. */
834 dwarf2out_def_cfa (label, reg, offset)
835 register const char *label;
844 def_cfa_1 (label, &loc);
847 /* This routine does the actual work. The CFA is now calculated from
848 the dw_cfa_location structure. */
850 def_cfa_1 (label, loc_p)
851 register const char *label;
852 dw_cfa_location *loc_p;
854 register dw_cfi_ref cfi;
855 dw_cfa_location old_cfa, loc;
860 if (cfa_store.reg == loc.reg && loc.indirect == 0)
861 cfa_store.offset = loc.offset;
863 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
864 lookup_cfa (&old_cfa);
866 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
867 loc.indirect == old_cfa.indirect)
869 if (loc.indirect == 0)
872 if (loc.base_offset == old_cfa.base_offset)
878 if (loc.reg == old_cfa.reg && loc.indirect == old_cfa.indirect)
880 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
881 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
884 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
885 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
886 && loc.indirect == old_cfa.indirect)
888 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
889 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
893 else if (loc.indirect == 0)
895 cfi->dw_cfi_opc = DW_CFA_def_cfa;
896 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
897 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
901 struct dw_loc_descr_struct * loc_list;
902 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
903 loc_list = build_cfa_loc (&loc);
904 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
907 add_fde_cfi (label, cfi);
910 /* Add the CFI for saving a register. REG is the CFA column number.
911 LABEL is passed to add_fde_cfi.
912 If SREG is -1, the register is saved at OFFSET from the CFA;
913 otherwise it is saved in SREG. */
916 reg_save (label, reg, sreg, offset)
917 register const char *label;
918 register unsigned reg;
919 register unsigned sreg;
920 register long offset;
922 register dw_cfi_ref cfi = new_cfi ();
924 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
926 /* The following comparison is correct. -1 is used to indicate that
927 the value isn't a register number. */
928 if (sreg == (unsigned int) -1)
931 /* The register number won't fit in 6 bits, so we have to use
933 cfi->dw_cfi_opc = DW_CFA_offset_extended;
935 cfi->dw_cfi_opc = DW_CFA_offset;
937 offset /= DWARF_CIE_DATA_ALIGNMENT;
940 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
943 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
945 else if (sreg == reg)
946 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
950 cfi->dw_cfi_opc = DW_CFA_register;
951 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
954 add_fde_cfi (label, cfi);
957 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
958 This CFI tells the unwinder that it needs to restore the window registers
959 from the previous frame's window save area.
961 ??? Perhaps we should note in the CIE where windows are saved (instead of
962 assuming 0(cfa)) and what registers are in the window. */
965 dwarf2out_window_save (label)
966 register const char *label;
968 register dw_cfi_ref cfi = new_cfi ();
969 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
970 add_fde_cfi (label, cfi);
973 /* Add a CFI to update the running total of the size of arguments
974 pushed onto the stack. */
977 dwarf2out_args_size (label, size)
981 register dw_cfi_ref cfi;
983 if (size == old_args_size)
985 old_args_size = size;
988 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
989 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
990 add_fde_cfi (label, cfi);
993 /* Entry point for saving a register to the stack. REG is the GCC register
994 number. LABEL and OFFSET are passed to reg_save. */
997 dwarf2out_reg_save (label, reg, offset)
998 register const char *label;
999 register unsigned reg;
1000 register long offset;
1002 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
1005 /* Entry point for saving the return address in the stack.
1006 LABEL and OFFSET are passed to reg_save. */
1009 dwarf2out_return_save (label, offset)
1010 register const char *label;
1011 register long offset;
1013 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
1016 /* Entry point for saving the return address in a register.
1017 LABEL and SREG are passed to reg_save. */
1020 dwarf2out_return_reg (label, sreg)
1021 register const char *label;
1022 register unsigned sreg;
1024 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
1027 /* Record the initial position of the return address. RTL is
1028 INCOMING_RETURN_ADDR_RTX. */
1031 initial_return_save (rtl)
1034 unsigned int reg = (unsigned int) -1;
1037 switch (GET_CODE (rtl))
1040 /* RA is in a register. */
1041 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1044 /* RA is on the stack. */
1045 rtl = XEXP (rtl, 0);
1046 switch (GET_CODE (rtl))
1049 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1054 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1056 offset = INTVAL (XEXP (rtl, 1));
1059 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1061 offset = -INTVAL (XEXP (rtl, 1));
1068 /* The return address is at some offset from any value we can
1069 actually load. For instance, on the SPARC it is in %i7+8. Just
1070 ignore the offset for now; it doesn't matter for unwinding frames. */
1071 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1073 initial_return_save (XEXP (rtl, 0));
1079 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1082 /* Check INSN to see if it looks like a push or a stack adjustment, and
1083 make a note of it if it does. EH uses this information to find out how
1084 much extra space it needs to pop off the stack. */
1087 dwarf2out_stack_adjust (insn)
1093 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1095 /* Extract the size of the args from the CALL rtx itself. */
1097 insn = PATTERN (insn);
1098 if (GET_CODE (insn) == PARALLEL)
1099 insn = XVECEXP (insn, 0, 0);
1100 if (GET_CODE (insn) == SET)
1101 insn = SET_SRC (insn);
1102 assert (GET_CODE (insn) == CALL);
1103 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1107 /* If only calls can throw, and we have a frame pointer,
1108 save up adjustments until we see the CALL_INSN. */
1109 else if (! asynchronous_exceptions
1110 && cfa.reg != STACK_POINTER_REGNUM)
1113 if (GET_CODE (insn) == BARRIER)
1115 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1116 the compiler will have already emitted a stack adjustment, but
1117 doesn't bother for calls to noreturn functions. */
1118 #ifdef STACK_GROWS_DOWNWARD
1119 offset = -args_size;
1124 else if (GET_CODE (PATTERN (insn)) == SET)
1129 insn = PATTERN (insn);
1130 src = SET_SRC (insn);
1131 dest = SET_DEST (insn);
1133 if (dest == stack_pointer_rtx)
1135 /* (set (reg sp) (plus (reg sp) (const_int))) */
1136 code = GET_CODE (src);
1137 if (! (code == PLUS || code == MINUS)
1138 || XEXP (src, 0) != stack_pointer_rtx
1139 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1142 offset = INTVAL (XEXP (src, 1));
1144 else if (GET_CODE (dest) == MEM)
1146 /* (set (mem (pre_dec (reg sp))) (foo)) */
1147 src = XEXP (dest, 0);
1148 code = GET_CODE (src);
1150 if (! (code == PRE_DEC || code == PRE_INC)
1151 || XEXP (src, 0) != stack_pointer_rtx)
1154 offset = GET_MODE_SIZE (GET_MODE (dest));
1159 if (code == PLUS || code == PRE_INC)
1168 if (cfa.reg == STACK_POINTER_REGNUM)
1169 cfa.offset += offset;
1171 #ifndef STACK_GROWS_DOWNWARD
1174 args_size += offset;
1178 label = dwarf2out_cfi_label ();
1179 def_cfa_1 (label, &cfa);
1180 dwarf2out_args_size (label, args_size);
1183 /* A temporary register used in adjusting SP or setting up the store_reg. */
1184 static unsigned cfa_temp_reg;
1186 /* A temporary value used in adjusting SP or setting up the store_reg. */
1187 static long cfa_temp_value;
1189 /* Record call frame debugging information for an expression, which either
1190 sets SP or FP (adjusting how we calculate the frame address) or saves a
1191 register to the stack. */
1194 dwarf2out_frame_debug_expr (expr, label)
1201 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1202 the PARALLEL independantly. The first element is always processed if
1203 it is a SET. This is for backward compatability. Other elements
1204 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1205 flag is set in them. */
1207 if (GET_CODE (expr) == PARALLEL)
1210 int limit = XVECLEN (expr, 0);
1212 for (par_index = 0; par_index < limit; par_index++)
1214 rtx x = XVECEXP (expr, 0, par_index);
1216 if (GET_CODE (x) == SET &&
1217 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1218 dwarf2out_frame_debug_expr (x, label);
1223 if (GET_CODE (expr) != SET)
1226 src = SET_SRC (expr);
1227 dest = SET_DEST (expr);
1229 switch (GET_CODE (dest))
1232 /* Update the CFA rule wrt SP or FP. Make sure src is
1233 relative to the current CFA register. */
1234 switch (GET_CODE (src))
1236 /* Setting FP from SP. */
1238 if (cfa.reg != (unsigned) REGNO (src))
1241 /* We used to require that dest be either SP or FP, but the
1242 ARM copies SP to a temporary register, and from there to
1243 FP. So we just rely on the backends to only set
1244 RTX_FRAME_RELATED_P on appropriate insns. */
1245 cfa.reg = REGNO (dest);
1250 if (dest == stack_pointer_rtx)
1253 switch (GET_CODE (XEXP (src, 1)))
1256 offset = INTVAL (XEXP (src, 1));
1259 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1261 offset = cfa_temp_value;
1267 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1269 /* Restoring SP from FP in the epilogue. */
1270 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1272 cfa.reg = STACK_POINTER_REGNUM;
1274 else if (XEXP (src, 0) != stack_pointer_rtx)
1277 if (GET_CODE (src) == PLUS)
1279 if (cfa.reg == STACK_POINTER_REGNUM)
1280 cfa.offset += offset;
1281 if (cfa_store.reg == STACK_POINTER_REGNUM)
1282 cfa_store.offset += offset;
1284 else if (dest == hard_frame_pointer_rtx)
1286 /* Either setting the FP from an offset of the SP,
1287 or adjusting the FP */
1288 if (! frame_pointer_needed)
1291 if (GET_CODE (XEXP (src, 0)) == REG
1292 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1293 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1295 offset = INTVAL (XEXP (src, 1));
1296 if (GET_CODE (src) == PLUS)
1298 cfa.offset += offset;
1299 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1306 if (GET_CODE (src) != PLUS
1307 || XEXP (src, 1) != stack_pointer_rtx)
1309 if (GET_CODE (XEXP (src, 0)) != REG
1310 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1312 if (cfa.reg != STACK_POINTER_REGNUM)
1314 cfa_store.reg = REGNO (dest);
1315 cfa_store.offset = cfa.offset - cfa_temp_value;
1320 cfa_temp_reg = REGNO (dest);
1321 cfa_temp_value = INTVAL (src);
1325 if (GET_CODE (XEXP (src, 0)) != REG
1326 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1327 || (unsigned) REGNO (dest) != cfa_temp_reg
1328 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1330 cfa_temp_value |= INTVAL (XEXP (src, 1));
1336 def_cfa_1 (label, &cfa);
1339 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1340 will fill in all of the bits. */
1345 cfa_temp_reg = REGNO (dest);
1346 cfa_temp_value = INTVAL (XEXP (src, 1));
1350 if (GET_CODE (src) != REG)
1353 /* If the src is our current CFA, and it isn't the SP or FP, then we're
1354 going to have to use an indrect mechanism. */
1355 if (REGNO (src) != STACK_POINTER_REGNUM
1356 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1357 && (unsigned) REGNO (src) == cfa.reg)
1359 /* We currently allow this to be ONLY a MEM or MEM + offset. */
1360 rtx x = XEXP (dest, 0);
1362 if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS)
1364 offset = INTVAL (XEXP (x, 1));
1365 if (GET_CODE (x) == MINUS)
1369 if (GET_CODE (x) != REG)
1371 cfa.reg = (unsigned) REGNO (x);
1372 cfa.base_offset = offset;
1374 def_cfa_1 (label, &cfa);
1378 /* Saving a register to the stack. Make sure dest is relative to the
1380 switch (GET_CODE (XEXP (dest, 0)))
1385 offset = GET_MODE_SIZE (GET_MODE (dest));
1386 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1389 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1390 || cfa_store.reg != STACK_POINTER_REGNUM)
1392 cfa_store.offset += offset;
1393 if (cfa.reg == STACK_POINTER_REGNUM)
1394 cfa.offset = cfa_store.offset;
1396 offset = -cfa_store.offset;
1399 /* With an offset. */
1402 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1403 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1406 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1408 offset -= cfa_store.offset;
1411 /* Without an offset. */
1413 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1415 offset = -cfa_store.offset;
1421 def_cfa_1 (label, &cfa);
1422 dwarf2out_reg_save (label, REGNO (src), offset);
1431 /* Record call frame debugging information for INSN, which either
1432 sets SP or FP (adjusting how we calculate the frame address) or saves a
1433 register to the stack. If INSN is NULL_RTX, initialize our state. */
1436 dwarf2out_frame_debug (insn)
1442 if (insn == NULL_RTX)
1444 /* Set up state for generating call frame debug info. */
1446 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1448 cfa.reg = STACK_POINTER_REGNUM;
1455 if (! RTX_FRAME_RELATED_P (insn))
1457 dwarf2out_stack_adjust (insn);
1461 label = dwarf2out_cfi_label ();
1463 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1465 insn = XEXP (src, 0);
1467 insn = PATTERN (insn);
1469 dwarf2out_frame_debug_expr (insn, label);
1472 /* Return the size of an unsigned LEB128 quantity. */
1474 static inline unsigned long
1475 size_of_uleb128 (value)
1476 register unsigned long value;
1478 register unsigned long size = 0;
1479 register unsigned byte;
1483 byte = (value & 0x7f);
1492 /* Return the size of a signed LEB128 quantity. */
1494 static inline unsigned long
1495 size_of_sleb128 (value)
1496 register long value;
1498 register unsigned long size = 0;
1499 register unsigned byte;
1503 byte = (value & 0x7f);
1507 while (!(((value == 0) && ((byte & 0x40) == 0))
1508 || ((value == -1) && ((byte & 0x40) != 0))));
1513 /* Output an unsigned LEB128 quantity. */
1516 output_uleb128 (value)
1517 register unsigned long value;
1519 unsigned long save_value = value;
1521 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1524 register unsigned byte = (value & 0x7f);
1527 /* More bytes to follow. */
1530 fprintf (asm_out_file, "0x%x", byte);
1532 fprintf (asm_out_file, ",");
1537 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1540 /* Output an signed LEB128 quantity. */
1543 output_sleb128 (value)
1544 register long value;
1547 register unsigned byte;
1548 long save_value = value;
1550 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1553 byte = (value & 0x7f);
1554 /* arithmetic shift */
1556 more = !((((value == 0) && ((byte & 0x40) == 0))
1557 || ((value == -1) && ((byte & 0x40) != 0))));
1561 fprintf (asm_out_file, "0x%x", byte);
1563 fprintf (asm_out_file, ",");
1568 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1571 /* Output a Call Frame Information opcode and its operand(s). */
1574 output_cfi (cfi, fde)
1575 register dw_cfi_ref cfi;
1576 register dw_fde_ref fde;
1578 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1580 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1582 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1584 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1585 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1586 fputc ('\n', asm_out_file);
1589 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1591 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1593 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1595 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1596 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1598 fputc ('\n', asm_out_file);
1599 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1600 fputc ('\n', asm_out_file);
1602 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1604 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1606 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1608 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1609 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1611 fputc ('\n', asm_out_file);
1615 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1617 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1618 dwarf_cfi_name (cfi->dw_cfi_opc));
1620 fputc ('\n', asm_out_file);
1621 switch (cfi->dw_cfi_opc)
1623 case DW_CFA_set_loc:
1624 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1625 fputc ('\n', asm_out_file);
1627 case DW_CFA_advance_loc1:
1628 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1629 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1630 fde->dw_fde_current_label);
1631 fputc ('\n', asm_out_file);
1632 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1634 case DW_CFA_advance_loc2:
1635 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1636 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1637 fde->dw_fde_current_label);
1638 fputc ('\n', asm_out_file);
1639 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1641 case DW_CFA_advance_loc4:
1642 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1643 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1644 fde->dw_fde_current_label);
1645 fputc ('\n', asm_out_file);
1646 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1648 #ifdef MIPS_DEBUGGING_INFO
1649 case DW_CFA_MIPS_advance_loc8:
1650 /* TODO: not currently implemented. */
1654 case DW_CFA_offset_extended:
1655 case DW_CFA_GNU_negative_offset_extended:
1656 case DW_CFA_def_cfa:
1657 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1658 fputc ('\n', asm_out_file);
1659 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1660 fputc ('\n', asm_out_file);
1662 case DW_CFA_restore_extended:
1663 case DW_CFA_undefined:
1664 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1665 fputc ('\n', asm_out_file);
1667 case DW_CFA_same_value:
1668 case DW_CFA_def_cfa_register:
1669 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1670 fputc ('\n', asm_out_file);
1672 case DW_CFA_register:
1673 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1674 fputc ('\n', asm_out_file);
1675 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1676 fputc ('\n', asm_out_file);
1678 case DW_CFA_def_cfa_offset:
1679 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1680 fputc ('\n', asm_out_file);
1682 case DW_CFA_GNU_window_save:
1684 case DW_CFA_GNU_args_size:
1685 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1686 fputc ('\n', asm_out_file);
1688 case DW_CFA_def_cfa_expression:
1689 output_cfa_loc (cfi);
1697 /* Output the call frame information used to used to record information
1698 that relates to calculating the frame pointer, and records the
1699 location of saved registers. */
1702 output_call_frame_info (for_eh)
1705 register unsigned long i;
1706 register dw_fde_ref fde;
1707 register dw_cfi_ref cfi;
1708 char l1[20], l2[20];
1709 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1713 /* Do we want to include a pointer to the exception table? */
1714 int eh_ptr = for_eh && exception_table_p ();
1716 /* If we don't have any functions we'll want to unwind out of, don't
1717 emit any EH unwind information. */
1720 for (i = 0; i < fde_table_in_use; ++i)
1721 if (! fde_table[i].nothrow)
1727 fputc ('\n', asm_out_file);
1729 /* We're going to be generating comments, so turn on app. */
1735 #ifdef EH_FRAME_SECTION
1736 EH_FRAME_SECTION ();
1738 tree label = get_file_function_name ('F');
1740 force_data_section ();
1741 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1742 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1743 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1745 assemble_label ("__FRAME_BEGIN__");
1748 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1750 /* Output the CIE. */
1751 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1752 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1753 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1754 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1756 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1758 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1761 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1763 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1766 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1769 fputc ('\n', asm_out_file);
1770 ASM_OUTPUT_LABEL (asm_out_file, l1);
1773 /* Now that the CIE pointer is PC-relative for EH,
1774 use 0 to identify the CIE. */
1775 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1777 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1780 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1782 fputc ('\n', asm_out_file);
1783 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1785 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1786 fputc ('\n', asm_out_file);
1789 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1791 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1793 fputc ('\n', asm_out_file);
1796 /* The CIE contains a pointer to the exception region info for the
1797 frame. Make the augmentation string three bytes (including the
1798 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1799 can't handle unaligned relocs. */
1802 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1803 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1807 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1809 fputc ('\n', asm_out_file);
1811 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1813 fprintf (asm_out_file, "\t%s pointer to exception region info",
1818 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1820 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1824 fputc ('\n', asm_out_file);
1827 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1829 fputc ('\n', asm_out_file);
1830 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1832 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1834 fputc ('\n', asm_out_file);
1835 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1837 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1839 fputc ('\n', asm_out_file);
1841 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1842 output_cfi (cfi, NULL);
1844 /* Pad the CIE out to an address sized boundary. */
1845 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1846 ASM_OUTPUT_LABEL (asm_out_file, l2);
1847 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1848 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1850 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1851 fputc ('\n', asm_out_file);
1854 /* Loop through all of the FDE's. */
1855 for (i = 0; i < fde_table_in_use; ++i)
1857 fde = &fde_table[i];
1859 /* Don't emit EH unwind info for leaf functions. */
1860 if (for_eh && fde->nothrow)
1863 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2);
1864 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2);
1865 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1866 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2);
1868 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1870 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1873 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1875 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1878 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1879 fputc ('\n', asm_out_file);
1880 ASM_OUTPUT_LABEL (asm_out_file, l1);
1882 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1883 emits a target dependent sized offset when for_eh is not true.
1884 This inconsistency may confuse gdb. The only case where we need a
1885 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1886 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1887 though in order to be compatible with the dwarf_fde struct in frame.c.
1888 If the for_eh case is changed, then the struct in frame.c has
1889 to be adjusted appropriately. */
1891 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1893 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1895 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1897 fputc ('\n', asm_out_file);
1898 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1900 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1902 fputc ('\n', asm_out_file);
1903 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1904 fde->dw_fde_end, fde->dw_fde_begin);
1906 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1908 fputc ('\n', asm_out_file);
1910 /* Loop through the Call Frame Instructions associated with
1912 fde->dw_fde_current_label = fde->dw_fde_begin;
1913 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1914 output_cfi (cfi, fde);
1916 /* Pad the FDE out to an address sized boundary. */
1917 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1918 ASM_OUTPUT_LABEL (asm_out_file, l2);
1919 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1920 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1922 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1923 fputc ('\n', asm_out_file);
1926 #ifndef EH_FRAME_SECTION
1929 /* Emit terminating zero for table. */
1930 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1931 fputc ('\n', asm_out_file);
1934 #ifdef MIPS_DEBUGGING_INFO
1935 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1936 get a value of 0. Putting .align 0 after the label fixes it. */
1937 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1940 /* Turn off app to make assembly quicker. */
1945 /* Output a marker (i.e. a label) for the beginning of a function, before
1949 dwarf2out_begin_prologue ()
1951 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1952 register dw_fde_ref fde;
1954 ++current_funcdef_number;
1956 function_section (current_function_decl);
1957 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1958 current_funcdef_number);
1959 ASM_OUTPUT_LABEL (asm_out_file, label);
1960 current_function_func_begin_label = get_identifier (label);
1962 /* Expand the fde table if necessary. */
1963 if (fde_table_in_use == fde_table_allocated)
1965 fde_table_allocated += FDE_TABLE_INCREMENT;
1967 = (dw_fde_ref) xrealloc (fde_table,
1968 fde_table_allocated * sizeof (dw_fde_node));
1971 /* Record the FDE associated with this function. */
1972 current_funcdef_fde = fde_table_in_use;
1974 /* Add the new FDE at the end of the fde_table. */
1975 fde = &fde_table[fde_table_in_use++];
1976 fde->dw_fde_begin = xstrdup (label);
1977 fde->dw_fde_current_label = NULL;
1978 fde->dw_fde_end = NULL;
1979 fde->dw_fde_cfi = NULL;
1980 fde->nothrow = current_function_nothrow;
1982 args_size = old_args_size = 0;
1985 /* Output a marker (i.e. a label) for the absolute end of the generated code
1986 for a function definition. This gets called *after* the epilogue code has
1990 dwarf2out_end_epilogue ()
1993 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1995 /* Output a label to mark the endpoint of the code generated for this
1997 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1998 ASM_OUTPUT_LABEL (asm_out_file, label);
1999 fde = &fde_table[fde_table_in_use - 1];
2000 fde->dw_fde_end = xstrdup (label);
2004 dwarf2out_frame_init ()
2006 /* Allocate the initial hunk of the fde_table. */
2007 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2008 fde_table_allocated = FDE_TABLE_INCREMENT;
2009 fde_table_in_use = 0;
2011 /* Generate the CFA instructions common to all FDE's. Do it now for the
2012 sake of lookup_cfa. */
2014 #ifdef DWARF2_UNWIND_INFO
2015 /* On entry, the Canonical Frame Address is at SP. */
2016 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2017 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2022 dwarf2out_frame_finish ()
2024 /* Output call frame information. */
2025 #ifdef MIPS_DEBUGGING_INFO
2026 if (write_symbols == DWARF2_DEBUG)
2027 output_call_frame_info (0);
2028 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2029 output_call_frame_info (1);
2031 if (write_symbols == DWARF2_DEBUG
2032 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2033 output_call_frame_info (1);
2037 /* And now, the subset of the debugging information support code necessary
2038 for emitting location expressions. */
2040 typedef struct dw_val_struct *dw_val_ref;
2041 typedef struct die_struct *dw_die_ref;
2042 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2044 /* Each DIE may have a series of attribute/value pairs. Values
2045 can take on several forms. The forms that are used in this
2046 implementation are listed below. */
2053 dw_val_class_unsigned_const,
2054 dw_val_class_long_long,
2057 dw_val_class_die_ref,
2058 dw_val_class_fde_ref,
2059 dw_val_class_lbl_id,
2060 dw_val_class_lbl_offset,
2065 /* Describe a double word constant value. */
2066 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2068 typedef struct dw_long_long_struct
2075 /* Describe a floating point constant value. */
2077 typedef struct dw_fp_struct
2084 /* The dw_val_node describes an attribute's value, as it is
2085 represented internally. */
2087 typedef struct dw_val_struct
2089 dw_val_class val_class;
2093 dw_loc_descr_ref val_loc;
2095 long unsigned val_unsigned;
2096 dw_long_long_const val_long_long;
2097 dw_float_const val_float;
2098 dw_die_ref val_die_ref;
2099 unsigned val_fde_index;
2102 unsigned char val_flag;
2108 /* Locations in memory are described using a sequence of stack machine
2111 typedef struct dw_loc_descr_struct
2113 dw_loc_descr_ref dw_loc_next;
2114 enum dwarf_location_atom dw_loc_opc;
2115 dw_val_node dw_loc_oprnd1;
2116 dw_val_node dw_loc_oprnd2;
2120 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2121 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2124 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2126 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2127 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2128 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2129 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2131 /* Convert a DWARF stack opcode into its string name. */
2134 dwarf_stack_op_name (op)
2135 register unsigned op;
2140 return "DW_OP_addr";
2142 return "DW_OP_deref";
2144 return "DW_OP_const1u";
2146 return "DW_OP_const1s";
2148 return "DW_OP_const2u";
2150 return "DW_OP_const2s";
2152 return "DW_OP_const4u";
2154 return "DW_OP_const4s";
2156 return "DW_OP_const8u";
2158 return "DW_OP_const8s";
2160 return "DW_OP_constu";
2162 return "DW_OP_consts";
2166 return "DW_OP_drop";
2168 return "DW_OP_over";
2170 return "DW_OP_pick";
2172 return "DW_OP_swap";
2176 return "DW_OP_xderef";
2184 return "DW_OP_minus";
2196 return "DW_OP_plus";
2197 case DW_OP_plus_uconst:
2198 return "DW_OP_plus_uconst";
2204 return "DW_OP_shra";
2222 return "DW_OP_skip";
2224 return "DW_OP_lit0";
2226 return "DW_OP_lit1";
2228 return "DW_OP_lit2";
2230 return "DW_OP_lit3";
2232 return "DW_OP_lit4";
2234 return "DW_OP_lit5";
2236 return "DW_OP_lit6";
2238 return "DW_OP_lit7";
2240 return "DW_OP_lit8";
2242 return "DW_OP_lit9";
2244 return "DW_OP_lit10";
2246 return "DW_OP_lit11";
2248 return "DW_OP_lit12";
2250 return "DW_OP_lit13";
2252 return "DW_OP_lit14";
2254 return "DW_OP_lit15";
2256 return "DW_OP_lit16";
2258 return "DW_OP_lit17";
2260 return "DW_OP_lit18";
2262 return "DW_OP_lit19";
2264 return "DW_OP_lit20";
2266 return "DW_OP_lit21";
2268 return "DW_OP_lit22";
2270 return "DW_OP_lit23";
2272 return "DW_OP_lit24";
2274 return "DW_OP_lit25";
2276 return "DW_OP_lit26";
2278 return "DW_OP_lit27";
2280 return "DW_OP_lit28";
2282 return "DW_OP_lit29";
2284 return "DW_OP_lit30";
2286 return "DW_OP_lit31";
2288 return "DW_OP_reg0";
2290 return "DW_OP_reg1";
2292 return "DW_OP_reg2";
2294 return "DW_OP_reg3";
2296 return "DW_OP_reg4";
2298 return "DW_OP_reg5";
2300 return "DW_OP_reg6";
2302 return "DW_OP_reg7";
2304 return "DW_OP_reg8";
2306 return "DW_OP_reg9";
2308 return "DW_OP_reg10";
2310 return "DW_OP_reg11";
2312 return "DW_OP_reg12";
2314 return "DW_OP_reg13";
2316 return "DW_OP_reg14";
2318 return "DW_OP_reg15";
2320 return "DW_OP_reg16";
2322 return "DW_OP_reg17";
2324 return "DW_OP_reg18";
2326 return "DW_OP_reg19";
2328 return "DW_OP_reg20";
2330 return "DW_OP_reg21";
2332 return "DW_OP_reg22";
2334 return "DW_OP_reg23";
2336 return "DW_OP_reg24";
2338 return "DW_OP_reg25";
2340 return "DW_OP_reg26";
2342 return "DW_OP_reg27";
2344 return "DW_OP_reg28";
2346 return "DW_OP_reg29";
2348 return "DW_OP_reg30";
2350 return "DW_OP_reg31";
2352 return "DW_OP_breg0";
2354 return "DW_OP_breg1";
2356 return "DW_OP_breg2";
2358 return "DW_OP_breg3";
2360 return "DW_OP_breg4";
2362 return "DW_OP_breg5";
2364 return "DW_OP_breg6";
2366 return "DW_OP_breg7";
2368 return "DW_OP_breg8";
2370 return "DW_OP_breg9";
2372 return "DW_OP_breg10";
2374 return "DW_OP_breg11";
2376 return "DW_OP_breg12";
2378 return "DW_OP_breg13";
2380 return "DW_OP_breg14";
2382 return "DW_OP_breg15";
2384 return "DW_OP_breg16";
2386 return "DW_OP_breg17";
2388 return "DW_OP_breg18";
2390 return "DW_OP_breg19";
2392 return "DW_OP_breg20";
2394 return "DW_OP_breg21";
2396 return "DW_OP_breg22";
2398 return "DW_OP_breg23";
2400 return "DW_OP_breg24";
2402 return "DW_OP_breg25";
2404 return "DW_OP_breg26";
2406 return "DW_OP_breg27";
2408 return "DW_OP_breg28";
2410 return "DW_OP_breg29";
2412 return "DW_OP_breg30";
2414 return "DW_OP_breg31";
2416 return "DW_OP_regx";
2418 return "DW_OP_fbreg";
2420 return "DW_OP_bregx";
2422 return "DW_OP_piece";
2423 case DW_OP_deref_size:
2424 return "DW_OP_deref_size";
2425 case DW_OP_xderef_size:
2426 return "DW_OP_xderef_size";
2430 return "OP_<unknown>";
2435 /* Return a pointer to a newly allocated location description. Location
2436 descriptions are simple expression terms that can be strung
2437 together to form more complicated location (address) descriptions. */
2439 static inline dw_loc_descr_ref
2440 new_loc_descr (op, oprnd1, oprnd2)
2441 register enum dwarf_location_atom op;
2442 register unsigned long oprnd1;
2443 register unsigned long oprnd2;
2445 register dw_loc_descr_ref descr
2446 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
2448 descr->dw_loc_next = NULL;
2449 descr->dw_loc_opc = op;
2450 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2451 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2452 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2453 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2458 /* Add a location description term to a location description expression. */
2461 add_loc_descr (list_head, descr)
2462 register dw_loc_descr_ref *list_head;
2463 register dw_loc_descr_ref descr;
2465 register dw_loc_descr_ref *d;
2467 /* Find the end of the chain. */
2468 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2474 /* Return the size of a location descriptor. */
2476 static unsigned long
2477 size_of_loc_descr (loc)
2478 register dw_loc_descr_ref loc;
2480 register unsigned long size = 1;
2482 switch (loc->dw_loc_opc)
2485 size += DWARF2_ADDR_SIZE;
2504 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2507 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2512 case DW_OP_plus_uconst:
2513 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2551 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2554 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2557 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2560 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2561 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2564 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2566 case DW_OP_deref_size:
2567 case DW_OP_xderef_size:
2577 /* Return the size of a series of location descriptors. */
2579 static unsigned long
2581 register dw_loc_descr_ref loc;
2583 register unsigned long size = 0;
2585 for (; loc != NULL; loc = loc->dw_loc_next)
2586 size += size_of_loc_descr (loc);
2591 /* Output location description stack opcode's operands (if any). */
2594 output_loc_operands (loc)
2595 register dw_loc_descr_ref loc;
2597 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2598 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2600 switch (loc->dw_loc_opc)
2603 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
2604 fputc ('\n', asm_out_file);
2608 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2609 fputc ('\n', asm_out_file);
2613 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2614 fputc ('\n', asm_out_file);
2618 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
2619 fputc ('\n', asm_out_file);
2624 fputc ('\n', asm_out_file);
2627 output_uleb128 (val1->v.val_unsigned);
2628 fputc ('\n', asm_out_file);
2631 output_sleb128 (val1->v.val_int);
2632 fputc ('\n', asm_out_file);
2635 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
2636 fputc ('\n', asm_out_file);
2638 case DW_OP_plus_uconst:
2639 output_uleb128 (val1->v.val_unsigned);
2640 fputc ('\n', asm_out_file);
2644 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2645 fputc ('\n', asm_out_file);
2679 output_sleb128 (val1->v.val_int);
2680 fputc ('\n', asm_out_file);
2683 output_uleb128 (val1->v.val_unsigned);
2684 fputc ('\n', asm_out_file);
2687 output_sleb128 (val1->v.val_int);
2688 fputc ('\n', asm_out_file);
2691 output_uleb128 (val1->v.val_unsigned);
2692 fputc ('\n', asm_out_file);
2693 output_sleb128 (val2->v.val_int);
2694 fputc ('\n', asm_out_file);
2697 output_uleb128 (val1->v.val_unsigned);
2698 fputc ('\n', asm_out_file);
2700 case DW_OP_deref_size:
2701 case DW_OP_xderef_size:
2702 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2703 fputc ('\n', asm_out_file);
2710 /* Output a sequence of location operations. */
2713 output_loc_sequence (loc)
2714 dw_loc_descr_ref loc;
2716 for (; loc != NULL; loc = loc->dw_loc_next)
2718 /* Output the opcode. */
2719 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
2721 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
2722 dwarf_stack_op_name (loc->dw_loc_opc));
2724 fputc ('\n', asm_out_file);
2726 /* Output the operand(s) (if any). */
2727 output_loc_operands (loc);
2731 /* This routine will generate the correct assembly data for a location
2732 description based on a cfi entry with a complex address. */
2735 output_cfa_loc (cfi)
2738 dw_loc_descr_ref loc;
2741 /* Output the size of the block. */
2742 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2743 size = size_of_locs (loc);
2744 output_uleb128 (size);
2745 fputc ('\n', asm_out_file);
2747 /* Now output the operations themselves. */
2748 output_loc_sequence (loc);
2751 /* This function builds a dwarf location descriptor seqeunce from
2752 a dw_cfa_location. */
2754 static struct dw_loc_descr_struct *
2756 dw_cfa_location *cfa;
2758 struct dw_loc_descr_struct *head, *tmp;
2760 if (cfa->indirect == 0)
2763 if (cfa->base_offset)
2764 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2766 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2767 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2768 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2769 add_loc_descr (&head, tmp);
2770 if (cfa->offset != 0)
2772 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2773 add_loc_descr (&head, tmp);
2778 /* This function fills in aa dw_cfa_location structure from a
2779 dwarf location descriptor sequence. */
2782 get_cfa_from_loc_descr (cfa, loc)
2783 dw_cfa_location *cfa;
2784 struct dw_loc_descr_struct * loc;
2786 struct dw_loc_descr_struct * ptr;
2788 cfa->base_offset = 0;
2792 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2794 enum dwarf_location_atom op = ptr->dw_loc_opc;
2829 cfa->reg = op - DW_OP_reg0;
2832 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2866 cfa->reg = op - DW_OP_breg0;
2867 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2870 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2871 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2876 case DW_OP_plus_uconst:
2877 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2880 fatal ("DW_LOC_OP %s not implememnted yet.\n",
2881 dwarf_stack_op_name (ptr->dw_loc_opc));
2885 #endif /* .debug_frame support */
2887 /* And now, the support for symbolic debugging information. */
2888 #ifdef DWARF2_DEBUGGING_INFO
2890 /* NOTE: In the comments in this file, many references are made to
2891 "Debugging Information Entries". This term is abbreviated as `DIE'
2892 throughout the remainder of this file. */
2894 /* An internal representation of the DWARF output is built, and then
2895 walked to generate the DWARF debugging info. The walk of the internal
2896 representation is done after the entire program has been compiled.
2897 The types below are used to describe the internal representation. */
2899 /* Various DIE's use offsets relative to the beginning of the
2900 .debug_info section to refer to each other. */
2902 typedef long int dw_offset;
2904 /* Define typedefs here to avoid circular dependencies. */
2906 typedef struct dw_attr_struct *dw_attr_ref;
2907 typedef struct dw_line_info_struct *dw_line_info_ref;
2908 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
2909 typedef struct pubname_struct *pubname_ref;
2910 typedef dw_die_ref *arange_ref;
2912 /* Each entry in the line_info_table maintains the file and
2913 line number associated with the label generated for that
2914 entry. The label gives the PC value associated with
2915 the line number entry. */
2917 typedef struct dw_line_info_struct
2919 unsigned long dw_file_num;
2920 unsigned long dw_line_num;
2924 /* Line information for functions in separate sections; each one gets its
2926 typedef struct dw_separate_line_info_struct
2928 unsigned long dw_file_num;
2929 unsigned long dw_line_num;
2930 unsigned long function;
2932 dw_separate_line_info_entry;
2934 /* Each DIE attribute has a field specifying the attribute kind,
2935 a link to the next attribute in the chain, and an attribute value.
2936 Attributes are typically linked below the DIE they modify. */
2938 typedef struct dw_attr_struct
2940 enum dwarf_attribute dw_attr;
2941 dw_attr_ref dw_attr_next;
2942 dw_val_node dw_attr_val;
2946 /* The Debugging Information Entry (DIE) structure */
2948 typedef struct die_struct
2950 enum dwarf_tag die_tag;
2951 dw_attr_ref die_attr;
2952 dw_die_ref die_parent;
2953 dw_die_ref die_child;
2955 dw_offset die_offset;
2956 unsigned long die_abbrev;
2960 /* The pubname structure */
2962 typedef struct pubname_struct
2969 /* The limbo die list structure. */
2970 typedef struct limbo_die_struct
2973 struct limbo_die_struct *next;
2977 /* How to start an assembler comment. */
2978 #ifndef ASM_COMMENT_START
2979 #define ASM_COMMENT_START ";#"
2982 /* Define a macro which returns non-zero for a TYPE_DECL which was
2983 implicitly generated for a tagged type.
2985 Note that unlike the gcc front end (which generates a NULL named
2986 TYPE_DECL node for each complete tagged type, each array type, and
2987 each function type node created) the g++ front end generates a
2988 _named_ TYPE_DECL node for each tagged type node created.
2989 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2990 generate a DW_TAG_typedef DIE for them. */
2992 #define TYPE_DECL_IS_STUB(decl) \
2993 (DECL_NAME (decl) == NULL_TREE \
2994 || (DECL_ARTIFICIAL (decl) \
2995 && is_tagged_type (TREE_TYPE (decl)) \
2996 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2997 /* This is necessary for stub decls that \
2998 appear in nested inline functions. */ \
2999 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3000 && (decl_ultimate_origin (decl) \
3001 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3003 /* Information concerning the compilation unit's programming
3004 language, and compiler version. */
3006 extern int flag_traditional;
3008 /* Fixed size portion of the DWARF compilation unit header. */
3009 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3011 /* Fixed size portion of debugging line information prolog. */
3012 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3014 /* Fixed size portion of public names info. */
3015 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3017 /* Fixed size portion of the address range info. */
3018 #define DWARF_ARANGES_HEADER_SIZE \
3019 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3020 - DWARF_OFFSET_SIZE)
3022 /* Size of padding portion in the address range info. It must be
3023 aligned to twice the pointer size. */
3024 #define DWARF_ARANGES_PAD_SIZE \
3025 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3026 - (2 * DWARF_OFFSET_SIZE + 4))
3028 /* The default is to have gcc emit the line number tables. */
3029 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3030 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3033 /* Define the architecture-dependent minimum instruction length (in bytes).
3034 In this implementation of DWARF, this field is used for information
3035 purposes only. Since GCC generates assembly language, we have
3036 no a priori knowledge of how many instruction bytes are generated
3037 for each source line, and therefore can use only the DW_LNE_set_address
3038 and DW_LNS_fixed_advance_pc line information commands. */
3040 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3041 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3044 /* Minimum line offset in a special line info. opcode.
3045 This value was chosen to give a reasonable range of values. */
3046 #define DWARF_LINE_BASE -10
3048 /* First special line opcde - leave room for the standard opcodes. */
3049 #define DWARF_LINE_OPCODE_BASE 10
3051 /* Range of line offsets in a special line info. opcode. */
3052 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3054 /* Flag that indicates the initial value of the is_stmt_start flag.
3055 In the present implementation, we do not mark any lines as
3056 the beginning of a source statement, because that information
3057 is not made available by the GCC front-end. */
3058 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3060 /* This location is used by calc_die_sizes() to keep track
3061 the offset of each DIE within the .debug_info section. */
3062 static unsigned long next_die_offset;
3064 /* Record the root of the DIE's built for the current compilation unit. */
3065 static dw_die_ref comp_unit_die;
3067 /* A list of DIEs with a NULL parent waiting to be relocated. */
3068 static limbo_die_node *limbo_die_list = 0;
3070 /* Pointer to an array of filenames referenced by this compilation unit. */
3071 static char **file_table;
3073 /* Total number of entries in the table (i.e. array) pointed to by
3074 `file_table'. This is the *total* and includes both used and unused
3076 static unsigned file_table_allocated;
3078 /* Number of entries in the file_table which are actually in use. */
3079 static unsigned file_table_in_use;
3081 /* Size (in elements) of increments by which we may expand the filename
3083 #define FILE_TABLE_INCREMENT 64
3085 /* Local pointer to the name of the main input file. Initialized in
3087 static const char *primary_filename;
3089 /* A pointer to the base of a table of references to DIE's that describe
3090 declarations. The table is indexed by DECL_UID() which is a unique
3091 number identifying each decl. */
3092 static dw_die_ref *decl_die_table;
3094 /* Number of elements currently allocated for the decl_die_table. */
3095 static unsigned decl_die_table_allocated;
3097 /* Number of elements in decl_die_table currently in use. */
3098 static unsigned decl_die_table_in_use;
3100 /* Size (in elements) of increments by which we may expand the
3102 #define DECL_DIE_TABLE_INCREMENT 256
3104 /* A pointer to the base of a table of references to declaration
3105 scopes. This table is a display which tracks the nesting
3106 of declaration scopes at the current scope and containing
3107 scopes. This table is used to find the proper place to
3108 define type declaration DIE's. */
3109 static tree *decl_scope_table;
3111 /* Number of elements currently allocated for the decl_scope_table. */
3112 static int decl_scope_table_allocated;
3114 /* Current level of nesting of declaration scopes. */
3115 static int decl_scope_depth;
3117 /* Size (in elements) of increments by which we may expand the
3118 decl_scope_table. */
3119 #define DECL_SCOPE_TABLE_INCREMENT 64
3121 /* A pointer to the base of a list of references to DIE's that
3122 are uniquely identified by their tag, presence/absence of
3123 children DIE's, and list of attribute/value pairs. */
3124 static dw_die_ref *abbrev_die_table;
3126 /* Number of elements currently allocated for abbrev_die_table. */
3127 static unsigned abbrev_die_table_allocated;
3129 /* Number of elements in type_die_table currently in use. */
3130 static unsigned abbrev_die_table_in_use;
3132 /* Size (in elements) of increments by which we may expand the
3133 abbrev_die_table. */
3134 #define ABBREV_DIE_TABLE_INCREMENT 256
3136 /* A pointer to the base of a table that contains line information
3137 for each source code line in .text in the compilation unit. */
3138 static dw_line_info_ref line_info_table;
3140 /* Number of elements currently allocated for line_info_table. */
3141 static unsigned line_info_table_allocated;
3143 /* Number of elements in separate_line_info_table currently in use. */
3144 static unsigned separate_line_info_table_in_use;
3146 /* A pointer to the base of a table that contains line information
3147 for each source code line outside of .text in the compilation unit. */
3148 static dw_separate_line_info_ref separate_line_info_table;
3150 /* Number of elements currently allocated for separate_line_info_table. */
3151 static unsigned separate_line_info_table_allocated;
3153 /* Number of elements in line_info_table currently in use. */
3154 static unsigned line_info_table_in_use;
3156 /* Size (in elements) of increments by which we may expand the
3158 #define LINE_INFO_TABLE_INCREMENT 1024
3160 /* A pointer to the base of a table that contains a list of publicly
3161 accessible names. */
3162 static pubname_ref pubname_table;
3164 /* Number of elements currently allocated for pubname_table. */
3165 static unsigned pubname_table_allocated;
3167 /* Number of elements in pubname_table currently in use. */
3168 static unsigned pubname_table_in_use;
3170 /* Size (in elements) of increments by which we may expand the
3172 #define PUBNAME_TABLE_INCREMENT 64
3174 /* A pointer to the base of a table that contains a list of publicly
3175 accessible names. */
3176 static arange_ref arange_table;
3178 /* Number of elements currently allocated for arange_table. */
3179 static unsigned arange_table_allocated;
3181 /* Number of elements in arange_table currently in use. */
3182 static unsigned arange_table_in_use;
3184 /* Size (in elements) of increments by which we may expand the
3186 #define ARANGE_TABLE_INCREMENT 64
3188 /* A pointer to the base of a list of incomplete types which might be
3189 completed at some later time. */
3191 static tree *incomplete_types_list;
3193 /* Number of elements currently allocated for the incomplete_types_list. */
3194 static unsigned incomplete_types_allocated;
3196 /* Number of elements of incomplete_types_list currently in use. */
3197 static unsigned incomplete_types;
3199 /* Size (in elements) of increments by which we may expand the incomplete
3200 types list. Actually, a single hunk of space of this size should
3201 be enough for most typical programs. */
3202 #define INCOMPLETE_TYPES_INCREMENT 64
3204 /* Record whether the function being analyzed contains inlined functions. */
3205 static int current_function_has_inlines;
3206 #if 0 && defined (MIPS_DEBUGGING_INFO)
3207 static int comp_unit_has_inlines;
3210 /* Array of RTXes referenced by the debugging information, which therefore
3211 must be kept around forever. We do this rather than perform GC on
3212 the dwarf info because almost all of the dwarf info lives forever, and
3213 it's easier to support non-GC frontends this way. */
3214 static varray_type used_rtx_varray;
3216 /* Forward declarations for functions defined in this file. */
3218 static int is_pseudo_reg PARAMS ((rtx));
3219 static tree type_main_variant PARAMS ((tree));
3220 static int is_tagged_type PARAMS ((tree));
3221 static const char *dwarf_tag_name PARAMS ((unsigned));
3222 static const char *dwarf_attr_name PARAMS ((unsigned));
3223 static const char *dwarf_form_name PARAMS ((unsigned));
3225 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3227 static tree decl_ultimate_origin PARAMS ((tree));
3228 static tree block_ultimate_origin PARAMS ((tree));
3229 static tree decl_class_context PARAMS ((tree));
3230 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3231 static void add_AT_flag PARAMS ((dw_die_ref,
3232 enum dwarf_attribute,
3234 static void add_AT_int PARAMS ((dw_die_ref,
3235 enum dwarf_attribute, long));
3236 static void add_AT_unsigned PARAMS ((dw_die_ref,
3237 enum dwarf_attribute,
3239 static void add_AT_long_long PARAMS ((dw_die_ref,
3240 enum dwarf_attribute,
3243 static void add_AT_float PARAMS ((dw_die_ref,
3244 enum dwarf_attribute,
3246 static void add_AT_string PARAMS ((dw_die_ref,
3247 enum dwarf_attribute,
3249 static void add_AT_die_ref PARAMS ((dw_die_ref,
3250 enum dwarf_attribute,
3252 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3253 enum dwarf_attribute,
3255 static void add_AT_loc PARAMS ((dw_die_ref,
3256 enum dwarf_attribute,
3258 static void add_AT_addr PARAMS ((dw_die_ref,
3259 enum dwarf_attribute,
3261 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3262 enum dwarf_attribute,
3264 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3265 enum dwarf_attribute,
3267 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3268 enum dwarf_attribute));
3269 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3270 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3271 static const char *get_AT_string PARAMS ((dw_die_ref,
3272 enum dwarf_attribute));
3273 static int get_AT_flag PARAMS ((dw_die_ref,
3274 enum dwarf_attribute));
3275 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3276 enum dwarf_attribute));
3277 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3278 enum dwarf_attribute));
3279 static int is_c_family PARAMS ((void));
3280 static int is_fortran PARAMS ((void));
3281 static void remove_AT PARAMS ((dw_die_ref,
3282 enum dwarf_attribute));
3283 static void remove_children PARAMS ((dw_die_ref));
3284 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3285 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3286 static dw_die_ref lookup_type_die PARAMS ((tree));
3287 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3288 static dw_die_ref lookup_decl_die PARAMS ((tree));
3289 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3290 static void print_spaces PARAMS ((FILE *));
3291 static void print_die PARAMS ((dw_die_ref, FILE *));
3292 static void print_dwarf_line_table PARAMS ((FILE *));
3293 static void add_sibling_attributes PARAMS ((dw_die_ref));
3294 static void build_abbrev_table PARAMS ((dw_die_ref));
3295 static unsigned long size_of_string PARAMS ((const char *));
3296 static int constant_size PARAMS ((long unsigned));
3297 static unsigned long size_of_die PARAMS ((dw_die_ref));
3298 static void calc_die_sizes PARAMS ((dw_die_ref));
3299 static unsigned long size_of_line_prolog PARAMS ((void));
3300 static unsigned long size_of_pubnames PARAMS ((void));
3301 static unsigned long size_of_aranges PARAMS ((void));
3302 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3303 static void output_value_format PARAMS ((dw_attr_ref));
3304 static void output_abbrev_section PARAMS ((void));
3305 static void output_die PARAMS ((dw_die_ref));
3306 static void output_compilation_unit_header PARAMS ((void));
3307 static const char *dwarf2_name PARAMS ((tree, int));
3308 static void add_pubname PARAMS ((tree, dw_die_ref));
3309 static void output_pubnames PARAMS ((void));
3310 static void add_arange PARAMS ((tree, dw_die_ref));
3311 static void output_aranges PARAMS ((void));
3312 static void output_line_info PARAMS ((void));
3313 static dw_die_ref base_type_die PARAMS ((tree));
3314 static tree root_type PARAMS ((tree));
3315 static int is_base_type PARAMS ((tree));
3316 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3317 static int type_is_enum PARAMS ((tree));
3318 static unsigned int reg_number PARAMS ((rtx));
3319 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3320 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3321 static int is_based_loc PARAMS ((rtx));
3322 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3323 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3324 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3325 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3326 static tree field_type PARAMS ((tree));
3327 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3328 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3329 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3330 static void add_AT_location_description PARAMS ((dw_die_ref,
3331 enum dwarf_attribute, rtx));
3332 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3333 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3334 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3335 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3336 static void add_bound_info PARAMS ((dw_die_ref,
3337 enum dwarf_attribute, tree));
3338 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3339 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3340 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3341 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3342 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3343 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3344 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3345 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3346 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3347 static void push_decl_scope PARAMS ((tree));
3348 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3349 static void pop_decl_scope PARAMS ((void));
3350 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3352 static const char *type_tag PARAMS ((tree));
3353 static tree member_declared_type PARAMS ((tree));
3355 static const char *decl_start_label PARAMS ((tree));
3357 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3358 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3360 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3362 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3363 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3364 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3365 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3366 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3367 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3368 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3369 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3370 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3371 static void gen_label_die PARAMS ((tree, dw_die_ref));
3372 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3373 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3374 static void gen_field_die PARAMS ((tree, dw_die_ref));
3375 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3376 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3377 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3378 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3379 static void gen_member_die PARAMS ((tree, dw_die_ref));
3380 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3381 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3382 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3383 static void gen_type_die PARAMS ((tree, dw_die_ref));
3384 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3385 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3386 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3387 static int is_redundant_typedef PARAMS ((tree));
3388 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3389 static unsigned lookup_filename PARAMS ((const char *));
3390 static void add_incomplete_type PARAMS ((tree));
3391 static void retry_incomplete_types PARAMS ((void));
3392 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3393 static void gen_abstract_function PARAMS ((tree));
3394 static rtx save_rtx PARAMS ((rtx));
3395 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3396 static void reverse_die_lists PARAMS ((dw_die_ref));
3398 /* Section names used to hold DWARF debugging information. */
3399 #ifndef DEBUG_INFO_SECTION
3400 #define DEBUG_INFO_SECTION ".debug_info"
3402 #ifndef ABBREV_SECTION
3403 #define ABBREV_SECTION ".debug_abbrev"
3405 #ifndef ARANGES_SECTION
3406 #define ARANGES_SECTION ".debug_aranges"
3408 #ifndef DW_MACINFO_SECTION
3409 #define DW_MACINFO_SECTION ".debug_macinfo"
3411 #ifndef DEBUG_LINE_SECTION
3412 #define DEBUG_LINE_SECTION ".debug_line"
3415 #define LOC_SECTION ".debug_loc"
3417 #ifndef PUBNAMES_SECTION
3418 #define PUBNAMES_SECTION ".debug_pubnames"
3421 #define STR_SECTION ".debug_str"
3424 /* Standard ELF section names for compiled code and data. */
3425 #ifndef TEXT_SECTION
3426 #define TEXT_SECTION ".text"
3428 #ifndef DATA_SECTION
3429 #define DATA_SECTION ".data"
3432 #define BSS_SECTION ".bss"
3435 /* Labels we insert at beginning sections we can reference instead of
3436 the section names themselves. */
3438 #ifndef TEXT_SECTION_LABEL
3439 #define TEXT_SECTION_LABEL "Ltext"
3441 #ifndef DEBUG_LINE_SECTION_LABEL
3442 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3444 #ifndef DEBUG_INFO_SECTION_LABEL
3445 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3447 #ifndef ABBREV_SECTION_LABEL
3448 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3452 /* Definitions of defaults for formats and names of various special
3453 (artificial) labels which may be generated within this file (when the -g
3454 options is used and DWARF_DEBUGGING_INFO is in effect.
3455 If necessary, these may be overridden from within the tm.h file, but
3456 typically, overriding these defaults is unnecessary. */
3458 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3459 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3460 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3461 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3462 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3464 #ifndef TEXT_END_LABEL
3465 #define TEXT_END_LABEL "Letext"
3467 #ifndef DATA_END_LABEL
3468 #define DATA_END_LABEL "Ledata"
3470 #ifndef BSS_END_LABEL
3471 #define BSS_END_LABEL "Lebss"
3473 #ifndef INSN_LABEL_FMT
3474 #define INSN_LABEL_FMT "LI%u_"
3476 #ifndef BLOCK_BEGIN_LABEL
3477 #define BLOCK_BEGIN_LABEL "LBB"
3479 #ifndef BLOCK_END_LABEL
3480 #define BLOCK_END_LABEL "LBE"
3482 #ifndef BODY_BEGIN_LABEL
3483 #define BODY_BEGIN_LABEL "Lbb"
3485 #ifndef BODY_END_LABEL
3486 #define BODY_END_LABEL "Lbe"
3488 #ifndef LINE_CODE_LABEL
3489 #define LINE_CODE_LABEL "LM"
3491 #ifndef SEPARATE_LINE_CODE_LABEL
3492 #define SEPARATE_LINE_CODE_LABEL "LSM"
3495 /* We allow a language front-end to designate a function that is to be
3496 called to "demangle" any name before it it put into a DIE. */
3498 static const char *(*demangle_name_func) PARAMS ((const char *));
3501 dwarf2out_set_demangle_name_func (func)
3502 const char *(*func) PARAMS ((const char *));
3504 demangle_name_func = func;
3507 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3508 that means adding it to used_rtx_varray. If not, that means making
3509 a copy on the permanent_obstack. */
3516 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3519 push_obstacks_nochange ();
3520 end_temporary_allocation ();
3521 orig = copy_rtx (orig);
3528 /* Test if rtl node points to a pseudo register. */
3534 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3535 || (GET_CODE (rtl) == SUBREG
3536 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3539 /* Return a reference to a type, with its const and volatile qualifiers
3543 type_main_variant (type)
3546 type = TYPE_MAIN_VARIANT (type);
3548 /* There really should be only one main variant among any group of variants
3549 of a given type (and all of the MAIN_VARIANT values for all members of
3550 the group should point to that one type) but sometimes the C front-end
3551 messes this up for array types, so we work around that bug here. */
3553 if (TREE_CODE (type) == ARRAY_TYPE)
3554 while (type != TYPE_MAIN_VARIANT (type))
3555 type = TYPE_MAIN_VARIANT (type);
3560 /* Return non-zero if the given type node represents a tagged type. */
3563 is_tagged_type (type)
3566 register enum tree_code code = TREE_CODE (type);
3568 return (code == RECORD_TYPE || code == UNION_TYPE
3569 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3572 /* Convert a DIE tag into its string name. */
3575 dwarf_tag_name (tag)
3576 register unsigned tag;
3580 case DW_TAG_padding:
3581 return "DW_TAG_padding";
3582 case DW_TAG_array_type:
3583 return "DW_TAG_array_type";
3584 case DW_TAG_class_type:
3585 return "DW_TAG_class_type";
3586 case DW_TAG_entry_point:
3587 return "DW_TAG_entry_point";
3588 case DW_TAG_enumeration_type:
3589 return "DW_TAG_enumeration_type";
3590 case DW_TAG_formal_parameter:
3591 return "DW_TAG_formal_parameter";
3592 case DW_TAG_imported_declaration:
3593 return "DW_TAG_imported_declaration";
3595 return "DW_TAG_label";
3596 case DW_TAG_lexical_block:
3597 return "DW_TAG_lexical_block";
3599 return "DW_TAG_member";
3600 case DW_TAG_pointer_type:
3601 return "DW_TAG_pointer_type";
3602 case DW_TAG_reference_type:
3603 return "DW_TAG_reference_type";
3604 case DW_TAG_compile_unit:
3605 return "DW_TAG_compile_unit";
3606 case DW_TAG_string_type:
3607 return "DW_TAG_string_type";
3608 case DW_TAG_structure_type:
3609 return "DW_TAG_structure_type";
3610 case DW_TAG_subroutine_type:
3611 return "DW_TAG_subroutine_type";
3612 case DW_TAG_typedef:
3613 return "DW_TAG_typedef";
3614 case DW_TAG_union_type:
3615 return "DW_TAG_union_type";
3616 case DW_TAG_unspecified_parameters:
3617 return "DW_TAG_unspecified_parameters";
3618 case DW_TAG_variant:
3619 return "DW_TAG_variant";
3620 case DW_TAG_common_block:
3621 return "DW_TAG_common_block";
3622 case DW_TAG_common_inclusion:
3623 return "DW_TAG_common_inclusion";
3624 case DW_TAG_inheritance:
3625 return "DW_TAG_inheritance";
3626 case DW_TAG_inlined_subroutine:
3627 return "DW_TAG_inlined_subroutine";
3629 return "DW_TAG_module";
3630 case DW_TAG_ptr_to_member_type:
3631 return "DW_TAG_ptr_to_member_type";
3632 case DW_TAG_set_type:
3633 return "DW_TAG_set_type";
3634 case DW_TAG_subrange_type:
3635 return "DW_TAG_subrange_type";
3636 case DW_TAG_with_stmt:
3637 return "DW_TAG_with_stmt";
3638 case DW_TAG_access_declaration:
3639 return "DW_TAG_access_declaration";
3640 case DW_TAG_base_type:
3641 return "DW_TAG_base_type";
3642 case DW_TAG_catch_block:
3643 return "DW_TAG_catch_block";
3644 case DW_TAG_const_type:
3645 return "DW_TAG_const_type";
3646 case DW_TAG_constant:
3647 return "DW_TAG_constant";
3648 case DW_TAG_enumerator:
3649 return "DW_TAG_enumerator";
3650 case DW_TAG_file_type:
3651 return "DW_TAG_file_type";
3653 return "DW_TAG_friend";
3654 case DW_TAG_namelist:
3655 return "DW_TAG_namelist";
3656 case DW_TAG_namelist_item:
3657 return "DW_TAG_namelist_item";
3658 case DW_TAG_packed_type:
3659 return "DW_TAG_packed_type";
3660 case DW_TAG_subprogram:
3661 return "DW_TAG_subprogram";
3662 case DW_TAG_template_type_param:
3663 return "DW_TAG_template_type_param";
3664 case DW_TAG_template_value_param:
3665 return "DW_TAG_template_value_param";
3666 case DW_TAG_thrown_type:
3667 return "DW_TAG_thrown_type";
3668 case DW_TAG_try_block:
3669 return "DW_TAG_try_block";
3670 case DW_TAG_variant_part:
3671 return "DW_TAG_variant_part";
3672 case DW_TAG_variable:
3673 return "DW_TAG_variable";
3674 case DW_TAG_volatile_type:
3675 return "DW_TAG_volatile_type";
3676 case DW_TAG_MIPS_loop:
3677 return "DW_TAG_MIPS_loop";
3678 case DW_TAG_format_label:
3679 return "DW_TAG_format_label";
3680 case DW_TAG_function_template:
3681 return "DW_TAG_function_template";
3682 case DW_TAG_class_template:
3683 return "DW_TAG_class_template";
3685 return "DW_TAG_<unknown>";
3689 /* Convert a DWARF attribute code into its string name. */
3692 dwarf_attr_name (attr)
3693 register unsigned attr;
3698 return "DW_AT_sibling";
3699 case DW_AT_location:
3700 return "DW_AT_location";
3702 return "DW_AT_name";
3703 case DW_AT_ordering:
3704 return "DW_AT_ordering";
3705 case DW_AT_subscr_data:
3706 return "DW_AT_subscr_data";
3707 case DW_AT_byte_size:
3708 return "DW_AT_byte_size";
3709 case DW_AT_bit_offset:
3710 return "DW_AT_bit_offset";
3711 case DW_AT_bit_size:
3712 return "DW_AT_bit_size";
3713 case DW_AT_element_list:
3714 return "DW_AT_element_list";
3715 case DW_AT_stmt_list:
3716 return "DW_AT_stmt_list";
3718 return "DW_AT_low_pc";
3720 return "DW_AT_high_pc";
3721 case DW_AT_language:
3722 return "DW_AT_language";
3724 return "DW_AT_member";
3726 return "DW_AT_discr";
3727 case DW_AT_discr_value:
3728 return "DW_AT_discr_value";
3729 case DW_AT_visibility:
3730 return "DW_AT_visibility";
3732 return "DW_AT_import";
3733 case DW_AT_string_length:
3734 return "DW_AT_string_length";
3735 case DW_AT_common_reference:
3736 return "DW_AT_common_reference";
3737 case DW_AT_comp_dir:
3738 return "DW_AT_comp_dir";
3739 case DW_AT_const_value:
3740 return "DW_AT_const_value";
3741 case DW_AT_containing_type:
3742 return "DW_AT_containing_type";
3743 case DW_AT_default_value:
3744 return "DW_AT_default_value";
3746 return "DW_AT_inline";
3747 case DW_AT_is_optional:
3748 return "DW_AT_is_optional";
3749 case DW_AT_lower_bound:
3750 return "DW_AT_lower_bound";
3751 case DW_AT_producer:
3752 return "DW_AT_producer";
3753 case DW_AT_prototyped:
3754 return "DW_AT_prototyped";
3755 case DW_AT_return_addr:
3756 return "DW_AT_return_addr";
3757 case DW_AT_start_scope:
3758 return "DW_AT_start_scope";
3759 case DW_AT_stride_size:
3760 return "DW_AT_stride_size";
3761 case DW_AT_upper_bound:
3762 return "DW_AT_upper_bound";
3763 case DW_AT_abstract_origin:
3764 return "DW_AT_abstract_origin";
3765 case DW_AT_accessibility:
3766 return "DW_AT_accessibility";
3767 case DW_AT_address_class:
3768 return "DW_AT_address_class";
3769 case DW_AT_artificial:
3770 return "DW_AT_artificial";
3771 case DW_AT_base_types:
3772 return "DW_AT_base_types";
3773 case DW_AT_calling_convention:
3774 return "DW_AT_calling_convention";
3776 return "DW_AT_count";
3777 case DW_AT_data_member_location:
3778 return "DW_AT_data_member_location";
3779 case DW_AT_decl_column:
3780 return "DW_AT_decl_column";
3781 case DW_AT_decl_file:
3782 return "DW_AT_decl_file";
3783 case DW_AT_decl_line:
3784 return "DW_AT_decl_line";
3785 case DW_AT_declaration:
3786 return "DW_AT_declaration";
3787 case DW_AT_discr_list:
3788 return "DW_AT_discr_list";
3789 case DW_AT_encoding:
3790 return "DW_AT_encoding";
3791 case DW_AT_external:
3792 return "DW_AT_external";
3793 case DW_AT_frame_base:
3794 return "DW_AT_frame_base";
3796 return "DW_AT_friend";
3797 case DW_AT_identifier_case:
3798 return "DW_AT_identifier_case";
3799 case DW_AT_macro_info:
3800 return "DW_AT_macro_info";
3801 case DW_AT_namelist_items:
3802 return "DW_AT_namelist_items";
3803 case DW_AT_priority:
3804 return "DW_AT_priority";
3806 return "DW_AT_segment";
3807 case DW_AT_specification:
3808 return "DW_AT_specification";
3809 case DW_AT_static_link:
3810 return "DW_AT_static_link";
3812 return "DW_AT_type";
3813 case DW_AT_use_location:
3814 return "DW_AT_use_location";
3815 case DW_AT_variable_parameter:
3816 return "DW_AT_variable_parameter";
3817 case DW_AT_virtuality:
3818 return "DW_AT_virtuality";
3819 case DW_AT_vtable_elem_location:
3820 return "DW_AT_vtable_elem_location";
3822 case DW_AT_MIPS_fde:
3823 return "DW_AT_MIPS_fde";
3824 case DW_AT_MIPS_loop_begin:
3825 return "DW_AT_MIPS_loop_begin";
3826 case DW_AT_MIPS_tail_loop_begin:
3827 return "DW_AT_MIPS_tail_loop_begin";
3828 case DW_AT_MIPS_epilog_begin:
3829 return "DW_AT_MIPS_epilog_begin";
3830 case DW_AT_MIPS_loop_unroll_factor:
3831 return "DW_AT_MIPS_loop_unroll_factor";
3832 case DW_AT_MIPS_software_pipeline_depth:
3833 return "DW_AT_MIPS_software_pipeline_depth";
3834 case DW_AT_MIPS_linkage_name:
3835 return "DW_AT_MIPS_linkage_name";
3836 case DW_AT_MIPS_stride:
3837 return "DW_AT_MIPS_stride";
3838 case DW_AT_MIPS_abstract_name:
3839 return "DW_AT_MIPS_abstract_name";
3840 case DW_AT_MIPS_clone_origin:
3841 return "DW_AT_MIPS_clone_origin";
3842 case DW_AT_MIPS_has_inlines:
3843 return "DW_AT_MIPS_has_inlines";
3845 case DW_AT_sf_names:
3846 return "DW_AT_sf_names";
3847 case DW_AT_src_info:
3848 return "DW_AT_src_info";
3849 case DW_AT_mac_info:
3850 return "DW_AT_mac_info";
3851 case DW_AT_src_coords:
3852 return "DW_AT_src_coords";
3853 case DW_AT_body_begin:
3854 return "DW_AT_body_begin";
3855 case DW_AT_body_end:
3856 return "DW_AT_body_end";
3858 return "DW_AT_<unknown>";
3862 /* Convert a DWARF value form code into its string name. */
3865 dwarf_form_name (form)
3866 register unsigned form;
3871 return "DW_FORM_addr";
3872 case DW_FORM_block2:
3873 return "DW_FORM_block2";
3874 case DW_FORM_block4:
3875 return "DW_FORM_block4";
3877 return "DW_FORM_data2";
3879 return "DW_FORM_data4";
3881 return "DW_FORM_data8";
3882 case DW_FORM_string:
3883 return "DW_FORM_string";
3885 return "DW_FORM_block";
3886 case DW_FORM_block1:
3887 return "DW_FORM_block1";
3889 return "DW_FORM_data1";
3891 return "DW_FORM_flag";
3893 return "DW_FORM_sdata";
3895 return "DW_FORM_strp";
3897 return "DW_FORM_udata";
3898 case DW_FORM_ref_addr:
3899 return "DW_FORM_ref_addr";
3901 return "DW_FORM_ref1";
3903 return "DW_FORM_ref2";
3905 return "DW_FORM_ref4";
3907 return "DW_FORM_ref8";
3908 case DW_FORM_ref_udata:
3909 return "DW_FORM_ref_udata";
3910 case DW_FORM_indirect:
3911 return "DW_FORM_indirect";
3913 return "DW_FORM_<unknown>";
3917 /* Convert a DWARF type code into its string name. */
3921 dwarf_type_encoding_name (enc)
3922 register unsigned enc;
3926 case DW_ATE_address:
3927 return "DW_ATE_address";
3928 case DW_ATE_boolean:
3929 return "DW_ATE_boolean";
3930 case DW_ATE_complex_float:
3931 return "DW_ATE_complex_float";
3933 return "DW_ATE_float";
3935 return "DW_ATE_signed";
3936 case DW_ATE_signed_char:
3937 return "DW_ATE_signed_char";
3938 case DW_ATE_unsigned:
3939 return "DW_ATE_unsigned";
3940 case DW_ATE_unsigned_char:
3941 return "DW_ATE_unsigned_char";
3943 return "DW_ATE_<unknown>";
3948 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3949 instance of an inlined instance of a decl which is local to an inline
3950 function, so we have to trace all of the way back through the origin chain
3951 to find out what sort of node actually served as the original seed for the
3955 decl_ultimate_origin (decl)
3958 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3959 nodes in the function to point to themselves; ignore that if
3960 we're trying to output the abstract instance of this function. */
3961 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
3964 #ifdef ENABLE_CHECKING
3965 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
3966 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3967 most distant ancestor, this should never happen. */
3971 return DECL_ABSTRACT_ORIGIN (decl);
3974 /* Determine the "ultimate origin" of a block. The block may be an inlined
3975 instance of an inlined instance of a block which is local to an inline
3976 function, so we have to trace all of the way back through the origin chain
3977 to find out what sort of node actually served as the original seed for the
3981 block_ultimate_origin (block)
3982 register tree block;
3984 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3986 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
3987 nodes in the function to point to themselves; ignore that if
3988 we're trying to output the abstract instance of this function. */
3989 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
3992 if (immediate_origin == NULL_TREE)
3996 register tree ret_val;
3997 register tree lookahead = immediate_origin;
4001 ret_val = lookahead;
4002 lookahead = (TREE_CODE (ret_val) == BLOCK)
4003 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4006 while (lookahead != NULL && lookahead != ret_val);
4012 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4013 of a virtual function may refer to a base class, so we check the 'this'
4017 decl_class_context (decl)
4020 tree context = NULL_TREE;
4022 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4023 context = DECL_CONTEXT (decl);
4025 context = TYPE_MAIN_VARIANT
4026 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4028 if (context && !TYPE_P (context))
4029 context = NULL_TREE;
4034 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4035 addition order, and correct that in add_sibling_attributes. */
4038 add_dwarf_attr (die, attr)
4039 register dw_die_ref die;
4040 register dw_attr_ref attr;
4042 if (die != NULL && attr != NULL)
4044 attr->dw_attr_next = die->die_attr;
4045 die->die_attr = attr;
4049 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4050 static inline dw_val_class
4054 return a->dw_attr_val.val_class;
4057 /* Add a flag value attribute to a DIE. */
4060 add_AT_flag (die, attr_kind, flag)
4061 register dw_die_ref die;
4062 register enum dwarf_attribute attr_kind;
4063 register unsigned flag;
4065 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4067 attr->dw_attr_next = NULL;
4068 attr->dw_attr = attr_kind;
4069 attr->dw_attr_val.val_class = dw_val_class_flag;
4070 attr->dw_attr_val.v.val_flag = flag;
4071 add_dwarf_attr (die, attr);
4074 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4075 static inline unsigned
4077 register dw_attr_ref a;
4079 if (a && AT_class (a) == dw_val_class_flag)
4080 return a->dw_attr_val.v.val_flag;
4085 /* Add a signed integer attribute value to a DIE. */
4088 add_AT_int (die, attr_kind, int_val)
4089 register dw_die_ref die;
4090 register enum dwarf_attribute attr_kind;
4091 register long int int_val;
4093 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4095 attr->dw_attr_next = NULL;
4096 attr->dw_attr = attr_kind;
4097 attr->dw_attr_val.val_class = dw_val_class_const;
4098 attr->dw_attr_val.v.val_int = int_val;
4099 add_dwarf_attr (die, attr);
4102 static inline long int AT_int PARAMS ((dw_attr_ref));
4103 static inline long int
4105 register dw_attr_ref a;
4107 if (a && AT_class (a) == dw_val_class_const)
4108 return a->dw_attr_val.v.val_int;
4113 /* Add an unsigned integer attribute value to a DIE. */
4116 add_AT_unsigned (die, attr_kind, unsigned_val)
4117 register dw_die_ref die;
4118 register enum dwarf_attribute attr_kind;
4119 register unsigned long unsigned_val;
4121 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4123 attr->dw_attr_next = NULL;
4124 attr->dw_attr = attr_kind;
4125 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4126 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4127 add_dwarf_attr (die, attr);
4130 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4131 static inline unsigned long
4133 register dw_attr_ref a;
4135 if (a && AT_class (a) == dw_val_class_unsigned_const)
4136 return a->dw_attr_val.v.val_unsigned;
4141 /* Add an unsigned double integer attribute value to a DIE. */
4144 add_AT_long_long (die, attr_kind, val_hi, val_low)
4145 register dw_die_ref die;
4146 register enum dwarf_attribute attr_kind;
4147 register unsigned long val_hi;
4148 register unsigned long val_low;
4150 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4152 attr->dw_attr_next = NULL;
4153 attr->dw_attr = attr_kind;
4154 attr->dw_attr_val.val_class = dw_val_class_long_long;
4155 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4156 attr->dw_attr_val.v.val_long_long.low = val_low;
4157 add_dwarf_attr (die, attr);
4160 /* Add a floating point attribute value to a DIE and return it. */
4163 add_AT_float (die, attr_kind, length, array)
4164 register dw_die_ref die;
4165 register enum dwarf_attribute attr_kind;
4166 register unsigned length;
4167 register long *array;
4169 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4171 attr->dw_attr_next = NULL;
4172 attr->dw_attr = attr_kind;
4173 attr->dw_attr_val.val_class = dw_val_class_float;
4174 attr->dw_attr_val.v.val_float.length = length;
4175 attr->dw_attr_val.v.val_float.array = array;
4176 add_dwarf_attr (die, attr);
4179 /* Add a string attribute value to a DIE. */
4182 add_AT_string (die, attr_kind, str)
4183 register dw_die_ref die;
4184 register enum dwarf_attribute attr_kind;
4185 register const char *str;
4187 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4189 attr->dw_attr_next = NULL;
4190 attr->dw_attr = attr_kind;
4191 attr->dw_attr_val.val_class = dw_val_class_str;
4192 attr->dw_attr_val.v.val_str = xstrdup (str);
4193 add_dwarf_attr (die, attr);
4196 static inline const char *AT_string PARAMS ((dw_attr_ref));
4197 static inline const char *
4199 register dw_attr_ref a;
4201 if (a && AT_class (a) == dw_val_class_str)
4202 return a->dw_attr_val.v.val_str;
4207 /* Add a DIE reference attribute value to a DIE. */
4210 add_AT_die_ref (die, attr_kind, targ_die)
4211 register dw_die_ref die;
4212 register enum dwarf_attribute attr_kind;
4213 register dw_die_ref targ_die;
4215 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4217 attr->dw_attr_next = NULL;
4218 attr->dw_attr = attr_kind;
4219 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4220 attr->dw_attr_val.v.val_die_ref = targ_die;
4221 add_dwarf_attr (die, attr);
4224 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4225 static inline dw_die_ref
4227 register dw_attr_ref a;
4229 if (a && AT_class (a) == dw_val_class_die_ref)
4230 return a->dw_attr_val.v.val_die_ref;
4235 /* Add an FDE reference attribute value to a DIE. */
4238 add_AT_fde_ref (die, attr_kind, targ_fde)
4239 register dw_die_ref die;
4240 register enum dwarf_attribute attr_kind;
4241 register unsigned targ_fde;
4243 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4245 attr->dw_attr_next = NULL;
4246 attr->dw_attr = attr_kind;
4247 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4248 attr->dw_attr_val.v.val_fde_index = targ_fde;
4249 add_dwarf_attr (die, attr);
4252 /* Add a location description attribute value to a DIE. */
4255 add_AT_loc (die, attr_kind, loc)
4256 register dw_die_ref die;
4257 register enum dwarf_attribute attr_kind;
4258 register dw_loc_descr_ref loc;
4260 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4262 attr->dw_attr_next = NULL;
4263 attr->dw_attr = attr_kind;
4264 attr->dw_attr_val.val_class = dw_val_class_loc;
4265 attr->dw_attr_val.v.val_loc = loc;
4266 add_dwarf_attr (die, attr);
4269 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4270 static inline dw_loc_descr_ref
4272 register dw_attr_ref a;
4274 if (a && AT_class (a) == dw_val_class_loc)
4275 return a->dw_attr_val.v.val_loc;
4280 /* Add an address constant attribute value to a DIE. */
4283 add_AT_addr (die, attr_kind, addr)
4284 register dw_die_ref die;
4285 register enum dwarf_attribute attr_kind;
4288 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4290 attr->dw_attr_next = NULL;
4291 attr->dw_attr = attr_kind;
4292 attr->dw_attr_val.val_class = dw_val_class_addr;
4293 attr->dw_attr_val.v.val_addr = addr;
4294 add_dwarf_attr (die, attr);
4297 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4300 register dw_attr_ref a;
4302 if (a && AT_class (a) == dw_val_class_addr)
4303 return a->dw_attr_val.v.val_addr;
4308 /* Add a label identifier attribute value to a DIE. */
4311 add_AT_lbl_id (die, attr_kind, lbl_id)
4312 register dw_die_ref die;
4313 register enum dwarf_attribute attr_kind;
4314 register const char *lbl_id;
4316 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4318 attr->dw_attr_next = NULL;
4319 attr->dw_attr = attr_kind;
4320 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4321 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4322 add_dwarf_attr (die, attr);
4325 /* Add a section offset attribute value to a DIE. */
4328 add_AT_lbl_offset (die, attr_kind, label)
4329 register dw_die_ref die;
4330 register enum dwarf_attribute attr_kind;
4331 register const char *label;
4333 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4335 attr->dw_attr_next = NULL;
4336 attr->dw_attr = attr_kind;
4337 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4338 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4339 add_dwarf_attr (die, attr);
4343 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4344 static inline const char *
4346 register dw_attr_ref a;
4348 if (a && (AT_class (a) == dw_val_class_lbl_id
4349 || AT_class (a) == dw_val_class_lbl_offset))
4350 return a->dw_attr_val.v.val_lbl_id;
4355 /* Get the attribute of type attr_kind. */
4357 static inline dw_attr_ref
4358 get_AT (die, attr_kind)
4359 register dw_die_ref die;
4360 register enum dwarf_attribute attr_kind;
4362 register dw_attr_ref a;
4363 register dw_die_ref spec = NULL;
4367 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4369 if (a->dw_attr == attr_kind)
4372 if (a->dw_attr == DW_AT_specification
4373 || a->dw_attr == DW_AT_abstract_origin)
4378 return get_AT (spec, attr_kind);
4384 /* Return the "low pc" attribute value, typically associated with
4385 a subprogram DIE. Return null if the "low pc" attribute is
4386 either not prsent, or if it cannot be represented as an
4387 assembler label identifier. */
4389 static inline const char *
4391 register dw_die_ref die;
4393 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4397 /* Return the "high pc" attribute value, typically associated with
4398 a subprogram DIE. Return null if the "high pc" attribute is
4399 either not prsent, or if it cannot be represented as an
4400 assembler label identifier. */
4402 static inline const char *
4404 register dw_die_ref die;
4406 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4410 /* Return the value of the string attribute designated by ATTR_KIND, or
4411 NULL if it is not present. */
4413 static inline const char *
4414 get_AT_string (die, attr_kind)
4415 register dw_die_ref die;
4416 register enum dwarf_attribute attr_kind;
4418 register dw_attr_ref a = get_AT (die, attr_kind);
4419 return AT_string (a);
4422 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4423 if it is not present. */
4426 get_AT_flag (die, attr_kind)
4427 register dw_die_ref die;
4428 register enum dwarf_attribute attr_kind;
4430 register dw_attr_ref a = get_AT (die, attr_kind);
4434 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4435 if it is not present. */
4437 static inline unsigned
4438 get_AT_unsigned (die, attr_kind)
4439 register dw_die_ref die;
4440 register enum dwarf_attribute attr_kind;
4442 register dw_attr_ref a = get_AT (die, attr_kind);
4443 return AT_unsigned (a);
4446 static inline dw_die_ref
4447 get_AT_ref (die, attr_kind)
4449 register enum dwarf_attribute attr_kind;
4451 register dw_attr_ref a = get_AT (die, attr_kind);
4458 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4460 return (lang == DW_LANG_C || lang == DW_LANG_C89
4461 || lang == DW_LANG_C_plus_plus);
4467 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4469 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4472 /* Free up the memory used by A. */
4474 static inline void free_AT PARAMS ((dw_attr_ref));
4479 switch (AT_class (a))
4481 case dw_val_class_str:
4482 case dw_val_class_lbl_id:
4483 case dw_val_class_lbl_offset:
4484 free (a->dw_attr_val.v.val_str);
4494 /* Remove the specified attribute if present. */
4497 remove_AT (die, attr_kind)
4498 register dw_die_ref die;
4499 register enum dwarf_attribute attr_kind;
4501 register dw_attr_ref *p;
4502 register dw_attr_ref removed = NULL;
4506 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4507 if ((*p)->dw_attr == attr_kind)
4510 *p = (*p)->dw_attr_next;
4519 /* Free up the memory used by DIE. */
4521 static inline void free_die PARAMS ((dw_die_ref));
4526 remove_children (die);
4530 /* Discard the children of this DIE. */
4533 remove_children (die)
4534 register dw_die_ref die;
4536 register dw_die_ref child_die = die->die_child;
4538 die->die_child = NULL;
4540 while (child_die != NULL)
4542 register dw_die_ref tmp_die = child_die;
4543 register dw_attr_ref a;
4545 child_die = child_die->die_sib;
4547 for (a = tmp_die->die_attr; a != NULL; )
4549 register dw_attr_ref tmp_a = a;
4551 a = a->dw_attr_next;
4559 /* Add a child DIE below its parent. We build the lists up in reverse
4560 addition order, and correct that in add_sibling_attributes. */
4563 add_child_die (die, child_die)
4564 register dw_die_ref die;
4565 register dw_die_ref child_die;
4567 if (die != NULL && child_die != NULL)
4569 if (die == child_die)
4571 child_die->die_parent = die;
4572 child_die->die_sib = die->die_child;
4573 die->die_child = child_die;
4577 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4578 is the specification, to the front of PARENT's list of children. */
4581 splice_child_die (parent, child)
4582 dw_die_ref parent, child;
4586 /* We want the declaration DIE from inside the class, not the
4587 specification DIE at toplevel. */
4588 if (child->die_parent != parent)
4590 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4595 if (child->die_parent != parent
4596 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4599 for (p = &(parent->die_child); *p; p = &((*p)->die_sib))
4602 *p = child->die_sib;
4606 child->die_sib = parent->die_child;
4607 parent->die_child = child;
4610 /* Return a pointer to a newly created DIE node. */
4612 static inline dw_die_ref
4613 new_die (tag_value, parent_die)
4614 register enum dwarf_tag tag_value;
4615 register dw_die_ref parent_die;
4617 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4619 die->die_tag = tag_value;
4620 die->die_abbrev = 0;
4621 die->die_offset = 0;
4622 die->die_child = NULL;
4623 die->die_parent = NULL;
4624 die->die_sib = NULL;
4625 die->die_attr = NULL;
4627 if (parent_die != NULL)
4628 add_child_die (parent_die, die);
4631 limbo_die_node *limbo_node;
4633 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4634 limbo_node->die = die;
4635 limbo_node->next = limbo_die_list;
4636 limbo_die_list = limbo_node;
4642 /* Return the DIE associated with the given type specifier. */
4644 static inline dw_die_ref
4645 lookup_type_die (type)
4648 if (TREE_CODE (type) == VECTOR_TYPE)
4649 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4650 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4653 /* Equate a DIE to a given type specifier. */
4656 equate_type_number_to_die (type, type_die)
4658 register dw_die_ref type_die;
4660 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4663 /* Return the DIE associated with a given declaration. */
4665 static inline dw_die_ref
4666 lookup_decl_die (decl)
4669 register unsigned decl_id = DECL_UID (decl);
4671 return (decl_id < decl_die_table_in_use
4672 ? decl_die_table[decl_id] : NULL);
4675 /* Equate a DIE to a particular declaration. */
4678 equate_decl_number_to_die (decl, decl_die)
4680 register dw_die_ref decl_die;
4682 register unsigned decl_id = DECL_UID (decl);
4683 register unsigned num_allocated;
4685 if (decl_id >= decl_die_table_allocated)
4688 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4689 / DECL_DIE_TABLE_INCREMENT)
4690 * DECL_DIE_TABLE_INCREMENT;
4693 = (dw_die_ref *) xrealloc (decl_die_table,
4694 sizeof (dw_die_ref) * num_allocated);
4696 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4697 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4698 decl_die_table_allocated = num_allocated;
4701 if (decl_id >= decl_die_table_in_use)
4702 decl_die_table_in_use = (decl_id + 1);
4704 decl_die_table[decl_id] = decl_die;
4707 /* Keep track of the number of spaces used to indent the
4708 output of the debugging routines that print the structure of
4709 the DIE internal representation. */
4710 static int print_indent;
4712 /* Indent the line the number of spaces given by print_indent. */
4715 print_spaces (outfile)
4718 fprintf (outfile, "%*s", print_indent, "");
4721 /* Print the information associated with a given DIE, and its children.
4722 This routine is a debugging aid only. */
4725 print_die (die, outfile)
4729 register dw_attr_ref a;
4730 register dw_die_ref c;
4732 print_spaces (outfile);
4733 fprintf (outfile, "DIE %4lu: %s\n",
4734 die->die_offset, dwarf_tag_name (die->die_tag));
4735 print_spaces (outfile);
4736 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4737 fprintf (outfile, " offset: %lu\n", die->die_offset);
4739 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4741 print_spaces (outfile);
4742 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4744 switch (AT_class (a))
4746 case dw_val_class_addr:
4747 fprintf (outfile, "address");
4749 case dw_val_class_loc:
4750 fprintf (outfile, "location descriptor");
4752 case dw_val_class_const:
4753 fprintf (outfile, "%ld", AT_int (a));
4755 case dw_val_class_unsigned_const:
4756 fprintf (outfile, "%lu", AT_unsigned (a));
4758 case dw_val_class_long_long:
4759 fprintf (outfile, "constant (%lu,%lu)",
4760 a->dw_attr_val.v.val_long_long.hi,
4761 a->dw_attr_val.v.val_long_long.low);
4763 case dw_val_class_float:
4764 fprintf (outfile, "floating-point constant");
4766 case dw_val_class_flag:
4767 fprintf (outfile, "%u", AT_flag (a));
4769 case dw_val_class_die_ref:
4770 if (AT_ref (a) != NULL)
4771 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4773 fprintf (outfile, "die -> <null>");
4775 case dw_val_class_lbl_id:
4776 case dw_val_class_lbl_offset:
4777 fprintf (outfile, "label: %s", AT_lbl (a));
4779 case dw_val_class_str:
4780 if (AT_string (a) != NULL)
4781 fprintf (outfile, "\"%s\"", AT_string (a));
4783 fprintf (outfile, "<null>");
4789 fprintf (outfile, "\n");
4792 if (die->die_child != NULL)
4795 for (c = die->die_child; c != NULL; c = c->die_sib)
4796 print_die (c, outfile);
4802 /* Print the contents of the source code line number correspondence table.
4803 This routine is a debugging aid only. */
4806 print_dwarf_line_table (outfile)
4809 register unsigned i;
4810 register dw_line_info_ref line_info;
4812 fprintf (outfile, "\n\nDWARF source line information\n");
4813 for (i = 1; i < line_info_table_in_use; ++i)
4815 line_info = &line_info_table[i];
4816 fprintf (outfile, "%5d: ", i);
4817 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4818 fprintf (outfile, "%6ld", line_info->dw_line_num);
4819 fprintf (outfile, "\n");
4822 fprintf (outfile, "\n\n");
4825 /* Print the information collected for a given DIE. */
4828 debug_dwarf_die (die)
4831 print_die (die, stderr);
4834 /* Print all DWARF information collected for the compilation unit.
4835 This routine is a debugging aid only. */
4841 print_die (comp_unit_die, stderr);
4842 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4843 print_dwarf_line_table (stderr);
4846 /* We build up the lists of children and attributes by pushing new ones
4847 onto the beginning of the list. Reverse the lists for DIE so that
4848 they are in order of addition. */
4851 reverse_die_lists (die)
4852 register dw_die_ref die;
4854 register dw_die_ref c, cp, cn;
4855 register dw_attr_ref a, ap, an;
4857 for (a = die->die_attr, ap = 0; a; a = an)
4859 an = a->dw_attr_next;
4860 a->dw_attr_next = ap;
4865 for (c = die->die_child, cp = 0; c; c = cn)
4871 die->die_child = cp;
4874 /* Traverse the DIE, reverse its lists of attributes and children, and
4875 add a sibling attribute if it may have the effect of speeding up
4876 access to siblings. To save some space, avoid generating sibling
4877 attributes for DIE's without children. */
4880 add_sibling_attributes (die)
4881 register dw_die_ref die;
4883 register dw_die_ref c;
4885 reverse_die_lists (die);
4887 if (die != comp_unit_die && die->die_sib && die->die_child != NULL)
4888 /* Add the sibling link to the front of the attribute list. */
4889 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
4891 for (c = die->die_child; c != NULL; c = c->die_sib)
4892 add_sibling_attributes (c);
4895 /* The format of each DIE (and its attribute value pairs)
4896 is encoded in an abbreviation table. This routine builds the
4897 abbreviation table and assigns a unique abbreviation id for
4898 each abbreviation entry. The children of each die are visited
4902 build_abbrev_table (die)
4903 register dw_die_ref die;
4905 register unsigned long abbrev_id;
4906 register unsigned long n_alloc;
4907 register dw_die_ref c;
4908 register dw_attr_ref d_attr, a_attr;
4909 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4911 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4913 if (abbrev->die_tag == die->die_tag)
4915 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
4917 a_attr = abbrev->die_attr;
4918 d_attr = die->die_attr;
4920 while (a_attr != NULL && d_attr != NULL)
4922 if ((a_attr->dw_attr != d_attr->dw_attr)
4923 || (value_format (a_attr) != value_format (d_attr)))
4926 a_attr = a_attr->dw_attr_next;
4927 d_attr = d_attr->dw_attr_next;
4930 if (a_attr == NULL && d_attr == NULL)
4936 if (abbrev_id >= abbrev_die_table_in_use)
4938 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
4940 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
4942 = (dw_die_ref *) xrealloc (abbrev_die_table,
4943 sizeof (dw_die_ref) * n_alloc);
4945 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
4946 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
4947 abbrev_die_table_allocated = n_alloc;
4950 ++abbrev_die_table_in_use;
4951 abbrev_die_table[abbrev_id] = die;
4954 die->die_abbrev = abbrev_id;
4955 for (c = die->die_child; c != NULL; c = c->die_sib)
4956 build_abbrev_table (c);
4959 /* Return the size of a string, including the null byte.
4961 This used to treat backslashes as escapes, and hence they were not included
4962 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
4963 which treats a backslash as a backslash, escaping it if necessary, and hence
4964 we must include them in the count. */
4966 static unsigned long
4967 size_of_string (str)
4968 register const char *str;
4970 return strlen (str) + 1;
4973 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4976 constant_size (value)
4977 long unsigned value;
4984 log = floor_log2 (value);
4987 log = 1 << (floor_log2 (log) + 1);
4992 /* Return the size of a DIE, as it is represented in the
4993 .debug_info section. */
4995 static unsigned long
4997 register dw_die_ref die;
4999 register unsigned long size = 0;
5000 register dw_attr_ref a;
5002 size += size_of_uleb128 (die->die_abbrev);
5003 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5005 switch (AT_class (a))
5007 case dw_val_class_addr:
5008 size += DWARF2_ADDR_SIZE;
5010 case dw_val_class_loc:
5012 register unsigned long lsize = size_of_locs (AT_loc (a));
5015 size += constant_size (lsize);
5019 case dw_val_class_const:
5020 size += size_of_sleb128 (AT_int (a));
5022 case dw_val_class_unsigned_const:
5023 size += constant_size (AT_unsigned (a));
5025 case dw_val_class_long_long:
5026 size += 1 + 8; /* block */
5028 case dw_val_class_float:
5029 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5031 case dw_val_class_flag:
5034 case dw_val_class_die_ref:
5035 size += DWARF_OFFSET_SIZE;
5037 case dw_val_class_fde_ref:
5038 size += DWARF_OFFSET_SIZE;
5040 case dw_val_class_lbl_id:
5041 size += DWARF2_ADDR_SIZE;
5043 case dw_val_class_lbl_offset:
5044 size += DWARF_OFFSET_SIZE;
5046 case dw_val_class_str:
5047 size += size_of_string (AT_string (a));
5057 /* Size the debugging information associated with a given DIE.
5058 Visits the DIE's children recursively. Updates the global
5059 variable next_die_offset, on each time through. Uses the
5060 current value of next_die_offset to update the die_offset
5061 field in each DIE. */
5064 calc_die_sizes (die)
5067 register dw_die_ref c;
5068 die->die_offset = next_die_offset;
5069 next_die_offset += size_of_die (die);
5071 for (c = die->die_child; c != NULL; c = c->die_sib)
5074 if (die->die_child != NULL)
5075 /* Count the null byte used to terminate sibling lists. */
5076 next_die_offset += 1;
5079 /* Return the size of the line information prolog generated for the
5080 compilation unit. */
5082 static unsigned long
5083 size_of_line_prolog ()
5085 register unsigned long size;
5086 register unsigned long ft_index;
5088 size = DWARF_LINE_PROLOG_HEADER_SIZE;
5090 /* Count the size of the table giving number of args for each
5092 size += DWARF_LINE_OPCODE_BASE - 1;
5094 /* Include directory table is empty (at present). Count only the
5095 null byte used to terminate the table. */
5098 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5100 /* File name entry. */
5101 size += size_of_string (file_table[ft_index]);
5103 /* Include directory index. */
5104 size += size_of_uleb128 (0);
5106 /* Modification time. */
5107 size += size_of_uleb128 (0);
5109 /* File length in bytes. */
5110 size += size_of_uleb128 (0);
5113 /* Count the file table terminator. */
5118 /* Return the size of the .debug_pubnames table generated for the
5119 compilation unit. */
5121 static unsigned long
5124 register unsigned long size;
5125 register unsigned i;
5127 size = DWARF_PUBNAMES_HEADER_SIZE;
5128 for (i = 0; i < pubname_table_in_use; ++i)
5130 register pubname_ref p = &pubname_table[i];
5131 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5134 size += DWARF_OFFSET_SIZE;
5138 /* Return the size of the information in the .debug_aranges section. */
5140 static unsigned long
5143 register unsigned long size;
5145 size = DWARF_ARANGES_HEADER_SIZE;
5147 /* Count the address/length pair for this compilation unit. */
5148 size += 2 * DWARF2_ADDR_SIZE;
5149 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5151 /* Count the two zero words used to terminated the address range table. */
5152 size += 2 * DWARF2_ADDR_SIZE;
5156 /* Select the encoding of an attribute value. */
5158 static enum dwarf_form
5162 switch (a->dw_attr_val.val_class)
5164 case dw_val_class_addr:
5165 return DW_FORM_addr;
5166 case dw_val_class_loc:
5167 switch (constant_size (size_of_locs (AT_loc (a))))
5170 return DW_FORM_block1;
5172 return DW_FORM_block2;
5176 case dw_val_class_const:
5177 return DW_FORM_sdata;
5178 case dw_val_class_unsigned_const:
5179 switch (constant_size (AT_unsigned (a)))
5182 return DW_FORM_data1;
5184 return DW_FORM_data2;
5186 return DW_FORM_data4;
5188 return DW_FORM_data8;
5192 case dw_val_class_long_long:
5193 return DW_FORM_block1;
5194 case dw_val_class_float:
5195 return DW_FORM_block1;
5196 case dw_val_class_flag:
5197 return DW_FORM_flag;
5198 case dw_val_class_die_ref:
5200 case dw_val_class_fde_ref:
5201 return DW_FORM_data;
5202 case dw_val_class_lbl_id:
5203 return DW_FORM_addr;
5204 case dw_val_class_lbl_offset:
5205 return DW_FORM_data;
5206 case dw_val_class_str:
5207 return DW_FORM_string;
5213 /* Output the encoding of an attribute value. */
5216 output_value_format (a)
5219 enum dwarf_form form = value_format (a);
5221 output_uleb128 (form);
5223 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
5225 fputc ('\n', asm_out_file);
5228 /* Output the .debug_abbrev section which defines the DIE abbreviation
5232 output_abbrev_section ()
5234 unsigned long abbrev_id;
5237 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5239 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5241 output_uleb128 (abbrev_id);
5243 fprintf (asm_out_file, " (abbrev code)");
5245 fputc ('\n', asm_out_file);
5246 output_uleb128 (abbrev->die_tag);
5248 fprintf (asm_out_file, " (TAG: %s)",
5249 dwarf_tag_name (abbrev->die_tag));
5251 fputc ('\n', asm_out_file);
5252 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
5253 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
5256 fprintf (asm_out_file, "\t%s %s",
5258 (abbrev->die_child != NULL
5259 ? "DW_children_yes" : "DW_children_no"));
5261 fputc ('\n', asm_out_file);
5263 for (a_attr = abbrev->die_attr; a_attr != NULL;
5264 a_attr = a_attr->dw_attr_next)
5266 output_uleb128 (a_attr->dw_attr);
5268 fprintf (asm_out_file, " (%s)",
5269 dwarf_attr_name (a_attr->dw_attr));
5271 fputc ('\n', asm_out_file);
5272 output_value_format (a_attr);
5275 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
5278 /* Terminate the table. */
5279 fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP);
5282 /* Output the DIE and its attributes. Called recursively to generate
5283 the definitions of each child DIE. */
5287 register dw_die_ref die;
5289 register dw_attr_ref a;
5290 register dw_die_ref c;
5291 register unsigned long size;
5293 output_uleb128 (die->die_abbrev);
5295 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5296 die->die_offset, dwarf_tag_name (die->die_tag));
5298 fputc ('\n', asm_out_file);
5300 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5302 switch (AT_class (a))
5304 case dw_val_class_addr:
5305 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
5308 case dw_val_class_loc:
5309 size = size_of_locs (AT_loc (a));
5311 /* Output the block length for this list of location operations. */
5312 switch (constant_size (size))
5315 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5318 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5325 fprintf (asm_out_file, "\t%s %s",
5326 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5328 fputc ('\n', asm_out_file);
5330 output_loc_sequence (AT_loc (a));
5333 case dw_val_class_const:
5334 /* ??? It would be slightly more efficient to use a scheme like is
5335 used for unsigned constants below, but gdb 4.x does not sign
5336 extend. Gdb 5.x does sign extend. */
5337 output_sleb128 (AT_int (a));
5340 case dw_val_class_unsigned_const:
5341 switch (constant_size (AT_unsigned (a)))
5344 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
5347 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
5350 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
5353 ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a));
5360 case dw_val_class_long_long:
5361 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5363 fprintf (asm_out_file, "\t%s %s",
5364 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5366 fputc ('\n', asm_out_file);
5367 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file,
5368 a->dw_attr_val.v.val_long_long.hi,
5369 a->dw_attr_val.v.val_long_long.low);
5372 fprintf (asm_out_file,
5373 "\t%s long long constant", ASM_COMMENT_START);
5375 fputc ('\n', asm_out_file);
5378 case dw_val_class_float:
5380 register unsigned int i;
5381 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5382 a->dw_attr_val.v.val_float.length * 4);
5384 fprintf (asm_out_file, "\t%s %s",
5385 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5387 fputc ('\n', asm_out_file);
5388 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5390 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5391 a->dw_attr_val.v.val_float.array[i]);
5393 fprintf (asm_out_file, "\t%s fp constant word %u",
5394 ASM_COMMENT_START, i);
5396 fputc ('\n', asm_out_file);
5401 case dw_val_class_flag:
5402 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
5405 case dw_val_class_die_ref:
5406 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
5409 case dw_val_class_fde_ref:
5412 ASM_GENERATE_INTERNAL_LABEL
5413 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5414 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5415 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5419 case dw_val_class_lbl_id:
5420 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
5423 case dw_val_class_lbl_offset:
5424 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
5427 case dw_val_class_str:
5429 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
5431 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
5432 (int) strlen (AT_string (a)) + 1);
5439 if (AT_class (a) != dw_val_class_loc
5440 && AT_class (a) != dw_val_class_long_long
5441 && AT_class (a) != dw_val_class_float)
5444 fprintf (asm_out_file, "\t%s %s",
5445 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5447 fputc ('\n', asm_out_file);
5451 for (c = die->die_child; c != NULL; c = c->die_sib)
5454 if (die->die_child != NULL)
5456 /* Add null byte to terminate sibling list. */
5457 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5459 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
5460 ASM_COMMENT_START, die->die_offset);
5462 fputc ('\n', asm_out_file);
5466 /* Output the compilation unit that appears at the beginning of the
5467 .debug_info section, and precedes the DIE descriptions. */
5470 output_compilation_unit_header ()
5472 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
5474 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
5477 fputc ('\n', asm_out_file);
5478 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5480 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
5482 fputc ('\n', asm_out_file);
5483 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
5485 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
5488 fputc ('\n', asm_out_file);
5489 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
5491 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
5493 fputc ('\n', asm_out_file);
5496 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5497 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5498 argument list, and maybe the scope. */
5501 dwarf2_name (decl, scope)
5505 return (*decl_printable_name) (decl, scope ? 1 : 0);
5508 /* Add a new entry to .debug_pubnames if appropriate. */
5511 add_pubname (decl, die)
5517 if (! TREE_PUBLIC (decl))
5520 if (pubname_table_in_use == pubname_table_allocated)
5522 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5523 pubname_table = (pubname_ref) xrealloc
5524 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5527 p = &pubname_table[pubname_table_in_use++];
5530 p->name = xstrdup (dwarf2_name (decl, 1));
5533 /* Output the public names table used to speed up access to externally
5534 visible names. For now, only generate entries for externally
5535 visible procedures. */
5540 register unsigned i;
5541 register unsigned long pubnames_length = size_of_pubnames ();
5543 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
5546 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
5549 fputc ('\n', asm_out_file);
5550 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5553 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5555 fputc ('\n', asm_out_file);
5556 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5558 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5561 fputc ('\n', asm_out_file);
5562 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
5564 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
5566 fputc ('\n', asm_out_file);
5567 for (i = 0; i < pubname_table_in_use; ++i)
5569 register pubname_ref pub = &pubname_table[i];
5571 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
5573 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
5575 fputc ('\n', asm_out_file);
5579 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
5580 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
5584 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
5585 (int) strlen (pub->name) + 1);
5588 fputc ('\n', asm_out_file);
5591 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
5592 fputc ('\n', asm_out_file);
5595 /* Add a new entry to .debug_aranges if appropriate. */
5598 add_arange (decl, die)
5602 if (! DECL_SECTION_NAME (decl))
5605 if (arange_table_in_use == arange_table_allocated)
5607 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5609 = (arange_ref) xrealloc (arange_table,
5610 arange_table_allocated * sizeof (dw_die_ref));
5613 arange_table[arange_table_in_use++] = die;
5616 /* Output the information that goes into the .debug_aranges table.
5617 Namely, define the beginning and ending address range of the
5618 text section generated for this compilation unit. */
5623 register unsigned i;
5624 register unsigned long aranges_length = size_of_aranges ();
5626 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
5628 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
5631 fputc ('\n', asm_out_file);
5632 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5634 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5636 fputc ('\n', asm_out_file);
5637 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5639 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5642 fputc ('\n', asm_out_file);
5643 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
5645 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
5647 fputc ('\n', asm_out_file);
5648 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5650 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
5653 fputc ('\n', asm_out_file);
5655 /* We need to align to twice the pointer size here. */
5656 if (DWARF_ARANGES_PAD_SIZE)
5658 /* Pad using a 2 bytes word so that padding is correct
5659 for any pointer size. */
5660 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
5661 for (i = 2; i < DWARF_ARANGES_PAD_SIZE; i += 2)
5662 fprintf (asm_out_file, ",0");
5664 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5665 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
5668 fputc ('\n', asm_out_file);
5669 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
5671 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5673 fputc ('\n', asm_out_file);
5674 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
5675 text_section_label);
5677 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5679 fputc ('\n', asm_out_file);
5680 for (i = 0; i < arange_table_in_use; ++i)
5682 dw_die_ref die = arange_table[i];
5684 if (die->die_tag == DW_TAG_subprogram)
5685 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
5688 /* A static variable; extract the symbol from DW_AT_location.
5689 Note that this code isn't currently hit, as we only emit
5690 aranges for functions (jason 9/23/99). */
5692 dw_attr_ref a = get_AT (die, DW_AT_location);
5693 dw_loc_descr_ref loc;
5694 if (! a || AT_class (a) != dw_val_class_loc)
5698 if (loc->dw_loc_opc != DW_OP_addr)
5701 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
5702 loc->dw_loc_oprnd1.v.val_addr);
5706 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5708 fputc ('\n', asm_out_file);
5709 if (die->die_tag == DW_TAG_subprogram)
5710 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
5711 get_AT_low_pc (die));
5713 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5714 get_AT_unsigned (die, DW_AT_byte_size));
5717 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5719 fputc ('\n', asm_out_file);
5722 /* Output the terminator words. */
5723 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5724 fputc ('\n', asm_out_file);
5725 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5726 fputc ('\n', asm_out_file);
5729 /* Output the source line number correspondence information. This
5730 information goes into the .debug_line section. */
5735 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5736 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5737 register unsigned opc;
5738 register unsigned n_op_args;
5739 register unsigned long ft_index;
5740 register unsigned long lt_index;
5741 register unsigned long current_line;
5742 register long line_offset;
5743 register long line_delta;
5744 register unsigned long current_file;
5745 register unsigned long function;
5747 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
5749 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5752 fputc ('\n', asm_out_file);
5753 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
5754 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5756 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5758 fputc ('\n', asm_out_file);
5759 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
5761 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5763 fputc ('\n', asm_out_file);
5764 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
5766 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5769 fputc ('\n', asm_out_file);
5770 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
5772 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5775 fputc ('\n', asm_out_file);
5776 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
5778 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5781 fputc ('\n', asm_out_file);
5782 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
5784 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5787 fputc ('\n', asm_out_file);
5788 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5790 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5792 fputc ('\n', asm_out_file);
5793 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5797 case DW_LNS_advance_pc:
5798 case DW_LNS_advance_line:
5799 case DW_LNS_set_file:
5800 case DW_LNS_set_column:
5801 case DW_LNS_fixed_advance_pc:
5808 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5810 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5811 ASM_COMMENT_START, opc, n_op_args);
5812 fputc ('\n', asm_out_file);
5816 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5818 /* Include directory table is empty, at present */
5819 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5820 fputc ('\n', asm_out_file);
5822 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5824 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5828 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5829 fprintf (asm_out_file, "%s File Entry: 0x%lx",
5830 ASM_COMMENT_START, ft_index);
5834 ASM_OUTPUT_ASCII (asm_out_file,
5835 file_table[ft_index],
5836 (int) strlen (file_table[ft_index]) + 1);
5839 fputc ('\n', asm_out_file);
5841 /* Include directory index */
5843 fputc ('\n', asm_out_file);
5845 /* Modification time */
5847 fputc ('\n', asm_out_file);
5849 /* File length in bytes */
5851 fputc ('\n', asm_out_file);
5854 /* Terminate the file name table */
5855 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5856 fputc ('\n', asm_out_file);
5858 /* We used to set the address register to the first location in the text
5859 section here, but that didn't accomplish anything since we already
5860 have a line note for the opening brace of the first function. */
5862 /* Generate the line number to PC correspondence table, encoded as
5863 a series of state machine operations. */
5866 strcpy (prev_line_label, text_section_label);
5867 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5869 register dw_line_info_ref line_info = &line_info_table[lt_index];
5872 /* Disable this optimization for now; GDB wants to see two line notes
5873 at the beginning of a function so it can find the end of the
5876 /* Don't emit anything for redundant notes. Just updating the
5877 address doesn't accomplish anything, because we already assume
5878 that anything after the last address is this line. */
5879 if (line_info->dw_line_num == current_line
5880 && line_info->dw_file_num == current_file)
5884 /* Emit debug info for the address of the current line, choosing
5885 the encoding that uses the least amount of space. */
5886 /* ??? Unfortunately, we have little choice here currently, and must
5887 always use the most general form. Gcc does not know the address
5888 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5889 dwarf2 aware assemblers at this time, so we can't use any special
5890 pseudo ops that would allow the assembler to optimally encode this for
5891 us. Many ports do have length attributes which will give an upper
5892 bound on the address range. We could perhaps use length attributes
5893 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5894 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5897 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5898 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5900 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5903 fputc ('\n', asm_out_file);
5904 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5905 fputc ('\n', asm_out_file);
5909 /* This can handle any delta. This takes
5910 4+DWARF2_ADDR_SIZE bytes. */
5911 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5913 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5915 fputc ('\n', asm_out_file);
5916 output_uleb128 (1 + DWARF2_ADDR_SIZE);
5917 fputc ('\n', asm_out_file);
5918 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5919 fputc ('\n', asm_out_file);
5920 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5921 fputc ('\n', asm_out_file);
5923 strcpy (prev_line_label, line_label);
5925 /* Emit debug info for the source file of the current line, if
5926 different from the previous line. */
5927 if (line_info->dw_file_num != current_file)
5929 current_file = line_info->dw_file_num;
5930 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5932 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5934 fputc ('\n', asm_out_file);
5935 output_uleb128 (current_file);
5937 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5939 fputc ('\n', asm_out_file);
5942 /* Emit debug info for the current line number, choosing the encoding
5943 that uses the least amount of space. */
5944 if (line_info->dw_line_num != current_line)
5946 line_offset = line_info->dw_line_num - current_line;
5947 line_delta = line_offset - DWARF_LINE_BASE;
5948 current_line = line_info->dw_line_num;
5949 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5951 /* This can handle deltas from -10 to 234, using the current
5952 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5954 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5955 DWARF_LINE_OPCODE_BASE + line_delta);
5957 fprintf (asm_out_file,
5958 "\t%s line %ld", ASM_COMMENT_START, current_line);
5960 fputc ('\n', asm_out_file);
5964 /* This can handle any delta. This takes at least 4 bytes,
5965 depending on the value being encoded. */
5966 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5968 fprintf (asm_out_file, "\t%s advance to line %ld",
5969 ASM_COMMENT_START, current_line);
5971 fputc ('\n', asm_out_file);
5972 output_sleb128 (line_offset);
5973 fputc ('\n', asm_out_file);
5974 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5976 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5977 fputc ('\n', asm_out_file);
5982 /* We still need to start a new row, so output a copy insn. */
5983 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5985 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5986 fputc ('\n', asm_out_file);
5990 /* Emit debug info for the address of the end of the function. */
5993 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5995 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5998 fputc ('\n', asm_out_file);
5999 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
6000 fputc ('\n', asm_out_file);
6004 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6006 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
6007 fputc ('\n', asm_out_file);
6008 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6009 fputc ('\n', asm_out_file);
6010 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6011 fputc ('\n', asm_out_file);
6012 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
6013 fputc ('\n', asm_out_file);
6016 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6018 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
6020 fputc ('\n', asm_out_file);
6022 fputc ('\n', asm_out_file);
6023 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6024 fputc ('\n', asm_out_file);
6029 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
6031 register dw_separate_line_info_ref line_info
6032 = &separate_line_info_table[lt_index];
6035 /* Don't emit anything for redundant notes. */
6036 if (line_info->dw_line_num == current_line
6037 && line_info->dw_file_num == current_file
6038 && line_info->function == function)
6042 /* Emit debug info for the address of the current line. If this is
6043 a new function, or the first line of a function, then we need
6044 to handle it differently. */
6045 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6047 if (function != line_info->function)
6049 function = line_info->function;
6051 /* Set the address register to the first line in the function */
6052 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6054 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6057 fputc ('\n', asm_out_file);
6058 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6059 fputc ('\n', asm_out_file);
6060 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6061 fputc ('\n', asm_out_file);
6062 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6063 fputc ('\n', asm_out_file);
6067 /* ??? See the DW_LNS_advance_pc comment above. */
6070 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6072 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6075 fputc ('\n', asm_out_file);
6076 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6078 fputc ('\n', asm_out_file);
6082 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6084 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6086 fputc ('\n', asm_out_file);
6087 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6088 fputc ('\n', asm_out_file);
6089 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6090 fputc ('\n', asm_out_file);
6091 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6092 fputc ('\n', asm_out_file);
6095 strcpy (prev_line_label, line_label);
6097 /* Emit debug info for the source file of the current line, if
6098 different from the previous line. */
6099 if (line_info->dw_file_num != current_file)
6101 current_file = line_info->dw_file_num;
6102 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6104 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6106 fputc ('\n', asm_out_file);
6107 output_uleb128 (current_file);
6109 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
6111 fputc ('\n', asm_out_file);
6114 /* Emit debug info for the current line number, choosing the encoding
6115 that uses the least amount of space. */
6116 if (line_info->dw_line_num != current_line)
6118 line_offset = line_info->dw_line_num - current_line;
6119 line_delta = line_offset - DWARF_LINE_BASE;
6120 current_line = line_info->dw_line_num;
6121 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6123 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6124 DWARF_LINE_OPCODE_BASE + line_delta);
6126 fprintf (asm_out_file,
6127 "\t%s line %ld", ASM_COMMENT_START, current_line);
6129 fputc ('\n', asm_out_file);
6133 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6135 fprintf (asm_out_file, "\t%s advance to line %ld",
6136 ASM_COMMENT_START, current_line);
6138 fputc ('\n', asm_out_file);
6139 output_sleb128 (line_offset);
6140 fputc ('\n', asm_out_file);
6141 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6143 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6144 fputc ('\n', asm_out_file);
6149 /* We still need to start a new row, so output a copy insn. */
6150 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6152 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6153 fputc ('\n', asm_out_file);
6161 /* If we're done with a function, end its sequence. */
6162 if (lt_index == separate_line_info_table_in_use
6163 || separate_line_info_table[lt_index].function != function)
6168 /* Emit debug info for the address of the end of the function. */
6169 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6172 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6174 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6177 fputc ('\n', asm_out_file);
6178 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6180 fputc ('\n', asm_out_file);
6184 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6186 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6188 fputc ('\n', asm_out_file);
6189 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6190 fputc ('\n', asm_out_file);
6191 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6192 fputc ('\n', asm_out_file);
6193 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6194 fputc ('\n', asm_out_file);
6197 /* Output the marker for the end of this sequence. */
6198 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6200 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
6203 fputc ('\n', asm_out_file);
6205 fputc ('\n', asm_out_file);
6206 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6207 fputc ('\n', asm_out_file);
6211 /* Output the marker for the end of the line number info. */
6212 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
6215 /* Given a pointer to a tree node for some base type, return a pointer to
6216 a DIE that describes the given type.
6218 This routine must only be called for GCC type nodes that correspond to
6219 Dwarf base (fundamental) types. */
6222 base_type_die (type)
6225 register dw_die_ref base_type_result;
6226 register const char *type_name;
6227 register enum dwarf_type encoding;
6228 register tree name = TYPE_NAME (type);
6230 if (TREE_CODE (type) == ERROR_MARK
6231 || TREE_CODE (type) == VOID_TYPE)
6236 if (TREE_CODE (name) == TYPE_DECL)
6237 name = DECL_NAME (name);
6239 type_name = IDENTIFIER_POINTER (name);
6242 type_name = "__unknown__";
6244 switch (TREE_CODE (type))
6247 /* Carefully distinguish the C character types, without messing
6248 up if the language is not C. Note that we check only for the names
6249 that contain spaces; other names might occur by coincidence in other
6251 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6252 && (type == char_type_node
6253 || ! strcmp (type_name, "signed char")
6254 || ! strcmp (type_name, "unsigned char"))))
6256 if (TREE_UNSIGNED (type))
6257 encoding = DW_ATE_unsigned;
6259 encoding = DW_ATE_signed;
6262 /* else fall through */
6265 /* GNU Pascal/Ada CHAR type. Not used in C. */
6266 if (TREE_UNSIGNED (type))
6267 encoding = DW_ATE_unsigned_char;
6269 encoding = DW_ATE_signed_char;
6273 encoding = DW_ATE_float;
6276 /* Dwarf2 doesn't know anything about complex ints, so use
6277 a user defined type for it. */
6279 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6280 encoding = DW_ATE_complex_float;
6282 encoding = DW_ATE_lo_user;
6286 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6287 encoding = DW_ATE_boolean;
6291 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6294 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6295 if (demangle_name_func)
6296 type_name = (*demangle_name_func) (type_name);
6298 add_AT_string (base_type_result, DW_AT_name, type_name);
6299 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6300 int_size_in_bytes (type));
6301 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6303 return base_type_result;
6306 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6307 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6308 a given type is generally the same as the given type, except that if the
6309 given type is a pointer or reference type, then the root type of the given
6310 type is the root type of the "basis" type for the pointer or reference
6311 type. (This definition of the "root" type is recursive.) Also, the root
6312 type of a `const' qualified type or a `volatile' qualified type is the
6313 root type of the given type without the qualifiers. */
6319 if (TREE_CODE (type) == ERROR_MARK)
6320 return error_mark_node;
6322 switch (TREE_CODE (type))
6325 return error_mark_node;
6328 case REFERENCE_TYPE:
6329 return type_main_variant (root_type (TREE_TYPE (type)));
6332 return type_main_variant (type);
6336 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6337 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6343 switch (TREE_CODE (type))
6358 case QUAL_UNION_TYPE:
6363 case REFERENCE_TYPE:
6376 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6377 entry that chains various modifiers in front of the given type. */
6380 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6382 register int is_const_type;
6383 register int is_volatile_type;
6384 register dw_die_ref context_die;
6386 register enum tree_code code = TREE_CODE (type);
6387 register dw_die_ref mod_type_die = NULL;
6388 register dw_die_ref sub_die = NULL;
6389 register tree item_type = NULL;
6391 if (code != ERROR_MARK)
6393 type = build_type_variant (type, is_const_type, is_volatile_type);
6395 mod_type_die = lookup_type_die (type);
6397 return mod_type_die;
6399 /* Handle C typedef types. */
6400 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6401 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6403 tree dtype = TREE_TYPE (TYPE_NAME (type));
6406 /* For a named type, use the typedef. */
6407 gen_type_die (type, context_die);
6408 mod_type_die = lookup_type_die (type);
6411 else if (is_const_type < TYPE_READONLY (dtype)
6412 || is_volatile_type < TYPE_VOLATILE (dtype))
6413 /* cv-unqualified version of named type. Just use the unnamed
6414 type to which it refers. */
6416 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6417 is_const_type, is_volatile_type,
6419 /* Else cv-qualified version of named type; fall through. */
6424 else if (is_const_type)
6426 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6427 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6429 else if (is_volatile_type)
6431 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6432 sub_die = modified_type_die (type, 0, 0, context_die);
6434 else if (code == POINTER_TYPE)
6436 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6437 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6439 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6441 item_type = TREE_TYPE (type);
6443 else if (code == REFERENCE_TYPE)
6445 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6446 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6448 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6450 item_type = TREE_TYPE (type);
6452 else if (is_base_type (type))
6453 mod_type_die = base_type_die (type);
6456 gen_type_die (type, context_die);
6458 /* We have to get the type_main_variant here (and pass that to the
6459 `lookup_type_die' routine) because the ..._TYPE node we have
6460 might simply be a *copy* of some original type node (where the
6461 copy was created to help us keep track of typedef names) and
6462 that copy might have a different TYPE_UID from the original
6464 mod_type_die = lookup_type_die (type_main_variant (type));
6465 if (mod_type_die == NULL)
6470 equate_type_number_to_die (type, mod_type_die);
6472 /* We must do this after the equate_type_number_to_die call, in case
6473 this is a recursive type. This ensures that the modified_type_die
6474 recursion will terminate even if the type is recursive. Recursive
6475 types are possible in Ada. */
6476 sub_die = modified_type_die (item_type,
6477 TYPE_READONLY (item_type),
6478 TYPE_VOLATILE (item_type),
6481 if (sub_die != NULL)
6482 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6484 return mod_type_die;
6487 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6488 an enumerated type. */
6494 return TREE_CODE (type) == ENUMERAL_TYPE;
6497 /* Return the register number described by a given RTL node. */
6503 register unsigned regno = REGNO (rtl);
6505 if (regno >= FIRST_PSEUDO_REGISTER)
6507 warning ("internal regno botch: regno = %d\n", regno);
6511 regno = DBX_REGISTER_NUMBER (regno);
6515 /* Return a location descriptor that designates a machine register. */
6517 static dw_loc_descr_ref
6518 reg_loc_descriptor (rtl)
6521 register dw_loc_descr_ref loc_result = NULL;
6522 register unsigned reg = reg_number (rtl);
6525 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6527 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6532 /* Return a location descriptor that designates a base+offset location. */
6534 static dw_loc_descr_ref
6535 based_loc_descr (reg, offset)
6539 register dw_loc_descr_ref loc_result;
6540 /* For the "frame base", we use the frame pointer or stack pointer
6541 registers, since the RTL for local variables is relative to one of
6543 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6544 ? HARD_FRAME_POINTER_REGNUM
6545 : STACK_POINTER_REGNUM);
6548 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
6550 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
6552 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
6557 /* Return true if this RTL expression describes a base+offset calculation. */
6563 return (GET_CODE (rtl) == PLUS
6564 && ((GET_CODE (XEXP (rtl, 0)) == REG
6565 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
6568 /* The following routine converts the RTL for a variable or parameter
6569 (resident in memory) into an equivalent Dwarf representation of a
6570 mechanism for getting the address of that same variable onto the top of a
6571 hypothetical "address evaluation" stack.
6573 When creating memory location descriptors, we are effectively transforming
6574 the RTL for a memory-resident object into its Dwarf postfix expression
6575 equivalent. This routine recursively descends an RTL tree, turning
6576 it into Dwarf postfix code as it goes.
6578 MODE is the mode of the memory reference, needed to handle some
6579 autoincrement addressing modes. */
6581 static dw_loc_descr_ref
6582 mem_loc_descriptor (rtl, mode)
6584 enum machine_mode mode;
6586 dw_loc_descr_ref mem_loc_result = NULL;
6587 /* Note that for a dynamically sized array, the location we will generate a
6588 description of here will be the lowest numbered location which is
6589 actually within the array. That's *not* necessarily the same as the
6590 zeroth element of the array. */
6592 #ifdef ASM_SIMPLIFY_DWARF_ADDR
6593 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
6596 switch (GET_CODE (rtl))
6600 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
6601 just fall into the SUBREG code. */
6603 /* ... fall through ... */
6606 /* The case of a subreg may arise when we have a local (register)
6607 variable or a formal (register) parameter which doesn't quite fill
6608 up an entire register. For now, just assume that it is
6609 legitimate to make the Dwarf info refer to the whole register which
6610 contains the given subreg. */
6611 rtl = XEXP (rtl, 0);
6613 /* ... fall through ... */
6616 /* Whenever a register number forms a part of the description of the
6617 method for calculating the (dynamic) address of a memory resident
6618 object, DWARF rules require the register number be referred to as
6619 a "base register". This distinction is not based in any way upon
6620 what category of register the hardware believes the given register
6621 belongs to. This is strictly DWARF terminology we're dealing with
6622 here. Note that in cases where the location of a memory-resident
6623 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6624 OP_CONST (0)) the actual DWARF location descriptor that we generate
6625 may just be OP_BASEREG (basereg). This may look deceptively like
6626 the object in question was allocated to a register (rather than in
6627 memory) so DWARF consumers need to be aware of the subtle
6628 distinction between OP_REG and OP_BASEREG. */
6629 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
6633 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
6634 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6638 /* Some ports can transform a symbol ref into a label ref, because
6639 the symbol ref is too far away and has to be dumped into a constant
6643 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6644 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6645 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
6650 /* Turn these into a PLUS expression and fall into the PLUS code
6652 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
6653 GEN_INT (GET_CODE (rtl) == PRE_INC
6654 ? GET_MODE_UNIT_SIZE (mode)
6655 : - GET_MODE_UNIT_SIZE (mode)));
6657 /* ... fall through ... */
6660 if (is_based_loc (rtl))
6661 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
6662 INTVAL (XEXP (rtl, 1)));
6665 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0),
6667 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1),
6669 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
6674 /* If a pseudo-reg is optimized away, it is possible for it to
6675 be replaced with a MEM containing a multiply. */
6676 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode));
6677 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode));
6678 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
6682 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6689 return mem_loc_result;
6692 /* Return a descriptor that describes the concatenation of two locations.
6693 This is typically a complex variable. */
6695 static dw_loc_descr_ref
6696 concat_loc_descriptor (x0, x1)
6697 register rtx x0, x1;
6699 dw_loc_descr_ref cc_loc_result = NULL;
6701 if (!is_pseudo_reg (x0)
6702 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
6703 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
6704 add_loc_descr (&cc_loc_result,
6705 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
6707 if (!is_pseudo_reg (x1)
6708 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
6709 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
6710 add_loc_descr (&cc_loc_result,
6711 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
6713 return cc_loc_result;
6716 /* Output a proper Dwarf location descriptor for a variable or parameter
6717 which is either allocated in a register or in a memory location. For a
6718 register, we just generate an OP_REG and the register number. For a
6719 memory location we provide a Dwarf postfix expression describing how to
6720 generate the (dynamic) address of the object onto the address stack. */
6722 static dw_loc_descr_ref
6723 loc_descriptor (rtl)
6726 dw_loc_descr_ref loc_result = NULL;
6727 switch (GET_CODE (rtl))
6730 /* The case of a subreg may arise when we have a local (register)
6731 variable or a formal (register) parameter which doesn't quite fill
6732 up an entire register. For now, just assume that it is
6733 legitimate to make the Dwarf info refer to the whole register which
6734 contains the given subreg. */
6735 rtl = XEXP (rtl, 0);
6737 /* ... fall through ... */
6740 loc_result = reg_loc_descriptor (rtl);
6744 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
6748 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
6758 /* Given a value, round it up to the lowest multiple of `boundary'
6759 which is not less than the value itself. */
6761 static inline HOST_WIDE_INT
6762 ceiling (value, boundary)
6763 HOST_WIDE_INT value;
6764 unsigned int boundary;
6766 return (((value + boundary - 1) / boundary) * boundary);
6769 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6770 pointer to the declared type for the relevant field variable, or return
6771 `integer_type_node' if the given node turns out to be an
6780 if (TREE_CODE (decl) == ERROR_MARK)
6781 return integer_type_node;
6783 type = DECL_BIT_FIELD_TYPE (decl);
6784 if (type == NULL_TREE)
6785 type = TREE_TYPE (decl);
6790 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6791 node, return the alignment in bits for the type, or else return
6792 BITS_PER_WORD if the node actually turns out to be an
6795 static inline unsigned
6796 simple_type_align_in_bits (type)
6799 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6802 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6803 node, return the size in bits for the type if it is a constant, or else
6804 return the alignment for the type if the type's size is not constant, or
6805 else return BITS_PER_WORD if the type actually turns out to be an
6808 static inline unsigned HOST_WIDE_INT
6809 simple_type_size_in_bits (type)
6812 if (TREE_CODE (type) == ERROR_MARK)
6813 return BITS_PER_WORD;
6816 register tree type_size_tree = TYPE_SIZE (type);
6818 if (! host_integerp (type_size_tree, 1))
6819 return TYPE_ALIGN (type);
6821 return tree_low_cst (type_size_tree, 1);
6825 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6826 return the byte offset of the lowest addressed byte of the "containing
6827 object" for the given FIELD_DECL, or return 0 if we are unable to
6828 determine what that offset is, either because the argument turns out to
6829 be a pointer to an ERROR_MARK node, or because the offset is actually
6830 variable. (We can't handle the latter case just yet). */
6832 static HOST_WIDE_INT
6833 field_byte_offset (decl)
6836 unsigned int type_align_in_bytes;
6837 unsigned int type_align_in_bits;
6838 unsigned HOST_WIDE_INT type_size_in_bits;
6839 HOST_WIDE_INT object_offset_in_align_units;
6840 HOST_WIDE_INT object_offset_in_bits;
6841 HOST_WIDE_INT object_offset_in_bytes;
6843 tree field_size_tree;
6844 HOST_WIDE_INT bitpos_int;
6845 HOST_WIDE_INT deepest_bitpos;
6846 unsigned HOST_WIDE_INT field_size_in_bits;
6848 if (TREE_CODE (decl) == ERROR_MARK)
6851 if (TREE_CODE (decl) != FIELD_DECL)
6854 type = field_type (decl);
6855 field_size_tree = DECL_SIZE (decl);
6857 /* If there was an error, the size could be zero. */
6858 if (! field_size_tree)
6866 /* We cannot yet cope with fields whose positions are variable, so
6867 for now, when we see such things, we simply return 0. Someday, we may
6868 be able to handle such cases, but it will be damn difficult. */
6869 if (! host_integerp (bit_position (decl), 0))
6872 bitpos_int = int_bit_position (decl);
6874 /* If we don't know the size of the field, pretend it's a full word. */
6875 if (host_integerp (field_size_tree, 1))
6876 field_size_in_bits = tree_low_cst (field_size_tree, 1);
6878 field_size_in_bits = BITS_PER_WORD;
6880 type_size_in_bits = simple_type_size_in_bits (type);
6881 type_align_in_bits = simple_type_align_in_bits (type);
6882 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6884 /* Note that the GCC front-end doesn't make any attempt to keep track of
6885 the starting bit offset (relative to the start of the containing
6886 structure type) of the hypothetical "containing object" for a bit-
6887 field. Thus, when computing the byte offset value for the start of the
6888 "containing object" of a bit-field, we must deduce this information on
6889 our own. This can be rather tricky to do in some cases. For example,
6890 handling the following structure type definition when compiling for an
6891 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6894 struct S { int field1; long long field2:31; };
6896 Fortunately, there is a simple rule-of-thumb which can be
6897 used in such cases. When compiling for an i386/i486, GCC will allocate
6898 8 bytes for the structure shown above. It decides to do this based upon
6899 one simple rule for bit-field allocation. Quite simply, GCC allocates
6900 each "containing object" for each bit-field at the first (i.e. lowest
6901 addressed) legitimate alignment boundary (based upon the required
6902 minimum alignment for the declared type of the field) which it can
6903 possibly use, subject to the condition that there is still enough
6904 available space remaining in the containing object (when allocated at
6905 the selected point) to fully accommodate all of the bits of the
6906 bit-field itself. This simple rule makes it obvious why GCC allocates
6907 8 bytes for each object of the structure type shown above. When looking
6908 for a place to allocate the "containing object" for `field2', the
6909 compiler simply tries to allocate a 64-bit "containing object" at each
6910 successive 32-bit boundary (starting at zero) until it finds a place to
6911 allocate that 64- bit field such that at least 31 contiguous (and
6912 previously unallocated) bits remain within that selected 64 bit field.
6913 (As it turns out, for the example above, the compiler finds that it is
6914 OK to allocate the "containing object" 64-bit field at bit-offset zero
6915 within the structure type.) Here we attempt to work backwards from the
6916 limited set of facts we're given, and we try to deduce from those facts,
6917 where GCC must have believed that the containing object started (within
6918 the structure type). The value we deduce is then used (by the callers of
6919 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6920 for fields (both bit-fields and, in the case of DW_AT_location, regular
6923 /* Figure out the bit-distance from the start of the structure to the
6924 "deepest" bit of the bit-field. */
6925 deepest_bitpos = bitpos_int + field_size_in_bits;
6927 /* This is the tricky part. Use some fancy footwork to deduce where the
6928 lowest addressed bit of the containing object must be. */
6929 object_offset_in_bits
6930 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6932 /* Compute the offset of the containing object in "alignment units". */
6933 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6935 /* Compute the offset of the containing object in bytes. */
6936 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6938 return object_offset_in_bytes;
6941 /* The following routines define various Dwarf attributes and any data
6942 associated with them. */
6944 /* Add a location description attribute value to a DIE.
6946 This emits location attributes suitable for whole variables and
6947 whole parameters. Note that the location attributes for struct fields are
6948 generated by the routine `data_member_location_attribute' below. */
6951 add_AT_location_description (die, attr_kind, rtl)
6953 enum dwarf_attribute attr_kind;
6956 /* Handle a special case. If we are about to output a location descriptor
6957 for a variable or parameter which has been optimized out of existence,
6958 don't do that. A variable which has been optimized out
6959 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6960 Currently, in some rare cases, variables can have DECL_RTL values which
6961 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6962 elsewhere in the compiler. We treat such cases as if the variable(s) in
6963 question had been optimized out of existence. */
6965 if (is_pseudo_reg (rtl)
6966 || (GET_CODE (rtl) == MEM
6967 && is_pseudo_reg (XEXP (rtl, 0)))
6968 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
6969 references the internal argument pointer (a pseudo) in a function
6970 where all references to the internal argument pointer were
6971 eliminated via the optimizers. */
6972 || (GET_CODE (rtl) == MEM
6973 && GET_CODE (XEXP (rtl, 0)) == PLUS
6974 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
6975 || (GET_CODE (rtl) == CONCAT
6976 && is_pseudo_reg (XEXP (rtl, 0))
6977 && is_pseudo_reg (XEXP (rtl, 1))))
6980 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
6983 /* Attach the specialized form of location attribute used for data
6984 members of struct and union types. In the special case of a
6985 FIELD_DECL node which represents a bit-field, the "offset" part
6986 of this special location descriptor must indicate the distance
6987 in bytes from the lowest-addressed byte of the containing struct
6988 or union type to the lowest-addressed byte of the "containing
6989 object" for the bit-field. (See the `field_byte_offset' function
6990 above).. For any given bit-field, the "containing object" is a
6991 hypothetical object (of some integral or enum type) within which
6992 the given bit-field lives. The type of this hypothetical
6993 "containing object" is always the same as the declared type of
6994 the individual bit-field itself (for GCC anyway... the DWARF
6995 spec doesn't actually mandate this). Note that it is the size
6996 (in bytes) of the hypothetical "containing object" which will
6997 be given in the DW_AT_byte_size attribute for this bit-field.
6998 (See the `byte_size_attribute' function below.) It is also used
6999 when calculating the value of the DW_AT_bit_offset attribute.
7000 (See the `bit_offset_attribute' function below). */
7003 add_data_member_location_attribute (die, decl)
7004 register dw_die_ref die;
7007 register unsigned long offset;
7008 register dw_loc_descr_ref loc_descr;
7009 register enum dwarf_location_atom op;
7011 if (TREE_CODE (decl) == TREE_VEC)
7012 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
7014 offset = field_byte_offset (decl);
7016 /* The DWARF2 standard says that we should assume that the structure address
7017 is already on the stack, so we can specify a structure field address
7018 by using DW_OP_plus_uconst. */
7020 #ifdef MIPS_DEBUGGING_INFO
7021 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
7022 correctly. It works only if we leave the offset on the stack. */
7025 op = DW_OP_plus_uconst;
7028 loc_descr = new_loc_descr (op, offset, 0);
7029 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
7032 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
7033 does not have a "location" either in memory or in a register. These
7034 things can arise in GNU C when a constant is passed as an actual parameter
7035 to an inlined function. They can also arise in C++ where declared
7036 constants do not necessarily get memory "homes". */
7039 add_const_value_attribute (die, rtl)
7040 register dw_die_ref die;
7043 switch (GET_CODE (rtl))
7046 /* Note that a CONST_INT rtx could represent either an integer or a
7047 floating-point constant. A CONST_INT is used whenever the constant
7048 will fit into a single word. In all such cases, the original mode
7049 of the constant value is wiped out, and the CONST_INT rtx is
7050 assigned VOIDmode. */
7051 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
7055 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
7056 floating-point constant. A CONST_DOUBLE is used whenever the
7057 constant requires more than one word in order to be adequately
7058 represented. We output CONST_DOUBLEs as blocks. */
7060 register enum machine_mode mode = GET_MODE (rtl);
7062 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
7064 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
7068 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
7072 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
7076 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
7081 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
7088 add_AT_float (die, DW_AT_const_value, length, array);
7091 add_AT_long_long (die, DW_AT_const_value,
7092 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
7097 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
7103 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
7107 /* In cases where an inlined instance of an inline function is passed
7108 the address of an `auto' variable (which is local to the caller) we
7109 can get a situation where the DECL_RTL of the artificial local
7110 variable (for the inlining) which acts as a stand-in for the
7111 corresponding formal parameter (of the inline function) will look
7112 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
7113 exactly a compile-time constant expression, but it isn't the address
7114 of the (artificial) local variable either. Rather, it represents the
7115 *value* which the artificial local variable always has during its
7116 lifetime. We currently have no way to represent such quasi-constant
7117 values in Dwarf, so for now we just punt and generate nothing. */
7121 /* No other kinds of rtx should be possible here. */
7127 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
7128 data attribute for a variable or a parameter. We generate the
7129 DW_AT_const_value attribute only in those cases where the given variable
7130 or parameter does not have a true "location" either in memory or in a
7131 register. This can happen (for example) when a constant is passed as an
7132 actual argument in a call to an inline function. (It's possible that
7133 these things can crop up in other ways also.) Note that one type of
7134 constant value which can be passed into an inlined function is a constant
7135 pointer. This can happen for example if an actual argument in an inlined
7136 function call evaluates to a compile-time constant address. */
7139 add_location_or_const_value_attribute (die, decl)
7140 register dw_die_ref die;
7144 register tree declared_type;
7145 register tree passed_type;
7147 if (TREE_CODE (decl) == ERROR_MARK)
7150 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
7153 /* Here we have to decide where we are going to say the parameter "lives"
7154 (as far as the debugger is concerned). We only have a couple of
7155 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
7157 DECL_RTL normally indicates where the parameter lives during most of the
7158 activation of the function. If optimization is enabled however, this
7159 could be either NULL or else a pseudo-reg. Both of those cases indicate
7160 that the parameter doesn't really live anywhere (as far as the code
7161 generation parts of GCC are concerned) during most of the function's
7162 activation. That will happen (for example) if the parameter is never
7163 referenced within the function.
7165 We could just generate a location descriptor here for all non-NULL
7166 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
7167 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
7168 where DECL_RTL is NULL or is a pseudo-reg.
7170 Note however that we can only get away with using DECL_INCOMING_RTL as
7171 a backup substitute for DECL_RTL in certain limited cases. In cases
7172 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
7173 we can be sure that the parameter was passed using the same type as it is
7174 declared to have within the function, and that its DECL_INCOMING_RTL
7175 points us to a place where a value of that type is passed.
7177 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
7178 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
7179 because in these cases DECL_INCOMING_RTL points us to a value of some
7180 type which is *different* from the type of the parameter itself. Thus,
7181 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
7182 such cases, the debugger would end up (for example) trying to fetch a
7183 `float' from a place which actually contains the first part of a
7184 `double'. That would lead to really incorrect and confusing
7185 output at debug-time.
7187 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
7188 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
7189 are a couple of exceptions however. On little-endian machines we can
7190 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
7191 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
7192 an integral type that is smaller than TREE_TYPE (decl). These cases arise
7193 when (on a little-endian machine) a non-prototyped function has a
7194 parameter declared to be of type `short' or `char'. In such cases,
7195 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
7196 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
7197 passed `int' value. If the debugger then uses that address to fetch
7198 a `short' or a `char' (on a little-endian machine) the result will be
7199 the correct data, so we allow for such exceptional cases below.
7201 Note that our goal here is to describe the place where the given formal
7202 parameter lives during most of the function's activation (i.e. between
7203 the end of the prologue and the start of the epilogue). We'll do that
7204 as best as we can. Note however that if the given formal parameter is
7205 modified sometime during the execution of the function, then a stack
7206 backtrace (at debug-time) will show the function as having been
7207 called with the *new* value rather than the value which was
7208 originally passed in. This happens rarely enough that it is not
7209 a major problem, but it *is* a problem, and I'd like to fix it.
7211 A future version of dwarf2out.c may generate two additional
7212 attributes for any given DW_TAG_formal_parameter DIE which will
7213 describe the "passed type" and the "passed location" for the
7214 given formal parameter in addition to the attributes we now
7215 generate to indicate the "declared type" and the "active
7216 location" for each parameter. This additional set of attributes
7217 could be used by debuggers for stack backtraces. Separately, note
7218 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
7219 NULL also. This happens (for example) for inlined-instances of
7220 inline function formal parameters which are never referenced.
7221 This really shouldn't be happening. All PARM_DECL nodes should
7222 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
7223 doesn't currently generate these values for inlined instances of
7224 inline function parameters, so when we see such cases, we are
7225 just out-of-luck for the time being (until integrate.c
7228 /* Use DECL_RTL as the "location" unless we find something better. */
7229 rtl = DECL_RTL (decl);
7231 if (TREE_CODE (decl) == PARM_DECL)
7233 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
7235 declared_type = type_main_variant (TREE_TYPE (decl));
7236 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
7238 /* This decl represents a formal parameter which was optimized out.
7239 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
7240 all* cases where (rtl == NULL_RTX) just below. */
7241 if (declared_type == passed_type)
7242 rtl = DECL_INCOMING_RTL (decl);
7243 else if (! BYTES_BIG_ENDIAN
7244 && TREE_CODE (declared_type) == INTEGER_TYPE
7245 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
7246 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
7247 rtl = DECL_INCOMING_RTL (decl);
7250 /* If the parm was passed in registers, but lives on the stack, then
7251 make a big endian correction if the mode of the type of the
7252 parameter is not the same as the mode of the rtl. */
7253 /* ??? This is the same series of checks that are made in dbxout.c before
7254 we reach the big endian correction code there. It isn't clear if all
7255 of these checks are necessary here, but keeping them all is the safe
7257 else if (GET_CODE (rtl) == MEM
7258 && XEXP (rtl, 0) != const0_rtx
7259 && ! CONSTANT_P (XEXP (rtl, 0))
7260 /* Not passed in memory. */
7261 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
7262 /* Not passed by invisible reference. */
7263 && (GET_CODE (XEXP (rtl, 0)) != REG
7264 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
7265 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
7266 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
7267 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
7270 /* Big endian correction check. */
7272 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
7273 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
7276 int offset = (UNITS_PER_WORD
7277 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
7278 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
7279 plus_constant (XEXP (rtl, 0), offset));
7283 if (rtl == NULL_RTX)
7286 rtl = eliminate_regs (rtl, 0, NULL_RTX);
7287 #ifdef LEAF_REG_REMAP
7288 if (current_function_uses_only_leaf_regs)
7289 leaf_renumber_regs_insn (rtl);
7292 switch (GET_CODE (rtl))
7295 /* The address of a variable that was optimized away; don't emit
7306 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7307 add_const_value_attribute (die, rtl);
7314 add_AT_location_description (die, DW_AT_location, rtl);
7322 /* Generate an DW_AT_name attribute given some string value to be included as
7323 the value of the attribute. */
7326 add_name_attribute (die, name_string)
7327 register dw_die_ref die;
7328 register const char *name_string;
7330 if (name_string != NULL && *name_string != 0)
7332 if (demangle_name_func)
7333 name_string = (*demangle_name_func) (name_string);
7335 add_AT_string (die, DW_AT_name, name_string);
7339 /* Given a tree node describing an array bound (either lower or upper) output
7340 a representation for that bound. */
7343 add_bound_info (subrange_die, bound_attr, bound)
7344 register dw_die_ref subrange_die;
7345 register enum dwarf_attribute bound_attr;
7346 register tree bound;
7348 /* If this is an Ada unconstrained array type, then don't emit any debug
7349 info because the array bounds are unknown. They are parameterized when
7350 the type is instantiated. */
7351 if (contains_placeholder_p (bound))
7354 switch (TREE_CODE (bound))
7359 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7361 if (! host_integerp (bound, 0)
7362 || (bound_attr == DW_AT_lower_bound
7363 && ((is_c_family () && integer_zerop (bound))
7364 || (is_fortran () && integer_onep (bound)))))
7365 /* use the default */
7368 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
7373 case NON_LVALUE_EXPR:
7374 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7378 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7379 access the upper bound values may be bogus. If they refer to a
7380 register, they may only describe how to get at these values at the
7381 points in the generated code right after they have just been
7382 computed. Worse yet, in the typical case, the upper bound values
7383 will not even *be* computed in the optimized code (though the
7384 number of elements will), so these SAVE_EXPRs are entirely
7385 bogus. In order to compensate for this fact, we check here to see
7386 if optimization is enabled, and if so, we don't add an attribute
7387 for the (unknown and unknowable) upper bound. This should not
7388 cause too much trouble for existing (stupid?) debuggers because
7389 they have to deal with empty upper bounds location descriptions
7390 anyway in order to be able to deal with incomplete array types.
7391 Of course an intelligent debugger (GDB?) should be able to
7392 comprehend that a missing upper bound specification in a array
7393 type used for a storage class `auto' local array variable
7394 indicates that the upper bound is both unknown (at compile- time)
7395 and unknowable (at run-time) due to optimization.
7397 We assume that a MEM rtx is safe because gcc wouldn't put the
7398 value there unless it was going to be used repeatedly in the
7399 function, i.e. for cleanups. */
7400 if (! optimize || (SAVE_EXPR_RTL (bound)
7401 && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
7403 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7404 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7405 register rtx loc = SAVE_EXPR_RTL (bound);
7407 /* If the RTL for the SAVE_EXPR is memory, handle the case where
7408 it references an outer function's frame. */
7410 if (GET_CODE (loc) == MEM)
7412 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
7414 if (XEXP (loc, 0) != new_addr)
7415 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
7418 add_AT_flag (decl_die, DW_AT_artificial, 1);
7419 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
7420 add_AT_location_description (decl_die, DW_AT_location, loc);
7421 add_AT_die_ref (subrange_die, bound_attr, decl_die);
7424 /* Else leave out the attribute. */
7430 /* ??? These types of bounds can be created by the Ada front end,
7431 and it isn't clear how to emit debug info for them. */
7439 /* Note that the block of subscript information for an array type also
7440 includes information about the element type of type given array type. */
7443 add_subscript_info (type_die, type)
7444 register dw_die_ref type_die;
7447 #ifndef MIPS_DEBUGGING_INFO
7448 register unsigned dimension_number;
7450 register tree lower, upper;
7451 register dw_die_ref subrange_die;
7453 /* The GNU compilers represent multidimensional array types as sequences of
7454 one dimensional array types whose element types are themselves array
7455 types. Here we squish that down, so that each multidimensional array
7456 type gets only one array_type DIE in the Dwarf debugging info. The draft
7457 Dwarf specification say that we are allowed to do this kind of
7458 compression in C (because there is no difference between an array or
7459 arrays and a multidimensional array in C) but for other source languages
7460 (e.g. Ada) we probably shouldn't do this. */
7462 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7463 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7464 We work around this by disabling this feature. See also
7465 gen_array_type_die. */
7466 #ifndef MIPS_DEBUGGING_INFO
7467 for (dimension_number = 0;
7468 TREE_CODE (type) == ARRAY_TYPE;
7469 type = TREE_TYPE (type), dimension_number++)
7472 register tree domain = TYPE_DOMAIN (type);
7474 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7475 and (in GNU C only) variable bounds. Handle all three forms
7477 subrange_die = new_die (DW_TAG_subrange_type, type_die);
7480 /* We have an array type with specified bounds. */
7481 lower = TYPE_MIN_VALUE (domain);
7482 upper = TYPE_MAX_VALUE (domain);
7484 /* define the index type. */
7485 if (TREE_TYPE (domain))
7487 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7488 TREE_TYPE field. We can't emit debug info for this
7489 because it is an unnamed integral type. */
7490 if (TREE_CODE (domain) == INTEGER_TYPE
7491 && TYPE_NAME (domain) == NULL_TREE
7492 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
7493 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
7496 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
7500 /* ??? If upper is NULL, the array has unspecified length,
7501 but it does have a lower bound. This happens with Fortran
7503 Since the debugger is definitely going to need to know N
7504 to produce useful results, go ahead and output the lower
7505 bound solo, and hope the debugger can cope. */
7507 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
7509 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
7512 /* We have an array type with an unspecified length. The DWARF-2
7513 spec does not say how to handle this; let's just leave out the
7518 #ifndef MIPS_DEBUGGING_INFO
7524 add_byte_size_attribute (die, tree_node)
7526 register tree tree_node;
7528 register unsigned size;
7530 switch (TREE_CODE (tree_node))
7538 case QUAL_UNION_TYPE:
7539 size = int_size_in_bytes (tree_node);
7542 /* For a data member of a struct or union, the DW_AT_byte_size is
7543 generally given as the number of bytes normally allocated for an
7544 object of the *declared* type of the member itself. This is true
7545 even for bit-fields. */
7546 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
7552 /* Note that `size' might be -1 when we get to this point. If it is, that
7553 indicates that the byte size of the entity in question is variable. We
7554 have no good way of expressing this fact in Dwarf at the present time,
7555 so just let the -1 pass on through. */
7557 add_AT_unsigned (die, DW_AT_byte_size, size);
7560 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7561 which specifies the distance in bits from the highest order bit of the
7562 "containing object" for the bit-field to the highest order bit of the
7565 For any given bit-field, the "containing object" is a hypothetical
7566 object (of some integral or enum type) within which the given bit-field
7567 lives. The type of this hypothetical "containing object" is always the
7568 same as the declared type of the individual bit-field itself. The
7569 determination of the exact location of the "containing object" for a
7570 bit-field is rather complicated. It's handled by the
7571 `field_byte_offset' function (above).
7573 Note that it is the size (in bytes) of the hypothetical "containing object"
7574 which will be given in the DW_AT_byte_size attribute for this bit-field.
7575 (See `byte_size_attribute' above). */
7578 add_bit_offset_attribute (die, decl)
7579 register dw_die_ref die;
7582 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
7583 tree type = DECL_BIT_FIELD_TYPE (decl);
7584 HOST_WIDE_INT bitpos_int;
7585 HOST_WIDE_INT highest_order_object_bit_offset;
7586 HOST_WIDE_INT highest_order_field_bit_offset;
7587 HOST_WIDE_INT unsigned bit_offset;
7589 /* Must be a field and a bit field. */
7591 || TREE_CODE (decl) != FIELD_DECL)
7594 /* We can't yet handle bit-fields whose offsets are variable, so if we
7595 encounter such things, just return without generating any attribute
7596 whatsoever. Likewise for variable or too large size. */
7597 if (! host_integerp (bit_position (decl), 0)
7598 || ! host_integerp (DECL_SIZE (decl), 1))
7601 bitpos_int = int_bit_position (decl);
7603 /* Note that the bit offset is always the distance (in bits) from the
7604 highest-order bit of the "containing object" to the highest-order bit of
7605 the bit-field itself. Since the "high-order end" of any object or field
7606 is different on big-endian and little-endian machines, the computation
7607 below must take account of these differences. */
7608 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
7609 highest_order_field_bit_offset = bitpos_int;
7611 if (! BYTES_BIG_ENDIAN)
7613 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
7614 highest_order_object_bit_offset += simple_type_size_in_bits (type);
7618 = (! BYTES_BIG_ENDIAN
7619 ? highest_order_object_bit_offset - highest_order_field_bit_offset
7620 : highest_order_field_bit_offset - highest_order_object_bit_offset);
7622 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
7625 /* For a FIELD_DECL node which represents a bit field, output an attribute
7626 which specifies the length in bits of the given field. */
7629 add_bit_size_attribute (die, decl)
7630 register dw_die_ref die;
7633 /* Must be a field and a bit field. */
7634 if (TREE_CODE (decl) != FIELD_DECL
7635 || ! DECL_BIT_FIELD_TYPE (decl))
7638 if (host_integerp (DECL_SIZE (decl), 1))
7639 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
7642 /* If the compiled language is ANSI C, then add a 'prototyped'
7643 attribute, if arg types are given for the parameters of a function. */
7646 add_prototyped_attribute (die, func_type)
7647 register dw_die_ref die;
7648 register tree func_type;
7650 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
7651 && TYPE_ARG_TYPES (func_type) != NULL)
7652 add_AT_flag (die, DW_AT_prototyped, 1);
7656 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7657 by looking in either the type declaration or object declaration
7661 add_abstract_origin_attribute (die, origin)
7662 register dw_die_ref die;
7663 register tree origin;
7665 dw_die_ref origin_die = NULL;
7667 if (TREE_CODE (origin) != FUNCTION_DECL)
7669 /* We may have gotten separated from the block for the inlined
7670 function, if we're in an exception handler or some such; make
7671 sure that the abstract function has been written out.
7673 Doing this for nested functions is wrong, however; functions are
7674 distinct units, and our context might not even be inline. */
7677 fn = TYPE_STUB_DECL (fn);
7678 fn = decl_function_context (fn);
7680 gen_abstract_function (fn);
7683 if (DECL_P (origin))
7684 origin_die = lookup_decl_die (origin);
7685 else if (TYPE_P (origin))
7686 origin_die = lookup_type_die (origin);
7688 if (origin_die == NULL)
7691 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
7694 /* We do not currently support the pure_virtual attribute. */
7697 add_pure_or_virtual_attribute (die, func_decl)
7698 register dw_die_ref die;
7699 register tree func_decl;
7701 if (DECL_VINDEX (func_decl))
7703 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7705 if (host_integerp (DECL_VINDEX (func_decl), 0))
7706 add_AT_loc (die, DW_AT_vtable_elem_location,
7707 new_loc_descr (DW_OP_constu,
7708 tree_low_cst (DECL_VINDEX (func_decl), 0),
7711 /* GNU extension: Record what type this method came from originally. */
7712 if (debug_info_level > DINFO_LEVEL_TERSE)
7713 add_AT_die_ref (die, DW_AT_containing_type,
7714 lookup_type_die (DECL_CONTEXT (func_decl)));
7718 /* Add source coordinate attributes for the given decl. */
7721 add_src_coords_attributes (die, decl)
7722 register dw_die_ref die;
7725 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
7727 add_AT_unsigned (die, DW_AT_decl_file, file_index);
7728 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7731 /* Add an DW_AT_name attribute and source coordinate attribute for the
7732 given decl, but only if it actually has a name. */
7735 add_name_and_src_coords_attributes (die, decl)
7736 register dw_die_ref die;
7739 register tree decl_name;
7741 decl_name = DECL_NAME (decl);
7742 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
7744 add_name_attribute (die, dwarf2_name (decl, 0));
7745 if (! DECL_ARTIFICIAL (decl))
7746 add_src_coords_attributes (die, decl);
7748 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
7749 && TREE_PUBLIC (decl)
7750 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
7751 add_AT_string (die, DW_AT_MIPS_linkage_name,
7752 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
7756 /* Push a new declaration scope. */
7759 push_decl_scope (scope)
7762 /* Make room in the decl_scope_table, if necessary. */
7763 if (decl_scope_table_allocated == decl_scope_depth)
7765 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
7767 = (tree *) xrealloc (decl_scope_table,
7768 decl_scope_table_allocated * sizeof (tree));
7771 decl_scope_table[decl_scope_depth] = scope;
7775 /* Pop a declaration scope. */
7779 if (decl_scope_depth <= 0)
7784 /* Return the DIE for the scope that immediately contains this type.
7785 Non-named types get global scope. Named types nested in other
7786 types get their containing scope if it's open, or global scope
7787 otherwise. All other types (i.e. function-local named types) get
7788 the current active scope. */
7791 scope_die_for (t, context_die)
7793 register dw_die_ref context_die;
7795 register dw_die_ref scope_die = NULL;
7796 register tree containing_scope;
7799 /* Non-types always go in the current scope. */
7803 containing_scope = TYPE_CONTEXT (t);
7805 /* Ignore namespaces for the moment. */
7806 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
7807 containing_scope = NULL_TREE;
7809 /* Ignore function type "scopes" from the C frontend. They mean that
7810 a tagged type is local to a parmlist of a function declarator, but
7811 that isn't useful to DWARF. */
7812 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
7813 containing_scope = NULL_TREE;
7815 if (containing_scope == NULL_TREE)
7816 scope_die = comp_unit_die;
7817 else if (TYPE_P (containing_scope))
7819 /* For types, we can just look up the appropriate DIE. But
7820 first we check to see if we're in the middle of emitting it
7821 so we know where the new DIE should go. */
7823 for (i = decl_scope_depth - 1; i >= 0; --i)
7824 if (decl_scope_table[i] == containing_scope)
7829 if (debug_info_level > DINFO_LEVEL_TERSE
7830 && !TREE_ASM_WRITTEN (containing_scope))
7833 /* If none of the current dies are suitable, we get file scope. */
7834 scope_die = comp_unit_die;
7837 scope_die = lookup_type_die (containing_scope);
7840 scope_die = context_die;
7845 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
7847 static inline int local_scope_p PARAMS ((dw_die_ref));
7849 local_scope_p (context_die)
7850 dw_die_ref context_die;
7852 for (; context_die; context_die = context_die->die_parent)
7853 if (context_die->die_tag == DW_TAG_inlined_subroutine
7854 || context_die->die_tag == DW_TAG_subprogram)
7859 /* Returns nonzero iff CONTEXT_DIE is a class. */
7861 static inline int class_scope_p PARAMS ((dw_die_ref));
7863 class_scope_p (context_die)
7864 dw_die_ref context_die;
7867 && (context_die->die_tag == DW_TAG_structure_type
7868 || context_die->die_tag == DW_TAG_union_type));
7871 /* Many forms of DIEs require a "type description" attribute. This
7872 routine locates the proper "type descriptor" die for the type given
7873 by 'type', and adds an DW_AT_type attribute below the given die. */
7876 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
7877 register dw_die_ref object_die;
7879 register int decl_const;
7880 register int decl_volatile;
7881 register dw_die_ref context_die;
7883 register enum tree_code code = TREE_CODE (type);
7884 register dw_die_ref type_die = NULL;
7886 /* ??? If this type is an unnamed subrange type of an integral or
7887 floating-point type, use the inner type. This is because we have no
7888 support for unnamed types in base_type_die. This can happen if this is
7889 an Ada subrange type. Correct solution is emit a subrange type die. */
7890 if ((code == INTEGER_TYPE || code == REAL_TYPE)
7891 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
7892 type = TREE_TYPE (type), code = TREE_CODE (type);
7894 if (code == ERROR_MARK)
7897 /* Handle a special case. For functions whose return type is void, we
7898 generate *no* type attribute. (Note that no object may have type
7899 `void', so this only applies to function return types). */
7900 if (code == VOID_TYPE)
7903 type_die = modified_type_die (type,
7904 decl_const || TYPE_READONLY (type),
7905 decl_volatile || TYPE_VOLATILE (type),
7907 if (type_die != NULL)
7908 add_AT_die_ref (object_die, DW_AT_type, type_die);
7911 /* Given a tree pointer to a struct, class, union, or enum type node, return
7912 a pointer to the (string) tag name for the given type, or zero if the type
7913 was declared without a tag. */
7919 register const char *name = 0;
7921 if (TYPE_NAME (type) != 0)
7923 register tree t = 0;
7925 /* Find the IDENTIFIER_NODE for the type name. */
7926 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7927 t = TYPE_NAME (type);
7929 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7930 a TYPE_DECL node, regardless of whether or not a `typedef' was
7932 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7933 && ! DECL_IGNORED_P (TYPE_NAME (type)))
7934 t = DECL_NAME (TYPE_NAME (type));
7936 /* Now get the name as a string, or invent one. */
7938 name = IDENTIFIER_POINTER (t);
7941 return (name == 0 || *name == '\0') ? 0 : name;
7944 /* Return the type associated with a data member, make a special check
7945 for bit field types. */
7948 member_declared_type (member)
7949 register tree member;
7951 return (DECL_BIT_FIELD_TYPE (member)
7952 ? DECL_BIT_FIELD_TYPE (member)
7953 : TREE_TYPE (member));
7956 /* Get the decl's label, as described by its RTL. This may be different
7957 from the DECL_NAME name used in the source file. */
7961 decl_start_label (decl)
7966 x = DECL_RTL (decl);
7967 if (GET_CODE (x) != MEM)
7971 if (GET_CODE (x) != SYMBOL_REF)
7974 fnname = XSTR (x, 0);
7979 /* These routines generate the internal representation of the DIE's for
7980 the compilation unit. Debugging information is collected by walking
7981 the declaration trees passed in from dwarf2out_decl(). */
7984 gen_array_type_die (type, context_die)
7986 register dw_die_ref context_die;
7988 register dw_die_ref scope_die = scope_die_for (type, context_die);
7989 register dw_die_ref array_die;
7990 register tree element_type;
7992 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7993 the inner array type comes before the outer array type. Thus we must
7994 call gen_type_die before we call new_die. See below also. */
7995 #ifdef MIPS_DEBUGGING_INFO
7996 gen_type_die (TREE_TYPE (type), context_die);
7999 array_die = new_die (DW_TAG_array_type, scope_die);
8002 /* We default the array ordering. SDB will probably do
8003 the right things even if DW_AT_ordering is not present. It's not even
8004 an issue until we start to get into multidimensional arrays anyway. If
8005 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
8006 then we'll have to put the DW_AT_ordering attribute back in. (But if
8007 and when we find out that we need to put these in, we will only do so
8008 for multidimensional arrays. */
8009 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
8012 #ifdef MIPS_DEBUGGING_INFO
8013 /* The SGI compilers handle arrays of unknown bound by setting
8014 AT_declaration and not emitting any subrange DIEs. */
8015 if (! TYPE_DOMAIN (type))
8016 add_AT_unsigned (array_die, DW_AT_declaration, 1);
8019 add_subscript_info (array_die, type);
8021 add_name_attribute (array_die, type_tag (type));
8022 equate_type_number_to_die (type, array_die);
8024 /* Add representation of the type of the elements of this array type. */
8025 element_type = TREE_TYPE (type);
8027 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8028 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8029 We work around this by disabling this feature. See also
8030 add_subscript_info. */
8031 #ifndef MIPS_DEBUGGING_INFO
8032 while (TREE_CODE (element_type) == ARRAY_TYPE)
8033 element_type = TREE_TYPE (element_type);
8035 gen_type_die (element_type, context_die);
8038 add_type_attribute (array_die, element_type, 0, 0, context_die);
8042 gen_set_type_die (type, context_die)
8044 register dw_die_ref context_die;
8046 register dw_die_ref type_die
8047 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
8049 equate_type_number_to_die (type, type_die);
8050 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
8055 gen_entry_point_die (decl, context_die)
8057 register dw_die_ref context_die;
8059 register tree origin = decl_ultimate_origin (decl);
8060 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
8062 add_abstract_origin_attribute (decl_die, origin);
8065 add_name_and_src_coords_attributes (decl_die, decl);
8066 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
8070 if (DECL_ABSTRACT (decl))
8071 equate_decl_number_to_die (decl, decl_die);
8073 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
8077 /* Remember a type in the incomplete_types_list. */
8080 add_incomplete_type (type)
8083 if (incomplete_types == incomplete_types_allocated)
8085 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
8086 incomplete_types_list
8087 = (tree *) xrealloc (incomplete_types_list,
8088 sizeof (tree) * incomplete_types_allocated);
8091 incomplete_types_list[incomplete_types++] = type;
8094 /* Walk through the list of incomplete types again, trying once more to
8095 emit full debugging info for them. */
8098 retry_incomplete_types ()
8102 while (incomplete_types)
8105 type = incomplete_types_list[incomplete_types];
8106 gen_type_die (type, comp_unit_die);
8110 /* Generate a DIE to represent an inlined instance of an enumeration type. */
8113 gen_inlined_enumeration_type_die (type, context_die)
8115 register dw_die_ref context_die;
8117 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
8119 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8120 be incomplete and such types are not marked. */
8121 add_abstract_origin_attribute (type_die, type);
8124 /* Generate a DIE to represent an inlined instance of a structure type. */
8127 gen_inlined_structure_type_die (type, context_die)
8129 register dw_die_ref context_die;
8131 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
8133 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8134 be incomplete and such types are not marked. */
8135 add_abstract_origin_attribute (type_die, type);
8138 /* Generate a DIE to represent an inlined instance of a union type. */
8141 gen_inlined_union_type_die (type, context_die)
8143 register dw_die_ref context_die;
8145 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
8147 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8148 be incomplete and such types are not marked. */
8149 add_abstract_origin_attribute (type_die, type);
8152 /* Generate a DIE to represent an enumeration type. Note that these DIEs
8153 include all of the information about the enumeration values also. Each
8154 enumerated type name/value is listed as a child of the enumerated type
8158 gen_enumeration_type_die (type, context_die)
8160 register dw_die_ref context_die;
8162 register dw_die_ref type_die = lookup_type_die (type);
8164 if (type_die == NULL)
8166 type_die = new_die (DW_TAG_enumeration_type,
8167 scope_die_for (type, context_die));
8168 equate_type_number_to_die (type, type_die);
8169 add_name_attribute (type_die, type_tag (type));
8171 else if (! TYPE_SIZE (type))
8174 remove_AT (type_die, DW_AT_declaration);
8176 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
8177 given enum type is incomplete, do not generate the DW_AT_byte_size
8178 attribute or the DW_AT_element_list attribute. */
8179 if (TYPE_SIZE (type))
8183 TREE_ASM_WRITTEN (type) = 1;
8184 add_byte_size_attribute (type_die, type);
8185 if (TYPE_STUB_DECL (type) != NULL_TREE)
8186 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8188 /* If the first reference to this type was as the return type of an
8189 inline function, then it may not have a parent. Fix this now. */
8190 if (type_die->die_parent == NULL)
8191 add_child_die (scope_die_for (type, context_die), type_die);
8193 for (link = TYPE_FIELDS (type);
8194 link != NULL; link = TREE_CHAIN (link))
8196 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
8198 add_name_attribute (enum_die,
8199 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
8201 if (host_integerp (TREE_VALUE (link), 0))
8203 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
8204 add_AT_int (enum_die, DW_AT_const_value,
8205 tree_low_cst (TREE_VALUE (link), 0));
8207 add_AT_unsigned (enum_die, DW_AT_const_value,
8208 tree_low_cst (TREE_VALUE (link), 0));
8213 add_AT_flag (type_die, DW_AT_declaration, 1);
8217 /* Generate a DIE to represent either a real live formal parameter decl or to
8218 represent just the type of some formal parameter position in some function
8221 Note that this routine is a bit unusual because its argument may be a
8222 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
8223 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
8224 node. If it's the former then this function is being called to output a
8225 DIE to represent a formal parameter object (or some inlining thereof). If
8226 it's the latter, then this function is only being called to output a
8227 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
8228 argument type of some subprogram type. */
8231 gen_formal_parameter_die (node, context_die)
8233 register dw_die_ref context_die;
8235 register dw_die_ref parm_die
8236 = new_die (DW_TAG_formal_parameter, context_die);
8237 register tree origin;
8239 switch (TREE_CODE_CLASS (TREE_CODE (node)))
8242 origin = decl_ultimate_origin (node);
8244 add_abstract_origin_attribute (parm_die, origin);
8247 add_name_and_src_coords_attributes (parm_die, node);
8248 add_type_attribute (parm_die, TREE_TYPE (node),
8249 TREE_READONLY (node),
8250 TREE_THIS_VOLATILE (node),
8252 if (DECL_ARTIFICIAL (node))
8253 add_AT_flag (parm_die, DW_AT_artificial, 1);
8256 equate_decl_number_to_die (node, parm_die);
8257 if (! DECL_ABSTRACT (node))
8258 add_location_or_const_value_attribute (parm_die, node);
8263 /* We were called with some kind of a ..._TYPE node. */
8264 add_type_attribute (parm_die, node, 0, 0, context_die);
8274 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
8275 at the end of an (ANSI prototyped) formal parameters list. */
8278 gen_unspecified_parameters_die (decl_or_type, context_die)
8279 register tree decl_or_type ATTRIBUTE_UNUSED;
8280 register dw_die_ref context_die;
8282 new_die (DW_TAG_unspecified_parameters, context_die);
8285 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
8286 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
8287 parameters as specified in some function type specification (except for
8288 those which appear as part of a function *definition*). */
8291 gen_formal_types_die (function_or_method_type, context_die)
8292 register tree function_or_method_type;
8293 register dw_die_ref context_die;
8296 register tree formal_type = NULL;
8297 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
8300 /* In the case where we are generating a formal types list for a C++
8301 non-static member function type, skip over the first thing on the
8302 TYPE_ARG_TYPES list because it only represents the type of the hidden
8303 `this pointer'. The debugger should be able to figure out (without
8304 being explicitly told) that this non-static member function type takes a
8305 `this pointer' and should be able to figure what the type of that hidden
8306 parameter is from the DW_AT_member attribute of the parent
8307 DW_TAG_subroutine_type DIE. */
8308 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
8309 first_parm_type = TREE_CHAIN (first_parm_type);
8312 /* Make our first pass over the list of formal parameter types and output a
8313 DW_TAG_formal_parameter DIE for each one. */
8314 for (link = first_parm_type; link; link = TREE_CHAIN (link))
8316 register dw_die_ref parm_die;
8318 formal_type = TREE_VALUE (link);
8319 if (formal_type == void_type_node)
8322 /* Output a (nameless) DIE to represent the formal parameter itself. */
8323 parm_die = gen_formal_parameter_die (formal_type, context_die);
8324 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8325 && link == first_parm_type)
8326 add_AT_flag (parm_die, DW_AT_artificial, 1);
8329 /* If this function type has an ellipsis, add a
8330 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8331 if (formal_type != void_type_node)
8332 gen_unspecified_parameters_die (function_or_method_type, context_die);
8334 /* Make our second (and final) pass over the list of formal parameter types
8335 and output DIEs to represent those types (as necessary). */
8336 for (link = TYPE_ARG_TYPES (function_or_method_type);
8338 link = TREE_CHAIN (link))
8340 formal_type = TREE_VALUE (link);
8341 if (formal_type == void_type_node)
8344 gen_type_die (formal_type, context_die);
8348 /* We want to generate the DIE for TYPE so that we can generate the
8349 die for MEMBER, which has been defined; we will need to refer back
8350 to the member declaration nested within TYPE. If we're trying to
8351 generate minimal debug info for TYPE, processing TYPE won't do the
8352 trick; we need to attach the member declaration by hand. */
8355 gen_type_die_for_member (type, member, context_die)
8357 dw_die_ref context_die;
8359 gen_type_die (type, context_die);
8361 /* If we're trying to avoid duplicate debug info, we may not have
8362 emitted the member decl for this function. Emit it now. */
8363 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
8364 && ! lookup_decl_die (member))
8366 if (decl_ultimate_origin (member))
8369 push_decl_scope (type);
8370 if (TREE_CODE (member) == FUNCTION_DECL)
8371 gen_subprogram_die (member, lookup_type_die (type));
8373 gen_variable_die (member, lookup_type_die (type));
8378 /* Generate the DWARF2 info for the "abstract" instance
8379 of a function which we may later generate inlined and/or
8380 out-of-line instances of. */
8383 gen_abstract_function (decl)
8386 register dw_die_ref old_die = lookup_decl_die (decl);
8389 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
8390 /* We've already generated the abstract instance. */
8393 save_fn = current_function_decl;
8394 current_function_decl = decl;
8396 set_decl_abstract_flags (decl, 1);
8397 dwarf2out_decl (decl);
8398 set_decl_abstract_flags (decl, 0);
8400 current_function_decl = save_fn;
8403 /* Generate a DIE to represent a declared function (either file-scope or
8407 gen_subprogram_die (decl, context_die)
8409 register dw_die_ref context_die;
8411 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
8412 register tree origin = decl_ultimate_origin (decl);
8413 register dw_die_ref subr_die;
8414 register rtx fp_reg;
8415 register tree fn_arg_types;
8416 register tree outer_scope;
8417 register dw_die_ref old_die = lookup_decl_die (decl);
8418 register int declaration = (current_function_decl != decl
8419 || class_scope_p (context_die));
8421 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
8422 be true, if we started to generate the abstract instance of an inline,
8423 decided to output its containing class, and proceeded to emit the
8424 declaration of the inline from the member list for the class. In that
8425 case, `declaration' takes priority; we'll get back to the abstract
8426 instance when we're done with the class. */
8428 /* The class-scope declaration DIE must be the primary DIE. */
8429 if (origin && declaration && class_scope_p (context_die))
8438 if (declaration && ! local_scope_p (context_die))
8441 /* Fixup die_parent for the abstract instance of a nested
8443 if (old_die && old_die->die_parent == NULL)
8444 add_child_die (context_die, old_die);
8446 subr_die = new_die (DW_TAG_subprogram, context_die);
8447 add_abstract_origin_attribute (subr_die, origin);
8449 else if (old_die && DECL_ABSTRACT (decl)
8450 && get_AT_unsigned (old_die, DW_AT_inline))
8452 /* This must be a redefinition of an extern inline function.
8453 We can just reuse the old die here. */
8456 /* Clear out the inlined attribute and parm types. */
8457 remove_AT (subr_die, DW_AT_inline);
8458 remove_children (subr_die);
8462 register unsigned file_index
8463 = lookup_filename (DECL_SOURCE_FILE (decl));
8465 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
8467 /* ??? This can happen if there is a bug in the program, for
8468 instance, if it has duplicate function definitions. Ideally,
8469 we should detect this case and ignore it. For now, if we have
8470 already reported an error, any error at all, then assume that
8471 we got here because of a input error, not a dwarf2 bug. */
8477 /* If the definition comes from the same place as the declaration,
8478 maybe use the old DIE. We always want the DIE for this function
8479 that has the *_pc attributes to be under comp_unit_die so the
8480 debugger can find it. For inlines, that is the concrete instance,
8481 so we can use the old DIE here. For non-inline methods, we want a
8482 specification DIE at toplevel, so we need a new DIE. For local
8483 class methods, this doesn't apply; we just use the old DIE. */
8484 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
8485 || context_die == NULL)
8486 && (DECL_ARTIFICIAL (decl)
8487 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
8488 && (get_AT_unsigned (old_die, DW_AT_decl_line)
8489 == (unsigned)DECL_SOURCE_LINE (decl)))))
8493 /* Clear out the declaration attribute and the parm types. */
8494 remove_AT (subr_die, DW_AT_declaration);
8495 remove_children (subr_die);
8499 subr_die = new_die (DW_TAG_subprogram, context_die);
8500 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
8501 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8502 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
8503 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8504 != (unsigned)DECL_SOURCE_LINE (decl))
8506 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8511 subr_die = new_die (DW_TAG_subprogram, context_die);
8513 if (TREE_PUBLIC (decl))
8514 add_AT_flag (subr_die, DW_AT_external, 1);
8516 add_name_and_src_coords_attributes (subr_die, decl);
8517 if (debug_info_level > DINFO_LEVEL_TERSE)
8519 register tree type = TREE_TYPE (decl);
8521 add_prototyped_attribute (subr_die, type);
8522 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
8525 add_pure_or_virtual_attribute (subr_die, decl);
8526 if (DECL_ARTIFICIAL (decl))
8527 add_AT_flag (subr_die, DW_AT_artificial, 1);
8528 if (TREE_PROTECTED (decl))
8529 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
8530 else if (TREE_PRIVATE (decl))
8531 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
8537 add_AT_flag (subr_die, DW_AT_declaration, 1);
8539 /* The first time we see a member function, it is in the context of
8540 the class to which it belongs. We make sure of this by emitting
8541 the class first. The next time is the definition, which is
8542 handled above. The two may come from the same source text. */
8543 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
8544 equate_decl_number_to_die (decl, subr_die);
8546 else if (DECL_ABSTRACT (decl))
8548 if (DECL_INLINE (decl) && !flag_no_inline)
8550 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
8551 inline functions, but not for extern inline functions.
8552 We can't get this completely correct because information
8553 about whether the function was declared inline is not
8555 if (DECL_DEFER_OUTPUT (decl))
8556 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
8558 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
8561 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
8563 equate_decl_number_to_die (decl, subr_die);
8565 else if (!DECL_EXTERNAL (decl))
8567 if (origin == NULL_TREE)
8568 equate_decl_number_to_die (decl, subr_die);
8570 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
8571 current_funcdef_number);
8572 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
8573 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
8574 current_funcdef_number);
8575 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
8577 add_pubname (decl, subr_die);
8578 add_arange (decl, subr_die);
8580 #ifdef MIPS_DEBUGGING_INFO
8581 /* Add a reference to the FDE for this routine. */
8582 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
8585 /* Define the "frame base" location for this routine. We use the
8586 frame pointer or stack pointer registers, since the RTL for local
8587 variables is relative to one of them. */
8589 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
8590 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
8593 /* ??? This fails for nested inline functions, because context_display
8594 is not part of the state saved/restored for inline functions. */
8595 if (current_function_needs_context)
8596 add_AT_location_description (subr_die, DW_AT_static_link,
8597 lookup_static_chain (decl));
8601 /* Now output descriptions of the arguments for this function. This gets
8602 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8603 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8604 `...' at the end of the formal parameter list. In order to find out if
8605 there was a trailing ellipsis or not, we must instead look at the type
8606 associated with the FUNCTION_DECL. This will be a node of type
8607 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8608 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8609 an ellipsis at the end. */
8611 /* In the case where we are describing a mere function declaration, all we
8612 need to do here (and all we *can* do here) is to describe the *types* of
8613 its formal parameters. */
8614 if (debug_info_level <= DINFO_LEVEL_TERSE)
8616 else if (declaration)
8617 gen_formal_types_die (TREE_TYPE (decl), subr_die);
8620 /* Generate DIEs to represent all known formal parameters */
8621 register tree arg_decls = DECL_ARGUMENTS (decl);
8624 /* When generating DIEs, generate the unspecified_parameters DIE
8625 instead if we come across the arg "__builtin_va_alist" */
8626 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
8627 if (TREE_CODE (parm) == PARM_DECL)
8629 if (DECL_NAME (parm)
8630 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
8631 "__builtin_va_alist"))
8632 gen_unspecified_parameters_die (parm, subr_die);
8634 gen_decl_die (parm, subr_die);
8637 /* Decide whether we need a unspecified_parameters DIE at the end.
8638 There are 2 more cases to do this for: 1) the ansi ... declaration -
8639 this is detectable when the end of the arg list is not a
8640 void_type_node 2) an unprototyped function declaration (not a
8641 definition). This just means that we have no info about the
8642 parameters at all. */
8643 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
8644 if (fn_arg_types != NULL)
8646 /* this is the prototyped case, check for ... */
8647 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
8648 gen_unspecified_parameters_die (decl, subr_die);
8650 else if (DECL_INITIAL (decl) == NULL_TREE)
8651 gen_unspecified_parameters_die (decl, subr_die);
8654 /* Output Dwarf info for all of the stuff within the body of the function
8655 (if it has one - it may be just a declaration). */
8656 outer_scope = DECL_INITIAL (decl);
8658 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8659 node created to represent a function. This outermost BLOCK actually
8660 represents the outermost binding contour for the function, i.e. the
8661 contour in which the function's formal parameters and labels get
8662 declared. Curiously, it appears that the front end doesn't actually
8663 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8664 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8665 list for the function instead.) The BLOCK_VARS list for the
8666 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8667 the function however, and we output DWARF info for those in
8668 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8669 node representing the function's outermost pair of curly braces, and
8670 any blocks used for the base and member initializers of a C++
8671 constructor function. */
8672 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
8674 current_function_has_inlines = 0;
8675 decls_for_scope (outer_scope, subr_die, 0);
8677 #if 0 && defined (MIPS_DEBUGGING_INFO)
8678 if (current_function_has_inlines)
8680 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
8681 if (! comp_unit_has_inlines)
8683 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
8684 comp_unit_has_inlines = 1;
8691 /* Generate a DIE to represent a declared data object. */
8694 gen_variable_die (decl, context_die)
8696 register dw_die_ref context_die;
8698 register tree origin = decl_ultimate_origin (decl);
8699 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
8701 dw_die_ref old_die = lookup_decl_die (decl);
8702 int declaration = (DECL_EXTERNAL (decl)
8703 || class_scope_p (context_die));
8706 add_abstract_origin_attribute (var_die, origin);
8707 /* Loop unrolling can create multiple blocks that refer to the same
8708 static variable, so we must test for the DW_AT_declaration flag. */
8709 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8710 copy decls and set the DECL_ABSTRACT flag on them instead of
8712 else if (old_die && TREE_STATIC (decl)
8713 && get_AT_flag (old_die, DW_AT_declaration) == 1)
8715 /* This is a definition of a C++ class level static. */
8716 add_AT_die_ref (var_die, DW_AT_specification, old_die);
8717 if (DECL_NAME (decl))
8719 register unsigned file_index
8720 = lookup_filename (DECL_SOURCE_FILE (decl));
8722 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8723 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
8725 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8726 != (unsigned)DECL_SOURCE_LINE (decl))
8728 add_AT_unsigned (var_die, DW_AT_decl_line,
8729 DECL_SOURCE_LINE (decl));
8734 add_name_and_src_coords_attributes (var_die, decl);
8735 add_type_attribute (var_die, TREE_TYPE (decl),
8736 TREE_READONLY (decl),
8737 TREE_THIS_VOLATILE (decl), context_die);
8739 if (TREE_PUBLIC (decl))
8740 add_AT_flag (var_die, DW_AT_external, 1);
8742 if (DECL_ARTIFICIAL (decl))
8743 add_AT_flag (var_die, DW_AT_artificial, 1);
8745 if (TREE_PROTECTED (decl))
8746 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
8748 else if (TREE_PRIVATE (decl))
8749 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
8753 add_AT_flag (var_die, DW_AT_declaration, 1);
8755 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
8756 equate_decl_number_to_die (decl, var_die);
8758 if (! declaration && ! DECL_ABSTRACT (decl))
8760 add_location_or_const_value_attribute (var_die, decl);
8761 add_pubname (decl, var_die);
8765 /* Generate a DIE to represent a label identifier. */
8768 gen_label_die (decl, context_die)
8770 register dw_die_ref context_die;
8772 register tree origin = decl_ultimate_origin (decl);
8773 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
8775 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8776 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
8779 add_abstract_origin_attribute (lbl_die, origin);
8781 add_name_and_src_coords_attributes (lbl_die, decl);
8783 if (DECL_ABSTRACT (decl))
8784 equate_decl_number_to_die (decl, lbl_die);
8787 insn = DECL_RTL (decl);
8789 /* Deleted labels are programmer specified labels which have been
8790 eliminated because of various optimisations. We still emit them
8791 here so that it is possible to put breakpoints on them. */
8792 if (GET_CODE (insn) == CODE_LABEL
8793 || ((GET_CODE (insn) == NOTE
8794 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
8796 /* When optimization is enabled (via -O) some parts of the compiler
8797 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8798 represent source-level labels which were explicitly declared by
8799 the user. This really shouldn't be happening though, so catch
8800 it if it ever does happen. */
8801 if (INSN_DELETED_P (insn))
8804 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
8805 ASM_GENERATE_INTERNAL_LABEL (label, label2,
8806 (unsigned) INSN_UID (insn));
8807 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
8812 /* Generate a DIE for a lexical block. */
8815 gen_lexical_block_die (stmt, context_die, depth)
8817 register dw_die_ref context_die;
8820 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
8821 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8823 if (! BLOCK_ABSTRACT (stmt))
8825 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8826 BLOCK_NUMBER (stmt));
8827 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
8828 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
8829 BLOCK_NUMBER (stmt));
8830 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
8833 decls_for_scope (stmt, stmt_die, depth);
8836 /* Generate a DIE for an inlined subprogram. */
8839 gen_inlined_subroutine_die (stmt, context_die, depth)
8841 register dw_die_ref context_die;
8844 if (! BLOCK_ABSTRACT (stmt))
8846 register dw_die_ref subr_die
8847 = new_die (DW_TAG_inlined_subroutine, context_die);
8848 register tree decl = block_ultimate_origin (stmt);
8849 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8851 /* Emit info for the abstract instance first, if we haven't yet. */
8852 gen_abstract_function (decl);
8854 add_abstract_origin_attribute (subr_die, decl);
8855 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8856 BLOCK_NUMBER (stmt));
8857 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
8858 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
8859 BLOCK_NUMBER (stmt));
8860 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
8861 decls_for_scope (stmt, subr_die, depth);
8862 current_function_has_inlines = 1;
8866 /* Generate a DIE for a field in a record, or structure. */
8869 gen_field_die (decl, context_die)
8871 register dw_die_ref context_die;
8873 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
8875 add_name_and_src_coords_attributes (decl_die, decl);
8876 add_type_attribute (decl_die, member_declared_type (decl),
8877 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
8880 /* If this is a bit field... */
8881 if (DECL_BIT_FIELD_TYPE (decl))
8883 add_byte_size_attribute (decl_die, decl);
8884 add_bit_size_attribute (decl_die, decl);
8885 add_bit_offset_attribute (decl_die, decl);
8888 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
8889 add_data_member_location_attribute (decl_die, decl);
8891 if (DECL_ARTIFICIAL (decl))
8892 add_AT_flag (decl_die, DW_AT_artificial, 1);
8894 if (TREE_PROTECTED (decl))
8895 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
8897 else if (TREE_PRIVATE (decl))
8898 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
8902 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8903 Use modified_type_die instead.
8904 We keep this code here just in case these types of DIEs may be needed to
8905 represent certain things in other languages (e.g. Pascal) someday. */
8907 gen_pointer_type_die (type, context_die)
8909 register dw_die_ref context_die;
8911 register dw_die_ref ptr_die
8912 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
8914 equate_type_number_to_die (type, ptr_die);
8915 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8916 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8919 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8920 Use modified_type_die instead.
8921 We keep this code here just in case these types of DIEs may be needed to
8922 represent certain things in other languages (e.g. Pascal) someday. */
8924 gen_reference_type_die (type, context_die)
8926 register dw_die_ref context_die;
8928 register dw_die_ref ref_die
8929 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
8931 equate_type_number_to_die (type, ref_die);
8932 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
8933 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8937 /* Generate a DIE for a pointer to a member type. */
8939 gen_ptr_to_mbr_type_die (type, context_die)
8941 register dw_die_ref context_die;
8943 register dw_die_ref ptr_die
8944 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8946 equate_type_number_to_die (type, ptr_die);
8947 add_AT_die_ref (ptr_die, DW_AT_containing_type,
8948 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
8949 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8952 /* Generate the DIE for the compilation unit. */
8955 gen_compile_unit_die (filename)
8956 register const char *filename;
8958 register dw_die_ref die;
8960 const char *wd = getpwd ();
8963 die = new_die (DW_TAG_compile_unit, NULL);
8964 add_name_attribute (die, filename);
8966 if (wd != NULL && filename[0] != DIR_SEPARATOR)
8967 add_AT_string (die, DW_AT_comp_dir, wd);
8969 sprintf (producer, "%s %s", language_string, version_string);
8971 #ifdef MIPS_DEBUGGING_INFO
8972 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8973 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8974 not appear in the producer string, the debugger reaches the conclusion
8975 that the object file is stripped and has no debugging information.
8976 To get the MIPS/SGI debugger to believe that there is debugging
8977 information in the object file, we add a -g to the producer string. */
8978 if (debug_info_level > DINFO_LEVEL_TERSE)
8979 strcat (producer, " -g");
8982 add_AT_string (die, DW_AT_producer, producer);
8984 if (strcmp (language_string, "GNU C++") == 0)
8985 language = DW_LANG_C_plus_plus;
8986 else if (strcmp (language_string, "GNU Ada") == 0)
8987 language = DW_LANG_Ada83;
8988 else if (strcmp (language_string, "GNU F77") == 0)
8989 language = DW_LANG_Fortran77;
8990 else if (strcmp (language_string, "GNU Pascal") == 0)
8991 language = DW_LANG_Pascal83;
8992 else if (flag_traditional)
8993 language = DW_LANG_C;
8995 language = DW_LANG_C89;
8997 add_AT_unsigned (die, DW_AT_language, language);
9002 /* Generate a DIE for a string type. */
9005 gen_string_type_die (type, context_die)
9007 register dw_die_ref context_die;
9009 register dw_die_ref type_die
9010 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
9012 equate_type_number_to_die (type, type_die);
9014 /* Fudge the string length attribute for now. */
9016 /* TODO: add string length info.
9017 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
9018 bound_representation (upper_bound, 0, 'u'); */
9021 /* Generate the DIE for a base class. */
9024 gen_inheritance_die (binfo, context_die)
9025 register tree binfo;
9026 register dw_die_ref context_die;
9028 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
9030 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
9031 add_data_member_location_attribute (die, binfo);
9033 if (TREE_VIA_VIRTUAL (binfo))
9034 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9035 if (TREE_VIA_PUBLIC (binfo))
9036 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
9037 else if (TREE_VIA_PROTECTED (binfo))
9038 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
9041 /* Generate a DIE for a class member. */
9044 gen_member_die (type, context_die)
9046 register dw_die_ref context_die;
9048 register tree member;
9051 /* If this is not an incomplete type, output descriptions of each of its
9052 members. Note that as we output the DIEs necessary to represent the
9053 members of this record or union type, we will also be trying to output
9054 DIEs to represent the *types* of those members. However the `type'
9055 function (above) will specifically avoid generating type DIEs for member
9056 types *within* the list of member DIEs for this (containing) type execpt
9057 for those types (of members) which are explicitly marked as also being
9058 members of this (containing) type themselves. The g++ front- end can
9059 force any given type to be treated as a member of some other
9060 (containing) type by setting the TYPE_CONTEXT of the given (member) type
9061 to point to the TREE node representing the appropriate (containing)
9064 /* First output info about the base classes. */
9065 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
9067 register tree bases = TYPE_BINFO_BASETYPES (type);
9068 register int n_bases = TREE_VEC_LENGTH (bases);
9071 for (i = 0; i < n_bases; i++)
9072 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
9075 /* Now output info about the data members and type members. */
9076 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
9078 /* If we thought we were generating minimal debug info for TYPE
9079 and then changed our minds, some of the member declarations
9080 may have already been defined. Don't define them again, but
9081 do put them in the right order. */
9083 child = lookup_decl_die (member);
9085 splice_child_die (context_die, child);
9087 gen_decl_die (member, context_die);
9090 /* Now output info about the function members (if any). */
9091 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
9093 child = lookup_decl_die (member);
9095 splice_child_die (context_die, child);
9097 gen_decl_die (member, context_die);
9101 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
9102 is set, we pretend that the type was never defined, so we only get the
9103 member DIEs needed by later specification DIEs. */
9106 gen_struct_or_union_type_die (type, context_die)
9108 register dw_die_ref context_die;
9110 register dw_die_ref type_die = lookup_type_die (type);
9111 register dw_die_ref scope_die = 0;
9112 register int nested = 0;
9113 int complete = (TYPE_SIZE (type)
9114 && (! TYPE_STUB_DECL (type)
9115 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
9117 if (type_die && ! complete)
9120 if (TYPE_CONTEXT (type) != NULL_TREE
9121 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
9124 scope_die = scope_die_for (type, context_die);
9126 if (! type_die || (nested && scope_die == comp_unit_die))
9127 /* First occurrence of type or toplevel definition of nested class. */
9129 register dw_die_ref old_die = type_die;
9131 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
9132 ? DW_TAG_structure_type : DW_TAG_union_type,
9134 equate_type_number_to_die (type, type_die);
9135 add_name_attribute (type_die, type_tag (type));
9137 add_AT_die_ref (type_die, DW_AT_specification, old_die);
9140 remove_AT (type_die, DW_AT_declaration);
9142 /* If this type has been completed, then give it a byte_size attribute and
9143 then give a list of members. */
9146 /* Prevent infinite recursion in cases where the type of some member of
9147 this type is expressed in terms of this type itself. */
9148 TREE_ASM_WRITTEN (type) = 1;
9149 add_byte_size_attribute (type_die, type);
9150 if (TYPE_STUB_DECL (type) != NULL_TREE)
9151 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9153 /* If the first reference to this type was as the return type of an
9154 inline function, then it may not have a parent. Fix this now. */
9155 if (type_die->die_parent == NULL)
9156 add_child_die (scope_die, type_die);
9158 push_decl_scope (type);
9159 gen_member_die (type, type_die);
9162 /* GNU extension: Record what type our vtable lives in. */
9163 if (TYPE_VFIELD (type))
9165 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
9167 gen_type_die (vtype, context_die);
9168 add_AT_die_ref (type_die, DW_AT_containing_type,
9169 lookup_type_die (vtype));
9174 add_AT_flag (type_die, DW_AT_declaration, 1);
9176 /* We don't need to do this for function-local types. */
9177 if (! decl_function_context (TYPE_STUB_DECL (type)))
9178 add_incomplete_type (type);
9182 /* Generate a DIE for a subroutine _type_. */
9185 gen_subroutine_type_die (type, context_die)
9187 register dw_die_ref context_die;
9189 register tree return_type = TREE_TYPE (type);
9190 register dw_die_ref subr_die
9191 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
9193 equate_type_number_to_die (type, subr_die);
9194 add_prototyped_attribute (subr_die, type);
9195 add_type_attribute (subr_die, return_type, 0, 0, context_die);
9196 gen_formal_types_die (type, subr_die);
9199 /* Generate a DIE for a type definition */
9202 gen_typedef_die (decl, context_die)
9204 register dw_die_ref context_die;
9206 register dw_die_ref type_die;
9207 register tree origin;
9209 if (TREE_ASM_WRITTEN (decl))
9211 TREE_ASM_WRITTEN (decl) = 1;
9213 type_die = new_die (DW_TAG_typedef, context_die);
9214 origin = decl_ultimate_origin (decl);
9216 add_abstract_origin_attribute (type_die, origin);
9220 add_name_and_src_coords_attributes (type_die, decl);
9221 if (DECL_ORIGINAL_TYPE (decl))
9223 type = DECL_ORIGINAL_TYPE (decl);
9224 equate_type_number_to_die (TREE_TYPE (decl), type_die);
9227 type = TREE_TYPE (decl);
9228 add_type_attribute (type_die, type, TREE_READONLY (decl),
9229 TREE_THIS_VOLATILE (decl), context_die);
9232 if (DECL_ABSTRACT (decl))
9233 equate_decl_number_to_die (decl, type_die);
9236 /* Generate a type description DIE. */
9239 gen_type_die (type, context_die)
9241 register dw_die_ref context_die;
9245 if (type == NULL_TREE || type == error_mark_node)
9248 /* We are going to output a DIE to represent the unqualified version of
9249 this type (i.e. without any const or volatile qualifiers) so get the
9250 main variant (i.e. the unqualified version) of this type now. */
9251 type = type_main_variant (type);
9253 if (TREE_ASM_WRITTEN (type))
9256 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9257 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
9259 TREE_ASM_WRITTEN (type) = 1;
9260 gen_decl_die (TYPE_NAME (type), context_die);
9264 switch (TREE_CODE (type))
9270 case REFERENCE_TYPE:
9271 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
9272 ensures that the gen_type_die recursion will terminate even if the
9273 type is recursive. Recursive types are possible in Ada. */
9274 /* ??? We could perhaps do this for all types before the switch
9276 TREE_ASM_WRITTEN (type) = 1;
9278 /* For these types, all that is required is that we output a DIE (or a
9279 set of DIEs) to represent the "basis" type. */
9280 gen_type_die (TREE_TYPE (type), context_die);
9284 /* This code is used for C++ pointer-to-data-member types.
9285 Output a description of the relevant class type. */
9286 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
9288 /* Output a description of the type of the object pointed to. */
9289 gen_type_die (TREE_TYPE (type), context_die);
9291 /* Now output a DIE to represent this pointer-to-data-member type
9293 gen_ptr_to_mbr_type_die (type, context_die);
9297 gen_type_die (TYPE_DOMAIN (type), context_die);
9298 gen_set_type_die (type, context_die);
9302 gen_type_die (TREE_TYPE (type), context_die);
9303 abort (); /* No way to represent these in Dwarf yet! */
9307 /* Force out return type (in case it wasn't forced out already). */
9308 gen_type_die (TREE_TYPE (type), context_die);
9309 gen_subroutine_type_die (type, context_die);
9313 /* Force out return type (in case it wasn't forced out already). */
9314 gen_type_die (TREE_TYPE (type), context_die);
9315 gen_subroutine_type_die (type, context_die);
9319 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
9321 gen_type_die (TREE_TYPE (type), context_die);
9322 gen_string_type_die (type, context_die);
9325 gen_array_type_die (type, context_die);
9329 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
9335 case QUAL_UNION_TYPE:
9336 /* If this is a nested type whose containing class hasn't been
9337 written out yet, writing it out will cover this one, too.
9338 This does not apply to instantiations of member class templates;
9339 they need to be added to the containing class as they are
9340 generated. FIXME: This hurts the idea of combining type decls
9341 from multiple TUs, since we can't predict what set of template
9342 instantiations we'll get. */
9343 if (TYPE_CONTEXT (type)
9344 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9345 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9347 gen_type_die (TYPE_CONTEXT (type), context_die);
9349 if (TREE_ASM_WRITTEN (type))
9352 /* If that failed, attach ourselves to the stub. */
9353 push_decl_scope (TYPE_CONTEXT (type));
9354 context_die = lookup_type_die (TYPE_CONTEXT (type));
9360 if (TREE_CODE (type) == ENUMERAL_TYPE)
9361 gen_enumeration_type_die (type, context_die);
9363 gen_struct_or_union_type_die (type, context_die);
9368 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9369 it up if it is ever completed. gen_*_type_die will set it for us
9370 when appropriate. */
9379 /* No DIEs needed for fundamental types. */
9383 /* No Dwarf representation currently defined. */
9390 TREE_ASM_WRITTEN (type) = 1;
9393 /* Generate a DIE for a tagged type instantiation. */
9396 gen_tagged_type_instantiation_die (type, context_die)
9398 register dw_die_ref context_die;
9400 if (type == NULL_TREE || type == error_mark_node)
9403 /* We are going to output a DIE to represent the unqualified version of
9404 this type (i.e. without any const or volatile qualifiers) so make sure
9405 that we have the main variant (i.e. the unqualified version) of this
9407 if (type != type_main_variant (type))
9410 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
9411 an instance of an unresolved type. */
9413 switch (TREE_CODE (type))
9419 gen_inlined_enumeration_type_die (type, context_die);
9423 gen_inlined_structure_type_die (type, context_die);
9427 case QUAL_UNION_TYPE:
9428 gen_inlined_union_type_die (type, context_die);
9436 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
9437 things which are local to the given block. */
9440 gen_block_die (stmt, context_die, depth)
9442 register dw_die_ref context_die;
9445 register int must_output_die = 0;
9446 register tree origin;
9448 register enum tree_code origin_code;
9450 /* Ignore blocks never really used to make RTL. */
9452 if (stmt == NULL_TREE || !TREE_USED (stmt)
9453 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
9456 /* Determine the "ultimate origin" of this block. This block may be an
9457 inlined instance of an inlined instance of inline function, so we have
9458 to trace all of the way back through the origin chain to find out what
9459 sort of node actually served as the original seed for the creation of
9460 the current block. */
9461 origin = block_ultimate_origin (stmt);
9462 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
9464 /* Determine if we need to output any Dwarf DIEs at all to represent this
9466 if (origin_code == FUNCTION_DECL)
9467 /* The outer scopes for inlinings *must* always be represented. We
9468 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9469 must_output_die = 1;
9472 /* In the case where the current block represents an inlining of the
9473 "body block" of an inline function, we must *NOT* output any DIE for
9474 this block because we have already output a DIE to represent the
9475 whole inlined function scope and the "body block" of any function
9476 doesn't really represent a different scope according to ANSI C
9477 rules. So we check here to make sure that this block does not
9478 represent a "body block inlining" before trying to set the
9479 `must_output_die' flag. */
9480 if (! is_body_block (origin ? origin : stmt))
9482 /* Determine if this block directly contains any "significant"
9483 local declarations which we will need to output DIEs for. */
9484 if (debug_info_level > DINFO_LEVEL_TERSE)
9485 /* We are not in terse mode so *any* local declaration counts
9486 as being a "significant" one. */
9487 must_output_die = (BLOCK_VARS (stmt) != NULL);
9489 /* We are in terse mode, so only local (nested) function
9490 definitions count as "significant" local declarations. */
9491 for (decl = BLOCK_VARS (stmt);
9492 decl != NULL; decl = TREE_CHAIN (decl))
9493 if (TREE_CODE (decl) == FUNCTION_DECL
9494 && DECL_INITIAL (decl))
9496 must_output_die = 1;
9502 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9503 DIE for any block which contains no significant local declarations at
9504 all. Rather, in such cases we just call `decls_for_scope' so that any
9505 needed Dwarf info for any sub-blocks will get properly generated. Note
9506 that in terse mode, our definition of what constitutes a "significant"
9507 local declaration gets restricted to include only inlined function
9508 instances and local (nested) function definitions. */
9509 if (must_output_die)
9511 if (origin_code == FUNCTION_DECL)
9512 gen_inlined_subroutine_die (stmt, context_die, depth);
9514 gen_lexical_block_die (stmt, context_die, depth);
9517 decls_for_scope (stmt, context_die, depth);
9520 /* Generate all of the decls declared within a given scope and (recursively)
9521 all of its sub-blocks. */
9524 decls_for_scope (stmt, context_die, depth)
9526 register dw_die_ref context_die;
9530 register tree subblocks;
9532 /* Ignore blocks never really used to make RTL. */
9533 if (stmt == NULL_TREE || ! TREE_USED (stmt))
9536 /* Output the DIEs to represent all of the data objects and typedefs
9537 declared directly within this block but not within any nested
9538 sub-blocks. Also, nested function and tag DIEs have been
9539 generated with a parent of NULL; fix that up now. */
9540 for (decl = BLOCK_VARS (stmt);
9541 decl != NULL; decl = TREE_CHAIN (decl))
9543 register dw_die_ref die;
9545 if (TREE_CODE (decl) == FUNCTION_DECL)
9546 die = lookup_decl_die (decl);
9547 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9548 die = lookup_type_die (TREE_TYPE (decl));
9552 if (die != NULL && die->die_parent == NULL)
9553 add_child_die (context_die, die);
9555 gen_decl_die (decl, context_die);
9558 /* Output the DIEs to represent all sub-blocks (and the items declared
9559 therein) of this block. */
9560 for (subblocks = BLOCK_SUBBLOCKS (stmt);
9562 subblocks = BLOCK_CHAIN (subblocks))
9563 gen_block_die (subblocks, context_die, depth + 1);
9566 /* Is this a typedef we can avoid emitting? */
9569 is_redundant_typedef (decl)
9572 if (TYPE_DECL_IS_STUB (decl))
9575 if (DECL_ARTIFICIAL (decl)
9576 && DECL_CONTEXT (decl)
9577 && is_tagged_type (DECL_CONTEXT (decl))
9578 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
9579 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
9580 /* Also ignore the artificial member typedef for the class name. */
9586 /* Generate Dwarf debug information for a decl described by DECL. */
9589 gen_decl_die (decl, context_die)
9591 register dw_die_ref context_die;
9593 register tree origin;
9595 if (TREE_CODE (decl) == ERROR_MARK)
9598 /* If this ..._DECL node is marked to be ignored, then ignore it. */
9599 if (DECL_IGNORED_P (decl))
9602 switch (TREE_CODE (decl))
9605 /* The individual enumerators of an enum type get output when we output
9606 the Dwarf representation of the relevant enum type itself. */
9610 /* Don't output any DIEs to represent mere function declarations,
9611 unless they are class members or explicit block externs. */
9612 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
9613 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
9616 /* If we're emitting an out-of-line copy of an inline function,
9617 emit info for the abstract instance and set up to refer to it. */
9618 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
9619 && ! class_scope_p (context_die))
9621 gen_abstract_function (decl);
9622 set_decl_origin_self (decl);
9625 if (debug_info_level > DINFO_LEVEL_TERSE)
9627 /* Before we describe the FUNCTION_DECL itself, make sure that we
9628 have described its return type. */
9629 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
9631 /* And its virtual context. */
9632 if (DECL_VINDEX (decl) != NULL_TREE)
9633 gen_type_die (DECL_CONTEXT (decl), context_die);
9635 /* And its containing type. */
9636 origin = decl_class_context (decl);
9637 if (origin != NULL_TREE)
9638 gen_type_die_for_member (origin, decl, context_die);
9641 /* Now output a DIE to represent the function itself. */
9642 gen_subprogram_die (decl, context_die);
9646 /* If we are in terse mode, don't generate any DIEs to represent any
9648 if (debug_info_level <= DINFO_LEVEL_TERSE)
9651 /* In the special case of a TYPE_DECL node representing the
9652 declaration of some type tag, if the given TYPE_DECL is marked as
9653 having been instantiated from some other (original) TYPE_DECL node
9654 (e.g. one which was generated within the original definition of an
9655 inline function) we have to generate a special (abbreviated)
9656 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9658 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
9660 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
9664 if (is_redundant_typedef (decl))
9665 gen_type_die (TREE_TYPE (decl), context_die);
9667 /* Output a DIE to represent the typedef itself. */
9668 gen_typedef_die (decl, context_die);
9672 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9673 gen_label_die (decl, context_die);
9677 /* If we are in terse mode, don't generate any DIEs to represent any
9678 variable declarations or definitions. */
9679 if (debug_info_level <= DINFO_LEVEL_TERSE)
9682 /* Output any DIEs that are needed to specify the type of this data
9684 gen_type_die (TREE_TYPE (decl), context_die);
9686 /* And its containing type. */
9687 origin = decl_class_context (decl);
9688 if (origin != NULL_TREE)
9689 gen_type_die_for_member (origin, decl, context_die);
9691 /* Now output the DIE to represent the data object itself. This gets
9692 complicated because of the possibility that the VAR_DECL really
9693 represents an inlined instance of a formal parameter for an inline
9695 origin = decl_ultimate_origin (decl);
9696 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
9697 gen_formal_parameter_die (decl, context_die);
9699 gen_variable_die (decl, context_die);
9703 /* Ignore the nameless fields that are used to skip bits, but
9704 handle C++ anonymous unions. */
9705 if (DECL_NAME (decl) != NULL_TREE
9706 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
9708 gen_type_die (member_declared_type (decl), context_die);
9709 gen_field_die (decl, context_die);
9714 gen_type_die (TREE_TYPE (decl), context_die);
9715 gen_formal_parameter_die (decl, context_die);
9718 case NAMESPACE_DECL:
9719 /* Ignore for now. */
9727 /* Add Ada "use" clause information for SGI Workshop debugger. */
9730 dwarf2out_add_library_unit_info (filename, context_list)
9731 const char *filename;
9732 const char *context_list;
9734 unsigned int file_index;
9736 if (filename != NULL)
9738 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
9739 tree context_list_decl
9740 = build_decl (LABEL_DECL, get_identifier (context_list),
9743 TREE_PUBLIC (context_list_decl) = TRUE;
9744 add_name_attribute (unit_die, context_list);
9745 file_index = lookup_filename (filename);
9746 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
9747 add_pubname (context_list_decl, unit_die);
9751 /* Write the debugging output for DECL. */
9754 dwarf2out_decl (decl)
9757 register dw_die_ref context_die = comp_unit_die;
9759 if (TREE_CODE (decl) == ERROR_MARK)
9762 /* If this ..._DECL node is marked to be ignored, then ignore it. */
9763 if (DECL_IGNORED_P (decl))
9766 switch (TREE_CODE (decl))
9769 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9770 builtin function. Explicit programmer-supplied declarations of
9771 these same functions should NOT be ignored however. */
9772 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
9775 /* What we would really like to do here is to filter out all mere
9776 file-scope declarations of file-scope functions which are never
9777 referenced later within this translation unit (and keep all of ones
9778 that *are* referenced later on) but we aren't clairvoyant, so we have
9779 no idea which functions will be referenced in the future (i.e. later
9780 on within the current translation unit). So here we just ignore all
9781 file-scope function declarations which are not also definitions. If
9782 and when the debugger needs to know something about these functions,
9783 it will have to hunt around and find the DWARF information associated
9784 with the definition of the function. Note that we can't just check
9785 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9786 definitions and which ones represent mere declarations. We have to
9787 check `DECL_INITIAL' instead. That's because the C front-end
9788 supports some weird semantics for "extern inline" function
9789 definitions. These can get inlined within the current translation
9790 unit (an thus, we need to generate DWARF info for their abstract
9791 instances so that the DWARF info for the concrete inlined instances
9792 can have something to refer to) but the compiler never generates any
9793 out-of-lines instances of such things (despite the fact that they
9794 *are* definitions). The important point is that the C front-end
9795 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9796 to generate DWARF for them anyway. Note that the C++ front-end also
9797 plays some similar games for inline function definitions appearing
9798 within include files which also contain
9799 `#pragma interface' pragmas. */
9800 if (DECL_INITIAL (decl) == NULL_TREE)
9803 /* If we're a nested function, initially use a parent of NULL; if we're
9804 a plain function, this will be fixed up in decls_for_scope. If
9805 we're a method, it will be ignored, since we already have a DIE. */
9806 if (decl_function_context (decl))
9812 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9813 declaration and if the declaration was never even referenced from
9814 within this entire compilation unit. We suppress these DIEs in
9815 order to save space in the .debug section (by eliminating entries
9816 which are probably useless). Note that we must not suppress
9817 block-local extern declarations (whether used or not) because that
9818 would screw-up the debugger's name lookup mechanism and cause it to
9819 miss things which really ought to be in scope at a given point. */
9820 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
9823 /* If we are in terse mode, don't generate any DIEs to represent any
9824 variable declarations or definitions. */
9825 if (debug_info_level <= DINFO_LEVEL_TERSE)
9830 /* Don't emit stubs for types unless they are needed by other DIEs. */
9831 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
9834 /* Don't bother trying to generate any DIEs to represent any of the
9835 normal built-in types for the language we are compiling. */
9836 if (DECL_SOURCE_LINE (decl) == 0)
9838 /* OK, we need to generate one for `bool' so GDB knows what type
9839 comparisons have. */
9840 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
9841 == DW_LANG_C_plus_plus)
9842 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
9843 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
9848 /* If we are in terse mode, don't generate any DIEs for types. */
9849 if (debug_info_level <= DINFO_LEVEL_TERSE)
9852 /* If we're a function-scope tag, initially use a parent of NULL;
9853 this will be fixed up in decls_for_scope. */
9854 if (decl_function_context (decl))
9863 gen_decl_die (decl, context_die);
9866 /* Output a marker (i.e. a label) for the beginning of the generated code for
9870 dwarf2out_begin_block (blocknum)
9871 register unsigned blocknum;
9873 function_section (current_function_decl);
9874 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
9877 /* Output a marker (i.e. a label) for the end of the generated code for a
9881 dwarf2out_end_block (blocknum)
9882 register unsigned blocknum;
9884 function_section (current_function_decl);
9885 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
9888 /* Returns nonzero if it is appropriate not to emit any debugging
9889 information for BLOCK, because it doesn't contain any instructions.
9891 Don't allow this for blocks with nested functions or local classes
9892 as we would end up with orphans, and in the presence of scheduling
9893 we may end up calling them anyway. */
9896 dwarf2out_ignore_block (block)
9900 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
9901 if (TREE_CODE (decl) == FUNCTION_DECL
9902 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
9907 /* Output a marker (i.e. a label) at a point in the assembly code which
9908 corresponds to a given source level label. */
9911 dwarf2out_label (insn)
9914 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9916 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9918 function_section (current_function_decl);
9919 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
9920 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
9921 (unsigned) INSN_UID (insn));
9925 /* Lookup a filename (in the list of filenames that we know about here in
9926 dwarf2out.c) and return its "index". The index of each (known) filename is
9927 just a unique number which is associated with only that one filename.
9928 We need such numbers for the sake of generating labels
9929 (in the .debug_sfnames section) and references to those
9930 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9931 If the filename given as an argument is not found in our current list,
9932 add it to the list and assign it the next available unique index number.
9933 In order to speed up searches, we remember the index of the filename
9934 was looked up last. This handles the majority of all searches. */
9937 lookup_filename (file_name)
9938 const char *file_name;
9940 static unsigned last_file_lookup_index = 0;
9941 register unsigned i;
9943 /* Check to see if the file name that was searched on the previous call
9944 matches this file name. If so, return the index. */
9945 if (last_file_lookup_index != 0)
9946 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
9947 return last_file_lookup_index;
9949 /* Didn't match the previous lookup, search the table */
9950 for (i = 1; i < file_table_in_use; ++i)
9951 if (strcmp (file_name, file_table[i]) == 0)
9953 last_file_lookup_index = i;
9957 /* Prepare to add a new table entry by making sure there is enough space in
9958 the table to do so. If not, expand the current table. */
9959 if (file_table_in_use == file_table_allocated)
9961 file_table_allocated += FILE_TABLE_INCREMENT;
9963 = (char **) xrealloc (file_table,
9964 file_table_allocated * sizeof (char *));
9967 /* Add the new entry to the end of the filename table. */
9968 file_table[file_table_in_use] = xstrdup (file_name);
9969 last_file_lookup_index = file_table_in_use++;
9971 return last_file_lookup_index;
9974 /* Output a label to mark the beginning of a source code line entry
9975 and record information relating to this source line, in
9976 'line_info_table' for later output of the .debug_line section. */
9979 dwarf2out_line (filename, line)
9980 register const char *filename;
9981 register unsigned line;
9983 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9985 function_section (current_function_decl);
9987 if (DWARF2_ASM_LINE_DEBUG_INFO)
9989 static const char *lastfile;
9991 /* Emit the .file and .loc directives understood by GNU as. */
9992 if (lastfile == 0 || strcmp (filename, lastfile))
9995 ggc_add_string_root ((char **) &lastfile, 1);
9997 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
9998 lastfile = filename;
10001 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
10003 /* Indicate that line number info exists. */
10004 ++line_info_table_in_use;
10006 /* Indicate that multiple line number tables exist. */
10007 if (DECL_SECTION_NAME (current_function_decl))
10008 ++separate_line_info_table_in_use;
10010 else if (DECL_SECTION_NAME (current_function_decl))
10012 register dw_separate_line_info_ref line_info;
10013 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
10014 separate_line_info_table_in_use);
10015 if (flag_debug_asm)
10016 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
10017 fputc ('\n', asm_out_file);
10019 /* expand the line info table if necessary */
10020 if (separate_line_info_table_in_use
10021 == separate_line_info_table_allocated)
10023 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10024 separate_line_info_table
10025 = (dw_separate_line_info_ref)
10026 xrealloc (separate_line_info_table,
10027 separate_line_info_table_allocated
10028 * sizeof (dw_separate_line_info_entry));
10031 /* Add the new entry at the end of the line_info_table. */
10033 = &separate_line_info_table[separate_line_info_table_in_use++];
10034 line_info->dw_file_num = lookup_filename (filename);
10035 line_info->dw_line_num = line;
10036 line_info->function = current_funcdef_number;
10040 register dw_line_info_ref line_info;
10042 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
10043 line_info_table_in_use);
10044 if (flag_debug_asm)
10045 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
10046 fputc ('\n', asm_out_file);
10048 /* Expand the line info table if necessary. */
10049 if (line_info_table_in_use == line_info_table_allocated)
10051 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10053 = (dw_line_info_ref)
10054 xrealloc (line_info_table,
10055 (line_info_table_allocated
10056 * sizeof (dw_line_info_entry)));
10059 /* Add the new entry at the end of the line_info_table. */
10060 line_info = &line_info_table[line_info_table_in_use++];
10061 line_info->dw_file_num = lookup_filename (filename);
10062 line_info->dw_line_num = line;
10067 /* Record the beginning of a new source file, for later output
10068 of the .debug_macinfo section. At present, unimplemented. */
10071 dwarf2out_start_source_file (filename)
10072 register const char *filename ATTRIBUTE_UNUSED;
10076 /* Record the end of a source file, for later output
10077 of the .debug_macinfo section. At present, unimplemented. */
10080 dwarf2out_end_source_file ()
10084 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10085 the tail part of the directive line, i.e. the part which is past the
10086 initial whitespace, #, whitespace, directive-name, whitespace part. */
10089 dwarf2out_define (lineno, buffer)
10090 register unsigned lineno ATTRIBUTE_UNUSED;
10091 register const char *buffer ATTRIBUTE_UNUSED;
10093 static int initialized = 0;
10096 dwarf2out_start_source_file (primary_filename);
10101 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10102 the tail part of the directive line, i.e. the part which is past the
10103 initial whitespace, #, whitespace, directive-name, whitespace part. */
10106 dwarf2out_undef (lineno, buffer)
10107 register unsigned lineno ATTRIBUTE_UNUSED;
10108 register const char *buffer ATTRIBUTE_UNUSED;
10112 /* Set up for Dwarf output at the start of compilation. */
10115 dwarf2out_init (asm_out_file, main_input_filename)
10116 register FILE *asm_out_file;
10117 register const char *main_input_filename;
10119 /* Remember the name of the primary input file. */
10120 primary_filename = main_input_filename;
10122 /* Allocate the initial hunk of the file_table. */
10123 file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
10124 file_table_allocated = FILE_TABLE_INCREMENT;
10126 /* Skip the first entry - file numbers begin at 1. */
10127 file_table_in_use = 1;
10129 /* Allocate the initial hunk of the decl_die_table. */
10131 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
10132 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
10133 decl_die_table_in_use = 0;
10135 /* Allocate the initial hunk of the decl_scope_table. */
10137 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
10138 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
10139 decl_scope_depth = 0;
10141 /* Allocate the initial hunk of the abbrev_die_table. */
10143 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
10144 sizeof (dw_die_ref));
10145 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
10146 /* Zero-th entry is allocated, but unused */
10147 abbrev_die_table_in_use = 1;
10149 /* Allocate the initial hunk of the line_info_table. */
10151 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
10152 sizeof (dw_line_info_entry));
10153 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
10154 /* Zero-th entry is allocated, but unused */
10155 line_info_table_in_use = 1;
10157 /* Generate the initial DIE for the .debug section. Note that the (string)
10158 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
10159 will (typically) be a relative pathname and that this pathname should be
10160 taken as being relative to the directory from which the compiler was
10161 invoked when the given (base) source file was compiled. */
10162 comp_unit_die = gen_compile_unit_die (main_input_filename);
10166 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
10167 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
10170 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
10171 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
10172 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
10173 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
10175 strcpy (text_section_label, stripattributes (TEXT_SECTION));
10176 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
10177 DEBUG_INFO_SECTION_LABEL, 0);
10178 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
10179 DEBUG_LINE_SECTION_LABEL, 0);
10181 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
10182 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
10183 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
10185 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
10186 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
10188 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
10189 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
10190 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
10191 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
10194 /* Output stuff that dwarf requires at the end of every file,
10195 and generate the DWARF-2 debugging info. */
10198 dwarf2out_finish ()
10200 limbo_die_node *node, *next_node;
10203 /* Traverse the limbo die list, and add parent/child links. The only
10204 dies without parents that should be here are concrete instances of
10205 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
10206 For concrete instances, we can get the parent die from the abstract
10208 for (node = limbo_die_list; node; node = next_node)
10210 next_node = node->next;
10213 if (die->die_parent == NULL)
10215 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
10217 add_child_die (origin->die_parent, die);
10218 else if (die == comp_unit_die)
10225 limbo_die_list = NULL;
10227 /* Walk through the list of incomplete types again, trying once more to
10228 emit full debugging info for them. */
10229 retry_incomplete_types ();
10231 /* Traverse the DIE's, reverse their lists of attributes and children,
10232 and add add sibling attributes to those DIE's that have children. */
10233 add_sibling_attributes (comp_unit_die);
10235 /* Output a terminator label for the .text section. */
10236 fputc ('\n', asm_out_file);
10237 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
10238 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
10241 /* Output a terminator label for the .data section. */
10242 fputc ('\n', asm_out_file);
10243 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
10244 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
10246 /* Output a terminator label for the .bss section. */
10247 fputc ('\n', asm_out_file);
10248 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
10249 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
10252 /* Output the source line correspondence table. */
10253 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
10255 if (! DWARF2_ASM_LINE_DEBUG_INFO)
10257 fputc ('\n', asm_out_file);
10258 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
10259 output_line_info ();
10262 /* We can only use the low/high_pc attributes if all of the code
10264 if (separate_line_info_table_in_use == 0)
10266 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
10267 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
10270 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
10271 debug_line_section_label);
10274 #if 0 /* unimplemented */
10275 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
10276 add_AT_unsigned (die, DW_AT_macro_info, 0);
10279 /* Output the abbreviation table. */
10280 fputc ('\n', asm_out_file);
10281 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
10282 build_abbrev_table (comp_unit_die);
10283 output_abbrev_section ();
10285 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
10286 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
10287 calc_die_sizes (comp_unit_die);
10289 /* Output debugging information. */
10290 fputc ('\n', asm_out_file);
10291 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
10292 output_compilation_unit_header ();
10293 output_die (comp_unit_die);
10295 if (pubname_table_in_use)
10297 /* Output public names table. */
10298 fputc ('\n', asm_out_file);
10299 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
10300 output_pubnames ();
10303 /* We only put functions in the arange table, so don't write it out if
10304 we don't have any. */
10305 if (fde_table_in_use)
10307 /* Output the address range information. */
10308 fputc ('\n', asm_out_file);
10309 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
10313 #endif /* DWARF2_DEBUGGING_INFO */