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 /* CIE identifier. */
292 #if HOST_BITS_PER_WIDE_INT >= 64
293 #define DWARF_CIE_ID \
294 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
296 #define DWARF_CIE_ID DW_CIE_ID
299 /* A pointer to the base of a table that contains frame description
300 information for each routine. */
301 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table
;
303 /* Number of elements currently allocated for fde_table. */
304 static GTY(()) unsigned fde_table_allocated
;
306 /* Number of elements in fde_table currently in use. */
307 static GTY(()) unsigned fde_table_in_use
;
309 /* Size (in elements) of increments by which we may expand the
311 #define FDE_TABLE_INCREMENT 256
313 /* A list of call frame insns for the CIE. */
314 static GTY(()) dw_cfi_ref cie_cfi_head
;
316 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
317 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
318 attribute that accelerates the lookup of the FDE associated
319 with the subprogram. This variable holds the table index of the FDE
320 associated with the current function (body) definition. */
321 static unsigned current_funcdef_fde
;
324 struct indirect_string_node
GTY(())
327 unsigned int refcount
;
332 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
334 static GTY(()) int dw2_string_counter
;
335 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
337 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
339 /* Forward declarations for functions defined in this file. */
341 static char *stripattributes (const char *);
342 static const char *dwarf_cfi_name (unsigned);
343 static dw_cfi_ref
new_cfi (void);
344 static void add_cfi (dw_cfi_ref
*, dw_cfi_ref
);
345 static void add_fde_cfi (const char *, dw_cfi_ref
);
346 static void lookup_cfa_1 (dw_cfi_ref
, dw_cfa_location
*);
347 static void lookup_cfa (dw_cfa_location
*);
348 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT
);
349 static void initial_return_save (rtx
);
350 static HOST_WIDE_INT
stack_adjust_offset (rtx
);
351 static void output_cfi (dw_cfi_ref
, dw_fde_ref
, int);
352 static void output_call_frame_info (int);
353 static void dwarf2out_stack_adjust (rtx
, bool);
354 static void flush_queued_reg_saves (void);
355 static bool clobbers_queued_reg_save (rtx
);
356 static void dwarf2out_frame_debug_expr (rtx
, const char *);
358 /* Support for complex CFA locations. */
359 static void output_cfa_loc (dw_cfi_ref
);
360 static void get_cfa_from_loc_descr (dw_cfa_location
*,
361 struct dw_loc_descr_struct
*);
362 static struct dw_loc_descr_struct
*build_cfa_loc
363 (dw_cfa_location
*, HOST_WIDE_INT
);
364 static void def_cfa_1 (const char *, dw_cfa_location
*);
366 /* How to start an assembler comment. */
367 #ifndef ASM_COMMENT_START
368 #define ASM_COMMENT_START ";#"
371 /* Data and reference forms for relocatable data. */
372 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
373 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
375 #ifndef DEBUG_FRAME_SECTION
376 #define DEBUG_FRAME_SECTION ".debug_frame"
379 #ifndef FUNC_BEGIN_LABEL
380 #define FUNC_BEGIN_LABEL "LFB"
383 #ifndef FUNC_END_LABEL
384 #define FUNC_END_LABEL "LFE"
387 #ifndef FRAME_BEGIN_LABEL
388 #define FRAME_BEGIN_LABEL "Lframe"
390 #define CIE_AFTER_SIZE_LABEL "LSCIE"
391 #define CIE_END_LABEL "LECIE"
392 #define FDE_LABEL "LSFDE"
393 #define FDE_AFTER_SIZE_LABEL "LASFDE"
394 #define FDE_END_LABEL "LEFDE"
395 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
396 #define LINE_NUMBER_END_LABEL "LELT"
397 #define LN_PROLOG_AS_LABEL "LASLTP"
398 #define LN_PROLOG_END_LABEL "LELTP"
399 #define DIE_LABEL_PREFIX "DW"
401 /* The DWARF 2 CFA column which tracks the return address. Normally this
402 is the column for PC, or the first column after all of the hard
404 #ifndef DWARF_FRAME_RETURN_COLUMN
406 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
408 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
412 /* The mapping from gcc register number to DWARF 2 CFA column number. By
413 default, we just provide columns for all registers. */
414 #ifndef DWARF_FRAME_REGNUM
415 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
418 /* Hook used by __throw. */
421 expand_builtin_dwarf_sp_column (void)
423 unsigned int dwarf_regnum
= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
);
424 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum
, 1));
427 /* Return a pointer to a copy of the section string name S with all
428 attributes stripped off, and an asterisk prepended (for assemble_name). */
431 stripattributes (const char *s
)
433 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
438 while (*s
&& *s
!= ',')
445 /* Generate code to initialize the register size table. */
448 expand_builtin_init_dwarf_reg_sizes (tree address
)
451 enum machine_mode mode
= TYPE_MODE (char_type_node
);
452 rtx addr
= expand_normal (address
);
453 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
454 bool wrote_return_column
= false;
456 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
458 int rnum
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i
), 1);
460 if (rnum
< DWARF_FRAME_REGISTERS
)
462 HOST_WIDE_INT offset
= rnum
* GET_MODE_SIZE (mode
);
463 enum machine_mode save_mode
= reg_raw_mode
[i
];
466 if (HARD_REGNO_CALL_PART_CLOBBERED (i
, save_mode
))
467 save_mode
= choose_hard_reg_mode (i
, 1, true);
468 if (DWARF_FRAME_REGNUM (i
) == DWARF_FRAME_RETURN_COLUMN
)
470 if (save_mode
== VOIDmode
)
472 wrote_return_column
= true;
474 size
= GET_MODE_SIZE (save_mode
);
478 emit_move_insn (adjust_address (mem
, mode
, offset
),
479 gen_int_mode (size
, mode
));
483 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
484 gcc_assert (wrote_return_column
);
485 i
= DWARF_ALT_FRAME_RETURN_COLUMN
;
486 wrote_return_column
= false;
488 i
= DWARF_FRAME_RETURN_COLUMN
;
491 if (! wrote_return_column
)
493 enum machine_mode save_mode
= Pmode
;
494 HOST_WIDE_INT offset
= i
* GET_MODE_SIZE (mode
);
495 HOST_WIDE_INT size
= GET_MODE_SIZE (save_mode
);
496 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
500 /* Convert a DWARF call frame info. operation to its string name */
503 dwarf_cfi_name (unsigned int cfi_opc
)
507 case DW_CFA_advance_loc
:
508 return "DW_CFA_advance_loc";
510 return "DW_CFA_offset";
512 return "DW_CFA_restore";
516 return "DW_CFA_set_loc";
517 case DW_CFA_advance_loc1
:
518 return "DW_CFA_advance_loc1";
519 case DW_CFA_advance_loc2
:
520 return "DW_CFA_advance_loc2";
521 case DW_CFA_advance_loc4
:
522 return "DW_CFA_advance_loc4";
523 case DW_CFA_offset_extended
:
524 return "DW_CFA_offset_extended";
525 case DW_CFA_restore_extended
:
526 return "DW_CFA_restore_extended";
527 case DW_CFA_undefined
:
528 return "DW_CFA_undefined";
529 case DW_CFA_same_value
:
530 return "DW_CFA_same_value";
531 case DW_CFA_register
:
532 return "DW_CFA_register";
533 case DW_CFA_remember_state
:
534 return "DW_CFA_remember_state";
535 case DW_CFA_restore_state
:
536 return "DW_CFA_restore_state";
538 return "DW_CFA_def_cfa";
539 case DW_CFA_def_cfa_register
:
540 return "DW_CFA_def_cfa_register";
541 case DW_CFA_def_cfa_offset
:
542 return "DW_CFA_def_cfa_offset";
545 case DW_CFA_def_cfa_expression
:
546 return "DW_CFA_def_cfa_expression";
547 case DW_CFA_expression
:
548 return "DW_CFA_expression";
549 case DW_CFA_offset_extended_sf
:
550 return "DW_CFA_offset_extended_sf";
551 case DW_CFA_def_cfa_sf
:
552 return "DW_CFA_def_cfa_sf";
553 case DW_CFA_def_cfa_offset_sf
:
554 return "DW_CFA_def_cfa_offset_sf";
556 /* SGI/MIPS specific */
557 case DW_CFA_MIPS_advance_loc8
:
558 return "DW_CFA_MIPS_advance_loc8";
561 case DW_CFA_GNU_window_save
:
562 return "DW_CFA_GNU_window_save";
563 case DW_CFA_GNU_args_size
:
564 return "DW_CFA_GNU_args_size";
565 case DW_CFA_GNU_negative_offset_extended
:
566 return "DW_CFA_GNU_negative_offset_extended";
569 return "DW_CFA_<unknown>";
573 /* Return a pointer to a newly allocated Call Frame Instruction. */
575 static inline dw_cfi_ref
578 dw_cfi_ref cfi
= ggc_alloc (sizeof (dw_cfi_node
));
580 cfi
->dw_cfi_next
= NULL
;
581 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
582 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
587 /* Add a Call Frame Instruction to list of instructions. */
590 add_cfi (dw_cfi_ref
*list_head
, dw_cfi_ref cfi
)
594 /* Find the end of the chain. */
595 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
601 /* Generate a new label for the CFI info to refer to. */
604 dwarf2out_cfi_label (void)
606 static char label
[20];
608 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", dwarf2out_cfi_label_num
++);
609 ASM_OUTPUT_LABEL (asm_out_file
, label
);
613 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
614 or to the CIE if LABEL is NULL. */
617 add_fde_cfi (const char *label
, dw_cfi_ref cfi
)
621 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
624 label
= dwarf2out_cfi_label ();
626 if (fde
->dw_fde_current_label
== NULL
627 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
631 fde
->dw_fde_current_label
= label
= xstrdup (label
);
633 /* Set the location counter to the new label. */
635 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
636 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
637 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
640 add_cfi (&fde
->dw_fde_cfi
, cfi
);
644 add_cfi (&cie_cfi_head
, cfi
);
647 /* Subroutine of lookup_cfa. */
650 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
)
652 switch (cfi
->dw_cfi_opc
)
654 case DW_CFA_def_cfa_offset
:
655 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
657 case DW_CFA_def_cfa_offset_sf
:
659 = cfi
->dw_cfi_oprnd1
.dw_cfi_offset
* DWARF_CIE_DATA_ALIGNMENT
;
661 case DW_CFA_def_cfa_register
:
662 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
665 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
666 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
668 case DW_CFA_def_cfa_sf
:
669 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
671 = cfi
->dw_cfi_oprnd2
.dw_cfi_offset
* DWARF_CIE_DATA_ALIGNMENT
;
673 case DW_CFA_def_cfa_expression
:
674 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
681 /* Find the previous value for the CFA. */
684 lookup_cfa (dw_cfa_location
*loc
)
688 loc
->reg
= INVALID_REGNUM
;
691 loc
->base_offset
= 0;
693 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
694 lookup_cfa_1 (cfi
, loc
);
696 if (fde_table_in_use
)
698 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
699 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
700 lookup_cfa_1 (cfi
, loc
);
704 /* The current rule for calculating the DWARF2 canonical frame address. */
705 static dw_cfa_location cfa
;
707 /* The register used for saving registers to the stack, and its offset
709 static dw_cfa_location cfa_store
;
711 /* The running total of the size of arguments pushed onto the stack. */
712 static HOST_WIDE_INT args_size
;
714 /* The last args_size we actually output. */
715 static HOST_WIDE_INT old_args_size
;
717 /* Entry point to update the canonical frame address (CFA).
718 LABEL is passed to add_fde_cfi. The value of CFA is now to be
719 calculated from REG+OFFSET. */
722 dwarf2out_def_cfa (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
729 def_cfa_1 (label
, &loc
);
732 /* Determine if two dw_cfa_location structures define the same data. */
735 cfa_equal_p (const dw_cfa_location
*loc1
, const dw_cfa_location
*loc2
)
737 return (loc1
->reg
== loc2
->reg
738 && loc1
->offset
== loc2
->offset
739 && loc1
->indirect
== loc2
->indirect
740 && (loc1
->indirect
== 0
741 || loc1
->base_offset
== loc2
->base_offset
));
744 /* This routine does the actual work. The CFA is now calculated from
745 the dw_cfa_location structure. */
748 def_cfa_1 (const char *label
, dw_cfa_location
*loc_p
)
751 dw_cfa_location old_cfa
, loc
;
756 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
757 cfa_store
.offset
= loc
.offset
;
759 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
760 lookup_cfa (&old_cfa
);
762 /* If nothing changed, no need to issue any call frame instructions. */
763 if (cfa_equal_p (&loc
, &old_cfa
))
768 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
770 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
771 the CFA register did not change but the offset did. */
774 HOST_WIDE_INT f_offset
= loc
.offset
/ DWARF_CIE_DATA_ALIGNMENT
;
775 gcc_assert (f_offset
* DWARF_CIE_DATA_ALIGNMENT
== loc
.offset
);
777 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset_sf
;
778 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= f_offset
;
782 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
783 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
787 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
788 else if (loc
.offset
== old_cfa
.offset
789 && old_cfa
.reg
!= INVALID_REGNUM
792 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
793 indicating the CFA register has changed to <register> but the
794 offset has not changed. */
795 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
796 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
800 else if (loc
.indirect
== 0)
802 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
803 indicating the CFA register has changed to <register> with
804 the specified offset. */
807 HOST_WIDE_INT f_offset
= loc
.offset
/ DWARF_CIE_DATA_ALIGNMENT
;
808 gcc_assert (f_offset
* DWARF_CIE_DATA_ALIGNMENT
== loc
.offset
);
810 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_sf
;
811 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
812 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= f_offset
;
816 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
817 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
818 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
823 /* Construct a DW_CFA_def_cfa_expression instruction to
824 calculate the CFA using a full location expression since no
825 register-offset pair is available. */
826 struct dw_loc_descr_struct
*loc_list
;
828 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
829 loc_list
= build_cfa_loc (&loc
, 0);
830 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
833 add_fde_cfi (label
, cfi
);
836 /* Add the CFI for saving a register. REG is the CFA column number.
837 LABEL is passed to add_fde_cfi.
838 If SREG is -1, the register is saved at OFFSET from the CFA;
839 otherwise it is saved in SREG. */
842 reg_save (const char *label
, unsigned int reg
, unsigned int sreg
, HOST_WIDE_INT offset
)
844 dw_cfi_ref cfi
= new_cfi ();
846 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
848 if (sreg
== INVALID_REGNUM
)
851 /* The register number won't fit in 6 bits, so we have to use
853 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
855 cfi
->dw_cfi_opc
= DW_CFA_offset
;
857 #ifdef ENABLE_CHECKING
859 /* If we get an offset that is not a multiple of
860 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
861 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
863 HOST_WIDE_INT check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
865 gcc_assert (check_offset
* DWARF_CIE_DATA_ALIGNMENT
== offset
);
868 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
870 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
872 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
874 else if (sreg
== reg
)
875 cfi
->dw_cfi_opc
= DW_CFA_same_value
;
878 cfi
->dw_cfi_opc
= DW_CFA_register
;
879 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
882 add_fde_cfi (label
, cfi
);
885 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
886 This CFI tells the unwinder that it needs to restore the window registers
887 from the previous frame's window save area.
889 ??? Perhaps we should note in the CIE where windows are saved (instead of
890 assuming 0(cfa)) and what registers are in the window. */
893 dwarf2out_window_save (const char *label
)
895 dw_cfi_ref cfi
= new_cfi ();
897 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
898 add_fde_cfi (label
, cfi
);
901 /* Add a CFI to update the running total of the size of arguments
902 pushed onto the stack. */
905 dwarf2out_args_size (const char *label
, HOST_WIDE_INT size
)
909 if (size
== old_args_size
)
912 old_args_size
= size
;
915 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
916 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
917 add_fde_cfi (label
, cfi
);
920 /* Entry point for saving a register to the stack. REG is the GCC register
921 number. LABEL and OFFSET are passed to reg_save. */
924 dwarf2out_reg_save (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
926 reg_save (label
, DWARF_FRAME_REGNUM (reg
), INVALID_REGNUM
, offset
);
929 /* Entry point for saving the return address in the stack.
930 LABEL and OFFSET are passed to reg_save. */
933 dwarf2out_return_save (const char *label
, HOST_WIDE_INT offset
)
935 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, INVALID_REGNUM
, offset
);
938 /* Entry point for saving the return address in a register.
939 LABEL and SREG are passed to reg_save. */
942 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
944 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, DWARF_FRAME_REGNUM (sreg
), 0);
947 /* Record the initial position of the return address. RTL is
948 INCOMING_RETURN_ADDR_RTX. */
951 initial_return_save (rtx rtl
)
953 unsigned int reg
= INVALID_REGNUM
;
954 HOST_WIDE_INT offset
= 0;
956 switch (GET_CODE (rtl
))
959 /* RA is in a register. */
960 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
964 /* RA is on the stack. */
966 switch (GET_CODE (rtl
))
969 gcc_assert (REGNO (rtl
) == STACK_POINTER_REGNUM
);
974 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
975 offset
= INTVAL (XEXP (rtl
, 1));
979 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
980 offset
= -INTVAL (XEXP (rtl
, 1));
990 /* The return address is at some offset from any value we can
991 actually load. For instance, on the SPARC it is in %i7+8. Just
992 ignore the offset for now; it doesn't matter for unwinding frames. */
993 gcc_assert (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
);
994 initial_return_save (XEXP (rtl
, 0));
1001 if (reg
!= DWARF_FRAME_RETURN_COLUMN
)
1002 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
1005 /* Given a SET, calculate the amount of stack adjustment it
1008 static HOST_WIDE_INT
1009 stack_adjust_offset (rtx pattern
)
1011 rtx src
= SET_SRC (pattern
);
1012 rtx dest
= SET_DEST (pattern
);
1013 HOST_WIDE_INT offset
= 0;
1016 if (dest
== stack_pointer_rtx
)
1018 /* (set (reg sp) (plus (reg sp) (const_int))) */
1019 code
= GET_CODE (src
);
1020 if (! (code
== PLUS
|| code
== MINUS
)
1021 || XEXP (src
, 0) != stack_pointer_rtx
1022 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1025 offset
= INTVAL (XEXP (src
, 1));
1029 else if (MEM_P (dest
))
1031 /* (set (mem (pre_dec (reg sp))) (foo)) */
1032 src
= XEXP (dest
, 0);
1033 code
= GET_CODE (src
);
1039 if (XEXP (src
, 0) == stack_pointer_rtx
)
1041 rtx val
= XEXP (XEXP (src
, 1), 1);
1042 /* We handle only adjustments by constant amount. */
1043 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
1044 && GET_CODE (val
) == CONST_INT
);
1045 offset
= -INTVAL (val
);
1052 if (XEXP (src
, 0) == stack_pointer_rtx
)
1054 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1061 if (XEXP (src
, 0) == stack_pointer_rtx
)
1063 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1078 /* Check INSN to see if it looks like a push or a stack adjustment, and
1079 make a note of it if it does. EH uses this information to find out how
1080 much extra space it needs to pop off the stack. */
1083 dwarf2out_stack_adjust (rtx insn
, bool after_p ATTRIBUTE_UNUSED
)
1085 HOST_WIDE_INT offset
;
1089 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1090 with this function. Proper support would require all frame-related
1091 insns to be marked, and to be able to handle saving state around
1092 epilogues textually in the middle of the function. */
1093 if (prologue_epilogue_contains (insn
) || sibcall_epilogue_contains (insn
))
1096 if (BARRIER_P (insn
))
1098 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1099 the compiler will have already emitted a stack adjustment, but
1100 doesn't bother for calls to noreturn functions. */
1101 #ifdef STACK_GROWS_DOWNWARD
1102 offset
= -args_size
;
1107 else if (GET_CODE (PATTERN (insn
)) == SET
)
1108 offset
= stack_adjust_offset (PATTERN (insn
));
1109 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1110 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1112 /* There may be stack adjustments inside compound insns. Search
1114 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1115 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1116 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1118 else if (GET_CODE (insn
) == CALL_INSN
)
1123 /* We handle this separately because we want stack adjustments in a
1124 CALL_INSN to be handled. */;
1125 if (GET_CODE (insn
) == CALL_INSN
)
1127 /* If only calls can throw, adjust args_size only at call sites. */
1128 if (!flag_asynchronous_unwind_tables
)
1129 dwarf2out_args_size ("", args_size
);
1135 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1136 cfa
.offset
+= offset
;
1138 #ifndef STACK_GROWS_DOWNWARD
1142 args_size
+= offset
;
1146 /* If only calls can throw and we have a frame pointer, we'll save
1147 up adjustments until we see the CALL_INSN. We used to return
1148 early and derive args_size from NARGS in the CALL_INSN itself,
1149 but that doesn't compute the right value if we have nested call
1150 expansions, e.g., stack adjustments for a call have already been
1151 emitted, and then we issue another call to compute an argument
1152 for the enclosing call (i.e., bar (foo ())). */
1153 if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1156 label
= dwarf2out_cfi_label ();
1157 def_cfa_1 (label
, &cfa
);
1158 if (flag_asynchronous_unwind_tables
)
1159 dwarf2out_args_size (label
, args_size
);
1164 /* We delay emitting a register save until either (a) we reach the end
1165 of the prologue or (b) the register is clobbered. This clusters
1166 register saves so that there are fewer pc advances. */
1168 struct queued_reg_save
GTY(())
1170 struct queued_reg_save
*next
;
1172 HOST_WIDE_INT cfa_offset
;
1176 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1178 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1179 struct reg_saved_in_data
GTY(()) {
1184 /* A list of registers saved in other registers.
1185 The list intentionally has a small maximum capacity of 4; if your
1186 port needs more than that, you might consider implementing a
1187 more efficient data structure. */
1188 static GTY(()) struct reg_saved_in_data regs_saved_in_regs
[4];
1189 static GTY(()) size_t num_regs_saved_in_regs
;
1191 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1192 static const char *last_reg_save_label
;
1194 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1195 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1198 queue_reg_save (const char *label
, rtx reg
, rtx sreg
, HOST_WIDE_INT offset
)
1200 struct queued_reg_save
*q
;
1202 /* Duplicates waste space, but it's also necessary to remove them
1203 for correctness, since the queue gets output in reverse
1205 for (q
= queued_reg_saves
; q
!= NULL
; q
= q
->next
)
1206 if (REGNO (q
->reg
) == REGNO (reg
))
1211 q
= ggc_alloc (sizeof (*q
));
1212 q
->next
= queued_reg_saves
;
1213 queued_reg_saves
= q
;
1217 q
->cfa_offset
= offset
;
1218 q
->saved_reg
= sreg
;
1220 last_reg_save_label
= label
;
1223 /* Output all the entries in QUEUED_REG_SAVES. */
1226 flush_queued_reg_saves (void)
1228 struct queued_reg_save
*q
;
1230 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1233 unsigned int reg
, sreg
;
1235 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1236 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (q
->reg
))
1238 if (q
->saved_reg
&& i
== num_regs_saved_in_regs
)
1240 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1241 num_regs_saved_in_regs
++;
1243 if (i
!= num_regs_saved_in_regs
)
1245 regs_saved_in_regs
[i
].orig_reg
= q
->reg
;
1246 regs_saved_in_regs
[i
].saved_in_reg
= q
->saved_reg
;
1249 reg
= DWARF_FRAME_REGNUM (REGNO (q
->reg
));
1251 sreg
= DWARF_FRAME_REGNUM (REGNO (q
->saved_reg
));
1253 sreg
= INVALID_REGNUM
;
1254 reg_save (last_reg_save_label
, reg
, sreg
, q
->cfa_offset
);
1257 queued_reg_saves
= NULL
;
1258 last_reg_save_label
= NULL
;
1261 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1262 location for? Or, does it clobber a register which we've previously
1263 said that some other register is saved in, and for which we now
1264 have a new location for? */
1267 clobbers_queued_reg_save (rtx insn
)
1269 struct queued_reg_save
*q
;
1271 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1274 if (modified_in_p (q
->reg
, insn
))
1276 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1277 if (REGNO (q
->reg
) == REGNO (regs_saved_in_regs
[i
].orig_reg
)
1278 && modified_in_p (regs_saved_in_regs
[i
].saved_in_reg
, insn
))
1285 /* Entry point for saving the first register into the second. */
1288 dwarf2out_reg_save_reg (const char *label
, rtx reg
, rtx sreg
)
1291 unsigned int regno
, sregno
;
1293 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1294 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (reg
))
1296 if (i
== num_regs_saved_in_regs
)
1298 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1299 num_regs_saved_in_regs
++;
1301 regs_saved_in_regs
[i
].orig_reg
= reg
;
1302 regs_saved_in_regs
[i
].saved_in_reg
= sreg
;
1304 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
1305 sregno
= DWARF_FRAME_REGNUM (REGNO (sreg
));
1306 reg_save (label
, regno
, sregno
, 0);
1309 /* What register, if any, is currently saved in REG? */
1312 reg_saved_in (rtx reg
)
1314 unsigned int regn
= REGNO (reg
);
1316 struct queued_reg_save
*q
;
1318 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1319 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1322 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1323 if (regs_saved_in_regs
[i
].saved_in_reg
1324 && regn
== REGNO (regs_saved_in_regs
[i
].saved_in_reg
))
1325 return regs_saved_in_regs
[i
].orig_reg
;
1331 /* A temporary register holding an integral value used in adjusting SP
1332 or setting up the store_reg. The "offset" field holds the integer
1333 value, not an offset. */
1334 static dw_cfa_location cfa_temp
;
1336 /* Record call frame debugging information for an expression EXPR,
1337 which either sets SP or FP (adjusting how we calculate the frame
1338 address) or saves a register to the stack or another register.
1339 LABEL indicates the address of EXPR.
1341 This function encodes a state machine mapping rtxes to actions on
1342 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1343 users need not read the source code.
1345 The High-Level Picture
1347 Changes in the register we use to calculate the CFA: Currently we
1348 assume that if you copy the CFA register into another register, we
1349 should take the other one as the new CFA register; this seems to
1350 work pretty well. If it's wrong for some target, it's simple
1351 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1353 Changes in the register we use for saving registers to the stack:
1354 This is usually SP, but not always. Again, we deduce that if you
1355 copy SP into another register (and SP is not the CFA register),
1356 then the new register is the one we will be using for register
1357 saves. This also seems to work.
1359 Register saves: There's not much guesswork about this one; if
1360 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1361 register save, and the register used to calculate the destination
1362 had better be the one we think we're using for this purpose.
1363 It's also assumed that a copy from a call-saved register to another
1364 register is saving that register if RTX_FRAME_RELATED_P is set on
1365 that instruction. If the copy is from a call-saved register to
1366 the *same* register, that means that the register is now the same
1367 value as in the caller.
1369 Except: If the register being saved is the CFA register, and the
1370 offset is nonzero, we are saving the CFA, so we assume we have to
1371 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1372 the intent is to save the value of SP from the previous frame.
1374 In addition, if a register has previously been saved to a different
1377 Invariants / Summaries of Rules
1379 cfa current rule for calculating the CFA. It usually
1380 consists of a register and an offset.
1381 cfa_store register used by prologue code to save things to the stack
1382 cfa_store.offset is the offset from the value of
1383 cfa_store.reg to the actual CFA
1384 cfa_temp register holding an integral value. cfa_temp.offset
1385 stores the value, which will be used to adjust the
1386 stack pointer. cfa_temp is also used like cfa_store,
1387 to track stores to the stack via fp or a temp reg.
1389 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1390 with cfa.reg as the first operand changes the cfa.reg and its
1391 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1394 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1395 expression yielding a constant. This sets cfa_temp.reg
1396 and cfa_temp.offset.
1398 Rule 5: Create a new register cfa_store used to save items to the
1401 Rules 10-14: Save a register to the stack. Define offset as the
1402 difference of the original location and cfa_store's
1403 location (or cfa_temp's location if cfa_temp is used).
1407 "{a,b}" indicates a choice of a xor b.
1408 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1411 (set <reg1> <reg2>:cfa.reg)
1412 effects: cfa.reg = <reg1>
1413 cfa.offset unchanged
1414 cfa_temp.reg = <reg1>
1415 cfa_temp.offset = cfa.offset
1418 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1419 {<const_int>,<reg>:cfa_temp.reg}))
1420 effects: cfa.reg = sp if fp used
1421 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1422 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1423 if cfa_store.reg==sp
1426 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1427 effects: cfa.reg = fp
1428 cfa_offset += +/- <const_int>
1431 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1432 constraints: <reg1> != fp
1434 effects: cfa.reg = <reg1>
1435 cfa_temp.reg = <reg1>
1436 cfa_temp.offset = cfa.offset
1439 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1440 constraints: <reg1> != fp
1442 effects: cfa_store.reg = <reg1>
1443 cfa_store.offset = cfa.offset - cfa_temp.offset
1446 (set <reg> <const_int>)
1447 effects: cfa_temp.reg = <reg>
1448 cfa_temp.offset = <const_int>
1451 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1452 effects: cfa_temp.reg = <reg1>
1453 cfa_temp.offset |= <const_int>
1456 (set <reg> (high <exp>))
1460 (set <reg> (lo_sum <exp> <const_int>))
1461 effects: cfa_temp.reg = <reg>
1462 cfa_temp.offset = <const_int>
1465 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1466 effects: cfa_store.offset -= <const_int>
1467 cfa.offset = cfa_store.offset if cfa.reg == sp
1469 cfa.base_offset = -cfa_store.offset
1472 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1473 effects: cfa_store.offset += -/+ mode_size(mem)
1474 cfa.offset = cfa_store.offset if cfa.reg == sp
1476 cfa.base_offset = -cfa_store.offset
1479 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1482 effects: cfa.reg = <reg1>
1483 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1486 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1487 effects: cfa.reg = <reg1>
1488 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1491 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1492 effects: cfa.reg = <reg1>
1493 cfa.base_offset = -cfa_temp.offset
1494 cfa_temp.offset -= mode_size(mem)
1497 Â (set <reg> {unspec, unspec_volatile})
1498 Â effects: target-dependent */
1501 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
1504 HOST_WIDE_INT offset
;
1506 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1507 the PARALLEL independently. The first element is always processed if
1508 it is a SET. This is for backward compatibility. Other elements
1509 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1510 flag is set in them. */
1511 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1514 int limit
= XVECLEN (expr
, 0);
1516 for (par_index
= 0; par_index
< limit
; par_index
++)
1517 if (GET_CODE (XVECEXP (expr
, 0, par_index
)) == SET
1518 && (RTX_FRAME_RELATED_P (XVECEXP (expr
, 0, par_index
))
1520 dwarf2out_frame_debug_expr (XVECEXP (expr
, 0, par_index
), label
);
1525 gcc_assert (GET_CODE (expr
) == SET
);
1527 src
= SET_SRC (expr
);
1528 dest
= SET_DEST (expr
);
1532 rtx rsi
= reg_saved_in (src
);
1537 switch (GET_CODE (dest
))
1540 switch (GET_CODE (src
))
1542 /* Setting FP from SP. */
1544 if (cfa
.reg
== (unsigned) REGNO (src
))
1547 /* Update the CFA rule wrt SP or FP. Make sure src is
1548 relative to the current CFA register.
1550 We used to require that dest be either SP or FP, but the
1551 ARM copies SP to a temporary register, and from there to
1552 FP. So we just rely on the backends to only set
1553 RTX_FRAME_RELATED_P on appropriate insns. */
1554 cfa
.reg
= REGNO (dest
);
1555 cfa_temp
.reg
= cfa
.reg
;
1556 cfa_temp
.offset
= cfa
.offset
;
1560 /* Saving a register in a register. */
1561 gcc_assert (!fixed_regs
[REGNO (dest
)]
1562 /* For the SPARC and its register window. */
1563 || (DWARF_FRAME_REGNUM (REGNO (src
))
1564 == DWARF_FRAME_RETURN_COLUMN
));
1565 queue_reg_save (label
, src
, dest
, 0);
1572 if (dest
== stack_pointer_rtx
)
1576 switch (GET_CODE (XEXP (src
, 1)))
1579 offset
= INTVAL (XEXP (src
, 1));
1582 gcc_assert ((unsigned) REGNO (XEXP (src
, 1))
1584 offset
= cfa_temp
.offset
;
1590 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1592 /* Restoring SP from FP in the epilogue. */
1593 gcc_assert (cfa
.reg
== (unsigned) HARD_FRAME_POINTER_REGNUM
);
1594 cfa
.reg
= STACK_POINTER_REGNUM
;
1596 else if (GET_CODE (src
) == LO_SUM
)
1597 /* Assume we've set the source reg of the LO_SUM from sp. */
1600 gcc_assert (XEXP (src
, 0) == stack_pointer_rtx
);
1602 if (GET_CODE (src
) != MINUS
)
1604 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1605 cfa
.offset
+= offset
;
1606 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1607 cfa_store
.offset
+= offset
;
1609 else if (dest
== hard_frame_pointer_rtx
)
1612 /* Either setting the FP from an offset of the SP,
1613 or adjusting the FP */
1614 gcc_assert (frame_pointer_needed
);
1616 gcc_assert (REG_P (XEXP (src
, 0))
1617 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1618 && GET_CODE (XEXP (src
, 1)) == CONST_INT
);
1619 offset
= INTVAL (XEXP (src
, 1));
1620 if (GET_CODE (src
) != MINUS
)
1622 cfa
.offset
+= offset
;
1623 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1627 gcc_assert (GET_CODE (src
) != MINUS
);
1630 if (REG_P (XEXP (src
, 0))
1631 && REGNO (XEXP (src
, 0)) == cfa
.reg
1632 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1634 /* Setting a temporary CFA register that will be copied
1635 into the FP later on. */
1636 offset
= - INTVAL (XEXP (src
, 1));
1637 cfa
.offset
+= offset
;
1638 cfa
.reg
= REGNO (dest
);
1639 /* Or used to save regs to the stack. */
1640 cfa_temp
.reg
= cfa
.reg
;
1641 cfa_temp
.offset
= cfa
.offset
;
1645 else if (REG_P (XEXP (src
, 0))
1646 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1647 && XEXP (src
, 1) == stack_pointer_rtx
)
1649 /* Setting a scratch register that we will use instead
1650 of SP for saving registers to the stack. */
1651 gcc_assert (cfa
.reg
== STACK_POINTER_REGNUM
);
1652 cfa_store
.reg
= REGNO (dest
);
1653 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
1657 else if (GET_CODE (src
) == LO_SUM
1658 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1660 cfa_temp
.reg
= REGNO (dest
);
1661 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
1670 cfa_temp
.reg
= REGNO (dest
);
1671 cfa_temp
.offset
= INTVAL (src
);
1676 gcc_assert (REG_P (XEXP (src
, 0))
1677 && (unsigned) REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1678 && GET_CODE (XEXP (src
, 1)) == CONST_INT
);
1680 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
1681 cfa_temp
.reg
= REGNO (dest
);
1682 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
1685 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1686 which will fill in all of the bits. */
1693 case UNSPEC_VOLATILE
:
1694 gcc_assert (targetm
.dwarf_handle_frame_unspec
);
1695 targetm
.dwarf_handle_frame_unspec (label
, expr
, XINT (src
, 1));
1702 def_cfa_1 (label
, &cfa
);
1706 gcc_assert (REG_P (src
));
1708 /* Saving a register to the stack. Make sure dest is relative to the
1710 switch (GET_CODE (XEXP (dest
, 0)))
1715 /* We can't handle variable size modifications. */
1716 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1))
1718 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1720 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
1721 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
1723 cfa_store
.offset
+= offset
;
1724 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1725 cfa
.offset
= cfa_store
.offset
;
1727 offset
= -cfa_store
.offset
;
1733 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1734 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1737 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
1738 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
1740 cfa_store
.offset
+= offset
;
1741 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1742 cfa
.offset
= cfa_store
.offset
;
1744 offset
= -cfa_store
.offset
;
1748 /* With an offset. */
1755 gcc_assert (GET_CODE (XEXP (XEXP (dest
, 0), 1)) == CONST_INT
1756 && REG_P (XEXP (XEXP (dest
, 0), 0)));
1757 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1758 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1761 regno
= REGNO (XEXP (XEXP (dest
, 0), 0));
1763 if (cfa_store
.reg
== (unsigned) regno
)
1764 offset
-= cfa_store
.offset
;
1767 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
1768 offset
-= cfa_temp
.offset
;
1774 /* Without an offset. */
1777 int regno
= REGNO (XEXP (dest
, 0));
1779 if (cfa_store
.reg
== (unsigned) regno
)
1780 offset
= -cfa_store
.offset
;
1783 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
1784 offset
= -cfa_temp
.offset
;
1791 gcc_assert (cfa_temp
.reg
1792 == (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)));
1793 offset
= -cfa_temp
.offset
;
1794 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1801 if (REGNO (src
) != STACK_POINTER_REGNUM
1802 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1803 && (unsigned) REGNO (src
) == cfa
.reg
)
1805 /* We're storing the current CFA reg into the stack. */
1807 if (cfa
.offset
== 0)
1809 /* If the source register is exactly the CFA, assume
1810 we're saving SP like any other register; this happens
1812 def_cfa_1 (label
, &cfa
);
1813 queue_reg_save (label
, stack_pointer_rtx
, NULL_RTX
, offset
);
1818 /* Otherwise, we'll need to look in the stack to
1819 calculate the CFA. */
1820 rtx x
= XEXP (dest
, 0);
1824 gcc_assert (REG_P (x
));
1826 cfa
.reg
= REGNO (x
);
1827 cfa
.base_offset
= offset
;
1829 def_cfa_1 (label
, &cfa
);
1834 def_cfa_1 (label
, &cfa
);
1835 queue_reg_save (label
, src
, NULL_RTX
, offset
);
1843 /* Record call frame debugging information for INSN, which either
1844 sets SP or FP (adjusting how we calculate the frame address) or saves a
1845 register to the stack. If INSN is NULL_RTX, initialize our state.
1847 If AFTER_P is false, we're being called before the insn is emitted,
1848 otherwise after. Call instructions get invoked twice. */
1851 dwarf2out_frame_debug (rtx insn
, bool after_p
)
1856 if (insn
== NULL_RTX
)
1860 /* Flush any queued register saves. */
1861 flush_queued_reg_saves ();
1863 /* Set up state for generating call frame debug info. */
1866 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
));
1868 cfa
.reg
= STACK_POINTER_REGNUM
;
1871 cfa_temp
.offset
= 0;
1873 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1875 regs_saved_in_regs
[i
].orig_reg
= NULL_RTX
;
1876 regs_saved_in_regs
[i
].saved_in_reg
= NULL_RTX
;
1878 num_regs_saved_in_regs
= 0;
1882 if (!NONJUMP_INSN_P (insn
) || clobbers_queued_reg_save (insn
))
1883 flush_queued_reg_saves ();
1885 if (! RTX_FRAME_RELATED_P (insn
))
1887 if (!ACCUMULATE_OUTGOING_ARGS
)
1888 dwarf2out_stack_adjust (insn
, after_p
);
1892 label
= dwarf2out_cfi_label ();
1893 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1895 insn
= XEXP (src
, 0);
1897 insn
= PATTERN (insn
);
1899 dwarf2out_frame_debug_expr (insn
, label
);
1904 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1905 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1906 (enum dwarf_call_frame_info cfi
);
1908 static enum dw_cfi_oprnd_type
1909 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
1914 case DW_CFA_GNU_window_save
:
1915 return dw_cfi_oprnd_unused
;
1917 case DW_CFA_set_loc
:
1918 case DW_CFA_advance_loc1
:
1919 case DW_CFA_advance_loc2
:
1920 case DW_CFA_advance_loc4
:
1921 case DW_CFA_MIPS_advance_loc8
:
1922 return dw_cfi_oprnd_addr
;
1925 case DW_CFA_offset_extended
:
1926 case DW_CFA_def_cfa
:
1927 case DW_CFA_offset_extended_sf
:
1928 case DW_CFA_def_cfa_sf
:
1929 case DW_CFA_restore_extended
:
1930 case DW_CFA_undefined
:
1931 case DW_CFA_same_value
:
1932 case DW_CFA_def_cfa_register
:
1933 case DW_CFA_register
:
1934 return dw_cfi_oprnd_reg_num
;
1936 case DW_CFA_def_cfa_offset
:
1937 case DW_CFA_GNU_args_size
:
1938 case DW_CFA_def_cfa_offset_sf
:
1939 return dw_cfi_oprnd_offset
;
1941 case DW_CFA_def_cfa_expression
:
1942 case DW_CFA_expression
:
1943 return dw_cfi_oprnd_loc
;
1950 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1951 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1952 (enum dwarf_call_frame_info cfi
);
1954 static enum dw_cfi_oprnd_type
1955 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
1959 case DW_CFA_def_cfa
:
1960 case DW_CFA_def_cfa_sf
:
1962 case DW_CFA_offset_extended_sf
:
1963 case DW_CFA_offset_extended
:
1964 return dw_cfi_oprnd_offset
;
1966 case DW_CFA_register
:
1967 return dw_cfi_oprnd_reg_num
;
1970 return dw_cfi_oprnd_unused
;
1974 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1976 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
1977 switch to the data section instead, and write out a synthetic label
1981 switch_to_eh_frame_section (void)
1985 #ifdef EH_FRAME_SECTION_NAME
1986 if (eh_frame_section
== 0)
1990 if (EH_TABLES_CAN_BE_READ_ONLY
)
1996 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
1998 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2000 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2002 flags
= ((! flag_pic
2003 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
2004 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
2005 && (per_encoding
& 0x70) != DW_EH_PE_absptr
2006 && (per_encoding
& 0x70) != DW_EH_PE_aligned
2007 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
2008 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
2009 ? 0 : SECTION_WRITE
);
2012 flags
= SECTION_WRITE
;
2013 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
2017 if (eh_frame_section
)
2018 switch_to_section (eh_frame_section
);
2021 /* We have no special eh_frame section. Put the information in
2022 the data section and emit special labels to guide collect2. */
2023 switch_to_section (data_section
);
2024 label
= get_file_function_name ('F');
2025 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2026 targetm
.asm_out
.globalize_label (asm_out_file
,
2027 IDENTIFIER_POINTER (label
));
2028 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
2032 /* Output a Call Frame Information opcode and its operand(s). */
2035 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
2038 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
2039 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
2040 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
2041 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
2042 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
2043 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
2045 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2046 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2047 "DW_CFA_offset, column 0x%lx", r
);
2048 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2050 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
2052 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2053 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2054 "DW_CFA_restore, column 0x%lx", r
);
2058 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
2059 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
2061 switch (cfi
->dw_cfi_opc
)
2063 case DW_CFA_set_loc
:
2065 dw2_asm_output_encoded_addr_rtx (
2066 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2067 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
2070 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2071 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
2074 case DW_CFA_advance_loc1
:
2075 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2076 fde
->dw_fde_current_label
, NULL
);
2077 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2080 case DW_CFA_advance_loc2
:
2081 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2082 fde
->dw_fde_current_label
, NULL
);
2083 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2086 case DW_CFA_advance_loc4
:
2087 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2088 fde
->dw_fde_current_label
, NULL
);
2089 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2092 case DW_CFA_MIPS_advance_loc8
:
2093 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2094 fde
->dw_fde_current_label
, NULL
);
2095 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2098 case DW_CFA_offset_extended
:
2099 case DW_CFA_def_cfa
:
2100 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2101 dw2_asm_output_data_uleb128 (r
, NULL
);
2102 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2105 case DW_CFA_offset_extended_sf
:
2106 case DW_CFA_def_cfa_sf
:
2107 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2108 dw2_asm_output_data_uleb128 (r
, NULL
);
2109 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2112 case DW_CFA_restore_extended
:
2113 case DW_CFA_undefined
:
2114 case DW_CFA_same_value
:
2115 case DW_CFA_def_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
);
2120 case DW_CFA_register
:
2121 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2122 dw2_asm_output_data_uleb128 (r
, NULL
);
2123 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
2124 dw2_asm_output_data_uleb128 (r
, NULL
);
2127 case DW_CFA_def_cfa_offset
:
2128 case DW_CFA_GNU_args_size
:
2129 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2132 case DW_CFA_def_cfa_offset_sf
:
2133 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2136 case DW_CFA_GNU_window_save
:
2139 case DW_CFA_def_cfa_expression
:
2140 case DW_CFA_expression
:
2141 output_cfa_loc (cfi
);
2144 case DW_CFA_GNU_negative_offset_extended
:
2145 /* Obsoleted by DW_CFA_offset_extended_sf. */
2154 /* Output the call frame information used to record information
2155 that relates to calculating the frame pointer, and records the
2156 location of saved registers. */
2159 output_call_frame_info (int for_eh
)
2164 char l1
[20], l2
[20], section_start_label
[20];
2165 bool any_lsda_needed
= false;
2166 char augmentation
[6];
2167 int augmentation_size
;
2168 int fde_encoding
= DW_EH_PE_absptr
;
2169 int per_encoding
= DW_EH_PE_absptr
;
2170 int lsda_encoding
= DW_EH_PE_absptr
;
2173 /* Don't emit a CIE if there won't be any FDEs. */
2174 if (fde_table_in_use
== 0)
2177 /* If we make FDEs linkonce, we may have to emit an empty label for
2178 an FDE that wouldn't otherwise be emitted. We want to avoid
2179 having an FDE kept around when the function it refers to is
2180 discarded. Example where this matters: a primary function
2181 template in C++ requires EH information, but an explicit
2182 specialization doesn't. */
2183 if (TARGET_USES_WEAK_UNWIND_INFO
2184 && ! flag_asynchronous_unwind_tables
2186 for (i
= 0; i
< fde_table_in_use
; i
++)
2187 if ((fde_table
[i
].nothrow
|| fde_table
[i
].all_throwers_are_sibcalls
)
2188 && !fde_table
[i
].uses_eh_lsda
2189 && ! DECL_WEAK (fde_table
[i
].decl
))
2190 targetm
.asm_out
.unwind_label (asm_out_file
, fde_table
[i
].decl
,
2191 for_eh
, /* empty */ 1);
2193 /* If we don't have any functions we'll want to unwind out of, don't
2194 emit any EH unwind information. Note that if exceptions aren't
2195 enabled, we won't have collected nothrow information, and if we
2196 asked for asynchronous tables, we always want this info. */
2199 bool any_eh_needed
= !flag_exceptions
|| flag_asynchronous_unwind_tables
;
2201 for (i
= 0; i
< fde_table_in_use
; i
++)
2202 if (fde_table
[i
].uses_eh_lsda
)
2203 any_eh_needed
= any_lsda_needed
= true;
2204 else if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
2205 any_eh_needed
= true;
2206 else if (! fde_table
[i
].nothrow
2207 && ! fde_table
[i
].all_throwers_are_sibcalls
)
2208 any_eh_needed
= true;
2210 if (! any_eh_needed
)
2214 /* We're going to be generating comments, so turn on app. */
2219 switch_to_eh_frame_section ();
2221 switch_to_section (debug_frame_section
);
2223 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
2224 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
2226 /* Output the CIE. */
2227 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
2228 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
2229 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
2230 dw2_asm_output_data (4, 0xffffffff,
2231 "Initial length escape value indicating 64-bit DWARF extension");
2232 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2233 "Length of Common Information Entry");
2234 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2236 /* Now that the CIE pointer is PC-relative for EH,
2237 use 0 to identify the CIE. */
2238 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
2239 (for_eh
? 0 : DWARF_CIE_ID
),
2240 "CIE Identifier Tag");
2242 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
2244 augmentation
[0] = 0;
2245 augmentation_size
= 0;
2251 z Indicates that a uleb128 is present to size the
2252 augmentation section.
2253 L Indicates the encoding (and thus presence) of
2254 an LSDA pointer in the FDE augmentation.
2255 R Indicates a non-default pointer encoding for
2257 P Indicates the presence of an encoding + language
2258 personality routine in the CIE augmentation. */
2260 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2261 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2262 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2264 p
= augmentation
+ 1;
2265 if (eh_personality_libfunc
)
2268 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
2270 if (any_lsda_needed
)
2273 augmentation_size
+= 1;
2275 if (fde_encoding
!= DW_EH_PE_absptr
)
2278 augmentation_size
+= 1;
2280 if (p
> augmentation
+ 1)
2282 augmentation
[0] = 'z';
2286 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2287 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
2289 int offset
= ( 4 /* Length */
2291 + 1 /* CIE version */
2292 + strlen (augmentation
) + 1 /* Augmentation */
2293 + size_of_uleb128 (1) /* Code alignment */
2294 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
2296 + 1 /* Augmentation size */
2297 + 1 /* Personality encoding */ );
2298 int pad
= -offset
& (PTR_SIZE
- 1);
2300 augmentation_size
+= pad
;
2302 /* Augmentations should be small, so there's scarce need to
2303 iterate for a solution. Die if we exceed one uleb128 byte. */
2304 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
2308 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
2309 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2310 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
2311 "CIE Data Alignment Factor");
2313 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
2314 if (DW_CIE_VERSION
== 1)
2315 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
2317 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
2319 if (augmentation
[0])
2321 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
2322 if (eh_personality_libfunc
)
2324 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
2325 eh_data_format_name (per_encoding
));
2326 dw2_asm_output_encoded_addr_rtx (per_encoding
,
2327 eh_personality_libfunc
,
2331 if (any_lsda_needed
)
2332 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
2333 eh_data_format_name (lsda_encoding
));
2335 if (fde_encoding
!= DW_EH_PE_absptr
)
2336 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
2337 eh_data_format_name (fde_encoding
));
2340 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2341 output_cfi (cfi
, NULL
, for_eh
);
2343 /* Pad the CIE out to an address sized boundary. */
2344 ASM_OUTPUT_ALIGN (asm_out_file
,
2345 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
2346 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2348 /* Loop through all of the FDE's. */
2349 for (i
= 0; i
< fde_table_in_use
; i
++)
2351 fde
= &fde_table
[i
];
2353 /* Don't emit EH unwind info for leaf functions that don't need it. */
2354 if (for_eh
&& !flag_asynchronous_unwind_tables
&& flag_exceptions
2355 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
2356 && ! (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
2357 && !fde
->uses_eh_lsda
)
2360 targetm
.asm_out
.unwind_label (asm_out_file
, fde
->decl
, for_eh
, /* empty */ 0);
2361 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
2362 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
2363 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
2364 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
2365 dw2_asm_output_data (4, 0xffffffff,
2366 "Initial length escape value indicating 64-bit DWARF extension");
2367 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2369 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2372 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
2374 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
2375 debug_frame_section
, "FDE CIE offset");
2379 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
);
2380 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
2381 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
2384 "FDE initial location");
2385 if (fde
->dw_fde_switched_sections
)
2387 rtx sym_ref2
= gen_rtx_SYMBOL_REF (Pmode
,
2388 fde
->dw_fde_unlikely_section_label
);
2389 rtx sym_ref3
= gen_rtx_SYMBOL_REF (Pmode
,
2390 fde
->dw_fde_hot_section_label
);
2391 SYMBOL_REF_FLAGS (sym_ref2
) |= SYMBOL_FLAG_LOCAL
;
2392 SYMBOL_REF_FLAGS (sym_ref3
) |= SYMBOL_FLAG_LOCAL
;
2393 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref3
, false,
2394 "FDE initial location");
2395 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2396 fde
->dw_fde_hot_section_end_label
,
2397 fde
->dw_fde_hot_section_label
,
2398 "FDE address range");
2399 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref2
, false,
2400 "FDE initial location");
2401 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2402 fde
->dw_fde_unlikely_section_end_label
,
2403 fde
->dw_fde_unlikely_section_label
,
2404 "FDE address range");
2407 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2408 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2409 "FDE address range");
2413 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
2414 "FDE initial location");
2415 if (fde
->dw_fde_switched_sections
)
2417 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2418 fde
->dw_fde_hot_section_label
,
2419 "FDE initial location");
2420 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2421 fde
->dw_fde_hot_section_end_label
,
2422 fde
->dw_fde_hot_section_label
,
2423 "FDE address range");
2424 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2425 fde
->dw_fde_unlikely_section_label
,
2426 "FDE initial location");
2427 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2428 fde
->dw_fde_unlikely_section_end_label
,
2429 fde
->dw_fde_unlikely_section_label
,
2430 "FDE address range");
2433 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2434 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2435 "FDE address range");
2438 if (augmentation
[0])
2440 if (any_lsda_needed
)
2442 int size
= size_of_encoded_value (lsda_encoding
);
2444 if (lsda_encoding
== DW_EH_PE_aligned
)
2446 int offset
= ( 4 /* Length */
2447 + 4 /* CIE offset */
2448 + 2 * size_of_encoded_value (fde_encoding
)
2449 + 1 /* Augmentation size */ );
2450 int pad
= -offset
& (PTR_SIZE
- 1);
2453 gcc_assert (size_of_uleb128 (size
) == 1);
2456 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2458 if (fde
->uses_eh_lsda
)
2460 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2461 fde
->funcdef_number
);
2462 dw2_asm_output_encoded_addr_rtx (
2463 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2464 false, "Language Specific Data Area");
2468 if (lsda_encoding
== DW_EH_PE_aligned
)
2469 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2471 (size_of_encoded_value (lsda_encoding
), 0,
2472 "Language Specific Data Area (none)");
2476 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2479 /* Loop through the Call Frame Instructions associated with
2481 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2482 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2483 output_cfi (cfi
, fde
, for_eh
);
2485 /* Pad the FDE out to an address sized boundary. */
2486 ASM_OUTPUT_ALIGN (asm_out_file
,
2487 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2488 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2491 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
2492 dw2_asm_output_data (4, 0, "End of Table");
2493 #ifdef MIPS_DEBUGGING_INFO
2494 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2495 get a value of 0. Putting .align 0 after the label fixes it. */
2496 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2499 /* Turn off app to make assembly quicker. */
2504 /* Output a marker (i.e. a label) for the beginning of a function, before
2508 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
2509 const char *file ATTRIBUTE_UNUSED
)
2511 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2515 current_function_func_begin_label
= NULL
;
2517 #ifdef TARGET_UNWIND_INFO
2518 /* ??? current_function_func_begin_label is also used by except.c
2519 for call-site information. We must emit this label if it might
2521 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2522 && ! dwarf2out_do_frame ())
2525 if (! dwarf2out_do_frame ())
2529 switch_to_section (function_section (current_function_decl
));
2530 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2531 current_function_funcdef_no
);
2532 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2533 current_function_funcdef_no
);
2534 dup_label
= xstrdup (label
);
2535 current_function_func_begin_label
= dup_label
;
2537 #ifdef TARGET_UNWIND_INFO
2538 /* We can elide the fde allocation if we're not emitting debug info. */
2539 if (! dwarf2out_do_frame ())
2543 /* Expand the fde table if necessary. */
2544 if (fde_table_in_use
== fde_table_allocated
)
2546 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2547 fde_table
= ggc_realloc (fde_table
,
2548 fde_table_allocated
* sizeof (dw_fde_node
));
2549 memset (fde_table
+ fde_table_in_use
, 0,
2550 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2553 /* Record the FDE associated with this function. */
2554 current_funcdef_fde
= fde_table_in_use
;
2556 /* Add the new FDE at the end of the fde_table. */
2557 fde
= &fde_table
[fde_table_in_use
++];
2558 fde
->decl
= current_function_decl
;
2559 fde
->dw_fde_begin
= dup_label
;
2560 fde
->dw_fde_current_label
= NULL
;
2561 fde
->dw_fde_hot_section_label
= NULL
;
2562 fde
->dw_fde_hot_section_end_label
= NULL
;
2563 fde
->dw_fde_unlikely_section_label
= NULL
;
2564 fde
->dw_fde_unlikely_section_end_label
= NULL
;
2565 fde
->dw_fde_switched_sections
= false;
2566 fde
->dw_fde_end
= NULL
;
2567 fde
->dw_fde_cfi
= NULL
;
2568 fde
->funcdef_number
= current_function_funcdef_no
;
2569 fde
->nothrow
= TREE_NOTHROW (current_function_decl
);
2570 fde
->uses_eh_lsda
= cfun
->uses_eh_lsda
;
2571 fde
->all_throwers_are_sibcalls
= cfun
->all_throwers_are_sibcalls
;
2573 args_size
= old_args_size
= 0;
2575 /* We only want to output line number information for the genuine dwarf2
2576 prologue case, not the eh frame case. */
2577 #ifdef DWARF2_DEBUGGING_INFO
2579 dwarf2out_source_line (line
, file
);
2583 /* Output a marker (i.e. a label) for the absolute end of the generated code
2584 for a function definition. This gets called *after* the epilogue code has
2588 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
2589 const char *file ATTRIBUTE_UNUSED
)
2592 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2594 /* Output a label to mark the endpoint of the code generated for this
2596 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
2597 current_function_funcdef_no
);
2598 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2599 fde
= &fde_table
[fde_table_in_use
- 1];
2600 fde
->dw_fde_end
= xstrdup (label
);
2604 dwarf2out_frame_init (void)
2606 /* Allocate the initial hunk of the fde_table. */
2607 fde_table
= ggc_alloc_cleared (FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2608 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2609 fde_table_in_use
= 0;
2611 /* Generate the CFA instructions common to all FDE's. Do it now for the
2612 sake of lookup_cfa. */
2614 /* On entry, the Canonical Frame Address is at SP. */
2615 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2617 #ifdef DWARF2_UNWIND_INFO
2618 if (DWARF2_UNWIND_INFO
)
2619 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2624 dwarf2out_frame_finish (void)
2626 /* Output call frame information. */
2627 if (DWARF2_FRAME_INFO
)
2628 output_call_frame_info (0);
2630 #ifndef TARGET_UNWIND_INFO
2631 /* Output another copy for the unwinder. */
2632 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2633 output_call_frame_info (1);
2638 /* And now, the subset of the debugging information support code necessary
2639 for emitting location expressions. */
2641 /* We need some way to distinguish DW_OP_addr with a direct symbol
2642 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2643 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2646 typedef struct dw_val_struct
*dw_val_ref
;
2647 typedef struct die_struct
*dw_die_ref
;
2648 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2649 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2651 /* Each DIE may have a series of attribute/value pairs. Values
2652 can take on several forms. The forms that are used in this
2653 implementation are listed below. */
2658 dw_val_class_offset
,
2660 dw_val_class_loc_list
,
2661 dw_val_class_range_list
,
2663 dw_val_class_unsigned_const
,
2664 dw_val_class_long_long
,
2667 dw_val_class_die_ref
,
2668 dw_val_class_fde_ref
,
2669 dw_val_class_lbl_id
,
2670 dw_val_class_lineptr
,
2675 /* Describe a double word constant value. */
2676 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2678 typedef struct dw_long_long_struct
GTY(())
2685 /* Describe a floating point constant value, or a vector constant value. */
2687 typedef struct dw_vec_struct
GTY(())
2689 unsigned char * GTY((length ("%h.length"))) array
;
2695 /* The dw_val_node describes an attribute's value, as it is
2696 represented internally. */
2698 typedef struct dw_val_struct
GTY(())
2700 enum dw_val_class val_class
;
2701 union dw_val_struct_union
2703 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
2704 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_offset"))) val_offset
;
2705 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
2706 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
2707 HOST_WIDE_INT
GTY ((default)) val_int
;
2708 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
2709 dw_long_long_const
GTY ((tag ("dw_val_class_long_long"))) val_long_long
;
2710 dw_vec_const
GTY ((tag ("dw_val_class_vec"))) val_vec
;
2711 struct dw_val_die_union
2715 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
2716 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
2717 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
2718 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
2719 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
2721 GTY ((desc ("%1.val_class"))) v
;
2725 /* Locations in memory are described using a sequence of stack machine
2728 typedef struct dw_loc_descr_struct
GTY(())
2730 dw_loc_descr_ref dw_loc_next
;
2731 enum dwarf_location_atom dw_loc_opc
;
2732 dw_val_node dw_loc_oprnd1
;
2733 dw_val_node dw_loc_oprnd2
;
2738 /* Location lists are ranges + location descriptions for that range,
2739 so you can track variables that are in different places over
2740 their entire life. */
2741 typedef struct dw_loc_list_struct
GTY(())
2743 dw_loc_list_ref dw_loc_next
;
2744 const char *begin
; /* Label for begin address of range */
2745 const char *end
; /* Label for end address of range */
2746 char *ll_symbol
; /* Label for beginning of location list.
2747 Only on head of list */
2748 const char *section
; /* Section this loclist is relative to */
2749 dw_loc_descr_ref expr
;
2752 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2754 static const char *dwarf_stack_op_name (unsigned);
2755 static dw_loc_descr_ref
new_loc_descr (enum dwarf_location_atom
,
2756 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2757 static void add_loc_descr (dw_loc_descr_ref
*, dw_loc_descr_ref
);
2758 static unsigned long size_of_loc_descr (dw_loc_descr_ref
);
2759 static unsigned long size_of_locs (dw_loc_descr_ref
);
2760 static void output_loc_operands (dw_loc_descr_ref
);
2761 static void output_loc_sequence (dw_loc_descr_ref
);
2763 /* Convert a DWARF stack opcode into its string name. */
2766 dwarf_stack_op_name (unsigned int op
)
2771 case INTERNAL_DW_OP_tls_addr
:
2772 return "DW_OP_addr";
2774 return "DW_OP_deref";
2776 return "DW_OP_const1u";
2778 return "DW_OP_const1s";
2780 return "DW_OP_const2u";
2782 return "DW_OP_const2s";
2784 return "DW_OP_const4u";
2786 return "DW_OP_const4s";
2788 return "DW_OP_const8u";
2790 return "DW_OP_const8s";
2792 return "DW_OP_constu";
2794 return "DW_OP_consts";
2798 return "DW_OP_drop";
2800 return "DW_OP_over";
2802 return "DW_OP_pick";
2804 return "DW_OP_swap";
2808 return "DW_OP_xderef";
2816 return "DW_OP_minus";
2828 return "DW_OP_plus";
2829 case DW_OP_plus_uconst
:
2830 return "DW_OP_plus_uconst";
2836 return "DW_OP_shra";
2854 return "DW_OP_skip";
2856 return "DW_OP_lit0";
2858 return "DW_OP_lit1";
2860 return "DW_OP_lit2";
2862 return "DW_OP_lit3";
2864 return "DW_OP_lit4";
2866 return "DW_OP_lit5";
2868 return "DW_OP_lit6";
2870 return "DW_OP_lit7";
2872 return "DW_OP_lit8";
2874 return "DW_OP_lit9";
2876 return "DW_OP_lit10";
2878 return "DW_OP_lit11";
2880 return "DW_OP_lit12";
2882 return "DW_OP_lit13";
2884 return "DW_OP_lit14";
2886 return "DW_OP_lit15";
2888 return "DW_OP_lit16";
2890 return "DW_OP_lit17";
2892 return "DW_OP_lit18";
2894 return "DW_OP_lit19";
2896 return "DW_OP_lit20";
2898 return "DW_OP_lit21";
2900 return "DW_OP_lit22";
2902 return "DW_OP_lit23";
2904 return "DW_OP_lit24";
2906 return "DW_OP_lit25";
2908 return "DW_OP_lit26";
2910 return "DW_OP_lit27";
2912 return "DW_OP_lit28";
2914 return "DW_OP_lit29";
2916 return "DW_OP_lit30";
2918 return "DW_OP_lit31";
2920 return "DW_OP_reg0";
2922 return "DW_OP_reg1";
2924 return "DW_OP_reg2";
2926 return "DW_OP_reg3";
2928 return "DW_OP_reg4";
2930 return "DW_OP_reg5";
2932 return "DW_OP_reg6";
2934 return "DW_OP_reg7";
2936 return "DW_OP_reg8";
2938 return "DW_OP_reg9";
2940 return "DW_OP_reg10";
2942 return "DW_OP_reg11";
2944 return "DW_OP_reg12";
2946 return "DW_OP_reg13";
2948 return "DW_OP_reg14";
2950 return "DW_OP_reg15";
2952 return "DW_OP_reg16";
2954 return "DW_OP_reg17";
2956 return "DW_OP_reg18";
2958 return "DW_OP_reg19";
2960 return "DW_OP_reg20";
2962 return "DW_OP_reg21";
2964 return "DW_OP_reg22";
2966 return "DW_OP_reg23";
2968 return "DW_OP_reg24";
2970 return "DW_OP_reg25";
2972 return "DW_OP_reg26";
2974 return "DW_OP_reg27";
2976 return "DW_OP_reg28";
2978 return "DW_OP_reg29";
2980 return "DW_OP_reg30";
2982 return "DW_OP_reg31";
2984 return "DW_OP_breg0";
2986 return "DW_OP_breg1";
2988 return "DW_OP_breg2";
2990 return "DW_OP_breg3";
2992 return "DW_OP_breg4";
2994 return "DW_OP_breg5";
2996 return "DW_OP_breg6";
2998 return "DW_OP_breg7";
3000 return "DW_OP_breg8";
3002 return "DW_OP_breg9";
3004 return "DW_OP_breg10";
3006 return "DW_OP_breg11";
3008 return "DW_OP_breg12";
3010 return "DW_OP_breg13";
3012 return "DW_OP_breg14";
3014 return "DW_OP_breg15";
3016 return "DW_OP_breg16";
3018 return "DW_OP_breg17";
3020 return "DW_OP_breg18";
3022 return "DW_OP_breg19";
3024 return "DW_OP_breg20";
3026 return "DW_OP_breg21";
3028 return "DW_OP_breg22";
3030 return "DW_OP_breg23";
3032 return "DW_OP_breg24";
3034 return "DW_OP_breg25";
3036 return "DW_OP_breg26";
3038 return "DW_OP_breg27";
3040 return "DW_OP_breg28";
3042 return "DW_OP_breg29";
3044 return "DW_OP_breg30";
3046 return "DW_OP_breg31";
3048 return "DW_OP_regx";
3050 return "DW_OP_fbreg";
3052 return "DW_OP_bregx";
3054 return "DW_OP_piece";
3055 case DW_OP_deref_size
:
3056 return "DW_OP_deref_size";
3057 case DW_OP_xderef_size
:
3058 return "DW_OP_xderef_size";
3061 case DW_OP_push_object_address
:
3062 return "DW_OP_push_object_address";
3064 return "DW_OP_call2";
3066 return "DW_OP_call4";
3067 case DW_OP_call_ref
:
3068 return "DW_OP_call_ref";
3069 case DW_OP_GNU_push_tls_address
:
3070 return "DW_OP_GNU_push_tls_address";
3072 return "OP_<unknown>";
3076 /* Return a pointer to a newly allocated location description. Location
3077 descriptions are simple expression terms that can be strung
3078 together to form more complicated location (address) descriptions. */
3080 static inline dw_loc_descr_ref
3081 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
3082 unsigned HOST_WIDE_INT oprnd2
)
3084 dw_loc_descr_ref descr
= ggc_alloc_cleared (sizeof (dw_loc_descr_node
));
3086 descr
->dw_loc_opc
= op
;
3087 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
3088 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
3089 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
3090 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
3095 /* Add a location description term to a location description expression. */
3098 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
3100 dw_loc_descr_ref
*d
;
3102 /* Find the end of the chain. */
3103 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
3109 /* Return the size of a location descriptor. */
3111 static unsigned long
3112 size_of_loc_descr (dw_loc_descr_ref loc
)
3114 unsigned long size
= 1;
3116 switch (loc
->dw_loc_opc
)
3119 case INTERNAL_DW_OP_tls_addr
:
3120 size
+= DWARF2_ADDR_SIZE
;
3139 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3142 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3147 case DW_OP_plus_uconst
:
3148 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3186 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3189 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3192 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3195 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3196 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
3199 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3201 case DW_OP_deref_size
:
3202 case DW_OP_xderef_size
:
3211 case DW_OP_call_ref
:
3212 size
+= DWARF2_ADDR_SIZE
;
3221 /* Return the size of a series of location descriptors. */
3223 static unsigned long
3224 size_of_locs (dw_loc_descr_ref loc
)
3228 for (size
= 0; loc
!= NULL
; loc
= loc
->dw_loc_next
)
3230 loc
->dw_loc_addr
= size
;
3231 size
+= size_of_loc_descr (loc
);
3237 /* Output location description stack opcode's operands (if any). */
3240 output_loc_operands (dw_loc_descr_ref loc
)
3242 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
3243 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
3245 switch (loc
->dw_loc_opc
)
3247 #ifdef DWARF2_DEBUGGING_INFO
3249 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
3253 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
3257 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
3261 gcc_assert (HOST_BITS_PER_LONG
>= 64);
3262 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
3269 gcc_assert (val1
->val_class
== dw_val_class_loc
);
3270 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
3272 dw2_asm_output_data (2, offset
, NULL
);
3285 /* We currently don't make any attempt to make sure these are
3286 aligned properly like we do for the main unwind info, so
3287 don't support emitting things larger than a byte if we're
3288 only doing unwinding. */
3293 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3296 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3299 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3302 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3304 case DW_OP_plus_uconst
:
3305 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3339 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3342 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3345 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3348 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3349 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
3352 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3354 case DW_OP_deref_size
:
3355 case DW_OP_xderef_size
:
3356 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3359 case INTERNAL_DW_OP_tls_addr
:
3360 if (targetm
.asm_out
.output_dwarf_dtprel
)
3362 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
3365 fputc ('\n', asm_out_file
);
3372 /* Other codes have no operands. */
3377 /* Output a sequence of location operations. */
3380 output_loc_sequence (dw_loc_descr_ref loc
)
3382 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
3384 /* Output the opcode. */
3385 dw2_asm_output_data (1, loc
->dw_loc_opc
,
3386 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
3388 /* Output the operand(s) (if any). */
3389 output_loc_operands (loc
);
3393 /* This routine will generate the correct assembly data for a location
3394 description based on a cfi entry with a complex address. */
3397 output_cfa_loc (dw_cfi_ref cfi
)
3399 dw_loc_descr_ref loc
;
3402 /* Output the size of the block. */
3403 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
3404 size
= size_of_locs (loc
);
3405 dw2_asm_output_data_uleb128 (size
, NULL
);
3407 /* Now output the operations themselves. */
3408 output_loc_sequence (loc
);
3411 /* This function builds a dwarf location descriptor sequence from a
3412 dw_cfa_location, adding the given OFFSET to the result of the
3415 static struct dw_loc_descr_struct
*
3416 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
3418 struct dw_loc_descr_struct
*head
, *tmp
;
3420 offset
+= cfa
->offset
;
3424 if (cfa
->base_offset
)
3427 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
3429 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
3431 else if (cfa
->reg
<= 31)
3432 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3434 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3436 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
3437 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
3438 add_loc_descr (&head
, tmp
);
3441 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
3442 add_loc_descr (&head
, tmp
);
3449 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3451 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3452 else if (cfa
->reg
<= 31)
3453 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, offset
, 0);
3455 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, offset
);
3461 /* This function fills in aa dw_cfa_location structure from a dwarf location
3462 descriptor sequence. */
3465 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
3467 struct dw_loc_descr_struct
*ptr
;
3469 cfa
->base_offset
= 0;
3473 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
3475 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3511 cfa
->reg
= op
- DW_OP_reg0
;
3514 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3548 cfa
->reg
= op
- DW_OP_breg0
;
3549 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3552 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3553 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3558 case DW_OP_plus_uconst
:
3559 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3562 internal_error ("DW_LOC_OP %s not implemented",
3563 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3567 #endif /* .debug_frame support */
3569 /* And now, the support for symbolic debugging information. */
3570 #ifdef DWARF2_DEBUGGING_INFO
3572 /* .debug_str support. */
3573 static int output_indirect_string (void **, void *);
3575 static void dwarf2out_init (const char *);
3576 static void dwarf2out_finish (const char *);
3577 static void dwarf2out_define (unsigned int, const char *);
3578 static void dwarf2out_undef (unsigned int, const char *);
3579 static void dwarf2out_start_source_file (unsigned, const char *);
3580 static void dwarf2out_end_source_file (unsigned);
3581 static void dwarf2out_begin_block (unsigned, unsigned);
3582 static void dwarf2out_end_block (unsigned, unsigned);
3583 static bool dwarf2out_ignore_block (tree
);
3584 static void dwarf2out_global_decl (tree
);
3585 static void dwarf2out_type_decl (tree
, int);
3586 static void dwarf2out_imported_module_or_decl (tree
, tree
);
3587 static void dwarf2out_abstract_function (tree
);
3588 static void dwarf2out_var_location (rtx
);
3589 static void dwarf2out_begin_function (tree
);
3590 static void dwarf2out_switch_text_section (void);
3592 /* The debug hooks structure. */
3594 const struct gcc_debug_hooks dwarf2_debug_hooks
=
3600 dwarf2out_start_source_file
,
3601 dwarf2out_end_source_file
,
3602 dwarf2out_begin_block
,
3603 dwarf2out_end_block
,
3604 dwarf2out_ignore_block
,
3605 dwarf2out_source_line
,
3606 dwarf2out_begin_prologue
,
3607 debug_nothing_int_charstar
, /* end_prologue */
3608 dwarf2out_end_epilogue
,
3609 dwarf2out_begin_function
,
3610 debug_nothing_int
, /* end_function */
3611 dwarf2out_decl
, /* function_decl */
3612 dwarf2out_global_decl
,
3613 dwarf2out_type_decl
, /* type_decl */
3614 dwarf2out_imported_module_or_decl
,
3615 debug_nothing_tree
, /* deferred_inline_function */
3616 /* The DWARF 2 backend tries to reduce debugging bloat by not
3617 emitting the abstract description of inline functions until
3618 something tries to reference them. */
3619 dwarf2out_abstract_function
, /* outlining_inline_function */
3620 debug_nothing_rtx
, /* label */
3621 debug_nothing_int
, /* handle_pch */
3622 dwarf2out_var_location
,
3623 dwarf2out_switch_text_section
,
3624 1 /* start_end_main_source_file */
3628 /* NOTE: In the comments in this file, many references are made to
3629 "Debugging Information Entries". This term is abbreviated as `DIE'
3630 throughout the remainder of this file. */
3632 /* An internal representation of the DWARF output is built, and then
3633 walked to generate the DWARF debugging info. The walk of the internal
3634 representation is done after the entire program has been compiled.
3635 The types below are used to describe the internal representation. */
3637 /* Various DIE's use offsets relative to the beginning of the
3638 .debug_info section to refer to each other. */
3640 typedef long int dw_offset
;
3642 /* Define typedefs here to avoid circular dependencies. */
3644 typedef struct dw_attr_struct
*dw_attr_ref
;
3645 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3646 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3647 typedef struct pubname_struct
*pubname_ref
;
3648 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3650 /* Each entry in the line_info_table maintains the file and
3651 line number associated with the label generated for that
3652 entry. The label gives the PC value associated with
3653 the line number entry. */
3655 typedef struct dw_line_info_struct
GTY(())
3657 unsigned long dw_file_num
;
3658 unsigned long dw_line_num
;
3662 /* Line information for functions in separate sections; each one gets its
3664 typedef struct dw_separate_line_info_struct
GTY(())
3666 unsigned long dw_file_num
;
3667 unsigned long dw_line_num
;
3668 unsigned long function
;
3670 dw_separate_line_info_entry
;
3672 /* Each DIE attribute has a field specifying the attribute kind,
3673 a link to the next attribute in the chain, and an attribute value.
3674 Attributes are typically linked below the DIE they modify. */
3676 typedef struct dw_attr_struct
GTY(())
3678 enum dwarf_attribute dw_attr
;
3679 dw_val_node dw_attr_val
;
3683 DEF_VEC_O(dw_attr_node
);
3684 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
3686 /* The Debugging Information Entry (DIE) structure */
3688 typedef struct die_struct
GTY(())
3690 enum dwarf_tag die_tag
;
3692 VEC(dw_attr_node
,gc
) * die_attr
;
3693 dw_die_ref die_parent
;
3694 dw_die_ref die_child
;
3696 dw_die_ref die_definition
; /* ref from a specification to its definition */
3697 dw_offset die_offset
;
3698 unsigned long die_abbrev
;
3700 /* Die is used and must not be pruned as unused. */
3701 int die_perennial_p
;
3702 unsigned int decl_id
;
3706 /* The pubname structure */
3708 typedef struct pubname_struct
GTY(())
3715 struct dw_ranges_struct
GTY(())
3720 /* The limbo die list structure. */
3721 typedef struct limbo_die_struct
GTY(())
3725 struct limbo_die_struct
*next
;
3729 /* How to start an assembler comment. */
3730 #ifndef ASM_COMMENT_START
3731 #define ASM_COMMENT_START ";#"
3734 /* Define a macro which returns nonzero for a TYPE_DECL which was
3735 implicitly generated for a tagged type.
3737 Note that unlike the gcc front end (which generates a NULL named
3738 TYPE_DECL node for each complete tagged type, each array type, and
3739 each function type node created) the g++ front end generates a
3740 _named_ TYPE_DECL node for each tagged type node created.
3741 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3742 generate a DW_TAG_typedef DIE for them. */
3744 #define TYPE_DECL_IS_STUB(decl) \
3745 (DECL_NAME (decl) == NULL_TREE \
3746 || (DECL_ARTIFICIAL (decl) \
3747 && is_tagged_type (TREE_TYPE (decl)) \
3748 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3749 /* This is necessary for stub decls that \
3750 appear in nested inline functions. */ \
3751 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3752 && (decl_ultimate_origin (decl) \
3753 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3755 /* Information concerning the compilation unit's programming
3756 language, and compiler version. */
3758 /* Fixed size portion of the DWARF compilation unit header. */
3759 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3760 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3762 /* Fixed size portion of public names info. */
3763 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3765 /* Fixed size portion of the address range info. */
3766 #define DWARF_ARANGES_HEADER_SIZE \
3767 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3768 DWARF2_ADDR_SIZE * 2) \
3769 - DWARF_INITIAL_LENGTH_SIZE)
3771 /* Size of padding portion in the address range info. It must be
3772 aligned to twice the pointer size. */
3773 #define DWARF_ARANGES_PAD_SIZE \
3774 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3775 DWARF2_ADDR_SIZE * 2) \
3776 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3778 /* Use assembler line directives if available. */
3779 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3780 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3781 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3783 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3787 /* Minimum line offset in a special line info. opcode.
3788 This value was chosen to give a reasonable range of values. */
3789 #define DWARF_LINE_BASE -10
3791 /* First special line opcode - leave room for the standard opcodes. */
3792 #define DWARF_LINE_OPCODE_BASE 10
3794 /* Range of line offsets in a special line info. opcode. */
3795 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3797 /* Flag that indicates the initial value of the is_stmt_start flag.
3798 In the present implementation, we do not mark any lines as
3799 the beginning of a source statement, because that information
3800 is not made available by the GCC front-end. */
3801 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3803 #ifdef DWARF2_DEBUGGING_INFO
3804 /* This location is used by calc_die_sizes() to keep track
3805 the offset of each DIE within the .debug_info section. */
3806 static unsigned long next_die_offset
;
3809 /* Record the root of the DIE's built for the current compilation unit. */
3810 static GTY(()) dw_die_ref comp_unit_die
;
3812 /* A list of DIEs with a NULL parent waiting to be relocated. */
3813 static GTY(()) limbo_die_node
*limbo_die_list
;
3815 /* Filenames referenced by this compilation unit. */
3816 static GTY(()) varray_type file_table
;
3817 static GTY(()) varray_type file_table_emitted
;
3818 static GTY(()) size_t file_table_last_lookup_index
;
3820 /* A hash table of references to DIE's that describe declarations.
3821 The key is a DECL_UID() which is a unique number identifying each decl. */
3822 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
3824 /* Node of the variable location list. */
3825 struct var_loc_node
GTY ((chain_next ("%h.next")))
3827 rtx
GTY (()) var_loc_note
;
3828 const char * GTY (()) label
;
3829 const char * GTY (()) section_label
;
3830 struct var_loc_node
* GTY (()) next
;
3833 /* Variable location list. */
3834 struct var_loc_list_def
GTY (())
3836 struct var_loc_node
* GTY (()) first
;
3838 /* Do not mark the last element of the chained list because
3839 it is marked through the chain. */
3840 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3842 /* DECL_UID of the variable decl. */
3843 unsigned int decl_id
;
3845 typedef struct var_loc_list_def var_loc_list
;
3848 /* Table of decl location linked lists. */
3849 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
3851 /* A pointer to the base of a list of references to DIE's that
3852 are uniquely identified by their tag, presence/absence of
3853 children DIE's, and list of attribute/value pairs. */
3854 static GTY((length ("abbrev_die_table_allocated")))
3855 dw_die_ref
*abbrev_die_table
;
3857 /* Number of elements currently allocated for abbrev_die_table. */
3858 static GTY(()) unsigned abbrev_die_table_allocated
;
3860 /* Number of elements in type_die_table currently in use. */
3861 static GTY(()) unsigned abbrev_die_table_in_use
;
3863 /* Size (in elements) of increments by which we may expand the
3864 abbrev_die_table. */
3865 #define ABBREV_DIE_TABLE_INCREMENT 256
3867 /* A pointer to the base of a table that contains line information
3868 for each source code line in .text in the compilation unit. */
3869 static GTY((length ("line_info_table_allocated")))
3870 dw_line_info_ref line_info_table
;
3872 /* Number of elements currently allocated for line_info_table. */
3873 static GTY(()) unsigned line_info_table_allocated
;
3875 /* Number of elements in line_info_table currently in use. */
3876 static GTY(()) unsigned line_info_table_in_use
;
3878 /* True if the compilation unit places functions in more than one section. */
3879 static GTY(()) bool have_multiple_function_sections
= false;
3881 /* A pointer to the base of a table that contains line information
3882 for each source code line outside of .text in the compilation unit. */
3883 static GTY ((length ("separate_line_info_table_allocated")))
3884 dw_separate_line_info_ref separate_line_info_table
;
3886 /* Number of elements currently allocated for separate_line_info_table. */
3887 static GTY(()) unsigned separate_line_info_table_allocated
;
3889 /* Number of elements in separate_line_info_table currently in use. */
3890 static GTY(()) unsigned separate_line_info_table_in_use
;
3892 /* Size (in elements) of increments by which we may expand the
3894 #define LINE_INFO_TABLE_INCREMENT 1024
3896 /* A pointer to the base of a table that contains a list of publicly
3897 accessible names. */
3898 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table
;
3900 /* Number of elements currently allocated for pubname_table. */
3901 static GTY(()) unsigned pubname_table_allocated
;
3903 /* Number of elements in pubname_table currently in use. */
3904 static GTY(()) unsigned pubname_table_in_use
;
3906 /* Size (in elements) of increments by which we may expand the
3908 #define PUBNAME_TABLE_INCREMENT 64
3910 /* Array of dies for which we should generate .debug_arange info. */
3911 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
3913 /* Number of elements currently allocated for arange_table. */
3914 static GTY(()) unsigned arange_table_allocated
;
3916 /* Number of elements in arange_table currently in use. */
3917 static GTY(()) unsigned arange_table_in_use
;
3919 /* Size (in elements) of increments by which we may expand the
3921 #define ARANGE_TABLE_INCREMENT 64
3923 /* Array of dies for which we should generate .debug_ranges info. */
3924 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
3926 /* Number of elements currently allocated for ranges_table. */
3927 static GTY(()) unsigned ranges_table_allocated
;
3929 /* Number of elements in ranges_table currently in use. */
3930 static GTY(()) unsigned ranges_table_in_use
;
3932 /* Size (in elements) of increments by which we may expand the
3934 #define RANGES_TABLE_INCREMENT 64
3936 /* Whether we have location lists that need outputting */
3937 static GTY(()) bool have_location_lists
;
3939 /* Unique label counter. */
3940 static GTY(()) unsigned int loclabel_num
;
3942 #ifdef DWARF2_DEBUGGING_INFO
3943 /* Record whether the function being analyzed contains inlined functions. */
3944 static int current_function_has_inlines
;
3946 #if 0 && defined (MIPS_DEBUGGING_INFO)
3947 static int comp_unit_has_inlines
;
3950 /* Number of file tables emitted in maybe_emit_file(). */
3951 static GTY(()) int emitcount
= 0;
3953 /* Number of internal labels generated by gen_internal_sym(). */
3954 static GTY(()) int label_num
;
3956 #ifdef DWARF2_DEBUGGING_INFO
3958 /* Offset from the "steady-state frame pointer" to the frame base,
3959 within the current function. */
3960 static HOST_WIDE_INT frame_pointer_fb_offset
;
3962 /* Forward declarations for functions defined in this file. */
3964 static int is_pseudo_reg (rtx
);
3965 static tree
type_main_variant (tree
);
3966 static int is_tagged_type (tree
);
3967 static const char *dwarf_tag_name (unsigned);
3968 static const char *dwarf_attr_name (unsigned);
3969 static const char *dwarf_form_name (unsigned);
3970 static tree
decl_ultimate_origin (tree
);
3971 static tree
block_ultimate_origin (tree
);
3972 static tree
decl_class_context (tree
);
3973 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
3974 static inline enum dw_val_class
AT_class (dw_attr_ref
);
3975 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3976 static inline unsigned AT_flag (dw_attr_ref
);
3977 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3978 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
3979 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3980 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
3981 static void add_AT_long_long (dw_die_ref
, enum dwarf_attribute
, unsigned long,
3983 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3984 unsigned int, unsigned char *);
3985 static hashval_t
debug_str_do_hash (const void *);
3986 static int debug_str_eq (const void *, const void *);
3987 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3988 static inline const char *AT_string (dw_attr_ref
);
3989 static int AT_string_form (dw_attr_ref
);
3990 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3991 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3992 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3993 static inline int AT_ref_external (dw_attr_ref
);
3994 static inline void set_AT_ref_external (dw_attr_ref
, int);
3995 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3996 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3997 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3998 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
4000 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
4001 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
4002 static inline rtx
AT_addr (dw_attr_ref
);
4003 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
4004 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
4005 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
4006 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
4007 unsigned HOST_WIDE_INT
);
4008 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
4010 static inline const char *AT_lbl (dw_attr_ref
);
4011 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
4012 static const char *get_AT_low_pc (dw_die_ref
);
4013 static const char *get_AT_hi_pc (dw_die_ref
);
4014 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
4015 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
4016 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
4017 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
4018 static bool is_c_family (void);
4019 static bool is_cxx (void);
4020 static bool is_java (void);
4021 static bool is_fortran (void);
4022 static bool is_ada (void);
4023 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
4024 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
4025 static inline void free_die (dw_die_ref
);
4026 static void add_child_die (dw_die_ref
, dw_die_ref
);
4027 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
4028 static dw_die_ref
lookup_type_die (tree
);
4029 static void equate_type_number_to_die (tree
, dw_die_ref
);
4030 static hashval_t
decl_die_table_hash (const void *);
4031 static int decl_die_table_eq (const void *, const void *);
4032 static dw_die_ref
lookup_decl_die (tree
);
4033 static hashval_t
decl_loc_table_hash (const void *);
4034 static int decl_loc_table_eq (const void *, const void *);
4035 static var_loc_list
*lookup_decl_loc (tree
);
4036 static void equate_decl_number_to_die (tree
, dw_die_ref
);
4037 static void add_var_loc_to_decl (tree
, struct var_loc_node
*);
4038 static void print_spaces (FILE *);
4039 static void print_die (dw_die_ref
, FILE *);
4040 static void print_dwarf_line_table (FILE *);
4041 static void reverse_die_lists (dw_die_ref
);
4042 static void reverse_all_dies (dw_die_ref
);
4043 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
4044 static dw_die_ref
pop_compile_unit (dw_die_ref
);
4045 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
4046 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
4047 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
4048 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
4049 static int same_dw_val_p (dw_val_node
*, dw_val_node
*, int *);
4050 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
4051 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
4052 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
4053 static void compute_section_prefix (dw_die_ref
);
4054 static int is_type_die (dw_die_ref
);
4055 static int is_comdat_die (dw_die_ref
);
4056 static int is_symbol_die (dw_die_ref
);
4057 static void assign_symbol_names (dw_die_ref
);
4058 static void break_out_includes (dw_die_ref
);
4059 static hashval_t
htab_cu_hash (const void *);
4060 static int htab_cu_eq (const void *, const void *);
4061 static void htab_cu_del (void *);
4062 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
4063 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
4064 static void add_sibling_attributes (dw_die_ref
);
4065 static void build_abbrev_table (dw_die_ref
);
4066 static void output_location_lists (dw_die_ref
);
4067 static int constant_size (long unsigned);
4068 static unsigned long size_of_die (dw_die_ref
);
4069 static void calc_die_sizes (dw_die_ref
);
4070 static void mark_dies (dw_die_ref
);
4071 static void unmark_dies (dw_die_ref
);
4072 static void unmark_all_dies (dw_die_ref
);
4073 static unsigned long size_of_pubnames (void);
4074 static unsigned long size_of_aranges (void);
4075 static enum dwarf_form
value_format (dw_attr_ref
);
4076 static void output_value_format (dw_attr_ref
);
4077 static void output_abbrev_section (void);
4078 static void output_die_symbol (dw_die_ref
);
4079 static void output_die (dw_die_ref
);
4080 static void output_compilation_unit_header (void);
4081 static void output_comp_unit (dw_die_ref
, int);
4082 static const char *dwarf2_name (tree
, int);
4083 static void add_pubname (tree
, dw_die_ref
);
4084 static void output_pubnames (void);
4085 static void add_arange (tree
, dw_die_ref
);
4086 static void output_aranges (void);
4087 static unsigned int add_ranges (tree
);
4088 static void output_ranges (void);
4089 static void output_line_info (void);
4090 static void output_file_names (void);
4091 static dw_die_ref
base_type_die (tree
);
4092 static tree
root_type (tree
);
4093 static int is_base_type (tree
);
4094 static bool is_subrange_type (tree
);
4095 static dw_die_ref
subrange_type_die (tree
, dw_die_ref
);
4096 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
4097 static int type_is_enum (tree
);
4098 static unsigned int dbx_reg_number (rtx
);
4099 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
4100 static dw_loc_descr_ref
reg_loc_descriptor (rtx
);
4101 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int);
4102 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
);
4103 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
4104 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
);
4105 static int is_based_loc (rtx
);
4106 static dw_loc_descr_ref
mem_loc_descriptor (rtx
, enum machine_mode mode
);
4107 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
);
4108 static dw_loc_descr_ref
loc_descriptor (rtx
);
4109 static dw_loc_descr_ref
loc_descriptor_from_tree_1 (tree
, int);
4110 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
);
4111 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
4112 static tree
field_type (tree
);
4113 static unsigned int simple_type_align_in_bits (tree
);
4114 static unsigned int simple_decl_align_in_bits (tree
);
4115 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (tree
);
4116 static HOST_WIDE_INT
field_byte_offset (tree
);
4117 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
4119 static void add_data_member_location_attribute (dw_die_ref
, tree
);
4120 static void add_const_value_attribute (dw_die_ref
, rtx
);
4121 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
4122 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
4123 static void insert_float (rtx
, unsigned char *);
4124 static rtx
rtl_for_decl_location (tree
);
4125 static void add_location_or_const_value_attribute (dw_die_ref
, tree
,
4126 enum dwarf_attribute
);
4127 static void tree_add_const_value_attribute (dw_die_ref
, tree
);
4128 static void add_name_attribute (dw_die_ref
, const char *);
4129 static void add_comp_dir_attribute (dw_die_ref
);
4130 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
4131 static void add_subscript_info (dw_die_ref
, tree
);
4132 static void add_byte_size_attribute (dw_die_ref
, tree
);
4133 static void add_bit_offset_attribute (dw_die_ref
, tree
);
4134 static void add_bit_size_attribute (dw_die_ref
, tree
);
4135 static void add_prototyped_attribute (dw_die_ref
, tree
);
4136 static void add_abstract_origin_attribute (dw_die_ref
, tree
);
4137 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
4138 static void add_src_coords_attributes (dw_die_ref
, tree
);
4139 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
4140 static void push_decl_scope (tree
);
4141 static void pop_decl_scope (void);
4142 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
4143 static inline int local_scope_p (dw_die_ref
);
4144 static inline int class_or_namespace_scope_p (dw_die_ref
);
4145 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
4146 static void add_calling_convention_attribute (dw_die_ref
, tree
);
4147 static const char *type_tag (tree
);
4148 static tree
member_declared_type (tree
);
4150 static const char *decl_start_label (tree
);
4152 static void gen_array_type_die (tree
, dw_die_ref
);
4154 static void gen_entry_point_die (tree
, dw_die_ref
);
4156 static void gen_inlined_enumeration_type_die (tree
, dw_die_ref
);
4157 static void gen_inlined_structure_type_die (tree
, dw_die_ref
);
4158 static void gen_inlined_union_type_die (tree
, dw_die_ref
);
4159 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
4160 static dw_die_ref
gen_formal_parameter_die (tree
, dw_die_ref
);
4161 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
4162 static void gen_formal_types_die (tree
, dw_die_ref
);
4163 static void gen_subprogram_die (tree
, dw_die_ref
);
4164 static void gen_variable_die (tree
, dw_die_ref
);
4165 static void gen_label_die (tree
, dw_die_ref
);
4166 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
4167 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
4168 static void gen_field_die (tree
, dw_die_ref
);
4169 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
4170 static dw_die_ref
gen_compile_unit_die (const char *);
4171 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
4172 static void gen_member_die (tree
, dw_die_ref
);
4173 static void gen_struct_or_union_type_die (tree
, dw_die_ref
);
4174 static void gen_subroutine_type_die (tree
, dw_die_ref
);
4175 static void gen_typedef_die (tree
, dw_die_ref
);
4176 static void gen_type_die (tree
, dw_die_ref
);
4177 static void gen_tagged_type_instantiation_die (tree
, dw_die_ref
);
4178 static void gen_block_die (tree
, dw_die_ref
, int);
4179 static void decls_for_scope (tree
, dw_die_ref
, int);
4180 static int is_redundant_typedef (tree
);
4181 static void gen_namespace_die (tree
);
4182 static void gen_decl_die (tree
, dw_die_ref
);
4183 static dw_die_ref
force_decl_die (tree
);
4184 static dw_die_ref
force_type_die (tree
);
4185 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
4186 static void declare_in_namespace (tree
, dw_die_ref
);
4187 static unsigned lookup_filename (const char *);
4188 static void init_file_table (void);
4189 static void retry_incomplete_types (void);
4190 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
4191 static void splice_child_die (dw_die_ref
, dw_die_ref
);
4192 static int file_info_cmp (const void *, const void *);
4193 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
4194 const char *, const char *, unsigned);
4195 static void add_loc_descr_to_loc_list (dw_loc_list_ref
*, dw_loc_descr_ref
,
4196 const char *, const char *,
4198 static void output_loc_list (dw_loc_list_ref
);
4199 static char *gen_internal_sym (const char *);
4201 static void prune_unmark_dies (dw_die_ref
);
4202 static void prune_unused_types_mark (dw_die_ref
, int);
4203 static void prune_unused_types_walk (dw_die_ref
);
4204 static void prune_unused_types_walk_attribs (dw_die_ref
);
4205 static void prune_unused_types_prune (dw_die_ref
);
4206 static void prune_unused_types (void);
4207 static int maybe_emit_file (int);
4209 /* Section names used to hold DWARF debugging information. */
4210 #ifndef DEBUG_INFO_SECTION
4211 #define DEBUG_INFO_SECTION ".debug_info"
4213 #ifndef DEBUG_ABBREV_SECTION
4214 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4216 #ifndef DEBUG_ARANGES_SECTION
4217 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4219 #ifndef DEBUG_MACINFO_SECTION
4220 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4222 #ifndef DEBUG_LINE_SECTION
4223 #define DEBUG_LINE_SECTION ".debug_line"
4225 #ifndef DEBUG_LOC_SECTION
4226 #define DEBUG_LOC_SECTION ".debug_loc"
4228 #ifndef DEBUG_PUBNAMES_SECTION
4229 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4231 #ifndef DEBUG_STR_SECTION
4232 #define DEBUG_STR_SECTION ".debug_str"
4234 #ifndef DEBUG_RANGES_SECTION
4235 #define DEBUG_RANGES_SECTION ".debug_ranges"
4238 /* Standard ELF section names for compiled code and data. */
4239 #ifndef TEXT_SECTION_NAME
4240 #define TEXT_SECTION_NAME ".text"
4243 /* Section flags for .debug_str section. */
4244 #define DEBUG_STR_SECTION_FLAGS \
4245 (HAVE_GAS_SHF_MERGE && flag_merge_constants \
4246 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4249 /* Labels we insert at beginning sections we can reference instead of
4250 the section names themselves. */
4252 #ifndef TEXT_SECTION_LABEL
4253 #define TEXT_SECTION_LABEL "Ltext"
4255 #ifndef COLD_TEXT_SECTION_LABEL
4256 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4258 #ifndef DEBUG_LINE_SECTION_LABEL
4259 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4261 #ifndef DEBUG_INFO_SECTION_LABEL
4262 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4264 #ifndef DEBUG_ABBREV_SECTION_LABEL
4265 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4267 #ifndef DEBUG_LOC_SECTION_LABEL
4268 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4270 #ifndef DEBUG_RANGES_SECTION_LABEL
4271 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4273 #ifndef DEBUG_MACINFO_SECTION_LABEL
4274 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4277 /* Definitions of defaults for formats and names of various special
4278 (artificial) labels which may be generated within this file (when the -g
4279 options is used and DWARF2_DEBUGGING_INFO is in effect.
4280 If necessary, these may be overridden from within the tm.h file, but
4281 typically, overriding these defaults is unnecessary. */
4283 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4284 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4285 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4286 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4287 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4288 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4289 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4290 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4291 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4292 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
4294 #ifndef TEXT_END_LABEL
4295 #define TEXT_END_LABEL "Letext"
4297 #ifndef COLD_END_LABEL
4298 #define COLD_END_LABEL "Letext_cold"
4300 #ifndef BLOCK_BEGIN_LABEL
4301 #define BLOCK_BEGIN_LABEL "LBB"
4303 #ifndef BLOCK_END_LABEL
4304 #define BLOCK_END_LABEL "LBE"
4306 #ifndef LINE_CODE_LABEL
4307 #define LINE_CODE_LABEL "LM"
4309 #ifndef SEPARATE_LINE_CODE_LABEL
4310 #define SEPARATE_LINE_CODE_LABEL "LSM"
4313 /* We allow a language front-end to designate a function that is to be
4314 called to "demangle" any name before it is put into a DIE. */
4316 static const char *(*demangle_name_func
) (const char *);
4319 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
4321 demangle_name_func
= func
;
4324 /* Test if rtl node points to a pseudo register. */
4327 is_pseudo_reg (rtx rtl
)
4329 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
4330 || (GET_CODE (rtl
) == SUBREG
4331 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
4334 /* Return a reference to a type, with its const and volatile qualifiers
4338 type_main_variant (tree type
)
4340 type
= TYPE_MAIN_VARIANT (type
);
4342 /* ??? There really should be only one main variant among any group of
4343 variants of a given type (and all of the MAIN_VARIANT values for all
4344 members of the group should point to that one type) but sometimes the C
4345 front-end messes this up for array types, so we work around that bug
4347 if (TREE_CODE (type
) == ARRAY_TYPE
)
4348 while (type
!= TYPE_MAIN_VARIANT (type
))
4349 type
= TYPE_MAIN_VARIANT (type
);
4354 /* Return nonzero if the given type node represents a tagged type. */
4357 is_tagged_type (tree type
)
4359 enum tree_code code
= TREE_CODE (type
);
4361 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
4362 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
4365 /* Convert a DIE tag into its string name. */
4368 dwarf_tag_name (unsigned int tag
)
4372 case DW_TAG_padding
:
4373 return "DW_TAG_padding";
4374 case DW_TAG_array_type
:
4375 return "DW_TAG_array_type";
4376 case DW_TAG_class_type
:
4377 return "DW_TAG_class_type";
4378 case DW_TAG_entry_point
:
4379 return "DW_TAG_entry_point";
4380 case DW_TAG_enumeration_type
:
4381 return "DW_TAG_enumeration_type";
4382 case DW_TAG_formal_parameter
:
4383 return "DW_TAG_formal_parameter";
4384 case DW_TAG_imported_declaration
:
4385 return "DW_TAG_imported_declaration";
4387 return "DW_TAG_label";
4388 case DW_TAG_lexical_block
:
4389 return "DW_TAG_lexical_block";
4391 return "DW_TAG_member";
4392 case DW_TAG_pointer_type
:
4393 return "DW_TAG_pointer_type";
4394 case DW_TAG_reference_type
:
4395 return "DW_TAG_reference_type";
4396 case DW_TAG_compile_unit
:
4397 return "DW_TAG_compile_unit";
4398 case DW_TAG_string_type
:
4399 return "DW_TAG_string_type";
4400 case DW_TAG_structure_type
:
4401 return "DW_TAG_structure_type";
4402 case DW_TAG_subroutine_type
:
4403 return "DW_TAG_subroutine_type";
4404 case DW_TAG_typedef
:
4405 return "DW_TAG_typedef";
4406 case DW_TAG_union_type
:
4407 return "DW_TAG_union_type";
4408 case DW_TAG_unspecified_parameters
:
4409 return "DW_TAG_unspecified_parameters";
4410 case DW_TAG_variant
:
4411 return "DW_TAG_variant";
4412 case DW_TAG_common_block
:
4413 return "DW_TAG_common_block";
4414 case DW_TAG_common_inclusion
:
4415 return "DW_TAG_common_inclusion";
4416 case DW_TAG_inheritance
:
4417 return "DW_TAG_inheritance";
4418 case DW_TAG_inlined_subroutine
:
4419 return "DW_TAG_inlined_subroutine";
4421 return "DW_TAG_module";
4422 case DW_TAG_ptr_to_member_type
:
4423 return "DW_TAG_ptr_to_member_type";
4424 case DW_TAG_set_type
:
4425 return "DW_TAG_set_type";
4426 case DW_TAG_subrange_type
:
4427 return "DW_TAG_subrange_type";
4428 case DW_TAG_with_stmt
:
4429 return "DW_TAG_with_stmt";
4430 case DW_TAG_access_declaration
:
4431 return "DW_TAG_access_declaration";
4432 case DW_TAG_base_type
:
4433 return "DW_TAG_base_type";
4434 case DW_TAG_catch_block
:
4435 return "DW_TAG_catch_block";
4436 case DW_TAG_const_type
:
4437 return "DW_TAG_const_type";
4438 case DW_TAG_constant
:
4439 return "DW_TAG_constant";
4440 case DW_TAG_enumerator
:
4441 return "DW_TAG_enumerator";
4442 case DW_TAG_file_type
:
4443 return "DW_TAG_file_type";
4445 return "DW_TAG_friend";
4446 case DW_TAG_namelist
:
4447 return "DW_TAG_namelist";
4448 case DW_TAG_namelist_item
:
4449 return "DW_TAG_namelist_item";
4450 case DW_TAG_namespace
:
4451 return "DW_TAG_namespace";
4452 case DW_TAG_packed_type
:
4453 return "DW_TAG_packed_type";
4454 case DW_TAG_subprogram
:
4455 return "DW_TAG_subprogram";
4456 case DW_TAG_template_type_param
:
4457 return "DW_TAG_template_type_param";
4458 case DW_TAG_template_value_param
:
4459 return "DW_TAG_template_value_param";
4460 case DW_TAG_thrown_type
:
4461 return "DW_TAG_thrown_type";
4462 case DW_TAG_try_block
:
4463 return "DW_TAG_try_block";
4464 case DW_TAG_variant_part
:
4465 return "DW_TAG_variant_part";
4466 case DW_TAG_variable
:
4467 return "DW_TAG_variable";
4468 case DW_TAG_volatile_type
:
4469 return "DW_TAG_volatile_type";
4470 case DW_TAG_imported_module
:
4471 return "DW_TAG_imported_module";
4472 case DW_TAG_MIPS_loop
:
4473 return "DW_TAG_MIPS_loop";
4474 case DW_TAG_format_label
:
4475 return "DW_TAG_format_label";
4476 case DW_TAG_function_template
:
4477 return "DW_TAG_function_template";
4478 case DW_TAG_class_template
:
4479 return "DW_TAG_class_template";
4480 case DW_TAG_GNU_BINCL
:
4481 return "DW_TAG_GNU_BINCL";
4482 case DW_TAG_GNU_EINCL
:
4483 return "DW_TAG_GNU_EINCL";
4485 return "DW_TAG_<unknown>";
4489 /* Convert a DWARF attribute code into its string name. */
4492 dwarf_attr_name (unsigned int attr
)
4497 return "DW_AT_sibling";
4498 case DW_AT_location
:
4499 return "DW_AT_location";
4501 return "DW_AT_name";
4502 case DW_AT_ordering
:
4503 return "DW_AT_ordering";
4504 case DW_AT_subscr_data
:
4505 return "DW_AT_subscr_data";
4506 case DW_AT_byte_size
:
4507 return "DW_AT_byte_size";
4508 case DW_AT_bit_offset
:
4509 return "DW_AT_bit_offset";
4510 case DW_AT_bit_size
:
4511 return "DW_AT_bit_size";
4512 case DW_AT_element_list
:
4513 return "DW_AT_element_list";
4514 case DW_AT_stmt_list
:
4515 return "DW_AT_stmt_list";
4517 return "DW_AT_low_pc";
4519 return "DW_AT_high_pc";
4520 case DW_AT_language
:
4521 return "DW_AT_language";
4523 return "DW_AT_member";
4525 return "DW_AT_discr";
4526 case DW_AT_discr_value
:
4527 return "DW_AT_discr_value";
4528 case DW_AT_visibility
:
4529 return "DW_AT_visibility";
4531 return "DW_AT_import";
4532 case DW_AT_string_length
:
4533 return "DW_AT_string_length";
4534 case DW_AT_common_reference
:
4535 return "DW_AT_common_reference";
4536 case DW_AT_comp_dir
:
4537 return "DW_AT_comp_dir";
4538 case DW_AT_const_value
:
4539 return "DW_AT_const_value";
4540 case DW_AT_containing_type
:
4541 return "DW_AT_containing_type";
4542 case DW_AT_default_value
:
4543 return "DW_AT_default_value";
4545 return "DW_AT_inline";
4546 case DW_AT_is_optional
:
4547 return "DW_AT_is_optional";
4548 case DW_AT_lower_bound
:
4549 return "DW_AT_lower_bound";
4550 case DW_AT_producer
:
4551 return "DW_AT_producer";
4552 case DW_AT_prototyped
:
4553 return "DW_AT_prototyped";
4554 case DW_AT_return_addr
:
4555 return "DW_AT_return_addr";
4556 case DW_AT_start_scope
:
4557 return "DW_AT_start_scope";
4558 case DW_AT_stride_size
:
4559 return "DW_AT_stride_size";
4560 case DW_AT_upper_bound
:
4561 return "DW_AT_upper_bound";
4562 case DW_AT_abstract_origin
:
4563 return "DW_AT_abstract_origin";
4564 case DW_AT_accessibility
:
4565 return "DW_AT_accessibility";
4566 case DW_AT_address_class
:
4567 return "DW_AT_address_class";
4568 case DW_AT_artificial
:
4569 return "DW_AT_artificial";
4570 case DW_AT_base_types
:
4571 return "DW_AT_base_types";
4572 case DW_AT_calling_convention
:
4573 return "DW_AT_calling_convention";
4575 return "DW_AT_count";
4576 case DW_AT_data_member_location
:
4577 return "DW_AT_data_member_location";
4578 case DW_AT_decl_column
:
4579 return "DW_AT_decl_column";
4580 case DW_AT_decl_file
:
4581 return "DW_AT_decl_file";
4582 case DW_AT_decl_line
:
4583 return "DW_AT_decl_line";
4584 case DW_AT_declaration
:
4585 return "DW_AT_declaration";
4586 case DW_AT_discr_list
:
4587 return "DW_AT_discr_list";
4588 case DW_AT_encoding
:
4589 return "DW_AT_encoding";
4590 case DW_AT_external
:
4591 return "DW_AT_external";
4592 case DW_AT_frame_base
:
4593 return "DW_AT_frame_base";
4595 return "DW_AT_friend";
4596 case DW_AT_identifier_case
:
4597 return "DW_AT_identifier_case";
4598 case DW_AT_macro_info
:
4599 return "DW_AT_macro_info";
4600 case DW_AT_namelist_items
:
4601 return "DW_AT_namelist_items";
4602 case DW_AT_priority
:
4603 return "DW_AT_priority";
4605 return "DW_AT_segment";
4606 case DW_AT_specification
:
4607 return "DW_AT_specification";
4608 case DW_AT_static_link
:
4609 return "DW_AT_static_link";
4611 return "DW_AT_type";
4612 case DW_AT_use_location
:
4613 return "DW_AT_use_location";
4614 case DW_AT_variable_parameter
:
4615 return "DW_AT_variable_parameter";
4616 case DW_AT_virtuality
:
4617 return "DW_AT_virtuality";
4618 case DW_AT_vtable_elem_location
:
4619 return "DW_AT_vtable_elem_location";
4621 case DW_AT_allocated
:
4622 return "DW_AT_allocated";
4623 case DW_AT_associated
:
4624 return "DW_AT_associated";
4625 case DW_AT_data_location
:
4626 return "DW_AT_data_location";
4628 return "DW_AT_stride";
4629 case DW_AT_entry_pc
:
4630 return "DW_AT_entry_pc";
4631 case DW_AT_use_UTF8
:
4632 return "DW_AT_use_UTF8";
4633 case DW_AT_extension
:
4634 return "DW_AT_extension";
4636 return "DW_AT_ranges";
4637 case DW_AT_trampoline
:
4638 return "DW_AT_trampoline";
4639 case DW_AT_call_column
:
4640 return "DW_AT_call_column";
4641 case DW_AT_call_file
:
4642 return "DW_AT_call_file";
4643 case DW_AT_call_line
:
4644 return "DW_AT_call_line";
4646 case DW_AT_MIPS_fde
:
4647 return "DW_AT_MIPS_fde";
4648 case DW_AT_MIPS_loop_begin
:
4649 return "DW_AT_MIPS_loop_begin";
4650 case DW_AT_MIPS_tail_loop_begin
:
4651 return "DW_AT_MIPS_tail_loop_begin";
4652 case DW_AT_MIPS_epilog_begin
:
4653 return "DW_AT_MIPS_epilog_begin";
4654 case DW_AT_MIPS_loop_unroll_factor
:
4655 return "DW_AT_MIPS_loop_unroll_factor";
4656 case DW_AT_MIPS_software_pipeline_depth
:
4657 return "DW_AT_MIPS_software_pipeline_depth";
4658 case DW_AT_MIPS_linkage_name
:
4659 return "DW_AT_MIPS_linkage_name";
4660 case DW_AT_MIPS_stride
:
4661 return "DW_AT_MIPS_stride";
4662 case DW_AT_MIPS_abstract_name
:
4663 return "DW_AT_MIPS_abstract_name";
4664 case DW_AT_MIPS_clone_origin
:
4665 return "DW_AT_MIPS_clone_origin";
4666 case DW_AT_MIPS_has_inlines
:
4667 return "DW_AT_MIPS_has_inlines";
4669 case DW_AT_sf_names
:
4670 return "DW_AT_sf_names";
4671 case DW_AT_src_info
:
4672 return "DW_AT_src_info";
4673 case DW_AT_mac_info
:
4674 return "DW_AT_mac_info";
4675 case DW_AT_src_coords
:
4676 return "DW_AT_src_coords";
4677 case DW_AT_body_begin
:
4678 return "DW_AT_body_begin";
4679 case DW_AT_body_end
:
4680 return "DW_AT_body_end";
4681 case DW_AT_GNU_vector
:
4682 return "DW_AT_GNU_vector";
4684 case DW_AT_VMS_rtnbeg_pd_address
:
4685 return "DW_AT_VMS_rtnbeg_pd_address";
4688 return "DW_AT_<unknown>";
4692 /* Convert a DWARF value form code into its string name. */
4695 dwarf_form_name (unsigned int form
)
4700 return "DW_FORM_addr";
4701 case DW_FORM_block2
:
4702 return "DW_FORM_block2";
4703 case DW_FORM_block4
:
4704 return "DW_FORM_block4";
4706 return "DW_FORM_data2";
4708 return "DW_FORM_data4";
4710 return "DW_FORM_data8";
4711 case DW_FORM_string
:
4712 return "DW_FORM_string";
4714 return "DW_FORM_block";
4715 case DW_FORM_block1
:
4716 return "DW_FORM_block1";
4718 return "DW_FORM_data1";
4720 return "DW_FORM_flag";
4722 return "DW_FORM_sdata";
4724 return "DW_FORM_strp";
4726 return "DW_FORM_udata";
4727 case DW_FORM_ref_addr
:
4728 return "DW_FORM_ref_addr";
4730 return "DW_FORM_ref1";
4732 return "DW_FORM_ref2";
4734 return "DW_FORM_ref4";
4736 return "DW_FORM_ref8";
4737 case DW_FORM_ref_udata
:
4738 return "DW_FORM_ref_udata";
4739 case DW_FORM_indirect
:
4740 return "DW_FORM_indirect";
4742 return "DW_FORM_<unknown>";
4746 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4747 instance of an inlined instance of a decl which is local to an inline
4748 function, so we have to trace all of the way back through the origin chain
4749 to find out what sort of node actually served as the original seed for the
4753 decl_ultimate_origin (tree decl
)
4755 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4758 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4759 nodes in the function to point to themselves; ignore that if
4760 we're trying to output the abstract instance of this function. */
4761 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4764 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4765 most distant ancestor, this should never happen. */
4766 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4768 return DECL_ABSTRACT_ORIGIN (decl
);
4771 /* Determine the "ultimate origin" of a block. The block may be an inlined
4772 instance of an inlined instance of a block which is local to an inline
4773 function, so we have to trace all of the way back through the origin chain
4774 to find out what sort of node actually served as the original seed for the
4778 block_ultimate_origin (tree block
)
4780 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4782 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4783 nodes in the function to point to themselves; ignore that if
4784 we're trying to output the abstract instance of this function. */
4785 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4788 if (immediate_origin
== NULL_TREE
)
4793 tree lookahead
= immediate_origin
;
4797 ret_val
= lookahead
;
4798 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4799 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4801 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4803 /* The block's abstract origin chain may not be the *ultimate* origin of
4804 the block. It could lead to a DECL that has an abstract origin set.
4805 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
4806 will give us if it has one). Note that DECL's abstract origins are
4807 supposed to be the most distant ancestor (or so decl_ultimate_origin
4808 claims), so we don't need to loop following the DECL origins. */
4809 if (DECL_P (ret_val
))
4810 return DECL_ORIGIN (ret_val
);
4816 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4817 of a virtual function may refer to a base class, so we check the 'this'
4821 decl_class_context (tree decl
)
4823 tree context
= NULL_TREE
;
4825 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4826 context
= DECL_CONTEXT (decl
);
4828 context
= TYPE_MAIN_VARIANT
4829 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4831 if (context
&& !TYPE_P (context
))
4832 context
= NULL_TREE
;
4837 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4838 addition order, and correct that in reverse_all_dies. */
4841 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
4843 /* Maybe this should be an assert? */
4847 if (die
->die_attr
== NULL
)
4848 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
4849 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, attr
);
4852 static inline enum dw_val_class
4853 AT_class (dw_attr_ref a
)
4855 return a
->dw_attr_val
.val_class
;
4858 /* Add a flag value attribute to a DIE. */
4861 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4865 attr
.dw_attr
= attr_kind
;
4866 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
4867 attr
.dw_attr_val
.v
.val_flag
= flag
;
4868 add_dwarf_attr (die
, &attr
);
4871 static inline unsigned
4872 AT_flag (dw_attr_ref a
)
4874 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4875 return a
->dw_attr_val
.v
.val_flag
;
4878 /* Add a signed integer attribute value to a DIE. */
4881 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4885 attr
.dw_attr
= attr_kind
;
4886 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
4887 attr
.dw_attr_val
.v
.val_int
= int_val
;
4888 add_dwarf_attr (die
, &attr
);
4891 static inline HOST_WIDE_INT
4892 AT_int (dw_attr_ref a
)
4894 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
4895 return a
->dw_attr_val
.v
.val_int
;
4898 /* Add an unsigned integer attribute value to a DIE. */
4901 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4902 unsigned HOST_WIDE_INT unsigned_val
)
4906 attr
.dw_attr
= attr_kind
;
4907 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4908 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4909 add_dwarf_attr (die
, &attr
);
4912 static inline unsigned HOST_WIDE_INT
4913 AT_unsigned (dw_attr_ref a
)
4915 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
4916 return a
->dw_attr_val
.v
.val_unsigned
;
4919 /* Add an unsigned double integer attribute value to a DIE. */
4922 add_AT_long_long (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4923 long unsigned int val_hi
, long unsigned int val_low
)
4927 attr
.dw_attr
= attr_kind
;
4928 attr
.dw_attr_val
.val_class
= dw_val_class_long_long
;
4929 attr
.dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4930 attr
.dw_attr_val
.v
.val_long_long
.low
= val_low
;
4931 add_dwarf_attr (die
, &attr
);
4934 /* Add a floating point attribute value to a DIE and return it. */
4937 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4938 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4942 attr
.dw_attr
= attr_kind
;
4943 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4944 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4945 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4946 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4947 add_dwarf_attr (die
, &attr
);
4950 /* Hash and equality functions for debug_str_hash. */
4953 debug_str_do_hash (const void *x
)
4955 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
4959 debug_str_eq (const void *x1
, const void *x2
)
4961 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
4962 (const char *)x2
) == 0;
4965 /* Add a string attribute value to a DIE. */
4968 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4971 struct indirect_string_node
*node
;
4974 if (! debug_str_hash
)
4975 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
4976 debug_str_eq
, NULL
);
4978 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
4979 htab_hash_string (str
), INSERT
);
4981 *slot
= ggc_alloc_cleared (sizeof (struct indirect_string_node
));
4982 node
= (struct indirect_string_node
*) *slot
;
4983 node
->str
= ggc_strdup (str
);
4986 attr
.dw_attr
= attr_kind
;
4987 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4988 attr
.dw_attr_val
.v
.val_str
= node
;
4989 add_dwarf_attr (die
, &attr
);
4992 static inline const char *
4993 AT_string (dw_attr_ref a
)
4995 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4996 return a
->dw_attr_val
.v
.val_str
->str
;
4999 /* Find out whether a string should be output inline in DIE
5000 or out-of-line in .debug_str section. */
5003 AT_string_form (dw_attr_ref a
)
5005 struct indirect_string_node
*node
;
5009 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
5011 node
= a
->dw_attr_val
.v
.val_str
;
5015 len
= strlen (node
->str
) + 1;
5017 /* If the string is shorter or equal to the size of the reference, it is
5018 always better to put it inline. */
5019 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
5020 return node
->form
= DW_FORM_string
;
5022 /* If we cannot expect the linker to merge strings in .debug_str
5023 section, only put it into .debug_str if it is worth even in this
5025 if ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
5026 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
5027 return node
->form
= DW_FORM_string
;
5029 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
5030 ++dw2_string_counter
;
5031 node
->label
= xstrdup (label
);
5033 return node
->form
= DW_FORM_strp
;
5036 /* Add a DIE reference attribute value to a DIE. */
5039 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
5043 attr
.dw_attr
= attr_kind
;
5044 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
5045 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
5046 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
5047 add_dwarf_attr (die
, &attr
);
5050 /* Add an AT_specification attribute to a DIE, and also make the back
5051 pointer from the specification to the definition. */
5054 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
5056 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
5057 gcc_assert (!targ_die
->die_definition
);
5058 targ_die
->die_definition
= die
;
5061 static inline dw_die_ref
5062 AT_ref (dw_attr_ref a
)
5064 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
5065 return a
->dw_attr_val
.v
.val_die_ref
.die
;
5069 AT_ref_external (dw_attr_ref a
)
5071 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
5072 return a
->dw_attr_val
.v
.val_die_ref
.external
;
5078 set_AT_ref_external (dw_attr_ref a
, int i
)
5080 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
5081 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
5084 /* Add an FDE reference attribute value to a DIE. */
5087 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
5091 attr
.dw_attr
= attr_kind
;
5092 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
5093 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
5094 add_dwarf_attr (die
, &attr
);
5097 /* Add a location description attribute value to a DIE. */
5100 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
5104 attr
.dw_attr
= attr_kind
;
5105 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
5106 attr
.dw_attr_val
.v
.val_loc
= loc
;
5107 add_dwarf_attr (die
, &attr
);
5110 static inline dw_loc_descr_ref
5111 AT_loc (dw_attr_ref a
)
5113 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
5114 return a
->dw_attr_val
.v
.val_loc
;
5118 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
5122 attr
.dw_attr
= attr_kind
;
5123 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
5124 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
5125 add_dwarf_attr (die
, &attr
);
5126 have_location_lists
= true;
5129 static inline dw_loc_list_ref
5130 AT_loc_list (dw_attr_ref a
)
5132 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
5133 return a
->dw_attr_val
.v
.val_loc_list
;
5136 /* Add an address constant attribute value to a DIE. */
5139 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
5143 attr
.dw_attr
= attr_kind
;
5144 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
5145 attr
.dw_attr_val
.v
.val_addr
= addr
;
5146 add_dwarf_attr (die
, &attr
);
5150 AT_addr (dw_attr_ref a
)
5152 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
5153 return a
->dw_attr_val
.v
.val_addr
;
5156 /* Add a label identifier attribute value to a DIE. */
5159 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
5163 attr
.dw_attr
= attr_kind
;
5164 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
5165 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
5166 add_dwarf_attr (die
, &attr
);
5169 /* Add a section offset attribute value to a DIE, an offset into the
5170 debug_line section. */
5173 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5178 attr
.dw_attr
= attr_kind
;
5179 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
5180 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5181 add_dwarf_attr (die
, &attr
);
5184 /* Add a section offset attribute value to a DIE, an offset into the
5185 debug_macinfo section. */
5188 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5193 attr
.dw_attr
= attr_kind
;
5194 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
5195 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5196 add_dwarf_attr (die
, &attr
);
5199 /* Add an offset attribute value to a DIE. */
5202 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5203 unsigned HOST_WIDE_INT offset
)
5207 attr
.dw_attr
= attr_kind
;
5208 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
5209 attr
.dw_attr_val
.v
.val_offset
= offset
;
5210 add_dwarf_attr (die
, &attr
);
5213 /* Add an range_list attribute value to a DIE. */
5216 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5217 long unsigned int offset
)
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
)
5243 dw_die_ref spec
= NULL
;
5248 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
5249 if (a
->dw_attr
== attr_kind
)
5251 else if (a
->dw_attr
== DW_AT_specification
5252 || a
->dw_attr
== DW_AT_abstract_origin
)
5256 return get_AT (spec
, attr_kind
);
5261 /* Return the "low pc" attribute value, typically associated with a subprogram
5262 DIE. Return null if the "low pc" attribute is either not present, or if it
5263 cannot be represented as an assembler label identifier. */
5265 static inline const char *
5266 get_AT_low_pc (dw_die_ref die
)
5268 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
5270 return a
? AT_lbl (a
) : NULL
;
5273 /* Return the "high pc" attribute value, typically associated with a subprogram
5274 DIE. Return null if the "high pc" attribute is either not present, or if it
5275 cannot be represented as an assembler label identifier. */
5277 static inline const char *
5278 get_AT_hi_pc (dw_die_ref die
)
5280 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
5282 return a
? AT_lbl (a
) : NULL
;
5285 /* Return the value of the string attribute designated by ATTR_KIND, or
5286 NULL if it is not present. */
5288 static inline const char *
5289 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5291 dw_attr_ref a
= get_AT (die
, attr_kind
);
5293 return a
? AT_string (a
) : NULL
;
5296 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5297 if it is not present. */
5300 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5302 dw_attr_ref a
= get_AT (die
, attr_kind
);
5304 return a
? AT_flag (a
) : 0;
5307 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5308 if it is not present. */
5310 static inline unsigned
5311 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5313 dw_attr_ref a
= get_AT (die
, attr_kind
);
5315 return a
? AT_unsigned (a
) : 0;
5318 static inline dw_die_ref
5319 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5321 dw_attr_ref a
= get_AT (die
, attr_kind
);
5323 return a
? AT_ref (a
) : NULL
;
5326 /* Return TRUE if the language is C or C++. */
5331 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5333 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
|| lang
== DW_LANG_ObjC
5334 || lang
== DW_LANG_C99
5335 || lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
);
5338 /* Return TRUE if the language is C++. */
5343 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5345 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
5348 /* Return TRUE if the language is Fortran. */
5353 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5355 return (lang
== DW_LANG_Fortran77
5356 || lang
== DW_LANG_Fortran90
5357 || lang
== DW_LANG_Fortran95
);
5360 /* Return TRUE if the language is Java. */
5365 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5367 return lang
== DW_LANG_Java
;
5370 /* Return TRUE if the language is Ada. */
5375 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5377 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5380 /* Free up the memory used by A. */
5382 static inline void free_AT (dw_attr_ref
);
5384 free_AT (dw_attr_ref a
)
5386 if (AT_class (a
) == dw_val_class_str
)
5387 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5388 a
->dw_attr_val
.v
.val_str
->refcount
--;
5391 /* Remove the specified attribute if present. */
5394 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5402 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
5403 if (a
->dw_attr
== attr_kind
)
5406 /* VEC_ordered_remove should help reduce the number of abbrevs
5408 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
5413 /* Remove child die whose die_tag is specified tag. */
5416 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5418 dw_die_ref current
, prev
, next
;
5419 current
= die
->die_child
;
5421 while (current
!= NULL
)
5423 if (current
->die_tag
== tag
)
5425 next
= current
->die_sib
;
5427 die
->die_child
= next
;
5429 prev
->die_sib
= next
;
5436 current
= current
->die_sib
;
5441 /* Free up the memory used by DIE, by removing its children and
5442 anything associated with its attributes. DIEs are garbage
5443 collected, so there is no actual freeing to do; the only real work is
5444 to decrease string reference counts. */
5447 free_die (dw_die_ref die
)
5449 dw_die_ref child_die
= die
->die_child
;
5451 die
->die_child
= NULL
;
5453 while (child_die
!= NULL
)
5455 dw_die_ref tmp_die
= child_die
;
5459 child_die
= child_die
->die_sib
;
5461 for (ix
= 0; VEC_iterate (dw_attr_node
, tmp_die
->die_attr
, ix
, a
); ix
++)
5468 /* Add a child DIE below its parent. We build the lists up in reverse
5469 addition order, and correct that in reverse_all_dies. */
5472 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5474 if (die
!= NULL
&& child_die
!= NULL
)
5476 gcc_assert (die
!= child_die
);
5478 child_die
->die_parent
= die
;
5479 child_die
->die_sib
= die
->die_child
;
5480 die
->die_child
= child_die
;
5484 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5485 is the specification, to the front of PARENT's list of children. */
5488 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5492 /* We want the declaration DIE from inside the class, not the
5493 specification DIE at toplevel. */
5494 if (child
->die_parent
!= parent
)
5496 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5502 gcc_assert (child
->die_parent
== parent
5503 || (child
->die_parent
5504 == get_AT_ref (parent
, DW_AT_specification
)));
5506 for (p
= &(child
->die_parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
5509 *p
= child
->die_sib
;
5513 child
->die_parent
= parent
;
5514 child
->die_sib
= parent
->die_child
;
5515 parent
->die_child
= child
;
5518 /* Return a pointer to a newly created DIE node. */
5520 static inline dw_die_ref
5521 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5523 dw_die_ref die
= ggc_alloc_cleared (sizeof (die_node
));
5525 die
->die_tag
= tag_value
;
5527 if (parent_die
!= NULL
)
5528 add_child_die (parent_die
, die
);
5531 limbo_die_node
*limbo_node
;
5533 limbo_node
= ggc_alloc_cleared (sizeof (limbo_die_node
));
5534 limbo_node
->die
= die
;
5535 limbo_node
->created_for
= t
;
5536 limbo_node
->next
= limbo_die_list
;
5537 limbo_die_list
= limbo_node
;
5543 /* Return the DIE associated with the given type specifier. */
5545 static inline dw_die_ref
5546 lookup_type_die (tree type
)
5548 return TYPE_SYMTAB_DIE (type
);
5551 /* Equate a DIE to a given type specifier. */
5554 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5556 TYPE_SYMTAB_DIE (type
) = type_die
;
5559 /* Returns a hash value for X (which really is a die_struct). */
5562 decl_die_table_hash (const void *x
)
5564 return (hashval_t
) ((const dw_die_ref
) x
)->decl_id
;
5567 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5570 decl_die_table_eq (const void *x
, const void *y
)
5572 return (((const dw_die_ref
) x
)->decl_id
== DECL_UID ((const tree
) y
));
5575 /* Return the DIE associated with a given declaration. */
5577 static inline dw_die_ref
5578 lookup_decl_die (tree decl
)
5580 return htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
5583 /* Returns a hash value for X (which really is a var_loc_list). */
5586 decl_loc_table_hash (const void *x
)
5588 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
5591 /* Return nonzero if decl_id of var_loc_list X is the same as
5595 decl_loc_table_eq (const void *x
, const void *y
)
5597 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const tree
) y
));
5600 /* Return the var_loc list associated with a given declaration. */
5602 static inline var_loc_list
*
5603 lookup_decl_loc (tree decl
)
5605 return htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
5608 /* Equate a DIE to a particular declaration. */
5611 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5613 unsigned int decl_id
= DECL_UID (decl
);
5616 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
5618 decl_die
->decl_id
= decl_id
;
5621 /* Add a variable location node to the linked list for DECL. */
5624 add_var_loc_to_decl (tree decl
, struct var_loc_node
*loc
)
5626 unsigned int decl_id
= DECL_UID (decl
);
5630 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5633 temp
= ggc_alloc_cleared (sizeof (var_loc_list
));
5634 temp
->decl_id
= decl_id
;
5642 /* If the current location is the same as the end of the list,
5643 we have nothing to do. */
5644 if (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->last
->var_loc_note
),
5645 NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
)))
5647 /* Add LOC to the end of list and update LAST. */
5648 temp
->last
->next
= loc
;
5652 /* Do not add empty location to the beginning of the list. */
5653 else if (NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
) != NULL_RTX
)
5660 /* Keep track of the number of spaces used to indent the
5661 output of the debugging routines that print the structure of
5662 the DIE internal representation. */
5663 static int print_indent
;
5665 /* Indent the line the number of spaces given by print_indent. */
5668 print_spaces (FILE *outfile
)
5670 fprintf (outfile
, "%*s", print_indent
, "");
5673 /* Print the information associated with a given DIE, and its children.
5674 This routine is a debugging aid only. */
5677 print_die (dw_die_ref die
, FILE *outfile
)
5683 print_spaces (outfile
);
5684 fprintf (outfile
, "DIE %4lu: %s\n",
5685 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5686 print_spaces (outfile
);
5687 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5688 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
5690 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
5692 print_spaces (outfile
);
5693 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5695 switch (AT_class (a
))
5697 case dw_val_class_addr
:
5698 fprintf (outfile
, "address");
5700 case dw_val_class_offset
:
5701 fprintf (outfile
, "offset");
5703 case dw_val_class_loc
:
5704 fprintf (outfile
, "location descriptor");
5706 case dw_val_class_loc_list
:
5707 fprintf (outfile
, "location list -> label:%s",
5708 AT_loc_list (a
)->ll_symbol
);
5710 case dw_val_class_range_list
:
5711 fprintf (outfile
, "range list");
5713 case dw_val_class_const
:
5714 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5716 case dw_val_class_unsigned_const
:
5717 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5719 case dw_val_class_long_long
:
5720 fprintf (outfile
, "constant (%lu,%lu)",
5721 a
->dw_attr_val
.v
.val_long_long
.hi
,
5722 a
->dw_attr_val
.v
.val_long_long
.low
);
5724 case dw_val_class_vec
:
5725 fprintf (outfile
, "floating-point or vector constant");
5727 case dw_val_class_flag
:
5728 fprintf (outfile
, "%u", AT_flag (a
));
5730 case dw_val_class_die_ref
:
5731 if (AT_ref (a
) != NULL
)
5733 if (AT_ref (a
)->die_symbol
)
5734 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5736 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
5739 fprintf (outfile
, "die -> <null>");
5741 case dw_val_class_lbl_id
:
5742 case dw_val_class_lineptr
:
5743 case dw_val_class_macptr
:
5744 fprintf (outfile
, "label: %s", AT_lbl (a
));
5746 case dw_val_class_str
:
5747 if (AT_string (a
) != NULL
)
5748 fprintf (outfile
, "\"%s\"", AT_string (a
));
5750 fprintf (outfile
, "<null>");
5756 fprintf (outfile
, "\n");
5759 if (die
->die_child
!= NULL
)
5762 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5763 print_die (c
, outfile
);
5767 if (print_indent
== 0)
5768 fprintf (outfile
, "\n");
5771 /* Print the contents of the source code line number correspondence table.
5772 This routine is a debugging aid only. */
5775 print_dwarf_line_table (FILE *outfile
)
5778 dw_line_info_ref line_info
;
5780 fprintf (outfile
, "\n\nDWARF source line information\n");
5781 for (i
= 1; i
< line_info_table_in_use
; i
++)
5783 line_info
= &line_info_table
[i
];
5784 fprintf (outfile
, "%5d: ", i
);
5785 fprintf (outfile
, "%-20s",
5786 VARRAY_CHAR_PTR (file_table
, line_info
->dw_file_num
));
5787 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
5788 fprintf (outfile
, "\n");
5791 fprintf (outfile
, "\n\n");
5794 /* Print the information collected for a given DIE. */
5797 debug_dwarf_die (dw_die_ref die
)
5799 print_die (die
, stderr
);
5802 /* Print all DWARF information collected for the compilation unit.
5803 This routine is a debugging aid only. */
5809 print_die (comp_unit_die
, stderr
);
5810 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5811 print_dwarf_line_table (stderr
);
5814 /* We build up the lists of children and attributes by pushing new ones
5815 onto the beginning of the list. Reverse the lists for DIE so that
5816 they are in order of addition. */
5819 reverse_die_lists (dw_die_ref die
)
5821 dw_die_ref c
, cp
, cn
;
5823 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
5830 die
->die_child
= cp
;
5833 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5834 reverse all dies in add_sibling_attributes, which runs through all the dies,
5835 it would reverse all the dies. Now, however, since we don't call
5836 reverse_die_lists in add_sibling_attributes, we need a routine to
5837 recursively reverse all the dies. This is that routine. */
5840 reverse_all_dies (dw_die_ref die
)
5844 reverse_die_lists (die
);
5846 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5847 reverse_all_dies (c
);
5850 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5851 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5852 DIE that marks the start of the DIEs for this include file. */
5855 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5857 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5858 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5860 new_unit
->die_sib
= old_unit
;
5864 /* Close an include-file CU and reopen the enclosing one. */
5867 pop_compile_unit (dw_die_ref old_unit
)
5869 dw_die_ref new_unit
= old_unit
->die_sib
;
5871 old_unit
->die_sib
= NULL
;
5875 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5876 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5878 /* Calculate the checksum of a location expression. */
5881 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5883 CHECKSUM (loc
->dw_loc_opc
);
5884 CHECKSUM (loc
->dw_loc_oprnd1
);
5885 CHECKSUM (loc
->dw_loc_oprnd2
);
5888 /* Calculate the checksum of an attribute. */
5891 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5893 dw_loc_descr_ref loc
;
5896 CHECKSUM (at
->dw_attr
);
5898 /* We don't care about differences in file numbering. */
5899 if (at
->dw_attr
== DW_AT_decl_file
5900 /* Or that this was compiled with a different compiler snapshot; if
5901 the output is the same, that's what matters. */
5902 || at
->dw_attr
== DW_AT_producer
)
5905 switch (AT_class (at
))
5907 case dw_val_class_const
:
5908 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5910 case dw_val_class_unsigned_const
:
5911 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5913 case dw_val_class_long_long
:
5914 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
5916 case dw_val_class_vec
:
5917 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5919 case dw_val_class_flag
:
5920 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5922 case dw_val_class_str
:
5923 CHECKSUM_STRING (AT_string (at
));
5926 case dw_val_class_addr
:
5928 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5929 CHECKSUM_STRING (XSTR (r
, 0));
5932 case dw_val_class_offset
:
5933 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5936 case dw_val_class_loc
:
5937 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5938 loc_checksum (loc
, ctx
);
5941 case dw_val_class_die_ref
:
5942 die_checksum (AT_ref (at
), ctx
, mark
);
5945 case dw_val_class_fde_ref
:
5946 case dw_val_class_lbl_id
:
5947 case dw_val_class_lineptr
:
5948 case dw_val_class_macptr
:
5956 /* Calculate the checksum of a DIE. */
5959 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5965 /* To avoid infinite recursion. */
5968 CHECKSUM (die
->die_mark
);
5971 die
->die_mark
= ++(*mark
);
5973 CHECKSUM (die
->die_tag
);
5975 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
5976 attr_checksum (a
, ctx
, mark
);
5978 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5979 die_checksum (c
, ctx
, mark
);
5983 #undef CHECKSUM_STRING
5985 /* Do the location expressions look same? */
5987 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
5989 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
5990 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
5991 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
5994 /* Do the values look the same? */
5996 same_dw_val_p (dw_val_node
*v1
, dw_val_node
*v2
, int *mark
)
5998 dw_loc_descr_ref loc1
, loc2
;
6001 if (v1
->val_class
!= v2
->val_class
)
6004 switch (v1
->val_class
)
6006 case dw_val_class_const
:
6007 return v1
->v
.val_int
== v2
->v
.val_int
;
6008 case dw_val_class_unsigned_const
:
6009 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6010 case dw_val_class_long_long
:
6011 return v1
->v
.val_long_long
.hi
== v2
->v
.val_long_long
.hi
6012 && v1
->v
.val_long_long
.low
== v2
->v
.val_long_long
.low
;
6013 case dw_val_class_vec
:
6014 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6015 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6017 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6018 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6021 case dw_val_class_flag
:
6022 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6023 case dw_val_class_str
:
6024 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6026 case dw_val_class_addr
:
6027 r1
= v1
->v
.val_addr
;
6028 r2
= v2
->v
.val_addr
;
6029 if (GET_CODE (r1
) != GET_CODE (r2
))
6031 gcc_assert (GET_CODE (r1
) == SYMBOL_REF
);
6032 return !strcmp (XSTR (r1
, 0), XSTR (r2
, 0));
6034 case dw_val_class_offset
:
6035 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6037 case dw_val_class_loc
:
6038 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6040 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6041 if (!same_loc_p (loc1
, loc2
, mark
))
6043 return !loc1
&& !loc2
;
6045 case dw_val_class_die_ref
:
6046 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6048 case dw_val_class_fde_ref
:
6049 case dw_val_class_lbl_id
:
6050 case dw_val_class_lineptr
:
6051 case dw_val_class_macptr
:
6059 /* Do the attributes look the same? */
6062 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6064 if (at1
->dw_attr
!= at2
->dw_attr
)
6067 /* We don't care about differences in file numbering. */
6068 if (at1
->dw_attr
== DW_AT_decl_file
6069 /* Or that this was compiled with a different compiler snapshot; if
6070 the output is the same, that's what matters. */
6071 || at1
->dw_attr
== DW_AT_producer
)
6074 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6077 /* Do the dies look the same? */
6080 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6086 /* To avoid infinite recursion. */
6088 return die1
->die_mark
== die2
->die_mark
;
6089 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6091 if (die1
->die_tag
!= die2
->die_tag
)
6094 if (VEC_length (dw_attr_node
, die1
->die_attr
)
6095 != VEC_length (dw_attr_node
, die2
->die_attr
))
6098 for (ix
= 0; VEC_iterate (dw_attr_node
, die1
->die_attr
, ix
, a1
); ix
++)
6099 if (!same_attr_p (a1
, VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
6102 for (c1
= die1
->die_child
, c2
= die2
->die_child
;
6104 c1
= c1
->die_sib
, c2
= c2
->die_sib
)
6105 if (!same_die_p (c1
, c2
, mark
))
6113 /* Do the dies look the same? Wrapper around same_die_p. */
6116 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6119 int ret
= same_die_p (die1
, die2
, &mark
);
6121 unmark_all_dies (die1
);
6122 unmark_all_dies (die2
);
6127 /* The prefix to attach to symbols on DIEs in the current comdat debug
6129 static char *comdat_symbol_id
;
6131 /* The index of the current symbol within the current comdat CU. */
6132 static unsigned int comdat_symbol_number
;
6134 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6135 children, and set comdat_symbol_id accordingly. */
6138 compute_section_prefix (dw_die_ref unit_die
)
6140 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6141 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6142 char *name
= alloca (strlen (base
) + 64);
6145 unsigned char checksum
[16];
6148 /* Compute the checksum of the DIE, then append part of it as hex digits to
6149 the name filename of the unit. */
6151 md5_init_ctx (&ctx
);
6153 die_checksum (unit_die
, &ctx
, &mark
);
6154 unmark_all_dies (unit_die
);
6155 md5_finish_ctx (&ctx
, checksum
);
6157 sprintf (name
, "%s.", base
);
6158 clean_symbol_name (name
);
6160 p
= name
+ strlen (name
);
6161 for (i
= 0; i
< 4; i
++)
6163 sprintf (p
, "%.2x", checksum
[i
]);
6167 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
6168 comdat_symbol_number
= 0;
6171 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6174 is_type_die (dw_die_ref die
)
6176 switch (die
->die_tag
)
6178 case DW_TAG_array_type
:
6179 case DW_TAG_class_type
:
6180 case DW_TAG_enumeration_type
:
6181 case DW_TAG_pointer_type
:
6182 case DW_TAG_reference_type
:
6183 case DW_TAG_string_type
:
6184 case DW_TAG_structure_type
:
6185 case DW_TAG_subroutine_type
:
6186 case DW_TAG_union_type
:
6187 case DW_TAG_ptr_to_member_type
:
6188 case DW_TAG_set_type
:
6189 case DW_TAG_subrange_type
:
6190 case DW_TAG_base_type
:
6191 case DW_TAG_const_type
:
6192 case DW_TAG_file_type
:
6193 case DW_TAG_packed_type
:
6194 case DW_TAG_volatile_type
:
6195 case DW_TAG_typedef
:
6202 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6203 Basically, we want to choose the bits that are likely to be shared between
6204 compilations (types) and leave out the bits that are specific to individual
6205 compilations (functions). */
6208 is_comdat_die (dw_die_ref c
)
6210 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6211 we do for stabs. The advantage is a greater likelihood of sharing between
6212 objects that don't include headers in the same order (and therefore would
6213 put the base types in a different comdat). jason 8/28/00 */
6215 if (c
->die_tag
== DW_TAG_base_type
)
6218 if (c
->die_tag
== DW_TAG_pointer_type
6219 || c
->die_tag
== DW_TAG_reference_type
6220 || c
->die_tag
== DW_TAG_const_type
6221 || c
->die_tag
== DW_TAG_volatile_type
)
6223 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6225 return t
? is_comdat_die (t
) : 0;
6228 return is_type_die (c
);
6231 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6232 compilation unit. */
6235 is_symbol_die (dw_die_ref c
)
6237 return (is_type_die (c
)
6238 || (get_AT (c
, DW_AT_declaration
)
6239 && !get_AT (c
, DW_AT_specification
))
6240 || c
->die_tag
== DW_TAG_namespace
);
6244 gen_internal_sym (const char *prefix
)
6248 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6249 return xstrdup (buf
);
6252 /* Assign symbols to all worthy DIEs under DIE. */
6255 assign_symbol_names (dw_die_ref die
)
6259 if (is_symbol_die (die
))
6261 if (comdat_symbol_id
)
6263 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
6265 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6266 comdat_symbol_id
, comdat_symbol_number
++);
6267 die
->die_symbol
= xstrdup (p
);
6270 die
->die_symbol
= gen_internal_sym ("LDIE");
6273 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6274 assign_symbol_names (c
);
6277 struct cu_hash_table_entry
6280 unsigned min_comdat_num
, max_comdat_num
;
6281 struct cu_hash_table_entry
*next
;
6284 /* Routines to manipulate hash table of CUs. */
6286 htab_cu_hash (const void *of
)
6288 const struct cu_hash_table_entry
*entry
= of
;
6290 return htab_hash_string (entry
->cu
->die_symbol
);
6294 htab_cu_eq (const void *of1
, const void *of2
)
6296 const struct cu_hash_table_entry
*entry1
= of1
;
6297 const struct die_struct
*entry2
= of2
;
6299 return !strcmp (entry1
->cu
->die_symbol
, entry2
->die_symbol
);
6303 htab_cu_del (void *what
)
6305 struct cu_hash_table_entry
*next
, *entry
= what
;
6315 /* Check whether we have already seen this CU and set up SYM_NUM
6318 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6320 struct cu_hash_table_entry dummy
;
6321 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6323 dummy
.max_comdat_num
= 0;
6325 slot
= (struct cu_hash_table_entry
**)
6326 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6330 for (; entry
; last
= entry
, entry
= entry
->next
)
6332 if (same_die_p_wrap (cu
, entry
->cu
))
6338 *sym_num
= entry
->min_comdat_num
;
6342 entry
= XCNEW (struct cu_hash_table_entry
);
6344 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6345 entry
->next
= *slot
;
6351 /* Record SYM_NUM to record of CU in HTABLE. */
6353 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6355 struct cu_hash_table_entry
**slot
, *entry
;
6357 slot
= (struct cu_hash_table_entry
**)
6358 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6362 entry
->max_comdat_num
= sym_num
;
6365 /* Traverse the DIE (which is always comp_unit_die), and set up
6366 additional compilation units for each of the include files we see
6367 bracketed by BINCL/EINCL. */
6370 break_out_includes (dw_die_ref die
)
6373 dw_die_ref unit
= NULL
;
6374 limbo_die_node
*node
, **pnode
;
6375 htab_t cu_hash_table
;
6377 for (ptr
= &(die
->die_child
); *ptr
;)
6379 dw_die_ref c
= *ptr
;
6381 if (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6382 || (unit
&& is_comdat_die (c
)))
6384 /* This DIE is for a secondary CU; remove it from the main one. */
6387 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6389 unit
= push_new_compile_unit (unit
, c
);
6392 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6394 unit
= pop_compile_unit (unit
);
6398 add_child_die (unit
, c
);
6402 /* Leave this DIE in the main CU. */
6403 ptr
= &(c
->die_sib
);
6409 /* We can only use this in debugging, since the frontend doesn't check
6410 to make sure that we leave every include file we enter. */
6414 assign_symbol_names (die
);
6415 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6416 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6422 compute_section_prefix (node
->die
);
6423 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6424 &comdat_symbol_number
);
6425 assign_symbol_names (node
->die
);
6427 *pnode
= node
->next
;
6430 pnode
= &node
->next
;
6431 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6432 comdat_symbol_number
);
6435 htab_delete (cu_hash_table
);
6438 /* Traverse the DIE and add a sibling attribute if it may have the
6439 effect of speeding up access to siblings. To save some space,
6440 avoid generating sibling attributes for DIE's without children. */
6443 add_sibling_attributes (dw_die_ref die
)
6447 if (die
->die_tag
!= DW_TAG_compile_unit
6448 && die
->die_sib
&& die
->die_child
!= NULL
)
6449 /* Add the sibling link to the front of the attribute list. */
6450 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
6452 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6453 add_sibling_attributes (c
);
6456 /* Output all location lists for the DIE and its children. */
6459 output_location_lists (dw_die_ref die
)
6465 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6466 if (AT_class (a
) == dw_val_class_loc_list
)
6467 output_loc_list (AT_loc_list (a
));
6469 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6470 output_location_lists (c
);
6474 /* The format of each DIE (and its attribute value pairs) is encoded in an
6475 abbreviation table. This routine builds the abbreviation table and assigns
6476 a unique abbreviation id for each abbreviation entry. The children of each
6477 die are visited recursively. */
6480 build_abbrev_table (dw_die_ref die
)
6482 unsigned long abbrev_id
;
6483 unsigned int n_alloc
;
6488 /* Scan the DIE references, and mark as external any that refer to
6489 DIEs from other CUs (i.e. those which are not marked). */
6490 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6491 if (AT_class (a
) == dw_val_class_die_ref
6492 && AT_ref (a
)->die_mark
== 0)
6494 gcc_assert (AT_ref (a
)->die_symbol
);
6496 set_AT_ref_external (a
, 1);
6499 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6501 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6502 dw_attr_ref die_a
, abbrev_a
;
6506 if (abbrev
->die_tag
!= die
->die_tag
)
6508 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
6511 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
6512 != VEC_length (dw_attr_node
, die
->die_attr
))
6515 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, die_a
); ix
++)
6517 abbrev_a
= VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
6518 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
6519 || (value_format (abbrev_a
) != value_format (die_a
)))
6529 if (abbrev_id
>= abbrev_die_table_in_use
)
6531 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
6533 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
6534 abbrev_die_table
= ggc_realloc (abbrev_die_table
,
6535 sizeof (dw_die_ref
) * n_alloc
);
6537 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
6538 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
6539 abbrev_die_table_allocated
= n_alloc
;
6542 ++abbrev_die_table_in_use
;
6543 abbrev_die_table
[abbrev_id
] = die
;
6546 die
->die_abbrev
= abbrev_id
;
6547 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6548 build_abbrev_table (c
);
6551 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6554 constant_size (long unsigned int value
)
6561 log
= floor_log2 (value
);
6564 log
= 1 << (floor_log2 (log
) + 1);
6569 /* Return the size of a DIE as it is represented in the
6570 .debug_info section. */
6572 static unsigned long
6573 size_of_die (dw_die_ref die
)
6575 unsigned long size
= 0;
6579 size
+= size_of_uleb128 (die
->die_abbrev
);
6580 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6582 switch (AT_class (a
))
6584 case dw_val_class_addr
:
6585 size
+= DWARF2_ADDR_SIZE
;
6587 case dw_val_class_offset
:
6588 size
+= DWARF_OFFSET_SIZE
;
6590 case dw_val_class_loc
:
6592 unsigned long lsize
= size_of_locs (AT_loc (a
));
6595 size
+= constant_size (lsize
);
6599 case dw_val_class_loc_list
:
6600 size
+= DWARF_OFFSET_SIZE
;
6602 case dw_val_class_range_list
:
6603 size
+= DWARF_OFFSET_SIZE
;
6605 case dw_val_class_const
:
6606 size
+= size_of_sleb128 (AT_int (a
));
6608 case dw_val_class_unsigned_const
:
6609 size
+= constant_size (AT_unsigned (a
));
6611 case dw_val_class_long_long
:
6612 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
6614 case dw_val_class_vec
:
6615 size
+= 1 + (a
->dw_attr_val
.v
.val_vec
.length
6616 * a
->dw_attr_val
.v
.val_vec
.elt_size
); /* block */
6618 case dw_val_class_flag
:
6621 case dw_val_class_die_ref
:
6622 if (AT_ref_external (a
))
6623 size
+= DWARF2_ADDR_SIZE
;
6625 size
+= DWARF_OFFSET_SIZE
;
6627 case dw_val_class_fde_ref
:
6628 size
+= DWARF_OFFSET_SIZE
;
6630 case dw_val_class_lbl_id
:
6631 size
+= DWARF2_ADDR_SIZE
;
6633 case dw_val_class_lineptr
:
6634 case dw_val_class_macptr
:
6635 size
+= DWARF_OFFSET_SIZE
;
6637 case dw_val_class_str
:
6638 if (AT_string_form (a
) == DW_FORM_strp
)
6639 size
+= DWARF_OFFSET_SIZE
;
6641 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
6651 /* Size the debugging information associated with a given DIE. Visits the
6652 DIE's children recursively. Updates the global variable next_die_offset, on
6653 each time through. Uses the current value of next_die_offset to update the
6654 die_offset field in each DIE. */
6657 calc_die_sizes (dw_die_ref die
)
6661 die
->die_offset
= next_die_offset
;
6662 next_die_offset
+= size_of_die (die
);
6664 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6667 if (die
->die_child
!= NULL
)
6668 /* Count the null byte used to terminate sibling lists. */
6669 next_die_offset
+= 1;
6672 /* Set the marks for a die and its children. We do this so
6673 that we know whether or not a reference needs to use FORM_ref_addr; only
6674 DIEs in the same CU will be marked. We used to clear out the offset
6675 and use that as the flag, but ran into ordering problems. */
6678 mark_dies (dw_die_ref die
)
6682 gcc_assert (!die
->die_mark
);
6685 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6689 /* Clear the marks for a die and its children. */
6692 unmark_dies (dw_die_ref die
)
6696 gcc_assert (die
->die_mark
);
6699 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6703 /* Clear the marks for a die, its children and referred dies. */
6706 unmark_all_dies (dw_die_ref die
)
6716 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6717 unmark_all_dies (c
);
6719 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6720 if (AT_class (a
) == dw_val_class_die_ref
)
6721 unmark_all_dies (AT_ref (a
));
6724 /* Return the size of the .debug_pubnames table generated for the
6725 compilation unit. */
6727 static unsigned long
6728 size_of_pubnames (void)
6733 size
= DWARF_PUBNAMES_HEADER_SIZE
;
6734 for (i
= 0; i
< pubname_table_in_use
; i
++)
6736 pubname_ref p
= &pubname_table
[i
];
6737 size
+= DWARF_OFFSET_SIZE
+ strlen (p
->name
) + 1;
6740 size
+= DWARF_OFFSET_SIZE
;
6744 /* Return the size of the information in the .debug_aranges section. */
6746 static unsigned long
6747 size_of_aranges (void)
6751 size
= DWARF_ARANGES_HEADER_SIZE
;
6753 /* Count the address/length pair for this compilation unit. */
6754 size
+= 2 * DWARF2_ADDR_SIZE
;
6755 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
6757 /* Count the two zero words used to terminated the address range table. */
6758 size
+= 2 * DWARF2_ADDR_SIZE
;
6762 /* Select the encoding of an attribute value. */
6764 static enum dwarf_form
6765 value_format (dw_attr_ref a
)
6767 switch (a
->dw_attr_val
.val_class
)
6769 case dw_val_class_addr
:
6770 return DW_FORM_addr
;
6771 case dw_val_class_range_list
:
6772 case dw_val_class_offset
:
6773 case dw_val_class_loc_list
:
6774 switch (DWARF_OFFSET_SIZE
)
6777 return DW_FORM_data4
;
6779 return DW_FORM_data8
;
6783 case dw_val_class_loc
:
6784 switch (constant_size (size_of_locs (AT_loc (a
))))
6787 return DW_FORM_block1
;
6789 return DW_FORM_block2
;
6793 case dw_val_class_const
:
6794 return DW_FORM_sdata
;
6795 case dw_val_class_unsigned_const
:
6796 switch (constant_size (AT_unsigned (a
)))
6799 return DW_FORM_data1
;
6801 return DW_FORM_data2
;
6803 return DW_FORM_data4
;
6805 return DW_FORM_data8
;
6809 case dw_val_class_long_long
:
6810 return DW_FORM_block1
;
6811 case dw_val_class_vec
:
6812 return DW_FORM_block1
;
6813 case dw_val_class_flag
:
6814 return DW_FORM_flag
;
6815 case dw_val_class_die_ref
:
6816 if (AT_ref_external (a
))
6817 return DW_FORM_ref_addr
;
6820 case dw_val_class_fde_ref
:
6821 return DW_FORM_data
;
6822 case dw_val_class_lbl_id
:
6823 return DW_FORM_addr
;
6824 case dw_val_class_lineptr
:
6825 case dw_val_class_macptr
:
6826 return DW_FORM_data
;
6827 case dw_val_class_str
:
6828 return AT_string_form (a
);
6835 /* Output the encoding of an attribute value. */
6838 output_value_format (dw_attr_ref a
)
6840 enum dwarf_form form
= value_format (a
);
6842 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
6845 /* Output the .debug_abbrev section which defines the DIE abbreviation
6849 output_abbrev_section (void)
6851 unsigned long abbrev_id
;
6853 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6855 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6859 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
6860 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
6861 dwarf_tag_name (abbrev
->die_tag
));
6863 if (abbrev
->die_child
!= NULL
)
6864 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
6866 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
6868 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
6871 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
6872 dwarf_attr_name (a_attr
->dw_attr
));
6873 output_value_format (a_attr
);
6876 dw2_asm_output_data (1, 0, NULL
);
6877 dw2_asm_output_data (1, 0, NULL
);
6880 /* Terminate the table. */
6881 dw2_asm_output_data (1, 0, NULL
);
6884 /* Output a symbol we can use to refer to this DIE from another CU. */
6887 output_die_symbol (dw_die_ref die
)
6889 char *sym
= die
->die_symbol
;
6894 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
6895 /* We make these global, not weak; if the target doesn't support
6896 .linkonce, it doesn't support combining the sections, so debugging
6898 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
6900 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
6903 /* Return a new location list, given the begin and end range, and the
6904 expression. gensym tells us whether to generate a new internal symbol for
6905 this location list node, which is done for the head of the list only. */
6907 static inline dw_loc_list_ref
6908 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
6909 const char *section
, unsigned int gensym
)
6911 dw_loc_list_ref retlist
= ggc_alloc_cleared (sizeof (dw_loc_list_node
));
6913 retlist
->begin
= begin
;
6915 retlist
->expr
= expr
;
6916 retlist
->section
= section
;
6918 retlist
->ll_symbol
= gen_internal_sym ("LLST");
6923 /* Add a location description expression to a location list. */
6926 add_loc_descr_to_loc_list (dw_loc_list_ref
*list_head
, dw_loc_descr_ref descr
,
6927 const char *begin
, const char *end
,
6928 const char *section
)
6932 /* Find the end of the chain. */
6933 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
6936 /* Add a new location list node to the list. */
6937 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
6941 dwarf2out_switch_text_section (void)
6947 fde
= &fde_table
[fde_table_in_use
- 1];
6948 fde
->dw_fde_switched_sections
= true;
6949 fde
->dw_fde_hot_section_label
= cfun
->hot_section_label
;
6950 fde
->dw_fde_hot_section_end_label
= cfun
->hot_section_end_label
;
6951 fde
->dw_fde_unlikely_section_label
= cfun
->cold_section_label
;
6952 fde
->dw_fde_unlikely_section_end_label
= cfun
->cold_section_end_label
;
6953 have_multiple_function_sections
= true;
6956 /* Output the location list given to us. */
6959 output_loc_list (dw_loc_list_ref list_head
)
6961 dw_loc_list_ref curr
= list_head
;
6963 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
6965 /* Walk the location list, and output each range + expression. */
6966 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
6969 if (!have_multiple_function_sections
)
6971 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
6972 "Location list begin address (%s)",
6973 list_head
->ll_symbol
);
6974 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
6975 "Location list end address (%s)",
6976 list_head
->ll_symbol
);
6980 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
6981 "Location list begin address (%s)",
6982 list_head
->ll_symbol
);
6983 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
6984 "Location list end address (%s)",
6985 list_head
->ll_symbol
);
6987 size
= size_of_locs (curr
->expr
);
6989 /* Output the block length for this list of location operations. */
6990 gcc_assert (size
<= 0xffff);
6991 dw2_asm_output_data (2, size
, "%s", "Location expression size");
6993 output_loc_sequence (curr
->expr
);
6996 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
6997 "Location list terminator begin (%s)",
6998 list_head
->ll_symbol
);
6999 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7000 "Location list terminator end (%s)",
7001 list_head
->ll_symbol
);
7004 /* Output the DIE and its attributes. Called recursively to generate
7005 the definitions of each child DIE. */
7008 output_die (dw_die_ref die
)
7015 /* If someone in another CU might refer to us, set up a symbol for
7016 them to point to. */
7017 if (die
->die_symbol
)
7018 output_die_symbol (die
);
7020 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
7021 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
7023 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7025 const char *name
= dwarf_attr_name (a
->dw_attr
);
7027 switch (AT_class (a
))
7029 case dw_val_class_addr
:
7030 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
7033 case dw_val_class_offset
:
7034 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
7038 case dw_val_class_range_list
:
7040 char *p
= strchr (ranges_section_label
, '\0');
7042 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
7043 a
->dw_attr_val
.v
.val_offset
);
7044 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
7045 debug_ranges_section
, "%s", name
);
7050 case dw_val_class_loc
:
7051 size
= size_of_locs (AT_loc (a
));
7053 /* Output the block length for this list of location operations. */
7054 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
7056 output_loc_sequence (AT_loc (a
));
7059 case dw_val_class_const
:
7060 /* ??? It would be slightly more efficient to use a scheme like is
7061 used for unsigned constants below, but gdb 4.x does not sign
7062 extend. Gdb 5.x does sign extend. */
7063 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
7066 case dw_val_class_unsigned_const
:
7067 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
7068 AT_unsigned (a
), "%s", name
);
7071 case dw_val_class_long_long
:
7073 unsigned HOST_WIDE_INT first
, second
;
7075 dw2_asm_output_data (1,
7076 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
7079 if (WORDS_BIG_ENDIAN
)
7081 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
7082 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
7086 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
7087 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
7090 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
7091 first
, "long long constant");
7092 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
7097 case dw_val_class_vec
:
7099 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
7100 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
7104 dw2_asm_output_data (1, len
* elt_size
, "%s", name
);
7105 if (elt_size
> sizeof (HOST_WIDE_INT
))
7110 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
7113 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
7114 "fp or vector constant word %u", i
);
7118 case dw_val_class_flag
:
7119 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
7122 case dw_val_class_loc_list
:
7124 char *sym
= AT_loc_list (a
)->ll_symbol
;
7127 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
7132 case dw_val_class_die_ref
:
7133 if (AT_ref_external (a
))
7135 char *sym
= AT_ref (a
)->die_symbol
;
7138 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, debug_info_section
,
7143 gcc_assert (AT_ref (a
)->die_offset
);
7144 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
7149 case dw_val_class_fde_ref
:
7153 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
7154 a
->dw_attr_val
.v
.val_fde_index
* 2);
7155 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
7160 case dw_val_class_lbl_id
:
7161 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
7164 case dw_val_class_lineptr
:
7165 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
7166 debug_line_section
, "%s", name
);
7169 case dw_val_class_macptr
:
7170 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
7171 debug_macinfo_section
, "%s", name
);
7174 case dw_val_class_str
:
7175 if (AT_string_form (a
) == DW_FORM_strp
)
7176 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
7177 a
->dw_attr_val
.v
.val_str
->label
,
7179 "%s: \"%s\"", name
, AT_string (a
));
7181 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
7189 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
7192 /* Add null byte to terminate sibling list. */
7193 if (die
->die_child
!= NULL
)
7194 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7198 /* Output the compilation unit that appears at the beginning of the
7199 .debug_info section, and precedes the DIE descriptions. */
7202 output_compilation_unit_header (void)
7204 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7205 dw2_asm_output_data (4, 0xffffffff,
7206 "Initial length escape value indicating 64-bit DWARF extension");
7207 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
7208 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
7209 "Length of Compilation Unit Info");
7210 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
7211 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
7212 debug_abbrev_section
,
7213 "Offset Into Abbrev. Section");
7214 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
7217 /* Output the compilation unit DIE and its children. */
7220 output_comp_unit (dw_die_ref die
, int output_if_empty
)
7222 const char *secname
;
7225 /* Unless we are outputting main CU, we may throw away empty ones. */
7226 if (!output_if_empty
&& die
->die_child
== NULL
)
7229 /* Even if there are no children of this DIE, we must output the information
7230 about the compilation unit. Otherwise, on an empty translation unit, we
7231 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7232 will then complain when examining the file. First mark all the DIEs in
7233 this CU so we know which get local refs. */
7236 build_abbrev_table (die
);
7238 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7239 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7240 calc_die_sizes (die
);
7242 oldsym
= die
->die_symbol
;
7245 tmp
= alloca (strlen (oldsym
) + 24);
7247 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
7249 die
->die_symbol
= NULL
;
7250 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
7253 switch_to_section (debug_info_section
);
7255 /* Output debugging information. */
7256 output_compilation_unit_header ();
7259 /* Leave the marks on the main CU, so we can check them in
7264 die
->die_symbol
= oldsym
;
7268 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
7269 output of lang_hooks.decl_printable_name for C++ looks like
7270 "A::f(int)". Let's drop the argument list, and maybe the scope. */
7273 dwarf2_name (tree decl
, int scope
)
7275 return lang_hooks
.decl_printable_name (decl
, scope
? 1 : 0);
7278 /* Add a new entry to .debug_pubnames if appropriate. */
7281 add_pubname (tree decl
, dw_die_ref die
)
7285 if (! TREE_PUBLIC (decl
))
7288 if (pubname_table_in_use
== pubname_table_allocated
)
7290 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
7292 = ggc_realloc (pubname_table
,
7293 (pubname_table_allocated
* sizeof (pubname_entry
)));
7294 memset (pubname_table
+ pubname_table_in_use
, 0,
7295 PUBNAME_TABLE_INCREMENT
* sizeof (pubname_entry
));
7298 p
= &pubname_table
[pubname_table_in_use
++];
7300 p
->name
= xstrdup (dwarf2_name (decl
, 1));
7303 /* Output the public names table used to speed up access to externally
7304 visible names. For now, only generate entries for externally
7305 visible procedures. */
7308 output_pubnames (void)
7311 unsigned long pubnames_length
= size_of_pubnames ();
7313 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7314 dw2_asm_output_data (4, 0xffffffff,
7315 "Initial length escape value indicating 64-bit DWARF extension");
7316 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
7317 "Length of Public Names Info");
7318 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7319 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
7321 "Offset of Compilation Unit Info");
7322 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
7323 "Compilation Unit Length");
7325 for (i
= 0; i
< pubname_table_in_use
; i
++)
7327 pubname_ref pub
= &pubname_table
[i
];
7329 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7330 gcc_assert (pub
->die
->die_mark
);
7332 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
7335 dw2_asm_output_nstring (pub
->name
, -1, "external name");
7338 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
7341 /* Add a new entry to .debug_aranges if appropriate. */
7344 add_arange (tree decl
, dw_die_ref die
)
7346 if (! DECL_SECTION_NAME (decl
))
7349 if (arange_table_in_use
== arange_table_allocated
)
7351 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
7352 arange_table
= ggc_realloc (arange_table
,
7353 (arange_table_allocated
7354 * sizeof (dw_die_ref
)));
7355 memset (arange_table
+ arange_table_in_use
, 0,
7356 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
7359 arange_table
[arange_table_in_use
++] = die
;
7362 /* Output the information that goes into the .debug_aranges table.
7363 Namely, define the beginning and ending address range of the
7364 text section generated for this compilation unit. */
7367 output_aranges (void)
7370 unsigned long aranges_length
= size_of_aranges ();
7372 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7373 dw2_asm_output_data (4, 0xffffffff,
7374 "Initial length escape value indicating 64-bit DWARF extension");
7375 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
7376 "Length of Address Ranges Info");
7377 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7378 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
7380 "Offset of Compilation Unit Info");
7381 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
7382 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7384 /* We need to align to twice the pointer size here. */
7385 if (DWARF_ARANGES_PAD_SIZE
)
7387 /* Pad using a 2 byte words so that padding is correct for any
7389 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7390 2 * DWARF2_ADDR_SIZE
);
7391 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
7392 dw2_asm_output_data (2, 0, NULL
);
7395 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
7396 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
7397 text_section_label
, "Length");
7398 if (flag_reorder_blocks_and_partition
)
7400 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
7402 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
7403 cold_text_section_label
, "Length");
7406 for (i
= 0; i
< arange_table_in_use
; i
++)
7408 dw_die_ref die
= arange_table
[i
];
7410 /* We shouldn't see aranges for DIEs outside of the main CU. */
7411 gcc_assert (die
->die_mark
);
7413 if (die
->die_tag
== DW_TAG_subprogram
)
7415 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
7417 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
7418 get_AT_low_pc (die
), "Length");
7422 /* A static variable; extract the symbol from DW_AT_location.
7423 Note that this code isn't currently hit, as we only emit
7424 aranges for functions (jason 9/23/99). */
7425 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
7426 dw_loc_descr_ref loc
;
7428 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
7431 gcc_assert (loc
->dw_loc_opc
== DW_OP_addr
);
7433 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
7434 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
7435 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
7436 get_AT_unsigned (die
, DW_AT_byte_size
),
7441 /* Output the terminator words. */
7442 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7443 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7446 /* Add a new entry to .debug_ranges. Return the offset at which it
7450 add_ranges (tree block
)
7452 unsigned int in_use
= ranges_table_in_use
;
7454 if (in_use
== ranges_table_allocated
)
7456 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
7458 = ggc_realloc (ranges_table
, (ranges_table_allocated
7459 * sizeof (struct dw_ranges_struct
)));
7460 memset (ranges_table
+ ranges_table_in_use
, 0,
7461 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
7464 ranges_table
[in_use
].block_num
= (block
? BLOCK_NUMBER (block
) : 0);
7465 ranges_table_in_use
= in_use
+ 1;
7467 return in_use
* 2 * DWARF2_ADDR_SIZE
;
7471 output_ranges (void)
7474 static const char *const start_fmt
= "Offset 0x%x";
7475 const char *fmt
= start_fmt
;
7477 for (i
= 0; i
< ranges_table_in_use
; i
++)
7479 int block_num
= ranges_table
[i
].block_num
;
7483 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7484 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7486 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
7487 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
7489 /* If all code is in the text section, then the compilation
7490 unit base address defaults to DW_AT_low_pc, which is the
7491 base of the text section. */
7492 if (!have_multiple_function_sections
)
7494 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
7496 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7497 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
7498 text_section_label
, NULL
);
7501 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
7502 compilation unit base address to zero, which allows us to
7503 use absolute addresses, and not worry about whether the
7504 target supports cross-section arithmetic. */
7507 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
7508 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7509 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
7516 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7517 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7523 /* Data structure containing information about input files. */
7526 char *path
; /* Complete file name. */
7527 char *fname
; /* File name part. */
7528 int length
; /* Length of entire string. */
7529 int file_idx
; /* Index in input file table. */
7530 int dir_idx
; /* Index in directory table. */
7533 /* Data structure containing information about directories with source
7537 char *path
; /* Path including directory name. */
7538 int length
; /* Path length. */
7539 int prefix
; /* Index of directory entry which is a prefix. */
7540 int count
; /* Number of files in this directory. */
7541 int dir_idx
; /* Index of directory used as base. */
7542 int used
; /* Used in the end? */
7545 /* Callback function for file_info comparison. We sort by looking at
7546 the directories in the path. */
7549 file_info_cmp (const void *p1
, const void *p2
)
7551 const struct file_info
*s1
= p1
;
7552 const struct file_info
*s2
= p2
;
7556 /* Take care of file names without directories. We need to make sure that
7557 we return consistent values to qsort since some will get confused if
7558 we return the same value when identical operands are passed in opposite
7559 orders. So if neither has a directory, return 0 and otherwise return
7560 1 or -1 depending on which one has the directory. */
7561 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
7562 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
7564 cp1
= (unsigned char *) s1
->path
;
7565 cp2
= (unsigned char *) s2
->path
;
7571 /* Reached the end of the first path? If so, handle like above. */
7572 if ((cp1
== (unsigned char *) s1
->fname
)
7573 || (cp2
== (unsigned char *) s2
->fname
))
7574 return ((cp2
== (unsigned char *) s2
->fname
)
7575 - (cp1
== (unsigned char *) s1
->fname
));
7577 /* Character of current path component the same? */
7578 else if (*cp1
!= *cp2
)
7583 /* Output the directory table and the file name table. We try to minimize
7584 the total amount of memory needed. A heuristic is used to avoid large
7585 slowdowns with many input files. */
7588 output_file_names (void)
7590 struct file_info
*files
;
7591 struct dir_info
*dirs
;
7600 /* Handle the case where file_table is empty. */
7601 if (VARRAY_ACTIVE_SIZE (file_table
) <= 1)
7603 dw2_asm_output_data (1, 0, "End directory table");
7604 dw2_asm_output_data (1, 0, "End file name table");
7608 /* Allocate the various arrays we need. */
7609 files
= alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (struct file_info
));
7610 dirs
= alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (struct dir_info
));
7612 /* Sort the file names. */
7613 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7617 /* Skip all leading "./". */
7618 f
= VARRAY_CHAR_PTR (file_table
, i
);
7619 while (f
[0] == '.' && f
[1] == '/')
7622 /* Create a new array entry. */
7624 files
[i
].length
= strlen (f
);
7625 files
[i
].file_idx
= i
;
7627 /* Search for the file name part. */
7628 f
= strrchr (f
, '/');
7629 files
[i
].fname
= f
== NULL
? files
[i
].path
: f
+ 1;
7632 qsort (files
+ 1, VARRAY_ACTIVE_SIZE (file_table
) - 1,
7633 sizeof (files
[0]), file_info_cmp
);
7635 /* Find all the different directories used. */
7636 dirs
[0].path
= files
[1].path
;
7637 dirs
[0].length
= files
[1].fname
- files
[1].path
;
7638 dirs
[0].prefix
= -1;
7640 dirs
[0].dir_idx
= 0;
7642 files
[1].dir_idx
= 0;
7645 for (i
= 2; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7646 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
7647 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
7648 dirs
[ndirs
- 1].length
) == 0)
7650 /* Same directory as last entry. */
7651 files
[i
].dir_idx
= ndirs
- 1;
7652 ++dirs
[ndirs
- 1].count
;
7658 /* This is a new directory. */
7659 dirs
[ndirs
].path
= files
[i
].path
;
7660 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
7661 dirs
[ndirs
].count
= 1;
7662 dirs
[ndirs
].dir_idx
= ndirs
;
7663 dirs
[ndirs
].used
= 0;
7664 files
[i
].dir_idx
= ndirs
;
7666 /* Search for a prefix. */
7667 dirs
[ndirs
].prefix
= -1;
7668 for (j
= 0; j
< ndirs
; j
++)
7669 if (dirs
[j
].length
< dirs
[ndirs
].length
7670 && dirs
[j
].length
> 1
7671 && (dirs
[ndirs
].prefix
== -1
7672 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
7673 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
7674 dirs
[ndirs
].prefix
= j
;
7679 /* Now to the actual work. We have to find a subset of the directories which
7680 allow expressing the file name using references to the directory table
7681 with the least amount of characters. We do not do an exhaustive search
7682 where we would have to check out every combination of every single
7683 possible prefix. Instead we use a heuristic which provides nearly optimal
7684 results in most cases and never is much off. */
7685 saved
= alloca (ndirs
* sizeof (int));
7686 savehere
= alloca (ndirs
* sizeof (int));
7688 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
7689 for (i
= 0; i
< ndirs
; i
++)
7694 /* We can always save some space for the current directory. But this
7695 does not mean it will be enough to justify adding the directory. */
7696 savehere
[i
] = dirs
[i
].length
;
7697 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
7699 for (j
= i
+ 1; j
< ndirs
; j
++)
7702 if (saved
[j
] < dirs
[i
].length
)
7704 /* Determine whether the dirs[i] path is a prefix of the
7709 while (k
!= -1 && k
!= (int) i
)
7714 /* Yes it is. We can possibly safe some memory but
7715 writing the filenames in dirs[j] relative to
7717 savehere
[j
] = dirs
[i
].length
;
7718 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
7723 /* Check whether we can safe enough to justify adding the dirs[i]
7725 if (total
> dirs
[i
].length
+ 1)
7727 /* It's worthwhile adding. */
7728 for (j
= i
; j
< ndirs
; j
++)
7729 if (savehere
[j
] > 0)
7731 /* Remember how much we saved for this directory so far. */
7732 saved
[j
] = savehere
[j
];
7734 /* Remember the prefix directory. */
7735 dirs
[j
].dir_idx
= i
;
7740 /* We have to emit them in the order they appear in the file_table array
7741 since the index is used in the debug info generation. To do this
7742 efficiently we generate a back-mapping of the indices first. */
7743 backmap
= alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (int));
7744 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7746 backmap
[files
[i
].file_idx
] = i
;
7748 /* Mark this directory as used. */
7749 dirs
[dirs
[files
[i
].dir_idx
].dir_idx
].used
= 1;
7752 /* That was it. We are ready to emit the information. First emit the
7753 directory name table. We have to make sure the first actually emitted
7754 directory name has index one; zero is reserved for the current working
7755 directory. Make sure we do not confuse these indices with the one for the
7756 constructed table (even though most of the time they are identical). */
7758 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
7759 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
7760 if (dirs
[i
].used
!= 0)
7762 dirs
[i
].used
= idx
++;
7763 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
7764 "Directory Entry: 0x%x", dirs
[i
].used
);
7767 dw2_asm_output_data (1, 0, "End directory table");
7769 /* Correct the index for the current working directory entry if it
7771 if (idx_offset
== 0)
7774 /* Now write all the file names. */
7775 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7777 int file_idx
= backmap
[i
];
7778 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
7780 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
7781 "File Entry: 0x%lx", (unsigned long) i
);
7783 /* Include directory index. */
7784 dw2_asm_output_data_uleb128 (dirs
[dir_idx
].used
, NULL
);
7786 /* Modification time. */
7787 dw2_asm_output_data_uleb128 (0, NULL
);
7789 /* File length in bytes. */
7790 dw2_asm_output_data_uleb128 (0, NULL
);
7793 dw2_asm_output_data (1, 0, "End file name table");
7797 /* Output the source line number correspondence information. This
7798 information goes into the .debug_line section. */
7801 output_line_info (void)
7803 char l1
[20], l2
[20], p1
[20], p2
[20];
7804 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7805 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7808 unsigned long lt_index
;
7809 unsigned long current_line
;
7812 unsigned long current_file
;
7813 unsigned long function
;
7815 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
7816 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
7817 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
7818 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
7820 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7821 dw2_asm_output_data (4, 0xffffffff,
7822 "Initial length escape value indicating 64-bit DWARF extension");
7823 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
7824 "Length of Source Line Info");
7825 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
7827 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7828 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
7829 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
7831 /* Define the architecture-dependent minimum instruction length (in
7832 bytes). In this implementation of DWARF, this field is used for
7833 information purposes only. Since GCC generates assembly language,
7834 we have no a priori knowledge of how many instruction bytes are
7835 generated for each source line, and therefore can use only the
7836 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7837 commands. Accordingly, we fix this as `1', which is "correct
7838 enough" for all architectures, and don't let the target override. */
7839 dw2_asm_output_data (1, 1,
7840 "Minimum Instruction Length");
7842 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
7843 "Default is_stmt_start flag");
7844 dw2_asm_output_data (1, DWARF_LINE_BASE
,
7845 "Line Base Value (Special Opcodes)");
7846 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
7847 "Line Range Value (Special Opcodes)");
7848 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
7849 "Special Opcode Base");
7851 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
7855 case DW_LNS_advance_pc
:
7856 case DW_LNS_advance_line
:
7857 case DW_LNS_set_file
:
7858 case DW_LNS_set_column
:
7859 case DW_LNS_fixed_advance_pc
:
7867 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
7871 /* Write out the information about the files we use. */
7872 output_file_names ();
7873 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
7875 /* We used to set the address register to the first location in the text
7876 section here, but that didn't accomplish anything since we already
7877 have a line note for the opening brace of the first function. */
7879 /* Generate the line number to PC correspondence table, encoded as
7880 a series of state machine operations. */
7884 if (cfun
&& in_cold_section_p
)
7885 strcpy (prev_line_label
, cfun
->cold_section_label
);
7887 strcpy (prev_line_label
, text_section_label
);
7888 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
7890 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
7893 /* Disable this optimization for now; GDB wants to see two line notes
7894 at the beginning of a function so it can find the end of the
7897 /* Don't emit anything for redundant notes. Just updating the
7898 address doesn't accomplish anything, because we already assume
7899 that anything after the last address is this line. */
7900 if (line_info
->dw_line_num
== current_line
7901 && line_info
->dw_file_num
== current_file
)
7905 /* Emit debug info for the address of the current line.
7907 Unfortunately, we have little choice here currently, and must always
7908 use the most general form. GCC does not know the address delta
7909 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7910 attributes which will give an upper bound on the address range. We
7911 could perhaps use length attributes to determine when it is safe to
7912 use DW_LNS_fixed_advance_pc. */
7914 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
7917 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7918 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7919 "DW_LNS_fixed_advance_pc");
7920 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7924 /* This can handle any delta. This takes
7925 4+DWARF2_ADDR_SIZE bytes. */
7926 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7927 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7928 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7929 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7932 strcpy (prev_line_label
, line_label
);
7934 /* Emit debug info for the source file of the current line, if
7935 different from the previous line. */
7936 if (line_info
->dw_file_num
!= current_file
)
7938 current_file
= line_info
->dw_file_num
;
7939 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7940 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7941 VARRAY_CHAR_PTR (file_table
,
7945 /* Emit debug info for the current line number, choosing the encoding
7946 that uses the least amount of space. */
7947 if (line_info
->dw_line_num
!= current_line
)
7949 line_offset
= line_info
->dw_line_num
- current_line
;
7950 line_delta
= line_offset
- DWARF_LINE_BASE
;
7951 current_line
= line_info
->dw_line_num
;
7952 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7953 /* This can handle deltas from -10 to 234, using the current
7954 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7956 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7957 "line %lu", current_line
);
7960 /* This can handle any delta. This takes at least 4 bytes,
7961 depending on the value being encoded. */
7962 dw2_asm_output_data (1, DW_LNS_advance_line
,
7963 "advance to line %lu", current_line
);
7964 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7965 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7969 /* We still need to start a new row, so output a copy insn. */
7970 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7973 /* Emit debug info for the address of the end of the function. */
7976 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7977 "DW_LNS_fixed_advance_pc");
7978 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
7982 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7983 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7984 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7985 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
7988 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7989 dw2_asm_output_data_uleb128 (1, NULL
);
7990 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7995 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
7997 dw_separate_line_info_ref line_info
7998 = &separate_line_info_table
[lt_index
];
8001 /* Don't emit anything for redundant notes. */
8002 if (line_info
->dw_line_num
== current_line
8003 && line_info
->dw_file_num
== current_file
8004 && line_info
->function
== function
)
8008 /* Emit debug info for the address of the current line. If this is
8009 a new function, or the first line of a function, then we need
8010 to handle it differently. */
8011 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
8013 if (function
!= line_info
->function
)
8015 function
= line_info
->function
;
8017 /* Set the address register to the first line in the function. */
8018 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8019 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8020 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8021 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8025 /* ??? See the DW_LNS_advance_pc comment above. */
8028 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
8029 "DW_LNS_fixed_advance_pc");
8030 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
8034 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8035 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8036 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8037 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8041 strcpy (prev_line_label
, line_label
);
8043 /* Emit debug info for the source file of the current line, if
8044 different from the previous line. */
8045 if (line_info
->dw_file_num
!= current_file
)
8047 current_file
= line_info
->dw_file_num
;
8048 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
8049 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
8050 VARRAY_CHAR_PTR (file_table
,
8054 /* Emit debug info for the current line number, choosing the encoding
8055 that uses the least amount of space. */
8056 if (line_info
->dw_line_num
!= current_line
)
8058 line_offset
= line_info
->dw_line_num
- current_line
;
8059 line_delta
= line_offset
- DWARF_LINE_BASE
;
8060 current_line
= line_info
->dw_line_num
;
8061 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
8062 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
8063 "line %lu", current_line
);
8066 dw2_asm_output_data (1, DW_LNS_advance_line
,
8067 "advance to line %lu", current_line
);
8068 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
8069 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8073 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8081 /* If we're done with a function, end its sequence. */
8082 if (lt_index
== separate_line_info_table_in_use
8083 || separate_line_info_table
[lt_index
].function
!= function
)
8088 /* Emit debug info for the address of the end of the function. */
8089 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
8092 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
8093 "DW_LNS_fixed_advance_pc");
8094 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
8098 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8099 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8100 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8101 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8104 /* Output the marker for the end of this sequence. */
8105 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8106 dw2_asm_output_data_uleb128 (1, NULL
);
8107 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
8111 /* Output the marker for the end of the line number info. */
8112 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
8115 /* Given a pointer to a tree node for some base type, return a pointer to
8116 a DIE that describes the given type.
8118 This routine must only be called for GCC type nodes that correspond to
8119 Dwarf base (fundamental) types. */
8122 base_type_die (tree type
)
8124 dw_die_ref base_type_result
;
8125 enum dwarf_type encoding
;
8127 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
8130 switch (TREE_CODE (type
))
8133 if (TYPE_STRING_FLAG (type
))
8135 if (TYPE_UNSIGNED (type
))
8136 encoding
= DW_ATE_unsigned_char
;
8138 encoding
= DW_ATE_signed_char
;
8140 else if (TYPE_UNSIGNED (type
))
8141 encoding
= DW_ATE_unsigned
;
8143 encoding
= DW_ATE_signed
;
8147 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
8148 encoding
= DW_ATE_decimal_float
;
8150 encoding
= DW_ATE_float
;
8153 /* Dwarf2 doesn't know anything about complex ints, so use
8154 a user defined type for it. */
8156 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
8157 encoding
= DW_ATE_complex_float
;
8159 encoding
= DW_ATE_lo_user
;
8163 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8164 encoding
= DW_ATE_boolean
;
8168 /* No other TREE_CODEs are Dwarf fundamental types. */
8172 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
8174 /* This probably indicates a bug. */
8175 if (! TYPE_NAME (type
))
8176 add_name_attribute (base_type_result
, "__unknown__");
8178 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
8179 int_size_in_bytes (type
));
8180 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
8182 return base_type_result
;
8185 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
8186 the Dwarf "root" type for the given input type. The Dwarf "root" type of
8187 a given type is generally the same as the given type, except that if the
8188 given type is a pointer or reference type, then the root type of the given
8189 type is the root type of the "basis" type for the pointer or reference
8190 type. (This definition of the "root" type is recursive.) Also, the root
8191 type of a `const' qualified type or a `volatile' qualified type is the
8192 root type of the given type without the qualifiers. */
8195 root_type (tree type
)
8197 if (TREE_CODE (type
) == ERROR_MARK
)
8198 return error_mark_node
;
8200 switch (TREE_CODE (type
))
8203 return error_mark_node
;
8206 case REFERENCE_TYPE
:
8207 return type_main_variant (root_type (TREE_TYPE (type
)));
8210 return type_main_variant (type
);
8214 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8215 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8218 is_base_type (tree type
)
8220 switch (TREE_CODE (type
))
8233 case QUAL_UNION_TYPE
:
8238 case REFERENCE_TYPE
:
8251 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8252 node, return the size in bits for the type if it is a constant, or else
8253 return the alignment for the type if the type's size is not constant, or
8254 else return BITS_PER_WORD if the type actually turns out to be an
8257 static inline unsigned HOST_WIDE_INT
8258 simple_type_size_in_bits (tree type
)
8260 if (TREE_CODE (type
) == ERROR_MARK
)
8261 return BITS_PER_WORD
;
8262 else if (TYPE_SIZE (type
) == NULL_TREE
)
8264 else if (host_integerp (TYPE_SIZE (type
), 1))
8265 return tree_low_cst (TYPE_SIZE (type
), 1);
8267 return TYPE_ALIGN (type
);
8270 /* Return true if the debug information for the given type should be
8271 emitted as a subrange type. */
8274 is_subrange_type (tree type
)
8276 tree subtype
= TREE_TYPE (type
);
8278 /* Subrange types are identified by the fact that they are integer
8279 types, and that they have a subtype which is either an integer type
8280 or an enumeral type. */
8282 if (TREE_CODE (type
) != INTEGER_TYPE
8283 || subtype
== NULL_TREE
)
8286 if (TREE_CODE (subtype
) != INTEGER_TYPE
8287 && TREE_CODE (subtype
) != ENUMERAL_TYPE
)
8290 if (TREE_CODE (type
) == TREE_CODE (subtype
)
8291 && int_size_in_bytes (type
) == int_size_in_bytes (subtype
)
8292 && TYPE_MIN_VALUE (type
) != NULL
8293 && TYPE_MIN_VALUE (subtype
) != NULL
8294 && tree_int_cst_equal (TYPE_MIN_VALUE (type
), TYPE_MIN_VALUE (subtype
))
8295 && TYPE_MAX_VALUE (type
) != NULL
8296 && TYPE_MAX_VALUE (subtype
) != NULL
8297 && tree_int_cst_equal (TYPE_MAX_VALUE (type
), TYPE_MAX_VALUE (subtype
)))
8299 /* The type and its subtype have the same representation. If in
8300 addition the two types also have the same name, then the given
8301 type is not a subrange type, but rather a plain base type. */
8302 /* FIXME: brobecker/2004-03-22:
8303 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8304 therefore be sufficient to check the TYPE_SIZE node pointers
8305 rather than checking the actual size. Unfortunately, we have
8306 found some cases, such as in the Ada "integer" type, where
8307 this is not the case. Until this problem is solved, we need to
8308 keep checking the actual size. */
8309 tree type_name
= TYPE_NAME (type
);
8310 tree subtype_name
= TYPE_NAME (subtype
);
8312 if (type_name
!= NULL
&& TREE_CODE (type_name
) == TYPE_DECL
)
8313 type_name
= DECL_NAME (type_name
);
8315 if (subtype_name
!= NULL
&& TREE_CODE (subtype_name
) == TYPE_DECL
)
8316 subtype_name
= DECL_NAME (subtype_name
);
8318 if (type_name
== subtype_name
)
8325 /* Given a pointer to a tree node for a subrange type, return a pointer
8326 to a DIE that describes the given type. */
8329 subrange_type_die (tree type
, dw_die_ref context_die
)
8331 dw_die_ref subrange_die
;
8332 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
8334 if (context_die
== NULL
)
8335 context_die
= comp_unit_die
;
8337 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
8339 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
8341 /* The size of the subrange type and its base type do not match,
8342 so we need to generate a size attribute for the subrange type. */
8343 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
8346 if (TYPE_MIN_VALUE (type
) != NULL
)
8347 add_bound_info (subrange_die
, DW_AT_lower_bound
,
8348 TYPE_MIN_VALUE (type
));
8349 if (TYPE_MAX_VALUE (type
) != NULL
)
8350 add_bound_info (subrange_die
, DW_AT_upper_bound
,
8351 TYPE_MAX_VALUE (type
));
8353 return subrange_die
;
8356 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8357 entry that chains various modifiers in front of the given type. */
8360 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
8361 dw_die_ref context_die
)
8363 enum tree_code code
= TREE_CODE (type
);
8364 dw_die_ref mod_type_die
;
8365 dw_die_ref sub_die
= NULL
;
8366 tree item_type
= NULL
;
8367 tree qualified_type
;
8370 if (code
== ERROR_MARK
)
8373 /* See if we already have the appropriately qualified variant of
8376 = get_qualified_type (type
,
8377 ((is_const_type
? TYPE_QUAL_CONST
: 0)
8378 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
8380 /* If we do, then we can just use its DIE, if it exists. */
8383 mod_type_die
= lookup_type_die (qualified_type
);
8385 return mod_type_die
;
8388 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
8390 /* Handle C typedef types. */
8391 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
))
8393 tree dtype
= TREE_TYPE (name
);
8395 if (qualified_type
== dtype
)
8397 /* For a named type, use the typedef. */
8398 gen_type_die (qualified_type
, context_die
);
8399 return lookup_type_die (qualified_type
);
8401 else if (DECL_ORIGINAL_TYPE (name
)
8402 && (is_const_type
< TYPE_READONLY (dtype
)
8403 || is_volatile_type
< TYPE_VOLATILE (dtype
)))
8404 /* cv-unqualified version of named type. Just use the unnamed
8405 type to which it refers. */
8406 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
8407 is_const_type
, is_volatile_type
,
8409 /* Else cv-qualified version of named type; fall through. */
8414 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
8415 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
8417 else if (is_volatile_type
)
8419 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
8420 sub_die
= modified_type_die (type
, 0, 0, context_die
);
8422 else if (code
== POINTER_TYPE
)
8424 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
8425 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
8426 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
8427 item_type
= TREE_TYPE (type
);
8429 else if (code
== REFERENCE_TYPE
)
8431 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
8432 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
8433 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
8434 item_type
= TREE_TYPE (type
);
8436 else if (is_subrange_type (type
))
8438 mod_type_die
= subrange_type_die (type
, context_die
);
8439 item_type
= TREE_TYPE (type
);
8441 else if (is_base_type (type
))
8442 mod_type_die
= base_type_die (type
);
8445 gen_type_die (type
, context_die
);
8447 /* We have to get the type_main_variant here (and pass that to the
8448 `lookup_type_die' routine) because the ..._TYPE node we have
8449 might simply be a *copy* of some original type node (where the
8450 copy was created to help us keep track of typedef names) and
8451 that copy might have a different TYPE_UID from the original
8453 if (TREE_CODE (type
) != VECTOR_TYPE
)
8454 return lookup_type_die (type_main_variant (type
));
8456 /* Vectors have the debugging information in the type,
8457 not the main variant. */
8458 return lookup_type_die (type
);
8461 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
8462 don't output a DW_TAG_typedef, since there isn't one in the
8463 user's program; just attach a DW_AT_name to the type. */
8465 && (TREE_CODE (name
) != TYPE_DECL
|| TREE_TYPE (name
) == qualified_type
))
8467 if (TREE_CODE (name
) == TYPE_DECL
)
8468 /* Could just call add_name_and_src_coords_attributes here,
8469 but since this is a builtin type it doesn't have any
8470 useful source coordinates anyway. */
8471 name
= DECL_NAME (name
);
8472 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
8476 equate_type_number_to_die (qualified_type
, mod_type_die
);
8479 /* We must do this after the equate_type_number_to_die call, in case
8480 this is a recursive type. This ensures that the modified_type_die
8481 recursion will terminate even if the type is recursive. Recursive
8482 types are possible in Ada. */
8483 sub_die
= modified_type_die (item_type
,
8484 TYPE_READONLY (item_type
),
8485 TYPE_VOLATILE (item_type
),
8488 if (sub_die
!= NULL
)
8489 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
8491 return mod_type_die
;
8494 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8495 an enumerated type. */
8498 type_is_enum (tree type
)
8500 return TREE_CODE (type
) == ENUMERAL_TYPE
;
8503 /* Return the DBX register number described by a given RTL node. */
8506 dbx_reg_number (rtx rtl
)
8508 unsigned regno
= REGNO (rtl
);
8510 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
8512 #ifdef LEAF_REG_REMAP
8513 regno
= LEAF_REG_REMAP (regno
);
8516 return DBX_REGISTER_NUMBER (regno
);
8519 /* Optionally add a DW_OP_piece term to a location description expression.
8520 DW_OP_piece is only added if the location description expression already
8521 doesn't end with DW_OP_piece. */
8524 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
8526 dw_loc_descr_ref loc
;
8528 if (*list_head
!= NULL
)
8530 /* Find the end of the chain. */
8531 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
8534 if (loc
->dw_loc_opc
!= DW_OP_piece
)
8535 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
8539 /* Return a location descriptor that designates a machine register or
8540 zero if there is none. */
8542 static dw_loc_descr_ref
8543 reg_loc_descriptor (rtx rtl
)
8547 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
8550 regs
= targetm
.dwarf_register_span (rtl
);
8552 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
8553 return multiple_reg_loc_descriptor (rtl
, regs
);
8555 return one_reg_loc_descriptor (dbx_reg_number (rtl
));
8558 /* Return a location descriptor that designates a machine register for
8559 a given hard register number. */
8561 static dw_loc_descr_ref
8562 one_reg_loc_descriptor (unsigned int regno
)
8565 return new_loc_descr (DW_OP_reg0
+ regno
, 0, 0);
8567 return new_loc_descr (DW_OP_regx
, regno
, 0);
8570 /* Given an RTL of a register, return a location descriptor that
8571 designates a value that spans more than one register. */
8573 static dw_loc_descr_ref
8574 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
)
8578 dw_loc_descr_ref loc_result
= NULL
;
8581 #ifdef LEAF_REG_REMAP
8582 reg
= LEAF_REG_REMAP (reg
);
8584 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
8585 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
8587 /* Simple, contiguous registers. */
8588 if (regs
== NULL_RTX
)
8590 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
8597 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
));
8598 add_loc_descr (&loc_result
, t
);
8599 add_loc_descr_op_piece (&loc_result
, size
);
8605 /* Now onto stupid register sets in non contiguous locations. */
8607 gcc_assert (GET_CODE (regs
) == PARALLEL
);
8609 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8612 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
8616 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)));
8617 add_loc_descr (&loc_result
, t
);
8618 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8619 add_loc_descr_op_piece (&loc_result
, size
);
8624 /* Return a location descriptor that designates a constant. */
8626 static dw_loc_descr_ref
8627 int_loc_descriptor (HOST_WIDE_INT i
)
8629 enum dwarf_location_atom op
;
8631 /* Pick the smallest representation of a constant, rather than just
8632 defaulting to the LEB encoding. */
8636 op
= DW_OP_lit0
+ i
;
8639 else if (i
<= 0xffff)
8641 else if (HOST_BITS_PER_WIDE_INT
== 32
8651 else if (i
>= -0x8000)
8653 else if (HOST_BITS_PER_WIDE_INT
== 32
8654 || i
>= -0x80000000)
8660 return new_loc_descr (op
, i
, 0);
8663 /* Return a location descriptor that designates a base+offset location. */
8665 static dw_loc_descr_ref
8666 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
)
8670 /* We only use "frame base" when we're sure we're talking about the
8671 post-prologue local stack frame. We do this by *not* running
8672 register elimination until this point, and recognizing the special
8673 argument pointer and soft frame pointer rtx's. */
8674 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
8676 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
8680 if (GET_CODE (elim
) == PLUS
)
8682 offset
+= INTVAL (XEXP (elim
, 1));
8683 elim
= XEXP (elim
, 0);
8685 gcc_assert (elim
== (frame_pointer_needed
? hard_frame_pointer_rtx
8686 : stack_pointer_rtx
));
8687 offset
+= frame_pointer_fb_offset
;
8689 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
8693 regno
= dbx_reg_number (reg
);
8695 return new_loc_descr (DW_OP_breg0
+ regno
, offset
, 0);
8697 return new_loc_descr (DW_OP_bregx
, regno
, offset
);
8700 /* Return true if this RTL expression describes a base+offset calculation. */
8703 is_based_loc (rtx rtl
)
8705 return (GET_CODE (rtl
) == PLUS
8706 && ((REG_P (XEXP (rtl
, 0))
8707 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
8708 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
8711 /* The following routine converts the RTL for a variable or parameter
8712 (resident in memory) into an equivalent Dwarf representation of a
8713 mechanism for getting the address of that same variable onto the top of a
8714 hypothetical "address evaluation" stack.
8716 When creating memory location descriptors, we are effectively transforming
8717 the RTL for a memory-resident object into its Dwarf postfix expression
8718 equivalent. This routine recursively descends an RTL tree, turning
8719 it into Dwarf postfix code as it goes.
8721 MODE is the mode of the memory reference, needed to handle some
8722 autoincrement addressing modes.
8724 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
8725 location list for RTL.
8727 Return 0 if we can't represent the location. */
8729 static dw_loc_descr_ref
8730 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
)
8732 dw_loc_descr_ref mem_loc_result
= NULL
;
8733 enum dwarf_location_atom op
;
8735 /* Note that for a dynamically sized array, the location we will generate a
8736 description of here will be the lowest numbered location which is
8737 actually within the array. That's *not* necessarily the same as the
8738 zeroth element of the array. */
8740 rtl
= targetm
.delegitimize_address (rtl
);
8742 switch (GET_CODE (rtl
))
8747 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8748 just fall into the SUBREG code. */
8750 /* ... fall through ... */
8753 /* The case of a subreg may arise when we have a local (register)
8754 variable or a formal (register) parameter which doesn't quite fill
8755 up an entire register. For now, just assume that it is
8756 legitimate to make the Dwarf info refer to the whole register which
8757 contains the given subreg. */
8758 rtl
= XEXP (rtl
, 0);
8760 /* ... fall through ... */
8763 /* Whenever a register number forms a part of the description of the
8764 method for calculating the (dynamic) address of a memory resident
8765 object, DWARF rules require the register number be referred to as
8766 a "base register". This distinction is not based in any way upon
8767 what category of register the hardware believes the given register
8768 belongs to. This is strictly DWARF terminology we're dealing with
8769 here. Note that in cases where the location of a memory-resident
8770 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8771 OP_CONST (0)) the actual DWARF location descriptor that we generate
8772 may just be OP_BASEREG (basereg). This may look deceptively like
8773 the object in question was allocated to a register (rather than in
8774 memory) so DWARF consumers need to be aware of the subtle
8775 distinction between OP_REG and OP_BASEREG. */
8776 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
8777 mem_loc_result
= based_loc_descr (rtl
, 0);
8781 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
8782 if (mem_loc_result
!= 0)
8783 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
8787 rtl
= XEXP (rtl
, 1);
8789 /* ... fall through ... */
8792 /* Some ports can transform a symbol ref into a label ref, because
8793 the symbol ref is too far away and has to be dumped into a constant
8797 /* Alternatively, the symbol in the constant pool might be referenced
8798 by a different symbol. */
8799 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
8802 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
8804 if (GET_CODE (tmp
) == SYMBOL_REF
)
8807 if (CONSTANT_POOL_ADDRESS_P (tmp
))
8808 get_pool_constant_mark (tmp
, &marked
);
8813 /* If all references to this pool constant were optimized away,
8814 it was not output and thus we can't represent it.
8815 FIXME: might try to use DW_OP_const_value here, though
8816 DW_OP_piece complicates it. */
8821 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
8822 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8823 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8824 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
8828 /* Extract the PLUS expression nested inside and fall into
8830 rtl
= XEXP (rtl
, 1);
8835 /* Turn these into a PLUS expression and fall into the PLUS code
8837 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
8838 GEN_INT (GET_CODE (rtl
) == PRE_INC
8839 ? GET_MODE_UNIT_SIZE (mode
)
8840 : -GET_MODE_UNIT_SIZE (mode
)));
8842 /* ... fall through ... */
8846 if (is_based_loc (rtl
))
8847 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
8848 INTVAL (XEXP (rtl
, 1)));
8851 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
8852 if (mem_loc_result
== 0)
8855 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
8856 && INTVAL (XEXP (rtl
, 1)) >= 0)
8857 add_loc_descr (&mem_loc_result
,
8858 new_loc_descr (DW_OP_plus_uconst
,
8859 INTVAL (XEXP (rtl
, 1)), 0));
8862 add_loc_descr (&mem_loc_result
,
8863 mem_loc_descriptor (XEXP (rtl
, 1), mode
));
8864 add_loc_descr (&mem_loc_result
,
8865 new_loc_descr (DW_OP_plus
, 0, 0));
8870 /* If a pseudo-reg is optimized away, it is possible for it to
8871 be replaced with a MEM containing a multiply or shift. */
8890 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
8891 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
);
8893 if (op0
== 0 || op1
== 0)
8896 mem_loc_result
= op0
;
8897 add_loc_descr (&mem_loc_result
, op1
);
8898 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
8903 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
8910 return mem_loc_result
;
8913 /* Return a descriptor that describes the concatenation of two locations.
8914 This is typically a complex variable. */
8916 static dw_loc_descr_ref
8917 concat_loc_descriptor (rtx x0
, rtx x1
)
8919 dw_loc_descr_ref cc_loc_result
= NULL
;
8920 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
);
8921 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
);
8923 if (x0_ref
== 0 || x1_ref
== 0)
8926 cc_loc_result
= x0_ref
;
8927 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
8929 add_loc_descr (&cc_loc_result
, x1_ref
);
8930 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
8932 return cc_loc_result
;
8935 /* Output a proper Dwarf location descriptor for a variable or parameter
8936 which is either allocated in a register or in a memory location. For a
8937 register, we just generate an OP_REG and the register number. For a
8938 memory location we provide a Dwarf postfix expression describing how to
8939 generate the (dynamic) address of the object onto the address stack.
8941 If we don't know how to describe it, return 0. */
8943 static dw_loc_descr_ref
8944 loc_descriptor (rtx rtl
)
8946 dw_loc_descr_ref loc_result
= NULL
;
8948 switch (GET_CODE (rtl
))
8951 /* The case of a subreg may arise when we have a local (register)
8952 variable or a formal (register) parameter which doesn't quite fill
8953 up an entire register. For now, just assume that it is
8954 legitimate to make the Dwarf info refer to the whole register which
8955 contains the given subreg. */
8956 rtl
= SUBREG_REG (rtl
);
8958 /* ... fall through ... */
8961 loc_result
= reg_loc_descriptor (rtl
);
8965 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
8969 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
8974 if (GET_CODE (XEXP (rtl
, 1)) != PARALLEL
)
8976 loc_result
= loc_descriptor (XEXP (XEXP (rtl
, 1), 0));
8980 rtl
= XEXP (rtl
, 1);
8985 rtvec par_elems
= XVEC (rtl
, 0);
8986 int num_elem
= GET_NUM_ELEM (par_elems
);
8987 enum machine_mode mode
;
8990 /* Create the first one, so we have something to add to. */
8991 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0));
8992 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
8993 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
8994 for (i
= 1; i
< num_elem
; i
++)
8996 dw_loc_descr_ref temp
;
8998 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0));
8999 add_loc_descr (&loc_result
, temp
);
9000 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
9001 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
9013 /* Similar, but generate the descriptor from trees instead of rtl. This comes
9014 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
9015 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
9016 top-level invocation, and we require the address of LOC; is 0 if we require
9017 the value of LOC. */
9019 static dw_loc_descr_ref
9020 loc_descriptor_from_tree_1 (tree loc
, int want_address
)
9022 dw_loc_descr_ref ret
, ret1
;
9023 int have_address
= 0;
9024 enum dwarf_location_atom op
;
9026 /* ??? Most of the time we do not take proper care for sign/zero
9027 extending the values properly. Hopefully this won't be a real
9030 switch (TREE_CODE (loc
))
9035 case PLACEHOLDER_EXPR
:
9036 /* This case involves extracting fields from an object to determine the
9037 position of other fields. We don't try to encode this here. The
9038 only user of this is Ada, which encodes the needed information using
9039 the names of types. */
9045 case PREINCREMENT_EXPR
:
9046 case PREDECREMENT_EXPR
:
9047 case POSTINCREMENT_EXPR
:
9048 case POSTDECREMENT_EXPR
:
9049 /* There are no opcodes for these operations. */
9053 /* If we already want an address, there's nothing we can do. */
9057 /* Otherwise, process the argument and look for the address. */
9058 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 1);
9061 if (DECL_THREAD_LOCAL_P (loc
))
9065 /* If this is not defined, we have no way to emit the data. */
9066 if (!targetm
.asm_out
.output_dwarf_dtprel
)
9069 /* The way DW_OP_GNU_push_tls_address is specified, we can only
9070 look up addresses of objects in the current module. */
9071 if (DECL_EXTERNAL (loc
))
9074 rtl
= rtl_for_decl_location (loc
);
9075 if (rtl
== NULL_RTX
)
9080 rtl
= XEXP (rtl
, 0);
9081 if (! CONSTANT_P (rtl
))
9084 ret
= new_loc_descr (INTERNAL_DW_OP_tls_addr
, 0, 0);
9085 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
9086 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
9088 ret1
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
9089 add_loc_descr (&ret
, ret1
);
9097 if (DECL_HAS_VALUE_EXPR_P (loc
))
9098 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc
),
9104 rtx rtl
= rtl_for_decl_location (loc
);
9106 if (rtl
== NULL_RTX
)
9108 else if (GET_CODE (rtl
) == CONST_INT
)
9110 HOST_WIDE_INT val
= INTVAL (rtl
);
9111 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
9112 val
&= GET_MODE_MASK (DECL_MODE (loc
));
9113 ret
= int_loc_descriptor (val
);
9115 else if (GET_CODE (rtl
) == CONST_STRING
)
9117 else if (CONSTANT_P (rtl
))
9119 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
9120 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
9121 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
9125 enum machine_mode mode
;
9127 /* Certain constructs can only be represented at top-level. */
9128 if (want_address
== 2)
9129 return loc_descriptor (rtl
);
9131 mode
= GET_MODE (rtl
);
9134 rtl
= XEXP (rtl
, 0);
9137 ret
= mem_loc_descriptor (rtl
, mode
);
9143 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9148 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
);
9152 case NON_LVALUE_EXPR
:
9153 case VIEW_CONVERT_EXPR
:
9156 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
);
9161 case ARRAY_RANGE_REF
:
9164 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
9165 enum machine_mode mode
;
9167 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
9169 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
9170 &unsignedp
, &volatilep
, false);
9175 ret
= loc_descriptor_from_tree_1 (obj
, 1);
9177 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
9180 if (offset
!= NULL_TREE
)
9182 /* Variable offset. */
9183 add_loc_descr (&ret
, loc_descriptor_from_tree_1 (offset
, 0));
9184 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
9187 bytepos
= bitpos
/ BITS_PER_UNIT
;
9189 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
9190 else if (bytepos
< 0)
9192 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
9193 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
9201 if (host_integerp (loc
, 0))
9202 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
9209 /* Get an RTL for this, if something has been emitted. */
9210 rtx rtl
= lookup_constant_def (loc
);
9211 enum machine_mode mode
;
9213 if (!rtl
|| !MEM_P (rtl
))
9215 mode
= GET_MODE (rtl
);
9216 rtl
= XEXP (rtl
, 0);
9217 ret
= mem_loc_descriptor (rtl
, mode
);
9222 case TRUTH_AND_EXPR
:
9223 case TRUTH_ANDIF_EXPR
:
9228 case TRUTH_XOR_EXPR
:
9234 case TRUTH_ORIF_EXPR
:
9239 case FLOOR_DIV_EXPR
:
9241 case ROUND_DIV_EXPR
:
9242 case TRUNC_DIV_EXPR
:
9250 case FLOOR_MOD_EXPR
:
9252 case ROUND_MOD_EXPR
:
9253 case TRUNC_MOD_EXPR
:
9266 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
9270 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
9271 && host_integerp (TREE_OPERAND (loc
, 1), 0))
9273 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9277 add_loc_descr (&ret
,
9278 new_loc_descr (DW_OP_plus_uconst
,
9279 tree_low_cst (TREE_OPERAND (loc
, 1),
9289 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9296 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9303 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9310 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9325 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9326 ret1
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
9327 if (ret
== 0 || ret1
== 0)
9330 add_loc_descr (&ret
, ret1
);
9331 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
9334 case TRUTH_NOT_EXPR
:
9348 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9352 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
9358 const enum tree_code code
=
9359 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
9361 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
9362 build2 (code
, integer_type_node
,
9363 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
9364 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
9367 /* ... fall through ... */
9371 dw_loc_descr_ref lhs
9372 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
9373 dw_loc_descr_ref rhs
9374 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 2), 0);
9375 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
9377 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9378 if (ret
== 0 || lhs
== 0 || rhs
== 0)
9381 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
9382 add_loc_descr (&ret
, bra_node
);
9384 add_loc_descr (&ret
, rhs
);
9385 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
9386 add_loc_descr (&ret
, jump_node
);
9388 add_loc_descr (&ret
, lhs
);
9389 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
9390 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
9392 /* ??? Need a node to point the skip at. Use a nop. */
9393 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
9394 add_loc_descr (&ret
, tmp
);
9395 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
9396 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
9400 case FIX_TRUNC_EXPR
:
9402 case FIX_FLOOR_EXPR
:
9403 case FIX_ROUND_EXPR
:
9407 /* Leave front-end specific codes as simply unknown. This comes
9408 up, for instance, with the C STMT_EXPR. */
9409 if ((unsigned int) TREE_CODE (loc
)
9410 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
9413 #ifdef ENABLE_CHECKING
9414 /* Otherwise this is a generic code; we should just lists all of
9415 these explicitly. We forgot one. */
9418 /* In a release build, we want to degrade gracefully: better to
9419 generate incomplete debugging information than to crash. */
9424 /* Show if we can't fill the request for an address. */
9425 if (want_address
&& !have_address
)
9428 /* If we've got an address and don't want one, dereference. */
9429 if (!want_address
&& have_address
&& ret
)
9431 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
9433 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
9435 else if (size
== DWARF2_ADDR_SIZE
)
9438 op
= DW_OP_deref_size
;
9440 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
9446 static inline dw_loc_descr_ref
9447 loc_descriptor_from_tree (tree loc
)
9449 return loc_descriptor_from_tree_1 (loc
, 2);
9452 /* Given a value, round it up to the lowest multiple of `boundary'
9453 which is not less than the value itself. */
9455 static inline HOST_WIDE_INT
9456 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
9458 return (((value
+ boundary
- 1) / boundary
) * boundary
);
9461 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9462 pointer to the declared type for the relevant field variable, or return
9463 `integer_type_node' if the given node turns out to be an
9467 field_type (tree decl
)
9471 if (TREE_CODE (decl
) == ERROR_MARK
)
9472 return integer_type_node
;
9474 type
= DECL_BIT_FIELD_TYPE (decl
);
9475 if (type
== NULL_TREE
)
9476 type
= TREE_TYPE (decl
);
9481 /* Given a pointer to a tree node, return the alignment in bits for
9482 it, or else return BITS_PER_WORD if the node actually turns out to
9483 be an ERROR_MARK node. */
9485 static inline unsigned
9486 simple_type_align_in_bits (tree type
)
9488 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
9491 static inline unsigned
9492 simple_decl_align_in_bits (tree decl
)
9494 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
9497 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9498 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9499 or return 0 if we are unable to determine what that offset is, either
9500 because the argument turns out to be a pointer to an ERROR_MARK node, or
9501 because the offset is actually variable. (We can't handle the latter case
9504 static HOST_WIDE_INT
9505 field_byte_offset (tree decl
)
9507 unsigned int type_align_in_bits
;
9508 unsigned int decl_align_in_bits
;
9509 unsigned HOST_WIDE_INT type_size_in_bits
;
9510 HOST_WIDE_INT object_offset_in_bits
;
9512 tree field_size_tree
;
9513 HOST_WIDE_INT bitpos_int
;
9514 HOST_WIDE_INT deepest_bitpos
;
9515 unsigned HOST_WIDE_INT field_size_in_bits
;
9517 if (TREE_CODE (decl
) == ERROR_MARK
)
9520 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
9522 type
= field_type (decl
);
9523 field_size_tree
= DECL_SIZE (decl
);
9525 /* The size could be unspecified if there was an error, or for
9526 a flexible array member. */
9527 if (! field_size_tree
)
9528 field_size_tree
= bitsize_zero_node
;
9530 /* We cannot yet cope with fields whose positions are variable, so
9531 for now, when we see such things, we simply return 0. Someday, we may
9532 be able to handle such cases, but it will be damn difficult. */
9533 if (! host_integerp (bit_position (decl
), 0))
9536 bitpos_int
= int_bit_position (decl
);
9538 /* If we don't know the size of the field, pretend it's a full word. */
9539 if (host_integerp (field_size_tree
, 1))
9540 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
9542 field_size_in_bits
= BITS_PER_WORD
;
9544 type_size_in_bits
= simple_type_size_in_bits (type
);
9545 type_align_in_bits
= simple_type_align_in_bits (type
);
9546 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
9548 /* The GCC front-end doesn't make any attempt to keep track of the starting
9549 bit offset (relative to the start of the containing structure type) of the
9550 hypothetical "containing object" for a bit-field. Thus, when computing
9551 the byte offset value for the start of the "containing object" of a
9552 bit-field, we must deduce this information on our own. This can be rather
9553 tricky to do in some cases. For example, handling the following structure
9554 type definition when compiling for an i386/i486 target (which only aligns
9555 long long's to 32-bit boundaries) can be very tricky:
9557 struct S { int field1; long long field2:31; };
9559 Fortunately, there is a simple rule-of-thumb which can be used in such
9560 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
9561 structure shown above. It decides to do this based upon one simple rule
9562 for bit-field allocation. GCC allocates each "containing object" for each
9563 bit-field at the first (i.e. lowest addressed) legitimate alignment
9564 boundary (based upon the required minimum alignment for the declared type
9565 of the field) which it can possibly use, subject to the condition that
9566 there is still enough available space remaining in the containing object
9567 (when allocated at the selected point) to fully accommodate all of the
9568 bits of the bit-field itself.
9570 This simple rule makes it obvious why GCC allocates 8 bytes for each
9571 object of the structure type shown above. When looking for a place to
9572 allocate the "containing object" for `field2', the compiler simply tries
9573 to allocate a 64-bit "containing object" at each successive 32-bit
9574 boundary (starting at zero) until it finds a place to allocate that 64-
9575 bit field such that at least 31 contiguous (and previously unallocated)
9576 bits remain within that selected 64 bit field. (As it turns out, for the
9577 example above, the compiler finds it is OK to allocate the "containing
9578 object" 64-bit field at bit-offset zero within the structure type.)
9580 Here we attempt to work backwards from the limited set of facts we're
9581 given, and we try to deduce from those facts, where GCC must have believed
9582 that the containing object started (within the structure type). The value
9583 we deduce is then used (by the callers of this routine) to generate
9584 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
9585 and, in the case of DW_AT_location, regular fields as well). */
9587 /* Figure out the bit-distance from the start of the structure to the
9588 "deepest" bit of the bit-field. */
9589 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
9591 /* This is the tricky part. Use some fancy footwork to deduce where the
9592 lowest addressed bit of the containing object must be. */
9593 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
9595 /* Round up to type_align by default. This works best for bitfields. */
9596 object_offset_in_bits
+= type_align_in_bits
- 1;
9597 object_offset_in_bits
/= type_align_in_bits
;
9598 object_offset_in_bits
*= type_align_in_bits
;
9600 if (object_offset_in_bits
> bitpos_int
)
9602 /* Sigh, the decl must be packed. */
9603 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
9605 /* Round up to decl_align instead. */
9606 object_offset_in_bits
+= decl_align_in_bits
- 1;
9607 object_offset_in_bits
/= decl_align_in_bits
;
9608 object_offset_in_bits
*= decl_align_in_bits
;
9611 return object_offset_in_bits
/ BITS_PER_UNIT
;
9614 /* The following routines define various Dwarf attributes and any data
9615 associated with them. */
9617 /* Add a location description attribute value to a DIE.
9619 This emits location attributes suitable for whole variables and
9620 whole parameters. Note that the location attributes for struct fields are
9621 generated by the routine `data_member_location_attribute' below. */
9624 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9625 dw_loc_descr_ref descr
)
9628 add_AT_loc (die
, attr_kind
, descr
);
9631 /* Attach the specialized form of location attribute used for data members of
9632 struct and union types. In the special case of a FIELD_DECL node which
9633 represents a bit-field, the "offset" part of this special location
9634 descriptor must indicate the distance in bytes from the lowest-addressed
9635 byte of the containing struct or union type to the lowest-addressed byte of
9636 the "containing object" for the bit-field. (See the `field_byte_offset'
9639 For any given bit-field, the "containing object" is a hypothetical object
9640 (of some integral or enum type) within which the given bit-field lives. The
9641 type of this hypothetical "containing object" is always the same as the
9642 declared type of the individual bit-field itself (for GCC anyway... the
9643 DWARF spec doesn't actually mandate this). Note that it is the size (in
9644 bytes) of the hypothetical "containing object" which will be given in the
9645 DW_AT_byte_size attribute for this bit-field. (See the
9646 `byte_size_attribute' function below.) It is also used when calculating the
9647 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
9651 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
9653 HOST_WIDE_INT offset
;
9654 dw_loc_descr_ref loc_descr
= 0;
9656 if (TREE_CODE (decl
) == TREE_BINFO
)
9658 /* We're working on the TAG_inheritance for a base class. */
9659 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
9661 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
9662 aren't at a fixed offset from all (sub)objects of the same
9663 type. We need to extract the appropriate offset from our
9664 vtable. The following dwarf expression means
9666 BaseAddr = ObAddr + *((*ObAddr) - Offset)
9668 This is specific to the V3 ABI, of course. */
9670 dw_loc_descr_ref tmp
;
9672 /* Make a copy of the object address. */
9673 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
9674 add_loc_descr (&loc_descr
, tmp
);
9676 /* Extract the vtable address. */
9677 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
9678 add_loc_descr (&loc_descr
, tmp
);
9680 /* Calculate the address of the offset. */
9681 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
9682 gcc_assert (offset
< 0);
9684 tmp
= int_loc_descriptor (-offset
);
9685 add_loc_descr (&loc_descr
, tmp
);
9686 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
9687 add_loc_descr (&loc_descr
, tmp
);
9689 /* Extract the offset. */
9690 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
9691 add_loc_descr (&loc_descr
, tmp
);
9693 /* Add it to the object address. */
9694 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
9695 add_loc_descr (&loc_descr
, tmp
);
9698 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
9701 offset
= field_byte_offset (decl
);
9705 enum dwarf_location_atom op
;
9707 /* The DWARF2 standard says that we should assume that the structure
9708 address is already on the stack, so we can specify a structure field
9709 address by using DW_OP_plus_uconst. */
9711 #ifdef MIPS_DEBUGGING_INFO
9712 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9713 operator correctly. It works only if we leave the offset on the
9717 op
= DW_OP_plus_uconst
;
9720 loc_descr
= new_loc_descr (op
, offset
, 0);
9723 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
9726 /* Writes integer values to dw_vec_const array. */
9729 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
9733 *dest
++ = val
& 0xff;
9739 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
9741 static HOST_WIDE_INT
9742 extract_int (const unsigned char *src
, unsigned int size
)
9744 HOST_WIDE_INT val
= 0;
9750 val
|= *--src
& 0xff;
9756 /* Writes floating point values to dw_vec_const array. */
9759 insert_float (rtx rtl
, unsigned char *array
)
9765 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
9766 real_to_target (val
, &rv
, GET_MODE (rtl
));
9768 /* real_to_target puts 32-bit pieces in each long. Pack them. */
9769 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
9771 insert_int (val
[i
], 4, array
);
9776 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9777 does not have a "location" either in memory or in a register. These
9778 things can arise in GNU C when a constant is passed as an actual parameter
9779 to an inlined function. They can also arise in C++ where declared
9780 constants do not necessarily get memory "homes". */
9783 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
9785 switch (GET_CODE (rtl
))
9789 HOST_WIDE_INT val
= INTVAL (rtl
);
9792 add_AT_int (die
, DW_AT_const_value
, val
);
9794 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
9799 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9800 floating-point constant. A CONST_DOUBLE is used whenever the
9801 constant requires more than one word in order to be adequately
9802 represented. We output CONST_DOUBLEs as blocks. */
9804 enum machine_mode mode
= GET_MODE (rtl
);
9806 if (SCALAR_FLOAT_MODE_P (mode
))
9808 unsigned int length
= GET_MODE_SIZE (mode
);
9809 unsigned char *array
= ggc_alloc (length
);
9811 insert_float (rtl
, array
);
9812 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
9816 /* ??? We really should be using HOST_WIDE_INT throughout. */
9817 gcc_assert (HOST_BITS_PER_LONG
== HOST_BITS_PER_WIDE_INT
);
9819 add_AT_long_long (die
, DW_AT_const_value
,
9820 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
9827 enum machine_mode mode
= GET_MODE (rtl
);
9828 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
9829 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
9830 unsigned char *array
= ggc_alloc (length
* elt_size
);
9834 switch (GET_MODE_CLASS (mode
))
9836 case MODE_VECTOR_INT
:
9837 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
9839 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
9840 HOST_WIDE_INT lo
, hi
;
9842 switch (GET_CODE (elt
))
9850 lo
= CONST_DOUBLE_LOW (elt
);
9851 hi
= CONST_DOUBLE_HIGH (elt
);
9858 if (elt_size
<= sizeof (HOST_WIDE_INT
))
9859 insert_int (lo
, elt_size
, p
);
9862 unsigned char *p0
= p
;
9863 unsigned char *p1
= p
+ sizeof (HOST_WIDE_INT
);
9865 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
9866 if (WORDS_BIG_ENDIAN
)
9871 insert_int (lo
, sizeof (HOST_WIDE_INT
), p0
);
9872 insert_int (hi
, sizeof (HOST_WIDE_INT
), p1
);
9877 case MODE_VECTOR_FLOAT
:
9878 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
9880 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
9881 insert_float (elt
, p
);
9889 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
9894 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
9900 add_AT_addr (die
, DW_AT_const_value
, rtl
);
9901 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
9905 /* In cases where an inlined instance of an inline function is passed
9906 the address of an `auto' variable (which is local to the caller) we
9907 can get a situation where the DECL_RTL of the artificial local
9908 variable (for the inlining) which acts as a stand-in for the
9909 corresponding formal parameter (of the inline function) will look
9910 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9911 exactly a compile-time constant expression, but it isn't the address
9912 of the (artificial) local variable either. Rather, it represents the
9913 *value* which the artificial local variable always has during its
9914 lifetime. We currently have no way to represent such quasi-constant
9915 values in Dwarf, so for now we just punt and generate nothing. */
9919 /* No other kinds of rtx should be possible here. */
9925 /* Determine whether the evaluation of EXPR references any variables
9926 or functions which aren't otherwise used (and therefore may not be
9929 reference_to_unused (tree
* tp
, int * walk_subtrees
,
9930 void * data ATTRIBUTE_UNUSED
)
9932 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
9935 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
9936 && ! TREE_ASM_WRITTEN (*tp
))
9942 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
9943 for use in a later add_const_value_attribute call. */
9946 rtl_for_decl_init (tree init
, tree type
)
9950 /* If a variable is initialized with a string constant without embedded
9951 zeros, build CONST_STRING. */
9952 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
9954 tree enttype
= TREE_TYPE (type
);
9955 tree domain
= TYPE_DOMAIN (type
);
9956 enum machine_mode mode
= TYPE_MODE (enttype
);
9958 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
9960 && integer_zerop (TYPE_MIN_VALUE (domain
))
9961 && compare_tree_int (TYPE_MAX_VALUE (domain
),
9962 TREE_STRING_LENGTH (init
) - 1) == 0
9963 && ((size_t) TREE_STRING_LENGTH (init
)
9964 == strlen (TREE_STRING_POINTER (init
)) + 1))
9965 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
9966 ggc_strdup (TREE_STRING_POINTER (init
)));
9968 /* Although DWARF could easily handle other kinds of aggregates, we
9969 have no way to represent such values as RTL constants, so skip
9971 else if (AGGREGATE_TYPE_P (type
))
9973 /* If the initializer is something that we know will expand into an
9974 immediate RTL constant, expand it now. We must be careful not to
9975 reference variables which won't be output. */
9976 else if (initializer_constant_valid_p (init
, type
)
9977 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
9979 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
9981 /* If expand_expr returns a MEM, it wasn't immediate. */
9982 gcc_assert (!rtl
|| !MEM_P (rtl
));
9988 /* Generate RTL for the variable DECL to represent its location. */
9991 rtl_for_decl_location (tree decl
)
9995 /* Here we have to decide where we are going to say the parameter "lives"
9996 (as far as the debugger is concerned). We only have a couple of
9997 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
9999 DECL_RTL normally indicates where the parameter lives during most of the
10000 activation of the function. If optimization is enabled however, this
10001 could be either NULL or else a pseudo-reg. Both of those cases indicate
10002 that the parameter doesn't really live anywhere (as far as the code
10003 generation parts of GCC are concerned) during most of the function's
10004 activation. That will happen (for example) if the parameter is never
10005 referenced within the function.
10007 We could just generate a location descriptor here for all non-NULL
10008 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
10009 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
10010 where DECL_RTL is NULL or is a pseudo-reg.
10012 Note however that we can only get away with using DECL_INCOMING_RTL as
10013 a backup substitute for DECL_RTL in certain limited cases. In cases
10014 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
10015 we can be sure that the parameter was passed using the same type as it is
10016 declared to have within the function, and that its DECL_INCOMING_RTL
10017 points us to a place where a value of that type is passed.
10019 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
10020 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
10021 because in these cases DECL_INCOMING_RTL points us to a value of some
10022 type which is *different* from the type of the parameter itself. Thus,
10023 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
10024 such cases, the debugger would end up (for example) trying to fetch a
10025 `float' from a place which actually contains the first part of a
10026 `double'. That would lead to really incorrect and confusing
10027 output at debug-time.
10029 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
10030 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
10031 are a couple of exceptions however. On little-endian machines we can
10032 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
10033 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
10034 an integral type that is smaller than TREE_TYPE (decl). These cases arise
10035 when (on a little-endian machine) a non-prototyped function has a
10036 parameter declared to be of type `short' or `char'. In such cases,
10037 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
10038 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
10039 passed `int' value. If the debugger then uses that address to fetch
10040 a `short' or a `char' (on a little-endian machine) the result will be
10041 the correct data, so we allow for such exceptional cases below.
10043 Note that our goal here is to describe the place where the given formal
10044 parameter lives during most of the function's activation (i.e. between the
10045 end of the prologue and the start of the epilogue). We'll do that as best
10046 as we can. Note however that if the given formal parameter is modified
10047 sometime during the execution of the function, then a stack backtrace (at
10048 debug-time) will show the function as having been called with the *new*
10049 value rather than the value which was originally passed in. This happens
10050 rarely enough that it is not a major problem, but it *is* a problem, and
10051 I'd like to fix it.
10053 A future version of dwarf2out.c may generate two additional attributes for
10054 any given DW_TAG_formal_parameter DIE which will describe the "passed
10055 type" and the "passed location" for the given formal parameter in addition
10056 to the attributes we now generate to indicate the "declared type" and the
10057 "active location" for each parameter. This additional set of attributes
10058 could be used by debuggers for stack backtraces. Separately, note that
10059 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
10060 This happens (for example) for inlined-instances of inline function formal
10061 parameters which are never referenced. This really shouldn't be
10062 happening. All PARM_DECL nodes should get valid non-NULL
10063 DECL_INCOMING_RTL values. FIXME. */
10065 /* Use DECL_RTL as the "location" unless we find something better. */
10066 rtl
= DECL_RTL_IF_SET (decl
);
10068 /* When generating abstract instances, ignore everything except
10069 constants, symbols living in memory, and symbols living in
10070 fixed registers. */
10071 if (! reload_completed
)
10074 && (CONSTANT_P (rtl
)
10076 && CONSTANT_P (XEXP (rtl
, 0)))
10078 && TREE_CODE (decl
) == VAR_DECL
10079 && TREE_STATIC (decl
))))
10081 rtl
= targetm
.delegitimize_address (rtl
);
10086 else if (TREE_CODE (decl
) == PARM_DECL
)
10088 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
10090 tree declared_type
= TREE_TYPE (decl
);
10091 tree passed_type
= DECL_ARG_TYPE (decl
);
10092 enum machine_mode dmode
= TYPE_MODE (declared_type
);
10093 enum machine_mode pmode
= TYPE_MODE (passed_type
);
10095 /* This decl represents a formal parameter which was optimized out.
10096 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
10097 all cases where (rtl == NULL_RTX) just below. */
10098 if (dmode
== pmode
)
10099 rtl
= DECL_INCOMING_RTL (decl
);
10100 else if (SCALAR_INT_MODE_P (dmode
)
10101 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
10102 && DECL_INCOMING_RTL (decl
))
10104 rtx inc
= DECL_INCOMING_RTL (decl
);
10107 else if (MEM_P (inc
))
10109 if (BYTES_BIG_ENDIAN
)
10110 rtl
= adjust_address_nv (inc
, dmode
,
10111 GET_MODE_SIZE (pmode
)
10112 - GET_MODE_SIZE (dmode
));
10119 /* If the parm was passed in registers, but lives on the stack, then
10120 make a big endian correction if the mode of the type of the
10121 parameter is not the same as the mode of the rtl. */
10122 /* ??? This is the same series of checks that are made in dbxout.c before
10123 we reach the big endian correction code there. It isn't clear if all
10124 of these checks are necessary here, but keeping them all is the safe
10126 else if (MEM_P (rtl
)
10127 && XEXP (rtl
, 0) != const0_rtx
10128 && ! CONSTANT_P (XEXP (rtl
, 0))
10129 /* Not passed in memory. */
10130 && !MEM_P (DECL_INCOMING_RTL (decl
))
10131 /* Not passed by invisible reference. */
10132 && (!REG_P (XEXP (rtl
, 0))
10133 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
10134 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
10135 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
10136 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
10139 /* Big endian correction check. */
10140 && BYTES_BIG_ENDIAN
10141 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
10142 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
10145 int offset
= (UNITS_PER_WORD
10146 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
10148 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
10149 plus_constant (XEXP (rtl
, 0), offset
));
10152 else if (TREE_CODE (decl
) == VAR_DECL
10155 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
10156 && BYTES_BIG_ENDIAN
)
10158 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
10159 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
10161 /* If a variable is declared "register" yet is smaller than
10162 a register, then if we store the variable to memory, it
10163 looks like we're storing a register-sized value, when in
10164 fact we are not. We need to adjust the offset of the
10165 storage location to reflect the actual value's bytes,
10166 else gdb will not be able to display it. */
10168 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
10169 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
10172 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
10173 and will have been substituted directly into all expressions that use it.
10174 C does not have such a concept, but C++ and other languages do. */
10175 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
10176 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
10179 rtl
= targetm
.delegitimize_address (rtl
);
10181 /* If we don't look past the constant pool, we risk emitting a
10182 reference to a constant pool entry that isn't referenced from
10183 code, and thus is not emitted. */
10185 rtl
= avoid_constant_pool_reference (rtl
);
10190 /* We need to figure out what section we should use as the base for the
10191 address ranges where a given location is valid.
10192 1. If this particular DECL has a section associated with it, use that.
10193 2. If this function has a section associated with it, use that.
10194 3. Otherwise, use the text section.
10195 XXX: If you split a variable across multiple sections, we won't notice. */
10197 static const char *
10198 secname_for_decl (tree decl
)
10200 const char *secname
;
10202 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
10204 tree sectree
= DECL_SECTION_NAME (decl
);
10205 secname
= TREE_STRING_POINTER (sectree
);
10207 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
10209 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
10210 secname
= TREE_STRING_POINTER (sectree
);
10212 else if (cfun
&& in_cold_section_p
)
10213 secname
= cfun
->cold_section_label
;
10215 secname
= text_section_label
;
10220 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
10221 data attribute for a variable or a parameter. We generate the
10222 DW_AT_const_value attribute only in those cases where the given variable
10223 or parameter does not have a true "location" either in memory or in a
10224 register. This can happen (for example) when a constant is passed as an
10225 actual argument in a call to an inline function. (It's possible that
10226 these things can crop up in other ways also.) Note that one type of
10227 constant value which can be passed into an inlined function is a constant
10228 pointer. This can happen for example if an actual argument in an inlined
10229 function call evaluates to a compile-time constant address. */
10232 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
,
10233 enum dwarf_attribute attr
)
10236 dw_loc_descr_ref descr
;
10237 var_loc_list
*loc_list
;
10238 struct var_loc_node
*node
;
10239 if (TREE_CODE (decl
) == ERROR_MARK
)
10242 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
10243 || TREE_CODE (decl
) == RESULT_DECL
);
10245 /* See if we possibly have multiple locations for this variable. */
10246 loc_list
= lookup_decl_loc (decl
);
10248 /* If it truly has multiple locations, the first and last node will
10250 if (loc_list
&& loc_list
->first
!= loc_list
->last
)
10252 const char *endname
, *secname
;
10253 dw_loc_list_ref list
;
10256 /* Now that we know what section we are using for a base,
10257 actually construct the list of locations.
10258 The first location information is what is passed to the
10259 function that creates the location list, and the remaining
10260 locations just get added on to that list.
10261 Note that we only know the start address for a location
10262 (IE location changes), so to build the range, we use
10263 the range [current location start, next location start].
10264 This means we have to special case the last node, and generate
10265 a range of [last location start, end of function label]. */
10267 node
= loc_list
->first
;
10268 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10269 secname
= secname_for_decl (decl
);
10271 list
= new_loc_list (loc_descriptor (varloc
),
10272 node
->label
, node
->next
->label
, secname
, 1);
10275 for (; node
->next
; node
= node
->next
)
10276 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
10278 /* The variable has a location between NODE->LABEL and
10279 NODE->NEXT->LABEL. */
10280 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10281 add_loc_descr_to_loc_list (&list
, loc_descriptor (varloc
),
10282 node
->label
, node
->next
->label
, secname
);
10285 /* If the variable has a location at the last label
10286 it keeps its location until the end of function. */
10287 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
10289 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
10291 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10292 if (!current_function_decl
)
10293 endname
= text_end_label
;
10296 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
10297 current_function_funcdef_no
);
10298 endname
= ggc_strdup (label_id
);
10300 add_loc_descr_to_loc_list (&list
, loc_descriptor (varloc
),
10301 node
->label
, endname
, secname
);
10304 /* Finally, add the location list to the DIE, and we are done. */
10305 add_AT_loc_list (die
, attr
, list
);
10309 /* Try to get some constant RTL for this decl, and use that as the value of
10312 rtl
= rtl_for_decl_location (decl
);
10313 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
))
10315 add_const_value_attribute (die
, rtl
);
10319 /* If we have tried to generate the location otherwise, and it
10320 didn't work out (we wouldn't be here if we did), and we have a one entry
10321 location list, try generating a location from that. */
10322 if (loc_list
&& loc_list
->first
)
10324 node
= loc_list
->first
;
10325 descr
= loc_descriptor (NOTE_VAR_LOCATION (node
->var_loc_note
));
10328 add_AT_location_description (die
, attr
, descr
);
10333 /* We couldn't get any rtl, so try directly generating the location
10334 description from the tree. */
10335 descr
= loc_descriptor_from_tree (decl
);
10338 add_AT_location_description (die
, attr
, descr
);
10341 /* None of that worked, so it must not really have a location;
10342 try adding a constant value attribute from the DECL_INITIAL. */
10343 tree_add_const_value_attribute (die
, decl
);
10346 /* If we don't have a copy of this variable in memory for some reason (such
10347 as a C++ member constant that doesn't have an out-of-line definition),
10348 we should tell the debugger about the constant value. */
10351 tree_add_const_value_attribute (dw_die_ref var_die
, tree decl
)
10353 tree init
= DECL_INITIAL (decl
);
10354 tree type
= TREE_TYPE (decl
);
10357 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
)
10362 rtl
= rtl_for_decl_init (init
, type
);
10364 add_const_value_attribute (var_die
, rtl
);
10367 /* Convert the CFI instructions for the current function into a
10368 location list. This is used for DW_AT_frame_base when we targeting
10369 a dwarf2 consumer that does not support the dwarf3
10370 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
10373 static dw_loc_list_ref
10374 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
10377 dw_loc_list_ref list
, *list_tail
;
10379 dw_cfa_location last_cfa
, next_cfa
;
10380 const char *start_label
, *last_label
, *section
;
10382 fde
= &fde_table
[fde_table_in_use
- 1];
10384 section
= secname_for_decl (current_function_decl
);
10388 next_cfa
.reg
= INVALID_REGNUM
;
10389 next_cfa
.offset
= 0;
10390 next_cfa
.indirect
= 0;
10391 next_cfa
.base_offset
= 0;
10393 start_label
= fde
->dw_fde_begin
;
10395 /* ??? Bald assumption that the CIE opcode list does not contain
10396 advance opcodes. */
10397 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
10398 lookup_cfa_1 (cfi
, &next_cfa
);
10400 last_cfa
= next_cfa
;
10401 last_label
= start_label
;
10403 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
10404 switch (cfi
->dw_cfi_opc
)
10406 case DW_CFA_advance_loc1
:
10407 case DW_CFA_advance_loc2
:
10408 case DW_CFA_advance_loc4
:
10409 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
10411 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
10412 start_label
, last_label
, section
,
10415 list_tail
= &(*list_tail
)->dw_loc_next
;
10416 last_cfa
= next_cfa
;
10417 start_label
= last_label
;
10419 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
10422 case DW_CFA_advance_loc
:
10423 /* The encoding is complex enough that we should never emit this. */
10424 case DW_CFA_remember_state
:
10425 case DW_CFA_restore_state
:
10426 /* We don't handle these two in this function. It would be possible
10427 if it were to be required. */
10428 gcc_unreachable ();
10431 lookup_cfa_1 (cfi
, &next_cfa
);
10435 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
10437 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
10438 start_label
, last_label
, section
,
10440 list_tail
= &(*list_tail
)->dw_loc_next
;
10441 start_label
= last_label
;
10443 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
10444 start_label
, fde
->dw_fde_end
, section
,
10450 /* Compute a displacement from the "steady-state frame pointer" to the
10451 frame base (often the same as the CFA), and store it in
10452 frame_pointer_fb_offset. OFFSET is added to the displacement
10453 before the latter is negated. */
10456 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
10460 #ifdef FRAME_POINTER_CFA_OFFSET
10461 reg
= frame_pointer_rtx
;
10462 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
10464 reg
= arg_pointer_rtx
;
10465 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
10468 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
10469 if (GET_CODE (elim
) == PLUS
)
10471 offset
+= INTVAL (XEXP (elim
, 1));
10472 elim
= XEXP (elim
, 0);
10474 gcc_assert (elim
== (frame_pointer_needed
? hard_frame_pointer_rtx
10475 : stack_pointer_rtx
));
10477 frame_pointer_fb_offset
= -offset
;
10480 /* Generate a DW_AT_name attribute given some string value to be included as
10481 the value of the attribute. */
10484 add_name_attribute (dw_die_ref die
, const char *name_string
)
10486 if (name_string
!= NULL
&& *name_string
!= 0)
10488 if (demangle_name_func
)
10489 name_string
= (*demangle_name_func
) (name_string
);
10491 add_AT_string (die
, DW_AT_name
, name_string
);
10495 /* Generate a DW_AT_comp_dir attribute for DIE. */
10498 add_comp_dir_attribute (dw_die_ref die
)
10500 const char *wd
= get_src_pwd ();
10502 add_AT_string (die
, DW_AT_comp_dir
, wd
);
10505 /* Given a tree node describing an array bound (either lower or upper) output
10506 a representation for that bound. */
10509 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
10511 switch (TREE_CODE (bound
))
10516 /* All fixed-bounds are represented by INTEGER_CST nodes. */
10518 if (! host_integerp (bound
, 0)
10519 || (bound_attr
== DW_AT_lower_bound
10520 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
10521 || (is_fortran () && integer_onep (bound
)))))
10522 /* Use the default. */
10525 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
10530 case NON_LVALUE_EXPR
:
10531 case VIEW_CONVERT_EXPR
:
10532 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
10542 dw_die_ref decl_die
= lookup_decl_die (bound
);
10544 /* ??? Can this happen, or should the variable have been bound
10545 first? Probably it can, since I imagine that we try to create
10546 the types of parameters in the order in which they exist in
10547 the list, and won't have created a forward reference to a
10548 later parameter. */
10549 if (decl_die
!= NULL
)
10550 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
10556 /* Otherwise try to create a stack operation procedure to
10557 evaluate the value of the array bound. */
10559 dw_die_ref ctx
, decl_die
;
10560 dw_loc_descr_ref loc
;
10562 loc
= loc_descriptor_from_tree (bound
);
10566 if (current_function_decl
== 0)
10567 ctx
= comp_unit_die
;
10569 ctx
= lookup_decl_die (current_function_decl
);
10571 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
10572 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
10573 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
10574 add_AT_loc (decl_die
, DW_AT_location
, loc
);
10576 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
10582 /* Note that the block of subscript information for an array type also
10583 includes information about the element type of type given array type. */
10586 add_subscript_info (dw_die_ref type_die
, tree type
)
10588 #ifndef MIPS_DEBUGGING_INFO
10589 unsigned dimension_number
;
10592 dw_die_ref subrange_die
;
10594 /* The GNU compilers represent multidimensional array types as sequences of
10595 one dimensional array types whose element types are themselves array
10596 types. Here we squish that down, so that each multidimensional array
10597 type gets only one array_type DIE in the Dwarf debugging info. The draft
10598 Dwarf specification say that we are allowed to do this kind of
10599 compression in C (because there is no difference between an array or
10600 arrays and a multidimensional array in C) but for other source languages
10601 (e.g. Ada) we probably shouldn't do this. */
10603 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10604 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10605 We work around this by disabling this feature. See also
10606 gen_array_type_die. */
10607 #ifndef MIPS_DEBUGGING_INFO
10608 for (dimension_number
= 0;
10609 TREE_CODE (type
) == ARRAY_TYPE
;
10610 type
= TREE_TYPE (type
), dimension_number
++)
10613 tree domain
= TYPE_DOMAIN (type
);
10615 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
10616 and (in GNU C only) variable bounds. Handle all three forms
10618 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
10621 /* We have an array type with specified bounds. */
10622 lower
= TYPE_MIN_VALUE (domain
);
10623 upper
= TYPE_MAX_VALUE (domain
);
10625 /* Define the index type. */
10626 if (TREE_TYPE (domain
))
10628 /* ??? This is probably an Ada unnamed subrange type. Ignore the
10629 TREE_TYPE field. We can't emit debug info for this
10630 because it is an unnamed integral type. */
10631 if (TREE_CODE (domain
) == INTEGER_TYPE
10632 && TYPE_NAME (domain
) == NULL_TREE
10633 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
10634 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
10637 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
10641 /* ??? If upper is NULL, the array has unspecified length,
10642 but it does have a lower bound. This happens with Fortran
10644 Since the debugger is definitely going to need to know N
10645 to produce useful results, go ahead and output the lower
10646 bound solo, and hope the debugger can cope. */
10648 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
10650 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
10653 /* Otherwise we have an array type with an unspecified length. The
10654 DWARF-2 spec does not say how to handle this; let's just leave out the
10660 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
10664 switch (TREE_CODE (tree_node
))
10669 case ENUMERAL_TYPE
:
10672 case QUAL_UNION_TYPE
:
10673 size
= int_size_in_bytes (tree_node
);
10676 /* For a data member of a struct or union, the DW_AT_byte_size is
10677 generally given as the number of bytes normally allocated for an
10678 object of the *declared* type of the member itself. This is true
10679 even for bit-fields. */
10680 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
10683 gcc_unreachable ();
10686 /* Note that `size' might be -1 when we get to this point. If it is, that
10687 indicates that the byte size of the entity in question is variable. We
10688 have no good way of expressing this fact in Dwarf at the present time,
10689 so just let the -1 pass on through. */
10690 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
10693 /* For a FIELD_DECL node which represents a bit-field, output an attribute
10694 which specifies the distance in bits from the highest order bit of the
10695 "containing object" for the bit-field to the highest order bit of the
10698 For any given bit-field, the "containing object" is a hypothetical object
10699 (of some integral or enum type) within which the given bit-field lives. The
10700 type of this hypothetical "containing object" is always the same as the
10701 declared type of the individual bit-field itself. The determination of the
10702 exact location of the "containing object" for a bit-field is rather
10703 complicated. It's handled by the `field_byte_offset' function (above).
10705 Note that it is the size (in bytes) of the hypothetical "containing object"
10706 which will be given in the DW_AT_byte_size attribute for this bit-field.
10707 (See `byte_size_attribute' above). */
10710 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
10712 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
10713 tree type
= DECL_BIT_FIELD_TYPE (decl
);
10714 HOST_WIDE_INT bitpos_int
;
10715 HOST_WIDE_INT highest_order_object_bit_offset
;
10716 HOST_WIDE_INT highest_order_field_bit_offset
;
10717 HOST_WIDE_INT
unsigned bit_offset
;
10719 /* Must be a field and a bit field. */
10720 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
10722 /* We can't yet handle bit-fields whose offsets are variable, so if we
10723 encounter such things, just return without generating any attribute
10724 whatsoever. Likewise for variable or too large size. */
10725 if (! host_integerp (bit_position (decl
), 0)
10726 || ! host_integerp (DECL_SIZE (decl
), 1))
10729 bitpos_int
= int_bit_position (decl
);
10731 /* Note that the bit offset is always the distance (in bits) from the
10732 highest-order bit of the "containing object" to the highest-order bit of
10733 the bit-field itself. Since the "high-order end" of any object or field
10734 is different on big-endian and little-endian machines, the computation
10735 below must take account of these differences. */
10736 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
10737 highest_order_field_bit_offset
= bitpos_int
;
10739 if (! BYTES_BIG_ENDIAN
)
10741 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
10742 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
10746 = (! BYTES_BIG_ENDIAN
10747 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
10748 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
10750 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
10753 /* For a FIELD_DECL node which represents a bit field, output an attribute
10754 which specifies the length in bits of the given field. */
10757 add_bit_size_attribute (dw_die_ref die
, tree decl
)
10759 /* Must be a field and a bit field. */
10760 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
10761 && DECL_BIT_FIELD_TYPE (decl
));
10763 if (host_integerp (DECL_SIZE (decl
), 1))
10764 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
10767 /* If the compiled language is ANSI C, then add a 'prototyped'
10768 attribute, if arg types are given for the parameters of a function. */
10771 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
10773 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
10774 && TYPE_ARG_TYPES (func_type
) != NULL
)
10775 add_AT_flag (die
, DW_AT_prototyped
, 1);
10778 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
10779 by looking in either the type declaration or object declaration
10783 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
10785 dw_die_ref origin_die
= NULL
;
10787 if (TREE_CODE (origin
) != FUNCTION_DECL
)
10789 /* We may have gotten separated from the block for the inlined
10790 function, if we're in an exception handler or some such; make
10791 sure that the abstract function has been written out.
10793 Doing this for nested functions is wrong, however; functions are
10794 distinct units, and our context might not even be inline. */
10798 fn
= TYPE_STUB_DECL (fn
);
10800 fn
= decl_function_context (fn
);
10802 dwarf2out_abstract_function (fn
);
10805 if (DECL_P (origin
))
10806 origin_die
= lookup_decl_die (origin
);
10807 else if (TYPE_P (origin
))
10808 origin_die
= lookup_type_die (origin
);
10810 /* XXX: Functions that are never lowered don't always have correct block
10811 trees (in the case of java, they simply have no block tree, in some other
10812 languages). For these functions, there is nothing we can really do to
10813 output correct debug info for inlined functions in all cases. Rather
10814 than die, we'll just produce deficient debug info now, in that we will
10815 have variables without a proper abstract origin. In the future, when all
10816 functions are lowered, we should re-add a gcc_assert (origin_die)
10820 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
10823 /* We do not currently support the pure_virtual attribute. */
10826 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
10828 if (DECL_VINDEX (func_decl
))
10830 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
10832 if (host_integerp (DECL_VINDEX (func_decl
), 0))
10833 add_AT_loc (die
, DW_AT_vtable_elem_location
,
10834 new_loc_descr (DW_OP_constu
,
10835 tree_low_cst (DECL_VINDEX (func_decl
), 0),
10838 /* GNU extension: Record what type this method came from originally. */
10839 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10840 add_AT_die_ref (die
, DW_AT_containing_type
,
10841 lookup_type_die (DECL_CONTEXT (func_decl
)));
10845 /* Add source coordinate attributes for the given decl. */
10848 add_src_coords_attributes (dw_die_ref die
, tree decl
)
10850 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
10851 unsigned file_index
= lookup_filename (s
.file
);
10853 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
10854 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
10857 /* Add a DW_AT_name attribute and source coordinate attribute for the
10858 given decl, but only if it actually has a name. */
10861 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
10865 decl_name
= DECL_NAME (decl
);
10866 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
10868 add_name_attribute (die
, dwarf2_name (decl
, 0));
10869 if (! DECL_ARTIFICIAL (decl
))
10870 add_src_coords_attributes (die
, decl
);
10872 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
10873 && TREE_PUBLIC (decl
)
10874 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
10875 && !DECL_ABSTRACT (decl
)
10876 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
)))
10877 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
10878 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
10881 #ifdef VMS_DEBUGGING_INFO
10882 /* Get the function's name, as described by its RTL. This may be different
10883 from the DECL_NAME name used in the source file. */
10884 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
10886 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
10887 XEXP (DECL_RTL (decl
), 0));
10888 VEC_safe_push (tree
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
10893 /* Push a new declaration scope. */
10896 push_decl_scope (tree scope
)
10898 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
10901 /* Pop a declaration scope. */
10904 pop_decl_scope (void)
10906 VEC_pop (tree
, decl_scope_table
);
10909 /* Return the DIE for the scope that immediately contains this type.
10910 Non-named types get global scope. Named types nested in other
10911 types get their containing scope if it's open, or global scope
10912 otherwise. All other types (i.e. function-local named types) get
10913 the current active scope. */
10916 scope_die_for (tree t
, dw_die_ref context_die
)
10918 dw_die_ref scope_die
= NULL
;
10919 tree containing_scope
;
10922 /* Non-types always go in the current scope. */
10923 gcc_assert (TYPE_P (t
));
10925 containing_scope
= TYPE_CONTEXT (t
);
10927 /* Use the containing namespace if it was passed in (for a declaration). */
10928 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
10930 if (context_die
== lookup_decl_die (containing_scope
))
10933 containing_scope
= NULL_TREE
;
10936 /* Ignore function type "scopes" from the C frontend. They mean that
10937 a tagged type is local to a parmlist of a function declarator, but
10938 that isn't useful to DWARF. */
10939 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
10940 containing_scope
= NULL_TREE
;
10942 if (containing_scope
== NULL_TREE
)
10943 scope_die
= comp_unit_die
;
10944 else if (TYPE_P (containing_scope
))
10946 /* For types, we can just look up the appropriate DIE. But
10947 first we check to see if we're in the middle of emitting it
10948 so we know where the new DIE should go. */
10949 for (i
= VEC_length (tree
, decl_scope_table
) - 1; i
>= 0; --i
)
10950 if (VEC_index (tree
, decl_scope_table
, i
) == containing_scope
)
10955 gcc_assert (debug_info_level
<= DINFO_LEVEL_TERSE
10956 || TREE_ASM_WRITTEN (containing_scope
));
10958 /* If none of the current dies are suitable, we get file scope. */
10959 scope_die
= comp_unit_die
;
10962 scope_die
= lookup_type_die (containing_scope
);
10965 scope_die
= context_die
;
10970 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
10973 local_scope_p (dw_die_ref context_die
)
10975 for (; context_die
; context_die
= context_die
->die_parent
)
10976 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
10977 || context_die
->die_tag
== DW_TAG_subprogram
)
10983 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
10984 whether or not to treat a DIE in this context as a declaration. */
10987 class_or_namespace_scope_p (dw_die_ref context_die
)
10989 return (context_die
10990 && (context_die
->die_tag
== DW_TAG_structure_type
10991 || context_die
->die_tag
== DW_TAG_union_type
10992 || context_die
->die_tag
== DW_TAG_namespace
));
10995 /* Many forms of DIEs require a "type description" attribute. This
10996 routine locates the proper "type descriptor" die for the type given
10997 by 'type', and adds a DW_AT_type attribute below the given die. */
11000 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
11001 int decl_volatile
, dw_die_ref context_die
)
11003 enum tree_code code
= TREE_CODE (type
);
11004 dw_die_ref type_die
= NULL
;
11006 /* ??? If this type is an unnamed subrange type of an integral or
11007 floating-point type, use the inner type. This is because we have no
11008 support for unnamed types in base_type_die. This can happen if this is
11009 an Ada subrange type. Correct solution is emit a subrange type die. */
11010 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
11011 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
11012 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
11014 if (code
== ERROR_MARK
11015 /* Handle a special case. For functions whose return type is void, we
11016 generate *no* type attribute. (Note that no object may have type
11017 `void', so this only applies to function return types). */
11018 || code
== VOID_TYPE
)
11021 type_die
= modified_type_die (type
,
11022 decl_const
|| TYPE_READONLY (type
),
11023 decl_volatile
|| TYPE_VOLATILE (type
),
11026 if (type_die
!= NULL
)
11027 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
11030 /* Given an object die, add the calling convention attribute for the
11031 function call type. */
11033 add_calling_convention_attribute (dw_die_ref subr_die
, tree type
)
11035 enum dwarf_calling_convention value
= DW_CC_normal
;
11037 value
= targetm
.dwarf_calling_convention (type
);
11039 /* Only add the attribute if the backend requests it, and
11040 is not DW_CC_normal. */
11041 if (value
&& (value
!= DW_CC_normal
))
11042 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
11045 /* Given a tree pointer to a struct, class, union, or enum type node, return
11046 a pointer to the (string) tag name for the given type, or zero if the type
11047 was declared without a tag. */
11049 static const char *
11050 type_tag (tree type
)
11052 const char *name
= 0;
11054 if (TYPE_NAME (type
) != 0)
11058 /* Find the IDENTIFIER_NODE for the type name. */
11059 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
11060 t
= TYPE_NAME (type
);
11062 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
11063 a TYPE_DECL node, regardless of whether or not a `typedef' was
11065 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
11066 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
11067 t
= DECL_NAME (TYPE_NAME (type
));
11069 /* Now get the name as a string, or invent one. */
11071 name
= IDENTIFIER_POINTER (t
);
11074 return (name
== 0 || *name
== '\0') ? 0 : name
;
11077 /* Return the type associated with a data member, make a special check
11078 for bit field types. */
11081 member_declared_type (tree member
)
11083 return (DECL_BIT_FIELD_TYPE (member
)
11084 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
11087 /* Get the decl's label, as described by its RTL. This may be different
11088 from the DECL_NAME name used in the source file. */
11091 static const char *
11092 decl_start_label (tree decl
)
11095 const char *fnname
;
11097 x
= DECL_RTL (decl
);
11098 gcc_assert (MEM_P (x
));
11101 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
11103 fnname
= XSTR (x
, 0);
11108 /* These routines generate the internal representation of the DIE's for
11109 the compilation unit. Debugging information is collected by walking
11110 the declaration trees passed in from dwarf2out_decl(). */
11113 gen_array_type_die (tree type
, dw_die_ref context_die
)
11115 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
11116 dw_die_ref array_die
;
11119 /* ??? The SGI dwarf reader fails for array of array of enum types unless
11120 the inner array type comes before the outer array type. Thus we must
11121 call gen_type_die before we call new_die. See below also. */
11122 #ifdef MIPS_DEBUGGING_INFO
11123 gen_type_die (TREE_TYPE (type
), context_die
);
11126 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
11127 add_name_attribute (array_die
, type_tag (type
));
11128 equate_type_number_to_die (type
, array_die
);
11130 if (TREE_CODE (type
) == VECTOR_TYPE
)
11132 /* The frontend feeds us a representation for the vector as a struct
11133 containing an array. Pull out the array type. */
11134 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
11135 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
11139 /* We default the array ordering. SDB will probably do
11140 the right things even if DW_AT_ordering is not present. It's not even
11141 an issue until we start to get into multidimensional arrays anyway. If
11142 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
11143 then we'll have to put the DW_AT_ordering attribute back in. (But if
11144 and when we find out that we need to put these in, we will only do so
11145 for multidimensional arrays. */
11146 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
11149 #ifdef MIPS_DEBUGGING_INFO
11150 /* The SGI compilers handle arrays of unknown bound by setting
11151 AT_declaration and not emitting any subrange DIEs. */
11152 if (! TYPE_DOMAIN (type
))
11153 add_AT_flag (array_die
, DW_AT_declaration
, 1);
11156 add_subscript_info (array_die
, type
);
11158 /* Add representation of the type of the elements of this array type. */
11159 element_type
= TREE_TYPE (type
);
11161 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11162 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11163 We work around this by disabling this feature. See also
11164 add_subscript_info. */
11165 #ifndef MIPS_DEBUGGING_INFO
11166 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
11167 element_type
= TREE_TYPE (element_type
);
11169 gen_type_die (element_type
, context_die
);
11172 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
11177 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
11179 tree origin
= decl_ultimate_origin (decl
);
11180 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
11182 if (origin
!= NULL
)
11183 add_abstract_origin_attribute (decl_die
, origin
);
11186 add_name_and_src_coords_attributes (decl_die
, decl
);
11187 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
11188 0, 0, context_die
);
11191 if (DECL_ABSTRACT (decl
))
11192 equate_decl_number_to_die (decl
, decl_die
);
11194 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
11198 /* Walk through the list of incomplete types again, trying once more to
11199 emit full debugging info for them. */
11202 retry_incomplete_types (void)
11206 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
11207 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die
);
11210 /* Generate a DIE to represent an inlined instance of an enumeration type. */
11213 gen_inlined_enumeration_type_die (tree type
, dw_die_ref context_die
)
11215 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
11217 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11218 be incomplete and such types are not marked. */
11219 add_abstract_origin_attribute (type_die
, type
);
11222 /* Generate a DIE to represent an inlined instance of a structure type. */
11225 gen_inlined_structure_type_die (tree type
, dw_die_ref context_die
)
11227 dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
, type
);
11229 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11230 be incomplete and such types are not marked. */
11231 add_abstract_origin_attribute (type_die
, type
);
11234 /* Generate a DIE to represent an inlined instance of a union type. */
11237 gen_inlined_union_type_die (tree type
, dw_die_ref context_die
)
11239 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
11241 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11242 be incomplete and such types are not marked. */
11243 add_abstract_origin_attribute (type_die
, type
);
11246 /* Generate a DIE to represent an enumeration type. Note that these DIEs
11247 include all of the information about the enumeration values also. Each
11248 enumerated type name/value is listed as a child of the enumerated type
11252 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
11254 dw_die_ref type_die
= lookup_type_die (type
);
11256 if (type_die
== NULL
)
11258 type_die
= new_die (DW_TAG_enumeration_type
,
11259 scope_die_for (type
, context_die
), type
);
11260 equate_type_number_to_die (type
, type_die
);
11261 add_name_attribute (type_die
, type_tag (type
));
11263 else if (! TYPE_SIZE (type
))
11266 remove_AT (type_die
, DW_AT_declaration
);
11268 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
11269 given enum type is incomplete, do not generate the DW_AT_byte_size
11270 attribute or the DW_AT_element_list attribute. */
11271 if (TYPE_SIZE (type
))
11275 TREE_ASM_WRITTEN (type
) = 1;
11276 add_byte_size_attribute (type_die
, type
);
11277 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
11278 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
11280 /* If the first reference to this type was as the return type of an
11281 inline function, then it may not have a parent. Fix this now. */
11282 if (type_die
->die_parent
== NULL
)
11283 add_child_die (scope_die_for (type
, context_die
), type_die
);
11285 for (link
= TYPE_VALUES (type
);
11286 link
!= NULL
; link
= TREE_CHAIN (link
))
11288 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
11289 tree value
= TREE_VALUE (link
);
11291 add_name_attribute (enum_die
,
11292 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
11294 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
11295 /* DWARF2 does not provide a way of indicating whether or
11296 not enumeration constants are signed or unsigned. GDB
11297 always assumes the values are signed, so we output all
11298 values as if they were signed. That means that
11299 enumeration constants with very large unsigned values
11300 will appear to have negative values in the debugger. */
11301 add_AT_int (enum_die
, DW_AT_const_value
,
11302 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
11306 add_AT_flag (type_die
, DW_AT_declaration
, 1);
11311 /* Generate a DIE to represent either a real live formal parameter decl or to
11312 represent just the type of some formal parameter position in some function
11315 Note that this routine is a bit unusual because its argument may be a
11316 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
11317 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
11318 node. If it's the former then this function is being called to output a
11319 DIE to represent a formal parameter object (or some inlining thereof). If
11320 it's the latter, then this function is only being called to output a
11321 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
11322 argument type of some subprogram type. */
11325 gen_formal_parameter_die (tree node
, dw_die_ref context_die
)
11327 dw_die_ref parm_die
11328 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
11331 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
11333 case tcc_declaration
:
11334 origin
= decl_ultimate_origin (node
);
11335 if (origin
!= NULL
)
11336 add_abstract_origin_attribute (parm_die
, origin
);
11339 add_name_and_src_coords_attributes (parm_die
, node
);
11340 add_type_attribute (parm_die
, TREE_TYPE (node
),
11341 TREE_READONLY (node
),
11342 TREE_THIS_VOLATILE (node
),
11344 if (DECL_ARTIFICIAL (node
))
11345 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
11348 equate_decl_number_to_die (node
, parm_die
);
11349 if (! DECL_ABSTRACT (node
))
11350 add_location_or_const_value_attribute (parm_die
, node
, DW_AT_location
);
11355 /* We were called with some kind of a ..._TYPE node. */
11356 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
11360 gcc_unreachable ();
11366 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
11367 at the end of an (ANSI prototyped) formal parameters list. */
11370 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
11372 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
11375 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
11376 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
11377 parameters as specified in some function type specification (except for
11378 those which appear as part of a function *definition*). */
11381 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
11384 tree formal_type
= NULL
;
11385 tree first_parm_type
;
11388 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
11390 arg
= DECL_ARGUMENTS (function_or_method_type
);
11391 function_or_method_type
= TREE_TYPE (function_or_method_type
);
11396 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
11398 /* Make our first pass over the list of formal parameter types and output a
11399 DW_TAG_formal_parameter DIE for each one. */
11400 for (link
= first_parm_type
; link
; )
11402 dw_die_ref parm_die
;
11404 formal_type
= TREE_VALUE (link
);
11405 if (formal_type
== void_type_node
)
11408 /* Output a (nameless) DIE to represent the formal parameter itself. */
11409 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
11410 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
11411 && link
== first_parm_type
)
11412 || (arg
&& DECL_ARTIFICIAL (arg
)))
11413 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
11415 link
= TREE_CHAIN (link
);
11417 arg
= TREE_CHAIN (arg
);
11420 /* If this function type has an ellipsis, add a
11421 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
11422 if (formal_type
!= void_type_node
)
11423 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
11425 /* Make our second (and final) pass over the list of formal parameter types
11426 and output DIEs to represent those types (as necessary). */
11427 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
11428 link
&& TREE_VALUE (link
);
11429 link
= TREE_CHAIN (link
))
11430 gen_type_die (TREE_VALUE (link
), context_die
);
11433 /* We want to generate the DIE for TYPE so that we can generate the
11434 die for MEMBER, which has been defined; we will need to refer back
11435 to the member declaration nested within TYPE. If we're trying to
11436 generate minimal debug info for TYPE, processing TYPE won't do the
11437 trick; we need to attach the member declaration by hand. */
11440 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
11442 gen_type_die (type
, context_die
);
11444 /* If we're trying to avoid duplicate debug info, we may not have
11445 emitted the member decl for this function. Emit it now. */
11446 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
11447 && ! lookup_decl_die (member
))
11449 dw_die_ref type_die
;
11450 gcc_assert (!decl_ultimate_origin (member
));
11452 push_decl_scope (type
);
11453 type_die
= lookup_type_die (type
);
11454 if (TREE_CODE (member
) == FUNCTION_DECL
)
11455 gen_subprogram_die (member
, type_die
);
11456 else if (TREE_CODE (member
) == FIELD_DECL
)
11458 /* Ignore the nameless fields that are used to skip bits but handle
11459 C++ anonymous unions and structs. */
11460 if (DECL_NAME (member
) != NULL_TREE
11461 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
11462 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
11464 gen_type_die (member_declared_type (member
), type_die
);
11465 gen_field_die (member
, type_die
);
11469 gen_variable_die (member
, type_die
);
11475 /* Generate the DWARF2 info for the "abstract" instance of a function which we
11476 may later generate inlined and/or out-of-line instances of. */
11479 dwarf2out_abstract_function (tree decl
)
11481 dw_die_ref old_die
;
11484 int was_abstract
= DECL_ABSTRACT (decl
);
11486 /* Make sure we have the actual abstract inline, not a clone. */
11487 decl
= DECL_ORIGIN (decl
);
11489 old_die
= lookup_decl_die (decl
);
11490 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
11491 /* We've already generated the abstract instance. */
11494 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
11495 we don't get confused by DECL_ABSTRACT. */
11496 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11498 context
= decl_class_context (decl
);
11500 gen_type_die_for_member
11501 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
11504 /* Pretend we've just finished compiling this function. */
11505 save_fn
= current_function_decl
;
11506 current_function_decl
= decl
;
11508 set_decl_abstract_flags (decl
, 1);
11509 dwarf2out_decl (decl
);
11510 if (! was_abstract
)
11511 set_decl_abstract_flags (decl
, 0);
11513 current_function_decl
= save_fn
;
11516 /* Helper function of premark_used_types() which gets called through
11517 htab_traverse_resize().
11519 Marks the DIE of a given type in *SLOT as perennial, so it never gets
11520 marked as unused by prune_unused_types. */
11522 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
11528 die
= lookup_type_die (type
);
11530 die
->die_perennial_p
= 1;
11534 /* Mark all members of used_types_hash as perennial. */
11536 premark_used_types (void)
11538 if (cfun
&& cfun
->used_types_hash
)
11539 htab_traverse (cfun
->used_types_hash
, premark_used_types_helper
, NULL
);
11542 /* Generate a DIE to represent a declared function (either file-scope or
11546 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
11548 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
11549 tree origin
= decl_ultimate_origin (decl
);
11550 dw_die_ref subr_die
;
11553 dw_die_ref old_die
= lookup_decl_die (decl
);
11554 int declaration
= (current_function_decl
!= decl
11555 || class_or_namespace_scope_p (context_die
));
11557 premark_used_types();
11559 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
11560 started to generate the abstract instance of an inline, decided to output
11561 its containing class, and proceeded to emit the declaration of the inline
11562 from the member list for the class. If so, DECLARATION takes priority;
11563 we'll get back to the abstract instance when done with the class. */
11565 /* The class-scope declaration DIE must be the primary DIE. */
11566 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
11569 gcc_assert (!old_die
);
11572 /* Now that the C++ front end lazily declares artificial member fns, we
11573 might need to retrofit the declaration into its class. */
11574 if (!declaration
&& !origin
&& !old_die
11575 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
11576 && !class_or_namespace_scope_p (context_die
)
11577 && debug_info_level
> DINFO_LEVEL_TERSE
)
11578 old_die
= force_decl_die (decl
);
11580 if (origin
!= NULL
)
11582 gcc_assert (!declaration
|| local_scope_p (context_die
));
11584 /* Fixup die_parent for the abstract instance of a nested
11585 inline function. */
11586 if (old_die
&& old_die
->die_parent
== NULL
)
11587 add_child_die (context_die
, old_die
);
11589 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11590 add_abstract_origin_attribute (subr_die
, origin
);
11594 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
11595 unsigned file_index
= lookup_filename (s
.file
);
11597 if (!get_AT_flag (old_die
, DW_AT_declaration
)
11598 /* We can have a normal definition following an inline one in the
11599 case of redefinition of GNU C extern inlines.
11600 It seems reasonable to use AT_specification in this case. */
11601 && !get_AT (old_die
, DW_AT_inline
))
11603 /* Detect and ignore this case, where we are trying to output
11604 something we have already output. */
11608 /* If the definition comes from the same place as the declaration,
11609 maybe use the old DIE. We always want the DIE for this function
11610 that has the *_pc attributes to be under comp_unit_die so the
11611 debugger can find it. We also need to do this for abstract
11612 instances of inlines, since the spec requires the out-of-line copy
11613 to have the same parent. For local class methods, this doesn't
11614 apply; we just use the old DIE. */
11615 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
11616 && (DECL_ARTIFICIAL (decl
)
11617 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
11618 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11619 == (unsigned) s
.line
))))
11621 subr_die
= old_die
;
11623 /* Clear out the declaration attribute and the formal parameters.
11624 Do not remove all children, because it is possible that this
11625 declaration die was forced using force_decl_die(). In such
11626 cases die that forced declaration die (e.g. TAG_imported_module)
11627 is one of the children that we do not want to remove. */
11628 remove_AT (subr_die
, DW_AT_declaration
);
11629 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
11633 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11634 add_AT_specification (subr_die
, old_die
);
11635 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
11636 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
11637 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11638 != (unsigned) s
.line
)
11640 (subr_die
, DW_AT_decl_line
, s
.line
);
11645 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11647 if (TREE_PUBLIC (decl
))
11648 add_AT_flag (subr_die
, DW_AT_external
, 1);
11650 add_name_and_src_coords_attributes (subr_die
, decl
);
11651 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11653 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
11654 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
11655 0, 0, context_die
);
11658 add_pure_or_virtual_attribute (subr_die
, decl
);
11659 if (DECL_ARTIFICIAL (decl
))
11660 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
11662 if (TREE_PROTECTED (decl
))
11663 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11664 else if (TREE_PRIVATE (decl
))
11665 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11670 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
11672 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
11674 /* The first time we see a member function, it is in the context of
11675 the class to which it belongs. We make sure of this by emitting
11676 the class first. The next time is the definition, which is
11677 handled above. The two may come from the same source text.
11679 Note that force_decl_die() forces function declaration die. It is
11680 later reused to represent definition. */
11681 equate_decl_number_to_die (decl
, subr_die
);
11684 else if (DECL_ABSTRACT (decl
))
11686 if (DECL_DECLARED_INLINE_P (decl
))
11688 if (cgraph_function_possibly_inlined_p (decl
))
11689 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
11691 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
11695 if (cgraph_function_possibly_inlined_p (decl
))
11696 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
11698 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
11701 equate_decl_number_to_die (decl
, subr_die
);
11703 else if (!DECL_EXTERNAL (decl
))
11705 HOST_WIDE_INT cfa_fb_offset
;
11707 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
11708 equate_decl_number_to_die (decl
, subr_die
);
11710 if (!flag_reorder_blocks_and_partition
)
11712 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
11713 current_function_funcdef_no
);
11714 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
11715 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
11716 current_function_funcdef_no
);
11717 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
11719 add_pubname (decl
, subr_die
);
11720 add_arange (decl
, subr_die
);
11723 { /* Do nothing for now; maybe need to duplicate die, one for
11724 hot section and ond for cold section, then use the hot/cold
11725 section begin/end labels to generate the aranges... */
11727 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
11728 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
11729 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
11730 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
11732 add_pubname (decl, subr_die);
11733 add_arange (decl, subr_die);
11734 add_arange (decl, subr_die);
11738 #ifdef MIPS_DEBUGGING_INFO
11739 /* Add a reference to the FDE for this routine. */
11740 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
11743 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
11745 /* We define the "frame base" as the function's CFA. This is more
11746 convenient for several reasons: (1) It's stable across the prologue
11747 and epilogue, which makes it better than just a frame pointer,
11748 (2) With dwarf3, there exists a one-byte encoding that allows us
11749 to reference the .debug_frame data by proxy, but failing that,
11750 (3) We can at least reuse the code inspection and interpretation
11751 code that determines the CFA position at various points in the
11753 /* ??? Use some command-line or configury switch to enable the use
11754 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
11755 consumers that understand it; fall back to "pure" dwarf2 and
11756 convert the CFA data into a location list. */
11758 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
11759 if (list
->dw_loc_next
)
11760 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
11762 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
11765 /* Compute a displacement from the "steady-state frame pointer" to
11766 the CFA. The former is what all stack slots and argument slots
11767 will reference in the rtl; the later is what we've told the
11768 debugger about. We'll need to adjust all frame_base references
11769 by this displacement. */
11770 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
11772 if (cfun
->static_chain_decl
)
11773 add_AT_location_description (subr_die
, DW_AT_static_link
,
11774 loc_descriptor_from_tree (cfun
->static_chain_decl
));
11777 /* Now output descriptions of the arguments for this function. This gets
11778 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
11779 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
11780 `...' at the end of the formal parameter list. In order to find out if
11781 there was a trailing ellipsis or not, we must instead look at the type
11782 associated with the FUNCTION_DECL. This will be a node of type
11783 FUNCTION_TYPE. If the chain of type nodes hanging off of this
11784 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
11785 an ellipsis at the end. */
11787 /* In the case where we are describing a mere function declaration, all we
11788 need to do here (and all we *can* do here) is to describe the *types* of
11789 its formal parameters. */
11790 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11792 else if (declaration
)
11793 gen_formal_types_die (decl
, subr_die
);
11796 /* Generate DIEs to represent all known formal parameters. */
11797 tree arg_decls
= DECL_ARGUMENTS (decl
);
11800 /* When generating DIEs, generate the unspecified_parameters DIE
11801 instead if we come across the arg "__builtin_va_alist" */
11802 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
11803 if (TREE_CODE (parm
) == PARM_DECL
)
11805 if (DECL_NAME (parm
)
11806 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
11807 "__builtin_va_alist"))
11808 gen_unspecified_parameters_die (parm
, subr_die
);
11810 gen_decl_die (parm
, subr_die
);
11813 /* Decide whether we need an unspecified_parameters DIE at the end.
11814 There are 2 more cases to do this for: 1) the ansi ... declaration -
11815 this is detectable when the end of the arg list is not a
11816 void_type_node 2) an unprototyped function declaration (not a
11817 definition). This just means that we have no info about the
11818 parameters at all. */
11819 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
11820 if (fn_arg_types
!= NULL
)
11822 /* This is the prototyped case, check for.... */
11823 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
11824 gen_unspecified_parameters_die (decl
, subr_die
);
11826 else if (DECL_INITIAL (decl
) == NULL_TREE
)
11827 gen_unspecified_parameters_die (decl
, subr_die
);
11830 /* Output Dwarf info for all of the stuff within the body of the function
11831 (if it has one - it may be just a declaration). */
11832 outer_scope
= DECL_INITIAL (decl
);
11834 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
11835 a function. This BLOCK actually represents the outermost binding contour
11836 for the function, i.e. the contour in which the function's formal
11837 parameters and labels get declared. Curiously, it appears that the front
11838 end doesn't actually put the PARM_DECL nodes for the current function onto
11839 the BLOCK_VARS list for this outer scope, but are strung off of the
11840 DECL_ARGUMENTS list for the function instead.
11842 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
11843 the LABEL_DECL nodes for the function however, and we output DWARF info
11844 for those in decls_for_scope. Just within the `outer_scope' there will be
11845 a BLOCK node representing the function's outermost pair of curly braces,
11846 and any blocks used for the base and member initializers of a C++
11847 constructor function. */
11848 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
11850 /* Emit a DW_TAG_variable DIE for a named return value. */
11851 if (DECL_NAME (DECL_RESULT (decl
)))
11852 gen_decl_die (DECL_RESULT (decl
), subr_die
);
11854 current_function_has_inlines
= 0;
11855 decls_for_scope (outer_scope
, subr_die
, 0);
11857 #if 0 && defined (MIPS_DEBUGGING_INFO)
11858 if (current_function_has_inlines
)
11860 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
11861 if (! comp_unit_has_inlines
)
11863 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
11864 comp_unit_has_inlines
= 1;
11869 /* Add the calling convention attribute if requested. */
11870 add_calling_convention_attribute (subr_die
, TREE_TYPE (decl
));
11874 /* Generate a DIE to represent a declared data object. */
11877 gen_variable_die (tree decl
, dw_die_ref context_die
)
11879 tree origin
= decl_ultimate_origin (decl
);
11880 dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
11882 dw_die_ref old_die
= lookup_decl_die (decl
);
11883 int declaration
= (DECL_EXTERNAL (decl
)
11884 /* If DECL is COMDAT and has not actually been
11885 emitted, we cannot take its address; there
11886 might end up being no definition anywhere in
11887 the program. For example, consider the C++
11891 struct S { static const int i = 7; };
11896 int f() { return S<int>::i; }
11898 Here, S<int>::i is not DECL_EXTERNAL, but no
11899 definition is required, so the compiler will
11900 not emit a definition. */
11901 || (TREE_CODE (decl
) == VAR_DECL
11902 && DECL_COMDAT (decl
) && !TREE_ASM_WRITTEN (decl
))
11903 || class_or_namespace_scope_p (context_die
));
11905 if (origin
!= NULL
)
11906 add_abstract_origin_attribute (var_die
, origin
);
11908 /* Loop unrolling can create multiple blocks that refer to the same
11909 static variable, so we must test for the DW_AT_declaration flag.
11911 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
11912 copy decls and set the DECL_ABSTRACT flag on them instead of
11915 ??? Duplicated blocks have been rewritten to use .debug_ranges.
11917 ??? The declare_in_namespace support causes us to get two DIEs for one
11918 variable, both of which are declarations. We want to avoid considering
11919 one to be a specification, so we must test that this DIE is not a
11921 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
11922 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
11924 /* This is a definition of a C++ class level static. */
11925 add_AT_specification (var_die
, old_die
);
11926 if (DECL_NAME (decl
))
11928 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
11929 unsigned file_index
= lookup_filename (s
.file
);
11931 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
11932 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
11934 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11935 != (unsigned) s
.line
)
11937 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
11942 add_name_and_src_coords_attributes (var_die
, decl
);
11943 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
11944 TREE_THIS_VOLATILE (decl
), context_die
);
11946 if (TREE_PUBLIC (decl
))
11947 add_AT_flag (var_die
, DW_AT_external
, 1);
11949 if (DECL_ARTIFICIAL (decl
))
11950 add_AT_flag (var_die
, DW_AT_artificial
, 1);
11952 if (TREE_PROTECTED (decl
))
11953 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11954 else if (TREE_PRIVATE (decl
))
11955 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11959 add_AT_flag (var_die
, DW_AT_declaration
, 1);
11961 if (DECL_ABSTRACT (decl
) || declaration
)
11962 equate_decl_number_to_die (decl
, var_die
);
11964 if (! declaration
&& ! DECL_ABSTRACT (decl
))
11966 add_location_or_const_value_attribute (var_die
, decl
, DW_AT_location
);
11967 add_pubname (decl
, var_die
);
11970 tree_add_const_value_attribute (var_die
, decl
);
11973 /* Generate a DIE to represent a label identifier. */
11976 gen_label_die (tree decl
, dw_die_ref context_die
)
11978 tree origin
= decl_ultimate_origin (decl
);
11979 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
11981 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11983 if (origin
!= NULL
)
11984 add_abstract_origin_attribute (lbl_die
, origin
);
11986 add_name_and_src_coords_attributes (lbl_die
, decl
);
11988 if (DECL_ABSTRACT (decl
))
11989 equate_decl_number_to_die (decl
, lbl_die
);
11992 insn
= DECL_RTL_IF_SET (decl
);
11994 /* Deleted labels are programmer specified labels which have been
11995 eliminated because of various optimizations. We still emit them
11996 here so that it is possible to put breakpoints on them. */
12000 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
))))
12002 /* When optimization is enabled (via -O) some parts of the compiler
12003 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
12004 represent source-level labels which were explicitly declared by
12005 the user. This really shouldn't be happening though, so catch
12006 it if it ever does happen. */
12007 gcc_assert (!INSN_DELETED_P (insn
));
12009 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
12010 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
12015 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
12016 attributes to the DIE for a block STMT, to describe where the inlined
12017 function was called from. This is similar to add_src_coords_attributes. */
12020 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
12022 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
12023 unsigned file_index
= lookup_filename (s
.file
);
12025 add_AT_unsigned (die
, DW_AT_call_file
, file_index
);
12026 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
12029 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
12030 Add low_pc and high_pc attributes to the DIE for a block STMT. */
12033 add_high_low_attributes (tree stmt
, dw_die_ref die
)
12035 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12037 if (BLOCK_FRAGMENT_CHAIN (stmt
))
12041 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
12043 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
12046 add_ranges (chain
);
12047 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
12054 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
12055 BLOCK_NUMBER (stmt
));
12056 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
12057 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
12058 BLOCK_NUMBER (stmt
));
12059 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
12063 /* Generate a DIE for a lexical block. */
12066 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
12068 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
12070 if (! BLOCK_ABSTRACT (stmt
))
12071 add_high_low_attributes (stmt
, stmt_die
);
12073 decls_for_scope (stmt
, stmt_die
, depth
);
12076 /* Generate a DIE for an inlined subprogram. */
12079 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
12081 tree decl
= block_ultimate_origin (stmt
);
12083 /* Emit info for the abstract instance first, if we haven't yet. We
12084 must emit this even if the block is abstract, otherwise when we
12085 emit the block below (or elsewhere), we may end up trying to emit
12086 a die whose origin die hasn't been emitted, and crashing. */
12087 dwarf2out_abstract_function (decl
);
12089 if (! BLOCK_ABSTRACT (stmt
))
12091 dw_die_ref subr_die
12092 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
12094 add_abstract_origin_attribute (subr_die
, decl
);
12095 add_high_low_attributes (stmt
, subr_die
);
12096 add_call_src_coords_attributes (stmt
, subr_die
);
12098 decls_for_scope (stmt
, subr_die
, depth
);
12099 current_function_has_inlines
= 1;
12102 /* We may get here if we're the outer block of function A that was
12103 inlined into function B that was inlined into function C. When
12104 generating debugging info for C, dwarf2out_abstract_function(B)
12105 would mark all inlined blocks as abstract, including this one.
12106 So, we wouldn't (and shouldn't) expect labels to be generated
12107 for this one. Instead, just emit debugging info for
12108 declarations within the block. This is particularly important
12109 in the case of initializers of arguments passed from B to us:
12110 if they're statement expressions containing declarations, we
12111 wouldn't generate dies for their abstract variables, and then,
12112 when generating dies for the real variables, we'd die (pun
12114 gen_lexical_block_die (stmt
, context_die
, depth
);
12117 /* Generate a DIE for a field in a record, or structure. */
12120 gen_field_die (tree decl
, dw_die_ref context_die
)
12122 dw_die_ref decl_die
;
12124 if (TREE_TYPE (decl
) == error_mark_node
)
12127 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
12128 add_name_and_src_coords_attributes (decl_die
, decl
);
12129 add_type_attribute (decl_die
, member_declared_type (decl
),
12130 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
12133 if (DECL_BIT_FIELD_TYPE (decl
))
12135 add_byte_size_attribute (decl_die
, decl
);
12136 add_bit_size_attribute (decl_die
, decl
);
12137 add_bit_offset_attribute (decl_die
, decl
);
12140 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
12141 add_data_member_location_attribute (decl_die
, decl
);
12143 if (DECL_ARTIFICIAL (decl
))
12144 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
12146 if (TREE_PROTECTED (decl
))
12147 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
12148 else if (TREE_PRIVATE (decl
))
12149 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
12151 /* Equate decl number to die, so that we can look up this decl later on. */
12152 equate_decl_number_to_die (decl
, decl_die
);
12156 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12157 Use modified_type_die instead.
12158 We keep this code here just in case these types of DIEs may be needed to
12159 represent certain things in other languages (e.g. Pascal) someday. */
12162 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
12165 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
12167 equate_type_number_to_die (type
, ptr_die
);
12168 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
12169 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
12172 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12173 Use modified_type_die instead.
12174 We keep this code here just in case these types of DIEs may be needed to
12175 represent certain things in other languages (e.g. Pascal) someday. */
12178 gen_reference_type_die (tree type
, dw_die_ref context_die
)
12181 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
12183 equate_type_number_to_die (type
, ref_die
);
12184 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
12185 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
12189 /* Generate a DIE for a pointer to a member type. */
12192 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
12195 = new_die (DW_TAG_ptr_to_member_type
,
12196 scope_die_for (type
, context_die
), type
);
12198 equate_type_number_to_die (type
, ptr_die
);
12199 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
12200 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
12201 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
12204 /* Generate the DIE for the compilation unit. */
12207 gen_compile_unit_die (const char *filename
)
12210 char producer
[250];
12211 const char *language_string
= lang_hooks
.name
;
12214 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
12218 add_name_attribute (die
, filename
);
12219 /* Don't add cwd for <built-in>. */
12220 if (filename
[0] != DIR_SEPARATOR
&& filename
[0] != '<')
12221 add_comp_dir_attribute (die
);
12224 sprintf (producer
, "%s %s", language_string
, version_string
);
12226 #ifdef MIPS_DEBUGGING_INFO
12227 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
12228 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
12229 not appear in the producer string, the debugger reaches the conclusion
12230 that the object file is stripped and has no debugging information.
12231 To get the MIPS/SGI debugger to believe that there is debugging
12232 information in the object file, we add a -g to the producer string. */
12233 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12234 strcat (producer
, " -g");
12237 add_AT_string (die
, DW_AT_producer
, producer
);
12239 if (strcmp (language_string
, "GNU C++") == 0)
12240 language
= DW_LANG_C_plus_plus
;
12241 else if (strcmp (language_string
, "GNU Ada") == 0)
12242 language
= DW_LANG_Ada95
;
12243 else if (strcmp (language_string
, "GNU F77") == 0)
12244 language
= DW_LANG_Fortran77
;
12245 else if (strcmp (language_string
, "GNU F95") == 0)
12246 language
= DW_LANG_Fortran95
;
12247 else if (strcmp (language_string
, "GNU Pascal") == 0)
12248 language
= DW_LANG_Pascal83
;
12249 else if (strcmp (language_string
, "GNU Java") == 0)
12250 language
= DW_LANG_Java
;
12251 else if (strcmp (language_string
, "GNU Objective-C") == 0)
12252 language
= DW_LANG_ObjC
;
12253 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
12254 language
= DW_LANG_ObjC_plus_plus
;
12256 language
= DW_LANG_C89
;
12258 add_AT_unsigned (die
, DW_AT_language
, language
);
12262 /* Generate the DIE for a base class. */
12265 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
12267 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
12269 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
12270 add_data_member_location_attribute (die
, binfo
);
12272 if (BINFO_VIRTUAL_P (binfo
))
12273 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
12275 if (access
== access_public_node
)
12276 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
12277 else if (access
== access_protected_node
)
12278 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
12281 /* Generate a DIE for a class member. */
12284 gen_member_die (tree type
, dw_die_ref context_die
)
12287 tree binfo
= TYPE_BINFO (type
);
12290 /* If this is not an incomplete type, output descriptions of each of its
12291 members. Note that as we output the DIEs necessary to represent the
12292 members of this record or union type, we will also be trying to output
12293 DIEs to represent the *types* of those members. However the `type'
12294 function (above) will specifically avoid generating type DIEs for member
12295 types *within* the list of member DIEs for this (containing) type except
12296 for those types (of members) which are explicitly marked as also being
12297 members of this (containing) type themselves. The g++ front- end can
12298 force any given type to be treated as a member of some other (containing)
12299 type by setting the TYPE_CONTEXT of the given (member) type to point to
12300 the TREE node representing the appropriate (containing) type. */
12302 /* First output info about the base classes. */
12305 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
12309 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
12310 gen_inheritance_die (base
,
12311 (accesses
? VEC_index (tree
, accesses
, i
)
12312 : access_public_node
), context_die
);
12315 /* Now output info about the data members and type members. */
12316 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
12318 /* If we thought we were generating minimal debug info for TYPE
12319 and then changed our minds, some of the member declarations
12320 may have already been defined. Don't define them again, but
12321 do put them in the right order. */
12323 child
= lookup_decl_die (member
);
12325 splice_child_die (context_die
, child
);
12327 gen_decl_die (member
, context_die
);
12330 /* Now output info about the function members (if any). */
12331 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
12333 /* Don't include clones in the member list. */
12334 if (DECL_ABSTRACT_ORIGIN (member
))
12337 child
= lookup_decl_die (member
);
12339 splice_child_die (context_die
, child
);
12341 gen_decl_die (member
, context_die
);
12345 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
12346 is set, we pretend that the type was never defined, so we only get the
12347 member DIEs needed by later specification DIEs. */
12350 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
)
12352 dw_die_ref type_die
= lookup_type_die (type
);
12353 dw_die_ref scope_die
= 0;
12355 int complete
= (TYPE_SIZE (type
)
12356 && (! TYPE_STUB_DECL (type
)
12357 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
12358 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
12360 if (type_die
&& ! complete
)
12363 if (TYPE_CONTEXT (type
) != NULL_TREE
12364 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
12365 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
12368 scope_die
= scope_die_for (type
, context_die
);
12370 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
12371 /* First occurrence of type or toplevel definition of nested class. */
12373 dw_die_ref old_die
= type_die
;
12375 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
12376 ? DW_TAG_structure_type
: DW_TAG_union_type
,
12378 equate_type_number_to_die (type
, type_die
);
12380 add_AT_specification (type_die
, old_die
);
12382 add_name_attribute (type_die
, type_tag (type
));
12385 remove_AT (type_die
, DW_AT_declaration
);
12387 /* If this type has been completed, then give it a byte_size attribute and
12388 then give a list of members. */
12389 if (complete
&& !ns_decl
)
12391 /* Prevent infinite recursion in cases where the type of some member of
12392 this type is expressed in terms of this type itself. */
12393 TREE_ASM_WRITTEN (type
) = 1;
12394 add_byte_size_attribute (type_die
, type
);
12395 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
12396 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
12398 /* If the first reference to this type was as the return type of an
12399 inline function, then it may not have a parent. Fix this now. */
12400 if (type_die
->die_parent
== NULL
)
12401 add_child_die (scope_die
, type_die
);
12403 push_decl_scope (type
);
12404 gen_member_die (type
, type_die
);
12407 /* GNU extension: Record what type our vtable lives in. */
12408 if (TYPE_VFIELD (type
))
12410 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
12412 gen_type_die (vtype
, context_die
);
12413 add_AT_die_ref (type_die
, DW_AT_containing_type
,
12414 lookup_type_die (vtype
));
12419 add_AT_flag (type_die
, DW_AT_declaration
, 1);
12421 /* We don't need to do this for function-local types. */
12422 if (TYPE_STUB_DECL (type
)
12423 && ! decl_function_context (TYPE_STUB_DECL (type
)))
12424 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
12428 /* Generate a DIE for a subroutine _type_. */
12431 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
12433 tree return_type
= TREE_TYPE (type
);
12434 dw_die_ref subr_die
12435 = new_die (DW_TAG_subroutine_type
,
12436 scope_die_for (type
, context_die
), type
);
12438 equate_type_number_to_die (type
, subr_die
);
12439 add_prototyped_attribute (subr_die
, type
);
12440 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
12441 gen_formal_types_die (type
, subr_die
);
12444 /* Generate a DIE for a type definition. */
12447 gen_typedef_die (tree decl
, dw_die_ref context_die
)
12449 dw_die_ref type_die
;
12452 if (TREE_ASM_WRITTEN (decl
))
12455 TREE_ASM_WRITTEN (decl
) = 1;
12456 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
12457 origin
= decl_ultimate_origin (decl
);
12458 if (origin
!= NULL
)
12459 add_abstract_origin_attribute (type_die
, origin
);
12464 add_name_and_src_coords_attributes (type_die
, decl
);
12465 if (DECL_ORIGINAL_TYPE (decl
))
12467 type
= DECL_ORIGINAL_TYPE (decl
);
12469 gcc_assert (type
!= TREE_TYPE (decl
));
12470 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
12473 type
= TREE_TYPE (decl
);
12475 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
12476 TREE_THIS_VOLATILE (decl
), context_die
);
12479 if (DECL_ABSTRACT (decl
))
12480 equate_decl_number_to_die (decl
, type_die
);
12483 /* Generate a type description DIE. */
12486 gen_type_die (tree type
, dw_die_ref context_die
)
12490 if (type
== NULL_TREE
|| type
== error_mark_node
)
12493 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12494 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
12496 if (TREE_ASM_WRITTEN (type
))
12499 /* Prevent broken recursion; we can't hand off to the same type. */
12500 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
12502 TREE_ASM_WRITTEN (type
) = 1;
12503 gen_decl_die (TYPE_NAME (type
), context_die
);
12507 /* We are going to output a DIE to represent the unqualified version
12508 of this type (i.e. without any const or volatile qualifiers) so
12509 get the main variant (i.e. the unqualified version) of this type
12510 now. (Vectors are special because the debugging info is in the
12511 cloned type itself). */
12512 if (TREE_CODE (type
) != VECTOR_TYPE
)
12513 type
= type_main_variant (type
);
12515 if (TREE_ASM_WRITTEN (type
))
12518 switch (TREE_CODE (type
))
12524 case REFERENCE_TYPE
:
12525 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
12526 ensures that the gen_type_die recursion will terminate even if the
12527 type is recursive. Recursive types are possible in Ada. */
12528 /* ??? We could perhaps do this for all types before the switch
12530 TREE_ASM_WRITTEN (type
) = 1;
12532 /* For these types, all that is required is that we output a DIE (or a
12533 set of DIEs) to represent the "basis" type. */
12534 gen_type_die (TREE_TYPE (type
), context_die
);
12538 /* This code is used for C++ pointer-to-data-member types.
12539 Output a description of the relevant class type. */
12540 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
12542 /* Output a description of the type of the object pointed to. */
12543 gen_type_die (TREE_TYPE (type
), context_die
);
12545 /* Now output a DIE to represent this pointer-to-data-member type
12547 gen_ptr_to_mbr_type_die (type
, context_die
);
12550 case FUNCTION_TYPE
:
12551 /* Force out return type (in case it wasn't forced out already). */
12552 gen_type_die (TREE_TYPE (type
), context_die
);
12553 gen_subroutine_type_die (type
, context_die
);
12557 /* Force out return type (in case it wasn't forced out already). */
12558 gen_type_die (TREE_TYPE (type
), context_die
);
12559 gen_subroutine_type_die (type
, context_die
);
12563 gen_array_type_die (type
, context_die
);
12567 gen_array_type_die (type
, context_die
);
12570 case ENUMERAL_TYPE
:
12573 case QUAL_UNION_TYPE
:
12574 /* If this is a nested type whose containing class hasn't been written
12575 out yet, writing it out will cover this one, too. This does not apply
12576 to instantiations of member class templates; they need to be added to
12577 the containing class as they are generated. FIXME: This hurts the
12578 idea of combining type decls from multiple TUs, since we can't predict
12579 what set of template instantiations we'll get. */
12580 if (TYPE_CONTEXT (type
)
12581 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
12582 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
12584 gen_type_die (TYPE_CONTEXT (type
), context_die
);
12586 if (TREE_ASM_WRITTEN (type
))
12589 /* If that failed, attach ourselves to the stub. */
12590 push_decl_scope (TYPE_CONTEXT (type
));
12591 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
12596 declare_in_namespace (type
, context_die
);
12600 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
12601 gen_enumeration_type_die (type
, context_die
);
12603 gen_struct_or_union_type_die (type
, context_die
);
12608 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
12609 it up if it is ever completed. gen_*_type_die will set it for us
12610 when appropriate. */
12618 /* No DIEs needed for fundamental types. */
12622 /* No Dwarf representation currently defined. */
12626 gcc_unreachable ();
12629 TREE_ASM_WRITTEN (type
) = 1;
12632 /* Generate a DIE for a tagged type instantiation. */
12635 gen_tagged_type_instantiation_die (tree type
, dw_die_ref context_die
)
12637 if (type
== NULL_TREE
|| type
== error_mark_node
)
12640 /* We are going to output a DIE to represent the unqualified version of
12641 this type (i.e. without any const or volatile qualifiers) so make sure
12642 that we have the main variant (i.e. the unqualified version) of this
12644 gcc_assert (type
== type_main_variant (type
));
12646 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
12647 an instance of an unresolved type. */
12649 switch (TREE_CODE (type
))
12654 case ENUMERAL_TYPE
:
12655 gen_inlined_enumeration_type_die (type
, context_die
);
12659 gen_inlined_structure_type_die (type
, context_die
);
12663 case QUAL_UNION_TYPE
:
12664 gen_inlined_union_type_die (type
, context_die
);
12668 gcc_unreachable ();
12672 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
12673 things which are local to the given block. */
12676 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
12678 int must_output_die
= 0;
12681 enum tree_code origin_code
;
12683 /* Ignore blocks that are NULL. */
12684 if (stmt
== NULL_TREE
)
12687 /* If the block is one fragment of a non-contiguous block, do not
12688 process the variables, since they will have been done by the
12689 origin block. Do process subblocks. */
12690 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
12694 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
12695 gen_block_die (sub
, context_die
, depth
+ 1);
12700 /* Determine the "ultimate origin" of this block. This block may be an
12701 inlined instance of an inlined instance of inline function, so we have
12702 to trace all of the way back through the origin chain to find out what
12703 sort of node actually served as the original seed for the creation of
12704 the current block. */
12705 origin
= block_ultimate_origin (stmt
);
12706 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
12708 /* Determine if we need to output any Dwarf DIEs at all to represent this
12710 if (origin_code
== FUNCTION_DECL
)
12711 /* The outer scopes for inlinings *must* always be represented. We
12712 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
12713 must_output_die
= 1;
12716 /* In the case where the current block represents an inlining of the
12717 "body block" of an inline function, we must *NOT* output any DIE for
12718 this block because we have already output a DIE to represent the whole
12719 inlined function scope and the "body block" of any function doesn't
12720 really represent a different scope according to ANSI C rules. So we
12721 check here to make sure that this block does not represent a "body
12722 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
12723 if (! is_body_block (origin
? origin
: stmt
))
12725 /* Determine if this block directly contains any "significant"
12726 local declarations which we will need to output DIEs for. */
12727 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12728 /* We are not in terse mode so *any* local declaration counts
12729 as being a "significant" one. */
12730 must_output_die
= (BLOCK_VARS (stmt
) != NULL
12731 && (TREE_USED (stmt
)
12732 || TREE_ASM_WRITTEN (stmt
)
12733 || BLOCK_ABSTRACT (stmt
)));
12735 /* We are in terse mode, so only local (nested) function
12736 definitions count as "significant" local declarations. */
12737 for (decl
= BLOCK_VARS (stmt
);
12738 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
12739 if (TREE_CODE (decl
) == FUNCTION_DECL
12740 && DECL_INITIAL (decl
))
12742 must_output_die
= 1;
12748 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
12749 DIE for any block which contains no significant local declarations at
12750 all. Rather, in such cases we just call `decls_for_scope' so that any
12751 needed Dwarf info for any sub-blocks will get properly generated. Note
12752 that in terse mode, our definition of what constitutes a "significant"
12753 local declaration gets restricted to include only inlined function
12754 instances and local (nested) function definitions. */
12755 if (must_output_die
)
12757 if (origin_code
== FUNCTION_DECL
)
12758 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
12760 gen_lexical_block_die (stmt
, context_die
, depth
);
12763 decls_for_scope (stmt
, context_die
, depth
);
12766 /* Generate all of the decls declared within a given scope and (recursively)
12767 all of its sub-blocks. */
12770 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
12775 /* Ignore NULL blocks. */
12776 if (stmt
== NULL_TREE
)
12779 if (TREE_USED (stmt
))
12781 /* Output the DIEs to represent all of the data objects and typedefs
12782 declared directly within this block but not within any nested
12783 sub-blocks. Also, nested function and tag DIEs have been
12784 generated with a parent of NULL; fix that up now. */
12785 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
12789 if (TREE_CODE (decl
) == FUNCTION_DECL
)
12790 die
= lookup_decl_die (decl
);
12791 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
12792 die
= lookup_type_die (TREE_TYPE (decl
));
12796 if (die
!= NULL
&& die
->die_parent
== NULL
)
12797 add_child_die (context_die
, die
);
12798 /* Do not produce debug information for static variables since
12799 these might be optimized out. We are called for these later
12800 in cgraph_varpool_analyze_pending_decls. */
12801 if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
12804 gen_decl_die (decl
, context_die
);
12808 /* If we're at -g1, we're not interested in subblocks. */
12809 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12812 /* Output the DIEs to represent all sub-blocks (and the items declared
12813 therein) of this block. */
12814 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
12816 subblocks
= BLOCK_CHAIN (subblocks
))
12817 gen_block_die (subblocks
, context_die
, depth
+ 1);
12820 /* Is this a typedef we can avoid emitting? */
12823 is_redundant_typedef (tree decl
)
12825 if (TYPE_DECL_IS_STUB (decl
))
12828 if (DECL_ARTIFICIAL (decl
)
12829 && DECL_CONTEXT (decl
)
12830 && is_tagged_type (DECL_CONTEXT (decl
))
12831 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
12832 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
12833 /* Also ignore the artificial member typedef for the class name. */
12839 /* Returns the DIE for decl. A DIE will always be returned. */
12842 force_decl_die (tree decl
)
12844 dw_die_ref decl_die
;
12845 unsigned saved_external_flag
;
12846 tree save_fn
= NULL_TREE
;
12847 decl_die
= lookup_decl_die (decl
);
12850 dw_die_ref context_die
;
12851 tree decl_context
= DECL_CONTEXT (decl
);
12854 /* Find die that represents this context. */
12855 if (TYPE_P (decl_context
))
12856 context_die
= force_type_die (decl_context
);
12858 context_die
= force_decl_die (decl_context
);
12861 context_die
= comp_unit_die
;
12863 decl_die
= lookup_decl_die (decl
);
12867 switch (TREE_CODE (decl
))
12869 case FUNCTION_DECL
:
12870 /* Clear current_function_decl, so that gen_subprogram_die thinks
12871 that this is a declaration. At this point, we just want to force
12872 declaration die. */
12873 save_fn
= current_function_decl
;
12874 current_function_decl
= NULL_TREE
;
12875 gen_subprogram_die (decl
, context_die
);
12876 current_function_decl
= save_fn
;
12880 /* Set external flag to force declaration die. Restore it after
12881 gen_decl_die() call. */
12882 saved_external_flag
= DECL_EXTERNAL (decl
);
12883 DECL_EXTERNAL (decl
) = 1;
12884 gen_decl_die (decl
, context_die
);
12885 DECL_EXTERNAL (decl
) = saved_external_flag
;
12888 case NAMESPACE_DECL
:
12889 dwarf2out_decl (decl
);
12893 gcc_unreachable ();
12896 /* We should be able to find the DIE now. */
12898 decl_die
= lookup_decl_die (decl
);
12899 gcc_assert (decl_die
);
12905 /* Returns the DIE for TYPE. A DIE is always returned. */
12908 force_type_die (tree type
)
12910 dw_die_ref type_die
;
12912 type_die
= lookup_type_die (type
);
12915 dw_die_ref context_die
;
12916 if (TYPE_CONTEXT (type
))
12918 if (TYPE_P (TYPE_CONTEXT (type
)))
12919 context_die
= force_type_die (TYPE_CONTEXT (type
));
12921 context_die
= force_decl_die (TYPE_CONTEXT (type
));
12924 context_die
= comp_unit_die
;
12926 type_die
= lookup_type_die (type
);
12929 gen_type_die (type
, context_die
);
12930 type_die
= lookup_type_die (type
);
12931 gcc_assert (type_die
);
12936 /* Force out any required namespaces to be able to output DECL,
12937 and return the new context_die for it, if it's changed. */
12940 setup_namespace_context (tree thing
, dw_die_ref context_die
)
12942 tree context
= (DECL_P (thing
)
12943 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
12944 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
12945 /* Force out the namespace. */
12946 context_die
= force_decl_die (context
);
12948 return context_die
;
12951 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
12952 type) within its namespace, if appropriate.
12954 For compatibility with older debuggers, namespace DIEs only contain
12955 declarations; all definitions are emitted at CU scope. */
12958 declare_in_namespace (tree thing
, dw_die_ref context_die
)
12960 dw_die_ref ns_context
;
12962 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12965 /* If this decl is from an inlined function, then don't try to emit it in its
12966 namespace, as we will get confused. It would have already been emitted
12967 when the abstract instance of the inline function was emitted anyways. */
12968 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
12971 ns_context
= setup_namespace_context (thing
, context_die
);
12973 if (ns_context
!= context_die
)
12975 if (DECL_P (thing
))
12976 gen_decl_die (thing
, ns_context
);
12978 gen_type_die (thing
, ns_context
);
12982 /* Generate a DIE for a namespace or namespace alias. */
12985 gen_namespace_die (tree decl
)
12987 dw_die_ref context_die
= setup_namespace_context (decl
, comp_unit_die
);
12989 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
12990 they are an alias of. */
12991 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
12993 /* Output a real namespace. */
12994 dw_die_ref namespace_die
12995 = new_die (DW_TAG_namespace
, context_die
, decl
);
12996 add_name_and_src_coords_attributes (namespace_die
, decl
);
12997 equate_decl_number_to_die (decl
, namespace_die
);
13001 /* Output a namespace alias. */
13003 /* Force out the namespace we are an alias of, if necessary. */
13004 dw_die_ref origin_die
13005 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
13007 /* Now create the namespace alias DIE. */
13008 dw_die_ref namespace_die
13009 = new_die (DW_TAG_imported_declaration
, context_die
, decl
);
13010 add_name_and_src_coords_attributes (namespace_die
, decl
);
13011 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
13012 equate_decl_number_to_die (decl
, namespace_die
);
13016 /* Generate Dwarf debug information for a decl described by DECL. */
13019 gen_decl_die (tree decl
, dw_die_ref context_die
)
13023 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
13026 switch (TREE_CODE (decl
))
13032 /* The individual enumerators of an enum type get output when we output
13033 the Dwarf representation of the relevant enum type itself. */
13036 case FUNCTION_DECL
:
13037 /* Don't output any DIEs to represent mere function declarations,
13038 unless they are class members or explicit block externs. */
13039 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
13040 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
13045 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
13046 on local redeclarations of global functions. That seems broken. */
13047 if (current_function_decl
!= decl
)
13048 /* This is only a declaration. */;
13051 /* If we're emitting a clone, emit info for the abstract instance. */
13052 if (DECL_ORIGIN (decl
) != decl
)
13053 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
13055 /* If we're emitting an out-of-line copy of an inline function,
13056 emit info for the abstract instance and set up to refer to it. */
13057 else if (cgraph_function_possibly_inlined_p (decl
)
13058 && ! DECL_ABSTRACT (decl
)
13059 && ! class_or_namespace_scope_p (context_die
)
13060 /* dwarf2out_abstract_function won't emit a die if this is just
13061 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
13062 that case, because that works only if we have a die. */
13063 && DECL_INITIAL (decl
) != NULL_TREE
)
13065 dwarf2out_abstract_function (decl
);
13066 set_decl_origin_self (decl
);
13069 /* Otherwise we're emitting the primary DIE for this decl. */
13070 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
13072 /* Before we describe the FUNCTION_DECL itself, make sure that we
13073 have described its return type. */
13074 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
13076 /* And its virtual context. */
13077 if (DECL_VINDEX (decl
) != NULL_TREE
)
13078 gen_type_die (DECL_CONTEXT (decl
), context_die
);
13080 /* And its containing type. */
13081 origin
= decl_class_context (decl
);
13082 if (origin
!= NULL_TREE
)
13083 gen_type_die_for_member (origin
, decl
, context_die
);
13085 /* And its containing namespace. */
13086 declare_in_namespace (decl
, context_die
);
13089 /* Now output a DIE to represent the function itself. */
13090 gen_subprogram_die (decl
, context_die
);
13094 /* If we are in terse mode, don't generate any DIEs to represent any
13095 actual typedefs. */
13096 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13099 /* In the special case of a TYPE_DECL node representing the declaration
13100 of some type tag, if the given TYPE_DECL is marked as having been
13101 instantiated from some other (original) TYPE_DECL node (e.g. one which
13102 was generated within the original definition of an inline function) we
13103 have to generate a special (abbreviated) DW_TAG_structure_type,
13104 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
13105 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
13107 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
13111 if (is_redundant_typedef (decl
))
13112 gen_type_die (TREE_TYPE (decl
), context_die
);
13114 /* Output a DIE to represent the typedef itself. */
13115 gen_typedef_die (decl
, context_die
);
13119 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
13120 gen_label_die (decl
, context_die
);
13125 /* If we are in terse mode, don't generate any DIEs to represent any
13126 variable declarations or definitions. */
13127 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13130 /* Output any DIEs that are needed to specify the type of this data
13132 gen_type_die (TREE_TYPE (decl
), context_die
);
13134 /* And its containing type. */
13135 origin
= decl_class_context (decl
);
13136 if (origin
!= NULL_TREE
)
13137 gen_type_die_for_member (origin
, decl
, context_die
);
13139 /* And its containing namespace. */
13140 declare_in_namespace (decl
, context_die
);
13142 /* Now output the DIE to represent the data object itself. This gets
13143 complicated because of the possibility that the VAR_DECL really
13144 represents an inlined instance of a formal parameter for an inline
13146 origin
= decl_ultimate_origin (decl
);
13147 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
13148 gen_formal_parameter_die (decl
, context_die
);
13150 gen_variable_die (decl
, context_die
);
13154 /* Ignore the nameless fields that are used to skip bits but handle C++
13155 anonymous unions and structs. */
13156 if (DECL_NAME (decl
) != NULL_TREE
13157 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
13158 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
13160 gen_type_die (member_declared_type (decl
), context_die
);
13161 gen_field_die (decl
, context_die
);
13166 gen_type_die (TREE_TYPE (decl
), context_die
);
13167 gen_formal_parameter_die (decl
, context_die
);
13170 case NAMESPACE_DECL
:
13171 gen_namespace_die (decl
);
13175 /* Probably some frontend-internal decl. Assume we don't care. */
13176 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
13181 /* Output debug information for global decl DECL. Called from toplev.c after
13182 compilation proper has finished. */
13185 dwarf2out_global_decl (tree decl
)
13187 /* Output DWARF2 information for file-scope tentative data object
13188 declarations, file-scope (extern) function declarations (which had no
13189 corresponding body) and file-scope tagged type declarations and
13190 definitions which have not yet been forced out. */
13191 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
13192 dwarf2out_decl (decl
);
13195 /* Output debug information for type decl DECL. Called from toplev.c
13196 and from language front ends (to record built-in types). */
13198 dwarf2out_type_decl (tree decl
, int local
)
13201 dwarf2out_decl (decl
);
13204 /* Output debug information for imported module or decl. */
13207 dwarf2out_imported_module_or_decl (tree decl
, tree context
)
13209 dw_die_ref imported_die
, at_import_die
;
13210 dw_die_ref scope_die
;
13211 unsigned file_index
;
13212 expanded_location xloc
;
13214 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13219 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
13220 We need decl DIE for reference and scope die. First, get DIE for the decl
13223 /* Get the scope die for decl context. Use comp_unit_die for global module
13224 or decl. If die is not found for non globals, force new die. */
13226 scope_die
= comp_unit_die
;
13227 else if (TYPE_P (context
))
13228 scope_die
= force_type_die (context
);
13230 scope_die
= force_decl_die (context
);
13232 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
13233 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
13234 at_import_die
= force_type_die (TREE_TYPE (decl
));
13237 at_import_die
= lookup_decl_die (decl
);
13238 if (!at_import_die
)
13240 /* If we're trying to avoid duplicate debug info, we may not have
13241 emitted the member decl for this field. Emit it now. */
13242 if (TREE_CODE (decl
) == FIELD_DECL
)
13244 tree type
= DECL_CONTEXT (decl
);
13245 dw_die_ref type_context_die
;
13247 if (TYPE_CONTEXT (type
))
13248 if (TYPE_P (TYPE_CONTEXT (type
)))
13249 type_context_die
= force_type_die (TYPE_CONTEXT (type
));
13251 type_context_die
= force_decl_die (TYPE_CONTEXT (type
));
13253 type_context_die
= comp_unit_die
;
13254 gen_type_die_for_member (type
, decl
, type_context_die
);
13256 at_import_die
= force_decl_die (decl
);
13260 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
13261 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
13262 imported_die
= new_die (DW_TAG_imported_module
, scope_die
, context
);
13264 imported_die
= new_die (DW_TAG_imported_declaration
, scope_die
, context
);
13266 xloc
= expand_location (input_location
);
13267 file_index
= lookup_filename (xloc
.file
);
13268 add_AT_unsigned (imported_die
, DW_AT_decl_file
, file_index
);
13269 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
13270 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
13273 /* Write the debugging output for DECL. */
13276 dwarf2out_decl (tree decl
)
13278 dw_die_ref context_die
= comp_unit_die
;
13280 switch (TREE_CODE (decl
))
13285 case FUNCTION_DECL
:
13286 /* What we would really like to do here is to filter out all mere
13287 file-scope declarations of file-scope functions which are never
13288 referenced later within this translation unit (and keep all of ones
13289 that *are* referenced later on) but we aren't clairvoyant, so we have
13290 no idea which functions will be referenced in the future (i.e. later
13291 on within the current translation unit). So here we just ignore all
13292 file-scope function declarations which are not also definitions. If
13293 and when the debugger needs to know something about these functions,
13294 it will have to hunt around and find the DWARF information associated
13295 with the definition of the function.
13297 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
13298 nodes represent definitions and which ones represent mere
13299 declarations. We have to check DECL_INITIAL instead. That's because
13300 the C front-end supports some weird semantics for "extern inline"
13301 function definitions. These can get inlined within the current
13302 translation unit (and thus, we need to generate Dwarf info for their
13303 abstract instances so that the Dwarf info for the concrete inlined
13304 instances can have something to refer to) but the compiler never
13305 generates any out-of-lines instances of such things (despite the fact
13306 that they *are* definitions).
13308 The important point is that the C front-end marks these "extern
13309 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
13310 them anyway. Note that the C++ front-end also plays some similar games
13311 for inline function definitions appearing within include files which
13312 also contain `#pragma interface' pragmas. */
13313 if (DECL_INITIAL (decl
) == NULL_TREE
)
13316 /* If we're a nested function, initially use a parent of NULL; if we're
13317 a plain function, this will be fixed up in decls_for_scope. If
13318 we're a method, it will be ignored, since we already have a DIE. */
13319 if (decl_function_context (decl
)
13320 /* But if we're in terse mode, we don't care about scope. */
13321 && debug_info_level
> DINFO_LEVEL_TERSE
)
13322 context_die
= NULL
;
13326 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
13327 declaration and if the declaration was never even referenced from
13328 within this entire compilation unit. We suppress these DIEs in
13329 order to save space in the .debug section (by eliminating entries
13330 which are probably useless). Note that we must not suppress
13331 block-local extern declarations (whether used or not) because that
13332 would screw-up the debugger's name lookup mechanism and cause it to
13333 miss things which really ought to be in scope at a given point. */
13334 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
13337 /* For local statics lookup proper context die. */
13338 if (TREE_STATIC (decl
) && decl_function_context (decl
))
13339 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
13341 /* If we are in terse mode, don't generate any DIEs to represent any
13342 variable declarations or definitions. */
13343 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13347 case NAMESPACE_DECL
:
13348 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13350 if (lookup_decl_die (decl
) != NULL
)
13355 /* Don't emit stubs for types unless they are needed by other DIEs. */
13356 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
13359 /* Don't bother trying to generate any DIEs to represent any of the
13360 normal built-in types for the language we are compiling. */
13361 if (DECL_IS_BUILTIN (decl
))
13363 /* OK, we need to generate one for `bool' so GDB knows what type
13364 comparisons have. */
13366 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
13367 && ! DECL_IGNORED_P (decl
))
13368 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
13373 /* If we are in terse mode, don't generate any DIEs for types. */
13374 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13377 /* If we're a function-scope tag, initially use a parent of NULL;
13378 this will be fixed up in decls_for_scope. */
13379 if (decl_function_context (decl
))
13380 context_die
= NULL
;
13388 gen_decl_die (decl
, context_die
);
13391 /* Output a marker (i.e. a label) for the beginning of the generated code for
13392 a lexical block. */
13395 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
13396 unsigned int blocknum
)
13398 switch_to_section (current_function_section ());
13399 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
13402 /* Output a marker (i.e. a label) for the end of the generated code for a
13406 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
13408 switch_to_section (current_function_section ());
13409 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
13412 /* Returns nonzero if it is appropriate not to emit any debugging
13413 information for BLOCK, because it doesn't contain any instructions.
13415 Don't allow this for blocks with nested functions or local classes
13416 as we would end up with orphans, and in the presence of scheduling
13417 we may end up calling them anyway. */
13420 dwarf2out_ignore_block (tree block
)
13424 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
13425 if (TREE_CODE (decl
) == FUNCTION_DECL
13426 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
13432 /* Lookup FILE_NAME (in the list of filenames that we know about here in
13433 dwarf2out.c) and return its "index". The index of each (known) filename is
13434 just a unique number which is associated with only that one filename. We
13435 need such numbers for the sake of generating labels (in the .debug_sfnames
13436 section) and references to those files numbers (in the .debug_srcinfo
13437 and.debug_macinfo sections). If the filename given as an argument is not
13438 found in our current list, add it to the list and assign it the next
13439 available unique index number. In order to speed up searches, we remember
13440 the index of the filename was looked up last. This handles the majority of
13444 lookup_filename (const char *file_name
)
13447 char *save_file_name
;
13449 /* Check to see if the file name that was searched on the previous
13450 call matches this file name. If so, return the index. */
13451 if (file_table_last_lookup_index
!= 0)
13454 = VARRAY_CHAR_PTR (file_table
, file_table_last_lookup_index
);
13455 if (strcmp (file_name
, last
) == 0)
13456 return file_table_last_lookup_index
;
13459 /* Didn't match the previous lookup, search the table. */
13460 n
= VARRAY_ACTIVE_SIZE (file_table
);
13461 for (i
= 1; i
< n
; i
++)
13462 if (strcmp (file_name
, VARRAY_CHAR_PTR (file_table
, i
)) == 0)
13464 file_table_last_lookup_index
= i
;
13468 /* Add the new entry to the end of the filename table. */
13469 file_table_last_lookup_index
= n
;
13470 save_file_name
= (char *) ggc_strdup (file_name
);
13471 VARRAY_PUSH_CHAR_PTR (file_table
, save_file_name
);
13472 VARRAY_PUSH_UINT (file_table_emitted
, 0);
13474 /* If the assembler is emitting the file table, and we aren't eliminating
13475 unused debug types, then we must emit .file here. If we are eliminating
13476 unused debug types, then this will be done by the maybe_emit_file call in
13477 prune_unused_types_walk_attribs. */
13479 if (DWARF2_ASM_LINE_DEBUG_INFO
&& ! flag_eliminate_unused_debug_types
)
13480 return maybe_emit_file (i
);
13485 /* If the assembler will construct the file table, then translate the compiler
13486 internal file table number into the assembler file table number, and emit
13487 a .file directive if we haven't already emitted one yet. The file table
13488 numbers are different because we prune debug info for unused variables and
13489 types, which may include filenames. */
13492 maybe_emit_file (int fileno
)
13494 if (DWARF2_ASM_LINE_DEBUG_INFO
&& fileno
> 0)
13496 if (!VARRAY_UINT (file_table_emitted
, fileno
))
13498 VARRAY_UINT (file_table_emitted
, fileno
) = ++emitcount
;
13499 fprintf (asm_out_file
, "\t.file %u ",
13500 VARRAY_UINT (file_table_emitted
, fileno
));
13501 output_quoted_string (asm_out_file
,
13502 VARRAY_CHAR_PTR (file_table
, fileno
));
13503 fputc ('\n', asm_out_file
);
13505 return VARRAY_UINT (file_table_emitted
, fileno
);
13511 /* Initialize the compiler internal file table. */
13514 init_file_table (void)
13516 /* Allocate the initial hunk of the file_table. */
13517 VARRAY_CHAR_PTR_INIT (file_table
, 64, "file_table");
13518 VARRAY_UINT_INIT (file_table_emitted
, 64, "file_table_emitted");
13520 /* Skip the first entry - file numbers begin at 1. */
13521 VARRAY_PUSH_CHAR_PTR (file_table
, NULL
);
13522 VARRAY_PUSH_UINT (file_table_emitted
, 0);
13523 file_table_last_lookup_index
= 0;
13526 /* Called by the final INSN scan whenever we see a var location. We
13527 use it to drop labels in the right places, and throw the location in
13528 our lookup table. */
13531 dwarf2out_var_location (rtx loc_note
)
13533 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
13534 struct var_loc_node
*newloc
;
13536 static rtx last_insn
;
13537 static const char *last_label
;
13540 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
13542 prev_insn
= PREV_INSN (loc_note
);
13544 newloc
= ggc_alloc_cleared (sizeof (struct var_loc_node
));
13545 /* If the insn we processed last time is the previous insn
13546 and it is also a var location note, use the label we emitted
13548 if (last_insn
!= NULL_RTX
13549 && last_insn
== prev_insn
13550 && NOTE_P (prev_insn
)
13551 && NOTE_LINE_NUMBER (prev_insn
) == NOTE_INSN_VAR_LOCATION
)
13553 newloc
->label
= last_label
;
13557 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
13558 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
13560 newloc
->label
= ggc_strdup (loclabel
);
13562 newloc
->var_loc_note
= loc_note
;
13563 newloc
->next
= NULL
;
13565 if (cfun
&& in_cold_section_p
)
13566 newloc
->section_label
= cfun
->cold_section_label
;
13568 newloc
->section_label
= text_section_label
;
13570 last_insn
= loc_note
;
13571 last_label
= newloc
->label
;
13572 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
13573 if (DECL_DEBUG_EXPR_IS_FROM (decl
) && DECL_DEBUG_EXPR (decl
)
13574 && DECL_P (DECL_DEBUG_EXPR (decl
)))
13575 decl
= DECL_DEBUG_EXPR (decl
);
13576 add_var_loc_to_decl (decl
, newloc
);
13579 /* We need to reset the locations at the beginning of each
13580 function. We can't do this in the end_function hook, because the
13581 declarations that use the locations won't have been output when
13582 that hook is called. Also compute have_multiple_function_sections here. */
13585 dwarf2out_begin_function (tree fun
)
13587 htab_empty (decl_loc_table
);
13589 if (function_section (fun
) != text_section
)
13590 have_multiple_function_sections
= true;
13593 /* Output a label to mark the beginning of a source code line entry
13594 and record information relating to this source line, in
13595 'line_info_table' for later output of the .debug_line section. */
13598 dwarf2out_source_line (unsigned int line
, const char *filename
)
13600 if (debug_info_level
>= DINFO_LEVEL_NORMAL
13603 switch_to_section (current_function_section ());
13605 /* If requested, emit something human-readable. */
13606 if (flag_debug_asm
)
13607 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
13610 if (DWARF2_ASM_LINE_DEBUG_INFO
)
13612 unsigned file_num
= lookup_filename (filename
);
13614 file_num
= maybe_emit_file (file_num
);
13616 /* Emit the .loc directive understood by GNU as. */
13617 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
13619 /* Indicate that line number info exists. */
13620 line_info_table_in_use
++;
13622 else if (function_section (current_function_decl
) != text_section
)
13624 dw_separate_line_info_ref line_info
;
13625 targetm
.asm_out
.internal_label (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
13626 separate_line_info_table_in_use
);
13628 /* Expand the line info table if necessary. */
13629 if (separate_line_info_table_in_use
13630 == separate_line_info_table_allocated
)
13632 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
13633 separate_line_info_table
13634 = ggc_realloc (separate_line_info_table
,
13635 separate_line_info_table_allocated
13636 * sizeof (dw_separate_line_info_entry
));
13637 memset (separate_line_info_table
13638 + separate_line_info_table_in_use
,
13640 (LINE_INFO_TABLE_INCREMENT
13641 * sizeof (dw_separate_line_info_entry
)));
13644 /* Add the new entry at the end of the line_info_table. */
13646 = &separate_line_info_table
[separate_line_info_table_in_use
++];
13647 line_info
->dw_file_num
= lookup_filename (filename
);
13648 line_info
->dw_line_num
= line
;
13649 line_info
->function
= current_function_funcdef_no
;
13653 dw_line_info_ref line_info
;
13655 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
,
13656 line_info_table_in_use
);
13658 /* Expand the line info table if necessary. */
13659 if (line_info_table_in_use
== line_info_table_allocated
)
13661 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
13663 = ggc_realloc (line_info_table
,
13664 (line_info_table_allocated
13665 * sizeof (dw_line_info_entry
)));
13666 memset (line_info_table
+ line_info_table_in_use
, 0,
13667 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
13670 /* Add the new entry at the end of the line_info_table. */
13671 line_info
= &line_info_table
[line_info_table_in_use
++];
13672 line_info
->dw_file_num
= lookup_filename (filename
);
13673 line_info
->dw_line_num
= line
;
13678 /* Record the beginning of a new source file. */
13681 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
13683 if (flag_eliminate_dwarf2_dups
)
13685 /* Record the beginning of the file for break_out_includes. */
13686 dw_die_ref bincl_die
;
13688 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
13689 add_AT_string (bincl_die
, DW_AT_name
, filename
);
13692 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13696 switch_to_section (debug_macinfo_section
);
13697 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
13698 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
13701 fileno
= maybe_emit_file (lookup_filename (filename
));
13702 dw2_asm_output_data_uleb128 (fileno
, "Filename we just started");
13706 /* Record the end of a source file. */
13709 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
13711 if (flag_eliminate_dwarf2_dups
)
13712 /* Record the end of the file for break_out_includes. */
13713 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
13715 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13717 switch_to_section (debug_macinfo_section
);
13718 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
13722 /* Called from debug_define in toplev.c. The `buffer' parameter contains
13723 the tail part of the directive line, i.e. the part which is past the
13724 initial whitespace, #, whitespace, directive-name, whitespace part. */
13727 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
13728 const char *buffer ATTRIBUTE_UNUSED
)
13730 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13732 switch_to_section (debug_macinfo_section
);
13733 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
13734 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
13735 dw2_asm_output_nstring (buffer
, -1, "The macro");
13739 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
13740 the tail part of the directive line, i.e. the part which is past the
13741 initial whitespace, #, whitespace, directive-name, whitespace part. */
13744 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
13745 const char *buffer ATTRIBUTE_UNUSED
)
13747 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13749 switch_to_section (debug_macinfo_section
);
13750 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
13751 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
13752 dw2_asm_output_nstring (buffer
, -1, "The macro");
13756 /* Set up for Dwarf output at the start of compilation. */
13759 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
13761 init_file_table ();
13763 /* Allocate the decl_die_table. */
13764 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
13765 decl_die_table_eq
, NULL
);
13767 /* Allocate the decl_loc_table. */
13768 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
13769 decl_loc_table_eq
, NULL
);
13771 /* Allocate the initial hunk of the decl_scope_table. */
13772 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
13774 /* Allocate the initial hunk of the abbrev_die_table. */
13775 abbrev_die_table
= ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
13776 * sizeof (dw_die_ref
));
13777 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
13778 /* Zero-th entry is allocated, but unused. */
13779 abbrev_die_table_in_use
= 1;
13781 /* Allocate the initial hunk of the line_info_table. */
13782 line_info_table
= ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
13783 * sizeof (dw_line_info_entry
));
13784 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
13786 /* Zero-th entry is allocated, but unused. */
13787 line_info_table_in_use
= 1;
13789 /* Generate the initial DIE for the .debug section. Note that the (string)
13790 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
13791 will (typically) be a relative pathname and that this pathname should be
13792 taken as being relative to the directory from which the compiler was
13793 invoked when the given (base) source file was compiled. We will fill
13794 in this value in dwarf2out_finish. */
13795 comp_unit_die
= gen_compile_unit_die (NULL
);
13797 incomplete_types
= VEC_alloc (tree
, gc
, 64);
13799 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
13801 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
13802 SECTION_DEBUG
, NULL
);
13803 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
13804 SECTION_DEBUG
, NULL
);
13805 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
13806 SECTION_DEBUG
, NULL
);
13807 debug_macinfo_section
= get_section (DEBUG_MACINFO_SECTION
,
13808 SECTION_DEBUG
, NULL
);
13809 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
13810 SECTION_DEBUG
, NULL
);
13811 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
13812 SECTION_DEBUG
, NULL
);
13813 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
13814 SECTION_DEBUG
, NULL
);
13815 debug_str_section
= get_section (DEBUG_STR_SECTION
,
13816 DEBUG_STR_SECTION_FLAGS
, NULL
);
13817 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
13818 SECTION_DEBUG
, NULL
);
13819 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
13820 SECTION_DEBUG
, NULL
);
13822 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
13823 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
13824 DEBUG_ABBREV_SECTION_LABEL
, 0);
13825 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
13826 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
13827 COLD_TEXT_SECTION_LABEL
, 0);
13828 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
13830 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
13831 DEBUG_INFO_SECTION_LABEL
, 0);
13832 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
13833 DEBUG_LINE_SECTION_LABEL
, 0);
13834 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
13835 DEBUG_RANGES_SECTION_LABEL
, 0);
13836 switch_to_section (debug_abbrev_section
);
13837 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
13838 switch_to_section (debug_info_section
);
13839 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
13840 switch_to_section (debug_line_section
);
13841 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
13843 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13845 switch_to_section (debug_macinfo_section
);
13846 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
13847 DEBUG_MACINFO_SECTION_LABEL
, 0);
13848 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
13851 switch_to_section (text_section
);
13852 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
13853 if (flag_reorder_blocks_and_partition
)
13855 switch_to_section (unlikely_text_section ());
13856 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
13860 /* A helper function for dwarf2out_finish called through
13861 ht_forall. Emit one queued .debug_str string. */
13864 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
13866 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
13868 if (node
->form
== DW_FORM_strp
)
13870 switch_to_section (debug_str_section
);
13871 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
13872 assemble_string (node
->str
, strlen (node
->str
) + 1);
13880 /* Clear the marks for a die and its children.
13881 Be cool if the mark isn't set. */
13884 prune_unmark_dies (dw_die_ref die
)
13888 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
13889 prune_unmark_dies (c
);
13893 /* Given DIE that we're marking as used, find any other dies
13894 it references as attributes and mark them as used. */
13897 prune_unused_types_walk_attribs (dw_die_ref die
)
13902 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
13904 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
13906 /* A reference to another DIE.
13907 Make sure that it will get emitted. */
13908 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
13910 else if (a
->dw_attr
== DW_AT_decl_file
|| a
->dw_attr
== DW_AT_call_file
)
13912 /* A reference to a file. Make sure the file name is emitted. */
13913 a
->dw_attr_val
.v
.val_unsigned
=
13914 maybe_emit_file (a
->dw_attr_val
.v
.val_unsigned
);
13920 /* Mark DIE as being used. If DOKIDS is true, then walk down
13921 to DIE's children. */
13924 prune_unused_types_mark (dw_die_ref die
, int dokids
)
13928 if (die
->die_mark
== 0)
13930 /* We haven't done this node yet. Mark it as used. */
13933 /* We also have to mark its parents as used.
13934 (But we don't want to mark our parents' kids due to this.) */
13935 if (die
->die_parent
)
13936 prune_unused_types_mark (die
->die_parent
, 0);
13938 /* Mark any referenced nodes. */
13939 prune_unused_types_walk_attribs (die
);
13941 /* If this node is a specification,
13942 also mark the definition, if it exists. */
13943 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
13944 prune_unused_types_mark (die
->die_definition
, 1);
13947 if (dokids
&& die
->die_mark
!= 2)
13949 /* We need to walk the children, but haven't done so yet.
13950 Remember that we've walked the kids. */
13954 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
13956 /* If this is an array type, we need to make sure our
13957 kids get marked, even if they're types. */
13958 if (die
->die_tag
== DW_TAG_array_type
)
13959 prune_unused_types_mark (c
, 1);
13961 prune_unused_types_walk (c
);
13967 /* Walk the tree DIE and mark types that we actually use. */
13970 prune_unused_types_walk (dw_die_ref die
)
13974 /* Don't do anything if this node is already marked. */
13978 switch (die
->die_tag
) {
13979 case DW_TAG_const_type
:
13980 case DW_TAG_packed_type
:
13981 case DW_TAG_pointer_type
:
13982 case DW_TAG_reference_type
:
13983 case DW_TAG_volatile_type
:
13984 case DW_TAG_typedef
:
13985 case DW_TAG_array_type
:
13986 case DW_TAG_structure_type
:
13987 case DW_TAG_union_type
:
13988 case DW_TAG_class_type
:
13989 case DW_TAG_friend
:
13990 case DW_TAG_variant_part
:
13991 case DW_TAG_enumeration_type
:
13992 case DW_TAG_subroutine_type
:
13993 case DW_TAG_string_type
:
13994 case DW_TAG_set_type
:
13995 case DW_TAG_subrange_type
:
13996 case DW_TAG_ptr_to_member_type
:
13997 case DW_TAG_file_type
:
13998 if (die
->die_perennial_p
)
14001 /* It's a type node --- don't mark it. */
14005 /* Mark everything else. */
14011 /* Now, mark any dies referenced from here. */
14012 prune_unused_types_walk_attribs (die
);
14014 /* Mark children. */
14015 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
14016 prune_unused_types_walk (c
);
14020 /* Remove from the tree DIE any dies that aren't marked. */
14023 prune_unused_types_prune (dw_die_ref die
)
14025 dw_die_ref c
, p
, n
;
14027 gcc_assert (die
->die_mark
);
14030 for (c
= die
->die_child
; c
; c
= n
)
14035 prune_unused_types_prune (c
);
14043 die
->die_child
= n
;
14050 /* Remove dies representing declarations that we never use. */
14053 prune_unused_types (void)
14056 limbo_die_node
*node
;
14058 /* Clear all the marks. */
14059 prune_unmark_dies (comp_unit_die
);
14060 for (node
= limbo_die_list
; node
; node
= node
->next
)
14061 prune_unmark_dies (node
->die
);
14063 /* Set the mark on nodes that are actually used. */
14064 prune_unused_types_walk (comp_unit_die
);
14065 for (node
= limbo_die_list
; node
; node
= node
->next
)
14066 prune_unused_types_walk (node
->die
);
14068 /* Also set the mark on nodes referenced from the
14069 pubname_table or arange_table. */
14070 for (i
= 0; i
< pubname_table_in_use
; i
++)
14071 prune_unused_types_mark (pubname_table
[i
].die
, 1);
14072 for (i
= 0; i
< arange_table_in_use
; i
++)
14073 prune_unused_types_mark (arange_table
[i
], 1);
14075 /* Get rid of nodes that aren't marked. */
14076 prune_unused_types_prune (comp_unit_die
);
14077 for (node
= limbo_die_list
; node
; node
= node
->next
)
14078 prune_unused_types_prune (node
->die
);
14080 /* Leave the marks clear. */
14081 prune_unmark_dies (comp_unit_die
);
14082 for (node
= limbo_die_list
; node
; node
= node
->next
)
14083 prune_unmark_dies (node
->die
);
14086 /* Output stuff that dwarf requires at the end of every file,
14087 and generate the DWARF-2 debugging info. */
14090 dwarf2out_finish (const char *filename
)
14092 limbo_die_node
*node
, *next_node
;
14093 dw_die_ref die
= 0;
14095 /* Add the name for the main input file now. We delayed this from
14096 dwarf2out_init to avoid complications with PCH. */
14097 add_name_attribute (comp_unit_die
, filename
);
14098 if (filename
[0] != DIR_SEPARATOR
)
14099 add_comp_dir_attribute (comp_unit_die
);
14100 else if (get_AT (comp_unit_die
, DW_AT_comp_dir
) == NULL
)
14103 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
14104 if (VARRAY_CHAR_PTR (file_table
, i
)[0] != DIR_SEPARATOR
14105 /* Don't add cwd for <built-in>. */
14106 && VARRAY_CHAR_PTR (file_table
, i
)[0] != '<')
14108 add_comp_dir_attribute (comp_unit_die
);
14113 /* Traverse the limbo die list, and add parent/child links. The only
14114 dies without parents that should be here are concrete instances of
14115 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
14116 For concrete instances, we can get the parent die from the abstract
14118 for (node
= limbo_die_list
; node
; node
= next_node
)
14120 next_node
= node
->next
;
14123 if (die
->die_parent
== NULL
)
14125 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
14128 add_child_die (origin
->die_parent
, die
);
14129 else if (die
== comp_unit_die
)
14131 else if (errorcount
> 0 || sorrycount
> 0)
14132 /* It's OK to be confused by errors in the input. */
14133 add_child_die (comp_unit_die
, die
);
14136 /* In certain situations, the lexical block containing a
14137 nested function can be optimized away, which results
14138 in the nested function die being orphaned. Likewise
14139 with the return type of that nested function. Force
14140 this to be a child of the containing function.
14142 It may happen that even the containing function got fully
14143 inlined and optimized out. In that case we are lost and
14144 assign the empty child. This should not be big issue as
14145 the function is likely unreachable too. */
14146 tree context
= NULL_TREE
;
14148 gcc_assert (node
->created_for
);
14150 if (DECL_P (node
->created_for
))
14151 context
= DECL_CONTEXT (node
->created_for
);
14152 else if (TYPE_P (node
->created_for
))
14153 context
= TYPE_CONTEXT (node
->created_for
);
14155 gcc_assert (context
&& TREE_CODE (context
) == FUNCTION_DECL
);
14157 origin
= lookup_decl_die (context
);
14159 add_child_die (origin
, die
);
14161 add_child_die (comp_unit_die
, die
);
14166 limbo_die_list
= NULL
;
14168 /* Walk through the list of incomplete types again, trying once more to
14169 emit full debugging info for them. */
14170 retry_incomplete_types ();
14172 /* We need to reverse all the dies before break_out_includes, or
14173 we'll see the end of an include file before the beginning. */
14174 reverse_all_dies (comp_unit_die
);
14176 if (flag_eliminate_unused_debug_types
)
14177 prune_unused_types ();
14179 /* Generate separate CUs for each of the include files we've seen.
14180 They will go into limbo_die_list. */
14181 if (flag_eliminate_dwarf2_dups
)
14182 break_out_includes (comp_unit_die
);
14184 /* Traverse the DIE's and add add sibling attributes to those DIE's
14185 that have children. */
14186 add_sibling_attributes (comp_unit_die
);
14187 for (node
= limbo_die_list
; node
; node
= node
->next
)
14188 add_sibling_attributes (node
->die
);
14190 /* Output a terminator label for the .text section. */
14191 switch_to_section (text_section
);
14192 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
14193 if (flag_reorder_blocks_and_partition
)
14195 switch_to_section (unlikely_text_section ());
14196 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
14199 /* Output the source line correspondence table. We must do this
14200 even if there is no line information. Otherwise, on an empty
14201 translation unit, we will generate a present, but empty,
14202 .debug_info section. IRIX 6.5 `nm' will then complain when
14203 examining the file. */
14204 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
14206 switch_to_section (debug_line_section
);
14207 output_line_info ();
14210 /* We can only use the low/high_pc attributes if all of the code was
14212 if (!have_multiple_function_sections
)
14214 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
14215 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
14218 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
14219 "base address". Use zero so that these addresses become absolute. */
14220 else if (have_location_lists
|| ranges_table_in_use
)
14221 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
14223 /* Output location list section if necessary. */
14224 if (have_location_lists
)
14226 /* Output the location lists info. */
14227 switch_to_section (debug_loc_section
);
14228 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
14229 DEBUG_LOC_SECTION_LABEL
, 0);
14230 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
14231 output_location_lists (die
);
14234 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
14235 add_AT_lineptr (comp_unit_die
, DW_AT_stmt_list
,
14236 debug_line_section_label
);
14238 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
14239 add_AT_macptr (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
14241 /* Output all of the compilation units. We put the main one last so that
14242 the offsets are available to output_pubnames. */
14243 for (node
= limbo_die_list
; node
; node
= node
->next
)
14244 output_comp_unit (node
->die
, 0);
14246 output_comp_unit (comp_unit_die
, 0);
14248 /* Output the abbreviation table. */
14249 switch_to_section (debug_abbrev_section
);
14250 output_abbrev_section ();
14252 /* Output public names table if necessary. */
14253 if (pubname_table_in_use
)
14255 switch_to_section (debug_pubnames_section
);
14256 output_pubnames ();
14259 /* Output the address range information. We only put functions in the arange
14260 table, so don't write it out if we don't have any. */
14261 if (fde_table_in_use
)
14263 switch_to_section (debug_aranges_section
);
14267 /* Output ranges section if necessary. */
14268 if (ranges_table_in_use
)
14270 switch_to_section (debug_ranges_section
);
14271 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
14275 /* Have to end the macro section. */
14276 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
14278 switch_to_section (debug_macinfo_section
);
14279 dw2_asm_output_data (1, 0, "End compilation unit");
14282 /* If we emitted any DW_FORM_strp form attribute, output the string
14284 if (debug_str_hash
)
14285 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
14289 /* This should never be used, but its address is needed for comparisons. */
14290 const struct gcc_debug_hooks dwarf2_debug_hooks
;
14292 #endif /* DWARF2_DEBUGGING_INFO */
14294 #include "gt-dwarf2out.h"