1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* TODO: Implement .debug_str handling, and share entries somehow.
26 Emit .debug_line header even when there are no functions, since
27 the file numbers are used by .debug_info. Alternately, leave
28 out locations for types and decls.
29 Avoid talking about ctors and op= for PODs.
30 Factor out common prologue sequences into multiple CIEs. */
32 /* The first part of this file deals with the DWARF 2 frame unwind
33 information, which is also used by the GCC efficient exception handling
34 mechanism. The second part, controlled only by an #ifdef
35 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
44 #include "hard-reg-set.h"
46 #include "insn-config.h"
52 #include "dwarf2out.h"
59 /* Decide whether we want to emit frame unwind information for the current
65 return (write_symbols == DWARF2_DEBUG
66 #ifdef DWARF2_FRAME_INFO
69 #ifdef DWARF2_UNWIND_INFO
71 || (flag_exceptions && ! exceptions_via_longjmp)
76 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
78 /* How to start an assembler comment. */
79 #ifndef ASM_COMMENT_START
80 #define ASM_COMMENT_START ";#"
83 typedef struct dw_cfi_struct *dw_cfi_ref;
84 typedef struct dw_fde_struct *dw_fde_ref;
85 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
87 /* Call frames are described using a sequence of Call Frame
88 Information instructions. The register number, offset
89 and address fields are provided as possible operands;
90 their use is selected by the opcode field. */
92 typedef union dw_cfi_oprnd_struct
94 unsigned long dw_cfi_reg_num;
95 long int dw_cfi_offset;
96 const char *dw_cfi_addr;
97 struct dw_loc_descr_struct *dw_cfi_loc;
101 typedef struct dw_cfi_struct
103 dw_cfi_ref dw_cfi_next;
104 enum dwarf_call_frame_info dw_cfi_opc;
105 dw_cfi_oprnd dw_cfi_oprnd1;
106 dw_cfi_oprnd dw_cfi_oprnd2;
110 /* This is how we define the location of the CFA. We use to handle it
111 as REG + OFFSET all the time, but now it can be more complex.
112 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
113 Instead of passing around REG and OFFSET, we pass a copy
114 of this structure. */
115 typedef struct cfa_loc
120 int indirect; /* 1 if CFA is accessed via a dereference. */
123 /* All call frame descriptions (FDE's) in the GCC generated DWARF
124 refer to a single Common Information Entry (CIE), defined at
125 the beginning of the .debug_frame section. This used of a single
126 CIE obviates the need to keep track of multiple CIE's
127 in the DWARF generation routines below. */
129 typedef struct dw_fde_struct
131 const char *dw_fde_begin;
132 const char *dw_fde_current_label;
133 const char *dw_fde_end;
134 dw_cfi_ref dw_fde_cfi;
139 /* Maximum size (in bytes) of an artificially generated label. */
140 #define MAX_ARTIFICIAL_LABEL_BYTES 30
142 /* The size of the target's pointer type. */
144 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
147 /* The size of addresses as they appear in the Dwarf 2 data.
148 Some architectures use word addresses to refer to code locations,
149 but Dwarf 2 info always uses byte addresses. On such machines,
150 Dwarf 2 addresses need to be larger than the architecture's
152 #ifndef DWARF2_ADDR_SIZE
153 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
156 /* The size in bytes of a DWARF field indicating an offset or length
157 relative to a debug info section, specified to be 4 bytes in the
158 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
161 #ifndef DWARF_OFFSET_SIZE
162 #define DWARF_OFFSET_SIZE 4
165 #define DWARF_VERSION 2
167 /* Round SIZE up to the nearest BOUNDARY. */
168 #define DWARF_ROUND(SIZE,BOUNDARY) \
169 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
171 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
172 #ifndef DWARF_CIE_DATA_ALIGNMENT
173 #ifdef STACK_GROWS_DOWNWARD
174 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
176 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
178 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
180 /* A pointer to the base of a table that contains frame description
181 information for each routine. */
182 static dw_fde_ref fde_table;
184 /* Number of elements currently allocated for fde_table. */
185 static unsigned fde_table_allocated;
187 /* Number of elements in fde_table currently in use. */
188 static unsigned fde_table_in_use;
190 /* Size (in elements) of increments by which we may expand the
192 #define FDE_TABLE_INCREMENT 256
194 /* A list of call frame insns for the CIE. */
195 static dw_cfi_ref cie_cfi_head;
197 /* The number of the current function definition for which debugging
198 information is being generated. These numbers range from 1 up to the
199 maximum number of function definitions contained within the current
200 compilation unit. These numbers are used to create unique label id's
201 unique to each function definition. */
202 static unsigned current_funcdef_number = 0;
204 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
205 attribute that accelerates the lookup of the FDE associated
206 with the subprogram. This variable holds the table index of the FDE
207 associated with the current function (body) definition. */
208 static unsigned current_funcdef_fde;
210 /* Forward declarations for functions defined in this file. */
212 static char *stripattributes PARAMS ((const char *));
213 static const char *dwarf_cfi_name PARAMS ((unsigned));
214 static dw_cfi_ref new_cfi PARAMS ((void));
215 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
216 static unsigned long size_of_uleb128 PARAMS ((unsigned long));
217 static unsigned long size_of_sleb128 PARAMS ((long));
218 static void output_uleb128 PARAMS ((unsigned long));
219 static void output_sleb128 PARAMS ((long));
220 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
221 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
222 static void lookup_cfa PARAMS ((dw_cfa_location *));
223 static void reg_save PARAMS ((const char *, unsigned,
225 static void initial_return_save PARAMS ((rtx));
226 static long stack_adjust_offset PARAMS ((rtx));
227 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
228 static void output_call_frame_info PARAMS ((int));
229 static void dwarf2out_stack_adjust PARAMS ((rtx));
230 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
232 /* Support for complex CFA locations. */
233 static void output_cfa_loc PARAMS ((dw_cfi_ref));
234 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
235 struct dw_loc_descr_struct *));
236 static struct dw_loc_descr_struct *build_cfa_loc
237 PARAMS ((dw_cfa_location *));
238 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
240 /* Definitions of defaults for assembler-dependent names of various
241 pseudo-ops and section names.
242 Theses may be overridden in the tm.h file (if necessary) for a particular
245 #ifdef OBJECT_FORMAT_ELF
246 #ifndef UNALIGNED_SHORT_ASM_OP
247 #define UNALIGNED_SHORT_ASM_OP "\t.2byte\t"
249 #ifndef UNALIGNED_INT_ASM_OP
250 #define UNALIGNED_INT_ASM_OP "\t.4byte\t"
252 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
253 #define UNALIGNED_DOUBLE_INT_ASM_OP "\t.8byte\t"
255 #endif /* OBJECT_FORMAT_ELF */
258 #define ASM_BYTE_OP "\t.byte\t"
261 /* Data and reference forms for relocatable data. */
262 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
263 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
265 /* Pseudo-op for defining a new section. */
266 #ifndef SECTION_ASM_OP
267 #define SECTION_ASM_OP "\t.section\t"
270 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
271 print the SECTION_ASM_OP and the section name. The default here works for
272 almost all svr4 assemblers, except for the sparc, where the section name
273 must be enclosed in double quotes. (See sparcv4.h). */
274 #ifndef SECTION_FORMAT
275 #ifdef PUSHSECTION_FORMAT
276 #define SECTION_FORMAT PUSHSECTION_FORMAT
278 #define SECTION_FORMAT "%s%s\n"
282 #ifndef FRAME_SECTION
283 #define FRAME_SECTION ".debug_frame"
286 #ifndef FUNC_BEGIN_LABEL
287 #define FUNC_BEGIN_LABEL "LFB"
289 #ifndef FUNC_END_LABEL
290 #define FUNC_END_LABEL "LFE"
292 #define CIE_AFTER_SIZE_LABEL "LSCIE"
293 #define CIE_END_LABEL "LECIE"
294 #define CIE_LENGTH_LABEL "LLCIE"
295 #define FDE_AFTER_SIZE_LABEL "LSFDE"
296 #define FDE_END_LABEL "LEFDE"
297 #define FDE_LENGTH_LABEL "LLFDE"
298 #define DIE_LABEL_PREFIX "DW"
300 /* Definitions of defaults for various types of primitive assembly language
301 output operations. These may be overridden from within the tm.h file,
302 but typically, that is unnecessary. */
304 #ifndef ASM_OUTPUT_SECTION
305 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
306 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
309 #ifndef ASM_OUTPUT_DWARF_DATA1
310 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
311 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
314 #ifndef ASM_OUTPUT_DWARF_DELTA1
315 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
316 do { fprintf ((FILE), "%s", ASM_BYTE_OP); \
317 assemble_name (FILE, LABEL1); \
318 fprintf (FILE, "-"); \
319 assemble_name (FILE, LABEL2); \
323 #ifdef UNALIGNED_INT_ASM_OP
325 #ifndef UNALIGNED_OFFSET_ASM_OP
326 #define UNALIGNED_OFFSET_ASM_OP \
327 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
330 #ifndef UNALIGNED_WORD_ASM_OP
331 #define UNALIGNED_WORD_ASM_OP \
332 ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \
333 : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \
334 : UNALIGNED_INT_ASM_OP)
337 #ifndef ASM_OUTPUT_DWARF_DELTA2
338 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
339 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \
340 assemble_name (FILE, LABEL1); \
341 fprintf (FILE, "-"); \
342 assemble_name (FILE, LABEL2); \
346 #ifndef ASM_OUTPUT_DWARF_DELTA4
347 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
348 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
349 assemble_name (FILE, LABEL1); \
350 fprintf (FILE, "-"); \
351 assemble_name (FILE, LABEL2); \
355 #ifndef ASM_OUTPUT_DWARF_DELTA
356 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
357 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \
358 assemble_name (FILE, LABEL1); \
359 fprintf (FILE, "-"); \
360 assemble_name (FILE, LABEL2); \
364 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
365 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
366 do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
367 assemble_name (FILE, LABEL1); \
368 fprintf (FILE, "-"); \
369 assemble_name (FILE, LABEL2); \
373 #ifndef ASM_OUTPUT_DWARF_ADDR
374 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
375 do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
376 assemble_name (FILE, LABEL); \
380 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
381 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
383 fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
384 output_addr_const ((FILE), (RTX)); \
388 #ifndef ASM_OUTPUT_DWARF_OFFSET4
389 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
390 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
391 assemble_name (FILE, LABEL); \
395 #ifndef ASM_OUTPUT_DWARF_OFFSET
396 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
397 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \
398 assemble_name (FILE, LABEL); \
402 #ifndef ASM_OUTPUT_DWARF_DATA2
403 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
404 fprintf ((FILE), "%s0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
407 #ifndef ASM_OUTPUT_DWARF_DATA4
408 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
409 fprintf ((FILE), "%s0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
412 #ifndef ASM_OUTPUT_DWARF_DATA8
413 #define ASM_OUTPUT_DWARF_DATA8(FILE,VALUE) \
414 fprintf ((FILE), "%s0x%lx", UNALIGNED_DOUBLE_INT_ASM_OP, \
415 (unsigned long) (VALUE))
418 #ifndef ASM_OUTPUT_DWARF_DATA
419 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
420 fprintf ((FILE), "%s0x%lx", UNALIGNED_OFFSET_ASM_OP, \
421 (unsigned long) (VALUE))
424 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
425 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
426 fprintf ((FILE), "%s0x%lx", UNALIGNED_WORD_ASM_OP, \
427 (unsigned long) (VALUE))
430 #ifndef ASM_OUTPUT_DWARF_CONST_DOUBLE
431 #define ASM_OUTPUT_DWARF_CONST_DOUBLE(FILE,HIGH_VALUE,LOW_VALUE) \
433 if (WORDS_BIG_ENDIAN) \
435 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
436 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
440 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
441 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
446 #else /* UNALIGNED_INT_ASM_OP */
448 /* We don't have unaligned support, let's hope the normal output works for
449 .debug_frame. But we know it won't work for .debug_info. */
451 #ifdef DWARF2_DEBUGGING_INFO
452 #error DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP.
455 #ifndef ASM_OUTPUT_DWARF_ADDR
456 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
457 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1)
460 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
461 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) ASM_OUTPUT_DWARF_ADDR (FILE,RTX)
464 #ifndef ASM_OUTPUT_DWARF_OFFSET4
465 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
466 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
469 #ifndef ASM_OUTPUT_DWARF_OFFSET
470 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
471 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
474 #ifndef ASM_OUTPUT_DWARF_DELTA2
475 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
476 assemble_integer (gen_rtx_MINUS (HImode, \
477 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
478 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
482 #ifndef ASM_OUTPUT_DWARF_DELTA4
483 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
484 assemble_integer (gen_rtx_MINUS (SImode, \
485 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
486 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
490 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
491 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
492 assemble_integer (gen_rtx_MINUS (Pmode, \
493 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
494 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
498 #ifndef ASM_OUTPUT_DWARF_DELTA
499 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
500 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
503 #ifndef ASM_OUTPUT_DWARF_DATA2
504 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
505 assemble_integer (GEN_INT (VALUE), 2, 1)
508 #ifndef ASM_OUTPUT_DWARF_DATA4
509 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
510 assemble_integer (GEN_INT (VALUE), 4, 1)
513 #endif /* UNALIGNED_INT_ASM_OP */
516 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
517 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
519 fprintf (FILE, "%s", SET_ASM_OP); \
520 assemble_name (FILE, SY); \
522 assemble_name (FILE, HI); \
524 assemble_name (FILE, LO); \
527 #endif /* SET_ASM_OP */
529 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
530 newline is produced. When flag_debug_asm is asserted, we add commentary
531 at the end of the line, so we must avoid output of a newline here. */
532 #ifndef ASM_OUTPUT_DWARF_NSTRING
533 #define ASM_OUTPUT_DWARF_NSTRING(FILE,P,SLEN) \
535 register int slen = (SLEN); \
536 register const char *p = (P); \
538 fprintf (FILE, "\t.ascii \""); \
539 for (i = 0; i < slen; i++) \
541 register int c = p[i]; \
542 if (c == '\"' || c == '\\') \
548 fprintf (FILE, "\\%o", c); \
551 fprintf (FILE, "\\0\""); \
555 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
556 ASM_OUTPUT_DWARF_NSTRING (FILE, P, strlen (P))
558 /* The DWARF 2 CFA column which tracks the return address. Normally this
559 is the column for PC, or the first column after all of the hard
561 #ifndef DWARF_FRAME_RETURN_COLUMN
563 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
565 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
569 /* The mapping from gcc register number to DWARF 2 CFA column number. By
570 default, we just provide columns for all registers. */
571 #ifndef DWARF_FRAME_REGNUM
572 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
575 /* Hook used by __throw. */
578 expand_builtin_dwarf_fp_regnum ()
580 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
583 /* The offset from the incoming value of %sp to the top of the stack frame
584 for the current function. */
585 #ifndef INCOMING_FRAME_SP_OFFSET
586 #define INCOMING_FRAME_SP_OFFSET 0
589 /* Return a pointer to a copy of the section string name S with all
590 attributes stripped off, and an asterisk prepended (for assemble_name). */
596 char *stripped = xmalloc (strlen (s) + 2);
601 while (*s && *s != ',')
608 /* Generate code to initialize the register size table. */
611 expand_builtin_init_dwarf_reg_sizes (address)
615 enum machine_mode mode = TYPE_MODE (char_type_node);
616 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
617 rtx mem = gen_rtx_MEM (mode, addr);
619 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
621 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
622 int size = GET_MODE_SIZE (reg_raw_mode[i]);
627 emit_move_insn (change_address (mem, mode,
628 plus_constant (addr, offset)),
633 /* Convert a DWARF call frame info. operation to its string name */
636 dwarf_cfi_name (cfi_opc)
637 register unsigned cfi_opc;
641 case DW_CFA_advance_loc:
642 return "DW_CFA_advance_loc";
644 return "DW_CFA_offset";
646 return "DW_CFA_restore";
650 return "DW_CFA_set_loc";
651 case DW_CFA_advance_loc1:
652 return "DW_CFA_advance_loc1";
653 case DW_CFA_advance_loc2:
654 return "DW_CFA_advance_loc2";
655 case DW_CFA_advance_loc4:
656 return "DW_CFA_advance_loc4";
657 case DW_CFA_offset_extended:
658 return "DW_CFA_offset_extended";
659 case DW_CFA_restore_extended:
660 return "DW_CFA_restore_extended";
661 case DW_CFA_undefined:
662 return "DW_CFA_undefined";
663 case DW_CFA_same_value:
664 return "DW_CFA_same_value";
665 case DW_CFA_register:
666 return "DW_CFA_register";
667 case DW_CFA_remember_state:
668 return "DW_CFA_remember_state";
669 case DW_CFA_restore_state:
670 return "DW_CFA_restore_state";
672 return "DW_CFA_def_cfa";
673 case DW_CFA_def_cfa_register:
674 return "DW_CFA_def_cfa_register";
675 case DW_CFA_def_cfa_offset:
676 return "DW_CFA_def_cfa_offset";
677 case DW_CFA_def_cfa_expression:
678 return "DW_CFA_def_cfa_expression";
680 /* SGI/MIPS specific */
681 case DW_CFA_MIPS_advance_loc8:
682 return "DW_CFA_MIPS_advance_loc8";
685 case DW_CFA_GNU_window_save:
686 return "DW_CFA_GNU_window_save";
687 case DW_CFA_GNU_args_size:
688 return "DW_CFA_GNU_args_size";
689 case DW_CFA_GNU_negative_offset_extended:
690 return "DW_CFA_GNU_negative_offset_extended";
693 return "DW_CFA_<unknown>";
697 /* Return a pointer to a newly allocated Call Frame Instruction. */
699 static inline dw_cfi_ref
702 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
704 cfi->dw_cfi_next = NULL;
705 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
706 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
711 /* Add a Call Frame Instruction to list of instructions. */
714 add_cfi (list_head, cfi)
715 register dw_cfi_ref *list_head;
716 register dw_cfi_ref cfi;
718 register dw_cfi_ref *p;
720 /* Find the end of the chain. */
721 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
727 /* Generate a new label for the CFI info to refer to. */
730 dwarf2out_cfi_label ()
732 static char label[20];
733 static unsigned long label_num = 0;
735 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
736 ASM_OUTPUT_LABEL (asm_out_file, label);
741 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
742 or to the CIE if LABEL is NULL. */
745 add_fde_cfi (label, cfi)
746 register const char *label;
747 register dw_cfi_ref cfi;
751 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
754 label = dwarf2out_cfi_label ();
756 if (fde->dw_fde_current_label == NULL
757 || strcmp (label, fde->dw_fde_current_label) != 0)
759 register dw_cfi_ref xcfi;
761 fde->dw_fde_current_label = label = xstrdup (label);
763 /* Set the location counter to the new label. */
765 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
766 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
767 add_cfi (&fde->dw_fde_cfi, xcfi);
770 add_cfi (&fde->dw_fde_cfi, cfi);
774 add_cfi (&cie_cfi_head, cfi);
777 /* Subroutine of lookup_cfa. */
780 lookup_cfa_1 (cfi, loc)
781 register dw_cfi_ref cfi;
782 register dw_cfa_location *loc;
784 switch (cfi->dw_cfi_opc)
786 case DW_CFA_def_cfa_offset:
787 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
789 case DW_CFA_def_cfa_register:
790 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
793 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
794 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
796 case DW_CFA_def_cfa_expression:
797 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
804 /* Find the previous value for the CFA. */
808 register dw_cfa_location *loc;
810 register dw_cfi_ref cfi;
812 loc->reg = (unsigned long) -1;
815 loc->base_offset = 0;
817 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
818 lookup_cfa_1 (cfi, loc);
820 if (fde_table_in_use)
822 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
823 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
824 lookup_cfa_1 (cfi, loc);
828 /* The current rule for calculating the DWARF2 canonical frame address. */
831 /* The register used for saving registers to the stack, and its offset
833 dw_cfa_location cfa_store;
835 /* The running total of the size of arguments pushed onto the stack. */
836 static long args_size;
838 /* The last args_size we actually output. */
839 static long old_args_size;
841 /* Entry point to update the canonical frame address (CFA).
842 LABEL is passed to add_fde_cfi. The value of CFA is now to be
843 calculated from REG+OFFSET. */
846 dwarf2out_def_cfa (label, reg, offset)
847 register const char *label;
856 def_cfa_1 (label, &loc);
859 /* This routine does the actual work. The CFA is now calculated from
860 the dw_cfa_location structure. */
862 def_cfa_1 (label, loc_p)
863 register const char *label;
864 dw_cfa_location *loc_p;
866 register dw_cfi_ref cfi;
867 dw_cfa_location old_cfa, loc;
872 if (cfa_store.reg == loc.reg && loc.indirect == 0)
873 cfa_store.offset = loc.offset;
875 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
876 lookup_cfa (&old_cfa);
878 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
879 loc.indirect == old_cfa.indirect)
881 if (loc.indirect == 0
882 || loc.base_offset == old_cfa.base_offset)
888 if (loc.reg == old_cfa.reg && !loc.indirect)
890 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
891 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
894 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
895 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
898 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
899 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
903 else if (loc.indirect == 0)
905 cfi->dw_cfi_opc = DW_CFA_def_cfa;
906 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
907 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
911 struct dw_loc_descr_struct *loc_list;
912 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
913 loc_list = build_cfa_loc (&loc);
914 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
917 add_fde_cfi (label, cfi);
920 /* Add the CFI for saving a register. REG is the CFA column number.
921 LABEL is passed to add_fde_cfi.
922 If SREG is -1, the register is saved at OFFSET from the CFA;
923 otherwise it is saved in SREG. */
926 reg_save (label, reg, sreg, offset)
927 register const char *label;
928 register unsigned reg;
929 register unsigned sreg;
930 register long offset;
932 register dw_cfi_ref cfi = new_cfi ();
934 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
936 /* The following comparison is correct. -1 is used to indicate that
937 the value isn't a register number. */
938 if (sreg == (unsigned int) -1)
941 /* The register number won't fit in 6 bits, so we have to use
943 cfi->dw_cfi_opc = DW_CFA_offset_extended;
945 cfi->dw_cfi_opc = DW_CFA_offset;
947 #ifdef ENABLE_CHECKING
949 /* If we get an offset that is not a multiple of
950 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
951 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
953 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
955 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
959 offset /= DWARF_CIE_DATA_ALIGNMENT;
962 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
965 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
967 else if (sreg == reg)
968 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
972 cfi->dw_cfi_opc = DW_CFA_register;
973 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
976 add_fde_cfi (label, cfi);
979 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
980 This CFI tells the unwinder that it needs to restore the window registers
981 from the previous frame's window save area.
983 ??? Perhaps we should note in the CIE where windows are saved (instead of
984 assuming 0(cfa)) and what registers are in the window. */
987 dwarf2out_window_save (label)
988 register const char *label;
990 register dw_cfi_ref cfi = new_cfi ();
991 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
992 add_fde_cfi (label, cfi);
995 /* Add a CFI to update the running total of the size of arguments
996 pushed onto the stack. */
999 dwarf2out_args_size (label, size)
1003 register dw_cfi_ref cfi;
1005 if (size == old_args_size)
1007 old_args_size = size;
1010 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1011 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1012 add_fde_cfi (label, cfi);
1015 /* Entry point for saving a register to the stack. REG is the GCC register
1016 number. LABEL and OFFSET are passed to reg_save. */
1019 dwarf2out_reg_save (label, reg, offset)
1020 register const char *label;
1021 register unsigned reg;
1022 register long offset;
1024 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
1027 /* Entry point for saving the return address in the stack.
1028 LABEL and OFFSET are passed to reg_save. */
1031 dwarf2out_return_save (label, offset)
1032 register const char *label;
1033 register long offset;
1035 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
1038 /* Entry point for saving the return address in a register.
1039 LABEL and SREG are passed to reg_save. */
1042 dwarf2out_return_reg (label, sreg)
1043 register const char *label;
1044 register unsigned sreg;
1046 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
1049 /* Record the initial position of the return address. RTL is
1050 INCOMING_RETURN_ADDR_RTX. */
1053 initial_return_save (rtl)
1056 unsigned int reg = (unsigned int) -1;
1059 switch (GET_CODE (rtl))
1062 /* RA is in a register. */
1063 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1066 /* RA is on the stack. */
1067 rtl = XEXP (rtl, 0);
1068 switch (GET_CODE (rtl))
1071 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1076 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1078 offset = INTVAL (XEXP (rtl, 1));
1081 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1083 offset = -INTVAL (XEXP (rtl, 1));
1090 /* The return address is at some offset from any value we can
1091 actually load. For instance, on the SPARC it is in %i7+8. Just
1092 ignore the offset for now; it doesn't matter for unwinding frames. */
1093 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1095 initial_return_save (XEXP (rtl, 0));
1101 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1104 /* Given a SET, calculate the amount of stack adjustment it
1108 stack_adjust_offset (pattern)
1111 rtx src = SET_SRC (pattern);
1112 rtx dest = SET_DEST (pattern);
1116 if (dest == stack_pointer_rtx)
1118 /* (set (reg sp) (plus (reg sp) (const_int))) */
1119 code = GET_CODE (src);
1120 if (! (code == PLUS || code == MINUS)
1121 || XEXP (src, 0) != stack_pointer_rtx
1122 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1125 offset = INTVAL (XEXP (src, 1));
1127 else if (GET_CODE (dest) == MEM)
1129 /* (set (mem (pre_dec (reg sp))) (foo)) */
1130 src = XEXP (dest, 0);
1131 code = GET_CODE (src);
1133 if (! (code == PRE_DEC || code == PRE_INC
1134 || code == PRE_MODIFY)
1135 || XEXP (src, 0) != stack_pointer_rtx)
1138 if (code == PRE_MODIFY)
1140 rtx val = XEXP (XEXP (src, 1), 1);
1141 /* We handle only adjustments by constant amount. */
1142 if (GET_CODE (XEXP (src, 1)) != PLUS ||
1143 GET_CODE (val) != CONST_INT)
1145 offset = -INTVAL (val);
1147 else offset = GET_MODE_SIZE (GET_MODE (dest));
1152 if (code == PLUS || code == PRE_INC)
1158 /* Check INSN to see if it looks like a push or a stack adjustment, and
1159 make a note of it if it does. EH uses this information to find out how
1160 much extra space it needs to pop off the stack. */
1163 dwarf2out_stack_adjust (insn)
1169 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1171 /* Extract the size of the args from the CALL rtx itself. */
1173 insn = PATTERN (insn);
1174 if (GET_CODE (insn) == PARALLEL)
1175 insn = XVECEXP (insn, 0, 0);
1176 if (GET_CODE (insn) == SET)
1177 insn = SET_SRC (insn);
1178 if (GET_CODE (insn) != CALL)
1180 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1184 /* If only calls can throw, and we have a frame pointer,
1185 save up adjustments until we see the CALL_INSN. */
1186 else if (! asynchronous_exceptions
1187 && cfa.reg != STACK_POINTER_REGNUM)
1190 if (GET_CODE (insn) == BARRIER)
1192 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1193 the compiler will have already emitted a stack adjustment, but
1194 doesn't bother for calls to noreturn functions. */
1195 #ifdef STACK_GROWS_DOWNWARD
1196 offset = -args_size;
1201 else if (GET_CODE (PATTERN (insn)) == SET)
1203 offset = stack_adjust_offset (PATTERN (insn));
1205 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1206 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1208 /* There may be stack adjustments inside compound insns. Search
1213 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1215 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1216 if (GET_CODE (pattern) == SET)
1217 offset += stack_adjust_offset (pattern);
1226 if (cfa.reg == STACK_POINTER_REGNUM)
1227 cfa.offset += offset;
1229 #ifndef STACK_GROWS_DOWNWARD
1232 args_size += offset;
1236 label = dwarf2out_cfi_label ();
1237 def_cfa_1 (label, &cfa);
1238 dwarf2out_args_size (label, args_size);
1241 /* A temporary register used in adjusting SP or setting up the store_reg. */
1242 static unsigned cfa_temp_reg;
1244 /* A temporary value used in adjusting SP or setting up the store_reg. */
1245 static long cfa_temp_value;
1247 /* Record call frame debugging information for an expression, which either
1248 sets SP or FP (adjusting how we calculate the frame address) or saves a
1249 register to the stack. */
1252 dwarf2out_frame_debug_expr (expr, label)
1259 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1260 the PARALLEL independently. The first element is always processed if
1261 it is a SET. This is for backward compatability. Other elements
1262 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1263 flag is set in them. */
1265 if (GET_CODE (expr) == PARALLEL
1266 || GET_CODE (expr) == SEQUENCE)
1269 int limit = XVECLEN (expr, 0);
1271 for (par_index = 0; par_index < limit; par_index++)
1273 rtx x = XVECEXP (expr, 0, par_index);
1275 if (GET_CODE (x) == SET &&
1276 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1277 dwarf2out_frame_debug_expr (x, label);
1282 if (GET_CODE (expr) != SET)
1285 src = SET_SRC (expr);
1286 dest = SET_DEST (expr);
1288 switch (GET_CODE (dest))
1291 /* Update the CFA rule wrt SP or FP. Make sure src is
1292 relative to the current CFA register. */
1293 switch (GET_CODE (src))
1295 /* Setting FP from SP. */
1297 if (cfa.reg == (unsigned) REGNO (src))
1303 /* We used to require that dest be either SP or FP, but the
1304 ARM copies SP to a temporary register, and from there to
1305 FP. So we just rely on the backends to only set
1306 RTX_FRAME_RELATED_P on appropriate insns. */
1307 cfa.reg = REGNO (dest);
1312 if (dest == stack_pointer_rtx)
1315 switch (GET_CODE (XEXP (src, 1)))
1318 offset = INTVAL (XEXP (src, 1));
1321 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1323 offset = cfa_temp_value;
1329 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1331 /* Restoring SP from FP in the epilogue. */
1332 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1334 cfa.reg = STACK_POINTER_REGNUM;
1336 else if (XEXP (src, 0) != stack_pointer_rtx)
1339 if (GET_CODE (src) == PLUS)
1341 if (cfa.reg == STACK_POINTER_REGNUM)
1342 cfa.offset += offset;
1343 if (cfa_store.reg == STACK_POINTER_REGNUM)
1344 cfa_store.offset += offset;
1346 else if (dest == hard_frame_pointer_rtx)
1348 /* Either setting the FP from an offset of the SP,
1349 or adjusting the FP */
1350 if (! frame_pointer_needed)
1353 if (GET_CODE (XEXP (src, 0)) == REG
1354 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1355 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1357 offset = INTVAL (XEXP (src, 1));
1358 if (GET_CODE (src) == PLUS)
1360 cfa.offset += offset;
1361 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1368 if (GET_CODE (src) != PLUS)
1371 if (GET_CODE (XEXP (src, 0)) == REG
1372 && REGNO (XEXP (src, 0)) == cfa.reg
1373 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1374 /* Setting the FP (or a scratch that will be copied into the FP
1375 later on) from SP + const. */
1376 cfa.reg = REGNO (dest);
1379 if (XEXP (src, 1) != stack_pointer_rtx)
1381 if (GET_CODE (XEXP (src, 0)) != REG
1382 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1384 if (cfa.reg != STACK_POINTER_REGNUM)
1386 cfa_store.reg = REGNO (dest);
1387 cfa_store.offset = cfa.offset - cfa_temp_value;
1393 cfa_temp_reg = REGNO (dest);
1394 cfa_temp_value = INTVAL (src);
1398 if (GET_CODE (XEXP (src, 0)) != REG
1399 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1400 || (unsigned) REGNO (dest) != cfa_temp_reg
1401 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1403 cfa_temp_value |= INTVAL (XEXP (src, 1));
1409 def_cfa_1 (label, &cfa);
1412 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1413 will fill in all of the bits. */
1418 cfa_temp_reg = REGNO (dest);
1419 cfa_temp_value = INTVAL (XEXP (src, 1));
1423 if (GET_CODE (src) != REG)
1426 /* Saving a register to the stack. Make sure dest is relative to the
1428 switch (GET_CODE (XEXP (dest, 0)))
1432 /* We can't handle variable size modifications. */
1433 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1435 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1437 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1438 || cfa_store.reg != STACK_POINTER_REGNUM)
1440 cfa_store.offset += offset;
1441 if (cfa.reg == STACK_POINTER_REGNUM)
1442 cfa.offset = cfa_store.offset;
1444 offset = -cfa_store.offset;
1448 offset = GET_MODE_SIZE (GET_MODE (dest));
1449 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1452 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1453 || cfa_store.reg != STACK_POINTER_REGNUM)
1455 cfa_store.offset += offset;
1456 if (cfa.reg == STACK_POINTER_REGNUM)
1457 cfa.offset = cfa_store.offset;
1459 offset = -cfa_store.offset;
1462 /* With an offset. */
1465 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1466 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1469 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1471 offset -= cfa_store.offset;
1474 /* Without an offset. */
1476 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1478 offset = -cfa_store.offset;
1485 if (REGNO (src) != STACK_POINTER_REGNUM
1486 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1487 && (unsigned) REGNO (src) == cfa.reg)
1489 /* We're storing the current CFA reg into the stack. */
1491 if (cfa.offset == 0)
1493 /* If the source register is exactly the CFA, assume
1494 we're saving SP like any other register; this happens
1497 def_cfa_1 (label, &cfa);
1498 dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset);
1503 /* Otherwise, we'll need to look in the stack to
1504 calculate the CFA. */
1506 rtx x = XEXP (dest, 0);
1507 if (GET_CODE (x) != REG)
1509 if (GET_CODE (x) != REG)
1511 cfa.reg = (unsigned) REGNO (x);
1512 cfa.base_offset = offset;
1514 def_cfa_1 (label, &cfa);
1519 def_cfa_1 (label, &cfa);
1520 dwarf2out_reg_save (label, REGNO (src), offset);
1528 /* Record call frame debugging information for INSN, which either
1529 sets SP or FP (adjusting how we calculate the frame address) or saves a
1530 register to the stack. If INSN is NULL_RTX, initialize our state. */
1533 dwarf2out_frame_debug (insn)
1539 if (insn == NULL_RTX)
1541 /* Set up state for generating call frame debug info. */
1543 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1545 cfa.reg = STACK_POINTER_REGNUM;
1552 if (! RTX_FRAME_RELATED_P (insn))
1554 dwarf2out_stack_adjust (insn);
1558 label = dwarf2out_cfi_label ();
1560 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1562 insn = XEXP (src, 0);
1564 insn = PATTERN (insn);
1566 dwarf2out_frame_debug_expr (insn, label);
1569 /* Return the size of an unsigned LEB128 quantity. */
1571 static inline unsigned long
1572 size_of_uleb128 (value)
1573 register unsigned long value;
1575 register unsigned long size = 0;
1576 register unsigned byte;
1580 byte = (value & 0x7f);
1589 /* Return the size of a signed LEB128 quantity. */
1591 static inline unsigned long
1592 size_of_sleb128 (value)
1593 register long value;
1595 register unsigned long size = 0;
1596 register unsigned byte;
1600 byte = (value & 0x7f);
1604 while (!(((value == 0) && ((byte & 0x40) == 0))
1605 || ((value == -1) && ((byte & 0x40) != 0))));
1610 /* Output an unsigned LEB128 quantity. */
1613 output_uleb128 (value)
1614 register unsigned long value;
1616 unsigned long save_value = value;
1618 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1621 register unsigned byte = (value & 0x7f);
1624 /* More bytes to follow. */
1627 fprintf (asm_out_file, "0x%x", byte);
1629 fprintf (asm_out_file, ",");
1634 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1637 /* Output an signed LEB128 quantity. */
1640 output_sleb128 (value)
1641 register long value;
1644 register unsigned byte;
1645 long save_value = value;
1647 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1650 byte = (value & 0x7f);
1651 /* arithmetic shift */
1653 more = !((((value == 0) && ((byte & 0x40) == 0))
1654 || ((value == -1) && ((byte & 0x40) != 0))));
1658 fprintf (asm_out_file, "0x%x", byte);
1660 fprintf (asm_out_file, ",");
1665 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1668 /* Output a Call Frame Information opcode and its operand(s). */
1671 output_cfi (cfi, fde)
1672 register dw_cfi_ref cfi;
1673 register dw_fde_ref fde;
1675 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1677 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1679 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1681 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1682 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1683 fputc ('\n', asm_out_file);
1686 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1688 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1690 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1692 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1693 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1695 fputc ('\n', asm_out_file);
1696 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1697 fputc ('\n', asm_out_file);
1699 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1701 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1703 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1705 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1706 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1708 fputc ('\n', asm_out_file);
1712 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1714 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1715 dwarf_cfi_name (cfi->dw_cfi_opc));
1717 fputc ('\n', asm_out_file);
1718 switch (cfi->dw_cfi_opc)
1720 case DW_CFA_set_loc:
1721 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1722 fputc ('\n', asm_out_file);
1724 case DW_CFA_advance_loc1:
1725 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1726 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1727 fde->dw_fde_current_label);
1728 fputc ('\n', asm_out_file);
1729 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1731 case DW_CFA_advance_loc2:
1732 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1733 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1734 fde->dw_fde_current_label);
1735 fputc ('\n', asm_out_file);
1736 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1738 case DW_CFA_advance_loc4:
1739 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1740 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1741 fde->dw_fde_current_label);
1742 fputc ('\n', asm_out_file);
1743 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1745 #ifdef MIPS_DEBUGGING_INFO
1746 case DW_CFA_MIPS_advance_loc8:
1747 /* TODO: not currently implemented. */
1751 case DW_CFA_offset_extended:
1752 case DW_CFA_GNU_negative_offset_extended:
1753 case DW_CFA_def_cfa:
1754 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1755 fputc ('\n', asm_out_file);
1756 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1757 fputc ('\n', asm_out_file);
1759 case DW_CFA_restore_extended:
1760 case DW_CFA_undefined:
1761 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1762 fputc ('\n', asm_out_file);
1764 case DW_CFA_same_value:
1765 case DW_CFA_def_cfa_register:
1766 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1767 fputc ('\n', asm_out_file);
1769 case DW_CFA_register:
1770 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1771 fputc ('\n', asm_out_file);
1772 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1773 fputc ('\n', asm_out_file);
1775 case DW_CFA_def_cfa_offset:
1776 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1777 fputc ('\n', asm_out_file);
1779 case DW_CFA_GNU_window_save:
1781 case DW_CFA_GNU_args_size:
1782 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1783 fputc ('\n', asm_out_file);
1785 case DW_CFA_def_cfa_expression:
1786 output_cfa_loc (cfi);
1794 /* Output the call frame information used to used to record information
1795 that relates to calculating the frame pointer, and records the
1796 location of saved registers. */
1799 output_call_frame_info (for_eh)
1802 register unsigned long i;
1803 register dw_fde_ref fde;
1804 register dw_cfi_ref cfi;
1805 char l1[20], l2[20];
1806 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1810 /* Do we want to include a pointer to the exception table? */
1811 int eh_ptr = for_eh && exception_table_p ();
1813 /* If we don't have any functions we'll want to unwind out of, don't
1814 emit any EH unwind information. */
1817 for (i = 0; i < fde_table_in_use; ++i)
1818 if (! fde_table[i].nothrow)
1824 fputc ('\n', asm_out_file);
1826 /* We're going to be generating comments, so turn on app. */
1832 #ifdef EH_FRAME_SECTION
1833 EH_FRAME_SECTION ();
1835 tree label = get_file_function_name ('F');
1837 force_data_section ();
1838 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1839 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1840 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1842 assemble_label ("__FRAME_BEGIN__");
1845 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1847 /* Output the CIE. */
1848 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1849 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1850 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1851 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1853 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1855 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1858 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1860 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1863 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1866 fputc ('\n', asm_out_file);
1867 ASM_OUTPUT_LABEL (asm_out_file, l1);
1870 /* Now that the CIE pointer is PC-relative for EH,
1871 use 0 to identify the CIE. */
1872 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1874 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1877 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1879 fputc ('\n', asm_out_file);
1880 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1882 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1883 fputc ('\n', asm_out_file);
1886 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1888 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1890 fputc ('\n', asm_out_file);
1893 /* The CIE contains a pointer to the exception region info for the
1894 frame. Make the augmentation string three bytes (including the
1895 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1896 can't handle unaligned relocs. */
1899 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1900 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1904 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1906 fputc ('\n', asm_out_file);
1908 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1910 fprintf (asm_out_file, "\t%s pointer to exception region info",
1915 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1917 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1921 fputc ('\n', asm_out_file);
1924 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1926 fputc ('\n', asm_out_file);
1927 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1929 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1931 fputc ('\n', asm_out_file);
1932 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1934 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1936 fputc ('\n', asm_out_file);
1938 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1939 output_cfi (cfi, NULL);
1941 /* Pad the CIE out to an address sized boundary. */
1942 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1943 ASM_OUTPUT_LABEL (asm_out_file, l2);
1944 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1945 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1947 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1948 fputc ('\n', asm_out_file);
1951 /* Loop through all of the FDE's. */
1952 for (i = 0; i < fde_table_in_use; ++i)
1954 fde = &fde_table[i];
1956 /* Don't emit EH unwind info for leaf functions. */
1957 if (for_eh && fde->nothrow)
1960 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1961 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1962 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1963 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i * 2);
1965 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1967 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1970 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1972 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1975 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1976 fputc ('\n', asm_out_file);
1977 ASM_OUTPUT_LABEL (asm_out_file, l1);
1979 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1980 emits a target dependent sized offset when for_eh is not true.
1981 This inconsistency may confuse gdb. The only case where we need a
1982 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1983 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1984 though in order to be compatible with the dwarf_fde struct in frame.c.
1985 If the for_eh case is changed, then the struct in frame.c has
1986 to be adjusted appropriately. */
1988 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1990 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1992 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1994 fputc ('\n', asm_out_file);
1995 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1997 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1999 fputc ('\n', asm_out_file);
2000 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
2001 fde->dw_fde_end, fde->dw_fde_begin);
2003 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
2005 fputc ('\n', asm_out_file);
2007 /* Loop through the Call Frame Instructions associated with
2009 fde->dw_fde_current_label = fde->dw_fde_begin;
2010 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2011 output_cfi (cfi, fde);
2013 /* Pad the FDE out to an address sized boundary. */
2014 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2015 ASM_OUTPUT_LABEL (asm_out_file, l2);
2016 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2017 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
2019 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
2020 fputc ('\n', asm_out_file);
2023 #ifndef EH_FRAME_SECTION
2026 /* Emit terminating zero for table. */
2027 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2028 fputc ('\n', asm_out_file);
2031 #ifdef MIPS_DEBUGGING_INFO
2032 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2033 get a value of 0. Putting .align 0 after the label fixes it. */
2034 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2037 /* Turn off app to make assembly quicker. */
2042 /* Output a marker (i.e. a label) for the beginning of a function, before
2046 dwarf2out_begin_prologue ()
2048 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2049 register dw_fde_ref fde;
2051 ++current_funcdef_number;
2053 function_section (current_function_decl);
2054 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2055 current_funcdef_number);
2056 ASM_OUTPUT_LABEL (asm_out_file, label);
2057 current_function_func_begin_label = get_identifier (label);
2059 /* Expand the fde table if necessary. */
2060 if (fde_table_in_use == fde_table_allocated)
2062 fde_table_allocated += FDE_TABLE_INCREMENT;
2064 = (dw_fde_ref) xrealloc (fde_table,
2065 fde_table_allocated * sizeof (dw_fde_node));
2068 /* Record the FDE associated with this function. */
2069 current_funcdef_fde = fde_table_in_use;
2071 /* Add the new FDE at the end of the fde_table. */
2072 fde = &fde_table[fde_table_in_use++];
2073 fde->dw_fde_begin = xstrdup (label);
2074 fde->dw_fde_current_label = NULL;
2075 fde->dw_fde_end = NULL;
2076 fde->dw_fde_cfi = NULL;
2077 fde->nothrow = current_function_nothrow;
2079 args_size = old_args_size = 0;
2082 /* Output a marker (i.e. a label) for the absolute end of the generated code
2083 for a function definition. This gets called *after* the epilogue code has
2087 dwarf2out_end_epilogue ()
2090 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2092 /* Output a label to mark the endpoint of the code generated for this
2094 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2095 ASM_OUTPUT_LABEL (asm_out_file, label);
2096 fde = &fde_table[fde_table_in_use - 1];
2097 fde->dw_fde_end = xstrdup (label);
2101 dwarf2out_frame_init ()
2103 /* Allocate the initial hunk of the fde_table. */
2104 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2105 fde_table_allocated = FDE_TABLE_INCREMENT;
2106 fde_table_in_use = 0;
2108 /* Generate the CFA instructions common to all FDE's. Do it now for the
2109 sake of lookup_cfa. */
2111 #ifdef DWARF2_UNWIND_INFO
2112 /* On entry, the Canonical Frame Address is at SP. */
2113 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2114 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2119 dwarf2out_frame_finish ()
2121 /* Output call frame information. */
2122 #ifdef MIPS_DEBUGGING_INFO
2123 if (write_symbols == DWARF2_DEBUG)
2124 output_call_frame_info (0);
2125 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2126 output_call_frame_info (1);
2128 if (write_symbols == DWARF2_DEBUG
2129 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2130 output_call_frame_info (1);
2134 /* And now, the subset of the debugging information support code necessary
2135 for emitting location expressions. */
2137 typedef struct dw_val_struct *dw_val_ref;
2138 typedef struct die_struct *dw_die_ref;
2139 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2141 /* Each DIE may have a series of attribute/value pairs. Values
2142 can take on several forms. The forms that are used in this
2143 implementation are listed below. */
2150 dw_val_class_unsigned_const,
2151 dw_val_class_long_long,
2154 dw_val_class_die_ref,
2155 dw_val_class_fde_ref,
2156 dw_val_class_lbl_id,
2157 dw_val_class_lbl_offset,
2162 /* Describe a double word constant value. */
2163 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2165 typedef struct dw_long_long_struct
2172 /* Describe a floating point constant value. */
2174 typedef struct dw_fp_struct
2181 /* The dw_val_node describes an attribute's value, as it is
2182 represented internally. */
2184 typedef struct dw_val_struct
2186 dw_val_class val_class;
2190 dw_loc_descr_ref val_loc;
2192 long unsigned val_unsigned;
2193 dw_long_long_const val_long_long;
2194 dw_float_const val_float;
2199 unsigned val_fde_index;
2202 unsigned char val_flag;
2208 /* Locations in memory are described using a sequence of stack machine
2211 typedef struct dw_loc_descr_struct
2213 dw_loc_descr_ref dw_loc_next;
2214 enum dwarf_location_atom dw_loc_opc;
2215 dw_val_node dw_loc_oprnd1;
2216 dw_val_node dw_loc_oprnd2;
2221 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2222 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2225 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2227 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2228 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2229 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2230 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2232 /* Convert a DWARF stack opcode into its string name. */
2235 dwarf_stack_op_name (op)
2236 register unsigned op;
2241 return "DW_OP_addr";
2243 return "DW_OP_deref";
2245 return "DW_OP_const1u";
2247 return "DW_OP_const1s";
2249 return "DW_OP_const2u";
2251 return "DW_OP_const2s";
2253 return "DW_OP_const4u";
2255 return "DW_OP_const4s";
2257 return "DW_OP_const8u";
2259 return "DW_OP_const8s";
2261 return "DW_OP_constu";
2263 return "DW_OP_consts";
2267 return "DW_OP_drop";
2269 return "DW_OP_over";
2271 return "DW_OP_pick";
2273 return "DW_OP_swap";
2277 return "DW_OP_xderef";
2285 return "DW_OP_minus";
2297 return "DW_OP_plus";
2298 case DW_OP_plus_uconst:
2299 return "DW_OP_plus_uconst";
2305 return "DW_OP_shra";
2323 return "DW_OP_skip";
2325 return "DW_OP_lit0";
2327 return "DW_OP_lit1";
2329 return "DW_OP_lit2";
2331 return "DW_OP_lit3";
2333 return "DW_OP_lit4";
2335 return "DW_OP_lit5";
2337 return "DW_OP_lit6";
2339 return "DW_OP_lit7";
2341 return "DW_OP_lit8";
2343 return "DW_OP_lit9";
2345 return "DW_OP_lit10";
2347 return "DW_OP_lit11";
2349 return "DW_OP_lit12";
2351 return "DW_OP_lit13";
2353 return "DW_OP_lit14";
2355 return "DW_OP_lit15";
2357 return "DW_OP_lit16";
2359 return "DW_OP_lit17";
2361 return "DW_OP_lit18";
2363 return "DW_OP_lit19";
2365 return "DW_OP_lit20";
2367 return "DW_OP_lit21";
2369 return "DW_OP_lit22";
2371 return "DW_OP_lit23";
2373 return "DW_OP_lit24";
2375 return "DW_OP_lit25";
2377 return "DW_OP_lit26";
2379 return "DW_OP_lit27";
2381 return "DW_OP_lit28";
2383 return "DW_OP_lit29";
2385 return "DW_OP_lit30";
2387 return "DW_OP_lit31";
2389 return "DW_OP_reg0";
2391 return "DW_OP_reg1";
2393 return "DW_OP_reg2";
2395 return "DW_OP_reg3";
2397 return "DW_OP_reg4";
2399 return "DW_OP_reg5";
2401 return "DW_OP_reg6";
2403 return "DW_OP_reg7";
2405 return "DW_OP_reg8";
2407 return "DW_OP_reg9";
2409 return "DW_OP_reg10";
2411 return "DW_OP_reg11";
2413 return "DW_OP_reg12";
2415 return "DW_OP_reg13";
2417 return "DW_OP_reg14";
2419 return "DW_OP_reg15";
2421 return "DW_OP_reg16";
2423 return "DW_OP_reg17";
2425 return "DW_OP_reg18";
2427 return "DW_OP_reg19";
2429 return "DW_OP_reg20";
2431 return "DW_OP_reg21";
2433 return "DW_OP_reg22";
2435 return "DW_OP_reg23";
2437 return "DW_OP_reg24";
2439 return "DW_OP_reg25";
2441 return "DW_OP_reg26";
2443 return "DW_OP_reg27";
2445 return "DW_OP_reg28";
2447 return "DW_OP_reg29";
2449 return "DW_OP_reg30";
2451 return "DW_OP_reg31";
2453 return "DW_OP_breg0";
2455 return "DW_OP_breg1";
2457 return "DW_OP_breg2";
2459 return "DW_OP_breg3";
2461 return "DW_OP_breg4";
2463 return "DW_OP_breg5";
2465 return "DW_OP_breg6";
2467 return "DW_OP_breg7";
2469 return "DW_OP_breg8";
2471 return "DW_OP_breg9";
2473 return "DW_OP_breg10";
2475 return "DW_OP_breg11";
2477 return "DW_OP_breg12";
2479 return "DW_OP_breg13";
2481 return "DW_OP_breg14";
2483 return "DW_OP_breg15";
2485 return "DW_OP_breg16";
2487 return "DW_OP_breg17";
2489 return "DW_OP_breg18";
2491 return "DW_OP_breg19";
2493 return "DW_OP_breg20";
2495 return "DW_OP_breg21";
2497 return "DW_OP_breg22";
2499 return "DW_OP_breg23";
2501 return "DW_OP_breg24";
2503 return "DW_OP_breg25";
2505 return "DW_OP_breg26";
2507 return "DW_OP_breg27";
2509 return "DW_OP_breg28";
2511 return "DW_OP_breg29";
2513 return "DW_OP_breg30";
2515 return "DW_OP_breg31";
2517 return "DW_OP_regx";
2519 return "DW_OP_fbreg";
2521 return "DW_OP_bregx";
2523 return "DW_OP_piece";
2524 case DW_OP_deref_size:
2525 return "DW_OP_deref_size";
2526 case DW_OP_xderef_size:
2527 return "DW_OP_xderef_size";
2531 return "OP_<unknown>";
2535 /* Return a pointer to a newly allocated location description. Location
2536 descriptions are simple expression terms that can be strung
2537 together to form more complicated location (address) descriptions. */
2539 static inline dw_loc_descr_ref
2540 new_loc_descr (op, oprnd1, oprnd2)
2541 register enum dwarf_location_atom op;
2542 register unsigned long oprnd1;
2543 register unsigned long oprnd2;
2545 /* Use xcalloc here so we clear out all of the long_long constant in
2547 register dw_loc_descr_ref descr
2548 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2550 descr->dw_loc_opc = op;
2551 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2552 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2553 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2554 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2559 /* Add a location description term to a location description expression. */
2562 add_loc_descr (list_head, descr)
2563 register dw_loc_descr_ref *list_head;
2564 register dw_loc_descr_ref descr;
2566 register dw_loc_descr_ref *d;
2568 /* Find the end of the chain. */
2569 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2575 /* Return the size of a location descriptor. */
2577 static unsigned long
2578 size_of_loc_descr (loc)
2579 register dw_loc_descr_ref loc;
2581 register unsigned long size = 1;
2583 switch (loc->dw_loc_opc)
2586 size += DWARF2_ADDR_SIZE;
2605 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2608 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2613 case DW_OP_plus_uconst:
2614 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2652 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2655 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2658 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2661 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2662 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2665 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2667 case DW_OP_deref_size:
2668 case DW_OP_xderef_size:
2678 /* Return the size of a series of location descriptors. */
2680 static unsigned long
2682 register dw_loc_descr_ref loc;
2684 register unsigned long size = 0;
2686 for (; loc != NULL; loc = loc->dw_loc_next)
2688 loc->dw_loc_addr = size;
2689 size += size_of_loc_descr (loc);
2695 /* Output location description stack opcode's operands (if any). */
2698 output_loc_operands (loc)
2699 register dw_loc_descr_ref loc;
2701 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2702 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2704 switch (loc->dw_loc_opc)
2706 #ifdef DWARF2_DEBUGGING_INFO
2708 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
2709 fputc ('\n', asm_out_file);
2713 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2714 fputc ('\n', asm_out_file);
2718 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
2719 fputc ('\n', asm_out_file);
2724 fputc ('\n', asm_out_file);
2731 if (val1->val_class == dw_val_class_loc)
2732 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2736 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, offset);
2737 fputc ('\n', asm_out_file);
2750 /* We currently don't make any attempt to make sure these are
2751 aligned properly like we do for the main unwind info, so
2752 don't support emitting things larger than a byte if we're
2753 only doing unwinding. */
2758 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2759 fputc ('\n', asm_out_file);
2762 output_uleb128 (val1->v.val_unsigned);
2763 fputc ('\n', asm_out_file);
2766 output_sleb128 (val1->v.val_int);
2767 fputc ('\n', asm_out_file);
2770 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
2771 fputc ('\n', asm_out_file);
2773 case DW_OP_plus_uconst:
2774 output_uleb128 (val1->v.val_unsigned);
2775 fputc ('\n', asm_out_file);
2809 output_sleb128 (val1->v.val_int);
2810 fputc ('\n', asm_out_file);
2813 output_uleb128 (val1->v.val_unsigned);
2814 fputc ('\n', asm_out_file);
2817 output_sleb128 (val1->v.val_int);
2818 fputc ('\n', asm_out_file);
2821 output_uleb128 (val1->v.val_unsigned);
2822 fputc ('\n', asm_out_file);
2823 output_sleb128 (val2->v.val_int);
2824 fputc ('\n', asm_out_file);
2827 output_uleb128 (val1->v.val_unsigned);
2828 fputc ('\n', asm_out_file);
2830 case DW_OP_deref_size:
2831 case DW_OP_xderef_size:
2832 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2833 fputc ('\n', asm_out_file);
2836 /* Other codes have no operands. */
2841 /* Output a sequence of location operations. */
2844 output_loc_sequence (loc)
2845 dw_loc_descr_ref loc;
2847 for (; loc != NULL; loc = loc->dw_loc_next)
2849 /* Output the opcode. */
2850 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
2852 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
2853 dwarf_stack_op_name (loc->dw_loc_opc));
2855 fputc ('\n', asm_out_file);
2857 /* Output the operand(s) (if any). */
2858 output_loc_operands (loc);
2862 /* This routine will generate the correct assembly data for a location
2863 description based on a cfi entry with a complex address. */
2866 output_cfa_loc (cfi)
2869 dw_loc_descr_ref loc;
2872 /* Output the size of the block. */
2873 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2874 size = size_of_locs (loc);
2875 output_uleb128 (size);
2876 fputc ('\n', asm_out_file);
2878 /* Now output the operations themselves. */
2879 output_loc_sequence (loc);
2882 /* This function builds a dwarf location descriptor seqeunce from
2883 a dw_cfa_location. */
2885 static struct dw_loc_descr_struct *
2887 dw_cfa_location *cfa;
2889 struct dw_loc_descr_struct *head, *tmp;
2891 if (cfa->indirect == 0)
2894 if (cfa->base_offset)
2897 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2899 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2901 else if (cfa->reg <= 31)
2902 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2904 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2905 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2906 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2907 add_loc_descr (&head, tmp);
2908 if (cfa->offset != 0)
2910 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2911 add_loc_descr (&head, tmp);
2916 /* This function fills in aa dw_cfa_location structure from a
2917 dwarf location descriptor sequence. */
2920 get_cfa_from_loc_descr (cfa, loc)
2921 dw_cfa_location *cfa;
2922 struct dw_loc_descr_struct *loc;
2924 struct dw_loc_descr_struct *ptr;
2926 cfa->base_offset = 0;
2930 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2932 enum dwarf_location_atom op = ptr->dw_loc_opc;
2967 cfa->reg = op - DW_OP_reg0;
2970 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3004 cfa->reg = op - DW_OP_breg0;
3005 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3008 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3009 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3014 case DW_OP_plus_uconst:
3015 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3018 fatal ("DW_LOC_OP %s not implememnted yet.\n",
3019 dwarf_stack_op_name (ptr->dw_loc_opc));
3023 #endif /* .debug_frame support */
3025 /* And now, the support for symbolic debugging information. */
3026 #ifdef DWARF2_DEBUGGING_INFO
3028 /* NOTE: In the comments in this file, many references are made to
3029 "Debugging Information Entries". This term is abbreviated as `DIE'
3030 throughout the remainder of this file. */
3032 /* An internal representation of the DWARF output is built, and then
3033 walked to generate the DWARF debugging info. The walk of the internal
3034 representation is done after the entire program has been compiled.
3035 The types below are used to describe the internal representation. */
3037 /* Various DIE's use offsets relative to the beginning of the
3038 .debug_info section to refer to each other. */
3040 typedef long int dw_offset;
3042 /* Define typedefs here to avoid circular dependencies. */
3044 typedef struct dw_attr_struct *dw_attr_ref;
3045 typedef struct dw_line_info_struct *dw_line_info_ref;
3046 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3047 typedef struct pubname_struct *pubname_ref;
3048 typedef dw_die_ref *arange_ref;
3050 /* Each entry in the line_info_table maintains the file and
3051 line number associated with the label generated for that
3052 entry. The label gives the PC value associated with
3053 the line number entry. */
3055 typedef struct dw_line_info_struct
3057 unsigned long dw_file_num;
3058 unsigned long dw_line_num;
3062 /* Line information for functions in separate sections; each one gets its
3064 typedef struct dw_separate_line_info_struct
3066 unsigned long dw_file_num;
3067 unsigned long dw_line_num;
3068 unsigned long function;
3070 dw_separate_line_info_entry;
3072 /* Each DIE attribute has a field specifying the attribute kind,
3073 a link to the next attribute in the chain, and an attribute value.
3074 Attributes are typically linked below the DIE they modify. */
3076 typedef struct dw_attr_struct
3078 enum dwarf_attribute dw_attr;
3079 dw_attr_ref dw_attr_next;
3080 dw_val_node dw_attr_val;
3084 /* The Debugging Information Entry (DIE) structure */
3086 typedef struct die_struct
3088 enum dwarf_tag die_tag;
3090 dw_attr_ref die_attr;
3091 dw_die_ref die_parent;
3092 dw_die_ref die_child;
3094 dw_offset die_offset;
3095 unsigned long die_abbrev;
3100 /* The pubname structure */
3102 typedef struct pubname_struct
3109 /* The limbo die list structure. */
3110 typedef struct limbo_die_struct
3113 struct limbo_die_struct *next;
3117 /* How to start an assembler comment. */
3118 #ifndef ASM_COMMENT_START
3119 #define ASM_COMMENT_START ";#"
3122 /* Define a macro which returns non-zero for a TYPE_DECL which was
3123 implicitly generated for a tagged type.
3125 Note that unlike the gcc front end (which generates a NULL named
3126 TYPE_DECL node for each complete tagged type, each array type, and
3127 each function type node created) the g++ front end generates a
3128 _named_ TYPE_DECL node for each tagged type node created.
3129 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3130 generate a DW_TAG_typedef DIE for them. */
3132 #define TYPE_DECL_IS_STUB(decl) \
3133 (DECL_NAME (decl) == NULL_TREE \
3134 || (DECL_ARTIFICIAL (decl) \
3135 && is_tagged_type (TREE_TYPE (decl)) \
3136 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3137 /* This is necessary for stub decls that \
3138 appear in nested inline functions. */ \
3139 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3140 && (decl_ultimate_origin (decl) \
3141 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3143 /* Information concerning the compilation unit's programming
3144 language, and compiler version. */
3146 extern int flag_traditional;
3148 /* Fixed size portion of the DWARF compilation unit header. */
3149 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3151 /* Fixed size portion of debugging line information prolog. */
3152 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3154 /* Fixed size portion of public names info. */
3155 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3157 /* Fixed size portion of the address range info. */
3158 #define DWARF_ARANGES_HEADER_SIZE \
3159 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3160 - DWARF_OFFSET_SIZE)
3162 /* Size of padding portion in the address range info. It must be
3163 aligned to twice the pointer size. */
3164 #define DWARF_ARANGES_PAD_SIZE \
3165 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3166 - (2 * DWARF_OFFSET_SIZE + 4))
3168 /* Use assembler line directives if available. */
3169 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3170 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3171 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3173 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3177 /* Define the architecture-dependent minimum instruction length (in bytes).
3178 In this implementation of DWARF, this field is used for information
3179 purposes only. Since GCC generates assembly language, we have
3180 no a priori knowledge of how many instruction bytes are generated
3181 for each source line, and therefore can use only the DW_LNE_set_address
3182 and DW_LNS_fixed_advance_pc line information commands. */
3184 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3185 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3188 /* Minimum line offset in a special line info. opcode.
3189 This value was chosen to give a reasonable range of values. */
3190 #define DWARF_LINE_BASE -10
3192 /* First special line opcde - leave room for the standard opcodes. */
3193 #define DWARF_LINE_OPCODE_BASE 10
3195 /* Range of line offsets in a special line info. opcode. */
3196 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3198 /* Flag that indicates the initial value of the is_stmt_start flag.
3199 In the present implementation, we do not mark any lines as
3200 the beginning of a source statement, because that information
3201 is not made available by the GCC front-end. */
3202 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3204 /* This location is used by calc_die_sizes() to keep track
3205 the offset of each DIE within the .debug_info section. */
3206 static unsigned long next_die_offset;
3208 /* Record the root of the DIE's built for the current compilation unit. */
3209 static dw_die_ref comp_unit_die;
3211 /* A list of DIEs with a NULL parent waiting to be relocated. */
3212 static limbo_die_node *limbo_die_list = 0;
3214 /* Structure used by lookup_filename to manage sets of filenames. */
3220 unsigned last_lookup_index;
3223 /* Size (in elements) of increments by which we may expand the filename
3225 #define FILE_TABLE_INCREMENT 64
3227 /* Filenames referenced by declarations this compilation unit. */
3228 static struct file_table decl_file_table;
3230 /* Filenames referenced by line numbers in this compilation unit. */
3231 static struct file_table line_file_table;
3233 /* Local pointer to the name of the main input file. Initialized in
3235 static const char *primary_filename;
3237 /* A pointer to the base of a table of references to DIE's that describe
3238 declarations. The table is indexed by DECL_UID() which is a unique
3239 number identifying each decl. */
3240 static dw_die_ref *decl_die_table;
3242 /* Number of elements currently allocated for the decl_die_table. */
3243 static unsigned decl_die_table_allocated;
3245 /* Number of elements in decl_die_table currently in use. */
3246 static unsigned decl_die_table_in_use;
3248 /* Size (in elements) of increments by which we may expand the
3250 #define DECL_DIE_TABLE_INCREMENT 256
3252 /* A pointer to the base of a table of references to declaration
3253 scopes. This table is a display which tracks the nesting
3254 of declaration scopes at the current scope and containing
3255 scopes. This table is used to find the proper place to
3256 define type declaration DIE's. */
3257 static tree *decl_scope_table;
3259 /* Number of elements currently allocated for the decl_scope_table. */
3260 static int decl_scope_table_allocated;
3262 /* Current level of nesting of declaration scopes. */
3263 static int decl_scope_depth;
3265 /* Size (in elements) of increments by which we may expand the
3266 decl_scope_table. */
3267 #define DECL_SCOPE_TABLE_INCREMENT 64
3269 /* A pointer to the base of a list of references to DIE's that
3270 are uniquely identified by their tag, presence/absence of
3271 children DIE's, and list of attribute/value pairs. */
3272 static dw_die_ref *abbrev_die_table;
3274 /* Number of elements currently allocated for abbrev_die_table. */
3275 static unsigned abbrev_die_table_allocated;
3277 /* Number of elements in type_die_table currently in use. */
3278 static unsigned abbrev_die_table_in_use;
3280 /* Size (in elements) of increments by which we may expand the
3281 abbrev_die_table. */
3282 #define ABBREV_DIE_TABLE_INCREMENT 256
3284 /* A pointer to the base of a table that contains line information
3285 for each source code line in .text in the compilation unit. */
3286 static dw_line_info_ref line_info_table;
3288 /* Number of elements currently allocated for line_info_table. */
3289 static unsigned line_info_table_allocated;
3291 /* Number of elements in separate_line_info_table currently in use. */
3292 static unsigned separate_line_info_table_in_use;
3294 /* A pointer to the base of a table that contains line information
3295 for each source code line outside of .text in the compilation unit. */
3296 static dw_separate_line_info_ref separate_line_info_table;
3298 /* Number of elements currently allocated for separate_line_info_table. */
3299 static unsigned separate_line_info_table_allocated;
3301 /* Number of elements in line_info_table currently in use. */
3302 static unsigned line_info_table_in_use;
3304 /* Size (in elements) of increments by which we may expand the
3306 #define LINE_INFO_TABLE_INCREMENT 1024
3308 /* A pointer to the base of a table that contains a list of publicly
3309 accessible names. */
3310 static pubname_ref pubname_table;
3312 /* Number of elements currently allocated for pubname_table. */
3313 static unsigned pubname_table_allocated;
3315 /* Number of elements in pubname_table currently in use. */
3316 static unsigned pubname_table_in_use;
3318 /* Size (in elements) of increments by which we may expand the
3320 #define PUBNAME_TABLE_INCREMENT 64
3322 /* A pointer to the base of a table that contains a list of publicly
3323 accessible names. */
3324 static arange_ref arange_table;
3326 /* Number of elements currently allocated for arange_table. */
3327 static unsigned arange_table_allocated;
3329 /* Number of elements in arange_table currently in use. */
3330 static unsigned arange_table_in_use;
3332 /* Size (in elements) of increments by which we may expand the
3334 #define ARANGE_TABLE_INCREMENT 64
3336 /* A pointer to the base of a list of incomplete types which might be
3337 completed at some later time. */
3339 static tree *incomplete_types_list;
3341 /* Number of elements currently allocated for the incomplete_types_list. */
3342 static unsigned incomplete_types_allocated;
3344 /* Number of elements of incomplete_types_list currently in use. */
3345 static unsigned incomplete_types;
3347 /* Size (in elements) of increments by which we may expand the incomplete
3348 types list. Actually, a single hunk of space of this size should
3349 be enough for most typical programs. */
3350 #define INCOMPLETE_TYPES_INCREMENT 64
3352 /* Record whether the function being analyzed contains inlined functions. */
3353 static int current_function_has_inlines;
3354 #if 0 && defined (MIPS_DEBUGGING_INFO)
3355 static int comp_unit_has_inlines;
3358 /* Array of RTXes referenced by the debugging information, which therefore
3359 must be kept around forever. We do this rather than perform GC on
3360 the dwarf info because almost all of the dwarf info lives forever, and
3361 it's easier to support non-GC frontends this way. */
3362 static varray_type used_rtx_varray;
3364 /* Forward declarations for functions defined in this file. */
3366 static int is_pseudo_reg PARAMS ((rtx));
3367 static tree type_main_variant PARAMS ((tree));
3368 static int is_tagged_type PARAMS ((tree));
3369 static const char *dwarf_tag_name PARAMS ((unsigned));
3370 static const char *dwarf_attr_name PARAMS ((unsigned));
3371 static const char *dwarf_form_name PARAMS ((unsigned));
3373 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3375 static tree decl_ultimate_origin PARAMS ((tree));
3376 static tree block_ultimate_origin PARAMS ((tree));
3377 static tree decl_class_context PARAMS ((tree));
3378 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3379 static void add_AT_flag PARAMS ((dw_die_ref,
3380 enum dwarf_attribute,
3382 static void add_AT_int PARAMS ((dw_die_ref,
3383 enum dwarf_attribute, long));
3384 static void add_AT_unsigned PARAMS ((dw_die_ref,
3385 enum dwarf_attribute,
3387 static void add_AT_long_long PARAMS ((dw_die_ref,
3388 enum dwarf_attribute,
3391 static void add_AT_float PARAMS ((dw_die_ref,
3392 enum dwarf_attribute,
3394 static void add_AT_string PARAMS ((dw_die_ref,
3395 enum dwarf_attribute,
3397 static void add_AT_die_ref PARAMS ((dw_die_ref,
3398 enum dwarf_attribute,
3400 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3401 enum dwarf_attribute,
3403 static void add_AT_loc PARAMS ((dw_die_ref,
3404 enum dwarf_attribute,
3406 static void add_AT_addr PARAMS ((dw_die_ref,
3407 enum dwarf_attribute,
3409 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3410 enum dwarf_attribute,
3412 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3413 enum dwarf_attribute,
3415 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3416 enum dwarf_attribute));
3417 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3418 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3419 static const char *get_AT_string PARAMS ((dw_die_ref,
3420 enum dwarf_attribute));
3421 static int get_AT_flag PARAMS ((dw_die_ref,
3422 enum dwarf_attribute));
3423 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3424 enum dwarf_attribute));
3425 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3426 enum dwarf_attribute));
3427 static int is_c_family PARAMS ((void));
3428 static int is_java PARAMS ((void));
3429 static int is_fortran PARAMS ((void));
3430 static void remove_AT PARAMS ((dw_die_ref,
3431 enum dwarf_attribute));
3432 static void remove_children PARAMS ((dw_die_ref));
3433 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3434 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3435 static dw_die_ref lookup_type_die PARAMS ((tree));
3436 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3437 static dw_die_ref lookup_decl_die PARAMS ((tree));
3438 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3439 static void print_spaces PARAMS ((FILE *));
3440 static void print_die PARAMS ((dw_die_ref, FILE *));
3441 static void print_dwarf_line_table PARAMS ((FILE *));
3442 static void reverse_die_lists PARAMS ((dw_die_ref));
3443 static void reverse_all_dies PARAMS ((dw_die_ref));
3444 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3445 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3446 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3447 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3448 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3449 static void compute_section_prefix PARAMS ((dw_die_ref));
3450 static int is_type_die PARAMS ((dw_die_ref));
3451 static int is_comdat_die PARAMS ((dw_die_ref));
3452 static int is_symbol_die PARAMS ((dw_die_ref));
3453 static char *gen_internal_sym PARAMS ((void));
3454 static void assign_symbol_names PARAMS ((dw_die_ref));
3455 static void break_out_includes PARAMS ((dw_die_ref));
3456 static void add_sibling_attributes PARAMS ((dw_die_ref));
3457 static void build_abbrev_table PARAMS ((dw_die_ref));
3458 static unsigned long size_of_string PARAMS ((const char *));
3459 static int constant_size PARAMS ((long unsigned));
3460 static unsigned long size_of_die PARAMS ((dw_die_ref));
3461 static void calc_die_sizes PARAMS ((dw_die_ref));
3462 static void mark_dies PARAMS ((dw_die_ref));
3463 static void unmark_dies PARAMS ((dw_die_ref));
3464 static unsigned long size_of_line_prolog PARAMS ((void));
3465 static unsigned long size_of_pubnames PARAMS ((void));
3466 static unsigned long size_of_aranges PARAMS ((void));
3467 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3468 static void output_value_format PARAMS ((dw_attr_ref));
3469 static void output_abbrev_section PARAMS ((void));
3470 static void output_die_symbol PARAMS ((dw_die_ref));
3471 static void output_symbolic_ref PARAMS ((dw_die_ref));
3472 static void output_die PARAMS ((dw_die_ref));
3473 static void output_compilation_unit_header PARAMS ((void));
3474 static void output_comp_unit PARAMS ((dw_die_ref));
3475 static const char *dwarf2_name PARAMS ((tree, int));
3476 static void add_pubname PARAMS ((tree, dw_die_ref));
3477 static void output_pubnames PARAMS ((void));
3478 static void add_arange PARAMS ((tree, dw_die_ref));
3479 static void output_aranges PARAMS ((void));
3480 static void output_line_info PARAMS ((void));
3481 static void output_file_names PARAMS ((void));
3482 static dw_die_ref base_type_die PARAMS ((tree));
3483 static tree root_type PARAMS ((tree));
3484 static int is_base_type PARAMS ((tree));
3485 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3486 static int type_is_enum PARAMS ((tree));
3487 static unsigned int reg_number PARAMS ((rtx));
3488 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3489 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3490 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3491 static int is_based_loc PARAMS ((rtx));
3492 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3493 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3494 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3495 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3496 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3497 static tree field_type PARAMS ((tree));
3498 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3499 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3500 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3501 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3502 static void add_AT_location_description PARAMS ((dw_die_ref,
3503 enum dwarf_attribute, rtx));
3504 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3505 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3506 static rtx rtl_for_decl_location PARAMS ((tree));
3507 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3508 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3509 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3510 static void add_bound_info PARAMS ((dw_die_ref,
3511 enum dwarf_attribute, tree));
3512 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3513 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3514 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3515 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3516 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3517 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3518 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3519 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3520 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3521 static void push_decl_scope PARAMS ((tree));
3522 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3523 static void pop_decl_scope PARAMS ((void));
3524 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3526 static const char *type_tag PARAMS ((tree));
3527 static tree member_declared_type PARAMS ((tree));
3529 static const char *decl_start_label PARAMS ((tree));
3531 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3532 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3534 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3536 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3537 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3538 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3539 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3540 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3541 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3542 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3543 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3544 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3545 static void gen_label_die PARAMS ((tree, dw_die_ref));
3546 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3547 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3548 static void gen_field_die PARAMS ((tree, dw_die_ref));
3549 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3550 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3551 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3552 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3553 static void gen_member_die PARAMS ((tree, dw_die_ref));
3554 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3555 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3556 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3557 static void gen_type_die PARAMS ((tree, dw_die_ref));
3558 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3559 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3560 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3561 static int is_redundant_typedef PARAMS ((tree));
3562 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3563 static unsigned lookup_filename PARAMS ((struct file_table *,
3565 static void init_file_table PARAMS ((struct file_table *));
3566 static void add_incomplete_type PARAMS ((tree));
3567 static void retry_incomplete_types PARAMS ((void));
3568 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3569 static void gen_abstract_function PARAMS ((tree));
3570 static rtx save_rtx PARAMS ((rtx));
3571 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3572 static int file_info_cmp PARAMS ((const void *, const void *));
3574 /* Section names used to hold DWARF debugging information. */
3575 #ifndef DEBUG_INFO_SECTION
3576 #define DEBUG_INFO_SECTION ".debug_info"
3578 #ifndef ABBREV_SECTION
3579 #define ABBREV_SECTION ".debug_abbrev"
3581 #ifndef ARANGES_SECTION
3582 #define ARANGES_SECTION ".debug_aranges"
3584 #ifndef DW_MACINFO_SECTION
3585 #define DW_MACINFO_SECTION ".debug_macinfo"
3587 #ifndef DEBUG_LINE_SECTION
3588 #define DEBUG_LINE_SECTION ".debug_line"
3591 #define LOC_SECTION ".debug_loc"
3593 #ifndef PUBNAMES_SECTION
3594 #define PUBNAMES_SECTION ".debug_pubnames"
3597 #define STR_SECTION ".debug_str"
3600 /* Standard ELF section names for compiled code and data. */
3601 #ifndef TEXT_SECTION
3602 #define TEXT_SECTION ".text"
3604 #ifndef DATA_SECTION
3605 #define DATA_SECTION ".data"
3608 #define BSS_SECTION ".bss"
3611 /* Labels we insert at beginning sections we can reference instead of
3612 the section names themselves. */
3614 #ifndef TEXT_SECTION_LABEL
3615 #define TEXT_SECTION_LABEL "Ltext"
3617 #ifndef DEBUG_LINE_SECTION_LABEL
3618 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3620 #ifndef DEBUG_INFO_SECTION_LABEL
3621 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3623 #ifndef ABBREV_SECTION_LABEL
3624 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3627 /* Definitions of defaults for formats and names of various special
3628 (artificial) labels which may be generated within this file (when the -g
3629 options is used and DWARF_DEBUGGING_INFO is in effect.
3630 If necessary, these may be overridden from within the tm.h file, but
3631 typically, overriding these defaults is unnecessary. */
3633 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3634 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3635 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3636 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3637 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3639 #ifndef TEXT_END_LABEL
3640 #define TEXT_END_LABEL "Letext"
3642 #ifndef DATA_END_LABEL
3643 #define DATA_END_LABEL "Ledata"
3645 #ifndef BSS_END_LABEL
3646 #define BSS_END_LABEL "Lebss"
3648 #ifndef BLOCK_BEGIN_LABEL
3649 #define BLOCK_BEGIN_LABEL "LBB"
3651 #ifndef BLOCK_END_LABEL
3652 #define BLOCK_END_LABEL "LBE"
3654 #ifndef BODY_BEGIN_LABEL
3655 #define BODY_BEGIN_LABEL "Lbb"
3657 #ifndef BODY_END_LABEL
3658 #define BODY_END_LABEL "Lbe"
3660 #ifndef LINE_CODE_LABEL
3661 #define LINE_CODE_LABEL "LM"
3663 #ifndef SEPARATE_LINE_CODE_LABEL
3664 #define SEPARATE_LINE_CODE_LABEL "LSM"
3667 /* We allow a language front-end to designate a function that is to be
3668 called to "demangle" any name before it it put into a DIE. */
3670 static const char *(*demangle_name_func) PARAMS ((const char *));
3673 dwarf2out_set_demangle_name_func (func)
3674 const char *(*func) PARAMS ((const char *));
3676 demangle_name_func = func;
3679 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3680 that means adding it to used_rtx_varray. If not, that means making
3681 a copy on the permanent_obstack. */
3687 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3692 /* Test if rtl node points to a pseudo register. */
3698 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3699 || (GET_CODE (rtl) == SUBREG
3700 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3703 /* Return a reference to a type, with its const and volatile qualifiers
3707 type_main_variant (type)
3710 type = TYPE_MAIN_VARIANT (type);
3712 /* There really should be only one main variant among any group of variants
3713 of a given type (and all of the MAIN_VARIANT values for all members of
3714 the group should point to that one type) but sometimes the C front-end
3715 messes this up for array types, so we work around that bug here. */
3717 if (TREE_CODE (type) == ARRAY_TYPE)
3718 while (type != TYPE_MAIN_VARIANT (type))
3719 type = TYPE_MAIN_VARIANT (type);
3724 /* Return non-zero if the given type node represents a tagged type. */
3727 is_tagged_type (type)
3730 register enum tree_code code = TREE_CODE (type);
3732 return (code == RECORD_TYPE || code == UNION_TYPE
3733 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3736 /* Convert a DIE tag into its string name. */
3739 dwarf_tag_name (tag)
3740 register unsigned tag;
3744 case DW_TAG_padding:
3745 return "DW_TAG_padding";
3746 case DW_TAG_array_type:
3747 return "DW_TAG_array_type";
3748 case DW_TAG_class_type:
3749 return "DW_TAG_class_type";
3750 case DW_TAG_entry_point:
3751 return "DW_TAG_entry_point";
3752 case DW_TAG_enumeration_type:
3753 return "DW_TAG_enumeration_type";
3754 case DW_TAG_formal_parameter:
3755 return "DW_TAG_formal_parameter";
3756 case DW_TAG_imported_declaration:
3757 return "DW_TAG_imported_declaration";
3759 return "DW_TAG_label";
3760 case DW_TAG_lexical_block:
3761 return "DW_TAG_lexical_block";
3763 return "DW_TAG_member";
3764 case DW_TAG_pointer_type:
3765 return "DW_TAG_pointer_type";
3766 case DW_TAG_reference_type:
3767 return "DW_TAG_reference_type";
3768 case DW_TAG_compile_unit:
3769 return "DW_TAG_compile_unit";
3770 case DW_TAG_string_type:
3771 return "DW_TAG_string_type";
3772 case DW_TAG_structure_type:
3773 return "DW_TAG_structure_type";
3774 case DW_TAG_subroutine_type:
3775 return "DW_TAG_subroutine_type";
3776 case DW_TAG_typedef:
3777 return "DW_TAG_typedef";
3778 case DW_TAG_union_type:
3779 return "DW_TAG_union_type";
3780 case DW_TAG_unspecified_parameters:
3781 return "DW_TAG_unspecified_parameters";
3782 case DW_TAG_variant:
3783 return "DW_TAG_variant";
3784 case DW_TAG_common_block:
3785 return "DW_TAG_common_block";
3786 case DW_TAG_common_inclusion:
3787 return "DW_TAG_common_inclusion";
3788 case DW_TAG_inheritance:
3789 return "DW_TAG_inheritance";
3790 case DW_TAG_inlined_subroutine:
3791 return "DW_TAG_inlined_subroutine";
3793 return "DW_TAG_module";
3794 case DW_TAG_ptr_to_member_type:
3795 return "DW_TAG_ptr_to_member_type";
3796 case DW_TAG_set_type:
3797 return "DW_TAG_set_type";
3798 case DW_TAG_subrange_type:
3799 return "DW_TAG_subrange_type";
3800 case DW_TAG_with_stmt:
3801 return "DW_TAG_with_stmt";
3802 case DW_TAG_access_declaration:
3803 return "DW_TAG_access_declaration";
3804 case DW_TAG_base_type:
3805 return "DW_TAG_base_type";
3806 case DW_TAG_catch_block:
3807 return "DW_TAG_catch_block";
3808 case DW_TAG_const_type:
3809 return "DW_TAG_const_type";
3810 case DW_TAG_constant:
3811 return "DW_TAG_constant";
3812 case DW_TAG_enumerator:
3813 return "DW_TAG_enumerator";
3814 case DW_TAG_file_type:
3815 return "DW_TAG_file_type";
3817 return "DW_TAG_friend";
3818 case DW_TAG_namelist:
3819 return "DW_TAG_namelist";
3820 case DW_TAG_namelist_item:
3821 return "DW_TAG_namelist_item";
3822 case DW_TAG_packed_type:
3823 return "DW_TAG_packed_type";
3824 case DW_TAG_subprogram:
3825 return "DW_TAG_subprogram";
3826 case DW_TAG_template_type_param:
3827 return "DW_TAG_template_type_param";
3828 case DW_TAG_template_value_param:
3829 return "DW_TAG_template_value_param";
3830 case DW_TAG_thrown_type:
3831 return "DW_TAG_thrown_type";
3832 case DW_TAG_try_block:
3833 return "DW_TAG_try_block";
3834 case DW_TAG_variant_part:
3835 return "DW_TAG_variant_part";
3836 case DW_TAG_variable:
3837 return "DW_TAG_variable";
3838 case DW_TAG_volatile_type:
3839 return "DW_TAG_volatile_type";
3840 case DW_TAG_MIPS_loop:
3841 return "DW_TAG_MIPS_loop";
3842 case DW_TAG_format_label:
3843 return "DW_TAG_format_label";
3844 case DW_TAG_function_template:
3845 return "DW_TAG_function_template";
3846 case DW_TAG_class_template:
3847 return "DW_TAG_class_template";
3848 case DW_TAG_GNU_BINCL:
3849 return "DW_TAG_GNU_BINCL";
3850 case DW_TAG_GNU_EINCL:
3851 return "DW_TAG_GNU_EINCL";
3853 return "DW_TAG_<unknown>";
3857 /* Convert a DWARF attribute code into its string name. */
3860 dwarf_attr_name (attr)
3861 register unsigned attr;
3866 return "DW_AT_sibling";
3867 case DW_AT_location:
3868 return "DW_AT_location";
3870 return "DW_AT_name";
3871 case DW_AT_ordering:
3872 return "DW_AT_ordering";
3873 case DW_AT_subscr_data:
3874 return "DW_AT_subscr_data";
3875 case DW_AT_byte_size:
3876 return "DW_AT_byte_size";
3877 case DW_AT_bit_offset:
3878 return "DW_AT_bit_offset";
3879 case DW_AT_bit_size:
3880 return "DW_AT_bit_size";
3881 case DW_AT_element_list:
3882 return "DW_AT_element_list";
3883 case DW_AT_stmt_list:
3884 return "DW_AT_stmt_list";
3886 return "DW_AT_low_pc";
3888 return "DW_AT_high_pc";
3889 case DW_AT_language:
3890 return "DW_AT_language";
3892 return "DW_AT_member";
3894 return "DW_AT_discr";
3895 case DW_AT_discr_value:
3896 return "DW_AT_discr_value";
3897 case DW_AT_visibility:
3898 return "DW_AT_visibility";
3900 return "DW_AT_import";
3901 case DW_AT_string_length:
3902 return "DW_AT_string_length";
3903 case DW_AT_common_reference:
3904 return "DW_AT_common_reference";
3905 case DW_AT_comp_dir:
3906 return "DW_AT_comp_dir";
3907 case DW_AT_const_value:
3908 return "DW_AT_const_value";
3909 case DW_AT_containing_type:
3910 return "DW_AT_containing_type";
3911 case DW_AT_default_value:
3912 return "DW_AT_default_value";
3914 return "DW_AT_inline";
3915 case DW_AT_is_optional:
3916 return "DW_AT_is_optional";
3917 case DW_AT_lower_bound:
3918 return "DW_AT_lower_bound";
3919 case DW_AT_producer:
3920 return "DW_AT_producer";
3921 case DW_AT_prototyped:
3922 return "DW_AT_prototyped";
3923 case DW_AT_return_addr:
3924 return "DW_AT_return_addr";
3925 case DW_AT_start_scope:
3926 return "DW_AT_start_scope";
3927 case DW_AT_stride_size:
3928 return "DW_AT_stride_size";
3929 case DW_AT_upper_bound:
3930 return "DW_AT_upper_bound";
3931 case DW_AT_abstract_origin:
3932 return "DW_AT_abstract_origin";
3933 case DW_AT_accessibility:
3934 return "DW_AT_accessibility";
3935 case DW_AT_address_class:
3936 return "DW_AT_address_class";
3937 case DW_AT_artificial:
3938 return "DW_AT_artificial";
3939 case DW_AT_base_types:
3940 return "DW_AT_base_types";
3941 case DW_AT_calling_convention:
3942 return "DW_AT_calling_convention";
3944 return "DW_AT_count";
3945 case DW_AT_data_member_location:
3946 return "DW_AT_data_member_location";
3947 case DW_AT_decl_column:
3948 return "DW_AT_decl_column";
3949 case DW_AT_decl_file:
3950 return "DW_AT_decl_file";
3951 case DW_AT_decl_line:
3952 return "DW_AT_decl_line";
3953 case DW_AT_declaration:
3954 return "DW_AT_declaration";
3955 case DW_AT_discr_list:
3956 return "DW_AT_discr_list";
3957 case DW_AT_encoding:
3958 return "DW_AT_encoding";
3959 case DW_AT_external:
3960 return "DW_AT_external";
3961 case DW_AT_frame_base:
3962 return "DW_AT_frame_base";
3964 return "DW_AT_friend";
3965 case DW_AT_identifier_case:
3966 return "DW_AT_identifier_case";
3967 case DW_AT_macro_info:
3968 return "DW_AT_macro_info";
3969 case DW_AT_namelist_items:
3970 return "DW_AT_namelist_items";
3971 case DW_AT_priority:
3972 return "DW_AT_priority";
3974 return "DW_AT_segment";
3975 case DW_AT_specification:
3976 return "DW_AT_specification";
3977 case DW_AT_static_link:
3978 return "DW_AT_static_link";
3980 return "DW_AT_type";
3981 case DW_AT_use_location:
3982 return "DW_AT_use_location";
3983 case DW_AT_variable_parameter:
3984 return "DW_AT_variable_parameter";
3985 case DW_AT_virtuality:
3986 return "DW_AT_virtuality";
3987 case DW_AT_vtable_elem_location:
3988 return "DW_AT_vtable_elem_location";
3990 case DW_AT_MIPS_fde:
3991 return "DW_AT_MIPS_fde";
3992 case DW_AT_MIPS_loop_begin:
3993 return "DW_AT_MIPS_loop_begin";
3994 case DW_AT_MIPS_tail_loop_begin:
3995 return "DW_AT_MIPS_tail_loop_begin";
3996 case DW_AT_MIPS_epilog_begin:
3997 return "DW_AT_MIPS_epilog_begin";
3998 case DW_AT_MIPS_loop_unroll_factor:
3999 return "DW_AT_MIPS_loop_unroll_factor";
4000 case DW_AT_MIPS_software_pipeline_depth:
4001 return "DW_AT_MIPS_software_pipeline_depth";
4002 case DW_AT_MIPS_linkage_name:
4003 return "DW_AT_MIPS_linkage_name";
4004 case DW_AT_MIPS_stride:
4005 return "DW_AT_MIPS_stride";
4006 case DW_AT_MIPS_abstract_name:
4007 return "DW_AT_MIPS_abstract_name";
4008 case DW_AT_MIPS_clone_origin:
4009 return "DW_AT_MIPS_clone_origin";
4010 case DW_AT_MIPS_has_inlines:
4011 return "DW_AT_MIPS_has_inlines";
4013 case DW_AT_sf_names:
4014 return "DW_AT_sf_names";
4015 case DW_AT_src_info:
4016 return "DW_AT_src_info";
4017 case DW_AT_mac_info:
4018 return "DW_AT_mac_info";
4019 case DW_AT_src_coords:
4020 return "DW_AT_src_coords";
4021 case DW_AT_body_begin:
4022 return "DW_AT_body_begin";
4023 case DW_AT_body_end:
4024 return "DW_AT_body_end";
4026 return "DW_AT_<unknown>";
4030 /* Convert a DWARF value form code into its string name. */
4033 dwarf_form_name (form)
4034 register unsigned form;
4039 return "DW_FORM_addr";
4040 case DW_FORM_block2:
4041 return "DW_FORM_block2";
4042 case DW_FORM_block4:
4043 return "DW_FORM_block4";
4045 return "DW_FORM_data2";
4047 return "DW_FORM_data4";
4049 return "DW_FORM_data8";
4050 case DW_FORM_string:
4051 return "DW_FORM_string";
4053 return "DW_FORM_block";
4054 case DW_FORM_block1:
4055 return "DW_FORM_block1";
4057 return "DW_FORM_data1";
4059 return "DW_FORM_flag";
4061 return "DW_FORM_sdata";
4063 return "DW_FORM_strp";
4065 return "DW_FORM_udata";
4066 case DW_FORM_ref_addr:
4067 return "DW_FORM_ref_addr";
4069 return "DW_FORM_ref1";
4071 return "DW_FORM_ref2";
4073 return "DW_FORM_ref4";
4075 return "DW_FORM_ref8";
4076 case DW_FORM_ref_udata:
4077 return "DW_FORM_ref_udata";
4078 case DW_FORM_indirect:
4079 return "DW_FORM_indirect";
4081 return "DW_FORM_<unknown>";
4085 /* Convert a DWARF type code into its string name. */
4089 dwarf_type_encoding_name (enc)
4090 register unsigned enc;
4094 case DW_ATE_address:
4095 return "DW_ATE_address";
4096 case DW_ATE_boolean:
4097 return "DW_ATE_boolean";
4098 case DW_ATE_complex_float:
4099 return "DW_ATE_complex_float";
4101 return "DW_ATE_float";
4103 return "DW_ATE_signed";
4104 case DW_ATE_signed_char:
4105 return "DW_ATE_signed_char";
4106 case DW_ATE_unsigned:
4107 return "DW_ATE_unsigned";
4108 case DW_ATE_unsigned_char:
4109 return "DW_ATE_unsigned_char";
4111 return "DW_ATE_<unknown>";
4116 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4117 instance of an inlined instance of a decl which is local to an inline
4118 function, so we have to trace all of the way back through the origin chain
4119 to find out what sort of node actually served as the original seed for the
4123 decl_ultimate_origin (decl)
4126 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4127 nodes in the function to point to themselves; ignore that if
4128 we're trying to output the abstract instance of this function. */
4129 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4132 #ifdef ENABLE_CHECKING
4133 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4134 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4135 most distant ancestor, this should never happen. */
4139 return DECL_ABSTRACT_ORIGIN (decl);
4142 /* Determine the "ultimate origin" of a block. The block may be an inlined
4143 instance of an inlined instance of a block which is local to an inline
4144 function, so we have to trace all of the way back through the origin chain
4145 to find out what sort of node actually served as the original seed for the
4149 block_ultimate_origin (block)
4150 register tree block;
4152 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4154 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4155 nodes in the function to point to themselves; ignore that if
4156 we're trying to output the abstract instance of this function. */
4157 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4160 if (immediate_origin == NULL_TREE)
4164 register tree ret_val;
4165 register tree lookahead = immediate_origin;
4169 ret_val = lookahead;
4170 lookahead = (TREE_CODE (ret_val) == BLOCK)
4171 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4174 while (lookahead != NULL && lookahead != ret_val);
4180 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4181 of a virtual function may refer to a base class, so we check the 'this'
4185 decl_class_context (decl)
4188 tree context = NULL_TREE;
4190 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4191 context = DECL_CONTEXT (decl);
4193 context = TYPE_MAIN_VARIANT
4194 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4196 if (context && !TYPE_P (context))
4197 context = NULL_TREE;
4202 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4203 addition order, and correct that in reverse_all_dies. */
4206 add_dwarf_attr (die, attr)
4207 register dw_die_ref die;
4208 register dw_attr_ref attr;
4210 if (die != NULL && attr != NULL)
4212 attr->dw_attr_next = die->die_attr;
4213 die->die_attr = attr;
4217 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4218 static inline dw_val_class
4222 return a->dw_attr_val.val_class;
4225 /* Add a flag value attribute to a DIE. */
4228 add_AT_flag (die, attr_kind, flag)
4229 register dw_die_ref die;
4230 register enum dwarf_attribute attr_kind;
4231 register unsigned flag;
4233 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4235 attr->dw_attr_next = NULL;
4236 attr->dw_attr = attr_kind;
4237 attr->dw_attr_val.val_class = dw_val_class_flag;
4238 attr->dw_attr_val.v.val_flag = flag;
4239 add_dwarf_attr (die, attr);
4242 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4243 static inline unsigned
4245 register dw_attr_ref a;
4247 if (a && AT_class (a) == dw_val_class_flag)
4248 return a->dw_attr_val.v.val_flag;
4253 /* Add a signed integer attribute value to a DIE. */
4256 add_AT_int (die, attr_kind, int_val)
4257 register dw_die_ref die;
4258 register enum dwarf_attribute attr_kind;
4259 register long int int_val;
4261 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4263 attr->dw_attr_next = NULL;
4264 attr->dw_attr = attr_kind;
4265 attr->dw_attr_val.val_class = dw_val_class_const;
4266 attr->dw_attr_val.v.val_int = int_val;
4267 add_dwarf_attr (die, attr);
4270 static inline long int AT_int PARAMS ((dw_attr_ref));
4271 static inline long int
4273 register dw_attr_ref a;
4275 if (a && AT_class (a) == dw_val_class_const)
4276 return a->dw_attr_val.v.val_int;
4281 /* Add an unsigned integer attribute value to a DIE. */
4284 add_AT_unsigned (die, attr_kind, unsigned_val)
4285 register dw_die_ref die;
4286 register enum dwarf_attribute attr_kind;
4287 register unsigned long unsigned_val;
4289 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4291 attr->dw_attr_next = NULL;
4292 attr->dw_attr = attr_kind;
4293 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4294 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4295 add_dwarf_attr (die, attr);
4298 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4299 static inline unsigned long
4301 register dw_attr_ref a;
4303 if (a && AT_class (a) == dw_val_class_unsigned_const)
4304 return a->dw_attr_val.v.val_unsigned;
4309 /* Add an unsigned double integer attribute value to a DIE. */
4312 add_AT_long_long (die, attr_kind, val_hi, val_low)
4313 register dw_die_ref die;
4314 register enum dwarf_attribute attr_kind;
4315 register unsigned long val_hi;
4316 register unsigned long val_low;
4318 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4320 attr->dw_attr_next = NULL;
4321 attr->dw_attr = attr_kind;
4322 attr->dw_attr_val.val_class = dw_val_class_long_long;
4323 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4324 attr->dw_attr_val.v.val_long_long.low = val_low;
4325 add_dwarf_attr (die, attr);
4328 /* Add a floating point attribute value to a DIE and return it. */
4331 add_AT_float (die, attr_kind, length, array)
4332 register dw_die_ref die;
4333 register enum dwarf_attribute attr_kind;
4334 register unsigned length;
4335 register long *array;
4337 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4339 attr->dw_attr_next = NULL;
4340 attr->dw_attr = attr_kind;
4341 attr->dw_attr_val.val_class = dw_val_class_float;
4342 attr->dw_attr_val.v.val_float.length = length;
4343 attr->dw_attr_val.v.val_float.array = array;
4344 add_dwarf_attr (die, attr);
4347 /* Add a string attribute value to a DIE. */
4350 add_AT_string (die, attr_kind, str)
4351 register dw_die_ref die;
4352 register enum dwarf_attribute attr_kind;
4353 register const char *str;
4355 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4357 attr->dw_attr_next = NULL;
4358 attr->dw_attr = attr_kind;
4359 attr->dw_attr_val.val_class = dw_val_class_str;
4360 attr->dw_attr_val.v.val_str = xstrdup (str);
4361 add_dwarf_attr (die, attr);
4364 static inline const char *AT_string PARAMS ((dw_attr_ref));
4365 static inline const char *
4367 register dw_attr_ref a;
4369 if (a && AT_class (a) == dw_val_class_str)
4370 return a->dw_attr_val.v.val_str;
4375 /* Add a DIE reference attribute value to a DIE. */
4378 add_AT_die_ref (die, attr_kind, targ_die)
4379 register dw_die_ref die;
4380 register enum dwarf_attribute attr_kind;
4381 register dw_die_ref targ_die;
4383 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4385 attr->dw_attr_next = NULL;
4386 attr->dw_attr = attr_kind;
4387 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4388 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4389 attr->dw_attr_val.v.val_die_ref.external = 0;
4390 add_dwarf_attr (die, attr);
4393 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4394 static inline dw_die_ref
4396 register dw_attr_ref a;
4398 if (a && AT_class (a) == dw_val_class_die_ref)
4399 return a->dw_attr_val.v.val_die_ref.die;
4404 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4407 register dw_attr_ref a;
4409 if (a && AT_class (a) == dw_val_class_die_ref)
4410 return a->dw_attr_val.v.val_die_ref.external;
4415 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4417 set_AT_ref_external (a, i)
4418 register dw_attr_ref a;
4421 if (a && AT_class (a) == dw_val_class_die_ref)
4422 a->dw_attr_val.v.val_die_ref.external = i;
4427 /* Add an FDE reference attribute value to a DIE. */
4430 add_AT_fde_ref (die, attr_kind, targ_fde)
4431 register dw_die_ref die;
4432 register enum dwarf_attribute attr_kind;
4433 register unsigned targ_fde;
4435 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4437 attr->dw_attr_next = NULL;
4438 attr->dw_attr = attr_kind;
4439 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4440 attr->dw_attr_val.v.val_fde_index = targ_fde;
4441 add_dwarf_attr (die, attr);
4444 /* Add a location description attribute value to a DIE. */
4447 add_AT_loc (die, attr_kind, loc)
4448 register dw_die_ref die;
4449 register enum dwarf_attribute attr_kind;
4450 register dw_loc_descr_ref loc;
4452 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4454 attr->dw_attr_next = NULL;
4455 attr->dw_attr = attr_kind;
4456 attr->dw_attr_val.val_class = dw_val_class_loc;
4457 attr->dw_attr_val.v.val_loc = loc;
4458 add_dwarf_attr (die, attr);
4461 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4462 static inline dw_loc_descr_ref
4464 register dw_attr_ref a;
4466 if (a && AT_class (a) == dw_val_class_loc)
4467 return a->dw_attr_val.v.val_loc;
4472 /* Add an address constant attribute value to a DIE. */
4475 add_AT_addr (die, attr_kind, addr)
4476 register dw_die_ref die;
4477 register enum dwarf_attribute attr_kind;
4480 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4482 attr->dw_attr_next = NULL;
4483 attr->dw_attr = attr_kind;
4484 attr->dw_attr_val.val_class = dw_val_class_addr;
4485 attr->dw_attr_val.v.val_addr = addr;
4486 add_dwarf_attr (die, attr);
4489 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4492 register dw_attr_ref a;
4494 if (a && AT_class (a) == dw_val_class_addr)
4495 return a->dw_attr_val.v.val_addr;
4500 /* Add a label identifier attribute value to a DIE. */
4503 add_AT_lbl_id (die, attr_kind, lbl_id)
4504 register dw_die_ref die;
4505 register enum dwarf_attribute attr_kind;
4506 register const char *lbl_id;
4508 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4510 attr->dw_attr_next = NULL;
4511 attr->dw_attr = attr_kind;
4512 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4513 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4514 add_dwarf_attr (die, attr);
4517 /* Add a section offset attribute value to a DIE. */
4520 add_AT_lbl_offset (die, attr_kind, label)
4521 register dw_die_ref die;
4522 register enum dwarf_attribute attr_kind;
4523 register const char *label;
4525 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4527 attr->dw_attr_next = NULL;
4528 attr->dw_attr = attr_kind;
4529 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4530 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4531 add_dwarf_attr (die, attr);
4534 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4535 static inline const char *
4537 register dw_attr_ref a;
4539 if (a && (AT_class (a) == dw_val_class_lbl_id
4540 || AT_class (a) == dw_val_class_lbl_offset))
4541 return a->dw_attr_val.v.val_lbl_id;
4546 /* Get the attribute of type attr_kind. */
4548 static inline dw_attr_ref
4549 get_AT (die, attr_kind)
4550 register dw_die_ref die;
4551 register enum dwarf_attribute attr_kind;
4553 register dw_attr_ref a;
4554 register dw_die_ref spec = NULL;
4558 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4560 if (a->dw_attr == attr_kind)
4563 if (a->dw_attr == DW_AT_specification
4564 || a->dw_attr == DW_AT_abstract_origin)
4569 return get_AT (spec, attr_kind);
4575 /* Return the "low pc" attribute value, typically associated with
4576 a subprogram DIE. Return null if the "low pc" attribute is
4577 either not prsent, or if it cannot be represented as an
4578 assembler label identifier. */
4580 static inline const char *
4582 register dw_die_ref die;
4584 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4585 return a ? AT_lbl (a) : NULL;
4588 /* Return the "high pc" attribute value, typically associated with
4589 a subprogram DIE. Return null if the "high pc" attribute is
4590 either not prsent, or if it cannot be represented as an
4591 assembler label identifier. */
4593 static inline const char *
4595 register dw_die_ref die;
4597 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4598 return a ? AT_lbl (a) : NULL;
4601 /* Return the value of the string attribute designated by ATTR_KIND, or
4602 NULL if it is not present. */
4604 static inline const char *
4605 get_AT_string (die, attr_kind)
4606 register dw_die_ref die;
4607 register enum dwarf_attribute attr_kind;
4609 register dw_attr_ref a = get_AT (die, attr_kind);
4610 return a ? AT_string (a) : NULL;
4613 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4614 if it is not present. */
4617 get_AT_flag (die, attr_kind)
4618 register dw_die_ref die;
4619 register enum dwarf_attribute attr_kind;
4621 register dw_attr_ref a = get_AT (die, attr_kind);
4622 return a ? AT_flag (a) : 0;
4625 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4626 if it is not present. */
4628 static inline unsigned
4629 get_AT_unsigned (die, attr_kind)
4630 register dw_die_ref die;
4631 register enum dwarf_attribute attr_kind;
4633 register dw_attr_ref a = get_AT (die, attr_kind);
4634 return a ? AT_unsigned (a) : 0;
4637 static inline dw_die_ref
4638 get_AT_ref (die, attr_kind)
4640 register enum dwarf_attribute attr_kind;
4642 register dw_attr_ref a = get_AT (die, attr_kind);
4643 return a ? AT_ref (a) : NULL;
4649 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4651 return (lang == DW_LANG_C || lang == DW_LANG_C89
4652 || lang == DW_LANG_C_plus_plus);
4658 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4660 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4666 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4668 return (lang == DW_LANG_Java);
4671 /* Free up the memory used by A. */
4673 static inline void free_AT PARAMS ((dw_attr_ref));
4678 switch (AT_class (a))
4680 case dw_val_class_str:
4681 case dw_val_class_lbl_id:
4682 case dw_val_class_lbl_offset:
4683 free (a->dw_attr_val.v.val_str);
4686 case dw_val_class_float:
4687 free (a->dw_attr_val.v.val_float.array);
4697 /* Remove the specified attribute if present. */
4700 remove_AT (die, attr_kind)
4701 register dw_die_ref die;
4702 register enum dwarf_attribute attr_kind;
4704 register dw_attr_ref *p;
4705 register dw_attr_ref removed = NULL;
4709 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4710 if ((*p)->dw_attr == attr_kind)
4713 *p = (*p)->dw_attr_next;
4722 /* Free up the memory used by DIE. */
4724 static inline void free_die PARAMS ((dw_die_ref));
4729 remove_children (die);
4733 /* Discard the children of this DIE. */
4736 remove_children (die)
4737 register dw_die_ref die;
4739 register dw_die_ref child_die = die->die_child;
4741 die->die_child = NULL;
4743 while (child_die != NULL)
4745 register dw_die_ref tmp_die = child_die;
4746 register dw_attr_ref a;
4748 child_die = child_die->die_sib;
4750 for (a = tmp_die->die_attr; a != NULL;)
4752 register dw_attr_ref tmp_a = a;
4754 a = a->dw_attr_next;
4762 /* Add a child DIE below its parent. We build the lists up in reverse
4763 addition order, and correct that in reverse_all_dies. */
4766 add_child_die (die, child_die)
4767 register dw_die_ref die;
4768 register dw_die_ref child_die;
4770 if (die != NULL && child_die != NULL)
4772 if (die == child_die)
4774 child_die->die_parent = die;
4775 child_die->die_sib = die->die_child;
4776 die->die_child = child_die;
4780 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4781 is the specification, to the front of PARENT's list of children. */
4784 splice_child_die (parent, child)
4785 dw_die_ref parent, child;
4789 /* We want the declaration DIE from inside the class, not the
4790 specification DIE at toplevel. */
4791 if (child->die_parent != parent)
4793 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4798 if (child->die_parent != parent
4799 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4802 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4805 *p = child->die_sib;
4809 child->die_sib = parent->die_child;
4810 parent->die_child = child;
4813 /* Return a pointer to a newly created DIE node. */
4815 static inline dw_die_ref
4816 new_die (tag_value, parent_die)
4817 register enum dwarf_tag tag_value;
4818 register dw_die_ref parent_die;
4820 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4822 die->die_tag = tag_value;
4823 die->die_abbrev = 0;
4824 die->die_offset = 0;
4825 die->die_child = NULL;
4826 die->die_parent = NULL;
4827 die->die_sib = NULL;
4828 die->die_attr = NULL;
4829 die->die_symbol = NULL;
4831 if (parent_die != NULL)
4832 add_child_die (parent_die, die);
4835 limbo_die_node *limbo_node;
4837 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4838 limbo_node->die = die;
4839 limbo_node->next = limbo_die_list;
4840 limbo_die_list = limbo_node;
4846 /* Return the DIE associated with the given type specifier. */
4848 static inline dw_die_ref
4849 lookup_type_die (type)
4852 if (TREE_CODE (type) == VECTOR_TYPE)
4853 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4854 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4857 /* Equate a DIE to a given type specifier. */
4860 equate_type_number_to_die (type, type_die)
4862 register dw_die_ref type_die;
4864 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4867 /* Return the DIE associated with a given declaration. */
4869 static inline dw_die_ref
4870 lookup_decl_die (decl)
4873 register unsigned decl_id = DECL_UID (decl);
4875 return (decl_id < decl_die_table_in_use
4876 ? decl_die_table[decl_id] : NULL);
4879 /* Equate a DIE to a particular declaration. */
4882 equate_decl_number_to_die (decl, decl_die)
4884 register dw_die_ref decl_die;
4886 register unsigned decl_id = DECL_UID (decl);
4887 register unsigned num_allocated;
4889 if (decl_id >= decl_die_table_allocated)
4892 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4893 / DECL_DIE_TABLE_INCREMENT)
4894 * DECL_DIE_TABLE_INCREMENT;
4897 = (dw_die_ref *) xrealloc (decl_die_table,
4898 sizeof (dw_die_ref) * num_allocated);
4900 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
4901 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4902 decl_die_table_allocated = num_allocated;
4905 if (decl_id >= decl_die_table_in_use)
4906 decl_die_table_in_use = (decl_id + 1);
4908 decl_die_table[decl_id] = decl_die;
4911 /* Keep track of the number of spaces used to indent the
4912 output of the debugging routines that print the structure of
4913 the DIE internal representation. */
4914 static int print_indent;
4916 /* Indent the line the number of spaces given by print_indent. */
4919 print_spaces (outfile)
4922 fprintf (outfile, "%*s", print_indent, "");
4925 /* Print the information associated with a given DIE, and its children.
4926 This routine is a debugging aid only. */
4929 print_die (die, outfile)
4933 register dw_attr_ref a;
4934 register dw_die_ref c;
4936 print_spaces (outfile);
4937 fprintf (outfile, "DIE %4lu: %s\n",
4938 die->die_offset, dwarf_tag_name (die->die_tag));
4939 print_spaces (outfile);
4940 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4941 fprintf (outfile, " offset: %lu\n", die->die_offset);
4943 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4945 print_spaces (outfile);
4946 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4948 switch (AT_class (a))
4950 case dw_val_class_addr:
4951 fprintf (outfile, "address");
4953 case dw_val_class_loc:
4954 fprintf (outfile, "location descriptor");
4956 case dw_val_class_const:
4957 fprintf (outfile, "%ld", AT_int (a));
4959 case dw_val_class_unsigned_const:
4960 fprintf (outfile, "%lu", AT_unsigned (a));
4962 case dw_val_class_long_long:
4963 fprintf (outfile, "constant (%lu,%lu)",
4964 a->dw_attr_val.v.val_long_long.hi,
4965 a->dw_attr_val.v.val_long_long.low);
4967 case dw_val_class_float:
4968 fprintf (outfile, "floating-point constant");
4970 case dw_val_class_flag:
4971 fprintf (outfile, "%u", AT_flag (a));
4973 case dw_val_class_die_ref:
4974 if (AT_ref (a) != NULL)
4976 if (AT_ref (a)->die_symbol)
4977 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
4979 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4982 fprintf (outfile, "die -> <null>");
4984 case dw_val_class_lbl_id:
4985 case dw_val_class_lbl_offset:
4986 fprintf (outfile, "label: %s", AT_lbl (a));
4988 case dw_val_class_str:
4989 if (AT_string (a) != NULL)
4990 fprintf (outfile, "\"%s\"", AT_string (a));
4992 fprintf (outfile, "<null>");
4998 fprintf (outfile, "\n");
5001 if (die->die_child != NULL)
5004 for (c = die->die_child; c != NULL; c = c->die_sib)
5005 print_die (c, outfile);
5009 if (print_indent == 0)
5010 fprintf (outfile, "\n");
5013 /* Print the contents of the source code line number correspondence table.
5014 This routine is a debugging aid only. */
5017 print_dwarf_line_table (outfile)
5020 register unsigned i;
5021 register dw_line_info_ref line_info;
5023 fprintf (outfile, "\n\nDWARF source line information\n");
5024 for (i = 1; i < line_info_table_in_use; ++i)
5026 line_info = &line_info_table[i];
5027 fprintf (outfile, "%5d: ", i);
5028 fprintf (outfile, "%-20s", line_file_table.table[line_info->dw_file_num]);
5029 fprintf (outfile, "%6ld", line_info->dw_line_num);
5030 fprintf (outfile, "\n");
5033 fprintf (outfile, "\n\n");
5036 /* Print the information collected for a given DIE. */
5039 debug_dwarf_die (die)
5042 print_die (die, stderr);
5045 /* Print all DWARF information collected for the compilation unit.
5046 This routine is a debugging aid only. */
5052 print_die (comp_unit_die, stderr);
5053 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5054 print_dwarf_line_table (stderr);
5057 /* We build up the lists of children and attributes by pushing new ones
5058 onto the beginning of the list. Reverse the lists for DIE so that
5059 they are in order of addition. */
5062 reverse_die_lists (die)
5063 register dw_die_ref die;
5065 register dw_die_ref c, cp, cn;
5066 register dw_attr_ref a, ap, an;
5068 for (a = die->die_attr, ap = 0; a; a = an)
5070 an = a->dw_attr_next;
5071 a->dw_attr_next = ap;
5076 for (c = die->die_child, cp = 0; c; c = cn)
5082 die->die_child = cp;
5085 /* reverse_die_lists only reverses the single die you pass it. Since
5086 we used to reverse all dies in add_sibling_attributes, which runs
5087 through all the dies, it would reverse all the dies. Now, however,
5088 since we don't call reverse_die_lists in add_sibling_attributes, we
5089 need a routine to recursively reverse all the dies. This is that
5093 reverse_all_dies (die)
5094 register dw_die_ref die;
5096 register dw_die_ref c;
5098 reverse_die_lists (die);
5100 for (c = die->die_child; c; c = c->die_sib)
5101 reverse_all_dies (c);
5104 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5105 the CU for the enclosing include file, if any. BINCL_DIE is the
5106 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5110 push_new_compile_unit (old_unit, bincl_die)
5111 dw_die_ref old_unit, bincl_die;
5113 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5114 dw_die_ref new_unit = gen_compile_unit_die (filename);
5115 new_unit->die_sib = old_unit;
5119 /* Close an include-file CU and reopen the enclosing one. */
5122 pop_compile_unit (old_unit)
5123 dw_die_ref old_unit;
5125 dw_die_ref new_unit = old_unit->die_sib;
5126 old_unit->die_sib = NULL;
5130 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5131 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5133 /* Calculate the checksum of a location expression. */
5136 loc_checksum (loc, ctx)
5137 dw_loc_descr_ref loc;
5138 struct md5_ctx *ctx;
5140 PROCESS (loc->dw_loc_opc);
5141 PROCESS (loc->dw_loc_oprnd1);
5142 PROCESS (loc->dw_loc_oprnd2);
5145 /* Calculate the checksum of an attribute. */
5148 attr_checksum (at, ctx)
5150 struct md5_ctx *ctx;
5152 dw_loc_descr_ref loc;
5155 PROCESS (at->dw_attr);
5157 /* We don't care about differences in file numbering. */
5158 if (at->dw_attr == DW_AT_decl_file
5159 /* Or that this was compiled with a different compiler snapshot; if
5160 the output is the same, that's what matters. */
5161 || at->dw_attr == DW_AT_producer)
5164 switch (AT_class (at))
5166 case dw_val_class_const:
5167 PROCESS (at->dw_attr_val.v.val_int);
5169 case dw_val_class_unsigned_const:
5170 PROCESS (at->dw_attr_val.v.val_unsigned);
5172 case dw_val_class_long_long:
5173 PROCESS (at->dw_attr_val.v.val_long_long);
5175 case dw_val_class_float:
5176 PROCESS (at->dw_attr_val.v.val_float);
5178 case dw_val_class_flag:
5179 PROCESS (at->dw_attr_val.v.val_flag);
5182 case dw_val_class_str:
5183 PROCESS_STRING (AT_string (at));
5185 case dw_val_class_addr:
5187 switch (GET_CODE (r))
5190 PROCESS_STRING (XSTR (r, 0));
5198 case dw_val_class_loc:
5199 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5200 loc_checksum (loc, ctx);
5203 case dw_val_class_die_ref:
5204 if (AT_ref (at)->die_offset)
5205 PROCESS (AT_ref (at)->die_offset);
5206 /* FIXME else use target die name or something. */
5208 case dw_val_class_fde_ref:
5209 case dw_val_class_lbl_id:
5210 case dw_val_class_lbl_offset:
5217 /* Calculate the checksum of a DIE. */
5220 die_checksum (die, ctx)
5222 struct md5_ctx *ctx;
5227 PROCESS (die->die_tag);
5229 for (a = die->die_attr; a; a = a->dw_attr_next)
5230 attr_checksum (a, ctx);
5232 for (c = die->die_child; c; c = c->die_sib)
5233 die_checksum (c, ctx);
5237 #undef PROCESS_STRING
5239 /* The prefix to attach to symbols on DIEs in the current comdat debug
5241 static char *comdat_symbol_id;
5243 /* The index of the current symbol within the current comdat CU. */
5244 static unsigned int comdat_symbol_number;
5246 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5247 children, and set comdat_symbol_id accordingly. */
5250 compute_section_prefix (unit_die)
5251 dw_die_ref unit_die;
5255 unsigned char checksum[16];
5258 md5_init_ctx (&ctx);
5259 die_checksum (unit_die, &ctx);
5260 md5_finish_ctx (&ctx, checksum);
5262 p = file_name_nondirectory (get_AT_string (unit_die, DW_AT_name));
5263 name = (char *) alloca (strlen (p) + 64);
5264 sprintf (name, "%s.", p);
5266 clean_symbol_name (name);
5268 p = name + strlen (name);
5269 for (i = 0; i < 4; ++i)
5271 sprintf (p, "%.2x", checksum[i]);
5275 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5276 comdat_symbol_number = 0;
5279 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5285 switch (die->die_tag)
5287 case DW_TAG_array_type:
5288 case DW_TAG_class_type:
5289 case DW_TAG_enumeration_type:
5290 case DW_TAG_pointer_type:
5291 case DW_TAG_reference_type:
5292 case DW_TAG_string_type:
5293 case DW_TAG_structure_type:
5294 case DW_TAG_subroutine_type:
5295 case DW_TAG_union_type:
5296 case DW_TAG_ptr_to_member_type:
5297 case DW_TAG_set_type:
5298 case DW_TAG_subrange_type:
5299 case DW_TAG_base_type:
5300 case DW_TAG_const_type:
5301 case DW_TAG_file_type:
5302 case DW_TAG_packed_type:
5303 case DW_TAG_volatile_type:
5310 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5311 Basically, we want to choose the bits that are likely to be shared between
5312 compilations (types) and leave out the bits that are specific to individual
5313 compilations (functions). */
5320 /* I think we want to leave base types and __vtbl_ptr_type in the
5321 main CU, as we do for stabs. The advantage is a greater
5322 likelihood of sharing between objects that don't include headers
5323 in the same order (and therefore would put the base types in a
5324 different comdat). jason 8/28/00 */
5325 if (c->die_tag == DW_TAG_base_type)
5328 if (c->die_tag == DW_TAG_pointer_type
5329 || c->die_tag == DW_TAG_reference_type
5330 || c->die_tag == DW_TAG_const_type
5331 || c->die_tag == DW_TAG_volatile_type)
5333 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5334 return t ? is_comdat_die (t) : 0;
5338 return is_type_die (c);
5341 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5342 compilation unit. */
5348 if (is_type_die (c))
5350 if (get_AT (c, DW_AT_declaration)
5351 && ! get_AT (c, DW_AT_specification))
5360 static int label_num;
5361 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5362 return xstrdup (buf);
5365 /* Assign symbols to all worthy DIEs under DIE. */
5368 assign_symbol_names (die)
5369 register dw_die_ref die;
5371 register dw_die_ref c;
5373 if (is_symbol_die (die))
5375 if (comdat_symbol_id)
5377 char *p = alloca (strlen (comdat_symbol_id) + 64);
5378 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5379 comdat_symbol_id, comdat_symbol_number++);
5380 die->die_symbol = xstrdup (p);
5383 die->die_symbol = gen_internal_sym ();
5386 for (c = die->die_child; c != NULL; c = c->die_sib)
5387 assign_symbol_names (c);
5390 /* Traverse the DIE (which is always comp_unit_die), and set up
5391 additional compilation units for each of the include files we see
5392 bracketed by BINCL/EINCL. */
5395 break_out_includes (die)
5396 register dw_die_ref die;
5399 register dw_die_ref unit = NULL;
5400 limbo_die_node *node;
5402 for (ptr = &(die->die_child); *ptr; )
5404 register dw_die_ref c = *ptr;
5406 if (c->die_tag == DW_TAG_GNU_BINCL
5407 || c->die_tag == DW_TAG_GNU_EINCL
5408 || (unit && is_comdat_die (c)))
5410 /* This DIE is for a secondary CU; remove it from the main one. */
5413 if (c->die_tag == DW_TAG_GNU_BINCL)
5415 unit = push_new_compile_unit (unit, c);
5418 else if (c->die_tag == DW_TAG_GNU_EINCL)
5420 unit = pop_compile_unit (unit);
5424 add_child_die (unit, c);
5428 /* Leave this DIE in the main CU. */
5429 ptr = &(c->die_sib);
5435 /* We can only use this in debugging, since the frontend doesn't check
5436 to make sure that we leave every include file we enter. */
5441 assign_symbol_names (die);
5442 for (node = limbo_die_list; node; node = node->next)
5444 compute_section_prefix (node->die);
5445 assign_symbol_names (node->die);
5449 /* Traverse the DIE and add a sibling attribute if it may have the
5450 effect of speeding up access to siblings. To save some space,
5451 avoid generating sibling attributes for DIE's without children. */
5454 add_sibling_attributes (die)
5455 register dw_die_ref die;
5457 register dw_die_ref c;
5459 if (die->die_tag != DW_TAG_compile_unit
5460 && die->die_sib && die->die_child != NULL)
5461 /* Add the sibling link to the front of the attribute list. */
5462 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5464 for (c = die->die_child; c != NULL; c = c->die_sib)
5465 add_sibling_attributes (c);
5468 /* The format of each DIE (and its attribute value pairs)
5469 is encoded in an abbreviation table. This routine builds the
5470 abbreviation table and assigns a unique abbreviation id for
5471 each abbreviation entry. The children of each die are visited
5475 build_abbrev_table (die)
5476 register dw_die_ref die;
5478 register unsigned long abbrev_id;
5479 register unsigned long n_alloc;
5480 register dw_die_ref c;
5481 register dw_attr_ref d_attr, a_attr;
5483 /* Scan the DIE references, and mark as external any that refer to
5484 DIEs from other CUs (i.e. those which are not marked). */
5485 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5487 if (AT_class (d_attr) == dw_val_class_die_ref
5488 && AT_ref (d_attr)->die_mark == 0)
5490 if (AT_ref (d_attr)->die_symbol == 0)
5492 set_AT_ref_external (d_attr, 1);
5496 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5498 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5500 if (abbrev->die_tag == die->die_tag)
5502 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5504 a_attr = abbrev->die_attr;
5505 d_attr = die->die_attr;
5507 while (a_attr != NULL && d_attr != NULL)
5509 if ((a_attr->dw_attr != d_attr->dw_attr)
5510 || (value_format (a_attr) != value_format (d_attr)))
5513 a_attr = a_attr->dw_attr_next;
5514 d_attr = d_attr->dw_attr_next;
5517 if (a_attr == NULL && d_attr == NULL)
5523 if (abbrev_id >= abbrev_die_table_in_use)
5525 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5527 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5529 = (dw_die_ref *) xrealloc (abbrev_die_table,
5530 sizeof (dw_die_ref) * n_alloc);
5532 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5533 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5534 abbrev_die_table_allocated = n_alloc;
5537 ++abbrev_die_table_in_use;
5538 abbrev_die_table[abbrev_id] = die;
5541 die->die_abbrev = abbrev_id;
5542 for (c = die->die_child; c != NULL; c = c->die_sib)
5543 build_abbrev_table (c);
5546 /* Return the size of a string, including the null byte.
5548 This used to treat backslashes as escapes, and hence they were not included
5549 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5550 which treats a backslash as a backslash, escaping it if necessary, and hence
5551 we must include them in the count. */
5553 static unsigned long
5554 size_of_string (str)
5555 register const char *str;
5557 return strlen (str) + 1;
5560 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5563 constant_size (value)
5564 long unsigned value;
5571 log = floor_log2 (value);
5574 log = 1 << (floor_log2 (log) + 1);
5579 /* Return the size of a DIE, as it is represented in the
5580 .debug_info section. */
5582 static unsigned long
5584 register dw_die_ref die;
5586 register unsigned long size = 0;
5587 register dw_attr_ref a;
5589 size += size_of_uleb128 (die->die_abbrev);
5590 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5592 switch (AT_class (a))
5594 case dw_val_class_addr:
5595 size += DWARF2_ADDR_SIZE;
5597 case dw_val_class_loc:
5599 register unsigned long lsize = size_of_locs (AT_loc (a));
5602 size += constant_size (lsize);
5606 case dw_val_class_const:
5607 size += size_of_sleb128 (AT_int (a));
5609 case dw_val_class_unsigned_const:
5610 size += constant_size (AT_unsigned (a));
5612 case dw_val_class_long_long:
5613 size += 1 + 8; /* block */
5615 case dw_val_class_float:
5616 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5618 case dw_val_class_flag:
5621 case dw_val_class_die_ref:
5622 size += DWARF_OFFSET_SIZE;
5624 case dw_val_class_fde_ref:
5625 size += DWARF_OFFSET_SIZE;
5627 case dw_val_class_lbl_id:
5628 size += DWARF2_ADDR_SIZE;
5630 case dw_val_class_lbl_offset:
5631 size += DWARF_OFFSET_SIZE;
5633 case dw_val_class_str:
5634 size += size_of_string (AT_string (a));
5644 /* Size the debugging information associated with a given DIE.
5645 Visits the DIE's children recursively. Updates the global
5646 variable next_die_offset, on each time through. Uses the
5647 current value of next_die_offset to update the die_offset
5648 field in each DIE. */
5651 calc_die_sizes (die)
5654 register dw_die_ref c;
5655 die->die_offset = next_die_offset;
5656 next_die_offset += size_of_die (die);
5658 for (c = die->die_child; c != NULL; c = c->die_sib)
5661 if (die->die_child != NULL)
5662 /* Count the null byte used to terminate sibling lists. */
5663 next_die_offset += 1;
5666 /* Set the marks for a die and its children. We do this so
5667 that we know whether or not a reference needs to use FORM_ref_addr; only
5668 DIEs in the same CU will be marked. We used to clear out the offset
5669 and use that as the flag, but ran into ordering problems. */
5675 register dw_die_ref c;
5677 for (c = die->die_child; c; c = c->die_sib)
5681 /* Clear the marks for a die and its children. */
5687 register dw_die_ref c;
5689 for (c = die->die_child; c; c = c->die_sib)
5693 /* Return the size of the line information prolog generated for the
5694 compilation unit. */
5696 static unsigned long
5697 size_of_line_prolog ()
5699 register unsigned long size;
5700 register unsigned long ft_index;
5702 size = DWARF_LINE_PROLOG_HEADER_SIZE;
5704 /* Count the size of the table giving number of args for each
5706 size += DWARF_LINE_OPCODE_BASE - 1;
5708 /* Include directory table is empty (at present). Count only the
5709 null byte used to terminate the table. */
5712 for (ft_index = 1; ft_index < decl_file_table.in_use; ++ft_index)
5714 /* File name entry. */
5715 size += size_of_string (decl_file_table.table[ft_index]);
5717 /* Include directory index. */
5718 size += size_of_uleb128 (0);
5720 /* Modification time. */
5721 size += size_of_uleb128 (0);
5723 /* File length in bytes. */
5724 size += size_of_uleb128 (0);
5727 /* Count the file table terminator. */
5732 /* Return the size of the .debug_pubnames table generated for the
5733 compilation unit. */
5735 static unsigned long
5738 register unsigned long size;
5739 register unsigned i;
5741 size = DWARF_PUBNAMES_HEADER_SIZE;
5742 for (i = 0; i < pubname_table_in_use; ++i)
5744 register pubname_ref p = &pubname_table[i];
5745 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5748 size += DWARF_OFFSET_SIZE;
5752 /* Return the size of the information in the .debug_aranges section. */
5754 static unsigned long
5757 register unsigned long size;
5759 size = DWARF_ARANGES_HEADER_SIZE;
5761 /* Count the address/length pair for this compilation unit. */
5762 size += 2 * DWARF2_ADDR_SIZE;
5763 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5765 /* Count the two zero words used to terminated the address range table. */
5766 size += 2 * DWARF2_ADDR_SIZE;
5770 /* Select the encoding of an attribute value. */
5772 static enum dwarf_form
5776 switch (a->dw_attr_val.val_class)
5778 case dw_val_class_addr:
5779 return DW_FORM_addr;
5780 case dw_val_class_loc:
5781 switch (constant_size (size_of_locs (AT_loc (a))))
5784 return DW_FORM_block1;
5786 return DW_FORM_block2;
5790 case dw_val_class_const:
5791 return DW_FORM_sdata;
5792 case dw_val_class_unsigned_const:
5793 switch (constant_size (AT_unsigned (a)))
5796 return DW_FORM_data1;
5798 return DW_FORM_data2;
5800 return DW_FORM_data4;
5802 return DW_FORM_data8;
5806 case dw_val_class_long_long:
5807 return DW_FORM_block1;
5808 case dw_val_class_float:
5809 return DW_FORM_block1;
5810 case dw_val_class_flag:
5811 return DW_FORM_flag;
5812 case dw_val_class_die_ref:
5813 if (AT_ref_external (a))
5814 return DW_FORM_ref_addr;
5817 case dw_val_class_fde_ref:
5818 return DW_FORM_data;
5819 case dw_val_class_lbl_id:
5820 return DW_FORM_addr;
5821 case dw_val_class_lbl_offset:
5822 return DW_FORM_data;
5823 case dw_val_class_str:
5824 return DW_FORM_string;
5830 /* Output the encoding of an attribute value. */
5833 output_value_format (a)
5836 enum dwarf_form form = value_format (a);
5838 output_uleb128 (form);
5840 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
5842 fputc ('\n', asm_out_file);
5845 /* Output the .debug_abbrev section which defines the DIE abbreviation
5849 output_abbrev_section ()
5851 unsigned long abbrev_id;
5854 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5856 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5858 output_uleb128 (abbrev_id);
5860 fprintf (asm_out_file, " (abbrev code)");
5862 fputc ('\n', asm_out_file);
5863 output_uleb128 (abbrev->die_tag);
5865 fprintf (asm_out_file, " (TAG: %s)",
5866 dwarf_tag_name (abbrev->die_tag));
5868 fputc ('\n', asm_out_file);
5869 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP,
5870 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
5873 fprintf (asm_out_file, "\t%s %s",
5875 (abbrev->die_child != NULL
5876 ? "DW_children_yes" : "DW_children_no"));
5878 fputc ('\n', asm_out_file);
5880 for (a_attr = abbrev->die_attr; a_attr != NULL;
5881 a_attr = a_attr->dw_attr_next)
5883 output_uleb128 (a_attr->dw_attr);
5885 fprintf (asm_out_file, " (%s)",
5886 dwarf_attr_name (a_attr->dw_attr));
5888 fputc ('\n', asm_out_file);
5889 output_value_format (a_attr);
5892 fprintf (asm_out_file, "%s0,0\n", ASM_BYTE_OP);
5895 /* Terminate the table. */
5896 fprintf (asm_out_file, "%s0\n", ASM_BYTE_OP);
5899 /* Output a symbol we can use to refer to this DIE from another CU. */
5902 output_die_symbol (die)
5903 register dw_die_ref die;
5905 char *sym = die->die_symbol;
5910 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5911 /* We make these global, not weak; if the target doesn't support
5912 .linkonce, it doesn't support combining the sections, so debugging
5914 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5915 ASM_OUTPUT_LABEL (asm_out_file, sym);
5918 /* Output a symbolic (i.e. FORM_ref_addr) reference to TARGET_DIE. */
5921 output_symbolic_ref (target_die)
5922 dw_die_ref target_die;
5924 char *sym = target_die->die_symbol;
5929 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, sym);
5932 /* Output the DIE and its attributes. Called recursively to generate
5933 the definitions of each child DIE. */
5937 register dw_die_ref die;
5939 register dw_attr_ref a;
5940 register dw_die_ref c;
5941 register unsigned long size;
5943 /* If someone in another CU might refer to us, set up a symbol for
5944 them to point to. */
5945 if (die->die_symbol)
5946 output_die_symbol (die);
5948 output_uleb128 (die->die_abbrev);
5950 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5951 die->die_offset, dwarf_tag_name (die->die_tag));
5953 fputc ('\n', asm_out_file);
5955 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5957 switch (AT_class (a))
5959 case dw_val_class_addr:
5960 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
5963 case dw_val_class_loc:
5964 size = size_of_locs (AT_loc (a));
5966 /* Output the block length for this list of location operations. */
5967 switch (constant_size (size))
5970 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5973 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5980 fprintf (asm_out_file, "\t%s %s",
5981 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5983 fputc ('\n', asm_out_file);
5985 output_loc_sequence (AT_loc (a));
5988 case dw_val_class_const:
5989 /* ??? It would be slightly more efficient to use a scheme like is
5990 used for unsigned constants below, but gdb 4.x does not sign
5991 extend. Gdb 5.x does sign extend. */
5992 output_sleb128 (AT_int (a));
5995 case dw_val_class_unsigned_const:
5996 switch (constant_size (AT_unsigned (a)))
5999 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
6002 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
6005 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
6008 ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a));
6015 case dw_val_class_long_long:
6016 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
6018 fprintf (asm_out_file, "\t%s %s",
6019 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6021 fputc ('\n', asm_out_file);
6022 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file,
6023 a->dw_attr_val.v.val_long_long.hi,
6024 a->dw_attr_val.v.val_long_long.low);
6027 fprintf (asm_out_file,
6028 "\t%s long long constant", ASM_COMMENT_START);
6030 fputc ('\n', asm_out_file);
6033 case dw_val_class_float:
6035 register unsigned int i;
6036 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6037 a->dw_attr_val.v.val_float.length * 4);
6039 fprintf (asm_out_file, "\t%s %s",
6040 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6042 fputc ('\n', asm_out_file);
6043 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6045 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
6046 a->dw_attr_val.v.val_float.array[i]);
6048 fprintf (asm_out_file, "\t%s fp constant word %u",
6049 ASM_COMMENT_START, i);
6051 fputc ('\n', asm_out_file);
6056 case dw_val_class_flag:
6057 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
6060 case dw_val_class_die_ref:
6061 if (AT_ref_external (a))
6062 output_symbolic_ref (AT_ref (a));
6064 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
6067 case dw_val_class_fde_ref:
6070 ASM_GENERATE_INTERNAL_LABEL
6071 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
6072 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
6073 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
6077 case dw_val_class_lbl_id:
6078 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
6081 case dw_val_class_lbl_offset:
6082 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
6085 case dw_val_class_str:
6087 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
6089 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
6090 (int) strlen (AT_string (a)) + 1);
6097 if (AT_class (a) != dw_val_class_loc
6098 && AT_class (a) != dw_val_class_long_long
6099 && AT_class (a) != dw_val_class_float)
6102 fprintf (asm_out_file, "\t%s %s",
6103 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6105 fputc ('\n', asm_out_file);
6109 for (c = die->die_child; c != NULL; c = c->die_sib)
6112 if (die->die_child != NULL)
6114 /* Add null byte to terminate sibling list. */
6115 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6117 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
6118 ASM_COMMENT_START, die->die_offset);
6120 fputc ('\n', asm_out_file);
6124 /* Output the compilation unit that appears at the beginning of the
6125 .debug_info section, and precedes the DIE descriptions. */
6128 output_compilation_unit_header ()
6130 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
6132 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
6135 fputc ('\n', asm_out_file);
6136 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6138 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
6140 fputc ('\n', asm_out_file);
6141 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
6143 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
6146 fputc ('\n', asm_out_file);
6147 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6149 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
6151 fputc ('\n', asm_out_file);
6154 /* Output the compilation unit DIE and its children. */
6157 output_comp_unit (die)
6160 const char *secname;
6162 if (die->die_child == 0)
6165 /* Mark all the DIEs in this CU so we know which get local refs. */
6168 build_abbrev_table (die);
6170 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6171 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6172 calc_die_sizes (die);
6174 if (die->die_symbol)
6176 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6177 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6179 die->die_symbol = NULL;
6182 secname = (const char *) DEBUG_INFO_SECTION;
6184 /* Output debugging information. */
6185 fputc ('\n', asm_out_file);
6186 ASM_OUTPUT_SECTION (asm_out_file, secname);
6187 output_compilation_unit_header ();
6190 /* Leave the marks on the main CU, so we can check them in
6192 if (die->die_symbol)
6196 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6197 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6198 argument list, and maybe the scope. */
6201 dwarf2_name (decl, scope)
6205 return (*decl_printable_name) (decl, scope ? 1 : 0);
6208 /* Add a new entry to .debug_pubnames if appropriate. */
6211 add_pubname (decl, die)
6217 if (! TREE_PUBLIC (decl))
6220 if (pubname_table_in_use == pubname_table_allocated)
6222 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6223 pubname_table = (pubname_ref) xrealloc
6224 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6227 p = &pubname_table[pubname_table_in_use++];
6230 p->name = xstrdup (dwarf2_name (decl, 1));
6233 /* Output the public names table used to speed up access to externally
6234 visible names. For now, only generate entries for externally
6235 visible procedures. */
6240 register unsigned i;
6241 register unsigned long pubnames_length = size_of_pubnames ();
6243 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
6246 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
6249 fputc ('\n', asm_out_file);
6250 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6253 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6255 fputc ('\n', asm_out_file);
6256 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6258 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6261 fputc ('\n', asm_out_file);
6262 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
6264 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
6266 fputc ('\n', asm_out_file);
6267 for (i = 0; i < pubname_table_in_use; ++i)
6269 register pubname_ref pub = &pubname_table[i];
6271 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6272 if (pub->die->die_mark == 0)
6275 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
6277 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
6279 fputc ('\n', asm_out_file);
6283 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
6284 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
6288 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
6289 (int) strlen (pub->name) + 1);
6292 fputc ('\n', asm_out_file);
6295 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
6296 fputc ('\n', asm_out_file);
6299 /* Add a new entry to .debug_aranges if appropriate. */
6302 add_arange (decl, die)
6306 if (! DECL_SECTION_NAME (decl))
6309 if (arange_table_in_use == arange_table_allocated)
6311 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6313 = (arange_ref) xrealloc (arange_table,
6314 arange_table_allocated * sizeof (dw_die_ref));
6317 arange_table[arange_table_in_use++] = die;
6320 /* Output the information that goes into the .debug_aranges table.
6321 Namely, define the beginning and ending address range of the
6322 text section generated for this compilation unit. */
6327 register unsigned i;
6328 register unsigned long aranges_length = size_of_aranges ();
6330 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
6332 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
6335 fputc ('\n', asm_out_file);
6336 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6338 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6340 fputc ('\n', asm_out_file);
6341 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6343 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6346 fputc ('\n', asm_out_file);
6347 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6349 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
6351 fputc ('\n', asm_out_file);
6352 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6354 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
6357 fputc ('\n', asm_out_file);
6359 /* We need to align to twice the pointer size here. */
6360 if (DWARF_ARANGES_PAD_SIZE)
6362 /* Pad using a 2 bytes word so that padding is correct
6363 for any pointer size. */
6364 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
6365 for (i = 2; i < DWARF_ARANGES_PAD_SIZE; i += 2)
6366 fprintf (asm_out_file, ",0");
6368 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
6369 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
6372 fputc ('\n', asm_out_file);
6373 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
6375 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6377 fputc ('\n', asm_out_file);
6378 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
6379 text_section_label);
6381 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6383 fputc ('\n', asm_out_file);
6384 for (i = 0; i < arange_table_in_use; ++i)
6386 dw_die_ref die = arange_table[i];
6388 /* We shouldn't see aranges for DIEs outside of the main CU. */
6389 if (die->die_mark == 0)
6392 if (die->die_tag == DW_TAG_subprogram)
6393 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
6396 /* A static variable; extract the symbol from DW_AT_location.
6397 Note that this code isn't currently hit, as we only emit
6398 aranges for functions (jason 9/23/99). */
6400 dw_attr_ref a = get_AT (die, DW_AT_location);
6401 dw_loc_descr_ref loc;
6402 if (! a || AT_class (a) != dw_val_class_loc)
6406 if (loc->dw_loc_opc != DW_OP_addr)
6409 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
6410 loc->dw_loc_oprnd1.v.val_addr);
6414 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6416 fputc ('\n', asm_out_file);
6417 if (die->die_tag == DW_TAG_subprogram)
6418 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
6419 get_AT_low_pc (die));
6421 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
6422 get_AT_unsigned (die, DW_AT_byte_size));
6425 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6427 fputc ('\n', asm_out_file);
6430 /* Output the terminator words. */
6431 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6432 fputc ('\n', asm_out_file);
6433 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6434 fputc ('\n', asm_out_file);
6438 /* Data structure containing information about input files. */
6441 char *path; /* Complete file name. */
6442 char *fname; /* File name part. */
6443 int length; /* Length of entire string. */
6444 int file_idx; /* Index in input file table. */
6445 int dir_idx; /* Index in directory table. */
6448 /* Data structure containing information about directories with source
6452 char *path; /* Path including directory name. */
6453 int length; /* Path length. */
6454 int prefix; /* Index of directory entry which is a prefix. */
6455 int nbytes; /* Total number of bytes in all file names excluding
6457 int count; /* Number of files in this directory. */
6458 int dir_idx; /* Index of directory used as base. */
6459 int used; /* Used in the end? */
6462 /* Callback function for file_info comparison. We sort by looking at
6463 the directories in the path. */
6465 file_info_cmp (p1, p2)
6469 const struct file_info *s1 = p1;
6470 const struct file_info *s2 = p2;
6474 /* Take care of file names without directories. */
6475 if (s1->path == s1->fname)
6477 else if (s2->path == s2->fname)
6480 cp1 = (unsigned char *) s1->path;
6481 cp2 = (unsigned char *) s2->path;
6487 /* Reached the end of the first path? */
6488 if (cp1 == (unsigned char *) s1->fname)
6489 /* It doesn't really matter in which order files from the
6490 same directory are sorted in. Therefore don't test for
6491 the second path reaching the end. */
6493 else if (cp2 == (unsigned char *) s2->fname)
6496 /* Character of current path component the same? */
6502 /* Output the directory table and the file name table. We try to minimize
6503 the total amount of memory needed. A heuristic is used to avoid large
6504 slowdowns with many input files. */
6506 output_file_names ()
6508 struct file_info *files;
6509 struct dir_info *dirs;
6518 /* Allocate the various arrays we need. */
6519 files = (struct file_info *) alloca (line_file_table.in_use
6520 * sizeof (struct file_info));
6521 dirs = (struct dir_info *) alloca (line_file_table.in_use
6522 * sizeof (struct dir_info));
6524 /* Sort the file names. */
6525 for (i = 1; i < (int) line_file_table.in_use; ++i)
6529 /* Skip all leading "./". */
6530 f = line_file_table.table[i];
6531 while (f[0] == '.' && f[1] == '/')
6534 /* Create a new array entry. */
6536 files[i].length = strlen (f);
6537 files[i].file_idx = i;
6539 /* Search for the file name part. */
6540 f = strrchr (f, '/');
6541 files[i].fname = f == NULL ? files[i].path : f + 1;
6543 qsort (files + 1, line_file_table.in_use - 1, sizeof (files[0]),
6546 /* Find all the different directories used. */
6547 dirs[0].path = files[1].path;
6548 dirs[0].length = files[1].fname - files[1].path;
6549 dirs[0].prefix = -1;
6550 dirs[0].nbytes = files[1].length - dirs[1].length + 1;
6552 dirs[0].dir_idx = 0;
6554 files[1].dir_idx = 0;
6557 for (i = 2; i < (int) line_file_table.in_use; ++i)
6558 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6559 && memcmp (dirs[ndirs - 1].path, files[i].path,
6560 dirs[ndirs - 1].length) == 0)
6562 /* Same directory as last entry. */
6563 files[i].dir_idx = ndirs - 1;
6564 dirs[ndirs - 1].nbytes += files[i].length - dirs[ndirs - 1].length + 1;
6565 ++dirs[ndirs - 1].count;
6571 /* This is a new directory. */
6572 dirs[ndirs].path = files[i].path;
6573 dirs[ndirs].length = files[i].fname - files[i].path;
6574 dirs[ndirs].nbytes = files[i].length - dirs[i].length + 1;
6575 dirs[ndirs].count = 1;
6576 dirs[ndirs].dir_idx = ndirs;
6577 dirs[ndirs].used = 0;
6578 files[i].dir_idx = ndirs;
6580 /* Search for a prefix. */
6581 dirs[ndirs].prefix = -1;
6582 for (j = 0; j < ndirs; ++j)
6583 if (dirs[j].length < dirs[ndirs].length
6584 && dirs[j].length != 0
6585 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6586 dirs[ndirs].prefix = j;
6591 /* Now to the actual work. We have to find a subset of the
6592 directories which allow expressing the file name using references
6593 to the directory table with the least amount of characters. We
6594 do not do an exhaustive search where we would have to check out
6595 every combination of every single possible prefix. Instead we
6596 use a heuristic which provides nearly optimal results in most
6597 cases and never is much off. */
6598 saved = (int *) alloca (ndirs * sizeof (int));
6599 savehere = (int *) alloca (ndirs * sizeof (int));
6601 memset (saved, '\0', ndirs * sizeof (saved[0]));
6602 for (i = 0; i < ndirs; ++i)
6607 /* We can always safe some space for the current directory. But
6608 this does not mean it will be enough to justify adding the
6610 savehere[i] = dirs[i].length;
6611 total = (savehere[i] - saved[i]) * dirs[i].count;
6613 for (j = i + 1; j < ndirs; ++j)
6617 if (saved[j] < dirs[i].length)
6619 /* Determine whether the dirs[i] path is a prefix of the
6624 while (k != -1 && k != i)
6629 /* Yes it is. We can possibly safe some memory but
6630 writing the filenames in dirs[j] relative to
6632 savehere[j] = dirs[i].length;
6633 total += (savehere[j] - saved[j]) * dirs[j].count;
6638 /* Check whether we can safe enough to justify adding the dirs[i]
6640 if (total > dirs[i].length + 1)
6642 /* It's worthwhile adding. */
6643 for (j = i; j < ndirs; ++j)
6644 if (savehere[j] > 0)
6646 /* Remember how much we saved for this directory so far. */
6647 saved[j] = savehere[j];
6649 /* Remember the prefix directory. */
6650 dirs[j].dir_idx = i;
6655 /* We have to emit them in the order they appear in the line_file_table
6656 array since the index is used in the debug info generation. To
6657 do this efficiently we generate a back-mapping of the indices
6659 backmap = (int *) alloca (line_file_table.in_use * sizeof (int));
6660 for (i = 1; i < (int) line_file_table.in_use; ++i)
6662 backmap[files[i].file_idx] = i;
6663 /* Mark this directory as used. */
6664 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6667 /* That was it. We are ready to emit the information. First the
6668 directory name table. Here we have to make sure that the first
6669 actually emitted directory name has the index one. Zero is
6670 reserved for the current working directory. Make sure we do not
6671 confuse these indices with the one for the constructed table
6672 (even though most of the time they are identical). */
6674 idx_offset = dirs[0].path[0] == '/' ? 1 : 0;
6675 for (i = 1 - idx_offset; i < ndirs; ++i)
6676 if (dirs[i].used != 0)
6678 dirs[i].used = idx++;
6682 ASM_OUTPUT_DWARF_NSTRING (asm_out_file,
6683 dirs[i].path, dirs[i].length - 1);
6684 fprintf (asm_out_file, "%s Directory Entry: 0x%x\n",
6685 ASM_COMMENT_START, dirs[i].used);
6689 ASM_OUTPUT_ASCII (asm_out_file, dirs[i].path, dirs[i].length - 1);
6690 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6691 fputc ('\n', asm_out_file);
6694 /* Correct the index for the current working directory entry if it
6696 if (idx_offset == 0)
6698 /* Terminate the directory name array. */
6699 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6701 fprintf (asm_out_file, "\t%s End directory table", ASM_COMMENT_START);
6702 fputc ('\n', asm_out_file);
6704 /* Now write all the file names. */
6705 for (i = 1; i < (int) line_file_table.in_use; ++i)
6707 int file_idx = backmap[i];
6708 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6712 ASM_OUTPUT_DWARF_STRING (asm_out_file,
6713 files[file_idx].path
6714 + dirs[dir_idx].length);
6715 fprintf (asm_out_file, "%s File Entry: 0x%x\n",
6716 ASM_COMMENT_START, i);
6719 ASM_OUTPUT_ASCII (asm_out_file,
6720 files[file_idx].path + dirs[dir_idx].length,
6721 (files[file_idx].length
6722 - dirs[dir_idx].length) + 1);
6724 /* Include directory index. */
6725 output_uleb128 (dirs[dir_idx].used);
6726 fputc ('\n', asm_out_file);
6728 /* Modification time. */
6730 fputc ('\n', asm_out_file);
6732 /* File length in bytes. */
6734 fputc ('\n', asm_out_file);
6737 /* Terminate the file name table */
6738 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6740 fprintf (asm_out_file, "\t%s End file name table", ASM_COMMENT_START);
6741 fputc ('\n', asm_out_file);
6745 /* Output the source line number correspondence information. This
6746 information goes into the .debug_line section. */
6751 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6752 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6753 register unsigned opc;
6754 register unsigned n_op_args;
6755 register unsigned long lt_index;
6756 register unsigned long current_line;
6757 register long line_offset;
6758 register long line_delta;
6759 register unsigned long current_file;
6760 register unsigned long function;
6762 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
6764 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
6767 fputc ('\n', asm_out_file);
6768 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
6769 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6771 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6773 fputc ('\n', asm_out_file);
6774 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
6776 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
6778 fputc ('\n', asm_out_file);
6779 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
6781 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
6784 fputc ('\n', asm_out_file);
6785 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
6787 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
6790 fputc ('\n', asm_out_file);
6791 fprintf (asm_out_file, "%s%d", ASM_BYTE_OP, DWARF_LINE_BASE);
6793 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
6796 fputc ('\n', asm_out_file);
6797 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
6799 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
6802 fputc ('\n', asm_out_file);
6803 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
6805 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
6807 fputc ('\n', asm_out_file);
6808 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6812 case DW_LNS_advance_pc:
6813 case DW_LNS_advance_line:
6814 case DW_LNS_set_file:
6815 case DW_LNS_set_column:
6816 case DW_LNS_fixed_advance_pc:
6823 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
6825 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
6826 ASM_COMMENT_START, opc, n_op_args);
6827 fputc ('\n', asm_out_file);
6830 /* Write out the information about the files we use. */
6831 output_file_names ();
6833 /* We used to set the address register to the first location in the text
6834 section here, but that didn't accomplish anything since we already
6835 have a line note for the opening brace of the first function. */
6837 /* Generate the line number to PC correspondence table, encoded as
6838 a series of state machine operations. */
6841 strcpy (prev_line_label, text_section_label);
6842 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6844 register dw_line_info_ref line_info = &line_info_table[lt_index];
6847 /* Disable this optimization for now; GDB wants to see two line notes
6848 at the beginning of a function so it can find the end of the
6851 /* Don't emit anything for redundant notes. Just updating the
6852 address doesn't accomplish anything, because we already assume
6853 that anything after the last address is this line. */
6854 if (line_info->dw_line_num == current_line
6855 && line_info->dw_file_num == current_file)
6859 /* Emit debug info for the address of the current line, choosing
6860 the encoding that uses the least amount of space. */
6861 /* ??? Unfortunately, we have little choice here currently, and must
6862 always use the most general form. Gcc does not know the address
6863 delta itself, so we can't use DW_LNS_advance_pc. There are no known
6864 dwarf2 aware assemblers at this time, so we can't use any special
6865 pseudo ops that would allow the assembler to optimally encode this for
6866 us. Many ports do have length attributes which will give an upper
6867 bound on the address range. We could perhaps use length attributes
6868 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
6869 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6872 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6873 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6875 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6878 fputc ('\n', asm_out_file);
6879 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
6880 fputc ('\n', asm_out_file);
6884 /* This can handle any delta. This takes
6885 4+DWARF2_ADDR_SIZE bytes. */
6886 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6888 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6890 fputc ('\n', asm_out_file);
6891 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6892 fputc ('\n', asm_out_file);
6893 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6894 fputc ('\n', asm_out_file);
6895 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6896 fputc ('\n', asm_out_file);
6898 strcpy (prev_line_label, line_label);
6900 /* Emit debug info for the source file of the current line, if
6901 different from the previous line. */
6902 if (line_info->dw_file_num != current_file)
6904 current_file = line_info->dw_file_num;
6905 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6907 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6909 fputc ('\n', asm_out_file);
6910 output_uleb128 (current_file);
6912 fprintf (asm_out_file, " (\"%s\")",
6913 line_file_table.table[current_file]);
6915 fputc ('\n', asm_out_file);
6918 /* Emit debug info for the current line number, choosing the encoding
6919 that uses the least amount of space. */
6920 if (line_info->dw_line_num != current_line)
6922 line_offset = line_info->dw_line_num - current_line;
6923 line_delta = line_offset - DWARF_LINE_BASE;
6924 current_line = line_info->dw_line_num;
6925 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6927 /* This can handle deltas from -10 to 234, using the current
6928 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6930 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6931 DWARF_LINE_OPCODE_BASE + line_delta);
6933 fprintf (asm_out_file,
6934 "\t%s line %ld", ASM_COMMENT_START, current_line);
6936 fputc ('\n', asm_out_file);
6940 /* This can handle any delta. This takes at least 4 bytes,
6941 depending on the value being encoded. */
6942 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6944 fprintf (asm_out_file, "\t%s advance to line %ld",
6945 ASM_COMMENT_START, current_line);
6947 fputc ('\n', asm_out_file);
6948 output_sleb128 (line_offset);
6949 fputc ('\n', asm_out_file);
6950 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6952 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6953 fputc ('\n', asm_out_file);
6958 /* We still need to start a new row, so output a copy insn. */
6959 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6961 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6962 fputc ('\n', asm_out_file);
6966 /* Emit debug info for the address of the end of the function. */
6969 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6971 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6974 fputc ('\n', asm_out_file);
6975 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
6976 fputc ('\n', asm_out_file);
6980 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6982 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
6983 fputc ('\n', asm_out_file);
6984 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6985 fputc ('\n', asm_out_file);
6986 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6987 fputc ('\n', asm_out_file);
6988 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
6989 fputc ('\n', asm_out_file);
6992 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6994 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
6996 fputc ('\n', asm_out_file);
6998 fputc ('\n', asm_out_file);
6999 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
7000 fputc ('\n', asm_out_file);
7005 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7007 register dw_separate_line_info_ref line_info
7008 = &separate_line_info_table[lt_index];
7011 /* Don't emit anything for redundant notes. */
7012 if (line_info->dw_line_num == current_line
7013 && line_info->dw_file_num == current_file
7014 && line_info->function == function)
7018 /* Emit debug info for the address of the current line. If this is
7019 a new function, or the first line of a function, then we need
7020 to handle it differently. */
7021 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7023 if (function != line_info->function)
7025 function = line_info->function;
7027 /* Set the address register to the first line in the function */
7028 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7030 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7033 fputc ('\n', asm_out_file);
7034 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7035 fputc ('\n', asm_out_file);
7036 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7037 fputc ('\n', asm_out_file);
7038 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7039 fputc ('\n', asm_out_file);
7043 /* ??? See the DW_LNS_advance_pc comment above. */
7046 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7048 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7051 fputc ('\n', asm_out_file);
7052 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7054 fputc ('\n', asm_out_file);
7058 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7060 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7062 fputc ('\n', asm_out_file);
7063 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7064 fputc ('\n', asm_out_file);
7065 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7066 fputc ('\n', asm_out_file);
7067 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7068 fputc ('\n', asm_out_file);
7071 strcpy (prev_line_label, line_label);
7073 /* Emit debug info for the source file of the current line, if
7074 different from the previous line. */
7075 if (line_info->dw_file_num != current_file)
7077 current_file = line_info->dw_file_num;
7078 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
7080 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
7082 fputc ('\n', asm_out_file);
7083 output_uleb128 (current_file);
7085 fprintf (asm_out_file, " (\"%s\")",
7086 line_file_table.table[current_file]);
7088 fputc ('\n', asm_out_file);
7091 /* Emit debug info for the current line number, choosing the encoding
7092 that uses the least amount of space. */
7093 if (line_info->dw_line_num != current_line)
7095 line_offset = line_info->dw_line_num - current_line;
7096 line_delta = line_offset - DWARF_LINE_BASE;
7097 current_line = line_info->dw_line_num;
7098 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7100 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
7101 DWARF_LINE_OPCODE_BASE + line_delta);
7103 fprintf (asm_out_file,
7104 "\t%s line %ld", ASM_COMMENT_START, current_line);
7106 fputc ('\n', asm_out_file);
7110 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
7112 fprintf (asm_out_file, "\t%s advance to line %ld",
7113 ASM_COMMENT_START, current_line);
7115 fputc ('\n', asm_out_file);
7116 output_sleb128 (line_offset);
7117 fputc ('\n', asm_out_file);
7118 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7120 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7121 fputc ('\n', asm_out_file);
7126 /* We still need to start a new row, so output a copy insn. */
7127 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7129 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7130 fputc ('\n', asm_out_file);
7138 /* If we're done with a function, end its sequence. */
7139 if (lt_index == separate_line_info_table_in_use
7140 || separate_line_info_table[lt_index].function != function)
7145 /* Emit debug info for the address of the end of the function. */
7146 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7149 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7151 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7154 fputc ('\n', asm_out_file);
7155 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7157 fputc ('\n', asm_out_file);
7161 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7163 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7165 fputc ('\n', asm_out_file);
7166 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7167 fputc ('\n', asm_out_file);
7168 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7169 fputc ('\n', asm_out_file);
7170 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7171 fputc ('\n', asm_out_file);
7174 /* Output the marker for the end of this sequence. */
7175 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7177 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
7180 fputc ('\n', asm_out_file);
7182 fputc ('\n', asm_out_file);
7183 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
7184 fputc ('\n', asm_out_file);
7188 /* Output the marker for the end of the line number info. */
7189 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
7192 /* Given a pointer to a tree node for some base type, return a pointer to
7193 a DIE that describes the given type.
7195 This routine must only be called for GCC type nodes that correspond to
7196 Dwarf base (fundamental) types. */
7199 base_type_die (type)
7202 register dw_die_ref base_type_result;
7203 register const char *type_name;
7204 register enum dwarf_type encoding;
7205 register tree name = TYPE_NAME (type);
7207 if (TREE_CODE (type) == ERROR_MARK
7208 || TREE_CODE (type) == VOID_TYPE)
7213 if (TREE_CODE (name) == TYPE_DECL)
7214 name = DECL_NAME (name);
7216 type_name = IDENTIFIER_POINTER (name);
7219 type_name = "__unknown__";
7221 switch (TREE_CODE (type))
7224 /* Carefully distinguish the C character types, without messing
7225 up if the language is not C. Note that we check only for the names
7226 that contain spaces; other names might occur by coincidence in other
7228 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7229 && (type == char_type_node
7230 || ! strcmp (type_name, "signed char")
7231 || ! strcmp (type_name, "unsigned char"))))
7233 if (TREE_UNSIGNED (type))
7234 encoding = DW_ATE_unsigned;
7236 encoding = DW_ATE_signed;
7239 /* else fall through. */
7242 /* GNU Pascal/Ada CHAR type. Not used in C. */
7243 if (TREE_UNSIGNED (type))
7244 encoding = DW_ATE_unsigned_char;
7246 encoding = DW_ATE_signed_char;
7250 encoding = DW_ATE_float;
7253 /* Dwarf2 doesn't know anything about complex ints, so use
7254 a user defined type for it. */
7256 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7257 encoding = DW_ATE_complex_float;
7259 encoding = DW_ATE_lo_user;
7263 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7264 encoding = DW_ATE_boolean;
7268 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7271 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7272 if (demangle_name_func)
7273 type_name = (*demangle_name_func) (type_name);
7275 add_AT_string (base_type_result, DW_AT_name, type_name);
7276 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7277 int_size_in_bytes (type));
7278 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7280 return base_type_result;
7283 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7284 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7285 a given type is generally the same as the given type, except that if the
7286 given type is a pointer or reference type, then the root type of the given
7287 type is the root type of the "basis" type for the pointer or reference
7288 type. (This definition of the "root" type is recursive.) Also, the root
7289 type of a `const' qualified type or a `volatile' qualified type is the
7290 root type of the given type without the qualifiers. */
7296 if (TREE_CODE (type) == ERROR_MARK)
7297 return error_mark_node;
7299 switch (TREE_CODE (type))
7302 return error_mark_node;
7305 case REFERENCE_TYPE:
7306 return type_main_variant (root_type (TREE_TYPE (type)));
7309 return type_main_variant (type);
7313 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7314 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7320 switch (TREE_CODE (type))
7335 case QUAL_UNION_TYPE:
7340 case REFERENCE_TYPE:
7354 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7355 entry that chains various modifiers in front of the given type. */
7358 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7360 register int is_const_type;
7361 register int is_volatile_type;
7362 register dw_die_ref context_die;
7364 register enum tree_code code = TREE_CODE (type);
7365 register dw_die_ref mod_type_die = NULL;
7366 register dw_die_ref sub_die = NULL;
7367 register tree item_type = NULL;
7369 if (code != ERROR_MARK)
7371 type = build_type_variant (type, is_const_type, is_volatile_type);
7373 mod_type_die = lookup_type_die (type);
7375 return mod_type_die;
7377 /* Handle C typedef types. */
7378 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7379 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
7381 tree dtype = TREE_TYPE (TYPE_NAME (type));
7384 /* For a named type, use the typedef. */
7385 gen_type_die (type, context_die);
7386 mod_type_die = lookup_type_die (type);
7389 else if (is_const_type < TYPE_READONLY (dtype)
7390 || is_volatile_type < TYPE_VOLATILE (dtype))
7391 /* cv-unqualified version of named type. Just use the unnamed
7392 type to which it refers. */
7394 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
7395 is_const_type, is_volatile_type,
7397 /* Else cv-qualified version of named type; fall through. */
7403 else if (is_const_type)
7405 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7406 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7408 else if (is_volatile_type)
7410 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7411 sub_die = modified_type_die (type, 0, 0, context_die);
7413 else if (code == POINTER_TYPE)
7415 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7416 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7418 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7420 item_type = TREE_TYPE (type);
7422 else if (code == REFERENCE_TYPE)
7424 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7425 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7427 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7429 item_type = TREE_TYPE (type);
7431 else if (is_base_type (type))
7432 mod_type_die = base_type_die (type);
7435 gen_type_die (type, context_die);
7437 /* We have to get the type_main_variant here (and pass that to the
7438 `lookup_type_die' routine) because the ..._TYPE node we have
7439 might simply be a *copy* of some original type node (where the
7440 copy was created to help us keep track of typedef names) and
7441 that copy might have a different TYPE_UID from the original
7443 mod_type_die = lookup_type_die (type_main_variant (type));
7444 if (mod_type_die == NULL)
7449 equate_type_number_to_die (type, mod_type_die);
7451 /* We must do this after the equate_type_number_to_die call, in case
7452 this is a recursive type. This ensures that the modified_type_die
7453 recursion will terminate even if the type is recursive. Recursive
7454 types are possible in Ada. */
7455 sub_die = modified_type_die (item_type,
7456 TYPE_READONLY (item_type),
7457 TYPE_VOLATILE (item_type),
7460 if (sub_die != NULL)
7461 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7463 return mod_type_die;
7466 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7467 an enumerated type. */
7473 return TREE_CODE (type) == ENUMERAL_TYPE;
7476 /* Return the register number described by a given RTL node. */
7482 register unsigned regno = REGNO (rtl);
7484 if (regno >= FIRST_PSEUDO_REGISTER)
7486 warning ("internal regno botch: regno = %d\n", regno);
7490 regno = DBX_REGISTER_NUMBER (regno);
7494 /* Return a location descriptor that designates a machine register. */
7496 static dw_loc_descr_ref
7497 reg_loc_descriptor (rtl)
7500 register dw_loc_descr_ref loc_result = NULL;
7501 register unsigned reg = reg_number (rtl);
7504 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7506 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7511 /* Return a location descriptor that designates a constant. */
7513 static dw_loc_descr_ref
7514 int_loc_descriptor (i)
7517 enum dwarf_location_atom op;
7519 /* Pick the smallest representation of a constant, rather than just
7520 defaulting to the LEB encoding. */
7524 op = DW_OP_lit0 + i;
7527 else if (i <= 0xffff)
7529 else if (HOST_BITS_PER_WIDE_INT == 32
7539 else if (i >= -0x8000)
7541 else if (HOST_BITS_PER_WIDE_INT == 32
7542 || i >= -0x80000000)
7548 return new_loc_descr (op, i, 0);
7551 /* Return a location descriptor that designates a base+offset location. */
7553 static dw_loc_descr_ref
7554 based_loc_descr (reg, offset)
7558 register dw_loc_descr_ref loc_result;
7559 /* For the "frame base", we use the frame pointer or stack pointer
7560 registers, since the RTL for local variables is relative to one of
7562 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7563 ? HARD_FRAME_POINTER_REGNUM
7564 : STACK_POINTER_REGNUM);
7567 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7569 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7571 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7576 /* Return true if this RTL expression describes a base+offset calculation. */
7582 return (GET_CODE (rtl) == PLUS
7583 && ((GET_CODE (XEXP (rtl, 0)) == REG
7584 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7587 /* The following routine converts the RTL for a variable or parameter
7588 (resident in memory) into an equivalent Dwarf representation of a
7589 mechanism for getting the address of that same variable onto the top of a
7590 hypothetical "address evaluation" stack.
7592 When creating memory location descriptors, we are effectively transforming
7593 the RTL for a memory-resident object into its Dwarf postfix expression
7594 equivalent. This routine recursively descends an RTL tree, turning
7595 it into Dwarf postfix code as it goes.
7597 MODE is the mode of the memory reference, needed to handle some
7598 autoincrement addressing modes. */
7600 static dw_loc_descr_ref
7601 mem_loc_descriptor (rtl, mode)
7603 enum machine_mode mode;
7605 dw_loc_descr_ref mem_loc_result = NULL;
7606 /* Note that for a dynamically sized array, the location we will generate a
7607 description of here will be the lowest numbered location which is
7608 actually within the array. That's *not* necessarily the same as the
7609 zeroth element of the array. */
7611 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7612 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7615 switch (GET_CODE (rtl))
7620 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7621 just fall into the SUBREG code. */
7626 /* The case of a subreg may arise when we have a local (register)
7627 variable or a formal (register) parameter which doesn't quite fill
7628 up an entire register. For now, just assume that it is
7629 legitimate to make the Dwarf info refer to the whole register which
7630 contains the given subreg. */
7631 rtl = XEXP (rtl, 0);
7636 /* Whenever a register number forms a part of the description of the
7637 method for calculating the (dynamic) address of a memory resident
7638 object, DWARF rules require the register number be referred to as
7639 a "base register". This distinction is not based in any way upon
7640 what category of register the hardware believes the given register
7641 belongs to. This is strictly DWARF terminology we're dealing with
7642 here. Note that in cases where the location of a memory-resident
7643 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7644 OP_CONST (0)) the actual DWARF location descriptor that we generate
7645 may just be OP_BASEREG (basereg). This may look deceptively like
7646 the object in question was allocated to a register (rather than in
7647 memory) so DWARF consumers need to be aware of the subtle
7648 distinction between OP_REG and OP_BASEREG. */
7649 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7653 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7654 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7658 /* Some ports can transform a symbol ref into a label ref, because
7659 the symbol ref is too far away and has to be dumped into a constant
7663 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7664 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7665 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7669 /* Extract the PLUS expression nested inside and fall into
7670 PLUS code bellow. */
7671 rtl = XEXP (rtl, 1);
7676 /* Turn these into a PLUS expression and fall into the PLUS code
7678 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7679 GEN_INT (GET_CODE (rtl) == PRE_INC
7680 ? GET_MODE_UNIT_SIZE (mode)
7681 : -GET_MODE_UNIT_SIZE (mode)));
7687 if (is_based_loc (rtl))
7688 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7689 INTVAL (XEXP (rtl, 1)));
7692 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7694 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7695 && INTVAL (XEXP (rtl, 1)) >= 0)
7697 add_loc_descr (&mem_loc_result,
7698 new_loc_descr (DW_OP_plus_uconst,
7699 INTVAL (XEXP (rtl, 1)), 0));
7703 add_loc_descr (&mem_loc_result,
7704 mem_loc_descriptor (XEXP (rtl, 1), mode));
7705 add_loc_descr (&mem_loc_result,
7706 new_loc_descr (DW_OP_plus, 0, 0));
7712 /* If a pseudo-reg is optimized away, it is possible for it to
7713 be replaced with a MEM containing a multiply. */
7714 add_loc_descr (&mem_loc_result,
7715 mem_loc_descriptor (XEXP (rtl, 0), mode));
7716 add_loc_descr (&mem_loc_result,
7717 mem_loc_descriptor (XEXP (rtl, 1), mode));
7718 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7722 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7729 return mem_loc_result;
7732 /* Return a descriptor that describes the concatenation of two locations.
7733 This is typically a complex variable. */
7735 static dw_loc_descr_ref
7736 concat_loc_descriptor (x0, x1)
7737 register rtx x0, x1;
7739 dw_loc_descr_ref cc_loc_result = NULL;
7741 if (!is_pseudo_reg (x0)
7742 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7743 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7744 add_loc_descr (&cc_loc_result,
7745 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7747 if (!is_pseudo_reg (x1)
7748 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7749 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7750 add_loc_descr (&cc_loc_result,
7751 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7753 return cc_loc_result;
7756 /* Output a proper Dwarf location descriptor for a variable or parameter
7757 which is either allocated in a register or in a memory location. For a
7758 register, we just generate an OP_REG and the register number. For a
7759 memory location we provide a Dwarf postfix expression describing how to
7760 generate the (dynamic) address of the object onto the address stack. */
7762 static dw_loc_descr_ref
7763 loc_descriptor (rtl)
7766 dw_loc_descr_ref loc_result = NULL;
7767 switch (GET_CODE (rtl))
7770 /* The case of a subreg may arise when we have a local (register)
7771 variable or a formal (register) parameter which doesn't quite fill
7772 up an entire register. For now, just assume that it is
7773 legitimate to make the Dwarf info refer to the whole register which
7774 contains the given subreg. */
7775 rtl = XEXP (rtl, 0);
7780 loc_result = reg_loc_descriptor (rtl);
7784 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7788 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7798 /* Similar, but generate the descriptor from trees instead of rtl.
7799 This comes up particularly with variable length arrays. */
7801 static dw_loc_descr_ref
7802 loc_descriptor_from_tree (loc, addressp)
7806 dw_loc_descr_ref ret = NULL;
7807 int indirect_size = 0;
7808 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7809 enum dwarf_location_atom op;
7811 /* ??? Most of the time we do not take proper care for sign/zero
7812 extending the values properly. Hopefully this won't be a real
7815 switch (TREE_CODE (loc))
7820 case WITH_RECORD_EXPR:
7821 /* This case involves extracting fields from an object to determine the
7822 position of other fields. We don't try to encode this here. The
7823 only user of this is Ada, which encodes the needed information using
7824 the names of types. */
7830 rtx rtl = rtl_for_decl_location (loc);
7831 enum machine_mode mode = DECL_MODE (loc);
7833 if (rtl == NULL_RTX)
7835 else if (CONSTANT_P (rtl))
7837 ret = new_loc_descr (DW_OP_addr, 0, 0);
7838 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7839 ret->dw_loc_oprnd1.v.val_addr = rtl;
7840 indirect_size = GET_MODE_SIZE (mode);
7844 if (GET_CODE (rtl) == MEM)
7846 indirect_size = GET_MODE_SIZE (mode);
7847 rtl = XEXP (rtl, 0);
7849 ret = mem_loc_descriptor (rtl, mode);
7855 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7856 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7861 case NON_LVALUE_EXPR:
7863 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7870 HOST_WIDE_INT bitsize, bitpos, bytepos;
7871 enum machine_mode mode;
7873 unsigned int alignment;
7875 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7876 &unsignedp, &volatilep, &alignment);
7877 ret = loc_descriptor_from_tree (obj, 1);
7879 if (offset != NULL_TREE)
7881 /* Variable offset. */
7882 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7883 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7888 /* We cannot address anything not on a unit boundary. */
7889 if (bitpos % BITS_PER_UNIT != 0)
7894 if (bitpos % BITS_PER_UNIT != 0
7895 || bitsize % BITS_PER_UNIT != 0)
7897 /* ??? We could handle this by loading and shifting etc.
7898 Wait until someone needs it before expending the effort. */
7902 indirect_size = bitsize / BITS_PER_UNIT;
7905 bytepos = bitpos / BITS_PER_UNIT;
7907 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7908 else if (bytepos < 0)
7910 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7911 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7917 if (host_integerp (loc, 0))
7918 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7930 case TRUNC_DIV_EXPR:
7936 case TRUNC_MOD_EXPR:
7946 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7949 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7950 && host_integerp (TREE_OPERAND (loc, 1), 0))
7952 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7953 add_loc_descr (&ret,
7954 new_loc_descr (DW_OP_plus_uconst,
7955 tree_low_cst (TREE_OPERAND (loc, 1),
7963 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7968 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7973 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7978 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7990 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7991 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7992 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8006 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8007 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8011 loc = build (COND_EXPR, TREE_TYPE (loc),
8012 build (LT_EXPR, integer_type_node,
8013 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8014 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8019 dw_loc_descr_ref bra_node, jump_node, tmp;
8021 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8022 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8023 add_loc_descr (&ret, bra_node);
8025 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8026 add_loc_descr (&ret, tmp);
8027 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8028 add_loc_descr (&ret, jump_node);
8030 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8031 add_loc_descr (&ret, tmp);
8032 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8033 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
8035 /* ??? Need a node to point the skip at. Use a nop. */
8036 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8037 add_loc_descr (&ret, tmp);
8038 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8039 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8047 /* If we can't fill the request for an address, die. */
8048 if (addressp && indirect_size == 0)
8051 /* If we've got an address and don't want one, dereference. */
8052 if (!addressp && indirect_size > 0)
8054 if (indirect_size > DWARF2_ADDR_SIZE)
8056 if (indirect_size == DWARF2_ADDR_SIZE)
8059 op = DW_OP_deref_size;
8060 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
8066 /* Given a value, round it up to the lowest multiple of `boundary'
8067 which is not less than the value itself. */
8069 static inline HOST_WIDE_INT
8070 ceiling (value, boundary)
8071 HOST_WIDE_INT value;
8072 unsigned int boundary;
8074 return (((value + boundary - 1) / boundary) * boundary);
8077 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8078 pointer to the declared type for the relevant field variable, or return
8079 `integer_type_node' if the given node turns out to be an
8088 if (TREE_CODE (decl) == ERROR_MARK)
8089 return integer_type_node;
8091 type = DECL_BIT_FIELD_TYPE (decl);
8092 if (type == NULL_TREE)
8093 type = TREE_TYPE (decl);
8098 /* Given a pointer to a tree node, return the alignment in bits for
8099 it, or else return BITS_PER_WORD if the node actually turns out to
8100 be an ERROR_MARK node. */
8102 static inline unsigned
8103 simple_type_align_in_bits (type)
8106 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8109 static inline unsigned
8110 simple_decl_align_in_bits (decl)
8113 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8116 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8117 node, return the size in bits for the type if it is a constant, or else
8118 return the alignment for the type if the type's size is not constant, or
8119 else return BITS_PER_WORD if the type actually turns out to be an
8122 static inline unsigned HOST_WIDE_INT
8123 simple_type_size_in_bits (type)
8126 tree type_size_tree;
8128 if (TREE_CODE (type) == ERROR_MARK)
8129 return BITS_PER_WORD;
8130 type_size_tree = TYPE_SIZE (type);
8132 if (type_size_tree == NULL_TREE)
8134 if (! host_integerp (type_size_tree, 1))
8135 return TYPE_ALIGN (type);
8136 return tree_low_cst (type_size_tree, 1);
8139 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
8140 return the byte offset of the lowest addressed byte of the "containing
8141 object" for the given FIELD_DECL, or return 0 if we are unable to
8142 determine what that offset is, either because the argument turns out to
8143 be a pointer to an ERROR_MARK node, or because the offset is actually
8144 variable. (We can't handle the latter case just yet). */
8146 static HOST_WIDE_INT
8147 field_byte_offset (decl)
8150 unsigned int type_align_in_bits;
8151 unsigned int decl_align_in_bits;
8152 unsigned HOST_WIDE_INT type_size_in_bits;
8153 HOST_WIDE_INT object_offset_in_bits;
8154 HOST_WIDE_INT object_offset_in_bytes;
8156 tree field_size_tree;
8157 HOST_WIDE_INT bitpos_int;
8158 HOST_WIDE_INT deepest_bitpos;
8159 unsigned HOST_WIDE_INT field_size_in_bits;
8161 if (TREE_CODE (decl) == ERROR_MARK)
8164 if (TREE_CODE (decl) != FIELD_DECL)
8167 type = field_type (decl);
8168 field_size_tree = DECL_SIZE (decl);
8170 /* The size could be unspecified if there was an error, or for
8171 a flexible array member. */
8172 if (! field_size_tree)
8173 field_size_tree = bitsize_zero_node;
8175 /* We cannot yet cope with fields whose positions are variable, so
8176 for now, when we see such things, we simply return 0. Someday, we may
8177 be able to handle such cases, but it will be damn difficult. */
8178 if (! host_integerp (bit_position (decl), 0))
8181 bitpos_int = int_bit_position (decl);
8183 /* If we don't know the size of the field, pretend it's a full word. */
8184 if (host_integerp (field_size_tree, 1))
8185 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8187 field_size_in_bits = BITS_PER_WORD;
8189 type_size_in_bits = simple_type_size_in_bits (type);
8190 type_align_in_bits = simple_type_align_in_bits (type);
8191 decl_align_in_bits = simple_decl_align_in_bits (decl);
8193 /* Note that the GCC front-end doesn't make any attempt to keep track of
8194 the starting bit offset (relative to the start of the containing
8195 structure type) of the hypothetical "containing object" for a bit-
8196 field. Thus, when computing the byte offset value for the start of the
8197 "containing object" of a bit-field, we must deduce this information on
8198 our own. This can be rather tricky to do in some cases. For example,
8199 handling the following structure type definition when compiling for an
8200 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8203 struct S { int field1; long long field2:31; };
8205 Fortunately, there is a simple rule-of-thumb which can be
8206 used in such cases. When compiling for an i386/i486, GCC will allocate
8207 8 bytes for the structure shown above. It decides to do this based upon
8208 one simple rule for bit-field allocation. Quite simply, GCC allocates
8209 each "containing object" for each bit-field at the first (i.e. lowest
8210 addressed) legitimate alignment boundary (based upon the required
8211 minimum alignment for the declared type of the field) which it can
8212 possibly use, subject to the condition that there is still enough
8213 available space remaining in the containing object (when allocated at
8214 the selected point) to fully accommodate all of the bits of the
8215 bit-field itself. This simple rule makes it obvious why GCC allocates
8216 8 bytes for each object of the structure type shown above. When looking
8217 for a place to allocate the "containing object" for `field2', the
8218 compiler simply tries to allocate a 64-bit "containing object" at each
8219 successive 32-bit boundary (starting at zero) until it finds a place to
8220 allocate that 64- bit field such that at least 31 contiguous (and
8221 previously unallocated) bits remain within that selected 64 bit field.
8222 (As it turns out, for the example above, the compiler finds that it is
8223 OK to allocate the "containing object" 64-bit field at bit-offset zero
8224 within the structure type.) Here we attempt to work backwards from the
8225 limited set of facts we're given, and we try to deduce from those facts,
8226 where GCC must have believed that the containing object started (within
8227 the structure type). The value we deduce is then used (by the callers of
8228 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8229 for fields (both bit-fields and, in the case of DW_AT_location, regular
8232 /* Figure out the bit-distance from the start of the structure to the
8233 "deepest" bit of the bit-field. */
8234 deepest_bitpos = bitpos_int + field_size_in_bits;
8236 /* This is the tricky part. Use some fancy footwork to deduce where the
8237 lowest addressed bit of the containing object must be. */
8238 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8240 /* Round up to type_align by default. This works best for bitfields. */
8241 object_offset_in_bits += type_align_in_bits - 1;
8242 object_offset_in_bits /= type_align_in_bits;
8243 object_offset_in_bits *= type_align_in_bits;
8245 if (object_offset_in_bits > bitpos_int)
8247 /* Sigh, the decl must be packed. */
8248 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8250 /* Round up to decl_align instead. */
8251 object_offset_in_bits += decl_align_in_bits - 1;
8252 object_offset_in_bits /= decl_align_in_bits;
8253 object_offset_in_bits *= decl_align_in_bits;
8256 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8258 return object_offset_in_bytes;
8261 /* The following routines define various Dwarf attributes and any data
8262 associated with them. */
8264 /* Add a location description attribute value to a DIE.
8266 This emits location attributes suitable for whole variables and
8267 whole parameters. Note that the location attributes for struct fields are
8268 generated by the routine `data_member_location_attribute' below. */
8271 add_AT_location_description (die, attr_kind, rtl)
8273 enum dwarf_attribute attr_kind;
8276 /* Handle a special case. If we are about to output a location descriptor
8277 for a variable or parameter which has been optimized out of existence,
8278 don't do that. A variable which has been optimized out
8279 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8280 Currently, in some rare cases, variables can have DECL_RTL values which
8281 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8282 elsewhere in the compiler. We treat such cases as if the variable(s) in
8283 question had been optimized out of existence. */
8285 if (is_pseudo_reg (rtl)
8286 || (GET_CODE (rtl) == MEM
8287 && is_pseudo_reg (XEXP (rtl, 0)))
8288 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8289 references the internal argument pointer (a pseudo) in a function
8290 where all references to the internal argument pointer were
8291 eliminated via the optimizers. */
8292 || (GET_CODE (rtl) == MEM
8293 && GET_CODE (XEXP (rtl, 0)) == PLUS
8294 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8295 || (GET_CODE (rtl) == CONCAT
8296 && is_pseudo_reg (XEXP (rtl, 0))
8297 && is_pseudo_reg (XEXP (rtl, 1))))
8300 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8303 /* Attach the specialized form of location attribute used for data
8304 members of struct and union types. In the special case of a
8305 FIELD_DECL node which represents a bit-field, the "offset" part
8306 of this special location descriptor must indicate the distance
8307 in bytes from the lowest-addressed byte of the containing struct
8308 or union type to the lowest-addressed byte of the "containing
8309 object" for the bit-field. (See the `field_byte_offset' function
8310 above).. For any given bit-field, the "containing object" is a
8311 hypothetical object (of some integral or enum type) within which
8312 the given bit-field lives. The type of this hypothetical
8313 "containing object" is always the same as the declared type of
8314 the individual bit-field itself (for GCC anyway... the DWARF
8315 spec doesn't actually mandate this). Note that it is the size
8316 (in bytes) of the hypothetical "containing object" which will
8317 be given in the DW_AT_byte_size attribute for this bit-field.
8318 (See the `byte_size_attribute' function below.) It is also used
8319 when calculating the value of the DW_AT_bit_offset attribute.
8320 (See the `bit_offset_attribute' function below). */
8323 add_data_member_location_attribute (die, decl)
8324 register dw_die_ref die;
8327 register unsigned long offset;
8328 register dw_loc_descr_ref loc_descr;
8329 register enum dwarf_location_atom op;
8331 if (TREE_CODE (decl) == TREE_VEC)
8332 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8334 offset = field_byte_offset (decl);
8336 /* The DWARF2 standard says that we should assume that the structure address
8337 is already on the stack, so we can specify a structure field address
8338 by using DW_OP_plus_uconst. */
8340 #ifdef MIPS_DEBUGGING_INFO
8341 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8342 correctly. It works only if we leave the offset on the stack. */
8345 op = DW_OP_plus_uconst;
8348 loc_descr = new_loc_descr (op, offset, 0);
8349 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8352 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8353 does not have a "location" either in memory or in a register. These
8354 things can arise in GNU C when a constant is passed as an actual parameter
8355 to an inlined function. They can also arise in C++ where declared
8356 constants do not necessarily get memory "homes". */
8359 add_const_value_attribute (die, rtl)
8360 register dw_die_ref die;
8363 switch (GET_CODE (rtl))
8366 /* Note that a CONST_INT rtx could represent either an integer or a
8367 floating-point constant. A CONST_INT is used whenever the constant
8368 will fit into a single word. In all such cases, the original mode
8369 of the constant value is wiped out, and the CONST_INT rtx is
8370 assigned VOIDmode. */
8371 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
8375 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8376 floating-point constant. A CONST_DOUBLE is used whenever the
8377 constant requires more than one word in order to be adequately
8378 represented. We output CONST_DOUBLEs as blocks. */
8380 register enum machine_mode mode = GET_MODE (rtl);
8382 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8384 register unsigned length = GET_MODE_SIZE (mode) / 4;
8385 long *array = (long *) xmalloc (sizeof (long) * length);
8388 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8392 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8396 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8401 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8408 add_AT_float (die, DW_AT_const_value, length, array);
8411 add_AT_long_long (die, DW_AT_const_value,
8412 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8417 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8423 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8427 /* In cases where an inlined instance of an inline function is passed
8428 the address of an `auto' variable (which is local to the caller) we
8429 can get a situation where the DECL_RTL of the artificial local
8430 variable (for the inlining) which acts as a stand-in for the
8431 corresponding formal parameter (of the inline function) will look
8432 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8433 exactly a compile-time constant expression, but it isn't the address
8434 of the (artificial) local variable either. Rather, it represents the
8435 *value* which the artificial local variable always has during its
8436 lifetime. We currently have no way to represent such quasi-constant
8437 values in Dwarf, so for now we just punt and generate nothing. */
8441 /* No other kinds of rtx should be possible here. */
8448 rtl_for_decl_location (decl)
8453 /* Here we have to decide where we are going to say the parameter "lives"
8454 (as far as the debugger is concerned). We only have a couple of
8455 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8457 DECL_RTL normally indicates where the parameter lives during most of the
8458 activation of the function. If optimization is enabled however, this
8459 could be either NULL or else a pseudo-reg. Both of those cases indicate
8460 that the parameter doesn't really live anywhere (as far as the code
8461 generation parts of GCC are concerned) during most of the function's
8462 activation. That will happen (for example) if the parameter is never
8463 referenced within the function.
8465 We could just generate a location descriptor here for all non-NULL
8466 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8467 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8468 where DECL_RTL is NULL or is a pseudo-reg.
8470 Note however that we can only get away with using DECL_INCOMING_RTL as
8471 a backup substitute for DECL_RTL in certain limited cases. In cases
8472 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8473 we can be sure that the parameter was passed using the same type as it is
8474 declared to have within the function, and that its DECL_INCOMING_RTL
8475 points us to a place where a value of that type is passed.
8477 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8478 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8479 because in these cases DECL_INCOMING_RTL points us to a value of some
8480 type which is *different* from the type of the parameter itself. Thus,
8481 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8482 such cases, the debugger would end up (for example) trying to fetch a
8483 `float' from a place which actually contains the first part of a
8484 `double'. That would lead to really incorrect and confusing
8485 output at debug-time.
8487 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8488 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8489 are a couple of exceptions however. On little-endian machines we can
8490 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8491 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8492 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8493 when (on a little-endian machine) a non-prototyped function has a
8494 parameter declared to be of type `short' or `char'. In such cases,
8495 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8496 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8497 passed `int' value. If the debugger then uses that address to fetch
8498 a `short' or a `char' (on a little-endian machine) the result will be
8499 the correct data, so we allow for such exceptional cases below.
8501 Note that our goal here is to describe the place where the given formal
8502 parameter lives during most of the function's activation (i.e. between
8503 the end of the prologue and the start of the epilogue). We'll do that
8504 as best as we can. Note however that if the given formal parameter is
8505 modified sometime during the execution of the function, then a stack
8506 backtrace (at debug-time) will show the function as having been
8507 called with the *new* value rather than the value which was
8508 originally passed in. This happens rarely enough that it is not
8509 a major problem, but it *is* a problem, and I'd like to fix it.
8511 A future version of dwarf2out.c may generate two additional
8512 attributes for any given DW_TAG_formal_parameter DIE which will
8513 describe the "passed type" and the "passed location" for the
8514 given formal parameter in addition to the attributes we now
8515 generate to indicate the "declared type" and the "active
8516 location" for each parameter. This additional set of attributes
8517 could be used by debuggers for stack backtraces. Separately, note
8518 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8519 NULL also. This happens (for example) for inlined-instances of
8520 inline function formal parameters which are never referenced.
8521 This really shouldn't be happening. All PARM_DECL nodes should
8522 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8523 doesn't currently generate these values for inlined instances of
8524 inline function parameters, so when we see such cases, we are
8525 just out-of-luck for the time being (until integrate.c
8528 /* Use DECL_RTL as the "location" unless we find something better. */
8529 rtl = DECL_RTL (decl);
8531 if (TREE_CODE (decl) == PARM_DECL)
8533 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8535 tree declared_type = type_main_variant (TREE_TYPE (decl));
8536 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8538 /* This decl represents a formal parameter which was optimized out.
8539 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8540 all* cases where (rtl == NULL_RTX) just below. */
8541 if (declared_type == passed_type)
8542 rtl = DECL_INCOMING_RTL (decl);
8543 else if (! BYTES_BIG_ENDIAN
8544 && TREE_CODE (declared_type) == INTEGER_TYPE
8545 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8546 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8547 rtl = DECL_INCOMING_RTL (decl);
8550 /* If the parm was passed in registers, but lives on the stack, then
8551 make a big endian correction if the mode of the type of the
8552 parameter is not the same as the mode of the rtl. */
8553 /* ??? This is the same series of checks that are made in dbxout.c before
8554 we reach the big endian correction code there. It isn't clear if all
8555 of these checks are necessary here, but keeping them all is the safe
8557 else if (GET_CODE (rtl) == MEM
8558 && XEXP (rtl, 0) != const0_rtx
8559 && ! CONSTANT_P (XEXP (rtl, 0))
8560 /* Not passed in memory. */
8561 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8562 /* Not passed by invisible reference. */
8563 && (GET_CODE (XEXP (rtl, 0)) != REG
8564 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8565 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8566 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8567 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8570 /* Big endian correction check. */
8572 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8573 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8576 int offset = (UNITS_PER_WORD
8577 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8578 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8579 plus_constant (XEXP (rtl, 0), offset));
8583 if (rtl != NULL_RTX)
8585 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8586 #ifdef LEAF_REG_REMAP
8587 if (current_function_uses_only_leaf_regs)
8588 leaf_renumber_regs_insn (rtl);
8595 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8596 data attribute for a variable or a parameter. We generate the
8597 DW_AT_const_value attribute only in those cases where the given variable
8598 or parameter does not have a true "location" either in memory or in a
8599 register. This can happen (for example) when a constant is passed as an
8600 actual argument in a call to an inline function. (It's possible that
8601 these things can crop up in other ways also.) Note that one type of
8602 constant value which can be passed into an inlined function is a constant
8603 pointer. This can happen for example if an actual argument in an inlined
8604 function call evaluates to a compile-time constant address. */
8607 add_location_or_const_value_attribute (die, decl)
8608 register dw_die_ref die;
8613 if (TREE_CODE (decl) == ERROR_MARK)
8616 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8619 rtl = rtl_for_decl_location (decl);
8620 if (rtl == NULL_RTX)
8623 switch (GET_CODE (rtl))
8626 /* The address of a variable that was optimized away; don't emit
8637 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8638 add_const_value_attribute (die, rtl);
8645 add_AT_location_description (die, DW_AT_location, rtl);
8653 /* If we don't have a copy of this variable in memory for some reason (such
8654 as a C++ member constant that doesn't have an out-of-line definition),
8655 we should tell the debugger about the constant value. */
8658 tree_add_const_value_attribute (var_die, decl)
8662 tree init = DECL_INITIAL (decl);
8663 tree type = TREE_TYPE (decl);
8665 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8666 && initializer_constant_valid_p (init, type) == null_pointer_node)
8671 switch (TREE_CODE (type))
8674 if (host_integerp (init, 0))
8675 add_AT_unsigned (var_die, DW_AT_const_value,
8676 TREE_INT_CST_LOW (init));
8678 add_AT_long_long (var_die, DW_AT_const_value,
8679 TREE_INT_CST_HIGH (init),
8680 TREE_INT_CST_LOW (init));
8687 /* Generate an DW_AT_name attribute given some string value to be included as
8688 the value of the attribute. */
8691 add_name_attribute (die, name_string)
8692 register dw_die_ref die;
8693 register const char *name_string;
8695 if (name_string != NULL && *name_string != 0)
8697 if (demangle_name_func)
8698 name_string = (*demangle_name_func) (name_string);
8700 add_AT_string (die, DW_AT_name, name_string);
8704 /* Given a tree node describing an array bound (either lower or upper) output
8705 a representation for that bound. */
8708 add_bound_info (subrange_die, bound_attr, bound)
8709 register dw_die_ref subrange_die;
8710 register enum dwarf_attribute bound_attr;
8711 register tree bound;
8713 /* If this is an Ada unconstrained array type, then don't emit any debug
8714 info because the array bounds are unknown. They are parameterized when
8715 the type is instantiated. */
8716 if (contains_placeholder_p (bound))
8719 switch (TREE_CODE (bound))
8724 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8726 if (! host_integerp (bound, 0)
8727 || (bound_attr == DW_AT_lower_bound
8728 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8729 || (is_fortran () && integer_onep (bound)))))
8730 /* use the default */
8733 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8738 case NON_LVALUE_EXPR:
8739 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8743 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8744 access the upper bound values may be bogus. If they refer to a
8745 register, they may only describe how to get at these values at the
8746 points in the generated code right after they have just been
8747 computed. Worse yet, in the typical case, the upper bound values
8748 will not even *be* computed in the optimized code (though the
8749 number of elements will), so these SAVE_EXPRs are entirely
8750 bogus. In order to compensate for this fact, we check here to see
8751 if optimization is enabled, and if so, we don't add an attribute
8752 for the (unknown and unknowable) upper bound. This should not
8753 cause too much trouble for existing (stupid?) debuggers because
8754 they have to deal with empty upper bounds location descriptions
8755 anyway in order to be able to deal with incomplete array types.
8756 Of course an intelligent debugger (GDB?) should be able to
8757 comprehend that a missing upper bound specification in a array
8758 type used for a storage class `auto' local array variable
8759 indicates that the upper bound is both unknown (at compile- time)
8760 and unknowable (at run-time) due to optimization.
8762 We assume that a MEM rtx is safe because gcc wouldn't put the
8763 value there unless it was going to be used repeatedly in the
8764 function, i.e. for cleanups. */
8765 if (! optimize || (SAVE_EXPR_RTL (bound)
8766 && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8768 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8769 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8770 register rtx loc = SAVE_EXPR_RTL (bound);
8772 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8773 it references an outer function's frame. */
8775 if (GET_CODE (loc) == MEM)
8777 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8779 if (XEXP (loc, 0) != new_addr)
8780 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8783 add_AT_flag (decl_die, DW_AT_artificial, 1);
8784 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8785 add_AT_location_description (decl_die, DW_AT_location, loc);
8786 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8789 /* Else leave out the attribute. */
8795 dw_die_ref decl_die = lookup_decl_die (bound);
8797 /* ??? Can this happen, or should the variable have been bound
8798 first? Probably it can, since I imagine that we try to create
8799 the types of parameters in the order in which they exist in
8800 the list, and won't have created a forward reference to a
8802 if (decl_die != NULL)
8803 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8809 /* Otherwise try to create a stack operation procedure to
8810 evaluate the value of the array bound. */
8812 dw_die_ref ctx, decl_die;
8813 dw_loc_descr_ref loc;
8815 loc = loc_descriptor_from_tree (bound, 0);
8819 ctx = lookup_decl_die (current_function_decl);
8821 decl_die = new_die (DW_TAG_variable, ctx);
8822 add_AT_flag (decl_die, DW_AT_artificial, 1);
8823 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8824 add_AT_loc (decl_die, DW_AT_location, loc);
8826 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8832 /* Note that the block of subscript information for an array type also
8833 includes information about the element type of type given array type. */
8836 add_subscript_info (type_die, type)
8837 register dw_die_ref type_die;
8840 #ifndef MIPS_DEBUGGING_INFO
8841 register unsigned dimension_number;
8843 register tree lower, upper;
8844 register dw_die_ref subrange_die;
8846 /* The GNU compilers represent multidimensional array types as sequences of
8847 one dimensional array types whose element types are themselves array
8848 types. Here we squish that down, so that each multidimensional array
8849 type gets only one array_type DIE in the Dwarf debugging info. The draft
8850 Dwarf specification say that we are allowed to do this kind of
8851 compression in C (because there is no difference between an array or
8852 arrays and a multidimensional array in C) but for other source languages
8853 (e.g. Ada) we probably shouldn't do this. */
8855 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8856 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8857 We work around this by disabling this feature. See also
8858 gen_array_type_die. */
8859 #ifndef MIPS_DEBUGGING_INFO
8860 for (dimension_number = 0;
8861 TREE_CODE (type) == ARRAY_TYPE;
8862 type = TREE_TYPE (type), dimension_number++)
8865 register tree domain = TYPE_DOMAIN (type);
8867 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8868 and (in GNU C only) variable bounds. Handle all three forms
8870 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8873 /* We have an array type with specified bounds. */
8874 lower = TYPE_MIN_VALUE (domain);
8875 upper = TYPE_MAX_VALUE (domain);
8877 /* define the index type. */
8878 if (TREE_TYPE (domain))
8880 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8881 TREE_TYPE field. We can't emit debug info for this
8882 because it is an unnamed integral type. */
8883 if (TREE_CODE (domain) == INTEGER_TYPE
8884 && TYPE_NAME (domain) == NULL_TREE
8885 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8886 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8889 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8893 /* ??? If upper is NULL, the array has unspecified length,
8894 but it does have a lower bound. This happens with Fortran
8896 Since the debugger is definitely going to need to know N
8897 to produce useful results, go ahead and output the lower
8898 bound solo, and hope the debugger can cope. */
8900 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8902 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8905 /* We have an array type with an unspecified length. The DWARF-2
8906 spec does not say how to handle this; let's just leave out the
8910 #ifndef MIPS_DEBUGGING_INFO
8916 add_byte_size_attribute (die, tree_node)
8918 register tree tree_node;
8920 register unsigned size;
8922 switch (TREE_CODE (tree_node))
8930 case QUAL_UNION_TYPE:
8931 size = int_size_in_bytes (tree_node);
8934 /* For a data member of a struct or union, the DW_AT_byte_size is
8935 generally given as the number of bytes normally allocated for an
8936 object of the *declared* type of the member itself. This is true
8937 even for bit-fields. */
8938 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8944 /* Note that `size' might be -1 when we get to this point. If it is, that
8945 indicates that the byte size of the entity in question is variable. We
8946 have no good way of expressing this fact in Dwarf at the present time,
8947 so just let the -1 pass on through. */
8949 add_AT_unsigned (die, DW_AT_byte_size, size);
8952 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8953 which specifies the distance in bits from the highest order bit of the
8954 "containing object" for the bit-field to the highest order bit of the
8957 For any given bit-field, the "containing object" is a hypothetical
8958 object (of some integral or enum type) within which the given bit-field
8959 lives. The type of this hypothetical "containing object" is always the
8960 same as the declared type of the individual bit-field itself. The
8961 determination of the exact location of the "containing object" for a
8962 bit-field is rather complicated. It's handled by the
8963 `field_byte_offset' function (above).
8965 Note that it is the size (in bytes) of the hypothetical "containing object"
8966 which will be given in the DW_AT_byte_size attribute for this bit-field.
8967 (See `byte_size_attribute' above). */
8970 add_bit_offset_attribute (die, decl)
8971 register dw_die_ref die;
8974 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8975 tree type = DECL_BIT_FIELD_TYPE (decl);
8976 HOST_WIDE_INT bitpos_int;
8977 HOST_WIDE_INT highest_order_object_bit_offset;
8978 HOST_WIDE_INT highest_order_field_bit_offset;
8979 HOST_WIDE_INT unsigned bit_offset;
8981 /* Must be a field and a bit field. */
8983 || TREE_CODE (decl) != FIELD_DECL)
8986 /* We can't yet handle bit-fields whose offsets are variable, so if we
8987 encounter such things, just return without generating any attribute
8988 whatsoever. Likewise for variable or too large size. */
8989 if (! host_integerp (bit_position (decl), 0)
8990 || ! host_integerp (DECL_SIZE (decl), 1))
8993 bitpos_int = int_bit_position (decl);
8995 /* Note that the bit offset is always the distance (in bits) from the
8996 highest-order bit of the "containing object" to the highest-order bit of
8997 the bit-field itself. Since the "high-order end" of any object or field
8998 is different on big-endian and little-endian machines, the computation
8999 below must take account of these differences. */
9000 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9001 highest_order_field_bit_offset = bitpos_int;
9003 if (! BYTES_BIG_ENDIAN)
9005 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9006 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9010 = (! BYTES_BIG_ENDIAN
9011 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9012 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9014 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9017 /* For a FIELD_DECL node which represents a bit field, output an attribute
9018 which specifies the length in bits of the given field. */
9021 add_bit_size_attribute (die, decl)
9022 register dw_die_ref die;
9025 /* Must be a field and a bit field. */
9026 if (TREE_CODE (decl) != FIELD_DECL
9027 || ! DECL_BIT_FIELD_TYPE (decl))
9030 if (host_integerp (DECL_SIZE (decl), 1))
9031 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9034 /* If the compiled language is ANSI C, then add a 'prototyped'
9035 attribute, if arg types are given for the parameters of a function. */
9038 add_prototyped_attribute (die, func_type)
9039 register dw_die_ref die;
9040 register tree func_type;
9042 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9043 && TYPE_ARG_TYPES (func_type) != NULL)
9044 add_AT_flag (die, DW_AT_prototyped, 1);
9047 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9048 by looking in either the type declaration or object declaration
9052 add_abstract_origin_attribute (die, origin)
9053 register dw_die_ref die;
9054 register tree origin;
9056 dw_die_ref origin_die = NULL;
9058 if (TREE_CODE (origin) != FUNCTION_DECL)
9060 /* We may have gotten separated from the block for the inlined
9061 function, if we're in an exception handler or some such; make
9062 sure that the abstract function has been written out.
9064 Doing this for nested functions is wrong, however; functions are
9065 distinct units, and our context might not even be inline. */
9068 fn = TYPE_STUB_DECL (fn);
9069 fn = decl_function_context (fn);
9071 gen_abstract_function (fn);
9074 if (DECL_P (origin))
9075 origin_die = lookup_decl_die (origin);
9076 else if (TYPE_P (origin))
9077 origin_die = lookup_type_die (origin);
9079 if (origin_die == NULL)
9082 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9085 /* We do not currently support the pure_virtual attribute. */
9088 add_pure_or_virtual_attribute (die, func_decl)
9089 register dw_die_ref die;
9090 register tree func_decl;
9092 if (DECL_VINDEX (func_decl))
9094 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9096 if (host_integerp (DECL_VINDEX (func_decl), 0))
9097 add_AT_loc (die, DW_AT_vtable_elem_location,
9098 new_loc_descr (DW_OP_constu,
9099 tree_low_cst (DECL_VINDEX (func_decl), 0),
9102 /* GNU extension: Record what type this method came from originally. */
9103 if (debug_info_level > DINFO_LEVEL_TERSE)
9104 add_AT_die_ref (die, DW_AT_containing_type,
9105 lookup_type_die (DECL_CONTEXT (func_decl)));
9109 /* Add source coordinate attributes for the given decl. */
9112 add_src_coords_attributes (die, decl)
9113 register dw_die_ref die;
9116 register unsigned file_index = lookup_filename (&decl_file_table,
9117 DECL_SOURCE_FILE (decl));
9119 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9120 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9123 /* Add an DW_AT_name attribute and source coordinate attribute for the
9124 given decl, but only if it actually has a name. */
9127 add_name_and_src_coords_attributes (die, decl)
9128 register dw_die_ref die;
9131 register tree decl_name;
9133 decl_name = DECL_NAME (decl);
9134 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9136 add_name_attribute (die, dwarf2_name (decl, 0));
9137 if (! DECL_ARTIFICIAL (decl))
9138 add_src_coords_attributes (die, decl);
9140 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9141 && TREE_PUBLIC (decl)
9142 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
9143 add_AT_string (die, DW_AT_MIPS_linkage_name,
9144 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9148 /* Push a new declaration scope. */
9151 push_decl_scope (scope)
9154 /* Make room in the decl_scope_table, if necessary. */
9155 if (decl_scope_table_allocated == decl_scope_depth)
9157 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
9159 = (tree *) xrealloc (decl_scope_table,
9160 decl_scope_table_allocated * sizeof (tree));
9163 decl_scope_table[decl_scope_depth] = scope;
9167 /* Pop a declaration scope. */
9171 if (decl_scope_depth <= 0)
9176 /* Return the DIE for the scope that immediately contains this type.
9177 Non-named types get global scope. Named types nested in other
9178 types get their containing scope if it's open, or global scope
9179 otherwise. All other types (i.e. function-local named types) get
9180 the current active scope. */
9183 scope_die_for (t, context_die)
9185 register dw_die_ref context_die;
9187 register dw_die_ref scope_die = NULL;
9188 register tree containing_scope;
9191 /* Non-types always go in the current scope. */
9195 containing_scope = TYPE_CONTEXT (t);
9197 /* Ignore namespaces for the moment. */
9198 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9199 containing_scope = NULL_TREE;
9201 /* Ignore function type "scopes" from the C frontend. They mean that
9202 a tagged type is local to a parmlist of a function declarator, but
9203 that isn't useful to DWARF. */
9204 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9205 containing_scope = NULL_TREE;
9207 if (containing_scope == NULL_TREE)
9208 scope_die = comp_unit_die;
9209 else if (TYPE_P (containing_scope))
9211 /* For types, we can just look up the appropriate DIE. But
9212 first we check to see if we're in the middle of emitting it
9213 so we know where the new DIE should go. */
9215 for (i = decl_scope_depth - 1; i >= 0; --i)
9216 if (decl_scope_table[i] == containing_scope)
9221 if (debug_info_level > DINFO_LEVEL_TERSE
9222 && !TREE_ASM_WRITTEN (containing_scope))
9225 /* If none of the current dies are suitable, we get file scope. */
9226 scope_die = comp_unit_die;
9229 scope_die = lookup_type_die (containing_scope);
9232 scope_die = context_die;
9237 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9239 static inline int local_scope_p PARAMS ((dw_die_ref));
9241 local_scope_p (context_die)
9242 dw_die_ref context_die;
9244 for (; context_die; context_die = context_die->die_parent)
9245 if (context_die->die_tag == DW_TAG_inlined_subroutine
9246 || context_die->die_tag == DW_TAG_subprogram)
9251 /* Returns nonzero iff CONTEXT_DIE is a class. */
9253 static inline int class_scope_p PARAMS ((dw_die_ref));
9255 class_scope_p (context_die)
9256 dw_die_ref context_die;
9259 && (context_die->die_tag == DW_TAG_structure_type
9260 || context_die->die_tag == DW_TAG_union_type));
9263 /* Many forms of DIEs require a "type description" attribute. This
9264 routine locates the proper "type descriptor" die for the type given
9265 by 'type', and adds an DW_AT_type attribute below the given die. */
9268 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9269 register dw_die_ref object_die;
9271 register int decl_const;
9272 register int decl_volatile;
9273 register dw_die_ref context_die;
9275 register enum tree_code code = TREE_CODE (type);
9276 register dw_die_ref type_die = NULL;
9278 /* ??? If this type is an unnamed subrange type of an integral or
9279 floating-point type, use the inner type. This is because we have no
9280 support for unnamed types in base_type_die. This can happen if this is
9281 an Ada subrange type. Correct solution is emit a subrange type die. */
9282 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9283 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9284 type = TREE_TYPE (type), code = TREE_CODE (type);
9286 if (code == ERROR_MARK)
9289 /* Handle a special case. For functions whose return type is void, we
9290 generate *no* type attribute. (Note that no object may have type
9291 `void', so this only applies to function return types). */
9292 if (code == VOID_TYPE)
9295 type_die = modified_type_die (type,
9296 decl_const || TYPE_READONLY (type),
9297 decl_volatile || TYPE_VOLATILE (type),
9299 if (type_die != NULL)
9300 add_AT_die_ref (object_die, DW_AT_type, type_die);
9303 /* Given a tree pointer to a struct, class, union, or enum type node, return
9304 a pointer to the (string) tag name for the given type, or zero if the type
9305 was declared without a tag. */
9311 register const char *name = 0;
9313 if (TYPE_NAME (type) != 0)
9315 register tree t = 0;
9317 /* Find the IDENTIFIER_NODE for the type name. */
9318 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9319 t = TYPE_NAME (type);
9321 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9322 a TYPE_DECL node, regardless of whether or not a `typedef' was
9324 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9325 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9326 t = DECL_NAME (TYPE_NAME (type));
9328 /* Now get the name as a string, or invent one. */
9330 name = IDENTIFIER_POINTER (t);
9333 return (name == 0 || *name == '\0') ? 0 : name;
9336 /* Return the type associated with a data member, make a special check
9337 for bit field types. */
9340 member_declared_type (member)
9341 register tree member;
9343 return (DECL_BIT_FIELD_TYPE (member)
9344 ? DECL_BIT_FIELD_TYPE (member)
9345 : TREE_TYPE (member));
9348 /* Get the decl's label, as described by its RTL. This may be different
9349 from the DECL_NAME name used in the source file. */
9353 decl_start_label (decl)
9358 x = DECL_RTL (decl);
9359 if (GET_CODE (x) != MEM)
9363 if (GET_CODE (x) != SYMBOL_REF)
9366 fnname = XSTR (x, 0);
9371 /* These routines generate the internal representation of the DIE's for
9372 the compilation unit. Debugging information is collected by walking
9373 the declaration trees passed in from dwarf2out_decl(). */
9376 gen_array_type_die (type, context_die)
9378 register dw_die_ref context_die;
9380 register dw_die_ref scope_die = scope_die_for (type, context_die);
9381 register dw_die_ref array_die;
9382 register tree element_type;
9384 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9385 the inner array type comes before the outer array type. Thus we must
9386 call gen_type_die before we call new_die. See below also. */
9387 #ifdef MIPS_DEBUGGING_INFO
9388 gen_type_die (TREE_TYPE (type), context_die);
9391 array_die = new_die (DW_TAG_array_type, scope_die);
9394 /* We default the array ordering. SDB will probably do
9395 the right things even if DW_AT_ordering is not present. It's not even
9396 an issue until we start to get into multidimensional arrays anyway. If
9397 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9398 then we'll have to put the DW_AT_ordering attribute back in. (But if
9399 and when we find out that we need to put these in, we will only do so
9400 for multidimensional arrays. */
9401 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9404 #ifdef MIPS_DEBUGGING_INFO
9405 /* The SGI compilers handle arrays of unknown bound by setting
9406 AT_declaration and not emitting any subrange DIEs. */
9407 if (! TYPE_DOMAIN (type))
9408 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9411 add_subscript_info (array_die, type);
9413 add_name_attribute (array_die, type_tag (type));
9414 equate_type_number_to_die (type, array_die);
9416 /* Add representation of the type of the elements of this array type. */
9417 element_type = TREE_TYPE (type);
9419 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9420 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9421 We work around this by disabling this feature. See also
9422 add_subscript_info. */
9423 #ifndef MIPS_DEBUGGING_INFO
9424 while (TREE_CODE (element_type) == ARRAY_TYPE)
9425 element_type = TREE_TYPE (element_type);
9427 gen_type_die (element_type, context_die);
9430 add_type_attribute (array_die, element_type, 0, 0, context_die);
9434 gen_set_type_die (type, context_die)
9436 register dw_die_ref context_die;
9438 register dw_die_ref type_die
9439 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9441 equate_type_number_to_die (type, type_die);
9442 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9447 gen_entry_point_die (decl, context_die)
9449 register dw_die_ref context_die;
9451 register tree origin = decl_ultimate_origin (decl);
9452 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9454 add_abstract_origin_attribute (decl_die, origin);
9457 add_name_and_src_coords_attributes (decl_die, decl);
9458 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9462 if (DECL_ABSTRACT (decl))
9463 equate_decl_number_to_die (decl, decl_die);
9465 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9469 /* Remember a type in the incomplete_types_list. */
9472 add_incomplete_type (type)
9475 if (incomplete_types == incomplete_types_allocated)
9477 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9478 incomplete_types_list
9479 = (tree *) xrealloc (incomplete_types_list,
9480 sizeof (tree) * incomplete_types_allocated);
9483 incomplete_types_list[incomplete_types++] = type;
9486 /* Walk through the list of incomplete types again, trying once more to
9487 emit full debugging info for them. */
9490 retry_incomplete_types ()
9494 while (incomplete_types)
9497 type = incomplete_types_list[incomplete_types];
9498 gen_type_die (type, comp_unit_die);
9502 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9505 gen_inlined_enumeration_type_die (type, context_die)
9507 register dw_die_ref context_die;
9509 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9511 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9512 be incomplete and such types are not marked. */
9513 add_abstract_origin_attribute (type_die, type);
9516 /* Generate a DIE to represent an inlined instance of a structure type. */
9519 gen_inlined_structure_type_die (type, context_die)
9521 register dw_die_ref context_die;
9523 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9525 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9526 be incomplete and such types are not marked. */
9527 add_abstract_origin_attribute (type_die, type);
9530 /* Generate a DIE to represent an inlined instance of a union type. */
9533 gen_inlined_union_type_die (type, context_die)
9535 register dw_die_ref context_die;
9537 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9539 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9540 be incomplete and such types are not marked. */
9541 add_abstract_origin_attribute (type_die, type);
9544 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9545 include all of the information about the enumeration values also. Each
9546 enumerated type name/value is listed as a child of the enumerated type
9550 gen_enumeration_type_die (type, context_die)
9552 register dw_die_ref context_die;
9554 register dw_die_ref type_die = lookup_type_die (type);
9556 if (type_die == NULL)
9558 type_die = new_die (DW_TAG_enumeration_type,
9559 scope_die_for (type, context_die));
9560 equate_type_number_to_die (type, type_die);
9561 add_name_attribute (type_die, type_tag (type));
9563 else if (! TYPE_SIZE (type))
9566 remove_AT (type_die, DW_AT_declaration);
9568 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9569 given enum type is incomplete, do not generate the DW_AT_byte_size
9570 attribute or the DW_AT_element_list attribute. */
9571 if (TYPE_SIZE (type))
9575 TREE_ASM_WRITTEN (type) = 1;
9576 add_byte_size_attribute (type_die, type);
9577 if (TYPE_STUB_DECL (type) != NULL_TREE)
9578 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9580 /* If the first reference to this type was as the return type of an
9581 inline function, then it may not have a parent. Fix this now. */
9582 if (type_die->die_parent == NULL)
9583 add_child_die (scope_die_for (type, context_die), type_die);
9585 for (link = TYPE_FIELDS (type);
9586 link != NULL; link = TREE_CHAIN (link))
9588 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9590 add_name_attribute (enum_die,
9591 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9593 if (host_integerp (TREE_VALUE (link), 0))
9595 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9596 add_AT_int (enum_die, DW_AT_const_value,
9597 tree_low_cst (TREE_VALUE (link), 0));
9599 add_AT_unsigned (enum_die, DW_AT_const_value,
9600 tree_low_cst (TREE_VALUE (link), 0));
9605 add_AT_flag (type_die, DW_AT_declaration, 1);
9608 /* Generate a DIE to represent either a real live formal parameter decl or to
9609 represent just the type of some formal parameter position in some function
9612 Note that this routine is a bit unusual because its argument may be a
9613 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9614 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9615 node. If it's the former then this function is being called to output a
9616 DIE to represent a formal parameter object (or some inlining thereof). If
9617 it's the latter, then this function is only being called to output a
9618 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9619 argument type of some subprogram type. */
9622 gen_formal_parameter_die (node, context_die)
9624 register dw_die_ref context_die;
9626 register dw_die_ref parm_die
9627 = new_die (DW_TAG_formal_parameter, context_die);
9628 register tree origin;
9630 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9633 origin = decl_ultimate_origin (node);
9635 add_abstract_origin_attribute (parm_die, origin);
9638 add_name_and_src_coords_attributes (parm_die, node);
9639 add_type_attribute (parm_die, TREE_TYPE (node),
9640 TREE_READONLY (node),
9641 TREE_THIS_VOLATILE (node),
9643 if (DECL_ARTIFICIAL (node))
9644 add_AT_flag (parm_die, DW_AT_artificial, 1);
9647 equate_decl_number_to_die (node, parm_die);
9648 if (! DECL_ABSTRACT (node))
9649 add_location_or_const_value_attribute (parm_die, node);
9654 /* We were called with some kind of a ..._TYPE node. */
9655 add_type_attribute (parm_die, node, 0, 0, context_die);
9665 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9666 at the end of an (ANSI prototyped) formal parameters list. */
9669 gen_unspecified_parameters_die (decl_or_type, context_die)
9670 register tree decl_or_type ATTRIBUTE_UNUSED;
9671 register dw_die_ref context_die;
9673 new_die (DW_TAG_unspecified_parameters, context_die);
9676 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9677 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9678 parameters as specified in some function type specification (except for
9679 those which appear as part of a function *definition*). */
9682 gen_formal_types_die (function_or_method_type, context_die)
9683 register tree function_or_method_type;
9684 register dw_die_ref context_die;
9687 register tree formal_type = NULL;
9688 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9691 /* In the case where we are generating a formal types list for a C++
9692 non-static member function type, skip over the first thing on the
9693 TYPE_ARG_TYPES list because it only represents the type of the hidden
9694 `this pointer'. The debugger should be able to figure out (without
9695 being explicitly told) that this non-static member function type takes a
9696 `this pointer' and should be able to figure what the type of that hidden
9697 parameter is from the DW_AT_member attribute of the parent
9698 DW_TAG_subroutine_type DIE. */
9699 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
9700 first_parm_type = TREE_CHAIN (first_parm_type);
9703 /* Make our first pass over the list of formal parameter types and output a
9704 DW_TAG_formal_parameter DIE for each one. */
9705 for (link = first_parm_type; link; link = TREE_CHAIN (link))
9707 register dw_die_ref parm_die;
9709 formal_type = TREE_VALUE (link);
9710 if (formal_type == void_type_node)
9713 /* Output a (nameless) DIE to represent the formal parameter itself. */
9714 parm_die = gen_formal_parameter_die (formal_type, context_die);
9715 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
9716 && link == first_parm_type)
9717 add_AT_flag (parm_die, DW_AT_artificial, 1);
9720 /* If this function type has an ellipsis, add a
9721 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9722 if (formal_type != void_type_node)
9723 gen_unspecified_parameters_die (function_or_method_type, context_die);
9725 /* Make our second (and final) pass over the list of formal parameter types
9726 and output DIEs to represent those types (as necessary). */
9727 for (link = TYPE_ARG_TYPES (function_or_method_type);
9729 link = TREE_CHAIN (link))
9731 formal_type = TREE_VALUE (link);
9732 if (formal_type == void_type_node)
9735 gen_type_die (formal_type, context_die);
9739 /* We want to generate the DIE for TYPE so that we can generate the
9740 die for MEMBER, which has been defined; we will need to refer back
9741 to the member declaration nested within TYPE. If we're trying to
9742 generate minimal debug info for TYPE, processing TYPE won't do the
9743 trick; we need to attach the member declaration by hand. */
9746 gen_type_die_for_member (type, member, context_die)
9748 dw_die_ref context_die;
9750 gen_type_die (type, context_die);
9752 /* If we're trying to avoid duplicate debug info, we may not have
9753 emitted the member decl for this function. Emit it now. */
9754 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9755 && ! lookup_decl_die (member))
9757 if (decl_ultimate_origin (member))
9760 push_decl_scope (type);
9761 if (TREE_CODE (member) == FUNCTION_DECL)
9762 gen_subprogram_die (member, lookup_type_die (type));
9764 gen_variable_die (member, lookup_type_die (type));
9769 /* Generate the DWARF2 info for the "abstract" instance
9770 of a function which we may later generate inlined and/or
9771 out-of-line instances of. */
9774 gen_abstract_function (decl)
9777 register dw_die_ref old_die = lookup_decl_die (decl);
9780 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9781 /* We've already generated the abstract instance. */
9784 save_fn = current_function_decl;
9785 current_function_decl = decl;
9787 set_decl_abstract_flags (decl, 1);
9788 dwarf2out_decl (decl);
9789 set_decl_abstract_flags (decl, 0);
9791 current_function_decl = save_fn;
9794 /* Generate a DIE to represent a declared function (either file-scope or
9798 gen_subprogram_die (decl, context_die)
9800 register dw_die_ref context_die;
9802 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9803 register tree origin = decl_ultimate_origin (decl);
9804 register dw_die_ref subr_die;
9805 register rtx fp_reg;
9806 register tree fn_arg_types;
9807 register tree outer_scope;
9808 register dw_die_ref old_die = lookup_decl_die (decl);
9809 register int declaration = (current_function_decl != decl
9810 || class_scope_p (context_die));
9812 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9813 be true, if we started to generate the abstract instance of an inline,
9814 decided to output its containing class, and proceeded to emit the
9815 declaration of the inline from the member list for the class. In that
9816 case, `declaration' takes priority; we'll get back to the abstract
9817 instance when we're done with the class. */
9819 /* The class-scope declaration DIE must be the primary DIE. */
9820 if (origin && declaration && class_scope_p (context_die))
9829 if (declaration && ! local_scope_p (context_die))
9832 /* Fixup die_parent for the abstract instance of a nested
9834 if (old_die && old_die->die_parent == NULL)
9835 add_child_die (context_die, old_die);
9837 subr_die = new_die (DW_TAG_subprogram, context_die);
9838 add_abstract_origin_attribute (subr_die, origin);
9840 else if (old_die && DECL_ABSTRACT (decl)
9841 && get_AT_unsigned (old_die, DW_AT_inline))
9843 /* This must be a redefinition of an extern inline function.
9844 We can just reuse the old die here. */
9847 /* Clear out the inlined attribute and parm types. */
9848 remove_AT (subr_die, DW_AT_inline);
9849 remove_children (subr_die);
9853 register unsigned file_index
9854 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
9856 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
9858 /* ??? This can happen if there is a bug in the program, for
9859 instance, if it has duplicate function definitions. Ideally,
9860 we should detect this case and ignore it. For now, if we have
9861 already reported an error, any error at all, then assume that
9862 we got here because of a input error, not a dwarf2 bug. */
9868 /* If the definition comes from the same place as the declaration,
9869 maybe use the old DIE. We always want the DIE for this function
9870 that has the *_pc attributes to be under comp_unit_die so the
9871 debugger can find it. We also need to do this for abstract
9872 instances of inlines, since the spec requires the out-of-line copy
9873 to have the same parent. For local class methods, this doesn't
9874 apply; we just use the old DIE. */
9875 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9876 && (DECL_ARTIFICIAL (decl)
9877 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9878 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9879 == (unsigned) DECL_SOURCE_LINE (decl)))))
9883 /* Clear out the declaration attribute and the parm types. */
9884 remove_AT (subr_die, DW_AT_declaration);
9885 remove_children (subr_die);
9889 subr_die = new_die (DW_TAG_subprogram, context_die);
9890 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9891 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9892 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9893 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9894 != (unsigned) DECL_SOURCE_LINE (decl))
9896 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9901 subr_die = new_die (DW_TAG_subprogram, context_die);
9903 if (TREE_PUBLIC (decl))
9904 add_AT_flag (subr_die, DW_AT_external, 1);
9906 add_name_and_src_coords_attributes (subr_die, decl);
9907 if (debug_info_level > DINFO_LEVEL_TERSE)
9909 register tree type = TREE_TYPE (decl);
9911 add_prototyped_attribute (subr_die, type);
9912 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9915 add_pure_or_virtual_attribute (subr_die, decl);
9916 if (DECL_ARTIFICIAL (decl))
9917 add_AT_flag (subr_die, DW_AT_artificial, 1);
9918 if (TREE_PROTECTED (decl))
9919 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9920 else if (TREE_PRIVATE (decl))
9921 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9927 add_AT_flag (subr_die, DW_AT_declaration, 1);
9929 /* The first time we see a member function, it is in the context of
9930 the class to which it belongs. We make sure of this by emitting
9931 the class first. The next time is the definition, which is
9932 handled above. The two may come from the same source text. */
9933 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9934 equate_decl_number_to_die (decl, subr_die);
9936 else if (DECL_ABSTRACT (decl))
9938 if (DECL_INLINE (decl) && !flag_no_inline)
9940 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9941 inline functions, but not for extern inline functions.
9942 We can't get this completely correct because information
9943 about whether the function was declared inline is not
9945 if (DECL_DEFER_OUTPUT (decl))
9946 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9948 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9951 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9953 equate_decl_number_to_die (decl, subr_die);
9955 else if (!DECL_EXTERNAL (decl))
9957 if (origin == NULL_TREE)
9958 equate_decl_number_to_die (decl, subr_die);
9960 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9961 current_funcdef_number);
9962 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9963 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9964 current_funcdef_number);
9965 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9967 add_pubname (decl, subr_die);
9968 add_arange (decl, subr_die);
9970 #ifdef MIPS_DEBUGGING_INFO
9971 /* Add a reference to the FDE for this routine. */
9972 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9975 /* Define the "frame base" location for this routine. We use the
9976 frame pointer or stack pointer registers, since the RTL for local
9977 variables is relative to one of them. */
9979 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9980 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9983 /* ??? This fails for nested inline functions, because context_display
9984 is not part of the state saved/restored for inline functions. */
9985 if (current_function_needs_context)
9986 add_AT_location_description (subr_die, DW_AT_static_link,
9987 lookup_static_chain (decl));
9991 /* Now output descriptions of the arguments for this function. This gets
9992 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9993 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9994 `...' at the end of the formal parameter list. In order to find out if
9995 there was a trailing ellipsis or not, we must instead look at the type
9996 associated with the FUNCTION_DECL. This will be a node of type
9997 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9998 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9999 an ellipsis at the end. */
10001 /* In the case where we are describing a mere function declaration, all we
10002 need to do here (and all we *can* do here) is to describe the *types* of
10003 its formal parameters. */
10004 if (debug_info_level <= DINFO_LEVEL_TERSE)
10006 else if (declaration)
10007 gen_formal_types_die (TREE_TYPE (decl), subr_die);
10010 /* Generate DIEs to represent all known formal parameters */
10011 register tree arg_decls = DECL_ARGUMENTS (decl);
10012 register tree parm;
10014 /* When generating DIEs, generate the unspecified_parameters DIE
10015 instead if we come across the arg "__builtin_va_alist" */
10016 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10017 if (TREE_CODE (parm) == PARM_DECL)
10019 if (DECL_NAME (parm)
10020 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10021 "__builtin_va_alist"))
10022 gen_unspecified_parameters_die (parm, subr_die);
10024 gen_decl_die (parm, subr_die);
10027 /* Decide whether we need a unspecified_parameters DIE at the end.
10028 There are 2 more cases to do this for: 1) the ansi ... declaration -
10029 this is detectable when the end of the arg list is not a
10030 void_type_node 2) an unprototyped function declaration (not a
10031 definition). This just means that we have no info about the
10032 parameters at all. */
10033 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10034 if (fn_arg_types != NULL)
10036 /* this is the prototyped case, check for ... */
10037 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10038 gen_unspecified_parameters_die (decl, subr_die);
10040 else if (DECL_INITIAL (decl) == NULL_TREE)
10041 gen_unspecified_parameters_die (decl, subr_die);
10044 /* Output Dwarf info for all of the stuff within the body of the function
10045 (if it has one - it may be just a declaration). */
10046 outer_scope = DECL_INITIAL (decl);
10048 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
10049 node created to represent a function. This outermost BLOCK actually
10050 represents the outermost binding contour for the function, i.e. the
10051 contour in which the function's formal parameters and labels get
10052 declared. Curiously, it appears that the front end doesn't actually
10053 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
10054 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
10055 list for the function instead.) The BLOCK_VARS list for the
10056 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
10057 the function however, and we output DWARF info for those in
10058 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
10059 node representing the function's outermost pair of curly braces, and
10060 any blocks used for the base and member initializers of a C++
10061 constructor function. */
10062 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10064 current_function_has_inlines = 0;
10065 decls_for_scope (outer_scope, subr_die, 0);
10067 #if 0 && defined (MIPS_DEBUGGING_INFO)
10068 if (current_function_has_inlines)
10070 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10071 if (! comp_unit_has_inlines)
10073 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10074 comp_unit_has_inlines = 1;
10081 /* Generate a DIE to represent a declared data object. */
10084 gen_variable_die (decl, context_die)
10085 register tree decl;
10086 register dw_die_ref context_die;
10088 register tree origin = decl_ultimate_origin (decl);
10089 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
10091 dw_die_ref old_die = lookup_decl_die (decl);
10092 int declaration = (DECL_EXTERNAL (decl)
10093 || class_scope_p (context_die));
10095 if (origin != NULL)
10096 add_abstract_origin_attribute (var_die, origin);
10097 /* Loop unrolling can create multiple blocks that refer to the same
10098 static variable, so we must test for the DW_AT_declaration flag. */
10099 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10100 copy decls and set the DECL_ABSTRACT flag on them instead of
10102 else if (old_die && TREE_STATIC (decl)
10103 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10105 /* This is a definition of a C++ class level static. */
10106 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10107 if (DECL_NAME (decl))
10109 register unsigned file_index
10110 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
10112 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10113 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10115 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10116 != (unsigned) DECL_SOURCE_LINE (decl))
10118 add_AT_unsigned (var_die, DW_AT_decl_line,
10119 DECL_SOURCE_LINE (decl));
10124 add_name_and_src_coords_attributes (var_die, decl);
10125 add_type_attribute (var_die, TREE_TYPE (decl),
10126 TREE_READONLY (decl),
10127 TREE_THIS_VOLATILE (decl), context_die);
10129 if (TREE_PUBLIC (decl))
10130 add_AT_flag (var_die, DW_AT_external, 1);
10132 if (DECL_ARTIFICIAL (decl))
10133 add_AT_flag (var_die, DW_AT_artificial, 1);
10135 if (TREE_PROTECTED (decl))
10136 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10138 else if (TREE_PRIVATE (decl))
10139 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10143 add_AT_flag (var_die, DW_AT_declaration, 1);
10145 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10146 equate_decl_number_to_die (decl, var_die);
10148 if (! declaration && ! DECL_ABSTRACT (decl))
10150 add_location_or_const_value_attribute (var_die, decl);
10151 add_pubname (decl, var_die);
10154 tree_add_const_value_attribute (var_die, decl);
10157 /* Generate a DIE to represent a label identifier. */
10160 gen_label_die (decl, context_die)
10161 register tree decl;
10162 register dw_die_ref context_die;
10164 register tree origin = decl_ultimate_origin (decl);
10165 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
10167 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10169 if (origin != NULL)
10170 add_abstract_origin_attribute (lbl_die, origin);
10172 add_name_and_src_coords_attributes (lbl_die, decl);
10174 if (DECL_ABSTRACT (decl))
10175 equate_decl_number_to_die (decl, lbl_die);
10178 insn = DECL_RTL (decl);
10180 /* Deleted labels are programmer specified labels which have been
10181 eliminated because of various optimisations. We still emit them
10182 here so that it is possible to put breakpoints on them. */
10183 if (GET_CODE (insn) == CODE_LABEL
10184 || ((GET_CODE (insn) == NOTE
10185 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10187 /* When optimization is enabled (via -O) some parts of the compiler
10188 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10189 represent source-level labels which were explicitly declared by
10190 the user. This really shouldn't be happening though, so catch
10191 it if it ever does happen. */
10192 if (INSN_DELETED_P (insn))
10195 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10196 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10201 /* Generate a DIE for a lexical block. */
10204 gen_lexical_block_die (stmt, context_die, depth)
10205 register tree stmt;
10206 register dw_die_ref context_die;
10209 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10210 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10212 if (! BLOCK_ABSTRACT (stmt))
10214 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10215 BLOCK_NUMBER (stmt));
10216 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10217 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10218 BLOCK_NUMBER (stmt));
10219 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10222 decls_for_scope (stmt, stmt_die, depth);
10225 /* Generate a DIE for an inlined subprogram. */
10228 gen_inlined_subroutine_die (stmt, context_die, depth)
10229 register tree stmt;
10230 register dw_die_ref context_die;
10233 if (! BLOCK_ABSTRACT (stmt))
10235 register dw_die_ref subr_die
10236 = new_die (DW_TAG_inlined_subroutine, context_die);
10237 register tree decl = block_ultimate_origin (stmt);
10238 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10240 /* Emit info for the abstract instance first, if we haven't yet. */
10241 gen_abstract_function (decl);
10243 add_abstract_origin_attribute (subr_die, decl);
10244 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10245 BLOCK_NUMBER (stmt));
10246 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10247 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10248 BLOCK_NUMBER (stmt));
10249 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10250 decls_for_scope (stmt, subr_die, depth);
10251 current_function_has_inlines = 1;
10255 /* Generate a DIE for a field in a record, or structure. */
10258 gen_field_die (decl, context_die)
10259 register tree decl;
10260 register dw_die_ref context_die;
10262 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10264 add_name_and_src_coords_attributes (decl_die, decl);
10265 add_type_attribute (decl_die, member_declared_type (decl),
10266 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10269 /* If this is a bit field... */
10270 if (DECL_BIT_FIELD_TYPE (decl))
10272 add_byte_size_attribute (decl_die, decl);
10273 add_bit_size_attribute (decl_die, decl);
10274 add_bit_offset_attribute (decl_die, decl);
10277 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10278 add_data_member_location_attribute (decl_die, decl);
10280 if (DECL_ARTIFICIAL (decl))
10281 add_AT_flag (decl_die, DW_AT_artificial, 1);
10283 if (TREE_PROTECTED (decl))
10284 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10286 else if (TREE_PRIVATE (decl))
10287 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10291 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10292 Use modified_type_die instead.
10293 We keep this code here just in case these types of DIEs may be needed to
10294 represent certain things in other languages (e.g. Pascal) someday. */
10296 gen_pointer_type_die (type, context_die)
10297 register tree type;
10298 register dw_die_ref context_die;
10300 register dw_die_ref ptr_die
10301 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10303 equate_type_number_to_die (type, ptr_die);
10304 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10305 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10308 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10309 Use modified_type_die instead.
10310 We keep this code here just in case these types of DIEs may be needed to
10311 represent certain things in other languages (e.g. Pascal) someday. */
10313 gen_reference_type_die (type, context_die)
10314 register tree type;
10315 register dw_die_ref context_die;
10317 register dw_die_ref ref_die
10318 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10320 equate_type_number_to_die (type, ref_die);
10321 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10322 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10326 /* Generate a DIE for a pointer to a member type. */
10328 gen_ptr_to_mbr_type_die (type, context_die)
10329 register tree type;
10330 register dw_die_ref context_die;
10332 register dw_die_ref ptr_die
10333 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10335 equate_type_number_to_die (type, ptr_die);
10336 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10337 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10338 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10341 /* Generate the DIE for the compilation unit. */
10344 gen_compile_unit_die (filename)
10345 register const char *filename;
10347 register dw_die_ref die;
10348 char producer[250];
10349 const char *wd = getpwd ();
10352 die = new_die (DW_TAG_compile_unit, NULL);
10353 add_name_attribute (die, filename);
10355 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10356 add_AT_string (die, DW_AT_comp_dir, wd);
10358 sprintf (producer, "%s %s", language_string, version_string);
10360 #ifdef MIPS_DEBUGGING_INFO
10361 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10362 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10363 not appear in the producer string, the debugger reaches the conclusion
10364 that the object file is stripped and has no debugging information.
10365 To get the MIPS/SGI debugger to believe that there is debugging
10366 information in the object file, we add a -g to the producer string. */
10367 if (debug_info_level > DINFO_LEVEL_TERSE)
10368 strcat (producer, " -g");
10371 add_AT_string (die, DW_AT_producer, producer);
10373 if (strcmp (language_string, "GNU C++") == 0)
10374 language = DW_LANG_C_plus_plus;
10375 else if (strcmp (language_string, "GNU Ada") == 0)
10376 language = DW_LANG_Ada83;
10377 else if (strcmp (language_string, "GNU F77") == 0)
10378 language = DW_LANG_Fortran77;
10379 else if (strcmp (language_string, "GNU Pascal") == 0)
10380 language = DW_LANG_Pascal83;
10381 else if (strcmp (language_string, "GNU Java") == 0)
10382 language = DW_LANG_Java;
10383 else if (flag_traditional)
10384 language = DW_LANG_C;
10386 language = DW_LANG_C89;
10388 add_AT_unsigned (die, DW_AT_language, language);
10393 /* Generate a DIE for a string type. */
10396 gen_string_type_die (type, context_die)
10397 register tree type;
10398 register dw_die_ref context_die;
10400 register dw_die_ref type_die
10401 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10403 equate_type_number_to_die (type, type_die);
10405 /* Fudge the string length attribute for now. */
10407 /* TODO: add string length info.
10408 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10409 bound_representation (upper_bound, 0, 'u'); */
10412 /* Generate the DIE for a base class. */
10415 gen_inheritance_die (binfo, context_die)
10416 register tree binfo;
10417 register dw_die_ref context_die;
10419 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10421 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10422 add_data_member_location_attribute (die, binfo);
10424 if (TREE_VIA_VIRTUAL (binfo))
10425 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10426 if (TREE_VIA_PUBLIC (binfo))
10427 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10428 else if (TREE_VIA_PROTECTED (binfo))
10429 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10432 /* Generate a DIE for a class member. */
10435 gen_member_die (type, context_die)
10436 register tree type;
10437 register dw_die_ref context_die;
10439 register tree member;
10442 /* If this is not an incomplete type, output descriptions of each of its
10443 members. Note that as we output the DIEs necessary to represent the
10444 members of this record or union type, we will also be trying to output
10445 DIEs to represent the *types* of those members. However the `type'
10446 function (above) will specifically avoid generating type DIEs for member
10447 types *within* the list of member DIEs for this (containing) type execpt
10448 for those types (of members) which are explicitly marked as also being
10449 members of this (containing) type themselves. The g++ front- end can
10450 force any given type to be treated as a member of some other
10451 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10452 to point to the TREE node representing the appropriate (containing)
10455 /* First output info about the base classes. */
10456 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10458 register tree bases = TYPE_BINFO_BASETYPES (type);
10459 register int n_bases = TREE_VEC_LENGTH (bases);
10462 for (i = 0; i < n_bases; i++)
10463 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10466 /* Now output info about the data members and type members. */
10467 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10469 /* If we thought we were generating minimal debug info for TYPE
10470 and then changed our minds, some of the member declarations
10471 may have already been defined. Don't define them again, but
10472 do put them in the right order. */
10474 child = lookup_decl_die (member);
10476 splice_child_die (context_die, child);
10478 gen_decl_die (member, context_die);
10481 /* Now output info about the function members (if any). */
10482 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10484 child = lookup_decl_die (member);
10486 splice_child_die (context_die, child);
10488 gen_decl_die (member, context_die);
10492 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10493 is set, we pretend that the type was never defined, so we only get the
10494 member DIEs needed by later specification DIEs. */
10497 gen_struct_or_union_type_die (type, context_die)
10498 register tree type;
10499 register dw_die_ref context_die;
10501 register dw_die_ref type_die = lookup_type_die (type);
10502 register dw_die_ref scope_die = 0;
10503 register int nested = 0;
10504 int complete = (TYPE_SIZE (type)
10505 && (! TYPE_STUB_DECL (type)
10506 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10508 if (type_die && ! complete)
10511 if (TYPE_CONTEXT (type) != NULL_TREE
10512 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10515 scope_die = scope_die_for (type, context_die);
10517 if (! type_die || (nested && scope_die == comp_unit_die))
10518 /* First occurrence of type or toplevel definition of nested class. */
10520 register dw_die_ref old_die = type_die;
10522 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10523 ? DW_TAG_structure_type : DW_TAG_union_type,
10525 equate_type_number_to_die (type, type_die);
10527 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10529 add_name_attribute (type_die, type_tag (type));
10532 remove_AT (type_die, DW_AT_declaration);
10534 /* If this type has been completed, then give it a byte_size attribute and
10535 then give a list of members. */
10538 /* Prevent infinite recursion in cases where the type of some member of
10539 this type is expressed in terms of this type itself. */
10540 TREE_ASM_WRITTEN (type) = 1;
10541 add_byte_size_attribute (type_die, type);
10542 if (TYPE_STUB_DECL (type) != NULL_TREE)
10543 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10545 /* If the first reference to this type was as the return type of an
10546 inline function, then it may not have a parent. Fix this now. */
10547 if (type_die->die_parent == NULL)
10548 add_child_die (scope_die, type_die);
10550 push_decl_scope (type);
10551 gen_member_die (type, type_die);
10554 /* GNU extension: Record what type our vtable lives in. */
10555 if (TYPE_VFIELD (type))
10557 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10559 gen_type_die (vtype, context_die);
10560 add_AT_die_ref (type_die, DW_AT_containing_type,
10561 lookup_type_die (vtype));
10566 add_AT_flag (type_die, DW_AT_declaration, 1);
10568 /* We don't need to do this for function-local types. */
10569 if (! decl_function_context (TYPE_STUB_DECL (type)))
10570 add_incomplete_type (type);
10574 /* Generate a DIE for a subroutine _type_. */
10577 gen_subroutine_type_die (type, context_die)
10578 register tree type;
10579 register dw_die_ref context_die;
10581 register tree return_type = TREE_TYPE (type);
10582 register dw_die_ref subr_die
10583 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10585 equate_type_number_to_die (type, subr_die);
10586 add_prototyped_attribute (subr_die, type);
10587 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10588 gen_formal_types_die (type, subr_die);
10591 /* Generate a DIE for a type definition */
10594 gen_typedef_die (decl, context_die)
10595 register tree decl;
10596 register dw_die_ref context_die;
10598 register dw_die_ref type_die;
10599 register tree origin;
10601 if (TREE_ASM_WRITTEN (decl))
10603 TREE_ASM_WRITTEN (decl) = 1;
10605 type_die = new_die (DW_TAG_typedef, context_die);
10606 origin = decl_ultimate_origin (decl);
10607 if (origin != NULL)
10608 add_abstract_origin_attribute (type_die, origin);
10611 register tree type;
10612 add_name_and_src_coords_attributes (type_die, decl);
10613 if (DECL_ORIGINAL_TYPE (decl))
10615 type = DECL_ORIGINAL_TYPE (decl);
10617 if (type == TREE_TYPE (decl))
10620 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10623 type = TREE_TYPE (decl);
10624 add_type_attribute (type_die, type, TREE_READONLY (decl),
10625 TREE_THIS_VOLATILE (decl), context_die);
10628 if (DECL_ABSTRACT (decl))
10629 equate_decl_number_to_die (decl, type_die);
10632 /* Generate a type description DIE. */
10635 gen_type_die (type, context_die)
10636 register tree type;
10637 register dw_die_ref context_die;
10641 if (type == NULL_TREE || type == error_mark_node)
10644 /* We are going to output a DIE to represent the unqualified version of
10645 this type (i.e. without any const or volatile qualifiers) so get the
10646 main variant (i.e. the unqualified version) of this type now. */
10647 type = type_main_variant (type);
10649 if (TREE_ASM_WRITTEN (type))
10652 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10653 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10655 TREE_ASM_WRITTEN (type) = 1;
10656 gen_decl_die (TYPE_NAME (type), context_die);
10660 switch (TREE_CODE (type))
10666 case REFERENCE_TYPE:
10667 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10668 ensures that the gen_type_die recursion will terminate even if the
10669 type is recursive. Recursive types are possible in Ada. */
10670 /* ??? We could perhaps do this for all types before the switch
10672 TREE_ASM_WRITTEN (type) = 1;
10674 /* For these types, all that is required is that we output a DIE (or a
10675 set of DIEs) to represent the "basis" type. */
10676 gen_type_die (TREE_TYPE (type), context_die);
10680 /* This code is used for C++ pointer-to-data-member types.
10681 Output a description of the relevant class type. */
10682 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10684 /* Output a description of the type of the object pointed to. */
10685 gen_type_die (TREE_TYPE (type), context_die);
10687 /* Now output a DIE to represent this pointer-to-data-member type
10689 gen_ptr_to_mbr_type_die (type, context_die);
10693 gen_type_die (TYPE_DOMAIN (type), context_die);
10694 gen_set_type_die (type, context_die);
10698 gen_type_die (TREE_TYPE (type), context_die);
10699 abort (); /* No way to represent these in Dwarf yet! */
10702 case FUNCTION_TYPE:
10703 /* Force out return type (in case it wasn't forced out already). */
10704 gen_type_die (TREE_TYPE (type), context_die);
10705 gen_subroutine_type_die (type, context_die);
10709 /* Force out return type (in case it wasn't forced out already). */
10710 gen_type_die (TREE_TYPE (type), context_die);
10711 gen_subroutine_type_die (type, context_die);
10715 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10717 gen_type_die (TREE_TYPE (type), context_die);
10718 gen_string_type_die (type, context_die);
10721 gen_array_type_die (type, context_die);
10725 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10728 case ENUMERAL_TYPE:
10731 case QUAL_UNION_TYPE:
10732 /* If this is a nested type whose containing class hasn't been
10733 written out yet, writing it out will cover this one, too.
10734 This does not apply to instantiations of member class templates;
10735 they need to be added to the containing class as they are
10736 generated. FIXME: This hurts the idea of combining type decls
10737 from multiple TUs, since we can't predict what set of template
10738 instantiations we'll get. */
10739 if (TYPE_CONTEXT (type)
10740 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10741 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10743 gen_type_die (TYPE_CONTEXT (type), context_die);
10745 if (TREE_ASM_WRITTEN (type))
10748 /* If that failed, attach ourselves to the stub. */
10749 push_decl_scope (TYPE_CONTEXT (type));
10750 context_die = lookup_type_die (TYPE_CONTEXT (type));
10756 if (TREE_CODE (type) == ENUMERAL_TYPE)
10757 gen_enumeration_type_die (type, context_die);
10759 gen_struct_or_union_type_die (type, context_die);
10764 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10765 it up if it is ever completed. gen_*_type_die will set it for us
10766 when appropriate. */
10775 /* No DIEs needed for fundamental types. */
10779 /* No Dwarf representation currently defined. */
10786 TREE_ASM_WRITTEN (type) = 1;
10789 /* Generate a DIE for a tagged type instantiation. */
10792 gen_tagged_type_instantiation_die (type, context_die)
10793 register tree type;
10794 register dw_die_ref context_die;
10796 if (type == NULL_TREE || type == error_mark_node)
10799 /* We are going to output a DIE to represent the unqualified version of
10800 this type (i.e. without any const or volatile qualifiers) so make sure
10801 that we have the main variant (i.e. the unqualified version) of this
10803 if (type != type_main_variant (type))
10806 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10807 an instance of an unresolved type. */
10809 switch (TREE_CODE (type))
10814 case ENUMERAL_TYPE:
10815 gen_inlined_enumeration_type_die (type, context_die);
10819 gen_inlined_structure_type_die (type, context_die);
10823 case QUAL_UNION_TYPE:
10824 gen_inlined_union_type_die (type, context_die);
10832 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10833 things which are local to the given block. */
10836 gen_block_die (stmt, context_die, depth)
10837 register tree stmt;
10838 register dw_die_ref context_die;
10841 register int must_output_die = 0;
10842 register tree origin;
10843 register tree decl;
10844 register enum tree_code origin_code;
10846 /* Ignore blocks never really used to make RTL. */
10848 if (stmt == NULL_TREE || !TREE_USED (stmt)
10849 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10852 /* Determine the "ultimate origin" of this block. This block may be an
10853 inlined instance of an inlined instance of inline function, so we have
10854 to trace all of the way back through the origin chain to find out what
10855 sort of node actually served as the original seed for the creation of
10856 the current block. */
10857 origin = block_ultimate_origin (stmt);
10858 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10860 /* Determine if we need to output any Dwarf DIEs at all to represent this
10862 if (origin_code == FUNCTION_DECL)
10863 /* The outer scopes for inlinings *must* always be represented. We
10864 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10865 must_output_die = 1;
10868 /* In the case where the current block represents an inlining of the
10869 "body block" of an inline function, we must *NOT* output any DIE for
10870 this block because we have already output a DIE to represent the
10871 whole inlined function scope and the "body block" of any function
10872 doesn't really represent a different scope according to ANSI C
10873 rules. So we check here to make sure that this block does not
10874 represent a "body block inlining" before trying to set the
10875 `must_output_die' flag. */
10876 if (! is_body_block (origin ? origin : stmt))
10878 /* Determine if this block directly contains any "significant"
10879 local declarations which we will need to output DIEs for. */
10880 if (debug_info_level > DINFO_LEVEL_TERSE)
10881 /* We are not in terse mode so *any* local declaration counts
10882 as being a "significant" one. */
10883 must_output_die = (BLOCK_VARS (stmt) != NULL);
10885 /* We are in terse mode, so only local (nested) function
10886 definitions count as "significant" local declarations. */
10887 for (decl = BLOCK_VARS (stmt);
10888 decl != NULL; decl = TREE_CHAIN (decl))
10889 if (TREE_CODE (decl) == FUNCTION_DECL
10890 && DECL_INITIAL (decl))
10892 must_output_die = 1;
10898 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10899 DIE for any block which contains no significant local declarations at
10900 all. Rather, in such cases we just call `decls_for_scope' so that any
10901 needed Dwarf info for any sub-blocks will get properly generated. Note
10902 that in terse mode, our definition of what constitutes a "significant"
10903 local declaration gets restricted to include only inlined function
10904 instances and local (nested) function definitions. */
10905 if (must_output_die)
10907 if (origin_code == FUNCTION_DECL)
10908 gen_inlined_subroutine_die (stmt, context_die, depth);
10910 gen_lexical_block_die (stmt, context_die, depth);
10913 decls_for_scope (stmt, context_die, depth);
10916 /* Generate all of the decls declared within a given scope and (recursively)
10917 all of its sub-blocks. */
10920 decls_for_scope (stmt, context_die, depth)
10921 register tree stmt;
10922 register dw_die_ref context_die;
10925 register tree decl;
10926 register tree subblocks;
10928 /* Ignore blocks never really used to make RTL. */
10929 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10932 /* Output the DIEs to represent all of the data objects and typedefs
10933 declared directly within this block but not within any nested
10934 sub-blocks. Also, nested function and tag DIEs have been
10935 generated with a parent of NULL; fix that up now. */
10936 for (decl = BLOCK_VARS (stmt);
10937 decl != NULL; decl = TREE_CHAIN (decl))
10939 register dw_die_ref die;
10941 if (TREE_CODE (decl) == FUNCTION_DECL)
10942 die = lookup_decl_die (decl);
10943 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10944 die = lookup_type_die (TREE_TYPE (decl));
10948 if (die != NULL && die->die_parent == NULL)
10949 add_child_die (context_die, die);
10951 gen_decl_die (decl, context_die);
10954 /* Output the DIEs to represent all sub-blocks (and the items declared
10955 therein) of this block. */
10956 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10958 subblocks = BLOCK_CHAIN (subblocks))
10959 gen_block_die (subblocks, context_die, depth + 1);
10962 /* Is this a typedef we can avoid emitting? */
10965 is_redundant_typedef (decl)
10966 register tree decl;
10968 if (TYPE_DECL_IS_STUB (decl))
10971 if (DECL_ARTIFICIAL (decl)
10972 && DECL_CONTEXT (decl)
10973 && is_tagged_type (DECL_CONTEXT (decl))
10974 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10975 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10976 /* Also ignore the artificial member typedef for the class name. */
10982 /* Generate Dwarf debug information for a decl described by DECL. */
10985 gen_decl_die (decl, context_die)
10986 register tree decl;
10987 register dw_die_ref context_die;
10989 register tree origin;
10991 if (TREE_CODE (decl) == ERROR_MARK)
10994 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10995 if (DECL_IGNORED_P (decl))
10998 switch (TREE_CODE (decl))
11001 /* The individual enumerators of an enum type get output when we output
11002 the Dwarf representation of the relevant enum type itself. */
11005 case FUNCTION_DECL:
11006 /* Don't output any DIEs to represent mere function declarations,
11007 unless they are class members or explicit block externs. */
11008 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11009 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11012 /* If we're emitting an out-of-line copy of an inline function,
11013 emit info for the abstract instance and set up to refer to it. */
11014 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11015 && ! class_scope_p (context_die)
11016 /* gen_abstract_function won't emit a die if this is just a
11017 declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11018 that case, because that works only if we have a die. */
11019 && DECL_INITIAL (decl) != NULL_TREE)
11021 gen_abstract_function (decl);
11022 set_decl_origin_self (decl);
11025 if (debug_info_level > DINFO_LEVEL_TERSE)
11027 /* Before we describe the FUNCTION_DECL itself, make sure that we
11028 have described its return type. */
11029 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11031 /* And its virtual context. */
11032 if (DECL_VINDEX (decl) != NULL_TREE)
11033 gen_type_die (DECL_CONTEXT (decl), context_die);
11035 /* And its containing type. */
11036 origin = decl_class_context (decl);
11037 if (origin != NULL_TREE)
11038 gen_type_die_for_member (origin, decl, context_die);
11041 /* Now output a DIE to represent the function itself. */
11042 gen_subprogram_die (decl, context_die);
11046 /* If we are in terse mode, don't generate any DIEs to represent any
11047 actual typedefs. */
11048 if (debug_info_level <= DINFO_LEVEL_TERSE)
11051 /* In the special case of a TYPE_DECL node representing the
11052 declaration of some type tag, if the given TYPE_DECL is marked as
11053 having been instantiated from some other (original) TYPE_DECL node
11054 (e.g. one which was generated within the original definition of an
11055 inline function) we have to generate a special (abbreviated)
11056 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
11058 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11060 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11064 if (is_redundant_typedef (decl))
11065 gen_type_die (TREE_TYPE (decl), context_die);
11067 /* Output a DIE to represent the typedef itself. */
11068 gen_typedef_die (decl, context_die);
11072 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11073 gen_label_die (decl, context_die);
11077 /* If we are in terse mode, don't generate any DIEs to represent any
11078 variable declarations or definitions. */
11079 if (debug_info_level <= DINFO_LEVEL_TERSE)
11082 /* Output any DIEs that are needed to specify the type of this data
11084 gen_type_die (TREE_TYPE (decl), context_die);
11086 /* And its containing type. */
11087 origin = decl_class_context (decl);
11088 if (origin != NULL_TREE)
11089 gen_type_die_for_member (origin, decl, context_die);
11091 /* Now output the DIE to represent the data object itself. This gets
11092 complicated because of the possibility that the VAR_DECL really
11093 represents an inlined instance of a formal parameter for an inline
11095 origin = decl_ultimate_origin (decl);
11096 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11097 gen_formal_parameter_die (decl, context_die);
11099 gen_variable_die (decl, context_die);
11103 /* Ignore the nameless fields that are used to skip bits, but
11104 handle C++ anonymous unions. */
11105 if (DECL_NAME (decl) != NULL_TREE
11106 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11108 gen_type_die (member_declared_type (decl), context_die);
11109 gen_field_die (decl, context_die);
11114 gen_type_die (TREE_TYPE (decl), context_die);
11115 gen_formal_parameter_die (decl, context_die);
11118 case NAMESPACE_DECL:
11119 /* Ignore for now. */
11127 /* Add Ada "use" clause information for SGI Workshop debugger. */
11130 dwarf2out_add_library_unit_info (filename, context_list)
11131 const char *filename;
11132 const char *context_list;
11134 unsigned int file_index;
11136 if (filename != NULL)
11138 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
11139 tree context_list_decl
11140 = build_decl (LABEL_DECL, get_identifier (context_list),
11143 TREE_PUBLIC (context_list_decl) = TRUE;
11144 add_name_attribute (unit_die, context_list);
11145 file_index = lookup_filename (&decl_file_table, filename);
11146 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11147 add_pubname (context_list_decl, unit_die);
11151 /* Write the debugging output for DECL. */
11154 dwarf2out_decl (decl)
11155 register tree decl;
11157 register dw_die_ref context_die = comp_unit_die;
11159 if (TREE_CODE (decl) == ERROR_MARK)
11162 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11163 if (DECL_IGNORED_P (decl))
11166 switch (TREE_CODE (decl))
11168 case FUNCTION_DECL:
11169 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11170 builtin function. Explicit programmer-supplied declarations of
11171 these same functions should NOT be ignored however. */
11172 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11175 /* What we would really like to do here is to filter out all mere
11176 file-scope declarations of file-scope functions which are never
11177 referenced later within this translation unit (and keep all of ones
11178 that *are* referenced later on) but we aren't clairvoyant, so we have
11179 no idea which functions will be referenced in the future (i.e. later
11180 on within the current translation unit). So here we just ignore all
11181 file-scope function declarations which are not also definitions. If
11182 and when the debugger needs to know something about these functions,
11183 it will have to hunt around and find the DWARF information associated
11184 with the definition of the function. Note that we can't just check
11185 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11186 definitions and which ones represent mere declarations. We have to
11187 check `DECL_INITIAL' instead. That's because the C front-end
11188 supports some weird semantics for "extern inline" function
11189 definitions. These can get inlined within the current translation
11190 unit (an thus, we need to generate DWARF info for their abstract
11191 instances so that the DWARF info for the concrete inlined instances
11192 can have something to refer to) but the compiler never generates any
11193 out-of-lines instances of such things (despite the fact that they
11194 *are* definitions). The important point is that the C front-end
11195 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11196 to generate DWARF for them anyway. Note that the C++ front-end also
11197 plays some similar games for inline function definitions appearing
11198 within include files which also contain
11199 `#pragma interface' pragmas. */
11200 if (DECL_INITIAL (decl) == NULL_TREE)
11203 /* If we're a nested function, initially use a parent of NULL; if we're
11204 a plain function, this will be fixed up in decls_for_scope. If
11205 we're a method, it will be ignored, since we already have a DIE. */
11206 if (decl_function_context (decl))
11207 context_die = NULL;
11212 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11213 declaration and if the declaration was never even referenced from
11214 within this entire compilation unit. We suppress these DIEs in
11215 order to save space in the .debug section (by eliminating entries
11216 which are probably useless). Note that we must not suppress
11217 block-local extern declarations (whether used or not) because that
11218 would screw-up the debugger's name lookup mechanism and cause it to
11219 miss things which really ought to be in scope at a given point. */
11220 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11223 /* If we are in terse mode, don't generate any DIEs to represent any
11224 variable declarations or definitions. */
11225 if (debug_info_level <= DINFO_LEVEL_TERSE)
11230 /* Don't emit stubs for types unless they are needed by other DIEs. */
11231 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11234 /* Don't bother trying to generate any DIEs to represent any of the
11235 normal built-in types for the language we are compiling. */
11236 if (DECL_SOURCE_LINE (decl) == 0)
11238 /* OK, we need to generate one for `bool' so GDB knows what type
11239 comparisons have. */
11240 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11241 == DW_LANG_C_plus_plus)
11242 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11243 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11248 /* If we are in terse mode, don't generate any DIEs for types. */
11249 if (debug_info_level <= DINFO_LEVEL_TERSE)
11252 /* If we're a function-scope tag, initially use a parent of NULL;
11253 this will be fixed up in decls_for_scope. */
11254 if (decl_function_context (decl))
11255 context_die = NULL;
11263 gen_decl_die (decl, context_die);
11266 /* Output a marker (i.e. a label) for the beginning of the generated code for
11267 a lexical block. */
11270 dwarf2out_begin_block (blocknum)
11271 register unsigned blocknum;
11273 function_section (current_function_decl);
11274 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11277 /* Output a marker (i.e. a label) for the end of the generated code for a
11281 dwarf2out_end_block (blocknum)
11282 register unsigned blocknum;
11284 function_section (current_function_decl);
11285 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11288 /* Returns nonzero if it is appropriate not to emit any debugging
11289 information for BLOCK, because it doesn't contain any instructions.
11291 Don't allow this for blocks with nested functions or local classes
11292 as we would end up with orphans, and in the presence of scheduling
11293 we may end up calling them anyway. */
11296 dwarf2out_ignore_block (block)
11300 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11301 if (TREE_CODE (decl) == FUNCTION_DECL
11302 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11307 /* Lookup a filename (in the list of filenames that we know about here in
11308 dwarf2out.c) and return its "index". The index of each (known) filename is
11309 just a unique number which is associated with only that one filename.
11310 We need such numbers for the sake of generating labels
11311 (in the .debug_sfnames section) and references to those
11312 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11313 If the filename given as an argument is not found in our current list,
11314 add it to the list and assign it the next available unique index number.
11315 In order to speed up searches, we remember the index of the filename
11316 was looked up last. This handles the majority of all searches. */
11319 lookup_filename (t, file_name)
11320 struct file_table *t;
11321 const char *file_name;
11323 register unsigned i;
11325 /* Check to see if the file name that was searched on the previous
11326 call matches this file name. If so, return the index. */
11327 if (t->last_lookup_index != 0)
11328 if (strcmp (file_name, t->table[t->last_lookup_index]) == 0)
11329 return t->last_lookup_index;
11331 /* Didn't match the previous lookup, search the table */
11332 for (i = 1; i < t->in_use; ++i)
11333 if (strcmp (file_name, t->table[i]) == 0)
11335 t->last_lookup_index = i;
11339 /* Prepare to add a new table entry by making sure there is enough space in
11340 the table to do so. If not, expand the current table. */
11341 if (i == t->allocated)
11343 t->allocated = i + FILE_TABLE_INCREMENT;
11344 t->table = (char **)
11345 xrealloc (t->table, t->allocated * sizeof (char *));
11348 /* Add the new entry to the end of the filename table. */
11349 t->table[i] = xstrdup (file_name);
11351 t->last_lookup_index = i;
11357 init_file_table (t)
11358 struct file_table *t;
11360 /* Allocate the initial hunk of the file_table. */
11361 t->table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11362 t->allocated = FILE_TABLE_INCREMENT;
11364 /* Skip the first entry - file numbers begin at 1. */
11366 t->last_lookup_index = 0;
11369 /* Output a label to mark the beginning of a source code line entry
11370 and record information relating to this source line, in
11371 'line_info_table' for later output of the .debug_line section. */
11374 dwarf2out_line (filename, line)
11375 register const char *filename;
11376 register unsigned line;
11378 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11380 function_section (current_function_decl);
11382 if (DWARF2_ASM_LINE_DEBUG_INFO)
11385 unsigned old_in_use = line_file_table.in_use;
11387 unsigned file_num = lookup_filename (&line_file_table, filename);
11389 /* Emit the .file and .loc directives understood by GNU as. */
11391 /* ??? As of 2000-11-25, gas has a bug in which it doesn't
11392 actually use the file number argument. It merely remembers
11393 the last .file directive emitted. */
11394 if (file_num >= old_in_use)
11395 fprintf (asm_out_file, "\t.file %d \"%s\"\n", file_num, filename);
11396 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11398 static int last_file_num;
11399 if (file_num != last_file_num)
11401 last_file_num = file_num;
11402 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
11404 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
11407 /* Indicate that line number info exists. */
11408 ++line_info_table_in_use;
11410 /* Indicate that multiple line number tables exist. */
11411 if (DECL_SECTION_NAME (current_function_decl))
11412 ++separate_line_info_table_in_use;
11414 else if (DECL_SECTION_NAME (current_function_decl))
11416 register dw_separate_line_info_ref line_info;
11417 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11418 separate_line_info_table_in_use);
11419 if (flag_debug_asm)
11420 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
11421 fputc ('\n', asm_out_file);
11423 /* expand the line info table if necessary */
11424 if (separate_line_info_table_in_use
11425 == separate_line_info_table_allocated)
11427 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11428 separate_line_info_table
11429 = (dw_separate_line_info_ref)
11430 xrealloc (separate_line_info_table,
11431 separate_line_info_table_allocated
11432 * sizeof (dw_separate_line_info_entry));
11435 /* Add the new entry at the end of the line_info_table. */
11437 = &separate_line_info_table[separate_line_info_table_in_use++];
11438 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
11439 line_info->dw_line_num = line;
11440 line_info->function = current_funcdef_number;
11444 register dw_line_info_ref line_info;
11446 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11447 line_info_table_in_use);
11448 if (flag_debug_asm)
11449 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
11450 fputc ('\n', asm_out_file);
11452 /* Expand the line info table if necessary. */
11453 if (line_info_table_in_use == line_info_table_allocated)
11455 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11457 = (dw_line_info_ref)
11458 xrealloc (line_info_table,
11459 (line_info_table_allocated
11460 * sizeof (dw_line_info_entry)));
11463 /* Add the new entry at the end of the line_info_table. */
11464 line_info = &line_info_table[line_info_table_in_use++];
11465 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
11466 line_info->dw_line_num = line;
11471 /* Record the beginning of a new source file, for later output
11472 of the .debug_macinfo section. At present, unimplemented. */
11475 dwarf2out_start_source_file (filename)
11476 register const char *filename ATTRIBUTE_UNUSED;
11478 if (flag_eliminate_dwarf2_dups)
11480 /* Record the beginning of the file for break_out_includes. */
11481 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11482 add_AT_string (bincl_die, DW_AT_name, filename);
11486 /* Record the end of a source file, for later output
11487 of the .debug_macinfo section. At present, unimplemented. */
11490 dwarf2out_end_source_file ()
11492 if (flag_eliminate_dwarf2_dups)
11494 /* Record the end of the file for break_out_includes. */
11495 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11499 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11500 the tail part of the directive line, i.e. the part which is past the
11501 initial whitespace, #, whitespace, directive-name, whitespace part. */
11504 dwarf2out_define (lineno, buffer)
11505 register unsigned lineno ATTRIBUTE_UNUSED;
11506 register const char *buffer ATTRIBUTE_UNUSED;
11508 static int initialized = 0;
11511 dwarf2out_start_source_file (primary_filename);
11516 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11517 the tail part of the directive line, i.e. the part which is past the
11518 initial whitespace, #, whitespace, directive-name, whitespace part. */
11521 dwarf2out_undef (lineno, buffer)
11522 register unsigned lineno ATTRIBUTE_UNUSED;
11523 register const char *buffer ATTRIBUTE_UNUSED;
11527 /* Set up for Dwarf output at the start of compilation. */
11530 dwarf2out_init (asm_out_file, main_input_filename)
11531 register FILE *asm_out_file;
11532 register const char *main_input_filename;
11534 /* Remember the name of the primary input file. */
11535 primary_filename = main_input_filename;
11537 init_file_table (&decl_file_table);
11538 init_file_table (&line_file_table);
11540 /* Allocate the initial hunk of the decl_die_table. */
11542 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11543 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11544 decl_die_table_in_use = 0;
11546 /* Allocate the initial hunk of the decl_scope_table. */
11548 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11549 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11550 decl_scope_depth = 0;
11552 /* Allocate the initial hunk of the abbrev_die_table. */
11554 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11555 sizeof (dw_die_ref));
11556 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11557 /* Zero-th entry is allocated, but unused */
11558 abbrev_die_table_in_use = 1;
11560 /* Allocate the initial hunk of the line_info_table. */
11562 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11563 sizeof (dw_line_info_entry));
11564 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11565 /* Zero-th entry is allocated, but unused */
11566 line_info_table_in_use = 1;
11568 /* Generate the initial DIE for the .debug section. Note that the (string)
11569 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11570 will (typically) be a relative pathname and that this pathname should be
11571 taken as being relative to the directory from which the compiler was
11572 invoked when the given (base) source file was compiled. */
11573 comp_unit_die = gen_compile_unit_die (main_input_filename);
11575 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11576 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11578 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11579 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
11580 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11581 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11583 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11584 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11585 DEBUG_INFO_SECTION_LABEL, 0);
11586 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11587 DEBUG_LINE_SECTION_LABEL, 0);
11589 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11590 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11591 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11593 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11594 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11596 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11597 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11598 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11599 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11602 /* Output stuff that dwarf requires at the end of every file,
11603 and generate the DWARF-2 debugging info. */
11606 dwarf2out_finish ()
11608 limbo_die_node *node, *next_node;
11611 /* Traverse the limbo die list, and add parent/child links. The only
11612 dies without parents that should be here are concrete instances of
11613 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11614 For concrete instances, we can get the parent die from the abstract
11616 for (node = limbo_die_list; node; node = next_node)
11618 next_node = node->next;
11621 if (die->die_parent == NULL)
11623 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11625 add_child_die (origin->die_parent, die);
11626 else if (die == comp_unit_die)
11633 limbo_die_list = NULL;
11635 /* Walk through the list of incomplete types again, trying once more to
11636 emit full debugging info for them. */
11637 retry_incomplete_types ();
11639 /* We need to reverse all the dies before break_out_includes, or
11640 we'll see the end of an include file before the beginning. */
11641 reverse_all_dies (comp_unit_die);
11643 /* Generate separate CUs for each of the include files we've seen.
11644 They will go into limbo_die_list. */
11645 if (flag_eliminate_dwarf2_dups)
11646 break_out_includes (comp_unit_die);
11648 /* Traverse the DIE's and add add sibling attributes to those DIE's
11649 that have children. */
11650 add_sibling_attributes (comp_unit_die);
11651 for (node = limbo_die_list; node; node = node->next)
11652 add_sibling_attributes (node->die);
11654 /* Output a terminator label for the .text section. */
11655 fputc ('\n', asm_out_file);
11656 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11657 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11660 /* Output a terminator label for the .data section. */
11661 fputc ('\n', asm_out_file);
11662 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11663 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11665 /* Output a terminator label for the .bss section. */
11666 fputc ('\n', asm_out_file);
11667 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11668 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11671 /* Output the source line correspondence table. */
11672 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
11674 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11676 fputc ('\n', asm_out_file);
11677 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11678 output_line_info ();
11681 /* We can only use the low/high_pc attributes if all of the code
11683 if (separate_line_info_table_in_use == 0)
11685 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11686 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11689 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11690 debug_line_section_label);
11693 #if 0 /* unimplemented */
11694 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
11695 add_AT_unsigned (die, DW_AT_macro_info, 0);
11698 /* Output all of the compilation units. We put the main one last so that
11699 the offsets are available to output_pubnames. */
11700 for (node = limbo_die_list; node; node = node->next)
11701 output_comp_unit (node->die);
11702 output_comp_unit (comp_unit_die);
11704 /* Output the abbreviation table. */
11705 fputc ('\n', asm_out_file);
11706 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11707 output_abbrev_section ();
11709 if (pubname_table_in_use)
11711 /* Output public names table. */
11712 fputc ('\n', asm_out_file);
11713 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
11714 output_pubnames ();
11717 /* We only put functions in the arange table, so don't write it out if
11718 we don't have any. */
11719 if (fde_table_in_use)
11721 /* Output the address range information. */
11722 fputc ('\n', asm_out_file);
11723 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11727 #endif /* DWARF2_DEBUGGING_INFO */