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 enum machine_mode save_mode
= reg_raw_mode
[i
];
454 if (HARD_REGNO_CALL_PART_CLOBBERED (i
, save_mode
))
455 save_mode
= choose_hard_reg_mode (i
, 1, true);
456 size
= GET_MODE_SIZE (save_mode
);
460 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
464 /* Convert a DWARF call frame info. operation to its string name */
467 dwarf_cfi_name (unsigned int cfi_opc
)
471 case DW_CFA_advance_loc
:
472 return "DW_CFA_advance_loc";
474 return "DW_CFA_offset";
476 return "DW_CFA_restore";
480 return "DW_CFA_set_loc";
481 case DW_CFA_advance_loc1
:
482 return "DW_CFA_advance_loc1";
483 case DW_CFA_advance_loc2
:
484 return "DW_CFA_advance_loc2";
485 case DW_CFA_advance_loc4
:
486 return "DW_CFA_advance_loc4";
487 case DW_CFA_offset_extended
:
488 return "DW_CFA_offset_extended";
489 case DW_CFA_restore_extended
:
490 return "DW_CFA_restore_extended";
491 case DW_CFA_undefined
:
492 return "DW_CFA_undefined";
493 case DW_CFA_same_value
:
494 return "DW_CFA_same_value";
495 case DW_CFA_register
:
496 return "DW_CFA_register";
497 case DW_CFA_remember_state
:
498 return "DW_CFA_remember_state";
499 case DW_CFA_restore_state
:
500 return "DW_CFA_restore_state";
502 return "DW_CFA_def_cfa";
503 case DW_CFA_def_cfa_register
:
504 return "DW_CFA_def_cfa_register";
505 case DW_CFA_def_cfa_offset
:
506 return "DW_CFA_def_cfa_offset";
509 case DW_CFA_def_cfa_expression
:
510 return "DW_CFA_def_cfa_expression";
511 case DW_CFA_expression
:
512 return "DW_CFA_expression";
513 case DW_CFA_offset_extended_sf
:
514 return "DW_CFA_offset_extended_sf";
515 case DW_CFA_def_cfa_sf
:
516 return "DW_CFA_def_cfa_sf";
517 case DW_CFA_def_cfa_offset_sf
:
518 return "DW_CFA_def_cfa_offset_sf";
520 /* SGI/MIPS specific */
521 case DW_CFA_MIPS_advance_loc8
:
522 return "DW_CFA_MIPS_advance_loc8";
525 case DW_CFA_GNU_window_save
:
526 return "DW_CFA_GNU_window_save";
527 case DW_CFA_GNU_args_size
:
528 return "DW_CFA_GNU_args_size";
529 case DW_CFA_GNU_negative_offset_extended
:
530 return "DW_CFA_GNU_negative_offset_extended";
533 return "DW_CFA_<unknown>";
537 /* Return a pointer to a newly allocated Call Frame Instruction. */
539 static inline dw_cfi_ref
542 dw_cfi_ref cfi
= (dw_cfi_ref
) ggc_alloc (sizeof (dw_cfi_node
));
544 cfi
->dw_cfi_next
= NULL
;
545 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
546 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
551 /* Add a Call Frame Instruction to list of instructions. */
554 add_cfi (dw_cfi_ref
*list_head
, dw_cfi_ref cfi
)
558 /* Find the end of the chain. */
559 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
565 /* Generate a new label for the CFI info to refer to. */
568 dwarf2out_cfi_label (void)
570 static char label
[20];
572 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", dwarf2out_cfi_label_num
++);
573 ASM_OUTPUT_LABEL (asm_out_file
, label
);
577 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
578 or to the CIE if LABEL is NULL. */
581 add_fde_cfi (const char *label
, dw_cfi_ref cfi
)
585 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
588 label
= dwarf2out_cfi_label ();
590 if (fde
->dw_fde_current_label
== NULL
591 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
595 fde
->dw_fde_current_label
= label
= xstrdup (label
);
597 /* Set the location counter to the new label. */
599 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
600 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
601 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
604 add_cfi (&fde
->dw_fde_cfi
, cfi
);
608 add_cfi (&cie_cfi_head
, cfi
);
611 /* Subroutine of lookup_cfa. */
614 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
)
616 switch (cfi
->dw_cfi_opc
)
618 case DW_CFA_def_cfa_offset
:
619 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
621 case DW_CFA_def_cfa_register
:
622 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
625 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
626 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
628 case DW_CFA_def_cfa_expression
:
629 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
636 /* Find the previous value for the CFA. */
639 lookup_cfa (dw_cfa_location
*loc
)
643 loc
->reg
= (unsigned long) -1;
646 loc
->base_offset
= 0;
648 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
649 lookup_cfa_1 (cfi
, loc
);
651 if (fde_table_in_use
)
653 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
654 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
655 lookup_cfa_1 (cfi
, loc
);
659 /* The current rule for calculating the DWARF2 canonical frame address. */
660 static dw_cfa_location cfa
;
662 /* The register used for saving registers to the stack, and its offset
664 static dw_cfa_location cfa_store
;
666 /* The running total of the size of arguments pushed onto the stack. */
667 static long args_size
;
669 /* The last args_size we actually output. */
670 static long old_args_size
;
672 /* Entry point to update the canonical frame address (CFA).
673 LABEL is passed to add_fde_cfi. The value of CFA is now to be
674 calculated from REG+OFFSET. */
677 dwarf2out_def_cfa (const char *label
, unsigned int reg
, long int offset
)
684 def_cfa_1 (label
, &loc
);
687 /* This routine does the actual work. The CFA is now calculated from
688 the dw_cfa_location structure. */
691 def_cfa_1 (const char *label
, dw_cfa_location
*loc_p
)
694 dw_cfa_location old_cfa
, loc
;
699 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
700 cfa_store
.offset
= loc
.offset
;
702 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
703 lookup_cfa (&old_cfa
);
705 /* If nothing changed, no need to issue any call frame instructions. */
706 if (loc
.reg
== old_cfa
.reg
&& loc
.offset
== old_cfa
.offset
707 && loc
.indirect
== old_cfa
.indirect
708 && (loc
.indirect
== 0 || loc
.base_offset
== old_cfa
.base_offset
))
713 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
715 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
716 indicating the CFA register did not change but the offset
718 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
719 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
722 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
723 else if (loc
.offset
== old_cfa
.offset
&& old_cfa
.reg
!= (unsigned long) -1
726 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
727 indicating the CFA register has changed to <register> but the
728 offset has not changed. */
729 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
730 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
734 else if (loc
.indirect
== 0)
736 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
737 indicating the CFA register has changed to <register> with
738 the specified offset. */
739 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
740 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
741 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
745 /* Construct a DW_CFA_def_cfa_expression instruction to
746 calculate the CFA using a full location expression since no
747 register-offset pair is available. */
748 struct dw_loc_descr_struct
*loc_list
;
750 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
751 loc_list
= build_cfa_loc (&loc
);
752 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
755 add_fde_cfi (label
, cfi
);
758 /* Add the CFI for saving a register. REG is the CFA column number.
759 LABEL is passed to add_fde_cfi.
760 If SREG is -1, the register is saved at OFFSET from the CFA;
761 otherwise it is saved in SREG. */
764 reg_save (const char *label
, unsigned int reg
, unsigned int sreg
, long int offset
)
766 dw_cfi_ref cfi
= new_cfi ();
768 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
770 /* The following comparison is correct. -1 is used to indicate that
771 the value isn't a register number. */
772 if (sreg
== (unsigned int) -1)
775 /* The register number won't fit in 6 bits, so we have to use
777 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
779 cfi
->dw_cfi_opc
= DW_CFA_offset
;
781 #ifdef ENABLE_CHECKING
783 /* If we get an offset that is not a multiple of
784 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
785 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
787 long check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
789 if (check_offset
* DWARF_CIE_DATA_ALIGNMENT
!= offset
)
793 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
795 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
797 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
799 else if (sreg
== reg
)
800 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
804 cfi
->dw_cfi_opc
= DW_CFA_register
;
805 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
808 add_fde_cfi (label
, cfi
);
811 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
812 This CFI tells the unwinder that it needs to restore the window registers
813 from the previous frame's window save area.
815 ??? Perhaps we should note in the CIE where windows are saved (instead of
816 assuming 0(cfa)) and what registers are in the window. */
819 dwarf2out_window_save (const char *label
)
821 dw_cfi_ref cfi
= new_cfi ();
823 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
824 add_fde_cfi (label
, cfi
);
827 /* Add a CFI to update the running total of the size of arguments
828 pushed onto the stack. */
831 dwarf2out_args_size (const char *label
, long int size
)
835 if (size
== old_args_size
)
838 old_args_size
= size
;
841 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
842 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
843 add_fde_cfi (label
, cfi
);
846 /* Entry point for saving a register to the stack. REG is the GCC register
847 number. LABEL and OFFSET are passed to reg_save. */
850 dwarf2out_reg_save (const char *label
, unsigned int reg
, long int offset
)
852 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
855 /* Entry point for saving the return address in the stack.
856 LABEL and OFFSET are passed to reg_save. */
859 dwarf2out_return_save (const char *label
, long int offset
)
861 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, -1, offset
);
864 /* Entry point for saving the return address in a register.
865 LABEL and SREG are passed to reg_save. */
868 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
870 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, sreg
, 0);
873 /* Record the initial position of the return address. RTL is
874 INCOMING_RETURN_ADDR_RTX. */
877 initial_return_save (rtx rtl
)
879 unsigned int reg
= (unsigned int) -1;
880 HOST_WIDE_INT offset
= 0;
882 switch (GET_CODE (rtl
))
885 /* RA is in a register. */
886 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
890 /* RA is on the stack. */
892 switch (GET_CODE (rtl
))
895 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
901 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
903 offset
= INTVAL (XEXP (rtl
, 1));
907 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
909 offset
= -INTVAL (XEXP (rtl
, 1));
919 /* The return address is at some offset from any value we can
920 actually load. For instance, on the SPARC it is in %i7+8. Just
921 ignore the offset for now; it doesn't matter for unwinding frames. */
922 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
924 initial_return_save (XEXP (rtl
, 0));
931 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
934 /* Given a SET, calculate the amount of stack adjustment it
938 stack_adjust_offset (rtx pattern
)
940 rtx src
= SET_SRC (pattern
);
941 rtx dest
= SET_DEST (pattern
);
942 HOST_WIDE_INT offset
= 0;
945 if (dest
== stack_pointer_rtx
)
947 /* (set (reg sp) (plus (reg sp) (const_int))) */
948 code
= GET_CODE (src
);
949 if (! (code
== PLUS
|| code
== MINUS
)
950 || XEXP (src
, 0) != stack_pointer_rtx
951 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
954 offset
= INTVAL (XEXP (src
, 1));
958 else if (GET_CODE (dest
) == MEM
)
960 /* (set (mem (pre_dec (reg sp))) (foo)) */
961 src
= XEXP (dest
, 0);
962 code
= GET_CODE (src
);
968 if (XEXP (src
, 0) == stack_pointer_rtx
)
970 rtx val
= XEXP (XEXP (src
, 1), 1);
971 /* We handle only adjustments by constant amount. */
972 if (GET_CODE (XEXP (src
, 1)) != PLUS
||
973 GET_CODE (val
) != CONST_INT
)
975 offset
= -INTVAL (val
);
982 if (XEXP (src
, 0) == stack_pointer_rtx
)
984 offset
= GET_MODE_SIZE (GET_MODE (dest
));
991 if (XEXP (src
, 0) == stack_pointer_rtx
)
993 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1008 /* Check INSN to see if it looks like a push or a stack adjustment, and
1009 make a note of it if it does. EH uses this information to find out how
1010 much extra space it needs to pop off the stack. */
1013 dwarf2out_stack_adjust (rtx insn
)
1015 HOST_WIDE_INT offset
;
1019 if (!flag_asynchronous_unwind_tables
&& GET_CODE (insn
) == CALL_INSN
)
1021 /* Extract the size of the args from the CALL rtx itself. */
1022 insn
= PATTERN (insn
);
1023 if (GET_CODE (insn
) == PARALLEL
)
1024 insn
= XVECEXP (insn
, 0, 0);
1025 if (GET_CODE (insn
) == SET
)
1026 insn
= SET_SRC (insn
);
1027 if (GET_CODE (insn
) != CALL
)
1030 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1034 /* If only calls can throw, and we have a frame pointer,
1035 save up adjustments until we see the CALL_INSN. */
1036 else if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1039 if (GET_CODE (insn
) == BARRIER
)
1041 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1042 the compiler will have already emitted a stack adjustment, but
1043 doesn't bother for calls to noreturn functions. */
1044 #ifdef STACK_GROWS_DOWNWARD
1045 offset
= -args_size
;
1050 else if (GET_CODE (PATTERN (insn
)) == SET
)
1051 offset
= stack_adjust_offset (PATTERN (insn
));
1052 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1053 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1055 /* There may be stack adjustments inside compound insns. Search
1057 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1058 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1059 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1067 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1068 cfa
.offset
+= offset
;
1070 #ifndef STACK_GROWS_DOWNWARD
1074 args_size
+= offset
;
1078 label
= dwarf2out_cfi_label ();
1079 def_cfa_1 (label
, &cfa
);
1080 dwarf2out_args_size (label
, args_size
);
1085 /* We delay emitting a register save until either (a) we reach the end
1086 of the prologue or (b) the register is clobbered. This clusters
1087 register saves so that there are fewer pc advances. */
1089 struct queued_reg_save
GTY(())
1091 struct queued_reg_save
*next
;
1096 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1098 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1099 static const char *last_reg_save_label
;
1102 queue_reg_save (const char *label
, rtx reg
, long int offset
)
1104 struct queued_reg_save
*q
= ggc_alloc (sizeof (*q
));
1106 q
->next
= queued_reg_saves
;
1108 q
->cfa_offset
= offset
;
1109 queued_reg_saves
= q
;
1111 last_reg_save_label
= label
;
1115 flush_queued_reg_saves (void)
1117 struct queued_reg_save
*q
, *next
;
1119 for (q
= queued_reg_saves
; q
; q
= next
)
1121 dwarf2out_reg_save (last_reg_save_label
, REGNO (q
->reg
), q
->cfa_offset
);
1125 queued_reg_saves
= NULL
;
1126 last_reg_save_label
= NULL
;
1130 clobbers_queued_reg_save (rtx insn
)
1132 struct queued_reg_save
*q
;
1134 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1135 if (modified_in_p (q
->reg
, insn
))
1142 /* A temporary register holding an integral value used in adjusting SP
1143 or setting up the store_reg. The "offset" field holds the integer
1144 value, not an offset. */
1145 static dw_cfa_location cfa_temp
;
1147 /* Record call frame debugging information for an expression EXPR,
1148 which either sets SP or FP (adjusting how we calculate the frame
1149 address) or saves a register to the stack. LABEL indicates the
1152 This function encodes a state machine mapping rtxes to actions on
1153 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1154 users need not read the source code.
1156 The High-Level Picture
1158 Changes in the register we use to calculate the CFA: Currently we
1159 assume that if you copy the CFA register into another register, we
1160 should take the other one as the new CFA register; this seems to
1161 work pretty well. If it's wrong for some target, it's simple
1162 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1164 Changes in the register we use for saving registers to the stack:
1165 This is usually SP, but not always. Again, we deduce that if you
1166 copy SP into another register (and SP is not the CFA register),
1167 then the new register is the one we will be using for register
1168 saves. This also seems to work.
1170 Register saves: There's not much guesswork about this one; if
1171 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1172 register save, and the register used to calculate the destination
1173 had better be the one we think we're using for this purpose.
1175 Except: If the register being saved is the CFA register, and the
1176 offset is nonzero, we are saving the CFA, so we assume we have to
1177 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1178 the intent is to save the value of SP from the previous frame.
1180 Invariants / Summaries of Rules
1182 cfa current rule for calculating the CFA. It usually
1183 consists of a register and an offset.
1184 cfa_store register used by prologue code to save things to the stack
1185 cfa_store.offset is the offset from the value of
1186 cfa_store.reg to the actual CFA
1187 cfa_temp register holding an integral value. cfa_temp.offset
1188 stores the value, which will be used to adjust the
1189 stack pointer. cfa_temp is also used like cfa_store,
1190 to track stores to the stack via fp or a temp reg.
1192 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1193 with cfa.reg as the first operand changes the cfa.reg and its
1194 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1197 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1198 expression yielding a constant. This sets cfa_temp.reg
1199 and cfa_temp.offset.
1201 Rule 5: Create a new register cfa_store used to save items to the
1204 Rules 10-14: Save a register to the stack. Define offset as the
1205 difference of the original location and cfa_store's
1206 location (or cfa_temp's location if cfa_temp is used).
1210 "{a,b}" indicates a choice of a xor b.
1211 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1214 (set <reg1> <reg2>:cfa.reg)
1215 effects: cfa.reg = <reg1>
1216 cfa.offset unchanged
1217 cfa_temp.reg = <reg1>
1218 cfa_temp.offset = cfa.offset
1221 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1222 {<const_int>,<reg>:cfa_temp.reg}))
1223 effects: cfa.reg = sp if fp used
1224 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1225 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1226 if cfa_store.reg==sp
1229 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1230 effects: cfa.reg = fp
1231 cfa_offset += +/- <const_int>
1234 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1235 constraints: <reg1> != fp
1237 effects: cfa.reg = <reg1>
1238 cfa_temp.reg = <reg1>
1239 cfa_temp.offset = cfa.offset
1242 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1243 constraints: <reg1> != fp
1245 effects: cfa_store.reg = <reg1>
1246 cfa_store.offset = cfa.offset - cfa_temp.offset
1249 (set <reg> <const_int>)
1250 effects: cfa_temp.reg = <reg>
1251 cfa_temp.offset = <const_int>
1254 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1255 effects: cfa_temp.reg = <reg1>
1256 cfa_temp.offset |= <const_int>
1259 (set <reg> (high <exp>))
1263 (set <reg> (lo_sum <exp> <const_int>))
1264 effects: cfa_temp.reg = <reg>
1265 cfa_temp.offset = <const_int>
1268 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1269 effects: cfa_store.offset -= <const_int>
1270 cfa.offset = cfa_store.offset if cfa.reg == sp
1272 cfa.base_offset = -cfa_store.offset
1275 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1276 effects: cfa_store.offset += -/+ mode_size(mem)
1277 cfa.offset = cfa_store.offset if cfa.reg == sp
1279 cfa.base_offset = -cfa_store.offset
1282 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1285 effects: cfa.reg = <reg1>
1286 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1289 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1290 effects: cfa.reg = <reg1>
1291 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1294 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1295 effects: cfa.reg = <reg1>
1296 cfa.base_offset = -cfa_temp.offset
1297 cfa_temp.offset -= mode_size(mem) */
1300 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
1303 HOST_WIDE_INT offset
;
1305 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1306 the PARALLEL independently. The first element is always processed if
1307 it is a SET. This is for backward compatibility. Other elements
1308 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1309 flag is set in them. */
1310 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1313 int limit
= XVECLEN (expr
, 0);
1315 for (par_index
= 0; par_index
< limit
; par_index
++)
1316 if (GET_CODE (XVECEXP (expr
, 0, par_index
)) == SET
1317 && (RTX_FRAME_RELATED_P (XVECEXP (expr
, 0, par_index
))
1319 dwarf2out_frame_debug_expr (XVECEXP (expr
, 0, par_index
), label
);
1324 if (GET_CODE (expr
) != SET
)
1327 src
= SET_SRC (expr
);
1328 dest
= SET_DEST (expr
);
1330 switch (GET_CODE (dest
))
1334 /* Update the CFA rule wrt SP or FP. Make sure src is
1335 relative to the current CFA register. */
1336 switch (GET_CODE (src
))
1338 /* Setting FP from SP. */
1340 if (cfa
.reg
== (unsigned) REGNO (src
))
1346 /* We used to require that dest be either SP or FP, but the
1347 ARM copies SP to a temporary register, and from there to
1348 FP. So we just rely on the backends to only set
1349 RTX_FRAME_RELATED_P on appropriate insns. */
1350 cfa
.reg
= REGNO (dest
);
1351 cfa_temp
.reg
= cfa
.reg
;
1352 cfa_temp
.offset
= cfa
.offset
;
1358 if (dest
== stack_pointer_rtx
)
1362 switch (GET_CODE (XEXP (src
, 1)))
1365 offset
= INTVAL (XEXP (src
, 1));
1368 if ((unsigned) REGNO (XEXP (src
, 1)) != cfa_temp
.reg
)
1370 offset
= cfa_temp
.offset
;
1376 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1378 /* Restoring SP from FP in the epilogue. */
1379 if (cfa
.reg
!= (unsigned) HARD_FRAME_POINTER_REGNUM
)
1381 cfa
.reg
= STACK_POINTER_REGNUM
;
1383 else if (GET_CODE (src
) == LO_SUM
)
1384 /* Assume we've set the source reg of the LO_SUM from sp. */
1386 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1389 if (GET_CODE (src
) != MINUS
)
1391 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1392 cfa
.offset
+= offset
;
1393 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1394 cfa_store
.offset
+= offset
;
1396 else if (dest
== hard_frame_pointer_rtx
)
1399 /* Either setting the FP from an offset of the SP,
1400 or adjusting the FP */
1401 if (! frame_pointer_needed
)
1404 if (GET_CODE (XEXP (src
, 0)) == REG
1405 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1406 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1408 offset
= INTVAL (XEXP (src
, 1));
1409 if (GET_CODE (src
) != MINUS
)
1411 cfa
.offset
+= offset
;
1412 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1419 if (GET_CODE (src
) == MINUS
)
1423 if (GET_CODE (XEXP (src
, 0)) == REG
1424 && REGNO (XEXP (src
, 0)) == cfa
.reg
1425 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1427 /* Setting a temporary CFA register that will be copied
1428 into the FP later on. */
1429 offset
= - INTVAL (XEXP (src
, 1));
1430 cfa
.offset
+= offset
;
1431 cfa
.reg
= REGNO (dest
);
1432 /* Or used to save regs to the stack. */
1433 cfa_temp
.reg
= cfa
.reg
;
1434 cfa_temp
.offset
= cfa
.offset
;
1438 else if (GET_CODE (XEXP (src
, 0)) == REG
1439 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1440 && XEXP (src
, 1) == stack_pointer_rtx
)
1442 /* Setting a scratch register that we will use instead
1443 of SP for saving registers to the stack. */
1444 if (cfa
.reg
!= STACK_POINTER_REGNUM
)
1446 cfa_store
.reg
= REGNO (dest
);
1447 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
1451 else if (GET_CODE (src
) == LO_SUM
1452 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1454 cfa_temp
.reg
= REGNO (dest
);
1455 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
1464 cfa_temp
.reg
= REGNO (dest
);
1465 cfa_temp
.offset
= INTVAL (src
);
1470 if (GET_CODE (XEXP (src
, 0)) != REG
1471 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp
.reg
1472 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1475 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
1476 cfa_temp
.reg
= REGNO (dest
);
1477 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
1480 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1481 which will fill in all of the bits. */
1490 def_cfa_1 (label
, &cfa
);
1494 if (GET_CODE (src
) != REG
)
1497 /* Saving a register to the stack. Make sure dest is relative to the
1499 switch (GET_CODE (XEXP (dest
, 0)))
1504 /* We can't handle variable size modifications. */
1505 if (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1)) != CONST_INT
)
1507 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1509 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1510 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1513 cfa_store
.offset
+= offset
;
1514 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1515 cfa
.offset
= cfa_store
.offset
;
1517 offset
= -cfa_store
.offset
;
1523 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1524 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1527 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1528 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1531 cfa_store
.offset
+= offset
;
1532 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1533 cfa
.offset
= cfa_store
.offset
;
1535 offset
= -cfa_store
.offset
;
1539 /* With an offset. */
1543 if (GET_CODE (XEXP (XEXP (dest
, 0), 1)) != CONST_INT
)
1545 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1546 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1549 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1550 offset
-= cfa_store
.offset
;
1551 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1552 offset
-= cfa_temp
.offset
;
1558 /* Without an offset. */
1560 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1561 offset
= -cfa_store
.offset
;
1562 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1563 offset
= -cfa_temp
.offset
;
1570 if (cfa_temp
.reg
!= (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1572 offset
= -cfa_temp
.offset
;
1573 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1580 if (REGNO (src
) != STACK_POINTER_REGNUM
1581 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1582 && (unsigned) REGNO (src
) == cfa
.reg
)
1584 /* We're storing the current CFA reg into the stack. */
1586 if (cfa
.offset
== 0)
1588 /* If the source register is exactly the CFA, assume
1589 we're saving SP like any other register; this happens
1591 def_cfa_1 (label
, &cfa
);
1592 queue_reg_save (label
, stack_pointer_rtx
, offset
);
1597 /* Otherwise, we'll need to look in the stack to
1598 calculate the CFA. */
1599 rtx x
= XEXP (dest
, 0);
1601 if (GET_CODE (x
) != REG
)
1603 if (GET_CODE (x
) != REG
)
1606 cfa
.reg
= REGNO (x
);
1607 cfa
.base_offset
= offset
;
1609 def_cfa_1 (label
, &cfa
);
1614 def_cfa_1 (label
, &cfa
);
1615 queue_reg_save (label
, src
, offset
);
1623 /* Record call frame debugging information for INSN, which either
1624 sets SP or FP (adjusting how we calculate the frame address) or saves a
1625 register to the stack. If INSN is NULL_RTX, initialize our state. */
1628 dwarf2out_frame_debug (rtx insn
)
1633 if (insn
== NULL_RTX
)
1635 /* Flush any queued register saves. */
1636 flush_queued_reg_saves ();
1638 /* Set up state for generating call frame debug info. */
1640 if (cfa
.reg
!= (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1643 cfa
.reg
= STACK_POINTER_REGNUM
;
1646 cfa_temp
.offset
= 0;
1650 if (GET_CODE (insn
) != INSN
|| clobbers_queued_reg_save (insn
))
1651 flush_queued_reg_saves ();
1653 if (! RTX_FRAME_RELATED_P (insn
))
1655 if (!ACCUMULATE_OUTGOING_ARGS
)
1656 dwarf2out_stack_adjust (insn
);
1661 label
= dwarf2out_cfi_label ();
1662 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1664 insn
= XEXP (src
, 0);
1666 insn
= PATTERN (insn
);
1668 dwarf2out_frame_debug_expr (insn
, label
);
1673 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1674 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1675 (enum dwarf_call_frame_info cfi
);
1677 static enum dw_cfi_oprnd_type
1678 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
1683 case DW_CFA_GNU_window_save
:
1684 return dw_cfi_oprnd_unused
;
1686 case DW_CFA_set_loc
:
1687 case DW_CFA_advance_loc1
:
1688 case DW_CFA_advance_loc2
:
1689 case DW_CFA_advance_loc4
:
1690 case DW_CFA_MIPS_advance_loc8
:
1691 return dw_cfi_oprnd_addr
;
1694 case DW_CFA_offset_extended
:
1695 case DW_CFA_def_cfa
:
1696 case DW_CFA_offset_extended_sf
:
1697 case DW_CFA_def_cfa_sf
:
1698 case DW_CFA_restore_extended
:
1699 case DW_CFA_undefined
:
1700 case DW_CFA_same_value
:
1701 case DW_CFA_def_cfa_register
:
1702 case DW_CFA_register
:
1703 return dw_cfi_oprnd_reg_num
;
1705 case DW_CFA_def_cfa_offset
:
1706 case DW_CFA_GNU_args_size
:
1707 case DW_CFA_def_cfa_offset_sf
:
1708 return dw_cfi_oprnd_offset
;
1710 case DW_CFA_def_cfa_expression
:
1711 case DW_CFA_expression
:
1712 return dw_cfi_oprnd_loc
;
1719 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1720 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1721 (enum dwarf_call_frame_info cfi
);
1723 static enum dw_cfi_oprnd_type
1724 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
1728 case DW_CFA_def_cfa
:
1729 case DW_CFA_def_cfa_sf
:
1731 case DW_CFA_offset_extended_sf
:
1732 case DW_CFA_offset_extended
:
1733 return dw_cfi_oprnd_offset
;
1735 case DW_CFA_register
:
1736 return dw_cfi_oprnd_reg_num
;
1739 return dw_cfi_oprnd_unused
;
1743 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1745 /* Output a Call Frame Information opcode and its operand(s). */
1748 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
1750 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1751 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1752 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
1753 "DW_CFA_advance_loc 0x%lx",
1754 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1755 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1757 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1758 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1759 "DW_CFA_offset, column 0x%lx",
1760 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1761 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1763 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1764 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1765 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1766 "DW_CFA_restore, column 0x%lx",
1767 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1770 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
1771 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
1773 switch (cfi
->dw_cfi_opc
)
1775 case DW_CFA_set_loc
:
1777 dw2_asm_output_encoded_addr_rtx (
1778 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1779 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
1782 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
1783 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
1786 case DW_CFA_advance_loc1
:
1787 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1788 fde
->dw_fde_current_label
, NULL
);
1789 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1792 case DW_CFA_advance_loc2
:
1793 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1794 fde
->dw_fde_current_label
, NULL
);
1795 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1798 case DW_CFA_advance_loc4
:
1799 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1800 fde
->dw_fde_current_label
, NULL
);
1801 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1804 case DW_CFA_MIPS_advance_loc8
:
1805 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1806 fde
->dw_fde_current_label
, NULL
);
1807 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1810 case DW_CFA_offset_extended
:
1811 case DW_CFA_def_cfa
:
1812 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1814 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1817 case DW_CFA_offset_extended_sf
:
1818 case DW_CFA_def_cfa_sf
:
1819 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1821 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1824 case DW_CFA_restore_extended
:
1825 case DW_CFA_undefined
:
1826 case DW_CFA_same_value
:
1827 case DW_CFA_def_cfa_register
:
1828 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1832 case DW_CFA_register
:
1833 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1835 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
,
1839 case DW_CFA_def_cfa_offset
:
1840 case DW_CFA_GNU_args_size
:
1841 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1844 case DW_CFA_def_cfa_offset_sf
:
1845 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1848 case DW_CFA_GNU_window_save
:
1851 case DW_CFA_def_cfa_expression
:
1852 case DW_CFA_expression
:
1853 output_cfa_loc (cfi
);
1856 case DW_CFA_GNU_negative_offset_extended
:
1857 /* Obsoleted by DW_CFA_offset_extended_sf. */
1866 /* Output the call frame information used to used to record information
1867 that relates to calculating the frame pointer, and records the
1868 location of saved registers. */
1871 output_call_frame_info (int for_eh
)
1876 char l1
[20], l2
[20], section_start_label
[20];
1877 bool any_lsda_needed
= false;
1878 char augmentation
[6];
1879 int augmentation_size
;
1880 int fde_encoding
= DW_EH_PE_absptr
;
1881 int per_encoding
= DW_EH_PE_absptr
;
1882 int lsda_encoding
= DW_EH_PE_absptr
;
1884 /* Don't emit a CIE if there won't be any FDEs. */
1885 if (fde_table_in_use
== 0)
1888 /* If we don't have any functions we'll want to unwind out of, don't
1889 emit any EH unwind information. Note that if exceptions aren't
1890 enabled, we won't have collected nothrow information, and if we
1891 asked for asynchronous tables, we always want this info. */
1894 bool any_eh_needed
= !flag_exceptions
|| flag_asynchronous_unwind_tables
;
1896 for (i
= 0; i
< fde_table_in_use
; i
++)
1897 if (fde_table
[i
].uses_eh_lsda
)
1898 any_eh_needed
= any_lsda_needed
= true;
1899 else if (! fde_table
[i
].nothrow
1900 && ! fde_table
[i
].all_throwers_are_sibcalls
)
1901 any_eh_needed
= true;
1903 if (! any_eh_needed
)
1907 /* We're going to be generating comments, so turn on app. */
1912 (*targetm
.asm_out
.eh_frame_section
) ();
1914 named_section_flags (DEBUG_FRAME_SECTION
, SECTION_DEBUG
);
1916 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
1917 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
1919 /* Output the CIE. */
1920 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
1921 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
1922 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
1923 "Length of Common Information Entry");
1924 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1926 /* Now that the CIE pointer is PC-relative for EH,
1927 use 0 to identify the CIE. */
1928 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
1929 (for_eh
? 0 : DW_CIE_ID
),
1930 "CIE Identifier Tag");
1932 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
1934 augmentation
[0] = 0;
1935 augmentation_size
= 0;
1941 z Indicates that a uleb128 is present to size the
1942 augmentation section.
1943 L Indicates the encoding (and thus presence) of
1944 an LSDA pointer in the FDE augmentation.
1945 R Indicates a non-default pointer encoding for
1947 P Indicates the presence of an encoding + language
1948 personality routine in the CIE augmentation. */
1950 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1951 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1952 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1954 p
= augmentation
+ 1;
1955 if (eh_personality_libfunc
)
1958 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
1960 if (any_lsda_needed
)
1963 augmentation_size
+= 1;
1965 if (fde_encoding
!= DW_EH_PE_absptr
)
1968 augmentation_size
+= 1;
1970 if (p
> augmentation
+ 1)
1972 augmentation
[0] = 'z';
1976 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1977 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
1979 int offset
= ( 4 /* Length */
1981 + 1 /* CIE version */
1982 + strlen (augmentation
) + 1 /* Augmentation */
1983 + size_of_uleb128 (1) /* Code alignment */
1984 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
1986 + 1 /* Augmentation size */
1987 + 1 /* Personality encoding */ );
1988 int pad
= -offset
& (PTR_SIZE
- 1);
1990 augmentation_size
+= pad
;
1992 /* Augmentations should be small, so there's scarce need to
1993 iterate for a solution. Die if we exceed one uleb128 byte. */
1994 if (size_of_uleb128 (augmentation_size
) != 1)
1999 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
2000 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2001 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
2002 "CIE Data Alignment Factor");
2003 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN
, "CIE RA Column");
2005 if (augmentation
[0])
2007 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
2008 if (eh_personality_libfunc
)
2010 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
2011 eh_data_format_name (per_encoding
));
2012 dw2_asm_output_encoded_addr_rtx (per_encoding
,
2013 eh_personality_libfunc
, NULL
);
2016 if (any_lsda_needed
)
2017 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
2018 eh_data_format_name (lsda_encoding
));
2020 if (fde_encoding
!= DW_EH_PE_absptr
)
2021 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
2022 eh_data_format_name (fde_encoding
));
2025 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2026 output_cfi (cfi
, NULL
, for_eh
);
2028 /* Pad the CIE out to an address sized boundary. */
2029 ASM_OUTPUT_ALIGN (asm_out_file
,
2030 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
2031 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2033 /* Loop through all of the FDE's. */
2034 for (i
= 0; i
< fde_table_in_use
; i
++)
2036 fde
= &fde_table
[i
];
2038 /* Don't emit EH unwind info for leaf functions that don't need it. */
2039 if (for_eh
&& !flag_asynchronous_unwind_tables
&& flag_exceptions
2040 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
2041 && !fde
->uses_eh_lsda
)
2044 (*targetm
.asm_out
.internal_label
) (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
2045 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
2046 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
2047 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2049 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2052 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
2054 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
2059 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
2060 gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
),
2061 "FDE initial location");
2062 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2063 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2064 "FDE address range");
2068 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
2069 "FDE initial location");
2070 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2071 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2072 "FDE address range");
2075 if (augmentation
[0])
2077 if (any_lsda_needed
)
2079 int size
= size_of_encoded_value (lsda_encoding
);
2081 if (lsda_encoding
== DW_EH_PE_aligned
)
2083 int offset
= ( 4 /* Length */
2084 + 4 /* CIE offset */
2085 + 2 * size_of_encoded_value (fde_encoding
)
2086 + 1 /* Augmentation size */ );
2087 int pad
= -offset
& (PTR_SIZE
- 1);
2090 if (size_of_uleb128 (size
) != 1)
2094 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2096 if (fde
->uses_eh_lsda
)
2098 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2099 fde
->funcdef_number
);
2100 dw2_asm_output_encoded_addr_rtx (
2101 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2102 "Language Specific Data Area");
2106 if (lsda_encoding
== DW_EH_PE_aligned
)
2107 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2109 (size_of_encoded_value (lsda_encoding
), 0,
2110 "Language Specific Data Area (none)");
2114 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2117 /* Loop through the Call Frame Instructions associated with
2119 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2120 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2121 output_cfi (cfi
, fde
, for_eh
);
2123 /* Pad the FDE out to an address sized boundary. */
2124 ASM_OUTPUT_ALIGN (asm_out_file
,
2125 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2126 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2129 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
2130 dw2_asm_output_data (4, 0, "End of Table");
2131 #ifdef MIPS_DEBUGGING_INFO
2132 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2133 get a value of 0. Putting .align 0 after the label fixes it. */
2134 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2137 /* Turn off app to make assembly quicker. */
2142 /* Output a marker (i.e. a label) for the beginning of a function, before
2146 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
2147 const char *file ATTRIBUTE_UNUSED
)
2149 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2152 current_function_func_begin_label
= 0;
2154 #ifdef IA64_UNWIND_INFO
2155 /* ??? current_function_func_begin_label is also used by except.c
2156 for call-site information. We must emit this label if it might
2158 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2159 && ! dwarf2out_do_frame ())
2162 if (! dwarf2out_do_frame ())
2166 function_section (current_function_decl
);
2167 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2168 current_function_funcdef_no
);
2169 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2170 current_function_funcdef_no
);
2171 current_function_func_begin_label
= get_identifier (label
);
2173 #ifdef IA64_UNWIND_INFO
2174 /* We can elide the fde allocation if we're not emitting debug info. */
2175 if (! dwarf2out_do_frame ())
2179 /* Expand the fde table if necessary. */
2180 if (fde_table_in_use
== fde_table_allocated
)
2182 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2183 fde_table
= ggc_realloc (fde_table
,
2184 fde_table_allocated
* sizeof (dw_fde_node
));
2185 memset (fde_table
+ fde_table_in_use
, 0,
2186 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2189 /* Record the FDE associated with this function. */
2190 current_funcdef_fde
= fde_table_in_use
;
2192 /* Add the new FDE at the end of the fde_table. */
2193 fde
= &fde_table
[fde_table_in_use
++];
2194 fde
->dw_fde_begin
= xstrdup (label
);
2195 fde
->dw_fde_current_label
= NULL
;
2196 fde
->dw_fde_end
= NULL
;
2197 fde
->dw_fde_cfi
= NULL
;
2198 fde
->funcdef_number
= current_function_funcdef_no
;
2199 fde
->nothrow
= current_function_nothrow
;
2200 fde
->uses_eh_lsda
= cfun
->uses_eh_lsda
;
2201 fde
->all_throwers_are_sibcalls
= cfun
->all_throwers_are_sibcalls
;
2203 args_size
= old_args_size
= 0;
2205 /* We only want to output line number information for the genuine dwarf2
2206 prologue case, not the eh frame case. */
2207 #ifdef DWARF2_DEBUGGING_INFO
2209 dwarf2out_source_line (line
, file
);
2213 /* Output a marker (i.e. a label) for the absolute end of the generated code
2214 for a function definition. This gets called *after* the epilogue code has
2218 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
2219 const char *file ATTRIBUTE_UNUSED
)
2222 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2224 /* Output a label to mark the endpoint of the code generated for this
2226 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
2227 current_function_funcdef_no
);
2228 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2229 fde
= &fde_table
[fde_table_in_use
- 1];
2230 fde
->dw_fde_end
= xstrdup (label
);
2234 dwarf2out_frame_init (void)
2236 /* Allocate the initial hunk of the fde_table. */
2237 fde_table
= (dw_fde_ref
) ggc_alloc_cleared (FDE_TABLE_INCREMENT
2238 * sizeof (dw_fde_node
));
2239 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2240 fde_table_in_use
= 0;
2242 /* Generate the CFA instructions common to all FDE's. Do it now for the
2243 sake of lookup_cfa. */
2245 #ifdef DWARF2_UNWIND_INFO
2246 /* On entry, the Canonical Frame Address is at SP. */
2247 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2248 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2253 dwarf2out_frame_finish (void)
2255 /* Output call frame information. */
2256 if (write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
2257 output_call_frame_info (0);
2259 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2260 output_call_frame_info (1);
2264 /* And now, the subset of the debugging information support code necessary
2265 for emitting location expressions. */
2267 /* We need some way to distinguish DW_OP_addr with a direct symbol
2268 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2269 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2272 typedef struct dw_val_struct
*dw_val_ref
;
2273 typedef struct die_struct
*dw_die_ref
;
2274 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2275 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2277 /* Each DIE may have a series of attribute/value pairs. Values
2278 can take on several forms. The forms that are used in this
2279 implementation are listed below. */
2284 dw_val_class_offset
,
2286 dw_val_class_loc_list
,
2287 dw_val_class_range_list
,
2289 dw_val_class_unsigned_const
,
2290 dw_val_class_long_long
,
2293 dw_val_class_die_ref
,
2294 dw_val_class_fde_ref
,
2295 dw_val_class_lbl_id
,
2296 dw_val_class_lbl_offset
,
2300 /* Describe a double word constant value. */
2301 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2303 typedef struct dw_long_long_struct
GTY(())
2310 /* Describe a floating point constant value. */
2312 typedef struct dw_fp_struct
GTY(())
2314 long * GTY((length ("%h.length"))) array
;
2319 /* The dw_val_node describes an attribute's value, as it is
2320 represented internally. */
2322 typedef struct dw_val_struct
GTY(())
2324 enum dw_val_class val_class
;
2325 union dw_val_struct_union
2327 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
2328 long unsigned GTY ((tag ("dw_val_class_offset"))) val_offset
;
2329 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
2330 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
2331 long int GTY ((default (""))) val_int
;
2332 long unsigned GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
2333 dw_long_long_const
GTY ((tag ("dw_val_class_long_long"))) val_long_long
;
2334 dw_float_const
GTY ((tag ("dw_val_class_float"))) val_float
;
2335 struct dw_val_die_union
2339 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
2340 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
2341 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
2342 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
2343 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
2345 GTY ((desc ("%1.val_class"))) v
;
2349 /* Locations in memory are described using a sequence of stack machine
2352 typedef struct dw_loc_descr_struct
GTY(())
2354 dw_loc_descr_ref dw_loc_next
;
2355 enum dwarf_location_atom dw_loc_opc
;
2356 dw_val_node dw_loc_oprnd1
;
2357 dw_val_node dw_loc_oprnd2
;
2362 /* Location lists are ranges + location descriptions for that range,
2363 so you can track variables that are in different places over
2364 their entire life. */
2365 typedef struct dw_loc_list_struct
GTY(())
2367 dw_loc_list_ref dw_loc_next
;
2368 const char *begin
; /* Label for begin address of range */
2369 const char *end
; /* Label for end address of range */
2370 char *ll_symbol
; /* Label for beginning of location list.
2371 Only on head of list */
2372 const char *section
; /* Section this loclist is relative to */
2373 dw_loc_descr_ref expr
;
2376 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2378 static const char *dwarf_stack_op_name (unsigned);
2379 static dw_loc_descr_ref
new_loc_descr (enum dwarf_location_atom
,
2380 unsigned long, unsigned long);
2381 static void add_loc_descr (dw_loc_descr_ref
*, dw_loc_descr_ref
);
2382 static unsigned long size_of_loc_descr (dw_loc_descr_ref
);
2383 static unsigned long size_of_locs (dw_loc_descr_ref
);
2384 static void output_loc_operands (dw_loc_descr_ref
);
2385 static void output_loc_sequence (dw_loc_descr_ref
);
2387 /* Convert a DWARF stack opcode into its string name. */
2390 dwarf_stack_op_name (unsigned int op
)
2395 case INTERNAL_DW_OP_tls_addr
:
2396 return "DW_OP_addr";
2398 return "DW_OP_deref";
2400 return "DW_OP_const1u";
2402 return "DW_OP_const1s";
2404 return "DW_OP_const2u";
2406 return "DW_OP_const2s";
2408 return "DW_OP_const4u";
2410 return "DW_OP_const4s";
2412 return "DW_OP_const8u";
2414 return "DW_OP_const8s";
2416 return "DW_OP_constu";
2418 return "DW_OP_consts";
2422 return "DW_OP_drop";
2424 return "DW_OP_over";
2426 return "DW_OP_pick";
2428 return "DW_OP_swap";
2432 return "DW_OP_xderef";
2440 return "DW_OP_minus";
2452 return "DW_OP_plus";
2453 case DW_OP_plus_uconst
:
2454 return "DW_OP_plus_uconst";
2460 return "DW_OP_shra";
2478 return "DW_OP_skip";
2480 return "DW_OP_lit0";
2482 return "DW_OP_lit1";
2484 return "DW_OP_lit2";
2486 return "DW_OP_lit3";
2488 return "DW_OP_lit4";
2490 return "DW_OP_lit5";
2492 return "DW_OP_lit6";
2494 return "DW_OP_lit7";
2496 return "DW_OP_lit8";
2498 return "DW_OP_lit9";
2500 return "DW_OP_lit10";
2502 return "DW_OP_lit11";
2504 return "DW_OP_lit12";
2506 return "DW_OP_lit13";
2508 return "DW_OP_lit14";
2510 return "DW_OP_lit15";
2512 return "DW_OP_lit16";
2514 return "DW_OP_lit17";
2516 return "DW_OP_lit18";
2518 return "DW_OP_lit19";
2520 return "DW_OP_lit20";
2522 return "DW_OP_lit21";
2524 return "DW_OP_lit22";
2526 return "DW_OP_lit23";
2528 return "DW_OP_lit24";
2530 return "DW_OP_lit25";
2532 return "DW_OP_lit26";
2534 return "DW_OP_lit27";
2536 return "DW_OP_lit28";
2538 return "DW_OP_lit29";
2540 return "DW_OP_lit30";
2542 return "DW_OP_lit31";
2544 return "DW_OP_reg0";
2546 return "DW_OP_reg1";
2548 return "DW_OP_reg2";
2550 return "DW_OP_reg3";
2552 return "DW_OP_reg4";
2554 return "DW_OP_reg5";
2556 return "DW_OP_reg6";
2558 return "DW_OP_reg7";
2560 return "DW_OP_reg8";
2562 return "DW_OP_reg9";
2564 return "DW_OP_reg10";
2566 return "DW_OP_reg11";
2568 return "DW_OP_reg12";
2570 return "DW_OP_reg13";
2572 return "DW_OP_reg14";
2574 return "DW_OP_reg15";
2576 return "DW_OP_reg16";
2578 return "DW_OP_reg17";
2580 return "DW_OP_reg18";
2582 return "DW_OP_reg19";
2584 return "DW_OP_reg20";
2586 return "DW_OP_reg21";
2588 return "DW_OP_reg22";
2590 return "DW_OP_reg23";
2592 return "DW_OP_reg24";
2594 return "DW_OP_reg25";
2596 return "DW_OP_reg26";
2598 return "DW_OP_reg27";
2600 return "DW_OP_reg28";
2602 return "DW_OP_reg29";
2604 return "DW_OP_reg30";
2606 return "DW_OP_reg31";
2608 return "DW_OP_breg0";
2610 return "DW_OP_breg1";
2612 return "DW_OP_breg2";
2614 return "DW_OP_breg3";
2616 return "DW_OP_breg4";
2618 return "DW_OP_breg5";
2620 return "DW_OP_breg6";
2622 return "DW_OP_breg7";
2624 return "DW_OP_breg8";
2626 return "DW_OP_breg9";
2628 return "DW_OP_breg10";
2630 return "DW_OP_breg11";
2632 return "DW_OP_breg12";
2634 return "DW_OP_breg13";
2636 return "DW_OP_breg14";
2638 return "DW_OP_breg15";
2640 return "DW_OP_breg16";
2642 return "DW_OP_breg17";
2644 return "DW_OP_breg18";
2646 return "DW_OP_breg19";
2648 return "DW_OP_breg20";
2650 return "DW_OP_breg21";
2652 return "DW_OP_breg22";
2654 return "DW_OP_breg23";
2656 return "DW_OP_breg24";
2658 return "DW_OP_breg25";
2660 return "DW_OP_breg26";
2662 return "DW_OP_breg27";
2664 return "DW_OP_breg28";
2666 return "DW_OP_breg29";
2668 return "DW_OP_breg30";
2670 return "DW_OP_breg31";
2672 return "DW_OP_regx";
2674 return "DW_OP_fbreg";
2676 return "DW_OP_bregx";
2678 return "DW_OP_piece";
2679 case DW_OP_deref_size
:
2680 return "DW_OP_deref_size";
2681 case DW_OP_xderef_size
:
2682 return "DW_OP_xderef_size";
2685 case DW_OP_push_object_address
:
2686 return "DW_OP_push_object_address";
2688 return "DW_OP_call2";
2690 return "DW_OP_call4";
2691 case DW_OP_call_ref
:
2692 return "DW_OP_call_ref";
2693 case DW_OP_GNU_push_tls_address
:
2694 return "DW_OP_GNU_push_tls_address";
2696 return "OP_<unknown>";
2700 /* Return a pointer to a newly allocated location description. Location
2701 descriptions are simple expression terms that can be strung
2702 together to form more complicated location (address) descriptions. */
2704 static inline dw_loc_descr_ref
2705 new_loc_descr (enum dwarf_location_atom op
, long unsigned int oprnd1
,
2706 long unsigned int oprnd2
)
2708 dw_loc_descr_ref descr
2709 = (dw_loc_descr_ref
) ggc_alloc_cleared (sizeof (dw_loc_descr_node
));
2711 descr
->dw_loc_opc
= op
;
2712 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
2713 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
2714 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
2715 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
2721 /* Add a location description term to a location description expression. */
2724 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
2726 dw_loc_descr_ref
*d
;
2728 /* Find the end of the chain. */
2729 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
2735 /* Return the size of a location descriptor. */
2737 static unsigned long
2738 size_of_loc_descr (dw_loc_descr_ref loc
)
2740 unsigned long size
= 1;
2742 switch (loc
->dw_loc_opc
)
2745 case INTERNAL_DW_OP_tls_addr
:
2746 size
+= DWARF2_ADDR_SIZE
;
2765 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2768 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2773 case DW_OP_plus_uconst
:
2774 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2812 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2815 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2818 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2821 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2822 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
2825 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2827 case DW_OP_deref_size
:
2828 case DW_OP_xderef_size
:
2837 case DW_OP_call_ref
:
2838 size
+= DWARF2_ADDR_SIZE
;
2847 /* Return the size of a series of location descriptors. */
2849 static unsigned long
2850 size_of_locs (dw_loc_descr_ref loc
)
2854 for (size
= 0; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2856 loc
->dw_loc_addr
= size
;
2857 size
+= size_of_loc_descr (loc
);
2863 /* Output location description stack opcode's operands (if any). */
2866 output_loc_operands (dw_loc_descr_ref loc
)
2868 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2869 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2871 switch (loc
->dw_loc_opc
)
2873 #ifdef DWARF2_DEBUGGING_INFO
2875 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2879 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2883 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2887 if (HOST_BITS_PER_LONG
< 64)
2889 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2896 if (val1
->val_class
== dw_val_class_loc
)
2897 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2901 dw2_asm_output_data (2, offset
, NULL
);
2914 /* We currently don't make any attempt to make sure these are
2915 aligned properly like we do for the main unwind info, so
2916 don't support emitting things larger than a byte if we're
2917 only doing unwinding. */
2922 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2925 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2928 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2931 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2933 case DW_OP_plus_uconst
:
2934 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2968 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2971 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2974 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2977 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2978 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2981 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2983 case DW_OP_deref_size
:
2984 case DW_OP_xderef_size
:
2985 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2988 case INTERNAL_DW_OP_tls_addr
:
2989 #ifdef ASM_OUTPUT_DWARF_DTPREL
2990 ASM_OUTPUT_DWARF_DTPREL (asm_out_file
, DWARF2_ADDR_SIZE
,
2992 fputc ('\n', asm_out_file
);
2999 /* Other codes have no operands. */
3004 /* Output a sequence of location operations. */
3007 output_loc_sequence (dw_loc_descr_ref loc
)
3009 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
3011 /* Output the opcode. */
3012 dw2_asm_output_data (1, loc
->dw_loc_opc
,
3013 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
3015 /* Output the operand(s) (if any). */
3016 output_loc_operands (loc
);
3020 /* This routine will generate the correct assembly data for a location
3021 description based on a cfi entry with a complex address. */
3024 output_cfa_loc (dw_cfi_ref cfi
)
3026 dw_loc_descr_ref loc
;
3029 /* Output the size of the block. */
3030 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
3031 size
= size_of_locs (loc
);
3032 dw2_asm_output_data_uleb128 (size
, NULL
);
3034 /* Now output the operations themselves. */
3035 output_loc_sequence (loc
);
3038 /* This function builds a dwarf location descriptor sequence from
3039 a dw_cfa_location. */
3041 static struct dw_loc_descr_struct
*
3042 build_cfa_loc (dw_cfa_location
*cfa
)
3044 struct dw_loc_descr_struct
*head
, *tmp
;
3046 if (cfa
->indirect
== 0)
3049 if (cfa
->base_offset
)
3052 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
3054 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
3056 else if (cfa
->reg
<= 31)
3057 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3059 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3061 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
3062 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
3063 add_loc_descr (&head
, tmp
);
3064 if (cfa
->offset
!= 0)
3066 tmp
= new_loc_descr (DW_OP_plus_uconst
, cfa
->offset
, 0);
3067 add_loc_descr (&head
, tmp
);
3073 /* This function fills in aa dw_cfa_location structure from a dwarf location
3074 descriptor sequence. */
3077 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
3079 struct dw_loc_descr_struct
*ptr
;
3081 cfa
->base_offset
= 0;
3085 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
3087 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3123 cfa
->reg
= op
- DW_OP_reg0
;
3126 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3160 cfa
->reg
= op
- DW_OP_breg0
;
3161 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3164 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3165 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3170 case DW_OP_plus_uconst
:
3171 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3174 internal_error ("DW_LOC_OP %s not implemented\n",
3175 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3179 #endif /* .debug_frame support */
3181 /* And now, the support for symbolic debugging information. */
3182 #ifdef DWARF2_DEBUGGING_INFO
3184 /* .debug_str support. */
3185 static int output_indirect_string (void **, void *);
3187 static void dwarf2out_init (const char *);
3188 static void dwarf2out_finish (const char *);
3189 static void dwarf2out_define (unsigned int, const char *);
3190 static void dwarf2out_undef (unsigned int, const char *);
3191 static void dwarf2out_start_source_file (unsigned, const char *);
3192 static void dwarf2out_end_source_file (unsigned);
3193 static void dwarf2out_begin_block (unsigned, unsigned);
3194 static void dwarf2out_end_block (unsigned, unsigned);
3195 static bool dwarf2out_ignore_block (tree
);
3196 static void dwarf2out_global_decl (tree
);
3197 static void dwarf2out_abstract_function (tree
);
3199 /* The debug hooks structure. */
3201 const struct gcc_debug_hooks dwarf2_debug_hooks
=
3207 dwarf2out_start_source_file
,
3208 dwarf2out_end_source_file
,
3209 dwarf2out_begin_block
,
3210 dwarf2out_end_block
,
3211 dwarf2out_ignore_block
,
3212 dwarf2out_source_line
,
3213 dwarf2out_begin_prologue
,
3214 debug_nothing_int_charstar
, /* end_prologue */
3215 dwarf2out_end_epilogue
,
3216 debug_nothing_tree
, /* begin_function */
3217 debug_nothing_int
, /* end_function */
3218 dwarf2out_decl
, /* function_decl */
3219 dwarf2out_global_decl
,
3220 debug_nothing_tree
, /* deferred_inline_function */
3221 /* The DWARF 2 backend tries to reduce debugging bloat by not
3222 emitting the abstract description of inline functions until
3223 something tries to reference them. */
3224 dwarf2out_abstract_function
, /* outlining_inline_function */
3225 debug_nothing_rtx
, /* label */
3226 debug_nothing_int
/* handle_pch */
3230 /* NOTE: In the comments in this file, many references are made to
3231 "Debugging Information Entries". This term is abbreviated as `DIE'
3232 throughout the remainder of this file. */
3234 /* An internal representation of the DWARF output is built, and then
3235 walked to generate the DWARF debugging info. The walk of the internal
3236 representation is done after the entire program has been compiled.
3237 The types below are used to describe the internal representation. */
3239 /* Various DIE's use offsets relative to the beginning of the
3240 .debug_info section to refer to each other. */
3242 typedef long int dw_offset
;
3244 /* Define typedefs here to avoid circular dependencies. */
3246 typedef struct dw_attr_struct
*dw_attr_ref
;
3247 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3248 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3249 typedef struct pubname_struct
*pubname_ref
;
3250 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3252 /* Each entry in the line_info_table maintains the file and
3253 line number associated with the label generated for that
3254 entry. The label gives the PC value associated with
3255 the line number entry. */
3257 typedef struct dw_line_info_struct
GTY(())
3259 unsigned long dw_file_num
;
3260 unsigned long dw_line_num
;
3264 /* Line information for functions in separate sections; each one gets its
3266 typedef struct dw_separate_line_info_struct
GTY(())
3268 unsigned long dw_file_num
;
3269 unsigned long dw_line_num
;
3270 unsigned long function
;
3272 dw_separate_line_info_entry
;
3274 /* Each DIE attribute has a field specifying the attribute kind,
3275 a link to the next attribute in the chain, and an attribute value.
3276 Attributes are typically linked below the DIE they modify. */
3278 typedef struct dw_attr_struct
GTY(())
3280 enum dwarf_attribute dw_attr
;
3281 dw_attr_ref dw_attr_next
;
3282 dw_val_node dw_attr_val
;
3286 /* The Debugging Information Entry (DIE) structure */
3288 typedef struct die_struct
GTY(())
3290 enum dwarf_tag die_tag
;
3292 dw_attr_ref die_attr
;
3293 dw_die_ref die_parent
;
3294 dw_die_ref die_child
;
3296 dw_offset die_offset
;
3297 unsigned long die_abbrev
;
3302 /* The pubname structure */
3304 typedef struct pubname_struct
GTY(())
3311 struct dw_ranges_struct
GTY(())
3316 /* The limbo die list structure. */
3317 typedef struct limbo_die_struct
GTY(())
3321 struct limbo_die_struct
*next
;
3325 /* How to start an assembler comment. */
3326 #ifndef ASM_COMMENT_START
3327 #define ASM_COMMENT_START ";#"
3330 /* Define a macro which returns nonzero for a TYPE_DECL which was
3331 implicitly generated for a tagged type.
3333 Note that unlike the gcc front end (which generates a NULL named
3334 TYPE_DECL node for each complete tagged type, each array type, and
3335 each function type node created) the g++ front end generates a
3336 _named_ TYPE_DECL node for each tagged type node created.
3337 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3338 generate a DW_TAG_typedef DIE for them. */
3340 #define TYPE_DECL_IS_STUB(decl) \
3341 (DECL_NAME (decl) == NULL_TREE \
3342 || (DECL_ARTIFICIAL (decl) \
3343 && is_tagged_type (TREE_TYPE (decl)) \
3344 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3345 /* This is necessary for stub decls that \
3346 appear in nested inline functions. */ \
3347 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3348 && (decl_ultimate_origin (decl) \
3349 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3351 /* Information concerning the compilation unit's programming
3352 language, and compiler version. */
3354 /* Fixed size portion of the DWARF compilation unit header. */
3355 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3356 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3358 /* Fixed size portion of public names info. */
3359 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3361 /* Fixed size portion of the address range info. */
3362 #define DWARF_ARANGES_HEADER_SIZE \
3363 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3364 DWARF2_ADDR_SIZE * 2) \
3365 - DWARF_INITIAL_LENGTH_SIZE)
3367 /* Size of padding portion in the address range info. It must be
3368 aligned to twice the pointer size. */
3369 #define DWARF_ARANGES_PAD_SIZE \
3370 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3371 DWARF2_ADDR_SIZE * 2) \
3372 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3374 /* Use assembler line directives if available. */
3375 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3376 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3377 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3379 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3383 /* Minimum line offset in a special line info. opcode.
3384 This value was chosen to give a reasonable range of values. */
3385 #define DWARF_LINE_BASE -10
3387 /* First special line opcode - leave room for the standard opcodes. */
3388 #define DWARF_LINE_OPCODE_BASE 10
3390 /* Range of line offsets in a special line info. opcode. */
3391 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3393 /* Flag that indicates the initial value of the is_stmt_start flag.
3394 In the present implementation, we do not mark any lines as
3395 the beginning of a source statement, because that information
3396 is not made available by the GCC front-end. */
3397 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3399 #ifdef DWARF2_DEBUGGING_INFO
3400 /* This location is used by calc_die_sizes() to keep track
3401 the offset of each DIE within the .debug_info section. */
3402 static unsigned long next_die_offset
;
3405 /* Record the root of the DIE's built for the current compilation unit. */
3406 static GTY(()) dw_die_ref comp_unit_die
;
3408 #ifdef DWARF2_DEBUGGING_INFO
3409 /* We need special handling in dwarf2out_start_source_file if it is
3411 static int is_main_source
;
3414 /* A list of DIEs with a NULL parent waiting to be relocated. */
3415 static GTY(()) limbo_die_node
*limbo_die_list
;
3417 /* Filenames referenced by this compilation unit. */
3418 static GTY(()) varray_type file_table
;
3419 static GTY(()) varray_type file_table_emitted
;
3420 static GTY(()) size_t file_table_last_lookup_index
;
3422 /* A pointer to the base of a table of references to DIE's that describe
3423 declarations. The table is indexed by DECL_UID() which is a unique
3424 number identifying each decl. */
3425 static GTY((length ("decl_die_table_allocated"))) dw_die_ref
*decl_die_table
;
3427 /* Number of elements currently allocated for the decl_die_table. */
3428 static GTY(()) unsigned decl_die_table_allocated
;
3430 /* Number of elements in decl_die_table currently in use. */
3431 static GTY(()) unsigned decl_die_table_in_use
;
3433 /* Size (in elements) of increments by which we may expand the
3435 #define DECL_DIE_TABLE_INCREMENT 256
3437 /* A pointer to the base of a list of references to DIE's that
3438 are uniquely identified by their tag, presence/absence of
3439 children DIE's, and list of attribute/value pairs. */
3440 static GTY((length ("abbrev_die_table_allocated")))
3441 dw_die_ref
*abbrev_die_table
;
3443 /* Number of elements currently allocated for abbrev_die_table. */
3444 static GTY(()) unsigned abbrev_die_table_allocated
;
3446 /* Number of elements in type_die_table currently in use. */
3447 static GTY(()) unsigned abbrev_die_table_in_use
;
3449 /* Size (in elements) of increments by which we may expand the
3450 abbrev_die_table. */
3451 #define ABBREV_DIE_TABLE_INCREMENT 256
3453 /* A pointer to the base of a table that contains line information
3454 for each source code line in .text in the compilation unit. */
3455 static GTY((length ("line_info_table_allocated")))
3456 dw_line_info_ref line_info_table
;
3458 /* Number of elements currently allocated for line_info_table. */
3459 static GTY(()) unsigned line_info_table_allocated
;
3461 /* Number of elements in line_info_table currently in use. */
3462 static GTY(()) unsigned line_info_table_in_use
;
3464 /* A pointer to the base of a table that contains line information
3465 for each source code line outside of .text in the compilation unit. */
3466 static GTY ((length ("separate_line_info_table_allocated")))
3467 dw_separate_line_info_ref separate_line_info_table
;
3469 /* Number of elements currently allocated for separate_line_info_table. */
3470 static GTY(()) unsigned separate_line_info_table_allocated
;
3472 /* Number of elements in separate_line_info_table currently in use. */
3473 static GTY(()) unsigned separate_line_info_table_in_use
;
3475 /* Size (in elements) of increments by which we may expand the
3477 #define LINE_INFO_TABLE_INCREMENT 1024
3479 /* A pointer to the base of a table that contains a list of publicly
3480 accessible names. */
3481 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table
;
3483 /* Number of elements currently allocated for pubname_table. */
3484 static GTY(()) unsigned pubname_table_allocated
;
3486 /* Number of elements in pubname_table currently in use. */
3487 static GTY(()) unsigned pubname_table_in_use
;
3489 /* Size (in elements) of increments by which we may expand the
3491 #define PUBNAME_TABLE_INCREMENT 64
3493 /* Array of dies for which we should generate .debug_arange info. */
3494 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
3496 /* Number of elements currently allocated for arange_table. */
3497 static GTY(()) unsigned arange_table_allocated
;
3499 /* Number of elements in arange_table currently in use. */
3500 static GTY(()) unsigned arange_table_in_use
;
3502 /* Size (in elements) of increments by which we may expand the
3504 #define ARANGE_TABLE_INCREMENT 64
3506 /* Array of dies for which we should generate .debug_ranges info. */
3507 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
3509 /* Number of elements currently allocated for ranges_table. */
3510 static GTY(()) unsigned ranges_table_allocated
;
3512 /* Number of elements in ranges_table currently in use. */
3513 static GTY(()) unsigned ranges_table_in_use
;
3515 /* Size (in elements) of increments by which we may expand the
3517 #define RANGES_TABLE_INCREMENT 64
3519 /* Whether we have location lists that need outputting */
3520 static GTY(()) unsigned have_location_lists
;
3522 #ifdef DWARF2_DEBUGGING_INFO
3523 /* Record whether the function being analyzed contains inlined functions. */
3524 static int current_function_has_inlines
;
3526 #if 0 && defined (MIPS_DEBUGGING_INFO)
3527 static int comp_unit_has_inlines
;
3530 /* Number of file tables emitted in maybe_emit_file(). */
3531 static GTY(()) int emitcount
= 0;
3533 /* Number of internal labels generated by gen_internal_sym(). */
3534 static GTY(()) int label_num
;
3536 #ifdef DWARF2_DEBUGGING_INFO
3538 /* Forward declarations for functions defined in this file. */
3540 static int is_pseudo_reg (rtx
);
3541 static tree
type_main_variant (tree
);
3542 static int is_tagged_type (tree
);
3543 static const char *dwarf_tag_name (unsigned);
3544 static const char *dwarf_attr_name (unsigned);
3545 static const char *dwarf_form_name (unsigned);
3547 static const char *dwarf_type_encoding_name (unsigned);
3549 static tree
decl_ultimate_origin (tree
);
3550 static tree
block_ultimate_origin (tree
);
3551 static tree
decl_class_context (tree
);
3552 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
3553 static inline enum dw_val_class
AT_class (dw_attr_ref
);
3554 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3555 static inline unsigned AT_flag (dw_attr_ref
);
3556 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, long);
3557 static inline long int AT_int (dw_attr_ref
);
3558 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned long);
3559 static inline unsigned long AT_unsigned (dw_attr_ref
);
3560 static void add_AT_long_long (dw_die_ref
, enum dwarf_attribute
, unsigned long,
3562 static void add_AT_float (dw_die_ref
, enum dwarf_attribute
, unsigned, long *);
3563 static hashval_t
debug_str_do_hash (const void *);
3564 static int debug_str_eq (const void *, const void *);
3565 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3566 static inline const char *AT_string (dw_attr_ref
);
3567 static int AT_string_form (dw_attr_ref
);
3568 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3569 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3570 static inline int AT_ref_external (dw_attr_ref
);
3571 static inline void set_AT_ref_external (dw_attr_ref
, int);
3572 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3573 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3574 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3575 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3577 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3578 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
3579 static inline rtx
AT_addr (dw_attr_ref
);
3580 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3581 static void add_AT_lbl_offset (dw_die_ref
, enum dwarf_attribute
, const char *);
3582 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
, unsigned long);
3583 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3585 static inline const char *AT_lbl (dw_attr_ref
);
3586 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3587 static const char *get_AT_low_pc (dw_die_ref
);
3588 static const char *get_AT_hi_pc (dw_die_ref
);
3589 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3590 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3591 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3592 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3593 static bool is_c_family (void);
3594 static bool is_cxx (void);
3595 static bool is_java (void);
3596 static bool is_fortran (void);
3597 static bool is_ada (void);
3598 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
3599 static inline void free_die (dw_die_ref
);
3600 static void remove_children (dw_die_ref
);
3601 static void add_child_die (dw_die_ref
, dw_die_ref
);
3602 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3603 static dw_die_ref
lookup_type_die (tree
);
3604 static void equate_type_number_to_die (tree
, dw_die_ref
);
3605 static dw_die_ref
lookup_decl_die (tree
);
3606 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3607 static void print_spaces (FILE *);
3608 static void print_die (dw_die_ref
, FILE *);
3609 static void print_dwarf_line_table (FILE *);
3610 static void reverse_die_lists (dw_die_ref
);
3611 static void reverse_all_dies (dw_die_ref
);
3612 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3613 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3614 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3615 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3616 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3617 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3618 static int same_dw_val_p (dw_val_node
*, dw_val_node
*, int *);
3619 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3620 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3621 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3622 static void compute_section_prefix (dw_die_ref
);
3623 static int is_type_die (dw_die_ref
);
3624 static int is_comdat_die (dw_die_ref
);
3625 static int is_symbol_die (dw_die_ref
);
3626 static void assign_symbol_names (dw_die_ref
);
3627 static void break_out_includes (dw_die_ref
);
3628 static hashval_t
htab_cu_hash (const void *);
3629 static int htab_cu_eq (const void *, const void *);
3630 static void htab_cu_del (void *);
3631 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
3632 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
3633 static void add_sibling_attributes (dw_die_ref
);
3634 static void build_abbrev_table (dw_die_ref
);
3635 static void output_location_lists (dw_die_ref
);
3636 static int constant_size (long unsigned);
3637 static unsigned long size_of_die (dw_die_ref
);
3638 static void calc_die_sizes (dw_die_ref
);
3639 static void mark_dies (dw_die_ref
);
3640 static void unmark_dies (dw_die_ref
);
3641 static void unmark_all_dies (dw_die_ref
);
3642 static unsigned long size_of_pubnames (void);
3643 static unsigned long size_of_aranges (void);
3644 static enum dwarf_form
value_format (dw_attr_ref
);
3645 static void output_value_format (dw_attr_ref
);
3646 static void output_abbrev_section (void);
3647 static void output_die_symbol (dw_die_ref
);
3648 static void output_die (dw_die_ref
);
3649 static void output_compilation_unit_header (void);
3650 static void output_comp_unit (dw_die_ref
, int);
3651 static const char *dwarf2_name (tree
, int);
3652 static void add_pubname (tree
, dw_die_ref
);
3653 static void output_pubnames (void);
3654 static void add_arange (tree
, dw_die_ref
);
3655 static void output_aranges (void);
3656 static unsigned int add_ranges (tree
);
3657 static void output_ranges (void);
3658 static void output_line_info (void);
3659 static void output_file_names (void);
3660 static dw_die_ref
base_type_die (tree
);
3661 static tree
root_type (tree
);
3662 static int is_base_type (tree
);
3663 static bool is_ada_subrange_type (tree
);
3664 static dw_die_ref
subrange_type_die (tree
);
3665 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3666 static int type_is_enum (tree
);
3667 static unsigned int reg_number (rtx
);
3668 static dw_loc_descr_ref
reg_loc_descriptor (rtx
);
3669 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int);
3670 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
);
3671 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
3672 static dw_loc_descr_ref
based_loc_descr (unsigned, long);
3673 static int is_based_loc (rtx
);
3674 static dw_loc_descr_ref
mem_loc_descriptor (rtx
, enum machine_mode mode
);
3675 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
);
3676 static dw_loc_descr_ref
loc_descriptor (rtx
);
3677 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3678 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3679 static tree
field_type (tree
);
3680 static unsigned int simple_type_align_in_bits (tree
);
3681 static unsigned int simple_decl_align_in_bits (tree
);
3682 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (tree
);
3683 static HOST_WIDE_INT
field_byte_offset (tree
);
3684 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3686 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3687 static void add_const_value_attribute (dw_die_ref
, rtx
);
3688 static rtx
rtl_for_decl_location (tree
);
3689 static void add_location_or_const_value_attribute (dw_die_ref
, tree
);
3690 static void tree_add_const_value_attribute (dw_die_ref
, tree
);
3691 static void add_name_attribute (dw_die_ref
, const char *);
3692 static void add_comp_dir_attribute (dw_die_ref
);
3693 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3694 static void add_subscript_info (dw_die_ref
, tree
);
3695 static void add_byte_size_attribute (dw_die_ref
, tree
);
3696 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3697 static void add_bit_size_attribute (dw_die_ref
, tree
);
3698 static void add_prototyped_attribute (dw_die_ref
, tree
);
3699 static void add_abstract_origin_attribute (dw_die_ref
, tree
);
3700 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3701 static void add_src_coords_attributes (dw_die_ref
, tree
);
3702 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3703 static void push_decl_scope (tree
);
3704 static void pop_decl_scope (void);
3705 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3706 static inline int local_scope_p (dw_die_ref
);
3707 static inline int class_scope_p (dw_die_ref
);
3708 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3709 static const char *type_tag (tree
);
3710 static tree
member_declared_type (tree
);
3712 static const char *decl_start_label (tree
);
3714 static void gen_array_type_die (tree
, dw_die_ref
);
3715 static void gen_set_type_die (tree
, dw_die_ref
);
3717 static void gen_entry_point_die (tree
, dw_die_ref
);
3719 static void gen_inlined_enumeration_type_die (tree
, dw_die_ref
);
3720 static void gen_inlined_structure_type_die (tree
, dw_die_ref
);
3721 static void gen_inlined_union_type_die (tree
, dw_die_ref
);
3722 static void gen_enumeration_type_die (tree
, dw_die_ref
);
3723 static dw_die_ref
gen_formal_parameter_die (tree
, dw_die_ref
);
3724 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3725 static void gen_formal_types_die (tree
, dw_die_ref
);
3726 static void gen_subprogram_die (tree
, dw_die_ref
);
3727 static void gen_variable_die (tree
, dw_die_ref
);
3728 static void gen_label_die (tree
, dw_die_ref
);
3729 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3730 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3731 static void gen_field_die (tree
, dw_die_ref
);
3732 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3733 static dw_die_ref
gen_compile_unit_die (const char *);
3734 static void gen_string_type_die (tree
, dw_die_ref
);
3735 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3736 static void gen_member_die (tree
, dw_die_ref
);
3737 static void gen_struct_or_union_type_die (tree
, dw_die_ref
);
3738 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3739 static void gen_typedef_die (tree
, dw_die_ref
);
3740 static void gen_type_die (tree
, dw_die_ref
);
3741 static void gen_tagged_type_instantiation_die (tree
, dw_die_ref
);
3742 static void gen_block_die (tree
, dw_die_ref
, int);
3743 static void decls_for_scope (tree
, dw_die_ref
, int);
3744 static int is_redundant_typedef (tree
);
3745 static void gen_decl_die (tree
, dw_die_ref
);
3746 static unsigned lookup_filename (const char *);
3747 static void init_file_table (void);
3748 static void retry_incomplete_types (void);
3749 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3750 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3751 static int file_info_cmp (const void *, const void *);
3752 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3753 const char *, const char *, unsigned);
3754 static void add_loc_descr_to_loc_list (dw_loc_list_ref
*, dw_loc_descr_ref
,
3755 const char *, const char *,
3757 static void output_loc_list (dw_loc_list_ref
);
3758 static char *gen_internal_sym (const char *);
3760 static void prune_unmark_dies (dw_die_ref
);
3761 static void prune_unused_types_mark (dw_die_ref
, int);
3762 static void prune_unused_types_walk (dw_die_ref
);
3763 static void prune_unused_types_walk_attribs (dw_die_ref
);
3764 static void prune_unused_types_prune (dw_die_ref
);
3765 static void prune_unused_types (void);
3766 static int maybe_emit_file (int);
3768 /* Section names used to hold DWARF debugging information. */
3769 #ifndef DEBUG_INFO_SECTION
3770 #define DEBUG_INFO_SECTION ".debug_info"
3772 #ifndef DEBUG_ABBREV_SECTION
3773 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3775 #ifndef DEBUG_ARANGES_SECTION
3776 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3778 #ifndef DEBUG_MACINFO_SECTION
3779 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3781 #ifndef DEBUG_LINE_SECTION
3782 #define DEBUG_LINE_SECTION ".debug_line"
3784 #ifndef DEBUG_LOC_SECTION
3785 #define DEBUG_LOC_SECTION ".debug_loc"
3787 #ifndef DEBUG_PUBNAMES_SECTION
3788 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3790 #ifndef DEBUG_STR_SECTION
3791 #define DEBUG_STR_SECTION ".debug_str"
3793 #ifndef DEBUG_RANGES_SECTION
3794 #define DEBUG_RANGES_SECTION ".debug_ranges"
3797 /* Standard ELF section names for compiled code and data. */
3798 #ifndef TEXT_SECTION_NAME
3799 #define TEXT_SECTION_NAME ".text"
3802 /* Section flags for .debug_str section. */
3803 #ifdef HAVE_GAS_SHF_MERGE
3804 #define DEBUG_STR_SECTION_FLAGS \
3805 (flag_merge_constants \
3806 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3809 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3812 /* Labels we insert at beginning sections we can reference instead of
3813 the section names themselves. */
3815 #ifndef TEXT_SECTION_LABEL
3816 #define TEXT_SECTION_LABEL "Ltext"
3818 #ifndef DEBUG_LINE_SECTION_LABEL
3819 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3821 #ifndef DEBUG_INFO_SECTION_LABEL
3822 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3824 #ifndef DEBUG_ABBREV_SECTION_LABEL
3825 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3827 #ifndef DEBUG_LOC_SECTION_LABEL
3828 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3830 #ifndef DEBUG_RANGES_SECTION_LABEL
3831 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3833 #ifndef DEBUG_MACINFO_SECTION_LABEL
3834 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3837 /* Definitions of defaults for formats and names of various special
3838 (artificial) labels which may be generated within this file (when the -g
3839 options is used and DWARF_DEBUGGING_INFO is in effect.
3840 If necessary, these may be overridden from within the tm.h file, but
3841 typically, overriding these defaults is unnecessary. */
3843 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3844 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3845 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3846 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3847 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3848 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3849 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3850 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3852 #ifndef TEXT_END_LABEL
3853 #define TEXT_END_LABEL "Letext"
3855 #ifndef BLOCK_BEGIN_LABEL
3856 #define BLOCK_BEGIN_LABEL "LBB"
3858 #ifndef BLOCK_END_LABEL
3859 #define BLOCK_END_LABEL "LBE"
3861 #ifndef LINE_CODE_LABEL
3862 #define LINE_CODE_LABEL "LM"
3864 #ifndef SEPARATE_LINE_CODE_LABEL
3865 #define SEPARATE_LINE_CODE_LABEL "LSM"
3868 /* We allow a language front-end to designate a function that is to be
3869 called to "demangle" any name before it it put into a DIE. */
3871 static const char *(*demangle_name_func
) (const char *);
3874 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3876 demangle_name_func
= func
;
3879 /* Test if rtl node points to a pseudo register. */
3882 is_pseudo_reg (rtx rtl
)
3884 return ((GET_CODE (rtl
) == REG
&& REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3885 || (GET_CODE (rtl
) == SUBREG
3886 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3889 /* Return a reference to a type, with its const and volatile qualifiers
3893 type_main_variant (tree type
)
3895 type
= TYPE_MAIN_VARIANT (type
);
3897 /* ??? There really should be only one main variant among any group of
3898 variants of a given type (and all of the MAIN_VARIANT values for all
3899 members of the group should point to that one type) but sometimes the C
3900 front-end messes this up for array types, so we work around that bug
3902 if (TREE_CODE (type
) == ARRAY_TYPE
)
3903 while (type
!= TYPE_MAIN_VARIANT (type
))
3904 type
= TYPE_MAIN_VARIANT (type
);
3909 /* Return nonzero if the given type node represents a tagged type. */
3912 is_tagged_type (tree type
)
3914 enum tree_code code
= TREE_CODE (type
);
3916 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3917 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3920 /* Convert a DIE tag into its string name. */
3923 dwarf_tag_name (unsigned int tag
)
3927 case DW_TAG_padding
:
3928 return "DW_TAG_padding";
3929 case DW_TAG_array_type
:
3930 return "DW_TAG_array_type";
3931 case DW_TAG_class_type
:
3932 return "DW_TAG_class_type";
3933 case DW_TAG_entry_point
:
3934 return "DW_TAG_entry_point";
3935 case DW_TAG_enumeration_type
:
3936 return "DW_TAG_enumeration_type";
3937 case DW_TAG_formal_parameter
:
3938 return "DW_TAG_formal_parameter";
3939 case DW_TAG_imported_declaration
:
3940 return "DW_TAG_imported_declaration";
3942 return "DW_TAG_label";
3943 case DW_TAG_lexical_block
:
3944 return "DW_TAG_lexical_block";
3946 return "DW_TAG_member";
3947 case DW_TAG_pointer_type
:
3948 return "DW_TAG_pointer_type";
3949 case DW_TAG_reference_type
:
3950 return "DW_TAG_reference_type";
3951 case DW_TAG_compile_unit
:
3952 return "DW_TAG_compile_unit";
3953 case DW_TAG_string_type
:
3954 return "DW_TAG_string_type";
3955 case DW_TAG_structure_type
:
3956 return "DW_TAG_structure_type";
3957 case DW_TAG_subroutine_type
:
3958 return "DW_TAG_subroutine_type";
3959 case DW_TAG_typedef
:
3960 return "DW_TAG_typedef";
3961 case DW_TAG_union_type
:
3962 return "DW_TAG_union_type";
3963 case DW_TAG_unspecified_parameters
:
3964 return "DW_TAG_unspecified_parameters";
3965 case DW_TAG_variant
:
3966 return "DW_TAG_variant";
3967 case DW_TAG_common_block
:
3968 return "DW_TAG_common_block";
3969 case DW_TAG_common_inclusion
:
3970 return "DW_TAG_common_inclusion";
3971 case DW_TAG_inheritance
:
3972 return "DW_TAG_inheritance";
3973 case DW_TAG_inlined_subroutine
:
3974 return "DW_TAG_inlined_subroutine";
3976 return "DW_TAG_module";
3977 case DW_TAG_ptr_to_member_type
:
3978 return "DW_TAG_ptr_to_member_type";
3979 case DW_TAG_set_type
:
3980 return "DW_TAG_set_type";
3981 case DW_TAG_subrange_type
:
3982 return "DW_TAG_subrange_type";
3983 case DW_TAG_with_stmt
:
3984 return "DW_TAG_with_stmt";
3985 case DW_TAG_access_declaration
:
3986 return "DW_TAG_access_declaration";
3987 case DW_TAG_base_type
:
3988 return "DW_TAG_base_type";
3989 case DW_TAG_catch_block
:
3990 return "DW_TAG_catch_block";
3991 case DW_TAG_const_type
:
3992 return "DW_TAG_const_type";
3993 case DW_TAG_constant
:
3994 return "DW_TAG_constant";
3995 case DW_TAG_enumerator
:
3996 return "DW_TAG_enumerator";
3997 case DW_TAG_file_type
:
3998 return "DW_TAG_file_type";
4000 return "DW_TAG_friend";
4001 case DW_TAG_namelist
:
4002 return "DW_TAG_namelist";
4003 case DW_TAG_namelist_item
:
4004 return "DW_TAG_namelist_item";
4005 case DW_TAG_packed_type
:
4006 return "DW_TAG_packed_type";
4007 case DW_TAG_subprogram
:
4008 return "DW_TAG_subprogram";
4009 case DW_TAG_template_type_param
:
4010 return "DW_TAG_template_type_param";
4011 case DW_TAG_template_value_param
:
4012 return "DW_TAG_template_value_param";
4013 case DW_TAG_thrown_type
:
4014 return "DW_TAG_thrown_type";
4015 case DW_TAG_try_block
:
4016 return "DW_TAG_try_block";
4017 case DW_TAG_variant_part
:
4018 return "DW_TAG_variant_part";
4019 case DW_TAG_variable
:
4020 return "DW_TAG_variable";
4021 case DW_TAG_volatile_type
:
4022 return "DW_TAG_volatile_type";
4023 case DW_TAG_MIPS_loop
:
4024 return "DW_TAG_MIPS_loop";
4025 case DW_TAG_format_label
:
4026 return "DW_TAG_format_label";
4027 case DW_TAG_function_template
:
4028 return "DW_TAG_function_template";
4029 case DW_TAG_class_template
:
4030 return "DW_TAG_class_template";
4031 case DW_TAG_GNU_BINCL
:
4032 return "DW_TAG_GNU_BINCL";
4033 case DW_TAG_GNU_EINCL
:
4034 return "DW_TAG_GNU_EINCL";
4036 return "DW_TAG_<unknown>";
4040 /* Convert a DWARF attribute code into its string name. */
4043 dwarf_attr_name (unsigned int attr
)
4048 return "DW_AT_sibling";
4049 case DW_AT_location
:
4050 return "DW_AT_location";
4052 return "DW_AT_name";
4053 case DW_AT_ordering
:
4054 return "DW_AT_ordering";
4055 case DW_AT_subscr_data
:
4056 return "DW_AT_subscr_data";
4057 case DW_AT_byte_size
:
4058 return "DW_AT_byte_size";
4059 case DW_AT_bit_offset
:
4060 return "DW_AT_bit_offset";
4061 case DW_AT_bit_size
:
4062 return "DW_AT_bit_size";
4063 case DW_AT_element_list
:
4064 return "DW_AT_element_list";
4065 case DW_AT_stmt_list
:
4066 return "DW_AT_stmt_list";
4068 return "DW_AT_low_pc";
4070 return "DW_AT_high_pc";
4071 case DW_AT_language
:
4072 return "DW_AT_language";
4074 return "DW_AT_member";
4076 return "DW_AT_discr";
4077 case DW_AT_discr_value
:
4078 return "DW_AT_discr_value";
4079 case DW_AT_visibility
:
4080 return "DW_AT_visibility";
4082 return "DW_AT_import";
4083 case DW_AT_string_length
:
4084 return "DW_AT_string_length";
4085 case DW_AT_common_reference
:
4086 return "DW_AT_common_reference";
4087 case DW_AT_comp_dir
:
4088 return "DW_AT_comp_dir";
4089 case DW_AT_const_value
:
4090 return "DW_AT_const_value";
4091 case DW_AT_containing_type
:
4092 return "DW_AT_containing_type";
4093 case DW_AT_default_value
:
4094 return "DW_AT_default_value";
4096 return "DW_AT_inline";
4097 case DW_AT_is_optional
:
4098 return "DW_AT_is_optional";
4099 case DW_AT_lower_bound
:
4100 return "DW_AT_lower_bound";
4101 case DW_AT_producer
:
4102 return "DW_AT_producer";
4103 case DW_AT_prototyped
:
4104 return "DW_AT_prototyped";
4105 case DW_AT_return_addr
:
4106 return "DW_AT_return_addr";
4107 case DW_AT_start_scope
:
4108 return "DW_AT_start_scope";
4109 case DW_AT_stride_size
:
4110 return "DW_AT_stride_size";
4111 case DW_AT_upper_bound
:
4112 return "DW_AT_upper_bound";
4113 case DW_AT_abstract_origin
:
4114 return "DW_AT_abstract_origin";
4115 case DW_AT_accessibility
:
4116 return "DW_AT_accessibility";
4117 case DW_AT_address_class
:
4118 return "DW_AT_address_class";
4119 case DW_AT_artificial
:
4120 return "DW_AT_artificial";
4121 case DW_AT_base_types
:
4122 return "DW_AT_base_types";
4123 case DW_AT_calling_convention
:
4124 return "DW_AT_calling_convention";
4126 return "DW_AT_count";
4127 case DW_AT_data_member_location
:
4128 return "DW_AT_data_member_location";
4129 case DW_AT_decl_column
:
4130 return "DW_AT_decl_column";
4131 case DW_AT_decl_file
:
4132 return "DW_AT_decl_file";
4133 case DW_AT_decl_line
:
4134 return "DW_AT_decl_line";
4135 case DW_AT_declaration
:
4136 return "DW_AT_declaration";
4137 case DW_AT_discr_list
:
4138 return "DW_AT_discr_list";
4139 case DW_AT_encoding
:
4140 return "DW_AT_encoding";
4141 case DW_AT_external
:
4142 return "DW_AT_external";
4143 case DW_AT_frame_base
:
4144 return "DW_AT_frame_base";
4146 return "DW_AT_friend";
4147 case DW_AT_identifier_case
:
4148 return "DW_AT_identifier_case";
4149 case DW_AT_macro_info
:
4150 return "DW_AT_macro_info";
4151 case DW_AT_namelist_items
:
4152 return "DW_AT_namelist_items";
4153 case DW_AT_priority
:
4154 return "DW_AT_priority";
4156 return "DW_AT_segment";
4157 case DW_AT_specification
:
4158 return "DW_AT_specification";
4159 case DW_AT_static_link
:
4160 return "DW_AT_static_link";
4162 return "DW_AT_type";
4163 case DW_AT_use_location
:
4164 return "DW_AT_use_location";
4165 case DW_AT_variable_parameter
:
4166 return "DW_AT_variable_parameter";
4167 case DW_AT_virtuality
:
4168 return "DW_AT_virtuality";
4169 case DW_AT_vtable_elem_location
:
4170 return "DW_AT_vtable_elem_location";
4172 case DW_AT_allocated
:
4173 return "DW_AT_allocated";
4174 case DW_AT_associated
:
4175 return "DW_AT_associated";
4176 case DW_AT_data_location
:
4177 return "DW_AT_data_location";
4179 return "DW_AT_stride";
4180 case DW_AT_entry_pc
:
4181 return "DW_AT_entry_pc";
4182 case DW_AT_use_UTF8
:
4183 return "DW_AT_use_UTF8";
4184 case DW_AT_extension
:
4185 return "DW_AT_extension";
4187 return "DW_AT_ranges";
4188 case DW_AT_trampoline
:
4189 return "DW_AT_trampoline";
4190 case DW_AT_call_column
:
4191 return "DW_AT_call_column";
4192 case DW_AT_call_file
:
4193 return "DW_AT_call_file";
4194 case DW_AT_call_line
:
4195 return "DW_AT_call_line";
4197 case DW_AT_MIPS_fde
:
4198 return "DW_AT_MIPS_fde";
4199 case DW_AT_MIPS_loop_begin
:
4200 return "DW_AT_MIPS_loop_begin";
4201 case DW_AT_MIPS_tail_loop_begin
:
4202 return "DW_AT_MIPS_tail_loop_begin";
4203 case DW_AT_MIPS_epilog_begin
:
4204 return "DW_AT_MIPS_epilog_begin";
4205 case DW_AT_MIPS_loop_unroll_factor
:
4206 return "DW_AT_MIPS_loop_unroll_factor";
4207 case DW_AT_MIPS_software_pipeline_depth
:
4208 return "DW_AT_MIPS_software_pipeline_depth";
4209 case DW_AT_MIPS_linkage_name
:
4210 return "DW_AT_MIPS_linkage_name";
4211 case DW_AT_MIPS_stride
:
4212 return "DW_AT_MIPS_stride";
4213 case DW_AT_MIPS_abstract_name
:
4214 return "DW_AT_MIPS_abstract_name";
4215 case DW_AT_MIPS_clone_origin
:
4216 return "DW_AT_MIPS_clone_origin";
4217 case DW_AT_MIPS_has_inlines
:
4218 return "DW_AT_MIPS_has_inlines";
4220 case DW_AT_sf_names
:
4221 return "DW_AT_sf_names";
4222 case DW_AT_src_info
:
4223 return "DW_AT_src_info";
4224 case DW_AT_mac_info
:
4225 return "DW_AT_mac_info";
4226 case DW_AT_src_coords
:
4227 return "DW_AT_src_coords";
4228 case DW_AT_body_begin
:
4229 return "DW_AT_body_begin";
4230 case DW_AT_body_end
:
4231 return "DW_AT_body_end";
4232 case DW_AT_GNU_vector
:
4233 return "DW_AT_GNU_vector";
4235 case DW_AT_VMS_rtnbeg_pd_address
:
4236 return "DW_AT_VMS_rtnbeg_pd_address";
4239 return "DW_AT_<unknown>";
4243 /* Convert a DWARF value form code into its string name. */
4246 dwarf_form_name (unsigned int form
)
4251 return "DW_FORM_addr";
4252 case DW_FORM_block2
:
4253 return "DW_FORM_block2";
4254 case DW_FORM_block4
:
4255 return "DW_FORM_block4";
4257 return "DW_FORM_data2";
4259 return "DW_FORM_data4";
4261 return "DW_FORM_data8";
4262 case DW_FORM_string
:
4263 return "DW_FORM_string";
4265 return "DW_FORM_block";
4266 case DW_FORM_block1
:
4267 return "DW_FORM_block1";
4269 return "DW_FORM_data1";
4271 return "DW_FORM_flag";
4273 return "DW_FORM_sdata";
4275 return "DW_FORM_strp";
4277 return "DW_FORM_udata";
4278 case DW_FORM_ref_addr
:
4279 return "DW_FORM_ref_addr";
4281 return "DW_FORM_ref1";
4283 return "DW_FORM_ref2";
4285 return "DW_FORM_ref4";
4287 return "DW_FORM_ref8";
4288 case DW_FORM_ref_udata
:
4289 return "DW_FORM_ref_udata";
4290 case DW_FORM_indirect
:
4291 return "DW_FORM_indirect";
4293 return "DW_FORM_<unknown>";
4297 /* Convert a DWARF type code into its string name. */
4301 dwarf_type_encoding_name (unsigned enc
)
4305 case DW_ATE_address
:
4306 return "DW_ATE_address";
4307 case DW_ATE_boolean
:
4308 return "DW_ATE_boolean";
4309 case DW_ATE_complex_float
:
4310 return "DW_ATE_complex_float";
4312 return "DW_ATE_float";
4314 return "DW_ATE_signed";
4315 case DW_ATE_signed_char
:
4316 return "DW_ATE_signed_char";
4317 case DW_ATE_unsigned
:
4318 return "DW_ATE_unsigned";
4319 case DW_ATE_unsigned_char
:
4320 return "DW_ATE_unsigned_char";
4322 return "DW_ATE_<unknown>";
4327 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4328 instance of an inlined instance of a decl which is local to an inline
4329 function, so we have to trace all of the way back through the origin chain
4330 to find out what sort of node actually served as the original seed for the
4334 decl_ultimate_origin (tree decl
)
4336 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4337 nodes in the function to point to themselves; ignore that if
4338 we're trying to output the abstract instance of this function. */
4339 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4342 #ifdef ENABLE_CHECKING
4343 if (DECL_FROM_INLINE (DECL_ORIGIN (decl
)))
4344 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4345 most distant ancestor, this should never happen. */
4349 return DECL_ABSTRACT_ORIGIN (decl
);
4352 /* Determine the "ultimate origin" of a block. The block may be an inlined
4353 instance of an inlined instance of a block which is local to an inline
4354 function, so we have to trace all of the way back through the origin chain
4355 to find out what sort of node actually served as the original seed for the
4359 block_ultimate_origin (tree block
)
4361 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4363 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4364 nodes in the function to point to themselves; ignore that if
4365 we're trying to output the abstract instance of this function. */
4366 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4369 if (immediate_origin
== NULL_TREE
)
4374 tree lookahead
= immediate_origin
;
4378 ret_val
= lookahead
;
4379 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4380 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4382 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4388 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4389 of a virtual function may refer to a base class, so we check the 'this'
4393 decl_class_context (tree decl
)
4395 tree context
= NULL_TREE
;
4397 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4398 context
= DECL_CONTEXT (decl
);
4400 context
= TYPE_MAIN_VARIANT
4401 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4403 if (context
&& !TYPE_P (context
))
4404 context
= NULL_TREE
;
4409 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4410 addition order, and correct that in reverse_all_dies. */
4413 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
4415 if (die
!= NULL
&& attr
!= NULL
)
4417 attr
->dw_attr_next
= die
->die_attr
;
4418 die
->die_attr
= attr
;
4422 static inline enum dw_val_class
4423 AT_class (dw_attr_ref a
)
4425 return a
->dw_attr_val
.val_class
;
4428 /* Add a flag value attribute to a DIE. */
4431 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4433 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4435 attr
->dw_attr_next
= NULL
;
4436 attr
->dw_attr
= attr_kind
;
4437 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
4438 attr
->dw_attr_val
.v
.val_flag
= flag
;
4439 add_dwarf_attr (die
, attr
);
4442 static inline unsigned
4443 AT_flag (dw_attr_ref a
)
4445 if (a
&& AT_class (a
) == dw_val_class_flag
)
4446 return a
->dw_attr_val
.v
.val_flag
;
4451 /* Add a signed integer attribute value to a DIE. */
4454 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, long int int_val
)
4456 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4458 attr
->dw_attr_next
= NULL
;
4459 attr
->dw_attr
= attr_kind
;
4460 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
4461 attr
->dw_attr_val
.v
.val_int
= int_val
;
4462 add_dwarf_attr (die
, attr
);
4465 static inline long int
4466 AT_int (dw_attr_ref a
)
4468 if (a
&& AT_class (a
) == dw_val_class_const
)
4469 return a
->dw_attr_val
.v
.val_int
;
4474 /* Add an unsigned integer attribute value to a DIE. */
4477 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4478 long unsigned int unsigned_val
)
4480 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4482 attr
->dw_attr_next
= NULL
;
4483 attr
->dw_attr
= attr_kind
;
4484 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4485 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4486 add_dwarf_attr (die
, attr
);
4489 static inline unsigned long
4490 AT_unsigned (dw_attr_ref a
)
4492 if (a
&& AT_class (a
) == dw_val_class_unsigned_const
)
4493 return a
->dw_attr_val
.v
.val_unsigned
;
4498 /* Add an unsigned double integer attribute value to a DIE. */
4501 add_AT_long_long (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4502 long unsigned int val_hi
, long unsigned int val_low
)
4504 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4506 attr
->dw_attr_next
= NULL
;
4507 attr
->dw_attr
= attr_kind
;
4508 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
4509 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4510 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
4511 add_dwarf_attr (die
, attr
);
4514 /* Add a floating point attribute value to a DIE and return it. */
4517 add_AT_float (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4518 unsigned int length
, long int *array
)
4520 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4522 attr
->dw_attr_next
= NULL
;
4523 attr
->dw_attr
= attr_kind
;
4524 attr
->dw_attr_val
.val_class
= dw_val_class_float
;
4525 attr
->dw_attr_val
.v
.val_float
.length
= length
;
4526 attr
->dw_attr_val
.v
.val_float
.array
= array
;
4527 add_dwarf_attr (die
, attr
);
4530 /* Hash and equality functions for debug_str_hash. */
4533 debug_str_do_hash (const void *x
)
4535 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
4539 debug_str_eq (const void *x1
, const void *x2
)
4541 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
4542 (const char *)x2
) == 0;
4545 /* Add a string attribute value to a DIE. */
4548 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4550 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4551 struct indirect_string_node
*node
;
4554 if (! debug_str_hash
)
4555 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
4556 debug_str_eq
, NULL
);
4558 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
4559 htab_hash_string (str
), INSERT
);
4561 *slot
= ggc_alloc_cleared (sizeof (struct indirect_string_node
));
4562 node
= (struct indirect_string_node
*) *slot
;
4563 node
->str
= ggc_strdup (str
);
4566 attr
->dw_attr_next
= NULL
;
4567 attr
->dw_attr
= attr_kind
;
4568 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
4569 attr
->dw_attr_val
.v
.val_str
= node
;
4570 add_dwarf_attr (die
, attr
);
4573 static inline const char *
4574 AT_string (dw_attr_ref a
)
4576 if (a
&& AT_class (a
) == dw_val_class_str
)
4577 return a
->dw_attr_val
.v
.val_str
->str
;
4582 /* Find out whether a string should be output inline in DIE
4583 or out-of-line in .debug_str section. */
4586 AT_string_form (dw_attr_ref a
)
4588 if (a
&& AT_class (a
) == dw_val_class_str
)
4590 struct indirect_string_node
*node
;
4594 node
= a
->dw_attr_val
.v
.val_str
;
4598 len
= strlen (node
->str
) + 1;
4600 /* If the string is shorter or equal to the size of the reference, it is
4601 always better to put it inline. */
4602 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4603 return node
->form
= DW_FORM_string
;
4605 /* If we cannot expect the linker to merge strings in .debug_str
4606 section, only put it into .debug_str if it is worth even in this
4608 if ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) == 0
4609 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
4610 return node
->form
= DW_FORM_string
;
4612 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4613 ++dw2_string_counter
;
4614 node
->label
= xstrdup (label
);
4616 return node
->form
= DW_FORM_strp
;
4622 /* Add a DIE reference attribute value to a DIE. */
4625 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4627 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4629 attr
->dw_attr_next
= NULL
;
4630 attr
->dw_attr
= attr_kind
;
4631 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
4632 attr
->dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4633 attr
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4634 add_dwarf_attr (die
, attr
);
4637 static inline dw_die_ref
4638 AT_ref (dw_attr_ref a
)
4640 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4641 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4647 AT_ref_external (dw_attr_ref a
)
4649 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4650 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4656 set_AT_ref_external (dw_attr_ref a
, int i
)
4658 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4659 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4664 /* Add an FDE reference attribute value to a DIE. */
4667 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4669 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4671 attr
->dw_attr_next
= NULL
;
4672 attr
->dw_attr
= attr_kind
;
4673 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4674 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
4675 add_dwarf_attr (die
, attr
);
4678 /* Add a location description attribute value to a DIE. */
4681 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4683 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4685 attr
->dw_attr_next
= NULL
;
4686 attr
->dw_attr
= attr_kind
;
4687 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
4688 attr
->dw_attr_val
.v
.val_loc
= loc
;
4689 add_dwarf_attr (die
, attr
);
4692 static inline dw_loc_descr_ref
4693 AT_loc (dw_attr_ref a
)
4695 if (a
&& AT_class (a
) == dw_val_class_loc
)
4696 return a
->dw_attr_val
.v
.val_loc
;
4702 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4704 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4706 attr
->dw_attr_next
= NULL
;
4707 attr
->dw_attr
= attr_kind
;
4708 attr
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
4709 attr
->dw_attr_val
.v
.val_loc_list
= loc_list
;
4710 add_dwarf_attr (die
, attr
);
4711 have_location_lists
= 1;
4714 static inline dw_loc_list_ref
4715 AT_loc_list (dw_attr_ref a
)
4717 if (a
&& AT_class (a
) == dw_val_class_loc_list
)
4718 return a
->dw_attr_val
.v
.val_loc_list
;
4723 /* Add an address constant attribute value to a DIE. */
4726 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
4728 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4730 attr
->dw_attr_next
= NULL
;
4731 attr
->dw_attr
= attr_kind
;
4732 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
4733 attr
->dw_attr_val
.v
.val_addr
= addr
;
4734 add_dwarf_attr (die
, attr
);
4738 AT_addr (dw_attr_ref a
)
4740 if (a
&& AT_class (a
) == dw_val_class_addr
)
4741 return a
->dw_attr_val
.v
.val_addr
;
4746 /* Add a label identifier attribute value to a DIE. */
4749 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
4751 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4753 attr
->dw_attr_next
= NULL
;
4754 attr
->dw_attr
= attr_kind
;
4755 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4756 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4757 add_dwarf_attr (die
, attr
);
4760 /* Add a section offset attribute value to a DIE. */
4763 add_AT_lbl_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *label
)
4765 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4767 attr
->dw_attr_next
= NULL
;
4768 attr
->dw_attr
= attr_kind
;
4769 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_offset
;
4770 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4771 add_dwarf_attr (die
, attr
);
4774 /* Add an offset attribute value to a DIE. */
4777 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
, long unsigned int offset
)
4779 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4781 attr
->dw_attr_next
= NULL
;
4782 attr
->dw_attr
= attr_kind
;
4783 attr
->dw_attr_val
.val_class
= dw_val_class_offset
;
4784 attr
->dw_attr_val
.v
.val_offset
= offset
;
4785 add_dwarf_attr (die
, attr
);
4788 /* Add an range_list attribute value to a DIE. */
4791 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4792 long unsigned int offset
)
4794 dw_attr_ref attr
= (dw_attr_ref
) ggc_alloc (sizeof (dw_attr_node
));
4796 attr
->dw_attr_next
= NULL
;
4797 attr
->dw_attr
= attr_kind
;
4798 attr
->dw_attr_val
.val_class
= dw_val_class_range_list
;
4799 attr
->dw_attr_val
.v
.val_offset
= offset
;
4800 add_dwarf_attr (die
, attr
);
4803 static inline const char *
4804 AT_lbl (dw_attr_ref a
)
4806 if (a
&& (AT_class (a
) == dw_val_class_lbl_id
4807 || AT_class (a
) == dw_val_class_lbl_offset
))
4808 return a
->dw_attr_val
.v
.val_lbl_id
;
4813 /* Get the attribute of type attr_kind. */
4815 static inline dw_attr_ref
4816 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4819 dw_die_ref spec
= NULL
;
4823 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4824 if (a
->dw_attr
== attr_kind
)
4826 else if (a
->dw_attr
== DW_AT_specification
4827 || a
->dw_attr
== DW_AT_abstract_origin
)
4831 return get_AT (spec
, attr_kind
);
4837 /* Return the "low pc" attribute value, typically associated with a subprogram
4838 DIE. Return null if the "low pc" attribute is either not present, or if it
4839 cannot be represented as an assembler label identifier. */
4841 static inline const char *
4842 get_AT_low_pc (dw_die_ref die
)
4844 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4846 return a
? AT_lbl (a
) : NULL
;
4849 /* Return the "high pc" attribute value, typically associated with a subprogram
4850 DIE. Return null if the "high pc" attribute is either not present, or if it
4851 cannot be represented as an assembler label identifier. */
4853 static inline const char *
4854 get_AT_hi_pc (dw_die_ref die
)
4856 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4858 return a
? AT_lbl (a
) : NULL
;
4861 /* Return the value of the string attribute designated by ATTR_KIND, or
4862 NULL if it is not present. */
4864 static inline const char *
4865 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4867 dw_attr_ref a
= get_AT (die
, attr_kind
);
4869 return a
? AT_string (a
) : NULL
;
4872 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4873 if it is not present. */
4876 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4878 dw_attr_ref a
= get_AT (die
, attr_kind
);
4880 return a
? AT_flag (a
) : 0;
4883 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4884 if it is not present. */
4886 static inline unsigned
4887 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4889 dw_attr_ref a
= get_AT (die
, attr_kind
);
4891 return a
? AT_unsigned (a
) : 0;
4894 static inline dw_die_ref
4895 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4897 dw_attr_ref a
= get_AT (die
, attr_kind
);
4899 return a
? AT_ref (a
) : NULL
;
4902 /* Return TRUE if the language is C or C++. */
4907 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4909 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
4910 || lang
== DW_LANG_C_plus_plus
);
4913 /* Return TRUE if the language is C++. */
4918 return (get_AT_unsigned (comp_unit_die
, DW_AT_language
)
4919 == DW_LANG_C_plus_plus
);
4922 /* Return TRUE if the language is Fortran. */
4927 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4929 return lang
== DW_LANG_Fortran77
|| lang
== DW_LANG_Fortran90
;
4932 /* Return TRUE if the language is Java. */
4937 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4939 return lang
== DW_LANG_Java
;
4942 /* Return TRUE if the language is Ada. */
4947 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4949 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4952 /* Free up the memory used by A. */
4954 static inline void free_AT (dw_attr_ref
);
4956 free_AT (dw_attr_ref a
)
4958 if (AT_class (a
) == dw_val_class_str
)
4959 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4960 a
->dw_attr_val
.v
.val_str
->refcount
--;
4963 /* Remove the specified attribute if present. */
4966 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4969 dw_attr_ref removed
= NULL
;
4973 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
4974 if ((*p
)->dw_attr
== attr_kind
)
4977 *p
= (*p
)->dw_attr_next
;
4986 /* Free up the memory used by DIE. */
4989 free_die (dw_die_ref die
)
4991 remove_children (die
);
4994 /* Discard the children of this DIE. */
4997 remove_children (dw_die_ref die
)
4999 dw_die_ref child_die
= die
->die_child
;
5001 die
->die_child
= NULL
;
5003 while (child_die
!= NULL
)
5005 dw_die_ref tmp_die
= child_die
;
5008 child_die
= child_die
->die_sib
;
5010 for (a
= tmp_die
->die_attr
; a
!= NULL
;)
5012 dw_attr_ref tmp_a
= a
;
5014 a
= a
->dw_attr_next
;
5022 /* Add a child DIE below its parent. We build the lists up in reverse
5023 addition order, and correct that in reverse_all_dies. */
5026 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5028 if (die
!= NULL
&& child_die
!= NULL
)
5030 if (die
== child_die
)
5033 child_die
->die_parent
= die
;
5034 child_die
->die_sib
= die
->die_child
;
5035 die
->die_child
= child_die
;
5039 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5040 is the specification, to the front of PARENT's list of children. */
5043 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5047 /* We want the declaration DIE from inside the class, not the
5048 specification DIE at toplevel. */
5049 if (child
->die_parent
!= parent
)
5051 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5057 if (child
->die_parent
!= parent
5058 && child
->die_parent
!= get_AT_ref (parent
, DW_AT_specification
))
5061 for (p
= &(child
->die_parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
5064 *p
= child
->die_sib
;
5068 child
->die_parent
= parent
;
5069 child
->die_sib
= parent
->die_child
;
5070 parent
->die_child
= child
;
5073 /* Return a pointer to a newly created DIE node. */
5075 static inline dw_die_ref
5076 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5078 dw_die_ref die
= (dw_die_ref
) ggc_alloc_cleared (sizeof (die_node
));
5080 die
->die_tag
= tag_value
;
5082 if (parent_die
!= NULL
)
5083 add_child_die (parent_die
, die
);
5086 limbo_die_node
*limbo_node
;
5088 limbo_node
= ggc_alloc_cleared (sizeof (limbo_die_node
));
5089 limbo_node
->die
= die
;
5090 limbo_node
->created_for
= t
;
5091 limbo_node
->next
= limbo_die_list
;
5092 limbo_die_list
= limbo_node
;
5098 /* Return the DIE associated with the given type specifier. */
5100 static inline dw_die_ref
5101 lookup_type_die (tree type
)
5103 return TYPE_SYMTAB_DIE (type
);
5106 /* Equate a DIE to a given type specifier. */
5109 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5111 TYPE_SYMTAB_DIE (type
) = type_die
;
5114 /* Return the DIE associated with a given declaration. */
5116 static inline dw_die_ref
5117 lookup_decl_die (tree decl
)
5119 unsigned decl_id
= DECL_UID (decl
);
5121 return (decl_id
< decl_die_table_in_use
? decl_die_table
[decl_id
] : NULL
);
5124 /* Equate a DIE to a particular declaration. */
5127 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5129 unsigned int decl_id
= DECL_UID (decl
);
5130 unsigned int num_allocated
;
5132 if (decl_id
>= decl_die_table_allocated
)
5135 = ((decl_id
+ 1 + DECL_DIE_TABLE_INCREMENT
- 1)
5136 / DECL_DIE_TABLE_INCREMENT
)
5137 * DECL_DIE_TABLE_INCREMENT
;
5139 decl_die_table
= ggc_realloc (decl_die_table
,
5140 sizeof (dw_die_ref
) * num_allocated
);
5142 memset ((char *) &decl_die_table
[decl_die_table_allocated
], 0,
5143 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
5144 decl_die_table_allocated
= num_allocated
;
5147 if (decl_id
>= decl_die_table_in_use
)
5148 decl_die_table_in_use
= (decl_id
+ 1);
5150 decl_die_table
[decl_id
] = decl_die
;
5153 /* Keep track of the number of spaces used to indent the
5154 output of the debugging routines that print the structure of
5155 the DIE internal representation. */
5156 static int print_indent
;
5158 /* Indent the line the number of spaces given by print_indent. */
5161 print_spaces (FILE *outfile
)
5163 fprintf (outfile
, "%*s", print_indent
, "");
5166 /* Print the information associated with a given DIE, and its children.
5167 This routine is a debugging aid only. */
5170 print_die (dw_die_ref die
, FILE *outfile
)
5175 print_spaces (outfile
);
5176 fprintf (outfile
, "DIE %4lu: %s\n",
5177 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5178 print_spaces (outfile
);
5179 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5180 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
5182 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5184 print_spaces (outfile
);
5185 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5187 switch (AT_class (a
))
5189 case dw_val_class_addr
:
5190 fprintf (outfile
, "address");
5192 case dw_val_class_offset
:
5193 fprintf (outfile
, "offset");
5195 case dw_val_class_loc
:
5196 fprintf (outfile
, "location descriptor");
5198 case dw_val_class_loc_list
:
5199 fprintf (outfile
, "location list -> label:%s",
5200 AT_loc_list (a
)->ll_symbol
);
5202 case dw_val_class_range_list
:
5203 fprintf (outfile
, "range list");
5205 case dw_val_class_const
:
5206 fprintf (outfile
, "%ld", AT_int (a
));
5208 case dw_val_class_unsigned_const
:
5209 fprintf (outfile
, "%lu", AT_unsigned (a
));
5211 case dw_val_class_long_long
:
5212 fprintf (outfile
, "constant (%lu,%lu)",
5213 a
->dw_attr_val
.v
.val_long_long
.hi
,
5214 a
->dw_attr_val
.v
.val_long_long
.low
);
5216 case dw_val_class_float
:
5217 fprintf (outfile
, "floating-point constant");
5219 case dw_val_class_flag
:
5220 fprintf (outfile
, "%u", AT_flag (a
));
5222 case dw_val_class_die_ref
:
5223 if (AT_ref (a
) != NULL
)
5225 if (AT_ref (a
)->die_symbol
)
5226 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5228 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
5231 fprintf (outfile
, "die -> <null>");
5233 case dw_val_class_lbl_id
:
5234 case dw_val_class_lbl_offset
:
5235 fprintf (outfile
, "label: %s", AT_lbl (a
));
5237 case dw_val_class_str
:
5238 if (AT_string (a
) != NULL
)
5239 fprintf (outfile
, "\"%s\"", AT_string (a
));
5241 fprintf (outfile
, "<null>");
5247 fprintf (outfile
, "\n");
5250 if (die
->die_child
!= NULL
)
5253 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5254 print_die (c
, outfile
);
5258 if (print_indent
== 0)
5259 fprintf (outfile
, "\n");
5262 /* Print the contents of the source code line number correspondence table.
5263 This routine is a debugging aid only. */
5266 print_dwarf_line_table (FILE *outfile
)
5269 dw_line_info_ref line_info
;
5271 fprintf (outfile
, "\n\nDWARF source line information\n");
5272 for (i
= 1; i
< line_info_table_in_use
; i
++)
5274 line_info
= &line_info_table
[i
];
5275 fprintf (outfile
, "%5d: ", i
);
5276 fprintf (outfile
, "%-20s",
5277 VARRAY_CHAR_PTR (file_table
, line_info
->dw_file_num
));
5278 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
5279 fprintf (outfile
, "\n");
5282 fprintf (outfile
, "\n\n");
5285 /* Print the information collected for a given DIE. */
5288 debug_dwarf_die (dw_die_ref die
)
5290 print_die (die
, stderr
);
5293 /* Print all DWARF information collected for the compilation unit.
5294 This routine is a debugging aid only. */
5300 print_die (comp_unit_die
, stderr
);
5301 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5302 print_dwarf_line_table (stderr
);
5305 /* We build up the lists of children and attributes by pushing new ones
5306 onto the beginning of the list. Reverse the lists for DIE so that
5307 they are in order of addition. */
5310 reverse_die_lists (dw_die_ref die
)
5312 dw_die_ref c
, cp
, cn
;
5313 dw_attr_ref a
, ap
, an
;
5315 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
5317 an
= a
->dw_attr_next
;
5318 a
->dw_attr_next
= ap
;
5324 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
5331 die
->die_child
= cp
;
5334 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5335 reverse all dies in add_sibling_attributes, which runs through all the dies,
5336 it would reverse all the dies. Now, however, since we don't call
5337 reverse_die_lists in add_sibling_attributes, we need a routine to
5338 recursively reverse all the dies. This is that routine. */
5341 reverse_all_dies (dw_die_ref die
)
5345 reverse_die_lists (die
);
5347 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5348 reverse_all_dies (c
);
5351 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5352 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5353 DIE that marks the start of the DIEs for this include file. */
5356 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5358 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5359 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5361 new_unit
->die_sib
= old_unit
;
5365 /* Close an include-file CU and reopen the enclosing one. */
5368 pop_compile_unit (dw_die_ref old_unit
)
5370 dw_die_ref new_unit
= old_unit
->die_sib
;
5372 old_unit
->die_sib
= NULL
;
5376 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5377 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5379 /* Calculate the checksum of a location expression. */
5382 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5384 CHECKSUM (loc
->dw_loc_opc
);
5385 CHECKSUM (loc
->dw_loc_oprnd1
);
5386 CHECKSUM (loc
->dw_loc_oprnd2
);
5389 /* Calculate the checksum of an attribute. */
5392 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5394 dw_loc_descr_ref loc
;
5397 CHECKSUM (at
->dw_attr
);
5399 /* We don't care about differences in file numbering. */
5400 if (at
->dw_attr
== DW_AT_decl_file
5401 /* Or that this was compiled with a different compiler snapshot; if
5402 the output is the same, that's what matters. */
5403 || at
->dw_attr
== DW_AT_producer
)
5406 switch (AT_class (at
))
5408 case dw_val_class_const
:
5409 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5411 case dw_val_class_unsigned_const
:
5412 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5414 case dw_val_class_long_long
:
5415 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
5417 case dw_val_class_float
:
5418 CHECKSUM (at
->dw_attr_val
.v
.val_float
);
5420 case dw_val_class_flag
:
5421 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5423 case dw_val_class_str
:
5424 CHECKSUM_STRING (AT_string (at
));
5427 case dw_val_class_addr
:
5429 switch (GET_CODE (r
))
5432 CHECKSUM_STRING (XSTR (r
, 0));
5440 case dw_val_class_offset
:
5441 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5444 case dw_val_class_loc
:
5445 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5446 loc_checksum (loc
, ctx
);
5449 case dw_val_class_die_ref
:
5450 die_checksum (AT_ref (at
), ctx
, mark
);
5453 case dw_val_class_fde_ref
:
5454 case dw_val_class_lbl_id
:
5455 case dw_val_class_lbl_offset
:
5463 /* Calculate the checksum of a DIE. */
5466 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5471 /* To avoid infinite recursion. */
5474 CHECKSUM (die
->die_mark
);
5477 die
->die_mark
= ++(*mark
);
5479 CHECKSUM (die
->die_tag
);
5481 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
5482 attr_checksum (a
, ctx
, mark
);
5484 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5485 die_checksum (c
, ctx
, mark
);
5489 #undef CHECKSUM_STRING
5491 /* Do the location expressions look same? */
5493 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
5495 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
5496 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
5497 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
5500 /* Do the values look the same? */
5502 same_dw_val_p (dw_val_node
*v1
, dw_val_node
*v2
, int *mark
)
5504 dw_loc_descr_ref loc1
, loc2
;
5508 if (v1
->val_class
!= v2
->val_class
)
5511 switch (v1
->val_class
)
5513 case dw_val_class_const
:
5514 return v1
->v
.val_int
== v2
->v
.val_int
;
5515 case dw_val_class_unsigned_const
:
5516 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
5517 case dw_val_class_long_long
:
5518 return v1
->v
.val_long_long
.hi
== v2
->v
.val_long_long
.hi
5519 && v1
->v
.val_long_long
.low
== v2
->v
.val_long_long
.low
;
5520 case dw_val_class_float
:
5521 if (v1
->v
.val_float
.length
!= v2
->v
.val_float
.length
)
5523 for (i
= 0; i
< v1
->v
.val_float
.length
; i
++)
5524 if (v1
->v
.val_float
.array
[i
] != v2
->v
.val_float
.array
[i
])
5527 case dw_val_class_flag
:
5528 return v1
->v
.val_flag
== v2
->v
.val_flag
;
5529 case dw_val_class_str
:
5530 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
5532 case dw_val_class_addr
:
5533 r1
= v1
->v
.val_addr
;
5534 r2
= v2
->v
.val_addr
;
5535 if (GET_CODE (r1
) != GET_CODE (r2
))
5537 switch (GET_CODE (r1
))
5540 return !strcmp (XSTR (r1
, 0), XSTR (r2
, 0));
5546 case dw_val_class_offset
:
5547 return v1
->v
.val_offset
== v2
->v
.val_offset
;
5549 case dw_val_class_loc
:
5550 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
5552 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
5553 if (!same_loc_p (loc1
, loc2
, mark
))
5555 return !loc1
&& !loc2
;
5557 case dw_val_class_die_ref
:
5558 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
5560 case dw_val_class_fde_ref
:
5561 case dw_val_class_lbl_id
:
5562 case dw_val_class_lbl_offset
:
5570 /* Do the attributes look the same? */
5573 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
5575 if (at1
->dw_attr
!= at2
->dw_attr
)
5578 /* We don't care about differences in file numbering. */
5579 if (at1
->dw_attr
== DW_AT_decl_file
5580 /* Or that this was compiled with a different compiler snapshot; if
5581 the output is the same, that's what matters. */
5582 || at1
->dw_attr
== DW_AT_producer
)
5585 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
5588 /* Do the dies look the same? */
5591 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
5596 /* To avoid infinite recursion. */
5598 return die1
->die_mark
== die2
->die_mark
;
5599 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
5601 if (die1
->die_tag
!= die2
->die_tag
)
5604 for (a1
= die1
->die_attr
, a2
= die2
->die_attr
;
5606 a1
= a1
->dw_attr_next
, a2
= a2
->dw_attr_next
)
5607 if (!same_attr_p (a1
, a2
, mark
))
5612 for (c1
= die1
->die_child
, c2
= die2
->die_child
;
5614 c1
= c1
->die_sib
, c2
= c2
->die_sib
)
5615 if (!same_die_p (c1
, c2
, mark
))
5623 /* Do the dies look the same? Wrapper around same_die_p. */
5626 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
5629 int ret
= same_die_p (die1
, die2
, &mark
);
5631 unmark_all_dies (die1
);
5632 unmark_all_dies (die2
);
5637 /* The prefix to attach to symbols on DIEs in the current comdat debug
5639 static char *comdat_symbol_id
;
5641 /* The index of the current symbol within the current comdat CU. */
5642 static unsigned int comdat_symbol_number
;
5644 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5645 children, and set comdat_symbol_id accordingly. */
5648 compute_section_prefix (dw_die_ref unit_die
)
5650 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
5651 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
5652 char *name
= (char *) alloca (strlen (base
) + 64);
5655 unsigned char checksum
[16];
5658 /* Compute the checksum of the DIE, then append part of it as hex digits to
5659 the name filename of the unit. */
5661 md5_init_ctx (&ctx
);
5663 die_checksum (unit_die
, &ctx
, &mark
);
5664 unmark_all_dies (unit_die
);
5665 md5_finish_ctx (&ctx
, checksum
);
5667 sprintf (name
, "%s.", base
);
5668 clean_symbol_name (name
);
5670 p
= name
+ strlen (name
);
5671 for (i
= 0; i
< 4; i
++)
5673 sprintf (p
, "%.2x", checksum
[i
]);
5677 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
5678 comdat_symbol_number
= 0;
5681 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5684 is_type_die (dw_die_ref die
)
5686 switch (die
->die_tag
)
5688 case DW_TAG_array_type
:
5689 case DW_TAG_class_type
:
5690 case DW_TAG_enumeration_type
:
5691 case DW_TAG_pointer_type
:
5692 case DW_TAG_reference_type
:
5693 case DW_TAG_string_type
:
5694 case DW_TAG_structure_type
:
5695 case DW_TAG_subroutine_type
:
5696 case DW_TAG_union_type
:
5697 case DW_TAG_ptr_to_member_type
:
5698 case DW_TAG_set_type
:
5699 case DW_TAG_subrange_type
:
5700 case DW_TAG_base_type
:
5701 case DW_TAG_const_type
:
5702 case DW_TAG_file_type
:
5703 case DW_TAG_packed_type
:
5704 case DW_TAG_volatile_type
:
5705 case DW_TAG_typedef
:
5712 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5713 Basically, we want to choose the bits that are likely to be shared between
5714 compilations (types) and leave out the bits that are specific to individual
5715 compilations (functions). */
5718 is_comdat_die (dw_die_ref c
)
5720 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5721 we do for stabs. The advantage is a greater likelihood of sharing between
5722 objects that don't include headers in the same order (and therefore would
5723 put the base types in a different comdat). jason 8/28/00 */
5725 if (c
->die_tag
== DW_TAG_base_type
)
5728 if (c
->die_tag
== DW_TAG_pointer_type
5729 || c
->die_tag
== DW_TAG_reference_type
5730 || c
->die_tag
== DW_TAG_const_type
5731 || c
->die_tag
== DW_TAG_volatile_type
)
5733 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
5735 return t
? is_comdat_die (t
) : 0;
5738 return is_type_die (c
);
5741 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5742 compilation unit. */
5745 is_symbol_die (dw_die_ref c
)
5747 return (is_type_die (c
)
5748 || (get_AT (c
, DW_AT_declaration
)
5749 && !get_AT (c
, DW_AT_specification
)));
5753 gen_internal_sym (const char *prefix
)
5757 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
5758 return xstrdup (buf
);
5761 /* Assign symbols to all worthy DIEs under DIE. */
5764 assign_symbol_names (dw_die_ref die
)
5768 if (is_symbol_die (die
))
5770 if (comdat_symbol_id
)
5772 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
5774 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
5775 comdat_symbol_id
, comdat_symbol_number
++);
5776 die
->die_symbol
= xstrdup (p
);
5779 die
->die_symbol
= gen_internal_sym ("LDIE");
5782 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5783 assign_symbol_names (c
);
5786 struct cu_hash_table_entry
5789 unsigned min_comdat_num
, max_comdat_num
;
5790 struct cu_hash_table_entry
*next
;
5793 /* Routines to manipulate hash table of CUs. */
5795 htab_cu_hash (const void *of
)
5797 const struct cu_hash_table_entry
*entry
= of
;
5799 return htab_hash_string (entry
->cu
->die_symbol
);
5803 htab_cu_eq (const void *of1
, const void *of2
)
5805 const struct cu_hash_table_entry
*entry1
= of1
;
5806 const struct die_struct
*entry2
= of2
;
5808 return !strcmp (entry1
->cu
->die_symbol
, entry2
->die_symbol
);
5812 htab_cu_del (void *what
)
5814 struct cu_hash_table_entry
*next
, *entry
= what
;
5824 /* Check whether we have already seen this CU and set up SYM_NUM
5827 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
5829 struct cu_hash_table_entry dummy
;
5830 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
5832 dummy
.max_comdat_num
= 0;
5834 slot
= (struct cu_hash_table_entry
**)
5835 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
5839 for (; entry
; last
= entry
, entry
= entry
->next
)
5841 if (same_die_p_wrap (cu
, entry
->cu
))
5847 *sym_num
= entry
->min_comdat_num
;
5851 entry
= xcalloc (1, sizeof (struct cu_hash_table_entry
));
5853 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
5854 entry
->next
= *slot
;
5860 /* Record SYM_NUM to record of CU in HTABLE. */
5862 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
5864 struct cu_hash_table_entry
**slot
, *entry
;
5866 slot
= (struct cu_hash_table_entry
**)
5867 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
5871 entry
->max_comdat_num
= sym_num
;
5874 /* Traverse the DIE (which is always comp_unit_die), and set up
5875 additional compilation units for each of the include files we see
5876 bracketed by BINCL/EINCL. */
5879 break_out_includes (dw_die_ref die
)
5882 dw_die_ref unit
= NULL
;
5883 limbo_die_node
*node
, **pnode
;
5884 htab_t cu_hash_table
;
5886 for (ptr
= &(die
->die_child
); *ptr
;)
5888 dw_die_ref c
= *ptr
;
5890 if (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
5891 || (unit
&& is_comdat_die (c
)))
5893 /* This DIE is for a secondary CU; remove it from the main one. */
5896 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
5898 unit
= push_new_compile_unit (unit
, c
);
5901 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
5903 unit
= pop_compile_unit (unit
);
5907 add_child_die (unit
, c
);
5911 /* Leave this DIE in the main CU. */
5912 ptr
= &(c
->die_sib
);
5918 /* We can only use this in debugging, since the frontend doesn't check
5919 to make sure that we leave every include file we enter. */
5924 assign_symbol_names (die
);
5925 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
5926 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
5932 compute_section_prefix (node
->die
);
5933 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
5934 &comdat_symbol_number
);
5935 assign_symbol_names (node
->die
);
5937 *pnode
= node
->next
;
5940 pnode
= &node
->next
;
5941 record_comdat_symbol_number (node
->die
, cu_hash_table
,
5942 comdat_symbol_number
);
5945 htab_delete (cu_hash_table
);
5948 /* Traverse the DIE and add a sibling attribute if it may have the
5949 effect of speeding up access to siblings. To save some space,
5950 avoid generating sibling attributes for DIE's without children. */
5953 add_sibling_attributes (dw_die_ref die
)
5957 if (die
->die_tag
!= DW_TAG_compile_unit
5958 && die
->die_sib
&& die
->die_child
!= NULL
)
5959 /* Add the sibling link to the front of the attribute list. */
5960 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
5962 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5963 add_sibling_attributes (c
);
5966 /* Output all location lists for the DIE and its children. */
5969 output_location_lists (dw_die_ref die
)
5974 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
5975 if (AT_class (d_attr
) == dw_val_class_loc_list
)
5976 output_loc_list (AT_loc_list (d_attr
));
5978 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5979 output_location_lists (c
);
5983 /* The format of each DIE (and its attribute value pairs) is encoded in an
5984 abbreviation table. This routine builds the abbreviation table and assigns
5985 a unique abbreviation id for each abbreviation entry. The children of each
5986 die are visited recursively. */
5989 build_abbrev_table (dw_die_ref die
)
5991 unsigned long abbrev_id
;
5992 unsigned int n_alloc
;
5994 dw_attr_ref d_attr
, a_attr
;
5996 /* Scan the DIE references, and mark as external any that refer to
5997 DIEs from other CUs (i.e. those which are not marked). */
5998 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
5999 if (AT_class (d_attr
) == dw_val_class_die_ref
6000 && AT_ref (d_attr
)->die_mark
== 0)
6002 if (AT_ref (d_attr
)->die_symbol
== 0)
6005 set_AT_ref_external (d_attr
, 1);
6008 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6010 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6012 if (abbrev
->die_tag
== die
->die_tag
)
6014 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
6016 a_attr
= abbrev
->die_attr
;
6017 d_attr
= die
->die_attr
;
6019 while (a_attr
!= NULL
&& d_attr
!= NULL
)
6021 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
6022 || (value_format (a_attr
) != value_format (d_attr
)))
6025 a_attr
= a_attr
->dw_attr_next
;
6026 d_attr
= d_attr
->dw_attr_next
;
6029 if (a_attr
== NULL
&& d_attr
== NULL
)
6035 if (abbrev_id
>= abbrev_die_table_in_use
)
6037 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
6039 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
6040 abbrev_die_table
= ggc_realloc (abbrev_die_table
,
6041 sizeof (dw_die_ref
) * n_alloc
);
6043 memset ((char *) &abbrev_die_table
[abbrev_die_table_allocated
], 0,
6044 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
6045 abbrev_die_table_allocated
= n_alloc
;
6048 ++abbrev_die_table_in_use
;
6049 abbrev_die_table
[abbrev_id
] = die
;
6052 die
->die_abbrev
= abbrev_id
;
6053 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6054 build_abbrev_table (c
);
6057 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6060 constant_size (long unsigned int value
)
6067 log
= floor_log2 (value
);
6070 log
= 1 << (floor_log2 (log
) + 1);
6075 /* Return the size of a DIE as it is represented in the
6076 .debug_info section. */
6078 static unsigned long
6079 size_of_die (dw_die_ref die
)
6081 unsigned long size
= 0;
6084 size
+= size_of_uleb128 (die
->die_abbrev
);
6085 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6087 switch (AT_class (a
))
6089 case dw_val_class_addr
:
6090 size
+= DWARF2_ADDR_SIZE
;
6092 case dw_val_class_offset
:
6093 size
+= DWARF_OFFSET_SIZE
;
6095 case dw_val_class_loc
:
6097 unsigned long lsize
= size_of_locs (AT_loc (a
));
6100 size
+= constant_size (lsize
);
6104 case dw_val_class_loc_list
:
6105 size
+= DWARF_OFFSET_SIZE
;
6107 case dw_val_class_range_list
:
6108 size
+= DWARF_OFFSET_SIZE
;
6110 case dw_val_class_const
:
6111 size
+= size_of_sleb128 (AT_int (a
));
6113 case dw_val_class_unsigned_const
:
6114 size
+= constant_size (AT_unsigned (a
));
6116 case dw_val_class_long_long
:
6117 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
6119 case dw_val_class_float
:
6120 size
+= 1 + a
->dw_attr_val
.v
.val_float
.length
* 4; /* block */
6122 case dw_val_class_flag
:
6125 case dw_val_class_die_ref
:
6126 if (AT_ref_external (a
))
6127 size
+= DWARF2_ADDR_SIZE
;
6129 size
+= DWARF_OFFSET_SIZE
;
6131 case dw_val_class_fde_ref
:
6132 size
+= DWARF_OFFSET_SIZE
;
6134 case dw_val_class_lbl_id
:
6135 size
+= DWARF2_ADDR_SIZE
;
6137 case dw_val_class_lbl_offset
:
6138 size
+= DWARF_OFFSET_SIZE
;
6140 case dw_val_class_str
:
6141 if (AT_string_form (a
) == DW_FORM_strp
)
6142 size
+= DWARF_OFFSET_SIZE
;
6144 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
6154 /* Size the debugging information associated with a given DIE. Visits the
6155 DIE's children recursively. Updates the global variable next_die_offset, on
6156 each time through. Uses the current value of next_die_offset to update the
6157 die_offset field in each DIE. */
6160 calc_die_sizes (dw_die_ref die
)
6164 die
->die_offset
= next_die_offset
;
6165 next_die_offset
+= size_of_die (die
);
6167 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6170 if (die
->die_child
!= NULL
)
6171 /* Count the null byte used to terminate sibling lists. */
6172 next_die_offset
+= 1;
6175 /* Set the marks for a die and its children. We do this so
6176 that we know whether or not a reference needs to use FORM_ref_addr; only
6177 DIEs in the same CU will be marked. We used to clear out the offset
6178 and use that as the flag, but ran into ordering problems. */
6181 mark_dies (dw_die_ref die
)
6189 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6193 /* Clear the marks for a die and its children. */
6196 unmark_dies (dw_die_ref die
)
6204 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6208 /* Clear the marks for a die, its children and referred dies. */
6211 unmark_all_dies (dw_die_ref die
)
6220 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6221 unmark_all_dies (c
);
6223 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
6224 if (AT_class (a
) == dw_val_class_die_ref
)
6225 unmark_all_dies (AT_ref (a
));
6228 /* Return the size of the .debug_pubnames table generated for the
6229 compilation unit. */
6231 static unsigned long
6232 size_of_pubnames (void)
6237 size
= DWARF_PUBNAMES_HEADER_SIZE
;
6238 for (i
= 0; i
< pubname_table_in_use
; i
++)
6240 pubname_ref p
= &pubname_table
[i
];
6241 size
+= DWARF_OFFSET_SIZE
+ strlen (p
->name
) + 1;
6244 size
+= DWARF_OFFSET_SIZE
;
6248 /* Return the size of the information in the .debug_aranges section. */
6250 static unsigned long
6251 size_of_aranges (void)
6255 size
= DWARF_ARANGES_HEADER_SIZE
;
6257 /* Count the address/length pair for this compilation unit. */
6258 size
+= 2 * DWARF2_ADDR_SIZE
;
6259 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
6261 /* Count the two zero words used to terminated the address range table. */
6262 size
+= 2 * DWARF2_ADDR_SIZE
;
6266 /* Select the encoding of an attribute value. */
6268 static enum dwarf_form
6269 value_format (dw_attr_ref a
)
6271 switch (a
->dw_attr_val
.val_class
)
6273 case dw_val_class_addr
:
6274 return DW_FORM_addr
;
6275 case dw_val_class_range_list
:
6276 case dw_val_class_offset
:
6277 if (DWARF_OFFSET_SIZE
== 4)
6278 return DW_FORM_data4
;
6279 if (DWARF_OFFSET_SIZE
== 8)
6280 return DW_FORM_data8
;
6282 case dw_val_class_loc_list
:
6283 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6284 .debug_loc section */
6285 return DW_FORM_data4
;
6286 case dw_val_class_loc
:
6287 switch (constant_size (size_of_locs (AT_loc (a
))))
6290 return DW_FORM_block1
;
6292 return DW_FORM_block2
;
6296 case dw_val_class_const
:
6297 return DW_FORM_sdata
;
6298 case dw_val_class_unsigned_const
:
6299 switch (constant_size (AT_unsigned (a
)))
6302 return DW_FORM_data1
;
6304 return DW_FORM_data2
;
6306 return DW_FORM_data4
;
6308 return DW_FORM_data8
;
6312 case dw_val_class_long_long
:
6313 return DW_FORM_block1
;
6314 case dw_val_class_float
:
6315 return DW_FORM_block1
;
6316 case dw_val_class_flag
:
6317 return DW_FORM_flag
;
6318 case dw_val_class_die_ref
:
6319 if (AT_ref_external (a
))
6320 return DW_FORM_ref_addr
;
6323 case dw_val_class_fde_ref
:
6324 return DW_FORM_data
;
6325 case dw_val_class_lbl_id
:
6326 return DW_FORM_addr
;
6327 case dw_val_class_lbl_offset
:
6328 return DW_FORM_data
;
6329 case dw_val_class_str
:
6330 return AT_string_form (a
);
6337 /* Output the encoding of an attribute value. */
6340 output_value_format (dw_attr_ref a
)
6342 enum dwarf_form form
= value_format (a
);
6344 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
6347 /* Output the .debug_abbrev section which defines the DIE abbreviation
6351 output_abbrev_section (void)
6353 unsigned long abbrev_id
;
6357 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6359 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6361 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
6362 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
6363 dwarf_tag_name (abbrev
->die_tag
));
6365 if (abbrev
->die_child
!= NULL
)
6366 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
6368 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
6370 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
6371 a_attr
= a_attr
->dw_attr_next
)
6373 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
6374 dwarf_attr_name (a_attr
->dw_attr
));
6375 output_value_format (a_attr
);
6378 dw2_asm_output_data (1, 0, NULL
);
6379 dw2_asm_output_data (1, 0, NULL
);
6382 /* Terminate the table. */
6383 dw2_asm_output_data (1, 0, NULL
);
6386 /* Output a symbol we can use to refer to this DIE from another CU. */
6389 output_die_symbol (dw_die_ref die
)
6391 char *sym
= die
->die_symbol
;
6396 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
6397 /* We make these global, not weak; if the target doesn't support
6398 .linkonce, it doesn't support combining the sections, so debugging
6400 (*targetm
.asm_out
.globalize_label
) (asm_out_file
, sym
);
6402 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
6405 /* Return a new location list, given the begin and end range, and the
6406 expression. gensym tells us whether to generate a new internal symbol for
6407 this location list node, which is done for the head of the list only. */
6409 static inline dw_loc_list_ref
6410 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
6411 const char *section
, unsigned int gensym
)
6413 dw_loc_list_ref retlist
= ggc_alloc_cleared (sizeof (dw_loc_list_node
));
6415 retlist
->begin
= begin
;
6417 retlist
->expr
= expr
;
6418 retlist
->section
= section
;
6420 retlist
->ll_symbol
= gen_internal_sym ("LLST");
6425 /* Add a location description expression to a location list. */
6428 add_loc_descr_to_loc_list (dw_loc_list_ref
*list_head
, dw_loc_descr_ref descr
,
6429 const char *begin
, const char *end
,
6430 const char *section
)
6434 /* Find the end of the chain. */
6435 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
6438 /* Add a new location list node to the list. */
6439 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
6442 /* Output the location list given to us. */
6445 output_loc_list (dw_loc_list_ref list_head
)
6447 dw_loc_list_ref curr
= list_head
;
6449 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
6451 /* ??? This shouldn't be needed now that we've forced the
6452 compilation unit base address to zero when there is code
6453 in more than one section. */
6454 if (strcmp (curr
->section
, ".text") == 0)
6456 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6457 dw2_asm_output_data (DWARF2_ADDR_SIZE
, ~(unsigned HOST_WIDE_INT
) 0,
6458 "Location list base address specifier fake entry");
6459 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, curr
->section
,
6460 "Location list base address specifier base");
6463 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
6467 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
6468 "Location list begin address (%s)",
6469 list_head
->ll_symbol
);
6470 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
6471 "Location list end address (%s)",
6472 list_head
->ll_symbol
);
6473 size
= size_of_locs (curr
->expr
);
6475 /* Output the block length for this list of location operations. */
6478 dw2_asm_output_data (2, size
, "%s", "Location expression size");
6480 output_loc_sequence (curr
->expr
);
6483 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6484 "Location list terminator begin (%s)",
6485 list_head
->ll_symbol
);
6486 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6487 "Location list terminator end (%s)",
6488 list_head
->ll_symbol
);
6491 /* Output the DIE and its attributes. Called recursively to generate
6492 the definitions of each child DIE. */
6495 output_die (dw_die_ref die
)
6501 /* If someone in another CU might refer to us, set up a symbol for
6502 them to point to. */
6503 if (die
->die_symbol
)
6504 output_die_symbol (die
);
6506 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
6507 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6509 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6511 const char *name
= dwarf_attr_name (a
->dw_attr
);
6513 switch (AT_class (a
))
6515 case dw_val_class_addr
:
6516 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
6519 case dw_val_class_offset
:
6520 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
6524 case dw_val_class_range_list
:
6526 char *p
= strchr (ranges_section_label
, '\0');
6528 sprintf (p
, "+0x%lx", a
->dw_attr_val
.v
.val_offset
);
6529 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
6535 case dw_val_class_loc
:
6536 size
= size_of_locs (AT_loc (a
));
6538 /* Output the block length for this list of location operations. */
6539 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
6541 output_loc_sequence (AT_loc (a
));
6544 case dw_val_class_const
:
6545 /* ??? It would be slightly more efficient to use a scheme like is
6546 used for unsigned constants below, but gdb 4.x does not sign
6547 extend. Gdb 5.x does sign extend. */
6548 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
6551 case dw_val_class_unsigned_const
:
6552 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
6553 AT_unsigned (a
), "%s", name
);
6556 case dw_val_class_long_long
:
6558 unsigned HOST_WIDE_INT first
, second
;
6560 dw2_asm_output_data (1,
6561 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6564 if (WORDS_BIG_ENDIAN
)
6566 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6567 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
6571 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
6572 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6575 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6576 first
, "long long constant");
6577 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6582 case dw_val_class_float
:
6586 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_float
.length
* 4,
6589 for (i
= 0; i
< a
->dw_attr_val
.v
.val_float
.length
; i
++)
6590 dw2_asm_output_data (4, a
->dw_attr_val
.v
.val_float
.array
[i
],
6591 "fp constant word %u", i
);
6595 case dw_val_class_flag
:
6596 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
6599 case dw_val_class_loc_list
:
6601 char *sym
= AT_loc_list (a
)->ll_symbol
;
6605 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
,
6606 loc_section_label
, "%s", name
);
6610 case dw_val_class_die_ref
:
6611 if (AT_ref_external (a
))
6613 char *sym
= AT_ref (a
)->die_symbol
;
6617 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, "%s", name
);
6619 else if (AT_ref (a
)->die_offset
== 0)
6622 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
6626 case dw_val_class_fde_ref
:
6630 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
6631 a
->dw_attr_val
.v
.val_fde_index
* 2);
6632 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, "%s", name
);
6636 case dw_val_class_lbl_id
:
6637 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
6640 case dw_val_class_lbl_offset
:
6641 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
), "%s", name
);
6644 case dw_val_class_str
:
6645 if (AT_string_form (a
) == DW_FORM_strp
)
6646 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
6647 a
->dw_attr_val
.v
.val_str
->label
,
6648 "%s: \"%s\"", name
, AT_string (a
));
6650 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
6658 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6661 /* Add null byte to terminate sibling list. */
6662 if (die
->die_child
!= NULL
)
6663 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6667 /* Output the compilation unit that appears at the beginning of the
6668 .debug_info section, and precedes the DIE descriptions. */
6671 output_compilation_unit_header (void)
6673 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
6674 dw2_asm_output_data (4, 0xffffffff,
6675 "Initial length escape value indicating 64-bit DWARF extension");
6676 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
6677 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
6678 "Length of Compilation Unit Info");
6679 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
6680 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
6681 "Offset Into Abbrev. Section");
6682 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
6685 /* Output the compilation unit DIE and its children. */
6688 output_comp_unit (dw_die_ref die
, int output_if_empty
)
6690 const char *secname
;
6693 /* Unless we are outputting main CU, we may throw away empty ones. */
6694 if (!output_if_empty
&& die
->die_child
== NULL
)
6697 /* Even if there are no children of this DIE, we must output the information
6698 about the compilation unit. Otherwise, on an empty translation unit, we
6699 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6700 will then complain when examining the file. First mark all the DIEs in
6701 this CU so we know which get local refs. */
6704 build_abbrev_table (die
);
6706 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6707 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
6708 calc_die_sizes (die
);
6710 oldsym
= die
->die_symbol
;
6713 tmp
= (char *) alloca (strlen (oldsym
) + 24);
6715 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
6717 die
->die_symbol
= NULL
;
6720 secname
= (const char *) DEBUG_INFO_SECTION
;
6722 /* Output debugging information. */
6723 named_section_flags (secname
, SECTION_DEBUG
);
6724 output_compilation_unit_header ();
6727 /* Leave the marks on the main CU, so we can check them in
6732 die
->die_symbol
= oldsym
;
6736 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6737 output of lang_hooks.decl_printable_name for C++ looks like
6738 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6741 dwarf2_name (tree decl
, int scope
)
6743 return (*lang_hooks
.decl_printable_name
) (decl
, scope
? 1 : 0);
6746 /* Add a new entry to .debug_pubnames if appropriate. */
6749 add_pubname (tree decl
, dw_die_ref die
)
6753 if (! TREE_PUBLIC (decl
))
6756 if (pubname_table_in_use
== pubname_table_allocated
)
6758 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
6760 = (pubname_ref
) ggc_realloc (pubname_table
,
6761 (pubname_table_allocated
6762 * sizeof (pubname_entry
)));
6763 memset (pubname_table
+ pubname_table_in_use
, 0,
6764 PUBNAME_TABLE_INCREMENT
* sizeof (pubname_entry
));
6767 p
= &pubname_table
[pubname_table_in_use
++];
6769 p
->name
= xstrdup (dwarf2_name (decl
, 1));
6772 /* Output the public names table used to speed up access to externally
6773 visible names. For now, only generate entries for externally
6774 visible procedures. */
6777 output_pubnames (void)
6780 unsigned long pubnames_length
= size_of_pubnames ();
6782 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
6783 dw2_asm_output_data (4, 0xffffffff,
6784 "Initial length escape value indicating 64-bit DWARF extension");
6785 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
6786 "Length of Public Names Info");
6787 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6788 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6789 "Offset of Compilation Unit Info");
6790 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
6791 "Compilation Unit Length");
6793 for (i
= 0; i
< pubname_table_in_use
; i
++)
6795 pubname_ref pub
= &pubname_table
[i
];
6797 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6798 if (pub
->die
->die_mark
== 0)
6801 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
6804 dw2_asm_output_nstring (pub
->name
, -1, "external name");
6807 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
6810 /* Add a new entry to .debug_aranges if appropriate. */
6813 add_arange (tree decl
, dw_die_ref die
)
6815 if (! DECL_SECTION_NAME (decl
))
6818 if (arange_table_in_use
== arange_table_allocated
)
6820 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
6821 arange_table
= ggc_realloc (arange_table
,
6822 (arange_table_allocated
6823 * sizeof (dw_die_ref
)));
6824 memset (arange_table
+ arange_table_in_use
, 0,
6825 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
6828 arange_table
[arange_table_in_use
++] = die
;
6831 /* Output the information that goes into the .debug_aranges table.
6832 Namely, define the beginning and ending address range of the
6833 text section generated for this compilation unit. */
6836 output_aranges (void)
6839 unsigned long aranges_length
= size_of_aranges ();
6841 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
6842 dw2_asm_output_data (4, 0xffffffff,
6843 "Initial length escape value indicating 64-bit DWARF extension");
6844 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
6845 "Length of Address Ranges Info");
6846 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6847 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6848 "Offset of Compilation Unit Info");
6849 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
6850 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6852 /* We need to align to twice the pointer size here. */
6853 if (DWARF_ARANGES_PAD_SIZE
)
6855 /* Pad using a 2 byte words so that padding is correct for any
6857 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6858 2 * DWARF2_ADDR_SIZE
);
6859 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
6860 dw2_asm_output_data (2, 0, NULL
);
6863 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
6864 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
6865 text_section_label
, "Length");
6867 for (i
= 0; i
< arange_table_in_use
; i
++)
6869 dw_die_ref die
= arange_table
[i
];
6871 /* We shouldn't see aranges for DIEs outside of the main CU. */
6872 if (die
->die_mark
== 0)
6875 if (die
->die_tag
== DW_TAG_subprogram
)
6877 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
6879 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
6880 get_AT_low_pc (die
), "Length");
6884 /* A static variable; extract the symbol from DW_AT_location.
6885 Note that this code isn't currently hit, as we only emit
6886 aranges for functions (jason 9/23/99). */
6887 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
6888 dw_loc_descr_ref loc
;
6890 if (! a
|| AT_class (a
) != dw_val_class_loc
)
6894 if (loc
->dw_loc_opc
!= DW_OP_addr
)
6897 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
6898 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
6899 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
6900 get_AT_unsigned (die
, DW_AT_byte_size
),
6905 /* Output the terminator words. */
6906 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6907 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6910 /* Add a new entry to .debug_ranges. Return the offset at which it
6914 add_ranges (tree block
)
6916 unsigned int in_use
= ranges_table_in_use
;
6918 if (in_use
== ranges_table_allocated
)
6920 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
6921 ranges_table
= (dw_ranges_ref
)
6922 ggc_realloc (ranges_table
, (ranges_table_allocated
6923 * sizeof (struct dw_ranges_struct
)));
6924 memset (ranges_table
+ ranges_table_in_use
, 0,
6925 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
6928 ranges_table
[in_use
].block_num
= (block
? BLOCK_NUMBER (block
) : 0);
6929 ranges_table_in_use
= in_use
+ 1;
6931 return in_use
* 2 * DWARF2_ADDR_SIZE
;
6935 output_ranges (void)
6938 static const char *const start_fmt
= "Offset 0x%x";
6939 const char *fmt
= start_fmt
;
6941 for (i
= 0; i
< ranges_table_in_use
; i
++)
6943 int block_num
= ranges_table
[i
].block_num
;
6947 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
6948 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
6950 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
6951 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
6953 /* If all code is in the text section, then the compilation
6954 unit base address defaults to DW_AT_low_pc, which is the
6955 base of the text section. */
6956 if (separate_line_info_table_in_use
== 0)
6958 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
6960 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
6961 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
6962 text_section_label
, NULL
);
6965 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6966 compilation unit base address to zero, which allows us to
6967 use absolute addresses, and not worry about whether the
6968 target supports cross-section arithmetic. */
6971 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
6972 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
6973 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
6980 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6981 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6987 /* Data structure containing information about input files. */
6990 char *path
; /* Complete file name. */
6991 char *fname
; /* File name part. */
6992 int length
; /* Length of entire string. */
6993 int file_idx
; /* Index in input file table. */
6994 int dir_idx
; /* Index in directory table. */
6997 /* Data structure containing information about directories with source
7001 char *path
; /* Path including directory name. */
7002 int length
; /* Path length. */
7003 int prefix
; /* Index of directory entry which is a prefix. */
7004 int count
; /* Number of files in this directory. */
7005 int dir_idx
; /* Index of directory used as base. */
7006 int used
; /* Used in the end? */
7009 /* Callback function for file_info comparison. We sort by looking at
7010 the directories in the path. */
7013 file_info_cmp (const void *p1
, const void *p2
)
7015 const struct file_info
*s1
= p1
;
7016 const struct file_info
*s2
= p2
;
7020 /* Take care of file names without directories. We need to make sure that
7021 we return consistent values to qsort since some will get confused if
7022 we return the same value when identical operands are passed in opposite
7023 orders. So if neither has a directory, return 0 and otherwise return
7024 1 or -1 depending on which one has the directory. */
7025 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
7026 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
7028 cp1
= (unsigned char *) s1
->path
;
7029 cp2
= (unsigned char *) s2
->path
;
7035 /* Reached the end of the first path? If so, handle like above. */
7036 if ((cp1
== (unsigned char *) s1
->fname
)
7037 || (cp2
== (unsigned char *) s2
->fname
))
7038 return ((cp2
== (unsigned char *) s2
->fname
)
7039 - (cp1
== (unsigned char *) s1
->fname
));
7041 /* Character of current path component the same? */
7042 else if (*cp1
!= *cp2
)
7047 /* Output the directory table and the file name table. We try to minimize
7048 the total amount of memory needed. A heuristic is used to avoid large
7049 slowdowns with many input files. */
7052 output_file_names (void)
7054 struct file_info
*files
;
7055 struct dir_info
*dirs
;
7064 /* Handle the case where file_table is empty. */
7065 if (VARRAY_ACTIVE_SIZE (file_table
) <= 1)
7067 dw2_asm_output_data (1, 0, "End directory table");
7068 dw2_asm_output_data (1, 0, "End file name table");
7072 /* Allocate the various arrays we need. */
7073 files
= (struct file_info
*) alloca (VARRAY_ACTIVE_SIZE (file_table
)
7074 * sizeof (struct file_info
));
7075 dirs
= (struct dir_info
*) alloca (VARRAY_ACTIVE_SIZE (file_table
)
7076 * sizeof (struct dir_info
));
7078 /* Sort the file names. */
7079 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7083 /* Skip all leading "./". */
7084 f
= VARRAY_CHAR_PTR (file_table
, i
);
7085 while (f
[0] == '.' && f
[1] == '/')
7088 /* Create a new array entry. */
7090 files
[i
].length
= strlen (f
);
7091 files
[i
].file_idx
= i
;
7093 /* Search for the file name part. */
7094 f
= strrchr (f
, '/');
7095 files
[i
].fname
= f
== NULL
? files
[i
].path
: f
+ 1;
7098 qsort (files
+ 1, VARRAY_ACTIVE_SIZE (file_table
) - 1,
7099 sizeof (files
[0]), file_info_cmp
);
7101 /* Find all the different directories used. */
7102 dirs
[0].path
= files
[1].path
;
7103 dirs
[0].length
= files
[1].fname
- files
[1].path
;
7104 dirs
[0].prefix
= -1;
7106 dirs
[0].dir_idx
= 0;
7108 files
[1].dir_idx
= 0;
7111 for (i
= 2; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7112 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
7113 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
7114 dirs
[ndirs
- 1].length
) == 0)
7116 /* Same directory as last entry. */
7117 files
[i
].dir_idx
= ndirs
- 1;
7118 ++dirs
[ndirs
- 1].count
;
7124 /* This is a new directory. */
7125 dirs
[ndirs
].path
= files
[i
].path
;
7126 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
7127 dirs
[ndirs
].count
= 1;
7128 dirs
[ndirs
].dir_idx
= ndirs
;
7129 dirs
[ndirs
].used
= 0;
7130 files
[i
].dir_idx
= ndirs
;
7132 /* Search for a prefix. */
7133 dirs
[ndirs
].prefix
= -1;
7134 for (j
= 0; j
< ndirs
; j
++)
7135 if (dirs
[j
].length
< dirs
[ndirs
].length
7136 && dirs
[j
].length
> 1
7137 && (dirs
[ndirs
].prefix
== -1
7138 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
7139 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
7140 dirs
[ndirs
].prefix
= j
;
7145 /* Now to the actual work. We have to find a subset of the directories which
7146 allow expressing the file name using references to the directory table
7147 with the least amount of characters. We do not do an exhaustive search
7148 where we would have to check out every combination of every single
7149 possible prefix. Instead we use a heuristic which provides nearly optimal
7150 results in most cases and never is much off. */
7151 saved
= (int *) alloca (ndirs
* sizeof (int));
7152 savehere
= (int *) alloca (ndirs
* sizeof (int));
7154 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
7155 for (i
= 0; i
< ndirs
; i
++)
7160 /* We can always save some space for the current directory. But this
7161 does not mean it will be enough to justify adding the directory. */
7162 savehere
[i
] = dirs
[i
].length
;
7163 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
7165 for (j
= i
+ 1; j
< ndirs
; j
++)
7168 if (saved
[j
] < dirs
[i
].length
)
7170 /* Determine whether the dirs[i] path is a prefix of the
7175 while (k
!= -1 && k
!= (int) i
)
7180 /* Yes it is. We can possibly safe some memory but
7181 writing the filenames in dirs[j] relative to
7183 savehere
[j
] = dirs
[i
].length
;
7184 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
7189 /* Check whether we can safe enough to justify adding the dirs[i]
7191 if (total
> dirs
[i
].length
+ 1)
7193 /* It's worthwhile adding. */
7194 for (j
= i
; j
< ndirs
; j
++)
7195 if (savehere
[j
] > 0)
7197 /* Remember how much we saved for this directory so far. */
7198 saved
[j
] = savehere
[j
];
7200 /* Remember the prefix directory. */
7201 dirs
[j
].dir_idx
= i
;
7206 /* We have to emit them in the order they appear in the file_table array
7207 since the index is used in the debug info generation. To do this
7208 efficiently we generate a back-mapping of the indices first. */
7209 backmap
= (int *) alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (int));
7210 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7212 backmap
[files
[i
].file_idx
] = i
;
7214 /* Mark this directory as used. */
7215 dirs
[dirs
[files
[i
].dir_idx
].dir_idx
].used
= 1;
7218 /* That was it. We are ready to emit the information. First emit the
7219 directory name table. We have to make sure the first actually emitted
7220 directory name has index one; zero is reserved for the current working
7221 directory. Make sure we do not confuse these indices with the one for the
7222 constructed table (even though most of the time they are identical). */
7224 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
7225 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
7226 if (dirs
[i
].used
!= 0)
7228 dirs
[i
].used
= idx
++;
7229 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
7230 "Directory Entry: 0x%x", dirs
[i
].used
);
7233 dw2_asm_output_data (1, 0, "End directory table");
7235 /* Correct the index for the current working directory entry if it
7237 if (idx_offset
== 0)
7240 /* Now write all the file names. */
7241 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7243 int file_idx
= backmap
[i
];
7244 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
7246 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
7247 "File Entry: 0x%lx", (unsigned long) i
);
7249 /* Include directory index. */
7250 dw2_asm_output_data_uleb128 (dirs
[dir_idx
].used
, NULL
);
7252 /* Modification time. */
7253 dw2_asm_output_data_uleb128 (0, NULL
);
7255 /* File length in bytes. */
7256 dw2_asm_output_data_uleb128 (0, NULL
);
7259 dw2_asm_output_data (1, 0, "End file name table");
7263 /* Output the source line number correspondence information. This
7264 information goes into the .debug_line section. */
7267 output_line_info (void)
7269 char l1
[20], l2
[20], p1
[20], p2
[20];
7270 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7271 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7274 unsigned long lt_index
;
7275 unsigned long current_line
;
7278 unsigned long current_file
;
7279 unsigned long function
;
7281 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
7282 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
7283 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
7284 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
7286 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7287 dw2_asm_output_data (4, 0xffffffff,
7288 "Initial length escape value indicating 64-bit DWARF extension");
7289 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
7290 "Length of Source Line Info");
7291 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
7293 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7294 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
7295 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
7297 /* Define the architecture-dependent minimum instruction length (in
7298 bytes). In this implementation of DWARF, this field is used for
7299 information purposes only. Since GCC generates assembly language,
7300 we have no a priori knowledge of how many instruction bytes are
7301 generated for each source line, and therefore can use only the
7302 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7303 commands. Accordingly, we fix this as `1', which is "correct
7304 enough" for all architectures, and don't let the target override. */
7305 dw2_asm_output_data (1, 1,
7306 "Minimum Instruction Length");
7308 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
7309 "Default is_stmt_start flag");
7310 dw2_asm_output_data (1, DWARF_LINE_BASE
,
7311 "Line Base Value (Special Opcodes)");
7312 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
7313 "Line Range Value (Special Opcodes)");
7314 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
7315 "Special Opcode Base");
7317 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
7321 case DW_LNS_advance_pc
:
7322 case DW_LNS_advance_line
:
7323 case DW_LNS_set_file
:
7324 case DW_LNS_set_column
:
7325 case DW_LNS_fixed_advance_pc
:
7333 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
7337 /* Write out the information about the files we use. */
7338 output_file_names ();
7339 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
7341 /* We used to set the address register to the first location in the text
7342 section here, but that didn't accomplish anything since we already
7343 have a line note for the opening brace of the first function. */
7345 /* Generate the line number to PC correspondence table, encoded as
7346 a series of state machine operations. */
7349 strcpy (prev_line_label
, text_section_label
);
7350 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
7352 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
7355 /* Disable this optimization for now; GDB wants to see two line notes
7356 at the beginning of a function so it can find the end of the
7359 /* Don't emit anything for redundant notes. Just updating the
7360 address doesn't accomplish anything, because we already assume
7361 that anything after the last address is this line. */
7362 if (line_info
->dw_line_num
== current_line
7363 && line_info
->dw_file_num
== current_file
)
7367 /* Emit debug info for the address of the current line.
7369 Unfortunately, we have little choice here currently, and must always
7370 use the most general form. GCC does not know the address delta
7371 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7372 attributes which will give an upper bound on the address range. We
7373 could perhaps use length attributes to determine when it is safe to
7374 use DW_LNS_fixed_advance_pc. */
7376 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
7379 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7380 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7381 "DW_LNS_fixed_advance_pc");
7382 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7386 /* This can handle any delta. This takes
7387 4+DWARF2_ADDR_SIZE bytes. */
7388 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7389 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7390 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7391 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7394 strcpy (prev_line_label
, line_label
);
7396 /* Emit debug info for the source file of the current line, if
7397 different from the previous line. */
7398 if (line_info
->dw_file_num
!= current_file
)
7400 current_file
= line_info
->dw_file_num
;
7401 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7402 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7403 VARRAY_CHAR_PTR (file_table
,
7407 /* Emit debug info for the current line number, choosing the encoding
7408 that uses the least amount of space. */
7409 if (line_info
->dw_line_num
!= current_line
)
7411 line_offset
= line_info
->dw_line_num
- current_line
;
7412 line_delta
= line_offset
- DWARF_LINE_BASE
;
7413 current_line
= line_info
->dw_line_num
;
7414 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7415 /* This can handle deltas from -10 to 234, using the current
7416 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7418 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7419 "line %lu", current_line
);
7422 /* This can handle any delta. This takes at least 4 bytes,
7423 depending on the value being encoded. */
7424 dw2_asm_output_data (1, DW_LNS_advance_line
,
7425 "advance to line %lu", current_line
);
7426 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7427 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7431 /* We still need to start a new row, so output a copy insn. */
7432 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7435 /* Emit debug info for the address of the end of the function. */
7438 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7439 "DW_LNS_fixed_advance_pc");
7440 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
7444 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7445 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7446 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7447 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
7450 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7451 dw2_asm_output_data_uleb128 (1, NULL
);
7452 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7457 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
7459 dw_separate_line_info_ref line_info
7460 = &separate_line_info_table
[lt_index
];
7463 /* Don't emit anything for redundant notes. */
7464 if (line_info
->dw_line_num
== current_line
7465 && line_info
->dw_file_num
== current_file
7466 && line_info
->function
== function
)
7470 /* Emit debug info for the address of the current line. If this is
7471 a new function, or the first line of a function, then we need
7472 to handle it differently. */
7473 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
7475 if (function
!= line_info
->function
)
7477 function
= line_info
->function
;
7479 /* Set the address register to the first line in the function. */
7480 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7481 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7482 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7483 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7487 /* ??? See the DW_LNS_advance_pc comment above. */
7490 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7491 "DW_LNS_fixed_advance_pc");
7492 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7496 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7497 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7498 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7499 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7503 strcpy (prev_line_label
, line_label
);
7505 /* Emit debug info for the source file of the current line, if
7506 different from the previous line. */
7507 if (line_info
->dw_file_num
!= current_file
)
7509 current_file
= line_info
->dw_file_num
;
7510 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7511 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7512 VARRAY_CHAR_PTR (file_table
,
7516 /* Emit debug info for the current line number, choosing the encoding
7517 that uses the least amount of space. */
7518 if (line_info
->dw_line_num
!= current_line
)
7520 line_offset
= line_info
->dw_line_num
- current_line
;
7521 line_delta
= line_offset
- DWARF_LINE_BASE
;
7522 current_line
= line_info
->dw_line_num
;
7523 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7524 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7525 "line %lu", current_line
);
7528 dw2_asm_output_data (1, DW_LNS_advance_line
,
7529 "advance to line %lu", current_line
);
7530 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7531 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7535 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7543 /* If we're done with a function, end its sequence. */
7544 if (lt_index
== separate_line_info_table_in_use
7545 || separate_line_info_table
[lt_index
].function
!= function
)
7550 /* Emit debug info for the address of the end of the function. */
7551 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
7554 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7555 "DW_LNS_fixed_advance_pc");
7556 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7560 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7561 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7562 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7563 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7566 /* Output the marker for the end of this sequence. */
7567 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7568 dw2_asm_output_data_uleb128 (1, NULL
);
7569 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7573 /* Output the marker for the end of the line number info. */
7574 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
7577 /* Given a pointer to a tree node for some base type, return a pointer to
7578 a DIE that describes the given type.
7580 This routine must only be called for GCC type nodes that correspond to
7581 Dwarf base (fundamental) types. */
7584 base_type_die (tree type
)
7586 dw_die_ref base_type_result
;
7587 const char *type_name
;
7588 enum dwarf_type encoding
;
7589 tree name
= TYPE_NAME (type
);
7591 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
7596 if (TREE_CODE (name
) == TYPE_DECL
)
7597 name
= DECL_NAME (name
);
7599 type_name
= IDENTIFIER_POINTER (name
);
7602 type_name
= "__unknown__";
7604 switch (TREE_CODE (type
))
7607 /* Carefully distinguish the C character types, without messing
7608 up if the language is not C. Note that we check only for the names
7609 that contain spaces; other names might occur by coincidence in other
7611 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
7612 && (type
== char_type_node
7613 || ! strcmp (type_name
, "signed char")
7614 || ! strcmp (type_name
, "unsigned char"))))
7616 if (TREE_UNSIGNED (type
))
7617 encoding
= DW_ATE_unsigned
;
7619 encoding
= DW_ATE_signed
;
7622 /* else fall through. */
7625 /* GNU Pascal/Ada CHAR type. Not used in C. */
7626 if (TREE_UNSIGNED (type
))
7627 encoding
= DW_ATE_unsigned_char
;
7629 encoding
= DW_ATE_signed_char
;
7633 encoding
= DW_ATE_float
;
7636 /* Dwarf2 doesn't know anything about complex ints, so use
7637 a user defined type for it. */
7639 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
7640 encoding
= DW_ATE_complex_float
;
7642 encoding
= DW_ATE_lo_user
;
7646 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7647 encoding
= DW_ATE_boolean
;
7651 /* No other TREE_CODEs are Dwarf fundamental types. */
7655 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
7656 if (demangle_name_func
)
7657 type_name
= (*demangle_name_func
) (type_name
);
7659 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
7660 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
7661 int_size_in_bytes (type
));
7662 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
7664 return base_type_result
;
7667 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7668 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7669 a given type is generally the same as the given type, except that if the
7670 given type is a pointer or reference type, then the root type of the given
7671 type is the root type of the "basis" type for the pointer or reference
7672 type. (This definition of the "root" type is recursive.) Also, the root
7673 type of a `const' qualified type or a `volatile' qualified type is the
7674 root type of the given type without the qualifiers. */
7677 root_type (tree type
)
7679 if (TREE_CODE (type
) == ERROR_MARK
)
7680 return error_mark_node
;
7682 switch (TREE_CODE (type
))
7685 return error_mark_node
;
7688 case REFERENCE_TYPE
:
7689 return type_main_variant (root_type (TREE_TYPE (type
)));
7692 return type_main_variant (type
);
7696 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
7697 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7700 is_base_type (tree type
)
7702 switch (TREE_CODE (type
))
7717 case QUAL_UNION_TYPE
:
7722 case REFERENCE_TYPE
:
7736 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7737 node, return the size in bits for the type if it is a constant, or else
7738 return the alignment for the type if the type's size is not constant, or
7739 else return BITS_PER_WORD if the type actually turns out to be an
7742 static inline unsigned HOST_WIDE_INT
7743 simple_type_size_in_bits (tree type
)
7745 if (TREE_CODE (type
) == ERROR_MARK
)
7746 return BITS_PER_WORD
;
7747 else if (TYPE_SIZE (type
) == NULL_TREE
)
7749 else if (host_integerp (TYPE_SIZE (type
), 1))
7750 return tree_low_cst (TYPE_SIZE (type
), 1);
7752 return TYPE_ALIGN (type
);
7755 /* Return true if the debug information for the given type should be
7756 emitted as a subrange type. */
7759 is_ada_subrange_type (tree type
)
7761 /* We do this for INTEGER_TYPEs that have names, parent types, and when
7762 we are compiling Ada code. */
7763 return (TREE_CODE (type
) == INTEGER_TYPE
7764 && TYPE_NAME (type
) != 0 && TREE_TYPE (type
) != 0
7765 && TREE_CODE (TREE_TYPE (type
)) == INTEGER_TYPE
7766 && TREE_UNSIGNED (TREE_TYPE (type
)) && is_ada ());
7769 /* Given a pointer to a tree node for a subrange type, return a pointer
7770 to a DIE that describes the given type. */
7773 subrange_type_die (tree type
)
7775 dw_die_ref subtype_die
;
7776 dw_die_ref subrange_die
;
7777 tree name
= TYPE_NAME (type
);
7779 subtype_die
= base_type_die (TREE_TYPE (type
));
7781 if (TREE_CODE (name
) == TYPE_DECL
)
7782 name
= DECL_NAME (name
);
7784 subrange_die
= new_die (DW_TAG_subrange_type
, comp_unit_die
, type
);
7785 add_name_attribute (subrange_die
, IDENTIFIER_POINTER (name
));
7786 if (TYPE_MIN_VALUE (type
) != NULL
)
7787 add_bound_info (subrange_die
, DW_AT_lower_bound
,
7788 TYPE_MIN_VALUE (type
));
7789 if (TYPE_MAX_VALUE (type
) != NULL
)
7790 add_bound_info (subrange_die
, DW_AT_upper_bound
,
7791 TYPE_MAX_VALUE (type
));
7792 add_AT_die_ref (subrange_die
, DW_AT_type
, subtype_die
);
7794 return subrange_die
;
7797 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7798 entry that chains various modifiers in front of the given type. */
7801 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
7802 dw_die_ref context_die
)
7804 enum tree_code code
= TREE_CODE (type
);
7805 dw_die_ref mod_type_die
= NULL
;
7806 dw_die_ref sub_die
= NULL
;
7807 tree item_type
= NULL
;
7809 if (code
!= ERROR_MARK
)
7811 tree qualified_type
;
7813 /* See if we already have the appropriately qualified variant of
7816 = get_qualified_type (type
,
7817 ((is_const_type
? TYPE_QUAL_CONST
: 0)
7819 ? TYPE_QUAL_VOLATILE
: 0)));
7821 /* If we do, then we can just use its DIE, if it exists. */
7824 mod_type_die
= lookup_type_die (qualified_type
);
7826 return mod_type_die
;
7829 /* Handle C typedef types. */
7830 if (qualified_type
&& TYPE_NAME (qualified_type
)
7831 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
7832 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type
)))
7834 tree type_name
= TYPE_NAME (qualified_type
);
7835 tree dtype
= TREE_TYPE (type_name
);
7837 if (qualified_type
== dtype
)
7839 /* For a named type, use the typedef. */
7840 gen_type_die (qualified_type
, context_die
);
7841 mod_type_die
= lookup_type_die (qualified_type
);
7843 else if (is_const_type
< TYPE_READONLY (dtype
)
7844 || is_volatile_type
< TYPE_VOLATILE (dtype
))
7845 /* cv-unqualified version of named type. Just use the unnamed
7846 type to which it refers. */
7848 = modified_type_die (DECL_ORIGINAL_TYPE (type_name
),
7849 is_const_type
, is_volatile_type
,
7852 /* Else cv-qualified version of named type; fall through. */
7858 else if (is_const_type
)
7860 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
7861 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
7863 else if (is_volatile_type
)
7865 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
7866 sub_die
= modified_type_die (type
, 0, 0, context_die
);
7868 else if (code
== POINTER_TYPE
)
7870 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
7871 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
7872 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
7874 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7876 item_type
= TREE_TYPE (type
);
7878 else if (code
== REFERENCE_TYPE
)
7880 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
7881 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
7882 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
7884 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7886 item_type
= TREE_TYPE (type
);
7888 else if (is_ada_subrange_type (type
))
7889 mod_type_die
= subrange_type_die (type
);
7890 else if (is_base_type (type
))
7891 mod_type_die
= base_type_die (type
);
7894 gen_type_die (type
, context_die
);
7896 /* We have to get the type_main_variant here (and pass that to the
7897 `lookup_type_die' routine) because the ..._TYPE node we have
7898 might simply be a *copy* of some original type node (where the
7899 copy was created to help us keep track of typedef names) and
7900 that copy might have a different TYPE_UID from the original
7902 if (TREE_CODE (type
) != VECTOR_TYPE
)
7903 mod_type_die
= lookup_type_die (type_main_variant (type
));
7905 /* Vectors have the debugging information in the type,
7906 not the main variant. */
7907 mod_type_die
= lookup_type_die (type
);
7908 if (mod_type_die
== NULL
)
7912 /* We want to equate the qualified type to the die below. */
7913 type
= qualified_type
;
7917 equate_type_number_to_die (type
, mod_type_die
);
7919 /* We must do this after the equate_type_number_to_die call, in case
7920 this is a recursive type. This ensures that the modified_type_die
7921 recursion will terminate even if the type is recursive. Recursive
7922 types are possible in Ada. */
7923 sub_die
= modified_type_die (item_type
,
7924 TYPE_READONLY (item_type
),
7925 TYPE_VOLATILE (item_type
),
7928 if (sub_die
!= NULL
)
7929 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
7931 return mod_type_die
;
7934 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7935 an enumerated type. */
7938 type_is_enum (tree type
)
7940 return TREE_CODE (type
) == ENUMERAL_TYPE
;
7943 /* Return the register number described by a given RTL node. */
7946 reg_number (rtx rtl
)
7948 unsigned regno
= REGNO (rtl
);
7950 if (regno
>= FIRST_PSEUDO_REGISTER
)
7953 return DBX_REGISTER_NUMBER (regno
);
7956 /* Return a location descriptor that designates a machine register or
7957 zero if there is none. */
7959 static dw_loc_descr_ref
7960 reg_loc_descriptor (rtx rtl
)
7965 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
7968 reg
= reg_number (rtl
);
7969 regs
= (*targetm
.dwarf_register_span
) (rtl
);
7971 if (HARD_REGNO_NREGS (reg
, GET_MODE (rtl
)) > 1
7973 return multiple_reg_loc_descriptor (rtl
, regs
);
7975 return one_reg_loc_descriptor (reg
);
7978 /* Return a location descriptor that designates a machine register for
7979 a given hard register number. */
7981 static dw_loc_descr_ref
7982 one_reg_loc_descriptor (unsigned int regno
)
7985 return new_loc_descr (DW_OP_reg0
+ regno
, 0, 0);
7987 return new_loc_descr (DW_OP_regx
, regno
, 0);
7990 /* Given an RTL of a register, return a location descriptor that
7991 designates a value that spans more than one register. */
7993 static dw_loc_descr_ref
7994 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
)
7998 dw_loc_descr_ref loc_result
= NULL
;
8000 reg
= reg_number (rtl
);
8001 nregs
= HARD_REGNO_NREGS (reg
, GET_MODE (rtl
));
8003 /* Simple, contiguous registers. */
8004 if (regs
== NULL_RTX
)
8006 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
8013 t
= one_reg_loc_descriptor (reg
);
8014 add_loc_descr (&loc_result
, t
);
8015 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_piece
, size
, 0));
8021 /* Now onto stupid register sets in non contiguous locations. */
8023 if (GET_CODE (regs
) != PARALLEL
)
8026 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8029 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
8033 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)));
8034 add_loc_descr (&loc_result
, t
);
8035 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8036 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_piece
, size
, 0));
8041 /* Return a location descriptor that designates a constant. */
8043 static dw_loc_descr_ref
8044 int_loc_descriptor (HOST_WIDE_INT i
)
8046 enum dwarf_location_atom op
;
8048 /* Pick the smallest representation of a constant, rather than just
8049 defaulting to the LEB encoding. */
8053 op
= DW_OP_lit0
+ i
;
8056 else if (i
<= 0xffff)
8058 else if (HOST_BITS_PER_WIDE_INT
== 32
8068 else if (i
>= -0x8000)
8070 else if (HOST_BITS_PER_WIDE_INT
== 32
8071 || i
>= -0x80000000)
8077 return new_loc_descr (op
, i
, 0);
8080 /* Return a location descriptor that designates a base+offset location. */
8082 static dw_loc_descr_ref
8083 based_loc_descr (unsigned int reg
, long int offset
)
8085 dw_loc_descr_ref loc_result
;
8086 /* For the "frame base", we use the frame pointer or stack pointer
8087 registers, since the RTL for local variables is relative to one of
8089 unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
8090 ? HARD_FRAME_POINTER_REGNUM
8091 : STACK_POINTER_REGNUM
);
8094 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
8096 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
8098 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
8103 /* Return true if this RTL expression describes a base+offset calculation. */
8106 is_based_loc (rtx rtl
)
8108 return (GET_CODE (rtl
) == PLUS
8109 && ((GET_CODE (XEXP (rtl
, 0)) == REG
8110 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
8111 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
8114 /* The following routine converts the RTL for a variable or parameter
8115 (resident in memory) into an equivalent Dwarf representation of a
8116 mechanism for getting the address of that same variable onto the top of a
8117 hypothetical "address evaluation" stack.
8119 When creating memory location descriptors, we are effectively transforming
8120 the RTL for a memory-resident object into its Dwarf postfix expression
8121 equivalent. This routine recursively descends an RTL tree, turning
8122 it into Dwarf postfix code as it goes.
8124 MODE is the mode of the memory reference, needed to handle some
8125 autoincrement addressing modes.
8127 Return 0 if we can't represent the location. */
8129 static dw_loc_descr_ref
8130 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
)
8132 dw_loc_descr_ref mem_loc_result
= NULL
;
8134 /* Note that for a dynamically sized array, the location we will generate a
8135 description of here will be the lowest numbered location which is
8136 actually within the array. That's *not* necessarily the same as the
8137 zeroth element of the array. */
8139 rtl
= (*targetm
.delegitimize_address
) (rtl
);
8141 switch (GET_CODE (rtl
))
8146 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8147 just fall into the SUBREG code. */
8149 /* ... fall through ... */
8152 /* The case of a subreg may arise when we have a local (register)
8153 variable or a formal (register) parameter which doesn't quite fill
8154 up an entire register. For now, just assume that it is
8155 legitimate to make the Dwarf info refer to the whole register which
8156 contains the given subreg. */
8157 rtl
= SUBREG_REG (rtl
);
8159 /* ... fall through ... */
8162 /* Whenever a register number forms a part of the description of the
8163 method for calculating the (dynamic) address of a memory resident
8164 object, DWARF rules require the register number be referred to as
8165 a "base register". This distinction is not based in any way upon
8166 what category of register the hardware believes the given register
8167 belongs to. This is strictly DWARF terminology we're dealing with
8168 here. Note that in cases where the location of a memory-resident
8169 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8170 OP_CONST (0)) the actual DWARF location descriptor that we generate
8171 may just be OP_BASEREG (basereg). This may look deceptively like
8172 the object in question was allocated to a register (rather than in
8173 memory) so DWARF consumers need to be aware of the subtle
8174 distinction between OP_REG and OP_BASEREG. */
8175 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
8176 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
8180 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
8181 if (mem_loc_result
!= 0)
8182 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
8186 rtl
= XEXP (rtl
, 1);
8188 /* ... fall through ... */
8191 /* Some ports can transform a symbol ref into a label ref, because
8192 the symbol ref is too far away and has to be dumped into a constant
8196 /* Alternatively, the symbol in the constant pool might be referenced
8197 by a different symbol. */
8198 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
8201 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
8203 if (GET_CODE (tmp
) == SYMBOL_REF
)
8206 if (CONSTANT_POOL_ADDRESS_P (tmp
))
8207 get_pool_constant_mark (tmp
, &marked
);
8212 /* If all references to this pool constant were optimized away,
8213 it was not output and thus we can't represent it.
8214 FIXME: might try to use DW_OP_const_value here, though
8215 DW_OP_piece complicates it. */
8220 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
8221 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8222 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8223 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
8227 /* Extract the PLUS expression nested inside and fall into
8229 rtl
= XEXP (rtl
, 1);
8234 /* Turn these into a PLUS expression and fall into the PLUS code
8236 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
8237 GEN_INT (GET_CODE (rtl
) == PRE_INC
8238 ? GET_MODE_UNIT_SIZE (mode
)
8239 : -GET_MODE_UNIT_SIZE (mode
)));
8241 /* ... fall through ... */
8245 if (is_based_loc (rtl
))
8246 mem_loc_result
= based_loc_descr (reg_number (XEXP (rtl
, 0)),
8247 INTVAL (XEXP (rtl
, 1)));
8250 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
8251 if (mem_loc_result
== 0)
8254 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
8255 && INTVAL (XEXP (rtl
, 1)) >= 0)
8256 add_loc_descr (&mem_loc_result
,
8257 new_loc_descr (DW_OP_plus_uconst
,
8258 INTVAL (XEXP (rtl
, 1)), 0));
8261 add_loc_descr (&mem_loc_result
,
8262 mem_loc_descriptor (XEXP (rtl
, 1), mode
));
8263 add_loc_descr (&mem_loc_result
,
8264 new_loc_descr (DW_OP_plus
, 0, 0));
8271 /* If a pseudo-reg is optimized away, it is possible for it to
8272 be replaced with a MEM containing a multiply. */
8273 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
8274 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
);
8276 if (op0
== 0 || op1
== 0)
8279 mem_loc_result
= op0
;
8280 add_loc_descr (&mem_loc_result
, op1
);
8281 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
8286 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
8290 /* If this is a MEM, return its address. Otherwise, we can't
8292 if (GET_CODE (XEXP (rtl
, 0)) == MEM
)
8293 return mem_loc_descriptor (XEXP (XEXP (rtl
, 0), 0), mode
);
8301 return mem_loc_result
;
8304 /* Return a descriptor that describes the concatenation of two locations.
8305 This is typically a complex variable. */
8307 static dw_loc_descr_ref
8308 concat_loc_descriptor (rtx x0
, rtx x1
)
8310 dw_loc_descr_ref cc_loc_result
= NULL
;
8311 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
);
8312 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
);
8314 if (x0_ref
== 0 || x1_ref
== 0)
8317 cc_loc_result
= x0_ref
;
8318 add_loc_descr (&cc_loc_result
,
8319 new_loc_descr (DW_OP_piece
,
8320 GET_MODE_SIZE (GET_MODE (x0
)), 0));
8322 add_loc_descr (&cc_loc_result
, x1_ref
);
8323 add_loc_descr (&cc_loc_result
,
8324 new_loc_descr (DW_OP_piece
,
8325 GET_MODE_SIZE (GET_MODE (x1
)), 0));
8327 return cc_loc_result
;
8330 /* Output a proper Dwarf location descriptor for a variable or parameter
8331 which is either allocated in a register or in a memory location. For a
8332 register, we just generate an OP_REG and the register number. For a
8333 memory location we provide a Dwarf postfix expression describing how to
8334 generate the (dynamic) address of the object onto the address stack.
8336 If we don't know how to describe it, return 0. */
8338 static dw_loc_descr_ref
8339 loc_descriptor (rtx rtl
)
8341 dw_loc_descr_ref loc_result
= NULL
;
8343 switch (GET_CODE (rtl
))
8346 /* The case of a subreg may arise when we have a local (register)
8347 variable or a formal (register) parameter which doesn't quite fill
8348 up an entire register. For now, just assume that it is
8349 legitimate to make the Dwarf info refer to the whole register which
8350 contains the given subreg. */
8351 rtl
= SUBREG_REG (rtl
);
8353 /* ... fall through ... */
8356 loc_result
= reg_loc_descriptor (rtl
);
8360 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
8364 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
8374 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8375 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8376 looking for an address. Otherwise, we return a value. If we can't make a
8377 descriptor, return 0. */
8379 static dw_loc_descr_ref
8380 loc_descriptor_from_tree (tree loc
, int addressp
)
8382 dw_loc_descr_ref ret
, ret1
;
8384 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (loc
));
8385 enum dwarf_location_atom op
;
8387 /* ??? Most of the time we do not take proper care for sign/zero
8388 extending the values properly. Hopefully this won't be a real
8391 switch (TREE_CODE (loc
))
8396 case WITH_RECORD_EXPR
:
8397 case PLACEHOLDER_EXPR
:
8398 /* This case involves extracting fields from an object to determine the
8399 position of other fields. We don't try to encode this here. The
8400 only user of this is Ada, which encodes the needed information using
8401 the names of types. */
8408 /* We can support this only if we can look through conversions and
8409 find an INDIRECT_EXPR. */
8410 for (loc
= TREE_OPERAND (loc
, 0);
8411 TREE_CODE (loc
) == CONVERT_EXPR
|| TREE_CODE (loc
) == NOP_EXPR
8412 || TREE_CODE (loc
) == NON_LVALUE_EXPR
8413 || TREE_CODE (loc
) == VIEW_CONVERT_EXPR
8414 || TREE_CODE (loc
) == SAVE_EXPR
;
8415 loc
= TREE_OPERAND (loc
, 0))
8418 return (TREE_CODE (loc
) == INDIRECT_REF
8419 ? loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
)
8423 if (DECL_THREAD_LOCAL (loc
))
8427 #ifndef ASM_OUTPUT_DWARF_DTPREL
8428 /* If this is not defined, we have no way to emit the data. */
8432 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8433 look up addresses of objects in the current module. */
8434 if (DECL_EXTERNAL (loc
))
8437 rtl
= rtl_for_decl_location (loc
);
8438 if (rtl
== NULL_RTX
)
8441 if (GET_CODE (rtl
) != MEM
)
8443 rtl
= XEXP (rtl
, 0);
8444 if (! CONSTANT_P (rtl
))
8447 ret
= new_loc_descr (INTERNAL_DW_OP_tls_addr
, 0, 0);
8448 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8449 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8451 ret1
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
8452 add_loc_descr (&ret
, ret1
);
8461 rtx rtl
= rtl_for_decl_location (loc
);
8463 if (rtl
== NULL_RTX
)
8465 else if (CONSTANT_P (rtl
))
8467 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
8468 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8469 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8474 enum machine_mode mode
= GET_MODE (rtl
);
8476 if (GET_CODE (rtl
) == MEM
)
8479 rtl
= XEXP (rtl
, 0);
8482 ret
= mem_loc_descriptor (rtl
, mode
);
8488 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8493 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), addressp
);
8497 case NON_LVALUE_EXPR
:
8498 case VIEW_CONVERT_EXPR
:
8501 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
);
8506 case ARRAY_RANGE_REF
:
8509 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
8510 enum machine_mode mode
;
8513 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
8514 &unsignedp
, &volatilep
);
8519 ret
= loc_descriptor_from_tree (obj
, 1);
8521 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
8524 if (offset
!= NULL_TREE
)
8526 /* Variable offset. */
8527 add_loc_descr (&ret
, loc_descriptor_from_tree (offset
, 0));
8528 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8534 bytepos
= bitpos
/ BITS_PER_UNIT
;
8536 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
8537 else if (bytepos
< 0)
8539 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
8540 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8546 if (host_integerp (loc
, 0))
8547 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
8552 case TRUTH_AND_EXPR
:
8553 case TRUTH_ANDIF_EXPR
:
8558 case TRUTH_XOR_EXPR
:
8564 case TRUTH_ORIF_EXPR
:
8569 case FLOOR_DIV_EXPR
:
8571 case ROUND_DIV_EXPR
:
8572 case TRUNC_DIV_EXPR
:
8580 case FLOOR_MOD_EXPR
:
8582 case ROUND_MOD_EXPR
:
8583 case TRUNC_MOD_EXPR
:
8596 op
= (unsignedp
? DW_OP_shr
: DW_OP_shra
);
8600 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
8601 && host_integerp (TREE_OPERAND (loc
, 1), 0))
8603 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8607 add_loc_descr (&ret
,
8608 new_loc_descr (DW_OP_plus_uconst
,
8609 tree_low_cst (TREE_OPERAND (loc
, 1),
8619 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8626 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8633 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8640 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8655 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8656 ret1
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8657 if (ret
== 0 || ret1
== 0)
8660 add_loc_descr (&ret
, ret1
);
8661 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8664 case TRUTH_NOT_EXPR
:
8678 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8682 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8686 loc
= build (COND_EXPR
, TREE_TYPE (loc
),
8687 build (LT_EXPR
, integer_type_node
,
8688 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
8689 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
8691 /* ... fall through ... */
8695 dw_loc_descr_ref lhs
8696 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8697 dw_loc_descr_ref rhs
8698 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 2), 0);
8699 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
8701 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8702 if (ret
== 0 || lhs
== 0 || rhs
== 0)
8705 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
8706 add_loc_descr (&ret
, bra_node
);
8708 add_loc_descr (&ret
, rhs
);
8709 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
8710 add_loc_descr (&ret
, jump_node
);
8712 add_loc_descr (&ret
, lhs
);
8713 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8714 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
8716 /* ??? Need a node to point the skip at. Use a nop. */
8717 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
8718 add_loc_descr (&ret
, tmp
);
8719 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8720 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
8725 /* Leave front-end specific codes as simply unknown. This comes
8726 up, for instance, with the C STMT_EXPR. */
8727 if ((unsigned int) TREE_CODE (loc
)
8728 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
8731 /* Otherwise this is a generic code; we should just lists all of
8732 these explicitly. Aborting means we forgot one. */
8736 /* Show if we can't fill the request for an address. */
8737 if (addressp
&& indirect_p
== 0)
8740 /* If we've got an address and don't want one, dereference. */
8741 if (!addressp
&& indirect_p
> 0)
8743 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
8745 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
8747 else if (size
== DWARF2_ADDR_SIZE
)
8750 op
= DW_OP_deref_size
;
8752 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
8758 /* Given a value, round it up to the lowest multiple of `boundary'
8759 which is not less than the value itself. */
8761 static inline HOST_WIDE_INT
8762 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
8764 return (((value
+ boundary
- 1) / boundary
) * boundary
);
8767 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8768 pointer to the declared type for the relevant field variable, or return
8769 `integer_type_node' if the given node turns out to be an
8773 field_type (tree decl
)
8777 if (TREE_CODE (decl
) == ERROR_MARK
)
8778 return integer_type_node
;
8780 type
= DECL_BIT_FIELD_TYPE (decl
);
8781 if (type
== NULL_TREE
)
8782 type
= TREE_TYPE (decl
);
8787 /* Given a pointer to a tree node, return the alignment in bits for
8788 it, or else return BITS_PER_WORD if the node actually turns out to
8789 be an ERROR_MARK node. */
8791 static inline unsigned
8792 simple_type_align_in_bits (tree type
)
8794 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
8797 static inline unsigned
8798 simple_decl_align_in_bits (tree decl
)
8800 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
8803 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8804 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8805 or return 0 if we are unable to determine what that offset is, either
8806 because the argument turns out to be a pointer to an ERROR_MARK node, or
8807 because the offset is actually variable. (We can't handle the latter case
8810 static HOST_WIDE_INT
8811 field_byte_offset (tree decl
)
8813 unsigned int type_align_in_bits
;
8814 unsigned int decl_align_in_bits
;
8815 unsigned HOST_WIDE_INT type_size_in_bits
;
8816 HOST_WIDE_INT object_offset_in_bits
;
8818 tree field_size_tree
;
8819 HOST_WIDE_INT bitpos_int
;
8820 HOST_WIDE_INT deepest_bitpos
;
8821 unsigned HOST_WIDE_INT field_size_in_bits
;
8823 if (TREE_CODE (decl
) == ERROR_MARK
)
8825 else if (TREE_CODE (decl
) != FIELD_DECL
)
8828 type
= field_type (decl
);
8829 field_size_tree
= DECL_SIZE (decl
);
8831 /* The size could be unspecified if there was an error, or for
8832 a flexible array member. */
8833 if (! field_size_tree
)
8834 field_size_tree
= bitsize_zero_node
;
8836 /* We cannot yet cope with fields whose positions are variable, so
8837 for now, when we see such things, we simply return 0. Someday, we may
8838 be able to handle such cases, but it will be damn difficult. */
8839 if (! host_integerp (bit_position (decl
), 0))
8842 bitpos_int
= int_bit_position (decl
);
8844 /* If we don't know the size of the field, pretend it's a full word. */
8845 if (host_integerp (field_size_tree
, 1))
8846 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
8848 field_size_in_bits
= BITS_PER_WORD
;
8850 type_size_in_bits
= simple_type_size_in_bits (type
);
8851 type_align_in_bits
= simple_type_align_in_bits (type
);
8852 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
8854 /* The GCC front-end doesn't make any attempt to keep track of the starting
8855 bit offset (relative to the start of the containing structure type) of the
8856 hypothetical "containing object" for a bit-field. Thus, when computing
8857 the byte offset value for the start of the "containing object" of a
8858 bit-field, we must deduce this information on our own. This can be rather
8859 tricky to do in some cases. For example, handling the following structure
8860 type definition when compiling for an i386/i486 target (which only aligns
8861 long long's to 32-bit boundaries) can be very tricky:
8863 struct S { int field1; long long field2:31; };
8865 Fortunately, there is a simple rule-of-thumb which can be used in such
8866 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8867 structure shown above. It decides to do this based upon one simple rule
8868 for bit-field allocation. GCC allocates each "containing object" for each
8869 bit-field at the first (i.e. lowest addressed) legitimate alignment
8870 boundary (based upon the required minimum alignment for the declared type
8871 of the field) which it can possibly use, subject to the condition that
8872 there is still enough available space remaining in the containing object
8873 (when allocated at the selected point) to fully accommodate all of the
8874 bits of the bit-field itself.
8876 This simple rule makes it obvious why GCC allocates 8 bytes for each
8877 object of the structure type shown above. When looking for a place to
8878 allocate the "containing object" for `field2', the compiler simply tries
8879 to allocate a 64-bit "containing object" at each successive 32-bit
8880 boundary (starting at zero) until it finds a place to allocate that 64-
8881 bit field such that at least 31 contiguous (and previously unallocated)
8882 bits remain within that selected 64 bit field. (As it turns out, for the
8883 example above, the compiler finds it is OK to allocate the "containing
8884 object" 64-bit field at bit-offset zero within the structure type.)
8886 Here we attempt to work backwards from the limited set of facts we're
8887 given, and we try to deduce from those facts, where GCC must have believed
8888 that the containing object started (within the structure type). The value
8889 we deduce is then used (by the callers of this routine) to generate
8890 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8891 and, in the case of DW_AT_location, regular fields as well). */
8893 /* Figure out the bit-distance from the start of the structure to the
8894 "deepest" bit of the bit-field. */
8895 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
8897 /* This is the tricky part. Use some fancy footwork to deduce where the
8898 lowest addressed bit of the containing object must be. */
8899 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8901 /* Round up to type_align by default. This works best for bitfields. */
8902 object_offset_in_bits
+= type_align_in_bits
- 1;
8903 object_offset_in_bits
/= type_align_in_bits
;
8904 object_offset_in_bits
*= type_align_in_bits
;
8906 if (object_offset_in_bits
> bitpos_int
)
8908 /* Sigh, the decl must be packed. */
8909 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8911 /* Round up to decl_align instead. */
8912 object_offset_in_bits
+= decl_align_in_bits
- 1;
8913 object_offset_in_bits
/= decl_align_in_bits
;
8914 object_offset_in_bits
*= decl_align_in_bits
;
8917 return object_offset_in_bits
/ BITS_PER_UNIT
;
8920 /* The following routines define various Dwarf attributes and any data
8921 associated with them. */
8923 /* Add a location description attribute value to a DIE.
8925 This emits location attributes suitable for whole variables and
8926 whole parameters. Note that the location attributes for struct fields are
8927 generated by the routine `data_member_location_attribute' below. */
8930 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
8931 dw_loc_descr_ref descr
)
8934 add_AT_loc (die
, attr_kind
, descr
);
8937 /* Attach the specialized form of location attribute used for data members of
8938 struct and union types. In the special case of a FIELD_DECL node which
8939 represents a bit-field, the "offset" part of this special location
8940 descriptor must indicate the distance in bytes from the lowest-addressed
8941 byte of the containing struct or union type to the lowest-addressed byte of
8942 the "containing object" for the bit-field. (See the `field_byte_offset'
8945 For any given bit-field, the "containing object" is a hypothetical object
8946 (of some integral or enum type) within which the given bit-field lives. The
8947 type of this hypothetical "containing object" is always the same as the
8948 declared type of the individual bit-field itself (for GCC anyway... the
8949 DWARF spec doesn't actually mandate this). Note that it is the size (in
8950 bytes) of the hypothetical "containing object" which will be given in the
8951 DW_AT_byte_size attribute for this bit-field. (See the
8952 `byte_size_attribute' function below.) It is also used when calculating the
8953 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8957 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
8960 dw_loc_descr_ref loc_descr
= 0;
8962 if (TREE_CODE (decl
) == TREE_VEC
)
8964 /* We're working on the TAG_inheritance for a base class. */
8965 if (TREE_VIA_VIRTUAL (decl
) && is_cxx ())
8967 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8968 aren't at a fixed offset from all (sub)objects of the same
8969 type. We need to extract the appropriate offset from our
8970 vtable. The following dwarf expression means
8972 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8974 This is specific to the V3 ABI, of course. */
8976 dw_loc_descr_ref tmp
;
8978 /* Make a copy of the object address. */
8979 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
8980 add_loc_descr (&loc_descr
, tmp
);
8982 /* Extract the vtable address. */
8983 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
8984 add_loc_descr (&loc_descr
, tmp
);
8986 /* Calculate the address of the offset. */
8987 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
8991 tmp
= int_loc_descriptor (-offset
);
8992 add_loc_descr (&loc_descr
, tmp
);
8993 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
8994 add_loc_descr (&loc_descr
, tmp
);
8996 /* Extract the offset. */
8997 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
8998 add_loc_descr (&loc_descr
, tmp
);
9000 /* Add it to the object address. */
9001 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
9002 add_loc_descr (&loc_descr
, tmp
);
9005 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
9008 offset
= field_byte_offset (decl
);
9012 enum dwarf_location_atom op
;
9014 /* The DWARF2 standard says that we should assume that the structure
9015 address is already on the stack, so we can specify a structure field
9016 address by using DW_OP_plus_uconst. */
9018 #ifdef MIPS_DEBUGGING_INFO
9019 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9020 operator correctly. It works only if we leave the offset on the
9024 op
= DW_OP_plus_uconst
;
9027 loc_descr
= new_loc_descr (op
, offset
, 0);
9030 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
9033 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9034 does not have a "location" either in memory or in a register. These
9035 things can arise in GNU C when a constant is passed as an actual parameter
9036 to an inlined function. They can also arise in C++ where declared
9037 constants do not necessarily get memory "homes". */
9040 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
9042 switch (GET_CODE (rtl
))
9045 /* Note that a CONST_INT rtx could represent either an integer
9046 or a floating-point constant. A CONST_INT is used whenever
9047 the constant will fit into a single word. In all such
9048 cases, the original mode of the constant value is wiped
9049 out, and the CONST_INT rtx is assigned VOIDmode. */
9051 HOST_WIDE_INT val
= INTVAL (rtl
);
9053 /* ??? We really should be using HOST_WIDE_INT throughout. */
9054 if (val
< 0 && (long) val
== val
)
9055 add_AT_int (die
, DW_AT_const_value
, (long) val
);
9056 else if ((unsigned long) val
== (unsigned HOST_WIDE_INT
) val
)
9057 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned long) val
);
9060 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
9061 add_AT_long_long (die
, DW_AT_const_value
,
9062 val
>> HOST_BITS_PER_LONG
, val
);
9071 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9072 floating-point constant. A CONST_DOUBLE is used whenever the
9073 constant requires more than one word in order to be adequately
9074 represented. We output CONST_DOUBLEs as blocks. */
9076 enum machine_mode mode
= GET_MODE (rtl
);
9078 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
9080 unsigned length
= GET_MODE_SIZE (mode
) / 4;
9081 long *array
= (long *) ggc_alloc (sizeof (long) * length
);
9084 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
9088 REAL_VALUE_TO_TARGET_SINGLE (rv
, array
[0]);
9092 REAL_VALUE_TO_TARGET_DOUBLE (rv
, array
);
9097 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv
, array
);
9104 add_AT_float (die
, DW_AT_const_value
, length
, array
);
9108 /* ??? We really should be using HOST_WIDE_INT throughout. */
9109 if (HOST_BITS_PER_LONG
!= HOST_BITS_PER_WIDE_INT
)
9112 add_AT_long_long (die
, DW_AT_const_value
,
9113 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
9119 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
9125 add_AT_addr (die
, DW_AT_const_value
, rtl
);
9126 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
9130 /* In cases where an inlined instance of an inline function is passed
9131 the address of an `auto' variable (which is local to the caller) we
9132 can get a situation where the DECL_RTL of the artificial local
9133 variable (for the inlining) which acts as a stand-in for the
9134 corresponding formal parameter (of the inline function) will look
9135 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9136 exactly a compile-time constant expression, but it isn't the address
9137 of the (artificial) local variable either. Rather, it represents the
9138 *value* which the artificial local variable always has during its
9139 lifetime. We currently have no way to represent such quasi-constant
9140 values in Dwarf, so for now we just punt and generate nothing. */
9144 /* No other kinds of rtx should be possible here. */
9151 rtl_for_decl_location (tree decl
)
9155 /* Here we have to decide where we are going to say the parameter "lives"
9156 (as far as the debugger is concerned). We only have a couple of
9157 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
9159 DECL_RTL normally indicates where the parameter lives during most of the
9160 activation of the function. If optimization is enabled however, this
9161 could be either NULL or else a pseudo-reg. Both of those cases indicate
9162 that the parameter doesn't really live anywhere (as far as the code
9163 generation parts of GCC are concerned) during most of the function's
9164 activation. That will happen (for example) if the parameter is never
9165 referenced within the function.
9167 We could just generate a location descriptor here for all non-NULL
9168 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
9169 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
9170 where DECL_RTL is NULL or is a pseudo-reg.
9172 Note however that we can only get away with using DECL_INCOMING_RTL as
9173 a backup substitute for DECL_RTL in certain limited cases. In cases
9174 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
9175 we can be sure that the parameter was passed using the same type as it is
9176 declared to have within the function, and that its DECL_INCOMING_RTL
9177 points us to a place where a value of that type is passed.
9179 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
9180 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
9181 because in these cases DECL_INCOMING_RTL points us to a value of some
9182 type which is *different* from the type of the parameter itself. Thus,
9183 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
9184 such cases, the debugger would end up (for example) trying to fetch a
9185 `float' from a place which actually contains the first part of a
9186 `double'. That would lead to really incorrect and confusing
9187 output at debug-time.
9189 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
9190 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
9191 are a couple of exceptions however. On little-endian machines we can
9192 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
9193 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
9194 an integral type that is smaller than TREE_TYPE (decl). These cases arise
9195 when (on a little-endian machine) a non-prototyped function has a
9196 parameter declared to be of type `short' or `char'. In such cases,
9197 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
9198 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
9199 passed `int' value. If the debugger then uses that address to fetch
9200 a `short' or a `char' (on a little-endian machine) the result will be
9201 the correct data, so we allow for such exceptional cases below.
9203 Note that our goal here is to describe the place where the given formal
9204 parameter lives during most of the function's activation (i.e. between the
9205 end of the prologue and the start of the epilogue). We'll do that as best
9206 as we can. Note however that if the given formal parameter is modified
9207 sometime during the execution of the function, then a stack backtrace (at
9208 debug-time) will show the function as having been called with the *new*
9209 value rather than the value which was originally passed in. This happens
9210 rarely enough that it is not a major problem, but it *is* a problem, and
9213 A future version of dwarf2out.c may generate two additional attributes for
9214 any given DW_TAG_formal_parameter DIE which will describe the "passed
9215 type" and the "passed location" for the given formal parameter in addition
9216 to the attributes we now generate to indicate the "declared type" and the
9217 "active location" for each parameter. This additional set of attributes
9218 could be used by debuggers for stack backtraces. Separately, note that
9219 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
9220 This happens (for example) for inlined-instances of inline function formal
9221 parameters which are never referenced. This really shouldn't be
9222 happening. All PARM_DECL nodes should get valid non-NULL
9223 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
9224 values for inlined instances of inline function parameters, so when we see
9225 such cases, we are just out-of-luck for the time being (until integrate.c
9228 /* Use DECL_RTL as the "location" unless we find something better. */
9229 rtl
= DECL_RTL_IF_SET (decl
);
9231 /* When generating abstract instances, ignore everything except
9232 constants, symbols living in memory, and symbols living in
9234 if (! reload_completed
)
9237 && (CONSTANT_P (rtl
)
9238 || (GET_CODE (rtl
) == MEM
9239 && CONSTANT_P (XEXP (rtl
, 0)))
9240 || (GET_CODE (rtl
) == REG
9241 && TREE_CODE (decl
) == VAR_DECL
9242 && TREE_STATIC (decl
))))
9244 rtl
= (*targetm
.delegitimize_address
) (rtl
);
9249 else if (TREE_CODE (decl
) == PARM_DECL
)
9251 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
9253 tree declared_type
= type_main_variant (TREE_TYPE (decl
));
9254 tree passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
9256 /* This decl represents a formal parameter which was optimized out.
9257 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
9258 all cases where (rtl == NULL_RTX) just below. */
9259 if (declared_type
== passed_type
)
9260 rtl
= DECL_INCOMING_RTL (decl
);
9261 else if (! BYTES_BIG_ENDIAN
9262 && TREE_CODE (declared_type
) == INTEGER_TYPE
9263 && (GET_MODE_SIZE (TYPE_MODE (declared_type
))
9264 <= GET_MODE_SIZE (TYPE_MODE (passed_type
))))
9265 rtl
= DECL_INCOMING_RTL (decl
);
9268 /* If the parm was passed in registers, but lives on the stack, then
9269 make a big endian correction if the mode of the type of the
9270 parameter is not the same as the mode of the rtl. */
9271 /* ??? This is the same series of checks that are made in dbxout.c before
9272 we reach the big endian correction code there. It isn't clear if all
9273 of these checks are necessary here, but keeping them all is the safe
9275 else if (GET_CODE (rtl
) == MEM
9276 && XEXP (rtl
, 0) != const0_rtx
9277 && ! CONSTANT_P (XEXP (rtl
, 0))
9278 /* Not passed in memory. */
9279 && GET_CODE (DECL_INCOMING_RTL (decl
)) != MEM
9280 /* Not passed by invisible reference. */
9281 && (GET_CODE (XEXP (rtl
, 0)) != REG
9282 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
9283 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
9284 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
9285 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
9288 /* Big endian correction check. */
9290 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
9291 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
9294 int offset
= (UNITS_PER_WORD
9295 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
9297 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
9298 plus_constant (XEXP (rtl
, 0), offset
));
9302 if (rtl
!= NULL_RTX
)
9304 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
9305 #ifdef LEAF_REG_REMAP
9306 if (current_function_uses_only_leaf_regs
)
9307 leaf_renumber_regs_insn (rtl
);
9311 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
9312 and will have been substituted directly into all expressions that use it.
9313 C does not have such a concept, but C++ and other languages do. */
9314 else if (TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
9316 /* If a variable is initialized with a string constant without embedded
9317 zeros, build CONST_STRING. */
9318 if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
9319 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
9321 tree arrtype
= TREE_TYPE (decl
);
9322 tree enttype
= TREE_TYPE (arrtype
);
9323 tree domain
= TYPE_DOMAIN (arrtype
);
9324 tree init
= DECL_INITIAL (decl
);
9325 enum machine_mode mode
= TYPE_MODE (enttype
);
9327 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
9329 && integer_zerop (TYPE_MIN_VALUE (domain
))
9330 && compare_tree_int (TYPE_MAX_VALUE (domain
),
9331 TREE_STRING_LENGTH (init
) - 1) == 0
9332 && ((size_t) TREE_STRING_LENGTH (init
)
9333 == strlen (TREE_STRING_POINTER (init
)) + 1))
9334 rtl
= gen_rtx_CONST_STRING (VOIDmode
, TREE_STRING_POINTER (init
));
9336 /* If the initializer is something that we know will expand into an
9337 immediate RTL constant, expand it now. Expanding anything else
9338 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
9339 else if (TREE_CODE (DECL_INITIAL (decl
)) == INTEGER_CST
9340 || TREE_CODE (DECL_INITIAL (decl
)) == REAL_CST
)
9342 rtl
= expand_expr (DECL_INITIAL (decl
), NULL_RTX
, VOIDmode
,
9343 EXPAND_INITIALIZER
);
9344 /* If expand_expr returns a MEM, it wasn't immediate. */
9345 if (rtl
&& GET_CODE (rtl
) == MEM
)
9351 rtl
= (*targetm
.delegitimize_address
) (rtl
);
9353 /* If we don't look past the constant pool, we risk emitting a
9354 reference to a constant pool entry that isn't referenced from
9355 code, and thus is not emitted. */
9357 rtl
= avoid_constant_pool_reference (rtl
);
9362 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
9363 data attribute for a variable or a parameter. We generate the
9364 DW_AT_const_value attribute only in those cases where the given variable
9365 or parameter does not have a true "location" either in memory or in a
9366 register. This can happen (for example) when a constant is passed as an
9367 actual argument in a call to an inline function. (It's possible that
9368 these things can crop up in other ways also.) Note that one type of
9369 constant value which can be passed into an inlined function is a constant
9370 pointer. This can happen for example if an actual argument in an inlined
9371 function call evaluates to a compile-time constant address. */
9374 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
)
9377 dw_loc_descr_ref descr
;
9379 if (TREE_CODE (decl
) == ERROR_MARK
)
9381 else if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
)
9384 rtl
= rtl_for_decl_location (decl
);
9385 if (rtl
== NULL_RTX
)
9388 switch (GET_CODE (rtl
))
9391 /* The address of a variable that was optimized away;
9392 don't emit anything. */
9402 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
9403 add_const_value_attribute (die
, rtl
);
9407 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL (decl
))
9409 /* Need loc_descriptor_from_tree since that's where we know
9410 how to handle TLS variables. Want the object's address
9411 since the top-level DW_AT_location assumes such. See
9412 the confusion in loc_descriptor for reference. */
9413 descr
= loc_descriptor_from_tree (decl
, 1);
9420 descr
= loc_descriptor (rtl
);
9422 add_AT_location_description (die
, DW_AT_location
, descr
);
9430 /* If we don't have a copy of this variable in memory for some reason (such
9431 as a C++ member constant that doesn't have an out-of-line definition),
9432 we should tell the debugger about the constant value. */
9435 tree_add_const_value_attribute (dw_die_ref var_die
, tree decl
)
9437 tree init
= DECL_INITIAL (decl
);
9438 tree type
= TREE_TYPE (decl
);
9440 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
9441 && initializer_constant_valid_p (init
, type
) == null_pointer_node
)
9446 switch (TREE_CODE (type
))
9449 if (host_integerp (init
, 0))
9450 add_AT_unsigned (var_die
, DW_AT_const_value
,
9451 tree_low_cst (init
, 0));
9453 add_AT_long_long (var_die
, DW_AT_const_value
,
9454 TREE_INT_CST_HIGH (init
),
9455 TREE_INT_CST_LOW (init
));
9462 /* Generate a DW_AT_name attribute given some string value to be included as
9463 the value of the attribute. */
9466 add_name_attribute (dw_die_ref die
, const char *name_string
)
9468 if (name_string
!= NULL
&& *name_string
!= 0)
9470 if (demangle_name_func
)
9471 name_string
= (*demangle_name_func
) (name_string
);
9473 add_AT_string (die
, DW_AT_name
, name_string
);
9477 /* Generate a DW_AT_comp_dir attribute for DIE. */
9480 add_comp_dir_attribute (dw_die_ref die
)
9482 const char *wd
= getpwd ();
9484 add_AT_string (die
, DW_AT_comp_dir
, wd
);
9487 /* Given a tree node describing an array bound (either lower or upper) output
9488 a representation for that bound. */
9491 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
9493 switch (TREE_CODE (bound
))
9498 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9500 if (! host_integerp (bound
, 0)
9501 || (bound_attr
== DW_AT_lower_bound
9502 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
9503 || (is_fortran () && integer_onep (bound
)))))
9504 /* use the default */
9507 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
9512 case NON_LVALUE_EXPR
:
9513 case VIEW_CONVERT_EXPR
:
9514 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
9518 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9519 access the upper bound values may be bogus. If they refer to a
9520 register, they may only describe how to get at these values at the
9521 points in the generated code right after they have just been
9522 computed. Worse yet, in the typical case, the upper bound values
9523 will not even *be* computed in the optimized code (though the
9524 number of elements will), so these SAVE_EXPRs are entirely
9525 bogus. In order to compensate for this fact, we check here to see
9526 if optimization is enabled, and if so, we don't add an attribute
9527 for the (unknown and unknowable) upper bound. This should not
9528 cause too much trouble for existing (stupid?) debuggers because
9529 they have to deal with empty upper bounds location descriptions
9530 anyway in order to be able to deal with incomplete array types.
9531 Of course an intelligent debugger (GDB?) should be able to
9532 comprehend that a missing upper bound specification in an array
9533 type used for a storage class `auto' local array variable
9534 indicates that the upper bound is both unknown (at compile- time)
9535 and unknowable (at run-time) due to optimization.
9537 We assume that a MEM rtx is safe because gcc wouldn't put the
9538 value there unless it was going to be used repeatedly in the
9539 function, i.e. for cleanups. */
9540 if (SAVE_EXPR_RTL (bound
)
9541 && (! optimize
|| GET_CODE (SAVE_EXPR_RTL (bound
)) == MEM
))
9543 dw_die_ref ctx
= lookup_decl_die (current_function_decl
);
9544 dw_die_ref decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9545 rtx loc
= SAVE_EXPR_RTL (bound
);
9547 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9548 it references an outer function's frame. */
9549 if (GET_CODE (loc
) == MEM
)
9551 rtx new_addr
= fix_lexical_addr (XEXP (loc
, 0), bound
);
9553 if (XEXP (loc
, 0) != new_addr
)
9554 loc
= gen_rtx_MEM (GET_MODE (loc
), new_addr
);
9557 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9558 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9559 add_AT_location_description (decl_die
, DW_AT_location
,
9560 loc_descriptor (loc
));
9561 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9564 /* Else leave out the attribute. */
9570 dw_die_ref decl_die
= lookup_decl_die (bound
);
9572 /* ??? Can this happen, or should the variable have been bound
9573 first? Probably it can, since I imagine that we try to create
9574 the types of parameters in the order in which they exist in
9575 the list, and won't have created a forward reference to a
9577 if (decl_die
!= NULL
)
9578 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9584 /* Otherwise try to create a stack operation procedure to
9585 evaluate the value of the array bound. */
9587 dw_die_ref ctx
, decl_die
;
9588 dw_loc_descr_ref loc
;
9590 loc
= loc_descriptor_from_tree (bound
, 0);
9594 if (current_function_decl
== 0)
9595 ctx
= comp_unit_die
;
9597 ctx
= lookup_decl_die (current_function_decl
);
9599 /* If we weren't able to find a context, it's most likely the case
9600 that we are processing the return type of the function. So
9601 make a SAVE_EXPR to point to it and have the limbo DIE code
9602 find the proper die. The save_expr function doesn't always
9603 make a SAVE_EXPR, so do it ourselves. */
9605 bound
= build (SAVE_EXPR
, TREE_TYPE (bound
), bound
,
9606 current_function_decl
, NULL_TREE
);
9608 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9609 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9610 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9611 add_AT_loc (decl_die
, DW_AT_location
, loc
);
9613 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9619 /* Note that the block of subscript information for an array type also
9620 includes information about the element type of type given array type. */
9623 add_subscript_info (dw_die_ref type_die
, tree type
)
9625 #ifndef MIPS_DEBUGGING_INFO
9626 unsigned dimension_number
;
9629 dw_die_ref subrange_die
;
9631 /* The GNU compilers represent multidimensional array types as sequences of
9632 one dimensional array types whose element types are themselves array
9633 types. Here we squish that down, so that each multidimensional array
9634 type gets only one array_type DIE in the Dwarf debugging info. The draft
9635 Dwarf specification say that we are allowed to do this kind of
9636 compression in C (because there is no difference between an array or
9637 arrays and a multidimensional array in C) but for other source languages
9638 (e.g. Ada) we probably shouldn't do this. */
9640 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9641 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9642 We work around this by disabling this feature. See also
9643 gen_array_type_die. */
9644 #ifndef MIPS_DEBUGGING_INFO
9645 for (dimension_number
= 0;
9646 TREE_CODE (type
) == ARRAY_TYPE
;
9647 type
= TREE_TYPE (type
), dimension_number
++)
9650 tree domain
= TYPE_DOMAIN (type
);
9652 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9653 and (in GNU C only) variable bounds. Handle all three forms
9655 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
9658 /* We have an array type with specified bounds. */
9659 lower
= TYPE_MIN_VALUE (domain
);
9660 upper
= TYPE_MAX_VALUE (domain
);
9662 /* define the index type. */
9663 if (TREE_TYPE (domain
))
9665 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9666 TREE_TYPE field. We can't emit debug info for this
9667 because it is an unnamed integral type. */
9668 if (TREE_CODE (domain
) == INTEGER_TYPE
9669 && TYPE_NAME (domain
) == NULL_TREE
9670 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
9671 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
9674 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
9678 /* ??? If upper is NULL, the array has unspecified length,
9679 but it does have a lower bound. This happens with Fortran
9681 Since the debugger is definitely going to need to know N
9682 to produce useful results, go ahead and output the lower
9683 bound solo, and hope the debugger can cope. */
9685 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
9687 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
9690 /* Otherwise we have an array type with an unspecified length. The
9691 DWARF-2 spec does not say how to handle this; let's just leave out the
9697 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
9701 switch (TREE_CODE (tree_node
))
9709 case QUAL_UNION_TYPE
:
9710 size
= int_size_in_bytes (tree_node
);
9713 /* For a data member of a struct or union, the DW_AT_byte_size is
9714 generally given as the number of bytes normally allocated for an
9715 object of the *declared* type of the member itself. This is true
9716 even for bit-fields. */
9717 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
9723 /* Note that `size' might be -1 when we get to this point. If it is, that
9724 indicates that the byte size of the entity in question is variable. We
9725 have no good way of expressing this fact in Dwarf at the present time,
9726 so just let the -1 pass on through. */
9727 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
9730 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9731 which specifies the distance in bits from the highest order bit of the
9732 "containing object" for the bit-field to the highest order bit of the
9735 For any given bit-field, the "containing object" is a hypothetical object
9736 (of some integral or enum type) within which the given bit-field lives. The
9737 type of this hypothetical "containing object" is always the same as the
9738 declared type of the individual bit-field itself. The determination of the
9739 exact location of the "containing object" for a bit-field is rather
9740 complicated. It's handled by the `field_byte_offset' function (above).
9742 Note that it is the size (in bytes) of the hypothetical "containing object"
9743 which will be given in the DW_AT_byte_size attribute for this bit-field.
9744 (See `byte_size_attribute' above). */
9747 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
9749 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
9750 tree type
= DECL_BIT_FIELD_TYPE (decl
);
9751 HOST_WIDE_INT bitpos_int
;
9752 HOST_WIDE_INT highest_order_object_bit_offset
;
9753 HOST_WIDE_INT highest_order_field_bit_offset
;
9754 HOST_WIDE_INT
unsigned bit_offset
;
9756 /* Must be a field and a bit field. */
9758 || TREE_CODE (decl
) != FIELD_DECL
)
9761 /* We can't yet handle bit-fields whose offsets are variable, so if we
9762 encounter such things, just return without generating any attribute
9763 whatsoever. Likewise for variable or too large size. */
9764 if (! host_integerp (bit_position (decl
), 0)
9765 || ! host_integerp (DECL_SIZE (decl
), 1))
9768 bitpos_int
= int_bit_position (decl
);
9770 /* Note that the bit offset is always the distance (in bits) from the
9771 highest-order bit of the "containing object" to the highest-order bit of
9772 the bit-field itself. Since the "high-order end" of any object or field
9773 is different on big-endian and little-endian machines, the computation
9774 below must take account of these differences. */
9775 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
9776 highest_order_field_bit_offset
= bitpos_int
;
9778 if (! BYTES_BIG_ENDIAN
)
9780 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
9781 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
9785 = (! BYTES_BIG_ENDIAN
9786 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
9787 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
9789 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
9792 /* For a FIELD_DECL node which represents a bit field, output an attribute
9793 which specifies the length in bits of the given field. */
9796 add_bit_size_attribute (dw_die_ref die
, tree decl
)
9798 /* Must be a field and a bit field. */
9799 if (TREE_CODE (decl
) != FIELD_DECL
9800 || ! DECL_BIT_FIELD_TYPE (decl
))
9803 if (host_integerp (DECL_SIZE (decl
), 1))
9804 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
9807 /* If the compiled language is ANSI C, then add a 'prototyped'
9808 attribute, if arg types are given for the parameters of a function. */
9811 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
9813 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
9814 && TYPE_ARG_TYPES (func_type
) != NULL
)
9815 add_AT_flag (die
, DW_AT_prototyped
, 1);
9818 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9819 by looking in either the type declaration or object declaration
9823 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
9825 dw_die_ref origin_die
= NULL
;
9827 if (TREE_CODE (origin
) != FUNCTION_DECL
)
9829 /* We may have gotten separated from the block for the inlined
9830 function, if we're in an exception handler or some such; make
9831 sure that the abstract function has been written out.
9833 Doing this for nested functions is wrong, however; functions are
9834 distinct units, and our context might not even be inline. */
9838 fn
= TYPE_STUB_DECL (fn
);
9840 fn
= decl_function_context (fn
);
9842 dwarf2out_abstract_function (fn
);
9845 if (DECL_P (origin
))
9846 origin_die
= lookup_decl_die (origin
);
9847 else if (TYPE_P (origin
))
9848 origin_die
= lookup_type_die (origin
);
9850 if (origin_die
== NULL
)
9853 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
9856 /* We do not currently support the pure_virtual attribute. */
9859 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
9861 if (DECL_VINDEX (func_decl
))
9863 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
9865 if (host_integerp (DECL_VINDEX (func_decl
), 0))
9866 add_AT_loc (die
, DW_AT_vtable_elem_location
,
9867 new_loc_descr (DW_OP_constu
,
9868 tree_low_cst (DECL_VINDEX (func_decl
), 0),
9871 /* GNU extension: Record what type this method came from originally. */
9872 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9873 add_AT_die_ref (die
, DW_AT_containing_type
,
9874 lookup_type_die (DECL_CONTEXT (func_decl
)));
9878 /* Add source coordinate attributes for the given decl. */
9881 add_src_coords_attributes (dw_die_ref die
, tree decl
)
9883 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
9885 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
9886 add_AT_unsigned (die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
9889 /* Add a DW_AT_name attribute and source coordinate attribute for the
9890 given decl, but only if it actually has a name. */
9893 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
9897 decl_name
= DECL_NAME (decl
);
9898 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
9900 add_name_attribute (die
, dwarf2_name (decl
, 0));
9901 if (! DECL_ARTIFICIAL (decl
))
9902 add_src_coords_attributes (die
, decl
);
9904 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
9905 && TREE_PUBLIC (decl
)
9906 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
9907 && !DECL_ABSTRACT (decl
))
9908 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
9909 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
9912 #ifdef VMS_DEBUGGING_INFO
9913 /* Get the function's name, as described by its RTL. This may be different
9914 from the DECL_NAME name used in the source file. */
9915 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
9917 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
9918 XEXP (DECL_RTL (decl
), 0));
9919 VARRAY_PUSH_RTX (used_rtx_varray
, XEXP (DECL_RTL (decl
), 0));
9924 /* Push a new declaration scope. */
9927 push_decl_scope (tree scope
)
9929 VARRAY_PUSH_TREE (decl_scope_table
, scope
);
9932 /* Pop a declaration scope. */
9935 pop_decl_scope (void)
9937 if (VARRAY_ACTIVE_SIZE (decl_scope_table
) <= 0)
9940 VARRAY_POP (decl_scope_table
);
9943 /* Return the DIE for the scope that immediately contains this type.
9944 Non-named types get global scope. Named types nested in other
9945 types get their containing scope if it's open, or global scope
9946 otherwise. All other types (i.e. function-local named types) get
9947 the current active scope. */
9950 scope_die_for (tree t
, dw_die_ref context_die
)
9952 dw_die_ref scope_die
= NULL
;
9953 tree containing_scope
;
9956 /* Non-types always go in the current scope. */
9960 containing_scope
= TYPE_CONTEXT (t
);
9962 /* Ignore namespaces for the moment. */
9963 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
9964 containing_scope
= NULL_TREE
;
9966 /* Ignore function type "scopes" from the C frontend. They mean that
9967 a tagged type is local to a parmlist of a function declarator, but
9968 that isn't useful to DWARF. */
9969 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
9970 containing_scope
= NULL_TREE
;
9972 if (containing_scope
== NULL_TREE
)
9973 scope_die
= comp_unit_die
;
9974 else if (TYPE_P (containing_scope
))
9976 /* For types, we can just look up the appropriate DIE. But
9977 first we check to see if we're in the middle of emitting it
9978 so we know where the new DIE should go. */
9979 for (i
= VARRAY_ACTIVE_SIZE (decl_scope_table
) - 1; i
>= 0; --i
)
9980 if (VARRAY_TREE (decl_scope_table
, i
) == containing_scope
)
9985 if (debug_info_level
> DINFO_LEVEL_TERSE
9986 && !TREE_ASM_WRITTEN (containing_scope
))
9989 /* If none of the current dies are suitable, we get file scope. */
9990 scope_die
= comp_unit_die
;
9993 scope_die
= lookup_type_die (containing_scope
);
9996 scope_die
= context_die
;
10001 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
10004 local_scope_p (dw_die_ref context_die
)
10006 for (; context_die
; context_die
= context_die
->die_parent
)
10007 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
10008 || context_die
->die_tag
== DW_TAG_subprogram
)
10014 /* Returns nonzero if CONTEXT_DIE is a class. */
10017 class_scope_p (dw_die_ref context_die
)
10019 return (context_die
10020 && (context_die
->die_tag
== DW_TAG_structure_type
10021 || context_die
->die_tag
== DW_TAG_union_type
));
10024 /* Many forms of DIEs require a "type description" attribute. This
10025 routine locates the proper "type descriptor" die for the type given
10026 by 'type', and adds a DW_AT_type attribute below the given die. */
10029 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
10030 int decl_volatile
, dw_die_ref context_die
)
10032 enum tree_code code
= TREE_CODE (type
);
10033 dw_die_ref type_die
= NULL
;
10035 /* ??? If this type is an unnamed subrange type of an integral or
10036 floating-point type, use the inner type. This is because we have no
10037 support for unnamed types in base_type_die. This can happen if this is
10038 an Ada subrange type. Correct solution is emit a subrange type die. */
10039 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
10040 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
10041 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
10043 if (code
== ERROR_MARK
10044 /* Handle a special case. For functions whose return type is void, we
10045 generate *no* type attribute. (Note that no object may have type
10046 `void', so this only applies to function return types). */
10047 || code
== VOID_TYPE
)
10050 type_die
= modified_type_die (type
,
10051 decl_const
|| TYPE_READONLY (type
),
10052 decl_volatile
|| TYPE_VOLATILE (type
),
10055 if (type_die
!= NULL
)
10056 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
10059 /* Given a tree pointer to a struct, class, union, or enum type node, return
10060 a pointer to the (string) tag name for the given type, or zero if the type
10061 was declared without a tag. */
10063 static const char *
10064 type_tag (tree type
)
10066 const char *name
= 0;
10068 if (TYPE_NAME (type
) != 0)
10072 /* Find the IDENTIFIER_NODE for the type name. */
10073 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
10074 t
= TYPE_NAME (type
);
10076 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
10077 a TYPE_DECL node, regardless of whether or not a `typedef' was
10079 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10080 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
10081 t
= DECL_NAME (TYPE_NAME (type
));
10083 /* Now get the name as a string, or invent one. */
10085 name
= IDENTIFIER_POINTER (t
);
10088 return (name
== 0 || *name
== '\0') ? 0 : name
;
10091 /* Return the type associated with a data member, make a special check
10092 for bit field types. */
10095 member_declared_type (tree member
)
10097 return (DECL_BIT_FIELD_TYPE (member
)
10098 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
10101 /* Get the decl's label, as described by its RTL. This may be different
10102 from the DECL_NAME name used in the source file. */
10105 static const char *
10106 decl_start_label (tree decl
)
10109 const char *fnname
;
10111 x
= DECL_RTL (decl
);
10112 if (GET_CODE (x
) != MEM
)
10116 if (GET_CODE (x
) != SYMBOL_REF
)
10119 fnname
= XSTR (x
, 0);
10124 /* These routines generate the internal representation of the DIE's for
10125 the compilation unit. Debugging information is collected by walking
10126 the declaration trees passed in from dwarf2out_decl(). */
10129 gen_array_type_die (tree type
, dw_die_ref context_die
)
10131 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
10132 dw_die_ref array_die
;
10135 /* ??? The SGI dwarf reader fails for array of array of enum types unless
10136 the inner array type comes before the outer array type. Thus we must
10137 call gen_type_die before we call new_die. See below also. */
10138 #ifdef MIPS_DEBUGGING_INFO
10139 gen_type_die (TREE_TYPE (type
), context_die
);
10142 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
10143 add_name_attribute (array_die
, type_tag (type
));
10144 equate_type_number_to_die (type
, array_die
);
10146 if (TREE_CODE (type
) == VECTOR_TYPE
)
10148 /* The frontend feeds us a representation for the vector as a struct
10149 containing an array. Pull out the array type. */
10150 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
10151 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
10155 /* We default the array ordering. SDB will probably do
10156 the right things even if DW_AT_ordering is not present. It's not even
10157 an issue until we start to get into multidimensional arrays anyway. If
10158 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
10159 then we'll have to put the DW_AT_ordering attribute back in. (But if
10160 and when we find out that we need to put these in, we will only do so
10161 for multidimensional arrays. */
10162 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
10165 #ifdef MIPS_DEBUGGING_INFO
10166 /* The SGI compilers handle arrays of unknown bound by setting
10167 AT_declaration and not emitting any subrange DIEs. */
10168 if (! TYPE_DOMAIN (type
))
10169 add_AT_unsigned (array_die
, DW_AT_declaration
, 1);
10172 add_subscript_info (array_die
, type
);
10174 /* Add representation of the type of the elements of this array type. */
10175 element_type
= TREE_TYPE (type
);
10177 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10178 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10179 We work around this by disabling this feature. See also
10180 add_subscript_info. */
10181 #ifndef MIPS_DEBUGGING_INFO
10182 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
10183 element_type
= TREE_TYPE (element_type
);
10185 gen_type_die (element_type
, context_die
);
10188 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
10192 gen_set_type_die (tree type
, dw_die_ref context_die
)
10194 dw_die_ref type_die
10195 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
), type
);
10197 equate_type_number_to_die (type
, type_die
);
10198 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
10203 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
10205 tree origin
= decl_ultimate_origin (decl
);
10206 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
10208 if (origin
!= NULL
)
10209 add_abstract_origin_attribute (decl_die
, origin
);
10212 add_name_and_src_coords_attributes (decl_die
, decl
);
10213 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
10214 0, 0, context_die
);
10217 if (DECL_ABSTRACT (decl
))
10218 equate_decl_number_to_die (decl
, decl_die
);
10220 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
10224 /* Walk through the list of incomplete types again, trying once more to
10225 emit full debugging info for them. */
10228 retry_incomplete_types (void)
10232 for (i
= VARRAY_ACTIVE_SIZE (incomplete_types
) - 1; i
>= 0; i
--)
10233 gen_type_die (VARRAY_TREE (incomplete_types
, i
), comp_unit_die
);
10236 /* Generate a DIE to represent an inlined instance of an enumeration type. */
10239 gen_inlined_enumeration_type_die (tree type
, dw_die_ref context_die
)
10241 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
10243 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10244 be incomplete and such types are not marked. */
10245 add_abstract_origin_attribute (type_die
, type
);
10248 /* Generate a DIE to represent an inlined instance of a structure type. */
10251 gen_inlined_structure_type_die (tree type
, dw_die_ref context_die
)
10253 dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
, type
);
10255 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10256 be incomplete and such types are not marked. */
10257 add_abstract_origin_attribute (type_die
, type
);
10260 /* Generate a DIE to represent an inlined instance of a union type. */
10263 gen_inlined_union_type_die (tree type
, dw_die_ref context_die
)
10265 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
10267 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10268 be incomplete and such types are not marked. */
10269 add_abstract_origin_attribute (type_die
, type
);
10272 /* Generate a DIE to represent an enumeration type. Note that these DIEs
10273 include all of the information about the enumeration values also. Each
10274 enumerated type name/value is listed as a child of the enumerated type
10278 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
10280 dw_die_ref type_die
= lookup_type_die (type
);
10282 if (type_die
== NULL
)
10284 type_die
= new_die (DW_TAG_enumeration_type
,
10285 scope_die_for (type
, context_die
), type
);
10286 equate_type_number_to_die (type
, type_die
);
10287 add_name_attribute (type_die
, type_tag (type
));
10289 else if (! TYPE_SIZE (type
))
10292 remove_AT (type_die
, DW_AT_declaration
);
10294 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
10295 given enum type is incomplete, do not generate the DW_AT_byte_size
10296 attribute or the DW_AT_element_list attribute. */
10297 if (TYPE_SIZE (type
))
10301 TREE_ASM_WRITTEN (type
) = 1;
10302 add_byte_size_attribute (type_die
, type
);
10303 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
10304 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
10306 /* If the first reference to this type was as the return type of an
10307 inline function, then it may not have a parent. Fix this now. */
10308 if (type_die
->die_parent
== NULL
)
10309 add_child_die (scope_die_for (type
, context_die
), type_die
);
10311 for (link
= TYPE_FIELDS (type
);
10312 link
!= NULL
; link
= TREE_CHAIN (link
))
10314 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
10316 add_name_attribute (enum_die
,
10317 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
10319 if (host_integerp (TREE_VALUE (link
), 0))
10321 if (tree_int_cst_sgn (TREE_VALUE (link
)) < 0)
10322 add_AT_int (enum_die
, DW_AT_const_value
,
10323 tree_low_cst (TREE_VALUE (link
), 0));
10325 add_AT_unsigned (enum_die
, DW_AT_const_value
,
10326 tree_low_cst (TREE_VALUE (link
), 0));
10331 add_AT_flag (type_die
, DW_AT_declaration
, 1);
10334 /* Generate a DIE to represent either a real live formal parameter decl or to
10335 represent just the type of some formal parameter position in some function
10338 Note that this routine is a bit unusual because its argument may be a
10339 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
10340 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
10341 node. If it's the former then this function is being called to output a
10342 DIE to represent a formal parameter object (or some inlining thereof). If
10343 it's the latter, then this function is only being called to output a
10344 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
10345 argument type of some subprogram type. */
10348 gen_formal_parameter_die (tree node
, dw_die_ref context_die
)
10350 dw_die_ref parm_die
10351 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
10354 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
10357 origin
= decl_ultimate_origin (node
);
10358 if (origin
!= NULL
)
10359 add_abstract_origin_attribute (parm_die
, origin
);
10362 add_name_and_src_coords_attributes (parm_die
, node
);
10363 add_type_attribute (parm_die
, TREE_TYPE (node
),
10364 TREE_READONLY (node
),
10365 TREE_THIS_VOLATILE (node
),
10367 if (DECL_ARTIFICIAL (node
))
10368 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
10371 equate_decl_number_to_die (node
, parm_die
);
10372 if (! DECL_ABSTRACT (node
))
10373 add_location_or_const_value_attribute (parm_die
, node
);
10378 /* We were called with some kind of a ..._TYPE node. */
10379 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
10389 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
10390 at the end of an (ANSI prototyped) formal parameters list. */
10393 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
10395 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
10398 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10399 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10400 parameters as specified in some function type specification (except for
10401 those which appear as part of a function *definition*). */
10404 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
10407 tree formal_type
= NULL
;
10408 tree first_parm_type
;
10411 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
10413 arg
= DECL_ARGUMENTS (function_or_method_type
);
10414 function_or_method_type
= TREE_TYPE (function_or_method_type
);
10419 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
10421 /* Make our first pass over the list of formal parameter types and output a
10422 DW_TAG_formal_parameter DIE for each one. */
10423 for (link
= first_parm_type
; link
; )
10425 dw_die_ref parm_die
;
10427 formal_type
= TREE_VALUE (link
);
10428 if (formal_type
== void_type_node
)
10431 /* Output a (nameless) DIE to represent the formal parameter itself. */
10432 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
10433 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
10434 && link
== first_parm_type
)
10435 || (arg
&& DECL_ARTIFICIAL (arg
)))
10436 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
10438 link
= TREE_CHAIN (link
);
10440 arg
= TREE_CHAIN (arg
);
10443 /* If this function type has an ellipsis, add a
10444 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10445 if (formal_type
!= void_type_node
)
10446 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
10448 /* Make our second (and final) pass over the list of formal parameter types
10449 and output DIEs to represent those types (as necessary). */
10450 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
10451 link
&& TREE_VALUE (link
);
10452 link
= TREE_CHAIN (link
))
10453 gen_type_die (TREE_VALUE (link
), context_die
);
10456 /* We want to generate the DIE for TYPE so that we can generate the
10457 die for MEMBER, which has been defined; we will need to refer back
10458 to the member declaration nested within TYPE. If we're trying to
10459 generate minimal debug info for TYPE, processing TYPE won't do the
10460 trick; we need to attach the member declaration by hand. */
10463 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
10465 gen_type_die (type
, context_die
);
10467 /* If we're trying to avoid duplicate debug info, we may not have
10468 emitted the member decl for this function. Emit it now. */
10469 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
10470 && ! lookup_decl_die (member
))
10472 if (decl_ultimate_origin (member
))
10475 push_decl_scope (type
);
10476 if (TREE_CODE (member
) == FUNCTION_DECL
)
10477 gen_subprogram_die (member
, lookup_type_die (type
));
10479 gen_variable_die (member
, lookup_type_die (type
));
10485 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10486 may later generate inlined and/or out-of-line instances of. */
10489 dwarf2out_abstract_function (tree decl
)
10491 dw_die_ref old_die
;
10494 int was_abstract
= DECL_ABSTRACT (decl
);
10496 /* Make sure we have the actual abstract inline, not a clone. */
10497 decl
= DECL_ORIGIN (decl
);
10499 old_die
= lookup_decl_die (decl
);
10500 if (old_die
&& get_AT_unsigned (old_die
, DW_AT_inline
))
10501 /* We've already generated the abstract instance. */
10504 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10505 we don't get confused by DECL_ABSTRACT. */
10506 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10508 context
= decl_class_context (decl
);
10510 gen_type_die_for_member
10511 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
10514 /* Pretend we've just finished compiling this function. */
10515 save_fn
= current_function_decl
;
10516 current_function_decl
= decl
;
10518 set_decl_abstract_flags (decl
, 1);
10519 dwarf2out_decl (decl
);
10520 if (! was_abstract
)
10521 set_decl_abstract_flags (decl
, 0);
10523 current_function_decl
= save_fn
;
10526 /* Generate a DIE to represent a declared function (either file-scope or
10530 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
10532 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
10533 tree origin
= decl_ultimate_origin (decl
);
10534 dw_die_ref subr_die
;
10538 dw_die_ref old_die
= lookup_decl_die (decl
);
10539 int declaration
= (current_function_decl
!= decl
10540 || class_scope_p (context_die
));
10542 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10543 started to generate the abstract instance of an inline, decided to output
10544 its containing class, and proceeded to emit the declaration of the inline
10545 from the member list for the class. If so, DECLARATION takes priority;
10546 we'll get back to the abstract instance when done with the class. */
10548 /* The class-scope declaration DIE must be the primary DIE. */
10549 if (origin
&& declaration
&& class_scope_p (context_die
))
10556 if (origin
!= NULL
)
10558 if (declaration
&& ! local_scope_p (context_die
))
10561 /* Fixup die_parent for the abstract instance of a nested
10562 inline function. */
10563 if (old_die
&& old_die
->die_parent
== NULL
)
10564 add_child_die (context_die
, old_die
);
10566 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10567 add_abstract_origin_attribute (subr_die
, origin
);
10571 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10573 if (!get_AT_flag (old_die
, DW_AT_declaration
)
10574 /* We can have a normal definition following an inline one in the
10575 case of redefinition of GNU C extern inlines.
10576 It seems reasonable to use AT_specification in this case. */
10577 && !get_AT_unsigned (old_die
, DW_AT_inline
))
10579 /* ??? This can happen if there is a bug in the program, for
10580 instance, if it has duplicate function definitions. Ideally,
10581 we should detect this case and ignore it. For now, if we have
10582 already reported an error, any error at all, then assume that
10583 we got here because of an input error, not a dwarf2 bug. */
10589 /* If the definition comes from the same place as the declaration,
10590 maybe use the old DIE. We always want the DIE for this function
10591 that has the *_pc attributes to be under comp_unit_die so the
10592 debugger can find it. We also need to do this for abstract
10593 instances of inlines, since the spec requires the out-of-line copy
10594 to have the same parent. For local class methods, this doesn't
10595 apply; we just use the old DIE. */
10596 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
10597 && (DECL_ARTIFICIAL (decl
)
10598 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
10599 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10600 == (unsigned) DECL_SOURCE_LINE (decl
)))))
10602 subr_die
= old_die
;
10604 /* Clear out the declaration attribute and the parm types. */
10605 remove_AT (subr_die
, DW_AT_declaration
);
10606 remove_children (subr_die
);
10610 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10611 add_AT_die_ref (subr_die
, DW_AT_specification
, old_die
);
10612 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10613 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
10614 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10615 != (unsigned) DECL_SOURCE_LINE (decl
))
10617 (subr_die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
10622 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10624 if (TREE_PUBLIC (decl
))
10625 add_AT_flag (subr_die
, DW_AT_external
, 1);
10627 add_name_and_src_coords_attributes (subr_die
, decl
);
10628 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10630 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
10631 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
10632 0, 0, context_die
);
10635 add_pure_or_virtual_attribute (subr_die
, decl
);
10636 if (DECL_ARTIFICIAL (decl
))
10637 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
10639 if (TREE_PROTECTED (decl
))
10640 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10641 else if (TREE_PRIVATE (decl
))
10642 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10647 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10649 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
10651 /* The first time we see a member function, it is in the context of
10652 the class to which it belongs. We make sure of this by emitting
10653 the class first. The next time is the definition, which is
10654 handled above. The two may come from the same source text. */
10655 if (DECL_CONTEXT (decl
) || DECL_ABSTRACT (decl
))
10656 equate_decl_number_to_die (decl
, subr_die
);
10659 else if (DECL_ABSTRACT (decl
))
10661 if (DECL_INLINE (decl
) && !flag_no_inline
)
10663 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10664 inline functions, but not for extern inline functions.
10665 We can't get this completely correct because information
10666 about whether the function was declared inline is not
10668 if (DECL_DEFER_OUTPUT (decl
))
10669 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
10671 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
10674 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
10676 equate_decl_number_to_die (decl
, subr_die
);
10678 else if (!DECL_EXTERNAL (decl
))
10680 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10681 equate_decl_number_to_die (decl
, subr_die
);
10683 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
10684 current_function_funcdef_no
);
10685 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
10686 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
10687 current_function_funcdef_no
);
10688 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
10690 add_pubname (decl
, subr_die
);
10691 add_arange (decl
, subr_die
);
10693 #ifdef MIPS_DEBUGGING_INFO
10694 /* Add a reference to the FDE for this routine. */
10695 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
10698 /* Define the "frame base" location for this routine. We use the
10699 frame pointer or stack pointer registers, since the RTL for local
10700 variables is relative to one of them. */
10702 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
10703 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
10706 /* ??? This fails for nested inline functions, because context_display
10707 is not part of the state saved/restored for inline functions. */
10708 if (current_function_needs_context
)
10709 add_AT_location_description (subr_die
, DW_AT_static_link
,
10710 loc_descriptor (lookup_static_chain (decl
)));
10714 /* Now output descriptions of the arguments for this function. This gets
10715 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10716 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10717 `...' at the end of the formal parameter list. In order to find out if
10718 there was a trailing ellipsis or not, we must instead look at the type
10719 associated with the FUNCTION_DECL. This will be a node of type
10720 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10721 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10722 an ellipsis at the end. */
10724 /* In the case where we are describing a mere function declaration, all we
10725 need to do here (and all we *can* do here) is to describe the *types* of
10726 its formal parameters. */
10727 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10729 else if (declaration
)
10730 gen_formal_types_die (decl
, subr_die
);
10733 /* Generate DIEs to represent all known formal parameters. */
10734 tree arg_decls
= DECL_ARGUMENTS (decl
);
10737 /* When generating DIEs, generate the unspecified_parameters DIE
10738 instead if we come across the arg "__builtin_va_alist" */
10739 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
10740 if (TREE_CODE (parm
) == PARM_DECL
)
10742 if (DECL_NAME (parm
)
10743 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
10744 "__builtin_va_alist"))
10745 gen_unspecified_parameters_die (parm
, subr_die
);
10747 gen_decl_die (parm
, subr_die
);
10750 /* Decide whether we need an unspecified_parameters DIE at the end.
10751 There are 2 more cases to do this for: 1) the ansi ... declaration -
10752 this is detectable when the end of the arg list is not a
10753 void_type_node 2) an unprototyped function declaration (not a
10754 definition). This just means that we have no info about the
10755 parameters at all. */
10756 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
10757 if (fn_arg_types
!= NULL
)
10759 /* this is the prototyped case, check for ... */
10760 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
10761 gen_unspecified_parameters_die (decl
, subr_die
);
10763 else if (DECL_INITIAL (decl
) == NULL_TREE
)
10764 gen_unspecified_parameters_die (decl
, subr_die
);
10767 /* Output Dwarf info for all of the stuff within the body of the function
10768 (if it has one - it may be just a declaration). */
10769 outer_scope
= DECL_INITIAL (decl
);
10771 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10772 a function. This BLOCK actually represents the outermost binding contour
10773 for the function, i.e. the contour in which the function's formal
10774 parameters and labels get declared. Curiously, it appears that the front
10775 end doesn't actually put the PARM_DECL nodes for the current function onto
10776 the BLOCK_VARS list for this outer scope, but are strung off of the
10777 DECL_ARGUMENTS list for the function instead.
10779 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10780 the LABEL_DECL nodes for the function however, and we output DWARF info
10781 for those in decls_for_scope. Just within the `outer_scope' there will be
10782 a BLOCK node representing the function's outermost pair of curly braces,
10783 and any blocks used for the base and member initializers of a C++
10784 constructor function. */
10785 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
10787 current_function_has_inlines
= 0;
10788 decls_for_scope (outer_scope
, subr_die
, 0);
10790 #if 0 && defined (MIPS_DEBUGGING_INFO)
10791 if (current_function_has_inlines
)
10793 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
10794 if (! comp_unit_has_inlines
)
10796 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
10797 comp_unit_has_inlines
= 1;
10804 /* Generate a DIE to represent a declared data object. */
10807 gen_variable_die (tree decl
, dw_die_ref context_die
)
10809 tree origin
= decl_ultimate_origin (decl
);
10810 dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
10812 dw_die_ref old_die
= lookup_decl_die (decl
);
10813 int declaration
= (DECL_EXTERNAL (decl
)
10814 || class_scope_p (context_die
));
10816 if (origin
!= NULL
)
10817 add_abstract_origin_attribute (var_die
, origin
);
10819 /* Loop unrolling can create multiple blocks that refer to the same
10820 static variable, so we must test for the DW_AT_declaration flag.
10822 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10823 copy decls and set the DECL_ABSTRACT flag on them instead of
10826 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10827 else if (old_die
&& TREE_STATIC (decl
)
10828 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
10830 /* This is a definition of a C++ class level static. */
10831 add_AT_die_ref (var_die
, DW_AT_specification
, old_die
);
10832 if (DECL_NAME (decl
))
10834 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10836 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10837 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
10839 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10840 != (unsigned) DECL_SOURCE_LINE (decl
))
10842 add_AT_unsigned (var_die
, DW_AT_decl_line
,
10843 DECL_SOURCE_LINE (decl
));
10848 add_name_and_src_coords_attributes (var_die
, decl
);
10849 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
10850 TREE_THIS_VOLATILE (decl
), context_die
);
10852 if (TREE_PUBLIC (decl
))
10853 add_AT_flag (var_die
, DW_AT_external
, 1);
10855 if (DECL_ARTIFICIAL (decl
))
10856 add_AT_flag (var_die
, DW_AT_artificial
, 1);
10858 if (TREE_PROTECTED (decl
))
10859 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10860 else if (TREE_PRIVATE (decl
))
10861 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10865 add_AT_flag (var_die
, DW_AT_declaration
, 1);
10867 if (class_scope_p (context_die
) || DECL_ABSTRACT (decl
))
10868 equate_decl_number_to_die (decl
, var_die
);
10870 if (! declaration
&& ! DECL_ABSTRACT (decl
))
10872 add_location_or_const_value_attribute (var_die
, decl
);
10873 add_pubname (decl
, var_die
);
10876 tree_add_const_value_attribute (var_die
, decl
);
10879 /* Generate a DIE to represent a label identifier. */
10882 gen_label_die (tree decl
, dw_die_ref context_die
)
10884 tree origin
= decl_ultimate_origin (decl
);
10885 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
10887 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10889 if (origin
!= NULL
)
10890 add_abstract_origin_attribute (lbl_die
, origin
);
10892 add_name_and_src_coords_attributes (lbl_die
, decl
);
10894 if (DECL_ABSTRACT (decl
))
10895 equate_decl_number_to_die (decl
, lbl_die
);
10898 insn
= DECL_RTL (decl
);
10900 /* Deleted labels are programmer specified labels which have been
10901 eliminated because of various optimizations. We still emit them
10902 here so that it is possible to put breakpoints on them. */
10903 if (GET_CODE (insn
) == CODE_LABEL
10904 || ((GET_CODE (insn
) == NOTE
10905 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
)))
10907 /* When optimization is enabled (via -O) some parts of the compiler
10908 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10909 represent source-level labels which were explicitly declared by
10910 the user. This really shouldn't be happening though, so catch
10911 it if it ever does happen. */
10912 if (INSN_DELETED_P (insn
))
10915 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
10916 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
10921 /* Generate a DIE for a lexical block. */
10924 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
10926 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
10927 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10929 if (! BLOCK_ABSTRACT (stmt
))
10931 if (BLOCK_FRAGMENT_CHAIN (stmt
))
10935 add_AT_range_list (stmt_die
, DW_AT_ranges
, add_ranges (stmt
));
10937 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
10940 add_ranges (chain
);
10941 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
10948 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10949 BLOCK_NUMBER (stmt
));
10950 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
10951 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10952 BLOCK_NUMBER (stmt
));
10953 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
10957 decls_for_scope (stmt
, stmt_die
, depth
);
10960 /* Generate a DIE for an inlined subprogram. */
10963 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
10965 if (! BLOCK_ABSTRACT (stmt
))
10967 dw_die_ref subr_die
10968 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
10969 tree decl
= block_ultimate_origin (stmt
);
10970 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10972 /* Emit info for the abstract instance first, if we haven't yet. */
10973 dwarf2out_abstract_function (decl
);
10975 add_abstract_origin_attribute (subr_die
, decl
);
10976 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10977 BLOCK_NUMBER (stmt
));
10978 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
10979 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10980 BLOCK_NUMBER (stmt
));
10981 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
10982 decls_for_scope (stmt
, subr_die
, depth
);
10983 current_function_has_inlines
= 1;
10986 /* We may get here if we're the outer block of function A that was
10987 inlined into function B that was inlined into function C. When
10988 generating debugging info for C, dwarf2out_abstract_function(B)
10989 would mark all inlined blocks as abstract, including this one.
10990 So, we wouldn't (and shouldn't) expect labels to be generated
10991 for this one. Instead, just emit debugging info for
10992 declarations within the block. This is particularly important
10993 in the case of initializers of arguments passed from B to us:
10994 if they're statement expressions containing declarations, we
10995 wouldn't generate dies for their abstract variables, and then,
10996 when generating dies for the real variables, we'd die (pun
10998 gen_lexical_block_die (stmt
, context_die
, depth
);
11001 /* Generate a DIE for a field in a record, or structure. */
11004 gen_field_die (tree decl
, dw_die_ref context_die
)
11006 dw_die_ref decl_die
;
11008 if (TREE_TYPE (decl
) == error_mark_node
)
11011 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
11012 add_name_and_src_coords_attributes (decl_die
, decl
);
11013 add_type_attribute (decl_die
, member_declared_type (decl
),
11014 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
11017 if (DECL_BIT_FIELD_TYPE (decl
))
11019 add_byte_size_attribute (decl_die
, decl
);
11020 add_bit_size_attribute (decl_die
, decl
);
11021 add_bit_offset_attribute (decl_die
, decl
);
11024 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
11025 add_data_member_location_attribute (decl_die
, decl
);
11027 if (DECL_ARTIFICIAL (decl
))
11028 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
11030 if (TREE_PROTECTED (decl
))
11031 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11032 else if (TREE_PRIVATE (decl
))
11033 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11037 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11038 Use modified_type_die instead.
11039 We keep this code here just in case these types of DIEs may be needed to
11040 represent certain things in other languages (e.g. Pascal) someday. */
11043 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
11046 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
11048 equate_type_number_to_die (type
, ptr_die
);
11049 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
11050 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
11053 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11054 Use modified_type_die instead.
11055 We keep this code here just in case these types of DIEs may be needed to
11056 represent certain things in other languages (e.g. Pascal) someday. */
11059 gen_reference_type_die (tree type
, dw_die_ref context_die
)
11062 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
11064 equate_type_number_to_die (type
, ref_die
);
11065 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
11066 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
11070 /* Generate a DIE for a pointer to a member type. */
11073 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
11076 = new_die (DW_TAG_ptr_to_member_type
,
11077 scope_die_for (type
, context_die
), type
);
11079 equate_type_number_to_die (type
, ptr_die
);
11080 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
11081 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
11082 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
11085 /* Generate the DIE for the compilation unit. */
11088 gen_compile_unit_die (const char *filename
)
11091 char producer
[250];
11092 const char *language_string
= lang_hooks
.name
;
11095 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
11099 add_name_attribute (die
, filename
);
11100 /* Don't add cwd for <built-in>. */
11101 if (filename
[0] != DIR_SEPARATOR
&& filename
[0] != '<')
11102 add_comp_dir_attribute (die
);
11105 sprintf (producer
, "%s %s", language_string
, version_string
);
11107 #ifdef MIPS_DEBUGGING_INFO
11108 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
11109 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
11110 not appear in the producer string, the debugger reaches the conclusion
11111 that the object file is stripped and has no debugging information.
11112 To get the MIPS/SGI debugger to believe that there is debugging
11113 information in the object file, we add a -g to the producer string. */
11114 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11115 strcat (producer
, " -g");
11118 add_AT_string (die
, DW_AT_producer
, producer
);
11120 if (strcmp (language_string
, "GNU C++") == 0)
11121 language
= DW_LANG_C_plus_plus
;
11122 else if (strcmp (language_string
, "GNU Ada") == 0)
11123 language
= DW_LANG_Ada95
;
11124 else if (strcmp (language_string
, "GNU F77") == 0)
11125 language
= DW_LANG_Fortran77
;
11126 else if (strcmp (language_string
, "GNU Pascal") == 0)
11127 language
= DW_LANG_Pascal83
;
11128 else if (strcmp (language_string
, "GNU Java") == 0)
11129 language
= DW_LANG_Java
;
11131 language
= DW_LANG_C89
;
11133 add_AT_unsigned (die
, DW_AT_language
, language
);
11137 /* Generate a DIE for a string type. */
11140 gen_string_type_die (tree type
, dw_die_ref context_die
)
11142 dw_die_ref type_die
11143 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
), type
);
11145 equate_type_number_to_die (type
, type_die
);
11147 /* ??? Fudge the string length attribute for now.
11148 TODO: add string length info. */
11150 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
11151 bound_representation (upper_bound
, 0, 'u');
11155 /* Generate the DIE for a base class. */
11158 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
11160 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
11162 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
11163 add_data_member_location_attribute (die
, binfo
);
11165 if (TREE_VIA_VIRTUAL (binfo
))
11166 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
11168 if (access
== access_public_node
)
11169 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
11170 else if (access
== access_protected_node
)
11171 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11174 /* Generate a DIE for a class member. */
11177 gen_member_die (tree type
, dw_die_ref context_die
)
11180 tree binfo
= TYPE_BINFO (type
);
11183 /* If this is not an incomplete type, output descriptions of each of its
11184 members. Note that as we output the DIEs necessary to represent the
11185 members of this record or union type, we will also be trying to output
11186 DIEs to represent the *types* of those members. However the `type'
11187 function (above) will specifically avoid generating type DIEs for member
11188 types *within* the list of member DIEs for this (containing) type except
11189 for those types (of members) which are explicitly marked as also being
11190 members of this (containing) type themselves. The g++ front- end can
11191 force any given type to be treated as a member of some other (containing)
11192 type by setting the TYPE_CONTEXT of the given (member) type to point to
11193 the TREE node representing the appropriate (containing) type. */
11195 /* First output info about the base classes. */
11196 if (binfo
&& BINFO_BASETYPES (binfo
))
11198 tree bases
= BINFO_BASETYPES (binfo
);
11199 tree accesses
= BINFO_BASEACCESSES (binfo
);
11200 int n_bases
= TREE_VEC_LENGTH (bases
);
11203 for (i
= 0; i
< n_bases
; i
++)
11204 gen_inheritance_die (TREE_VEC_ELT (bases
, i
),
11205 (accesses
? TREE_VEC_ELT (accesses
, i
)
11206 : access_public_node
), context_die
);
11209 /* Now output info about the data members and type members. */
11210 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
11212 /* If we thought we were generating minimal debug info for TYPE
11213 and then changed our minds, some of the member declarations
11214 may have already been defined. Don't define them again, but
11215 do put them in the right order. */
11217 child
= lookup_decl_die (member
);
11219 splice_child_die (context_die
, child
);
11221 gen_decl_die (member
, context_die
);
11224 /* Now output info about the function members (if any). */
11225 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
11227 /* Don't include clones in the member list. */
11228 if (DECL_ABSTRACT_ORIGIN (member
))
11231 child
= lookup_decl_die (member
);
11233 splice_child_die (context_die
, child
);
11235 gen_decl_die (member
, context_die
);
11239 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
11240 is set, we pretend that the type was never defined, so we only get the
11241 member DIEs needed by later specification DIEs. */
11244 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
)
11246 dw_die_ref type_die
= lookup_type_die (type
);
11247 dw_die_ref scope_die
= 0;
11249 int complete
= (TYPE_SIZE (type
)
11250 && (! TYPE_STUB_DECL (type
)
11251 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
11253 if (type_die
&& ! complete
)
11256 if (TYPE_CONTEXT (type
) != NULL_TREE
11257 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
)))
11260 scope_die
= scope_die_for (type
, context_die
);
11262 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
11263 /* First occurrence of type or toplevel definition of nested class. */
11265 dw_die_ref old_die
= type_die
;
11267 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
11268 ? DW_TAG_structure_type
: DW_TAG_union_type
,
11270 equate_type_number_to_die (type
, type_die
);
11272 add_AT_die_ref (type_die
, DW_AT_specification
, old_die
);
11274 add_name_attribute (type_die
, type_tag (type
));
11277 remove_AT (type_die
, DW_AT_declaration
);
11279 /* If this type has been completed, then give it a byte_size attribute and
11280 then give a list of members. */
11283 /* Prevent infinite recursion in cases where the type of some member of
11284 this type is expressed in terms of this type itself. */
11285 TREE_ASM_WRITTEN (type
) = 1;
11286 add_byte_size_attribute (type_die
, type
);
11287 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
11288 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
11290 /* If the first reference to this type was as the return type of an
11291 inline function, then it may not have a parent. Fix this now. */
11292 if (type_die
->die_parent
== NULL
)
11293 add_child_die (scope_die
, type_die
);
11295 push_decl_scope (type
);
11296 gen_member_die (type
, type_die
);
11299 /* GNU extension: Record what type our vtable lives in. */
11300 if (TYPE_VFIELD (type
))
11302 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
11304 gen_type_die (vtype
, context_die
);
11305 add_AT_die_ref (type_die
, DW_AT_containing_type
,
11306 lookup_type_die (vtype
));
11311 add_AT_flag (type_die
, DW_AT_declaration
, 1);
11313 /* We don't need to do this for function-local types. */
11314 if (TYPE_STUB_DECL (type
)
11315 && ! decl_function_context (TYPE_STUB_DECL (type
)))
11316 VARRAY_PUSH_TREE (incomplete_types
, type
);
11320 /* Generate a DIE for a subroutine _type_. */
11323 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
11325 tree return_type
= TREE_TYPE (type
);
11326 dw_die_ref subr_die
11327 = new_die (DW_TAG_subroutine_type
,
11328 scope_die_for (type
, context_die
), type
);
11330 equate_type_number_to_die (type
, subr_die
);
11331 add_prototyped_attribute (subr_die
, type
);
11332 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
11333 gen_formal_types_die (type
, subr_die
);
11336 /* Generate a DIE for a type definition. */
11339 gen_typedef_die (tree decl
, dw_die_ref context_die
)
11341 dw_die_ref type_die
;
11344 if (TREE_ASM_WRITTEN (decl
))
11347 TREE_ASM_WRITTEN (decl
) = 1;
11348 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
11349 origin
= decl_ultimate_origin (decl
);
11350 if (origin
!= NULL
)
11351 add_abstract_origin_attribute (type_die
, origin
);
11356 add_name_and_src_coords_attributes (type_die
, decl
);
11357 if (DECL_ORIGINAL_TYPE (decl
))
11359 type
= DECL_ORIGINAL_TYPE (decl
);
11361 if (type
== TREE_TYPE (decl
))
11364 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
11367 type
= TREE_TYPE (decl
);
11369 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
11370 TREE_THIS_VOLATILE (decl
), context_die
);
11373 if (DECL_ABSTRACT (decl
))
11374 equate_decl_number_to_die (decl
, type_die
);
11377 /* Generate a type description DIE. */
11380 gen_type_die (tree type
, dw_die_ref context_die
)
11384 if (type
== NULL_TREE
|| type
== error_mark_node
)
11387 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
11388 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
11390 if (TREE_ASM_WRITTEN (type
))
11393 /* Prevent broken recursion; we can't hand off to the same type. */
11394 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) == type
)
11397 TREE_ASM_WRITTEN (type
) = 1;
11398 gen_decl_die (TYPE_NAME (type
), context_die
);
11402 /* We are going to output a DIE to represent the unqualified version
11403 of this type (i.e. without any const or volatile qualifiers) so
11404 get the main variant (i.e. the unqualified version) of this type
11405 now. (Vectors are special because the debugging info is in the
11406 cloned type itself). */
11407 if (TREE_CODE (type
) != VECTOR_TYPE
)
11408 type
= type_main_variant (type
);
11410 if (TREE_ASM_WRITTEN (type
))
11413 switch (TREE_CODE (type
))
11419 case REFERENCE_TYPE
:
11420 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11421 ensures that the gen_type_die recursion will terminate even if the
11422 type is recursive. Recursive types are possible in Ada. */
11423 /* ??? We could perhaps do this for all types before the switch
11425 TREE_ASM_WRITTEN (type
) = 1;
11427 /* For these types, all that is required is that we output a DIE (or a
11428 set of DIEs) to represent the "basis" type. */
11429 gen_type_die (TREE_TYPE (type
), context_die
);
11433 /* This code is used for C++ pointer-to-data-member types.
11434 Output a description of the relevant class type. */
11435 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
11437 /* Output a description of the type of the object pointed to. */
11438 gen_type_die (TREE_TYPE (type
), context_die
);
11440 /* Now output a DIE to represent this pointer-to-data-member type
11442 gen_ptr_to_mbr_type_die (type
, context_die
);
11446 gen_type_die (TYPE_DOMAIN (type
), context_die
);
11447 gen_set_type_die (type
, context_die
);
11451 gen_type_die (TREE_TYPE (type
), context_die
);
11452 abort (); /* No way to represent these in Dwarf yet! */
11455 case FUNCTION_TYPE
:
11456 /* Force out return type (in case it wasn't forced out already). */
11457 gen_type_die (TREE_TYPE (type
), context_die
);
11458 gen_subroutine_type_die (type
, context_die
);
11462 /* Force out return type (in case it wasn't forced out already). */
11463 gen_type_die (TREE_TYPE (type
), context_die
);
11464 gen_subroutine_type_die (type
, context_die
);
11468 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
11470 gen_type_die (TREE_TYPE (type
), context_die
);
11471 gen_string_type_die (type
, context_die
);
11474 gen_array_type_die (type
, context_die
);
11478 gen_array_type_die (type
, context_die
);
11481 case ENUMERAL_TYPE
:
11484 case QUAL_UNION_TYPE
:
11485 /* If this is a nested type whose containing class hasn't been written
11486 out yet, writing it out will cover this one, too. This does not apply
11487 to instantiations of member class templates; they need to be added to
11488 the containing class as they are generated. FIXME: This hurts the
11489 idea of combining type decls from multiple TUs, since we can't predict
11490 what set of template instantiations we'll get. */
11491 if (TYPE_CONTEXT (type
)
11492 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
11493 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
11495 gen_type_die (TYPE_CONTEXT (type
), context_die
);
11497 if (TREE_ASM_WRITTEN (type
))
11500 /* If that failed, attach ourselves to the stub. */
11501 push_decl_scope (TYPE_CONTEXT (type
));
11502 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
11508 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
11509 gen_enumeration_type_die (type
, context_die
);
11511 gen_struct_or_union_type_die (type
, context_die
);
11516 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11517 it up if it is ever completed. gen_*_type_die will set it for us
11518 when appropriate. */
11527 /* No DIEs needed for fundamental types. */
11531 /* No Dwarf representation currently defined. */
11538 TREE_ASM_WRITTEN (type
) = 1;
11541 /* Generate a DIE for a tagged type instantiation. */
11544 gen_tagged_type_instantiation_die (tree type
, dw_die_ref context_die
)
11546 if (type
== NULL_TREE
|| type
== error_mark_node
)
11549 /* We are going to output a DIE to represent the unqualified version of
11550 this type (i.e. without any const or volatile qualifiers) so make sure
11551 that we have the main variant (i.e. the unqualified version) of this
11553 if (type
!= type_main_variant (type
))
11556 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11557 an instance of an unresolved type. */
11559 switch (TREE_CODE (type
))
11564 case ENUMERAL_TYPE
:
11565 gen_inlined_enumeration_type_die (type
, context_die
);
11569 gen_inlined_structure_type_die (type
, context_die
);
11573 case QUAL_UNION_TYPE
:
11574 gen_inlined_union_type_die (type
, context_die
);
11582 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11583 things which are local to the given block. */
11586 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
11588 int must_output_die
= 0;
11591 enum tree_code origin_code
;
11593 /* Ignore blocks never really used to make RTL. */
11594 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
)
11595 || (!TREE_ASM_WRITTEN (stmt
) && !BLOCK_ABSTRACT (stmt
)))
11598 /* If the block is one fragment of a non-contiguous block, do not
11599 process the variables, since they will have been done by the
11600 origin block. Do process subblocks. */
11601 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
11605 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
11606 gen_block_die (sub
, context_die
, depth
+ 1);
11611 /* Determine the "ultimate origin" of this block. This block may be an
11612 inlined instance of an inlined instance of inline function, so we have
11613 to trace all of the way back through the origin chain to find out what
11614 sort of node actually served as the original seed for the creation of
11615 the current block. */
11616 origin
= block_ultimate_origin (stmt
);
11617 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
11619 /* Determine if we need to output any Dwarf DIEs at all to represent this
11621 if (origin_code
== FUNCTION_DECL
)
11622 /* The outer scopes for inlinings *must* always be represented. We
11623 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11624 must_output_die
= 1;
11627 /* In the case where the current block represents an inlining of the
11628 "body block" of an inline function, we must *NOT* output any DIE for
11629 this block because we have already output a DIE to represent the whole
11630 inlined function scope and the "body block" of any function doesn't
11631 really represent a different scope according to ANSI C rules. So we
11632 check here to make sure that this block does not represent a "body
11633 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11634 if (! is_body_block (origin
? origin
: stmt
))
11636 /* Determine if this block directly contains any "significant"
11637 local declarations which we will need to output DIEs for. */
11638 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11639 /* We are not in terse mode so *any* local declaration counts
11640 as being a "significant" one. */
11641 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
11643 /* We are in terse mode, so only local (nested) function
11644 definitions count as "significant" local declarations. */
11645 for (decl
= BLOCK_VARS (stmt
);
11646 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11647 if (TREE_CODE (decl
) == FUNCTION_DECL
11648 && DECL_INITIAL (decl
))
11650 must_output_die
= 1;
11656 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11657 DIE for any block which contains no significant local declarations at
11658 all. Rather, in such cases we just call `decls_for_scope' so that any
11659 needed Dwarf info for any sub-blocks will get properly generated. Note
11660 that in terse mode, our definition of what constitutes a "significant"
11661 local declaration gets restricted to include only inlined function
11662 instances and local (nested) function definitions. */
11663 if (must_output_die
)
11665 if (origin_code
== FUNCTION_DECL
)
11666 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
11668 gen_lexical_block_die (stmt
, context_die
, depth
);
11671 decls_for_scope (stmt
, context_die
, depth
);
11674 /* Generate all of the decls declared within a given scope and (recursively)
11675 all of its sub-blocks. */
11678 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
11683 /* Ignore blocks never really used to make RTL. */
11684 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
11687 /* Output the DIEs to represent all of the data objects and typedefs
11688 declared directly within this block but not within any nested
11689 sub-blocks. Also, nested function and tag DIEs have been
11690 generated with a parent of NULL; fix that up now. */
11691 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11695 if (TREE_CODE (decl
) == FUNCTION_DECL
)
11696 die
= lookup_decl_die (decl
);
11697 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
11698 die
= lookup_type_die (TREE_TYPE (decl
));
11702 if (die
!= NULL
&& die
->die_parent
== NULL
)
11703 add_child_die (context_die
, die
);
11705 gen_decl_die (decl
, context_die
);
11708 /* If we're at -g1, we're not interested in subblocks. */
11709 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11712 /* Output the DIEs to represent all sub-blocks (and the items declared
11713 therein) of this block. */
11714 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
11716 subblocks
= BLOCK_CHAIN (subblocks
))
11717 gen_block_die (subblocks
, context_die
, depth
+ 1);
11720 /* Is this a typedef we can avoid emitting? */
11723 is_redundant_typedef (tree decl
)
11725 if (TYPE_DECL_IS_STUB (decl
))
11728 if (DECL_ARTIFICIAL (decl
)
11729 && DECL_CONTEXT (decl
)
11730 && is_tagged_type (DECL_CONTEXT (decl
))
11731 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
11732 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
11733 /* Also ignore the artificial member typedef for the class name. */
11739 /* Generate Dwarf debug information for a decl described by DECL. */
11742 gen_decl_die (tree decl
, dw_die_ref context_die
)
11746 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
11749 switch (TREE_CODE (decl
))
11755 /* The individual enumerators of an enum type get output when we output
11756 the Dwarf representation of the relevant enum type itself. */
11759 case FUNCTION_DECL
:
11760 /* Don't output any DIEs to represent mere function declarations,
11761 unless they are class members or explicit block externs. */
11762 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
11763 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
11766 /* If we're emitting a clone, emit info for the abstract instance. */
11767 if (DECL_ORIGIN (decl
) != decl
)
11768 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
11770 /* If we're emitting an out-of-line copy of an inline function,
11771 emit info for the abstract instance and set up to refer to it. */
11772 else if (DECL_INLINE (decl
) && ! DECL_ABSTRACT (decl
)
11773 && ! class_scope_p (context_die
)
11774 /* dwarf2out_abstract_function won't emit a die if this is just
11775 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11776 that case, because that works only if we have a die. */
11777 && DECL_INITIAL (decl
) != NULL_TREE
)
11779 dwarf2out_abstract_function (decl
);
11780 set_decl_origin_self (decl
);
11783 /* Otherwise we're emitting the primary DIE for this decl. */
11784 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
11786 /* Before we describe the FUNCTION_DECL itself, make sure that we
11787 have described its return type. */
11788 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
11790 /* And its virtual context. */
11791 if (DECL_VINDEX (decl
) != NULL_TREE
)
11792 gen_type_die (DECL_CONTEXT (decl
), context_die
);
11794 /* And its containing type. */
11795 origin
= decl_class_context (decl
);
11796 if (origin
!= NULL_TREE
)
11797 gen_type_die_for_member (origin
, decl
, context_die
);
11800 /* Now output a DIE to represent the function itself. */
11801 gen_subprogram_die (decl
, context_die
);
11805 /* If we are in terse mode, don't generate any DIEs to represent any
11806 actual typedefs. */
11807 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11810 /* In the special case of a TYPE_DECL node representing the declaration
11811 of some type tag, if the given TYPE_DECL is marked as having been
11812 instantiated from some other (original) TYPE_DECL node (e.g. one which
11813 was generated within the original definition of an inline function) we
11814 have to generate a special (abbreviated) DW_TAG_structure_type,
11815 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11816 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
11818 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
11822 if (is_redundant_typedef (decl
))
11823 gen_type_die (TREE_TYPE (decl
), context_die
);
11825 /* Output a DIE to represent the typedef itself. */
11826 gen_typedef_die (decl
, context_die
);
11830 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
11831 gen_label_die (decl
, context_die
);
11835 /* If we are in terse mode, don't generate any DIEs to represent any
11836 variable declarations or definitions. */
11837 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11840 /* Output any DIEs that are needed to specify the type of this data
11842 gen_type_die (TREE_TYPE (decl
), context_die
);
11844 /* And its containing type. */
11845 origin
= decl_class_context (decl
);
11846 if (origin
!= NULL_TREE
)
11847 gen_type_die_for_member (origin
, decl
, context_die
);
11849 /* Now output the DIE to represent the data object itself. This gets
11850 complicated because of the possibility that the VAR_DECL really
11851 represents an inlined instance of a formal parameter for an inline
11853 origin
= decl_ultimate_origin (decl
);
11854 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
11855 gen_formal_parameter_die (decl
, context_die
);
11857 gen_variable_die (decl
, context_die
);
11861 /* Ignore the nameless fields that are used to skip bits but handle C++
11862 anonymous unions. */
11863 if (DECL_NAME (decl
) != NULL_TREE
11864 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
)
11866 gen_type_die (member_declared_type (decl
), context_die
);
11867 gen_field_die (decl
, context_die
);
11872 gen_type_die (TREE_TYPE (decl
), context_die
);
11873 gen_formal_parameter_die (decl
, context_die
);
11876 case NAMESPACE_DECL
:
11877 /* Ignore for now. */
11881 if ((int)TREE_CODE (decl
) > NUM_TREE_CODES
)
11882 /* Probably some frontend-internal decl. Assume we don't care. */
11888 /* Add Ada "use" clause information for SGI Workshop debugger. */
11891 dwarf2out_add_library_unit_info (const char *filename
, const char *context_list
)
11893 unsigned int file_index
;
11895 if (filename
!= NULL
)
11897 dw_die_ref unit_die
= new_die (DW_TAG_module
, comp_unit_die
, NULL
);
11898 tree context_list_decl
11899 = build_decl (LABEL_DECL
, get_identifier (context_list
),
11902 TREE_PUBLIC (context_list_decl
) = TRUE
;
11903 add_name_attribute (unit_die
, context_list
);
11904 file_index
= lookup_filename (filename
);
11905 add_AT_unsigned (unit_die
, DW_AT_decl_file
, file_index
);
11906 add_pubname (context_list_decl
, unit_die
);
11910 /* Output debug information for global decl DECL. Called from toplev.c after
11911 compilation proper has finished. */
11914 dwarf2out_global_decl (tree decl
)
11916 /* Output DWARF2 information for file-scope tentative data object
11917 declarations, file-scope (extern) function declarations (which had no
11918 corresponding body) and file-scope tagged type declarations and
11919 definitions which have not yet been forced out. */
11920 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
11921 dwarf2out_decl (decl
);
11924 /* Write the debugging output for DECL. */
11927 dwarf2out_decl (tree decl
)
11929 dw_die_ref context_die
= comp_unit_die
;
11931 switch (TREE_CODE (decl
))
11936 case FUNCTION_DECL
:
11937 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11938 builtin function. Explicit programmer-supplied declarations of
11939 these same functions should NOT be ignored however. */
11940 if (DECL_EXTERNAL (decl
) && DECL_BUILT_IN (decl
))
11943 /* What we would really like to do here is to filter out all mere
11944 file-scope declarations of file-scope functions which are never
11945 referenced later within this translation unit (and keep all of ones
11946 that *are* referenced later on) but we aren't clairvoyant, so we have
11947 no idea which functions will be referenced in the future (i.e. later
11948 on within the current translation unit). So here we just ignore all
11949 file-scope function declarations which are not also definitions. If
11950 and when the debugger needs to know something about these functions,
11951 it will have to hunt around and find the DWARF information associated
11952 with the definition of the function.
11954 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11955 nodes represent definitions and which ones represent mere
11956 declarations. We have to check DECL_INITIAL instead. That's because
11957 the C front-end supports some weird semantics for "extern inline"
11958 function definitions. These can get inlined within the current
11959 translation unit (an thus, we need to generate Dwarf info for their
11960 abstract instances so that the Dwarf info for the concrete inlined
11961 instances can have something to refer to) but the compiler never
11962 generates any out-of-lines instances of such things (despite the fact
11963 that they *are* definitions).
11965 The important point is that the C front-end marks these "extern
11966 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11967 them anyway. Note that the C++ front-end also plays some similar games
11968 for inline function definitions appearing within include files which
11969 also contain `#pragma interface' pragmas. */
11970 if (DECL_INITIAL (decl
) == NULL_TREE
)
11973 /* If we're a nested function, initially use a parent of NULL; if we're
11974 a plain function, this will be fixed up in decls_for_scope. If
11975 we're a method, it will be ignored, since we already have a DIE. */
11976 if (decl_function_context (decl
)
11977 /* But if we're in terse mode, we don't care about scope. */
11978 && debug_info_level
> DINFO_LEVEL_TERSE
)
11979 context_die
= NULL
;
11983 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11984 declaration and if the declaration was never even referenced from
11985 within this entire compilation unit. We suppress these DIEs in
11986 order to save space in the .debug section (by eliminating entries
11987 which are probably useless). Note that we must not suppress
11988 block-local extern declarations (whether used or not) because that
11989 would screw-up the debugger's name lookup mechanism and cause it to
11990 miss things which really ought to be in scope at a given point. */
11991 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
11994 /* If we are in terse mode, don't generate any DIEs to represent any
11995 variable declarations or definitions. */
11996 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12001 /* Don't emit stubs for types unless they are needed by other DIEs. */
12002 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
12005 /* Don't bother trying to generate any DIEs to represent any of the
12006 normal built-in types for the language we are compiling. */
12007 if (DECL_SOURCE_LINE (decl
) == 0)
12009 /* OK, we need to generate one for `bool' so GDB knows what type
12010 comparisons have. */
12011 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
12012 == DW_LANG_C_plus_plus
)
12013 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
12014 && ! DECL_IGNORED_P (decl
))
12015 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
12020 /* If we are in terse mode, don't generate any DIEs for types. */
12021 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12024 /* If we're a function-scope tag, initially use a parent of NULL;
12025 this will be fixed up in decls_for_scope. */
12026 if (decl_function_context (decl
))
12027 context_die
= NULL
;
12035 gen_decl_die (decl
, context_die
);
12038 /* Output a marker (i.e. a label) for the beginning of the generated code for
12039 a lexical block. */
12042 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
12043 unsigned int blocknum
)
12045 function_section (current_function_decl
);
12046 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
12049 /* Output a marker (i.e. a label) for the end of the generated code for a
12053 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
12055 function_section (current_function_decl
);
12056 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
12059 /* Returns nonzero if it is appropriate not to emit any debugging
12060 information for BLOCK, because it doesn't contain any instructions.
12062 Don't allow this for blocks with nested functions or local classes
12063 as we would end up with orphans, and in the presence of scheduling
12064 we may end up calling them anyway. */
12067 dwarf2out_ignore_block (tree block
)
12071 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
12072 if (TREE_CODE (decl
) == FUNCTION_DECL
12073 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
12079 /* Lookup FILE_NAME (in the list of filenames that we know about here in
12080 dwarf2out.c) and return its "index". The index of each (known) filename is
12081 just a unique number which is associated with only that one filename. We
12082 need such numbers for the sake of generating labels (in the .debug_sfnames
12083 section) and references to those files numbers (in the .debug_srcinfo
12084 and.debug_macinfo sections). If the filename given as an argument is not
12085 found in our current list, add it to the list and assign it the next
12086 available unique index number. In order to speed up searches, we remember
12087 the index of the filename was looked up last. This handles the majority of
12091 lookup_filename (const char *file_name
)
12094 char *save_file_name
;
12096 /* Check to see if the file name that was searched on the previous
12097 call matches this file name. If so, return the index. */
12098 if (file_table_last_lookup_index
!= 0)
12101 = VARRAY_CHAR_PTR (file_table
, file_table_last_lookup_index
);
12102 if (strcmp (file_name
, last
) == 0)
12103 return file_table_last_lookup_index
;
12106 /* Didn't match the previous lookup, search the table */
12107 n
= VARRAY_ACTIVE_SIZE (file_table
);
12108 for (i
= 1; i
< n
; i
++)
12109 if (strcmp (file_name
, VARRAY_CHAR_PTR (file_table
, i
)) == 0)
12111 file_table_last_lookup_index
= i
;
12115 /* Add the new entry to the end of the filename table. */
12116 file_table_last_lookup_index
= n
;
12117 save_file_name
= (char *) ggc_strdup (file_name
);
12118 VARRAY_PUSH_CHAR_PTR (file_table
, save_file_name
);
12119 VARRAY_PUSH_UINT (file_table_emitted
, 0);
12125 maybe_emit_file (int fileno
)
12127 if (DWARF2_ASM_LINE_DEBUG_INFO
&& fileno
> 0)
12129 if (!VARRAY_UINT (file_table_emitted
, fileno
))
12131 VARRAY_UINT (file_table_emitted
, fileno
) = ++emitcount
;
12132 fprintf (asm_out_file
, "\t.file %u ",
12133 VARRAY_UINT (file_table_emitted
, fileno
));
12134 output_quoted_string (asm_out_file
,
12135 VARRAY_CHAR_PTR (file_table
, fileno
));
12136 fputc ('\n', asm_out_file
);
12138 return VARRAY_UINT (file_table_emitted
, fileno
);
12145 init_file_table (void)
12147 /* Allocate the initial hunk of the file_table. */
12148 VARRAY_CHAR_PTR_INIT (file_table
, 64, "file_table");
12149 VARRAY_UINT_INIT (file_table_emitted
, 64, "file_table_emitted");
12151 /* Skip the first entry - file numbers begin at 1. */
12152 VARRAY_PUSH_CHAR_PTR (file_table
, NULL
);
12153 VARRAY_PUSH_UINT (file_table_emitted
, 0);
12154 file_table_last_lookup_index
= 0;
12157 /* Output a label to mark the beginning of a source code line entry
12158 and record information relating to this source line, in
12159 'line_info_table' for later output of the .debug_line section. */
12162 dwarf2out_source_line (unsigned int line
, const char *filename
)
12164 if (debug_info_level
>= DINFO_LEVEL_NORMAL
12167 function_section (current_function_decl
);
12169 /* If requested, emit something human-readable. */
12170 if (flag_debug_asm
)
12171 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
12174 if (DWARF2_ASM_LINE_DEBUG_INFO
)
12176 unsigned file_num
= lookup_filename (filename
);
12178 file_num
= maybe_emit_file (file_num
);
12180 /* Emit the .loc directive understood by GNU as. */
12181 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
12183 /* Indicate that line number info exists. */
12184 line_info_table_in_use
++;
12186 /* Indicate that multiple line number tables exist. */
12187 if (DECL_SECTION_NAME (current_function_decl
))
12188 separate_line_info_table_in_use
++;
12190 else if (DECL_SECTION_NAME (current_function_decl
))
12192 dw_separate_line_info_ref line_info
;
12193 (*targetm
.asm_out
.internal_label
) (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
12194 separate_line_info_table_in_use
);
12196 /* expand the line info table if necessary */
12197 if (separate_line_info_table_in_use
12198 == separate_line_info_table_allocated
)
12200 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
12201 separate_line_info_table
12202 = (dw_separate_line_info_ref
)
12203 ggc_realloc (separate_line_info_table
,
12204 separate_line_info_table_allocated
12205 * sizeof (dw_separate_line_info_entry
));
12206 memset ((separate_line_info_table
12207 + separate_line_info_table_in_use
),
12209 (LINE_INFO_TABLE_INCREMENT
12210 * sizeof (dw_separate_line_info_entry
)));
12213 /* Add the new entry at the end of the line_info_table. */
12215 = &separate_line_info_table
[separate_line_info_table_in_use
++];
12216 line_info
->dw_file_num
= lookup_filename (filename
);
12217 line_info
->dw_line_num
= line
;
12218 line_info
->function
= current_function_funcdef_no
;
12222 dw_line_info_ref line_info
;
12224 (*targetm
.asm_out
.internal_label
) (asm_out_file
, LINE_CODE_LABEL
,
12225 line_info_table_in_use
);
12227 /* Expand the line info table if necessary. */
12228 if (line_info_table_in_use
== line_info_table_allocated
)
12230 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
12232 = ggc_realloc (line_info_table
,
12233 (line_info_table_allocated
12234 * sizeof (dw_line_info_entry
)));
12235 memset (line_info_table
+ line_info_table_in_use
, 0,
12236 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
12239 /* Add the new entry at the end of the line_info_table. */
12240 line_info
= &line_info_table
[line_info_table_in_use
++];
12241 line_info
->dw_file_num
= lookup_filename (filename
);
12242 line_info
->dw_line_num
= line
;
12247 /* Record the beginning of a new source file. */
12250 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
12252 if (flag_eliminate_dwarf2_dups
&& !is_main_source
)
12254 /* Record the beginning of the file for break_out_includes. */
12255 dw_die_ref bincl_die
;
12257 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
12258 add_AT_string (bincl_die
, DW_AT_name
, filename
);
12261 is_main_source
= 0;
12263 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12265 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12266 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
12267 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
12269 maybe_emit_file (lookup_filename (filename
));
12270 dw2_asm_output_data_uleb128 (lookup_filename (filename
),
12271 "Filename we just started");
12275 /* Record the end of a source file. */
12278 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
12280 if (flag_eliminate_dwarf2_dups
)
12281 /* Record the end of the file for break_out_includes. */
12282 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
12284 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12286 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12287 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
12291 /* Called from debug_define in toplev.c. The `buffer' parameter contains
12292 the tail part of the directive line, i.e. the part which is past the
12293 initial whitespace, #, whitespace, directive-name, whitespace part. */
12296 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
12297 const char *buffer ATTRIBUTE_UNUSED
)
12299 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12301 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12302 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
12303 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
12304 dw2_asm_output_nstring (buffer
, -1, "The macro");
12308 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
12309 the tail part of the directive line, i.e. the part which is past the
12310 initial whitespace, #, whitespace, directive-name, whitespace part. */
12313 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
12314 const char *buffer ATTRIBUTE_UNUSED
)
12316 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12318 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12319 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
12320 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
12321 dw2_asm_output_nstring (buffer
, -1, "The macro");
12325 /* Set up for Dwarf output at the start of compilation. */
12328 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
12330 init_file_table ();
12332 /* Allocate the initial hunk of the decl_die_table. */
12333 decl_die_table
= ggc_alloc_cleared (DECL_DIE_TABLE_INCREMENT
12334 * sizeof (dw_die_ref
));
12335 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
12336 decl_die_table_in_use
= 0;
12338 /* Allocate the initial hunk of the decl_scope_table. */
12339 VARRAY_TREE_INIT (decl_scope_table
, 256, "decl_scope_table");
12341 /* Allocate the initial hunk of the abbrev_die_table. */
12342 abbrev_die_table
= ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
12343 * sizeof (dw_die_ref
));
12344 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
12345 /* Zero-th entry is allocated, but unused */
12346 abbrev_die_table_in_use
= 1;
12348 /* Allocate the initial hunk of the line_info_table. */
12349 line_info_table
= ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
12350 * sizeof (dw_line_info_entry
));
12351 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
12353 /* Zero-th entry is allocated, but unused */
12354 line_info_table_in_use
= 1;
12356 /* Generate the initial DIE for the .debug section. Note that the (string)
12357 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12358 will (typically) be a relative pathname and that this pathname should be
12359 taken as being relative to the directory from which the compiler was
12360 invoked when the given (base) source file was compiled. We will fill
12361 in this value in dwarf2out_finish. */
12362 comp_unit_die
= gen_compile_unit_die (NULL
);
12363 is_main_source
= 1;
12365 VARRAY_TREE_INIT (incomplete_types
, 64, "incomplete_types");
12367 VARRAY_RTX_INIT (used_rtx_varray
, 32, "used_rtx_varray");
12369 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
12370 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
12371 DEBUG_ABBREV_SECTION_LABEL
, 0);
12372 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12373 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
12375 strcpy (text_section_label
, stripattributes (TEXT_SECTION_NAME
));
12377 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
12378 DEBUG_INFO_SECTION_LABEL
, 0);
12379 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
12380 DEBUG_LINE_SECTION_LABEL
, 0);
12381 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
12382 DEBUG_RANGES_SECTION_LABEL
, 0);
12383 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12384 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
12385 named_section_flags (DEBUG_INFO_SECTION
, SECTION_DEBUG
);
12386 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
12387 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12388 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
12390 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12392 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12393 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
12394 DEBUG_MACINFO_SECTION_LABEL
, 0);
12395 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
12398 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12401 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
12405 /* A helper function for dwarf2out_finish called through
12406 ht_forall. Emit one queued .debug_str string. */
12409 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
12411 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
12413 if (node
->form
== DW_FORM_strp
)
12415 named_section_flags (DEBUG_STR_SECTION
, DEBUG_STR_SECTION_FLAGS
);
12416 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
12417 assemble_string (node
->str
, strlen (node
->str
) + 1);
12425 /* Clear the marks for a die and its children.
12426 Be cool if the mark isn't set. */
12429 prune_unmark_dies (dw_die_ref die
)
12433 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
12434 prune_unmark_dies (c
);
12438 /* Given DIE that we're marking as used, find any other dies
12439 it references as attributes and mark them as used. */
12442 prune_unused_types_walk_attribs (dw_die_ref die
)
12446 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
12448 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
12450 /* A reference to another DIE.
12451 Make sure that it will get emitted. */
12452 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
12454 else if (a
->dw_attr
== DW_AT_decl_file
)
12456 /* A reference to a file. Make sure the file name is emitted. */
12457 a
->dw_attr_val
.v
.val_unsigned
=
12458 maybe_emit_file (a
->dw_attr_val
.v
.val_unsigned
);
12464 /* Mark DIE as being used. If DOKIDS is true, then walk down
12465 to DIE's children. */
12468 prune_unused_types_mark (dw_die_ref die
, int dokids
)
12472 if (die
->die_mark
== 0)
12474 /* We haven't done this node yet. Mark it as used. */
12477 /* We also have to mark its parents as used.
12478 (But we don't want to mark our parents' kids due to this.) */
12479 if (die
->die_parent
)
12480 prune_unused_types_mark (die
->die_parent
, 0);
12482 /* Mark any referenced nodes. */
12483 prune_unused_types_walk_attribs (die
);
12486 if (dokids
&& die
->die_mark
!= 2)
12488 /* We need to walk the children, but haven't done so yet.
12489 Remember that we've walked the kids. */
12493 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
12495 /* If this is an array type, we need to make sure our
12496 kids get marked, even if they're types. */
12497 if (die
->die_tag
== DW_TAG_array_type
)
12498 prune_unused_types_mark (c
, 1);
12500 prune_unused_types_walk (c
);
12506 /* Walk the tree DIE and mark types that we actually use. */
12509 prune_unused_types_walk (dw_die_ref die
)
12513 /* Don't do anything if this node is already marked. */
12517 switch (die
->die_tag
) {
12518 case DW_TAG_const_type
:
12519 case DW_TAG_packed_type
:
12520 case DW_TAG_pointer_type
:
12521 case DW_TAG_reference_type
:
12522 case DW_TAG_volatile_type
:
12523 case DW_TAG_typedef
:
12524 case DW_TAG_array_type
:
12525 case DW_TAG_structure_type
:
12526 case DW_TAG_union_type
:
12527 case DW_TAG_class_type
:
12528 case DW_TAG_friend
:
12529 case DW_TAG_variant_part
:
12530 case DW_TAG_enumeration_type
:
12531 case DW_TAG_subroutine_type
:
12532 case DW_TAG_string_type
:
12533 case DW_TAG_set_type
:
12534 case DW_TAG_subrange_type
:
12535 case DW_TAG_ptr_to_member_type
:
12536 case DW_TAG_file_type
:
12537 /* It's a type node --- don't mark it. */
12541 /* Mark everything else. */
12547 /* Now, mark any dies referenced from here. */
12548 prune_unused_types_walk_attribs (die
);
12550 /* Mark children. */
12551 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
12552 prune_unused_types_walk (c
);
12556 /* Remove from the tree DIE any dies that aren't marked. */
12559 prune_unused_types_prune (dw_die_ref die
)
12561 dw_die_ref c
, p
, n
;
12562 if (!die
->die_mark
)
12566 for (c
= die
->die_child
; c
; c
= n
)
12571 prune_unused_types_prune (c
);
12579 die
->die_child
= n
;
12586 /* Remove dies representing declarations that we never use. */
12589 prune_unused_types (void)
12592 limbo_die_node
*node
;
12594 /* Clear all the marks. */
12595 prune_unmark_dies (comp_unit_die
);
12596 for (node
= limbo_die_list
; node
; node
= node
->next
)
12597 prune_unmark_dies (node
->die
);
12599 /* Set the mark on nodes that are actually used. */
12600 prune_unused_types_walk (comp_unit_die
);
12601 for (node
= limbo_die_list
; node
; node
= node
->next
)
12602 prune_unused_types_walk (node
->die
);
12604 /* Also set the mark on nodes referenced from the
12605 pubname_table or arange_table. */
12606 for (i
= 0; i
< pubname_table_in_use
; i
++)
12607 prune_unused_types_mark (pubname_table
[i
].die
, 1);
12608 for (i
= 0; i
< arange_table_in_use
; i
++)
12609 prune_unused_types_mark (arange_table
[i
], 1);
12611 /* Get rid of nodes that aren't marked. */
12612 prune_unused_types_prune (comp_unit_die
);
12613 for (node
= limbo_die_list
; node
; node
= node
->next
)
12614 prune_unused_types_prune (node
->die
);
12616 /* Leave the marks clear. */
12617 prune_unmark_dies (comp_unit_die
);
12618 for (node
= limbo_die_list
; node
; node
= node
->next
)
12619 prune_unmark_dies (node
->die
);
12622 /* Output stuff that dwarf requires at the end of every file,
12623 and generate the DWARF-2 debugging info. */
12626 dwarf2out_finish (const char *filename
)
12628 limbo_die_node
*node
, *next_node
;
12629 dw_die_ref die
= 0;
12631 /* Add the name for the main input file now. We delayed this from
12632 dwarf2out_init to avoid complications with PCH. */
12633 add_name_attribute (comp_unit_die
, filename
);
12634 if (filename
[0] != DIR_SEPARATOR
)
12635 add_comp_dir_attribute (comp_unit_die
);
12636 else if (get_AT (comp_unit_die
, DW_AT_comp_dir
) == NULL
)
12639 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
12640 if (VARRAY_CHAR_PTR (file_table
, i
)[0] != DIR_SEPARATOR
12641 /* Don't add cwd for <built-in>. */
12642 && VARRAY_CHAR_PTR (file_table
, i
)[0] != '<')
12644 add_comp_dir_attribute (comp_unit_die
);
12649 /* Traverse the limbo die list, and add parent/child links. The only
12650 dies without parents that should be here are concrete instances of
12651 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12652 For concrete instances, we can get the parent die from the abstract
12654 for (node
= limbo_die_list
; node
; node
= next_node
)
12656 next_node
= node
->next
;
12659 if (die
->die_parent
== NULL
)
12661 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
12665 add_child_die (origin
->die_parent
, die
);
12666 else if (die
== comp_unit_die
)
12668 /* If this was an expression for a bound involved in a function
12669 return type, it may be a SAVE_EXPR for which we weren't able
12670 to find a DIE previously. So try now. */
12671 else if (node
->created_for
12672 && TREE_CODE (node
->created_for
) == SAVE_EXPR
12673 && 0 != (origin
= (lookup_decl_die
12675 (node
->created_for
)))))
12676 add_child_die (origin
, die
);
12677 else if (errorcount
> 0 || sorrycount
> 0)
12678 /* It's OK to be confused by errors in the input. */
12679 add_child_die (comp_unit_die
, die
);
12680 else if (node
->created_for
12681 && ((DECL_P (node
->created_for
)
12682 && (context
= DECL_CONTEXT (node
->created_for
)))
12683 || (TYPE_P (node
->created_for
)
12684 && (context
= TYPE_CONTEXT (node
->created_for
))))
12685 && TREE_CODE (context
) == FUNCTION_DECL
)
12687 /* In certain situations, the lexical block containing a
12688 nested function can be optimized away, which results
12689 in the nested function die being orphaned. Likewise
12690 with the return type of that nested function. Force
12691 this to be a child of the containing function. */
12692 origin
= lookup_decl_die (context
);
12695 add_child_die (origin
, die
);
12702 limbo_die_list
= NULL
;
12704 /* Walk through the list of incomplete types again, trying once more to
12705 emit full debugging info for them. */
12706 retry_incomplete_types ();
12708 /* We need to reverse all the dies before break_out_includes, or
12709 we'll see the end of an include file before the beginning. */
12710 reverse_all_dies (comp_unit_die
);
12712 if (flag_eliminate_unused_debug_types
)
12713 prune_unused_types ();
12715 /* Generate separate CUs for each of the include files we've seen.
12716 They will go into limbo_die_list. */
12717 if (flag_eliminate_dwarf2_dups
)
12718 break_out_includes (comp_unit_die
);
12720 /* Traverse the DIE's and add add sibling attributes to those DIE's
12721 that have children. */
12722 add_sibling_attributes (comp_unit_die
);
12723 for (node
= limbo_die_list
; node
; node
= node
->next
)
12724 add_sibling_attributes (node
->die
);
12726 /* Output a terminator label for the .text section. */
12728 (*targetm
.asm_out
.internal_label
) (asm_out_file
, TEXT_END_LABEL
, 0);
12730 /* Output the source line correspondence table. We must do this
12731 even if there is no line information. Otherwise, on an empty
12732 translation unit, we will generate a present, but empty,
12733 .debug_info section. IRIX 6.5 `nm' will then complain when
12734 examining the file. */
12735 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
12737 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12738 output_line_info ();
12741 /* Output location list section if necessary. */
12742 if (have_location_lists
)
12744 /* Output the location lists info. */
12745 named_section_flags (DEBUG_LOC_SECTION
, SECTION_DEBUG
);
12746 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
12747 DEBUG_LOC_SECTION_LABEL
, 0);
12748 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
12749 output_location_lists (die
);
12750 have_location_lists
= 0;
12753 /* We can only use the low/high_pc attributes if all of the code was
12755 if (separate_line_info_table_in_use
== 0)
12757 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
12758 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
12761 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12762 "base address". Use zero so that these addresses become absolute. */
12763 else if (have_location_lists
|| ranges_table_in_use
)
12764 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
12766 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
12767 add_AT_lbl_offset (comp_unit_die
, DW_AT_stmt_list
,
12768 debug_line_section_label
);
12770 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12771 add_AT_lbl_offset (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
12773 /* Output all of the compilation units. We put the main one last so that
12774 the offsets are available to output_pubnames. */
12775 for (node
= limbo_die_list
; node
; node
= node
->next
)
12776 output_comp_unit (node
->die
, 0);
12778 output_comp_unit (comp_unit_die
, 0);
12780 /* Output the abbreviation table. */
12781 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12782 output_abbrev_section ();
12784 /* Output public names table if necessary. */
12785 if (pubname_table_in_use
)
12787 named_section_flags (DEBUG_PUBNAMES_SECTION
, SECTION_DEBUG
);
12788 output_pubnames ();
12791 /* Output the address range information. We only put functions in the arange
12792 table, so don't write it out if we don't have any. */
12793 if (fde_table_in_use
)
12795 named_section_flags (DEBUG_ARANGES_SECTION
, SECTION_DEBUG
);
12799 /* Output ranges section if necessary. */
12800 if (ranges_table_in_use
)
12802 named_section_flags (DEBUG_RANGES_SECTION
, SECTION_DEBUG
);
12803 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
12807 /* Have to end the primary source file. */
12808 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12810 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12811 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
12812 dw2_asm_output_data (1, 0, "End compilation unit");
12815 /* If we emitted any DW_FORM_strp form attribute, output the string
12817 if (debug_str_hash
)
12818 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
12822 /* This should never be used, but its address is needed for comparisons. */
12823 const struct gcc_debug_hooks dwarf2_debug_hooks
;
12825 #endif /* DWARF2_DEBUGGING_INFO */
12827 #include "gt-dwarf2out.h"