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 a fixed address on the stack which identifies a call frame.
61 We define it to be the value of SP just before the call insn.
62 The CFA register and offset, which may change during the course
63 of the function, are used to calculate its value at runtime.
64 CFI = Call Frame Instruction
65 an instruction for the DWARF2 abstract machine
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 The High-Level Picture
1288 Changes in the register we use to calculate the CFA: Currently we
1289 assume that if you copy the CFA register into another register, we
1290 should take the other one as the new CFA register; this seems to
1291 work pretty well. If it's wrong for some target, it's simple
1292 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1294 Changes in the register we use for saving registers to the stack:
1295 This is usually SP, but not always. Again, we deduce that if you
1296 copy SP into another register (and SP is not the CFA register),
1297 then the new register is the one we will be using for register
1298 saves. This also seems to work.
1300 Register saves: There's not much guesswork about this one; if
1301 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1302 register save, and the register used to calculate the destination
1303 had better be the one we think we're using for this purpose.
1305 Except: If the register being saved is the CFA register, and the
1306 offset is non-zero, we are saving the CFA, so we assume we have to
1307 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1308 the intent is to save the value of SP from the previous frame.
1310 Invariants / Summaries of Rules
1312 cfa current rule for calculating the CFA. It usually
1313 consists of a register and an offset.
1314 cfa_store register used by prologue code to save things to the stack
1315 cfa_store.offset is the offset from the value of
1316 cfa_store.reg to the actual CFA
1317 cfa_temp register holding an integral value. cfa_temp.offset
1318 stores the value, which will be used to adjust the
1321 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1322 with cfa.reg as the first operand changes the cfa.reg and its
1324 (For an unknown reason, Rule 4 does not fully obey the
1327 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1328 expression yielding a constant. This sets cfa_temp.reg
1329 and cfa_temp.offset.
1331 Rule 5: Create a new register cfa_store used to save items to the
1334 Rules 10-13: Save a register to the stack. Define offset as the
1335 difference of the original location and cfa_store's
1340 "{a,b}" indicates a choice of a xor b.
1341 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1344 (set <reg1> <reg2>:cfa.reg)
1345 effects: cfa.reg = <REG1>
1346 cfa.offset unchanged
1349 (set sp ({minus,plus} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1350 effects: cfa.reg = sp if fp used
1351 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1352 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1353 if cfa_store.reg==sp
1356 (set fp ({minus,plus} <reg>:cfa.reg <const_int>))
1357 effects: cfa.reg = fp
1358 cfa_offset += +/- <const_int>
1361 (set <reg1> (plus <reg2>:cfa.reg <const_int>))
1362 constraints: <reg1> != fp
1364 effects: cfa.reg = <reg1>
1365 questions: Where is <const_int> used?
1366 Should cfa.offset be changed?
1369 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1370 constraints: <reg1> != fp
1372 effects: cfa_store.reg = <reg1>
1373 cfa_store.offset = cfa.offset - cfa_temp.offset
1376 (set <reg> <const_int>)
1377 effects: cfa_temp.reg = <reg>
1378 cfa_temp.offset = <const_int>
1381 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1382 effects: cfa_temp.reg = <reg1>
1383 cfa_temp.offset |= <const_int>
1386 (set <reg> (high <exp>))
1390 (set <reg> (lo_sum <exp> <const_int>))
1391 effects: cfa_temp.reg = <reg>
1392 cfa_temp.offset = <const_int>
1395 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1396 effects: cfa_store.offset -= <const_int>
1397 cfa.offset = cfa_store.offset if cfa.reg == sp
1398 offset = -cfa_store.offset
1400 cfa.base_offset = offset
1403 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1404 effects: cfa_store.offset += -/+ mode_size(mem)
1405 cfa.offset = cfa_store.offset if cfa.reg == sp
1406 offset = -cfa_store.offset
1408 cfa.base_offset = offset
1411 (set (mem ({minus,plus} <reg1>:cfa_store <const_int>)) <reg2>)
1412 effects: cfa_store.offset += -/+ <const_int>
1413 offset = -cfa_store.offset
1415 cfa.base_offset = offset
1418 (set (mem <reg1>:cfa_store) <reg2>)
1419 effects: offset = -cfa_store.offset
1421 cfa.base_offset = offset */
1424 dwarf2out_frame_debug_expr (expr, label)
1431 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1432 the PARALLEL independently. The first element is always processed if
1433 it is a SET. This is for backward compatibility. Other elements
1434 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1435 flag is set in them. */
1437 if (GET_CODE (expr) == PARALLEL
1438 || GET_CODE (expr) == SEQUENCE)
1441 int limit = XVECLEN (expr, 0);
1443 for (par_index = 0; par_index < limit; par_index++)
1445 rtx x = XVECEXP (expr, 0, par_index);
1447 if (GET_CODE (x) == SET &&
1448 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1449 dwarf2out_frame_debug_expr (x, label);
1454 if (GET_CODE (expr) != SET)
1457 src = SET_SRC (expr);
1458 dest = SET_DEST (expr);
1460 switch (GET_CODE (dest))
1464 /* Update the CFA rule wrt SP or FP. Make sure src is
1465 relative to the current CFA register. */
1466 switch (GET_CODE (src))
1468 /* Setting FP from SP. */
1470 if (cfa.reg == (unsigned) REGNO (src))
1476 /* We used to require that dest be either SP or FP, but the
1477 ARM copies SP to a temporary register, and from there to
1478 FP. So we just rely on the backends to only set
1479 RTX_FRAME_RELATED_P on appropriate insns. */
1480 cfa.reg = REGNO (dest);
1485 if (dest == stack_pointer_rtx)
1489 switch (GET_CODE (XEXP (src, 1)))
1492 offset = INTVAL (XEXP (src, 1));
1495 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1497 offset = cfa_temp.offset;
1503 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1505 /* Restoring SP from FP in the epilogue. */
1506 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1508 cfa.reg = STACK_POINTER_REGNUM;
1510 else if (XEXP (src, 0) != stack_pointer_rtx)
1513 if (GET_CODE (src) == PLUS)
1515 if (cfa.reg == STACK_POINTER_REGNUM)
1516 cfa.offset += offset;
1517 if (cfa_store.reg == STACK_POINTER_REGNUM)
1518 cfa_store.offset += offset;
1520 else if (dest == hard_frame_pointer_rtx)
1523 /* Either setting the FP from an offset of the SP,
1524 or adjusting the FP */
1525 if (! frame_pointer_needed)
1528 if (GET_CODE (XEXP (src, 0)) == REG
1529 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1530 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1532 offset = INTVAL (XEXP (src, 1));
1533 if (GET_CODE (src) == PLUS)
1535 cfa.offset += offset;
1536 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1543 if (GET_CODE (src) != PLUS)
1547 if (GET_CODE (XEXP (src, 0)) == REG
1548 && REGNO (XEXP (src, 0)) == cfa.reg
1549 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1550 /* Setting a temporary CFA register that will be copied
1551 into the FP later on. */
1552 cfa.reg = REGNO (dest);
1556 /* Setting a scratch register that we will use instead
1557 of SP for saving registers to the stack. */
1558 if (XEXP (src, 1) != stack_pointer_rtx)
1560 if (GET_CODE (XEXP (src, 0)) != REG
1561 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg)
1563 if (cfa.reg != STACK_POINTER_REGNUM)
1565 cfa_store.reg = REGNO (dest);
1566 cfa_store.offset = cfa.offset - cfa_temp.offset;
1573 cfa_temp.reg = REGNO (dest);
1574 cfa_temp.offset = INTVAL (src);
1579 if (GET_CODE (XEXP (src, 0)) != REG
1580 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1581 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1583 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1584 cfa_temp.reg = REGNO (dest);
1585 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1591 def_cfa_1 (label, &cfa);
1594 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1595 will fill in all of the bits. */
1602 if (GET_CODE (XEXP (src, 1)) != CONST_INT)
1604 cfa_temp.reg = REGNO (dest);
1605 cfa_temp.offset = INTVAL (XEXP (src, 1));
1609 if (GET_CODE (src) != REG)
1612 /* Saving a register to the stack. Make sure dest is relative to the
1614 switch (GET_CODE (XEXP (dest, 0)))
1619 /* We can't handle variable size modifications. */
1620 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1622 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1624 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1625 || cfa_store.reg != STACK_POINTER_REGNUM)
1627 cfa_store.offset += offset;
1628 if (cfa.reg == STACK_POINTER_REGNUM)
1629 cfa.offset = cfa_store.offset;
1631 offset = -cfa_store.offset;
1636 offset = GET_MODE_SIZE (GET_MODE (dest));
1637 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1640 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1641 || cfa_store.reg != STACK_POINTER_REGNUM)
1643 cfa_store.offset += offset;
1644 if (cfa.reg == STACK_POINTER_REGNUM)
1645 cfa.offset = cfa_store.offset;
1647 offset = -cfa_store.offset;
1651 /* With an offset. */
1654 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1656 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1657 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1660 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1662 offset -= cfa_store.offset;
1666 /* Without an offset. */
1668 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1670 offset = -cfa_store.offset;
1677 if (REGNO (src) != STACK_POINTER_REGNUM
1678 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1679 && (unsigned) REGNO (src) == cfa.reg)
1681 /* We're storing the current CFA reg into the stack. */
1683 if (cfa.offset == 0)
1685 /* If the source register is exactly the CFA, assume
1686 we're saving SP like any other register; this happens
1689 def_cfa_1 (label, &cfa);
1690 dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset);
1695 /* Otherwise, we'll need to look in the stack to
1696 calculate the CFA. */
1698 rtx x = XEXP (dest, 0);
1699 if (GET_CODE (x) != REG)
1701 if (GET_CODE (x) != REG)
1703 cfa.reg = (unsigned) REGNO (x);
1704 cfa.base_offset = offset;
1706 def_cfa_1 (label, &cfa);
1711 def_cfa_1 (label, &cfa);
1712 dwarf2out_reg_save (label, REGNO (src), offset);
1720 /* Record call frame debugging information for INSN, which either
1721 sets SP or FP (adjusting how we calculate the frame address) or saves a
1722 register to the stack. If INSN is NULL_RTX, initialize our state. */
1725 dwarf2out_frame_debug (insn)
1731 if (insn == NULL_RTX)
1733 /* Set up state for generating call frame debug info. */
1735 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1737 cfa.reg = STACK_POINTER_REGNUM;
1740 cfa_temp.offset = 0;
1744 if (! RTX_FRAME_RELATED_P (insn))
1746 dwarf2out_stack_adjust (insn);
1750 label = dwarf2out_cfi_label ();
1752 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1754 insn = XEXP (src, 0);
1756 insn = PATTERN (insn);
1758 dwarf2out_frame_debug_expr (insn, label);
1761 /* Return the size of an unsigned LEB128 quantity. */
1763 static inline unsigned long
1764 size_of_uleb128 (value)
1765 register unsigned long value;
1767 register unsigned long size = 0;
1768 register unsigned byte;
1772 byte = (value & 0x7f);
1781 /* Return the size of a signed LEB128 quantity. */
1783 static inline unsigned long
1784 size_of_sleb128 (value)
1785 register long value;
1787 register unsigned long size = 0;
1788 register unsigned byte;
1792 byte = (value & 0x7f);
1796 while (!(((value == 0) && ((byte & 0x40) == 0))
1797 || ((value == -1) && ((byte & 0x40) != 0))));
1802 /* Output an unsigned LEB128 quantity. */
1805 output_uleb128 (value)
1806 register unsigned long value;
1808 unsigned long save_value = value;
1810 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1813 register unsigned byte = (value & 0x7f);
1816 /* More bytes to follow. */
1819 fprintf (asm_out_file, "0x%x", byte);
1821 fprintf (asm_out_file, ",");
1826 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1829 /* Output an signed LEB128 quantity. */
1832 output_sleb128 (value)
1833 register long value;
1836 register unsigned byte;
1837 long save_value = value;
1839 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1842 byte = (value & 0x7f);
1843 /* arithmetic shift */
1845 more = !((((value == 0) && ((byte & 0x40) == 0))
1846 || ((value == -1) && ((byte & 0x40) != 0))));
1850 fprintf (asm_out_file, "0x%x", byte);
1852 fprintf (asm_out_file, ",");
1857 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1860 /* Output a Call Frame Information opcode and its operand(s). */
1863 output_cfi (cfi, fde)
1864 register dw_cfi_ref cfi;
1865 register dw_fde_ref fde;
1867 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1869 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1871 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1873 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1874 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1875 fputc ('\n', asm_out_file);
1878 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1880 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1882 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1884 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1885 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1887 fputc ('\n', asm_out_file);
1888 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1889 fputc ('\n', asm_out_file);
1891 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1893 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1895 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1897 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1898 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1900 fputc ('\n', asm_out_file);
1904 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1906 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1907 dwarf_cfi_name (cfi->dw_cfi_opc));
1909 fputc ('\n', asm_out_file);
1910 switch (cfi->dw_cfi_opc)
1912 case DW_CFA_set_loc:
1913 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1914 fputc ('\n', asm_out_file);
1916 case DW_CFA_advance_loc1:
1917 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1918 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1919 fde->dw_fde_current_label);
1920 fputc ('\n', asm_out_file);
1921 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1923 case DW_CFA_advance_loc2:
1924 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1925 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1926 fde->dw_fde_current_label);
1927 fputc ('\n', asm_out_file);
1928 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1930 case DW_CFA_advance_loc4:
1931 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1932 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1933 fde->dw_fde_current_label);
1934 fputc ('\n', asm_out_file);
1935 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1937 #ifdef MIPS_DEBUGGING_INFO
1938 case DW_CFA_MIPS_advance_loc8:
1939 /* TODO: not currently implemented. */
1943 case DW_CFA_offset_extended:
1944 case DW_CFA_GNU_negative_offset_extended:
1945 case DW_CFA_def_cfa:
1946 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1947 fputc ('\n', asm_out_file);
1948 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1949 fputc ('\n', asm_out_file);
1951 case DW_CFA_restore_extended:
1952 case DW_CFA_undefined:
1953 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1954 fputc ('\n', asm_out_file);
1956 case DW_CFA_same_value:
1957 case DW_CFA_def_cfa_register:
1958 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1959 fputc ('\n', asm_out_file);
1961 case DW_CFA_register:
1962 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1963 fputc ('\n', asm_out_file);
1964 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1965 fputc ('\n', asm_out_file);
1967 case DW_CFA_def_cfa_offset:
1968 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1969 fputc ('\n', asm_out_file);
1971 case DW_CFA_GNU_window_save:
1973 case DW_CFA_GNU_args_size:
1974 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1975 fputc ('\n', asm_out_file);
1977 case DW_CFA_def_cfa_expression:
1978 output_cfa_loc (cfi);
1986 /* Output the call frame information used to used to record information
1987 that relates to calculating the frame pointer, and records the
1988 location of saved registers. */
1991 output_call_frame_info (for_eh)
1994 register unsigned long i;
1995 register dw_fde_ref fde;
1996 register dw_cfi_ref cfi;
1997 char l1[20], l2[20];
1998 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2002 /* Do we want to include a pointer to the exception table? */
2003 int eh_ptr = for_eh && exception_table_p ();
2005 /* If we don't have any functions we'll want to unwind out of, don't
2006 emit any EH unwind information. */
2009 for (i = 0; i < fde_table_in_use; ++i)
2010 if (! fde_table[i].nothrow)
2016 fputc ('\n', asm_out_file);
2018 /* We're going to be generating comments, so turn on app. */
2024 #ifdef EH_FRAME_SECTION
2025 EH_FRAME_SECTION ();
2027 tree label = get_file_function_name ('F');
2029 force_data_section ();
2030 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2031 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2032 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2034 assemble_label ("__FRAME_BEGIN__");
2037 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
2039 /* Output the CIE. */
2040 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2041 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2042 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2043 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
2045 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
2047 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
2050 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
2052 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
2055 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
2058 fputc ('\n', asm_out_file);
2059 ASM_OUTPUT_LABEL (asm_out_file, l1);
2062 /* Now that the CIE pointer is PC-relative for EH,
2063 use 0 to identify the CIE. */
2064 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2066 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
2069 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
2071 fputc ('\n', asm_out_file);
2072 if (! for_eh && DWARF_OFFSET_SIZE == 8)
2074 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
2075 fputc ('\n', asm_out_file);
2078 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
2080 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
2082 fputc ('\n', asm_out_file);
2085 /* The CIE contains a pointer to the exception region info for the
2086 frame. Make the augmentation string three bytes (including the
2087 trailing null) so the pointer is 4-byte aligned. The Solaris ld
2088 can't handle unaligned relocs. */
2091 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
2092 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
2096 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
2098 fputc ('\n', asm_out_file);
2100 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
2102 fprintf (asm_out_file, "\t%s pointer to exception region info",
2107 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
2109 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
2113 fputc ('\n', asm_out_file);
2116 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
2118 fputc ('\n', asm_out_file);
2119 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
2121 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
2123 fputc ('\n', asm_out_file);
2124 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
2126 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
2128 fputc ('\n', asm_out_file);
2130 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2131 output_cfi (cfi, NULL);
2133 /* Pad the CIE out to an address sized boundary. */
2134 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2135 ASM_OUTPUT_LABEL (asm_out_file, l2);
2136 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2137 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
2139 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
2140 fputc ('\n', asm_out_file);
2143 /* Loop through all of the FDE's. */
2144 for (i = 0; i < fde_table_in_use; ++i)
2146 fde = &fde_table[i];
2148 /* Don't emit EH unwind info for leaf functions. */
2149 if (for_eh && fde->nothrow)
2152 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2153 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2154 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2155 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i * 2);
2157 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
2159 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
2162 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
2164 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
2167 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
2168 fputc ('\n', asm_out_file);
2169 ASM_OUTPUT_LABEL (asm_out_file, l1);
2171 /* ??? This always emits a 4 byte offset when for_eh is true, but it
2172 emits a target dependent sized offset when for_eh is not true.
2173 This inconsistency may confuse gdb. The only case where we need a
2174 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
2175 compatibility if we emit a 4 byte offset. We need a 4 byte offset
2176 though in order to be compatible with the dwarf_fde struct in frame.c.
2177 If the for_eh case is changed, then the struct in frame.c has
2178 to be adjusted appropriately. */
2180 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
2182 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
2184 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
2186 fputc ('\n', asm_out_file);
2187 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
2189 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
2191 fputc ('\n', asm_out_file);
2192 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
2193 fde->dw_fde_end, fde->dw_fde_begin);
2195 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
2197 fputc ('\n', asm_out_file);
2199 /* Loop through the Call Frame Instructions associated with
2201 fde->dw_fde_current_label = fde->dw_fde_begin;
2202 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2203 output_cfi (cfi, fde);
2205 /* Pad the FDE out to an address sized boundary. */
2206 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2207 ASM_OUTPUT_LABEL (asm_out_file, l2);
2208 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2209 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
2211 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
2212 fputc ('\n', asm_out_file);
2215 #ifndef EH_FRAME_SECTION
2218 /* Emit terminating zero for table. */
2219 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2220 fputc ('\n', asm_out_file);
2223 #ifdef MIPS_DEBUGGING_INFO
2224 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2225 get a value of 0. Putting .align 0 after the label fixes it. */
2226 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2229 /* Turn off app to make assembly quicker. */
2234 /* Output a marker (i.e. a label) for the beginning of a function, before
2238 dwarf2out_begin_prologue ()
2240 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2241 register dw_fde_ref fde;
2243 ++current_funcdef_number;
2245 function_section (current_function_decl);
2246 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2247 current_funcdef_number);
2248 ASM_OUTPUT_LABEL (asm_out_file, label);
2249 current_function_func_begin_label = get_identifier (label);
2251 /* Expand the fde table if necessary. */
2252 if (fde_table_in_use == fde_table_allocated)
2254 fde_table_allocated += FDE_TABLE_INCREMENT;
2256 = (dw_fde_ref) xrealloc (fde_table,
2257 fde_table_allocated * sizeof (dw_fde_node));
2260 /* Record the FDE associated with this function. */
2261 current_funcdef_fde = fde_table_in_use;
2263 /* Add the new FDE at the end of the fde_table. */
2264 fde = &fde_table[fde_table_in_use++];
2265 fde->dw_fde_begin = xstrdup (label);
2266 fde->dw_fde_current_label = NULL;
2267 fde->dw_fde_end = NULL;
2268 fde->dw_fde_cfi = NULL;
2269 fde->nothrow = current_function_nothrow;
2271 args_size = old_args_size = 0;
2274 /* Output a marker (i.e. a label) for the absolute end of the generated code
2275 for a function definition. This gets called *after* the epilogue code has
2279 dwarf2out_end_epilogue ()
2282 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2284 /* Output a label to mark the endpoint of the code generated for this
2286 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2287 ASM_OUTPUT_LABEL (asm_out_file, label);
2288 fde = &fde_table[fde_table_in_use - 1];
2289 fde->dw_fde_end = xstrdup (label);
2293 dwarf2out_frame_init ()
2295 /* Allocate the initial hunk of the fde_table. */
2296 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2297 fde_table_allocated = FDE_TABLE_INCREMENT;
2298 fde_table_in_use = 0;
2300 /* Generate the CFA instructions common to all FDE's. Do it now for the
2301 sake of lookup_cfa. */
2303 #ifdef DWARF2_UNWIND_INFO
2304 /* On entry, the Canonical Frame Address is at SP. */
2305 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2306 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2311 dwarf2out_frame_finish ()
2313 /* Output call frame information. */
2314 #ifdef MIPS_DEBUGGING_INFO
2315 if (write_symbols == DWARF2_DEBUG)
2316 output_call_frame_info (0);
2317 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2318 output_call_frame_info (1);
2320 if (write_symbols == DWARF2_DEBUG
2321 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2322 output_call_frame_info (1);
2326 /* And now, the subset of the debugging information support code necessary
2327 for emitting location expressions. */
2329 typedef struct dw_val_struct *dw_val_ref;
2330 typedef struct die_struct *dw_die_ref;
2331 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2333 /* Each DIE may have a series of attribute/value pairs. Values
2334 can take on several forms. The forms that are used in this
2335 implementation are listed below. */
2342 dw_val_class_unsigned_const,
2343 dw_val_class_long_long,
2346 dw_val_class_die_ref,
2347 dw_val_class_fde_ref,
2348 dw_val_class_lbl_id,
2349 dw_val_class_lbl_offset,
2354 /* Describe a double word constant value. */
2355 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2357 typedef struct dw_long_long_struct
2364 /* Describe a floating point constant value. */
2366 typedef struct dw_fp_struct
2373 /* The dw_val_node describes an attribute's value, as it is
2374 represented internally. */
2376 typedef struct dw_val_struct
2378 dw_val_class val_class;
2382 dw_loc_descr_ref val_loc;
2384 long unsigned val_unsigned;
2385 dw_long_long_const val_long_long;
2386 dw_float_const val_float;
2391 unsigned val_fde_index;
2394 unsigned char val_flag;
2400 /* Locations in memory are described using a sequence of stack machine
2403 typedef struct dw_loc_descr_struct
2405 dw_loc_descr_ref dw_loc_next;
2406 enum dwarf_location_atom dw_loc_opc;
2407 dw_val_node dw_loc_oprnd1;
2408 dw_val_node dw_loc_oprnd2;
2413 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2414 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2417 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2419 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2420 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2421 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2422 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2424 /* Convert a DWARF stack opcode into its string name. */
2427 dwarf_stack_op_name (op)
2428 register unsigned op;
2433 return "DW_OP_addr";
2435 return "DW_OP_deref";
2437 return "DW_OP_const1u";
2439 return "DW_OP_const1s";
2441 return "DW_OP_const2u";
2443 return "DW_OP_const2s";
2445 return "DW_OP_const4u";
2447 return "DW_OP_const4s";
2449 return "DW_OP_const8u";
2451 return "DW_OP_const8s";
2453 return "DW_OP_constu";
2455 return "DW_OP_consts";
2459 return "DW_OP_drop";
2461 return "DW_OP_over";
2463 return "DW_OP_pick";
2465 return "DW_OP_swap";
2469 return "DW_OP_xderef";
2477 return "DW_OP_minus";
2489 return "DW_OP_plus";
2490 case DW_OP_plus_uconst:
2491 return "DW_OP_plus_uconst";
2497 return "DW_OP_shra";
2515 return "DW_OP_skip";
2517 return "DW_OP_lit0";
2519 return "DW_OP_lit1";
2521 return "DW_OP_lit2";
2523 return "DW_OP_lit3";
2525 return "DW_OP_lit4";
2527 return "DW_OP_lit5";
2529 return "DW_OP_lit6";
2531 return "DW_OP_lit7";
2533 return "DW_OP_lit8";
2535 return "DW_OP_lit9";
2537 return "DW_OP_lit10";
2539 return "DW_OP_lit11";
2541 return "DW_OP_lit12";
2543 return "DW_OP_lit13";
2545 return "DW_OP_lit14";
2547 return "DW_OP_lit15";
2549 return "DW_OP_lit16";
2551 return "DW_OP_lit17";
2553 return "DW_OP_lit18";
2555 return "DW_OP_lit19";
2557 return "DW_OP_lit20";
2559 return "DW_OP_lit21";
2561 return "DW_OP_lit22";
2563 return "DW_OP_lit23";
2565 return "DW_OP_lit24";
2567 return "DW_OP_lit25";
2569 return "DW_OP_lit26";
2571 return "DW_OP_lit27";
2573 return "DW_OP_lit28";
2575 return "DW_OP_lit29";
2577 return "DW_OP_lit30";
2579 return "DW_OP_lit31";
2581 return "DW_OP_reg0";
2583 return "DW_OP_reg1";
2585 return "DW_OP_reg2";
2587 return "DW_OP_reg3";
2589 return "DW_OP_reg4";
2591 return "DW_OP_reg5";
2593 return "DW_OP_reg6";
2595 return "DW_OP_reg7";
2597 return "DW_OP_reg8";
2599 return "DW_OP_reg9";
2601 return "DW_OP_reg10";
2603 return "DW_OP_reg11";
2605 return "DW_OP_reg12";
2607 return "DW_OP_reg13";
2609 return "DW_OP_reg14";
2611 return "DW_OP_reg15";
2613 return "DW_OP_reg16";
2615 return "DW_OP_reg17";
2617 return "DW_OP_reg18";
2619 return "DW_OP_reg19";
2621 return "DW_OP_reg20";
2623 return "DW_OP_reg21";
2625 return "DW_OP_reg22";
2627 return "DW_OP_reg23";
2629 return "DW_OP_reg24";
2631 return "DW_OP_reg25";
2633 return "DW_OP_reg26";
2635 return "DW_OP_reg27";
2637 return "DW_OP_reg28";
2639 return "DW_OP_reg29";
2641 return "DW_OP_reg30";
2643 return "DW_OP_reg31";
2645 return "DW_OP_breg0";
2647 return "DW_OP_breg1";
2649 return "DW_OP_breg2";
2651 return "DW_OP_breg3";
2653 return "DW_OP_breg4";
2655 return "DW_OP_breg5";
2657 return "DW_OP_breg6";
2659 return "DW_OP_breg7";
2661 return "DW_OP_breg8";
2663 return "DW_OP_breg9";
2665 return "DW_OP_breg10";
2667 return "DW_OP_breg11";
2669 return "DW_OP_breg12";
2671 return "DW_OP_breg13";
2673 return "DW_OP_breg14";
2675 return "DW_OP_breg15";
2677 return "DW_OP_breg16";
2679 return "DW_OP_breg17";
2681 return "DW_OP_breg18";
2683 return "DW_OP_breg19";
2685 return "DW_OP_breg20";
2687 return "DW_OP_breg21";
2689 return "DW_OP_breg22";
2691 return "DW_OP_breg23";
2693 return "DW_OP_breg24";
2695 return "DW_OP_breg25";
2697 return "DW_OP_breg26";
2699 return "DW_OP_breg27";
2701 return "DW_OP_breg28";
2703 return "DW_OP_breg29";
2705 return "DW_OP_breg30";
2707 return "DW_OP_breg31";
2709 return "DW_OP_regx";
2711 return "DW_OP_fbreg";
2713 return "DW_OP_bregx";
2715 return "DW_OP_piece";
2716 case DW_OP_deref_size:
2717 return "DW_OP_deref_size";
2718 case DW_OP_xderef_size:
2719 return "DW_OP_xderef_size";
2723 return "OP_<unknown>";
2727 /* Return a pointer to a newly allocated location description. Location
2728 descriptions are simple expression terms that can be strung
2729 together to form more complicated location (address) descriptions. */
2731 static inline dw_loc_descr_ref
2732 new_loc_descr (op, oprnd1, oprnd2)
2733 register enum dwarf_location_atom op;
2734 register unsigned long oprnd1;
2735 register unsigned long oprnd2;
2737 /* Use xcalloc here so we clear out all of the long_long constant in
2739 register dw_loc_descr_ref descr
2740 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2742 descr->dw_loc_opc = op;
2743 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2744 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2745 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2746 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2751 /* Add a location description term to a location description expression. */
2754 add_loc_descr (list_head, descr)
2755 register dw_loc_descr_ref *list_head;
2756 register dw_loc_descr_ref descr;
2758 register dw_loc_descr_ref *d;
2760 /* Find the end of the chain. */
2761 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2767 /* Return the size of a location descriptor. */
2769 static unsigned long
2770 size_of_loc_descr (loc)
2771 register dw_loc_descr_ref loc;
2773 register unsigned long size = 1;
2775 switch (loc->dw_loc_opc)
2778 size += DWARF2_ADDR_SIZE;
2797 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2800 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2805 case DW_OP_plus_uconst:
2806 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2844 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2847 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2850 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2853 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2854 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2857 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2859 case DW_OP_deref_size:
2860 case DW_OP_xderef_size:
2870 /* Return the size of a series of location descriptors. */
2872 static unsigned long
2874 register dw_loc_descr_ref loc;
2876 register unsigned long size = 0;
2878 for (; loc != NULL; loc = loc->dw_loc_next)
2880 loc->dw_loc_addr = size;
2881 size += size_of_loc_descr (loc);
2887 /* Output location description stack opcode's operands (if any). */
2890 output_loc_operands (loc)
2891 register dw_loc_descr_ref loc;
2893 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2894 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2896 switch (loc->dw_loc_opc)
2898 #ifdef DWARF2_DEBUGGING_INFO
2900 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
2901 fputc ('\n', asm_out_file);
2905 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2906 fputc ('\n', asm_out_file);
2910 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
2911 fputc ('\n', asm_out_file);
2916 fputc ('\n', asm_out_file);
2923 if (val1->val_class == dw_val_class_loc)
2924 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2928 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, offset);
2929 fputc ('\n', asm_out_file);
2942 /* We currently don't make any attempt to make sure these are
2943 aligned properly like we do for the main unwind info, so
2944 don't support emitting things larger than a byte if we're
2945 only doing unwinding. */
2950 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2951 fputc ('\n', asm_out_file);
2954 output_uleb128 (val1->v.val_unsigned);
2955 fputc ('\n', asm_out_file);
2958 output_sleb128 (val1->v.val_int);
2959 fputc ('\n', asm_out_file);
2962 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
2963 fputc ('\n', asm_out_file);
2965 case DW_OP_plus_uconst:
2966 output_uleb128 (val1->v.val_unsigned);
2967 fputc ('\n', asm_out_file);
3001 output_sleb128 (val1->v.val_int);
3002 fputc ('\n', asm_out_file);
3005 output_uleb128 (val1->v.val_unsigned);
3006 fputc ('\n', asm_out_file);
3009 output_sleb128 (val1->v.val_int);
3010 fputc ('\n', asm_out_file);
3013 output_uleb128 (val1->v.val_unsigned);
3014 fputc ('\n', asm_out_file);
3015 output_sleb128 (val2->v.val_int);
3016 fputc ('\n', asm_out_file);
3019 output_uleb128 (val1->v.val_unsigned);
3020 fputc ('\n', asm_out_file);
3022 case DW_OP_deref_size:
3023 case DW_OP_xderef_size:
3024 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3025 fputc ('\n', asm_out_file);
3028 /* Other codes have no operands. */
3033 /* Output a sequence of location operations. */
3036 output_loc_sequence (loc)
3037 dw_loc_descr_ref loc;
3039 for (; loc != NULL; loc = loc->dw_loc_next)
3041 /* Output the opcode. */
3042 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
3044 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
3045 dwarf_stack_op_name (loc->dw_loc_opc));
3047 fputc ('\n', asm_out_file);
3049 /* Output the operand(s) (if any). */
3050 output_loc_operands (loc);
3054 /* This routine will generate the correct assembly data for a location
3055 description based on a cfi entry with a complex address. */
3058 output_cfa_loc (cfi)
3061 dw_loc_descr_ref loc;
3064 /* Output the size of the block. */
3065 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3066 size = size_of_locs (loc);
3067 output_uleb128 (size);
3068 fputc ('\n', asm_out_file);
3070 /* Now output the operations themselves. */
3071 output_loc_sequence (loc);
3074 /* This function builds a dwarf location descriptor seqeunce from
3075 a dw_cfa_location. */
3077 static struct dw_loc_descr_struct *
3079 dw_cfa_location *cfa;
3081 struct dw_loc_descr_struct *head, *tmp;
3083 if (cfa->indirect == 0)
3086 if (cfa->base_offset)
3089 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3091 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3093 else if (cfa->reg <= 31)
3094 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3096 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3097 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3098 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3099 add_loc_descr (&head, tmp);
3100 if (cfa->offset != 0)
3102 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3103 add_loc_descr (&head, tmp);
3108 /* This function fills in aa dw_cfa_location structure from a
3109 dwarf location descriptor sequence. */
3112 get_cfa_from_loc_descr (cfa, loc)
3113 dw_cfa_location *cfa;
3114 struct dw_loc_descr_struct *loc;
3116 struct dw_loc_descr_struct *ptr;
3118 cfa->base_offset = 0;
3122 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3124 enum dwarf_location_atom op = ptr->dw_loc_opc;
3159 cfa->reg = op - DW_OP_reg0;
3162 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3196 cfa->reg = op - DW_OP_breg0;
3197 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3200 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3201 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3206 case DW_OP_plus_uconst:
3207 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3210 internal_error ("DW_LOC_OP %s not implememnted\n",
3211 dwarf_stack_op_name (ptr->dw_loc_opc));
3215 #endif /* .debug_frame support */
3217 /* And now, the support for symbolic debugging information. */
3218 #ifdef DWARF2_DEBUGGING_INFO
3220 /* NOTE: In the comments in this file, many references are made to
3221 "Debugging Information Entries". This term is abbreviated as `DIE'
3222 throughout the remainder of this file. */
3224 /* An internal representation of the DWARF output is built, and then
3225 walked to generate the DWARF debugging info. The walk of the internal
3226 representation is done after the entire program has been compiled.
3227 The types below are used to describe the internal representation. */
3229 /* Various DIE's use offsets relative to the beginning of the
3230 .debug_info section to refer to each other. */
3232 typedef long int dw_offset;
3234 /* Define typedefs here to avoid circular dependencies. */
3236 typedef struct dw_attr_struct *dw_attr_ref;
3237 typedef struct dw_line_info_struct *dw_line_info_ref;
3238 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3239 typedef struct pubname_struct *pubname_ref;
3240 typedef dw_die_ref *arange_ref;
3242 /* Each entry in the line_info_table maintains the file and
3243 line number associated with the label generated for that
3244 entry. The label gives the PC value associated with
3245 the line number entry. */
3247 typedef struct dw_line_info_struct
3249 unsigned long dw_file_num;
3250 unsigned long dw_line_num;
3254 /* Line information for functions in separate sections; each one gets its
3256 typedef struct dw_separate_line_info_struct
3258 unsigned long dw_file_num;
3259 unsigned long dw_line_num;
3260 unsigned long function;
3262 dw_separate_line_info_entry;
3264 /* Each DIE attribute has a field specifying the attribute kind,
3265 a link to the next attribute in the chain, and an attribute value.
3266 Attributes are typically linked below the DIE they modify. */
3268 typedef struct dw_attr_struct
3270 enum dwarf_attribute dw_attr;
3271 dw_attr_ref dw_attr_next;
3272 dw_val_node dw_attr_val;
3276 /* The Debugging Information Entry (DIE) structure */
3278 typedef struct die_struct
3280 enum dwarf_tag die_tag;
3282 dw_attr_ref die_attr;
3283 dw_die_ref die_parent;
3284 dw_die_ref die_child;
3286 dw_offset die_offset;
3287 unsigned long die_abbrev;
3292 /* The pubname structure */
3294 typedef struct pubname_struct
3301 /* The limbo die list structure. */
3302 typedef struct limbo_die_struct
3305 struct limbo_die_struct *next;
3309 /* How to start an assembler comment. */
3310 #ifndef ASM_COMMENT_START
3311 #define ASM_COMMENT_START ";#"
3314 /* Define a macro which returns non-zero for a TYPE_DECL which was
3315 implicitly generated for a tagged type.
3317 Note that unlike the gcc front end (which generates a NULL named
3318 TYPE_DECL node for each complete tagged type, each array type, and
3319 each function type node created) the g++ front end generates a
3320 _named_ TYPE_DECL node for each tagged type node created.
3321 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3322 generate a DW_TAG_typedef DIE for them. */
3324 #define TYPE_DECL_IS_STUB(decl) \
3325 (DECL_NAME (decl) == NULL_TREE \
3326 || (DECL_ARTIFICIAL (decl) \
3327 && is_tagged_type (TREE_TYPE (decl)) \
3328 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3329 /* This is necessary for stub decls that \
3330 appear in nested inline functions. */ \
3331 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3332 && (decl_ultimate_origin (decl) \
3333 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3335 /* Information concerning the compilation unit's programming
3336 language, and compiler version. */
3338 extern int flag_traditional;
3340 /* Fixed size portion of the DWARF compilation unit header. */
3341 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3343 /* Fixed size portion of debugging line information prolog. */
3344 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3346 /* Fixed size portion of public names info. */
3347 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3349 /* Fixed size portion of the address range info. */
3350 #define DWARF_ARANGES_HEADER_SIZE \
3351 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3352 - DWARF_OFFSET_SIZE)
3354 /* Size of padding portion in the address range info. It must be
3355 aligned to twice the pointer size. */
3356 #define DWARF_ARANGES_PAD_SIZE \
3357 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3358 - (2 * DWARF_OFFSET_SIZE + 4))
3360 /* Use assembler line directives if available. */
3361 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3362 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3363 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3365 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3369 /* Define the architecture-dependent minimum instruction length (in bytes).
3370 In this implementation of DWARF, this field is used for information
3371 purposes only. Since GCC generates assembly language, we have
3372 no a priori knowledge of how many instruction bytes are generated
3373 for each source line, and therefore can use only the DW_LNE_set_address
3374 and DW_LNS_fixed_advance_pc line information commands. */
3376 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3377 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3380 /* Minimum line offset in a special line info. opcode.
3381 This value was chosen to give a reasonable range of values. */
3382 #define DWARF_LINE_BASE -10
3384 /* First special line opcde - leave room for the standard opcodes. */
3385 #define DWARF_LINE_OPCODE_BASE 10
3387 /* Range of line offsets in a special line info. opcode. */
3388 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3390 /* Flag that indicates the initial value of the is_stmt_start flag.
3391 In the present implementation, we do not mark any lines as
3392 the beginning of a source statement, because that information
3393 is not made available by the GCC front-end. */
3394 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3396 /* This location is used by calc_die_sizes() to keep track
3397 the offset of each DIE within the .debug_info section. */
3398 static unsigned long next_die_offset;
3400 /* Record the root of the DIE's built for the current compilation unit. */
3401 static dw_die_ref comp_unit_die;
3403 /* A list of DIEs with a NULL parent waiting to be relocated. */
3404 static limbo_die_node *limbo_die_list = 0;
3406 /* Structure used by lookup_filename to manage sets of filenames. */
3412 unsigned last_lookup_index;
3415 /* Size (in elements) of increments by which we may expand the filename
3417 #define FILE_TABLE_INCREMENT 64
3419 /* Filenames referenced by declarations this compilation unit. */
3420 static struct file_table decl_file_table;
3422 /* Filenames referenced by line numbers in this compilation unit. */
3423 static struct file_table line_file_table;
3425 /* Local pointer to the name of the main input file. Initialized in
3427 static const char *primary_filename;
3429 /* A pointer to the base of a table of references to DIE's that describe
3430 declarations. The table is indexed by DECL_UID() which is a unique
3431 number identifying each decl. */
3432 static dw_die_ref *decl_die_table;
3434 /* Number of elements currently allocated for the decl_die_table. */
3435 static unsigned decl_die_table_allocated;
3437 /* Number of elements in decl_die_table currently in use. */
3438 static unsigned decl_die_table_in_use;
3440 /* Size (in elements) of increments by which we may expand the
3442 #define DECL_DIE_TABLE_INCREMENT 256
3444 /* A pointer to the base of a table of references to declaration
3445 scopes. This table is a display which tracks the nesting
3446 of declaration scopes at the current scope and containing
3447 scopes. This table is used to find the proper place to
3448 define type declaration DIE's. */
3449 static tree *decl_scope_table;
3451 /* Number of elements currently allocated for the decl_scope_table. */
3452 static int decl_scope_table_allocated;
3454 /* Current level of nesting of declaration scopes. */
3455 static int decl_scope_depth;
3457 /* Size (in elements) of increments by which we may expand the
3458 decl_scope_table. */
3459 #define DECL_SCOPE_TABLE_INCREMENT 64
3461 /* A pointer to the base of a list of references to DIE's that
3462 are uniquely identified by their tag, presence/absence of
3463 children DIE's, and list of attribute/value pairs. */
3464 static dw_die_ref *abbrev_die_table;
3466 /* Number of elements currently allocated for abbrev_die_table. */
3467 static unsigned abbrev_die_table_allocated;
3469 /* Number of elements in type_die_table currently in use. */
3470 static unsigned abbrev_die_table_in_use;
3472 /* Size (in elements) of increments by which we may expand the
3473 abbrev_die_table. */
3474 #define ABBREV_DIE_TABLE_INCREMENT 256
3476 /* A pointer to the base of a table that contains line information
3477 for each source code line in .text in the compilation unit. */
3478 static dw_line_info_ref line_info_table;
3480 /* Number of elements currently allocated for line_info_table. */
3481 static unsigned line_info_table_allocated;
3483 /* Number of elements in separate_line_info_table currently in use. */
3484 static unsigned separate_line_info_table_in_use;
3486 /* A pointer to the base of a table that contains line information
3487 for each source code line outside of .text in the compilation unit. */
3488 static dw_separate_line_info_ref separate_line_info_table;
3490 /* Number of elements currently allocated for separate_line_info_table. */
3491 static unsigned separate_line_info_table_allocated;
3493 /* Number of elements in line_info_table currently in use. */
3494 static unsigned line_info_table_in_use;
3496 /* Size (in elements) of increments by which we may expand the
3498 #define LINE_INFO_TABLE_INCREMENT 1024
3500 /* A pointer to the base of a table that contains a list of publicly
3501 accessible names. */
3502 static pubname_ref pubname_table;
3504 /* Number of elements currently allocated for pubname_table. */
3505 static unsigned pubname_table_allocated;
3507 /* Number of elements in pubname_table currently in use. */
3508 static unsigned pubname_table_in_use;
3510 /* Size (in elements) of increments by which we may expand the
3512 #define PUBNAME_TABLE_INCREMENT 64
3514 /* A pointer to the base of a table that contains a list of publicly
3515 accessible names. */
3516 static arange_ref arange_table;
3518 /* Number of elements currently allocated for arange_table. */
3519 static unsigned arange_table_allocated;
3521 /* Number of elements in arange_table currently in use. */
3522 static unsigned arange_table_in_use;
3524 /* Size (in elements) of increments by which we may expand the
3526 #define ARANGE_TABLE_INCREMENT 64
3528 /* A pointer to the base of a list of incomplete types which might be
3529 completed at some later time. */
3531 static tree *incomplete_types_list;
3533 /* Number of elements currently allocated for the incomplete_types_list. */
3534 static unsigned incomplete_types_allocated;
3536 /* Number of elements of incomplete_types_list currently in use. */
3537 static unsigned incomplete_types;
3539 /* Size (in elements) of increments by which we may expand the incomplete
3540 types list. Actually, a single hunk of space of this size should
3541 be enough for most typical programs. */
3542 #define INCOMPLETE_TYPES_INCREMENT 64
3544 /* Record whether the function being analyzed contains inlined functions. */
3545 static int current_function_has_inlines;
3546 #if 0 && defined (MIPS_DEBUGGING_INFO)
3547 static int comp_unit_has_inlines;
3550 /* Array of RTXes referenced by the debugging information, which therefore
3551 must be kept around forever. We do this rather than perform GC on
3552 the dwarf info because almost all of the dwarf info lives forever, and
3553 it's easier to support non-GC frontends this way. */
3554 static varray_type used_rtx_varray;
3556 /* Forward declarations for functions defined in this file. */
3558 static int is_pseudo_reg PARAMS ((rtx));
3559 static tree type_main_variant PARAMS ((tree));
3560 static int is_tagged_type PARAMS ((tree));
3561 static const char *dwarf_tag_name PARAMS ((unsigned));
3562 static const char *dwarf_attr_name PARAMS ((unsigned));
3563 static const char *dwarf_form_name PARAMS ((unsigned));
3565 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3567 static tree decl_ultimate_origin PARAMS ((tree));
3568 static tree block_ultimate_origin PARAMS ((tree));
3569 static tree decl_class_context PARAMS ((tree));
3570 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3571 static void add_AT_flag PARAMS ((dw_die_ref,
3572 enum dwarf_attribute,
3574 static void add_AT_int PARAMS ((dw_die_ref,
3575 enum dwarf_attribute, long));
3576 static void add_AT_unsigned PARAMS ((dw_die_ref,
3577 enum dwarf_attribute,
3579 static void add_AT_long_long PARAMS ((dw_die_ref,
3580 enum dwarf_attribute,
3583 static void add_AT_float PARAMS ((dw_die_ref,
3584 enum dwarf_attribute,
3586 static void add_AT_string PARAMS ((dw_die_ref,
3587 enum dwarf_attribute,
3589 static void add_AT_die_ref PARAMS ((dw_die_ref,
3590 enum dwarf_attribute,
3592 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3593 enum dwarf_attribute,
3595 static void add_AT_loc PARAMS ((dw_die_ref,
3596 enum dwarf_attribute,
3598 static void add_AT_addr PARAMS ((dw_die_ref,
3599 enum dwarf_attribute,
3601 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3602 enum dwarf_attribute,
3604 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3605 enum dwarf_attribute,
3607 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3608 enum dwarf_attribute));
3609 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3610 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3611 static const char *get_AT_string PARAMS ((dw_die_ref,
3612 enum dwarf_attribute));
3613 static int get_AT_flag PARAMS ((dw_die_ref,
3614 enum dwarf_attribute));
3615 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3616 enum dwarf_attribute));
3617 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3618 enum dwarf_attribute));
3619 static int is_c_family PARAMS ((void));
3620 static int is_java PARAMS ((void));
3621 static int is_fortran PARAMS ((void));
3622 static void remove_AT PARAMS ((dw_die_ref,
3623 enum dwarf_attribute));
3624 static void remove_children PARAMS ((dw_die_ref));
3625 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3626 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3627 static dw_die_ref lookup_type_die PARAMS ((tree));
3628 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3629 static dw_die_ref lookup_decl_die PARAMS ((tree));
3630 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3631 static void print_spaces PARAMS ((FILE *));
3632 static void print_die PARAMS ((dw_die_ref, FILE *));
3633 static void print_dwarf_line_table PARAMS ((FILE *));
3634 static void reverse_die_lists PARAMS ((dw_die_ref));
3635 static void reverse_all_dies PARAMS ((dw_die_ref));
3636 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3637 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3638 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3639 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3640 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3641 static void compute_section_prefix PARAMS ((dw_die_ref));
3642 static int is_type_die PARAMS ((dw_die_ref));
3643 static int is_comdat_die PARAMS ((dw_die_ref));
3644 static int is_symbol_die PARAMS ((dw_die_ref));
3645 static char *gen_internal_sym PARAMS ((void));
3646 static void assign_symbol_names PARAMS ((dw_die_ref));
3647 static void break_out_includes PARAMS ((dw_die_ref));
3648 static void add_sibling_attributes PARAMS ((dw_die_ref));
3649 static void build_abbrev_table PARAMS ((dw_die_ref));
3650 static unsigned long size_of_string PARAMS ((const char *));
3651 static int constant_size PARAMS ((long unsigned));
3652 static unsigned long size_of_die PARAMS ((dw_die_ref));
3653 static void calc_die_sizes PARAMS ((dw_die_ref));
3654 static void mark_dies PARAMS ((dw_die_ref));
3655 static void unmark_dies PARAMS ((dw_die_ref));
3656 static unsigned long size_of_line_prolog PARAMS ((void));
3657 static unsigned long size_of_pubnames PARAMS ((void));
3658 static unsigned long size_of_aranges PARAMS ((void));
3659 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3660 static void output_value_format PARAMS ((dw_attr_ref));
3661 static void output_abbrev_section PARAMS ((void));
3662 static void output_die_symbol PARAMS ((dw_die_ref));
3663 static void output_symbolic_ref PARAMS ((dw_die_ref));
3664 static void output_die PARAMS ((dw_die_ref));
3665 static void output_compilation_unit_header PARAMS ((void));
3666 static void output_comp_unit PARAMS ((dw_die_ref));
3667 static const char *dwarf2_name PARAMS ((tree, int));
3668 static void add_pubname PARAMS ((tree, dw_die_ref));
3669 static void output_pubnames PARAMS ((void));
3670 static void add_arange PARAMS ((tree, dw_die_ref));
3671 static void output_aranges PARAMS ((void));
3672 static void output_line_info PARAMS ((void));
3673 static void output_file_names PARAMS ((void));
3674 static dw_die_ref base_type_die PARAMS ((tree));
3675 static tree root_type PARAMS ((tree));
3676 static int is_base_type PARAMS ((tree));
3677 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3678 static int type_is_enum PARAMS ((tree));
3679 static unsigned int reg_number PARAMS ((rtx));
3680 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3681 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3682 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3683 static int is_based_loc PARAMS ((rtx));
3684 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3685 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3686 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3687 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3688 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3689 static tree field_type PARAMS ((tree));
3690 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3691 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3692 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3693 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3694 static void add_AT_location_description PARAMS ((dw_die_ref,
3695 enum dwarf_attribute, rtx));
3696 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3697 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3698 static rtx rtl_for_decl_location PARAMS ((tree));
3699 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3700 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3701 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3702 static void add_bound_info PARAMS ((dw_die_ref,
3703 enum dwarf_attribute, tree));
3704 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3705 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3706 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3707 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3708 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3709 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3710 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3711 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3712 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3713 static void push_decl_scope PARAMS ((tree));
3714 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3715 static void pop_decl_scope PARAMS ((void));
3716 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3718 static const char *type_tag PARAMS ((tree));
3719 static tree member_declared_type PARAMS ((tree));
3721 static const char *decl_start_label PARAMS ((tree));
3723 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3724 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3726 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3728 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3729 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3730 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3731 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3732 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3733 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3734 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3735 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3736 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3737 static void gen_label_die PARAMS ((tree, dw_die_ref));
3738 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3739 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3740 static void gen_field_die PARAMS ((tree, dw_die_ref));
3741 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3742 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3743 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3744 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3745 static void gen_member_die PARAMS ((tree, dw_die_ref));
3746 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3747 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3748 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3749 static void gen_type_die PARAMS ((tree, dw_die_ref));
3750 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3751 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3752 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3753 static int is_redundant_typedef PARAMS ((tree));
3754 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3755 static unsigned lookup_filename PARAMS ((struct file_table *,
3757 static void init_file_table PARAMS ((struct file_table *));
3758 static void add_incomplete_type PARAMS ((tree));
3759 static void retry_incomplete_types PARAMS ((void));
3760 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3761 static void gen_abstract_function PARAMS ((tree));
3762 static rtx save_rtx PARAMS ((rtx));
3763 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3764 static int file_info_cmp PARAMS ((const void *, const void *));
3766 /* Section names used to hold DWARF debugging information. */
3767 #ifndef DEBUG_INFO_SECTION
3768 #define DEBUG_INFO_SECTION ".debug_info"
3770 #ifndef ABBREV_SECTION
3771 #define ABBREV_SECTION ".debug_abbrev"
3773 #ifndef ARANGES_SECTION
3774 #define ARANGES_SECTION ".debug_aranges"
3776 #ifndef DW_MACINFO_SECTION
3777 #define DW_MACINFO_SECTION ".debug_macinfo"
3779 #ifndef DEBUG_LINE_SECTION
3780 #define DEBUG_LINE_SECTION ".debug_line"
3783 #define LOC_SECTION ".debug_loc"
3785 #ifndef PUBNAMES_SECTION
3786 #define PUBNAMES_SECTION ".debug_pubnames"
3789 #define STR_SECTION ".debug_str"
3792 /* Standard ELF section names for compiled code and data. */
3793 #ifndef TEXT_SECTION
3794 #define TEXT_SECTION ".text"
3796 #ifndef DATA_SECTION
3797 #define DATA_SECTION ".data"
3800 #define BSS_SECTION ".bss"
3803 /* Labels we insert at beginning sections we can reference instead of
3804 the section names themselves. */
3806 #ifndef TEXT_SECTION_LABEL
3807 #define TEXT_SECTION_LABEL "Ltext"
3809 #ifndef DEBUG_LINE_SECTION_LABEL
3810 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3812 #ifndef DEBUG_INFO_SECTION_LABEL
3813 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3815 #ifndef ABBREV_SECTION_LABEL
3816 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3819 /* Definitions of defaults for formats and names of various special
3820 (artificial) labels which may be generated within this file (when the -g
3821 options is used and DWARF_DEBUGGING_INFO is in effect.
3822 If necessary, these may be overridden from within the tm.h file, but
3823 typically, overriding these defaults is unnecessary. */
3825 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3826 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3827 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3828 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3829 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3831 #ifndef TEXT_END_LABEL
3832 #define TEXT_END_LABEL "Letext"
3834 #ifndef DATA_END_LABEL
3835 #define DATA_END_LABEL "Ledata"
3837 #ifndef BSS_END_LABEL
3838 #define BSS_END_LABEL "Lebss"
3840 #ifndef BLOCK_BEGIN_LABEL
3841 #define BLOCK_BEGIN_LABEL "LBB"
3843 #ifndef BLOCK_END_LABEL
3844 #define BLOCK_END_LABEL "LBE"
3846 #ifndef BODY_BEGIN_LABEL
3847 #define BODY_BEGIN_LABEL "Lbb"
3849 #ifndef BODY_END_LABEL
3850 #define BODY_END_LABEL "Lbe"
3852 #ifndef LINE_CODE_LABEL
3853 #define LINE_CODE_LABEL "LM"
3855 #ifndef SEPARATE_LINE_CODE_LABEL
3856 #define SEPARATE_LINE_CODE_LABEL "LSM"
3859 /* We allow a language front-end to designate a function that is to be
3860 called to "demangle" any name before it it put into a DIE. */
3862 static const char *(*demangle_name_func) PARAMS ((const char *));
3865 dwarf2out_set_demangle_name_func (func)
3866 const char *(*func) PARAMS ((const char *));
3868 demangle_name_func = func;
3871 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3872 that means adding it to used_rtx_varray. If not, that means making
3873 a copy on the permanent_obstack. */
3879 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3884 /* Test if rtl node points to a pseudo register. */
3890 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3891 || (GET_CODE (rtl) == SUBREG
3892 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3895 /* Return a reference to a type, with its const and volatile qualifiers
3899 type_main_variant (type)
3902 type = TYPE_MAIN_VARIANT (type);
3904 /* There really should be only one main variant among any group of variants
3905 of a given type (and all of the MAIN_VARIANT values for all members of
3906 the group should point to that one type) but sometimes the C front-end
3907 messes this up for array types, so we work around that bug here. */
3909 if (TREE_CODE (type) == ARRAY_TYPE)
3910 while (type != TYPE_MAIN_VARIANT (type))
3911 type = TYPE_MAIN_VARIANT (type);
3916 /* Return non-zero if the given type node represents a tagged type. */
3919 is_tagged_type (type)
3922 register enum tree_code code = TREE_CODE (type);
3924 return (code == RECORD_TYPE || code == UNION_TYPE
3925 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3928 /* Convert a DIE tag into its string name. */
3931 dwarf_tag_name (tag)
3932 register unsigned tag;
3936 case DW_TAG_padding:
3937 return "DW_TAG_padding";
3938 case DW_TAG_array_type:
3939 return "DW_TAG_array_type";
3940 case DW_TAG_class_type:
3941 return "DW_TAG_class_type";
3942 case DW_TAG_entry_point:
3943 return "DW_TAG_entry_point";
3944 case DW_TAG_enumeration_type:
3945 return "DW_TAG_enumeration_type";
3946 case DW_TAG_formal_parameter:
3947 return "DW_TAG_formal_parameter";
3948 case DW_TAG_imported_declaration:
3949 return "DW_TAG_imported_declaration";
3951 return "DW_TAG_label";
3952 case DW_TAG_lexical_block:
3953 return "DW_TAG_lexical_block";
3955 return "DW_TAG_member";
3956 case DW_TAG_pointer_type:
3957 return "DW_TAG_pointer_type";
3958 case DW_TAG_reference_type:
3959 return "DW_TAG_reference_type";
3960 case DW_TAG_compile_unit:
3961 return "DW_TAG_compile_unit";
3962 case DW_TAG_string_type:
3963 return "DW_TAG_string_type";
3964 case DW_TAG_structure_type:
3965 return "DW_TAG_structure_type";
3966 case DW_TAG_subroutine_type:
3967 return "DW_TAG_subroutine_type";
3968 case DW_TAG_typedef:
3969 return "DW_TAG_typedef";
3970 case DW_TAG_union_type:
3971 return "DW_TAG_union_type";
3972 case DW_TAG_unspecified_parameters:
3973 return "DW_TAG_unspecified_parameters";
3974 case DW_TAG_variant:
3975 return "DW_TAG_variant";
3976 case DW_TAG_common_block:
3977 return "DW_TAG_common_block";
3978 case DW_TAG_common_inclusion:
3979 return "DW_TAG_common_inclusion";
3980 case DW_TAG_inheritance:
3981 return "DW_TAG_inheritance";
3982 case DW_TAG_inlined_subroutine:
3983 return "DW_TAG_inlined_subroutine";
3985 return "DW_TAG_module";
3986 case DW_TAG_ptr_to_member_type:
3987 return "DW_TAG_ptr_to_member_type";
3988 case DW_TAG_set_type:
3989 return "DW_TAG_set_type";
3990 case DW_TAG_subrange_type:
3991 return "DW_TAG_subrange_type";
3992 case DW_TAG_with_stmt:
3993 return "DW_TAG_with_stmt";
3994 case DW_TAG_access_declaration:
3995 return "DW_TAG_access_declaration";
3996 case DW_TAG_base_type:
3997 return "DW_TAG_base_type";
3998 case DW_TAG_catch_block:
3999 return "DW_TAG_catch_block";
4000 case DW_TAG_const_type:
4001 return "DW_TAG_const_type";
4002 case DW_TAG_constant:
4003 return "DW_TAG_constant";
4004 case DW_TAG_enumerator:
4005 return "DW_TAG_enumerator";
4006 case DW_TAG_file_type:
4007 return "DW_TAG_file_type";
4009 return "DW_TAG_friend";
4010 case DW_TAG_namelist:
4011 return "DW_TAG_namelist";
4012 case DW_TAG_namelist_item:
4013 return "DW_TAG_namelist_item";
4014 case DW_TAG_packed_type:
4015 return "DW_TAG_packed_type";
4016 case DW_TAG_subprogram:
4017 return "DW_TAG_subprogram";
4018 case DW_TAG_template_type_param:
4019 return "DW_TAG_template_type_param";
4020 case DW_TAG_template_value_param:
4021 return "DW_TAG_template_value_param";
4022 case DW_TAG_thrown_type:
4023 return "DW_TAG_thrown_type";
4024 case DW_TAG_try_block:
4025 return "DW_TAG_try_block";
4026 case DW_TAG_variant_part:
4027 return "DW_TAG_variant_part";
4028 case DW_TAG_variable:
4029 return "DW_TAG_variable";
4030 case DW_TAG_volatile_type:
4031 return "DW_TAG_volatile_type";
4032 case DW_TAG_MIPS_loop:
4033 return "DW_TAG_MIPS_loop";
4034 case DW_TAG_format_label:
4035 return "DW_TAG_format_label";
4036 case DW_TAG_function_template:
4037 return "DW_TAG_function_template";
4038 case DW_TAG_class_template:
4039 return "DW_TAG_class_template";
4040 case DW_TAG_GNU_BINCL:
4041 return "DW_TAG_GNU_BINCL";
4042 case DW_TAG_GNU_EINCL:
4043 return "DW_TAG_GNU_EINCL";
4045 return "DW_TAG_<unknown>";
4049 /* Convert a DWARF attribute code into its string name. */
4052 dwarf_attr_name (attr)
4053 register unsigned attr;
4058 return "DW_AT_sibling";
4059 case DW_AT_location:
4060 return "DW_AT_location";
4062 return "DW_AT_name";
4063 case DW_AT_ordering:
4064 return "DW_AT_ordering";
4065 case DW_AT_subscr_data:
4066 return "DW_AT_subscr_data";
4067 case DW_AT_byte_size:
4068 return "DW_AT_byte_size";
4069 case DW_AT_bit_offset:
4070 return "DW_AT_bit_offset";
4071 case DW_AT_bit_size:
4072 return "DW_AT_bit_size";
4073 case DW_AT_element_list:
4074 return "DW_AT_element_list";
4075 case DW_AT_stmt_list:
4076 return "DW_AT_stmt_list";
4078 return "DW_AT_low_pc";
4080 return "DW_AT_high_pc";
4081 case DW_AT_language:
4082 return "DW_AT_language";
4084 return "DW_AT_member";
4086 return "DW_AT_discr";
4087 case DW_AT_discr_value:
4088 return "DW_AT_discr_value";
4089 case DW_AT_visibility:
4090 return "DW_AT_visibility";
4092 return "DW_AT_import";
4093 case DW_AT_string_length:
4094 return "DW_AT_string_length";
4095 case DW_AT_common_reference:
4096 return "DW_AT_common_reference";
4097 case DW_AT_comp_dir:
4098 return "DW_AT_comp_dir";
4099 case DW_AT_const_value:
4100 return "DW_AT_const_value";
4101 case DW_AT_containing_type:
4102 return "DW_AT_containing_type";
4103 case DW_AT_default_value:
4104 return "DW_AT_default_value";
4106 return "DW_AT_inline";
4107 case DW_AT_is_optional:
4108 return "DW_AT_is_optional";
4109 case DW_AT_lower_bound:
4110 return "DW_AT_lower_bound";
4111 case DW_AT_producer:
4112 return "DW_AT_producer";
4113 case DW_AT_prototyped:
4114 return "DW_AT_prototyped";
4115 case DW_AT_return_addr:
4116 return "DW_AT_return_addr";
4117 case DW_AT_start_scope:
4118 return "DW_AT_start_scope";
4119 case DW_AT_stride_size:
4120 return "DW_AT_stride_size";
4121 case DW_AT_upper_bound:
4122 return "DW_AT_upper_bound";
4123 case DW_AT_abstract_origin:
4124 return "DW_AT_abstract_origin";
4125 case DW_AT_accessibility:
4126 return "DW_AT_accessibility";
4127 case DW_AT_address_class:
4128 return "DW_AT_address_class";
4129 case DW_AT_artificial:
4130 return "DW_AT_artificial";
4131 case DW_AT_base_types:
4132 return "DW_AT_base_types";
4133 case DW_AT_calling_convention:
4134 return "DW_AT_calling_convention";
4136 return "DW_AT_count";
4137 case DW_AT_data_member_location:
4138 return "DW_AT_data_member_location";
4139 case DW_AT_decl_column:
4140 return "DW_AT_decl_column";
4141 case DW_AT_decl_file:
4142 return "DW_AT_decl_file";
4143 case DW_AT_decl_line:
4144 return "DW_AT_decl_line";
4145 case DW_AT_declaration:
4146 return "DW_AT_declaration";
4147 case DW_AT_discr_list:
4148 return "DW_AT_discr_list";
4149 case DW_AT_encoding:
4150 return "DW_AT_encoding";
4151 case DW_AT_external:
4152 return "DW_AT_external";
4153 case DW_AT_frame_base:
4154 return "DW_AT_frame_base";
4156 return "DW_AT_friend";
4157 case DW_AT_identifier_case:
4158 return "DW_AT_identifier_case";
4159 case DW_AT_macro_info:
4160 return "DW_AT_macro_info";
4161 case DW_AT_namelist_items:
4162 return "DW_AT_namelist_items";
4163 case DW_AT_priority:
4164 return "DW_AT_priority";
4166 return "DW_AT_segment";
4167 case DW_AT_specification:
4168 return "DW_AT_specification";
4169 case DW_AT_static_link:
4170 return "DW_AT_static_link";
4172 return "DW_AT_type";
4173 case DW_AT_use_location:
4174 return "DW_AT_use_location";
4175 case DW_AT_variable_parameter:
4176 return "DW_AT_variable_parameter";
4177 case DW_AT_virtuality:
4178 return "DW_AT_virtuality";
4179 case DW_AT_vtable_elem_location:
4180 return "DW_AT_vtable_elem_location";
4182 case DW_AT_MIPS_fde:
4183 return "DW_AT_MIPS_fde";
4184 case DW_AT_MIPS_loop_begin:
4185 return "DW_AT_MIPS_loop_begin";
4186 case DW_AT_MIPS_tail_loop_begin:
4187 return "DW_AT_MIPS_tail_loop_begin";
4188 case DW_AT_MIPS_epilog_begin:
4189 return "DW_AT_MIPS_epilog_begin";
4190 case DW_AT_MIPS_loop_unroll_factor:
4191 return "DW_AT_MIPS_loop_unroll_factor";
4192 case DW_AT_MIPS_software_pipeline_depth:
4193 return "DW_AT_MIPS_software_pipeline_depth";
4194 case DW_AT_MIPS_linkage_name:
4195 return "DW_AT_MIPS_linkage_name";
4196 case DW_AT_MIPS_stride:
4197 return "DW_AT_MIPS_stride";
4198 case DW_AT_MIPS_abstract_name:
4199 return "DW_AT_MIPS_abstract_name";
4200 case DW_AT_MIPS_clone_origin:
4201 return "DW_AT_MIPS_clone_origin";
4202 case DW_AT_MIPS_has_inlines:
4203 return "DW_AT_MIPS_has_inlines";
4205 case DW_AT_sf_names:
4206 return "DW_AT_sf_names";
4207 case DW_AT_src_info:
4208 return "DW_AT_src_info";
4209 case DW_AT_mac_info:
4210 return "DW_AT_mac_info";
4211 case DW_AT_src_coords:
4212 return "DW_AT_src_coords";
4213 case DW_AT_body_begin:
4214 return "DW_AT_body_begin";
4215 case DW_AT_body_end:
4216 return "DW_AT_body_end";
4218 return "DW_AT_<unknown>";
4222 /* Convert a DWARF value form code into its string name. */
4225 dwarf_form_name (form)
4226 register unsigned form;
4231 return "DW_FORM_addr";
4232 case DW_FORM_block2:
4233 return "DW_FORM_block2";
4234 case DW_FORM_block4:
4235 return "DW_FORM_block4";
4237 return "DW_FORM_data2";
4239 return "DW_FORM_data4";
4241 return "DW_FORM_data8";
4242 case DW_FORM_string:
4243 return "DW_FORM_string";
4245 return "DW_FORM_block";
4246 case DW_FORM_block1:
4247 return "DW_FORM_block1";
4249 return "DW_FORM_data1";
4251 return "DW_FORM_flag";
4253 return "DW_FORM_sdata";
4255 return "DW_FORM_strp";
4257 return "DW_FORM_udata";
4258 case DW_FORM_ref_addr:
4259 return "DW_FORM_ref_addr";
4261 return "DW_FORM_ref1";
4263 return "DW_FORM_ref2";
4265 return "DW_FORM_ref4";
4267 return "DW_FORM_ref8";
4268 case DW_FORM_ref_udata:
4269 return "DW_FORM_ref_udata";
4270 case DW_FORM_indirect:
4271 return "DW_FORM_indirect";
4273 return "DW_FORM_<unknown>";
4277 /* Convert a DWARF type code into its string name. */
4281 dwarf_type_encoding_name (enc)
4282 register unsigned enc;
4286 case DW_ATE_address:
4287 return "DW_ATE_address";
4288 case DW_ATE_boolean:
4289 return "DW_ATE_boolean";
4290 case DW_ATE_complex_float:
4291 return "DW_ATE_complex_float";
4293 return "DW_ATE_float";
4295 return "DW_ATE_signed";
4296 case DW_ATE_signed_char:
4297 return "DW_ATE_signed_char";
4298 case DW_ATE_unsigned:
4299 return "DW_ATE_unsigned";
4300 case DW_ATE_unsigned_char:
4301 return "DW_ATE_unsigned_char";
4303 return "DW_ATE_<unknown>";
4308 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4309 instance of an inlined instance of a decl 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 decl_ultimate_origin (decl)
4318 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4319 nodes in the function to point to themselves; ignore that if
4320 we're trying to output the abstract instance of this function. */
4321 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4324 #ifdef ENABLE_CHECKING
4325 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4326 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4327 most distant ancestor, this should never happen. */
4331 return DECL_ABSTRACT_ORIGIN (decl);
4334 /* Determine the "ultimate origin" of a block. The block may be an inlined
4335 instance of an inlined instance of a block which is local to an inline
4336 function, so we have to trace all of the way back through the origin chain
4337 to find out what sort of node actually served as the original seed for the
4341 block_ultimate_origin (block)
4342 register tree block;
4344 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4346 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4347 nodes in the function to point to themselves; ignore that if
4348 we're trying to output the abstract instance of this function. */
4349 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4352 if (immediate_origin == NULL_TREE)
4356 register tree ret_val;
4357 register tree lookahead = immediate_origin;
4361 ret_val = lookahead;
4362 lookahead = (TREE_CODE (ret_val) == BLOCK)
4363 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4366 while (lookahead != NULL && lookahead != ret_val);
4372 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4373 of a virtual function may refer to a base class, so we check the 'this'
4377 decl_class_context (decl)
4380 tree context = NULL_TREE;
4382 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4383 context = DECL_CONTEXT (decl);
4385 context = TYPE_MAIN_VARIANT
4386 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4388 if (context && !TYPE_P (context))
4389 context = NULL_TREE;
4394 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4395 addition order, and correct that in reverse_all_dies. */
4398 add_dwarf_attr (die, attr)
4399 register dw_die_ref die;
4400 register dw_attr_ref attr;
4402 if (die != NULL && attr != NULL)
4404 attr->dw_attr_next = die->die_attr;
4405 die->die_attr = attr;
4409 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4410 static inline dw_val_class
4414 return a->dw_attr_val.val_class;
4417 /* Add a flag value attribute to a DIE. */
4420 add_AT_flag (die, attr_kind, flag)
4421 register dw_die_ref die;
4422 register enum dwarf_attribute attr_kind;
4423 register unsigned flag;
4425 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4427 attr->dw_attr_next = NULL;
4428 attr->dw_attr = attr_kind;
4429 attr->dw_attr_val.val_class = dw_val_class_flag;
4430 attr->dw_attr_val.v.val_flag = flag;
4431 add_dwarf_attr (die, attr);
4434 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4435 static inline unsigned
4437 register dw_attr_ref a;
4439 if (a && AT_class (a) == dw_val_class_flag)
4440 return a->dw_attr_val.v.val_flag;
4445 /* Add a signed integer attribute value to a DIE. */
4448 add_AT_int (die, attr_kind, int_val)
4449 register dw_die_ref die;
4450 register enum dwarf_attribute attr_kind;
4451 register long int int_val;
4453 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4455 attr->dw_attr_next = NULL;
4456 attr->dw_attr = attr_kind;
4457 attr->dw_attr_val.val_class = dw_val_class_const;
4458 attr->dw_attr_val.v.val_int = int_val;
4459 add_dwarf_attr (die, attr);
4462 static inline long int AT_int PARAMS ((dw_attr_ref));
4463 static inline long int
4465 register dw_attr_ref a;
4467 if (a && AT_class (a) == dw_val_class_const)
4468 return a->dw_attr_val.v.val_int;
4473 /* Add an unsigned integer attribute value to a DIE. */
4476 add_AT_unsigned (die, attr_kind, unsigned_val)
4477 register dw_die_ref die;
4478 register enum dwarf_attribute attr_kind;
4479 register unsigned long unsigned_val;
4481 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4483 attr->dw_attr_next = NULL;
4484 attr->dw_attr = attr_kind;
4485 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4486 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4487 add_dwarf_attr (die, attr);
4490 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4491 static inline unsigned long
4493 register dw_attr_ref a;
4495 if (a && AT_class (a) == dw_val_class_unsigned_const)
4496 return a->dw_attr_val.v.val_unsigned;
4501 /* Add an unsigned double integer attribute value to a DIE. */
4504 add_AT_long_long (die, attr_kind, val_hi, val_low)
4505 register dw_die_ref die;
4506 register enum dwarf_attribute attr_kind;
4507 register unsigned long val_hi;
4508 register unsigned long val_low;
4510 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4512 attr->dw_attr_next = NULL;
4513 attr->dw_attr = attr_kind;
4514 attr->dw_attr_val.val_class = dw_val_class_long_long;
4515 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4516 attr->dw_attr_val.v.val_long_long.low = val_low;
4517 add_dwarf_attr (die, attr);
4520 /* Add a floating point attribute value to a DIE and return it. */
4523 add_AT_float (die, attr_kind, length, array)
4524 register dw_die_ref die;
4525 register enum dwarf_attribute attr_kind;
4526 register unsigned length;
4527 register long *array;
4529 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4531 attr->dw_attr_next = NULL;
4532 attr->dw_attr = attr_kind;
4533 attr->dw_attr_val.val_class = dw_val_class_float;
4534 attr->dw_attr_val.v.val_float.length = length;
4535 attr->dw_attr_val.v.val_float.array = array;
4536 add_dwarf_attr (die, attr);
4539 /* Add a string attribute value to a DIE. */
4542 add_AT_string (die, attr_kind, str)
4543 register dw_die_ref die;
4544 register enum dwarf_attribute attr_kind;
4545 register const char *str;
4547 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4549 attr->dw_attr_next = NULL;
4550 attr->dw_attr = attr_kind;
4551 attr->dw_attr_val.val_class = dw_val_class_str;
4552 attr->dw_attr_val.v.val_str = xstrdup (str);
4553 add_dwarf_attr (die, attr);
4556 static inline const char *AT_string PARAMS ((dw_attr_ref));
4557 static inline const char *
4559 register dw_attr_ref a;
4561 if (a && AT_class (a) == dw_val_class_str)
4562 return a->dw_attr_val.v.val_str;
4567 /* Add a DIE reference attribute value to a DIE. */
4570 add_AT_die_ref (die, attr_kind, targ_die)
4571 register dw_die_ref die;
4572 register enum dwarf_attribute attr_kind;
4573 register dw_die_ref targ_die;
4575 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4577 attr->dw_attr_next = NULL;
4578 attr->dw_attr = attr_kind;
4579 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4580 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4581 attr->dw_attr_val.v.val_die_ref.external = 0;
4582 add_dwarf_attr (die, attr);
4585 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4586 static inline dw_die_ref
4588 register dw_attr_ref a;
4590 if (a && AT_class (a) == dw_val_class_die_ref)
4591 return a->dw_attr_val.v.val_die_ref.die;
4596 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4599 register dw_attr_ref a;
4601 if (a && AT_class (a) == dw_val_class_die_ref)
4602 return a->dw_attr_val.v.val_die_ref.external;
4607 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4609 set_AT_ref_external (a, i)
4610 register dw_attr_ref a;
4613 if (a && AT_class (a) == dw_val_class_die_ref)
4614 a->dw_attr_val.v.val_die_ref.external = i;
4619 /* Add an FDE reference attribute value to a DIE. */
4622 add_AT_fde_ref (die, attr_kind, targ_fde)
4623 register dw_die_ref die;
4624 register enum dwarf_attribute attr_kind;
4625 register unsigned targ_fde;
4627 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4629 attr->dw_attr_next = NULL;
4630 attr->dw_attr = attr_kind;
4631 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4632 attr->dw_attr_val.v.val_fde_index = targ_fde;
4633 add_dwarf_attr (die, attr);
4636 /* Add a location description attribute value to a DIE. */
4639 add_AT_loc (die, attr_kind, loc)
4640 register dw_die_ref die;
4641 register enum dwarf_attribute attr_kind;
4642 register dw_loc_descr_ref loc;
4644 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4646 attr->dw_attr_next = NULL;
4647 attr->dw_attr = attr_kind;
4648 attr->dw_attr_val.val_class = dw_val_class_loc;
4649 attr->dw_attr_val.v.val_loc = loc;
4650 add_dwarf_attr (die, attr);
4653 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4654 static inline dw_loc_descr_ref
4656 register dw_attr_ref a;
4658 if (a && AT_class (a) == dw_val_class_loc)
4659 return a->dw_attr_val.v.val_loc;
4664 /* Add an address constant attribute value to a DIE. */
4667 add_AT_addr (die, attr_kind, addr)
4668 register dw_die_ref die;
4669 register enum dwarf_attribute attr_kind;
4672 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4674 attr->dw_attr_next = NULL;
4675 attr->dw_attr = attr_kind;
4676 attr->dw_attr_val.val_class = dw_val_class_addr;
4677 attr->dw_attr_val.v.val_addr = addr;
4678 add_dwarf_attr (die, attr);
4681 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4684 register dw_attr_ref a;
4686 if (a && AT_class (a) == dw_val_class_addr)
4687 return a->dw_attr_val.v.val_addr;
4692 /* Add a label identifier attribute value to a DIE. */
4695 add_AT_lbl_id (die, attr_kind, lbl_id)
4696 register dw_die_ref die;
4697 register enum dwarf_attribute attr_kind;
4698 register const char *lbl_id;
4700 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4702 attr->dw_attr_next = NULL;
4703 attr->dw_attr = attr_kind;
4704 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4705 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4706 add_dwarf_attr (die, attr);
4709 /* Add a section offset attribute value to a DIE. */
4712 add_AT_lbl_offset (die, attr_kind, label)
4713 register dw_die_ref die;
4714 register enum dwarf_attribute attr_kind;
4715 register const char *label;
4717 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4719 attr->dw_attr_next = NULL;
4720 attr->dw_attr = attr_kind;
4721 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4722 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4723 add_dwarf_attr (die, attr);
4726 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4727 static inline const char *
4729 register dw_attr_ref a;
4731 if (a && (AT_class (a) == dw_val_class_lbl_id
4732 || AT_class (a) == dw_val_class_lbl_offset))
4733 return a->dw_attr_val.v.val_lbl_id;
4738 /* Get the attribute of type attr_kind. */
4740 static inline dw_attr_ref
4741 get_AT (die, attr_kind)
4742 register dw_die_ref die;
4743 register enum dwarf_attribute attr_kind;
4745 register dw_attr_ref a;
4746 register dw_die_ref spec = NULL;
4750 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4752 if (a->dw_attr == attr_kind)
4755 if (a->dw_attr == DW_AT_specification
4756 || a->dw_attr == DW_AT_abstract_origin)
4761 return get_AT (spec, attr_kind);
4767 /* Return the "low pc" attribute value, typically associated with
4768 a subprogram DIE. Return null if the "low pc" attribute is
4769 either not prsent, or if it cannot be represented as an
4770 assembler label identifier. */
4772 static inline const char *
4774 register dw_die_ref die;
4776 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4777 return a ? AT_lbl (a) : NULL;
4780 /* Return the "high pc" attribute value, typically associated with
4781 a subprogram DIE. Return null if the "high pc" attribute is
4782 either not prsent, or if it cannot be represented as an
4783 assembler label identifier. */
4785 static inline const char *
4787 register dw_die_ref die;
4789 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4790 return a ? AT_lbl (a) : NULL;
4793 /* Return the value of the string attribute designated by ATTR_KIND, or
4794 NULL if it is not present. */
4796 static inline const char *
4797 get_AT_string (die, attr_kind)
4798 register dw_die_ref die;
4799 register enum dwarf_attribute attr_kind;
4801 register dw_attr_ref a = get_AT (die, attr_kind);
4802 return a ? AT_string (a) : NULL;
4805 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4806 if it is not present. */
4809 get_AT_flag (die, attr_kind)
4810 register dw_die_ref die;
4811 register enum dwarf_attribute attr_kind;
4813 register dw_attr_ref a = get_AT (die, attr_kind);
4814 return a ? AT_flag (a) : 0;
4817 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4818 if it is not present. */
4820 static inline unsigned
4821 get_AT_unsigned (die, attr_kind)
4822 register dw_die_ref die;
4823 register enum dwarf_attribute attr_kind;
4825 register dw_attr_ref a = get_AT (die, attr_kind);
4826 return a ? AT_unsigned (a) : 0;
4829 static inline dw_die_ref
4830 get_AT_ref (die, attr_kind)
4832 register enum dwarf_attribute attr_kind;
4834 register dw_attr_ref a = get_AT (die, attr_kind);
4835 return a ? AT_ref (a) : NULL;
4841 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4843 return (lang == DW_LANG_C || lang == DW_LANG_C89
4844 || lang == DW_LANG_C_plus_plus);
4850 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4852 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4858 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4860 return (lang == DW_LANG_Java);
4863 /* Free up the memory used by A. */
4865 static inline void free_AT PARAMS ((dw_attr_ref));
4870 switch (AT_class (a))
4872 case dw_val_class_str:
4873 case dw_val_class_lbl_id:
4874 case dw_val_class_lbl_offset:
4875 free (a->dw_attr_val.v.val_str);
4878 case dw_val_class_float:
4879 free (a->dw_attr_val.v.val_float.array);
4889 /* Remove the specified attribute if present. */
4892 remove_AT (die, attr_kind)
4893 register dw_die_ref die;
4894 register enum dwarf_attribute attr_kind;
4896 register dw_attr_ref *p;
4897 register dw_attr_ref removed = NULL;
4901 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4902 if ((*p)->dw_attr == attr_kind)
4905 *p = (*p)->dw_attr_next;
4914 /* Free up the memory used by DIE. */
4916 static inline void free_die PARAMS ((dw_die_ref));
4921 remove_children (die);
4925 /* Discard the children of this DIE. */
4928 remove_children (die)
4929 register dw_die_ref die;
4931 register dw_die_ref child_die = die->die_child;
4933 die->die_child = NULL;
4935 while (child_die != NULL)
4937 register dw_die_ref tmp_die = child_die;
4938 register dw_attr_ref a;
4940 child_die = child_die->die_sib;
4942 for (a = tmp_die->die_attr; a != NULL;)
4944 register dw_attr_ref tmp_a = a;
4946 a = a->dw_attr_next;
4954 /* Add a child DIE below its parent. We build the lists up in reverse
4955 addition order, and correct that in reverse_all_dies. */
4958 add_child_die (die, child_die)
4959 register dw_die_ref die;
4960 register dw_die_ref child_die;
4962 if (die != NULL && child_die != NULL)
4964 if (die == child_die)
4966 child_die->die_parent = die;
4967 child_die->die_sib = die->die_child;
4968 die->die_child = child_die;
4972 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4973 is the specification, to the front of PARENT's list of children. */
4976 splice_child_die (parent, child)
4977 dw_die_ref parent, child;
4981 /* We want the declaration DIE from inside the class, not the
4982 specification DIE at toplevel. */
4983 if (child->die_parent != parent)
4985 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4990 if (child->die_parent != parent
4991 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4994 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4997 *p = child->die_sib;
5001 child->die_sib = parent->die_child;
5002 parent->die_child = child;
5005 /* Return a pointer to a newly created DIE node. */
5007 static inline dw_die_ref
5008 new_die (tag_value, parent_die)
5009 register enum dwarf_tag tag_value;
5010 register dw_die_ref parent_die;
5012 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
5014 die->die_tag = tag_value;
5016 if (parent_die != NULL)
5017 add_child_die (parent_die, die);
5020 limbo_die_node *limbo_node;
5022 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5023 limbo_node->die = die;
5024 limbo_node->next = limbo_die_list;
5025 limbo_die_list = limbo_node;
5031 /* Return the DIE associated with the given type specifier. */
5033 static inline dw_die_ref
5034 lookup_type_die (type)
5037 if (TREE_CODE (type) == VECTOR_TYPE)
5038 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
5039 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
5042 /* Equate a DIE to a given type specifier. */
5045 equate_type_number_to_die (type, type_die)
5047 register dw_die_ref type_die;
5049 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
5052 /* Return the DIE associated with a given declaration. */
5054 static inline dw_die_ref
5055 lookup_decl_die (decl)
5058 register unsigned decl_id = DECL_UID (decl);
5060 return (decl_id < decl_die_table_in_use
5061 ? decl_die_table[decl_id] : NULL);
5064 /* Equate a DIE to a particular declaration. */
5067 equate_decl_number_to_die (decl, decl_die)
5069 register dw_die_ref decl_die;
5071 register unsigned decl_id = DECL_UID (decl);
5072 register unsigned num_allocated;
5074 if (decl_id >= decl_die_table_allocated)
5077 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5078 / DECL_DIE_TABLE_INCREMENT)
5079 * DECL_DIE_TABLE_INCREMENT;
5082 = (dw_die_ref *) xrealloc (decl_die_table,
5083 sizeof (dw_die_ref) * num_allocated);
5085 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5086 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5087 decl_die_table_allocated = num_allocated;
5090 if (decl_id >= decl_die_table_in_use)
5091 decl_die_table_in_use = (decl_id + 1);
5093 decl_die_table[decl_id] = decl_die;
5096 /* Keep track of the number of spaces used to indent the
5097 output of the debugging routines that print the structure of
5098 the DIE internal representation. */
5099 static int print_indent;
5101 /* Indent the line the number of spaces given by print_indent. */
5104 print_spaces (outfile)
5107 fprintf (outfile, "%*s", print_indent, "");
5110 /* Print the information associated with a given DIE, and its children.
5111 This routine is a debugging aid only. */
5114 print_die (die, outfile)
5118 register dw_attr_ref a;
5119 register dw_die_ref c;
5121 print_spaces (outfile);
5122 fprintf (outfile, "DIE %4lu: %s\n",
5123 die->die_offset, dwarf_tag_name (die->die_tag));
5124 print_spaces (outfile);
5125 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5126 fprintf (outfile, " offset: %lu\n", die->die_offset);
5128 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5130 print_spaces (outfile);
5131 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5133 switch (AT_class (a))
5135 case dw_val_class_addr:
5136 fprintf (outfile, "address");
5138 case dw_val_class_loc:
5139 fprintf (outfile, "location descriptor");
5141 case dw_val_class_const:
5142 fprintf (outfile, "%ld", AT_int (a));
5144 case dw_val_class_unsigned_const:
5145 fprintf (outfile, "%lu", AT_unsigned (a));
5147 case dw_val_class_long_long:
5148 fprintf (outfile, "constant (%lu,%lu)",
5149 a->dw_attr_val.v.val_long_long.hi,
5150 a->dw_attr_val.v.val_long_long.low);
5152 case dw_val_class_float:
5153 fprintf (outfile, "floating-point constant");
5155 case dw_val_class_flag:
5156 fprintf (outfile, "%u", AT_flag (a));
5158 case dw_val_class_die_ref:
5159 if (AT_ref (a) != NULL)
5161 if (AT_ref (a)->die_symbol)
5162 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5164 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5167 fprintf (outfile, "die -> <null>");
5169 case dw_val_class_lbl_id:
5170 case dw_val_class_lbl_offset:
5171 fprintf (outfile, "label: %s", AT_lbl (a));
5173 case dw_val_class_str:
5174 if (AT_string (a) != NULL)
5175 fprintf (outfile, "\"%s\"", AT_string (a));
5177 fprintf (outfile, "<null>");
5183 fprintf (outfile, "\n");
5186 if (die->die_child != NULL)
5189 for (c = die->die_child; c != NULL; c = c->die_sib)
5190 print_die (c, outfile);
5194 if (print_indent == 0)
5195 fprintf (outfile, "\n");
5198 /* Print the contents of the source code line number correspondence table.
5199 This routine is a debugging aid only. */
5202 print_dwarf_line_table (outfile)
5205 register unsigned i;
5206 register dw_line_info_ref line_info;
5208 fprintf (outfile, "\n\nDWARF source line information\n");
5209 for (i = 1; i < line_info_table_in_use; ++i)
5211 line_info = &line_info_table[i];
5212 fprintf (outfile, "%5d: ", i);
5213 fprintf (outfile, "%-20s", line_file_table.table[line_info->dw_file_num]);
5214 fprintf (outfile, "%6ld", line_info->dw_line_num);
5215 fprintf (outfile, "\n");
5218 fprintf (outfile, "\n\n");
5221 /* Print the information collected for a given DIE. */
5224 debug_dwarf_die (die)
5227 print_die (die, stderr);
5230 /* Print all DWARF information collected for the compilation unit.
5231 This routine is a debugging aid only. */
5237 print_die (comp_unit_die, stderr);
5238 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5239 print_dwarf_line_table (stderr);
5242 /* We build up the lists of children and attributes by pushing new ones
5243 onto the beginning of the list. Reverse the lists for DIE so that
5244 they are in order of addition. */
5247 reverse_die_lists (die)
5248 register dw_die_ref die;
5250 register dw_die_ref c, cp, cn;
5251 register dw_attr_ref a, ap, an;
5253 for (a = die->die_attr, ap = 0; a; a = an)
5255 an = a->dw_attr_next;
5256 a->dw_attr_next = ap;
5261 for (c = die->die_child, cp = 0; c; c = cn)
5267 die->die_child = cp;
5270 /* reverse_die_lists only reverses the single die you pass it. Since
5271 we used to reverse all dies in add_sibling_attributes, which runs
5272 through all the dies, it would reverse all the dies. Now, however,
5273 since we don't call reverse_die_lists in add_sibling_attributes, we
5274 need a routine to recursively reverse all the dies. This is that
5278 reverse_all_dies (die)
5279 register dw_die_ref die;
5281 register dw_die_ref c;
5283 reverse_die_lists (die);
5285 for (c = die->die_child; c; c = c->die_sib)
5286 reverse_all_dies (c);
5289 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5290 the CU for the enclosing include file, if any. BINCL_DIE is the
5291 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5295 push_new_compile_unit (old_unit, bincl_die)
5296 dw_die_ref old_unit, bincl_die;
5298 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5299 dw_die_ref new_unit = gen_compile_unit_die (filename);
5300 new_unit->die_sib = old_unit;
5304 /* Close an include-file CU and reopen the enclosing one. */
5307 pop_compile_unit (old_unit)
5308 dw_die_ref old_unit;
5310 dw_die_ref new_unit = old_unit->die_sib;
5311 old_unit->die_sib = NULL;
5315 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5316 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5318 /* Calculate the checksum of a location expression. */
5321 loc_checksum (loc, ctx)
5322 dw_loc_descr_ref loc;
5323 struct md5_ctx *ctx;
5325 PROCESS (loc->dw_loc_opc);
5326 PROCESS (loc->dw_loc_oprnd1);
5327 PROCESS (loc->dw_loc_oprnd2);
5330 /* Calculate the checksum of an attribute. */
5333 attr_checksum (at, ctx)
5335 struct md5_ctx *ctx;
5337 dw_loc_descr_ref loc;
5340 PROCESS (at->dw_attr);
5342 /* We don't care about differences in file numbering. */
5343 if (at->dw_attr == DW_AT_decl_file
5344 /* Or that this was compiled with a different compiler snapshot; if
5345 the output is the same, that's what matters. */
5346 || at->dw_attr == DW_AT_producer)
5349 switch (AT_class (at))
5351 case dw_val_class_const:
5352 PROCESS (at->dw_attr_val.v.val_int);
5354 case dw_val_class_unsigned_const:
5355 PROCESS (at->dw_attr_val.v.val_unsigned);
5357 case dw_val_class_long_long:
5358 PROCESS (at->dw_attr_val.v.val_long_long);
5360 case dw_val_class_float:
5361 PROCESS (at->dw_attr_val.v.val_float);
5363 case dw_val_class_flag:
5364 PROCESS (at->dw_attr_val.v.val_flag);
5367 case dw_val_class_str:
5368 PROCESS_STRING (AT_string (at));
5370 case dw_val_class_addr:
5372 switch (GET_CODE (r))
5375 PROCESS_STRING (XSTR (r, 0));
5383 case dw_val_class_loc:
5384 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5385 loc_checksum (loc, ctx);
5388 case dw_val_class_die_ref:
5389 if (AT_ref (at)->die_offset)
5390 PROCESS (AT_ref (at)->die_offset);
5391 /* FIXME else use target die name or something. */
5393 case dw_val_class_fde_ref:
5394 case dw_val_class_lbl_id:
5395 case dw_val_class_lbl_offset:
5402 /* Calculate the checksum of a DIE. */
5405 die_checksum (die, ctx)
5407 struct md5_ctx *ctx;
5412 PROCESS (die->die_tag);
5414 for (a = die->die_attr; a; a = a->dw_attr_next)
5415 attr_checksum (a, ctx);
5417 for (c = die->die_child; c; c = c->die_sib)
5418 die_checksum (c, ctx);
5422 #undef PROCESS_STRING
5424 /* The prefix to attach to symbols on DIEs in the current comdat debug
5426 static char *comdat_symbol_id;
5428 /* The index of the current symbol within the current comdat CU. */
5429 static unsigned int comdat_symbol_number;
5431 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5432 children, and set comdat_symbol_id accordingly. */
5435 compute_section_prefix (unit_die)
5436 dw_die_ref unit_die;
5440 unsigned char checksum[16];
5443 md5_init_ctx (&ctx);
5444 die_checksum (unit_die, &ctx);
5445 md5_finish_ctx (&ctx, checksum);
5447 p = file_name_nondirectory (get_AT_string (unit_die, DW_AT_name));
5448 name = (char *) alloca (strlen (p) + 64);
5449 sprintf (name, "%s.", p);
5451 clean_symbol_name (name);
5453 p = name + strlen (name);
5454 for (i = 0; i < 4; ++i)
5456 sprintf (p, "%.2x", checksum[i]);
5460 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5461 comdat_symbol_number = 0;
5464 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5470 switch (die->die_tag)
5472 case DW_TAG_array_type:
5473 case DW_TAG_class_type:
5474 case DW_TAG_enumeration_type:
5475 case DW_TAG_pointer_type:
5476 case DW_TAG_reference_type:
5477 case DW_TAG_string_type:
5478 case DW_TAG_structure_type:
5479 case DW_TAG_subroutine_type:
5480 case DW_TAG_union_type:
5481 case DW_TAG_ptr_to_member_type:
5482 case DW_TAG_set_type:
5483 case DW_TAG_subrange_type:
5484 case DW_TAG_base_type:
5485 case DW_TAG_const_type:
5486 case DW_TAG_file_type:
5487 case DW_TAG_packed_type:
5488 case DW_TAG_volatile_type:
5495 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5496 Basically, we want to choose the bits that are likely to be shared between
5497 compilations (types) and leave out the bits that are specific to individual
5498 compilations (functions). */
5505 /* I think we want to leave base types and __vtbl_ptr_type in the
5506 main CU, as we do for stabs. The advantage is a greater
5507 likelihood of sharing between objects that don't include headers
5508 in the same order (and therefore would put the base types in a
5509 different comdat). jason 8/28/00 */
5510 if (c->die_tag == DW_TAG_base_type)
5513 if (c->die_tag == DW_TAG_pointer_type
5514 || c->die_tag == DW_TAG_reference_type
5515 || c->die_tag == DW_TAG_const_type
5516 || c->die_tag == DW_TAG_volatile_type)
5518 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5519 return t ? is_comdat_die (t) : 0;
5523 return is_type_die (c);
5526 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5527 compilation unit. */
5533 if (is_type_die (c))
5535 if (get_AT (c, DW_AT_declaration)
5536 && ! get_AT (c, DW_AT_specification))
5545 static int label_num;
5546 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5547 return xstrdup (buf);
5550 /* Assign symbols to all worthy DIEs under DIE. */
5553 assign_symbol_names (die)
5554 register dw_die_ref die;
5556 register dw_die_ref c;
5558 if (is_symbol_die (die))
5560 if (comdat_symbol_id)
5562 char *p = alloca (strlen (comdat_symbol_id) + 64);
5563 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5564 comdat_symbol_id, comdat_symbol_number++);
5565 die->die_symbol = xstrdup (p);
5568 die->die_symbol = gen_internal_sym ();
5571 for (c = die->die_child; c != NULL; c = c->die_sib)
5572 assign_symbol_names (c);
5575 /* Traverse the DIE (which is always comp_unit_die), and set up
5576 additional compilation units for each of the include files we see
5577 bracketed by BINCL/EINCL. */
5580 break_out_includes (die)
5581 register dw_die_ref die;
5584 register dw_die_ref unit = NULL;
5585 limbo_die_node *node;
5587 for (ptr = &(die->die_child); *ptr; )
5589 register dw_die_ref c = *ptr;
5591 if (c->die_tag == DW_TAG_GNU_BINCL
5592 || c->die_tag == DW_TAG_GNU_EINCL
5593 || (unit && is_comdat_die (c)))
5595 /* This DIE is for a secondary CU; remove it from the main one. */
5598 if (c->die_tag == DW_TAG_GNU_BINCL)
5600 unit = push_new_compile_unit (unit, c);
5603 else if (c->die_tag == DW_TAG_GNU_EINCL)
5605 unit = pop_compile_unit (unit);
5609 add_child_die (unit, c);
5613 /* Leave this DIE in the main CU. */
5614 ptr = &(c->die_sib);
5620 /* We can only use this in debugging, since the frontend doesn't check
5621 to make sure that we leave every include file we enter. */
5626 assign_symbol_names (die);
5627 for (node = limbo_die_list; node; node = node->next)
5629 compute_section_prefix (node->die);
5630 assign_symbol_names (node->die);
5634 /* Traverse the DIE and add a sibling attribute if it may have the
5635 effect of speeding up access to siblings. To save some space,
5636 avoid generating sibling attributes for DIE's without children. */
5639 add_sibling_attributes (die)
5640 register dw_die_ref die;
5642 register dw_die_ref c;
5644 if (die->die_tag != DW_TAG_compile_unit
5645 && die->die_sib && die->die_child != NULL)
5646 /* Add the sibling link to the front of the attribute list. */
5647 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5649 for (c = die->die_child; c != NULL; c = c->die_sib)
5650 add_sibling_attributes (c);
5653 /* The format of each DIE (and its attribute value pairs)
5654 is encoded in an abbreviation table. This routine builds the
5655 abbreviation table and assigns a unique abbreviation id for
5656 each abbreviation entry. The children of each die are visited
5660 build_abbrev_table (die)
5661 register dw_die_ref die;
5663 register unsigned long abbrev_id;
5664 register unsigned long n_alloc;
5665 register dw_die_ref c;
5666 register dw_attr_ref d_attr, a_attr;
5668 /* Scan the DIE references, and mark as external any that refer to
5669 DIEs from other CUs (i.e. those which are not marked). */
5670 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5672 if (AT_class (d_attr) == dw_val_class_die_ref
5673 && AT_ref (d_attr)->die_mark == 0)
5675 if (AT_ref (d_attr)->die_symbol == 0)
5677 set_AT_ref_external (d_attr, 1);
5681 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5683 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5685 if (abbrev->die_tag == die->die_tag)
5687 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5689 a_attr = abbrev->die_attr;
5690 d_attr = die->die_attr;
5692 while (a_attr != NULL && d_attr != NULL)
5694 if ((a_attr->dw_attr != d_attr->dw_attr)
5695 || (value_format (a_attr) != value_format (d_attr)))
5698 a_attr = a_attr->dw_attr_next;
5699 d_attr = d_attr->dw_attr_next;
5702 if (a_attr == NULL && d_attr == NULL)
5708 if (abbrev_id >= abbrev_die_table_in_use)
5710 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5712 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5714 = (dw_die_ref *) xrealloc (abbrev_die_table,
5715 sizeof (dw_die_ref) * n_alloc);
5717 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5718 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5719 abbrev_die_table_allocated = n_alloc;
5722 ++abbrev_die_table_in_use;
5723 abbrev_die_table[abbrev_id] = die;
5726 die->die_abbrev = abbrev_id;
5727 for (c = die->die_child; c != NULL; c = c->die_sib)
5728 build_abbrev_table (c);
5731 /* Return the size of a string, including the null byte.
5733 This used to treat backslashes as escapes, and hence they were not included
5734 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5735 which treats a backslash as a backslash, escaping it if necessary, and hence
5736 we must include them in the count. */
5738 static unsigned long
5739 size_of_string (str)
5740 register const char *str;
5742 return strlen (str) + 1;
5745 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5748 constant_size (value)
5749 long unsigned value;
5756 log = floor_log2 (value);
5759 log = 1 << (floor_log2 (log) + 1);
5764 /* Return the size of a DIE, as it is represented in the
5765 .debug_info section. */
5767 static unsigned long
5769 register dw_die_ref die;
5771 register unsigned long size = 0;
5772 register dw_attr_ref a;
5774 size += size_of_uleb128 (die->die_abbrev);
5775 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5777 switch (AT_class (a))
5779 case dw_val_class_addr:
5780 size += DWARF2_ADDR_SIZE;
5782 case dw_val_class_loc:
5784 register unsigned long lsize = size_of_locs (AT_loc (a));
5787 size += constant_size (lsize);
5791 case dw_val_class_const:
5792 size += size_of_sleb128 (AT_int (a));
5794 case dw_val_class_unsigned_const:
5795 size += constant_size (AT_unsigned (a));
5797 case dw_val_class_long_long:
5798 size += 1 + 8; /* block */
5800 case dw_val_class_float:
5801 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5803 case dw_val_class_flag:
5806 case dw_val_class_die_ref:
5807 size += DWARF_OFFSET_SIZE;
5809 case dw_val_class_fde_ref:
5810 size += DWARF_OFFSET_SIZE;
5812 case dw_val_class_lbl_id:
5813 size += DWARF2_ADDR_SIZE;
5815 case dw_val_class_lbl_offset:
5816 size += DWARF_OFFSET_SIZE;
5818 case dw_val_class_str:
5819 size += size_of_string (AT_string (a));
5829 /* Size the debugging information associated with a given DIE.
5830 Visits the DIE's children recursively. Updates the global
5831 variable next_die_offset, on each time through. Uses the
5832 current value of next_die_offset to update the die_offset
5833 field in each DIE. */
5836 calc_die_sizes (die)
5839 register dw_die_ref c;
5840 die->die_offset = next_die_offset;
5841 next_die_offset += size_of_die (die);
5843 for (c = die->die_child; c != NULL; c = c->die_sib)
5846 if (die->die_child != NULL)
5847 /* Count the null byte used to terminate sibling lists. */
5848 next_die_offset += 1;
5851 /* Set the marks for a die and its children. We do this so
5852 that we know whether or not a reference needs to use FORM_ref_addr; only
5853 DIEs in the same CU will be marked. We used to clear out the offset
5854 and use that as the flag, but ran into ordering problems. */
5860 register dw_die_ref c;
5862 for (c = die->die_child; c; c = c->die_sib)
5866 /* Clear the marks for a die and its children. */
5872 register dw_die_ref c;
5874 for (c = die->die_child; c; c = c->die_sib)
5878 /* Return the size of the line information prolog generated for the
5879 compilation unit. */
5881 static unsigned long
5882 size_of_line_prolog ()
5884 register unsigned long size;
5885 register unsigned long ft_index;
5887 size = DWARF_LINE_PROLOG_HEADER_SIZE;
5889 /* Count the size of the table giving number of args for each
5891 size += DWARF_LINE_OPCODE_BASE - 1;
5893 /* Include directory table is empty (at present). Count only the
5894 null byte used to terminate the table. */
5897 for (ft_index = 1; ft_index < decl_file_table.in_use; ++ft_index)
5899 /* File name entry. */
5900 size += size_of_string (decl_file_table.table[ft_index]);
5902 /* Include directory index. */
5903 size += size_of_uleb128 (0);
5905 /* Modification time. */
5906 size += size_of_uleb128 (0);
5908 /* File length in bytes. */
5909 size += size_of_uleb128 (0);
5912 /* Count the file table terminator. */
5917 /* Return the size of the .debug_pubnames table generated for the
5918 compilation unit. */
5920 static unsigned long
5923 register unsigned long size;
5924 register unsigned i;
5926 size = DWARF_PUBNAMES_HEADER_SIZE;
5927 for (i = 0; i < pubname_table_in_use; ++i)
5929 register pubname_ref p = &pubname_table[i];
5930 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5933 size += DWARF_OFFSET_SIZE;
5937 /* Return the size of the information in the .debug_aranges section. */
5939 static unsigned long
5942 register unsigned long size;
5944 size = DWARF_ARANGES_HEADER_SIZE;
5946 /* Count the address/length pair for this compilation unit. */
5947 size += 2 * DWARF2_ADDR_SIZE;
5948 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5950 /* Count the two zero words used to terminated the address range table. */
5951 size += 2 * DWARF2_ADDR_SIZE;
5955 /* Select the encoding of an attribute value. */
5957 static enum dwarf_form
5961 switch (a->dw_attr_val.val_class)
5963 case dw_val_class_addr:
5964 return DW_FORM_addr;
5965 case dw_val_class_loc:
5966 switch (constant_size (size_of_locs (AT_loc (a))))
5969 return DW_FORM_block1;
5971 return DW_FORM_block2;
5975 case dw_val_class_const:
5976 return DW_FORM_sdata;
5977 case dw_val_class_unsigned_const:
5978 switch (constant_size (AT_unsigned (a)))
5981 return DW_FORM_data1;
5983 return DW_FORM_data2;
5985 return DW_FORM_data4;
5987 return DW_FORM_data8;
5991 case dw_val_class_long_long:
5992 return DW_FORM_block1;
5993 case dw_val_class_float:
5994 return DW_FORM_block1;
5995 case dw_val_class_flag:
5996 return DW_FORM_flag;
5997 case dw_val_class_die_ref:
5998 if (AT_ref_external (a))
5999 return DW_FORM_ref_addr;
6002 case dw_val_class_fde_ref:
6003 return DW_FORM_data;
6004 case dw_val_class_lbl_id:
6005 return DW_FORM_addr;
6006 case dw_val_class_lbl_offset:
6007 return DW_FORM_data;
6008 case dw_val_class_str:
6009 return DW_FORM_string;
6015 /* Output the encoding of an attribute value. */
6018 output_value_format (a)
6021 enum dwarf_form form = value_format (a);
6023 output_uleb128 (form);
6025 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
6027 fputc ('\n', asm_out_file);
6030 /* Output the .debug_abbrev section which defines the DIE abbreviation
6034 output_abbrev_section ()
6036 unsigned long abbrev_id;
6039 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6041 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6043 output_uleb128 (abbrev_id);
6045 fprintf (asm_out_file, " (abbrev code)");
6047 fputc ('\n', asm_out_file);
6048 output_uleb128 (abbrev->die_tag);
6050 fprintf (asm_out_file, " (TAG: %s)",
6051 dwarf_tag_name (abbrev->die_tag));
6053 fputc ('\n', asm_out_file);
6054 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP,
6055 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
6058 fprintf (asm_out_file, "\t%s %s",
6060 (abbrev->die_child != NULL
6061 ? "DW_children_yes" : "DW_children_no"));
6063 fputc ('\n', asm_out_file);
6065 for (a_attr = abbrev->die_attr; a_attr != NULL;
6066 a_attr = a_attr->dw_attr_next)
6068 output_uleb128 (a_attr->dw_attr);
6070 fprintf (asm_out_file, " (%s)",
6071 dwarf_attr_name (a_attr->dw_attr));
6073 fputc ('\n', asm_out_file);
6074 output_value_format (a_attr);
6077 fprintf (asm_out_file, "%s0,0\n", ASM_BYTE_OP);
6080 /* Terminate the table. */
6081 fprintf (asm_out_file, "%s0\n", ASM_BYTE_OP);
6084 /* Output a symbol we can use to refer to this DIE from another CU. */
6087 output_die_symbol (die)
6088 register dw_die_ref die;
6090 char *sym = die->die_symbol;
6095 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6096 /* We make these global, not weak; if the target doesn't support
6097 .linkonce, it doesn't support combining the sections, so debugging
6099 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6100 ASM_OUTPUT_LABEL (asm_out_file, sym);
6103 /* Output a symbolic (i.e. FORM_ref_addr) reference to TARGET_DIE. */
6106 output_symbolic_ref (target_die)
6107 dw_die_ref target_die;
6109 char *sym = target_die->die_symbol;
6114 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, sym);
6117 /* Output the DIE and its attributes. Called recursively to generate
6118 the definitions of each child DIE. */
6122 register dw_die_ref die;
6124 register dw_attr_ref a;
6125 register dw_die_ref c;
6126 register unsigned long size;
6128 /* If someone in another CU might refer to us, set up a symbol for
6129 them to point to. */
6130 if (die->die_symbol)
6131 output_die_symbol (die);
6133 output_uleb128 (die->die_abbrev);
6135 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
6136 die->die_offset, dwarf_tag_name (die->die_tag));
6138 fputc ('\n', asm_out_file);
6140 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6142 switch (AT_class (a))
6144 case dw_val_class_addr:
6145 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
6148 case dw_val_class_loc:
6149 size = size_of_locs (AT_loc (a));
6151 /* Output the block length for this list of location operations. */
6152 switch (constant_size (size))
6155 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
6158 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
6165 fprintf (asm_out_file, "\t%s %s",
6166 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6168 fputc ('\n', asm_out_file);
6170 output_loc_sequence (AT_loc (a));
6173 case dw_val_class_const:
6174 /* ??? It would be slightly more efficient to use a scheme like is
6175 used for unsigned constants below, but gdb 4.x does not sign
6176 extend. Gdb 5.x does sign extend. */
6177 output_sleb128 (AT_int (a));
6180 case dw_val_class_unsigned_const:
6181 switch (constant_size (AT_unsigned (a)))
6184 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
6187 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
6190 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
6193 ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a));
6200 case dw_val_class_long_long:
6201 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
6203 fprintf (asm_out_file, "\t%s %s",
6204 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6206 fputc ('\n', asm_out_file);
6207 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file,
6208 a->dw_attr_val.v.val_long_long.hi,
6209 a->dw_attr_val.v.val_long_long.low);
6212 fprintf (asm_out_file,
6213 "\t%s long long constant", ASM_COMMENT_START);
6215 fputc ('\n', asm_out_file);
6218 case dw_val_class_float:
6220 register unsigned int i;
6221 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6222 a->dw_attr_val.v.val_float.length * 4);
6224 fprintf (asm_out_file, "\t%s %s",
6225 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6227 fputc ('\n', asm_out_file);
6228 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6230 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
6231 a->dw_attr_val.v.val_float.array[i]);
6233 fprintf (asm_out_file, "\t%s fp constant word %u",
6234 ASM_COMMENT_START, i);
6236 fputc ('\n', asm_out_file);
6241 case dw_val_class_flag:
6242 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
6245 case dw_val_class_die_ref:
6246 if (AT_ref_external (a))
6247 output_symbolic_ref (AT_ref (a));
6248 else if (AT_ref (a)->die_offset == 0)
6251 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
6254 case dw_val_class_fde_ref:
6257 ASM_GENERATE_INTERNAL_LABEL
6258 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
6259 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
6260 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
6264 case dw_val_class_lbl_id:
6265 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
6268 case dw_val_class_lbl_offset:
6269 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
6272 case dw_val_class_str:
6274 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
6276 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
6277 (int) strlen (AT_string (a)) + 1);
6284 if (AT_class (a) != dw_val_class_loc
6285 && AT_class (a) != dw_val_class_long_long
6286 && AT_class (a) != dw_val_class_float)
6289 fprintf (asm_out_file, "\t%s %s",
6290 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6292 fputc ('\n', asm_out_file);
6296 for (c = die->die_child; c != NULL; c = c->die_sib)
6299 if (die->die_child != NULL)
6301 /* Add null byte to terminate sibling list. */
6302 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6304 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
6305 ASM_COMMENT_START, die->die_offset);
6307 fputc ('\n', asm_out_file);
6311 /* Output the compilation unit that appears at the beginning of the
6312 .debug_info section, and precedes the DIE descriptions. */
6315 output_compilation_unit_header ()
6317 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
6319 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
6322 fputc ('\n', asm_out_file);
6323 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6325 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
6327 fputc ('\n', asm_out_file);
6328 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
6330 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
6333 fputc ('\n', asm_out_file);
6334 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6336 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
6338 fputc ('\n', asm_out_file);
6341 /* Output the compilation unit DIE and its children. */
6344 output_comp_unit (die)
6347 const char *secname;
6349 if (die->die_child == 0)
6352 /* Mark all the DIEs in this CU so we know which get local refs. */
6355 build_abbrev_table (die);
6357 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6358 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6359 calc_die_sizes (die);
6361 if (die->die_symbol)
6363 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6364 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6366 die->die_symbol = NULL;
6369 secname = (const char *) DEBUG_INFO_SECTION;
6371 /* Output debugging information. */
6372 fputc ('\n', asm_out_file);
6373 ASM_OUTPUT_SECTION (asm_out_file, secname);
6374 output_compilation_unit_header ();
6377 /* Leave the marks on the main CU, so we can check them in
6379 if (die->die_symbol)
6383 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6384 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6385 argument list, and maybe the scope. */
6388 dwarf2_name (decl, scope)
6392 return (*decl_printable_name) (decl, scope ? 1 : 0);
6395 /* Add a new entry to .debug_pubnames if appropriate. */
6398 add_pubname (decl, die)
6404 if (! TREE_PUBLIC (decl))
6407 if (pubname_table_in_use == pubname_table_allocated)
6409 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6410 pubname_table = (pubname_ref) xrealloc
6411 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6414 p = &pubname_table[pubname_table_in_use++];
6417 p->name = xstrdup (dwarf2_name (decl, 1));
6420 /* Output the public names table used to speed up access to externally
6421 visible names. For now, only generate entries for externally
6422 visible procedures. */
6427 register unsigned i;
6428 register unsigned long pubnames_length = size_of_pubnames ();
6430 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
6433 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
6436 fputc ('\n', asm_out_file);
6437 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6440 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6442 fputc ('\n', asm_out_file);
6443 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6445 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6448 fputc ('\n', asm_out_file);
6449 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
6451 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
6453 fputc ('\n', asm_out_file);
6454 for (i = 0; i < pubname_table_in_use; ++i)
6456 register pubname_ref pub = &pubname_table[i];
6458 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6459 if (pub->die->die_mark == 0)
6462 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
6464 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
6466 fputc ('\n', asm_out_file);
6470 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
6471 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
6475 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
6476 (int) strlen (pub->name) + 1);
6479 fputc ('\n', asm_out_file);
6482 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
6483 fputc ('\n', asm_out_file);
6486 /* Add a new entry to .debug_aranges if appropriate. */
6489 add_arange (decl, die)
6493 if (! DECL_SECTION_NAME (decl))
6496 if (arange_table_in_use == arange_table_allocated)
6498 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6500 = (arange_ref) xrealloc (arange_table,
6501 arange_table_allocated * sizeof (dw_die_ref));
6504 arange_table[arange_table_in_use++] = die;
6507 /* Output the information that goes into the .debug_aranges table.
6508 Namely, define the beginning and ending address range of the
6509 text section generated for this compilation unit. */
6514 register unsigned i;
6515 register unsigned long aranges_length = size_of_aranges ();
6517 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
6519 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
6522 fputc ('\n', asm_out_file);
6523 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6525 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6527 fputc ('\n', asm_out_file);
6528 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6530 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6533 fputc ('\n', asm_out_file);
6534 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6536 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
6538 fputc ('\n', asm_out_file);
6539 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6541 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
6544 fputc ('\n', asm_out_file);
6546 /* We need to align to twice the pointer size here. */
6547 if (DWARF_ARANGES_PAD_SIZE)
6549 /* Pad using a 2 bytes word so that padding is correct
6550 for any pointer size. */
6551 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
6552 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6553 fprintf (asm_out_file, ",0");
6555 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
6556 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
6559 fputc ('\n', asm_out_file);
6560 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
6562 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6564 fputc ('\n', asm_out_file);
6565 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
6566 text_section_label);
6568 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6570 fputc ('\n', asm_out_file);
6571 for (i = 0; i < arange_table_in_use; ++i)
6573 dw_die_ref die = arange_table[i];
6575 /* We shouldn't see aranges for DIEs outside of the main CU. */
6576 if (die->die_mark == 0)
6579 if (die->die_tag == DW_TAG_subprogram)
6580 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
6583 /* A static variable; extract the symbol from DW_AT_location.
6584 Note that this code isn't currently hit, as we only emit
6585 aranges for functions (jason 9/23/99). */
6587 dw_attr_ref a = get_AT (die, DW_AT_location);
6588 dw_loc_descr_ref loc;
6589 if (! a || AT_class (a) != dw_val_class_loc)
6593 if (loc->dw_loc_opc != DW_OP_addr)
6596 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
6597 loc->dw_loc_oprnd1.v.val_addr);
6601 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6603 fputc ('\n', asm_out_file);
6604 if (die->die_tag == DW_TAG_subprogram)
6605 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
6606 get_AT_low_pc (die));
6608 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
6609 get_AT_unsigned (die, DW_AT_byte_size));
6612 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6614 fputc ('\n', asm_out_file);
6617 /* Output the terminator words. */
6618 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6619 fputc ('\n', asm_out_file);
6620 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6621 fputc ('\n', asm_out_file);
6625 /* Data structure containing information about input files. */
6628 char *path; /* Complete file name. */
6629 char *fname; /* File name part. */
6630 int length; /* Length of entire string. */
6631 int file_idx; /* Index in input file table. */
6632 int dir_idx; /* Index in directory table. */
6635 /* Data structure containing information about directories with source
6639 char *path; /* Path including directory name. */
6640 int length; /* Path length. */
6641 int prefix; /* Index of directory entry which is a prefix. */
6642 int nbytes; /* Total number of bytes in all file names excluding
6644 int count; /* Number of files in this directory. */
6645 int dir_idx; /* Index of directory used as base. */
6646 int used; /* Used in the end? */
6649 /* Callback function for file_info comparison. We sort by looking at
6650 the directories in the path. */
6652 file_info_cmp (p1, p2)
6656 const struct file_info *s1 = p1;
6657 const struct file_info *s2 = p2;
6661 /* Take care of file names without directories. */
6662 if (s1->path == s1->fname)
6664 else if (s2->path == s2->fname)
6667 cp1 = (unsigned char *) s1->path;
6668 cp2 = (unsigned char *) s2->path;
6674 /* Reached the end of the first path? */
6675 if (cp1 == (unsigned char *) s1->fname)
6676 /* It doesn't really matter in which order files from the
6677 same directory are sorted in. Therefore don't test for
6678 the second path reaching the end. */
6680 else if (cp2 == (unsigned char *) s2->fname)
6683 /* Character of current path component the same? */
6689 /* Compute the maximum prefix of P2 appearing also in P1. Entire
6690 directory names must match. */
6691 static int prefix_of PARAMS ((struct dir_info *, struct dir_info *));
6694 struct dir_info *p1;
6695 struct dir_info *p2;
6697 char *s1 = p1->path;
6698 char *s2 = p2->path;
6699 int len = p1->length < p2->length ? p1->length : p2->length;
6701 while (*s1 == *s2 && s1 < p1->path + len)
6704 if (*s1 == '/' && *s2 == '/')
6705 /* The whole of P1 is the prefix. */
6708 /* Go back to the last directory component. */
6709 while (s1 > p1->path)
6711 return s1 - p1->path + 1;
6716 /* Output the directory table and the file name table. We try to minimize
6717 the total amount of memory needed. A heuristic is used to avoid large
6718 slowdowns with many input files. */
6720 output_file_names ()
6722 struct file_info *files;
6723 struct dir_info *dirs;
6732 /* Allocate the various arrays we need. */
6733 files = (struct file_info *) alloca (line_file_table.in_use
6734 * sizeof (struct file_info));
6735 dirs = (struct dir_info *) alloca (line_file_table.in_use * 2
6736 * sizeof (struct dir_info));
6738 /* Sort the file names. */
6739 for (i = 1; i < (int) line_file_table.in_use; ++i)
6743 /* Skip all leading "./". */
6744 f = line_file_table.table[i];
6745 while (f[0] == '.' && f[1] == '/')
6748 /* Create a new array entry. */
6750 files[i].length = strlen (f);
6751 files[i].file_idx = i;
6753 /* Search for the file name part. */
6754 f = strrchr (f, '/');
6755 files[i].fname = f == NULL ? files[i].path : f + 1;
6757 qsort (files + 1, line_file_table.in_use - 1, sizeof (files[0]),
6760 /* Find all the different directories used. */
6761 dirs[0].path = files[1].path;
6762 dirs[0].length = files[1].fname - files[1].path;
6763 dirs[0].prefix = -1;
6764 dirs[0].nbytes = files[1].length - dirs[1].length + 1;
6766 dirs[0].dir_idx = 0;
6768 files[1].dir_idx = 0;
6771 for (i = 2; i < (int) line_file_table.in_use; ++i)
6772 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6773 && memcmp (dirs[ndirs - 1].path, files[i].path,
6774 dirs[ndirs - 1].length) == 0)
6776 /* Same directory as last entry. */
6777 files[i].dir_idx = ndirs - 1;
6778 dirs[ndirs - 1].nbytes += files[i].length - dirs[ndirs - 1].length + 1;
6779 ++dirs[ndirs - 1].count;
6787 /* This is a new directory. */
6788 dirs[ndirs].path = files[i].path;
6789 dirs[ndirs].length = files[i].fname - files[i].path;
6790 dirs[ndirs].nbytes = files[i].length - dirs[i].length + 1;
6791 dirs[ndirs].count = 1;
6792 dirs[ndirs].dir_idx = ndirs;
6793 dirs[ndirs].used = 0;
6794 files[i].dir_idx = ndirs;
6796 /* Search for a prefix. */
6799 for (j = 0; j < ndirs; ++j)
6800 if (dirs[j].length > max_len)
6802 int this_len = prefix_of (&dirs[j], &dirs[ndirs]);
6804 if (this_len > max_len)
6811 /* Remember the prefix. If this is a known prefix simply
6812 remember the index. Otherwise we will have to create an
6813 artificial entry. */
6814 if (max_len == dirs[max_idx].length)
6815 /* This is our prefix. */
6816 dirs[ndirs].prefix = max_idx;
6817 else if (max_len > 0)
6819 /* Create an entry without associated file. Since we have
6820 to keep the dirs array sorted (means, entries with paths
6821 which come first) we have to move the new entry in the
6822 place of the old one. */
6823 dirs[++ndirs] = dirs[max_idx];
6825 /* We don't have to set .path. */
6826 dirs[max_idx].length = max_len;
6827 dirs[max_idx].nbytes = 0;
6828 dirs[max_idx].count = 0;
6829 dirs[max_idx].dir_idx = ndirs;
6830 dirs[max_idx].used = 0;
6831 dirs[max_idx].prefix = dirs[ndirs].prefix;
6833 dirs[ndirs - 1].prefix = dirs[ndirs].prefix = max_idx;
6836 dirs[ndirs].prefix = -1;
6841 /* Now to the actual work. We have to find a subset of the
6842 directories which allow expressing the file name using references
6843 to the directory table with the least amount of characters. We
6844 do not do an exhaustive search where we would have to check out
6845 every combination of every single possible prefix. Instead we
6846 use a heuristic which provides nearly optimal results in most
6847 cases and never is much off. */
6848 saved = (int *) alloca (ndirs * sizeof (int));
6849 savehere = (int *) alloca (ndirs * sizeof (int));
6851 memset (saved, '\0', ndirs * sizeof (saved[0]));
6852 for (i = 0; i < ndirs; ++i)
6857 /* We can always safe some space for the current directory. But
6858 this does not mean it will be enough to justify adding the
6860 savehere[i] = dirs[i].length;
6861 total = (savehere[i] - saved[i]) * dirs[i].count;
6863 for (j = i + 1; j < ndirs; ++j)
6867 if (saved[j] < dirs[i].length)
6869 /* Determine whether the dirs[i] path is a prefix of the
6874 while (k != -1 && k != i)
6879 /* Yes it is. We can possibly safe some memory but
6880 writing the filenames in dirs[j] relative to
6882 savehere[j] = dirs[i].length;
6883 total += (savehere[j] - saved[j]) * dirs[j].count;
6888 /* Check whether we can safe enough to justify adding the dirs[i]
6890 if (total > dirs[i].length + 1)
6892 /* It's worthwhile adding. */
6893 for (j = i; j < ndirs; ++j)
6894 if (savehere[j] > 0)
6896 /* Remember how much we saved for this directory so far. */
6897 saved[j] = savehere[j];
6899 /* Remember the prefix directory. */
6900 dirs[j].dir_idx = i;
6905 /* We have to emit them in the order they appear in the line_file_table
6906 array since the index is used in the debug info generation. To
6907 do this efficiently we generate a back-mapping of the indices
6909 backmap = (int *) alloca (line_file_table.in_use * sizeof (int));
6910 for (i = 1; i < (int) line_file_table.in_use; ++i)
6912 backmap[files[i].file_idx] = i;
6913 /* Mark this directory as used. */
6914 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6917 /* That was it. We are ready to emit the information. First the
6918 directory name table. Here we have to make sure that the first
6919 actually emitted directory name has the index one. Zero is
6920 reserved for the current working directory. Make sure we do not
6921 confuse these indices with the one for the constructed table
6922 (even though most of the time they are identical). */
6924 idx_offset = dirs[0].length > 0 ? 1 : 0;
6925 for (i = 1 - idx_offset; i < ndirs; ++i)
6926 if (dirs[i].used != 0)
6928 dirs[i].used = idx++;
6932 ASM_OUTPUT_DWARF_NSTRING (asm_out_file,
6933 dirs[i].path, dirs[i].length - 1);
6934 fprintf (asm_out_file, "%s Directory Entry: 0x%x\n",
6935 ASM_COMMENT_START, dirs[i].used);
6939 ASM_OUTPUT_ASCII (asm_out_file, dirs[i].path, dirs[i].length - 1);
6940 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6941 fputc ('\n', asm_out_file);
6944 /* Correct the index for the current working directory entry if it
6946 if (idx_offset == 0)
6948 /* Terminate the directory name array. */
6949 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6951 fprintf (asm_out_file, "\t%s End directory table", ASM_COMMENT_START);
6952 fputc ('\n', asm_out_file);
6954 /* Now write all the file names. */
6955 for (i = 1; i < (int) line_file_table.in_use; ++i)
6957 int file_idx = backmap[i];
6958 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6962 ASM_OUTPUT_DWARF_STRING (asm_out_file,
6963 files[file_idx].path
6964 + dirs[dir_idx].length);
6965 fprintf (asm_out_file, "%s File Entry: 0x%x\n",
6966 ASM_COMMENT_START, i);
6969 ASM_OUTPUT_ASCII (asm_out_file,
6970 files[file_idx].path + dirs[dir_idx].length,
6971 (files[file_idx].length
6972 - dirs[dir_idx].length) + 1);
6974 /* Include directory index. */
6975 output_uleb128 (dirs[dir_idx].used);
6976 fputc ('\n', asm_out_file);
6978 /* Modification time. */
6980 fputc ('\n', asm_out_file);
6982 /* File length in bytes. */
6984 fputc ('\n', asm_out_file);
6987 /* Terminate the file name table */
6988 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6990 fprintf (asm_out_file, "\t%s End file name table", ASM_COMMENT_START);
6991 fputc ('\n', asm_out_file);
6995 /* Output the source line number correspondence information. This
6996 information goes into the .debug_line section. */
7001 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7002 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7003 register unsigned opc;
7004 register unsigned n_op_args;
7005 register unsigned long lt_index;
7006 register unsigned long current_line;
7007 register long line_offset;
7008 register long line_delta;
7009 register unsigned long current_file;
7010 register unsigned long function;
7012 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
7014 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
7017 fputc ('\n', asm_out_file);
7018 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
7019 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
7021 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
7023 fputc ('\n', asm_out_file);
7024 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
7026 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
7028 fputc ('\n', asm_out_file);
7029 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
7031 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
7034 fputc ('\n', asm_out_file);
7035 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
7037 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
7040 fputc ('\n', asm_out_file);
7041 fprintf (asm_out_file, "%s%d", ASM_BYTE_OP, DWARF_LINE_BASE);
7043 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
7046 fputc ('\n', asm_out_file);
7047 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
7049 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
7052 fputc ('\n', asm_out_file);
7053 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
7055 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
7057 fputc ('\n', asm_out_file);
7058 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
7062 case DW_LNS_advance_pc:
7063 case DW_LNS_advance_line:
7064 case DW_LNS_set_file:
7065 case DW_LNS_set_column:
7066 case DW_LNS_fixed_advance_pc:
7073 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
7075 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
7076 ASM_COMMENT_START, opc, n_op_args);
7077 fputc ('\n', asm_out_file);
7080 /* Write out the information about the files we use. */
7081 output_file_names ();
7083 /* We used to set the address register to the first location in the text
7084 section here, but that didn't accomplish anything since we already
7085 have a line note for the opening brace of the first function. */
7087 /* Generate the line number to PC correspondence table, encoded as
7088 a series of state machine operations. */
7091 strcpy (prev_line_label, text_section_label);
7092 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7094 register dw_line_info_ref line_info = &line_info_table[lt_index];
7097 /* Disable this optimization for now; GDB wants to see two line notes
7098 at the beginning of a function so it can find the end of the
7101 /* Don't emit anything for redundant notes. Just updating the
7102 address doesn't accomplish anything, because we already assume
7103 that anything after the last address is this line. */
7104 if (line_info->dw_line_num == current_line
7105 && line_info->dw_file_num == current_file)
7109 /* Emit debug info for the address of the current line, choosing
7110 the encoding that uses the least amount of space. */
7111 /* ??? Unfortunately, we have little choice here currently, and must
7112 always use the most general form. Gcc does not know the address
7113 delta itself, so we can't use DW_LNS_advance_pc. There are no known
7114 dwarf2 aware assemblers at this time, so we can't use any special
7115 pseudo ops that would allow the assembler to optimally encode this for
7116 us. Many ports do have length attributes which will give an upper
7117 bound on the address range. We could perhaps use length attributes
7118 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
7119 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7122 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7123 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7125 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7128 fputc ('\n', asm_out_file);
7129 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
7130 fputc ('\n', asm_out_file);
7134 /* This can handle any delta. This takes
7135 4+DWARF2_ADDR_SIZE bytes. */
7136 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7138 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7140 fputc ('\n', asm_out_file);
7141 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7142 fputc ('\n', asm_out_file);
7143 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7144 fputc ('\n', asm_out_file);
7145 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7146 fputc ('\n', asm_out_file);
7148 strcpy (prev_line_label, line_label);
7150 /* Emit debug info for the source file of the current line, if
7151 different from the previous line. */
7152 if (line_info->dw_file_num != current_file)
7154 current_file = line_info->dw_file_num;
7155 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
7157 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
7159 fputc ('\n', asm_out_file);
7160 output_uleb128 (current_file);
7162 fprintf (asm_out_file, " (\"%s\")",
7163 line_file_table.table[current_file]);
7165 fputc ('\n', asm_out_file);
7168 /* Emit debug info for the current line number, choosing the encoding
7169 that uses the least amount of space. */
7170 if (line_info->dw_line_num != current_line)
7172 line_offset = line_info->dw_line_num - current_line;
7173 line_delta = line_offset - DWARF_LINE_BASE;
7174 current_line = line_info->dw_line_num;
7175 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7177 /* This can handle deltas from -10 to 234, using the current
7178 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7180 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
7181 DWARF_LINE_OPCODE_BASE + line_delta);
7183 fprintf (asm_out_file,
7184 "\t%s line %ld", ASM_COMMENT_START, current_line);
7186 fputc ('\n', asm_out_file);
7190 /* This can handle any delta. This takes at least 4 bytes,
7191 depending on the value being encoded. */
7192 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
7194 fprintf (asm_out_file, "\t%s advance to line %ld",
7195 ASM_COMMENT_START, current_line);
7197 fputc ('\n', asm_out_file);
7198 output_sleb128 (line_offset);
7199 fputc ('\n', asm_out_file);
7200 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7202 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7203 fputc ('\n', asm_out_file);
7208 /* We still need to start a new row, so output a copy insn. */
7209 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7211 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7212 fputc ('\n', asm_out_file);
7216 /* Emit debug info for the address of the end of the function. */
7219 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7221 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7224 fputc ('\n', asm_out_file);
7225 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
7226 fputc ('\n', asm_out_file);
7230 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7232 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
7233 fputc ('\n', asm_out_file);
7234 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7235 fputc ('\n', asm_out_file);
7236 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7237 fputc ('\n', asm_out_file);
7238 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
7239 fputc ('\n', asm_out_file);
7242 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7244 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
7246 fputc ('\n', asm_out_file);
7248 fputc ('\n', asm_out_file);
7249 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
7250 fputc ('\n', asm_out_file);
7255 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7257 register dw_separate_line_info_ref line_info
7258 = &separate_line_info_table[lt_index];
7261 /* Don't emit anything for redundant notes. */
7262 if (line_info->dw_line_num == current_line
7263 && line_info->dw_file_num == current_file
7264 && line_info->function == function)
7268 /* Emit debug info for the address of the current line. If this is
7269 a new function, or the first line of a function, then we need
7270 to handle it differently. */
7271 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7273 if (function != line_info->function)
7275 function = line_info->function;
7277 /* Set the address register to the first line in the function */
7278 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7280 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7283 fputc ('\n', asm_out_file);
7284 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7285 fputc ('\n', asm_out_file);
7286 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7287 fputc ('\n', asm_out_file);
7288 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7289 fputc ('\n', asm_out_file);
7293 /* ??? See the DW_LNS_advance_pc comment above. */
7296 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7298 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7301 fputc ('\n', asm_out_file);
7302 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7304 fputc ('\n', asm_out_file);
7308 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7310 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7312 fputc ('\n', asm_out_file);
7313 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7314 fputc ('\n', asm_out_file);
7315 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7316 fputc ('\n', asm_out_file);
7317 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7318 fputc ('\n', asm_out_file);
7321 strcpy (prev_line_label, line_label);
7323 /* Emit debug info for the source file of the current line, if
7324 different from the previous line. */
7325 if (line_info->dw_file_num != current_file)
7327 current_file = line_info->dw_file_num;
7328 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
7330 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
7332 fputc ('\n', asm_out_file);
7333 output_uleb128 (current_file);
7335 fprintf (asm_out_file, " (\"%s\")",
7336 line_file_table.table[current_file]);
7338 fputc ('\n', asm_out_file);
7341 /* Emit debug info for the current line number, choosing the encoding
7342 that uses the least amount of space. */
7343 if (line_info->dw_line_num != current_line)
7345 line_offset = line_info->dw_line_num - current_line;
7346 line_delta = line_offset - DWARF_LINE_BASE;
7347 current_line = line_info->dw_line_num;
7348 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7350 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
7351 DWARF_LINE_OPCODE_BASE + line_delta);
7353 fprintf (asm_out_file,
7354 "\t%s line %ld", ASM_COMMENT_START, current_line);
7356 fputc ('\n', asm_out_file);
7360 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
7362 fprintf (asm_out_file, "\t%s advance to line %ld",
7363 ASM_COMMENT_START, current_line);
7365 fputc ('\n', asm_out_file);
7366 output_sleb128 (line_offset);
7367 fputc ('\n', asm_out_file);
7368 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7370 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7371 fputc ('\n', asm_out_file);
7376 /* We still need to start a new row, so output a copy insn. */
7377 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7379 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7380 fputc ('\n', asm_out_file);
7388 /* If we're done with a function, end its sequence. */
7389 if (lt_index == separate_line_info_table_in_use
7390 || separate_line_info_table[lt_index].function != function)
7395 /* Emit debug info for the address of the end of the function. */
7396 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7399 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7401 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7404 fputc ('\n', asm_out_file);
7405 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7407 fputc ('\n', asm_out_file);
7411 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7413 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7415 fputc ('\n', asm_out_file);
7416 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7417 fputc ('\n', asm_out_file);
7418 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7419 fputc ('\n', asm_out_file);
7420 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7421 fputc ('\n', asm_out_file);
7424 /* Output the marker for the end of this sequence. */
7425 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7427 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
7430 fputc ('\n', asm_out_file);
7432 fputc ('\n', asm_out_file);
7433 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
7434 fputc ('\n', asm_out_file);
7438 /* Output the marker for the end of the line number info. */
7439 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
7442 /* Given a pointer to a tree node for some base type, return a pointer to
7443 a DIE that describes the given type.
7445 This routine must only be called for GCC type nodes that correspond to
7446 Dwarf base (fundamental) types. */
7449 base_type_die (type)
7452 register dw_die_ref base_type_result;
7453 register const char *type_name;
7454 register enum dwarf_type encoding;
7455 register tree name = TYPE_NAME (type);
7457 if (TREE_CODE (type) == ERROR_MARK
7458 || TREE_CODE (type) == VOID_TYPE)
7463 if (TREE_CODE (name) == TYPE_DECL)
7464 name = DECL_NAME (name);
7466 type_name = IDENTIFIER_POINTER (name);
7469 type_name = "__unknown__";
7471 switch (TREE_CODE (type))
7474 /* Carefully distinguish the C character types, without messing
7475 up if the language is not C. Note that we check only for the names
7476 that contain spaces; other names might occur by coincidence in other
7478 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7479 && (type == char_type_node
7480 || ! strcmp (type_name, "signed char")
7481 || ! strcmp (type_name, "unsigned char"))))
7483 if (TREE_UNSIGNED (type))
7484 encoding = DW_ATE_unsigned;
7486 encoding = DW_ATE_signed;
7489 /* else fall through. */
7492 /* GNU Pascal/Ada CHAR type. Not used in C. */
7493 if (TREE_UNSIGNED (type))
7494 encoding = DW_ATE_unsigned_char;
7496 encoding = DW_ATE_signed_char;
7500 encoding = DW_ATE_float;
7503 /* Dwarf2 doesn't know anything about complex ints, so use
7504 a user defined type for it. */
7506 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7507 encoding = DW_ATE_complex_float;
7509 encoding = DW_ATE_lo_user;
7513 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7514 encoding = DW_ATE_boolean;
7518 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7521 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7522 if (demangle_name_func)
7523 type_name = (*demangle_name_func) (type_name);
7525 add_AT_string (base_type_result, DW_AT_name, type_name);
7526 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7527 int_size_in_bytes (type));
7528 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7530 return base_type_result;
7533 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7534 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7535 a given type is generally the same as the given type, except that if the
7536 given type is a pointer or reference type, then the root type of the given
7537 type is the root type of the "basis" type for the pointer or reference
7538 type. (This definition of the "root" type is recursive.) Also, the root
7539 type of a `const' qualified type or a `volatile' qualified type is the
7540 root type of the given type without the qualifiers. */
7546 if (TREE_CODE (type) == ERROR_MARK)
7547 return error_mark_node;
7549 switch (TREE_CODE (type))
7552 return error_mark_node;
7555 case REFERENCE_TYPE:
7556 return type_main_variant (root_type (TREE_TYPE (type)));
7559 return type_main_variant (type);
7563 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7564 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7570 switch (TREE_CODE (type))
7585 case QUAL_UNION_TYPE:
7590 case REFERENCE_TYPE:
7604 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7605 entry that chains various modifiers in front of the given type. */
7608 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7610 register int is_const_type;
7611 register int is_volatile_type;
7612 register dw_die_ref context_die;
7614 register enum tree_code code = TREE_CODE (type);
7615 register dw_die_ref mod_type_die = NULL;
7616 register dw_die_ref sub_die = NULL;
7617 register tree item_type = NULL;
7619 if (code != ERROR_MARK)
7621 type = build_type_variant (type, is_const_type, is_volatile_type);
7623 mod_type_die = lookup_type_die (type);
7625 return mod_type_die;
7627 /* Handle C typedef types. */
7628 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7629 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
7631 tree dtype = TREE_TYPE (TYPE_NAME (type));
7634 /* For a named type, use the typedef. */
7635 gen_type_die (type, context_die);
7636 mod_type_die = lookup_type_die (type);
7639 else if (is_const_type < TYPE_READONLY (dtype)
7640 || is_volatile_type < TYPE_VOLATILE (dtype))
7641 /* cv-unqualified version of named type. Just use the unnamed
7642 type to which it refers. */
7644 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
7645 is_const_type, is_volatile_type,
7647 /* Else cv-qualified version of named type; fall through. */
7653 else if (is_const_type)
7655 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7656 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7658 else if (is_volatile_type)
7660 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7661 sub_die = modified_type_die (type, 0, 0, context_die);
7663 else if (code == POINTER_TYPE)
7665 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7666 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7668 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7670 item_type = TREE_TYPE (type);
7672 else if (code == REFERENCE_TYPE)
7674 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7675 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7677 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7679 item_type = TREE_TYPE (type);
7681 else if (is_base_type (type))
7682 mod_type_die = base_type_die (type);
7685 gen_type_die (type, context_die);
7687 /* We have to get the type_main_variant here (and pass that to the
7688 `lookup_type_die' routine) because the ..._TYPE node we have
7689 might simply be a *copy* of some original type node (where the
7690 copy was created to help us keep track of typedef names) and
7691 that copy might have a different TYPE_UID from the original
7693 mod_type_die = lookup_type_die (type_main_variant (type));
7694 if (mod_type_die == NULL)
7699 equate_type_number_to_die (type, mod_type_die);
7701 /* We must do this after the equate_type_number_to_die call, in case
7702 this is a recursive type. This ensures that the modified_type_die
7703 recursion will terminate even if the type is recursive. Recursive
7704 types are possible in Ada. */
7705 sub_die = modified_type_die (item_type,
7706 TYPE_READONLY (item_type),
7707 TYPE_VOLATILE (item_type),
7710 if (sub_die != NULL)
7711 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7713 return mod_type_die;
7716 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7717 an enumerated type. */
7723 return TREE_CODE (type) == ENUMERAL_TYPE;
7726 /* Return the register number described by a given RTL node. */
7732 register unsigned regno = REGNO (rtl);
7734 if (regno >= FIRST_PSEUDO_REGISTER)
7736 warning ("internal regno botch: regno = %d\n", regno);
7740 regno = DBX_REGISTER_NUMBER (regno);
7744 /* Return a location descriptor that designates a machine register. */
7746 static dw_loc_descr_ref
7747 reg_loc_descriptor (rtl)
7750 register dw_loc_descr_ref loc_result = NULL;
7751 register unsigned reg = reg_number (rtl);
7754 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7756 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7761 /* Return a location descriptor that designates a constant. */
7763 static dw_loc_descr_ref
7764 int_loc_descriptor (i)
7767 enum dwarf_location_atom op;
7769 /* Pick the smallest representation of a constant, rather than just
7770 defaulting to the LEB encoding. */
7774 op = DW_OP_lit0 + i;
7777 else if (i <= 0xffff)
7779 else if (HOST_BITS_PER_WIDE_INT == 32
7789 else if (i >= -0x8000)
7791 else if (HOST_BITS_PER_WIDE_INT == 32
7792 || i >= -0x80000000)
7798 return new_loc_descr (op, i, 0);
7801 /* Return a location descriptor that designates a base+offset location. */
7803 static dw_loc_descr_ref
7804 based_loc_descr (reg, offset)
7808 register dw_loc_descr_ref loc_result;
7809 /* For the "frame base", we use the frame pointer or stack pointer
7810 registers, since the RTL for local variables is relative to one of
7812 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7813 ? HARD_FRAME_POINTER_REGNUM
7814 : STACK_POINTER_REGNUM);
7817 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7819 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7821 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7826 /* Return true if this RTL expression describes a base+offset calculation. */
7832 return (GET_CODE (rtl) == PLUS
7833 && ((GET_CODE (XEXP (rtl, 0)) == REG
7834 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7837 /* The following routine converts the RTL for a variable or parameter
7838 (resident in memory) into an equivalent Dwarf representation of a
7839 mechanism for getting the address of that same variable onto the top of a
7840 hypothetical "address evaluation" stack.
7842 When creating memory location descriptors, we are effectively transforming
7843 the RTL for a memory-resident object into its Dwarf postfix expression
7844 equivalent. This routine recursively descends an RTL tree, turning
7845 it into Dwarf postfix code as it goes.
7847 MODE is the mode of the memory reference, needed to handle some
7848 autoincrement addressing modes. */
7850 static dw_loc_descr_ref
7851 mem_loc_descriptor (rtl, mode)
7853 enum machine_mode mode;
7855 dw_loc_descr_ref mem_loc_result = NULL;
7856 /* Note that for a dynamically sized array, the location we will generate a
7857 description of here will be the lowest numbered location which is
7858 actually within the array. That's *not* necessarily the same as the
7859 zeroth element of the array. */
7861 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7862 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7865 switch (GET_CODE (rtl))
7870 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7871 just fall into the SUBREG code. */
7876 /* The case of a subreg may arise when we have a local (register)
7877 variable or a formal (register) parameter which doesn't quite fill
7878 up an entire register. For now, just assume that it is
7879 legitimate to make the Dwarf info refer to the whole register which
7880 contains the given subreg. */
7881 rtl = XEXP (rtl, 0);
7886 /* Whenever a register number forms a part of the description of the
7887 method for calculating the (dynamic) address of a memory resident
7888 object, DWARF rules require the register number be referred to as
7889 a "base register". This distinction is not based in any way upon
7890 what category of register the hardware believes the given register
7891 belongs to. This is strictly DWARF terminology we're dealing with
7892 here. Note that in cases where the location of a memory-resident
7893 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7894 OP_CONST (0)) the actual DWARF location descriptor that we generate
7895 may just be OP_BASEREG (basereg). This may look deceptively like
7896 the object in question was allocated to a register (rather than in
7897 memory) so DWARF consumers need to be aware of the subtle
7898 distinction between OP_REG and OP_BASEREG. */
7899 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7903 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7904 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7908 /* Some ports can transform a symbol ref into a label ref, because
7909 the symbol ref is too far away and has to be dumped into a constant
7913 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7914 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7915 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7919 /* Extract the PLUS expression nested inside and fall into
7920 PLUS code bellow. */
7921 rtl = XEXP (rtl, 1);
7926 /* Turn these into a PLUS expression and fall into the PLUS code
7928 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7929 GEN_INT (GET_CODE (rtl) == PRE_INC
7930 ? GET_MODE_UNIT_SIZE (mode)
7931 : -GET_MODE_UNIT_SIZE (mode)));
7937 if (is_based_loc (rtl))
7938 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7939 INTVAL (XEXP (rtl, 1)));
7942 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7944 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7945 && INTVAL (XEXP (rtl, 1)) >= 0)
7947 add_loc_descr (&mem_loc_result,
7948 new_loc_descr (DW_OP_plus_uconst,
7949 INTVAL (XEXP (rtl, 1)), 0));
7953 add_loc_descr (&mem_loc_result,
7954 mem_loc_descriptor (XEXP (rtl, 1), mode));
7955 add_loc_descr (&mem_loc_result,
7956 new_loc_descr (DW_OP_plus, 0, 0));
7962 /* If a pseudo-reg is optimized away, it is possible for it to
7963 be replaced with a MEM containing a multiply. */
7964 add_loc_descr (&mem_loc_result,
7965 mem_loc_descriptor (XEXP (rtl, 0), mode));
7966 add_loc_descr (&mem_loc_result,
7967 mem_loc_descriptor (XEXP (rtl, 1), mode));
7968 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7972 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7979 return mem_loc_result;
7982 /* Return a descriptor that describes the concatenation of two locations.
7983 This is typically a complex variable. */
7985 static dw_loc_descr_ref
7986 concat_loc_descriptor (x0, x1)
7987 register rtx x0, x1;
7989 dw_loc_descr_ref cc_loc_result = NULL;
7991 if (!is_pseudo_reg (x0)
7992 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7993 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7994 add_loc_descr (&cc_loc_result,
7995 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7997 if (!is_pseudo_reg (x1)
7998 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7999 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
8000 add_loc_descr (&cc_loc_result,
8001 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
8003 return cc_loc_result;
8006 /* Output a proper Dwarf location descriptor for a variable or parameter
8007 which is either allocated in a register or in a memory location. For a
8008 register, we just generate an OP_REG and the register number. For a
8009 memory location we provide a Dwarf postfix expression describing how to
8010 generate the (dynamic) address of the object onto the address stack. */
8012 static dw_loc_descr_ref
8013 loc_descriptor (rtl)
8016 dw_loc_descr_ref loc_result = NULL;
8017 switch (GET_CODE (rtl))
8020 /* The case of a subreg may arise when we have a local (register)
8021 variable or a formal (register) parameter which doesn't quite fill
8022 up an entire register. For now, just assume that it is
8023 legitimate to make the Dwarf info refer to the whole register which
8024 contains the given subreg. */
8025 rtl = XEXP (rtl, 0);
8030 loc_result = reg_loc_descriptor (rtl);
8034 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8038 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
8048 /* Similar, but generate the descriptor from trees instead of rtl.
8049 This comes up particularly with variable length arrays. */
8051 static dw_loc_descr_ref
8052 loc_descriptor_from_tree (loc, addressp)
8056 dw_loc_descr_ref ret = NULL;
8057 int indirect_size = 0;
8058 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
8059 enum dwarf_location_atom op;
8061 /* ??? Most of the time we do not take proper care for sign/zero
8062 extending the values properly. Hopefully this won't be a real
8065 switch (TREE_CODE (loc))
8070 case WITH_RECORD_EXPR:
8071 /* This case involves extracting fields from an object to determine the
8072 position of other fields. We don't try to encode this here. The
8073 only user of this is Ada, which encodes the needed information using
8074 the names of types. */
8080 rtx rtl = rtl_for_decl_location (loc);
8081 enum machine_mode mode = DECL_MODE (loc);
8083 if (rtl == NULL_RTX)
8085 else if (CONSTANT_P (rtl))
8087 ret = new_loc_descr (DW_OP_addr, 0, 0);
8088 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8089 ret->dw_loc_oprnd1.v.val_addr = rtl;
8090 indirect_size = GET_MODE_SIZE (mode);
8094 if (GET_CODE (rtl) == MEM)
8096 indirect_size = GET_MODE_SIZE (mode);
8097 rtl = XEXP (rtl, 0);
8099 ret = mem_loc_descriptor (rtl, mode);
8105 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8106 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
8111 case NON_LVALUE_EXPR:
8113 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8120 HOST_WIDE_INT bitsize, bitpos, bytepos;
8121 enum machine_mode mode;
8123 unsigned int alignment;
8125 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8126 &unsignedp, &volatilep, &alignment);
8127 ret = loc_descriptor_from_tree (obj, 1);
8129 if (offset != NULL_TREE)
8131 /* Variable offset. */
8132 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8133 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8138 /* We cannot address anything not on a unit boundary. */
8139 if (bitpos % BITS_PER_UNIT != 0)
8144 if (bitpos % BITS_PER_UNIT != 0
8145 || bitsize % BITS_PER_UNIT != 0)
8147 /* ??? We could handle this by loading and shifting etc.
8148 Wait until someone needs it before expending the effort. */
8152 indirect_size = bitsize / BITS_PER_UNIT;
8155 bytepos = bitpos / BITS_PER_UNIT;
8157 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8158 else if (bytepos < 0)
8160 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8161 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8167 if (host_integerp (loc, 0))
8168 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8180 case TRUNC_DIV_EXPR:
8186 case TRUNC_MOD_EXPR:
8196 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8199 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8200 && host_integerp (TREE_OPERAND (loc, 1), 0))
8202 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8203 add_loc_descr (&ret,
8204 new_loc_descr (DW_OP_plus_uconst,
8205 tree_low_cst (TREE_OPERAND (loc, 1),
8213 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8218 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8223 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8228 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8240 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8241 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
8242 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8256 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8257 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8261 loc = build (COND_EXPR, TREE_TYPE (loc),
8262 build (LT_EXPR, integer_type_node,
8263 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8264 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8269 dw_loc_descr_ref bra_node, jump_node, tmp;
8271 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8272 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8273 add_loc_descr (&ret, bra_node);
8275 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8276 add_loc_descr (&ret, tmp);
8277 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8278 add_loc_descr (&ret, jump_node);
8280 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8281 add_loc_descr (&ret, tmp);
8282 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8283 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
8285 /* ??? Need a node to point the skip at. Use a nop. */
8286 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8287 add_loc_descr (&ret, tmp);
8288 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8289 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8297 /* If we can't fill the request for an address, die. */
8298 if (addressp && indirect_size == 0)
8301 /* If we've got an address and don't want one, dereference. */
8302 if (!addressp && indirect_size > 0)
8304 if (indirect_size > DWARF2_ADDR_SIZE)
8306 if (indirect_size == DWARF2_ADDR_SIZE)
8309 op = DW_OP_deref_size;
8310 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
8316 /* Given a value, round it up to the lowest multiple of `boundary'
8317 which is not less than the value itself. */
8319 static inline HOST_WIDE_INT
8320 ceiling (value, boundary)
8321 HOST_WIDE_INT value;
8322 unsigned int boundary;
8324 return (((value + boundary - 1) / boundary) * boundary);
8327 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8328 pointer to the declared type for the relevant field variable, or return
8329 `integer_type_node' if the given node turns out to be an
8338 if (TREE_CODE (decl) == ERROR_MARK)
8339 return integer_type_node;
8341 type = DECL_BIT_FIELD_TYPE (decl);
8342 if (type == NULL_TREE)
8343 type = TREE_TYPE (decl);
8348 /* Given a pointer to a tree node, return the alignment in bits for
8349 it, or else return BITS_PER_WORD if the node actually turns out to
8350 be an ERROR_MARK node. */
8352 static inline unsigned
8353 simple_type_align_in_bits (type)
8356 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8359 static inline unsigned
8360 simple_decl_align_in_bits (decl)
8363 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8366 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8367 node, return the size in bits for the type if it is a constant, or else
8368 return the alignment for the type if the type's size is not constant, or
8369 else return BITS_PER_WORD if the type actually turns out to be an
8372 static inline unsigned HOST_WIDE_INT
8373 simple_type_size_in_bits (type)
8376 tree type_size_tree;
8378 if (TREE_CODE (type) == ERROR_MARK)
8379 return BITS_PER_WORD;
8380 type_size_tree = TYPE_SIZE (type);
8382 if (type_size_tree == NULL_TREE)
8384 if (! host_integerp (type_size_tree, 1))
8385 return TYPE_ALIGN (type);
8386 return tree_low_cst (type_size_tree, 1);
8389 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
8390 return the byte offset of the lowest addressed byte of the "containing
8391 object" for the given FIELD_DECL, or return 0 if we are unable to
8392 determine what that offset is, either because the argument turns out to
8393 be a pointer to an ERROR_MARK node, or because the offset is actually
8394 variable. (We can't handle the latter case just yet). */
8396 static HOST_WIDE_INT
8397 field_byte_offset (decl)
8400 unsigned int type_align_in_bits;
8401 unsigned int decl_align_in_bits;
8402 unsigned HOST_WIDE_INT type_size_in_bits;
8403 HOST_WIDE_INT object_offset_in_bits;
8404 HOST_WIDE_INT object_offset_in_bytes;
8406 tree field_size_tree;
8407 HOST_WIDE_INT bitpos_int;
8408 HOST_WIDE_INT deepest_bitpos;
8409 unsigned HOST_WIDE_INT field_size_in_bits;
8411 if (TREE_CODE (decl) == ERROR_MARK)
8414 if (TREE_CODE (decl) != FIELD_DECL)
8417 type = field_type (decl);
8418 field_size_tree = DECL_SIZE (decl);
8420 /* The size could be unspecified if there was an error, or for
8421 a flexible array member. */
8422 if (! field_size_tree)
8423 field_size_tree = bitsize_zero_node;
8425 /* We cannot yet cope with fields whose positions are variable, so
8426 for now, when we see such things, we simply return 0. Someday, we may
8427 be able to handle such cases, but it will be damn difficult. */
8428 if (! host_integerp (bit_position (decl), 0))
8431 bitpos_int = int_bit_position (decl);
8433 /* If we don't know the size of the field, pretend it's a full word. */
8434 if (host_integerp (field_size_tree, 1))
8435 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8437 field_size_in_bits = BITS_PER_WORD;
8439 type_size_in_bits = simple_type_size_in_bits (type);
8440 type_align_in_bits = simple_type_align_in_bits (type);
8441 decl_align_in_bits = simple_decl_align_in_bits (decl);
8443 /* Note that the GCC front-end doesn't make any attempt to keep track of
8444 the starting bit offset (relative to the start of the containing
8445 structure type) of the hypothetical "containing object" for a bit-
8446 field. Thus, when computing the byte offset value for the start of the
8447 "containing object" of a bit-field, we must deduce this information on
8448 our own. This can be rather tricky to do in some cases. For example,
8449 handling the following structure type definition when compiling for an
8450 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8453 struct S { int field1; long long field2:31; };
8455 Fortunately, there is a simple rule-of-thumb which can be
8456 used in such cases. When compiling for an i386/i486, GCC will allocate
8457 8 bytes for the structure shown above. It decides to do this based upon
8458 one simple rule for bit-field allocation. Quite simply, GCC allocates
8459 each "containing object" for each bit-field at the first (i.e. lowest
8460 addressed) legitimate alignment boundary (based upon the required
8461 minimum alignment for the declared type of the field) which it can
8462 possibly use, subject to the condition that there is still enough
8463 available space remaining in the containing object (when allocated at
8464 the selected point) to fully accommodate all of the bits of the
8465 bit-field itself. This simple rule makes it obvious why GCC allocates
8466 8 bytes for each object of the structure type shown above. When looking
8467 for a place to allocate the "containing object" for `field2', the
8468 compiler simply tries to allocate a 64-bit "containing object" at each
8469 successive 32-bit boundary (starting at zero) until it finds a place to
8470 allocate that 64- bit field such that at least 31 contiguous (and
8471 previously unallocated) bits remain within that selected 64 bit field.
8472 (As it turns out, for the example above, the compiler finds that it is
8473 OK to allocate the "containing object" 64-bit field at bit-offset zero
8474 within the structure type.) Here we attempt to work backwards from the
8475 limited set of facts we're given, and we try to deduce from those facts,
8476 where GCC must have believed that the containing object started (within
8477 the structure type). The value we deduce is then used (by the callers of
8478 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8479 for fields (both bit-fields and, in the case of DW_AT_location, regular
8482 /* Figure out the bit-distance from the start of the structure to the
8483 "deepest" bit of the bit-field. */
8484 deepest_bitpos = bitpos_int + field_size_in_bits;
8486 /* This is the tricky part. Use some fancy footwork to deduce where the
8487 lowest addressed bit of the containing object must be. */
8488 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8490 /* Round up to type_align by default. This works best for bitfields. */
8491 object_offset_in_bits += type_align_in_bits - 1;
8492 object_offset_in_bits /= type_align_in_bits;
8493 object_offset_in_bits *= type_align_in_bits;
8495 if (object_offset_in_bits > bitpos_int)
8497 /* Sigh, the decl must be packed. */
8498 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8500 /* Round up to decl_align instead. */
8501 object_offset_in_bits += decl_align_in_bits - 1;
8502 object_offset_in_bits /= decl_align_in_bits;
8503 object_offset_in_bits *= decl_align_in_bits;
8506 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8508 return object_offset_in_bytes;
8511 /* The following routines define various Dwarf attributes and any data
8512 associated with them. */
8514 /* Add a location description attribute value to a DIE.
8516 This emits location attributes suitable for whole variables and
8517 whole parameters. Note that the location attributes for struct fields are
8518 generated by the routine `data_member_location_attribute' below. */
8521 add_AT_location_description (die, attr_kind, rtl)
8523 enum dwarf_attribute attr_kind;
8526 /* Handle a special case. If we are about to output a location descriptor
8527 for a variable or parameter which has been optimized out of existence,
8528 don't do that. A variable which has been optimized out
8529 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8530 Currently, in some rare cases, variables can have DECL_RTL values which
8531 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8532 elsewhere in the compiler. We treat such cases as if the variable(s) in
8533 question had been optimized out of existence. */
8535 if (is_pseudo_reg (rtl)
8536 || (GET_CODE (rtl) == MEM
8537 && is_pseudo_reg (XEXP (rtl, 0)))
8538 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8539 references the internal argument pointer (a pseudo) in a function
8540 where all references to the internal argument pointer were
8541 eliminated via the optimizers. */
8542 || (GET_CODE (rtl) == MEM
8543 && GET_CODE (XEXP (rtl, 0)) == PLUS
8544 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8545 || (GET_CODE (rtl) == CONCAT
8546 && is_pseudo_reg (XEXP (rtl, 0))
8547 && is_pseudo_reg (XEXP (rtl, 1))))
8550 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8553 /* Attach the specialized form of location attribute used for data
8554 members of struct and union types. In the special case of a
8555 FIELD_DECL node which represents a bit-field, the "offset" part
8556 of this special location descriptor must indicate the distance
8557 in bytes from the lowest-addressed byte of the containing struct
8558 or union type to the lowest-addressed byte of the "containing
8559 object" for the bit-field. (See the `field_byte_offset' function
8560 above).. For any given bit-field, the "containing object" is a
8561 hypothetical object (of some integral or enum type) within which
8562 the given bit-field lives. The type of this hypothetical
8563 "containing object" is always the same as the declared type of
8564 the individual bit-field itself (for GCC anyway... the DWARF
8565 spec doesn't actually mandate this). Note that it is the size
8566 (in bytes) of the hypothetical "containing object" which will
8567 be given in the DW_AT_byte_size attribute for this bit-field.
8568 (See the `byte_size_attribute' function below.) It is also used
8569 when calculating the value of the DW_AT_bit_offset attribute.
8570 (See the `bit_offset_attribute' function below). */
8573 add_data_member_location_attribute (die, decl)
8574 register dw_die_ref die;
8577 register unsigned long offset;
8578 register dw_loc_descr_ref loc_descr;
8579 register enum dwarf_location_atom op;
8581 if (TREE_CODE (decl) == TREE_VEC)
8582 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8584 offset = field_byte_offset (decl);
8586 /* The DWARF2 standard says that we should assume that the structure address
8587 is already on the stack, so we can specify a structure field address
8588 by using DW_OP_plus_uconst. */
8590 #ifdef MIPS_DEBUGGING_INFO
8591 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8592 correctly. It works only if we leave the offset on the stack. */
8595 op = DW_OP_plus_uconst;
8598 loc_descr = new_loc_descr (op, offset, 0);
8599 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8602 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8603 does not have a "location" either in memory or in a register. These
8604 things can arise in GNU C when a constant is passed as an actual parameter
8605 to an inlined function. They can also arise in C++ where declared
8606 constants do not necessarily get memory "homes". */
8609 add_const_value_attribute (die, rtl)
8610 register dw_die_ref die;
8613 switch (GET_CODE (rtl))
8616 /* Note that a CONST_INT rtx could represent either an integer or a
8617 floating-point constant. A CONST_INT is used whenever the constant
8618 will fit into a single word. In all such cases, the original mode
8619 of the constant value is wiped out, and the CONST_INT rtx is
8620 assigned VOIDmode. */
8621 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
8625 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8626 floating-point constant. A CONST_DOUBLE is used whenever the
8627 constant requires more than one word in order to be adequately
8628 represented. We output CONST_DOUBLEs as blocks. */
8630 register enum machine_mode mode = GET_MODE (rtl);
8632 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8634 register unsigned length = GET_MODE_SIZE (mode) / 4;
8635 long *array = (long *) xmalloc (sizeof (long) * length);
8638 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8642 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8646 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8651 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8658 add_AT_float (die, DW_AT_const_value, length, array);
8661 add_AT_long_long (die, DW_AT_const_value,
8662 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8667 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8673 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8677 /* In cases where an inlined instance of an inline function is passed
8678 the address of an `auto' variable (which is local to the caller) we
8679 can get a situation where the DECL_RTL of the artificial local
8680 variable (for the inlining) which acts as a stand-in for the
8681 corresponding formal parameter (of the inline function) will look
8682 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8683 exactly a compile-time constant expression, but it isn't the address
8684 of the (artificial) local variable either. Rather, it represents the
8685 *value* which the artificial local variable always has during its
8686 lifetime. We currently have no way to represent such quasi-constant
8687 values in Dwarf, so for now we just punt and generate nothing. */
8691 /* No other kinds of rtx should be possible here. */
8698 rtl_for_decl_location (decl)
8703 /* Here we have to decide where we are going to say the parameter "lives"
8704 (as far as the debugger is concerned). We only have a couple of
8705 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8707 DECL_RTL normally indicates where the parameter lives during most of the
8708 activation of the function. If optimization is enabled however, this
8709 could be either NULL or else a pseudo-reg. Both of those cases indicate
8710 that the parameter doesn't really live anywhere (as far as the code
8711 generation parts of GCC are concerned) during most of the function's
8712 activation. That will happen (for example) if the parameter is never
8713 referenced within the function.
8715 We could just generate a location descriptor here for all non-NULL
8716 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8717 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8718 where DECL_RTL is NULL or is a pseudo-reg.
8720 Note however that we can only get away with using DECL_INCOMING_RTL as
8721 a backup substitute for DECL_RTL in certain limited cases. In cases
8722 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8723 we can be sure that the parameter was passed using the same type as it is
8724 declared to have within the function, and that its DECL_INCOMING_RTL
8725 points us to a place where a value of that type is passed.
8727 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8728 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8729 because in these cases DECL_INCOMING_RTL points us to a value of some
8730 type which is *different* from the type of the parameter itself. Thus,
8731 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8732 such cases, the debugger would end up (for example) trying to fetch a
8733 `float' from a place which actually contains the first part of a
8734 `double'. That would lead to really incorrect and confusing
8735 output at debug-time.
8737 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8738 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8739 are a couple of exceptions however. On little-endian machines we can
8740 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8741 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8742 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8743 when (on a little-endian machine) a non-prototyped function has a
8744 parameter declared to be of type `short' or `char'. In such cases,
8745 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8746 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8747 passed `int' value. If the debugger then uses that address to fetch
8748 a `short' or a `char' (on a little-endian machine) the result will be
8749 the correct data, so we allow for such exceptional cases below.
8751 Note that our goal here is to describe the place where the given formal
8752 parameter lives during most of the function's activation (i.e. between
8753 the end of the prologue and the start of the epilogue). We'll do that
8754 as best as we can. Note however that if the given formal parameter is
8755 modified sometime during the execution of the function, then a stack
8756 backtrace (at debug-time) will show the function as having been
8757 called with the *new* value rather than the value which was
8758 originally passed in. This happens rarely enough that it is not
8759 a major problem, but it *is* a problem, and I'd like to fix it.
8761 A future version of dwarf2out.c may generate two additional
8762 attributes for any given DW_TAG_formal_parameter DIE which will
8763 describe the "passed type" and the "passed location" for the
8764 given formal parameter in addition to the attributes we now
8765 generate to indicate the "declared type" and the "active
8766 location" for each parameter. This additional set of attributes
8767 could be used by debuggers for stack backtraces. Separately, note
8768 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8769 NULL also. This happens (for example) for inlined-instances of
8770 inline function formal parameters which are never referenced.
8771 This really shouldn't be happening. All PARM_DECL nodes should
8772 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8773 doesn't currently generate these values for inlined instances of
8774 inline function parameters, so when we see such cases, we are
8775 just out-of-luck for the time being (until integrate.c
8778 /* Use DECL_RTL as the "location" unless we find something better. */
8779 rtl = DECL_RTL (decl);
8781 if (TREE_CODE (decl) == PARM_DECL)
8783 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8785 tree declared_type = type_main_variant (TREE_TYPE (decl));
8786 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8788 /* This decl represents a formal parameter which was optimized out.
8789 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8790 all* cases where (rtl == NULL_RTX) just below. */
8791 if (declared_type == passed_type)
8792 rtl = DECL_INCOMING_RTL (decl);
8793 else if (! BYTES_BIG_ENDIAN
8794 && TREE_CODE (declared_type) == INTEGER_TYPE
8795 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8796 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8797 rtl = DECL_INCOMING_RTL (decl);
8800 /* If the parm was passed in registers, but lives on the stack, then
8801 make a big endian correction if the mode of the type of the
8802 parameter is not the same as the mode of the rtl. */
8803 /* ??? This is the same series of checks that are made in dbxout.c before
8804 we reach the big endian correction code there. It isn't clear if all
8805 of these checks are necessary here, but keeping them all is the safe
8807 else if (GET_CODE (rtl) == MEM
8808 && XEXP (rtl, 0) != const0_rtx
8809 && ! CONSTANT_P (XEXP (rtl, 0))
8810 /* Not passed in memory. */
8811 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8812 /* Not passed by invisible reference. */
8813 && (GET_CODE (XEXP (rtl, 0)) != REG
8814 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8815 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8816 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8817 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8820 /* Big endian correction check. */
8822 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8823 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8826 int offset = (UNITS_PER_WORD
8827 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8828 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8829 plus_constant (XEXP (rtl, 0), offset));
8833 if (rtl != NULL_RTX)
8835 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8836 #ifdef LEAF_REG_REMAP
8837 if (current_function_uses_only_leaf_regs)
8838 leaf_renumber_regs_insn (rtl);
8845 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8846 data attribute for a variable or a parameter. We generate the
8847 DW_AT_const_value attribute only in those cases where the given variable
8848 or parameter does not have a true "location" either in memory or in a
8849 register. This can happen (for example) when a constant is passed as an
8850 actual argument in a call to an inline function. (It's possible that
8851 these things can crop up in other ways also.) Note that one type of
8852 constant value which can be passed into an inlined function is a constant
8853 pointer. This can happen for example if an actual argument in an inlined
8854 function call evaluates to a compile-time constant address. */
8857 add_location_or_const_value_attribute (die, decl)
8858 register dw_die_ref die;
8863 if (TREE_CODE (decl) == ERROR_MARK)
8866 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8869 rtl = rtl_for_decl_location (decl);
8870 if (rtl == NULL_RTX)
8873 switch (GET_CODE (rtl))
8876 /* The address of a variable that was optimized away; don't emit
8887 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8888 add_const_value_attribute (die, rtl);
8895 add_AT_location_description (die, DW_AT_location, rtl);
8903 /* If we don't have a copy of this variable in memory for some reason (such
8904 as a C++ member constant that doesn't have an out-of-line definition),
8905 we should tell the debugger about the constant value. */
8908 tree_add_const_value_attribute (var_die, decl)
8912 tree init = DECL_INITIAL (decl);
8913 tree type = TREE_TYPE (decl);
8915 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8916 && initializer_constant_valid_p (init, type) == null_pointer_node)
8921 switch (TREE_CODE (type))
8924 if (host_integerp (init, 0))
8925 add_AT_unsigned (var_die, DW_AT_const_value,
8926 TREE_INT_CST_LOW (init));
8928 add_AT_long_long (var_die, DW_AT_const_value,
8929 TREE_INT_CST_HIGH (init),
8930 TREE_INT_CST_LOW (init));
8937 /* Generate an DW_AT_name attribute given some string value to be included as
8938 the value of the attribute. */
8941 add_name_attribute (die, name_string)
8942 register dw_die_ref die;
8943 register const char *name_string;
8945 if (name_string != NULL && *name_string != 0)
8947 if (demangle_name_func)
8948 name_string = (*demangle_name_func) (name_string);
8950 add_AT_string (die, DW_AT_name, name_string);
8954 /* Given a tree node describing an array bound (either lower or upper) output
8955 a representation for that bound. */
8958 add_bound_info (subrange_die, bound_attr, bound)
8959 register dw_die_ref subrange_die;
8960 register enum dwarf_attribute bound_attr;
8961 register tree bound;
8963 /* If this is an Ada unconstrained array type, then don't emit any debug
8964 info because the array bounds are unknown. They are parameterized when
8965 the type is instantiated. */
8966 if (contains_placeholder_p (bound))
8969 switch (TREE_CODE (bound))
8974 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8976 if (! host_integerp (bound, 0)
8977 || (bound_attr == DW_AT_lower_bound
8978 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8979 || (is_fortran () && integer_onep (bound)))))
8980 /* use the default */
8983 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8988 case NON_LVALUE_EXPR:
8989 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8993 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8994 access the upper bound values may be bogus. If they refer to a
8995 register, they may only describe how to get at these values at the
8996 points in the generated code right after they have just been
8997 computed. Worse yet, in the typical case, the upper bound values
8998 will not even *be* computed in the optimized code (though the
8999 number of elements will), so these SAVE_EXPRs are entirely
9000 bogus. In order to compensate for this fact, we check here to see
9001 if optimization is enabled, and if so, we don't add an attribute
9002 for the (unknown and unknowable) upper bound. This should not
9003 cause too much trouble for existing (stupid?) debuggers because
9004 they have to deal with empty upper bounds location descriptions
9005 anyway in order to be able to deal with incomplete array types.
9006 Of course an intelligent debugger (GDB?) should be able to
9007 comprehend that a missing upper bound specification in a array
9008 type used for a storage class `auto' local array variable
9009 indicates that the upper bound is both unknown (at compile- time)
9010 and unknowable (at run-time) due to optimization.
9012 We assume that a MEM rtx is safe because gcc wouldn't put the
9013 value there unless it was going to be used repeatedly in the
9014 function, i.e. for cleanups. */
9015 if (! optimize || (SAVE_EXPR_RTL (bound)
9016 && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
9018 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
9019 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
9020 register rtx loc = SAVE_EXPR_RTL (bound);
9022 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9023 it references an outer function's frame. */
9025 if (GET_CODE (loc) == MEM)
9027 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9029 if (XEXP (loc, 0) != new_addr)
9030 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9033 add_AT_flag (decl_die, DW_AT_artificial, 1);
9034 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9035 add_AT_location_description (decl_die, DW_AT_location, loc);
9036 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9039 /* Else leave out the attribute. */
9045 dw_die_ref decl_die = lookup_decl_die (bound);
9047 /* ??? Can this happen, or should the variable have been bound
9048 first? Probably it can, since I imagine that we try to create
9049 the types of parameters in the order in which they exist in
9050 the list, and won't have created a forward reference to a
9052 if (decl_die != NULL)
9053 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9059 /* Otherwise try to create a stack operation procedure to
9060 evaluate the value of the array bound. */
9062 dw_die_ref ctx, decl_die;
9063 dw_loc_descr_ref loc;
9065 loc = loc_descriptor_from_tree (bound, 0);
9069 ctx = lookup_decl_die (current_function_decl);
9071 decl_die = new_die (DW_TAG_variable, ctx);
9072 add_AT_flag (decl_die, DW_AT_artificial, 1);
9073 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9074 add_AT_loc (decl_die, DW_AT_location, loc);
9076 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9082 /* Note that the block of subscript information for an array type also
9083 includes information about the element type of type given array type. */
9086 add_subscript_info (type_die, type)
9087 register dw_die_ref type_die;
9090 #ifndef MIPS_DEBUGGING_INFO
9091 register unsigned dimension_number;
9093 register tree lower, upper;
9094 register dw_die_ref subrange_die;
9096 /* The GNU compilers represent multidimensional array types as sequences of
9097 one dimensional array types whose element types are themselves array
9098 types. Here we squish that down, so that each multidimensional array
9099 type gets only one array_type DIE in the Dwarf debugging info. The draft
9100 Dwarf specification say that we are allowed to do this kind of
9101 compression in C (because there is no difference between an array or
9102 arrays and a multidimensional array in C) but for other source languages
9103 (e.g. Ada) we probably shouldn't do this. */
9105 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9106 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9107 We work around this by disabling this feature. See also
9108 gen_array_type_die. */
9109 #ifndef MIPS_DEBUGGING_INFO
9110 for (dimension_number = 0;
9111 TREE_CODE (type) == ARRAY_TYPE;
9112 type = TREE_TYPE (type), dimension_number++)
9115 register tree domain = TYPE_DOMAIN (type);
9117 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9118 and (in GNU C only) variable bounds. Handle all three forms
9120 subrange_die = new_die (DW_TAG_subrange_type, type_die);
9123 /* We have an array type with specified bounds. */
9124 lower = TYPE_MIN_VALUE (domain);
9125 upper = TYPE_MAX_VALUE (domain);
9127 /* define the index type. */
9128 if (TREE_TYPE (domain))
9130 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9131 TREE_TYPE field. We can't emit debug info for this
9132 because it is an unnamed integral type. */
9133 if (TREE_CODE (domain) == INTEGER_TYPE
9134 && TYPE_NAME (domain) == NULL_TREE
9135 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9136 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9139 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9143 /* ??? If upper is NULL, the array has unspecified length,
9144 but it does have a lower bound. This happens with Fortran
9146 Since the debugger is definitely going to need to know N
9147 to produce useful results, go ahead and output the lower
9148 bound solo, and hope the debugger can cope. */
9150 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9152 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9155 /* We have an array type with an unspecified length. The DWARF-2
9156 spec does not say how to handle this; let's just leave out the
9160 #ifndef MIPS_DEBUGGING_INFO
9166 add_byte_size_attribute (die, tree_node)
9168 register tree tree_node;
9170 register unsigned size;
9172 switch (TREE_CODE (tree_node))
9180 case QUAL_UNION_TYPE:
9181 size = int_size_in_bytes (tree_node);
9184 /* For a data member of a struct or union, the DW_AT_byte_size is
9185 generally given as the number of bytes normally allocated for an
9186 object of the *declared* type of the member itself. This is true
9187 even for bit-fields. */
9188 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9194 /* Note that `size' might be -1 when we get to this point. If it is, that
9195 indicates that the byte size of the entity in question is variable. We
9196 have no good way of expressing this fact in Dwarf at the present time,
9197 so just let the -1 pass on through. */
9199 add_AT_unsigned (die, DW_AT_byte_size, size);
9202 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9203 which specifies the distance in bits from the highest order bit of the
9204 "containing object" for the bit-field to the highest order bit of the
9207 For any given bit-field, the "containing object" is a hypothetical
9208 object (of some integral or enum type) within which the given bit-field
9209 lives. The type of this hypothetical "containing object" is always the
9210 same as the declared type of the individual bit-field itself. The
9211 determination of the exact location of the "containing object" for a
9212 bit-field is rather complicated. It's handled by the
9213 `field_byte_offset' function (above).
9215 Note that it is the size (in bytes) of the hypothetical "containing object"
9216 which will be given in the DW_AT_byte_size attribute for this bit-field.
9217 (See `byte_size_attribute' above). */
9220 add_bit_offset_attribute (die, decl)
9221 register dw_die_ref die;
9224 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9225 tree type = DECL_BIT_FIELD_TYPE (decl);
9226 HOST_WIDE_INT bitpos_int;
9227 HOST_WIDE_INT highest_order_object_bit_offset;
9228 HOST_WIDE_INT highest_order_field_bit_offset;
9229 HOST_WIDE_INT unsigned bit_offset;
9231 /* Must be a field and a bit field. */
9233 || TREE_CODE (decl) != FIELD_DECL)
9236 /* We can't yet handle bit-fields whose offsets are variable, so if we
9237 encounter such things, just return without generating any attribute
9238 whatsoever. Likewise for variable or too large size. */
9239 if (! host_integerp (bit_position (decl), 0)
9240 || ! host_integerp (DECL_SIZE (decl), 1))
9243 bitpos_int = int_bit_position (decl);
9245 /* Note that the bit offset is always the distance (in bits) from the
9246 highest-order bit of the "containing object" to the highest-order bit of
9247 the bit-field itself. Since the "high-order end" of any object or field
9248 is different on big-endian and little-endian machines, the computation
9249 below must take account of these differences. */
9250 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9251 highest_order_field_bit_offset = bitpos_int;
9253 if (! BYTES_BIG_ENDIAN)
9255 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9256 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9260 = (! BYTES_BIG_ENDIAN
9261 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9262 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9264 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9267 /* For a FIELD_DECL node which represents a bit field, output an attribute
9268 which specifies the length in bits of the given field. */
9271 add_bit_size_attribute (die, decl)
9272 register dw_die_ref die;
9275 /* Must be a field and a bit field. */
9276 if (TREE_CODE (decl) != FIELD_DECL
9277 || ! DECL_BIT_FIELD_TYPE (decl))
9280 if (host_integerp (DECL_SIZE (decl), 1))
9281 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9284 /* If the compiled language is ANSI C, then add a 'prototyped'
9285 attribute, if arg types are given for the parameters of a function. */
9288 add_prototyped_attribute (die, func_type)
9289 register dw_die_ref die;
9290 register tree func_type;
9292 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9293 && TYPE_ARG_TYPES (func_type) != NULL)
9294 add_AT_flag (die, DW_AT_prototyped, 1);
9297 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9298 by looking in either the type declaration or object declaration
9302 add_abstract_origin_attribute (die, origin)
9303 register dw_die_ref die;
9304 register tree origin;
9306 dw_die_ref origin_die = NULL;
9308 if (TREE_CODE (origin) != FUNCTION_DECL)
9310 /* We may have gotten separated from the block for the inlined
9311 function, if we're in an exception handler or some such; make
9312 sure that the abstract function has been written out.
9314 Doing this for nested functions is wrong, however; functions are
9315 distinct units, and our context might not even be inline. */
9318 fn = TYPE_STUB_DECL (fn);
9319 fn = decl_function_context (fn);
9321 gen_abstract_function (fn);
9324 if (DECL_P (origin))
9325 origin_die = lookup_decl_die (origin);
9326 else if (TYPE_P (origin))
9327 origin_die = lookup_type_die (origin);
9329 if (origin_die == NULL)
9332 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9335 /* We do not currently support the pure_virtual attribute. */
9338 add_pure_or_virtual_attribute (die, func_decl)
9339 register dw_die_ref die;
9340 register tree func_decl;
9342 if (DECL_VINDEX (func_decl))
9344 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9346 if (host_integerp (DECL_VINDEX (func_decl), 0))
9347 add_AT_loc (die, DW_AT_vtable_elem_location,
9348 new_loc_descr (DW_OP_constu,
9349 tree_low_cst (DECL_VINDEX (func_decl), 0),
9352 /* GNU extension: Record what type this method came from originally. */
9353 if (debug_info_level > DINFO_LEVEL_TERSE)
9354 add_AT_die_ref (die, DW_AT_containing_type,
9355 lookup_type_die (DECL_CONTEXT (func_decl)));
9359 /* Add source coordinate attributes for the given decl. */
9362 add_src_coords_attributes (die, decl)
9363 register dw_die_ref die;
9366 register unsigned file_index = lookup_filename (&decl_file_table,
9367 DECL_SOURCE_FILE (decl));
9369 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9370 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9373 /* Add an DW_AT_name attribute and source coordinate attribute for the
9374 given decl, but only if it actually has a name. */
9377 add_name_and_src_coords_attributes (die, decl)
9378 register dw_die_ref die;
9381 register tree decl_name;
9383 decl_name = DECL_NAME (decl);
9384 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9386 add_name_attribute (die, dwarf2_name (decl, 0));
9387 if (! DECL_ARTIFICIAL (decl))
9388 add_src_coords_attributes (die, decl);
9390 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9391 && TREE_PUBLIC (decl)
9392 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
9393 add_AT_string (die, DW_AT_MIPS_linkage_name,
9394 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9398 /* Push a new declaration scope. */
9401 push_decl_scope (scope)
9404 /* Make room in the decl_scope_table, if necessary. */
9405 if (decl_scope_table_allocated == decl_scope_depth)
9407 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
9409 = (tree *) xrealloc (decl_scope_table,
9410 decl_scope_table_allocated * sizeof (tree));
9413 decl_scope_table[decl_scope_depth] = scope;
9417 /* Pop a declaration scope. */
9421 if (decl_scope_depth <= 0)
9426 /* Return the DIE for the scope that immediately contains this type.
9427 Non-named types get global scope. Named types nested in other
9428 types get their containing scope if it's open, or global scope
9429 otherwise. All other types (i.e. function-local named types) get
9430 the current active scope. */
9433 scope_die_for (t, context_die)
9435 register dw_die_ref context_die;
9437 register dw_die_ref scope_die = NULL;
9438 register tree containing_scope;
9441 /* Non-types always go in the current scope. */
9445 containing_scope = TYPE_CONTEXT (t);
9447 /* Ignore namespaces for the moment. */
9448 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9449 containing_scope = NULL_TREE;
9451 /* Ignore function type "scopes" from the C frontend. They mean that
9452 a tagged type is local to a parmlist of a function declarator, but
9453 that isn't useful to DWARF. */
9454 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9455 containing_scope = NULL_TREE;
9457 if (containing_scope == NULL_TREE)
9458 scope_die = comp_unit_die;
9459 else if (TYPE_P (containing_scope))
9461 /* For types, we can just look up the appropriate DIE. But
9462 first we check to see if we're in the middle of emitting it
9463 so we know where the new DIE should go. */
9465 for (i = decl_scope_depth - 1; i >= 0; --i)
9466 if (decl_scope_table[i] == containing_scope)
9471 if (debug_info_level > DINFO_LEVEL_TERSE
9472 && !TREE_ASM_WRITTEN (containing_scope))
9475 /* If none of the current dies are suitable, we get file scope. */
9476 scope_die = comp_unit_die;
9479 scope_die = lookup_type_die (containing_scope);
9482 scope_die = context_die;
9487 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9489 static inline int local_scope_p PARAMS ((dw_die_ref));
9491 local_scope_p (context_die)
9492 dw_die_ref context_die;
9494 for (; context_die; context_die = context_die->die_parent)
9495 if (context_die->die_tag == DW_TAG_inlined_subroutine
9496 || context_die->die_tag == DW_TAG_subprogram)
9501 /* Returns nonzero iff CONTEXT_DIE is a class. */
9503 static inline int class_scope_p PARAMS ((dw_die_ref));
9505 class_scope_p (context_die)
9506 dw_die_ref context_die;
9509 && (context_die->die_tag == DW_TAG_structure_type
9510 || context_die->die_tag == DW_TAG_union_type));
9513 /* Many forms of DIEs require a "type description" attribute. This
9514 routine locates the proper "type descriptor" die for the type given
9515 by 'type', and adds an DW_AT_type attribute below the given die. */
9518 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9519 register dw_die_ref object_die;
9521 register int decl_const;
9522 register int decl_volatile;
9523 register dw_die_ref context_die;
9525 register enum tree_code code = TREE_CODE (type);
9526 register dw_die_ref type_die = NULL;
9528 /* ??? If this type is an unnamed subrange type of an integral or
9529 floating-point type, use the inner type. This is because we have no
9530 support for unnamed types in base_type_die. This can happen if this is
9531 an Ada subrange type. Correct solution is emit a subrange type die. */
9532 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9533 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9534 type = TREE_TYPE (type), code = TREE_CODE (type);
9536 if (code == ERROR_MARK)
9539 /* Handle a special case. For functions whose return type is void, we
9540 generate *no* type attribute. (Note that no object may have type
9541 `void', so this only applies to function return types). */
9542 if (code == VOID_TYPE)
9545 type_die = modified_type_die (type,
9546 decl_const || TYPE_READONLY (type),
9547 decl_volatile || TYPE_VOLATILE (type),
9549 if (type_die != NULL)
9550 add_AT_die_ref (object_die, DW_AT_type, type_die);
9553 /* Given a tree pointer to a struct, class, union, or enum type node, return
9554 a pointer to the (string) tag name for the given type, or zero if the type
9555 was declared without a tag. */
9561 register const char *name = 0;
9563 if (TYPE_NAME (type) != 0)
9565 register tree t = 0;
9567 /* Find the IDENTIFIER_NODE for the type name. */
9568 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9569 t = TYPE_NAME (type);
9571 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9572 a TYPE_DECL node, regardless of whether or not a `typedef' was
9574 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9575 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9576 t = DECL_NAME (TYPE_NAME (type));
9578 /* Now get the name as a string, or invent one. */
9580 name = IDENTIFIER_POINTER (t);
9583 return (name == 0 || *name == '\0') ? 0 : name;
9586 /* Return the type associated with a data member, make a special check
9587 for bit field types. */
9590 member_declared_type (member)
9591 register tree member;
9593 return (DECL_BIT_FIELD_TYPE (member)
9594 ? DECL_BIT_FIELD_TYPE (member)
9595 : TREE_TYPE (member));
9598 /* Get the decl's label, as described by its RTL. This may be different
9599 from the DECL_NAME name used in the source file. */
9603 decl_start_label (decl)
9608 x = DECL_RTL (decl);
9609 if (GET_CODE (x) != MEM)
9613 if (GET_CODE (x) != SYMBOL_REF)
9616 fnname = XSTR (x, 0);
9621 /* These routines generate the internal representation of the DIE's for
9622 the compilation unit. Debugging information is collected by walking
9623 the declaration trees passed in from dwarf2out_decl(). */
9626 gen_array_type_die (type, context_die)
9628 register dw_die_ref context_die;
9630 register dw_die_ref scope_die = scope_die_for (type, context_die);
9631 register dw_die_ref array_die;
9632 register tree element_type;
9634 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9635 the inner array type comes before the outer array type. Thus we must
9636 call gen_type_die before we call new_die. See below also. */
9637 #ifdef MIPS_DEBUGGING_INFO
9638 gen_type_die (TREE_TYPE (type), context_die);
9641 array_die = new_die (DW_TAG_array_type, scope_die);
9644 /* We default the array ordering. SDB will probably do
9645 the right things even if DW_AT_ordering is not present. It's not even
9646 an issue until we start to get into multidimensional arrays anyway. If
9647 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9648 then we'll have to put the DW_AT_ordering attribute back in. (But if
9649 and when we find out that we need to put these in, we will only do so
9650 for multidimensional arrays. */
9651 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9654 #ifdef MIPS_DEBUGGING_INFO
9655 /* The SGI compilers handle arrays of unknown bound by setting
9656 AT_declaration and not emitting any subrange DIEs. */
9657 if (! TYPE_DOMAIN (type))
9658 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9661 add_subscript_info (array_die, type);
9663 add_name_attribute (array_die, type_tag (type));
9664 equate_type_number_to_die (type, array_die);
9666 /* Add representation of the type of the elements of this array type. */
9667 element_type = TREE_TYPE (type);
9669 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9670 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9671 We work around this by disabling this feature. See also
9672 add_subscript_info. */
9673 #ifndef MIPS_DEBUGGING_INFO
9674 while (TREE_CODE (element_type) == ARRAY_TYPE)
9675 element_type = TREE_TYPE (element_type);
9677 gen_type_die (element_type, context_die);
9680 add_type_attribute (array_die, element_type, 0, 0, context_die);
9684 gen_set_type_die (type, context_die)
9686 register dw_die_ref context_die;
9688 register dw_die_ref type_die
9689 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9691 equate_type_number_to_die (type, type_die);
9692 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9697 gen_entry_point_die (decl, context_die)
9699 register dw_die_ref context_die;
9701 register tree origin = decl_ultimate_origin (decl);
9702 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9704 add_abstract_origin_attribute (decl_die, origin);
9707 add_name_and_src_coords_attributes (decl_die, decl);
9708 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9712 if (DECL_ABSTRACT (decl))
9713 equate_decl_number_to_die (decl, decl_die);
9715 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9719 /* Remember a type in the incomplete_types_list. */
9722 add_incomplete_type (type)
9725 if (incomplete_types == incomplete_types_allocated)
9727 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9728 incomplete_types_list
9729 = (tree *) xrealloc (incomplete_types_list,
9730 sizeof (tree) * incomplete_types_allocated);
9733 incomplete_types_list[incomplete_types++] = type;
9736 /* Walk through the list of incomplete types again, trying once more to
9737 emit full debugging info for them. */
9740 retry_incomplete_types ()
9744 while (incomplete_types)
9747 type = incomplete_types_list[incomplete_types];
9748 gen_type_die (type, comp_unit_die);
9752 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9755 gen_inlined_enumeration_type_die (type, context_die)
9757 register dw_die_ref context_die;
9759 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9761 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9762 be incomplete and such types are not marked. */
9763 add_abstract_origin_attribute (type_die, type);
9766 /* Generate a DIE to represent an inlined instance of a structure type. */
9769 gen_inlined_structure_type_die (type, context_die)
9771 register dw_die_ref context_die;
9773 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9775 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9776 be incomplete and such types are not marked. */
9777 add_abstract_origin_attribute (type_die, type);
9780 /* Generate a DIE to represent an inlined instance of a union type. */
9783 gen_inlined_union_type_die (type, context_die)
9785 register dw_die_ref context_die;
9787 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9789 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9790 be incomplete and such types are not marked. */
9791 add_abstract_origin_attribute (type_die, type);
9794 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9795 include all of the information about the enumeration values also. Each
9796 enumerated type name/value is listed as a child of the enumerated type
9800 gen_enumeration_type_die (type, context_die)
9802 register dw_die_ref context_die;
9804 register dw_die_ref type_die = lookup_type_die (type);
9806 if (type_die == NULL)
9808 type_die = new_die (DW_TAG_enumeration_type,
9809 scope_die_for (type, context_die));
9810 equate_type_number_to_die (type, type_die);
9811 add_name_attribute (type_die, type_tag (type));
9813 else if (! TYPE_SIZE (type))
9816 remove_AT (type_die, DW_AT_declaration);
9818 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9819 given enum type is incomplete, do not generate the DW_AT_byte_size
9820 attribute or the DW_AT_element_list attribute. */
9821 if (TYPE_SIZE (type))
9825 TREE_ASM_WRITTEN (type) = 1;
9826 add_byte_size_attribute (type_die, type);
9827 if (TYPE_STUB_DECL (type) != NULL_TREE)
9828 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9830 /* If the first reference to this type was as the return type of an
9831 inline function, then it may not have a parent. Fix this now. */
9832 if (type_die->die_parent == NULL)
9833 add_child_die (scope_die_for (type, context_die), type_die);
9835 for (link = TYPE_FIELDS (type);
9836 link != NULL; link = TREE_CHAIN (link))
9838 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9840 add_name_attribute (enum_die,
9841 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9843 if (host_integerp (TREE_VALUE (link), 0))
9845 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9846 add_AT_int (enum_die, DW_AT_const_value,
9847 tree_low_cst (TREE_VALUE (link), 0));
9849 add_AT_unsigned (enum_die, DW_AT_const_value,
9850 tree_low_cst (TREE_VALUE (link), 0));
9855 add_AT_flag (type_die, DW_AT_declaration, 1);
9858 /* Generate a DIE to represent either a real live formal parameter decl or to
9859 represent just the type of some formal parameter position in some function
9862 Note that this routine is a bit unusual because its argument may be a
9863 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9864 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9865 node. If it's the former then this function is being called to output a
9866 DIE to represent a formal parameter object (or some inlining thereof). If
9867 it's the latter, then this function is only being called to output a
9868 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9869 argument type of some subprogram type. */
9872 gen_formal_parameter_die (node, context_die)
9874 register dw_die_ref context_die;
9876 register dw_die_ref parm_die
9877 = new_die (DW_TAG_formal_parameter, context_die);
9878 register tree origin;
9880 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9883 origin = decl_ultimate_origin (node);
9885 add_abstract_origin_attribute (parm_die, origin);
9888 add_name_and_src_coords_attributes (parm_die, node);
9889 add_type_attribute (parm_die, TREE_TYPE (node),
9890 TREE_READONLY (node),
9891 TREE_THIS_VOLATILE (node),
9893 if (DECL_ARTIFICIAL (node))
9894 add_AT_flag (parm_die, DW_AT_artificial, 1);
9897 equate_decl_number_to_die (node, parm_die);
9898 if (! DECL_ABSTRACT (node))
9899 add_location_or_const_value_attribute (parm_die, node);
9904 /* We were called with some kind of a ..._TYPE node. */
9905 add_type_attribute (parm_die, node, 0, 0, context_die);
9915 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9916 at the end of an (ANSI prototyped) formal parameters list. */
9919 gen_unspecified_parameters_die (decl_or_type, context_die)
9920 register tree decl_or_type ATTRIBUTE_UNUSED;
9921 register dw_die_ref context_die;
9923 new_die (DW_TAG_unspecified_parameters, context_die);
9926 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9927 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9928 parameters as specified in some function type specification (except for
9929 those which appear as part of a function *definition*). */
9932 gen_formal_types_die (function_or_method_type, context_die)
9933 register tree function_or_method_type;
9934 register dw_die_ref context_die;
9937 register tree formal_type = NULL;
9938 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9941 /* In the case where we are generating a formal types list for a C++
9942 non-static member function type, skip over the first thing on the
9943 TYPE_ARG_TYPES list because it only represents the type of the hidden
9944 `this pointer'. The debugger should be able to figure out (without
9945 being explicitly told) that this non-static member function type takes a
9946 `this pointer' and should be able to figure what the type of that hidden
9947 parameter is from the DW_AT_member attribute of the parent
9948 DW_TAG_subroutine_type DIE. */
9949 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
9950 first_parm_type = TREE_CHAIN (first_parm_type);
9953 /* Make our first pass over the list of formal parameter types and output a
9954 DW_TAG_formal_parameter DIE for each one. */
9955 for (link = first_parm_type; link; link = TREE_CHAIN (link))
9957 register dw_die_ref parm_die;
9959 formal_type = TREE_VALUE (link);
9960 if (formal_type == void_type_node)
9963 /* Output a (nameless) DIE to represent the formal parameter itself. */
9964 parm_die = gen_formal_parameter_die (formal_type, context_die);
9965 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
9966 && link == first_parm_type)
9967 add_AT_flag (parm_die, DW_AT_artificial, 1);
9970 /* If this function type has an ellipsis, add a
9971 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9972 if (formal_type != void_type_node)
9973 gen_unspecified_parameters_die (function_or_method_type, context_die);
9975 /* Make our second (and final) pass over the list of formal parameter types
9976 and output DIEs to represent those types (as necessary). */
9977 for (link = TYPE_ARG_TYPES (function_or_method_type);
9979 link = TREE_CHAIN (link))
9981 formal_type = TREE_VALUE (link);
9982 if (formal_type == void_type_node)
9985 gen_type_die (formal_type, context_die);
9989 /* We want to generate the DIE for TYPE so that we can generate the
9990 die for MEMBER, which has been defined; we will need to refer back
9991 to the member declaration nested within TYPE. If we're trying to
9992 generate minimal debug info for TYPE, processing TYPE won't do the
9993 trick; we need to attach the member declaration by hand. */
9996 gen_type_die_for_member (type, member, context_die)
9998 dw_die_ref context_die;
10000 gen_type_die (type, context_die);
10002 /* If we're trying to avoid duplicate debug info, we may not have
10003 emitted the member decl for this function. Emit it now. */
10004 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
10005 && ! lookup_decl_die (member))
10007 if (decl_ultimate_origin (member))
10010 push_decl_scope (type);
10011 if (TREE_CODE (member) == FUNCTION_DECL)
10012 gen_subprogram_die (member, lookup_type_die (type));
10014 gen_variable_die (member, lookup_type_die (type));
10019 /* Generate the DWARF2 info for the "abstract" instance
10020 of a function which we may later generate inlined and/or
10021 out-of-line instances of. */
10024 gen_abstract_function (decl)
10027 register dw_die_ref old_die = lookup_decl_die (decl);
10030 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10031 /* We've already generated the abstract instance. */
10034 save_fn = current_function_decl;
10035 current_function_decl = decl;
10037 set_decl_abstract_flags (decl, 1);
10038 dwarf2out_decl (decl);
10039 set_decl_abstract_flags (decl, 0);
10041 current_function_decl = save_fn;
10044 /* Generate a DIE to represent a declared function (either file-scope or
10048 gen_subprogram_die (decl, context_die)
10049 register tree decl;
10050 register dw_die_ref context_die;
10052 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10053 register tree origin = decl_ultimate_origin (decl);
10054 register dw_die_ref subr_die;
10055 register rtx fp_reg;
10056 register tree fn_arg_types;
10057 register tree outer_scope;
10058 register dw_die_ref old_die = lookup_decl_die (decl);
10059 register int declaration = (current_function_decl != decl
10060 || class_scope_p (context_die));
10062 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
10063 be true, if we started to generate the abstract instance of an inline,
10064 decided to output its containing class, and proceeded to emit the
10065 declaration of the inline from the member list for the class. In that
10066 case, `declaration' takes priority; we'll get back to the abstract
10067 instance when we're done with the class. */
10069 /* The class-scope declaration DIE must be the primary DIE. */
10070 if (origin && declaration && class_scope_p (context_die))
10077 if (origin != NULL)
10079 if (declaration && ! local_scope_p (context_die))
10082 /* Fixup die_parent for the abstract instance of a nested
10083 inline function. */
10084 if (old_die && old_die->die_parent == NULL)
10085 add_child_die (context_die, old_die);
10087 subr_die = new_die (DW_TAG_subprogram, context_die);
10088 add_abstract_origin_attribute (subr_die, origin);
10090 else if (old_die && DECL_ABSTRACT (decl)
10091 && get_AT_unsigned (old_die, DW_AT_inline))
10093 /* This must be a redefinition of an extern inline function.
10094 We can just reuse the old die here. */
10095 subr_die = old_die;
10097 /* Clear out the inlined attribute and parm types. */
10098 remove_AT (subr_die, DW_AT_inline);
10099 remove_children (subr_die);
10103 register unsigned file_index
10104 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
10106 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
10108 /* ??? This can happen if there is a bug in the program, for
10109 instance, if it has duplicate function definitions. Ideally,
10110 we should detect this case and ignore it. For now, if we have
10111 already reported an error, any error at all, then assume that
10112 we got here because of a input error, not a dwarf2 bug. */
10118 /* If the definition comes from the same place as the declaration,
10119 maybe use the old DIE. We always want the DIE for this function
10120 that has the *_pc attributes to be under comp_unit_die so the
10121 debugger can find it. We also need to do this for abstract
10122 instances of inlines, since the spec requires the out-of-line copy
10123 to have the same parent. For local class methods, this doesn't
10124 apply; we just use the old DIE. */
10125 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10126 && (DECL_ARTIFICIAL (decl)
10127 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10128 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10129 == (unsigned) DECL_SOURCE_LINE (decl)))))
10131 subr_die = old_die;
10133 /* Clear out the declaration attribute and the parm types. */
10134 remove_AT (subr_die, DW_AT_declaration);
10135 remove_children (subr_die);
10139 subr_die = new_die (DW_TAG_subprogram, context_die);
10140 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10141 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10142 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10143 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10144 != (unsigned) DECL_SOURCE_LINE (decl))
10146 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10151 subr_die = new_die (DW_TAG_subprogram, context_die);
10153 if (TREE_PUBLIC (decl))
10154 add_AT_flag (subr_die, DW_AT_external, 1);
10156 add_name_and_src_coords_attributes (subr_die, decl);
10157 if (debug_info_level > DINFO_LEVEL_TERSE)
10159 register tree type = TREE_TYPE (decl);
10161 add_prototyped_attribute (subr_die, type);
10162 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
10165 add_pure_or_virtual_attribute (subr_die, decl);
10166 if (DECL_ARTIFICIAL (decl))
10167 add_AT_flag (subr_die, DW_AT_artificial, 1);
10168 if (TREE_PROTECTED (decl))
10169 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10170 else if (TREE_PRIVATE (decl))
10171 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10177 add_AT_flag (subr_die, DW_AT_declaration, 1);
10179 /* The first time we see a member function, it is in the context of
10180 the class to which it belongs. We make sure of this by emitting
10181 the class first. The next time is the definition, which is
10182 handled above. The two may come from the same source text. */
10183 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10184 equate_decl_number_to_die (decl, subr_die);
10186 else if (DECL_ABSTRACT (decl))
10188 if (DECL_INLINE (decl) && !flag_no_inline)
10190 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10191 inline functions, but not for extern inline functions.
10192 We can't get this completely correct because information
10193 about whether the function was declared inline is not
10195 if (DECL_DEFER_OUTPUT (decl))
10196 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10198 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10201 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10203 equate_decl_number_to_die (decl, subr_die);
10205 else if (!DECL_EXTERNAL (decl))
10207 if (origin == NULL_TREE)
10208 equate_decl_number_to_die (decl, subr_die);
10210 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10211 current_funcdef_number);
10212 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10213 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10214 current_funcdef_number);
10215 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10217 add_pubname (decl, subr_die);
10218 add_arange (decl, subr_die);
10220 #ifdef MIPS_DEBUGGING_INFO
10221 /* Add a reference to the FDE for this routine. */
10222 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10225 /* Define the "frame base" location for this routine. We use the
10226 frame pointer or stack pointer registers, since the RTL for local
10227 variables is relative to one of them. */
10229 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10230 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10233 /* ??? This fails for nested inline functions, because context_display
10234 is not part of the state saved/restored for inline functions. */
10235 if (current_function_needs_context)
10236 add_AT_location_description (subr_die, DW_AT_static_link,
10237 lookup_static_chain (decl));
10241 /* Now output descriptions of the arguments for this function. This gets
10242 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10243 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10244 `...' at the end of the formal parameter list. In order to find out if
10245 there was a trailing ellipsis or not, we must instead look at the type
10246 associated with the FUNCTION_DECL. This will be a node of type
10247 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10248 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10249 an ellipsis at the end. */
10251 /* In the case where we are describing a mere function declaration, all we
10252 need to do here (and all we *can* do here) is to describe the *types* of
10253 its formal parameters. */
10254 if (debug_info_level <= DINFO_LEVEL_TERSE)
10256 else if (declaration)
10257 gen_formal_types_die (TREE_TYPE (decl), subr_die);
10260 /* Generate DIEs to represent all known formal parameters */
10261 register tree arg_decls = DECL_ARGUMENTS (decl);
10262 register tree parm;
10264 /* When generating DIEs, generate the unspecified_parameters DIE
10265 instead if we come across the arg "__builtin_va_alist" */
10266 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10267 if (TREE_CODE (parm) == PARM_DECL)
10269 if (DECL_NAME (parm)
10270 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10271 "__builtin_va_alist"))
10272 gen_unspecified_parameters_die (parm, subr_die);
10274 gen_decl_die (parm, subr_die);
10277 /* Decide whether we need a unspecified_parameters DIE at the end.
10278 There are 2 more cases to do this for: 1) the ansi ... declaration -
10279 this is detectable when the end of the arg list is not a
10280 void_type_node 2) an unprototyped function declaration (not a
10281 definition). This just means that we have no info about the
10282 parameters at all. */
10283 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10284 if (fn_arg_types != NULL)
10286 /* this is the prototyped case, check for ... */
10287 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10288 gen_unspecified_parameters_die (decl, subr_die);
10290 else if (DECL_INITIAL (decl) == NULL_TREE)
10291 gen_unspecified_parameters_die (decl, subr_die);
10294 /* Output Dwarf info for all of the stuff within the body of the function
10295 (if it has one - it may be just a declaration). */
10296 outer_scope = DECL_INITIAL (decl);
10298 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
10299 node created to represent a function. This outermost BLOCK actually
10300 represents the outermost binding contour for the function, i.e. the
10301 contour in which the function's formal parameters and labels get
10302 declared. Curiously, it appears that the front end doesn't actually
10303 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
10304 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
10305 list for the function instead.) The BLOCK_VARS list for the
10306 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
10307 the function however, and we output DWARF info for those in
10308 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
10309 node representing the function's outermost pair of curly braces, and
10310 any blocks used for the base and member initializers of a C++
10311 constructor function. */
10312 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10314 current_function_has_inlines = 0;
10315 decls_for_scope (outer_scope, subr_die, 0);
10317 #if 0 && defined (MIPS_DEBUGGING_INFO)
10318 if (current_function_has_inlines)
10320 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10321 if (! comp_unit_has_inlines)
10323 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10324 comp_unit_has_inlines = 1;
10331 /* Generate a DIE to represent a declared data object. */
10334 gen_variable_die (decl, context_die)
10335 register tree decl;
10336 register dw_die_ref context_die;
10338 register tree origin = decl_ultimate_origin (decl);
10339 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
10341 dw_die_ref old_die = lookup_decl_die (decl);
10342 int declaration = (DECL_EXTERNAL (decl)
10343 || class_scope_p (context_die));
10345 if (origin != NULL)
10346 add_abstract_origin_attribute (var_die, origin);
10347 /* Loop unrolling can create multiple blocks that refer to the same
10348 static variable, so we must test for the DW_AT_declaration flag. */
10349 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10350 copy decls and set the DECL_ABSTRACT flag on them instead of
10352 else if (old_die && TREE_STATIC (decl)
10353 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10355 /* This is a definition of a C++ class level static. */
10356 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10357 if (DECL_NAME (decl))
10359 register unsigned file_index
10360 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
10362 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10363 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10365 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10366 != (unsigned) DECL_SOURCE_LINE (decl))
10368 add_AT_unsigned (var_die, DW_AT_decl_line,
10369 DECL_SOURCE_LINE (decl));
10374 add_name_and_src_coords_attributes (var_die, decl);
10375 add_type_attribute (var_die, TREE_TYPE (decl),
10376 TREE_READONLY (decl),
10377 TREE_THIS_VOLATILE (decl), context_die);
10379 if (TREE_PUBLIC (decl))
10380 add_AT_flag (var_die, DW_AT_external, 1);
10382 if (DECL_ARTIFICIAL (decl))
10383 add_AT_flag (var_die, DW_AT_artificial, 1);
10385 if (TREE_PROTECTED (decl))
10386 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10388 else if (TREE_PRIVATE (decl))
10389 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10393 add_AT_flag (var_die, DW_AT_declaration, 1);
10395 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10396 equate_decl_number_to_die (decl, var_die);
10398 if (! declaration && ! DECL_ABSTRACT (decl))
10400 add_location_or_const_value_attribute (var_die, decl);
10401 add_pubname (decl, var_die);
10404 tree_add_const_value_attribute (var_die, decl);
10407 /* Generate a DIE to represent a label identifier. */
10410 gen_label_die (decl, context_die)
10411 register tree decl;
10412 register dw_die_ref context_die;
10414 register tree origin = decl_ultimate_origin (decl);
10415 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
10417 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10419 if (origin != NULL)
10420 add_abstract_origin_attribute (lbl_die, origin);
10422 add_name_and_src_coords_attributes (lbl_die, decl);
10424 if (DECL_ABSTRACT (decl))
10425 equate_decl_number_to_die (decl, lbl_die);
10428 insn = DECL_RTL (decl);
10430 /* Deleted labels are programmer specified labels which have been
10431 eliminated because of various optimisations. We still emit them
10432 here so that it is possible to put breakpoints on them. */
10433 if (GET_CODE (insn) == CODE_LABEL
10434 || ((GET_CODE (insn) == NOTE
10435 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10437 /* When optimization is enabled (via -O) some parts of the compiler
10438 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10439 represent source-level labels which were explicitly declared by
10440 the user. This really shouldn't be happening though, so catch
10441 it if it ever does happen. */
10442 if (INSN_DELETED_P (insn))
10445 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10446 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10451 /* Generate a DIE for a lexical block. */
10454 gen_lexical_block_die (stmt, context_die, depth)
10455 register tree stmt;
10456 register dw_die_ref context_die;
10459 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10460 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10462 if (! BLOCK_ABSTRACT (stmt))
10464 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10465 BLOCK_NUMBER (stmt));
10466 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10467 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10468 BLOCK_NUMBER (stmt));
10469 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10472 decls_for_scope (stmt, stmt_die, depth);
10475 /* Generate a DIE for an inlined subprogram. */
10478 gen_inlined_subroutine_die (stmt, context_die, depth)
10479 register tree stmt;
10480 register dw_die_ref context_die;
10483 if (! BLOCK_ABSTRACT (stmt))
10485 register dw_die_ref subr_die
10486 = new_die (DW_TAG_inlined_subroutine, context_die);
10487 register tree decl = block_ultimate_origin (stmt);
10488 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10490 /* Emit info for the abstract instance first, if we haven't yet. */
10491 gen_abstract_function (decl);
10493 add_abstract_origin_attribute (subr_die, decl);
10494 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10495 BLOCK_NUMBER (stmt));
10496 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10497 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10498 BLOCK_NUMBER (stmt));
10499 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10500 decls_for_scope (stmt, subr_die, depth);
10501 current_function_has_inlines = 1;
10505 /* Generate a DIE for a field in a record, or structure. */
10508 gen_field_die (decl, context_die)
10509 register tree decl;
10510 register dw_die_ref context_die;
10512 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10514 add_name_and_src_coords_attributes (decl_die, decl);
10515 add_type_attribute (decl_die, member_declared_type (decl),
10516 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10519 /* If this is a bit field... */
10520 if (DECL_BIT_FIELD_TYPE (decl))
10522 add_byte_size_attribute (decl_die, decl);
10523 add_bit_size_attribute (decl_die, decl);
10524 add_bit_offset_attribute (decl_die, decl);
10527 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10528 add_data_member_location_attribute (decl_die, decl);
10530 if (DECL_ARTIFICIAL (decl))
10531 add_AT_flag (decl_die, DW_AT_artificial, 1);
10533 if (TREE_PROTECTED (decl))
10534 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10536 else if (TREE_PRIVATE (decl))
10537 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10541 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10542 Use modified_type_die instead.
10543 We keep this code here just in case these types of DIEs may be needed to
10544 represent certain things in other languages (e.g. Pascal) someday. */
10546 gen_pointer_type_die (type, context_die)
10547 register tree type;
10548 register dw_die_ref context_die;
10550 register dw_die_ref ptr_die
10551 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10553 equate_type_number_to_die (type, ptr_die);
10554 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10555 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10558 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10559 Use modified_type_die instead.
10560 We keep this code here just in case these types of DIEs may be needed to
10561 represent certain things in other languages (e.g. Pascal) someday. */
10563 gen_reference_type_die (type, context_die)
10564 register tree type;
10565 register dw_die_ref context_die;
10567 register dw_die_ref ref_die
10568 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10570 equate_type_number_to_die (type, ref_die);
10571 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10572 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10576 /* Generate a DIE for a pointer to a member type. */
10578 gen_ptr_to_mbr_type_die (type, context_die)
10579 register tree type;
10580 register dw_die_ref context_die;
10582 register dw_die_ref ptr_die
10583 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10585 equate_type_number_to_die (type, ptr_die);
10586 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10587 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10588 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10591 /* Generate the DIE for the compilation unit. */
10594 gen_compile_unit_die (filename)
10595 register const char *filename;
10597 register dw_die_ref die;
10598 char producer[250];
10599 const char *wd = getpwd ();
10602 die = new_die (DW_TAG_compile_unit, NULL);
10603 add_name_attribute (die, filename);
10605 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10606 add_AT_string (die, DW_AT_comp_dir, wd);
10608 sprintf (producer, "%s %s", language_string, version_string);
10610 #ifdef MIPS_DEBUGGING_INFO
10611 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10612 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10613 not appear in the producer string, the debugger reaches the conclusion
10614 that the object file is stripped and has no debugging information.
10615 To get the MIPS/SGI debugger to believe that there is debugging
10616 information in the object file, we add a -g to the producer string. */
10617 if (debug_info_level > DINFO_LEVEL_TERSE)
10618 strcat (producer, " -g");
10621 add_AT_string (die, DW_AT_producer, producer);
10623 if (strcmp (language_string, "GNU C++") == 0)
10624 language = DW_LANG_C_plus_plus;
10625 else if (strcmp (language_string, "GNU Ada") == 0)
10626 language = DW_LANG_Ada83;
10627 else if (strcmp (language_string, "GNU F77") == 0)
10628 language = DW_LANG_Fortran77;
10629 else if (strcmp (language_string, "GNU Pascal") == 0)
10630 language = DW_LANG_Pascal83;
10631 else if (strcmp (language_string, "GNU Java") == 0)
10632 language = DW_LANG_Java;
10633 else if (flag_traditional)
10634 language = DW_LANG_C;
10636 language = DW_LANG_C89;
10638 add_AT_unsigned (die, DW_AT_language, language);
10643 /* Generate a DIE for a string type. */
10646 gen_string_type_die (type, context_die)
10647 register tree type;
10648 register dw_die_ref context_die;
10650 register dw_die_ref type_die
10651 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10653 equate_type_number_to_die (type, type_die);
10655 /* Fudge the string length attribute for now. */
10657 /* TODO: add string length info.
10658 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10659 bound_representation (upper_bound, 0, 'u'); */
10662 /* Generate the DIE for a base class. */
10665 gen_inheritance_die (binfo, context_die)
10666 register tree binfo;
10667 register dw_die_ref context_die;
10669 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10671 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10672 add_data_member_location_attribute (die, binfo);
10674 if (TREE_VIA_VIRTUAL (binfo))
10675 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10676 if (TREE_VIA_PUBLIC (binfo))
10677 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10678 else if (TREE_VIA_PROTECTED (binfo))
10679 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10682 /* Generate a DIE for a class member. */
10685 gen_member_die (type, context_die)
10686 register tree type;
10687 register dw_die_ref context_die;
10689 register tree member;
10692 /* If this is not an incomplete type, output descriptions of each of its
10693 members. Note that as we output the DIEs necessary to represent the
10694 members of this record or union type, we will also be trying to output
10695 DIEs to represent the *types* of those members. However the `type'
10696 function (above) will specifically avoid generating type DIEs for member
10697 types *within* the list of member DIEs for this (containing) type execpt
10698 for those types (of members) which are explicitly marked as also being
10699 members of this (containing) type themselves. The g++ front- end can
10700 force any given type to be treated as a member of some other
10701 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10702 to point to the TREE node representing the appropriate (containing)
10705 /* First output info about the base classes. */
10706 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10708 register tree bases = TYPE_BINFO_BASETYPES (type);
10709 register int n_bases = TREE_VEC_LENGTH (bases);
10712 for (i = 0; i < n_bases; i++)
10713 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10716 /* Now output info about the data members and type members. */
10717 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10719 /* If we thought we were generating minimal debug info for TYPE
10720 and then changed our minds, some of the member declarations
10721 may have already been defined. Don't define them again, but
10722 do put them in the right order. */
10724 child = lookup_decl_die (member);
10726 splice_child_die (context_die, child);
10728 gen_decl_die (member, context_die);
10731 /* Now output info about the function members (if any). */
10732 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10734 child = lookup_decl_die (member);
10736 splice_child_die (context_die, child);
10738 gen_decl_die (member, context_die);
10742 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10743 is set, we pretend that the type was never defined, so we only get the
10744 member DIEs needed by later specification DIEs. */
10747 gen_struct_or_union_type_die (type, context_die)
10748 register tree type;
10749 register dw_die_ref context_die;
10751 register dw_die_ref type_die = lookup_type_die (type);
10752 register dw_die_ref scope_die = 0;
10753 register int nested = 0;
10754 int complete = (TYPE_SIZE (type)
10755 && (! TYPE_STUB_DECL (type)
10756 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10758 if (type_die && ! complete)
10761 if (TYPE_CONTEXT (type) != NULL_TREE
10762 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10765 scope_die = scope_die_for (type, context_die);
10767 if (! type_die || (nested && scope_die == comp_unit_die))
10768 /* First occurrence of type or toplevel definition of nested class. */
10770 register dw_die_ref old_die = type_die;
10772 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10773 ? DW_TAG_structure_type : DW_TAG_union_type,
10775 equate_type_number_to_die (type, type_die);
10777 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10779 add_name_attribute (type_die, type_tag (type));
10782 remove_AT (type_die, DW_AT_declaration);
10784 /* If this type has been completed, then give it a byte_size attribute and
10785 then give a list of members. */
10788 /* Prevent infinite recursion in cases where the type of some member of
10789 this type is expressed in terms of this type itself. */
10790 TREE_ASM_WRITTEN (type) = 1;
10791 add_byte_size_attribute (type_die, type);
10792 if (TYPE_STUB_DECL (type) != NULL_TREE)
10793 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10795 /* If the first reference to this type was as the return type of an
10796 inline function, then it may not have a parent. Fix this now. */
10797 if (type_die->die_parent == NULL)
10798 add_child_die (scope_die, type_die);
10800 push_decl_scope (type);
10801 gen_member_die (type, type_die);
10804 /* GNU extension: Record what type our vtable lives in. */
10805 if (TYPE_VFIELD (type))
10807 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10809 gen_type_die (vtype, context_die);
10810 add_AT_die_ref (type_die, DW_AT_containing_type,
10811 lookup_type_die (vtype));
10816 add_AT_flag (type_die, DW_AT_declaration, 1);
10818 /* We don't need to do this for function-local types. */
10819 if (! decl_function_context (TYPE_STUB_DECL (type)))
10820 add_incomplete_type (type);
10824 /* Generate a DIE for a subroutine _type_. */
10827 gen_subroutine_type_die (type, context_die)
10828 register tree type;
10829 register dw_die_ref context_die;
10831 register tree return_type = TREE_TYPE (type);
10832 register dw_die_ref subr_die
10833 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10835 equate_type_number_to_die (type, subr_die);
10836 add_prototyped_attribute (subr_die, type);
10837 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10838 gen_formal_types_die (type, subr_die);
10841 /* Generate a DIE for a type definition */
10844 gen_typedef_die (decl, context_die)
10845 register tree decl;
10846 register dw_die_ref context_die;
10848 register dw_die_ref type_die;
10849 register tree origin;
10851 if (TREE_ASM_WRITTEN (decl))
10853 TREE_ASM_WRITTEN (decl) = 1;
10855 type_die = new_die (DW_TAG_typedef, context_die);
10856 origin = decl_ultimate_origin (decl);
10857 if (origin != NULL)
10858 add_abstract_origin_attribute (type_die, origin);
10861 register tree type;
10862 add_name_and_src_coords_attributes (type_die, decl);
10863 if (DECL_ORIGINAL_TYPE (decl))
10865 type = DECL_ORIGINAL_TYPE (decl);
10867 if (type == TREE_TYPE (decl))
10870 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10873 type = TREE_TYPE (decl);
10874 add_type_attribute (type_die, type, TREE_READONLY (decl),
10875 TREE_THIS_VOLATILE (decl), context_die);
10878 if (DECL_ABSTRACT (decl))
10879 equate_decl_number_to_die (decl, type_die);
10882 /* Generate a type description DIE. */
10885 gen_type_die (type, context_die)
10886 register tree type;
10887 register dw_die_ref context_die;
10891 if (type == NULL_TREE || type == error_mark_node)
10894 /* We are going to output a DIE to represent the unqualified version of
10895 this type (i.e. without any const or volatile qualifiers) so get the
10896 main variant (i.e. the unqualified version) of this type now. */
10897 type = type_main_variant (type);
10899 if (TREE_ASM_WRITTEN (type))
10902 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10903 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10905 TREE_ASM_WRITTEN (type) = 1;
10906 gen_decl_die (TYPE_NAME (type), context_die);
10910 switch (TREE_CODE (type))
10916 case REFERENCE_TYPE:
10917 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10918 ensures that the gen_type_die recursion will terminate even if the
10919 type is recursive. Recursive types are possible in Ada. */
10920 /* ??? We could perhaps do this for all types before the switch
10922 TREE_ASM_WRITTEN (type) = 1;
10924 /* For these types, all that is required is that we output a DIE (or a
10925 set of DIEs) to represent the "basis" type. */
10926 gen_type_die (TREE_TYPE (type), context_die);
10930 /* This code is used for C++ pointer-to-data-member types.
10931 Output a description of the relevant class type. */
10932 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10934 /* Output a description of the type of the object pointed to. */
10935 gen_type_die (TREE_TYPE (type), context_die);
10937 /* Now output a DIE to represent this pointer-to-data-member type
10939 gen_ptr_to_mbr_type_die (type, context_die);
10943 gen_type_die (TYPE_DOMAIN (type), context_die);
10944 gen_set_type_die (type, context_die);
10948 gen_type_die (TREE_TYPE (type), context_die);
10949 abort (); /* No way to represent these in Dwarf yet! */
10952 case FUNCTION_TYPE:
10953 /* Force out return type (in case it wasn't forced out already). */
10954 gen_type_die (TREE_TYPE (type), context_die);
10955 gen_subroutine_type_die (type, context_die);
10959 /* Force out return type (in case it wasn't forced out already). */
10960 gen_type_die (TREE_TYPE (type), context_die);
10961 gen_subroutine_type_die (type, context_die);
10965 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10967 gen_type_die (TREE_TYPE (type), context_die);
10968 gen_string_type_die (type, context_die);
10971 gen_array_type_die (type, context_die);
10975 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10978 case ENUMERAL_TYPE:
10981 case QUAL_UNION_TYPE:
10982 /* If this is a nested type whose containing class hasn't been
10983 written out yet, writing it out will cover this one, too.
10984 This does not apply to instantiations of member class templates;
10985 they need to be added to the containing class as they are
10986 generated. FIXME: This hurts the idea of combining type decls
10987 from multiple TUs, since we can't predict what set of template
10988 instantiations we'll get. */
10989 if (TYPE_CONTEXT (type)
10990 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10991 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10993 gen_type_die (TYPE_CONTEXT (type), context_die);
10995 if (TREE_ASM_WRITTEN (type))
10998 /* If that failed, attach ourselves to the stub. */
10999 push_decl_scope (TYPE_CONTEXT (type));
11000 context_die = lookup_type_die (TYPE_CONTEXT (type));
11006 if (TREE_CODE (type) == ENUMERAL_TYPE)
11007 gen_enumeration_type_die (type, context_die);
11009 gen_struct_or_union_type_die (type, context_die);
11014 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11015 it up if it is ever completed. gen_*_type_die will set it for us
11016 when appropriate. */
11025 /* No DIEs needed for fundamental types. */
11029 /* No Dwarf representation currently defined. */
11036 TREE_ASM_WRITTEN (type) = 1;
11039 /* Generate a DIE for a tagged type instantiation. */
11042 gen_tagged_type_instantiation_die (type, context_die)
11043 register tree type;
11044 register dw_die_ref context_die;
11046 if (type == NULL_TREE || type == error_mark_node)
11049 /* We are going to output a DIE to represent the unqualified version of
11050 this type (i.e. without any const or volatile qualifiers) so make sure
11051 that we have the main variant (i.e. the unqualified version) of this
11053 if (type != type_main_variant (type))
11056 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11057 an instance of an unresolved type. */
11059 switch (TREE_CODE (type))
11064 case ENUMERAL_TYPE:
11065 gen_inlined_enumeration_type_die (type, context_die);
11069 gen_inlined_structure_type_die (type, context_die);
11073 case QUAL_UNION_TYPE:
11074 gen_inlined_union_type_die (type, context_die);
11082 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11083 things which are local to the given block. */
11086 gen_block_die (stmt, context_die, depth)
11087 register tree stmt;
11088 register dw_die_ref context_die;
11091 register int must_output_die = 0;
11092 register tree origin;
11093 register tree decl;
11094 register enum tree_code origin_code;
11096 /* Ignore blocks never really used to make RTL. */
11098 if (stmt == NULL_TREE || !TREE_USED (stmt)
11099 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11102 /* Determine the "ultimate origin" of this block. This block may be an
11103 inlined instance of an inlined instance of inline function, so we have
11104 to trace all of the way back through the origin chain to find out what
11105 sort of node actually served as the original seed for the creation of
11106 the current block. */
11107 origin = block_ultimate_origin (stmt);
11108 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11110 /* Determine if we need to output any Dwarf DIEs at all to represent this
11112 if (origin_code == FUNCTION_DECL)
11113 /* The outer scopes for inlinings *must* always be represented. We
11114 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11115 must_output_die = 1;
11118 /* In the case where the current block represents an inlining of the
11119 "body block" of an inline function, we must *NOT* output any DIE for
11120 this block because we have already output a DIE to represent the
11121 whole inlined function scope and the "body block" of any function
11122 doesn't really represent a different scope according to ANSI C
11123 rules. So we check here to make sure that this block does not
11124 represent a "body block inlining" before trying to set the
11125 `must_output_die' flag. */
11126 if (! is_body_block (origin ? origin : stmt))
11128 /* Determine if this block directly contains any "significant"
11129 local declarations which we will need to output DIEs for. */
11130 if (debug_info_level > DINFO_LEVEL_TERSE)
11131 /* We are not in terse mode so *any* local declaration counts
11132 as being a "significant" one. */
11133 must_output_die = (BLOCK_VARS (stmt) != NULL);
11135 /* We are in terse mode, so only local (nested) function
11136 definitions count as "significant" local declarations. */
11137 for (decl = BLOCK_VARS (stmt);
11138 decl != NULL; decl = TREE_CHAIN (decl))
11139 if (TREE_CODE (decl) == FUNCTION_DECL
11140 && DECL_INITIAL (decl))
11142 must_output_die = 1;
11148 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11149 DIE for any block which contains no significant local declarations at
11150 all. Rather, in such cases we just call `decls_for_scope' so that any
11151 needed Dwarf info for any sub-blocks will get properly generated. Note
11152 that in terse mode, our definition of what constitutes a "significant"
11153 local declaration gets restricted to include only inlined function
11154 instances and local (nested) function definitions. */
11155 if (must_output_die)
11157 if (origin_code == FUNCTION_DECL)
11158 gen_inlined_subroutine_die (stmt, context_die, depth);
11160 gen_lexical_block_die (stmt, context_die, depth);
11163 decls_for_scope (stmt, context_die, depth);
11166 /* Generate all of the decls declared within a given scope and (recursively)
11167 all of its sub-blocks. */
11170 decls_for_scope (stmt, context_die, depth)
11171 register tree stmt;
11172 register dw_die_ref context_die;
11175 register tree decl;
11176 register tree subblocks;
11178 /* Ignore blocks never really used to make RTL. */
11179 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11182 /* Output the DIEs to represent all of the data objects and typedefs
11183 declared directly within this block but not within any nested
11184 sub-blocks. Also, nested function and tag DIEs have been
11185 generated with a parent of NULL; fix that up now. */
11186 for (decl = BLOCK_VARS (stmt);
11187 decl != NULL; decl = TREE_CHAIN (decl))
11189 register dw_die_ref die;
11191 if (TREE_CODE (decl) == FUNCTION_DECL)
11192 die = lookup_decl_die (decl);
11193 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11194 die = lookup_type_die (TREE_TYPE (decl));
11198 if (die != NULL && die->die_parent == NULL)
11199 add_child_die (context_die, die);
11201 gen_decl_die (decl, context_die);
11204 /* Output the DIEs to represent all sub-blocks (and the items declared
11205 therein) of this block. */
11206 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11208 subblocks = BLOCK_CHAIN (subblocks))
11209 gen_block_die (subblocks, context_die, depth + 1);
11212 /* Is this a typedef we can avoid emitting? */
11215 is_redundant_typedef (decl)
11216 register tree decl;
11218 if (TYPE_DECL_IS_STUB (decl))
11221 if (DECL_ARTIFICIAL (decl)
11222 && DECL_CONTEXT (decl)
11223 && is_tagged_type (DECL_CONTEXT (decl))
11224 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11225 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11226 /* Also ignore the artificial member typedef for the class name. */
11232 /* Generate Dwarf debug information for a decl described by DECL. */
11235 gen_decl_die (decl, context_die)
11236 register tree decl;
11237 register dw_die_ref context_die;
11239 register tree origin;
11241 if (TREE_CODE (decl) == ERROR_MARK)
11244 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11245 if (DECL_IGNORED_P (decl))
11248 switch (TREE_CODE (decl))
11251 /* The individual enumerators of an enum type get output when we output
11252 the Dwarf representation of the relevant enum type itself. */
11255 case FUNCTION_DECL:
11256 /* Don't output any DIEs to represent mere function declarations,
11257 unless they are class members or explicit block externs. */
11258 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11259 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11262 /* If we're emitting an out-of-line copy of an inline function,
11263 emit info for the abstract instance and set up to refer to it. */
11264 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11265 && ! class_scope_p (context_die)
11266 /* gen_abstract_function won't emit a die if this is just a
11267 declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11268 that case, because that works only if we have a die. */
11269 && DECL_INITIAL (decl) != NULL_TREE)
11271 gen_abstract_function (decl);
11272 set_decl_origin_self (decl);
11275 if (debug_info_level > DINFO_LEVEL_TERSE)
11277 /* Before we describe the FUNCTION_DECL itself, make sure that we
11278 have described its return type. */
11279 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11281 /* And its virtual context. */
11282 if (DECL_VINDEX (decl) != NULL_TREE)
11283 gen_type_die (DECL_CONTEXT (decl), context_die);
11285 /* And its containing type. */
11286 origin = decl_class_context (decl);
11287 if (origin != NULL_TREE)
11288 gen_type_die_for_member (origin, decl, context_die);
11291 /* Now output a DIE to represent the function itself. */
11292 gen_subprogram_die (decl, context_die);
11296 /* If we are in terse mode, don't generate any DIEs to represent any
11297 actual typedefs. */
11298 if (debug_info_level <= DINFO_LEVEL_TERSE)
11301 /* In the special case of a TYPE_DECL node representing the
11302 declaration of some type tag, if the given TYPE_DECL is marked as
11303 having been instantiated from some other (original) TYPE_DECL node
11304 (e.g. one which was generated within the original definition of an
11305 inline function) we have to generate a special (abbreviated)
11306 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
11308 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11310 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11314 if (is_redundant_typedef (decl))
11315 gen_type_die (TREE_TYPE (decl), context_die);
11317 /* Output a DIE to represent the typedef itself. */
11318 gen_typedef_die (decl, context_die);
11322 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11323 gen_label_die (decl, context_die);
11327 /* If we are in terse mode, don't generate any DIEs to represent any
11328 variable declarations or definitions. */
11329 if (debug_info_level <= DINFO_LEVEL_TERSE)
11332 /* Output any DIEs that are needed to specify the type of this data
11334 gen_type_die (TREE_TYPE (decl), context_die);
11336 /* And its containing type. */
11337 origin = decl_class_context (decl);
11338 if (origin != NULL_TREE)
11339 gen_type_die_for_member (origin, decl, context_die);
11341 /* Now output the DIE to represent the data object itself. This gets
11342 complicated because of the possibility that the VAR_DECL really
11343 represents an inlined instance of a formal parameter for an inline
11345 origin = decl_ultimate_origin (decl);
11346 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11347 gen_formal_parameter_die (decl, context_die);
11349 gen_variable_die (decl, context_die);
11353 /* Ignore the nameless fields that are used to skip bits, but
11354 handle C++ anonymous unions. */
11355 if (DECL_NAME (decl) != NULL_TREE
11356 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11358 gen_type_die (member_declared_type (decl), context_die);
11359 gen_field_die (decl, context_die);
11364 gen_type_die (TREE_TYPE (decl), context_die);
11365 gen_formal_parameter_die (decl, context_die);
11368 case NAMESPACE_DECL:
11369 /* Ignore for now. */
11377 /* Add Ada "use" clause information for SGI Workshop debugger. */
11380 dwarf2out_add_library_unit_info (filename, context_list)
11381 const char *filename;
11382 const char *context_list;
11384 unsigned int file_index;
11386 if (filename != NULL)
11388 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
11389 tree context_list_decl
11390 = build_decl (LABEL_DECL, get_identifier (context_list),
11393 TREE_PUBLIC (context_list_decl) = TRUE;
11394 add_name_attribute (unit_die, context_list);
11395 file_index = lookup_filename (&decl_file_table, filename);
11396 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11397 add_pubname (context_list_decl, unit_die);
11401 /* Write the debugging output for DECL. */
11404 dwarf2out_decl (decl)
11405 register tree decl;
11407 register dw_die_ref context_die = comp_unit_die;
11409 if (TREE_CODE (decl) == ERROR_MARK)
11412 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11413 if (DECL_IGNORED_P (decl))
11416 switch (TREE_CODE (decl))
11418 case FUNCTION_DECL:
11419 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11420 builtin function. Explicit programmer-supplied declarations of
11421 these same functions should NOT be ignored however. */
11422 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11425 /* What we would really like to do here is to filter out all mere
11426 file-scope declarations of file-scope functions which are never
11427 referenced later within this translation unit (and keep all of ones
11428 that *are* referenced later on) but we aren't clairvoyant, so we have
11429 no idea which functions will be referenced in the future (i.e. later
11430 on within the current translation unit). So here we just ignore all
11431 file-scope function declarations which are not also definitions. If
11432 and when the debugger needs to know something about these functions,
11433 it will have to hunt around and find the DWARF information associated
11434 with the definition of the function. Note that we can't just check
11435 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11436 definitions and which ones represent mere declarations. We have to
11437 check `DECL_INITIAL' instead. That's because the C front-end
11438 supports some weird semantics for "extern inline" function
11439 definitions. These can get inlined within the current translation
11440 unit (an thus, we need to generate DWARF info for their abstract
11441 instances so that the DWARF info for the concrete inlined instances
11442 can have something to refer to) but the compiler never generates any
11443 out-of-lines instances of such things (despite the fact that they
11444 *are* definitions). The important point is that the C front-end
11445 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11446 to generate DWARF for them anyway. Note that the C++ front-end also
11447 plays some similar games for inline function definitions appearing
11448 within include files which also contain
11449 `#pragma interface' pragmas. */
11450 if (DECL_INITIAL (decl) == NULL_TREE)
11453 /* If we're a nested function, initially use a parent of NULL; if we're
11454 a plain function, this will be fixed up in decls_for_scope. If
11455 we're a method, it will be ignored, since we already have a DIE. */
11456 if (decl_function_context (decl))
11457 context_die = NULL;
11462 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11463 declaration and if the declaration was never even referenced from
11464 within this entire compilation unit. We suppress these DIEs in
11465 order to save space in the .debug section (by eliminating entries
11466 which are probably useless). Note that we must not suppress
11467 block-local extern declarations (whether used or not) because that
11468 would screw-up the debugger's name lookup mechanism and cause it to
11469 miss things which really ought to be in scope at a given point. */
11470 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11473 /* If we are in terse mode, don't generate any DIEs to represent any
11474 variable declarations or definitions. */
11475 if (debug_info_level <= DINFO_LEVEL_TERSE)
11480 /* Don't emit stubs for types unless they are needed by other DIEs. */
11481 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11484 /* Don't bother trying to generate any DIEs to represent any of the
11485 normal built-in types for the language we are compiling. */
11486 if (DECL_SOURCE_LINE (decl) == 0)
11488 /* OK, we need to generate one for `bool' so GDB knows what type
11489 comparisons have. */
11490 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11491 == DW_LANG_C_plus_plus)
11492 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11493 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11498 /* If we are in terse mode, don't generate any DIEs for types. */
11499 if (debug_info_level <= DINFO_LEVEL_TERSE)
11502 /* If we're a function-scope tag, initially use a parent of NULL;
11503 this will be fixed up in decls_for_scope. */
11504 if (decl_function_context (decl))
11505 context_die = NULL;
11513 gen_decl_die (decl, context_die);
11516 /* Output a marker (i.e. a label) for the beginning of the generated code for
11517 a lexical block. */
11520 dwarf2out_begin_block (blocknum)
11521 register unsigned blocknum;
11523 function_section (current_function_decl);
11524 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11527 /* Output a marker (i.e. a label) for the end of the generated code for a
11531 dwarf2out_end_block (blocknum)
11532 register unsigned blocknum;
11534 function_section (current_function_decl);
11535 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11538 /* Returns nonzero if it is appropriate not to emit any debugging
11539 information for BLOCK, because it doesn't contain any instructions.
11541 Don't allow this for blocks with nested functions or local classes
11542 as we would end up with orphans, and in the presence of scheduling
11543 we may end up calling them anyway. */
11546 dwarf2out_ignore_block (block)
11550 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11551 if (TREE_CODE (decl) == FUNCTION_DECL
11552 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11557 /* Lookup a filename (in the list of filenames that we know about here in
11558 dwarf2out.c) and return its "index". The index of each (known) filename is
11559 just a unique number which is associated with only that one filename.
11560 We need such numbers for the sake of generating labels
11561 (in the .debug_sfnames section) and references to those
11562 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11563 If the filename given as an argument is not found in our current list,
11564 add it to the list and assign it the next available unique index number.
11565 In order to speed up searches, we remember the index of the filename
11566 was looked up last. This handles the majority of all searches. */
11569 lookup_filename (t, file_name)
11570 struct file_table *t;
11571 const char *file_name;
11573 register unsigned i;
11575 /* Check to see if the file name that was searched on the previous
11576 call matches this file name. If so, return the index. */
11577 if (t->last_lookup_index != 0)
11578 if (strcmp (file_name, t->table[t->last_lookup_index]) == 0)
11579 return t->last_lookup_index;
11581 /* Didn't match the previous lookup, search the table */
11582 for (i = 1; i < t->in_use; ++i)
11583 if (strcmp (file_name, t->table[i]) == 0)
11585 t->last_lookup_index = i;
11589 /* Prepare to add a new table entry by making sure there is enough space in
11590 the table to do so. If not, expand the current table. */
11591 if (i == t->allocated)
11593 t->allocated = i + FILE_TABLE_INCREMENT;
11594 t->table = (char **)
11595 xrealloc (t->table, t->allocated * sizeof (char *));
11598 /* Add the new entry to the end of the filename table. */
11599 t->table[i] = xstrdup (file_name);
11601 t->last_lookup_index = i;
11607 init_file_table (t)
11608 struct file_table *t;
11610 /* Allocate the initial hunk of the file_table. */
11611 t->table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11612 t->allocated = FILE_TABLE_INCREMENT;
11614 /* Skip the first entry - file numbers begin at 1. */
11616 t->last_lookup_index = 0;
11619 /* Output a label to mark the beginning of a source code line entry
11620 and record information relating to this source line, in
11621 'line_info_table' for later output of the .debug_line section. */
11624 dwarf2out_line (filename, line)
11625 register const char *filename;
11626 register unsigned line;
11628 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11630 function_section (current_function_decl);
11632 if (DWARF2_ASM_LINE_DEBUG_INFO)
11635 unsigned old_in_use = line_file_table.in_use;
11637 unsigned file_num = lookup_filename (&line_file_table, filename);
11639 /* Emit the .file and .loc directives understood by GNU as. */
11641 /* ??? As of 2000-11-25, gas has a bug in which it doesn't
11642 actually use the file number argument. It merely remembers
11643 the last .file directive emitted. */
11644 if (file_num >= old_in_use)
11645 fprintf (asm_out_file, "\t.file %d \"%s\"\n", file_num, filename);
11646 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11648 static unsigned int last_file_num;
11649 if (file_num != last_file_num)
11651 last_file_num = file_num;
11652 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
11654 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
11657 /* Indicate that line number info exists. */
11658 ++line_info_table_in_use;
11660 /* Indicate that multiple line number tables exist. */
11661 if (DECL_SECTION_NAME (current_function_decl))
11662 ++separate_line_info_table_in_use;
11664 else if (DECL_SECTION_NAME (current_function_decl))
11666 register dw_separate_line_info_ref line_info;
11667 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11668 separate_line_info_table_in_use);
11669 if (flag_debug_asm)
11670 fprintf (asm_out_file, "\t%s %s:%d", ASM_COMMENT_START,
11672 fputc ('\n', asm_out_file);
11674 /* expand the line info table if necessary */
11675 if (separate_line_info_table_in_use
11676 == separate_line_info_table_allocated)
11678 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11679 separate_line_info_table
11680 = (dw_separate_line_info_ref)
11681 xrealloc (separate_line_info_table,
11682 separate_line_info_table_allocated
11683 * sizeof (dw_separate_line_info_entry));
11686 /* Add the new entry at the end of the line_info_table. */
11688 = &separate_line_info_table[separate_line_info_table_in_use++];
11689 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
11690 line_info->dw_line_num = line;
11691 line_info->function = current_funcdef_number;
11695 register dw_line_info_ref line_info;
11697 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11698 line_info_table_in_use);
11699 if (flag_debug_asm)
11700 fprintf (asm_out_file, "\t%s %s:%d", ASM_COMMENT_START,
11702 fputc ('\n', asm_out_file);
11704 /* Expand the line info table if necessary. */
11705 if (line_info_table_in_use == line_info_table_allocated)
11707 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11709 = (dw_line_info_ref)
11710 xrealloc (line_info_table,
11711 (line_info_table_allocated
11712 * sizeof (dw_line_info_entry)));
11715 /* Add the new entry at the end of the line_info_table. */
11716 line_info = &line_info_table[line_info_table_in_use++];
11717 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
11718 line_info->dw_line_num = line;
11723 /* Record the beginning of a new source file, for later output
11724 of the .debug_macinfo section. At present, unimplemented. */
11727 dwarf2out_start_source_file (filename)
11728 register const char *filename ATTRIBUTE_UNUSED;
11730 if (flag_eliminate_dwarf2_dups)
11732 /* Record the beginning of the file for break_out_includes. */
11733 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11734 add_AT_string (bincl_die, DW_AT_name, filename);
11738 /* Record the end of a source file, for later output
11739 of the .debug_macinfo section. At present, unimplemented. */
11742 dwarf2out_end_source_file ()
11744 if (flag_eliminate_dwarf2_dups)
11746 /* Record the end of the file for break_out_includes. */
11747 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11751 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11752 the tail part of the directive line, i.e. the part which is past the
11753 initial whitespace, #, whitespace, directive-name, whitespace part. */
11756 dwarf2out_define (lineno, buffer)
11757 register unsigned lineno ATTRIBUTE_UNUSED;
11758 register const char *buffer ATTRIBUTE_UNUSED;
11760 static int initialized = 0;
11763 dwarf2out_start_source_file (primary_filename);
11768 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11769 the tail part of the directive line, i.e. the part which is past the
11770 initial whitespace, #, whitespace, directive-name, whitespace part. */
11773 dwarf2out_undef (lineno, buffer)
11774 register unsigned lineno ATTRIBUTE_UNUSED;
11775 register const char *buffer ATTRIBUTE_UNUSED;
11779 /* Set up for Dwarf output at the start of compilation. */
11782 dwarf2out_init (asm_out_file, main_input_filename)
11783 register FILE *asm_out_file;
11784 register const char *main_input_filename;
11786 /* Remember the name of the primary input file. */
11787 primary_filename = main_input_filename;
11789 init_file_table (&decl_file_table);
11790 init_file_table (&line_file_table);
11792 /* Allocate the initial hunk of the decl_die_table. */
11794 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11795 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11796 decl_die_table_in_use = 0;
11798 /* Allocate the initial hunk of the decl_scope_table. */
11800 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11801 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11802 decl_scope_depth = 0;
11804 /* Allocate the initial hunk of the abbrev_die_table. */
11806 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11807 sizeof (dw_die_ref));
11808 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11809 /* Zero-th entry is allocated, but unused */
11810 abbrev_die_table_in_use = 1;
11812 /* Allocate the initial hunk of the line_info_table. */
11814 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11815 sizeof (dw_line_info_entry));
11816 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11817 /* Zero-th entry is allocated, but unused */
11818 line_info_table_in_use = 1;
11820 /* Generate the initial DIE for the .debug section. Note that the (string)
11821 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11822 will (typically) be a relative pathname and that this pathname should be
11823 taken as being relative to the directory from which the compiler was
11824 invoked when the given (base) source file was compiled. */
11825 comp_unit_die = gen_compile_unit_die (main_input_filename);
11827 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11828 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11830 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11831 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
11832 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11833 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11835 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11836 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11837 DEBUG_INFO_SECTION_LABEL, 0);
11838 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11839 DEBUG_LINE_SECTION_LABEL, 0);
11841 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11842 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11843 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11845 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11846 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11848 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11849 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11850 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11851 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11854 /* Output stuff that dwarf requires at the end of every file,
11855 and generate the DWARF-2 debugging info. */
11858 dwarf2out_finish ()
11860 limbo_die_node *node, *next_node;
11863 /* Traverse the limbo die list, and add parent/child links. The only
11864 dies without parents that should be here are concrete instances of
11865 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11866 For concrete instances, we can get the parent die from the abstract
11868 for (node = limbo_die_list; node; node = next_node)
11870 next_node = node->next;
11873 if (die->die_parent == NULL)
11875 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11877 add_child_die (origin->die_parent, die);
11878 else if (die == comp_unit_die)
11885 limbo_die_list = NULL;
11887 /* Walk through the list of incomplete types again, trying once more to
11888 emit full debugging info for them. */
11889 retry_incomplete_types ();
11891 /* We need to reverse all the dies before break_out_includes, or
11892 we'll see the end of an include file before the beginning. */
11893 reverse_all_dies (comp_unit_die);
11895 /* Generate separate CUs for each of the include files we've seen.
11896 They will go into limbo_die_list. */
11897 if (flag_eliminate_dwarf2_dups)
11898 break_out_includes (comp_unit_die);
11900 /* Traverse the DIE's and add add sibling attributes to those DIE's
11901 that have children. */
11902 add_sibling_attributes (comp_unit_die);
11903 for (node = limbo_die_list; node; node = node->next)
11904 add_sibling_attributes (node->die);
11906 /* Output a terminator label for the .text section. */
11907 fputc ('\n', asm_out_file);
11908 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11909 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11912 /* Output a terminator label for the .data section. */
11913 fputc ('\n', asm_out_file);
11914 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11915 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11917 /* Output a terminator label for the .bss section. */
11918 fputc ('\n', asm_out_file);
11919 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11920 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11923 /* Output the source line correspondence table. */
11924 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
11926 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11928 fputc ('\n', asm_out_file);
11929 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11930 output_line_info ();
11933 /* We can only use the low/high_pc attributes if all of the code
11935 if (separate_line_info_table_in_use == 0)
11937 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11938 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11941 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11942 debug_line_section_label);
11945 #if 0 /* unimplemented */
11946 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
11947 add_AT_unsigned (die, DW_AT_macro_info, 0);
11950 /* Output all of the compilation units. We put the main one last so that
11951 the offsets are available to output_pubnames. */
11952 for (node = limbo_die_list; node; node = node->next)
11953 output_comp_unit (node->die);
11954 output_comp_unit (comp_unit_die);
11956 /* Output the abbreviation table. */
11957 fputc ('\n', asm_out_file);
11958 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11959 output_abbrev_section ();
11961 if (pubname_table_in_use)
11963 /* Output public names table. */
11964 fputc ('\n', asm_out_file);
11965 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
11966 output_pubnames ();
11969 /* We only put functions in the arange table, so don't write it out if
11970 we don't have any. */
11971 if (fde_table_in_use)
11973 /* Output the address range information. */
11974 fputc ('\n', asm_out_file);
11975 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11979 #endif /* DWARF2_DEBUGGING_INFO */