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
43 #include "hard-reg-set.h"
45 #include "insn-config.h"
51 #include "dwarf2out.h"
58 /* DWARF2 Abbreviation Glossary:
59 CFA = Canonical Frame Address
60 stack address identifying a stack call frame; its value is
61 the value of the stack pointer just before the call to the
63 CFI = Canonical Frame Instruction
64 information describing entries in a stack call frame, e.g.,
66 CIE = Common Information Entry
67 information describing information common to one or more FDEs
68 DIE = Debugging Information Entry
69 FDE = Frame Description Entry
70 information describing the stack call frame, in particular,
71 how to restore registers
73 DW_CFA_... = DWARF2 CFA call frame instruction
74 DW_TAG_... = DWARF2 DIE tag */
76 /* Decide whether we want to emit frame unwind information for the current
82 return (write_symbols == DWARF2_DEBUG
83 #ifdef DWARF2_FRAME_INFO
86 #ifdef DWARF2_UNWIND_INFO
88 || (flag_exceptions && ! exceptions_via_longjmp)
93 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
95 /* How to start an assembler comment. */
96 #ifndef ASM_COMMENT_START
97 #define ASM_COMMENT_START ";#"
100 typedef struct dw_cfi_struct *dw_cfi_ref;
101 typedef struct dw_fde_struct *dw_fde_ref;
102 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
104 /* Call frames are described using a sequence of Call Frame
105 Information instructions. The register number, offset
106 and address fields are provided as possible operands;
107 their use is selected by the opcode field. */
109 typedef union dw_cfi_oprnd_struct
111 unsigned long dw_cfi_reg_num;
112 long int dw_cfi_offset;
113 const char *dw_cfi_addr;
114 struct dw_loc_descr_struct *dw_cfi_loc;
118 typedef struct dw_cfi_struct
120 dw_cfi_ref dw_cfi_next;
121 enum dwarf_call_frame_info dw_cfi_opc;
122 dw_cfi_oprnd dw_cfi_oprnd1;
123 dw_cfi_oprnd dw_cfi_oprnd2;
127 /* This is how we define the location of the CFA. We use to handle it
128 as REG + OFFSET all the time, but now it can be more complex.
129 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
130 Instead of passing around REG and OFFSET, we pass a copy
131 of this structure. */
132 typedef struct cfa_loc
137 int indirect; /* 1 if CFA is accessed via a dereference. */
140 /* All call frame descriptions (FDE's) in the GCC generated DWARF
141 refer to a single Common Information Entry (CIE), defined at
142 the beginning of the .debug_frame section. This used of a single
143 CIE obviates the need to keep track of multiple CIE's
144 in the DWARF generation routines below. */
146 typedef struct dw_fde_struct
148 const char *dw_fde_begin;
149 const char *dw_fde_current_label;
150 const char *dw_fde_end;
151 dw_cfi_ref dw_fde_cfi;
156 /* Maximum size (in bytes) of an artificially generated label. */
157 #define MAX_ARTIFICIAL_LABEL_BYTES 30
159 /* The size of the target's pointer type. */
161 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
164 /* The size of addresses as they appear in the Dwarf 2 data.
165 Some architectures use word addresses to refer to code locations,
166 but Dwarf 2 info always uses byte addresses. On such machines,
167 Dwarf 2 addresses need to be larger than the architecture's
169 #ifndef DWARF2_ADDR_SIZE
170 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
173 /* The size in bytes of a DWARF field indicating an offset or length
174 relative to a debug info section, specified to be 4 bytes in the
175 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
178 #ifndef DWARF_OFFSET_SIZE
179 #define DWARF_OFFSET_SIZE 4
182 #define DWARF_VERSION 2
184 /* Round SIZE up to the nearest BOUNDARY. */
185 #define DWARF_ROUND(SIZE,BOUNDARY) \
186 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
188 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
189 #ifndef DWARF_CIE_DATA_ALIGNMENT
190 #ifdef STACK_GROWS_DOWNWARD
191 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
193 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
195 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
197 /* A pointer to the base of a table that contains frame description
198 information for each routine. */
199 static dw_fde_ref fde_table;
201 /* Number of elements currently allocated for fde_table. */
202 static unsigned fde_table_allocated;
204 /* Number of elements in fde_table currently in use. */
205 static unsigned fde_table_in_use;
207 /* Size (in elements) of increments by which we may expand the
209 #define FDE_TABLE_INCREMENT 256
211 /* A list of call frame insns for the CIE. */
212 static dw_cfi_ref cie_cfi_head;
214 /* The number of the current function definition for which debugging
215 information is being generated. These numbers range from 1 up to the
216 maximum number of function definitions contained within the current
217 compilation unit. These numbers are used to create unique label id's
218 unique to each function definition. */
219 static unsigned current_funcdef_number = 0;
221 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
222 attribute that accelerates the lookup of the FDE associated
223 with the subprogram. This variable holds the table index of the FDE
224 associated with the current function (body) definition. */
225 static unsigned current_funcdef_fde;
227 /* Forward declarations for functions defined in this file. */
229 static char *stripattributes PARAMS ((const char *));
230 static const char *dwarf_cfi_name PARAMS ((unsigned));
231 static dw_cfi_ref new_cfi PARAMS ((void));
232 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
233 static unsigned long size_of_uleb128 PARAMS ((unsigned long));
234 static unsigned long size_of_sleb128 PARAMS ((long));
235 static void output_uleb128 PARAMS ((unsigned long));
236 static void output_sleb128 PARAMS ((long));
237 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
238 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
239 static void lookup_cfa PARAMS ((dw_cfa_location *));
240 static void reg_save PARAMS ((const char *, unsigned,
242 static void initial_return_save PARAMS ((rtx));
243 static long stack_adjust_offset PARAMS ((rtx));
244 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
245 static void output_call_frame_info PARAMS ((int));
246 static void dwarf2out_stack_adjust PARAMS ((rtx));
247 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
249 /* Support for complex CFA locations. */
250 static void output_cfa_loc PARAMS ((dw_cfi_ref));
251 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
252 struct dw_loc_descr_struct *));
253 static struct dw_loc_descr_struct *build_cfa_loc
254 PARAMS ((dw_cfa_location *));
255 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
257 /* Definitions of defaults for assembler-dependent names of various
258 pseudo-ops and section names.
259 Theses may be overridden in the tm.h file (if necessary) for a particular
262 #ifdef OBJECT_FORMAT_ELF
263 #ifndef UNALIGNED_SHORT_ASM_OP
264 #define UNALIGNED_SHORT_ASM_OP "\t.2byte\t"
266 #ifndef UNALIGNED_INT_ASM_OP
267 #define UNALIGNED_INT_ASM_OP "\t.4byte\t"
269 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
270 #define UNALIGNED_DOUBLE_INT_ASM_OP "\t.8byte\t"
272 #endif /* OBJECT_FORMAT_ELF */
275 #define ASM_BYTE_OP "\t.byte\t"
278 /* Data and reference forms for relocatable data. */
279 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
280 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
282 /* Pseudo-op for defining a new section. */
283 #ifndef SECTION_ASM_OP
284 #define SECTION_ASM_OP "\t.section\t"
287 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
288 print the SECTION_ASM_OP and the section name. The default here works for
289 almost all svr4 assemblers, except for the sparc, where the section name
290 must be enclosed in double quotes. (See sparcv4.h). */
291 #ifndef SECTION_FORMAT
292 #ifdef PUSHSECTION_FORMAT
293 #define SECTION_FORMAT PUSHSECTION_FORMAT
295 #define SECTION_FORMAT "%s%s\n"
299 #ifndef FRAME_SECTION
300 #define FRAME_SECTION ".debug_frame"
303 #ifndef FUNC_BEGIN_LABEL
304 #define FUNC_BEGIN_LABEL "LFB"
306 #ifndef FUNC_END_LABEL
307 #define FUNC_END_LABEL "LFE"
309 #define CIE_AFTER_SIZE_LABEL "LSCIE"
310 #define CIE_END_LABEL "LECIE"
311 #define CIE_LENGTH_LABEL "LLCIE"
312 #define FDE_AFTER_SIZE_LABEL "LSFDE"
313 #define FDE_END_LABEL "LEFDE"
314 #define FDE_LENGTH_LABEL "LLFDE"
315 #define DIE_LABEL_PREFIX "DW"
317 /* Definitions of defaults for various types of primitive assembly language
318 output operations. These may be overridden from within the tm.h file,
319 but typically, that is unnecessary. */
321 #ifndef ASM_OUTPUT_SECTION
322 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
323 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
326 #ifndef ASM_OUTPUT_DWARF_DATA1
327 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
328 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
331 #ifndef ASM_OUTPUT_DWARF_DELTA1
332 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
333 do { fprintf ((FILE), "%s", ASM_BYTE_OP); \
334 assemble_name (FILE, LABEL1); \
335 fprintf (FILE, "-"); \
336 assemble_name (FILE, LABEL2); \
340 #ifdef UNALIGNED_INT_ASM_OP
342 #ifndef UNALIGNED_OFFSET_ASM_OP
343 #define UNALIGNED_OFFSET_ASM_OP \
344 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
347 #ifndef UNALIGNED_WORD_ASM_OP
348 #define UNALIGNED_WORD_ASM_OP \
349 ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \
350 : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \
351 : UNALIGNED_INT_ASM_OP)
354 #ifndef ASM_OUTPUT_DWARF_DELTA2
355 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
356 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \
357 assemble_name (FILE, LABEL1); \
358 fprintf (FILE, "-"); \
359 assemble_name (FILE, LABEL2); \
363 #ifndef ASM_OUTPUT_DWARF_DELTA4
364 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
365 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
366 assemble_name (FILE, LABEL1); \
367 fprintf (FILE, "-"); \
368 assemble_name (FILE, LABEL2); \
372 #ifndef ASM_OUTPUT_DWARF_DELTA
373 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
374 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \
375 assemble_name (FILE, LABEL1); \
376 fprintf (FILE, "-"); \
377 assemble_name (FILE, LABEL2); \
381 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
382 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
383 do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
384 assemble_name (FILE, LABEL1); \
385 fprintf (FILE, "-"); \
386 assemble_name (FILE, LABEL2); \
390 #ifndef ASM_OUTPUT_DWARF_ADDR
391 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
392 do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
393 assemble_name (FILE, LABEL); \
397 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
398 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
400 fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
401 output_addr_const ((FILE), (RTX)); \
405 #ifndef ASM_OUTPUT_DWARF_OFFSET4
406 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
407 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
408 assemble_name (FILE, LABEL); \
412 #ifndef ASM_OUTPUT_DWARF_OFFSET
413 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
414 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \
415 assemble_name (FILE, LABEL); \
419 #ifndef ASM_OUTPUT_DWARF_DATA2
420 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
421 fprintf ((FILE), "%s0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
424 #ifndef ASM_OUTPUT_DWARF_DATA4
425 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
426 fprintf ((FILE), "%s0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
429 #ifndef ASM_OUTPUT_DWARF_DATA8
430 #define ASM_OUTPUT_DWARF_DATA8(FILE,VALUE) \
431 fprintf ((FILE), "%s0x%lx", UNALIGNED_DOUBLE_INT_ASM_OP, \
432 (unsigned long) (VALUE))
435 #ifndef ASM_OUTPUT_DWARF_DATA
436 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
437 fprintf ((FILE), "%s0x%lx", UNALIGNED_OFFSET_ASM_OP, \
438 (unsigned long) (VALUE))
441 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
442 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
443 fprintf ((FILE), "%s0x%lx", UNALIGNED_WORD_ASM_OP, \
444 (unsigned long) (VALUE))
447 #ifndef ASM_OUTPUT_DWARF_CONST_DOUBLE
448 #define ASM_OUTPUT_DWARF_CONST_DOUBLE(FILE,HIGH_VALUE,LOW_VALUE) \
450 if (WORDS_BIG_ENDIAN) \
452 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
453 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
457 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
458 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
463 #else /* UNALIGNED_INT_ASM_OP */
465 /* We don't have unaligned support, let's hope the normal output works for
466 .debug_frame. But we know it won't work for .debug_info. */
468 #ifdef DWARF2_DEBUGGING_INFO
469 #error DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP.
472 #ifndef ASM_OUTPUT_DWARF_ADDR
473 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
474 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1)
477 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
478 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) ASM_OUTPUT_DWARF_ADDR (FILE,RTX)
481 #ifndef ASM_OUTPUT_DWARF_OFFSET4
482 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
483 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
486 #ifndef ASM_OUTPUT_DWARF_OFFSET
487 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
488 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
491 #ifndef ASM_OUTPUT_DWARF_DELTA2
492 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
493 assemble_integer (gen_rtx_MINUS (HImode, \
494 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
495 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
499 #ifndef ASM_OUTPUT_DWARF_DELTA4
500 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
501 assemble_integer (gen_rtx_MINUS (SImode, \
502 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
503 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
507 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
508 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
509 assemble_integer (gen_rtx_MINUS (Pmode, \
510 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
511 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
515 #ifndef ASM_OUTPUT_DWARF_DELTA
516 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
517 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
520 #ifndef ASM_OUTPUT_DWARF_DATA2
521 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
522 assemble_integer (GEN_INT (VALUE), 2, 1)
525 #ifndef ASM_OUTPUT_DWARF_DATA4
526 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
527 assemble_integer (GEN_INT (VALUE), 4, 1)
530 #endif /* UNALIGNED_INT_ASM_OP */
533 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
534 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
536 fprintf (FILE, "%s", SET_ASM_OP); \
537 assemble_name (FILE, SY); \
539 assemble_name (FILE, HI); \
541 assemble_name (FILE, LO); \
544 #endif /* SET_ASM_OP */
546 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
547 newline is produced. When flag_debug_asm is asserted, we add commentary
548 at the end of the line, so we must avoid output of a newline here. */
549 #ifndef ASM_OUTPUT_DWARF_NSTRING
550 #define ASM_OUTPUT_DWARF_NSTRING(FILE,P,SLEN) \
552 register int slen = (SLEN); \
553 register const char *p = (P); \
555 fprintf (FILE, "\t.ascii \""); \
556 for (i = 0; i < slen; i++) \
558 register int c = p[i]; \
559 if (c == '\"' || c == '\\') \
565 fprintf (FILE, "\\%o", c); \
568 fprintf (FILE, "\\0\""); \
572 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
573 ASM_OUTPUT_DWARF_NSTRING (FILE, P, strlen (P))
575 /* The DWARF 2 CFA column which tracks the return address. Normally this
576 is the column for PC, or the first column after all of the hard
578 #ifndef DWARF_FRAME_RETURN_COLUMN
580 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
582 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
586 /* The mapping from gcc register number to DWARF 2 CFA column number. By
587 default, we just provide columns for all registers. */
588 #ifndef DWARF_FRAME_REGNUM
589 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
592 /* Hook used by __throw. */
595 expand_builtin_dwarf_fp_regnum ()
597 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
600 /* The offset from the incoming value of %sp to the top of the stack frame
601 for the current function. */
602 #ifndef INCOMING_FRAME_SP_OFFSET
603 #define INCOMING_FRAME_SP_OFFSET 0
606 /* Return a pointer to a copy of the section string name S with all
607 attributes stripped off, and an asterisk prepended (for assemble_name). */
613 char *stripped = xmalloc (strlen (s) + 2);
618 while (*s && *s != ',')
625 /* Generate code to initialize the register size table. */
628 expand_builtin_init_dwarf_reg_sizes (address)
632 enum machine_mode mode = TYPE_MODE (char_type_node);
633 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
634 rtx mem = gen_rtx_MEM (mode, addr);
636 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
638 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
639 int size = GET_MODE_SIZE (reg_raw_mode[i]);
644 emit_move_insn (change_address (mem, mode,
645 plus_constant (addr, offset)),
650 /* Convert a DWARF call frame info. operation to its string name */
653 dwarf_cfi_name (cfi_opc)
654 register unsigned cfi_opc;
658 case DW_CFA_advance_loc:
659 return "DW_CFA_advance_loc";
661 return "DW_CFA_offset";
663 return "DW_CFA_restore";
667 return "DW_CFA_set_loc";
668 case DW_CFA_advance_loc1:
669 return "DW_CFA_advance_loc1";
670 case DW_CFA_advance_loc2:
671 return "DW_CFA_advance_loc2";
672 case DW_CFA_advance_loc4:
673 return "DW_CFA_advance_loc4";
674 case DW_CFA_offset_extended:
675 return "DW_CFA_offset_extended";
676 case DW_CFA_restore_extended:
677 return "DW_CFA_restore_extended";
678 case DW_CFA_undefined:
679 return "DW_CFA_undefined";
680 case DW_CFA_same_value:
681 return "DW_CFA_same_value";
682 case DW_CFA_register:
683 return "DW_CFA_register";
684 case DW_CFA_remember_state:
685 return "DW_CFA_remember_state";
686 case DW_CFA_restore_state:
687 return "DW_CFA_restore_state";
689 return "DW_CFA_def_cfa";
690 case DW_CFA_def_cfa_register:
691 return "DW_CFA_def_cfa_register";
692 case DW_CFA_def_cfa_offset:
693 return "DW_CFA_def_cfa_offset";
694 case DW_CFA_def_cfa_expression:
695 return "DW_CFA_def_cfa_expression";
697 /* SGI/MIPS specific */
698 case DW_CFA_MIPS_advance_loc8:
699 return "DW_CFA_MIPS_advance_loc8";
702 case DW_CFA_GNU_window_save:
703 return "DW_CFA_GNU_window_save";
704 case DW_CFA_GNU_args_size:
705 return "DW_CFA_GNU_args_size";
706 case DW_CFA_GNU_negative_offset_extended:
707 return "DW_CFA_GNU_negative_offset_extended";
710 return "DW_CFA_<unknown>";
714 /* Return a pointer to a newly allocated Call Frame Instruction. */
716 static inline dw_cfi_ref
719 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
721 cfi->dw_cfi_next = NULL;
722 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
723 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
728 /* Add a Call Frame Instruction to list of instructions. */
731 add_cfi (list_head, cfi)
732 register dw_cfi_ref *list_head;
733 register dw_cfi_ref cfi;
735 register dw_cfi_ref *p;
737 /* Find the end of the chain. */
738 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
744 /* Generate a new label for the CFI info to refer to. */
747 dwarf2out_cfi_label ()
749 static char label[20];
750 static unsigned long label_num = 0;
752 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
753 ASM_OUTPUT_LABEL (asm_out_file, label);
758 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
759 or to the CIE if LABEL is NULL. */
762 add_fde_cfi (label, cfi)
763 register const char *label;
764 register dw_cfi_ref cfi;
768 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
771 label = dwarf2out_cfi_label ();
773 if (fde->dw_fde_current_label == NULL
774 || strcmp (label, fde->dw_fde_current_label) != 0)
776 register dw_cfi_ref xcfi;
778 fde->dw_fde_current_label = label = xstrdup (label);
780 /* Set the location counter to the new label. */
782 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
783 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
784 add_cfi (&fde->dw_fde_cfi, xcfi);
787 add_cfi (&fde->dw_fde_cfi, cfi);
791 add_cfi (&cie_cfi_head, cfi);
794 /* Subroutine of lookup_cfa. */
797 lookup_cfa_1 (cfi, loc)
798 register dw_cfi_ref cfi;
799 register dw_cfa_location *loc;
801 switch (cfi->dw_cfi_opc)
803 case DW_CFA_def_cfa_offset:
804 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
806 case DW_CFA_def_cfa_register:
807 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
810 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
811 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
813 case DW_CFA_def_cfa_expression:
814 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
821 /* Find the previous value for the CFA. */
825 register dw_cfa_location *loc;
827 register dw_cfi_ref cfi;
829 loc->reg = (unsigned long) -1;
832 loc->base_offset = 0;
834 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
835 lookup_cfa_1 (cfi, loc);
837 if (fde_table_in_use)
839 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
840 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
841 lookup_cfa_1 (cfi, loc);
845 /* The current rule for calculating the DWARF2 canonical frame address. */
848 /* The register used for saving registers to the stack, and its offset
850 dw_cfa_location cfa_store;
852 /* The running total of the size of arguments pushed onto the stack. */
853 static long args_size;
855 /* The last args_size we actually output. */
856 static long old_args_size;
858 /* Entry point to update the canonical frame address (CFA).
859 LABEL is passed to add_fde_cfi. The value of CFA is now to be
860 calculated from REG+OFFSET. */
863 dwarf2out_def_cfa (label, reg, offset)
864 register const char *label;
873 def_cfa_1 (label, &loc);
876 /* This routine does the actual work. The CFA is now calculated from
877 the dw_cfa_location structure. */
879 def_cfa_1 (label, loc_p)
880 register const char *label;
881 dw_cfa_location *loc_p;
883 register dw_cfi_ref cfi;
884 dw_cfa_location old_cfa, loc;
889 if (cfa_store.reg == loc.reg && loc.indirect == 0)
890 cfa_store.offset = loc.offset;
892 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
893 lookup_cfa (&old_cfa);
895 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
896 loc.indirect == old_cfa.indirect)
898 if (loc.indirect == 0
899 || loc.base_offset == old_cfa.base_offset)
900 /* Nothing changed so no need to issue any call frame
907 if (loc.reg == old_cfa.reg && !loc.indirect)
909 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
910 indicating the CFA register did not change but the offset
912 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
913 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
916 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
917 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
920 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
921 indicating the CFA register has changed to <register> but the
922 offset has not changed. */
923 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
924 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
928 else if (loc.indirect == 0)
930 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
931 indicating the CFA register has changed to <register> with
932 the specified offset. */
933 cfi->dw_cfi_opc = DW_CFA_def_cfa;
934 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
935 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
939 /* Construct a DW_CFA_def_cfa_expression instruction to
940 calculate the CFA using a full location expression since no
941 register-offset pair is available. */
942 struct dw_loc_descr_struct *loc_list;
943 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
944 loc_list = build_cfa_loc (&loc);
945 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
948 add_fde_cfi (label, cfi);
951 /* Add the CFI for saving a register. REG is the CFA column number.
952 LABEL is passed to add_fde_cfi.
953 If SREG is -1, the register is saved at OFFSET from the CFA;
954 otherwise it is saved in SREG. */
957 reg_save (label, reg, sreg, offset)
958 register const char *label;
959 register unsigned reg;
960 register unsigned sreg;
961 register long offset;
963 register dw_cfi_ref cfi = new_cfi ();
965 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
967 /* The following comparison is correct. -1 is used to indicate that
968 the value isn't a register number. */
969 if (sreg == (unsigned int) -1)
972 /* The register number won't fit in 6 bits, so we have to use
974 cfi->dw_cfi_opc = DW_CFA_offset_extended;
976 cfi->dw_cfi_opc = DW_CFA_offset;
978 #ifdef ENABLE_CHECKING
980 /* If we get an offset that is not a multiple of
981 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
982 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
984 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
986 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
990 offset /= DWARF_CIE_DATA_ALIGNMENT;
993 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
996 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
998 else if (sreg == reg)
999 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
1003 cfi->dw_cfi_opc = DW_CFA_register;
1004 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1007 add_fde_cfi (label, cfi);
1010 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1011 This CFI tells the unwinder that it needs to restore the window registers
1012 from the previous frame's window save area.
1014 ??? Perhaps we should note in the CIE where windows are saved (instead of
1015 assuming 0(cfa)) and what registers are in the window. */
1018 dwarf2out_window_save (label)
1019 register const char *label;
1021 register dw_cfi_ref cfi = new_cfi ();
1022 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1023 add_fde_cfi (label, cfi);
1026 /* Add a CFI to update the running total of the size of arguments
1027 pushed onto the stack. */
1030 dwarf2out_args_size (label, size)
1034 register dw_cfi_ref cfi;
1036 if (size == old_args_size)
1038 old_args_size = size;
1041 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1042 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1043 add_fde_cfi (label, cfi);
1046 /* Entry point for saving a register to the stack. REG is the GCC register
1047 number. LABEL and OFFSET are passed to reg_save. */
1050 dwarf2out_reg_save (label, reg, offset)
1051 register const char *label;
1052 register unsigned reg;
1053 register long offset;
1055 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
1058 /* Entry point for saving the return address in the stack.
1059 LABEL and OFFSET are passed to reg_save. */
1062 dwarf2out_return_save (label, offset)
1063 register const char *label;
1064 register long offset;
1066 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
1069 /* Entry point for saving the return address in a register.
1070 LABEL and SREG are passed to reg_save. */
1073 dwarf2out_return_reg (label, sreg)
1074 register const char *label;
1075 register unsigned sreg;
1077 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
1080 /* Record the initial position of the return address. RTL is
1081 INCOMING_RETURN_ADDR_RTX. */
1084 initial_return_save (rtl)
1087 unsigned int reg = (unsigned int) -1;
1090 switch (GET_CODE (rtl))
1093 /* RA is in a register. */
1094 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1097 /* RA is on the stack. */
1098 rtl = XEXP (rtl, 0);
1099 switch (GET_CODE (rtl))
1102 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1107 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1109 offset = INTVAL (XEXP (rtl, 1));
1112 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1114 offset = -INTVAL (XEXP (rtl, 1));
1121 /* The return address is at some offset from any value we can
1122 actually load. For instance, on the SPARC it is in %i7+8. Just
1123 ignore the offset for now; it doesn't matter for unwinding frames. */
1124 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1126 initial_return_save (XEXP (rtl, 0));
1132 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1135 /* Given a SET, calculate the amount of stack adjustment it
1139 stack_adjust_offset (pattern)
1142 rtx src = SET_SRC (pattern);
1143 rtx dest = SET_DEST (pattern);
1147 if (dest == stack_pointer_rtx)
1149 /* (set (reg sp) (plus (reg sp) (const_int))) */
1150 code = GET_CODE (src);
1151 if (! (code == PLUS || code == MINUS)
1152 || XEXP (src, 0) != stack_pointer_rtx
1153 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1156 offset = INTVAL (XEXP (src, 1));
1158 else if (GET_CODE (dest) == MEM)
1160 /* (set (mem (pre_dec (reg sp))) (foo)) */
1161 src = XEXP (dest, 0);
1162 code = GET_CODE (src);
1164 if (! (code == PRE_DEC || code == PRE_INC
1165 || code == PRE_MODIFY)
1166 || XEXP (src, 0) != stack_pointer_rtx)
1169 if (code == PRE_MODIFY)
1171 rtx val = XEXP (XEXP (src, 1), 1);
1172 /* We handle only adjustments by constant amount. */
1173 if (GET_CODE (XEXP (src, 1)) != PLUS ||
1174 GET_CODE (val) != CONST_INT)
1176 offset = -INTVAL (val);
1178 else offset = GET_MODE_SIZE (GET_MODE (dest));
1183 if (code == PLUS || code == PRE_INC)
1189 /* Check INSN to see if it looks like a push or a stack adjustment, and
1190 make a note of it if it does. EH uses this information to find out how
1191 much extra space it needs to pop off the stack. */
1194 dwarf2out_stack_adjust (insn)
1200 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1202 /* Extract the size of the args from the CALL rtx itself. */
1204 insn = PATTERN (insn);
1205 if (GET_CODE (insn) == PARALLEL)
1206 insn = XVECEXP (insn, 0, 0);
1207 if (GET_CODE (insn) == SET)
1208 insn = SET_SRC (insn);
1209 if (GET_CODE (insn) != CALL)
1211 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1215 /* If only calls can throw, and we have a frame pointer,
1216 save up adjustments until we see the CALL_INSN. */
1217 else if (! asynchronous_exceptions
1218 && cfa.reg != STACK_POINTER_REGNUM)
1221 if (GET_CODE (insn) == BARRIER)
1223 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1224 the compiler will have already emitted a stack adjustment, but
1225 doesn't bother for calls to noreturn functions. */
1226 #ifdef STACK_GROWS_DOWNWARD
1227 offset = -args_size;
1232 else if (GET_CODE (PATTERN (insn)) == SET)
1234 offset = stack_adjust_offset (PATTERN (insn));
1236 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1237 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1239 /* There may be stack adjustments inside compound insns. Search
1244 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1246 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1247 if (GET_CODE (pattern) == SET)
1248 offset += stack_adjust_offset (pattern);
1257 if (cfa.reg == STACK_POINTER_REGNUM)
1258 cfa.offset += offset;
1260 #ifndef STACK_GROWS_DOWNWARD
1263 args_size += offset;
1267 label = dwarf2out_cfi_label ();
1268 def_cfa_1 (label, &cfa);
1269 dwarf2out_args_size (label, args_size);
1272 /* A temporary register holding an integral value used in adjusting SP
1273 or setting up the store_reg. The "offset" field holds the integer
1274 value, not an offset. */
1275 dw_cfa_location cfa_temp;
1277 /* Record call frame debugging information for an expression EXPR,
1278 which either sets SP or FP (adjusting how we calculate the frame
1279 address) or saves a register to the stack. LABEL indicates the
1282 This function encodes a state machine mapping rtxes to actions on
1283 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1284 users need not read the source code.
1286 Invariants / Summaries of Rules
1288 cfa current register used to calculate the DWARF2 canonical
1289 frame address register and offset
1290 cfa_store register used by prologue code to save things to the stack
1291 cfa_store.offset is the offset from the value of
1292 cfa_store.reg to the actual CFA
1293 cfa_temp register holding an integral value. cfa_temp.offset
1294 stores the value, which will be used to adjust the
1297 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1298 with cfa.reg as the first operand changes the cfa.reg and its
1300 (For an unknown reason, Rule 4 does not fully obey the
1303 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1304 expression yielding a constant. This sets cfa_temp.reg
1305 and cfa_temp.offset.
1307 Rule 5: Create a new register cfa_store used to save items to the
1310 Rules 10-13: Save a register to the stack. Record the location in
1311 cfa_store.offset. Define offset as the difference of
1312 the original location and cfa_store's location.
1316 "{a,b}" indicates a choice of a xor b.
1317 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1320 (set <reg1> <reg2>:cfa.reg)
1321 effects: cfa.reg = <REG1>
1322 cfa.offset unchanged
1325 (set sp ({minus,plus} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1326 effects: cfa.reg = sp if fp used
1327 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1328 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1329 if cfa_store.reg==sp
1332 (set fp ({minus,plus} <reg>:cfa.reg <const_int>))
1333 effects: cfa.reg = fp
1334 cfa_offset += +/- <const_int>
1337 (set <reg1> (plus <reg2>:cfa.reg <const_int>))
1338 constraints: <reg1> != fp
1340 effects: cfa.reg = <reg1>
1341 questions: Where is <const_int> used?
1342 Should cfa.offset be changed?
1345 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1346 constraints: <reg1> != fp
1348 effects: cfa_store.reg = <reg1>
1349 cfa_store.offset = cfa.offset - cfa_temp.offset
1352 (set <reg> <const_int>)
1353 effects: cfa_temp.reg = <reg>
1354 cfa_temp.offset = <const_int>
1357 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1358 effects: cfa_temp.reg = <reg1>
1359 cfa_temp.offset |= <const_int>
1362 (set <reg> (high <exp>))
1366 (set <reg> (lo_sum <exp> <const_int>))
1367 effects: cfa_temp.reg = <reg>
1368 cfa_temp.offset = <const_int>
1371 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1372 effects: cfa_store.offset -= <const_int>
1373 cfa.offset = cfa_store.offset if cfa.reg == sp
1374 offset = -cfa_store.offset
1376 cfa.base_offset = offset
1379 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1380 effects: cfa_store.offset += -/+ mode_size(mem)
1381 cfa.offset = cfa_store.offset if cfa.reg == sp
1382 offset = -cfa_store.offset
1384 cfa.base_offset = offset
1387 (set (mem ({minus,plus} <reg1>:cfa_store <const_int>)) <reg2>)
1388 effects: cfa_store.offset += -/+ <const_int>
1389 offset = -cfa_store.offset
1391 cfa.base_offset = offset
1394 (set (mem <reg1>:cfa_store) <reg2>)
1395 effects: offset = -cfa_store.offset
1397 cfa.base_offset = offset */
1400 dwarf2out_frame_debug_expr (expr, label)
1407 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1408 the PARALLEL independently. The first element is always processed if
1409 it is a SET. This is for backward compatibility. Other elements
1410 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1411 flag is set in them. */
1413 if (GET_CODE (expr) == PARALLEL
1414 || GET_CODE (expr) == SEQUENCE)
1417 int limit = XVECLEN (expr, 0);
1419 for (par_index = 0; par_index < limit; par_index++)
1421 rtx x = XVECEXP (expr, 0, par_index);
1423 if (GET_CODE (x) == SET &&
1424 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1425 dwarf2out_frame_debug_expr (x, label);
1430 if (GET_CODE (expr) != SET)
1433 src = SET_SRC (expr);
1434 dest = SET_DEST (expr);
1436 switch (GET_CODE (dest))
1440 /* Update the CFA rule wrt SP or FP. Make sure src is
1441 relative to the current CFA register. */
1442 switch (GET_CODE (src))
1444 /* Setting FP from SP. */
1446 if (cfa.reg == (unsigned) REGNO (src))
1452 /* We used to require that dest be either SP or FP, but the
1453 ARM copies SP to a temporary register, and from there to
1454 FP. So we just rely on the backends to only set
1455 RTX_FRAME_RELATED_P on appropriate insns. */
1456 cfa.reg = REGNO (dest);
1461 if (dest == stack_pointer_rtx)
1465 switch (GET_CODE (XEXP (src, 1)))
1468 offset = INTVAL (XEXP (src, 1));
1471 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1473 offset = cfa_temp.offset;
1479 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1481 /* Restoring SP from FP in the epilogue. */
1482 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1484 cfa.reg = STACK_POINTER_REGNUM;
1486 else if (XEXP (src, 0) != stack_pointer_rtx)
1489 if (GET_CODE (src) == PLUS)
1491 if (cfa.reg == STACK_POINTER_REGNUM)
1492 cfa.offset += offset;
1493 if (cfa_store.reg == STACK_POINTER_REGNUM)
1494 cfa_store.offset += offset;
1496 else if (dest == hard_frame_pointer_rtx)
1499 /* Either setting the FP from an offset of the SP,
1500 or adjusting the FP */
1501 if (! frame_pointer_needed)
1504 if (GET_CODE (XEXP (src, 0)) == REG
1505 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1506 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1508 offset = INTVAL (XEXP (src, 1));
1509 if (GET_CODE (src) == PLUS)
1511 cfa.offset += offset;
1512 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1519 if (GET_CODE (src) != PLUS)
1523 if (GET_CODE (XEXP (src, 0)) == REG
1524 && REGNO (XEXP (src, 0)) == cfa.reg
1525 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1526 /* Setting the FP (or a scratch that will be copied into the FP
1527 later on) from SP + const. */
1528 cfa.reg = REGNO (dest);
1532 if (XEXP (src, 1) != stack_pointer_rtx)
1534 if (GET_CODE (XEXP (src, 0)) != REG
1535 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg)
1537 if (cfa.reg != STACK_POINTER_REGNUM)
1539 cfa_store.reg = REGNO (dest);
1540 cfa_store.offset = cfa.offset - cfa_temp.offset;
1547 cfa_temp.reg = REGNO (dest);
1548 cfa_temp.offset = INTVAL (src);
1553 if (GET_CODE (XEXP (src, 0)) != REG
1554 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1555 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1557 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1558 cfa_temp.reg = REGNO (dest);
1559 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1565 def_cfa_1 (label, &cfa);
1568 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1569 will fill in all of the bits. */
1576 if (GET_CODE (XEXP (src, 1)) != CONST_INT)
1578 cfa_temp.reg = REGNO (dest);
1579 cfa_temp.offset = INTVAL (XEXP (src, 1));
1583 if (GET_CODE (src) != REG)
1586 /* Saving a register to the stack. Make sure dest is relative to the
1588 switch (GET_CODE (XEXP (dest, 0)))
1593 /* We can't handle variable size modifications. */
1594 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1596 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1598 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1599 || cfa_store.reg != STACK_POINTER_REGNUM)
1601 cfa_store.offset += offset;
1602 if (cfa.reg == STACK_POINTER_REGNUM)
1603 cfa.offset = cfa_store.offset;
1605 offset = -cfa_store.offset;
1610 offset = GET_MODE_SIZE (GET_MODE (dest));
1611 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1614 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1615 || cfa_store.reg != STACK_POINTER_REGNUM)
1617 cfa_store.offset += offset;
1618 if (cfa.reg == STACK_POINTER_REGNUM)
1619 cfa.offset = cfa_store.offset;
1621 offset = -cfa_store.offset;
1625 /* With an offset. */
1628 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1630 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1631 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1634 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1636 offset -= cfa_store.offset;
1640 /* Without an offset. */
1642 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1644 offset = -cfa_store.offset;
1651 if (REGNO (src) != STACK_POINTER_REGNUM
1652 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1653 && (unsigned) REGNO (src) == cfa.reg)
1655 /* We're storing the current CFA reg into the stack. */
1657 if (cfa.offset == 0)
1659 /* If the source register is exactly the CFA, assume
1660 we're saving SP like any other register; this happens
1663 def_cfa_1 (label, &cfa);
1664 dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset);
1669 /* Otherwise, we'll need to look in the stack to
1670 calculate the CFA. */
1672 rtx x = XEXP (dest, 0);
1673 if (GET_CODE (x) != REG)
1675 if (GET_CODE (x) != REG)
1677 cfa.reg = (unsigned) REGNO (x);
1678 cfa.base_offset = offset;
1680 def_cfa_1 (label, &cfa);
1685 def_cfa_1 (label, &cfa);
1686 dwarf2out_reg_save (label, REGNO (src), offset);
1694 /* Record call frame debugging information for INSN, which either
1695 sets SP or FP (adjusting how we calculate the frame address) or saves a
1696 register to the stack. If INSN is NULL_RTX, initialize our state. */
1699 dwarf2out_frame_debug (insn)
1705 if (insn == NULL_RTX)
1707 /* Set up state for generating call frame debug info. */
1709 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1711 cfa.reg = STACK_POINTER_REGNUM;
1714 cfa_temp.offset = 0;
1718 if (! RTX_FRAME_RELATED_P (insn))
1720 dwarf2out_stack_adjust (insn);
1724 label = dwarf2out_cfi_label ();
1726 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1728 insn = XEXP (src, 0);
1730 insn = PATTERN (insn);
1732 dwarf2out_frame_debug_expr (insn, label);
1735 /* Return the size of an unsigned LEB128 quantity. */
1737 static inline unsigned long
1738 size_of_uleb128 (value)
1739 register unsigned long value;
1741 register unsigned long size = 0;
1742 register unsigned byte;
1746 byte = (value & 0x7f);
1755 /* Return the size of a signed LEB128 quantity. */
1757 static inline unsigned long
1758 size_of_sleb128 (value)
1759 register long value;
1761 register unsigned long size = 0;
1762 register unsigned byte;
1766 byte = (value & 0x7f);
1770 while (!(((value == 0) && ((byte & 0x40) == 0))
1771 || ((value == -1) && ((byte & 0x40) != 0))));
1776 /* Output an unsigned LEB128 quantity. */
1779 output_uleb128 (value)
1780 register unsigned long value;
1782 unsigned long save_value = value;
1784 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1787 register unsigned byte = (value & 0x7f);
1790 /* More bytes to follow. */
1793 fprintf (asm_out_file, "0x%x", byte);
1795 fprintf (asm_out_file, ",");
1800 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1803 /* Output an signed LEB128 quantity. */
1806 output_sleb128 (value)
1807 register long value;
1810 register unsigned byte;
1811 long save_value = value;
1813 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1816 byte = (value & 0x7f);
1817 /* arithmetic shift */
1819 more = !((((value == 0) && ((byte & 0x40) == 0))
1820 || ((value == -1) && ((byte & 0x40) != 0))));
1824 fprintf (asm_out_file, "0x%x", byte);
1826 fprintf (asm_out_file, ",");
1831 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1834 /* Output a Call Frame Information opcode and its operand(s). */
1837 output_cfi (cfi, fde)
1838 register dw_cfi_ref cfi;
1839 register dw_fde_ref fde;
1841 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1843 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1845 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1847 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1848 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1849 fputc ('\n', asm_out_file);
1852 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1854 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1856 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1858 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1859 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1861 fputc ('\n', asm_out_file);
1862 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1863 fputc ('\n', asm_out_file);
1865 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1867 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1869 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1871 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1872 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1874 fputc ('\n', asm_out_file);
1878 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1880 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1881 dwarf_cfi_name (cfi->dw_cfi_opc));
1883 fputc ('\n', asm_out_file);
1884 switch (cfi->dw_cfi_opc)
1886 case DW_CFA_set_loc:
1887 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1888 fputc ('\n', asm_out_file);
1890 case DW_CFA_advance_loc1:
1891 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1892 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1893 fde->dw_fde_current_label);
1894 fputc ('\n', asm_out_file);
1895 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1897 case DW_CFA_advance_loc2:
1898 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1899 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1900 fde->dw_fde_current_label);
1901 fputc ('\n', asm_out_file);
1902 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1904 case DW_CFA_advance_loc4:
1905 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1906 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1907 fde->dw_fde_current_label);
1908 fputc ('\n', asm_out_file);
1909 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1911 #ifdef MIPS_DEBUGGING_INFO
1912 case DW_CFA_MIPS_advance_loc8:
1913 /* TODO: not currently implemented. */
1917 case DW_CFA_offset_extended:
1918 case DW_CFA_GNU_negative_offset_extended:
1919 case DW_CFA_def_cfa:
1920 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1921 fputc ('\n', asm_out_file);
1922 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1923 fputc ('\n', asm_out_file);
1925 case DW_CFA_restore_extended:
1926 case DW_CFA_undefined:
1927 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1928 fputc ('\n', asm_out_file);
1930 case DW_CFA_same_value:
1931 case DW_CFA_def_cfa_register:
1932 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1933 fputc ('\n', asm_out_file);
1935 case DW_CFA_register:
1936 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1937 fputc ('\n', asm_out_file);
1938 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1939 fputc ('\n', asm_out_file);
1941 case DW_CFA_def_cfa_offset:
1942 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1943 fputc ('\n', asm_out_file);
1945 case DW_CFA_GNU_window_save:
1947 case DW_CFA_GNU_args_size:
1948 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1949 fputc ('\n', asm_out_file);
1951 case DW_CFA_def_cfa_expression:
1952 output_cfa_loc (cfi);
1960 /* Output the call frame information used to used to record information
1961 that relates to calculating the frame pointer, and records the
1962 location of saved registers. */
1965 output_call_frame_info (for_eh)
1968 register unsigned long i;
1969 register dw_fde_ref fde;
1970 register dw_cfi_ref cfi;
1971 char l1[20], l2[20];
1972 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1976 /* Do we want to include a pointer to the exception table? */
1977 int eh_ptr = for_eh && exception_table_p ();
1979 /* If we don't have any functions we'll want to unwind out of, don't
1980 emit any EH unwind information. */
1983 for (i = 0; i < fde_table_in_use; ++i)
1984 if (! fde_table[i].nothrow)
1990 fputc ('\n', asm_out_file);
1992 /* We're going to be generating comments, so turn on app. */
1998 #ifdef EH_FRAME_SECTION
1999 EH_FRAME_SECTION ();
2001 tree label = get_file_function_name ('F');
2003 force_data_section ();
2004 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2005 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2006 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2008 assemble_label ("__FRAME_BEGIN__");
2011 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
2013 /* Output the CIE. */
2014 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2015 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2016 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2017 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
2019 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
2021 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
2024 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
2026 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
2029 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
2032 fputc ('\n', asm_out_file);
2033 ASM_OUTPUT_LABEL (asm_out_file, l1);
2036 /* Now that the CIE pointer is PC-relative for EH,
2037 use 0 to identify the CIE. */
2038 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2040 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
2043 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
2045 fputc ('\n', asm_out_file);
2046 if (! for_eh && DWARF_OFFSET_SIZE == 8)
2048 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
2049 fputc ('\n', asm_out_file);
2052 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
2054 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
2056 fputc ('\n', asm_out_file);
2059 /* The CIE contains a pointer to the exception region info for the
2060 frame. Make the augmentation string three bytes (including the
2061 trailing null) so the pointer is 4-byte aligned. The Solaris ld
2062 can't handle unaligned relocs. */
2065 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
2066 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
2070 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
2072 fputc ('\n', asm_out_file);
2074 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
2076 fprintf (asm_out_file, "\t%s pointer to exception region info",
2081 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
2083 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
2087 fputc ('\n', asm_out_file);
2090 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
2092 fputc ('\n', asm_out_file);
2093 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
2095 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
2097 fputc ('\n', asm_out_file);
2098 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
2100 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
2102 fputc ('\n', asm_out_file);
2104 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2105 output_cfi (cfi, NULL);
2107 /* Pad the CIE out to an address sized boundary. */
2108 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2109 ASM_OUTPUT_LABEL (asm_out_file, l2);
2110 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2111 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
2113 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
2114 fputc ('\n', asm_out_file);
2117 /* Loop through all of the FDE's. */
2118 for (i = 0; i < fde_table_in_use; ++i)
2120 fde = &fde_table[i];
2122 /* Don't emit EH unwind info for leaf functions. */
2123 if (for_eh && fde->nothrow)
2126 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2127 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2128 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2129 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i * 2);
2131 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
2133 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
2136 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
2138 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
2141 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
2142 fputc ('\n', asm_out_file);
2143 ASM_OUTPUT_LABEL (asm_out_file, l1);
2145 /* ??? This always emits a 4 byte offset when for_eh is true, but it
2146 emits a target dependent sized offset when for_eh is not true.
2147 This inconsistency may confuse gdb. The only case where we need a
2148 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
2149 compatibility if we emit a 4 byte offset. We need a 4 byte offset
2150 though in order to be compatible with the dwarf_fde struct in frame.c.
2151 If the for_eh case is changed, then the struct in frame.c has
2152 to be adjusted appropriately. */
2154 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
2156 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
2158 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
2160 fputc ('\n', asm_out_file);
2161 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
2163 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
2165 fputc ('\n', asm_out_file);
2166 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
2167 fde->dw_fde_end, fde->dw_fde_begin);
2169 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
2171 fputc ('\n', asm_out_file);
2173 /* Loop through the Call Frame Instructions associated with
2175 fde->dw_fde_current_label = fde->dw_fde_begin;
2176 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2177 output_cfi (cfi, fde);
2179 /* Pad the FDE out to an address sized boundary. */
2180 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2181 ASM_OUTPUT_LABEL (asm_out_file, l2);
2182 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2183 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
2185 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
2186 fputc ('\n', asm_out_file);
2189 #ifndef EH_FRAME_SECTION
2192 /* Emit terminating zero for table. */
2193 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2194 fputc ('\n', asm_out_file);
2197 #ifdef MIPS_DEBUGGING_INFO
2198 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2199 get a value of 0. Putting .align 0 after the label fixes it. */
2200 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2203 /* Turn off app to make assembly quicker. */
2208 /* Output a marker (i.e. a label) for the beginning of a function, before
2212 dwarf2out_begin_prologue ()
2214 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2215 register dw_fde_ref fde;
2217 ++current_funcdef_number;
2219 function_section (current_function_decl);
2220 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2221 current_funcdef_number);
2222 ASM_OUTPUT_LABEL (asm_out_file, label);
2223 current_function_func_begin_label = get_identifier (label);
2225 /* Expand the fde table if necessary. */
2226 if (fde_table_in_use == fde_table_allocated)
2228 fde_table_allocated += FDE_TABLE_INCREMENT;
2230 = (dw_fde_ref) xrealloc (fde_table,
2231 fde_table_allocated * sizeof (dw_fde_node));
2234 /* Record the FDE associated with this function. */
2235 current_funcdef_fde = fde_table_in_use;
2237 /* Add the new FDE at the end of the fde_table. */
2238 fde = &fde_table[fde_table_in_use++];
2239 fde->dw_fde_begin = xstrdup (label);
2240 fde->dw_fde_current_label = NULL;
2241 fde->dw_fde_end = NULL;
2242 fde->dw_fde_cfi = NULL;
2243 fde->nothrow = current_function_nothrow;
2245 args_size = old_args_size = 0;
2248 /* Output a marker (i.e. a label) for the absolute end of the generated code
2249 for a function definition. This gets called *after* the epilogue code has
2253 dwarf2out_end_epilogue ()
2256 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2258 /* Output a label to mark the endpoint of the code generated for this
2260 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2261 ASM_OUTPUT_LABEL (asm_out_file, label);
2262 fde = &fde_table[fde_table_in_use - 1];
2263 fde->dw_fde_end = xstrdup (label);
2267 dwarf2out_frame_init ()
2269 /* Allocate the initial hunk of the fde_table. */
2270 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2271 fde_table_allocated = FDE_TABLE_INCREMENT;
2272 fde_table_in_use = 0;
2274 /* Generate the CFA instructions common to all FDE's. Do it now for the
2275 sake of lookup_cfa. */
2277 #ifdef DWARF2_UNWIND_INFO
2278 /* On entry, the Canonical Frame Address is at SP. */
2279 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2280 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2285 dwarf2out_frame_finish ()
2287 /* Output call frame information. */
2288 #ifdef MIPS_DEBUGGING_INFO
2289 if (write_symbols == DWARF2_DEBUG)
2290 output_call_frame_info (0);
2291 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2292 output_call_frame_info (1);
2294 if (write_symbols == DWARF2_DEBUG
2295 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2296 output_call_frame_info (1);
2300 /* And now, the subset of the debugging information support code necessary
2301 for emitting location expressions. */
2303 typedef struct dw_val_struct *dw_val_ref;
2304 typedef struct die_struct *dw_die_ref;
2305 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2307 /* Each DIE may have a series of attribute/value pairs. Values
2308 can take on several forms. The forms that are used in this
2309 implementation are listed below. */
2316 dw_val_class_unsigned_const,
2317 dw_val_class_long_long,
2320 dw_val_class_die_ref,
2321 dw_val_class_fde_ref,
2322 dw_val_class_lbl_id,
2323 dw_val_class_lbl_offset,
2328 /* Describe a double word constant value. */
2329 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2331 typedef struct dw_long_long_struct
2338 /* Describe a floating point constant value. */
2340 typedef struct dw_fp_struct
2347 /* The dw_val_node describes an attribute's value, as it is
2348 represented internally. */
2350 typedef struct dw_val_struct
2352 dw_val_class val_class;
2356 dw_loc_descr_ref val_loc;
2358 long unsigned val_unsigned;
2359 dw_long_long_const val_long_long;
2360 dw_float_const val_float;
2365 unsigned val_fde_index;
2368 unsigned char val_flag;
2374 /* Locations in memory are described using a sequence of stack machine
2377 typedef struct dw_loc_descr_struct
2379 dw_loc_descr_ref dw_loc_next;
2380 enum dwarf_location_atom dw_loc_opc;
2381 dw_val_node dw_loc_oprnd1;
2382 dw_val_node dw_loc_oprnd2;
2387 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2388 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2391 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2393 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2394 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2395 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2396 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2398 /* Convert a DWARF stack opcode into its string name. */
2401 dwarf_stack_op_name (op)
2402 register unsigned op;
2407 return "DW_OP_addr";
2409 return "DW_OP_deref";
2411 return "DW_OP_const1u";
2413 return "DW_OP_const1s";
2415 return "DW_OP_const2u";
2417 return "DW_OP_const2s";
2419 return "DW_OP_const4u";
2421 return "DW_OP_const4s";
2423 return "DW_OP_const8u";
2425 return "DW_OP_const8s";
2427 return "DW_OP_constu";
2429 return "DW_OP_consts";
2433 return "DW_OP_drop";
2435 return "DW_OP_over";
2437 return "DW_OP_pick";
2439 return "DW_OP_swap";
2443 return "DW_OP_xderef";
2451 return "DW_OP_minus";
2463 return "DW_OP_plus";
2464 case DW_OP_plus_uconst:
2465 return "DW_OP_plus_uconst";
2471 return "DW_OP_shra";
2489 return "DW_OP_skip";
2491 return "DW_OP_lit0";
2493 return "DW_OP_lit1";
2495 return "DW_OP_lit2";
2497 return "DW_OP_lit3";
2499 return "DW_OP_lit4";
2501 return "DW_OP_lit5";
2503 return "DW_OP_lit6";
2505 return "DW_OP_lit7";
2507 return "DW_OP_lit8";
2509 return "DW_OP_lit9";
2511 return "DW_OP_lit10";
2513 return "DW_OP_lit11";
2515 return "DW_OP_lit12";
2517 return "DW_OP_lit13";
2519 return "DW_OP_lit14";
2521 return "DW_OP_lit15";
2523 return "DW_OP_lit16";
2525 return "DW_OP_lit17";
2527 return "DW_OP_lit18";
2529 return "DW_OP_lit19";
2531 return "DW_OP_lit20";
2533 return "DW_OP_lit21";
2535 return "DW_OP_lit22";
2537 return "DW_OP_lit23";
2539 return "DW_OP_lit24";
2541 return "DW_OP_lit25";
2543 return "DW_OP_lit26";
2545 return "DW_OP_lit27";
2547 return "DW_OP_lit28";
2549 return "DW_OP_lit29";
2551 return "DW_OP_lit30";
2553 return "DW_OP_lit31";
2555 return "DW_OP_reg0";
2557 return "DW_OP_reg1";
2559 return "DW_OP_reg2";
2561 return "DW_OP_reg3";
2563 return "DW_OP_reg4";
2565 return "DW_OP_reg5";
2567 return "DW_OP_reg6";
2569 return "DW_OP_reg7";
2571 return "DW_OP_reg8";
2573 return "DW_OP_reg9";
2575 return "DW_OP_reg10";
2577 return "DW_OP_reg11";
2579 return "DW_OP_reg12";
2581 return "DW_OP_reg13";
2583 return "DW_OP_reg14";
2585 return "DW_OP_reg15";
2587 return "DW_OP_reg16";
2589 return "DW_OP_reg17";
2591 return "DW_OP_reg18";
2593 return "DW_OP_reg19";
2595 return "DW_OP_reg20";
2597 return "DW_OP_reg21";
2599 return "DW_OP_reg22";
2601 return "DW_OP_reg23";
2603 return "DW_OP_reg24";
2605 return "DW_OP_reg25";
2607 return "DW_OP_reg26";
2609 return "DW_OP_reg27";
2611 return "DW_OP_reg28";
2613 return "DW_OP_reg29";
2615 return "DW_OP_reg30";
2617 return "DW_OP_reg31";
2619 return "DW_OP_breg0";
2621 return "DW_OP_breg1";
2623 return "DW_OP_breg2";
2625 return "DW_OP_breg3";
2627 return "DW_OP_breg4";
2629 return "DW_OP_breg5";
2631 return "DW_OP_breg6";
2633 return "DW_OP_breg7";
2635 return "DW_OP_breg8";
2637 return "DW_OP_breg9";
2639 return "DW_OP_breg10";
2641 return "DW_OP_breg11";
2643 return "DW_OP_breg12";
2645 return "DW_OP_breg13";
2647 return "DW_OP_breg14";
2649 return "DW_OP_breg15";
2651 return "DW_OP_breg16";
2653 return "DW_OP_breg17";
2655 return "DW_OP_breg18";
2657 return "DW_OP_breg19";
2659 return "DW_OP_breg20";
2661 return "DW_OP_breg21";
2663 return "DW_OP_breg22";
2665 return "DW_OP_breg23";
2667 return "DW_OP_breg24";
2669 return "DW_OP_breg25";
2671 return "DW_OP_breg26";
2673 return "DW_OP_breg27";
2675 return "DW_OP_breg28";
2677 return "DW_OP_breg29";
2679 return "DW_OP_breg30";
2681 return "DW_OP_breg31";
2683 return "DW_OP_regx";
2685 return "DW_OP_fbreg";
2687 return "DW_OP_bregx";
2689 return "DW_OP_piece";
2690 case DW_OP_deref_size:
2691 return "DW_OP_deref_size";
2692 case DW_OP_xderef_size:
2693 return "DW_OP_xderef_size";
2697 return "OP_<unknown>";
2701 /* Return a pointer to a newly allocated location description. Location
2702 descriptions are simple expression terms that can be strung
2703 together to form more complicated location (address) descriptions. */
2705 static inline dw_loc_descr_ref
2706 new_loc_descr (op, oprnd1, oprnd2)
2707 register enum dwarf_location_atom op;
2708 register unsigned long oprnd1;
2709 register unsigned long oprnd2;
2711 /* Use xcalloc here so we clear out all of the long_long constant in
2713 register dw_loc_descr_ref descr
2714 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2716 descr->dw_loc_opc = op;
2717 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2718 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2719 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2720 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2725 /* Add a location description term to a location description expression. */
2728 add_loc_descr (list_head, descr)
2729 register dw_loc_descr_ref *list_head;
2730 register dw_loc_descr_ref descr;
2732 register dw_loc_descr_ref *d;
2734 /* Find the end of the chain. */
2735 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2741 /* Return the size of a location descriptor. */
2743 static unsigned long
2744 size_of_loc_descr (loc)
2745 register dw_loc_descr_ref loc;
2747 register unsigned long size = 1;
2749 switch (loc->dw_loc_opc)
2752 size += DWARF2_ADDR_SIZE;
2771 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2774 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2779 case DW_OP_plus_uconst:
2780 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2818 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2821 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2824 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2827 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2828 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2831 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2833 case DW_OP_deref_size:
2834 case DW_OP_xderef_size:
2844 /* Return the size of a series of location descriptors. */
2846 static unsigned long
2848 register dw_loc_descr_ref loc;
2850 register unsigned long size = 0;
2852 for (; loc != NULL; loc = loc->dw_loc_next)
2854 loc->dw_loc_addr = size;
2855 size += size_of_loc_descr (loc);
2861 /* Output location description stack opcode's operands (if any). */
2864 output_loc_operands (loc)
2865 register dw_loc_descr_ref loc;
2867 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2868 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2870 switch (loc->dw_loc_opc)
2872 #ifdef DWARF2_DEBUGGING_INFO
2874 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
2875 fputc ('\n', asm_out_file);
2879 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2880 fputc ('\n', asm_out_file);
2884 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
2885 fputc ('\n', asm_out_file);
2890 fputc ('\n', asm_out_file);
2897 if (val1->val_class == dw_val_class_loc)
2898 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2902 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, offset);
2903 fputc ('\n', asm_out_file);
2916 /* We currently don't make any attempt to make sure these are
2917 aligned properly like we do for the main unwind info, so
2918 don't support emitting things larger than a byte if we're
2919 only doing unwinding. */
2924 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2925 fputc ('\n', asm_out_file);
2928 output_uleb128 (val1->v.val_unsigned);
2929 fputc ('\n', asm_out_file);
2932 output_sleb128 (val1->v.val_int);
2933 fputc ('\n', asm_out_file);
2936 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
2937 fputc ('\n', asm_out_file);
2939 case DW_OP_plus_uconst:
2940 output_uleb128 (val1->v.val_unsigned);
2941 fputc ('\n', asm_out_file);
2975 output_sleb128 (val1->v.val_int);
2976 fputc ('\n', asm_out_file);
2979 output_uleb128 (val1->v.val_unsigned);
2980 fputc ('\n', asm_out_file);
2983 output_sleb128 (val1->v.val_int);
2984 fputc ('\n', asm_out_file);
2987 output_uleb128 (val1->v.val_unsigned);
2988 fputc ('\n', asm_out_file);
2989 output_sleb128 (val2->v.val_int);
2990 fputc ('\n', asm_out_file);
2993 output_uleb128 (val1->v.val_unsigned);
2994 fputc ('\n', asm_out_file);
2996 case DW_OP_deref_size:
2997 case DW_OP_xderef_size:
2998 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2999 fputc ('\n', asm_out_file);
3002 /* Other codes have no operands. */
3007 /* Output a sequence of location operations. */
3010 output_loc_sequence (loc)
3011 dw_loc_descr_ref loc;
3013 for (; loc != NULL; loc = loc->dw_loc_next)
3015 /* Output the opcode. */
3016 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
3018 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
3019 dwarf_stack_op_name (loc->dw_loc_opc));
3021 fputc ('\n', asm_out_file);
3023 /* Output the operand(s) (if any). */
3024 output_loc_operands (loc);
3028 /* This routine will generate the correct assembly data for a location
3029 description based on a cfi entry with a complex address. */
3032 output_cfa_loc (cfi)
3035 dw_loc_descr_ref loc;
3038 /* Output the size of the block. */
3039 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3040 size = size_of_locs (loc);
3041 output_uleb128 (size);
3042 fputc ('\n', asm_out_file);
3044 /* Now output the operations themselves. */
3045 output_loc_sequence (loc);
3048 /* This function builds a dwarf location descriptor seqeunce from
3049 a dw_cfa_location. */
3051 static struct dw_loc_descr_struct *
3053 dw_cfa_location *cfa;
3055 struct dw_loc_descr_struct *head, *tmp;
3057 if (cfa->indirect == 0)
3060 if (cfa->base_offset)
3063 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3065 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3067 else if (cfa->reg <= 31)
3068 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3070 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3071 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3072 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3073 add_loc_descr (&head, tmp);
3074 if (cfa->offset != 0)
3076 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3077 add_loc_descr (&head, tmp);
3082 /* This function fills in aa dw_cfa_location structure from a
3083 dwarf location descriptor sequence. */
3086 get_cfa_from_loc_descr (cfa, loc)
3087 dw_cfa_location *cfa;
3088 struct dw_loc_descr_struct *loc;
3090 struct dw_loc_descr_struct *ptr;
3092 cfa->base_offset = 0;
3096 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3098 enum dwarf_location_atom op = ptr->dw_loc_opc;
3133 cfa->reg = op - DW_OP_reg0;
3136 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3170 cfa->reg = op - DW_OP_breg0;
3171 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3174 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3175 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3180 case DW_OP_plus_uconst:
3181 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3184 internal_error ("DW_LOC_OP %s not implememnted\n",
3185 dwarf_stack_op_name (ptr->dw_loc_opc));
3189 #endif /* .debug_frame support */
3191 /* And now, the support for symbolic debugging information. */
3192 #ifdef DWARF2_DEBUGGING_INFO
3194 /* NOTE: In the comments in this file, many references are made to
3195 "Debugging Information Entries". This term is abbreviated as `DIE'
3196 throughout the remainder of this file. */
3198 /* An internal representation of the DWARF output is built, and then
3199 walked to generate the DWARF debugging info. The walk of the internal
3200 representation is done after the entire program has been compiled.
3201 The types below are used to describe the internal representation. */
3203 /* Various DIE's use offsets relative to the beginning of the
3204 .debug_info section to refer to each other. */
3206 typedef long int dw_offset;
3208 /* Define typedefs here to avoid circular dependencies. */
3210 typedef struct dw_attr_struct *dw_attr_ref;
3211 typedef struct dw_line_info_struct *dw_line_info_ref;
3212 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3213 typedef struct pubname_struct *pubname_ref;
3214 typedef dw_die_ref *arange_ref;
3216 /* Each entry in the line_info_table maintains the file and
3217 line number associated with the label generated for that
3218 entry. The label gives the PC value associated with
3219 the line number entry. */
3221 typedef struct dw_line_info_struct
3223 unsigned long dw_file_num;
3224 unsigned long dw_line_num;
3228 /* Line information for functions in separate sections; each one gets its
3230 typedef struct dw_separate_line_info_struct
3232 unsigned long dw_file_num;
3233 unsigned long dw_line_num;
3234 unsigned long function;
3236 dw_separate_line_info_entry;
3238 /* Each DIE attribute has a field specifying the attribute kind,
3239 a link to the next attribute in the chain, and an attribute value.
3240 Attributes are typically linked below the DIE they modify. */
3242 typedef struct dw_attr_struct
3244 enum dwarf_attribute dw_attr;
3245 dw_attr_ref dw_attr_next;
3246 dw_val_node dw_attr_val;
3250 /* The Debugging Information Entry (DIE) structure */
3252 typedef struct die_struct
3254 enum dwarf_tag die_tag;
3256 dw_attr_ref die_attr;
3257 dw_die_ref die_parent;
3258 dw_die_ref die_child;
3260 dw_offset die_offset;
3261 unsigned long die_abbrev;
3266 /* The pubname structure */
3268 typedef struct pubname_struct
3275 /* The limbo die list structure. */
3276 typedef struct limbo_die_struct
3279 struct limbo_die_struct *next;
3283 /* How to start an assembler comment. */
3284 #ifndef ASM_COMMENT_START
3285 #define ASM_COMMENT_START ";#"
3288 /* Define a macro which returns non-zero for a TYPE_DECL which was
3289 implicitly generated for a tagged type.
3291 Note that unlike the gcc front end (which generates a NULL named
3292 TYPE_DECL node for each complete tagged type, each array type, and
3293 each function type node created) the g++ front end generates a
3294 _named_ TYPE_DECL node for each tagged type node created.
3295 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3296 generate a DW_TAG_typedef DIE for them. */
3298 #define TYPE_DECL_IS_STUB(decl) \
3299 (DECL_NAME (decl) == NULL_TREE \
3300 || (DECL_ARTIFICIAL (decl) \
3301 && is_tagged_type (TREE_TYPE (decl)) \
3302 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3303 /* This is necessary for stub decls that \
3304 appear in nested inline functions. */ \
3305 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3306 && (decl_ultimate_origin (decl) \
3307 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3309 /* Information concerning the compilation unit's programming
3310 language, and compiler version. */
3312 extern int flag_traditional;
3314 /* Fixed size portion of the DWARF compilation unit header. */
3315 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3317 /* Fixed size portion of debugging line information prolog. */
3318 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3320 /* Fixed size portion of public names info. */
3321 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3323 /* Fixed size portion of the address range info. */
3324 #define DWARF_ARANGES_HEADER_SIZE \
3325 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3326 - DWARF_OFFSET_SIZE)
3328 /* Size of padding portion in the address range info. It must be
3329 aligned to twice the pointer size. */
3330 #define DWARF_ARANGES_PAD_SIZE \
3331 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3332 - (2 * DWARF_OFFSET_SIZE + 4))
3334 /* Use assembler line directives if available. */
3335 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3336 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3337 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3339 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3343 /* Define the architecture-dependent minimum instruction length (in bytes).
3344 In this implementation of DWARF, this field is used for information
3345 purposes only. Since GCC generates assembly language, we have
3346 no a priori knowledge of how many instruction bytes are generated
3347 for each source line, and therefore can use only the DW_LNE_set_address
3348 and DW_LNS_fixed_advance_pc line information commands. */
3350 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3351 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3354 /* Minimum line offset in a special line info. opcode.
3355 This value was chosen to give a reasonable range of values. */
3356 #define DWARF_LINE_BASE -10
3358 /* First special line opcde - leave room for the standard opcodes. */
3359 #define DWARF_LINE_OPCODE_BASE 10
3361 /* Range of line offsets in a special line info. opcode. */
3362 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3364 /* Flag that indicates the initial value of the is_stmt_start flag.
3365 In the present implementation, we do not mark any lines as
3366 the beginning of a source statement, because that information
3367 is not made available by the GCC front-end. */
3368 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3370 /* This location is used by calc_die_sizes() to keep track
3371 the offset of each DIE within the .debug_info section. */
3372 static unsigned long next_die_offset;
3374 /* Record the root of the DIE's built for the current compilation unit. */
3375 static dw_die_ref comp_unit_die;
3377 /* A list of DIEs with a NULL parent waiting to be relocated. */
3378 static limbo_die_node *limbo_die_list = 0;
3380 /* Structure used by lookup_filename to manage sets of filenames. */
3386 unsigned last_lookup_index;
3389 /* Size (in elements) of increments by which we may expand the filename
3391 #define FILE_TABLE_INCREMENT 64
3393 /* Filenames referenced by declarations this compilation unit. */
3394 static struct file_table decl_file_table;
3396 /* Filenames referenced by line numbers in this compilation unit. */
3397 static struct file_table line_file_table;
3399 /* Local pointer to the name of the main input file. Initialized in
3401 static const char *primary_filename;
3403 /* A pointer to the base of a table of references to DIE's that describe
3404 declarations. The table is indexed by DECL_UID() which is a unique
3405 number identifying each decl. */
3406 static dw_die_ref *decl_die_table;
3408 /* Number of elements currently allocated for the decl_die_table. */
3409 static unsigned decl_die_table_allocated;
3411 /* Number of elements in decl_die_table currently in use. */
3412 static unsigned decl_die_table_in_use;
3414 /* Size (in elements) of increments by which we may expand the
3416 #define DECL_DIE_TABLE_INCREMENT 256
3418 /* A pointer to the base of a table of references to declaration
3419 scopes. This table is a display which tracks the nesting
3420 of declaration scopes at the current scope and containing
3421 scopes. This table is used to find the proper place to
3422 define type declaration DIE's. */
3423 static tree *decl_scope_table;
3425 /* Number of elements currently allocated for the decl_scope_table. */
3426 static int decl_scope_table_allocated;
3428 /* Current level of nesting of declaration scopes. */
3429 static int decl_scope_depth;
3431 /* Size (in elements) of increments by which we may expand the
3432 decl_scope_table. */
3433 #define DECL_SCOPE_TABLE_INCREMENT 64
3435 /* A pointer to the base of a list of references to DIE's that
3436 are uniquely identified by their tag, presence/absence of
3437 children DIE's, and list of attribute/value pairs. */
3438 static dw_die_ref *abbrev_die_table;
3440 /* Number of elements currently allocated for abbrev_die_table. */
3441 static unsigned abbrev_die_table_allocated;
3443 /* Number of elements in type_die_table currently in use. */
3444 static unsigned abbrev_die_table_in_use;
3446 /* Size (in elements) of increments by which we may expand the
3447 abbrev_die_table. */
3448 #define ABBREV_DIE_TABLE_INCREMENT 256
3450 /* A pointer to the base of a table that contains line information
3451 for each source code line in .text in the compilation unit. */
3452 static dw_line_info_ref line_info_table;
3454 /* Number of elements currently allocated for line_info_table. */
3455 static unsigned line_info_table_allocated;
3457 /* Number of elements in separate_line_info_table currently in use. */
3458 static unsigned separate_line_info_table_in_use;
3460 /* A pointer to the base of a table that contains line information
3461 for each source code line outside of .text in the compilation unit. */
3462 static dw_separate_line_info_ref separate_line_info_table;
3464 /* Number of elements currently allocated for separate_line_info_table. */
3465 static unsigned separate_line_info_table_allocated;
3467 /* Number of elements in line_info_table currently in use. */
3468 static unsigned line_info_table_in_use;
3470 /* Size (in elements) of increments by which we may expand the
3472 #define LINE_INFO_TABLE_INCREMENT 1024
3474 /* A pointer to the base of a table that contains a list of publicly
3475 accessible names. */
3476 static pubname_ref pubname_table;
3478 /* Number of elements currently allocated for pubname_table. */
3479 static unsigned pubname_table_allocated;
3481 /* Number of elements in pubname_table currently in use. */
3482 static unsigned pubname_table_in_use;
3484 /* Size (in elements) of increments by which we may expand the
3486 #define PUBNAME_TABLE_INCREMENT 64
3488 /* A pointer to the base of a table that contains a list of publicly
3489 accessible names. */
3490 static arange_ref arange_table;
3492 /* Number of elements currently allocated for arange_table. */
3493 static unsigned arange_table_allocated;
3495 /* Number of elements in arange_table currently in use. */
3496 static unsigned arange_table_in_use;
3498 /* Size (in elements) of increments by which we may expand the
3500 #define ARANGE_TABLE_INCREMENT 64
3502 /* A pointer to the base of a list of incomplete types which might be
3503 completed at some later time. */
3505 static tree *incomplete_types_list;
3507 /* Number of elements currently allocated for the incomplete_types_list. */
3508 static unsigned incomplete_types_allocated;
3510 /* Number of elements of incomplete_types_list currently in use. */
3511 static unsigned incomplete_types;
3513 /* Size (in elements) of increments by which we may expand the incomplete
3514 types list. Actually, a single hunk of space of this size should
3515 be enough for most typical programs. */
3516 #define INCOMPLETE_TYPES_INCREMENT 64
3518 /* Record whether the function being analyzed contains inlined functions. */
3519 static int current_function_has_inlines;
3520 #if 0 && defined (MIPS_DEBUGGING_INFO)
3521 static int comp_unit_has_inlines;
3524 /* Array of RTXes referenced by the debugging information, which therefore
3525 must be kept around forever. We do this rather than perform GC on
3526 the dwarf info because almost all of the dwarf info lives forever, and
3527 it's easier to support non-GC frontends this way. */
3528 static varray_type used_rtx_varray;
3530 /* Forward declarations for functions defined in this file. */
3532 static int is_pseudo_reg PARAMS ((rtx));
3533 static tree type_main_variant PARAMS ((tree));
3534 static int is_tagged_type PARAMS ((tree));
3535 static const char *dwarf_tag_name PARAMS ((unsigned));
3536 static const char *dwarf_attr_name PARAMS ((unsigned));
3537 static const char *dwarf_form_name PARAMS ((unsigned));
3539 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3541 static tree decl_ultimate_origin PARAMS ((tree));
3542 static tree block_ultimate_origin PARAMS ((tree));
3543 static tree decl_class_context PARAMS ((tree));
3544 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3545 static void add_AT_flag PARAMS ((dw_die_ref,
3546 enum dwarf_attribute,
3548 static void add_AT_int PARAMS ((dw_die_ref,
3549 enum dwarf_attribute, long));
3550 static void add_AT_unsigned PARAMS ((dw_die_ref,
3551 enum dwarf_attribute,
3553 static void add_AT_long_long PARAMS ((dw_die_ref,
3554 enum dwarf_attribute,
3557 static void add_AT_float PARAMS ((dw_die_ref,
3558 enum dwarf_attribute,
3560 static void add_AT_string PARAMS ((dw_die_ref,
3561 enum dwarf_attribute,
3563 static void add_AT_die_ref PARAMS ((dw_die_ref,
3564 enum dwarf_attribute,
3566 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3567 enum dwarf_attribute,
3569 static void add_AT_loc PARAMS ((dw_die_ref,
3570 enum dwarf_attribute,
3572 static void add_AT_addr PARAMS ((dw_die_ref,
3573 enum dwarf_attribute,
3575 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3576 enum dwarf_attribute,
3578 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3579 enum dwarf_attribute,
3581 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3582 enum dwarf_attribute));
3583 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3584 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3585 static const char *get_AT_string PARAMS ((dw_die_ref,
3586 enum dwarf_attribute));
3587 static int get_AT_flag PARAMS ((dw_die_ref,
3588 enum dwarf_attribute));
3589 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3590 enum dwarf_attribute));
3591 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3592 enum dwarf_attribute));
3593 static int is_c_family PARAMS ((void));
3594 static int is_java PARAMS ((void));
3595 static int is_fortran PARAMS ((void));
3596 static void remove_AT PARAMS ((dw_die_ref,
3597 enum dwarf_attribute));
3598 static void remove_children PARAMS ((dw_die_ref));
3599 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3600 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3601 static dw_die_ref lookup_type_die PARAMS ((tree));
3602 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3603 static dw_die_ref lookup_decl_die PARAMS ((tree));
3604 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3605 static void print_spaces PARAMS ((FILE *));
3606 static void print_die PARAMS ((dw_die_ref, FILE *));
3607 static void print_dwarf_line_table PARAMS ((FILE *));
3608 static void reverse_die_lists PARAMS ((dw_die_ref));
3609 static void reverse_all_dies PARAMS ((dw_die_ref));
3610 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3611 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3612 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3613 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3614 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3615 static void compute_section_prefix PARAMS ((dw_die_ref));
3616 static int is_type_die PARAMS ((dw_die_ref));
3617 static int is_comdat_die PARAMS ((dw_die_ref));
3618 static int is_symbol_die PARAMS ((dw_die_ref));
3619 static char *gen_internal_sym PARAMS ((void));
3620 static void assign_symbol_names PARAMS ((dw_die_ref));
3621 static void break_out_includes PARAMS ((dw_die_ref));
3622 static void add_sibling_attributes PARAMS ((dw_die_ref));
3623 static void build_abbrev_table PARAMS ((dw_die_ref));
3624 static unsigned long size_of_string PARAMS ((const char *));
3625 static int constant_size PARAMS ((long unsigned));
3626 static unsigned long size_of_die PARAMS ((dw_die_ref));
3627 static void calc_die_sizes PARAMS ((dw_die_ref));
3628 static void mark_dies PARAMS ((dw_die_ref));
3629 static void unmark_dies PARAMS ((dw_die_ref));
3630 static unsigned long size_of_line_prolog PARAMS ((void));
3631 static unsigned long size_of_pubnames PARAMS ((void));
3632 static unsigned long size_of_aranges PARAMS ((void));
3633 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3634 static void output_value_format PARAMS ((dw_attr_ref));
3635 static void output_abbrev_section PARAMS ((void));
3636 static void output_die_symbol PARAMS ((dw_die_ref));
3637 static void output_symbolic_ref PARAMS ((dw_die_ref));
3638 static void output_die PARAMS ((dw_die_ref));
3639 static void output_compilation_unit_header PARAMS ((void));
3640 static void output_comp_unit PARAMS ((dw_die_ref));
3641 static const char *dwarf2_name PARAMS ((tree, int));
3642 static void add_pubname PARAMS ((tree, dw_die_ref));
3643 static void output_pubnames PARAMS ((void));
3644 static void add_arange PARAMS ((tree, dw_die_ref));
3645 static void output_aranges PARAMS ((void));
3646 static void output_line_info PARAMS ((void));
3647 static void output_file_names PARAMS ((void));
3648 static dw_die_ref base_type_die PARAMS ((tree));
3649 static tree root_type PARAMS ((tree));
3650 static int is_base_type PARAMS ((tree));
3651 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3652 static int type_is_enum PARAMS ((tree));
3653 static unsigned int reg_number PARAMS ((rtx));
3654 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3655 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3656 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3657 static int is_based_loc PARAMS ((rtx));
3658 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3659 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3660 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3661 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3662 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3663 static tree field_type PARAMS ((tree));
3664 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3665 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3666 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3667 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3668 static void add_AT_location_description PARAMS ((dw_die_ref,
3669 enum dwarf_attribute, rtx));
3670 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3671 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3672 static rtx rtl_for_decl_location PARAMS ((tree));
3673 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3674 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3675 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3676 static void add_bound_info PARAMS ((dw_die_ref,
3677 enum dwarf_attribute, tree));
3678 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3679 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3680 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3681 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3682 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3683 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3684 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3685 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3686 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3687 static void push_decl_scope PARAMS ((tree));
3688 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3689 static void pop_decl_scope PARAMS ((void));
3690 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3692 static const char *type_tag PARAMS ((tree));
3693 static tree member_declared_type PARAMS ((tree));
3695 static const char *decl_start_label PARAMS ((tree));
3697 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3698 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3700 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3702 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3703 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3704 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3705 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3706 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3707 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3708 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3709 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3710 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3711 static void gen_label_die PARAMS ((tree, dw_die_ref));
3712 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3713 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3714 static void gen_field_die PARAMS ((tree, dw_die_ref));
3715 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3716 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3717 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3718 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3719 static void gen_member_die PARAMS ((tree, dw_die_ref));
3720 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3721 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3722 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3723 static void gen_type_die PARAMS ((tree, dw_die_ref));
3724 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3725 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3726 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3727 static int is_redundant_typedef PARAMS ((tree));
3728 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3729 static unsigned lookup_filename PARAMS ((struct file_table *,
3731 static void init_file_table PARAMS ((struct file_table *));
3732 static void add_incomplete_type PARAMS ((tree));
3733 static void retry_incomplete_types PARAMS ((void));
3734 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3735 static void gen_abstract_function PARAMS ((tree));
3736 static rtx save_rtx PARAMS ((rtx));
3737 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3738 static int file_info_cmp PARAMS ((const void *, const void *));
3740 /* Section names used to hold DWARF debugging information. */
3741 #ifndef DEBUG_INFO_SECTION
3742 #define DEBUG_INFO_SECTION ".debug_info"
3744 #ifndef ABBREV_SECTION
3745 #define ABBREV_SECTION ".debug_abbrev"
3747 #ifndef ARANGES_SECTION
3748 #define ARANGES_SECTION ".debug_aranges"
3750 #ifndef DW_MACINFO_SECTION
3751 #define DW_MACINFO_SECTION ".debug_macinfo"
3753 #ifndef DEBUG_LINE_SECTION
3754 #define DEBUG_LINE_SECTION ".debug_line"
3757 #define LOC_SECTION ".debug_loc"
3759 #ifndef PUBNAMES_SECTION
3760 #define PUBNAMES_SECTION ".debug_pubnames"
3763 #define STR_SECTION ".debug_str"
3766 /* Standard ELF section names for compiled code and data. */
3767 #ifndef TEXT_SECTION
3768 #define TEXT_SECTION ".text"
3770 #ifndef DATA_SECTION
3771 #define DATA_SECTION ".data"
3774 #define BSS_SECTION ".bss"
3777 /* Labels we insert at beginning sections we can reference instead of
3778 the section names themselves. */
3780 #ifndef TEXT_SECTION_LABEL
3781 #define TEXT_SECTION_LABEL "Ltext"
3783 #ifndef DEBUG_LINE_SECTION_LABEL
3784 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3786 #ifndef DEBUG_INFO_SECTION_LABEL
3787 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3789 #ifndef ABBREV_SECTION_LABEL
3790 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3793 /* Definitions of defaults for formats and names of various special
3794 (artificial) labels which may be generated within this file (when the -g
3795 options is used and DWARF_DEBUGGING_INFO is in effect.
3796 If necessary, these may be overridden from within the tm.h file, but
3797 typically, overriding these defaults is unnecessary. */
3799 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3800 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3801 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3802 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3803 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3805 #ifndef TEXT_END_LABEL
3806 #define TEXT_END_LABEL "Letext"
3808 #ifndef DATA_END_LABEL
3809 #define DATA_END_LABEL "Ledata"
3811 #ifndef BSS_END_LABEL
3812 #define BSS_END_LABEL "Lebss"
3814 #ifndef BLOCK_BEGIN_LABEL
3815 #define BLOCK_BEGIN_LABEL "LBB"
3817 #ifndef BLOCK_END_LABEL
3818 #define BLOCK_END_LABEL "LBE"
3820 #ifndef BODY_BEGIN_LABEL
3821 #define BODY_BEGIN_LABEL "Lbb"
3823 #ifndef BODY_END_LABEL
3824 #define BODY_END_LABEL "Lbe"
3826 #ifndef LINE_CODE_LABEL
3827 #define LINE_CODE_LABEL "LM"
3829 #ifndef SEPARATE_LINE_CODE_LABEL
3830 #define SEPARATE_LINE_CODE_LABEL "LSM"
3833 /* We allow a language front-end to designate a function that is to be
3834 called to "demangle" any name before it it put into a DIE. */
3836 static const char *(*demangle_name_func) PARAMS ((const char *));
3839 dwarf2out_set_demangle_name_func (func)
3840 const char *(*func) PARAMS ((const char *));
3842 demangle_name_func = func;
3845 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3846 that means adding it to used_rtx_varray. If not, that means making
3847 a copy on the permanent_obstack. */
3853 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3858 /* Test if rtl node points to a pseudo register. */
3864 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3865 || (GET_CODE (rtl) == SUBREG
3866 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3869 /* Return a reference to a type, with its const and volatile qualifiers
3873 type_main_variant (type)
3876 type = TYPE_MAIN_VARIANT (type);
3878 /* There really should be only one main variant among any group of variants
3879 of a given type (and all of the MAIN_VARIANT values for all members of
3880 the group should point to that one type) but sometimes the C front-end
3881 messes this up for array types, so we work around that bug here. */
3883 if (TREE_CODE (type) == ARRAY_TYPE)
3884 while (type != TYPE_MAIN_VARIANT (type))
3885 type = TYPE_MAIN_VARIANT (type);
3890 /* Return non-zero if the given type node represents a tagged type. */
3893 is_tagged_type (type)
3896 register enum tree_code code = TREE_CODE (type);
3898 return (code == RECORD_TYPE || code == UNION_TYPE
3899 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3902 /* Convert a DIE tag into its string name. */
3905 dwarf_tag_name (tag)
3906 register unsigned tag;
3910 case DW_TAG_padding:
3911 return "DW_TAG_padding";
3912 case DW_TAG_array_type:
3913 return "DW_TAG_array_type";
3914 case DW_TAG_class_type:
3915 return "DW_TAG_class_type";
3916 case DW_TAG_entry_point:
3917 return "DW_TAG_entry_point";
3918 case DW_TAG_enumeration_type:
3919 return "DW_TAG_enumeration_type";
3920 case DW_TAG_formal_parameter:
3921 return "DW_TAG_formal_parameter";
3922 case DW_TAG_imported_declaration:
3923 return "DW_TAG_imported_declaration";
3925 return "DW_TAG_label";
3926 case DW_TAG_lexical_block:
3927 return "DW_TAG_lexical_block";
3929 return "DW_TAG_member";
3930 case DW_TAG_pointer_type:
3931 return "DW_TAG_pointer_type";
3932 case DW_TAG_reference_type:
3933 return "DW_TAG_reference_type";
3934 case DW_TAG_compile_unit:
3935 return "DW_TAG_compile_unit";
3936 case DW_TAG_string_type:
3937 return "DW_TAG_string_type";
3938 case DW_TAG_structure_type:
3939 return "DW_TAG_structure_type";
3940 case DW_TAG_subroutine_type:
3941 return "DW_TAG_subroutine_type";
3942 case DW_TAG_typedef:
3943 return "DW_TAG_typedef";
3944 case DW_TAG_union_type:
3945 return "DW_TAG_union_type";
3946 case DW_TAG_unspecified_parameters:
3947 return "DW_TAG_unspecified_parameters";
3948 case DW_TAG_variant:
3949 return "DW_TAG_variant";
3950 case DW_TAG_common_block:
3951 return "DW_TAG_common_block";
3952 case DW_TAG_common_inclusion:
3953 return "DW_TAG_common_inclusion";
3954 case DW_TAG_inheritance:
3955 return "DW_TAG_inheritance";
3956 case DW_TAG_inlined_subroutine:
3957 return "DW_TAG_inlined_subroutine";
3959 return "DW_TAG_module";
3960 case DW_TAG_ptr_to_member_type:
3961 return "DW_TAG_ptr_to_member_type";
3962 case DW_TAG_set_type:
3963 return "DW_TAG_set_type";
3964 case DW_TAG_subrange_type:
3965 return "DW_TAG_subrange_type";
3966 case DW_TAG_with_stmt:
3967 return "DW_TAG_with_stmt";
3968 case DW_TAG_access_declaration:
3969 return "DW_TAG_access_declaration";
3970 case DW_TAG_base_type:
3971 return "DW_TAG_base_type";
3972 case DW_TAG_catch_block:
3973 return "DW_TAG_catch_block";
3974 case DW_TAG_const_type:
3975 return "DW_TAG_const_type";
3976 case DW_TAG_constant:
3977 return "DW_TAG_constant";
3978 case DW_TAG_enumerator:
3979 return "DW_TAG_enumerator";
3980 case DW_TAG_file_type:
3981 return "DW_TAG_file_type";
3983 return "DW_TAG_friend";
3984 case DW_TAG_namelist:
3985 return "DW_TAG_namelist";
3986 case DW_TAG_namelist_item:
3987 return "DW_TAG_namelist_item";
3988 case DW_TAG_packed_type:
3989 return "DW_TAG_packed_type";
3990 case DW_TAG_subprogram:
3991 return "DW_TAG_subprogram";
3992 case DW_TAG_template_type_param:
3993 return "DW_TAG_template_type_param";
3994 case DW_TAG_template_value_param:
3995 return "DW_TAG_template_value_param";
3996 case DW_TAG_thrown_type:
3997 return "DW_TAG_thrown_type";
3998 case DW_TAG_try_block:
3999 return "DW_TAG_try_block";
4000 case DW_TAG_variant_part:
4001 return "DW_TAG_variant_part";
4002 case DW_TAG_variable:
4003 return "DW_TAG_variable";
4004 case DW_TAG_volatile_type:
4005 return "DW_TAG_volatile_type";
4006 case DW_TAG_MIPS_loop:
4007 return "DW_TAG_MIPS_loop";
4008 case DW_TAG_format_label:
4009 return "DW_TAG_format_label";
4010 case DW_TAG_function_template:
4011 return "DW_TAG_function_template";
4012 case DW_TAG_class_template:
4013 return "DW_TAG_class_template";
4014 case DW_TAG_GNU_BINCL:
4015 return "DW_TAG_GNU_BINCL";
4016 case DW_TAG_GNU_EINCL:
4017 return "DW_TAG_GNU_EINCL";
4019 return "DW_TAG_<unknown>";
4023 /* Convert a DWARF attribute code into its string name. */
4026 dwarf_attr_name (attr)
4027 register unsigned attr;
4032 return "DW_AT_sibling";
4033 case DW_AT_location:
4034 return "DW_AT_location";
4036 return "DW_AT_name";
4037 case DW_AT_ordering:
4038 return "DW_AT_ordering";
4039 case DW_AT_subscr_data:
4040 return "DW_AT_subscr_data";
4041 case DW_AT_byte_size:
4042 return "DW_AT_byte_size";
4043 case DW_AT_bit_offset:
4044 return "DW_AT_bit_offset";
4045 case DW_AT_bit_size:
4046 return "DW_AT_bit_size";
4047 case DW_AT_element_list:
4048 return "DW_AT_element_list";
4049 case DW_AT_stmt_list:
4050 return "DW_AT_stmt_list";
4052 return "DW_AT_low_pc";
4054 return "DW_AT_high_pc";
4055 case DW_AT_language:
4056 return "DW_AT_language";
4058 return "DW_AT_member";
4060 return "DW_AT_discr";
4061 case DW_AT_discr_value:
4062 return "DW_AT_discr_value";
4063 case DW_AT_visibility:
4064 return "DW_AT_visibility";
4066 return "DW_AT_import";
4067 case DW_AT_string_length:
4068 return "DW_AT_string_length";
4069 case DW_AT_common_reference:
4070 return "DW_AT_common_reference";
4071 case DW_AT_comp_dir:
4072 return "DW_AT_comp_dir";
4073 case DW_AT_const_value:
4074 return "DW_AT_const_value";
4075 case DW_AT_containing_type:
4076 return "DW_AT_containing_type";
4077 case DW_AT_default_value:
4078 return "DW_AT_default_value";
4080 return "DW_AT_inline";
4081 case DW_AT_is_optional:
4082 return "DW_AT_is_optional";
4083 case DW_AT_lower_bound:
4084 return "DW_AT_lower_bound";
4085 case DW_AT_producer:
4086 return "DW_AT_producer";
4087 case DW_AT_prototyped:
4088 return "DW_AT_prototyped";
4089 case DW_AT_return_addr:
4090 return "DW_AT_return_addr";
4091 case DW_AT_start_scope:
4092 return "DW_AT_start_scope";
4093 case DW_AT_stride_size:
4094 return "DW_AT_stride_size";
4095 case DW_AT_upper_bound:
4096 return "DW_AT_upper_bound";
4097 case DW_AT_abstract_origin:
4098 return "DW_AT_abstract_origin";
4099 case DW_AT_accessibility:
4100 return "DW_AT_accessibility";
4101 case DW_AT_address_class:
4102 return "DW_AT_address_class";
4103 case DW_AT_artificial:
4104 return "DW_AT_artificial";
4105 case DW_AT_base_types:
4106 return "DW_AT_base_types";
4107 case DW_AT_calling_convention:
4108 return "DW_AT_calling_convention";
4110 return "DW_AT_count";
4111 case DW_AT_data_member_location:
4112 return "DW_AT_data_member_location";
4113 case DW_AT_decl_column:
4114 return "DW_AT_decl_column";
4115 case DW_AT_decl_file:
4116 return "DW_AT_decl_file";
4117 case DW_AT_decl_line:
4118 return "DW_AT_decl_line";
4119 case DW_AT_declaration:
4120 return "DW_AT_declaration";
4121 case DW_AT_discr_list:
4122 return "DW_AT_discr_list";
4123 case DW_AT_encoding:
4124 return "DW_AT_encoding";
4125 case DW_AT_external:
4126 return "DW_AT_external";
4127 case DW_AT_frame_base:
4128 return "DW_AT_frame_base";
4130 return "DW_AT_friend";
4131 case DW_AT_identifier_case:
4132 return "DW_AT_identifier_case";
4133 case DW_AT_macro_info:
4134 return "DW_AT_macro_info";
4135 case DW_AT_namelist_items:
4136 return "DW_AT_namelist_items";
4137 case DW_AT_priority:
4138 return "DW_AT_priority";
4140 return "DW_AT_segment";
4141 case DW_AT_specification:
4142 return "DW_AT_specification";
4143 case DW_AT_static_link:
4144 return "DW_AT_static_link";
4146 return "DW_AT_type";
4147 case DW_AT_use_location:
4148 return "DW_AT_use_location";
4149 case DW_AT_variable_parameter:
4150 return "DW_AT_variable_parameter";
4151 case DW_AT_virtuality:
4152 return "DW_AT_virtuality";
4153 case DW_AT_vtable_elem_location:
4154 return "DW_AT_vtable_elem_location";
4156 case DW_AT_MIPS_fde:
4157 return "DW_AT_MIPS_fde";
4158 case DW_AT_MIPS_loop_begin:
4159 return "DW_AT_MIPS_loop_begin";
4160 case DW_AT_MIPS_tail_loop_begin:
4161 return "DW_AT_MIPS_tail_loop_begin";
4162 case DW_AT_MIPS_epilog_begin:
4163 return "DW_AT_MIPS_epilog_begin";
4164 case DW_AT_MIPS_loop_unroll_factor:
4165 return "DW_AT_MIPS_loop_unroll_factor";
4166 case DW_AT_MIPS_software_pipeline_depth:
4167 return "DW_AT_MIPS_software_pipeline_depth";
4168 case DW_AT_MIPS_linkage_name:
4169 return "DW_AT_MIPS_linkage_name";
4170 case DW_AT_MIPS_stride:
4171 return "DW_AT_MIPS_stride";
4172 case DW_AT_MIPS_abstract_name:
4173 return "DW_AT_MIPS_abstract_name";
4174 case DW_AT_MIPS_clone_origin:
4175 return "DW_AT_MIPS_clone_origin";
4176 case DW_AT_MIPS_has_inlines:
4177 return "DW_AT_MIPS_has_inlines";
4179 case DW_AT_sf_names:
4180 return "DW_AT_sf_names";
4181 case DW_AT_src_info:
4182 return "DW_AT_src_info";
4183 case DW_AT_mac_info:
4184 return "DW_AT_mac_info";
4185 case DW_AT_src_coords:
4186 return "DW_AT_src_coords";
4187 case DW_AT_body_begin:
4188 return "DW_AT_body_begin";
4189 case DW_AT_body_end:
4190 return "DW_AT_body_end";
4192 return "DW_AT_<unknown>";
4196 /* Convert a DWARF value form code into its string name. */
4199 dwarf_form_name (form)
4200 register unsigned form;
4205 return "DW_FORM_addr";
4206 case DW_FORM_block2:
4207 return "DW_FORM_block2";
4208 case DW_FORM_block4:
4209 return "DW_FORM_block4";
4211 return "DW_FORM_data2";
4213 return "DW_FORM_data4";
4215 return "DW_FORM_data8";
4216 case DW_FORM_string:
4217 return "DW_FORM_string";
4219 return "DW_FORM_block";
4220 case DW_FORM_block1:
4221 return "DW_FORM_block1";
4223 return "DW_FORM_data1";
4225 return "DW_FORM_flag";
4227 return "DW_FORM_sdata";
4229 return "DW_FORM_strp";
4231 return "DW_FORM_udata";
4232 case DW_FORM_ref_addr:
4233 return "DW_FORM_ref_addr";
4235 return "DW_FORM_ref1";
4237 return "DW_FORM_ref2";
4239 return "DW_FORM_ref4";
4241 return "DW_FORM_ref8";
4242 case DW_FORM_ref_udata:
4243 return "DW_FORM_ref_udata";
4244 case DW_FORM_indirect:
4245 return "DW_FORM_indirect";
4247 return "DW_FORM_<unknown>";
4251 /* Convert a DWARF type code into its string name. */
4255 dwarf_type_encoding_name (enc)
4256 register unsigned enc;
4260 case DW_ATE_address:
4261 return "DW_ATE_address";
4262 case DW_ATE_boolean:
4263 return "DW_ATE_boolean";
4264 case DW_ATE_complex_float:
4265 return "DW_ATE_complex_float";
4267 return "DW_ATE_float";
4269 return "DW_ATE_signed";
4270 case DW_ATE_signed_char:
4271 return "DW_ATE_signed_char";
4272 case DW_ATE_unsigned:
4273 return "DW_ATE_unsigned";
4274 case DW_ATE_unsigned_char:
4275 return "DW_ATE_unsigned_char";
4277 return "DW_ATE_<unknown>";
4282 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4283 instance of an inlined instance of a decl which is local to an inline
4284 function, so we have to trace all of the way back through the origin chain
4285 to find out what sort of node actually served as the original seed for the
4289 decl_ultimate_origin (decl)
4292 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4293 nodes in the function to point to themselves; ignore that if
4294 we're trying to output the abstract instance of this function. */
4295 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4298 #ifdef ENABLE_CHECKING
4299 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4300 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4301 most distant ancestor, this should never happen. */
4305 return DECL_ABSTRACT_ORIGIN (decl);
4308 /* Determine the "ultimate origin" of a block. The block may be an inlined
4309 instance of an inlined instance of a block which is local to an inline
4310 function, so we have to trace all of the way back through the origin chain
4311 to find out what sort of node actually served as the original seed for the
4315 block_ultimate_origin (block)
4316 register tree block;
4318 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4320 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4321 nodes in the function to point to themselves; ignore that if
4322 we're trying to output the abstract instance of this function. */
4323 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4326 if (immediate_origin == NULL_TREE)
4330 register tree ret_val;
4331 register tree lookahead = immediate_origin;
4335 ret_val = lookahead;
4336 lookahead = (TREE_CODE (ret_val) == BLOCK)
4337 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4340 while (lookahead != NULL && lookahead != ret_val);
4346 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4347 of a virtual function may refer to a base class, so we check the 'this'
4351 decl_class_context (decl)
4354 tree context = NULL_TREE;
4356 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4357 context = DECL_CONTEXT (decl);
4359 context = TYPE_MAIN_VARIANT
4360 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4362 if (context && !TYPE_P (context))
4363 context = NULL_TREE;
4368 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4369 addition order, and correct that in reverse_all_dies. */
4372 add_dwarf_attr (die, attr)
4373 register dw_die_ref die;
4374 register dw_attr_ref attr;
4376 if (die != NULL && attr != NULL)
4378 attr->dw_attr_next = die->die_attr;
4379 die->die_attr = attr;
4383 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4384 static inline dw_val_class
4388 return a->dw_attr_val.val_class;
4391 /* Add a flag value attribute to a DIE. */
4394 add_AT_flag (die, attr_kind, flag)
4395 register dw_die_ref die;
4396 register enum dwarf_attribute attr_kind;
4397 register unsigned flag;
4399 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4401 attr->dw_attr_next = NULL;
4402 attr->dw_attr = attr_kind;
4403 attr->dw_attr_val.val_class = dw_val_class_flag;
4404 attr->dw_attr_val.v.val_flag = flag;
4405 add_dwarf_attr (die, attr);
4408 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4409 static inline unsigned
4411 register dw_attr_ref a;
4413 if (a && AT_class (a) == dw_val_class_flag)
4414 return a->dw_attr_val.v.val_flag;
4419 /* Add a signed integer attribute value to a DIE. */
4422 add_AT_int (die, attr_kind, int_val)
4423 register dw_die_ref die;
4424 register enum dwarf_attribute attr_kind;
4425 register long int int_val;
4427 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4429 attr->dw_attr_next = NULL;
4430 attr->dw_attr = attr_kind;
4431 attr->dw_attr_val.val_class = dw_val_class_const;
4432 attr->dw_attr_val.v.val_int = int_val;
4433 add_dwarf_attr (die, attr);
4436 static inline long int AT_int PARAMS ((dw_attr_ref));
4437 static inline long int
4439 register dw_attr_ref a;
4441 if (a && AT_class (a) == dw_val_class_const)
4442 return a->dw_attr_val.v.val_int;
4447 /* Add an unsigned integer attribute value to a DIE. */
4450 add_AT_unsigned (die, attr_kind, unsigned_val)
4451 register dw_die_ref die;
4452 register enum dwarf_attribute attr_kind;
4453 register unsigned long unsigned_val;
4455 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4457 attr->dw_attr_next = NULL;
4458 attr->dw_attr = attr_kind;
4459 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4460 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4461 add_dwarf_attr (die, attr);
4464 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4465 static inline unsigned long
4467 register dw_attr_ref a;
4469 if (a && AT_class (a) == dw_val_class_unsigned_const)
4470 return a->dw_attr_val.v.val_unsigned;
4475 /* Add an unsigned double integer attribute value to a DIE. */
4478 add_AT_long_long (die, attr_kind, val_hi, val_low)
4479 register dw_die_ref die;
4480 register enum dwarf_attribute attr_kind;
4481 register unsigned long val_hi;
4482 register unsigned long val_low;
4484 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4486 attr->dw_attr_next = NULL;
4487 attr->dw_attr = attr_kind;
4488 attr->dw_attr_val.val_class = dw_val_class_long_long;
4489 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4490 attr->dw_attr_val.v.val_long_long.low = val_low;
4491 add_dwarf_attr (die, attr);
4494 /* Add a floating point attribute value to a DIE and return it. */
4497 add_AT_float (die, attr_kind, length, array)
4498 register dw_die_ref die;
4499 register enum dwarf_attribute attr_kind;
4500 register unsigned length;
4501 register long *array;
4503 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4505 attr->dw_attr_next = NULL;
4506 attr->dw_attr = attr_kind;
4507 attr->dw_attr_val.val_class = dw_val_class_float;
4508 attr->dw_attr_val.v.val_float.length = length;
4509 attr->dw_attr_val.v.val_float.array = array;
4510 add_dwarf_attr (die, attr);
4513 /* Add a string attribute value to a DIE. */
4516 add_AT_string (die, attr_kind, str)
4517 register dw_die_ref die;
4518 register enum dwarf_attribute attr_kind;
4519 register const char *str;
4521 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4523 attr->dw_attr_next = NULL;
4524 attr->dw_attr = attr_kind;
4525 attr->dw_attr_val.val_class = dw_val_class_str;
4526 attr->dw_attr_val.v.val_str = xstrdup (str);
4527 add_dwarf_attr (die, attr);
4530 static inline const char *AT_string PARAMS ((dw_attr_ref));
4531 static inline const char *
4533 register dw_attr_ref a;
4535 if (a && AT_class (a) == dw_val_class_str)
4536 return a->dw_attr_val.v.val_str;
4541 /* Add a DIE reference attribute value to a DIE. */
4544 add_AT_die_ref (die, attr_kind, targ_die)
4545 register dw_die_ref die;
4546 register enum dwarf_attribute attr_kind;
4547 register dw_die_ref targ_die;
4549 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4551 attr->dw_attr_next = NULL;
4552 attr->dw_attr = attr_kind;
4553 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4554 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4555 attr->dw_attr_val.v.val_die_ref.external = 0;
4556 add_dwarf_attr (die, attr);
4559 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4560 static inline dw_die_ref
4562 register dw_attr_ref a;
4564 if (a && AT_class (a) == dw_val_class_die_ref)
4565 return a->dw_attr_val.v.val_die_ref.die;
4570 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4573 register dw_attr_ref a;
4575 if (a && AT_class (a) == dw_val_class_die_ref)
4576 return a->dw_attr_val.v.val_die_ref.external;
4581 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4583 set_AT_ref_external (a, i)
4584 register dw_attr_ref a;
4587 if (a && AT_class (a) == dw_val_class_die_ref)
4588 a->dw_attr_val.v.val_die_ref.external = i;
4593 /* Add an FDE reference attribute value to a DIE. */
4596 add_AT_fde_ref (die, attr_kind, targ_fde)
4597 register dw_die_ref die;
4598 register enum dwarf_attribute attr_kind;
4599 register unsigned targ_fde;
4601 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4603 attr->dw_attr_next = NULL;
4604 attr->dw_attr = attr_kind;
4605 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4606 attr->dw_attr_val.v.val_fde_index = targ_fde;
4607 add_dwarf_attr (die, attr);
4610 /* Add a location description attribute value to a DIE. */
4613 add_AT_loc (die, attr_kind, loc)
4614 register dw_die_ref die;
4615 register enum dwarf_attribute attr_kind;
4616 register dw_loc_descr_ref loc;
4618 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4620 attr->dw_attr_next = NULL;
4621 attr->dw_attr = attr_kind;
4622 attr->dw_attr_val.val_class = dw_val_class_loc;
4623 attr->dw_attr_val.v.val_loc = loc;
4624 add_dwarf_attr (die, attr);
4627 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4628 static inline dw_loc_descr_ref
4630 register dw_attr_ref a;
4632 if (a && AT_class (a) == dw_val_class_loc)
4633 return a->dw_attr_val.v.val_loc;
4638 /* Add an address constant attribute value to a DIE. */
4641 add_AT_addr (die, attr_kind, addr)
4642 register dw_die_ref die;
4643 register enum dwarf_attribute attr_kind;
4646 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4648 attr->dw_attr_next = NULL;
4649 attr->dw_attr = attr_kind;
4650 attr->dw_attr_val.val_class = dw_val_class_addr;
4651 attr->dw_attr_val.v.val_addr = addr;
4652 add_dwarf_attr (die, attr);
4655 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4658 register dw_attr_ref a;
4660 if (a && AT_class (a) == dw_val_class_addr)
4661 return a->dw_attr_val.v.val_addr;
4666 /* Add a label identifier attribute value to a DIE. */
4669 add_AT_lbl_id (die, attr_kind, lbl_id)
4670 register dw_die_ref die;
4671 register enum dwarf_attribute attr_kind;
4672 register const char *lbl_id;
4674 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4676 attr->dw_attr_next = NULL;
4677 attr->dw_attr = attr_kind;
4678 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4679 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4680 add_dwarf_attr (die, attr);
4683 /* Add a section offset attribute value to a DIE. */
4686 add_AT_lbl_offset (die, attr_kind, label)
4687 register dw_die_ref die;
4688 register enum dwarf_attribute attr_kind;
4689 register const char *label;
4691 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4693 attr->dw_attr_next = NULL;
4694 attr->dw_attr = attr_kind;
4695 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4696 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4697 add_dwarf_attr (die, attr);
4700 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4701 static inline const char *
4703 register dw_attr_ref a;
4705 if (a && (AT_class (a) == dw_val_class_lbl_id
4706 || AT_class (a) == dw_val_class_lbl_offset))
4707 return a->dw_attr_val.v.val_lbl_id;
4712 /* Get the attribute of type attr_kind. */
4714 static inline dw_attr_ref
4715 get_AT (die, attr_kind)
4716 register dw_die_ref die;
4717 register enum dwarf_attribute attr_kind;
4719 register dw_attr_ref a;
4720 register dw_die_ref spec = NULL;
4724 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4726 if (a->dw_attr == attr_kind)
4729 if (a->dw_attr == DW_AT_specification
4730 || a->dw_attr == DW_AT_abstract_origin)
4735 return get_AT (spec, attr_kind);
4741 /* Return the "low pc" attribute value, typically associated with
4742 a subprogram DIE. Return null if the "low pc" attribute is
4743 either not prsent, or if it cannot be represented as an
4744 assembler label identifier. */
4746 static inline const char *
4748 register dw_die_ref die;
4750 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4751 return a ? AT_lbl (a) : NULL;
4754 /* Return the "high pc" attribute value, typically associated with
4755 a subprogram DIE. Return null if the "high pc" attribute is
4756 either not prsent, or if it cannot be represented as an
4757 assembler label identifier. */
4759 static inline const char *
4761 register dw_die_ref die;
4763 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4764 return a ? AT_lbl (a) : NULL;
4767 /* Return the value of the string attribute designated by ATTR_KIND, or
4768 NULL if it is not present. */
4770 static inline const char *
4771 get_AT_string (die, attr_kind)
4772 register dw_die_ref die;
4773 register enum dwarf_attribute attr_kind;
4775 register dw_attr_ref a = get_AT (die, attr_kind);
4776 return a ? AT_string (a) : NULL;
4779 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4780 if it is not present. */
4783 get_AT_flag (die, attr_kind)
4784 register dw_die_ref die;
4785 register enum dwarf_attribute attr_kind;
4787 register dw_attr_ref a = get_AT (die, attr_kind);
4788 return a ? AT_flag (a) : 0;
4791 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4792 if it is not present. */
4794 static inline unsigned
4795 get_AT_unsigned (die, attr_kind)
4796 register dw_die_ref die;
4797 register enum dwarf_attribute attr_kind;
4799 register dw_attr_ref a = get_AT (die, attr_kind);
4800 return a ? AT_unsigned (a) : 0;
4803 static inline dw_die_ref
4804 get_AT_ref (die, attr_kind)
4806 register enum dwarf_attribute attr_kind;
4808 register dw_attr_ref a = get_AT (die, attr_kind);
4809 return a ? AT_ref (a) : NULL;
4815 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4817 return (lang == DW_LANG_C || lang == DW_LANG_C89
4818 || lang == DW_LANG_C_plus_plus);
4824 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4826 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4832 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4834 return (lang == DW_LANG_Java);
4837 /* Free up the memory used by A. */
4839 static inline void free_AT PARAMS ((dw_attr_ref));
4844 switch (AT_class (a))
4846 case dw_val_class_str:
4847 case dw_val_class_lbl_id:
4848 case dw_val_class_lbl_offset:
4849 free (a->dw_attr_val.v.val_str);
4852 case dw_val_class_float:
4853 free (a->dw_attr_val.v.val_float.array);
4863 /* Remove the specified attribute if present. */
4866 remove_AT (die, attr_kind)
4867 register dw_die_ref die;
4868 register enum dwarf_attribute attr_kind;
4870 register dw_attr_ref *p;
4871 register dw_attr_ref removed = NULL;
4875 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4876 if ((*p)->dw_attr == attr_kind)
4879 *p = (*p)->dw_attr_next;
4888 /* Free up the memory used by DIE. */
4890 static inline void free_die PARAMS ((dw_die_ref));
4895 remove_children (die);
4899 /* Discard the children of this DIE. */
4902 remove_children (die)
4903 register dw_die_ref die;
4905 register dw_die_ref child_die = die->die_child;
4907 die->die_child = NULL;
4909 while (child_die != NULL)
4911 register dw_die_ref tmp_die = child_die;
4912 register dw_attr_ref a;
4914 child_die = child_die->die_sib;
4916 for (a = tmp_die->die_attr; a != NULL;)
4918 register dw_attr_ref tmp_a = a;
4920 a = a->dw_attr_next;
4928 /* Add a child DIE below its parent. We build the lists up in reverse
4929 addition order, and correct that in reverse_all_dies. */
4932 add_child_die (die, child_die)
4933 register dw_die_ref die;
4934 register dw_die_ref child_die;
4936 if (die != NULL && child_die != NULL)
4938 if (die == child_die)
4940 child_die->die_parent = die;
4941 child_die->die_sib = die->die_child;
4942 die->die_child = child_die;
4946 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4947 is the specification, to the front of PARENT's list of children. */
4950 splice_child_die (parent, child)
4951 dw_die_ref parent, child;
4955 /* We want the declaration DIE from inside the class, not the
4956 specification DIE at toplevel. */
4957 if (child->die_parent != parent)
4959 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4964 if (child->die_parent != parent
4965 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4968 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4971 *p = child->die_sib;
4975 child->die_sib = parent->die_child;
4976 parent->die_child = child;
4979 /* Return a pointer to a newly created DIE node. */
4981 static inline dw_die_ref
4982 new_die (tag_value, parent_die)
4983 register enum dwarf_tag tag_value;
4984 register dw_die_ref parent_die;
4986 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4988 die->die_tag = tag_value;
4990 if (parent_die != NULL)
4991 add_child_die (parent_die, die);
4994 limbo_die_node *limbo_node;
4996 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4997 limbo_node->die = die;
4998 limbo_node->next = limbo_die_list;
4999 limbo_die_list = limbo_node;
5005 /* Return the DIE associated with the given type specifier. */
5007 static inline dw_die_ref
5008 lookup_type_die (type)
5011 if (TREE_CODE (type) == VECTOR_TYPE)
5012 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
5013 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
5016 /* Equate a DIE to a given type specifier. */
5019 equate_type_number_to_die (type, type_die)
5021 register dw_die_ref type_die;
5023 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
5026 /* Return the DIE associated with a given declaration. */
5028 static inline dw_die_ref
5029 lookup_decl_die (decl)
5032 register unsigned decl_id = DECL_UID (decl);
5034 return (decl_id < decl_die_table_in_use
5035 ? decl_die_table[decl_id] : NULL);
5038 /* Equate a DIE to a particular declaration. */
5041 equate_decl_number_to_die (decl, decl_die)
5043 register dw_die_ref decl_die;
5045 register unsigned decl_id = DECL_UID (decl);
5046 register unsigned num_allocated;
5048 if (decl_id >= decl_die_table_allocated)
5051 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5052 / DECL_DIE_TABLE_INCREMENT)
5053 * DECL_DIE_TABLE_INCREMENT;
5056 = (dw_die_ref *) xrealloc (decl_die_table,
5057 sizeof (dw_die_ref) * num_allocated);
5059 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5060 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5061 decl_die_table_allocated = num_allocated;
5064 if (decl_id >= decl_die_table_in_use)
5065 decl_die_table_in_use = (decl_id + 1);
5067 decl_die_table[decl_id] = decl_die;
5070 /* Keep track of the number of spaces used to indent the
5071 output of the debugging routines that print the structure of
5072 the DIE internal representation. */
5073 static int print_indent;
5075 /* Indent the line the number of spaces given by print_indent. */
5078 print_spaces (outfile)
5081 fprintf (outfile, "%*s", print_indent, "");
5084 /* Print the information associated with a given DIE, and its children.
5085 This routine is a debugging aid only. */
5088 print_die (die, outfile)
5092 register dw_attr_ref a;
5093 register dw_die_ref c;
5095 print_spaces (outfile);
5096 fprintf (outfile, "DIE %4lu: %s\n",
5097 die->die_offset, dwarf_tag_name (die->die_tag));
5098 print_spaces (outfile);
5099 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5100 fprintf (outfile, " offset: %lu\n", die->die_offset);
5102 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5104 print_spaces (outfile);
5105 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5107 switch (AT_class (a))
5109 case dw_val_class_addr:
5110 fprintf (outfile, "address");
5112 case dw_val_class_loc:
5113 fprintf (outfile, "location descriptor");
5115 case dw_val_class_const:
5116 fprintf (outfile, "%ld", AT_int (a));
5118 case dw_val_class_unsigned_const:
5119 fprintf (outfile, "%lu", AT_unsigned (a));
5121 case dw_val_class_long_long:
5122 fprintf (outfile, "constant (%lu,%lu)",
5123 a->dw_attr_val.v.val_long_long.hi,
5124 a->dw_attr_val.v.val_long_long.low);
5126 case dw_val_class_float:
5127 fprintf (outfile, "floating-point constant");
5129 case dw_val_class_flag:
5130 fprintf (outfile, "%u", AT_flag (a));
5132 case dw_val_class_die_ref:
5133 if (AT_ref (a) != NULL)
5135 if (AT_ref (a)->die_symbol)
5136 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5138 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5141 fprintf (outfile, "die -> <null>");
5143 case dw_val_class_lbl_id:
5144 case dw_val_class_lbl_offset:
5145 fprintf (outfile, "label: %s", AT_lbl (a));
5147 case dw_val_class_str:
5148 if (AT_string (a) != NULL)
5149 fprintf (outfile, "\"%s\"", AT_string (a));
5151 fprintf (outfile, "<null>");
5157 fprintf (outfile, "\n");
5160 if (die->die_child != NULL)
5163 for (c = die->die_child; c != NULL; c = c->die_sib)
5164 print_die (c, outfile);
5168 if (print_indent == 0)
5169 fprintf (outfile, "\n");
5172 /* Print the contents of the source code line number correspondence table.
5173 This routine is a debugging aid only. */
5176 print_dwarf_line_table (outfile)
5179 register unsigned i;
5180 register dw_line_info_ref line_info;
5182 fprintf (outfile, "\n\nDWARF source line information\n");
5183 for (i = 1; i < line_info_table_in_use; ++i)
5185 line_info = &line_info_table[i];
5186 fprintf (outfile, "%5d: ", i);
5187 fprintf (outfile, "%-20s", line_file_table.table[line_info->dw_file_num]);
5188 fprintf (outfile, "%6ld", line_info->dw_line_num);
5189 fprintf (outfile, "\n");
5192 fprintf (outfile, "\n\n");
5195 /* Print the information collected for a given DIE. */
5198 debug_dwarf_die (die)
5201 print_die (die, stderr);
5204 /* Print all DWARF information collected for the compilation unit.
5205 This routine is a debugging aid only. */
5211 print_die (comp_unit_die, stderr);
5212 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5213 print_dwarf_line_table (stderr);
5216 /* We build up the lists of children and attributes by pushing new ones
5217 onto the beginning of the list. Reverse the lists for DIE so that
5218 they are in order of addition. */
5221 reverse_die_lists (die)
5222 register dw_die_ref die;
5224 register dw_die_ref c, cp, cn;
5225 register dw_attr_ref a, ap, an;
5227 for (a = die->die_attr, ap = 0; a; a = an)
5229 an = a->dw_attr_next;
5230 a->dw_attr_next = ap;
5235 for (c = die->die_child, cp = 0; c; c = cn)
5241 die->die_child = cp;
5244 /* reverse_die_lists only reverses the single die you pass it. Since
5245 we used to reverse all dies in add_sibling_attributes, which runs
5246 through all the dies, it would reverse all the dies. Now, however,
5247 since we don't call reverse_die_lists in add_sibling_attributes, we
5248 need a routine to recursively reverse all the dies. This is that
5252 reverse_all_dies (die)
5253 register dw_die_ref die;
5255 register dw_die_ref c;
5257 reverse_die_lists (die);
5259 for (c = die->die_child; c; c = c->die_sib)
5260 reverse_all_dies (c);
5263 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5264 the CU for the enclosing include file, if any. BINCL_DIE is the
5265 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5269 push_new_compile_unit (old_unit, bincl_die)
5270 dw_die_ref old_unit, bincl_die;
5272 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5273 dw_die_ref new_unit = gen_compile_unit_die (filename);
5274 new_unit->die_sib = old_unit;
5278 /* Close an include-file CU and reopen the enclosing one. */
5281 pop_compile_unit (old_unit)
5282 dw_die_ref old_unit;
5284 dw_die_ref new_unit = old_unit->die_sib;
5285 old_unit->die_sib = NULL;
5289 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5290 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5292 /* Calculate the checksum of a location expression. */
5295 loc_checksum (loc, ctx)
5296 dw_loc_descr_ref loc;
5297 struct md5_ctx *ctx;
5299 PROCESS (loc->dw_loc_opc);
5300 PROCESS (loc->dw_loc_oprnd1);
5301 PROCESS (loc->dw_loc_oprnd2);
5304 /* Calculate the checksum of an attribute. */
5307 attr_checksum (at, ctx)
5309 struct md5_ctx *ctx;
5311 dw_loc_descr_ref loc;
5314 PROCESS (at->dw_attr);
5316 /* We don't care about differences in file numbering. */
5317 if (at->dw_attr == DW_AT_decl_file
5318 /* Or that this was compiled with a different compiler snapshot; if
5319 the output is the same, that's what matters. */
5320 || at->dw_attr == DW_AT_producer)
5323 switch (AT_class (at))
5325 case dw_val_class_const:
5326 PROCESS (at->dw_attr_val.v.val_int);
5328 case dw_val_class_unsigned_const:
5329 PROCESS (at->dw_attr_val.v.val_unsigned);
5331 case dw_val_class_long_long:
5332 PROCESS (at->dw_attr_val.v.val_long_long);
5334 case dw_val_class_float:
5335 PROCESS (at->dw_attr_val.v.val_float);
5337 case dw_val_class_flag:
5338 PROCESS (at->dw_attr_val.v.val_flag);
5341 case dw_val_class_str:
5342 PROCESS_STRING (AT_string (at));
5344 case dw_val_class_addr:
5346 switch (GET_CODE (r))
5349 PROCESS_STRING (XSTR (r, 0));
5357 case dw_val_class_loc:
5358 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5359 loc_checksum (loc, ctx);
5362 case dw_val_class_die_ref:
5363 if (AT_ref (at)->die_offset)
5364 PROCESS (AT_ref (at)->die_offset);
5365 /* FIXME else use target die name or something. */
5367 case dw_val_class_fde_ref:
5368 case dw_val_class_lbl_id:
5369 case dw_val_class_lbl_offset:
5376 /* Calculate the checksum of a DIE. */
5379 die_checksum (die, ctx)
5381 struct md5_ctx *ctx;
5386 PROCESS (die->die_tag);
5388 for (a = die->die_attr; a; a = a->dw_attr_next)
5389 attr_checksum (a, ctx);
5391 for (c = die->die_child; c; c = c->die_sib)
5392 die_checksum (c, ctx);
5396 #undef PROCESS_STRING
5398 /* The prefix to attach to symbols on DIEs in the current comdat debug
5400 static char *comdat_symbol_id;
5402 /* The index of the current symbol within the current comdat CU. */
5403 static unsigned int comdat_symbol_number;
5405 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5406 children, and set comdat_symbol_id accordingly. */
5409 compute_section_prefix (unit_die)
5410 dw_die_ref unit_die;
5414 unsigned char checksum[16];
5417 md5_init_ctx (&ctx);
5418 die_checksum (unit_die, &ctx);
5419 md5_finish_ctx (&ctx, checksum);
5421 p = file_name_nondirectory (get_AT_string (unit_die, DW_AT_name));
5422 name = (char *) alloca (strlen (p) + 64);
5423 sprintf (name, "%s.", p);
5425 clean_symbol_name (name);
5427 p = name + strlen (name);
5428 for (i = 0; i < 4; ++i)
5430 sprintf (p, "%.2x", checksum[i]);
5434 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5435 comdat_symbol_number = 0;
5438 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5444 switch (die->die_tag)
5446 case DW_TAG_array_type:
5447 case DW_TAG_class_type:
5448 case DW_TAG_enumeration_type:
5449 case DW_TAG_pointer_type:
5450 case DW_TAG_reference_type:
5451 case DW_TAG_string_type:
5452 case DW_TAG_structure_type:
5453 case DW_TAG_subroutine_type:
5454 case DW_TAG_union_type:
5455 case DW_TAG_ptr_to_member_type:
5456 case DW_TAG_set_type:
5457 case DW_TAG_subrange_type:
5458 case DW_TAG_base_type:
5459 case DW_TAG_const_type:
5460 case DW_TAG_file_type:
5461 case DW_TAG_packed_type:
5462 case DW_TAG_volatile_type:
5469 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5470 Basically, we want to choose the bits that are likely to be shared between
5471 compilations (types) and leave out the bits that are specific to individual
5472 compilations (functions). */
5479 /* I think we want to leave base types and __vtbl_ptr_type in the
5480 main CU, as we do for stabs. The advantage is a greater
5481 likelihood of sharing between objects that don't include headers
5482 in the same order (and therefore would put the base types in a
5483 different comdat). jason 8/28/00 */
5484 if (c->die_tag == DW_TAG_base_type)
5487 if (c->die_tag == DW_TAG_pointer_type
5488 || c->die_tag == DW_TAG_reference_type
5489 || c->die_tag == DW_TAG_const_type
5490 || c->die_tag == DW_TAG_volatile_type)
5492 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5493 return t ? is_comdat_die (t) : 0;
5497 return is_type_die (c);
5500 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5501 compilation unit. */
5507 if (is_type_die (c))
5509 if (get_AT (c, DW_AT_declaration)
5510 && ! get_AT (c, DW_AT_specification))
5519 static int label_num;
5520 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5521 return xstrdup (buf);
5524 /* Assign symbols to all worthy DIEs under DIE. */
5527 assign_symbol_names (die)
5528 register dw_die_ref die;
5530 register dw_die_ref c;
5532 if (is_symbol_die (die))
5534 if (comdat_symbol_id)
5536 char *p = alloca (strlen (comdat_symbol_id) + 64);
5537 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5538 comdat_symbol_id, comdat_symbol_number++);
5539 die->die_symbol = xstrdup (p);
5542 die->die_symbol = gen_internal_sym ();
5545 for (c = die->die_child; c != NULL; c = c->die_sib)
5546 assign_symbol_names (c);
5549 /* Traverse the DIE (which is always comp_unit_die), and set up
5550 additional compilation units for each of the include files we see
5551 bracketed by BINCL/EINCL. */
5554 break_out_includes (die)
5555 register dw_die_ref die;
5558 register dw_die_ref unit = NULL;
5559 limbo_die_node *node;
5561 for (ptr = &(die->die_child); *ptr; )
5563 register dw_die_ref c = *ptr;
5565 if (c->die_tag == DW_TAG_GNU_BINCL
5566 || c->die_tag == DW_TAG_GNU_EINCL
5567 || (unit && is_comdat_die (c)))
5569 /* This DIE is for a secondary CU; remove it from the main one. */
5572 if (c->die_tag == DW_TAG_GNU_BINCL)
5574 unit = push_new_compile_unit (unit, c);
5577 else if (c->die_tag == DW_TAG_GNU_EINCL)
5579 unit = pop_compile_unit (unit);
5583 add_child_die (unit, c);
5587 /* Leave this DIE in the main CU. */
5588 ptr = &(c->die_sib);
5594 /* We can only use this in debugging, since the frontend doesn't check
5595 to make sure that we leave every include file we enter. */
5600 assign_symbol_names (die);
5601 for (node = limbo_die_list; node; node = node->next)
5603 compute_section_prefix (node->die);
5604 assign_symbol_names (node->die);
5608 /* Traverse the DIE and add a sibling attribute if it may have the
5609 effect of speeding up access to siblings. To save some space,
5610 avoid generating sibling attributes for DIE's without children. */
5613 add_sibling_attributes (die)
5614 register dw_die_ref die;
5616 register dw_die_ref c;
5618 if (die->die_tag != DW_TAG_compile_unit
5619 && die->die_sib && die->die_child != NULL)
5620 /* Add the sibling link to the front of the attribute list. */
5621 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5623 for (c = die->die_child; c != NULL; c = c->die_sib)
5624 add_sibling_attributes (c);
5627 /* The format of each DIE (and its attribute value pairs)
5628 is encoded in an abbreviation table. This routine builds the
5629 abbreviation table and assigns a unique abbreviation id for
5630 each abbreviation entry. The children of each die are visited
5634 build_abbrev_table (die)
5635 register dw_die_ref die;
5637 register unsigned long abbrev_id;
5638 register unsigned long n_alloc;
5639 register dw_die_ref c;
5640 register dw_attr_ref d_attr, a_attr;
5642 /* Scan the DIE references, and mark as external any that refer to
5643 DIEs from other CUs (i.e. those which are not marked). */
5644 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5646 if (AT_class (d_attr) == dw_val_class_die_ref
5647 && AT_ref (d_attr)->die_mark == 0)
5649 if (AT_ref (d_attr)->die_symbol == 0)
5651 set_AT_ref_external (d_attr, 1);
5655 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5657 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5659 if (abbrev->die_tag == die->die_tag)
5661 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5663 a_attr = abbrev->die_attr;
5664 d_attr = die->die_attr;
5666 while (a_attr != NULL && d_attr != NULL)
5668 if ((a_attr->dw_attr != d_attr->dw_attr)
5669 || (value_format (a_attr) != value_format (d_attr)))
5672 a_attr = a_attr->dw_attr_next;
5673 d_attr = d_attr->dw_attr_next;
5676 if (a_attr == NULL && d_attr == NULL)
5682 if (abbrev_id >= abbrev_die_table_in_use)
5684 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5686 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5688 = (dw_die_ref *) xrealloc (abbrev_die_table,
5689 sizeof (dw_die_ref) * n_alloc);
5691 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5692 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5693 abbrev_die_table_allocated = n_alloc;
5696 ++abbrev_die_table_in_use;
5697 abbrev_die_table[abbrev_id] = die;
5700 die->die_abbrev = abbrev_id;
5701 for (c = die->die_child; c != NULL; c = c->die_sib)
5702 build_abbrev_table (c);
5705 /* Return the size of a string, including the null byte.
5707 This used to treat backslashes as escapes, and hence they were not included
5708 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5709 which treats a backslash as a backslash, escaping it if necessary, and hence
5710 we must include them in the count. */
5712 static unsigned long
5713 size_of_string (str)
5714 register const char *str;
5716 return strlen (str) + 1;
5719 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5722 constant_size (value)
5723 long unsigned value;
5730 log = floor_log2 (value);
5733 log = 1 << (floor_log2 (log) + 1);
5738 /* Return the size of a DIE, as it is represented in the
5739 .debug_info section. */
5741 static unsigned long
5743 register dw_die_ref die;
5745 register unsigned long size = 0;
5746 register dw_attr_ref a;
5748 size += size_of_uleb128 (die->die_abbrev);
5749 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5751 switch (AT_class (a))
5753 case dw_val_class_addr:
5754 size += DWARF2_ADDR_SIZE;
5756 case dw_val_class_loc:
5758 register unsigned long lsize = size_of_locs (AT_loc (a));
5761 size += constant_size (lsize);
5765 case dw_val_class_const:
5766 size += size_of_sleb128 (AT_int (a));
5768 case dw_val_class_unsigned_const:
5769 size += constant_size (AT_unsigned (a));
5771 case dw_val_class_long_long:
5772 size += 1 + 8; /* block */
5774 case dw_val_class_float:
5775 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5777 case dw_val_class_flag:
5780 case dw_val_class_die_ref:
5781 size += DWARF_OFFSET_SIZE;
5783 case dw_val_class_fde_ref:
5784 size += DWARF_OFFSET_SIZE;
5786 case dw_val_class_lbl_id:
5787 size += DWARF2_ADDR_SIZE;
5789 case dw_val_class_lbl_offset:
5790 size += DWARF_OFFSET_SIZE;
5792 case dw_val_class_str:
5793 size += size_of_string (AT_string (a));
5803 /* Size the debugging information associated with a given DIE.
5804 Visits the DIE's children recursively. Updates the global
5805 variable next_die_offset, on each time through. Uses the
5806 current value of next_die_offset to update the die_offset
5807 field in each DIE. */
5810 calc_die_sizes (die)
5813 register dw_die_ref c;
5814 die->die_offset = next_die_offset;
5815 next_die_offset += size_of_die (die);
5817 for (c = die->die_child; c != NULL; c = c->die_sib)
5820 if (die->die_child != NULL)
5821 /* Count the null byte used to terminate sibling lists. */
5822 next_die_offset += 1;
5825 /* Set the marks for a die and its children. We do this so
5826 that we know whether or not a reference needs to use FORM_ref_addr; only
5827 DIEs in the same CU will be marked. We used to clear out the offset
5828 and use that as the flag, but ran into ordering problems. */
5834 register dw_die_ref c;
5836 for (c = die->die_child; c; c = c->die_sib)
5840 /* Clear the marks for a die and its children. */
5846 register dw_die_ref c;
5848 for (c = die->die_child; c; c = c->die_sib)
5852 /* Return the size of the line information prolog generated for the
5853 compilation unit. */
5855 static unsigned long
5856 size_of_line_prolog ()
5858 register unsigned long size;
5859 register unsigned long ft_index;
5861 size = DWARF_LINE_PROLOG_HEADER_SIZE;
5863 /* Count the size of the table giving number of args for each
5865 size += DWARF_LINE_OPCODE_BASE - 1;
5867 /* Include directory table is empty (at present). Count only the
5868 null byte used to terminate the table. */
5871 for (ft_index = 1; ft_index < decl_file_table.in_use; ++ft_index)
5873 /* File name entry. */
5874 size += size_of_string (decl_file_table.table[ft_index]);
5876 /* Include directory index. */
5877 size += size_of_uleb128 (0);
5879 /* Modification time. */
5880 size += size_of_uleb128 (0);
5882 /* File length in bytes. */
5883 size += size_of_uleb128 (0);
5886 /* Count the file table terminator. */
5891 /* Return the size of the .debug_pubnames table generated for the
5892 compilation unit. */
5894 static unsigned long
5897 register unsigned long size;
5898 register unsigned i;
5900 size = DWARF_PUBNAMES_HEADER_SIZE;
5901 for (i = 0; i < pubname_table_in_use; ++i)
5903 register pubname_ref p = &pubname_table[i];
5904 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5907 size += DWARF_OFFSET_SIZE;
5911 /* Return the size of the information in the .debug_aranges section. */
5913 static unsigned long
5916 register unsigned long size;
5918 size = DWARF_ARANGES_HEADER_SIZE;
5920 /* Count the address/length pair for this compilation unit. */
5921 size += 2 * DWARF2_ADDR_SIZE;
5922 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5924 /* Count the two zero words used to terminated the address range table. */
5925 size += 2 * DWARF2_ADDR_SIZE;
5929 /* Select the encoding of an attribute value. */
5931 static enum dwarf_form
5935 switch (a->dw_attr_val.val_class)
5937 case dw_val_class_addr:
5938 return DW_FORM_addr;
5939 case dw_val_class_loc:
5940 switch (constant_size (size_of_locs (AT_loc (a))))
5943 return DW_FORM_block1;
5945 return DW_FORM_block2;
5949 case dw_val_class_const:
5950 return DW_FORM_sdata;
5951 case dw_val_class_unsigned_const:
5952 switch (constant_size (AT_unsigned (a)))
5955 return DW_FORM_data1;
5957 return DW_FORM_data2;
5959 return DW_FORM_data4;
5961 return DW_FORM_data8;
5965 case dw_val_class_long_long:
5966 return DW_FORM_block1;
5967 case dw_val_class_float:
5968 return DW_FORM_block1;
5969 case dw_val_class_flag:
5970 return DW_FORM_flag;
5971 case dw_val_class_die_ref:
5972 if (AT_ref_external (a))
5973 return DW_FORM_ref_addr;
5976 case dw_val_class_fde_ref:
5977 return DW_FORM_data;
5978 case dw_val_class_lbl_id:
5979 return DW_FORM_addr;
5980 case dw_val_class_lbl_offset:
5981 return DW_FORM_data;
5982 case dw_val_class_str:
5983 return DW_FORM_string;
5989 /* Output the encoding of an attribute value. */
5992 output_value_format (a)
5995 enum dwarf_form form = value_format (a);
5997 output_uleb128 (form);
5999 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
6001 fputc ('\n', asm_out_file);
6004 /* Output the .debug_abbrev section which defines the DIE abbreviation
6008 output_abbrev_section ()
6010 unsigned long abbrev_id;
6013 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6015 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6017 output_uleb128 (abbrev_id);
6019 fprintf (asm_out_file, " (abbrev code)");
6021 fputc ('\n', asm_out_file);
6022 output_uleb128 (abbrev->die_tag);
6024 fprintf (asm_out_file, " (TAG: %s)",
6025 dwarf_tag_name (abbrev->die_tag));
6027 fputc ('\n', asm_out_file);
6028 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP,
6029 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
6032 fprintf (asm_out_file, "\t%s %s",
6034 (abbrev->die_child != NULL
6035 ? "DW_children_yes" : "DW_children_no"));
6037 fputc ('\n', asm_out_file);
6039 for (a_attr = abbrev->die_attr; a_attr != NULL;
6040 a_attr = a_attr->dw_attr_next)
6042 output_uleb128 (a_attr->dw_attr);
6044 fprintf (asm_out_file, " (%s)",
6045 dwarf_attr_name (a_attr->dw_attr));
6047 fputc ('\n', asm_out_file);
6048 output_value_format (a_attr);
6051 fprintf (asm_out_file, "%s0,0\n", ASM_BYTE_OP);
6054 /* Terminate the table. */
6055 fprintf (asm_out_file, "%s0\n", ASM_BYTE_OP);
6058 /* Output a symbol we can use to refer to this DIE from another CU. */
6061 output_die_symbol (die)
6062 register dw_die_ref die;
6064 char *sym = die->die_symbol;
6069 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6070 /* We make these global, not weak; if the target doesn't support
6071 .linkonce, it doesn't support combining the sections, so debugging
6073 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6074 ASM_OUTPUT_LABEL (asm_out_file, sym);
6077 /* Output a symbolic (i.e. FORM_ref_addr) reference to TARGET_DIE. */
6080 output_symbolic_ref (target_die)
6081 dw_die_ref target_die;
6083 char *sym = target_die->die_symbol;
6088 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, sym);
6091 /* Output the DIE and its attributes. Called recursively to generate
6092 the definitions of each child DIE. */
6096 register dw_die_ref die;
6098 register dw_attr_ref a;
6099 register dw_die_ref c;
6100 register unsigned long size;
6102 /* If someone in another CU might refer to us, set up a symbol for
6103 them to point to. */
6104 if (die->die_symbol)
6105 output_die_symbol (die);
6107 output_uleb128 (die->die_abbrev);
6109 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
6110 die->die_offset, dwarf_tag_name (die->die_tag));
6112 fputc ('\n', asm_out_file);
6114 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6116 switch (AT_class (a))
6118 case dw_val_class_addr:
6119 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
6122 case dw_val_class_loc:
6123 size = size_of_locs (AT_loc (a));
6125 /* Output the block length for this list of location operations. */
6126 switch (constant_size (size))
6129 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
6132 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
6139 fprintf (asm_out_file, "\t%s %s",
6140 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6142 fputc ('\n', asm_out_file);
6144 output_loc_sequence (AT_loc (a));
6147 case dw_val_class_const:
6148 /* ??? It would be slightly more efficient to use a scheme like is
6149 used for unsigned constants below, but gdb 4.x does not sign
6150 extend. Gdb 5.x does sign extend. */
6151 output_sleb128 (AT_int (a));
6154 case dw_val_class_unsigned_const:
6155 switch (constant_size (AT_unsigned (a)))
6158 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
6161 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
6164 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
6167 ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a));
6174 case dw_val_class_long_long:
6175 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
6177 fprintf (asm_out_file, "\t%s %s",
6178 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6180 fputc ('\n', asm_out_file);
6181 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file,
6182 a->dw_attr_val.v.val_long_long.hi,
6183 a->dw_attr_val.v.val_long_long.low);
6186 fprintf (asm_out_file,
6187 "\t%s long long constant", ASM_COMMENT_START);
6189 fputc ('\n', asm_out_file);
6192 case dw_val_class_float:
6194 register unsigned int i;
6195 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6196 a->dw_attr_val.v.val_float.length * 4);
6198 fprintf (asm_out_file, "\t%s %s",
6199 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6201 fputc ('\n', asm_out_file);
6202 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6204 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
6205 a->dw_attr_val.v.val_float.array[i]);
6207 fprintf (asm_out_file, "\t%s fp constant word %u",
6208 ASM_COMMENT_START, i);
6210 fputc ('\n', asm_out_file);
6215 case dw_val_class_flag:
6216 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
6219 case dw_val_class_die_ref:
6220 if (AT_ref_external (a))
6221 output_symbolic_ref (AT_ref (a));
6222 else if (AT_ref (a)->die_offset == 0)
6225 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
6228 case dw_val_class_fde_ref:
6231 ASM_GENERATE_INTERNAL_LABEL
6232 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
6233 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
6234 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
6238 case dw_val_class_lbl_id:
6239 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
6242 case dw_val_class_lbl_offset:
6243 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
6246 case dw_val_class_str:
6248 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
6250 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
6251 (int) strlen (AT_string (a)) + 1);
6258 if (AT_class (a) != dw_val_class_loc
6259 && AT_class (a) != dw_val_class_long_long
6260 && AT_class (a) != dw_val_class_float)
6263 fprintf (asm_out_file, "\t%s %s",
6264 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6266 fputc ('\n', asm_out_file);
6270 for (c = die->die_child; c != NULL; c = c->die_sib)
6273 if (die->die_child != NULL)
6275 /* Add null byte to terminate sibling list. */
6276 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6278 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
6279 ASM_COMMENT_START, die->die_offset);
6281 fputc ('\n', asm_out_file);
6285 /* Output the compilation unit that appears at the beginning of the
6286 .debug_info section, and precedes the DIE descriptions. */
6289 output_compilation_unit_header ()
6291 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
6293 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
6296 fputc ('\n', asm_out_file);
6297 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6299 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
6301 fputc ('\n', asm_out_file);
6302 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
6304 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
6307 fputc ('\n', asm_out_file);
6308 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6310 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
6312 fputc ('\n', asm_out_file);
6315 /* Output the compilation unit DIE and its children. */
6318 output_comp_unit (die)
6321 const char *secname;
6323 if (die->die_child == 0)
6326 /* Mark all the DIEs in this CU so we know which get local refs. */
6329 build_abbrev_table (die);
6331 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6332 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6333 calc_die_sizes (die);
6335 if (die->die_symbol)
6337 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6338 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6340 die->die_symbol = NULL;
6343 secname = (const char *) DEBUG_INFO_SECTION;
6345 /* Output debugging information. */
6346 fputc ('\n', asm_out_file);
6347 ASM_OUTPUT_SECTION (asm_out_file, secname);
6348 output_compilation_unit_header ();
6351 /* Leave the marks on the main CU, so we can check them in
6353 if (die->die_symbol)
6357 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6358 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6359 argument list, and maybe the scope. */
6362 dwarf2_name (decl, scope)
6366 return (*decl_printable_name) (decl, scope ? 1 : 0);
6369 /* Add a new entry to .debug_pubnames if appropriate. */
6372 add_pubname (decl, die)
6378 if (! TREE_PUBLIC (decl))
6381 if (pubname_table_in_use == pubname_table_allocated)
6383 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6384 pubname_table = (pubname_ref) xrealloc
6385 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6388 p = &pubname_table[pubname_table_in_use++];
6391 p->name = xstrdup (dwarf2_name (decl, 1));
6394 /* Output the public names table used to speed up access to externally
6395 visible names. For now, only generate entries for externally
6396 visible procedures. */
6401 register unsigned i;
6402 register unsigned long pubnames_length = size_of_pubnames ();
6404 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
6407 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
6410 fputc ('\n', asm_out_file);
6411 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6414 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6416 fputc ('\n', asm_out_file);
6417 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6419 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6422 fputc ('\n', asm_out_file);
6423 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
6425 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
6427 fputc ('\n', asm_out_file);
6428 for (i = 0; i < pubname_table_in_use; ++i)
6430 register pubname_ref pub = &pubname_table[i];
6432 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6433 if (pub->die->die_mark == 0)
6436 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
6438 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
6440 fputc ('\n', asm_out_file);
6444 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
6445 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
6449 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
6450 (int) strlen (pub->name) + 1);
6453 fputc ('\n', asm_out_file);
6456 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
6457 fputc ('\n', asm_out_file);
6460 /* Add a new entry to .debug_aranges if appropriate. */
6463 add_arange (decl, die)
6467 if (! DECL_SECTION_NAME (decl))
6470 if (arange_table_in_use == arange_table_allocated)
6472 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6474 = (arange_ref) xrealloc (arange_table,
6475 arange_table_allocated * sizeof (dw_die_ref));
6478 arange_table[arange_table_in_use++] = die;
6481 /* Output the information that goes into the .debug_aranges table.
6482 Namely, define the beginning and ending address range of the
6483 text section generated for this compilation unit. */
6488 register unsigned i;
6489 register unsigned long aranges_length = size_of_aranges ();
6491 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
6493 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
6496 fputc ('\n', asm_out_file);
6497 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6499 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6501 fputc ('\n', asm_out_file);
6502 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6504 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6507 fputc ('\n', asm_out_file);
6508 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6510 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
6512 fputc ('\n', asm_out_file);
6513 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6515 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
6518 fputc ('\n', asm_out_file);
6520 /* We need to align to twice the pointer size here. */
6521 if (DWARF_ARANGES_PAD_SIZE)
6523 /* Pad using a 2 bytes word so that padding is correct
6524 for any pointer size. */
6525 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
6526 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6527 fprintf (asm_out_file, ",0");
6529 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
6530 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
6533 fputc ('\n', asm_out_file);
6534 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
6536 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6538 fputc ('\n', asm_out_file);
6539 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
6540 text_section_label);
6542 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6544 fputc ('\n', asm_out_file);
6545 for (i = 0; i < arange_table_in_use; ++i)
6547 dw_die_ref die = arange_table[i];
6549 /* We shouldn't see aranges for DIEs outside of the main CU. */
6550 if (die->die_mark == 0)
6553 if (die->die_tag == DW_TAG_subprogram)
6554 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
6557 /* A static variable; extract the symbol from DW_AT_location.
6558 Note that this code isn't currently hit, as we only emit
6559 aranges for functions (jason 9/23/99). */
6561 dw_attr_ref a = get_AT (die, DW_AT_location);
6562 dw_loc_descr_ref loc;
6563 if (! a || AT_class (a) != dw_val_class_loc)
6567 if (loc->dw_loc_opc != DW_OP_addr)
6570 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
6571 loc->dw_loc_oprnd1.v.val_addr);
6575 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6577 fputc ('\n', asm_out_file);
6578 if (die->die_tag == DW_TAG_subprogram)
6579 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
6580 get_AT_low_pc (die));
6582 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
6583 get_AT_unsigned (die, DW_AT_byte_size));
6586 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6588 fputc ('\n', asm_out_file);
6591 /* Output the terminator words. */
6592 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6593 fputc ('\n', asm_out_file);
6594 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6595 fputc ('\n', asm_out_file);
6599 /* Data structure containing information about input files. */
6602 char *path; /* Complete file name. */
6603 char *fname; /* File name part. */
6604 int length; /* Length of entire string. */
6605 int file_idx; /* Index in input file table. */
6606 int dir_idx; /* Index in directory table. */
6609 /* Data structure containing information about directories with source
6613 char *path; /* Path including directory name. */
6614 int length; /* Path length. */
6615 int prefix; /* Index of directory entry which is a prefix. */
6616 int nbytes; /* Total number of bytes in all file names excluding
6618 int count; /* Number of files in this directory. */
6619 int dir_idx; /* Index of directory used as base. */
6620 int used; /* Used in the end? */
6623 /* Callback function for file_info comparison. We sort by looking at
6624 the directories in the path. */
6626 file_info_cmp (p1, p2)
6630 const struct file_info *s1 = p1;
6631 const struct file_info *s2 = p2;
6635 /* Take care of file names without directories. */
6636 if (s1->path == s1->fname)
6638 else if (s2->path == s2->fname)
6641 cp1 = (unsigned char *) s1->path;
6642 cp2 = (unsigned char *) s2->path;
6648 /* Reached the end of the first path? */
6649 if (cp1 == (unsigned char *) s1->fname)
6650 /* It doesn't really matter in which order files from the
6651 same directory are sorted in. Therefore don't test for
6652 the second path reaching the end. */
6654 else if (cp2 == (unsigned char *) s2->fname)
6657 /* Character of current path component the same? */
6663 /* Compute the maximum prefix of P2 appearing also in P1. Entire
6664 directory names must match. */
6665 static int prefix_of PARAMS ((struct dir_info *, struct dir_info *));
6668 struct dir_info *p1;
6669 struct dir_info *p2;
6671 char *s1 = p1->path;
6672 char *s2 = p2->path;
6673 int len = p1->length < p2->length ? p1->length : p2->length;
6675 while (*s1 == *s2 && s1 < p1->path + len)
6678 if (*s1 == '/' && *s2 == '/')
6679 /* The whole of P1 is the prefix. */
6682 /* Go back to the last directory component. */
6683 while (s1 > p1->path)
6685 return s1 - p1->path + 1;
6690 /* Output the directory table and the file name table. We try to minimize
6691 the total amount of memory needed. A heuristic is used to avoid large
6692 slowdowns with many input files. */
6694 output_file_names ()
6696 struct file_info *files;
6697 struct dir_info *dirs;
6706 /* Allocate the various arrays we need. */
6707 files = (struct file_info *) alloca (line_file_table.in_use
6708 * sizeof (struct file_info));
6709 dirs = (struct dir_info *) alloca (line_file_table.in_use * 2
6710 * sizeof (struct dir_info));
6712 /* Sort the file names. */
6713 for (i = 1; i < (int) line_file_table.in_use; ++i)
6717 /* Skip all leading "./". */
6718 f = line_file_table.table[i];
6719 while (f[0] == '.' && f[1] == '/')
6722 /* Create a new array entry. */
6724 files[i].length = strlen (f);
6725 files[i].file_idx = i;
6727 /* Search for the file name part. */
6728 f = strrchr (f, '/');
6729 files[i].fname = f == NULL ? files[i].path : f + 1;
6731 qsort (files + 1, line_file_table.in_use - 1, sizeof (files[0]),
6734 /* Find all the different directories used. */
6735 dirs[0].path = files[1].path;
6736 dirs[0].length = files[1].fname - files[1].path;
6737 dirs[0].prefix = -1;
6738 dirs[0].nbytes = files[1].length - dirs[1].length + 1;
6740 dirs[0].dir_idx = 0;
6742 files[1].dir_idx = 0;
6745 for (i = 2; i < (int) line_file_table.in_use; ++i)
6746 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6747 && memcmp (dirs[ndirs - 1].path, files[i].path,
6748 dirs[ndirs - 1].length) == 0)
6750 /* Same directory as last entry. */
6751 files[i].dir_idx = ndirs - 1;
6752 dirs[ndirs - 1].nbytes += files[i].length - dirs[ndirs - 1].length + 1;
6753 ++dirs[ndirs - 1].count;
6761 /* This is a new directory. */
6762 dirs[ndirs].path = files[i].path;
6763 dirs[ndirs].length = files[i].fname - files[i].path;
6764 dirs[ndirs].nbytes = files[i].length - dirs[i].length + 1;
6765 dirs[ndirs].count = 1;
6766 dirs[ndirs].dir_idx = ndirs;
6767 dirs[ndirs].used = 0;
6768 files[i].dir_idx = ndirs;
6770 /* Search for a prefix. */
6773 for (j = 0; j < ndirs; ++j)
6774 if (dirs[j].length > max_len)
6776 int this_len = prefix_of (&dirs[j], &dirs[ndirs]);
6778 if (this_len > max_len)
6785 /* Remember the prefix. If this is a known prefix simply
6786 remember the index. Otherwise we will have to create an
6787 artificial entry. */
6788 if (max_len == dirs[max_idx].length)
6789 /* This is our prefix. */
6790 dirs[ndirs].prefix = max_idx;
6791 else if (max_len > 0)
6793 /* Create an entry without associated file. Since we have
6794 to keep the dirs array sorted (means, entries with paths
6795 which come first) we have to move the new entry in the
6796 place of the old one. */
6797 dirs[++ndirs] = dirs[max_idx];
6799 /* We don't have to set .path. */
6800 dirs[max_idx].length = max_len;
6801 dirs[max_idx].nbytes = 0;
6802 dirs[max_idx].count = 0;
6803 dirs[max_idx].dir_idx = ndirs;
6804 dirs[max_idx].used = 0;
6805 dirs[max_idx].prefix = dirs[ndirs].prefix;
6807 dirs[ndirs - 1].prefix = dirs[ndirs].prefix = max_idx;
6810 dirs[ndirs].prefix = -1;
6815 /* Now to the actual work. We have to find a subset of the
6816 directories which allow expressing the file name using references
6817 to the directory table with the least amount of characters. We
6818 do not do an exhaustive search where we would have to check out
6819 every combination of every single possible prefix. Instead we
6820 use a heuristic which provides nearly optimal results in most
6821 cases and never is much off. */
6822 saved = (int *) alloca (ndirs * sizeof (int));
6823 savehere = (int *) alloca (ndirs * sizeof (int));
6825 memset (saved, '\0', ndirs * sizeof (saved[0]));
6826 for (i = 0; i < ndirs; ++i)
6831 /* We can always safe some space for the current directory. But
6832 this does not mean it will be enough to justify adding the
6834 savehere[i] = dirs[i].length;
6835 total = (savehere[i] - saved[i]) * dirs[i].count;
6837 for (j = i + 1; j < ndirs; ++j)
6841 if (saved[j] < dirs[i].length)
6843 /* Determine whether the dirs[i] path is a prefix of the
6848 while (k != -1 && k != i)
6853 /* Yes it is. We can possibly safe some memory but
6854 writing the filenames in dirs[j] relative to
6856 savehere[j] = dirs[i].length;
6857 total += (savehere[j] - saved[j]) * dirs[j].count;
6862 /* Check whether we can safe enough to justify adding the dirs[i]
6864 if (total > dirs[i].length + 1)
6866 /* It's worthwhile adding. */
6867 for (j = i; j < ndirs; ++j)
6868 if (savehere[j] > 0)
6870 /* Remember how much we saved for this directory so far. */
6871 saved[j] = savehere[j];
6873 /* Remember the prefix directory. */
6874 dirs[j].dir_idx = i;
6879 /* We have to emit them in the order they appear in the line_file_table
6880 array since the index is used in the debug info generation. To
6881 do this efficiently we generate a back-mapping of the indices
6883 backmap = (int *) alloca (line_file_table.in_use * sizeof (int));
6884 for (i = 1; i < (int) line_file_table.in_use; ++i)
6886 backmap[files[i].file_idx] = i;
6887 /* Mark this directory as used. */
6888 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6891 /* That was it. We are ready to emit the information. First the
6892 directory name table. Here we have to make sure that the first
6893 actually emitted directory name has the index one. Zero is
6894 reserved for the current working directory. Make sure we do not
6895 confuse these indices with the one for the constructed table
6896 (even though most of the time they are identical). */
6898 idx_offset = dirs[0].length > 0 ? 1 : 0;
6899 for (i = 1 - idx_offset; i < ndirs; ++i)
6900 if (dirs[i].used != 0)
6902 dirs[i].used = idx++;
6906 ASM_OUTPUT_DWARF_NSTRING (asm_out_file,
6907 dirs[i].path, dirs[i].length - 1);
6908 fprintf (asm_out_file, "%s Directory Entry: 0x%x\n",
6909 ASM_COMMENT_START, dirs[i].used);
6913 ASM_OUTPUT_ASCII (asm_out_file, dirs[i].path, dirs[i].length - 1);
6914 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6915 fputc ('\n', asm_out_file);
6918 /* Correct the index for the current working directory entry if it
6920 if (idx_offset == 0)
6922 /* Terminate the directory name array. */
6923 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6925 fprintf (asm_out_file, "\t%s End directory table", ASM_COMMENT_START);
6926 fputc ('\n', asm_out_file);
6928 /* Now write all the file names. */
6929 for (i = 1; i < (int) line_file_table.in_use; ++i)
6931 int file_idx = backmap[i];
6932 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6936 ASM_OUTPUT_DWARF_STRING (asm_out_file,
6937 files[file_idx].path
6938 + dirs[dir_idx].length);
6939 fprintf (asm_out_file, "%s File Entry: 0x%x\n",
6940 ASM_COMMENT_START, i);
6943 ASM_OUTPUT_ASCII (asm_out_file,
6944 files[file_idx].path + dirs[dir_idx].length,
6945 (files[file_idx].length
6946 - dirs[dir_idx].length) + 1);
6948 /* Include directory index. */
6949 output_uleb128 (dirs[dir_idx].used);
6950 fputc ('\n', asm_out_file);
6952 /* Modification time. */
6954 fputc ('\n', asm_out_file);
6956 /* File length in bytes. */
6958 fputc ('\n', asm_out_file);
6961 /* Terminate the file name table */
6962 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6964 fprintf (asm_out_file, "\t%s End file name table", ASM_COMMENT_START);
6965 fputc ('\n', asm_out_file);
6969 /* Output the source line number correspondence information. This
6970 information goes into the .debug_line section. */
6975 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6976 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6977 register unsigned opc;
6978 register unsigned n_op_args;
6979 register unsigned long lt_index;
6980 register unsigned long current_line;
6981 register long line_offset;
6982 register long line_delta;
6983 register unsigned long current_file;
6984 register unsigned long function;
6986 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
6988 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
6991 fputc ('\n', asm_out_file);
6992 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
6993 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6995 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6997 fputc ('\n', asm_out_file);
6998 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
7000 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
7002 fputc ('\n', asm_out_file);
7003 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
7005 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
7008 fputc ('\n', asm_out_file);
7009 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
7011 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
7014 fputc ('\n', asm_out_file);
7015 fprintf (asm_out_file, "%s%d", ASM_BYTE_OP, DWARF_LINE_BASE);
7017 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
7020 fputc ('\n', asm_out_file);
7021 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
7023 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
7026 fputc ('\n', asm_out_file);
7027 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
7029 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
7031 fputc ('\n', asm_out_file);
7032 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
7036 case DW_LNS_advance_pc:
7037 case DW_LNS_advance_line:
7038 case DW_LNS_set_file:
7039 case DW_LNS_set_column:
7040 case DW_LNS_fixed_advance_pc:
7047 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
7049 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
7050 ASM_COMMENT_START, opc, n_op_args);
7051 fputc ('\n', asm_out_file);
7054 /* Write out the information about the files we use. */
7055 output_file_names ();
7057 /* We used to set the address register to the first location in the text
7058 section here, but that didn't accomplish anything since we already
7059 have a line note for the opening brace of the first function. */
7061 /* Generate the line number to PC correspondence table, encoded as
7062 a series of state machine operations. */
7065 strcpy (prev_line_label, text_section_label);
7066 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7068 register dw_line_info_ref line_info = &line_info_table[lt_index];
7071 /* Disable this optimization for now; GDB wants to see two line notes
7072 at the beginning of a function so it can find the end of the
7075 /* Don't emit anything for redundant notes. Just updating the
7076 address doesn't accomplish anything, because we already assume
7077 that anything after the last address is this line. */
7078 if (line_info->dw_line_num == current_line
7079 && line_info->dw_file_num == current_file)
7083 /* Emit debug info for the address of the current line, choosing
7084 the encoding that uses the least amount of space. */
7085 /* ??? Unfortunately, we have little choice here currently, and must
7086 always use the most general form. Gcc does not know the address
7087 delta itself, so we can't use DW_LNS_advance_pc. There are no known
7088 dwarf2 aware assemblers at this time, so we can't use any special
7089 pseudo ops that would allow the assembler to optimally encode this for
7090 us. Many ports do have length attributes which will give an upper
7091 bound on the address range. We could perhaps use length attributes
7092 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
7093 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7096 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7097 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7099 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7102 fputc ('\n', asm_out_file);
7103 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
7104 fputc ('\n', asm_out_file);
7108 /* This can handle any delta. This takes
7109 4+DWARF2_ADDR_SIZE bytes. */
7110 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7112 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7114 fputc ('\n', asm_out_file);
7115 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7116 fputc ('\n', asm_out_file);
7117 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7118 fputc ('\n', asm_out_file);
7119 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7120 fputc ('\n', asm_out_file);
7122 strcpy (prev_line_label, line_label);
7124 /* Emit debug info for the source file of the current line, if
7125 different from the previous line. */
7126 if (line_info->dw_file_num != current_file)
7128 current_file = line_info->dw_file_num;
7129 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
7131 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
7133 fputc ('\n', asm_out_file);
7134 output_uleb128 (current_file);
7136 fprintf (asm_out_file, " (\"%s\")",
7137 line_file_table.table[current_file]);
7139 fputc ('\n', asm_out_file);
7142 /* Emit debug info for the current line number, choosing the encoding
7143 that uses the least amount of space. */
7144 if (line_info->dw_line_num != current_line)
7146 line_offset = line_info->dw_line_num - current_line;
7147 line_delta = line_offset - DWARF_LINE_BASE;
7148 current_line = line_info->dw_line_num;
7149 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7151 /* This can handle deltas from -10 to 234, using the current
7152 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7154 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
7155 DWARF_LINE_OPCODE_BASE + line_delta);
7157 fprintf (asm_out_file,
7158 "\t%s line %ld", ASM_COMMENT_START, current_line);
7160 fputc ('\n', asm_out_file);
7164 /* This can handle any delta. This takes at least 4 bytes,
7165 depending on the value being encoded. */
7166 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
7168 fprintf (asm_out_file, "\t%s advance to line %ld",
7169 ASM_COMMENT_START, current_line);
7171 fputc ('\n', asm_out_file);
7172 output_sleb128 (line_offset);
7173 fputc ('\n', asm_out_file);
7174 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7176 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7177 fputc ('\n', asm_out_file);
7182 /* We still need to start a new row, so output a copy insn. */
7183 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7185 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7186 fputc ('\n', asm_out_file);
7190 /* Emit debug info for the address of the end of the function. */
7193 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7195 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7198 fputc ('\n', asm_out_file);
7199 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
7200 fputc ('\n', asm_out_file);
7204 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7206 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
7207 fputc ('\n', asm_out_file);
7208 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7209 fputc ('\n', asm_out_file);
7210 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7211 fputc ('\n', asm_out_file);
7212 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
7213 fputc ('\n', asm_out_file);
7216 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7218 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
7220 fputc ('\n', asm_out_file);
7222 fputc ('\n', asm_out_file);
7223 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
7224 fputc ('\n', asm_out_file);
7229 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7231 register dw_separate_line_info_ref line_info
7232 = &separate_line_info_table[lt_index];
7235 /* Don't emit anything for redundant notes. */
7236 if (line_info->dw_line_num == current_line
7237 && line_info->dw_file_num == current_file
7238 && line_info->function == function)
7242 /* Emit debug info for the address of the current line. If this is
7243 a new function, or the first line of a function, then we need
7244 to handle it differently. */
7245 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7247 if (function != line_info->function)
7249 function = line_info->function;
7251 /* Set the address register to the first line in the function */
7252 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7254 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7257 fputc ('\n', asm_out_file);
7258 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7259 fputc ('\n', asm_out_file);
7260 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7261 fputc ('\n', asm_out_file);
7262 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7263 fputc ('\n', asm_out_file);
7267 /* ??? See the DW_LNS_advance_pc comment above. */
7270 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7272 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7275 fputc ('\n', asm_out_file);
7276 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7278 fputc ('\n', asm_out_file);
7282 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7284 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7286 fputc ('\n', asm_out_file);
7287 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7288 fputc ('\n', asm_out_file);
7289 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7290 fputc ('\n', asm_out_file);
7291 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7292 fputc ('\n', asm_out_file);
7295 strcpy (prev_line_label, line_label);
7297 /* Emit debug info for the source file of the current line, if
7298 different from the previous line. */
7299 if (line_info->dw_file_num != current_file)
7301 current_file = line_info->dw_file_num;
7302 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
7304 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
7306 fputc ('\n', asm_out_file);
7307 output_uleb128 (current_file);
7309 fprintf (asm_out_file, " (\"%s\")",
7310 line_file_table.table[current_file]);
7312 fputc ('\n', asm_out_file);
7315 /* Emit debug info for the current line number, choosing the encoding
7316 that uses the least amount of space. */
7317 if (line_info->dw_line_num != current_line)
7319 line_offset = line_info->dw_line_num - current_line;
7320 line_delta = line_offset - DWARF_LINE_BASE;
7321 current_line = line_info->dw_line_num;
7322 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7324 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
7325 DWARF_LINE_OPCODE_BASE + line_delta);
7327 fprintf (asm_out_file,
7328 "\t%s line %ld", ASM_COMMENT_START, current_line);
7330 fputc ('\n', asm_out_file);
7334 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
7336 fprintf (asm_out_file, "\t%s advance to line %ld",
7337 ASM_COMMENT_START, current_line);
7339 fputc ('\n', asm_out_file);
7340 output_sleb128 (line_offset);
7341 fputc ('\n', asm_out_file);
7342 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7344 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7345 fputc ('\n', asm_out_file);
7350 /* We still need to start a new row, so output a copy insn. */
7351 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7353 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7354 fputc ('\n', asm_out_file);
7362 /* If we're done with a function, end its sequence. */
7363 if (lt_index == separate_line_info_table_in_use
7364 || separate_line_info_table[lt_index].function != function)
7369 /* Emit debug info for the address of the end of the function. */
7370 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7373 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7375 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7378 fputc ('\n', asm_out_file);
7379 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7381 fputc ('\n', asm_out_file);
7385 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7387 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7389 fputc ('\n', asm_out_file);
7390 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7391 fputc ('\n', asm_out_file);
7392 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7393 fputc ('\n', asm_out_file);
7394 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7395 fputc ('\n', asm_out_file);
7398 /* Output the marker for the end of this sequence. */
7399 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7401 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
7404 fputc ('\n', asm_out_file);
7406 fputc ('\n', asm_out_file);
7407 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
7408 fputc ('\n', asm_out_file);
7412 /* Output the marker for the end of the line number info. */
7413 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
7416 /* Given a pointer to a tree node for some base type, return a pointer to
7417 a DIE that describes the given type.
7419 This routine must only be called for GCC type nodes that correspond to
7420 Dwarf base (fundamental) types. */
7423 base_type_die (type)
7426 register dw_die_ref base_type_result;
7427 register const char *type_name;
7428 register enum dwarf_type encoding;
7429 register tree name = TYPE_NAME (type);
7431 if (TREE_CODE (type) == ERROR_MARK
7432 || TREE_CODE (type) == VOID_TYPE)
7437 if (TREE_CODE (name) == TYPE_DECL)
7438 name = DECL_NAME (name);
7440 type_name = IDENTIFIER_POINTER (name);
7443 type_name = "__unknown__";
7445 switch (TREE_CODE (type))
7448 /* Carefully distinguish the C character types, without messing
7449 up if the language is not C. Note that we check only for the names
7450 that contain spaces; other names might occur by coincidence in other
7452 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7453 && (type == char_type_node
7454 || ! strcmp (type_name, "signed char")
7455 || ! strcmp (type_name, "unsigned char"))))
7457 if (TREE_UNSIGNED (type))
7458 encoding = DW_ATE_unsigned;
7460 encoding = DW_ATE_signed;
7463 /* else fall through. */
7466 /* GNU Pascal/Ada CHAR type. Not used in C. */
7467 if (TREE_UNSIGNED (type))
7468 encoding = DW_ATE_unsigned_char;
7470 encoding = DW_ATE_signed_char;
7474 encoding = DW_ATE_float;
7477 /* Dwarf2 doesn't know anything about complex ints, so use
7478 a user defined type for it. */
7480 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7481 encoding = DW_ATE_complex_float;
7483 encoding = DW_ATE_lo_user;
7487 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7488 encoding = DW_ATE_boolean;
7492 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7495 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7496 if (demangle_name_func)
7497 type_name = (*demangle_name_func) (type_name);
7499 add_AT_string (base_type_result, DW_AT_name, type_name);
7500 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7501 int_size_in_bytes (type));
7502 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7504 return base_type_result;
7507 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7508 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7509 a given type is generally the same as the given type, except that if the
7510 given type is a pointer or reference type, then the root type of the given
7511 type is the root type of the "basis" type for the pointer or reference
7512 type. (This definition of the "root" type is recursive.) Also, the root
7513 type of a `const' qualified type or a `volatile' qualified type is the
7514 root type of the given type without the qualifiers. */
7520 if (TREE_CODE (type) == ERROR_MARK)
7521 return error_mark_node;
7523 switch (TREE_CODE (type))
7526 return error_mark_node;
7529 case REFERENCE_TYPE:
7530 return type_main_variant (root_type (TREE_TYPE (type)));
7533 return type_main_variant (type);
7537 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7538 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7544 switch (TREE_CODE (type))
7559 case QUAL_UNION_TYPE:
7564 case REFERENCE_TYPE:
7578 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7579 entry that chains various modifiers in front of the given type. */
7582 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7584 register int is_const_type;
7585 register int is_volatile_type;
7586 register dw_die_ref context_die;
7588 register enum tree_code code = TREE_CODE (type);
7589 register dw_die_ref mod_type_die = NULL;
7590 register dw_die_ref sub_die = NULL;
7591 register tree item_type = NULL;
7593 if (code != ERROR_MARK)
7595 type = build_type_variant (type, is_const_type, is_volatile_type);
7597 mod_type_die = lookup_type_die (type);
7599 return mod_type_die;
7601 /* Handle C typedef types. */
7602 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7603 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
7605 tree dtype = TREE_TYPE (TYPE_NAME (type));
7608 /* For a named type, use the typedef. */
7609 gen_type_die (type, context_die);
7610 mod_type_die = lookup_type_die (type);
7613 else if (is_const_type < TYPE_READONLY (dtype)
7614 || is_volatile_type < TYPE_VOLATILE (dtype))
7615 /* cv-unqualified version of named type. Just use the unnamed
7616 type to which it refers. */
7618 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
7619 is_const_type, is_volatile_type,
7621 /* Else cv-qualified version of named type; fall through. */
7627 else if (is_const_type)
7629 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7630 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7632 else if (is_volatile_type)
7634 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7635 sub_die = modified_type_die (type, 0, 0, context_die);
7637 else if (code == POINTER_TYPE)
7639 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7640 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7642 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7644 item_type = TREE_TYPE (type);
7646 else if (code == REFERENCE_TYPE)
7648 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7649 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7651 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7653 item_type = TREE_TYPE (type);
7655 else if (is_base_type (type))
7656 mod_type_die = base_type_die (type);
7659 gen_type_die (type, context_die);
7661 /* We have to get the type_main_variant here (and pass that to the
7662 `lookup_type_die' routine) because the ..._TYPE node we have
7663 might simply be a *copy* of some original type node (where the
7664 copy was created to help us keep track of typedef names) and
7665 that copy might have a different TYPE_UID from the original
7667 mod_type_die = lookup_type_die (type_main_variant (type));
7668 if (mod_type_die == NULL)
7673 equate_type_number_to_die (type, mod_type_die);
7675 /* We must do this after the equate_type_number_to_die call, in case
7676 this is a recursive type. This ensures that the modified_type_die
7677 recursion will terminate even if the type is recursive. Recursive
7678 types are possible in Ada. */
7679 sub_die = modified_type_die (item_type,
7680 TYPE_READONLY (item_type),
7681 TYPE_VOLATILE (item_type),
7684 if (sub_die != NULL)
7685 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7687 return mod_type_die;
7690 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7691 an enumerated type. */
7697 return TREE_CODE (type) == ENUMERAL_TYPE;
7700 /* Return the register number described by a given RTL node. */
7706 register unsigned regno = REGNO (rtl);
7708 if (regno >= FIRST_PSEUDO_REGISTER)
7710 warning ("internal regno botch: regno = %d\n", regno);
7714 regno = DBX_REGISTER_NUMBER (regno);
7718 /* Return a location descriptor that designates a machine register. */
7720 static dw_loc_descr_ref
7721 reg_loc_descriptor (rtl)
7724 register dw_loc_descr_ref loc_result = NULL;
7725 register unsigned reg = reg_number (rtl);
7728 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7730 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7735 /* Return a location descriptor that designates a constant. */
7737 static dw_loc_descr_ref
7738 int_loc_descriptor (i)
7741 enum dwarf_location_atom op;
7743 /* Pick the smallest representation of a constant, rather than just
7744 defaulting to the LEB encoding. */
7748 op = DW_OP_lit0 + i;
7751 else if (i <= 0xffff)
7753 else if (HOST_BITS_PER_WIDE_INT == 32
7763 else if (i >= -0x8000)
7765 else if (HOST_BITS_PER_WIDE_INT == 32
7766 || i >= -0x80000000)
7772 return new_loc_descr (op, i, 0);
7775 /* Return a location descriptor that designates a base+offset location. */
7777 static dw_loc_descr_ref
7778 based_loc_descr (reg, offset)
7782 register dw_loc_descr_ref loc_result;
7783 /* For the "frame base", we use the frame pointer or stack pointer
7784 registers, since the RTL for local variables is relative to one of
7786 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7787 ? HARD_FRAME_POINTER_REGNUM
7788 : STACK_POINTER_REGNUM);
7791 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7793 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7795 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7800 /* Return true if this RTL expression describes a base+offset calculation. */
7806 return (GET_CODE (rtl) == PLUS
7807 && ((GET_CODE (XEXP (rtl, 0)) == REG
7808 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7811 /* The following routine converts the RTL for a variable or parameter
7812 (resident in memory) into an equivalent Dwarf representation of a
7813 mechanism for getting the address of that same variable onto the top of a
7814 hypothetical "address evaluation" stack.
7816 When creating memory location descriptors, we are effectively transforming
7817 the RTL for a memory-resident object into its Dwarf postfix expression
7818 equivalent. This routine recursively descends an RTL tree, turning
7819 it into Dwarf postfix code as it goes.
7821 MODE is the mode of the memory reference, needed to handle some
7822 autoincrement addressing modes. */
7824 static dw_loc_descr_ref
7825 mem_loc_descriptor (rtl, mode)
7827 enum machine_mode mode;
7829 dw_loc_descr_ref mem_loc_result = NULL;
7830 /* Note that for a dynamically sized array, the location we will generate a
7831 description of here will be the lowest numbered location which is
7832 actually within the array. That's *not* necessarily the same as the
7833 zeroth element of the array. */
7835 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7836 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7839 switch (GET_CODE (rtl))
7844 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7845 just fall into the SUBREG code. */
7850 /* The case of a subreg may arise when we have a local (register)
7851 variable or a formal (register) parameter which doesn't quite fill
7852 up an entire register. For now, just assume that it is
7853 legitimate to make the Dwarf info refer to the whole register which
7854 contains the given subreg. */
7855 rtl = XEXP (rtl, 0);
7860 /* Whenever a register number forms a part of the description of the
7861 method for calculating the (dynamic) address of a memory resident
7862 object, DWARF rules require the register number be referred to as
7863 a "base register". This distinction is not based in any way upon
7864 what category of register the hardware believes the given register
7865 belongs to. This is strictly DWARF terminology we're dealing with
7866 here. Note that in cases where the location of a memory-resident
7867 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7868 OP_CONST (0)) the actual DWARF location descriptor that we generate
7869 may just be OP_BASEREG (basereg). This may look deceptively like
7870 the object in question was allocated to a register (rather than in
7871 memory) so DWARF consumers need to be aware of the subtle
7872 distinction between OP_REG and OP_BASEREG. */
7873 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7877 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7878 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7882 /* Some ports can transform a symbol ref into a label ref, because
7883 the symbol ref is too far away and has to be dumped into a constant
7887 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7888 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7889 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7893 /* Extract the PLUS expression nested inside and fall into
7894 PLUS code bellow. */
7895 rtl = XEXP (rtl, 1);
7900 /* Turn these into a PLUS expression and fall into the PLUS code
7902 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7903 GEN_INT (GET_CODE (rtl) == PRE_INC
7904 ? GET_MODE_UNIT_SIZE (mode)
7905 : -GET_MODE_UNIT_SIZE (mode)));
7911 if (is_based_loc (rtl))
7912 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7913 INTVAL (XEXP (rtl, 1)));
7916 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7918 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7919 && INTVAL (XEXP (rtl, 1)) >= 0)
7921 add_loc_descr (&mem_loc_result,
7922 new_loc_descr (DW_OP_plus_uconst,
7923 INTVAL (XEXP (rtl, 1)), 0));
7927 add_loc_descr (&mem_loc_result,
7928 mem_loc_descriptor (XEXP (rtl, 1), mode));
7929 add_loc_descr (&mem_loc_result,
7930 new_loc_descr (DW_OP_plus, 0, 0));
7936 /* If a pseudo-reg is optimized away, it is possible for it to
7937 be replaced with a MEM containing a multiply. */
7938 add_loc_descr (&mem_loc_result,
7939 mem_loc_descriptor (XEXP (rtl, 0), mode));
7940 add_loc_descr (&mem_loc_result,
7941 mem_loc_descriptor (XEXP (rtl, 1), mode));
7942 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7946 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7953 return mem_loc_result;
7956 /* Return a descriptor that describes the concatenation of two locations.
7957 This is typically a complex variable. */
7959 static dw_loc_descr_ref
7960 concat_loc_descriptor (x0, x1)
7961 register rtx x0, x1;
7963 dw_loc_descr_ref cc_loc_result = NULL;
7965 if (!is_pseudo_reg (x0)
7966 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7967 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7968 add_loc_descr (&cc_loc_result,
7969 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7971 if (!is_pseudo_reg (x1)
7972 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7973 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7974 add_loc_descr (&cc_loc_result,
7975 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7977 return cc_loc_result;
7980 /* Output a proper Dwarf location descriptor for a variable or parameter
7981 which is either allocated in a register or in a memory location. For a
7982 register, we just generate an OP_REG and the register number. For a
7983 memory location we provide a Dwarf postfix expression describing how to
7984 generate the (dynamic) address of the object onto the address stack. */
7986 static dw_loc_descr_ref
7987 loc_descriptor (rtl)
7990 dw_loc_descr_ref loc_result = NULL;
7991 switch (GET_CODE (rtl))
7994 /* The case of a subreg may arise when we have a local (register)
7995 variable or a formal (register) parameter which doesn't quite fill
7996 up an entire register. For now, just assume that it is
7997 legitimate to make the Dwarf info refer to the whole register which
7998 contains the given subreg. */
7999 rtl = XEXP (rtl, 0);
8004 loc_result = reg_loc_descriptor (rtl);
8008 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8012 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
8022 /* Similar, but generate the descriptor from trees instead of rtl.
8023 This comes up particularly with variable length arrays. */
8025 static dw_loc_descr_ref
8026 loc_descriptor_from_tree (loc, addressp)
8030 dw_loc_descr_ref ret = NULL;
8031 int indirect_size = 0;
8032 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
8033 enum dwarf_location_atom op;
8035 /* ??? Most of the time we do not take proper care for sign/zero
8036 extending the values properly. Hopefully this won't be a real
8039 switch (TREE_CODE (loc))
8044 case WITH_RECORD_EXPR:
8045 /* This case involves extracting fields from an object to determine the
8046 position of other fields. We don't try to encode this here. The
8047 only user of this is Ada, which encodes the needed information using
8048 the names of types. */
8054 rtx rtl = rtl_for_decl_location (loc);
8055 enum machine_mode mode = DECL_MODE (loc);
8057 if (rtl == NULL_RTX)
8059 else if (CONSTANT_P (rtl))
8061 ret = new_loc_descr (DW_OP_addr, 0, 0);
8062 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8063 ret->dw_loc_oprnd1.v.val_addr = rtl;
8064 indirect_size = GET_MODE_SIZE (mode);
8068 if (GET_CODE (rtl) == MEM)
8070 indirect_size = GET_MODE_SIZE (mode);
8071 rtl = XEXP (rtl, 0);
8073 ret = mem_loc_descriptor (rtl, mode);
8079 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8080 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
8085 case NON_LVALUE_EXPR:
8087 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8094 HOST_WIDE_INT bitsize, bitpos, bytepos;
8095 enum machine_mode mode;
8097 unsigned int alignment;
8099 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8100 &unsignedp, &volatilep, &alignment);
8101 ret = loc_descriptor_from_tree (obj, 1);
8103 if (offset != NULL_TREE)
8105 /* Variable offset. */
8106 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8107 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8112 /* We cannot address anything not on a unit boundary. */
8113 if (bitpos % BITS_PER_UNIT != 0)
8118 if (bitpos % BITS_PER_UNIT != 0
8119 || bitsize % BITS_PER_UNIT != 0)
8121 /* ??? We could handle this by loading and shifting etc.
8122 Wait until someone needs it before expending the effort. */
8126 indirect_size = bitsize / BITS_PER_UNIT;
8129 bytepos = bitpos / BITS_PER_UNIT;
8131 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8132 else if (bytepos < 0)
8134 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8135 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8141 if (host_integerp (loc, 0))
8142 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8154 case TRUNC_DIV_EXPR:
8160 case TRUNC_MOD_EXPR:
8170 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8173 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8174 && host_integerp (TREE_OPERAND (loc, 1), 0))
8176 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8177 add_loc_descr (&ret,
8178 new_loc_descr (DW_OP_plus_uconst,
8179 tree_low_cst (TREE_OPERAND (loc, 1),
8187 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8192 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8197 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8202 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8214 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8215 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
8216 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8230 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8231 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8235 loc = build (COND_EXPR, TREE_TYPE (loc),
8236 build (LT_EXPR, integer_type_node,
8237 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8238 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8243 dw_loc_descr_ref bra_node, jump_node, tmp;
8245 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8246 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8247 add_loc_descr (&ret, bra_node);
8249 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8250 add_loc_descr (&ret, tmp);
8251 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8252 add_loc_descr (&ret, jump_node);
8254 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8255 add_loc_descr (&ret, tmp);
8256 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8257 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
8259 /* ??? Need a node to point the skip at. Use a nop. */
8260 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8261 add_loc_descr (&ret, tmp);
8262 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8263 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8271 /* If we can't fill the request for an address, die. */
8272 if (addressp && indirect_size == 0)
8275 /* If we've got an address and don't want one, dereference. */
8276 if (!addressp && indirect_size > 0)
8278 if (indirect_size > DWARF2_ADDR_SIZE)
8280 if (indirect_size == DWARF2_ADDR_SIZE)
8283 op = DW_OP_deref_size;
8284 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
8290 /* Given a value, round it up to the lowest multiple of `boundary'
8291 which is not less than the value itself. */
8293 static inline HOST_WIDE_INT
8294 ceiling (value, boundary)
8295 HOST_WIDE_INT value;
8296 unsigned int boundary;
8298 return (((value + boundary - 1) / boundary) * boundary);
8301 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8302 pointer to the declared type for the relevant field variable, or return
8303 `integer_type_node' if the given node turns out to be an
8312 if (TREE_CODE (decl) == ERROR_MARK)
8313 return integer_type_node;
8315 type = DECL_BIT_FIELD_TYPE (decl);
8316 if (type == NULL_TREE)
8317 type = TREE_TYPE (decl);
8322 /* Given a pointer to a tree node, return the alignment in bits for
8323 it, or else return BITS_PER_WORD if the node actually turns out to
8324 be an ERROR_MARK node. */
8326 static inline unsigned
8327 simple_type_align_in_bits (type)
8330 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8333 static inline unsigned
8334 simple_decl_align_in_bits (decl)
8337 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8340 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8341 node, return the size in bits for the type if it is a constant, or else
8342 return the alignment for the type if the type's size is not constant, or
8343 else return BITS_PER_WORD if the type actually turns out to be an
8346 static inline unsigned HOST_WIDE_INT
8347 simple_type_size_in_bits (type)
8350 tree type_size_tree;
8352 if (TREE_CODE (type) == ERROR_MARK)
8353 return BITS_PER_WORD;
8354 type_size_tree = TYPE_SIZE (type);
8356 if (type_size_tree == NULL_TREE)
8358 if (! host_integerp (type_size_tree, 1))
8359 return TYPE_ALIGN (type);
8360 return tree_low_cst (type_size_tree, 1);
8363 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
8364 return the byte offset of the lowest addressed byte of the "containing
8365 object" for the given FIELD_DECL, or return 0 if we are unable to
8366 determine what that offset is, either because the argument turns out to
8367 be a pointer to an ERROR_MARK node, or because the offset is actually
8368 variable. (We can't handle the latter case just yet). */
8370 static HOST_WIDE_INT
8371 field_byte_offset (decl)
8374 unsigned int type_align_in_bits;
8375 unsigned int decl_align_in_bits;
8376 unsigned HOST_WIDE_INT type_size_in_bits;
8377 HOST_WIDE_INT object_offset_in_bits;
8378 HOST_WIDE_INT object_offset_in_bytes;
8380 tree field_size_tree;
8381 HOST_WIDE_INT bitpos_int;
8382 HOST_WIDE_INT deepest_bitpos;
8383 unsigned HOST_WIDE_INT field_size_in_bits;
8385 if (TREE_CODE (decl) == ERROR_MARK)
8388 if (TREE_CODE (decl) != FIELD_DECL)
8391 type = field_type (decl);
8392 field_size_tree = DECL_SIZE (decl);
8394 /* The size could be unspecified if there was an error, or for
8395 a flexible array member. */
8396 if (! field_size_tree)
8397 field_size_tree = bitsize_zero_node;
8399 /* We cannot yet cope with fields whose positions are variable, so
8400 for now, when we see such things, we simply return 0. Someday, we may
8401 be able to handle such cases, but it will be damn difficult. */
8402 if (! host_integerp (bit_position (decl), 0))
8405 bitpos_int = int_bit_position (decl);
8407 /* If we don't know the size of the field, pretend it's a full word. */
8408 if (host_integerp (field_size_tree, 1))
8409 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8411 field_size_in_bits = BITS_PER_WORD;
8413 type_size_in_bits = simple_type_size_in_bits (type);
8414 type_align_in_bits = simple_type_align_in_bits (type);
8415 decl_align_in_bits = simple_decl_align_in_bits (decl);
8417 /* Note that the GCC front-end doesn't make any attempt to keep track of
8418 the starting bit offset (relative to the start of the containing
8419 structure type) of the hypothetical "containing object" for a bit-
8420 field. Thus, when computing the byte offset value for the start of the
8421 "containing object" of a bit-field, we must deduce this information on
8422 our own. This can be rather tricky to do in some cases. For example,
8423 handling the following structure type definition when compiling for an
8424 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8427 struct S { int field1; long long field2:31; };
8429 Fortunately, there is a simple rule-of-thumb which can be
8430 used in such cases. When compiling for an i386/i486, GCC will allocate
8431 8 bytes for the structure shown above. It decides to do this based upon
8432 one simple rule for bit-field allocation. Quite simply, GCC allocates
8433 each "containing object" for each bit-field at the first (i.e. lowest
8434 addressed) legitimate alignment boundary (based upon the required
8435 minimum alignment for the declared type of the field) which it can
8436 possibly use, subject to the condition that there is still enough
8437 available space remaining in the containing object (when allocated at
8438 the selected point) to fully accommodate all of the bits of the
8439 bit-field itself. This simple rule makes it obvious why GCC allocates
8440 8 bytes for each object of the structure type shown above. When looking
8441 for a place to allocate the "containing object" for `field2', the
8442 compiler simply tries to allocate a 64-bit "containing object" at each
8443 successive 32-bit boundary (starting at zero) until it finds a place to
8444 allocate that 64- bit field such that at least 31 contiguous (and
8445 previously unallocated) bits remain within that selected 64 bit field.
8446 (As it turns out, for the example above, the compiler finds that it is
8447 OK to allocate the "containing object" 64-bit field at bit-offset zero
8448 within the structure type.) Here we attempt to work backwards from the
8449 limited set of facts we're given, and we try to deduce from those facts,
8450 where GCC must have believed that the containing object started (within
8451 the structure type). The value we deduce is then used (by the callers of
8452 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8453 for fields (both bit-fields and, in the case of DW_AT_location, regular
8456 /* Figure out the bit-distance from the start of the structure to the
8457 "deepest" bit of the bit-field. */
8458 deepest_bitpos = bitpos_int + field_size_in_bits;
8460 /* This is the tricky part. Use some fancy footwork to deduce where the
8461 lowest addressed bit of the containing object must be. */
8462 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8464 /* Round up to type_align by default. This works best for bitfields. */
8465 object_offset_in_bits += type_align_in_bits - 1;
8466 object_offset_in_bits /= type_align_in_bits;
8467 object_offset_in_bits *= type_align_in_bits;
8469 if (object_offset_in_bits > bitpos_int)
8471 /* Sigh, the decl must be packed. */
8472 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8474 /* Round up to decl_align instead. */
8475 object_offset_in_bits += decl_align_in_bits - 1;
8476 object_offset_in_bits /= decl_align_in_bits;
8477 object_offset_in_bits *= decl_align_in_bits;
8480 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8482 return object_offset_in_bytes;
8485 /* The following routines define various Dwarf attributes and any data
8486 associated with them. */
8488 /* Add a location description attribute value to a DIE.
8490 This emits location attributes suitable for whole variables and
8491 whole parameters. Note that the location attributes for struct fields are
8492 generated by the routine `data_member_location_attribute' below. */
8495 add_AT_location_description (die, attr_kind, rtl)
8497 enum dwarf_attribute attr_kind;
8500 /* Handle a special case. If we are about to output a location descriptor
8501 for a variable or parameter which has been optimized out of existence,
8502 don't do that. A variable which has been optimized out
8503 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8504 Currently, in some rare cases, variables can have DECL_RTL values which
8505 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8506 elsewhere in the compiler. We treat such cases as if the variable(s) in
8507 question had been optimized out of existence. */
8509 if (is_pseudo_reg (rtl)
8510 || (GET_CODE (rtl) == MEM
8511 && is_pseudo_reg (XEXP (rtl, 0)))
8512 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8513 references the internal argument pointer (a pseudo) in a function
8514 where all references to the internal argument pointer were
8515 eliminated via the optimizers. */
8516 || (GET_CODE (rtl) == MEM
8517 && GET_CODE (XEXP (rtl, 0)) == PLUS
8518 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8519 || (GET_CODE (rtl) == CONCAT
8520 && is_pseudo_reg (XEXP (rtl, 0))
8521 && is_pseudo_reg (XEXP (rtl, 1))))
8524 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8527 /* Attach the specialized form of location attribute used for data
8528 members of struct and union types. In the special case of a
8529 FIELD_DECL node which represents a bit-field, the "offset" part
8530 of this special location descriptor must indicate the distance
8531 in bytes from the lowest-addressed byte of the containing struct
8532 or union type to the lowest-addressed byte of the "containing
8533 object" for the bit-field. (See the `field_byte_offset' function
8534 above).. For any given bit-field, the "containing object" is a
8535 hypothetical object (of some integral or enum type) within which
8536 the given bit-field lives. The type of this hypothetical
8537 "containing object" is always the same as the declared type of
8538 the individual bit-field itself (for GCC anyway... the DWARF
8539 spec doesn't actually mandate this). Note that it is the size
8540 (in bytes) of the hypothetical "containing object" which will
8541 be given in the DW_AT_byte_size attribute for this bit-field.
8542 (See the `byte_size_attribute' function below.) It is also used
8543 when calculating the value of the DW_AT_bit_offset attribute.
8544 (See the `bit_offset_attribute' function below). */
8547 add_data_member_location_attribute (die, decl)
8548 register dw_die_ref die;
8551 register unsigned long offset;
8552 register dw_loc_descr_ref loc_descr;
8553 register enum dwarf_location_atom op;
8555 if (TREE_CODE (decl) == TREE_VEC)
8556 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8558 offset = field_byte_offset (decl);
8560 /* The DWARF2 standard says that we should assume that the structure address
8561 is already on the stack, so we can specify a structure field address
8562 by using DW_OP_plus_uconst. */
8564 #ifdef MIPS_DEBUGGING_INFO
8565 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8566 correctly. It works only if we leave the offset on the stack. */
8569 op = DW_OP_plus_uconst;
8572 loc_descr = new_loc_descr (op, offset, 0);
8573 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8576 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8577 does not have a "location" either in memory or in a register. These
8578 things can arise in GNU C when a constant is passed as an actual parameter
8579 to an inlined function. They can also arise in C++ where declared
8580 constants do not necessarily get memory "homes". */
8583 add_const_value_attribute (die, rtl)
8584 register dw_die_ref die;
8587 switch (GET_CODE (rtl))
8590 /* Note that a CONST_INT rtx could represent either an integer or a
8591 floating-point constant. A CONST_INT is used whenever the constant
8592 will fit into a single word. In all such cases, the original mode
8593 of the constant value is wiped out, and the CONST_INT rtx is
8594 assigned VOIDmode. */
8595 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
8599 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8600 floating-point constant. A CONST_DOUBLE is used whenever the
8601 constant requires more than one word in order to be adequately
8602 represented. We output CONST_DOUBLEs as blocks. */
8604 register enum machine_mode mode = GET_MODE (rtl);
8606 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8608 register unsigned length = GET_MODE_SIZE (mode) / 4;
8609 long *array = (long *) xmalloc (sizeof (long) * length);
8612 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8616 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8620 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8625 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8632 add_AT_float (die, DW_AT_const_value, length, array);
8635 add_AT_long_long (die, DW_AT_const_value,
8636 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8641 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8647 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8651 /* In cases where an inlined instance of an inline function is passed
8652 the address of an `auto' variable (which is local to the caller) we
8653 can get a situation where the DECL_RTL of the artificial local
8654 variable (for the inlining) which acts as a stand-in for the
8655 corresponding formal parameter (of the inline function) will look
8656 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8657 exactly a compile-time constant expression, but it isn't the address
8658 of the (artificial) local variable either. Rather, it represents the
8659 *value* which the artificial local variable always has during its
8660 lifetime. We currently have no way to represent such quasi-constant
8661 values in Dwarf, so for now we just punt and generate nothing. */
8665 /* No other kinds of rtx should be possible here. */
8672 rtl_for_decl_location (decl)
8677 /* Here we have to decide where we are going to say the parameter "lives"
8678 (as far as the debugger is concerned). We only have a couple of
8679 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8681 DECL_RTL normally indicates where the parameter lives during most of the
8682 activation of the function. If optimization is enabled however, this
8683 could be either NULL or else a pseudo-reg. Both of those cases indicate
8684 that the parameter doesn't really live anywhere (as far as the code
8685 generation parts of GCC are concerned) during most of the function's
8686 activation. That will happen (for example) if the parameter is never
8687 referenced within the function.
8689 We could just generate a location descriptor here for all non-NULL
8690 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8691 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8692 where DECL_RTL is NULL or is a pseudo-reg.
8694 Note however that we can only get away with using DECL_INCOMING_RTL as
8695 a backup substitute for DECL_RTL in certain limited cases. In cases
8696 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8697 we can be sure that the parameter was passed using the same type as it is
8698 declared to have within the function, and that its DECL_INCOMING_RTL
8699 points us to a place where a value of that type is passed.
8701 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8702 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8703 because in these cases DECL_INCOMING_RTL points us to a value of some
8704 type which is *different* from the type of the parameter itself. Thus,
8705 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8706 such cases, the debugger would end up (for example) trying to fetch a
8707 `float' from a place which actually contains the first part of a
8708 `double'. That would lead to really incorrect and confusing
8709 output at debug-time.
8711 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8712 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8713 are a couple of exceptions however. On little-endian machines we can
8714 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8715 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8716 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8717 when (on a little-endian machine) a non-prototyped function has a
8718 parameter declared to be of type `short' or `char'. In such cases,
8719 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8720 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8721 passed `int' value. If the debugger then uses that address to fetch
8722 a `short' or a `char' (on a little-endian machine) the result will be
8723 the correct data, so we allow for such exceptional cases below.
8725 Note that our goal here is to describe the place where the given formal
8726 parameter lives during most of the function's activation (i.e. between
8727 the end of the prologue and the start of the epilogue). We'll do that
8728 as best as we can. Note however that if the given formal parameter is
8729 modified sometime during the execution of the function, then a stack
8730 backtrace (at debug-time) will show the function as having been
8731 called with the *new* value rather than the value which was
8732 originally passed in. This happens rarely enough that it is not
8733 a major problem, but it *is* a problem, and I'd like to fix it.
8735 A future version of dwarf2out.c may generate two additional
8736 attributes for any given DW_TAG_formal_parameter DIE which will
8737 describe the "passed type" and the "passed location" for the
8738 given formal parameter in addition to the attributes we now
8739 generate to indicate the "declared type" and the "active
8740 location" for each parameter. This additional set of attributes
8741 could be used by debuggers for stack backtraces. Separately, note
8742 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8743 NULL also. This happens (for example) for inlined-instances of
8744 inline function formal parameters which are never referenced.
8745 This really shouldn't be happening. All PARM_DECL nodes should
8746 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8747 doesn't currently generate these values for inlined instances of
8748 inline function parameters, so when we see such cases, we are
8749 just out-of-luck for the time being (until integrate.c
8752 /* Use DECL_RTL as the "location" unless we find something better. */
8753 rtl = DECL_RTL (decl);
8755 if (TREE_CODE (decl) == PARM_DECL)
8757 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8759 tree declared_type = type_main_variant (TREE_TYPE (decl));
8760 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8762 /* This decl represents a formal parameter which was optimized out.
8763 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8764 all* cases where (rtl == NULL_RTX) just below. */
8765 if (declared_type == passed_type)
8766 rtl = DECL_INCOMING_RTL (decl);
8767 else if (! BYTES_BIG_ENDIAN
8768 && TREE_CODE (declared_type) == INTEGER_TYPE
8769 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8770 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8771 rtl = DECL_INCOMING_RTL (decl);
8774 /* If the parm was passed in registers, but lives on the stack, then
8775 make a big endian correction if the mode of the type of the
8776 parameter is not the same as the mode of the rtl. */
8777 /* ??? This is the same series of checks that are made in dbxout.c before
8778 we reach the big endian correction code there. It isn't clear if all
8779 of these checks are necessary here, but keeping them all is the safe
8781 else if (GET_CODE (rtl) == MEM
8782 && XEXP (rtl, 0) != const0_rtx
8783 && ! CONSTANT_P (XEXP (rtl, 0))
8784 /* Not passed in memory. */
8785 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8786 /* Not passed by invisible reference. */
8787 && (GET_CODE (XEXP (rtl, 0)) != REG
8788 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8789 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8790 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8791 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8794 /* Big endian correction check. */
8796 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8797 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8800 int offset = (UNITS_PER_WORD
8801 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8802 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8803 plus_constant (XEXP (rtl, 0), offset));
8807 if (rtl != NULL_RTX)
8809 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8810 #ifdef LEAF_REG_REMAP
8811 if (current_function_uses_only_leaf_regs)
8812 leaf_renumber_regs_insn (rtl);
8819 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8820 data attribute for a variable or a parameter. We generate the
8821 DW_AT_const_value attribute only in those cases where the given variable
8822 or parameter does not have a true "location" either in memory or in a
8823 register. This can happen (for example) when a constant is passed as an
8824 actual argument in a call to an inline function. (It's possible that
8825 these things can crop up in other ways also.) Note that one type of
8826 constant value which can be passed into an inlined function is a constant
8827 pointer. This can happen for example if an actual argument in an inlined
8828 function call evaluates to a compile-time constant address. */
8831 add_location_or_const_value_attribute (die, decl)
8832 register dw_die_ref die;
8837 if (TREE_CODE (decl) == ERROR_MARK)
8840 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8843 rtl = rtl_for_decl_location (decl);
8844 if (rtl == NULL_RTX)
8847 switch (GET_CODE (rtl))
8850 /* The address of a variable that was optimized away; don't emit
8861 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8862 add_const_value_attribute (die, rtl);
8869 add_AT_location_description (die, DW_AT_location, rtl);
8877 /* If we don't have a copy of this variable in memory for some reason (such
8878 as a C++ member constant that doesn't have an out-of-line definition),
8879 we should tell the debugger about the constant value. */
8882 tree_add_const_value_attribute (var_die, decl)
8886 tree init = DECL_INITIAL (decl);
8887 tree type = TREE_TYPE (decl);
8889 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8890 && initializer_constant_valid_p (init, type) == null_pointer_node)
8895 switch (TREE_CODE (type))
8898 if (host_integerp (init, 0))
8899 add_AT_unsigned (var_die, DW_AT_const_value,
8900 TREE_INT_CST_LOW (init));
8902 add_AT_long_long (var_die, DW_AT_const_value,
8903 TREE_INT_CST_HIGH (init),
8904 TREE_INT_CST_LOW (init));
8911 /* Generate an DW_AT_name attribute given some string value to be included as
8912 the value of the attribute. */
8915 add_name_attribute (die, name_string)
8916 register dw_die_ref die;
8917 register const char *name_string;
8919 if (name_string != NULL && *name_string != 0)
8921 if (demangle_name_func)
8922 name_string = (*demangle_name_func) (name_string);
8924 add_AT_string (die, DW_AT_name, name_string);
8928 /* Given a tree node describing an array bound (either lower or upper) output
8929 a representation for that bound. */
8932 add_bound_info (subrange_die, bound_attr, bound)
8933 register dw_die_ref subrange_die;
8934 register enum dwarf_attribute bound_attr;
8935 register tree bound;
8937 /* If this is an Ada unconstrained array type, then don't emit any debug
8938 info because the array bounds are unknown. They are parameterized when
8939 the type is instantiated. */
8940 if (contains_placeholder_p (bound))
8943 switch (TREE_CODE (bound))
8948 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8950 if (! host_integerp (bound, 0)
8951 || (bound_attr == DW_AT_lower_bound
8952 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8953 || (is_fortran () && integer_onep (bound)))))
8954 /* use the default */
8957 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8962 case NON_LVALUE_EXPR:
8963 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8967 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8968 access the upper bound values may be bogus. If they refer to a
8969 register, they may only describe how to get at these values at the
8970 points in the generated code right after they have just been
8971 computed. Worse yet, in the typical case, the upper bound values
8972 will not even *be* computed in the optimized code (though the
8973 number of elements will), so these SAVE_EXPRs are entirely
8974 bogus. In order to compensate for this fact, we check here to see
8975 if optimization is enabled, and if so, we don't add an attribute
8976 for the (unknown and unknowable) upper bound. This should not
8977 cause too much trouble for existing (stupid?) debuggers because
8978 they have to deal with empty upper bounds location descriptions
8979 anyway in order to be able to deal with incomplete array types.
8980 Of course an intelligent debugger (GDB?) should be able to
8981 comprehend that a missing upper bound specification in a array
8982 type used for a storage class `auto' local array variable
8983 indicates that the upper bound is both unknown (at compile- time)
8984 and unknowable (at run-time) due to optimization.
8986 We assume that a MEM rtx is safe because gcc wouldn't put the
8987 value there unless it was going to be used repeatedly in the
8988 function, i.e. for cleanups. */
8989 if (! optimize || (SAVE_EXPR_RTL (bound)
8990 && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8992 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8993 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8994 register rtx loc = SAVE_EXPR_RTL (bound);
8996 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8997 it references an outer function's frame. */
8999 if (GET_CODE (loc) == MEM)
9001 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9003 if (XEXP (loc, 0) != new_addr)
9004 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9007 add_AT_flag (decl_die, DW_AT_artificial, 1);
9008 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9009 add_AT_location_description (decl_die, DW_AT_location, loc);
9010 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9013 /* Else leave out the attribute. */
9019 dw_die_ref decl_die = lookup_decl_die (bound);
9021 /* ??? Can this happen, or should the variable have been bound
9022 first? Probably it can, since I imagine that we try to create
9023 the types of parameters in the order in which they exist in
9024 the list, and won't have created a forward reference to a
9026 if (decl_die != NULL)
9027 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9033 /* Otherwise try to create a stack operation procedure to
9034 evaluate the value of the array bound. */
9036 dw_die_ref ctx, decl_die;
9037 dw_loc_descr_ref loc;
9039 loc = loc_descriptor_from_tree (bound, 0);
9043 ctx = lookup_decl_die (current_function_decl);
9045 decl_die = new_die (DW_TAG_variable, ctx);
9046 add_AT_flag (decl_die, DW_AT_artificial, 1);
9047 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9048 add_AT_loc (decl_die, DW_AT_location, loc);
9050 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9056 /* Note that the block of subscript information for an array type also
9057 includes information about the element type of type given array type. */
9060 add_subscript_info (type_die, type)
9061 register dw_die_ref type_die;
9064 #ifndef MIPS_DEBUGGING_INFO
9065 register unsigned dimension_number;
9067 register tree lower, upper;
9068 register dw_die_ref subrange_die;
9070 /* The GNU compilers represent multidimensional array types as sequences of
9071 one dimensional array types whose element types are themselves array
9072 types. Here we squish that down, so that each multidimensional array
9073 type gets only one array_type DIE in the Dwarf debugging info. The draft
9074 Dwarf specification say that we are allowed to do this kind of
9075 compression in C (because there is no difference between an array or
9076 arrays and a multidimensional array in C) but for other source languages
9077 (e.g. Ada) we probably shouldn't do this. */
9079 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9080 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9081 We work around this by disabling this feature. See also
9082 gen_array_type_die. */
9083 #ifndef MIPS_DEBUGGING_INFO
9084 for (dimension_number = 0;
9085 TREE_CODE (type) == ARRAY_TYPE;
9086 type = TREE_TYPE (type), dimension_number++)
9089 register tree domain = TYPE_DOMAIN (type);
9091 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9092 and (in GNU C only) variable bounds. Handle all three forms
9094 subrange_die = new_die (DW_TAG_subrange_type, type_die);
9097 /* We have an array type with specified bounds. */
9098 lower = TYPE_MIN_VALUE (domain);
9099 upper = TYPE_MAX_VALUE (domain);
9101 /* define the index type. */
9102 if (TREE_TYPE (domain))
9104 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9105 TREE_TYPE field. We can't emit debug info for this
9106 because it is an unnamed integral type. */
9107 if (TREE_CODE (domain) == INTEGER_TYPE
9108 && TYPE_NAME (domain) == NULL_TREE
9109 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9110 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9113 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9117 /* ??? If upper is NULL, the array has unspecified length,
9118 but it does have a lower bound. This happens with Fortran
9120 Since the debugger is definitely going to need to know N
9121 to produce useful results, go ahead and output the lower
9122 bound solo, and hope the debugger can cope. */
9124 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9126 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9129 /* We have an array type with an unspecified length. The DWARF-2
9130 spec does not say how to handle this; let's just leave out the
9134 #ifndef MIPS_DEBUGGING_INFO
9140 add_byte_size_attribute (die, tree_node)
9142 register tree tree_node;
9144 register unsigned size;
9146 switch (TREE_CODE (tree_node))
9154 case QUAL_UNION_TYPE:
9155 size = int_size_in_bytes (tree_node);
9158 /* For a data member of a struct or union, the DW_AT_byte_size is
9159 generally given as the number of bytes normally allocated for an
9160 object of the *declared* type of the member itself. This is true
9161 even for bit-fields. */
9162 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9168 /* Note that `size' might be -1 when we get to this point. If it is, that
9169 indicates that the byte size of the entity in question is variable. We
9170 have no good way of expressing this fact in Dwarf at the present time,
9171 so just let the -1 pass on through. */
9173 add_AT_unsigned (die, DW_AT_byte_size, size);
9176 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9177 which specifies the distance in bits from the highest order bit of the
9178 "containing object" for the bit-field to the highest order bit of the
9181 For any given bit-field, the "containing object" is a hypothetical
9182 object (of some integral or enum type) within which the given bit-field
9183 lives. The type of this hypothetical "containing object" is always the
9184 same as the declared type of the individual bit-field itself. The
9185 determination of the exact location of the "containing object" for a
9186 bit-field is rather complicated. It's handled by the
9187 `field_byte_offset' function (above).
9189 Note that it is the size (in bytes) of the hypothetical "containing object"
9190 which will be given in the DW_AT_byte_size attribute for this bit-field.
9191 (See `byte_size_attribute' above). */
9194 add_bit_offset_attribute (die, decl)
9195 register dw_die_ref die;
9198 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9199 tree type = DECL_BIT_FIELD_TYPE (decl);
9200 HOST_WIDE_INT bitpos_int;
9201 HOST_WIDE_INT highest_order_object_bit_offset;
9202 HOST_WIDE_INT highest_order_field_bit_offset;
9203 HOST_WIDE_INT unsigned bit_offset;
9205 /* Must be a field and a bit field. */
9207 || TREE_CODE (decl) != FIELD_DECL)
9210 /* We can't yet handle bit-fields whose offsets are variable, so if we
9211 encounter such things, just return without generating any attribute
9212 whatsoever. Likewise for variable or too large size. */
9213 if (! host_integerp (bit_position (decl), 0)
9214 || ! host_integerp (DECL_SIZE (decl), 1))
9217 bitpos_int = int_bit_position (decl);
9219 /* Note that the bit offset is always the distance (in bits) from the
9220 highest-order bit of the "containing object" to the highest-order bit of
9221 the bit-field itself. Since the "high-order end" of any object or field
9222 is different on big-endian and little-endian machines, the computation
9223 below must take account of these differences. */
9224 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9225 highest_order_field_bit_offset = bitpos_int;
9227 if (! BYTES_BIG_ENDIAN)
9229 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9230 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9234 = (! BYTES_BIG_ENDIAN
9235 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9236 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9238 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9241 /* For a FIELD_DECL node which represents a bit field, output an attribute
9242 which specifies the length in bits of the given field. */
9245 add_bit_size_attribute (die, decl)
9246 register dw_die_ref die;
9249 /* Must be a field and a bit field. */
9250 if (TREE_CODE (decl) != FIELD_DECL
9251 || ! DECL_BIT_FIELD_TYPE (decl))
9254 if (host_integerp (DECL_SIZE (decl), 1))
9255 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9258 /* If the compiled language is ANSI C, then add a 'prototyped'
9259 attribute, if arg types are given for the parameters of a function. */
9262 add_prototyped_attribute (die, func_type)
9263 register dw_die_ref die;
9264 register tree func_type;
9266 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9267 && TYPE_ARG_TYPES (func_type) != NULL)
9268 add_AT_flag (die, DW_AT_prototyped, 1);
9271 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9272 by looking in either the type declaration or object declaration
9276 add_abstract_origin_attribute (die, origin)
9277 register dw_die_ref die;
9278 register tree origin;
9280 dw_die_ref origin_die = NULL;
9282 if (TREE_CODE (origin) != FUNCTION_DECL)
9284 /* We may have gotten separated from the block for the inlined
9285 function, if we're in an exception handler or some such; make
9286 sure that the abstract function has been written out.
9288 Doing this for nested functions is wrong, however; functions are
9289 distinct units, and our context might not even be inline. */
9292 fn = TYPE_STUB_DECL (fn);
9293 fn = decl_function_context (fn);
9295 gen_abstract_function (fn);
9298 if (DECL_P (origin))
9299 origin_die = lookup_decl_die (origin);
9300 else if (TYPE_P (origin))
9301 origin_die = lookup_type_die (origin);
9303 if (origin_die == NULL)
9306 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9309 /* We do not currently support the pure_virtual attribute. */
9312 add_pure_or_virtual_attribute (die, func_decl)
9313 register dw_die_ref die;
9314 register tree func_decl;
9316 if (DECL_VINDEX (func_decl))
9318 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9320 if (host_integerp (DECL_VINDEX (func_decl), 0))
9321 add_AT_loc (die, DW_AT_vtable_elem_location,
9322 new_loc_descr (DW_OP_constu,
9323 tree_low_cst (DECL_VINDEX (func_decl), 0),
9326 /* GNU extension: Record what type this method came from originally. */
9327 if (debug_info_level > DINFO_LEVEL_TERSE)
9328 add_AT_die_ref (die, DW_AT_containing_type,
9329 lookup_type_die (DECL_CONTEXT (func_decl)));
9333 /* Add source coordinate attributes for the given decl. */
9336 add_src_coords_attributes (die, decl)
9337 register dw_die_ref die;
9340 register unsigned file_index = lookup_filename (&decl_file_table,
9341 DECL_SOURCE_FILE (decl));
9343 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9344 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9347 /* Add an DW_AT_name attribute and source coordinate attribute for the
9348 given decl, but only if it actually has a name. */
9351 add_name_and_src_coords_attributes (die, decl)
9352 register dw_die_ref die;
9355 register tree decl_name;
9357 decl_name = DECL_NAME (decl);
9358 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9360 add_name_attribute (die, dwarf2_name (decl, 0));
9361 if (! DECL_ARTIFICIAL (decl))
9362 add_src_coords_attributes (die, decl);
9364 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9365 && TREE_PUBLIC (decl)
9366 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
9367 add_AT_string (die, DW_AT_MIPS_linkage_name,
9368 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9372 /* Push a new declaration scope. */
9375 push_decl_scope (scope)
9378 /* Make room in the decl_scope_table, if necessary. */
9379 if (decl_scope_table_allocated == decl_scope_depth)
9381 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
9383 = (tree *) xrealloc (decl_scope_table,
9384 decl_scope_table_allocated * sizeof (tree));
9387 decl_scope_table[decl_scope_depth] = scope;
9391 /* Pop a declaration scope. */
9395 if (decl_scope_depth <= 0)
9400 /* Return the DIE for the scope that immediately contains this type.
9401 Non-named types get global scope. Named types nested in other
9402 types get their containing scope if it's open, or global scope
9403 otherwise. All other types (i.e. function-local named types) get
9404 the current active scope. */
9407 scope_die_for (t, context_die)
9409 register dw_die_ref context_die;
9411 register dw_die_ref scope_die = NULL;
9412 register tree containing_scope;
9415 /* Non-types always go in the current scope. */
9419 containing_scope = TYPE_CONTEXT (t);
9421 /* Ignore namespaces for the moment. */
9422 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9423 containing_scope = NULL_TREE;
9425 /* Ignore function type "scopes" from the C frontend. They mean that
9426 a tagged type is local to a parmlist of a function declarator, but
9427 that isn't useful to DWARF. */
9428 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9429 containing_scope = NULL_TREE;
9431 if (containing_scope == NULL_TREE)
9432 scope_die = comp_unit_die;
9433 else if (TYPE_P (containing_scope))
9435 /* For types, we can just look up the appropriate DIE. But
9436 first we check to see if we're in the middle of emitting it
9437 so we know where the new DIE should go. */
9439 for (i = decl_scope_depth - 1; i >= 0; --i)
9440 if (decl_scope_table[i] == containing_scope)
9445 if (debug_info_level > DINFO_LEVEL_TERSE
9446 && !TREE_ASM_WRITTEN (containing_scope))
9449 /* If none of the current dies are suitable, we get file scope. */
9450 scope_die = comp_unit_die;
9453 scope_die = lookup_type_die (containing_scope);
9456 scope_die = context_die;
9461 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9463 static inline int local_scope_p PARAMS ((dw_die_ref));
9465 local_scope_p (context_die)
9466 dw_die_ref context_die;
9468 for (; context_die; context_die = context_die->die_parent)
9469 if (context_die->die_tag == DW_TAG_inlined_subroutine
9470 || context_die->die_tag == DW_TAG_subprogram)
9475 /* Returns nonzero iff CONTEXT_DIE is a class. */
9477 static inline int class_scope_p PARAMS ((dw_die_ref));
9479 class_scope_p (context_die)
9480 dw_die_ref context_die;
9483 && (context_die->die_tag == DW_TAG_structure_type
9484 || context_die->die_tag == DW_TAG_union_type));
9487 /* Many forms of DIEs require a "type description" attribute. This
9488 routine locates the proper "type descriptor" die for the type given
9489 by 'type', and adds an DW_AT_type attribute below the given die. */
9492 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9493 register dw_die_ref object_die;
9495 register int decl_const;
9496 register int decl_volatile;
9497 register dw_die_ref context_die;
9499 register enum tree_code code = TREE_CODE (type);
9500 register dw_die_ref type_die = NULL;
9502 /* ??? If this type is an unnamed subrange type of an integral or
9503 floating-point type, use the inner type. This is because we have no
9504 support for unnamed types in base_type_die. This can happen if this is
9505 an Ada subrange type. Correct solution is emit a subrange type die. */
9506 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9507 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9508 type = TREE_TYPE (type), code = TREE_CODE (type);
9510 if (code == ERROR_MARK)
9513 /* Handle a special case. For functions whose return type is void, we
9514 generate *no* type attribute. (Note that no object may have type
9515 `void', so this only applies to function return types). */
9516 if (code == VOID_TYPE)
9519 type_die = modified_type_die (type,
9520 decl_const || TYPE_READONLY (type),
9521 decl_volatile || TYPE_VOLATILE (type),
9523 if (type_die != NULL)
9524 add_AT_die_ref (object_die, DW_AT_type, type_die);
9527 /* Given a tree pointer to a struct, class, union, or enum type node, return
9528 a pointer to the (string) tag name for the given type, or zero if the type
9529 was declared without a tag. */
9535 register const char *name = 0;
9537 if (TYPE_NAME (type) != 0)
9539 register tree t = 0;
9541 /* Find the IDENTIFIER_NODE for the type name. */
9542 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9543 t = TYPE_NAME (type);
9545 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9546 a TYPE_DECL node, regardless of whether or not a `typedef' was
9548 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9549 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9550 t = DECL_NAME (TYPE_NAME (type));
9552 /* Now get the name as a string, or invent one. */
9554 name = IDENTIFIER_POINTER (t);
9557 return (name == 0 || *name == '\0') ? 0 : name;
9560 /* Return the type associated with a data member, make a special check
9561 for bit field types. */
9564 member_declared_type (member)
9565 register tree member;
9567 return (DECL_BIT_FIELD_TYPE (member)
9568 ? DECL_BIT_FIELD_TYPE (member)
9569 : TREE_TYPE (member));
9572 /* Get the decl's label, as described by its RTL. This may be different
9573 from the DECL_NAME name used in the source file. */
9577 decl_start_label (decl)
9582 x = DECL_RTL (decl);
9583 if (GET_CODE (x) != MEM)
9587 if (GET_CODE (x) != SYMBOL_REF)
9590 fnname = XSTR (x, 0);
9595 /* These routines generate the internal representation of the DIE's for
9596 the compilation unit. Debugging information is collected by walking
9597 the declaration trees passed in from dwarf2out_decl(). */
9600 gen_array_type_die (type, context_die)
9602 register dw_die_ref context_die;
9604 register dw_die_ref scope_die = scope_die_for (type, context_die);
9605 register dw_die_ref array_die;
9606 register tree element_type;
9608 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9609 the inner array type comes before the outer array type. Thus we must
9610 call gen_type_die before we call new_die. See below also. */
9611 #ifdef MIPS_DEBUGGING_INFO
9612 gen_type_die (TREE_TYPE (type), context_die);
9615 array_die = new_die (DW_TAG_array_type, scope_die);
9618 /* We default the array ordering. SDB will probably do
9619 the right things even if DW_AT_ordering is not present. It's not even
9620 an issue until we start to get into multidimensional arrays anyway. If
9621 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9622 then we'll have to put the DW_AT_ordering attribute back in. (But if
9623 and when we find out that we need to put these in, we will only do so
9624 for multidimensional arrays. */
9625 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9628 #ifdef MIPS_DEBUGGING_INFO
9629 /* The SGI compilers handle arrays of unknown bound by setting
9630 AT_declaration and not emitting any subrange DIEs. */
9631 if (! TYPE_DOMAIN (type))
9632 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9635 add_subscript_info (array_die, type);
9637 add_name_attribute (array_die, type_tag (type));
9638 equate_type_number_to_die (type, array_die);
9640 /* Add representation of the type of the elements of this array type. */
9641 element_type = TREE_TYPE (type);
9643 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9644 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9645 We work around this by disabling this feature. See also
9646 add_subscript_info. */
9647 #ifndef MIPS_DEBUGGING_INFO
9648 while (TREE_CODE (element_type) == ARRAY_TYPE)
9649 element_type = TREE_TYPE (element_type);
9651 gen_type_die (element_type, context_die);
9654 add_type_attribute (array_die, element_type, 0, 0, context_die);
9658 gen_set_type_die (type, context_die)
9660 register dw_die_ref context_die;
9662 register dw_die_ref type_die
9663 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9665 equate_type_number_to_die (type, type_die);
9666 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9671 gen_entry_point_die (decl, context_die)
9673 register dw_die_ref context_die;
9675 register tree origin = decl_ultimate_origin (decl);
9676 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9678 add_abstract_origin_attribute (decl_die, origin);
9681 add_name_and_src_coords_attributes (decl_die, decl);
9682 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9686 if (DECL_ABSTRACT (decl))
9687 equate_decl_number_to_die (decl, decl_die);
9689 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9693 /* Remember a type in the incomplete_types_list. */
9696 add_incomplete_type (type)
9699 if (incomplete_types == incomplete_types_allocated)
9701 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9702 incomplete_types_list
9703 = (tree *) xrealloc (incomplete_types_list,
9704 sizeof (tree) * incomplete_types_allocated);
9707 incomplete_types_list[incomplete_types++] = type;
9710 /* Walk through the list of incomplete types again, trying once more to
9711 emit full debugging info for them. */
9714 retry_incomplete_types ()
9718 while (incomplete_types)
9721 type = incomplete_types_list[incomplete_types];
9722 gen_type_die (type, comp_unit_die);
9726 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9729 gen_inlined_enumeration_type_die (type, context_die)
9731 register dw_die_ref context_die;
9733 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9735 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9736 be incomplete and such types are not marked. */
9737 add_abstract_origin_attribute (type_die, type);
9740 /* Generate a DIE to represent an inlined instance of a structure type. */
9743 gen_inlined_structure_type_die (type, context_die)
9745 register dw_die_ref context_die;
9747 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9749 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9750 be incomplete and such types are not marked. */
9751 add_abstract_origin_attribute (type_die, type);
9754 /* Generate a DIE to represent an inlined instance of a union type. */
9757 gen_inlined_union_type_die (type, context_die)
9759 register dw_die_ref context_die;
9761 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9763 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9764 be incomplete and such types are not marked. */
9765 add_abstract_origin_attribute (type_die, type);
9768 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9769 include all of the information about the enumeration values also. Each
9770 enumerated type name/value is listed as a child of the enumerated type
9774 gen_enumeration_type_die (type, context_die)
9776 register dw_die_ref context_die;
9778 register dw_die_ref type_die = lookup_type_die (type);
9780 if (type_die == NULL)
9782 type_die = new_die (DW_TAG_enumeration_type,
9783 scope_die_for (type, context_die));
9784 equate_type_number_to_die (type, type_die);
9785 add_name_attribute (type_die, type_tag (type));
9787 else if (! TYPE_SIZE (type))
9790 remove_AT (type_die, DW_AT_declaration);
9792 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9793 given enum type is incomplete, do not generate the DW_AT_byte_size
9794 attribute or the DW_AT_element_list attribute. */
9795 if (TYPE_SIZE (type))
9799 TREE_ASM_WRITTEN (type) = 1;
9800 add_byte_size_attribute (type_die, type);
9801 if (TYPE_STUB_DECL (type) != NULL_TREE)
9802 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9804 /* If the first reference to this type was as the return type of an
9805 inline function, then it may not have a parent. Fix this now. */
9806 if (type_die->die_parent == NULL)
9807 add_child_die (scope_die_for (type, context_die), type_die);
9809 for (link = TYPE_FIELDS (type);
9810 link != NULL; link = TREE_CHAIN (link))
9812 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9814 add_name_attribute (enum_die,
9815 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9817 if (host_integerp (TREE_VALUE (link), 0))
9819 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9820 add_AT_int (enum_die, DW_AT_const_value,
9821 tree_low_cst (TREE_VALUE (link), 0));
9823 add_AT_unsigned (enum_die, DW_AT_const_value,
9824 tree_low_cst (TREE_VALUE (link), 0));
9829 add_AT_flag (type_die, DW_AT_declaration, 1);
9832 /* Generate a DIE to represent either a real live formal parameter decl or to
9833 represent just the type of some formal parameter position in some function
9836 Note that this routine is a bit unusual because its argument may be a
9837 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9838 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9839 node. If it's the former then this function is being called to output a
9840 DIE to represent a formal parameter object (or some inlining thereof). If
9841 it's the latter, then this function is only being called to output a
9842 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9843 argument type of some subprogram type. */
9846 gen_formal_parameter_die (node, context_die)
9848 register dw_die_ref context_die;
9850 register dw_die_ref parm_die
9851 = new_die (DW_TAG_formal_parameter, context_die);
9852 register tree origin;
9854 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9857 origin = decl_ultimate_origin (node);
9859 add_abstract_origin_attribute (parm_die, origin);
9862 add_name_and_src_coords_attributes (parm_die, node);
9863 add_type_attribute (parm_die, TREE_TYPE (node),
9864 TREE_READONLY (node),
9865 TREE_THIS_VOLATILE (node),
9867 if (DECL_ARTIFICIAL (node))
9868 add_AT_flag (parm_die, DW_AT_artificial, 1);
9871 equate_decl_number_to_die (node, parm_die);
9872 if (! DECL_ABSTRACT (node))
9873 add_location_or_const_value_attribute (parm_die, node);
9878 /* We were called with some kind of a ..._TYPE node. */
9879 add_type_attribute (parm_die, node, 0, 0, context_die);
9889 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9890 at the end of an (ANSI prototyped) formal parameters list. */
9893 gen_unspecified_parameters_die (decl_or_type, context_die)
9894 register tree decl_or_type ATTRIBUTE_UNUSED;
9895 register dw_die_ref context_die;
9897 new_die (DW_TAG_unspecified_parameters, context_die);
9900 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9901 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9902 parameters as specified in some function type specification (except for
9903 those which appear as part of a function *definition*). */
9906 gen_formal_types_die (function_or_method_type, context_die)
9907 register tree function_or_method_type;
9908 register dw_die_ref context_die;
9911 register tree formal_type = NULL;
9912 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9915 /* In the case where we are generating a formal types list for a C++
9916 non-static member function type, skip over the first thing on the
9917 TYPE_ARG_TYPES list because it only represents the type of the hidden
9918 `this pointer'. The debugger should be able to figure out (without
9919 being explicitly told) that this non-static member function type takes a
9920 `this pointer' and should be able to figure what the type of that hidden
9921 parameter is from the DW_AT_member attribute of the parent
9922 DW_TAG_subroutine_type DIE. */
9923 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
9924 first_parm_type = TREE_CHAIN (first_parm_type);
9927 /* Make our first pass over the list of formal parameter types and output a
9928 DW_TAG_formal_parameter DIE for each one. */
9929 for (link = first_parm_type; link; link = TREE_CHAIN (link))
9931 register dw_die_ref parm_die;
9933 formal_type = TREE_VALUE (link);
9934 if (formal_type == void_type_node)
9937 /* Output a (nameless) DIE to represent the formal parameter itself. */
9938 parm_die = gen_formal_parameter_die (formal_type, context_die);
9939 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
9940 && link == first_parm_type)
9941 add_AT_flag (parm_die, DW_AT_artificial, 1);
9944 /* If this function type has an ellipsis, add a
9945 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9946 if (formal_type != void_type_node)
9947 gen_unspecified_parameters_die (function_or_method_type, context_die);
9949 /* Make our second (and final) pass over the list of formal parameter types
9950 and output DIEs to represent those types (as necessary). */
9951 for (link = TYPE_ARG_TYPES (function_or_method_type);
9953 link = TREE_CHAIN (link))
9955 formal_type = TREE_VALUE (link);
9956 if (formal_type == void_type_node)
9959 gen_type_die (formal_type, context_die);
9963 /* We want to generate the DIE for TYPE so that we can generate the
9964 die for MEMBER, which has been defined; we will need to refer back
9965 to the member declaration nested within TYPE. If we're trying to
9966 generate minimal debug info for TYPE, processing TYPE won't do the
9967 trick; we need to attach the member declaration by hand. */
9970 gen_type_die_for_member (type, member, context_die)
9972 dw_die_ref context_die;
9974 gen_type_die (type, context_die);
9976 /* If we're trying to avoid duplicate debug info, we may not have
9977 emitted the member decl for this function. Emit it now. */
9978 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9979 && ! lookup_decl_die (member))
9981 if (decl_ultimate_origin (member))
9984 push_decl_scope (type);
9985 if (TREE_CODE (member) == FUNCTION_DECL)
9986 gen_subprogram_die (member, lookup_type_die (type));
9988 gen_variable_die (member, lookup_type_die (type));
9993 /* Generate the DWARF2 info for the "abstract" instance
9994 of a function which we may later generate inlined and/or
9995 out-of-line instances of. */
9998 gen_abstract_function (decl)
10001 register dw_die_ref old_die = lookup_decl_die (decl);
10004 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10005 /* We've already generated the abstract instance. */
10008 save_fn = current_function_decl;
10009 current_function_decl = decl;
10011 set_decl_abstract_flags (decl, 1);
10012 dwarf2out_decl (decl);
10013 set_decl_abstract_flags (decl, 0);
10015 current_function_decl = save_fn;
10018 /* Generate a DIE to represent a declared function (either file-scope or
10022 gen_subprogram_die (decl, context_die)
10023 register tree decl;
10024 register dw_die_ref context_die;
10026 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10027 register tree origin = decl_ultimate_origin (decl);
10028 register dw_die_ref subr_die;
10029 register rtx fp_reg;
10030 register tree fn_arg_types;
10031 register tree outer_scope;
10032 register dw_die_ref old_die = lookup_decl_die (decl);
10033 register int declaration = (current_function_decl != decl
10034 || class_scope_p (context_die));
10036 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
10037 be true, if we started to generate the abstract instance of an inline,
10038 decided to output its containing class, and proceeded to emit the
10039 declaration of the inline from the member list for the class. In that
10040 case, `declaration' takes priority; we'll get back to the abstract
10041 instance when we're done with the class. */
10043 /* The class-scope declaration DIE must be the primary DIE. */
10044 if (origin && declaration && class_scope_p (context_die))
10051 if (origin != NULL)
10053 if (declaration && ! local_scope_p (context_die))
10056 /* Fixup die_parent for the abstract instance of a nested
10057 inline function. */
10058 if (old_die && old_die->die_parent == NULL)
10059 add_child_die (context_die, old_die);
10061 subr_die = new_die (DW_TAG_subprogram, context_die);
10062 add_abstract_origin_attribute (subr_die, origin);
10064 else if (old_die && DECL_ABSTRACT (decl)
10065 && get_AT_unsigned (old_die, DW_AT_inline))
10067 /* This must be a redefinition of an extern inline function.
10068 We can just reuse the old die here. */
10069 subr_die = old_die;
10071 /* Clear out the inlined attribute and parm types. */
10072 remove_AT (subr_die, DW_AT_inline);
10073 remove_children (subr_die);
10077 register unsigned file_index
10078 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
10080 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
10082 /* ??? This can happen if there is a bug in the program, for
10083 instance, if it has duplicate function definitions. Ideally,
10084 we should detect this case and ignore it. For now, if we have
10085 already reported an error, any error at all, then assume that
10086 we got here because of a input error, not a dwarf2 bug. */
10092 /* If the definition comes from the same place as the declaration,
10093 maybe use the old DIE. We always want the DIE for this function
10094 that has the *_pc attributes to be under comp_unit_die so the
10095 debugger can find it. We also need to do this for abstract
10096 instances of inlines, since the spec requires the out-of-line copy
10097 to have the same parent. For local class methods, this doesn't
10098 apply; we just use the old DIE. */
10099 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10100 && (DECL_ARTIFICIAL (decl)
10101 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10102 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10103 == (unsigned) DECL_SOURCE_LINE (decl)))))
10105 subr_die = old_die;
10107 /* Clear out the declaration attribute and the parm types. */
10108 remove_AT (subr_die, DW_AT_declaration);
10109 remove_children (subr_die);
10113 subr_die = new_die (DW_TAG_subprogram, context_die);
10114 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10115 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10116 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10117 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10118 != (unsigned) DECL_SOURCE_LINE (decl))
10120 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10125 subr_die = new_die (DW_TAG_subprogram, context_die);
10127 if (TREE_PUBLIC (decl))
10128 add_AT_flag (subr_die, DW_AT_external, 1);
10130 add_name_and_src_coords_attributes (subr_die, decl);
10131 if (debug_info_level > DINFO_LEVEL_TERSE)
10133 register tree type = TREE_TYPE (decl);
10135 add_prototyped_attribute (subr_die, type);
10136 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
10139 add_pure_or_virtual_attribute (subr_die, decl);
10140 if (DECL_ARTIFICIAL (decl))
10141 add_AT_flag (subr_die, DW_AT_artificial, 1);
10142 if (TREE_PROTECTED (decl))
10143 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10144 else if (TREE_PRIVATE (decl))
10145 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10151 add_AT_flag (subr_die, DW_AT_declaration, 1);
10153 /* The first time we see a member function, it is in the context of
10154 the class to which it belongs. We make sure of this by emitting
10155 the class first. The next time is the definition, which is
10156 handled above. The two may come from the same source text. */
10157 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10158 equate_decl_number_to_die (decl, subr_die);
10160 else if (DECL_ABSTRACT (decl))
10162 if (DECL_INLINE (decl) && !flag_no_inline)
10164 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10165 inline functions, but not for extern inline functions.
10166 We can't get this completely correct because information
10167 about whether the function was declared inline is not
10169 if (DECL_DEFER_OUTPUT (decl))
10170 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10172 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10175 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10177 equate_decl_number_to_die (decl, subr_die);
10179 else if (!DECL_EXTERNAL (decl))
10181 if (origin == NULL_TREE)
10182 equate_decl_number_to_die (decl, subr_die);
10184 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10185 current_funcdef_number);
10186 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10187 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10188 current_funcdef_number);
10189 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10191 add_pubname (decl, subr_die);
10192 add_arange (decl, subr_die);
10194 #ifdef MIPS_DEBUGGING_INFO
10195 /* Add a reference to the FDE for this routine. */
10196 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10199 /* Define the "frame base" location for this routine. We use the
10200 frame pointer or stack pointer registers, since the RTL for local
10201 variables is relative to one of them. */
10203 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10204 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10207 /* ??? This fails for nested inline functions, because context_display
10208 is not part of the state saved/restored for inline functions. */
10209 if (current_function_needs_context)
10210 add_AT_location_description (subr_die, DW_AT_static_link,
10211 lookup_static_chain (decl));
10215 /* Now output descriptions of the arguments for this function. This gets
10216 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10217 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10218 `...' at the end of the formal parameter list. In order to find out if
10219 there was a trailing ellipsis or not, we must instead look at the type
10220 associated with the FUNCTION_DECL. This will be a node of type
10221 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10222 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10223 an ellipsis at the end. */
10225 /* In the case where we are describing a mere function declaration, all we
10226 need to do here (and all we *can* do here) is to describe the *types* of
10227 its formal parameters. */
10228 if (debug_info_level <= DINFO_LEVEL_TERSE)
10230 else if (declaration)
10231 gen_formal_types_die (TREE_TYPE (decl), subr_die);
10234 /* Generate DIEs to represent all known formal parameters */
10235 register tree arg_decls = DECL_ARGUMENTS (decl);
10236 register tree parm;
10238 /* When generating DIEs, generate the unspecified_parameters DIE
10239 instead if we come across the arg "__builtin_va_alist" */
10240 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10241 if (TREE_CODE (parm) == PARM_DECL)
10243 if (DECL_NAME (parm)
10244 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10245 "__builtin_va_alist"))
10246 gen_unspecified_parameters_die (parm, subr_die);
10248 gen_decl_die (parm, subr_die);
10251 /* Decide whether we need a unspecified_parameters DIE at the end.
10252 There are 2 more cases to do this for: 1) the ansi ... declaration -
10253 this is detectable when the end of the arg list is not a
10254 void_type_node 2) an unprototyped function declaration (not a
10255 definition). This just means that we have no info about the
10256 parameters at all. */
10257 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10258 if (fn_arg_types != NULL)
10260 /* this is the prototyped case, check for ... */
10261 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10262 gen_unspecified_parameters_die (decl, subr_die);
10264 else if (DECL_INITIAL (decl) == NULL_TREE)
10265 gen_unspecified_parameters_die (decl, subr_die);
10268 /* Output Dwarf info for all of the stuff within the body of the function
10269 (if it has one - it may be just a declaration). */
10270 outer_scope = DECL_INITIAL (decl);
10272 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
10273 node created to represent a function. This outermost BLOCK actually
10274 represents the outermost binding contour for the function, i.e. the
10275 contour in which the function's formal parameters and labels get
10276 declared. Curiously, it appears that the front end doesn't actually
10277 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
10278 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
10279 list for the function instead.) The BLOCK_VARS list for the
10280 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
10281 the function however, and we output DWARF info for those in
10282 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
10283 node representing the function's outermost pair of curly braces, and
10284 any blocks used for the base and member initializers of a C++
10285 constructor function. */
10286 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10288 current_function_has_inlines = 0;
10289 decls_for_scope (outer_scope, subr_die, 0);
10291 #if 0 && defined (MIPS_DEBUGGING_INFO)
10292 if (current_function_has_inlines)
10294 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10295 if (! comp_unit_has_inlines)
10297 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10298 comp_unit_has_inlines = 1;
10305 /* Generate a DIE to represent a declared data object. */
10308 gen_variable_die (decl, context_die)
10309 register tree decl;
10310 register dw_die_ref context_die;
10312 register tree origin = decl_ultimate_origin (decl);
10313 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
10315 dw_die_ref old_die = lookup_decl_die (decl);
10316 int declaration = (DECL_EXTERNAL (decl)
10317 || class_scope_p (context_die));
10319 if (origin != NULL)
10320 add_abstract_origin_attribute (var_die, origin);
10321 /* Loop unrolling can create multiple blocks that refer to the same
10322 static variable, so we must test for the DW_AT_declaration flag. */
10323 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10324 copy decls and set the DECL_ABSTRACT flag on them instead of
10326 else if (old_die && TREE_STATIC (decl)
10327 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10329 /* This is a definition of a C++ class level static. */
10330 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10331 if (DECL_NAME (decl))
10333 register unsigned file_index
10334 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
10336 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10337 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10339 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10340 != (unsigned) DECL_SOURCE_LINE (decl))
10342 add_AT_unsigned (var_die, DW_AT_decl_line,
10343 DECL_SOURCE_LINE (decl));
10348 add_name_and_src_coords_attributes (var_die, decl);
10349 add_type_attribute (var_die, TREE_TYPE (decl),
10350 TREE_READONLY (decl),
10351 TREE_THIS_VOLATILE (decl), context_die);
10353 if (TREE_PUBLIC (decl))
10354 add_AT_flag (var_die, DW_AT_external, 1);
10356 if (DECL_ARTIFICIAL (decl))
10357 add_AT_flag (var_die, DW_AT_artificial, 1);
10359 if (TREE_PROTECTED (decl))
10360 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10362 else if (TREE_PRIVATE (decl))
10363 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10367 add_AT_flag (var_die, DW_AT_declaration, 1);
10369 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10370 equate_decl_number_to_die (decl, var_die);
10372 if (! declaration && ! DECL_ABSTRACT (decl))
10374 add_location_or_const_value_attribute (var_die, decl);
10375 add_pubname (decl, var_die);
10378 tree_add_const_value_attribute (var_die, decl);
10381 /* Generate a DIE to represent a label identifier. */
10384 gen_label_die (decl, context_die)
10385 register tree decl;
10386 register dw_die_ref context_die;
10388 register tree origin = decl_ultimate_origin (decl);
10389 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
10391 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10393 if (origin != NULL)
10394 add_abstract_origin_attribute (lbl_die, origin);
10396 add_name_and_src_coords_attributes (lbl_die, decl);
10398 if (DECL_ABSTRACT (decl))
10399 equate_decl_number_to_die (decl, lbl_die);
10402 insn = DECL_RTL (decl);
10404 /* Deleted labels are programmer specified labels which have been
10405 eliminated because of various optimisations. We still emit them
10406 here so that it is possible to put breakpoints on them. */
10407 if (GET_CODE (insn) == CODE_LABEL
10408 || ((GET_CODE (insn) == NOTE
10409 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10411 /* When optimization is enabled (via -O) some parts of the compiler
10412 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10413 represent source-level labels which were explicitly declared by
10414 the user. This really shouldn't be happening though, so catch
10415 it if it ever does happen. */
10416 if (INSN_DELETED_P (insn))
10419 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10420 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10425 /* Generate a DIE for a lexical block. */
10428 gen_lexical_block_die (stmt, context_die, depth)
10429 register tree stmt;
10430 register dw_die_ref context_die;
10433 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10434 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10436 if (! BLOCK_ABSTRACT (stmt))
10438 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10439 BLOCK_NUMBER (stmt));
10440 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10441 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10442 BLOCK_NUMBER (stmt));
10443 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10446 decls_for_scope (stmt, stmt_die, depth);
10449 /* Generate a DIE for an inlined subprogram. */
10452 gen_inlined_subroutine_die (stmt, context_die, depth)
10453 register tree stmt;
10454 register dw_die_ref context_die;
10457 if (! BLOCK_ABSTRACT (stmt))
10459 register dw_die_ref subr_die
10460 = new_die (DW_TAG_inlined_subroutine, context_die);
10461 register tree decl = block_ultimate_origin (stmt);
10462 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10464 /* Emit info for the abstract instance first, if we haven't yet. */
10465 gen_abstract_function (decl);
10467 add_abstract_origin_attribute (subr_die, decl);
10468 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10469 BLOCK_NUMBER (stmt));
10470 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10471 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10472 BLOCK_NUMBER (stmt));
10473 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10474 decls_for_scope (stmt, subr_die, depth);
10475 current_function_has_inlines = 1;
10479 /* Generate a DIE for a field in a record, or structure. */
10482 gen_field_die (decl, context_die)
10483 register tree decl;
10484 register dw_die_ref context_die;
10486 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10488 add_name_and_src_coords_attributes (decl_die, decl);
10489 add_type_attribute (decl_die, member_declared_type (decl),
10490 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10493 /* If this is a bit field... */
10494 if (DECL_BIT_FIELD_TYPE (decl))
10496 add_byte_size_attribute (decl_die, decl);
10497 add_bit_size_attribute (decl_die, decl);
10498 add_bit_offset_attribute (decl_die, decl);
10501 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10502 add_data_member_location_attribute (decl_die, decl);
10504 if (DECL_ARTIFICIAL (decl))
10505 add_AT_flag (decl_die, DW_AT_artificial, 1);
10507 if (TREE_PROTECTED (decl))
10508 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10510 else if (TREE_PRIVATE (decl))
10511 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10515 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10516 Use modified_type_die instead.
10517 We keep this code here just in case these types of DIEs may be needed to
10518 represent certain things in other languages (e.g. Pascal) someday. */
10520 gen_pointer_type_die (type, context_die)
10521 register tree type;
10522 register dw_die_ref context_die;
10524 register dw_die_ref ptr_die
10525 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10527 equate_type_number_to_die (type, ptr_die);
10528 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10529 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10532 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10533 Use modified_type_die instead.
10534 We keep this code here just in case these types of DIEs may be needed to
10535 represent certain things in other languages (e.g. Pascal) someday. */
10537 gen_reference_type_die (type, context_die)
10538 register tree type;
10539 register dw_die_ref context_die;
10541 register dw_die_ref ref_die
10542 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10544 equate_type_number_to_die (type, ref_die);
10545 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10546 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10550 /* Generate a DIE for a pointer to a member type. */
10552 gen_ptr_to_mbr_type_die (type, context_die)
10553 register tree type;
10554 register dw_die_ref context_die;
10556 register dw_die_ref ptr_die
10557 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10559 equate_type_number_to_die (type, ptr_die);
10560 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10561 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10562 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10565 /* Generate the DIE for the compilation unit. */
10568 gen_compile_unit_die (filename)
10569 register const char *filename;
10571 register dw_die_ref die;
10572 char producer[250];
10573 const char *wd = getpwd ();
10576 die = new_die (DW_TAG_compile_unit, NULL);
10577 add_name_attribute (die, filename);
10579 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10580 add_AT_string (die, DW_AT_comp_dir, wd);
10582 sprintf (producer, "%s %s", language_string, version_string);
10584 #ifdef MIPS_DEBUGGING_INFO
10585 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10586 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10587 not appear in the producer string, the debugger reaches the conclusion
10588 that the object file is stripped and has no debugging information.
10589 To get the MIPS/SGI debugger to believe that there is debugging
10590 information in the object file, we add a -g to the producer string. */
10591 if (debug_info_level > DINFO_LEVEL_TERSE)
10592 strcat (producer, " -g");
10595 add_AT_string (die, DW_AT_producer, producer);
10597 if (strcmp (language_string, "GNU C++") == 0)
10598 language = DW_LANG_C_plus_plus;
10599 else if (strcmp (language_string, "GNU Ada") == 0)
10600 language = DW_LANG_Ada83;
10601 else if (strcmp (language_string, "GNU F77") == 0)
10602 language = DW_LANG_Fortran77;
10603 else if (strcmp (language_string, "GNU Pascal") == 0)
10604 language = DW_LANG_Pascal83;
10605 else if (strcmp (language_string, "GNU Java") == 0)
10606 language = DW_LANG_Java;
10607 else if (flag_traditional)
10608 language = DW_LANG_C;
10610 language = DW_LANG_C89;
10612 add_AT_unsigned (die, DW_AT_language, language);
10617 /* Generate a DIE for a string type. */
10620 gen_string_type_die (type, context_die)
10621 register tree type;
10622 register dw_die_ref context_die;
10624 register dw_die_ref type_die
10625 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10627 equate_type_number_to_die (type, type_die);
10629 /* Fudge the string length attribute for now. */
10631 /* TODO: add string length info.
10632 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10633 bound_representation (upper_bound, 0, 'u'); */
10636 /* Generate the DIE for a base class. */
10639 gen_inheritance_die (binfo, context_die)
10640 register tree binfo;
10641 register dw_die_ref context_die;
10643 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10645 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10646 add_data_member_location_attribute (die, binfo);
10648 if (TREE_VIA_VIRTUAL (binfo))
10649 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10650 if (TREE_VIA_PUBLIC (binfo))
10651 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10652 else if (TREE_VIA_PROTECTED (binfo))
10653 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10656 /* Generate a DIE for a class member. */
10659 gen_member_die (type, context_die)
10660 register tree type;
10661 register dw_die_ref context_die;
10663 register tree member;
10666 /* If this is not an incomplete type, output descriptions of each of its
10667 members. Note that as we output the DIEs necessary to represent the
10668 members of this record or union type, we will also be trying to output
10669 DIEs to represent the *types* of those members. However the `type'
10670 function (above) will specifically avoid generating type DIEs for member
10671 types *within* the list of member DIEs for this (containing) type execpt
10672 for those types (of members) which are explicitly marked as also being
10673 members of this (containing) type themselves. The g++ front- end can
10674 force any given type to be treated as a member of some other
10675 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10676 to point to the TREE node representing the appropriate (containing)
10679 /* First output info about the base classes. */
10680 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10682 register tree bases = TYPE_BINFO_BASETYPES (type);
10683 register int n_bases = TREE_VEC_LENGTH (bases);
10686 for (i = 0; i < n_bases; i++)
10687 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10690 /* Now output info about the data members and type members. */
10691 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10693 /* If we thought we were generating minimal debug info for TYPE
10694 and then changed our minds, some of the member declarations
10695 may have already been defined. Don't define them again, but
10696 do put them in the right order. */
10698 child = lookup_decl_die (member);
10700 splice_child_die (context_die, child);
10702 gen_decl_die (member, context_die);
10705 /* Now output info about the function members (if any). */
10706 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10708 child = lookup_decl_die (member);
10710 splice_child_die (context_die, child);
10712 gen_decl_die (member, context_die);
10716 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10717 is set, we pretend that the type was never defined, so we only get the
10718 member DIEs needed by later specification DIEs. */
10721 gen_struct_or_union_type_die (type, context_die)
10722 register tree type;
10723 register dw_die_ref context_die;
10725 register dw_die_ref type_die = lookup_type_die (type);
10726 register dw_die_ref scope_die = 0;
10727 register int nested = 0;
10728 int complete = (TYPE_SIZE (type)
10729 && (! TYPE_STUB_DECL (type)
10730 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10732 if (type_die && ! complete)
10735 if (TYPE_CONTEXT (type) != NULL_TREE
10736 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10739 scope_die = scope_die_for (type, context_die);
10741 if (! type_die || (nested && scope_die == comp_unit_die))
10742 /* First occurrence of type or toplevel definition of nested class. */
10744 register dw_die_ref old_die = type_die;
10746 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10747 ? DW_TAG_structure_type : DW_TAG_union_type,
10749 equate_type_number_to_die (type, type_die);
10751 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10753 add_name_attribute (type_die, type_tag (type));
10756 remove_AT (type_die, DW_AT_declaration);
10758 /* If this type has been completed, then give it a byte_size attribute and
10759 then give a list of members. */
10762 /* Prevent infinite recursion in cases where the type of some member of
10763 this type is expressed in terms of this type itself. */
10764 TREE_ASM_WRITTEN (type) = 1;
10765 add_byte_size_attribute (type_die, type);
10766 if (TYPE_STUB_DECL (type) != NULL_TREE)
10767 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10769 /* If the first reference to this type was as the return type of an
10770 inline function, then it may not have a parent. Fix this now. */
10771 if (type_die->die_parent == NULL)
10772 add_child_die (scope_die, type_die);
10774 push_decl_scope (type);
10775 gen_member_die (type, type_die);
10778 /* GNU extension: Record what type our vtable lives in. */
10779 if (TYPE_VFIELD (type))
10781 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10783 gen_type_die (vtype, context_die);
10784 add_AT_die_ref (type_die, DW_AT_containing_type,
10785 lookup_type_die (vtype));
10790 add_AT_flag (type_die, DW_AT_declaration, 1);
10792 /* We don't need to do this for function-local types. */
10793 if (! decl_function_context (TYPE_STUB_DECL (type)))
10794 add_incomplete_type (type);
10798 /* Generate a DIE for a subroutine _type_. */
10801 gen_subroutine_type_die (type, context_die)
10802 register tree type;
10803 register dw_die_ref context_die;
10805 register tree return_type = TREE_TYPE (type);
10806 register dw_die_ref subr_die
10807 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10809 equate_type_number_to_die (type, subr_die);
10810 add_prototyped_attribute (subr_die, type);
10811 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10812 gen_formal_types_die (type, subr_die);
10815 /* Generate a DIE for a type definition */
10818 gen_typedef_die (decl, context_die)
10819 register tree decl;
10820 register dw_die_ref context_die;
10822 register dw_die_ref type_die;
10823 register tree origin;
10825 if (TREE_ASM_WRITTEN (decl))
10827 TREE_ASM_WRITTEN (decl) = 1;
10829 type_die = new_die (DW_TAG_typedef, context_die);
10830 origin = decl_ultimate_origin (decl);
10831 if (origin != NULL)
10832 add_abstract_origin_attribute (type_die, origin);
10835 register tree type;
10836 add_name_and_src_coords_attributes (type_die, decl);
10837 if (DECL_ORIGINAL_TYPE (decl))
10839 type = DECL_ORIGINAL_TYPE (decl);
10841 if (type == TREE_TYPE (decl))
10844 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10847 type = TREE_TYPE (decl);
10848 add_type_attribute (type_die, type, TREE_READONLY (decl),
10849 TREE_THIS_VOLATILE (decl), context_die);
10852 if (DECL_ABSTRACT (decl))
10853 equate_decl_number_to_die (decl, type_die);
10856 /* Generate a type description DIE. */
10859 gen_type_die (type, context_die)
10860 register tree type;
10861 register dw_die_ref context_die;
10865 if (type == NULL_TREE || type == error_mark_node)
10868 /* We are going to output a DIE to represent the unqualified version of
10869 this type (i.e. without any const or volatile qualifiers) so get the
10870 main variant (i.e. the unqualified version) of this type now. */
10871 type = type_main_variant (type);
10873 if (TREE_ASM_WRITTEN (type))
10876 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10877 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10879 TREE_ASM_WRITTEN (type) = 1;
10880 gen_decl_die (TYPE_NAME (type), context_die);
10884 switch (TREE_CODE (type))
10890 case REFERENCE_TYPE:
10891 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10892 ensures that the gen_type_die recursion will terminate even if the
10893 type is recursive. Recursive types are possible in Ada. */
10894 /* ??? We could perhaps do this for all types before the switch
10896 TREE_ASM_WRITTEN (type) = 1;
10898 /* For these types, all that is required is that we output a DIE (or a
10899 set of DIEs) to represent the "basis" type. */
10900 gen_type_die (TREE_TYPE (type), context_die);
10904 /* This code is used for C++ pointer-to-data-member types.
10905 Output a description of the relevant class type. */
10906 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10908 /* Output a description of the type of the object pointed to. */
10909 gen_type_die (TREE_TYPE (type), context_die);
10911 /* Now output a DIE to represent this pointer-to-data-member type
10913 gen_ptr_to_mbr_type_die (type, context_die);
10917 gen_type_die (TYPE_DOMAIN (type), context_die);
10918 gen_set_type_die (type, context_die);
10922 gen_type_die (TREE_TYPE (type), context_die);
10923 abort (); /* No way to represent these in Dwarf yet! */
10926 case FUNCTION_TYPE:
10927 /* Force out return type (in case it wasn't forced out already). */
10928 gen_type_die (TREE_TYPE (type), context_die);
10929 gen_subroutine_type_die (type, context_die);
10933 /* Force out return type (in case it wasn't forced out already). */
10934 gen_type_die (TREE_TYPE (type), context_die);
10935 gen_subroutine_type_die (type, context_die);
10939 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10941 gen_type_die (TREE_TYPE (type), context_die);
10942 gen_string_type_die (type, context_die);
10945 gen_array_type_die (type, context_die);
10949 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10952 case ENUMERAL_TYPE:
10955 case QUAL_UNION_TYPE:
10956 /* If this is a nested type whose containing class hasn't been
10957 written out yet, writing it out will cover this one, too.
10958 This does not apply to instantiations of member class templates;
10959 they need to be added to the containing class as they are
10960 generated. FIXME: This hurts the idea of combining type decls
10961 from multiple TUs, since we can't predict what set of template
10962 instantiations we'll get. */
10963 if (TYPE_CONTEXT (type)
10964 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10965 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10967 gen_type_die (TYPE_CONTEXT (type), context_die);
10969 if (TREE_ASM_WRITTEN (type))
10972 /* If that failed, attach ourselves to the stub. */
10973 push_decl_scope (TYPE_CONTEXT (type));
10974 context_die = lookup_type_die (TYPE_CONTEXT (type));
10980 if (TREE_CODE (type) == ENUMERAL_TYPE)
10981 gen_enumeration_type_die (type, context_die);
10983 gen_struct_or_union_type_die (type, context_die);
10988 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10989 it up if it is ever completed. gen_*_type_die will set it for us
10990 when appropriate. */
10999 /* No DIEs needed for fundamental types. */
11003 /* No Dwarf representation currently defined. */
11010 TREE_ASM_WRITTEN (type) = 1;
11013 /* Generate a DIE for a tagged type instantiation. */
11016 gen_tagged_type_instantiation_die (type, context_die)
11017 register tree type;
11018 register dw_die_ref context_die;
11020 if (type == NULL_TREE || type == error_mark_node)
11023 /* We are going to output a DIE to represent the unqualified version of
11024 this type (i.e. without any const or volatile qualifiers) so make sure
11025 that we have the main variant (i.e. the unqualified version) of this
11027 if (type != type_main_variant (type))
11030 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11031 an instance of an unresolved type. */
11033 switch (TREE_CODE (type))
11038 case ENUMERAL_TYPE:
11039 gen_inlined_enumeration_type_die (type, context_die);
11043 gen_inlined_structure_type_die (type, context_die);
11047 case QUAL_UNION_TYPE:
11048 gen_inlined_union_type_die (type, context_die);
11056 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11057 things which are local to the given block. */
11060 gen_block_die (stmt, context_die, depth)
11061 register tree stmt;
11062 register dw_die_ref context_die;
11065 register int must_output_die = 0;
11066 register tree origin;
11067 register tree decl;
11068 register enum tree_code origin_code;
11070 /* Ignore blocks never really used to make RTL. */
11072 if (stmt == NULL_TREE || !TREE_USED (stmt)
11073 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11076 /* Determine the "ultimate origin" of this block. This block may be an
11077 inlined instance of an inlined instance of inline function, so we have
11078 to trace all of the way back through the origin chain to find out what
11079 sort of node actually served as the original seed for the creation of
11080 the current block. */
11081 origin = block_ultimate_origin (stmt);
11082 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11084 /* Determine if we need to output any Dwarf DIEs at all to represent this
11086 if (origin_code == FUNCTION_DECL)
11087 /* The outer scopes for inlinings *must* always be represented. We
11088 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11089 must_output_die = 1;
11092 /* In the case where the current block represents an inlining of the
11093 "body block" of an inline function, we must *NOT* output any DIE for
11094 this block because we have already output a DIE to represent the
11095 whole inlined function scope and the "body block" of any function
11096 doesn't really represent a different scope according to ANSI C
11097 rules. So we check here to make sure that this block does not
11098 represent a "body block inlining" before trying to set the
11099 `must_output_die' flag. */
11100 if (! is_body_block (origin ? origin : stmt))
11102 /* Determine if this block directly contains any "significant"
11103 local declarations which we will need to output DIEs for. */
11104 if (debug_info_level > DINFO_LEVEL_TERSE)
11105 /* We are not in terse mode so *any* local declaration counts
11106 as being a "significant" one. */
11107 must_output_die = (BLOCK_VARS (stmt) != NULL);
11109 /* We are in terse mode, so only local (nested) function
11110 definitions count as "significant" local declarations. */
11111 for (decl = BLOCK_VARS (stmt);
11112 decl != NULL; decl = TREE_CHAIN (decl))
11113 if (TREE_CODE (decl) == FUNCTION_DECL
11114 && DECL_INITIAL (decl))
11116 must_output_die = 1;
11122 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11123 DIE for any block which contains no significant local declarations at
11124 all. Rather, in such cases we just call `decls_for_scope' so that any
11125 needed Dwarf info for any sub-blocks will get properly generated. Note
11126 that in terse mode, our definition of what constitutes a "significant"
11127 local declaration gets restricted to include only inlined function
11128 instances and local (nested) function definitions. */
11129 if (must_output_die)
11131 if (origin_code == FUNCTION_DECL)
11132 gen_inlined_subroutine_die (stmt, context_die, depth);
11134 gen_lexical_block_die (stmt, context_die, depth);
11137 decls_for_scope (stmt, context_die, depth);
11140 /* Generate all of the decls declared within a given scope and (recursively)
11141 all of its sub-blocks. */
11144 decls_for_scope (stmt, context_die, depth)
11145 register tree stmt;
11146 register dw_die_ref context_die;
11149 register tree decl;
11150 register tree subblocks;
11152 /* Ignore blocks never really used to make RTL. */
11153 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11156 /* Output the DIEs to represent all of the data objects and typedefs
11157 declared directly within this block but not within any nested
11158 sub-blocks. Also, nested function and tag DIEs have been
11159 generated with a parent of NULL; fix that up now. */
11160 for (decl = BLOCK_VARS (stmt);
11161 decl != NULL; decl = TREE_CHAIN (decl))
11163 register dw_die_ref die;
11165 if (TREE_CODE (decl) == FUNCTION_DECL)
11166 die = lookup_decl_die (decl);
11167 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11168 die = lookup_type_die (TREE_TYPE (decl));
11172 if (die != NULL && die->die_parent == NULL)
11173 add_child_die (context_die, die);
11175 gen_decl_die (decl, context_die);
11178 /* Output the DIEs to represent all sub-blocks (and the items declared
11179 therein) of this block. */
11180 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11182 subblocks = BLOCK_CHAIN (subblocks))
11183 gen_block_die (subblocks, context_die, depth + 1);
11186 /* Is this a typedef we can avoid emitting? */
11189 is_redundant_typedef (decl)
11190 register tree decl;
11192 if (TYPE_DECL_IS_STUB (decl))
11195 if (DECL_ARTIFICIAL (decl)
11196 && DECL_CONTEXT (decl)
11197 && is_tagged_type (DECL_CONTEXT (decl))
11198 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11199 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11200 /* Also ignore the artificial member typedef for the class name. */
11206 /* Generate Dwarf debug information for a decl described by DECL. */
11209 gen_decl_die (decl, context_die)
11210 register tree decl;
11211 register dw_die_ref context_die;
11213 register tree origin;
11215 if (TREE_CODE (decl) == ERROR_MARK)
11218 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11219 if (DECL_IGNORED_P (decl))
11222 switch (TREE_CODE (decl))
11225 /* The individual enumerators of an enum type get output when we output
11226 the Dwarf representation of the relevant enum type itself. */
11229 case FUNCTION_DECL:
11230 /* Don't output any DIEs to represent mere function declarations,
11231 unless they are class members or explicit block externs. */
11232 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11233 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11236 /* If we're emitting an out-of-line copy of an inline function,
11237 emit info for the abstract instance and set up to refer to it. */
11238 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11239 && ! class_scope_p (context_die)
11240 /* gen_abstract_function won't emit a die if this is just a
11241 declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11242 that case, because that works only if we have a die. */
11243 && DECL_INITIAL (decl) != NULL_TREE)
11245 gen_abstract_function (decl);
11246 set_decl_origin_self (decl);
11249 if (debug_info_level > DINFO_LEVEL_TERSE)
11251 /* Before we describe the FUNCTION_DECL itself, make sure that we
11252 have described its return type. */
11253 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11255 /* And its virtual context. */
11256 if (DECL_VINDEX (decl) != NULL_TREE)
11257 gen_type_die (DECL_CONTEXT (decl), context_die);
11259 /* And its containing type. */
11260 origin = decl_class_context (decl);
11261 if (origin != NULL_TREE)
11262 gen_type_die_for_member (origin, decl, context_die);
11265 /* Now output a DIE to represent the function itself. */
11266 gen_subprogram_die (decl, context_die);
11270 /* If we are in terse mode, don't generate any DIEs to represent any
11271 actual typedefs. */
11272 if (debug_info_level <= DINFO_LEVEL_TERSE)
11275 /* In the special case of a TYPE_DECL node representing the
11276 declaration of some type tag, if the given TYPE_DECL is marked as
11277 having been instantiated from some other (original) TYPE_DECL node
11278 (e.g. one which was generated within the original definition of an
11279 inline function) we have to generate a special (abbreviated)
11280 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
11282 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11284 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11288 if (is_redundant_typedef (decl))
11289 gen_type_die (TREE_TYPE (decl), context_die);
11291 /* Output a DIE to represent the typedef itself. */
11292 gen_typedef_die (decl, context_die);
11296 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11297 gen_label_die (decl, context_die);
11301 /* If we are in terse mode, don't generate any DIEs to represent any
11302 variable declarations or definitions. */
11303 if (debug_info_level <= DINFO_LEVEL_TERSE)
11306 /* Output any DIEs that are needed to specify the type of this data
11308 gen_type_die (TREE_TYPE (decl), context_die);
11310 /* And its containing type. */
11311 origin = decl_class_context (decl);
11312 if (origin != NULL_TREE)
11313 gen_type_die_for_member (origin, decl, context_die);
11315 /* Now output the DIE to represent the data object itself. This gets
11316 complicated because of the possibility that the VAR_DECL really
11317 represents an inlined instance of a formal parameter for an inline
11319 origin = decl_ultimate_origin (decl);
11320 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11321 gen_formal_parameter_die (decl, context_die);
11323 gen_variable_die (decl, context_die);
11327 /* Ignore the nameless fields that are used to skip bits, but
11328 handle C++ anonymous unions. */
11329 if (DECL_NAME (decl) != NULL_TREE
11330 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11332 gen_type_die (member_declared_type (decl), context_die);
11333 gen_field_die (decl, context_die);
11338 gen_type_die (TREE_TYPE (decl), context_die);
11339 gen_formal_parameter_die (decl, context_die);
11342 case NAMESPACE_DECL:
11343 /* Ignore for now. */
11351 /* Add Ada "use" clause information for SGI Workshop debugger. */
11354 dwarf2out_add_library_unit_info (filename, context_list)
11355 const char *filename;
11356 const char *context_list;
11358 unsigned int file_index;
11360 if (filename != NULL)
11362 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
11363 tree context_list_decl
11364 = build_decl (LABEL_DECL, get_identifier (context_list),
11367 TREE_PUBLIC (context_list_decl) = TRUE;
11368 add_name_attribute (unit_die, context_list);
11369 file_index = lookup_filename (&decl_file_table, filename);
11370 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11371 add_pubname (context_list_decl, unit_die);
11375 /* Write the debugging output for DECL. */
11378 dwarf2out_decl (decl)
11379 register tree decl;
11381 register dw_die_ref context_die = comp_unit_die;
11383 if (TREE_CODE (decl) == ERROR_MARK)
11386 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11387 if (DECL_IGNORED_P (decl))
11390 switch (TREE_CODE (decl))
11392 case FUNCTION_DECL:
11393 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11394 builtin function. Explicit programmer-supplied declarations of
11395 these same functions should NOT be ignored however. */
11396 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11399 /* What we would really like to do here is to filter out all mere
11400 file-scope declarations of file-scope functions which are never
11401 referenced later within this translation unit (and keep all of ones
11402 that *are* referenced later on) but we aren't clairvoyant, so we have
11403 no idea which functions will be referenced in the future (i.e. later
11404 on within the current translation unit). So here we just ignore all
11405 file-scope function declarations which are not also definitions. If
11406 and when the debugger needs to know something about these functions,
11407 it will have to hunt around and find the DWARF information associated
11408 with the definition of the function. Note that we can't just check
11409 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11410 definitions and which ones represent mere declarations. We have to
11411 check `DECL_INITIAL' instead. That's because the C front-end
11412 supports some weird semantics for "extern inline" function
11413 definitions. These can get inlined within the current translation
11414 unit (an thus, we need to generate DWARF info for their abstract
11415 instances so that the DWARF info for the concrete inlined instances
11416 can have something to refer to) but the compiler never generates any
11417 out-of-lines instances of such things (despite the fact that they
11418 *are* definitions). The important point is that the C front-end
11419 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11420 to generate DWARF for them anyway. Note that the C++ front-end also
11421 plays some similar games for inline function definitions appearing
11422 within include files which also contain
11423 `#pragma interface' pragmas. */
11424 if (DECL_INITIAL (decl) == NULL_TREE)
11427 /* If we're a nested function, initially use a parent of NULL; if we're
11428 a plain function, this will be fixed up in decls_for_scope. If
11429 we're a method, it will be ignored, since we already have a DIE. */
11430 if (decl_function_context (decl))
11431 context_die = NULL;
11436 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11437 declaration and if the declaration was never even referenced from
11438 within this entire compilation unit. We suppress these DIEs in
11439 order to save space in the .debug section (by eliminating entries
11440 which are probably useless). Note that we must not suppress
11441 block-local extern declarations (whether used or not) because that
11442 would screw-up the debugger's name lookup mechanism and cause it to
11443 miss things which really ought to be in scope at a given point. */
11444 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11447 /* If we are in terse mode, don't generate any DIEs to represent any
11448 variable declarations or definitions. */
11449 if (debug_info_level <= DINFO_LEVEL_TERSE)
11454 /* Don't emit stubs for types unless they are needed by other DIEs. */
11455 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11458 /* Don't bother trying to generate any DIEs to represent any of the
11459 normal built-in types for the language we are compiling. */
11460 if (DECL_SOURCE_LINE (decl) == 0)
11462 /* OK, we need to generate one for `bool' so GDB knows what type
11463 comparisons have. */
11464 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11465 == DW_LANG_C_plus_plus)
11466 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11467 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11472 /* If we are in terse mode, don't generate any DIEs for types. */
11473 if (debug_info_level <= DINFO_LEVEL_TERSE)
11476 /* If we're a function-scope tag, initially use a parent of NULL;
11477 this will be fixed up in decls_for_scope. */
11478 if (decl_function_context (decl))
11479 context_die = NULL;
11487 gen_decl_die (decl, context_die);
11490 /* Output a marker (i.e. a label) for the beginning of the generated code for
11491 a lexical block. */
11494 dwarf2out_begin_block (blocknum)
11495 register unsigned blocknum;
11497 function_section (current_function_decl);
11498 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11501 /* Output a marker (i.e. a label) for the end of the generated code for a
11505 dwarf2out_end_block (blocknum)
11506 register unsigned blocknum;
11508 function_section (current_function_decl);
11509 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11512 /* Returns nonzero if it is appropriate not to emit any debugging
11513 information for BLOCK, because it doesn't contain any instructions.
11515 Don't allow this for blocks with nested functions or local classes
11516 as we would end up with orphans, and in the presence of scheduling
11517 we may end up calling them anyway. */
11520 dwarf2out_ignore_block (block)
11524 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11525 if (TREE_CODE (decl) == FUNCTION_DECL
11526 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11531 /* Lookup a filename (in the list of filenames that we know about here in
11532 dwarf2out.c) and return its "index". The index of each (known) filename is
11533 just a unique number which is associated with only that one filename.
11534 We need such numbers for the sake of generating labels
11535 (in the .debug_sfnames section) and references to those
11536 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11537 If the filename given as an argument is not found in our current list,
11538 add it to the list and assign it the next available unique index number.
11539 In order to speed up searches, we remember the index of the filename
11540 was looked up last. This handles the majority of all searches. */
11543 lookup_filename (t, file_name)
11544 struct file_table *t;
11545 const char *file_name;
11547 register unsigned i;
11549 /* Check to see if the file name that was searched on the previous
11550 call matches this file name. If so, return the index. */
11551 if (t->last_lookup_index != 0)
11552 if (strcmp (file_name, t->table[t->last_lookup_index]) == 0)
11553 return t->last_lookup_index;
11555 /* Didn't match the previous lookup, search the table */
11556 for (i = 1; i < t->in_use; ++i)
11557 if (strcmp (file_name, t->table[i]) == 0)
11559 t->last_lookup_index = i;
11563 /* Prepare to add a new table entry by making sure there is enough space in
11564 the table to do so. If not, expand the current table. */
11565 if (i == t->allocated)
11567 t->allocated = i + FILE_TABLE_INCREMENT;
11568 t->table = (char **)
11569 xrealloc (t->table, t->allocated * sizeof (char *));
11572 /* Add the new entry to the end of the filename table. */
11573 t->table[i] = xstrdup (file_name);
11575 t->last_lookup_index = i;
11581 init_file_table (t)
11582 struct file_table *t;
11584 /* Allocate the initial hunk of the file_table. */
11585 t->table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11586 t->allocated = FILE_TABLE_INCREMENT;
11588 /* Skip the first entry - file numbers begin at 1. */
11590 t->last_lookup_index = 0;
11593 /* Output a label to mark the beginning of a source code line entry
11594 and record information relating to this source line, in
11595 'line_info_table' for later output of the .debug_line section. */
11598 dwarf2out_line (filename, line)
11599 register const char *filename;
11600 register unsigned line;
11602 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11604 function_section (current_function_decl);
11606 if (DWARF2_ASM_LINE_DEBUG_INFO)
11609 unsigned old_in_use = line_file_table.in_use;
11611 unsigned file_num = lookup_filename (&line_file_table, filename);
11613 /* Emit the .file and .loc directives understood by GNU as. */
11615 /* ??? As of 2000-11-25, gas has a bug in which it doesn't
11616 actually use the file number argument. It merely remembers
11617 the last .file directive emitted. */
11618 if (file_num >= old_in_use)
11619 fprintf (asm_out_file, "\t.file %d \"%s\"\n", file_num, filename);
11620 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11622 static unsigned int last_file_num;
11623 if (file_num != last_file_num)
11625 last_file_num = file_num;
11626 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
11628 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
11631 /* Indicate that line number info exists. */
11632 ++line_info_table_in_use;
11634 /* Indicate that multiple line number tables exist. */
11635 if (DECL_SECTION_NAME (current_function_decl))
11636 ++separate_line_info_table_in_use;
11638 else if (DECL_SECTION_NAME (current_function_decl))
11640 register dw_separate_line_info_ref line_info;
11641 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11642 separate_line_info_table_in_use);
11643 if (flag_debug_asm)
11644 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
11645 fputc ('\n', asm_out_file);
11647 /* expand the line info table if necessary */
11648 if (separate_line_info_table_in_use
11649 == separate_line_info_table_allocated)
11651 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11652 separate_line_info_table
11653 = (dw_separate_line_info_ref)
11654 xrealloc (separate_line_info_table,
11655 separate_line_info_table_allocated
11656 * sizeof (dw_separate_line_info_entry));
11659 /* Add the new entry at the end of the line_info_table. */
11661 = &separate_line_info_table[separate_line_info_table_in_use++];
11662 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
11663 line_info->dw_line_num = line;
11664 line_info->function = current_funcdef_number;
11668 register dw_line_info_ref line_info;
11670 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11671 line_info_table_in_use);
11672 if (flag_debug_asm)
11673 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
11674 fputc ('\n', asm_out_file);
11676 /* Expand the line info table if necessary. */
11677 if (line_info_table_in_use == line_info_table_allocated)
11679 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11681 = (dw_line_info_ref)
11682 xrealloc (line_info_table,
11683 (line_info_table_allocated
11684 * sizeof (dw_line_info_entry)));
11687 /* Add the new entry at the end of the line_info_table. */
11688 line_info = &line_info_table[line_info_table_in_use++];
11689 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
11690 line_info->dw_line_num = line;
11695 /* Record the beginning of a new source file, for later output
11696 of the .debug_macinfo section. At present, unimplemented. */
11699 dwarf2out_start_source_file (filename)
11700 register const char *filename ATTRIBUTE_UNUSED;
11702 if (flag_eliminate_dwarf2_dups)
11704 /* Record the beginning of the file for break_out_includes. */
11705 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11706 add_AT_string (bincl_die, DW_AT_name, filename);
11710 /* Record the end of a source file, for later output
11711 of the .debug_macinfo section. At present, unimplemented. */
11714 dwarf2out_end_source_file ()
11716 if (flag_eliminate_dwarf2_dups)
11718 /* Record the end of the file for break_out_includes. */
11719 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11723 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11724 the tail part of the directive line, i.e. the part which is past the
11725 initial whitespace, #, whitespace, directive-name, whitespace part. */
11728 dwarf2out_define (lineno, buffer)
11729 register unsigned lineno ATTRIBUTE_UNUSED;
11730 register const char *buffer ATTRIBUTE_UNUSED;
11732 static int initialized = 0;
11735 dwarf2out_start_source_file (primary_filename);
11740 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11741 the tail part of the directive line, i.e. the part which is past the
11742 initial whitespace, #, whitespace, directive-name, whitespace part. */
11745 dwarf2out_undef (lineno, buffer)
11746 register unsigned lineno ATTRIBUTE_UNUSED;
11747 register const char *buffer ATTRIBUTE_UNUSED;
11751 /* Set up for Dwarf output at the start of compilation. */
11754 dwarf2out_init (asm_out_file, main_input_filename)
11755 register FILE *asm_out_file;
11756 register const char *main_input_filename;
11758 /* Remember the name of the primary input file. */
11759 primary_filename = main_input_filename;
11761 init_file_table (&decl_file_table);
11762 init_file_table (&line_file_table);
11764 /* Allocate the initial hunk of the decl_die_table. */
11766 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11767 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11768 decl_die_table_in_use = 0;
11770 /* Allocate the initial hunk of the decl_scope_table. */
11772 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11773 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11774 decl_scope_depth = 0;
11776 /* Allocate the initial hunk of the abbrev_die_table. */
11778 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11779 sizeof (dw_die_ref));
11780 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11781 /* Zero-th entry is allocated, but unused */
11782 abbrev_die_table_in_use = 1;
11784 /* Allocate the initial hunk of the line_info_table. */
11786 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11787 sizeof (dw_line_info_entry));
11788 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11789 /* Zero-th entry is allocated, but unused */
11790 line_info_table_in_use = 1;
11792 /* Generate the initial DIE for the .debug section. Note that the (string)
11793 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11794 will (typically) be a relative pathname and that this pathname should be
11795 taken as being relative to the directory from which the compiler was
11796 invoked when the given (base) source file was compiled. */
11797 comp_unit_die = gen_compile_unit_die (main_input_filename);
11799 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11800 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11802 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11803 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
11804 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11805 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11807 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11808 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11809 DEBUG_INFO_SECTION_LABEL, 0);
11810 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11811 DEBUG_LINE_SECTION_LABEL, 0);
11813 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11814 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11815 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11817 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11818 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11820 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11821 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11822 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11823 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11826 /* Output stuff that dwarf requires at the end of every file,
11827 and generate the DWARF-2 debugging info. */
11830 dwarf2out_finish ()
11832 limbo_die_node *node, *next_node;
11835 /* Traverse the limbo die list, and add parent/child links. The only
11836 dies without parents that should be here are concrete instances of
11837 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11838 For concrete instances, we can get the parent die from the abstract
11840 for (node = limbo_die_list; node; node = next_node)
11842 next_node = node->next;
11845 if (die->die_parent == NULL)
11847 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11849 add_child_die (origin->die_parent, die);
11850 else if (die == comp_unit_die)
11857 limbo_die_list = NULL;
11859 /* Walk through the list of incomplete types again, trying once more to
11860 emit full debugging info for them. */
11861 retry_incomplete_types ();
11863 /* We need to reverse all the dies before break_out_includes, or
11864 we'll see the end of an include file before the beginning. */
11865 reverse_all_dies (comp_unit_die);
11867 /* Generate separate CUs for each of the include files we've seen.
11868 They will go into limbo_die_list. */
11869 if (flag_eliminate_dwarf2_dups)
11870 break_out_includes (comp_unit_die);
11872 /* Traverse the DIE's and add add sibling attributes to those DIE's
11873 that have children. */
11874 add_sibling_attributes (comp_unit_die);
11875 for (node = limbo_die_list; node; node = node->next)
11876 add_sibling_attributes (node->die);
11878 /* Output a terminator label for the .text section. */
11879 fputc ('\n', asm_out_file);
11880 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11881 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11884 /* Output a terminator label for the .data section. */
11885 fputc ('\n', asm_out_file);
11886 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11887 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11889 /* Output a terminator label for the .bss section. */
11890 fputc ('\n', asm_out_file);
11891 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11892 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11895 /* Output the source line correspondence table. */
11896 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
11898 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11900 fputc ('\n', asm_out_file);
11901 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11902 output_line_info ();
11905 /* We can only use the low/high_pc attributes if all of the code
11907 if (separate_line_info_table_in_use == 0)
11909 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11910 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11913 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11914 debug_line_section_label);
11917 #if 0 /* unimplemented */
11918 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
11919 add_AT_unsigned (die, DW_AT_macro_info, 0);
11922 /* Output all of the compilation units. We put the main one last so that
11923 the offsets are available to output_pubnames. */
11924 for (node = limbo_die_list; node; node = node->next)
11925 output_comp_unit (node->die);
11926 output_comp_unit (comp_unit_die);
11928 /* Output the abbreviation table. */
11929 fputc ('\n', asm_out_file);
11930 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11931 output_abbrev_section ();
11933 if (pubname_table_in_use)
11935 /* Output public names table. */
11936 fputc ('\n', asm_out_file);
11937 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
11938 output_pubnames ();
11941 /* We only put functions in the arange table, so don't write it out if
11942 we don't have any. */
11943 if (fde_table_in_use)
11945 /* Output the address range information. */
11946 fputc ('\n', asm_out_file);
11947 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11951 #endif /* DWARF2_DEBUGGING_INFO */