1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* TODO: Implement .debug_str handling, and share entries somehow.
26 Emit .debug_line header even when there are no functions, since
27 the file numbers are used by .debug_info. Alternately, leave
28 out locations for types and decls.
29 Avoid talking about ctors and op= for PODs.
30 Factor out common prologue sequences into multiple CIEs. */
32 /* The first part of this file deals with the DWARF 2 frame unwind
33 information, which is also used by the GCC efficient exception handling
34 mechanism. The second part, controlled only by an #ifdef
35 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
44 #include "hard-reg-set.h"
46 #include "insn-config.h"
52 #include "dwarf2out.h"
59 /* Decide whether we want to emit frame unwind information for the current
65 return (write_symbols
== DWARF2_DEBUG
66 #ifdef DWARF2_FRAME_INFO
69 #ifdef DWARF2_UNWIND_INFO
71 || (flag_exceptions
&& ! exceptions_via_longjmp
)
76 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
78 /* How to start an assembler comment. */
79 #ifndef ASM_COMMENT_START
80 #define ASM_COMMENT_START ";#"
83 typedef struct dw_cfi_struct
*dw_cfi_ref
;
84 typedef struct dw_fde_struct
*dw_fde_ref
;
85 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
87 /* Call frames are described using a sequence of Call Frame
88 Information instructions. The register number, offset
89 and address fields are provided as possible operands;
90 their use is selected by the opcode field. */
92 typedef union dw_cfi_oprnd_struct
94 unsigned long dw_cfi_reg_num
;
95 long int dw_cfi_offset
;
96 const char *dw_cfi_addr
;
97 struct dw_loc_descr_struct
*dw_cfi_loc
;
101 typedef struct dw_cfi_struct
103 dw_cfi_ref dw_cfi_next
;
104 enum dwarf_call_frame_info dw_cfi_opc
;
105 dw_cfi_oprnd dw_cfi_oprnd1
;
106 dw_cfi_oprnd dw_cfi_oprnd2
;
110 /* This is how we define the location of the CFA. We use to handle it
111 as REG + OFFSET all the time, but now it can be more complex.
112 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
113 Instead of passing around REG and OFFSET, we pass a copy
114 of this structure. */
115 typedef struct cfa_loc
120 int indirect
; /* 1 if CFA is accessed via a dereference. */
123 /* All call frame descriptions (FDE's) in the GCC generated DWARF
124 refer to a single Common Information Entry (CIE), defined at
125 the beginning of the .debug_frame section. This used of a single
126 CIE obviates the need to keep track of multiple CIE's
127 in the DWARF generation routines below. */
129 typedef struct dw_fde_struct
131 const char *dw_fde_begin
;
132 const char *dw_fde_current_label
;
133 const char *dw_fde_end
;
134 dw_cfi_ref dw_fde_cfi
;
139 /* Maximum size (in bytes) of an artificially generated label. */
140 #define MAX_ARTIFICIAL_LABEL_BYTES 30
142 /* The size of the target's pointer type. */
144 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
147 /* The size of addresses as they appear in the Dwarf 2 data.
148 Some architectures use word addresses to refer to code locations,
149 but Dwarf 2 info always uses byte addresses. On such machines,
150 Dwarf 2 addresses need to be larger than the architecture's
152 #ifndef DWARF2_ADDR_SIZE
153 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
156 /* The size in bytes of a DWARF field indicating an offset or length
157 relative to a debug info section, specified to be 4 bytes in the
158 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
161 #ifndef DWARF_OFFSET_SIZE
162 #define DWARF_OFFSET_SIZE 4
165 #define DWARF_VERSION 2
167 /* Round SIZE up to the nearest BOUNDARY. */
168 #define DWARF_ROUND(SIZE,BOUNDARY) \
169 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
171 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
172 #ifndef DWARF_CIE_DATA_ALIGNMENT
173 #ifdef STACK_GROWS_DOWNWARD
174 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
176 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
178 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
180 /* A pointer to the base of a table that contains frame description
181 information for each routine. */
182 static dw_fde_ref fde_table
;
184 /* Number of elements currently allocated for fde_table. */
185 static unsigned fde_table_allocated
;
187 /* Number of elements in fde_table currently in use. */
188 static unsigned fde_table_in_use
;
190 /* Size (in elements) of increments by which we may expand the
192 #define FDE_TABLE_INCREMENT 256
194 /* A list of call frame insns for the CIE. */
195 static dw_cfi_ref cie_cfi_head
;
197 /* The number of the current function definition for which debugging
198 information is being generated. These numbers range from 1 up to the
199 maximum number of function definitions contained within the current
200 compilation unit. These numbers are used to create unique label id's
201 unique to each function definition. */
202 static unsigned current_funcdef_number
= 0;
204 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
205 attribute that accelerates the lookup of the FDE associated
206 with the subprogram. This variable holds the table index of the FDE
207 associated with the current function (body) definition. */
208 static unsigned current_funcdef_fde
;
210 /* Forward declarations for functions defined in this file. */
212 static char *stripattributes
PARAMS ((const char *));
213 static const char *dwarf_cfi_name
PARAMS ((unsigned));
214 static dw_cfi_ref new_cfi
PARAMS ((void));
215 static void add_cfi
PARAMS ((dw_cfi_ref
*, dw_cfi_ref
));
216 static unsigned long size_of_uleb128
PARAMS ((unsigned long));
217 static unsigned long size_of_sleb128
PARAMS ((long));
218 static void output_uleb128
PARAMS ((unsigned long));
219 static void output_sleb128
PARAMS ((long));
220 static void add_fde_cfi
PARAMS ((const char *, dw_cfi_ref
));
221 static void lookup_cfa_1
PARAMS ((dw_cfi_ref
, dw_cfa_location
*));
222 static void lookup_cfa
PARAMS ((dw_cfa_location
*));
223 static void reg_save
PARAMS ((const char *, unsigned,
225 static void initial_return_save
PARAMS ((rtx
));
226 static long stack_adjust_offset
PARAMS ((rtx
));
227 static void output_cfi
PARAMS ((dw_cfi_ref
, dw_fde_ref
));
228 static void output_call_frame_info
PARAMS ((int));
229 static void dwarf2out_stack_adjust
PARAMS ((rtx
));
230 static void dwarf2out_frame_debug_expr
PARAMS ((rtx
, const char *));
232 /* Support for complex CFA locations. */
233 static void output_cfa_loc
PARAMS ((dw_cfi_ref
));
234 static void get_cfa_from_loc_descr
PARAMS ((dw_cfa_location
*,
235 struct dw_loc_descr_struct
*));
236 static struct dw_loc_descr_struct
*build_cfa_loc
237 PARAMS ((dw_cfa_location
*));
238 static void def_cfa_1
PARAMS ((const char *, dw_cfa_location
*));
240 /* Definitions of defaults for assembler-dependent names of various
241 pseudo-ops and section names.
242 Theses may be overridden in the tm.h file (if necessary) for a particular
245 #ifdef OBJECT_FORMAT_ELF
246 #ifndef UNALIGNED_SHORT_ASM_OP
247 #define UNALIGNED_SHORT_ASM_OP "\t.2byte\t"
249 #ifndef UNALIGNED_INT_ASM_OP
250 #define UNALIGNED_INT_ASM_OP "\t.4byte\t"
252 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
253 #define UNALIGNED_DOUBLE_INT_ASM_OP "\t.8byte\t"
255 #endif /* OBJECT_FORMAT_ELF */
258 #define ASM_BYTE_OP "\t.byte\t"
261 /* Data and reference forms for relocatable data. */
262 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
263 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
265 /* Pseudo-op for defining a new section. */
266 #ifndef SECTION_ASM_OP
267 #define SECTION_ASM_OP "\t.section\t"
270 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
271 print the SECTION_ASM_OP and the section name. The default here works for
272 almost all svr4 assemblers, except for the sparc, where the section name
273 must be enclosed in double quotes. (See sparcv4.h). */
274 #ifndef SECTION_FORMAT
275 #ifdef PUSHSECTION_FORMAT
276 #define SECTION_FORMAT PUSHSECTION_FORMAT
278 #define SECTION_FORMAT "%s%s\n"
282 #ifndef FRAME_SECTION
283 #define FRAME_SECTION ".debug_frame"
286 #ifndef FUNC_BEGIN_LABEL
287 #define FUNC_BEGIN_LABEL "LFB"
289 #ifndef FUNC_END_LABEL
290 #define FUNC_END_LABEL "LFE"
292 #define CIE_AFTER_SIZE_LABEL "LSCIE"
293 #define CIE_END_LABEL "LECIE"
294 #define CIE_LENGTH_LABEL "LLCIE"
295 #define FDE_AFTER_SIZE_LABEL "LSFDE"
296 #define FDE_END_LABEL "LEFDE"
297 #define FDE_LENGTH_LABEL "LLFDE"
298 #define DIE_LABEL_PREFIX "DW"
300 /* Definitions of defaults for various types of primitive assembly language
301 output operations. These may be overridden from within the tm.h file,
302 but typically, that is unnecessary. */
304 #ifndef ASM_OUTPUT_SECTION
305 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
306 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
309 #ifndef ASM_OUTPUT_DWARF_DATA1
310 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
311 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
314 #ifndef ASM_OUTPUT_DWARF_DELTA1
315 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
316 do { fprintf ((FILE), "%s", ASM_BYTE_OP); \
317 assemble_name (FILE, LABEL1); \
318 fprintf (FILE, "-"); \
319 assemble_name (FILE, LABEL2); \
323 #ifdef UNALIGNED_INT_ASM_OP
325 #ifndef UNALIGNED_OFFSET_ASM_OP
326 #define UNALIGNED_OFFSET_ASM_OP \
327 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
330 #ifndef UNALIGNED_WORD_ASM_OP
331 #define UNALIGNED_WORD_ASM_OP \
332 ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \
333 : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \
334 : UNALIGNED_INT_ASM_OP)
337 #ifndef ASM_OUTPUT_DWARF_DELTA2
338 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
339 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \
340 assemble_name (FILE, LABEL1); \
341 fprintf (FILE, "-"); \
342 assemble_name (FILE, LABEL2); \
346 #ifndef ASM_OUTPUT_DWARF_DELTA4
347 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
348 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
349 assemble_name (FILE, LABEL1); \
350 fprintf (FILE, "-"); \
351 assemble_name (FILE, LABEL2); \
355 #ifndef ASM_OUTPUT_DWARF_DELTA
356 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
357 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \
358 assemble_name (FILE, LABEL1); \
359 fprintf (FILE, "-"); \
360 assemble_name (FILE, LABEL2); \
364 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
365 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
366 do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
367 assemble_name (FILE, LABEL1); \
368 fprintf (FILE, "-"); \
369 assemble_name (FILE, LABEL2); \
373 #ifndef ASM_OUTPUT_DWARF_ADDR
374 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
375 do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
376 assemble_name (FILE, LABEL); \
380 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
381 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
383 fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
384 output_addr_const ((FILE), (RTX)); \
388 #ifndef ASM_OUTPUT_DWARF_OFFSET4
389 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
390 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
391 assemble_name (FILE, LABEL); \
395 #ifndef ASM_OUTPUT_DWARF_OFFSET
396 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
397 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \
398 assemble_name (FILE, LABEL); \
402 #ifndef ASM_OUTPUT_DWARF_DATA2
403 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
404 fprintf ((FILE), "%s0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
407 #ifndef ASM_OUTPUT_DWARF_DATA4
408 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
409 fprintf ((FILE), "%s0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
412 #ifndef ASM_OUTPUT_DWARF_DATA8
413 #define ASM_OUTPUT_DWARF_DATA8(FILE,VALUE) \
414 fprintf ((FILE), "%s0x%lx", UNALIGNED_DOUBLE_INT_ASM_OP, \
415 (unsigned long) (VALUE))
418 #ifndef ASM_OUTPUT_DWARF_DATA
419 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
420 fprintf ((FILE), "%s0x%lx", UNALIGNED_OFFSET_ASM_OP, \
421 (unsigned long) (VALUE))
424 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
425 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
426 fprintf ((FILE), "%s0x%lx", UNALIGNED_WORD_ASM_OP, \
427 (unsigned long) (VALUE))
430 #ifndef ASM_OUTPUT_DWARF_CONST_DOUBLE
431 #define ASM_OUTPUT_DWARF_CONST_DOUBLE(FILE,HIGH_VALUE,LOW_VALUE) \
433 if (WORDS_BIG_ENDIAN) \
435 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
436 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
440 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
441 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
446 #else /* UNALIGNED_INT_ASM_OP */
448 /* We don't have unaligned support, let's hope the normal output works for
449 .debug_frame. But we know it won't work for .debug_info. */
451 #ifdef DWARF2_DEBUGGING_INFO
452 #error DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP.
455 #ifndef ASM_OUTPUT_DWARF_ADDR
456 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
457 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1)
460 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
461 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) ASM_OUTPUT_DWARF_ADDR (FILE,RTX)
464 #ifndef ASM_OUTPUT_DWARF_OFFSET4
465 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
466 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
469 #ifndef ASM_OUTPUT_DWARF_OFFSET
470 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
471 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
474 #ifndef ASM_OUTPUT_DWARF_DELTA2
475 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
476 assemble_integer (gen_rtx_MINUS (HImode, \
477 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
478 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
482 #ifndef ASM_OUTPUT_DWARF_DELTA4
483 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
484 assemble_integer (gen_rtx_MINUS (SImode, \
485 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
486 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
490 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
491 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
492 assemble_integer (gen_rtx_MINUS (Pmode, \
493 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
494 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
498 #ifndef ASM_OUTPUT_DWARF_DELTA
499 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
500 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
503 #ifndef ASM_OUTPUT_DWARF_DATA2
504 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
505 assemble_integer (GEN_INT (VALUE), 2, 1)
508 #ifndef ASM_OUTPUT_DWARF_DATA4
509 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
510 assemble_integer (GEN_INT (VALUE), 4, 1)
513 #endif /* UNALIGNED_INT_ASM_OP */
516 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
517 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
519 fprintf (FILE, "%s", SET_ASM_OP); \
520 assemble_name (FILE, SY); \
522 assemble_name (FILE, HI); \
524 assemble_name (FILE, LO); \
527 #endif /* SET_ASM_OP */
529 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
530 newline is produced. When flag_debug_asm is asserted, we add commentary
531 at the end of the line, so we must avoid output of a newline here. */
532 #ifndef ASM_OUTPUT_DWARF_NSTRING
533 #define ASM_OUTPUT_DWARF_NSTRING(FILE,P,SLEN) \
535 register int slen = (SLEN); \
536 register const char *p = (P); \
538 fprintf (FILE, "\t.ascii \""); \
539 for (i = 0; i < slen; i++) \
541 register int c = p[i]; \
542 if (c == '\"' || c == '\\') \
548 fprintf (FILE, "\\%o", c); \
551 fprintf (FILE, "\\0\""); \
555 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
556 ASM_OUTPUT_DWARF_NSTRING (FILE, P, strlen (P))
558 /* The DWARF 2 CFA column which tracks the return address. Normally this
559 is the column for PC, or the first column after all of the hard
561 #ifndef DWARF_FRAME_RETURN_COLUMN
563 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
565 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
569 /* The mapping from gcc register number to DWARF 2 CFA column number. By
570 default, we just provide columns for all registers. */
571 #ifndef DWARF_FRAME_REGNUM
572 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
575 /* Hook used by __throw. */
578 expand_builtin_dwarf_fp_regnum ()
580 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
));
583 /* The offset from the incoming value of %sp to the top of the stack frame
584 for the current function. */
585 #ifndef INCOMING_FRAME_SP_OFFSET
586 #define INCOMING_FRAME_SP_OFFSET 0
589 /* Return a pointer to a copy of the section string name S with all
590 attributes stripped off, and an asterisk prepended (for assemble_name). */
596 char *stripped
= xmalloc (strlen (s
) + 2);
601 while (*s
&& *s
!= ',')
608 /* Generate code to initialize the register size table. */
611 expand_builtin_init_dwarf_reg_sizes (address
)
615 enum machine_mode mode
= TYPE_MODE (char_type_node
);
616 rtx addr
= expand_expr (address
, NULL_RTX
, VOIDmode
, 0);
617 rtx mem
= gen_rtx_MEM (mode
, addr
);
619 for (i
= 0; i
< DWARF_FRAME_REGISTERS
; ++i
)
621 int offset
= DWARF_FRAME_REGNUM (i
) * GET_MODE_SIZE (mode
);
622 int size
= GET_MODE_SIZE (reg_raw_mode
[i
]);
627 emit_move_insn (change_address (mem
, mode
,
628 plus_constant (addr
, offset
)),
633 /* Convert a DWARF call frame info. operation to its string name */
636 dwarf_cfi_name (cfi_opc
)
637 register unsigned cfi_opc
;
641 case DW_CFA_advance_loc
:
642 return "DW_CFA_advance_loc";
644 return "DW_CFA_offset";
646 return "DW_CFA_restore";
650 return "DW_CFA_set_loc";
651 case DW_CFA_advance_loc1
:
652 return "DW_CFA_advance_loc1";
653 case DW_CFA_advance_loc2
:
654 return "DW_CFA_advance_loc2";
655 case DW_CFA_advance_loc4
:
656 return "DW_CFA_advance_loc4";
657 case DW_CFA_offset_extended
:
658 return "DW_CFA_offset_extended";
659 case DW_CFA_restore_extended
:
660 return "DW_CFA_restore_extended";
661 case DW_CFA_undefined
:
662 return "DW_CFA_undefined";
663 case DW_CFA_same_value
:
664 return "DW_CFA_same_value";
665 case DW_CFA_register
:
666 return "DW_CFA_register";
667 case DW_CFA_remember_state
:
668 return "DW_CFA_remember_state";
669 case DW_CFA_restore_state
:
670 return "DW_CFA_restore_state";
672 return "DW_CFA_def_cfa";
673 case DW_CFA_def_cfa_register
:
674 return "DW_CFA_def_cfa_register";
675 case DW_CFA_def_cfa_offset
:
676 return "DW_CFA_def_cfa_offset";
677 case DW_CFA_def_cfa_expression
:
678 return "DW_CFA_def_cfa_expression";
680 /* SGI/MIPS specific */
681 case DW_CFA_MIPS_advance_loc8
:
682 return "DW_CFA_MIPS_advance_loc8";
685 case DW_CFA_GNU_window_save
:
686 return "DW_CFA_GNU_window_save";
687 case DW_CFA_GNU_args_size
:
688 return "DW_CFA_GNU_args_size";
689 case DW_CFA_GNU_negative_offset_extended
:
690 return "DW_CFA_GNU_negative_offset_extended";
693 return "DW_CFA_<unknown>";
697 /* Return a pointer to a newly allocated Call Frame Instruction. */
699 static inline dw_cfi_ref
702 register dw_cfi_ref cfi
= (dw_cfi_ref
) xmalloc (sizeof (dw_cfi_node
));
704 cfi
->dw_cfi_next
= NULL
;
705 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
706 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
711 /* Add a Call Frame Instruction to list of instructions. */
714 add_cfi (list_head
, cfi
)
715 register dw_cfi_ref
*list_head
;
716 register dw_cfi_ref cfi
;
718 register dw_cfi_ref
*p
;
720 /* Find the end of the chain. */
721 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
727 /* Generate a new label for the CFI info to refer to. */
730 dwarf2out_cfi_label ()
732 static char label
[20];
733 static unsigned long label_num
= 0;
735 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", label_num
++);
736 ASM_OUTPUT_LABEL (asm_out_file
, label
);
741 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
742 or to the CIE if LABEL is NULL. */
745 add_fde_cfi (label
, cfi
)
746 register const char *label
;
747 register dw_cfi_ref cfi
;
751 register dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
754 label
= dwarf2out_cfi_label ();
756 if (fde
->dw_fde_current_label
== NULL
757 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
759 register dw_cfi_ref xcfi
;
761 fde
->dw_fde_current_label
= label
= xstrdup (label
);
763 /* Set the location counter to the new label. */
765 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
766 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
767 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
770 add_cfi (&fde
->dw_fde_cfi
, cfi
);
774 add_cfi (&cie_cfi_head
, cfi
);
777 /* Subroutine of lookup_cfa. */
780 lookup_cfa_1 (cfi
, loc
)
781 register dw_cfi_ref cfi
;
782 register dw_cfa_location
*loc
;
784 switch (cfi
->dw_cfi_opc
)
786 case DW_CFA_def_cfa_offset
:
787 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
789 case DW_CFA_def_cfa_register
:
790 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
793 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
794 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
796 case DW_CFA_def_cfa_expression
:
797 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
804 /* Find the previous value for the CFA. */
808 register dw_cfa_location
*loc
;
810 register dw_cfi_ref cfi
;
812 loc
->reg
= (unsigned long) -1;
815 loc
->base_offset
= 0;
817 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
818 lookup_cfa_1 (cfi
, loc
);
820 if (fde_table_in_use
)
822 register dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
823 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
824 lookup_cfa_1 (cfi
, loc
);
828 /* The current rule for calculating the DWARF2 canonical frame address. */
831 /* The register used for saving registers to the stack, and its offset
833 dw_cfa_location cfa_store
;
835 /* The running total of the size of arguments pushed onto the stack. */
836 static long args_size
;
838 /* The last args_size we actually output. */
839 static long old_args_size
;
841 /* Entry point to update the canonical frame address (CFA).
842 LABEL is passed to add_fde_cfi. The value of CFA is now to be
843 calculated from REG+OFFSET. */
846 dwarf2out_def_cfa (label
, reg
, offset
)
847 register const char *label
;
856 def_cfa_1 (label
, &loc
);
859 /* This routine does the actual work. The CFA is now calculated from
860 the dw_cfa_location structure. */
862 def_cfa_1 (label
, loc_p
)
863 register const char *label
;
864 dw_cfa_location
*loc_p
;
866 register dw_cfi_ref cfi
;
867 dw_cfa_location old_cfa
, loc
;
872 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
873 cfa_store
.offset
= loc
.offset
;
875 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
876 lookup_cfa (&old_cfa
);
878 if (loc
.reg
== old_cfa
.reg
&& loc
.offset
== old_cfa
.offset
&&
879 loc
.indirect
== old_cfa
.indirect
)
881 if (loc
.indirect
== 0
882 || loc
.base_offset
== old_cfa
.base_offset
)
888 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
890 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
891 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
894 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
895 else if (loc
.offset
== old_cfa
.offset
&& old_cfa
.reg
!= (unsigned long) -1
898 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
899 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
903 else if (loc
.indirect
== 0)
905 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
906 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
907 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
911 struct dw_loc_descr_struct
*loc_list
;
912 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
913 loc_list
= build_cfa_loc (&loc
);
914 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
917 add_fde_cfi (label
, cfi
);
920 /* Add the CFI for saving a register. REG is the CFA column number.
921 LABEL is passed to add_fde_cfi.
922 If SREG is -1, the register is saved at OFFSET from the CFA;
923 otherwise it is saved in SREG. */
926 reg_save (label
, reg
, sreg
, offset
)
927 register const char *label
;
928 register unsigned reg
;
929 register unsigned sreg
;
930 register long offset
;
932 register dw_cfi_ref cfi
= new_cfi ();
934 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
936 /* The following comparison is correct. -1 is used to indicate that
937 the value isn't a register number. */
938 if (sreg
== (unsigned int) -1)
941 /* The register number won't fit in 6 bits, so we have to use
943 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
945 cfi
->dw_cfi_opc
= DW_CFA_offset
;
947 #ifdef ENABLE_CHECKING
949 /* If we get an offset that is not a multiple of
950 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
951 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
953 long check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
955 if (check_offset
* DWARF_CIE_DATA_ALIGNMENT
!= offset
)
959 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
962 cfi
->dw_cfi_opc
= DW_CFA_GNU_negative_offset_extended
;
965 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
967 else if (sreg
== reg
)
968 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
972 cfi
->dw_cfi_opc
= DW_CFA_register
;
973 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
976 add_fde_cfi (label
, cfi
);
979 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
980 This CFI tells the unwinder that it needs to restore the window registers
981 from the previous frame's window save area.
983 ??? Perhaps we should note in the CIE where windows are saved (instead of
984 assuming 0(cfa)) and what registers are in the window. */
987 dwarf2out_window_save (label
)
988 register const char *label
;
990 register dw_cfi_ref cfi
= new_cfi ();
991 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
992 add_fde_cfi (label
, cfi
);
995 /* Add a CFI to update the running total of the size of arguments
996 pushed onto the stack. */
999 dwarf2out_args_size (label
, size
)
1003 register dw_cfi_ref cfi
;
1005 if (size
== old_args_size
)
1007 old_args_size
= size
;
1010 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
1011 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
1012 add_fde_cfi (label
, cfi
);
1015 /* Entry point for saving a register to the stack. REG is the GCC register
1016 number. LABEL and OFFSET are passed to reg_save. */
1019 dwarf2out_reg_save (label
, reg
, offset
)
1020 register const char *label
;
1021 register unsigned reg
;
1022 register long offset
;
1024 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
1027 /* Entry point for saving the return address in the stack.
1028 LABEL and OFFSET are passed to reg_save. */
1031 dwarf2out_return_save (label
, offset
)
1032 register const char *label
;
1033 register long offset
;
1035 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, -1, offset
);
1038 /* Entry point for saving the return address in a register.
1039 LABEL and SREG are passed to reg_save. */
1042 dwarf2out_return_reg (label
, sreg
)
1043 register const char *label
;
1044 register unsigned sreg
;
1046 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, sreg
, 0);
1049 /* Record the initial position of the return address. RTL is
1050 INCOMING_RETURN_ADDR_RTX. */
1053 initial_return_save (rtl
)
1056 unsigned int reg
= (unsigned int) -1;
1059 switch (GET_CODE (rtl
))
1062 /* RA is in a register. */
1063 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
1066 /* RA is on the stack. */
1067 rtl
= XEXP (rtl
, 0);
1068 switch (GET_CODE (rtl
))
1071 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
1076 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
1078 offset
= INTVAL (XEXP (rtl
, 1));
1081 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
1083 offset
= -INTVAL (XEXP (rtl
, 1));
1090 /* The return address is at some offset from any value we can
1091 actually load. For instance, on the SPARC it is in %i7+8. Just
1092 ignore the offset for now; it doesn't matter for unwinding frames. */
1093 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
1095 initial_return_save (XEXP (rtl
, 0));
1101 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
1104 /* Given a SET, calculate the amount of stack adjustment it
1108 stack_adjust_offset (pattern
)
1111 rtx src
= SET_SRC (pattern
);
1112 rtx dest
= SET_DEST (pattern
);
1116 if (dest
== stack_pointer_rtx
)
1118 /* (set (reg sp) (plus (reg sp) (const_int))) */
1119 code
= GET_CODE (src
);
1120 if (! (code
== PLUS
|| code
== MINUS
)
1121 || XEXP (src
, 0) != stack_pointer_rtx
1122 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1125 offset
= INTVAL (XEXP (src
, 1));
1127 else if (GET_CODE (dest
) == MEM
)
1129 /* (set (mem (pre_dec (reg sp))) (foo)) */
1130 src
= XEXP (dest
, 0);
1131 code
= GET_CODE (src
);
1133 if (! (code
== PRE_DEC
|| code
== PRE_INC
1134 || code
== PRE_MODIFY
)
1135 || XEXP (src
, 0) != stack_pointer_rtx
)
1138 if (code
== PRE_MODIFY
)
1140 rtx val
= XEXP (XEXP (src
, 1), 1);
1141 /* We handle only adjustments by constant amount. */
1142 if (GET_CODE (XEXP (src
, 1)) != PLUS
||
1143 GET_CODE (val
) != CONST_INT
)
1145 offset
= -INTVAL (val
);
1147 else offset
= GET_MODE_SIZE (GET_MODE (dest
));
1152 if (code
== PLUS
|| code
== PRE_INC
)
1158 /* Check INSN to see if it looks like a push or a stack adjustment, and
1159 make a note of it if it does. EH uses this information to find out how
1160 much extra space it needs to pop off the stack. */
1163 dwarf2out_stack_adjust (insn
)
1169 if (! asynchronous_exceptions
&& GET_CODE (insn
) == CALL_INSN
)
1171 /* Extract the size of the args from the CALL rtx itself. */
1173 insn
= PATTERN (insn
);
1174 if (GET_CODE (insn
) == PARALLEL
)
1175 insn
= XVECEXP (insn
, 0, 0);
1176 if (GET_CODE (insn
) == SET
)
1177 insn
= SET_SRC (insn
);
1178 if (GET_CODE (insn
) != CALL
)
1180 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1184 /* If only calls can throw, and we have a frame pointer,
1185 save up adjustments until we see the CALL_INSN. */
1186 else if (! asynchronous_exceptions
1187 && cfa
.reg
!= STACK_POINTER_REGNUM
)
1190 if (GET_CODE (insn
) == BARRIER
)
1192 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1193 the compiler will have already emitted a stack adjustment, but
1194 doesn't bother for calls to noreturn functions. */
1195 #ifdef STACK_GROWS_DOWNWARD
1196 offset
= -args_size
;
1201 else if (GET_CODE (PATTERN (insn
)) == SET
)
1203 offset
= stack_adjust_offset (PATTERN (insn
));
1205 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1206 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1208 /* There may be stack adjustments inside compound insns. Search
1213 for (j
= XVECLEN (PATTERN (insn
), 0) - 1; j
>= 0; j
--)
1215 rtx pattern
= XVECEXP (PATTERN (insn
), 0, j
);
1216 if (GET_CODE (pattern
) == SET
)
1217 offset
+= stack_adjust_offset (pattern
);
1226 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1227 cfa
.offset
+= offset
;
1229 #ifndef STACK_GROWS_DOWNWARD
1232 args_size
+= offset
;
1236 label
= dwarf2out_cfi_label ();
1237 def_cfa_1 (label
, &cfa
);
1238 dwarf2out_args_size (label
, args_size
);
1241 /* A temporary register used in adjusting SP or setting up the store_reg. */
1242 static unsigned cfa_temp_reg
;
1244 /* A temporary value used in adjusting SP or setting up the store_reg. */
1245 static long cfa_temp_value
;
1247 /* Record call frame debugging information for an expression, which either
1248 sets SP or FP (adjusting how we calculate the frame address) or saves a
1249 register to the stack. */
1252 dwarf2out_frame_debug_expr (expr
, label
)
1259 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1260 the PARALLEL independently. The first element is always processed if
1261 it is a SET. This is for backward compatability. Other elements
1262 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1263 flag is set in them. */
1265 if (GET_CODE (expr
) == PARALLEL
1266 || GET_CODE (expr
) == SEQUENCE
)
1269 int limit
= XVECLEN (expr
, 0);
1271 for (par_index
= 0; par_index
< limit
; par_index
++)
1273 rtx x
= XVECEXP (expr
, 0, par_index
);
1275 if (GET_CODE (x
) == SET
&&
1276 (RTX_FRAME_RELATED_P (x
) || par_index
== 0))
1277 dwarf2out_frame_debug_expr (x
, label
);
1282 if (GET_CODE (expr
) != SET
)
1285 src
= SET_SRC (expr
);
1286 dest
= SET_DEST (expr
);
1288 switch (GET_CODE (dest
))
1291 /* Update the CFA rule wrt SP or FP. Make sure src is
1292 relative to the current CFA register. */
1293 switch (GET_CODE (src
))
1295 /* Setting FP from SP. */
1297 if (cfa
.reg
== (unsigned) REGNO (src
))
1303 /* We used to require that dest be either SP or FP, but the
1304 ARM copies SP to a temporary register, and from there to
1305 FP. So we just rely on the backends to only set
1306 RTX_FRAME_RELATED_P on appropriate insns. */
1307 cfa
.reg
= REGNO (dest
);
1312 if (dest
== stack_pointer_rtx
)
1315 switch (GET_CODE (XEXP (src
, 1)))
1318 offset
= INTVAL (XEXP (src
, 1));
1321 if ((unsigned) REGNO (XEXP (src
, 1)) != cfa_temp_reg
)
1323 offset
= cfa_temp_value
;
1329 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1331 /* Restoring SP from FP in the epilogue. */
1332 if (cfa
.reg
!= (unsigned) HARD_FRAME_POINTER_REGNUM
)
1334 cfa
.reg
= STACK_POINTER_REGNUM
;
1336 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1339 if (GET_CODE (src
) == PLUS
)
1341 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1342 cfa
.offset
+= offset
;
1343 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1344 cfa_store
.offset
+= offset
;
1346 else if (dest
== hard_frame_pointer_rtx
)
1348 /* Either setting the FP from an offset of the SP,
1349 or adjusting the FP */
1350 if (! frame_pointer_needed
)
1353 if (GET_CODE (XEXP (src
, 0)) == REG
1354 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1355 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1357 offset
= INTVAL (XEXP (src
, 1));
1358 if (GET_CODE (src
) == PLUS
)
1360 cfa
.offset
+= offset
;
1361 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1368 if (GET_CODE (src
) != PLUS
)
1371 if (GET_CODE (XEXP (src
, 0)) == REG
1372 && REGNO (XEXP (src
, 0)) == cfa
.reg
1373 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1374 /* Setting the FP (or a scratch that will be copied into the FP
1375 later on) from SP + const. */
1376 cfa
.reg
= REGNO (dest
);
1379 if (XEXP (src
, 1) != stack_pointer_rtx
)
1381 if (GET_CODE (XEXP (src
, 0)) != REG
1382 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp_reg
)
1384 if (cfa
.reg
!= STACK_POINTER_REGNUM
)
1386 cfa_store
.reg
= REGNO (dest
);
1387 cfa_store
.offset
= cfa
.offset
- cfa_temp_value
;
1393 cfa_temp_reg
= REGNO (dest
);
1394 cfa_temp_value
= INTVAL (src
);
1398 if (GET_CODE (XEXP (src
, 0)) != REG
1399 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp_reg
1400 || (unsigned) REGNO (dest
) != cfa_temp_reg
1401 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1403 cfa_temp_value
|= INTVAL (XEXP (src
, 1));
1409 def_cfa_1 (label
, &cfa
);
1412 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1413 will fill in all of the bits. */
1418 cfa_temp_reg
= REGNO (dest
);
1419 cfa_temp_value
= INTVAL (XEXP (src
, 1));
1423 if (GET_CODE (src
) != REG
)
1426 /* Saving a register to the stack. Make sure dest is relative to the
1428 switch (GET_CODE (XEXP (dest
, 0)))
1432 /* We can't handle variable size modifications. */
1433 if (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1)) != CONST_INT
)
1435 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1437 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1438 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1440 cfa_store
.offset
+= offset
;
1441 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1442 cfa
.offset
= cfa_store
.offset
;
1444 offset
= -cfa_store
.offset
;
1448 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1449 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1452 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1453 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1455 cfa_store
.offset
+= offset
;
1456 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1457 cfa
.offset
= cfa_store
.offset
;
1459 offset
= -cfa_store
.offset
;
1462 /* With an offset. */
1465 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1466 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1469 if (cfa_store
.reg
!= (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1471 offset
-= cfa_store
.offset
;
1474 /* Without an offset. */
1476 if (cfa_store
.reg
!= (unsigned) REGNO (XEXP (dest
, 0)))
1478 offset
= -cfa_store
.offset
;
1485 if (REGNO (src
) != STACK_POINTER_REGNUM
1486 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1487 && (unsigned) REGNO (src
) == cfa
.reg
)
1489 /* We're storing the current CFA reg into the stack. */
1491 if (cfa
.offset
== 0)
1493 /* If the source register is exactly the CFA, assume
1494 we're saving SP like any other register; this happens
1497 def_cfa_1 (label
, &cfa
);
1498 dwarf2out_reg_save (label
, STACK_POINTER_REGNUM
, offset
);
1503 /* Otherwise, we'll need to look in the stack to
1504 calculate the CFA. */
1506 rtx x
= XEXP (dest
, 0);
1507 if (GET_CODE (x
) != REG
)
1509 if (GET_CODE (x
) != REG
)
1511 cfa
.reg
= (unsigned) REGNO (x
);
1512 cfa
.base_offset
= offset
;
1514 def_cfa_1 (label
, &cfa
);
1519 def_cfa_1 (label
, &cfa
);
1520 dwarf2out_reg_save (label
, REGNO (src
), offset
);
1528 /* Record call frame debugging information for INSN, which either
1529 sets SP or FP (adjusting how we calculate the frame address) or saves a
1530 register to the stack. If INSN is NULL_RTX, initialize our state. */
1533 dwarf2out_frame_debug (insn
)
1539 if (insn
== NULL_RTX
)
1541 /* Set up state for generating call frame debug info. */
1543 if (cfa
.reg
!= (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1545 cfa
.reg
= STACK_POINTER_REGNUM
;
1552 if (! RTX_FRAME_RELATED_P (insn
))
1554 dwarf2out_stack_adjust (insn
);
1558 label
= dwarf2out_cfi_label ();
1560 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1562 insn
= XEXP (src
, 0);
1564 insn
= PATTERN (insn
);
1566 dwarf2out_frame_debug_expr (insn
, label
);
1569 /* Return the size of an unsigned LEB128 quantity. */
1571 static inline unsigned long
1572 size_of_uleb128 (value
)
1573 register unsigned long value
;
1575 register unsigned long size
= 0;
1576 register unsigned byte
;
1580 byte
= (value
& 0x7f);
1589 /* Return the size of a signed LEB128 quantity. */
1591 static inline unsigned long
1592 size_of_sleb128 (value
)
1593 register long value
;
1595 register unsigned long size
= 0;
1596 register unsigned byte
;
1600 byte
= (value
& 0x7f);
1604 while (!(((value
== 0) && ((byte
& 0x40) == 0))
1605 || ((value
== -1) && ((byte
& 0x40) != 0))));
1610 /* Output an unsigned LEB128 quantity. */
1613 output_uleb128 (value
)
1614 register unsigned long value
;
1616 unsigned long save_value
= value
;
1618 fprintf (asm_out_file
, "%s", ASM_BYTE_OP
);
1621 register unsigned byte
= (value
& 0x7f);
1624 /* More bytes to follow. */
1627 fprintf (asm_out_file
, "0x%x", byte
);
1629 fprintf (asm_out_file
, ",");
1634 fprintf (asm_out_file
, "\t%s ULEB128 0x%lx", ASM_COMMENT_START
, save_value
);
1637 /* Output an signed LEB128 quantity. */
1640 output_sleb128 (value
)
1641 register long value
;
1644 register unsigned byte
;
1645 long save_value
= value
;
1647 fprintf (asm_out_file
, "%s", ASM_BYTE_OP
);
1650 byte
= (value
& 0x7f);
1651 /* arithmetic shift */
1653 more
= !((((value
== 0) && ((byte
& 0x40) == 0))
1654 || ((value
== -1) && ((byte
& 0x40) != 0))));
1658 fprintf (asm_out_file
, "0x%x", byte
);
1660 fprintf (asm_out_file
, ",");
1665 fprintf (asm_out_file
, "\t%s SLEB128 %ld", ASM_COMMENT_START
, save_value
);
1668 /* Output a Call Frame Information opcode and its operand(s). */
1671 output_cfi (cfi
, fde
)
1672 register dw_cfi_ref cfi
;
1673 register dw_fde_ref fde
;
1675 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1677 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
1679 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f));
1681 fprintf (asm_out_file
, "\t%s DW_CFA_advance_loc 0x%lx",
1682 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1683 fputc ('\n', asm_out_file
);
1686 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1688 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
1690 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f));
1692 fprintf (asm_out_file
, "\t%s DW_CFA_offset, column 0x%lx",
1693 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1695 fputc ('\n', asm_out_file
);
1696 output_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
1697 fputc ('\n', asm_out_file
);
1699 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1701 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
1703 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f));
1705 fprintf (asm_out_file
, "\t%s DW_CFA_restore, column 0x%lx",
1706 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1708 fputc ('\n', asm_out_file
);
1712 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, cfi
->dw_cfi_opc
);
1714 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
,
1715 dwarf_cfi_name (cfi
->dw_cfi_opc
));
1717 fputc ('\n', asm_out_file
);
1718 switch (cfi
->dw_cfi_opc
)
1720 case DW_CFA_set_loc
:
1721 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
);
1722 fputc ('\n', asm_out_file
);
1724 case DW_CFA_advance_loc1
:
1725 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file
,
1726 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1727 fde
->dw_fde_current_label
);
1728 fputc ('\n', asm_out_file
);
1729 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1731 case DW_CFA_advance_loc2
:
1732 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
,
1733 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1734 fde
->dw_fde_current_label
);
1735 fputc ('\n', asm_out_file
);
1736 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1738 case DW_CFA_advance_loc4
:
1739 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
,
1740 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1741 fde
->dw_fde_current_label
);
1742 fputc ('\n', asm_out_file
);
1743 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1745 #ifdef MIPS_DEBUGGING_INFO
1746 case DW_CFA_MIPS_advance_loc8
:
1747 /* TODO: not currently implemented. */
1751 case DW_CFA_offset_extended
:
1752 case DW_CFA_GNU_negative_offset_extended
:
1753 case DW_CFA_def_cfa
:
1754 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1755 fputc ('\n', asm_out_file
);
1756 output_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
1757 fputc ('\n', asm_out_file
);
1759 case DW_CFA_restore_extended
:
1760 case DW_CFA_undefined
:
1761 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1762 fputc ('\n', asm_out_file
);
1764 case DW_CFA_same_value
:
1765 case DW_CFA_def_cfa_register
:
1766 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1767 fputc ('\n', asm_out_file
);
1769 case DW_CFA_register
:
1770 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1771 fputc ('\n', asm_out_file
);
1772 output_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
);
1773 fputc ('\n', asm_out_file
);
1775 case DW_CFA_def_cfa_offset
:
1776 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1777 fputc ('\n', asm_out_file
);
1779 case DW_CFA_GNU_window_save
:
1781 case DW_CFA_GNU_args_size
:
1782 output_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1783 fputc ('\n', asm_out_file
);
1785 case DW_CFA_def_cfa_expression
:
1786 output_cfa_loc (cfi
);
1794 /* Output the call frame information used to used to record information
1795 that relates to calculating the frame pointer, and records the
1796 location of saved registers. */
1799 output_call_frame_info (for_eh
)
1802 register unsigned long i
;
1803 register dw_fde_ref fde
;
1804 register dw_cfi_ref cfi
;
1805 char l1
[20], l2
[20];
1806 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1810 /* Do we want to include a pointer to the exception table? */
1811 int eh_ptr
= for_eh
&& exception_table_p ();
1813 /* If we don't have any functions we'll want to unwind out of, don't
1814 emit any EH unwind information. */
1817 for (i
= 0; i
< fde_table_in_use
; ++i
)
1818 if (! fde_table
[i
].nothrow
)
1824 fputc ('\n', asm_out_file
);
1826 /* We're going to be generating comments, so turn on app. */
1832 #ifdef EH_FRAME_SECTION
1833 EH_FRAME_SECTION ();
1835 tree label
= get_file_function_name ('F');
1837 force_data_section ();
1838 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DWARF2_ADDR_SIZE
));
1839 ASM_GLOBALIZE_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
1840 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
1842 assemble_label ("__FRAME_BEGIN__");
1845 ASM_OUTPUT_SECTION (asm_out_file
, FRAME_SECTION
);
1847 /* Output the CIE. */
1848 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
1849 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
1850 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1851 ASM_GENERATE_INTERNAL_LABEL (ld
, CIE_LENGTH_LABEL
, for_eh
);
1853 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file
, ld
);
1855 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, ld
);
1858 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
, l2
, l1
);
1860 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, l2
, l1
);
1863 fprintf (asm_out_file
, "\t%s Length of Common Information Entry",
1866 fputc ('\n', asm_out_file
);
1867 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1870 /* Now that the CIE pointer is PC-relative for EH,
1871 use 0 to identify the CIE. */
1872 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 0);
1874 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, DW_CIE_ID
);
1877 fprintf (asm_out_file
, "\t%s CIE Identifier Tag", ASM_COMMENT_START
);
1879 fputc ('\n', asm_out_file
);
1880 if (! for_eh
&& DWARF_OFFSET_SIZE
== 8)
1882 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, DW_CIE_ID
);
1883 fputc ('\n', asm_out_file
);
1886 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_CIE_VERSION
);
1888 fprintf (asm_out_file
, "\t%s CIE Version", ASM_COMMENT_START
);
1890 fputc ('\n', asm_out_file
);
1893 /* The CIE contains a pointer to the exception region info for the
1894 frame. Make the augmentation string three bytes (including the
1895 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1896 can't handle unaligned relocs. */
1899 ASM_OUTPUT_DWARF_STRING (asm_out_file
, "eh");
1900 fprintf (asm_out_file
, "\t%s CIE Augmentation", ASM_COMMENT_START
);
1904 ASM_OUTPUT_ASCII (asm_out_file
, "eh", 3);
1906 fputc ('\n', asm_out_file
);
1908 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, "__EXCEPTION_TABLE__");
1910 fprintf (asm_out_file
, "\t%s pointer to exception region info",
1915 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
1917 fprintf (asm_out_file
, "\t%s CIE Augmentation (none)",
1921 fputc ('\n', asm_out_file
);
1924 fprintf (asm_out_file
, " (CIE Code Alignment Factor)");
1926 fputc ('\n', asm_out_file
);
1927 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT
);
1929 fprintf (asm_out_file
, " (CIE Data Alignment Factor)");
1931 fputc ('\n', asm_out_file
);
1932 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_FRAME_RETURN_COLUMN
);
1934 fprintf (asm_out_file
, "\t%s CIE RA Column", ASM_COMMENT_START
);
1936 fputc ('\n', asm_out_file
);
1938 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
1939 output_cfi (cfi
, NULL
);
1941 /* Pad the CIE out to an address sized boundary. */
1942 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DWARF2_ADDR_SIZE
));
1943 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
1944 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1945 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file
, ld
, l2
, l1
);
1947 fprintf (asm_out_file
, "\t%s CIE Length Symbol", ASM_COMMENT_START
);
1948 fputc ('\n', asm_out_file
);
1951 /* Loop through all of the FDE's. */
1952 for (i
= 0; i
< fde_table_in_use
; ++i
)
1954 fde
= &fde_table
[i
];
1956 /* Don't emit EH unwind info for leaf functions. */
1957 if (for_eh
&& fde
->nothrow
)
1960 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
1961 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
1962 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1963 ASM_GENERATE_INTERNAL_LABEL (ld
, FDE_LENGTH_LABEL
, for_eh
+ i
* 2);
1965 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file
, ld
);
1967 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, ld
);
1970 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
, l2
, l1
);
1972 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, l2
, l1
);
1975 fprintf (asm_out_file
, "\t%s FDE Length", ASM_COMMENT_START
);
1976 fputc ('\n', asm_out_file
);
1977 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1979 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1980 emits a target dependent sized offset when for_eh is not true.
1981 This inconsistency may confuse gdb. The only case where we need a
1982 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1983 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1984 though in order to be compatible with the dwarf_fde struct in frame.c.
1985 If the for_eh case is changed, then the struct in frame.c has
1986 to be adjusted appropriately. */
1988 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
, l1
, "__FRAME_BEGIN__");
1990 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, stripattributes (FRAME_SECTION
));
1992 fprintf (asm_out_file
, "\t%s FDE CIE offset", ASM_COMMENT_START
);
1994 fputc ('\n', asm_out_file
);
1995 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, fde
->dw_fde_begin
);
1997 fprintf (asm_out_file
, "\t%s FDE initial location", ASM_COMMENT_START
);
1999 fputc ('\n', asm_out_file
);
2000 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
,
2001 fde
->dw_fde_end
, fde
->dw_fde_begin
);
2003 fprintf (asm_out_file
, "\t%s FDE address range", ASM_COMMENT_START
);
2005 fputc ('\n', asm_out_file
);
2007 /* Loop through the Call Frame Instructions associated with
2009 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2010 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2011 output_cfi (cfi
, fde
);
2013 /* Pad the FDE out to an address sized boundary. */
2014 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DWARF2_ADDR_SIZE
));
2015 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2016 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2017 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file
, ld
, l2
, l1
);
2019 fprintf (asm_out_file
, "\t%s FDE Length Symbol", ASM_COMMENT_START
);
2020 fputc ('\n', asm_out_file
);
2023 #ifndef EH_FRAME_SECTION
2026 /* Emit terminating zero for table. */
2027 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 0);
2028 fputc ('\n', asm_out_file
);
2031 #ifdef MIPS_DEBUGGING_INFO
2032 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2033 get a value of 0. Putting .align 0 after the label fixes it. */
2034 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2037 /* Turn off app to make assembly quicker. */
2042 /* Output a marker (i.e. a label) for the beginning of a function, before
2046 dwarf2out_begin_prologue ()
2048 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2049 register dw_fde_ref fde
;
2051 ++current_funcdef_number
;
2053 function_section (current_function_decl
);
2054 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2055 current_funcdef_number
);
2056 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2057 current_function_func_begin_label
= get_identifier (label
);
2059 /* Expand the fde table if necessary. */
2060 if (fde_table_in_use
== fde_table_allocated
)
2062 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2064 = (dw_fde_ref
) xrealloc (fde_table
,
2065 fde_table_allocated
* sizeof (dw_fde_node
));
2068 /* Record the FDE associated with this function. */
2069 current_funcdef_fde
= fde_table_in_use
;
2071 /* Add the new FDE at the end of the fde_table. */
2072 fde
= &fde_table
[fde_table_in_use
++];
2073 fde
->dw_fde_begin
= xstrdup (label
);
2074 fde
->dw_fde_current_label
= NULL
;
2075 fde
->dw_fde_end
= NULL
;
2076 fde
->dw_fde_cfi
= NULL
;
2077 fde
->nothrow
= current_function_nothrow
;
2079 args_size
= old_args_size
= 0;
2082 /* Output a marker (i.e. a label) for the absolute end of the generated code
2083 for a function definition. This gets called *after* the epilogue code has
2087 dwarf2out_end_epilogue ()
2090 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2092 /* Output a label to mark the endpoint of the code generated for this
2094 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
, current_funcdef_number
);
2095 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2096 fde
= &fde_table
[fde_table_in_use
- 1];
2097 fde
->dw_fde_end
= xstrdup (label
);
2101 dwarf2out_frame_init ()
2103 /* Allocate the initial hunk of the fde_table. */
2104 fde_table
= (dw_fde_ref
) xcalloc (FDE_TABLE_INCREMENT
, sizeof (dw_fde_node
));
2105 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2106 fde_table_in_use
= 0;
2108 /* Generate the CFA instructions common to all FDE's. Do it now for the
2109 sake of lookup_cfa. */
2111 #ifdef DWARF2_UNWIND_INFO
2112 /* On entry, the Canonical Frame Address is at SP. */
2113 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2114 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2119 dwarf2out_frame_finish ()
2121 /* Output call frame information. */
2122 #ifdef MIPS_DEBUGGING_INFO
2123 if (write_symbols
== DWARF2_DEBUG
)
2124 output_call_frame_info (0);
2125 if (flag_unwind_tables
|| (flag_exceptions
&& ! exceptions_via_longjmp
))
2126 output_call_frame_info (1);
2128 if (write_symbols
== DWARF2_DEBUG
2129 || flag_unwind_tables
|| (flag_exceptions
&& ! exceptions_via_longjmp
))
2130 output_call_frame_info (1);
2134 /* And now, the subset of the debugging information support code necessary
2135 for emitting location expressions. */
2137 typedef struct dw_val_struct
*dw_val_ref
;
2138 typedef struct die_struct
*dw_die_ref
;
2139 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2141 /* Each DIE may have a series of attribute/value pairs. Values
2142 can take on several forms. The forms that are used in this
2143 implementation are listed below. */
2150 dw_val_class_unsigned_const
,
2151 dw_val_class_long_long
,
2154 dw_val_class_die_ref
,
2155 dw_val_class_fde_ref
,
2156 dw_val_class_lbl_id
,
2157 dw_val_class_lbl_offset
,
2162 /* Describe a double word constant value. */
2163 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2165 typedef struct dw_long_long_struct
2172 /* Describe a floating point constant value. */
2174 typedef struct dw_fp_struct
2181 /* The dw_val_node describes an attribute's value, as it is
2182 represented internally. */
2184 typedef struct dw_val_struct
2186 dw_val_class val_class
;
2190 dw_loc_descr_ref val_loc
;
2192 long unsigned val_unsigned
;
2193 dw_long_long_const val_long_long
;
2194 dw_float_const val_float
;
2199 unsigned val_fde_index
;
2202 unsigned char val_flag
;
2208 /* Locations in memory are described using a sequence of stack machine
2211 typedef struct dw_loc_descr_struct
2213 dw_loc_descr_ref dw_loc_next
;
2214 enum dwarf_location_atom dw_loc_opc
;
2215 dw_val_node dw_loc_oprnd1
;
2216 dw_val_node dw_loc_oprnd2
;
2221 static const char *dwarf_stack_op_name
PARAMS ((unsigned));
2222 static dw_loc_descr_ref new_loc_descr
PARAMS ((enum dwarf_location_atom
,
2225 static void add_loc_descr
PARAMS ((dw_loc_descr_ref
*,
2227 static unsigned long size_of_loc_descr
PARAMS ((dw_loc_descr_ref
));
2228 static unsigned long size_of_locs
PARAMS ((dw_loc_descr_ref
));
2229 static void output_loc_operands
PARAMS ((dw_loc_descr_ref
));
2230 static void output_loc_sequence
PARAMS ((dw_loc_descr_ref
));
2232 /* Convert a DWARF stack opcode into its string name. */
2235 dwarf_stack_op_name (op
)
2236 register unsigned op
;
2241 return "DW_OP_addr";
2243 return "DW_OP_deref";
2245 return "DW_OP_const1u";
2247 return "DW_OP_const1s";
2249 return "DW_OP_const2u";
2251 return "DW_OP_const2s";
2253 return "DW_OP_const4u";
2255 return "DW_OP_const4s";
2257 return "DW_OP_const8u";
2259 return "DW_OP_const8s";
2261 return "DW_OP_constu";
2263 return "DW_OP_consts";
2267 return "DW_OP_drop";
2269 return "DW_OP_over";
2271 return "DW_OP_pick";
2273 return "DW_OP_swap";
2277 return "DW_OP_xderef";
2285 return "DW_OP_minus";
2297 return "DW_OP_plus";
2298 case DW_OP_plus_uconst
:
2299 return "DW_OP_plus_uconst";
2305 return "DW_OP_shra";
2323 return "DW_OP_skip";
2325 return "DW_OP_lit0";
2327 return "DW_OP_lit1";
2329 return "DW_OP_lit2";
2331 return "DW_OP_lit3";
2333 return "DW_OP_lit4";
2335 return "DW_OP_lit5";
2337 return "DW_OP_lit6";
2339 return "DW_OP_lit7";
2341 return "DW_OP_lit8";
2343 return "DW_OP_lit9";
2345 return "DW_OP_lit10";
2347 return "DW_OP_lit11";
2349 return "DW_OP_lit12";
2351 return "DW_OP_lit13";
2353 return "DW_OP_lit14";
2355 return "DW_OP_lit15";
2357 return "DW_OP_lit16";
2359 return "DW_OP_lit17";
2361 return "DW_OP_lit18";
2363 return "DW_OP_lit19";
2365 return "DW_OP_lit20";
2367 return "DW_OP_lit21";
2369 return "DW_OP_lit22";
2371 return "DW_OP_lit23";
2373 return "DW_OP_lit24";
2375 return "DW_OP_lit25";
2377 return "DW_OP_lit26";
2379 return "DW_OP_lit27";
2381 return "DW_OP_lit28";
2383 return "DW_OP_lit29";
2385 return "DW_OP_lit30";
2387 return "DW_OP_lit31";
2389 return "DW_OP_reg0";
2391 return "DW_OP_reg1";
2393 return "DW_OP_reg2";
2395 return "DW_OP_reg3";
2397 return "DW_OP_reg4";
2399 return "DW_OP_reg5";
2401 return "DW_OP_reg6";
2403 return "DW_OP_reg7";
2405 return "DW_OP_reg8";
2407 return "DW_OP_reg9";
2409 return "DW_OP_reg10";
2411 return "DW_OP_reg11";
2413 return "DW_OP_reg12";
2415 return "DW_OP_reg13";
2417 return "DW_OP_reg14";
2419 return "DW_OP_reg15";
2421 return "DW_OP_reg16";
2423 return "DW_OP_reg17";
2425 return "DW_OP_reg18";
2427 return "DW_OP_reg19";
2429 return "DW_OP_reg20";
2431 return "DW_OP_reg21";
2433 return "DW_OP_reg22";
2435 return "DW_OP_reg23";
2437 return "DW_OP_reg24";
2439 return "DW_OP_reg25";
2441 return "DW_OP_reg26";
2443 return "DW_OP_reg27";
2445 return "DW_OP_reg28";
2447 return "DW_OP_reg29";
2449 return "DW_OP_reg30";
2451 return "DW_OP_reg31";
2453 return "DW_OP_breg0";
2455 return "DW_OP_breg1";
2457 return "DW_OP_breg2";
2459 return "DW_OP_breg3";
2461 return "DW_OP_breg4";
2463 return "DW_OP_breg5";
2465 return "DW_OP_breg6";
2467 return "DW_OP_breg7";
2469 return "DW_OP_breg8";
2471 return "DW_OP_breg9";
2473 return "DW_OP_breg10";
2475 return "DW_OP_breg11";
2477 return "DW_OP_breg12";
2479 return "DW_OP_breg13";
2481 return "DW_OP_breg14";
2483 return "DW_OP_breg15";
2485 return "DW_OP_breg16";
2487 return "DW_OP_breg17";
2489 return "DW_OP_breg18";
2491 return "DW_OP_breg19";
2493 return "DW_OP_breg20";
2495 return "DW_OP_breg21";
2497 return "DW_OP_breg22";
2499 return "DW_OP_breg23";
2501 return "DW_OP_breg24";
2503 return "DW_OP_breg25";
2505 return "DW_OP_breg26";
2507 return "DW_OP_breg27";
2509 return "DW_OP_breg28";
2511 return "DW_OP_breg29";
2513 return "DW_OP_breg30";
2515 return "DW_OP_breg31";
2517 return "DW_OP_regx";
2519 return "DW_OP_fbreg";
2521 return "DW_OP_bregx";
2523 return "DW_OP_piece";
2524 case DW_OP_deref_size
:
2525 return "DW_OP_deref_size";
2526 case DW_OP_xderef_size
:
2527 return "DW_OP_xderef_size";
2531 return "OP_<unknown>";
2535 /* Return a pointer to a newly allocated location description. Location
2536 descriptions are simple expression terms that can be strung
2537 together to form more complicated location (address) descriptions. */
2539 static inline dw_loc_descr_ref
2540 new_loc_descr (op
, oprnd1
, oprnd2
)
2541 register enum dwarf_location_atom op
;
2542 register unsigned long oprnd1
;
2543 register unsigned long oprnd2
;
2545 /* Use xcalloc here so we clear out all of the long_long constant in
2547 register dw_loc_descr_ref descr
2548 = (dw_loc_descr_ref
) xcalloc (1, sizeof (dw_loc_descr_node
));
2550 descr
->dw_loc_opc
= op
;
2551 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
2552 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
2553 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
2554 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
2559 /* Add a location description term to a location description expression. */
2562 add_loc_descr (list_head
, descr
)
2563 register dw_loc_descr_ref
*list_head
;
2564 register dw_loc_descr_ref descr
;
2566 register dw_loc_descr_ref
*d
;
2568 /* Find the end of the chain. */
2569 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
2575 /* Return the size of a location descriptor. */
2577 static unsigned long
2578 size_of_loc_descr (loc
)
2579 register dw_loc_descr_ref loc
;
2581 register unsigned long size
= 1;
2583 switch (loc
->dw_loc_opc
)
2586 size
+= DWARF2_ADDR_SIZE
;
2605 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2608 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2613 case DW_OP_plus_uconst
:
2614 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2652 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2655 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2658 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2661 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2662 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
2665 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2667 case DW_OP_deref_size
:
2668 case DW_OP_xderef_size
:
2678 /* Return the size of a series of location descriptors. */
2680 static unsigned long
2682 register dw_loc_descr_ref loc
;
2684 register unsigned long size
= 0;
2686 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2688 loc
->dw_loc_addr
= size
;
2689 size
+= size_of_loc_descr (loc
);
2695 /* Output location description stack opcode's operands (if any). */
2698 output_loc_operands (loc
)
2699 register dw_loc_descr_ref loc
;
2701 register dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2702 register dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2704 switch (loc
->dw_loc_opc
)
2706 #ifdef DWARF2_DEBUGGING_INFO
2708 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
, val1
->v
.val_addr
);
2709 fputc ('\n', asm_out_file
);
2713 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, val1
->v
.val_int
);
2714 fputc ('\n', asm_out_file
);
2718 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, val1
->v
.val_int
);
2719 fputc ('\n', asm_out_file
);
2724 fputc ('\n', asm_out_file
);
2731 if (val1
->val_class
== dw_val_class_loc
)
2732 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2736 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, offset
);
2737 fputc ('\n', asm_out_file
);
2750 /* We currently don't make any attempt to make sure these are
2751 aligned properly like we do for the main unwind info, so
2752 don't support emitting things larger than a byte if we're
2753 only doing unwinding. */
2758 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_flag
);
2759 fputc ('\n', asm_out_file
);
2762 output_uleb128 (val1
->v
.val_unsigned
);
2763 fputc ('\n', asm_out_file
);
2766 output_sleb128 (val1
->v
.val_int
);
2767 fputc ('\n', asm_out_file
);
2770 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_int
);
2771 fputc ('\n', asm_out_file
);
2773 case DW_OP_plus_uconst
:
2774 output_uleb128 (val1
->v
.val_unsigned
);
2775 fputc ('\n', asm_out_file
);
2809 output_sleb128 (val1
->v
.val_int
);
2810 fputc ('\n', asm_out_file
);
2813 output_uleb128 (val1
->v
.val_unsigned
);
2814 fputc ('\n', asm_out_file
);
2817 output_sleb128 (val1
->v
.val_int
);
2818 fputc ('\n', asm_out_file
);
2821 output_uleb128 (val1
->v
.val_unsigned
);
2822 fputc ('\n', asm_out_file
);
2823 output_sleb128 (val2
->v
.val_int
);
2824 fputc ('\n', asm_out_file
);
2827 output_uleb128 (val1
->v
.val_unsigned
);
2828 fputc ('\n', asm_out_file
);
2830 case DW_OP_deref_size
:
2831 case DW_OP_xderef_size
:
2832 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_flag
);
2833 fputc ('\n', asm_out_file
);
2836 /* Other codes have no operands. */
2841 /* Output a sequence of location operations. */
2844 output_loc_sequence (loc
)
2845 dw_loc_descr_ref loc
;
2847 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2849 /* Output the opcode. */
2850 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, loc
->dw_loc_opc
);
2852 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
,
2853 dwarf_stack_op_name (loc
->dw_loc_opc
));
2855 fputc ('\n', asm_out_file
);
2857 /* Output the operand(s) (if any). */
2858 output_loc_operands (loc
);
2862 /* This routine will generate the correct assembly data for a location
2863 description based on a cfi entry with a complex address. */
2866 output_cfa_loc (cfi
)
2869 dw_loc_descr_ref loc
;
2872 /* Output the size of the block. */
2873 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
2874 size
= size_of_locs (loc
);
2875 output_uleb128 (size
);
2876 fputc ('\n', asm_out_file
);
2878 /* Now output the operations themselves. */
2879 output_loc_sequence (loc
);
2882 /* This function builds a dwarf location descriptor seqeunce from
2883 a dw_cfa_location. */
2885 static struct dw_loc_descr_struct
*
2887 dw_cfa_location
*cfa
;
2889 struct dw_loc_descr_struct
*head
, *tmp
;
2891 if (cfa
->indirect
== 0)
2894 if (cfa
->base_offset
)
2897 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
2899 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
2901 else if (cfa
->reg
<= 31)
2902 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
2904 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
2905 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2906 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2907 add_loc_descr (&head
, tmp
);
2908 if (cfa
->offset
!= 0)
2910 tmp
= new_loc_descr (DW_OP_plus_uconst
, cfa
->offset
, 0);
2911 add_loc_descr (&head
, tmp
);
2916 /* This function fills in aa dw_cfa_location structure from a
2917 dwarf location descriptor sequence. */
2920 get_cfa_from_loc_descr (cfa
, loc
)
2921 dw_cfa_location
*cfa
;
2922 struct dw_loc_descr_struct
*loc
;
2924 struct dw_loc_descr_struct
*ptr
;
2926 cfa
->base_offset
= 0;
2930 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
2932 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
2967 cfa
->reg
= op
- DW_OP_reg0
;
2970 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3004 cfa
->reg
= op
- DW_OP_breg0
;
3005 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3008 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3009 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3014 case DW_OP_plus_uconst
:
3015 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3018 fatal ("DW_LOC_OP %s not implememnted yet.\n",
3019 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3023 #endif /* .debug_frame support */
3025 /* And now, the support for symbolic debugging information. */
3026 #ifdef DWARF2_DEBUGGING_INFO
3028 /* NOTE: In the comments in this file, many references are made to
3029 "Debugging Information Entries". This term is abbreviated as `DIE'
3030 throughout the remainder of this file. */
3032 /* An internal representation of the DWARF output is built, and then
3033 walked to generate the DWARF debugging info. The walk of the internal
3034 representation is done after the entire program has been compiled.
3035 The types below are used to describe the internal representation. */
3037 /* Various DIE's use offsets relative to the beginning of the
3038 .debug_info section to refer to each other. */
3040 typedef long int dw_offset
;
3042 /* Define typedefs here to avoid circular dependencies. */
3044 typedef struct dw_attr_struct
*dw_attr_ref
;
3045 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3046 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3047 typedef struct pubname_struct
*pubname_ref
;
3048 typedef dw_die_ref
*arange_ref
;
3050 /* Each entry in the line_info_table maintains the file and
3051 line number associated with the label generated for that
3052 entry. The label gives the PC value associated with
3053 the line number entry. */
3055 typedef struct dw_line_info_struct
3057 unsigned long dw_file_num
;
3058 unsigned long dw_line_num
;
3062 /* Line information for functions in separate sections; each one gets its
3064 typedef struct dw_separate_line_info_struct
3066 unsigned long dw_file_num
;
3067 unsigned long dw_line_num
;
3068 unsigned long function
;
3070 dw_separate_line_info_entry
;
3072 /* Each DIE attribute has a field specifying the attribute kind,
3073 a link to the next attribute in the chain, and an attribute value.
3074 Attributes are typically linked below the DIE they modify. */
3076 typedef struct dw_attr_struct
3078 enum dwarf_attribute dw_attr
;
3079 dw_attr_ref dw_attr_next
;
3080 dw_val_node dw_attr_val
;
3084 /* The Debugging Information Entry (DIE) structure */
3086 typedef struct die_struct
3088 enum dwarf_tag die_tag
;
3090 dw_attr_ref die_attr
;
3091 dw_die_ref die_parent
;
3092 dw_die_ref die_child
;
3094 dw_offset die_offset
;
3095 unsigned long die_abbrev
;
3100 /* The pubname structure */
3102 typedef struct pubname_struct
3109 /* The limbo die list structure. */
3110 typedef struct limbo_die_struct
3113 struct limbo_die_struct
*next
;
3117 /* How to start an assembler comment. */
3118 #ifndef ASM_COMMENT_START
3119 #define ASM_COMMENT_START ";#"
3122 /* Define a macro which returns non-zero for a TYPE_DECL which was
3123 implicitly generated for a tagged type.
3125 Note that unlike the gcc front end (which generates a NULL named
3126 TYPE_DECL node for each complete tagged type, each array type, and
3127 each function type node created) the g++ front end generates a
3128 _named_ TYPE_DECL node for each tagged type node created.
3129 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3130 generate a DW_TAG_typedef DIE for them. */
3132 #define TYPE_DECL_IS_STUB(decl) \
3133 (DECL_NAME (decl) == NULL_TREE \
3134 || (DECL_ARTIFICIAL (decl) \
3135 && is_tagged_type (TREE_TYPE (decl)) \
3136 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3137 /* This is necessary for stub decls that \
3138 appear in nested inline functions. */ \
3139 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3140 && (decl_ultimate_origin (decl) \
3141 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3143 /* Information concerning the compilation unit's programming
3144 language, and compiler version. */
3146 extern int flag_traditional
;
3148 /* Fixed size portion of the DWARF compilation unit header. */
3149 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3151 /* Fixed size portion of debugging line information prolog. */
3152 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3154 /* Fixed size portion of public names info. */
3155 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3157 /* Fixed size portion of the address range info. */
3158 #define DWARF_ARANGES_HEADER_SIZE \
3159 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3160 - DWARF_OFFSET_SIZE)
3162 /* Size of padding portion in the address range info. It must be
3163 aligned to twice the pointer size. */
3164 #define DWARF_ARANGES_PAD_SIZE \
3165 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3166 - (2 * DWARF_OFFSET_SIZE + 4))
3168 /* Use assembler line directives if available. */
3169 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3170 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3171 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3173 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3177 /* Define the architecture-dependent minimum instruction length (in bytes).
3178 In this implementation of DWARF, this field is used for information
3179 purposes only. Since GCC generates assembly language, we have
3180 no a priori knowledge of how many instruction bytes are generated
3181 for each source line, and therefore can use only the DW_LNE_set_address
3182 and DW_LNS_fixed_advance_pc line information commands. */
3184 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3185 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3188 /* Minimum line offset in a special line info. opcode.
3189 This value was chosen to give a reasonable range of values. */
3190 #define DWARF_LINE_BASE -10
3192 /* First special line opcde - leave room for the standard opcodes. */
3193 #define DWARF_LINE_OPCODE_BASE 10
3195 /* Range of line offsets in a special line info. opcode. */
3196 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3198 /* Flag that indicates the initial value of the is_stmt_start flag.
3199 In the present implementation, we do not mark any lines as
3200 the beginning of a source statement, because that information
3201 is not made available by the GCC front-end. */
3202 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3204 /* This location is used by calc_die_sizes() to keep track
3205 the offset of each DIE within the .debug_info section. */
3206 static unsigned long next_die_offset
;
3208 /* Record the root of the DIE's built for the current compilation unit. */
3209 static dw_die_ref comp_unit_die
;
3211 /* A list of DIEs with a NULL parent waiting to be relocated. */
3212 static limbo_die_node
*limbo_die_list
= 0;
3214 /* Structure used by lookup_filename to manage sets of filenames. */
3220 unsigned last_lookup_index
;
3223 /* Size (in elements) of increments by which we may expand the filename
3225 #define FILE_TABLE_INCREMENT 64
3227 /* Filenames referenced by declarations this compilation unit. */
3228 static struct file_table decl_file_table
;
3230 /* Filenames referenced by line numbers in this compilation unit. */
3231 static struct file_table line_file_table
;
3233 /* Local pointer to the name of the main input file. Initialized in
3235 static const char *primary_filename
;
3237 /* A pointer to the base of a table of references to DIE's that describe
3238 declarations. The table is indexed by DECL_UID() which is a unique
3239 number identifying each decl. */
3240 static dw_die_ref
*decl_die_table
;
3242 /* Number of elements currently allocated for the decl_die_table. */
3243 static unsigned decl_die_table_allocated
;
3245 /* Number of elements in decl_die_table currently in use. */
3246 static unsigned decl_die_table_in_use
;
3248 /* Size (in elements) of increments by which we may expand the
3250 #define DECL_DIE_TABLE_INCREMENT 256
3252 /* A pointer to the base of a table of references to declaration
3253 scopes. This table is a display which tracks the nesting
3254 of declaration scopes at the current scope and containing
3255 scopes. This table is used to find the proper place to
3256 define type declaration DIE's. */
3257 static tree
*decl_scope_table
;
3259 /* Number of elements currently allocated for the decl_scope_table. */
3260 static int decl_scope_table_allocated
;
3262 /* Current level of nesting of declaration scopes. */
3263 static int decl_scope_depth
;
3265 /* Size (in elements) of increments by which we may expand the
3266 decl_scope_table. */
3267 #define DECL_SCOPE_TABLE_INCREMENT 64
3269 /* A pointer to the base of a list of references to DIE's that
3270 are uniquely identified by their tag, presence/absence of
3271 children DIE's, and list of attribute/value pairs. */
3272 static dw_die_ref
*abbrev_die_table
;
3274 /* Number of elements currently allocated for abbrev_die_table. */
3275 static unsigned abbrev_die_table_allocated
;
3277 /* Number of elements in type_die_table currently in use. */
3278 static unsigned abbrev_die_table_in_use
;
3280 /* Size (in elements) of increments by which we may expand the
3281 abbrev_die_table. */
3282 #define ABBREV_DIE_TABLE_INCREMENT 256
3284 /* A pointer to the base of a table that contains line information
3285 for each source code line in .text in the compilation unit. */
3286 static dw_line_info_ref line_info_table
;
3288 /* Number of elements currently allocated for line_info_table. */
3289 static unsigned line_info_table_allocated
;
3291 /* Number of elements in separate_line_info_table currently in use. */
3292 static unsigned separate_line_info_table_in_use
;
3294 /* A pointer to the base of a table that contains line information
3295 for each source code line outside of .text in the compilation unit. */
3296 static dw_separate_line_info_ref separate_line_info_table
;
3298 /* Number of elements currently allocated for separate_line_info_table. */
3299 static unsigned separate_line_info_table_allocated
;
3301 /* Number of elements in line_info_table currently in use. */
3302 static unsigned line_info_table_in_use
;
3304 /* Size (in elements) of increments by which we may expand the
3306 #define LINE_INFO_TABLE_INCREMENT 1024
3308 /* A pointer to the base of a table that contains a list of publicly
3309 accessible names. */
3310 static pubname_ref pubname_table
;
3312 /* Number of elements currently allocated for pubname_table. */
3313 static unsigned pubname_table_allocated
;
3315 /* Number of elements in pubname_table currently in use. */
3316 static unsigned pubname_table_in_use
;
3318 /* Size (in elements) of increments by which we may expand the
3320 #define PUBNAME_TABLE_INCREMENT 64
3322 /* A pointer to the base of a table that contains a list of publicly
3323 accessible names. */
3324 static arange_ref arange_table
;
3326 /* Number of elements currently allocated for arange_table. */
3327 static unsigned arange_table_allocated
;
3329 /* Number of elements in arange_table currently in use. */
3330 static unsigned arange_table_in_use
;
3332 /* Size (in elements) of increments by which we may expand the
3334 #define ARANGE_TABLE_INCREMENT 64
3336 /* A pointer to the base of a list of incomplete types which might be
3337 completed at some later time. */
3339 static tree
*incomplete_types_list
;
3341 /* Number of elements currently allocated for the incomplete_types_list. */
3342 static unsigned incomplete_types_allocated
;
3344 /* Number of elements of incomplete_types_list currently in use. */
3345 static unsigned incomplete_types
;
3347 /* Size (in elements) of increments by which we may expand the incomplete
3348 types list. Actually, a single hunk of space of this size should
3349 be enough for most typical programs. */
3350 #define INCOMPLETE_TYPES_INCREMENT 64
3352 /* Record whether the function being analyzed contains inlined functions. */
3353 static int current_function_has_inlines
;
3354 #if 0 && defined (MIPS_DEBUGGING_INFO)
3355 static int comp_unit_has_inlines
;
3358 /* Array of RTXes referenced by the debugging information, which therefore
3359 must be kept around forever. We do this rather than perform GC on
3360 the dwarf info because almost all of the dwarf info lives forever, and
3361 it's easier to support non-GC frontends this way. */
3362 static varray_type used_rtx_varray
;
3364 /* Forward declarations for functions defined in this file. */
3366 static int is_pseudo_reg
PARAMS ((rtx
));
3367 static tree type_main_variant
PARAMS ((tree
));
3368 static int is_tagged_type
PARAMS ((tree
));
3369 static const char *dwarf_tag_name
PARAMS ((unsigned));
3370 static const char *dwarf_attr_name
PARAMS ((unsigned));
3371 static const char *dwarf_form_name
PARAMS ((unsigned));
3373 static const char *dwarf_type_encoding_name
PARAMS ((unsigned));
3375 static tree decl_ultimate_origin
PARAMS ((tree
));
3376 static tree block_ultimate_origin
PARAMS ((tree
));
3377 static tree decl_class_context
PARAMS ((tree
));
3378 static void add_dwarf_attr
PARAMS ((dw_die_ref
, dw_attr_ref
));
3379 static void add_AT_flag
PARAMS ((dw_die_ref
,
3380 enum dwarf_attribute
,
3382 static void add_AT_int
PARAMS ((dw_die_ref
,
3383 enum dwarf_attribute
, long));
3384 static void add_AT_unsigned
PARAMS ((dw_die_ref
,
3385 enum dwarf_attribute
,
3387 static void add_AT_long_long
PARAMS ((dw_die_ref
,
3388 enum dwarf_attribute
,
3391 static void add_AT_float
PARAMS ((dw_die_ref
,
3392 enum dwarf_attribute
,
3394 static void add_AT_string
PARAMS ((dw_die_ref
,
3395 enum dwarf_attribute
,
3397 static void add_AT_die_ref
PARAMS ((dw_die_ref
,
3398 enum dwarf_attribute
,
3400 static void add_AT_fde_ref
PARAMS ((dw_die_ref
,
3401 enum dwarf_attribute
,
3403 static void add_AT_loc
PARAMS ((dw_die_ref
,
3404 enum dwarf_attribute
,
3406 static void add_AT_addr
PARAMS ((dw_die_ref
,
3407 enum dwarf_attribute
,
3409 static void add_AT_lbl_id
PARAMS ((dw_die_ref
,
3410 enum dwarf_attribute
,
3412 static void add_AT_lbl_offset
PARAMS ((dw_die_ref
,
3413 enum dwarf_attribute
,
3415 static dw_attr_ref get_AT
PARAMS ((dw_die_ref
,
3416 enum dwarf_attribute
));
3417 static const char *get_AT_low_pc
PARAMS ((dw_die_ref
));
3418 static const char *get_AT_hi_pc
PARAMS ((dw_die_ref
));
3419 static const char *get_AT_string
PARAMS ((dw_die_ref
,
3420 enum dwarf_attribute
));
3421 static int get_AT_flag
PARAMS ((dw_die_ref
,
3422 enum dwarf_attribute
));
3423 static unsigned get_AT_unsigned
PARAMS ((dw_die_ref
,
3424 enum dwarf_attribute
));
3425 static inline dw_die_ref get_AT_ref
PARAMS ((dw_die_ref
,
3426 enum dwarf_attribute
));
3427 static int is_c_family
PARAMS ((void));
3428 static int is_java
PARAMS ((void));
3429 static int is_fortran
PARAMS ((void));
3430 static void remove_AT
PARAMS ((dw_die_ref
,
3431 enum dwarf_attribute
));
3432 static void remove_children
PARAMS ((dw_die_ref
));
3433 static void add_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3434 static dw_die_ref new_die
PARAMS ((enum dwarf_tag
, dw_die_ref
));
3435 static dw_die_ref lookup_type_die
PARAMS ((tree
));
3436 static void equate_type_number_to_die
PARAMS ((tree
, dw_die_ref
));
3437 static dw_die_ref lookup_decl_die
PARAMS ((tree
));
3438 static void equate_decl_number_to_die
PARAMS ((tree
, dw_die_ref
));
3439 static void print_spaces
PARAMS ((FILE *));
3440 static void print_die
PARAMS ((dw_die_ref
, FILE *));
3441 static void print_dwarf_line_table
PARAMS ((FILE *));
3442 static void reverse_die_lists
PARAMS ((dw_die_ref
));
3443 static void reverse_all_dies
PARAMS ((dw_die_ref
));
3444 static dw_die_ref push_new_compile_unit
PARAMS ((dw_die_ref
, dw_die_ref
));
3445 static dw_die_ref pop_compile_unit
PARAMS ((dw_die_ref
));
3446 static void loc_checksum
PARAMS ((dw_loc_descr_ref
, struct md5_ctx
*));
3447 static void attr_checksum
PARAMS ((dw_attr_ref
, struct md5_ctx
*));
3448 static void die_checksum
PARAMS ((dw_die_ref
, struct md5_ctx
*));
3449 static void compute_section_prefix
PARAMS ((dw_die_ref
));
3450 static int is_type_die
PARAMS ((dw_die_ref
));
3451 static int is_comdat_die
PARAMS ((dw_die_ref
));
3452 static int is_symbol_die
PARAMS ((dw_die_ref
));
3453 static char *gen_internal_sym
PARAMS ((void));
3454 static void assign_symbol_names
PARAMS ((dw_die_ref
));
3455 static void break_out_includes
PARAMS ((dw_die_ref
));
3456 static void add_sibling_attributes
PARAMS ((dw_die_ref
));
3457 static void build_abbrev_table
PARAMS ((dw_die_ref
));
3458 static unsigned long size_of_string
PARAMS ((const char *));
3459 static int constant_size
PARAMS ((long unsigned));
3460 static unsigned long size_of_die
PARAMS ((dw_die_ref
));
3461 static void calc_die_sizes
PARAMS ((dw_die_ref
));
3462 static void mark_dies
PARAMS ((dw_die_ref
));
3463 static void unmark_dies
PARAMS ((dw_die_ref
));
3464 static unsigned long size_of_line_prolog
PARAMS ((void));
3465 static unsigned long size_of_pubnames
PARAMS ((void));
3466 static unsigned long size_of_aranges
PARAMS ((void));
3467 static enum dwarf_form value_format
PARAMS ((dw_attr_ref
));
3468 static void output_value_format
PARAMS ((dw_attr_ref
));
3469 static void output_abbrev_section
PARAMS ((void));
3470 static void output_die_symbol
PARAMS ((dw_die_ref
));
3471 static void output_symbolic_ref
PARAMS ((dw_die_ref
));
3472 static void output_die
PARAMS ((dw_die_ref
));
3473 static void output_compilation_unit_header
PARAMS ((void));
3474 static void output_comp_unit
PARAMS ((dw_die_ref
));
3475 static const char *dwarf2_name
PARAMS ((tree
, int));
3476 static void add_pubname
PARAMS ((tree
, dw_die_ref
));
3477 static void output_pubnames
PARAMS ((void));
3478 static void add_arange
PARAMS ((tree
, dw_die_ref
));
3479 static void output_aranges
PARAMS ((void));
3480 static void output_line_info
PARAMS ((void));
3481 static void output_file_names
PARAMS ((void));
3482 static dw_die_ref base_type_die
PARAMS ((tree
));
3483 static tree root_type
PARAMS ((tree
));
3484 static int is_base_type
PARAMS ((tree
));
3485 static dw_die_ref modified_type_die
PARAMS ((tree
, int, int, dw_die_ref
));
3486 static int type_is_enum
PARAMS ((tree
));
3487 static unsigned int reg_number
PARAMS ((rtx
));
3488 static dw_loc_descr_ref reg_loc_descriptor
PARAMS ((rtx
));
3489 static dw_loc_descr_ref int_loc_descriptor
PARAMS ((HOST_WIDE_INT
));
3490 static dw_loc_descr_ref based_loc_descr
PARAMS ((unsigned, long));
3491 static int is_based_loc
PARAMS ((rtx
));
3492 static dw_loc_descr_ref mem_loc_descriptor
PARAMS ((rtx
, enum machine_mode mode
));
3493 static dw_loc_descr_ref concat_loc_descriptor
PARAMS ((rtx
, rtx
));
3494 static dw_loc_descr_ref loc_descriptor
PARAMS ((rtx
));
3495 static dw_loc_descr_ref loc_descriptor_from_tree
PARAMS ((tree
, int));
3496 static HOST_WIDE_INT ceiling
PARAMS ((HOST_WIDE_INT
, unsigned int));
3497 static tree field_type
PARAMS ((tree
));
3498 static unsigned int simple_type_align_in_bits
PARAMS ((tree
));
3499 static unsigned int simple_decl_align_in_bits
PARAMS ((tree
));
3500 static unsigned HOST_WIDE_INT simple_type_size_in_bits
PARAMS ((tree
));
3501 static HOST_WIDE_INT field_byte_offset
PARAMS ((tree
));
3502 static void add_AT_location_description
PARAMS ((dw_die_ref
,
3503 enum dwarf_attribute
, rtx
));
3504 static void add_data_member_location_attribute
PARAMS ((dw_die_ref
, tree
));
3505 static void add_const_value_attribute
PARAMS ((dw_die_ref
, rtx
));
3506 static rtx rtl_for_decl_location
PARAMS ((tree
));
3507 static void add_location_or_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3508 static void tree_add_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3509 static void add_name_attribute
PARAMS ((dw_die_ref
, const char *));
3510 static void add_bound_info
PARAMS ((dw_die_ref
,
3511 enum dwarf_attribute
, tree
));
3512 static void add_subscript_info
PARAMS ((dw_die_ref
, tree
));
3513 static void add_byte_size_attribute
PARAMS ((dw_die_ref
, tree
));
3514 static void add_bit_offset_attribute
PARAMS ((dw_die_ref
, tree
));
3515 static void add_bit_size_attribute
PARAMS ((dw_die_ref
, tree
));
3516 static void add_prototyped_attribute
PARAMS ((dw_die_ref
, tree
));
3517 static void add_abstract_origin_attribute
PARAMS ((dw_die_ref
, tree
));
3518 static void add_pure_or_virtual_attribute
PARAMS ((dw_die_ref
, tree
));
3519 static void add_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3520 static void add_name_and_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3521 static void push_decl_scope
PARAMS ((tree
));
3522 static dw_die_ref scope_die_for
PARAMS ((tree
, dw_die_ref
));
3523 static void pop_decl_scope
PARAMS ((void));
3524 static void add_type_attribute
PARAMS ((dw_die_ref
, tree
, int, int,
3526 static const char *type_tag
PARAMS ((tree
));
3527 static tree member_declared_type
PARAMS ((tree
));
3529 static const char *decl_start_label
PARAMS ((tree
));
3531 static void gen_array_type_die
PARAMS ((tree
, dw_die_ref
));
3532 static void gen_set_type_die
PARAMS ((tree
, dw_die_ref
));
3534 static void gen_entry_point_die
PARAMS ((tree
, dw_die_ref
));
3536 static void gen_inlined_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3537 static void gen_inlined_structure_type_die
PARAMS ((tree
, dw_die_ref
));
3538 static void gen_inlined_union_type_die
PARAMS ((tree
, dw_die_ref
));
3539 static void gen_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3540 static dw_die_ref gen_formal_parameter_die
PARAMS ((tree
, dw_die_ref
));
3541 static void gen_unspecified_parameters_die
PARAMS ((tree
, dw_die_ref
));
3542 static void gen_formal_types_die
PARAMS ((tree
, dw_die_ref
));
3543 static void gen_subprogram_die
PARAMS ((tree
, dw_die_ref
));
3544 static void gen_variable_die
PARAMS ((tree
, dw_die_ref
));
3545 static void gen_label_die
PARAMS ((tree
, dw_die_ref
));
3546 static void gen_lexical_block_die
PARAMS ((tree
, dw_die_ref
, int));
3547 static void gen_inlined_subroutine_die
PARAMS ((tree
, dw_die_ref
, int));
3548 static void gen_field_die
PARAMS ((tree
, dw_die_ref
));
3549 static void gen_ptr_to_mbr_type_die
PARAMS ((tree
, dw_die_ref
));
3550 static dw_die_ref gen_compile_unit_die
PARAMS ((const char *));
3551 static void gen_string_type_die
PARAMS ((tree
, dw_die_ref
));
3552 static void gen_inheritance_die
PARAMS ((tree
, dw_die_ref
));
3553 static void gen_member_die
PARAMS ((tree
, dw_die_ref
));
3554 static void gen_struct_or_union_type_die
PARAMS ((tree
, dw_die_ref
));
3555 static void gen_subroutine_type_die
PARAMS ((tree
, dw_die_ref
));
3556 static void gen_typedef_die
PARAMS ((tree
, dw_die_ref
));
3557 static void gen_type_die
PARAMS ((tree
, dw_die_ref
));
3558 static void gen_tagged_type_instantiation_die
PARAMS ((tree
, dw_die_ref
));
3559 static void gen_block_die
PARAMS ((tree
, dw_die_ref
, int));
3560 static void decls_for_scope
PARAMS ((tree
, dw_die_ref
, int));
3561 static int is_redundant_typedef
PARAMS ((tree
));
3562 static void gen_decl_die
PARAMS ((tree
, dw_die_ref
));
3563 static unsigned lookup_filename
PARAMS ((struct file_table
*,
3565 static void init_file_table
PARAMS ((struct file_table
*));
3566 static void add_incomplete_type
PARAMS ((tree
));
3567 static void retry_incomplete_types
PARAMS ((void));
3568 static void gen_type_die_for_member
PARAMS ((tree
, tree
, dw_die_ref
));
3569 static void gen_abstract_function
PARAMS ((tree
));
3570 static rtx save_rtx
PARAMS ((rtx
));
3571 static void splice_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3572 static int file_info_cmp
PARAMS ((const void *, const void *));
3574 /* Section names used to hold DWARF debugging information. */
3575 #ifndef DEBUG_INFO_SECTION
3576 #define DEBUG_INFO_SECTION ".debug_info"
3578 #ifndef ABBREV_SECTION
3579 #define ABBREV_SECTION ".debug_abbrev"
3581 #ifndef ARANGES_SECTION
3582 #define ARANGES_SECTION ".debug_aranges"
3584 #ifndef DW_MACINFO_SECTION
3585 #define DW_MACINFO_SECTION ".debug_macinfo"
3587 #ifndef DEBUG_LINE_SECTION
3588 #define DEBUG_LINE_SECTION ".debug_line"
3591 #define LOC_SECTION ".debug_loc"
3593 #ifndef PUBNAMES_SECTION
3594 #define PUBNAMES_SECTION ".debug_pubnames"
3597 #define STR_SECTION ".debug_str"
3600 /* Standard ELF section names for compiled code and data. */
3601 #ifndef TEXT_SECTION
3602 #define TEXT_SECTION ".text"
3604 #ifndef DATA_SECTION
3605 #define DATA_SECTION ".data"
3608 #define BSS_SECTION ".bss"
3611 /* Labels we insert at beginning sections we can reference instead of
3612 the section names themselves. */
3614 #ifndef TEXT_SECTION_LABEL
3615 #define TEXT_SECTION_LABEL "Ltext"
3617 #ifndef DEBUG_LINE_SECTION_LABEL
3618 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3620 #ifndef DEBUG_INFO_SECTION_LABEL
3621 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3623 #ifndef ABBREV_SECTION_LABEL
3624 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3627 /* Definitions of defaults for formats and names of various special
3628 (artificial) labels which may be generated within this file (when the -g
3629 options is used and DWARF_DEBUGGING_INFO is in effect.
3630 If necessary, these may be overridden from within the tm.h file, but
3631 typically, overriding these defaults is unnecessary. */
3633 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3634 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3635 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3636 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3637 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3639 #ifndef TEXT_END_LABEL
3640 #define TEXT_END_LABEL "Letext"
3642 #ifndef DATA_END_LABEL
3643 #define DATA_END_LABEL "Ledata"
3645 #ifndef BSS_END_LABEL
3646 #define BSS_END_LABEL "Lebss"
3648 #ifndef BLOCK_BEGIN_LABEL
3649 #define BLOCK_BEGIN_LABEL "LBB"
3651 #ifndef BLOCK_END_LABEL
3652 #define BLOCK_END_LABEL "LBE"
3654 #ifndef BODY_BEGIN_LABEL
3655 #define BODY_BEGIN_LABEL "Lbb"
3657 #ifndef BODY_END_LABEL
3658 #define BODY_END_LABEL "Lbe"
3660 #ifndef LINE_CODE_LABEL
3661 #define LINE_CODE_LABEL "LM"
3663 #ifndef SEPARATE_LINE_CODE_LABEL
3664 #define SEPARATE_LINE_CODE_LABEL "LSM"
3667 /* We allow a language front-end to designate a function that is to be
3668 called to "demangle" any name before it it put into a DIE. */
3670 static const char *(*demangle_name_func
) PARAMS ((const char *));
3673 dwarf2out_set_demangle_name_func (func
)
3674 const char *(*func
) PARAMS ((const char *));
3676 demangle_name_func
= func
;
3679 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3680 that means adding it to used_rtx_varray. If not, that means making
3681 a copy on the permanent_obstack. */
3687 VARRAY_PUSH_RTX (used_rtx_varray
, orig
);
3692 /* Test if rtl node points to a pseudo register. */
3698 return ((GET_CODE (rtl
) == REG
&& REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3699 || (GET_CODE (rtl
) == SUBREG
3700 && REGNO (XEXP (rtl
, 0)) >= FIRST_PSEUDO_REGISTER
));
3703 /* Return a reference to a type, with its const and volatile qualifiers
3707 type_main_variant (type
)
3710 type
= TYPE_MAIN_VARIANT (type
);
3712 /* There really should be only one main variant among any group of variants
3713 of a given type (and all of the MAIN_VARIANT values for all members of
3714 the group should point to that one type) but sometimes the C front-end
3715 messes this up for array types, so we work around that bug here. */
3717 if (TREE_CODE (type
) == ARRAY_TYPE
)
3718 while (type
!= TYPE_MAIN_VARIANT (type
))
3719 type
= TYPE_MAIN_VARIANT (type
);
3724 /* Return non-zero if the given type node represents a tagged type. */
3727 is_tagged_type (type
)
3730 register enum tree_code code
= TREE_CODE (type
);
3732 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3733 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3736 /* Convert a DIE tag into its string name. */
3739 dwarf_tag_name (tag
)
3740 register unsigned tag
;
3744 case DW_TAG_padding
:
3745 return "DW_TAG_padding";
3746 case DW_TAG_array_type
:
3747 return "DW_TAG_array_type";
3748 case DW_TAG_class_type
:
3749 return "DW_TAG_class_type";
3750 case DW_TAG_entry_point
:
3751 return "DW_TAG_entry_point";
3752 case DW_TAG_enumeration_type
:
3753 return "DW_TAG_enumeration_type";
3754 case DW_TAG_formal_parameter
:
3755 return "DW_TAG_formal_parameter";
3756 case DW_TAG_imported_declaration
:
3757 return "DW_TAG_imported_declaration";
3759 return "DW_TAG_label";
3760 case DW_TAG_lexical_block
:
3761 return "DW_TAG_lexical_block";
3763 return "DW_TAG_member";
3764 case DW_TAG_pointer_type
:
3765 return "DW_TAG_pointer_type";
3766 case DW_TAG_reference_type
:
3767 return "DW_TAG_reference_type";
3768 case DW_TAG_compile_unit
:
3769 return "DW_TAG_compile_unit";
3770 case DW_TAG_string_type
:
3771 return "DW_TAG_string_type";
3772 case DW_TAG_structure_type
:
3773 return "DW_TAG_structure_type";
3774 case DW_TAG_subroutine_type
:
3775 return "DW_TAG_subroutine_type";
3776 case DW_TAG_typedef
:
3777 return "DW_TAG_typedef";
3778 case DW_TAG_union_type
:
3779 return "DW_TAG_union_type";
3780 case DW_TAG_unspecified_parameters
:
3781 return "DW_TAG_unspecified_parameters";
3782 case DW_TAG_variant
:
3783 return "DW_TAG_variant";
3784 case DW_TAG_common_block
:
3785 return "DW_TAG_common_block";
3786 case DW_TAG_common_inclusion
:
3787 return "DW_TAG_common_inclusion";
3788 case DW_TAG_inheritance
:
3789 return "DW_TAG_inheritance";
3790 case DW_TAG_inlined_subroutine
:
3791 return "DW_TAG_inlined_subroutine";
3793 return "DW_TAG_module";
3794 case DW_TAG_ptr_to_member_type
:
3795 return "DW_TAG_ptr_to_member_type";
3796 case DW_TAG_set_type
:
3797 return "DW_TAG_set_type";
3798 case DW_TAG_subrange_type
:
3799 return "DW_TAG_subrange_type";
3800 case DW_TAG_with_stmt
:
3801 return "DW_TAG_with_stmt";
3802 case DW_TAG_access_declaration
:
3803 return "DW_TAG_access_declaration";
3804 case DW_TAG_base_type
:
3805 return "DW_TAG_base_type";
3806 case DW_TAG_catch_block
:
3807 return "DW_TAG_catch_block";
3808 case DW_TAG_const_type
:
3809 return "DW_TAG_const_type";
3810 case DW_TAG_constant
:
3811 return "DW_TAG_constant";
3812 case DW_TAG_enumerator
:
3813 return "DW_TAG_enumerator";
3814 case DW_TAG_file_type
:
3815 return "DW_TAG_file_type";
3817 return "DW_TAG_friend";
3818 case DW_TAG_namelist
:
3819 return "DW_TAG_namelist";
3820 case DW_TAG_namelist_item
:
3821 return "DW_TAG_namelist_item";
3822 case DW_TAG_packed_type
:
3823 return "DW_TAG_packed_type";
3824 case DW_TAG_subprogram
:
3825 return "DW_TAG_subprogram";
3826 case DW_TAG_template_type_param
:
3827 return "DW_TAG_template_type_param";
3828 case DW_TAG_template_value_param
:
3829 return "DW_TAG_template_value_param";
3830 case DW_TAG_thrown_type
:
3831 return "DW_TAG_thrown_type";
3832 case DW_TAG_try_block
:
3833 return "DW_TAG_try_block";
3834 case DW_TAG_variant_part
:
3835 return "DW_TAG_variant_part";
3836 case DW_TAG_variable
:
3837 return "DW_TAG_variable";
3838 case DW_TAG_volatile_type
:
3839 return "DW_TAG_volatile_type";
3840 case DW_TAG_MIPS_loop
:
3841 return "DW_TAG_MIPS_loop";
3842 case DW_TAG_format_label
:
3843 return "DW_TAG_format_label";
3844 case DW_TAG_function_template
:
3845 return "DW_TAG_function_template";
3846 case DW_TAG_class_template
:
3847 return "DW_TAG_class_template";
3848 case DW_TAG_GNU_BINCL
:
3849 return "DW_TAG_GNU_BINCL";
3850 case DW_TAG_GNU_EINCL
:
3851 return "DW_TAG_GNU_EINCL";
3853 return "DW_TAG_<unknown>";
3857 /* Convert a DWARF attribute code into its string name. */
3860 dwarf_attr_name (attr
)
3861 register unsigned attr
;
3866 return "DW_AT_sibling";
3867 case DW_AT_location
:
3868 return "DW_AT_location";
3870 return "DW_AT_name";
3871 case DW_AT_ordering
:
3872 return "DW_AT_ordering";
3873 case DW_AT_subscr_data
:
3874 return "DW_AT_subscr_data";
3875 case DW_AT_byte_size
:
3876 return "DW_AT_byte_size";
3877 case DW_AT_bit_offset
:
3878 return "DW_AT_bit_offset";
3879 case DW_AT_bit_size
:
3880 return "DW_AT_bit_size";
3881 case DW_AT_element_list
:
3882 return "DW_AT_element_list";
3883 case DW_AT_stmt_list
:
3884 return "DW_AT_stmt_list";
3886 return "DW_AT_low_pc";
3888 return "DW_AT_high_pc";
3889 case DW_AT_language
:
3890 return "DW_AT_language";
3892 return "DW_AT_member";
3894 return "DW_AT_discr";
3895 case DW_AT_discr_value
:
3896 return "DW_AT_discr_value";
3897 case DW_AT_visibility
:
3898 return "DW_AT_visibility";
3900 return "DW_AT_import";
3901 case DW_AT_string_length
:
3902 return "DW_AT_string_length";
3903 case DW_AT_common_reference
:
3904 return "DW_AT_common_reference";
3905 case DW_AT_comp_dir
:
3906 return "DW_AT_comp_dir";
3907 case DW_AT_const_value
:
3908 return "DW_AT_const_value";
3909 case DW_AT_containing_type
:
3910 return "DW_AT_containing_type";
3911 case DW_AT_default_value
:
3912 return "DW_AT_default_value";
3914 return "DW_AT_inline";
3915 case DW_AT_is_optional
:
3916 return "DW_AT_is_optional";
3917 case DW_AT_lower_bound
:
3918 return "DW_AT_lower_bound";
3919 case DW_AT_producer
:
3920 return "DW_AT_producer";
3921 case DW_AT_prototyped
:
3922 return "DW_AT_prototyped";
3923 case DW_AT_return_addr
:
3924 return "DW_AT_return_addr";
3925 case DW_AT_start_scope
:
3926 return "DW_AT_start_scope";
3927 case DW_AT_stride_size
:
3928 return "DW_AT_stride_size";
3929 case DW_AT_upper_bound
:
3930 return "DW_AT_upper_bound";
3931 case DW_AT_abstract_origin
:
3932 return "DW_AT_abstract_origin";
3933 case DW_AT_accessibility
:
3934 return "DW_AT_accessibility";
3935 case DW_AT_address_class
:
3936 return "DW_AT_address_class";
3937 case DW_AT_artificial
:
3938 return "DW_AT_artificial";
3939 case DW_AT_base_types
:
3940 return "DW_AT_base_types";
3941 case DW_AT_calling_convention
:
3942 return "DW_AT_calling_convention";
3944 return "DW_AT_count";
3945 case DW_AT_data_member_location
:
3946 return "DW_AT_data_member_location";
3947 case DW_AT_decl_column
:
3948 return "DW_AT_decl_column";
3949 case DW_AT_decl_file
:
3950 return "DW_AT_decl_file";
3951 case DW_AT_decl_line
:
3952 return "DW_AT_decl_line";
3953 case DW_AT_declaration
:
3954 return "DW_AT_declaration";
3955 case DW_AT_discr_list
:
3956 return "DW_AT_discr_list";
3957 case DW_AT_encoding
:
3958 return "DW_AT_encoding";
3959 case DW_AT_external
:
3960 return "DW_AT_external";
3961 case DW_AT_frame_base
:
3962 return "DW_AT_frame_base";
3964 return "DW_AT_friend";
3965 case DW_AT_identifier_case
:
3966 return "DW_AT_identifier_case";
3967 case DW_AT_macro_info
:
3968 return "DW_AT_macro_info";
3969 case DW_AT_namelist_items
:
3970 return "DW_AT_namelist_items";
3971 case DW_AT_priority
:
3972 return "DW_AT_priority";
3974 return "DW_AT_segment";
3975 case DW_AT_specification
:
3976 return "DW_AT_specification";
3977 case DW_AT_static_link
:
3978 return "DW_AT_static_link";
3980 return "DW_AT_type";
3981 case DW_AT_use_location
:
3982 return "DW_AT_use_location";
3983 case DW_AT_variable_parameter
:
3984 return "DW_AT_variable_parameter";
3985 case DW_AT_virtuality
:
3986 return "DW_AT_virtuality";
3987 case DW_AT_vtable_elem_location
:
3988 return "DW_AT_vtable_elem_location";
3990 case DW_AT_MIPS_fde
:
3991 return "DW_AT_MIPS_fde";
3992 case DW_AT_MIPS_loop_begin
:
3993 return "DW_AT_MIPS_loop_begin";
3994 case DW_AT_MIPS_tail_loop_begin
:
3995 return "DW_AT_MIPS_tail_loop_begin";
3996 case DW_AT_MIPS_epilog_begin
:
3997 return "DW_AT_MIPS_epilog_begin";
3998 case DW_AT_MIPS_loop_unroll_factor
:
3999 return "DW_AT_MIPS_loop_unroll_factor";
4000 case DW_AT_MIPS_software_pipeline_depth
:
4001 return "DW_AT_MIPS_software_pipeline_depth";
4002 case DW_AT_MIPS_linkage_name
:
4003 return "DW_AT_MIPS_linkage_name";
4004 case DW_AT_MIPS_stride
:
4005 return "DW_AT_MIPS_stride";
4006 case DW_AT_MIPS_abstract_name
:
4007 return "DW_AT_MIPS_abstract_name";
4008 case DW_AT_MIPS_clone_origin
:
4009 return "DW_AT_MIPS_clone_origin";
4010 case DW_AT_MIPS_has_inlines
:
4011 return "DW_AT_MIPS_has_inlines";
4013 case DW_AT_sf_names
:
4014 return "DW_AT_sf_names";
4015 case DW_AT_src_info
:
4016 return "DW_AT_src_info";
4017 case DW_AT_mac_info
:
4018 return "DW_AT_mac_info";
4019 case DW_AT_src_coords
:
4020 return "DW_AT_src_coords";
4021 case DW_AT_body_begin
:
4022 return "DW_AT_body_begin";
4023 case DW_AT_body_end
:
4024 return "DW_AT_body_end";
4026 return "DW_AT_<unknown>";
4030 /* Convert a DWARF value form code into its string name. */
4033 dwarf_form_name (form
)
4034 register unsigned form
;
4039 return "DW_FORM_addr";
4040 case DW_FORM_block2
:
4041 return "DW_FORM_block2";
4042 case DW_FORM_block4
:
4043 return "DW_FORM_block4";
4045 return "DW_FORM_data2";
4047 return "DW_FORM_data4";
4049 return "DW_FORM_data8";
4050 case DW_FORM_string
:
4051 return "DW_FORM_string";
4053 return "DW_FORM_block";
4054 case DW_FORM_block1
:
4055 return "DW_FORM_block1";
4057 return "DW_FORM_data1";
4059 return "DW_FORM_flag";
4061 return "DW_FORM_sdata";
4063 return "DW_FORM_strp";
4065 return "DW_FORM_udata";
4066 case DW_FORM_ref_addr
:
4067 return "DW_FORM_ref_addr";
4069 return "DW_FORM_ref1";
4071 return "DW_FORM_ref2";
4073 return "DW_FORM_ref4";
4075 return "DW_FORM_ref8";
4076 case DW_FORM_ref_udata
:
4077 return "DW_FORM_ref_udata";
4078 case DW_FORM_indirect
:
4079 return "DW_FORM_indirect";
4081 return "DW_FORM_<unknown>";
4085 /* Convert a DWARF type code into its string name. */
4089 dwarf_type_encoding_name (enc
)
4090 register unsigned enc
;
4094 case DW_ATE_address
:
4095 return "DW_ATE_address";
4096 case DW_ATE_boolean
:
4097 return "DW_ATE_boolean";
4098 case DW_ATE_complex_float
:
4099 return "DW_ATE_complex_float";
4101 return "DW_ATE_float";
4103 return "DW_ATE_signed";
4104 case DW_ATE_signed_char
:
4105 return "DW_ATE_signed_char";
4106 case DW_ATE_unsigned
:
4107 return "DW_ATE_unsigned";
4108 case DW_ATE_unsigned_char
:
4109 return "DW_ATE_unsigned_char";
4111 return "DW_ATE_<unknown>";
4116 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4117 instance of an inlined instance of a decl which is local to an inline
4118 function, so we have to trace all of the way back through the origin chain
4119 to find out what sort of node actually served as the original seed for the
4123 decl_ultimate_origin (decl
)
4126 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4127 nodes in the function to point to themselves; ignore that if
4128 we're trying to output the abstract instance of this function. */
4129 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4132 #ifdef ENABLE_CHECKING
4133 if (DECL_FROM_INLINE (DECL_ORIGIN (decl
)))
4134 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4135 most distant ancestor, this should never happen. */
4139 return DECL_ABSTRACT_ORIGIN (decl
);
4142 /* Determine the "ultimate origin" of a block. The block may be an inlined
4143 instance of an inlined instance of a block which is local to an inline
4144 function, so we have to trace all of the way back through the origin chain
4145 to find out what sort of node actually served as the original seed for the
4149 block_ultimate_origin (block
)
4150 register tree block
;
4152 register tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4154 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4155 nodes in the function to point to themselves; ignore that if
4156 we're trying to output the abstract instance of this function. */
4157 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4160 if (immediate_origin
== NULL_TREE
)
4164 register tree ret_val
;
4165 register tree lookahead
= immediate_origin
;
4169 ret_val
= lookahead
;
4170 lookahead
= (TREE_CODE (ret_val
) == BLOCK
)
4171 ? BLOCK_ABSTRACT_ORIGIN (ret_val
)
4174 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4180 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4181 of a virtual function may refer to a base class, so we check the 'this'
4185 decl_class_context (decl
)
4188 tree context
= NULL_TREE
;
4190 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4191 context
= DECL_CONTEXT (decl
);
4193 context
= TYPE_MAIN_VARIANT
4194 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4196 if (context
&& !TYPE_P (context
))
4197 context
= NULL_TREE
;
4202 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4203 addition order, and correct that in reverse_all_dies. */
4206 add_dwarf_attr (die
, attr
)
4207 register dw_die_ref die
;
4208 register dw_attr_ref attr
;
4210 if (die
!= NULL
&& attr
!= NULL
)
4212 attr
->dw_attr_next
= die
->die_attr
;
4213 die
->die_attr
= attr
;
4217 static inline dw_val_class AT_class
PARAMS ((dw_attr_ref
));
4218 static inline dw_val_class
4222 return a
->dw_attr_val
.val_class
;
4225 /* Add a flag value attribute to a DIE. */
4228 add_AT_flag (die
, attr_kind
, flag
)
4229 register dw_die_ref die
;
4230 register enum dwarf_attribute attr_kind
;
4231 register unsigned flag
;
4233 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4235 attr
->dw_attr_next
= NULL
;
4236 attr
->dw_attr
= attr_kind
;
4237 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
4238 attr
->dw_attr_val
.v
.val_flag
= flag
;
4239 add_dwarf_attr (die
, attr
);
4242 static inline unsigned AT_flag
PARAMS ((dw_attr_ref
));
4243 static inline unsigned
4245 register dw_attr_ref a
;
4247 if (a
&& AT_class (a
) == dw_val_class_flag
)
4248 return a
->dw_attr_val
.v
.val_flag
;
4253 /* Add a signed integer attribute value to a DIE. */
4256 add_AT_int (die
, attr_kind
, int_val
)
4257 register dw_die_ref die
;
4258 register enum dwarf_attribute attr_kind
;
4259 register long int int_val
;
4261 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4263 attr
->dw_attr_next
= NULL
;
4264 attr
->dw_attr
= attr_kind
;
4265 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
4266 attr
->dw_attr_val
.v
.val_int
= int_val
;
4267 add_dwarf_attr (die
, attr
);
4270 static inline long int AT_int
PARAMS ((dw_attr_ref
));
4271 static inline long int
4273 register dw_attr_ref a
;
4275 if (a
&& AT_class (a
) == dw_val_class_const
)
4276 return a
->dw_attr_val
.v
.val_int
;
4281 /* Add an unsigned integer attribute value to a DIE. */
4284 add_AT_unsigned (die
, attr_kind
, unsigned_val
)
4285 register dw_die_ref die
;
4286 register enum dwarf_attribute attr_kind
;
4287 register unsigned long unsigned_val
;
4289 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4291 attr
->dw_attr_next
= NULL
;
4292 attr
->dw_attr
= attr_kind
;
4293 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4294 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4295 add_dwarf_attr (die
, attr
);
4298 static inline unsigned long AT_unsigned
PARAMS ((dw_attr_ref
));
4299 static inline unsigned long
4301 register dw_attr_ref a
;
4303 if (a
&& AT_class (a
) == dw_val_class_unsigned_const
)
4304 return a
->dw_attr_val
.v
.val_unsigned
;
4309 /* Add an unsigned double integer attribute value to a DIE. */
4312 add_AT_long_long (die
, attr_kind
, val_hi
, val_low
)
4313 register dw_die_ref die
;
4314 register enum dwarf_attribute attr_kind
;
4315 register unsigned long val_hi
;
4316 register unsigned long val_low
;
4318 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4320 attr
->dw_attr_next
= NULL
;
4321 attr
->dw_attr
= attr_kind
;
4322 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
4323 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4324 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
4325 add_dwarf_attr (die
, attr
);
4328 /* Add a floating point attribute value to a DIE and return it. */
4331 add_AT_float (die
, attr_kind
, length
, array
)
4332 register dw_die_ref die
;
4333 register enum dwarf_attribute attr_kind
;
4334 register unsigned length
;
4335 register long *array
;
4337 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4339 attr
->dw_attr_next
= NULL
;
4340 attr
->dw_attr
= attr_kind
;
4341 attr
->dw_attr_val
.val_class
= dw_val_class_float
;
4342 attr
->dw_attr_val
.v
.val_float
.length
= length
;
4343 attr
->dw_attr_val
.v
.val_float
.array
= array
;
4344 add_dwarf_attr (die
, attr
);
4347 /* Add a string attribute value to a DIE. */
4350 add_AT_string (die
, attr_kind
, str
)
4351 register dw_die_ref die
;
4352 register enum dwarf_attribute attr_kind
;
4353 register const char *str
;
4355 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4357 attr
->dw_attr_next
= NULL
;
4358 attr
->dw_attr
= attr_kind
;
4359 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
4360 attr
->dw_attr_val
.v
.val_str
= xstrdup (str
);
4361 add_dwarf_attr (die
, attr
);
4364 static inline const char *AT_string
PARAMS ((dw_attr_ref
));
4365 static inline const char *
4367 register dw_attr_ref a
;
4369 if (a
&& AT_class (a
) == dw_val_class_str
)
4370 return a
->dw_attr_val
.v
.val_str
;
4375 /* Add a DIE reference attribute value to a DIE. */
4378 add_AT_die_ref (die
, attr_kind
, targ_die
)
4379 register dw_die_ref die
;
4380 register enum dwarf_attribute attr_kind
;
4381 register dw_die_ref targ_die
;
4383 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4385 attr
->dw_attr_next
= NULL
;
4386 attr
->dw_attr
= attr_kind
;
4387 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
4388 attr
->dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4389 attr
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4390 add_dwarf_attr (die
, attr
);
4393 static inline dw_die_ref AT_ref
PARAMS ((dw_attr_ref
));
4394 static inline dw_die_ref
4396 register dw_attr_ref a
;
4398 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4399 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4404 static inline int AT_ref_external
PARAMS ((dw_attr_ref
));
4407 register dw_attr_ref a
;
4409 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4410 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4415 static inline void set_AT_ref_external
PARAMS ((dw_attr_ref
, int));
4417 set_AT_ref_external (a
, i
)
4418 register dw_attr_ref a
;
4421 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4422 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4427 /* Add an FDE reference attribute value to a DIE. */
4430 add_AT_fde_ref (die
, attr_kind
, targ_fde
)
4431 register dw_die_ref die
;
4432 register enum dwarf_attribute attr_kind
;
4433 register unsigned targ_fde
;
4435 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4437 attr
->dw_attr_next
= NULL
;
4438 attr
->dw_attr
= attr_kind
;
4439 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4440 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
4441 add_dwarf_attr (die
, attr
);
4444 /* Add a location description attribute value to a DIE. */
4447 add_AT_loc (die
, attr_kind
, loc
)
4448 register dw_die_ref die
;
4449 register enum dwarf_attribute attr_kind
;
4450 register dw_loc_descr_ref loc
;
4452 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4454 attr
->dw_attr_next
= NULL
;
4455 attr
->dw_attr
= attr_kind
;
4456 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
4457 attr
->dw_attr_val
.v
.val_loc
= loc
;
4458 add_dwarf_attr (die
, attr
);
4461 static inline dw_loc_descr_ref AT_loc
PARAMS ((dw_attr_ref
));
4462 static inline dw_loc_descr_ref
4464 register dw_attr_ref a
;
4466 if (a
&& AT_class (a
) == dw_val_class_loc
)
4467 return a
->dw_attr_val
.v
.val_loc
;
4472 /* Add an address constant attribute value to a DIE. */
4475 add_AT_addr (die
, attr_kind
, addr
)
4476 register dw_die_ref die
;
4477 register enum dwarf_attribute attr_kind
;
4480 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4482 attr
->dw_attr_next
= NULL
;
4483 attr
->dw_attr
= attr_kind
;
4484 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
4485 attr
->dw_attr_val
.v
.val_addr
= addr
;
4486 add_dwarf_attr (die
, attr
);
4489 static inline rtx AT_addr
PARAMS ((dw_attr_ref
));
4492 register dw_attr_ref a
;
4494 if (a
&& AT_class (a
) == dw_val_class_addr
)
4495 return a
->dw_attr_val
.v
.val_addr
;
4500 /* Add a label identifier attribute value to a DIE. */
4503 add_AT_lbl_id (die
, attr_kind
, lbl_id
)
4504 register dw_die_ref die
;
4505 register enum dwarf_attribute attr_kind
;
4506 register const char *lbl_id
;
4508 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4510 attr
->dw_attr_next
= NULL
;
4511 attr
->dw_attr
= attr_kind
;
4512 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4513 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4514 add_dwarf_attr (die
, attr
);
4517 /* Add a section offset attribute value to a DIE. */
4520 add_AT_lbl_offset (die
, attr_kind
, label
)
4521 register dw_die_ref die
;
4522 register enum dwarf_attribute attr_kind
;
4523 register const char *label
;
4525 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4527 attr
->dw_attr_next
= NULL
;
4528 attr
->dw_attr
= attr_kind
;
4529 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_offset
;
4530 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4531 add_dwarf_attr (die
, attr
);
4534 static inline const char *AT_lbl
PARAMS ((dw_attr_ref
));
4535 static inline const char *
4537 register dw_attr_ref a
;
4539 if (a
&& (AT_class (a
) == dw_val_class_lbl_id
4540 || AT_class (a
) == dw_val_class_lbl_offset
))
4541 return a
->dw_attr_val
.v
.val_lbl_id
;
4546 /* Get the attribute of type attr_kind. */
4548 static inline dw_attr_ref
4549 get_AT (die
, attr_kind
)
4550 register dw_die_ref die
;
4551 register enum dwarf_attribute attr_kind
;
4553 register dw_attr_ref a
;
4554 register dw_die_ref spec
= NULL
;
4558 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4560 if (a
->dw_attr
== attr_kind
)
4563 if (a
->dw_attr
== DW_AT_specification
4564 || a
->dw_attr
== DW_AT_abstract_origin
)
4569 return get_AT (spec
, attr_kind
);
4575 /* Return the "low pc" attribute value, typically associated with
4576 a subprogram DIE. Return null if the "low pc" attribute is
4577 either not prsent, or if it cannot be represented as an
4578 assembler label identifier. */
4580 static inline const char *
4582 register dw_die_ref die
;
4584 register dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4585 return a
? AT_lbl (a
) : NULL
;
4588 /* Return the "high pc" attribute value, typically associated with
4589 a subprogram DIE. Return null if the "high pc" attribute is
4590 either not prsent, or if it cannot be represented as an
4591 assembler label identifier. */
4593 static inline const char *
4595 register dw_die_ref die
;
4597 register dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4598 return a
? AT_lbl (a
) : NULL
;
4601 /* Return the value of the string attribute designated by ATTR_KIND, or
4602 NULL if it is not present. */
4604 static inline const char *
4605 get_AT_string (die
, attr_kind
)
4606 register dw_die_ref die
;
4607 register enum dwarf_attribute attr_kind
;
4609 register dw_attr_ref a
= get_AT (die
, attr_kind
);
4610 return a
? AT_string (a
) : NULL
;
4613 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4614 if it is not present. */
4617 get_AT_flag (die
, attr_kind
)
4618 register dw_die_ref die
;
4619 register enum dwarf_attribute attr_kind
;
4621 register dw_attr_ref a
= get_AT (die
, attr_kind
);
4622 return a
? AT_flag (a
) : 0;
4625 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4626 if it is not present. */
4628 static inline unsigned
4629 get_AT_unsigned (die
, attr_kind
)
4630 register dw_die_ref die
;
4631 register enum dwarf_attribute attr_kind
;
4633 register dw_attr_ref a
= get_AT (die
, attr_kind
);
4634 return a
? AT_unsigned (a
) : 0;
4637 static inline dw_die_ref
4638 get_AT_ref (die
, attr_kind
)
4640 register enum dwarf_attribute attr_kind
;
4642 register dw_attr_ref a
= get_AT (die
, attr_kind
);
4643 return a
? AT_ref (a
) : NULL
;
4649 register unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4651 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
4652 || lang
== DW_LANG_C_plus_plus
);
4658 register unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4660 return (lang
== DW_LANG_Fortran77
|| lang
== DW_LANG_Fortran90
);
4666 register unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4668 return (lang
== DW_LANG_Java
);
4671 /* Free up the memory used by A. */
4673 static inline void free_AT
PARAMS ((dw_attr_ref
));
4678 switch (AT_class (a
))
4680 case dw_val_class_str
:
4681 case dw_val_class_lbl_id
:
4682 case dw_val_class_lbl_offset
:
4683 free (a
->dw_attr_val
.v
.val_str
);
4686 case dw_val_class_float
:
4687 free (a
->dw_attr_val
.v
.val_float
.array
);
4697 /* Remove the specified attribute if present. */
4700 remove_AT (die
, attr_kind
)
4701 register dw_die_ref die
;
4702 register enum dwarf_attribute attr_kind
;
4704 register dw_attr_ref
*p
;
4705 register dw_attr_ref removed
= NULL
;
4709 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
4710 if ((*p
)->dw_attr
== attr_kind
)
4713 *p
= (*p
)->dw_attr_next
;
4722 /* Free up the memory used by DIE. */
4724 static inline void free_die
PARAMS ((dw_die_ref
));
4729 remove_children (die
);
4733 /* Discard the children of this DIE. */
4736 remove_children (die
)
4737 register dw_die_ref die
;
4739 register dw_die_ref child_die
= die
->die_child
;
4741 die
->die_child
= NULL
;
4743 while (child_die
!= NULL
)
4745 register dw_die_ref tmp_die
= child_die
;
4746 register dw_attr_ref a
;
4748 child_die
= child_die
->die_sib
;
4750 for (a
= tmp_die
->die_attr
; a
!= NULL
;)
4752 register dw_attr_ref tmp_a
= a
;
4754 a
= a
->dw_attr_next
;
4762 /* Add a child DIE below its parent. We build the lists up in reverse
4763 addition order, and correct that in reverse_all_dies. */
4766 add_child_die (die
, child_die
)
4767 register dw_die_ref die
;
4768 register dw_die_ref child_die
;
4770 if (die
!= NULL
&& child_die
!= NULL
)
4772 if (die
== child_die
)
4774 child_die
->die_parent
= die
;
4775 child_die
->die_sib
= die
->die_child
;
4776 die
->die_child
= child_die
;
4780 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4781 is the specification, to the front of PARENT's list of children. */
4784 splice_child_die (parent
, child
)
4785 dw_die_ref parent
, child
;
4789 /* We want the declaration DIE from inside the class, not the
4790 specification DIE at toplevel. */
4791 if (child
->die_parent
!= parent
)
4793 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4798 if (child
->die_parent
!= parent
4799 && child
->die_parent
!= get_AT_ref (parent
, DW_AT_specification
))
4802 for (p
= &(child
->die_parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
4805 *p
= child
->die_sib
;
4809 child
->die_sib
= parent
->die_child
;
4810 parent
->die_child
= child
;
4813 /* Return a pointer to a newly created DIE node. */
4815 static inline dw_die_ref
4816 new_die (tag_value
, parent_die
)
4817 register enum dwarf_tag tag_value
;
4818 register dw_die_ref parent_die
;
4820 register dw_die_ref die
= (dw_die_ref
) xcalloc (1, sizeof (die_node
));
4822 die
->die_tag
= tag_value
;
4824 if (parent_die
!= NULL
)
4825 add_child_die (parent_die
, die
);
4828 limbo_die_node
*limbo_node
;
4830 limbo_node
= (limbo_die_node
*) xmalloc (sizeof (limbo_die_node
));
4831 limbo_node
->die
= die
;
4832 limbo_node
->next
= limbo_die_list
;
4833 limbo_die_list
= limbo_node
;
4839 /* Return the DIE associated with the given type specifier. */
4841 static inline dw_die_ref
4842 lookup_type_die (type
)
4845 if (TREE_CODE (type
) == VECTOR_TYPE
)
4846 type
= TYPE_DEBUG_REPRESENTATION_TYPE (type
);
4847 return (dw_die_ref
) TYPE_SYMTAB_POINTER (type
);
4850 /* Equate a DIE to a given type specifier. */
4853 equate_type_number_to_die (type
, type_die
)
4855 register dw_die_ref type_die
;
4857 TYPE_SYMTAB_POINTER (type
) = (char *) type_die
;
4860 /* Return the DIE associated with a given declaration. */
4862 static inline dw_die_ref
4863 lookup_decl_die (decl
)
4866 register unsigned decl_id
= DECL_UID (decl
);
4868 return (decl_id
< decl_die_table_in_use
4869 ? decl_die_table
[decl_id
] : NULL
);
4872 /* Equate a DIE to a particular declaration. */
4875 equate_decl_number_to_die (decl
, decl_die
)
4877 register dw_die_ref decl_die
;
4879 register unsigned decl_id
= DECL_UID (decl
);
4880 register unsigned num_allocated
;
4882 if (decl_id
>= decl_die_table_allocated
)
4885 = ((decl_id
+ 1 + DECL_DIE_TABLE_INCREMENT
- 1)
4886 / DECL_DIE_TABLE_INCREMENT
)
4887 * DECL_DIE_TABLE_INCREMENT
;
4890 = (dw_die_ref
*) xrealloc (decl_die_table
,
4891 sizeof (dw_die_ref
) * num_allocated
);
4893 memset ((char *) &decl_die_table
[decl_die_table_allocated
], 0,
4894 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
4895 decl_die_table_allocated
= num_allocated
;
4898 if (decl_id
>= decl_die_table_in_use
)
4899 decl_die_table_in_use
= (decl_id
+ 1);
4901 decl_die_table
[decl_id
] = decl_die
;
4904 /* Keep track of the number of spaces used to indent the
4905 output of the debugging routines that print the structure of
4906 the DIE internal representation. */
4907 static int print_indent
;
4909 /* Indent the line the number of spaces given by print_indent. */
4912 print_spaces (outfile
)
4915 fprintf (outfile
, "%*s", print_indent
, "");
4918 /* Print the information associated with a given DIE, and its children.
4919 This routine is a debugging aid only. */
4922 print_die (die
, outfile
)
4926 register dw_attr_ref a
;
4927 register dw_die_ref c
;
4929 print_spaces (outfile
);
4930 fprintf (outfile
, "DIE %4lu: %s\n",
4931 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
4932 print_spaces (outfile
);
4933 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
4934 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
4936 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4938 print_spaces (outfile
);
4939 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
4941 switch (AT_class (a
))
4943 case dw_val_class_addr
:
4944 fprintf (outfile
, "address");
4946 case dw_val_class_loc
:
4947 fprintf (outfile
, "location descriptor");
4949 case dw_val_class_const
:
4950 fprintf (outfile
, "%ld", AT_int (a
));
4952 case dw_val_class_unsigned_const
:
4953 fprintf (outfile
, "%lu", AT_unsigned (a
));
4955 case dw_val_class_long_long
:
4956 fprintf (outfile
, "constant (%lu,%lu)",
4957 a
->dw_attr_val
.v
.val_long_long
.hi
,
4958 a
->dw_attr_val
.v
.val_long_long
.low
);
4960 case dw_val_class_float
:
4961 fprintf (outfile
, "floating-point constant");
4963 case dw_val_class_flag
:
4964 fprintf (outfile
, "%u", AT_flag (a
));
4966 case dw_val_class_die_ref
:
4967 if (AT_ref (a
) != NULL
)
4969 if (AT_ref (a
)->die_symbol
)
4970 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
4972 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
4975 fprintf (outfile
, "die -> <null>");
4977 case dw_val_class_lbl_id
:
4978 case dw_val_class_lbl_offset
:
4979 fprintf (outfile
, "label: %s", AT_lbl (a
));
4981 case dw_val_class_str
:
4982 if (AT_string (a
) != NULL
)
4983 fprintf (outfile
, "\"%s\"", AT_string (a
));
4985 fprintf (outfile
, "<null>");
4991 fprintf (outfile
, "\n");
4994 if (die
->die_child
!= NULL
)
4997 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
4998 print_die (c
, outfile
);
5002 if (print_indent
== 0)
5003 fprintf (outfile
, "\n");
5006 /* Print the contents of the source code line number correspondence table.
5007 This routine is a debugging aid only. */
5010 print_dwarf_line_table (outfile
)
5013 register unsigned i
;
5014 register dw_line_info_ref line_info
;
5016 fprintf (outfile
, "\n\nDWARF source line information\n");
5017 for (i
= 1; i
< line_info_table_in_use
; ++i
)
5019 line_info
= &line_info_table
[i
];
5020 fprintf (outfile
, "%5d: ", i
);
5021 fprintf (outfile
, "%-20s", line_file_table
.table
[line_info
->dw_file_num
]);
5022 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
5023 fprintf (outfile
, "\n");
5026 fprintf (outfile
, "\n\n");
5029 /* Print the information collected for a given DIE. */
5032 debug_dwarf_die (die
)
5035 print_die (die
, stderr
);
5038 /* Print all DWARF information collected for the compilation unit.
5039 This routine is a debugging aid only. */
5045 print_die (comp_unit_die
, stderr
);
5046 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5047 print_dwarf_line_table (stderr
);
5050 /* We build up the lists of children and attributes by pushing new ones
5051 onto the beginning of the list. Reverse the lists for DIE so that
5052 they are in order of addition. */
5055 reverse_die_lists (die
)
5056 register dw_die_ref die
;
5058 register dw_die_ref c
, cp
, cn
;
5059 register dw_attr_ref a
, ap
, an
;
5061 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
5063 an
= a
->dw_attr_next
;
5064 a
->dw_attr_next
= ap
;
5069 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
5075 die
->die_child
= cp
;
5078 /* reverse_die_lists only reverses the single die you pass it. Since
5079 we used to reverse all dies in add_sibling_attributes, which runs
5080 through all the dies, it would reverse all the dies. Now, however,
5081 since we don't call reverse_die_lists in add_sibling_attributes, we
5082 need a routine to recursively reverse all the dies. This is that
5086 reverse_all_dies (die
)
5087 register dw_die_ref die
;
5089 register dw_die_ref c
;
5091 reverse_die_lists (die
);
5093 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5094 reverse_all_dies (c
);
5097 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5098 the CU for the enclosing include file, if any. BINCL_DIE is the
5099 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5103 push_new_compile_unit (old_unit
, bincl_die
)
5104 dw_die_ref old_unit
, bincl_die
;
5106 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5107 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5108 new_unit
->die_sib
= old_unit
;
5112 /* Close an include-file CU and reopen the enclosing one. */
5115 pop_compile_unit (old_unit
)
5116 dw_die_ref old_unit
;
5118 dw_die_ref new_unit
= old_unit
->die_sib
;
5119 old_unit
->die_sib
= NULL
;
5123 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5124 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5126 /* Calculate the checksum of a location expression. */
5129 loc_checksum (loc
, ctx
)
5130 dw_loc_descr_ref loc
;
5131 struct md5_ctx
*ctx
;
5133 PROCESS (loc
->dw_loc_opc
);
5134 PROCESS (loc
->dw_loc_oprnd1
);
5135 PROCESS (loc
->dw_loc_oprnd2
);
5138 /* Calculate the checksum of an attribute. */
5141 attr_checksum (at
, ctx
)
5143 struct md5_ctx
*ctx
;
5145 dw_loc_descr_ref loc
;
5148 PROCESS (at
->dw_attr
);
5150 /* We don't care about differences in file numbering. */
5151 if (at
->dw_attr
== DW_AT_decl_file
5152 /* Or that this was compiled with a different compiler snapshot; if
5153 the output is the same, that's what matters. */
5154 || at
->dw_attr
== DW_AT_producer
)
5157 switch (AT_class (at
))
5159 case dw_val_class_const
:
5160 PROCESS (at
->dw_attr_val
.v
.val_int
);
5162 case dw_val_class_unsigned_const
:
5163 PROCESS (at
->dw_attr_val
.v
.val_unsigned
);
5165 case dw_val_class_long_long
:
5166 PROCESS (at
->dw_attr_val
.v
.val_long_long
);
5168 case dw_val_class_float
:
5169 PROCESS (at
->dw_attr_val
.v
.val_float
);
5171 case dw_val_class_flag
:
5172 PROCESS (at
->dw_attr_val
.v
.val_flag
);
5175 case dw_val_class_str
:
5176 PROCESS_STRING (AT_string (at
));
5178 case dw_val_class_addr
:
5180 switch (GET_CODE (r
))
5183 PROCESS_STRING (XSTR (r
, 0));
5191 case dw_val_class_loc
:
5192 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5193 loc_checksum (loc
, ctx
);
5196 case dw_val_class_die_ref
:
5197 if (AT_ref (at
)->die_offset
)
5198 PROCESS (AT_ref (at
)->die_offset
);
5199 /* FIXME else use target die name or something. */
5201 case dw_val_class_fde_ref
:
5202 case dw_val_class_lbl_id
:
5203 case dw_val_class_lbl_offset
:
5210 /* Calculate the checksum of a DIE. */
5213 die_checksum (die
, ctx
)
5215 struct md5_ctx
*ctx
;
5220 PROCESS (die
->die_tag
);
5222 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
5223 attr_checksum (a
, ctx
);
5225 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5226 die_checksum (c
, ctx
);
5230 #undef PROCESS_STRING
5232 /* The prefix to attach to symbols on DIEs in the current comdat debug
5234 static char *comdat_symbol_id
;
5236 /* The index of the current symbol within the current comdat CU. */
5237 static unsigned int comdat_symbol_number
;
5239 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5240 children, and set comdat_symbol_id accordingly. */
5243 compute_section_prefix (unit_die
)
5244 dw_die_ref unit_die
;
5248 unsigned char checksum
[16];
5251 md5_init_ctx (&ctx
);
5252 die_checksum (unit_die
, &ctx
);
5253 md5_finish_ctx (&ctx
, checksum
);
5255 p
= file_name_nondirectory (get_AT_string (unit_die
, DW_AT_name
));
5256 name
= (char *) alloca (strlen (p
) + 64);
5257 sprintf (name
, "%s.", p
);
5259 clean_symbol_name (name
);
5261 p
= name
+ strlen (name
);
5262 for (i
= 0; i
< 4; ++i
)
5264 sprintf (p
, "%.2x", checksum
[i
]);
5268 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
5269 comdat_symbol_number
= 0;
5272 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5278 switch (die
->die_tag
)
5280 case DW_TAG_array_type
:
5281 case DW_TAG_class_type
:
5282 case DW_TAG_enumeration_type
:
5283 case DW_TAG_pointer_type
:
5284 case DW_TAG_reference_type
:
5285 case DW_TAG_string_type
:
5286 case DW_TAG_structure_type
:
5287 case DW_TAG_subroutine_type
:
5288 case DW_TAG_union_type
:
5289 case DW_TAG_ptr_to_member_type
:
5290 case DW_TAG_set_type
:
5291 case DW_TAG_subrange_type
:
5292 case DW_TAG_base_type
:
5293 case DW_TAG_const_type
:
5294 case DW_TAG_file_type
:
5295 case DW_TAG_packed_type
:
5296 case DW_TAG_volatile_type
:
5303 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5304 Basically, we want to choose the bits that are likely to be shared between
5305 compilations (types) and leave out the bits that are specific to individual
5306 compilations (functions). */
5313 /* I think we want to leave base types and __vtbl_ptr_type in the
5314 main CU, as we do for stabs. The advantage is a greater
5315 likelihood of sharing between objects that don't include headers
5316 in the same order (and therefore would put the base types in a
5317 different comdat). jason 8/28/00 */
5318 if (c
->die_tag
== DW_TAG_base_type
)
5321 if (c
->die_tag
== DW_TAG_pointer_type
5322 || c
->die_tag
== DW_TAG_reference_type
5323 || c
->die_tag
== DW_TAG_const_type
5324 || c
->die_tag
== DW_TAG_volatile_type
)
5326 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
5327 return t
? is_comdat_die (t
) : 0;
5331 return is_type_die (c
);
5334 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5335 compilation unit. */
5341 if (is_type_die (c
))
5343 if (get_AT (c
, DW_AT_declaration
)
5344 && ! get_AT (c
, DW_AT_specification
))
5353 static int label_num
;
5354 ASM_GENERATE_INTERNAL_LABEL (buf
, "LDIE", label_num
++);
5355 return xstrdup (buf
);
5358 /* Assign symbols to all worthy DIEs under DIE. */
5361 assign_symbol_names (die
)
5362 register dw_die_ref die
;
5364 register dw_die_ref c
;
5366 if (is_symbol_die (die
))
5368 if (comdat_symbol_id
)
5370 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
5371 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
5372 comdat_symbol_id
, comdat_symbol_number
++);
5373 die
->die_symbol
= xstrdup (p
);
5376 die
->die_symbol
= gen_internal_sym ();
5379 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5380 assign_symbol_names (c
);
5383 /* Traverse the DIE (which is always comp_unit_die), and set up
5384 additional compilation units for each of the include files we see
5385 bracketed by BINCL/EINCL. */
5388 break_out_includes (die
)
5389 register dw_die_ref die
;
5392 register dw_die_ref unit
= NULL
;
5393 limbo_die_node
*node
;
5395 for (ptr
= &(die
->die_child
); *ptr
; )
5397 register dw_die_ref c
= *ptr
;
5399 if (c
->die_tag
== DW_TAG_GNU_BINCL
5400 || c
->die_tag
== DW_TAG_GNU_EINCL
5401 || (unit
&& is_comdat_die (c
)))
5403 /* This DIE is for a secondary CU; remove it from the main one. */
5406 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
5408 unit
= push_new_compile_unit (unit
, c
);
5411 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
5413 unit
= pop_compile_unit (unit
);
5417 add_child_die (unit
, c
);
5421 /* Leave this DIE in the main CU. */
5422 ptr
= &(c
->die_sib
);
5428 /* We can only use this in debugging, since the frontend doesn't check
5429 to make sure that we leave every include file we enter. */
5434 assign_symbol_names (die
);
5435 for (node
= limbo_die_list
; node
; node
= node
->next
)
5437 compute_section_prefix (node
->die
);
5438 assign_symbol_names (node
->die
);
5442 /* Traverse the DIE and add a sibling attribute if it may have the
5443 effect of speeding up access to siblings. To save some space,
5444 avoid generating sibling attributes for DIE's without children. */
5447 add_sibling_attributes (die
)
5448 register dw_die_ref die
;
5450 register dw_die_ref c
;
5452 if (die
->die_tag
!= DW_TAG_compile_unit
5453 && die
->die_sib
&& die
->die_child
!= NULL
)
5454 /* Add the sibling link to the front of the attribute list. */
5455 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
5457 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5458 add_sibling_attributes (c
);
5461 /* The format of each DIE (and its attribute value pairs)
5462 is encoded in an abbreviation table. This routine builds the
5463 abbreviation table and assigns a unique abbreviation id for
5464 each abbreviation entry. The children of each die are visited
5468 build_abbrev_table (die
)
5469 register dw_die_ref die
;
5471 register unsigned long abbrev_id
;
5472 register unsigned long n_alloc
;
5473 register dw_die_ref c
;
5474 register dw_attr_ref d_attr
, a_attr
;
5476 /* Scan the DIE references, and mark as external any that refer to
5477 DIEs from other CUs (i.e. those which are not marked). */
5478 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
5480 if (AT_class (d_attr
) == dw_val_class_die_ref
5481 && AT_ref (d_attr
)->die_mark
== 0)
5483 if (AT_ref (d_attr
)->die_symbol
== 0)
5485 set_AT_ref_external (d_attr
, 1);
5489 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
5491 register dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
5493 if (abbrev
->die_tag
== die
->die_tag
)
5495 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
5497 a_attr
= abbrev
->die_attr
;
5498 d_attr
= die
->die_attr
;
5500 while (a_attr
!= NULL
&& d_attr
!= NULL
)
5502 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
5503 || (value_format (a_attr
) != value_format (d_attr
)))
5506 a_attr
= a_attr
->dw_attr_next
;
5507 d_attr
= d_attr
->dw_attr_next
;
5510 if (a_attr
== NULL
&& d_attr
== NULL
)
5516 if (abbrev_id
>= abbrev_die_table_in_use
)
5518 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
5520 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
5522 = (dw_die_ref
*) xrealloc (abbrev_die_table
,
5523 sizeof (dw_die_ref
) * n_alloc
);
5525 memset ((char *) &abbrev_die_table
[abbrev_die_table_allocated
], 0,
5526 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
5527 abbrev_die_table_allocated
= n_alloc
;
5530 ++abbrev_die_table_in_use
;
5531 abbrev_die_table
[abbrev_id
] = die
;
5534 die
->die_abbrev
= abbrev_id
;
5535 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5536 build_abbrev_table (c
);
5539 /* Return the size of a string, including the null byte.
5541 This used to treat backslashes as escapes, and hence they were not included
5542 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5543 which treats a backslash as a backslash, escaping it if necessary, and hence
5544 we must include them in the count. */
5546 static unsigned long
5547 size_of_string (str
)
5548 register const char *str
;
5550 return strlen (str
) + 1;
5553 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5556 constant_size (value
)
5557 long unsigned value
;
5564 log
= floor_log2 (value
);
5567 log
= 1 << (floor_log2 (log
) + 1);
5572 /* Return the size of a DIE, as it is represented in the
5573 .debug_info section. */
5575 static unsigned long
5577 register dw_die_ref die
;
5579 register unsigned long size
= 0;
5580 register dw_attr_ref a
;
5582 size
+= size_of_uleb128 (die
->die_abbrev
);
5583 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5585 switch (AT_class (a
))
5587 case dw_val_class_addr
:
5588 size
+= DWARF2_ADDR_SIZE
;
5590 case dw_val_class_loc
:
5592 register unsigned long lsize
= size_of_locs (AT_loc (a
));
5595 size
+= constant_size (lsize
);
5599 case dw_val_class_const
:
5600 size
+= size_of_sleb128 (AT_int (a
));
5602 case dw_val_class_unsigned_const
:
5603 size
+= constant_size (AT_unsigned (a
));
5605 case dw_val_class_long_long
:
5606 size
+= 1 + 8; /* block */
5608 case dw_val_class_float
:
5609 size
+= 1 + a
->dw_attr_val
.v
.val_float
.length
* 4; /* block */
5611 case dw_val_class_flag
:
5614 case dw_val_class_die_ref
:
5615 size
+= DWARF_OFFSET_SIZE
;
5617 case dw_val_class_fde_ref
:
5618 size
+= DWARF_OFFSET_SIZE
;
5620 case dw_val_class_lbl_id
:
5621 size
+= DWARF2_ADDR_SIZE
;
5623 case dw_val_class_lbl_offset
:
5624 size
+= DWARF_OFFSET_SIZE
;
5626 case dw_val_class_str
:
5627 size
+= size_of_string (AT_string (a
));
5637 /* Size the debugging information associated with a given DIE.
5638 Visits the DIE's children recursively. Updates the global
5639 variable next_die_offset, on each time through. Uses the
5640 current value of next_die_offset to update the die_offset
5641 field in each DIE. */
5644 calc_die_sizes (die
)
5647 register dw_die_ref c
;
5648 die
->die_offset
= next_die_offset
;
5649 next_die_offset
+= size_of_die (die
);
5651 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5654 if (die
->die_child
!= NULL
)
5655 /* Count the null byte used to terminate sibling lists. */
5656 next_die_offset
+= 1;
5659 /* Set the marks for a die and its children. We do this so
5660 that we know whether or not a reference needs to use FORM_ref_addr; only
5661 DIEs in the same CU will be marked. We used to clear out the offset
5662 and use that as the flag, but ran into ordering problems. */
5668 register dw_die_ref c
;
5670 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5674 /* Clear the marks for a die and its children. */
5680 register dw_die_ref c
;
5682 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5686 /* Return the size of the line information prolog generated for the
5687 compilation unit. */
5689 static unsigned long
5690 size_of_line_prolog ()
5692 register unsigned long size
;
5693 register unsigned long ft_index
;
5695 size
= DWARF_LINE_PROLOG_HEADER_SIZE
;
5697 /* Count the size of the table giving number of args for each
5699 size
+= DWARF_LINE_OPCODE_BASE
- 1;
5701 /* Include directory table is empty (at present). Count only the
5702 null byte used to terminate the table. */
5705 for (ft_index
= 1; ft_index
< decl_file_table
.in_use
; ++ft_index
)
5707 /* File name entry. */
5708 size
+= size_of_string (decl_file_table
.table
[ft_index
]);
5710 /* Include directory index. */
5711 size
+= size_of_uleb128 (0);
5713 /* Modification time. */
5714 size
+= size_of_uleb128 (0);
5716 /* File length in bytes. */
5717 size
+= size_of_uleb128 (0);
5720 /* Count the file table terminator. */
5725 /* Return the size of the .debug_pubnames table generated for the
5726 compilation unit. */
5728 static unsigned long
5731 register unsigned long size
;
5732 register unsigned i
;
5734 size
= DWARF_PUBNAMES_HEADER_SIZE
;
5735 for (i
= 0; i
< pubname_table_in_use
; ++i
)
5737 register pubname_ref p
= &pubname_table
[i
];
5738 size
+= DWARF_OFFSET_SIZE
+ size_of_string (p
->name
);
5741 size
+= DWARF_OFFSET_SIZE
;
5745 /* Return the size of the information in the .debug_aranges section. */
5747 static unsigned long
5750 register unsigned long size
;
5752 size
= DWARF_ARANGES_HEADER_SIZE
;
5754 /* Count the address/length pair for this compilation unit. */
5755 size
+= 2 * DWARF2_ADDR_SIZE
;
5756 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
5758 /* Count the two zero words used to terminated the address range table. */
5759 size
+= 2 * DWARF2_ADDR_SIZE
;
5763 /* Select the encoding of an attribute value. */
5765 static enum dwarf_form
5769 switch (a
->dw_attr_val
.val_class
)
5771 case dw_val_class_addr
:
5772 return DW_FORM_addr
;
5773 case dw_val_class_loc
:
5774 switch (constant_size (size_of_locs (AT_loc (a
))))
5777 return DW_FORM_block1
;
5779 return DW_FORM_block2
;
5783 case dw_val_class_const
:
5784 return DW_FORM_sdata
;
5785 case dw_val_class_unsigned_const
:
5786 switch (constant_size (AT_unsigned (a
)))
5789 return DW_FORM_data1
;
5791 return DW_FORM_data2
;
5793 return DW_FORM_data4
;
5795 return DW_FORM_data8
;
5799 case dw_val_class_long_long
:
5800 return DW_FORM_block1
;
5801 case dw_val_class_float
:
5802 return DW_FORM_block1
;
5803 case dw_val_class_flag
:
5804 return DW_FORM_flag
;
5805 case dw_val_class_die_ref
:
5806 if (AT_ref_external (a
))
5807 return DW_FORM_ref_addr
;
5810 case dw_val_class_fde_ref
:
5811 return DW_FORM_data
;
5812 case dw_val_class_lbl_id
:
5813 return DW_FORM_addr
;
5814 case dw_val_class_lbl_offset
:
5815 return DW_FORM_data
;
5816 case dw_val_class_str
:
5817 return DW_FORM_string
;
5823 /* Output the encoding of an attribute value. */
5826 output_value_format (a
)
5829 enum dwarf_form form
= value_format (a
);
5831 output_uleb128 (form
);
5833 fprintf (asm_out_file
, " (%s)", dwarf_form_name (form
));
5835 fputc ('\n', asm_out_file
);
5838 /* Output the .debug_abbrev section which defines the DIE abbreviation
5842 output_abbrev_section ()
5844 unsigned long abbrev_id
;
5847 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
5849 register dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
5851 output_uleb128 (abbrev_id
);
5853 fprintf (asm_out_file
, " (abbrev code)");
5855 fputc ('\n', asm_out_file
);
5856 output_uleb128 (abbrev
->die_tag
);
5858 fprintf (asm_out_file
, " (TAG: %s)",
5859 dwarf_tag_name (abbrev
->die_tag
));
5861 fputc ('\n', asm_out_file
);
5862 fprintf (asm_out_file
, "%s0x%x", ASM_BYTE_OP
,
5863 abbrev
->die_child
!= NULL
? DW_children_yes
: DW_children_no
);
5866 fprintf (asm_out_file
, "\t%s %s",
5868 (abbrev
->die_child
!= NULL
5869 ? "DW_children_yes" : "DW_children_no"));
5871 fputc ('\n', asm_out_file
);
5873 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
5874 a_attr
= a_attr
->dw_attr_next
)
5876 output_uleb128 (a_attr
->dw_attr
);
5878 fprintf (asm_out_file
, " (%s)",
5879 dwarf_attr_name (a_attr
->dw_attr
));
5881 fputc ('\n', asm_out_file
);
5882 output_value_format (a_attr
);
5885 fprintf (asm_out_file
, "%s0,0\n", ASM_BYTE_OP
);
5888 /* Terminate the table. */
5889 fprintf (asm_out_file
, "%s0\n", ASM_BYTE_OP
);
5892 /* Output a symbol we can use to refer to this DIE from another CU. */
5895 output_die_symbol (die
)
5896 register dw_die_ref die
;
5898 char *sym
= die
->die_symbol
;
5903 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
5904 /* We make these global, not weak; if the target doesn't support
5905 .linkonce, it doesn't support combining the sections, so debugging
5907 ASM_GLOBALIZE_LABEL (asm_out_file
, sym
);
5908 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
5911 /* Output a symbolic (i.e. FORM_ref_addr) reference to TARGET_DIE. */
5914 output_symbolic_ref (target_die
)
5915 dw_die_ref target_die
;
5917 char *sym
= target_die
->die_symbol
;
5922 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, sym
);
5925 /* Output the DIE and its attributes. Called recursively to generate
5926 the definitions of each child DIE. */
5930 register dw_die_ref die
;
5932 register dw_attr_ref a
;
5933 register dw_die_ref c
;
5934 register unsigned long size
;
5936 /* If someone in another CU might refer to us, set up a symbol for
5937 them to point to. */
5938 if (die
->die_symbol
)
5939 output_die_symbol (die
);
5941 output_uleb128 (die
->die_abbrev
);
5943 fprintf (asm_out_file
, " (DIE (0x%lx) %s)",
5944 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5946 fputc ('\n', asm_out_file
);
5948 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5950 switch (AT_class (a
))
5952 case dw_val_class_addr
:
5953 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
, AT_addr (a
));
5956 case dw_val_class_loc
:
5957 size
= size_of_locs (AT_loc (a
));
5959 /* Output the block length for this list of location operations. */
5960 switch (constant_size (size
))
5963 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, size
);
5966 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, size
);
5973 fprintf (asm_out_file
, "\t%s %s",
5974 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
5976 fputc ('\n', asm_out_file
);
5978 output_loc_sequence (AT_loc (a
));
5981 case dw_val_class_const
:
5982 /* ??? It would be slightly more efficient to use a scheme like is
5983 used for unsigned constants below, but gdb 4.x does not sign
5984 extend. Gdb 5.x does sign extend. */
5985 output_sleb128 (AT_int (a
));
5988 case dw_val_class_unsigned_const
:
5989 switch (constant_size (AT_unsigned (a
)))
5992 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, AT_unsigned (a
));
5995 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, AT_unsigned (a
));
5998 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, AT_unsigned (a
));
6001 ASM_OUTPUT_DWARF_DATA8 (asm_out_file
, AT_unsigned (a
));
6008 case dw_val_class_long_long
:
6009 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 8);
6011 fprintf (asm_out_file
, "\t%s %s",
6012 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
6014 fputc ('\n', asm_out_file
);
6015 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file
,
6016 a
->dw_attr_val
.v
.val_long_long
.hi
,
6017 a
->dw_attr_val
.v
.val_long_long
.low
);
6020 fprintf (asm_out_file
,
6021 "\t%s long long constant", ASM_COMMENT_START
);
6023 fputc ('\n', asm_out_file
);
6026 case dw_val_class_float
:
6028 register unsigned int i
;
6029 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
6030 a
->dw_attr_val
.v
.val_float
.length
* 4);
6032 fprintf (asm_out_file
, "\t%s %s",
6033 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
6035 fputc ('\n', asm_out_file
);
6036 for (i
= 0; i
< a
->dw_attr_val
.v
.val_float
.length
; ++i
)
6038 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
,
6039 a
->dw_attr_val
.v
.val_float
.array
[i
]);
6041 fprintf (asm_out_file
, "\t%s fp constant word %u",
6042 ASM_COMMENT_START
, i
);
6044 fputc ('\n', asm_out_file
);
6049 case dw_val_class_flag
:
6050 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, AT_flag (a
));
6053 case dw_val_class_die_ref
:
6054 if (AT_ref_external (a
))
6055 output_symbolic_ref (AT_ref (a
));
6056 else if (AT_ref (a
)->die_offset
== 0)
6059 ASM_OUTPUT_DWARF_DATA (asm_out_file
, AT_ref (a
)->die_offset
);
6062 case dw_val_class_fde_ref
:
6065 ASM_GENERATE_INTERNAL_LABEL
6066 (l1
, FDE_AFTER_SIZE_LABEL
, a
->dw_attr_val
.v
.val_fde_index
* 2);
6067 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, l1
);
6068 fprintf (asm_out_file
, " - %d", DWARF_OFFSET_SIZE
);
6072 case dw_val_class_lbl_id
:
6073 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, AT_lbl (a
));
6076 case dw_val_class_lbl_offset
:
6077 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, AT_lbl (a
));
6080 case dw_val_class_str
:
6082 ASM_OUTPUT_DWARF_STRING (asm_out_file
, AT_string (a
));
6084 ASM_OUTPUT_ASCII (asm_out_file
, AT_string (a
),
6085 (int) strlen (AT_string (a
)) + 1);
6092 if (AT_class (a
) != dw_val_class_loc
6093 && AT_class (a
) != dw_val_class_long_long
6094 && AT_class (a
) != dw_val_class_float
)
6097 fprintf (asm_out_file
, "\t%s %s",
6098 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
6100 fputc ('\n', asm_out_file
);
6104 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6107 if (die
->die_child
!= NULL
)
6109 /* Add null byte to terminate sibling list. */
6110 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
6112 fprintf (asm_out_file
, "\t%s end of children of DIE 0x%lx",
6113 ASM_COMMENT_START
, die
->die_offset
);
6115 fputc ('\n', asm_out_file
);
6119 /* Output the compilation unit that appears at the beginning of the
6120 .debug_info section, and precedes the DIE descriptions. */
6123 output_compilation_unit_header ()
6125 ASM_OUTPUT_DWARF_DATA (asm_out_file
, next_die_offset
- DWARF_OFFSET_SIZE
);
6127 fprintf (asm_out_file
, "\t%s Length of Compilation Unit Info.",
6130 fputc ('\n', asm_out_file
);
6131 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
6133 fprintf (asm_out_file
, "\t%s DWARF version number", ASM_COMMENT_START
);
6135 fputc ('\n', asm_out_file
);
6136 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, abbrev_section_label
);
6138 fprintf (asm_out_file
, "\t%s Offset Into Abbrev. Section",
6141 fputc ('\n', asm_out_file
);
6142 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF2_ADDR_SIZE
);
6144 fprintf (asm_out_file
, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START
);
6146 fputc ('\n', asm_out_file
);
6149 /* Output the compilation unit DIE and its children. */
6152 output_comp_unit (die
)
6155 const char *secname
;
6157 if (die
->die_child
== 0)
6160 /* Mark all the DIEs in this CU so we know which get local refs. */
6163 build_abbrev_table (die
);
6165 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6166 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
6167 calc_die_sizes (die
);
6169 if (die
->die_symbol
)
6171 char *tmp
= (char *) alloca (strlen (die
->die_symbol
) + 24);
6172 sprintf (tmp
, ".gnu.linkonce.wi.%s", die
->die_symbol
);
6174 die
->die_symbol
= NULL
;
6177 secname
= (const char *) DEBUG_INFO_SECTION
;
6179 /* Output debugging information. */
6180 fputc ('\n', asm_out_file
);
6181 ASM_OUTPUT_SECTION (asm_out_file
, secname
);
6182 output_compilation_unit_header ();
6185 /* Leave the marks on the main CU, so we can check them in
6187 if (die
->die_symbol
)
6191 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6192 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6193 argument list, and maybe the scope. */
6196 dwarf2_name (decl
, scope
)
6200 return (*decl_printable_name
) (decl
, scope
? 1 : 0);
6203 /* Add a new entry to .debug_pubnames if appropriate. */
6206 add_pubname (decl
, die
)
6212 if (! TREE_PUBLIC (decl
))
6215 if (pubname_table_in_use
== pubname_table_allocated
)
6217 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
6218 pubname_table
= (pubname_ref
) xrealloc
6219 (pubname_table
, pubname_table_allocated
* sizeof (pubname_entry
));
6222 p
= &pubname_table
[pubname_table_in_use
++];
6225 p
->name
= xstrdup (dwarf2_name (decl
, 1));
6228 /* Output the public names table used to speed up access to externally
6229 visible names. For now, only generate entries for externally
6230 visible procedures. */
6235 register unsigned i
;
6236 register unsigned long pubnames_length
= size_of_pubnames ();
6238 ASM_OUTPUT_DWARF_DATA (asm_out_file
, pubnames_length
);
6241 fprintf (asm_out_file
, "\t%s Length of Public Names Info.",
6244 fputc ('\n', asm_out_file
);
6245 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
6248 fprintf (asm_out_file
, "\t%s DWARF Version", ASM_COMMENT_START
);
6250 fputc ('\n', asm_out_file
);
6251 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, debug_info_section_label
);
6253 fprintf (asm_out_file
, "\t%s Offset of Compilation Unit Info.",
6256 fputc ('\n', asm_out_file
);
6257 ASM_OUTPUT_DWARF_DATA (asm_out_file
, next_die_offset
);
6259 fprintf (asm_out_file
, "\t%s Compilation Unit Length", ASM_COMMENT_START
);
6261 fputc ('\n', asm_out_file
);
6262 for (i
= 0; i
< pubname_table_in_use
; ++i
)
6264 register pubname_ref pub
= &pubname_table
[i
];
6266 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6267 if (pub
->die
->die_mark
== 0)
6270 ASM_OUTPUT_DWARF_DATA (asm_out_file
, pub
->die
->die_offset
);
6272 fprintf (asm_out_file
, "\t%s DIE offset", ASM_COMMENT_START
);
6274 fputc ('\n', asm_out_file
);
6278 ASM_OUTPUT_DWARF_STRING (asm_out_file
, pub
->name
);
6279 fprintf (asm_out_file
, "%s external name", ASM_COMMENT_START
);
6283 ASM_OUTPUT_ASCII (asm_out_file
, pub
->name
,
6284 (int) strlen (pub
->name
) + 1);
6287 fputc ('\n', asm_out_file
);
6290 ASM_OUTPUT_DWARF_DATA (asm_out_file
, 0);
6291 fputc ('\n', asm_out_file
);
6294 /* Add a new entry to .debug_aranges if appropriate. */
6297 add_arange (decl
, die
)
6301 if (! DECL_SECTION_NAME (decl
))
6304 if (arange_table_in_use
== arange_table_allocated
)
6306 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
6308 = (arange_ref
) xrealloc (arange_table
,
6309 arange_table_allocated
* sizeof (dw_die_ref
));
6312 arange_table
[arange_table_in_use
++] = die
;
6315 /* Output the information that goes into the .debug_aranges table.
6316 Namely, define the beginning and ending address range of the
6317 text section generated for this compilation unit. */
6322 register unsigned i
;
6323 register unsigned long aranges_length
= size_of_aranges ();
6325 ASM_OUTPUT_DWARF_DATA (asm_out_file
, aranges_length
);
6327 fprintf (asm_out_file
, "\t%s Length of Address Ranges Info.",
6330 fputc ('\n', asm_out_file
);
6331 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
6333 fprintf (asm_out_file
, "\t%s DWARF Version", ASM_COMMENT_START
);
6335 fputc ('\n', asm_out_file
);
6336 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, debug_info_section_label
);
6338 fprintf (asm_out_file
, "\t%s Offset of Compilation Unit Info.",
6341 fputc ('\n', asm_out_file
);
6342 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF2_ADDR_SIZE
);
6344 fprintf (asm_out_file
, "\t%s Size of Address", ASM_COMMENT_START
);
6346 fputc ('\n', asm_out_file
);
6347 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
6349 fprintf (asm_out_file
, "\t%s Size of Segment Descriptor",
6352 fputc ('\n', asm_out_file
);
6354 /* We need to align to twice the pointer size here. */
6355 if (DWARF_ARANGES_PAD_SIZE
)
6357 /* Pad using a 2 bytes word so that padding is correct
6358 for any pointer size. */
6359 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, 0);
6360 for (i
= 2; i
< DWARF_ARANGES_PAD_SIZE
; i
+= 2)
6361 fprintf (asm_out_file
, ",0");
6363 fprintf (asm_out_file
, "\t%s Pad to %d byte boundary",
6364 ASM_COMMENT_START
, 2 * DWARF2_ADDR_SIZE
);
6367 fputc ('\n', asm_out_file
);
6368 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, text_section_label
);
6370 fprintf (asm_out_file
, "\t%s Address", ASM_COMMENT_START
);
6372 fputc ('\n', asm_out_file
);
6373 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
, text_end_label
,
6374 text_section_label
);
6376 fprintf (asm_out_file
, "%s Length", ASM_COMMENT_START
);
6378 fputc ('\n', asm_out_file
);
6379 for (i
= 0; i
< arange_table_in_use
; ++i
)
6381 dw_die_ref die
= arange_table
[i
];
6383 /* We shouldn't see aranges for DIEs outside of the main CU. */
6384 if (die
->die_mark
== 0)
6387 if (die
->die_tag
== DW_TAG_subprogram
)
6388 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, get_AT_low_pc (die
));
6391 /* A static variable; extract the symbol from DW_AT_location.
6392 Note that this code isn't currently hit, as we only emit
6393 aranges for functions (jason 9/23/99). */
6395 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
6396 dw_loc_descr_ref loc
;
6397 if (! a
|| AT_class (a
) != dw_val_class_loc
)
6401 if (loc
->dw_loc_opc
!= DW_OP_addr
)
6404 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
,
6405 loc
->dw_loc_oprnd1
.v
.val_addr
);
6409 fprintf (asm_out_file
, "\t%s Address", ASM_COMMENT_START
);
6411 fputc ('\n', asm_out_file
);
6412 if (die
->die_tag
== DW_TAG_subprogram
)
6413 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
, get_AT_hi_pc (die
),
6414 get_AT_low_pc (die
));
6416 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
,
6417 get_AT_unsigned (die
, DW_AT_byte_size
));
6420 fprintf (asm_out_file
, "%s Length", ASM_COMMENT_START
);
6422 fputc ('\n', asm_out_file
);
6425 /* Output the terminator words. */
6426 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
, 0);
6427 fputc ('\n', asm_out_file
);
6428 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
, 0);
6429 fputc ('\n', asm_out_file
);
6433 /* Data structure containing information about input files. */
6436 char *path
; /* Complete file name. */
6437 char *fname
; /* File name part. */
6438 int length
; /* Length of entire string. */
6439 int file_idx
; /* Index in input file table. */
6440 int dir_idx
; /* Index in directory table. */
6443 /* Data structure containing information about directories with source
6447 char *path
; /* Path including directory name. */
6448 int length
; /* Path length. */
6449 int prefix
; /* Index of directory entry which is a prefix. */
6450 int nbytes
; /* Total number of bytes in all file names excluding
6452 int count
; /* Number of files in this directory. */
6453 int dir_idx
; /* Index of directory used as base. */
6454 int used
; /* Used in the end? */
6457 /* Callback function for file_info comparison. We sort by looking at
6458 the directories in the path. */
6460 file_info_cmp (p1
, p2
)
6464 const struct file_info
*s1
= p1
;
6465 const struct file_info
*s2
= p2
;
6469 /* Take care of file names without directories. */
6470 if (s1
->path
== s1
->fname
)
6472 else if (s2
->path
== s2
->fname
)
6475 cp1
= (unsigned char *) s1
->path
;
6476 cp2
= (unsigned char *) s2
->path
;
6482 /* Reached the end of the first path? */
6483 if (cp1
== (unsigned char *) s1
->fname
)
6484 /* It doesn't really matter in which order files from the
6485 same directory are sorted in. Therefore don't test for
6486 the second path reaching the end. */
6488 else if (cp2
== (unsigned char *) s2
->fname
)
6491 /* Character of current path component the same? */
6497 /* Output the directory table and the file name table. We try to minimize
6498 the total amount of memory needed. A heuristic is used to avoid large
6499 slowdowns with many input files. */
6501 output_file_names ()
6503 struct file_info
*files
;
6504 struct dir_info
*dirs
;
6513 /* Allocate the various arrays we need. */
6514 files
= (struct file_info
*) alloca (line_file_table
.in_use
6515 * sizeof (struct file_info
));
6516 dirs
= (struct dir_info
*) alloca (line_file_table
.in_use
6517 * sizeof (struct dir_info
));
6519 /* Sort the file names. */
6520 for (i
= 1; i
< (int) line_file_table
.in_use
; ++i
)
6524 /* Skip all leading "./". */
6525 f
= line_file_table
.table
[i
];
6526 while (f
[0] == '.' && f
[1] == '/')
6529 /* Create a new array entry. */
6531 files
[i
].length
= strlen (f
);
6532 files
[i
].file_idx
= i
;
6534 /* Search for the file name part. */
6535 f
= strrchr (f
, '/');
6536 files
[i
].fname
= f
== NULL
? files
[i
].path
: f
+ 1;
6538 qsort (files
+ 1, line_file_table
.in_use
- 1, sizeof (files
[0]),
6541 /* Find all the different directories used. */
6542 dirs
[0].path
= files
[1].path
;
6543 dirs
[0].length
= files
[1].fname
- files
[1].path
;
6544 dirs
[0].prefix
= -1;
6545 dirs
[0].nbytes
= files
[1].length
- dirs
[1].length
+ 1;
6547 dirs
[0].dir_idx
= 0;
6549 files
[1].dir_idx
= 0;
6552 for (i
= 2; i
< (int) line_file_table
.in_use
; ++i
)
6553 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
6554 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
6555 dirs
[ndirs
- 1].length
) == 0)
6557 /* Same directory as last entry. */
6558 files
[i
].dir_idx
= ndirs
- 1;
6559 dirs
[ndirs
- 1].nbytes
+= files
[i
].length
- dirs
[ndirs
- 1].length
+ 1;
6560 ++dirs
[ndirs
- 1].count
;
6566 /* This is a new directory. */
6567 dirs
[ndirs
].path
= files
[i
].path
;
6568 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
6569 dirs
[ndirs
].nbytes
= files
[i
].length
- dirs
[i
].length
+ 1;
6570 dirs
[ndirs
].count
= 1;
6571 dirs
[ndirs
].dir_idx
= ndirs
;
6572 dirs
[ndirs
].used
= 0;
6573 files
[i
].dir_idx
= ndirs
;
6575 /* Search for a prefix. */
6576 dirs
[ndirs
].prefix
= -1;
6577 for (j
= 0; j
< ndirs
; ++j
)
6578 if (dirs
[j
].length
< dirs
[ndirs
].length
6579 && dirs
[j
].length
!= 0
6580 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
6581 dirs
[ndirs
].prefix
= j
;
6586 /* Now to the actual work. We have to find a subset of the
6587 directories which allow expressing the file name using references
6588 to the directory table with the least amount of characters. We
6589 do not do an exhaustive search where we would have to check out
6590 every combination of every single possible prefix. Instead we
6591 use a heuristic which provides nearly optimal results in most
6592 cases and never is much off. */
6593 saved
= (int *) alloca (ndirs
* sizeof (int));
6594 savehere
= (int *) alloca (ndirs
* sizeof (int));
6596 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
6597 for (i
= 0; i
< ndirs
; ++i
)
6602 /* We can always safe some space for the current directory. But
6603 this does not mean it will be enough to justify adding the
6605 savehere
[i
] = dirs
[i
].length
;
6606 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
6608 for (j
= i
+ 1; j
< ndirs
; ++j
)
6612 if (saved
[j
] < dirs
[i
].length
)
6614 /* Determine whether the dirs[i] path is a prefix of the
6619 while (k
!= -1 && k
!= i
)
6624 /* Yes it is. We can possibly safe some memory but
6625 writing the filenames in dirs[j] relative to
6627 savehere
[j
] = dirs
[i
].length
;
6628 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
6633 /* Check whether we can safe enough to justify adding the dirs[i]
6635 if (total
> dirs
[i
].length
+ 1)
6637 /* It's worthwhile adding. */
6638 for (j
= i
; j
< ndirs
; ++j
)
6639 if (savehere
[j
] > 0)
6641 /* Remember how much we saved for this directory so far. */
6642 saved
[j
] = savehere
[j
];
6644 /* Remember the prefix directory. */
6645 dirs
[j
].dir_idx
= i
;
6650 /* We have to emit them in the order they appear in the line_file_table
6651 array since the index is used in the debug info generation. To
6652 do this efficiently we generate a back-mapping of the indices
6654 backmap
= (int *) alloca (line_file_table
.in_use
* sizeof (int));
6655 for (i
= 1; i
< (int) line_file_table
.in_use
; ++i
)
6657 backmap
[files
[i
].file_idx
] = i
;
6658 /* Mark this directory as used. */
6659 dirs
[dirs
[files
[i
].dir_idx
].dir_idx
].used
= 1;
6662 /* That was it. We are ready to emit the information. First the
6663 directory name table. Here we have to make sure that the first
6664 actually emitted directory name has the index one. Zero is
6665 reserved for the current working directory. Make sure we do not
6666 confuse these indices with the one for the constructed table
6667 (even though most of the time they are identical). */
6669 idx_offset
= dirs
[0].path
[0] == '/' ? 1 : 0;
6670 for (i
= 1 - idx_offset
; i
< ndirs
; ++i
)
6671 if (dirs
[i
].used
!= 0)
6673 dirs
[i
].used
= idx
++;
6677 ASM_OUTPUT_DWARF_NSTRING (asm_out_file
,
6678 dirs
[i
].path
, dirs
[i
].length
- 1);
6679 fprintf (asm_out_file
, "%s Directory Entry: 0x%x\n",
6680 ASM_COMMENT_START
, dirs
[i
].used
);
6684 ASM_OUTPUT_ASCII (asm_out_file
, dirs
[i
].path
, dirs
[i
].length
- 1);
6685 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
6686 fputc ('\n', asm_out_file
);
6689 /* Correct the index for the current working directory entry if it
6691 if (idx_offset
== 0)
6693 /* Terminate the directory name array. */
6694 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
6696 fprintf (asm_out_file
, "\t%s End directory table", ASM_COMMENT_START
);
6697 fputc ('\n', asm_out_file
);
6699 /* Now write all the file names. */
6700 for (i
= 1; i
< (int) line_file_table
.in_use
; ++i
)
6702 int file_idx
= backmap
[i
];
6703 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
6707 ASM_OUTPUT_DWARF_STRING (asm_out_file
,
6708 files
[file_idx
].path
6709 + dirs
[dir_idx
].length
);
6710 fprintf (asm_out_file
, "%s File Entry: 0x%x\n",
6711 ASM_COMMENT_START
, i
);
6714 ASM_OUTPUT_ASCII (asm_out_file
,
6715 files
[file_idx
].path
+ dirs
[dir_idx
].length
,
6716 (files
[file_idx
].length
6717 - dirs
[dir_idx
].length
) + 1);
6719 /* Include directory index. */
6720 output_uleb128 (dirs
[dir_idx
].used
);
6721 fputc ('\n', asm_out_file
);
6723 /* Modification time. */
6725 fputc ('\n', asm_out_file
);
6727 /* File length in bytes. */
6729 fputc ('\n', asm_out_file
);
6732 /* Terminate the file name table */
6733 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
6735 fprintf (asm_out_file
, "\t%s End file name table", ASM_COMMENT_START
);
6736 fputc ('\n', asm_out_file
);
6740 /* Output the source line number correspondence information. This
6741 information goes into the .debug_line section. */
6746 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6747 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6748 register unsigned opc
;
6749 register unsigned n_op_args
;
6750 register unsigned long lt_index
;
6751 register unsigned long current_line
;
6752 register long line_offset
;
6753 register long line_delta
;
6754 register unsigned long current_file
;
6755 register unsigned long function
;
6757 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, ".LTEND", ".LTSTART");
6759 fprintf (asm_out_file
, "\t%s Length of Source Line Info.",
6762 fputc ('\n', asm_out_file
);
6763 ASM_OUTPUT_LABEL (asm_out_file
, ".LTSTART");
6764 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
6766 fprintf (asm_out_file
, "\t%s DWARF Version", ASM_COMMENT_START
);
6768 fputc ('\n', asm_out_file
);
6769 ASM_OUTPUT_DWARF_DATA (asm_out_file
, size_of_line_prolog ());
6771 fprintf (asm_out_file
, "\t%s Prolog Length", ASM_COMMENT_START
);
6773 fputc ('\n', asm_out_file
);
6774 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_LINE_MIN_INSTR_LENGTH
);
6776 fprintf (asm_out_file
, "\t%s Minimum Instruction Length",
6779 fputc ('\n', asm_out_file
);
6780 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_LINE_DEFAULT_IS_STMT_START
);
6782 fprintf (asm_out_file
, "\t%s Default is_stmt_start flag",
6785 fputc ('\n', asm_out_file
);
6786 fprintf (asm_out_file
, "%s%d", ASM_BYTE_OP
, DWARF_LINE_BASE
);
6788 fprintf (asm_out_file
, "\t%s Line Base Value (Special Opcodes)",
6791 fputc ('\n', asm_out_file
);
6792 fprintf (asm_out_file
, "%s%u", ASM_BYTE_OP
, DWARF_LINE_RANGE
);
6794 fprintf (asm_out_file
, "\t%s Line Range Value (Special Opcodes)",
6797 fputc ('\n', asm_out_file
);
6798 fprintf (asm_out_file
, "%s%u", ASM_BYTE_OP
, DWARF_LINE_OPCODE_BASE
);
6800 fprintf (asm_out_file
, "\t%s Special Opcode Base", ASM_COMMENT_START
);
6802 fputc ('\n', asm_out_file
);
6803 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; ++opc
)
6807 case DW_LNS_advance_pc
:
6808 case DW_LNS_advance_line
:
6809 case DW_LNS_set_file
:
6810 case DW_LNS_set_column
:
6811 case DW_LNS_fixed_advance_pc
:
6818 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, n_op_args
);
6820 fprintf (asm_out_file
, "\t%s opcode: 0x%x has %d args",
6821 ASM_COMMENT_START
, opc
, n_op_args
);
6822 fputc ('\n', asm_out_file
);
6825 /* Write out the information about the files we use. */
6826 output_file_names ();
6828 /* We used to set the address register to the first location in the text
6829 section here, but that didn't accomplish anything since we already
6830 have a line note for the opening brace of the first function. */
6832 /* Generate the line number to PC correspondence table, encoded as
6833 a series of state machine operations. */
6836 strcpy (prev_line_label
, text_section_label
);
6837 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
6839 register dw_line_info_ref line_info
= &line_info_table
[lt_index
];
6842 /* Disable this optimization for now; GDB wants to see two line notes
6843 at the beginning of a function so it can find the end of the
6846 /* Don't emit anything for redundant notes. Just updating the
6847 address doesn't accomplish anything, because we already assume
6848 that anything after the last address is this line. */
6849 if (line_info
->dw_line_num
== current_line
6850 && line_info
->dw_file_num
== current_file
)
6854 /* Emit debug info for the address of the current line, choosing
6855 the encoding that uses the least amount of space. */
6856 /* ??? Unfortunately, we have little choice here currently, and must
6857 always use the most general form. Gcc does not know the address
6858 delta itself, so we can't use DW_LNS_advance_pc. There are no known
6859 dwarf2 aware assemblers at this time, so we can't use any special
6860 pseudo ops that would allow the assembler to optimally encode this for
6861 us. Many ports do have length attributes which will give an upper
6862 bound on the address range. We could perhaps use length attributes
6863 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
6864 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
6867 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6868 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
6870 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
6873 fputc ('\n', asm_out_file
);
6874 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
, prev_line_label
);
6875 fputc ('\n', asm_out_file
);
6879 /* This can handle any delta. This takes
6880 4+DWARF2_ADDR_SIZE bytes. */
6881 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
6883 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
6885 fputc ('\n', asm_out_file
);
6886 output_uleb128 (1 + DWARF2_ADDR_SIZE
);
6887 fputc ('\n', asm_out_file
);
6888 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
6889 fputc ('\n', asm_out_file
);
6890 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
6891 fputc ('\n', asm_out_file
);
6893 strcpy (prev_line_label
, line_label
);
6895 /* Emit debug info for the source file of the current line, if
6896 different from the previous line. */
6897 if (line_info
->dw_file_num
!= current_file
)
6899 current_file
= line_info
->dw_file_num
;
6900 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_set_file
);
6902 fprintf (asm_out_file
, "\t%s DW_LNS_set_file", ASM_COMMENT_START
);
6904 fputc ('\n', asm_out_file
);
6905 output_uleb128 (current_file
);
6907 fprintf (asm_out_file
, " (\"%s\")",
6908 line_file_table
.table
[current_file
]);
6910 fputc ('\n', asm_out_file
);
6913 /* Emit debug info for the current line number, choosing the encoding
6914 that uses the least amount of space. */
6915 if (line_info
->dw_line_num
!= current_line
)
6917 line_offset
= line_info
->dw_line_num
- current_line
;
6918 line_delta
= line_offset
- DWARF_LINE_BASE
;
6919 current_line
= line_info
->dw_line_num
;
6920 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
6922 /* This can handle deltas from -10 to 234, using the current
6923 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6925 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
6926 DWARF_LINE_OPCODE_BASE
+ line_delta
);
6928 fprintf (asm_out_file
,
6929 "\t%s line %ld", ASM_COMMENT_START
, current_line
);
6931 fputc ('\n', asm_out_file
);
6935 /* This can handle any delta. This takes at least 4 bytes,
6936 depending on the value being encoded. */
6937 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_advance_line
);
6939 fprintf (asm_out_file
, "\t%s advance to line %ld",
6940 ASM_COMMENT_START
, current_line
);
6942 fputc ('\n', asm_out_file
);
6943 output_sleb128 (line_offset
);
6944 fputc ('\n', asm_out_file
);
6945 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
6947 fprintf (asm_out_file
, "\t%s DW_LNS_copy", ASM_COMMENT_START
);
6948 fputc ('\n', asm_out_file
);
6953 /* We still need to start a new row, so output a copy insn. */
6954 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
6956 fprintf (asm_out_file
, "\t%s DW_LNS_copy", ASM_COMMENT_START
);
6957 fputc ('\n', asm_out_file
);
6961 /* Emit debug info for the address of the end of the function. */
6964 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
6966 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
6969 fputc ('\n', asm_out_file
);
6970 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, text_end_label
, prev_line_label
);
6971 fputc ('\n', asm_out_file
);
6975 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
6977 fprintf (asm_out_file
, "\t%s DW_LNE_set_address", ASM_COMMENT_START
);
6978 fputc ('\n', asm_out_file
);
6979 output_uleb128 (1 + DWARF2_ADDR_SIZE
);
6980 fputc ('\n', asm_out_file
);
6981 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
6982 fputc ('\n', asm_out_file
);
6983 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, text_end_label
);
6984 fputc ('\n', asm_out_file
);
6987 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
6989 fprintf (asm_out_file
, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START
);
6991 fputc ('\n', asm_out_file
);
6993 fputc ('\n', asm_out_file
);
6994 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_end_sequence
);
6995 fputc ('\n', asm_out_file
);
7000 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
7002 register dw_separate_line_info_ref line_info
7003 = &separate_line_info_table
[lt_index
];
7006 /* Don't emit anything for redundant notes. */
7007 if (line_info
->dw_line_num
== current_line
7008 && line_info
->dw_file_num
== current_file
7009 && line_info
->function
== function
)
7013 /* Emit debug info for the address of the current line. If this is
7014 a new function, or the first line of a function, then we need
7015 to handle it differently. */
7016 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
7018 if (function
!= line_info
->function
)
7020 function
= line_info
->function
;
7022 /* Set the address register to the first line in the function */
7023 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
7025 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
7028 fputc ('\n', asm_out_file
);
7029 output_uleb128 (1 + DWARF2_ADDR_SIZE
);
7030 fputc ('\n', asm_out_file
);
7031 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
7032 fputc ('\n', asm_out_file
);
7033 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
7034 fputc ('\n', asm_out_file
);
7038 /* ??? See the DW_LNS_advance_pc comment above. */
7041 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
7043 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
7046 fputc ('\n', asm_out_file
);
7047 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
,
7049 fputc ('\n', asm_out_file
);
7053 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
7055 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
7057 fputc ('\n', asm_out_file
);
7058 output_uleb128 (1 + DWARF2_ADDR_SIZE
);
7059 fputc ('\n', asm_out_file
);
7060 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
7061 fputc ('\n', asm_out_file
);
7062 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
7063 fputc ('\n', asm_out_file
);
7066 strcpy (prev_line_label
, line_label
);
7068 /* Emit debug info for the source file of the current line, if
7069 different from the previous line. */
7070 if (line_info
->dw_file_num
!= current_file
)
7072 current_file
= line_info
->dw_file_num
;
7073 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_set_file
);
7075 fprintf (asm_out_file
, "\t%s DW_LNS_set_file", ASM_COMMENT_START
);
7077 fputc ('\n', asm_out_file
);
7078 output_uleb128 (current_file
);
7080 fprintf (asm_out_file
, " (\"%s\")",
7081 line_file_table
.table
[current_file
]);
7083 fputc ('\n', asm_out_file
);
7086 /* Emit debug info for the current line number, choosing the encoding
7087 that uses the least amount of space. */
7088 if (line_info
->dw_line_num
!= current_line
)
7090 line_offset
= line_info
->dw_line_num
- current_line
;
7091 line_delta
= line_offset
- DWARF_LINE_BASE
;
7092 current_line
= line_info
->dw_line_num
;
7093 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7095 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
7096 DWARF_LINE_OPCODE_BASE
+ line_delta
);
7098 fprintf (asm_out_file
,
7099 "\t%s line %ld", ASM_COMMENT_START
, current_line
);
7101 fputc ('\n', asm_out_file
);
7105 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_advance_line
);
7107 fprintf (asm_out_file
, "\t%s advance to line %ld",
7108 ASM_COMMENT_START
, current_line
);
7110 fputc ('\n', asm_out_file
);
7111 output_sleb128 (line_offset
);
7112 fputc ('\n', asm_out_file
);
7113 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
7115 fprintf (asm_out_file
, "\t%s DW_LNS_copy", ASM_COMMENT_START
);
7116 fputc ('\n', asm_out_file
);
7121 /* We still need to start a new row, so output a copy insn. */
7122 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
7124 fprintf (asm_out_file
, "\t%s DW_LNS_copy", ASM_COMMENT_START
);
7125 fputc ('\n', asm_out_file
);
7133 /* If we're done with a function, end its sequence. */
7134 if (lt_index
== separate_line_info_table_in_use
7135 || separate_line_info_table
[lt_index
].function
!= function
)
7140 /* Emit debug info for the address of the end of the function. */
7141 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
7144 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
7146 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
7149 fputc ('\n', asm_out_file
);
7150 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
,
7152 fputc ('\n', asm_out_file
);
7156 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
7158 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
7160 fputc ('\n', asm_out_file
);
7161 output_uleb128 (1 + DWARF2_ADDR_SIZE
);
7162 fputc ('\n', asm_out_file
);
7163 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
7164 fputc ('\n', asm_out_file
);
7165 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
7166 fputc ('\n', asm_out_file
);
7169 /* Output the marker for the end of this sequence. */
7170 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
7172 fprintf (asm_out_file
, "\t%s DW_LNE_end_sequence",
7175 fputc ('\n', asm_out_file
);
7177 fputc ('\n', asm_out_file
);
7178 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_end_sequence
);
7179 fputc ('\n', asm_out_file
);
7183 /* Output the marker for the end of the line number info. */
7184 ASM_OUTPUT_LABEL (asm_out_file
, ".LTEND");
7187 /* Given a pointer to a tree node for some base type, return a pointer to
7188 a DIE that describes the given type.
7190 This routine must only be called for GCC type nodes that correspond to
7191 Dwarf base (fundamental) types. */
7194 base_type_die (type
)
7197 register dw_die_ref base_type_result
;
7198 register const char *type_name
;
7199 register enum dwarf_type encoding
;
7200 register tree name
= TYPE_NAME (type
);
7202 if (TREE_CODE (type
) == ERROR_MARK
7203 || TREE_CODE (type
) == VOID_TYPE
)
7208 if (TREE_CODE (name
) == TYPE_DECL
)
7209 name
= DECL_NAME (name
);
7211 type_name
= IDENTIFIER_POINTER (name
);
7214 type_name
= "__unknown__";
7216 switch (TREE_CODE (type
))
7219 /* Carefully distinguish the C character types, without messing
7220 up if the language is not C. Note that we check only for the names
7221 that contain spaces; other names might occur by coincidence in other
7223 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
7224 && (type
== char_type_node
7225 || ! strcmp (type_name
, "signed char")
7226 || ! strcmp (type_name
, "unsigned char"))))
7228 if (TREE_UNSIGNED (type
))
7229 encoding
= DW_ATE_unsigned
;
7231 encoding
= DW_ATE_signed
;
7234 /* else fall through. */
7237 /* GNU Pascal/Ada CHAR type. Not used in C. */
7238 if (TREE_UNSIGNED (type
))
7239 encoding
= DW_ATE_unsigned_char
;
7241 encoding
= DW_ATE_signed_char
;
7245 encoding
= DW_ATE_float
;
7248 /* Dwarf2 doesn't know anything about complex ints, so use
7249 a user defined type for it. */
7251 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
7252 encoding
= DW_ATE_complex_float
;
7254 encoding
= DW_ATE_lo_user
;
7258 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7259 encoding
= DW_ATE_boolean
;
7263 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7266 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
);
7267 if (demangle_name_func
)
7268 type_name
= (*demangle_name_func
) (type_name
);
7270 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
7271 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
7272 int_size_in_bytes (type
));
7273 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
7275 return base_type_result
;
7278 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7279 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7280 a given type is generally the same as the given type, except that if the
7281 given type is a pointer or reference type, then the root type of the given
7282 type is the root type of the "basis" type for the pointer or reference
7283 type. (This definition of the "root" type is recursive.) Also, the root
7284 type of a `const' qualified type or a `volatile' qualified type is the
7285 root type of the given type without the qualifiers. */
7291 if (TREE_CODE (type
) == ERROR_MARK
)
7292 return error_mark_node
;
7294 switch (TREE_CODE (type
))
7297 return error_mark_node
;
7300 case REFERENCE_TYPE
:
7301 return type_main_variant (root_type (TREE_TYPE (type
)));
7304 return type_main_variant (type
);
7308 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7309 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7315 switch (TREE_CODE (type
))
7330 case QUAL_UNION_TYPE
:
7335 case REFERENCE_TYPE
:
7349 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7350 entry that chains various modifiers in front of the given type. */
7353 modified_type_die (type
, is_const_type
, is_volatile_type
, context_die
)
7355 register int is_const_type
;
7356 register int is_volatile_type
;
7357 register dw_die_ref context_die
;
7359 register enum tree_code code
= TREE_CODE (type
);
7360 register dw_die_ref mod_type_die
= NULL
;
7361 register dw_die_ref sub_die
= NULL
;
7362 register tree item_type
= NULL
;
7364 if (code
!= ERROR_MARK
)
7366 type
= build_type_variant (type
, is_const_type
, is_volatile_type
);
7368 mod_type_die
= lookup_type_die (type
);
7370 return mod_type_die
;
7372 /* Handle C typedef types. */
7373 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
7374 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
7376 tree dtype
= TREE_TYPE (TYPE_NAME (type
));
7379 /* For a named type, use the typedef. */
7380 gen_type_die (type
, context_die
);
7381 mod_type_die
= lookup_type_die (type
);
7384 else if (is_const_type
< TYPE_READONLY (dtype
)
7385 || is_volatile_type
< TYPE_VOLATILE (dtype
))
7386 /* cv-unqualified version of named type. Just use the unnamed
7387 type to which it refers. */
7389 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)),
7390 is_const_type
, is_volatile_type
,
7392 /* Else cv-qualified version of named type; fall through. */
7398 else if (is_const_type
)
7400 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
);
7401 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
7403 else if (is_volatile_type
)
7405 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
);
7406 sub_die
= modified_type_die (type
, 0, 0, context_die
);
7408 else if (code
== POINTER_TYPE
)
7410 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
);
7411 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7413 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7415 item_type
= TREE_TYPE (type
);
7417 else if (code
== REFERENCE_TYPE
)
7419 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
);
7420 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7422 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7424 item_type
= TREE_TYPE (type
);
7426 else if (is_base_type (type
))
7427 mod_type_die
= base_type_die (type
);
7430 gen_type_die (type
, context_die
);
7432 /* We have to get the type_main_variant here (and pass that to the
7433 `lookup_type_die' routine) because the ..._TYPE node we have
7434 might simply be a *copy* of some original type node (where the
7435 copy was created to help us keep track of typedef names) and
7436 that copy might have a different TYPE_UID from the original
7438 mod_type_die
= lookup_type_die (type_main_variant (type
));
7439 if (mod_type_die
== NULL
)
7444 equate_type_number_to_die (type
, mod_type_die
);
7446 /* We must do this after the equate_type_number_to_die call, in case
7447 this is a recursive type. This ensures that the modified_type_die
7448 recursion will terminate even if the type is recursive. Recursive
7449 types are possible in Ada. */
7450 sub_die
= modified_type_die (item_type
,
7451 TYPE_READONLY (item_type
),
7452 TYPE_VOLATILE (item_type
),
7455 if (sub_die
!= NULL
)
7456 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
7458 return mod_type_die
;
7461 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7462 an enumerated type. */
7468 return TREE_CODE (type
) == ENUMERAL_TYPE
;
7471 /* Return the register number described by a given RTL node. */
7477 register unsigned regno
= REGNO (rtl
);
7479 if (regno
>= FIRST_PSEUDO_REGISTER
)
7481 warning ("internal regno botch: regno = %d\n", regno
);
7485 regno
= DBX_REGISTER_NUMBER (regno
);
7489 /* Return a location descriptor that designates a machine register. */
7491 static dw_loc_descr_ref
7492 reg_loc_descriptor (rtl
)
7495 register dw_loc_descr_ref loc_result
= NULL
;
7496 register unsigned reg
= reg_number (rtl
);
7499 loc_result
= new_loc_descr (DW_OP_reg0
+ reg
, 0, 0);
7501 loc_result
= new_loc_descr (DW_OP_regx
, reg
, 0);
7506 /* Return a location descriptor that designates a constant. */
7508 static dw_loc_descr_ref
7509 int_loc_descriptor (i
)
7512 enum dwarf_location_atom op
;
7514 /* Pick the smallest representation of a constant, rather than just
7515 defaulting to the LEB encoding. */
7519 op
= DW_OP_lit0
+ i
;
7522 else if (i
<= 0xffff)
7524 else if (HOST_BITS_PER_WIDE_INT
== 32
7534 else if (i
>= -0x8000)
7536 else if (HOST_BITS_PER_WIDE_INT
== 32
7537 || i
>= -0x80000000)
7543 return new_loc_descr (op
, i
, 0);
7546 /* Return a location descriptor that designates a base+offset location. */
7548 static dw_loc_descr_ref
7549 based_loc_descr (reg
, offset
)
7553 register dw_loc_descr_ref loc_result
;
7554 /* For the "frame base", we use the frame pointer or stack pointer
7555 registers, since the RTL for local variables is relative to one of
7557 register unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
7558 ? HARD_FRAME_POINTER_REGNUM
7559 : STACK_POINTER_REGNUM
);
7562 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
7564 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
7566 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
7571 /* Return true if this RTL expression describes a base+offset calculation. */
7577 return (GET_CODE (rtl
) == PLUS
7578 && ((GET_CODE (XEXP (rtl
, 0)) == REG
7579 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
7582 /* The following routine converts the RTL for a variable or parameter
7583 (resident in memory) into an equivalent Dwarf representation of a
7584 mechanism for getting the address of that same variable onto the top of a
7585 hypothetical "address evaluation" stack.
7587 When creating memory location descriptors, we are effectively transforming
7588 the RTL for a memory-resident object into its Dwarf postfix expression
7589 equivalent. This routine recursively descends an RTL tree, turning
7590 it into Dwarf postfix code as it goes.
7592 MODE is the mode of the memory reference, needed to handle some
7593 autoincrement addressing modes. */
7595 static dw_loc_descr_ref
7596 mem_loc_descriptor (rtl
, mode
)
7598 enum machine_mode mode
;
7600 dw_loc_descr_ref mem_loc_result
= NULL
;
7601 /* Note that for a dynamically sized array, the location we will generate a
7602 description of here will be the lowest numbered location which is
7603 actually within the array. That's *not* necessarily the same as the
7604 zeroth element of the array. */
7606 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7607 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
7610 switch (GET_CODE (rtl
))
7615 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7616 just fall into the SUBREG code. */
7621 /* The case of a subreg may arise when we have a local (register)
7622 variable or a formal (register) parameter which doesn't quite fill
7623 up an entire register. For now, just assume that it is
7624 legitimate to make the Dwarf info refer to the whole register which
7625 contains the given subreg. */
7626 rtl
= XEXP (rtl
, 0);
7631 /* Whenever a register number forms a part of the description of the
7632 method for calculating the (dynamic) address of a memory resident
7633 object, DWARF rules require the register number be referred to as
7634 a "base register". This distinction is not based in any way upon
7635 what category of register the hardware believes the given register
7636 belongs to. This is strictly DWARF terminology we're dealing with
7637 here. Note that in cases where the location of a memory-resident
7638 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7639 OP_CONST (0)) the actual DWARF location descriptor that we generate
7640 may just be OP_BASEREG (basereg). This may look deceptively like
7641 the object in question was allocated to a register (rather than in
7642 memory) so DWARF consumers need to be aware of the subtle
7643 distinction between OP_REG and OP_BASEREG. */
7644 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
7648 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
7649 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
7653 /* Some ports can transform a symbol ref into a label ref, because
7654 the symbol ref is too far away and has to be dumped into a constant
7658 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
7659 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
7660 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= save_rtx (rtl
);
7664 /* Extract the PLUS expression nested inside and fall into
7665 PLUS code bellow. */
7666 rtl
= XEXP (rtl
, 1);
7671 /* Turn these into a PLUS expression and fall into the PLUS code
7673 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
7674 GEN_INT (GET_CODE (rtl
) == PRE_INC
7675 ? GET_MODE_UNIT_SIZE (mode
)
7676 : -GET_MODE_UNIT_SIZE (mode
)));
7682 if (is_based_loc (rtl
))
7683 mem_loc_result
= based_loc_descr (reg_number (XEXP (rtl
, 0)),
7684 INTVAL (XEXP (rtl
, 1)));
7687 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
7689 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
7690 && INTVAL (XEXP (rtl
, 1)) >= 0)
7692 add_loc_descr (&mem_loc_result
,
7693 new_loc_descr (DW_OP_plus_uconst
,
7694 INTVAL (XEXP (rtl
, 1)), 0));
7698 add_loc_descr (&mem_loc_result
,
7699 mem_loc_descriptor (XEXP (rtl
, 1), mode
));
7700 add_loc_descr (&mem_loc_result
,
7701 new_loc_descr (DW_OP_plus
, 0, 0));
7707 /* If a pseudo-reg is optimized away, it is possible for it to
7708 be replaced with a MEM containing a multiply. */
7709 add_loc_descr (&mem_loc_result
,
7710 mem_loc_descriptor (XEXP (rtl
, 0), mode
));
7711 add_loc_descr (&mem_loc_result
,
7712 mem_loc_descriptor (XEXP (rtl
, 1), mode
));
7713 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
7717 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
7724 return mem_loc_result
;
7727 /* Return a descriptor that describes the concatenation of two locations.
7728 This is typically a complex variable. */
7730 static dw_loc_descr_ref
7731 concat_loc_descriptor (x0
, x1
)
7732 register rtx x0
, x1
;
7734 dw_loc_descr_ref cc_loc_result
= NULL
;
7736 if (!is_pseudo_reg (x0
)
7737 && (GET_CODE (x0
) != MEM
|| !is_pseudo_reg (XEXP (x0
, 0))))
7738 add_loc_descr (&cc_loc_result
, loc_descriptor (x0
));
7739 add_loc_descr (&cc_loc_result
,
7740 new_loc_descr (DW_OP_piece
, GET_MODE_SIZE (GET_MODE (x0
)), 0));
7742 if (!is_pseudo_reg (x1
)
7743 && (GET_CODE (x1
) != MEM
|| !is_pseudo_reg (XEXP (x1
, 0))))
7744 add_loc_descr (&cc_loc_result
, loc_descriptor (x1
));
7745 add_loc_descr (&cc_loc_result
,
7746 new_loc_descr (DW_OP_piece
, GET_MODE_SIZE (GET_MODE (x1
)), 0));
7748 return cc_loc_result
;
7751 /* Output a proper Dwarf location descriptor for a variable or parameter
7752 which is either allocated in a register or in a memory location. For a
7753 register, we just generate an OP_REG and the register number. For a
7754 memory location we provide a Dwarf postfix expression describing how to
7755 generate the (dynamic) address of the object onto the address stack. */
7757 static dw_loc_descr_ref
7758 loc_descriptor (rtl
)
7761 dw_loc_descr_ref loc_result
= NULL
;
7762 switch (GET_CODE (rtl
))
7765 /* The case of a subreg may arise when we have a local (register)
7766 variable or a formal (register) parameter which doesn't quite fill
7767 up an entire register. For now, just assume that it is
7768 legitimate to make the Dwarf info refer to the whole register which
7769 contains the given subreg. */
7770 rtl
= XEXP (rtl
, 0);
7775 loc_result
= reg_loc_descriptor (rtl
);
7779 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
7783 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
7793 /* Similar, but generate the descriptor from trees instead of rtl.
7794 This comes up particularly with variable length arrays. */
7796 static dw_loc_descr_ref
7797 loc_descriptor_from_tree (loc
, addressp
)
7801 dw_loc_descr_ref ret
= NULL
;
7802 int indirect_size
= 0;
7803 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (loc
));
7804 enum dwarf_location_atom op
;
7806 /* ??? Most of the time we do not take proper care for sign/zero
7807 extending the values properly. Hopefully this won't be a real
7810 switch (TREE_CODE (loc
))
7815 case WITH_RECORD_EXPR
:
7816 /* This case involves extracting fields from an object to determine the
7817 position of other fields. We don't try to encode this here. The
7818 only user of this is Ada, which encodes the needed information using
7819 the names of types. */
7825 rtx rtl
= rtl_for_decl_location (loc
);
7826 enum machine_mode mode
= DECL_MODE (loc
);
7828 if (rtl
== NULL_RTX
)
7830 else if (CONSTANT_P (rtl
))
7832 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
7833 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
7834 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
7835 indirect_size
= GET_MODE_SIZE (mode
);
7839 if (GET_CODE (rtl
) == MEM
)
7841 indirect_size
= GET_MODE_SIZE (mode
);
7842 rtl
= XEXP (rtl
, 0);
7844 ret
= mem_loc_descriptor (rtl
, mode
);
7850 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
7851 indirect_size
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc
)));
7856 case NON_LVALUE_EXPR
:
7858 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
);
7865 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
7866 enum machine_mode mode
;
7868 unsigned int alignment
;
7870 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
7871 &unsignedp
, &volatilep
, &alignment
);
7872 ret
= loc_descriptor_from_tree (obj
, 1);
7874 if (offset
!= NULL_TREE
)
7876 /* Variable offset. */
7877 add_loc_descr (&ret
, loc_descriptor_from_tree (offset
, 0));
7878 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
7883 /* We cannot address anything not on a unit boundary. */
7884 if (bitpos
% BITS_PER_UNIT
!= 0)
7889 if (bitpos
% BITS_PER_UNIT
!= 0
7890 || bitsize
% BITS_PER_UNIT
!= 0)
7892 /* ??? We could handle this by loading and shifting etc.
7893 Wait until someone needs it before expending the effort. */
7897 indirect_size
= bitsize
/ BITS_PER_UNIT
;
7900 bytepos
= bitpos
/ BITS_PER_UNIT
;
7902 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
7903 else if (bytepos
< 0)
7905 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
7906 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
7912 if (host_integerp (loc
, 0))
7913 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
7925 case TRUNC_DIV_EXPR
:
7931 case TRUNC_MOD_EXPR
:
7941 op
= (unsignedp
? DW_OP_shr
: DW_OP_shra
);
7944 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
7945 && host_integerp (TREE_OPERAND (loc
, 1), 0))
7947 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
7948 add_loc_descr (&ret
,
7949 new_loc_descr (DW_OP_plus_uconst
,
7950 tree_low_cst (TREE_OPERAND (loc
, 1),
7958 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
7963 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
7968 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
7973 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
7985 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
7986 add_loc_descr (&ret
, loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0));
7987 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8001 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8002 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8006 loc
= build (COND_EXPR
, TREE_TYPE (loc
),
8007 build (LT_EXPR
, integer_type_node
,
8008 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
8009 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
8014 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
8016 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8017 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
8018 add_loc_descr (&ret
, bra_node
);
8020 tmp
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 2), 0);
8021 add_loc_descr (&ret
, tmp
);
8022 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
8023 add_loc_descr (&ret
, jump_node
);
8025 tmp
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8026 add_loc_descr (&ret
, tmp
);
8027 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8028 bra_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
8030 /* ??? Need a node to point the skip at. Use a nop. */
8031 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
8032 add_loc_descr (&ret
, tmp
);
8033 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8034 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
8042 /* If we can't fill the request for an address, die. */
8043 if (addressp
&& indirect_size
== 0)
8046 /* If we've got an address and don't want one, dereference. */
8047 if (!addressp
&& indirect_size
> 0)
8049 if (indirect_size
> DWARF2_ADDR_SIZE
)
8051 if (indirect_size
== DWARF2_ADDR_SIZE
)
8054 op
= DW_OP_deref_size
;
8055 add_loc_descr (&ret
, new_loc_descr (op
, indirect_size
, 0));
8061 /* Given a value, round it up to the lowest multiple of `boundary'
8062 which is not less than the value itself. */
8064 static inline HOST_WIDE_INT
8065 ceiling (value
, boundary
)
8066 HOST_WIDE_INT value
;
8067 unsigned int boundary
;
8069 return (((value
+ boundary
- 1) / boundary
) * boundary
);
8072 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8073 pointer to the declared type for the relevant field variable, or return
8074 `integer_type_node' if the given node turns out to be an
8083 if (TREE_CODE (decl
) == ERROR_MARK
)
8084 return integer_type_node
;
8086 type
= DECL_BIT_FIELD_TYPE (decl
);
8087 if (type
== NULL_TREE
)
8088 type
= TREE_TYPE (decl
);
8093 /* Given a pointer to a tree node, return the alignment in bits for
8094 it, or else return BITS_PER_WORD if the node actually turns out to
8095 be an ERROR_MARK node. */
8097 static inline unsigned
8098 simple_type_align_in_bits (type
)
8101 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
8104 static inline unsigned
8105 simple_decl_align_in_bits (decl
)
8108 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
8111 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8112 node, return the size in bits for the type if it is a constant, or else
8113 return the alignment for the type if the type's size is not constant, or
8114 else return BITS_PER_WORD if the type actually turns out to be an
8117 static inline unsigned HOST_WIDE_INT
8118 simple_type_size_in_bits (type
)
8121 tree type_size_tree
;
8123 if (TREE_CODE (type
) == ERROR_MARK
)
8124 return BITS_PER_WORD
;
8125 type_size_tree
= TYPE_SIZE (type
);
8127 if (type_size_tree
== NULL_TREE
)
8129 if (! host_integerp (type_size_tree
, 1))
8130 return TYPE_ALIGN (type
);
8131 return tree_low_cst (type_size_tree
, 1);
8134 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
8135 return the byte offset of the lowest addressed byte of the "containing
8136 object" for the given FIELD_DECL, or return 0 if we are unable to
8137 determine what that offset is, either because the argument turns out to
8138 be a pointer to an ERROR_MARK node, or because the offset is actually
8139 variable. (We can't handle the latter case just yet). */
8141 static HOST_WIDE_INT
8142 field_byte_offset (decl
)
8145 unsigned int type_align_in_bits
;
8146 unsigned int decl_align_in_bits
;
8147 unsigned HOST_WIDE_INT type_size_in_bits
;
8148 HOST_WIDE_INT object_offset_in_bits
;
8149 HOST_WIDE_INT object_offset_in_bytes
;
8151 tree field_size_tree
;
8152 HOST_WIDE_INT bitpos_int
;
8153 HOST_WIDE_INT deepest_bitpos
;
8154 unsigned HOST_WIDE_INT field_size_in_bits
;
8156 if (TREE_CODE (decl
) == ERROR_MARK
)
8159 if (TREE_CODE (decl
) != FIELD_DECL
)
8162 type
= field_type (decl
);
8163 field_size_tree
= DECL_SIZE (decl
);
8165 /* The size could be unspecified if there was an error, or for
8166 a flexible array member. */
8167 if (! field_size_tree
)
8168 field_size_tree
= bitsize_zero_node
;
8170 /* We cannot yet cope with fields whose positions are variable, so
8171 for now, when we see such things, we simply return 0. Someday, we may
8172 be able to handle such cases, but it will be damn difficult. */
8173 if (! host_integerp (bit_position (decl
), 0))
8176 bitpos_int
= int_bit_position (decl
);
8178 /* If we don't know the size of the field, pretend it's a full word. */
8179 if (host_integerp (field_size_tree
, 1))
8180 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
8182 field_size_in_bits
= BITS_PER_WORD
;
8184 type_size_in_bits
= simple_type_size_in_bits (type
);
8185 type_align_in_bits
= simple_type_align_in_bits (type
);
8186 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
8188 /* Note that the GCC front-end doesn't make any attempt to keep track of
8189 the starting bit offset (relative to the start of the containing
8190 structure type) of the hypothetical "containing object" for a bit-
8191 field. Thus, when computing the byte offset value for the start of the
8192 "containing object" of a bit-field, we must deduce this information on
8193 our own. This can be rather tricky to do in some cases. For example,
8194 handling the following structure type definition when compiling for an
8195 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8198 struct S { int field1; long long field2:31; };
8200 Fortunately, there is a simple rule-of-thumb which can be
8201 used in such cases. When compiling for an i386/i486, GCC will allocate
8202 8 bytes for the structure shown above. It decides to do this based upon
8203 one simple rule for bit-field allocation. Quite simply, GCC allocates
8204 each "containing object" for each bit-field at the first (i.e. lowest
8205 addressed) legitimate alignment boundary (based upon the required
8206 minimum alignment for the declared type of the field) which it can
8207 possibly use, subject to the condition that there is still enough
8208 available space remaining in the containing object (when allocated at
8209 the selected point) to fully accommodate all of the bits of the
8210 bit-field itself. This simple rule makes it obvious why GCC allocates
8211 8 bytes for each object of the structure type shown above. When looking
8212 for a place to allocate the "containing object" for `field2', the
8213 compiler simply tries to allocate a 64-bit "containing object" at each
8214 successive 32-bit boundary (starting at zero) until it finds a place to
8215 allocate that 64- bit field such that at least 31 contiguous (and
8216 previously unallocated) bits remain within that selected 64 bit field.
8217 (As it turns out, for the example above, the compiler finds that it is
8218 OK to allocate the "containing object" 64-bit field at bit-offset zero
8219 within the structure type.) Here we attempt to work backwards from the
8220 limited set of facts we're given, and we try to deduce from those facts,
8221 where GCC must have believed that the containing object started (within
8222 the structure type). The value we deduce is then used (by the callers of
8223 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8224 for fields (both bit-fields and, in the case of DW_AT_location, regular
8227 /* Figure out the bit-distance from the start of the structure to the
8228 "deepest" bit of the bit-field. */
8229 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
8231 /* This is the tricky part. Use some fancy footwork to deduce where the
8232 lowest addressed bit of the containing object must be. */
8233 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8235 /* Round up to type_align by default. This works best for bitfields. */
8236 object_offset_in_bits
+= type_align_in_bits
- 1;
8237 object_offset_in_bits
/= type_align_in_bits
;
8238 object_offset_in_bits
*= type_align_in_bits
;
8240 if (object_offset_in_bits
> bitpos_int
)
8242 /* Sigh, the decl must be packed. */
8243 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8245 /* Round up to decl_align instead. */
8246 object_offset_in_bits
+= decl_align_in_bits
- 1;
8247 object_offset_in_bits
/= decl_align_in_bits
;
8248 object_offset_in_bits
*= decl_align_in_bits
;
8251 object_offset_in_bytes
= object_offset_in_bits
/ BITS_PER_UNIT
;
8253 return object_offset_in_bytes
;
8256 /* The following routines define various Dwarf attributes and any data
8257 associated with them. */
8259 /* Add a location description attribute value to a DIE.
8261 This emits location attributes suitable for whole variables and
8262 whole parameters. Note that the location attributes for struct fields are
8263 generated by the routine `data_member_location_attribute' below. */
8266 add_AT_location_description (die
, attr_kind
, rtl
)
8268 enum dwarf_attribute attr_kind
;
8271 /* Handle a special case. If we are about to output a location descriptor
8272 for a variable or parameter which has been optimized out of existence,
8273 don't do that. A variable which has been optimized out
8274 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8275 Currently, in some rare cases, variables can have DECL_RTL values which
8276 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8277 elsewhere in the compiler. We treat such cases as if the variable(s) in
8278 question had been optimized out of existence. */
8280 if (is_pseudo_reg (rtl
)
8281 || (GET_CODE (rtl
) == MEM
8282 && is_pseudo_reg (XEXP (rtl
, 0)))
8283 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8284 references the internal argument pointer (a pseudo) in a function
8285 where all references to the internal argument pointer were
8286 eliminated via the optimizers. */
8287 || (GET_CODE (rtl
) == MEM
8288 && GET_CODE (XEXP (rtl
, 0)) == PLUS
8289 && is_pseudo_reg (XEXP (XEXP (rtl
, 0), 0)))
8290 || (GET_CODE (rtl
) == CONCAT
8291 && is_pseudo_reg (XEXP (rtl
, 0))
8292 && is_pseudo_reg (XEXP (rtl
, 1))))
8295 add_AT_loc (die
, attr_kind
, loc_descriptor (rtl
));
8298 /* Attach the specialized form of location attribute used for data
8299 members of struct and union types. In the special case of a
8300 FIELD_DECL node which represents a bit-field, the "offset" part
8301 of this special location descriptor must indicate the distance
8302 in bytes from the lowest-addressed byte of the containing struct
8303 or union type to the lowest-addressed byte of the "containing
8304 object" for the bit-field. (See the `field_byte_offset' function
8305 above).. For any given bit-field, the "containing object" is a
8306 hypothetical object (of some integral or enum type) within which
8307 the given bit-field lives. The type of this hypothetical
8308 "containing object" is always the same as the declared type of
8309 the individual bit-field itself (for GCC anyway... the DWARF
8310 spec doesn't actually mandate this). Note that it is the size
8311 (in bytes) of the hypothetical "containing object" which will
8312 be given in the DW_AT_byte_size attribute for this bit-field.
8313 (See the `byte_size_attribute' function below.) It is also used
8314 when calculating the value of the DW_AT_bit_offset attribute.
8315 (See the `bit_offset_attribute' function below). */
8318 add_data_member_location_attribute (die
, decl
)
8319 register dw_die_ref die
;
8322 register unsigned long offset
;
8323 register dw_loc_descr_ref loc_descr
;
8324 register enum dwarf_location_atom op
;
8326 if (TREE_CODE (decl
) == TREE_VEC
)
8327 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
8329 offset
= field_byte_offset (decl
);
8331 /* The DWARF2 standard says that we should assume that the structure address
8332 is already on the stack, so we can specify a structure field address
8333 by using DW_OP_plus_uconst. */
8335 #ifdef MIPS_DEBUGGING_INFO
8336 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8337 correctly. It works only if we leave the offset on the stack. */
8340 op
= DW_OP_plus_uconst
;
8343 loc_descr
= new_loc_descr (op
, offset
, 0);
8344 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
8347 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8348 does not have a "location" either in memory or in a register. These
8349 things can arise in GNU C when a constant is passed as an actual parameter
8350 to an inlined function. They can also arise in C++ where declared
8351 constants do not necessarily get memory "homes". */
8354 add_const_value_attribute (die
, rtl
)
8355 register dw_die_ref die
;
8358 switch (GET_CODE (rtl
))
8361 /* Note that a CONST_INT rtx could represent either an integer or a
8362 floating-point constant. A CONST_INT is used whenever the constant
8363 will fit into a single word. In all such cases, the original mode
8364 of the constant value is wiped out, and the CONST_INT rtx is
8365 assigned VOIDmode. */
8366 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned) INTVAL (rtl
));
8370 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8371 floating-point constant. A CONST_DOUBLE is used whenever the
8372 constant requires more than one word in order to be adequately
8373 represented. We output CONST_DOUBLEs as blocks. */
8375 register enum machine_mode mode
= GET_MODE (rtl
);
8377 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
8379 register unsigned length
= GET_MODE_SIZE (mode
) / 4;
8380 long *array
= (long *) xmalloc (sizeof (long) * length
);
8383 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
8387 REAL_VALUE_TO_TARGET_SINGLE (rv
, array
[0]);
8391 REAL_VALUE_TO_TARGET_DOUBLE (rv
, array
);
8396 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv
, array
);
8403 add_AT_float (die
, DW_AT_const_value
, length
, array
);
8406 add_AT_long_long (die
, DW_AT_const_value
,
8407 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
8412 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
8418 add_AT_addr (die
, DW_AT_const_value
, save_rtx (rtl
));
8422 /* In cases where an inlined instance of an inline function is passed
8423 the address of an `auto' variable (which is local to the caller) we
8424 can get a situation where the DECL_RTL of the artificial local
8425 variable (for the inlining) which acts as a stand-in for the
8426 corresponding formal parameter (of the inline function) will look
8427 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8428 exactly a compile-time constant expression, but it isn't the address
8429 of the (artificial) local variable either. Rather, it represents the
8430 *value* which the artificial local variable always has during its
8431 lifetime. We currently have no way to represent such quasi-constant
8432 values in Dwarf, so for now we just punt and generate nothing. */
8436 /* No other kinds of rtx should be possible here. */
8443 rtl_for_decl_location (decl
)
8448 /* Here we have to decide where we are going to say the parameter "lives"
8449 (as far as the debugger is concerned). We only have a couple of
8450 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8452 DECL_RTL normally indicates where the parameter lives during most of the
8453 activation of the function. If optimization is enabled however, this
8454 could be either NULL or else a pseudo-reg. Both of those cases indicate
8455 that the parameter doesn't really live anywhere (as far as the code
8456 generation parts of GCC are concerned) during most of the function's
8457 activation. That will happen (for example) if the parameter is never
8458 referenced within the function.
8460 We could just generate a location descriptor here for all non-NULL
8461 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8462 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8463 where DECL_RTL is NULL or is a pseudo-reg.
8465 Note however that we can only get away with using DECL_INCOMING_RTL as
8466 a backup substitute for DECL_RTL in certain limited cases. In cases
8467 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8468 we can be sure that the parameter was passed using the same type as it is
8469 declared to have within the function, and that its DECL_INCOMING_RTL
8470 points us to a place where a value of that type is passed.
8472 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8473 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8474 because in these cases DECL_INCOMING_RTL points us to a value of some
8475 type which is *different* from the type of the parameter itself. Thus,
8476 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8477 such cases, the debugger would end up (for example) trying to fetch a
8478 `float' from a place which actually contains the first part of a
8479 `double'. That would lead to really incorrect and confusing
8480 output at debug-time.
8482 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8483 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8484 are a couple of exceptions however. On little-endian machines we can
8485 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8486 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8487 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8488 when (on a little-endian machine) a non-prototyped function has a
8489 parameter declared to be of type `short' or `char'. In such cases,
8490 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8491 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8492 passed `int' value. If the debugger then uses that address to fetch
8493 a `short' or a `char' (on a little-endian machine) the result will be
8494 the correct data, so we allow for such exceptional cases below.
8496 Note that our goal here is to describe the place where the given formal
8497 parameter lives during most of the function's activation (i.e. between
8498 the end of the prologue and the start of the epilogue). We'll do that
8499 as best as we can. Note however that if the given formal parameter is
8500 modified sometime during the execution of the function, then a stack
8501 backtrace (at debug-time) will show the function as having been
8502 called with the *new* value rather than the value which was
8503 originally passed in. This happens rarely enough that it is not
8504 a major problem, but it *is* a problem, and I'd like to fix it.
8506 A future version of dwarf2out.c may generate two additional
8507 attributes for any given DW_TAG_formal_parameter DIE which will
8508 describe the "passed type" and the "passed location" for the
8509 given formal parameter in addition to the attributes we now
8510 generate to indicate the "declared type" and the "active
8511 location" for each parameter. This additional set of attributes
8512 could be used by debuggers for stack backtraces. Separately, note
8513 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8514 NULL also. This happens (for example) for inlined-instances of
8515 inline function formal parameters which are never referenced.
8516 This really shouldn't be happening. All PARM_DECL nodes should
8517 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8518 doesn't currently generate these values for inlined instances of
8519 inline function parameters, so when we see such cases, we are
8520 just out-of-luck for the time being (until integrate.c
8523 /* Use DECL_RTL as the "location" unless we find something better. */
8524 rtl
= DECL_RTL (decl
);
8526 if (TREE_CODE (decl
) == PARM_DECL
)
8528 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
8530 tree declared_type
= type_main_variant (TREE_TYPE (decl
));
8531 tree passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
8533 /* This decl represents a formal parameter which was optimized out.
8534 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8535 all* cases where (rtl == NULL_RTX) just below. */
8536 if (declared_type
== passed_type
)
8537 rtl
= DECL_INCOMING_RTL (decl
);
8538 else if (! BYTES_BIG_ENDIAN
8539 && TREE_CODE (declared_type
) == INTEGER_TYPE
8540 && (GET_MODE_SIZE (TYPE_MODE (declared_type
))
8541 <= GET_MODE_SIZE (TYPE_MODE (passed_type
))))
8542 rtl
= DECL_INCOMING_RTL (decl
);
8545 /* If the parm was passed in registers, but lives on the stack, then
8546 make a big endian correction if the mode of the type of the
8547 parameter is not the same as the mode of the rtl. */
8548 /* ??? This is the same series of checks that are made in dbxout.c before
8549 we reach the big endian correction code there. It isn't clear if all
8550 of these checks are necessary here, but keeping them all is the safe
8552 else if (GET_CODE (rtl
) == MEM
8553 && XEXP (rtl
, 0) != const0_rtx
8554 && ! CONSTANT_P (XEXP (rtl
, 0))
8555 /* Not passed in memory. */
8556 && GET_CODE (DECL_INCOMING_RTL (decl
)) != MEM
8557 /* Not passed by invisible reference. */
8558 && (GET_CODE (XEXP (rtl
, 0)) != REG
8559 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
8560 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
8561 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8562 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
8565 /* Big endian correction check. */
8567 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
8568 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
8571 int offset
= (UNITS_PER_WORD
8572 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
8573 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
8574 plus_constant (XEXP (rtl
, 0), offset
));
8578 if (rtl
!= NULL_RTX
)
8580 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
8581 #ifdef LEAF_REG_REMAP
8582 if (current_function_uses_only_leaf_regs
)
8583 leaf_renumber_regs_insn (rtl
);
8590 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8591 data attribute for a variable or a parameter. We generate the
8592 DW_AT_const_value attribute only in those cases where the given variable
8593 or parameter does not have a true "location" either in memory or in a
8594 register. This can happen (for example) when a constant is passed as an
8595 actual argument in a call to an inline function. (It's possible that
8596 these things can crop up in other ways also.) Note that one type of
8597 constant value which can be passed into an inlined function is a constant
8598 pointer. This can happen for example if an actual argument in an inlined
8599 function call evaluates to a compile-time constant address. */
8602 add_location_or_const_value_attribute (die
, decl
)
8603 register dw_die_ref die
;
8608 if (TREE_CODE (decl
) == ERROR_MARK
)
8611 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
)
8614 rtl
= rtl_for_decl_location (decl
);
8615 if (rtl
== NULL_RTX
)
8618 switch (GET_CODE (rtl
))
8621 /* The address of a variable that was optimized away; don't emit
8632 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8633 add_const_value_attribute (die
, rtl
);
8640 add_AT_location_description (die
, DW_AT_location
, rtl
);
8648 /* If we don't have a copy of this variable in memory for some reason (such
8649 as a C++ member constant that doesn't have an out-of-line definition),
8650 we should tell the debugger about the constant value. */
8653 tree_add_const_value_attribute (var_die
, decl
)
8657 tree init
= DECL_INITIAL (decl
);
8658 tree type
= TREE_TYPE (decl
);
8660 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
8661 && initializer_constant_valid_p (init
, type
) == null_pointer_node
)
8666 switch (TREE_CODE (type
))
8669 if (host_integerp (init
, 0))
8670 add_AT_unsigned (var_die
, DW_AT_const_value
,
8671 TREE_INT_CST_LOW (init
));
8673 add_AT_long_long (var_die
, DW_AT_const_value
,
8674 TREE_INT_CST_HIGH (init
),
8675 TREE_INT_CST_LOW (init
));
8682 /* Generate an DW_AT_name attribute given some string value to be included as
8683 the value of the attribute. */
8686 add_name_attribute (die
, name_string
)
8687 register dw_die_ref die
;
8688 register const char *name_string
;
8690 if (name_string
!= NULL
&& *name_string
!= 0)
8692 if (demangle_name_func
)
8693 name_string
= (*demangle_name_func
) (name_string
);
8695 add_AT_string (die
, DW_AT_name
, name_string
);
8699 /* Given a tree node describing an array bound (either lower or upper) output
8700 a representation for that bound. */
8703 add_bound_info (subrange_die
, bound_attr
, bound
)
8704 register dw_die_ref subrange_die
;
8705 register enum dwarf_attribute bound_attr
;
8706 register tree bound
;
8708 /* If this is an Ada unconstrained array type, then don't emit any debug
8709 info because the array bounds are unknown. They are parameterized when
8710 the type is instantiated. */
8711 if (contains_placeholder_p (bound
))
8714 switch (TREE_CODE (bound
))
8719 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8721 if (! host_integerp (bound
, 0)
8722 || (bound_attr
== DW_AT_lower_bound
8723 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
8724 || (is_fortran () && integer_onep (bound
)))))
8725 /* use the default */
8728 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
8733 case NON_LVALUE_EXPR
:
8734 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
8738 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8739 access the upper bound values may be bogus. If they refer to a
8740 register, they may only describe how to get at these values at the
8741 points in the generated code right after they have just been
8742 computed. Worse yet, in the typical case, the upper bound values
8743 will not even *be* computed in the optimized code (though the
8744 number of elements will), so these SAVE_EXPRs are entirely
8745 bogus. In order to compensate for this fact, we check here to see
8746 if optimization is enabled, and if so, we don't add an attribute
8747 for the (unknown and unknowable) upper bound. This should not
8748 cause too much trouble for existing (stupid?) debuggers because
8749 they have to deal with empty upper bounds location descriptions
8750 anyway in order to be able to deal with incomplete array types.
8751 Of course an intelligent debugger (GDB?) should be able to
8752 comprehend that a missing upper bound specification in a array
8753 type used for a storage class `auto' local array variable
8754 indicates that the upper bound is both unknown (at compile- time)
8755 and unknowable (at run-time) due to optimization.
8757 We assume that a MEM rtx is safe because gcc wouldn't put the
8758 value there unless it was going to be used repeatedly in the
8759 function, i.e. for cleanups. */
8760 if (! optimize
|| (SAVE_EXPR_RTL (bound
)
8761 && GET_CODE (SAVE_EXPR_RTL (bound
)) == MEM
))
8763 register dw_die_ref ctx
= lookup_decl_die (current_function_decl
);
8764 register dw_die_ref decl_die
= new_die (DW_TAG_variable
, ctx
);
8765 register rtx loc
= SAVE_EXPR_RTL (bound
);
8767 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8768 it references an outer function's frame. */
8770 if (GET_CODE (loc
) == MEM
)
8772 rtx new_addr
= fix_lexical_addr (XEXP (loc
, 0), bound
);
8774 if (XEXP (loc
, 0) != new_addr
)
8775 loc
= gen_rtx_MEM (GET_MODE (loc
), new_addr
);
8778 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
8779 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
8780 add_AT_location_description (decl_die
, DW_AT_location
, loc
);
8781 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
8784 /* Else leave out the attribute. */
8790 dw_die_ref decl_die
= lookup_decl_die (bound
);
8792 /* ??? Can this happen, or should the variable have been bound
8793 first? Probably it can, since I imagine that we try to create
8794 the types of parameters in the order in which they exist in
8795 the list, and won't have created a forward reference to a
8797 if (decl_die
!= NULL
)
8798 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
8804 /* Otherwise try to create a stack operation procedure to
8805 evaluate the value of the array bound. */
8807 dw_die_ref ctx
, decl_die
;
8808 dw_loc_descr_ref loc
;
8810 loc
= loc_descriptor_from_tree (bound
, 0);
8814 ctx
= lookup_decl_die (current_function_decl
);
8816 decl_die
= new_die (DW_TAG_variable
, ctx
);
8817 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
8818 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
8819 add_AT_loc (decl_die
, DW_AT_location
, loc
);
8821 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
8827 /* Note that the block of subscript information for an array type also
8828 includes information about the element type of type given array type. */
8831 add_subscript_info (type_die
, type
)
8832 register dw_die_ref type_die
;
8835 #ifndef MIPS_DEBUGGING_INFO
8836 register unsigned dimension_number
;
8838 register tree lower
, upper
;
8839 register dw_die_ref subrange_die
;
8841 /* The GNU compilers represent multidimensional array types as sequences of
8842 one dimensional array types whose element types are themselves array
8843 types. Here we squish that down, so that each multidimensional array
8844 type gets only one array_type DIE in the Dwarf debugging info. The draft
8845 Dwarf specification say that we are allowed to do this kind of
8846 compression in C (because there is no difference between an array or
8847 arrays and a multidimensional array in C) but for other source languages
8848 (e.g. Ada) we probably shouldn't do this. */
8850 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8851 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8852 We work around this by disabling this feature. See also
8853 gen_array_type_die. */
8854 #ifndef MIPS_DEBUGGING_INFO
8855 for (dimension_number
= 0;
8856 TREE_CODE (type
) == ARRAY_TYPE
;
8857 type
= TREE_TYPE (type
), dimension_number
++)
8860 register tree domain
= TYPE_DOMAIN (type
);
8862 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8863 and (in GNU C only) variable bounds. Handle all three forms
8865 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
);
8868 /* We have an array type with specified bounds. */
8869 lower
= TYPE_MIN_VALUE (domain
);
8870 upper
= TYPE_MAX_VALUE (domain
);
8872 /* define the index type. */
8873 if (TREE_TYPE (domain
))
8875 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8876 TREE_TYPE field. We can't emit debug info for this
8877 because it is an unnamed integral type. */
8878 if (TREE_CODE (domain
) == INTEGER_TYPE
8879 && TYPE_NAME (domain
) == NULL_TREE
8880 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
8881 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
8884 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
8888 /* ??? If upper is NULL, the array has unspecified length,
8889 but it does have a lower bound. This happens with Fortran
8891 Since the debugger is definitely going to need to know N
8892 to produce useful results, go ahead and output the lower
8893 bound solo, and hope the debugger can cope. */
8895 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
8897 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
8900 /* We have an array type with an unspecified length. The DWARF-2
8901 spec does not say how to handle this; let's just leave out the
8905 #ifndef MIPS_DEBUGGING_INFO
8911 add_byte_size_attribute (die
, tree_node
)
8913 register tree tree_node
;
8915 register unsigned size
;
8917 switch (TREE_CODE (tree_node
))
8925 case QUAL_UNION_TYPE
:
8926 size
= int_size_in_bytes (tree_node
);
8929 /* For a data member of a struct or union, the DW_AT_byte_size is
8930 generally given as the number of bytes normally allocated for an
8931 object of the *declared* type of the member itself. This is true
8932 even for bit-fields. */
8933 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
8939 /* Note that `size' might be -1 when we get to this point. If it is, that
8940 indicates that the byte size of the entity in question is variable. We
8941 have no good way of expressing this fact in Dwarf at the present time,
8942 so just let the -1 pass on through. */
8944 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
8947 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8948 which specifies the distance in bits from the highest order bit of the
8949 "containing object" for the bit-field to the highest order bit of the
8952 For any given bit-field, the "containing object" is a hypothetical
8953 object (of some integral or enum type) within which the given bit-field
8954 lives. The type of this hypothetical "containing object" is always the
8955 same as the declared type of the individual bit-field itself. The
8956 determination of the exact location of the "containing object" for a
8957 bit-field is rather complicated. It's handled by the
8958 `field_byte_offset' function (above).
8960 Note that it is the size (in bytes) of the hypothetical "containing object"
8961 which will be given in the DW_AT_byte_size attribute for this bit-field.
8962 (See `byte_size_attribute' above). */
8965 add_bit_offset_attribute (die
, decl
)
8966 register dw_die_ref die
;
8969 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
8970 tree type
= DECL_BIT_FIELD_TYPE (decl
);
8971 HOST_WIDE_INT bitpos_int
;
8972 HOST_WIDE_INT highest_order_object_bit_offset
;
8973 HOST_WIDE_INT highest_order_field_bit_offset
;
8974 HOST_WIDE_INT
unsigned bit_offset
;
8976 /* Must be a field and a bit field. */
8978 || TREE_CODE (decl
) != FIELD_DECL
)
8981 /* We can't yet handle bit-fields whose offsets are variable, so if we
8982 encounter such things, just return without generating any attribute
8983 whatsoever. Likewise for variable or too large size. */
8984 if (! host_integerp (bit_position (decl
), 0)
8985 || ! host_integerp (DECL_SIZE (decl
), 1))
8988 bitpos_int
= int_bit_position (decl
);
8990 /* Note that the bit offset is always the distance (in bits) from the
8991 highest-order bit of the "containing object" to the highest-order bit of
8992 the bit-field itself. Since the "high-order end" of any object or field
8993 is different on big-endian and little-endian machines, the computation
8994 below must take account of these differences. */
8995 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
8996 highest_order_field_bit_offset
= bitpos_int
;
8998 if (! BYTES_BIG_ENDIAN
)
9000 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
9001 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
9005 = (! BYTES_BIG_ENDIAN
9006 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
9007 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
9009 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
9012 /* For a FIELD_DECL node which represents a bit field, output an attribute
9013 which specifies the length in bits of the given field. */
9016 add_bit_size_attribute (die
, decl
)
9017 register dw_die_ref die
;
9020 /* Must be a field and a bit field. */
9021 if (TREE_CODE (decl
) != FIELD_DECL
9022 || ! DECL_BIT_FIELD_TYPE (decl
))
9025 if (host_integerp (DECL_SIZE (decl
), 1))
9026 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
9029 /* If the compiled language is ANSI C, then add a 'prototyped'
9030 attribute, if arg types are given for the parameters of a function. */
9033 add_prototyped_attribute (die
, func_type
)
9034 register dw_die_ref die
;
9035 register tree func_type
;
9037 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
9038 && TYPE_ARG_TYPES (func_type
) != NULL
)
9039 add_AT_flag (die
, DW_AT_prototyped
, 1);
9042 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9043 by looking in either the type declaration or object declaration
9047 add_abstract_origin_attribute (die
, origin
)
9048 register dw_die_ref die
;
9049 register tree origin
;
9051 dw_die_ref origin_die
= NULL
;
9053 if (TREE_CODE (origin
) != FUNCTION_DECL
)
9055 /* We may have gotten separated from the block for the inlined
9056 function, if we're in an exception handler or some such; make
9057 sure that the abstract function has been written out.
9059 Doing this for nested functions is wrong, however; functions are
9060 distinct units, and our context might not even be inline. */
9063 fn
= TYPE_STUB_DECL (fn
);
9064 fn
= decl_function_context (fn
);
9066 gen_abstract_function (fn
);
9069 if (DECL_P (origin
))
9070 origin_die
= lookup_decl_die (origin
);
9071 else if (TYPE_P (origin
))
9072 origin_die
= lookup_type_die (origin
);
9074 if (origin_die
== NULL
)
9077 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
9080 /* We do not currently support the pure_virtual attribute. */
9083 add_pure_or_virtual_attribute (die
, func_decl
)
9084 register dw_die_ref die
;
9085 register tree func_decl
;
9087 if (DECL_VINDEX (func_decl
))
9089 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
9091 if (host_integerp (DECL_VINDEX (func_decl
), 0))
9092 add_AT_loc (die
, DW_AT_vtable_elem_location
,
9093 new_loc_descr (DW_OP_constu
,
9094 tree_low_cst (DECL_VINDEX (func_decl
), 0),
9097 /* GNU extension: Record what type this method came from originally. */
9098 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9099 add_AT_die_ref (die
, DW_AT_containing_type
,
9100 lookup_type_die (DECL_CONTEXT (func_decl
)));
9104 /* Add source coordinate attributes for the given decl. */
9107 add_src_coords_attributes (die
, decl
)
9108 register dw_die_ref die
;
9111 register unsigned file_index
= lookup_filename (&decl_file_table
,
9112 DECL_SOURCE_FILE (decl
));
9114 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
9115 add_AT_unsigned (die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
9118 /* Add an DW_AT_name attribute and source coordinate attribute for the
9119 given decl, but only if it actually has a name. */
9122 add_name_and_src_coords_attributes (die
, decl
)
9123 register dw_die_ref die
;
9126 register tree decl_name
;
9128 decl_name
= DECL_NAME (decl
);
9129 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
9131 add_name_attribute (die
, dwarf2_name (decl
, 0));
9132 if (! DECL_ARTIFICIAL (decl
))
9133 add_src_coords_attributes (die
, decl
);
9135 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
9136 && TREE_PUBLIC (decl
)
9137 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
9138 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
9139 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
9143 /* Push a new declaration scope. */
9146 push_decl_scope (scope
)
9149 /* Make room in the decl_scope_table, if necessary. */
9150 if (decl_scope_table_allocated
== decl_scope_depth
)
9152 decl_scope_table_allocated
+= DECL_SCOPE_TABLE_INCREMENT
;
9154 = (tree
*) xrealloc (decl_scope_table
,
9155 decl_scope_table_allocated
* sizeof (tree
));
9158 decl_scope_table
[decl_scope_depth
] = scope
;
9162 /* Pop a declaration scope. */
9166 if (decl_scope_depth
<= 0)
9171 /* Return the DIE for the scope that immediately contains this type.
9172 Non-named types get global scope. Named types nested in other
9173 types get their containing scope if it's open, or global scope
9174 otherwise. All other types (i.e. function-local named types) get
9175 the current active scope. */
9178 scope_die_for (t
, context_die
)
9180 register dw_die_ref context_die
;
9182 register dw_die_ref scope_die
= NULL
;
9183 register tree containing_scope
;
9186 /* Non-types always go in the current scope. */
9190 containing_scope
= TYPE_CONTEXT (t
);
9192 /* Ignore namespaces for the moment. */
9193 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
9194 containing_scope
= NULL_TREE
;
9196 /* Ignore function type "scopes" from the C frontend. They mean that
9197 a tagged type is local to a parmlist of a function declarator, but
9198 that isn't useful to DWARF. */
9199 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
9200 containing_scope
= NULL_TREE
;
9202 if (containing_scope
== NULL_TREE
)
9203 scope_die
= comp_unit_die
;
9204 else if (TYPE_P (containing_scope
))
9206 /* For types, we can just look up the appropriate DIE. But
9207 first we check to see if we're in the middle of emitting it
9208 so we know where the new DIE should go. */
9210 for (i
= decl_scope_depth
- 1; i
>= 0; --i
)
9211 if (decl_scope_table
[i
] == containing_scope
)
9216 if (debug_info_level
> DINFO_LEVEL_TERSE
9217 && !TREE_ASM_WRITTEN (containing_scope
))
9220 /* If none of the current dies are suitable, we get file scope. */
9221 scope_die
= comp_unit_die
;
9224 scope_die
= lookup_type_die (containing_scope
);
9227 scope_die
= context_die
;
9232 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9234 static inline int local_scope_p
PARAMS ((dw_die_ref
));
9236 local_scope_p (context_die
)
9237 dw_die_ref context_die
;
9239 for (; context_die
; context_die
= context_die
->die_parent
)
9240 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
9241 || context_die
->die_tag
== DW_TAG_subprogram
)
9246 /* Returns nonzero iff CONTEXT_DIE is a class. */
9248 static inline int class_scope_p
PARAMS ((dw_die_ref
));
9250 class_scope_p (context_die
)
9251 dw_die_ref context_die
;
9254 && (context_die
->die_tag
== DW_TAG_structure_type
9255 || context_die
->die_tag
== DW_TAG_union_type
));
9258 /* Many forms of DIEs require a "type description" attribute. This
9259 routine locates the proper "type descriptor" die for the type given
9260 by 'type', and adds an DW_AT_type attribute below the given die. */
9263 add_type_attribute (object_die
, type
, decl_const
, decl_volatile
, context_die
)
9264 register dw_die_ref object_die
;
9266 register int decl_const
;
9267 register int decl_volatile
;
9268 register dw_die_ref context_die
;
9270 register enum tree_code code
= TREE_CODE (type
);
9271 register dw_die_ref type_die
= NULL
;
9273 /* ??? If this type is an unnamed subrange type of an integral or
9274 floating-point type, use the inner type. This is because we have no
9275 support for unnamed types in base_type_die. This can happen if this is
9276 an Ada subrange type. Correct solution is emit a subrange type die. */
9277 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
9278 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
9279 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
9281 if (code
== ERROR_MARK
)
9284 /* Handle a special case. For functions whose return type is void, we
9285 generate *no* type attribute. (Note that no object may have type
9286 `void', so this only applies to function return types). */
9287 if (code
== VOID_TYPE
)
9290 type_die
= modified_type_die (type
,
9291 decl_const
|| TYPE_READONLY (type
),
9292 decl_volatile
|| TYPE_VOLATILE (type
),
9294 if (type_die
!= NULL
)
9295 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
9298 /* Given a tree pointer to a struct, class, union, or enum type node, return
9299 a pointer to the (string) tag name for the given type, or zero if the type
9300 was declared without a tag. */
9306 register const char *name
= 0;
9308 if (TYPE_NAME (type
) != 0)
9310 register tree t
= 0;
9312 /* Find the IDENTIFIER_NODE for the type name. */
9313 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
9314 t
= TYPE_NAME (type
);
9316 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9317 a TYPE_DECL node, regardless of whether or not a `typedef' was
9319 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9320 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
9321 t
= DECL_NAME (TYPE_NAME (type
));
9323 /* Now get the name as a string, or invent one. */
9325 name
= IDENTIFIER_POINTER (t
);
9328 return (name
== 0 || *name
== '\0') ? 0 : name
;
9331 /* Return the type associated with a data member, make a special check
9332 for bit field types. */
9335 member_declared_type (member
)
9336 register tree member
;
9338 return (DECL_BIT_FIELD_TYPE (member
)
9339 ? DECL_BIT_FIELD_TYPE (member
)
9340 : TREE_TYPE (member
));
9343 /* Get the decl's label, as described by its RTL. This may be different
9344 from the DECL_NAME name used in the source file. */
9348 decl_start_label (decl
)
9353 x
= DECL_RTL (decl
);
9354 if (GET_CODE (x
) != MEM
)
9358 if (GET_CODE (x
) != SYMBOL_REF
)
9361 fnname
= XSTR (x
, 0);
9366 /* These routines generate the internal representation of the DIE's for
9367 the compilation unit. Debugging information is collected by walking
9368 the declaration trees passed in from dwarf2out_decl(). */
9371 gen_array_type_die (type
, context_die
)
9373 register dw_die_ref context_die
;
9375 register dw_die_ref scope_die
= scope_die_for (type
, context_die
);
9376 register dw_die_ref array_die
;
9377 register tree element_type
;
9379 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9380 the inner array type comes before the outer array type. Thus we must
9381 call gen_type_die before we call new_die. See below also. */
9382 #ifdef MIPS_DEBUGGING_INFO
9383 gen_type_die (TREE_TYPE (type
), context_die
);
9386 array_die
= new_die (DW_TAG_array_type
, scope_die
);
9389 /* We default the array ordering. SDB will probably do
9390 the right things even if DW_AT_ordering is not present. It's not even
9391 an issue until we start to get into multidimensional arrays anyway. If
9392 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9393 then we'll have to put the DW_AT_ordering attribute back in. (But if
9394 and when we find out that we need to put these in, we will only do so
9395 for multidimensional arrays. */
9396 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
9399 #ifdef MIPS_DEBUGGING_INFO
9400 /* The SGI compilers handle arrays of unknown bound by setting
9401 AT_declaration and not emitting any subrange DIEs. */
9402 if (! TYPE_DOMAIN (type
))
9403 add_AT_unsigned (array_die
, DW_AT_declaration
, 1);
9406 add_subscript_info (array_die
, type
);
9408 add_name_attribute (array_die
, type_tag (type
));
9409 equate_type_number_to_die (type
, array_die
);
9411 /* Add representation of the type of the elements of this array type. */
9412 element_type
= TREE_TYPE (type
);
9414 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9415 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9416 We work around this by disabling this feature. See also
9417 add_subscript_info. */
9418 #ifndef MIPS_DEBUGGING_INFO
9419 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
9420 element_type
= TREE_TYPE (element_type
);
9422 gen_type_die (element_type
, context_die
);
9425 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
9429 gen_set_type_die (type
, context_die
)
9431 register dw_die_ref context_die
;
9433 register dw_die_ref type_die
9434 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
));
9436 equate_type_number_to_die (type
, type_die
);
9437 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
9442 gen_entry_point_die (decl
, context_die
)
9444 register dw_die_ref context_die
;
9446 register tree origin
= decl_ultimate_origin (decl
);
9447 register dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
);
9449 add_abstract_origin_attribute (decl_die
, origin
);
9452 add_name_and_src_coords_attributes (decl_die
, decl
);
9453 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
9457 if (DECL_ABSTRACT (decl
))
9458 equate_decl_number_to_die (decl
, decl_die
);
9460 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
9464 /* Remember a type in the incomplete_types_list. */
9467 add_incomplete_type (type
)
9470 if (incomplete_types
== incomplete_types_allocated
)
9472 incomplete_types_allocated
+= INCOMPLETE_TYPES_INCREMENT
;
9473 incomplete_types_list
9474 = (tree
*) xrealloc (incomplete_types_list
,
9475 sizeof (tree
) * incomplete_types_allocated
);
9478 incomplete_types_list
[incomplete_types
++] = type
;
9481 /* Walk through the list of incomplete types again, trying once more to
9482 emit full debugging info for them. */
9485 retry_incomplete_types ()
9489 while (incomplete_types
)
9492 type
= incomplete_types_list
[incomplete_types
];
9493 gen_type_die (type
, comp_unit_die
);
9497 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9500 gen_inlined_enumeration_type_die (type
, context_die
)
9502 register dw_die_ref context_die
;
9504 register dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
,
9506 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9507 be incomplete and such types are not marked. */
9508 add_abstract_origin_attribute (type_die
, type
);
9511 /* Generate a DIE to represent an inlined instance of a structure type. */
9514 gen_inlined_structure_type_die (type
, context_die
)
9516 register dw_die_ref context_die
;
9518 register dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
);
9520 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9521 be incomplete and such types are not marked. */
9522 add_abstract_origin_attribute (type_die
, type
);
9525 /* Generate a DIE to represent an inlined instance of a union type. */
9528 gen_inlined_union_type_die (type
, context_die
)
9530 register dw_die_ref context_die
;
9532 register dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
);
9534 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9535 be incomplete and such types are not marked. */
9536 add_abstract_origin_attribute (type_die
, type
);
9539 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9540 include all of the information about the enumeration values also. Each
9541 enumerated type name/value is listed as a child of the enumerated type
9545 gen_enumeration_type_die (type
, context_die
)
9547 register dw_die_ref context_die
;
9549 register dw_die_ref type_die
= lookup_type_die (type
);
9551 if (type_die
== NULL
)
9553 type_die
= new_die (DW_TAG_enumeration_type
,
9554 scope_die_for (type
, context_die
));
9555 equate_type_number_to_die (type
, type_die
);
9556 add_name_attribute (type_die
, type_tag (type
));
9558 else if (! TYPE_SIZE (type
))
9561 remove_AT (type_die
, DW_AT_declaration
);
9563 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9564 given enum type is incomplete, do not generate the DW_AT_byte_size
9565 attribute or the DW_AT_element_list attribute. */
9566 if (TYPE_SIZE (type
))
9570 TREE_ASM_WRITTEN (type
) = 1;
9571 add_byte_size_attribute (type_die
, type
);
9572 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
9573 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
9575 /* If the first reference to this type was as the return type of an
9576 inline function, then it may not have a parent. Fix this now. */
9577 if (type_die
->die_parent
== NULL
)
9578 add_child_die (scope_die_for (type
, context_die
), type_die
);
9580 for (link
= TYPE_FIELDS (type
);
9581 link
!= NULL
; link
= TREE_CHAIN (link
))
9583 register dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
);
9585 add_name_attribute (enum_die
,
9586 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
9588 if (host_integerp (TREE_VALUE (link
), 0))
9590 if (tree_int_cst_sgn (TREE_VALUE (link
)) < 0)
9591 add_AT_int (enum_die
, DW_AT_const_value
,
9592 tree_low_cst (TREE_VALUE (link
), 0));
9594 add_AT_unsigned (enum_die
, DW_AT_const_value
,
9595 tree_low_cst (TREE_VALUE (link
), 0));
9600 add_AT_flag (type_die
, DW_AT_declaration
, 1);
9603 /* Generate a DIE to represent either a real live formal parameter decl or to
9604 represent just the type of some formal parameter position in some function
9607 Note that this routine is a bit unusual because its argument may be a
9608 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9609 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9610 node. If it's the former then this function is being called to output a
9611 DIE to represent a formal parameter object (or some inlining thereof). If
9612 it's the latter, then this function is only being called to output a
9613 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9614 argument type of some subprogram type. */
9617 gen_formal_parameter_die (node
, context_die
)
9619 register dw_die_ref context_die
;
9621 register dw_die_ref parm_die
9622 = new_die (DW_TAG_formal_parameter
, context_die
);
9623 register tree origin
;
9625 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
9628 origin
= decl_ultimate_origin (node
);
9630 add_abstract_origin_attribute (parm_die
, origin
);
9633 add_name_and_src_coords_attributes (parm_die
, node
);
9634 add_type_attribute (parm_die
, TREE_TYPE (node
),
9635 TREE_READONLY (node
),
9636 TREE_THIS_VOLATILE (node
),
9638 if (DECL_ARTIFICIAL (node
))
9639 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
9642 equate_decl_number_to_die (node
, parm_die
);
9643 if (! DECL_ABSTRACT (node
))
9644 add_location_or_const_value_attribute (parm_die
, node
);
9649 /* We were called with some kind of a ..._TYPE node. */
9650 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
9660 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9661 at the end of an (ANSI prototyped) formal parameters list. */
9664 gen_unspecified_parameters_die (decl_or_type
, context_die
)
9665 register tree decl_or_type ATTRIBUTE_UNUSED
;
9666 register dw_die_ref context_die
;
9668 new_die (DW_TAG_unspecified_parameters
, context_die
);
9671 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9672 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9673 parameters as specified in some function type specification (except for
9674 those which appear as part of a function *definition*). */
9677 gen_formal_types_die (function_or_method_type
, context_die
)
9678 register tree function_or_method_type
;
9679 register dw_die_ref context_die
;
9682 register tree formal_type
= NULL
;
9683 register tree first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
9686 /* In the case where we are generating a formal types list for a C++
9687 non-static member function type, skip over the first thing on the
9688 TYPE_ARG_TYPES list because it only represents the type of the hidden
9689 `this pointer'. The debugger should be able to figure out (without
9690 being explicitly told) that this non-static member function type takes a
9691 `this pointer' and should be able to figure what the type of that hidden
9692 parameter is from the DW_AT_member attribute of the parent
9693 DW_TAG_subroutine_type DIE. */
9694 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
)
9695 first_parm_type
= TREE_CHAIN (first_parm_type
);
9698 /* Make our first pass over the list of formal parameter types and output a
9699 DW_TAG_formal_parameter DIE for each one. */
9700 for (link
= first_parm_type
; link
; link
= TREE_CHAIN (link
))
9702 register dw_die_ref parm_die
;
9704 formal_type
= TREE_VALUE (link
);
9705 if (formal_type
== void_type_node
)
9708 /* Output a (nameless) DIE to represent the formal parameter itself. */
9709 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
9710 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
9711 && link
== first_parm_type
)
9712 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
9715 /* If this function type has an ellipsis, add a
9716 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9717 if (formal_type
!= void_type_node
)
9718 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
9720 /* Make our second (and final) pass over the list of formal parameter types
9721 and output DIEs to represent those types (as necessary). */
9722 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
9724 link
= TREE_CHAIN (link
))
9726 formal_type
= TREE_VALUE (link
);
9727 if (formal_type
== void_type_node
)
9730 gen_type_die (formal_type
, context_die
);
9734 /* We want to generate the DIE for TYPE so that we can generate the
9735 die for MEMBER, which has been defined; we will need to refer back
9736 to the member declaration nested within TYPE. If we're trying to
9737 generate minimal debug info for TYPE, processing TYPE won't do the
9738 trick; we need to attach the member declaration by hand. */
9741 gen_type_die_for_member (type
, member
, context_die
)
9743 dw_die_ref context_die
;
9745 gen_type_die (type
, context_die
);
9747 /* If we're trying to avoid duplicate debug info, we may not have
9748 emitted the member decl for this function. Emit it now. */
9749 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
9750 && ! lookup_decl_die (member
))
9752 if (decl_ultimate_origin (member
))
9755 push_decl_scope (type
);
9756 if (TREE_CODE (member
) == FUNCTION_DECL
)
9757 gen_subprogram_die (member
, lookup_type_die (type
));
9759 gen_variable_die (member
, lookup_type_die (type
));
9764 /* Generate the DWARF2 info for the "abstract" instance
9765 of a function which we may later generate inlined and/or
9766 out-of-line instances of. */
9769 gen_abstract_function (decl
)
9772 register dw_die_ref old_die
= lookup_decl_die (decl
);
9775 if (old_die
&& get_AT_unsigned (old_die
, DW_AT_inline
))
9776 /* We've already generated the abstract instance. */
9779 save_fn
= current_function_decl
;
9780 current_function_decl
= decl
;
9782 set_decl_abstract_flags (decl
, 1);
9783 dwarf2out_decl (decl
);
9784 set_decl_abstract_flags (decl
, 0);
9786 current_function_decl
= save_fn
;
9789 /* Generate a DIE to represent a declared function (either file-scope or
9793 gen_subprogram_die (decl
, context_die
)
9795 register dw_die_ref context_die
;
9797 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
9798 register tree origin
= decl_ultimate_origin (decl
);
9799 register dw_die_ref subr_die
;
9800 register rtx fp_reg
;
9801 register tree fn_arg_types
;
9802 register tree outer_scope
;
9803 register dw_die_ref old_die
= lookup_decl_die (decl
);
9804 register int declaration
= (current_function_decl
!= decl
9805 || class_scope_p (context_die
));
9807 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9808 be true, if we started to generate the abstract instance of an inline,
9809 decided to output its containing class, and proceeded to emit the
9810 declaration of the inline from the member list for the class. In that
9811 case, `declaration' takes priority; we'll get back to the abstract
9812 instance when we're done with the class. */
9814 /* The class-scope declaration DIE must be the primary DIE. */
9815 if (origin
&& declaration
&& class_scope_p (context_die
))
9824 if (declaration
&& ! local_scope_p (context_die
))
9827 /* Fixup die_parent for the abstract instance of a nested
9829 if (old_die
&& old_die
->die_parent
== NULL
)
9830 add_child_die (context_die
, old_die
);
9832 subr_die
= new_die (DW_TAG_subprogram
, context_die
);
9833 add_abstract_origin_attribute (subr_die
, origin
);
9835 else if (old_die
&& DECL_ABSTRACT (decl
)
9836 && get_AT_unsigned (old_die
, DW_AT_inline
))
9838 /* This must be a redefinition of an extern inline function.
9839 We can just reuse the old die here. */
9842 /* Clear out the inlined attribute and parm types. */
9843 remove_AT (subr_die
, DW_AT_inline
);
9844 remove_children (subr_die
);
9848 register unsigned file_index
9849 = lookup_filename (&decl_file_table
, DECL_SOURCE_FILE (decl
));
9851 if (get_AT_flag (old_die
, DW_AT_declaration
) != 1)
9853 /* ??? This can happen if there is a bug in the program, for
9854 instance, if it has duplicate function definitions. Ideally,
9855 we should detect this case and ignore it. For now, if we have
9856 already reported an error, any error at all, then assume that
9857 we got here because of a input error, not a dwarf2 bug. */
9863 /* If the definition comes from the same place as the declaration,
9864 maybe use the old DIE. We always want the DIE for this function
9865 that has the *_pc attributes to be under comp_unit_die so the
9866 debugger can find it. We also need to do this for abstract
9867 instances of inlines, since the spec requires the out-of-line copy
9868 to have the same parent. For local class methods, this doesn't
9869 apply; we just use the old DIE. */
9870 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
9871 && (DECL_ARTIFICIAL (decl
)
9872 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
9873 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
9874 == (unsigned) DECL_SOURCE_LINE (decl
)))))
9878 /* Clear out the declaration attribute and the parm types. */
9879 remove_AT (subr_die
, DW_AT_declaration
);
9880 remove_children (subr_die
);
9884 subr_die
= new_die (DW_TAG_subprogram
, context_die
);
9885 add_AT_die_ref (subr_die
, DW_AT_specification
, old_die
);
9886 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
9887 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
9888 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
9889 != (unsigned) DECL_SOURCE_LINE (decl
))
9891 (subr_die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
9896 subr_die
= new_die (DW_TAG_subprogram
, context_die
);
9898 if (TREE_PUBLIC (decl
))
9899 add_AT_flag (subr_die
, DW_AT_external
, 1);
9901 add_name_and_src_coords_attributes (subr_die
, decl
);
9902 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9904 register tree type
= TREE_TYPE (decl
);
9906 add_prototyped_attribute (subr_die
, type
);
9907 add_type_attribute (subr_die
, TREE_TYPE (type
), 0, 0, context_die
);
9910 add_pure_or_virtual_attribute (subr_die
, decl
);
9911 if (DECL_ARTIFICIAL (decl
))
9912 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
9913 if (TREE_PROTECTED (decl
))
9914 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
9915 else if (TREE_PRIVATE (decl
))
9916 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
9922 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
9924 /* The first time we see a member function, it is in the context of
9925 the class to which it belongs. We make sure of this by emitting
9926 the class first. The next time is the definition, which is
9927 handled above. The two may come from the same source text. */
9928 if (DECL_CONTEXT (decl
) || DECL_ABSTRACT (decl
))
9929 equate_decl_number_to_die (decl
, subr_die
);
9931 else if (DECL_ABSTRACT (decl
))
9933 if (DECL_INLINE (decl
) && !flag_no_inline
)
9935 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9936 inline functions, but not for extern inline functions.
9937 We can't get this completely correct because information
9938 about whether the function was declared inline is not
9940 if (DECL_DEFER_OUTPUT (decl
))
9941 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
9943 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
9946 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
9948 equate_decl_number_to_die (decl
, subr_die
);
9950 else if (!DECL_EXTERNAL (decl
))
9952 if (origin
== NULL_TREE
)
9953 equate_decl_number_to_die (decl
, subr_die
);
9955 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
9956 current_funcdef_number
);
9957 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
9958 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
9959 current_funcdef_number
);
9960 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
9962 add_pubname (decl
, subr_die
);
9963 add_arange (decl
, subr_die
);
9965 #ifdef MIPS_DEBUGGING_INFO
9966 /* Add a reference to the FDE for this routine. */
9967 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
9970 /* Define the "frame base" location for this routine. We use the
9971 frame pointer or stack pointer registers, since the RTL for local
9972 variables is relative to one of them. */
9974 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
9975 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
9978 /* ??? This fails for nested inline functions, because context_display
9979 is not part of the state saved/restored for inline functions. */
9980 if (current_function_needs_context
)
9981 add_AT_location_description (subr_die
, DW_AT_static_link
,
9982 lookup_static_chain (decl
));
9986 /* Now output descriptions of the arguments for this function. This gets
9987 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9988 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9989 `...' at the end of the formal parameter list. In order to find out if
9990 there was a trailing ellipsis or not, we must instead look at the type
9991 associated with the FUNCTION_DECL. This will be a node of type
9992 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9993 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9994 an ellipsis at the end. */
9996 /* In the case where we are describing a mere function declaration, all we
9997 need to do here (and all we *can* do here) is to describe the *types* of
9998 its formal parameters. */
9999 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10001 else if (declaration
)
10002 gen_formal_types_die (TREE_TYPE (decl
), subr_die
);
10005 /* Generate DIEs to represent all known formal parameters */
10006 register tree arg_decls
= DECL_ARGUMENTS (decl
);
10007 register tree parm
;
10009 /* When generating DIEs, generate the unspecified_parameters DIE
10010 instead if we come across the arg "__builtin_va_alist" */
10011 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
10012 if (TREE_CODE (parm
) == PARM_DECL
)
10014 if (DECL_NAME (parm
)
10015 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
10016 "__builtin_va_alist"))
10017 gen_unspecified_parameters_die (parm
, subr_die
);
10019 gen_decl_die (parm
, subr_die
);
10022 /* Decide whether we need a unspecified_parameters DIE at the end.
10023 There are 2 more cases to do this for: 1) the ansi ... declaration -
10024 this is detectable when the end of the arg list is not a
10025 void_type_node 2) an unprototyped function declaration (not a
10026 definition). This just means that we have no info about the
10027 parameters at all. */
10028 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
10029 if (fn_arg_types
!= NULL
)
10031 /* this is the prototyped case, check for ... */
10032 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
10033 gen_unspecified_parameters_die (decl
, subr_die
);
10035 else if (DECL_INITIAL (decl
) == NULL_TREE
)
10036 gen_unspecified_parameters_die (decl
, subr_die
);
10039 /* Output Dwarf info for all of the stuff within the body of the function
10040 (if it has one - it may be just a declaration). */
10041 outer_scope
= DECL_INITIAL (decl
);
10043 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
10044 node created to represent a function. This outermost BLOCK actually
10045 represents the outermost binding contour for the function, i.e. the
10046 contour in which the function's formal parameters and labels get
10047 declared. Curiously, it appears that the front end doesn't actually
10048 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
10049 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
10050 list for the function instead.) The BLOCK_VARS list for the
10051 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
10052 the function however, and we output DWARF info for those in
10053 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
10054 node representing the function's outermost pair of curly braces, and
10055 any blocks used for the base and member initializers of a C++
10056 constructor function. */
10057 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
10059 current_function_has_inlines
= 0;
10060 decls_for_scope (outer_scope
, subr_die
, 0);
10062 #if 0 && defined (MIPS_DEBUGGING_INFO)
10063 if (current_function_has_inlines
)
10065 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
10066 if (! comp_unit_has_inlines
)
10068 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
10069 comp_unit_has_inlines
= 1;
10076 /* Generate a DIE to represent a declared data object. */
10079 gen_variable_die (decl
, context_die
)
10080 register tree decl
;
10081 register dw_die_ref context_die
;
10083 register tree origin
= decl_ultimate_origin (decl
);
10084 register dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
);
10086 dw_die_ref old_die
= lookup_decl_die (decl
);
10087 int declaration
= (DECL_EXTERNAL (decl
)
10088 || class_scope_p (context_die
));
10090 if (origin
!= NULL
)
10091 add_abstract_origin_attribute (var_die
, origin
);
10092 /* Loop unrolling can create multiple blocks that refer to the same
10093 static variable, so we must test for the DW_AT_declaration flag. */
10094 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10095 copy decls and set the DECL_ABSTRACT flag on them instead of
10097 else if (old_die
&& TREE_STATIC (decl
)
10098 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
10100 /* This is a definition of a C++ class level static. */
10101 add_AT_die_ref (var_die
, DW_AT_specification
, old_die
);
10102 if (DECL_NAME (decl
))
10104 register unsigned file_index
10105 = lookup_filename (&decl_file_table
, DECL_SOURCE_FILE (decl
));
10107 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10108 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
10110 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10111 != (unsigned) DECL_SOURCE_LINE (decl
))
10113 add_AT_unsigned (var_die
, DW_AT_decl_line
,
10114 DECL_SOURCE_LINE (decl
));
10119 add_name_and_src_coords_attributes (var_die
, decl
);
10120 add_type_attribute (var_die
, TREE_TYPE (decl
),
10121 TREE_READONLY (decl
),
10122 TREE_THIS_VOLATILE (decl
), context_die
);
10124 if (TREE_PUBLIC (decl
))
10125 add_AT_flag (var_die
, DW_AT_external
, 1);
10127 if (DECL_ARTIFICIAL (decl
))
10128 add_AT_flag (var_die
, DW_AT_artificial
, 1);
10130 if (TREE_PROTECTED (decl
))
10131 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10133 else if (TREE_PRIVATE (decl
))
10134 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10138 add_AT_flag (var_die
, DW_AT_declaration
, 1);
10140 if (class_scope_p (context_die
) || DECL_ABSTRACT (decl
))
10141 equate_decl_number_to_die (decl
, var_die
);
10143 if (! declaration
&& ! DECL_ABSTRACT (decl
))
10145 add_location_or_const_value_attribute (var_die
, decl
);
10146 add_pubname (decl
, var_die
);
10149 tree_add_const_value_attribute (var_die
, decl
);
10152 /* Generate a DIE to represent a label identifier. */
10155 gen_label_die (decl
, context_die
)
10156 register tree decl
;
10157 register dw_die_ref context_die
;
10159 register tree origin
= decl_ultimate_origin (decl
);
10160 register dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
);
10162 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10164 if (origin
!= NULL
)
10165 add_abstract_origin_attribute (lbl_die
, origin
);
10167 add_name_and_src_coords_attributes (lbl_die
, decl
);
10169 if (DECL_ABSTRACT (decl
))
10170 equate_decl_number_to_die (decl
, lbl_die
);
10173 insn
= DECL_RTL (decl
);
10175 /* Deleted labels are programmer specified labels which have been
10176 eliminated because of various optimisations. We still emit them
10177 here so that it is possible to put breakpoints on them. */
10178 if (GET_CODE (insn
) == CODE_LABEL
10179 || ((GET_CODE (insn
) == NOTE
10180 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
)))
10182 /* When optimization is enabled (via -O) some parts of the compiler
10183 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10184 represent source-level labels which were explicitly declared by
10185 the user. This really shouldn't be happening though, so catch
10186 it if it ever does happen. */
10187 if (INSN_DELETED_P (insn
))
10190 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
10191 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
10196 /* Generate a DIE for a lexical block. */
10199 gen_lexical_block_die (stmt
, context_die
, depth
)
10200 register tree stmt
;
10201 register dw_die_ref context_die
;
10204 register dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
);
10205 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10207 if (! BLOCK_ABSTRACT (stmt
))
10209 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10210 BLOCK_NUMBER (stmt
));
10211 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
10212 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10213 BLOCK_NUMBER (stmt
));
10214 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
10217 decls_for_scope (stmt
, stmt_die
, depth
);
10220 /* Generate a DIE for an inlined subprogram. */
10223 gen_inlined_subroutine_die (stmt
, context_die
, depth
)
10224 register tree stmt
;
10225 register dw_die_ref context_die
;
10228 if (! BLOCK_ABSTRACT (stmt
))
10230 register dw_die_ref subr_die
10231 = new_die (DW_TAG_inlined_subroutine
, context_die
);
10232 register tree decl
= block_ultimate_origin (stmt
);
10233 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10235 /* Emit info for the abstract instance first, if we haven't yet. */
10236 gen_abstract_function (decl
);
10238 add_abstract_origin_attribute (subr_die
, decl
);
10239 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10240 BLOCK_NUMBER (stmt
));
10241 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
10242 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10243 BLOCK_NUMBER (stmt
));
10244 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
10245 decls_for_scope (stmt
, subr_die
, depth
);
10246 current_function_has_inlines
= 1;
10250 /* Generate a DIE for a field in a record, or structure. */
10253 gen_field_die (decl
, context_die
)
10254 register tree decl
;
10255 register dw_die_ref context_die
;
10257 register dw_die_ref decl_die
= new_die (DW_TAG_member
, context_die
);
10259 add_name_and_src_coords_attributes (decl_die
, decl
);
10260 add_type_attribute (decl_die
, member_declared_type (decl
),
10261 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
10264 /* If this is a bit field... */
10265 if (DECL_BIT_FIELD_TYPE (decl
))
10267 add_byte_size_attribute (decl_die
, decl
);
10268 add_bit_size_attribute (decl_die
, decl
);
10269 add_bit_offset_attribute (decl_die
, decl
);
10272 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
10273 add_data_member_location_attribute (decl_die
, decl
);
10275 if (DECL_ARTIFICIAL (decl
))
10276 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
10278 if (TREE_PROTECTED (decl
))
10279 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10281 else if (TREE_PRIVATE (decl
))
10282 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10286 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10287 Use modified_type_die instead.
10288 We keep this code here just in case these types of DIEs may be needed to
10289 represent certain things in other languages (e.g. Pascal) someday. */
10291 gen_pointer_type_die (type
, context_die
)
10292 register tree type
;
10293 register dw_die_ref context_die
;
10295 register dw_die_ref ptr_die
10296 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
));
10298 equate_type_number_to_die (type
, ptr_die
);
10299 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
10300 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
10303 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10304 Use modified_type_die instead.
10305 We keep this code here just in case these types of DIEs may be needed to
10306 represent certain things in other languages (e.g. Pascal) someday. */
10308 gen_reference_type_die (type
, context_die
)
10309 register tree type
;
10310 register dw_die_ref context_die
;
10312 register dw_die_ref ref_die
10313 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
));
10315 equate_type_number_to_die (type
, ref_die
);
10316 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
10317 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
10321 /* Generate a DIE for a pointer to a member type. */
10323 gen_ptr_to_mbr_type_die (type
, context_die
)
10324 register tree type
;
10325 register dw_die_ref context_die
;
10327 register dw_die_ref ptr_die
10328 = new_die (DW_TAG_ptr_to_member_type
, scope_die_for (type
, context_die
));
10330 equate_type_number_to_die (type
, ptr_die
);
10331 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
10332 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
10333 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
10336 /* Generate the DIE for the compilation unit. */
10339 gen_compile_unit_die (filename
)
10340 register const char *filename
;
10342 register dw_die_ref die
;
10343 char producer
[250];
10344 const char *wd
= getpwd ();
10347 die
= new_die (DW_TAG_compile_unit
, NULL
);
10348 add_name_attribute (die
, filename
);
10350 if (wd
!= NULL
&& filename
[0] != DIR_SEPARATOR
)
10351 add_AT_string (die
, DW_AT_comp_dir
, wd
);
10353 sprintf (producer
, "%s %s", language_string
, version_string
);
10355 #ifdef MIPS_DEBUGGING_INFO
10356 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10357 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10358 not appear in the producer string, the debugger reaches the conclusion
10359 that the object file is stripped and has no debugging information.
10360 To get the MIPS/SGI debugger to believe that there is debugging
10361 information in the object file, we add a -g to the producer string. */
10362 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10363 strcat (producer
, " -g");
10366 add_AT_string (die
, DW_AT_producer
, producer
);
10368 if (strcmp (language_string
, "GNU C++") == 0)
10369 language
= DW_LANG_C_plus_plus
;
10370 else if (strcmp (language_string
, "GNU Ada") == 0)
10371 language
= DW_LANG_Ada83
;
10372 else if (strcmp (language_string
, "GNU F77") == 0)
10373 language
= DW_LANG_Fortran77
;
10374 else if (strcmp (language_string
, "GNU Pascal") == 0)
10375 language
= DW_LANG_Pascal83
;
10376 else if (strcmp (language_string
, "GNU Java") == 0)
10377 language
= DW_LANG_Java
;
10378 else if (flag_traditional
)
10379 language
= DW_LANG_C
;
10381 language
= DW_LANG_C89
;
10383 add_AT_unsigned (die
, DW_AT_language
, language
);
10388 /* Generate a DIE for a string type. */
10391 gen_string_type_die (type
, context_die
)
10392 register tree type
;
10393 register dw_die_ref context_die
;
10395 register dw_die_ref type_die
10396 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
));
10398 equate_type_number_to_die (type
, type_die
);
10400 /* Fudge the string length attribute for now. */
10402 /* TODO: add string length info.
10403 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10404 bound_representation (upper_bound, 0, 'u'); */
10407 /* Generate the DIE for a base class. */
10410 gen_inheritance_die (binfo
, context_die
)
10411 register tree binfo
;
10412 register dw_die_ref context_die
;
10414 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
);
10416 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
10417 add_data_member_location_attribute (die
, binfo
);
10419 if (TREE_VIA_VIRTUAL (binfo
))
10420 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
10421 if (TREE_VIA_PUBLIC (binfo
))
10422 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
10423 else if (TREE_VIA_PROTECTED (binfo
))
10424 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10427 /* Generate a DIE for a class member. */
10430 gen_member_die (type
, context_die
)
10431 register tree type
;
10432 register dw_die_ref context_die
;
10434 register tree member
;
10437 /* If this is not an incomplete type, output descriptions of each of its
10438 members. Note that as we output the DIEs necessary to represent the
10439 members of this record or union type, we will also be trying to output
10440 DIEs to represent the *types* of those members. However the `type'
10441 function (above) will specifically avoid generating type DIEs for member
10442 types *within* the list of member DIEs for this (containing) type execpt
10443 for those types (of members) which are explicitly marked as also being
10444 members of this (containing) type themselves. The g++ front- end can
10445 force any given type to be treated as a member of some other
10446 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10447 to point to the TREE node representing the appropriate (containing)
10450 /* First output info about the base classes. */
10451 if (TYPE_BINFO (type
) && TYPE_BINFO_BASETYPES (type
))
10453 register tree bases
= TYPE_BINFO_BASETYPES (type
);
10454 register int n_bases
= TREE_VEC_LENGTH (bases
);
10457 for (i
= 0; i
< n_bases
; i
++)
10458 gen_inheritance_die (TREE_VEC_ELT (bases
, i
), context_die
);
10461 /* Now output info about the data members and type members. */
10462 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
10464 /* If we thought we were generating minimal debug info for TYPE
10465 and then changed our minds, some of the member declarations
10466 may have already been defined. Don't define them again, but
10467 do put them in the right order. */
10469 child
= lookup_decl_die (member
);
10471 splice_child_die (context_die
, child
);
10473 gen_decl_die (member
, context_die
);
10476 /* Now output info about the function members (if any). */
10477 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
10479 child
= lookup_decl_die (member
);
10481 splice_child_die (context_die
, child
);
10483 gen_decl_die (member
, context_die
);
10487 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10488 is set, we pretend that the type was never defined, so we only get the
10489 member DIEs needed by later specification DIEs. */
10492 gen_struct_or_union_type_die (type
, context_die
)
10493 register tree type
;
10494 register dw_die_ref context_die
;
10496 register dw_die_ref type_die
= lookup_type_die (type
);
10497 register dw_die_ref scope_die
= 0;
10498 register int nested
= 0;
10499 int complete
= (TYPE_SIZE (type
)
10500 && (! TYPE_STUB_DECL (type
)
10501 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
10503 if (type_die
&& ! complete
)
10506 if (TYPE_CONTEXT (type
) != NULL_TREE
10507 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
)))
10510 scope_die
= scope_die_for (type
, context_die
);
10512 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
10513 /* First occurrence of type or toplevel definition of nested class. */
10515 register dw_die_ref old_die
= type_die
;
10517 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
10518 ? DW_TAG_structure_type
: DW_TAG_union_type
,
10520 equate_type_number_to_die (type
, type_die
);
10522 add_AT_die_ref (type_die
, DW_AT_specification
, old_die
);
10524 add_name_attribute (type_die
, type_tag (type
));
10527 remove_AT (type_die
, DW_AT_declaration
);
10529 /* If this type has been completed, then give it a byte_size attribute and
10530 then give a list of members. */
10533 /* Prevent infinite recursion in cases where the type of some member of
10534 this type is expressed in terms of this type itself. */
10535 TREE_ASM_WRITTEN (type
) = 1;
10536 add_byte_size_attribute (type_die
, type
);
10537 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
10538 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
10540 /* If the first reference to this type was as the return type of an
10541 inline function, then it may not have a parent. Fix this now. */
10542 if (type_die
->die_parent
== NULL
)
10543 add_child_die (scope_die
, type_die
);
10545 push_decl_scope (type
);
10546 gen_member_die (type
, type_die
);
10549 /* GNU extension: Record what type our vtable lives in. */
10550 if (TYPE_VFIELD (type
))
10552 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
10554 gen_type_die (vtype
, context_die
);
10555 add_AT_die_ref (type_die
, DW_AT_containing_type
,
10556 lookup_type_die (vtype
));
10561 add_AT_flag (type_die
, DW_AT_declaration
, 1);
10563 /* We don't need to do this for function-local types. */
10564 if (! decl_function_context (TYPE_STUB_DECL (type
)))
10565 add_incomplete_type (type
);
10569 /* Generate a DIE for a subroutine _type_. */
10572 gen_subroutine_type_die (type
, context_die
)
10573 register tree type
;
10574 register dw_die_ref context_die
;
10576 register tree return_type
= TREE_TYPE (type
);
10577 register dw_die_ref subr_die
10578 = new_die (DW_TAG_subroutine_type
, scope_die_for (type
, context_die
));
10580 equate_type_number_to_die (type
, subr_die
);
10581 add_prototyped_attribute (subr_die
, type
);
10582 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
10583 gen_formal_types_die (type
, subr_die
);
10586 /* Generate a DIE for a type definition */
10589 gen_typedef_die (decl
, context_die
)
10590 register tree decl
;
10591 register dw_die_ref context_die
;
10593 register dw_die_ref type_die
;
10594 register tree origin
;
10596 if (TREE_ASM_WRITTEN (decl
))
10598 TREE_ASM_WRITTEN (decl
) = 1;
10600 type_die
= new_die (DW_TAG_typedef
, context_die
);
10601 origin
= decl_ultimate_origin (decl
);
10602 if (origin
!= NULL
)
10603 add_abstract_origin_attribute (type_die
, origin
);
10606 register tree type
;
10607 add_name_and_src_coords_attributes (type_die
, decl
);
10608 if (DECL_ORIGINAL_TYPE (decl
))
10610 type
= DECL_ORIGINAL_TYPE (decl
);
10612 if (type
== TREE_TYPE (decl
))
10615 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
10618 type
= TREE_TYPE (decl
);
10619 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
10620 TREE_THIS_VOLATILE (decl
), context_die
);
10623 if (DECL_ABSTRACT (decl
))
10624 equate_decl_number_to_die (decl
, type_die
);
10627 /* Generate a type description DIE. */
10630 gen_type_die (type
, context_die
)
10631 register tree type
;
10632 register dw_die_ref context_die
;
10636 if (type
== NULL_TREE
|| type
== error_mark_node
)
10639 /* We are going to output a DIE to represent the unqualified version of
10640 this type (i.e. without any const or volatile qualifiers) so get the
10641 main variant (i.e. the unqualified version) of this type now. */
10642 type
= type_main_variant (type
);
10644 if (TREE_ASM_WRITTEN (type
))
10647 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10648 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
10650 TREE_ASM_WRITTEN (type
) = 1;
10651 gen_decl_die (TYPE_NAME (type
), context_die
);
10655 switch (TREE_CODE (type
))
10661 case REFERENCE_TYPE
:
10662 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10663 ensures that the gen_type_die recursion will terminate even if the
10664 type is recursive. Recursive types are possible in Ada. */
10665 /* ??? We could perhaps do this for all types before the switch
10667 TREE_ASM_WRITTEN (type
) = 1;
10669 /* For these types, all that is required is that we output a DIE (or a
10670 set of DIEs) to represent the "basis" type. */
10671 gen_type_die (TREE_TYPE (type
), context_die
);
10675 /* This code is used for C++ pointer-to-data-member types.
10676 Output a description of the relevant class type. */
10677 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
10679 /* Output a description of the type of the object pointed to. */
10680 gen_type_die (TREE_TYPE (type
), context_die
);
10682 /* Now output a DIE to represent this pointer-to-data-member type
10684 gen_ptr_to_mbr_type_die (type
, context_die
);
10688 gen_type_die (TYPE_DOMAIN (type
), context_die
);
10689 gen_set_type_die (type
, context_die
);
10693 gen_type_die (TREE_TYPE (type
), context_die
);
10694 abort (); /* No way to represent these in Dwarf yet! */
10697 case FUNCTION_TYPE
:
10698 /* Force out return type (in case it wasn't forced out already). */
10699 gen_type_die (TREE_TYPE (type
), context_die
);
10700 gen_subroutine_type_die (type
, context_die
);
10704 /* Force out return type (in case it wasn't forced out already). */
10705 gen_type_die (TREE_TYPE (type
), context_die
);
10706 gen_subroutine_type_die (type
, context_die
);
10710 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
10712 gen_type_die (TREE_TYPE (type
), context_die
);
10713 gen_string_type_die (type
, context_die
);
10716 gen_array_type_die (type
, context_die
);
10720 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type
), context_die
);
10723 case ENUMERAL_TYPE
:
10726 case QUAL_UNION_TYPE
:
10727 /* If this is a nested type whose containing class hasn't been
10728 written out yet, writing it out will cover this one, too.
10729 This does not apply to instantiations of member class templates;
10730 they need to be added to the containing class as they are
10731 generated. FIXME: This hurts the idea of combining type decls
10732 from multiple TUs, since we can't predict what set of template
10733 instantiations we'll get. */
10734 if (TYPE_CONTEXT (type
)
10735 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
10736 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
10738 gen_type_die (TYPE_CONTEXT (type
), context_die
);
10740 if (TREE_ASM_WRITTEN (type
))
10743 /* If that failed, attach ourselves to the stub. */
10744 push_decl_scope (TYPE_CONTEXT (type
));
10745 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
10751 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
10752 gen_enumeration_type_die (type
, context_die
);
10754 gen_struct_or_union_type_die (type
, context_die
);
10759 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10760 it up if it is ever completed. gen_*_type_die will set it for us
10761 when appropriate. */
10770 /* No DIEs needed for fundamental types. */
10774 /* No Dwarf representation currently defined. */
10781 TREE_ASM_WRITTEN (type
) = 1;
10784 /* Generate a DIE for a tagged type instantiation. */
10787 gen_tagged_type_instantiation_die (type
, context_die
)
10788 register tree type
;
10789 register dw_die_ref context_die
;
10791 if (type
== NULL_TREE
|| type
== error_mark_node
)
10794 /* We are going to output a DIE to represent the unqualified version of
10795 this type (i.e. without any const or volatile qualifiers) so make sure
10796 that we have the main variant (i.e. the unqualified version) of this
10798 if (type
!= type_main_variant (type
))
10801 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10802 an instance of an unresolved type. */
10804 switch (TREE_CODE (type
))
10809 case ENUMERAL_TYPE
:
10810 gen_inlined_enumeration_type_die (type
, context_die
);
10814 gen_inlined_structure_type_die (type
, context_die
);
10818 case QUAL_UNION_TYPE
:
10819 gen_inlined_union_type_die (type
, context_die
);
10827 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10828 things which are local to the given block. */
10831 gen_block_die (stmt
, context_die
, depth
)
10832 register tree stmt
;
10833 register dw_die_ref context_die
;
10836 register int must_output_die
= 0;
10837 register tree origin
;
10838 register tree decl
;
10839 register enum tree_code origin_code
;
10841 /* Ignore blocks never really used to make RTL. */
10843 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
)
10844 || (!TREE_ASM_WRITTEN (stmt
) && !BLOCK_ABSTRACT (stmt
)))
10847 /* Determine the "ultimate origin" of this block. This block may be an
10848 inlined instance of an inlined instance of inline function, so we have
10849 to trace all of the way back through the origin chain to find out what
10850 sort of node actually served as the original seed for the creation of
10851 the current block. */
10852 origin
= block_ultimate_origin (stmt
);
10853 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
10855 /* Determine if we need to output any Dwarf DIEs at all to represent this
10857 if (origin_code
== FUNCTION_DECL
)
10858 /* The outer scopes for inlinings *must* always be represented. We
10859 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10860 must_output_die
= 1;
10863 /* In the case where the current block represents an inlining of the
10864 "body block" of an inline function, we must *NOT* output any DIE for
10865 this block because we have already output a DIE to represent the
10866 whole inlined function scope and the "body block" of any function
10867 doesn't really represent a different scope according to ANSI C
10868 rules. So we check here to make sure that this block does not
10869 represent a "body block inlining" before trying to set the
10870 `must_output_die' flag. */
10871 if (! is_body_block (origin
? origin
: stmt
))
10873 /* Determine if this block directly contains any "significant"
10874 local declarations which we will need to output DIEs for. */
10875 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10876 /* We are not in terse mode so *any* local declaration counts
10877 as being a "significant" one. */
10878 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
10880 /* We are in terse mode, so only local (nested) function
10881 definitions count as "significant" local declarations. */
10882 for (decl
= BLOCK_VARS (stmt
);
10883 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
10884 if (TREE_CODE (decl
) == FUNCTION_DECL
10885 && DECL_INITIAL (decl
))
10887 must_output_die
= 1;
10893 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10894 DIE for any block which contains no significant local declarations at
10895 all. Rather, in such cases we just call `decls_for_scope' so that any
10896 needed Dwarf info for any sub-blocks will get properly generated. Note
10897 that in terse mode, our definition of what constitutes a "significant"
10898 local declaration gets restricted to include only inlined function
10899 instances and local (nested) function definitions. */
10900 if (must_output_die
)
10902 if (origin_code
== FUNCTION_DECL
)
10903 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
10905 gen_lexical_block_die (stmt
, context_die
, depth
);
10908 decls_for_scope (stmt
, context_die
, depth
);
10911 /* Generate all of the decls declared within a given scope and (recursively)
10912 all of its sub-blocks. */
10915 decls_for_scope (stmt
, context_die
, depth
)
10916 register tree stmt
;
10917 register dw_die_ref context_die
;
10920 register tree decl
;
10921 register tree subblocks
;
10923 /* Ignore blocks never really used to make RTL. */
10924 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
10927 /* Output the DIEs to represent all of the data objects and typedefs
10928 declared directly within this block but not within any nested
10929 sub-blocks. Also, nested function and tag DIEs have been
10930 generated with a parent of NULL; fix that up now. */
10931 for (decl
= BLOCK_VARS (stmt
);
10932 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
10934 register dw_die_ref die
;
10936 if (TREE_CODE (decl
) == FUNCTION_DECL
)
10937 die
= lookup_decl_die (decl
);
10938 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
10939 die
= lookup_type_die (TREE_TYPE (decl
));
10943 if (die
!= NULL
&& die
->die_parent
== NULL
)
10944 add_child_die (context_die
, die
);
10946 gen_decl_die (decl
, context_die
);
10949 /* Output the DIEs to represent all sub-blocks (and the items declared
10950 therein) of this block. */
10951 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
10953 subblocks
= BLOCK_CHAIN (subblocks
))
10954 gen_block_die (subblocks
, context_die
, depth
+ 1);
10957 /* Is this a typedef we can avoid emitting? */
10960 is_redundant_typedef (decl
)
10961 register tree decl
;
10963 if (TYPE_DECL_IS_STUB (decl
))
10966 if (DECL_ARTIFICIAL (decl
)
10967 && DECL_CONTEXT (decl
)
10968 && is_tagged_type (DECL_CONTEXT (decl
))
10969 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
10970 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
10971 /* Also ignore the artificial member typedef for the class name. */
10977 /* Generate Dwarf debug information for a decl described by DECL. */
10980 gen_decl_die (decl
, context_die
)
10981 register tree decl
;
10982 register dw_die_ref context_die
;
10984 register tree origin
;
10986 if (TREE_CODE (decl
) == ERROR_MARK
)
10989 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10990 if (DECL_IGNORED_P (decl
))
10993 switch (TREE_CODE (decl
))
10996 /* The individual enumerators of an enum type get output when we output
10997 the Dwarf representation of the relevant enum type itself. */
11000 case FUNCTION_DECL
:
11001 /* Don't output any DIEs to represent mere function declarations,
11002 unless they are class members or explicit block externs. */
11003 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
11004 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
11007 /* If we're emitting an out-of-line copy of an inline function,
11008 emit info for the abstract instance and set up to refer to it. */
11009 if (DECL_INLINE (decl
) && ! DECL_ABSTRACT (decl
)
11010 && ! class_scope_p (context_die
)
11011 /* gen_abstract_function won't emit a die if this is just a
11012 declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11013 that case, because that works only if we have a die. */
11014 && DECL_INITIAL (decl
) != NULL_TREE
)
11016 gen_abstract_function (decl
);
11017 set_decl_origin_self (decl
);
11020 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11022 /* Before we describe the FUNCTION_DECL itself, make sure that we
11023 have described its return type. */
11024 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
11026 /* And its virtual context. */
11027 if (DECL_VINDEX (decl
) != NULL_TREE
)
11028 gen_type_die (DECL_CONTEXT (decl
), context_die
);
11030 /* And its containing type. */
11031 origin
= decl_class_context (decl
);
11032 if (origin
!= NULL_TREE
)
11033 gen_type_die_for_member (origin
, decl
, context_die
);
11036 /* Now output a DIE to represent the function itself. */
11037 gen_subprogram_die (decl
, context_die
);
11041 /* If we are in terse mode, don't generate any DIEs to represent any
11042 actual typedefs. */
11043 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11046 /* In the special case of a TYPE_DECL node representing the
11047 declaration of some type tag, if the given TYPE_DECL is marked as
11048 having been instantiated from some other (original) TYPE_DECL node
11049 (e.g. one which was generated within the original definition of an
11050 inline function) we have to generate a special (abbreviated)
11051 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
11053 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
11055 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
11059 if (is_redundant_typedef (decl
))
11060 gen_type_die (TREE_TYPE (decl
), context_die
);
11062 /* Output a DIE to represent the typedef itself. */
11063 gen_typedef_die (decl
, context_die
);
11067 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
11068 gen_label_die (decl
, context_die
);
11072 /* If we are in terse mode, don't generate any DIEs to represent any
11073 variable declarations or definitions. */
11074 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11077 /* Output any DIEs that are needed to specify the type of this data
11079 gen_type_die (TREE_TYPE (decl
), context_die
);
11081 /* And its containing type. */
11082 origin
= decl_class_context (decl
);
11083 if (origin
!= NULL_TREE
)
11084 gen_type_die_for_member (origin
, decl
, context_die
);
11086 /* Now output the DIE to represent the data object itself. This gets
11087 complicated because of the possibility that the VAR_DECL really
11088 represents an inlined instance of a formal parameter for an inline
11090 origin
= decl_ultimate_origin (decl
);
11091 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
11092 gen_formal_parameter_die (decl
, context_die
);
11094 gen_variable_die (decl
, context_die
);
11098 /* Ignore the nameless fields that are used to skip bits, but
11099 handle C++ anonymous unions. */
11100 if (DECL_NAME (decl
) != NULL_TREE
11101 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
)
11103 gen_type_die (member_declared_type (decl
), context_die
);
11104 gen_field_die (decl
, context_die
);
11109 gen_type_die (TREE_TYPE (decl
), context_die
);
11110 gen_formal_parameter_die (decl
, context_die
);
11113 case NAMESPACE_DECL
:
11114 /* Ignore for now. */
11122 /* Add Ada "use" clause information for SGI Workshop debugger. */
11125 dwarf2out_add_library_unit_info (filename
, context_list
)
11126 const char *filename
;
11127 const char *context_list
;
11129 unsigned int file_index
;
11131 if (filename
!= NULL
)
11133 dw_die_ref unit_die
= new_die (DW_TAG_module
, comp_unit_die
);
11134 tree context_list_decl
11135 = build_decl (LABEL_DECL
, get_identifier (context_list
),
11138 TREE_PUBLIC (context_list_decl
) = TRUE
;
11139 add_name_attribute (unit_die
, context_list
);
11140 file_index
= lookup_filename (&decl_file_table
, filename
);
11141 add_AT_unsigned (unit_die
, DW_AT_decl_file
, file_index
);
11142 add_pubname (context_list_decl
, unit_die
);
11146 /* Write the debugging output for DECL. */
11149 dwarf2out_decl (decl
)
11150 register tree decl
;
11152 register dw_die_ref context_die
= comp_unit_die
;
11154 if (TREE_CODE (decl
) == ERROR_MARK
)
11157 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11158 if (DECL_IGNORED_P (decl
))
11161 switch (TREE_CODE (decl
))
11163 case FUNCTION_DECL
:
11164 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11165 builtin function. Explicit programmer-supplied declarations of
11166 these same functions should NOT be ignored however. */
11167 if (DECL_EXTERNAL (decl
) && DECL_BUILT_IN (decl
))
11170 /* What we would really like to do here is to filter out all mere
11171 file-scope declarations of file-scope functions which are never
11172 referenced later within this translation unit (and keep all of ones
11173 that *are* referenced later on) but we aren't clairvoyant, so we have
11174 no idea which functions will be referenced in the future (i.e. later
11175 on within the current translation unit). So here we just ignore all
11176 file-scope function declarations which are not also definitions. If
11177 and when the debugger needs to know something about these functions,
11178 it will have to hunt around and find the DWARF information associated
11179 with the definition of the function. Note that we can't just check
11180 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11181 definitions and which ones represent mere declarations. We have to
11182 check `DECL_INITIAL' instead. That's because the C front-end
11183 supports some weird semantics for "extern inline" function
11184 definitions. These can get inlined within the current translation
11185 unit (an thus, we need to generate DWARF info for their abstract
11186 instances so that the DWARF info for the concrete inlined instances
11187 can have something to refer to) but the compiler never generates any
11188 out-of-lines instances of such things (despite the fact that they
11189 *are* definitions). The important point is that the C front-end
11190 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11191 to generate DWARF for them anyway. Note that the C++ front-end also
11192 plays some similar games for inline function definitions appearing
11193 within include files which also contain
11194 `#pragma interface' pragmas. */
11195 if (DECL_INITIAL (decl
) == NULL_TREE
)
11198 /* If we're a nested function, initially use a parent of NULL; if we're
11199 a plain function, this will be fixed up in decls_for_scope. If
11200 we're a method, it will be ignored, since we already have a DIE. */
11201 if (decl_function_context (decl
))
11202 context_die
= NULL
;
11207 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11208 declaration and if the declaration was never even referenced from
11209 within this entire compilation unit. We suppress these DIEs in
11210 order to save space in the .debug section (by eliminating entries
11211 which are probably useless). Note that we must not suppress
11212 block-local extern declarations (whether used or not) because that
11213 would screw-up the debugger's name lookup mechanism and cause it to
11214 miss things which really ought to be in scope at a given point. */
11215 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
11218 /* If we are in terse mode, don't generate any DIEs to represent any
11219 variable declarations or definitions. */
11220 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11225 /* Don't emit stubs for types unless they are needed by other DIEs. */
11226 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
11229 /* Don't bother trying to generate any DIEs to represent any of the
11230 normal built-in types for the language we are compiling. */
11231 if (DECL_SOURCE_LINE (decl
) == 0)
11233 /* OK, we need to generate one for `bool' so GDB knows what type
11234 comparisons have. */
11235 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
11236 == DW_LANG_C_plus_plus
)
11237 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
)
11238 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
11243 /* If we are in terse mode, don't generate any DIEs for types. */
11244 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11247 /* If we're a function-scope tag, initially use a parent of NULL;
11248 this will be fixed up in decls_for_scope. */
11249 if (decl_function_context (decl
))
11250 context_die
= NULL
;
11258 gen_decl_die (decl
, context_die
);
11261 /* Output a marker (i.e. a label) for the beginning of the generated code for
11262 a lexical block. */
11265 dwarf2out_begin_block (blocknum
)
11266 register unsigned blocknum
;
11268 function_section (current_function_decl
);
11269 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
11272 /* Output a marker (i.e. a label) for the end of the generated code for a
11276 dwarf2out_end_block (blocknum
)
11277 register unsigned blocknum
;
11279 function_section (current_function_decl
);
11280 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
11283 /* Returns nonzero if it is appropriate not to emit any debugging
11284 information for BLOCK, because it doesn't contain any instructions.
11286 Don't allow this for blocks with nested functions or local classes
11287 as we would end up with orphans, and in the presence of scheduling
11288 we may end up calling them anyway. */
11291 dwarf2out_ignore_block (block
)
11295 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
11296 if (TREE_CODE (decl
) == FUNCTION_DECL
11297 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
11302 /* Lookup a filename (in the list of filenames that we know about here in
11303 dwarf2out.c) and return its "index". The index of each (known) filename is
11304 just a unique number which is associated with only that one filename.
11305 We need such numbers for the sake of generating labels
11306 (in the .debug_sfnames section) and references to those
11307 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11308 If the filename given as an argument is not found in our current list,
11309 add it to the list and assign it the next available unique index number.
11310 In order to speed up searches, we remember the index of the filename
11311 was looked up last. This handles the majority of all searches. */
11314 lookup_filename (t
, file_name
)
11315 struct file_table
*t
;
11316 const char *file_name
;
11318 register unsigned i
;
11320 /* Check to see if the file name that was searched on the previous
11321 call matches this file name. If so, return the index. */
11322 if (t
->last_lookup_index
!= 0)
11323 if (strcmp (file_name
, t
->table
[t
->last_lookup_index
]) == 0)
11324 return t
->last_lookup_index
;
11326 /* Didn't match the previous lookup, search the table */
11327 for (i
= 1; i
< t
->in_use
; ++i
)
11328 if (strcmp (file_name
, t
->table
[i
]) == 0)
11330 t
->last_lookup_index
= i
;
11334 /* Prepare to add a new table entry by making sure there is enough space in
11335 the table to do so. If not, expand the current table. */
11336 if (i
== t
->allocated
)
11338 t
->allocated
= i
+ FILE_TABLE_INCREMENT
;
11339 t
->table
= (char **)
11340 xrealloc (t
->table
, t
->allocated
* sizeof (char *));
11343 /* Add the new entry to the end of the filename table. */
11344 t
->table
[i
] = xstrdup (file_name
);
11346 t
->last_lookup_index
= i
;
11352 init_file_table (t
)
11353 struct file_table
*t
;
11355 /* Allocate the initial hunk of the file_table. */
11356 t
->table
= (char **) xcalloc (FILE_TABLE_INCREMENT
, sizeof (char *));
11357 t
->allocated
= FILE_TABLE_INCREMENT
;
11359 /* Skip the first entry - file numbers begin at 1. */
11361 t
->last_lookup_index
= 0;
11364 /* Output a label to mark the beginning of a source code line entry
11365 and record information relating to this source line, in
11366 'line_info_table' for later output of the .debug_line section. */
11369 dwarf2out_line (filename
, line
)
11370 register const char *filename
;
11371 register unsigned line
;
11373 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
11375 function_section (current_function_decl
);
11377 if (DWARF2_ASM_LINE_DEBUG_INFO
)
11380 unsigned old_in_use
= line_file_table
.in_use
;
11382 unsigned file_num
= lookup_filename (&line_file_table
, filename
);
11384 /* Emit the .file and .loc directives understood by GNU as. */
11386 /* ??? As of 2000-11-25, gas has a bug in which it doesn't
11387 actually use the file number argument. It merely remembers
11388 the last .file directive emitted. */
11389 if (file_num
>= old_in_use
)
11390 fprintf (asm_out_file
, "\t.file %d \"%s\"\n", file_num
, filename
);
11391 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
11393 static unsigned int last_file_num
;
11394 if (file_num
!= last_file_num
)
11396 last_file_num
= file_num
;
11397 fprintf (asm_out_file
, "\t.file 0 \"%s\"\n", filename
);
11399 fprintf (asm_out_file
, "\t.loc 0 %d 0\n", line
);
11402 /* Indicate that line number info exists. */
11403 ++line_info_table_in_use
;
11405 /* Indicate that multiple line number tables exist. */
11406 if (DECL_SECTION_NAME (current_function_decl
))
11407 ++separate_line_info_table_in_use
;
11409 else if (DECL_SECTION_NAME (current_function_decl
))
11411 register dw_separate_line_info_ref line_info
;
11412 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
11413 separate_line_info_table_in_use
);
11414 if (flag_debug_asm
)
11415 fprintf (asm_out_file
, "\t%s line %d", ASM_COMMENT_START
, line
);
11416 fputc ('\n', asm_out_file
);
11418 /* expand the line info table if necessary */
11419 if (separate_line_info_table_in_use
11420 == separate_line_info_table_allocated
)
11422 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
11423 separate_line_info_table
11424 = (dw_separate_line_info_ref
)
11425 xrealloc (separate_line_info_table
,
11426 separate_line_info_table_allocated
11427 * sizeof (dw_separate_line_info_entry
));
11430 /* Add the new entry at the end of the line_info_table. */
11432 = &separate_line_info_table
[separate_line_info_table_in_use
++];
11433 line_info
->dw_file_num
= lookup_filename (&line_file_table
, filename
);
11434 line_info
->dw_line_num
= line
;
11435 line_info
->function
= current_funcdef_number
;
11439 register dw_line_info_ref line_info
;
11441 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, LINE_CODE_LABEL
,
11442 line_info_table_in_use
);
11443 if (flag_debug_asm
)
11444 fprintf (asm_out_file
, "\t%s line %d", ASM_COMMENT_START
, line
);
11445 fputc ('\n', asm_out_file
);
11447 /* Expand the line info table if necessary. */
11448 if (line_info_table_in_use
== line_info_table_allocated
)
11450 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
11452 = (dw_line_info_ref
)
11453 xrealloc (line_info_table
,
11454 (line_info_table_allocated
11455 * sizeof (dw_line_info_entry
)));
11458 /* Add the new entry at the end of the line_info_table. */
11459 line_info
= &line_info_table
[line_info_table_in_use
++];
11460 line_info
->dw_file_num
= lookup_filename (&line_file_table
, filename
);
11461 line_info
->dw_line_num
= line
;
11466 /* Record the beginning of a new source file, for later output
11467 of the .debug_macinfo section. At present, unimplemented. */
11470 dwarf2out_start_source_file (filename
)
11471 register const char *filename ATTRIBUTE_UNUSED
;
11473 if (flag_eliminate_dwarf2_dups
)
11475 /* Record the beginning of the file for break_out_includes. */
11476 dw_die_ref bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
);
11477 add_AT_string (bincl_die
, DW_AT_name
, filename
);
11481 /* Record the end of a source file, for later output
11482 of the .debug_macinfo section. At present, unimplemented. */
11485 dwarf2out_end_source_file ()
11487 if (flag_eliminate_dwarf2_dups
)
11489 /* Record the end of the file for break_out_includes. */
11490 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
);
11494 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11495 the tail part of the directive line, i.e. the part which is past the
11496 initial whitespace, #, whitespace, directive-name, whitespace part. */
11499 dwarf2out_define (lineno
, buffer
)
11500 register unsigned lineno ATTRIBUTE_UNUSED
;
11501 register const char *buffer ATTRIBUTE_UNUSED
;
11503 static int initialized
= 0;
11506 dwarf2out_start_source_file (primary_filename
);
11511 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11512 the tail part of the directive line, i.e. the part which is past the
11513 initial whitespace, #, whitespace, directive-name, whitespace part. */
11516 dwarf2out_undef (lineno
, buffer
)
11517 register unsigned lineno ATTRIBUTE_UNUSED
;
11518 register const char *buffer ATTRIBUTE_UNUSED
;
11522 /* Set up for Dwarf output at the start of compilation. */
11525 dwarf2out_init (asm_out_file
, main_input_filename
)
11526 register FILE *asm_out_file
;
11527 register const char *main_input_filename
;
11529 /* Remember the name of the primary input file. */
11530 primary_filename
= main_input_filename
;
11532 init_file_table (&decl_file_table
);
11533 init_file_table (&line_file_table
);
11535 /* Allocate the initial hunk of the decl_die_table. */
11537 = (dw_die_ref
*) xcalloc (DECL_DIE_TABLE_INCREMENT
, sizeof (dw_die_ref
));
11538 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
11539 decl_die_table_in_use
= 0;
11541 /* Allocate the initial hunk of the decl_scope_table. */
11543 = (tree
*) xcalloc (DECL_SCOPE_TABLE_INCREMENT
, sizeof (tree
));
11544 decl_scope_table_allocated
= DECL_SCOPE_TABLE_INCREMENT
;
11545 decl_scope_depth
= 0;
11547 /* Allocate the initial hunk of the abbrev_die_table. */
11549 = (dw_die_ref
*) xcalloc (ABBREV_DIE_TABLE_INCREMENT
,
11550 sizeof (dw_die_ref
));
11551 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
11552 /* Zero-th entry is allocated, but unused */
11553 abbrev_die_table_in_use
= 1;
11555 /* Allocate the initial hunk of the line_info_table. */
11557 = (dw_line_info_ref
) xcalloc (LINE_INFO_TABLE_INCREMENT
,
11558 sizeof (dw_line_info_entry
));
11559 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
11560 /* Zero-th entry is allocated, but unused */
11561 line_info_table_in_use
= 1;
11563 /* Generate the initial DIE for the .debug section. Note that the (string)
11564 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11565 will (typically) be a relative pathname and that this pathname should be
11566 taken as being relative to the directory from which the compiler was
11567 invoked when the given (base) source file was compiled. */
11568 comp_unit_die
= gen_compile_unit_die (main_input_filename
);
11570 VARRAY_RTX_INIT (used_rtx_varray
, 32, "used_rtx_varray");
11571 ggc_add_rtx_varray_root (&used_rtx_varray
, 1);
11573 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
11574 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
, ABBREV_SECTION_LABEL
, 0);
11575 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
11576 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
11578 strcpy (text_section_label
, stripattributes (TEXT_SECTION
));
11579 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
11580 DEBUG_INFO_SECTION_LABEL
, 0);
11581 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
11582 DEBUG_LINE_SECTION_LABEL
, 0);
11584 ASM_OUTPUT_SECTION (asm_out_file
, ABBREV_SECTION
);
11585 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
11586 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
11588 ASM_OUTPUT_SECTION (asm_out_file
, TEXT_SECTION
);
11589 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
11591 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_INFO_SECTION
);
11592 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
11593 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_LINE_SECTION
);
11594 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
11597 /* Output stuff that dwarf requires at the end of every file,
11598 and generate the DWARF-2 debugging info. */
11601 dwarf2out_finish ()
11603 limbo_die_node
*node
, *next_node
;
11606 /* Traverse the limbo die list, and add parent/child links. The only
11607 dies without parents that should be here are concrete instances of
11608 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11609 For concrete instances, we can get the parent die from the abstract
11611 for (node
= limbo_die_list
; node
; node
= next_node
)
11613 next_node
= node
->next
;
11616 if (die
->die_parent
== NULL
)
11618 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
11620 add_child_die (origin
->die_parent
, die
);
11621 else if (die
== comp_unit_die
)
11628 limbo_die_list
= NULL
;
11630 /* Walk through the list of incomplete types again, trying once more to
11631 emit full debugging info for them. */
11632 retry_incomplete_types ();
11634 /* We need to reverse all the dies before break_out_includes, or
11635 we'll see the end of an include file before the beginning. */
11636 reverse_all_dies (comp_unit_die
);
11638 /* Generate separate CUs for each of the include files we've seen.
11639 They will go into limbo_die_list. */
11640 if (flag_eliminate_dwarf2_dups
)
11641 break_out_includes (comp_unit_die
);
11643 /* Traverse the DIE's and add add sibling attributes to those DIE's
11644 that have children. */
11645 add_sibling_attributes (comp_unit_die
);
11646 for (node
= limbo_die_list
; node
; node
= node
->next
)
11647 add_sibling_attributes (node
->die
);
11649 /* Output a terminator label for the .text section. */
11650 fputc ('\n', asm_out_file
);
11651 ASM_OUTPUT_SECTION (asm_out_file
, TEXT_SECTION
);
11652 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, TEXT_END_LABEL
, 0);
11655 /* Output a terminator label for the .data section. */
11656 fputc ('\n', asm_out_file
);
11657 ASM_OUTPUT_SECTION (asm_out_file
, DATA_SECTION
);
11658 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, DATA_END_LABEL
, 0);
11660 /* Output a terminator label for the .bss section. */
11661 fputc ('\n', asm_out_file
);
11662 ASM_OUTPUT_SECTION (asm_out_file
, BSS_SECTION
);
11663 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BSS_END_LABEL
, 0);
11666 /* Output the source line correspondence table. */
11667 if (line_info_table_in_use
> 1 || separate_line_info_table_in_use
)
11669 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
11671 fputc ('\n', asm_out_file
);
11672 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_LINE_SECTION
);
11673 output_line_info ();
11676 /* We can only use the low/high_pc attributes if all of the code
11678 if (separate_line_info_table_in_use
== 0)
11680 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
11681 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
11684 add_AT_lbl_offset (comp_unit_die
, DW_AT_stmt_list
,
11685 debug_line_section_label
);
11688 #if 0 /* unimplemented */
11689 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
&& primary
)
11690 add_AT_unsigned (die
, DW_AT_macro_info
, 0);
11693 /* Output all of the compilation units. We put the main one last so that
11694 the offsets are available to output_pubnames. */
11695 for (node
= limbo_die_list
; node
; node
= node
->next
)
11696 output_comp_unit (node
->die
);
11697 output_comp_unit (comp_unit_die
);
11699 /* Output the abbreviation table. */
11700 fputc ('\n', asm_out_file
);
11701 ASM_OUTPUT_SECTION (asm_out_file
, ABBREV_SECTION
);
11702 output_abbrev_section ();
11704 if (pubname_table_in_use
)
11706 /* Output public names table. */
11707 fputc ('\n', asm_out_file
);
11708 ASM_OUTPUT_SECTION (asm_out_file
, PUBNAMES_SECTION
);
11709 output_pubnames ();
11712 /* We only put functions in the arange table, so don't write it out if
11713 we don't have any. */
11714 if (fde_table_in_use
)
11716 /* Output the address range information. */
11717 fputc ('\n', asm_out_file
);
11718 ASM_OUTPUT_SECTION (asm_out_file
, ARANGES_SECTION
);
11722 #endif /* DWARF2_DEBUGGING_INFO */