1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006 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, 51 Franklin Street, Fifth Floor, 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"
46 #include "hard-reg-set.h"
48 #include "insn-config.h"
56 #include "dwarf2out.h"
57 #include "dwarf2asm.h"
63 #include "diagnostic.h"
66 #include "langhooks.h"
71 #ifdef DWARF2_DEBUGGING_INFO
72 static void dwarf2out_source_line (unsigned int, const char *);
75 /* DWARF2 Abbreviation Glossary:
76 CFA = Canonical Frame Address
77 a fixed address on the stack which identifies a call frame.
78 We define it to be the value of SP just before the call insn.
79 The CFA register and offset, which may change during the course
80 of the function, are used to calculate its value at runtime.
81 CFI = Call Frame Instruction
82 an instruction for the DWARF2 abstract machine
83 CIE = Common Information Entry
84 information describing information common to one or more FDEs
85 DIE = Debugging Information Entry
86 FDE = Frame Description Entry
87 information describing the stack call frame, in particular,
88 how to restore registers
90 DW_CFA_... = DWARF2 CFA call frame instruction
91 DW_TAG_... = DWARF2 DIE tag */
93 #ifndef DWARF2_FRAME_INFO
94 # ifdef DWARF2_DEBUGGING_INFO
95 # define DWARF2_FRAME_INFO \
96 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
98 # define DWARF2_FRAME_INFO 0
102 /* Map register numbers held in the call frame info that gcc has
103 collected using DWARF_FRAME_REGNUM to those that should be output in
104 .debug_frame and .eh_frame. */
105 #ifndef DWARF2_FRAME_REG_OUT
106 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
109 /* Decide whether we want to emit frame unwind information for the current
113 dwarf2out_do_frame (void)
115 /* We want to emit correct CFA location expressions or lists, so we
116 have to return true if we're going to output debug info, even if
117 we're not going to output frame or unwind info. */
118 return (write_symbols
== DWARF2_DEBUG
119 || write_symbols
== VMS_AND_DWARF2_DEBUG
121 #ifdef DWARF2_UNWIND_INFO
122 || (DWARF2_UNWIND_INFO
123 && (flag_unwind_tables
124 || (flag_exceptions
&& ! USING_SJLJ_EXCEPTIONS
)))
129 /* The size of the target's pointer type. */
131 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
134 /* Array of RTXes referenced by the debugging information, which therefore
135 must be kept around forever. */
136 static GTY(()) VEC(rtx
,gc
) *used_rtx_array
;
138 /* A pointer to the base of a list of incomplete types which might be
139 completed at some later time. incomplete_types_list needs to be a
140 VEC(tree,gc) because we want to tell the garbage collector about
142 static GTY(()) VEC(tree
,gc
) *incomplete_types
;
144 /* A pointer to the base of a table of references to declaration
145 scopes. This table is a display which tracks the nesting
146 of declaration scopes at the current scope and containing
147 scopes. This table is used to find the proper place to
148 define type declaration DIE's. */
149 static GTY(()) VEC(tree
,gc
) *decl_scope_table
;
151 /* Pointers to various DWARF2 sections. */
152 static GTY(()) section
*debug_info_section
;
153 static GTY(()) section
*debug_abbrev_section
;
154 static GTY(()) section
*debug_aranges_section
;
155 static GTY(()) section
*debug_macinfo_section
;
156 static GTY(()) section
*debug_line_section
;
157 static GTY(()) section
*debug_loc_section
;
158 static GTY(()) section
*debug_pubnames_section
;
159 static GTY(()) section
*debug_str_section
;
160 static GTY(()) section
*debug_ranges_section
;
161 static GTY(()) section
*debug_frame_section
;
163 /* How to start an assembler comment. */
164 #ifndef ASM_COMMENT_START
165 #define ASM_COMMENT_START ";#"
168 typedef struct dw_cfi_struct
*dw_cfi_ref
;
169 typedef struct dw_fde_struct
*dw_fde_ref
;
170 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
172 /* Call frames are described using a sequence of Call Frame
173 Information instructions. The register number, offset
174 and address fields are provided as possible operands;
175 their use is selected by the opcode field. */
177 enum dw_cfi_oprnd_type
{
179 dw_cfi_oprnd_reg_num
,
185 typedef union dw_cfi_oprnd_struct
GTY(())
187 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num
;
188 HOST_WIDE_INT
GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset
;
189 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr
;
190 struct dw_loc_descr_struct
* GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc
;
194 typedef struct dw_cfi_struct
GTY(())
196 dw_cfi_ref dw_cfi_next
;
197 enum dwarf_call_frame_info dw_cfi_opc
;
198 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
200 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
205 /* This is how we define the location of the CFA. We use to handle it
206 as REG + OFFSET all the time, but now it can be more complex.
207 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
208 Instead of passing around REG and OFFSET, we pass a copy
209 of this structure. */
210 typedef struct cfa_loc
GTY(())
212 HOST_WIDE_INT offset
;
213 HOST_WIDE_INT base_offset
;
215 int indirect
; /* 1 if CFA is accessed via a dereference. */
218 /* All call frame descriptions (FDE's) in the GCC generated DWARF
219 refer to a single Common Information Entry (CIE), defined at
220 the beginning of the .debug_frame section. This use of a single
221 CIE obviates the need to keep track of multiple CIE's
222 in the DWARF generation routines below. */
224 typedef struct dw_fde_struct
GTY(())
227 const char *dw_fde_begin
;
228 const char *dw_fde_current_label
;
229 const char *dw_fde_end
;
230 const char *dw_fde_hot_section_label
;
231 const char *dw_fde_hot_section_end_label
;
232 const char *dw_fde_unlikely_section_label
;
233 const char *dw_fde_unlikely_section_end_label
;
234 bool dw_fde_switched_sections
;
235 dw_cfi_ref dw_fde_cfi
;
236 unsigned funcdef_number
;
237 unsigned all_throwers_are_sibcalls
: 1;
238 unsigned nothrow
: 1;
239 unsigned uses_eh_lsda
: 1;
243 /* Maximum size (in bytes) of an artificially generated label. */
244 #define MAX_ARTIFICIAL_LABEL_BYTES 30
246 /* The size of addresses as they appear in the Dwarf 2 data.
247 Some architectures use word addresses to refer to code locations,
248 but Dwarf 2 info always uses byte addresses. On such machines,
249 Dwarf 2 addresses need to be larger than the architecture's
251 #ifndef DWARF2_ADDR_SIZE
252 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
255 /* The size in bytes of a DWARF field indicating an offset or length
256 relative to a debug info section, specified to be 4 bytes in the
257 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
260 #ifndef DWARF_OFFSET_SIZE
261 #define DWARF_OFFSET_SIZE 4
264 /* According to the (draft) DWARF 3 specification, the initial length
265 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
266 bytes are 0xffffffff, followed by the length stored in the next 8
269 However, the SGI/MIPS ABI uses an initial length which is equal to
270 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
272 #ifndef DWARF_INITIAL_LENGTH_SIZE
273 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
276 #define DWARF_VERSION 2
278 /* Round SIZE up to the nearest BOUNDARY. */
279 #define DWARF_ROUND(SIZE,BOUNDARY) \
280 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
282 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
283 #ifndef DWARF_CIE_DATA_ALIGNMENT
284 #ifdef STACK_GROWS_DOWNWARD
285 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
287 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
291 /* A pointer to the base of a table that contains frame description
292 information for each routine. */
293 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table
;
295 /* Number of elements currently allocated for fde_table. */
296 static GTY(()) unsigned fde_table_allocated
;
298 /* Number of elements in fde_table currently in use. */
299 static GTY(()) unsigned fde_table_in_use
;
301 /* Size (in elements) of increments by which we may expand the
303 #define FDE_TABLE_INCREMENT 256
305 /* A list of call frame insns for the CIE. */
306 static GTY(()) dw_cfi_ref cie_cfi_head
;
308 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
309 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
310 attribute that accelerates the lookup of the FDE associated
311 with the subprogram. This variable holds the table index of the FDE
312 associated with the current function (body) definition. */
313 static unsigned current_funcdef_fde
;
316 struct indirect_string_node
GTY(())
319 unsigned int refcount
;
324 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
326 static GTY(()) int dw2_string_counter
;
327 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
329 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
331 /* Forward declarations for functions defined in this file. */
333 static char *stripattributes (const char *);
334 static const char *dwarf_cfi_name (unsigned);
335 static dw_cfi_ref
new_cfi (void);
336 static void add_cfi (dw_cfi_ref
*, dw_cfi_ref
);
337 static void add_fde_cfi (const char *, dw_cfi_ref
);
338 static void lookup_cfa_1 (dw_cfi_ref
, dw_cfa_location
*);
339 static void lookup_cfa (dw_cfa_location
*);
340 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT
);
341 static void initial_return_save (rtx
);
342 static HOST_WIDE_INT
stack_adjust_offset (rtx
);
343 static void output_cfi (dw_cfi_ref
, dw_fde_ref
, int);
344 static void output_call_frame_info (int);
345 static void dwarf2out_stack_adjust (rtx
, bool);
346 static void flush_queued_reg_saves (void);
347 static bool clobbers_queued_reg_save (rtx
);
348 static void dwarf2out_frame_debug_expr (rtx
, const char *);
350 /* Support for complex CFA locations. */
351 static void output_cfa_loc (dw_cfi_ref
);
352 static void get_cfa_from_loc_descr (dw_cfa_location
*,
353 struct dw_loc_descr_struct
*);
354 static struct dw_loc_descr_struct
*build_cfa_loc
355 (dw_cfa_location
*, HOST_WIDE_INT
);
356 static void def_cfa_1 (const char *, dw_cfa_location
*);
358 /* How to start an assembler comment. */
359 #ifndef ASM_COMMENT_START
360 #define ASM_COMMENT_START ";#"
363 /* Data and reference forms for relocatable data. */
364 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
365 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
367 #ifndef DEBUG_FRAME_SECTION
368 #define DEBUG_FRAME_SECTION ".debug_frame"
371 #ifndef FUNC_BEGIN_LABEL
372 #define FUNC_BEGIN_LABEL "LFB"
375 #ifndef FUNC_END_LABEL
376 #define FUNC_END_LABEL "LFE"
379 #ifndef FRAME_BEGIN_LABEL
380 #define FRAME_BEGIN_LABEL "Lframe"
382 #define CIE_AFTER_SIZE_LABEL "LSCIE"
383 #define CIE_END_LABEL "LECIE"
384 #define FDE_LABEL "LSFDE"
385 #define FDE_AFTER_SIZE_LABEL "LASFDE"
386 #define FDE_END_LABEL "LEFDE"
387 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
388 #define LINE_NUMBER_END_LABEL "LELT"
389 #define LN_PROLOG_AS_LABEL "LASLTP"
390 #define LN_PROLOG_END_LABEL "LELTP"
391 #define DIE_LABEL_PREFIX "DW"
393 /* The DWARF 2 CFA column which tracks the return address. Normally this
394 is the column for PC, or the first column after all of the hard
396 #ifndef DWARF_FRAME_RETURN_COLUMN
398 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
400 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
404 /* The mapping from gcc register number to DWARF 2 CFA column number. By
405 default, we just provide columns for all registers. */
406 #ifndef DWARF_FRAME_REGNUM
407 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
410 /* Hook used by __throw. */
413 expand_builtin_dwarf_sp_column (void)
415 unsigned int dwarf_regnum
= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
);
416 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum
, 1));
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
= XNEWVEC (char, 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_normal (address
);
445 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
446 bool wrote_return_column
= false;
448 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
450 int rnum
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i
), 1);
452 if (rnum
< DWARF_FRAME_REGISTERS
)
454 HOST_WIDE_INT offset
= rnum
* GET_MODE_SIZE (mode
);
455 enum machine_mode save_mode
= reg_raw_mode
[i
];
458 if (HARD_REGNO_CALL_PART_CLOBBERED (i
, save_mode
))
459 save_mode
= choose_hard_reg_mode (i
, 1, true);
460 if (DWARF_FRAME_REGNUM (i
) == DWARF_FRAME_RETURN_COLUMN
)
462 if (save_mode
== VOIDmode
)
464 wrote_return_column
= true;
466 size
= GET_MODE_SIZE (save_mode
);
470 emit_move_insn (adjust_address (mem
, mode
, offset
),
471 gen_int_mode (size
, mode
));
475 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
476 gcc_assert (wrote_return_column
);
477 i
= DWARF_ALT_FRAME_RETURN_COLUMN
;
478 wrote_return_column
= false;
480 i
= DWARF_FRAME_RETURN_COLUMN
;
483 if (! wrote_return_column
)
485 enum machine_mode save_mode
= Pmode
;
486 HOST_WIDE_INT offset
= i
* GET_MODE_SIZE (mode
);
487 HOST_WIDE_INT size
= GET_MODE_SIZE (save_mode
);
488 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
492 /* Convert a DWARF call frame info. operation to its string name */
495 dwarf_cfi_name (unsigned int cfi_opc
)
499 case DW_CFA_advance_loc
:
500 return "DW_CFA_advance_loc";
502 return "DW_CFA_offset";
504 return "DW_CFA_restore";
508 return "DW_CFA_set_loc";
509 case DW_CFA_advance_loc1
:
510 return "DW_CFA_advance_loc1";
511 case DW_CFA_advance_loc2
:
512 return "DW_CFA_advance_loc2";
513 case DW_CFA_advance_loc4
:
514 return "DW_CFA_advance_loc4";
515 case DW_CFA_offset_extended
:
516 return "DW_CFA_offset_extended";
517 case DW_CFA_restore_extended
:
518 return "DW_CFA_restore_extended";
519 case DW_CFA_undefined
:
520 return "DW_CFA_undefined";
521 case DW_CFA_same_value
:
522 return "DW_CFA_same_value";
523 case DW_CFA_register
:
524 return "DW_CFA_register";
525 case DW_CFA_remember_state
:
526 return "DW_CFA_remember_state";
527 case DW_CFA_restore_state
:
528 return "DW_CFA_restore_state";
530 return "DW_CFA_def_cfa";
531 case DW_CFA_def_cfa_register
:
532 return "DW_CFA_def_cfa_register";
533 case DW_CFA_def_cfa_offset
:
534 return "DW_CFA_def_cfa_offset";
537 case DW_CFA_def_cfa_expression
:
538 return "DW_CFA_def_cfa_expression";
539 case DW_CFA_expression
:
540 return "DW_CFA_expression";
541 case DW_CFA_offset_extended_sf
:
542 return "DW_CFA_offset_extended_sf";
543 case DW_CFA_def_cfa_sf
:
544 return "DW_CFA_def_cfa_sf";
545 case DW_CFA_def_cfa_offset_sf
:
546 return "DW_CFA_def_cfa_offset_sf";
548 /* SGI/MIPS specific */
549 case DW_CFA_MIPS_advance_loc8
:
550 return "DW_CFA_MIPS_advance_loc8";
553 case DW_CFA_GNU_window_save
:
554 return "DW_CFA_GNU_window_save";
555 case DW_CFA_GNU_args_size
:
556 return "DW_CFA_GNU_args_size";
557 case DW_CFA_GNU_negative_offset_extended
:
558 return "DW_CFA_GNU_negative_offset_extended";
561 return "DW_CFA_<unknown>";
565 /* Return a pointer to a newly allocated Call Frame Instruction. */
567 static inline dw_cfi_ref
570 dw_cfi_ref cfi
= ggc_alloc (sizeof (dw_cfi_node
));
572 cfi
->dw_cfi_next
= NULL
;
573 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
574 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
579 /* Add a Call Frame Instruction to list of instructions. */
582 add_cfi (dw_cfi_ref
*list_head
, dw_cfi_ref cfi
)
586 /* Find the end of the chain. */
587 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
593 /* Generate a new label for the CFI info to refer to. */
596 dwarf2out_cfi_label (void)
598 static char label
[20];
600 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", dwarf2out_cfi_label_num
++);
601 ASM_OUTPUT_LABEL (asm_out_file
, label
);
605 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
606 or to the CIE if LABEL is NULL. */
609 add_fde_cfi (const char *label
, dw_cfi_ref cfi
)
613 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
616 label
= dwarf2out_cfi_label ();
618 if (fde
->dw_fde_current_label
== NULL
619 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
623 fde
->dw_fde_current_label
= label
= xstrdup (label
);
625 /* Set the location counter to the new label. */
627 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
628 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
629 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
632 add_cfi (&fde
->dw_fde_cfi
, cfi
);
636 add_cfi (&cie_cfi_head
, cfi
);
639 /* Subroutine of lookup_cfa. */
642 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
)
644 switch (cfi
->dw_cfi_opc
)
646 case DW_CFA_def_cfa_offset
:
647 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
649 case DW_CFA_def_cfa_offset_sf
:
651 = cfi
->dw_cfi_oprnd1
.dw_cfi_offset
* DWARF_CIE_DATA_ALIGNMENT
;
653 case DW_CFA_def_cfa_register
:
654 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
657 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
658 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
660 case DW_CFA_def_cfa_sf
:
661 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
663 = cfi
->dw_cfi_oprnd2
.dw_cfi_offset
* DWARF_CIE_DATA_ALIGNMENT
;
665 case DW_CFA_def_cfa_expression
:
666 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
673 /* Find the previous value for the CFA. */
676 lookup_cfa (dw_cfa_location
*loc
)
680 loc
->reg
= INVALID_REGNUM
;
683 loc
->base_offset
= 0;
685 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
686 lookup_cfa_1 (cfi
, loc
);
688 if (fde_table_in_use
)
690 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
691 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
692 lookup_cfa_1 (cfi
, loc
);
696 /* The current rule for calculating the DWARF2 canonical frame address. */
697 static dw_cfa_location cfa
;
699 /* The register used for saving registers to the stack, and its offset
701 static dw_cfa_location cfa_store
;
703 /* The running total of the size of arguments pushed onto the stack. */
704 static HOST_WIDE_INT args_size
;
706 /* The last args_size we actually output. */
707 static HOST_WIDE_INT old_args_size
;
709 /* Entry point to update the canonical frame address (CFA).
710 LABEL is passed to add_fde_cfi. The value of CFA is now to be
711 calculated from REG+OFFSET. */
714 dwarf2out_def_cfa (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
721 def_cfa_1 (label
, &loc
);
724 /* Determine if two dw_cfa_location structures define the same data. */
727 cfa_equal_p (const dw_cfa_location
*loc1
, const dw_cfa_location
*loc2
)
729 return (loc1
->reg
== loc2
->reg
730 && loc1
->offset
== loc2
->offset
731 && loc1
->indirect
== loc2
->indirect
732 && (loc1
->indirect
== 0
733 || loc1
->base_offset
== loc2
->base_offset
));
736 /* This routine does the actual work. The CFA is now calculated from
737 the dw_cfa_location structure. */
740 def_cfa_1 (const char *label
, dw_cfa_location
*loc_p
)
743 dw_cfa_location old_cfa
, loc
;
748 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
749 cfa_store
.offset
= loc
.offset
;
751 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
752 lookup_cfa (&old_cfa
);
754 /* If nothing changed, no need to issue any call frame instructions. */
755 if (cfa_equal_p (&loc
, &old_cfa
))
760 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
762 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
763 the CFA register did not change but the offset did. */
766 HOST_WIDE_INT f_offset
= loc
.offset
/ DWARF_CIE_DATA_ALIGNMENT
;
767 gcc_assert (f_offset
* DWARF_CIE_DATA_ALIGNMENT
== loc
.offset
);
769 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset_sf
;
770 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= f_offset
;
774 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
775 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
779 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
780 else if (loc
.offset
== old_cfa
.offset
781 && old_cfa
.reg
!= INVALID_REGNUM
784 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
785 indicating the CFA register has changed to <register> but the
786 offset has not changed. */
787 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
788 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
792 else if (loc
.indirect
== 0)
794 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
795 indicating the CFA register has changed to <register> with
796 the specified offset. */
799 HOST_WIDE_INT f_offset
= loc
.offset
/ DWARF_CIE_DATA_ALIGNMENT
;
800 gcc_assert (f_offset
* DWARF_CIE_DATA_ALIGNMENT
== loc
.offset
);
802 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_sf
;
803 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
804 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= f_offset
;
808 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
809 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
810 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
815 /* Construct a DW_CFA_def_cfa_expression instruction to
816 calculate the CFA using a full location expression since no
817 register-offset pair is available. */
818 struct dw_loc_descr_struct
*loc_list
;
820 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
821 loc_list
= build_cfa_loc (&loc
, 0);
822 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
825 add_fde_cfi (label
, cfi
);
828 /* Add the CFI for saving a register. REG is the CFA column number.
829 LABEL is passed to add_fde_cfi.
830 If SREG is -1, the register is saved at OFFSET from the CFA;
831 otherwise it is saved in SREG. */
834 reg_save (const char *label
, unsigned int reg
, unsigned int sreg
, HOST_WIDE_INT offset
)
836 dw_cfi_ref cfi
= new_cfi ();
838 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
840 if (sreg
== INVALID_REGNUM
)
843 /* The register number won't fit in 6 bits, so we have to use
845 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
847 cfi
->dw_cfi_opc
= DW_CFA_offset
;
849 #ifdef ENABLE_CHECKING
851 /* If we get an offset that is not a multiple of
852 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
853 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
855 HOST_WIDE_INT check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
857 gcc_assert (check_offset
* DWARF_CIE_DATA_ALIGNMENT
== offset
);
860 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
862 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
864 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
866 else if (sreg
== reg
)
867 cfi
->dw_cfi_opc
= DW_CFA_same_value
;
870 cfi
->dw_cfi_opc
= DW_CFA_register
;
871 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
874 add_fde_cfi (label
, cfi
);
877 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
878 This CFI tells the unwinder that it needs to restore the window registers
879 from the previous frame's window save area.
881 ??? Perhaps we should note in the CIE where windows are saved (instead of
882 assuming 0(cfa)) and what registers are in the window. */
885 dwarf2out_window_save (const char *label
)
887 dw_cfi_ref cfi
= new_cfi ();
889 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
890 add_fde_cfi (label
, cfi
);
893 /* Add a CFI to update the running total of the size of arguments
894 pushed onto the stack. */
897 dwarf2out_args_size (const char *label
, HOST_WIDE_INT size
)
901 if (size
== old_args_size
)
904 old_args_size
= size
;
907 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
908 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
909 add_fde_cfi (label
, cfi
);
912 /* Entry point for saving a register to the stack. REG is the GCC register
913 number. LABEL and OFFSET are passed to reg_save. */
916 dwarf2out_reg_save (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
918 reg_save (label
, DWARF_FRAME_REGNUM (reg
), INVALID_REGNUM
, offset
);
921 /* Entry point for saving the return address in the stack.
922 LABEL and OFFSET are passed to reg_save. */
925 dwarf2out_return_save (const char *label
, HOST_WIDE_INT offset
)
927 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, INVALID_REGNUM
, offset
);
930 /* Entry point for saving the return address in a register.
931 LABEL and SREG are passed to reg_save. */
934 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
936 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, DWARF_FRAME_REGNUM (sreg
), 0);
939 /* Record the initial position of the return address. RTL is
940 INCOMING_RETURN_ADDR_RTX. */
943 initial_return_save (rtx rtl
)
945 unsigned int reg
= INVALID_REGNUM
;
946 HOST_WIDE_INT offset
= 0;
948 switch (GET_CODE (rtl
))
951 /* RA is in a register. */
952 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
956 /* RA is on the stack. */
958 switch (GET_CODE (rtl
))
961 gcc_assert (REGNO (rtl
) == STACK_POINTER_REGNUM
);
966 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
967 offset
= INTVAL (XEXP (rtl
, 1));
971 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
972 offset
= -INTVAL (XEXP (rtl
, 1));
982 /* The return address is at some offset from any value we can
983 actually load. For instance, on the SPARC it is in %i7+8. Just
984 ignore the offset for now; it doesn't matter for unwinding frames. */
985 gcc_assert (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
);
986 initial_return_save (XEXP (rtl
, 0));
993 if (reg
!= DWARF_FRAME_RETURN_COLUMN
)
994 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
997 /* Given a SET, calculate the amount of stack adjustment it
1000 static HOST_WIDE_INT
1001 stack_adjust_offset (rtx pattern
)
1003 rtx src
= SET_SRC (pattern
);
1004 rtx dest
= SET_DEST (pattern
);
1005 HOST_WIDE_INT offset
= 0;
1008 if (dest
== stack_pointer_rtx
)
1010 /* (set (reg sp) (plus (reg sp) (const_int))) */
1011 code
= GET_CODE (src
);
1012 if (! (code
== PLUS
|| code
== MINUS
)
1013 || XEXP (src
, 0) != stack_pointer_rtx
1014 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1017 offset
= INTVAL (XEXP (src
, 1));
1021 else if (MEM_P (dest
))
1023 /* (set (mem (pre_dec (reg sp))) (foo)) */
1024 src
= XEXP (dest
, 0);
1025 code
= GET_CODE (src
);
1031 if (XEXP (src
, 0) == stack_pointer_rtx
)
1033 rtx val
= XEXP (XEXP (src
, 1), 1);
1034 /* We handle only adjustments by constant amount. */
1035 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
1036 && GET_CODE (val
) == CONST_INT
);
1037 offset
= -INTVAL (val
);
1044 if (XEXP (src
, 0) == stack_pointer_rtx
)
1046 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1053 if (XEXP (src
, 0) == stack_pointer_rtx
)
1055 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1070 /* Check INSN to see if it looks like a push or a stack adjustment, and
1071 make a note of it if it does. EH uses this information to find out how
1072 much extra space it needs to pop off the stack. */
1075 dwarf2out_stack_adjust (rtx insn
, bool after_p
)
1077 HOST_WIDE_INT offset
;
1081 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1082 with this function. Proper support would require all frame-related
1083 insns to be marked, and to be able to handle saving state around
1084 epilogues textually in the middle of the function. */
1085 if (prologue_epilogue_contains (insn
) || sibcall_epilogue_contains (insn
))
1088 /* If only calls can throw, and we have a frame pointer,
1089 save up adjustments until we see the CALL_INSN. */
1090 if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1092 if (CALL_P (insn
) && !after_p
)
1094 /* Extract the size of the args from the CALL rtx itself. */
1095 insn
= PATTERN (insn
);
1096 if (GET_CODE (insn
) == PARALLEL
)
1097 insn
= XVECEXP (insn
, 0, 0);
1098 if (GET_CODE (insn
) == SET
)
1099 insn
= SET_SRC (insn
);
1100 gcc_assert (GET_CODE (insn
) == CALL
);
1101 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1106 if (CALL_P (insn
) && !after_p
)
1108 if (!flag_asynchronous_unwind_tables
)
1109 dwarf2out_args_size ("", args_size
);
1112 else if (BARRIER_P (insn
))
1114 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1115 the compiler will have already emitted a stack adjustment, but
1116 doesn't bother for calls to noreturn functions. */
1117 #ifdef STACK_GROWS_DOWNWARD
1118 offset
= -args_size
;
1123 else if (GET_CODE (PATTERN (insn
)) == SET
)
1124 offset
= stack_adjust_offset (PATTERN (insn
));
1125 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1126 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1128 /* There may be stack adjustments inside compound insns. Search
1130 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1131 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1132 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1140 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1141 cfa
.offset
+= offset
;
1143 #ifndef STACK_GROWS_DOWNWARD
1147 args_size
+= offset
;
1151 label
= dwarf2out_cfi_label ();
1152 def_cfa_1 (label
, &cfa
);
1153 if (flag_asynchronous_unwind_tables
)
1154 dwarf2out_args_size (label
, args_size
);
1159 /* We delay emitting a register save until either (a) we reach the end
1160 of the prologue or (b) the register is clobbered. This clusters
1161 register saves so that there are fewer pc advances. */
1163 struct queued_reg_save
GTY(())
1165 struct queued_reg_save
*next
;
1167 HOST_WIDE_INT cfa_offset
;
1171 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1173 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1174 struct reg_saved_in_data
GTY(()) {
1179 /* A list of registers saved in other registers.
1180 The list intentionally has a small maximum capacity of 4; if your
1181 port needs more than that, you might consider implementing a
1182 more efficient data structure. */
1183 static GTY(()) struct reg_saved_in_data regs_saved_in_regs
[4];
1184 static GTY(()) size_t num_regs_saved_in_regs
;
1186 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1187 static const char *last_reg_save_label
;
1189 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1190 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1193 queue_reg_save (const char *label
, rtx reg
, rtx sreg
, HOST_WIDE_INT offset
)
1195 struct queued_reg_save
*q
;
1197 /* Duplicates waste space, but it's also necessary to remove them
1198 for correctness, since the queue gets output in reverse
1200 for (q
= queued_reg_saves
; q
!= NULL
; q
= q
->next
)
1201 if (REGNO (q
->reg
) == REGNO (reg
))
1206 q
= ggc_alloc (sizeof (*q
));
1207 q
->next
= queued_reg_saves
;
1208 queued_reg_saves
= q
;
1212 q
->cfa_offset
= offset
;
1213 q
->saved_reg
= sreg
;
1215 last_reg_save_label
= label
;
1218 /* Output all the entries in QUEUED_REG_SAVES. */
1221 flush_queued_reg_saves (void)
1223 struct queued_reg_save
*q
;
1225 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1228 unsigned int reg
, sreg
;
1230 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1231 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (q
->reg
))
1233 if (q
->saved_reg
&& i
== num_regs_saved_in_regs
)
1235 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1236 num_regs_saved_in_regs
++;
1238 if (i
!= num_regs_saved_in_regs
)
1240 regs_saved_in_regs
[i
].orig_reg
= q
->reg
;
1241 regs_saved_in_regs
[i
].saved_in_reg
= q
->saved_reg
;
1244 reg
= DWARF_FRAME_REGNUM (REGNO (q
->reg
));
1246 sreg
= DWARF_FRAME_REGNUM (REGNO (q
->saved_reg
));
1248 sreg
= INVALID_REGNUM
;
1249 reg_save (last_reg_save_label
, reg
, sreg
, q
->cfa_offset
);
1252 queued_reg_saves
= NULL
;
1253 last_reg_save_label
= NULL
;
1256 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1257 location for? Or, does it clobber a register which we've previously
1258 said that some other register is saved in, and for which we now
1259 have a new location for? */
1262 clobbers_queued_reg_save (rtx insn
)
1264 struct queued_reg_save
*q
;
1266 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1269 if (modified_in_p (q
->reg
, insn
))
1271 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1272 if (REGNO (q
->reg
) == REGNO (regs_saved_in_regs
[i
].orig_reg
)
1273 && modified_in_p (regs_saved_in_regs
[i
].saved_in_reg
, insn
))
1280 /* Entry point for saving the first register into the second. */
1283 dwarf2out_reg_save_reg (const char *label
, rtx reg
, rtx sreg
)
1286 unsigned int regno
, sregno
;
1288 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1289 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (reg
))
1291 if (i
== num_regs_saved_in_regs
)
1293 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1294 num_regs_saved_in_regs
++;
1296 regs_saved_in_regs
[i
].orig_reg
= reg
;
1297 regs_saved_in_regs
[i
].saved_in_reg
= sreg
;
1299 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
1300 sregno
= DWARF_FRAME_REGNUM (REGNO (sreg
));
1301 reg_save (label
, regno
, sregno
, 0);
1304 /* What register, if any, is currently saved in REG? */
1307 reg_saved_in (rtx reg
)
1309 unsigned int regn
= REGNO (reg
);
1311 struct queued_reg_save
*q
;
1313 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1314 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1317 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1318 if (regs_saved_in_regs
[i
].saved_in_reg
1319 && regn
== REGNO (regs_saved_in_regs
[i
].saved_in_reg
))
1320 return regs_saved_in_regs
[i
].orig_reg
;
1326 /* A temporary register holding an integral value used in adjusting SP
1327 or setting up the store_reg. The "offset" field holds the integer
1328 value, not an offset. */
1329 static dw_cfa_location cfa_temp
;
1331 /* Record call frame debugging information for an expression EXPR,
1332 which either sets SP or FP (adjusting how we calculate the frame
1333 address) or saves a register to the stack or another register.
1334 LABEL indicates the address of EXPR.
1336 This function encodes a state machine mapping rtxes to actions on
1337 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1338 users need not read the source code.
1340 The High-Level Picture
1342 Changes in the register we use to calculate the CFA: Currently we
1343 assume that if you copy the CFA register into another register, we
1344 should take the other one as the new CFA register; this seems to
1345 work pretty well. If it's wrong for some target, it's simple
1346 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1348 Changes in the register we use for saving registers to the stack:
1349 This is usually SP, but not always. Again, we deduce that if you
1350 copy SP into another register (and SP is not the CFA register),
1351 then the new register is the one we will be using for register
1352 saves. This also seems to work.
1354 Register saves: There's not much guesswork about this one; if
1355 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1356 register save, and the register used to calculate the destination
1357 had better be the one we think we're using for this purpose.
1358 It's also assumed that a copy from a call-saved register to another
1359 register is saving that register if RTX_FRAME_RELATED_P is set on
1360 that instruction. If the copy is from a call-saved register to
1361 the *same* register, that means that the register is now the same
1362 value as in the caller.
1364 Except: If the register being saved is the CFA register, and the
1365 offset is nonzero, we are saving the CFA, so we assume we have to
1366 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1367 the intent is to save the value of SP from the previous frame.
1369 In addition, if a register has previously been saved to a different
1372 Invariants / Summaries of Rules
1374 cfa current rule for calculating the CFA. It usually
1375 consists of a register and an offset.
1376 cfa_store register used by prologue code to save things to the stack
1377 cfa_store.offset is the offset from the value of
1378 cfa_store.reg to the actual CFA
1379 cfa_temp register holding an integral value. cfa_temp.offset
1380 stores the value, which will be used to adjust the
1381 stack pointer. cfa_temp is also used like cfa_store,
1382 to track stores to the stack via fp or a temp reg.
1384 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1385 with cfa.reg as the first operand changes the cfa.reg and its
1386 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1389 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1390 expression yielding a constant. This sets cfa_temp.reg
1391 and cfa_temp.offset.
1393 Rule 5: Create a new register cfa_store used to save items to the
1396 Rules 10-14: Save a register to the stack. Define offset as the
1397 difference of the original location and cfa_store's
1398 location (or cfa_temp's location if cfa_temp is used).
1402 "{a,b}" indicates a choice of a xor b.
1403 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1406 (set <reg1> <reg2>:cfa.reg)
1407 effects: cfa.reg = <reg1>
1408 cfa.offset unchanged
1409 cfa_temp.reg = <reg1>
1410 cfa_temp.offset = cfa.offset
1413 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1414 {<const_int>,<reg>:cfa_temp.reg}))
1415 effects: cfa.reg = sp if fp used
1416 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1417 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1418 if cfa_store.reg==sp
1421 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1422 effects: cfa.reg = fp
1423 cfa_offset += +/- <const_int>
1426 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1427 constraints: <reg1> != fp
1429 effects: cfa.reg = <reg1>
1430 cfa_temp.reg = <reg1>
1431 cfa_temp.offset = cfa.offset
1434 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1435 constraints: <reg1> != fp
1437 effects: cfa_store.reg = <reg1>
1438 cfa_store.offset = cfa.offset - cfa_temp.offset
1441 (set <reg> <const_int>)
1442 effects: cfa_temp.reg = <reg>
1443 cfa_temp.offset = <const_int>
1446 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1447 effects: cfa_temp.reg = <reg1>
1448 cfa_temp.offset |= <const_int>
1451 (set <reg> (high <exp>))
1455 (set <reg> (lo_sum <exp> <const_int>))
1456 effects: cfa_temp.reg = <reg>
1457 cfa_temp.offset = <const_int>
1460 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1461 effects: cfa_store.offset -= <const_int>
1462 cfa.offset = cfa_store.offset if cfa.reg == sp
1464 cfa.base_offset = -cfa_store.offset
1467 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1468 effects: cfa_store.offset += -/+ mode_size(mem)
1469 cfa.offset = cfa_store.offset if cfa.reg == sp
1471 cfa.base_offset = -cfa_store.offset
1474 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1477 effects: cfa.reg = <reg1>
1478 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1481 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1482 effects: cfa.reg = <reg1>
1483 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1486 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1487 effects: cfa.reg = <reg1>
1488 cfa.base_offset = -cfa_temp.offset
1489 cfa_temp.offset -= mode_size(mem)
1492 Â (set <reg> {unspec, unspec_volatile})
1493 Â effects: target-dependent */
1496 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
1499 HOST_WIDE_INT offset
;
1501 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1502 the PARALLEL independently. The first element is always processed if
1503 it is a SET. This is for backward compatibility. Other elements
1504 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1505 flag is set in them. */
1506 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1509 int limit
= XVECLEN (expr
, 0);
1511 for (par_index
= 0; par_index
< limit
; par_index
++)
1512 if (GET_CODE (XVECEXP (expr
, 0, par_index
)) == SET
1513 && (RTX_FRAME_RELATED_P (XVECEXP (expr
, 0, par_index
))
1515 dwarf2out_frame_debug_expr (XVECEXP (expr
, 0, par_index
), label
);
1520 gcc_assert (GET_CODE (expr
) == SET
);
1522 src
= SET_SRC (expr
);
1523 dest
= SET_DEST (expr
);
1527 rtx rsi
= reg_saved_in (src
);
1532 switch (GET_CODE (dest
))
1535 switch (GET_CODE (src
))
1537 /* Setting FP from SP. */
1539 if (cfa
.reg
== (unsigned) REGNO (src
))
1542 /* Update the CFA rule wrt SP or FP. Make sure src is
1543 relative to the current CFA register.
1545 We used to require that dest be either SP or FP, but the
1546 ARM copies SP to a temporary register, and from there to
1547 FP. So we just rely on the backends to only set
1548 RTX_FRAME_RELATED_P on appropriate insns. */
1549 cfa
.reg
= REGNO (dest
);
1550 cfa_temp
.reg
= cfa
.reg
;
1551 cfa_temp
.offset
= cfa
.offset
;
1555 /* Saving a register in a register. */
1556 gcc_assert (!fixed_regs
[REGNO (dest
)]
1557 /* For the SPARC and its register window. */
1558 || (DWARF_FRAME_REGNUM (REGNO (src
))
1559 == DWARF_FRAME_RETURN_COLUMN
));
1560 queue_reg_save (label
, src
, dest
, 0);
1567 if (dest
== stack_pointer_rtx
)
1571 switch (GET_CODE (XEXP (src
, 1)))
1574 offset
= INTVAL (XEXP (src
, 1));
1577 gcc_assert ((unsigned) REGNO (XEXP (src
, 1))
1579 offset
= cfa_temp
.offset
;
1585 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1587 /* Restoring SP from FP in the epilogue. */
1588 gcc_assert (cfa
.reg
== (unsigned) HARD_FRAME_POINTER_REGNUM
);
1589 cfa
.reg
= STACK_POINTER_REGNUM
;
1591 else if (GET_CODE (src
) == LO_SUM
)
1592 /* Assume we've set the source reg of the LO_SUM from sp. */
1595 gcc_assert (XEXP (src
, 0) == stack_pointer_rtx
);
1597 if (GET_CODE (src
) != MINUS
)
1599 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1600 cfa
.offset
+= offset
;
1601 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1602 cfa_store
.offset
+= offset
;
1604 else if (dest
== hard_frame_pointer_rtx
)
1607 /* Either setting the FP from an offset of the SP,
1608 or adjusting the FP */
1609 gcc_assert (frame_pointer_needed
);
1611 gcc_assert (REG_P (XEXP (src
, 0))
1612 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1613 && GET_CODE (XEXP (src
, 1)) == CONST_INT
);
1614 offset
= INTVAL (XEXP (src
, 1));
1615 if (GET_CODE (src
) != MINUS
)
1617 cfa
.offset
+= offset
;
1618 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1622 gcc_assert (GET_CODE (src
) != MINUS
);
1625 if (REG_P (XEXP (src
, 0))
1626 && REGNO (XEXP (src
, 0)) == cfa
.reg
1627 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1629 /* Setting a temporary CFA register that will be copied
1630 into the FP later on. */
1631 offset
= - INTVAL (XEXP (src
, 1));
1632 cfa
.offset
+= offset
;
1633 cfa
.reg
= REGNO (dest
);
1634 /* Or used to save regs to the stack. */
1635 cfa_temp
.reg
= cfa
.reg
;
1636 cfa_temp
.offset
= cfa
.offset
;
1640 else if (REG_P (XEXP (src
, 0))
1641 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1642 && XEXP (src
, 1) == stack_pointer_rtx
)
1644 /* Setting a scratch register that we will use instead
1645 of SP for saving registers to the stack. */
1646 gcc_assert (cfa
.reg
== STACK_POINTER_REGNUM
);
1647 cfa_store
.reg
= REGNO (dest
);
1648 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
1652 else if (GET_CODE (src
) == LO_SUM
1653 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1655 cfa_temp
.reg
= REGNO (dest
);
1656 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
1665 cfa_temp
.reg
= REGNO (dest
);
1666 cfa_temp
.offset
= INTVAL (src
);
1671 gcc_assert (REG_P (XEXP (src
, 0))
1672 && (unsigned) REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1673 && GET_CODE (XEXP (src
, 1)) == CONST_INT
);
1675 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
1676 cfa_temp
.reg
= REGNO (dest
);
1677 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
1680 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1681 which will fill in all of the bits. */
1688 case UNSPEC_VOLATILE
:
1689 gcc_assert (targetm
.dwarf_handle_frame_unspec
);
1690 targetm
.dwarf_handle_frame_unspec (label
, expr
, XINT (src
, 1));
1697 def_cfa_1 (label
, &cfa
);
1701 gcc_assert (REG_P (src
));
1703 /* Saving a register to the stack. Make sure dest is relative to the
1705 switch (GET_CODE (XEXP (dest
, 0)))
1710 /* We can't handle variable size modifications. */
1711 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1))
1713 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1715 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
1716 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
1718 cfa_store
.offset
+= offset
;
1719 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1720 cfa
.offset
= cfa_store
.offset
;
1722 offset
= -cfa_store
.offset
;
1728 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1729 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1732 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
1733 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
1735 cfa_store
.offset
+= offset
;
1736 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1737 cfa
.offset
= cfa_store
.offset
;
1739 offset
= -cfa_store
.offset
;
1743 /* With an offset. */
1750 gcc_assert (GET_CODE (XEXP (XEXP (dest
, 0), 1)) == CONST_INT
1751 && REG_P (XEXP (XEXP (dest
, 0), 0)));
1752 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1753 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1756 regno
= REGNO (XEXP (XEXP (dest
, 0), 0));
1758 if (cfa_store
.reg
== (unsigned) regno
)
1759 offset
-= cfa_store
.offset
;
1762 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
1763 offset
-= cfa_temp
.offset
;
1769 /* Without an offset. */
1772 int regno
= REGNO (XEXP (dest
, 0));
1774 if (cfa_store
.reg
== (unsigned) regno
)
1775 offset
= -cfa_store
.offset
;
1778 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
1779 offset
= -cfa_temp
.offset
;
1786 gcc_assert (cfa_temp
.reg
1787 == (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)));
1788 offset
= -cfa_temp
.offset
;
1789 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1796 if (REGNO (src
) != STACK_POINTER_REGNUM
1797 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1798 && (unsigned) REGNO (src
) == cfa
.reg
)
1800 /* We're storing the current CFA reg into the stack. */
1802 if (cfa
.offset
== 0)
1804 /* If the source register is exactly the CFA, assume
1805 we're saving SP like any other register; this happens
1807 def_cfa_1 (label
, &cfa
);
1808 queue_reg_save (label
, stack_pointer_rtx
, NULL_RTX
, offset
);
1813 /* Otherwise, we'll need to look in the stack to
1814 calculate the CFA. */
1815 rtx x
= XEXP (dest
, 0);
1819 gcc_assert (REG_P (x
));
1821 cfa
.reg
= REGNO (x
);
1822 cfa
.base_offset
= offset
;
1824 def_cfa_1 (label
, &cfa
);
1829 def_cfa_1 (label
, &cfa
);
1830 queue_reg_save (label
, src
, NULL_RTX
, offset
);
1838 /* Record call frame debugging information for INSN, which either
1839 sets SP or FP (adjusting how we calculate the frame address) or saves a
1840 register to the stack. If INSN is NULL_RTX, initialize our state.
1842 If AFTER_P is false, we're being called before the insn is emitted,
1843 otherwise after. Call instructions get invoked twice. */
1846 dwarf2out_frame_debug (rtx insn
, bool after_p
)
1851 if (insn
== NULL_RTX
)
1855 /* Flush any queued register saves. */
1856 flush_queued_reg_saves ();
1858 /* Set up state for generating call frame debug info. */
1861 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
));
1863 cfa
.reg
= STACK_POINTER_REGNUM
;
1866 cfa_temp
.offset
= 0;
1868 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1870 regs_saved_in_regs
[i
].orig_reg
= NULL_RTX
;
1871 regs_saved_in_regs
[i
].saved_in_reg
= NULL_RTX
;
1873 num_regs_saved_in_regs
= 0;
1877 if (!NONJUMP_INSN_P (insn
) || clobbers_queued_reg_save (insn
))
1878 flush_queued_reg_saves ();
1880 if (! RTX_FRAME_RELATED_P (insn
))
1882 if (!ACCUMULATE_OUTGOING_ARGS
)
1883 dwarf2out_stack_adjust (insn
, after_p
);
1887 label
= dwarf2out_cfi_label ();
1888 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1890 insn
= XEXP (src
, 0);
1892 insn
= PATTERN (insn
);
1894 dwarf2out_frame_debug_expr (insn
, label
);
1899 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1900 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1901 (enum dwarf_call_frame_info cfi
);
1903 static enum dw_cfi_oprnd_type
1904 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
1909 case DW_CFA_GNU_window_save
:
1910 return dw_cfi_oprnd_unused
;
1912 case DW_CFA_set_loc
:
1913 case DW_CFA_advance_loc1
:
1914 case DW_CFA_advance_loc2
:
1915 case DW_CFA_advance_loc4
:
1916 case DW_CFA_MIPS_advance_loc8
:
1917 return dw_cfi_oprnd_addr
;
1920 case DW_CFA_offset_extended
:
1921 case DW_CFA_def_cfa
:
1922 case DW_CFA_offset_extended_sf
:
1923 case DW_CFA_def_cfa_sf
:
1924 case DW_CFA_restore_extended
:
1925 case DW_CFA_undefined
:
1926 case DW_CFA_same_value
:
1927 case DW_CFA_def_cfa_register
:
1928 case DW_CFA_register
:
1929 return dw_cfi_oprnd_reg_num
;
1931 case DW_CFA_def_cfa_offset
:
1932 case DW_CFA_GNU_args_size
:
1933 case DW_CFA_def_cfa_offset_sf
:
1934 return dw_cfi_oprnd_offset
;
1936 case DW_CFA_def_cfa_expression
:
1937 case DW_CFA_expression
:
1938 return dw_cfi_oprnd_loc
;
1945 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1946 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1947 (enum dwarf_call_frame_info cfi
);
1949 static enum dw_cfi_oprnd_type
1950 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
1954 case DW_CFA_def_cfa
:
1955 case DW_CFA_def_cfa_sf
:
1957 case DW_CFA_offset_extended_sf
:
1958 case DW_CFA_offset_extended
:
1959 return dw_cfi_oprnd_offset
;
1961 case DW_CFA_register
:
1962 return dw_cfi_oprnd_reg_num
;
1965 return dw_cfi_oprnd_unused
;
1969 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1971 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
1972 switch to the data section instead, and write out a synthetic label
1976 switch_to_eh_frame_section (void)
1980 #ifdef EH_FRAME_SECTION_NAME
1981 if (eh_frame_section
== 0)
1985 if (EH_TABLES_CAN_BE_READ_ONLY
)
1991 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
1993 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
1995 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
1997 flags
= ((! flag_pic
1998 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
1999 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
2000 && (per_encoding
& 0x70) != DW_EH_PE_absptr
2001 && (per_encoding
& 0x70) != DW_EH_PE_aligned
2002 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
2003 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
2004 ? 0 : SECTION_WRITE
);
2007 flags
= SECTION_WRITE
;
2008 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
2012 if (eh_frame_section
)
2013 switch_to_section (eh_frame_section
);
2016 /* We have no special eh_frame section. Put the information in
2017 the data section and emit special labels to guide collect2. */
2018 switch_to_section (data_section
);
2019 label
= get_file_function_name ('F');
2020 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2021 targetm
.asm_out
.globalize_label (asm_out_file
,
2022 IDENTIFIER_POINTER (label
));
2023 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
2027 /* Output a Call Frame Information opcode and its operand(s). */
2030 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
2033 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
2034 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
2035 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
2036 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
2037 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
2038 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
2040 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2041 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2042 "DW_CFA_offset, column 0x%lx", r
);
2043 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2045 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
2047 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2048 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2049 "DW_CFA_restore, column 0x%lx", r
);
2053 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
2054 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
2056 switch (cfi
->dw_cfi_opc
)
2058 case DW_CFA_set_loc
:
2060 dw2_asm_output_encoded_addr_rtx (
2061 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2062 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
2065 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2066 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
2069 case DW_CFA_advance_loc1
:
2070 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2071 fde
->dw_fde_current_label
, NULL
);
2072 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2075 case DW_CFA_advance_loc2
:
2076 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2077 fde
->dw_fde_current_label
, NULL
);
2078 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2081 case DW_CFA_advance_loc4
:
2082 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2083 fde
->dw_fde_current_label
, NULL
);
2084 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2087 case DW_CFA_MIPS_advance_loc8
:
2088 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2089 fde
->dw_fde_current_label
, NULL
);
2090 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2093 case DW_CFA_offset_extended
:
2094 case DW_CFA_def_cfa
:
2095 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2096 dw2_asm_output_data_uleb128 (r
, NULL
);
2097 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2100 case DW_CFA_offset_extended_sf
:
2101 case DW_CFA_def_cfa_sf
:
2102 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2103 dw2_asm_output_data_uleb128 (r
, NULL
);
2104 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2107 case DW_CFA_restore_extended
:
2108 case DW_CFA_undefined
:
2109 case DW_CFA_same_value
:
2110 case DW_CFA_def_cfa_register
:
2111 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2112 dw2_asm_output_data_uleb128 (r
, NULL
);
2115 case DW_CFA_register
:
2116 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2117 dw2_asm_output_data_uleb128 (r
, NULL
);
2118 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
2119 dw2_asm_output_data_uleb128 (r
, NULL
);
2122 case DW_CFA_def_cfa_offset
:
2123 case DW_CFA_GNU_args_size
:
2124 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2127 case DW_CFA_def_cfa_offset_sf
:
2128 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2131 case DW_CFA_GNU_window_save
:
2134 case DW_CFA_def_cfa_expression
:
2135 case DW_CFA_expression
:
2136 output_cfa_loc (cfi
);
2139 case DW_CFA_GNU_negative_offset_extended
:
2140 /* Obsoleted by DW_CFA_offset_extended_sf. */
2149 /* Output the call frame information used to record information
2150 that relates to calculating the frame pointer, and records the
2151 location of saved registers. */
2154 output_call_frame_info (int for_eh
)
2159 char l1
[20], l2
[20], section_start_label
[20];
2160 bool any_lsda_needed
= false;
2161 char augmentation
[6];
2162 int augmentation_size
;
2163 int fde_encoding
= DW_EH_PE_absptr
;
2164 int per_encoding
= DW_EH_PE_absptr
;
2165 int lsda_encoding
= DW_EH_PE_absptr
;
2168 /* Don't emit a CIE if there won't be any FDEs. */
2169 if (fde_table_in_use
== 0)
2172 /* If we make FDEs linkonce, we may have to emit an empty label for
2173 an FDE that wouldn't otherwise be emitted. We want to avoid
2174 having an FDE kept around when the function it refers to is
2175 discarded. Example where this matters: a primary function
2176 template in C++ requires EH information, but an explicit
2177 specialization doesn't. */
2178 if (TARGET_USES_WEAK_UNWIND_INFO
2179 && ! flag_asynchronous_unwind_tables
2181 for (i
= 0; i
< fde_table_in_use
; i
++)
2182 if ((fde_table
[i
].nothrow
|| fde_table
[i
].all_throwers_are_sibcalls
)
2183 && !fde_table
[i
].uses_eh_lsda
2184 && ! DECL_WEAK (fde_table
[i
].decl
))
2185 targetm
.asm_out
.unwind_label (asm_out_file
, fde_table
[i
].decl
,
2186 for_eh
, /* empty */ 1);
2188 /* If we don't have any functions we'll want to unwind out of, don't
2189 emit any EH unwind information. Note that if exceptions aren't
2190 enabled, we won't have collected nothrow information, and if we
2191 asked for asynchronous tables, we always want this info. */
2194 bool any_eh_needed
= !flag_exceptions
|| flag_asynchronous_unwind_tables
;
2196 for (i
= 0; i
< fde_table_in_use
; i
++)
2197 if (fde_table
[i
].uses_eh_lsda
)
2198 any_eh_needed
= any_lsda_needed
= true;
2199 else if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
2200 any_eh_needed
= true;
2201 else if (! fde_table
[i
].nothrow
2202 && ! fde_table
[i
].all_throwers_are_sibcalls
)
2203 any_eh_needed
= true;
2205 if (! any_eh_needed
)
2209 /* We're going to be generating comments, so turn on app. */
2214 switch_to_eh_frame_section ();
2216 switch_to_section (debug_frame_section
);
2218 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
2219 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
2221 /* Output the CIE. */
2222 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
2223 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
2224 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2225 "Length of Common Information Entry");
2226 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2228 /* Now that the CIE pointer is PC-relative for EH,
2229 use 0 to identify the CIE. */
2230 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
2231 (for_eh
? 0 : DW_CIE_ID
),
2232 "CIE Identifier Tag");
2234 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
2236 augmentation
[0] = 0;
2237 augmentation_size
= 0;
2243 z Indicates that a uleb128 is present to size the
2244 augmentation section.
2245 L Indicates the encoding (and thus presence) of
2246 an LSDA pointer in the FDE augmentation.
2247 R Indicates a non-default pointer encoding for
2249 P Indicates the presence of an encoding + language
2250 personality routine in the CIE augmentation. */
2252 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2253 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2254 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2256 p
= augmentation
+ 1;
2257 if (eh_personality_libfunc
)
2260 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
2262 if (any_lsda_needed
)
2265 augmentation_size
+= 1;
2267 if (fde_encoding
!= DW_EH_PE_absptr
)
2270 augmentation_size
+= 1;
2272 if (p
> augmentation
+ 1)
2274 augmentation
[0] = 'z';
2278 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2279 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
2281 int offset
= ( 4 /* Length */
2283 + 1 /* CIE version */
2284 + strlen (augmentation
) + 1 /* Augmentation */
2285 + size_of_uleb128 (1) /* Code alignment */
2286 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
2288 + 1 /* Augmentation size */
2289 + 1 /* Personality encoding */ );
2290 int pad
= -offset
& (PTR_SIZE
- 1);
2292 augmentation_size
+= pad
;
2294 /* Augmentations should be small, so there's scarce need to
2295 iterate for a solution. Die if we exceed one uleb128 byte. */
2296 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
2300 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
2301 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2302 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
2303 "CIE Data Alignment Factor");
2305 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
2306 if (DW_CIE_VERSION
== 1)
2307 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
2309 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
2311 if (augmentation
[0])
2313 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
2314 if (eh_personality_libfunc
)
2316 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
2317 eh_data_format_name (per_encoding
));
2318 dw2_asm_output_encoded_addr_rtx (per_encoding
,
2319 eh_personality_libfunc
,
2323 if (any_lsda_needed
)
2324 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
2325 eh_data_format_name (lsda_encoding
));
2327 if (fde_encoding
!= DW_EH_PE_absptr
)
2328 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
2329 eh_data_format_name (fde_encoding
));
2332 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2333 output_cfi (cfi
, NULL
, for_eh
);
2335 /* Pad the CIE out to an address sized boundary. */
2336 ASM_OUTPUT_ALIGN (asm_out_file
,
2337 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
2338 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2340 /* Loop through all of the FDE's. */
2341 for (i
= 0; i
< fde_table_in_use
; i
++)
2343 fde
= &fde_table
[i
];
2345 /* Don't emit EH unwind info for leaf functions that don't need it. */
2346 if (for_eh
&& !flag_asynchronous_unwind_tables
&& flag_exceptions
2347 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
2348 && ! (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
2349 && !fde
->uses_eh_lsda
)
2352 targetm
.asm_out
.unwind_label (asm_out_file
, fde
->decl
, for_eh
, /* empty */ 0);
2353 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
2354 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
2355 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
2356 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2358 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2361 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
2363 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
2364 debug_frame_section
, "FDE CIE offset");
2368 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
);
2369 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
2370 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
2373 "FDE initial location");
2374 if (fde
->dw_fde_switched_sections
)
2376 rtx sym_ref2
= gen_rtx_SYMBOL_REF (Pmode
,
2377 fde
->dw_fde_unlikely_section_label
);
2378 rtx sym_ref3
= gen_rtx_SYMBOL_REF (Pmode
,
2379 fde
->dw_fde_hot_section_label
);
2380 SYMBOL_REF_FLAGS (sym_ref2
) |= SYMBOL_FLAG_LOCAL
;
2381 SYMBOL_REF_FLAGS (sym_ref3
) |= SYMBOL_FLAG_LOCAL
;
2382 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref3
, false,
2383 "FDE initial location");
2384 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2385 fde
->dw_fde_hot_section_end_label
,
2386 fde
->dw_fde_hot_section_label
,
2387 "FDE address range");
2388 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref2
, false,
2389 "FDE initial location");
2390 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2391 fde
->dw_fde_unlikely_section_end_label
,
2392 fde
->dw_fde_unlikely_section_label
,
2393 "FDE address range");
2396 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2397 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2398 "FDE address range");
2402 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
2403 "FDE initial location");
2404 if (fde
->dw_fde_switched_sections
)
2406 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2407 fde
->dw_fde_hot_section_label
,
2408 "FDE initial location");
2409 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2410 fde
->dw_fde_hot_section_end_label
,
2411 fde
->dw_fde_hot_section_label
,
2412 "FDE address range");
2413 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2414 fde
->dw_fde_unlikely_section_label
,
2415 "FDE initial location");
2416 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2417 fde
->dw_fde_unlikely_section_end_label
,
2418 fde
->dw_fde_unlikely_section_label
,
2419 "FDE address range");
2422 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2423 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2424 "FDE address range");
2427 if (augmentation
[0])
2429 if (any_lsda_needed
)
2431 int size
= size_of_encoded_value (lsda_encoding
);
2433 if (lsda_encoding
== DW_EH_PE_aligned
)
2435 int offset
= ( 4 /* Length */
2436 + 4 /* CIE offset */
2437 + 2 * size_of_encoded_value (fde_encoding
)
2438 + 1 /* Augmentation size */ );
2439 int pad
= -offset
& (PTR_SIZE
- 1);
2442 gcc_assert (size_of_uleb128 (size
) == 1);
2445 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2447 if (fde
->uses_eh_lsda
)
2449 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2450 fde
->funcdef_number
);
2451 dw2_asm_output_encoded_addr_rtx (
2452 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2453 false, "Language Specific Data Area");
2457 if (lsda_encoding
== DW_EH_PE_aligned
)
2458 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2460 (size_of_encoded_value (lsda_encoding
), 0,
2461 "Language Specific Data Area (none)");
2465 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2468 /* Loop through the Call Frame Instructions associated with
2470 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2471 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2472 output_cfi (cfi
, fde
, for_eh
);
2474 /* Pad the FDE out to an address sized boundary. */
2475 ASM_OUTPUT_ALIGN (asm_out_file
,
2476 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2477 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2480 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
2481 dw2_asm_output_data (4, 0, "End of Table");
2482 #ifdef MIPS_DEBUGGING_INFO
2483 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2484 get a value of 0. Putting .align 0 after the label fixes it. */
2485 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2488 /* Turn off app to make assembly quicker. */
2493 /* Output a marker (i.e. a label) for the beginning of a function, before
2497 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
2498 const char *file ATTRIBUTE_UNUSED
)
2500 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2504 current_function_func_begin_label
= NULL
;
2506 #ifdef TARGET_UNWIND_INFO
2507 /* ??? current_function_func_begin_label is also used by except.c
2508 for call-site information. We must emit this label if it might
2510 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2511 && ! dwarf2out_do_frame ())
2514 if (! dwarf2out_do_frame ())
2518 switch_to_section (function_section (current_function_decl
));
2519 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2520 current_function_funcdef_no
);
2521 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2522 current_function_funcdef_no
);
2523 dup_label
= xstrdup (label
);
2524 current_function_func_begin_label
= dup_label
;
2526 #ifdef TARGET_UNWIND_INFO
2527 /* We can elide the fde allocation if we're not emitting debug info. */
2528 if (! dwarf2out_do_frame ())
2532 /* Expand the fde table if necessary. */
2533 if (fde_table_in_use
== fde_table_allocated
)
2535 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2536 fde_table
= ggc_realloc (fde_table
,
2537 fde_table_allocated
* sizeof (dw_fde_node
));
2538 memset (fde_table
+ fde_table_in_use
, 0,
2539 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2542 /* Record the FDE associated with this function. */
2543 current_funcdef_fde
= fde_table_in_use
;
2545 /* Add the new FDE at the end of the fde_table. */
2546 fde
= &fde_table
[fde_table_in_use
++];
2547 fde
->decl
= current_function_decl
;
2548 fde
->dw_fde_begin
= dup_label
;
2549 fde
->dw_fde_current_label
= NULL
;
2550 fde
->dw_fde_hot_section_label
= NULL
;
2551 fde
->dw_fde_hot_section_end_label
= NULL
;
2552 fde
->dw_fde_unlikely_section_label
= NULL
;
2553 fde
->dw_fde_unlikely_section_end_label
= NULL
;
2554 fde
->dw_fde_switched_sections
= false;
2555 fde
->dw_fde_end
= NULL
;
2556 fde
->dw_fde_cfi
= NULL
;
2557 fde
->funcdef_number
= current_function_funcdef_no
;
2558 fde
->nothrow
= TREE_NOTHROW (current_function_decl
);
2559 fde
->uses_eh_lsda
= cfun
->uses_eh_lsda
;
2560 fde
->all_throwers_are_sibcalls
= cfun
->all_throwers_are_sibcalls
;
2562 args_size
= old_args_size
= 0;
2564 /* We only want to output line number information for the genuine dwarf2
2565 prologue case, not the eh frame case. */
2566 #ifdef DWARF2_DEBUGGING_INFO
2568 dwarf2out_source_line (line
, file
);
2572 /* Output a marker (i.e. a label) for the absolute end of the generated code
2573 for a function definition. This gets called *after* the epilogue code has
2577 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
2578 const char *file ATTRIBUTE_UNUSED
)
2581 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2583 /* Output a label to mark the endpoint of the code generated for this
2585 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
2586 current_function_funcdef_no
);
2587 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2588 fde
= &fde_table
[fde_table_in_use
- 1];
2589 fde
->dw_fde_end
= xstrdup (label
);
2593 dwarf2out_frame_init (void)
2595 /* Allocate the initial hunk of the fde_table. */
2596 fde_table
= ggc_alloc_cleared (FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2597 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2598 fde_table_in_use
= 0;
2600 /* Generate the CFA instructions common to all FDE's. Do it now for the
2601 sake of lookup_cfa. */
2603 /* On entry, the Canonical Frame Address is at SP. */
2604 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2606 #ifdef DWARF2_UNWIND_INFO
2607 if (DWARF2_UNWIND_INFO
)
2608 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2613 dwarf2out_frame_finish (void)
2615 /* Output call frame information. */
2616 if (DWARF2_FRAME_INFO
)
2617 output_call_frame_info (0);
2619 #ifndef TARGET_UNWIND_INFO
2620 /* Output another copy for the unwinder. */
2621 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2622 output_call_frame_info (1);
2627 /* And now, the subset of the debugging information support code necessary
2628 for emitting location expressions. */
2630 /* We need some way to distinguish DW_OP_addr with a direct symbol
2631 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2632 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2635 typedef struct dw_val_struct
*dw_val_ref
;
2636 typedef struct die_struct
*dw_die_ref
;
2637 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2638 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2640 /* Each DIE may have a series of attribute/value pairs. Values
2641 can take on several forms. The forms that are used in this
2642 implementation are listed below. */
2647 dw_val_class_offset
,
2649 dw_val_class_loc_list
,
2650 dw_val_class_range_list
,
2652 dw_val_class_unsigned_const
,
2653 dw_val_class_long_long
,
2656 dw_val_class_die_ref
,
2657 dw_val_class_fde_ref
,
2658 dw_val_class_lbl_id
,
2659 dw_val_class_lineptr
,
2664 /* Describe a double word constant value. */
2665 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2667 typedef struct dw_long_long_struct
GTY(())
2674 /* Describe a floating point constant value, or a vector constant value. */
2676 typedef struct dw_vec_struct
GTY(())
2678 unsigned char * GTY((length ("%h.length"))) array
;
2684 /* The dw_val_node describes an attribute's value, as it is
2685 represented internally. */
2687 typedef struct dw_val_struct
GTY(())
2689 enum dw_val_class val_class
;
2690 union dw_val_struct_union
2692 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
2693 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_offset"))) val_offset
;
2694 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
2695 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
2696 HOST_WIDE_INT
GTY ((default)) val_int
;
2697 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
2698 dw_long_long_const
GTY ((tag ("dw_val_class_long_long"))) val_long_long
;
2699 dw_vec_const
GTY ((tag ("dw_val_class_vec"))) val_vec
;
2700 struct dw_val_die_union
2704 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
2705 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
2706 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
2707 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
2708 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
2710 GTY ((desc ("%1.val_class"))) v
;
2714 /* Locations in memory are described using a sequence of stack machine
2717 typedef struct dw_loc_descr_struct
GTY(())
2719 dw_loc_descr_ref dw_loc_next
;
2720 enum dwarf_location_atom dw_loc_opc
;
2721 dw_val_node dw_loc_oprnd1
;
2722 dw_val_node dw_loc_oprnd2
;
2727 /* Location lists are ranges + location descriptions for that range,
2728 so you can track variables that are in different places over
2729 their entire life. */
2730 typedef struct dw_loc_list_struct
GTY(())
2732 dw_loc_list_ref dw_loc_next
;
2733 const char *begin
; /* Label for begin address of range */
2734 const char *end
; /* Label for end address of range */
2735 char *ll_symbol
; /* Label for beginning of location list.
2736 Only on head of list */
2737 const char *section
; /* Section this loclist is relative to */
2738 dw_loc_descr_ref expr
;
2741 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2743 static const char *dwarf_stack_op_name (unsigned);
2744 static dw_loc_descr_ref
new_loc_descr (enum dwarf_location_atom
,
2745 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2746 static void add_loc_descr (dw_loc_descr_ref
*, dw_loc_descr_ref
);
2747 static unsigned long size_of_loc_descr (dw_loc_descr_ref
);
2748 static unsigned long size_of_locs (dw_loc_descr_ref
);
2749 static void output_loc_operands (dw_loc_descr_ref
);
2750 static void output_loc_sequence (dw_loc_descr_ref
);
2752 /* Convert a DWARF stack opcode into its string name. */
2755 dwarf_stack_op_name (unsigned int op
)
2760 case INTERNAL_DW_OP_tls_addr
:
2761 return "DW_OP_addr";
2763 return "DW_OP_deref";
2765 return "DW_OP_const1u";
2767 return "DW_OP_const1s";
2769 return "DW_OP_const2u";
2771 return "DW_OP_const2s";
2773 return "DW_OP_const4u";
2775 return "DW_OP_const4s";
2777 return "DW_OP_const8u";
2779 return "DW_OP_const8s";
2781 return "DW_OP_constu";
2783 return "DW_OP_consts";
2787 return "DW_OP_drop";
2789 return "DW_OP_over";
2791 return "DW_OP_pick";
2793 return "DW_OP_swap";
2797 return "DW_OP_xderef";
2805 return "DW_OP_minus";
2817 return "DW_OP_plus";
2818 case DW_OP_plus_uconst
:
2819 return "DW_OP_plus_uconst";
2825 return "DW_OP_shra";
2843 return "DW_OP_skip";
2845 return "DW_OP_lit0";
2847 return "DW_OP_lit1";
2849 return "DW_OP_lit2";
2851 return "DW_OP_lit3";
2853 return "DW_OP_lit4";
2855 return "DW_OP_lit5";
2857 return "DW_OP_lit6";
2859 return "DW_OP_lit7";
2861 return "DW_OP_lit8";
2863 return "DW_OP_lit9";
2865 return "DW_OP_lit10";
2867 return "DW_OP_lit11";
2869 return "DW_OP_lit12";
2871 return "DW_OP_lit13";
2873 return "DW_OP_lit14";
2875 return "DW_OP_lit15";
2877 return "DW_OP_lit16";
2879 return "DW_OP_lit17";
2881 return "DW_OP_lit18";
2883 return "DW_OP_lit19";
2885 return "DW_OP_lit20";
2887 return "DW_OP_lit21";
2889 return "DW_OP_lit22";
2891 return "DW_OP_lit23";
2893 return "DW_OP_lit24";
2895 return "DW_OP_lit25";
2897 return "DW_OP_lit26";
2899 return "DW_OP_lit27";
2901 return "DW_OP_lit28";
2903 return "DW_OP_lit29";
2905 return "DW_OP_lit30";
2907 return "DW_OP_lit31";
2909 return "DW_OP_reg0";
2911 return "DW_OP_reg1";
2913 return "DW_OP_reg2";
2915 return "DW_OP_reg3";
2917 return "DW_OP_reg4";
2919 return "DW_OP_reg5";
2921 return "DW_OP_reg6";
2923 return "DW_OP_reg7";
2925 return "DW_OP_reg8";
2927 return "DW_OP_reg9";
2929 return "DW_OP_reg10";
2931 return "DW_OP_reg11";
2933 return "DW_OP_reg12";
2935 return "DW_OP_reg13";
2937 return "DW_OP_reg14";
2939 return "DW_OP_reg15";
2941 return "DW_OP_reg16";
2943 return "DW_OP_reg17";
2945 return "DW_OP_reg18";
2947 return "DW_OP_reg19";
2949 return "DW_OP_reg20";
2951 return "DW_OP_reg21";
2953 return "DW_OP_reg22";
2955 return "DW_OP_reg23";
2957 return "DW_OP_reg24";
2959 return "DW_OP_reg25";
2961 return "DW_OP_reg26";
2963 return "DW_OP_reg27";
2965 return "DW_OP_reg28";
2967 return "DW_OP_reg29";
2969 return "DW_OP_reg30";
2971 return "DW_OP_reg31";
2973 return "DW_OP_breg0";
2975 return "DW_OP_breg1";
2977 return "DW_OP_breg2";
2979 return "DW_OP_breg3";
2981 return "DW_OP_breg4";
2983 return "DW_OP_breg5";
2985 return "DW_OP_breg6";
2987 return "DW_OP_breg7";
2989 return "DW_OP_breg8";
2991 return "DW_OP_breg9";
2993 return "DW_OP_breg10";
2995 return "DW_OP_breg11";
2997 return "DW_OP_breg12";
2999 return "DW_OP_breg13";
3001 return "DW_OP_breg14";
3003 return "DW_OP_breg15";
3005 return "DW_OP_breg16";
3007 return "DW_OP_breg17";
3009 return "DW_OP_breg18";
3011 return "DW_OP_breg19";
3013 return "DW_OP_breg20";
3015 return "DW_OP_breg21";
3017 return "DW_OP_breg22";
3019 return "DW_OP_breg23";
3021 return "DW_OP_breg24";
3023 return "DW_OP_breg25";
3025 return "DW_OP_breg26";
3027 return "DW_OP_breg27";
3029 return "DW_OP_breg28";
3031 return "DW_OP_breg29";
3033 return "DW_OP_breg30";
3035 return "DW_OP_breg31";
3037 return "DW_OP_regx";
3039 return "DW_OP_fbreg";
3041 return "DW_OP_bregx";
3043 return "DW_OP_piece";
3044 case DW_OP_deref_size
:
3045 return "DW_OP_deref_size";
3046 case DW_OP_xderef_size
:
3047 return "DW_OP_xderef_size";
3050 case DW_OP_push_object_address
:
3051 return "DW_OP_push_object_address";
3053 return "DW_OP_call2";
3055 return "DW_OP_call4";
3056 case DW_OP_call_ref
:
3057 return "DW_OP_call_ref";
3058 case DW_OP_GNU_push_tls_address
:
3059 return "DW_OP_GNU_push_tls_address";
3061 return "OP_<unknown>";
3065 /* Return a pointer to a newly allocated location description. Location
3066 descriptions are simple expression terms that can be strung
3067 together to form more complicated location (address) descriptions. */
3069 static inline dw_loc_descr_ref
3070 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
3071 unsigned HOST_WIDE_INT oprnd2
)
3073 dw_loc_descr_ref descr
= ggc_alloc_cleared (sizeof (dw_loc_descr_node
));
3075 descr
->dw_loc_opc
= op
;
3076 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
3077 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
3078 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
3079 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
3084 /* Add a location description term to a location description expression. */
3087 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
3089 dw_loc_descr_ref
*d
;
3091 /* Find the end of the chain. */
3092 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
3098 /* Return the size of a location descriptor. */
3100 static unsigned long
3101 size_of_loc_descr (dw_loc_descr_ref loc
)
3103 unsigned long size
= 1;
3105 switch (loc
->dw_loc_opc
)
3108 case INTERNAL_DW_OP_tls_addr
:
3109 size
+= DWARF2_ADDR_SIZE
;
3128 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3131 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3136 case DW_OP_plus_uconst
:
3137 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3175 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3178 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3181 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3184 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3185 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
3188 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3190 case DW_OP_deref_size
:
3191 case DW_OP_xderef_size
:
3200 case DW_OP_call_ref
:
3201 size
+= DWARF2_ADDR_SIZE
;
3210 /* Return the size of a series of location descriptors. */
3212 static unsigned long
3213 size_of_locs (dw_loc_descr_ref loc
)
3217 for (size
= 0; loc
!= NULL
; loc
= loc
->dw_loc_next
)
3219 loc
->dw_loc_addr
= size
;
3220 size
+= size_of_loc_descr (loc
);
3226 /* Output location description stack opcode's operands (if any). */
3229 output_loc_operands (dw_loc_descr_ref loc
)
3231 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
3232 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
3234 switch (loc
->dw_loc_opc
)
3236 #ifdef DWARF2_DEBUGGING_INFO
3238 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
3242 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
3246 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
3250 gcc_assert (HOST_BITS_PER_LONG
>= 64);
3251 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
3258 gcc_assert (val1
->val_class
== dw_val_class_loc
);
3259 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
3261 dw2_asm_output_data (2, offset
, NULL
);
3274 /* We currently don't make any attempt to make sure these are
3275 aligned properly like we do for the main unwind info, so
3276 don't support emitting things larger than a byte if we're
3277 only doing unwinding. */
3282 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3285 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3288 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3291 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3293 case DW_OP_plus_uconst
:
3294 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3328 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3331 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3334 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3337 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3338 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
3341 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3343 case DW_OP_deref_size
:
3344 case DW_OP_xderef_size
:
3345 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3348 case INTERNAL_DW_OP_tls_addr
:
3349 if (targetm
.asm_out
.output_dwarf_dtprel
)
3351 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
3354 fputc ('\n', asm_out_file
);
3361 /* Other codes have no operands. */
3366 /* Output a sequence of location operations. */
3369 output_loc_sequence (dw_loc_descr_ref loc
)
3371 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
3373 /* Output the opcode. */
3374 dw2_asm_output_data (1, loc
->dw_loc_opc
,
3375 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
3377 /* Output the operand(s) (if any). */
3378 output_loc_operands (loc
);
3382 /* This routine will generate the correct assembly data for a location
3383 description based on a cfi entry with a complex address. */
3386 output_cfa_loc (dw_cfi_ref cfi
)
3388 dw_loc_descr_ref loc
;
3391 /* Output the size of the block. */
3392 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
3393 size
= size_of_locs (loc
);
3394 dw2_asm_output_data_uleb128 (size
, NULL
);
3396 /* Now output the operations themselves. */
3397 output_loc_sequence (loc
);
3400 /* This function builds a dwarf location descriptor sequence from a
3401 dw_cfa_location, adding the given OFFSET to the result of the
3404 static struct dw_loc_descr_struct
*
3405 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
3407 struct dw_loc_descr_struct
*head
, *tmp
;
3409 offset
+= cfa
->offset
;
3413 if (cfa
->base_offset
)
3416 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
3418 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
3420 else if (cfa
->reg
<= 31)
3421 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3423 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3425 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
3426 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
3427 add_loc_descr (&head
, tmp
);
3430 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
3431 add_loc_descr (&head
, tmp
);
3438 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3440 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3441 else if (cfa
->reg
<= 31)
3442 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, offset
, 0);
3444 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, offset
);
3450 /* This function fills in aa dw_cfa_location structure from a dwarf location
3451 descriptor sequence. */
3454 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
3456 struct dw_loc_descr_struct
*ptr
;
3458 cfa
->base_offset
= 0;
3462 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
3464 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3500 cfa
->reg
= op
- DW_OP_reg0
;
3503 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3537 cfa
->reg
= op
- DW_OP_breg0
;
3538 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3541 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3542 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3547 case DW_OP_plus_uconst
:
3548 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3551 internal_error ("DW_LOC_OP %s not implemented",
3552 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3556 #endif /* .debug_frame support */
3558 /* And now, the support for symbolic debugging information. */
3559 #ifdef DWARF2_DEBUGGING_INFO
3561 /* .debug_str support. */
3562 static int output_indirect_string (void **, void *);
3564 static void dwarf2out_init (const char *);
3565 static void dwarf2out_finish (const char *);
3566 static void dwarf2out_define (unsigned int, const char *);
3567 static void dwarf2out_undef (unsigned int, const char *);
3568 static void dwarf2out_start_source_file (unsigned, const char *);
3569 static void dwarf2out_end_source_file (unsigned);
3570 static void dwarf2out_begin_block (unsigned, unsigned);
3571 static void dwarf2out_end_block (unsigned, unsigned);
3572 static bool dwarf2out_ignore_block (tree
);
3573 static void dwarf2out_global_decl (tree
);
3574 static void dwarf2out_type_decl (tree
, int);
3575 static void dwarf2out_imported_module_or_decl (tree
, tree
);
3576 static void dwarf2out_abstract_function (tree
);
3577 static void dwarf2out_var_location (rtx
);
3578 static void dwarf2out_begin_function (tree
);
3579 static void dwarf2out_switch_text_section (void);
3581 /* The debug hooks structure. */
3583 const struct gcc_debug_hooks dwarf2_debug_hooks
=
3589 dwarf2out_start_source_file
,
3590 dwarf2out_end_source_file
,
3591 dwarf2out_begin_block
,
3592 dwarf2out_end_block
,
3593 dwarf2out_ignore_block
,
3594 dwarf2out_source_line
,
3595 dwarf2out_begin_prologue
,
3596 debug_nothing_int_charstar
, /* end_prologue */
3597 dwarf2out_end_epilogue
,
3598 dwarf2out_begin_function
,
3599 debug_nothing_int
, /* end_function */
3600 dwarf2out_decl
, /* function_decl */
3601 dwarf2out_global_decl
,
3602 dwarf2out_type_decl
, /* type_decl */
3603 dwarf2out_imported_module_or_decl
,
3604 debug_nothing_tree
, /* deferred_inline_function */
3605 /* The DWARF 2 backend tries to reduce debugging bloat by not
3606 emitting the abstract description of inline functions until
3607 something tries to reference them. */
3608 dwarf2out_abstract_function
, /* outlining_inline_function */
3609 debug_nothing_rtx
, /* label */
3610 debug_nothing_int
, /* handle_pch */
3611 dwarf2out_var_location
,
3612 dwarf2out_switch_text_section
,
3613 1 /* start_end_main_source_file */
3617 /* NOTE: In the comments in this file, many references are made to
3618 "Debugging Information Entries". This term is abbreviated as `DIE'
3619 throughout the remainder of this file. */
3621 /* An internal representation of the DWARF output is built, and then
3622 walked to generate the DWARF debugging info. The walk of the internal
3623 representation is done after the entire program has been compiled.
3624 The types below are used to describe the internal representation. */
3626 /* Various DIE's use offsets relative to the beginning of the
3627 .debug_info section to refer to each other. */
3629 typedef long int dw_offset
;
3631 /* Define typedefs here to avoid circular dependencies. */
3633 typedef struct dw_attr_struct
*dw_attr_ref
;
3634 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3635 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3636 typedef struct pubname_struct
*pubname_ref
;
3637 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3639 /* Each entry in the line_info_table maintains the file and
3640 line number associated with the label generated for that
3641 entry. The label gives the PC value associated with
3642 the line number entry. */
3644 typedef struct dw_line_info_struct
GTY(())
3646 unsigned long dw_file_num
;
3647 unsigned long dw_line_num
;
3651 /* Line information for functions in separate sections; each one gets its
3653 typedef struct dw_separate_line_info_struct
GTY(())
3655 unsigned long dw_file_num
;
3656 unsigned long dw_line_num
;
3657 unsigned long function
;
3659 dw_separate_line_info_entry
;
3661 /* Each DIE attribute has a field specifying the attribute kind,
3662 a link to the next attribute in the chain, and an attribute value.
3663 Attributes are typically linked below the DIE they modify. */
3665 typedef struct dw_attr_struct
GTY(())
3667 enum dwarf_attribute dw_attr
;
3668 dw_attr_ref dw_attr_next
;
3669 dw_val_node dw_attr_val
;
3673 /* The Debugging Information Entry (DIE) structure */
3675 typedef struct die_struct
GTY(())
3677 enum dwarf_tag die_tag
;
3679 dw_attr_ref die_attr
;
3680 dw_die_ref die_parent
;
3681 dw_die_ref die_child
;
3683 dw_die_ref die_definition
; /* ref from a specification to its definition */
3684 dw_offset die_offset
;
3685 unsigned long die_abbrev
;
3687 unsigned int decl_id
;
3691 /* The pubname structure */
3693 typedef struct pubname_struct
GTY(())
3700 struct dw_ranges_struct
GTY(())
3705 /* The limbo die list structure. */
3706 typedef struct limbo_die_struct
GTY(())
3710 struct limbo_die_struct
*next
;
3714 /* How to start an assembler comment. */
3715 #ifndef ASM_COMMENT_START
3716 #define ASM_COMMENT_START ";#"
3719 /* Define a macro which returns nonzero for a TYPE_DECL which was
3720 implicitly generated for a tagged type.
3722 Note that unlike the gcc front end (which generates a NULL named
3723 TYPE_DECL node for each complete tagged type, each array type, and
3724 each function type node created) the g++ front end generates a
3725 _named_ TYPE_DECL node for each tagged type node created.
3726 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3727 generate a DW_TAG_typedef DIE for them. */
3729 #define TYPE_DECL_IS_STUB(decl) \
3730 (DECL_NAME (decl) == NULL_TREE \
3731 || (DECL_ARTIFICIAL (decl) \
3732 && is_tagged_type (TREE_TYPE (decl)) \
3733 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3734 /* This is necessary for stub decls that \
3735 appear in nested inline functions. */ \
3736 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3737 && (decl_ultimate_origin (decl) \
3738 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3740 /* Information concerning the compilation unit's programming
3741 language, and compiler version. */
3743 /* Fixed size portion of the DWARF compilation unit header. */
3744 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3745 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3747 /* Fixed size portion of public names info. */
3748 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3750 /* Fixed size portion of the address range info. */
3751 #define DWARF_ARANGES_HEADER_SIZE \
3752 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3753 DWARF2_ADDR_SIZE * 2) \
3754 - DWARF_INITIAL_LENGTH_SIZE)
3756 /* Size of padding portion in the address range info. It must be
3757 aligned to twice the pointer size. */
3758 #define DWARF_ARANGES_PAD_SIZE \
3759 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3760 DWARF2_ADDR_SIZE * 2) \
3761 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3763 /* Use assembler line directives if available. */
3764 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3765 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3766 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3768 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3772 /* Minimum line offset in a special line info. opcode.
3773 This value was chosen to give a reasonable range of values. */
3774 #define DWARF_LINE_BASE -10
3776 /* First special line opcode - leave room for the standard opcodes. */
3777 #define DWARF_LINE_OPCODE_BASE 10
3779 /* Range of line offsets in a special line info. opcode. */
3780 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3782 /* Flag that indicates the initial value of the is_stmt_start flag.
3783 In the present implementation, we do not mark any lines as
3784 the beginning of a source statement, because that information
3785 is not made available by the GCC front-end. */
3786 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3788 #ifdef DWARF2_DEBUGGING_INFO
3789 /* This location is used by calc_die_sizes() to keep track
3790 the offset of each DIE within the .debug_info section. */
3791 static unsigned long next_die_offset
;
3794 /* Record the root of the DIE's built for the current compilation unit. */
3795 static GTY(()) dw_die_ref comp_unit_die
;
3797 /* A list of DIEs with a NULL parent waiting to be relocated. */
3798 static GTY(()) limbo_die_node
*limbo_die_list
;
3800 /* Filenames referenced by this compilation unit. */
3801 static GTY(()) varray_type file_table
;
3802 static GTY(()) varray_type file_table_emitted
;
3803 static GTY(()) size_t file_table_last_lookup_index
;
3805 /* A hash table of references to DIE's that describe declarations.
3806 The key is a DECL_UID() which is a unique number identifying each decl. */
3807 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
3809 /* Node of the variable location list. */
3810 struct var_loc_node
GTY ((chain_next ("%h.next")))
3812 rtx
GTY (()) var_loc_note
;
3813 const char * GTY (()) label
;
3814 const char * GTY (()) section_label
;
3815 struct var_loc_node
* GTY (()) next
;
3818 /* Variable location list. */
3819 struct var_loc_list_def
GTY (())
3821 struct var_loc_node
* GTY (()) first
;
3823 /* Do not mark the last element of the chained list because
3824 it is marked through the chain. */
3825 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3827 /* DECL_UID of the variable decl. */
3828 unsigned int decl_id
;
3830 typedef struct var_loc_list_def var_loc_list
;
3833 /* Table of decl location linked lists. */
3834 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
3836 /* A pointer to the base of a list of references to DIE's that
3837 are uniquely identified by their tag, presence/absence of
3838 children DIE's, and list of attribute/value pairs. */
3839 static GTY((length ("abbrev_die_table_allocated")))
3840 dw_die_ref
*abbrev_die_table
;
3842 /* Number of elements currently allocated for abbrev_die_table. */
3843 static GTY(()) unsigned abbrev_die_table_allocated
;
3845 /* Number of elements in type_die_table currently in use. */
3846 static GTY(()) unsigned abbrev_die_table_in_use
;
3848 /* Size (in elements) of increments by which we may expand the
3849 abbrev_die_table. */
3850 #define ABBREV_DIE_TABLE_INCREMENT 256
3852 /* A pointer to the base of a table that contains line information
3853 for each source code line in .text in the compilation unit. */
3854 static GTY((length ("line_info_table_allocated")))
3855 dw_line_info_ref line_info_table
;
3857 /* Number of elements currently allocated for line_info_table. */
3858 static GTY(()) unsigned line_info_table_allocated
;
3860 /* Number of elements in line_info_table currently in use. */
3861 static GTY(()) unsigned line_info_table_in_use
;
3863 /* True if the compilation unit places functions in more than one section. */
3864 static GTY(()) bool have_multiple_function_sections
= false;
3866 /* A pointer to the base of a table that contains line information
3867 for each source code line outside of .text in the compilation unit. */
3868 static GTY ((length ("separate_line_info_table_allocated")))
3869 dw_separate_line_info_ref separate_line_info_table
;
3871 /* Number of elements currently allocated for separate_line_info_table. */
3872 static GTY(()) unsigned separate_line_info_table_allocated
;
3874 /* Number of elements in separate_line_info_table currently in use. */
3875 static GTY(()) unsigned separate_line_info_table_in_use
;
3877 /* Size (in elements) of increments by which we may expand the
3879 #define LINE_INFO_TABLE_INCREMENT 1024
3881 /* A pointer to the base of a table that contains a list of publicly
3882 accessible names. */
3883 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table
;
3885 /* Number of elements currently allocated for pubname_table. */
3886 static GTY(()) unsigned pubname_table_allocated
;
3888 /* Number of elements in pubname_table currently in use. */
3889 static GTY(()) unsigned pubname_table_in_use
;
3891 /* Size (in elements) of increments by which we may expand the
3893 #define PUBNAME_TABLE_INCREMENT 64
3895 /* Array of dies for which we should generate .debug_arange info. */
3896 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
3898 /* Number of elements currently allocated for arange_table. */
3899 static GTY(()) unsigned arange_table_allocated
;
3901 /* Number of elements in arange_table currently in use. */
3902 static GTY(()) unsigned arange_table_in_use
;
3904 /* Size (in elements) of increments by which we may expand the
3906 #define ARANGE_TABLE_INCREMENT 64
3908 /* Array of dies for which we should generate .debug_ranges info. */
3909 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
3911 /* Number of elements currently allocated for ranges_table. */
3912 static GTY(()) unsigned ranges_table_allocated
;
3914 /* Number of elements in ranges_table currently in use. */
3915 static GTY(()) unsigned ranges_table_in_use
;
3917 /* Size (in elements) of increments by which we may expand the
3919 #define RANGES_TABLE_INCREMENT 64
3921 /* Whether we have location lists that need outputting */
3922 static GTY(()) bool have_location_lists
;
3924 /* Unique label counter. */
3925 static GTY(()) unsigned int loclabel_num
;
3927 #ifdef DWARF2_DEBUGGING_INFO
3928 /* Record whether the function being analyzed contains inlined functions. */
3929 static int current_function_has_inlines
;
3931 #if 0 && defined (MIPS_DEBUGGING_INFO)
3932 static int comp_unit_has_inlines
;
3935 /* Number of file tables emitted in maybe_emit_file(). */
3936 static GTY(()) int emitcount
= 0;
3938 /* Number of internal labels generated by gen_internal_sym(). */
3939 static GTY(()) int label_num
;
3941 #ifdef DWARF2_DEBUGGING_INFO
3943 /* Offset from the "steady-state frame pointer" to the frame base,
3944 within the current function. */
3945 static HOST_WIDE_INT frame_pointer_fb_offset
;
3947 /* Forward declarations for functions defined in this file. */
3949 static int is_pseudo_reg (rtx
);
3950 static tree
type_main_variant (tree
);
3951 static int is_tagged_type (tree
);
3952 static const char *dwarf_tag_name (unsigned);
3953 static const char *dwarf_attr_name (unsigned);
3954 static const char *dwarf_form_name (unsigned);
3955 static tree
decl_ultimate_origin (tree
);
3956 static tree
block_ultimate_origin (tree
);
3957 static tree
decl_class_context (tree
);
3958 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
3959 static inline enum dw_val_class
AT_class (dw_attr_ref
);
3960 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3961 static inline unsigned AT_flag (dw_attr_ref
);
3962 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3963 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
3964 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3965 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
3966 static void add_AT_long_long (dw_die_ref
, enum dwarf_attribute
, unsigned long,
3968 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3969 unsigned int, unsigned char *);
3970 static hashval_t
debug_str_do_hash (const void *);
3971 static int debug_str_eq (const void *, const void *);
3972 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3973 static inline const char *AT_string (dw_attr_ref
);
3974 static int AT_string_form (dw_attr_ref
);
3975 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3976 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3977 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3978 static inline int AT_ref_external (dw_attr_ref
);
3979 static inline void set_AT_ref_external (dw_attr_ref
, int);
3980 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3981 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3982 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3983 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3985 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3986 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
3987 static inline rtx
AT_addr (dw_attr_ref
);
3988 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3989 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3990 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3991 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3992 unsigned HOST_WIDE_INT
);
3993 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3995 static inline const char *AT_lbl (dw_attr_ref
);
3996 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3997 static const char *get_AT_low_pc (dw_die_ref
);
3998 static const char *get_AT_hi_pc (dw_die_ref
);
3999 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
4000 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
4001 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
4002 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
4003 static bool is_c_family (void);
4004 static bool is_cxx (void);
4005 static bool is_java (void);
4006 static bool is_fortran (void);
4007 static bool is_ada (void);
4008 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
4009 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
4010 static inline void free_die (dw_die_ref
);
4011 static void remove_children (dw_die_ref
);
4012 static void add_child_die (dw_die_ref
, dw_die_ref
);
4013 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
4014 static dw_die_ref
lookup_type_die (tree
);
4015 static void equate_type_number_to_die (tree
, dw_die_ref
);
4016 static hashval_t
decl_die_table_hash (const void *);
4017 static int decl_die_table_eq (const void *, const void *);
4018 static dw_die_ref
lookup_decl_die (tree
);
4019 static hashval_t
decl_loc_table_hash (const void *);
4020 static int decl_loc_table_eq (const void *, const void *);
4021 static var_loc_list
*lookup_decl_loc (tree
);
4022 static void equate_decl_number_to_die (tree
, dw_die_ref
);
4023 static void add_var_loc_to_decl (tree
, struct var_loc_node
*);
4024 static void print_spaces (FILE *);
4025 static void print_die (dw_die_ref
, FILE *);
4026 static void print_dwarf_line_table (FILE *);
4027 static void reverse_die_lists (dw_die_ref
);
4028 static void reverse_all_dies (dw_die_ref
);
4029 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
4030 static dw_die_ref
pop_compile_unit (dw_die_ref
);
4031 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
4032 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
4033 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
4034 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
4035 static int same_dw_val_p (dw_val_node
*, dw_val_node
*, int *);
4036 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
4037 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
4038 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
4039 static void compute_section_prefix (dw_die_ref
);
4040 static int is_type_die (dw_die_ref
);
4041 static int is_comdat_die (dw_die_ref
);
4042 static int is_symbol_die (dw_die_ref
);
4043 static void assign_symbol_names (dw_die_ref
);
4044 static void break_out_includes (dw_die_ref
);
4045 static hashval_t
htab_cu_hash (const void *);
4046 static int htab_cu_eq (const void *, const void *);
4047 static void htab_cu_del (void *);
4048 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
4049 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
4050 static void add_sibling_attributes (dw_die_ref
);
4051 static void build_abbrev_table (dw_die_ref
);
4052 static void output_location_lists (dw_die_ref
);
4053 static int constant_size (long unsigned);
4054 static unsigned long size_of_die (dw_die_ref
);
4055 static void calc_die_sizes (dw_die_ref
);
4056 static void mark_dies (dw_die_ref
);
4057 static void unmark_dies (dw_die_ref
);
4058 static void unmark_all_dies (dw_die_ref
);
4059 static unsigned long size_of_pubnames (void);
4060 static unsigned long size_of_aranges (void);
4061 static enum dwarf_form
value_format (dw_attr_ref
);
4062 static void output_value_format (dw_attr_ref
);
4063 static void output_abbrev_section (void);
4064 static void output_die_symbol (dw_die_ref
);
4065 static void output_die (dw_die_ref
);
4066 static void output_compilation_unit_header (void);
4067 static void output_comp_unit (dw_die_ref
, int);
4068 static const char *dwarf2_name (tree
, int);
4069 static void add_pubname (tree
, dw_die_ref
);
4070 static void output_pubnames (void);
4071 static void add_arange (tree
, dw_die_ref
);
4072 static void output_aranges (void);
4073 static unsigned int add_ranges (tree
);
4074 static void output_ranges (void);
4075 static void output_line_info (void);
4076 static void output_file_names (void);
4077 static dw_die_ref
base_type_die (tree
);
4078 static tree
root_type (tree
);
4079 static int is_base_type (tree
);
4080 static bool is_subrange_type (tree
);
4081 static dw_die_ref
subrange_type_die (tree
, dw_die_ref
);
4082 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
4083 static int type_is_enum (tree
);
4084 static unsigned int dbx_reg_number (rtx
);
4085 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
4086 static dw_loc_descr_ref
reg_loc_descriptor (rtx
);
4087 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int);
4088 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
);
4089 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
4090 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
);
4091 static int is_based_loc (rtx
);
4092 static dw_loc_descr_ref
mem_loc_descriptor (rtx
, enum machine_mode mode
);
4093 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
);
4094 static dw_loc_descr_ref
loc_descriptor (rtx
);
4095 static dw_loc_descr_ref
loc_descriptor_from_tree_1 (tree
, int);
4096 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
);
4097 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
4098 static tree
field_type (tree
);
4099 static unsigned int simple_type_align_in_bits (tree
);
4100 static unsigned int simple_decl_align_in_bits (tree
);
4101 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (tree
);
4102 static HOST_WIDE_INT
field_byte_offset (tree
);
4103 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
4105 static void add_data_member_location_attribute (dw_die_ref
, tree
);
4106 static void add_const_value_attribute (dw_die_ref
, rtx
);
4107 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
4108 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
4109 static void insert_float (rtx
, unsigned char *);
4110 static rtx
rtl_for_decl_location (tree
);
4111 static void add_location_or_const_value_attribute (dw_die_ref
, tree
,
4112 enum dwarf_attribute
);
4113 static void tree_add_const_value_attribute (dw_die_ref
, tree
);
4114 static void add_name_attribute (dw_die_ref
, const char *);
4115 static void add_comp_dir_attribute (dw_die_ref
);
4116 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
4117 static void add_subscript_info (dw_die_ref
, tree
);
4118 static void add_byte_size_attribute (dw_die_ref
, tree
);
4119 static void add_bit_offset_attribute (dw_die_ref
, tree
);
4120 static void add_bit_size_attribute (dw_die_ref
, tree
);
4121 static void add_prototyped_attribute (dw_die_ref
, tree
);
4122 static void add_abstract_origin_attribute (dw_die_ref
, tree
);
4123 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
4124 static void add_src_coords_attributes (dw_die_ref
, tree
);
4125 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
4126 static void push_decl_scope (tree
);
4127 static void pop_decl_scope (void);
4128 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
4129 static inline int local_scope_p (dw_die_ref
);
4130 static inline int class_or_namespace_scope_p (dw_die_ref
);
4131 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
4132 static void add_calling_convention_attribute (dw_die_ref
, tree
);
4133 static const char *type_tag (tree
);
4134 static tree
member_declared_type (tree
);
4136 static const char *decl_start_label (tree
);
4138 static void gen_array_type_die (tree
, dw_die_ref
);
4140 static void gen_entry_point_die (tree
, dw_die_ref
);
4142 static void gen_inlined_enumeration_type_die (tree
, dw_die_ref
);
4143 static void gen_inlined_structure_type_die (tree
, dw_die_ref
);
4144 static void gen_inlined_union_type_die (tree
, dw_die_ref
);
4145 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
4146 static dw_die_ref
gen_formal_parameter_die (tree
, dw_die_ref
);
4147 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
4148 static void gen_formal_types_die (tree
, dw_die_ref
);
4149 static void gen_subprogram_die (tree
, dw_die_ref
);
4150 static void gen_variable_die (tree
, dw_die_ref
);
4151 static void gen_label_die (tree
, dw_die_ref
);
4152 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
4153 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
4154 static void gen_field_die (tree
, dw_die_ref
);
4155 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
4156 static dw_die_ref
gen_compile_unit_die (const char *);
4157 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
4158 static void gen_member_die (tree
, dw_die_ref
);
4159 static void gen_struct_or_union_type_die (tree
, dw_die_ref
);
4160 static void gen_subroutine_type_die (tree
, dw_die_ref
);
4161 static void gen_typedef_die (tree
, dw_die_ref
);
4162 static void gen_type_die (tree
, dw_die_ref
);
4163 static void gen_tagged_type_instantiation_die (tree
, dw_die_ref
);
4164 static void gen_block_die (tree
, dw_die_ref
, int);
4165 static void decls_for_scope (tree
, dw_die_ref
, int);
4166 static int is_redundant_typedef (tree
);
4167 static void gen_namespace_die (tree
);
4168 static void gen_decl_die (tree
, dw_die_ref
);
4169 static dw_die_ref
force_decl_die (tree
);
4170 static dw_die_ref
force_type_die (tree
);
4171 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
4172 static void declare_in_namespace (tree
, dw_die_ref
);
4173 static unsigned lookup_filename (const char *);
4174 static void init_file_table (void);
4175 static void retry_incomplete_types (void);
4176 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
4177 static void splice_child_die (dw_die_ref
, dw_die_ref
);
4178 static int file_info_cmp (const void *, const void *);
4179 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
4180 const char *, const char *, unsigned);
4181 static void add_loc_descr_to_loc_list (dw_loc_list_ref
*, dw_loc_descr_ref
,
4182 const char *, const char *,
4184 static void output_loc_list (dw_loc_list_ref
);
4185 static char *gen_internal_sym (const char *);
4187 static void prune_unmark_dies (dw_die_ref
);
4188 static void prune_unused_types_mark (dw_die_ref
, int);
4189 static void prune_unused_types_walk (dw_die_ref
);
4190 static void prune_unused_types_walk_attribs (dw_die_ref
);
4191 static void prune_unused_types_prune (dw_die_ref
);
4192 static void prune_unused_types (void);
4193 static int maybe_emit_file (int);
4195 /* Section names used to hold DWARF debugging information. */
4196 #ifndef DEBUG_INFO_SECTION
4197 #define DEBUG_INFO_SECTION ".debug_info"
4199 #ifndef DEBUG_ABBREV_SECTION
4200 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4202 #ifndef DEBUG_ARANGES_SECTION
4203 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4205 #ifndef DEBUG_MACINFO_SECTION
4206 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4208 #ifndef DEBUG_LINE_SECTION
4209 #define DEBUG_LINE_SECTION ".debug_line"
4211 #ifndef DEBUG_LOC_SECTION
4212 #define DEBUG_LOC_SECTION ".debug_loc"
4214 #ifndef DEBUG_PUBNAMES_SECTION
4215 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4217 #ifndef DEBUG_STR_SECTION
4218 #define DEBUG_STR_SECTION ".debug_str"
4220 #ifndef DEBUG_RANGES_SECTION
4221 #define DEBUG_RANGES_SECTION ".debug_ranges"
4224 /* Standard ELF section names for compiled code and data. */
4225 #ifndef TEXT_SECTION_NAME
4226 #define TEXT_SECTION_NAME ".text"
4229 /* Section flags for .debug_str section. */
4230 #define DEBUG_STR_SECTION_FLAGS \
4231 (HAVE_GAS_SHF_MERGE && flag_merge_constants \
4232 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4235 /* Labels we insert at beginning sections we can reference instead of
4236 the section names themselves. */
4238 #ifndef TEXT_SECTION_LABEL
4239 #define TEXT_SECTION_LABEL "Ltext"
4241 #ifndef COLD_TEXT_SECTION_LABEL
4242 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4244 #ifndef DEBUG_LINE_SECTION_LABEL
4245 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4247 #ifndef DEBUG_INFO_SECTION_LABEL
4248 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4250 #ifndef DEBUG_ABBREV_SECTION_LABEL
4251 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4253 #ifndef DEBUG_LOC_SECTION_LABEL
4254 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4256 #ifndef DEBUG_RANGES_SECTION_LABEL
4257 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4259 #ifndef DEBUG_MACINFO_SECTION_LABEL
4260 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4263 /* Definitions of defaults for formats and names of various special
4264 (artificial) labels which may be generated within this file (when the -g
4265 options is used and DWARF2_DEBUGGING_INFO is in effect.
4266 If necessary, these may be overridden from within the tm.h file, but
4267 typically, overriding these defaults is unnecessary. */
4269 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4270 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4271 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4272 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4273 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4274 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4275 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4276 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4277 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4278 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
4280 #ifndef TEXT_END_LABEL
4281 #define TEXT_END_LABEL "Letext"
4283 #ifndef COLD_END_LABEL
4284 #define COLD_END_LABEL "Letext_cold"
4286 #ifndef BLOCK_BEGIN_LABEL
4287 #define BLOCK_BEGIN_LABEL "LBB"
4289 #ifndef BLOCK_END_LABEL
4290 #define BLOCK_END_LABEL "LBE"
4292 #ifndef LINE_CODE_LABEL
4293 #define LINE_CODE_LABEL "LM"
4295 #ifndef SEPARATE_LINE_CODE_LABEL
4296 #define SEPARATE_LINE_CODE_LABEL "LSM"
4299 /* We allow a language front-end to designate a function that is to be
4300 called to "demangle" any name before it is put into a DIE. */
4302 static const char *(*demangle_name_func
) (const char *);
4305 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
4307 demangle_name_func
= func
;
4310 /* Test if rtl node points to a pseudo register. */
4313 is_pseudo_reg (rtx rtl
)
4315 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
4316 || (GET_CODE (rtl
) == SUBREG
4317 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
4320 /* Return a reference to a type, with its const and volatile qualifiers
4324 type_main_variant (tree type
)
4326 type
= TYPE_MAIN_VARIANT (type
);
4328 /* ??? There really should be only one main variant among any group of
4329 variants of a given type (and all of the MAIN_VARIANT values for all
4330 members of the group should point to that one type) but sometimes the C
4331 front-end messes this up for array types, so we work around that bug
4333 if (TREE_CODE (type
) == ARRAY_TYPE
)
4334 while (type
!= TYPE_MAIN_VARIANT (type
))
4335 type
= TYPE_MAIN_VARIANT (type
);
4340 /* Return nonzero if the given type node represents a tagged type. */
4343 is_tagged_type (tree type
)
4345 enum tree_code code
= TREE_CODE (type
);
4347 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
4348 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
4351 /* Convert a DIE tag into its string name. */
4354 dwarf_tag_name (unsigned int tag
)
4358 case DW_TAG_padding
:
4359 return "DW_TAG_padding";
4360 case DW_TAG_array_type
:
4361 return "DW_TAG_array_type";
4362 case DW_TAG_class_type
:
4363 return "DW_TAG_class_type";
4364 case DW_TAG_entry_point
:
4365 return "DW_TAG_entry_point";
4366 case DW_TAG_enumeration_type
:
4367 return "DW_TAG_enumeration_type";
4368 case DW_TAG_formal_parameter
:
4369 return "DW_TAG_formal_parameter";
4370 case DW_TAG_imported_declaration
:
4371 return "DW_TAG_imported_declaration";
4373 return "DW_TAG_label";
4374 case DW_TAG_lexical_block
:
4375 return "DW_TAG_lexical_block";
4377 return "DW_TAG_member";
4378 case DW_TAG_pointer_type
:
4379 return "DW_TAG_pointer_type";
4380 case DW_TAG_reference_type
:
4381 return "DW_TAG_reference_type";
4382 case DW_TAG_compile_unit
:
4383 return "DW_TAG_compile_unit";
4384 case DW_TAG_string_type
:
4385 return "DW_TAG_string_type";
4386 case DW_TAG_structure_type
:
4387 return "DW_TAG_structure_type";
4388 case DW_TAG_subroutine_type
:
4389 return "DW_TAG_subroutine_type";
4390 case DW_TAG_typedef
:
4391 return "DW_TAG_typedef";
4392 case DW_TAG_union_type
:
4393 return "DW_TAG_union_type";
4394 case DW_TAG_unspecified_parameters
:
4395 return "DW_TAG_unspecified_parameters";
4396 case DW_TAG_variant
:
4397 return "DW_TAG_variant";
4398 case DW_TAG_common_block
:
4399 return "DW_TAG_common_block";
4400 case DW_TAG_common_inclusion
:
4401 return "DW_TAG_common_inclusion";
4402 case DW_TAG_inheritance
:
4403 return "DW_TAG_inheritance";
4404 case DW_TAG_inlined_subroutine
:
4405 return "DW_TAG_inlined_subroutine";
4407 return "DW_TAG_module";
4408 case DW_TAG_ptr_to_member_type
:
4409 return "DW_TAG_ptr_to_member_type";
4410 case DW_TAG_set_type
:
4411 return "DW_TAG_set_type";
4412 case DW_TAG_subrange_type
:
4413 return "DW_TAG_subrange_type";
4414 case DW_TAG_with_stmt
:
4415 return "DW_TAG_with_stmt";
4416 case DW_TAG_access_declaration
:
4417 return "DW_TAG_access_declaration";
4418 case DW_TAG_base_type
:
4419 return "DW_TAG_base_type";
4420 case DW_TAG_catch_block
:
4421 return "DW_TAG_catch_block";
4422 case DW_TAG_const_type
:
4423 return "DW_TAG_const_type";
4424 case DW_TAG_constant
:
4425 return "DW_TAG_constant";
4426 case DW_TAG_enumerator
:
4427 return "DW_TAG_enumerator";
4428 case DW_TAG_file_type
:
4429 return "DW_TAG_file_type";
4431 return "DW_TAG_friend";
4432 case DW_TAG_namelist
:
4433 return "DW_TAG_namelist";
4434 case DW_TAG_namelist_item
:
4435 return "DW_TAG_namelist_item";
4436 case DW_TAG_namespace
:
4437 return "DW_TAG_namespace";
4438 case DW_TAG_packed_type
:
4439 return "DW_TAG_packed_type";
4440 case DW_TAG_subprogram
:
4441 return "DW_TAG_subprogram";
4442 case DW_TAG_template_type_param
:
4443 return "DW_TAG_template_type_param";
4444 case DW_TAG_template_value_param
:
4445 return "DW_TAG_template_value_param";
4446 case DW_TAG_thrown_type
:
4447 return "DW_TAG_thrown_type";
4448 case DW_TAG_try_block
:
4449 return "DW_TAG_try_block";
4450 case DW_TAG_variant_part
:
4451 return "DW_TAG_variant_part";
4452 case DW_TAG_variable
:
4453 return "DW_TAG_variable";
4454 case DW_TAG_volatile_type
:
4455 return "DW_TAG_volatile_type";
4456 case DW_TAG_imported_module
:
4457 return "DW_TAG_imported_module";
4458 case DW_TAG_MIPS_loop
:
4459 return "DW_TAG_MIPS_loop";
4460 case DW_TAG_format_label
:
4461 return "DW_TAG_format_label";
4462 case DW_TAG_function_template
:
4463 return "DW_TAG_function_template";
4464 case DW_TAG_class_template
:
4465 return "DW_TAG_class_template";
4466 case DW_TAG_GNU_BINCL
:
4467 return "DW_TAG_GNU_BINCL";
4468 case DW_TAG_GNU_EINCL
:
4469 return "DW_TAG_GNU_EINCL";
4471 return "DW_TAG_<unknown>";
4475 /* Convert a DWARF attribute code into its string name. */
4478 dwarf_attr_name (unsigned int attr
)
4483 return "DW_AT_sibling";
4484 case DW_AT_location
:
4485 return "DW_AT_location";
4487 return "DW_AT_name";
4488 case DW_AT_ordering
:
4489 return "DW_AT_ordering";
4490 case DW_AT_subscr_data
:
4491 return "DW_AT_subscr_data";
4492 case DW_AT_byte_size
:
4493 return "DW_AT_byte_size";
4494 case DW_AT_bit_offset
:
4495 return "DW_AT_bit_offset";
4496 case DW_AT_bit_size
:
4497 return "DW_AT_bit_size";
4498 case DW_AT_element_list
:
4499 return "DW_AT_element_list";
4500 case DW_AT_stmt_list
:
4501 return "DW_AT_stmt_list";
4503 return "DW_AT_low_pc";
4505 return "DW_AT_high_pc";
4506 case DW_AT_language
:
4507 return "DW_AT_language";
4509 return "DW_AT_member";
4511 return "DW_AT_discr";
4512 case DW_AT_discr_value
:
4513 return "DW_AT_discr_value";
4514 case DW_AT_visibility
:
4515 return "DW_AT_visibility";
4517 return "DW_AT_import";
4518 case DW_AT_string_length
:
4519 return "DW_AT_string_length";
4520 case DW_AT_common_reference
:
4521 return "DW_AT_common_reference";
4522 case DW_AT_comp_dir
:
4523 return "DW_AT_comp_dir";
4524 case DW_AT_const_value
:
4525 return "DW_AT_const_value";
4526 case DW_AT_containing_type
:
4527 return "DW_AT_containing_type";
4528 case DW_AT_default_value
:
4529 return "DW_AT_default_value";
4531 return "DW_AT_inline";
4532 case DW_AT_is_optional
:
4533 return "DW_AT_is_optional";
4534 case DW_AT_lower_bound
:
4535 return "DW_AT_lower_bound";
4536 case DW_AT_producer
:
4537 return "DW_AT_producer";
4538 case DW_AT_prototyped
:
4539 return "DW_AT_prototyped";
4540 case DW_AT_return_addr
:
4541 return "DW_AT_return_addr";
4542 case DW_AT_start_scope
:
4543 return "DW_AT_start_scope";
4544 case DW_AT_stride_size
:
4545 return "DW_AT_stride_size";
4546 case DW_AT_upper_bound
:
4547 return "DW_AT_upper_bound";
4548 case DW_AT_abstract_origin
:
4549 return "DW_AT_abstract_origin";
4550 case DW_AT_accessibility
:
4551 return "DW_AT_accessibility";
4552 case DW_AT_address_class
:
4553 return "DW_AT_address_class";
4554 case DW_AT_artificial
:
4555 return "DW_AT_artificial";
4556 case DW_AT_base_types
:
4557 return "DW_AT_base_types";
4558 case DW_AT_calling_convention
:
4559 return "DW_AT_calling_convention";
4561 return "DW_AT_count";
4562 case DW_AT_data_member_location
:
4563 return "DW_AT_data_member_location";
4564 case DW_AT_decl_column
:
4565 return "DW_AT_decl_column";
4566 case DW_AT_decl_file
:
4567 return "DW_AT_decl_file";
4568 case DW_AT_decl_line
:
4569 return "DW_AT_decl_line";
4570 case DW_AT_declaration
:
4571 return "DW_AT_declaration";
4572 case DW_AT_discr_list
:
4573 return "DW_AT_discr_list";
4574 case DW_AT_encoding
:
4575 return "DW_AT_encoding";
4576 case DW_AT_external
:
4577 return "DW_AT_external";
4578 case DW_AT_frame_base
:
4579 return "DW_AT_frame_base";
4581 return "DW_AT_friend";
4582 case DW_AT_identifier_case
:
4583 return "DW_AT_identifier_case";
4584 case DW_AT_macro_info
:
4585 return "DW_AT_macro_info";
4586 case DW_AT_namelist_items
:
4587 return "DW_AT_namelist_items";
4588 case DW_AT_priority
:
4589 return "DW_AT_priority";
4591 return "DW_AT_segment";
4592 case DW_AT_specification
:
4593 return "DW_AT_specification";
4594 case DW_AT_static_link
:
4595 return "DW_AT_static_link";
4597 return "DW_AT_type";
4598 case DW_AT_use_location
:
4599 return "DW_AT_use_location";
4600 case DW_AT_variable_parameter
:
4601 return "DW_AT_variable_parameter";
4602 case DW_AT_virtuality
:
4603 return "DW_AT_virtuality";
4604 case DW_AT_vtable_elem_location
:
4605 return "DW_AT_vtable_elem_location";
4607 case DW_AT_allocated
:
4608 return "DW_AT_allocated";
4609 case DW_AT_associated
:
4610 return "DW_AT_associated";
4611 case DW_AT_data_location
:
4612 return "DW_AT_data_location";
4614 return "DW_AT_stride";
4615 case DW_AT_entry_pc
:
4616 return "DW_AT_entry_pc";
4617 case DW_AT_use_UTF8
:
4618 return "DW_AT_use_UTF8";
4619 case DW_AT_extension
:
4620 return "DW_AT_extension";
4622 return "DW_AT_ranges";
4623 case DW_AT_trampoline
:
4624 return "DW_AT_trampoline";
4625 case DW_AT_call_column
:
4626 return "DW_AT_call_column";
4627 case DW_AT_call_file
:
4628 return "DW_AT_call_file";
4629 case DW_AT_call_line
:
4630 return "DW_AT_call_line";
4632 case DW_AT_MIPS_fde
:
4633 return "DW_AT_MIPS_fde";
4634 case DW_AT_MIPS_loop_begin
:
4635 return "DW_AT_MIPS_loop_begin";
4636 case DW_AT_MIPS_tail_loop_begin
:
4637 return "DW_AT_MIPS_tail_loop_begin";
4638 case DW_AT_MIPS_epilog_begin
:
4639 return "DW_AT_MIPS_epilog_begin";
4640 case DW_AT_MIPS_loop_unroll_factor
:
4641 return "DW_AT_MIPS_loop_unroll_factor";
4642 case DW_AT_MIPS_software_pipeline_depth
:
4643 return "DW_AT_MIPS_software_pipeline_depth";
4644 case DW_AT_MIPS_linkage_name
:
4645 return "DW_AT_MIPS_linkage_name";
4646 case DW_AT_MIPS_stride
:
4647 return "DW_AT_MIPS_stride";
4648 case DW_AT_MIPS_abstract_name
:
4649 return "DW_AT_MIPS_abstract_name";
4650 case DW_AT_MIPS_clone_origin
:
4651 return "DW_AT_MIPS_clone_origin";
4652 case DW_AT_MIPS_has_inlines
:
4653 return "DW_AT_MIPS_has_inlines";
4655 case DW_AT_sf_names
:
4656 return "DW_AT_sf_names";
4657 case DW_AT_src_info
:
4658 return "DW_AT_src_info";
4659 case DW_AT_mac_info
:
4660 return "DW_AT_mac_info";
4661 case DW_AT_src_coords
:
4662 return "DW_AT_src_coords";
4663 case DW_AT_body_begin
:
4664 return "DW_AT_body_begin";
4665 case DW_AT_body_end
:
4666 return "DW_AT_body_end";
4667 case DW_AT_GNU_vector
:
4668 return "DW_AT_GNU_vector";
4670 case DW_AT_VMS_rtnbeg_pd_address
:
4671 return "DW_AT_VMS_rtnbeg_pd_address";
4674 return "DW_AT_<unknown>";
4678 /* Convert a DWARF value form code into its string name. */
4681 dwarf_form_name (unsigned int form
)
4686 return "DW_FORM_addr";
4687 case DW_FORM_block2
:
4688 return "DW_FORM_block2";
4689 case DW_FORM_block4
:
4690 return "DW_FORM_block4";
4692 return "DW_FORM_data2";
4694 return "DW_FORM_data4";
4696 return "DW_FORM_data8";
4697 case DW_FORM_string
:
4698 return "DW_FORM_string";
4700 return "DW_FORM_block";
4701 case DW_FORM_block1
:
4702 return "DW_FORM_block1";
4704 return "DW_FORM_data1";
4706 return "DW_FORM_flag";
4708 return "DW_FORM_sdata";
4710 return "DW_FORM_strp";
4712 return "DW_FORM_udata";
4713 case DW_FORM_ref_addr
:
4714 return "DW_FORM_ref_addr";
4716 return "DW_FORM_ref1";
4718 return "DW_FORM_ref2";
4720 return "DW_FORM_ref4";
4722 return "DW_FORM_ref8";
4723 case DW_FORM_ref_udata
:
4724 return "DW_FORM_ref_udata";
4725 case DW_FORM_indirect
:
4726 return "DW_FORM_indirect";
4728 return "DW_FORM_<unknown>";
4732 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4733 instance of an inlined instance of a decl which is local to an inline
4734 function, so we have to trace all of the way back through the origin chain
4735 to find out what sort of node actually served as the original seed for the
4739 decl_ultimate_origin (tree decl
)
4741 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4744 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4745 nodes in the function to point to themselves; ignore that if
4746 we're trying to output the abstract instance of this function. */
4747 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4750 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4751 most distant ancestor, this should never happen. */
4752 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4754 return DECL_ABSTRACT_ORIGIN (decl
);
4757 /* Determine the "ultimate origin" of a block. The block may be an inlined
4758 instance of an inlined instance of a block which is local to an inline
4759 function, so we have to trace all of the way back through the origin chain
4760 to find out what sort of node actually served as the original seed for the
4764 block_ultimate_origin (tree block
)
4766 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4768 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4769 nodes in the function to point to themselves; ignore that if
4770 we're trying to output the abstract instance of this function. */
4771 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4774 if (immediate_origin
== NULL_TREE
)
4779 tree lookahead
= immediate_origin
;
4783 ret_val
= lookahead
;
4784 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4785 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4787 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4789 /* The block's abstract origin chain may not be the *ultimate* origin of
4790 the block. It could lead to a DECL that has an abstract origin set.
4791 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
4792 will give us if it has one). Note that DECL's abstract origins are
4793 supposed to be the most distant ancestor (or so decl_ultimate_origin
4794 claims), so we don't need to loop following the DECL origins. */
4795 if (DECL_P (ret_val
))
4796 return DECL_ORIGIN (ret_val
);
4802 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4803 of a virtual function may refer to a base class, so we check the 'this'
4807 decl_class_context (tree decl
)
4809 tree context
= NULL_TREE
;
4811 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4812 context
= DECL_CONTEXT (decl
);
4814 context
= TYPE_MAIN_VARIANT
4815 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4817 if (context
&& !TYPE_P (context
))
4818 context
= NULL_TREE
;
4823 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4824 addition order, and correct that in reverse_all_dies. */
4827 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
4829 if (die
!= NULL
&& attr
!= NULL
)
4831 attr
->dw_attr_next
= die
->die_attr
;
4832 die
->die_attr
= attr
;
4836 static inline enum dw_val_class
4837 AT_class (dw_attr_ref a
)
4839 return a
->dw_attr_val
.val_class
;
4842 /* Add a flag value attribute to a DIE. */
4845 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4847 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4849 attr
->dw_attr_next
= NULL
;
4850 attr
->dw_attr
= attr_kind
;
4851 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
4852 attr
->dw_attr_val
.v
.val_flag
= flag
;
4853 add_dwarf_attr (die
, attr
);
4856 static inline unsigned
4857 AT_flag (dw_attr_ref a
)
4859 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4860 return a
->dw_attr_val
.v
.val_flag
;
4863 /* Add a signed integer attribute value to a DIE. */
4866 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4868 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4870 attr
->dw_attr_next
= NULL
;
4871 attr
->dw_attr
= attr_kind
;
4872 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
4873 attr
->dw_attr_val
.v
.val_int
= int_val
;
4874 add_dwarf_attr (die
, attr
);
4877 static inline HOST_WIDE_INT
4878 AT_int (dw_attr_ref a
)
4880 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
4881 return a
->dw_attr_val
.v
.val_int
;
4884 /* Add an unsigned integer attribute value to a DIE. */
4887 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4888 unsigned HOST_WIDE_INT unsigned_val
)
4890 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4892 attr
->dw_attr_next
= NULL
;
4893 attr
->dw_attr
= attr_kind
;
4894 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4895 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4896 add_dwarf_attr (die
, attr
);
4899 static inline unsigned HOST_WIDE_INT
4900 AT_unsigned (dw_attr_ref a
)
4902 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
4903 return a
->dw_attr_val
.v
.val_unsigned
;
4906 /* Add an unsigned double integer attribute value to a DIE. */
4909 add_AT_long_long (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4910 long unsigned int val_hi
, long unsigned int val_low
)
4912 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4914 attr
->dw_attr_next
= NULL
;
4915 attr
->dw_attr
= attr_kind
;
4916 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
4917 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4918 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
4919 add_dwarf_attr (die
, attr
);
4922 /* Add a floating point attribute value to a DIE and return it. */
4925 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4926 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4928 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4930 attr
->dw_attr_next
= NULL
;
4931 attr
->dw_attr
= attr_kind
;
4932 attr
->dw_attr_val
.val_class
= dw_val_class_vec
;
4933 attr
->dw_attr_val
.v
.val_vec
.length
= length
;
4934 attr
->dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4935 attr
->dw_attr_val
.v
.val_vec
.array
= array
;
4936 add_dwarf_attr (die
, attr
);
4939 /* Hash and equality functions for debug_str_hash. */
4942 debug_str_do_hash (const void *x
)
4944 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
4948 debug_str_eq (const void *x1
, const void *x2
)
4950 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
4951 (const char *)x2
) == 0;
4954 /* Add a string attribute value to a DIE. */
4957 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4959 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4960 struct indirect_string_node
*node
;
4963 if (! debug_str_hash
)
4964 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
4965 debug_str_eq
, NULL
);
4967 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
4968 htab_hash_string (str
), INSERT
);
4970 *slot
= ggc_alloc_cleared (sizeof (struct indirect_string_node
));
4971 node
= (struct indirect_string_node
*) *slot
;
4972 node
->str
= ggc_strdup (str
);
4975 attr
->dw_attr_next
= NULL
;
4976 attr
->dw_attr
= attr_kind
;
4977 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
4978 attr
->dw_attr_val
.v
.val_str
= node
;
4979 add_dwarf_attr (die
, attr
);
4982 static inline const char *
4983 AT_string (dw_attr_ref a
)
4985 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4986 return a
->dw_attr_val
.v
.val_str
->str
;
4989 /* Find out whether a string should be output inline in DIE
4990 or out-of-line in .debug_str section. */
4993 AT_string_form (dw_attr_ref a
)
4995 struct indirect_string_node
*node
;
4999 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
5001 node
= a
->dw_attr_val
.v
.val_str
;
5005 len
= strlen (node
->str
) + 1;
5007 /* If the string is shorter or equal to the size of the reference, it is
5008 always better to put it inline. */
5009 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
5010 return node
->form
= DW_FORM_string
;
5012 /* If we cannot expect the linker to merge strings in .debug_str
5013 section, only put it into .debug_str if it is worth even in this
5015 if ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
5016 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
5017 return node
->form
= DW_FORM_string
;
5019 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
5020 ++dw2_string_counter
;
5021 node
->label
= xstrdup (label
);
5023 return node
->form
= DW_FORM_strp
;
5026 /* Add a DIE reference attribute value to a DIE. */
5029 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
5031 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5033 attr
->dw_attr_next
= NULL
;
5034 attr
->dw_attr
= attr_kind
;
5035 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
5036 attr
->dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
5037 attr
->dw_attr_val
.v
.val_die_ref
.external
= 0;
5038 add_dwarf_attr (die
, attr
);
5041 /* Add an AT_specification attribute to a DIE, and also make the back
5042 pointer from the specification to the definition. */
5045 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
5047 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
5048 gcc_assert (!targ_die
->die_definition
);
5049 targ_die
->die_definition
= die
;
5052 static inline dw_die_ref
5053 AT_ref (dw_attr_ref a
)
5055 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
5056 return a
->dw_attr_val
.v
.val_die_ref
.die
;
5060 AT_ref_external (dw_attr_ref a
)
5062 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
5063 return a
->dw_attr_val
.v
.val_die_ref
.external
;
5069 set_AT_ref_external (dw_attr_ref a
, int i
)
5071 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
5072 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
5075 /* Add an FDE reference attribute value to a DIE. */
5078 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
5080 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5082 attr
->dw_attr_next
= NULL
;
5083 attr
->dw_attr
= attr_kind
;
5084 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
5085 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
5086 add_dwarf_attr (die
, attr
);
5089 /* Add a location description attribute value to a DIE. */
5092 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
5094 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5096 attr
->dw_attr_next
= NULL
;
5097 attr
->dw_attr
= attr_kind
;
5098 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
5099 attr
->dw_attr_val
.v
.val_loc
= loc
;
5100 add_dwarf_attr (die
, attr
);
5103 static inline dw_loc_descr_ref
5104 AT_loc (dw_attr_ref a
)
5106 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
5107 return a
->dw_attr_val
.v
.val_loc
;
5111 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
5113 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5115 attr
->dw_attr_next
= NULL
;
5116 attr
->dw_attr
= attr_kind
;
5117 attr
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
5118 attr
->dw_attr_val
.v
.val_loc_list
= loc_list
;
5119 add_dwarf_attr (die
, attr
);
5120 have_location_lists
= true;
5123 static inline dw_loc_list_ref
5124 AT_loc_list (dw_attr_ref a
)
5126 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
5127 return a
->dw_attr_val
.v
.val_loc_list
;
5130 /* Add an address constant attribute value to a DIE. */
5133 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
5135 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5137 attr
->dw_attr_next
= NULL
;
5138 attr
->dw_attr
= attr_kind
;
5139 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
5140 attr
->dw_attr_val
.v
.val_addr
= addr
;
5141 add_dwarf_attr (die
, attr
);
5145 AT_addr (dw_attr_ref a
)
5147 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
5148 return a
->dw_attr_val
.v
.val_addr
;
5151 /* Add a label identifier attribute value to a DIE. */
5154 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
5156 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5158 attr
->dw_attr_next
= NULL
;
5159 attr
->dw_attr
= attr_kind
;
5160 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
5161 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
5162 add_dwarf_attr (die
, attr
);
5165 /* Add a section offset attribute value to a DIE, an offset into the
5166 debug_line section. */
5169 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5172 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5174 attr
->dw_attr_next
= NULL
;
5175 attr
->dw_attr
= attr_kind
;
5176 attr
->dw_attr_val
.val_class
= dw_val_class_lineptr
;
5177 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5178 add_dwarf_attr (die
, attr
);
5181 /* Add a section offset attribute value to a DIE, an offset into the
5182 debug_macinfo section. */
5185 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5188 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5190 attr
->dw_attr_next
= NULL
;
5191 attr
->dw_attr
= attr_kind
;
5192 attr
->dw_attr_val
.val_class
= dw_val_class_macptr
;
5193 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5194 add_dwarf_attr (die
, attr
);
5197 /* Add an offset attribute value to a DIE. */
5200 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5201 unsigned HOST_WIDE_INT offset
)
5203 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5205 attr
->dw_attr_next
= NULL
;
5206 attr
->dw_attr
= attr_kind
;
5207 attr
->dw_attr_val
.val_class
= dw_val_class_offset
;
5208 attr
->dw_attr_val
.v
.val_offset
= offset
;
5209 add_dwarf_attr (die
, attr
);
5212 /* Add an range_list attribute value to a DIE. */
5215 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5216 long unsigned int offset
)
5218 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5220 attr
->dw_attr_next
= NULL
;
5221 attr
->dw_attr
= attr_kind
;
5222 attr
->dw_attr_val
.val_class
= dw_val_class_range_list
;
5223 attr
->dw_attr_val
.v
.val_offset
= offset
;
5224 add_dwarf_attr (die
, attr
);
5227 static inline const char *
5228 AT_lbl (dw_attr_ref a
)
5230 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
5231 || AT_class (a
) == dw_val_class_lineptr
5232 || AT_class (a
) == dw_val_class_macptr
));
5233 return a
->dw_attr_val
.v
.val_lbl_id
;
5236 /* Get the attribute of type attr_kind. */
5239 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5242 dw_die_ref spec
= NULL
;
5246 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5247 if (a
->dw_attr
== attr_kind
)
5249 else if (a
->dw_attr
== DW_AT_specification
5250 || a
->dw_attr
== DW_AT_abstract_origin
)
5254 return get_AT (spec
, attr_kind
);
5260 /* Return the "low pc" attribute value, typically associated with a subprogram
5261 DIE. Return null if the "low pc" attribute is either not present, or if it
5262 cannot be represented as an assembler label identifier. */
5264 static inline const char *
5265 get_AT_low_pc (dw_die_ref die
)
5267 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
5269 return a
? AT_lbl (a
) : NULL
;
5272 /* Return the "high pc" attribute value, typically associated with a subprogram
5273 DIE. Return null if the "high pc" attribute is either not present, or if it
5274 cannot be represented as an assembler label identifier. */
5276 static inline const char *
5277 get_AT_hi_pc (dw_die_ref die
)
5279 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
5281 return a
? AT_lbl (a
) : NULL
;
5284 /* Return the value of the string attribute designated by ATTR_KIND, or
5285 NULL if it is not present. */
5287 static inline const char *
5288 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5290 dw_attr_ref a
= get_AT (die
, attr_kind
);
5292 return a
? AT_string (a
) : NULL
;
5295 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5296 if it is not present. */
5299 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5301 dw_attr_ref a
= get_AT (die
, attr_kind
);
5303 return a
? AT_flag (a
) : 0;
5306 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5307 if it is not present. */
5309 static inline unsigned
5310 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5312 dw_attr_ref a
= get_AT (die
, attr_kind
);
5314 return a
? AT_unsigned (a
) : 0;
5317 static inline dw_die_ref
5318 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5320 dw_attr_ref a
= get_AT (die
, attr_kind
);
5322 return a
? AT_ref (a
) : NULL
;
5325 /* Return TRUE if the language is C or C++. */
5330 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5332 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
5333 || lang
== DW_LANG_C_plus_plus
);
5336 /* Return TRUE if the language is C++. */
5341 return (get_AT_unsigned (comp_unit_die
, DW_AT_language
)
5342 == DW_LANG_C_plus_plus
);
5345 /* Return TRUE if the language is Fortran. */
5350 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5352 return (lang
== DW_LANG_Fortran77
5353 || lang
== DW_LANG_Fortran90
5354 || lang
== DW_LANG_Fortran95
);
5357 /* Return TRUE if the language is Java. */
5362 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5364 return lang
== DW_LANG_Java
;
5367 /* Return TRUE if the language is Ada. */
5372 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5374 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5377 /* Free up the memory used by A. */
5379 static inline void free_AT (dw_attr_ref
);
5381 free_AT (dw_attr_ref a
)
5383 if (AT_class (a
) == dw_val_class_str
)
5384 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5385 a
->dw_attr_val
.v
.val_str
->refcount
--;
5388 /* Remove the specified attribute if present. */
5391 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5394 dw_attr_ref removed
= NULL
;
5398 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
5399 if ((*p
)->dw_attr
== attr_kind
)
5402 *p
= (*p
)->dw_attr_next
;
5411 /* Remove child die whose die_tag is specified tag. */
5414 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5416 dw_die_ref current
, prev
, next
;
5417 current
= die
->die_child
;
5419 while (current
!= NULL
)
5421 if (current
->die_tag
== tag
)
5423 next
= current
->die_sib
;
5425 die
->die_child
= next
;
5427 prev
->die_sib
= next
;
5434 current
= current
->die_sib
;
5439 /* Free up the memory used by DIE. */
5442 free_die (dw_die_ref die
)
5444 remove_children (die
);
5447 /* Discard the children of this DIE. */
5450 remove_children (dw_die_ref die
)
5452 dw_die_ref child_die
= die
->die_child
;
5454 die
->die_child
= NULL
;
5456 while (child_die
!= NULL
)
5458 dw_die_ref tmp_die
= child_die
;
5461 child_die
= child_die
->die_sib
;
5463 for (a
= tmp_die
->die_attr
; a
!= NULL
;)
5465 dw_attr_ref tmp_a
= a
;
5467 a
= a
->dw_attr_next
;
5475 /* Add a child DIE below its parent. We build the lists up in reverse
5476 addition order, and correct that in reverse_all_dies. */
5479 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5481 if (die
!= NULL
&& child_die
!= NULL
)
5483 gcc_assert (die
!= child_die
);
5485 child_die
->die_parent
= die
;
5486 child_die
->die_sib
= die
->die_child
;
5487 die
->die_child
= child_die
;
5491 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5492 is the specification, to the front of PARENT's list of children. */
5495 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5499 /* We want the declaration DIE from inside the class, not the
5500 specification DIE at toplevel. */
5501 if (child
->die_parent
!= parent
)
5503 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5509 gcc_assert (child
->die_parent
== parent
5510 || (child
->die_parent
5511 == get_AT_ref (parent
, DW_AT_specification
)));
5513 for (p
= &(child
->die_parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
5516 *p
= child
->die_sib
;
5520 child
->die_parent
= parent
;
5521 child
->die_sib
= parent
->die_child
;
5522 parent
->die_child
= child
;
5525 /* Return a pointer to a newly created DIE node. */
5527 static inline dw_die_ref
5528 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5530 dw_die_ref die
= ggc_alloc_cleared (sizeof (die_node
));
5532 die
->die_tag
= tag_value
;
5534 if (parent_die
!= NULL
)
5535 add_child_die (parent_die
, die
);
5538 limbo_die_node
*limbo_node
;
5540 limbo_node
= ggc_alloc_cleared (sizeof (limbo_die_node
));
5541 limbo_node
->die
= die
;
5542 limbo_node
->created_for
= t
;
5543 limbo_node
->next
= limbo_die_list
;
5544 limbo_die_list
= limbo_node
;
5550 /* Return the DIE associated with the given type specifier. */
5552 static inline dw_die_ref
5553 lookup_type_die (tree type
)
5555 return TYPE_SYMTAB_DIE (type
);
5558 /* Equate a DIE to a given type specifier. */
5561 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5563 TYPE_SYMTAB_DIE (type
) = type_die
;
5566 /* Returns a hash value for X (which really is a die_struct). */
5569 decl_die_table_hash (const void *x
)
5571 return (hashval_t
) ((const dw_die_ref
) x
)->decl_id
;
5574 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5577 decl_die_table_eq (const void *x
, const void *y
)
5579 return (((const dw_die_ref
) x
)->decl_id
== DECL_UID ((const tree
) y
));
5582 /* Return the DIE associated with a given declaration. */
5584 static inline dw_die_ref
5585 lookup_decl_die (tree decl
)
5587 return htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
5590 /* Returns a hash value for X (which really is a var_loc_list). */
5593 decl_loc_table_hash (const void *x
)
5595 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
5598 /* Return nonzero if decl_id of var_loc_list X is the same as
5602 decl_loc_table_eq (const void *x
, const void *y
)
5604 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const tree
) y
));
5607 /* Return the var_loc list associated with a given declaration. */
5609 static inline var_loc_list
*
5610 lookup_decl_loc (tree decl
)
5612 return htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
5615 /* Equate a DIE to a particular declaration. */
5618 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5620 unsigned int decl_id
= DECL_UID (decl
);
5623 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
5625 decl_die
->decl_id
= decl_id
;
5628 /* Add a variable location node to the linked list for DECL. */
5631 add_var_loc_to_decl (tree decl
, struct var_loc_node
*loc
)
5633 unsigned int decl_id
= DECL_UID (decl
);
5637 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5640 temp
= ggc_alloc_cleared (sizeof (var_loc_list
));
5641 temp
->decl_id
= decl_id
;
5649 /* If the current location is the same as the end of the list,
5650 we have nothing to do. */
5651 if (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->last
->var_loc_note
),
5652 NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
)))
5654 /* Add LOC to the end of list and update LAST. */
5655 temp
->last
->next
= loc
;
5659 /* Do not add empty location to the beginning of the list. */
5660 else if (NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
) != NULL_RTX
)
5667 /* Keep track of the number of spaces used to indent the
5668 output of the debugging routines that print the structure of
5669 the DIE internal representation. */
5670 static int print_indent
;
5672 /* Indent the line the number of spaces given by print_indent. */
5675 print_spaces (FILE *outfile
)
5677 fprintf (outfile
, "%*s", print_indent
, "");
5680 /* Print the information associated with a given DIE, and its children.
5681 This routine is a debugging aid only. */
5684 print_die (dw_die_ref die
, FILE *outfile
)
5689 print_spaces (outfile
);
5690 fprintf (outfile
, "DIE %4lu: %s\n",
5691 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5692 print_spaces (outfile
);
5693 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5694 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
5696 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5698 print_spaces (outfile
);
5699 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5701 switch (AT_class (a
))
5703 case dw_val_class_addr
:
5704 fprintf (outfile
, "address");
5706 case dw_val_class_offset
:
5707 fprintf (outfile
, "offset");
5709 case dw_val_class_loc
:
5710 fprintf (outfile
, "location descriptor");
5712 case dw_val_class_loc_list
:
5713 fprintf (outfile
, "location list -> label:%s",
5714 AT_loc_list (a
)->ll_symbol
);
5716 case dw_val_class_range_list
:
5717 fprintf (outfile
, "range list");
5719 case dw_val_class_const
:
5720 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5722 case dw_val_class_unsigned_const
:
5723 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5725 case dw_val_class_long_long
:
5726 fprintf (outfile
, "constant (%lu,%lu)",
5727 a
->dw_attr_val
.v
.val_long_long
.hi
,
5728 a
->dw_attr_val
.v
.val_long_long
.low
);
5730 case dw_val_class_vec
:
5731 fprintf (outfile
, "floating-point or vector constant");
5733 case dw_val_class_flag
:
5734 fprintf (outfile
, "%u", AT_flag (a
));
5736 case dw_val_class_die_ref
:
5737 if (AT_ref (a
) != NULL
)
5739 if (AT_ref (a
)->die_symbol
)
5740 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5742 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
5745 fprintf (outfile
, "die -> <null>");
5747 case dw_val_class_lbl_id
:
5748 case dw_val_class_lineptr
:
5749 case dw_val_class_macptr
:
5750 fprintf (outfile
, "label: %s", AT_lbl (a
));
5752 case dw_val_class_str
:
5753 if (AT_string (a
) != NULL
)
5754 fprintf (outfile
, "\"%s\"", AT_string (a
));
5756 fprintf (outfile
, "<null>");
5762 fprintf (outfile
, "\n");
5765 if (die
->die_child
!= NULL
)
5768 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5769 print_die (c
, outfile
);
5773 if (print_indent
== 0)
5774 fprintf (outfile
, "\n");
5777 /* Print the contents of the source code line number correspondence table.
5778 This routine is a debugging aid only. */
5781 print_dwarf_line_table (FILE *outfile
)
5784 dw_line_info_ref line_info
;
5786 fprintf (outfile
, "\n\nDWARF source line information\n");
5787 for (i
= 1; i
< line_info_table_in_use
; i
++)
5789 line_info
= &line_info_table
[i
];
5790 fprintf (outfile
, "%5d: ", i
);
5791 fprintf (outfile
, "%-20s",
5792 VARRAY_CHAR_PTR (file_table
, line_info
->dw_file_num
));
5793 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
5794 fprintf (outfile
, "\n");
5797 fprintf (outfile
, "\n\n");
5800 /* Print the information collected for a given DIE. */
5803 debug_dwarf_die (dw_die_ref die
)
5805 print_die (die
, stderr
);
5808 /* Print all DWARF information collected for the compilation unit.
5809 This routine is a debugging aid only. */
5815 print_die (comp_unit_die
, stderr
);
5816 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5817 print_dwarf_line_table (stderr
);
5820 /* We build up the lists of children and attributes by pushing new ones
5821 onto the beginning of the list. Reverse the lists for DIE so that
5822 they are in order of addition. */
5825 reverse_die_lists (dw_die_ref die
)
5827 dw_die_ref c
, cp
, cn
;
5828 dw_attr_ref a
, ap
, an
;
5830 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
5832 an
= a
->dw_attr_next
;
5833 a
->dw_attr_next
= ap
;
5839 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
5846 die
->die_child
= cp
;
5849 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5850 reverse all dies in add_sibling_attributes, which runs through all the dies,
5851 it would reverse all the dies. Now, however, since we don't call
5852 reverse_die_lists in add_sibling_attributes, we need a routine to
5853 recursively reverse all the dies. This is that routine. */
5856 reverse_all_dies (dw_die_ref die
)
5860 reverse_die_lists (die
);
5862 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5863 reverse_all_dies (c
);
5866 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5867 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5868 DIE that marks the start of the DIEs for this include file. */
5871 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5873 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5874 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5876 new_unit
->die_sib
= old_unit
;
5880 /* Close an include-file CU and reopen the enclosing one. */
5883 pop_compile_unit (dw_die_ref old_unit
)
5885 dw_die_ref new_unit
= old_unit
->die_sib
;
5887 old_unit
->die_sib
= NULL
;
5891 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5892 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5894 /* Calculate the checksum of a location expression. */
5897 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5899 CHECKSUM (loc
->dw_loc_opc
);
5900 CHECKSUM (loc
->dw_loc_oprnd1
);
5901 CHECKSUM (loc
->dw_loc_oprnd2
);
5904 /* Calculate the checksum of an attribute. */
5907 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5909 dw_loc_descr_ref loc
;
5912 CHECKSUM (at
->dw_attr
);
5914 /* We don't care about differences in file numbering. */
5915 if (at
->dw_attr
== DW_AT_decl_file
5916 /* Or that this was compiled with a different compiler snapshot; if
5917 the output is the same, that's what matters. */
5918 || at
->dw_attr
== DW_AT_producer
)
5921 switch (AT_class (at
))
5923 case dw_val_class_const
:
5924 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5926 case dw_val_class_unsigned_const
:
5927 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5929 case dw_val_class_long_long
:
5930 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
5932 case dw_val_class_vec
:
5933 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5935 case dw_val_class_flag
:
5936 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5938 case dw_val_class_str
:
5939 CHECKSUM_STRING (AT_string (at
));
5942 case dw_val_class_addr
:
5944 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5945 CHECKSUM_STRING (XSTR (r
, 0));
5948 case dw_val_class_offset
:
5949 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5952 case dw_val_class_loc
:
5953 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5954 loc_checksum (loc
, ctx
);
5957 case dw_val_class_die_ref
:
5958 die_checksum (AT_ref (at
), ctx
, mark
);
5961 case dw_val_class_fde_ref
:
5962 case dw_val_class_lbl_id
:
5963 case dw_val_class_lineptr
:
5964 case dw_val_class_macptr
:
5972 /* Calculate the checksum of a DIE. */
5975 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5980 /* To avoid infinite recursion. */
5983 CHECKSUM (die
->die_mark
);
5986 die
->die_mark
= ++(*mark
);
5988 CHECKSUM (die
->die_tag
);
5990 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
5991 attr_checksum (a
, ctx
, mark
);
5993 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5994 die_checksum (c
, ctx
, mark
);
5998 #undef CHECKSUM_STRING
6000 /* Do the location expressions look same? */
6002 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6004 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6005 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6006 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6009 /* Do the values look the same? */
6011 same_dw_val_p (dw_val_node
*v1
, dw_val_node
*v2
, int *mark
)
6013 dw_loc_descr_ref loc1
, loc2
;
6016 if (v1
->val_class
!= v2
->val_class
)
6019 switch (v1
->val_class
)
6021 case dw_val_class_const
:
6022 return v1
->v
.val_int
== v2
->v
.val_int
;
6023 case dw_val_class_unsigned_const
:
6024 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6025 case dw_val_class_long_long
:
6026 return v1
->v
.val_long_long
.hi
== v2
->v
.val_long_long
.hi
6027 && v1
->v
.val_long_long
.low
== v2
->v
.val_long_long
.low
;
6028 case dw_val_class_vec
:
6029 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6030 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6032 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6033 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6036 case dw_val_class_flag
:
6037 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6038 case dw_val_class_str
:
6039 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6041 case dw_val_class_addr
:
6042 r1
= v1
->v
.val_addr
;
6043 r2
= v2
->v
.val_addr
;
6044 if (GET_CODE (r1
) != GET_CODE (r2
))
6046 gcc_assert (GET_CODE (r1
) == SYMBOL_REF
);
6047 return !strcmp (XSTR (r1
, 0), XSTR (r2
, 0));
6049 case dw_val_class_offset
:
6050 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6052 case dw_val_class_loc
:
6053 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6055 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6056 if (!same_loc_p (loc1
, loc2
, mark
))
6058 return !loc1
&& !loc2
;
6060 case dw_val_class_die_ref
:
6061 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6063 case dw_val_class_fde_ref
:
6064 case dw_val_class_lbl_id
:
6065 case dw_val_class_lineptr
:
6066 case dw_val_class_macptr
:
6074 /* Do the attributes look the same? */
6077 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6079 if (at1
->dw_attr
!= at2
->dw_attr
)
6082 /* We don't care about differences in file numbering. */
6083 if (at1
->dw_attr
== DW_AT_decl_file
6084 /* Or that this was compiled with a different compiler snapshot; if
6085 the output is the same, that's what matters. */
6086 || at1
->dw_attr
== DW_AT_producer
)
6089 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6092 /* Do the dies look the same? */
6095 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6100 /* To avoid infinite recursion. */
6102 return die1
->die_mark
== die2
->die_mark
;
6103 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6105 if (die1
->die_tag
!= die2
->die_tag
)
6108 for (a1
= die1
->die_attr
, a2
= die2
->die_attr
;
6110 a1
= a1
->dw_attr_next
, a2
= a2
->dw_attr_next
)
6111 if (!same_attr_p (a1
, a2
, mark
))
6116 for (c1
= die1
->die_child
, c2
= die2
->die_child
;
6118 c1
= c1
->die_sib
, c2
= c2
->die_sib
)
6119 if (!same_die_p (c1
, c2
, mark
))
6127 /* Do the dies look the same? Wrapper around same_die_p. */
6130 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6133 int ret
= same_die_p (die1
, die2
, &mark
);
6135 unmark_all_dies (die1
);
6136 unmark_all_dies (die2
);
6141 /* The prefix to attach to symbols on DIEs in the current comdat debug
6143 static char *comdat_symbol_id
;
6145 /* The index of the current symbol within the current comdat CU. */
6146 static unsigned int comdat_symbol_number
;
6148 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6149 children, and set comdat_symbol_id accordingly. */
6152 compute_section_prefix (dw_die_ref unit_die
)
6154 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6155 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6156 char *name
= alloca (strlen (base
) + 64);
6159 unsigned char checksum
[16];
6162 /* Compute the checksum of the DIE, then append part of it as hex digits to
6163 the name filename of the unit. */
6165 md5_init_ctx (&ctx
);
6167 die_checksum (unit_die
, &ctx
, &mark
);
6168 unmark_all_dies (unit_die
);
6169 md5_finish_ctx (&ctx
, checksum
);
6171 sprintf (name
, "%s.", base
);
6172 clean_symbol_name (name
);
6174 p
= name
+ strlen (name
);
6175 for (i
= 0; i
< 4; i
++)
6177 sprintf (p
, "%.2x", checksum
[i
]);
6181 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
6182 comdat_symbol_number
= 0;
6185 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6188 is_type_die (dw_die_ref die
)
6190 switch (die
->die_tag
)
6192 case DW_TAG_array_type
:
6193 case DW_TAG_class_type
:
6194 case DW_TAG_enumeration_type
:
6195 case DW_TAG_pointer_type
:
6196 case DW_TAG_reference_type
:
6197 case DW_TAG_string_type
:
6198 case DW_TAG_structure_type
:
6199 case DW_TAG_subroutine_type
:
6200 case DW_TAG_union_type
:
6201 case DW_TAG_ptr_to_member_type
:
6202 case DW_TAG_set_type
:
6203 case DW_TAG_subrange_type
:
6204 case DW_TAG_base_type
:
6205 case DW_TAG_const_type
:
6206 case DW_TAG_file_type
:
6207 case DW_TAG_packed_type
:
6208 case DW_TAG_volatile_type
:
6209 case DW_TAG_typedef
:
6216 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6217 Basically, we want to choose the bits that are likely to be shared between
6218 compilations (types) and leave out the bits that are specific to individual
6219 compilations (functions). */
6222 is_comdat_die (dw_die_ref c
)
6224 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6225 we do for stabs. The advantage is a greater likelihood of sharing between
6226 objects that don't include headers in the same order (and therefore would
6227 put the base types in a different comdat). jason 8/28/00 */
6229 if (c
->die_tag
== DW_TAG_base_type
)
6232 if (c
->die_tag
== DW_TAG_pointer_type
6233 || c
->die_tag
== DW_TAG_reference_type
6234 || c
->die_tag
== DW_TAG_const_type
6235 || c
->die_tag
== DW_TAG_volatile_type
)
6237 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6239 return t
? is_comdat_die (t
) : 0;
6242 return is_type_die (c
);
6245 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6246 compilation unit. */
6249 is_symbol_die (dw_die_ref c
)
6251 return (is_type_die (c
)
6252 || (get_AT (c
, DW_AT_declaration
)
6253 && !get_AT (c
, DW_AT_specification
)));
6257 gen_internal_sym (const char *prefix
)
6261 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6262 return xstrdup (buf
);
6265 /* Assign symbols to all worthy DIEs under DIE. */
6268 assign_symbol_names (dw_die_ref die
)
6272 if (is_symbol_die (die
))
6274 if (comdat_symbol_id
)
6276 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
6278 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6279 comdat_symbol_id
, comdat_symbol_number
++);
6280 die
->die_symbol
= xstrdup (p
);
6283 die
->die_symbol
= gen_internal_sym ("LDIE");
6286 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6287 assign_symbol_names (c
);
6290 struct cu_hash_table_entry
6293 unsigned min_comdat_num
, max_comdat_num
;
6294 struct cu_hash_table_entry
*next
;
6297 /* Routines to manipulate hash table of CUs. */
6299 htab_cu_hash (const void *of
)
6301 const struct cu_hash_table_entry
*entry
= of
;
6303 return htab_hash_string (entry
->cu
->die_symbol
);
6307 htab_cu_eq (const void *of1
, const void *of2
)
6309 const struct cu_hash_table_entry
*entry1
= of1
;
6310 const struct die_struct
*entry2
= of2
;
6312 return !strcmp (entry1
->cu
->die_symbol
, entry2
->die_symbol
);
6316 htab_cu_del (void *what
)
6318 struct cu_hash_table_entry
*next
, *entry
= what
;
6328 /* Check whether we have already seen this CU and set up SYM_NUM
6331 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6333 struct cu_hash_table_entry dummy
;
6334 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6336 dummy
.max_comdat_num
= 0;
6338 slot
= (struct cu_hash_table_entry
**)
6339 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6343 for (; entry
; last
= entry
, entry
= entry
->next
)
6345 if (same_die_p_wrap (cu
, entry
->cu
))
6351 *sym_num
= entry
->min_comdat_num
;
6355 entry
= XCNEW (struct cu_hash_table_entry
);
6357 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6358 entry
->next
= *slot
;
6364 /* Record SYM_NUM to record of CU in HTABLE. */
6366 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6368 struct cu_hash_table_entry
**slot
, *entry
;
6370 slot
= (struct cu_hash_table_entry
**)
6371 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6375 entry
->max_comdat_num
= sym_num
;
6378 /* Traverse the DIE (which is always comp_unit_die), and set up
6379 additional compilation units for each of the include files we see
6380 bracketed by BINCL/EINCL. */
6383 break_out_includes (dw_die_ref die
)
6386 dw_die_ref unit
= NULL
;
6387 limbo_die_node
*node
, **pnode
;
6388 htab_t cu_hash_table
;
6390 for (ptr
= &(die
->die_child
); *ptr
;)
6392 dw_die_ref c
= *ptr
;
6394 if (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6395 || (unit
&& is_comdat_die (c
)))
6397 /* This DIE is for a secondary CU; remove it from the main one. */
6400 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6402 unit
= push_new_compile_unit (unit
, c
);
6405 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6407 unit
= pop_compile_unit (unit
);
6411 add_child_die (unit
, c
);
6415 /* Leave this DIE in the main CU. */
6416 ptr
= &(c
->die_sib
);
6422 /* We can only use this in debugging, since the frontend doesn't check
6423 to make sure that we leave every include file we enter. */
6427 assign_symbol_names (die
);
6428 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6429 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6435 compute_section_prefix (node
->die
);
6436 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6437 &comdat_symbol_number
);
6438 assign_symbol_names (node
->die
);
6440 *pnode
= node
->next
;
6443 pnode
= &node
->next
;
6444 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6445 comdat_symbol_number
);
6448 htab_delete (cu_hash_table
);
6451 /* Traverse the DIE and add a sibling attribute if it may have the
6452 effect of speeding up access to siblings. To save some space,
6453 avoid generating sibling attributes for DIE's without children. */
6456 add_sibling_attributes (dw_die_ref die
)
6460 if (die
->die_tag
!= DW_TAG_compile_unit
6461 && die
->die_sib
&& die
->die_child
!= NULL
)
6462 /* Add the sibling link to the front of the attribute list. */
6463 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
6465 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6466 add_sibling_attributes (c
);
6469 /* Output all location lists for the DIE and its children. */
6472 output_location_lists (dw_die_ref die
)
6477 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
6478 if (AT_class (d_attr
) == dw_val_class_loc_list
)
6479 output_loc_list (AT_loc_list (d_attr
));
6481 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6482 output_location_lists (c
);
6486 /* The format of each DIE (and its attribute value pairs) is encoded in an
6487 abbreviation table. This routine builds the abbreviation table and assigns
6488 a unique abbreviation id for each abbreviation entry. The children of each
6489 die are visited recursively. */
6492 build_abbrev_table (dw_die_ref die
)
6494 unsigned long abbrev_id
;
6495 unsigned int n_alloc
;
6497 dw_attr_ref d_attr
, a_attr
;
6499 /* Scan the DIE references, and mark as external any that refer to
6500 DIEs from other CUs (i.e. those which are not marked). */
6501 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
6502 if (AT_class (d_attr
) == dw_val_class_die_ref
6503 && AT_ref (d_attr
)->die_mark
== 0)
6505 gcc_assert (AT_ref (d_attr
)->die_symbol
);
6507 set_AT_ref_external (d_attr
, 1);
6510 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6512 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6514 if (abbrev
->die_tag
== die
->die_tag
)
6516 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
6518 a_attr
= abbrev
->die_attr
;
6519 d_attr
= die
->die_attr
;
6521 while (a_attr
!= NULL
&& d_attr
!= NULL
)
6523 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
6524 || (value_format (a_attr
) != value_format (d_attr
)))
6527 a_attr
= a_attr
->dw_attr_next
;
6528 d_attr
= d_attr
->dw_attr_next
;
6531 if (a_attr
== NULL
&& d_attr
== NULL
)
6537 if (abbrev_id
>= abbrev_die_table_in_use
)
6539 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
6541 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
6542 abbrev_die_table
= ggc_realloc (abbrev_die_table
,
6543 sizeof (dw_die_ref
) * n_alloc
);
6545 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
6546 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
6547 abbrev_die_table_allocated
= n_alloc
;
6550 ++abbrev_die_table_in_use
;
6551 abbrev_die_table
[abbrev_id
] = die
;
6554 die
->die_abbrev
= abbrev_id
;
6555 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6556 build_abbrev_table (c
);
6559 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6562 constant_size (long unsigned int value
)
6569 log
= floor_log2 (value
);
6572 log
= 1 << (floor_log2 (log
) + 1);
6577 /* Return the size of a DIE as it is represented in the
6578 .debug_info section. */
6580 static unsigned long
6581 size_of_die (dw_die_ref die
)
6583 unsigned long size
= 0;
6586 size
+= size_of_uleb128 (die
->die_abbrev
);
6587 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6589 switch (AT_class (a
))
6591 case dw_val_class_addr
:
6592 size
+= DWARF2_ADDR_SIZE
;
6594 case dw_val_class_offset
:
6595 size
+= DWARF_OFFSET_SIZE
;
6597 case dw_val_class_loc
:
6599 unsigned long lsize
= size_of_locs (AT_loc (a
));
6602 size
+= constant_size (lsize
);
6606 case dw_val_class_loc_list
:
6607 size
+= DWARF_OFFSET_SIZE
;
6609 case dw_val_class_range_list
:
6610 size
+= DWARF_OFFSET_SIZE
;
6612 case dw_val_class_const
:
6613 size
+= size_of_sleb128 (AT_int (a
));
6615 case dw_val_class_unsigned_const
:
6616 size
+= constant_size (AT_unsigned (a
));
6618 case dw_val_class_long_long
:
6619 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
6621 case dw_val_class_vec
:
6622 size
+= 1 + (a
->dw_attr_val
.v
.val_vec
.length
6623 * a
->dw_attr_val
.v
.val_vec
.elt_size
); /* block */
6625 case dw_val_class_flag
:
6628 case dw_val_class_die_ref
:
6629 if (AT_ref_external (a
))
6630 size
+= DWARF2_ADDR_SIZE
;
6632 size
+= DWARF_OFFSET_SIZE
;
6634 case dw_val_class_fde_ref
:
6635 size
+= DWARF_OFFSET_SIZE
;
6637 case dw_val_class_lbl_id
:
6638 size
+= DWARF2_ADDR_SIZE
;
6640 case dw_val_class_lineptr
:
6641 case dw_val_class_macptr
:
6642 size
+= DWARF_OFFSET_SIZE
;
6644 case dw_val_class_str
:
6645 if (AT_string_form (a
) == DW_FORM_strp
)
6646 size
+= DWARF_OFFSET_SIZE
;
6648 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
6658 /* Size the debugging information associated with a given DIE. Visits the
6659 DIE's children recursively. Updates the global variable next_die_offset, on
6660 each time through. Uses the current value of next_die_offset to update the
6661 die_offset field in each DIE. */
6664 calc_die_sizes (dw_die_ref die
)
6668 die
->die_offset
= next_die_offset
;
6669 next_die_offset
+= size_of_die (die
);
6671 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6674 if (die
->die_child
!= NULL
)
6675 /* Count the null byte used to terminate sibling lists. */
6676 next_die_offset
+= 1;
6679 /* Set the marks for a die and its children. We do this so
6680 that we know whether or not a reference needs to use FORM_ref_addr; only
6681 DIEs in the same CU will be marked. We used to clear out the offset
6682 and use that as the flag, but ran into ordering problems. */
6685 mark_dies (dw_die_ref die
)
6689 gcc_assert (!die
->die_mark
);
6692 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6696 /* Clear the marks for a die and its children. */
6699 unmark_dies (dw_die_ref die
)
6703 gcc_assert (die
->die_mark
);
6706 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6710 /* Clear the marks for a die, its children and referred dies. */
6713 unmark_all_dies (dw_die_ref die
)
6722 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6723 unmark_all_dies (c
);
6725 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
6726 if (AT_class (a
) == dw_val_class_die_ref
)
6727 unmark_all_dies (AT_ref (a
));
6730 /* Return the size of the .debug_pubnames table generated for the
6731 compilation unit. */
6733 static unsigned long
6734 size_of_pubnames (void)
6739 size
= DWARF_PUBNAMES_HEADER_SIZE
;
6740 for (i
= 0; i
< pubname_table_in_use
; i
++)
6742 pubname_ref p
= &pubname_table
[i
];
6743 size
+= DWARF_OFFSET_SIZE
+ strlen (p
->name
) + 1;
6746 size
+= DWARF_OFFSET_SIZE
;
6750 /* Return the size of the information in the .debug_aranges section. */
6752 static unsigned long
6753 size_of_aranges (void)
6757 size
= DWARF_ARANGES_HEADER_SIZE
;
6759 /* Count the address/length pair for this compilation unit. */
6760 size
+= 2 * DWARF2_ADDR_SIZE
;
6761 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
6763 /* Count the two zero words used to terminated the address range table. */
6764 size
+= 2 * DWARF2_ADDR_SIZE
;
6768 /* Select the encoding of an attribute value. */
6770 static enum dwarf_form
6771 value_format (dw_attr_ref a
)
6773 switch (a
->dw_attr_val
.val_class
)
6775 case dw_val_class_addr
:
6776 return DW_FORM_addr
;
6777 case dw_val_class_range_list
:
6778 case dw_val_class_offset
:
6779 switch (DWARF_OFFSET_SIZE
)
6782 return DW_FORM_data4
;
6784 return DW_FORM_data8
;
6788 case dw_val_class_loc_list
:
6789 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6790 .debug_loc section */
6791 return DW_FORM_data4
;
6792 case dw_val_class_loc
:
6793 switch (constant_size (size_of_locs (AT_loc (a
))))
6796 return DW_FORM_block1
;
6798 return DW_FORM_block2
;
6802 case dw_val_class_const
:
6803 return DW_FORM_sdata
;
6804 case dw_val_class_unsigned_const
:
6805 switch (constant_size (AT_unsigned (a
)))
6808 return DW_FORM_data1
;
6810 return DW_FORM_data2
;
6812 return DW_FORM_data4
;
6814 return DW_FORM_data8
;
6818 case dw_val_class_long_long
:
6819 return DW_FORM_block1
;
6820 case dw_val_class_vec
:
6821 return DW_FORM_block1
;
6822 case dw_val_class_flag
:
6823 return DW_FORM_flag
;
6824 case dw_val_class_die_ref
:
6825 if (AT_ref_external (a
))
6826 return DW_FORM_ref_addr
;
6829 case dw_val_class_fde_ref
:
6830 return DW_FORM_data
;
6831 case dw_val_class_lbl_id
:
6832 return DW_FORM_addr
;
6833 case dw_val_class_lineptr
:
6834 case dw_val_class_macptr
:
6835 return DW_FORM_data
;
6836 case dw_val_class_str
:
6837 return AT_string_form (a
);
6844 /* Output the encoding of an attribute value. */
6847 output_value_format (dw_attr_ref a
)
6849 enum dwarf_form form
= value_format (a
);
6851 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
6854 /* Output the .debug_abbrev section which defines the DIE abbreviation
6858 output_abbrev_section (void)
6860 unsigned long abbrev_id
;
6864 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6866 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6868 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
6869 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
6870 dwarf_tag_name (abbrev
->die_tag
));
6872 if (abbrev
->die_child
!= NULL
)
6873 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
6875 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
6877 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
6878 a_attr
= a_attr
->dw_attr_next
)
6880 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
6881 dwarf_attr_name (a_attr
->dw_attr
));
6882 output_value_format (a_attr
);
6885 dw2_asm_output_data (1, 0, NULL
);
6886 dw2_asm_output_data (1, 0, NULL
);
6889 /* Terminate the table. */
6890 dw2_asm_output_data (1, 0, NULL
);
6893 /* Output a symbol we can use to refer to this DIE from another CU. */
6896 output_die_symbol (dw_die_ref die
)
6898 char *sym
= die
->die_symbol
;
6903 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
6904 /* We make these global, not weak; if the target doesn't support
6905 .linkonce, it doesn't support combining the sections, so debugging
6907 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
6909 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
6912 /* Return a new location list, given the begin and end range, and the
6913 expression. gensym tells us whether to generate a new internal symbol for
6914 this location list node, which is done for the head of the list only. */
6916 static inline dw_loc_list_ref
6917 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
6918 const char *section
, unsigned int gensym
)
6920 dw_loc_list_ref retlist
= ggc_alloc_cleared (sizeof (dw_loc_list_node
));
6922 retlist
->begin
= begin
;
6924 retlist
->expr
= expr
;
6925 retlist
->section
= section
;
6927 retlist
->ll_symbol
= gen_internal_sym ("LLST");
6932 /* Add a location description expression to a location list. */
6935 add_loc_descr_to_loc_list (dw_loc_list_ref
*list_head
, dw_loc_descr_ref descr
,
6936 const char *begin
, const char *end
,
6937 const char *section
)
6941 /* Find the end of the chain. */
6942 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
6945 /* Add a new location list node to the list. */
6946 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
6950 dwarf2out_switch_text_section (void)
6956 fde
= &fde_table
[fde_table_in_use
- 1];
6957 fde
->dw_fde_switched_sections
= true;
6958 fde
->dw_fde_hot_section_label
= cfun
->hot_section_label
;
6959 fde
->dw_fde_hot_section_end_label
= cfun
->hot_section_end_label
;
6960 fde
->dw_fde_unlikely_section_label
= cfun
->cold_section_label
;
6961 fde
->dw_fde_unlikely_section_end_label
= cfun
->cold_section_end_label
;
6962 have_multiple_function_sections
= true;
6965 /* Output the location list given to us. */
6968 output_loc_list (dw_loc_list_ref list_head
)
6970 dw_loc_list_ref curr
= list_head
;
6972 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
6974 /* Walk the location list, and output each range + expression. */
6975 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
6978 if (!have_multiple_function_sections
)
6980 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
6981 "Location list begin address (%s)",
6982 list_head
->ll_symbol
);
6983 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
6984 "Location list end address (%s)",
6985 list_head
->ll_symbol
);
6989 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
6990 "Location list begin address (%s)",
6991 list_head
->ll_symbol
);
6992 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
6993 "Location list end address (%s)",
6994 list_head
->ll_symbol
);
6996 size
= size_of_locs (curr
->expr
);
6998 /* Output the block length for this list of location operations. */
6999 gcc_assert (size
<= 0xffff);
7000 dw2_asm_output_data (2, size
, "%s", "Location expression size");
7002 output_loc_sequence (curr
->expr
);
7005 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7006 "Location list terminator begin (%s)",
7007 list_head
->ll_symbol
);
7008 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7009 "Location list terminator end (%s)",
7010 list_head
->ll_symbol
);
7013 /* Output the DIE and its attributes. Called recursively to generate
7014 the definitions of each child DIE. */
7017 output_die (dw_die_ref die
)
7023 /* If someone in another CU might refer to us, set up a symbol for
7024 them to point to. */
7025 if (die
->die_symbol
)
7026 output_die_symbol (die
);
7028 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
7029 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
7031 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
7033 const char *name
= dwarf_attr_name (a
->dw_attr
);
7035 switch (AT_class (a
))
7037 case dw_val_class_addr
:
7038 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
7041 case dw_val_class_offset
:
7042 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
7046 case dw_val_class_range_list
:
7048 char *p
= strchr (ranges_section_label
, '\0');
7050 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
7051 a
->dw_attr_val
.v
.val_offset
);
7052 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
7053 debug_ranges_section
, "%s", name
);
7058 case dw_val_class_loc
:
7059 size
= size_of_locs (AT_loc (a
));
7061 /* Output the block length for this list of location operations. */
7062 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
7064 output_loc_sequence (AT_loc (a
));
7067 case dw_val_class_const
:
7068 /* ??? It would be slightly more efficient to use a scheme like is
7069 used for unsigned constants below, but gdb 4.x does not sign
7070 extend. Gdb 5.x does sign extend. */
7071 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
7074 case dw_val_class_unsigned_const
:
7075 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
7076 AT_unsigned (a
), "%s", name
);
7079 case dw_val_class_long_long
:
7081 unsigned HOST_WIDE_INT first
, second
;
7083 dw2_asm_output_data (1,
7084 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
7087 if (WORDS_BIG_ENDIAN
)
7089 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
7090 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
7094 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
7095 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
7098 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
7099 first
, "long long constant");
7100 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
7105 case dw_val_class_vec
:
7107 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
7108 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
7112 dw2_asm_output_data (1, len
* elt_size
, "%s", name
);
7113 if (elt_size
> sizeof (HOST_WIDE_INT
))
7118 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
7121 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
7122 "fp or vector constant word %u", i
);
7126 case dw_val_class_flag
:
7127 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
7130 case dw_val_class_loc_list
:
7132 char *sym
= AT_loc_list (a
)->ll_symbol
;
7135 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
7140 case dw_val_class_die_ref
:
7141 if (AT_ref_external (a
))
7143 char *sym
= AT_ref (a
)->die_symbol
;
7146 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, debug_info_section
,
7151 gcc_assert (AT_ref (a
)->die_offset
);
7152 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
7157 case dw_val_class_fde_ref
:
7161 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
7162 a
->dw_attr_val
.v
.val_fde_index
* 2);
7163 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
7168 case dw_val_class_lbl_id
:
7169 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
7172 case dw_val_class_lineptr
:
7173 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
7174 debug_line_section
, "%s", name
);
7177 case dw_val_class_macptr
:
7178 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
7179 debug_macinfo_section
, "%s", name
);
7182 case dw_val_class_str
:
7183 if (AT_string_form (a
) == DW_FORM_strp
)
7184 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
7185 a
->dw_attr_val
.v
.val_str
->label
,
7187 "%s: \"%s\"", name
, AT_string (a
));
7189 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
7197 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
7200 /* Add null byte to terminate sibling list. */
7201 if (die
->die_child
!= NULL
)
7202 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7206 /* Output the compilation unit that appears at the beginning of the
7207 .debug_info section, and precedes the DIE descriptions. */
7210 output_compilation_unit_header (void)
7212 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7213 dw2_asm_output_data (4, 0xffffffff,
7214 "Initial length escape value indicating 64-bit DWARF extension");
7215 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
7216 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
7217 "Length of Compilation Unit Info");
7218 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
7219 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
7220 debug_abbrev_section
,
7221 "Offset Into Abbrev. Section");
7222 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
7225 /* Output the compilation unit DIE and its children. */
7228 output_comp_unit (dw_die_ref die
, int output_if_empty
)
7230 const char *secname
;
7233 /* Unless we are outputting main CU, we may throw away empty ones. */
7234 if (!output_if_empty
&& die
->die_child
== NULL
)
7237 /* Even if there are no children of this DIE, we must output the information
7238 about the compilation unit. Otherwise, on an empty translation unit, we
7239 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7240 will then complain when examining the file. First mark all the DIEs in
7241 this CU so we know which get local refs. */
7244 build_abbrev_table (die
);
7246 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7247 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7248 calc_die_sizes (die
);
7250 oldsym
= die
->die_symbol
;
7253 tmp
= alloca (strlen (oldsym
) + 24);
7255 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
7257 die
->die_symbol
= NULL
;
7258 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
7261 switch_to_section (debug_info_section
);
7263 /* Output debugging information. */
7264 output_compilation_unit_header ();
7267 /* Leave the marks on the main CU, so we can check them in
7272 die
->die_symbol
= oldsym
;
7276 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
7277 output of lang_hooks.decl_printable_name for C++ looks like
7278 "A::f(int)". Let's drop the argument list, and maybe the scope. */
7281 dwarf2_name (tree decl
, int scope
)
7283 return lang_hooks
.decl_printable_name (decl
, scope
? 1 : 0);
7286 /* Add a new entry to .debug_pubnames if appropriate. */
7289 add_pubname (tree decl
, dw_die_ref die
)
7293 if (! TREE_PUBLIC (decl
))
7296 if (pubname_table_in_use
== pubname_table_allocated
)
7298 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
7300 = ggc_realloc (pubname_table
,
7301 (pubname_table_allocated
* sizeof (pubname_entry
)));
7302 memset (pubname_table
+ pubname_table_in_use
, 0,
7303 PUBNAME_TABLE_INCREMENT
* sizeof (pubname_entry
));
7306 p
= &pubname_table
[pubname_table_in_use
++];
7308 p
->name
= xstrdup (dwarf2_name (decl
, 1));
7311 /* Output the public names table used to speed up access to externally
7312 visible names. For now, only generate entries for externally
7313 visible procedures. */
7316 output_pubnames (void)
7319 unsigned long pubnames_length
= size_of_pubnames ();
7321 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7322 dw2_asm_output_data (4, 0xffffffff,
7323 "Initial length escape value indicating 64-bit DWARF extension");
7324 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
7325 "Length of Public Names Info");
7326 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7327 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
7329 "Offset of Compilation Unit Info");
7330 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
7331 "Compilation Unit Length");
7333 for (i
= 0; i
< pubname_table_in_use
; i
++)
7335 pubname_ref pub
= &pubname_table
[i
];
7337 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7338 gcc_assert (pub
->die
->die_mark
);
7340 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
7343 dw2_asm_output_nstring (pub
->name
, -1, "external name");
7346 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
7349 /* Add a new entry to .debug_aranges if appropriate. */
7352 add_arange (tree decl
, dw_die_ref die
)
7354 if (! DECL_SECTION_NAME (decl
))
7357 if (arange_table_in_use
== arange_table_allocated
)
7359 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
7360 arange_table
= ggc_realloc (arange_table
,
7361 (arange_table_allocated
7362 * sizeof (dw_die_ref
)));
7363 memset (arange_table
+ arange_table_in_use
, 0,
7364 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
7367 arange_table
[arange_table_in_use
++] = die
;
7370 /* Output the information that goes into the .debug_aranges table.
7371 Namely, define the beginning and ending address range of the
7372 text section generated for this compilation unit. */
7375 output_aranges (void)
7378 unsigned long aranges_length
= size_of_aranges ();
7380 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7381 dw2_asm_output_data (4, 0xffffffff,
7382 "Initial length escape value indicating 64-bit DWARF extension");
7383 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
7384 "Length of Address Ranges Info");
7385 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7386 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
7388 "Offset of Compilation Unit Info");
7389 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
7390 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7392 /* We need to align to twice the pointer size here. */
7393 if (DWARF_ARANGES_PAD_SIZE
)
7395 /* Pad using a 2 byte words so that padding is correct for any
7397 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7398 2 * DWARF2_ADDR_SIZE
);
7399 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
7400 dw2_asm_output_data (2, 0, NULL
);
7403 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
7404 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
7405 text_section_label
, "Length");
7406 if (flag_reorder_blocks_and_partition
)
7408 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
7410 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
7411 cold_text_section_label
, "Length");
7414 for (i
= 0; i
< arange_table_in_use
; i
++)
7416 dw_die_ref die
= arange_table
[i
];
7418 /* We shouldn't see aranges for DIEs outside of the main CU. */
7419 gcc_assert (die
->die_mark
);
7421 if (die
->die_tag
== DW_TAG_subprogram
)
7423 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
7425 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
7426 get_AT_low_pc (die
), "Length");
7430 /* A static variable; extract the symbol from DW_AT_location.
7431 Note that this code isn't currently hit, as we only emit
7432 aranges for functions (jason 9/23/99). */
7433 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
7434 dw_loc_descr_ref loc
;
7436 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
7439 gcc_assert (loc
->dw_loc_opc
== DW_OP_addr
);
7441 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
7442 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
7443 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
7444 get_AT_unsigned (die
, DW_AT_byte_size
),
7449 /* Output the terminator words. */
7450 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7451 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7454 /* Add a new entry to .debug_ranges. Return the offset at which it
7458 add_ranges (tree block
)
7460 unsigned int in_use
= ranges_table_in_use
;
7462 if (in_use
== ranges_table_allocated
)
7464 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
7466 = ggc_realloc (ranges_table
, (ranges_table_allocated
7467 * sizeof (struct dw_ranges_struct
)));
7468 memset (ranges_table
+ ranges_table_in_use
, 0,
7469 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
7472 ranges_table
[in_use
].block_num
= (block
? BLOCK_NUMBER (block
) : 0);
7473 ranges_table_in_use
= in_use
+ 1;
7475 return in_use
* 2 * DWARF2_ADDR_SIZE
;
7479 output_ranges (void)
7482 static const char *const start_fmt
= "Offset 0x%x";
7483 const char *fmt
= start_fmt
;
7485 for (i
= 0; i
< ranges_table_in_use
; i
++)
7487 int block_num
= ranges_table
[i
].block_num
;
7491 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7492 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7494 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
7495 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
7497 /* If all code is in the text section, then the compilation
7498 unit base address defaults to DW_AT_low_pc, which is the
7499 base of the text section. */
7500 if (!have_multiple_function_sections
)
7502 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
7504 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7505 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
7506 text_section_label
, NULL
);
7509 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
7510 compilation unit base address to zero, which allows us to
7511 use absolute addresses, and not worry about whether the
7512 target supports cross-section arithmetic. */
7515 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
7516 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7517 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
7524 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7525 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7531 /* Data structure containing information about input files. */
7534 char *path
; /* Complete file name. */
7535 char *fname
; /* File name part. */
7536 int length
; /* Length of entire string. */
7537 int file_idx
; /* Index in input file table. */
7538 int dir_idx
; /* Index in directory table. */
7541 /* Data structure containing information about directories with source
7545 char *path
; /* Path including directory name. */
7546 int length
; /* Path length. */
7547 int prefix
; /* Index of directory entry which is a prefix. */
7548 int count
; /* Number of files in this directory. */
7549 int dir_idx
; /* Index of directory used as base. */
7550 int used
; /* Used in the end? */
7553 /* Callback function for file_info comparison. We sort by looking at
7554 the directories in the path. */
7557 file_info_cmp (const void *p1
, const void *p2
)
7559 const struct file_info
*s1
= p1
;
7560 const struct file_info
*s2
= p2
;
7564 /* Take care of file names without directories. We need to make sure that
7565 we return consistent values to qsort since some will get confused if
7566 we return the same value when identical operands are passed in opposite
7567 orders. So if neither has a directory, return 0 and otherwise return
7568 1 or -1 depending on which one has the directory. */
7569 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
7570 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
7572 cp1
= (unsigned char *) s1
->path
;
7573 cp2
= (unsigned char *) s2
->path
;
7579 /* Reached the end of the first path? If so, handle like above. */
7580 if ((cp1
== (unsigned char *) s1
->fname
)
7581 || (cp2
== (unsigned char *) s2
->fname
))
7582 return ((cp2
== (unsigned char *) s2
->fname
)
7583 - (cp1
== (unsigned char *) s1
->fname
));
7585 /* Character of current path component the same? */
7586 else if (*cp1
!= *cp2
)
7591 /* Output the directory table and the file name table. We try to minimize
7592 the total amount of memory needed. A heuristic is used to avoid large
7593 slowdowns with many input files. */
7596 output_file_names (void)
7598 struct file_info
*files
;
7599 struct dir_info
*dirs
;
7608 /* Handle the case where file_table is empty. */
7609 if (VARRAY_ACTIVE_SIZE (file_table
) <= 1)
7611 dw2_asm_output_data (1, 0, "End directory table");
7612 dw2_asm_output_data (1, 0, "End file name table");
7616 /* Allocate the various arrays we need. */
7617 files
= alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (struct file_info
));
7618 dirs
= alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (struct dir_info
));
7620 /* Sort the file names. */
7621 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7625 /* Skip all leading "./". */
7626 f
= VARRAY_CHAR_PTR (file_table
, i
);
7627 while (f
[0] == '.' && f
[1] == '/')
7630 /* Create a new array entry. */
7632 files
[i
].length
= strlen (f
);
7633 files
[i
].file_idx
= i
;
7635 /* Search for the file name part. */
7636 f
= strrchr (f
, '/');
7637 files
[i
].fname
= f
== NULL
? files
[i
].path
: f
+ 1;
7640 qsort (files
+ 1, VARRAY_ACTIVE_SIZE (file_table
) - 1,
7641 sizeof (files
[0]), file_info_cmp
);
7643 /* Find all the different directories used. */
7644 dirs
[0].path
= files
[1].path
;
7645 dirs
[0].length
= files
[1].fname
- files
[1].path
;
7646 dirs
[0].prefix
= -1;
7648 dirs
[0].dir_idx
= 0;
7650 files
[1].dir_idx
= 0;
7653 for (i
= 2; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7654 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
7655 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
7656 dirs
[ndirs
- 1].length
) == 0)
7658 /* Same directory as last entry. */
7659 files
[i
].dir_idx
= ndirs
- 1;
7660 ++dirs
[ndirs
- 1].count
;
7666 /* This is a new directory. */
7667 dirs
[ndirs
].path
= files
[i
].path
;
7668 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
7669 dirs
[ndirs
].count
= 1;
7670 dirs
[ndirs
].dir_idx
= ndirs
;
7671 dirs
[ndirs
].used
= 0;
7672 files
[i
].dir_idx
= ndirs
;
7674 /* Search for a prefix. */
7675 dirs
[ndirs
].prefix
= -1;
7676 for (j
= 0; j
< ndirs
; j
++)
7677 if (dirs
[j
].length
< dirs
[ndirs
].length
7678 && dirs
[j
].length
> 1
7679 && (dirs
[ndirs
].prefix
== -1
7680 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
7681 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
7682 dirs
[ndirs
].prefix
= j
;
7687 /* Now to the actual work. We have to find a subset of the directories which
7688 allow expressing the file name using references to the directory table
7689 with the least amount of characters. We do not do an exhaustive search
7690 where we would have to check out every combination of every single
7691 possible prefix. Instead we use a heuristic which provides nearly optimal
7692 results in most cases and never is much off. */
7693 saved
= alloca (ndirs
* sizeof (int));
7694 savehere
= alloca (ndirs
* sizeof (int));
7696 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
7697 for (i
= 0; i
< ndirs
; i
++)
7702 /* We can always save some space for the current directory. But this
7703 does not mean it will be enough to justify adding the directory. */
7704 savehere
[i
] = dirs
[i
].length
;
7705 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
7707 for (j
= i
+ 1; j
< ndirs
; j
++)
7710 if (saved
[j
] < dirs
[i
].length
)
7712 /* Determine whether the dirs[i] path is a prefix of the
7717 while (k
!= -1 && k
!= (int) i
)
7722 /* Yes it is. We can possibly safe some memory but
7723 writing the filenames in dirs[j] relative to
7725 savehere
[j
] = dirs
[i
].length
;
7726 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
7731 /* Check whether we can safe enough to justify adding the dirs[i]
7733 if (total
> dirs
[i
].length
+ 1)
7735 /* It's worthwhile adding. */
7736 for (j
= i
; j
< ndirs
; j
++)
7737 if (savehere
[j
] > 0)
7739 /* Remember how much we saved for this directory so far. */
7740 saved
[j
] = savehere
[j
];
7742 /* Remember the prefix directory. */
7743 dirs
[j
].dir_idx
= i
;
7748 /* We have to emit them in the order they appear in the file_table array
7749 since the index is used in the debug info generation. To do this
7750 efficiently we generate a back-mapping of the indices first. */
7751 backmap
= alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (int));
7752 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7754 backmap
[files
[i
].file_idx
] = i
;
7756 /* Mark this directory as used. */
7757 dirs
[dirs
[files
[i
].dir_idx
].dir_idx
].used
= 1;
7760 /* That was it. We are ready to emit the information. First emit the
7761 directory name table. We have to make sure the first actually emitted
7762 directory name has index one; zero is reserved for the current working
7763 directory. Make sure we do not confuse these indices with the one for the
7764 constructed table (even though most of the time they are identical). */
7766 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
7767 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
7768 if (dirs
[i
].used
!= 0)
7770 dirs
[i
].used
= idx
++;
7771 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
7772 "Directory Entry: 0x%x", dirs
[i
].used
);
7775 dw2_asm_output_data (1, 0, "End directory table");
7777 /* Correct the index for the current working directory entry if it
7779 if (idx_offset
== 0)
7782 /* Now write all the file names. */
7783 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7785 int file_idx
= backmap
[i
];
7786 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
7788 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
7789 "File Entry: 0x%lx", (unsigned long) i
);
7791 /* Include directory index. */
7792 dw2_asm_output_data_uleb128 (dirs
[dir_idx
].used
, NULL
);
7794 /* Modification time. */
7795 dw2_asm_output_data_uleb128 (0, NULL
);
7797 /* File length in bytes. */
7798 dw2_asm_output_data_uleb128 (0, NULL
);
7801 dw2_asm_output_data (1, 0, "End file name table");
7805 /* Output the source line number correspondence information. This
7806 information goes into the .debug_line section. */
7809 output_line_info (void)
7811 char l1
[20], l2
[20], p1
[20], p2
[20];
7812 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7813 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7816 unsigned long lt_index
;
7817 unsigned long current_line
;
7820 unsigned long current_file
;
7821 unsigned long function
;
7823 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
7824 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
7825 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
7826 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
7828 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7829 dw2_asm_output_data (4, 0xffffffff,
7830 "Initial length escape value indicating 64-bit DWARF extension");
7831 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
7832 "Length of Source Line Info");
7833 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
7835 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7836 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
7837 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
7839 /* Define the architecture-dependent minimum instruction length (in
7840 bytes). In this implementation of DWARF, this field is used for
7841 information purposes only. Since GCC generates assembly language,
7842 we have no a priori knowledge of how many instruction bytes are
7843 generated for each source line, and therefore can use only the
7844 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7845 commands. Accordingly, we fix this as `1', which is "correct
7846 enough" for all architectures, and don't let the target override. */
7847 dw2_asm_output_data (1, 1,
7848 "Minimum Instruction Length");
7850 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
7851 "Default is_stmt_start flag");
7852 dw2_asm_output_data (1, DWARF_LINE_BASE
,
7853 "Line Base Value (Special Opcodes)");
7854 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
7855 "Line Range Value (Special Opcodes)");
7856 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
7857 "Special Opcode Base");
7859 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
7863 case DW_LNS_advance_pc
:
7864 case DW_LNS_advance_line
:
7865 case DW_LNS_set_file
:
7866 case DW_LNS_set_column
:
7867 case DW_LNS_fixed_advance_pc
:
7875 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
7879 /* Write out the information about the files we use. */
7880 output_file_names ();
7881 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
7883 /* We used to set the address register to the first location in the text
7884 section here, but that didn't accomplish anything since we already
7885 have a line note for the opening brace of the first function. */
7887 /* Generate the line number to PC correspondence table, encoded as
7888 a series of state machine operations. */
7892 if (cfun
&& in_cold_section_p
)
7893 strcpy (prev_line_label
, cfun
->cold_section_label
);
7895 strcpy (prev_line_label
, text_section_label
);
7896 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
7898 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
7901 /* Disable this optimization for now; GDB wants to see two line notes
7902 at the beginning of a function so it can find the end of the
7905 /* Don't emit anything for redundant notes. Just updating the
7906 address doesn't accomplish anything, because we already assume
7907 that anything after the last address is this line. */
7908 if (line_info
->dw_line_num
== current_line
7909 && line_info
->dw_file_num
== current_file
)
7913 /* Emit debug info for the address of the current line.
7915 Unfortunately, we have little choice here currently, and must always
7916 use the most general form. GCC does not know the address delta
7917 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7918 attributes which will give an upper bound on the address range. We
7919 could perhaps use length attributes to determine when it is safe to
7920 use DW_LNS_fixed_advance_pc. */
7922 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
7925 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7926 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7927 "DW_LNS_fixed_advance_pc");
7928 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7932 /* This can handle any delta. This takes
7933 4+DWARF2_ADDR_SIZE bytes. */
7934 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7935 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7936 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7937 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7940 strcpy (prev_line_label
, line_label
);
7942 /* Emit debug info for the source file of the current line, if
7943 different from the previous line. */
7944 if (line_info
->dw_file_num
!= current_file
)
7946 current_file
= line_info
->dw_file_num
;
7947 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7948 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7949 VARRAY_CHAR_PTR (file_table
,
7953 /* Emit debug info for the current line number, choosing the encoding
7954 that uses the least amount of space. */
7955 if (line_info
->dw_line_num
!= current_line
)
7957 line_offset
= line_info
->dw_line_num
- current_line
;
7958 line_delta
= line_offset
- DWARF_LINE_BASE
;
7959 current_line
= line_info
->dw_line_num
;
7960 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7961 /* This can handle deltas from -10 to 234, using the current
7962 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7964 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7965 "line %lu", current_line
);
7968 /* This can handle any delta. This takes at least 4 bytes,
7969 depending on the value being encoded. */
7970 dw2_asm_output_data (1, DW_LNS_advance_line
,
7971 "advance to line %lu", current_line
);
7972 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7973 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7977 /* We still need to start a new row, so output a copy insn. */
7978 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7981 /* Emit debug info for the address of the end of the function. */
7984 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7985 "DW_LNS_fixed_advance_pc");
7986 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
7990 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7991 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7992 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7993 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
7996 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7997 dw2_asm_output_data_uleb128 (1, NULL
);
7998 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
8003 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
8005 dw_separate_line_info_ref line_info
8006 = &separate_line_info_table
[lt_index
];
8009 /* Don't emit anything for redundant notes. */
8010 if (line_info
->dw_line_num
== current_line
8011 && line_info
->dw_file_num
== current_file
8012 && line_info
->function
== function
)
8016 /* Emit debug info for the address of the current line. If this is
8017 a new function, or the first line of a function, then we need
8018 to handle it differently. */
8019 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
8021 if (function
!= line_info
->function
)
8023 function
= line_info
->function
;
8025 /* Set the address register to the first line in the function. */
8026 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8027 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8028 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8029 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8033 /* ??? See the DW_LNS_advance_pc comment above. */
8036 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
8037 "DW_LNS_fixed_advance_pc");
8038 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
8042 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8043 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8044 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8045 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8049 strcpy (prev_line_label
, line_label
);
8051 /* Emit debug info for the source file of the current line, if
8052 different from the previous line. */
8053 if (line_info
->dw_file_num
!= current_file
)
8055 current_file
= line_info
->dw_file_num
;
8056 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
8057 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
8058 VARRAY_CHAR_PTR (file_table
,
8062 /* Emit debug info for the current line number, choosing the encoding
8063 that uses the least amount of space. */
8064 if (line_info
->dw_line_num
!= current_line
)
8066 line_offset
= line_info
->dw_line_num
- current_line
;
8067 line_delta
= line_offset
- DWARF_LINE_BASE
;
8068 current_line
= line_info
->dw_line_num
;
8069 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
8070 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
8071 "line %lu", current_line
);
8074 dw2_asm_output_data (1, DW_LNS_advance_line
,
8075 "advance to line %lu", current_line
);
8076 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
8077 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8081 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8089 /* If we're done with a function, end its sequence. */
8090 if (lt_index
== separate_line_info_table_in_use
8091 || separate_line_info_table
[lt_index
].function
!= function
)
8096 /* Emit debug info for the address of the end of the function. */
8097 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
8100 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
8101 "DW_LNS_fixed_advance_pc");
8102 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
8106 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8107 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8108 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8109 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8112 /* Output the marker for the end of this sequence. */
8113 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8114 dw2_asm_output_data_uleb128 (1, NULL
);
8115 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
8119 /* Output the marker for the end of the line number info. */
8120 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
8123 /* Given a pointer to a tree node for some base type, return a pointer to
8124 a DIE that describes the given type.
8126 This routine must only be called for GCC type nodes that correspond to
8127 Dwarf base (fundamental) types. */
8130 base_type_die (tree type
)
8132 dw_die_ref base_type_result
;
8133 enum dwarf_type encoding
;
8135 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
8138 switch (TREE_CODE (type
))
8141 if (TYPE_STRING_FLAG (type
))
8143 if (TYPE_UNSIGNED (type
))
8144 encoding
= DW_ATE_unsigned_char
;
8146 encoding
= DW_ATE_signed_char
;
8148 else if (TYPE_UNSIGNED (type
))
8149 encoding
= DW_ATE_unsigned
;
8151 encoding
= DW_ATE_signed
;
8155 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
8156 encoding
= DW_ATE_decimal_float
;
8158 encoding
= DW_ATE_float
;
8161 /* Dwarf2 doesn't know anything about complex ints, so use
8162 a user defined type for it. */
8164 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
8165 encoding
= DW_ATE_complex_float
;
8167 encoding
= DW_ATE_lo_user
;
8171 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8172 encoding
= DW_ATE_boolean
;
8176 /* No other TREE_CODEs are Dwarf fundamental types. */
8180 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
8182 /* This probably indicates a bug. */
8183 if (! TYPE_NAME (type
))
8184 add_name_attribute (base_type_result
, "__unknown__");
8186 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
8187 int_size_in_bytes (type
));
8188 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
8190 return base_type_result
;
8193 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
8194 the Dwarf "root" type for the given input type. The Dwarf "root" type of
8195 a given type is generally the same as the given type, except that if the
8196 given type is a pointer or reference type, then the root type of the given
8197 type is the root type of the "basis" type for the pointer or reference
8198 type. (This definition of the "root" type is recursive.) Also, the root
8199 type of a `const' qualified type or a `volatile' qualified type is the
8200 root type of the given type without the qualifiers. */
8203 root_type (tree type
)
8205 if (TREE_CODE (type
) == ERROR_MARK
)
8206 return error_mark_node
;
8208 switch (TREE_CODE (type
))
8211 return error_mark_node
;
8214 case REFERENCE_TYPE
:
8215 return type_main_variant (root_type (TREE_TYPE (type
)));
8218 return type_main_variant (type
);
8222 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8223 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8226 is_base_type (tree type
)
8228 switch (TREE_CODE (type
))
8241 case QUAL_UNION_TYPE
:
8246 case REFERENCE_TYPE
:
8259 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8260 node, return the size in bits for the type if it is a constant, or else
8261 return the alignment for the type if the type's size is not constant, or
8262 else return BITS_PER_WORD if the type actually turns out to be an
8265 static inline unsigned HOST_WIDE_INT
8266 simple_type_size_in_bits (tree type
)
8268 if (TREE_CODE (type
) == ERROR_MARK
)
8269 return BITS_PER_WORD
;
8270 else if (TYPE_SIZE (type
) == NULL_TREE
)
8272 else if (host_integerp (TYPE_SIZE (type
), 1))
8273 return tree_low_cst (TYPE_SIZE (type
), 1);
8275 return TYPE_ALIGN (type
);
8278 /* Return true if the debug information for the given type should be
8279 emitted as a subrange type. */
8282 is_subrange_type (tree type
)
8284 tree subtype
= TREE_TYPE (type
);
8286 /* Subrange types are identified by the fact that they are integer
8287 types, and that they have a subtype which is either an integer type
8288 or an enumeral type. */
8290 if (TREE_CODE (type
) != INTEGER_TYPE
8291 || subtype
== NULL_TREE
)
8294 if (TREE_CODE (subtype
) != INTEGER_TYPE
8295 && TREE_CODE (subtype
) != ENUMERAL_TYPE
)
8298 if (TREE_CODE (type
) == TREE_CODE (subtype
)
8299 && int_size_in_bytes (type
) == int_size_in_bytes (subtype
)
8300 && TYPE_MIN_VALUE (type
) != NULL
8301 && TYPE_MIN_VALUE (subtype
) != NULL
8302 && tree_int_cst_equal (TYPE_MIN_VALUE (type
), TYPE_MIN_VALUE (subtype
))
8303 && TYPE_MAX_VALUE (type
) != NULL
8304 && TYPE_MAX_VALUE (subtype
) != NULL
8305 && tree_int_cst_equal (TYPE_MAX_VALUE (type
), TYPE_MAX_VALUE (subtype
)))
8307 /* The type and its subtype have the same representation. If in
8308 addition the two types also have the same name, then the given
8309 type is not a subrange type, but rather a plain base type. */
8310 /* FIXME: brobecker/2004-03-22:
8311 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8312 therefore be sufficient to check the TYPE_SIZE node pointers
8313 rather than checking the actual size. Unfortunately, we have
8314 found some cases, such as in the Ada "integer" type, where
8315 this is not the case. Until this problem is solved, we need to
8316 keep checking the actual size. */
8317 tree type_name
= TYPE_NAME (type
);
8318 tree subtype_name
= TYPE_NAME (subtype
);
8320 if (type_name
!= NULL
&& TREE_CODE (type_name
) == TYPE_DECL
)
8321 type_name
= DECL_NAME (type_name
);
8323 if (subtype_name
!= NULL
&& TREE_CODE (subtype_name
) == TYPE_DECL
)
8324 subtype_name
= DECL_NAME (subtype_name
);
8326 if (type_name
== subtype_name
)
8333 /* Given a pointer to a tree node for a subrange type, return a pointer
8334 to a DIE that describes the given type. */
8337 subrange_type_die (tree type
, dw_die_ref context_die
)
8339 dw_die_ref subrange_die
;
8340 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
8342 if (context_die
== NULL
)
8343 context_die
= comp_unit_die
;
8345 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
8347 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
8349 /* The size of the subrange type and its base type do not match,
8350 so we need to generate a size attribute for the subrange type. */
8351 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
8354 if (TYPE_MIN_VALUE (type
) != NULL
)
8355 add_bound_info (subrange_die
, DW_AT_lower_bound
,
8356 TYPE_MIN_VALUE (type
));
8357 if (TYPE_MAX_VALUE (type
) != NULL
)
8358 add_bound_info (subrange_die
, DW_AT_upper_bound
,
8359 TYPE_MAX_VALUE (type
));
8361 return subrange_die
;
8364 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8365 entry that chains various modifiers in front of the given type. */
8368 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
8369 dw_die_ref context_die
)
8371 enum tree_code code
= TREE_CODE (type
);
8372 dw_die_ref mod_type_die
;
8373 dw_die_ref sub_die
= NULL
;
8374 tree item_type
= NULL
;
8375 tree qualified_type
;
8378 if (code
== ERROR_MARK
)
8381 /* See if we already have the appropriately qualified variant of
8384 = get_qualified_type (type
,
8385 ((is_const_type
? TYPE_QUAL_CONST
: 0)
8386 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
8388 /* If we do, then we can just use its DIE, if it exists. */
8391 mod_type_die
= lookup_type_die (qualified_type
);
8393 return mod_type_die
;
8396 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
8398 /* Handle C typedef types. */
8399 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
))
8401 tree dtype
= TREE_TYPE (name
);
8403 if (qualified_type
== dtype
)
8405 /* For a named type, use the typedef. */
8406 gen_type_die (qualified_type
, context_die
);
8407 return lookup_type_die (qualified_type
);
8409 else if (DECL_ORIGINAL_TYPE (name
)
8410 && (is_const_type
< TYPE_READONLY (dtype
)
8411 || is_volatile_type
< TYPE_VOLATILE (dtype
)))
8412 /* cv-unqualified version of named type. Just use the unnamed
8413 type to which it refers. */
8414 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
8415 is_const_type
, is_volatile_type
,
8417 /* Else cv-qualified version of named type; fall through. */
8422 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
8423 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
8425 else if (is_volatile_type
)
8427 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
8428 sub_die
= modified_type_die (type
, 0, 0, context_die
);
8430 else if (code
== POINTER_TYPE
)
8432 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
8433 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
8434 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
8435 item_type
= TREE_TYPE (type
);
8437 else if (code
== REFERENCE_TYPE
)
8439 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
8440 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
8441 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
8442 item_type
= TREE_TYPE (type
);
8444 else if (is_subrange_type (type
))
8446 mod_type_die
= subrange_type_die (type
, context_die
);
8447 item_type
= TREE_TYPE (type
);
8449 else if (is_base_type (type
))
8450 mod_type_die
= base_type_die (type
);
8453 gen_type_die (type
, context_die
);
8455 /* We have to get the type_main_variant here (and pass that to the
8456 `lookup_type_die' routine) because the ..._TYPE node we have
8457 might simply be a *copy* of some original type node (where the
8458 copy was created to help us keep track of typedef names) and
8459 that copy might have a different TYPE_UID from the original
8461 if (TREE_CODE (type
) != VECTOR_TYPE
)
8462 return lookup_type_die (type_main_variant (type
));
8464 /* Vectors have the debugging information in the type,
8465 not the main variant. */
8466 return lookup_type_die (type
);
8469 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
8470 don't output a DW_TAG_typedef, since there isn't one in the
8471 user's program; just attach a DW_AT_name to the type. */
8473 && (TREE_CODE (name
) != TYPE_DECL
|| TREE_TYPE (name
) == qualified_type
))
8475 if (TREE_CODE (name
) == TYPE_DECL
)
8476 /* Could just call add_name_and_src_coords_attributes here,
8477 but since this is a builtin type it doesn't have any
8478 useful source coordinates anyway. */
8479 name
= DECL_NAME (name
);
8480 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
8484 equate_type_number_to_die (qualified_type
, mod_type_die
);
8487 /* We must do this after the equate_type_number_to_die call, in case
8488 this is a recursive type. This ensures that the modified_type_die
8489 recursion will terminate even if the type is recursive. Recursive
8490 types are possible in Ada. */
8491 sub_die
= modified_type_die (item_type
,
8492 TYPE_READONLY (item_type
),
8493 TYPE_VOLATILE (item_type
),
8496 if (sub_die
!= NULL
)
8497 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
8499 return mod_type_die
;
8502 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8503 an enumerated type. */
8506 type_is_enum (tree type
)
8508 return TREE_CODE (type
) == ENUMERAL_TYPE
;
8511 /* Return the DBX register number described by a given RTL node. */
8514 dbx_reg_number (rtx rtl
)
8516 unsigned regno
= REGNO (rtl
);
8518 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
8520 #ifdef LEAF_REG_REMAP
8521 regno
= LEAF_REG_REMAP (regno
);
8524 return DBX_REGISTER_NUMBER (regno
);
8527 /* Optionally add a DW_OP_piece term to a location description expression.
8528 DW_OP_piece is only added if the location description expression already
8529 doesn't end with DW_OP_piece. */
8532 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
8534 dw_loc_descr_ref loc
;
8536 if (*list_head
!= NULL
)
8538 /* Find the end of the chain. */
8539 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
8542 if (loc
->dw_loc_opc
!= DW_OP_piece
)
8543 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
8547 /* Return a location descriptor that designates a machine register or
8548 zero if there is none. */
8550 static dw_loc_descr_ref
8551 reg_loc_descriptor (rtx rtl
)
8555 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
8558 regs
= targetm
.dwarf_register_span (rtl
);
8560 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
8561 return multiple_reg_loc_descriptor (rtl
, regs
);
8563 return one_reg_loc_descriptor (dbx_reg_number (rtl
));
8566 /* Return a location descriptor that designates a machine register for
8567 a given hard register number. */
8569 static dw_loc_descr_ref
8570 one_reg_loc_descriptor (unsigned int regno
)
8573 return new_loc_descr (DW_OP_reg0
+ regno
, 0, 0);
8575 return new_loc_descr (DW_OP_regx
, regno
, 0);
8578 /* Given an RTL of a register, return a location descriptor that
8579 designates a value that spans more than one register. */
8581 static dw_loc_descr_ref
8582 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
)
8586 dw_loc_descr_ref loc_result
= NULL
;
8589 #ifdef LEAF_REG_REMAP
8590 reg
= LEAF_REG_REMAP (reg
);
8592 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
8593 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
8595 /* Simple, contiguous registers. */
8596 if (regs
== NULL_RTX
)
8598 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
8605 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
));
8606 add_loc_descr (&loc_result
, t
);
8607 add_loc_descr_op_piece (&loc_result
, size
);
8613 /* Now onto stupid register sets in non contiguous locations. */
8615 gcc_assert (GET_CODE (regs
) == PARALLEL
);
8617 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8620 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
8624 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)));
8625 add_loc_descr (&loc_result
, t
);
8626 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8627 add_loc_descr_op_piece (&loc_result
, size
);
8632 /* Return a location descriptor that designates a constant. */
8634 static dw_loc_descr_ref
8635 int_loc_descriptor (HOST_WIDE_INT i
)
8637 enum dwarf_location_atom op
;
8639 /* Pick the smallest representation of a constant, rather than just
8640 defaulting to the LEB encoding. */
8644 op
= DW_OP_lit0
+ i
;
8647 else if (i
<= 0xffff)
8649 else if (HOST_BITS_PER_WIDE_INT
== 32
8659 else if (i
>= -0x8000)
8661 else if (HOST_BITS_PER_WIDE_INT
== 32
8662 || i
>= -0x80000000)
8668 return new_loc_descr (op
, i
, 0);
8671 /* Return a location descriptor that designates a base+offset location. */
8673 static dw_loc_descr_ref
8674 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
)
8678 /* We only use "frame base" when we're sure we're talking about the
8679 post-prologue local stack frame. We do this by *not* running
8680 register elimination until this point, and recognizing the special
8681 argument pointer and soft frame pointer rtx's. */
8682 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
8684 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
8688 if (GET_CODE (elim
) == PLUS
)
8690 offset
+= INTVAL (XEXP (elim
, 1));
8691 elim
= XEXP (elim
, 0);
8693 gcc_assert (elim
== (frame_pointer_needed
? hard_frame_pointer_rtx
8694 : stack_pointer_rtx
));
8695 offset
+= frame_pointer_fb_offset
;
8697 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
8701 regno
= dbx_reg_number (reg
);
8703 return new_loc_descr (DW_OP_breg0
+ regno
, offset
, 0);
8705 return new_loc_descr (DW_OP_bregx
, regno
, offset
);
8708 /* Return true if this RTL expression describes a base+offset calculation. */
8711 is_based_loc (rtx rtl
)
8713 return (GET_CODE (rtl
) == PLUS
8714 && ((REG_P (XEXP (rtl
, 0))
8715 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
8716 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
8719 /* The following routine converts the RTL for a variable or parameter
8720 (resident in memory) into an equivalent Dwarf representation of a
8721 mechanism for getting the address of that same variable onto the top of a
8722 hypothetical "address evaluation" stack.
8724 When creating memory location descriptors, we are effectively transforming
8725 the RTL for a memory-resident object into its Dwarf postfix expression
8726 equivalent. This routine recursively descends an RTL tree, turning
8727 it into Dwarf postfix code as it goes.
8729 MODE is the mode of the memory reference, needed to handle some
8730 autoincrement addressing modes.
8732 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
8733 location list for RTL.
8735 Return 0 if we can't represent the location. */
8737 static dw_loc_descr_ref
8738 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
)
8740 dw_loc_descr_ref mem_loc_result
= NULL
;
8741 enum dwarf_location_atom op
;
8743 /* Note that for a dynamically sized array, the location we will generate a
8744 description of here will be the lowest numbered location which is
8745 actually within the array. That's *not* necessarily the same as the
8746 zeroth element of the array. */
8748 rtl
= targetm
.delegitimize_address (rtl
);
8750 switch (GET_CODE (rtl
))
8755 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8756 just fall into the SUBREG code. */
8758 /* ... fall through ... */
8761 /* The case of a subreg may arise when we have a local (register)
8762 variable or a formal (register) parameter which doesn't quite fill
8763 up an entire register. For now, just assume that it is
8764 legitimate to make the Dwarf info refer to the whole register which
8765 contains the given subreg. */
8766 rtl
= XEXP (rtl
, 0);
8768 /* ... fall through ... */
8771 /* Whenever a register number forms a part of the description of the
8772 method for calculating the (dynamic) address of a memory resident
8773 object, DWARF rules require the register number be referred to as
8774 a "base register". This distinction is not based in any way upon
8775 what category of register the hardware believes the given register
8776 belongs to. This is strictly DWARF terminology we're dealing with
8777 here. Note that in cases where the location of a memory-resident
8778 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8779 OP_CONST (0)) the actual DWARF location descriptor that we generate
8780 may just be OP_BASEREG (basereg). This may look deceptively like
8781 the object in question was allocated to a register (rather than in
8782 memory) so DWARF consumers need to be aware of the subtle
8783 distinction between OP_REG and OP_BASEREG. */
8784 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
8785 mem_loc_result
= based_loc_descr (rtl
, 0);
8789 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
8790 if (mem_loc_result
!= 0)
8791 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
8795 rtl
= XEXP (rtl
, 1);
8797 /* ... fall through ... */
8800 /* Some ports can transform a symbol ref into a label ref, because
8801 the symbol ref is too far away and has to be dumped into a constant
8805 /* Alternatively, the symbol in the constant pool might be referenced
8806 by a different symbol. */
8807 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
8810 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
8812 if (GET_CODE (tmp
) == SYMBOL_REF
)
8815 if (CONSTANT_POOL_ADDRESS_P (tmp
))
8816 get_pool_constant_mark (tmp
, &marked
);
8821 /* If all references to this pool constant were optimized away,
8822 it was not output and thus we can't represent it.
8823 FIXME: might try to use DW_OP_const_value here, though
8824 DW_OP_piece complicates it. */
8829 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
8830 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8831 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8832 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
8836 /* Extract the PLUS expression nested inside and fall into
8838 rtl
= XEXP (rtl
, 1);
8843 /* Turn these into a PLUS expression and fall into the PLUS code
8845 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
8846 GEN_INT (GET_CODE (rtl
) == PRE_INC
8847 ? GET_MODE_UNIT_SIZE (mode
)
8848 : -GET_MODE_UNIT_SIZE (mode
)));
8850 /* ... fall through ... */
8854 if (is_based_loc (rtl
))
8855 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
8856 INTVAL (XEXP (rtl
, 1)));
8859 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
8860 if (mem_loc_result
== 0)
8863 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
8864 && INTVAL (XEXP (rtl
, 1)) >= 0)
8865 add_loc_descr (&mem_loc_result
,
8866 new_loc_descr (DW_OP_plus_uconst
,
8867 INTVAL (XEXP (rtl
, 1)), 0));
8870 add_loc_descr (&mem_loc_result
,
8871 mem_loc_descriptor (XEXP (rtl
, 1), mode
));
8872 add_loc_descr (&mem_loc_result
,
8873 new_loc_descr (DW_OP_plus
, 0, 0));
8878 /* If a pseudo-reg is optimized away, it is possible for it to
8879 be replaced with a MEM containing a multiply or shift. */
8898 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
8899 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
);
8901 if (op0
== 0 || op1
== 0)
8904 mem_loc_result
= op0
;
8905 add_loc_descr (&mem_loc_result
, op1
);
8906 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
8911 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
8918 return mem_loc_result
;
8921 /* Return a descriptor that describes the concatenation of two locations.
8922 This is typically a complex variable. */
8924 static dw_loc_descr_ref
8925 concat_loc_descriptor (rtx x0
, rtx x1
)
8927 dw_loc_descr_ref cc_loc_result
= NULL
;
8928 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
);
8929 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
);
8931 if (x0_ref
== 0 || x1_ref
== 0)
8934 cc_loc_result
= x0_ref
;
8935 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
8937 add_loc_descr (&cc_loc_result
, x1_ref
);
8938 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
8940 return cc_loc_result
;
8943 /* Output a proper Dwarf location descriptor for a variable or parameter
8944 which is either allocated in a register or in a memory location. For a
8945 register, we just generate an OP_REG and the register number. For a
8946 memory location we provide a Dwarf postfix expression describing how to
8947 generate the (dynamic) address of the object onto the address stack.
8949 If we don't know how to describe it, return 0. */
8951 static dw_loc_descr_ref
8952 loc_descriptor (rtx rtl
)
8954 dw_loc_descr_ref loc_result
= NULL
;
8956 switch (GET_CODE (rtl
))
8959 /* The case of a subreg may arise when we have a local (register)
8960 variable or a formal (register) parameter which doesn't quite fill
8961 up an entire register. For now, just assume that it is
8962 legitimate to make the Dwarf info refer to the whole register which
8963 contains the given subreg. */
8964 rtl
= SUBREG_REG (rtl
);
8966 /* ... fall through ... */
8969 loc_result
= reg_loc_descriptor (rtl
);
8973 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
8977 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
8982 if (GET_CODE (XEXP (rtl
, 1)) != PARALLEL
)
8984 loc_result
= loc_descriptor (XEXP (XEXP (rtl
, 1), 0));
8988 rtl
= XEXP (rtl
, 1);
8993 rtvec par_elems
= XVEC (rtl
, 0);
8994 int num_elem
= GET_NUM_ELEM (par_elems
);
8995 enum machine_mode mode
;
8998 /* Create the first one, so we have something to add to. */
8999 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0));
9000 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
9001 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
9002 for (i
= 1; i
< num_elem
; i
++)
9004 dw_loc_descr_ref temp
;
9006 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0));
9007 add_loc_descr (&loc_result
, temp
);
9008 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
9009 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
9021 /* Similar, but generate the descriptor from trees instead of rtl. This comes
9022 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
9023 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
9024 top-level invocation, and we require the address of LOC; is 0 if we require
9025 the value of LOC. */
9027 static dw_loc_descr_ref
9028 loc_descriptor_from_tree_1 (tree loc
, int want_address
)
9030 dw_loc_descr_ref ret
, ret1
;
9031 int have_address
= 0;
9032 enum dwarf_location_atom op
;
9034 /* ??? Most of the time we do not take proper care for sign/zero
9035 extending the values properly. Hopefully this won't be a real
9038 switch (TREE_CODE (loc
))
9043 case PLACEHOLDER_EXPR
:
9044 /* This case involves extracting fields from an object to determine the
9045 position of other fields. We don't try to encode this here. The
9046 only user of this is Ada, which encodes the needed information using
9047 the names of types. */
9053 case PREINCREMENT_EXPR
:
9054 case PREDECREMENT_EXPR
:
9055 case POSTINCREMENT_EXPR
:
9056 case POSTDECREMENT_EXPR
:
9057 /* There are no opcodes for these operations. */
9061 /* If we already want an address, there's nothing we can do. */
9065 /* Otherwise, process the argument and look for the address. */
9066 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 1);
9069 if (DECL_THREAD_LOCAL_P (loc
))
9073 /* If this is not defined, we have no way to emit the data. */
9074 if (!targetm
.asm_out
.output_dwarf_dtprel
)
9077 /* The way DW_OP_GNU_push_tls_address is specified, we can only
9078 look up addresses of objects in the current module. */
9079 if (DECL_EXTERNAL (loc
))
9082 rtl
= rtl_for_decl_location (loc
);
9083 if (rtl
== NULL_RTX
)
9088 rtl
= XEXP (rtl
, 0);
9089 if (! CONSTANT_P (rtl
))
9092 ret
= new_loc_descr (INTERNAL_DW_OP_tls_addr
, 0, 0);
9093 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
9094 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
9096 ret1
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
9097 add_loc_descr (&ret
, ret1
);
9105 if (DECL_HAS_VALUE_EXPR_P (loc
))
9106 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc
),
9112 rtx rtl
= rtl_for_decl_location (loc
);
9114 if (rtl
== NULL_RTX
)
9116 else if (GET_CODE (rtl
) == CONST_INT
)
9118 HOST_WIDE_INT val
= INTVAL (rtl
);
9119 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
9120 val
&= GET_MODE_MASK (DECL_MODE (loc
));
9121 ret
= int_loc_descriptor (val
);
9123 else if (GET_CODE (rtl
) == CONST_STRING
)
9125 else if (CONSTANT_P (rtl
))
9127 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
9128 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
9129 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
9133 enum machine_mode mode
;
9135 /* Certain constructs can only be represented at top-level. */
9136 if (want_address
== 2)
9137 return loc_descriptor (rtl
);
9139 mode
= GET_MODE (rtl
);
9142 rtl
= XEXP (rtl
, 0);
9145 ret
= mem_loc_descriptor (rtl
, mode
);
9151 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9156 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
);
9160 case NON_LVALUE_EXPR
:
9161 case VIEW_CONVERT_EXPR
:
9164 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
);
9169 case ARRAY_RANGE_REF
:
9172 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
9173 enum machine_mode mode
;
9175 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
9177 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
9178 &unsignedp
, &volatilep
, false);
9183 ret
= loc_descriptor_from_tree_1 (obj
, 1);
9185 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
9188 if (offset
!= NULL_TREE
)
9190 /* Variable offset. */
9191 add_loc_descr (&ret
, loc_descriptor_from_tree_1 (offset
, 0));
9192 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
9195 bytepos
= bitpos
/ BITS_PER_UNIT
;
9197 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
9198 else if (bytepos
< 0)
9200 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
9201 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
9209 if (host_integerp (loc
, 0))
9210 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
9217 /* Get an RTL for this, if something has been emitted. */
9218 rtx rtl
= lookup_constant_def (loc
);
9219 enum machine_mode mode
;
9221 if (!rtl
|| !MEM_P (rtl
))
9223 mode
= GET_MODE (rtl
);
9224 rtl
= XEXP (rtl
, 0);
9225 ret
= mem_loc_descriptor (rtl
, mode
);
9230 case TRUTH_AND_EXPR
:
9231 case TRUTH_ANDIF_EXPR
:
9236 case TRUTH_XOR_EXPR
:
9242 case TRUTH_ORIF_EXPR
:
9247 case FLOOR_DIV_EXPR
:
9249 case ROUND_DIV_EXPR
:
9250 case TRUNC_DIV_EXPR
:
9258 case FLOOR_MOD_EXPR
:
9260 case ROUND_MOD_EXPR
:
9261 case TRUNC_MOD_EXPR
:
9274 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
9278 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
9279 && host_integerp (TREE_OPERAND (loc
, 1), 0))
9281 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9285 add_loc_descr (&ret
,
9286 new_loc_descr (DW_OP_plus_uconst
,
9287 tree_low_cst (TREE_OPERAND (loc
, 1),
9297 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9304 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9311 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9318 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9333 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9334 ret1
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
9335 if (ret
== 0 || ret1
== 0)
9338 add_loc_descr (&ret
, ret1
);
9339 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
9342 case TRUTH_NOT_EXPR
:
9356 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9360 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
9366 const enum tree_code code
=
9367 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
9369 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
9370 build2 (code
, integer_type_node
,
9371 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
9372 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
9375 /* ... fall through ... */
9379 dw_loc_descr_ref lhs
9380 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
9381 dw_loc_descr_ref rhs
9382 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 2), 0);
9383 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
9385 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9386 if (ret
== 0 || lhs
== 0 || rhs
== 0)
9389 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
9390 add_loc_descr (&ret
, bra_node
);
9392 add_loc_descr (&ret
, rhs
);
9393 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
9394 add_loc_descr (&ret
, jump_node
);
9396 add_loc_descr (&ret
, lhs
);
9397 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
9398 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
9400 /* ??? Need a node to point the skip at. Use a nop. */
9401 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
9402 add_loc_descr (&ret
, tmp
);
9403 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
9404 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
9408 case FIX_TRUNC_EXPR
:
9410 case FIX_FLOOR_EXPR
:
9411 case FIX_ROUND_EXPR
:
9415 /* Leave front-end specific codes as simply unknown. This comes
9416 up, for instance, with the C STMT_EXPR. */
9417 if ((unsigned int) TREE_CODE (loc
)
9418 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
9421 #ifdef ENABLE_CHECKING
9422 /* Otherwise this is a generic code; we should just lists all of
9423 these explicitly. We forgot one. */
9426 /* In a release build, we want to degrade gracefully: better to
9427 generate incomplete debugging information than to crash. */
9432 /* Show if we can't fill the request for an address. */
9433 if (want_address
&& !have_address
)
9436 /* If we've got an address and don't want one, dereference. */
9437 if (!want_address
&& have_address
&& ret
)
9439 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
9441 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
9443 else if (size
== DWARF2_ADDR_SIZE
)
9446 op
= DW_OP_deref_size
;
9448 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
9454 static inline dw_loc_descr_ref
9455 loc_descriptor_from_tree (tree loc
)
9457 return loc_descriptor_from_tree_1 (loc
, 2);
9460 /* Given a value, round it up to the lowest multiple of `boundary'
9461 which is not less than the value itself. */
9463 static inline HOST_WIDE_INT
9464 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
9466 return (((value
+ boundary
- 1) / boundary
) * boundary
);
9469 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9470 pointer to the declared type for the relevant field variable, or return
9471 `integer_type_node' if the given node turns out to be an
9475 field_type (tree decl
)
9479 if (TREE_CODE (decl
) == ERROR_MARK
)
9480 return integer_type_node
;
9482 type
= DECL_BIT_FIELD_TYPE (decl
);
9483 if (type
== NULL_TREE
)
9484 type
= TREE_TYPE (decl
);
9489 /* Given a pointer to a tree node, return the alignment in bits for
9490 it, or else return BITS_PER_WORD if the node actually turns out to
9491 be an ERROR_MARK node. */
9493 static inline unsigned
9494 simple_type_align_in_bits (tree type
)
9496 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
9499 static inline unsigned
9500 simple_decl_align_in_bits (tree decl
)
9502 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
9505 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9506 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9507 or return 0 if we are unable to determine what that offset is, either
9508 because the argument turns out to be a pointer to an ERROR_MARK node, or
9509 because the offset is actually variable. (We can't handle the latter case
9512 static HOST_WIDE_INT
9513 field_byte_offset (tree decl
)
9515 unsigned int type_align_in_bits
;
9516 unsigned int decl_align_in_bits
;
9517 unsigned HOST_WIDE_INT type_size_in_bits
;
9518 HOST_WIDE_INT object_offset_in_bits
;
9520 tree field_size_tree
;
9521 HOST_WIDE_INT bitpos_int
;
9522 HOST_WIDE_INT deepest_bitpos
;
9523 unsigned HOST_WIDE_INT field_size_in_bits
;
9525 if (TREE_CODE (decl
) == ERROR_MARK
)
9528 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
9530 type
= field_type (decl
);
9531 field_size_tree
= DECL_SIZE (decl
);
9533 /* The size could be unspecified if there was an error, or for
9534 a flexible array member. */
9535 if (! field_size_tree
)
9536 field_size_tree
= bitsize_zero_node
;
9538 /* We cannot yet cope with fields whose positions are variable, so
9539 for now, when we see such things, we simply return 0. Someday, we may
9540 be able to handle such cases, but it will be damn difficult. */
9541 if (! host_integerp (bit_position (decl
), 0))
9544 bitpos_int
= int_bit_position (decl
);
9546 /* If we don't know the size of the field, pretend it's a full word. */
9547 if (host_integerp (field_size_tree
, 1))
9548 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
9550 field_size_in_bits
= BITS_PER_WORD
;
9552 type_size_in_bits
= simple_type_size_in_bits (type
);
9553 type_align_in_bits
= simple_type_align_in_bits (type
);
9554 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
9556 /* The GCC front-end doesn't make any attempt to keep track of the starting
9557 bit offset (relative to the start of the containing structure type) of the
9558 hypothetical "containing object" for a bit-field. Thus, when computing
9559 the byte offset value for the start of the "containing object" of a
9560 bit-field, we must deduce this information on our own. This can be rather
9561 tricky to do in some cases. For example, handling the following structure
9562 type definition when compiling for an i386/i486 target (which only aligns
9563 long long's to 32-bit boundaries) can be very tricky:
9565 struct S { int field1; long long field2:31; };
9567 Fortunately, there is a simple rule-of-thumb which can be used in such
9568 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
9569 structure shown above. It decides to do this based upon one simple rule
9570 for bit-field allocation. GCC allocates each "containing object" for each
9571 bit-field at the first (i.e. lowest addressed) legitimate alignment
9572 boundary (based upon the required minimum alignment for the declared type
9573 of the field) which it can possibly use, subject to the condition that
9574 there is still enough available space remaining in the containing object
9575 (when allocated at the selected point) to fully accommodate all of the
9576 bits of the bit-field itself.
9578 This simple rule makes it obvious why GCC allocates 8 bytes for each
9579 object of the structure type shown above. When looking for a place to
9580 allocate the "containing object" for `field2', the compiler simply tries
9581 to allocate a 64-bit "containing object" at each successive 32-bit
9582 boundary (starting at zero) until it finds a place to allocate that 64-
9583 bit field such that at least 31 contiguous (and previously unallocated)
9584 bits remain within that selected 64 bit field. (As it turns out, for the
9585 example above, the compiler finds it is OK to allocate the "containing
9586 object" 64-bit field at bit-offset zero within the structure type.)
9588 Here we attempt to work backwards from the limited set of facts we're
9589 given, and we try to deduce from those facts, where GCC must have believed
9590 that the containing object started (within the structure type). The value
9591 we deduce is then used (by the callers of this routine) to generate
9592 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
9593 and, in the case of DW_AT_location, regular fields as well). */
9595 /* Figure out the bit-distance from the start of the structure to the
9596 "deepest" bit of the bit-field. */
9597 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
9599 /* This is the tricky part. Use some fancy footwork to deduce where the
9600 lowest addressed bit of the containing object must be. */
9601 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
9603 /* Round up to type_align by default. This works best for bitfields. */
9604 object_offset_in_bits
+= type_align_in_bits
- 1;
9605 object_offset_in_bits
/= type_align_in_bits
;
9606 object_offset_in_bits
*= type_align_in_bits
;
9608 if (object_offset_in_bits
> bitpos_int
)
9610 /* Sigh, the decl must be packed. */
9611 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
9613 /* Round up to decl_align instead. */
9614 object_offset_in_bits
+= decl_align_in_bits
- 1;
9615 object_offset_in_bits
/= decl_align_in_bits
;
9616 object_offset_in_bits
*= decl_align_in_bits
;
9619 return object_offset_in_bits
/ BITS_PER_UNIT
;
9622 /* The following routines define various Dwarf attributes and any data
9623 associated with them. */
9625 /* Add a location description attribute value to a DIE.
9627 This emits location attributes suitable for whole variables and
9628 whole parameters. Note that the location attributes for struct fields are
9629 generated by the routine `data_member_location_attribute' below. */
9632 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9633 dw_loc_descr_ref descr
)
9636 add_AT_loc (die
, attr_kind
, descr
);
9639 /* Attach the specialized form of location attribute used for data members of
9640 struct and union types. In the special case of a FIELD_DECL node which
9641 represents a bit-field, the "offset" part of this special location
9642 descriptor must indicate the distance in bytes from the lowest-addressed
9643 byte of the containing struct or union type to the lowest-addressed byte of
9644 the "containing object" for the bit-field. (See the `field_byte_offset'
9647 For any given bit-field, the "containing object" is a hypothetical object
9648 (of some integral or enum type) within which the given bit-field lives. The
9649 type of this hypothetical "containing object" is always the same as the
9650 declared type of the individual bit-field itself (for GCC anyway... the
9651 DWARF spec doesn't actually mandate this). Note that it is the size (in
9652 bytes) of the hypothetical "containing object" which will be given in the
9653 DW_AT_byte_size attribute for this bit-field. (See the
9654 `byte_size_attribute' function below.) It is also used when calculating the
9655 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
9659 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
9661 HOST_WIDE_INT offset
;
9662 dw_loc_descr_ref loc_descr
= 0;
9664 if (TREE_CODE (decl
) == TREE_BINFO
)
9666 /* We're working on the TAG_inheritance for a base class. */
9667 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
9669 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
9670 aren't at a fixed offset from all (sub)objects of the same
9671 type. We need to extract the appropriate offset from our
9672 vtable. The following dwarf expression means
9674 BaseAddr = ObAddr + *((*ObAddr) - Offset)
9676 This is specific to the V3 ABI, of course. */
9678 dw_loc_descr_ref tmp
;
9680 /* Make a copy of the object address. */
9681 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
9682 add_loc_descr (&loc_descr
, tmp
);
9684 /* Extract the vtable address. */
9685 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
9686 add_loc_descr (&loc_descr
, tmp
);
9688 /* Calculate the address of the offset. */
9689 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
9690 gcc_assert (offset
< 0);
9692 tmp
= int_loc_descriptor (-offset
);
9693 add_loc_descr (&loc_descr
, tmp
);
9694 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
9695 add_loc_descr (&loc_descr
, tmp
);
9697 /* Extract the offset. */
9698 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
9699 add_loc_descr (&loc_descr
, tmp
);
9701 /* Add it to the object address. */
9702 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
9703 add_loc_descr (&loc_descr
, tmp
);
9706 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
9709 offset
= field_byte_offset (decl
);
9713 enum dwarf_location_atom op
;
9715 /* The DWARF2 standard says that we should assume that the structure
9716 address is already on the stack, so we can specify a structure field
9717 address by using DW_OP_plus_uconst. */
9719 #ifdef MIPS_DEBUGGING_INFO
9720 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9721 operator correctly. It works only if we leave the offset on the
9725 op
= DW_OP_plus_uconst
;
9728 loc_descr
= new_loc_descr (op
, offset
, 0);
9731 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
9734 /* Writes integer values to dw_vec_const array. */
9737 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
9741 *dest
++ = val
& 0xff;
9747 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
9749 static HOST_WIDE_INT
9750 extract_int (const unsigned char *src
, unsigned int size
)
9752 HOST_WIDE_INT val
= 0;
9758 val
|= *--src
& 0xff;
9764 /* Writes floating point values to dw_vec_const array. */
9767 insert_float (rtx rtl
, unsigned char *array
)
9773 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
9774 real_to_target (val
, &rv
, GET_MODE (rtl
));
9776 /* real_to_target puts 32-bit pieces in each long. Pack them. */
9777 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
9779 insert_int (val
[i
], 4, array
);
9784 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9785 does not have a "location" either in memory or in a register. These
9786 things can arise in GNU C when a constant is passed as an actual parameter
9787 to an inlined function. They can also arise in C++ where declared
9788 constants do not necessarily get memory "homes". */
9791 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
9793 switch (GET_CODE (rtl
))
9797 HOST_WIDE_INT val
= INTVAL (rtl
);
9800 add_AT_int (die
, DW_AT_const_value
, val
);
9802 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
9807 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9808 floating-point constant. A CONST_DOUBLE is used whenever the
9809 constant requires more than one word in order to be adequately
9810 represented. We output CONST_DOUBLEs as blocks. */
9812 enum machine_mode mode
= GET_MODE (rtl
);
9814 if (SCALAR_FLOAT_MODE_P (mode
))
9816 unsigned int length
= GET_MODE_SIZE (mode
);
9817 unsigned char *array
= ggc_alloc (length
);
9819 insert_float (rtl
, array
);
9820 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
9824 /* ??? We really should be using HOST_WIDE_INT throughout. */
9825 gcc_assert (HOST_BITS_PER_LONG
== HOST_BITS_PER_WIDE_INT
);
9827 add_AT_long_long (die
, DW_AT_const_value
,
9828 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
9835 enum machine_mode mode
= GET_MODE (rtl
);
9836 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
9837 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
9838 unsigned char *array
= ggc_alloc (length
* elt_size
);
9842 switch (GET_MODE_CLASS (mode
))
9844 case MODE_VECTOR_INT
:
9845 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
9847 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
9848 HOST_WIDE_INT lo
, hi
;
9850 switch (GET_CODE (elt
))
9858 lo
= CONST_DOUBLE_LOW (elt
);
9859 hi
= CONST_DOUBLE_HIGH (elt
);
9866 if (elt_size
<= sizeof (HOST_WIDE_INT
))
9867 insert_int (lo
, elt_size
, p
);
9870 unsigned char *p0
= p
;
9871 unsigned char *p1
= p
+ sizeof (HOST_WIDE_INT
);
9873 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
9874 if (WORDS_BIG_ENDIAN
)
9879 insert_int (lo
, sizeof (HOST_WIDE_INT
), p0
);
9880 insert_int (hi
, sizeof (HOST_WIDE_INT
), p1
);
9885 case MODE_VECTOR_FLOAT
:
9886 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
9888 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
9889 insert_float (elt
, p
);
9897 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
9902 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
9908 add_AT_addr (die
, DW_AT_const_value
, rtl
);
9909 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
9913 /* In cases where an inlined instance of an inline function is passed
9914 the address of an `auto' variable (which is local to the caller) we
9915 can get a situation where the DECL_RTL of the artificial local
9916 variable (for the inlining) which acts as a stand-in for the
9917 corresponding formal parameter (of the inline function) will look
9918 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9919 exactly a compile-time constant expression, but it isn't the address
9920 of the (artificial) local variable either. Rather, it represents the
9921 *value* which the artificial local variable always has during its
9922 lifetime. We currently have no way to represent such quasi-constant
9923 values in Dwarf, so for now we just punt and generate nothing. */
9927 /* No other kinds of rtx should be possible here. */
9933 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
9934 for use in a later add_const_value_attribute call. */
9937 rtl_for_decl_init (tree init
, tree type
)
9941 /* If a variable is initialized with a string constant without embedded
9942 zeros, build CONST_STRING. */
9943 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
9945 tree enttype
= TREE_TYPE (type
);
9946 tree domain
= TYPE_DOMAIN (type
);
9947 enum machine_mode mode
= TYPE_MODE (enttype
);
9949 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
9951 && integer_zerop (TYPE_MIN_VALUE (domain
))
9952 && compare_tree_int (TYPE_MAX_VALUE (domain
),
9953 TREE_STRING_LENGTH (init
) - 1) == 0
9954 && ((size_t) TREE_STRING_LENGTH (init
)
9955 == strlen (TREE_STRING_POINTER (init
)) + 1))
9956 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
9957 ggc_strdup (TREE_STRING_POINTER (init
)));
9959 /* If the initializer is something that we know will expand into an
9960 immediate RTL constant, expand it now. Expanding anything else
9961 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
9962 /* Aggregate, vector, and complex types may contain constructors that may
9963 result in code being generated when expand_expr is called, so we can't
9964 handle them here. Integer and float are useful and safe types to handle
9966 else if ((INTEGRAL_TYPE_P (type
) || SCALAR_FLOAT_TYPE_P (type
))
9967 && initializer_constant_valid_p (init
, type
) == null_pointer_node
)
9969 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
9971 /* If expand_expr returns a MEM, it wasn't immediate. */
9972 gcc_assert (!rtl
|| !MEM_P (rtl
));
9978 /* Generate RTL for the variable DECL to represent its location. */
9981 rtl_for_decl_location (tree decl
)
9985 /* Here we have to decide where we are going to say the parameter "lives"
9986 (as far as the debugger is concerned). We only have a couple of
9987 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
9989 DECL_RTL normally indicates where the parameter lives during most of the
9990 activation of the function. If optimization is enabled however, this
9991 could be either NULL or else a pseudo-reg. Both of those cases indicate
9992 that the parameter doesn't really live anywhere (as far as the code
9993 generation parts of GCC are concerned) during most of the function's
9994 activation. That will happen (for example) if the parameter is never
9995 referenced within the function.
9997 We could just generate a location descriptor here for all non-NULL
9998 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
9999 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
10000 where DECL_RTL is NULL or is a pseudo-reg.
10002 Note however that we can only get away with using DECL_INCOMING_RTL as
10003 a backup substitute for DECL_RTL in certain limited cases. In cases
10004 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
10005 we can be sure that the parameter was passed using the same type as it is
10006 declared to have within the function, and that its DECL_INCOMING_RTL
10007 points us to a place where a value of that type is passed.
10009 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
10010 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
10011 because in these cases DECL_INCOMING_RTL points us to a value of some
10012 type which is *different* from the type of the parameter itself. Thus,
10013 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
10014 such cases, the debugger would end up (for example) trying to fetch a
10015 `float' from a place which actually contains the first part of a
10016 `double'. That would lead to really incorrect and confusing
10017 output at debug-time.
10019 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
10020 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
10021 are a couple of exceptions however. On little-endian machines we can
10022 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
10023 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
10024 an integral type that is smaller than TREE_TYPE (decl). These cases arise
10025 when (on a little-endian machine) a non-prototyped function has a
10026 parameter declared to be of type `short' or `char'. In such cases,
10027 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
10028 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
10029 passed `int' value. If the debugger then uses that address to fetch
10030 a `short' or a `char' (on a little-endian machine) the result will be
10031 the correct data, so we allow for such exceptional cases below.
10033 Note that our goal here is to describe the place where the given formal
10034 parameter lives during most of the function's activation (i.e. between the
10035 end of the prologue and the start of the epilogue). We'll do that as best
10036 as we can. Note however that if the given formal parameter is modified
10037 sometime during the execution of the function, then a stack backtrace (at
10038 debug-time) will show the function as having been called with the *new*
10039 value rather than the value which was originally passed in. This happens
10040 rarely enough that it is not a major problem, but it *is* a problem, and
10041 I'd like to fix it.
10043 A future version of dwarf2out.c may generate two additional attributes for
10044 any given DW_TAG_formal_parameter DIE which will describe the "passed
10045 type" and the "passed location" for the given formal parameter in addition
10046 to the attributes we now generate to indicate the "declared type" and the
10047 "active location" for each parameter. This additional set of attributes
10048 could be used by debuggers for stack backtraces. Separately, note that
10049 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
10050 This happens (for example) for inlined-instances of inline function formal
10051 parameters which are never referenced. This really shouldn't be
10052 happening. All PARM_DECL nodes should get valid non-NULL
10053 DECL_INCOMING_RTL values. FIXME. */
10055 /* Use DECL_RTL as the "location" unless we find something better. */
10056 rtl
= DECL_RTL_IF_SET (decl
);
10058 /* When generating abstract instances, ignore everything except
10059 constants, symbols living in memory, and symbols living in
10060 fixed registers. */
10061 if (! reload_completed
)
10064 && (CONSTANT_P (rtl
)
10066 && CONSTANT_P (XEXP (rtl
, 0)))
10068 && TREE_CODE (decl
) == VAR_DECL
10069 && TREE_STATIC (decl
))))
10071 rtl
= targetm
.delegitimize_address (rtl
);
10076 else if (TREE_CODE (decl
) == PARM_DECL
)
10078 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
10080 tree declared_type
= TREE_TYPE (decl
);
10081 tree passed_type
= DECL_ARG_TYPE (decl
);
10082 enum machine_mode dmode
= TYPE_MODE (declared_type
);
10083 enum machine_mode pmode
= TYPE_MODE (passed_type
);
10085 /* This decl represents a formal parameter which was optimized out.
10086 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
10087 all cases where (rtl == NULL_RTX) just below. */
10088 if (dmode
== pmode
)
10089 rtl
= DECL_INCOMING_RTL (decl
);
10090 else if (SCALAR_INT_MODE_P (dmode
)
10091 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
10092 && DECL_INCOMING_RTL (decl
))
10094 rtx inc
= DECL_INCOMING_RTL (decl
);
10097 else if (MEM_P (inc
))
10099 if (BYTES_BIG_ENDIAN
)
10100 rtl
= adjust_address_nv (inc
, dmode
,
10101 GET_MODE_SIZE (pmode
)
10102 - GET_MODE_SIZE (dmode
));
10109 /* If the parm was passed in registers, but lives on the stack, then
10110 make a big endian correction if the mode of the type of the
10111 parameter is not the same as the mode of the rtl. */
10112 /* ??? This is the same series of checks that are made in dbxout.c before
10113 we reach the big endian correction code there. It isn't clear if all
10114 of these checks are necessary here, but keeping them all is the safe
10116 else if (MEM_P (rtl
)
10117 && XEXP (rtl
, 0) != const0_rtx
10118 && ! CONSTANT_P (XEXP (rtl
, 0))
10119 /* Not passed in memory. */
10120 && !MEM_P (DECL_INCOMING_RTL (decl
))
10121 /* Not passed by invisible reference. */
10122 && (!REG_P (XEXP (rtl
, 0))
10123 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
10124 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
10125 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
10126 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
10129 /* Big endian correction check. */
10130 && BYTES_BIG_ENDIAN
10131 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
10132 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
10135 int offset
= (UNITS_PER_WORD
10136 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
10138 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
10139 plus_constant (XEXP (rtl
, 0), offset
));
10142 else if (TREE_CODE (decl
) == VAR_DECL
10145 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
10146 && BYTES_BIG_ENDIAN
)
10148 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
10149 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
10151 /* If a variable is declared "register" yet is smaller than
10152 a register, then if we store the variable to memory, it
10153 looks like we're storing a register-sized value, when in
10154 fact we are not. We need to adjust the offset of the
10155 storage location to reflect the actual value's bytes,
10156 else gdb will not be able to display it. */
10158 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
10159 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
10162 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
10163 and will have been substituted directly into all expressions that use it.
10164 C does not have such a concept, but C++ and other languages do. */
10165 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
10166 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
10169 rtl
= targetm
.delegitimize_address (rtl
);
10171 /* If we don't look past the constant pool, we risk emitting a
10172 reference to a constant pool entry that isn't referenced from
10173 code, and thus is not emitted. */
10175 rtl
= avoid_constant_pool_reference (rtl
);
10180 /* We need to figure out what section we should use as the base for the
10181 address ranges where a given location is valid.
10182 1. If this particular DECL has a section associated with it, use that.
10183 2. If this function has a section associated with it, use that.
10184 3. Otherwise, use the text section.
10185 XXX: If you split a variable across multiple sections, we won't notice. */
10187 static const char *
10188 secname_for_decl (tree decl
)
10190 const char *secname
;
10192 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
10194 tree sectree
= DECL_SECTION_NAME (decl
);
10195 secname
= TREE_STRING_POINTER (sectree
);
10197 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
10199 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
10200 secname
= TREE_STRING_POINTER (sectree
);
10202 else if (cfun
&& in_cold_section_p
)
10203 secname
= cfun
->cold_section_label
;
10205 secname
= text_section_label
;
10210 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
10211 data attribute for a variable or a parameter. We generate the
10212 DW_AT_const_value attribute only in those cases where the given variable
10213 or parameter does not have a true "location" either in memory or in a
10214 register. This can happen (for example) when a constant is passed as an
10215 actual argument in a call to an inline function. (It's possible that
10216 these things can crop up in other ways also.) Note that one type of
10217 constant value which can be passed into an inlined function is a constant
10218 pointer. This can happen for example if an actual argument in an inlined
10219 function call evaluates to a compile-time constant address. */
10222 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
,
10223 enum dwarf_attribute attr
)
10226 dw_loc_descr_ref descr
;
10227 var_loc_list
*loc_list
;
10228 struct var_loc_node
*node
;
10229 if (TREE_CODE (decl
) == ERROR_MARK
)
10232 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
10233 || TREE_CODE (decl
) == RESULT_DECL
);
10235 /* See if we possibly have multiple locations for this variable. */
10236 loc_list
= lookup_decl_loc (decl
);
10238 /* If it truly has multiple locations, the first and last node will
10240 if (loc_list
&& loc_list
->first
!= loc_list
->last
)
10242 const char *endname
, *secname
;
10243 dw_loc_list_ref list
;
10246 /* Now that we know what section we are using for a base,
10247 actually construct the list of locations.
10248 The first location information is what is passed to the
10249 function that creates the location list, and the remaining
10250 locations just get added on to that list.
10251 Note that we only know the start address for a location
10252 (IE location changes), so to build the range, we use
10253 the range [current location start, next location start].
10254 This means we have to special case the last node, and generate
10255 a range of [last location start, end of function label]. */
10257 node
= loc_list
->first
;
10258 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10259 secname
= secname_for_decl (decl
);
10261 list
= new_loc_list (loc_descriptor (varloc
),
10262 node
->label
, node
->next
->label
, secname
, 1);
10265 for (; node
->next
; node
= node
->next
)
10266 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
10268 /* The variable has a location between NODE->LABEL and
10269 NODE->NEXT->LABEL. */
10270 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10271 add_loc_descr_to_loc_list (&list
, loc_descriptor (varloc
),
10272 node
->label
, node
->next
->label
, secname
);
10275 /* If the variable has a location at the last label
10276 it keeps its location until the end of function. */
10277 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
10279 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
10281 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10282 if (!current_function_decl
)
10283 endname
= text_end_label
;
10286 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
10287 current_function_funcdef_no
);
10288 endname
= ggc_strdup (label_id
);
10290 add_loc_descr_to_loc_list (&list
, loc_descriptor (varloc
),
10291 node
->label
, endname
, secname
);
10294 /* Finally, add the location list to the DIE, and we are done. */
10295 add_AT_loc_list (die
, attr
, list
);
10299 /* Try to get some constant RTL for this decl, and use that as the value of
10302 rtl
= rtl_for_decl_location (decl
);
10303 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
))
10305 add_const_value_attribute (die
, rtl
);
10309 /* If we have tried to generate the location otherwise, and it
10310 didn't work out (we wouldn't be here if we did), and we have a one entry
10311 location list, try generating a location from that. */
10312 if (loc_list
&& loc_list
->first
)
10314 node
= loc_list
->first
;
10315 descr
= loc_descriptor (NOTE_VAR_LOCATION (node
->var_loc_note
));
10318 add_AT_location_description (die
, attr
, descr
);
10323 /* We couldn't get any rtl, so try directly generating the location
10324 description from the tree. */
10325 descr
= loc_descriptor_from_tree (decl
);
10328 add_AT_location_description (die
, attr
, descr
);
10333 /* If we don't have a copy of this variable in memory for some reason (such
10334 as a C++ member constant that doesn't have an out-of-line definition),
10335 we should tell the debugger about the constant value. */
10338 tree_add_const_value_attribute (dw_die_ref var_die
, tree decl
)
10340 tree init
= DECL_INITIAL (decl
);
10341 tree type
= TREE_TYPE (decl
);
10344 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
)
10349 rtl
= rtl_for_decl_init (init
, type
);
10351 add_const_value_attribute (var_die
, rtl
);
10354 /* Convert the CFI instructions for the current function into a
10355 location list. This is used for DW_AT_frame_base when we targeting
10356 a dwarf2 consumer that does not support the dwarf3
10357 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
10360 static dw_loc_list_ref
10361 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
10364 dw_loc_list_ref list
, *list_tail
;
10366 dw_cfa_location last_cfa
, next_cfa
;
10367 const char *start_label
, *last_label
, *section
;
10369 fde
= &fde_table
[fde_table_in_use
- 1];
10371 section
= secname_for_decl (current_function_decl
);
10375 next_cfa
.reg
= INVALID_REGNUM
;
10376 next_cfa
.offset
= 0;
10377 next_cfa
.indirect
= 0;
10378 next_cfa
.base_offset
= 0;
10380 start_label
= fde
->dw_fde_begin
;
10382 /* ??? Bald assumption that the CIE opcode list does not contain
10383 advance opcodes. */
10384 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
10385 lookup_cfa_1 (cfi
, &next_cfa
);
10387 last_cfa
= next_cfa
;
10388 last_label
= start_label
;
10390 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
10391 switch (cfi
->dw_cfi_opc
)
10393 case DW_CFA_advance_loc1
:
10394 case DW_CFA_advance_loc2
:
10395 case DW_CFA_advance_loc4
:
10396 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
10398 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
10399 start_label
, last_label
, section
,
10402 list_tail
= &(*list_tail
)->dw_loc_next
;
10403 last_cfa
= next_cfa
;
10404 start_label
= last_label
;
10406 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
10409 case DW_CFA_advance_loc
:
10410 /* The encoding is complex enough that we should never emit this. */
10411 case DW_CFA_remember_state
:
10412 case DW_CFA_restore_state
:
10413 /* We don't handle these two in this function. It would be possible
10414 if it were to be required. */
10415 gcc_unreachable ();
10418 lookup_cfa_1 (cfi
, &next_cfa
);
10422 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
10424 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
10425 start_label
, last_label
, section
,
10427 list_tail
= &(*list_tail
)->dw_loc_next
;
10428 start_label
= last_label
;
10430 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
10431 start_label
, fde
->dw_fde_end
, section
,
10437 /* Compute a displacement from the "steady-state frame pointer" to the
10438 frame base (often the same as the CFA), and store it in
10439 frame_pointer_fb_offset. OFFSET is added to the displacement
10440 before the latter is negated. */
10443 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
10447 #ifdef FRAME_POINTER_CFA_OFFSET
10448 reg
= frame_pointer_rtx
;
10449 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
10451 reg
= arg_pointer_rtx
;
10452 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
10455 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
10456 if (GET_CODE (elim
) == PLUS
)
10458 offset
+= INTVAL (XEXP (elim
, 1));
10459 elim
= XEXP (elim
, 0);
10461 gcc_assert (elim
== (frame_pointer_needed
? hard_frame_pointer_rtx
10462 : stack_pointer_rtx
));
10464 frame_pointer_fb_offset
= -offset
;
10467 /* Generate a DW_AT_name attribute given some string value to be included as
10468 the value of the attribute. */
10471 add_name_attribute (dw_die_ref die
, const char *name_string
)
10473 if (name_string
!= NULL
&& *name_string
!= 0)
10475 if (demangle_name_func
)
10476 name_string
= (*demangle_name_func
) (name_string
);
10478 add_AT_string (die
, DW_AT_name
, name_string
);
10482 /* Generate a DW_AT_comp_dir attribute for DIE. */
10485 add_comp_dir_attribute (dw_die_ref die
)
10487 const char *wd
= get_src_pwd ();
10489 add_AT_string (die
, DW_AT_comp_dir
, wd
);
10492 /* Given a tree node describing an array bound (either lower or upper) output
10493 a representation for that bound. */
10496 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
10498 switch (TREE_CODE (bound
))
10503 /* All fixed-bounds are represented by INTEGER_CST nodes. */
10505 if (! host_integerp (bound
, 0)
10506 || (bound_attr
== DW_AT_lower_bound
10507 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
10508 || (is_fortran () && integer_onep (bound
)))))
10509 /* Use the default. */
10512 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
10517 case NON_LVALUE_EXPR
:
10518 case VIEW_CONVERT_EXPR
:
10519 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
10529 dw_die_ref decl_die
= lookup_decl_die (bound
);
10531 /* ??? Can this happen, or should the variable have been bound
10532 first? Probably it can, since I imagine that we try to create
10533 the types of parameters in the order in which they exist in
10534 the list, and won't have created a forward reference to a
10535 later parameter. */
10536 if (decl_die
!= NULL
)
10537 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
10543 /* Otherwise try to create a stack operation procedure to
10544 evaluate the value of the array bound. */
10546 dw_die_ref ctx
, decl_die
;
10547 dw_loc_descr_ref loc
;
10549 loc
= loc_descriptor_from_tree (bound
);
10553 if (current_function_decl
== 0)
10554 ctx
= comp_unit_die
;
10556 ctx
= lookup_decl_die (current_function_decl
);
10558 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
10559 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
10560 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
10561 add_AT_loc (decl_die
, DW_AT_location
, loc
);
10563 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
10569 /* Note that the block of subscript information for an array type also
10570 includes information about the element type of type given array type. */
10573 add_subscript_info (dw_die_ref type_die
, tree type
)
10575 #ifndef MIPS_DEBUGGING_INFO
10576 unsigned dimension_number
;
10579 dw_die_ref subrange_die
;
10581 /* The GNU compilers represent multidimensional array types as sequences of
10582 one dimensional array types whose element types are themselves array
10583 types. Here we squish that down, so that each multidimensional array
10584 type gets only one array_type DIE in the Dwarf debugging info. The draft
10585 Dwarf specification say that we are allowed to do this kind of
10586 compression in C (because there is no difference between an array or
10587 arrays and a multidimensional array in C) but for other source languages
10588 (e.g. Ada) we probably shouldn't do this. */
10590 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10591 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10592 We work around this by disabling this feature. See also
10593 gen_array_type_die. */
10594 #ifndef MIPS_DEBUGGING_INFO
10595 for (dimension_number
= 0;
10596 TREE_CODE (type
) == ARRAY_TYPE
;
10597 type
= TREE_TYPE (type
), dimension_number
++)
10600 tree domain
= TYPE_DOMAIN (type
);
10602 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
10603 and (in GNU C only) variable bounds. Handle all three forms
10605 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
10608 /* We have an array type with specified bounds. */
10609 lower
= TYPE_MIN_VALUE (domain
);
10610 upper
= TYPE_MAX_VALUE (domain
);
10612 /* Define the index type. */
10613 if (TREE_TYPE (domain
))
10615 /* ??? This is probably an Ada unnamed subrange type. Ignore the
10616 TREE_TYPE field. We can't emit debug info for this
10617 because it is an unnamed integral type. */
10618 if (TREE_CODE (domain
) == INTEGER_TYPE
10619 && TYPE_NAME (domain
) == NULL_TREE
10620 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
10621 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
10624 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
10628 /* ??? If upper is NULL, the array has unspecified length,
10629 but it does have a lower bound. This happens with Fortran
10631 Since the debugger is definitely going to need to know N
10632 to produce useful results, go ahead and output the lower
10633 bound solo, and hope the debugger can cope. */
10635 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
10637 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
10640 /* Otherwise we have an array type with an unspecified length. The
10641 DWARF-2 spec does not say how to handle this; let's just leave out the
10647 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
10651 switch (TREE_CODE (tree_node
))
10656 case ENUMERAL_TYPE
:
10659 case QUAL_UNION_TYPE
:
10660 size
= int_size_in_bytes (tree_node
);
10663 /* For a data member of a struct or union, the DW_AT_byte_size is
10664 generally given as the number of bytes normally allocated for an
10665 object of the *declared* type of the member itself. This is true
10666 even for bit-fields. */
10667 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
10670 gcc_unreachable ();
10673 /* Note that `size' might be -1 when we get to this point. If it is, that
10674 indicates that the byte size of the entity in question is variable. We
10675 have no good way of expressing this fact in Dwarf at the present time,
10676 so just let the -1 pass on through. */
10677 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
10680 /* For a FIELD_DECL node which represents a bit-field, output an attribute
10681 which specifies the distance in bits from the highest order bit of the
10682 "containing object" for the bit-field to the highest order bit of the
10685 For any given bit-field, the "containing object" is a hypothetical object
10686 (of some integral or enum type) within which the given bit-field lives. The
10687 type of this hypothetical "containing object" is always the same as the
10688 declared type of the individual bit-field itself. The determination of the
10689 exact location of the "containing object" for a bit-field is rather
10690 complicated. It's handled by the `field_byte_offset' function (above).
10692 Note that it is the size (in bytes) of the hypothetical "containing object"
10693 which will be given in the DW_AT_byte_size attribute for this bit-field.
10694 (See `byte_size_attribute' above). */
10697 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
10699 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
10700 tree type
= DECL_BIT_FIELD_TYPE (decl
);
10701 HOST_WIDE_INT bitpos_int
;
10702 HOST_WIDE_INT highest_order_object_bit_offset
;
10703 HOST_WIDE_INT highest_order_field_bit_offset
;
10704 HOST_WIDE_INT
unsigned bit_offset
;
10706 /* Must be a field and a bit field. */
10707 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
10709 /* We can't yet handle bit-fields whose offsets are variable, so if we
10710 encounter such things, just return without generating any attribute
10711 whatsoever. Likewise for variable or too large size. */
10712 if (! host_integerp (bit_position (decl
), 0)
10713 || ! host_integerp (DECL_SIZE (decl
), 1))
10716 bitpos_int
= int_bit_position (decl
);
10718 /* Note that the bit offset is always the distance (in bits) from the
10719 highest-order bit of the "containing object" to the highest-order bit of
10720 the bit-field itself. Since the "high-order end" of any object or field
10721 is different on big-endian and little-endian machines, the computation
10722 below must take account of these differences. */
10723 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
10724 highest_order_field_bit_offset
= bitpos_int
;
10726 if (! BYTES_BIG_ENDIAN
)
10728 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
10729 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
10733 = (! BYTES_BIG_ENDIAN
10734 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
10735 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
10737 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
10740 /* For a FIELD_DECL node which represents a bit field, output an attribute
10741 which specifies the length in bits of the given field. */
10744 add_bit_size_attribute (dw_die_ref die
, tree decl
)
10746 /* Must be a field and a bit field. */
10747 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
10748 && DECL_BIT_FIELD_TYPE (decl
));
10750 if (host_integerp (DECL_SIZE (decl
), 1))
10751 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
10754 /* If the compiled language is ANSI C, then add a 'prototyped'
10755 attribute, if arg types are given for the parameters of a function. */
10758 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
10760 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
10761 && TYPE_ARG_TYPES (func_type
) != NULL
)
10762 add_AT_flag (die
, DW_AT_prototyped
, 1);
10765 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
10766 by looking in either the type declaration or object declaration
10770 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
10772 dw_die_ref origin_die
= NULL
;
10774 if (TREE_CODE (origin
) != FUNCTION_DECL
)
10776 /* We may have gotten separated from the block for the inlined
10777 function, if we're in an exception handler or some such; make
10778 sure that the abstract function has been written out.
10780 Doing this for nested functions is wrong, however; functions are
10781 distinct units, and our context might not even be inline. */
10785 fn
= TYPE_STUB_DECL (fn
);
10787 fn
= decl_function_context (fn
);
10789 dwarf2out_abstract_function (fn
);
10792 if (DECL_P (origin
))
10793 origin_die
= lookup_decl_die (origin
);
10794 else if (TYPE_P (origin
))
10795 origin_die
= lookup_type_die (origin
);
10797 /* XXX: Functions that are never lowered don't always have correct block
10798 trees (in the case of java, they simply have no block tree, in some other
10799 languages). For these functions, there is nothing we can really do to
10800 output correct debug info for inlined functions in all cases. Rather
10801 than die, we'll just produce deficient debug info now, in that we will
10802 have variables without a proper abstract origin. In the future, when all
10803 functions are lowered, we should re-add a gcc_assert (origin_die)
10807 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
10810 /* We do not currently support the pure_virtual attribute. */
10813 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
10815 if (DECL_VINDEX (func_decl
))
10817 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
10819 if (host_integerp (DECL_VINDEX (func_decl
), 0))
10820 add_AT_loc (die
, DW_AT_vtable_elem_location
,
10821 new_loc_descr (DW_OP_constu
,
10822 tree_low_cst (DECL_VINDEX (func_decl
), 0),
10825 /* GNU extension: Record what type this method came from originally. */
10826 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10827 add_AT_die_ref (die
, DW_AT_containing_type
,
10828 lookup_type_die (DECL_CONTEXT (func_decl
)));
10832 /* Add source coordinate attributes for the given decl. */
10835 add_src_coords_attributes (dw_die_ref die
, tree decl
)
10837 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
10838 unsigned file_index
= lookup_filename (s
.file
);
10840 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
10841 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
10844 /* Add a DW_AT_name attribute and source coordinate attribute for the
10845 given decl, but only if it actually has a name. */
10848 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
10852 decl_name
= DECL_NAME (decl
);
10853 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
10855 add_name_attribute (die
, dwarf2_name (decl
, 0));
10856 if (! DECL_ARTIFICIAL (decl
))
10857 add_src_coords_attributes (die
, decl
);
10859 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
10860 && TREE_PUBLIC (decl
)
10861 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
10862 && !DECL_ABSTRACT (decl
)
10863 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
)))
10864 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
10865 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
10868 #ifdef VMS_DEBUGGING_INFO
10869 /* Get the function's name, as described by its RTL. This may be different
10870 from the DECL_NAME name used in the source file. */
10871 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
10873 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
10874 XEXP (DECL_RTL (decl
), 0));
10875 VEC_safe_push (tree
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
10880 /* Push a new declaration scope. */
10883 push_decl_scope (tree scope
)
10885 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
10888 /* Pop a declaration scope. */
10891 pop_decl_scope (void)
10893 VEC_pop (tree
, decl_scope_table
);
10896 /* Return the DIE for the scope that immediately contains this type.
10897 Non-named types get global scope. Named types nested in other
10898 types get their containing scope if it's open, or global scope
10899 otherwise. All other types (i.e. function-local named types) get
10900 the current active scope. */
10903 scope_die_for (tree t
, dw_die_ref context_die
)
10905 dw_die_ref scope_die
= NULL
;
10906 tree containing_scope
;
10909 /* Non-types always go in the current scope. */
10910 gcc_assert (TYPE_P (t
));
10912 containing_scope
= TYPE_CONTEXT (t
);
10914 /* Use the containing namespace if it was passed in (for a declaration). */
10915 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
10917 if (context_die
== lookup_decl_die (containing_scope
))
10920 containing_scope
= NULL_TREE
;
10923 /* Ignore function type "scopes" from the C frontend. They mean that
10924 a tagged type is local to a parmlist of a function declarator, but
10925 that isn't useful to DWARF. */
10926 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
10927 containing_scope
= NULL_TREE
;
10929 if (containing_scope
== NULL_TREE
)
10930 scope_die
= comp_unit_die
;
10931 else if (TYPE_P (containing_scope
))
10933 /* For types, we can just look up the appropriate DIE. But
10934 first we check to see if we're in the middle of emitting it
10935 so we know where the new DIE should go. */
10936 for (i
= VEC_length (tree
, decl_scope_table
) - 1; i
>= 0; --i
)
10937 if (VEC_index (tree
, decl_scope_table
, i
) == containing_scope
)
10942 gcc_assert (debug_info_level
<= DINFO_LEVEL_TERSE
10943 || TREE_ASM_WRITTEN (containing_scope
));
10945 /* If none of the current dies are suitable, we get file scope. */
10946 scope_die
= comp_unit_die
;
10949 scope_die
= lookup_type_die (containing_scope
);
10952 scope_die
= context_die
;
10957 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
10960 local_scope_p (dw_die_ref context_die
)
10962 for (; context_die
; context_die
= context_die
->die_parent
)
10963 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
10964 || context_die
->die_tag
== DW_TAG_subprogram
)
10970 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
10971 whether or not to treat a DIE in this context as a declaration. */
10974 class_or_namespace_scope_p (dw_die_ref context_die
)
10976 return (context_die
10977 && (context_die
->die_tag
== DW_TAG_structure_type
10978 || context_die
->die_tag
== DW_TAG_union_type
10979 || context_die
->die_tag
== DW_TAG_namespace
));
10982 /* Many forms of DIEs require a "type description" attribute. This
10983 routine locates the proper "type descriptor" die for the type given
10984 by 'type', and adds a DW_AT_type attribute below the given die. */
10987 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
10988 int decl_volatile
, dw_die_ref context_die
)
10990 enum tree_code code
= TREE_CODE (type
);
10991 dw_die_ref type_die
= NULL
;
10993 /* ??? If this type is an unnamed subrange type of an integral or
10994 floating-point type, use the inner type. This is because we have no
10995 support for unnamed types in base_type_die. This can happen if this is
10996 an Ada subrange type. Correct solution is emit a subrange type die. */
10997 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
10998 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
10999 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
11001 if (code
== ERROR_MARK
11002 /* Handle a special case. For functions whose return type is void, we
11003 generate *no* type attribute. (Note that no object may have type
11004 `void', so this only applies to function return types). */
11005 || code
== VOID_TYPE
)
11008 type_die
= modified_type_die (type
,
11009 decl_const
|| TYPE_READONLY (type
),
11010 decl_volatile
|| TYPE_VOLATILE (type
),
11013 if (type_die
!= NULL
)
11014 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
11017 /* Given an object die, add the calling convention attribute for the
11018 function call type. */
11020 add_calling_convention_attribute (dw_die_ref subr_die
, tree type
)
11022 enum dwarf_calling_convention value
= DW_CC_normal
;
11024 value
= targetm
.dwarf_calling_convention (type
);
11026 /* Only add the attribute if the backend requests it, and
11027 is not DW_CC_normal. */
11028 if (value
&& (value
!= DW_CC_normal
))
11029 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
11032 /* Given a tree pointer to a struct, class, union, or enum type node, return
11033 a pointer to the (string) tag name for the given type, or zero if the type
11034 was declared without a tag. */
11036 static const char *
11037 type_tag (tree type
)
11039 const char *name
= 0;
11041 if (TYPE_NAME (type
) != 0)
11045 /* Find the IDENTIFIER_NODE for the type name. */
11046 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
11047 t
= TYPE_NAME (type
);
11049 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
11050 a TYPE_DECL node, regardless of whether or not a `typedef' was
11052 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
11053 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
11054 t
= DECL_NAME (TYPE_NAME (type
));
11056 /* Now get the name as a string, or invent one. */
11058 name
= IDENTIFIER_POINTER (t
);
11061 return (name
== 0 || *name
== '\0') ? 0 : name
;
11064 /* Return the type associated with a data member, make a special check
11065 for bit field types. */
11068 member_declared_type (tree member
)
11070 return (DECL_BIT_FIELD_TYPE (member
)
11071 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
11074 /* Get the decl's label, as described by its RTL. This may be different
11075 from the DECL_NAME name used in the source file. */
11078 static const char *
11079 decl_start_label (tree decl
)
11082 const char *fnname
;
11084 x
= DECL_RTL (decl
);
11085 gcc_assert (MEM_P (x
));
11088 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
11090 fnname
= XSTR (x
, 0);
11095 /* These routines generate the internal representation of the DIE's for
11096 the compilation unit. Debugging information is collected by walking
11097 the declaration trees passed in from dwarf2out_decl(). */
11100 gen_array_type_die (tree type
, dw_die_ref context_die
)
11102 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
11103 dw_die_ref array_die
;
11106 /* ??? The SGI dwarf reader fails for array of array of enum types unless
11107 the inner array type comes before the outer array type. Thus we must
11108 call gen_type_die before we call new_die. See below also. */
11109 #ifdef MIPS_DEBUGGING_INFO
11110 gen_type_die (TREE_TYPE (type
), context_die
);
11113 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
11114 add_name_attribute (array_die
, type_tag (type
));
11115 equate_type_number_to_die (type
, array_die
);
11117 if (TREE_CODE (type
) == VECTOR_TYPE
)
11119 /* The frontend feeds us a representation for the vector as a struct
11120 containing an array. Pull out the array type. */
11121 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
11122 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
11126 /* We default the array ordering. SDB will probably do
11127 the right things even if DW_AT_ordering is not present. It's not even
11128 an issue until we start to get into multidimensional arrays anyway. If
11129 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
11130 then we'll have to put the DW_AT_ordering attribute back in. (But if
11131 and when we find out that we need to put these in, we will only do so
11132 for multidimensional arrays. */
11133 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
11136 #ifdef MIPS_DEBUGGING_INFO
11137 /* The SGI compilers handle arrays of unknown bound by setting
11138 AT_declaration and not emitting any subrange DIEs. */
11139 if (! TYPE_DOMAIN (type
))
11140 add_AT_flag (array_die
, DW_AT_declaration
, 1);
11143 add_subscript_info (array_die
, type
);
11145 /* Add representation of the type of the elements of this array type. */
11146 element_type
= TREE_TYPE (type
);
11148 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11149 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11150 We work around this by disabling this feature. See also
11151 add_subscript_info. */
11152 #ifndef MIPS_DEBUGGING_INFO
11153 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
11154 element_type
= TREE_TYPE (element_type
);
11156 gen_type_die (element_type
, context_die
);
11159 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
11164 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
11166 tree origin
= decl_ultimate_origin (decl
);
11167 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
11169 if (origin
!= NULL
)
11170 add_abstract_origin_attribute (decl_die
, origin
);
11173 add_name_and_src_coords_attributes (decl_die
, decl
);
11174 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
11175 0, 0, context_die
);
11178 if (DECL_ABSTRACT (decl
))
11179 equate_decl_number_to_die (decl
, decl_die
);
11181 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
11185 /* Walk through the list of incomplete types again, trying once more to
11186 emit full debugging info for them. */
11189 retry_incomplete_types (void)
11193 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
11194 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die
);
11197 /* Generate a DIE to represent an inlined instance of an enumeration type. */
11200 gen_inlined_enumeration_type_die (tree type
, dw_die_ref context_die
)
11202 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
11204 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11205 be incomplete and such types are not marked. */
11206 add_abstract_origin_attribute (type_die
, type
);
11209 /* Generate a DIE to represent an inlined instance of a structure type. */
11212 gen_inlined_structure_type_die (tree type
, dw_die_ref context_die
)
11214 dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
, type
);
11216 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11217 be incomplete and such types are not marked. */
11218 add_abstract_origin_attribute (type_die
, type
);
11221 /* Generate a DIE to represent an inlined instance of a union type. */
11224 gen_inlined_union_type_die (tree type
, dw_die_ref context_die
)
11226 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
11228 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11229 be incomplete and such types are not marked. */
11230 add_abstract_origin_attribute (type_die
, type
);
11233 /* Generate a DIE to represent an enumeration type. Note that these DIEs
11234 include all of the information about the enumeration values also. Each
11235 enumerated type name/value is listed as a child of the enumerated type
11239 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
11241 dw_die_ref type_die
= lookup_type_die (type
);
11243 if (type_die
== NULL
)
11245 type_die
= new_die (DW_TAG_enumeration_type
,
11246 scope_die_for (type
, context_die
), type
);
11247 equate_type_number_to_die (type
, type_die
);
11248 add_name_attribute (type_die
, type_tag (type
));
11250 else if (! TYPE_SIZE (type
))
11253 remove_AT (type_die
, DW_AT_declaration
);
11255 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
11256 given enum type is incomplete, do not generate the DW_AT_byte_size
11257 attribute or the DW_AT_element_list attribute. */
11258 if (TYPE_SIZE (type
))
11262 TREE_ASM_WRITTEN (type
) = 1;
11263 add_byte_size_attribute (type_die
, type
);
11264 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
11265 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
11267 /* If the first reference to this type was as the return type of an
11268 inline function, then it may not have a parent. Fix this now. */
11269 if (type_die
->die_parent
== NULL
)
11270 add_child_die (scope_die_for (type
, context_die
), type_die
);
11272 for (link
= TYPE_VALUES (type
);
11273 link
!= NULL
; link
= TREE_CHAIN (link
))
11275 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
11276 tree value
= TREE_VALUE (link
);
11278 add_name_attribute (enum_die
,
11279 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
11281 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
11282 /* DWARF2 does not provide a way of indicating whether or
11283 not enumeration constants are signed or unsigned. GDB
11284 always assumes the values are signed, so we output all
11285 values as if they were signed. That means that
11286 enumeration constants with very large unsigned values
11287 will appear to have negative values in the debugger. */
11288 add_AT_int (enum_die
, DW_AT_const_value
,
11289 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
11293 add_AT_flag (type_die
, DW_AT_declaration
, 1);
11298 /* Generate a DIE to represent either a real live formal parameter decl or to
11299 represent just the type of some formal parameter position in some function
11302 Note that this routine is a bit unusual because its argument may be a
11303 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
11304 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
11305 node. If it's the former then this function is being called to output a
11306 DIE to represent a formal parameter object (or some inlining thereof). If
11307 it's the latter, then this function is only being called to output a
11308 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
11309 argument type of some subprogram type. */
11312 gen_formal_parameter_die (tree node
, dw_die_ref context_die
)
11314 dw_die_ref parm_die
11315 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
11318 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
11320 case tcc_declaration
:
11321 origin
= decl_ultimate_origin (node
);
11322 if (origin
!= NULL
)
11323 add_abstract_origin_attribute (parm_die
, origin
);
11326 add_name_and_src_coords_attributes (parm_die
, node
);
11327 add_type_attribute (parm_die
, TREE_TYPE (node
),
11328 TREE_READONLY (node
),
11329 TREE_THIS_VOLATILE (node
),
11331 if (DECL_ARTIFICIAL (node
))
11332 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
11335 equate_decl_number_to_die (node
, parm_die
);
11336 if (! DECL_ABSTRACT (node
))
11337 add_location_or_const_value_attribute (parm_die
, node
, DW_AT_location
);
11342 /* We were called with some kind of a ..._TYPE node. */
11343 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
11347 gcc_unreachable ();
11353 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
11354 at the end of an (ANSI prototyped) formal parameters list. */
11357 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
11359 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
11362 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
11363 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
11364 parameters as specified in some function type specification (except for
11365 those which appear as part of a function *definition*). */
11368 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
11371 tree formal_type
= NULL
;
11372 tree first_parm_type
;
11375 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
11377 arg
= DECL_ARGUMENTS (function_or_method_type
);
11378 function_or_method_type
= TREE_TYPE (function_or_method_type
);
11383 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
11385 /* Make our first pass over the list of formal parameter types and output a
11386 DW_TAG_formal_parameter DIE for each one. */
11387 for (link
= first_parm_type
; link
; )
11389 dw_die_ref parm_die
;
11391 formal_type
= TREE_VALUE (link
);
11392 if (formal_type
== void_type_node
)
11395 /* Output a (nameless) DIE to represent the formal parameter itself. */
11396 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
11397 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
11398 && link
== first_parm_type
)
11399 || (arg
&& DECL_ARTIFICIAL (arg
)))
11400 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
11402 link
= TREE_CHAIN (link
);
11404 arg
= TREE_CHAIN (arg
);
11407 /* If this function type has an ellipsis, add a
11408 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
11409 if (formal_type
!= void_type_node
)
11410 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
11412 /* Make our second (and final) pass over the list of formal parameter types
11413 and output DIEs to represent those types (as necessary). */
11414 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
11415 link
&& TREE_VALUE (link
);
11416 link
= TREE_CHAIN (link
))
11417 gen_type_die (TREE_VALUE (link
), context_die
);
11420 /* We want to generate the DIE for TYPE so that we can generate the
11421 die for MEMBER, which has been defined; we will need to refer back
11422 to the member declaration nested within TYPE. If we're trying to
11423 generate minimal debug info for TYPE, processing TYPE won't do the
11424 trick; we need to attach the member declaration by hand. */
11427 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
11429 gen_type_die (type
, context_die
);
11431 /* If we're trying to avoid duplicate debug info, we may not have
11432 emitted the member decl for this function. Emit it now. */
11433 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
11434 && ! lookup_decl_die (member
))
11436 dw_die_ref type_die
;
11437 gcc_assert (!decl_ultimate_origin (member
));
11439 push_decl_scope (type
);
11440 type_die
= lookup_type_die (type
);
11441 if (TREE_CODE (member
) == FUNCTION_DECL
)
11442 gen_subprogram_die (member
, type_die
);
11443 else if (TREE_CODE (member
) == FIELD_DECL
)
11445 /* Ignore the nameless fields that are used to skip bits but handle
11446 C++ anonymous unions and structs. */
11447 if (DECL_NAME (member
) != NULL_TREE
11448 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
11449 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
11451 gen_type_die (member_declared_type (member
), type_die
);
11452 gen_field_die (member
, type_die
);
11456 gen_variable_die (member
, type_die
);
11462 /* Generate the DWARF2 info for the "abstract" instance of a function which we
11463 may later generate inlined and/or out-of-line instances of. */
11466 dwarf2out_abstract_function (tree decl
)
11468 dw_die_ref old_die
;
11471 int was_abstract
= DECL_ABSTRACT (decl
);
11473 /* Make sure we have the actual abstract inline, not a clone. */
11474 decl
= DECL_ORIGIN (decl
);
11476 old_die
= lookup_decl_die (decl
);
11477 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
11478 /* We've already generated the abstract instance. */
11481 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
11482 we don't get confused by DECL_ABSTRACT. */
11483 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11485 context
= decl_class_context (decl
);
11487 gen_type_die_for_member
11488 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
11491 /* Pretend we've just finished compiling this function. */
11492 save_fn
= current_function_decl
;
11493 current_function_decl
= decl
;
11495 set_decl_abstract_flags (decl
, 1);
11496 dwarf2out_decl (decl
);
11497 if (! was_abstract
)
11498 set_decl_abstract_flags (decl
, 0);
11500 current_function_decl
= save_fn
;
11503 /* Generate a DIE to represent a declared function (either file-scope or
11507 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
11509 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
11510 tree origin
= decl_ultimate_origin (decl
);
11511 dw_die_ref subr_die
;
11514 dw_die_ref old_die
= lookup_decl_die (decl
);
11515 int declaration
= (current_function_decl
!= decl
11516 || class_or_namespace_scope_p (context_die
));
11518 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
11519 started to generate the abstract instance of an inline, decided to output
11520 its containing class, and proceeded to emit the declaration of the inline
11521 from the member list for the class. If so, DECLARATION takes priority;
11522 we'll get back to the abstract instance when done with the class. */
11524 /* The class-scope declaration DIE must be the primary DIE. */
11525 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
11528 gcc_assert (!old_die
);
11531 /* Now that the C++ front end lazily declares artificial member fns, we
11532 might need to retrofit the declaration into its class. */
11533 if (!declaration
&& !origin
&& !old_die
11534 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
11535 && !class_or_namespace_scope_p (context_die
)
11536 && debug_info_level
> DINFO_LEVEL_TERSE
)
11537 old_die
= force_decl_die (decl
);
11539 if (origin
!= NULL
)
11541 gcc_assert (!declaration
|| local_scope_p (context_die
));
11543 /* Fixup die_parent for the abstract instance of a nested
11544 inline function. */
11545 if (old_die
&& old_die
->die_parent
== NULL
)
11546 add_child_die (context_die
, old_die
);
11548 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11549 add_abstract_origin_attribute (subr_die
, origin
);
11553 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
11554 unsigned file_index
= lookup_filename (s
.file
);
11556 if (!get_AT_flag (old_die
, DW_AT_declaration
)
11557 /* We can have a normal definition following an inline one in the
11558 case of redefinition of GNU C extern inlines.
11559 It seems reasonable to use AT_specification in this case. */
11560 && !get_AT (old_die
, DW_AT_inline
))
11562 /* Detect and ignore this case, where we are trying to output
11563 something we have already output. */
11567 /* If the definition comes from the same place as the declaration,
11568 maybe use the old DIE. We always want the DIE for this function
11569 that has the *_pc attributes to be under comp_unit_die so the
11570 debugger can find it. We also need to do this for abstract
11571 instances of inlines, since the spec requires the out-of-line copy
11572 to have the same parent. For local class methods, this doesn't
11573 apply; we just use the old DIE. */
11574 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
11575 && (DECL_ARTIFICIAL (decl
)
11576 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
11577 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11578 == (unsigned) s
.line
))))
11580 subr_die
= old_die
;
11582 /* Clear out the declaration attribute and the formal parameters.
11583 Do not remove all children, because it is possible that this
11584 declaration die was forced using force_decl_die(). In such
11585 cases die that forced declaration die (e.g. TAG_imported_module)
11586 is one of the children that we do not want to remove. */
11587 remove_AT (subr_die
, DW_AT_declaration
);
11588 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
11592 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11593 add_AT_specification (subr_die
, old_die
);
11594 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
11595 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
11596 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11597 != (unsigned) s
.line
)
11599 (subr_die
, DW_AT_decl_line
, s
.line
);
11604 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11606 if (TREE_PUBLIC (decl
))
11607 add_AT_flag (subr_die
, DW_AT_external
, 1);
11609 add_name_and_src_coords_attributes (subr_die
, decl
);
11610 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11612 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
11613 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
11614 0, 0, context_die
);
11617 add_pure_or_virtual_attribute (subr_die
, decl
);
11618 if (DECL_ARTIFICIAL (decl
))
11619 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
11621 if (TREE_PROTECTED (decl
))
11622 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11623 else if (TREE_PRIVATE (decl
))
11624 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11629 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
11631 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
11633 /* The first time we see a member function, it is in the context of
11634 the class to which it belongs. We make sure of this by emitting
11635 the class first. The next time is the definition, which is
11636 handled above. The two may come from the same source text.
11638 Note that force_decl_die() forces function declaration die. It is
11639 later reused to represent definition. */
11640 equate_decl_number_to_die (decl
, subr_die
);
11643 else if (DECL_ABSTRACT (decl
))
11645 if (DECL_DECLARED_INLINE_P (decl
))
11647 if (cgraph_function_possibly_inlined_p (decl
))
11648 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
11650 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
11654 if (cgraph_function_possibly_inlined_p (decl
))
11655 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
11657 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
11660 equate_decl_number_to_die (decl
, subr_die
);
11662 else if (!DECL_EXTERNAL (decl
))
11664 HOST_WIDE_INT cfa_fb_offset
;
11666 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
11667 equate_decl_number_to_die (decl
, subr_die
);
11669 if (!flag_reorder_blocks_and_partition
)
11671 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
11672 current_function_funcdef_no
);
11673 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
11674 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
11675 current_function_funcdef_no
);
11676 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
11678 add_pubname (decl
, subr_die
);
11679 add_arange (decl
, subr_die
);
11682 { /* Do nothing for now; maybe need to duplicate die, one for
11683 hot section and ond for cold section, then use the hot/cold
11684 section begin/end labels to generate the aranges... */
11686 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
11687 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
11688 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
11689 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
11691 add_pubname (decl, subr_die);
11692 add_arange (decl, subr_die);
11693 add_arange (decl, subr_die);
11697 #ifdef MIPS_DEBUGGING_INFO
11698 /* Add a reference to the FDE for this routine. */
11699 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
11702 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
11704 /* We define the "frame base" as the function's CFA. This is more
11705 convenient for several reasons: (1) It's stable across the prologue
11706 and epilogue, which makes it better than just a frame pointer,
11707 (2) With dwarf3, there exists a one-byte encoding that allows us
11708 to reference the .debug_frame data by proxy, but failing that,
11709 (3) We can at least reuse the code inspection and interpretation
11710 code that determines the CFA position at various points in the
11712 /* ??? Use some command-line or configury switch to enable the use
11713 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
11714 consumers that understand it; fall back to "pure" dwarf2 and
11715 convert the CFA data into a location list. */
11717 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
11718 if (list
->dw_loc_next
)
11719 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
11721 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
11724 /* Compute a displacement from the "steady-state frame pointer" to
11725 the CFA. The former is what all stack slots and argument slots
11726 will reference in the rtl; the later is what we've told the
11727 debugger about. We'll need to adjust all frame_base references
11728 by this displacement. */
11729 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
11731 if (cfun
->static_chain_decl
)
11732 add_AT_location_description (subr_die
, DW_AT_static_link
,
11733 loc_descriptor_from_tree (cfun
->static_chain_decl
));
11736 /* Now output descriptions of the arguments for this function. This gets
11737 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
11738 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
11739 `...' at the end of the formal parameter list. In order to find out if
11740 there was a trailing ellipsis or not, we must instead look at the type
11741 associated with the FUNCTION_DECL. This will be a node of type
11742 FUNCTION_TYPE. If the chain of type nodes hanging off of this
11743 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
11744 an ellipsis at the end. */
11746 /* In the case where we are describing a mere function declaration, all we
11747 need to do here (and all we *can* do here) is to describe the *types* of
11748 its formal parameters. */
11749 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11751 else if (declaration
)
11752 gen_formal_types_die (decl
, subr_die
);
11755 /* Generate DIEs to represent all known formal parameters. */
11756 tree arg_decls
= DECL_ARGUMENTS (decl
);
11759 /* When generating DIEs, generate the unspecified_parameters DIE
11760 instead if we come across the arg "__builtin_va_alist" */
11761 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
11762 if (TREE_CODE (parm
) == PARM_DECL
)
11764 if (DECL_NAME (parm
)
11765 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
11766 "__builtin_va_alist"))
11767 gen_unspecified_parameters_die (parm
, subr_die
);
11769 gen_decl_die (parm
, subr_die
);
11772 /* Decide whether we need an unspecified_parameters DIE at the end.
11773 There are 2 more cases to do this for: 1) the ansi ... declaration -
11774 this is detectable when the end of the arg list is not a
11775 void_type_node 2) an unprototyped function declaration (not a
11776 definition). This just means that we have no info about the
11777 parameters at all. */
11778 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
11779 if (fn_arg_types
!= NULL
)
11781 /* This is the prototyped case, check for.... */
11782 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
11783 gen_unspecified_parameters_die (decl
, subr_die
);
11785 else if (DECL_INITIAL (decl
) == NULL_TREE
)
11786 gen_unspecified_parameters_die (decl
, subr_die
);
11789 /* Output Dwarf info for all of the stuff within the body of the function
11790 (if it has one - it may be just a declaration). */
11791 outer_scope
= DECL_INITIAL (decl
);
11793 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
11794 a function. This BLOCK actually represents the outermost binding contour
11795 for the function, i.e. the contour in which the function's formal
11796 parameters and labels get declared. Curiously, it appears that the front
11797 end doesn't actually put the PARM_DECL nodes for the current function onto
11798 the BLOCK_VARS list for this outer scope, but are strung off of the
11799 DECL_ARGUMENTS list for the function instead.
11801 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
11802 the LABEL_DECL nodes for the function however, and we output DWARF info
11803 for those in decls_for_scope. Just within the `outer_scope' there will be
11804 a BLOCK node representing the function's outermost pair of curly braces,
11805 and any blocks used for the base and member initializers of a C++
11806 constructor function. */
11807 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
11809 /* Emit a DW_TAG_variable DIE for a named return value. */
11810 if (DECL_NAME (DECL_RESULT (decl
)))
11811 gen_decl_die (DECL_RESULT (decl
), subr_die
);
11813 current_function_has_inlines
= 0;
11814 decls_for_scope (outer_scope
, subr_die
, 0);
11816 #if 0 && defined (MIPS_DEBUGGING_INFO)
11817 if (current_function_has_inlines
)
11819 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
11820 if (! comp_unit_has_inlines
)
11822 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
11823 comp_unit_has_inlines
= 1;
11828 /* Add the calling convention attribute if requested. */
11829 add_calling_convention_attribute (subr_die
, TREE_TYPE (decl
));
11833 /* Generate a DIE to represent a declared data object. */
11836 gen_variable_die (tree decl
, dw_die_ref context_die
)
11838 tree origin
= decl_ultimate_origin (decl
);
11839 dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
11841 dw_die_ref old_die
= lookup_decl_die (decl
);
11842 int declaration
= (DECL_EXTERNAL (decl
)
11843 /* If DECL is COMDAT and has not actually been
11844 emitted, we cannot take its address; there
11845 might end up being no definition anywhere in
11846 the program. For example, consider the C++
11850 struct S { static const int i = 7; };
11855 int f() { return S<int>::i; }
11857 Here, S<int>::i is not DECL_EXTERNAL, but no
11858 definition is required, so the compiler will
11859 not emit a definition. */
11860 || (TREE_CODE (decl
) == VAR_DECL
11861 && DECL_COMDAT (decl
) && !TREE_ASM_WRITTEN (decl
))
11862 || class_or_namespace_scope_p (context_die
));
11864 if (origin
!= NULL
)
11865 add_abstract_origin_attribute (var_die
, origin
);
11867 /* Loop unrolling can create multiple blocks that refer to the same
11868 static variable, so we must test for the DW_AT_declaration flag.
11870 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
11871 copy decls and set the DECL_ABSTRACT flag on them instead of
11874 ??? Duplicated blocks have been rewritten to use .debug_ranges.
11876 ??? The declare_in_namespace support causes us to get two DIEs for one
11877 variable, both of which are declarations. We want to avoid considering
11878 one to be a specification, so we must test that this DIE is not a
11880 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
11881 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
11883 /* This is a definition of a C++ class level static. */
11884 add_AT_specification (var_die
, old_die
);
11885 if (DECL_NAME (decl
))
11887 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
11888 unsigned file_index
= lookup_filename (s
.file
);
11890 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
11891 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
11893 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11894 != (unsigned) s
.line
)
11896 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
11901 add_name_and_src_coords_attributes (var_die
, decl
);
11902 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
11903 TREE_THIS_VOLATILE (decl
), context_die
);
11905 if (TREE_PUBLIC (decl
))
11906 add_AT_flag (var_die
, DW_AT_external
, 1);
11908 if (DECL_ARTIFICIAL (decl
))
11909 add_AT_flag (var_die
, DW_AT_artificial
, 1);
11911 if (TREE_PROTECTED (decl
))
11912 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11913 else if (TREE_PRIVATE (decl
))
11914 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11918 add_AT_flag (var_die
, DW_AT_declaration
, 1);
11920 if (DECL_ABSTRACT (decl
) || declaration
)
11921 equate_decl_number_to_die (decl
, var_die
);
11923 if (! declaration
&& ! DECL_ABSTRACT (decl
))
11925 add_location_or_const_value_attribute (var_die
, decl
, DW_AT_location
);
11926 add_pubname (decl
, var_die
);
11929 tree_add_const_value_attribute (var_die
, decl
);
11932 /* Generate a DIE to represent a label identifier. */
11935 gen_label_die (tree decl
, dw_die_ref context_die
)
11937 tree origin
= decl_ultimate_origin (decl
);
11938 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
11940 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11942 if (origin
!= NULL
)
11943 add_abstract_origin_attribute (lbl_die
, origin
);
11945 add_name_and_src_coords_attributes (lbl_die
, decl
);
11947 if (DECL_ABSTRACT (decl
))
11948 equate_decl_number_to_die (decl
, lbl_die
);
11951 insn
= DECL_RTL_IF_SET (decl
);
11953 /* Deleted labels are programmer specified labels which have been
11954 eliminated because of various optimizations. We still emit them
11955 here so that it is possible to put breakpoints on them. */
11959 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
))))
11961 /* When optimization is enabled (via -O) some parts of the compiler
11962 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
11963 represent source-level labels which were explicitly declared by
11964 the user. This really shouldn't be happening though, so catch
11965 it if it ever does happen. */
11966 gcc_assert (!INSN_DELETED_P (insn
));
11968 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
11969 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
11974 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
11975 attributes to the DIE for a block STMT, to describe where the inlined
11976 function was called from. This is similar to add_src_coords_attributes. */
11979 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
11981 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
11982 unsigned file_index
= lookup_filename (s
.file
);
11984 add_AT_unsigned (die
, DW_AT_call_file
, file_index
);
11985 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
11988 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
11989 Add low_pc and high_pc attributes to the DIE for a block STMT. */
11992 add_high_low_attributes (tree stmt
, dw_die_ref die
)
11994 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11996 if (BLOCK_FRAGMENT_CHAIN (stmt
))
12000 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
12002 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
12005 add_ranges (chain
);
12006 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
12013 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
12014 BLOCK_NUMBER (stmt
));
12015 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
12016 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
12017 BLOCK_NUMBER (stmt
));
12018 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
12022 /* Generate a DIE for a lexical block. */
12025 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
12027 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
12029 if (! BLOCK_ABSTRACT (stmt
))
12030 add_high_low_attributes (stmt
, stmt_die
);
12032 decls_for_scope (stmt
, stmt_die
, depth
);
12035 /* Generate a DIE for an inlined subprogram. */
12038 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
12040 tree decl
= block_ultimate_origin (stmt
);
12042 /* Emit info for the abstract instance first, if we haven't yet. We
12043 must emit this even if the block is abstract, otherwise when we
12044 emit the block below (or elsewhere), we may end up trying to emit
12045 a die whose origin die hasn't been emitted, and crashing. */
12046 dwarf2out_abstract_function (decl
);
12048 if (! BLOCK_ABSTRACT (stmt
))
12050 dw_die_ref subr_die
12051 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
12053 add_abstract_origin_attribute (subr_die
, decl
);
12054 add_high_low_attributes (stmt
, subr_die
);
12055 add_call_src_coords_attributes (stmt
, subr_die
);
12057 decls_for_scope (stmt
, subr_die
, depth
);
12058 current_function_has_inlines
= 1;
12061 /* We may get here if we're the outer block of function A that was
12062 inlined into function B that was inlined into function C. When
12063 generating debugging info for C, dwarf2out_abstract_function(B)
12064 would mark all inlined blocks as abstract, including this one.
12065 So, we wouldn't (and shouldn't) expect labels to be generated
12066 for this one. Instead, just emit debugging info for
12067 declarations within the block. This is particularly important
12068 in the case of initializers of arguments passed from B to us:
12069 if they're statement expressions containing declarations, we
12070 wouldn't generate dies for their abstract variables, and then,
12071 when generating dies for the real variables, we'd die (pun
12073 gen_lexical_block_die (stmt
, context_die
, depth
);
12076 /* Generate a DIE for a field in a record, or structure. */
12079 gen_field_die (tree decl
, dw_die_ref context_die
)
12081 dw_die_ref decl_die
;
12083 if (TREE_TYPE (decl
) == error_mark_node
)
12086 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
12087 add_name_and_src_coords_attributes (decl_die
, decl
);
12088 add_type_attribute (decl_die
, member_declared_type (decl
),
12089 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
12092 if (DECL_BIT_FIELD_TYPE (decl
))
12094 add_byte_size_attribute (decl_die
, decl
);
12095 add_bit_size_attribute (decl_die
, decl
);
12096 add_bit_offset_attribute (decl_die
, decl
);
12099 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
12100 add_data_member_location_attribute (decl_die
, decl
);
12102 if (DECL_ARTIFICIAL (decl
))
12103 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
12105 if (TREE_PROTECTED (decl
))
12106 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
12107 else if (TREE_PRIVATE (decl
))
12108 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
12110 /* Equate decl number to die, so that we can look up this decl later on. */
12111 equate_decl_number_to_die (decl
, decl_die
);
12115 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12116 Use modified_type_die instead.
12117 We keep this code here just in case these types of DIEs may be needed to
12118 represent certain things in other languages (e.g. Pascal) someday. */
12121 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
12124 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
12126 equate_type_number_to_die (type
, ptr_die
);
12127 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
12128 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
12131 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12132 Use modified_type_die instead.
12133 We keep this code here just in case these types of DIEs may be needed to
12134 represent certain things in other languages (e.g. Pascal) someday. */
12137 gen_reference_type_die (tree type
, dw_die_ref context_die
)
12140 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
12142 equate_type_number_to_die (type
, ref_die
);
12143 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
12144 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
12148 /* Generate a DIE for a pointer to a member type. */
12151 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
12154 = new_die (DW_TAG_ptr_to_member_type
,
12155 scope_die_for (type
, context_die
), type
);
12157 equate_type_number_to_die (type
, ptr_die
);
12158 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
12159 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
12160 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
12163 /* Generate the DIE for the compilation unit. */
12166 gen_compile_unit_die (const char *filename
)
12169 char producer
[250];
12170 const char *language_string
= lang_hooks
.name
;
12173 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
12177 add_name_attribute (die
, filename
);
12178 /* Don't add cwd for <built-in>. */
12179 if (filename
[0] != DIR_SEPARATOR
&& filename
[0] != '<')
12180 add_comp_dir_attribute (die
);
12183 sprintf (producer
, "%s %s", language_string
, version_string
);
12185 #ifdef MIPS_DEBUGGING_INFO
12186 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
12187 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
12188 not appear in the producer string, the debugger reaches the conclusion
12189 that the object file is stripped and has no debugging information.
12190 To get the MIPS/SGI debugger to believe that there is debugging
12191 information in the object file, we add a -g to the producer string. */
12192 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12193 strcat (producer
, " -g");
12196 add_AT_string (die
, DW_AT_producer
, producer
);
12198 if (strcmp (language_string
, "GNU C++") == 0)
12199 language
= DW_LANG_C_plus_plus
;
12200 else if (strcmp (language_string
, "GNU Ada") == 0)
12201 language
= DW_LANG_Ada95
;
12202 else if (strcmp (language_string
, "GNU F77") == 0)
12203 language
= DW_LANG_Fortran77
;
12204 else if (strcmp (language_string
, "GNU F95") == 0)
12205 language
= DW_LANG_Fortran95
;
12206 else if (strcmp (language_string
, "GNU Pascal") == 0)
12207 language
= DW_LANG_Pascal83
;
12208 else if (strcmp (language_string
, "GNU Java") == 0)
12209 language
= DW_LANG_Java
;
12211 language
= DW_LANG_C89
;
12213 add_AT_unsigned (die
, DW_AT_language
, language
);
12217 /* Generate the DIE for a base class. */
12220 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
12222 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
12224 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
12225 add_data_member_location_attribute (die
, binfo
);
12227 if (BINFO_VIRTUAL_P (binfo
))
12228 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
12230 if (access
== access_public_node
)
12231 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
12232 else if (access
== access_protected_node
)
12233 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
12236 /* Generate a DIE for a class member. */
12239 gen_member_die (tree type
, dw_die_ref context_die
)
12242 tree binfo
= TYPE_BINFO (type
);
12245 /* If this is not an incomplete type, output descriptions of each of its
12246 members. Note that as we output the DIEs necessary to represent the
12247 members of this record or union type, we will also be trying to output
12248 DIEs to represent the *types* of those members. However the `type'
12249 function (above) will specifically avoid generating type DIEs for member
12250 types *within* the list of member DIEs for this (containing) type except
12251 for those types (of members) which are explicitly marked as also being
12252 members of this (containing) type themselves. The g++ front- end can
12253 force any given type to be treated as a member of some other (containing)
12254 type by setting the TYPE_CONTEXT of the given (member) type to point to
12255 the TREE node representing the appropriate (containing) type. */
12257 /* First output info about the base classes. */
12260 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
12264 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
12265 gen_inheritance_die (base
,
12266 (accesses
? VEC_index (tree
, accesses
, i
)
12267 : access_public_node
), context_die
);
12270 /* Now output info about the data members and type members. */
12271 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
12273 /* If we thought we were generating minimal debug info for TYPE
12274 and then changed our minds, some of the member declarations
12275 may have already been defined. Don't define them again, but
12276 do put them in the right order. */
12278 child
= lookup_decl_die (member
);
12280 splice_child_die (context_die
, child
);
12282 gen_decl_die (member
, context_die
);
12285 /* Now output info about the function members (if any). */
12286 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
12288 /* Don't include clones in the member list. */
12289 if (DECL_ABSTRACT_ORIGIN (member
))
12292 child
= lookup_decl_die (member
);
12294 splice_child_die (context_die
, child
);
12296 gen_decl_die (member
, context_die
);
12300 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
12301 is set, we pretend that the type was never defined, so we only get the
12302 member DIEs needed by later specification DIEs. */
12305 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
)
12307 dw_die_ref type_die
= lookup_type_die (type
);
12308 dw_die_ref scope_die
= 0;
12310 int complete
= (TYPE_SIZE (type
)
12311 && (! TYPE_STUB_DECL (type
)
12312 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
12313 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
12315 if (type_die
&& ! complete
)
12318 if (TYPE_CONTEXT (type
) != NULL_TREE
12319 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
12320 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
12323 scope_die
= scope_die_for (type
, context_die
);
12325 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
12326 /* First occurrence of type or toplevel definition of nested class. */
12328 dw_die_ref old_die
= type_die
;
12330 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
12331 ? DW_TAG_structure_type
: DW_TAG_union_type
,
12333 equate_type_number_to_die (type
, type_die
);
12335 add_AT_specification (type_die
, old_die
);
12337 add_name_attribute (type_die
, type_tag (type
));
12340 remove_AT (type_die
, DW_AT_declaration
);
12342 /* If this type has been completed, then give it a byte_size attribute and
12343 then give a list of members. */
12344 if (complete
&& !ns_decl
)
12346 /* Prevent infinite recursion in cases where the type of some member of
12347 this type is expressed in terms of this type itself. */
12348 TREE_ASM_WRITTEN (type
) = 1;
12349 add_byte_size_attribute (type_die
, type
);
12350 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
12351 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
12353 /* If the first reference to this type was as the return type of an
12354 inline function, then it may not have a parent. Fix this now. */
12355 if (type_die
->die_parent
== NULL
)
12356 add_child_die (scope_die
, type_die
);
12358 push_decl_scope (type
);
12359 gen_member_die (type
, type_die
);
12362 /* GNU extension: Record what type our vtable lives in. */
12363 if (TYPE_VFIELD (type
))
12365 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
12367 gen_type_die (vtype
, context_die
);
12368 add_AT_die_ref (type_die
, DW_AT_containing_type
,
12369 lookup_type_die (vtype
));
12374 add_AT_flag (type_die
, DW_AT_declaration
, 1);
12376 /* We don't need to do this for function-local types. */
12377 if (TYPE_STUB_DECL (type
)
12378 && ! decl_function_context (TYPE_STUB_DECL (type
)))
12379 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
12383 /* Generate a DIE for a subroutine _type_. */
12386 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
12388 tree return_type
= TREE_TYPE (type
);
12389 dw_die_ref subr_die
12390 = new_die (DW_TAG_subroutine_type
,
12391 scope_die_for (type
, context_die
), type
);
12393 equate_type_number_to_die (type
, subr_die
);
12394 add_prototyped_attribute (subr_die
, type
);
12395 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
12396 gen_formal_types_die (type
, subr_die
);
12399 /* Generate a DIE for a type definition. */
12402 gen_typedef_die (tree decl
, dw_die_ref context_die
)
12404 dw_die_ref type_die
;
12407 if (TREE_ASM_WRITTEN (decl
))
12410 TREE_ASM_WRITTEN (decl
) = 1;
12411 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
12412 origin
= decl_ultimate_origin (decl
);
12413 if (origin
!= NULL
)
12414 add_abstract_origin_attribute (type_die
, origin
);
12419 add_name_and_src_coords_attributes (type_die
, decl
);
12420 if (DECL_ORIGINAL_TYPE (decl
))
12422 type
= DECL_ORIGINAL_TYPE (decl
);
12424 gcc_assert (type
!= TREE_TYPE (decl
));
12425 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
12428 type
= TREE_TYPE (decl
);
12430 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
12431 TREE_THIS_VOLATILE (decl
), context_die
);
12434 if (DECL_ABSTRACT (decl
))
12435 equate_decl_number_to_die (decl
, type_die
);
12438 /* Generate a type description DIE. */
12441 gen_type_die (tree type
, dw_die_ref context_die
)
12445 if (type
== NULL_TREE
|| type
== error_mark_node
)
12448 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12449 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
12451 if (TREE_ASM_WRITTEN (type
))
12454 /* Prevent broken recursion; we can't hand off to the same type. */
12455 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
12457 TREE_ASM_WRITTEN (type
) = 1;
12458 gen_decl_die (TYPE_NAME (type
), context_die
);
12462 /* We are going to output a DIE to represent the unqualified version
12463 of this type (i.e. without any const or volatile qualifiers) so
12464 get the main variant (i.e. the unqualified version) of this type
12465 now. (Vectors are special because the debugging info is in the
12466 cloned type itself). */
12467 if (TREE_CODE (type
) != VECTOR_TYPE
)
12468 type
= type_main_variant (type
);
12470 if (TREE_ASM_WRITTEN (type
))
12473 switch (TREE_CODE (type
))
12479 case REFERENCE_TYPE
:
12480 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
12481 ensures that the gen_type_die recursion will terminate even if the
12482 type is recursive. Recursive types are possible in Ada. */
12483 /* ??? We could perhaps do this for all types before the switch
12485 TREE_ASM_WRITTEN (type
) = 1;
12487 /* For these types, all that is required is that we output a DIE (or a
12488 set of DIEs) to represent the "basis" type. */
12489 gen_type_die (TREE_TYPE (type
), context_die
);
12493 /* This code is used for C++ pointer-to-data-member types.
12494 Output a description of the relevant class type. */
12495 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
12497 /* Output a description of the type of the object pointed to. */
12498 gen_type_die (TREE_TYPE (type
), context_die
);
12500 /* Now output a DIE to represent this pointer-to-data-member type
12502 gen_ptr_to_mbr_type_die (type
, context_die
);
12505 case FUNCTION_TYPE
:
12506 /* Force out return type (in case it wasn't forced out already). */
12507 gen_type_die (TREE_TYPE (type
), context_die
);
12508 gen_subroutine_type_die (type
, context_die
);
12512 /* Force out return type (in case it wasn't forced out already). */
12513 gen_type_die (TREE_TYPE (type
), context_die
);
12514 gen_subroutine_type_die (type
, context_die
);
12518 gen_array_type_die (type
, context_die
);
12522 gen_array_type_die (type
, context_die
);
12525 case ENUMERAL_TYPE
:
12528 case QUAL_UNION_TYPE
:
12529 /* If this is a nested type whose containing class hasn't been written
12530 out yet, writing it out will cover this one, too. This does not apply
12531 to instantiations of member class templates; they need to be added to
12532 the containing class as they are generated. FIXME: This hurts the
12533 idea of combining type decls from multiple TUs, since we can't predict
12534 what set of template instantiations we'll get. */
12535 if (TYPE_CONTEXT (type
)
12536 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
12537 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
12539 gen_type_die (TYPE_CONTEXT (type
), context_die
);
12541 if (TREE_ASM_WRITTEN (type
))
12544 /* If that failed, attach ourselves to the stub. */
12545 push_decl_scope (TYPE_CONTEXT (type
));
12546 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
12551 declare_in_namespace (type
, context_die
);
12555 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
12556 gen_enumeration_type_die (type
, context_die
);
12558 gen_struct_or_union_type_die (type
, context_die
);
12563 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
12564 it up if it is ever completed. gen_*_type_die will set it for us
12565 when appropriate. */
12573 /* No DIEs needed for fundamental types. */
12577 /* No Dwarf representation currently defined. */
12581 gcc_unreachable ();
12584 TREE_ASM_WRITTEN (type
) = 1;
12587 /* Generate a DIE for a tagged type instantiation. */
12590 gen_tagged_type_instantiation_die (tree type
, dw_die_ref context_die
)
12592 if (type
== NULL_TREE
|| type
== error_mark_node
)
12595 /* We are going to output a DIE to represent the unqualified version of
12596 this type (i.e. without any const or volatile qualifiers) so make sure
12597 that we have the main variant (i.e. the unqualified version) of this
12599 gcc_assert (type
== type_main_variant (type
));
12601 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
12602 an instance of an unresolved type. */
12604 switch (TREE_CODE (type
))
12609 case ENUMERAL_TYPE
:
12610 gen_inlined_enumeration_type_die (type
, context_die
);
12614 gen_inlined_structure_type_die (type
, context_die
);
12618 case QUAL_UNION_TYPE
:
12619 gen_inlined_union_type_die (type
, context_die
);
12623 gcc_unreachable ();
12627 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
12628 things which are local to the given block. */
12631 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
12633 int must_output_die
= 0;
12636 enum tree_code origin_code
;
12638 /* Ignore blocks that are NULL. */
12639 if (stmt
== NULL_TREE
)
12642 /* If the block is one fragment of a non-contiguous block, do not
12643 process the variables, since they will have been done by the
12644 origin block. Do process subblocks. */
12645 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
12649 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
12650 gen_block_die (sub
, context_die
, depth
+ 1);
12655 /* Determine the "ultimate origin" of this block. This block may be an
12656 inlined instance of an inlined instance of inline function, so we have
12657 to trace all of the way back through the origin chain to find out what
12658 sort of node actually served as the original seed for the creation of
12659 the current block. */
12660 origin
= block_ultimate_origin (stmt
);
12661 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
12663 /* Determine if we need to output any Dwarf DIEs at all to represent this
12665 if (origin_code
== FUNCTION_DECL
)
12666 /* The outer scopes for inlinings *must* always be represented. We
12667 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
12668 must_output_die
= 1;
12671 /* In the case where the current block represents an inlining of the
12672 "body block" of an inline function, we must *NOT* output any DIE for
12673 this block because we have already output a DIE to represent the whole
12674 inlined function scope and the "body block" of any function doesn't
12675 really represent a different scope according to ANSI C rules. So we
12676 check here to make sure that this block does not represent a "body
12677 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
12678 if (! is_body_block (origin
? origin
: stmt
))
12680 /* Determine if this block directly contains any "significant"
12681 local declarations which we will need to output DIEs for. */
12682 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12683 /* We are not in terse mode so *any* local declaration counts
12684 as being a "significant" one. */
12685 must_output_die
= (BLOCK_VARS (stmt
) != NULL
12686 && (TREE_USED (stmt
)
12687 || TREE_ASM_WRITTEN (stmt
)
12688 || BLOCK_ABSTRACT (stmt
)));
12690 /* We are in terse mode, so only local (nested) function
12691 definitions count as "significant" local declarations. */
12692 for (decl
= BLOCK_VARS (stmt
);
12693 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
12694 if (TREE_CODE (decl
) == FUNCTION_DECL
12695 && DECL_INITIAL (decl
))
12697 must_output_die
= 1;
12703 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
12704 DIE for any block which contains no significant local declarations at
12705 all. Rather, in such cases we just call `decls_for_scope' so that any
12706 needed Dwarf info for any sub-blocks will get properly generated. Note
12707 that in terse mode, our definition of what constitutes a "significant"
12708 local declaration gets restricted to include only inlined function
12709 instances and local (nested) function definitions. */
12710 if (must_output_die
)
12712 if (origin_code
== FUNCTION_DECL
)
12713 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
12715 gen_lexical_block_die (stmt
, context_die
, depth
);
12718 decls_for_scope (stmt
, context_die
, depth
);
12721 /* Generate all of the decls declared within a given scope and (recursively)
12722 all of its sub-blocks. */
12725 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
12730 /* Ignore NULL blocks. */
12731 if (stmt
== NULL_TREE
)
12734 if (TREE_USED (stmt
))
12736 /* Output the DIEs to represent all of the data objects and typedefs
12737 declared directly within this block but not within any nested
12738 sub-blocks. Also, nested function and tag DIEs have been
12739 generated with a parent of NULL; fix that up now. */
12740 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
12744 if (TREE_CODE (decl
) == FUNCTION_DECL
)
12745 die
= lookup_decl_die (decl
);
12746 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
12747 die
= lookup_type_die (TREE_TYPE (decl
));
12751 if (die
!= NULL
&& die
->die_parent
== NULL
)
12752 add_child_die (context_die
, die
);
12753 /* Do not produce debug information for static variables since
12754 these might be optimized out. We are called for these later
12755 in cgraph_varpool_analyze_pending_decls. */
12756 if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
12759 gen_decl_die (decl
, context_die
);
12763 /* If we're at -g1, we're not interested in subblocks. */
12764 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12767 /* Output the DIEs to represent all sub-blocks (and the items declared
12768 therein) of this block. */
12769 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
12771 subblocks
= BLOCK_CHAIN (subblocks
))
12772 gen_block_die (subblocks
, context_die
, depth
+ 1);
12775 /* Is this a typedef we can avoid emitting? */
12778 is_redundant_typedef (tree decl
)
12780 if (TYPE_DECL_IS_STUB (decl
))
12783 if (DECL_ARTIFICIAL (decl
)
12784 && DECL_CONTEXT (decl
)
12785 && is_tagged_type (DECL_CONTEXT (decl
))
12786 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
12787 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
12788 /* Also ignore the artificial member typedef for the class name. */
12794 /* Returns the DIE for decl. A DIE will always be returned. */
12797 force_decl_die (tree decl
)
12799 dw_die_ref decl_die
;
12800 unsigned saved_external_flag
;
12801 tree save_fn
= NULL_TREE
;
12802 decl_die
= lookup_decl_die (decl
);
12805 dw_die_ref context_die
;
12806 tree decl_context
= DECL_CONTEXT (decl
);
12809 /* Find die that represents this context. */
12810 if (TYPE_P (decl_context
))
12811 context_die
= force_type_die (decl_context
);
12813 context_die
= force_decl_die (decl_context
);
12816 context_die
= comp_unit_die
;
12818 decl_die
= lookup_decl_die (decl
);
12822 switch (TREE_CODE (decl
))
12824 case FUNCTION_DECL
:
12825 /* Clear current_function_decl, so that gen_subprogram_die thinks
12826 that this is a declaration. At this point, we just want to force
12827 declaration die. */
12828 save_fn
= current_function_decl
;
12829 current_function_decl
= NULL_TREE
;
12830 gen_subprogram_die (decl
, context_die
);
12831 current_function_decl
= save_fn
;
12835 /* Set external flag to force declaration die. Restore it after
12836 gen_decl_die() call. */
12837 saved_external_flag
= DECL_EXTERNAL (decl
);
12838 DECL_EXTERNAL (decl
) = 1;
12839 gen_decl_die (decl
, context_die
);
12840 DECL_EXTERNAL (decl
) = saved_external_flag
;
12843 case NAMESPACE_DECL
:
12844 dwarf2out_decl (decl
);
12848 gcc_unreachable ();
12851 /* We should be able to find the DIE now. */
12853 decl_die
= lookup_decl_die (decl
);
12854 gcc_assert (decl_die
);
12860 /* Returns the DIE for TYPE. A DIE is always returned. */
12863 force_type_die (tree type
)
12865 dw_die_ref type_die
;
12867 type_die
= lookup_type_die (type
);
12870 dw_die_ref context_die
;
12871 if (TYPE_CONTEXT (type
))
12873 if (TYPE_P (TYPE_CONTEXT (type
)))
12874 context_die
= force_type_die (TYPE_CONTEXT (type
));
12876 context_die
= force_decl_die (TYPE_CONTEXT (type
));
12879 context_die
= comp_unit_die
;
12881 type_die
= lookup_type_die (type
);
12884 gen_type_die (type
, context_die
);
12885 type_die
= lookup_type_die (type
);
12886 gcc_assert (type_die
);
12891 /* Force out any required namespaces to be able to output DECL,
12892 and return the new context_die for it, if it's changed. */
12895 setup_namespace_context (tree thing
, dw_die_ref context_die
)
12897 tree context
= (DECL_P (thing
)
12898 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
12899 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
12900 /* Force out the namespace. */
12901 context_die
= force_decl_die (context
);
12903 return context_die
;
12906 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
12907 type) within its namespace, if appropriate.
12909 For compatibility with older debuggers, namespace DIEs only contain
12910 declarations; all definitions are emitted at CU scope. */
12913 declare_in_namespace (tree thing
, dw_die_ref context_die
)
12915 dw_die_ref ns_context
;
12917 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12920 /* If this decl is from an inlined function, then don't try to emit it in its
12921 namespace, as we will get confused. It would have already been emitted
12922 when the abstract instance of the inline function was emitted anyways. */
12923 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
12926 ns_context
= setup_namespace_context (thing
, context_die
);
12928 if (ns_context
!= context_die
)
12930 if (DECL_P (thing
))
12931 gen_decl_die (thing
, ns_context
);
12933 gen_type_die (thing
, ns_context
);
12937 /* Generate a DIE for a namespace or namespace alias. */
12940 gen_namespace_die (tree decl
)
12942 dw_die_ref context_die
= setup_namespace_context (decl
, comp_unit_die
);
12944 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
12945 they are an alias of. */
12946 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
12948 /* Output a real namespace. */
12949 dw_die_ref namespace_die
12950 = new_die (DW_TAG_namespace
, context_die
, decl
);
12951 add_name_and_src_coords_attributes (namespace_die
, decl
);
12952 equate_decl_number_to_die (decl
, namespace_die
);
12956 /* Output a namespace alias. */
12958 /* Force out the namespace we are an alias of, if necessary. */
12959 dw_die_ref origin_die
12960 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
12962 /* Now create the namespace alias DIE. */
12963 dw_die_ref namespace_die
12964 = new_die (DW_TAG_imported_declaration
, context_die
, decl
);
12965 add_name_and_src_coords_attributes (namespace_die
, decl
);
12966 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
12967 equate_decl_number_to_die (decl
, namespace_die
);
12971 /* Generate Dwarf debug information for a decl described by DECL. */
12974 gen_decl_die (tree decl
, dw_die_ref context_die
)
12978 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
12981 switch (TREE_CODE (decl
))
12987 /* The individual enumerators of an enum type get output when we output
12988 the Dwarf representation of the relevant enum type itself. */
12991 case FUNCTION_DECL
:
12992 /* Don't output any DIEs to represent mere function declarations,
12993 unless they are class members or explicit block externs. */
12994 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
12995 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
13000 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
13001 on local redeclarations of global functions. That seems broken. */
13002 if (current_function_decl
!= decl
)
13003 /* This is only a declaration. */;
13006 /* If we're emitting a clone, emit info for the abstract instance. */
13007 if (DECL_ORIGIN (decl
) != decl
)
13008 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
13010 /* If we're emitting an out-of-line copy of an inline function,
13011 emit info for the abstract instance and set up to refer to it. */
13012 else if (cgraph_function_possibly_inlined_p (decl
)
13013 && ! DECL_ABSTRACT (decl
)
13014 && ! class_or_namespace_scope_p (context_die
)
13015 /* dwarf2out_abstract_function won't emit a die if this is just
13016 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
13017 that case, because that works only if we have a die. */
13018 && DECL_INITIAL (decl
) != NULL_TREE
)
13020 dwarf2out_abstract_function (decl
);
13021 set_decl_origin_self (decl
);
13024 /* Otherwise we're emitting the primary DIE for this decl. */
13025 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
13027 /* Before we describe the FUNCTION_DECL itself, make sure that we
13028 have described its return type. */
13029 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
13031 /* And its virtual context. */
13032 if (DECL_VINDEX (decl
) != NULL_TREE
)
13033 gen_type_die (DECL_CONTEXT (decl
), context_die
);
13035 /* And its containing type. */
13036 origin
= decl_class_context (decl
);
13037 if (origin
!= NULL_TREE
)
13038 gen_type_die_for_member (origin
, decl
, context_die
);
13040 /* And its containing namespace. */
13041 declare_in_namespace (decl
, context_die
);
13044 /* Now output a DIE to represent the function itself. */
13045 gen_subprogram_die (decl
, context_die
);
13049 /* If we are in terse mode, don't generate any DIEs to represent any
13050 actual typedefs. */
13051 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13054 /* In the special case of a TYPE_DECL node representing the declaration
13055 of some type tag, if the given TYPE_DECL is marked as having been
13056 instantiated from some other (original) TYPE_DECL node (e.g. one which
13057 was generated within the original definition of an inline function) we
13058 have to generate a special (abbreviated) DW_TAG_structure_type,
13059 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
13060 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
13062 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
13066 if (is_redundant_typedef (decl
))
13067 gen_type_die (TREE_TYPE (decl
), context_die
);
13069 /* Output a DIE to represent the typedef itself. */
13070 gen_typedef_die (decl
, context_die
);
13074 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
13075 gen_label_die (decl
, context_die
);
13080 /* If we are in terse mode, don't generate any DIEs to represent any
13081 variable declarations or definitions. */
13082 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13085 /* Output any DIEs that are needed to specify the type of this data
13087 gen_type_die (TREE_TYPE (decl
), context_die
);
13089 /* And its containing type. */
13090 origin
= decl_class_context (decl
);
13091 if (origin
!= NULL_TREE
)
13092 gen_type_die_for_member (origin
, decl
, context_die
);
13094 /* And its containing namespace. */
13095 declare_in_namespace (decl
, context_die
);
13097 /* Now output the DIE to represent the data object itself. This gets
13098 complicated because of the possibility that the VAR_DECL really
13099 represents an inlined instance of a formal parameter for an inline
13101 origin
= decl_ultimate_origin (decl
);
13102 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
13103 gen_formal_parameter_die (decl
, context_die
);
13105 gen_variable_die (decl
, context_die
);
13109 /* Ignore the nameless fields that are used to skip bits but handle C++
13110 anonymous unions and structs. */
13111 if (DECL_NAME (decl
) != NULL_TREE
13112 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
13113 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
13115 gen_type_die (member_declared_type (decl
), context_die
);
13116 gen_field_die (decl
, context_die
);
13121 gen_type_die (TREE_TYPE (decl
), context_die
);
13122 gen_formal_parameter_die (decl
, context_die
);
13125 case NAMESPACE_DECL
:
13126 gen_namespace_die (decl
);
13130 /* Probably some frontend-internal decl. Assume we don't care. */
13131 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
13136 /* Output debug information for global decl DECL. Called from toplev.c after
13137 compilation proper has finished. */
13140 dwarf2out_global_decl (tree decl
)
13142 /* Output DWARF2 information for file-scope tentative data object
13143 declarations, file-scope (extern) function declarations (which had no
13144 corresponding body) and file-scope tagged type declarations and
13145 definitions which have not yet been forced out. */
13146 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
13147 dwarf2out_decl (decl
);
13150 /* Output debug information for type decl DECL. Called from toplev.c
13151 and from language front ends (to record built-in types). */
13153 dwarf2out_type_decl (tree decl
, int local
)
13156 dwarf2out_decl (decl
);
13159 /* Output debug information for imported module or decl. */
13162 dwarf2out_imported_module_or_decl (tree decl
, tree context
)
13164 dw_die_ref imported_die
, at_import_die
;
13165 dw_die_ref scope_die
;
13166 unsigned file_index
;
13167 expanded_location xloc
;
13169 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13174 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
13175 We need decl DIE for reference and scope die. First, get DIE for the decl
13178 /* Get the scope die for decl context. Use comp_unit_die for global module
13179 or decl. If die is not found for non globals, force new die. */
13181 scope_die
= comp_unit_die
;
13182 else if (TYPE_P (context
))
13183 scope_die
= force_type_die (context
);
13185 scope_die
= force_decl_die (context
);
13187 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
13188 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
13189 at_import_die
= force_type_die (TREE_TYPE (decl
));
13192 at_import_die
= lookup_decl_die (decl
);
13193 if (!at_import_die
)
13195 /* If we're trying to avoid duplicate debug info, we may not have
13196 emitted the member decl for this field. Emit it now. */
13197 if (TREE_CODE (decl
) == FIELD_DECL
)
13199 tree type
= DECL_CONTEXT (decl
);
13200 dw_die_ref type_context_die
;
13202 if (TYPE_CONTEXT (type
))
13203 if (TYPE_P (TYPE_CONTEXT (type
)))
13204 type_context_die
= force_type_die (TYPE_CONTEXT (type
));
13206 type_context_die
= force_decl_die (TYPE_CONTEXT (type
));
13208 type_context_die
= comp_unit_die
;
13209 gen_type_die_for_member (type
, decl
, type_context_die
);
13211 at_import_die
= force_decl_die (decl
);
13215 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
13216 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
13217 imported_die
= new_die (DW_TAG_imported_module
, scope_die
, context
);
13219 imported_die
= new_die (DW_TAG_imported_declaration
, scope_die
, context
);
13221 xloc
= expand_location (input_location
);
13222 file_index
= lookup_filename (xloc
.file
);
13223 add_AT_unsigned (imported_die
, DW_AT_decl_file
, file_index
);
13224 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
13225 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
13228 /* Write the debugging output for DECL. */
13231 dwarf2out_decl (tree decl
)
13233 dw_die_ref context_die
= comp_unit_die
;
13235 switch (TREE_CODE (decl
))
13240 case FUNCTION_DECL
:
13241 /* What we would really like to do here is to filter out all mere
13242 file-scope declarations of file-scope functions which are never
13243 referenced later within this translation unit (and keep all of ones
13244 that *are* referenced later on) but we aren't clairvoyant, so we have
13245 no idea which functions will be referenced in the future (i.e. later
13246 on within the current translation unit). So here we just ignore all
13247 file-scope function declarations which are not also definitions. If
13248 and when the debugger needs to know something about these functions,
13249 it will have to hunt around and find the DWARF information associated
13250 with the definition of the function.
13252 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
13253 nodes represent definitions and which ones represent mere
13254 declarations. We have to check DECL_INITIAL instead. That's because
13255 the C front-end supports some weird semantics for "extern inline"
13256 function definitions. These can get inlined within the current
13257 translation unit (and thus, we need to generate Dwarf info for their
13258 abstract instances so that the Dwarf info for the concrete inlined
13259 instances can have something to refer to) but the compiler never
13260 generates any out-of-lines instances of such things (despite the fact
13261 that they *are* definitions).
13263 The important point is that the C front-end marks these "extern
13264 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
13265 them anyway. Note that the C++ front-end also plays some similar games
13266 for inline function definitions appearing within include files which
13267 also contain `#pragma interface' pragmas. */
13268 if (DECL_INITIAL (decl
) == NULL_TREE
)
13271 /* If we're a nested function, initially use a parent of NULL; if we're
13272 a plain function, this will be fixed up in decls_for_scope. If
13273 we're a method, it will be ignored, since we already have a DIE. */
13274 if (decl_function_context (decl
)
13275 /* But if we're in terse mode, we don't care about scope. */
13276 && debug_info_level
> DINFO_LEVEL_TERSE
)
13277 context_die
= NULL
;
13281 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
13282 declaration and if the declaration was never even referenced from
13283 within this entire compilation unit. We suppress these DIEs in
13284 order to save space in the .debug section (by eliminating entries
13285 which are probably useless). Note that we must not suppress
13286 block-local extern declarations (whether used or not) because that
13287 would screw-up the debugger's name lookup mechanism and cause it to
13288 miss things which really ought to be in scope at a given point. */
13289 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
13292 /* For local statics lookup proper context die. */
13293 if (TREE_STATIC (decl
) && decl_function_context (decl
))
13294 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
13296 /* If we are in terse mode, don't generate any DIEs to represent any
13297 variable declarations or definitions. */
13298 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13302 case NAMESPACE_DECL
:
13303 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13305 if (lookup_decl_die (decl
) != NULL
)
13310 /* Don't emit stubs for types unless they are needed by other DIEs. */
13311 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
13314 /* Don't bother trying to generate any DIEs to represent any of the
13315 normal built-in types for the language we are compiling. */
13316 if (DECL_IS_BUILTIN (decl
))
13318 /* OK, we need to generate one for `bool' so GDB knows what type
13319 comparisons have. */
13320 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
13321 == DW_LANG_C_plus_plus
)
13322 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
13323 && ! DECL_IGNORED_P (decl
))
13324 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
13329 /* If we are in terse mode, don't generate any DIEs for types. */
13330 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13333 /* If we're a function-scope tag, initially use a parent of NULL;
13334 this will be fixed up in decls_for_scope. */
13335 if (decl_function_context (decl
))
13336 context_die
= NULL
;
13344 gen_decl_die (decl
, context_die
);
13347 /* Output a marker (i.e. a label) for the beginning of the generated code for
13348 a lexical block. */
13351 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
13352 unsigned int blocknum
)
13354 switch_to_section (current_function_section ());
13355 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
13358 /* Output a marker (i.e. a label) for the end of the generated code for a
13362 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
13364 switch_to_section (current_function_section ());
13365 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
13368 /* Returns nonzero if it is appropriate not to emit any debugging
13369 information for BLOCK, because it doesn't contain any instructions.
13371 Don't allow this for blocks with nested functions or local classes
13372 as we would end up with orphans, and in the presence of scheduling
13373 we may end up calling them anyway. */
13376 dwarf2out_ignore_block (tree block
)
13380 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
13381 if (TREE_CODE (decl
) == FUNCTION_DECL
13382 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
13388 /* Lookup FILE_NAME (in the list of filenames that we know about here in
13389 dwarf2out.c) and return its "index". The index of each (known) filename is
13390 just a unique number which is associated with only that one filename. We
13391 need such numbers for the sake of generating labels (in the .debug_sfnames
13392 section) and references to those files numbers (in the .debug_srcinfo
13393 and.debug_macinfo sections). If the filename given as an argument is not
13394 found in our current list, add it to the list and assign it the next
13395 available unique index number. In order to speed up searches, we remember
13396 the index of the filename was looked up last. This handles the majority of
13400 lookup_filename (const char *file_name
)
13403 char *save_file_name
;
13405 /* Check to see if the file name that was searched on the previous
13406 call matches this file name. If so, return the index. */
13407 if (file_table_last_lookup_index
!= 0)
13410 = VARRAY_CHAR_PTR (file_table
, file_table_last_lookup_index
);
13411 if (strcmp (file_name
, last
) == 0)
13412 return file_table_last_lookup_index
;
13415 /* Didn't match the previous lookup, search the table. */
13416 n
= VARRAY_ACTIVE_SIZE (file_table
);
13417 for (i
= 1; i
< n
; i
++)
13418 if (strcmp (file_name
, VARRAY_CHAR_PTR (file_table
, i
)) == 0)
13420 file_table_last_lookup_index
= i
;
13424 /* Add the new entry to the end of the filename table. */
13425 file_table_last_lookup_index
= n
;
13426 save_file_name
= (char *) ggc_strdup (file_name
);
13427 VARRAY_PUSH_CHAR_PTR (file_table
, save_file_name
);
13428 VARRAY_PUSH_UINT (file_table_emitted
, 0);
13430 /* If the assembler is emitting the file table, and we aren't eliminating
13431 unused debug types, then we must emit .file here. If we are eliminating
13432 unused debug types, then this will be done by the maybe_emit_file call in
13433 prune_unused_types_walk_attribs. */
13435 if (DWARF2_ASM_LINE_DEBUG_INFO
&& ! flag_eliminate_unused_debug_types
)
13436 return maybe_emit_file (i
);
13441 /* If the assembler will construct the file table, then translate the compiler
13442 internal file table number into the assembler file table number, and emit
13443 a .file directive if we haven't already emitted one yet. The file table
13444 numbers are different because we prune debug info for unused variables and
13445 types, which may include filenames. */
13448 maybe_emit_file (int fileno
)
13450 if (DWARF2_ASM_LINE_DEBUG_INFO
&& fileno
> 0)
13452 if (!VARRAY_UINT (file_table_emitted
, fileno
))
13454 VARRAY_UINT (file_table_emitted
, fileno
) = ++emitcount
;
13455 fprintf (asm_out_file
, "\t.file %u ",
13456 VARRAY_UINT (file_table_emitted
, fileno
));
13457 output_quoted_string (asm_out_file
,
13458 VARRAY_CHAR_PTR (file_table
, fileno
));
13459 fputc ('\n', asm_out_file
);
13461 return VARRAY_UINT (file_table_emitted
, fileno
);
13467 /* Initialize the compiler internal file table. */
13470 init_file_table (void)
13472 /* Allocate the initial hunk of the file_table. */
13473 VARRAY_CHAR_PTR_INIT (file_table
, 64, "file_table");
13474 VARRAY_UINT_INIT (file_table_emitted
, 64, "file_table_emitted");
13476 /* Skip the first entry - file numbers begin at 1. */
13477 VARRAY_PUSH_CHAR_PTR (file_table
, NULL
);
13478 VARRAY_PUSH_UINT (file_table_emitted
, 0);
13479 file_table_last_lookup_index
= 0;
13482 /* Called by the final INSN scan whenever we see a var location. We
13483 use it to drop labels in the right places, and throw the location in
13484 our lookup table. */
13487 dwarf2out_var_location (rtx loc_note
)
13489 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
13490 struct var_loc_node
*newloc
;
13492 static rtx last_insn
;
13493 static const char *last_label
;
13496 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
13498 prev_insn
= PREV_INSN (loc_note
);
13500 newloc
= ggc_alloc_cleared (sizeof (struct var_loc_node
));
13501 /* If the insn we processed last time is the previous insn
13502 and it is also a var location note, use the label we emitted
13504 if (last_insn
!= NULL_RTX
13505 && last_insn
== prev_insn
13506 && NOTE_P (prev_insn
)
13507 && NOTE_LINE_NUMBER (prev_insn
) == NOTE_INSN_VAR_LOCATION
)
13509 newloc
->label
= last_label
;
13513 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
13514 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
13516 newloc
->label
= ggc_strdup (loclabel
);
13518 newloc
->var_loc_note
= loc_note
;
13519 newloc
->next
= NULL
;
13521 if (cfun
&& in_cold_section_p
)
13522 newloc
->section_label
= cfun
->cold_section_label
;
13524 newloc
->section_label
= text_section_label
;
13526 last_insn
= loc_note
;
13527 last_label
= newloc
->label
;
13528 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
13529 if (DECL_DEBUG_EXPR_IS_FROM (decl
) && DECL_DEBUG_EXPR (decl
)
13530 && DECL_P (DECL_DEBUG_EXPR (decl
)))
13531 decl
= DECL_DEBUG_EXPR (decl
);
13532 add_var_loc_to_decl (decl
, newloc
);
13535 /* We need to reset the locations at the beginning of each
13536 function. We can't do this in the end_function hook, because the
13537 declarations that use the locations won't have been output when
13538 that hook is called. Also compute have_multiple_function_sections here. */
13541 dwarf2out_begin_function (tree fun
)
13543 htab_empty (decl_loc_table
);
13545 if (function_section (fun
) != text_section
)
13546 have_multiple_function_sections
= true;
13549 /* Output a label to mark the beginning of a source code line entry
13550 and record information relating to this source line, in
13551 'line_info_table' for later output of the .debug_line section. */
13554 dwarf2out_source_line (unsigned int line
, const char *filename
)
13556 if (debug_info_level
>= DINFO_LEVEL_NORMAL
13559 switch_to_section (current_function_section ());
13561 /* If requested, emit something human-readable. */
13562 if (flag_debug_asm
)
13563 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
13566 if (DWARF2_ASM_LINE_DEBUG_INFO
)
13568 unsigned file_num
= lookup_filename (filename
);
13570 file_num
= maybe_emit_file (file_num
);
13572 /* Emit the .loc directive understood by GNU as. */
13573 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
13575 /* Indicate that line number info exists. */
13576 line_info_table_in_use
++;
13578 else if (function_section (current_function_decl
) != text_section
)
13580 dw_separate_line_info_ref line_info
;
13581 targetm
.asm_out
.internal_label (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
13582 separate_line_info_table_in_use
);
13584 /* Expand the line info table if necessary. */
13585 if (separate_line_info_table_in_use
13586 == separate_line_info_table_allocated
)
13588 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
13589 separate_line_info_table
13590 = ggc_realloc (separate_line_info_table
,
13591 separate_line_info_table_allocated
13592 * sizeof (dw_separate_line_info_entry
));
13593 memset (separate_line_info_table
13594 + separate_line_info_table_in_use
,
13596 (LINE_INFO_TABLE_INCREMENT
13597 * sizeof (dw_separate_line_info_entry
)));
13600 /* Add the new entry at the end of the line_info_table. */
13602 = &separate_line_info_table
[separate_line_info_table_in_use
++];
13603 line_info
->dw_file_num
= lookup_filename (filename
);
13604 line_info
->dw_line_num
= line
;
13605 line_info
->function
= current_function_funcdef_no
;
13609 dw_line_info_ref line_info
;
13611 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
,
13612 line_info_table_in_use
);
13614 /* Expand the line info table if necessary. */
13615 if (line_info_table_in_use
== line_info_table_allocated
)
13617 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
13619 = ggc_realloc (line_info_table
,
13620 (line_info_table_allocated
13621 * sizeof (dw_line_info_entry
)));
13622 memset (line_info_table
+ line_info_table_in_use
, 0,
13623 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
13626 /* Add the new entry at the end of the line_info_table. */
13627 line_info
= &line_info_table
[line_info_table_in_use
++];
13628 line_info
->dw_file_num
= lookup_filename (filename
);
13629 line_info
->dw_line_num
= line
;
13634 /* Record the beginning of a new source file. */
13637 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
13639 if (flag_eliminate_dwarf2_dups
)
13641 /* Record the beginning of the file for break_out_includes. */
13642 dw_die_ref bincl_die
;
13644 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
13645 add_AT_string (bincl_die
, DW_AT_name
, filename
);
13648 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13652 switch_to_section (debug_macinfo_section
);
13653 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
13654 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
13657 fileno
= maybe_emit_file (lookup_filename (filename
));
13658 dw2_asm_output_data_uleb128 (fileno
, "Filename we just started");
13662 /* Record the end of a source file. */
13665 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
13667 if (flag_eliminate_dwarf2_dups
)
13668 /* Record the end of the file for break_out_includes. */
13669 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
13671 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13673 switch_to_section (debug_macinfo_section
);
13674 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
13678 /* Called from debug_define in toplev.c. The `buffer' parameter contains
13679 the tail part of the directive line, i.e. the part which is past the
13680 initial whitespace, #, whitespace, directive-name, whitespace part. */
13683 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
13684 const char *buffer ATTRIBUTE_UNUSED
)
13686 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13688 switch_to_section (debug_macinfo_section
);
13689 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
13690 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
13691 dw2_asm_output_nstring (buffer
, -1, "The macro");
13695 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
13696 the tail part of the directive line, i.e. the part which is past the
13697 initial whitespace, #, whitespace, directive-name, whitespace part. */
13700 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
13701 const char *buffer ATTRIBUTE_UNUSED
)
13703 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13705 switch_to_section (debug_macinfo_section
);
13706 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
13707 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
13708 dw2_asm_output_nstring (buffer
, -1, "The macro");
13712 /* Set up for Dwarf output at the start of compilation. */
13715 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
13717 init_file_table ();
13719 /* Allocate the decl_die_table. */
13720 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
13721 decl_die_table_eq
, NULL
);
13723 /* Allocate the decl_loc_table. */
13724 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
13725 decl_loc_table_eq
, NULL
);
13727 /* Allocate the initial hunk of the decl_scope_table. */
13728 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
13730 /* Allocate the initial hunk of the abbrev_die_table. */
13731 abbrev_die_table
= ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
13732 * sizeof (dw_die_ref
));
13733 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
13734 /* Zero-th entry is allocated, but unused. */
13735 abbrev_die_table_in_use
= 1;
13737 /* Allocate the initial hunk of the line_info_table. */
13738 line_info_table
= ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
13739 * sizeof (dw_line_info_entry
));
13740 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
13742 /* Zero-th entry is allocated, but unused. */
13743 line_info_table_in_use
= 1;
13745 /* Generate the initial DIE for the .debug section. Note that the (string)
13746 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
13747 will (typically) be a relative pathname and that this pathname should be
13748 taken as being relative to the directory from which the compiler was
13749 invoked when the given (base) source file was compiled. We will fill
13750 in this value in dwarf2out_finish. */
13751 comp_unit_die
= gen_compile_unit_die (NULL
);
13753 incomplete_types
= VEC_alloc (tree
, gc
, 64);
13755 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
13757 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
13758 SECTION_DEBUG
, NULL
);
13759 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
13760 SECTION_DEBUG
, NULL
);
13761 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
13762 SECTION_DEBUG
, NULL
);
13763 debug_macinfo_section
= get_section (DEBUG_MACINFO_SECTION
,
13764 SECTION_DEBUG
, NULL
);
13765 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
13766 SECTION_DEBUG
, NULL
);
13767 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
13768 SECTION_DEBUG
, NULL
);
13769 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
13770 SECTION_DEBUG
, NULL
);
13771 debug_str_section
= get_section (DEBUG_STR_SECTION
,
13772 DEBUG_STR_SECTION_FLAGS
, NULL
);
13773 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
13774 SECTION_DEBUG
, NULL
);
13775 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
13776 SECTION_DEBUG
, NULL
);
13778 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
13779 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
13780 DEBUG_ABBREV_SECTION_LABEL
, 0);
13781 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
13782 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
13783 COLD_TEXT_SECTION_LABEL
, 0);
13784 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
13786 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
13787 DEBUG_INFO_SECTION_LABEL
, 0);
13788 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
13789 DEBUG_LINE_SECTION_LABEL
, 0);
13790 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
13791 DEBUG_RANGES_SECTION_LABEL
, 0);
13792 switch_to_section (debug_abbrev_section
);
13793 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
13794 switch_to_section (debug_info_section
);
13795 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
13796 switch_to_section (debug_line_section
);
13797 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
13799 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13801 switch_to_section (debug_macinfo_section
);
13802 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
13803 DEBUG_MACINFO_SECTION_LABEL
, 0);
13804 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
13807 switch_to_section (text_section
);
13808 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
13809 if (flag_reorder_blocks_and_partition
)
13811 switch_to_section (unlikely_text_section ());
13812 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
13816 /* A helper function for dwarf2out_finish called through
13817 ht_forall. Emit one queued .debug_str string. */
13820 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
13822 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
13824 if (node
->form
== DW_FORM_strp
)
13826 switch_to_section (debug_str_section
);
13827 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
13828 assemble_string (node
->str
, strlen (node
->str
) + 1);
13836 /* Clear the marks for a die and its children.
13837 Be cool if the mark isn't set. */
13840 prune_unmark_dies (dw_die_ref die
)
13844 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
13845 prune_unmark_dies (c
);
13849 /* Given DIE that we're marking as used, find any other dies
13850 it references as attributes and mark them as used. */
13853 prune_unused_types_walk_attribs (dw_die_ref die
)
13857 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
13859 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
13861 /* A reference to another DIE.
13862 Make sure that it will get emitted. */
13863 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
13865 else if (a
->dw_attr
== DW_AT_decl_file
|| a
->dw_attr
== DW_AT_call_file
)
13867 /* A reference to a file. Make sure the file name is emitted. */
13868 a
->dw_attr_val
.v
.val_unsigned
=
13869 maybe_emit_file (a
->dw_attr_val
.v
.val_unsigned
);
13875 /* Mark DIE as being used. If DOKIDS is true, then walk down
13876 to DIE's children. */
13879 prune_unused_types_mark (dw_die_ref die
, int dokids
)
13883 if (die
->die_mark
== 0)
13885 /* We haven't done this node yet. Mark it as used. */
13888 /* We also have to mark its parents as used.
13889 (But we don't want to mark our parents' kids due to this.) */
13890 if (die
->die_parent
)
13891 prune_unused_types_mark (die
->die_parent
, 0);
13893 /* Mark any referenced nodes. */
13894 prune_unused_types_walk_attribs (die
);
13896 /* If this node is a specification,
13897 also mark the definition, if it exists. */
13898 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
13899 prune_unused_types_mark (die
->die_definition
, 1);
13902 if (dokids
&& die
->die_mark
!= 2)
13904 /* We need to walk the children, but haven't done so yet.
13905 Remember that we've walked the kids. */
13909 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
13911 /* If this is an array type, we need to make sure our
13912 kids get marked, even if they're types. */
13913 if (die
->die_tag
== DW_TAG_array_type
)
13914 prune_unused_types_mark (c
, 1);
13916 prune_unused_types_walk (c
);
13922 /* Walk the tree DIE and mark types that we actually use. */
13925 prune_unused_types_walk (dw_die_ref die
)
13929 /* Don't do anything if this node is already marked. */
13933 switch (die
->die_tag
) {
13934 case DW_TAG_const_type
:
13935 case DW_TAG_packed_type
:
13936 case DW_TAG_pointer_type
:
13937 case DW_TAG_reference_type
:
13938 case DW_TAG_volatile_type
:
13939 case DW_TAG_typedef
:
13940 case DW_TAG_array_type
:
13941 case DW_TAG_structure_type
:
13942 case DW_TAG_union_type
:
13943 case DW_TAG_class_type
:
13944 case DW_TAG_friend
:
13945 case DW_TAG_variant_part
:
13946 case DW_TAG_enumeration_type
:
13947 case DW_TAG_subroutine_type
:
13948 case DW_TAG_string_type
:
13949 case DW_TAG_set_type
:
13950 case DW_TAG_subrange_type
:
13951 case DW_TAG_ptr_to_member_type
:
13952 case DW_TAG_file_type
:
13953 /* It's a type node --- don't mark it. */
13957 /* Mark everything else. */
13963 /* Now, mark any dies referenced from here. */
13964 prune_unused_types_walk_attribs (die
);
13966 /* Mark children. */
13967 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
13968 prune_unused_types_walk (c
);
13972 /* Remove from the tree DIE any dies that aren't marked. */
13975 prune_unused_types_prune (dw_die_ref die
)
13977 dw_die_ref c
, p
, n
;
13979 gcc_assert (die
->die_mark
);
13982 for (c
= die
->die_child
; c
; c
= n
)
13987 prune_unused_types_prune (c
);
13995 die
->die_child
= n
;
14002 /* Remove dies representing declarations that we never use. */
14005 prune_unused_types (void)
14008 limbo_die_node
*node
;
14010 /* Clear all the marks. */
14011 prune_unmark_dies (comp_unit_die
);
14012 for (node
= limbo_die_list
; node
; node
= node
->next
)
14013 prune_unmark_dies (node
->die
);
14015 /* Set the mark on nodes that are actually used. */
14016 prune_unused_types_walk (comp_unit_die
);
14017 for (node
= limbo_die_list
; node
; node
= node
->next
)
14018 prune_unused_types_walk (node
->die
);
14020 /* Also set the mark on nodes referenced from the
14021 pubname_table or arange_table. */
14022 for (i
= 0; i
< pubname_table_in_use
; i
++)
14023 prune_unused_types_mark (pubname_table
[i
].die
, 1);
14024 for (i
= 0; i
< arange_table_in_use
; i
++)
14025 prune_unused_types_mark (arange_table
[i
], 1);
14027 /* Get rid of nodes that aren't marked. */
14028 prune_unused_types_prune (comp_unit_die
);
14029 for (node
= limbo_die_list
; node
; node
= node
->next
)
14030 prune_unused_types_prune (node
->die
);
14032 /* Leave the marks clear. */
14033 prune_unmark_dies (comp_unit_die
);
14034 for (node
= limbo_die_list
; node
; node
= node
->next
)
14035 prune_unmark_dies (node
->die
);
14038 /* Output stuff that dwarf requires at the end of every file,
14039 and generate the DWARF-2 debugging info. */
14042 dwarf2out_finish (const char *filename
)
14044 limbo_die_node
*node
, *next_node
;
14045 dw_die_ref die
= 0;
14047 /* Add the name for the main input file now. We delayed this from
14048 dwarf2out_init to avoid complications with PCH. */
14049 add_name_attribute (comp_unit_die
, filename
);
14050 if (filename
[0] != DIR_SEPARATOR
)
14051 add_comp_dir_attribute (comp_unit_die
);
14052 else if (get_AT (comp_unit_die
, DW_AT_comp_dir
) == NULL
)
14055 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
14056 if (VARRAY_CHAR_PTR (file_table
, i
)[0] != DIR_SEPARATOR
14057 /* Don't add cwd for <built-in>. */
14058 && VARRAY_CHAR_PTR (file_table
, i
)[0] != '<')
14060 add_comp_dir_attribute (comp_unit_die
);
14065 /* Traverse the limbo die list, and add parent/child links. The only
14066 dies without parents that should be here are concrete instances of
14067 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
14068 For concrete instances, we can get the parent die from the abstract
14070 for (node
= limbo_die_list
; node
; node
= next_node
)
14072 next_node
= node
->next
;
14075 if (die
->die_parent
== NULL
)
14077 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
14080 add_child_die (origin
->die_parent
, die
);
14081 else if (die
== comp_unit_die
)
14083 else if (errorcount
> 0 || sorrycount
> 0)
14084 /* It's OK to be confused by errors in the input. */
14085 add_child_die (comp_unit_die
, die
);
14088 /* In certain situations, the lexical block containing a
14089 nested function can be optimized away, which results
14090 in the nested function die being orphaned. Likewise
14091 with the return type of that nested function. Force
14092 this to be a child of the containing function.
14094 It may happen that even the containing function got fully
14095 inlined and optimized out. In that case we are lost and
14096 assign the empty child. This should not be big issue as
14097 the function is likely unreachable too. */
14098 tree context
= NULL_TREE
;
14100 gcc_assert (node
->created_for
);
14102 if (DECL_P (node
->created_for
))
14103 context
= DECL_CONTEXT (node
->created_for
);
14104 else if (TYPE_P (node
->created_for
))
14105 context
= TYPE_CONTEXT (node
->created_for
);
14107 gcc_assert (context
&& TREE_CODE (context
) == FUNCTION_DECL
);
14109 origin
= lookup_decl_die (context
);
14111 add_child_die (origin
, die
);
14113 add_child_die (comp_unit_die
, die
);
14118 limbo_die_list
= NULL
;
14120 /* Walk through the list of incomplete types again, trying once more to
14121 emit full debugging info for them. */
14122 retry_incomplete_types ();
14124 /* We need to reverse all the dies before break_out_includes, or
14125 we'll see the end of an include file before the beginning. */
14126 reverse_all_dies (comp_unit_die
);
14128 if (flag_eliminate_unused_debug_types
)
14129 prune_unused_types ();
14131 /* Generate separate CUs for each of the include files we've seen.
14132 They will go into limbo_die_list. */
14133 if (flag_eliminate_dwarf2_dups
)
14134 break_out_includes (comp_unit_die
);
14136 /* Traverse the DIE's and add add sibling attributes to those DIE's
14137 that have children. */
14138 add_sibling_attributes (comp_unit_die
);
14139 for (node
= limbo_die_list
; node
; node
= node
->next
)
14140 add_sibling_attributes (node
->die
);
14142 /* Output a terminator label for the .text section. */
14143 switch_to_section (text_section
);
14144 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
14145 if (flag_reorder_blocks_and_partition
)
14147 switch_to_section (unlikely_text_section ());
14148 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
14151 /* Output the source line correspondence table. We must do this
14152 even if there is no line information. Otherwise, on an empty
14153 translation unit, we will generate a present, but empty,
14154 .debug_info section. IRIX 6.5 `nm' will then complain when
14155 examining the file. */
14156 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
14158 switch_to_section (debug_line_section
);
14159 output_line_info ();
14162 /* We can only use the low/high_pc attributes if all of the code was
14164 if (!have_multiple_function_sections
)
14166 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
14167 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
14170 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
14171 "base address". Use zero so that these addresses become absolute. */
14172 else if (have_location_lists
|| ranges_table_in_use
)
14173 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
14175 /* Output location list section if necessary. */
14176 if (have_location_lists
)
14178 /* Output the location lists info. */
14179 switch_to_section (debug_loc_section
);
14180 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
14181 DEBUG_LOC_SECTION_LABEL
, 0);
14182 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
14183 output_location_lists (die
);
14186 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
14187 add_AT_lineptr (comp_unit_die
, DW_AT_stmt_list
,
14188 debug_line_section_label
);
14190 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
14191 add_AT_macptr (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
14193 /* Output all of the compilation units. We put the main one last so that
14194 the offsets are available to output_pubnames. */
14195 for (node
= limbo_die_list
; node
; node
= node
->next
)
14196 output_comp_unit (node
->die
, 0);
14198 output_comp_unit (comp_unit_die
, 0);
14200 /* Output the abbreviation table. */
14201 switch_to_section (debug_abbrev_section
);
14202 output_abbrev_section ();
14204 /* Output public names table if necessary. */
14205 if (pubname_table_in_use
)
14207 switch_to_section (debug_pubnames_section
);
14208 output_pubnames ();
14211 /* Output the address range information. We only put functions in the arange
14212 table, so don't write it out if we don't have any. */
14213 if (fde_table_in_use
)
14215 switch_to_section (debug_aranges_section
);
14219 /* Output ranges section if necessary. */
14220 if (ranges_table_in_use
)
14222 switch_to_section (debug_ranges_section
);
14223 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
14227 /* Have to end the macro section. */
14228 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
14230 switch_to_section (debug_macinfo_section
);
14231 dw2_asm_output_data (1, 0, "End compilation unit");
14234 /* If we emitted any DW_FORM_strp form attribute, output the string
14236 if (debug_str_hash
)
14237 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
14241 /* This should never be used, but its address is needed for comparisons. */
14242 const struct gcc_debug_hooks dwarf2_debug_hooks
;
14244 #endif /* DWARF2_DEBUGGING_INFO */
14246 #include "gt-dwarf2out.h"