1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003 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 GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
39 #include "coretypes.h"
45 #include "hard-reg-set.h"
47 #include "insn-config.h"
55 #include "dwarf2out.h"
56 #include "dwarf2asm.h"
62 #include "diagnostic.h"
65 #include "langhooks.h"
68 #ifdef DWARF2_DEBUGGING_INFO
69 static void dwarf2out_source_line (unsigned int, const char *);
72 /* DWARF2 Abbreviation Glossary:
73 CFA = Canonical Frame Address
74 a fixed address on the stack which identifies a call frame.
75 We define it to be the value of SP just before the call insn.
76 The CFA register and offset, which may change during the course
77 of the function, are used to calculate its value at runtime.
78 CFI = Call Frame Instruction
79 an instruction for the DWARF2 abstract machine
80 CIE = Common Information Entry
81 information describing information common to one or more FDEs
82 DIE = Debugging Information Entry
83 FDE = Frame Description Entry
84 information describing the stack call frame, in particular,
85 how to restore registers
87 DW_CFA_... = DWARF2 CFA call frame instruction
88 DW_TAG_... = DWARF2 DIE tag */
90 /* Decide whether we want to emit frame unwind information for the current
94 dwarf2out_do_frame (void)
96 return (write_symbols
== DWARF2_DEBUG
97 || write_symbols
== VMS_AND_DWARF2_DEBUG
98 #ifdef DWARF2_FRAME_INFO
101 #ifdef DWARF2_UNWIND_INFO
102 || flag_unwind_tables
103 || (flag_exceptions
&& ! USING_SJLJ_EXCEPTIONS
)
108 /* The size of the target's pointer type. */
110 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
113 /* Default version of targetm.eh_frame_section. Note this must appear
114 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
118 default_eh_frame_section (void)
120 #ifdef EH_FRAME_SECTION_NAME
121 #ifdef HAVE_LD_RO_RW_SECTION_MIXING
122 int fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
123 int per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
124 int lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
128 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
129 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
130 && (per_encoding
& 0x70) != DW_EH_PE_absptr
131 && (per_encoding
& 0x70) != DW_EH_PE_aligned
132 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
133 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
135 named_section_flags (EH_FRAME_SECTION_NAME
, flags
);
137 named_section_flags (EH_FRAME_SECTION_NAME
, SECTION_WRITE
);
140 tree label
= get_file_function_name ('F');
143 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
144 (*targetm
.asm_out
.globalize_label
) (asm_out_file
, IDENTIFIER_POINTER (label
));
145 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
149 /* Array of RTXes referenced by the debugging information, which therefore
150 must be kept around forever. */
151 static GTY(()) varray_type used_rtx_varray
;
153 /* A pointer to the base of a list of incomplete types which might be
154 completed at some later time. incomplete_types_list needs to be a VARRAY
155 because we want to tell the garbage collector about it. */
156 static GTY(()) varray_type incomplete_types
;
158 /* A pointer to the base of a table of references to declaration
159 scopes. This table is a display which tracks the nesting
160 of declaration scopes at the current scope and containing
161 scopes. This table is used to find the proper place to
162 define type declaration DIE's. */
163 static GTY(()) varray_type decl_scope_table
;
165 /* How to start an assembler comment. */
166 #ifndef ASM_COMMENT_START
167 #define ASM_COMMENT_START ";#"
170 typedef struct dw_cfi_struct
*dw_cfi_ref
;
171 typedef struct dw_fde_struct
*dw_fde_ref
;
172 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
174 /* Call frames are described using a sequence of Call Frame
175 Information instructions. The register number, offset
176 and address fields are provided as possible operands;
177 their use is selected by the opcode field. */
179 enum dw_cfi_oprnd_type
{
181 dw_cfi_oprnd_reg_num
,
187 typedef union dw_cfi_oprnd_struct
GTY(())
189 unsigned long GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num
;
190 long int GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset
;
191 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr
;
192 struct dw_loc_descr_struct
* GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc
;
196 typedef struct dw_cfi_struct
GTY(())
198 dw_cfi_ref dw_cfi_next
;
199 enum dwarf_call_frame_info dw_cfi_opc
;
200 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
202 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
207 /* This is how we define the location of the CFA. We use to handle it
208 as REG + OFFSET all the time, but now it can be more complex.
209 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
210 Instead of passing around REG and OFFSET, we pass a copy
211 of this structure. */
212 typedef struct cfa_loc
GTY(())
217 int indirect
; /* 1 if CFA is accessed via a dereference. */
220 /* All call frame descriptions (FDE's) in the GCC generated DWARF
221 refer to a single Common Information Entry (CIE), defined at
222 the beginning of the .debug_frame section. This use of a single
223 CIE obviates the need to keep track of multiple CIE's
224 in the DWARF generation routines below. */
226 typedef struct dw_fde_struct
GTY(())
228 const char *dw_fde_begin
;
229 const char *dw_fde_current_label
;
230 const char *dw_fde_end
;
231 dw_cfi_ref dw_fde_cfi
;
232 unsigned funcdef_number
;
233 unsigned all_throwers_are_sibcalls
: 1;
234 unsigned nothrow
: 1;
235 unsigned uses_eh_lsda
: 1;
239 /* Maximum size (in bytes) of an artificially generated label. */
240 #define MAX_ARTIFICIAL_LABEL_BYTES 30
242 /* The size of addresses as they appear in the Dwarf 2 data.
243 Some architectures use word addresses to refer to code locations,
244 but Dwarf 2 info always uses byte addresses. On such machines,
245 Dwarf 2 addresses need to be larger than the architecture's
247 #ifndef DWARF2_ADDR_SIZE
248 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
251 /* The size in bytes of a DWARF field indicating an offset or length
252 relative to a debug info section, specified to be 4 bytes in the
253 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
256 #ifndef DWARF_OFFSET_SIZE
257 #define DWARF_OFFSET_SIZE 4
260 /* According to the (draft) DWARF 3 specification, the initial length
261 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
262 bytes are 0xffffffff, followed by the length stored in the next 8
265 However, the SGI/MIPS ABI uses an initial length which is equal to
266 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
268 #ifndef DWARF_INITIAL_LENGTH_SIZE
269 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
272 #define DWARF_VERSION 2
274 /* Round SIZE up to the nearest BOUNDARY. */
275 #define DWARF_ROUND(SIZE,BOUNDARY) \
276 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
278 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
279 #ifndef DWARF_CIE_DATA_ALIGNMENT
280 #ifdef STACK_GROWS_DOWNWARD
281 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
283 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
287 /* A pointer to the base of a table that contains frame description
288 information for each routine. */
289 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table
;
291 /* Number of elements currently allocated for fde_table. */
292 static GTY(()) unsigned fde_table_allocated
;
294 /* Number of elements in fde_table currently in use. */
295 static GTY(()) unsigned fde_table_in_use
;
297 /* Size (in elements) of increments by which we may expand the
299 #define FDE_TABLE_INCREMENT 256
301 /* A list of call frame insns for the CIE. */
302 static GTY(()) dw_cfi_ref cie_cfi_head
;
304 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
305 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
306 attribute that accelerates the lookup of the FDE associated
307 with the subprogram. This variable holds the table index of the FDE
308 associated with the current function (body) definition. */
309 static unsigned current_funcdef_fde
;
312 struct indirect_string_node
GTY(())
315 unsigned int refcount
;
320 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
322 static GTY(()) int dw2_string_counter
;
323 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
325 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
327 /* Forward declarations for functions defined in this file. */
329 static char *stripattributes (const char *);
330 static const char *dwarf_cfi_name (unsigned);
331 static dw_cfi_ref
new_cfi (void);
332 static void add_cfi (dw_cfi_ref
*, dw_cfi_ref
);
333 static void add_fde_cfi (const char *, dw_cfi_ref
);
334 static void lookup_cfa_1 (dw_cfi_ref
, dw_cfa_location
*);
335 static void lookup_cfa (dw_cfa_location
*);
336 static void reg_save (const char *, unsigned, unsigned, long);
337 static void initial_return_save (rtx
);
338 static long stack_adjust_offset (rtx
);
339 static void output_cfi (dw_cfi_ref
, dw_fde_ref
, int);
340 static void output_call_frame_info (int);
341 static void dwarf2out_stack_adjust (rtx
);
342 static void queue_reg_save (const char *, rtx
, long);
343 static void flush_queued_reg_saves (void);
344 static bool clobbers_queued_reg_save (rtx
);
345 static void dwarf2out_frame_debug_expr (rtx
, const char *);
347 /* Support for complex CFA locations. */
348 static void output_cfa_loc (dw_cfi_ref
);
349 static void get_cfa_from_loc_descr (dw_cfa_location
*,
350 struct dw_loc_descr_struct
*);
351 static struct dw_loc_descr_struct
*build_cfa_loc
353 static void def_cfa_1 (const char *, dw_cfa_location
*);
355 /* How to start an assembler comment. */
356 #ifndef ASM_COMMENT_START
357 #define ASM_COMMENT_START ";#"
360 /* Data and reference forms for relocatable data. */
361 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
362 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
364 #ifndef DEBUG_FRAME_SECTION
365 #define DEBUG_FRAME_SECTION ".debug_frame"
368 #ifndef FUNC_BEGIN_LABEL
369 #define FUNC_BEGIN_LABEL "LFB"
372 #ifndef FUNC_END_LABEL
373 #define FUNC_END_LABEL "LFE"
376 #define FRAME_BEGIN_LABEL "Lframe"
377 #define CIE_AFTER_SIZE_LABEL "LSCIE"
378 #define CIE_END_LABEL "LECIE"
379 #define FDE_LABEL "LSFDE"
380 #define FDE_AFTER_SIZE_LABEL "LASFDE"
381 #define FDE_END_LABEL "LEFDE"
382 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
383 #define LINE_NUMBER_END_LABEL "LELT"
384 #define LN_PROLOG_AS_LABEL "LASLTP"
385 #define LN_PROLOG_END_LABEL "LELTP"
386 #define DIE_LABEL_PREFIX "DW"
388 /* The DWARF 2 CFA column which tracks the return address. Normally this
389 is the column for PC, or the first column after all of the hard
391 #ifndef DWARF_FRAME_RETURN_COLUMN
393 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
395 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
399 /* The mapping from gcc register number to DWARF 2 CFA column number. By
400 default, we just provide columns for all registers. */
401 #ifndef DWARF_FRAME_REGNUM
402 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
405 /* The offset from the incoming value of %sp to the top of the stack frame
406 for the current function. */
407 #ifndef INCOMING_FRAME_SP_OFFSET
408 #define INCOMING_FRAME_SP_OFFSET 0
411 /* Hook used by __throw. */
414 expand_builtin_dwarf_sp_column (void)
416 return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
));
419 /* Return a pointer to a copy of the section string name S with all
420 attributes stripped off, and an asterisk prepended (for assemble_name). */
423 stripattributes (const char *s
)
425 char *stripped
= xmalloc (strlen (s
) + 2);
430 while (*s
&& *s
!= ',')
437 /* Generate code to initialize the register size table. */
440 expand_builtin_init_dwarf_reg_sizes (tree address
)
443 enum machine_mode mode
= TYPE_MODE (char_type_node
);
444 rtx addr
= expand_expr (address
, NULL_RTX
, VOIDmode
, 0);
445 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
447 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
448 if (DWARF_FRAME_REGNUM (i
) < DWARF_FRAME_REGISTERS
)
450 HOST_WIDE_INT offset
= DWARF_FRAME_REGNUM (i
) * GET_MODE_SIZE (mode
);
451 HOST_WIDE_INT size
= GET_MODE_SIZE (reg_raw_mode
[i
]);
456 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
460 /* Convert a DWARF call frame info. operation to its string name */
463 dwarf_cfi_name (unsigned int cfi_opc
)
467 case DW_CFA_advance_loc
:
468 return "DW_CFA_advance_loc";
470 return "DW_CFA_offset";
472 return "DW_CFA_restore";
476 return "DW_CFA_set_loc";
477 case DW_CFA_advance_loc1
:
478 return "DW_CFA_advance_loc1";
479 case DW_CFA_advance_loc2
:
480 return "DW_CFA_advance_loc2";
481 case DW_CFA_advance_loc4
:
482 return "DW_CFA_advance_loc4";
483 case DW_CFA_offset_extended
:
484 return "DW_CFA_offset_extended";
485 case DW_CFA_restore_extended
:
486 return "DW_CFA_restore_extended";
487 case DW_CFA_undefined
:
488 return "DW_CFA_undefined";
489 case DW_CFA_same_value
:
490 return "DW_CFA_same_value";
491 case DW_CFA_register
:
492 return "DW_CFA_register";
493 case DW_CFA_remember_state
:
494 return "DW_CFA_remember_state";
495 case DW_CFA_restore_state
:
496 return "DW_CFA_restore_state";
498 return "DW_CFA_def_cfa";
499 case DW_CFA_def_cfa_register
:
500 return "DW_CFA_def_cfa_register";
501 case DW_CFA_def_cfa_offset
:
502 return "DW_CFA_def_cfa_offset";
505 case DW_CFA_def_cfa_expression
:
506 return "DW_CFA_def_cfa_expression";
507 case DW_CFA_expression
:
508 return "DW_CFA_expression";
509 case DW_CFA_offset_extended_sf
:
510 return "DW_CFA_offset_extended_sf";
511 case DW_CFA_def_cfa_sf
:
512 return "DW_CFA_def_cfa_sf";
513 case DW_CFA_def_cfa_offset_sf
:
514 return "DW_CFA_def_cfa_offset_sf";
516 /* SGI/MIPS specific */
517 case DW_CFA_MIPS_advance_loc8
:
518 return "DW_CFA_MIPS_advance_loc8";
521 case DW_CFA_GNU_window_save
:
522 return "DW_CFA_GNU_window_save";
523 case DW_CFA_GNU_args_size
:
524 return "DW_CFA_GNU_args_size";
525 case DW_CFA_GNU_negative_offset_extended
:
526 return "DW_CFA_GNU_negative_offset_extended";
529 return "DW_CFA_<unknown>";
533 /* Return a pointer to a newly allocated Call Frame Instruction. */
535 static inline dw_cfi_ref
538 dw_cfi_ref cfi
= (dw_cfi_ref
) ggc_alloc (sizeof (dw_cfi_node
));
540 cfi
->dw_cfi_next
= NULL
;
541 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
542 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
547 /* Add a Call Frame Instruction to list of instructions. */
550 add_cfi (dw_cfi_ref
*list_head
, dw_cfi_ref cfi
)
554 /* Find the end of the chain. */
555 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
561 /* Generate a new label for the CFI info to refer to. */
564 dwarf2out_cfi_label (void)
566 static char label
[20];
568 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", dwarf2out_cfi_label_num
++);
569 ASM_OUTPUT_LABEL (asm_out_file
, label
);
573 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
574 or to the CIE if LABEL is NULL. */
577 add_fde_cfi (const char *label
, dw_cfi_ref cfi
)
581 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
584 label
= dwarf2out_cfi_label ();
586 if (fde
->dw_fde_current_label
== NULL
587 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
591 fde
->dw_fde_current_label
= label
= xstrdup (label
);
593 /* Set the location counter to the new label. */
595 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
596 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
597 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
600 add_cfi (&fde
->dw_fde_cfi
, cfi
);
604 add_cfi (&cie_cfi_head
, cfi
);
607 /* Subroutine of lookup_cfa. */
610 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
)
612 switch (cfi
->dw_cfi_opc
)
614 case DW_CFA_def_cfa_offset
:
615 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
617 case DW_CFA_def_cfa_register
:
618 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
621 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
622 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
624 case DW_CFA_def_cfa_expression
:
625 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
632 /* Find the previous value for the CFA. */
635 lookup_cfa (dw_cfa_location
*loc
)
639 loc
->reg
= (unsigned long) -1;
642 loc
->base_offset
= 0;
644 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
645 lookup_cfa_1 (cfi
, loc
);
647 if (fde_table_in_use
)
649 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
650 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
651 lookup_cfa_1 (cfi
, loc
);
655 /* The current rule for calculating the DWARF2 canonical frame address. */
656 static dw_cfa_location cfa
;
658 /* The register used for saving registers to the stack, and its offset
660 static dw_cfa_location cfa_store
;
662 /* The running total of the size of arguments pushed onto the stack. */
663 static long args_size
;
665 /* The last args_size we actually output. */
666 static long old_args_size
;
668 /* Entry point to update the canonical frame address (CFA).
669 LABEL is passed to add_fde_cfi. The value of CFA is now to be
670 calculated from REG+OFFSET. */
673 dwarf2out_def_cfa (const char *label
, unsigned int reg
, long int offset
)
680 def_cfa_1 (label
, &loc
);
683 /* This routine does the actual work. The CFA is now calculated from
684 the dw_cfa_location structure. */
687 def_cfa_1 (const char *label
, dw_cfa_location
*loc_p
)
690 dw_cfa_location old_cfa
, loc
;
695 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
696 cfa_store
.offset
= loc
.offset
;
698 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
699 lookup_cfa (&old_cfa
);
701 /* If nothing changed, no need to issue any call frame instructions. */
702 if (loc
.reg
== old_cfa
.reg
&& loc
.offset
== old_cfa
.offset
703 && loc
.indirect
== old_cfa
.indirect
704 && (loc
.indirect
== 0 || loc
.base_offset
== old_cfa
.base_offset
))
709 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
711 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
712 indicating the CFA register did not change but the offset
714 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
715 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
718 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
719 else if (loc
.offset
== old_cfa
.offset
&& old_cfa
.reg
!= (unsigned long) -1
722 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
723 indicating the CFA register has changed to <register> but the
724 offset has not changed. */
725 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
726 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
730 else if (loc
.indirect
== 0)
732 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
733 indicating the CFA register has changed to <register> with
734 the specified offset. */
735 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
736 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
737 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
741 /* Construct a DW_CFA_def_cfa_expression instruction to
742 calculate the CFA using a full location expression since no
743 register-offset pair is available. */
744 struct dw_loc_descr_struct
*loc_list
;
746 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
747 loc_list
= build_cfa_loc (&loc
);
748 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
751 add_fde_cfi (label
, cfi
);
754 /* Add the CFI for saving a register. REG is the CFA column number.
755 LABEL is passed to add_fde_cfi.
756 If SREG is -1, the register is saved at OFFSET from the CFA;
757 otherwise it is saved in SREG. */
760 reg_save (const char *label
, unsigned int reg
, unsigned int sreg
, long int offset
)
762 dw_cfi_ref cfi
= new_cfi ();
764 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
766 /* The following comparison is correct. -1 is used to indicate that
767 the value isn't a register number. */
768 if (sreg
== (unsigned int) -1)
771 /* The register number won't fit in 6 bits, so we have to use
773 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
775 cfi
->dw_cfi_opc
= DW_CFA_offset
;
777 #ifdef ENABLE_CHECKING
779 /* If we get an offset that is not a multiple of
780 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
781 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
783 long check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
785 if (check_offset
* DWARF_CIE_DATA_ALIGNMENT
!= offset
)
789 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
791 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
793 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
795 else if (sreg
== reg
)
796 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
800 cfi
->dw_cfi_opc
= DW_CFA_register
;
801 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
804 add_fde_cfi (label
, cfi
);
807 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
808 This CFI tells the unwinder that it needs to restore the window registers
809 from the previous frame's window save area.
811 ??? Perhaps we should note in the CIE where windows are saved (instead of
812 assuming 0(cfa)) and what registers are in the window. */
815 dwarf2out_window_save (const char *label
)
817 dw_cfi_ref cfi
= new_cfi ();
819 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
820 add_fde_cfi (label
, cfi
);
823 /* Add a CFI to update the running total of the size of arguments
824 pushed onto the stack. */
827 dwarf2out_args_size (const char *label
, long int size
)
831 if (size
== old_args_size
)
834 old_args_size
= size
;
837 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
838 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
839 add_fde_cfi (label
, cfi
);
842 /* Entry point for saving a register to the stack. REG is the GCC register
843 number. LABEL and OFFSET are passed to reg_save. */
846 dwarf2out_reg_save (const char *label
, unsigned int reg
, long int offset
)
848 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
851 /* Entry point for saving the return address in the stack.
852 LABEL and OFFSET are passed to reg_save. */
855 dwarf2out_return_save (const char *label
, long int offset
)
857 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, -1, offset
);
860 /* Entry point for saving the return address in a register.
861 LABEL and SREG are passed to reg_save. */
864 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
866 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, sreg
, 0);
869 /* Record the initial position of the return address. RTL is
870 INCOMING_RETURN_ADDR_RTX. */
873 initial_return_save (rtx rtl
)
875 unsigned int reg
= (unsigned int) -1;
876 HOST_WIDE_INT offset
= 0;
878 switch (GET_CODE (rtl
))
881 /* RA is in a register. */
882 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
886 /* RA is on the stack. */
888 switch (GET_CODE (rtl
))
891 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
897 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
899 offset
= INTVAL (XEXP (rtl
, 1));
903 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
905 offset
= -INTVAL (XEXP (rtl
, 1));
915 /* The return address is at some offset from any value we can
916 actually load. For instance, on the SPARC it is in %i7+8. Just
917 ignore the offset for now; it doesn't matter for unwinding frames. */
918 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
920 initial_return_save (XEXP (rtl
, 0));
927 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
930 /* Given a SET, calculate the amount of stack adjustment it
934 stack_adjust_offset (rtx pattern
)
936 rtx src
= SET_SRC (pattern
);
937 rtx dest
= SET_DEST (pattern
);
938 HOST_WIDE_INT offset
= 0;
941 if (dest
== stack_pointer_rtx
)
943 /* (set (reg sp) (plus (reg sp) (const_int))) */
944 code
= GET_CODE (src
);
945 if (! (code
== PLUS
|| code
== MINUS
)
946 || XEXP (src
, 0) != stack_pointer_rtx
947 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
950 offset
= INTVAL (XEXP (src
, 1));
954 else if (GET_CODE (dest
) == MEM
)
956 /* (set (mem (pre_dec (reg sp))) (foo)) */
957 src
= XEXP (dest
, 0);
958 code
= GET_CODE (src
);
964 if (XEXP (src
, 0) == stack_pointer_rtx
)
966 rtx val
= XEXP (XEXP (src
, 1), 1);
967 /* We handle only adjustments by constant amount. */
968 if (GET_CODE (XEXP (src
, 1)) != PLUS
||
969 GET_CODE (val
) != CONST_INT
)
971 offset
= -INTVAL (val
);
978 if (XEXP (src
, 0) == stack_pointer_rtx
)
980 offset
= GET_MODE_SIZE (GET_MODE (dest
));
987 if (XEXP (src
, 0) == stack_pointer_rtx
)
989 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1004 /* Check INSN to see if it looks like a push or a stack adjustment, and
1005 make a note of it if it does. EH uses this information to find out how
1006 much extra space it needs to pop off the stack. */
1009 dwarf2out_stack_adjust (rtx insn
)
1011 HOST_WIDE_INT offset
;
1015 if (!flag_asynchronous_unwind_tables
&& GET_CODE (insn
) == CALL_INSN
)
1017 /* Extract the size of the args from the CALL rtx itself. */
1018 insn
= PATTERN (insn
);
1019 if (GET_CODE (insn
) == PARALLEL
)
1020 insn
= XVECEXP (insn
, 0, 0);
1021 if (GET_CODE (insn
) == SET
)
1022 insn
= SET_SRC (insn
);
1023 if (GET_CODE (insn
) != CALL
)
1026 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1030 /* If only calls can throw, and we have a frame pointer,
1031 save up adjustments until we see the CALL_INSN. */
1032 else if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1035 if (GET_CODE (insn
) == BARRIER
)
1037 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1038 the compiler will have already emitted a stack adjustment, but
1039 doesn't bother for calls to noreturn functions. */
1040 #ifdef STACK_GROWS_DOWNWARD
1041 offset
= -args_size
;
1046 else if (GET_CODE (PATTERN (insn
)) == SET
)
1047 offset
= stack_adjust_offset (PATTERN (insn
));
1048 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1049 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1051 /* There may be stack adjustments inside compound insns. Search
1053 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1054 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1055 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1063 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1064 cfa
.offset
+= offset
;
1066 #ifndef STACK_GROWS_DOWNWARD
1070 args_size
+= offset
;
1074 label
= dwarf2out_cfi_label ();
1075 def_cfa_1 (label
, &cfa
);
1076 dwarf2out_args_size (label
, args_size
);
1081 /* We delay emitting a register save until either (a) we reach the end
1082 of the prologue or (b) the register is clobbered. This clusters
1083 register saves so that there are fewer pc advances. */
1085 struct queued_reg_save
GTY(())
1087 struct queued_reg_save
*next
;
1092 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1094 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1095 static const char *last_reg_save_label
;
1098 queue_reg_save (const char *label
, rtx reg
, long int offset
)
1100 struct queued_reg_save
*q
= ggc_alloc (sizeof (*q
));
1102 q
->next
= queued_reg_saves
;
1104 q
->cfa_offset
= offset
;
1105 queued_reg_saves
= q
;
1107 last_reg_save_label
= label
;
1111 flush_queued_reg_saves (void)
1113 struct queued_reg_save
*q
, *next
;
1115 for (q
= queued_reg_saves
; q
; q
= next
)
1117 dwarf2out_reg_save (last_reg_save_label
, REGNO (q
->reg
), q
->cfa_offset
);
1121 queued_reg_saves
= NULL
;
1122 last_reg_save_label
= NULL
;
1126 clobbers_queued_reg_save (rtx insn
)
1128 struct queued_reg_save
*q
;
1130 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1131 if (modified_in_p (q
->reg
, insn
))
1138 /* A temporary register holding an integral value used in adjusting SP
1139 or setting up the store_reg. The "offset" field holds the integer
1140 value, not an offset. */
1141 static dw_cfa_location cfa_temp
;
1143 /* Record call frame debugging information for an expression EXPR,
1144 which either sets SP or FP (adjusting how we calculate the frame
1145 address) or saves a register to the stack. LABEL indicates the
1148 This function encodes a state machine mapping rtxes to actions on
1149 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1150 users need not read the source code.
1152 The High-Level Picture
1154 Changes in the register we use to calculate the CFA: Currently we
1155 assume that if you copy the CFA register into another register, we
1156 should take the other one as the new CFA register; this seems to
1157 work pretty well. If it's wrong for some target, it's simple
1158 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1160 Changes in the register we use for saving registers to the stack:
1161 This is usually SP, but not always. Again, we deduce that if you
1162 copy SP into another register (and SP is not the CFA register),
1163 then the new register is the one we will be using for register
1164 saves. This also seems to work.
1166 Register saves: There's not much guesswork about this one; if
1167 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1168 register save, and the register used to calculate the destination
1169 had better be the one we think we're using for this purpose.
1171 Except: If the register being saved is the CFA register, and the
1172 offset is nonzero, we are saving the CFA, so we assume we have to
1173 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1174 the intent is to save the value of SP from the previous frame.
1176 Invariants / Summaries of Rules
1178 cfa current rule for calculating the CFA. It usually
1179 consists of a register and an offset.
1180 cfa_store register used by prologue code to save things to the stack
1181 cfa_store.offset is the offset from the value of
1182 cfa_store.reg to the actual CFA
1183 cfa_temp register holding an integral value. cfa_temp.offset
1184 stores the value, which will be used to adjust the
1185 stack pointer. cfa_temp is also used like cfa_store,
1186 to track stores to the stack via fp or a temp reg.
1188 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1189 with cfa.reg as the first operand changes the cfa.reg and its
1190 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1193 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1194 expression yielding a constant. This sets cfa_temp.reg
1195 and cfa_temp.offset.
1197 Rule 5: Create a new register cfa_store used to save items to the
1200 Rules 10-14: Save a register to the stack. Define offset as the
1201 difference of the original location and cfa_store's
1202 location (or cfa_temp's location if cfa_temp is used).
1206 "{a,b}" indicates a choice of a xor b.
1207 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1210 (set <reg1> <reg2>:cfa.reg)
1211 effects: cfa.reg = <reg1>
1212 cfa.offset unchanged
1213 cfa_temp.reg = <reg1>
1214 cfa_temp.offset = cfa.offset
1217 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1218 {<const_int>,<reg>:cfa_temp.reg}))
1219 effects: cfa.reg = sp if fp used
1220 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1221 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1222 if cfa_store.reg==sp
1225 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1226 effects: cfa.reg = fp
1227 cfa_offset += +/- <const_int>
1230 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1231 constraints: <reg1> != fp
1233 effects: cfa.reg = <reg1>
1234 cfa_temp.reg = <reg1>
1235 cfa_temp.offset = cfa.offset
1238 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1239 constraints: <reg1> != fp
1241 effects: cfa_store.reg = <reg1>
1242 cfa_store.offset = cfa.offset - cfa_temp.offset
1245 (set <reg> <const_int>)
1246 effects: cfa_temp.reg = <reg>
1247 cfa_temp.offset = <const_int>
1250 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1251 effects: cfa_temp.reg = <reg1>
1252 cfa_temp.offset |= <const_int>
1255 (set <reg> (high <exp>))
1259 (set <reg> (lo_sum <exp> <const_int>))
1260 effects: cfa_temp.reg = <reg>
1261 cfa_temp.offset = <const_int>
1264 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1265 effects: cfa_store.offset -= <const_int>
1266 cfa.offset = cfa_store.offset if cfa.reg == sp
1268 cfa.base_offset = -cfa_store.offset
1271 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1272 effects: cfa_store.offset += -/+ mode_size(mem)
1273 cfa.offset = cfa_store.offset if cfa.reg == sp
1275 cfa.base_offset = -cfa_store.offset
1278 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1281 effects: cfa.reg = <reg1>
1282 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1285 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1286 effects: cfa.reg = <reg1>
1287 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1290 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1291 effects: cfa.reg = <reg1>
1292 cfa.base_offset = -cfa_temp.offset
1293 cfa_temp.offset -= mode_size(mem) */
1296 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
1299 HOST_WIDE_INT offset
;
1301 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1302 the PARALLEL independently. The first element is always processed if
1303 it is a SET. This is for backward compatibility. Other elements
1304 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1305 flag is set in them. */
1306 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1309 int limit
= XVECLEN (expr
, 0);
1311 for (par_index
= 0; par_index
< limit
; par_index
++)
1312 if (GET_CODE (XVECEXP (expr
, 0, par_index
)) == SET
1313 && (RTX_FRAME_RELATED_P (XVECEXP (expr
, 0, par_index
))
1315 dwarf2out_frame_debug_expr (XVECEXP (expr
, 0, par_index
), label
);
1320 if (GET_CODE (expr
) != SET
)
1323 src
= SET_SRC (expr
);
1324 dest
= SET_DEST (expr
);
1326 switch (GET_CODE (dest
))
1330 /* Update the CFA rule wrt SP or FP. Make sure src is
1331 relative to the current CFA register. */
1332 switch (GET_CODE (src
))
1334 /* Setting FP from SP. */
1336 if (cfa
.reg
== (unsigned) REGNO (src
))
1342 /* We used to require that dest be either SP or FP, but the
1343 ARM copies SP to a temporary register, and from there to
1344 FP. So we just rely on the backends to only set
1345 RTX_FRAME_RELATED_P on appropriate insns. */
1346 cfa
.reg
= REGNO (dest
);
1347 cfa_temp
.reg
= cfa
.reg
;
1348 cfa_temp
.offset
= cfa
.offset
;
1354 if (dest
== stack_pointer_rtx
)
1358 switch (GET_CODE (XEXP (src
, 1)))
1361 offset
= INTVAL (XEXP (src
, 1));
1364 if ((unsigned) REGNO (XEXP (src
, 1)) != cfa_temp
.reg
)
1366 offset
= cfa_temp
.offset
;
1372 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1374 /* Restoring SP from FP in the epilogue. */
1375 if (cfa
.reg
!= (unsigned) HARD_FRAME_POINTER_REGNUM
)
1377 cfa
.reg
= STACK_POINTER_REGNUM
;
1379 else if (GET_CODE (src
) == LO_SUM
)
1380 /* Assume we've set the source reg of the LO_SUM from sp. */
1382 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1385 if (GET_CODE (src
) != MINUS
)
1387 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1388 cfa
.offset
+= offset
;
1389 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1390 cfa_store
.offset
+= offset
;
1392 else if (dest
== hard_frame_pointer_rtx
)
1395 /* Either setting the FP from an offset of the SP,
1396 or adjusting the FP */
1397 if (! frame_pointer_needed
)
1400 if (GET_CODE (XEXP (src
, 0)) == REG
1401 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1402 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1404 offset
= INTVAL (XEXP (src
, 1));
1405 if (GET_CODE (src
) != MINUS
)
1407 cfa
.offset
+= offset
;
1408 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1415 if (GET_CODE (src
) == MINUS
)
1419 if (GET_CODE (XEXP (src
, 0)) == REG
1420 && REGNO (XEXP (src
, 0)) == cfa
.reg
1421 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1423 /* Setting a temporary CFA register that will be copied
1424 into the FP later on. */
1425 offset
= - INTVAL (XEXP (src
, 1));
1426 cfa
.offset
+= offset
;
1427 cfa
.reg
= REGNO (dest
);
1428 /* Or used to save regs to the stack. */
1429 cfa_temp
.reg
= cfa
.reg
;
1430 cfa_temp
.offset
= cfa
.offset
;
1434 else if (GET_CODE (XEXP (src
, 0)) == REG
1435 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1436 && XEXP (src
, 1) == stack_pointer_rtx
)
1438 /* Setting a scratch register that we will use instead
1439 of SP for saving registers to the stack. */
1440 if (cfa
.reg
!= STACK_POINTER_REGNUM
)
1442 cfa_store
.reg
= REGNO (dest
);
1443 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
1447 else if (GET_CODE (src
) == LO_SUM
1448 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1450 cfa_temp
.reg
= REGNO (dest
);
1451 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
1460 cfa_temp
.reg
= REGNO (dest
);
1461 cfa_temp
.offset
= INTVAL (src
);
1466 if (GET_CODE (XEXP (src
, 0)) != REG
1467 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp
.reg
1468 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1471 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
1472 cfa_temp
.reg
= REGNO (dest
);
1473 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
1476 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1477 which will fill in all of the bits. */
1486 def_cfa_1 (label
, &cfa
);
1490 if (GET_CODE (src
) != REG
)
1493 /* Saving a register to the stack. Make sure dest is relative to the
1495 switch (GET_CODE (XEXP (dest
, 0)))
1500 /* We can't handle variable size modifications. */
1501 if (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1)) != CONST_INT
)
1503 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1505 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1506 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1509 cfa_store
.offset
+= offset
;
1510 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1511 cfa
.offset
= cfa_store
.offset
;
1513 offset
= -cfa_store
.offset
;
1519 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1520 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1523 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1524 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1527 cfa_store
.offset
+= offset
;
1528 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1529 cfa
.offset
= cfa_store
.offset
;
1531 offset
= -cfa_store
.offset
;
1535 /* With an offset. */
1539 if (GET_CODE (XEXP (XEXP (dest
, 0), 1)) != CONST_INT
)
1541 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1542 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1545 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1546 offset
-= cfa_store
.offset
;
1547 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1548 offset
-= cfa_temp
.offset
;
1554 /* Without an offset. */
1556 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1557 offset
= -cfa_store
.offset
;
1558 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1559 offset
= -cfa_temp
.offset
;
1566 if (cfa_temp
.reg
!= (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1568 offset
= -cfa_temp
.offset
;
1569 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1576 if (REGNO (src
) != STACK_POINTER_REGNUM
1577 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1578 && (unsigned) REGNO (src
) == cfa
.reg
)
1580 /* We're storing the current CFA reg into the stack. */
1582 if (cfa
.offset
== 0)
1584 /* If the source register is exactly the CFA, assume
1585 we're saving SP like any other register; this happens
1587 def_cfa_1 (label
, &cfa
);
1588 queue_reg_save (label
, stack_pointer_rtx
, offset
);
1593 /* Otherwise, we'll need to look in the stack to
1594 calculate the CFA. */
1595 rtx x
= XEXP (dest
, 0);
1597 if (GET_CODE (x
) != REG
)
1599 if (GET_CODE (x
) != REG
)
1602 cfa
.reg
= REGNO (x
);
1603 cfa
.base_offset
= offset
;
1605 def_cfa_1 (label
, &cfa
);
1610 def_cfa_1 (label
, &cfa
);
1611 queue_reg_save (label
, src
, offset
);
1619 /* Record call frame debugging information for INSN, which either
1620 sets SP or FP (adjusting how we calculate the frame address) or saves a
1621 register to the stack. If INSN is NULL_RTX, initialize our state. */
1624 dwarf2out_frame_debug (rtx insn
)
1629 if (insn
== NULL_RTX
)
1631 /* Flush any queued register saves. */
1632 flush_queued_reg_saves ();
1634 /* Set up state for generating call frame debug info. */
1636 if (cfa
.reg
!= (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1639 cfa
.reg
= STACK_POINTER_REGNUM
;
1642 cfa_temp
.offset
= 0;
1646 if (GET_CODE (insn
) != INSN
|| clobbers_queued_reg_save (insn
))
1647 flush_queued_reg_saves ();
1649 if (! RTX_FRAME_RELATED_P (insn
))
1651 if (!ACCUMULATE_OUTGOING_ARGS
)
1652 dwarf2out_stack_adjust (insn
);
1657 label
= dwarf2out_cfi_label ();
1658 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1660 insn
= XEXP (src
, 0);
1662 insn
= PATTERN (insn
);
1664 dwarf2out_frame_debug_expr (insn
, label
);
1669 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1670 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1671 (enum dwarf_call_frame_info cfi
);
1673 static enum dw_cfi_oprnd_type
1674 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
1679 case DW_CFA_GNU_window_save
:
1680 return dw_cfi_oprnd_unused
;
1682 case DW_CFA_set_loc
:
1683 case DW_CFA_advance_loc1
:
1684 case DW_CFA_advance_loc2
:
1685 case DW_CFA_advance_loc4
:
1686 case DW_CFA_MIPS_advance_loc8
:
1687 return dw_cfi_oprnd_addr
;
1690 case DW_CFA_offset_extended
:
1691 case DW_CFA_def_cfa
:
1692 case DW_CFA_offset_extended_sf
:
1693 case DW_CFA_def_cfa_sf
:
1694 case DW_CFA_restore_extended
:
1695 case DW_CFA_undefined
:
1696 case DW_CFA_same_value
:
1697 case DW_CFA_def_cfa_register
:
1698 case DW_CFA_register
:
1699 return dw_cfi_oprnd_reg_num
;
1701 case DW_CFA_def_cfa_offset
:
1702 case DW_CFA_GNU_args_size
:
1703 case DW_CFA_def_cfa_offset_sf
:
1704 return dw_cfi_oprnd_offset
;
1706 case DW_CFA_def_cfa_expression
:
1707 case DW_CFA_expression
:
1708 return dw_cfi_oprnd_loc
;
1715 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1716 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1717 (enum dwarf_call_frame_info cfi
);
1719 static enum dw_cfi_oprnd_type
1720 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
1724 case DW_CFA_def_cfa
:
1725 case DW_CFA_def_cfa_sf
:
1727 case DW_CFA_offset_extended_sf
:
1728 case DW_CFA_offset_extended
:
1729 return dw_cfi_oprnd_offset
;
1731 case DW_CFA_register
:
1732 return dw_cfi_oprnd_reg_num
;
1735 return dw_cfi_oprnd_unused
;
1739 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1741 /* Output a Call Frame Information opcode and its operand(s). */
1744 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
1746 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1747 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1748 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
1749 "DW_CFA_advance_loc 0x%lx",
1750 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1751 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1753 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1754 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1755 "DW_CFA_offset, column 0x%lx",
1756 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1757 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1759 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1760 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1761 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1762 "DW_CFA_restore, column 0x%lx",
1763 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1766 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
1767 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
1769 switch (cfi
->dw_cfi_opc
)
1771 case DW_CFA_set_loc
:
1773 dw2_asm_output_encoded_addr_rtx (
1774 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1775 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
1778 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
1779 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
1782 case DW_CFA_advance_loc1
:
1783 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1784 fde
->dw_fde_current_label
, NULL
);
1785 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1788 case DW_CFA_advance_loc2
:
1789 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1790 fde
->dw_fde_current_label
, NULL
);
1791 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1794 case DW_CFA_advance_loc4
:
1795 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1796 fde
->dw_fde_current_label
, NULL
);
1797 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1800 case DW_CFA_MIPS_advance_loc8
:
1801 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1802 fde
->dw_fde_current_label
, NULL
);
1803 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1806 case DW_CFA_offset_extended
:
1807 case DW_CFA_def_cfa
:
1808 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1810 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1813 case DW_CFA_offset_extended_sf
:
1814 case DW_CFA_def_cfa_sf
:
1815 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1817 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1820 case DW_CFA_restore_extended
:
1821 case DW_CFA_undefined
:
1822 case DW_CFA_same_value
:
1823 case DW_CFA_def_cfa_register
:
1824 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1828 case DW_CFA_register
:
1829 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1831 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
,
1835 case DW_CFA_def_cfa_offset
:
1836 case DW_CFA_GNU_args_size
:
1837 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1840 case DW_CFA_def_cfa_offset_sf
:
1841 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1844 case DW_CFA_GNU_window_save
:
1847 case DW_CFA_def_cfa_expression
:
1848 case DW_CFA_expression
:
1849 output_cfa_loc (cfi
);
1852 case DW_CFA_GNU_negative_offset_extended
:
1853 /* Obsoleted by DW_CFA_offset_extended_sf. */
1862 /* Output the call frame information used to used to record information
1863 that relates to calculating the frame pointer, and records the
1864 location of saved registers. */
1867 output_call_frame_info (int for_eh
)
1872 char l1
[20], l2
[20], section_start_label
[20];
1873 bool any_lsda_needed
= false;
1874 char augmentation
[6];
1875 int augmentation_size
;
1876 int fde_encoding
= DW_EH_PE_absptr
;
1877 int per_encoding
= DW_EH_PE_absptr
;
1878 int lsda_encoding
= DW_EH_PE_absptr
;
1880 /* Don't emit a CIE if there won't be any FDEs. */
1881 if (fde_table_in_use
== 0)
1884 /* If we don't have any functions we'll want to unwind out of, don't
1885 emit any EH unwind information. Note that if exceptions aren't
1886 enabled, we won't have collected nothrow information, and if we
1887 asked for asynchronous tables, we always want this info. */
1890 bool any_eh_needed
= !flag_exceptions
|| flag_asynchronous_unwind_tables
;
1892 for (i
= 0; i
< fde_table_in_use
; i
++)
1893 if (fde_table
[i
].uses_eh_lsda
)
1894 any_eh_needed
= any_lsda_needed
= true;
1895 else if (! fde_table
[i
].nothrow
1896 && ! fde_table
[i
].all_throwers_are_sibcalls
)
1897 any_eh_needed
= true;
1899 if (! any_eh_needed
)
1903 /* We're going to be generating comments, so turn on app. */
1908 (*targetm
.asm_out
.eh_frame_section
) ();
1910 named_section_flags (DEBUG_FRAME_SECTION
, SECTION_DEBUG
);
1912 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
1913 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
1915 /* Output the CIE. */
1916 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
1917 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
1918 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
1919 "Length of Common Information Entry");
1920 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1922 /* Now that the CIE pointer is PC-relative for EH,
1923 use 0 to identify the CIE. */
1924 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
1925 (for_eh
? 0 : DW_CIE_ID
),
1926 "CIE Identifier Tag");
1928 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
1930 augmentation
[0] = 0;
1931 augmentation_size
= 0;
1937 z Indicates that a uleb128 is present to size the
1938 augmentation section.
1939 L Indicates the encoding (and thus presence) of
1940 an LSDA pointer in the FDE augmentation.
1941 R Indicates a non-default pointer encoding for
1943 P Indicates the presence of an encoding + language
1944 personality routine in the CIE augmentation. */
1946 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1947 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1948 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1950 p
= augmentation
+ 1;
1951 if (eh_personality_libfunc
)
1954 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
1956 if (any_lsda_needed
)
1959 augmentation_size
+= 1;
1961 if (fde_encoding
!= DW_EH_PE_absptr
)
1964 augmentation_size
+= 1;
1966 if (p
> augmentation
+ 1)
1968 augmentation
[0] = 'z';
1972 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1973 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
1975 int offset
= ( 4 /* Length */
1977 + 1 /* CIE version */
1978 + strlen (augmentation
) + 1 /* Augmentation */
1979 + size_of_uleb128 (1) /* Code alignment */
1980 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
1982 + 1 /* Augmentation size */
1983 + 1 /* Personality encoding */ );
1984 int pad
= -offset
& (PTR_SIZE
- 1);
1986 augmentation_size
+= pad
;
1988 /* Augmentations should be small, so there's scarce need to
1989 iterate for a solution. Die if we exceed one uleb128 byte. */
1990 if (size_of_uleb128 (augmentation_size
) != 1)
1995 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
1996 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1997 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
1998 "CIE Data Alignment Factor");
1999 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN
, "CIE RA Column");
2001 if (augmentation
[0])
2003 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
2004 if (eh_personality_libfunc
)
2006 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
2007 eh_data_format_name (per_encoding
));
2008 dw2_asm_output_encoded_addr_rtx (per_encoding
,
2009 eh_personality_libfunc
, NULL
);
2012 if (any_lsda_needed
)
2013 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
2014 eh_data_format_name (lsda_encoding
));
2016 if (fde_encoding
!= DW_EH_PE_absptr
)
2017 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
2018 eh_data_format_name (fde_encoding
));
2021 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2022 output_cfi (cfi
, NULL
, for_eh
);
2024 /* Pad the CIE out to an address sized boundary. */
2025 ASM_OUTPUT_ALIGN (asm_out_file
,
2026 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
2027 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2029 /* Loop through all of the FDE's. */
2030 for (i
= 0; i
< fde_table_in_use
; i
++)
2032 fde
= &fde_table
[i
];
2034 /* Don't emit EH unwind info for leaf functions that don't need it. */
2035 if (for_eh
&& !flag_asynchronous_unwind_tables
&& flag_exceptions
2036 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
2037 && !fde
->uses_eh_lsda
)
2040 (*targetm
.asm_out
.internal_label
) (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
2041 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
2042 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
2043 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2045 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2048 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
2050 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
2055 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
2056 gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
),
2057 "FDE initial location");
2058 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2059 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2060 "FDE address range");
2064 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
2065 "FDE initial location");
2066 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2067 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2068 "FDE address range");
2071 if (augmentation
[0])
2073 if (any_lsda_needed
)
2075 int size
= size_of_encoded_value (lsda_encoding
);
2077 if (lsda_encoding
== DW_EH_PE_aligned
)
2079 int offset
= ( 4 /* Length */
2080 + 4 /* CIE offset */
2081 + 2 * size_of_encoded_value (fde_encoding
)
2082 + 1 /* Augmentation size */ );
2083 int pad
= -offset
& (PTR_SIZE
- 1);
2086 if (size_of_uleb128 (size
) != 1)
2090 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2092 if (fde
->uses_eh_lsda
)
2094 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2095 fde
->funcdef_number
);
2096 dw2_asm_output_encoded_addr_rtx (
2097 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2098 "Language Specific Data Area");
2102 if (lsda_encoding
== DW_EH_PE_aligned
)
2103 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2105 (size_of_encoded_value (lsda_encoding
), 0,
2106 "Language Specific Data Area (none)");
2110 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2113 /* Loop through the Call Frame Instructions associated with
2115 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2116 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2117 output_cfi (cfi
, fde
, for_eh
);
2119 /* Pad the FDE out to an address sized boundary. */
2120 ASM_OUTPUT_ALIGN (asm_out_file
,
2121 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2122 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2125 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
2126 dw2_asm_output_data (4, 0, "End of Table");
2127 #ifdef MIPS_DEBUGGING_INFO
2128 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2129 get a value of 0. Putting .align 0 after the label fixes it. */
2130 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2133 /* Turn off app to make assembly quicker. */
2138 /* Output a marker (i.e. a label) for the beginning of a function, before
2142 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
2143 const char *file ATTRIBUTE_UNUSED
)
2145 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2148 current_function_func_begin_label
= 0;
2150 #ifdef IA64_UNWIND_INFO
2151 /* ??? current_function_func_begin_label is also used by except.c
2152 for call-site information. We must emit this label if it might
2154 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2155 && ! dwarf2out_do_frame ())
2158 if (! dwarf2out_do_frame ())
2162 function_section (current_function_decl
);
2163 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2164 current_function_funcdef_no
);
2165 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2166 current_function_funcdef_no
);
2167 current_function_func_begin_label
= get_identifier (label
);
2169 #ifdef IA64_UNWIND_INFO
2170 /* We can elide the fde allocation if we're not emitting debug info. */
2171 if (! dwarf2out_do_frame ())
2175 /* Expand the fde table if necessary. */
2176 if (fde_table_in_use
== fde_table_allocated
)
2178 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2179 fde_table
= ggc_realloc (fde_table
,
2180 fde_table_allocated
* sizeof (dw_fde_node
));
2181 memset (fde_table
+ fde_table_in_use
, 0,
2182 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2185 /* Record the FDE associated with this function. */
2186 current_funcdef_fde
= fde_table_in_use
;
2188 /* Add the new FDE at the end of the fde_table. */
2189 fde
= &fde_table
[fde_table_in_use
++];
2190 fde
->dw_fde_begin
= xstrdup (label
);
2191 fde
->dw_fde_current_label
= NULL
;
2192 fde
->dw_fde_end
= NULL
;
2193 fde
->dw_fde_cfi
= NULL
;
2194 fde
->funcdef_number
= current_function_funcdef_no
;
2195 fde
->nothrow
= current_function_nothrow
;
2196 fde
->uses_eh_lsda
= cfun
->uses_eh_lsda
;
2197 fde
->all_throwers_are_sibcalls
= cfun
->all_throwers_are_sibcalls
;
2199 args_size
= old_args_size
= 0;
2201 /* We only want to output line number information for the genuine dwarf2
2202 prologue case, not the eh frame case. */
2203 #ifdef DWARF2_DEBUGGING_INFO
2205 dwarf2out_source_line (line
, file
);
2209 /* Output a marker (i.e. a label) for the absolute end of the generated code
2210 for a function definition. This gets called *after* the epilogue code has
2214 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
2215 const char *file ATTRIBUTE_UNUSED
)
2218 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2220 /* Output a label to mark the endpoint of the code generated for this
2222 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
2223 current_function_funcdef_no
);
2224 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2225 fde
= &fde_table
[fde_table_in_use
- 1];
2226 fde
->dw_fde_end
= xstrdup (label
);
2230 dwarf2out_frame_init (void)
2232 /* Allocate the initial hunk of the fde_table. */
2233 fde_table
= (dw_fde_ref
) ggc_alloc_cleared (FDE_TABLE_INCREMENT
2234 * sizeof (dw_fde_node
));
2235 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2236 fde_table_in_use
= 0;
2238 /* Generate the CFA instructions common to all FDE's. Do it now for the
2239 sake of lookup_cfa. */
2241 #ifdef DWARF2_UNWIND_INFO
2242 /* On entry, the Canonical Frame Address is at SP. */
2243 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2244 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2249 dwarf2out_frame_finish (void)
2251 /* Output call frame information. */
2252 if (write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
2253 output_call_frame_info (0);
2255 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2256 output_call_frame_info (1);
2260 /* And now, the subset of the debugging information support code necessary
2261 for emitting location expressions. */
2263 /* We need some way to distinguish DW_OP_addr with a direct symbol
2264 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2265 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2268 typedef struct dw_val_struct
*dw_val_ref
;
2269 typedef struct die_struct
*dw_die_ref
;
2270 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2271 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2273 /* Each DIE may have a series of attribute/value pairs. Values
2274 can take on several forms. The forms that are used in this
2275 implementation are listed below. */
2280 dw_val_class_offset
,
2282 dw_val_class_loc_list
,
2283 dw_val_class_range_list
,
2285 dw_val_class_unsigned_const
,
2286 dw_val_class_long_long
,
2289 dw_val_class_die_ref
,
2290 dw_val_class_fde_ref
,
2291 dw_val_class_lbl_id
,
2292 dw_val_class_lbl_offset
,
2296 /* Describe a double word constant value. */
2297 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2299 typedef struct dw_long_long_struct
GTY(())
2306 /* Describe a floating point constant value. */
2308 typedef struct dw_fp_struct
GTY(())
2310 long * GTY((length ("%h.length"))) array
;
2315 /* The dw_val_node describes an attribute's value, as it is
2316 represented internally. */
2318 typedef struct dw_val_struct
GTY(())
2320 enum dw_val_class val_class
;
2321 union dw_val_struct_union
2323 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
2324 long unsigned GTY ((tag ("dw_val_class_offset"))) val_offset
;
2325 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
2326 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
2327 long int GTY ((default (""))) val_int
;
2328 long unsigned GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
2329 dw_long_long_const
GTY ((tag ("dw_val_class_long_long"))) val_long_long
;
2330 dw_float_const
GTY ((tag ("dw_val_class_float"))) val_float
;
2331 struct dw_val_die_union
2335 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
2336 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
2337 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
2338 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
2339 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
2341 GTY ((desc ("%1.val_class"))) v
;
2345 /* Locations in memory are described using a sequence of stack machine
2348 typedef struct dw_loc_descr_struct
GTY(())
2350 dw_loc_descr_ref dw_loc_next
;
2351 enum dwarf_location_atom dw_loc_opc
;
2352 dw_val_node dw_loc_oprnd1
;
2353 dw_val_node dw_loc_oprnd2
;
2358 /* Location lists are ranges + location descriptions for that range,
2359 so you can track variables that are in different places over
2360 their entire life. */
2361 typedef struct dw_loc_list_struct
GTY(())
2363 dw_loc_list_ref dw_loc_next
;
2364 const char *begin
; /* Label for begin address of range */
2365 const char *end
; /* Label for end address of range */
2366 char *ll_symbol
; /* Label for beginning of location list.
2367 Only on head of list */
2368 const char *section
; /* Section this loclist is relative to */
2369 dw_loc_descr_ref expr
;
2372 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2374 static const char *dwarf_stack_op_name (unsigned);
2375 static dw_loc_descr_ref
new_loc_descr (enum dwarf_location_atom
,
2376 unsigned long, unsigned long);
2377 static void add_loc_descr (dw_loc_descr_ref
*, dw_loc_descr_ref
);
2378 static unsigned long size_of_loc_descr (dw_loc_descr_ref
);
2379 static unsigned long size_of_locs (dw_loc_descr_ref
);
2380 static void output_loc_operands (dw_loc_descr_ref
);
2381 static void output_loc_sequence (dw_loc_descr_ref
);
2383 /* Convert a DWARF stack opcode into its string name. */
2386 dwarf_stack_op_name (unsigned int op
)
2391 case INTERNAL_DW_OP_tls_addr
:
2392 return "DW_OP_addr";
2394 return "DW_OP_deref";
2396 return "DW_OP_const1u";
2398 return "DW_OP_const1s";
2400 return "DW_OP_const2u";
2402 return "DW_OP_const2s";
2404 return "DW_OP_const4u";
2406 return "DW_OP_const4s";
2408 return "DW_OP_const8u";
2410 return "DW_OP_const8s";
2412 return "DW_OP_constu";
2414 return "DW_OP_consts";
2418 return "DW_OP_drop";
2420 return "DW_OP_over";
2422 return "DW_OP_pick";
2424 return "DW_OP_swap";
2428 return "DW_OP_xderef";
2436 return "DW_OP_minus";
2448 return "DW_OP_plus";
2449 case DW_OP_plus_uconst
:
2450 return "DW_OP_plus_uconst";
2456 return "DW_OP_shra";
2474 return "DW_OP_skip";
2476 return "DW_OP_lit0";
2478 return "DW_OP_lit1";
2480 return "DW_OP_lit2";
2482 return "DW_OP_lit3";
2484 return "DW_OP_lit4";
2486 return "DW_OP_lit5";
2488 return "DW_OP_lit6";
2490 return "DW_OP_lit7";
2492 return "DW_OP_lit8";
2494 return "DW_OP_lit9";
2496 return "DW_OP_lit10";
2498 return "DW_OP_lit11";
2500 return "DW_OP_lit12";
2502 return "DW_OP_lit13";
2504 return "DW_OP_lit14";
2506 return "DW_OP_lit15";
2508 return "DW_OP_lit16";
2510 return "DW_OP_lit17";
2512 return "DW_OP_lit18";
2514 return "DW_OP_lit19";
2516 return "DW_OP_lit20";
2518 return "DW_OP_lit21";
2520 return "DW_OP_lit22";
2522 return "DW_OP_lit23";
2524 return "DW_OP_lit24";
2526 return "DW_OP_lit25";
2528 return "DW_OP_lit26";
2530 return "DW_OP_lit27";
2532 return "DW_OP_lit28";
2534 return "DW_OP_lit29";
2536 return "DW_OP_lit30";
2538 return "DW_OP_lit31";
2540 return "DW_OP_reg0";
2542 return "DW_OP_reg1";
2544 return "DW_OP_reg2";
2546 return "DW_OP_reg3";
2548 return "DW_OP_reg4";
2550 return "DW_OP_reg5";
2552 return "DW_OP_reg6";
2554 return "DW_OP_reg7";
2556 return "DW_OP_reg8";
2558 return "DW_OP_reg9";
2560 return "DW_OP_reg10";
2562 return "DW_OP_reg11";
2564 return "DW_OP_reg12";
2566 return "DW_OP_reg13";
2568 return "DW_OP_reg14";
2570 return "DW_OP_reg15";
2572 return "DW_OP_reg16";
2574 return "DW_OP_reg17";
2576 return "DW_OP_reg18";
2578 return "DW_OP_reg19";
2580 return "DW_OP_reg20";
2582 return "DW_OP_reg21";
2584 return "DW_OP_reg22";
2586 return "DW_OP_reg23";
2588 return "DW_OP_reg24";
2590 return "DW_OP_reg25";
2592 return "DW_OP_reg26";
2594 return "DW_OP_reg27";
2596 return "DW_OP_reg28";
2598 return "DW_OP_reg29";
2600 return "DW_OP_reg30";
2602 return "DW_OP_reg31";
2604 return "DW_OP_breg0";
2606 return "DW_OP_breg1";
2608 return "DW_OP_breg2";
2610 return "DW_OP_breg3";
2612 return "DW_OP_breg4";
2614 return "DW_OP_breg5";
2616 return "DW_OP_breg6";
2618 return "DW_OP_breg7";
2620 return "DW_OP_breg8";
2622 return "DW_OP_breg9";
2624 return "DW_OP_breg10";
2626 return "DW_OP_breg11";
2628 return "DW_OP_breg12";
2630 return "DW_OP_breg13";
2632 return "DW_OP_breg14";
2634 return "DW_OP_breg15";
2636 return "DW_OP_breg16";
2638 return "DW_OP_breg17";
2640 return "DW_OP_breg18";
2642 return "DW_OP_breg19";
2644 return "DW_OP_breg20";
2646 return "DW_OP_breg21";
2648 return "DW_OP_breg22";
2650 return "DW_OP_breg23";
2652 return "DW_OP_breg24";
2654 return "DW_OP_breg25";
2656 return "DW_OP_breg26";
2658 return "DW_OP_breg27";
2660 return "DW_OP_breg28";
2662 return "DW_OP_breg29";
2664 return "DW_OP_breg30";
2666 return "DW_OP_breg31";
2668 return "DW_OP_regx";
2670 return "DW_OP_fbreg";
2672 return "DW_OP_bregx";
2674 return "DW_OP_piece";
2675 case DW_OP_deref_size
:
2676 return "DW_OP_deref_size";
2677 case DW_OP_xderef_size
:
2678 return "DW_OP_xderef_size";
2681 case DW_OP_push_object_address
:
2682 return "DW_OP_push_object_address";
2684 return "DW_OP_call2";
2686 return "DW_OP_call4";
2687 case DW_OP_call_ref
:
2688 return "DW_OP_call_ref";
2689 case DW_OP_GNU_push_tls_address
:
2690 return "DW_OP_GNU_push_tls_address";
2692 return "OP_<unknown>";
2696 /* Return a pointer to a newly allocated location description. Location
2697 descriptions are simple expression terms that can be strung
2698 together to form more complicated location (address) descriptions. */
2700 static inline dw_loc_descr_ref
2701 new_loc_descr (enum dwarf_location_atom op
, long unsigned int oprnd1
,
2702 long unsigned int oprnd2
)
2704 dw_loc_descr_ref descr
2705 = (dw_loc_descr_ref
) ggc_alloc_cleared (sizeof (dw_loc_descr_node
));
2707 descr
->dw_loc_opc
= op
;
2708 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
2709 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
2710 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
2711 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
2717 /* Add a location description term to a location description expression. */
2720 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
2722 dw_loc_descr_ref
*d
;
2724 /* Find the end of the chain. */
2725 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
2731 /* Return the size of a location descriptor. */
2733 static unsigned long
2734 size_of_loc_descr (dw_loc_descr_ref loc
)
2736 unsigned long size
= 1;
2738 switch (loc
->dw_loc_opc
)
2741 case INTERNAL_DW_OP_tls_addr
:
2742 size
+= DWARF2_ADDR_SIZE
;
2761 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2764 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2769 case DW_OP_plus_uconst
:
2770 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2808 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2811 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2814 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2817 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2818 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
2821 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2823 case DW_OP_deref_size
:
2824 case DW_OP_xderef_size
:
2833 case DW_OP_call_ref
:
2834 size
+= DWARF2_ADDR_SIZE
;
2843 /* Return the size of a series of location descriptors. */
2845 static unsigned long
2846 size_of_locs (dw_loc_descr_ref loc
)
2850 for (size
= 0; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2852 loc
->dw_loc_addr
= size
;
2853 size
+= size_of_loc_descr (loc
);
2859 /* Output location description stack opcode's operands (if any). */
2862 output_loc_operands (dw_loc_descr_ref loc
)
2864 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2865 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2867 switch (loc
->dw_loc_opc
)
2869 #ifdef DWARF2_DEBUGGING_INFO
2871 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2875 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2879 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2883 if (HOST_BITS_PER_LONG
< 64)
2885 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2892 if (val1
->val_class
== dw_val_class_loc
)
2893 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2897 dw2_asm_output_data (2, offset
, NULL
);
2910 /* We currently don't make any attempt to make sure these are
2911 aligned properly like we do for the main unwind info, so
2912 don't support emitting things larger than a byte if we're
2913 only doing unwinding. */
2918 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2921 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2924 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2927 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2929 case DW_OP_plus_uconst
:
2930 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2964 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2967 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2970 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2973 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2974 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2977 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2979 case DW_OP_deref_size
:
2980 case DW_OP_xderef_size
:
2981 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2984 case INTERNAL_DW_OP_tls_addr
:
2985 #ifdef ASM_OUTPUT_DWARF_DTPREL
2986 ASM_OUTPUT_DWARF_DTPREL (asm_out_file
, DWARF2_ADDR_SIZE
,
2988 fputc ('\n', asm_out_file
);
2995 /* Other codes have no operands. */
3000 /* Output a sequence of location operations. */
3003 output_loc_sequence (dw_loc_descr_ref loc
)
3005 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
3007 /* Output the opcode. */
3008 dw2_asm_output_data (1, loc
->dw_loc_opc
,
3009 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
3011 /* Output the operand(s) (if any). */
3012 output_loc_operands (loc
);
3016 /* This routine will generate the correct assembly data for a location
3017 description based on a cfi entry with a complex address. */
3020 output_cfa_loc (dw_cfi_ref cfi
)
3022 dw_loc_descr_ref loc
;
3025 /* Output the size of the block. */
3026 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
3027 size
= size_of_locs (loc
);
3028 dw2_asm_output_data_uleb128 (size
, NULL
);
3030 /* Now output the operations themselves. */
3031 output_loc_sequence (loc
);
3034 /* This function builds a dwarf location descriptor sequence from
3035 a dw_cfa_location. */
3037 static struct dw_loc_descr_struct
*
3038 build_cfa_loc (dw_cfa_location
*cfa
)
3040 struct dw_loc_descr_struct
*head
, *tmp
;
3042 if (cfa
->indirect
== 0)
3045 if (cfa
->base_offset
)
3048 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
3050 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
3052 else if (cfa
->reg
<= 31)
3053 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3055 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3057 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
3058 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
3059 add_loc_descr (&head
, tmp
);
3060 if (cfa
->offset
!= 0)
3062 tmp
= new_loc_descr (DW_OP_plus_uconst
, cfa
->offset
, 0);
3063 add_loc_descr (&head
, tmp
);
3069 /* This function fills in aa dw_cfa_location structure from a dwarf location
3070 descriptor sequence. */
3073 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
3075 struct dw_loc_descr_struct
*ptr
;
3077 cfa
->base_offset
= 0;
3081 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
3083 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3119 cfa
->reg
= op
- DW_OP_reg0
;
3122 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3156 cfa
->reg
= op
- DW_OP_breg0
;
3157 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3160 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3161 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3166 case DW_OP_plus_uconst
:
3167 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3170 internal_error ("DW_LOC_OP %s not implemented\n",
3171 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3175 #endif /* .debug_frame support */
3177 /* And now, the support for symbolic debugging information. */
3178 #ifdef DWARF2_DEBUGGING_INFO
3180 /* .debug_str support. */
3181 static int output_indirect_string (void **, void *);
3183 static void dwarf2out_init (const char *);
3184 static void dwarf2out_finish (const char *);
3185 static void dwarf2out_define (unsigned int, const char *);
3186 static void dwarf2out_undef (unsigned int, const char *);
3187 static void dwarf2out_start_source_file (unsigned, const char *);
3188 static void dwarf2out_end_source_file (unsigned);
3189 static void dwarf2out_begin_block (unsigned, unsigned);
3190 static void dwarf2out_end_block (unsigned, unsigned);
3191 static bool dwarf2out_ignore_block (tree
);
3192 static void dwarf2out_global_decl (tree
);
3193 static void dwarf2out_abstract_function (tree
);
3195 /* The debug hooks structure. */
3197 const struct gcc_debug_hooks dwarf2_debug_hooks
=
3203 dwarf2out_start_source_file
,
3204 dwarf2out_end_source_file
,
3205 dwarf2out_begin_block
,
3206 dwarf2out_end_block
,
3207 dwarf2out_ignore_block
,
3208 dwarf2out_source_line
,
3209 dwarf2out_begin_prologue
,
3210 debug_nothing_int_charstar
, /* end_prologue */
3211 dwarf2out_end_epilogue
,
3212 debug_nothing_tree
, /* begin_function */
3213 debug_nothing_int
, /* end_function */
3214 dwarf2out_decl
, /* function_decl */
3215 dwarf2out_global_decl
,
3216 debug_nothing_tree
, /* deferred_inline_function */
3217 /* The DWARF 2 backend tries to reduce debugging bloat by not
3218 emitting the abstract description of inline functions until
3219 something tries to reference them. */
3220 dwarf2out_abstract_function
, /* outlining_inline_function */
3221 debug_nothing_rtx
, /* label */
3222 debug_nothing_int
/* handle_pch */
3226 /* NOTE: In the comments in this file, many references are made to
3227 "Debugging Information Entries". This term is abbreviated as `DIE'
3228 throughout the remainder of this file. */
3230 /* An internal representation of the DWARF output is built, and then
3231 walked to generate the DWARF debugging info. The walk of the internal
3232 representation is done after the entire program has been compiled.
3233 The types below are used to describe the internal representation. */
3235 /* Various DIE's use offsets relative to the beginning of the
3236 .debug_info section to refer to each other. */
3238 typedef long int dw_offset
;
3240 /* Define typedefs here to avoid circular dependencies. */
3242 typedef struct dw_attr_struct
*dw_attr_ref
;
3243 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3244 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3245 typedef struct pubname_struct
*pubname_ref
;
3246 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3248 /* Each entry in the line_info_table maintains the file and
3249 line number associated with the label generated for that
3250 entry. The label gives the PC value associated with
3251 the line number entry. */
3253 typedef struct dw_line_info_struct
GTY(())
3255 unsigned long dw_file_num
;
3256 unsigned long dw_line_num
;
3260 /* Line information for functions in separate sections; each one gets its
3262 typedef struct dw_separate_line_info_struct
GTY(())
3264 unsigned long dw_file_num
;
3265 unsigned long dw_line_num
;
3266 unsigned long function
;
3268 dw_separate_line_info_entry
;
3270 /* Each DIE attribute has a field specifying the attribute kind,
3271 a link to the next attribute in the chain, and an attribute value.
3272 Attributes are typically linked below the DIE they modify. */
3274 typedef struct dw_attr_struct
GTY(())
3276 enum dwarf_attribute dw_attr
;
3277 dw_attr_ref dw_attr_next
;
3278 dw_val_node dw_attr_val
;
3282 /* The Debugging Information Entry (DIE) structure */
3284 typedef struct die_struct
GTY(())
3286 enum dwarf_tag die_tag
;
3288 dw_attr_ref die_attr
;
3289 dw_die_ref die_parent
;
3290 dw_die_ref die_child
;
3292 dw_offset die_offset
;
3293 unsigned long die_abbrev
;
3298 /* The pubname structure */
3300 typedef struct pubname_struct
GTY(())
3307 struct dw_ranges_struct
GTY(())
3312 /* The limbo die list structure. */
3313 typedef struct limbo_die_struct
GTY(())
3317 struct limbo_die_struct
*next
;
3321 /* How to start an assembler comment. */
3322 #ifndef ASM_COMMENT_START
3323 #define ASM_COMMENT_START ";#"
3326 /* Define a macro which returns nonzero for a TYPE_DECL which was
3327 implicitly generated for a tagged type.
3329 Note that unlike the gcc front end (which generates a NULL named
3330 TYPE_DECL node for each complete tagged type, each array type, and
3331 each function type node created) the g++ front end generates a
3332 _named_ TYPE_DECL node for each tagged type node created.
3333 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3334 generate a DW_TAG_typedef DIE for them. */
3336 #define TYPE_DECL_IS_STUB(decl) \
3337 (DECL_NAME (decl) == NULL_TREE \
3338 || (DECL_ARTIFICIAL (decl) \
3339 && is_tagged_type (TREE_TYPE (decl)) \
3340 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3341 /* This is necessary for stub decls that \
3342 appear in nested inline functions. */ \
3343 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3344 && (decl_ultimate_origin (decl) \
3345 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3347 /* Information concerning the compilation unit's programming
3348 language, and compiler version. */
3350 /* Fixed size portion of the DWARF compilation unit header. */
3351 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3352 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3354 /* Fixed size portion of public names info. */
3355 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3357 /* Fixed size portion of the address range info. */
3358 #define DWARF_ARANGES_HEADER_SIZE \
3359 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3360 DWARF2_ADDR_SIZE * 2) \
3361 - DWARF_INITIAL_LENGTH_SIZE)
3363 /* Size of padding portion in the address range info. It must be
3364 aligned to twice the pointer size. */
3365 #define DWARF_ARANGES_PAD_SIZE \
3366 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3367 DWARF2_ADDR_SIZE * 2) \
3368 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3370 /* Use assembler line directives if available. */
3371 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3372 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3373 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3375 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3379 /* Minimum line offset in a special line info. opcode.
3380 This value was chosen to give a reasonable range of values. */
3381 #define DWARF_LINE_BASE -10
3383 /* First special line opcode - leave room for the standard opcodes. */
3384 #define DWARF_LINE_OPCODE_BASE 10
3386 /* Range of line offsets in a special line info. opcode. */
3387 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3389 /* Flag that indicates the initial value of the is_stmt_start flag.
3390 In the present implementation, we do not mark any lines as
3391 the beginning of a source statement, because that information
3392 is not made available by the GCC front-end. */
3393 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3395 #ifdef DWARF2_DEBUGGING_INFO
3396 /* This location is used by calc_die_sizes() to keep track
3397 the offset of each DIE within the .debug_info section. */
3398 static unsigned long next_die_offset
;
3401 /* Record the root of the DIE's built for the current compilation unit. */
3402 static GTY(()) dw_die_ref comp_unit_die
;
3404 #ifdef DWARF2_DEBUGGING_INFO
3405 /* We need special handling in dwarf2out_start_source_file if it is
3407 static int is_main_source
;
3410 /* A list of DIEs with a NULL parent waiting to be relocated. */
3411 static GTY(()) limbo_die_node
*limbo_die_list
;
3413 /* Filenames referenced by this compilation unit. */
3414 static GTY(()) varray_type file_table
;
3415 static GTY(()) varray_type file_table_emitted
;
3416 static GTY(()) size_t file_table_last_lookup_index
;
3418 /* A pointer to the base of a table of references to DIE's that describe
3419 declarations. The table is indexed by DECL_UID() which is a unique
3420 number identifying each decl. */
3421 static GTY((length ("decl_die_table_allocated"))) dw_die_ref
*decl_die_table
;
3423 /* Number of elements currently allocated for the decl_die_table. */
3424 static GTY(()) unsigned decl_die_table_allocated
;
3426 /* Number of elements in decl_die_table currently in use. */
3427 static GTY(()) unsigned decl_die_table_in_use
;
3429 /* Size (in elements) of increments by which we may expand the
3431 #define DECL_DIE_TABLE_INCREMENT 256
3433 /* A pointer to the base of a list of references to DIE's that
3434 are uniquely identified by their tag, presence/absence of
3435 children DIE's, and list of attribute/value pairs. */
3436 static GTY((length ("abbrev_die_table_allocated")))
3437 dw_die_ref
*abbrev_die_table
;
3439 /* Number of elements currently allocated for abbrev_die_table. */
3440 static GTY(()) unsigned abbrev_die_table_allocated
;
3442 /* Number of elements in type_die_table currently in use. */
3443 static GTY(()) unsigned abbrev_die_table_in_use
;
3445 /* Size (in elements) of increments by which we may expand the
3446 abbrev_die_table. */
3447 #define ABBREV_DIE_TABLE_INCREMENT 256
3449 /* A pointer to the base of a table that contains line information
3450 for each source code line in .text in the compilation unit. */
3451 static GTY((length ("line_info_table_allocated")))
3452 dw_line_info_ref line_info_table
;
3454 /* Number of elements currently allocated for line_info_table. */
3455 static GTY(()) unsigned line_info_table_allocated
;
3457 /* Number of elements in line_info_table currently in use. */
3458 static GTY(()) unsigned line_info_table_in_use
;
3460 /* A pointer to the base of a table that contains line information
3461 for each source code line outside of .text in the compilation unit. */
3462 static GTY ((length ("separate_line_info_table_allocated")))
3463 dw_separate_line_info_ref separate_line_info_table
;
3465 /* Number of elements currently allocated for separate_line_info_table. */
3466 static GTY(()) unsigned separate_line_info_table_allocated
;
3468 /* Number of elements in separate_line_info_table currently in use. */
3469 static GTY(()) unsigned separate_line_info_table_in_use
;
3471 /* Size (in elements) of increments by which we may expand the
3473 #define LINE_INFO_TABLE_INCREMENT 1024
3475 /* A pointer to the base of a table that contains a list of publicly
3476 accessible names. */
3477 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table
;
3479 /* Number of elements currently allocated for pubname_table. */
3480 static GTY(()) unsigned pubname_table_allocated
;
3482 /* Number of elements in pubname_table currently in use. */
3483 static GTY(()) unsigned pubname_table_in_use
;
3485 /* Size (in elements) of increments by which we may expand the
3487 #define PUBNAME_TABLE_INCREMENT 64
3489 /* Array of dies for which we should generate .debug_arange info. */
3490 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
3492 /* Number of elements currently allocated for arange_table. */
3493 static GTY(()) unsigned arange_table_allocated
;
3495 /* Number of elements in arange_table currently in use. */
3496 static GTY(()) unsigned arange_table_in_use
;
3498 /* Size (in elements) of increments by which we may expand the
3500 #define ARANGE_TABLE_INCREMENT 64
3502 /* Array of dies for which we should generate .debug_ranges info. */
3503 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
3505 /* Number of elements currently allocated for ranges_table. */
3506 static GTY(()) unsigned ranges_table_allocated
;
3508 /* Number of elements in ranges_table currently in use. */
3509 static GTY(()) unsigned ranges_table_in_use
;
3511 /* Size (in elements) of increments by which we may expand the
3513 #define RANGES_TABLE_INCREMENT 64
3515 /* Whether we have location lists that need outputting */
3516 static GTY(()) unsigned have_location_lists
;
3518 #ifdef DWARF2_DEBUGGING_INFO
3519 /* Record whether the function being analyzed contains inlined functions. */
3520 static int current_function_has_inlines
;
3522 #if 0 && defined (MIPS_DEBUGGING_INFO)
3523 static int comp_unit_has_inlines
;
3526 /* Number of file tables emitted in maybe_emit_file(). */
3527 static GTY(()) int emitcount
= 0;
3529 /* Number of internal labels generated by gen_internal_sym(). */
3530 static GTY(()) int label_num
;
3532 #ifdef DWARF2_DEBUGGING_INFO
3534 /* Forward declarations for functions defined in this file. */
3536 static int is_pseudo_reg (rtx
);
3537 static tree
type_main_variant (tree
);
3538 static int is_tagged_type (tree
);
3539 static const char *dwarf_tag_name (unsigned);
3540 static const char *dwarf_attr_name (unsigned);
3541 static const char *dwarf_form_name (unsigned);
3543 static const char *dwarf_type_encoding_name (unsigned);
3545 static tree
decl_ultimate_origin (tree
);
3546 static tree
block_ultimate_origin (tree
);
3547 static tree
decl_class_context (tree
);
3548 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
3549 static inline enum dw_val_class
AT_class (dw_attr_ref
);
3550 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3551 static inline unsigned AT_flag (dw_attr_ref
);
3552 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, long);
3553 static inline long int AT_int (dw_attr_ref
);
3554 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned long);
3555 static inline unsigned long AT_unsigned (dw_attr_ref
);
3556 static void add_AT_long_long (dw_die_ref
, enum dwarf_attribute
, unsigned long,
3558 static void add_AT_float (dw_die_ref
, enum dwarf_attribute
, unsigned, long *);
3559 static hashval_t
debug_str_do_hash (const void *);
3560 static int debug_str_eq (const void *, const void *);
3561 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3562 static inline const char *AT_string (dw_attr_ref
);
3563 static int AT_string_form (dw_attr_ref
);
3564 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3565 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3566 static inline int AT_ref_external (dw_attr_ref
);
3567 static inline void set_AT_ref_external (dw_attr_ref
, int);
3568 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3569 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3570 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3571 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3573 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3574 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
3575 static inline rtx
AT_addr (dw_attr_ref
);
3576 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3577 static void add_AT_lbl_offset (dw_die_ref
, enum dwarf_attribute
, const char *);
3578 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
, unsigned long);
3579 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3581 static inline const char *AT_lbl (dw_attr_ref
);
3582 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3583 static const char *get_AT_low_pc (dw_die_ref
);
3584 static const char *get_AT_hi_pc (dw_die_ref
);
3585 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3586 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3587 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3588 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3589 static bool is_c_family (void);
3590 static bool is_cxx (void);
3591 static bool is_java (void);
3592 static bool is_fortran (void);
3593 static bool is_ada (void);
3594 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
3595 static inline void free_die (dw_die_ref
);
3596 static void remove_children (dw_die_ref
);
3597 static void add_child_die (dw_die_ref
, dw_die_ref
);
3598 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3599 static dw_die_ref
lookup_type_die (tree
);
3600 static void equate_type_number_to_die (tree
, dw_die_ref
);
3601 static dw_die_ref
lookup_decl_die (tree
);
3602 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3603 static void print_spaces (FILE *);
3604 static void print_die (dw_die_ref
, FILE *);
3605 static void print_dwarf_line_table (FILE *);
3606 static void reverse_die_lists (dw_die_ref
);
3607 static void reverse_all_dies (dw_die_ref
);
3608 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3609 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3610 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3611 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3612 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3613 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3614 static int same_dw_val_p (dw_val_node
*, dw_val_node
*, int *);
3615 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3616 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3617 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3618 static void compute_section_prefix (dw_die_ref
);
3619 static int is_type_die (dw_die_ref
);
3620 static int is_comdat_die (dw_die_ref
);
3621 static int is_symbol_die (dw_die_ref
);
3622 static void assign_symbol_names (dw_die_ref
);
3623 static void break_out_includes (dw_die_ref
);
3624 static hashval_t
htab_cu_hash (const void *);
3625 static int htab_cu_eq (const void *, const void *);
3626 static void htab_cu_del (void *);
3627 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
3628 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
3629 static void add_sibling_attributes (dw_die_ref
);
3630 static void build_abbrev_table (dw_die_ref
);
3631 static void output_location_lists (dw_die_ref
);
3632 static int constant_size (long unsigned);
3633 static unsigned long size_of_die (dw_die_ref
);
3634 static void calc_die_sizes (dw_die_ref
);
3635 static void mark_dies (dw_die_ref
);
3636 static void unmark_dies (dw_die_ref
);
3637 static void unmark_all_dies (dw_die_ref
);
3638 static unsigned long size_of_pubnames (void);
3639 static unsigned long size_of_aranges (void);
3640 static enum dwarf_form
value_format (dw_attr_ref
);
3641 static void output_value_format (dw_attr_ref
);
3642 static void output_abbrev_section (void);
3643 static void output_die_symbol (dw_die_ref
);
3644 static void output_die (dw_die_ref
);
3645 static void output_compilation_unit_header (void);
3646 static void output_comp_unit (dw_die_ref
, int);
3647 static const char *dwarf2_name (tree
, int);
3648 static void add_pubname (tree
, dw_die_ref
);
3649 static void output_pubnames (void);
3650 static void add_arange (tree
, dw_die_ref
);
3651 static void output_aranges (void);
3652 static unsigned int add_ranges (tree
);
3653 static void output_ranges (void);
3654 static void output_line_info (void);
3655 static void output_file_names (void);
3656 static dw_die_ref
base_type_die (tree
);
3657 static tree
root_type (tree
);
3658 static int is_base_type (tree
);
3659 static bool is_ada_subrange_type (tree
);
3660 static dw_die_ref
subrange_type_die (tree
);
3661 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3662 static int type_is_enum (tree
);
3663 static unsigned int reg_number (rtx
);
3664 static dw_loc_descr_ref
reg_loc_descriptor (rtx
);
3665 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int);
3666 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
);
3667 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
3668 static dw_loc_descr_ref
based_loc_descr (unsigned, long);
3669 static int is_based_loc (rtx
);
3670 static dw_loc_descr_ref
mem_loc_descriptor (rtx
, enum machine_mode mode
);
3671 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
);
3672 static dw_loc_descr_ref
loc_descriptor (rtx
);
3673 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3674 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3675 static tree
field_type (tree
);
3676 static unsigned int simple_type_align_in_bits (tree
);
3677 static unsigned int simple_decl_align_in_bits (tree
);
3678 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (tree
);
3679 static HOST_WIDE_INT
field_byte_offset (tree
);
3680 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3682 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3683 static void add_const_value_attribute (dw_die_ref
, rtx
);
3684 static rtx
rtl_for_decl_location (tree
);
3685 static void add_location_or_const_value_attribute (dw_die_ref
, tree
);
3686 static void tree_add_const_value_attribute (dw_die_ref
, tree
);
3687 static void add_name_attribute (dw_die_ref
, const char *);
3688 static void add_comp_dir_attribute (dw_die_ref
);
3689 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3690 static void add_subscript_info (dw_die_ref
, tree
);
3691 static void add_byte_size_attribute (dw_die_ref
, tree
);
3692 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3693 static void add_bit_size_attribute (dw_die_ref
, tree
);
3694 static void add_prototyped_attribute (dw_die_ref
, tree
);
3695 static void add_abstract_origin_attribute (dw_die_ref
, tree
);
3696 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3697 static void add_src_coords_attributes (dw_die_ref
, tree
);
3698 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3699 static void push_decl_scope (tree
);
3700 static void pop_decl_scope (void);
3701 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3702 static inline int local_scope_p (dw_die_ref
);
3703 static inline int class_scope_p (dw_die_ref
);
3704 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3705 static const char *type_tag (tree
);
3706 static tree
member_declared_type (tree
);
3708 static const char *decl_start_label (tree
);
3710 static void gen_array_type_die (tree
, dw_die_ref
);
3711 static void gen_set_type_die (tree
, dw_die_ref
);
3713 static void gen_entry_point_die (tree
, dw_die_ref
);
3715 static void gen_inlined_enumeration_type_die (tree
, dw_die_ref
);
3716 static void gen_inlined_structure_type_die (tree
, dw_die_ref
);
3717 static void gen_inlined_union_type_die (tree
, dw_die_ref
);
3718 static void gen_enumeration_type_die (tree
, dw_die_ref
);
3719 static dw_die_ref
gen_formal_parameter_die (tree
, dw_die_ref
);
3720 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3721 static void gen_formal_types_die (tree
, dw_die_ref
);
3722 static void gen_subprogram_die (tree
, dw_die_ref
);
3723 static void gen_variable_die (tree
, dw_die_ref
);
3724 static void gen_label_die (tree
, dw_die_ref
);
3725 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3726 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3727 static void gen_field_die (tree
, dw_die_ref
);
3728 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3729 static dw_die_ref
gen_compile_unit_die (const char *);
3730 static void gen_string_type_die (tree
, dw_die_ref
);
3731 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3732 static void gen_member_die (tree
, dw_die_ref
);
3733 static void gen_struct_or_union_type_die (tree
, dw_die_ref
);
3734 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3735 static void gen_typedef_die (tree
, dw_die_ref
);
3736 static void gen_type_die (tree
, dw_die_ref
);
3737 static void gen_tagged_type_instantiation_die (tree
, dw_die_ref
);
3738 static void gen_block_die (tree
, dw_die_ref
, int);
3739 static void decls_for_scope (tree
, dw_die_ref
, int);
3740 static int is_redundant_typedef (tree
);
3741 static void gen_decl_die (tree
, dw_die_ref
);
3742 static unsigned lookup_filename (const char *);
3743 static void init_file_table (void);
3744 static void retry_incomplete_types (void);
3745 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3746 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3747 static int file_info_cmp (const void *, const void *);
3748 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3749 const char *, const char *, unsigned);
3750 static void add_loc_descr_to_loc_list (dw_loc_list_ref
*, dw_loc_descr_ref
,
3751 const char *, const char *,
3753 static void output_loc_list (dw_loc_list_ref
);
3754 static char *gen_internal_sym (const char *);
3756 static void prune_unmark_dies (dw_die_ref
);
3757 static void prune_unused_types_mark (dw_die_ref
, int);
3758 static void prune_unused_types_walk (dw_die_ref
);
3759 static void prune_unused_types_walk_attribs (dw_die_ref
);
3760 static void prune_unused_types_prune (dw_die_ref
);
3761 static void prune_unused_types (void);
3762 static int maybe_emit_file (int);
3764 /* Section names used to hold DWARF debugging information. */
3765 #ifndef DEBUG_INFO_SECTION
3766 #define DEBUG_INFO_SECTION ".debug_info"
3768 #ifndef DEBUG_ABBREV_SECTION
3769 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3771 #ifndef DEBUG_ARANGES_SECTION
3772 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3774 #ifndef DEBUG_MACINFO_SECTION
3775 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3777 #ifndef DEBUG_LINE_SECTION
3778 #define DEBUG_LINE_SECTION ".debug_line"
3780 #ifndef DEBUG_LOC_SECTION
3781 #define DEBUG_LOC_SECTION ".debug_loc"
3783 #ifndef DEBUG_PUBNAMES_SECTION
3784 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3786 #ifndef DEBUG_STR_SECTION
3787 #define DEBUG_STR_SECTION ".debug_str"
3789 #ifndef DEBUG_RANGES_SECTION
3790 #define DEBUG_RANGES_SECTION ".debug_ranges"
3793 /* Standard ELF section names for compiled code and data. */
3794 #ifndef TEXT_SECTION_NAME
3795 #define TEXT_SECTION_NAME ".text"
3798 /* Section flags for .debug_str section. */
3799 #ifdef HAVE_GAS_SHF_MERGE
3800 #define DEBUG_STR_SECTION_FLAGS \
3801 (flag_merge_constants \
3802 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3805 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3808 /* Labels we insert at beginning sections we can reference instead of
3809 the section names themselves. */
3811 #ifndef TEXT_SECTION_LABEL
3812 #define TEXT_SECTION_LABEL "Ltext"
3814 #ifndef DEBUG_LINE_SECTION_LABEL
3815 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3817 #ifndef DEBUG_INFO_SECTION_LABEL
3818 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3820 #ifndef DEBUG_ABBREV_SECTION_LABEL
3821 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3823 #ifndef DEBUG_LOC_SECTION_LABEL
3824 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3826 #ifndef DEBUG_RANGES_SECTION_LABEL
3827 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3829 #ifndef DEBUG_MACINFO_SECTION_LABEL
3830 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3833 /* Definitions of defaults for formats and names of various special
3834 (artificial) labels which may be generated within this file (when the -g
3835 options is used and DWARF_DEBUGGING_INFO is in effect.
3836 If necessary, these may be overridden from within the tm.h file, but
3837 typically, overriding these defaults is unnecessary. */
3839 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3840 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3841 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3842 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3843 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3844 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3845 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3846 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3848 #ifndef TEXT_END_LABEL
3849 #define TEXT_END_LABEL "Letext"
3851 #ifndef BLOCK_BEGIN_LABEL
3852 #define BLOCK_BEGIN_LABEL "LBB"
3854 #ifndef BLOCK_END_LABEL
3855 #define BLOCK_END_LABEL "LBE"
3857 #ifndef LINE_CODE_LABEL
3858 #define LINE_CODE_LABEL "LM"
3860 #ifndef SEPARATE_LINE_CODE_LABEL
3861 #define SEPARATE_LINE_CODE_LABEL "LSM"
3864 /* We allow a language front-end to designate a function that is to be
3865 called to "demangle" any name before it it put into a DIE. */
3867 static const char *(*demangle_name_func
) (const char *);
3870 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3872 demangle_name_func
= func
;
3875 /* Test if rtl node points to a pseudo register. */
3878 is_pseudo_reg (rtx rtl
)
3880 return ((GET_CODE (rtl
) == REG
&& REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3881 || (GET_CODE (rtl
) == SUBREG
3882 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3885 /* Return a reference to a type, with its const and volatile qualifiers
3889 type_main_variant (tree type
)
3891 type
= TYPE_MAIN_VARIANT (type
);
3893 /* ??? There really should be only one main variant among any group of
3894 variants of a given type (and all of the MAIN_VARIANT values for all
3895 members of the group should point to that one type) but sometimes the C
3896 front-end messes this up for array types, so we work around that bug
3898 if (TREE_CODE (type
) == ARRAY_TYPE
)
3899 while (type
!= TYPE_MAIN_VARIANT (type
))
3900 type
= TYPE_MAIN_VARIANT (type
);
3905 /* Return nonzero if the given type node represents a tagged type. */
3908 is_tagged_type (tree type
)
3910 enum tree_code code
= TREE_CODE (type
);
3912 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3913 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3916 /* Convert a DIE tag into its string name. */
3919 dwarf_tag_name (unsigned int tag
)
3923 case DW_TAG_padding
:
3924 return "DW_TAG_padding";
3925 case DW_TAG_array_type
:
3926 return "DW_TAG_array_type";
3927 case DW_TAG_class_type
:
3928 return "DW_TAG_class_type";
3929 case DW_TAG_entry_point
:
3930 return "DW_TAG_entry_point";
3931 case DW_TAG_enumeration_type
:
3932 return "DW_TAG_enumeration_type";
3933 case DW_TAG_formal_parameter
:
3934 return "DW_TAG_formal_parameter";
3935 case DW_TAG_imported_declaration
:
3936 return "DW_TAG_imported_declaration";
3938 return "DW_TAG_label";
3939 case DW_TAG_lexical_block
:
3940 return "DW_TAG_lexical_block";
3942 return "DW_TAG_member";
3943 case DW_TAG_pointer_type
:
3944 return "DW_TAG_pointer_type";
3945 case DW_TAG_reference_type
:
3946 return "DW_TAG_reference_type";
3947 case DW_TAG_compile_unit
:
3948 return "DW_TAG_compile_unit";
3949 case DW_TAG_string_type
:
3950 return "DW_TAG_string_type";
3951 case DW_TAG_structure_type
:
3952 return "DW_TAG_structure_type";
3953 case DW_TAG_subroutine_type
:
3954 return "DW_TAG_subroutine_type";
3955 case DW_TAG_typedef
:
3956 return "DW_TAG_typedef";
3957 case DW_TAG_union_type
:
3958 return "DW_TAG_union_type";
3959 case DW_TAG_unspecified_parameters
:
3960 return "DW_TAG_unspecified_parameters";
3961 case DW_TAG_variant
:
3962 return "DW_TAG_variant";
3963 case DW_TAG_common_block
:
3964 return "DW_TAG_common_block";
3965 case DW_TAG_common_inclusion
:
3966 return "DW_TAG_common_inclusion";
3967 case DW_TAG_inheritance
:
3968 return "DW_TAG_inheritance";
3969 case DW_TAG_inlined_subroutine
:
3970 return "DW_TAG_inlined_subroutine";
3972 return "DW_TAG_module";
3973 case DW_TAG_ptr_to_member_type
:
3974 return "DW_TAG_ptr_to_member_type";
3975 case DW_TAG_set_type
:
3976 return "DW_TAG_set_type";
3977 case DW_TAG_subrange_type
:
3978 return "DW_TAG_subrange_type";
3979 case DW_TAG_with_stmt
:
3980 return "DW_TAG_with_stmt";
3981 case DW_TAG_access_declaration
:
3982 return "DW_TAG_access_declaration";
3983 case DW_TAG_base_type
:
3984 return "DW_TAG_base_type";
3985 case DW_TAG_catch_block
:
3986 return "DW_TAG_catch_block";
3987 case DW_TAG_const_type
:
3988 return "DW_TAG_const_type";
3989 case DW_TAG_constant
:
3990 return "DW_TAG_constant";
3991 case DW_TAG_enumerator
:
3992 return "DW_TAG_enumerator";
3993 case DW_TAG_file_type
:
3994 return "DW_TAG_file_type";
3996 return "DW_TAG_friend";
3997 case DW_TAG_namelist
:
3998 return "DW_TAG_namelist";
3999 case DW_TAG_namelist_item
:
4000 return "DW_TAG_namelist_item";
4001 case DW_TAG_packed_type
:
4002 return "DW_TAG_packed_type";
4003 case DW_TAG_subprogram
:
4004 return "DW_TAG_subprogram";
4005 case DW_TAG_template_type_param
:
4006 return "DW_TAG_template_type_param";
4007 case DW_TAG_template_value_param
:
4008 return "DW_TAG_template_value_param";
4009 case DW_TAG_thrown_type
:
4010 return "DW_TAG_thrown_type";
4011 case DW_TAG_try_block
:
4012 return "DW_TAG_try_block";
4013 case DW_TAG_variant_part
:
4014 return "DW_TAG_variant_part";
4015 case DW_TAG_variable
:
4016 return "DW_TAG_variable";
4017 case DW_TAG_volatile_type
:
4018 return "DW_TAG_volatile_type";
4019 case DW_TAG_MIPS_loop
:
4020 return "DW_TAG_MIPS_loop";
4021 case DW_TAG_format_label
:
4022 return "DW_TAG_format_label";
4023 case DW_TAG_function_template
:
4024 return "DW_TAG_function_template";
4025 case DW_TAG_class_template
:
4026 return "DW_TAG_class_template";
4027 case DW_TAG_GNU_BINCL
:
4028 return "DW_TAG_GNU_BINCL";
4029 case DW_TAG_GNU_EINCL
:
4030 return "DW_TAG_GNU_EINCL";
4032 return "DW_TAG_<unknown>";
4036 /* Convert a DWARF attribute code into its string name. */
4039 dwarf_attr_name (unsigned int attr
)
4044 return "DW_AT_sibling";
4045 case DW_AT_location
:
4046 return "DW_AT_location";
4048 return "DW_AT_name";
4049 case DW_AT_ordering
:
4050 return "DW_AT_ordering";
4051 case DW_AT_subscr_data
:
4052 return "DW_AT_subscr_data";
4053 case DW_AT_byte_size
:
4054 return "DW_AT_byte_size";
4055 case DW_AT_bit_offset
:
4056 return "DW_AT_bit_offset";
4057 case DW_AT_bit_size
:
4058 return "DW_AT_bit_size";
4059 case DW_AT_element_list
:
4060 return "DW_AT_element_list";
4061 case DW_AT_stmt_list
:
4062 return "DW_AT_stmt_list";
4064 return "DW_AT_low_pc";
4066 return "DW_AT_high_pc";
4067 case DW_AT_language
:
4068 return "DW_AT_language";
4070 return "DW_AT_member";
4072 return "DW_AT_discr";
4073 case DW_AT_discr_value
:
4074 return "DW_AT_discr_value";
4075 case DW_AT_visibility
:
4076 return "DW_AT_visibility";
4078 return "DW_AT_import";
4079 case DW_AT_string_length
:
4080 return "DW_AT_string_length";
4081 case DW_AT_common_reference
:
4082 return "DW_AT_common_reference";
4083 case DW_AT_comp_dir
:
4084 return "DW_AT_comp_dir";
4085 case DW_AT_const_value
:
4086 return "DW_AT_const_value";
4087 case DW_AT_containing_type
:
4088 return "DW_AT_containing_type";
4089 case DW_AT_default_value
:
4090 return "DW_AT_default_value";
4092 return "DW_AT_inline";
4093 case DW_AT_is_optional
:
4094 return "DW_AT_is_optional";
4095 case DW_AT_lower_bound
:
4096 return "DW_AT_lower_bound";
4097 case DW_AT_producer
:
4098 return "DW_AT_producer";
4099 case DW_AT_prototyped
:
4100 return "DW_AT_prototyped";
4101 case DW_AT_return_addr
:
4102 return "DW_AT_return_addr";
4103 case DW_AT_start_scope
:
4104 return "DW_AT_start_scope";
4105 case DW_AT_stride_size
:
4106 return "DW_AT_stride_size";
4107 case DW_AT_upper_bound
:
4108 return "DW_AT_upper_bound";
4109 case DW_AT_abstract_origin
:
4110 return "DW_AT_abstract_origin";
4111 case DW_AT_accessibility
:
4112 return "DW_AT_accessibility";
4113 case DW_AT_address_class
:
4114 return "DW_AT_address_class";
4115 case DW_AT_artificial
:
4116 return "DW_AT_artificial";
4117 case DW_AT_base_types
:
4118 return "DW_AT_base_types";
4119 case DW_AT_calling_convention
:
4120 return "DW_AT_calling_convention";
4122 return "DW_AT_count";
4123 case DW_AT_data_member_location
:
4124 return "DW_AT_data_member_location";
4125 case DW_AT_decl_column
:
4126 return "DW_AT_decl_column";
4127 case DW_AT_decl_file
:
4128 return "DW_AT_decl_file";
4129 case DW_AT_decl_line
:
4130 return "DW_AT_decl_line";
4131 case DW_AT_declaration
:
4132 return "DW_AT_declaration";
4133 case DW_AT_discr_list
:
4134 return "DW_AT_discr_list";
4135 case DW_AT_encoding
:
4136 return "DW_AT_encoding";
4137 case DW_AT_external
:
4138 return "DW_AT_external";
4139 case DW_AT_frame_base
:
4140 return "DW_AT_frame_base";
4142 return "DW_AT_friend";
4143 case DW_AT_identifier_case
:
4144 return "DW_AT_identifier_case";
4145 case DW_AT_macro_info
:
4146 return "DW_AT_macro_info";
4147 case DW_AT_namelist_items
:
4148 return "DW_AT_namelist_items";
4149 case DW_AT_priority
:
4150 return "DW_AT_priority";
4152 return "DW_AT_segment";
4153 case DW_AT_specification
:
4154 return "DW_AT_specification";
4155 case DW_AT_static_link
:
4156 return "DW_AT_static_link";
4158 return "DW_AT_type";
4159 case DW_AT_use_location
:
4160 return "DW_AT_use_location";
4161 case DW_AT_variable_parameter
:
4162 return "DW_AT_variable_parameter";
4163 case DW_AT_virtuality
:
4164 return "DW_AT_virtuality";
4165 case DW_AT_vtable_elem_location
:
4166 return "DW_AT_vtable_elem_location";
4168 case DW_AT_allocated
:
4169 return "DW_AT_allocated";
4170 case DW_AT_associated
:
4171 return "DW_AT_associated";
4172 case DW_AT_data_location
:
4173 return "DW_AT_data_location";
4175 return "DW_AT_stride";
4176 case DW_AT_entry_pc
:
4177 return "DW_AT_entry_pc";
4178 case DW_AT_use_UTF8
:
4179 return "DW_AT_use_UTF8";
4180 case DW_AT_extension
:
4181 return "DW_AT_extension";
4183 return "DW_AT_ranges";
4184 case DW_AT_trampoline
:
4185 return "DW_AT_trampoline";
4186 case DW_AT_call_column
:
4187 return "DW_AT_call_column";
4188 case DW_AT_call_file
:
4189 return "DW_AT_call_file";
4190 case DW_AT_call_line
:
4191 return "DW_AT_call_line";
4193 case DW_AT_MIPS_fde
:
4194 return "DW_AT_MIPS_fde";
4195 case DW_AT_MIPS_loop_begin
:
4196 return "DW_AT_MIPS_loop_begin";
4197 case DW_AT_MIPS_tail_loop_begin
:
4198 return "DW_AT_MIPS_tail_loop_begin";
4199 case DW_AT_MIPS_epilog_begin
:
4200 return "DW_AT_MIPS_epilog_begin";
4201 case DW_AT_MIPS_loop_unroll_factor
:
4202 return "DW_AT_MIPS_loop_unroll_factor";
4203 case DW_AT_MIPS_software_pipeline_depth
:
4204 return "DW_AT_MIPS_software_pipeline_depth";
4205 case DW_AT_MIPS_linkage_name
:
4206 return "DW_AT_MIPS_linkage_name";
4207 case DW_AT_MIPS_stride
:
4208 return "DW_AT_MIPS_stride";
4209 case DW_AT_MIPS_abstract_name
:
4210 return "DW_AT_MIPS_abstract_name";
4211 case DW_AT_MIPS_clone_origin
:
4212 return "DW_AT_MIPS_clone_origin";
4213 case DW_AT_MIPS_has_inlines
:
4214 return "DW_AT_MIPS_has_inlines";
4216 case DW_AT_sf_names
:
4217 return "DW_AT_sf_names";
4218 case DW_AT_src_info
:
4219 return "DW_AT_src_info";
4220 case DW_AT_mac_info
:
4221 return "DW_AT_mac_info";
4222 case DW_AT_src_coords
:
4223 return "DW_AT_src_coords";
4224 case DW_AT_body_begin
:
4225 return "DW_AT_body_begin";
4226 case DW_AT_body_end
:
4227 return "DW_AT_body_end";
4228 case DW_AT_GNU_vector
:
4229 return "DW_AT_GNU_vector";
4231 case DW_AT_VMS_rtnbeg_pd_address
:
4232 return "DW_AT_VMS_rtnbeg_pd_address";
4235 return "DW_AT_<unknown>";
4239 /* Convert a DWARF value form code into its string name. */
4242 dwarf_form_name (unsigned int form
)
4247 return "DW_FORM_addr";
4248 case DW_FORM_block2
:
4249 return "DW_FORM_block2";
4250 case DW_FORM_block4
:
4251 return "DW_FORM_block4";
4253 return "DW_FORM_data2";
4255 return "DW_FORM_data4";
4257 return "DW_FORM_data8";
4258 case DW_FORM_string
:
4259 return "DW_FORM_string";
4261 return "DW_FORM_block";
4262 case DW_FORM_block1
:
4263 return "DW_FORM_block1";
4265 return "DW_FORM_data1";
4267 return "DW_FORM_flag";
4269 return "DW_FORM_sdata";
4271 return "DW_FORM_strp";
4273 return "DW_FORM_udata";
4274 case DW_FORM_ref_addr
:
4275 return "DW_FORM_ref_addr";
4277 return "DW_FORM_ref1";
4279 return "DW_FORM_ref2";
4281 return "DW_FORM_ref4";
4283 return "DW_FORM_ref8";
4284 case DW_FORM_ref_udata
:
4285 return "DW_FORM_ref_udata";
4286 case DW_FORM_indirect
:
4287 return "DW_FORM_indirect";
4289 return "DW_FORM_<unknown>";
4293 /* Convert a DWARF type code into its string name. */
4297 dwarf_type_encoding_name (unsigned enc
)
4301 case DW_ATE_address
:
4302 return "DW_ATE_address";
4303 case DW_ATE_boolean
:
4304 return "DW_ATE_boolean";
4305 case DW_ATE_complex_float
:
4306 return "DW_ATE_complex_float";
4308 return "DW_ATE_float";
4310 return "DW_ATE_signed";
4311 case DW_ATE_signed_char
:
4312 return "DW_ATE_signed_char";
4313 case DW_ATE_unsigned
:
4314 return "DW_ATE_unsigned";
4315 case DW_ATE_unsigned_char
:
4316 return "DW_ATE_unsigned_char";
4318 return "DW_ATE_<unknown>";
4323 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4324 instance of an inlined instance of a decl which is local to an inline
4325 function, so we have to trace all of the way back through the origin chain
4326 to find out what sort of node actually served as the original seed for the
4330 decl_ultimate_origin (tree decl
)
4332 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4333 nodes in the function to point to themselves; ignore that if
4334 we're trying to output the abstract instance of this function. */
4335 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4338 #ifdef ENABLE_CHECKING
4339 if (DECL_FROM_INLINE (DECL_ORIGIN (decl
)))
4340 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4341 most distant ancestor, this should never happen. */
4345 return DECL_ABSTRACT_ORIGIN (decl
);
4348 /* Determine the "ultimate origin" of a block. The block may be an inlined
4349 instance of an inlined instance of a block which is local to an inline
4350 function, so we have to trace all of the way back through the origin chain
4351 to find out what sort of node actually served as the original seed for the
4355 block_ultimate_origin (tree block
)
4357 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4359 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4360 nodes in the function to point to themselves; ignore that if
4361 we're trying to output the abstract instance of this function. */
4362 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4365 if (immediate_origin
== NULL_TREE
)
4370 tree lookahead
= immediate_origin
;
4374 ret_val
= lookahead
;
4375 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4376 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4378 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4384 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4385 of a virtual function may refer to a base class, so we check the 'this'
4389 decl_class_context (tree decl
)
4391 tree context
= NULL_TREE
;
4393 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4394 context
= DECL_CONTEXT (decl
);
4396 context
= TYPE_MAIN_VARIANT
4397 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4399 if (context
&& !TYPE_P (context
))
4400 context
= NULL_TREE
;
4405 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4406 addition order, and correct that in reverse_all_dies. */
4409 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
4411 if (die
!= NULL
&& attr
!= NULL
)
4413 attr
->dw_attr_next
= die
->die_attr
;
4414 die
->die_attr
= attr
;
4418 static inline enum dw_val_class
4419 AT_class (dw_attr_ref a
)
4421 return a
->dw_attr_val
.val_class
;
4424 /* Add a flag value attribute to a DIE. */
4427 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4429 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4431 attr
->dw_attr_next
= NULL
;
4432 attr
->dw_attr
= attr_kind
;
4433 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
4434 attr
->dw_attr_val
.v
.val_flag
= flag
;
4435 add_dwarf_attr (die
, attr
);
4438 static inline unsigned
4439 AT_flag (dw_attr_ref a
)
4441 if (a
&& AT_class (a
) == dw_val_class_flag
)
4442 return a
->dw_attr_val
.v
.val_flag
;
4447 /* Add a signed integer attribute value to a DIE. */
4450 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, long int int_val
)
4452 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (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_const
;
4457 attr
->dw_attr_val
.v
.val_int
= int_val
;
4458 add_dwarf_attr (die
, attr
);
4461 static inline long int
4462 AT_int (dw_attr_ref a
)
4464 if (a
&& AT_class (a
) == dw_val_class_const
)
4465 return a
->dw_attr_val
.v
.val_int
;
4470 /* Add an unsigned integer attribute value to a DIE. */
4473 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4474 long unsigned int unsigned_val
)
4476 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4478 attr
->dw_attr_next
= NULL
;
4479 attr
->dw_attr
= attr_kind
;
4480 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4481 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4482 add_dwarf_attr (die
, attr
);
4485 static inline unsigned long
4486 AT_unsigned (dw_attr_ref a
)
4488 if (a
&& AT_class (a
) == dw_val_class_unsigned_const
)
4489 return a
->dw_attr_val
.v
.val_unsigned
;
4494 /* Add an unsigned double integer attribute value to a DIE. */
4497 add_AT_long_long (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4498 long unsigned int val_hi
, long unsigned int val_low
)
4500 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4502 attr
->dw_attr_next
= NULL
;
4503 attr
->dw_attr
= attr_kind
;
4504 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
4505 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4506 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
4507 add_dwarf_attr (die
, attr
);
4510 /* Add a floating point attribute value to a DIE and return it. */
4513 add_AT_float (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4514 unsigned int length
, long int *array
)
4516 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4518 attr
->dw_attr_next
= NULL
;
4519 attr
->dw_attr
= attr_kind
;
4520 attr
->dw_attr_val
.val_class
= dw_val_class_float
;
4521 attr
->dw_attr_val
.v
.val_float
.length
= length
;
4522 attr
->dw_attr_val
.v
.val_float
.array
= array
;
4523 add_dwarf_attr (die
, attr
);
4526 /* Hash and equality functions for debug_str_hash. */
4529 debug_str_do_hash (const void *x
)
4531 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
4535 debug_str_eq (const void *x1
, const void *x2
)
4537 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
4538 (const char *)x2
) == 0;
4541 /* Add a string attribute value to a DIE. */
4544 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4546 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4547 struct indirect_string_node
*node
;
4550 if (! debug_str_hash
)
4551 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
4552 debug_str_eq
, NULL
);
4554 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
4555 htab_hash_string (str
), INSERT
);
4557 *slot
= ggc_alloc_cleared (sizeof (struct indirect_string_node
));
4558 node
= (struct indirect_string_node
*) *slot
;
4559 node
->str
= ggc_strdup (str
);
4562 attr
->dw_attr_next
= NULL
;
4563 attr
->dw_attr
= attr_kind
;
4564 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
4565 attr
->dw_attr_val
.v
.val_str
= node
;
4566 add_dwarf_attr (die
, attr
);
4569 static inline const char *
4570 AT_string (dw_attr_ref a
)
4572 if (a
&& AT_class (a
) == dw_val_class_str
)
4573 return a
->dw_attr_val
.v
.val_str
->str
;
4578 /* Find out whether a string should be output inline in DIE
4579 or out-of-line in .debug_str section. */
4582 AT_string_form (dw_attr_ref a
)
4584 if (a
&& AT_class (a
) == dw_val_class_str
)
4586 struct indirect_string_node
*node
;
4590 node
= a
->dw_attr_val
.v
.val_str
;
4594 len
= strlen (node
->str
) + 1;
4596 /* If the string is shorter or equal to the size of the reference, it is
4597 always better to put it inline. */
4598 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4599 return node
->form
= DW_FORM_string
;
4601 /* If we cannot expect the linker to merge strings in .debug_str
4602 section, only put it into .debug_str if it is worth even in this
4604 if ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) == 0
4605 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
4606 return node
->form
= DW_FORM_string
;
4608 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4609 ++dw2_string_counter
;
4610 node
->label
= xstrdup (label
);
4612 return node
->form
= DW_FORM_strp
;
4618 /* Add a DIE reference attribute value to a DIE. */
4621 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4623 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4625 attr
->dw_attr_next
= NULL
;
4626 attr
->dw_attr
= attr_kind
;
4627 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
4628 attr
->dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4629 attr
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4630 add_dwarf_attr (die
, attr
);
4633 static inline dw_die_ref
4634 AT_ref (dw_attr_ref a
)
4636 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4637 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4643 AT_ref_external (dw_attr_ref a
)
4645 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4646 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4652 set_AT_ref_external (dw_attr_ref a
, int i
)
4654 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4655 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4660 /* Add an FDE reference attribute value to a DIE. */
4663 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4665 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4667 attr
->dw_attr_next
= NULL
;
4668 attr
->dw_attr
= attr_kind
;
4669 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4670 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
4671 add_dwarf_attr (die
, attr
);
4674 /* Add a location description attribute value to a DIE. */
4677 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4679 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4681 attr
->dw_attr_next
= NULL
;
4682 attr
->dw_attr
= attr_kind
;
4683 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
4684 attr
->dw_attr_val
.v
.val_loc
= loc
;
4685 add_dwarf_attr (die
, attr
);
4688 static inline dw_loc_descr_ref
4689 AT_loc (dw_attr_ref a
)
4691 if (a
&& AT_class (a
) == dw_val_class_loc
)
4692 return a
->dw_attr_val
.v
.val_loc
;
4698 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4700 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4702 attr
->dw_attr_next
= NULL
;
4703 attr
->dw_attr
= attr_kind
;
4704 attr
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
4705 attr
->dw_attr_val
.v
.val_loc_list
= loc_list
;
4706 add_dwarf_attr (die
, attr
);
4707 have_location_lists
= 1;
4710 static inline dw_loc_list_ref
4711 AT_loc_list (dw_attr_ref a
)
4713 if (a
&& AT_class (a
) == dw_val_class_loc_list
)
4714 return a
->dw_attr_val
.v
.val_loc_list
;
4719 /* Add an address constant attribute value to a DIE. */
4722 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
4724 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4726 attr
->dw_attr_next
= NULL
;
4727 attr
->dw_attr
= attr_kind
;
4728 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
4729 attr
->dw_attr_val
.v
.val_addr
= addr
;
4730 add_dwarf_attr (die
, attr
);
4734 AT_addr (dw_attr_ref a
)
4736 if (a
&& AT_class (a
) == dw_val_class_addr
)
4737 return a
->dw_attr_val
.v
.val_addr
;
4742 /* Add a label identifier attribute value to a DIE. */
4745 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
4747 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4749 attr
->dw_attr_next
= NULL
;
4750 attr
->dw_attr
= attr_kind
;
4751 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4752 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4753 add_dwarf_attr (die
, attr
);
4756 /* Add a section offset attribute value to a DIE. */
4759 add_AT_lbl_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *label
)
4761 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4763 attr
->dw_attr_next
= NULL
;
4764 attr
->dw_attr
= attr_kind
;
4765 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_offset
;
4766 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4767 add_dwarf_attr (die
, attr
);
4770 /* Add an offset attribute value to a DIE. */
4773 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
, long unsigned int offset
)
4775 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4777 attr
->dw_attr_next
= NULL
;
4778 attr
->dw_attr
= attr_kind
;
4779 attr
->dw_attr_val
.val_class
= dw_val_class_offset
;
4780 attr
->dw_attr_val
.v
.val_offset
= offset
;
4781 add_dwarf_attr (die
, attr
);
4784 /* Add an range_list attribute value to a DIE. */
4787 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4788 long unsigned int offset
)
4790 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4792 attr
->dw_attr_next
= NULL
;
4793 attr
->dw_attr
= attr_kind
;
4794 attr
->dw_attr_val
.val_class
= dw_val_class_range_list
;
4795 attr
->dw_attr_val
.v
.val_offset
= offset
;
4796 add_dwarf_attr (die
, attr
);
4799 static inline const char *
4800 AT_lbl (dw_attr_ref a
)
4802 if (a
&& (AT_class (a
) == dw_val_class_lbl_id
4803 || AT_class (a
) == dw_val_class_lbl_offset
))
4804 return a
->dw_attr_val
.v
.val_lbl_id
;
4809 /* Get the attribute of type attr_kind. */
4811 static inline dw_attr_ref
4812 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4815 dw_die_ref spec
= NULL
;
4819 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4820 if (a
->dw_attr
== attr_kind
)
4822 else if (a
->dw_attr
== DW_AT_specification
4823 || a
->dw_attr
== DW_AT_abstract_origin
)
4827 return get_AT (spec
, attr_kind
);
4833 /* Return the "low pc" attribute value, typically associated with a subprogram
4834 DIE. Return null if the "low pc" attribute is either not present, or if it
4835 cannot be represented as an assembler label identifier. */
4837 static inline const char *
4838 get_AT_low_pc (dw_die_ref die
)
4840 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4842 return a
? AT_lbl (a
) : NULL
;
4845 /* Return the "high pc" attribute value, typically associated with a subprogram
4846 DIE. Return null if the "high pc" attribute is either not present, or if it
4847 cannot be represented as an assembler label identifier. */
4849 static inline const char *
4850 get_AT_hi_pc (dw_die_ref die
)
4852 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4854 return a
? AT_lbl (a
) : NULL
;
4857 /* Return the value of the string attribute designated by ATTR_KIND, or
4858 NULL if it is not present. */
4860 static inline const char *
4861 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4863 dw_attr_ref a
= get_AT (die
, attr_kind
);
4865 return a
? AT_string (a
) : NULL
;
4868 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4869 if it is not present. */
4872 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4874 dw_attr_ref a
= get_AT (die
, attr_kind
);
4876 return a
? AT_flag (a
) : 0;
4879 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4880 if it is not present. */
4882 static inline unsigned
4883 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4885 dw_attr_ref a
= get_AT (die
, attr_kind
);
4887 return a
? AT_unsigned (a
) : 0;
4890 static inline dw_die_ref
4891 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4893 dw_attr_ref a
= get_AT (die
, attr_kind
);
4895 return a
? AT_ref (a
) : NULL
;
4898 /* Return TRUE if the language is C or C++. */
4903 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4905 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
4906 || lang
== DW_LANG_C_plus_plus
);
4909 /* Return TRUE if the language is C++. */
4914 return (get_AT_unsigned (comp_unit_die
, DW_AT_language
)
4915 == DW_LANG_C_plus_plus
);
4918 /* Return TRUE if the language is Fortran. */
4923 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4925 return lang
== DW_LANG_Fortran77
|| lang
== DW_LANG_Fortran90
;
4928 /* Return TRUE if the language is Java. */
4933 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4935 return lang
== DW_LANG_Java
;
4938 /* Return TRUE if the language is Ada. */
4943 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4945 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4948 /* Free up the memory used by A. */
4950 static inline void free_AT (dw_attr_ref
);
4952 free_AT (dw_attr_ref a
)
4954 if (AT_class (a
) == dw_val_class_str
)
4955 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4956 a
->dw_attr_val
.v
.val_str
->refcount
--;
4959 /* Remove the specified attribute if present. */
4962 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4965 dw_attr_ref removed
= NULL
;
4969 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
4970 if ((*p
)->dw_attr
== attr_kind
)
4973 *p
= (*p
)->dw_attr_next
;
4982 /* Free up the memory used by DIE. */
4985 free_die (dw_die_ref die
)
4987 remove_children (die
);
4990 /* Discard the children of this DIE. */
4993 remove_children (dw_die_ref die
)
4995 dw_die_ref child_die
= die
->die_child
;
4997 die
->die_child
= NULL
;
4999 while (child_die
!= NULL
)
5001 dw_die_ref tmp_die
= child_die
;
5004 child_die
= child_die
->die_sib
;
5006 for (a
= tmp_die
->die_attr
; a
!= NULL
;)
5008 dw_attr_ref tmp_a
= a
;
5010 a
= a
->dw_attr_next
;
5018 /* Add a child DIE below its parent. We build the lists up in reverse
5019 addition order, and correct that in reverse_all_dies. */
5022 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5024 if (die
!= NULL
&& child_die
!= NULL
)
5026 if (die
== child_die
)
5029 child_die
->die_parent
= die
;
5030 child_die
->die_sib
= die
->die_child
;
5031 die
->die_child
= child_die
;
5035 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5036 is the specification, to the front of PARENT's list of children. */
5039 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5043 /* We want the declaration DIE from inside the class, not the
5044 specification DIE at toplevel. */
5045 if (child
->die_parent
!= parent
)
5047 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5053 if (child
->die_parent
!= parent
5054 && child
->die_parent
!= get_AT_ref (parent
, DW_AT_specification
))
5057 for (p
= &(child
->die_parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
5060 *p
= child
->die_sib
;
5064 child
->die_parent
= parent
;
5065 child
->die_sib
= parent
->die_child
;
5066 parent
->die_child
= child
;
5069 /* Return a pointer to a newly created DIE node. */
5071 static inline dw_die_ref
5072 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5074 dw_die_ref die
= (dw_die_ref
) ggc_alloc_cleared (sizeof (die_node
));
5076 die
->die_tag
= tag_value
;
5078 if (parent_die
!= NULL
)
5079 add_child_die (parent_die
, die
);
5082 limbo_die_node
*limbo_node
;
5084 limbo_node
= ggc_alloc_cleared (sizeof (limbo_die_node
));
5085 limbo_node
->die
= die
;
5086 limbo_node
->created_for
= t
;
5087 limbo_node
->next
= limbo_die_list
;
5088 limbo_die_list
= limbo_node
;
5094 /* Return the DIE associated with the given type specifier. */
5096 static inline dw_die_ref
5097 lookup_type_die (tree type
)
5099 return TYPE_SYMTAB_DIE (type
);
5102 /* Equate a DIE to a given type specifier. */
5105 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5107 TYPE_SYMTAB_DIE (type
) = type_die
;
5110 /* Return the DIE associated with a given declaration. */
5112 static inline dw_die_ref
5113 lookup_decl_die (tree decl
)
5115 unsigned decl_id
= DECL_UID (decl
);
5117 return (decl_id
< decl_die_table_in_use
? decl_die_table
[decl_id
] : NULL
);
5120 /* Equate a DIE to a particular declaration. */
5123 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5125 unsigned int decl_id
= DECL_UID (decl
);
5126 unsigned int num_allocated
;
5128 if (decl_id
>= decl_die_table_allocated
)
5131 = ((decl_id
+ 1 + DECL_DIE_TABLE_INCREMENT
- 1)
5132 / DECL_DIE_TABLE_INCREMENT
)
5133 * DECL_DIE_TABLE_INCREMENT
;
5135 decl_die_table
= ggc_realloc (decl_die_table
,
5136 sizeof (dw_die_ref
) * num_allocated
);
5138 memset ((char *) &decl_die_table
[decl_die_table_allocated
], 0,
5139 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
5140 decl_die_table_allocated
= num_allocated
;
5143 if (decl_id
>= decl_die_table_in_use
)
5144 decl_die_table_in_use
= (decl_id
+ 1);
5146 decl_die_table
[decl_id
] = decl_die
;
5149 /* Keep track of the number of spaces used to indent the
5150 output of the debugging routines that print the structure of
5151 the DIE internal representation. */
5152 static int print_indent
;
5154 /* Indent the line the number of spaces given by print_indent. */
5157 print_spaces (FILE *outfile
)
5159 fprintf (outfile
, "%*s", print_indent
, "");
5162 /* Print the information associated with a given DIE, and its children.
5163 This routine is a debugging aid only. */
5166 print_die (dw_die_ref die
, FILE *outfile
)
5171 print_spaces (outfile
);
5172 fprintf (outfile
, "DIE %4lu: %s\n",
5173 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5174 print_spaces (outfile
);
5175 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5176 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
5178 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5180 print_spaces (outfile
);
5181 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5183 switch (AT_class (a
))
5185 case dw_val_class_addr
:
5186 fprintf (outfile
, "address");
5188 case dw_val_class_offset
:
5189 fprintf (outfile
, "offset");
5191 case dw_val_class_loc
:
5192 fprintf (outfile
, "location descriptor");
5194 case dw_val_class_loc_list
:
5195 fprintf (outfile
, "location list -> label:%s",
5196 AT_loc_list (a
)->ll_symbol
);
5198 case dw_val_class_range_list
:
5199 fprintf (outfile
, "range list");
5201 case dw_val_class_const
:
5202 fprintf (outfile
, "%ld", AT_int (a
));
5204 case dw_val_class_unsigned_const
:
5205 fprintf (outfile
, "%lu", AT_unsigned (a
));
5207 case dw_val_class_long_long
:
5208 fprintf (outfile
, "constant (%lu,%lu)",
5209 a
->dw_attr_val
.v
.val_long_long
.hi
,
5210 a
->dw_attr_val
.v
.val_long_long
.low
);
5212 case dw_val_class_float
:
5213 fprintf (outfile
, "floating-point constant");
5215 case dw_val_class_flag
:
5216 fprintf (outfile
, "%u", AT_flag (a
));
5218 case dw_val_class_die_ref
:
5219 if (AT_ref (a
) != NULL
)
5221 if (AT_ref (a
)->die_symbol
)
5222 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5224 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
5227 fprintf (outfile
, "die -> <null>");
5229 case dw_val_class_lbl_id
:
5230 case dw_val_class_lbl_offset
:
5231 fprintf (outfile
, "label: %s", AT_lbl (a
));
5233 case dw_val_class_str
:
5234 if (AT_string (a
) != NULL
)
5235 fprintf (outfile
, "\"%s\"", AT_string (a
));
5237 fprintf (outfile
, "<null>");
5243 fprintf (outfile
, "\n");
5246 if (die
->die_child
!= NULL
)
5249 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5250 print_die (c
, outfile
);
5254 if (print_indent
== 0)
5255 fprintf (outfile
, "\n");
5258 /* Print the contents of the source code line number correspondence table.
5259 This routine is a debugging aid only. */
5262 print_dwarf_line_table (FILE *outfile
)
5265 dw_line_info_ref line_info
;
5267 fprintf (outfile
, "\n\nDWARF source line information\n");
5268 for (i
= 1; i
< line_info_table_in_use
; i
++)
5270 line_info
= &line_info_table
[i
];
5271 fprintf (outfile
, "%5d: ", i
);
5272 fprintf (outfile
, "%-20s",
5273 VARRAY_CHAR_PTR (file_table
, line_info
->dw_file_num
));
5274 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
5275 fprintf (outfile
, "\n");
5278 fprintf (outfile
, "\n\n");
5281 /* Print the information collected for a given DIE. */
5284 debug_dwarf_die (dw_die_ref die
)
5286 print_die (die
, stderr
);
5289 /* Print all DWARF information collected for the compilation unit.
5290 This routine is a debugging aid only. */
5296 print_die (comp_unit_die
, stderr
);
5297 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5298 print_dwarf_line_table (stderr
);
5301 /* We build up the lists of children and attributes by pushing new ones
5302 onto the beginning of the list. Reverse the lists for DIE so that
5303 they are in order of addition. */
5306 reverse_die_lists (dw_die_ref die
)
5308 dw_die_ref c
, cp
, cn
;
5309 dw_attr_ref a
, ap
, an
;
5311 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
5313 an
= a
->dw_attr_next
;
5314 a
->dw_attr_next
= ap
;
5320 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
5327 die
->die_child
= cp
;
5330 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5331 reverse all dies in add_sibling_attributes, which runs through all the dies,
5332 it would reverse all the dies. Now, however, since we don't call
5333 reverse_die_lists in add_sibling_attributes, we need a routine to
5334 recursively reverse all the dies. This is that routine. */
5337 reverse_all_dies (dw_die_ref die
)
5341 reverse_die_lists (die
);
5343 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5344 reverse_all_dies (c
);
5347 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5348 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5349 DIE that marks the start of the DIEs for this include file. */
5352 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5354 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5355 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5357 new_unit
->die_sib
= old_unit
;
5361 /* Close an include-file CU and reopen the enclosing one. */
5364 pop_compile_unit (dw_die_ref old_unit
)
5366 dw_die_ref new_unit
= old_unit
->die_sib
;
5368 old_unit
->die_sib
= NULL
;
5372 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5373 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5375 /* Calculate the checksum of a location expression. */
5378 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5380 CHECKSUM (loc
->dw_loc_opc
);
5381 CHECKSUM (loc
->dw_loc_oprnd1
);
5382 CHECKSUM (loc
->dw_loc_oprnd2
);
5385 /* Calculate the checksum of an attribute. */
5388 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5390 dw_loc_descr_ref loc
;
5393 CHECKSUM (at
->dw_attr
);
5395 /* We don't care about differences in file numbering. */
5396 if (at
->dw_attr
== DW_AT_decl_file
5397 /* Or that this was compiled with a different compiler snapshot; if
5398 the output is the same, that's what matters. */
5399 || at
->dw_attr
== DW_AT_producer
)
5402 switch (AT_class (at
))
5404 case dw_val_class_const
:
5405 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5407 case dw_val_class_unsigned_const
:
5408 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5410 case dw_val_class_long_long
:
5411 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
5413 case dw_val_class_float
:
5414 CHECKSUM (at
->dw_attr_val
.v
.val_float
);
5416 case dw_val_class_flag
:
5417 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5419 case dw_val_class_str
:
5420 CHECKSUM_STRING (AT_string (at
));
5423 case dw_val_class_addr
:
5425 switch (GET_CODE (r
))
5428 CHECKSUM_STRING (XSTR (r
, 0));
5436 case dw_val_class_offset
:
5437 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5440 case dw_val_class_loc
:
5441 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5442 loc_checksum (loc
, ctx
);
5445 case dw_val_class_die_ref
:
5446 die_checksum (AT_ref (at
), ctx
, mark
);
5449 case dw_val_class_fde_ref
:
5450 case dw_val_class_lbl_id
:
5451 case dw_val_class_lbl_offset
:
5459 /* Calculate the checksum of a DIE. */
5462 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5467 /* To avoid infinite recursion. */
5470 CHECKSUM (die
->die_mark
);
5473 die
->die_mark
= ++(*mark
);
5475 CHECKSUM (die
->die_tag
);
5477 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
5478 attr_checksum (a
, ctx
, mark
);
5480 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5481 die_checksum (c
, ctx
, mark
);
5485 #undef CHECKSUM_STRING
5487 /* Do the location expressions look same? */
5489 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
5491 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
5492 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
5493 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
5496 /* Do the values look the same? */
5498 same_dw_val_p (dw_val_node
*v1
, dw_val_node
*v2
, int *mark
)
5500 dw_loc_descr_ref loc1
, loc2
;
5504 if (v1
->val_class
!= v2
->val_class
)
5507 switch (v1
->val_class
)
5509 case dw_val_class_const
:
5510 return v1
->v
.val_int
== v2
->v
.val_int
;
5511 case dw_val_class_unsigned_const
:
5512 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
5513 case dw_val_class_long_long
:
5514 return v1
->v
.val_long_long
.hi
== v2
->v
.val_long_long
.hi
5515 && v1
->v
.val_long_long
.low
== v2
->v
.val_long_long
.low
;
5516 case dw_val_class_float
:
5517 if (v1
->v
.val_float
.length
!= v2
->v
.val_float
.length
)
5519 for (i
= 0; i
< v1
->v
.val_float
.length
; i
++)
5520 if (v1
->v
.val_float
.array
[i
] != v2
->v
.val_float
.array
[i
])
5523 case dw_val_class_flag
:
5524 return v1
->v
.val_flag
== v2
->v
.val_flag
;
5525 case dw_val_class_str
:
5526 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
5528 case dw_val_class_addr
:
5529 r1
= v1
->v
.val_addr
;
5530 r2
= v2
->v
.val_addr
;
5531 if (GET_CODE (r1
) != GET_CODE (r2
))
5533 switch (GET_CODE (r1
))
5536 return !strcmp (XSTR (r1
, 0), XSTR (r2
, 0));
5542 case dw_val_class_offset
:
5543 return v1
->v
.val_offset
== v2
->v
.val_offset
;
5545 case dw_val_class_loc
:
5546 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
5548 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
5549 if (!same_loc_p (loc1
, loc2
, mark
))
5551 return !loc1
&& !loc2
;
5553 case dw_val_class_die_ref
:
5554 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
5556 case dw_val_class_fde_ref
:
5557 case dw_val_class_lbl_id
:
5558 case dw_val_class_lbl_offset
:
5566 /* Do the attributes look the same? */
5569 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
5571 if (at1
->dw_attr
!= at2
->dw_attr
)
5574 /* We don't care about differences in file numbering. */
5575 if (at1
->dw_attr
== DW_AT_decl_file
5576 /* Or that this was compiled with a different compiler snapshot; if
5577 the output is the same, that's what matters. */
5578 || at1
->dw_attr
== DW_AT_producer
)
5581 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
5584 /* Do the dies look the same? */
5587 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
5592 /* To avoid infinite recursion. */
5594 return die1
->die_mark
== die2
->die_mark
;
5595 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
5597 if (die1
->die_tag
!= die2
->die_tag
)
5600 for (a1
= die1
->die_attr
, a2
= die2
->die_attr
;
5602 a1
= a1
->dw_attr_next
, a2
= a2
->dw_attr_next
)
5603 if (!same_attr_p (a1
, a2
, mark
))
5608 for (c1
= die1
->die_child
, c2
= die2
->die_child
;
5610 c1
= c1
->die_sib
, c2
= c2
->die_sib
)
5611 if (!same_die_p (c1
, c2
, mark
))
5619 /* Do the dies look the same? Wrapper around same_die_p. */
5622 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
5625 int ret
= same_die_p (die1
, die2
, &mark
);
5627 unmark_all_dies (die1
);
5628 unmark_all_dies (die2
);
5633 /* The prefix to attach to symbols on DIEs in the current comdat debug
5635 static char *comdat_symbol_id
;
5637 /* The index of the current symbol within the current comdat CU. */
5638 static unsigned int comdat_symbol_number
;
5640 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5641 children, and set comdat_symbol_id accordingly. */
5644 compute_section_prefix (dw_die_ref unit_die
)
5646 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
5647 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
5648 char *name
= (char *) alloca (strlen (base
) + 64);
5651 unsigned char checksum
[16];
5654 /* Compute the checksum of the DIE, then append part of it as hex digits to
5655 the name filename of the unit. */
5657 md5_init_ctx (&ctx
);
5659 die_checksum (unit_die
, &ctx
, &mark
);
5660 unmark_all_dies (unit_die
);
5661 md5_finish_ctx (&ctx
, checksum
);
5663 sprintf (name
, "%s.", base
);
5664 clean_symbol_name (name
);
5666 p
= name
+ strlen (name
);
5667 for (i
= 0; i
< 4; i
++)
5669 sprintf (p
, "%.2x", checksum
[i
]);
5673 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
5674 comdat_symbol_number
= 0;
5677 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5680 is_type_die (dw_die_ref die
)
5682 switch (die
->die_tag
)
5684 case DW_TAG_array_type
:
5685 case DW_TAG_class_type
:
5686 case DW_TAG_enumeration_type
:
5687 case DW_TAG_pointer_type
:
5688 case DW_TAG_reference_type
:
5689 case DW_TAG_string_type
:
5690 case DW_TAG_structure_type
:
5691 case DW_TAG_subroutine_type
:
5692 case DW_TAG_union_type
:
5693 case DW_TAG_ptr_to_member_type
:
5694 case DW_TAG_set_type
:
5695 case DW_TAG_subrange_type
:
5696 case DW_TAG_base_type
:
5697 case DW_TAG_const_type
:
5698 case DW_TAG_file_type
:
5699 case DW_TAG_packed_type
:
5700 case DW_TAG_volatile_type
:
5701 case DW_TAG_typedef
:
5708 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5709 Basically, we want to choose the bits that are likely to be shared between
5710 compilations (types) and leave out the bits that are specific to individual
5711 compilations (functions). */
5714 is_comdat_die (dw_die_ref c
)
5716 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5717 we do for stabs. The advantage is a greater likelihood of sharing between
5718 objects that don't include headers in the same order (and therefore would
5719 put the base types in a different comdat). jason 8/28/00 */
5721 if (c
->die_tag
== DW_TAG_base_type
)
5724 if (c
->die_tag
== DW_TAG_pointer_type
5725 || c
->die_tag
== DW_TAG_reference_type
5726 || c
->die_tag
== DW_TAG_const_type
5727 || c
->die_tag
== DW_TAG_volatile_type
)
5729 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
5731 return t
? is_comdat_die (t
) : 0;
5734 return is_type_die (c
);
5737 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5738 compilation unit. */
5741 is_symbol_die (dw_die_ref c
)
5743 return (is_type_die (c
)
5744 || (get_AT (c
, DW_AT_declaration
)
5745 && !get_AT (c
, DW_AT_specification
)));
5749 gen_internal_sym (const char *prefix
)
5753 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
5754 return xstrdup (buf
);
5757 /* Assign symbols to all worthy DIEs under DIE. */
5760 assign_symbol_names (dw_die_ref die
)
5764 if (is_symbol_die (die
))
5766 if (comdat_symbol_id
)
5768 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
5770 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
5771 comdat_symbol_id
, comdat_symbol_number
++);
5772 die
->die_symbol
= xstrdup (p
);
5775 die
->die_symbol
= gen_internal_sym ("LDIE");
5778 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5779 assign_symbol_names (c
);
5782 struct cu_hash_table_entry
5785 unsigned min_comdat_num
, max_comdat_num
;
5786 struct cu_hash_table_entry
*next
;
5789 /* Routines to manipulate hash table of CUs. */
5791 htab_cu_hash (const void *of
)
5793 const struct cu_hash_table_entry
*entry
= of
;
5795 return htab_hash_string (entry
->cu
->die_symbol
);
5799 htab_cu_eq (const void *of1
, const void *of2
)
5801 const struct cu_hash_table_entry
*entry1
= of1
;
5802 const struct die_struct
*entry2
= of2
;
5804 return !strcmp (entry1
->cu
->die_symbol
, entry2
->die_symbol
);
5808 htab_cu_del (void *what
)
5810 struct cu_hash_table_entry
*next
, *entry
= what
;
5820 /* Check whether we have already seen this CU and set up SYM_NUM
5823 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
5825 struct cu_hash_table_entry dummy
;
5826 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
5828 dummy
.max_comdat_num
= 0;
5830 slot
= (struct cu_hash_table_entry
**)
5831 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
5835 for (; entry
; last
= entry
, entry
= entry
->next
)
5837 if (same_die_p_wrap (cu
, entry
->cu
))
5843 *sym_num
= entry
->min_comdat_num
;
5847 entry
= xcalloc (1, sizeof (struct cu_hash_table_entry
));
5849 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
5850 entry
->next
= *slot
;
5856 /* Record SYM_NUM to record of CU in HTABLE. */
5858 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
5860 struct cu_hash_table_entry
**slot
, *entry
;
5862 slot
= (struct cu_hash_table_entry
**)
5863 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
5867 entry
->max_comdat_num
= sym_num
;
5870 /* Traverse the DIE (which is always comp_unit_die), and set up
5871 additional compilation units for each of the include files we see
5872 bracketed by BINCL/EINCL. */
5875 break_out_includes (dw_die_ref die
)
5878 dw_die_ref unit
= NULL
;
5879 limbo_die_node
*node
, **pnode
;
5880 htab_t cu_hash_table
;
5882 for (ptr
= &(die
->die_child
); *ptr
;)
5884 dw_die_ref c
= *ptr
;
5886 if (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
5887 || (unit
&& is_comdat_die (c
)))
5889 /* This DIE is for a secondary CU; remove it from the main one. */
5892 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
5894 unit
= push_new_compile_unit (unit
, c
);
5897 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
5899 unit
= pop_compile_unit (unit
);
5903 add_child_die (unit
, c
);
5907 /* Leave this DIE in the main CU. */
5908 ptr
= &(c
->die_sib
);
5914 /* We can only use this in debugging, since the frontend doesn't check
5915 to make sure that we leave every include file we enter. */
5920 assign_symbol_names (die
);
5921 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
5922 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
5928 compute_section_prefix (node
->die
);
5929 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
5930 &comdat_symbol_number
);
5931 assign_symbol_names (node
->die
);
5933 *pnode
= node
->next
;
5936 pnode
= &node
->next
;
5937 record_comdat_symbol_number (node
->die
, cu_hash_table
,
5938 comdat_symbol_number
);
5941 htab_delete (cu_hash_table
);
5944 /* Traverse the DIE and add a sibling attribute if it may have the
5945 effect of speeding up access to siblings. To save some space,
5946 avoid generating sibling attributes for DIE's without children. */
5949 add_sibling_attributes (dw_die_ref die
)
5953 if (die
->die_tag
!= DW_TAG_compile_unit
5954 && die
->die_sib
&& die
->die_child
!= NULL
)
5955 /* Add the sibling link to the front of the attribute list. */
5956 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
5958 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5959 add_sibling_attributes (c
);
5962 /* Output all location lists for the DIE and its children. */
5965 output_location_lists (dw_die_ref die
)
5970 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
5971 if (AT_class (d_attr
) == dw_val_class_loc_list
)
5972 output_loc_list (AT_loc_list (d_attr
));
5974 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5975 output_location_lists (c
);
5979 /* The format of each DIE (and its attribute value pairs) is encoded in an
5980 abbreviation table. This routine builds the abbreviation table and assigns
5981 a unique abbreviation id for each abbreviation entry. The children of each
5982 die are visited recursively. */
5985 build_abbrev_table (dw_die_ref die
)
5987 unsigned long abbrev_id
;
5988 unsigned int n_alloc
;
5990 dw_attr_ref d_attr
, a_attr
;
5992 /* Scan the DIE references, and mark as external any that refer to
5993 DIEs from other CUs (i.e. those which are not marked). */
5994 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
5995 if (AT_class (d_attr
) == dw_val_class_die_ref
5996 && AT_ref (d_attr
)->die_mark
== 0)
5998 if (AT_ref (d_attr
)->die_symbol
== 0)
6001 set_AT_ref_external (d_attr
, 1);
6004 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6006 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6008 if (abbrev
->die_tag
== die
->die_tag
)
6010 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
6012 a_attr
= abbrev
->die_attr
;
6013 d_attr
= die
->die_attr
;
6015 while (a_attr
!= NULL
&& d_attr
!= NULL
)
6017 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
6018 || (value_format (a_attr
) != value_format (d_attr
)))
6021 a_attr
= a_attr
->dw_attr_next
;
6022 d_attr
= d_attr
->dw_attr_next
;
6025 if (a_attr
== NULL
&& d_attr
== NULL
)
6031 if (abbrev_id
>= abbrev_die_table_in_use
)
6033 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
6035 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
6036 abbrev_die_table
= ggc_realloc (abbrev_die_table
,
6037 sizeof (dw_die_ref
) * n_alloc
);
6039 memset ((char *) &abbrev_die_table
[abbrev_die_table_allocated
], 0,
6040 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
6041 abbrev_die_table_allocated
= n_alloc
;
6044 ++abbrev_die_table_in_use
;
6045 abbrev_die_table
[abbrev_id
] = die
;
6048 die
->die_abbrev
= abbrev_id
;
6049 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6050 build_abbrev_table (c
);
6053 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6056 constant_size (long unsigned int value
)
6063 log
= floor_log2 (value
);
6066 log
= 1 << (floor_log2 (log
) + 1);
6071 /* Return the size of a DIE as it is represented in the
6072 .debug_info section. */
6074 static unsigned long
6075 size_of_die (dw_die_ref die
)
6077 unsigned long size
= 0;
6080 size
+= size_of_uleb128 (die
->die_abbrev
);
6081 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6083 switch (AT_class (a
))
6085 case dw_val_class_addr
:
6086 size
+= DWARF2_ADDR_SIZE
;
6088 case dw_val_class_offset
:
6089 size
+= DWARF_OFFSET_SIZE
;
6091 case dw_val_class_loc
:
6093 unsigned long lsize
= size_of_locs (AT_loc (a
));
6096 size
+= constant_size (lsize
);
6100 case dw_val_class_loc_list
:
6101 size
+= DWARF_OFFSET_SIZE
;
6103 case dw_val_class_range_list
:
6104 size
+= DWARF_OFFSET_SIZE
;
6106 case dw_val_class_const
:
6107 size
+= size_of_sleb128 (AT_int (a
));
6109 case dw_val_class_unsigned_const
:
6110 size
+= constant_size (AT_unsigned (a
));
6112 case dw_val_class_long_long
:
6113 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
6115 case dw_val_class_float
:
6116 size
+= 1 + a
->dw_attr_val
.v
.val_float
.length
* 4; /* block */
6118 case dw_val_class_flag
:
6121 case dw_val_class_die_ref
:
6122 if (AT_ref_external (a
))
6123 size
+= DWARF2_ADDR_SIZE
;
6125 size
+= DWARF_OFFSET_SIZE
;
6127 case dw_val_class_fde_ref
:
6128 size
+= DWARF_OFFSET_SIZE
;
6130 case dw_val_class_lbl_id
:
6131 size
+= DWARF2_ADDR_SIZE
;
6133 case dw_val_class_lbl_offset
:
6134 size
+= DWARF_OFFSET_SIZE
;
6136 case dw_val_class_str
:
6137 if (AT_string_form (a
) == DW_FORM_strp
)
6138 size
+= DWARF_OFFSET_SIZE
;
6140 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
6150 /* Size the debugging information associated with a given DIE. Visits the
6151 DIE's children recursively. Updates the global variable next_die_offset, on
6152 each time through. Uses the current value of next_die_offset to update the
6153 die_offset field in each DIE. */
6156 calc_die_sizes (dw_die_ref die
)
6160 die
->die_offset
= next_die_offset
;
6161 next_die_offset
+= size_of_die (die
);
6163 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6166 if (die
->die_child
!= NULL
)
6167 /* Count the null byte used to terminate sibling lists. */
6168 next_die_offset
+= 1;
6171 /* Set the marks for a die and its children. We do this so
6172 that we know whether or not a reference needs to use FORM_ref_addr; only
6173 DIEs in the same CU will be marked. We used to clear out the offset
6174 and use that as the flag, but ran into ordering problems. */
6177 mark_dies (dw_die_ref die
)
6185 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6189 /* Clear the marks for a die and its children. */
6192 unmark_dies (dw_die_ref die
)
6200 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6204 /* Clear the marks for a die, its children and referred dies. */
6207 unmark_all_dies (dw_die_ref die
)
6216 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6217 unmark_all_dies (c
);
6219 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
6220 if (AT_class (a
) == dw_val_class_die_ref
)
6221 unmark_all_dies (AT_ref (a
));
6224 /* Return the size of the .debug_pubnames table generated for the
6225 compilation unit. */
6227 static unsigned long
6228 size_of_pubnames (void)
6233 size
= DWARF_PUBNAMES_HEADER_SIZE
;
6234 for (i
= 0; i
< pubname_table_in_use
; i
++)
6236 pubname_ref p
= &pubname_table
[i
];
6237 size
+= DWARF_OFFSET_SIZE
+ strlen (p
->name
) + 1;
6240 size
+= DWARF_OFFSET_SIZE
;
6244 /* Return the size of the information in the .debug_aranges section. */
6246 static unsigned long
6247 size_of_aranges (void)
6251 size
= DWARF_ARANGES_HEADER_SIZE
;
6253 /* Count the address/length pair for this compilation unit. */
6254 size
+= 2 * DWARF2_ADDR_SIZE
;
6255 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
6257 /* Count the two zero words used to terminated the address range table. */
6258 size
+= 2 * DWARF2_ADDR_SIZE
;
6262 /* Select the encoding of an attribute value. */
6264 static enum dwarf_form
6265 value_format (dw_attr_ref a
)
6267 switch (a
->dw_attr_val
.val_class
)
6269 case dw_val_class_addr
:
6270 return DW_FORM_addr
;
6271 case dw_val_class_range_list
:
6272 case dw_val_class_offset
:
6273 if (DWARF_OFFSET_SIZE
== 4)
6274 return DW_FORM_data4
;
6275 if (DWARF_OFFSET_SIZE
== 8)
6276 return DW_FORM_data8
;
6278 case dw_val_class_loc_list
:
6279 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6280 .debug_loc section */
6281 return DW_FORM_data4
;
6282 case dw_val_class_loc
:
6283 switch (constant_size (size_of_locs (AT_loc (a
))))
6286 return DW_FORM_block1
;
6288 return DW_FORM_block2
;
6292 case dw_val_class_const
:
6293 return DW_FORM_sdata
;
6294 case dw_val_class_unsigned_const
:
6295 switch (constant_size (AT_unsigned (a
)))
6298 return DW_FORM_data1
;
6300 return DW_FORM_data2
;
6302 return DW_FORM_data4
;
6304 return DW_FORM_data8
;
6308 case dw_val_class_long_long
:
6309 return DW_FORM_block1
;
6310 case dw_val_class_float
:
6311 return DW_FORM_block1
;
6312 case dw_val_class_flag
:
6313 return DW_FORM_flag
;
6314 case dw_val_class_die_ref
:
6315 if (AT_ref_external (a
))
6316 return DW_FORM_ref_addr
;
6319 case dw_val_class_fde_ref
:
6320 return DW_FORM_data
;
6321 case dw_val_class_lbl_id
:
6322 return DW_FORM_addr
;
6323 case dw_val_class_lbl_offset
:
6324 return DW_FORM_data
;
6325 case dw_val_class_str
:
6326 return AT_string_form (a
);
6333 /* Output the encoding of an attribute value. */
6336 output_value_format (dw_attr_ref a
)
6338 enum dwarf_form form
= value_format (a
);
6340 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
6343 /* Output the .debug_abbrev section which defines the DIE abbreviation
6347 output_abbrev_section (void)
6349 unsigned long abbrev_id
;
6353 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6355 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6357 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
6358 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
6359 dwarf_tag_name (abbrev
->die_tag
));
6361 if (abbrev
->die_child
!= NULL
)
6362 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
6364 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
6366 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
6367 a_attr
= a_attr
->dw_attr_next
)
6369 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
6370 dwarf_attr_name (a_attr
->dw_attr
));
6371 output_value_format (a_attr
);
6374 dw2_asm_output_data (1, 0, NULL
);
6375 dw2_asm_output_data (1, 0, NULL
);
6378 /* Terminate the table. */
6379 dw2_asm_output_data (1, 0, NULL
);
6382 /* Output a symbol we can use to refer to this DIE from another CU. */
6385 output_die_symbol (dw_die_ref die
)
6387 char *sym
= die
->die_symbol
;
6392 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
6393 /* We make these global, not weak; if the target doesn't support
6394 .linkonce, it doesn't support combining the sections, so debugging
6396 (*targetm
.asm_out
.globalize_label
) (asm_out_file
, sym
);
6398 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
6401 /* Return a new location list, given the begin and end range, and the
6402 expression. gensym tells us whether to generate a new internal symbol for
6403 this location list node, which is done for the head of the list only. */
6405 static inline dw_loc_list_ref
6406 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
6407 const char *section
, unsigned int gensym
)
6409 dw_loc_list_ref retlist
= ggc_alloc_cleared (sizeof (dw_loc_list_node
));
6411 retlist
->begin
= begin
;
6413 retlist
->expr
= expr
;
6414 retlist
->section
= section
;
6416 retlist
->ll_symbol
= gen_internal_sym ("LLST");
6421 /* Add a location description expression to a location list. */
6424 add_loc_descr_to_loc_list (dw_loc_list_ref
*list_head
, dw_loc_descr_ref descr
,
6425 const char *begin
, const char *end
,
6426 const char *section
)
6430 /* Find the end of the chain. */
6431 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
6434 /* Add a new location list node to the list. */
6435 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
6438 /* Output the location list given to us. */
6441 output_loc_list (dw_loc_list_ref list_head
)
6443 dw_loc_list_ref curr
= list_head
;
6445 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
6447 /* ??? This shouldn't be needed now that we've forced the
6448 compilation unit base address to zero when there is code
6449 in more than one section. */
6450 if (strcmp (curr
->section
, ".text") == 0)
6452 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6453 dw2_asm_output_data (DWARF2_ADDR_SIZE
, ~(unsigned HOST_WIDE_INT
) 0,
6454 "Location list base address specifier fake entry");
6455 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, curr
->section
,
6456 "Location list base address specifier base");
6459 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
6463 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
6464 "Location list begin address (%s)",
6465 list_head
->ll_symbol
);
6466 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
6467 "Location list end address (%s)",
6468 list_head
->ll_symbol
);
6469 size
= size_of_locs (curr
->expr
);
6471 /* Output the block length for this list of location operations. */
6474 dw2_asm_output_data (2, size
, "%s", "Location expression size");
6476 output_loc_sequence (curr
->expr
);
6479 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6480 "Location list terminator begin (%s)",
6481 list_head
->ll_symbol
);
6482 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6483 "Location list terminator end (%s)",
6484 list_head
->ll_symbol
);
6487 /* Output the DIE and its attributes. Called recursively to generate
6488 the definitions of each child DIE. */
6491 output_die (dw_die_ref die
)
6497 /* If someone in another CU might refer to us, set up a symbol for
6498 them to point to. */
6499 if (die
->die_symbol
)
6500 output_die_symbol (die
);
6502 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
6503 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6505 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6507 const char *name
= dwarf_attr_name (a
->dw_attr
);
6509 switch (AT_class (a
))
6511 case dw_val_class_addr
:
6512 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
6515 case dw_val_class_offset
:
6516 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
6520 case dw_val_class_range_list
:
6522 char *p
= strchr (ranges_section_label
, '\0');
6524 sprintf (p
, "+0x%lx", a
->dw_attr_val
.v
.val_offset
);
6525 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
6531 case dw_val_class_loc
:
6532 size
= size_of_locs (AT_loc (a
));
6534 /* Output the block length for this list of location operations. */
6535 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
6537 output_loc_sequence (AT_loc (a
));
6540 case dw_val_class_const
:
6541 /* ??? It would be slightly more efficient to use a scheme like is
6542 used for unsigned constants below, but gdb 4.x does not sign
6543 extend. Gdb 5.x does sign extend. */
6544 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
6547 case dw_val_class_unsigned_const
:
6548 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
6549 AT_unsigned (a
), "%s", name
);
6552 case dw_val_class_long_long
:
6554 unsigned HOST_WIDE_INT first
, second
;
6556 dw2_asm_output_data (1,
6557 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6560 if (WORDS_BIG_ENDIAN
)
6562 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6563 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
6567 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
6568 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6571 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6572 first
, "long long constant");
6573 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6578 case dw_val_class_float
:
6582 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_float
.length
* 4,
6585 for (i
= 0; i
< a
->dw_attr_val
.v
.val_float
.length
; i
++)
6586 dw2_asm_output_data (4, a
->dw_attr_val
.v
.val_float
.array
[i
],
6587 "fp constant word %u", i
);
6591 case dw_val_class_flag
:
6592 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
6595 case dw_val_class_loc_list
:
6597 char *sym
= AT_loc_list (a
)->ll_symbol
;
6601 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
,
6602 loc_section_label
, "%s", name
);
6606 case dw_val_class_die_ref
:
6607 if (AT_ref_external (a
))
6609 char *sym
= AT_ref (a
)->die_symbol
;
6613 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, "%s", name
);
6615 else if (AT_ref (a
)->die_offset
== 0)
6618 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
6622 case dw_val_class_fde_ref
:
6626 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
6627 a
->dw_attr_val
.v
.val_fde_index
* 2);
6628 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, "%s", name
);
6632 case dw_val_class_lbl_id
:
6633 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
6636 case dw_val_class_lbl_offset
:
6637 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
), "%s", name
);
6640 case dw_val_class_str
:
6641 if (AT_string_form (a
) == DW_FORM_strp
)
6642 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
6643 a
->dw_attr_val
.v
.val_str
->label
,
6644 "%s: \"%s\"", name
, AT_string (a
));
6646 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
6654 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6657 /* Add null byte to terminate sibling list. */
6658 if (die
->die_child
!= NULL
)
6659 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6663 /* Output the compilation unit that appears at the beginning of the
6664 .debug_info section, and precedes the DIE descriptions. */
6667 output_compilation_unit_header (void)
6669 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
6670 dw2_asm_output_data (4, 0xffffffff,
6671 "Initial length escape value indicating 64-bit DWARF extension");
6672 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
6673 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
6674 "Length of Compilation Unit Info");
6675 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
6676 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
6677 "Offset Into Abbrev. Section");
6678 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
6681 /* Output the compilation unit DIE and its children. */
6684 output_comp_unit (dw_die_ref die
, int output_if_empty
)
6686 const char *secname
;
6689 /* Unless we are outputting main CU, we may throw away empty ones. */
6690 if (!output_if_empty
&& die
->die_child
== NULL
)
6693 /* Even if there are no children of this DIE, we must output the information
6694 about the compilation unit. Otherwise, on an empty translation unit, we
6695 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6696 will then complain when examining the file. First mark all the DIEs in
6697 this CU so we know which get local refs. */
6700 build_abbrev_table (die
);
6702 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6703 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
6704 calc_die_sizes (die
);
6706 oldsym
= die
->die_symbol
;
6709 tmp
= (char *) alloca (strlen (oldsym
) + 24);
6711 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
6713 die
->die_symbol
= NULL
;
6716 secname
= (const char *) DEBUG_INFO_SECTION
;
6718 /* Output debugging information. */
6719 named_section_flags (secname
, SECTION_DEBUG
);
6720 output_compilation_unit_header ();
6723 /* Leave the marks on the main CU, so we can check them in
6728 die
->die_symbol
= oldsym
;
6732 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6733 output of lang_hooks.decl_printable_name for C++ looks like
6734 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6737 dwarf2_name (tree decl
, int scope
)
6739 return (*lang_hooks
.decl_printable_name
) (decl
, scope
? 1 : 0);
6742 /* Add a new entry to .debug_pubnames if appropriate. */
6745 add_pubname (tree decl
, dw_die_ref die
)
6749 if (! TREE_PUBLIC (decl
))
6752 if (pubname_table_in_use
== pubname_table_allocated
)
6754 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
6756 = (pubname_ref
) ggc_realloc (pubname_table
,
6757 (pubname_table_allocated
6758 * sizeof (pubname_entry
)));
6759 memset (pubname_table
+ pubname_table_in_use
, 0,
6760 PUBNAME_TABLE_INCREMENT
* sizeof (pubname_entry
));
6763 p
= &pubname_table
[pubname_table_in_use
++];
6765 p
->name
= xstrdup (dwarf2_name (decl
, 1));
6768 /* Output the public names table used to speed up access to externally
6769 visible names. For now, only generate entries for externally
6770 visible procedures. */
6773 output_pubnames (void)
6776 unsigned long pubnames_length
= size_of_pubnames ();
6778 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
6779 dw2_asm_output_data (4, 0xffffffff,
6780 "Initial length escape value indicating 64-bit DWARF extension");
6781 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
6782 "Length of Public Names Info");
6783 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6784 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6785 "Offset of Compilation Unit Info");
6786 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
6787 "Compilation Unit Length");
6789 for (i
= 0; i
< pubname_table_in_use
; i
++)
6791 pubname_ref pub
= &pubname_table
[i
];
6793 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6794 if (pub
->die
->die_mark
== 0)
6797 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
6800 dw2_asm_output_nstring (pub
->name
, -1, "external name");
6803 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
6806 /* Add a new entry to .debug_aranges if appropriate. */
6809 add_arange (tree decl
, dw_die_ref die
)
6811 if (! DECL_SECTION_NAME (decl
))
6814 if (arange_table_in_use
== arange_table_allocated
)
6816 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
6817 arange_table
= ggc_realloc (arange_table
,
6818 (arange_table_allocated
6819 * sizeof (dw_die_ref
)));
6820 memset (arange_table
+ arange_table_in_use
, 0,
6821 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
6824 arange_table
[arange_table_in_use
++] = die
;
6827 /* Output the information that goes into the .debug_aranges table.
6828 Namely, define the beginning and ending address range of the
6829 text section generated for this compilation unit. */
6832 output_aranges (void)
6835 unsigned long aranges_length
= size_of_aranges ();
6837 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
6838 dw2_asm_output_data (4, 0xffffffff,
6839 "Initial length escape value indicating 64-bit DWARF extension");
6840 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
6841 "Length of Address Ranges Info");
6842 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6843 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6844 "Offset of Compilation Unit Info");
6845 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
6846 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6848 /* We need to align to twice the pointer size here. */
6849 if (DWARF_ARANGES_PAD_SIZE
)
6851 /* Pad using a 2 byte words so that padding is correct for any
6853 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6854 2 * DWARF2_ADDR_SIZE
);
6855 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
6856 dw2_asm_output_data (2, 0, NULL
);
6859 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
6860 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
6861 text_section_label
, "Length");
6863 for (i
= 0; i
< arange_table_in_use
; i
++)
6865 dw_die_ref die
= arange_table
[i
];
6867 /* We shouldn't see aranges for DIEs outside of the main CU. */
6868 if (die
->die_mark
== 0)
6871 if (die
->die_tag
== DW_TAG_subprogram
)
6873 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
6875 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
6876 get_AT_low_pc (die
), "Length");
6880 /* A static variable; extract the symbol from DW_AT_location.
6881 Note that this code isn't currently hit, as we only emit
6882 aranges for functions (jason 9/23/99). */
6883 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
6884 dw_loc_descr_ref loc
;
6886 if (! a
|| AT_class (a
) != dw_val_class_loc
)
6890 if (loc
->dw_loc_opc
!= DW_OP_addr
)
6893 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
6894 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
6895 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
6896 get_AT_unsigned (die
, DW_AT_byte_size
),
6901 /* Output the terminator words. */
6902 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6903 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6906 /* Add a new entry to .debug_ranges. Return the offset at which it
6910 add_ranges (tree block
)
6912 unsigned int in_use
= ranges_table_in_use
;
6914 if (in_use
== ranges_table_allocated
)
6916 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
6917 ranges_table
= (dw_ranges_ref
)
6918 ggc_realloc (ranges_table
, (ranges_table_allocated
6919 * sizeof (struct dw_ranges_struct
)));
6920 memset (ranges_table
+ ranges_table_in_use
, 0,
6921 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
6924 ranges_table
[in_use
].block_num
= (block
? BLOCK_NUMBER (block
) : 0);
6925 ranges_table_in_use
= in_use
+ 1;
6927 return in_use
* 2 * DWARF2_ADDR_SIZE
;
6931 output_ranges (void)
6934 static const char *const start_fmt
= "Offset 0x%x";
6935 const char *fmt
= start_fmt
;
6937 for (i
= 0; i
< ranges_table_in_use
; i
++)
6939 int block_num
= ranges_table
[i
].block_num
;
6943 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
6944 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
6946 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
6947 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
6949 /* If all code is in the text section, then the compilation
6950 unit base address defaults to DW_AT_low_pc, which is the
6951 base of the text section. */
6952 if (separate_line_info_table_in_use
== 0)
6954 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
6956 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
6957 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
6958 text_section_label
, NULL
);
6961 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6962 compilation unit base address to zero, which allows us to
6963 use absolute addresses, and not worry about whether the
6964 target supports cross-section arithmetic. */
6967 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
6968 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
6969 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
6976 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6977 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6983 /* Data structure containing information about input files. */
6986 char *path
; /* Complete file name. */
6987 char *fname
; /* File name part. */
6988 int length
; /* Length of entire string. */
6989 int file_idx
; /* Index in input file table. */
6990 int dir_idx
; /* Index in directory table. */
6993 /* Data structure containing information about directories with source
6997 char *path
; /* Path including directory name. */
6998 int length
; /* Path length. */
6999 int prefix
; /* Index of directory entry which is a prefix. */
7000 int count
; /* Number of files in this directory. */
7001 int dir_idx
; /* Index of directory used as base. */
7002 int used
; /* Used in the end? */
7005 /* Callback function for file_info comparison. We sort by looking at
7006 the directories in the path. */
7009 file_info_cmp (const void *p1
, const void *p2
)
7011 const struct file_info
*s1
= p1
;
7012 const struct file_info
*s2
= p2
;
7016 /* Take care of file names without directories. We need to make sure that
7017 we return consistent values to qsort since some will get confused if
7018 we return the same value when identical operands are passed in opposite
7019 orders. So if neither has a directory, return 0 and otherwise return
7020 1 or -1 depending on which one has the directory. */
7021 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
7022 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
7024 cp1
= (unsigned char *) s1
->path
;
7025 cp2
= (unsigned char *) s2
->path
;
7031 /* Reached the end of the first path? If so, handle like above. */
7032 if ((cp1
== (unsigned char *) s1
->fname
)
7033 || (cp2
== (unsigned char *) s2
->fname
))
7034 return ((cp2
== (unsigned char *) s2
->fname
)
7035 - (cp1
== (unsigned char *) s1
->fname
));
7037 /* Character of current path component the same? */
7038 else if (*cp1
!= *cp2
)
7043 /* Output the directory table and the file name table. We try to minimize
7044 the total amount of memory needed. A heuristic is used to avoid large
7045 slowdowns with many input files. */
7048 output_file_names (void)
7050 struct file_info
*files
;
7051 struct dir_info
*dirs
;
7060 /* Handle the case where file_table is empty. */
7061 if (VARRAY_ACTIVE_SIZE (file_table
) <= 1)
7063 dw2_asm_output_data (1, 0, "End directory table");
7064 dw2_asm_output_data (1, 0, "End file name table");
7068 /* Allocate the various arrays we need. */
7069 files
= (struct file_info
*) alloca (VARRAY_ACTIVE_SIZE (file_table
)
7070 * sizeof (struct file_info
));
7071 dirs
= (struct dir_info
*) alloca (VARRAY_ACTIVE_SIZE (file_table
)
7072 * sizeof (struct dir_info
));
7074 /* Sort the file names. */
7075 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7079 /* Skip all leading "./". */
7080 f
= VARRAY_CHAR_PTR (file_table
, i
);
7081 while (f
[0] == '.' && f
[1] == '/')
7084 /* Create a new array entry. */
7086 files
[i
].length
= strlen (f
);
7087 files
[i
].file_idx
= i
;
7089 /* Search for the file name part. */
7090 f
= strrchr (f
, '/');
7091 files
[i
].fname
= f
== NULL
? files
[i
].path
: f
+ 1;
7094 qsort (files
+ 1, VARRAY_ACTIVE_SIZE (file_table
) - 1,
7095 sizeof (files
[0]), file_info_cmp
);
7097 /* Find all the different directories used. */
7098 dirs
[0].path
= files
[1].path
;
7099 dirs
[0].length
= files
[1].fname
- files
[1].path
;
7100 dirs
[0].prefix
= -1;
7102 dirs
[0].dir_idx
= 0;
7104 files
[1].dir_idx
= 0;
7107 for (i
= 2; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7108 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
7109 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
7110 dirs
[ndirs
- 1].length
) == 0)
7112 /* Same directory as last entry. */
7113 files
[i
].dir_idx
= ndirs
- 1;
7114 ++dirs
[ndirs
- 1].count
;
7120 /* This is a new directory. */
7121 dirs
[ndirs
].path
= files
[i
].path
;
7122 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
7123 dirs
[ndirs
].count
= 1;
7124 dirs
[ndirs
].dir_idx
= ndirs
;
7125 dirs
[ndirs
].used
= 0;
7126 files
[i
].dir_idx
= ndirs
;
7128 /* Search for a prefix. */
7129 dirs
[ndirs
].prefix
= -1;
7130 for (j
= 0; j
< ndirs
; j
++)
7131 if (dirs
[j
].length
< dirs
[ndirs
].length
7132 && dirs
[j
].length
> 1
7133 && (dirs
[ndirs
].prefix
== -1
7134 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
7135 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
7136 dirs
[ndirs
].prefix
= j
;
7141 /* Now to the actual work. We have to find a subset of the directories which
7142 allow expressing the file name using references to the directory table
7143 with the least amount of characters. We do not do an exhaustive search
7144 where we would have to check out every combination of every single
7145 possible prefix. Instead we use a heuristic which provides nearly optimal
7146 results in most cases and never is much off. */
7147 saved
= (int *) alloca (ndirs
* sizeof (int));
7148 savehere
= (int *) alloca (ndirs
* sizeof (int));
7150 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
7151 for (i
= 0; i
< ndirs
; i
++)
7156 /* We can always save some space for the current directory. But this
7157 does not mean it will be enough to justify adding the directory. */
7158 savehere
[i
] = dirs
[i
].length
;
7159 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
7161 for (j
= i
+ 1; j
< ndirs
; j
++)
7164 if (saved
[j
] < dirs
[i
].length
)
7166 /* Determine whether the dirs[i] path is a prefix of the
7171 while (k
!= -1 && k
!= (int) i
)
7176 /* Yes it is. We can possibly safe some memory but
7177 writing the filenames in dirs[j] relative to
7179 savehere
[j
] = dirs
[i
].length
;
7180 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
7185 /* Check whether we can safe enough to justify adding the dirs[i]
7187 if (total
> dirs
[i
].length
+ 1)
7189 /* It's worthwhile adding. */
7190 for (j
= i
; j
< ndirs
; j
++)
7191 if (savehere
[j
] > 0)
7193 /* Remember how much we saved for this directory so far. */
7194 saved
[j
] = savehere
[j
];
7196 /* Remember the prefix directory. */
7197 dirs
[j
].dir_idx
= i
;
7202 /* We have to emit them in the order they appear in the file_table array
7203 since the index is used in the debug info generation. To do this
7204 efficiently we generate a back-mapping of the indices first. */
7205 backmap
= (int *) alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (int));
7206 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7208 backmap
[files
[i
].file_idx
] = i
;
7210 /* Mark this directory as used. */
7211 dirs
[dirs
[files
[i
].dir_idx
].dir_idx
].used
= 1;
7214 /* That was it. We are ready to emit the information. First emit the
7215 directory name table. We have to make sure the first actually emitted
7216 directory name has index one; zero is reserved for the current working
7217 directory. Make sure we do not confuse these indices with the one for the
7218 constructed table (even though most of the time they are identical). */
7220 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
7221 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
7222 if (dirs
[i
].used
!= 0)
7224 dirs
[i
].used
= idx
++;
7225 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
7226 "Directory Entry: 0x%x", dirs
[i
].used
);
7229 dw2_asm_output_data (1, 0, "End directory table");
7231 /* Correct the index for the current working directory entry if it
7233 if (idx_offset
== 0)
7236 /* Now write all the file names. */
7237 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7239 int file_idx
= backmap
[i
];
7240 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
7242 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
7243 "File Entry: 0x%lx", (unsigned long) i
);
7245 /* Include directory index. */
7246 dw2_asm_output_data_uleb128 (dirs
[dir_idx
].used
, NULL
);
7248 /* Modification time. */
7249 dw2_asm_output_data_uleb128 (0, NULL
);
7251 /* File length in bytes. */
7252 dw2_asm_output_data_uleb128 (0, NULL
);
7255 dw2_asm_output_data (1, 0, "End file name table");
7259 /* Output the source line number correspondence information. This
7260 information goes into the .debug_line section. */
7263 output_line_info (void)
7265 char l1
[20], l2
[20], p1
[20], p2
[20];
7266 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7267 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7270 unsigned long lt_index
;
7271 unsigned long current_line
;
7274 unsigned long current_file
;
7275 unsigned long function
;
7277 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
7278 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
7279 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
7280 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
7282 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7283 dw2_asm_output_data (4, 0xffffffff,
7284 "Initial length escape value indicating 64-bit DWARF extension");
7285 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
7286 "Length of Source Line Info");
7287 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
7289 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7290 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
7291 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
7293 /* Define the architecture-dependent minimum instruction length (in
7294 bytes). In this implementation of DWARF, this field is used for
7295 information purposes only. Since GCC generates assembly language,
7296 we have no a priori knowledge of how many instruction bytes are
7297 generated for each source line, and therefore can use only the
7298 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7299 commands. Accordingly, we fix this as `1', which is "correct
7300 enough" for all architectures, and don't let the target override. */
7301 dw2_asm_output_data (1, 1,
7302 "Minimum Instruction Length");
7304 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
7305 "Default is_stmt_start flag");
7306 dw2_asm_output_data (1, DWARF_LINE_BASE
,
7307 "Line Base Value (Special Opcodes)");
7308 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
7309 "Line Range Value (Special Opcodes)");
7310 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
7311 "Special Opcode Base");
7313 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
7317 case DW_LNS_advance_pc
:
7318 case DW_LNS_advance_line
:
7319 case DW_LNS_set_file
:
7320 case DW_LNS_set_column
:
7321 case DW_LNS_fixed_advance_pc
:
7329 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
7333 /* Write out the information about the files we use. */
7334 output_file_names ();
7335 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
7337 /* We used to set the address register to the first location in the text
7338 section here, but that didn't accomplish anything since we already
7339 have a line note for the opening brace of the first function. */
7341 /* Generate the line number to PC correspondence table, encoded as
7342 a series of state machine operations. */
7345 strcpy (prev_line_label
, text_section_label
);
7346 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
7348 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
7351 /* Disable this optimization for now; GDB wants to see two line notes
7352 at the beginning of a function so it can find the end of the
7355 /* Don't emit anything for redundant notes. Just updating the
7356 address doesn't accomplish anything, because we already assume
7357 that anything after the last address is this line. */
7358 if (line_info
->dw_line_num
== current_line
7359 && line_info
->dw_file_num
== current_file
)
7363 /* Emit debug info for the address of the current line.
7365 Unfortunately, we have little choice here currently, and must always
7366 use the most general form. GCC does not know the address delta
7367 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7368 attributes which will give an upper bound on the address range. We
7369 could perhaps use length attributes to determine when it is safe to
7370 use DW_LNS_fixed_advance_pc. */
7372 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
7375 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7376 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7377 "DW_LNS_fixed_advance_pc");
7378 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7382 /* This can handle any delta. This takes
7383 4+DWARF2_ADDR_SIZE bytes. */
7384 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7385 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7386 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7387 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7390 strcpy (prev_line_label
, line_label
);
7392 /* Emit debug info for the source file of the current line, if
7393 different from the previous line. */
7394 if (line_info
->dw_file_num
!= current_file
)
7396 current_file
= line_info
->dw_file_num
;
7397 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7398 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7399 VARRAY_CHAR_PTR (file_table
,
7403 /* Emit debug info for the current line number, choosing the encoding
7404 that uses the least amount of space. */
7405 if (line_info
->dw_line_num
!= current_line
)
7407 line_offset
= line_info
->dw_line_num
- current_line
;
7408 line_delta
= line_offset
- DWARF_LINE_BASE
;
7409 current_line
= line_info
->dw_line_num
;
7410 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7411 /* This can handle deltas from -10 to 234, using the current
7412 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7414 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7415 "line %lu", current_line
);
7418 /* This can handle any delta. This takes at least 4 bytes,
7419 depending on the value being encoded. */
7420 dw2_asm_output_data (1, DW_LNS_advance_line
,
7421 "advance to line %lu", current_line
);
7422 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7423 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7427 /* We still need to start a new row, so output a copy insn. */
7428 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7431 /* Emit debug info for the address of the end of the function. */
7434 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7435 "DW_LNS_fixed_advance_pc");
7436 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
7440 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7441 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7442 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7443 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
7446 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7447 dw2_asm_output_data_uleb128 (1, NULL
);
7448 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7453 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
7455 dw_separate_line_info_ref line_info
7456 = &separate_line_info_table
[lt_index
];
7459 /* Don't emit anything for redundant notes. */
7460 if (line_info
->dw_line_num
== current_line
7461 && line_info
->dw_file_num
== current_file
7462 && line_info
->function
== function
)
7466 /* Emit debug info for the address of the current line. If this is
7467 a new function, or the first line of a function, then we need
7468 to handle it differently. */
7469 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
7471 if (function
!= line_info
->function
)
7473 function
= line_info
->function
;
7475 /* Set the address register to the first line in the function. */
7476 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7477 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7478 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7479 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7483 /* ??? See the DW_LNS_advance_pc comment above. */
7486 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7487 "DW_LNS_fixed_advance_pc");
7488 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7492 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7493 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7494 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7495 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7499 strcpy (prev_line_label
, line_label
);
7501 /* Emit debug info for the source file of the current line, if
7502 different from the previous line. */
7503 if (line_info
->dw_file_num
!= current_file
)
7505 current_file
= line_info
->dw_file_num
;
7506 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7507 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7508 VARRAY_CHAR_PTR (file_table
,
7512 /* Emit debug info for the current line number, choosing the encoding
7513 that uses the least amount of space. */
7514 if (line_info
->dw_line_num
!= current_line
)
7516 line_offset
= line_info
->dw_line_num
- current_line
;
7517 line_delta
= line_offset
- DWARF_LINE_BASE
;
7518 current_line
= line_info
->dw_line_num
;
7519 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7520 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7521 "line %lu", current_line
);
7524 dw2_asm_output_data (1, DW_LNS_advance_line
,
7525 "advance to line %lu", current_line
);
7526 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7527 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7531 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7539 /* If we're done with a function, end its sequence. */
7540 if (lt_index
== separate_line_info_table_in_use
7541 || separate_line_info_table
[lt_index
].function
!= function
)
7546 /* Emit debug info for the address of the end of the function. */
7547 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
7550 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7551 "DW_LNS_fixed_advance_pc");
7552 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7556 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7557 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7558 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7559 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7562 /* Output the marker for the end of this sequence. */
7563 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7564 dw2_asm_output_data_uleb128 (1, NULL
);
7565 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7569 /* Output the marker for the end of the line number info. */
7570 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
7573 /* Given a pointer to a tree node for some base type, return a pointer to
7574 a DIE that describes the given type.
7576 This routine must only be called for GCC type nodes that correspond to
7577 Dwarf base (fundamental) types. */
7580 base_type_die (tree type
)
7582 dw_die_ref base_type_result
;
7583 const char *type_name
;
7584 enum dwarf_type encoding
;
7585 tree name
= TYPE_NAME (type
);
7587 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
7592 if (TREE_CODE (name
) == TYPE_DECL
)
7593 name
= DECL_NAME (name
);
7595 type_name
= IDENTIFIER_POINTER (name
);
7598 type_name
= "__unknown__";
7600 switch (TREE_CODE (type
))
7603 /* Carefully distinguish the C character types, without messing
7604 up if the language is not C. Note that we check only for the names
7605 that contain spaces; other names might occur by coincidence in other
7607 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
7608 && (type
== char_type_node
7609 || ! strcmp (type_name
, "signed char")
7610 || ! strcmp (type_name
, "unsigned char"))))
7612 if (TREE_UNSIGNED (type
))
7613 encoding
= DW_ATE_unsigned
;
7615 encoding
= DW_ATE_signed
;
7618 /* else fall through. */
7621 /* GNU Pascal/Ada CHAR type. Not used in C. */
7622 if (TREE_UNSIGNED (type
))
7623 encoding
= DW_ATE_unsigned_char
;
7625 encoding
= DW_ATE_signed_char
;
7629 encoding
= DW_ATE_float
;
7632 /* Dwarf2 doesn't know anything about complex ints, so use
7633 a user defined type for it. */
7635 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
7636 encoding
= DW_ATE_complex_float
;
7638 encoding
= DW_ATE_lo_user
;
7642 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7643 encoding
= DW_ATE_boolean
;
7647 /* No other TREE_CODEs are Dwarf fundamental types. */
7651 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
7652 if (demangle_name_func
)
7653 type_name
= (*demangle_name_func
) (type_name
);
7655 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
7656 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
7657 int_size_in_bytes (type
));
7658 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
7660 return base_type_result
;
7663 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7664 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7665 a given type is generally the same as the given type, except that if the
7666 given type is a pointer or reference type, then the root type of the given
7667 type is the root type of the "basis" type for the pointer or reference
7668 type. (This definition of the "root" type is recursive.) Also, the root
7669 type of a `const' qualified type or a `volatile' qualified type is the
7670 root type of the given type without the qualifiers. */
7673 root_type (tree type
)
7675 if (TREE_CODE (type
) == ERROR_MARK
)
7676 return error_mark_node
;
7678 switch (TREE_CODE (type
))
7681 return error_mark_node
;
7684 case REFERENCE_TYPE
:
7685 return type_main_variant (root_type (TREE_TYPE (type
)));
7688 return type_main_variant (type
);
7692 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
7693 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7696 is_base_type (tree type
)
7698 switch (TREE_CODE (type
))
7713 case QUAL_UNION_TYPE
:
7718 case REFERENCE_TYPE
:
7732 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7733 node, return the size in bits for the type if it is a constant, or else
7734 return the alignment for the type if the type's size is not constant, or
7735 else return BITS_PER_WORD if the type actually turns out to be an
7738 static inline unsigned HOST_WIDE_INT
7739 simple_type_size_in_bits (tree type
)
7741 if (TREE_CODE (type
) == ERROR_MARK
)
7742 return BITS_PER_WORD
;
7743 else if (TYPE_SIZE (type
) == NULL_TREE
)
7745 else if (host_integerp (TYPE_SIZE (type
), 1))
7746 return tree_low_cst (TYPE_SIZE (type
), 1);
7748 return TYPE_ALIGN (type
);
7751 /* Return true if the debug information for the given type should be
7752 emitted as a subrange type. */
7755 is_ada_subrange_type (tree type
)
7757 /* We do this for INTEGER_TYPEs that have names, parent types, and when
7758 we are compiling Ada code. */
7759 return (TREE_CODE (type
) == INTEGER_TYPE
7760 && TYPE_NAME (type
) != 0 && TREE_TYPE (type
) != 0
7761 && TREE_CODE (TREE_TYPE (type
)) == INTEGER_TYPE
7762 && TREE_UNSIGNED (TREE_TYPE (type
)) && is_ada ());
7765 /* Given a pointer to a tree node for a subrange type, return a pointer
7766 to a DIE that describes the given type. */
7769 subrange_type_die (tree type
)
7771 dw_die_ref subtype_die
;
7772 dw_die_ref subrange_die
;
7773 tree name
= TYPE_NAME (type
);
7775 subtype_die
= base_type_die (TREE_TYPE (type
));
7777 if (TREE_CODE (name
) == TYPE_DECL
)
7778 name
= DECL_NAME (name
);
7780 subrange_die
= new_die (DW_TAG_subrange_type
, comp_unit_die
, type
);
7781 add_name_attribute (subrange_die
, IDENTIFIER_POINTER (name
));
7782 if (TYPE_MIN_VALUE (type
) != NULL
)
7783 add_bound_info (subrange_die
, DW_AT_lower_bound
,
7784 TYPE_MIN_VALUE (type
));
7785 if (TYPE_MAX_VALUE (type
) != NULL
)
7786 add_bound_info (subrange_die
, DW_AT_upper_bound
,
7787 TYPE_MAX_VALUE (type
));
7788 add_AT_die_ref (subrange_die
, DW_AT_type
, subtype_die
);
7790 return subrange_die
;
7793 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7794 entry that chains various modifiers in front of the given type. */
7797 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
7798 dw_die_ref context_die
)
7800 enum tree_code code
= TREE_CODE (type
);
7801 dw_die_ref mod_type_die
= NULL
;
7802 dw_die_ref sub_die
= NULL
;
7803 tree item_type
= NULL
;
7805 if (code
!= ERROR_MARK
)
7807 tree qualified_type
;
7809 /* See if we already have the appropriately qualified variant of
7812 = get_qualified_type (type
,
7813 ((is_const_type
? TYPE_QUAL_CONST
: 0)
7815 ? TYPE_QUAL_VOLATILE
: 0)));
7817 /* If we do, then we can just use its DIE, if it exists. */
7820 mod_type_die
= lookup_type_die (qualified_type
);
7822 return mod_type_die
;
7825 /* Handle C typedef types. */
7826 if (qualified_type
&& TYPE_NAME (qualified_type
)
7827 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
7828 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type
)))
7830 tree type_name
= TYPE_NAME (qualified_type
);
7831 tree dtype
= TREE_TYPE (type_name
);
7833 if (qualified_type
== dtype
)
7835 /* For a named type, use the typedef. */
7836 gen_type_die (qualified_type
, context_die
);
7837 mod_type_die
= lookup_type_die (qualified_type
);
7839 else if (is_const_type
< TYPE_READONLY (dtype
)
7840 || is_volatile_type
< TYPE_VOLATILE (dtype
))
7841 /* cv-unqualified version of named type. Just use the unnamed
7842 type to which it refers. */
7844 = modified_type_die (DECL_ORIGINAL_TYPE (type_name
),
7845 is_const_type
, is_volatile_type
,
7848 /* Else cv-qualified version of named type; fall through. */
7854 else if (is_const_type
)
7856 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
7857 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
7859 else if (is_volatile_type
)
7861 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
7862 sub_die
= modified_type_die (type
, 0, 0, context_die
);
7864 else if (code
== POINTER_TYPE
)
7866 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
7867 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
7868 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
7870 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7872 item_type
= TREE_TYPE (type
);
7874 else if (code
== REFERENCE_TYPE
)
7876 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
7877 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
7878 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
7880 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7882 item_type
= TREE_TYPE (type
);
7884 else if (is_ada_subrange_type (type
))
7885 mod_type_die
= subrange_type_die (type
);
7886 else if (is_base_type (type
))
7887 mod_type_die
= base_type_die (type
);
7890 gen_type_die (type
, context_die
);
7892 /* We have to get the type_main_variant here (and pass that to the
7893 `lookup_type_die' routine) because the ..._TYPE node we have
7894 might simply be a *copy* of some original type node (where the
7895 copy was created to help us keep track of typedef names) and
7896 that copy might have a different TYPE_UID from the original
7898 if (TREE_CODE (type
) != VECTOR_TYPE
)
7899 mod_type_die
= lookup_type_die (type_main_variant (type
));
7901 /* Vectors have the debugging information in the type,
7902 not the main variant. */
7903 mod_type_die
= lookup_type_die (type
);
7904 if (mod_type_die
== NULL
)
7908 /* We want to equate the qualified type to the die below. */
7909 type
= qualified_type
;
7913 equate_type_number_to_die (type
, mod_type_die
);
7915 /* We must do this after the equate_type_number_to_die call, in case
7916 this is a recursive type. This ensures that the modified_type_die
7917 recursion will terminate even if the type is recursive. Recursive
7918 types are possible in Ada. */
7919 sub_die
= modified_type_die (item_type
,
7920 TYPE_READONLY (item_type
),
7921 TYPE_VOLATILE (item_type
),
7924 if (sub_die
!= NULL
)
7925 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
7927 return mod_type_die
;
7930 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7931 an enumerated type. */
7934 type_is_enum (tree type
)
7936 return TREE_CODE (type
) == ENUMERAL_TYPE
;
7939 /* Return the register number described by a given RTL node. */
7942 reg_number (rtx rtl
)
7944 unsigned regno
= REGNO (rtl
);
7946 if (regno
>= FIRST_PSEUDO_REGISTER
)
7949 return DBX_REGISTER_NUMBER (regno
);
7952 /* Return a location descriptor that designates a machine register or
7953 zero if there is none. */
7955 static dw_loc_descr_ref
7956 reg_loc_descriptor (rtx rtl
)
7961 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
7964 reg
= reg_number (rtl
);
7965 regs
= (*targetm
.dwarf_register_span
) (rtl
);
7967 if (HARD_REGNO_NREGS (reg
, GET_MODE (rtl
)) > 1
7969 return multiple_reg_loc_descriptor (rtl
, regs
);
7971 return one_reg_loc_descriptor (reg
);
7974 /* Return a location descriptor that designates a machine register for
7975 a given hard register number. */
7977 static dw_loc_descr_ref
7978 one_reg_loc_descriptor (unsigned int regno
)
7981 return new_loc_descr (DW_OP_reg0
+ regno
, 0, 0);
7983 return new_loc_descr (DW_OP_regx
, regno
, 0);
7986 /* Given an RTL of a register, return a location descriptor that
7987 designates a value that spans more than one register. */
7989 static dw_loc_descr_ref
7990 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
)
7994 dw_loc_descr_ref loc_result
= NULL
;
7996 reg
= reg_number (rtl
);
7997 nregs
= HARD_REGNO_NREGS (reg
, GET_MODE (rtl
));
7999 /* Simple, contiguous registers. */
8000 if (regs
== NULL_RTX
)
8002 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
8009 t
= one_reg_loc_descriptor (reg
);
8010 add_loc_descr (&loc_result
, t
);
8011 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_piece
, size
, 0));
8017 /* Now onto stupid register sets in non contiguous locations. */
8019 if (GET_CODE (regs
) != PARALLEL
)
8022 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8025 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
8029 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)));
8030 add_loc_descr (&loc_result
, t
);
8031 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8032 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_piece
, size
, 0));
8037 /* Return a location descriptor that designates a constant. */
8039 static dw_loc_descr_ref
8040 int_loc_descriptor (HOST_WIDE_INT i
)
8042 enum dwarf_location_atom op
;
8044 /* Pick the smallest representation of a constant, rather than just
8045 defaulting to the LEB encoding. */
8049 op
= DW_OP_lit0
+ i
;
8052 else if (i
<= 0xffff)
8054 else if (HOST_BITS_PER_WIDE_INT
== 32
8064 else if (i
>= -0x8000)
8066 else if (HOST_BITS_PER_WIDE_INT
== 32
8067 || i
>= -0x80000000)
8073 return new_loc_descr (op
, i
, 0);
8076 /* Return a location descriptor that designates a base+offset location. */
8078 static dw_loc_descr_ref
8079 based_loc_descr (unsigned int reg
, long int offset
)
8081 dw_loc_descr_ref loc_result
;
8082 /* For the "frame base", we use the frame pointer or stack pointer
8083 registers, since the RTL for local variables is relative to one of
8085 unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
8086 ? HARD_FRAME_POINTER_REGNUM
8087 : STACK_POINTER_REGNUM
);
8090 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
8092 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
8094 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
8099 /* Return true if this RTL expression describes a base+offset calculation. */
8102 is_based_loc (rtx rtl
)
8104 return (GET_CODE (rtl
) == PLUS
8105 && ((GET_CODE (XEXP (rtl
, 0)) == REG
8106 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
8107 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
8110 /* The following routine converts the RTL for a variable or parameter
8111 (resident in memory) into an equivalent Dwarf representation of a
8112 mechanism for getting the address of that same variable onto the top of a
8113 hypothetical "address evaluation" stack.
8115 When creating memory location descriptors, we are effectively transforming
8116 the RTL for a memory-resident object into its Dwarf postfix expression
8117 equivalent. This routine recursively descends an RTL tree, turning
8118 it into Dwarf postfix code as it goes.
8120 MODE is the mode of the memory reference, needed to handle some
8121 autoincrement addressing modes.
8123 Return 0 if we can't represent the location. */
8125 static dw_loc_descr_ref
8126 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
)
8128 dw_loc_descr_ref mem_loc_result
= NULL
;
8130 /* Note that for a dynamically sized array, the location we will generate a
8131 description of here will be the lowest numbered location which is
8132 actually within the array. That's *not* necessarily the same as the
8133 zeroth element of the array. */
8135 rtl
= (*targetm
.delegitimize_address
) (rtl
);
8137 switch (GET_CODE (rtl
))
8142 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8143 just fall into the SUBREG code. */
8145 /* ... fall through ... */
8148 /* The case of a subreg may arise when we have a local (register)
8149 variable or a formal (register) parameter which doesn't quite fill
8150 up an entire register. For now, just assume that it is
8151 legitimate to make the Dwarf info refer to the whole register which
8152 contains the given subreg. */
8153 rtl
= SUBREG_REG (rtl
);
8155 /* ... fall through ... */
8158 /* Whenever a register number forms a part of the description of the
8159 method for calculating the (dynamic) address of a memory resident
8160 object, DWARF rules require the register number be referred to as
8161 a "base register". This distinction is not based in any way upon
8162 what category of register the hardware believes the given register
8163 belongs to. This is strictly DWARF terminology we're dealing with
8164 here. Note that in cases where the location of a memory-resident
8165 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8166 OP_CONST (0)) the actual DWARF location descriptor that we generate
8167 may just be OP_BASEREG (basereg). This may look deceptively like
8168 the object in question was allocated to a register (rather than in
8169 memory) so DWARF consumers need to be aware of the subtle
8170 distinction between OP_REG and OP_BASEREG. */
8171 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
8172 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
8176 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
8177 if (mem_loc_result
!= 0)
8178 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
8182 rtl
= XEXP (rtl
, 1);
8184 /* ... fall through ... */
8187 /* Some ports can transform a symbol ref into a label ref, because
8188 the symbol ref is too far away and has to be dumped into a constant
8192 /* Alternatively, the symbol in the constant pool might be referenced
8193 by a different symbol. */
8194 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
8197 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
8199 if (GET_CODE (tmp
) == SYMBOL_REF
)
8202 if (CONSTANT_POOL_ADDRESS_P (tmp
))
8203 get_pool_constant_mark (tmp
, &marked
);
8208 /* If all references to this pool constant were optimized away,
8209 it was not output and thus we can't represent it.
8210 FIXME: might try to use DW_OP_const_value here, though
8211 DW_OP_piece complicates it. */
8216 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
8217 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8218 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8219 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
8223 /* Extract the PLUS expression nested inside and fall into
8225 rtl
= XEXP (rtl
, 1);
8230 /* Turn these into a PLUS expression and fall into the PLUS code
8232 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
8233 GEN_INT (GET_CODE (rtl
) == PRE_INC
8234 ? GET_MODE_UNIT_SIZE (mode
)
8235 : -GET_MODE_UNIT_SIZE (mode
)));
8237 /* ... fall through ... */
8241 if (is_based_loc (rtl
))
8242 mem_loc_result
= based_loc_descr (reg_number (XEXP (rtl
, 0)),
8243 INTVAL (XEXP (rtl
, 1)));
8246 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
8247 if (mem_loc_result
== 0)
8250 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
8251 && INTVAL (XEXP (rtl
, 1)) >= 0)
8252 add_loc_descr (&mem_loc_result
,
8253 new_loc_descr (DW_OP_plus_uconst
,
8254 INTVAL (XEXP (rtl
, 1)), 0));
8257 add_loc_descr (&mem_loc_result
,
8258 mem_loc_descriptor (XEXP (rtl
, 1), mode
));
8259 add_loc_descr (&mem_loc_result
,
8260 new_loc_descr (DW_OP_plus
, 0, 0));
8267 /* If a pseudo-reg is optimized away, it is possible for it to
8268 be replaced with a MEM containing a multiply. */
8269 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
8270 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
);
8272 if (op0
== 0 || op1
== 0)
8275 mem_loc_result
= op0
;
8276 add_loc_descr (&mem_loc_result
, op1
);
8277 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
8282 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
8286 /* If this is a MEM, return its address. Otherwise, we can't
8288 if (GET_CODE (XEXP (rtl
, 0)) == MEM
)
8289 return mem_loc_descriptor (XEXP (XEXP (rtl
, 0), 0), mode
);
8297 return mem_loc_result
;
8300 /* Return a descriptor that describes the concatenation of two locations.
8301 This is typically a complex variable. */
8303 static dw_loc_descr_ref
8304 concat_loc_descriptor (rtx x0
, rtx x1
)
8306 dw_loc_descr_ref cc_loc_result
= NULL
;
8307 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
);
8308 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
);
8310 if (x0_ref
== 0 || x1_ref
== 0)
8313 cc_loc_result
= x0_ref
;
8314 add_loc_descr (&cc_loc_result
,
8315 new_loc_descr (DW_OP_piece
,
8316 GET_MODE_SIZE (GET_MODE (x0
)), 0));
8318 add_loc_descr (&cc_loc_result
, x1_ref
);
8319 add_loc_descr (&cc_loc_result
,
8320 new_loc_descr (DW_OP_piece
,
8321 GET_MODE_SIZE (GET_MODE (x1
)), 0));
8323 return cc_loc_result
;
8326 /* Output a proper Dwarf location descriptor for a variable or parameter
8327 which is either allocated in a register or in a memory location. For a
8328 register, we just generate an OP_REG and the register number. For a
8329 memory location we provide a Dwarf postfix expression describing how to
8330 generate the (dynamic) address of the object onto the address stack.
8332 If we don't know how to describe it, return 0. */
8334 static dw_loc_descr_ref
8335 loc_descriptor (rtx rtl
)
8337 dw_loc_descr_ref loc_result
= NULL
;
8339 switch (GET_CODE (rtl
))
8342 /* The case of a subreg may arise when we have a local (register)
8343 variable or a formal (register) parameter which doesn't quite fill
8344 up an entire register. For now, just assume that it is
8345 legitimate to make the Dwarf info refer to the whole register which
8346 contains the given subreg. */
8347 rtl
= SUBREG_REG (rtl
);
8349 /* ... fall through ... */
8352 loc_result
= reg_loc_descriptor (rtl
);
8356 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
8360 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
8370 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8371 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8372 looking for an address. Otherwise, we return a value. If we can't make a
8373 descriptor, return 0. */
8375 static dw_loc_descr_ref
8376 loc_descriptor_from_tree (tree loc
, int addressp
)
8378 dw_loc_descr_ref ret
, ret1
;
8380 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (loc
));
8381 enum dwarf_location_atom op
;
8383 /* ??? Most of the time we do not take proper care for sign/zero
8384 extending the values properly. Hopefully this won't be a real
8387 switch (TREE_CODE (loc
))
8392 case WITH_RECORD_EXPR
:
8393 case PLACEHOLDER_EXPR
:
8394 /* This case involves extracting fields from an object to determine the
8395 position of other fields. We don't try to encode this here. The
8396 only user of this is Ada, which encodes the needed information using
8397 the names of types. */
8404 /* We can support this only if we can look through conversions and
8405 find an INDIRECT_EXPR. */
8406 for (loc
= TREE_OPERAND (loc
, 0);
8407 TREE_CODE (loc
) == CONVERT_EXPR
|| TREE_CODE (loc
) == NOP_EXPR
8408 || TREE_CODE (loc
) == NON_LVALUE_EXPR
8409 || TREE_CODE (loc
) == VIEW_CONVERT_EXPR
8410 || TREE_CODE (loc
) == SAVE_EXPR
;
8411 loc
= TREE_OPERAND (loc
, 0))
8414 return (TREE_CODE (loc
) == INDIRECT_REF
8415 ? loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
)
8419 if (DECL_THREAD_LOCAL (loc
))
8423 #ifndef ASM_OUTPUT_DWARF_DTPREL
8424 /* If this is not defined, we have no way to emit the data. */
8428 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8429 look up addresses of objects in the current module. */
8430 if (DECL_EXTERNAL (loc
))
8433 rtl
= rtl_for_decl_location (loc
);
8434 if (rtl
== NULL_RTX
)
8437 if (GET_CODE (rtl
) != MEM
)
8439 rtl
= XEXP (rtl
, 0);
8440 if (! CONSTANT_P (rtl
))
8443 ret
= new_loc_descr (INTERNAL_DW_OP_tls_addr
, 0, 0);
8444 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8445 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8447 ret1
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
8448 add_loc_descr (&ret
, ret1
);
8457 rtx rtl
= rtl_for_decl_location (loc
);
8459 if (rtl
== NULL_RTX
)
8461 else if (CONSTANT_P (rtl
))
8463 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
8464 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8465 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8470 enum machine_mode mode
= GET_MODE (rtl
);
8472 if (GET_CODE (rtl
) == MEM
)
8475 rtl
= XEXP (rtl
, 0);
8478 ret
= mem_loc_descriptor (rtl
, mode
);
8484 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8489 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), addressp
);
8493 case NON_LVALUE_EXPR
:
8494 case VIEW_CONVERT_EXPR
:
8497 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
);
8502 case ARRAY_RANGE_REF
:
8505 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
8506 enum machine_mode mode
;
8509 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
8510 &unsignedp
, &volatilep
);
8515 ret
= loc_descriptor_from_tree (obj
, 1);
8517 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
8520 if (offset
!= NULL_TREE
)
8522 /* Variable offset. */
8523 add_loc_descr (&ret
, loc_descriptor_from_tree (offset
, 0));
8524 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8530 bytepos
= bitpos
/ BITS_PER_UNIT
;
8532 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
8533 else if (bytepos
< 0)
8535 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
8536 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8542 if (host_integerp (loc
, 0))
8543 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
8548 case TRUTH_AND_EXPR
:
8549 case TRUTH_ANDIF_EXPR
:
8554 case TRUTH_XOR_EXPR
:
8560 case TRUTH_ORIF_EXPR
:
8565 case FLOOR_DIV_EXPR
:
8567 case ROUND_DIV_EXPR
:
8568 case TRUNC_DIV_EXPR
:
8576 case FLOOR_MOD_EXPR
:
8578 case ROUND_MOD_EXPR
:
8579 case TRUNC_MOD_EXPR
:
8592 op
= (unsignedp
? DW_OP_shr
: DW_OP_shra
);
8596 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
8597 && host_integerp (TREE_OPERAND (loc
, 1), 0))
8599 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8603 add_loc_descr (&ret
,
8604 new_loc_descr (DW_OP_plus_uconst
,
8605 tree_low_cst (TREE_OPERAND (loc
, 1),
8615 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8622 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8629 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8636 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8651 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8652 ret1
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8653 if (ret
== 0 || ret1
== 0)
8656 add_loc_descr (&ret
, ret1
);
8657 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8660 case TRUTH_NOT_EXPR
:
8674 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8678 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8682 loc
= build (COND_EXPR
, TREE_TYPE (loc
),
8683 build (LT_EXPR
, integer_type_node
,
8684 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
8685 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
8687 /* ... fall through ... */
8691 dw_loc_descr_ref lhs
8692 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8693 dw_loc_descr_ref rhs
8694 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 2), 0);
8695 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
8697 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8698 if (ret
== 0 || lhs
== 0 || rhs
== 0)
8701 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
8702 add_loc_descr (&ret
, bra_node
);
8704 add_loc_descr (&ret
, rhs
);
8705 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
8706 add_loc_descr (&ret
, jump_node
);
8708 add_loc_descr (&ret
, lhs
);
8709 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8710 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
8712 /* ??? Need a node to point the skip at. Use a nop. */
8713 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
8714 add_loc_descr (&ret
, tmp
);
8715 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8716 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
8721 /* Leave front-end specific codes as simply unknown. This comes
8722 up, for instance, with the C STMT_EXPR. */
8723 if ((unsigned int) TREE_CODE (loc
)
8724 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
8727 /* Otherwise this is a generic code; we should just lists all of
8728 these explicitly. Aborting means we forgot one. */
8732 /* Show if we can't fill the request for an address. */
8733 if (addressp
&& indirect_p
== 0)
8736 /* If we've got an address and don't want one, dereference. */
8737 if (!addressp
&& indirect_p
> 0)
8739 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
8741 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
8743 else if (size
== DWARF2_ADDR_SIZE
)
8746 op
= DW_OP_deref_size
;
8748 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
8754 /* Given a value, round it up to the lowest multiple of `boundary'
8755 which is not less than the value itself. */
8757 static inline HOST_WIDE_INT
8758 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
8760 return (((value
+ boundary
- 1) / boundary
) * boundary
);
8763 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8764 pointer to the declared type for the relevant field variable, or return
8765 `integer_type_node' if the given node turns out to be an
8769 field_type (tree decl
)
8773 if (TREE_CODE (decl
) == ERROR_MARK
)
8774 return integer_type_node
;
8776 type
= DECL_BIT_FIELD_TYPE (decl
);
8777 if (type
== NULL_TREE
)
8778 type
= TREE_TYPE (decl
);
8783 /* Given a pointer to a tree node, return the alignment in bits for
8784 it, or else return BITS_PER_WORD if the node actually turns out to
8785 be an ERROR_MARK node. */
8787 static inline unsigned
8788 simple_type_align_in_bits (tree type
)
8790 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
8793 static inline unsigned
8794 simple_decl_align_in_bits (tree decl
)
8796 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
8799 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8800 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8801 or return 0 if we are unable to determine what that offset is, either
8802 because the argument turns out to be a pointer to an ERROR_MARK node, or
8803 because the offset is actually variable. (We can't handle the latter case
8806 static HOST_WIDE_INT
8807 field_byte_offset (tree decl
)
8809 unsigned int type_align_in_bits
;
8810 unsigned int decl_align_in_bits
;
8811 unsigned HOST_WIDE_INT type_size_in_bits
;
8812 HOST_WIDE_INT object_offset_in_bits
;
8814 tree field_size_tree
;
8815 HOST_WIDE_INT bitpos_int
;
8816 HOST_WIDE_INT deepest_bitpos
;
8817 unsigned HOST_WIDE_INT field_size_in_bits
;
8819 if (TREE_CODE (decl
) == ERROR_MARK
)
8821 else if (TREE_CODE (decl
) != FIELD_DECL
)
8824 type
= field_type (decl
);
8825 field_size_tree
= DECL_SIZE (decl
);
8827 /* The size could be unspecified if there was an error, or for
8828 a flexible array member. */
8829 if (! field_size_tree
)
8830 field_size_tree
= bitsize_zero_node
;
8832 /* We cannot yet cope with fields whose positions are variable, so
8833 for now, when we see such things, we simply return 0. Someday, we may
8834 be able to handle such cases, but it will be damn difficult. */
8835 if (! host_integerp (bit_position (decl
), 0))
8838 bitpos_int
= int_bit_position (decl
);
8840 /* If we don't know the size of the field, pretend it's a full word. */
8841 if (host_integerp (field_size_tree
, 1))
8842 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
8844 field_size_in_bits
= BITS_PER_WORD
;
8846 type_size_in_bits
= simple_type_size_in_bits (type
);
8847 type_align_in_bits
= simple_type_align_in_bits (type
);
8848 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
8850 /* The GCC front-end doesn't make any attempt to keep track of the starting
8851 bit offset (relative to the start of the containing structure type) of the
8852 hypothetical "containing object" for a bit-field. Thus, when computing
8853 the byte offset value for the start of the "containing object" of a
8854 bit-field, we must deduce this information on our own. This can be rather
8855 tricky to do in some cases. For example, handling the following structure
8856 type definition when compiling for an i386/i486 target (which only aligns
8857 long long's to 32-bit boundaries) can be very tricky:
8859 struct S { int field1; long long field2:31; };
8861 Fortunately, there is a simple rule-of-thumb which can be used in such
8862 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8863 structure shown above. It decides to do this based upon one simple rule
8864 for bit-field allocation. GCC allocates each "containing object" for each
8865 bit-field at the first (i.e. lowest addressed) legitimate alignment
8866 boundary (based upon the required minimum alignment for the declared type
8867 of the field) which it can possibly use, subject to the condition that
8868 there is still enough available space remaining in the containing object
8869 (when allocated at the selected point) to fully accommodate all of the
8870 bits of the bit-field itself.
8872 This simple rule makes it obvious why GCC allocates 8 bytes for each
8873 object of the structure type shown above. When looking for a place to
8874 allocate the "containing object" for `field2', the compiler simply tries
8875 to allocate a 64-bit "containing object" at each successive 32-bit
8876 boundary (starting at zero) until it finds a place to allocate that 64-
8877 bit field such that at least 31 contiguous (and previously unallocated)
8878 bits remain within that selected 64 bit field. (As it turns out, for the
8879 example above, the compiler finds it is OK to allocate the "containing
8880 object" 64-bit field at bit-offset zero within the structure type.)
8882 Here we attempt to work backwards from the limited set of facts we're
8883 given, and we try to deduce from those facts, where GCC must have believed
8884 that the containing object started (within the structure type). The value
8885 we deduce is then used (by the callers of this routine) to generate
8886 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8887 and, in the case of DW_AT_location, regular fields as well). */
8889 /* Figure out the bit-distance from the start of the structure to the
8890 "deepest" bit of the bit-field. */
8891 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
8893 /* This is the tricky part. Use some fancy footwork to deduce where the
8894 lowest addressed bit of the containing object must be. */
8895 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8897 /* Round up to type_align by default. This works best for bitfields. */
8898 object_offset_in_bits
+= type_align_in_bits
- 1;
8899 object_offset_in_bits
/= type_align_in_bits
;
8900 object_offset_in_bits
*= type_align_in_bits
;
8902 if (object_offset_in_bits
> bitpos_int
)
8904 /* Sigh, the decl must be packed. */
8905 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8907 /* Round up to decl_align instead. */
8908 object_offset_in_bits
+= decl_align_in_bits
- 1;
8909 object_offset_in_bits
/= decl_align_in_bits
;
8910 object_offset_in_bits
*= decl_align_in_bits
;
8913 return object_offset_in_bits
/ BITS_PER_UNIT
;
8916 /* The following routines define various Dwarf attributes and any data
8917 associated with them. */
8919 /* Add a location description attribute value to a DIE.
8921 This emits location attributes suitable for whole variables and
8922 whole parameters. Note that the location attributes for struct fields are
8923 generated by the routine `data_member_location_attribute' below. */
8926 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
8927 dw_loc_descr_ref descr
)
8930 add_AT_loc (die
, attr_kind
, descr
);
8933 /* Attach the specialized form of location attribute used for data members of
8934 struct and union types. In the special case of a FIELD_DECL node which
8935 represents a bit-field, the "offset" part of this special location
8936 descriptor must indicate the distance in bytes from the lowest-addressed
8937 byte of the containing struct or union type to the lowest-addressed byte of
8938 the "containing object" for the bit-field. (See the `field_byte_offset'
8941 For any given bit-field, the "containing object" is a hypothetical object
8942 (of some integral or enum type) within which the given bit-field lives. The
8943 type of this hypothetical "containing object" is always the same as the
8944 declared type of the individual bit-field itself (for GCC anyway... the
8945 DWARF spec doesn't actually mandate this). Note that it is the size (in
8946 bytes) of the hypothetical "containing object" which will be given in the
8947 DW_AT_byte_size attribute for this bit-field. (See the
8948 `byte_size_attribute' function below.) It is also used when calculating the
8949 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8953 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
8956 dw_loc_descr_ref loc_descr
= 0;
8958 if (TREE_CODE (decl
) == TREE_VEC
)
8960 /* We're working on the TAG_inheritance for a base class. */
8961 if (TREE_VIA_VIRTUAL (decl
) && is_cxx ())
8963 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8964 aren't at a fixed offset from all (sub)objects of the same
8965 type. We need to extract the appropriate offset from our
8966 vtable. The following dwarf expression means
8968 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8970 This is specific to the V3 ABI, of course. */
8972 dw_loc_descr_ref tmp
;
8974 /* Make a copy of the object address. */
8975 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
8976 add_loc_descr (&loc_descr
, tmp
);
8978 /* Extract the vtable address. */
8979 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
8980 add_loc_descr (&loc_descr
, tmp
);
8982 /* Calculate the address of the offset. */
8983 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
8987 tmp
= int_loc_descriptor (-offset
);
8988 add_loc_descr (&loc_descr
, tmp
);
8989 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
8990 add_loc_descr (&loc_descr
, tmp
);
8992 /* Extract the offset. */
8993 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
8994 add_loc_descr (&loc_descr
, tmp
);
8996 /* Add it to the object address. */
8997 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
8998 add_loc_descr (&loc_descr
, tmp
);
9001 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
9004 offset
= field_byte_offset (decl
);
9008 enum dwarf_location_atom op
;
9010 /* The DWARF2 standard says that we should assume that the structure
9011 address is already on the stack, so we can specify a structure field
9012 address by using DW_OP_plus_uconst. */
9014 #ifdef MIPS_DEBUGGING_INFO
9015 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9016 operator correctly. It works only if we leave the offset on the
9020 op
= DW_OP_plus_uconst
;
9023 loc_descr
= new_loc_descr (op
, offset
, 0);
9026 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
9029 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9030 does not have a "location" either in memory or in a register. These
9031 things can arise in GNU C when a constant is passed as an actual parameter
9032 to an inlined function. They can also arise in C++ where declared
9033 constants do not necessarily get memory "homes". */
9036 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
9038 switch (GET_CODE (rtl
))
9041 /* Note that a CONST_INT rtx could represent either an integer
9042 or a floating-point constant. A CONST_INT is used whenever
9043 the constant will fit into a single word. In all such
9044 cases, the original mode of the constant value is wiped
9045 out, and the CONST_INT rtx is assigned VOIDmode. */
9047 HOST_WIDE_INT val
= INTVAL (rtl
);
9049 /* ??? We really should be using HOST_WIDE_INT throughout. */
9050 if (val
< 0 && (long) val
== val
)
9051 add_AT_int (die
, DW_AT_const_value
, (long) val
);
9052 else if ((unsigned long) val
== (unsigned HOST_WIDE_INT
) val
)
9053 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned long) val
);
9056 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
9057 add_AT_long_long (die
, DW_AT_const_value
,
9058 val
>> HOST_BITS_PER_LONG
, val
);
9067 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9068 floating-point constant. A CONST_DOUBLE is used whenever the
9069 constant requires more than one word in order to be adequately
9070 represented. We output CONST_DOUBLEs as blocks. */
9072 enum machine_mode mode
= GET_MODE (rtl
);
9074 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
9076 unsigned length
= GET_MODE_SIZE (mode
) / 4;
9077 long *array
= (long *) ggc_alloc (sizeof (long) * length
);
9080 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
9084 REAL_VALUE_TO_TARGET_SINGLE (rv
, array
[0]);
9088 REAL_VALUE_TO_TARGET_DOUBLE (rv
, array
);
9093 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv
, array
);
9100 add_AT_float (die
, DW_AT_const_value
, length
, array
);
9104 /* ??? We really should be using HOST_WIDE_INT throughout. */
9105 if (HOST_BITS_PER_LONG
!= HOST_BITS_PER_WIDE_INT
)
9108 add_AT_long_long (die
, DW_AT_const_value
,
9109 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
9115 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
9121 add_AT_addr (die
, DW_AT_const_value
, rtl
);
9122 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
9126 /* In cases where an inlined instance of an inline function is passed
9127 the address of an `auto' variable (which is local to the caller) we
9128 can get a situation where the DECL_RTL of the artificial local
9129 variable (for the inlining) which acts as a stand-in for the
9130 corresponding formal parameter (of the inline function) will look
9131 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9132 exactly a compile-time constant expression, but it isn't the address
9133 of the (artificial) local variable either. Rather, it represents the
9134 *value* which the artificial local variable always has during its
9135 lifetime. We currently have no way to represent such quasi-constant
9136 values in Dwarf, so for now we just punt and generate nothing. */
9140 /* No other kinds of rtx should be possible here. */
9147 rtl_for_decl_location (tree decl
)
9151 /* Here we have to decide where we are going to say the parameter "lives"
9152 (as far as the debugger is concerned). We only have a couple of
9153 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
9155 DECL_RTL normally indicates where the parameter lives during most of the
9156 activation of the function. If optimization is enabled however, this
9157 could be either NULL or else a pseudo-reg. Both of those cases indicate
9158 that the parameter doesn't really live anywhere (as far as the code
9159 generation parts of GCC are concerned) during most of the function's
9160 activation. That will happen (for example) if the parameter is never
9161 referenced within the function.
9163 We could just generate a location descriptor here for all non-NULL
9164 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
9165 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
9166 where DECL_RTL is NULL or is a pseudo-reg.
9168 Note however that we can only get away with using DECL_INCOMING_RTL as
9169 a backup substitute for DECL_RTL in certain limited cases. In cases
9170 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
9171 we can be sure that the parameter was passed using the same type as it is
9172 declared to have within the function, and that its DECL_INCOMING_RTL
9173 points us to a place where a value of that type is passed.
9175 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
9176 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
9177 because in these cases DECL_INCOMING_RTL points us to a value of some
9178 type which is *different* from the type of the parameter itself. Thus,
9179 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
9180 such cases, the debugger would end up (for example) trying to fetch a
9181 `float' from a place which actually contains the first part of a
9182 `double'. That would lead to really incorrect and confusing
9183 output at debug-time.
9185 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
9186 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
9187 are a couple of exceptions however. On little-endian machines we can
9188 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
9189 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
9190 an integral type that is smaller than TREE_TYPE (decl). These cases arise
9191 when (on a little-endian machine) a non-prototyped function has a
9192 parameter declared to be of type `short' or `char'. In such cases,
9193 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
9194 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
9195 passed `int' value. If the debugger then uses that address to fetch
9196 a `short' or a `char' (on a little-endian machine) the result will be
9197 the correct data, so we allow for such exceptional cases below.
9199 Note that our goal here is to describe the place where the given formal
9200 parameter lives during most of the function's activation (i.e. between the
9201 end of the prologue and the start of the epilogue). We'll do that as best
9202 as we can. Note however that if the given formal parameter is modified
9203 sometime during the execution of the function, then a stack backtrace (at
9204 debug-time) will show the function as having been called with the *new*
9205 value rather than the value which was originally passed in. This happens
9206 rarely enough that it is not a major problem, but it *is* a problem, and
9209 A future version of dwarf2out.c may generate two additional attributes for
9210 any given DW_TAG_formal_parameter DIE which will describe the "passed
9211 type" and the "passed location" for the given formal parameter in addition
9212 to the attributes we now generate to indicate the "declared type" and the
9213 "active location" for each parameter. This additional set of attributes
9214 could be used by debuggers for stack backtraces. Separately, note that
9215 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
9216 This happens (for example) for inlined-instances of inline function formal
9217 parameters which are never referenced. This really shouldn't be
9218 happening. All PARM_DECL nodes should get valid non-NULL
9219 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
9220 values for inlined instances of inline function parameters, so when we see
9221 such cases, we are just out-of-luck for the time being (until integrate.c
9224 /* Use DECL_RTL as the "location" unless we find something better. */
9225 rtl
= DECL_RTL_IF_SET (decl
);
9227 /* When generating abstract instances, ignore everything except
9228 constants, symbols living in memory, and symbols living in
9230 if (! reload_completed
)
9233 && (CONSTANT_P (rtl
)
9234 || (GET_CODE (rtl
) == MEM
9235 && CONSTANT_P (XEXP (rtl
, 0)))
9236 || (GET_CODE (rtl
) == REG
9237 && TREE_CODE (decl
) == VAR_DECL
9238 && TREE_STATIC (decl
))))
9240 rtl
= (*targetm
.delegitimize_address
) (rtl
);
9245 else if (TREE_CODE (decl
) == PARM_DECL
)
9247 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
9249 tree declared_type
= type_main_variant (TREE_TYPE (decl
));
9250 tree passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
9252 /* This decl represents a formal parameter which was optimized out.
9253 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
9254 all cases where (rtl == NULL_RTX) just below. */
9255 if (declared_type
== passed_type
)
9256 rtl
= DECL_INCOMING_RTL (decl
);
9257 else if (! BYTES_BIG_ENDIAN
9258 && TREE_CODE (declared_type
) == INTEGER_TYPE
9259 && (GET_MODE_SIZE (TYPE_MODE (declared_type
))
9260 <= GET_MODE_SIZE (TYPE_MODE (passed_type
))))
9261 rtl
= DECL_INCOMING_RTL (decl
);
9264 /* If the parm was passed in registers, but lives on the stack, then
9265 make a big endian correction if the mode of the type of the
9266 parameter is not the same as the mode of the rtl. */
9267 /* ??? This is the same series of checks that are made in dbxout.c before
9268 we reach the big endian correction code there. It isn't clear if all
9269 of these checks are necessary here, but keeping them all is the safe
9271 else if (GET_CODE (rtl
) == MEM
9272 && XEXP (rtl
, 0) != const0_rtx
9273 && ! CONSTANT_P (XEXP (rtl
, 0))
9274 /* Not passed in memory. */
9275 && GET_CODE (DECL_INCOMING_RTL (decl
)) != MEM
9276 /* Not passed by invisible reference. */
9277 && (GET_CODE (XEXP (rtl
, 0)) != REG
9278 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
9279 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
9280 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
9281 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
9284 /* Big endian correction check. */
9286 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
9287 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
9290 int offset
= (UNITS_PER_WORD
9291 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
9293 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
9294 plus_constant (XEXP (rtl
, 0), offset
));
9298 if (rtl
!= NULL_RTX
)
9300 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
9301 #ifdef LEAF_REG_REMAP
9302 if (current_function_uses_only_leaf_regs
)
9303 leaf_renumber_regs_insn (rtl
);
9307 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
9308 and will have been substituted directly into all expressions that use it.
9309 C does not have such a concept, but C++ and other languages do. */
9310 else if (TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
9312 /* If a variable is initialized with a string constant without embedded
9313 zeros, build CONST_STRING. */
9314 if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
9315 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
9317 tree arrtype
= TREE_TYPE (decl
);
9318 tree enttype
= TREE_TYPE (arrtype
);
9319 tree domain
= TYPE_DOMAIN (arrtype
);
9320 tree init
= DECL_INITIAL (decl
);
9321 enum machine_mode mode
= TYPE_MODE (enttype
);
9323 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
9325 && integer_zerop (TYPE_MIN_VALUE (domain
))
9326 && compare_tree_int (TYPE_MAX_VALUE (domain
),
9327 TREE_STRING_LENGTH (init
) - 1) == 0
9328 && ((size_t) TREE_STRING_LENGTH (init
)
9329 == strlen (TREE_STRING_POINTER (init
)) + 1))
9330 rtl
= gen_rtx_CONST_STRING (VOIDmode
, TREE_STRING_POINTER (init
));
9332 /* If the initializer is something that we know will expand into an
9333 immediate RTL constant, expand it now. Expanding anything else
9334 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
9335 else if (TREE_CODE (DECL_INITIAL (decl
)) == INTEGER_CST
9336 || TREE_CODE (DECL_INITIAL (decl
)) == REAL_CST
)
9338 rtl
= expand_expr (DECL_INITIAL (decl
), NULL_RTX
, VOIDmode
,
9339 EXPAND_INITIALIZER
);
9340 /* If expand_expr returns a MEM, it wasn't immediate. */
9341 if (rtl
&& GET_CODE (rtl
) == MEM
)
9347 rtl
= (*targetm
.delegitimize_address
) (rtl
);
9349 /* If we don't look past the constant pool, we risk emitting a
9350 reference to a constant pool entry that isn't referenced from
9351 code, and thus is not emitted. */
9353 rtl
= avoid_constant_pool_reference (rtl
);
9358 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
9359 data attribute for a variable or a parameter. We generate the
9360 DW_AT_const_value attribute only in those cases where the given variable
9361 or parameter does not have a true "location" either in memory or in a
9362 register. This can happen (for example) when a constant is passed as an
9363 actual argument in a call to an inline function. (It's possible that
9364 these things can crop up in other ways also.) Note that one type of
9365 constant value which can be passed into an inlined function is a constant
9366 pointer. This can happen for example if an actual argument in an inlined
9367 function call evaluates to a compile-time constant address. */
9370 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
)
9373 dw_loc_descr_ref descr
;
9375 if (TREE_CODE (decl
) == ERROR_MARK
)
9377 else if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
)
9380 rtl
= rtl_for_decl_location (decl
);
9381 if (rtl
== NULL_RTX
)
9384 switch (GET_CODE (rtl
))
9387 /* The address of a variable that was optimized away;
9388 don't emit anything. */
9398 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
9399 add_const_value_attribute (die
, rtl
);
9403 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL (decl
))
9405 /* Need loc_descriptor_from_tree since that's where we know
9406 how to handle TLS variables. Want the object's address
9407 since the top-level DW_AT_location assumes such. See
9408 the confusion in loc_descriptor for reference. */
9409 descr
= loc_descriptor_from_tree (decl
, 1);
9416 descr
= loc_descriptor (rtl
);
9418 add_AT_location_description (die
, DW_AT_location
, descr
);
9426 /* If we don't have a copy of this variable in memory for some reason (such
9427 as a C++ member constant that doesn't have an out-of-line definition),
9428 we should tell the debugger about the constant value. */
9431 tree_add_const_value_attribute (dw_die_ref var_die
, tree decl
)
9433 tree init
= DECL_INITIAL (decl
);
9434 tree type
= TREE_TYPE (decl
);
9436 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
9437 && initializer_constant_valid_p (init
, type
) == null_pointer_node
)
9442 switch (TREE_CODE (type
))
9445 if (host_integerp (init
, 0))
9446 add_AT_unsigned (var_die
, DW_AT_const_value
,
9447 tree_low_cst (init
, 0));
9449 add_AT_long_long (var_die
, DW_AT_const_value
,
9450 TREE_INT_CST_HIGH (init
),
9451 TREE_INT_CST_LOW (init
));
9458 /* Generate a DW_AT_name attribute given some string value to be included as
9459 the value of the attribute. */
9462 add_name_attribute (dw_die_ref die
, const char *name_string
)
9464 if (name_string
!= NULL
&& *name_string
!= 0)
9466 if (demangle_name_func
)
9467 name_string
= (*demangle_name_func
) (name_string
);
9469 add_AT_string (die
, DW_AT_name
, name_string
);
9473 /* Generate a DW_AT_comp_dir attribute for DIE. */
9476 add_comp_dir_attribute (dw_die_ref die
)
9478 const char *wd
= getpwd ();
9480 add_AT_string (die
, DW_AT_comp_dir
, wd
);
9483 /* Given a tree node describing an array bound (either lower or upper) output
9484 a representation for that bound. */
9487 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
9489 switch (TREE_CODE (bound
))
9494 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9496 if (! host_integerp (bound
, 0)
9497 || (bound_attr
== DW_AT_lower_bound
9498 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
9499 || (is_fortran () && integer_onep (bound
)))))
9500 /* use the default */
9503 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
9508 case NON_LVALUE_EXPR
:
9509 case VIEW_CONVERT_EXPR
:
9510 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
9514 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9515 access the upper bound values may be bogus. If they refer to a
9516 register, they may only describe how to get at these values at the
9517 points in the generated code right after they have just been
9518 computed. Worse yet, in the typical case, the upper bound values
9519 will not even *be* computed in the optimized code (though the
9520 number of elements will), so these SAVE_EXPRs are entirely
9521 bogus. In order to compensate for this fact, we check here to see
9522 if optimization is enabled, and if so, we don't add an attribute
9523 for the (unknown and unknowable) upper bound. This should not
9524 cause too much trouble for existing (stupid?) debuggers because
9525 they have to deal with empty upper bounds location descriptions
9526 anyway in order to be able to deal with incomplete array types.
9527 Of course an intelligent debugger (GDB?) should be able to
9528 comprehend that a missing upper bound specification in an array
9529 type used for a storage class `auto' local array variable
9530 indicates that the upper bound is both unknown (at compile- time)
9531 and unknowable (at run-time) due to optimization.
9533 We assume that a MEM rtx is safe because gcc wouldn't put the
9534 value there unless it was going to be used repeatedly in the
9535 function, i.e. for cleanups. */
9536 if (SAVE_EXPR_RTL (bound
)
9537 && (! optimize
|| GET_CODE (SAVE_EXPR_RTL (bound
)) == MEM
))
9539 dw_die_ref ctx
= lookup_decl_die (current_function_decl
);
9540 dw_die_ref decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9541 rtx loc
= SAVE_EXPR_RTL (bound
);
9543 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9544 it references an outer function's frame. */
9545 if (GET_CODE (loc
) == MEM
)
9547 rtx new_addr
= fix_lexical_addr (XEXP (loc
, 0), bound
);
9549 if (XEXP (loc
, 0) != new_addr
)
9550 loc
= gen_rtx_MEM (GET_MODE (loc
), new_addr
);
9553 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9554 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9555 add_AT_location_description (decl_die
, DW_AT_location
,
9556 loc_descriptor (loc
));
9557 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9560 /* Else leave out the attribute. */
9566 dw_die_ref decl_die
= lookup_decl_die (bound
);
9568 /* ??? Can this happen, or should the variable have been bound
9569 first? Probably it can, since I imagine that we try to create
9570 the types of parameters in the order in which they exist in
9571 the list, and won't have created a forward reference to a
9573 if (decl_die
!= NULL
)
9574 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9580 /* Otherwise try to create a stack operation procedure to
9581 evaluate the value of the array bound. */
9583 dw_die_ref ctx
, decl_die
;
9584 dw_loc_descr_ref loc
;
9586 loc
= loc_descriptor_from_tree (bound
, 0);
9590 if (current_function_decl
== 0)
9591 ctx
= comp_unit_die
;
9593 ctx
= lookup_decl_die (current_function_decl
);
9595 /* If we weren't able to find a context, it's most likely the case
9596 that we are processing the return type of the function. So
9597 make a SAVE_EXPR to point to it and have the limbo DIE code
9598 find the proper die. The save_expr function doesn't always
9599 make a SAVE_EXPR, so do it ourselves. */
9601 bound
= build (SAVE_EXPR
, TREE_TYPE (bound
), bound
,
9602 current_function_decl
, NULL_TREE
);
9604 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9605 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9606 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9607 add_AT_loc (decl_die
, DW_AT_location
, loc
);
9609 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9615 /* Note that the block of subscript information for an array type also
9616 includes information about the element type of type given array type. */
9619 add_subscript_info (dw_die_ref type_die
, tree type
)
9621 #ifndef MIPS_DEBUGGING_INFO
9622 unsigned dimension_number
;
9625 dw_die_ref subrange_die
;
9627 /* The GNU compilers represent multidimensional array types as sequences of
9628 one dimensional array types whose element types are themselves array
9629 types. Here we squish that down, so that each multidimensional array
9630 type gets only one array_type DIE in the Dwarf debugging info. The draft
9631 Dwarf specification say that we are allowed to do this kind of
9632 compression in C (because there is no difference between an array or
9633 arrays and a multidimensional array in C) but for other source languages
9634 (e.g. Ada) we probably shouldn't do this. */
9636 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9637 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9638 We work around this by disabling this feature. See also
9639 gen_array_type_die. */
9640 #ifndef MIPS_DEBUGGING_INFO
9641 for (dimension_number
= 0;
9642 TREE_CODE (type
) == ARRAY_TYPE
;
9643 type
= TREE_TYPE (type
), dimension_number
++)
9646 tree domain
= TYPE_DOMAIN (type
);
9648 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9649 and (in GNU C only) variable bounds. Handle all three forms
9651 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
9654 /* We have an array type with specified bounds. */
9655 lower
= TYPE_MIN_VALUE (domain
);
9656 upper
= TYPE_MAX_VALUE (domain
);
9658 /* define the index type. */
9659 if (TREE_TYPE (domain
))
9661 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9662 TREE_TYPE field. We can't emit debug info for this
9663 because it is an unnamed integral type. */
9664 if (TREE_CODE (domain
) == INTEGER_TYPE
9665 && TYPE_NAME (domain
) == NULL_TREE
9666 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
9667 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
9670 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
9674 /* ??? If upper is NULL, the array has unspecified length,
9675 but it does have a lower bound. This happens with Fortran
9677 Since the debugger is definitely going to need to know N
9678 to produce useful results, go ahead and output the lower
9679 bound solo, and hope the debugger can cope. */
9681 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
9683 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
9686 /* Otherwise we have an array type with an unspecified length. The
9687 DWARF-2 spec does not say how to handle this; let's just leave out the
9693 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
9697 switch (TREE_CODE (tree_node
))
9705 case QUAL_UNION_TYPE
:
9706 size
= int_size_in_bytes (tree_node
);
9709 /* For a data member of a struct or union, the DW_AT_byte_size is
9710 generally given as the number of bytes normally allocated for an
9711 object of the *declared* type of the member itself. This is true
9712 even for bit-fields. */
9713 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
9719 /* Note that `size' might be -1 when we get to this point. If it is, that
9720 indicates that the byte size of the entity in question is variable. We
9721 have no good way of expressing this fact in Dwarf at the present time,
9722 so just let the -1 pass on through. */
9723 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
9726 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9727 which specifies the distance in bits from the highest order bit of the
9728 "containing object" for the bit-field to the highest order bit of the
9731 For any given bit-field, the "containing object" is a hypothetical object
9732 (of some integral or enum type) within which the given bit-field lives. The
9733 type of this hypothetical "containing object" is always the same as the
9734 declared type of the individual bit-field itself. The determination of the
9735 exact location of the "containing object" for a bit-field is rather
9736 complicated. It's handled by the `field_byte_offset' function (above).
9738 Note that it is the size (in bytes) of the hypothetical "containing object"
9739 which will be given in the DW_AT_byte_size attribute for this bit-field.
9740 (See `byte_size_attribute' above). */
9743 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
9745 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
9746 tree type
= DECL_BIT_FIELD_TYPE (decl
);
9747 HOST_WIDE_INT bitpos_int
;
9748 HOST_WIDE_INT highest_order_object_bit_offset
;
9749 HOST_WIDE_INT highest_order_field_bit_offset
;
9750 HOST_WIDE_INT
unsigned bit_offset
;
9752 /* Must be a field and a bit field. */
9754 || TREE_CODE (decl
) != FIELD_DECL
)
9757 /* We can't yet handle bit-fields whose offsets are variable, so if we
9758 encounter such things, just return without generating any attribute
9759 whatsoever. Likewise for variable or too large size. */
9760 if (! host_integerp (bit_position (decl
), 0)
9761 || ! host_integerp (DECL_SIZE (decl
), 1))
9764 bitpos_int
= int_bit_position (decl
);
9766 /* Note that the bit offset is always the distance (in bits) from the
9767 highest-order bit of the "containing object" to the highest-order bit of
9768 the bit-field itself. Since the "high-order end" of any object or field
9769 is different on big-endian and little-endian machines, the computation
9770 below must take account of these differences. */
9771 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
9772 highest_order_field_bit_offset
= bitpos_int
;
9774 if (! BYTES_BIG_ENDIAN
)
9776 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
9777 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
9781 = (! BYTES_BIG_ENDIAN
9782 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
9783 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
9785 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
9788 /* For a FIELD_DECL node which represents a bit field, output an attribute
9789 which specifies the length in bits of the given field. */
9792 add_bit_size_attribute (dw_die_ref die
, tree decl
)
9794 /* Must be a field and a bit field. */
9795 if (TREE_CODE (decl
) != FIELD_DECL
9796 || ! DECL_BIT_FIELD_TYPE (decl
))
9799 if (host_integerp (DECL_SIZE (decl
), 1))
9800 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
9803 /* If the compiled language is ANSI C, then add a 'prototyped'
9804 attribute, if arg types are given for the parameters of a function. */
9807 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
9809 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
9810 && TYPE_ARG_TYPES (func_type
) != NULL
)
9811 add_AT_flag (die
, DW_AT_prototyped
, 1);
9814 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9815 by looking in either the type declaration or object declaration
9819 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
9821 dw_die_ref origin_die
= NULL
;
9823 if (TREE_CODE (origin
) != FUNCTION_DECL
)
9825 /* We may have gotten separated from the block for the inlined
9826 function, if we're in an exception handler or some such; make
9827 sure that the abstract function has been written out.
9829 Doing this for nested functions is wrong, however; functions are
9830 distinct units, and our context might not even be inline. */
9834 fn
= TYPE_STUB_DECL (fn
);
9836 fn
= decl_function_context (fn
);
9838 dwarf2out_abstract_function (fn
);
9841 if (DECL_P (origin
))
9842 origin_die
= lookup_decl_die (origin
);
9843 else if (TYPE_P (origin
))
9844 origin_die
= lookup_type_die (origin
);
9846 if (origin_die
== NULL
)
9849 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
9852 /* We do not currently support the pure_virtual attribute. */
9855 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
9857 if (DECL_VINDEX (func_decl
))
9859 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
9861 if (host_integerp (DECL_VINDEX (func_decl
), 0))
9862 add_AT_loc (die
, DW_AT_vtable_elem_location
,
9863 new_loc_descr (DW_OP_constu
,
9864 tree_low_cst (DECL_VINDEX (func_decl
), 0),
9867 /* GNU extension: Record what type this method came from originally. */
9868 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9869 add_AT_die_ref (die
, DW_AT_containing_type
,
9870 lookup_type_die (DECL_CONTEXT (func_decl
)));
9874 /* Add source coordinate attributes for the given decl. */
9877 add_src_coords_attributes (dw_die_ref die
, tree decl
)
9879 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
9881 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
9882 add_AT_unsigned (die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
9885 /* Add a DW_AT_name attribute and source coordinate attribute for the
9886 given decl, but only if it actually has a name. */
9889 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
9893 decl_name
= DECL_NAME (decl
);
9894 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
9896 add_name_attribute (die
, dwarf2_name (decl
, 0));
9897 if (! DECL_ARTIFICIAL (decl
))
9898 add_src_coords_attributes (die
, decl
);
9900 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
9901 && TREE_PUBLIC (decl
)
9902 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
9903 && !DECL_ABSTRACT (decl
))
9904 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
9905 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
9908 #ifdef VMS_DEBUGGING_INFO
9909 /* Get the function's name, as described by its RTL. This may be different
9910 from the DECL_NAME name used in the source file. */
9911 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
9913 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
9914 XEXP (DECL_RTL (decl
), 0));
9915 VARRAY_PUSH_RTX (used_rtx_varray
, XEXP (DECL_RTL (decl
), 0));
9920 /* Push a new declaration scope. */
9923 push_decl_scope (tree scope
)
9925 VARRAY_PUSH_TREE (decl_scope_table
, scope
);
9928 /* Pop a declaration scope. */
9931 pop_decl_scope (void)
9933 if (VARRAY_ACTIVE_SIZE (decl_scope_table
) <= 0)
9936 VARRAY_POP (decl_scope_table
);
9939 /* Return the DIE for the scope that immediately contains this type.
9940 Non-named types get global scope. Named types nested in other
9941 types get their containing scope if it's open, or global scope
9942 otherwise. All other types (i.e. function-local named types) get
9943 the current active scope. */
9946 scope_die_for (tree t
, dw_die_ref context_die
)
9948 dw_die_ref scope_die
= NULL
;
9949 tree containing_scope
;
9952 /* Non-types always go in the current scope. */
9956 containing_scope
= TYPE_CONTEXT (t
);
9958 /* Ignore namespaces for the moment. */
9959 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
9960 containing_scope
= NULL_TREE
;
9962 /* Ignore function type "scopes" from the C frontend. They mean that
9963 a tagged type is local to a parmlist of a function declarator, but
9964 that isn't useful to DWARF. */
9965 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
9966 containing_scope
= NULL_TREE
;
9968 if (containing_scope
== NULL_TREE
)
9969 scope_die
= comp_unit_die
;
9970 else if (TYPE_P (containing_scope
))
9972 /* For types, we can just look up the appropriate DIE. But
9973 first we check to see if we're in the middle of emitting it
9974 so we know where the new DIE should go. */
9975 for (i
= VARRAY_ACTIVE_SIZE (decl_scope_table
) - 1; i
>= 0; --i
)
9976 if (VARRAY_TREE (decl_scope_table
, i
) == containing_scope
)
9981 if (debug_info_level
> DINFO_LEVEL_TERSE
9982 && !TREE_ASM_WRITTEN (containing_scope
))
9985 /* If none of the current dies are suitable, we get file scope. */
9986 scope_die
= comp_unit_die
;
9989 scope_die
= lookup_type_die (containing_scope
);
9992 scope_die
= context_die
;
9997 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
10000 local_scope_p (dw_die_ref context_die
)
10002 for (; context_die
; context_die
= context_die
->die_parent
)
10003 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
10004 || context_die
->die_tag
== DW_TAG_subprogram
)
10010 /* Returns nonzero if CONTEXT_DIE is a class. */
10013 class_scope_p (dw_die_ref context_die
)
10015 return (context_die
10016 && (context_die
->die_tag
== DW_TAG_structure_type
10017 || context_die
->die_tag
== DW_TAG_union_type
));
10020 /* Many forms of DIEs require a "type description" attribute. This
10021 routine locates the proper "type descriptor" die for the type given
10022 by 'type', and adds a DW_AT_type attribute below the given die. */
10025 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
10026 int decl_volatile
, dw_die_ref context_die
)
10028 enum tree_code code
= TREE_CODE (type
);
10029 dw_die_ref type_die
= NULL
;
10031 /* ??? If this type is an unnamed subrange type of an integral or
10032 floating-point type, use the inner type. This is because we have no
10033 support for unnamed types in base_type_die. This can happen if this is
10034 an Ada subrange type. Correct solution is emit a subrange type die. */
10035 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
10036 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
10037 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
10039 if (code
== ERROR_MARK
10040 /* Handle a special case. For functions whose return type is void, we
10041 generate *no* type attribute. (Note that no object may have type
10042 `void', so this only applies to function return types). */
10043 || code
== VOID_TYPE
)
10046 type_die
= modified_type_die (type
,
10047 decl_const
|| TYPE_READONLY (type
),
10048 decl_volatile
|| TYPE_VOLATILE (type
),
10051 if (type_die
!= NULL
)
10052 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
10055 /* Given a tree pointer to a struct, class, union, or enum type node, return
10056 a pointer to the (string) tag name for the given type, or zero if the type
10057 was declared without a tag. */
10059 static const char *
10060 type_tag (tree type
)
10062 const char *name
= 0;
10064 if (TYPE_NAME (type
) != 0)
10068 /* Find the IDENTIFIER_NODE for the type name. */
10069 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
10070 t
= TYPE_NAME (type
);
10072 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
10073 a TYPE_DECL node, regardless of whether or not a `typedef' was
10075 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10076 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
10077 t
= DECL_NAME (TYPE_NAME (type
));
10079 /* Now get the name as a string, or invent one. */
10081 name
= IDENTIFIER_POINTER (t
);
10084 return (name
== 0 || *name
== '\0') ? 0 : name
;
10087 /* Return the type associated with a data member, make a special check
10088 for bit field types. */
10091 member_declared_type (tree member
)
10093 return (DECL_BIT_FIELD_TYPE (member
)
10094 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
10097 /* Get the decl's label, as described by its RTL. This may be different
10098 from the DECL_NAME name used in the source file. */
10101 static const char *
10102 decl_start_label (tree decl
)
10105 const char *fnname
;
10107 x
= DECL_RTL (decl
);
10108 if (GET_CODE (x
) != MEM
)
10112 if (GET_CODE (x
) != SYMBOL_REF
)
10115 fnname
= XSTR (x
, 0);
10120 /* These routines generate the internal representation of the DIE's for
10121 the compilation unit. Debugging information is collected by walking
10122 the declaration trees passed in from dwarf2out_decl(). */
10125 gen_array_type_die (tree type
, dw_die_ref context_die
)
10127 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
10128 dw_die_ref array_die
;
10131 /* ??? The SGI dwarf reader fails for array of array of enum types unless
10132 the inner array type comes before the outer array type. Thus we must
10133 call gen_type_die before we call new_die. See below also. */
10134 #ifdef MIPS_DEBUGGING_INFO
10135 gen_type_die (TREE_TYPE (type
), context_die
);
10138 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
10139 add_name_attribute (array_die
, type_tag (type
));
10140 equate_type_number_to_die (type
, array_die
);
10142 if (TREE_CODE (type
) == VECTOR_TYPE
)
10144 /* The frontend feeds us a representation for the vector as a struct
10145 containing an array. Pull out the array type. */
10146 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
10147 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
10151 /* We default the array ordering. SDB will probably do
10152 the right things even if DW_AT_ordering is not present. It's not even
10153 an issue until we start to get into multidimensional arrays anyway. If
10154 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
10155 then we'll have to put the DW_AT_ordering attribute back in. (But if
10156 and when we find out that we need to put these in, we will only do so
10157 for multidimensional arrays. */
10158 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
10161 #ifdef MIPS_DEBUGGING_INFO
10162 /* The SGI compilers handle arrays of unknown bound by setting
10163 AT_declaration and not emitting any subrange DIEs. */
10164 if (! TYPE_DOMAIN (type
))
10165 add_AT_unsigned (array_die
, DW_AT_declaration
, 1);
10168 add_subscript_info (array_die
, type
);
10170 /* Add representation of the type of the elements of this array type. */
10171 element_type
= TREE_TYPE (type
);
10173 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10174 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10175 We work around this by disabling this feature. See also
10176 add_subscript_info. */
10177 #ifndef MIPS_DEBUGGING_INFO
10178 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
10179 element_type
= TREE_TYPE (element_type
);
10181 gen_type_die (element_type
, context_die
);
10184 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
10188 gen_set_type_die (tree type
, dw_die_ref context_die
)
10190 dw_die_ref type_die
10191 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
), type
);
10193 equate_type_number_to_die (type
, type_die
);
10194 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
10199 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
10201 tree origin
= decl_ultimate_origin (decl
);
10202 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
10204 if (origin
!= NULL
)
10205 add_abstract_origin_attribute (decl_die
, origin
);
10208 add_name_and_src_coords_attributes (decl_die
, decl
);
10209 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
10210 0, 0, context_die
);
10213 if (DECL_ABSTRACT (decl
))
10214 equate_decl_number_to_die (decl
, decl_die
);
10216 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
10220 /* Walk through the list of incomplete types again, trying once more to
10221 emit full debugging info for them. */
10224 retry_incomplete_types (void)
10228 for (i
= VARRAY_ACTIVE_SIZE (incomplete_types
) - 1; i
>= 0; i
--)
10229 gen_type_die (VARRAY_TREE (incomplete_types
, i
), comp_unit_die
);
10232 /* Generate a DIE to represent an inlined instance of an enumeration type. */
10235 gen_inlined_enumeration_type_die (tree type
, dw_die_ref context_die
)
10237 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
10239 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10240 be incomplete and such types are not marked. */
10241 add_abstract_origin_attribute (type_die
, type
);
10244 /* Generate a DIE to represent an inlined instance of a structure type. */
10247 gen_inlined_structure_type_die (tree type
, dw_die_ref context_die
)
10249 dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
, type
);
10251 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10252 be incomplete and such types are not marked. */
10253 add_abstract_origin_attribute (type_die
, type
);
10256 /* Generate a DIE to represent an inlined instance of a union type. */
10259 gen_inlined_union_type_die (tree type
, dw_die_ref context_die
)
10261 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
10263 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10264 be incomplete and such types are not marked. */
10265 add_abstract_origin_attribute (type_die
, type
);
10268 /* Generate a DIE to represent an enumeration type. Note that these DIEs
10269 include all of the information about the enumeration values also. Each
10270 enumerated type name/value is listed as a child of the enumerated type
10274 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
10276 dw_die_ref type_die
= lookup_type_die (type
);
10278 if (type_die
== NULL
)
10280 type_die
= new_die (DW_TAG_enumeration_type
,
10281 scope_die_for (type
, context_die
), type
);
10282 equate_type_number_to_die (type
, type_die
);
10283 add_name_attribute (type_die
, type_tag (type
));
10285 else if (! TYPE_SIZE (type
))
10288 remove_AT (type_die
, DW_AT_declaration
);
10290 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
10291 given enum type is incomplete, do not generate the DW_AT_byte_size
10292 attribute or the DW_AT_element_list attribute. */
10293 if (TYPE_SIZE (type
))
10297 TREE_ASM_WRITTEN (type
) = 1;
10298 add_byte_size_attribute (type_die
, type
);
10299 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
10300 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
10302 /* If the first reference to this type was as the return type of an
10303 inline function, then it may not have a parent. Fix this now. */
10304 if (type_die
->die_parent
== NULL
)
10305 add_child_die (scope_die_for (type
, context_die
), type_die
);
10307 for (link
= TYPE_FIELDS (type
);
10308 link
!= NULL
; link
= TREE_CHAIN (link
))
10310 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
10312 add_name_attribute (enum_die
,
10313 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
10315 if (host_integerp (TREE_VALUE (link
), 0))
10317 if (tree_int_cst_sgn (TREE_VALUE (link
)) < 0)
10318 add_AT_int (enum_die
, DW_AT_const_value
,
10319 tree_low_cst (TREE_VALUE (link
), 0));
10321 add_AT_unsigned (enum_die
, DW_AT_const_value
,
10322 tree_low_cst (TREE_VALUE (link
), 0));
10327 add_AT_flag (type_die
, DW_AT_declaration
, 1);
10330 /* Generate a DIE to represent either a real live formal parameter decl or to
10331 represent just the type of some formal parameter position in some function
10334 Note that this routine is a bit unusual because its argument may be a
10335 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
10336 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
10337 node. If it's the former then this function is being called to output a
10338 DIE to represent a formal parameter object (or some inlining thereof). If
10339 it's the latter, then this function is only being called to output a
10340 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
10341 argument type of some subprogram type. */
10344 gen_formal_parameter_die (tree node
, dw_die_ref context_die
)
10346 dw_die_ref parm_die
10347 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
10350 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
10353 origin
= decl_ultimate_origin (node
);
10354 if (origin
!= NULL
)
10355 add_abstract_origin_attribute (parm_die
, origin
);
10358 add_name_and_src_coords_attributes (parm_die
, node
);
10359 add_type_attribute (parm_die
, TREE_TYPE (node
),
10360 TREE_READONLY (node
),
10361 TREE_THIS_VOLATILE (node
),
10363 if (DECL_ARTIFICIAL (node
))
10364 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
10367 equate_decl_number_to_die (node
, parm_die
);
10368 if (! DECL_ABSTRACT (node
))
10369 add_location_or_const_value_attribute (parm_die
, node
);
10374 /* We were called with some kind of a ..._TYPE node. */
10375 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
10385 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
10386 at the end of an (ANSI prototyped) formal parameters list. */
10389 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
10391 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
10394 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10395 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10396 parameters as specified in some function type specification (except for
10397 those which appear as part of a function *definition*). */
10400 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
10403 tree formal_type
= NULL
;
10404 tree first_parm_type
;
10407 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
10409 arg
= DECL_ARGUMENTS (function_or_method_type
);
10410 function_or_method_type
= TREE_TYPE (function_or_method_type
);
10415 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
10417 /* Make our first pass over the list of formal parameter types and output a
10418 DW_TAG_formal_parameter DIE for each one. */
10419 for (link
= first_parm_type
; link
; )
10421 dw_die_ref parm_die
;
10423 formal_type
= TREE_VALUE (link
);
10424 if (formal_type
== void_type_node
)
10427 /* Output a (nameless) DIE to represent the formal parameter itself. */
10428 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
10429 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
10430 && link
== first_parm_type
)
10431 || (arg
&& DECL_ARTIFICIAL (arg
)))
10432 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
10434 link
= TREE_CHAIN (link
);
10436 arg
= TREE_CHAIN (arg
);
10439 /* If this function type has an ellipsis, add a
10440 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10441 if (formal_type
!= void_type_node
)
10442 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
10444 /* Make our second (and final) pass over the list of formal parameter types
10445 and output DIEs to represent those types (as necessary). */
10446 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
10447 link
&& TREE_VALUE (link
);
10448 link
= TREE_CHAIN (link
))
10449 gen_type_die (TREE_VALUE (link
), context_die
);
10452 /* We want to generate the DIE for TYPE so that we can generate the
10453 die for MEMBER, which has been defined; we will need to refer back
10454 to the member declaration nested within TYPE. If we're trying to
10455 generate minimal debug info for TYPE, processing TYPE won't do the
10456 trick; we need to attach the member declaration by hand. */
10459 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
10461 gen_type_die (type
, context_die
);
10463 /* If we're trying to avoid duplicate debug info, we may not have
10464 emitted the member decl for this function. Emit it now. */
10465 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
10466 && ! lookup_decl_die (member
))
10468 if (decl_ultimate_origin (member
))
10471 push_decl_scope (type
);
10472 if (TREE_CODE (member
) == FUNCTION_DECL
)
10473 gen_subprogram_die (member
, lookup_type_die (type
));
10475 gen_variable_die (member
, lookup_type_die (type
));
10481 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10482 may later generate inlined and/or out-of-line instances of. */
10485 dwarf2out_abstract_function (tree decl
)
10487 dw_die_ref old_die
;
10490 int was_abstract
= DECL_ABSTRACT (decl
);
10492 /* Make sure we have the actual abstract inline, not a clone. */
10493 decl
= DECL_ORIGIN (decl
);
10495 old_die
= lookup_decl_die (decl
);
10496 if (old_die
&& get_AT_unsigned (old_die
, DW_AT_inline
))
10497 /* We've already generated the abstract instance. */
10500 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10501 we don't get confused by DECL_ABSTRACT. */
10502 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10504 context
= decl_class_context (decl
);
10506 gen_type_die_for_member
10507 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
10510 /* Pretend we've just finished compiling this function. */
10511 save_fn
= current_function_decl
;
10512 current_function_decl
= decl
;
10514 set_decl_abstract_flags (decl
, 1);
10515 dwarf2out_decl (decl
);
10516 if (! was_abstract
)
10517 set_decl_abstract_flags (decl
, 0);
10519 current_function_decl
= save_fn
;
10522 /* Generate a DIE to represent a declared function (either file-scope or
10526 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
10528 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
10529 tree origin
= decl_ultimate_origin (decl
);
10530 dw_die_ref subr_die
;
10534 dw_die_ref old_die
= lookup_decl_die (decl
);
10535 int declaration
= (current_function_decl
!= decl
10536 || class_scope_p (context_die
));
10538 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10539 started to generate the abstract instance of an inline, decided to output
10540 its containing class, and proceeded to emit the declaration of the inline
10541 from the member list for the class. If so, DECLARATION takes priority;
10542 we'll get back to the abstract instance when done with the class. */
10544 /* The class-scope declaration DIE must be the primary DIE. */
10545 if (origin
&& declaration
&& class_scope_p (context_die
))
10552 if (origin
!= NULL
)
10554 if (declaration
&& ! local_scope_p (context_die
))
10557 /* Fixup die_parent for the abstract instance of a nested
10558 inline function. */
10559 if (old_die
&& old_die
->die_parent
== NULL
)
10560 add_child_die (context_die
, old_die
);
10562 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10563 add_abstract_origin_attribute (subr_die
, origin
);
10567 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10569 if (!get_AT_flag (old_die
, DW_AT_declaration
)
10570 /* We can have a normal definition following an inline one in the
10571 case of redefinition of GNU C extern inlines.
10572 It seems reasonable to use AT_specification in this case. */
10573 && !get_AT_unsigned (old_die
, DW_AT_inline
))
10575 /* ??? This can happen if there is a bug in the program, for
10576 instance, if it has duplicate function definitions. Ideally,
10577 we should detect this case and ignore it. For now, if we have
10578 already reported an error, any error at all, then assume that
10579 we got here because of an input error, not a dwarf2 bug. */
10585 /* If the definition comes from the same place as the declaration,
10586 maybe use the old DIE. We always want the DIE for this function
10587 that has the *_pc attributes to be under comp_unit_die so the
10588 debugger can find it. We also need to do this for abstract
10589 instances of inlines, since the spec requires the out-of-line copy
10590 to have the same parent. For local class methods, this doesn't
10591 apply; we just use the old DIE. */
10592 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
10593 && (DECL_ARTIFICIAL (decl
)
10594 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
10595 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10596 == (unsigned) DECL_SOURCE_LINE (decl
)))))
10598 subr_die
= old_die
;
10600 /* Clear out the declaration attribute and the parm types. */
10601 remove_AT (subr_die
, DW_AT_declaration
);
10602 remove_children (subr_die
);
10606 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10607 add_AT_die_ref (subr_die
, DW_AT_specification
, old_die
);
10608 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10609 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
10610 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10611 != (unsigned) DECL_SOURCE_LINE (decl
))
10613 (subr_die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
10618 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10620 if (TREE_PUBLIC (decl
))
10621 add_AT_flag (subr_die
, DW_AT_external
, 1);
10623 add_name_and_src_coords_attributes (subr_die
, decl
);
10624 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10626 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
10627 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
10628 0, 0, context_die
);
10631 add_pure_or_virtual_attribute (subr_die
, decl
);
10632 if (DECL_ARTIFICIAL (decl
))
10633 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
10635 if (TREE_PROTECTED (decl
))
10636 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10637 else if (TREE_PRIVATE (decl
))
10638 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10643 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10645 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
10647 /* The first time we see a member function, it is in the context of
10648 the class to which it belongs. We make sure of this by emitting
10649 the class first. The next time is the definition, which is
10650 handled above. The two may come from the same source text. */
10651 if (DECL_CONTEXT (decl
) || DECL_ABSTRACT (decl
))
10652 equate_decl_number_to_die (decl
, subr_die
);
10655 else if (DECL_ABSTRACT (decl
))
10657 if (DECL_INLINE (decl
) && !flag_no_inline
)
10659 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10660 inline functions, but not for extern inline functions.
10661 We can't get this completely correct because information
10662 about whether the function was declared inline is not
10664 if (DECL_DEFER_OUTPUT (decl
))
10665 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
10667 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
10670 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
10672 equate_decl_number_to_die (decl
, subr_die
);
10674 else if (!DECL_EXTERNAL (decl
))
10676 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10677 equate_decl_number_to_die (decl
, subr_die
);
10679 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
10680 current_function_funcdef_no
);
10681 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
10682 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
10683 current_function_funcdef_no
);
10684 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
10686 add_pubname (decl
, subr_die
);
10687 add_arange (decl
, subr_die
);
10689 #ifdef MIPS_DEBUGGING_INFO
10690 /* Add a reference to the FDE for this routine. */
10691 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
10694 /* Define the "frame base" location for this routine. We use the
10695 frame pointer or stack pointer registers, since the RTL for local
10696 variables is relative to one of them. */
10698 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
10699 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
10702 /* ??? This fails for nested inline functions, because context_display
10703 is not part of the state saved/restored for inline functions. */
10704 if (current_function_needs_context
)
10705 add_AT_location_description (subr_die
, DW_AT_static_link
,
10706 loc_descriptor (lookup_static_chain (decl
)));
10710 /* Now output descriptions of the arguments for this function. This gets
10711 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10712 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10713 `...' at the end of the formal parameter list. In order to find out if
10714 there was a trailing ellipsis or not, we must instead look at the type
10715 associated with the FUNCTION_DECL. This will be a node of type
10716 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10717 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10718 an ellipsis at the end. */
10720 /* In the case where we are describing a mere function declaration, all we
10721 need to do here (and all we *can* do here) is to describe the *types* of
10722 its formal parameters. */
10723 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10725 else if (declaration
)
10726 gen_formal_types_die (decl
, subr_die
);
10729 /* Generate DIEs to represent all known formal parameters. */
10730 tree arg_decls
= DECL_ARGUMENTS (decl
);
10733 /* When generating DIEs, generate the unspecified_parameters DIE
10734 instead if we come across the arg "__builtin_va_alist" */
10735 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
10736 if (TREE_CODE (parm
) == PARM_DECL
)
10738 if (DECL_NAME (parm
)
10739 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
10740 "__builtin_va_alist"))
10741 gen_unspecified_parameters_die (parm
, subr_die
);
10743 gen_decl_die (parm
, subr_die
);
10746 /* Decide whether we need an unspecified_parameters DIE at the end.
10747 There are 2 more cases to do this for: 1) the ansi ... declaration -
10748 this is detectable when the end of the arg list is not a
10749 void_type_node 2) an unprototyped function declaration (not a
10750 definition). This just means that we have no info about the
10751 parameters at all. */
10752 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
10753 if (fn_arg_types
!= NULL
)
10755 /* this is the prototyped case, check for ... */
10756 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
10757 gen_unspecified_parameters_die (decl
, subr_die
);
10759 else if (DECL_INITIAL (decl
) == NULL_TREE
)
10760 gen_unspecified_parameters_die (decl
, subr_die
);
10763 /* Output Dwarf info for all of the stuff within the body of the function
10764 (if it has one - it may be just a declaration). */
10765 outer_scope
= DECL_INITIAL (decl
);
10767 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10768 a function. This BLOCK actually represents the outermost binding contour
10769 for the function, i.e. the contour in which the function's formal
10770 parameters and labels get declared. Curiously, it appears that the front
10771 end doesn't actually put the PARM_DECL nodes for the current function onto
10772 the BLOCK_VARS list for this outer scope, but are strung off of the
10773 DECL_ARGUMENTS list for the function instead.
10775 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10776 the LABEL_DECL nodes for the function however, and we output DWARF info
10777 for those in decls_for_scope. Just within the `outer_scope' there will be
10778 a BLOCK node representing the function's outermost pair of curly braces,
10779 and any blocks used for the base and member initializers of a C++
10780 constructor function. */
10781 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
10783 current_function_has_inlines
= 0;
10784 decls_for_scope (outer_scope
, subr_die
, 0);
10786 #if 0 && defined (MIPS_DEBUGGING_INFO)
10787 if (current_function_has_inlines
)
10789 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
10790 if (! comp_unit_has_inlines
)
10792 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
10793 comp_unit_has_inlines
= 1;
10800 /* Generate a DIE to represent a declared data object. */
10803 gen_variable_die (tree decl
, dw_die_ref context_die
)
10805 tree origin
= decl_ultimate_origin (decl
);
10806 dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
10808 dw_die_ref old_die
= lookup_decl_die (decl
);
10809 int declaration
= (DECL_EXTERNAL (decl
)
10810 || class_scope_p (context_die
));
10812 if (origin
!= NULL
)
10813 add_abstract_origin_attribute (var_die
, origin
);
10815 /* Loop unrolling can create multiple blocks that refer to the same
10816 static variable, so we must test for the DW_AT_declaration flag.
10818 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10819 copy decls and set the DECL_ABSTRACT flag on them instead of
10822 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10823 else if (old_die
&& TREE_STATIC (decl
)
10824 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
10826 /* This is a definition of a C++ class level static. */
10827 add_AT_die_ref (var_die
, DW_AT_specification
, old_die
);
10828 if (DECL_NAME (decl
))
10830 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10832 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10833 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
10835 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10836 != (unsigned) DECL_SOURCE_LINE (decl
))
10838 add_AT_unsigned (var_die
, DW_AT_decl_line
,
10839 DECL_SOURCE_LINE (decl
));
10844 add_name_and_src_coords_attributes (var_die
, decl
);
10845 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
10846 TREE_THIS_VOLATILE (decl
), context_die
);
10848 if (TREE_PUBLIC (decl
))
10849 add_AT_flag (var_die
, DW_AT_external
, 1);
10851 if (DECL_ARTIFICIAL (decl
))
10852 add_AT_flag (var_die
, DW_AT_artificial
, 1);
10854 if (TREE_PROTECTED (decl
))
10855 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10856 else if (TREE_PRIVATE (decl
))
10857 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10861 add_AT_flag (var_die
, DW_AT_declaration
, 1);
10863 if (class_scope_p (context_die
) || DECL_ABSTRACT (decl
))
10864 equate_decl_number_to_die (decl
, var_die
);
10866 if (! declaration
&& ! DECL_ABSTRACT (decl
))
10868 add_location_or_const_value_attribute (var_die
, decl
);
10869 add_pubname (decl
, var_die
);
10872 tree_add_const_value_attribute (var_die
, decl
);
10875 /* Generate a DIE to represent a label identifier. */
10878 gen_label_die (tree decl
, dw_die_ref context_die
)
10880 tree origin
= decl_ultimate_origin (decl
);
10881 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
10883 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10885 if (origin
!= NULL
)
10886 add_abstract_origin_attribute (lbl_die
, origin
);
10888 add_name_and_src_coords_attributes (lbl_die
, decl
);
10890 if (DECL_ABSTRACT (decl
))
10891 equate_decl_number_to_die (decl
, lbl_die
);
10894 insn
= DECL_RTL (decl
);
10896 /* Deleted labels are programmer specified labels which have been
10897 eliminated because of various optimizations. We still emit them
10898 here so that it is possible to put breakpoints on them. */
10899 if (GET_CODE (insn
) == CODE_LABEL
10900 || ((GET_CODE (insn
) == NOTE
10901 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
)))
10903 /* When optimization is enabled (via -O) some parts of the compiler
10904 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10905 represent source-level labels which were explicitly declared by
10906 the user. This really shouldn't be happening though, so catch
10907 it if it ever does happen. */
10908 if (INSN_DELETED_P (insn
))
10911 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
10912 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
10917 /* Generate a DIE for a lexical block. */
10920 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
10922 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
10923 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10925 if (! BLOCK_ABSTRACT (stmt
))
10927 if (BLOCK_FRAGMENT_CHAIN (stmt
))
10931 add_AT_range_list (stmt_die
, DW_AT_ranges
, add_ranges (stmt
));
10933 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
10936 add_ranges (chain
);
10937 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
10944 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10945 BLOCK_NUMBER (stmt
));
10946 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
10947 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10948 BLOCK_NUMBER (stmt
));
10949 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
10953 decls_for_scope (stmt
, stmt_die
, depth
);
10956 /* Generate a DIE for an inlined subprogram. */
10959 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
10961 if (! BLOCK_ABSTRACT (stmt
))
10963 dw_die_ref subr_die
10964 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
10965 tree decl
= block_ultimate_origin (stmt
);
10966 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10968 /* Emit info for the abstract instance first, if we haven't yet. */
10969 dwarf2out_abstract_function (decl
);
10971 add_abstract_origin_attribute (subr_die
, decl
);
10972 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10973 BLOCK_NUMBER (stmt
));
10974 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
10975 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10976 BLOCK_NUMBER (stmt
));
10977 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
10978 decls_for_scope (stmt
, subr_die
, depth
);
10979 current_function_has_inlines
= 1;
10982 /* We may get here if we're the outer block of function A that was
10983 inlined into function B that was inlined into function C. When
10984 generating debugging info for C, dwarf2out_abstract_function(B)
10985 would mark all inlined blocks as abstract, including this one.
10986 So, we wouldn't (and shouldn't) expect labels to be generated
10987 for this one. Instead, just emit debugging info for
10988 declarations within the block. This is particularly important
10989 in the case of initializers of arguments passed from B to us:
10990 if they're statement expressions containing declarations, we
10991 wouldn't generate dies for their abstract variables, and then,
10992 when generating dies for the real variables, we'd die (pun
10994 gen_lexical_block_die (stmt
, context_die
, depth
);
10997 /* Generate a DIE for a field in a record, or structure. */
11000 gen_field_die (tree decl
, dw_die_ref context_die
)
11002 dw_die_ref decl_die
;
11004 if (TREE_TYPE (decl
) == error_mark_node
)
11007 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
11008 add_name_and_src_coords_attributes (decl_die
, decl
);
11009 add_type_attribute (decl_die
, member_declared_type (decl
),
11010 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
11013 if (DECL_BIT_FIELD_TYPE (decl
))
11015 add_byte_size_attribute (decl_die
, decl
);
11016 add_bit_size_attribute (decl_die
, decl
);
11017 add_bit_offset_attribute (decl_die
, decl
);
11020 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
11021 add_data_member_location_attribute (decl_die
, decl
);
11023 if (DECL_ARTIFICIAL (decl
))
11024 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
11026 if (TREE_PROTECTED (decl
))
11027 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11028 else if (TREE_PRIVATE (decl
))
11029 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11033 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11034 Use modified_type_die instead.
11035 We keep this code here just in case these types of DIEs may be needed to
11036 represent certain things in other languages (e.g. Pascal) someday. */
11039 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
11042 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
11044 equate_type_number_to_die (type
, ptr_die
);
11045 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
11046 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
11049 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11050 Use modified_type_die instead.
11051 We keep this code here just in case these types of DIEs may be needed to
11052 represent certain things in other languages (e.g. Pascal) someday. */
11055 gen_reference_type_die (tree type
, dw_die_ref context_die
)
11058 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
11060 equate_type_number_to_die (type
, ref_die
);
11061 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
11062 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
11066 /* Generate a DIE for a pointer to a member type. */
11069 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
11072 = new_die (DW_TAG_ptr_to_member_type
,
11073 scope_die_for (type
, context_die
), type
);
11075 equate_type_number_to_die (type
, ptr_die
);
11076 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
11077 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
11078 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
11081 /* Generate the DIE for the compilation unit. */
11084 gen_compile_unit_die (const char *filename
)
11087 char producer
[250];
11088 const char *language_string
= lang_hooks
.name
;
11091 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
11095 add_name_attribute (die
, filename
);
11096 /* Don't add cwd for <built-in>. */
11097 if (filename
[0] != DIR_SEPARATOR
&& filename
[0] != '<')
11098 add_comp_dir_attribute (die
);
11101 sprintf (producer
, "%s %s", language_string
, version_string
);
11103 #ifdef MIPS_DEBUGGING_INFO
11104 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
11105 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
11106 not appear in the producer string, the debugger reaches the conclusion
11107 that the object file is stripped and has no debugging information.
11108 To get the MIPS/SGI debugger to believe that there is debugging
11109 information in the object file, we add a -g to the producer string. */
11110 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11111 strcat (producer
, " -g");
11114 add_AT_string (die
, DW_AT_producer
, producer
);
11116 if (strcmp (language_string
, "GNU C++") == 0)
11117 language
= DW_LANG_C_plus_plus
;
11118 else if (strcmp (language_string
, "GNU Ada") == 0)
11119 language
= DW_LANG_Ada95
;
11120 else if (strcmp (language_string
, "GNU F77") == 0)
11121 language
= DW_LANG_Fortran77
;
11122 else if (strcmp (language_string
, "GNU Pascal") == 0)
11123 language
= DW_LANG_Pascal83
;
11124 else if (strcmp (language_string
, "GNU Java") == 0)
11125 language
= DW_LANG_Java
;
11127 language
= DW_LANG_C89
;
11129 add_AT_unsigned (die
, DW_AT_language
, language
);
11133 /* Generate a DIE for a string type. */
11136 gen_string_type_die (tree type
, dw_die_ref context_die
)
11138 dw_die_ref type_die
11139 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
), type
);
11141 equate_type_number_to_die (type
, type_die
);
11143 /* ??? Fudge the string length attribute for now.
11144 TODO: add string length info. */
11146 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
11147 bound_representation (upper_bound
, 0, 'u');
11151 /* Generate the DIE for a base class. */
11154 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
11156 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
11158 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
11159 add_data_member_location_attribute (die
, binfo
);
11161 if (TREE_VIA_VIRTUAL (binfo
))
11162 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
11164 if (access
== access_public_node
)
11165 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
11166 else if (access
== access_protected_node
)
11167 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11170 /* Generate a DIE for a class member. */
11173 gen_member_die (tree type
, dw_die_ref context_die
)
11176 tree binfo
= TYPE_BINFO (type
);
11179 /* If this is not an incomplete type, output descriptions of each of its
11180 members. Note that as we output the DIEs necessary to represent the
11181 members of this record or union type, we will also be trying to output
11182 DIEs to represent the *types* of those members. However the `type'
11183 function (above) will specifically avoid generating type DIEs for member
11184 types *within* the list of member DIEs for this (containing) type except
11185 for those types (of members) which are explicitly marked as also being
11186 members of this (containing) type themselves. The g++ front- end can
11187 force any given type to be treated as a member of some other (containing)
11188 type by setting the TYPE_CONTEXT of the given (member) type to point to
11189 the TREE node representing the appropriate (containing) type. */
11191 /* First output info about the base classes. */
11192 if (binfo
&& BINFO_BASETYPES (binfo
))
11194 tree bases
= BINFO_BASETYPES (binfo
);
11195 tree accesses
= BINFO_BASEACCESSES (binfo
);
11196 int n_bases
= TREE_VEC_LENGTH (bases
);
11199 for (i
= 0; i
< n_bases
; i
++)
11200 gen_inheritance_die (TREE_VEC_ELT (bases
, i
),
11201 (accesses
? TREE_VEC_ELT (accesses
, i
)
11202 : access_public_node
), context_die
);
11205 /* Now output info about the data members and type members. */
11206 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
11208 /* If we thought we were generating minimal debug info for TYPE
11209 and then changed our minds, some of the member declarations
11210 may have already been defined. Don't define them again, but
11211 do put them in the right order. */
11213 child
= lookup_decl_die (member
);
11215 splice_child_die (context_die
, child
);
11217 gen_decl_die (member
, context_die
);
11220 /* Now output info about the function members (if any). */
11221 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
11223 /* Don't include clones in the member list. */
11224 if (DECL_ABSTRACT_ORIGIN (member
))
11227 child
= lookup_decl_die (member
);
11229 splice_child_die (context_die
, child
);
11231 gen_decl_die (member
, context_die
);
11235 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
11236 is set, we pretend that the type was never defined, so we only get the
11237 member DIEs needed by later specification DIEs. */
11240 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
)
11242 dw_die_ref type_die
= lookup_type_die (type
);
11243 dw_die_ref scope_die
= 0;
11245 int complete
= (TYPE_SIZE (type
)
11246 && (! TYPE_STUB_DECL (type
)
11247 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
11249 if (type_die
&& ! complete
)
11252 if (TYPE_CONTEXT (type
) != NULL_TREE
11253 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
)))
11256 scope_die
= scope_die_for (type
, context_die
);
11258 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
11259 /* First occurrence of type or toplevel definition of nested class. */
11261 dw_die_ref old_die
= type_die
;
11263 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
11264 ? DW_TAG_structure_type
: DW_TAG_union_type
,
11266 equate_type_number_to_die (type
, type_die
);
11268 add_AT_die_ref (type_die
, DW_AT_specification
, old_die
);
11270 add_name_attribute (type_die
, type_tag (type
));
11273 remove_AT (type_die
, DW_AT_declaration
);
11275 /* If this type has been completed, then give it a byte_size attribute and
11276 then give a list of members. */
11279 /* Prevent infinite recursion in cases where the type of some member of
11280 this type is expressed in terms of this type itself. */
11281 TREE_ASM_WRITTEN (type
) = 1;
11282 add_byte_size_attribute (type_die
, type
);
11283 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
11284 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
11286 /* If the first reference to this type was as the return type of an
11287 inline function, then it may not have a parent. Fix this now. */
11288 if (type_die
->die_parent
== NULL
)
11289 add_child_die (scope_die
, type_die
);
11291 push_decl_scope (type
);
11292 gen_member_die (type
, type_die
);
11295 /* GNU extension: Record what type our vtable lives in. */
11296 if (TYPE_VFIELD (type
))
11298 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
11300 gen_type_die (vtype
, context_die
);
11301 add_AT_die_ref (type_die
, DW_AT_containing_type
,
11302 lookup_type_die (vtype
));
11307 add_AT_flag (type_die
, DW_AT_declaration
, 1);
11309 /* We don't need to do this for function-local types. */
11310 if (TYPE_STUB_DECL (type
)
11311 && ! decl_function_context (TYPE_STUB_DECL (type
)))
11312 VARRAY_PUSH_TREE (incomplete_types
, type
);
11316 /* Generate a DIE for a subroutine _type_. */
11319 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
11321 tree return_type
= TREE_TYPE (type
);
11322 dw_die_ref subr_die
11323 = new_die (DW_TAG_subroutine_type
,
11324 scope_die_for (type
, context_die
), type
);
11326 equate_type_number_to_die (type
, subr_die
);
11327 add_prototyped_attribute (subr_die
, type
);
11328 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
11329 gen_formal_types_die (type
, subr_die
);
11332 /* Generate a DIE for a type definition. */
11335 gen_typedef_die (tree decl
, dw_die_ref context_die
)
11337 dw_die_ref type_die
;
11340 if (TREE_ASM_WRITTEN (decl
))
11343 TREE_ASM_WRITTEN (decl
) = 1;
11344 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
11345 origin
= decl_ultimate_origin (decl
);
11346 if (origin
!= NULL
)
11347 add_abstract_origin_attribute (type_die
, origin
);
11352 add_name_and_src_coords_attributes (type_die
, decl
);
11353 if (DECL_ORIGINAL_TYPE (decl
))
11355 type
= DECL_ORIGINAL_TYPE (decl
);
11357 if (type
== TREE_TYPE (decl
))
11360 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
11363 type
= TREE_TYPE (decl
);
11365 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
11366 TREE_THIS_VOLATILE (decl
), context_die
);
11369 if (DECL_ABSTRACT (decl
))
11370 equate_decl_number_to_die (decl
, type_die
);
11373 /* Generate a type description DIE. */
11376 gen_type_die (tree type
, dw_die_ref context_die
)
11380 if (type
== NULL_TREE
|| type
== error_mark_node
)
11383 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
11384 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
11386 if (TREE_ASM_WRITTEN (type
))
11389 /* Prevent broken recursion; we can't hand off to the same type. */
11390 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) == type
)
11393 TREE_ASM_WRITTEN (type
) = 1;
11394 gen_decl_die (TYPE_NAME (type
), context_die
);
11398 /* We are going to output a DIE to represent the unqualified version
11399 of this type (i.e. without any const or volatile qualifiers) so
11400 get the main variant (i.e. the unqualified version) of this type
11401 now. (Vectors are special because the debugging info is in the
11402 cloned type itself). */
11403 if (TREE_CODE (type
) != VECTOR_TYPE
)
11404 type
= type_main_variant (type
);
11406 if (TREE_ASM_WRITTEN (type
))
11409 switch (TREE_CODE (type
))
11415 case REFERENCE_TYPE
:
11416 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11417 ensures that the gen_type_die recursion will terminate even if the
11418 type is recursive. Recursive types are possible in Ada. */
11419 /* ??? We could perhaps do this for all types before the switch
11421 TREE_ASM_WRITTEN (type
) = 1;
11423 /* For these types, all that is required is that we output a DIE (or a
11424 set of DIEs) to represent the "basis" type. */
11425 gen_type_die (TREE_TYPE (type
), context_die
);
11429 /* This code is used for C++ pointer-to-data-member types.
11430 Output a description of the relevant class type. */
11431 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
11433 /* Output a description of the type of the object pointed to. */
11434 gen_type_die (TREE_TYPE (type
), context_die
);
11436 /* Now output a DIE to represent this pointer-to-data-member type
11438 gen_ptr_to_mbr_type_die (type
, context_die
);
11442 gen_type_die (TYPE_DOMAIN (type
), context_die
);
11443 gen_set_type_die (type
, context_die
);
11447 gen_type_die (TREE_TYPE (type
), context_die
);
11448 abort (); /* No way to represent these in Dwarf yet! */
11451 case FUNCTION_TYPE
:
11452 /* Force out return type (in case it wasn't forced out already). */
11453 gen_type_die (TREE_TYPE (type
), context_die
);
11454 gen_subroutine_type_die (type
, context_die
);
11458 /* Force out return type (in case it wasn't forced out already). */
11459 gen_type_die (TREE_TYPE (type
), context_die
);
11460 gen_subroutine_type_die (type
, context_die
);
11464 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
11466 gen_type_die (TREE_TYPE (type
), context_die
);
11467 gen_string_type_die (type
, context_die
);
11470 gen_array_type_die (type
, context_die
);
11474 gen_array_type_die (type
, context_die
);
11477 case ENUMERAL_TYPE
:
11480 case QUAL_UNION_TYPE
:
11481 /* If this is a nested type whose containing class hasn't been written
11482 out yet, writing it out will cover this one, too. This does not apply
11483 to instantiations of member class templates; they need to be added to
11484 the containing class as they are generated. FIXME: This hurts the
11485 idea of combining type decls from multiple TUs, since we can't predict
11486 what set of template instantiations we'll get. */
11487 if (TYPE_CONTEXT (type
)
11488 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
11489 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
11491 gen_type_die (TYPE_CONTEXT (type
), context_die
);
11493 if (TREE_ASM_WRITTEN (type
))
11496 /* If that failed, attach ourselves to the stub. */
11497 push_decl_scope (TYPE_CONTEXT (type
));
11498 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
11504 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
11505 gen_enumeration_type_die (type
, context_die
);
11507 gen_struct_or_union_type_die (type
, context_die
);
11512 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11513 it up if it is ever completed. gen_*_type_die will set it for us
11514 when appropriate. */
11523 /* No DIEs needed for fundamental types. */
11527 /* No Dwarf representation currently defined. */
11534 TREE_ASM_WRITTEN (type
) = 1;
11537 /* Generate a DIE for a tagged type instantiation. */
11540 gen_tagged_type_instantiation_die (tree type
, dw_die_ref context_die
)
11542 if (type
== NULL_TREE
|| type
== error_mark_node
)
11545 /* We are going to output a DIE to represent the unqualified version of
11546 this type (i.e. without any const or volatile qualifiers) so make sure
11547 that we have the main variant (i.e. the unqualified version) of this
11549 if (type
!= type_main_variant (type
))
11552 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11553 an instance of an unresolved type. */
11555 switch (TREE_CODE (type
))
11560 case ENUMERAL_TYPE
:
11561 gen_inlined_enumeration_type_die (type
, context_die
);
11565 gen_inlined_structure_type_die (type
, context_die
);
11569 case QUAL_UNION_TYPE
:
11570 gen_inlined_union_type_die (type
, context_die
);
11578 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11579 things which are local to the given block. */
11582 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
11584 int must_output_die
= 0;
11587 enum tree_code origin_code
;
11589 /* Ignore blocks never really used to make RTL. */
11590 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
)
11591 || (!TREE_ASM_WRITTEN (stmt
) && !BLOCK_ABSTRACT (stmt
)))
11594 /* If the block is one fragment of a non-contiguous block, do not
11595 process the variables, since they will have been done by the
11596 origin block. Do process subblocks. */
11597 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
11601 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
11602 gen_block_die (sub
, context_die
, depth
+ 1);
11607 /* Determine the "ultimate origin" of this block. This block may be an
11608 inlined instance of an inlined instance of inline function, so we have
11609 to trace all of the way back through the origin chain to find out what
11610 sort of node actually served as the original seed for the creation of
11611 the current block. */
11612 origin
= block_ultimate_origin (stmt
);
11613 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
11615 /* Determine if we need to output any Dwarf DIEs at all to represent this
11617 if (origin_code
== FUNCTION_DECL
)
11618 /* The outer scopes for inlinings *must* always be represented. We
11619 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11620 must_output_die
= 1;
11623 /* In the case where the current block represents an inlining of the
11624 "body block" of an inline function, we must *NOT* output any DIE for
11625 this block because we have already output a DIE to represent the whole
11626 inlined function scope and the "body block" of any function doesn't
11627 really represent a different scope according to ANSI C rules. So we
11628 check here to make sure that this block does not represent a "body
11629 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11630 if (! is_body_block (origin
? origin
: stmt
))
11632 /* Determine if this block directly contains any "significant"
11633 local declarations which we will need to output DIEs for. */
11634 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11635 /* We are not in terse mode so *any* local declaration counts
11636 as being a "significant" one. */
11637 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
11639 /* We are in terse mode, so only local (nested) function
11640 definitions count as "significant" local declarations. */
11641 for (decl
= BLOCK_VARS (stmt
);
11642 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11643 if (TREE_CODE (decl
) == FUNCTION_DECL
11644 && DECL_INITIAL (decl
))
11646 must_output_die
= 1;
11652 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11653 DIE for any block which contains no significant local declarations at
11654 all. Rather, in such cases we just call `decls_for_scope' so that any
11655 needed Dwarf info for any sub-blocks will get properly generated. Note
11656 that in terse mode, our definition of what constitutes a "significant"
11657 local declaration gets restricted to include only inlined function
11658 instances and local (nested) function definitions. */
11659 if (must_output_die
)
11661 if (origin_code
== FUNCTION_DECL
)
11662 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
11664 gen_lexical_block_die (stmt
, context_die
, depth
);
11667 decls_for_scope (stmt
, context_die
, depth
);
11670 /* Generate all of the decls declared within a given scope and (recursively)
11671 all of its sub-blocks. */
11674 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
11679 /* Ignore blocks never really used to make RTL. */
11680 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
11683 /* Output the DIEs to represent all of the data objects and typedefs
11684 declared directly within this block but not within any nested
11685 sub-blocks. Also, nested function and tag DIEs have been
11686 generated with a parent of NULL; fix that up now. */
11687 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11691 if (TREE_CODE (decl
) == FUNCTION_DECL
)
11692 die
= lookup_decl_die (decl
);
11693 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
11694 die
= lookup_type_die (TREE_TYPE (decl
));
11698 if (die
!= NULL
&& die
->die_parent
== NULL
)
11699 add_child_die (context_die
, die
);
11701 gen_decl_die (decl
, context_die
);
11704 /* If we're at -g1, we're not interested in subblocks. */
11705 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11708 /* Output the DIEs to represent all sub-blocks (and the items declared
11709 therein) of this block. */
11710 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
11712 subblocks
= BLOCK_CHAIN (subblocks
))
11713 gen_block_die (subblocks
, context_die
, depth
+ 1);
11716 /* Is this a typedef we can avoid emitting? */
11719 is_redundant_typedef (tree decl
)
11721 if (TYPE_DECL_IS_STUB (decl
))
11724 if (DECL_ARTIFICIAL (decl
)
11725 && DECL_CONTEXT (decl
)
11726 && is_tagged_type (DECL_CONTEXT (decl
))
11727 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
11728 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
11729 /* Also ignore the artificial member typedef for the class name. */
11735 /* Generate Dwarf debug information for a decl described by DECL. */
11738 gen_decl_die (tree decl
, dw_die_ref context_die
)
11742 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
11745 switch (TREE_CODE (decl
))
11751 /* The individual enumerators of an enum type get output when we output
11752 the Dwarf representation of the relevant enum type itself. */
11755 case FUNCTION_DECL
:
11756 /* Don't output any DIEs to represent mere function declarations,
11757 unless they are class members or explicit block externs. */
11758 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
11759 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
11762 /* If we're emitting a clone, emit info for the abstract instance. */
11763 if (DECL_ORIGIN (decl
) != decl
)
11764 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
11766 /* If we're emitting an out-of-line copy of an inline function,
11767 emit info for the abstract instance and set up to refer to it. */
11768 else if (DECL_INLINE (decl
) && ! DECL_ABSTRACT (decl
)
11769 && ! class_scope_p (context_die
)
11770 /* dwarf2out_abstract_function won't emit a die if this is just
11771 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11772 that case, because that works only if we have a die. */
11773 && DECL_INITIAL (decl
) != NULL_TREE
)
11775 dwarf2out_abstract_function (decl
);
11776 set_decl_origin_self (decl
);
11779 /* Otherwise we're emitting the primary DIE for this decl. */
11780 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
11782 /* Before we describe the FUNCTION_DECL itself, make sure that we
11783 have described its return type. */
11784 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
11786 /* And its virtual context. */
11787 if (DECL_VINDEX (decl
) != NULL_TREE
)
11788 gen_type_die (DECL_CONTEXT (decl
), context_die
);
11790 /* And its containing type. */
11791 origin
= decl_class_context (decl
);
11792 if (origin
!= NULL_TREE
)
11793 gen_type_die_for_member (origin
, decl
, context_die
);
11796 /* Now output a DIE to represent the function itself. */
11797 gen_subprogram_die (decl
, context_die
);
11801 /* If we are in terse mode, don't generate any DIEs to represent any
11802 actual typedefs. */
11803 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11806 /* In the special case of a TYPE_DECL node representing the declaration
11807 of some type tag, if the given TYPE_DECL is marked as having been
11808 instantiated from some other (original) TYPE_DECL node (e.g. one which
11809 was generated within the original definition of an inline function) we
11810 have to generate a special (abbreviated) DW_TAG_structure_type,
11811 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11812 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
11814 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
11818 if (is_redundant_typedef (decl
))
11819 gen_type_die (TREE_TYPE (decl
), context_die
);
11821 /* Output a DIE to represent the typedef itself. */
11822 gen_typedef_die (decl
, context_die
);
11826 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
11827 gen_label_die (decl
, context_die
);
11831 /* If we are in terse mode, don't generate any DIEs to represent any
11832 variable declarations or definitions. */
11833 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11836 /* Output any DIEs that are needed to specify the type of this data
11838 gen_type_die (TREE_TYPE (decl
), context_die
);
11840 /* And its containing type. */
11841 origin
= decl_class_context (decl
);
11842 if (origin
!= NULL_TREE
)
11843 gen_type_die_for_member (origin
, decl
, context_die
);
11845 /* Now output the DIE to represent the data object itself. This gets
11846 complicated because of the possibility that the VAR_DECL really
11847 represents an inlined instance of a formal parameter for an inline
11849 origin
= decl_ultimate_origin (decl
);
11850 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
11851 gen_formal_parameter_die (decl
, context_die
);
11853 gen_variable_die (decl
, context_die
);
11857 /* Ignore the nameless fields that are used to skip bits but handle C++
11858 anonymous unions. */
11859 if (DECL_NAME (decl
) != NULL_TREE
11860 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
)
11862 gen_type_die (member_declared_type (decl
), context_die
);
11863 gen_field_die (decl
, context_die
);
11868 gen_type_die (TREE_TYPE (decl
), context_die
);
11869 gen_formal_parameter_die (decl
, context_die
);
11872 case NAMESPACE_DECL
:
11873 /* Ignore for now. */
11877 if ((int)TREE_CODE (decl
) > NUM_TREE_CODES
)
11878 /* Probably some frontend-internal decl. Assume we don't care. */
11884 /* Add Ada "use" clause information for SGI Workshop debugger. */
11887 dwarf2out_add_library_unit_info (const char *filename
, const char *context_list
)
11889 unsigned int file_index
;
11891 if (filename
!= NULL
)
11893 dw_die_ref unit_die
= new_die (DW_TAG_module
, comp_unit_die
, NULL
);
11894 tree context_list_decl
11895 = build_decl (LABEL_DECL
, get_identifier (context_list
),
11898 TREE_PUBLIC (context_list_decl
) = TRUE
;
11899 add_name_attribute (unit_die
, context_list
);
11900 file_index
= lookup_filename (filename
);
11901 add_AT_unsigned (unit_die
, DW_AT_decl_file
, file_index
);
11902 add_pubname (context_list_decl
, unit_die
);
11906 /* Output debug information for global decl DECL. Called from toplev.c after
11907 compilation proper has finished. */
11910 dwarf2out_global_decl (tree decl
)
11912 /* Output DWARF2 information for file-scope tentative data object
11913 declarations, file-scope (extern) function declarations (which had no
11914 corresponding body) and file-scope tagged type declarations and
11915 definitions which have not yet been forced out. */
11916 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
11917 dwarf2out_decl (decl
);
11920 /* Write the debugging output for DECL. */
11923 dwarf2out_decl (tree decl
)
11925 dw_die_ref context_die
= comp_unit_die
;
11927 switch (TREE_CODE (decl
))
11932 case FUNCTION_DECL
:
11933 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11934 builtin function. Explicit programmer-supplied declarations of
11935 these same functions should NOT be ignored however. */
11936 if (DECL_EXTERNAL (decl
) && DECL_BUILT_IN (decl
))
11939 /* What we would really like to do here is to filter out all mere
11940 file-scope declarations of file-scope functions which are never
11941 referenced later within this translation unit (and keep all of ones
11942 that *are* referenced later on) but we aren't clairvoyant, so we have
11943 no idea which functions will be referenced in the future (i.e. later
11944 on within the current translation unit). So here we just ignore all
11945 file-scope function declarations which are not also definitions. If
11946 and when the debugger needs to know something about these functions,
11947 it will have to hunt around and find the DWARF information associated
11948 with the definition of the function.
11950 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11951 nodes represent definitions and which ones represent mere
11952 declarations. We have to check DECL_INITIAL instead. That's because
11953 the C front-end supports some weird semantics for "extern inline"
11954 function definitions. These can get inlined within the current
11955 translation unit (an thus, we need to generate Dwarf info for their
11956 abstract instances so that the Dwarf info for the concrete inlined
11957 instances can have something to refer to) but the compiler never
11958 generates any out-of-lines instances of such things (despite the fact
11959 that they *are* definitions).
11961 The important point is that the C front-end marks these "extern
11962 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11963 them anyway. Note that the C++ front-end also plays some similar games
11964 for inline function definitions appearing within include files which
11965 also contain `#pragma interface' pragmas. */
11966 if (DECL_INITIAL (decl
) == NULL_TREE
)
11969 /* If we're a nested function, initially use a parent of NULL; if we're
11970 a plain function, this will be fixed up in decls_for_scope. If
11971 we're a method, it will be ignored, since we already have a DIE. */
11972 if (decl_function_context (decl
)
11973 /* But if we're in terse mode, we don't care about scope. */
11974 && debug_info_level
> DINFO_LEVEL_TERSE
)
11975 context_die
= NULL
;
11979 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11980 declaration and if the declaration was never even referenced from
11981 within this entire compilation unit. We suppress these DIEs in
11982 order to save space in the .debug section (by eliminating entries
11983 which are probably useless). Note that we must not suppress
11984 block-local extern declarations (whether used or not) because that
11985 would screw-up the debugger's name lookup mechanism and cause it to
11986 miss things which really ought to be in scope at a given point. */
11987 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
11990 /* If we are in terse mode, don't generate any DIEs to represent any
11991 variable declarations or definitions. */
11992 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11997 /* Don't emit stubs for types unless they are needed by other DIEs. */
11998 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
12001 /* Don't bother trying to generate any DIEs to represent any of the
12002 normal built-in types for the language we are compiling. */
12003 if (DECL_SOURCE_LINE (decl
) == 0)
12005 /* OK, we need to generate one for `bool' so GDB knows what type
12006 comparisons have. */
12007 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
12008 == DW_LANG_C_plus_plus
)
12009 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
12010 && ! DECL_IGNORED_P (decl
))
12011 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
12016 /* If we are in terse mode, don't generate any DIEs for types. */
12017 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12020 /* If we're a function-scope tag, initially use a parent of NULL;
12021 this will be fixed up in decls_for_scope. */
12022 if (decl_function_context (decl
))
12023 context_die
= NULL
;
12031 gen_decl_die (decl
, context_die
);
12034 /* Output a marker (i.e. a label) for the beginning of the generated code for
12035 a lexical block. */
12038 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
12039 unsigned int blocknum
)
12041 function_section (current_function_decl
);
12042 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
12045 /* Output a marker (i.e. a label) for the end of the generated code for a
12049 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
12051 function_section (current_function_decl
);
12052 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
12055 /* Returns nonzero if it is appropriate not to emit any debugging
12056 information for BLOCK, because it doesn't contain any instructions.
12058 Don't allow this for blocks with nested functions or local classes
12059 as we would end up with orphans, and in the presence of scheduling
12060 we may end up calling them anyway. */
12063 dwarf2out_ignore_block (tree block
)
12067 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
12068 if (TREE_CODE (decl
) == FUNCTION_DECL
12069 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
12075 /* Lookup FILE_NAME (in the list of filenames that we know about here in
12076 dwarf2out.c) and return its "index". The index of each (known) filename is
12077 just a unique number which is associated with only that one filename. We
12078 need such numbers for the sake of generating labels (in the .debug_sfnames
12079 section) and references to those files numbers (in the .debug_srcinfo
12080 and.debug_macinfo sections). If the filename given as an argument is not
12081 found in our current list, add it to the list and assign it the next
12082 available unique index number. In order to speed up searches, we remember
12083 the index of the filename was looked up last. This handles the majority of
12087 lookup_filename (const char *file_name
)
12090 char *save_file_name
;
12092 /* Check to see if the file name that was searched on the previous
12093 call matches this file name. If so, return the index. */
12094 if (file_table_last_lookup_index
!= 0)
12097 = VARRAY_CHAR_PTR (file_table
, file_table_last_lookup_index
);
12098 if (strcmp (file_name
, last
) == 0)
12099 return file_table_last_lookup_index
;
12102 /* Didn't match the previous lookup, search the table */
12103 n
= VARRAY_ACTIVE_SIZE (file_table
);
12104 for (i
= 1; i
< n
; i
++)
12105 if (strcmp (file_name
, VARRAY_CHAR_PTR (file_table
, i
)) == 0)
12107 file_table_last_lookup_index
= i
;
12111 /* Add the new entry to the end of the filename table. */
12112 file_table_last_lookup_index
= n
;
12113 save_file_name
= (char *) ggc_strdup (file_name
);
12114 VARRAY_PUSH_CHAR_PTR (file_table
, save_file_name
);
12115 VARRAY_PUSH_UINT (file_table_emitted
, 0);
12121 maybe_emit_file (int fileno
)
12123 if (DWARF2_ASM_LINE_DEBUG_INFO
&& fileno
> 0)
12125 if (!VARRAY_UINT (file_table_emitted
, fileno
))
12127 VARRAY_UINT (file_table_emitted
, fileno
) = ++emitcount
;
12128 fprintf (asm_out_file
, "\t.file %u ",
12129 VARRAY_UINT (file_table_emitted
, fileno
));
12130 output_quoted_string (asm_out_file
,
12131 VARRAY_CHAR_PTR (file_table
, fileno
));
12132 fputc ('\n', asm_out_file
);
12134 return VARRAY_UINT (file_table_emitted
, fileno
);
12141 init_file_table (void)
12143 /* Allocate the initial hunk of the file_table. */
12144 VARRAY_CHAR_PTR_INIT (file_table
, 64, "file_table");
12145 VARRAY_UINT_INIT (file_table_emitted
, 64, "file_table_emitted");
12147 /* Skip the first entry - file numbers begin at 1. */
12148 VARRAY_PUSH_CHAR_PTR (file_table
, NULL
);
12149 VARRAY_PUSH_UINT (file_table_emitted
, 0);
12150 file_table_last_lookup_index
= 0;
12153 /* Output a label to mark the beginning of a source code line entry
12154 and record information relating to this source line, in
12155 'line_info_table' for later output of the .debug_line section. */
12158 dwarf2out_source_line (unsigned int line
, const char *filename
)
12160 if (debug_info_level
>= DINFO_LEVEL_NORMAL
12163 function_section (current_function_decl
);
12165 /* If requested, emit something human-readable. */
12166 if (flag_debug_asm
)
12167 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
12170 if (DWARF2_ASM_LINE_DEBUG_INFO
)
12172 unsigned file_num
= lookup_filename (filename
);
12174 file_num
= maybe_emit_file (file_num
);
12176 /* Emit the .loc directive understood by GNU as. */
12177 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
12179 /* Indicate that line number info exists. */
12180 line_info_table_in_use
++;
12182 /* Indicate that multiple line number tables exist. */
12183 if (DECL_SECTION_NAME (current_function_decl
))
12184 separate_line_info_table_in_use
++;
12186 else if (DECL_SECTION_NAME (current_function_decl
))
12188 dw_separate_line_info_ref line_info
;
12189 (*targetm
.asm_out
.internal_label
) (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
12190 separate_line_info_table_in_use
);
12192 /* expand the line info table if necessary */
12193 if (separate_line_info_table_in_use
12194 == separate_line_info_table_allocated
)
12196 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
12197 separate_line_info_table
12198 = (dw_separate_line_info_ref
)
12199 ggc_realloc (separate_line_info_table
,
12200 separate_line_info_table_allocated
12201 * sizeof (dw_separate_line_info_entry
));
12202 memset ((separate_line_info_table
12203 + separate_line_info_table_in_use
),
12205 (LINE_INFO_TABLE_INCREMENT
12206 * sizeof (dw_separate_line_info_entry
)));
12209 /* Add the new entry at the end of the line_info_table. */
12211 = &separate_line_info_table
[separate_line_info_table_in_use
++];
12212 line_info
->dw_file_num
= lookup_filename (filename
);
12213 line_info
->dw_line_num
= line
;
12214 line_info
->function
= current_function_funcdef_no
;
12218 dw_line_info_ref line_info
;
12220 (*targetm
.asm_out
.internal_label
) (asm_out_file
, LINE_CODE_LABEL
,
12221 line_info_table_in_use
);
12223 /* Expand the line info table if necessary. */
12224 if (line_info_table_in_use
== line_info_table_allocated
)
12226 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
12228 = ggc_realloc (line_info_table
,
12229 (line_info_table_allocated
12230 * sizeof (dw_line_info_entry
)));
12231 memset (line_info_table
+ line_info_table_in_use
, 0,
12232 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
12235 /* Add the new entry at the end of the line_info_table. */
12236 line_info
= &line_info_table
[line_info_table_in_use
++];
12237 line_info
->dw_file_num
= lookup_filename (filename
);
12238 line_info
->dw_line_num
= line
;
12243 /* Record the beginning of a new source file. */
12246 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
12248 if (flag_eliminate_dwarf2_dups
&& !is_main_source
)
12250 /* Record the beginning of the file for break_out_includes. */
12251 dw_die_ref bincl_die
;
12253 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
12254 add_AT_string (bincl_die
, DW_AT_name
, filename
);
12257 is_main_source
= 0;
12259 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12261 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12262 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
12263 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
12265 maybe_emit_file (lookup_filename (filename
));
12266 dw2_asm_output_data_uleb128 (lookup_filename (filename
),
12267 "Filename we just started");
12271 /* Record the end of a source file. */
12274 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
12276 if (flag_eliminate_dwarf2_dups
)
12277 /* Record the end of the file for break_out_includes. */
12278 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
12280 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12282 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12283 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
12287 /* Called from debug_define in toplev.c. The `buffer' parameter contains
12288 the tail part of the directive line, i.e. the part which is past the
12289 initial whitespace, #, whitespace, directive-name, whitespace part. */
12292 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
12293 const char *buffer ATTRIBUTE_UNUSED
)
12295 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12297 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12298 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
12299 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
12300 dw2_asm_output_nstring (buffer
, -1, "The macro");
12304 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
12305 the tail part of the directive line, i.e. the part which is past the
12306 initial whitespace, #, whitespace, directive-name, whitespace part. */
12309 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
12310 const char *buffer ATTRIBUTE_UNUSED
)
12312 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12314 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12315 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
12316 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
12317 dw2_asm_output_nstring (buffer
, -1, "The macro");
12321 /* Set up for Dwarf output at the start of compilation. */
12324 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
12326 init_file_table ();
12328 /* Allocate the initial hunk of the decl_die_table. */
12329 decl_die_table
= ggc_alloc_cleared (DECL_DIE_TABLE_INCREMENT
12330 * sizeof (dw_die_ref
));
12331 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
12332 decl_die_table_in_use
= 0;
12334 /* Allocate the initial hunk of the decl_scope_table. */
12335 VARRAY_TREE_INIT (decl_scope_table
, 256, "decl_scope_table");
12337 /* Allocate the initial hunk of the abbrev_die_table. */
12338 abbrev_die_table
= ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
12339 * sizeof (dw_die_ref
));
12340 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
12341 /* Zero-th entry is allocated, but unused */
12342 abbrev_die_table_in_use
= 1;
12344 /* Allocate the initial hunk of the line_info_table. */
12345 line_info_table
= ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
12346 * sizeof (dw_line_info_entry
));
12347 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
12349 /* Zero-th entry is allocated, but unused */
12350 line_info_table_in_use
= 1;
12352 /* Generate the initial DIE for the .debug section. Note that the (string)
12353 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12354 will (typically) be a relative pathname and that this pathname should be
12355 taken as being relative to the directory from which the compiler was
12356 invoked when the given (base) source file was compiled. We will fill
12357 in this value in dwarf2out_finish. */
12358 comp_unit_die
= gen_compile_unit_die (NULL
);
12359 is_main_source
= 1;
12361 VARRAY_TREE_INIT (incomplete_types
, 64, "incomplete_types");
12363 VARRAY_RTX_INIT (used_rtx_varray
, 32, "used_rtx_varray");
12365 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
12366 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
12367 DEBUG_ABBREV_SECTION_LABEL
, 0);
12368 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12369 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
12371 strcpy (text_section_label
, stripattributes (TEXT_SECTION_NAME
));
12373 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
12374 DEBUG_INFO_SECTION_LABEL
, 0);
12375 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
12376 DEBUG_LINE_SECTION_LABEL
, 0);
12377 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
12378 DEBUG_RANGES_SECTION_LABEL
, 0);
12379 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12380 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
12381 named_section_flags (DEBUG_INFO_SECTION
, SECTION_DEBUG
);
12382 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
12383 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12384 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
12386 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12388 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12389 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
12390 DEBUG_MACINFO_SECTION_LABEL
, 0);
12391 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
12394 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12397 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
12401 /* A helper function for dwarf2out_finish called through
12402 ht_forall. Emit one queued .debug_str string. */
12405 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
12407 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
12409 if (node
->form
== DW_FORM_strp
)
12411 named_section_flags (DEBUG_STR_SECTION
, DEBUG_STR_SECTION_FLAGS
);
12412 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
12413 assemble_string (node
->str
, strlen (node
->str
) + 1);
12421 /* Clear the marks for a die and its children.
12422 Be cool if the mark isn't set. */
12425 prune_unmark_dies (dw_die_ref die
)
12429 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
12430 prune_unmark_dies (c
);
12434 /* Given DIE that we're marking as used, find any other dies
12435 it references as attributes and mark them as used. */
12438 prune_unused_types_walk_attribs (dw_die_ref die
)
12442 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
12444 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
12446 /* A reference to another DIE.
12447 Make sure that it will get emitted. */
12448 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
12450 else if (a
->dw_attr
== DW_AT_decl_file
)
12452 /* A reference to a file. Make sure the file name is emitted. */
12453 a
->dw_attr_val
.v
.val_unsigned
=
12454 maybe_emit_file (a
->dw_attr_val
.v
.val_unsigned
);
12460 /* Mark DIE as being used. If DOKIDS is true, then walk down
12461 to DIE's children. */
12464 prune_unused_types_mark (dw_die_ref die
, int dokids
)
12468 if (die
->die_mark
== 0)
12470 /* We haven't done this node yet. Mark it as used. */
12473 /* We also have to mark its parents as used.
12474 (But we don't want to mark our parents' kids due to this.) */
12475 if (die
->die_parent
)
12476 prune_unused_types_mark (die
->die_parent
, 0);
12478 /* Mark any referenced nodes. */
12479 prune_unused_types_walk_attribs (die
);
12482 if (dokids
&& die
->die_mark
!= 2)
12484 /* We need to walk the children, but haven't done so yet.
12485 Remember that we've walked the kids. */
12489 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
12491 /* If this is an array type, we need to make sure our
12492 kids get marked, even if they're types. */
12493 if (die
->die_tag
== DW_TAG_array_type
)
12494 prune_unused_types_mark (c
, 1);
12496 prune_unused_types_walk (c
);
12502 /* Walk the tree DIE and mark types that we actually use. */
12505 prune_unused_types_walk (dw_die_ref die
)
12509 /* Don't do anything if this node is already marked. */
12513 switch (die
->die_tag
) {
12514 case DW_TAG_const_type
:
12515 case DW_TAG_packed_type
:
12516 case DW_TAG_pointer_type
:
12517 case DW_TAG_reference_type
:
12518 case DW_TAG_volatile_type
:
12519 case DW_TAG_typedef
:
12520 case DW_TAG_array_type
:
12521 case DW_TAG_structure_type
:
12522 case DW_TAG_union_type
:
12523 case DW_TAG_class_type
:
12524 case DW_TAG_friend
:
12525 case DW_TAG_variant_part
:
12526 case DW_TAG_enumeration_type
:
12527 case DW_TAG_subroutine_type
:
12528 case DW_TAG_string_type
:
12529 case DW_TAG_set_type
:
12530 case DW_TAG_subrange_type
:
12531 case DW_TAG_ptr_to_member_type
:
12532 case DW_TAG_file_type
:
12533 /* It's a type node --- don't mark it. */
12537 /* Mark everything else. */
12543 /* Now, mark any dies referenced from here. */
12544 prune_unused_types_walk_attribs (die
);
12546 /* Mark children. */
12547 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
12548 prune_unused_types_walk (c
);
12552 /* Remove from the tree DIE any dies that aren't marked. */
12555 prune_unused_types_prune (dw_die_ref die
)
12557 dw_die_ref c
, p
, n
;
12558 if (!die
->die_mark
)
12562 for (c
= die
->die_child
; c
; c
= n
)
12567 prune_unused_types_prune (c
);
12575 die
->die_child
= n
;
12582 /* Remove dies representing declarations that we never use. */
12585 prune_unused_types (void)
12588 limbo_die_node
*node
;
12590 /* Clear all the marks. */
12591 prune_unmark_dies (comp_unit_die
);
12592 for (node
= limbo_die_list
; node
; node
= node
->next
)
12593 prune_unmark_dies (node
->die
);
12595 /* Set the mark on nodes that are actually used. */
12596 prune_unused_types_walk (comp_unit_die
);
12597 for (node
= limbo_die_list
; node
; node
= node
->next
)
12598 prune_unused_types_walk (node
->die
);
12600 /* Also set the mark on nodes referenced from the
12601 pubname_table or arange_table. */
12602 for (i
= 0; i
< pubname_table_in_use
; i
++)
12603 prune_unused_types_mark (pubname_table
[i
].die
, 1);
12604 for (i
= 0; i
< arange_table_in_use
; i
++)
12605 prune_unused_types_mark (arange_table
[i
], 1);
12607 /* Get rid of nodes that aren't marked. */
12608 prune_unused_types_prune (comp_unit_die
);
12609 for (node
= limbo_die_list
; node
; node
= node
->next
)
12610 prune_unused_types_prune (node
->die
);
12612 /* Leave the marks clear. */
12613 prune_unmark_dies (comp_unit_die
);
12614 for (node
= limbo_die_list
; node
; node
= node
->next
)
12615 prune_unmark_dies (node
->die
);
12618 /* Output stuff that dwarf requires at the end of every file,
12619 and generate the DWARF-2 debugging info. */
12622 dwarf2out_finish (const char *filename
)
12624 limbo_die_node
*node
, *next_node
;
12625 dw_die_ref die
= 0;
12627 /* Add the name for the main input file now. We delayed this from
12628 dwarf2out_init to avoid complications with PCH. */
12629 add_name_attribute (comp_unit_die
, filename
);
12630 if (filename
[0] != DIR_SEPARATOR
)
12631 add_comp_dir_attribute (comp_unit_die
);
12632 else if (get_AT (comp_unit_die
, DW_AT_comp_dir
) == NULL
)
12635 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
12636 if (VARRAY_CHAR_PTR (file_table
, i
)[0] != DIR_SEPARATOR
12637 /* Don't add cwd for <built-in>. */
12638 && VARRAY_CHAR_PTR (file_table
, i
)[0] != '<')
12640 add_comp_dir_attribute (comp_unit_die
);
12645 /* Traverse the limbo die list, and add parent/child links. The only
12646 dies without parents that should be here are concrete instances of
12647 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12648 For concrete instances, we can get the parent die from the abstract
12650 for (node
= limbo_die_list
; node
; node
= next_node
)
12652 next_node
= node
->next
;
12655 if (die
->die_parent
== NULL
)
12657 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
12661 add_child_die (origin
->die_parent
, die
);
12662 else if (die
== comp_unit_die
)
12664 /* If this was an expression for a bound involved in a function
12665 return type, it may be a SAVE_EXPR for which we weren't able
12666 to find a DIE previously. So try now. */
12667 else if (node
->created_for
12668 && TREE_CODE (node
->created_for
) == SAVE_EXPR
12669 && 0 != (origin
= (lookup_decl_die
12671 (node
->created_for
)))))
12672 add_child_die (origin
, die
);
12673 else if (errorcount
> 0 || sorrycount
> 0)
12674 /* It's OK to be confused by errors in the input. */
12675 add_child_die (comp_unit_die
, die
);
12676 else if (node
->created_for
12677 && ((DECL_P (node
->created_for
)
12678 && (context
= DECL_CONTEXT (node
->created_for
)))
12679 || (TYPE_P (node
->created_for
)
12680 && (context
= TYPE_CONTEXT (node
->created_for
))))
12681 && TREE_CODE (context
) == FUNCTION_DECL
)
12683 /* In certain situations, the lexical block containing a
12684 nested function can be optimized away, which results
12685 in the nested function die being orphaned. Likewise
12686 with the return type of that nested function. Force
12687 this to be a child of the containing function. */
12688 origin
= lookup_decl_die (context
);
12691 add_child_die (origin
, die
);
12698 limbo_die_list
= NULL
;
12700 /* Walk through the list of incomplete types again, trying once more to
12701 emit full debugging info for them. */
12702 retry_incomplete_types ();
12704 /* We need to reverse all the dies before break_out_includes, or
12705 we'll see the end of an include file before the beginning. */
12706 reverse_all_dies (comp_unit_die
);
12708 if (flag_eliminate_unused_debug_types
)
12709 prune_unused_types ();
12711 /* Generate separate CUs for each of the include files we've seen.
12712 They will go into limbo_die_list. */
12713 if (flag_eliminate_dwarf2_dups
)
12714 break_out_includes (comp_unit_die
);
12716 /* Traverse the DIE's and add add sibling attributes to those DIE's
12717 that have children. */
12718 add_sibling_attributes (comp_unit_die
);
12719 for (node
= limbo_die_list
; node
; node
= node
->next
)
12720 add_sibling_attributes (node
->die
);
12722 /* Output a terminator label for the .text section. */
12724 (*targetm
.asm_out
.internal_label
) (asm_out_file
, TEXT_END_LABEL
, 0);
12726 /* Output the source line correspondence table. We must do this
12727 even if there is no line information. Otherwise, on an empty
12728 translation unit, we will generate a present, but empty,
12729 .debug_info section. IRIX 6.5 `nm' will then complain when
12730 examining the file. */
12731 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
12733 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12734 output_line_info ();
12737 /* Output location list section if necessary. */
12738 if (have_location_lists
)
12740 /* Output the location lists info. */
12741 named_section_flags (DEBUG_LOC_SECTION
, SECTION_DEBUG
);
12742 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
12743 DEBUG_LOC_SECTION_LABEL
, 0);
12744 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
12745 output_location_lists (die
);
12746 have_location_lists
= 0;
12749 /* We can only use the low/high_pc attributes if all of the code was
12751 if (separate_line_info_table_in_use
== 0)
12753 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
12754 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
12757 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12758 "base address". Use zero so that these addresses become absolute. */
12759 else if (have_location_lists
|| ranges_table_in_use
)
12760 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
12762 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
12763 add_AT_lbl_offset (comp_unit_die
, DW_AT_stmt_list
,
12764 debug_line_section_label
);
12766 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12767 add_AT_lbl_offset (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
12769 /* Output all of the compilation units. We put the main one last so that
12770 the offsets are available to output_pubnames. */
12771 for (node
= limbo_die_list
; node
; node
= node
->next
)
12772 output_comp_unit (node
->die
, 0);
12774 output_comp_unit (comp_unit_die
, 0);
12776 /* Output the abbreviation table. */
12777 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12778 output_abbrev_section ();
12780 /* Output public names table if necessary. */
12781 if (pubname_table_in_use
)
12783 named_section_flags (DEBUG_PUBNAMES_SECTION
, SECTION_DEBUG
);
12784 output_pubnames ();
12787 /* Output the address range information. We only put functions in the arange
12788 table, so don't write it out if we don't have any. */
12789 if (fde_table_in_use
)
12791 named_section_flags (DEBUG_ARANGES_SECTION
, SECTION_DEBUG
);
12795 /* Output ranges section if necessary. */
12796 if (ranges_table_in_use
)
12798 named_section_flags (DEBUG_RANGES_SECTION
, SECTION_DEBUG
);
12799 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
12803 /* Have to end the primary source file. */
12804 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12806 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12807 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
12808 dw2_asm_output_data (1, 0, "End compilation unit");
12811 /* If we emitted any DW_FORM_strp form attribute, output the string
12813 if (debug_str_hash
)
12814 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
12818 /* This should never be used, but its address is needed for comparisons. */
12819 const struct gcc_debug_hooks dwarf2_debug_hooks
;
12821 #endif /* DWARF2_DEBUGGING_INFO */
12823 #include "gt-dwarf2out.h"