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 an abstract idea representing a fixed stack address
61 identifying a stack call frame. The CFA register and
62 offset, whose value may change, keeps track of its value at
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 the FP (or a scratch that will be copied into the FP
1551 later on) from SP + const. */
1552 cfa.reg = REGNO (dest);
1556 if (XEXP (src, 1) != stack_pointer_rtx)
1558 if (GET_CODE (XEXP (src, 0)) != REG
1559 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg)
1561 if (cfa.reg != STACK_POINTER_REGNUM)
1563 cfa_store.reg = REGNO (dest);
1564 cfa_store.offset = cfa.offset - cfa_temp.offset;
1571 cfa_temp.reg = REGNO (dest);
1572 cfa_temp.offset = INTVAL (src);
1577 if (GET_CODE (XEXP (src, 0)) != REG
1578 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1579 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1581 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1582 cfa_temp.reg = REGNO (dest);
1583 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1589 def_cfa_1 (label, &cfa);
1592 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1593 will fill in all of the bits. */
1600 if (GET_CODE (XEXP (src, 1)) != CONST_INT)
1602 cfa_temp.reg = REGNO (dest);
1603 cfa_temp.offset = INTVAL (XEXP (src, 1));
1607 if (GET_CODE (src) != REG)
1610 /* Saving a register to the stack. Make sure dest is relative to the
1612 switch (GET_CODE (XEXP (dest, 0)))
1617 /* We can't handle variable size modifications. */
1618 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1620 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1622 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1623 || cfa_store.reg != STACK_POINTER_REGNUM)
1625 cfa_store.offset += offset;
1626 if (cfa.reg == STACK_POINTER_REGNUM)
1627 cfa.offset = cfa_store.offset;
1629 offset = -cfa_store.offset;
1634 offset = GET_MODE_SIZE (GET_MODE (dest));
1635 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1638 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1639 || cfa_store.reg != STACK_POINTER_REGNUM)
1641 cfa_store.offset += offset;
1642 if (cfa.reg == STACK_POINTER_REGNUM)
1643 cfa.offset = cfa_store.offset;
1645 offset = -cfa_store.offset;
1649 /* With an offset. */
1652 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1654 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1655 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1658 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1660 offset -= cfa_store.offset;
1664 /* Without an offset. */
1666 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1668 offset = -cfa_store.offset;
1675 if (REGNO (src) != STACK_POINTER_REGNUM
1676 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1677 && (unsigned) REGNO (src) == cfa.reg)
1679 /* We're storing the current CFA reg into the stack. */
1681 if (cfa.offset == 0)
1683 /* If the source register is exactly the CFA, assume
1684 we're saving SP like any other register; this happens
1687 def_cfa_1 (label, &cfa);
1688 dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset);
1693 /* Otherwise, we'll need to look in the stack to
1694 calculate the CFA. */
1696 rtx x = XEXP (dest, 0);
1697 if (GET_CODE (x) != REG)
1699 if (GET_CODE (x) != REG)
1701 cfa.reg = (unsigned) REGNO (x);
1702 cfa.base_offset = offset;
1704 def_cfa_1 (label, &cfa);
1709 def_cfa_1 (label, &cfa);
1710 dwarf2out_reg_save (label, REGNO (src), offset);
1718 /* Record call frame debugging information for INSN, which either
1719 sets SP or FP (adjusting how we calculate the frame address) or saves a
1720 register to the stack. If INSN is NULL_RTX, initialize our state. */
1723 dwarf2out_frame_debug (insn)
1729 if (insn == NULL_RTX)
1731 /* Set up state for generating call frame debug info. */
1733 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1735 cfa.reg = STACK_POINTER_REGNUM;
1738 cfa_temp.offset = 0;
1742 if (! RTX_FRAME_RELATED_P (insn))
1744 dwarf2out_stack_adjust (insn);
1748 label = dwarf2out_cfi_label ();
1750 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1752 insn = XEXP (src, 0);
1754 insn = PATTERN (insn);
1756 dwarf2out_frame_debug_expr (insn, label);
1759 /* Return the size of an unsigned LEB128 quantity. */
1761 static inline unsigned long
1762 size_of_uleb128 (value)
1763 register unsigned long value;
1765 register unsigned long size = 0;
1766 register unsigned byte;
1770 byte = (value & 0x7f);
1779 /* Return the size of a signed LEB128 quantity. */
1781 static inline unsigned long
1782 size_of_sleb128 (value)
1783 register long value;
1785 register unsigned long size = 0;
1786 register unsigned byte;
1790 byte = (value & 0x7f);
1794 while (!(((value == 0) && ((byte & 0x40) == 0))
1795 || ((value == -1) && ((byte & 0x40) != 0))));
1800 /* Output an unsigned LEB128 quantity. */
1803 output_uleb128 (value)
1804 register unsigned long value;
1806 unsigned long save_value = value;
1808 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1811 register unsigned byte = (value & 0x7f);
1814 /* More bytes to follow. */
1817 fprintf (asm_out_file, "0x%x", byte);
1819 fprintf (asm_out_file, ",");
1824 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1827 /* Output an signed LEB128 quantity. */
1830 output_sleb128 (value)
1831 register long value;
1834 register unsigned byte;
1835 long save_value = value;
1837 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1840 byte = (value & 0x7f);
1841 /* arithmetic shift */
1843 more = !((((value == 0) && ((byte & 0x40) == 0))
1844 || ((value == -1) && ((byte & 0x40) != 0))));
1848 fprintf (asm_out_file, "0x%x", byte);
1850 fprintf (asm_out_file, ",");
1855 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1858 /* Output a Call Frame Information opcode and its operand(s). */
1861 output_cfi (cfi, fde)
1862 register dw_cfi_ref cfi;
1863 register dw_fde_ref fde;
1865 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1867 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1869 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1871 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1872 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1873 fputc ('\n', asm_out_file);
1876 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1878 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1880 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1882 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1883 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1885 fputc ('\n', asm_out_file);
1886 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1887 fputc ('\n', asm_out_file);
1889 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1891 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1893 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1895 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1896 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1898 fputc ('\n', asm_out_file);
1902 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1904 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1905 dwarf_cfi_name (cfi->dw_cfi_opc));
1907 fputc ('\n', asm_out_file);
1908 switch (cfi->dw_cfi_opc)
1910 case DW_CFA_set_loc:
1911 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1912 fputc ('\n', asm_out_file);
1914 case DW_CFA_advance_loc1:
1915 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1916 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1917 fde->dw_fde_current_label);
1918 fputc ('\n', asm_out_file);
1919 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1921 case DW_CFA_advance_loc2:
1922 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1923 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1924 fde->dw_fde_current_label);
1925 fputc ('\n', asm_out_file);
1926 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1928 case DW_CFA_advance_loc4:
1929 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1930 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1931 fde->dw_fde_current_label);
1932 fputc ('\n', asm_out_file);
1933 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1935 #ifdef MIPS_DEBUGGING_INFO
1936 case DW_CFA_MIPS_advance_loc8:
1937 /* TODO: not currently implemented. */
1941 case DW_CFA_offset_extended:
1942 case DW_CFA_GNU_negative_offset_extended:
1943 case DW_CFA_def_cfa:
1944 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1945 fputc ('\n', asm_out_file);
1946 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1947 fputc ('\n', asm_out_file);
1949 case DW_CFA_restore_extended:
1950 case DW_CFA_undefined:
1951 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1952 fputc ('\n', asm_out_file);
1954 case DW_CFA_same_value:
1955 case DW_CFA_def_cfa_register:
1956 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1957 fputc ('\n', asm_out_file);
1959 case DW_CFA_register:
1960 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1961 fputc ('\n', asm_out_file);
1962 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1963 fputc ('\n', asm_out_file);
1965 case DW_CFA_def_cfa_offset:
1966 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1967 fputc ('\n', asm_out_file);
1969 case DW_CFA_GNU_window_save:
1971 case DW_CFA_GNU_args_size:
1972 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1973 fputc ('\n', asm_out_file);
1975 case DW_CFA_def_cfa_expression:
1976 output_cfa_loc (cfi);
1984 /* Output the call frame information used to used to record information
1985 that relates to calculating the frame pointer, and records the
1986 location of saved registers. */
1989 output_call_frame_info (for_eh)
1992 register unsigned long i;
1993 register dw_fde_ref fde;
1994 register dw_cfi_ref cfi;
1995 char l1[20], l2[20];
1996 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2000 /* Do we want to include a pointer to the exception table? */
2001 int eh_ptr = for_eh && exception_table_p ();
2003 /* If we don't have any functions we'll want to unwind out of, don't
2004 emit any EH unwind information. */
2007 for (i = 0; i < fde_table_in_use; ++i)
2008 if (! fde_table[i].nothrow)
2014 fputc ('\n', asm_out_file);
2016 /* We're going to be generating comments, so turn on app. */
2022 #ifdef EH_FRAME_SECTION
2023 EH_FRAME_SECTION ();
2025 tree label = get_file_function_name ('F');
2027 force_data_section ();
2028 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2029 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2030 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2032 assemble_label ("__FRAME_BEGIN__");
2035 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
2037 /* Output the CIE. */
2038 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2039 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2040 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2041 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
2043 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
2045 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
2048 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
2050 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
2053 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
2056 fputc ('\n', asm_out_file);
2057 ASM_OUTPUT_LABEL (asm_out_file, l1);
2060 /* Now that the CIE pointer is PC-relative for EH,
2061 use 0 to identify the CIE. */
2062 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2064 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
2067 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
2069 fputc ('\n', asm_out_file);
2070 if (! for_eh && DWARF_OFFSET_SIZE == 8)
2072 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
2073 fputc ('\n', asm_out_file);
2076 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
2078 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
2080 fputc ('\n', asm_out_file);
2083 /* The CIE contains a pointer to the exception region info for the
2084 frame. Make the augmentation string three bytes (including the
2085 trailing null) so the pointer is 4-byte aligned. The Solaris ld
2086 can't handle unaligned relocs. */
2089 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
2090 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
2094 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
2096 fputc ('\n', asm_out_file);
2098 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
2100 fprintf (asm_out_file, "\t%s pointer to exception region info",
2105 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
2107 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
2111 fputc ('\n', asm_out_file);
2114 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
2116 fputc ('\n', asm_out_file);
2117 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
2119 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
2121 fputc ('\n', asm_out_file);
2122 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
2124 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
2126 fputc ('\n', asm_out_file);
2128 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2129 output_cfi (cfi, NULL);
2131 /* Pad the CIE out to an address sized boundary. */
2132 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2133 ASM_OUTPUT_LABEL (asm_out_file, l2);
2134 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2135 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
2137 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
2138 fputc ('\n', asm_out_file);
2141 /* Loop through all of the FDE's. */
2142 for (i = 0; i < fde_table_in_use; ++i)
2144 fde = &fde_table[i];
2146 /* Don't emit EH unwind info for leaf functions. */
2147 if (for_eh && fde->nothrow)
2150 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2151 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2152 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2153 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i * 2);
2155 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
2157 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
2160 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
2162 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
2165 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
2166 fputc ('\n', asm_out_file);
2167 ASM_OUTPUT_LABEL (asm_out_file, l1);
2169 /* ??? This always emits a 4 byte offset when for_eh is true, but it
2170 emits a target dependent sized offset when for_eh is not true.
2171 This inconsistency may confuse gdb. The only case where we need a
2172 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
2173 compatibility if we emit a 4 byte offset. We need a 4 byte offset
2174 though in order to be compatible with the dwarf_fde struct in frame.c.
2175 If the for_eh case is changed, then the struct in frame.c has
2176 to be adjusted appropriately. */
2178 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
2180 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
2182 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
2184 fputc ('\n', asm_out_file);
2185 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
2187 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
2189 fputc ('\n', asm_out_file);
2190 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
2191 fde->dw_fde_end, fde->dw_fde_begin);
2193 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
2195 fputc ('\n', asm_out_file);
2197 /* Loop through the Call Frame Instructions associated with
2199 fde->dw_fde_current_label = fde->dw_fde_begin;
2200 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2201 output_cfi (cfi, fde);
2203 /* Pad the FDE out to an address sized boundary. */
2204 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2205 ASM_OUTPUT_LABEL (asm_out_file, l2);
2206 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2207 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
2209 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
2210 fputc ('\n', asm_out_file);
2213 #ifndef EH_FRAME_SECTION
2216 /* Emit terminating zero for table. */
2217 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2218 fputc ('\n', asm_out_file);
2221 #ifdef MIPS_DEBUGGING_INFO
2222 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2223 get a value of 0. Putting .align 0 after the label fixes it. */
2224 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2227 /* Turn off app to make assembly quicker. */
2232 /* Output a marker (i.e. a label) for the beginning of a function, before
2236 dwarf2out_begin_prologue ()
2238 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2239 register dw_fde_ref fde;
2241 ++current_funcdef_number;
2243 function_section (current_function_decl);
2244 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2245 current_funcdef_number);
2246 ASM_OUTPUT_LABEL (asm_out_file, label);
2247 current_function_func_begin_label = get_identifier (label);
2249 /* Expand the fde table if necessary. */
2250 if (fde_table_in_use == fde_table_allocated)
2252 fde_table_allocated += FDE_TABLE_INCREMENT;
2254 = (dw_fde_ref) xrealloc (fde_table,
2255 fde_table_allocated * sizeof (dw_fde_node));
2258 /* Record the FDE associated with this function. */
2259 current_funcdef_fde = fde_table_in_use;
2261 /* Add the new FDE at the end of the fde_table. */
2262 fde = &fde_table[fde_table_in_use++];
2263 fde->dw_fde_begin = xstrdup (label);
2264 fde->dw_fde_current_label = NULL;
2265 fde->dw_fde_end = NULL;
2266 fde->dw_fde_cfi = NULL;
2267 fde->nothrow = current_function_nothrow;
2269 args_size = old_args_size = 0;
2272 /* Output a marker (i.e. a label) for the absolute end of the generated code
2273 for a function definition. This gets called *after* the epilogue code has
2277 dwarf2out_end_epilogue ()
2280 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2282 /* Output a label to mark the endpoint of the code generated for this
2284 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2285 ASM_OUTPUT_LABEL (asm_out_file, label);
2286 fde = &fde_table[fde_table_in_use - 1];
2287 fde->dw_fde_end = xstrdup (label);
2291 dwarf2out_frame_init ()
2293 /* Allocate the initial hunk of the fde_table. */
2294 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2295 fde_table_allocated = FDE_TABLE_INCREMENT;
2296 fde_table_in_use = 0;
2298 /* Generate the CFA instructions common to all FDE's. Do it now for the
2299 sake of lookup_cfa. */
2301 #ifdef DWARF2_UNWIND_INFO
2302 /* On entry, the Canonical Frame Address is at SP. */
2303 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2304 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2309 dwarf2out_frame_finish ()
2311 /* Output call frame information. */
2312 #ifdef MIPS_DEBUGGING_INFO
2313 if (write_symbols == DWARF2_DEBUG)
2314 output_call_frame_info (0);
2315 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2316 output_call_frame_info (1);
2318 if (write_symbols == DWARF2_DEBUG
2319 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2320 output_call_frame_info (1);
2324 /* And now, the subset of the debugging information support code necessary
2325 for emitting location expressions. */
2327 typedef struct dw_val_struct *dw_val_ref;
2328 typedef struct die_struct *dw_die_ref;
2329 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2331 /* Each DIE may have a series of attribute/value pairs. Values
2332 can take on several forms. The forms that are used in this
2333 implementation are listed below. */
2340 dw_val_class_unsigned_const,
2341 dw_val_class_long_long,
2344 dw_val_class_die_ref,
2345 dw_val_class_fde_ref,
2346 dw_val_class_lbl_id,
2347 dw_val_class_lbl_offset,
2352 /* Describe a double word constant value. */
2353 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2355 typedef struct dw_long_long_struct
2362 /* Describe a floating point constant value. */
2364 typedef struct dw_fp_struct
2371 /* The dw_val_node describes an attribute's value, as it is
2372 represented internally. */
2374 typedef struct dw_val_struct
2376 dw_val_class val_class;
2380 dw_loc_descr_ref val_loc;
2382 long unsigned val_unsigned;
2383 dw_long_long_const val_long_long;
2384 dw_float_const val_float;
2389 unsigned val_fde_index;
2392 unsigned char val_flag;
2398 /* Locations in memory are described using a sequence of stack machine
2401 typedef struct dw_loc_descr_struct
2403 dw_loc_descr_ref dw_loc_next;
2404 enum dwarf_location_atom dw_loc_opc;
2405 dw_val_node dw_loc_oprnd1;
2406 dw_val_node dw_loc_oprnd2;
2411 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2412 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2415 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2417 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2418 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2419 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2420 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2422 /* Convert a DWARF stack opcode into its string name. */
2425 dwarf_stack_op_name (op)
2426 register unsigned op;
2431 return "DW_OP_addr";
2433 return "DW_OP_deref";
2435 return "DW_OP_const1u";
2437 return "DW_OP_const1s";
2439 return "DW_OP_const2u";
2441 return "DW_OP_const2s";
2443 return "DW_OP_const4u";
2445 return "DW_OP_const4s";
2447 return "DW_OP_const8u";
2449 return "DW_OP_const8s";
2451 return "DW_OP_constu";
2453 return "DW_OP_consts";
2457 return "DW_OP_drop";
2459 return "DW_OP_over";
2461 return "DW_OP_pick";
2463 return "DW_OP_swap";
2467 return "DW_OP_xderef";
2475 return "DW_OP_minus";
2487 return "DW_OP_plus";
2488 case DW_OP_plus_uconst:
2489 return "DW_OP_plus_uconst";
2495 return "DW_OP_shra";
2513 return "DW_OP_skip";
2515 return "DW_OP_lit0";
2517 return "DW_OP_lit1";
2519 return "DW_OP_lit2";
2521 return "DW_OP_lit3";
2523 return "DW_OP_lit4";
2525 return "DW_OP_lit5";
2527 return "DW_OP_lit6";
2529 return "DW_OP_lit7";
2531 return "DW_OP_lit8";
2533 return "DW_OP_lit9";
2535 return "DW_OP_lit10";
2537 return "DW_OP_lit11";
2539 return "DW_OP_lit12";
2541 return "DW_OP_lit13";
2543 return "DW_OP_lit14";
2545 return "DW_OP_lit15";
2547 return "DW_OP_lit16";
2549 return "DW_OP_lit17";
2551 return "DW_OP_lit18";
2553 return "DW_OP_lit19";
2555 return "DW_OP_lit20";
2557 return "DW_OP_lit21";
2559 return "DW_OP_lit22";
2561 return "DW_OP_lit23";
2563 return "DW_OP_lit24";
2565 return "DW_OP_lit25";
2567 return "DW_OP_lit26";
2569 return "DW_OP_lit27";
2571 return "DW_OP_lit28";
2573 return "DW_OP_lit29";
2575 return "DW_OP_lit30";
2577 return "DW_OP_lit31";
2579 return "DW_OP_reg0";
2581 return "DW_OP_reg1";
2583 return "DW_OP_reg2";
2585 return "DW_OP_reg3";
2587 return "DW_OP_reg4";
2589 return "DW_OP_reg5";
2591 return "DW_OP_reg6";
2593 return "DW_OP_reg7";
2595 return "DW_OP_reg8";
2597 return "DW_OP_reg9";
2599 return "DW_OP_reg10";
2601 return "DW_OP_reg11";
2603 return "DW_OP_reg12";
2605 return "DW_OP_reg13";
2607 return "DW_OP_reg14";
2609 return "DW_OP_reg15";
2611 return "DW_OP_reg16";
2613 return "DW_OP_reg17";
2615 return "DW_OP_reg18";
2617 return "DW_OP_reg19";
2619 return "DW_OP_reg20";
2621 return "DW_OP_reg21";
2623 return "DW_OP_reg22";
2625 return "DW_OP_reg23";
2627 return "DW_OP_reg24";
2629 return "DW_OP_reg25";
2631 return "DW_OP_reg26";
2633 return "DW_OP_reg27";
2635 return "DW_OP_reg28";
2637 return "DW_OP_reg29";
2639 return "DW_OP_reg30";
2641 return "DW_OP_reg31";
2643 return "DW_OP_breg0";
2645 return "DW_OP_breg1";
2647 return "DW_OP_breg2";
2649 return "DW_OP_breg3";
2651 return "DW_OP_breg4";
2653 return "DW_OP_breg5";
2655 return "DW_OP_breg6";
2657 return "DW_OP_breg7";
2659 return "DW_OP_breg8";
2661 return "DW_OP_breg9";
2663 return "DW_OP_breg10";
2665 return "DW_OP_breg11";
2667 return "DW_OP_breg12";
2669 return "DW_OP_breg13";
2671 return "DW_OP_breg14";
2673 return "DW_OP_breg15";
2675 return "DW_OP_breg16";
2677 return "DW_OP_breg17";
2679 return "DW_OP_breg18";
2681 return "DW_OP_breg19";
2683 return "DW_OP_breg20";
2685 return "DW_OP_breg21";
2687 return "DW_OP_breg22";
2689 return "DW_OP_breg23";
2691 return "DW_OP_breg24";
2693 return "DW_OP_breg25";
2695 return "DW_OP_breg26";
2697 return "DW_OP_breg27";
2699 return "DW_OP_breg28";
2701 return "DW_OP_breg29";
2703 return "DW_OP_breg30";
2705 return "DW_OP_breg31";
2707 return "DW_OP_regx";
2709 return "DW_OP_fbreg";
2711 return "DW_OP_bregx";
2713 return "DW_OP_piece";
2714 case DW_OP_deref_size:
2715 return "DW_OP_deref_size";
2716 case DW_OP_xderef_size:
2717 return "DW_OP_xderef_size";
2721 return "OP_<unknown>";
2725 /* Return a pointer to a newly allocated location description. Location
2726 descriptions are simple expression terms that can be strung
2727 together to form more complicated location (address) descriptions. */
2729 static inline dw_loc_descr_ref
2730 new_loc_descr (op, oprnd1, oprnd2)
2731 register enum dwarf_location_atom op;
2732 register unsigned long oprnd1;
2733 register unsigned long oprnd2;
2735 /* Use xcalloc here so we clear out all of the long_long constant in
2737 register dw_loc_descr_ref descr
2738 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2740 descr->dw_loc_opc = op;
2741 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2742 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2743 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2744 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2749 /* Add a location description term to a location description expression. */
2752 add_loc_descr (list_head, descr)
2753 register dw_loc_descr_ref *list_head;
2754 register dw_loc_descr_ref descr;
2756 register dw_loc_descr_ref *d;
2758 /* Find the end of the chain. */
2759 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2765 /* Return the size of a location descriptor. */
2767 static unsigned long
2768 size_of_loc_descr (loc)
2769 register dw_loc_descr_ref loc;
2771 register unsigned long size = 1;
2773 switch (loc->dw_loc_opc)
2776 size += DWARF2_ADDR_SIZE;
2795 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2798 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2803 case DW_OP_plus_uconst:
2804 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2842 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2845 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2848 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2851 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2852 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2855 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2857 case DW_OP_deref_size:
2858 case DW_OP_xderef_size:
2868 /* Return the size of a series of location descriptors. */
2870 static unsigned long
2872 register dw_loc_descr_ref loc;
2874 register unsigned long size = 0;
2876 for (; loc != NULL; loc = loc->dw_loc_next)
2878 loc->dw_loc_addr = size;
2879 size += size_of_loc_descr (loc);
2885 /* Output location description stack opcode's operands (if any). */
2888 output_loc_operands (loc)
2889 register dw_loc_descr_ref loc;
2891 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2892 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2894 switch (loc->dw_loc_opc)
2896 #ifdef DWARF2_DEBUGGING_INFO
2898 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
2899 fputc ('\n', asm_out_file);
2903 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2904 fputc ('\n', asm_out_file);
2908 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
2909 fputc ('\n', asm_out_file);
2914 fputc ('\n', asm_out_file);
2921 if (val1->val_class == dw_val_class_loc)
2922 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2926 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, offset);
2927 fputc ('\n', asm_out_file);
2940 /* We currently don't make any attempt to make sure these are
2941 aligned properly like we do for the main unwind info, so
2942 don't support emitting things larger than a byte if we're
2943 only doing unwinding. */
2948 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2949 fputc ('\n', asm_out_file);
2952 output_uleb128 (val1->v.val_unsigned);
2953 fputc ('\n', asm_out_file);
2956 output_sleb128 (val1->v.val_int);
2957 fputc ('\n', asm_out_file);
2960 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
2961 fputc ('\n', asm_out_file);
2963 case DW_OP_plus_uconst:
2964 output_uleb128 (val1->v.val_unsigned);
2965 fputc ('\n', asm_out_file);
2999 output_sleb128 (val1->v.val_int);
3000 fputc ('\n', asm_out_file);
3003 output_uleb128 (val1->v.val_unsigned);
3004 fputc ('\n', asm_out_file);
3007 output_sleb128 (val1->v.val_int);
3008 fputc ('\n', asm_out_file);
3011 output_uleb128 (val1->v.val_unsigned);
3012 fputc ('\n', asm_out_file);
3013 output_sleb128 (val2->v.val_int);
3014 fputc ('\n', asm_out_file);
3017 output_uleb128 (val1->v.val_unsigned);
3018 fputc ('\n', asm_out_file);
3020 case DW_OP_deref_size:
3021 case DW_OP_xderef_size:
3022 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3023 fputc ('\n', asm_out_file);
3026 /* Other codes have no operands. */
3031 /* Output a sequence of location operations. */
3034 output_loc_sequence (loc)
3035 dw_loc_descr_ref loc;
3037 for (; loc != NULL; loc = loc->dw_loc_next)
3039 /* Output the opcode. */
3040 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
3042 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
3043 dwarf_stack_op_name (loc->dw_loc_opc));
3045 fputc ('\n', asm_out_file);
3047 /* Output the operand(s) (if any). */
3048 output_loc_operands (loc);
3052 /* This routine will generate the correct assembly data for a location
3053 description based on a cfi entry with a complex address. */
3056 output_cfa_loc (cfi)
3059 dw_loc_descr_ref loc;
3062 /* Output the size of the block. */
3063 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3064 size = size_of_locs (loc);
3065 output_uleb128 (size);
3066 fputc ('\n', asm_out_file);
3068 /* Now output the operations themselves. */
3069 output_loc_sequence (loc);
3072 /* This function builds a dwarf location descriptor seqeunce from
3073 a dw_cfa_location. */
3075 static struct dw_loc_descr_struct *
3077 dw_cfa_location *cfa;
3079 struct dw_loc_descr_struct *head, *tmp;
3081 if (cfa->indirect == 0)
3084 if (cfa->base_offset)
3087 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3089 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3091 else if (cfa->reg <= 31)
3092 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3094 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3095 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3096 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3097 add_loc_descr (&head, tmp);
3098 if (cfa->offset != 0)
3100 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3101 add_loc_descr (&head, tmp);
3106 /* This function fills in aa dw_cfa_location structure from a
3107 dwarf location descriptor sequence. */
3110 get_cfa_from_loc_descr (cfa, loc)
3111 dw_cfa_location *cfa;
3112 struct dw_loc_descr_struct *loc;
3114 struct dw_loc_descr_struct *ptr;
3116 cfa->base_offset = 0;
3120 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3122 enum dwarf_location_atom op = ptr->dw_loc_opc;
3157 cfa->reg = op - DW_OP_reg0;
3160 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3194 cfa->reg = op - DW_OP_breg0;
3195 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3198 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3199 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3204 case DW_OP_plus_uconst:
3205 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3208 internal_error ("DW_LOC_OP %s not implememnted\n",
3209 dwarf_stack_op_name (ptr->dw_loc_opc));
3213 #endif /* .debug_frame support */
3215 /* And now, the support for symbolic debugging information. */
3216 #ifdef DWARF2_DEBUGGING_INFO
3218 /* NOTE: In the comments in this file, many references are made to
3219 "Debugging Information Entries". This term is abbreviated as `DIE'
3220 throughout the remainder of this file. */
3222 /* An internal representation of the DWARF output is built, and then
3223 walked to generate the DWARF debugging info. The walk of the internal
3224 representation is done after the entire program has been compiled.
3225 The types below are used to describe the internal representation. */
3227 /* Various DIE's use offsets relative to the beginning of the
3228 .debug_info section to refer to each other. */
3230 typedef long int dw_offset;
3232 /* Define typedefs here to avoid circular dependencies. */
3234 typedef struct dw_attr_struct *dw_attr_ref;
3235 typedef struct dw_line_info_struct *dw_line_info_ref;
3236 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3237 typedef struct pubname_struct *pubname_ref;
3238 typedef dw_die_ref *arange_ref;
3240 /* Each entry in the line_info_table maintains the file and
3241 line number associated with the label generated for that
3242 entry. The label gives the PC value associated with
3243 the line number entry. */
3245 typedef struct dw_line_info_struct
3247 unsigned long dw_file_num;
3248 unsigned long dw_line_num;
3252 /* Line information for functions in separate sections; each one gets its
3254 typedef struct dw_separate_line_info_struct
3256 unsigned long dw_file_num;
3257 unsigned long dw_line_num;
3258 unsigned long function;
3260 dw_separate_line_info_entry;
3262 /* Each DIE attribute has a field specifying the attribute kind,
3263 a link to the next attribute in the chain, and an attribute value.
3264 Attributes are typically linked below the DIE they modify. */
3266 typedef struct dw_attr_struct
3268 enum dwarf_attribute dw_attr;
3269 dw_attr_ref dw_attr_next;
3270 dw_val_node dw_attr_val;
3274 /* The Debugging Information Entry (DIE) structure */
3276 typedef struct die_struct
3278 enum dwarf_tag die_tag;
3280 dw_attr_ref die_attr;
3281 dw_die_ref die_parent;
3282 dw_die_ref die_child;
3284 dw_offset die_offset;
3285 unsigned long die_abbrev;
3290 /* The pubname structure */
3292 typedef struct pubname_struct
3299 /* The limbo die list structure. */
3300 typedef struct limbo_die_struct
3303 struct limbo_die_struct *next;
3307 /* How to start an assembler comment. */
3308 #ifndef ASM_COMMENT_START
3309 #define ASM_COMMENT_START ";#"
3312 /* Define a macro which returns non-zero for a TYPE_DECL which was
3313 implicitly generated for a tagged type.
3315 Note that unlike the gcc front end (which generates a NULL named
3316 TYPE_DECL node for each complete tagged type, each array type, and
3317 each function type node created) the g++ front end generates a
3318 _named_ TYPE_DECL node for each tagged type node created.
3319 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3320 generate a DW_TAG_typedef DIE for them. */
3322 #define TYPE_DECL_IS_STUB(decl) \
3323 (DECL_NAME (decl) == NULL_TREE \
3324 || (DECL_ARTIFICIAL (decl) \
3325 && is_tagged_type (TREE_TYPE (decl)) \
3326 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3327 /* This is necessary for stub decls that \
3328 appear in nested inline functions. */ \
3329 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3330 && (decl_ultimate_origin (decl) \
3331 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3333 /* Information concerning the compilation unit's programming
3334 language, and compiler version. */
3336 extern int flag_traditional;
3338 /* Fixed size portion of the DWARF compilation unit header. */
3339 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3341 /* Fixed size portion of debugging line information prolog. */
3342 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3344 /* Fixed size portion of public names info. */
3345 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3347 /* Fixed size portion of the address range info. */
3348 #define DWARF_ARANGES_HEADER_SIZE \
3349 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3350 - DWARF_OFFSET_SIZE)
3352 /* Size of padding portion in the address range info. It must be
3353 aligned to twice the pointer size. */
3354 #define DWARF_ARANGES_PAD_SIZE \
3355 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3356 - (2 * DWARF_OFFSET_SIZE + 4))
3358 /* Use assembler line directives if available. */
3359 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3360 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3361 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3363 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3367 /* Define the architecture-dependent minimum instruction length (in bytes).
3368 In this implementation of DWARF, this field is used for information
3369 purposes only. Since GCC generates assembly language, we have
3370 no a priori knowledge of how many instruction bytes are generated
3371 for each source line, and therefore can use only the DW_LNE_set_address
3372 and DW_LNS_fixed_advance_pc line information commands. */
3374 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3375 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3378 /* Minimum line offset in a special line info. opcode.
3379 This value was chosen to give a reasonable range of values. */
3380 #define DWARF_LINE_BASE -10
3382 /* First special line opcde - leave room for the standard opcodes. */
3383 #define DWARF_LINE_OPCODE_BASE 10
3385 /* Range of line offsets in a special line info. opcode. */
3386 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3388 /* Flag that indicates the initial value of the is_stmt_start flag.
3389 In the present implementation, we do not mark any lines as
3390 the beginning of a source statement, because that information
3391 is not made available by the GCC front-end. */
3392 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3394 /* This location is used by calc_die_sizes() to keep track
3395 the offset of each DIE within the .debug_info section. */
3396 static unsigned long next_die_offset;
3398 /* Record the root of the DIE's built for the current compilation unit. */
3399 static dw_die_ref comp_unit_die;
3401 /* A list of DIEs with a NULL parent waiting to be relocated. */
3402 static limbo_die_node *limbo_die_list = 0;
3404 /* Structure used by lookup_filename to manage sets of filenames. */
3410 unsigned last_lookup_index;
3413 /* Size (in elements) of increments by which we may expand the filename
3415 #define FILE_TABLE_INCREMENT 64
3417 /* Filenames referenced by declarations this compilation unit. */
3418 static struct file_table decl_file_table;
3420 /* Filenames referenced by line numbers in this compilation unit. */
3421 static struct file_table line_file_table;
3423 /* Local pointer to the name of the main input file. Initialized in
3425 static const char *primary_filename;
3427 /* A pointer to the base of a table of references to DIE's that describe
3428 declarations. The table is indexed by DECL_UID() which is a unique
3429 number identifying each decl. */
3430 static dw_die_ref *decl_die_table;
3432 /* Number of elements currently allocated for the decl_die_table. */
3433 static unsigned decl_die_table_allocated;
3435 /* Number of elements in decl_die_table currently in use. */
3436 static unsigned decl_die_table_in_use;
3438 /* Size (in elements) of increments by which we may expand the
3440 #define DECL_DIE_TABLE_INCREMENT 256
3442 /* A pointer to the base of a table of references to declaration
3443 scopes. This table is a display which tracks the nesting
3444 of declaration scopes at the current scope and containing
3445 scopes. This table is used to find the proper place to
3446 define type declaration DIE's. */
3447 static tree *decl_scope_table;
3449 /* Number of elements currently allocated for the decl_scope_table. */
3450 static int decl_scope_table_allocated;
3452 /* Current level of nesting of declaration scopes. */
3453 static int decl_scope_depth;
3455 /* Size (in elements) of increments by which we may expand the
3456 decl_scope_table. */
3457 #define DECL_SCOPE_TABLE_INCREMENT 64
3459 /* A pointer to the base of a list of references to DIE's that
3460 are uniquely identified by their tag, presence/absence of
3461 children DIE's, and list of attribute/value pairs. */
3462 static dw_die_ref *abbrev_die_table;
3464 /* Number of elements currently allocated for abbrev_die_table. */
3465 static unsigned abbrev_die_table_allocated;
3467 /* Number of elements in type_die_table currently in use. */
3468 static unsigned abbrev_die_table_in_use;
3470 /* Size (in elements) of increments by which we may expand the
3471 abbrev_die_table. */
3472 #define ABBREV_DIE_TABLE_INCREMENT 256
3474 /* A pointer to the base of a table that contains line information
3475 for each source code line in .text in the compilation unit. */
3476 static dw_line_info_ref line_info_table;
3478 /* Number of elements currently allocated for line_info_table. */
3479 static unsigned line_info_table_allocated;
3481 /* Number of elements in separate_line_info_table currently in use. */
3482 static unsigned separate_line_info_table_in_use;
3484 /* A pointer to the base of a table that contains line information
3485 for each source code line outside of .text in the compilation unit. */
3486 static dw_separate_line_info_ref separate_line_info_table;
3488 /* Number of elements currently allocated for separate_line_info_table. */
3489 static unsigned separate_line_info_table_allocated;
3491 /* Number of elements in line_info_table currently in use. */
3492 static unsigned line_info_table_in_use;
3494 /* Size (in elements) of increments by which we may expand the
3496 #define LINE_INFO_TABLE_INCREMENT 1024
3498 /* A pointer to the base of a table that contains a list of publicly
3499 accessible names. */
3500 static pubname_ref pubname_table;
3502 /* Number of elements currently allocated for pubname_table. */
3503 static unsigned pubname_table_allocated;
3505 /* Number of elements in pubname_table currently in use. */
3506 static unsigned pubname_table_in_use;
3508 /* Size (in elements) of increments by which we may expand the
3510 #define PUBNAME_TABLE_INCREMENT 64
3512 /* A pointer to the base of a table that contains a list of publicly
3513 accessible names. */
3514 static arange_ref arange_table;
3516 /* Number of elements currently allocated for arange_table. */
3517 static unsigned arange_table_allocated;
3519 /* Number of elements in arange_table currently in use. */
3520 static unsigned arange_table_in_use;
3522 /* Size (in elements) of increments by which we may expand the
3524 #define ARANGE_TABLE_INCREMENT 64
3526 /* A pointer to the base of a list of incomplete types which might be
3527 completed at some later time. */
3529 static tree *incomplete_types_list;
3531 /* Number of elements currently allocated for the incomplete_types_list. */
3532 static unsigned incomplete_types_allocated;
3534 /* Number of elements of incomplete_types_list currently in use. */
3535 static unsigned incomplete_types;
3537 /* Size (in elements) of increments by which we may expand the incomplete
3538 types list. Actually, a single hunk of space of this size should
3539 be enough for most typical programs. */
3540 #define INCOMPLETE_TYPES_INCREMENT 64
3542 /* Record whether the function being analyzed contains inlined functions. */
3543 static int current_function_has_inlines;
3544 #if 0 && defined (MIPS_DEBUGGING_INFO)
3545 static int comp_unit_has_inlines;
3548 /* Array of RTXes referenced by the debugging information, which therefore
3549 must be kept around forever. We do this rather than perform GC on
3550 the dwarf info because almost all of the dwarf info lives forever, and
3551 it's easier to support non-GC frontends this way. */
3552 static varray_type used_rtx_varray;
3554 /* Forward declarations for functions defined in this file. */
3556 static int is_pseudo_reg PARAMS ((rtx));
3557 static tree type_main_variant PARAMS ((tree));
3558 static int is_tagged_type PARAMS ((tree));
3559 static const char *dwarf_tag_name PARAMS ((unsigned));
3560 static const char *dwarf_attr_name PARAMS ((unsigned));
3561 static const char *dwarf_form_name PARAMS ((unsigned));
3563 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3565 static tree decl_ultimate_origin PARAMS ((tree));
3566 static tree block_ultimate_origin PARAMS ((tree));
3567 static tree decl_class_context PARAMS ((tree));
3568 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3569 static void add_AT_flag PARAMS ((dw_die_ref,
3570 enum dwarf_attribute,
3572 static void add_AT_int PARAMS ((dw_die_ref,
3573 enum dwarf_attribute, long));
3574 static void add_AT_unsigned PARAMS ((dw_die_ref,
3575 enum dwarf_attribute,
3577 static void add_AT_long_long PARAMS ((dw_die_ref,
3578 enum dwarf_attribute,
3581 static void add_AT_float PARAMS ((dw_die_ref,
3582 enum dwarf_attribute,
3584 static void add_AT_string PARAMS ((dw_die_ref,
3585 enum dwarf_attribute,
3587 static void add_AT_die_ref PARAMS ((dw_die_ref,
3588 enum dwarf_attribute,
3590 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3591 enum dwarf_attribute,
3593 static void add_AT_loc PARAMS ((dw_die_ref,
3594 enum dwarf_attribute,
3596 static void add_AT_addr PARAMS ((dw_die_ref,
3597 enum dwarf_attribute,
3599 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3600 enum dwarf_attribute,
3602 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3603 enum dwarf_attribute,
3605 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3606 enum dwarf_attribute));
3607 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3608 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3609 static const char *get_AT_string PARAMS ((dw_die_ref,
3610 enum dwarf_attribute));
3611 static int get_AT_flag PARAMS ((dw_die_ref,
3612 enum dwarf_attribute));
3613 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3614 enum dwarf_attribute));
3615 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3616 enum dwarf_attribute));
3617 static int is_c_family PARAMS ((void));
3618 static int is_java PARAMS ((void));
3619 static int is_fortran PARAMS ((void));
3620 static void remove_AT PARAMS ((dw_die_ref,
3621 enum dwarf_attribute));
3622 static void remove_children PARAMS ((dw_die_ref));
3623 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3624 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3625 static dw_die_ref lookup_type_die PARAMS ((tree));
3626 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3627 static dw_die_ref lookup_decl_die PARAMS ((tree));
3628 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3629 static void print_spaces PARAMS ((FILE *));
3630 static void print_die PARAMS ((dw_die_ref, FILE *));
3631 static void print_dwarf_line_table PARAMS ((FILE *));
3632 static void reverse_die_lists PARAMS ((dw_die_ref));
3633 static void reverse_all_dies PARAMS ((dw_die_ref));
3634 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3635 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3636 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3637 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3638 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3639 static void compute_section_prefix PARAMS ((dw_die_ref));
3640 static int is_type_die PARAMS ((dw_die_ref));
3641 static int is_comdat_die PARAMS ((dw_die_ref));
3642 static int is_symbol_die PARAMS ((dw_die_ref));
3643 static char *gen_internal_sym PARAMS ((void));
3644 static void assign_symbol_names PARAMS ((dw_die_ref));
3645 static void break_out_includes PARAMS ((dw_die_ref));
3646 static void add_sibling_attributes PARAMS ((dw_die_ref));
3647 static void build_abbrev_table PARAMS ((dw_die_ref));
3648 static unsigned long size_of_string PARAMS ((const char *));
3649 static int constant_size PARAMS ((long unsigned));
3650 static unsigned long size_of_die PARAMS ((dw_die_ref));
3651 static void calc_die_sizes PARAMS ((dw_die_ref));
3652 static void mark_dies PARAMS ((dw_die_ref));
3653 static void unmark_dies PARAMS ((dw_die_ref));
3654 static unsigned long size_of_line_prolog PARAMS ((void));
3655 static unsigned long size_of_pubnames PARAMS ((void));
3656 static unsigned long size_of_aranges PARAMS ((void));
3657 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3658 static void output_value_format PARAMS ((dw_attr_ref));
3659 static void output_abbrev_section PARAMS ((void));
3660 static void output_die_symbol PARAMS ((dw_die_ref));
3661 static void output_symbolic_ref PARAMS ((dw_die_ref));
3662 static void output_die PARAMS ((dw_die_ref));
3663 static void output_compilation_unit_header PARAMS ((void));
3664 static void output_comp_unit PARAMS ((dw_die_ref));
3665 static const char *dwarf2_name PARAMS ((tree, int));
3666 static void add_pubname PARAMS ((tree, dw_die_ref));
3667 static void output_pubnames PARAMS ((void));
3668 static void add_arange PARAMS ((tree, dw_die_ref));
3669 static void output_aranges PARAMS ((void));
3670 static void output_line_info PARAMS ((void));
3671 static void output_file_names PARAMS ((void));
3672 static dw_die_ref base_type_die PARAMS ((tree));
3673 static tree root_type PARAMS ((tree));
3674 static int is_base_type PARAMS ((tree));
3675 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3676 static int type_is_enum PARAMS ((tree));
3677 static unsigned int reg_number PARAMS ((rtx));
3678 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3679 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3680 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3681 static int is_based_loc PARAMS ((rtx));
3682 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3683 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3684 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3685 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3686 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3687 static tree field_type PARAMS ((tree));
3688 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3689 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3690 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3691 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3692 static void add_AT_location_description PARAMS ((dw_die_ref,
3693 enum dwarf_attribute, rtx));
3694 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3695 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3696 static rtx rtl_for_decl_location PARAMS ((tree));
3697 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3698 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3699 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3700 static void add_bound_info PARAMS ((dw_die_ref,
3701 enum dwarf_attribute, tree));
3702 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3703 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3704 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3705 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3706 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3707 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3708 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3709 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3710 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3711 static void push_decl_scope PARAMS ((tree));
3712 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3713 static void pop_decl_scope PARAMS ((void));
3714 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3716 static const char *type_tag PARAMS ((tree));
3717 static tree member_declared_type PARAMS ((tree));
3719 static const char *decl_start_label PARAMS ((tree));
3721 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3722 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3724 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3726 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3727 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3728 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3729 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3730 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3731 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3732 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3733 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3734 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3735 static void gen_label_die PARAMS ((tree, dw_die_ref));
3736 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3737 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3738 static void gen_field_die PARAMS ((tree, dw_die_ref));
3739 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3740 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3741 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3742 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3743 static void gen_member_die PARAMS ((tree, dw_die_ref));
3744 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3745 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3746 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3747 static void gen_type_die PARAMS ((tree, dw_die_ref));
3748 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3749 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3750 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3751 static int is_redundant_typedef PARAMS ((tree));
3752 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3753 static unsigned lookup_filename PARAMS ((struct file_table *,
3755 static void init_file_table PARAMS ((struct file_table *));
3756 static void add_incomplete_type PARAMS ((tree));
3757 static void retry_incomplete_types PARAMS ((void));
3758 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3759 static void gen_abstract_function PARAMS ((tree));
3760 static rtx save_rtx PARAMS ((rtx));
3761 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3762 static int file_info_cmp PARAMS ((const void *, const void *));
3764 /* Section names used to hold DWARF debugging information. */
3765 #ifndef DEBUG_INFO_SECTION
3766 #define DEBUG_INFO_SECTION ".debug_info"
3768 #ifndef ABBREV_SECTION
3769 #define ABBREV_SECTION ".debug_abbrev"
3771 #ifndef ARANGES_SECTION
3772 #define ARANGES_SECTION ".debug_aranges"
3774 #ifndef DW_MACINFO_SECTION
3775 #define DW_MACINFO_SECTION ".debug_macinfo"
3777 #ifndef DEBUG_LINE_SECTION
3778 #define DEBUG_LINE_SECTION ".debug_line"
3781 #define LOC_SECTION ".debug_loc"
3783 #ifndef PUBNAMES_SECTION
3784 #define PUBNAMES_SECTION ".debug_pubnames"
3787 #define STR_SECTION ".debug_str"
3790 /* Standard ELF section names for compiled code and data. */
3791 #ifndef TEXT_SECTION
3792 #define TEXT_SECTION ".text"
3794 #ifndef DATA_SECTION
3795 #define DATA_SECTION ".data"
3798 #define BSS_SECTION ".bss"
3801 /* Labels we insert at beginning sections we can reference instead of
3802 the section names themselves. */
3804 #ifndef TEXT_SECTION_LABEL
3805 #define TEXT_SECTION_LABEL "Ltext"
3807 #ifndef DEBUG_LINE_SECTION_LABEL
3808 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3810 #ifndef DEBUG_INFO_SECTION_LABEL
3811 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3813 #ifndef ABBREV_SECTION_LABEL
3814 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3817 /* Definitions of defaults for formats and names of various special
3818 (artificial) labels which may be generated within this file (when the -g
3819 options is used and DWARF_DEBUGGING_INFO is in effect.
3820 If necessary, these may be overridden from within the tm.h file, but
3821 typically, overriding these defaults is unnecessary. */
3823 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3824 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3825 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3826 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3827 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3829 #ifndef TEXT_END_LABEL
3830 #define TEXT_END_LABEL "Letext"
3832 #ifndef DATA_END_LABEL
3833 #define DATA_END_LABEL "Ledata"
3835 #ifndef BSS_END_LABEL
3836 #define BSS_END_LABEL "Lebss"
3838 #ifndef BLOCK_BEGIN_LABEL
3839 #define BLOCK_BEGIN_LABEL "LBB"
3841 #ifndef BLOCK_END_LABEL
3842 #define BLOCK_END_LABEL "LBE"
3844 #ifndef BODY_BEGIN_LABEL
3845 #define BODY_BEGIN_LABEL "Lbb"
3847 #ifndef BODY_END_LABEL
3848 #define BODY_END_LABEL "Lbe"
3850 #ifndef LINE_CODE_LABEL
3851 #define LINE_CODE_LABEL "LM"
3853 #ifndef SEPARATE_LINE_CODE_LABEL
3854 #define SEPARATE_LINE_CODE_LABEL "LSM"
3857 /* We allow a language front-end to designate a function that is to be
3858 called to "demangle" any name before it it put into a DIE. */
3860 static const char *(*demangle_name_func) PARAMS ((const char *));
3863 dwarf2out_set_demangle_name_func (func)
3864 const char *(*func) PARAMS ((const char *));
3866 demangle_name_func = func;
3869 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3870 that means adding it to used_rtx_varray. If not, that means making
3871 a copy on the permanent_obstack. */
3877 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3882 /* Test if rtl node points to a pseudo register. */
3888 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3889 || (GET_CODE (rtl) == SUBREG
3890 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3893 /* Return a reference to a type, with its const and volatile qualifiers
3897 type_main_variant (type)
3900 type = TYPE_MAIN_VARIANT (type);
3902 /* There really should be only one main variant among any group of variants
3903 of a given type (and all of the MAIN_VARIANT values for all members of
3904 the group should point to that one type) but sometimes the C front-end
3905 messes this up for array types, so we work around that bug here. */
3907 if (TREE_CODE (type) == ARRAY_TYPE)
3908 while (type != TYPE_MAIN_VARIANT (type))
3909 type = TYPE_MAIN_VARIANT (type);
3914 /* Return non-zero if the given type node represents a tagged type. */
3917 is_tagged_type (type)
3920 register enum tree_code code = TREE_CODE (type);
3922 return (code == RECORD_TYPE || code == UNION_TYPE
3923 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3926 /* Convert a DIE tag into its string name. */
3929 dwarf_tag_name (tag)
3930 register unsigned tag;
3934 case DW_TAG_padding:
3935 return "DW_TAG_padding";
3936 case DW_TAG_array_type:
3937 return "DW_TAG_array_type";
3938 case DW_TAG_class_type:
3939 return "DW_TAG_class_type";
3940 case DW_TAG_entry_point:
3941 return "DW_TAG_entry_point";
3942 case DW_TAG_enumeration_type:
3943 return "DW_TAG_enumeration_type";
3944 case DW_TAG_formal_parameter:
3945 return "DW_TAG_formal_parameter";
3946 case DW_TAG_imported_declaration:
3947 return "DW_TAG_imported_declaration";
3949 return "DW_TAG_label";
3950 case DW_TAG_lexical_block:
3951 return "DW_TAG_lexical_block";
3953 return "DW_TAG_member";
3954 case DW_TAG_pointer_type:
3955 return "DW_TAG_pointer_type";
3956 case DW_TAG_reference_type:
3957 return "DW_TAG_reference_type";
3958 case DW_TAG_compile_unit:
3959 return "DW_TAG_compile_unit";
3960 case DW_TAG_string_type:
3961 return "DW_TAG_string_type";
3962 case DW_TAG_structure_type:
3963 return "DW_TAG_structure_type";
3964 case DW_TAG_subroutine_type:
3965 return "DW_TAG_subroutine_type";
3966 case DW_TAG_typedef:
3967 return "DW_TAG_typedef";
3968 case DW_TAG_union_type:
3969 return "DW_TAG_union_type";
3970 case DW_TAG_unspecified_parameters:
3971 return "DW_TAG_unspecified_parameters";
3972 case DW_TAG_variant:
3973 return "DW_TAG_variant";
3974 case DW_TAG_common_block:
3975 return "DW_TAG_common_block";
3976 case DW_TAG_common_inclusion:
3977 return "DW_TAG_common_inclusion";
3978 case DW_TAG_inheritance:
3979 return "DW_TAG_inheritance";
3980 case DW_TAG_inlined_subroutine:
3981 return "DW_TAG_inlined_subroutine";
3983 return "DW_TAG_module";
3984 case DW_TAG_ptr_to_member_type:
3985 return "DW_TAG_ptr_to_member_type";
3986 case DW_TAG_set_type:
3987 return "DW_TAG_set_type";
3988 case DW_TAG_subrange_type:
3989 return "DW_TAG_subrange_type";
3990 case DW_TAG_with_stmt:
3991 return "DW_TAG_with_stmt";
3992 case DW_TAG_access_declaration:
3993 return "DW_TAG_access_declaration";
3994 case DW_TAG_base_type:
3995 return "DW_TAG_base_type";
3996 case DW_TAG_catch_block:
3997 return "DW_TAG_catch_block";
3998 case DW_TAG_const_type:
3999 return "DW_TAG_const_type";
4000 case DW_TAG_constant:
4001 return "DW_TAG_constant";
4002 case DW_TAG_enumerator:
4003 return "DW_TAG_enumerator";
4004 case DW_TAG_file_type:
4005 return "DW_TAG_file_type";
4007 return "DW_TAG_friend";
4008 case DW_TAG_namelist:
4009 return "DW_TAG_namelist";
4010 case DW_TAG_namelist_item:
4011 return "DW_TAG_namelist_item";
4012 case DW_TAG_packed_type:
4013 return "DW_TAG_packed_type";
4014 case DW_TAG_subprogram:
4015 return "DW_TAG_subprogram";
4016 case DW_TAG_template_type_param:
4017 return "DW_TAG_template_type_param";
4018 case DW_TAG_template_value_param:
4019 return "DW_TAG_template_value_param";
4020 case DW_TAG_thrown_type:
4021 return "DW_TAG_thrown_type";
4022 case DW_TAG_try_block:
4023 return "DW_TAG_try_block";
4024 case DW_TAG_variant_part:
4025 return "DW_TAG_variant_part";
4026 case DW_TAG_variable:
4027 return "DW_TAG_variable";
4028 case DW_TAG_volatile_type:
4029 return "DW_TAG_volatile_type";
4030 case DW_TAG_MIPS_loop:
4031 return "DW_TAG_MIPS_loop";
4032 case DW_TAG_format_label:
4033 return "DW_TAG_format_label";
4034 case DW_TAG_function_template:
4035 return "DW_TAG_function_template";
4036 case DW_TAG_class_template:
4037 return "DW_TAG_class_template";
4038 case DW_TAG_GNU_BINCL:
4039 return "DW_TAG_GNU_BINCL";
4040 case DW_TAG_GNU_EINCL:
4041 return "DW_TAG_GNU_EINCL";
4043 return "DW_TAG_<unknown>";
4047 /* Convert a DWARF attribute code into its string name. */
4050 dwarf_attr_name (attr)
4051 register unsigned attr;
4056 return "DW_AT_sibling";
4057 case DW_AT_location:
4058 return "DW_AT_location";
4060 return "DW_AT_name";
4061 case DW_AT_ordering:
4062 return "DW_AT_ordering";
4063 case DW_AT_subscr_data:
4064 return "DW_AT_subscr_data";
4065 case DW_AT_byte_size:
4066 return "DW_AT_byte_size";
4067 case DW_AT_bit_offset:
4068 return "DW_AT_bit_offset";
4069 case DW_AT_bit_size:
4070 return "DW_AT_bit_size";
4071 case DW_AT_element_list:
4072 return "DW_AT_element_list";
4073 case DW_AT_stmt_list:
4074 return "DW_AT_stmt_list";
4076 return "DW_AT_low_pc";
4078 return "DW_AT_high_pc";
4079 case DW_AT_language:
4080 return "DW_AT_language";
4082 return "DW_AT_member";
4084 return "DW_AT_discr";
4085 case DW_AT_discr_value:
4086 return "DW_AT_discr_value";
4087 case DW_AT_visibility:
4088 return "DW_AT_visibility";
4090 return "DW_AT_import";
4091 case DW_AT_string_length:
4092 return "DW_AT_string_length";
4093 case DW_AT_common_reference:
4094 return "DW_AT_common_reference";
4095 case DW_AT_comp_dir:
4096 return "DW_AT_comp_dir";
4097 case DW_AT_const_value:
4098 return "DW_AT_const_value";
4099 case DW_AT_containing_type:
4100 return "DW_AT_containing_type";
4101 case DW_AT_default_value:
4102 return "DW_AT_default_value";
4104 return "DW_AT_inline";
4105 case DW_AT_is_optional:
4106 return "DW_AT_is_optional";
4107 case DW_AT_lower_bound:
4108 return "DW_AT_lower_bound";
4109 case DW_AT_producer:
4110 return "DW_AT_producer";
4111 case DW_AT_prototyped:
4112 return "DW_AT_prototyped";
4113 case DW_AT_return_addr:
4114 return "DW_AT_return_addr";
4115 case DW_AT_start_scope:
4116 return "DW_AT_start_scope";
4117 case DW_AT_stride_size:
4118 return "DW_AT_stride_size";
4119 case DW_AT_upper_bound:
4120 return "DW_AT_upper_bound";
4121 case DW_AT_abstract_origin:
4122 return "DW_AT_abstract_origin";
4123 case DW_AT_accessibility:
4124 return "DW_AT_accessibility";
4125 case DW_AT_address_class:
4126 return "DW_AT_address_class";
4127 case DW_AT_artificial:
4128 return "DW_AT_artificial";
4129 case DW_AT_base_types:
4130 return "DW_AT_base_types";
4131 case DW_AT_calling_convention:
4132 return "DW_AT_calling_convention";
4134 return "DW_AT_count";
4135 case DW_AT_data_member_location:
4136 return "DW_AT_data_member_location";
4137 case DW_AT_decl_column:
4138 return "DW_AT_decl_column";
4139 case DW_AT_decl_file:
4140 return "DW_AT_decl_file";
4141 case DW_AT_decl_line:
4142 return "DW_AT_decl_line";
4143 case DW_AT_declaration:
4144 return "DW_AT_declaration";
4145 case DW_AT_discr_list:
4146 return "DW_AT_discr_list";
4147 case DW_AT_encoding:
4148 return "DW_AT_encoding";
4149 case DW_AT_external:
4150 return "DW_AT_external";
4151 case DW_AT_frame_base:
4152 return "DW_AT_frame_base";
4154 return "DW_AT_friend";
4155 case DW_AT_identifier_case:
4156 return "DW_AT_identifier_case";
4157 case DW_AT_macro_info:
4158 return "DW_AT_macro_info";
4159 case DW_AT_namelist_items:
4160 return "DW_AT_namelist_items";
4161 case DW_AT_priority:
4162 return "DW_AT_priority";
4164 return "DW_AT_segment";
4165 case DW_AT_specification:
4166 return "DW_AT_specification";
4167 case DW_AT_static_link:
4168 return "DW_AT_static_link";
4170 return "DW_AT_type";
4171 case DW_AT_use_location:
4172 return "DW_AT_use_location";
4173 case DW_AT_variable_parameter:
4174 return "DW_AT_variable_parameter";
4175 case DW_AT_virtuality:
4176 return "DW_AT_virtuality";
4177 case DW_AT_vtable_elem_location:
4178 return "DW_AT_vtable_elem_location";
4180 case DW_AT_MIPS_fde:
4181 return "DW_AT_MIPS_fde";
4182 case DW_AT_MIPS_loop_begin:
4183 return "DW_AT_MIPS_loop_begin";
4184 case DW_AT_MIPS_tail_loop_begin:
4185 return "DW_AT_MIPS_tail_loop_begin";
4186 case DW_AT_MIPS_epilog_begin:
4187 return "DW_AT_MIPS_epilog_begin";
4188 case DW_AT_MIPS_loop_unroll_factor:
4189 return "DW_AT_MIPS_loop_unroll_factor";
4190 case DW_AT_MIPS_software_pipeline_depth:
4191 return "DW_AT_MIPS_software_pipeline_depth";
4192 case DW_AT_MIPS_linkage_name:
4193 return "DW_AT_MIPS_linkage_name";
4194 case DW_AT_MIPS_stride:
4195 return "DW_AT_MIPS_stride";
4196 case DW_AT_MIPS_abstract_name:
4197 return "DW_AT_MIPS_abstract_name";
4198 case DW_AT_MIPS_clone_origin:
4199 return "DW_AT_MIPS_clone_origin";
4200 case DW_AT_MIPS_has_inlines:
4201 return "DW_AT_MIPS_has_inlines";
4203 case DW_AT_sf_names:
4204 return "DW_AT_sf_names";
4205 case DW_AT_src_info:
4206 return "DW_AT_src_info";
4207 case DW_AT_mac_info:
4208 return "DW_AT_mac_info";
4209 case DW_AT_src_coords:
4210 return "DW_AT_src_coords";
4211 case DW_AT_body_begin:
4212 return "DW_AT_body_begin";
4213 case DW_AT_body_end:
4214 return "DW_AT_body_end";
4216 return "DW_AT_<unknown>";
4220 /* Convert a DWARF value form code into its string name. */
4223 dwarf_form_name (form)
4224 register unsigned form;
4229 return "DW_FORM_addr";
4230 case DW_FORM_block2:
4231 return "DW_FORM_block2";
4232 case DW_FORM_block4:
4233 return "DW_FORM_block4";
4235 return "DW_FORM_data2";
4237 return "DW_FORM_data4";
4239 return "DW_FORM_data8";
4240 case DW_FORM_string:
4241 return "DW_FORM_string";
4243 return "DW_FORM_block";
4244 case DW_FORM_block1:
4245 return "DW_FORM_block1";
4247 return "DW_FORM_data1";
4249 return "DW_FORM_flag";
4251 return "DW_FORM_sdata";
4253 return "DW_FORM_strp";
4255 return "DW_FORM_udata";
4256 case DW_FORM_ref_addr:
4257 return "DW_FORM_ref_addr";
4259 return "DW_FORM_ref1";
4261 return "DW_FORM_ref2";
4263 return "DW_FORM_ref4";
4265 return "DW_FORM_ref8";
4266 case DW_FORM_ref_udata:
4267 return "DW_FORM_ref_udata";
4268 case DW_FORM_indirect:
4269 return "DW_FORM_indirect";
4271 return "DW_FORM_<unknown>";
4275 /* Convert a DWARF type code into its string name. */
4279 dwarf_type_encoding_name (enc)
4280 register unsigned enc;
4284 case DW_ATE_address:
4285 return "DW_ATE_address";
4286 case DW_ATE_boolean:
4287 return "DW_ATE_boolean";
4288 case DW_ATE_complex_float:
4289 return "DW_ATE_complex_float";
4291 return "DW_ATE_float";
4293 return "DW_ATE_signed";
4294 case DW_ATE_signed_char:
4295 return "DW_ATE_signed_char";
4296 case DW_ATE_unsigned:
4297 return "DW_ATE_unsigned";
4298 case DW_ATE_unsigned_char:
4299 return "DW_ATE_unsigned_char";
4301 return "DW_ATE_<unknown>";
4306 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4307 instance of an inlined instance of a decl which is local to an inline
4308 function, so we have to trace all of the way back through the origin chain
4309 to find out what sort of node actually served as the original seed for the
4313 decl_ultimate_origin (decl)
4316 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4317 nodes in the function to point to themselves; ignore that if
4318 we're trying to output the abstract instance of this function. */
4319 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4322 #ifdef ENABLE_CHECKING
4323 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4324 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4325 most distant ancestor, this should never happen. */
4329 return DECL_ABSTRACT_ORIGIN (decl);
4332 /* Determine the "ultimate origin" of a block. The block may be an inlined
4333 instance of an inlined instance of a block which is local to an inline
4334 function, so we have to trace all of the way back through the origin chain
4335 to find out what sort of node actually served as the original seed for the
4339 block_ultimate_origin (block)
4340 register tree block;
4342 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4344 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4345 nodes in the function to point to themselves; ignore that if
4346 we're trying to output the abstract instance of this function. */
4347 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4350 if (immediate_origin == NULL_TREE)
4354 register tree ret_val;
4355 register tree lookahead = immediate_origin;
4359 ret_val = lookahead;
4360 lookahead = (TREE_CODE (ret_val) == BLOCK)
4361 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4364 while (lookahead != NULL && lookahead != ret_val);
4370 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4371 of a virtual function may refer to a base class, so we check the 'this'
4375 decl_class_context (decl)
4378 tree context = NULL_TREE;
4380 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4381 context = DECL_CONTEXT (decl);
4383 context = TYPE_MAIN_VARIANT
4384 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4386 if (context && !TYPE_P (context))
4387 context = NULL_TREE;
4392 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4393 addition order, and correct that in reverse_all_dies. */
4396 add_dwarf_attr (die, attr)
4397 register dw_die_ref die;
4398 register dw_attr_ref attr;
4400 if (die != NULL && attr != NULL)
4402 attr->dw_attr_next = die->die_attr;
4403 die->die_attr = attr;
4407 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4408 static inline dw_val_class
4412 return a->dw_attr_val.val_class;
4415 /* Add a flag value attribute to a DIE. */
4418 add_AT_flag (die, attr_kind, flag)
4419 register dw_die_ref die;
4420 register enum dwarf_attribute attr_kind;
4421 register unsigned flag;
4423 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4425 attr->dw_attr_next = NULL;
4426 attr->dw_attr = attr_kind;
4427 attr->dw_attr_val.val_class = dw_val_class_flag;
4428 attr->dw_attr_val.v.val_flag = flag;
4429 add_dwarf_attr (die, attr);
4432 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4433 static inline unsigned
4435 register dw_attr_ref a;
4437 if (a && AT_class (a) == dw_val_class_flag)
4438 return a->dw_attr_val.v.val_flag;
4443 /* Add a signed integer attribute value to a DIE. */
4446 add_AT_int (die, attr_kind, int_val)
4447 register dw_die_ref die;
4448 register enum dwarf_attribute attr_kind;
4449 register long int int_val;
4451 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4453 attr->dw_attr_next = NULL;
4454 attr->dw_attr = attr_kind;
4455 attr->dw_attr_val.val_class = dw_val_class_const;
4456 attr->dw_attr_val.v.val_int = int_val;
4457 add_dwarf_attr (die, attr);
4460 static inline long int AT_int PARAMS ((dw_attr_ref));
4461 static inline long int
4463 register dw_attr_ref a;
4465 if (a && AT_class (a) == dw_val_class_const)
4466 return a->dw_attr_val.v.val_int;
4471 /* Add an unsigned integer attribute value to a DIE. */
4474 add_AT_unsigned (die, attr_kind, unsigned_val)
4475 register dw_die_ref die;
4476 register enum dwarf_attribute attr_kind;
4477 register unsigned long unsigned_val;
4479 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4481 attr->dw_attr_next = NULL;
4482 attr->dw_attr = attr_kind;
4483 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4484 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4485 add_dwarf_attr (die, attr);
4488 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4489 static inline unsigned long
4491 register dw_attr_ref a;
4493 if (a && AT_class (a) == dw_val_class_unsigned_const)
4494 return a->dw_attr_val.v.val_unsigned;
4499 /* Add an unsigned double integer attribute value to a DIE. */
4502 add_AT_long_long (die, attr_kind, val_hi, val_low)
4503 register dw_die_ref die;
4504 register enum dwarf_attribute attr_kind;
4505 register unsigned long val_hi;
4506 register unsigned long val_low;
4508 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4510 attr->dw_attr_next = NULL;
4511 attr->dw_attr = attr_kind;
4512 attr->dw_attr_val.val_class = dw_val_class_long_long;
4513 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4514 attr->dw_attr_val.v.val_long_long.low = val_low;
4515 add_dwarf_attr (die, attr);
4518 /* Add a floating point attribute value to a DIE and return it. */
4521 add_AT_float (die, attr_kind, length, array)
4522 register dw_die_ref die;
4523 register enum dwarf_attribute attr_kind;
4524 register unsigned length;
4525 register long *array;
4527 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4529 attr->dw_attr_next = NULL;
4530 attr->dw_attr = attr_kind;
4531 attr->dw_attr_val.val_class = dw_val_class_float;
4532 attr->dw_attr_val.v.val_float.length = length;
4533 attr->dw_attr_val.v.val_float.array = array;
4534 add_dwarf_attr (die, attr);
4537 /* Add a string attribute value to a DIE. */
4540 add_AT_string (die, attr_kind, str)
4541 register dw_die_ref die;
4542 register enum dwarf_attribute attr_kind;
4543 register const char *str;
4545 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4547 attr->dw_attr_next = NULL;
4548 attr->dw_attr = attr_kind;
4549 attr->dw_attr_val.val_class = dw_val_class_str;
4550 attr->dw_attr_val.v.val_str = xstrdup (str);
4551 add_dwarf_attr (die, attr);
4554 static inline const char *AT_string PARAMS ((dw_attr_ref));
4555 static inline const char *
4557 register dw_attr_ref a;
4559 if (a && AT_class (a) == dw_val_class_str)
4560 return a->dw_attr_val.v.val_str;
4565 /* Add a DIE reference attribute value to a DIE. */
4568 add_AT_die_ref (die, attr_kind, targ_die)
4569 register dw_die_ref die;
4570 register enum dwarf_attribute attr_kind;
4571 register dw_die_ref targ_die;
4573 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4575 attr->dw_attr_next = NULL;
4576 attr->dw_attr = attr_kind;
4577 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4578 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4579 attr->dw_attr_val.v.val_die_ref.external = 0;
4580 add_dwarf_attr (die, attr);
4583 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4584 static inline dw_die_ref
4586 register dw_attr_ref a;
4588 if (a && AT_class (a) == dw_val_class_die_ref)
4589 return a->dw_attr_val.v.val_die_ref.die;
4594 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4597 register dw_attr_ref a;
4599 if (a && AT_class (a) == dw_val_class_die_ref)
4600 return a->dw_attr_val.v.val_die_ref.external;
4605 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4607 set_AT_ref_external (a, i)
4608 register dw_attr_ref a;
4611 if (a && AT_class (a) == dw_val_class_die_ref)
4612 a->dw_attr_val.v.val_die_ref.external = i;
4617 /* Add an FDE reference attribute value to a DIE. */
4620 add_AT_fde_ref (die, attr_kind, targ_fde)
4621 register dw_die_ref die;
4622 register enum dwarf_attribute attr_kind;
4623 register unsigned targ_fde;
4625 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4627 attr->dw_attr_next = NULL;
4628 attr->dw_attr = attr_kind;
4629 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4630 attr->dw_attr_val.v.val_fde_index = targ_fde;
4631 add_dwarf_attr (die, attr);
4634 /* Add a location description attribute value to a DIE. */
4637 add_AT_loc (die, attr_kind, loc)
4638 register dw_die_ref die;
4639 register enum dwarf_attribute attr_kind;
4640 register dw_loc_descr_ref loc;
4642 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4644 attr->dw_attr_next = NULL;
4645 attr->dw_attr = attr_kind;
4646 attr->dw_attr_val.val_class = dw_val_class_loc;
4647 attr->dw_attr_val.v.val_loc = loc;
4648 add_dwarf_attr (die, attr);
4651 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4652 static inline dw_loc_descr_ref
4654 register dw_attr_ref a;
4656 if (a && AT_class (a) == dw_val_class_loc)
4657 return a->dw_attr_val.v.val_loc;
4662 /* Add an address constant attribute value to a DIE. */
4665 add_AT_addr (die, attr_kind, addr)
4666 register dw_die_ref die;
4667 register enum dwarf_attribute attr_kind;
4670 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4672 attr->dw_attr_next = NULL;
4673 attr->dw_attr = attr_kind;
4674 attr->dw_attr_val.val_class = dw_val_class_addr;
4675 attr->dw_attr_val.v.val_addr = addr;
4676 add_dwarf_attr (die, attr);
4679 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4682 register dw_attr_ref a;
4684 if (a && AT_class (a) == dw_val_class_addr)
4685 return a->dw_attr_val.v.val_addr;
4690 /* Add a label identifier attribute value to a DIE. */
4693 add_AT_lbl_id (die, attr_kind, lbl_id)
4694 register dw_die_ref die;
4695 register enum dwarf_attribute attr_kind;
4696 register const char *lbl_id;
4698 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4700 attr->dw_attr_next = NULL;
4701 attr->dw_attr = attr_kind;
4702 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4703 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4704 add_dwarf_attr (die, attr);
4707 /* Add a section offset attribute value to a DIE. */
4710 add_AT_lbl_offset (die, attr_kind, label)
4711 register dw_die_ref die;
4712 register enum dwarf_attribute attr_kind;
4713 register const char *label;
4715 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4717 attr->dw_attr_next = NULL;
4718 attr->dw_attr = attr_kind;
4719 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4720 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4721 add_dwarf_attr (die, attr);
4724 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4725 static inline const char *
4727 register dw_attr_ref a;
4729 if (a && (AT_class (a) == dw_val_class_lbl_id
4730 || AT_class (a) == dw_val_class_lbl_offset))
4731 return a->dw_attr_val.v.val_lbl_id;
4736 /* Get the attribute of type attr_kind. */
4738 static inline dw_attr_ref
4739 get_AT (die, attr_kind)
4740 register dw_die_ref die;
4741 register enum dwarf_attribute attr_kind;
4743 register dw_attr_ref a;
4744 register dw_die_ref spec = NULL;
4748 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4750 if (a->dw_attr == attr_kind)
4753 if (a->dw_attr == DW_AT_specification
4754 || a->dw_attr == DW_AT_abstract_origin)
4759 return get_AT (spec, attr_kind);
4765 /* Return the "low pc" attribute value, typically associated with
4766 a subprogram DIE. Return null if the "low pc" attribute is
4767 either not prsent, or if it cannot be represented as an
4768 assembler label identifier. */
4770 static inline const char *
4772 register dw_die_ref die;
4774 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4775 return a ? AT_lbl (a) : NULL;
4778 /* Return the "high pc" attribute value, typically associated with
4779 a subprogram DIE. Return null if the "high pc" attribute is
4780 either not prsent, or if it cannot be represented as an
4781 assembler label identifier. */
4783 static inline const char *
4785 register dw_die_ref die;
4787 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4788 return a ? AT_lbl (a) : NULL;
4791 /* Return the value of the string attribute designated by ATTR_KIND, or
4792 NULL if it is not present. */
4794 static inline const char *
4795 get_AT_string (die, attr_kind)
4796 register dw_die_ref die;
4797 register enum dwarf_attribute attr_kind;
4799 register dw_attr_ref a = get_AT (die, attr_kind);
4800 return a ? AT_string (a) : NULL;
4803 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4804 if it is not present. */
4807 get_AT_flag (die, attr_kind)
4808 register dw_die_ref die;
4809 register enum dwarf_attribute attr_kind;
4811 register dw_attr_ref a = get_AT (die, attr_kind);
4812 return a ? AT_flag (a) : 0;
4815 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4816 if it is not present. */
4818 static inline unsigned
4819 get_AT_unsigned (die, attr_kind)
4820 register dw_die_ref die;
4821 register enum dwarf_attribute attr_kind;
4823 register dw_attr_ref a = get_AT (die, attr_kind);
4824 return a ? AT_unsigned (a) : 0;
4827 static inline dw_die_ref
4828 get_AT_ref (die, attr_kind)
4830 register enum dwarf_attribute attr_kind;
4832 register dw_attr_ref a = get_AT (die, attr_kind);
4833 return a ? AT_ref (a) : NULL;
4839 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4841 return (lang == DW_LANG_C || lang == DW_LANG_C89
4842 || lang == DW_LANG_C_plus_plus);
4848 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4850 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4856 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4858 return (lang == DW_LANG_Java);
4861 /* Free up the memory used by A. */
4863 static inline void free_AT PARAMS ((dw_attr_ref));
4868 switch (AT_class (a))
4870 case dw_val_class_str:
4871 case dw_val_class_lbl_id:
4872 case dw_val_class_lbl_offset:
4873 free (a->dw_attr_val.v.val_str);
4876 case dw_val_class_float:
4877 free (a->dw_attr_val.v.val_float.array);
4887 /* Remove the specified attribute if present. */
4890 remove_AT (die, attr_kind)
4891 register dw_die_ref die;
4892 register enum dwarf_attribute attr_kind;
4894 register dw_attr_ref *p;
4895 register dw_attr_ref removed = NULL;
4899 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4900 if ((*p)->dw_attr == attr_kind)
4903 *p = (*p)->dw_attr_next;
4912 /* Free up the memory used by DIE. */
4914 static inline void free_die PARAMS ((dw_die_ref));
4919 remove_children (die);
4923 /* Discard the children of this DIE. */
4926 remove_children (die)
4927 register dw_die_ref die;
4929 register dw_die_ref child_die = die->die_child;
4931 die->die_child = NULL;
4933 while (child_die != NULL)
4935 register dw_die_ref tmp_die = child_die;
4936 register dw_attr_ref a;
4938 child_die = child_die->die_sib;
4940 for (a = tmp_die->die_attr; a != NULL;)
4942 register dw_attr_ref tmp_a = a;
4944 a = a->dw_attr_next;
4952 /* Add a child DIE below its parent. We build the lists up in reverse
4953 addition order, and correct that in reverse_all_dies. */
4956 add_child_die (die, child_die)
4957 register dw_die_ref die;
4958 register dw_die_ref child_die;
4960 if (die != NULL && child_die != NULL)
4962 if (die == child_die)
4964 child_die->die_parent = die;
4965 child_die->die_sib = die->die_child;
4966 die->die_child = child_die;
4970 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4971 is the specification, to the front of PARENT's list of children. */
4974 splice_child_die (parent, child)
4975 dw_die_ref parent, child;
4979 /* We want the declaration DIE from inside the class, not the
4980 specification DIE at toplevel. */
4981 if (child->die_parent != parent)
4983 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4988 if (child->die_parent != parent
4989 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4992 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4995 *p = child->die_sib;
4999 child->die_sib = parent->die_child;
5000 parent->die_child = child;
5003 /* Return a pointer to a newly created DIE node. */
5005 static inline dw_die_ref
5006 new_die (tag_value, parent_die)
5007 register enum dwarf_tag tag_value;
5008 register dw_die_ref parent_die;
5010 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
5012 die->die_tag = tag_value;
5014 if (parent_die != NULL)
5015 add_child_die (parent_die, die);
5018 limbo_die_node *limbo_node;
5020 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5021 limbo_node->die = die;
5022 limbo_node->next = limbo_die_list;
5023 limbo_die_list = limbo_node;
5029 /* Return the DIE associated with the given type specifier. */
5031 static inline dw_die_ref
5032 lookup_type_die (type)
5035 if (TREE_CODE (type) == VECTOR_TYPE)
5036 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
5037 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
5040 /* Equate a DIE to a given type specifier. */
5043 equate_type_number_to_die (type, type_die)
5045 register dw_die_ref type_die;
5047 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
5050 /* Return the DIE associated with a given declaration. */
5052 static inline dw_die_ref
5053 lookup_decl_die (decl)
5056 register unsigned decl_id = DECL_UID (decl);
5058 return (decl_id < decl_die_table_in_use
5059 ? decl_die_table[decl_id] : NULL);
5062 /* Equate a DIE to a particular declaration. */
5065 equate_decl_number_to_die (decl, decl_die)
5067 register dw_die_ref decl_die;
5069 register unsigned decl_id = DECL_UID (decl);
5070 register unsigned num_allocated;
5072 if (decl_id >= decl_die_table_allocated)
5075 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5076 / DECL_DIE_TABLE_INCREMENT)
5077 * DECL_DIE_TABLE_INCREMENT;
5080 = (dw_die_ref *) xrealloc (decl_die_table,
5081 sizeof (dw_die_ref) * num_allocated);
5083 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5084 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5085 decl_die_table_allocated = num_allocated;
5088 if (decl_id >= decl_die_table_in_use)
5089 decl_die_table_in_use = (decl_id + 1);
5091 decl_die_table[decl_id] = decl_die;
5094 /* Keep track of the number of spaces used to indent the
5095 output of the debugging routines that print the structure of
5096 the DIE internal representation. */
5097 static int print_indent;
5099 /* Indent the line the number of spaces given by print_indent. */
5102 print_spaces (outfile)
5105 fprintf (outfile, "%*s", print_indent, "");
5108 /* Print the information associated with a given DIE, and its children.
5109 This routine is a debugging aid only. */
5112 print_die (die, outfile)
5116 register dw_attr_ref a;
5117 register dw_die_ref c;
5119 print_spaces (outfile);
5120 fprintf (outfile, "DIE %4lu: %s\n",
5121 die->die_offset, dwarf_tag_name (die->die_tag));
5122 print_spaces (outfile);
5123 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5124 fprintf (outfile, " offset: %lu\n", die->die_offset);
5126 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5128 print_spaces (outfile);
5129 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5131 switch (AT_class (a))
5133 case dw_val_class_addr:
5134 fprintf (outfile, "address");
5136 case dw_val_class_loc:
5137 fprintf (outfile, "location descriptor");
5139 case dw_val_class_const:
5140 fprintf (outfile, "%ld", AT_int (a));
5142 case dw_val_class_unsigned_const:
5143 fprintf (outfile, "%lu", AT_unsigned (a));
5145 case dw_val_class_long_long:
5146 fprintf (outfile, "constant (%lu,%lu)",
5147 a->dw_attr_val.v.val_long_long.hi,
5148 a->dw_attr_val.v.val_long_long.low);
5150 case dw_val_class_float:
5151 fprintf (outfile, "floating-point constant");
5153 case dw_val_class_flag:
5154 fprintf (outfile, "%u", AT_flag (a));
5156 case dw_val_class_die_ref:
5157 if (AT_ref (a) != NULL)
5159 if (AT_ref (a)->die_symbol)
5160 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5162 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5165 fprintf (outfile, "die -> <null>");
5167 case dw_val_class_lbl_id:
5168 case dw_val_class_lbl_offset:
5169 fprintf (outfile, "label: %s", AT_lbl (a));
5171 case dw_val_class_str:
5172 if (AT_string (a) != NULL)
5173 fprintf (outfile, "\"%s\"", AT_string (a));
5175 fprintf (outfile, "<null>");
5181 fprintf (outfile, "\n");
5184 if (die->die_child != NULL)
5187 for (c = die->die_child; c != NULL; c = c->die_sib)
5188 print_die (c, outfile);
5192 if (print_indent == 0)
5193 fprintf (outfile, "\n");
5196 /* Print the contents of the source code line number correspondence table.
5197 This routine is a debugging aid only. */
5200 print_dwarf_line_table (outfile)
5203 register unsigned i;
5204 register dw_line_info_ref line_info;
5206 fprintf (outfile, "\n\nDWARF source line information\n");
5207 for (i = 1; i < line_info_table_in_use; ++i)
5209 line_info = &line_info_table[i];
5210 fprintf (outfile, "%5d: ", i);
5211 fprintf (outfile, "%-20s", line_file_table.table[line_info->dw_file_num]);
5212 fprintf (outfile, "%6ld", line_info->dw_line_num);
5213 fprintf (outfile, "\n");
5216 fprintf (outfile, "\n\n");
5219 /* Print the information collected for a given DIE. */
5222 debug_dwarf_die (die)
5225 print_die (die, stderr);
5228 /* Print all DWARF information collected for the compilation unit.
5229 This routine is a debugging aid only. */
5235 print_die (comp_unit_die, stderr);
5236 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5237 print_dwarf_line_table (stderr);
5240 /* We build up the lists of children and attributes by pushing new ones
5241 onto the beginning of the list. Reverse the lists for DIE so that
5242 they are in order of addition. */
5245 reverse_die_lists (die)
5246 register dw_die_ref die;
5248 register dw_die_ref c, cp, cn;
5249 register dw_attr_ref a, ap, an;
5251 for (a = die->die_attr, ap = 0; a; a = an)
5253 an = a->dw_attr_next;
5254 a->dw_attr_next = ap;
5259 for (c = die->die_child, cp = 0; c; c = cn)
5265 die->die_child = cp;
5268 /* reverse_die_lists only reverses the single die you pass it. Since
5269 we used to reverse all dies in add_sibling_attributes, which runs
5270 through all the dies, it would reverse all the dies. Now, however,
5271 since we don't call reverse_die_lists in add_sibling_attributes, we
5272 need a routine to recursively reverse all the dies. This is that
5276 reverse_all_dies (die)
5277 register dw_die_ref die;
5279 register dw_die_ref c;
5281 reverse_die_lists (die);
5283 for (c = die->die_child; c; c = c->die_sib)
5284 reverse_all_dies (c);
5287 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5288 the CU for the enclosing include file, if any. BINCL_DIE is the
5289 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5293 push_new_compile_unit (old_unit, bincl_die)
5294 dw_die_ref old_unit, bincl_die;
5296 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5297 dw_die_ref new_unit = gen_compile_unit_die (filename);
5298 new_unit->die_sib = old_unit;
5302 /* Close an include-file CU and reopen the enclosing one. */
5305 pop_compile_unit (old_unit)
5306 dw_die_ref old_unit;
5308 dw_die_ref new_unit = old_unit->die_sib;
5309 old_unit->die_sib = NULL;
5313 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5314 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5316 /* Calculate the checksum of a location expression. */
5319 loc_checksum (loc, ctx)
5320 dw_loc_descr_ref loc;
5321 struct md5_ctx *ctx;
5323 PROCESS (loc->dw_loc_opc);
5324 PROCESS (loc->dw_loc_oprnd1);
5325 PROCESS (loc->dw_loc_oprnd2);
5328 /* Calculate the checksum of an attribute. */
5331 attr_checksum (at, ctx)
5333 struct md5_ctx *ctx;
5335 dw_loc_descr_ref loc;
5338 PROCESS (at->dw_attr);
5340 /* We don't care about differences in file numbering. */
5341 if (at->dw_attr == DW_AT_decl_file
5342 /* Or that this was compiled with a different compiler snapshot; if
5343 the output is the same, that's what matters. */
5344 || at->dw_attr == DW_AT_producer)
5347 switch (AT_class (at))
5349 case dw_val_class_const:
5350 PROCESS (at->dw_attr_val.v.val_int);
5352 case dw_val_class_unsigned_const:
5353 PROCESS (at->dw_attr_val.v.val_unsigned);
5355 case dw_val_class_long_long:
5356 PROCESS (at->dw_attr_val.v.val_long_long);
5358 case dw_val_class_float:
5359 PROCESS (at->dw_attr_val.v.val_float);
5361 case dw_val_class_flag:
5362 PROCESS (at->dw_attr_val.v.val_flag);
5365 case dw_val_class_str:
5366 PROCESS_STRING (AT_string (at));
5368 case dw_val_class_addr:
5370 switch (GET_CODE (r))
5373 PROCESS_STRING (XSTR (r, 0));
5381 case dw_val_class_loc:
5382 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5383 loc_checksum (loc, ctx);
5386 case dw_val_class_die_ref:
5387 if (AT_ref (at)->die_offset)
5388 PROCESS (AT_ref (at)->die_offset);
5389 /* FIXME else use target die name or something. */
5391 case dw_val_class_fde_ref:
5392 case dw_val_class_lbl_id:
5393 case dw_val_class_lbl_offset:
5400 /* Calculate the checksum of a DIE. */
5403 die_checksum (die, ctx)
5405 struct md5_ctx *ctx;
5410 PROCESS (die->die_tag);
5412 for (a = die->die_attr; a; a = a->dw_attr_next)
5413 attr_checksum (a, ctx);
5415 for (c = die->die_child; c; c = c->die_sib)
5416 die_checksum (c, ctx);
5420 #undef PROCESS_STRING
5422 /* The prefix to attach to symbols on DIEs in the current comdat debug
5424 static char *comdat_symbol_id;
5426 /* The index of the current symbol within the current comdat CU. */
5427 static unsigned int comdat_symbol_number;
5429 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5430 children, and set comdat_symbol_id accordingly. */
5433 compute_section_prefix (unit_die)
5434 dw_die_ref unit_die;
5438 unsigned char checksum[16];
5441 md5_init_ctx (&ctx);
5442 die_checksum (unit_die, &ctx);
5443 md5_finish_ctx (&ctx, checksum);
5445 p = file_name_nondirectory (get_AT_string (unit_die, DW_AT_name));
5446 name = (char *) alloca (strlen (p) + 64);
5447 sprintf (name, "%s.", p);
5449 clean_symbol_name (name);
5451 p = name + strlen (name);
5452 for (i = 0; i < 4; ++i)
5454 sprintf (p, "%.2x", checksum[i]);
5458 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5459 comdat_symbol_number = 0;
5462 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5468 switch (die->die_tag)
5470 case DW_TAG_array_type:
5471 case DW_TAG_class_type:
5472 case DW_TAG_enumeration_type:
5473 case DW_TAG_pointer_type:
5474 case DW_TAG_reference_type:
5475 case DW_TAG_string_type:
5476 case DW_TAG_structure_type:
5477 case DW_TAG_subroutine_type:
5478 case DW_TAG_union_type:
5479 case DW_TAG_ptr_to_member_type:
5480 case DW_TAG_set_type:
5481 case DW_TAG_subrange_type:
5482 case DW_TAG_base_type:
5483 case DW_TAG_const_type:
5484 case DW_TAG_file_type:
5485 case DW_TAG_packed_type:
5486 case DW_TAG_volatile_type:
5493 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5494 Basically, we want to choose the bits that are likely to be shared between
5495 compilations (types) and leave out the bits that are specific to individual
5496 compilations (functions). */
5503 /* I think we want to leave base types and __vtbl_ptr_type in the
5504 main CU, as we do for stabs. The advantage is a greater
5505 likelihood of sharing between objects that don't include headers
5506 in the same order (and therefore would put the base types in a
5507 different comdat). jason 8/28/00 */
5508 if (c->die_tag == DW_TAG_base_type)
5511 if (c->die_tag == DW_TAG_pointer_type
5512 || c->die_tag == DW_TAG_reference_type
5513 || c->die_tag == DW_TAG_const_type
5514 || c->die_tag == DW_TAG_volatile_type)
5516 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5517 return t ? is_comdat_die (t) : 0;
5521 return is_type_die (c);
5524 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5525 compilation unit. */
5531 if (is_type_die (c))
5533 if (get_AT (c, DW_AT_declaration)
5534 && ! get_AT (c, DW_AT_specification))
5543 static int label_num;
5544 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5545 return xstrdup (buf);
5548 /* Assign symbols to all worthy DIEs under DIE. */
5551 assign_symbol_names (die)
5552 register dw_die_ref die;
5554 register dw_die_ref c;
5556 if (is_symbol_die (die))
5558 if (comdat_symbol_id)
5560 char *p = alloca (strlen (comdat_symbol_id) + 64);
5561 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5562 comdat_symbol_id, comdat_symbol_number++);
5563 die->die_symbol = xstrdup (p);
5566 die->die_symbol = gen_internal_sym ();
5569 for (c = die->die_child; c != NULL; c = c->die_sib)
5570 assign_symbol_names (c);
5573 /* Traverse the DIE (which is always comp_unit_die), and set up
5574 additional compilation units for each of the include files we see
5575 bracketed by BINCL/EINCL. */
5578 break_out_includes (die)
5579 register dw_die_ref die;
5582 register dw_die_ref unit = NULL;
5583 limbo_die_node *node;
5585 for (ptr = &(die->die_child); *ptr; )
5587 register dw_die_ref c = *ptr;
5589 if (c->die_tag == DW_TAG_GNU_BINCL
5590 || c->die_tag == DW_TAG_GNU_EINCL
5591 || (unit && is_comdat_die (c)))
5593 /* This DIE is for a secondary CU; remove it from the main one. */
5596 if (c->die_tag == DW_TAG_GNU_BINCL)
5598 unit = push_new_compile_unit (unit, c);
5601 else if (c->die_tag == DW_TAG_GNU_EINCL)
5603 unit = pop_compile_unit (unit);
5607 add_child_die (unit, c);
5611 /* Leave this DIE in the main CU. */
5612 ptr = &(c->die_sib);
5618 /* We can only use this in debugging, since the frontend doesn't check
5619 to make sure that we leave every include file we enter. */
5624 assign_symbol_names (die);
5625 for (node = limbo_die_list; node; node = node->next)
5627 compute_section_prefix (node->die);
5628 assign_symbol_names (node->die);
5632 /* Traverse the DIE and add a sibling attribute if it may have the
5633 effect of speeding up access to siblings. To save some space,
5634 avoid generating sibling attributes for DIE's without children. */
5637 add_sibling_attributes (die)
5638 register dw_die_ref die;
5640 register dw_die_ref c;
5642 if (die->die_tag != DW_TAG_compile_unit
5643 && die->die_sib && die->die_child != NULL)
5644 /* Add the sibling link to the front of the attribute list. */
5645 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5647 for (c = die->die_child; c != NULL; c = c->die_sib)
5648 add_sibling_attributes (c);
5651 /* The format of each DIE (and its attribute value pairs)
5652 is encoded in an abbreviation table. This routine builds the
5653 abbreviation table and assigns a unique abbreviation id for
5654 each abbreviation entry. The children of each die are visited
5658 build_abbrev_table (die)
5659 register dw_die_ref die;
5661 register unsigned long abbrev_id;
5662 register unsigned long n_alloc;
5663 register dw_die_ref c;
5664 register dw_attr_ref d_attr, a_attr;
5666 /* Scan the DIE references, and mark as external any that refer to
5667 DIEs from other CUs (i.e. those which are not marked). */
5668 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5670 if (AT_class (d_attr) == dw_val_class_die_ref
5671 && AT_ref (d_attr)->die_mark == 0)
5673 if (AT_ref (d_attr)->die_symbol == 0)
5675 set_AT_ref_external (d_attr, 1);
5679 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5681 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5683 if (abbrev->die_tag == die->die_tag)
5685 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5687 a_attr = abbrev->die_attr;
5688 d_attr = die->die_attr;
5690 while (a_attr != NULL && d_attr != NULL)
5692 if ((a_attr->dw_attr != d_attr->dw_attr)
5693 || (value_format (a_attr) != value_format (d_attr)))
5696 a_attr = a_attr->dw_attr_next;
5697 d_attr = d_attr->dw_attr_next;
5700 if (a_attr == NULL && d_attr == NULL)
5706 if (abbrev_id >= abbrev_die_table_in_use)
5708 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5710 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5712 = (dw_die_ref *) xrealloc (abbrev_die_table,
5713 sizeof (dw_die_ref) * n_alloc);
5715 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5716 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5717 abbrev_die_table_allocated = n_alloc;
5720 ++abbrev_die_table_in_use;
5721 abbrev_die_table[abbrev_id] = die;
5724 die->die_abbrev = abbrev_id;
5725 for (c = die->die_child; c != NULL; c = c->die_sib)
5726 build_abbrev_table (c);
5729 /* Return the size of a string, including the null byte.
5731 This used to treat backslashes as escapes, and hence they were not included
5732 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5733 which treats a backslash as a backslash, escaping it if necessary, and hence
5734 we must include them in the count. */
5736 static unsigned long
5737 size_of_string (str)
5738 register const char *str;
5740 return strlen (str) + 1;
5743 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5746 constant_size (value)
5747 long unsigned value;
5754 log = floor_log2 (value);
5757 log = 1 << (floor_log2 (log) + 1);
5762 /* Return the size of a DIE, as it is represented in the
5763 .debug_info section. */
5765 static unsigned long
5767 register dw_die_ref die;
5769 register unsigned long size = 0;
5770 register dw_attr_ref a;
5772 size += size_of_uleb128 (die->die_abbrev);
5773 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5775 switch (AT_class (a))
5777 case dw_val_class_addr:
5778 size += DWARF2_ADDR_SIZE;
5780 case dw_val_class_loc:
5782 register unsigned long lsize = size_of_locs (AT_loc (a));
5785 size += constant_size (lsize);
5789 case dw_val_class_const:
5790 size += size_of_sleb128 (AT_int (a));
5792 case dw_val_class_unsigned_const:
5793 size += constant_size (AT_unsigned (a));
5795 case dw_val_class_long_long:
5796 size += 1 + 8; /* block */
5798 case dw_val_class_float:
5799 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5801 case dw_val_class_flag:
5804 case dw_val_class_die_ref:
5805 size += DWARF_OFFSET_SIZE;
5807 case dw_val_class_fde_ref:
5808 size += DWARF_OFFSET_SIZE;
5810 case dw_val_class_lbl_id:
5811 size += DWARF2_ADDR_SIZE;
5813 case dw_val_class_lbl_offset:
5814 size += DWARF_OFFSET_SIZE;
5816 case dw_val_class_str:
5817 size += size_of_string (AT_string (a));
5827 /* Size the debugging information associated with a given DIE.
5828 Visits the DIE's children recursively. Updates the global
5829 variable next_die_offset, on each time through. Uses the
5830 current value of next_die_offset to update the die_offset
5831 field in each DIE. */
5834 calc_die_sizes (die)
5837 register dw_die_ref c;
5838 die->die_offset = next_die_offset;
5839 next_die_offset += size_of_die (die);
5841 for (c = die->die_child; c != NULL; c = c->die_sib)
5844 if (die->die_child != NULL)
5845 /* Count the null byte used to terminate sibling lists. */
5846 next_die_offset += 1;
5849 /* Set the marks for a die and its children. We do this so
5850 that we know whether or not a reference needs to use FORM_ref_addr; only
5851 DIEs in the same CU will be marked. We used to clear out the offset
5852 and use that as the flag, but ran into ordering problems. */
5858 register dw_die_ref c;
5860 for (c = die->die_child; c; c = c->die_sib)
5864 /* Clear the marks for a die and its children. */
5870 register dw_die_ref c;
5872 for (c = die->die_child; c; c = c->die_sib)
5876 /* Return the size of the line information prolog generated for the
5877 compilation unit. */
5879 static unsigned long
5880 size_of_line_prolog ()
5882 register unsigned long size;
5883 register unsigned long ft_index;
5885 size = DWARF_LINE_PROLOG_HEADER_SIZE;
5887 /* Count the size of the table giving number of args for each
5889 size += DWARF_LINE_OPCODE_BASE - 1;
5891 /* Include directory table is empty (at present). Count only the
5892 null byte used to terminate the table. */
5895 for (ft_index = 1; ft_index < decl_file_table.in_use; ++ft_index)
5897 /* File name entry. */
5898 size += size_of_string (decl_file_table.table[ft_index]);
5900 /* Include directory index. */
5901 size += size_of_uleb128 (0);
5903 /* Modification time. */
5904 size += size_of_uleb128 (0);
5906 /* File length in bytes. */
5907 size += size_of_uleb128 (0);
5910 /* Count the file table terminator. */
5915 /* Return the size of the .debug_pubnames table generated for the
5916 compilation unit. */
5918 static unsigned long
5921 register unsigned long size;
5922 register unsigned i;
5924 size = DWARF_PUBNAMES_HEADER_SIZE;
5925 for (i = 0; i < pubname_table_in_use; ++i)
5927 register pubname_ref p = &pubname_table[i];
5928 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5931 size += DWARF_OFFSET_SIZE;
5935 /* Return the size of the information in the .debug_aranges section. */
5937 static unsigned long
5940 register unsigned long size;
5942 size = DWARF_ARANGES_HEADER_SIZE;
5944 /* Count the address/length pair for this compilation unit. */
5945 size += 2 * DWARF2_ADDR_SIZE;
5946 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5948 /* Count the two zero words used to terminated the address range table. */
5949 size += 2 * DWARF2_ADDR_SIZE;
5953 /* Select the encoding of an attribute value. */
5955 static enum dwarf_form
5959 switch (a->dw_attr_val.val_class)
5961 case dw_val_class_addr:
5962 return DW_FORM_addr;
5963 case dw_val_class_loc:
5964 switch (constant_size (size_of_locs (AT_loc (a))))
5967 return DW_FORM_block1;
5969 return DW_FORM_block2;
5973 case dw_val_class_const:
5974 return DW_FORM_sdata;
5975 case dw_val_class_unsigned_const:
5976 switch (constant_size (AT_unsigned (a)))
5979 return DW_FORM_data1;
5981 return DW_FORM_data2;
5983 return DW_FORM_data4;
5985 return DW_FORM_data8;
5989 case dw_val_class_long_long:
5990 return DW_FORM_block1;
5991 case dw_val_class_float:
5992 return DW_FORM_block1;
5993 case dw_val_class_flag:
5994 return DW_FORM_flag;
5995 case dw_val_class_die_ref:
5996 if (AT_ref_external (a))
5997 return DW_FORM_ref_addr;
6000 case dw_val_class_fde_ref:
6001 return DW_FORM_data;
6002 case dw_val_class_lbl_id:
6003 return DW_FORM_addr;
6004 case dw_val_class_lbl_offset:
6005 return DW_FORM_data;
6006 case dw_val_class_str:
6007 return DW_FORM_string;
6013 /* Output the encoding of an attribute value. */
6016 output_value_format (a)
6019 enum dwarf_form form = value_format (a);
6021 output_uleb128 (form);
6023 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
6025 fputc ('\n', asm_out_file);
6028 /* Output the .debug_abbrev section which defines the DIE abbreviation
6032 output_abbrev_section ()
6034 unsigned long abbrev_id;
6037 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6039 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6041 output_uleb128 (abbrev_id);
6043 fprintf (asm_out_file, " (abbrev code)");
6045 fputc ('\n', asm_out_file);
6046 output_uleb128 (abbrev->die_tag);
6048 fprintf (asm_out_file, " (TAG: %s)",
6049 dwarf_tag_name (abbrev->die_tag));
6051 fputc ('\n', asm_out_file);
6052 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP,
6053 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
6056 fprintf (asm_out_file, "\t%s %s",
6058 (abbrev->die_child != NULL
6059 ? "DW_children_yes" : "DW_children_no"));
6061 fputc ('\n', asm_out_file);
6063 for (a_attr = abbrev->die_attr; a_attr != NULL;
6064 a_attr = a_attr->dw_attr_next)
6066 output_uleb128 (a_attr->dw_attr);
6068 fprintf (asm_out_file, " (%s)",
6069 dwarf_attr_name (a_attr->dw_attr));
6071 fputc ('\n', asm_out_file);
6072 output_value_format (a_attr);
6075 fprintf (asm_out_file, "%s0,0\n", ASM_BYTE_OP);
6078 /* Terminate the table. */
6079 fprintf (asm_out_file, "%s0\n", ASM_BYTE_OP);
6082 /* Output a symbol we can use to refer to this DIE from another CU. */
6085 output_die_symbol (die)
6086 register dw_die_ref die;
6088 char *sym = die->die_symbol;
6093 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6094 /* We make these global, not weak; if the target doesn't support
6095 .linkonce, it doesn't support combining the sections, so debugging
6097 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6098 ASM_OUTPUT_LABEL (asm_out_file, sym);
6101 /* Output a symbolic (i.e. FORM_ref_addr) reference to TARGET_DIE. */
6104 output_symbolic_ref (target_die)
6105 dw_die_ref target_die;
6107 char *sym = target_die->die_symbol;
6112 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, sym);
6115 /* Output the DIE and its attributes. Called recursively to generate
6116 the definitions of each child DIE. */
6120 register dw_die_ref die;
6122 register dw_attr_ref a;
6123 register dw_die_ref c;
6124 register unsigned long size;
6126 /* If someone in another CU might refer to us, set up a symbol for
6127 them to point to. */
6128 if (die->die_symbol)
6129 output_die_symbol (die);
6131 output_uleb128 (die->die_abbrev);
6133 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
6134 die->die_offset, dwarf_tag_name (die->die_tag));
6136 fputc ('\n', asm_out_file);
6138 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6140 switch (AT_class (a))
6142 case dw_val_class_addr:
6143 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
6146 case dw_val_class_loc:
6147 size = size_of_locs (AT_loc (a));
6149 /* Output the block length for this list of location operations. */
6150 switch (constant_size (size))
6153 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
6156 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
6163 fprintf (asm_out_file, "\t%s %s",
6164 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6166 fputc ('\n', asm_out_file);
6168 output_loc_sequence (AT_loc (a));
6171 case dw_val_class_const:
6172 /* ??? It would be slightly more efficient to use a scheme like is
6173 used for unsigned constants below, but gdb 4.x does not sign
6174 extend. Gdb 5.x does sign extend. */
6175 output_sleb128 (AT_int (a));
6178 case dw_val_class_unsigned_const:
6179 switch (constant_size (AT_unsigned (a)))
6182 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
6185 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
6188 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
6191 ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a));
6198 case dw_val_class_long_long:
6199 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
6201 fprintf (asm_out_file, "\t%s %s",
6202 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6204 fputc ('\n', asm_out_file);
6205 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file,
6206 a->dw_attr_val.v.val_long_long.hi,
6207 a->dw_attr_val.v.val_long_long.low);
6210 fprintf (asm_out_file,
6211 "\t%s long long constant", ASM_COMMENT_START);
6213 fputc ('\n', asm_out_file);
6216 case dw_val_class_float:
6218 register unsigned int i;
6219 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6220 a->dw_attr_val.v.val_float.length * 4);
6222 fprintf (asm_out_file, "\t%s %s",
6223 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6225 fputc ('\n', asm_out_file);
6226 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6228 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
6229 a->dw_attr_val.v.val_float.array[i]);
6231 fprintf (asm_out_file, "\t%s fp constant word %u",
6232 ASM_COMMENT_START, i);
6234 fputc ('\n', asm_out_file);
6239 case dw_val_class_flag:
6240 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
6243 case dw_val_class_die_ref:
6244 if (AT_ref_external (a))
6245 output_symbolic_ref (AT_ref (a));
6246 else if (AT_ref (a)->die_offset == 0)
6249 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
6252 case dw_val_class_fde_ref:
6255 ASM_GENERATE_INTERNAL_LABEL
6256 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
6257 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
6258 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
6262 case dw_val_class_lbl_id:
6263 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
6266 case dw_val_class_lbl_offset:
6267 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
6270 case dw_val_class_str:
6272 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
6274 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
6275 (int) strlen (AT_string (a)) + 1);
6282 if (AT_class (a) != dw_val_class_loc
6283 && AT_class (a) != dw_val_class_long_long
6284 && AT_class (a) != dw_val_class_float)
6287 fprintf (asm_out_file, "\t%s %s",
6288 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6290 fputc ('\n', asm_out_file);
6294 for (c = die->die_child; c != NULL; c = c->die_sib)
6297 if (die->die_child != NULL)
6299 /* Add null byte to terminate sibling list. */
6300 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6302 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
6303 ASM_COMMENT_START, die->die_offset);
6305 fputc ('\n', asm_out_file);
6309 /* Output the compilation unit that appears at the beginning of the
6310 .debug_info section, and precedes the DIE descriptions. */
6313 output_compilation_unit_header ()
6315 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
6317 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
6320 fputc ('\n', asm_out_file);
6321 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6323 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
6325 fputc ('\n', asm_out_file);
6326 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
6328 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
6331 fputc ('\n', asm_out_file);
6332 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6334 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
6336 fputc ('\n', asm_out_file);
6339 /* Output the compilation unit DIE and its children. */
6342 output_comp_unit (die)
6345 const char *secname;
6347 if (die->die_child == 0)
6350 /* Mark all the DIEs in this CU so we know which get local refs. */
6353 build_abbrev_table (die);
6355 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6356 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6357 calc_die_sizes (die);
6359 if (die->die_symbol)
6361 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6362 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6364 die->die_symbol = NULL;
6367 secname = (const char *) DEBUG_INFO_SECTION;
6369 /* Output debugging information. */
6370 fputc ('\n', asm_out_file);
6371 ASM_OUTPUT_SECTION (asm_out_file, secname);
6372 output_compilation_unit_header ();
6375 /* Leave the marks on the main CU, so we can check them in
6377 if (die->die_symbol)
6381 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6382 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6383 argument list, and maybe the scope. */
6386 dwarf2_name (decl, scope)
6390 return (*decl_printable_name) (decl, scope ? 1 : 0);
6393 /* Add a new entry to .debug_pubnames if appropriate. */
6396 add_pubname (decl, die)
6402 if (! TREE_PUBLIC (decl))
6405 if (pubname_table_in_use == pubname_table_allocated)
6407 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6408 pubname_table = (pubname_ref) xrealloc
6409 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6412 p = &pubname_table[pubname_table_in_use++];
6415 p->name = xstrdup (dwarf2_name (decl, 1));
6418 /* Output the public names table used to speed up access to externally
6419 visible names. For now, only generate entries for externally
6420 visible procedures. */
6425 register unsigned i;
6426 register unsigned long pubnames_length = size_of_pubnames ();
6428 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
6431 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
6434 fputc ('\n', asm_out_file);
6435 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6438 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6440 fputc ('\n', asm_out_file);
6441 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6443 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6446 fputc ('\n', asm_out_file);
6447 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
6449 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
6451 fputc ('\n', asm_out_file);
6452 for (i = 0; i < pubname_table_in_use; ++i)
6454 register pubname_ref pub = &pubname_table[i];
6456 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6457 if (pub->die->die_mark == 0)
6460 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
6462 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
6464 fputc ('\n', asm_out_file);
6468 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
6469 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
6473 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
6474 (int) strlen (pub->name) + 1);
6477 fputc ('\n', asm_out_file);
6480 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
6481 fputc ('\n', asm_out_file);
6484 /* Add a new entry to .debug_aranges if appropriate. */
6487 add_arange (decl, die)
6491 if (! DECL_SECTION_NAME (decl))
6494 if (arange_table_in_use == arange_table_allocated)
6496 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6498 = (arange_ref) xrealloc (arange_table,
6499 arange_table_allocated * sizeof (dw_die_ref));
6502 arange_table[arange_table_in_use++] = die;
6505 /* Output the information that goes into the .debug_aranges table.
6506 Namely, define the beginning and ending address range of the
6507 text section generated for this compilation unit. */
6512 register unsigned i;
6513 register unsigned long aranges_length = size_of_aranges ();
6515 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
6517 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
6520 fputc ('\n', asm_out_file);
6521 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6523 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6525 fputc ('\n', asm_out_file);
6526 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6528 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6531 fputc ('\n', asm_out_file);
6532 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6534 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
6536 fputc ('\n', asm_out_file);
6537 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6539 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
6542 fputc ('\n', asm_out_file);
6544 /* We need to align to twice the pointer size here. */
6545 if (DWARF_ARANGES_PAD_SIZE)
6547 /* Pad using a 2 bytes word so that padding is correct
6548 for any pointer size. */
6549 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
6550 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6551 fprintf (asm_out_file, ",0");
6553 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
6554 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
6557 fputc ('\n', asm_out_file);
6558 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
6560 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6562 fputc ('\n', asm_out_file);
6563 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
6564 text_section_label);
6566 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6568 fputc ('\n', asm_out_file);
6569 for (i = 0; i < arange_table_in_use; ++i)
6571 dw_die_ref die = arange_table[i];
6573 /* We shouldn't see aranges for DIEs outside of the main CU. */
6574 if (die->die_mark == 0)
6577 if (die->die_tag == DW_TAG_subprogram)
6578 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
6581 /* A static variable; extract the symbol from DW_AT_location.
6582 Note that this code isn't currently hit, as we only emit
6583 aranges for functions (jason 9/23/99). */
6585 dw_attr_ref a = get_AT (die, DW_AT_location);
6586 dw_loc_descr_ref loc;
6587 if (! a || AT_class (a) != dw_val_class_loc)
6591 if (loc->dw_loc_opc != DW_OP_addr)
6594 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
6595 loc->dw_loc_oprnd1.v.val_addr);
6599 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6601 fputc ('\n', asm_out_file);
6602 if (die->die_tag == DW_TAG_subprogram)
6603 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
6604 get_AT_low_pc (die));
6606 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
6607 get_AT_unsigned (die, DW_AT_byte_size));
6610 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6612 fputc ('\n', asm_out_file);
6615 /* Output the terminator words. */
6616 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6617 fputc ('\n', asm_out_file);
6618 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6619 fputc ('\n', asm_out_file);
6623 /* Data structure containing information about input files. */
6626 char *path; /* Complete file name. */
6627 char *fname; /* File name part. */
6628 int length; /* Length of entire string. */
6629 int file_idx; /* Index in input file table. */
6630 int dir_idx; /* Index in directory table. */
6633 /* Data structure containing information about directories with source
6637 char *path; /* Path including directory name. */
6638 int length; /* Path length. */
6639 int prefix; /* Index of directory entry which is a prefix. */
6640 int nbytes; /* Total number of bytes in all file names excluding
6642 int count; /* Number of files in this directory. */
6643 int dir_idx; /* Index of directory used as base. */
6644 int used; /* Used in the end? */
6647 /* Callback function for file_info comparison. We sort by looking at
6648 the directories in the path. */
6650 file_info_cmp (p1, p2)
6654 const struct file_info *s1 = p1;
6655 const struct file_info *s2 = p2;
6659 /* Take care of file names without directories. */
6660 if (s1->path == s1->fname)
6662 else if (s2->path == s2->fname)
6665 cp1 = (unsigned char *) s1->path;
6666 cp2 = (unsigned char *) s2->path;
6672 /* Reached the end of the first path? */
6673 if (cp1 == (unsigned char *) s1->fname)
6674 /* It doesn't really matter in which order files from the
6675 same directory are sorted in. Therefore don't test for
6676 the second path reaching the end. */
6678 else if (cp2 == (unsigned char *) s2->fname)
6681 /* Character of current path component the same? */
6687 /* Compute the maximum prefix of P2 appearing also in P1. Entire
6688 directory names must match. */
6689 static int prefix_of PARAMS ((struct dir_info *, struct dir_info *));
6692 struct dir_info *p1;
6693 struct dir_info *p2;
6695 char *s1 = p1->path;
6696 char *s2 = p2->path;
6697 int len = p1->length < p2->length ? p1->length : p2->length;
6699 while (*s1 == *s2 && s1 < p1->path + len)
6702 if (*s1 == '/' && *s2 == '/')
6703 /* The whole of P1 is the prefix. */
6706 /* Go back to the last directory component. */
6707 while (s1 > p1->path)
6709 return s1 - p1->path + 1;
6714 /* Output the directory table and the file name table. We try to minimize
6715 the total amount of memory needed. A heuristic is used to avoid large
6716 slowdowns with many input files. */
6718 output_file_names ()
6720 struct file_info *files;
6721 struct dir_info *dirs;
6730 /* Allocate the various arrays we need. */
6731 files = (struct file_info *) alloca (line_file_table.in_use
6732 * sizeof (struct file_info));
6733 dirs = (struct dir_info *) alloca (line_file_table.in_use * 2
6734 * sizeof (struct dir_info));
6736 /* Sort the file names. */
6737 for (i = 1; i < (int) line_file_table.in_use; ++i)
6741 /* Skip all leading "./". */
6742 f = line_file_table.table[i];
6743 while (f[0] == '.' && f[1] == '/')
6746 /* Create a new array entry. */
6748 files[i].length = strlen (f);
6749 files[i].file_idx = i;
6751 /* Search for the file name part. */
6752 f = strrchr (f, '/');
6753 files[i].fname = f == NULL ? files[i].path : f + 1;
6755 qsort (files + 1, line_file_table.in_use - 1, sizeof (files[0]),
6758 /* Find all the different directories used. */
6759 dirs[0].path = files[1].path;
6760 dirs[0].length = files[1].fname - files[1].path;
6761 dirs[0].prefix = -1;
6762 dirs[0].nbytes = files[1].length - dirs[1].length + 1;
6764 dirs[0].dir_idx = 0;
6766 files[1].dir_idx = 0;
6769 for (i = 2; i < (int) line_file_table.in_use; ++i)
6770 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6771 && memcmp (dirs[ndirs - 1].path, files[i].path,
6772 dirs[ndirs - 1].length) == 0)
6774 /* Same directory as last entry. */
6775 files[i].dir_idx = ndirs - 1;
6776 dirs[ndirs - 1].nbytes += files[i].length - dirs[ndirs - 1].length + 1;
6777 ++dirs[ndirs - 1].count;
6785 /* This is a new directory. */
6786 dirs[ndirs].path = files[i].path;
6787 dirs[ndirs].length = files[i].fname - files[i].path;
6788 dirs[ndirs].nbytes = files[i].length - dirs[i].length + 1;
6789 dirs[ndirs].count = 1;
6790 dirs[ndirs].dir_idx = ndirs;
6791 dirs[ndirs].used = 0;
6792 files[i].dir_idx = ndirs;
6794 /* Search for a prefix. */
6797 for (j = 0; j < ndirs; ++j)
6798 if (dirs[j].length > max_len)
6800 int this_len = prefix_of (&dirs[j], &dirs[ndirs]);
6802 if (this_len > max_len)
6809 /* Remember the prefix. If this is a known prefix simply
6810 remember the index. Otherwise we will have to create an
6811 artificial entry. */
6812 if (max_len == dirs[max_idx].length)
6813 /* This is our prefix. */
6814 dirs[ndirs].prefix = max_idx;
6815 else if (max_len > 0)
6817 /* Create an entry without associated file. Since we have
6818 to keep the dirs array sorted (means, entries with paths
6819 which come first) we have to move the new entry in the
6820 place of the old one. */
6821 dirs[++ndirs] = dirs[max_idx];
6823 /* We don't have to set .path. */
6824 dirs[max_idx].length = max_len;
6825 dirs[max_idx].nbytes = 0;
6826 dirs[max_idx].count = 0;
6827 dirs[max_idx].dir_idx = ndirs;
6828 dirs[max_idx].used = 0;
6829 dirs[max_idx].prefix = dirs[ndirs].prefix;
6831 dirs[ndirs - 1].prefix = dirs[ndirs].prefix = max_idx;
6834 dirs[ndirs].prefix = -1;
6839 /* Now to the actual work. We have to find a subset of the
6840 directories which allow expressing the file name using references
6841 to the directory table with the least amount of characters. We
6842 do not do an exhaustive search where we would have to check out
6843 every combination of every single possible prefix. Instead we
6844 use a heuristic which provides nearly optimal results in most
6845 cases and never is much off. */
6846 saved = (int *) alloca (ndirs * sizeof (int));
6847 savehere = (int *) alloca (ndirs * sizeof (int));
6849 memset (saved, '\0', ndirs * sizeof (saved[0]));
6850 for (i = 0; i < ndirs; ++i)
6855 /* We can always safe some space for the current directory. But
6856 this does not mean it will be enough to justify adding the
6858 savehere[i] = dirs[i].length;
6859 total = (savehere[i] - saved[i]) * dirs[i].count;
6861 for (j = i + 1; j < ndirs; ++j)
6865 if (saved[j] < dirs[i].length)
6867 /* Determine whether the dirs[i] path is a prefix of the
6872 while (k != -1 && k != i)
6877 /* Yes it is. We can possibly safe some memory but
6878 writing the filenames in dirs[j] relative to
6880 savehere[j] = dirs[i].length;
6881 total += (savehere[j] - saved[j]) * dirs[j].count;
6886 /* Check whether we can safe enough to justify adding the dirs[i]
6888 if (total > dirs[i].length + 1)
6890 /* It's worthwhile adding. */
6891 for (j = i; j < ndirs; ++j)
6892 if (savehere[j] > 0)
6894 /* Remember how much we saved for this directory so far. */
6895 saved[j] = savehere[j];
6897 /* Remember the prefix directory. */
6898 dirs[j].dir_idx = i;
6903 /* We have to emit them in the order they appear in the line_file_table
6904 array since the index is used in the debug info generation. To
6905 do this efficiently we generate a back-mapping of the indices
6907 backmap = (int *) alloca (line_file_table.in_use * sizeof (int));
6908 for (i = 1; i < (int) line_file_table.in_use; ++i)
6910 backmap[files[i].file_idx] = i;
6911 /* Mark this directory as used. */
6912 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6915 /* That was it. We are ready to emit the information. First the
6916 directory name table. Here we have to make sure that the first
6917 actually emitted directory name has the index one. Zero is
6918 reserved for the current working directory. Make sure we do not
6919 confuse these indices with the one for the constructed table
6920 (even though most of the time they are identical). */
6922 idx_offset = dirs[0].length > 0 ? 1 : 0;
6923 for (i = 1 - idx_offset; i < ndirs; ++i)
6924 if (dirs[i].used != 0)
6926 dirs[i].used = idx++;
6930 ASM_OUTPUT_DWARF_NSTRING (asm_out_file,
6931 dirs[i].path, dirs[i].length - 1);
6932 fprintf (asm_out_file, "%s Directory Entry: 0x%x\n",
6933 ASM_COMMENT_START, dirs[i].used);
6937 ASM_OUTPUT_ASCII (asm_out_file, dirs[i].path, dirs[i].length - 1);
6938 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6939 fputc ('\n', asm_out_file);
6942 /* Correct the index for the current working directory entry if it
6944 if (idx_offset == 0)
6946 /* Terminate the directory name array. */
6947 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6949 fprintf (asm_out_file, "\t%s End directory table", ASM_COMMENT_START);
6950 fputc ('\n', asm_out_file);
6952 /* Now write all the file names. */
6953 for (i = 1; i < (int) line_file_table.in_use; ++i)
6955 int file_idx = backmap[i];
6956 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6960 ASM_OUTPUT_DWARF_STRING (asm_out_file,
6961 files[file_idx].path
6962 + dirs[dir_idx].length);
6963 fprintf (asm_out_file, "%s File Entry: 0x%x\n",
6964 ASM_COMMENT_START, i);
6967 ASM_OUTPUT_ASCII (asm_out_file,
6968 files[file_idx].path + dirs[dir_idx].length,
6969 (files[file_idx].length
6970 - dirs[dir_idx].length) + 1);
6972 /* Include directory index. */
6973 output_uleb128 (dirs[dir_idx].used);
6974 fputc ('\n', asm_out_file);
6976 /* Modification time. */
6978 fputc ('\n', asm_out_file);
6980 /* File length in bytes. */
6982 fputc ('\n', asm_out_file);
6985 /* Terminate the file name table */
6986 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6988 fprintf (asm_out_file, "\t%s End file name table", ASM_COMMENT_START);
6989 fputc ('\n', asm_out_file);
6993 /* Output the source line number correspondence information. This
6994 information goes into the .debug_line section. */
6999 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7000 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7001 register unsigned opc;
7002 register unsigned n_op_args;
7003 register unsigned long lt_index;
7004 register unsigned long current_line;
7005 register long line_offset;
7006 register long line_delta;
7007 register unsigned long current_file;
7008 register unsigned long function;
7010 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
7012 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
7015 fputc ('\n', asm_out_file);
7016 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
7017 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
7019 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
7021 fputc ('\n', asm_out_file);
7022 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
7024 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
7026 fputc ('\n', asm_out_file);
7027 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
7029 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
7032 fputc ('\n', asm_out_file);
7033 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
7035 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
7038 fputc ('\n', asm_out_file);
7039 fprintf (asm_out_file, "%s%d", ASM_BYTE_OP, DWARF_LINE_BASE);
7041 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
7044 fputc ('\n', asm_out_file);
7045 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
7047 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
7050 fputc ('\n', asm_out_file);
7051 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
7053 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
7055 fputc ('\n', asm_out_file);
7056 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
7060 case DW_LNS_advance_pc:
7061 case DW_LNS_advance_line:
7062 case DW_LNS_set_file:
7063 case DW_LNS_set_column:
7064 case DW_LNS_fixed_advance_pc:
7071 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
7073 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
7074 ASM_COMMENT_START, opc, n_op_args);
7075 fputc ('\n', asm_out_file);
7078 /* Write out the information about the files we use. */
7079 output_file_names ();
7081 /* We used to set the address register to the first location in the text
7082 section here, but that didn't accomplish anything since we already
7083 have a line note for the opening brace of the first function. */
7085 /* Generate the line number to PC correspondence table, encoded as
7086 a series of state machine operations. */
7089 strcpy (prev_line_label, text_section_label);
7090 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7092 register dw_line_info_ref line_info = &line_info_table[lt_index];
7095 /* Disable this optimization for now; GDB wants to see two line notes
7096 at the beginning of a function so it can find the end of the
7099 /* Don't emit anything for redundant notes. Just updating the
7100 address doesn't accomplish anything, because we already assume
7101 that anything after the last address is this line. */
7102 if (line_info->dw_line_num == current_line
7103 && line_info->dw_file_num == current_file)
7107 /* Emit debug info for the address of the current line, choosing
7108 the encoding that uses the least amount of space. */
7109 /* ??? Unfortunately, we have little choice here currently, and must
7110 always use the most general form. Gcc does not know the address
7111 delta itself, so we can't use DW_LNS_advance_pc. There are no known
7112 dwarf2 aware assemblers at this time, so we can't use any special
7113 pseudo ops that would allow the assembler to optimally encode this for
7114 us. Many ports do have length attributes which will give an upper
7115 bound on the address range. We could perhaps use length attributes
7116 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
7117 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7120 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7121 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7123 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7126 fputc ('\n', asm_out_file);
7127 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
7128 fputc ('\n', asm_out_file);
7132 /* This can handle any delta. This takes
7133 4+DWARF2_ADDR_SIZE bytes. */
7134 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7136 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7138 fputc ('\n', asm_out_file);
7139 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7140 fputc ('\n', asm_out_file);
7141 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7142 fputc ('\n', asm_out_file);
7143 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7144 fputc ('\n', asm_out_file);
7146 strcpy (prev_line_label, line_label);
7148 /* Emit debug info for the source file of the current line, if
7149 different from the previous line. */
7150 if (line_info->dw_file_num != current_file)
7152 current_file = line_info->dw_file_num;
7153 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
7155 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
7157 fputc ('\n', asm_out_file);
7158 output_uleb128 (current_file);
7160 fprintf (asm_out_file, " (\"%s\")",
7161 line_file_table.table[current_file]);
7163 fputc ('\n', asm_out_file);
7166 /* Emit debug info for the current line number, choosing the encoding
7167 that uses the least amount of space. */
7168 if (line_info->dw_line_num != current_line)
7170 line_offset = line_info->dw_line_num - current_line;
7171 line_delta = line_offset - DWARF_LINE_BASE;
7172 current_line = line_info->dw_line_num;
7173 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7175 /* This can handle deltas from -10 to 234, using the current
7176 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7178 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
7179 DWARF_LINE_OPCODE_BASE + line_delta);
7181 fprintf (asm_out_file,
7182 "\t%s line %ld", ASM_COMMENT_START, current_line);
7184 fputc ('\n', asm_out_file);
7188 /* This can handle any delta. This takes at least 4 bytes,
7189 depending on the value being encoded. */
7190 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
7192 fprintf (asm_out_file, "\t%s advance to line %ld",
7193 ASM_COMMENT_START, current_line);
7195 fputc ('\n', asm_out_file);
7196 output_sleb128 (line_offset);
7197 fputc ('\n', asm_out_file);
7198 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7200 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7201 fputc ('\n', asm_out_file);
7206 /* We still need to start a new row, so output a copy insn. */
7207 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7209 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7210 fputc ('\n', asm_out_file);
7214 /* Emit debug info for the address of the end of the function. */
7217 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7219 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7222 fputc ('\n', asm_out_file);
7223 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
7224 fputc ('\n', asm_out_file);
7228 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7230 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
7231 fputc ('\n', asm_out_file);
7232 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7233 fputc ('\n', asm_out_file);
7234 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7235 fputc ('\n', asm_out_file);
7236 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
7237 fputc ('\n', asm_out_file);
7240 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7242 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
7244 fputc ('\n', asm_out_file);
7246 fputc ('\n', asm_out_file);
7247 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
7248 fputc ('\n', asm_out_file);
7253 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7255 register dw_separate_line_info_ref line_info
7256 = &separate_line_info_table[lt_index];
7259 /* Don't emit anything for redundant notes. */
7260 if (line_info->dw_line_num == current_line
7261 && line_info->dw_file_num == current_file
7262 && line_info->function == function)
7266 /* Emit debug info for the address of the current line. If this is
7267 a new function, or the first line of a function, then we need
7268 to handle it differently. */
7269 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7271 if (function != line_info->function)
7273 function = line_info->function;
7275 /* Set the address register to the first line in the function */
7276 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7278 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7281 fputc ('\n', asm_out_file);
7282 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7283 fputc ('\n', asm_out_file);
7284 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7285 fputc ('\n', asm_out_file);
7286 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7287 fputc ('\n', asm_out_file);
7291 /* ??? See the DW_LNS_advance_pc comment above. */
7294 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7296 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7299 fputc ('\n', asm_out_file);
7300 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7302 fputc ('\n', asm_out_file);
7306 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7308 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7310 fputc ('\n', asm_out_file);
7311 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7312 fputc ('\n', asm_out_file);
7313 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7314 fputc ('\n', asm_out_file);
7315 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7316 fputc ('\n', asm_out_file);
7319 strcpy (prev_line_label, line_label);
7321 /* Emit debug info for the source file of the current line, if
7322 different from the previous line. */
7323 if (line_info->dw_file_num != current_file)
7325 current_file = line_info->dw_file_num;
7326 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
7328 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
7330 fputc ('\n', asm_out_file);
7331 output_uleb128 (current_file);
7333 fprintf (asm_out_file, " (\"%s\")",
7334 line_file_table.table[current_file]);
7336 fputc ('\n', asm_out_file);
7339 /* Emit debug info for the current line number, choosing the encoding
7340 that uses the least amount of space. */
7341 if (line_info->dw_line_num != current_line)
7343 line_offset = line_info->dw_line_num - current_line;
7344 line_delta = line_offset - DWARF_LINE_BASE;
7345 current_line = line_info->dw_line_num;
7346 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7348 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
7349 DWARF_LINE_OPCODE_BASE + line_delta);
7351 fprintf (asm_out_file,
7352 "\t%s line %ld", ASM_COMMENT_START, current_line);
7354 fputc ('\n', asm_out_file);
7358 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
7360 fprintf (asm_out_file, "\t%s advance to line %ld",
7361 ASM_COMMENT_START, current_line);
7363 fputc ('\n', asm_out_file);
7364 output_sleb128 (line_offset);
7365 fputc ('\n', asm_out_file);
7366 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7368 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7369 fputc ('\n', asm_out_file);
7374 /* We still need to start a new row, so output a copy insn. */
7375 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7377 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7378 fputc ('\n', asm_out_file);
7386 /* If we're done with a function, end its sequence. */
7387 if (lt_index == separate_line_info_table_in_use
7388 || separate_line_info_table[lt_index].function != function)
7393 /* Emit debug info for the address of the end of the function. */
7394 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7397 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7399 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7402 fputc ('\n', asm_out_file);
7403 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7405 fputc ('\n', asm_out_file);
7409 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7411 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7413 fputc ('\n', asm_out_file);
7414 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7415 fputc ('\n', asm_out_file);
7416 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7417 fputc ('\n', asm_out_file);
7418 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7419 fputc ('\n', asm_out_file);
7422 /* Output the marker for the end of this sequence. */
7423 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7425 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
7428 fputc ('\n', asm_out_file);
7430 fputc ('\n', asm_out_file);
7431 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
7432 fputc ('\n', asm_out_file);
7436 /* Output the marker for the end of the line number info. */
7437 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
7440 /* Given a pointer to a tree node for some base type, return a pointer to
7441 a DIE that describes the given type.
7443 This routine must only be called for GCC type nodes that correspond to
7444 Dwarf base (fundamental) types. */
7447 base_type_die (type)
7450 register dw_die_ref base_type_result;
7451 register const char *type_name;
7452 register enum dwarf_type encoding;
7453 register tree name = TYPE_NAME (type);
7455 if (TREE_CODE (type) == ERROR_MARK
7456 || TREE_CODE (type) == VOID_TYPE)
7461 if (TREE_CODE (name) == TYPE_DECL)
7462 name = DECL_NAME (name);
7464 type_name = IDENTIFIER_POINTER (name);
7467 type_name = "__unknown__";
7469 switch (TREE_CODE (type))
7472 /* Carefully distinguish the C character types, without messing
7473 up if the language is not C. Note that we check only for the names
7474 that contain spaces; other names might occur by coincidence in other
7476 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7477 && (type == char_type_node
7478 || ! strcmp (type_name, "signed char")
7479 || ! strcmp (type_name, "unsigned char"))))
7481 if (TREE_UNSIGNED (type))
7482 encoding = DW_ATE_unsigned;
7484 encoding = DW_ATE_signed;
7487 /* else fall through. */
7490 /* GNU Pascal/Ada CHAR type. Not used in C. */
7491 if (TREE_UNSIGNED (type))
7492 encoding = DW_ATE_unsigned_char;
7494 encoding = DW_ATE_signed_char;
7498 encoding = DW_ATE_float;
7501 /* Dwarf2 doesn't know anything about complex ints, so use
7502 a user defined type for it. */
7504 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7505 encoding = DW_ATE_complex_float;
7507 encoding = DW_ATE_lo_user;
7511 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7512 encoding = DW_ATE_boolean;
7516 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7519 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7520 if (demangle_name_func)
7521 type_name = (*demangle_name_func) (type_name);
7523 add_AT_string (base_type_result, DW_AT_name, type_name);
7524 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7525 int_size_in_bytes (type));
7526 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7528 return base_type_result;
7531 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7532 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7533 a given type is generally the same as the given type, except that if the
7534 given type is a pointer or reference type, then the root type of the given
7535 type is the root type of the "basis" type for the pointer or reference
7536 type. (This definition of the "root" type is recursive.) Also, the root
7537 type of a `const' qualified type or a `volatile' qualified type is the
7538 root type of the given type without the qualifiers. */
7544 if (TREE_CODE (type) == ERROR_MARK)
7545 return error_mark_node;
7547 switch (TREE_CODE (type))
7550 return error_mark_node;
7553 case REFERENCE_TYPE:
7554 return type_main_variant (root_type (TREE_TYPE (type)));
7557 return type_main_variant (type);
7561 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7562 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7568 switch (TREE_CODE (type))
7583 case QUAL_UNION_TYPE:
7588 case REFERENCE_TYPE:
7602 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7603 entry that chains various modifiers in front of the given type. */
7606 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7608 register int is_const_type;
7609 register int is_volatile_type;
7610 register dw_die_ref context_die;
7612 register enum tree_code code = TREE_CODE (type);
7613 register dw_die_ref mod_type_die = NULL;
7614 register dw_die_ref sub_die = NULL;
7615 register tree item_type = NULL;
7617 if (code != ERROR_MARK)
7619 type = build_type_variant (type, is_const_type, is_volatile_type);
7621 mod_type_die = lookup_type_die (type);
7623 return mod_type_die;
7625 /* Handle C typedef types. */
7626 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7627 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
7629 tree dtype = TREE_TYPE (TYPE_NAME (type));
7632 /* For a named type, use the typedef. */
7633 gen_type_die (type, context_die);
7634 mod_type_die = lookup_type_die (type);
7637 else if (is_const_type < TYPE_READONLY (dtype)
7638 || is_volatile_type < TYPE_VOLATILE (dtype))
7639 /* cv-unqualified version of named type. Just use the unnamed
7640 type to which it refers. */
7642 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
7643 is_const_type, is_volatile_type,
7645 /* Else cv-qualified version of named type; fall through. */
7651 else if (is_const_type)
7653 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7654 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7656 else if (is_volatile_type)
7658 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7659 sub_die = modified_type_die (type, 0, 0, context_die);
7661 else if (code == POINTER_TYPE)
7663 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7664 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7666 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7668 item_type = TREE_TYPE (type);
7670 else if (code == REFERENCE_TYPE)
7672 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7673 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7675 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7677 item_type = TREE_TYPE (type);
7679 else if (is_base_type (type))
7680 mod_type_die = base_type_die (type);
7683 gen_type_die (type, context_die);
7685 /* We have to get the type_main_variant here (and pass that to the
7686 `lookup_type_die' routine) because the ..._TYPE node we have
7687 might simply be a *copy* of some original type node (where the
7688 copy was created to help us keep track of typedef names) and
7689 that copy might have a different TYPE_UID from the original
7691 mod_type_die = lookup_type_die (type_main_variant (type));
7692 if (mod_type_die == NULL)
7697 equate_type_number_to_die (type, mod_type_die);
7699 /* We must do this after the equate_type_number_to_die call, in case
7700 this is a recursive type. This ensures that the modified_type_die
7701 recursion will terminate even if the type is recursive. Recursive
7702 types are possible in Ada. */
7703 sub_die = modified_type_die (item_type,
7704 TYPE_READONLY (item_type),
7705 TYPE_VOLATILE (item_type),
7708 if (sub_die != NULL)
7709 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7711 return mod_type_die;
7714 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7715 an enumerated type. */
7721 return TREE_CODE (type) == ENUMERAL_TYPE;
7724 /* Return the register number described by a given RTL node. */
7730 register unsigned regno = REGNO (rtl);
7732 if (regno >= FIRST_PSEUDO_REGISTER)
7734 warning ("internal regno botch: regno = %d\n", regno);
7738 regno = DBX_REGISTER_NUMBER (regno);
7742 /* Return a location descriptor that designates a machine register. */
7744 static dw_loc_descr_ref
7745 reg_loc_descriptor (rtl)
7748 register dw_loc_descr_ref loc_result = NULL;
7749 register unsigned reg = reg_number (rtl);
7752 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7754 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7759 /* Return a location descriptor that designates a constant. */
7761 static dw_loc_descr_ref
7762 int_loc_descriptor (i)
7765 enum dwarf_location_atom op;
7767 /* Pick the smallest representation of a constant, rather than just
7768 defaulting to the LEB encoding. */
7772 op = DW_OP_lit0 + i;
7775 else if (i <= 0xffff)
7777 else if (HOST_BITS_PER_WIDE_INT == 32
7787 else if (i >= -0x8000)
7789 else if (HOST_BITS_PER_WIDE_INT == 32
7790 || i >= -0x80000000)
7796 return new_loc_descr (op, i, 0);
7799 /* Return a location descriptor that designates a base+offset location. */
7801 static dw_loc_descr_ref
7802 based_loc_descr (reg, offset)
7806 register dw_loc_descr_ref loc_result;
7807 /* For the "frame base", we use the frame pointer or stack pointer
7808 registers, since the RTL for local variables is relative to one of
7810 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7811 ? HARD_FRAME_POINTER_REGNUM
7812 : STACK_POINTER_REGNUM);
7815 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7817 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7819 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7824 /* Return true if this RTL expression describes a base+offset calculation. */
7830 return (GET_CODE (rtl) == PLUS
7831 && ((GET_CODE (XEXP (rtl, 0)) == REG
7832 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7835 /* The following routine converts the RTL for a variable or parameter
7836 (resident in memory) into an equivalent Dwarf representation of a
7837 mechanism for getting the address of that same variable onto the top of a
7838 hypothetical "address evaluation" stack.
7840 When creating memory location descriptors, we are effectively transforming
7841 the RTL for a memory-resident object into its Dwarf postfix expression
7842 equivalent. This routine recursively descends an RTL tree, turning
7843 it into Dwarf postfix code as it goes.
7845 MODE is the mode of the memory reference, needed to handle some
7846 autoincrement addressing modes. */
7848 static dw_loc_descr_ref
7849 mem_loc_descriptor (rtl, mode)
7851 enum machine_mode mode;
7853 dw_loc_descr_ref mem_loc_result = NULL;
7854 /* Note that for a dynamically sized array, the location we will generate a
7855 description of here will be the lowest numbered location which is
7856 actually within the array. That's *not* necessarily the same as the
7857 zeroth element of the array. */
7859 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7860 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7863 switch (GET_CODE (rtl))
7868 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7869 just fall into the SUBREG code. */
7874 /* The case of a subreg may arise when we have a local (register)
7875 variable or a formal (register) parameter which doesn't quite fill
7876 up an entire register. For now, just assume that it is
7877 legitimate to make the Dwarf info refer to the whole register which
7878 contains the given subreg. */
7879 rtl = XEXP (rtl, 0);
7884 /* Whenever a register number forms a part of the description of the
7885 method for calculating the (dynamic) address of a memory resident
7886 object, DWARF rules require the register number be referred to as
7887 a "base register". This distinction is not based in any way upon
7888 what category of register the hardware believes the given register
7889 belongs to. This is strictly DWARF terminology we're dealing with
7890 here. Note that in cases where the location of a memory-resident
7891 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7892 OP_CONST (0)) the actual DWARF location descriptor that we generate
7893 may just be OP_BASEREG (basereg). This may look deceptively like
7894 the object in question was allocated to a register (rather than in
7895 memory) so DWARF consumers need to be aware of the subtle
7896 distinction between OP_REG and OP_BASEREG. */
7897 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7901 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7902 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7906 /* Some ports can transform a symbol ref into a label ref, because
7907 the symbol ref is too far away and has to be dumped into a constant
7911 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7912 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7913 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7917 /* Extract the PLUS expression nested inside and fall into
7918 PLUS code bellow. */
7919 rtl = XEXP (rtl, 1);
7924 /* Turn these into a PLUS expression and fall into the PLUS code
7926 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7927 GEN_INT (GET_CODE (rtl) == PRE_INC
7928 ? GET_MODE_UNIT_SIZE (mode)
7929 : -GET_MODE_UNIT_SIZE (mode)));
7935 if (is_based_loc (rtl))
7936 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7937 INTVAL (XEXP (rtl, 1)));
7940 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7942 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7943 && INTVAL (XEXP (rtl, 1)) >= 0)
7945 add_loc_descr (&mem_loc_result,
7946 new_loc_descr (DW_OP_plus_uconst,
7947 INTVAL (XEXP (rtl, 1)), 0));
7951 add_loc_descr (&mem_loc_result,
7952 mem_loc_descriptor (XEXP (rtl, 1), mode));
7953 add_loc_descr (&mem_loc_result,
7954 new_loc_descr (DW_OP_plus, 0, 0));
7960 /* If a pseudo-reg is optimized away, it is possible for it to
7961 be replaced with a MEM containing a multiply. */
7962 add_loc_descr (&mem_loc_result,
7963 mem_loc_descriptor (XEXP (rtl, 0), mode));
7964 add_loc_descr (&mem_loc_result,
7965 mem_loc_descriptor (XEXP (rtl, 1), mode));
7966 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7970 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7977 return mem_loc_result;
7980 /* Return a descriptor that describes the concatenation of two locations.
7981 This is typically a complex variable. */
7983 static dw_loc_descr_ref
7984 concat_loc_descriptor (x0, x1)
7985 register rtx x0, x1;
7987 dw_loc_descr_ref cc_loc_result = NULL;
7989 if (!is_pseudo_reg (x0)
7990 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7991 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7992 add_loc_descr (&cc_loc_result,
7993 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7995 if (!is_pseudo_reg (x1)
7996 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7997 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7998 add_loc_descr (&cc_loc_result,
7999 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
8001 return cc_loc_result;
8004 /* Output a proper Dwarf location descriptor for a variable or parameter
8005 which is either allocated in a register or in a memory location. For a
8006 register, we just generate an OP_REG and the register number. For a
8007 memory location we provide a Dwarf postfix expression describing how to
8008 generate the (dynamic) address of the object onto the address stack. */
8010 static dw_loc_descr_ref
8011 loc_descriptor (rtl)
8014 dw_loc_descr_ref loc_result = NULL;
8015 switch (GET_CODE (rtl))
8018 /* The case of a subreg may arise when we have a local (register)
8019 variable or a formal (register) parameter which doesn't quite fill
8020 up an entire register. For now, just assume that it is
8021 legitimate to make the Dwarf info refer to the whole register which
8022 contains the given subreg. */
8023 rtl = XEXP (rtl, 0);
8028 loc_result = reg_loc_descriptor (rtl);
8032 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8036 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
8046 /* Similar, but generate the descriptor from trees instead of rtl.
8047 This comes up particularly with variable length arrays. */
8049 static dw_loc_descr_ref
8050 loc_descriptor_from_tree (loc, addressp)
8054 dw_loc_descr_ref ret = NULL;
8055 int indirect_size = 0;
8056 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
8057 enum dwarf_location_atom op;
8059 /* ??? Most of the time we do not take proper care for sign/zero
8060 extending the values properly. Hopefully this won't be a real
8063 switch (TREE_CODE (loc))
8068 case WITH_RECORD_EXPR:
8069 /* This case involves extracting fields from an object to determine the
8070 position of other fields. We don't try to encode this here. The
8071 only user of this is Ada, which encodes the needed information using
8072 the names of types. */
8078 rtx rtl = rtl_for_decl_location (loc);
8079 enum machine_mode mode = DECL_MODE (loc);
8081 if (rtl == NULL_RTX)
8083 else if (CONSTANT_P (rtl))
8085 ret = new_loc_descr (DW_OP_addr, 0, 0);
8086 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8087 ret->dw_loc_oprnd1.v.val_addr = rtl;
8088 indirect_size = GET_MODE_SIZE (mode);
8092 if (GET_CODE (rtl) == MEM)
8094 indirect_size = GET_MODE_SIZE (mode);
8095 rtl = XEXP (rtl, 0);
8097 ret = mem_loc_descriptor (rtl, mode);
8103 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8104 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
8109 case NON_LVALUE_EXPR:
8111 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8118 HOST_WIDE_INT bitsize, bitpos, bytepos;
8119 enum machine_mode mode;
8121 unsigned int alignment;
8123 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8124 &unsignedp, &volatilep, &alignment);
8125 ret = loc_descriptor_from_tree (obj, 1);
8127 if (offset != NULL_TREE)
8129 /* Variable offset. */
8130 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8131 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8136 /* We cannot address anything not on a unit boundary. */
8137 if (bitpos % BITS_PER_UNIT != 0)
8142 if (bitpos % BITS_PER_UNIT != 0
8143 || bitsize % BITS_PER_UNIT != 0)
8145 /* ??? We could handle this by loading and shifting etc.
8146 Wait until someone needs it before expending the effort. */
8150 indirect_size = bitsize / BITS_PER_UNIT;
8153 bytepos = bitpos / BITS_PER_UNIT;
8155 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8156 else if (bytepos < 0)
8158 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8159 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8165 if (host_integerp (loc, 0))
8166 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8178 case TRUNC_DIV_EXPR:
8184 case TRUNC_MOD_EXPR:
8194 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8197 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8198 && host_integerp (TREE_OPERAND (loc, 1), 0))
8200 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8201 add_loc_descr (&ret,
8202 new_loc_descr (DW_OP_plus_uconst,
8203 tree_low_cst (TREE_OPERAND (loc, 1),
8211 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8216 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8221 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8226 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8238 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8239 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
8240 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8254 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8255 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8259 loc = build (COND_EXPR, TREE_TYPE (loc),
8260 build (LT_EXPR, integer_type_node,
8261 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8262 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8267 dw_loc_descr_ref bra_node, jump_node, tmp;
8269 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8270 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8271 add_loc_descr (&ret, bra_node);
8273 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8274 add_loc_descr (&ret, tmp);
8275 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8276 add_loc_descr (&ret, jump_node);
8278 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8279 add_loc_descr (&ret, tmp);
8280 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8281 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
8283 /* ??? Need a node to point the skip at. Use a nop. */
8284 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8285 add_loc_descr (&ret, tmp);
8286 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8287 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8295 /* If we can't fill the request for an address, die. */
8296 if (addressp && indirect_size == 0)
8299 /* If we've got an address and don't want one, dereference. */
8300 if (!addressp && indirect_size > 0)
8302 if (indirect_size > DWARF2_ADDR_SIZE)
8304 if (indirect_size == DWARF2_ADDR_SIZE)
8307 op = DW_OP_deref_size;
8308 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
8314 /* Given a value, round it up to the lowest multiple of `boundary'
8315 which is not less than the value itself. */
8317 static inline HOST_WIDE_INT
8318 ceiling (value, boundary)
8319 HOST_WIDE_INT value;
8320 unsigned int boundary;
8322 return (((value + boundary - 1) / boundary) * boundary);
8325 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8326 pointer to the declared type for the relevant field variable, or return
8327 `integer_type_node' if the given node turns out to be an
8336 if (TREE_CODE (decl) == ERROR_MARK)
8337 return integer_type_node;
8339 type = DECL_BIT_FIELD_TYPE (decl);
8340 if (type == NULL_TREE)
8341 type = TREE_TYPE (decl);
8346 /* Given a pointer to a tree node, return the alignment in bits for
8347 it, or else return BITS_PER_WORD if the node actually turns out to
8348 be an ERROR_MARK node. */
8350 static inline unsigned
8351 simple_type_align_in_bits (type)
8354 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8357 static inline unsigned
8358 simple_decl_align_in_bits (decl)
8361 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8364 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8365 node, return the size in bits for the type if it is a constant, or else
8366 return the alignment for the type if the type's size is not constant, or
8367 else return BITS_PER_WORD if the type actually turns out to be an
8370 static inline unsigned HOST_WIDE_INT
8371 simple_type_size_in_bits (type)
8374 tree type_size_tree;
8376 if (TREE_CODE (type) == ERROR_MARK)
8377 return BITS_PER_WORD;
8378 type_size_tree = TYPE_SIZE (type);
8380 if (type_size_tree == NULL_TREE)
8382 if (! host_integerp (type_size_tree, 1))
8383 return TYPE_ALIGN (type);
8384 return tree_low_cst (type_size_tree, 1);
8387 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
8388 return the byte offset of the lowest addressed byte of the "containing
8389 object" for the given FIELD_DECL, or return 0 if we are unable to
8390 determine what that offset is, either because the argument turns out to
8391 be a pointer to an ERROR_MARK node, or because the offset is actually
8392 variable. (We can't handle the latter case just yet). */
8394 static HOST_WIDE_INT
8395 field_byte_offset (decl)
8398 unsigned int type_align_in_bits;
8399 unsigned int decl_align_in_bits;
8400 unsigned HOST_WIDE_INT type_size_in_bits;
8401 HOST_WIDE_INT object_offset_in_bits;
8402 HOST_WIDE_INT object_offset_in_bytes;
8404 tree field_size_tree;
8405 HOST_WIDE_INT bitpos_int;
8406 HOST_WIDE_INT deepest_bitpos;
8407 unsigned HOST_WIDE_INT field_size_in_bits;
8409 if (TREE_CODE (decl) == ERROR_MARK)
8412 if (TREE_CODE (decl) != FIELD_DECL)
8415 type = field_type (decl);
8416 field_size_tree = DECL_SIZE (decl);
8418 /* The size could be unspecified if there was an error, or for
8419 a flexible array member. */
8420 if (! field_size_tree)
8421 field_size_tree = bitsize_zero_node;
8423 /* We cannot yet cope with fields whose positions are variable, so
8424 for now, when we see such things, we simply return 0. Someday, we may
8425 be able to handle such cases, but it will be damn difficult. */
8426 if (! host_integerp (bit_position (decl), 0))
8429 bitpos_int = int_bit_position (decl);
8431 /* If we don't know the size of the field, pretend it's a full word. */
8432 if (host_integerp (field_size_tree, 1))
8433 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8435 field_size_in_bits = BITS_PER_WORD;
8437 type_size_in_bits = simple_type_size_in_bits (type);
8438 type_align_in_bits = simple_type_align_in_bits (type);
8439 decl_align_in_bits = simple_decl_align_in_bits (decl);
8441 /* Note that the GCC front-end doesn't make any attempt to keep track of
8442 the starting bit offset (relative to the start of the containing
8443 structure type) of the hypothetical "containing object" for a bit-
8444 field. Thus, when computing the byte offset value for the start of the
8445 "containing object" of a bit-field, we must deduce this information on
8446 our own. This can be rather tricky to do in some cases. For example,
8447 handling the following structure type definition when compiling for an
8448 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8451 struct S { int field1; long long field2:31; };
8453 Fortunately, there is a simple rule-of-thumb which can be
8454 used in such cases. When compiling for an i386/i486, GCC will allocate
8455 8 bytes for the structure shown above. It decides to do this based upon
8456 one simple rule for bit-field allocation. Quite simply, GCC allocates
8457 each "containing object" for each bit-field at the first (i.e. lowest
8458 addressed) legitimate alignment boundary (based upon the required
8459 minimum alignment for the declared type of the field) which it can
8460 possibly use, subject to the condition that there is still enough
8461 available space remaining in the containing object (when allocated at
8462 the selected point) to fully accommodate all of the bits of the
8463 bit-field itself. This simple rule makes it obvious why GCC allocates
8464 8 bytes for each object of the structure type shown above. When looking
8465 for a place to allocate the "containing object" for `field2', the
8466 compiler simply tries to allocate a 64-bit "containing object" at each
8467 successive 32-bit boundary (starting at zero) until it finds a place to
8468 allocate that 64- bit field such that at least 31 contiguous (and
8469 previously unallocated) bits remain within that selected 64 bit field.
8470 (As it turns out, for the example above, the compiler finds that it is
8471 OK to allocate the "containing object" 64-bit field at bit-offset zero
8472 within the structure type.) Here we attempt to work backwards from the
8473 limited set of facts we're given, and we try to deduce from those facts,
8474 where GCC must have believed that the containing object started (within
8475 the structure type). The value we deduce is then used (by the callers of
8476 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8477 for fields (both bit-fields and, in the case of DW_AT_location, regular
8480 /* Figure out the bit-distance from the start of the structure to the
8481 "deepest" bit of the bit-field. */
8482 deepest_bitpos = bitpos_int + field_size_in_bits;
8484 /* This is the tricky part. Use some fancy footwork to deduce where the
8485 lowest addressed bit of the containing object must be. */
8486 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8488 /* Round up to type_align by default. This works best for bitfields. */
8489 object_offset_in_bits += type_align_in_bits - 1;
8490 object_offset_in_bits /= type_align_in_bits;
8491 object_offset_in_bits *= type_align_in_bits;
8493 if (object_offset_in_bits > bitpos_int)
8495 /* Sigh, the decl must be packed. */
8496 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8498 /* Round up to decl_align instead. */
8499 object_offset_in_bits += decl_align_in_bits - 1;
8500 object_offset_in_bits /= decl_align_in_bits;
8501 object_offset_in_bits *= decl_align_in_bits;
8504 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8506 return object_offset_in_bytes;
8509 /* The following routines define various Dwarf attributes and any data
8510 associated with them. */
8512 /* Add a location description attribute value to a DIE.
8514 This emits location attributes suitable for whole variables and
8515 whole parameters. Note that the location attributes for struct fields are
8516 generated by the routine `data_member_location_attribute' below. */
8519 add_AT_location_description (die, attr_kind, rtl)
8521 enum dwarf_attribute attr_kind;
8524 /* Handle a special case. If we are about to output a location descriptor
8525 for a variable or parameter which has been optimized out of existence,
8526 don't do that. A variable which has been optimized out
8527 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8528 Currently, in some rare cases, variables can have DECL_RTL values which
8529 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8530 elsewhere in the compiler. We treat such cases as if the variable(s) in
8531 question had been optimized out of existence. */
8533 if (is_pseudo_reg (rtl)
8534 || (GET_CODE (rtl) == MEM
8535 && is_pseudo_reg (XEXP (rtl, 0)))
8536 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8537 references the internal argument pointer (a pseudo) in a function
8538 where all references to the internal argument pointer were
8539 eliminated via the optimizers. */
8540 || (GET_CODE (rtl) == MEM
8541 && GET_CODE (XEXP (rtl, 0)) == PLUS
8542 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8543 || (GET_CODE (rtl) == CONCAT
8544 && is_pseudo_reg (XEXP (rtl, 0))
8545 && is_pseudo_reg (XEXP (rtl, 1))))
8548 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8551 /* Attach the specialized form of location attribute used for data
8552 members of struct and union types. In the special case of a
8553 FIELD_DECL node which represents a bit-field, the "offset" part
8554 of this special location descriptor must indicate the distance
8555 in bytes from the lowest-addressed byte of the containing struct
8556 or union type to the lowest-addressed byte of the "containing
8557 object" for the bit-field. (See the `field_byte_offset' function
8558 above).. For any given bit-field, the "containing object" is a
8559 hypothetical object (of some integral or enum type) within which
8560 the given bit-field lives. The type of this hypothetical
8561 "containing object" is always the same as the declared type of
8562 the individual bit-field itself (for GCC anyway... the DWARF
8563 spec doesn't actually mandate this). Note that it is the size
8564 (in bytes) of the hypothetical "containing object" which will
8565 be given in the DW_AT_byte_size attribute for this bit-field.
8566 (See the `byte_size_attribute' function below.) It is also used
8567 when calculating the value of the DW_AT_bit_offset attribute.
8568 (See the `bit_offset_attribute' function below). */
8571 add_data_member_location_attribute (die, decl)
8572 register dw_die_ref die;
8575 register unsigned long offset;
8576 register dw_loc_descr_ref loc_descr;
8577 register enum dwarf_location_atom op;
8579 if (TREE_CODE (decl) == TREE_VEC)
8580 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8582 offset = field_byte_offset (decl);
8584 /* The DWARF2 standard says that we should assume that the structure address
8585 is already on the stack, so we can specify a structure field address
8586 by using DW_OP_plus_uconst. */
8588 #ifdef MIPS_DEBUGGING_INFO
8589 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8590 correctly. It works only if we leave the offset on the stack. */
8593 op = DW_OP_plus_uconst;
8596 loc_descr = new_loc_descr (op, offset, 0);
8597 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8600 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8601 does not have a "location" either in memory or in a register. These
8602 things can arise in GNU C when a constant is passed as an actual parameter
8603 to an inlined function. They can also arise in C++ where declared
8604 constants do not necessarily get memory "homes". */
8607 add_const_value_attribute (die, rtl)
8608 register dw_die_ref die;
8611 switch (GET_CODE (rtl))
8614 /* Note that a CONST_INT rtx could represent either an integer or a
8615 floating-point constant. A CONST_INT is used whenever the constant
8616 will fit into a single word. In all such cases, the original mode
8617 of the constant value is wiped out, and the CONST_INT rtx is
8618 assigned VOIDmode. */
8619 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
8623 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8624 floating-point constant. A CONST_DOUBLE is used whenever the
8625 constant requires more than one word in order to be adequately
8626 represented. We output CONST_DOUBLEs as blocks. */
8628 register enum machine_mode mode = GET_MODE (rtl);
8630 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8632 register unsigned length = GET_MODE_SIZE (mode) / 4;
8633 long *array = (long *) xmalloc (sizeof (long) * length);
8636 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8640 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8644 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8649 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8656 add_AT_float (die, DW_AT_const_value, length, array);
8659 add_AT_long_long (die, DW_AT_const_value,
8660 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8665 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8671 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8675 /* In cases where an inlined instance of an inline function is passed
8676 the address of an `auto' variable (which is local to the caller) we
8677 can get a situation where the DECL_RTL of the artificial local
8678 variable (for the inlining) which acts as a stand-in for the
8679 corresponding formal parameter (of the inline function) will look
8680 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8681 exactly a compile-time constant expression, but it isn't the address
8682 of the (artificial) local variable either. Rather, it represents the
8683 *value* which the artificial local variable always has during its
8684 lifetime. We currently have no way to represent such quasi-constant
8685 values in Dwarf, so for now we just punt and generate nothing. */
8689 /* No other kinds of rtx should be possible here. */
8696 rtl_for_decl_location (decl)
8701 /* Here we have to decide where we are going to say the parameter "lives"
8702 (as far as the debugger is concerned). We only have a couple of
8703 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8705 DECL_RTL normally indicates where the parameter lives during most of the
8706 activation of the function. If optimization is enabled however, this
8707 could be either NULL or else a pseudo-reg. Both of those cases indicate
8708 that the parameter doesn't really live anywhere (as far as the code
8709 generation parts of GCC are concerned) during most of the function's
8710 activation. That will happen (for example) if the parameter is never
8711 referenced within the function.
8713 We could just generate a location descriptor here for all non-NULL
8714 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8715 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8716 where DECL_RTL is NULL or is a pseudo-reg.
8718 Note however that we can only get away with using DECL_INCOMING_RTL as
8719 a backup substitute for DECL_RTL in certain limited cases. In cases
8720 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8721 we can be sure that the parameter was passed using the same type as it is
8722 declared to have within the function, and that its DECL_INCOMING_RTL
8723 points us to a place where a value of that type is passed.
8725 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8726 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8727 because in these cases DECL_INCOMING_RTL points us to a value of some
8728 type which is *different* from the type of the parameter itself. Thus,
8729 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8730 such cases, the debugger would end up (for example) trying to fetch a
8731 `float' from a place which actually contains the first part of a
8732 `double'. That would lead to really incorrect and confusing
8733 output at debug-time.
8735 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8736 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8737 are a couple of exceptions however. On little-endian machines we can
8738 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8739 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8740 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8741 when (on a little-endian machine) a non-prototyped function has a
8742 parameter declared to be of type `short' or `char'. In such cases,
8743 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8744 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8745 passed `int' value. If the debugger then uses that address to fetch
8746 a `short' or a `char' (on a little-endian machine) the result will be
8747 the correct data, so we allow for such exceptional cases below.
8749 Note that our goal here is to describe the place where the given formal
8750 parameter lives during most of the function's activation (i.e. between
8751 the end of the prologue and the start of the epilogue). We'll do that
8752 as best as we can. Note however that if the given formal parameter is
8753 modified sometime during the execution of the function, then a stack
8754 backtrace (at debug-time) will show the function as having been
8755 called with the *new* value rather than the value which was
8756 originally passed in. This happens rarely enough that it is not
8757 a major problem, but it *is* a problem, and I'd like to fix it.
8759 A future version of dwarf2out.c may generate two additional
8760 attributes for any given DW_TAG_formal_parameter DIE which will
8761 describe the "passed type" and the "passed location" for the
8762 given formal parameter in addition to the attributes we now
8763 generate to indicate the "declared type" and the "active
8764 location" for each parameter. This additional set of attributes
8765 could be used by debuggers for stack backtraces. Separately, note
8766 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8767 NULL also. This happens (for example) for inlined-instances of
8768 inline function formal parameters which are never referenced.
8769 This really shouldn't be happening. All PARM_DECL nodes should
8770 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8771 doesn't currently generate these values for inlined instances of
8772 inline function parameters, so when we see such cases, we are
8773 just out-of-luck for the time being (until integrate.c
8776 /* Use DECL_RTL as the "location" unless we find something better. */
8777 rtl = DECL_RTL (decl);
8779 if (TREE_CODE (decl) == PARM_DECL)
8781 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8783 tree declared_type = type_main_variant (TREE_TYPE (decl));
8784 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8786 /* This decl represents a formal parameter which was optimized out.
8787 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8788 all* cases where (rtl == NULL_RTX) just below. */
8789 if (declared_type == passed_type)
8790 rtl = DECL_INCOMING_RTL (decl);
8791 else if (! BYTES_BIG_ENDIAN
8792 && TREE_CODE (declared_type) == INTEGER_TYPE
8793 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8794 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8795 rtl = DECL_INCOMING_RTL (decl);
8798 /* If the parm was passed in registers, but lives on the stack, then
8799 make a big endian correction if the mode of the type of the
8800 parameter is not the same as the mode of the rtl. */
8801 /* ??? This is the same series of checks that are made in dbxout.c before
8802 we reach the big endian correction code there. It isn't clear if all
8803 of these checks are necessary here, but keeping them all is the safe
8805 else if (GET_CODE (rtl) == MEM
8806 && XEXP (rtl, 0) != const0_rtx
8807 && ! CONSTANT_P (XEXP (rtl, 0))
8808 /* Not passed in memory. */
8809 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8810 /* Not passed by invisible reference. */
8811 && (GET_CODE (XEXP (rtl, 0)) != REG
8812 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8813 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8814 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8815 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8818 /* Big endian correction check. */
8820 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8821 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8824 int offset = (UNITS_PER_WORD
8825 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8826 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8827 plus_constant (XEXP (rtl, 0), offset));
8831 if (rtl != NULL_RTX)
8833 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8834 #ifdef LEAF_REG_REMAP
8835 if (current_function_uses_only_leaf_regs)
8836 leaf_renumber_regs_insn (rtl);
8843 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8844 data attribute for a variable or a parameter. We generate the
8845 DW_AT_const_value attribute only in those cases where the given variable
8846 or parameter does not have a true "location" either in memory or in a
8847 register. This can happen (for example) when a constant is passed as an
8848 actual argument in a call to an inline function. (It's possible that
8849 these things can crop up in other ways also.) Note that one type of
8850 constant value which can be passed into an inlined function is a constant
8851 pointer. This can happen for example if an actual argument in an inlined
8852 function call evaluates to a compile-time constant address. */
8855 add_location_or_const_value_attribute (die, decl)
8856 register dw_die_ref die;
8861 if (TREE_CODE (decl) == ERROR_MARK)
8864 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8867 rtl = rtl_for_decl_location (decl);
8868 if (rtl == NULL_RTX)
8871 switch (GET_CODE (rtl))
8874 /* The address of a variable that was optimized away; don't emit
8885 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8886 add_const_value_attribute (die, rtl);
8893 add_AT_location_description (die, DW_AT_location, rtl);
8901 /* If we don't have a copy of this variable in memory for some reason (such
8902 as a C++ member constant that doesn't have an out-of-line definition),
8903 we should tell the debugger about the constant value. */
8906 tree_add_const_value_attribute (var_die, decl)
8910 tree init = DECL_INITIAL (decl);
8911 tree type = TREE_TYPE (decl);
8913 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8914 && initializer_constant_valid_p (init, type) == null_pointer_node)
8919 switch (TREE_CODE (type))
8922 if (host_integerp (init, 0))
8923 add_AT_unsigned (var_die, DW_AT_const_value,
8924 TREE_INT_CST_LOW (init));
8926 add_AT_long_long (var_die, DW_AT_const_value,
8927 TREE_INT_CST_HIGH (init),
8928 TREE_INT_CST_LOW (init));
8935 /* Generate an DW_AT_name attribute given some string value to be included as
8936 the value of the attribute. */
8939 add_name_attribute (die, name_string)
8940 register dw_die_ref die;
8941 register const char *name_string;
8943 if (name_string != NULL && *name_string != 0)
8945 if (demangle_name_func)
8946 name_string = (*demangle_name_func) (name_string);
8948 add_AT_string (die, DW_AT_name, name_string);
8952 /* Given a tree node describing an array bound (either lower or upper) output
8953 a representation for that bound. */
8956 add_bound_info (subrange_die, bound_attr, bound)
8957 register dw_die_ref subrange_die;
8958 register enum dwarf_attribute bound_attr;
8959 register tree bound;
8961 /* If this is an Ada unconstrained array type, then don't emit any debug
8962 info because the array bounds are unknown. They are parameterized when
8963 the type is instantiated. */
8964 if (contains_placeholder_p (bound))
8967 switch (TREE_CODE (bound))
8972 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8974 if (! host_integerp (bound, 0)
8975 || (bound_attr == DW_AT_lower_bound
8976 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8977 || (is_fortran () && integer_onep (bound)))))
8978 /* use the default */
8981 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8986 case NON_LVALUE_EXPR:
8987 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8991 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8992 access the upper bound values may be bogus. If they refer to a
8993 register, they may only describe how to get at these values at the
8994 points in the generated code right after they have just been
8995 computed. Worse yet, in the typical case, the upper bound values
8996 will not even *be* computed in the optimized code (though the
8997 number of elements will), so these SAVE_EXPRs are entirely
8998 bogus. In order to compensate for this fact, we check here to see
8999 if optimization is enabled, and if so, we don't add an attribute
9000 for the (unknown and unknowable) upper bound. This should not
9001 cause too much trouble for existing (stupid?) debuggers because
9002 they have to deal with empty upper bounds location descriptions
9003 anyway in order to be able to deal with incomplete array types.
9004 Of course an intelligent debugger (GDB?) should be able to
9005 comprehend that a missing upper bound specification in a array
9006 type used for a storage class `auto' local array variable
9007 indicates that the upper bound is both unknown (at compile- time)
9008 and unknowable (at run-time) due to optimization.
9010 We assume that a MEM rtx is safe because gcc wouldn't put the
9011 value there unless it was going to be used repeatedly in the
9012 function, i.e. for cleanups. */
9013 if (! optimize || (SAVE_EXPR_RTL (bound)
9014 && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
9016 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
9017 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
9018 register rtx loc = SAVE_EXPR_RTL (bound);
9020 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9021 it references an outer function's frame. */
9023 if (GET_CODE (loc) == MEM)
9025 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9027 if (XEXP (loc, 0) != new_addr)
9028 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9031 add_AT_flag (decl_die, DW_AT_artificial, 1);
9032 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9033 add_AT_location_description (decl_die, DW_AT_location, loc);
9034 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9037 /* Else leave out the attribute. */
9043 dw_die_ref decl_die = lookup_decl_die (bound);
9045 /* ??? Can this happen, or should the variable have been bound
9046 first? Probably it can, since I imagine that we try to create
9047 the types of parameters in the order in which they exist in
9048 the list, and won't have created a forward reference to a
9050 if (decl_die != NULL)
9051 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9057 /* Otherwise try to create a stack operation procedure to
9058 evaluate the value of the array bound. */
9060 dw_die_ref ctx, decl_die;
9061 dw_loc_descr_ref loc;
9063 loc = loc_descriptor_from_tree (bound, 0);
9067 ctx = lookup_decl_die (current_function_decl);
9069 decl_die = new_die (DW_TAG_variable, ctx);
9070 add_AT_flag (decl_die, DW_AT_artificial, 1);
9071 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9072 add_AT_loc (decl_die, DW_AT_location, loc);
9074 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9080 /* Note that the block of subscript information for an array type also
9081 includes information about the element type of type given array type. */
9084 add_subscript_info (type_die, type)
9085 register dw_die_ref type_die;
9088 #ifndef MIPS_DEBUGGING_INFO
9089 register unsigned dimension_number;
9091 register tree lower, upper;
9092 register dw_die_ref subrange_die;
9094 /* The GNU compilers represent multidimensional array types as sequences of
9095 one dimensional array types whose element types are themselves array
9096 types. Here we squish that down, so that each multidimensional array
9097 type gets only one array_type DIE in the Dwarf debugging info. The draft
9098 Dwarf specification say that we are allowed to do this kind of
9099 compression in C (because there is no difference between an array or
9100 arrays and a multidimensional array in C) but for other source languages
9101 (e.g. Ada) we probably shouldn't do this. */
9103 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9104 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9105 We work around this by disabling this feature. See also
9106 gen_array_type_die. */
9107 #ifndef MIPS_DEBUGGING_INFO
9108 for (dimension_number = 0;
9109 TREE_CODE (type) == ARRAY_TYPE;
9110 type = TREE_TYPE (type), dimension_number++)
9113 register tree domain = TYPE_DOMAIN (type);
9115 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9116 and (in GNU C only) variable bounds. Handle all three forms
9118 subrange_die = new_die (DW_TAG_subrange_type, type_die);
9121 /* We have an array type with specified bounds. */
9122 lower = TYPE_MIN_VALUE (domain);
9123 upper = TYPE_MAX_VALUE (domain);
9125 /* define the index type. */
9126 if (TREE_TYPE (domain))
9128 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9129 TREE_TYPE field. We can't emit debug info for this
9130 because it is an unnamed integral type. */
9131 if (TREE_CODE (domain) == INTEGER_TYPE
9132 && TYPE_NAME (domain) == NULL_TREE
9133 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9134 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9137 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9141 /* ??? If upper is NULL, the array has unspecified length,
9142 but it does have a lower bound. This happens with Fortran
9144 Since the debugger is definitely going to need to know N
9145 to produce useful results, go ahead and output the lower
9146 bound solo, and hope the debugger can cope. */
9148 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9150 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9153 /* We have an array type with an unspecified length. The DWARF-2
9154 spec does not say how to handle this; let's just leave out the
9158 #ifndef MIPS_DEBUGGING_INFO
9164 add_byte_size_attribute (die, tree_node)
9166 register tree tree_node;
9168 register unsigned size;
9170 switch (TREE_CODE (tree_node))
9178 case QUAL_UNION_TYPE:
9179 size = int_size_in_bytes (tree_node);
9182 /* For a data member of a struct or union, the DW_AT_byte_size is
9183 generally given as the number of bytes normally allocated for an
9184 object of the *declared* type of the member itself. This is true
9185 even for bit-fields. */
9186 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9192 /* Note that `size' might be -1 when we get to this point. If it is, that
9193 indicates that the byte size of the entity in question is variable. We
9194 have no good way of expressing this fact in Dwarf at the present time,
9195 so just let the -1 pass on through. */
9197 add_AT_unsigned (die, DW_AT_byte_size, size);
9200 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9201 which specifies the distance in bits from the highest order bit of the
9202 "containing object" for the bit-field to the highest order bit of the
9205 For any given bit-field, the "containing object" is a hypothetical
9206 object (of some integral or enum type) within which the given bit-field
9207 lives. The type of this hypothetical "containing object" is always the
9208 same as the declared type of the individual bit-field itself. The
9209 determination of the exact location of the "containing object" for a
9210 bit-field is rather complicated. It's handled by the
9211 `field_byte_offset' function (above).
9213 Note that it is the size (in bytes) of the hypothetical "containing object"
9214 which will be given in the DW_AT_byte_size attribute for this bit-field.
9215 (See `byte_size_attribute' above). */
9218 add_bit_offset_attribute (die, decl)
9219 register dw_die_ref die;
9222 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9223 tree type = DECL_BIT_FIELD_TYPE (decl);
9224 HOST_WIDE_INT bitpos_int;
9225 HOST_WIDE_INT highest_order_object_bit_offset;
9226 HOST_WIDE_INT highest_order_field_bit_offset;
9227 HOST_WIDE_INT unsigned bit_offset;
9229 /* Must be a field and a bit field. */
9231 || TREE_CODE (decl) != FIELD_DECL)
9234 /* We can't yet handle bit-fields whose offsets are variable, so if we
9235 encounter such things, just return without generating any attribute
9236 whatsoever. Likewise for variable or too large size. */
9237 if (! host_integerp (bit_position (decl), 0)
9238 || ! host_integerp (DECL_SIZE (decl), 1))
9241 bitpos_int = int_bit_position (decl);
9243 /* Note that the bit offset is always the distance (in bits) from the
9244 highest-order bit of the "containing object" to the highest-order bit of
9245 the bit-field itself. Since the "high-order end" of any object or field
9246 is different on big-endian and little-endian machines, the computation
9247 below must take account of these differences. */
9248 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9249 highest_order_field_bit_offset = bitpos_int;
9251 if (! BYTES_BIG_ENDIAN)
9253 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9254 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9258 = (! BYTES_BIG_ENDIAN
9259 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9260 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9262 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9265 /* For a FIELD_DECL node which represents a bit field, output an attribute
9266 which specifies the length in bits of the given field. */
9269 add_bit_size_attribute (die, decl)
9270 register dw_die_ref die;
9273 /* Must be a field and a bit field. */
9274 if (TREE_CODE (decl) != FIELD_DECL
9275 || ! DECL_BIT_FIELD_TYPE (decl))
9278 if (host_integerp (DECL_SIZE (decl), 1))
9279 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9282 /* If the compiled language is ANSI C, then add a 'prototyped'
9283 attribute, if arg types are given for the parameters of a function. */
9286 add_prototyped_attribute (die, func_type)
9287 register dw_die_ref die;
9288 register tree func_type;
9290 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9291 && TYPE_ARG_TYPES (func_type) != NULL)
9292 add_AT_flag (die, DW_AT_prototyped, 1);
9295 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9296 by looking in either the type declaration or object declaration
9300 add_abstract_origin_attribute (die, origin)
9301 register dw_die_ref die;
9302 register tree origin;
9304 dw_die_ref origin_die = NULL;
9306 if (TREE_CODE (origin) != FUNCTION_DECL)
9308 /* We may have gotten separated from the block for the inlined
9309 function, if we're in an exception handler or some such; make
9310 sure that the abstract function has been written out.
9312 Doing this for nested functions is wrong, however; functions are
9313 distinct units, and our context might not even be inline. */
9316 fn = TYPE_STUB_DECL (fn);
9317 fn = decl_function_context (fn);
9319 gen_abstract_function (fn);
9322 if (DECL_P (origin))
9323 origin_die = lookup_decl_die (origin);
9324 else if (TYPE_P (origin))
9325 origin_die = lookup_type_die (origin);
9327 if (origin_die == NULL)
9330 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9333 /* We do not currently support the pure_virtual attribute. */
9336 add_pure_or_virtual_attribute (die, func_decl)
9337 register dw_die_ref die;
9338 register tree func_decl;
9340 if (DECL_VINDEX (func_decl))
9342 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9344 if (host_integerp (DECL_VINDEX (func_decl), 0))
9345 add_AT_loc (die, DW_AT_vtable_elem_location,
9346 new_loc_descr (DW_OP_constu,
9347 tree_low_cst (DECL_VINDEX (func_decl), 0),
9350 /* GNU extension: Record what type this method came from originally. */
9351 if (debug_info_level > DINFO_LEVEL_TERSE)
9352 add_AT_die_ref (die, DW_AT_containing_type,
9353 lookup_type_die (DECL_CONTEXT (func_decl)));
9357 /* Add source coordinate attributes for the given decl. */
9360 add_src_coords_attributes (die, decl)
9361 register dw_die_ref die;
9364 register unsigned file_index = lookup_filename (&decl_file_table,
9365 DECL_SOURCE_FILE (decl));
9367 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9368 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9371 /* Add an DW_AT_name attribute and source coordinate attribute for the
9372 given decl, but only if it actually has a name. */
9375 add_name_and_src_coords_attributes (die, decl)
9376 register dw_die_ref die;
9379 register tree decl_name;
9381 decl_name = DECL_NAME (decl);
9382 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9384 add_name_attribute (die, dwarf2_name (decl, 0));
9385 if (! DECL_ARTIFICIAL (decl))
9386 add_src_coords_attributes (die, decl);
9388 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9389 && TREE_PUBLIC (decl)
9390 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
9391 add_AT_string (die, DW_AT_MIPS_linkage_name,
9392 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9396 /* Push a new declaration scope. */
9399 push_decl_scope (scope)
9402 /* Make room in the decl_scope_table, if necessary. */
9403 if (decl_scope_table_allocated == decl_scope_depth)
9405 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
9407 = (tree *) xrealloc (decl_scope_table,
9408 decl_scope_table_allocated * sizeof (tree));
9411 decl_scope_table[decl_scope_depth] = scope;
9415 /* Pop a declaration scope. */
9419 if (decl_scope_depth <= 0)
9424 /* Return the DIE for the scope that immediately contains this type.
9425 Non-named types get global scope. Named types nested in other
9426 types get their containing scope if it's open, or global scope
9427 otherwise. All other types (i.e. function-local named types) get
9428 the current active scope. */
9431 scope_die_for (t, context_die)
9433 register dw_die_ref context_die;
9435 register dw_die_ref scope_die = NULL;
9436 register tree containing_scope;
9439 /* Non-types always go in the current scope. */
9443 containing_scope = TYPE_CONTEXT (t);
9445 /* Ignore namespaces for the moment. */
9446 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9447 containing_scope = NULL_TREE;
9449 /* Ignore function type "scopes" from the C frontend. They mean that
9450 a tagged type is local to a parmlist of a function declarator, but
9451 that isn't useful to DWARF. */
9452 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9453 containing_scope = NULL_TREE;
9455 if (containing_scope == NULL_TREE)
9456 scope_die = comp_unit_die;
9457 else if (TYPE_P (containing_scope))
9459 /* For types, we can just look up the appropriate DIE. But
9460 first we check to see if we're in the middle of emitting it
9461 so we know where the new DIE should go. */
9463 for (i = decl_scope_depth - 1; i >= 0; --i)
9464 if (decl_scope_table[i] == containing_scope)
9469 if (debug_info_level > DINFO_LEVEL_TERSE
9470 && !TREE_ASM_WRITTEN (containing_scope))
9473 /* If none of the current dies are suitable, we get file scope. */
9474 scope_die = comp_unit_die;
9477 scope_die = lookup_type_die (containing_scope);
9480 scope_die = context_die;
9485 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9487 static inline int local_scope_p PARAMS ((dw_die_ref));
9489 local_scope_p (context_die)
9490 dw_die_ref context_die;
9492 for (; context_die; context_die = context_die->die_parent)
9493 if (context_die->die_tag == DW_TAG_inlined_subroutine
9494 || context_die->die_tag == DW_TAG_subprogram)
9499 /* Returns nonzero iff CONTEXT_DIE is a class. */
9501 static inline int class_scope_p PARAMS ((dw_die_ref));
9503 class_scope_p (context_die)
9504 dw_die_ref context_die;
9507 && (context_die->die_tag == DW_TAG_structure_type
9508 || context_die->die_tag == DW_TAG_union_type));
9511 /* Many forms of DIEs require a "type description" attribute. This
9512 routine locates the proper "type descriptor" die for the type given
9513 by 'type', and adds an DW_AT_type attribute below the given die. */
9516 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9517 register dw_die_ref object_die;
9519 register int decl_const;
9520 register int decl_volatile;
9521 register dw_die_ref context_die;
9523 register enum tree_code code = TREE_CODE (type);
9524 register dw_die_ref type_die = NULL;
9526 /* ??? If this type is an unnamed subrange type of an integral or
9527 floating-point type, use the inner type. This is because we have no
9528 support for unnamed types in base_type_die. This can happen if this is
9529 an Ada subrange type. Correct solution is emit a subrange type die. */
9530 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9531 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9532 type = TREE_TYPE (type), code = TREE_CODE (type);
9534 if (code == ERROR_MARK)
9537 /* Handle a special case. For functions whose return type is void, we
9538 generate *no* type attribute. (Note that no object may have type
9539 `void', so this only applies to function return types). */
9540 if (code == VOID_TYPE)
9543 type_die = modified_type_die (type,
9544 decl_const || TYPE_READONLY (type),
9545 decl_volatile || TYPE_VOLATILE (type),
9547 if (type_die != NULL)
9548 add_AT_die_ref (object_die, DW_AT_type, type_die);
9551 /* Given a tree pointer to a struct, class, union, or enum type node, return
9552 a pointer to the (string) tag name for the given type, or zero if the type
9553 was declared without a tag. */
9559 register const char *name = 0;
9561 if (TYPE_NAME (type) != 0)
9563 register tree t = 0;
9565 /* Find the IDENTIFIER_NODE for the type name. */
9566 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9567 t = TYPE_NAME (type);
9569 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9570 a TYPE_DECL node, regardless of whether or not a `typedef' was
9572 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9573 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9574 t = DECL_NAME (TYPE_NAME (type));
9576 /* Now get the name as a string, or invent one. */
9578 name = IDENTIFIER_POINTER (t);
9581 return (name == 0 || *name == '\0') ? 0 : name;
9584 /* Return the type associated with a data member, make a special check
9585 for bit field types. */
9588 member_declared_type (member)
9589 register tree member;
9591 return (DECL_BIT_FIELD_TYPE (member)
9592 ? DECL_BIT_FIELD_TYPE (member)
9593 : TREE_TYPE (member));
9596 /* Get the decl's label, as described by its RTL. This may be different
9597 from the DECL_NAME name used in the source file. */
9601 decl_start_label (decl)
9606 x = DECL_RTL (decl);
9607 if (GET_CODE (x) != MEM)
9611 if (GET_CODE (x) != SYMBOL_REF)
9614 fnname = XSTR (x, 0);
9619 /* These routines generate the internal representation of the DIE's for
9620 the compilation unit. Debugging information is collected by walking
9621 the declaration trees passed in from dwarf2out_decl(). */
9624 gen_array_type_die (type, context_die)
9626 register dw_die_ref context_die;
9628 register dw_die_ref scope_die = scope_die_for (type, context_die);
9629 register dw_die_ref array_die;
9630 register tree element_type;
9632 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9633 the inner array type comes before the outer array type. Thus we must
9634 call gen_type_die before we call new_die. See below also. */
9635 #ifdef MIPS_DEBUGGING_INFO
9636 gen_type_die (TREE_TYPE (type), context_die);
9639 array_die = new_die (DW_TAG_array_type, scope_die);
9642 /* We default the array ordering. SDB will probably do
9643 the right things even if DW_AT_ordering is not present. It's not even
9644 an issue until we start to get into multidimensional arrays anyway. If
9645 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9646 then we'll have to put the DW_AT_ordering attribute back in. (But if
9647 and when we find out that we need to put these in, we will only do so
9648 for multidimensional arrays. */
9649 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9652 #ifdef MIPS_DEBUGGING_INFO
9653 /* The SGI compilers handle arrays of unknown bound by setting
9654 AT_declaration and not emitting any subrange DIEs. */
9655 if (! TYPE_DOMAIN (type))
9656 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9659 add_subscript_info (array_die, type);
9661 add_name_attribute (array_die, type_tag (type));
9662 equate_type_number_to_die (type, array_die);
9664 /* Add representation of the type of the elements of this array type. */
9665 element_type = TREE_TYPE (type);
9667 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9668 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9669 We work around this by disabling this feature. See also
9670 add_subscript_info. */
9671 #ifndef MIPS_DEBUGGING_INFO
9672 while (TREE_CODE (element_type) == ARRAY_TYPE)
9673 element_type = TREE_TYPE (element_type);
9675 gen_type_die (element_type, context_die);
9678 add_type_attribute (array_die, element_type, 0, 0, context_die);
9682 gen_set_type_die (type, context_die)
9684 register dw_die_ref context_die;
9686 register dw_die_ref type_die
9687 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9689 equate_type_number_to_die (type, type_die);
9690 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9695 gen_entry_point_die (decl, context_die)
9697 register dw_die_ref context_die;
9699 register tree origin = decl_ultimate_origin (decl);
9700 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9702 add_abstract_origin_attribute (decl_die, origin);
9705 add_name_and_src_coords_attributes (decl_die, decl);
9706 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9710 if (DECL_ABSTRACT (decl))
9711 equate_decl_number_to_die (decl, decl_die);
9713 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9717 /* Remember a type in the incomplete_types_list. */
9720 add_incomplete_type (type)
9723 if (incomplete_types == incomplete_types_allocated)
9725 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9726 incomplete_types_list
9727 = (tree *) xrealloc (incomplete_types_list,
9728 sizeof (tree) * incomplete_types_allocated);
9731 incomplete_types_list[incomplete_types++] = type;
9734 /* Walk through the list of incomplete types again, trying once more to
9735 emit full debugging info for them. */
9738 retry_incomplete_types ()
9742 while (incomplete_types)
9745 type = incomplete_types_list[incomplete_types];
9746 gen_type_die (type, comp_unit_die);
9750 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9753 gen_inlined_enumeration_type_die (type, context_die)
9755 register dw_die_ref context_die;
9757 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9759 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9760 be incomplete and such types are not marked. */
9761 add_abstract_origin_attribute (type_die, type);
9764 /* Generate a DIE to represent an inlined instance of a structure type. */
9767 gen_inlined_structure_type_die (type, context_die)
9769 register dw_die_ref context_die;
9771 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9773 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9774 be incomplete and such types are not marked. */
9775 add_abstract_origin_attribute (type_die, type);
9778 /* Generate a DIE to represent an inlined instance of a union type. */
9781 gen_inlined_union_type_die (type, context_die)
9783 register dw_die_ref context_die;
9785 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9787 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9788 be incomplete and such types are not marked. */
9789 add_abstract_origin_attribute (type_die, type);
9792 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9793 include all of the information about the enumeration values also. Each
9794 enumerated type name/value is listed as a child of the enumerated type
9798 gen_enumeration_type_die (type, context_die)
9800 register dw_die_ref context_die;
9802 register dw_die_ref type_die = lookup_type_die (type);
9804 if (type_die == NULL)
9806 type_die = new_die (DW_TAG_enumeration_type,
9807 scope_die_for (type, context_die));
9808 equate_type_number_to_die (type, type_die);
9809 add_name_attribute (type_die, type_tag (type));
9811 else if (! TYPE_SIZE (type))
9814 remove_AT (type_die, DW_AT_declaration);
9816 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9817 given enum type is incomplete, do not generate the DW_AT_byte_size
9818 attribute or the DW_AT_element_list attribute. */
9819 if (TYPE_SIZE (type))
9823 TREE_ASM_WRITTEN (type) = 1;
9824 add_byte_size_attribute (type_die, type);
9825 if (TYPE_STUB_DECL (type) != NULL_TREE)
9826 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9828 /* If the first reference to this type was as the return type of an
9829 inline function, then it may not have a parent. Fix this now. */
9830 if (type_die->die_parent == NULL)
9831 add_child_die (scope_die_for (type, context_die), type_die);
9833 for (link = TYPE_FIELDS (type);
9834 link != NULL; link = TREE_CHAIN (link))
9836 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9838 add_name_attribute (enum_die,
9839 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9841 if (host_integerp (TREE_VALUE (link), 0))
9843 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9844 add_AT_int (enum_die, DW_AT_const_value,
9845 tree_low_cst (TREE_VALUE (link), 0));
9847 add_AT_unsigned (enum_die, DW_AT_const_value,
9848 tree_low_cst (TREE_VALUE (link), 0));
9853 add_AT_flag (type_die, DW_AT_declaration, 1);
9856 /* Generate a DIE to represent either a real live formal parameter decl or to
9857 represent just the type of some formal parameter position in some function
9860 Note that this routine is a bit unusual because its argument may be a
9861 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9862 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9863 node. If it's the former then this function is being called to output a
9864 DIE to represent a formal parameter object (or some inlining thereof). If
9865 it's the latter, then this function is only being called to output a
9866 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9867 argument type of some subprogram type. */
9870 gen_formal_parameter_die (node, context_die)
9872 register dw_die_ref context_die;
9874 register dw_die_ref parm_die
9875 = new_die (DW_TAG_formal_parameter, context_die);
9876 register tree origin;
9878 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9881 origin = decl_ultimate_origin (node);
9883 add_abstract_origin_attribute (parm_die, origin);
9886 add_name_and_src_coords_attributes (parm_die, node);
9887 add_type_attribute (parm_die, TREE_TYPE (node),
9888 TREE_READONLY (node),
9889 TREE_THIS_VOLATILE (node),
9891 if (DECL_ARTIFICIAL (node))
9892 add_AT_flag (parm_die, DW_AT_artificial, 1);
9895 equate_decl_number_to_die (node, parm_die);
9896 if (! DECL_ABSTRACT (node))
9897 add_location_or_const_value_attribute (parm_die, node);
9902 /* We were called with some kind of a ..._TYPE node. */
9903 add_type_attribute (parm_die, node, 0, 0, context_die);
9913 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9914 at the end of an (ANSI prototyped) formal parameters list. */
9917 gen_unspecified_parameters_die (decl_or_type, context_die)
9918 register tree decl_or_type ATTRIBUTE_UNUSED;
9919 register dw_die_ref context_die;
9921 new_die (DW_TAG_unspecified_parameters, context_die);
9924 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9925 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9926 parameters as specified in some function type specification (except for
9927 those which appear as part of a function *definition*). */
9930 gen_formal_types_die (function_or_method_type, context_die)
9931 register tree function_or_method_type;
9932 register dw_die_ref context_die;
9935 register tree formal_type = NULL;
9936 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9939 /* In the case where we are generating a formal types list for a C++
9940 non-static member function type, skip over the first thing on the
9941 TYPE_ARG_TYPES list because it only represents the type of the hidden
9942 `this pointer'. The debugger should be able to figure out (without
9943 being explicitly told) that this non-static member function type takes a
9944 `this pointer' and should be able to figure what the type of that hidden
9945 parameter is from the DW_AT_member attribute of the parent
9946 DW_TAG_subroutine_type DIE. */
9947 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
9948 first_parm_type = TREE_CHAIN (first_parm_type);
9951 /* Make our first pass over the list of formal parameter types and output a
9952 DW_TAG_formal_parameter DIE for each one. */
9953 for (link = first_parm_type; link; link = TREE_CHAIN (link))
9955 register dw_die_ref parm_die;
9957 formal_type = TREE_VALUE (link);
9958 if (formal_type == void_type_node)
9961 /* Output a (nameless) DIE to represent the formal parameter itself. */
9962 parm_die = gen_formal_parameter_die (formal_type, context_die);
9963 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
9964 && link == first_parm_type)
9965 add_AT_flag (parm_die, DW_AT_artificial, 1);
9968 /* If this function type has an ellipsis, add a
9969 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9970 if (formal_type != void_type_node)
9971 gen_unspecified_parameters_die (function_or_method_type, context_die);
9973 /* Make our second (and final) pass over the list of formal parameter types
9974 and output DIEs to represent those types (as necessary). */
9975 for (link = TYPE_ARG_TYPES (function_or_method_type);
9977 link = TREE_CHAIN (link))
9979 formal_type = TREE_VALUE (link);
9980 if (formal_type == void_type_node)
9983 gen_type_die (formal_type, context_die);
9987 /* We want to generate the DIE for TYPE so that we can generate the
9988 die for MEMBER, which has been defined; we will need to refer back
9989 to the member declaration nested within TYPE. If we're trying to
9990 generate minimal debug info for TYPE, processing TYPE won't do the
9991 trick; we need to attach the member declaration by hand. */
9994 gen_type_die_for_member (type, member, context_die)
9996 dw_die_ref context_die;
9998 gen_type_die (type, context_die);
10000 /* If we're trying to avoid duplicate debug info, we may not have
10001 emitted the member decl for this function. Emit it now. */
10002 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
10003 && ! lookup_decl_die (member))
10005 if (decl_ultimate_origin (member))
10008 push_decl_scope (type);
10009 if (TREE_CODE (member) == FUNCTION_DECL)
10010 gen_subprogram_die (member, lookup_type_die (type));
10012 gen_variable_die (member, lookup_type_die (type));
10017 /* Generate the DWARF2 info for the "abstract" instance
10018 of a function which we may later generate inlined and/or
10019 out-of-line instances of. */
10022 gen_abstract_function (decl)
10025 register dw_die_ref old_die = lookup_decl_die (decl);
10028 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10029 /* We've already generated the abstract instance. */
10032 save_fn = current_function_decl;
10033 current_function_decl = decl;
10035 set_decl_abstract_flags (decl, 1);
10036 dwarf2out_decl (decl);
10037 set_decl_abstract_flags (decl, 0);
10039 current_function_decl = save_fn;
10042 /* Generate a DIE to represent a declared function (either file-scope or
10046 gen_subprogram_die (decl, context_die)
10047 register tree decl;
10048 register dw_die_ref context_die;
10050 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10051 register tree origin = decl_ultimate_origin (decl);
10052 register dw_die_ref subr_die;
10053 register rtx fp_reg;
10054 register tree fn_arg_types;
10055 register tree outer_scope;
10056 register dw_die_ref old_die = lookup_decl_die (decl);
10057 register int declaration = (current_function_decl != decl
10058 || class_scope_p (context_die));
10060 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
10061 be true, if we started to generate the abstract instance of an inline,
10062 decided to output its containing class, and proceeded to emit the
10063 declaration of the inline from the member list for the class. In that
10064 case, `declaration' takes priority; we'll get back to the abstract
10065 instance when we're done with the class. */
10067 /* The class-scope declaration DIE must be the primary DIE. */
10068 if (origin && declaration && class_scope_p (context_die))
10075 if (origin != NULL)
10077 if (declaration && ! local_scope_p (context_die))
10080 /* Fixup die_parent for the abstract instance of a nested
10081 inline function. */
10082 if (old_die && old_die->die_parent == NULL)
10083 add_child_die (context_die, old_die);
10085 subr_die = new_die (DW_TAG_subprogram, context_die);
10086 add_abstract_origin_attribute (subr_die, origin);
10088 else if (old_die && DECL_ABSTRACT (decl)
10089 && get_AT_unsigned (old_die, DW_AT_inline))
10091 /* This must be a redefinition of an extern inline function.
10092 We can just reuse the old die here. */
10093 subr_die = old_die;
10095 /* Clear out the inlined attribute and parm types. */
10096 remove_AT (subr_die, DW_AT_inline);
10097 remove_children (subr_die);
10101 register unsigned file_index
10102 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
10104 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
10106 /* ??? This can happen if there is a bug in the program, for
10107 instance, if it has duplicate function definitions. Ideally,
10108 we should detect this case and ignore it. For now, if we have
10109 already reported an error, any error at all, then assume that
10110 we got here because of a input error, not a dwarf2 bug. */
10116 /* If the definition comes from the same place as the declaration,
10117 maybe use the old DIE. We always want the DIE for this function
10118 that has the *_pc attributes to be under comp_unit_die so the
10119 debugger can find it. We also need to do this for abstract
10120 instances of inlines, since the spec requires the out-of-line copy
10121 to have the same parent. For local class methods, this doesn't
10122 apply; we just use the old DIE. */
10123 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10124 && (DECL_ARTIFICIAL (decl)
10125 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10126 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10127 == (unsigned) DECL_SOURCE_LINE (decl)))))
10129 subr_die = old_die;
10131 /* Clear out the declaration attribute and the parm types. */
10132 remove_AT (subr_die, DW_AT_declaration);
10133 remove_children (subr_die);
10137 subr_die = new_die (DW_TAG_subprogram, context_die);
10138 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10139 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10140 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10141 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10142 != (unsigned) DECL_SOURCE_LINE (decl))
10144 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10149 subr_die = new_die (DW_TAG_subprogram, context_die);
10151 if (TREE_PUBLIC (decl))
10152 add_AT_flag (subr_die, DW_AT_external, 1);
10154 add_name_and_src_coords_attributes (subr_die, decl);
10155 if (debug_info_level > DINFO_LEVEL_TERSE)
10157 register tree type = TREE_TYPE (decl);
10159 add_prototyped_attribute (subr_die, type);
10160 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
10163 add_pure_or_virtual_attribute (subr_die, decl);
10164 if (DECL_ARTIFICIAL (decl))
10165 add_AT_flag (subr_die, DW_AT_artificial, 1);
10166 if (TREE_PROTECTED (decl))
10167 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10168 else if (TREE_PRIVATE (decl))
10169 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10175 add_AT_flag (subr_die, DW_AT_declaration, 1);
10177 /* The first time we see a member function, it is in the context of
10178 the class to which it belongs. We make sure of this by emitting
10179 the class first. The next time is the definition, which is
10180 handled above. The two may come from the same source text. */
10181 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10182 equate_decl_number_to_die (decl, subr_die);
10184 else if (DECL_ABSTRACT (decl))
10186 if (DECL_INLINE (decl) && !flag_no_inline)
10188 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10189 inline functions, but not for extern inline functions.
10190 We can't get this completely correct because information
10191 about whether the function was declared inline is not
10193 if (DECL_DEFER_OUTPUT (decl))
10194 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10196 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10199 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10201 equate_decl_number_to_die (decl, subr_die);
10203 else if (!DECL_EXTERNAL (decl))
10205 if (origin == NULL_TREE)
10206 equate_decl_number_to_die (decl, subr_die);
10208 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10209 current_funcdef_number);
10210 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10211 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10212 current_funcdef_number);
10213 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10215 add_pubname (decl, subr_die);
10216 add_arange (decl, subr_die);
10218 #ifdef MIPS_DEBUGGING_INFO
10219 /* Add a reference to the FDE for this routine. */
10220 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10223 /* Define the "frame base" location for this routine. We use the
10224 frame pointer or stack pointer registers, since the RTL for local
10225 variables is relative to one of them. */
10227 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10228 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10231 /* ??? This fails for nested inline functions, because context_display
10232 is not part of the state saved/restored for inline functions. */
10233 if (current_function_needs_context)
10234 add_AT_location_description (subr_die, DW_AT_static_link,
10235 lookup_static_chain (decl));
10239 /* Now output descriptions of the arguments for this function. This gets
10240 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10241 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10242 `...' at the end of the formal parameter list. In order to find out if
10243 there was a trailing ellipsis or not, we must instead look at the type
10244 associated with the FUNCTION_DECL. This will be a node of type
10245 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10246 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10247 an ellipsis at the end. */
10249 /* In the case where we are describing a mere function declaration, all we
10250 need to do here (and all we *can* do here) is to describe the *types* of
10251 its formal parameters. */
10252 if (debug_info_level <= DINFO_LEVEL_TERSE)
10254 else if (declaration)
10255 gen_formal_types_die (TREE_TYPE (decl), subr_die);
10258 /* Generate DIEs to represent all known formal parameters */
10259 register tree arg_decls = DECL_ARGUMENTS (decl);
10260 register tree parm;
10262 /* When generating DIEs, generate the unspecified_parameters DIE
10263 instead if we come across the arg "__builtin_va_alist" */
10264 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10265 if (TREE_CODE (parm) == PARM_DECL)
10267 if (DECL_NAME (parm)
10268 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10269 "__builtin_va_alist"))
10270 gen_unspecified_parameters_die (parm, subr_die);
10272 gen_decl_die (parm, subr_die);
10275 /* Decide whether we need a unspecified_parameters DIE at the end.
10276 There are 2 more cases to do this for: 1) the ansi ... declaration -
10277 this is detectable when the end of the arg list is not a
10278 void_type_node 2) an unprototyped function declaration (not a
10279 definition). This just means that we have no info about the
10280 parameters at all. */
10281 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10282 if (fn_arg_types != NULL)
10284 /* this is the prototyped case, check for ... */
10285 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10286 gen_unspecified_parameters_die (decl, subr_die);
10288 else if (DECL_INITIAL (decl) == NULL_TREE)
10289 gen_unspecified_parameters_die (decl, subr_die);
10292 /* Output Dwarf info for all of the stuff within the body of the function
10293 (if it has one - it may be just a declaration). */
10294 outer_scope = DECL_INITIAL (decl);
10296 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
10297 node created to represent a function. This outermost BLOCK actually
10298 represents the outermost binding contour for the function, i.e. the
10299 contour in which the function's formal parameters and labels get
10300 declared. Curiously, it appears that the front end doesn't actually
10301 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
10302 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
10303 list for the function instead.) The BLOCK_VARS list for the
10304 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
10305 the function however, and we output DWARF info for those in
10306 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
10307 node representing the function's outermost pair of curly braces, and
10308 any blocks used for the base and member initializers of a C++
10309 constructor function. */
10310 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10312 current_function_has_inlines = 0;
10313 decls_for_scope (outer_scope, subr_die, 0);
10315 #if 0 && defined (MIPS_DEBUGGING_INFO)
10316 if (current_function_has_inlines)
10318 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10319 if (! comp_unit_has_inlines)
10321 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10322 comp_unit_has_inlines = 1;
10329 /* Generate a DIE to represent a declared data object. */
10332 gen_variable_die (decl, context_die)
10333 register tree decl;
10334 register dw_die_ref context_die;
10336 register tree origin = decl_ultimate_origin (decl);
10337 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
10339 dw_die_ref old_die = lookup_decl_die (decl);
10340 int declaration = (DECL_EXTERNAL (decl)
10341 || class_scope_p (context_die));
10343 if (origin != NULL)
10344 add_abstract_origin_attribute (var_die, origin);
10345 /* Loop unrolling can create multiple blocks that refer to the same
10346 static variable, so we must test for the DW_AT_declaration flag. */
10347 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10348 copy decls and set the DECL_ABSTRACT flag on them instead of
10350 else if (old_die && TREE_STATIC (decl)
10351 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10353 /* This is a definition of a C++ class level static. */
10354 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10355 if (DECL_NAME (decl))
10357 register unsigned file_index
10358 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
10360 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10361 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10363 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10364 != (unsigned) DECL_SOURCE_LINE (decl))
10366 add_AT_unsigned (var_die, DW_AT_decl_line,
10367 DECL_SOURCE_LINE (decl));
10372 add_name_and_src_coords_attributes (var_die, decl);
10373 add_type_attribute (var_die, TREE_TYPE (decl),
10374 TREE_READONLY (decl),
10375 TREE_THIS_VOLATILE (decl), context_die);
10377 if (TREE_PUBLIC (decl))
10378 add_AT_flag (var_die, DW_AT_external, 1);
10380 if (DECL_ARTIFICIAL (decl))
10381 add_AT_flag (var_die, DW_AT_artificial, 1);
10383 if (TREE_PROTECTED (decl))
10384 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10386 else if (TREE_PRIVATE (decl))
10387 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10391 add_AT_flag (var_die, DW_AT_declaration, 1);
10393 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10394 equate_decl_number_to_die (decl, var_die);
10396 if (! declaration && ! DECL_ABSTRACT (decl))
10398 add_location_or_const_value_attribute (var_die, decl);
10399 add_pubname (decl, var_die);
10402 tree_add_const_value_attribute (var_die, decl);
10405 /* Generate a DIE to represent a label identifier. */
10408 gen_label_die (decl, context_die)
10409 register tree decl;
10410 register dw_die_ref context_die;
10412 register tree origin = decl_ultimate_origin (decl);
10413 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
10415 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10417 if (origin != NULL)
10418 add_abstract_origin_attribute (lbl_die, origin);
10420 add_name_and_src_coords_attributes (lbl_die, decl);
10422 if (DECL_ABSTRACT (decl))
10423 equate_decl_number_to_die (decl, lbl_die);
10426 insn = DECL_RTL (decl);
10428 /* Deleted labels are programmer specified labels which have been
10429 eliminated because of various optimisations. We still emit them
10430 here so that it is possible to put breakpoints on them. */
10431 if (GET_CODE (insn) == CODE_LABEL
10432 || ((GET_CODE (insn) == NOTE
10433 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10435 /* When optimization is enabled (via -O) some parts of the compiler
10436 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10437 represent source-level labels which were explicitly declared by
10438 the user. This really shouldn't be happening though, so catch
10439 it if it ever does happen. */
10440 if (INSN_DELETED_P (insn))
10443 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10444 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10449 /* Generate a DIE for a lexical block. */
10452 gen_lexical_block_die (stmt, context_die, depth)
10453 register tree stmt;
10454 register dw_die_ref context_die;
10457 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10458 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10460 if (! BLOCK_ABSTRACT (stmt))
10462 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10463 BLOCK_NUMBER (stmt));
10464 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10465 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10466 BLOCK_NUMBER (stmt));
10467 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10470 decls_for_scope (stmt, stmt_die, depth);
10473 /* Generate a DIE for an inlined subprogram. */
10476 gen_inlined_subroutine_die (stmt, context_die, depth)
10477 register tree stmt;
10478 register dw_die_ref context_die;
10481 if (! BLOCK_ABSTRACT (stmt))
10483 register dw_die_ref subr_die
10484 = new_die (DW_TAG_inlined_subroutine, context_die);
10485 register tree decl = block_ultimate_origin (stmt);
10486 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10488 /* Emit info for the abstract instance first, if we haven't yet. */
10489 gen_abstract_function (decl);
10491 add_abstract_origin_attribute (subr_die, decl);
10492 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10493 BLOCK_NUMBER (stmt));
10494 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10495 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10496 BLOCK_NUMBER (stmt));
10497 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10498 decls_for_scope (stmt, subr_die, depth);
10499 current_function_has_inlines = 1;
10503 /* Generate a DIE for a field in a record, or structure. */
10506 gen_field_die (decl, context_die)
10507 register tree decl;
10508 register dw_die_ref context_die;
10510 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10512 add_name_and_src_coords_attributes (decl_die, decl);
10513 add_type_attribute (decl_die, member_declared_type (decl),
10514 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10517 /* If this is a bit field... */
10518 if (DECL_BIT_FIELD_TYPE (decl))
10520 add_byte_size_attribute (decl_die, decl);
10521 add_bit_size_attribute (decl_die, decl);
10522 add_bit_offset_attribute (decl_die, decl);
10525 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10526 add_data_member_location_attribute (decl_die, decl);
10528 if (DECL_ARTIFICIAL (decl))
10529 add_AT_flag (decl_die, DW_AT_artificial, 1);
10531 if (TREE_PROTECTED (decl))
10532 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10534 else if (TREE_PRIVATE (decl))
10535 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10539 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10540 Use modified_type_die instead.
10541 We keep this code here just in case these types of DIEs may be needed to
10542 represent certain things in other languages (e.g. Pascal) someday. */
10544 gen_pointer_type_die (type, context_die)
10545 register tree type;
10546 register dw_die_ref context_die;
10548 register dw_die_ref ptr_die
10549 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10551 equate_type_number_to_die (type, ptr_die);
10552 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10553 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10556 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10557 Use modified_type_die instead.
10558 We keep this code here just in case these types of DIEs may be needed to
10559 represent certain things in other languages (e.g. Pascal) someday. */
10561 gen_reference_type_die (type, context_die)
10562 register tree type;
10563 register dw_die_ref context_die;
10565 register dw_die_ref ref_die
10566 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10568 equate_type_number_to_die (type, ref_die);
10569 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10570 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10574 /* Generate a DIE for a pointer to a member type. */
10576 gen_ptr_to_mbr_type_die (type, context_die)
10577 register tree type;
10578 register dw_die_ref context_die;
10580 register dw_die_ref ptr_die
10581 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10583 equate_type_number_to_die (type, ptr_die);
10584 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10585 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10586 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10589 /* Generate the DIE for the compilation unit. */
10592 gen_compile_unit_die (filename)
10593 register const char *filename;
10595 register dw_die_ref die;
10596 char producer[250];
10597 const char *wd = getpwd ();
10600 die = new_die (DW_TAG_compile_unit, NULL);
10601 add_name_attribute (die, filename);
10603 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10604 add_AT_string (die, DW_AT_comp_dir, wd);
10606 sprintf (producer, "%s %s", language_string, version_string);
10608 #ifdef MIPS_DEBUGGING_INFO
10609 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10610 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10611 not appear in the producer string, the debugger reaches the conclusion
10612 that the object file is stripped and has no debugging information.
10613 To get the MIPS/SGI debugger to believe that there is debugging
10614 information in the object file, we add a -g to the producer string. */
10615 if (debug_info_level > DINFO_LEVEL_TERSE)
10616 strcat (producer, " -g");
10619 add_AT_string (die, DW_AT_producer, producer);
10621 if (strcmp (language_string, "GNU C++") == 0)
10622 language = DW_LANG_C_plus_plus;
10623 else if (strcmp (language_string, "GNU Ada") == 0)
10624 language = DW_LANG_Ada83;
10625 else if (strcmp (language_string, "GNU F77") == 0)
10626 language = DW_LANG_Fortran77;
10627 else if (strcmp (language_string, "GNU Pascal") == 0)
10628 language = DW_LANG_Pascal83;
10629 else if (strcmp (language_string, "GNU Java") == 0)
10630 language = DW_LANG_Java;
10631 else if (flag_traditional)
10632 language = DW_LANG_C;
10634 language = DW_LANG_C89;
10636 add_AT_unsigned (die, DW_AT_language, language);
10641 /* Generate a DIE for a string type. */
10644 gen_string_type_die (type, context_die)
10645 register tree type;
10646 register dw_die_ref context_die;
10648 register dw_die_ref type_die
10649 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10651 equate_type_number_to_die (type, type_die);
10653 /* Fudge the string length attribute for now. */
10655 /* TODO: add string length info.
10656 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10657 bound_representation (upper_bound, 0, 'u'); */
10660 /* Generate the DIE for a base class. */
10663 gen_inheritance_die (binfo, context_die)
10664 register tree binfo;
10665 register dw_die_ref context_die;
10667 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10669 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10670 add_data_member_location_attribute (die, binfo);
10672 if (TREE_VIA_VIRTUAL (binfo))
10673 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10674 if (TREE_VIA_PUBLIC (binfo))
10675 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10676 else if (TREE_VIA_PROTECTED (binfo))
10677 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10680 /* Generate a DIE for a class member. */
10683 gen_member_die (type, context_die)
10684 register tree type;
10685 register dw_die_ref context_die;
10687 register tree member;
10690 /* If this is not an incomplete type, output descriptions of each of its
10691 members. Note that as we output the DIEs necessary to represent the
10692 members of this record or union type, we will also be trying to output
10693 DIEs to represent the *types* of those members. However the `type'
10694 function (above) will specifically avoid generating type DIEs for member
10695 types *within* the list of member DIEs for this (containing) type execpt
10696 for those types (of members) which are explicitly marked as also being
10697 members of this (containing) type themselves. The g++ front- end can
10698 force any given type to be treated as a member of some other
10699 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10700 to point to the TREE node representing the appropriate (containing)
10703 /* First output info about the base classes. */
10704 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10706 register tree bases = TYPE_BINFO_BASETYPES (type);
10707 register int n_bases = TREE_VEC_LENGTH (bases);
10710 for (i = 0; i < n_bases; i++)
10711 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10714 /* Now output info about the data members and type members. */
10715 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10717 /* If we thought we were generating minimal debug info for TYPE
10718 and then changed our minds, some of the member declarations
10719 may have already been defined. Don't define them again, but
10720 do put them in the right order. */
10722 child = lookup_decl_die (member);
10724 splice_child_die (context_die, child);
10726 gen_decl_die (member, context_die);
10729 /* Now output info about the function members (if any). */
10730 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10732 child = lookup_decl_die (member);
10734 splice_child_die (context_die, child);
10736 gen_decl_die (member, context_die);
10740 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10741 is set, we pretend that the type was never defined, so we only get the
10742 member DIEs needed by later specification DIEs. */
10745 gen_struct_or_union_type_die (type, context_die)
10746 register tree type;
10747 register dw_die_ref context_die;
10749 register dw_die_ref type_die = lookup_type_die (type);
10750 register dw_die_ref scope_die = 0;
10751 register int nested = 0;
10752 int complete = (TYPE_SIZE (type)
10753 && (! TYPE_STUB_DECL (type)
10754 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10756 if (type_die && ! complete)
10759 if (TYPE_CONTEXT (type) != NULL_TREE
10760 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10763 scope_die = scope_die_for (type, context_die);
10765 if (! type_die || (nested && scope_die == comp_unit_die))
10766 /* First occurrence of type or toplevel definition of nested class. */
10768 register dw_die_ref old_die = type_die;
10770 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10771 ? DW_TAG_structure_type : DW_TAG_union_type,
10773 equate_type_number_to_die (type, type_die);
10775 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10777 add_name_attribute (type_die, type_tag (type));
10780 remove_AT (type_die, DW_AT_declaration);
10782 /* If this type has been completed, then give it a byte_size attribute and
10783 then give a list of members. */
10786 /* Prevent infinite recursion in cases where the type of some member of
10787 this type is expressed in terms of this type itself. */
10788 TREE_ASM_WRITTEN (type) = 1;
10789 add_byte_size_attribute (type_die, type);
10790 if (TYPE_STUB_DECL (type) != NULL_TREE)
10791 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10793 /* If the first reference to this type was as the return type of an
10794 inline function, then it may not have a parent. Fix this now. */
10795 if (type_die->die_parent == NULL)
10796 add_child_die (scope_die, type_die);
10798 push_decl_scope (type);
10799 gen_member_die (type, type_die);
10802 /* GNU extension: Record what type our vtable lives in. */
10803 if (TYPE_VFIELD (type))
10805 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10807 gen_type_die (vtype, context_die);
10808 add_AT_die_ref (type_die, DW_AT_containing_type,
10809 lookup_type_die (vtype));
10814 add_AT_flag (type_die, DW_AT_declaration, 1);
10816 /* We don't need to do this for function-local types. */
10817 if (! decl_function_context (TYPE_STUB_DECL (type)))
10818 add_incomplete_type (type);
10822 /* Generate a DIE for a subroutine _type_. */
10825 gen_subroutine_type_die (type, context_die)
10826 register tree type;
10827 register dw_die_ref context_die;
10829 register tree return_type = TREE_TYPE (type);
10830 register dw_die_ref subr_die
10831 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10833 equate_type_number_to_die (type, subr_die);
10834 add_prototyped_attribute (subr_die, type);
10835 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10836 gen_formal_types_die (type, subr_die);
10839 /* Generate a DIE for a type definition */
10842 gen_typedef_die (decl, context_die)
10843 register tree decl;
10844 register dw_die_ref context_die;
10846 register dw_die_ref type_die;
10847 register tree origin;
10849 if (TREE_ASM_WRITTEN (decl))
10851 TREE_ASM_WRITTEN (decl) = 1;
10853 type_die = new_die (DW_TAG_typedef, context_die);
10854 origin = decl_ultimate_origin (decl);
10855 if (origin != NULL)
10856 add_abstract_origin_attribute (type_die, origin);
10859 register tree type;
10860 add_name_and_src_coords_attributes (type_die, decl);
10861 if (DECL_ORIGINAL_TYPE (decl))
10863 type = DECL_ORIGINAL_TYPE (decl);
10865 if (type == TREE_TYPE (decl))
10868 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10871 type = TREE_TYPE (decl);
10872 add_type_attribute (type_die, type, TREE_READONLY (decl),
10873 TREE_THIS_VOLATILE (decl), context_die);
10876 if (DECL_ABSTRACT (decl))
10877 equate_decl_number_to_die (decl, type_die);
10880 /* Generate a type description DIE. */
10883 gen_type_die (type, context_die)
10884 register tree type;
10885 register dw_die_ref context_die;
10889 if (type == NULL_TREE || type == error_mark_node)
10892 /* We are going to output a DIE to represent the unqualified version of
10893 this type (i.e. without any const or volatile qualifiers) so get the
10894 main variant (i.e. the unqualified version) of this type now. */
10895 type = type_main_variant (type);
10897 if (TREE_ASM_WRITTEN (type))
10900 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10901 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10903 TREE_ASM_WRITTEN (type) = 1;
10904 gen_decl_die (TYPE_NAME (type), context_die);
10908 switch (TREE_CODE (type))
10914 case REFERENCE_TYPE:
10915 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10916 ensures that the gen_type_die recursion will terminate even if the
10917 type is recursive. Recursive types are possible in Ada. */
10918 /* ??? We could perhaps do this for all types before the switch
10920 TREE_ASM_WRITTEN (type) = 1;
10922 /* For these types, all that is required is that we output a DIE (or a
10923 set of DIEs) to represent the "basis" type. */
10924 gen_type_die (TREE_TYPE (type), context_die);
10928 /* This code is used for C++ pointer-to-data-member types.
10929 Output a description of the relevant class type. */
10930 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10932 /* Output a description of the type of the object pointed to. */
10933 gen_type_die (TREE_TYPE (type), context_die);
10935 /* Now output a DIE to represent this pointer-to-data-member type
10937 gen_ptr_to_mbr_type_die (type, context_die);
10941 gen_type_die (TYPE_DOMAIN (type), context_die);
10942 gen_set_type_die (type, context_die);
10946 gen_type_die (TREE_TYPE (type), context_die);
10947 abort (); /* No way to represent these in Dwarf yet! */
10950 case FUNCTION_TYPE:
10951 /* Force out return type (in case it wasn't forced out already). */
10952 gen_type_die (TREE_TYPE (type), context_die);
10953 gen_subroutine_type_die (type, context_die);
10957 /* Force out return type (in case it wasn't forced out already). */
10958 gen_type_die (TREE_TYPE (type), context_die);
10959 gen_subroutine_type_die (type, context_die);
10963 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10965 gen_type_die (TREE_TYPE (type), context_die);
10966 gen_string_type_die (type, context_die);
10969 gen_array_type_die (type, context_die);
10973 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10976 case ENUMERAL_TYPE:
10979 case QUAL_UNION_TYPE:
10980 /* If this is a nested type whose containing class hasn't been
10981 written out yet, writing it out will cover this one, too.
10982 This does not apply to instantiations of member class templates;
10983 they need to be added to the containing class as they are
10984 generated. FIXME: This hurts the idea of combining type decls
10985 from multiple TUs, since we can't predict what set of template
10986 instantiations we'll get. */
10987 if (TYPE_CONTEXT (type)
10988 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10989 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10991 gen_type_die (TYPE_CONTEXT (type), context_die);
10993 if (TREE_ASM_WRITTEN (type))
10996 /* If that failed, attach ourselves to the stub. */
10997 push_decl_scope (TYPE_CONTEXT (type));
10998 context_die = lookup_type_die (TYPE_CONTEXT (type));
11004 if (TREE_CODE (type) == ENUMERAL_TYPE)
11005 gen_enumeration_type_die (type, context_die);
11007 gen_struct_or_union_type_die (type, context_die);
11012 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11013 it up if it is ever completed. gen_*_type_die will set it for us
11014 when appropriate. */
11023 /* No DIEs needed for fundamental types. */
11027 /* No Dwarf representation currently defined. */
11034 TREE_ASM_WRITTEN (type) = 1;
11037 /* Generate a DIE for a tagged type instantiation. */
11040 gen_tagged_type_instantiation_die (type, context_die)
11041 register tree type;
11042 register dw_die_ref context_die;
11044 if (type == NULL_TREE || type == error_mark_node)
11047 /* We are going to output a DIE to represent the unqualified version of
11048 this type (i.e. without any const or volatile qualifiers) so make sure
11049 that we have the main variant (i.e. the unqualified version) of this
11051 if (type != type_main_variant (type))
11054 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11055 an instance of an unresolved type. */
11057 switch (TREE_CODE (type))
11062 case ENUMERAL_TYPE:
11063 gen_inlined_enumeration_type_die (type, context_die);
11067 gen_inlined_structure_type_die (type, context_die);
11071 case QUAL_UNION_TYPE:
11072 gen_inlined_union_type_die (type, context_die);
11080 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11081 things which are local to the given block. */
11084 gen_block_die (stmt, context_die, depth)
11085 register tree stmt;
11086 register dw_die_ref context_die;
11089 register int must_output_die = 0;
11090 register tree origin;
11091 register tree decl;
11092 register enum tree_code origin_code;
11094 /* Ignore blocks never really used to make RTL. */
11096 if (stmt == NULL_TREE || !TREE_USED (stmt)
11097 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11100 /* Determine the "ultimate origin" of this block. This block may be an
11101 inlined instance of an inlined instance of inline function, so we have
11102 to trace all of the way back through the origin chain to find out what
11103 sort of node actually served as the original seed for the creation of
11104 the current block. */
11105 origin = block_ultimate_origin (stmt);
11106 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11108 /* Determine if we need to output any Dwarf DIEs at all to represent this
11110 if (origin_code == FUNCTION_DECL)
11111 /* The outer scopes for inlinings *must* always be represented. We
11112 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11113 must_output_die = 1;
11116 /* In the case where the current block represents an inlining of the
11117 "body block" of an inline function, we must *NOT* output any DIE for
11118 this block because we have already output a DIE to represent the
11119 whole inlined function scope and the "body block" of any function
11120 doesn't really represent a different scope according to ANSI C
11121 rules. So we check here to make sure that this block does not
11122 represent a "body block inlining" before trying to set the
11123 `must_output_die' flag. */
11124 if (! is_body_block (origin ? origin : stmt))
11126 /* Determine if this block directly contains any "significant"
11127 local declarations which we will need to output DIEs for. */
11128 if (debug_info_level > DINFO_LEVEL_TERSE)
11129 /* We are not in terse mode so *any* local declaration counts
11130 as being a "significant" one. */
11131 must_output_die = (BLOCK_VARS (stmt) != NULL);
11133 /* We are in terse mode, so only local (nested) function
11134 definitions count as "significant" local declarations. */
11135 for (decl = BLOCK_VARS (stmt);
11136 decl != NULL; decl = TREE_CHAIN (decl))
11137 if (TREE_CODE (decl) == FUNCTION_DECL
11138 && DECL_INITIAL (decl))
11140 must_output_die = 1;
11146 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11147 DIE for any block which contains no significant local declarations at
11148 all. Rather, in such cases we just call `decls_for_scope' so that any
11149 needed Dwarf info for any sub-blocks will get properly generated. Note
11150 that in terse mode, our definition of what constitutes a "significant"
11151 local declaration gets restricted to include only inlined function
11152 instances and local (nested) function definitions. */
11153 if (must_output_die)
11155 if (origin_code == FUNCTION_DECL)
11156 gen_inlined_subroutine_die (stmt, context_die, depth);
11158 gen_lexical_block_die (stmt, context_die, depth);
11161 decls_for_scope (stmt, context_die, depth);
11164 /* Generate all of the decls declared within a given scope and (recursively)
11165 all of its sub-blocks. */
11168 decls_for_scope (stmt, context_die, depth)
11169 register tree stmt;
11170 register dw_die_ref context_die;
11173 register tree decl;
11174 register tree subblocks;
11176 /* Ignore blocks never really used to make RTL. */
11177 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11180 /* Output the DIEs to represent all of the data objects and typedefs
11181 declared directly within this block but not within any nested
11182 sub-blocks. Also, nested function and tag DIEs have been
11183 generated with a parent of NULL; fix that up now. */
11184 for (decl = BLOCK_VARS (stmt);
11185 decl != NULL; decl = TREE_CHAIN (decl))
11187 register dw_die_ref die;
11189 if (TREE_CODE (decl) == FUNCTION_DECL)
11190 die = lookup_decl_die (decl);
11191 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11192 die = lookup_type_die (TREE_TYPE (decl));
11196 if (die != NULL && die->die_parent == NULL)
11197 add_child_die (context_die, die);
11199 gen_decl_die (decl, context_die);
11202 /* Output the DIEs to represent all sub-blocks (and the items declared
11203 therein) of this block. */
11204 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11206 subblocks = BLOCK_CHAIN (subblocks))
11207 gen_block_die (subblocks, context_die, depth + 1);
11210 /* Is this a typedef we can avoid emitting? */
11213 is_redundant_typedef (decl)
11214 register tree decl;
11216 if (TYPE_DECL_IS_STUB (decl))
11219 if (DECL_ARTIFICIAL (decl)
11220 && DECL_CONTEXT (decl)
11221 && is_tagged_type (DECL_CONTEXT (decl))
11222 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11223 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11224 /* Also ignore the artificial member typedef for the class name. */
11230 /* Generate Dwarf debug information for a decl described by DECL. */
11233 gen_decl_die (decl, context_die)
11234 register tree decl;
11235 register dw_die_ref context_die;
11237 register tree origin;
11239 if (TREE_CODE (decl) == ERROR_MARK)
11242 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11243 if (DECL_IGNORED_P (decl))
11246 switch (TREE_CODE (decl))
11249 /* The individual enumerators of an enum type get output when we output
11250 the Dwarf representation of the relevant enum type itself. */
11253 case FUNCTION_DECL:
11254 /* Don't output any DIEs to represent mere function declarations,
11255 unless they are class members or explicit block externs. */
11256 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11257 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11260 /* If we're emitting an out-of-line copy of an inline function,
11261 emit info for the abstract instance and set up to refer to it. */
11262 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11263 && ! class_scope_p (context_die)
11264 /* gen_abstract_function won't emit a die if this is just a
11265 declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11266 that case, because that works only if we have a die. */
11267 && DECL_INITIAL (decl) != NULL_TREE)
11269 gen_abstract_function (decl);
11270 set_decl_origin_self (decl);
11273 if (debug_info_level > DINFO_LEVEL_TERSE)
11275 /* Before we describe the FUNCTION_DECL itself, make sure that we
11276 have described its return type. */
11277 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11279 /* And its virtual context. */
11280 if (DECL_VINDEX (decl) != NULL_TREE)
11281 gen_type_die (DECL_CONTEXT (decl), context_die);
11283 /* And its containing type. */
11284 origin = decl_class_context (decl);
11285 if (origin != NULL_TREE)
11286 gen_type_die_for_member (origin, decl, context_die);
11289 /* Now output a DIE to represent the function itself. */
11290 gen_subprogram_die (decl, context_die);
11294 /* If we are in terse mode, don't generate any DIEs to represent any
11295 actual typedefs. */
11296 if (debug_info_level <= DINFO_LEVEL_TERSE)
11299 /* In the special case of a TYPE_DECL node representing the
11300 declaration of some type tag, if the given TYPE_DECL is marked as
11301 having been instantiated from some other (original) TYPE_DECL node
11302 (e.g. one which was generated within the original definition of an
11303 inline function) we have to generate a special (abbreviated)
11304 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
11306 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11308 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11312 if (is_redundant_typedef (decl))
11313 gen_type_die (TREE_TYPE (decl), context_die);
11315 /* Output a DIE to represent the typedef itself. */
11316 gen_typedef_die (decl, context_die);
11320 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11321 gen_label_die (decl, context_die);
11325 /* If we are in terse mode, don't generate any DIEs to represent any
11326 variable declarations or definitions. */
11327 if (debug_info_level <= DINFO_LEVEL_TERSE)
11330 /* Output any DIEs that are needed to specify the type of this data
11332 gen_type_die (TREE_TYPE (decl), context_die);
11334 /* And its containing type. */
11335 origin = decl_class_context (decl);
11336 if (origin != NULL_TREE)
11337 gen_type_die_for_member (origin, decl, context_die);
11339 /* Now output the DIE to represent the data object itself. This gets
11340 complicated because of the possibility that the VAR_DECL really
11341 represents an inlined instance of a formal parameter for an inline
11343 origin = decl_ultimate_origin (decl);
11344 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11345 gen_formal_parameter_die (decl, context_die);
11347 gen_variable_die (decl, context_die);
11351 /* Ignore the nameless fields that are used to skip bits, but
11352 handle C++ anonymous unions. */
11353 if (DECL_NAME (decl) != NULL_TREE
11354 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11356 gen_type_die (member_declared_type (decl), context_die);
11357 gen_field_die (decl, context_die);
11362 gen_type_die (TREE_TYPE (decl), context_die);
11363 gen_formal_parameter_die (decl, context_die);
11366 case NAMESPACE_DECL:
11367 /* Ignore for now. */
11375 /* Add Ada "use" clause information for SGI Workshop debugger. */
11378 dwarf2out_add_library_unit_info (filename, context_list)
11379 const char *filename;
11380 const char *context_list;
11382 unsigned int file_index;
11384 if (filename != NULL)
11386 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
11387 tree context_list_decl
11388 = build_decl (LABEL_DECL, get_identifier (context_list),
11391 TREE_PUBLIC (context_list_decl) = TRUE;
11392 add_name_attribute (unit_die, context_list);
11393 file_index = lookup_filename (&decl_file_table, filename);
11394 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11395 add_pubname (context_list_decl, unit_die);
11399 /* Write the debugging output for DECL. */
11402 dwarf2out_decl (decl)
11403 register tree decl;
11405 register dw_die_ref context_die = comp_unit_die;
11407 if (TREE_CODE (decl) == ERROR_MARK)
11410 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11411 if (DECL_IGNORED_P (decl))
11414 switch (TREE_CODE (decl))
11416 case FUNCTION_DECL:
11417 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11418 builtin function. Explicit programmer-supplied declarations of
11419 these same functions should NOT be ignored however. */
11420 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11423 /* What we would really like to do here is to filter out all mere
11424 file-scope declarations of file-scope functions which are never
11425 referenced later within this translation unit (and keep all of ones
11426 that *are* referenced later on) but we aren't clairvoyant, so we have
11427 no idea which functions will be referenced in the future (i.e. later
11428 on within the current translation unit). So here we just ignore all
11429 file-scope function declarations which are not also definitions. If
11430 and when the debugger needs to know something about these functions,
11431 it will have to hunt around and find the DWARF information associated
11432 with the definition of the function. Note that we can't just check
11433 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11434 definitions and which ones represent mere declarations. We have to
11435 check `DECL_INITIAL' instead. That's because the C front-end
11436 supports some weird semantics for "extern inline" function
11437 definitions. These can get inlined within the current translation
11438 unit (an thus, we need to generate DWARF info for their abstract
11439 instances so that the DWARF info for the concrete inlined instances
11440 can have something to refer to) but the compiler never generates any
11441 out-of-lines instances of such things (despite the fact that they
11442 *are* definitions). The important point is that the C front-end
11443 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11444 to generate DWARF for them anyway. Note that the C++ front-end also
11445 plays some similar games for inline function definitions appearing
11446 within include files which also contain
11447 `#pragma interface' pragmas. */
11448 if (DECL_INITIAL (decl) == NULL_TREE)
11451 /* If we're a nested function, initially use a parent of NULL; if we're
11452 a plain function, this will be fixed up in decls_for_scope. If
11453 we're a method, it will be ignored, since we already have a DIE. */
11454 if (decl_function_context (decl))
11455 context_die = NULL;
11460 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11461 declaration and if the declaration was never even referenced from
11462 within this entire compilation unit. We suppress these DIEs in
11463 order to save space in the .debug section (by eliminating entries
11464 which are probably useless). Note that we must not suppress
11465 block-local extern declarations (whether used or not) because that
11466 would screw-up the debugger's name lookup mechanism and cause it to
11467 miss things which really ought to be in scope at a given point. */
11468 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11471 /* If we are in terse mode, don't generate any DIEs to represent any
11472 variable declarations or definitions. */
11473 if (debug_info_level <= DINFO_LEVEL_TERSE)
11478 /* Don't emit stubs for types unless they are needed by other DIEs. */
11479 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11482 /* Don't bother trying to generate any DIEs to represent any of the
11483 normal built-in types for the language we are compiling. */
11484 if (DECL_SOURCE_LINE (decl) == 0)
11486 /* OK, we need to generate one for `bool' so GDB knows what type
11487 comparisons have. */
11488 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11489 == DW_LANG_C_plus_plus)
11490 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11491 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11496 /* If we are in terse mode, don't generate any DIEs for types. */
11497 if (debug_info_level <= DINFO_LEVEL_TERSE)
11500 /* If we're a function-scope tag, initially use a parent of NULL;
11501 this will be fixed up in decls_for_scope. */
11502 if (decl_function_context (decl))
11503 context_die = NULL;
11511 gen_decl_die (decl, context_die);
11514 /* Output a marker (i.e. a label) for the beginning of the generated code for
11515 a lexical block. */
11518 dwarf2out_begin_block (blocknum)
11519 register unsigned blocknum;
11521 function_section (current_function_decl);
11522 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11525 /* Output a marker (i.e. a label) for the end of the generated code for a
11529 dwarf2out_end_block (blocknum)
11530 register unsigned blocknum;
11532 function_section (current_function_decl);
11533 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11536 /* Returns nonzero if it is appropriate not to emit any debugging
11537 information for BLOCK, because it doesn't contain any instructions.
11539 Don't allow this for blocks with nested functions or local classes
11540 as we would end up with orphans, and in the presence of scheduling
11541 we may end up calling them anyway. */
11544 dwarf2out_ignore_block (block)
11548 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11549 if (TREE_CODE (decl) == FUNCTION_DECL
11550 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11555 /* Lookup a filename (in the list of filenames that we know about here in
11556 dwarf2out.c) and return its "index". The index of each (known) filename is
11557 just a unique number which is associated with only that one filename.
11558 We need such numbers for the sake of generating labels
11559 (in the .debug_sfnames section) and references to those
11560 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11561 If the filename given as an argument is not found in our current list,
11562 add it to the list and assign it the next available unique index number.
11563 In order to speed up searches, we remember the index of the filename
11564 was looked up last. This handles the majority of all searches. */
11567 lookup_filename (t, file_name)
11568 struct file_table *t;
11569 const char *file_name;
11571 register unsigned i;
11573 /* Check to see if the file name that was searched on the previous
11574 call matches this file name. If so, return the index. */
11575 if (t->last_lookup_index != 0)
11576 if (strcmp (file_name, t->table[t->last_lookup_index]) == 0)
11577 return t->last_lookup_index;
11579 /* Didn't match the previous lookup, search the table */
11580 for (i = 1; i < t->in_use; ++i)
11581 if (strcmp (file_name, t->table[i]) == 0)
11583 t->last_lookup_index = i;
11587 /* Prepare to add a new table entry by making sure there is enough space in
11588 the table to do so. If not, expand the current table. */
11589 if (i == t->allocated)
11591 t->allocated = i + FILE_TABLE_INCREMENT;
11592 t->table = (char **)
11593 xrealloc (t->table, t->allocated * sizeof (char *));
11596 /* Add the new entry to the end of the filename table. */
11597 t->table[i] = xstrdup (file_name);
11599 t->last_lookup_index = i;
11605 init_file_table (t)
11606 struct file_table *t;
11608 /* Allocate the initial hunk of the file_table. */
11609 t->table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11610 t->allocated = FILE_TABLE_INCREMENT;
11612 /* Skip the first entry - file numbers begin at 1. */
11614 t->last_lookup_index = 0;
11617 /* Output a label to mark the beginning of a source code line entry
11618 and record information relating to this source line, in
11619 'line_info_table' for later output of the .debug_line section. */
11622 dwarf2out_line (filename, line)
11623 register const char *filename;
11624 register unsigned line;
11626 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11628 function_section (current_function_decl);
11630 if (DWARF2_ASM_LINE_DEBUG_INFO)
11633 unsigned old_in_use = line_file_table.in_use;
11635 unsigned file_num = lookup_filename (&line_file_table, filename);
11637 /* Emit the .file and .loc directives understood by GNU as. */
11639 /* ??? As of 2000-11-25, gas has a bug in which it doesn't
11640 actually use the file number argument. It merely remembers
11641 the last .file directive emitted. */
11642 if (file_num >= old_in_use)
11643 fprintf (asm_out_file, "\t.file %d \"%s\"\n", file_num, filename);
11644 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11646 static unsigned int last_file_num;
11647 if (file_num != last_file_num)
11649 last_file_num = file_num;
11650 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
11652 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
11655 /* Indicate that line number info exists. */
11656 ++line_info_table_in_use;
11658 /* Indicate that multiple line number tables exist. */
11659 if (DECL_SECTION_NAME (current_function_decl))
11660 ++separate_line_info_table_in_use;
11662 else if (DECL_SECTION_NAME (current_function_decl))
11664 register dw_separate_line_info_ref line_info;
11665 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11666 separate_line_info_table_in_use);
11667 if (flag_debug_asm)
11668 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
11669 fputc ('\n', asm_out_file);
11671 /* expand the line info table if necessary */
11672 if (separate_line_info_table_in_use
11673 == separate_line_info_table_allocated)
11675 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11676 separate_line_info_table
11677 = (dw_separate_line_info_ref)
11678 xrealloc (separate_line_info_table,
11679 separate_line_info_table_allocated
11680 * sizeof (dw_separate_line_info_entry));
11683 /* Add the new entry at the end of the line_info_table. */
11685 = &separate_line_info_table[separate_line_info_table_in_use++];
11686 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
11687 line_info->dw_line_num = line;
11688 line_info->function = current_funcdef_number;
11692 register dw_line_info_ref line_info;
11694 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11695 line_info_table_in_use);
11696 if (flag_debug_asm)
11697 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
11698 fputc ('\n', asm_out_file);
11700 /* Expand the line info table if necessary. */
11701 if (line_info_table_in_use == line_info_table_allocated)
11703 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11705 = (dw_line_info_ref)
11706 xrealloc (line_info_table,
11707 (line_info_table_allocated
11708 * sizeof (dw_line_info_entry)));
11711 /* Add the new entry at the end of the line_info_table. */
11712 line_info = &line_info_table[line_info_table_in_use++];
11713 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
11714 line_info->dw_line_num = line;
11719 /* Record the beginning of a new source file, for later output
11720 of the .debug_macinfo section. At present, unimplemented. */
11723 dwarf2out_start_source_file (filename)
11724 register const char *filename ATTRIBUTE_UNUSED;
11726 if (flag_eliminate_dwarf2_dups)
11728 /* Record the beginning of the file for break_out_includes. */
11729 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11730 add_AT_string (bincl_die, DW_AT_name, filename);
11734 /* Record the end of a source file, for later output
11735 of the .debug_macinfo section. At present, unimplemented. */
11738 dwarf2out_end_source_file ()
11740 if (flag_eliminate_dwarf2_dups)
11742 /* Record the end of the file for break_out_includes. */
11743 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11747 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11748 the tail part of the directive line, i.e. the part which is past the
11749 initial whitespace, #, whitespace, directive-name, whitespace part. */
11752 dwarf2out_define (lineno, buffer)
11753 register unsigned lineno ATTRIBUTE_UNUSED;
11754 register const char *buffer ATTRIBUTE_UNUSED;
11756 static int initialized = 0;
11759 dwarf2out_start_source_file (primary_filename);
11764 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11765 the tail part of the directive line, i.e. the part which is past the
11766 initial whitespace, #, whitespace, directive-name, whitespace part. */
11769 dwarf2out_undef (lineno, buffer)
11770 register unsigned lineno ATTRIBUTE_UNUSED;
11771 register const char *buffer ATTRIBUTE_UNUSED;
11775 /* Set up for Dwarf output at the start of compilation. */
11778 dwarf2out_init (asm_out_file, main_input_filename)
11779 register FILE *asm_out_file;
11780 register const char *main_input_filename;
11782 /* Remember the name of the primary input file. */
11783 primary_filename = main_input_filename;
11785 init_file_table (&decl_file_table);
11786 init_file_table (&line_file_table);
11788 /* Allocate the initial hunk of the decl_die_table. */
11790 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11791 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11792 decl_die_table_in_use = 0;
11794 /* Allocate the initial hunk of the decl_scope_table. */
11796 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11797 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11798 decl_scope_depth = 0;
11800 /* Allocate the initial hunk of the abbrev_die_table. */
11802 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11803 sizeof (dw_die_ref));
11804 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11805 /* Zero-th entry is allocated, but unused */
11806 abbrev_die_table_in_use = 1;
11808 /* Allocate the initial hunk of the line_info_table. */
11810 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11811 sizeof (dw_line_info_entry));
11812 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11813 /* Zero-th entry is allocated, but unused */
11814 line_info_table_in_use = 1;
11816 /* Generate the initial DIE for the .debug section. Note that the (string)
11817 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11818 will (typically) be a relative pathname and that this pathname should be
11819 taken as being relative to the directory from which the compiler was
11820 invoked when the given (base) source file was compiled. */
11821 comp_unit_die = gen_compile_unit_die (main_input_filename);
11823 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11824 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11826 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11827 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
11828 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11829 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11831 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11832 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11833 DEBUG_INFO_SECTION_LABEL, 0);
11834 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11835 DEBUG_LINE_SECTION_LABEL, 0);
11837 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11838 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11839 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11841 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11842 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11844 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11845 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11846 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11847 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11850 /* Output stuff that dwarf requires at the end of every file,
11851 and generate the DWARF-2 debugging info. */
11854 dwarf2out_finish ()
11856 limbo_die_node *node, *next_node;
11859 /* Traverse the limbo die list, and add parent/child links. The only
11860 dies without parents that should be here are concrete instances of
11861 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11862 For concrete instances, we can get the parent die from the abstract
11864 for (node = limbo_die_list; node; node = next_node)
11866 next_node = node->next;
11869 if (die->die_parent == NULL)
11871 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11873 add_child_die (origin->die_parent, die);
11874 else if (die == comp_unit_die)
11881 limbo_die_list = NULL;
11883 /* Walk through the list of incomplete types again, trying once more to
11884 emit full debugging info for them. */
11885 retry_incomplete_types ();
11887 /* We need to reverse all the dies before break_out_includes, or
11888 we'll see the end of an include file before the beginning. */
11889 reverse_all_dies (comp_unit_die);
11891 /* Generate separate CUs for each of the include files we've seen.
11892 They will go into limbo_die_list. */
11893 if (flag_eliminate_dwarf2_dups)
11894 break_out_includes (comp_unit_die);
11896 /* Traverse the DIE's and add add sibling attributes to those DIE's
11897 that have children. */
11898 add_sibling_attributes (comp_unit_die);
11899 for (node = limbo_die_list; node; node = node->next)
11900 add_sibling_attributes (node->die);
11902 /* Output a terminator label for the .text section. */
11903 fputc ('\n', asm_out_file);
11904 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11905 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11908 /* Output a terminator label for the .data section. */
11909 fputc ('\n', asm_out_file);
11910 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11911 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11913 /* Output a terminator label for the .bss section. */
11914 fputc ('\n', asm_out_file);
11915 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11916 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11919 /* Output the source line correspondence table. */
11920 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
11922 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11924 fputc ('\n', asm_out_file);
11925 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11926 output_line_info ();
11929 /* We can only use the low/high_pc attributes if all of the code
11931 if (separate_line_info_table_in_use == 0)
11933 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11934 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11937 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11938 debug_line_section_label);
11941 #if 0 /* unimplemented */
11942 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
11943 add_AT_unsigned (die, DW_AT_macro_info, 0);
11946 /* Output all of the compilation units. We put the main one last so that
11947 the offsets are available to output_pubnames. */
11948 for (node = limbo_die_list; node; node = node->next)
11949 output_comp_unit (node->die);
11950 output_comp_unit (comp_unit_die);
11952 /* Output the abbreviation table. */
11953 fputc ('\n', asm_out_file);
11954 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11955 output_abbrev_section ();
11957 if (pubname_table_in_use)
11959 /* Output public names table. */
11960 fputc ('\n', asm_out_file);
11961 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
11962 output_pubnames ();
11965 /* We only put functions in the arange table, so don't write it out if
11966 we don't have any. */
11967 if (fde_table_in_use)
11969 /* Output the address range information. */
11970 fputc ('\n', asm_out_file);
11971 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11975 #endif /* DWARF2_DEBUGGING_INFO */